@skipruntime/helpers 0.0.13 → 0.0.14
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/src/external.d.ts +2 -3
- package/dist/src/external.d.ts.map +1 -1
- package/dist/src/external.js +1 -1
- package/dist/src/external.js.map +1 -1
- package/dist/src/index.d.ts +2 -2
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +2 -2
- package/dist/src/index.js.map +1 -1
- package/dist/src/remote.d.ts +24 -1
- package/dist/src/remote.d.ts.map +1 -1
- package/dist/src/remote.js +56 -0
- package/dist/src/remote.js.map +1 -1
- package/package.json +2 -2
- package/src/external.ts +2 -3
- package/src/index.ts +6 -2
- package/src/remote.ts +80 -1
package/dist/src/external.d.ts
CHANGED
|
@@ -11,8 +11,7 @@ export declare function defaultParamEncoder(params: Json): string;
|
|
|
11
11
|
/**
|
|
12
12
|
* Description of an external HTTP endpoint and how to poll it.
|
|
13
13
|
*
|
|
14
|
-
* The URL of the external resource is formed by appending the given base `url` and the result of `encodeParams(params)` where `params` are the parameters provided to [`Context#useExternalResource`](api/core/interfaces/Context#useexternalresource)
|
|
15
|
-
*
|
|
14
|
+
* The URL of the external resource is formed by appending the given base `url` and the result of `encodeParams(params)` where `params` are the parameters provided to [`Context#useExternalResource`](https://skiplabs.io/docs/api/core/interfaces/Context#useexternalresource)
|
|
16
15
|
*/
|
|
17
16
|
export interface PolledHTTPResource {
|
|
18
17
|
/**
|
|
@@ -46,7 +45,7 @@ export interface PolledHTTPResource {
|
|
|
46
45
|
/**
|
|
47
46
|
* An external HTTP service that is kept up-to-date by polling.
|
|
48
47
|
*
|
|
49
|
-
* A `PolledExternalService` may be composed of one or more [`PolledHTTPResource`](api/helpers/interfaces/PolledHTTPResource)s, each of which describes a single endpoint and how to poll it.
|
|
48
|
+
* A `PolledExternalService` may be composed of one or more [`PolledHTTPResource`](https://skiplabs.io/docs/api/helpers/interfaces/PolledHTTPResource)s, each of which describes a single endpoint and how to poll it.
|
|
50
49
|
*/
|
|
51
50
|
export declare class PolledExternalService implements ExternalService {
|
|
52
51
|
private readonly resources;
|
|
@@ -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,mBAAmB,CAAC;AAMtE;;;;;;;GAOG;AACH,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,IAAI,GAAG,MAAM,CASxD;AAED
|
|
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,mBAAmB,CAAC;AAMtE;;;;;;;GAOG;AACH,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,IAAI,GAAG,MAAM,CASxD;AAED;;;;GAIG;AACH,MAAM,WAAW,kBAAkB;IACjC;;OAEG;IACH,GAAG,EAAE,MAAM,CAAC;IACZ;;OAEG;IACH,QAAQ,EAAE,MAAM,CAAC;IACjB;;OAEG;IACH,IAAI,EAAE,CAAC,IAAI,EAAE,IAAI,KAAK,KAAK,CAAC,IAAI,EAAE,IAAI,CAAC,EAAE,CAAC;IAC1C;;;;OAIG;IACH,YAAY,CAAC,EAAE,CAAC,MAAM,EAAE,IAAI,KAAK,MAAM,CAAC;IACxC;;OAEG;IACH,OAAO,CAAC,EAAE;QAAE,OAAO,CAAC,EAAE;YAAE,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAAA;SAAE,CAAC;QAAC,OAAO,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;CACxE;AAED;;;;GAIG;AACH,qBAAa,qBAAsB,YAAW,eAAe;IASzD,OAAO,CAAC,QAAQ,CAAC,SAAS;IAR5B,OAAO,CAAC,QAAQ,CAAC,SAAS,CAA8B;IAExD;;;;OAIG;gBAEgB,SAAS,EAAE;QAC1B,CAAC,QAAQ,EAAE,MAAM,GAAG,kBAAkB,CAAC;KACxC;IAGH,SAAS,CACP,QAAQ,EAAE,MAAM,EAChB,YAAY,EAAE,MAAM,EACpB,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;IAwBH,WAAW,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI;IAQnC,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC;CAO1B"}
|
package/dist/src/external.js
CHANGED
|
@@ -25,7 +25,7 @@ export function defaultParamEncoder(params) {
|
|
|
25
25
|
/**
|
|
26
26
|
* An external HTTP service that is kept up-to-date by polling.
|
|
27
27
|
*
|
|
28
|
-
* A `PolledExternalService` may be composed of one or more [`PolledHTTPResource`](api/helpers/interfaces/PolledHTTPResource)s, each of which describes a single endpoint and how to poll it.
|
|
28
|
+
* A `PolledExternalService` may be composed of one or more [`PolledHTTPResource`](https://skiplabs.io/docs/api/helpers/interfaces/PolledHTTPResource)s, each of which describes a single endpoint and how to poll it.
|
|
29
29
|
*/
|
|
30
30
|
export class PolledExternalService {
|
|
31
31
|
/**
|
package/dist/src/external.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"external.js","sourceRoot":"","sources":["../../src/external.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,wBAAwB,EAAE,MAAM,mBAAmB,CAAC;AAC7D,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAItC;;;;;;;GAOG;AACH,MAAM,UAAU,mBAAmB,CAAC,MAAY;IAC9C,IAAI,OAAO,MAAM,IAAI,QAAQ,EAAE,C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AC;QACP,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,QAAQ,EAAE,WAAW,CAAC,IAAI,EAAE,QAAQ,CAAC,QAAQ,CAAC,CAAC,CAAC;IACrE,CAAC;IAED,WAAW,CAAC,QAAgB;QAC1B,MAAM,QAAQ,GAAG,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;QAC9C,IAAI,QAAQ,EAAE,CAAC;YACb,aAAa,CAAC,QAAQ,CAAC,CAAC;YACxB,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;QAClC,CAAC;IACH,CAAC;IAED,QAAQ;QACN,KAAK,MAAM,CAAC,QAAQ,EAAE,QAAQ,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE,CAAC;YAClE,aAAa,CAAC,QAAmB,CAAC,CAAC;YACnC,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;QAClC,CAAC;QACD,OAAO,OAAO,CAAC,OAAO,EAAE,CAAC;IAC3B,CAAC;CACF"}
|
package/dist/src/index.d.ts
CHANGED
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
*
|
|
4
4
|
* @packageDocumentation
|
|
5
5
|
*/
|
|
6
|
-
export { defaultParamEncoder, PolledExternalService } from "./external.js";
|
|
7
|
-
export { SkipExternalService } from "./remote.js";
|
|
6
|
+
export { defaultParamEncoder, PolledExternalService, type PolledHTTPResource, } from "./external.js";
|
|
7
|
+
export { SkipExternalService, asLeader, asFollower } from "./remote.js";
|
|
8
8
|
export { SkipServiceBroker, fetchJSON, type Entrypoint } from "./rest.js";
|
|
9
9
|
export { Count, Max, Min, Sum } from "./utils.js";
|
|
10
10
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/src/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,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EACL,mBAAmB,EACnB,qBAAqB,EACrB,KAAK,kBAAkB,GACxB,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,mBAAmB,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACxE,OAAO,EAAE,iBAAiB,EAAE,SAAS,EAAE,KAAK,UAAU,EAAE,MAAM,WAAW,CAAC;AAC1E,OAAO,EAAE,KAAK,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,MAAM,YAAY,CAAC"}
|
package/dist/src/index.js
CHANGED
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
*
|
|
4
4
|
* @packageDocumentation
|
|
5
5
|
*/
|
|
6
|
-
export { defaultParamEncoder, PolledExternalService } from "./external.js";
|
|
7
|
-
export { SkipExternalService } from "./remote.js";
|
|
6
|
+
export { defaultParamEncoder, PolledExternalService, } from "./external.js";
|
|
7
|
+
export { SkipExternalService, asLeader, asFollower } from "./remote.js";
|
|
8
8
|
export { SkipServiceBroker, fetchJSON } from "./rest.js";
|
|
9
9
|
export { Count, Max, Min, Sum } from "./utils.js";
|
|
10
10
|
//# sourceMappingURL=index.js.map
|
package/dist/src/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EACL,mBAAmB,EACnB,qBAAqB,GAEtB,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,mBAAmB,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACxE,OAAO,EAAE,iBAAiB,EAAE,SAAS,EAAmB,MAAM,WAAW,CAAC;AAC1E,OAAO,EAAE,KAAK,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,MAAM,YAAY,CAAC"}
|
package/dist/src/remote.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Entry, ExternalService, Json } from "@skipruntime/core";
|
|
1
|
+
import type { Entry, ExternalService, Json, SkipService } from "@skipruntime/core";
|
|
2
2
|
import type { Entrypoint } from "./rest.js";
|
|
3
3
|
/**
|
|
4
4
|
* An external Skip reactive service.
|
|
@@ -29,4 +29,27 @@ export declare class SkipExternalService implements ExternalService {
|
|
|
29
29
|
unsubscribe(instance: string): void;
|
|
30
30
|
shutdown(): Promise<void>;
|
|
31
31
|
}
|
|
32
|
+
/**
|
|
33
|
+
* Run a `SkipService` as the *leader* in a leader-follower topology.
|
|
34
|
+
*
|
|
35
|
+
* Instead of running a `service` on one machine, it can be distributed across multiple in a leader-follower architecture, with one "leader" maintaining the shared computation graph and one or more "followers" across which client-requested resource instances are distributed.
|
|
36
|
+
*
|
|
37
|
+
* @returns The *leader* component to run `service` in such a configuration.
|
|
38
|
+
*/
|
|
39
|
+
export declare function asLeader(service: SkipService): SkipService;
|
|
40
|
+
/**
|
|
41
|
+
* Run a `SkipService` as a *follower* in a leader-follower topology.
|
|
42
|
+
*
|
|
43
|
+
* Instead of running a `service` on one machine, it can be distributed across multiple in a leader-follower architecture, with one "leader" maintaining the shared computation graph and one or more "followers" across which client-requested resource instances are distributed.
|
|
44
|
+
*
|
|
45
|
+
* @returns The *follower* component to run `service` in such a configuration, given the leader's address and the names of the shared computation graph collections to be mirrored from it (typically the `ResourceInputs` of `service`).
|
|
46
|
+
*/
|
|
47
|
+
export declare function asFollower(service: SkipService, leader: {
|
|
48
|
+
leader: {
|
|
49
|
+
host: string;
|
|
50
|
+
streaming_port: number;
|
|
51
|
+
control_port: number;
|
|
52
|
+
};
|
|
53
|
+
collections: string[];
|
|
54
|
+
}): SkipService;
|
|
32
55
|
//# sourceMappingURL=remote.d.ts.map
|
package/dist/src/remote.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"remote.d.ts","sourceRoot":"","sources":["../../src/remote.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"remote.d.ts","sourceRoot":"","sources":["../../src/remote.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAGV,KAAK,EACL,eAAe,EACf,IAAI,EAGJ,WAAW,EACZ,MAAM,mBAAmB,CAAC;AAG3B,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,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;IA8BP,WAAW,CAAC,QAAQ,EAAE,MAAM;IAQ5B,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC;CAM1B;AAqBD;;;;;;GAMG;AACH,wBAAgB,QAAQ,CAAC,OAAO,EAAE,WAAW,GAAG,WAAW,CAM1D;AAED;;;;;;GAMG;AACH,wBAAgB,UAAU,CACxB,OAAO,EAAE,WAAW,EACpB,MAAM,EAAE;IACN,MAAM,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,cAAc,EAAE,MAAM,CAAC;QAAC,YAAY,EAAE,MAAM,CAAA;KAAE,CAAC;IACvE,WAAW,EAAE,MAAM,EAAE,CAAC;CACvB,GACA,WAAW,CAoBb"}
|
package/dist/src/remote.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// TODO: Remove once global `EventSource` makes it out of experimental
|
|
2
2
|
// in nodejs LTS.
|
|
3
3
|
import EventSource from "eventsource";
|
|
4
|
+
import { SkipError } from "@skipruntime/core";
|
|
4
5
|
/**
|
|
5
6
|
* An external Skip reactive service.
|
|
6
7
|
*
|
|
@@ -75,4 +76,59 @@ export class SkipExternalService {
|
|
|
75
76
|
return Promise.resolve();
|
|
76
77
|
}
|
|
77
78
|
}
|
|
79
|
+
class LeaderResource {
|
|
80
|
+
constructor(param) {
|
|
81
|
+
if (typeof param == "string")
|
|
82
|
+
this.collection = param;
|
|
83
|
+
else
|
|
84
|
+
throw new SkipError("Followers must specify a shared collection to mirror from leader.");
|
|
85
|
+
}
|
|
86
|
+
instantiate(collections) {
|
|
87
|
+
if (this.collection in collections)
|
|
88
|
+
return collections[this.collection];
|
|
89
|
+
throw new SkipError(`Unknown shared collection in leader: ${this.collection}`);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Run a `SkipService` as the *leader* in a leader-follower topology.
|
|
94
|
+
*
|
|
95
|
+
* Instead of running a `service` on one machine, it can be distributed across multiple in a leader-follower architecture, with one "leader" maintaining the shared computation graph and one or more "followers" across which client-requested resource instances are distributed.
|
|
96
|
+
*
|
|
97
|
+
* @returns The *leader* component to run `service` in such a configuration.
|
|
98
|
+
*/
|
|
99
|
+
export function asLeader(service) {
|
|
100
|
+
//TODO: add mechanism to split externals between leader/follower
|
|
101
|
+
return {
|
|
102
|
+
...service,
|
|
103
|
+
resources: { leader: LeaderResource },
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Run a `SkipService` as a *follower* in a leader-follower topology.
|
|
108
|
+
*
|
|
109
|
+
* Instead of running a `service` on one machine, it can be distributed across multiple in a leader-follower architecture, with one "leader" maintaining the shared computation graph and one or more "followers" across which client-requested resource instances are distributed.
|
|
110
|
+
*
|
|
111
|
+
* @returns The *follower* component to run `service` in such a configuration, given the leader's address and the names of the shared computation graph collections to be mirrored from it (typically the `ResourceInputs` of `service`).
|
|
112
|
+
*/
|
|
113
|
+
export function asFollower(service, leader) {
|
|
114
|
+
return {
|
|
115
|
+
...service,
|
|
116
|
+
initialData: {},
|
|
117
|
+
externalServices: {
|
|
118
|
+
...service.externalServices,
|
|
119
|
+
__skip_leader: SkipExternalService.direct(leader.leader),
|
|
120
|
+
},
|
|
121
|
+
createGraph(_inputs, context) {
|
|
122
|
+
const mirroredCollections = {};
|
|
123
|
+
for (const collection of leader.collections) {
|
|
124
|
+
mirroredCollections[collection] = context.useExternalResource({
|
|
125
|
+
service: "__skip_leader",
|
|
126
|
+
identifier: "leader",
|
|
127
|
+
params: collection,
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
return mirroredCollections;
|
|
131
|
+
},
|
|
132
|
+
};
|
|
133
|
+
}
|
|
78
134
|
//# sourceMappingURL=remote.js.map
|
package/dist/src/remote.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"remote.js","sourceRoot":"","sources":["../../src/remote.ts"],"names":[],"mappings":"AAAA,sEAAsE;AACtE,iBAAiB;AACjB,OAAO,WAAW,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"remote.js","sourceRoot":"","sources":["../../src/remote.ts"],"names":[],"mappings":"AAAA,sEAAsE;AACtE,iBAAiB;AACjB,OAAO,WAAW,MAAM,aAAa,CAAC;AAYtC,OA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,UAAU;iBACnB,CAAC,CAAC;YACL,CAAC;YACD,OAAO,mBAAmB,CAAC;QAC7B,CAAC;KACF,CAAC;AACJ,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@skipruntime/helpers",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.14",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": "./dist/src/index.js"
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
"dependencies": {
|
|
20
20
|
"eventsource": "^2.0.2",
|
|
21
21
|
"express": "^4.21.1",
|
|
22
|
-
"@skipruntime/core": "0.0.
|
|
22
|
+
"@skipruntime/core": "0.0.14"
|
|
23
23
|
},
|
|
24
24
|
"devDependencies": {
|
|
25
25
|
"@types/eventsource": "^1.1.15"
|
package/src/external.ts
CHANGED
|
@@ -26,8 +26,7 @@ export function defaultParamEncoder(params: Json): string {
|
|
|
26
26
|
/**
|
|
27
27
|
* Description of an external HTTP endpoint and how to poll it.
|
|
28
28
|
*
|
|
29
|
-
* The URL of the external resource is formed by appending the given base `url` and the result of `encodeParams(params)` where `params` are the parameters provided to [`Context#useExternalResource`](api/core/interfaces/Context#useexternalresource)
|
|
30
|
-
*
|
|
29
|
+
* The URL of the external resource is formed by appending the given base `url` and the result of `encodeParams(params)` where `params` are the parameters provided to [`Context#useExternalResource`](https://skiplabs.io/docs/api/core/interfaces/Context#useexternalresource)
|
|
31
30
|
*/
|
|
32
31
|
export interface PolledHTTPResource {
|
|
33
32
|
/**
|
|
@@ -57,7 +56,7 @@ export interface PolledHTTPResource {
|
|
|
57
56
|
/**
|
|
58
57
|
* An external HTTP service that is kept up-to-date by polling.
|
|
59
58
|
*
|
|
60
|
-
* A `PolledExternalService` may be composed of one or more [`PolledHTTPResource`](api/helpers/interfaces/PolledHTTPResource)s, each of which describes a single endpoint and how to poll it.
|
|
59
|
+
* A `PolledExternalService` may be composed of one or more [`PolledHTTPResource`](https://skiplabs.io/docs/api/helpers/interfaces/PolledHTTPResource)s, each of which describes a single endpoint and how to poll it.
|
|
61
60
|
*/
|
|
62
61
|
export class PolledExternalService implements ExternalService {
|
|
63
62
|
private readonly intervals = new Map<string, Timeout>();
|
package/src/index.ts
CHANGED
|
@@ -4,7 +4,11 @@
|
|
|
4
4
|
* @packageDocumentation
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
-
export {
|
|
8
|
-
|
|
7
|
+
export {
|
|
8
|
+
defaultParamEncoder,
|
|
9
|
+
PolledExternalService,
|
|
10
|
+
type PolledHTTPResource,
|
|
11
|
+
} from "./external.js";
|
|
12
|
+
export { SkipExternalService, asLeader, asFollower } from "./remote.js";
|
|
9
13
|
export { SkipServiceBroker, fetchJSON, type Entrypoint } from "./rest.js";
|
|
10
14
|
export { Count, Max, Min, Sum } from "./utils.js";
|
package/src/remote.ts
CHANGED
|
@@ -2,7 +2,17 @@
|
|
|
2
2
|
// in nodejs LTS.
|
|
3
3
|
import EventSource from "eventsource";
|
|
4
4
|
|
|
5
|
-
import type {
|
|
5
|
+
import type {
|
|
6
|
+
Context,
|
|
7
|
+
EagerCollection,
|
|
8
|
+
Entry,
|
|
9
|
+
ExternalService,
|
|
10
|
+
Json,
|
|
11
|
+
NamedCollections,
|
|
12
|
+
Resource,
|
|
13
|
+
SkipService,
|
|
14
|
+
} from "@skipruntime/core";
|
|
15
|
+
import { SkipError } from "@skipruntime/core";
|
|
6
16
|
|
|
7
17
|
import type { Entrypoint } from "./rest.js";
|
|
8
18
|
|
|
@@ -100,3 +110,72 @@ export class SkipExternalService implements ExternalService {
|
|
|
100
110
|
return Promise.resolve();
|
|
101
111
|
}
|
|
102
112
|
}
|
|
113
|
+
|
|
114
|
+
class LeaderResource implements Resource {
|
|
115
|
+
private collection: string;
|
|
116
|
+
|
|
117
|
+
constructor(param: Json) {
|
|
118
|
+
if (typeof param == "string") this.collection = param;
|
|
119
|
+
else
|
|
120
|
+
throw new SkipError(
|
|
121
|
+
"Followers must specify a shared collection to mirror from leader.",
|
|
122
|
+
);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
instantiate(collections: NamedCollections): EagerCollection<Json, Json> {
|
|
126
|
+
if (this.collection in collections) return collections[this.collection]!;
|
|
127
|
+
throw new SkipError(
|
|
128
|
+
`Unknown shared collection in leader: ${this.collection}`,
|
|
129
|
+
);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* Run a `SkipService` as the *leader* in a leader-follower topology.
|
|
135
|
+
*
|
|
136
|
+
* Instead of running a `service` on one machine, it can be distributed across multiple in a leader-follower architecture, with one "leader" maintaining the shared computation graph and one or more "followers" across which client-requested resource instances are distributed.
|
|
137
|
+
*
|
|
138
|
+
* @returns The *leader* component to run `service` in such a configuration.
|
|
139
|
+
*/
|
|
140
|
+
export function asLeader(service: SkipService): SkipService {
|
|
141
|
+
//TODO: add mechanism to split externals between leader/follower
|
|
142
|
+
return {
|
|
143
|
+
...service,
|
|
144
|
+
resources: { leader: LeaderResource },
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* Run a `SkipService` as a *follower* in a leader-follower topology.
|
|
150
|
+
*
|
|
151
|
+
* Instead of running a `service` on one machine, it can be distributed across multiple in a leader-follower architecture, with one "leader" maintaining the shared computation graph and one or more "followers" across which client-requested resource instances are distributed.
|
|
152
|
+
*
|
|
153
|
+
* @returns The *follower* component to run `service` in such a configuration, given the leader's address and the names of the shared computation graph collections to be mirrored from it (typically the `ResourceInputs` of `service`).
|
|
154
|
+
*/
|
|
155
|
+
export function asFollower(
|
|
156
|
+
service: SkipService,
|
|
157
|
+
leader: {
|
|
158
|
+
leader: { host: string; streaming_port: number; control_port: number };
|
|
159
|
+
collections: string[];
|
|
160
|
+
},
|
|
161
|
+
): SkipService {
|
|
162
|
+
return {
|
|
163
|
+
...service,
|
|
164
|
+
initialData: {},
|
|
165
|
+
externalServices: {
|
|
166
|
+
...service.externalServices,
|
|
167
|
+
__skip_leader: SkipExternalService.direct(leader.leader),
|
|
168
|
+
},
|
|
169
|
+
createGraph(_inputs: object, context: Context): NamedCollections {
|
|
170
|
+
const mirroredCollections: NamedCollections = {};
|
|
171
|
+
for (const collection of leader.collections) {
|
|
172
|
+
mirroredCollections[collection] = context.useExternalResource({
|
|
173
|
+
service: "__skip_leader",
|
|
174
|
+
identifier: "leader",
|
|
175
|
+
params: collection,
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
return mirroredCollections;
|
|
179
|
+
},
|
|
180
|
+
};
|
|
181
|
+
}
|