@skipruntime/helpers 0.0.3 → 0.0.5
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/dist/external.d.ts +6 -6
- package/dist/external.d.ts.map +1 -1
- package/dist/external.js.map +1 -1
- package/dist/index.d.ts +1 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -3
- package/dist/index.js.map +1 -1
- package/dist/rest.d.ts +83 -5
- package/dist/rest.d.ts.map +1 -1
- package/dist/rest.js +92 -11
- package/dist/rest.js.map +1 -1
- package/package.json +3 -4
- package/src/external.ts +8 -6
- package/src/index.ts +1 -3
- package/src/rest.ts +116 -16
- package/dist/errors.d.ts +0 -3
- package/dist/errors.d.ts.map +0 -1
- package/dist/errors.js +0 -3
- package/dist/errors.js.map +0 -1
- package/dist/remote.d.ts +0 -22
- package/dist/remote.d.ts.map +0 -1
- package/dist/remote.js +0 -71
- package/dist/remote.js.map +0 -1
- package/dist/utils.d.ts +0 -22
- package/dist/utils.d.ts.map +0 -1
- package/dist/utils.js +0 -40
- package/dist/utils.js.map +0 -1
- package/src/errors.ts +0 -1
- package/src/remote.ts +0 -94
- package/src/utils.ts +0 -48
package/dist/external.d.ts
CHANGED
|
@@ -12,7 +12,7 @@ export interface ExternalResource {
|
|
|
12
12
|
}): void;
|
|
13
13
|
}
|
|
14
14
|
export declare class GenericExternalService implements ExternalService {
|
|
15
|
-
private resources;
|
|
15
|
+
private readonly resources;
|
|
16
16
|
constructor(resources: {
|
|
17
17
|
[name: string]: ExternalResource;
|
|
18
18
|
});
|
|
@@ -29,7 +29,7 @@ export declare class GenericExternalService implements ExternalService {
|
|
|
29
29
|
shutdown(): void;
|
|
30
30
|
}
|
|
31
31
|
export declare class TimerResource implements ExternalResource {
|
|
32
|
-
private intervals;
|
|
32
|
+
private readonly intervals;
|
|
33
33
|
open(params: {
|
|
34
34
|
[param: string]: string | number;
|
|
35
35
|
}, callbacks: {
|
|
@@ -42,10 +42,10 @@ export declare class TimerResource implements ExternalResource {
|
|
|
42
42
|
}): void;
|
|
43
43
|
}
|
|
44
44
|
export declare class Polled<S extends Json, K extends Json, V extends Json> implements ExternalResource {
|
|
45
|
-
private url;
|
|
46
|
-
private duration;
|
|
47
|
-
private conv;
|
|
48
|
-
private intervals;
|
|
45
|
+
private readonly url;
|
|
46
|
+
private readonly duration;
|
|
47
|
+
private readonly conv;
|
|
48
|
+
private readonly intervals;
|
|
49
49
|
constructor(url: string, duration: number, conv: (data: S) => Entry<K, V>[]);
|
|
50
50
|
open(params: {
|
|
51
51
|
[param: string]: string | number;
|
package/dist/external.d.ts.map
CHANGED
|
@@ -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,KAAK,IAAI,CAAC;QAChE,KAAK,EAAE,CAAC,KAAK,EAAE,IAAI,KAAK,IAAI,CAAC;QAC7B,OAAO,EAAE,MAAM,IAAI,CAAC;KACrB,GACA,IAAI,CAAC;IAER,KAAK,CAAC,MAAM,EAAE;QAAE,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,CAAA;KAAE,GAAG,IAAI,CAAC;CAC3D;AAED,qBAAa,sBAAuB,YAAW,eAAe;
|
|
1
|
+
{"version":3,"file":"external.d.ts","sourceRoot":"","sources":["../src/external.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,eAAe,EAAE,IA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CAAC;KACrB,GACA,IAAI;IAuBP,KAAK,CAAC,MAAM,EAAE;QAAE,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,CAAA;KAAE,GAAG,IAAI;CAM1D"}
|
package/dist/external.js.map
CHANGED
|
@@ -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,
|
|
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;I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CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC;gBACpE,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;YACnB,CAAC,CAAC,CAAC;QACP,CAAC,CAAC;QACF,IAAI,EAAE,CAAC;QACP,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,WAAW,CAAC,IAAI,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC;IACrE,CAAC;IAED,KAAK,CAAC,MAA4C;QAChD,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,MAA4C;IACxD,MAAM,SAAS,GAAG,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC;SACrC,GAAG,CAAC,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,EAAE,EAAE,CAAC,GAAG,GAAG,IAAI,KAAK,CAAC,QAAQ,EAAE,EAAE,CAAC;SACnD,IAAI,EAAE,CAAC;IACV,OAAO,IAAI,SAAS,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC;AACpC,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
export { SkipExternalService } from "./remote.js";
|
|
2
1
|
export { type ExternalResource, GenericExternalService, Polled, } from "./external.js";
|
|
3
|
-
export {
|
|
4
|
-
export { RESTWrapperOfSkipService } from "./rest.js";
|
|
2
|
+
export { fetchJSON, SkipServiceBroker } from "./rest.js";
|
|
5
3
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
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"}
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
export { SkipExternalService } from "./remote.js";
|
|
2
1
|
export { GenericExternalService, Polled, } from "./external.js";
|
|
3
|
-
export {
|
|
4
|
-
export { RESTWrapperOfSkipService } from "./rest.js";
|
|
2
|
+
export { fetchJSON, SkipServiceBroker } from "./rest.js";
|
|
5
3
|
//# 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,
|
|
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"}
|
package/dist/rest.d.ts
CHANGED
|
@@ -1,24 +1,102 @@
|
|
|
1
1
|
import type { Json, Entry } from "@skipruntime/api";
|
|
2
|
+
/**
|
|
3
|
+
* An entry point of a Skip reactive service.
|
|
4
|
+
*
|
|
5
|
+
* URLs for the service's control and streaming APIs can be constructed from an `Entrypoint`.
|
|
6
|
+
*/
|
|
2
7
|
export type Entrypoint = {
|
|
3
8
|
host: string;
|
|
4
9
|
streaming_port: number;
|
|
5
10
|
control_port: number;
|
|
6
11
|
secured?: boolean;
|
|
7
12
|
};
|
|
8
|
-
export declare function fetchJSON<V>(url: string, method?: "POST" | "GET" | "PUT" | "PATCH" | "HEAD" | "DELETE", headers?: {
|
|
13
|
+
export declare function fetchJSON<V extends Json>(url: string, method?: "POST" | "GET" | "PUT" | "PATCH" | "HEAD" | "DELETE", headers?: {
|
|
9
14
|
[header: string]: string;
|
|
10
15
|
}, data?: Json): Promise<[V | null, Headers]>;
|
|
11
|
-
|
|
12
|
-
|
|
16
|
+
/**
|
|
17
|
+
* Wrapper providing a method-call interface to the Skip service HTTP APIs.
|
|
18
|
+
*
|
|
19
|
+
* Skip services, as started by `runService`, support an HTTP interface for reading from resources and writing to input collections.
|
|
20
|
+
* `SkipServiceBroker` provides a method-call interface to the backing HTTP interface.
|
|
21
|
+
*/
|
|
22
|
+
export declare class SkipServiceBroker {
|
|
23
|
+
private readonly entrypoint;
|
|
24
|
+
/**
|
|
25
|
+
* 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
|
|
28
|
+
*/
|
|
13
29
|
constructor(entrypoint?: Entrypoint);
|
|
30
|
+
/**
|
|
31
|
+
* Read the entire contents of a resource.
|
|
32
|
+
*
|
|
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
|
|
36
|
+
*/
|
|
14
37
|
getAll<K extends Json, V extends Json>(resource: string, params: {
|
|
15
38
|
[param: string]: string;
|
|
16
39
|
}): Promise<Entry<K, V>[]>;
|
|
40
|
+
/**
|
|
41
|
+
* 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
|
|
46
|
+
*/
|
|
17
47
|
getArray<V extends Json>(resource: string, params: {
|
|
18
48
|
[param: string]: string;
|
|
19
49
|
}, key: string): Promise<V[]>;
|
|
20
|
-
|
|
21
|
-
|
|
50
|
+
/**
|
|
51
|
+
* 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
|
|
57
|
+
*/
|
|
58
|
+
getUnique<V extends Json>(resource: string, params: {
|
|
59
|
+
[param: string]: string;
|
|
60
|
+
}, key: string): Promise<V>;
|
|
61
|
+
/**
|
|
62
|
+
* 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
|
|
66
|
+
* @returns {void}
|
|
67
|
+
*/
|
|
68
|
+
put<K extends Json, V extends Json>(collection: string, key: K, values: V[]): Promise<void>;
|
|
69
|
+
/**
|
|
70
|
+
* 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
|
|
73
|
+
* @returns {void}
|
|
74
|
+
*/
|
|
75
|
+
patch<K extends Json, V extends Json>(collection: string, entries: Entry<K, V>[]): Promise<void>;
|
|
76
|
+
/**
|
|
77
|
+
* 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
|
|
80
|
+
* @returns {void}
|
|
81
|
+
*/
|
|
22
82
|
deleteKey<K extends Json>(collection: string, key: K): Promise<void>;
|
|
83
|
+
/**
|
|
84
|
+
* 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
|
|
88
|
+
*/
|
|
89
|
+
getStreamUUID(resource: string, params?: {
|
|
90
|
+
[param: string]: string;
|
|
91
|
+
}): Promise<string>;
|
|
92
|
+
/**
|
|
93
|
+
* Destroy a resource instance.
|
|
94
|
+
*
|
|
95
|
+
* Under normal circumstances, resource instances are deleted automatically after some period of inactivity; this method enables immediately deleting live streams under exceptional circumstances.
|
|
96
|
+
*
|
|
97
|
+
* @param uuid - resource instance UUID
|
|
98
|
+
* @returns {void}
|
|
99
|
+
*/
|
|
100
|
+
deleteUUID(uuid: string): Promise<void>;
|
|
23
101
|
}
|
|
24
102
|
//# sourceMappingURL=rest.d.ts.map
|
package/dist/rest.d.ts.map
CHANGED
|
@@ -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;
|
|
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,C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SAAS,CAAC,CAAC,SAAS,IAAI,EAAE,UAAU,EAAE,MAAM,EAAE,GAAG,EAAE,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;IAI1E;;;;;OAKG;IACG,aAAa,CACjB,QAAQ,EAAE,MAAM,EAChB,MAAM,GAAE;QAAE,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAAA;KAAO,GACvC,OAAO,CAAC,MAAM,CAAC;IAQlB;;;;;;;OAOG;IACG,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;CAG9C"}
|
package/dist/rest.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { NonUniqueValueException } from "@skipruntime/api";
|
|
1
2
|
function toHttp(entrypoint) {
|
|
2
3
|
if (entrypoint.secured)
|
|
3
4
|
return `https://${entrypoint.host}:${entrypoint.control_port}`;
|
|
@@ -24,7 +25,18 @@ export async function fetchJSON(url, method = "GET", headers = {}, data) {
|
|
|
24
25
|
: null;
|
|
25
26
|
return [responseJSON, response.headers];
|
|
26
27
|
}
|
|
27
|
-
|
|
28
|
+
/**
|
|
29
|
+
* Wrapper providing a method-call interface to the Skip service HTTP APIs.
|
|
30
|
+
*
|
|
31
|
+
* Skip services, as started by `runService`, support an HTTP interface for reading from resources and writing to input collections.
|
|
32
|
+
* `SkipServiceBroker` provides a method-call interface to the backing HTTP interface.
|
|
33
|
+
*/
|
|
34
|
+
export class SkipServiceBroker {
|
|
35
|
+
/**
|
|
36
|
+
* 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
|
|
39
|
+
*/
|
|
28
40
|
constructor(entrypoint = {
|
|
29
41
|
host: "localhost",
|
|
30
42
|
streaming_port: 8080,
|
|
@@ -32,25 +44,94 @@ export class RESTWrapperOfSkipService {
|
|
|
32
44
|
}) {
|
|
33
45
|
this.entrypoint = toHttp(entrypoint);
|
|
34
46
|
}
|
|
47
|
+
/**
|
|
48
|
+
* Read the entire contents of a resource.
|
|
49
|
+
*
|
|
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
|
|
53
|
+
*/
|
|
35
54
|
async getAll(resource, params) {
|
|
36
|
-
const
|
|
37
|
-
|
|
38
|
-
const values = optValues ?? [];
|
|
39
|
-
return values;
|
|
55
|
+
const [data, _headers] = await fetchJSON(`${this.entrypoint}/v1/snapshot`, "POST", {}, { resource, params });
|
|
56
|
+
return data ?? [];
|
|
40
57
|
}
|
|
58
|
+
/**
|
|
59
|
+
* 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
|
|
64
|
+
*/
|
|
41
65
|
async getArray(resource, params, key) {
|
|
42
|
-
const
|
|
43
|
-
const [data, _headers] = await fetchJSON(`${this.entrypoint}/v1/resources/${resource}/${key}?${qParams}`, "GET");
|
|
66
|
+
const [data, _headers] = await fetchJSON(`${this.entrypoint}/v1/snapshot`, "POST", {}, { resource, key, params });
|
|
44
67
|
return data ?? [];
|
|
45
68
|
}
|
|
46
|
-
|
|
47
|
-
|
|
69
|
+
/**
|
|
70
|
+
* 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
|
|
76
|
+
*/
|
|
77
|
+
async getUnique(resource, params, key) {
|
|
78
|
+
return this.getArray(resource, params, key).then((values) => {
|
|
79
|
+
if (values.length !== 1 || values[0] === undefined)
|
|
80
|
+
throw new NonUniqueValueException();
|
|
81
|
+
return values[0];
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* 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
|
|
89
|
+
* @returns {void}
|
|
90
|
+
*/
|
|
91
|
+
async put(collection, key, values) {
|
|
92
|
+
return await this.patch(collection, [[key, values]]);
|
|
48
93
|
}
|
|
49
|
-
|
|
50
|
-
|
|
94
|
+
/**
|
|
95
|
+
* 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
|
|
98
|
+
* @returns {void}
|
|
99
|
+
*/
|
|
100
|
+
async patch(collection, entries) {
|
|
101
|
+
await fetchJSON(`${this.entrypoint}/v1/inputs/${collection}`, "PATCH", {}, entries);
|
|
51
102
|
}
|
|
103
|
+
/**
|
|
104
|
+
* 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
|
|
107
|
+
* @returns {void}
|
|
108
|
+
*/
|
|
52
109
|
async deleteKey(collection, key) {
|
|
53
110
|
return await this.patch(collection, [[key, []]]);
|
|
54
111
|
}
|
|
112
|
+
/**
|
|
113
|
+
* 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
|
|
117
|
+
*/
|
|
118
|
+
async getStreamUUID(resource, params = {}) {
|
|
119
|
+
return fetch(`${this.entrypoint}/v1/streams`, {
|
|
120
|
+
method: "POST",
|
|
121
|
+
headers: { "Content-Type": "application/json" },
|
|
122
|
+
body: JSON.stringify({ resource, params }),
|
|
123
|
+
}).then((res) => res.text());
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Destroy a resource instance.
|
|
127
|
+
*
|
|
128
|
+
* Under normal circumstances, resource instances are deleted automatically after some period of inactivity; this method enables immediately deleting live streams under exceptional circumstances.
|
|
129
|
+
*
|
|
130
|
+
* @param uuid - resource instance UUID
|
|
131
|
+
* @returns {void}
|
|
132
|
+
*/
|
|
133
|
+
async deleteUUID(uuid) {
|
|
134
|
+
await fetchJSON(`${this.entrypoint}/v1/streams/${uuid}`, "DELETE");
|
|
135
|
+
}
|
|
55
136
|
}
|
|
56
137
|
//# sourceMappingURL=rest.js.map
|
package/dist/rest.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rest.js","sourceRoot":"","sources":["../src/rest.ts"],"names":[],"mappings":"
|
|
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,UAAU,CAAC,YAAY,EAAE,CAAC;IACjE,OAAO,UAAU,UAAU,CAAC,IAAI,IAAI,UAAU,CAAC,YAAY,EAAE,CAAC;AAChE,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,SAAS,CAC7B,GAAW,EACX,SAA+D,KAAK,EACpE,UAAwC,EAAE,EAC1C,IAAW;IAEX,MAAM,IAAI,GAAG,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;IACrD,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,GAAG,EAAE;QAChC,MAAM;QACN,IAAI;QACJ,OAAO,EAAE;YACP,cAAc,EAAE,kBAAkB;YAClC,MAAM,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I,CAAC,UAAU,aAAa,EAAE;YAC5C,MAAM,EAAE,MAAM;YACd,OAAO,EAAE,EAAE,cAAc,EAAE,kBAAkB,EAAE;YAC/C,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,EAAE,QAAQ,EAAE,MAAM,EAAE,CAAC;SAC3C,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,10 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@skipruntime/helpers",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.5",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": "./dist/index.js",
|
|
7
|
-
"./errors.js": "./dist/errors.js",
|
|
8
7
|
"./rest.js": "./dist/rest.js",
|
|
9
8
|
"./external.js": "./dist/external.js"
|
|
10
9
|
},
|
|
@@ -21,8 +20,8 @@
|
|
|
21
20
|
},
|
|
22
21
|
"dependencies": {
|
|
23
22
|
"eventsource": "^2.0.2",
|
|
24
|
-
"express": "^4.21.
|
|
25
|
-
"@skipruntime/api": "^0.0.
|
|
23
|
+
"express": "^4.21.1",
|
|
24
|
+
"@skipruntime/api": "^0.0.4"
|
|
26
25
|
},
|
|
27
26
|
"devDependencies": {
|
|
28
27
|
"@types/eventsource": "^1.1.15"
|
package/src/external.ts
CHANGED
|
@@ -15,7 +15,9 @@ export interface ExternalResource {
|
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
export class GenericExternalService implements ExternalService {
|
|
18
|
-
constructor(
|
|
18
|
+
constructor(
|
|
19
|
+
private readonly resources: { [name: string]: ExternalResource },
|
|
20
|
+
) {}
|
|
19
21
|
|
|
20
22
|
subscribe(
|
|
21
23
|
resourceName: string,
|
|
@@ -53,7 +55,7 @@ export class GenericExternalService implements ExternalService {
|
|
|
53
55
|
type Timeout = ReturnType<typeof setInterval>;
|
|
54
56
|
|
|
55
57
|
export class TimerResource implements ExternalResource {
|
|
56
|
-
private intervals = new Map<string, { [name: string]: Timeout }>();
|
|
58
|
+
private readonly intervals = new Map<string, { [name: string]: Timeout }>();
|
|
57
59
|
|
|
58
60
|
open(
|
|
59
61
|
params: { [param: string]: string | number },
|
|
@@ -96,12 +98,12 @@ export class TimerResource implements ExternalResource {
|
|
|
96
98
|
export class Polled<S extends Json, K extends Json, V extends Json>
|
|
97
99
|
implements ExternalResource
|
|
98
100
|
{
|
|
99
|
-
private intervals = new Map<string, Timeout>();
|
|
101
|
+
private readonly intervals = new Map<string, Timeout>();
|
|
100
102
|
|
|
101
103
|
constructor(
|
|
102
|
-
private url: string,
|
|
103
|
-
private duration: number,
|
|
104
|
-
private conv: (data: S) => Entry<K, V>[],
|
|
104
|
+
private readonly url: string,
|
|
105
|
+
private readonly duration: number,
|
|
106
|
+
private readonly conv: (data: S) => Entry<K, V>[],
|
|
105
107
|
) {}
|
|
106
108
|
|
|
107
109
|
open(
|
package/src/index.ts
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
export { SkipExternalService } from "./remote.js";
|
|
2
1
|
export {
|
|
3
2
|
type ExternalResource,
|
|
4
3
|
GenericExternalService,
|
|
5
4
|
Polled,
|
|
6
5
|
} from "./external.js";
|
|
7
|
-
export {
|
|
8
|
-
export { RESTWrapperOfSkipService } from "./rest.js";
|
|
6
|
+
export { fetchJSON, SkipServiceBroker } from "./rest.js";
|
package/src/rest.ts
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
import type { Json, Entry } from "@skipruntime/api";
|
|
2
|
+
import { NonUniqueValueException } from "@skipruntime/api";
|
|
2
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
|
+
*/
|
|
3
9
|
export type Entrypoint = {
|
|
4
10
|
host: string;
|
|
5
11
|
streaming_port: number;
|
|
@@ -13,7 +19,7 @@ function toHttp(entrypoint: Entrypoint) {
|
|
|
13
19
|
return `http://${entrypoint.host}:${entrypoint.control_port}`;
|
|
14
20
|
}
|
|
15
21
|
|
|
16
|
-
export async function fetchJSON<V>(
|
|
22
|
+
export async function fetchJSON<V extends Json>(
|
|
17
23
|
url: string,
|
|
18
24
|
method: "POST" | "GET" | "PUT" | "PATCH" | "HEAD" | "DELETE" = "GET",
|
|
19
25
|
headers: { [header: string]: string } = {},
|
|
@@ -41,9 +47,20 @@ export async function fetchJSON<V>(
|
|
|
41
47
|
return [responseJSON, response.headers];
|
|
42
48
|
}
|
|
43
49
|
|
|
44
|
-
|
|
45
|
-
|
|
50
|
+
/**
|
|
51
|
+
* Wrapper providing a method-call interface to the Skip service HTTP APIs.
|
|
52
|
+
*
|
|
53
|
+
* Skip services, as started by `runService`, support an HTTP interface for reading from resources and writing to input collections.
|
|
54
|
+
* `SkipServiceBroker` provides a method-call interface to the backing HTTP interface.
|
|
55
|
+
*/
|
|
56
|
+
export class SkipServiceBroker {
|
|
57
|
+
private readonly entrypoint: string;
|
|
46
58
|
|
|
59
|
+
/**
|
|
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
|
|
63
|
+
*/
|
|
47
64
|
constructor(
|
|
48
65
|
entrypoint: Entrypoint = {
|
|
49
66
|
host: "localhost",
|
|
@@ -54,53 +71,136 @@ export class RESTWrapperOfSkipService {
|
|
|
54
71
|
this.entrypoint = toHttp(entrypoint);
|
|
55
72
|
}
|
|
56
73
|
|
|
74
|
+
/**
|
|
75
|
+
* Read the entire contents of a resource.
|
|
76
|
+
*
|
|
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
|
|
80
|
+
*/
|
|
57
81
|
async getAll<K extends Json, V extends Json>(
|
|
58
82
|
resource: string,
|
|
59
83
|
params: { [param: string]: string },
|
|
60
84
|
): Promise<Entry<K, V>[]> {
|
|
61
|
-
const
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
85
|
+
const [data, _headers] = await fetchJSON<Entry<K, V>[]>(
|
|
86
|
+
`${this.entrypoint}/v1/snapshot`,
|
|
87
|
+
"POST",
|
|
88
|
+
{},
|
|
89
|
+
{ resource, params },
|
|
65
90
|
);
|
|
66
|
-
|
|
67
|
-
return values;
|
|
91
|
+
return data ?? [];
|
|
68
92
|
}
|
|
69
93
|
|
|
94
|
+
/**
|
|
95
|
+
* 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
|
|
100
|
+
*/
|
|
70
101
|
async getArray<V extends Json>(
|
|
71
102
|
resource: string,
|
|
72
103
|
params: { [param: string]: string },
|
|
73
104
|
key: string,
|
|
74
105
|
): Promise<V[]> {
|
|
75
|
-
const qParams = new URLSearchParams(params).toString();
|
|
76
106
|
const [data, _headers] = await fetchJSON<V[]>(
|
|
77
|
-
`${this.entrypoint}/v1/
|
|
78
|
-
"
|
|
107
|
+
`${this.entrypoint}/v1/snapshot`,
|
|
108
|
+
"POST",
|
|
109
|
+
{},
|
|
110
|
+
{ resource, key, params },
|
|
79
111
|
);
|
|
80
112
|
return data ?? [];
|
|
81
113
|
}
|
|
82
114
|
|
|
115
|
+
/**
|
|
116
|
+
* 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
|
|
122
|
+
*/
|
|
123
|
+
async getUnique<V extends Json>(
|
|
124
|
+
resource: string,
|
|
125
|
+
params: { [param: string]: string },
|
|
126
|
+
key: string,
|
|
127
|
+
): Promise<V> {
|
|
128
|
+
return this.getArray<V>(resource, params, key).then((values) => {
|
|
129
|
+
if (values.length !== 1 || values[0] === undefined)
|
|
130
|
+
throw new NonUniqueValueException();
|
|
131
|
+
return values[0];
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* 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
|
|
140
|
+
* @returns {void}
|
|
141
|
+
*/
|
|
83
142
|
async put<K extends Json, V extends Json>(
|
|
84
143
|
collection: string,
|
|
85
144
|
key: K,
|
|
86
|
-
|
|
145
|
+
values: V[],
|
|
87
146
|
): Promise<void> {
|
|
88
|
-
return await this.patch(collection, [[key,
|
|
147
|
+
return await this.patch(collection, [[key, values]]);
|
|
89
148
|
}
|
|
90
149
|
|
|
150
|
+
/**
|
|
151
|
+
* 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
|
|
154
|
+
* @returns {void}
|
|
155
|
+
*/
|
|
91
156
|
async patch<K extends Json, V extends Json>(
|
|
92
157
|
collection: string,
|
|
93
|
-
|
|
158
|
+
entries: Entry<K, V>[],
|
|
94
159
|
): Promise<void> {
|
|
95
160
|
await fetchJSON(
|
|
96
161
|
`${this.entrypoint}/v1/inputs/${collection}`,
|
|
97
162
|
"PATCH",
|
|
98
163
|
{},
|
|
99
|
-
|
|
164
|
+
entries,
|
|
100
165
|
);
|
|
101
166
|
}
|
|
102
167
|
|
|
168
|
+
/**
|
|
169
|
+
* 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
|
|
172
|
+
* @returns {void}
|
|
173
|
+
*/
|
|
103
174
|
async deleteKey<K extends Json>(collection: string, key: K): Promise<void> {
|
|
104
175
|
return await this.patch(collection, [[key, []]]);
|
|
105
176
|
}
|
|
177
|
+
|
|
178
|
+
/**
|
|
179
|
+
* 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
|
|
183
|
+
*/
|
|
184
|
+
async getStreamUUID(
|
|
185
|
+
resource: string,
|
|
186
|
+
params: { [param: string]: string } = {},
|
|
187
|
+
): Promise<string> {
|
|
188
|
+
return fetch(`${this.entrypoint}/v1/streams`, {
|
|
189
|
+
method: "POST",
|
|
190
|
+
headers: { "Content-Type": "application/json" },
|
|
191
|
+
body: JSON.stringify({ resource, params }),
|
|
192
|
+
}).then((res) => res.text());
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
/**
|
|
196
|
+
* Destroy a resource instance.
|
|
197
|
+
*
|
|
198
|
+
* Under normal circumstances, resource instances are deleted automatically after some period of inactivity; this method enables immediately deleting live streams under exceptional circumstances.
|
|
199
|
+
*
|
|
200
|
+
* @param uuid - resource instance UUID
|
|
201
|
+
* @returns {void}
|
|
202
|
+
*/
|
|
203
|
+
async deleteUUID(uuid: string): Promise<void> {
|
|
204
|
+
await fetchJSON(`${this.entrypoint}/v1/streams/${uuid}`, "DELETE");
|
|
205
|
+
}
|
|
106
206
|
}
|
package/dist/errors.d.ts
DELETED
package/dist/errors.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,qBAAa,sBAAuB,SAAQ,KAAK;CAAG"}
|
package/dist/errors.js
DELETED
package/dist/errors.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,sBAAuB,SAAQ,KAAK;CAAG"}
|
package/dist/remote.d.ts
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import type { Entry, ExternalService, Json } from "@skipruntime/api";
|
|
2
|
-
import type { Entrypoint } from "./rest.js";
|
|
3
|
-
export declare class SkipExternalService implements ExternalService {
|
|
4
|
-
private url;
|
|
5
|
-
private control_url;
|
|
6
|
-
private resources;
|
|
7
|
-
constructor(url: string, control_url: string);
|
|
8
|
-
static direct(entrypoint: Entrypoint): SkipExternalService;
|
|
9
|
-
subscribe(resource: string, params: {
|
|
10
|
-
[param: string]: string;
|
|
11
|
-
}, callbacks: {
|
|
12
|
-
update: (updates: Entry<Json, Json>[], isInitial: boolean) => void;
|
|
13
|
-
error: (error: Json) => void;
|
|
14
|
-
loading: () => void;
|
|
15
|
-
}): void;
|
|
16
|
-
unsubscribe(resource: string, params: {
|
|
17
|
-
[param: string]: string;
|
|
18
|
-
}): void;
|
|
19
|
-
shutdown(): void;
|
|
20
|
-
private toId;
|
|
21
|
-
}
|
|
22
|
-
//# sourceMappingURL=remote.d.ts.map
|
package/dist/remote.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"remote.d.ts","sourceRoot":"","sources":["../src/remote.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,KAAK,EAAE,eAAe,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAErE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAM5C,qBAAa,mBAAoB,YAAW,eAAe;IAIvD,OAAO,CAAC,GAAG;IACX,OAAO,CAAC,WAAW;IAJrB,OAAO,CAAC,SAAS,CAA+B;gBAGtC,GAAG,EAAE,MAAM,EACX,WAAW,EAAE,MAAM;IAI7B,MAAM,CAAC,MAAM,CAAC,UAAU,EAAE,UAAU,GAAG,mBAAmB;IAU1D,SAAS,CACP,QAAQ,EAAE,MAAM,EAChB,MAAM,EAAE;QAAE,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAAA;KAAE,EACnC,SAAS,EAAE;QACT,MAAM,EAAE,CAAC,OAAO,EAAE,KAAK,CAAC,IAAI,EAAE,IAAI,CAAC,EAAE,EAAE,SAAS,EAAE,OAAO,KAAK,IAAI,CAAC;QAEnE,KAAK,EAAE,CAAC,KAAK,EAAE,IAAI,KAAK,IAAI,CAAC;QAE7B,OAAO,EAAE,MAAM,IAAI,CAAC;KACrB,GACA,IAAI;IAiCP,WAAW,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE;QAAE,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAAA;KAAE;IAKjE,QAAQ,IAAI,IAAI;IAMhB,OAAO,CAAC,IAAI;CAQb"}
|
package/dist/remote.js
DELETED
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
// TODO: Remove once global `EventSource` makes it out of experimental
|
|
2
|
-
// in nodejs LTS.
|
|
3
|
-
import EventSource from "eventsource";
|
|
4
|
-
export class SkipExternalService {
|
|
5
|
-
constructor(url, control_url) {
|
|
6
|
-
this.url = url;
|
|
7
|
-
this.control_url = control_url;
|
|
8
|
-
this.resources = new Map();
|
|
9
|
-
}
|
|
10
|
-
// TODO: Support Skip external services going through a gateway.
|
|
11
|
-
static direct(entrypoint) {
|
|
12
|
-
let url = `http://${entrypoint.host}:${entrypoint.streaming_port.toString()}`;
|
|
13
|
-
let control_url = `http://${entrypoint.host}:${entrypoint.control_port.toString()}`;
|
|
14
|
-
if (entrypoint.secured) {
|
|
15
|
-
url = `https://${entrypoint.host}:${entrypoint.streaming_port.toString()}`;
|
|
16
|
-
control_url = `https://${entrypoint.host}:${entrypoint.control_port.toString()}`;
|
|
17
|
-
}
|
|
18
|
-
return new SkipExternalService(url, control_url);
|
|
19
|
-
}
|
|
20
|
-
subscribe(resource, params, callbacks) {
|
|
21
|
-
// TODO Manage Status
|
|
22
|
-
fetch(`${this.control_url}/v1/streams`, {
|
|
23
|
-
method: "POST",
|
|
24
|
-
headers: {
|
|
25
|
-
"Content-Type": "application/json",
|
|
26
|
-
},
|
|
27
|
-
body: JSON.stringify({
|
|
28
|
-
resource,
|
|
29
|
-
params,
|
|
30
|
-
}),
|
|
31
|
-
})
|
|
32
|
-
.then((resp) => resp.json())
|
|
33
|
-
.then((uuid) => {
|
|
34
|
-
const evSource = new EventSource(`${this.url}/v1/streams/${uuid}`);
|
|
35
|
-
evSource.addEventListener("init", (e) => {
|
|
36
|
-
const updates = JSON.parse(e.data);
|
|
37
|
-
callbacks.update(updates, true);
|
|
38
|
-
});
|
|
39
|
-
evSource.addEventListener("update", (e) => {
|
|
40
|
-
const updates = JSON.parse(e.data);
|
|
41
|
-
callbacks.update(updates, false);
|
|
42
|
-
});
|
|
43
|
-
evSource.onerror = (e) => {
|
|
44
|
-
console.log(e);
|
|
45
|
-
};
|
|
46
|
-
this.resources.set(this.toId(resource, params), evSource);
|
|
47
|
-
})
|
|
48
|
-
.catch((e) => {
|
|
49
|
-
console.log(e);
|
|
50
|
-
});
|
|
51
|
-
}
|
|
52
|
-
unsubscribe(resource, params) {
|
|
53
|
-
const closable = this.resources.get(this.toId(resource, params));
|
|
54
|
-
if (closable)
|
|
55
|
-
closable.close();
|
|
56
|
-
}
|
|
57
|
-
shutdown() {
|
|
58
|
-
for (const res of this.resources.values()) {
|
|
59
|
-
res.close();
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
toId(resource, params) {
|
|
63
|
-
// TODO: This is equivalent to `querystring.encode(params, ',', ':')`.
|
|
64
|
-
const strparams = [];
|
|
65
|
-
for (const key of Object.keys(params).sort()) {
|
|
66
|
-
strparams.push(`${key}:${params[key]}`);
|
|
67
|
-
}
|
|
68
|
-
return `${resource}[${strparams.join(",")}]`;
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
//# sourceMappingURL=remote.js.map
|
package/dist/remote.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"remote.js","sourceRoot":"","sources":["../src/remote.ts"],"names":[],"mappings":"AAAA,sEAAsE;AACtE,iBAAiB;AACjB,OAAO,WAAW,MAAM,aAAa,CAAC;AAUtC,MAAM,OAAO,mBAAmB;IAG9B,YACU,GAAW,EACX,WAAmB;QADnB,QAAG,GAAH,GAAG,CAAQ;QACX,gBAAW,GAAX,WAAW,CAAQ;QAJrB,cAAS,GAAG,IAAI,GAAG,EAAoB,CAAC;IAK7C,CAAC;IAEJ,gEAAgE;IAChE,MAAM,CAAC,MAAM,CAAC,UAAsB;QAClC,IAAI,GAAG,GAAG,UAAU,UAAU,CAAC,IAAI,IAAI,UAAU,CAAC,cAAc,CAAC,QAAQ,EAAE,EAAE,CAAC;QAC9E,IAAI,WAAW,GAAG,UAAU,UAAU,CAAC,IAAI,IAAI,UAAU,CAAC,YAAY,CAAC,QAAQ,EAAE,EAAE,CAAC;QACpF,IAAI,UAAU,CAAC,OAAO,EAAE,CAAC;YACvB,GAAG,GAAG,WAAW,UAAU,CAAC,IAAI,IAAI,UAAU,CAAC,cAAc,CAAC,QAAQ,EAAE,EAAE,CAAC;YAC3E,WAAW,GAAG,WAAW,UAAU,CAAC,IAAI,IAAI,UAAU,CAAC,YAAY,CAAC,QAAQ,EAAE,EAAE,CAAC;QACnF,CAAC;QACD,OAAO,IAAI,mBAAmB,CAAC,GAAG,EAAE,WAAW,CAAC,CAAC;IACnD,CAAC;IAED,SAAS,CACP,QAAgB,EAChB,MAAmC,EACnC,SAMC;QAED,qBAAqB;QACrB,KAAK,C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CAAC,CAAC;QACjB,CAAC,CAAC,CAAC;IACP,CAAC;IAED,WAAW,CAAC,QAAgB,EAAE,MAAmC;QAC/D,MAAM,QAAQ,GAAG,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC,CAAC;QACjE,IAAI,QAAQ;YAAE,QAAQ,CAAC,KAAK,EAAE,CAAC;IACjC,CAAC;IAED,QAAQ;QACN,KAAK,MAAM,GAAG,IAAI,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,EAAE,CAAC;YAC1C,GAAG,CAAC,KAAK,EAAE,CAAC;QACd,CAAC;IACH,CAAC;IAEO,IAAI,CAAC,QAAgB,EAAE,MAAmC;QAChE,sEAAsE;QACtE,MAAM,SAAS,GAAa,EAAE,CAAC;QAC/B,KAAK,MAAM,GAAG,IAAI,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC;YAC7C,SAAS,CAAC,IAAI,CAAC,GAAG,GAAG,IAAI,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;QAC1C,CAAC;QACD,OAAO,GAAG,QAAQ,IAAI,SAAS,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC;IAC/C,CAAC;CACF"}
|
package/dist/utils.d.ts
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import type { Nullable } from "@skip-wasm/std";
|
|
2
|
-
import { ManyToOneMapper } from "@skipruntime/api";
|
|
3
|
-
import type { Reducer, NonEmptyIterator, Json } from "@skipruntime/api";
|
|
4
|
-
export declare class Sum implements Reducer<number, number> {
|
|
5
|
-
default: number;
|
|
6
|
-
add(acc: number, value: number): number;
|
|
7
|
-
remove(acc: number, value: number): Nullable<number>;
|
|
8
|
-
}
|
|
9
|
-
export declare class Min implements Reducer<number, number> {
|
|
10
|
-
default: null;
|
|
11
|
-
add(acc: Nullable<number>, value: number): number;
|
|
12
|
-
remove(acc: number, value: number): Nullable<number>;
|
|
13
|
-
}
|
|
14
|
-
export declare class Max implements Reducer<number, number> {
|
|
15
|
-
default: null;
|
|
16
|
-
add(acc: Nullable<number>, value: number): number;
|
|
17
|
-
remove(acc: number, value: number): Nullable<number>;
|
|
18
|
-
}
|
|
19
|
-
export declare class CountMapper<K extends Json, V extends Json> extends ManyToOneMapper<K, V, number> {
|
|
20
|
-
mapValues(values: NonEmptyIterator<V>): number;
|
|
21
|
-
}
|
|
22
|
-
//# sourceMappingURL=utils.d.ts.map
|
package/dist/utils.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC/C,OAAO,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AACnD,OAAO,KAAK,EAAE,OAAO,EAAE,gBAAgB,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAExE,qBAAa,GAAI,YAAW,OAAO,CAAC,MAAM,EAAE,MAAM,CAAC;IACjD,OAAO,SAAK;IAEZ,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM;IAIvC,MAAM,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,QAAQ,CAAC,MAAM,CAAC;CAGrD;AAED,qBAAa,GAAI,YAAW,OAAO,CAAC,MAAM,EAAE,MAAM,CAAC;IACjD,OAAO,OAAQ;IAEf,GAAG,CAAC,GAAG,EAAE,QAAQ,CAAC,MAAM,CAAC,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM;IAIjD,MAAM,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,QAAQ,CAAC,MAAM,CAAC;CAGrD;AAED,qBAAa,GAAI,YAAW,OAAO,CAAC,MAAM,EAAE,MAAM,CAAC;IACjD,OAAO,OAAQ;IAEf,GAAG,CAAC,GAAG,EAAE,QAAQ,CAAC,MAAM,CAAC,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM;IAIjD,MAAM,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,QAAQ,CAAC,MAAM,CAAC;CAGrD;AAED,qBAAa,WAAW,CACtB,CAAC,SAAS,IAAI,EACd,CAAC,SAAS,IAAI,CACd,SAAQ,eAAe,CAAC,CAAC,EAAE,CAAC,EAAE,MAAM,CAAC;IACrC,SAAS,CAAC,MAAM,EAAE,gBAAgB,CAAC,CAAC,CAAC,GAAG,MAAM;CAG/C"}
|
package/dist/utils.js
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import { ManyToOneMapper } from "@skipruntime/api";
|
|
2
|
-
export class Sum {
|
|
3
|
-
constructor() {
|
|
4
|
-
this.default = 0;
|
|
5
|
-
}
|
|
6
|
-
add(acc, value) {
|
|
7
|
-
return acc + value;
|
|
8
|
-
}
|
|
9
|
-
remove(acc, value) {
|
|
10
|
-
return acc - value;
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
export class Min {
|
|
14
|
-
constructor() {
|
|
15
|
-
this.default = null;
|
|
16
|
-
}
|
|
17
|
-
add(acc, value) {
|
|
18
|
-
return acc === null ? value : Math.min(acc, value);
|
|
19
|
-
}
|
|
20
|
-
remove(acc, value) {
|
|
21
|
-
return value > acc ? acc : null;
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
export class Max {
|
|
25
|
-
constructor() {
|
|
26
|
-
this.default = null;
|
|
27
|
-
}
|
|
28
|
-
add(acc, value) {
|
|
29
|
-
return acc === null ? value : Math.max(acc, value);
|
|
30
|
-
}
|
|
31
|
-
remove(acc, value) {
|
|
32
|
-
return value < acc ? acc : null;
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
export class CountMapper extends ManyToOneMapper {
|
|
36
|
-
mapValues(values) {
|
|
37
|
-
return values.toArray().length;
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
//# sourceMappingURL=utils.js.map
|
package/dist/utils.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAGnD,MAAM,OAAO,GAAG;IAAhB;QACE,YAAO,GAAG,CAAC,CAAC;IASd,CAAC;IAPC,GAAG,CAAC,GAAW,EAAE,KAAa;QAC5B,OAAO,GAAG,GAAG,KAAK,CAAC;IACrB,CAAC;IAED,MAAM,CAAC,GAAW,EAAE,KAAa;QAC/B,OAAO,GAAG,GAAG,KAAK,CAAC;IACrB,CAAC;CACF;AAED,MAAM,OAAO,GAAG;IAAhB;QACE,YAAO,GAAG,IAAI,CAAC;IASjB,CAAC;IAPC,GAAG,CAAC,GAAqB,EAAE,KAAa;QACtC,OAAO,GAAG,KAAK,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;IACrD,CAAC;IAED,MAAM,CAAC,GAAW,EAAE,KAAa;QAC/B,OAAO,KAAK,GAAG,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC;IAClC,CAAC;CACF;AAED,MAAM,OAAO,GAAG;IAAhB;QACE,YAAO,GAAG,IAAI,CAAC;IASjB,CAAC;IAPC,GAAG,CAAC,GAAqB,EAAE,KAAa;QACtC,OAAO,GAAG,KAAK,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;IACrD,CAAC;IAED,MAAM,CAAC,GAAW,EAAE,KAAa;QAC/B,OAAO,KAAK,GAAG,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC;IAClC,CAAC;CACF;AAED,MAAM,OAAO,WAGX,SAAQ,eAA6B;IACrC,SAAS,CAAC,MAA2B;QACnC,OAAO,MAAM,CAAC,OAAO,EAAE,CAAC,MAAM,CAAC;IACjC,CAAC;CACF"}
|
package/src/errors.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export class UnknownCollectionError extends Error {}
|
package/src/remote.ts
DELETED
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
// TODO: Remove once global `EventSource` makes it out of experimental
|
|
2
|
-
// in nodejs LTS.
|
|
3
|
-
import EventSource from "eventsource";
|
|
4
|
-
|
|
5
|
-
import type { Entry, ExternalService, Json } from "@skipruntime/api";
|
|
6
|
-
|
|
7
|
-
import type { Entrypoint } from "./rest.js";
|
|
8
|
-
|
|
9
|
-
interface Closable {
|
|
10
|
-
close(): void;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export class SkipExternalService implements ExternalService {
|
|
14
|
-
private resources = new Map<string, Closable>();
|
|
15
|
-
|
|
16
|
-
constructor(
|
|
17
|
-
private url: string,
|
|
18
|
-
private control_url: string,
|
|
19
|
-
) {}
|
|
20
|
-
|
|
21
|
-
// TODO: Support Skip external services going through a gateway.
|
|
22
|
-
static direct(entrypoint: Entrypoint): SkipExternalService {
|
|
23
|
-
let url = `http://${entrypoint.host}:${entrypoint.streaming_port.toString()}`;
|
|
24
|
-
let control_url = `http://${entrypoint.host}:${entrypoint.control_port.toString()}`;
|
|
25
|
-
if (entrypoint.secured) {
|
|
26
|
-
url = `https://${entrypoint.host}:${entrypoint.streaming_port.toString()}`;
|
|
27
|
-
control_url = `https://${entrypoint.host}:${entrypoint.control_port.toString()}`;
|
|
28
|
-
}
|
|
29
|
-
return new SkipExternalService(url, control_url);
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
subscribe(
|
|
33
|
-
resource: string,
|
|
34
|
-
params: { [param: string]: string },
|
|
35
|
-
callbacks: {
|
|
36
|
-
update: (updates: Entry<Json, Json>[], isInitial: boolean) => void;
|
|
37
|
-
// FIXME: What is `error()` used for?
|
|
38
|
-
error: (error: Json) => void;
|
|
39
|
-
// FIXME: What is `loading()` used for?
|
|
40
|
-
loading: () => void;
|
|
41
|
-
},
|
|
42
|
-
): void {
|
|
43
|
-
// TODO Manage Status
|
|
44
|
-
fetch(`${this.control_url}/v1/streams`, {
|
|
45
|
-
method: "POST",
|
|
46
|
-
headers: {
|
|
47
|
-
"Content-Type": "application/json",
|
|
48
|
-
},
|
|
49
|
-
body: JSON.stringify({
|
|
50
|
-
resource,
|
|
51
|
-
params,
|
|
52
|
-
}),
|
|
53
|
-
})
|
|
54
|
-
.then((resp) => resp.json())
|
|
55
|
-
.then((uuid) => {
|
|
56
|
-
const evSource = new EventSource(`${this.url}/v1/streams/${uuid}`);
|
|
57
|
-
evSource.addEventListener("init", (e: MessageEvent<string>) => {
|
|
58
|
-
const updates = JSON.parse(e.data) as Entry<Json, Json>[];
|
|
59
|
-
callbacks.update(updates, true);
|
|
60
|
-
});
|
|
61
|
-
evSource.addEventListener("update", (e: MessageEvent<string>) => {
|
|
62
|
-
const updates = JSON.parse(e.data) as Entry<Json, Json>[];
|
|
63
|
-
callbacks.update(updates, false);
|
|
64
|
-
});
|
|
65
|
-
evSource.onerror = (e) => {
|
|
66
|
-
console.log(e);
|
|
67
|
-
};
|
|
68
|
-
this.resources.set(this.toId(resource, params), evSource);
|
|
69
|
-
})
|
|
70
|
-
.catch((e: unknown) => {
|
|
71
|
-
console.log(e);
|
|
72
|
-
});
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
unsubscribe(resource: string, params: { [param: string]: string }) {
|
|
76
|
-
const closable = this.resources.get(this.toId(resource, params));
|
|
77
|
-
if (closable) closable.close();
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
shutdown(): void {
|
|
81
|
-
for (const res of this.resources.values()) {
|
|
82
|
-
res.close();
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
private toId(resource: string, params: { [param: string]: string }): string {
|
|
87
|
-
// TODO: This is equivalent to `querystring.encode(params, ',', ':')`.
|
|
88
|
-
const strparams: string[] = [];
|
|
89
|
-
for (const key of Object.keys(params).sort()) {
|
|
90
|
-
strparams.push(`${key}:${params[key]}`);
|
|
91
|
-
}
|
|
92
|
-
return `${resource}[${strparams.join(",")}]`;
|
|
93
|
-
}
|
|
94
|
-
}
|
package/src/utils.ts
DELETED
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import type { Nullable } from "@skip-wasm/std";
|
|
2
|
-
import { ManyToOneMapper } from "@skipruntime/api";
|
|
3
|
-
import type { Reducer, NonEmptyIterator, Json } from "@skipruntime/api";
|
|
4
|
-
|
|
5
|
-
export class Sum implements Reducer<number, number> {
|
|
6
|
-
default = 0;
|
|
7
|
-
|
|
8
|
-
add(acc: number, value: number): number {
|
|
9
|
-
return acc + value;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
remove(acc: number, value: number): Nullable<number> {
|
|
13
|
-
return acc - value;
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export class Min implements Reducer<number, number> {
|
|
18
|
-
default = null;
|
|
19
|
-
|
|
20
|
-
add(acc: Nullable<number>, value: number): number {
|
|
21
|
-
return acc === null ? value : Math.min(acc, value);
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
remove(acc: number, value: number): Nullable<number> {
|
|
25
|
-
return value > acc ? acc : null;
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
export class Max implements Reducer<number, number> {
|
|
30
|
-
default = null;
|
|
31
|
-
|
|
32
|
-
add(acc: Nullable<number>, value: number): number {
|
|
33
|
-
return acc === null ? value : Math.max(acc, value);
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
remove(acc: number, value: number): Nullable<number> {
|
|
37
|
-
return value < acc ? acc : null;
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
export class CountMapper<
|
|
42
|
-
K extends Json,
|
|
43
|
-
V extends Json,
|
|
44
|
-
> extends ManyToOneMapper<K, V, number> {
|
|
45
|
-
mapValues(values: NonEmptyIterator<V>): number {
|
|
46
|
-
return values.toArray().length;
|
|
47
|
-
}
|
|
48
|
-
}
|