@skipruntime/helpers 0.0.6 → 0.0.7
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/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/dist/remote.d.ts +33 -0
- package/dist/remote.d.ts.map +1 -0
- package/dist/remote.js +88 -0
- package/dist/remote.js.map +1 -0
- package/dist/rest.d.ts +34 -7
- package/dist/rest.d.ts.map +1 -1
- package/dist/rest.js +15 -8
- package/dist/rest.js.map +1 -1
- package/package.json +2 -2
- package/src/index.ts +2 -8
- package/src/remote.ts +109 -0
- package/src/rest.ts +47 -19
package/dist/index.d.ts
CHANGED
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
* @packageDocumentation
|
|
5
5
|
*/
|
|
6
6
|
export { type ExternalResource, GenericExternalService, Polled, } from "./external.js";
|
|
7
|
+
export { SkipExternalService } from "./remote.js";
|
|
7
8
|
export { SkipServiceBroker, fetchJSON, type Entrypoint } from "./rest.js";
|
|
8
|
-
export { Count,
|
|
9
|
+
export { Count, Max, Min, Sum } from "@skipruntime/core";
|
|
9
10
|
//# 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;;;;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,
|
|
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,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAClD,OAAO,EAAE,iBAAiB,EAAE,SAAS,EAAE,KAAK,UAAU,EAAE,MAAM,WAAW,CAAC;AAC1E,OAAO,EAAE,KAAK,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,MAAM,mBAAmB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
* @packageDocumentation
|
|
5
5
|
*/
|
|
6
6
|
export { GenericExternalService, Polled, } from "./external.js";
|
|
7
|
+
export { SkipExternalService } from "./remote.js";
|
|
7
8
|
export { SkipServiceBroker, fetchJSON } from "./rest.js";
|
|
8
|
-
export { Count,
|
|
9
|
+
export { Count, Max, Min, Sum } from "@skipruntime/core";
|
|
9
10
|
//# 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;;;;GAIG;AAEH,OAAO,EAEL,sBAAsB,EACtB,MAAM,GACP,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,iBAAiB,EAAE,SAAS,EAAmB,MAAM,WAAW,CAAC;AAC1E,OAAO,
|
|
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,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAClD,OAAO,EAAE,iBAAiB,EAAE,SAAS,EAAmB,MAAM,WAAW,CAAC;AAC1E,OAAO,EAAE,KAAK,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,MAAM,mBAAmB,CAAC"}
|
package/dist/remote.d.ts
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { Entry, ExternalService, Json } from "@skipruntime/api";
|
|
2
|
+
import type { Entrypoint } from "./rest.js";
|
|
3
|
+
/**
|
|
4
|
+
* An external Skip reactive service.
|
|
5
|
+
*
|
|
6
|
+
* `SkipExternalService` provides an implementation of `ExternalService` for an external Skip service.
|
|
7
|
+
*/
|
|
8
|
+
export declare class SkipExternalService implements ExternalService {
|
|
9
|
+
private readonly url;
|
|
10
|
+
private readonly control_url;
|
|
11
|
+
private readonly resources;
|
|
12
|
+
/**
|
|
13
|
+
* @param url - URL to use for the service's streaming interface.
|
|
14
|
+
* @param control_url - URL to use for the service's control interface.
|
|
15
|
+
*/
|
|
16
|
+
constructor(url: string, control_url: string);
|
|
17
|
+
/**
|
|
18
|
+
* Constructor accepting an `Entrypoint`.
|
|
19
|
+
*
|
|
20
|
+
* @param entrypoint - The entry point for the external Skip service.
|
|
21
|
+
* @returns An `ExternalService` to interact with the service running at `entrypoint`.
|
|
22
|
+
*/
|
|
23
|
+
static direct(entrypoint: Entrypoint): SkipExternalService;
|
|
24
|
+
subscribe(resource: string, params: Json, callbacks: {
|
|
25
|
+
update: (updates: Entry<Json, Json>[], isInitial: boolean) => void;
|
|
26
|
+
error: (error: Json) => void;
|
|
27
|
+
loading: () => void;
|
|
28
|
+
}): void;
|
|
29
|
+
unsubscribe(resource: string, params: Json): void;
|
|
30
|
+
shutdown(): void;
|
|
31
|
+
private toId;
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=remote.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
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;;;;GAIG;AACH,qBAAa,mBAAoB,YAAW,eAAe;IAQvD,OAAO,CAAC,QAAQ,CAAC,GAAG;IACpB,OAAO,CAAC,QAAQ,CAAC,WAAW;IAR9B,OAAO,CAAC,QAAQ,CAAC,SAAS,CAA+B;IAEzD;;;OAGG;gBAEgB,GAAG,EAAE,MAAM,EACX,WAAW,EAAE,MAAM;IAGtC;;;;;OAKG;IAEH,MAAM,CAAC,MAAM,CAAC,UAAU,EAAE,UAAU,GAAG,mBAAmB;IAU1D,SAAS,CACP,QAAQ,EAAE,MAAM,EAChB,MAAM,EAAE,IAAI,EACZ,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,IAAI;IAK1C,QAAQ,IAAI,IAAI;IAMhB,OAAO,CAAC,IAAI;CAQb"}
|
package/dist/remote.js
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
// TODO: Remove once global `EventSource` makes it out of experimental
|
|
2
|
+
// in nodejs LTS.
|
|
3
|
+
import EventSource from "eventsource";
|
|
4
|
+
/**
|
|
5
|
+
* An external Skip reactive service.
|
|
6
|
+
*
|
|
7
|
+
* `SkipExternalService` provides an implementation of `ExternalService` for an external Skip service.
|
|
8
|
+
*/
|
|
9
|
+
export class SkipExternalService {
|
|
10
|
+
/**
|
|
11
|
+
* @param url - URL to use for the service's streaming interface.
|
|
12
|
+
* @param control_url - URL to use for the service's control interface.
|
|
13
|
+
*/
|
|
14
|
+
constructor(url, control_url) {
|
|
15
|
+
this.url = url;
|
|
16
|
+
this.control_url = control_url;
|
|
17
|
+
this.resources = new Map();
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Constructor accepting an `Entrypoint`.
|
|
21
|
+
*
|
|
22
|
+
* @param entrypoint - The entry point for the external Skip service.
|
|
23
|
+
* @returns An `ExternalService` to interact with the service running at `entrypoint`.
|
|
24
|
+
*/
|
|
25
|
+
// TODO: Support Skip external services going through a gateway.
|
|
26
|
+
static direct(entrypoint) {
|
|
27
|
+
let url = `http://${entrypoint.host}:${entrypoint.streaming_port.toString()}`;
|
|
28
|
+
let control_url = `http://${entrypoint.host}:${entrypoint.control_port.toString()}`;
|
|
29
|
+
if (entrypoint.secured) {
|
|
30
|
+
url = `https://${entrypoint.host}:${entrypoint.streaming_port.toString()}`;
|
|
31
|
+
control_url = `https://${entrypoint.host}:${entrypoint.control_port.toString()}`;
|
|
32
|
+
}
|
|
33
|
+
return new SkipExternalService(url, control_url);
|
|
34
|
+
}
|
|
35
|
+
subscribe(resource, params, callbacks) {
|
|
36
|
+
// TODO Manage Status
|
|
37
|
+
fetch(`${this.control_url}/v1/streams`, {
|
|
38
|
+
method: "POST",
|
|
39
|
+
headers: {
|
|
40
|
+
"Content-Type": "application/json",
|
|
41
|
+
},
|
|
42
|
+
body: JSON.stringify({
|
|
43
|
+
resource,
|
|
44
|
+
params,
|
|
45
|
+
}),
|
|
46
|
+
})
|
|
47
|
+
.then((resp) => resp.text())
|
|
48
|
+
.then((uuid) => {
|
|
49
|
+
const evSource = new EventSource(`${this.url}/v1/streams/${uuid}`);
|
|
50
|
+
evSource.addEventListener("init", (e) => {
|
|
51
|
+
const updates = JSON.parse(e.data);
|
|
52
|
+
callbacks.update(updates, true);
|
|
53
|
+
});
|
|
54
|
+
evSource.addEventListener("update", (e) => {
|
|
55
|
+
const updates = JSON.parse(e.data);
|
|
56
|
+
callbacks.update(updates, false);
|
|
57
|
+
});
|
|
58
|
+
evSource.onerror = (e) => {
|
|
59
|
+
console.log(e);
|
|
60
|
+
};
|
|
61
|
+
this.resources.set(this.toId(resource, params), evSource);
|
|
62
|
+
})
|
|
63
|
+
.catch((e) => {
|
|
64
|
+
console.log(e);
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
unsubscribe(resource, params) {
|
|
68
|
+
const closable = this.resources.get(this.toId(resource, params));
|
|
69
|
+
if (closable)
|
|
70
|
+
closable.close();
|
|
71
|
+
}
|
|
72
|
+
shutdown() {
|
|
73
|
+
for (const res of this.resources.values()) {
|
|
74
|
+
res.close();
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
toId(resource, params) {
|
|
78
|
+
if (typeof params == "object") {
|
|
79
|
+
const strparams = Object.entries(params)
|
|
80
|
+
.map(([key, value]) => `${key}:${btoa(JSON.stringify(value))}`)
|
|
81
|
+
.sort();
|
|
82
|
+
return `${resource}[${strparams.join(",")}]`;
|
|
83
|
+
}
|
|
84
|
+
else
|
|
85
|
+
return `${resource}[${btoa(JSON.stringify(params))}]`;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
//# sourceMappingURL=remote.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"remote.js","sourceRoot":"","sources":["../src/remote.ts"],"names":[],"mappings":"AAAA,sEAAsE;AACtE,iBAAiB;AACjB,OAAO,WAAW,MAAM,aAAa,CAAC;AAUtC;;;;GAIG;AACH,MAAM,OAAO,mBAAmB;IAG9B;;;OAGG;IACH,YACmB,GAAW,EACX,WAAmB;QADnB,QAAG,GAAH,GAAG,CAAQ;QACX,gBAAW,GAAX,WAAW,CAAQ;QARrB,cAAS,GAAG,IAAI,GAAG,EAAoB,CAAC;IAStD,CAAC;IAEJ;;;;;OAKG;IACH,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,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,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC;IAC/D,CAAC;CACF"}
|
package/dist/rest.d.ts
CHANGED
|
@@ -1,19 +1,46 @@
|
|
|
1
1
|
import type { Json, Entry } from "@skipruntime/api";
|
|
2
|
-
|
|
3
|
-
|
|
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
|
+
*/
|
|
7
|
+
export type Entrypoint = {
|
|
8
|
+
/**
|
|
9
|
+
* Hostname of the service.
|
|
10
|
+
*/
|
|
11
|
+
host: string;
|
|
12
|
+
/**
|
|
13
|
+
* Port to use for the service's streaming interface.
|
|
14
|
+
*/
|
|
15
|
+
streaming_port: number;
|
|
16
|
+
/**
|
|
17
|
+
* Port to use for the service's control interface.
|
|
18
|
+
*/
|
|
19
|
+
control_port: number;
|
|
20
|
+
/**
|
|
21
|
+
* Flag that when set indicates that https should be used instead of http.
|
|
22
|
+
*/
|
|
23
|
+
secured?: boolean;
|
|
24
|
+
};
|
|
4
25
|
/**
|
|
5
26
|
* Perform an HTTP fetch where input and output data is `Json`.
|
|
6
27
|
*
|
|
7
28
|
* @typeParam V - Type response is *assumed* to have.
|
|
8
29
|
* @param url - URL from which to fetch.
|
|
9
30
|
* @param method - HTTP method of request.
|
|
10
|
-
* @param
|
|
11
|
-
* @param
|
|
31
|
+
* @param options - Optional parameters.
|
|
32
|
+
* @param options.headers - Additional headers to add to request.
|
|
33
|
+
* @param options.body - Data to convert to JSON and send in request body.
|
|
34
|
+
* @param options.timeout - Timeout for request, in milliseconds. Defaults to 1000ms.
|
|
12
35
|
* @returns Response parsed as JSON, and headers.
|
|
13
36
|
*/
|
|
14
|
-
export declare function fetchJSON<V extends Json>(url: string, method?: "POST" | "GET" | "PUT" | "PATCH" | "HEAD" | "DELETE",
|
|
15
|
-
|
|
16
|
-
|
|
37
|
+
export declare function fetchJSON<V extends Json>(url: string, method?: "POST" | "GET" | "PUT" | "PATCH" | "HEAD" | "DELETE", options?: {
|
|
38
|
+
headers?: {
|
|
39
|
+
[header: string]: string;
|
|
40
|
+
};
|
|
41
|
+
body?: Json;
|
|
42
|
+
timeout?: number;
|
|
43
|
+
}): Promise<[V | null, Headers]>;
|
|
17
44
|
/**
|
|
18
45
|
* Wrapper providing a method-call interface to the Skip service HTTP APIs.
|
|
19
46
|
*
|
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;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC;IAEb;;OAEG;IACH,cAAc,EAAE,MAAM,CAAC;IAEvB;;OAEG;IACH,YAAY,EAAE,MAAM,CAAC;IAErB;;OAEG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB,CAAC;AAQF;;;;;;;;;;;GAWG;AACH,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;IACP,OAAO,CAAC,EAAE;QAAE,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAAA;KAAE,CAAC;IACvC,IAAI,CAAC,EAAE,IAAI,CAAC;IACZ,OAAO,CAAC,EAAE,MAAM,CAAC;CAIlB,GACA,OAAO,CAAC,CAAC,CAA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,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
|
@@ -10,19 +10,24 @@ function toHttp(entrypoint) {
|
|
|
10
10
|
* @typeParam V - Type response is *assumed* to have.
|
|
11
11
|
* @param url - URL from which to fetch.
|
|
12
12
|
* @param method - HTTP method of request.
|
|
13
|
-
* @param
|
|
14
|
-
* @param
|
|
13
|
+
* @param options - Optional parameters.
|
|
14
|
+
* @param options.headers - Additional headers to add to request.
|
|
15
|
+
* @param options.body - Data to convert to JSON and send in request body.
|
|
16
|
+
* @param options.timeout - Timeout for request, in milliseconds. Defaults to 1000ms.
|
|
15
17
|
* @returns Response parsed as JSON, and headers.
|
|
16
18
|
*/
|
|
17
|
-
export async function fetchJSON(url, method = "GET",
|
|
18
|
-
|
|
19
|
+
export async function fetchJSON(url, method = "GET", options = {
|
|
20
|
+
headers: {},
|
|
21
|
+
timeout: 1000,
|
|
22
|
+
}) {
|
|
23
|
+
const body = options.body ? JSON.stringify(options.body) : undefined;
|
|
19
24
|
const response = await fetch(url, {
|
|
20
25
|
method,
|
|
21
26
|
body,
|
|
22
27
|
headers: {
|
|
23
28
|
"Content-Type": "application/json",
|
|
24
29
|
Accept: "application/json",
|
|
25
|
-
...headers,
|
|
30
|
+
...options.headers,
|
|
26
31
|
},
|
|
27
32
|
signal: AbortSignal.timeout(1000),
|
|
28
33
|
});
|
|
@@ -65,7 +70,7 @@ export class SkipServiceBroker {
|
|
|
65
70
|
* @returns All entries in resource.
|
|
66
71
|
*/
|
|
67
72
|
async getAll(resource, params) {
|
|
68
|
-
const [data, _headers] = await fetchJSON(`${this.entrypoint}/v1/snapshot/${resource}`, "POST", {
|
|
73
|
+
const [data, _headers] = await fetchJSON(`${this.entrypoint}/v1/snapshot/${resource}`, "POST", { body: params });
|
|
69
74
|
return data ?? [];
|
|
70
75
|
}
|
|
71
76
|
/**
|
|
@@ -79,7 +84,7 @@ export class SkipServiceBroker {
|
|
|
79
84
|
* @returns The values associated to the key.
|
|
80
85
|
*/
|
|
81
86
|
async getArray(resource, params, key) {
|
|
82
|
-
const [data, _headers] = await fetchJSON(`${this.entrypoint}/v1/snapshot/${resource}`, "POST", {
|
|
87
|
+
const [data, _headers] = await fetchJSON(`${this.entrypoint}/v1/snapshot/${resource}/lookup`, "POST", { body: { key, params } });
|
|
83
88
|
return data ?? [];
|
|
84
89
|
}
|
|
85
90
|
/**
|
|
@@ -123,7 +128,9 @@ export class SkipServiceBroker {
|
|
|
123
128
|
* @returns {void}
|
|
124
129
|
*/
|
|
125
130
|
async patch(collection, entries) {
|
|
126
|
-
await fetchJSON(`${this.entrypoint}/v1/inputs/${collection}`, "PATCH", {
|
|
131
|
+
await fetchJSON(`${this.entrypoint}/v1/inputs/${collection}`, "PATCH", {
|
|
132
|
+
body: entries,
|
|
133
|
+
});
|
|
127
134
|
}
|
|
128
135
|
/**
|
|
129
136
|
* Remove all values associated with a key in a collection.
|
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;
|
|
1
|
+
{"version":3,"file":"rest.js","sourceRoot":"","sources":["../src/rest.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,uBAAuB,EAAE,MAAM,kBAAkB,CAAC;AA6B3D,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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AC,CAAC;IACvD,CAAC;IAED;;;;;;;;OAQG;IACH,KAAK,CAAC,KAAK,CACT,UAAkB,EAClB,OAAsB;QAEtB,MAAM,SAAS,CAAC,GAAG,IAAI,CAAC,UAAU,cAAc,UAAU,EAAE,EAAE,OAAO,EAAE;YACrE,IAAI,EAAE,OAAO;SACd,CAAC,CAAC;IACL,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.
|
|
3
|
+
"version": "0.0.7",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": "./dist/index.js",
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
"dependencies": {
|
|
22
22
|
"eventsource": "^2.0.2",
|
|
23
23
|
"express": "^4.21.1",
|
|
24
|
-
"@skipruntime/core": "^0.0.
|
|
24
|
+
"@skipruntime/core": "^0.0.4",
|
|
25
25
|
"@skipruntime/api": "^0.0.5"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
package/src/index.ts
CHANGED
|
@@ -9,12 +9,6 @@ export {
|
|
|
9
9
|
GenericExternalService,
|
|
10
10
|
Polled,
|
|
11
11
|
} from "./external.js";
|
|
12
|
+
export { SkipExternalService } from "./remote.js";
|
|
12
13
|
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";
|
|
14
|
+
export { Count, Max, Min, Sum } from "@skipruntime/core";
|
package/src/remote.ts
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
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
|
+
/**
|
|
14
|
+
* An external Skip reactive service.
|
|
15
|
+
*
|
|
16
|
+
* `SkipExternalService` provides an implementation of `ExternalService` for an external Skip service.
|
|
17
|
+
*/
|
|
18
|
+
export class SkipExternalService implements ExternalService {
|
|
19
|
+
private readonly resources = new Map<string, Closable>();
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* @param url - URL to use for the service's streaming interface.
|
|
23
|
+
* @param control_url - URL to use for the service's control interface.
|
|
24
|
+
*/
|
|
25
|
+
constructor(
|
|
26
|
+
private readonly url: string,
|
|
27
|
+
private readonly control_url: string,
|
|
28
|
+
) {}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Constructor accepting an `Entrypoint`.
|
|
32
|
+
*
|
|
33
|
+
* @param entrypoint - The entry point for the external Skip service.
|
|
34
|
+
* @returns An `ExternalService` to interact with the service running at `entrypoint`.
|
|
35
|
+
*/
|
|
36
|
+
// TODO: Support Skip external services going through a gateway.
|
|
37
|
+
static direct(entrypoint: Entrypoint): SkipExternalService {
|
|
38
|
+
let url = `http://${entrypoint.host}:${entrypoint.streaming_port.toString()}`;
|
|
39
|
+
let control_url = `http://${entrypoint.host}:${entrypoint.control_port.toString()}`;
|
|
40
|
+
if (entrypoint.secured) {
|
|
41
|
+
url = `https://${entrypoint.host}:${entrypoint.streaming_port.toString()}`;
|
|
42
|
+
control_url = `https://${entrypoint.host}:${entrypoint.control_port.toString()}`;
|
|
43
|
+
}
|
|
44
|
+
return new SkipExternalService(url, control_url);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
subscribe(
|
|
48
|
+
resource: string,
|
|
49
|
+
params: Json,
|
|
50
|
+
callbacks: {
|
|
51
|
+
update: (updates: Entry<Json, Json>[], isInitial: boolean) => void;
|
|
52
|
+
// FIXME: What is `error()` used for?
|
|
53
|
+
error: (error: Json) => void;
|
|
54
|
+
// FIXME: What is `loading()` used for?
|
|
55
|
+
loading: () => void;
|
|
56
|
+
},
|
|
57
|
+
): void {
|
|
58
|
+
// TODO Manage Status
|
|
59
|
+
fetch(`${this.control_url}/v1/streams`, {
|
|
60
|
+
method: "POST",
|
|
61
|
+
headers: {
|
|
62
|
+
"Content-Type": "application/json",
|
|
63
|
+
},
|
|
64
|
+
body: JSON.stringify({
|
|
65
|
+
resource,
|
|
66
|
+
params,
|
|
67
|
+
}),
|
|
68
|
+
})
|
|
69
|
+
.then((resp) => resp.text())
|
|
70
|
+
.then((uuid) => {
|
|
71
|
+
const evSource = new EventSource(`${this.url}/v1/streams/${uuid}`);
|
|
72
|
+
evSource.addEventListener("init", (e: MessageEvent<string>) => {
|
|
73
|
+
const updates = JSON.parse(e.data) as Entry<Json, Json>[];
|
|
74
|
+
callbacks.update(updates, true);
|
|
75
|
+
});
|
|
76
|
+
evSource.addEventListener("update", (e: MessageEvent<string>) => {
|
|
77
|
+
const updates = JSON.parse(e.data) as Entry<Json, Json>[];
|
|
78
|
+
callbacks.update(updates, false);
|
|
79
|
+
});
|
|
80
|
+
evSource.onerror = (e) => {
|
|
81
|
+
console.log(e);
|
|
82
|
+
};
|
|
83
|
+
this.resources.set(this.toId(resource, params), evSource);
|
|
84
|
+
})
|
|
85
|
+
.catch((e: unknown) => {
|
|
86
|
+
console.log(e);
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
unsubscribe(resource: string, params: Json) {
|
|
91
|
+
const closable = this.resources.get(this.toId(resource, params));
|
|
92
|
+
if (closable) closable.close();
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
shutdown(): void {
|
|
96
|
+
for (const res of this.resources.values()) {
|
|
97
|
+
res.close();
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
private toId(resource: string, params: Json): string {
|
|
102
|
+
if (typeof params == "object") {
|
|
103
|
+
const strparams = Object.entries(params)
|
|
104
|
+
.map(([key, value]) => `${key}:${btoa(JSON.stringify(value))}`)
|
|
105
|
+
.sort();
|
|
106
|
+
return `${resource}[${strparams.join(",")}]`;
|
|
107
|
+
} else return `${resource}[${btoa(JSON.stringify(params))}]`;
|
|
108
|
+
}
|
|
109
|
+
}
|
package/src/rest.ts
CHANGED
|
@@ -1,7 +1,32 @@
|
|
|
1
1
|
import type { Json, Entry } from "@skipruntime/api";
|
|
2
2
|
import { NonUniqueValueException } from "@skipruntime/api";
|
|
3
|
-
|
|
4
|
-
|
|
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
|
+
/**
|
|
11
|
+
* Hostname of the service.
|
|
12
|
+
*/
|
|
13
|
+
host: string;
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Port to use for the service's streaming interface.
|
|
17
|
+
*/
|
|
18
|
+
streaming_port: number;
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Port to use for the service's control interface.
|
|
22
|
+
*/
|
|
23
|
+
control_port: number;
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Flag that when set indicates that https should be used instead of http.
|
|
27
|
+
*/
|
|
28
|
+
secured?: boolean;
|
|
29
|
+
};
|
|
5
30
|
|
|
6
31
|
function toHttp(entrypoint: Entrypoint) {
|
|
7
32
|
if (entrypoint.secured)
|
|
@@ -15,24 +40,32 @@ function toHttp(entrypoint: Entrypoint) {
|
|
|
15
40
|
* @typeParam V - Type response is *assumed* to have.
|
|
16
41
|
* @param url - URL from which to fetch.
|
|
17
42
|
* @param method - HTTP method of request.
|
|
18
|
-
* @param
|
|
19
|
-
* @param
|
|
43
|
+
* @param options - Optional parameters.
|
|
44
|
+
* @param options.headers - Additional headers to add to request.
|
|
45
|
+
* @param options.body - Data to convert to JSON and send in request body.
|
|
46
|
+
* @param options.timeout - Timeout for request, in milliseconds. Defaults to 1000ms.
|
|
20
47
|
* @returns Response parsed as JSON, and headers.
|
|
21
48
|
*/
|
|
22
49
|
export async function fetchJSON<V extends Json>(
|
|
23
50
|
url: string,
|
|
24
51
|
method: "POST" | "GET" | "PUT" | "PATCH" | "HEAD" | "DELETE" = "GET",
|
|
25
|
-
|
|
26
|
-
|
|
52
|
+
options: {
|
|
53
|
+
headers?: { [header: string]: string };
|
|
54
|
+
body?: Json;
|
|
55
|
+
timeout?: number;
|
|
56
|
+
} = {
|
|
57
|
+
headers: {},
|
|
58
|
+
timeout: 1000,
|
|
59
|
+
},
|
|
27
60
|
): Promise<[V | null, Headers]> {
|
|
28
|
-
const body =
|
|
61
|
+
const body = options.body ? JSON.stringify(options.body) : undefined;
|
|
29
62
|
const response = await fetch(url, {
|
|
30
63
|
method,
|
|
31
64
|
body,
|
|
32
65
|
headers: {
|
|
33
66
|
"Content-Type": "application/json",
|
|
34
67
|
Accept: "application/json",
|
|
35
|
-
...headers,
|
|
68
|
+
...options.headers,
|
|
36
69
|
},
|
|
37
70
|
signal: AbortSignal.timeout(1000),
|
|
38
71
|
});
|
|
@@ -88,8 +121,7 @@ export class SkipServiceBroker {
|
|
|
88
121
|
const [data, _headers] = await fetchJSON<Entry<K, V>[]>(
|
|
89
122
|
`${this.entrypoint}/v1/snapshot/${resource}`,
|
|
90
123
|
"POST",
|
|
91
|
-
{},
|
|
92
|
-
params,
|
|
124
|
+
{ body: params },
|
|
93
125
|
);
|
|
94
126
|
return data ?? [];
|
|
95
127
|
}
|
|
@@ -110,10 +142,9 @@ export class SkipServiceBroker {
|
|
|
110
142
|
key: K,
|
|
111
143
|
): Promise<V[]> {
|
|
112
144
|
const [data, _headers] = await fetchJSON<V[]>(
|
|
113
|
-
`${this.entrypoint}/v1/snapshot/${resource}`,
|
|
145
|
+
`${this.entrypoint}/v1/snapshot/${resource}/lookup`,
|
|
114
146
|
"POST",
|
|
115
|
-
{},
|
|
116
|
-
{ key, params },
|
|
147
|
+
{ body: { key, params } },
|
|
117
148
|
);
|
|
118
149
|
return data ?? [];
|
|
119
150
|
}
|
|
@@ -172,12 +203,9 @@ export class SkipServiceBroker {
|
|
|
172
203
|
collection: string,
|
|
173
204
|
entries: Entry<K, V>[],
|
|
174
205
|
): Promise<void> {
|
|
175
|
-
await fetchJSON(
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
{},
|
|
179
|
-
entries,
|
|
180
|
-
);
|
|
206
|
+
await fetchJSON(`${this.entrypoint}/v1/inputs/${collection}`, "PATCH", {
|
|
207
|
+
body: entries,
|
|
208
|
+
});
|
|
181
209
|
}
|
|
182
210
|
|
|
183
211
|
/**
|