Skip to content

Commit d15ce20

Browse files
committed
Adding type definitions
1 parent 2d7f927 commit d15ce20

28 files changed

Lines changed: 657 additions & 7 deletions

package-lock.json

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "hds-lib",
3-
"version": "0.1.1",
3+
"version": "0.1.2",
44
"description": "Health Data Safe - Library",
55
"main": "src/index.js",
66
"scripts": {
@@ -15,6 +15,7 @@
1515
"type": "git",
1616
"url": "git+https://github.com/healthdatasafe/hds-lib-js.git"
1717
},
18+
"types": "types/index.d.ts",
1819
"keywords": [
1920
"HDS",
2021
"Health",

src/appTemplates/Collector.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ class Collector {
5757
}
5858

5959
/**
60-
* @type {StatusData}
6160
* Payload that can be modified
6261
* */
6362
get statusData () {

tsconfig.json

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
// Change this to match your project
3+
"include": ["src/**/*"],
4+
"compilerOptions": {
5+
// Tells TypeScript to read JS files, as
6+
// normally they are ignored as source files
7+
"allowJs": true,
8+
// Generate d.ts files
9+
"declaration": true,
10+
// This compiler run should
11+
// only output d.ts files
12+
"emitDeclarationOnly": true,
13+
// Types should go into this directory.
14+
// Removing this would place the .d.ts files
15+
// next to the .js files
16+
"outDir": "types",
17+
// go to js file when using IDE functions like
18+
// "Go to Definition" in VSCode
19+
"declarationMap": true
20+
}
21+
}

types/HDSModel/HDSItemDef.d.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
export = HDSItemDef;
2+
declare class HDSItemDef {
3+
constructor(key: string, definitionData: any);
4+
get eventTypes(): any[];
5+
get key(): string;
6+
get data(): any;
7+
/** @type {string} label Localized */
8+
get label(): string;
9+
/** @type {string} description Localized */
10+
get description(): string;
11+
/**
12+
* a template event with eventType and streamIds
13+
* // TODO handle variations
14+
* @returns {Object}
15+
*/
16+
eventTemplate(): any;
17+
#private;
18+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
export = HDSModelAuthorizations;
2+
/**
3+
* Authorizations - Extension of HDSModel
4+
*/
5+
declare class HDSModelAuthorizations {
6+
constructor(model: any);
7+
/**
8+
* Get minimal Authorization set for itemKeys
9+
* /!\ Does not handle requests with streamId = "*"
10+
* @param {Array<itemKeys>} itemKeys
11+
* @param {Object} [options]
12+
* @param {string} [options.defaultLevel] (default = write) one of 'read', 'manage', 'contribute', 'writeOnly'
13+
* @param {boolean} [options.includeDefaultName] (default = true) defaultNames are needed for permission requests but not for access creation
14+
* @param {Array<AuthorizationRequestItem>} [options.preRequest]
15+
* @return {Array<AuthorizationRequestItem>}
16+
*/
17+
forItemKeys(itemKeys: any, options?: {
18+
defaultLevel?: string;
19+
includeDefaultName?: boolean;
20+
preRequest?: Array<AuthorizationRequestItem>;
21+
}): Array<AuthorizationRequestItem>;
22+
#private;
23+
}
24+
declare namespace HDSModelAuthorizations {
25+
export { AuthorizationRequestItem };
26+
}
27+
type AuthorizationRequestItem = {
28+
streamId: string;
29+
level: string;
30+
defaultName: string;
31+
};
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
export = HDSModelItemsDefs;
2+
/**
3+
* ItemsDefs - Extension of HDSModel
4+
*/
5+
declare class HDSModelItemsDefs {
6+
constructor(model: any);
7+
/**
8+
* get item for a key
9+
* @param {string} key
10+
* @param {boolean} [throwErrorIfNotFound] default `true`
11+
*/
12+
forKey(key: string, throwErrorIfNotFound?: boolean): any;
13+
/**
14+
* get a definition for an event
15+
* @param {Event} event
16+
* @param {boolean} [throwErrorIfNotFound] default `true`
17+
*/
18+
forEvent(event: Event, throwErrorIfNotFound?: boolean): any;
19+
#private;
20+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import HDSItemDef from "./HDSItemDef";
2+
export = HDSModelStreams;
3+
/**
4+
* Streams - Extension of HDSModel
5+
*/
6+
declare class HDSModelStreams {
7+
constructor(model: any);
8+
/**
9+
* Get a list of streams to be created for usage of these keys (whithout children)
10+
* @param {Array<string>|Array<HDSItemDef>} itemKeysOrDefs
11+
* @param {Object} params
12+
* @param {String} [params.nameProperty = 'name'] - can be set to 'name' (default), 'defaultName' or 'none' => if you want nothing
13+
* @param {Array<string>} [params.knowExistingStreamsIds]
14+
*/
15+
getNecessaryListForItems(itemKeysOrDefs: Array<string> | Array<HDSItemDef>, params?: {
16+
nameProperty?: string;
17+
knowExistingStreamsIds?: Array<string>;
18+
}): {
19+
id: any;
20+
parentId: any;
21+
}[];
22+
/**
23+
* Get stream Data by Id;
24+
* @param {string} streamId
25+
*/
26+
getDataById(streamId: string, throwErrorIfNotFound?: boolean): any;
27+
/**
28+
* Get all parents id;
29+
* @param {string} streamId
30+
* @param {boolean} [throwErrorIfNotFound] default `true`
31+
* @param {Array} [initialArray] - a pre-filled array
32+
*/
33+
getParentsIds(streamId: string, throwErrorIfNotFound?: boolean, initialArray?: any[]): any[];
34+
#private;
35+
}

types/HDSModel/HDSModel.d.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
export = HDSModel;
2+
/**
3+
* @class {HDSModel}
4+
* @property {object} modelData - Raw ModelData
5+
* @property {HDSModelItemsDefs} itemsDefs
6+
* @property {HDSModelStreams} streams
7+
* @property {HDSModelAuthorizations} authorizations
8+
*/
9+
declare class HDSModel {
10+
/**
11+
* @param {string} modelUrl - JSON definition file URL. Should come from service/info assets.hds-model
12+
*/
13+
constructor(modelUrl: string);
14+
/**
15+
* @private
16+
* Map of properties loaded "on demand"
17+
*/
18+
private laziliyLoadedMap;
19+
get isLoaded(): boolean;
20+
/**
21+
* Load model definitions
22+
*/
23+
load(modelUrl?: any): Promise<void>;
24+
/** RAW model data */
25+
get modelData(): any;
26+
#private;
27+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
export function getModel(): any;
2+
/**
3+
* Initialized model singleton
4+
* @returns {HDSModel}
5+
*/
6+
export function initHDSModel(): HDSModel;
7+
import HDSModel = require("./HDSModel");

0 commit comments

Comments
 (0)