@openframe-org/criteria-set-protocol 1.0.0 → 1.0.2

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 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
  }
@@ -1,4 +1,7 @@
1
1
  import * as yup from 'yup';
2
+ /**
3
+ * Validates the criteriaSetId parameter for endpoints which use it
4
+ */
2
5
  export declare const criteriaSetIdParamSchema: yup.ObjectSchema<{
3
6
  params: {
4
7
  criteriaSetId: string;
@@ -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()
@@ -1,4 +1,7 @@
1
1
  import * as yup from 'yup';
2
+ /**
3
+ * Validates the request body for the download matrix endpoints
4
+ */
2
5
  export declare const downloadMatrixBodySchema: yup.ObjectSchema<{
3
6
  body: {
4
7
  values: {};
@@ -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(),
@@ -1,3 +1,3 @@
1
1
  export * from './criteria-set-id-param-schema';
2
- export * from './download-matrix-body-schema';
2
+ export * from './tree-and-matrix-body-schema';
3
3
  export * from './version-param-schema';
@@ -15,5 +15,5 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./criteria-set-id-param-schema"), exports);
18
- __exportStar(require("./download-matrix-body-schema"), exports);
18
+ __exportStar(require("./tree-and-matrix-body-schema"), exports);
19
19
  __exportStar(require("./version-param-schema"), exports);
@@ -0,0 +1,17 @@
1
+ import * as yup from 'yup';
2
+ /**
3
+ * Validates the request body for the tree and matrix endpoints
4
+ */
5
+ export declare const treeAndMatrixBodySchema: yup.ObjectSchema<{
6
+ body: {
7
+ locale?: string | undefined;
8
+ values: {};
9
+ parameters: {};
10
+ };
11
+ }, yup.AnyObject, {
12
+ body: {
13
+ locale: undefined;
14
+ parameters: {};
15
+ values: {};
16
+ };
17
+ }, "">;
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.treeAndMatrixBodySchema = void 0;
27
+ const yup = __importStar(require("yup"));
28
+ /**
29
+ * Validates the request body for the tree and matrix endpoints
30
+ */
31
+ exports.treeAndMatrixBodySchema = yup.object({
32
+ body: yup.object({
33
+ locale: yup.string(),
34
+ parameters: yup.object().required(),
35
+ values: yup.object()
36
+ })
37
+ });
@@ -1,4 +1,7 @@
1
1
  import * as yup from 'yup';
2
+ /**
3
+ * Validates the version parameter for endpoints which use it
4
+ */
2
5
  export declare const versionParamSchema: yup.ObjectSchema<{
3
6
  params: {
4
7
  version: string;
@@ -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
- getMatrixMetadataList(): Metadata[];
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,14 +1,15 @@
1
1
  /// <reference types="node" />
2
2
  import { Stream } from 'stream';
3
3
  import { Metadata, TaskItemValue } from './criteria';
4
- export type MetadataSchema<Parameters extends ParameterCombination = ParameterCombination> = {
4
+ export type MetadataResponse<Parameters extends ParameterCombination = ParameterCombination> = {
5
5
  protocol: 1;
6
6
  metadata: Metadata;
7
7
  parameters: Parameters;
8
8
  };
9
9
  export type StringParam<ParamName extends string> = Record<ParamName, string>;
10
10
  export type TaskItemValueMap = Record<string, TaskItemValue>;
11
- export type StreamCriteriaSetMatrixBody = {
11
+ export type TreeAndMatrixRequestBody = {
12
+ locale?: string;
12
13
  parameters: ParameterCombination;
13
14
  values?: TaskItemValueMap;
14
15
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openframe-org/criteria-set-protocol",
3
- "version": "1.0.0",
3
+ "version": "1.0.2",
4
4
  "description": "A protocol and tools for defining and working with criteria sets",
5
5
  "private": false,
6
6
  "author": "Andrés Angulo <aa@openframe.org>",