Skip to content

Commit 1aee274

Browse files
committed
Completed Readme
1 parent c8fb85e commit 1aee274

2 files changed

Lines changed: 100 additions & 15 deletions

File tree

README.md

Lines changed: 99 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,30 +2,82 @@
22

33
Generic toolkit for server and web applications.
44

5-
- [ ]
5+
1. Manages global settings for the lib (servers, localization, logger)
6+
2. Extends orginal Pryv's JS lib to fit HDS needs
7+
3. Based on [HDS data model](https://github.com/healthdatasafe/data-model-draft?tab=readme-ov-file#hds-data-model-drafting-space) exposes methods to facilitate app development.
8+
- load data model and exposes it as a singleton
9+
- retrieve definitions
10+
- provides helper for stream creation and authorizations requests
11+
4. Provide app templates to create new applications for
12+
- Requesting and managing consents - And collecting data
13+
- Approving requests and sharing data
14+
5. Other tools to facilitate app developments
615

7-
## Usage
816

9-
### Model
17+
## Components
1018

11-
#### Load
19+
### settings
20+
21+
#### settings.setServiceInfoURL(url)
22+
Set the default service for `HDSModel` and `HDSService`
23+
24+
#### settings.setPreferredLocales(Array of locales)
25+
Change the order of pereferred localization codes
26+
27+
### HDSService
28+
Is an extension of `pryv.Service` which uses the default service set with `settings.setServiceInfoURL(url)``
29+
30+
### pryv
31+
Patched version of [pryv's javacript library](https://github.com/pryv/lib-js) including supports for [Socket.io](https://github.com/pryv/lib-js/tree/master/components/pryv-socket.io) and [Monitors](https://github.com/pryv/lib-js/tree/master/components/pryv-monitor)
32+
33+
#### pryv.Connection.apiOne(method, params, expectedKey)
34+
One liner call to pryv api based on `connection.api()``
35+
36+
#### pryv.Connection.revoke()
37+
Helper to revoke current connection
38+
39+
### localizeText (alias "l")
40+
Handles localization of text. The choice of locales can be set with `settings.setPreferredLocales()`
41+
42+
### HDSModel
43+
44+
an instance of HDSModel loads the definitions from a json file, usually `https://model.datasafe.dev/pack.json`. This may be overridden with:
45+
46+
**Load your own model**
1247

1348
```javascript
1449
const model = new HDSLib.HDSModel('https://model.datasafe.dev/pack.json');
1550
await model.load();
1651
```
1752

18-
#### ItemDef
53+
**Per service auto loading.** (preferred way)
54+
0. (Optional) You may set the defaultService info of the lib with `HDSLib.setServiceInfoURL()`.
55+
1. Initialize model singleton once with `await HDSLib.initHDSModel()`
56+
2. Use model from `HDSLib.model`
57+
58+
#### HDSModel.ItemDef
1959

2060
An `ItemDef` is an object representation of the items from the data Model
2161

62+
- **itemDef.key**: (string) a unique identifier, for example `body-weight`
63+
- **itemDef.data**: (Object) raw data for this item from [HDS data model](https://github.com/healthdatasafe/data-model-draft?tab=readme-ov-file#hds-data-model-drafting-space)
64+
- **itemDef.label**: (string) localized `item.data.label`
65+
- **itemDef.description**: (string) localized `item.data.description`
66+
- **itemDef.eventTypes**: (Array) of supported eventTypes
67+
68+
#### model.itemDefs
69+
Tools to retrieve itemDefinitons
70+
71+
##### model.itemDefs.forKey()
72+
retrieve an itemDef with its key
73+
2274
```javascript
23-
// retrieve an itemDef by it's key
2475
const weight = model.itemDefs.forKey('body-weight');
2576
weight.streamId; // => 'body-weight'
2677
weight.eventTypes; // => ['mass/kg', 'mass/lb']
2778
```
2879

80+
##### model.itemDefs.forKey()
2981
```javascript
3082
// retrieve an itemDef from an event
3183
const anEvent = {
@@ -36,10 +88,16 @@ const itemDef = model.itemsDefs.forEvent(anEvent);
3688
itemDef.key // => 'body-weight'
3789
```
3890

39-
#### Streams
91+
#### HDSModel.Streams
92+
93+
##### model.streams.getNecessaryListForItems(itemKeys, params)
94+
get the list of streams to be created to store these items
95+
96+
**params**
97+
- **nameProperty**: (string) can be set to 'name' (default), 'defaultName' or 'none' => if you want nothing
98+
- **knowExistingStreamsIds**: (Array of strings) Array of known existing streams' ids
4099

41100
```javascript
42-
// get the list of streams to be created to store these items
43101
const itemKeys = [
44102
'profile-name',
45103
'profile-date-of-birth',
@@ -49,10 +107,25 @@ const itemKeys = [
49107
const streamsToBeCreated = model.streams.getNecessaryListForItems(itemKeys);
50108
```
51109

52-
#### Authorizations
110+
##### model.streams.getDataById(streamId)
111+
retrieve model data related to this stream
53112

54-
```javascript
55-
// get the authorization needed to manipulate a set of items
113+
##### model.streams.getParentsIds(streamId)
114+
retrieve order list of parents up to this streamId
115+
116+
117+
#### HDSModel.Authorizations
118+
Helpers to generate authorizations from itemKeys
119+
120+
##### model.authorizations.forItemKeys(itemKeys, options);
121+
get the authorization needed to manipulate a set of items
122+
123+
**options** (all optional)
124+
- **defaultLevel**: (string, default = 'name' ) - one of'read', 'manage', 'contribue', 'writeOnly'
125+
- **includeDefaultName** (boolean, default = true) - if false does not add defaultNames for streams
126+
- **preRequest** (Array of AuthorizationRequestItem) you may specify a custom set or authorizations
127+
128+
```javascript
56129
const itemKeys = [
57130
'body-vulva-mucus-inspect',
58131
'profile-name',
@@ -84,17 +157,28 @@ const expected = [
84157
];
85158
```
86159

87-
88-
89160
### AppTemplates
90161

91162
App templates based on HDS Model, provide frameworks to build applications for HDS.
92163

93164
Some of the functionalities will be moved from the lib
94165

166+
### toolkit
167+
Misc. tools
168+
169+
#### toolkit.StreamsAutoCreate
170+
helper to be attached to a `Connection` to facilitate auto creation of streams when needed.
95171

172+
Exemple:
173+
```javascript
174+
// done at initialization of connection (a pryv.Connection)
175+
toolkit.StreamsAutoCreate.attachToConnection(connection)
176+
177+
// later
178+
await connection.streamsAutoCreate.ensureExistsForItems(['body-weight', 'profile-name']);
179+
```
96180

97-
### Browser
181+
## Usage Browser
98182

99183
```html
100184
<head>
@@ -116,6 +200,7 @@ Some of the functionalities will be moved from the lib
116200
## Node
117201
- all tests: `npm run test`
118202
- specific test: `npm run test -- --grep=<string>`
203+
- coverage: `npm run test:coverage`
119204

120205
## Browser
121206
Test suite is accessible in `docs/`

src/HDSModel/HDSModel-Authorizations.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class HDSModelAuthorizations {
1616
* /!\ Does not handle requests with streamId = "*"
1717
* @param {Array<itemKeys>} itemKeys
1818
* @param {Object} [options]
19-
* @param {string} [options.defaultLevel] (default = write) one of 'read', 'write', 'contribute', 'writeOnly'
19+
* @param {string} [options.defaultLevel] (default = write) one of 'read', 'manage', 'contribute', 'writeOnly'
2020
* @param {boolean} [options.includeDefaultName] (default = true) defaultNames are needed for permission requests but not for access creation
2121
* @param {Array<AuthorizationRequestItem>} [options.preRequest]
2222
* @return {Array<AuthorizationRequestItem>}

0 commit comments

Comments
 (0)