@openframe-org/criteria-set-protocol 1.0.0 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +53 -0
- package/dist/services/i-versioned.service.d.ts +11 -0
- package/dist/services/versions.service.d.ts +28 -0
- package/dist/services/versions.service.js +28 -0
- package/dist/v1/schemas/criteria-set-id-param-schema.d.ts +3 -0
- package/dist/v1/schemas/criteria-set-id-param-schema.js +3 -0
- package/dist/v1/schemas/download-matrix-body-schema.d.ts +3 -0
- package/dist/v1/schemas/download-matrix-body-schema.js +3 -0
- package/dist/v1/schemas/version-param-schema.d.ts +3 -0
- package/dist/v1/schemas/version-param-schema.js +3 -0
- package/dist/v1/services/i-protocol-v1.service.d.ts +22 -1
- package/dist/v1/types/express.d.ts +1 -1
- package/package.json +1 -1
package/README.md
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
<img alt="Frame ApS" src="https://openframe-public.s3.eu-west-1.amazonaws.com/assets/logo-text-google-admin.png" width="200" />
|
|
2
|
+
|
|
3
|
+
# Criteria Set Protocol
|
|
4
|
+
|
|
5
|
+
## TypeScript library
|
|
6
|
+
This is a TypeScript library with types and implementations of the Criteria Set Protocol. It is published
|
|
7
|
+
publicly on [npmjs](https://www.npmjs.com/package/@openframe-org/criteria-set-protocol) as `@openframe-org/criteria-set-protocol`.
|
|
8
|
+
|
|
9
|
+
### Installation
|
|
10
|
+
```bash
|
|
11
|
+
npm install --save @openframe-org/criteria-set-protocol
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
### Contents
|
|
15
|
+
The library contains a service to work with protocol versions, and an interface to interact with this service.
|
|
16
|
+
|
|
17
|
+
#### Protocol v1
|
|
18
|
+
The library contains the types defined in the protocol v1 specification, and a service that implements this specification.
|
|
19
|
+
|
|
20
|
+
##### Types
|
|
21
|
+
| Type | Remarks |
|
|
22
|
+
|-------------------------------|-----------------------------------------------------|
|
|
23
|
+
| **Metadata types** | |
|
|
24
|
+
| `Metadata` | |
|
|
25
|
+
| **Task tree types** | |
|
|
26
|
+
| `CriteriaTree` | |
|
|
27
|
+
| `Criterion` | |
|
|
28
|
+
| `TaskGroup` | |
|
|
29
|
+
| `Task` | |
|
|
30
|
+
| `TaskItem` | |
|
|
31
|
+
| **TaskItem value types** | |
|
|
32
|
+
| `SelectSingleType` | |
|
|
33
|
+
| `SelectMultipleType` | |
|
|
34
|
+
| `NumberType` | |
|
|
35
|
+
| `BooleanType` | |
|
|
36
|
+
| `PointOption` | Used by `SelectSingleType` and `SelectMultipleType` |
|
|
37
|
+
| `TaskItemValue` | The raw value of a TaskItem |
|
|
38
|
+
| **Express types** | |
|
|
39
|
+
| `MetadataResponse` | Metadata endpoint response body |
|
|
40
|
+
| `StreamCriteriaSetMatrixBody` | Request body for the matrix streaming endpoints |
|
|
41
|
+
| `StreamMatrixResponse` | Matrix streaming endpoints response body |
|
|
42
|
+
|
|
43
|
+
##### Schemas
|
|
44
|
+
Validation schemas are provided for validating the endpoints of the protocol v1 specification.
|
|
45
|
+
|
|
46
|
+
| Schema | Remarks |
|
|
47
|
+
|----------------------------|------------------------------------------------------------------|
|
|
48
|
+
| `criteriaSetIdParamSchema` | Validates the criteriaSetId parameter for endpoints which use it |
|
|
49
|
+
| `versionParamSchema` | Validates the version parameter for endpoints which use it |
|
|
50
|
+
| `downloadMatrixBody` | Validates the request body for the download matrix endpoints |
|
|
51
|
+
|
|
52
|
+
##### Services
|
|
53
|
+
The `IProtocolV1Service` interface defines a service which implements the v1 protocol.
|
|
@@ -1,5 +1,16 @@
|
|
|
1
1
|
import { ProtocolVersionServiceMap } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* Interface for versioned services
|
|
4
|
+
*
|
|
5
|
+
* Services that implement this interface can be managed by the VersionsService
|
|
6
|
+
*/
|
|
2
7
|
export interface IVersionedService {
|
|
8
|
+
/**
|
|
9
|
+
* The SemVer version of the service
|
|
10
|
+
*/
|
|
3
11
|
version: string;
|
|
12
|
+
/**
|
|
13
|
+
* Whether the service supports the given protocol version
|
|
14
|
+
*/
|
|
4
15
|
supportsProtocol: <ProtocolVersion extends number>(protocolVersion: ProtocolVersion) => this is ProtocolVersionServiceMap<ProtocolVersion>;
|
|
5
16
|
}
|
|
@@ -1,10 +1,38 @@
|
|
|
1
1
|
import { IVersionedService } from './i-versioned.service';
|
|
2
2
|
import { ProtocolVersionServiceMap } from '../types';
|
|
3
|
+
/**
|
|
4
|
+
* Service for managing versions of services
|
|
5
|
+
*
|
|
6
|
+
* The VersionsService class is a utility class for services which implement different versions of the protocol, and different versions of their
|
|
7
|
+
* own service. For example, say you have a v1service, v11service, v2service and v21service with versions 1.0, 1.1, 2.0 and 2.1 respectively.
|
|
8
|
+
* The VersionsService class can be used to manage these services:
|
|
9
|
+
*
|
|
10
|
+
* const versionsService = new VersionsService([v1service, v11service, v2service, v21service]);
|
|
11
|
+
* versionsService.getLatestVersion(); // v21service
|
|
12
|
+
* versionsService.getServiceVersions(1); // [v1service, v11service]
|
|
13
|
+
* versionsService.getServiceVersions(2); // [v2service, v21service]
|
|
14
|
+
* versionsService.get('1.1'); // v11service
|
|
15
|
+
*/
|
|
3
16
|
export declare class VersionsService {
|
|
4
17
|
protected versions: IVersionedService[];
|
|
18
|
+
/**
|
|
19
|
+
* @param versions An array of services implementing IVersionedService
|
|
20
|
+
*/
|
|
5
21
|
constructor(versions: IVersionedService[]);
|
|
22
|
+
/**
|
|
23
|
+
* Get all services
|
|
24
|
+
*/
|
|
6
25
|
getAll(): IVersionedService[];
|
|
26
|
+
/**
|
|
27
|
+
* Retrieve the services which are compatible with the requested protocol version
|
|
28
|
+
*/
|
|
7
29
|
getServiceVersions<ProtocolVersion extends number, ProtocolImplementingService = ProtocolVersionServiceMap<ProtocolVersion>>(protocolVersion: ProtocolVersion): ProtocolImplementingService[];
|
|
30
|
+
/**
|
|
31
|
+
* Retrieve a service by version
|
|
32
|
+
*/
|
|
8
33
|
get(version: string): IVersionedService | undefined;
|
|
34
|
+
/**
|
|
35
|
+
* Retrieve the latest service
|
|
36
|
+
*/
|
|
9
37
|
getLatestVersion(): IVersionedService;
|
|
10
38
|
}
|
|
@@ -1,19 +1,47 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.VersionsService = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Service for managing versions of services
|
|
6
|
+
*
|
|
7
|
+
* The VersionsService class is a utility class for services which implement different versions of the protocol, and different versions of their
|
|
8
|
+
* own service. For example, say you have a v1service, v11service, v2service and v21service with versions 1.0, 1.1, 2.0 and 2.1 respectively.
|
|
9
|
+
* The VersionsService class can be used to manage these services:
|
|
10
|
+
*
|
|
11
|
+
* const versionsService = new VersionsService([v1service, v11service, v2service, v21service]);
|
|
12
|
+
* versionsService.getLatestVersion(); // v21service
|
|
13
|
+
* versionsService.getServiceVersions(1); // [v1service, v11service]
|
|
14
|
+
* versionsService.getServiceVersions(2); // [v2service, v21service]
|
|
15
|
+
* versionsService.get('1.1'); // v11service
|
|
16
|
+
*/
|
|
4
17
|
class VersionsService {
|
|
18
|
+
/**
|
|
19
|
+
* @param versions An array of services implementing IVersionedService
|
|
20
|
+
*/
|
|
5
21
|
constructor(versions) {
|
|
6
22
|
this.versions = versions;
|
|
7
23
|
}
|
|
24
|
+
/**
|
|
25
|
+
* Get all services
|
|
26
|
+
*/
|
|
8
27
|
getAll() {
|
|
9
28
|
return this.versions;
|
|
10
29
|
}
|
|
30
|
+
/**
|
|
31
|
+
* Retrieve the services which are compatible with the requested protocol version
|
|
32
|
+
*/
|
|
11
33
|
getServiceVersions(protocolVersion) {
|
|
12
34
|
return this.versions.filter((service) => service.supportsProtocol(protocolVersion));
|
|
13
35
|
}
|
|
36
|
+
/**
|
|
37
|
+
* Retrieve a service by version
|
|
38
|
+
*/
|
|
14
39
|
get(version) {
|
|
15
40
|
return this.versions.find((service) => service.version === version);
|
|
16
41
|
}
|
|
42
|
+
/**
|
|
43
|
+
* Retrieve the latest service
|
|
44
|
+
*/
|
|
17
45
|
getLatestVersion() {
|
|
18
46
|
return this.versions[this.versions.length - 1];
|
|
19
47
|
}
|
|
@@ -25,6 +25,9 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
26
|
exports.criteriaSetIdParamSchema = void 0;
|
|
27
27
|
const yup = __importStar(require("yup"));
|
|
28
|
+
/**
|
|
29
|
+
* Validates the criteriaSetId parameter for endpoints which use it
|
|
30
|
+
*/
|
|
28
31
|
exports.criteriaSetIdParamSchema = yup.object({
|
|
29
32
|
params: yup.object({
|
|
30
33
|
criteriaSetId: yup.string()
|
|
@@ -25,6 +25,9 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
26
|
exports.downloadMatrixBodySchema = void 0;
|
|
27
27
|
const yup = __importStar(require("yup"));
|
|
28
|
+
/**
|
|
29
|
+
* Validates the request body for the download matrix endpoints
|
|
30
|
+
*/
|
|
28
31
|
exports.downloadMatrixBodySchema = yup.object({
|
|
29
32
|
body: yup.object({
|
|
30
33
|
parameters: yup.object().required(),
|
|
@@ -25,6 +25,9 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
26
|
exports.versionParamSchema = void 0;
|
|
27
27
|
const yup = __importStar(require("yup"));
|
|
28
|
+
/**
|
|
29
|
+
* Validates the version parameter for endpoints which use it
|
|
30
|
+
*/
|
|
28
31
|
exports.versionParamSchema = yup.object({
|
|
29
32
|
params: yup.object({
|
|
30
33
|
version: yup.string()
|
|
@@ -1,9 +1,30 @@
|
|
|
1
1
|
import { CriteriaTree, Metadata, StreamMatrixResponse, TaskItemValueMap } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* Interface for services which implement the v1 protocol
|
|
4
|
+
*/
|
|
2
5
|
export interface IProtocolV1Service {
|
|
6
|
+
/**
|
|
7
|
+
* Specific version of this service, SemVer-formatted
|
|
8
|
+
*/
|
|
3
9
|
version: string;
|
|
10
|
+
/**
|
|
11
|
+
* Get the criteria tree for the given criteria set ID and combination of parameters
|
|
12
|
+
*/
|
|
4
13
|
getCriteriaTree(criteriaSetId: string, rawParameters: Record<string, unknown>): Promise<CriteriaTree>;
|
|
14
|
+
/**
|
|
15
|
+
* Validate the given parameters for the given criteria set ID
|
|
16
|
+
*/
|
|
5
17
|
validateParameters<RequestParameters>(criteriaSetId: string, parameters: RequestParameters): void;
|
|
18
|
+
/**
|
|
19
|
+
* Stream the matrix for the given criteria set ID, parameter combination and value map
|
|
20
|
+
*/
|
|
6
21
|
streamMatrix(criteriaSetId: string, rawParameters: Record<string, unknown>, values: TaskItemValueMap): Promise<StreamMatrixResponse>;
|
|
7
|
-
|
|
22
|
+
/**
|
|
23
|
+
* Get the metadata of all criteria sets supported by this service
|
|
24
|
+
*/
|
|
25
|
+
getCriteriaSetMetadataList(): Metadata[];
|
|
26
|
+
/**
|
|
27
|
+
* Get the JSON schema for the given criteria set ID
|
|
28
|
+
*/
|
|
8
29
|
getParametersJsonSchema(criteriaSetId: string): Record<string, unknown>;
|
|
9
30
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import { Stream } from 'stream';
|
|
3
3
|
import { Metadata, TaskItemValue } from './criteria';
|
|
4
|
-
export type
|
|
4
|
+
export type MetadataResponse<Parameters extends ParameterCombination = ParameterCombination> = {
|
|
5
5
|
protocol: 1;
|
|
6
6
|
metadata: Metadata;
|
|
7
7
|
parameters: Parameters;
|
package/package.json
CHANGED