@skipruntime/helpers 0.0.5 → 0.0.6

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.
@@ -1,61 +1,70 @@
1
1
  import type { Entry, ExternalService, Json } from "@skipruntime/api";
2
+ /**
3
+ * Interface required by `GenericExternalService` for external resources.
4
+ */
2
5
  export interface ExternalResource {
3
- open(params: {
4
- [param: string]: string | number;
5
- }, callbacks: {
6
+ open(params: Json, callbacks: {
6
7
  update: (updates: Entry<Json, Json>[], isInit: boolean) => void;
7
8
  error: (error: Json) => void;
8
9
  loading: () => void;
9
10
  }): void;
10
- close(params: {
11
- [param: string]: string | number;
12
- }): void;
11
+ close(params: Json): void;
13
12
  }
13
+ /**
14
+ * A generic external service providing external resources.
15
+ *
16
+ * `GenericExternalService` provides an implementation of `ExternalService` for external resources by lifting the `open` and `close` operations from `ExternalResource` to the `subscribe` and `unsubscribe` operations required by `ExternalService`.
17
+ */
14
18
  export declare class GenericExternalService implements ExternalService {
15
19
  private readonly resources;
20
+ /**
21
+ * @param resources - Association of resource names to `ExternalResource`s.
22
+ */
16
23
  constructor(resources: {
17
24
  [name: string]: ExternalResource;
18
25
  });
19
- subscribe(resourceName: string, params: {
20
- [param: string]: string | number;
21
- }, callbacks: {
26
+ subscribe(resourceName: string, params: Json, callbacks: {
22
27
  update: (updates: Entry<Json, Json>[], isInit: boolean) => void;
23
28
  error: (error: Json) => void;
24
29
  loading: () => void;
25
30
  }): void;
26
- unsubscribe(resourceName: string, params: {
27
- [param: string]: string;
28
- }): void;
31
+ unsubscribe(resourceName: string, params: Json): void;
29
32
  shutdown(): void;
30
33
  }
31
34
  export declare class TimerResource implements ExternalResource {
32
35
  private readonly intervals;
33
- open(params: {
34
- [param: string]: string | number;
35
- }, callbacks: {
36
+ open(params: Json, callbacks: {
36
37
  update: (updates: Entry<Json, Json>[], isInit: boolean) => void;
37
38
  error: (error: Json) => void;
38
39
  loading: () => void;
39
40
  }): void;
40
- close(params: {
41
- [param: string]: string | number;
42
- }): void;
41
+ close(params: Json): void;
43
42
  }
43
+ /**
44
+ * An external resource that is refreshed at some polling interval.
45
+ *
46
+ * @typeParam S - Type of data received from external resource.
47
+ * @typeParam K - Type of keys.
48
+ * @typeParam V - Type of values.
49
+ */
44
50
  export declare class Polled<S extends Json, K extends Json, V extends Json> implements ExternalResource {
45
51
  private readonly url;
46
52
  private readonly duration;
47
53
  private readonly conv;
54
+ private readonly encodeParams;
48
55
  private readonly intervals;
49
- constructor(url: string, duration: number, conv: (data: S) => Entry<K, V>[]);
50
- open(params: {
51
- [param: string]: string | number;
52
- }, callbacks: {
56
+ /**
57
+ * @param url - HTTP endpoint of external resource to poll.
58
+ * @param duration - Refresh interval, in milliseconds.
59
+ * @param conv - Function to convert data of type `S` received from external resource to `key`-`value` entries.
60
+ * @param encodeParams - Function to use to encode params of type `Json` for external resource request.
61
+ */
62
+ constructor(url: string, duration: number, conv: (data: S) => Entry<K, V>[], encodeParams?: (params: Json) => string);
63
+ open(params: Json, callbacks: {
53
64
  update: (updates: Entry<Json, Json>[], isInit: boolean) => void;
54
65
  error: (error: Json) => void;
55
66
  loading: () => void;
56
67
  }): void;
57
- close(params: {
58
- [param: string]: string | number;
59
- }): void;
68
+ close(params: Json): void;
60
69
  }
61
70
  //# sourceMappingURL=external.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"external.d.ts","sourceRoot":"","sources":["../src/external.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,eAAe,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAGrE,MAAM,WAAW,gBAAgB;IAC/B,IAAI,CACF,MAAM,EAAE;QAAE,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,CAAA;KAAE,EAC5C,SAAS,EAAE;QACT,MAAM,EAAE,CAAC,OAAO,EAAE,KAAK,CAAC,IAAI,EAAE,IAAI,CAAC,EAAE,EAAE,MAAM,EAAE,OAAO,K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,CAAC;QAChE,KAAK,EAAE,CAAC,KAAK,EAAE,IAAI,KAAK,IAAI,CAAC;QAC7B,OAAO,EAAE,MAAM,IAAI,CAAC;KACrB;IAsBH,KAAK,CAAC,MAAM,EAAE,IAAI,GAAG,IAAI;CAQ1B;AAaD;;;;;;GAMG;AACH,qBAAa,MAAM,CAAC,CAAC,SAAS,IAAI,EAAE,CAAC,SAAS,IAAI,EAAE,CAAC,SAAS,IAAI,CAChE,YAAW,gBAAgB;IAWzB,OAAO,CAAC,QAAQ,CAAC,GAAG;IACpB,OAAO,CAAC,QAAQ,CAAC,QAAQ;IACzB,OAAO,CAAC,QAAQ,CAAC,IAAI;IACrB,OAAO,CAAC,QAAQ,CAAC,YAAY;IAZ/B,OAAO,CAAC,QAAQ,CAAC,SAAS,CAA8B;IAExD;;;;;OAKG;gBAEgB,GAAG,EAAE,MAAM,EACX,QAAQ,EAAE,MAAM,EAChB,IAAI,EAAE,CAAC,IAAI,EAAE,CAAC,KAAK,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,EAChC,YAAY,GAAE,CAC7B,MAAM,EAAE,IAAI,KACT,MAA4B;IAGnC,IAAI,CACF,MAAM,EAAE,IAAI,EACZ,SAAS,EAAE;QACT,MAAM,EAAE,CAAC,OAAO,EAAE,KAAK,CAAC,IAAI,EAAE,IAAI,CAAC,EAAE,EAAE,MAAM,EAAE,OAAO,KAAK,IAAI,CAAC;QAChE,KAAK,EAAE,CAAC,KAAK,EAAE,IAAI,KAAK,IAAI,CAAC;QAC7B,OAAO,EAAE,MAAM,IAAI,CAAC;KACrB,GACA,IAAI;IAkBP,KAAK,CAAC,MAAM,EAAE,IAAI,GAAG,IAAI;CAM1B"}
package/dist/external.js CHANGED
@@ -1,5 +1,13 @@
1
1
  import { fetchJSON } from "./rest.js";
2
+ /**
3
+ * A generic external service providing external resources.
4
+ *
5
+ * `GenericExternalService` provides an implementation of `ExternalService` for external resources by lifting the `open` and `close` operations from `ExternalResource` to the `subscribe` and `unsubscribe` operations required by `ExternalService`.
6
+ */
2
7
  export class GenericExternalService {
8
+ /**
9
+ * @param resources - Association of resource names to `ExternalResource`s.
10
+ */
3
11
  constructor(resources) {
4
12
  this.resources = resources;
5
13
  }
@@ -54,21 +62,44 @@ export class TimerResource {
54
62
  }
55
63
  }
56
64
  }
65
+ function defaultParamEncoder(params) {
66
+ if (typeof params == "object") {
67
+ const queryParams = {};
68
+ for (const [key, value] of Object.entries(params)) {
69
+ if (typeof value == "object")
70
+ queryParams[key] = JSON.stringify(value);
71
+ else
72
+ queryParams[key] = value.toString();
73
+ }
74
+ return new URLSearchParams(queryParams).toString();
75
+ }
76
+ else
77
+ return `params=${JSON.stringify(params)}`;
78
+ }
79
+ /**
80
+ * An external resource that is refreshed at some polling interval.
81
+ *
82
+ * @typeParam S - Type of data received from external resource.
83
+ * @typeParam K - Type of keys.
84
+ * @typeParam V - Type of values.
85
+ */
57
86
  export class Polled {
58
- constructor(url, duration, conv) {
87
+ /**
88
+ * @param url - HTTP endpoint of external resource to poll.
89
+ * @param duration - Refresh interval, in milliseconds.
90
+ * @param conv - Function to convert data of type `S` received from external resource to `key`-`value` entries.
91
+ * @param encodeParams - Function to use to encode params of type `Json` for external resource request.
92
+ */
93
+ constructor(url, duration, conv, encodeParams = defaultParamEncoder) {
59
94
  this.url = url;
60
95
  this.duration = duration;
61
96
  this.conv = conv;
97
+ this.encodeParams = encodeParams;
62
98
  this.intervals = new Map();
63
99
  }
64
100
  open(params, callbacks) {
65
101
  this.close(params);
66
- const queryParams = {};
67
- for (const [key, value] of Object.entries(params)) {
68
- queryParams[key] = value.toString();
69
- }
70
- const strParams = new URLSearchParams(queryParams).toString();
71
- const url = `${this.url}?${strParams}`;
102
+ const url = `${this.url}?${this.encodeParams(params)}`;
72
103
  const call = () => {
73
104
  callbacks.loading();
74
105
  fetchJSON(url, "GET", {})
@@ -91,9 +122,13 @@ export class Polled {
91
122
  }
92
123
  }
93
124
  function toId(params) {
94
- const strparams = Object.entries(params)
95
- .map(([key, value]) => `${key}:${value.toString()}`)
96
- .sort();
97
- return `[${strparams.join(",")}]`;
125
+ if (typeof params == "object") {
126
+ const strparams = Object.entries(params)
127
+ .map(([key, value]) => `${key}:${btoa(JSON.stringify(value))}`)
128
+ .sort();
129
+ return `[${strparams.join(",")}]`;
130
+ }
131
+ else
132
+ return btoa(JSON.stringify(params));
98
133
  }
99
134
  //# sourceMappingURL=external.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"external.js","sourceRoot":"","sources":["../src/external.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAetC,MAAM,OAAO,sBAAsB;IACjC,YACmB,SAA+C;QAA/C,cAAS,GAAT,SAAS,CAAsC;IAC/D,CAAC;IAEJ,SAAS,CACP,YAAoB,EACpB,MAA4C,EAC5C,SAIC;QAED,MAAM,QAAQ,GAAG,IAAI,CAAC,SAAS,CAAC,YAAY,CAE/B,CAAC;QACd,IAAI,CAAC,QAAQ,EAAE,CAAC;YACd,MAAM,IAAI,KAAK,CAAC,2BAA2B,YAAY,GAAG,CAAC,CAAC;QAC9D,CAAC;QACD,QAAQ,CAAC,IAAI,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC;IACnC,CAAC;IAED,WAAW,CAAC,YAAoB,EAAE,MAAmC;QACnE,MAAM,QAAQ,GAAG,IAAI,CAAC,SAAS,CAAC,YAAY,CAE/B,CAAC;QACd,IAAI,CAAC,QAAQ,EAAE,CAAC;YACd,MAAM,IAAI,KAAK,CAAC,2BAA2B,YAAY,GAAG,CAAC,CAAC;QAC9D,CAAC;QACD,QAAQ,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;IACzB,CAAC;IAED,QAAQ;QACN,OAAO;IACT,CAAC;CACF;AAID,MAAM,OAAO,aAAa;IAA1B;QACmB,cAAS,GAAG,IAAI,GAAG,EAAuC,CAAC;IAsC9E,CAAC;IApCC,IAAI,CACF,MAA4C,EAC5C,SAIC;QAED,MAAM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AAC;IACrE,CAAC;IAED,KAAK,CAAC,MAAY;QAChB,MAAM,QAAQ,GAAG,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC;QAClD,IAAI,QAAQ,EAAE,CAAC;YACb,aAAa,CAAC,QAAQ,CAAC,CAAC;QAC1B,CAAC;IACH,CAAC;CACF;AAED,SAAS,IAAI,CAAC,MAAY;IACxB,IAAI,OAAO,MAAM,IAAI,QAAQ,EAAE,CAAC;QAC9B,MAAM,SAAS,GAAG,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC;aACrC,GAAG,CAAC,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,EAAE,EAAE,CAAC,GAAG,GAAG,IAAI,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC;aAC9D,IAAI,EAAE,CAAC;QACV,OAAO,IAAI,SAAS,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC;IACpC,CAAC;;QAAM,OAAO,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,CAAC;AAC7C,CAAC"}
package/dist/index.d.ts CHANGED
@@ -1,3 +1,9 @@
1
+ /**
2
+ * This package contains items that may be useful for working with the Skip framework, but are not strictly necessary.
3
+ *
4
+ * @packageDocumentation
5
+ */
1
6
  export { type ExternalResource, GenericExternalService, Polled, } from "./external.js";
2
- export { fetchJSON, SkipServiceBroker } from "./rest.js";
7
+ export { SkipServiceBroker, fetchJSON, type Entrypoint } from "./rest.js";
8
+ export { Count, CountMapper, Max, Min, SkipExternalService, Sum, } from "@skipruntime/core";
3
9
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,gBAAgB,EACrB,sBAAsB,EACtB,MAAM,GACP,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,SAAS,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EACL,KAAK,gBAAgB,EACrB,sBAAsB,EACtB,MAAM,GACP,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,iBAAiB,EAAE,SAAS,EAAE,KAAK,UAAU,EAAE,MAAM,WAAW,CAAC;AAC1E,OAAO,EACL,KAAK,EACL,WAAW,EACX,GAAG,EACH,GAAG,EACH,mBAAmB,EACnB,GAAG,GACJ,MAAM,mBAAmB,CAAC"}
package/dist/index.js CHANGED
@@ -1,3 +1,9 @@
1
+ /**
2
+ * This package contains items that may be useful for working with the Skip framework, but are not strictly necessary.
3
+ *
4
+ * @packageDocumentation
5
+ */
1
6
  export { GenericExternalService, Polled, } from "./external.js";
2
- export { fetchJSON, SkipServiceBroker } from "./rest.js";
7
+ export { SkipServiceBroker, fetchJSON } from "./rest.js";
8
+ export { Count, CountMapper, Max, Min, SkipExternalService, Sum, } from "@skipruntime/core";
3
9
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,sBAAsB,EACtB,MAAM,GACP,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,SAAS,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAEL,sBAAsB,EACtB,MAAM,GACP,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,iBAAiB,EAAE,SAAS,EAAmB,MAAM,WAAW,CAAC;AAC1E,OAAO,EACL,KAAK,EACL,WAAW,EACX,GAAG,EACH,GAAG,EACH,mBAAmB,EACnB,GAAG,GACJ,MAAM,mBAAmB,CAAC"}
package/dist/rest.d.ts CHANGED
@@ -1,15 +1,16 @@
1
1
  import type { Json, Entry } from "@skipruntime/api";
2
+ import type { Entrypoint } from "@skipruntime/core";
3
+ export type { Entrypoint };
2
4
  /**
3
- * An entry point of a Skip reactive service.
5
+ * Perform an HTTP fetch where input and output data is `Json`.
4
6
  *
5
- * URLs for the service's control and streaming APIs can be constructed from an `Entrypoint`.
7
+ * @typeParam V - Type response is *assumed* to have.
8
+ * @param url - URL from which to fetch.
9
+ * @param method - HTTP method of request.
10
+ * @param headers - Additional headers to add to request.
11
+ * @param data - Data to convert to JSON and send in request body.
12
+ * @returns Response parsed as JSON, and headers.
6
13
  */
7
- export type Entrypoint = {
8
- host: string;
9
- streaming_port: number;
10
- control_port: number;
11
- secured?: boolean;
12
- };
13
14
  export declare function fetchJSON<V extends Json>(url: string, method?: "POST" | "GET" | "PUT" | "PATCH" | "HEAD" | "DELETE", headers?: {
14
15
  [header: string]: string;
15
16
  }, data?: Json): Promise<[V | null, Headers]>;
@@ -23,78 +24,90 @@ export declare class SkipServiceBroker {
23
24
  private readonly entrypoint;
24
25
  /**
25
26
  * Construct a broker for a Skip service at the given entry point.
26
- * @param entrypoint - entry point of backing service
27
- * @returns - method-call broker to service
27
+ *
28
+ * @param entrypoint - Entry point of backing service.
29
+ * @returns Method-call broker to service.
28
30
  */
29
31
  constructor(entrypoint?: Entrypoint);
30
32
  /**
31
33
  * Read the entire contents of a resource.
32
34
  *
33
- * @param resource - name of resource, must be a key of the `resources` field of the `SkipService` running at `entrypoint`
34
- * @param params - resource instance parameters
35
- * @returns - all entries in resource
35
+ * @typeParam K - Type of keys.
36
+ * @typeParam V - Type of values.
37
+ * @param resource - Name of resource, must be a key of the `resources` field of the `SkipService` running at `entrypoint`.
38
+ * @param params - Resource instance parameters.
39
+ * @returns All entries in resource.
36
40
  */
37
- getAll<K extends Json, V extends Json>(resource: string, params: {
38
- [param: string]: string;
39
- }): Promise<Entry<K, V>[]>;
41
+ getAll<K extends Json, V extends Json>(resource: string, params: Json): Promise<Entry<K, V>[]>;
40
42
  /**
41
43
  * Read the values a resource associates with a single key.
42
- * @param resource - name of resource, must be a key of the `resources` field of the `SkipService` running at `entrypoint`
43
- * @param params - resource instance parameters
44
- * @param key - key to read
45
- * @returns - the values associated to the key
44
+ *
45
+ * @typeParam K - Type of keys.
46
+ * @typeParam V - Type of values.
47
+ * @param resource - Name of resource, must be a key of the `resources` field of the `SkipService` running at `entrypoint`.
48
+ * @param params - Resource instance parameters.
49
+ * @param key - Key to read.
50
+ * @returns The values associated to the key.
46
51
  */
47
- getArray<V extends Json>(resource: string, params: {
48
- [param: string]: string;
49
- }, key: string): Promise<V[]>;
52
+ getArray<K extends Json, V extends Json>(resource: string, params: Json, key: K): Promise<V[]>;
50
53
  /**
51
54
  * Read the single value a resource associates with a key.
52
- * @param resource - name of resource, must be a key of the `resources` field of the `SkipService` running at `entrypoint`
53
- * @param params - resource instance parameters
54
- * @param key - key to read
55
- * @returns - the value associated to the key
56
- * @throws {NonUniqueValueException} when the key is associated to either zero or multiple values
55
+ *
56
+ * @typeParam K - Type of keys.
57
+ * @typeParam V - Type of values.
58
+ * @param resource - Name of resource, must be a key of the `resources` field of the `SkipService` running at `entrypoint`.
59
+ * @param params - Resource instance parameters.
60
+ * @param key - Key to read.
61
+ * @returns The value associated to the key.
62
+ * @throws `NonUniqueValueException` when the key is associated to either zero or multiple values.
57
63
  */
58
- getUnique<V extends Json>(resource: string, params: {
59
- [param: string]: string;
60
- }, key: string): Promise<V>;
64
+ getUnique<K extends Json, V extends Json>(resource: string, params: Json, key: K): Promise<V>;
61
65
  /**
62
66
  * Write the values for a single key in a collection.
63
- * @param collection - name of the input collection to update, must be a key of the `Inputs` type parameter of the `SkipService` running at `entrypoint`
64
- * @param key - key of entry to write
65
- * @param values - values of entry to write
67
+ *
68
+ * @typeParam K - Type of keys.
69
+ * @typeParam V - Type of values.
70
+ * @param collection - Name of the input collection to update, must be a key of the `Inputs` type parameter of the `SkipService` running at `entrypoint`.
71
+ * @param key - Key of entry to write.
72
+ * @param values - Values of entry to write.
66
73
  * @returns {void}
67
74
  */
68
75
  put<K extends Json, V extends Json>(collection: string, key: K, values: V[]): Promise<void>;
69
76
  /**
70
77
  * Write multiple entries to a collection.
71
- * @param collection - name of the input collection to update, must be a key of the `Inputs` type parameter of the `SkipService` running at `entrypoint`
72
- * @param entries - entries to write
78
+ *
79
+ * @typeParam K - Type of keys.
80
+ * @typeParam V - Type of values.
81
+ * @param collection - Name of the input collection to update, must be a key of the `Inputs` type parameter of the `SkipService` running at `entrypoint`.
82
+ * @param entries - Entries to write.
73
83
  * @returns {void}
74
84
  */
75
85
  patch<K extends Json, V extends Json>(collection: string, entries: Entry<K, V>[]): Promise<void>;
76
86
  /**
77
87
  * Remove all values associated with a key in a collection.
78
- * @param collection - name of the input collection to update, must be a key of the `Inputs` type parameter of the `SkipService` running at `entrypoint`
79
- * @param key - key of entry to delete
88
+ *
89
+ * @typeParam K - Type of keys.
90
+ * @param collection - Name of the input collection to update, must be a key of the `Inputs` type parameter of the `SkipService` running at `entrypoint`.
91
+ * @param key - Key of entry to delete.
80
92
  * @returns {void}
81
93
  */
82
94
  deleteKey<K extends Json>(collection: string, key: K): Promise<void>;
83
95
  /**
84
96
  * Create a resource instance UUID.
85
- * @param resource - name of resource, must be a key of the `resources` field of the `SkipService` running at `entrypoint`
86
- * @param params - resource instance parameters
87
- * @returns - UUID that can be used to subscribe to updates to resource instance
97
+ *
98
+ * @typeParam K - Type of keys.
99
+ * @typeParam V - Type of values.
100
+ * @param resource - Name of resource, must be a key of the `resources` field of the `SkipService` running at `entrypoint`.
101
+ * @param params - Resource instance parameters.
102
+ * @returns UUID that can be used to subscribe to updates to resource instance.
88
103
  */
89
- getStreamUUID(resource: string, params?: {
90
- [param: string]: string;
91
- }): Promise<string>;
104
+ getStreamUUID(resource: string, params?: Json): Promise<string>;
92
105
  /**
93
106
  * Destroy a resource instance.
94
107
  *
95
108
  * Under normal circumstances, resource instances are deleted automatically after some period of inactivity; this method enables immediately deleting live streams under exceptional circumstances.
96
109
  *
97
- * @param uuid - resource instance UUID
110
+ * @param uuid - Resource instance UUID.
98
111
  * @returns {void}
99
112
  */
100
113
  deleteUUID(uuid: string): Promise<void>;
@@ -1 +1 @@
1
- {"version":3,"file":"rest.d.ts","sourceRoot":"","sources":["../src/rest.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AAGpD;;;;GAIG;AACH,MAAM,MAAM,UAAU,GAAG;IACvB,IAAI,EAAE,MAAM,CAAC;IACb,cAAc,EAAE,MAAM,CAAC;IACvB,YAAY,EAAE,MAAM,CAAC;IACrB,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB,CAAC;AAQF,wBAAsB,SAAS,CAAC,CAAC,SAAS,IAAI,EAC5C,GAAG,EAAE,MAAM,EACX,MAAM,GAAE,MAAM,GAAG,KAAK,GAAG,KAAK,GAAG,OAAO,GAAG,MAAM,GAAG,QAAgB,EACpE,OAAO,GAAE;IAAE,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAAA;CAAO,EAC1C,IAAI,CAAC,EAAE,IAAI,GACV,OAAO,CAAC,CAAC,CAAC,GAAG,IAAI,EAAE,OAAO,CAAC,CAAC,CAqB9B;AAED;;;;;GAKG;AACH,qBAAa,iBAAiB;IAC5B,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAS;IAEpC;;;;OAIG;gBAED,UAAU,GAAE,UAIX;IAKH;;;;;;OAMG;IACG,MAAM,CAAC,CAAC,SAAS,IAAI,EAAE,CAAC,SAAS,IAAI,EACzC,QAAQ,EAAE,MAAM,EAChB,MAAM,EAAE;QAAE,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAAA;KAAE,GAClC,OAAO,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC;IAUzB;;;;;;OAMG;IACG,QAAQ,CAAC,CAA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EAAE,CAAC,SAAS,IAAI,EACtC,UAAU,EAAE,MAAM,EAClB,GAAG,EAAE,CAAC,EACN,MAAM,EAAE,CAAC,EAAE,GACV,OAAO,CAAC,IAAI,CAAC;IAIhB;;;;;;;;OAQG;IACG,KAAK,CAAC,CAAC,SAAS,IAAI,EAAE,CAAC,SAAS,IAAI,EACxC,UAAU,EAAE,MAAM,EAClB,OAAO,EAAE,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,GACrB,OAAO,CAAC,IAAI,CAAC;IAShB;;;;;;;OAOG;IACG,SAAS,CAAC,CAAC,SAAS,IAAI,EAAE,UAAU,EAAE,MAAM,EAAE,GAAG,EAAE,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;IAI1E;;;;;;;;OAQG;IACG,aAAa,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,GAAE,IAAS,GAAG,OAAO,CAAC,MAAM,CAAC;IAQzE;;;;;;;OAOG;IACG,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;CAG9C"}
package/dist/rest.js CHANGED
@@ -4,6 +4,16 @@ function toHttp(entrypoint) {
4
4
  return `https://${entrypoint.host}:${entrypoint.control_port}`;
5
5
  return `http://${entrypoint.host}:${entrypoint.control_port}`;
6
6
  }
7
+ /**
8
+ * Perform an HTTP fetch where input and output data is `Json`.
9
+ *
10
+ * @typeParam V - Type response is *assumed* to have.
11
+ * @param url - URL from which to fetch.
12
+ * @param method - HTTP method of request.
13
+ * @param headers - Additional headers to add to request.
14
+ * @param data - Data to convert to JSON and send in request body.
15
+ * @returns Response parsed as JSON, and headers.
16
+ */
7
17
  export async function fetchJSON(url, method = "GET", headers = {}, data) {
8
18
  const body = data ? JSON.stringify(data) : undefined;
9
19
  const response = await fetch(url, {
@@ -34,8 +44,9 @@ export async function fetchJSON(url, method = "GET", headers = {}, data) {
34
44
  export class SkipServiceBroker {
35
45
  /**
36
46
  * Construct a broker for a Skip service at the given entry point.
37
- * @param entrypoint - entry point of backing service
38
- * @returns - method-call broker to service
47
+ *
48
+ * @param entrypoint - Entry point of backing service.
49
+ * @returns Method-call broker to service.
39
50
  */
40
51
  constructor(entrypoint = {
41
52
  host: "localhost",
@@ -47,32 +58,40 @@ export class SkipServiceBroker {
47
58
  /**
48
59
  * Read the entire contents of a resource.
49
60
  *
50
- * @param resource - name of resource, must be a key of the `resources` field of the `SkipService` running at `entrypoint`
51
- * @param params - resource instance parameters
52
- * @returns - all entries in resource
61
+ * @typeParam K - Type of keys.
62
+ * @typeParam V - Type of values.
63
+ * @param resource - Name of resource, must be a key of the `resources` field of the `SkipService` running at `entrypoint`.
64
+ * @param params - Resource instance parameters.
65
+ * @returns All entries in resource.
53
66
  */
54
67
  async getAll(resource, params) {
55
- const [data, _headers] = await fetchJSON(`${this.entrypoint}/v1/snapshot`, "POST", {}, { resource, params });
68
+ const [data, _headers] = await fetchJSON(`${this.entrypoint}/v1/snapshot/${resource}`, "POST", {}, params);
56
69
  return data ?? [];
57
70
  }
58
71
  /**
59
72
  * Read the values a resource associates with a single key.
60
- * @param resource - name of resource, must be a key of the `resources` field of the `SkipService` running at `entrypoint`
61
- * @param params - resource instance parameters
62
- * @param key - key to read
63
- * @returns - the values associated to the key
73
+ *
74
+ * @typeParam K - Type of keys.
75
+ * @typeParam V - Type of values.
76
+ * @param resource - Name of resource, must be a key of the `resources` field of the `SkipService` running at `entrypoint`.
77
+ * @param params - Resource instance parameters.
78
+ * @param key - Key to read.
79
+ * @returns The values associated to the key.
64
80
  */
65
81
  async getArray(resource, params, key) {
66
- const [data, _headers] = await fetchJSON(`${this.entrypoint}/v1/snapshot`, "POST", {}, { resource, key, params });
82
+ const [data, _headers] = await fetchJSON(`${this.entrypoint}/v1/snapshot/${resource}`, "POST", {}, { key, params });
67
83
  return data ?? [];
68
84
  }
69
85
  /**
70
86
  * Read the single value a resource associates with a key.
71
- * @param resource - name of resource, must be a key of the `resources` field of the `SkipService` running at `entrypoint`
72
- * @param params - resource instance parameters
73
- * @param key - key to read
74
- * @returns - the value associated to the key
75
- * @throws {NonUniqueValueException} when the key is associated to either zero or multiple values
87
+ *
88
+ * @typeParam K - Type of keys.
89
+ * @typeParam V - Type of values.
90
+ * @param resource - Name of resource, must be a key of the `resources` field of the `SkipService` running at `entrypoint`.
91
+ * @param params - Resource instance parameters.
92
+ * @param key - Key to read.
93
+ * @returns The value associated to the key.
94
+ * @throws `NonUniqueValueException` when the key is associated to either zero or multiple values.
76
95
  */
77
96
  async getUnique(resource, params, key) {
78
97
  return this.getArray(resource, params, key).then((values) => {
@@ -83,9 +102,12 @@ export class SkipServiceBroker {
83
102
  }
84
103
  /**
85
104
  * Write the values for a single key in a collection.
86
- * @param collection - name of the input collection to update, must be a key of the `Inputs` type parameter of the `SkipService` running at `entrypoint`
87
- * @param key - key of entry to write
88
- * @param values - values of entry to write
105
+ *
106
+ * @typeParam K - Type of keys.
107
+ * @typeParam V - Type of values.
108
+ * @param collection - Name of the input collection to update, must be a key of the `Inputs` type parameter of the `SkipService` running at `entrypoint`.
109
+ * @param key - Key of entry to write.
110
+ * @param values - Values of entry to write.
89
111
  * @returns {void}
90
112
  */
91
113
  async put(collection, key, values) {
@@ -93,8 +115,11 @@ export class SkipServiceBroker {
93
115
  }
94
116
  /**
95
117
  * Write multiple entries to a collection.
96
- * @param collection - name of the input collection to update, must be a key of the `Inputs` type parameter of the `SkipService` running at `entrypoint`
97
- * @param entries - entries to write
118
+ *
119
+ * @typeParam K - Type of keys.
120
+ * @typeParam V - Type of values.
121
+ * @param collection - Name of the input collection to update, must be a key of the `Inputs` type parameter of the `SkipService` running at `entrypoint`.
122
+ * @param entries - Entries to write.
98
123
  * @returns {void}
99
124
  */
100
125
  async patch(collection, entries) {
@@ -102,8 +127,10 @@ export class SkipServiceBroker {
102
127
  }
103
128
  /**
104
129
  * Remove all values associated with a key in a collection.
105
- * @param collection - name of the input collection to update, must be a key of the `Inputs` type parameter of the `SkipService` running at `entrypoint`
106
- * @param key - key of entry to delete
130
+ *
131
+ * @typeParam K - Type of keys.
132
+ * @param collection - Name of the input collection to update, must be a key of the `Inputs` type parameter of the `SkipService` running at `entrypoint`.
133
+ * @param key - Key of entry to delete.
107
134
  * @returns {void}
108
135
  */
109
136
  async deleteKey(collection, key) {
@@ -111,15 +138,18 @@ export class SkipServiceBroker {
111
138
  }
112
139
  /**
113
140
  * Create a resource instance UUID.
114
- * @param resource - name of resource, must be a key of the `resources` field of the `SkipService` running at `entrypoint`
115
- * @param params - resource instance parameters
116
- * @returns - UUID that can be used to subscribe to updates to resource instance
141
+ *
142
+ * @typeParam K - Type of keys.
143
+ * @typeParam V - Type of values.
144
+ * @param resource - Name of resource, must be a key of the `resources` field of the `SkipService` running at `entrypoint`.
145
+ * @param params - Resource instance parameters.
146
+ * @returns UUID that can be used to subscribe to updates to resource instance.
117
147
  */
118
148
  async getStreamUUID(resource, params = {}) {
119
- return fetch(`${this.entrypoint}/v1/streams`, {
149
+ return fetch(`${this.entrypoint}/v1/streams/${resource}`, {
120
150
  method: "POST",
121
151
  headers: { "Content-Type": "application/json" },
122
- body: JSON.stringify({ resource, params }),
152
+ body: JSON.stringify(params),
123
153
  }).then((res) => res.text());
124
154
  }
125
155
  /**
@@ -127,7 +157,7 @@ export class SkipServiceBroker {
127
157
  *
128
158
  * Under normal circumstances, resource instances are deleted automatically after some period of inactivity; this method enables immediately deleting live streams under exceptional circumstances.
129
159
  *
130
- * @param uuid - resource instance UUID
160
+ * @param uuid - Resource instance UUID.
131
161
  * @returns {void}
132
162
  */
133
163
  async deleteUUID(uuid) {
package/dist/rest.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"rest.js","sourceRoot":"","sources":["../src/rest.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,uBAAuB,EAAE,MAAM,kBAAkB,CAAC;AAc3D,SAAS,MAAM,CAAC,UAAsB;IACpC,IAAI,UAAU,CAAC,OAAO;QACpB,OAAO,WAAW,UAAU,CAAC,IAAI,IAAI,UAA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G,IAAI,CAAC,UAAU,cAAc,UAAU,EAAE,EAC5C,OAAO,EACP,EAAE,EACF,OAAO,CACR,CAAC;IACJ,CAAC;IAED;;;;;;;OAOG;IACH,KAAK,CAAC,SAAS,CAAiB,UAAkB,EAAE,GAAM;QACxD,OAAO,MAAM,IAAI,CAAC,KAAK,CAAC,UAAU,EAAE,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC;IACnD,CAAC;IAED;;;;;;;;OAQG;IACH,KAAK,CAAC,aAAa,CAAC,QAAgB,EAAE,SAAe,EAAE;QACrD,OAAO,KAAK,CAAC,GAAG,IAAI,CAAC,UAAU,eAAe,QAAQ,EAAE,EAAE;YACxD,MAAM,EAAE,MAAM;YACd,OAAO,EAAE,EAAE,cAAc,EAAE,kBAAkB,EAAE;YAC/C,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC;SAC7B,CAAC,CAAC,IAAI,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC,CAAC;IAC/B,CAAC;IAED;;;;;;;OAOG;IACH,KAAK,CAAC,UAAU,CAAC,IAAY;QAC3B,MAAM,SAAS,CAAC,GAAG,IAAI,CAAC,UAAU,eAAe,IAAI,EAAE,EAAE,QAAQ,CAAC,CAAC;IACrE,CAAC;CACF"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@skipruntime/helpers",
3
- "version": "0.0.5",
3
+ "version": "0.0.6",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": "./dist/index.js",
@@ -21,7 +21,8 @@
21
21
  "dependencies": {
22
22
  "eventsource": "^2.0.2",
23
23
  "express": "^4.21.1",
24
- "@skipruntime/api": "^0.0.4"
24
+ "@skipruntime/core": "^0.0.3",
25
+ "@skipruntime/api": "^0.0.5"
25
26
  },
26
27
  "devDependencies": {
27
28
  "@types/eventsource": "^1.1.15"
package/src/external.ts CHANGED
@@ -1,9 +1,12 @@
1
1
  import type { Entry, ExternalService, Json } from "@skipruntime/api";
2
2
  import { fetchJSON } from "./rest.js";
3
3
 
4
+ /**
5
+ * Interface required by `GenericExternalService` for external resources.
6
+ */
4
7
  export interface ExternalResource {
5
8
  open(
6
- params: { [param: string]: string | number },
9
+ params: Json,
7
10
  callbacks: {
8
11
  update: (updates: Entry<Json, Json>[], isInit: boolean) => void;
9
12
  error: (error: Json) => void;
@@ -11,17 +14,25 @@ export interface ExternalResource {
11
14
  },
12
15
  ): void;
13
16
 
14
- close(params: { [param: string]: string | number }): void;
17
+ close(params: Json): void;
15
18
  }
16
19
 
20
+ /**
21
+ * A generic external service providing external resources.
22
+ *
23
+ * `GenericExternalService` provides an implementation of `ExternalService` for external resources by lifting the `open` and `close` operations from `ExternalResource` to the `subscribe` and `unsubscribe` operations required by `ExternalService`.
24
+ */
17
25
  export class GenericExternalService implements ExternalService {
26
+ /**
27
+ * @param resources - Association of resource names to `ExternalResource`s.
28
+ */
18
29
  constructor(
19
30
  private readonly resources: { [name: string]: ExternalResource },
20
31
  ) {}
21
32
 
22
33
  subscribe(
23
34
  resourceName: string,
24
- params: { [param: string]: string | number },
35
+ params: Json,
25
36
  callbacks: {
26
37
  update: (updates: Entry<Json, Json>[], isInit: boolean) => void;
27
38
  error: (error: Json) => void;
@@ -37,7 +48,7 @@ export class GenericExternalService implements ExternalService {
37
48
  resource.open(params, callbacks);
38
49
  }
39
50
 
40
- unsubscribe(resourceName: string, params: { [param: string]: string }) {
51
+ unsubscribe(resourceName: string, params: Json) {
41
52
  const resource = this.resources[resourceName] as
42
53
  | ExternalResource
43
54
  | undefined;
@@ -58,7 +69,7 @@ export class TimerResource implements ExternalResource {
58
69
  private readonly intervals = new Map<string, { [name: string]: Timeout }>();
59
70
 
60
71
  open(
61
- params: { [param: string]: string | number },
72
+ params: Json,
62
73
  callbacks: {
63
74
  update: (updates: Entry<Json, Json>[], isInit: boolean) => void;
64
75
  error: (error: Json) => void;
@@ -85,7 +96,7 @@ export class TimerResource implements ExternalResource {
85
96
  this.intervals.set(id, intervals);
86
97
  }
87
98
 
88
- close(params: { [param: string]: string | number }): void {
99
+ close(params: Json): void {
89
100
  const intervals = this.intervals.get(toId(params));
90
101
  if (intervals != null) {
91
102
  for (const interval of Object.values(intervals)) {
@@ -95,19 +106,46 @@ export class TimerResource implements ExternalResource {
95
106
  }
96
107
  }
97
108
 
109
+ function defaultParamEncoder(params: Json): string {
110
+ if (typeof params == "object") {
111
+ const queryParams: { [param: string]: string } = {};
112
+ for (const [key, value] of Object.entries(params)) {
113
+ if (typeof value == "object") queryParams[key] = JSON.stringify(value);
114
+ else queryParams[key] = value.toString();
115
+ }
116
+ return new URLSearchParams(queryParams).toString();
117
+ } else return `params=${JSON.stringify(params)}`;
118
+ }
119
+
120
+ /**
121
+ * An external resource that is refreshed at some polling interval.
122
+ *
123
+ * @typeParam S - Type of data received from external resource.
124
+ * @typeParam K - Type of keys.
125
+ * @typeParam V - Type of values.
126
+ */
98
127
  export class Polled<S extends Json, K extends Json, V extends Json>
99
128
  implements ExternalResource
100
129
  {
101
130
  private readonly intervals = new Map<string, Timeout>();
102
131
 
132
+ /**
133
+ * @param url - HTTP endpoint of external resource to poll.
134
+ * @param duration - Refresh interval, in milliseconds.
135
+ * @param conv - Function to convert data of type `S` received from external resource to `key`-`value` entries.
136
+ * @param encodeParams - Function to use to encode params of type `Json` for external resource request.
137
+ */
103
138
  constructor(
104
139
  private readonly url: string,
105
140
  private readonly duration: number,
106
141
  private readonly conv: (data: S) => Entry<K, V>[],
142
+ private readonly encodeParams: (
143
+ params: Json,
144
+ ) => string = defaultParamEncoder,
107
145
  ) {}
108
146
 
109
147
  open(
110
- params: { [param: string]: string | number },
148
+ params: Json,
111
149
  callbacks: {
112
150
  update: (updates: Entry<Json, Json>[], isInit: boolean) => void;
113
151
  error: (error: Json) => void;
@@ -115,12 +153,7 @@ export class Polled<S extends Json, K extends Json, V extends Json>
115
153
  },
116
154
  ): void {
117
155
  this.close(params);
118
- const queryParams: { [param: string]: string } = {};
119
- for (const [key, value] of Object.entries(params)) {
120
- queryParams[key] = value.toString();
121
- }
122
- const strParams = new URLSearchParams(queryParams).toString();
123
- const url = `${this.url}?${strParams}`;
156
+ const url = `${this.url}?${this.encodeParams(params)}`;
124
157
  const call = () => {
125
158
  callbacks.loading();
126
159
  fetchJSON(url, "GET", {})
@@ -136,7 +169,7 @@ export class Polled<S extends Json, K extends Json, V extends Json>
136
169
  this.intervals.set(toId(params), setInterval(call, this.duration));
137
170
  }
138
171
 
139
- close(params: { [param: string]: string | number }): void {
172
+ close(params: Json): void {
140
173
  const interval = this.intervals.get(toId(params));
141
174
  if (interval) {
142
175
  clearInterval(interval);
@@ -144,9 +177,11 @@ export class Polled<S extends Json, K extends Json, V extends Json>
144
177
  }
145
178
  }
146
179
 
147
- function toId(params: { [param: string]: string | number }): string {
148
- const strparams = Object.entries(params)
149
- .map(([key, value]) => `${key}:${value.toString()}`)
150
- .sort();
151
- return `[${strparams.join(",")}]`;
180
+ function toId(params: Json): string {
181
+ if (typeof params == "object") {
182
+ const strparams = Object.entries(params)
183
+ .map(([key, value]) => `${key}:${btoa(JSON.stringify(value))}`)
184
+ .sort();
185
+ return `[${strparams.join(",")}]`;
186
+ } else return btoa(JSON.stringify(params));
152
187
  }
package/src/index.ts CHANGED
@@ -1,6 +1,20 @@
1
+ /**
2
+ * This package contains items that may be useful for working with the Skip framework, but are not strictly necessary.
3
+ *
4
+ * @packageDocumentation
5
+ */
6
+
1
7
  export {
2
8
  type ExternalResource,
3
9
  GenericExternalService,
4
10
  Polled,
5
11
  } from "./external.js";
6
- export { fetchJSON, SkipServiceBroker } from "./rest.js";
12
+ export { SkipServiceBroker, fetchJSON, type Entrypoint } from "./rest.js";
13
+ export {
14
+ Count,
15
+ CountMapper,
16
+ Max,
17
+ Min,
18
+ SkipExternalService,
19
+ Sum,
20
+ } from "@skipruntime/core";
package/src/rest.ts CHANGED
@@ -1,17 +1,7 @@
1
1
  import type { Json, Entry } from "@skipruntime/api";
2
2
  import { NonUniqueValueException } from "@skipruntime/api";
3
-
4
- /**
5
- * An entry point of a Skip reactive service.
6
- *
7
- * URLs for the service's control and streaming APIs can be constructed from an `Entrypoint`.
8
- */
9
- export type Entrypoint = {
10
- host: string;
11
- streaming_port: number;
12
- control_port: number;
13
- secured?: boolean;
14
- };
3
+ import type { Entrypoint } from "@skipruntime/core";
4
+ export type { Entrypoint };
15
5
 
16
6
  function toHttp(entrypoint: Entrypoint) {
17
7
  if (entrypoint.secured)
@@ -19,6 +9,16 @@ function toHttp(entrypoint: Entrypoint) {
19
9
  return `http://${entrypoint.host}:${entrypoint.control_port}`;
20
10
  }
21
11
 
12
+ /**
13
+ * Perform an HTTP fetch where input and output data is `Json`.
14
+ *
15
+ * @typeParam V - Type response is *assumed* to have.
16
+ * @param url - URL from which to fetch.
17
+ * @param method - HTTP method of request.
18
+ * @param headers - Additional headers to add to request.
19
+ * @param data - Data to convert to JSON and send in request body.
20
+ * @returns Response parsed as JSON, and headers.
21
+ */
22
22
  export async function fetchJSON<V extends Json>(
23
23
  url: string,
24
24
  method: "POST" | "GET" | "PUT" | "PATCH" | "HEAD" | "DELETE" = "GET",
@@ -58,8 +58,9 @@ export class SkipServiceBroker {
58
58
 
59
59
  /**
60
60
  * Construct a broker for a Skip service at the given entry point.
61
- * @param entrypoint - entry point of backing service
62
- * @returns - method-call broker to service
61
+ *
62
+ * @param entrypoint - Entry point of backing service.
63
+ * @returns Method-call broker to service.
63
64
  */
64
65
  constructor(
65
66
  entrypoint: Entrypoint = {
@@ -74,58 +75,66 @@ export class SkipServiceBroker {
74
75
  /**
75
76
  * Read the entire contents of a resource.
76
77
  *
77
- * @param resource - name of resource, must be a key of the `resources` field of the `SkipService` running at `entrypoint`
78
- * @param params - resource instance parameters
79
- * @returns - all entries in resource
78
+ * @typeParam K - Type of keys.
79
+ * @typeParam V - Type of values.
80
+ * @param resource - Name of resource, must be a key of the `resources` field of the `SkipService` running at `entrypoint`.
81
+ * @param params - Resource instance parameters.
82
+ * @returns All entries in resource.
80
83
  */
81
84
  async getAll<K extends Json, V extends Json>(
82
85
  resource: string,
83
- params: { [param: string]: string },
86
+ params: Json,
84
87
  ): Promise<Entry<K, V>[]> {
85
88
  const [data, _headers] = await fetchJSON<Entry<K, V>[]>(
86
- `${this.entrypoint}/v1/snapshot`,
89
+ `${this.entrypoint}/v1/snapshot/${resource}`,
87
90
  "POST",
88
91
  {},
89
- { resource, params },
92
+ params,
90
93
  );
91
94
  return data ?? [];
92
95
  }
93
96
 
94
97
  /**
95
98
  * Read the values a resource associates with a single key.
96
- * @param resource - name of resource, must be a key of the `resources` field of the `SkipService` running at `entrypoint`
97
- * @param params - resource instance parameters
98
- * @param key - key to read
99
- * @returns - the values associated to the key
99
+ *
100
+ * @typeParam K - Type of keys.
101
+ * @typeParam V - Type of values.
102
+ * @param resource - Name of resource, must be a key of the `resources` field of the `SkipService` running at `entrypoint`.
103
+ * @param params - Resource instance parameters.
104
+ * @param key - Key to read.
105
+ * @returns The values associated to the key.
100
106
  */
101
- async getArray<V extends Json>(
107
+ async getArray<K extends Json, V extends Json>(
102
108
  resource: string,
103
- params: { [param: string]: string },
104
- key: string,
109
+ params: Json,
110
+ key: K,
105
111
  ): Promise<V[]> {
106
112
  const [data, _headers] = await fetchJSON<V[]>(
107
- `${this.entrypoint}/v1/snapshot`,
113
+ `${this.entrypoint}/v1/snapshot/${resource}`,
108
114
  "POST",
109
115
  {},
110
- { resource, key, params },
116
+ { key, params },
111
117
  );
112
118
  return data ?? [];
113
119
  }
114
120
 
115
121
  /**
116
122
  * Read the single value a resource associates with a key.
117
- * @param resource - name of resource, must be a key of the `resources` field of the `SkipService` running at `entrypoint`
118
- * @param params - resource instance parameters
119
- * @param key - key to read
120
- * @returns - the value associated to the key
121
- * @throws {NonUniqueValueException} when the key is associated to either zero or multiple values
123
+ *
124
+ * @typeParam K - Type of keys.
125
+ * @typeParam V - Type of values.
126
+ * @param resource - Name of resource, must be a key of the `resources` field of the `SkipService` running at `entrypoint`.
127
+ * @param params - Resource instance parameters.
128
+ * @param key - Key to read.
129
+ * @returns The value associated to the key.
130
+ * @throws `NonUniqueValueException` when the key is associated to either zero or multiple values.
122
131
  */
123
- async getUnique<V extends Json>(
132
+ async getUnique<K extends Json, V extends Json>(
124
133
  resource: string,
125
- params: { [param: string]: string },
126
- key: string,
134
+ params: Json,
135
+ key: K,
127
136
  ): Promise<V> {
128
- return this.getArray<V>(resource, params, key).then((values) => {
137
+ return this.getArray<K, V>(resource, params, key).then((values) => {
129
138
  if (values.length !== 1 || values[0] === undefined)
130
139
  throw new NonUniqueValueException();
131
140
  return values[0];
@@ -134,9 +143,12 @@ export class SkipServiceBroker {
134
143
 
135
144
  /**
136
145
  * Write the values for a single key in a collection.
137
- * @param collection - name of the input collection to update, must be a key of the `Inputs` type parameter of the `SkipService` running at `entrypoint`
138
- * @param key - key of entry to write
139
- * @param values - values of entry to write
146
+ *
147
+ * @typeParam K - Type of keys.
148
+ * @typeParam V - Type of values.
149
+ * @param collection - Name of the input collection to update, must be a key of the `Inputs` type parameter of the `SkipService` running at `entrypoint`.
150
+ * @param key - Key of entry to write.
151
+ * @param values - Values of entry to write.
140
152
  * @returns {void}
141
153
  */
142
154
  async put<K extends Json, V extends Json>(
@@ -149,8 +161,11 @@ export class SkipServiceBroker {
149
161
 
150
162
  /**
151
163
  * Write multiple entries to a collection.
152
- * @param collection - name of the input collection to update, must be a key of the `Inputs` type parameter of the `SkipService` running at `entrypoint`
153
- * @param entries - entries to write
164
+ *
165
+ * @typeParam K - Type of keys.
166
+ * @typeParam V - Type of values.
167
+ * @param collection - Name of the input collection to update, must be a key of the `Inputs` type parameter of the `SkipService` running at `entrypoint`.
168
+ * @param entries - Entries to write.
154
169
  * @returns {void}
155
170
  */
156
171
  async patch<K extends Json, V extends Json>(
@@ -167,8 +182,10 @@ export class SkipServiceBroker {
167
182
 
168
183
  /**
169
184
  * Remove all values associated with a key in a collection.
170
- * @param collection - name of the input collection to update, must be a key of the `Inputs` type parameter of the `SkipService` running at `entrypoint`
171
- * @param key - key of entry to delete
185
+ *
186
+ * @typeParam K - Type of keys.
187
+ * @param collection - Name of the input collection to update, must be a key of the `Inputs` type parameter of the `SkipService` running at `entrypoint`.
188
+ * @param key - Key of entry to delete.
172
189
  * @returns {void}
173
190
  */
174
191
  async deleteKey<K extends Json>(collection: string, key: K): Promise<void> {
@@ -177,18 +194,18 @@ export class SkipServiceBroker {
177
194
 
178
195
  /**
179
196
  * Create a resource instance UUID.
180
- * @param resource - name of resource, must be a key of the `resources` field of the `SkipService` running at `entrypoint`
181
- * @param params - resource instance parameters
182
- * @returns - UUID that can be used to subscribe to updates to resource instance
197
+ *
198
+ * @typeParam K - Type of keys.
199
+ * @typeParam V - Type of values.
200
+ * @param resource - Name of resource, must be a key of the `resources` field of the `SkipService` running at `entrypoint`.
201
+ * @param params - Resource instance parameters.
202
+ * @returns UUID that can be used to subscribe to updates to resource instance.
183
203
  */
184
- async getStreamUUID(
185
- resource: string,
186
- params: { [param: string]: string } = {},
187
- ): Promise<string> {
188
- return fetch(`${this.entrypoint}/v1/streams`, {
204
+ async getStreamUUID(resource: string, params: Json = {}): Promise<string> {
205
+ return fetch(`${this.entrypoint}/v1/streams/${resource}`, {
189
206
  method: "POST",
190
207
  headers: { "Content-Type": "application/json" },
191
- body: JSON.stringify({ resource, params }),
208
+ body: JSON.stringify(params),
192
209
  }).then((res) => res.text());
193
210
  }
194
211
 
@@ -197,7 +214,7 @@ export class SkipServiceBroker {
197
214
  *
198
215
  * Under normal circumstances, resource instances are deleted automatically after some period of inactivity; this method enables immediately deleting live streams under exceptional circumstances.
199
216
  *
200
- * @param uuid - resource instance UUID
217
+ * @param uuid - Resource instance UUID.
201
218
  * @returns {void}
202
219
  */
203
220
  async deleteUUID(uuid: string): Promise<void> {