@dxos/functions 0.5.3-main.25e4f82 → 0.5.3-main.2ad0afc
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/lib/browser/chunk-366QG6IX.mjs +81 -0
- package/dist/lib/browser/chunk-366QG6IX.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +692 -493
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/types.mjs +12 -0
- package/dist/lib/browser/types.mjs.map +7 -0
- package/dist/lib/node/chunk-3VSJ57ZZ.cjs +97 -0
- package/dist/lib/node/chunk-3VSJ57ZZ.cjs.map +7 -0
- package/dist/lib/node/index.cjs +675 -486
- package/dist/lib/node/index.cjs.map +4 -4
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node/types.cjs +33 -0
- package/dist/lib/node/types.cjs.map +7 -0
- package/dist/types/src/function/function-registry.d.ts +24 -0
- package/dist/types/src/function/function-registry.d.ts.map +1 -0
- package/dist/types/src/function/function-registry.test.d.ts +2 -0
- package/dist/types/src/function/function-registry.test.d.ts.map +1 -0
- package/dist/types/src/function/index.d.ts +2 -0
- package/dist/types/src/function/index.d.ts.map +1 -0
- package/dist/types/src/index.d.ts +2 -0
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/runtime/dev-server.d.ts +7 -10
- package/dist/types/src/runtime/dev-server.d.ts.map +1 -1
- package/dist/types/src/runtime/scheduler.d.ts +11 -59
- package/dist/types/src/runtime/scheduler.d.ts.map +1 -1
- package/dist/types/src/testing/functions-integration.test.d.ts +2 -0
- package/dist/types/src/testing/functions-integration.test.d.ts.map +1 -0
- package/dist/types/src/testing/index.d.ts +4 -0
- package/dist/types/src/testing/index.d.ts.map +1 -0
- package/dist/types/src/testing/setup.d.ts +5 -0
- package/dist/types/src/testing/setup.d.ts.map +1 -0
- package/dist/types/src/testing/test/handler.d.ts +1 -0
- package/dist/types/src/testing/test/handler.d.ts.map +1 -1
- package/dist/types/src/testing/types.d.ts +9 -0
- package/dist/types/src/testing/types.d.ts.map +1 -0
- package/dist/types/src/testing/util.d.ts +3 -0
- package/dist/types/src/testing/util.d.ts.map +1 -0
- package/dist/types/src/trigger/index.d.ts +2 -0
- package/dist/types/src/trigger/index.d.ts.map +1 -0
- package/dist/types/src/trigger/trigger-registry.d.ts +40 -0
- package/dist/types/src/trigger/trigger-registry.d.ts.map +1 -0
- package/dist/types/src/trigger/trigger-registry.test.d.ts +2 -0
- package/dist/types/src/trigger/trigger-registry.test.d.ts.map +1 -0
- package/dist/types/src/trigger/type/index.d.ts +5 -0
- package/dist/types/src/trigger/type/index.d.ts.map +1 -0
- package/dist/types/src/trigger/type/subscription-trigger.d.ts +4 -0
- package/dist/types/src/trigger/type/subscription-trigger.d.ts.map +1 -0
- package/dist/types/src/trigger/type/timer-trigger.d.ts +4 -0
- package/dist/types/src/trigger/type/timer-trigger.d.ts.map +1 -0
- package/dist/types/src/trigger/type/webhook-trigger.d.ts +4 -0
- package/dist/types/src/trigger/type/webhook-trigger.d.ts.map +1 -0
- package/dist/types/src/trigger/type/websocket-trigger.d.ts +13 -0
- package/dist/types/src/trigger/type/websocket-trigger.d.ts.map +1 -0
- package/dist/types/src/types.d.ts +131 -111
- package/dist/types/src/types.d.ts.map +1 -1
- package/dist/types/src/util.d.ts +15 -0
- package/dist/types/src/util.d.ts.map +1 -0
- package/dist/types/src/util.test.d.ts +2 -0
- package/dist/types/src/util.test.d.ts.map +1 -0
- package/package.json +30 -14
- package/schema/functions.json +139 -116
- package/src/function/function-registry.test.ts +105 -0
- package/src/function/function-registry.ts +90 -0
- package/src/function/index.ts +5 -0
- package/src/index.ts +2 -0
- package/src/runtime/dev-server.test.ts +15 -35
- package/src/runtime/dev-server.ts +37 -20
- package/src/runtime/scheduler.test.ts +54 -75
- package/src/runtime/scheduler.ts +66 -298
- package/src/testing/functions-integration.test.ts +99 -0
- package/src/testing/index.ts +7 -0
- package/src/testing/setup.ts +45 -0
- package/src/testing/test/handler.ts +8 -2
- package/src/testing/types.ts +9 -0
- package/src/testing/util.ts +16 -0
- package/src/trigger/index.ts +5 -0
- package/src/trigger/trigger-registry.test.ts +255 -0
- package/src/trigger/trigger-registry.ts +189 -0
- package/src/trigger/type/index.ts +8 -0
- package/src/trigger/type/subscription-trigger.ts +80 -0
- package/src/trigger/type/timer-trigger.ts +44 -0
- package/src/trigger/type/webhook-trigger.ts +47 -0
- package/src/trigger/type/websocket-trigger.ts +91 -0
- package/src/types.ts +58 -42
- package/src/util.test.ts +43 -0
- package/src/util.ts +48 -0
package/dist/lib/node/index.cjs
CHANGED
|
@@ -29,61 +29,165 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
29
29
|
var node_exports = {};
|
|
30
30
|
__export(node_exports, {
|
|
31
31
|
DevServer: () => DevServer,
|
|
32
|
-
|
|
32
|
+
FunctionDef: () => import_chunk_3VSJ57ZZ.FunctionDef,
|
|
33
|
+
FunctionManifestSchema: () => import_chunk_3VSJ57ZZ.FunctionManifestSchema,
|
|
34
|
+
FunctionRegistry: () => FunctionRegistry,
|
|
35
|
+
FunctionTrigger: () => import_chunk_3VSJ57ZZ.FunctionTrigger,
|
|
33
36
|
Scheduler: () => Scheduler,
|
|
37
|
+
TriggerRegistry: () => TriggerRegistry,
|
|
34
38
|
subscriptionHandler: () => subscriptionHandler
|
|
35
39
|
});
|
|
36
40
|
module.exports = __toCommonJS(node_exports);
|
|
37
|
-
var
|
|
41
|
+
var import_chunk_3VSJ57ZZ = require("./chunk-3VSJ57ZZ.cjs");
|
|
42
|
+
var import_async = require("@dxos/async");
|
|
43
|
+
var import_echo = require("@dxos/client/echo");
|
|
44
|
+
var import_context = require("@dxos/context");
|
|
45
|
+
var import_keys = require("@dxos/keys");
|
|
38
46
|
var import_log = require("@dxos/log");
|
|
39
47
|
var import_util = require("@dxos/util");
|
|
48
|
+
var import_client = require("@dxos/client");
|
|
49
|
+
var import_log2 = require("@dxos/log");
|
|
50
|
+
var import_util2 = require("@dxos/util");
|
|
40
51
|
var import_express = __toESM(require("express"));
|
|
41
52
|
var import_get_port_please = require("get-port-please");
|
|
42
53
|
var import_node_path = require("node:path");
|
|
43
|
-
var
|
|
54
|
+
var import_async2 = require("@dxos/async");
|
|
55
|
+
var import_context2 = require("@dxos/context");
|
|
44
56
|
var import_invariant = require("@dxos/invariant");
|
|
45
|
-
var
|
|
57
|
+
var import_log3 = require("@dxos/log");
|
|
58
|
+
var import_node_path2 = __toESM(require("node:path"));
|
|
59
|
+
var import_async3 = require("@dxos/async");
|
|
60
|
+
var import_context3 = require("@dxos/context");
|
|
61
|
+
var import_log4 = require("@dxos/log");
|
|
62
|
+
var import_async4 = require("@dxos/async");
|
|
63
|
+
var import_echo2 = require("@dxos/client/echo");
|
|
64
|
+
var import_context4 = require("@dxos/context");
|
|
65
|
+
var import_echo_schema = require("@dxos/echo-schema");
|
|
66
|
+
var import_invariant2 = require("@dxos/invariant");
|
|
67
|
+
var import_keys2 = require("@dxos/keys");
|
|
68
|
+
var import_log5 = require("@dxos/log");
|
|
69
|
+
var import_util3 = require("@dxos/util");
|
|
70
|
+
var import_types = require("@braneframe/types");
|
|
71
|
+
var import_async5 = require("@dxos/async");
|
|
72
|
+
var import_echo_db = require("@dxos/echo-db");
|
|
73
|
+
var import_log6 = require("@dxos/log");
|
|
46
74
|
var import_cron = require("cron");
|
|
75
|
+
var import_async6 = require("@dxos/async");
|
|
76
|
+
var import_log7 = require("@dxos/log");
|
|
47
77
|
var import_get_port_please2 = require("get-port-please");
|
|
48
78
|
var import_node_http = __toESM(require("node:http"));
|
|
49
|
-
var
|
|
79
|
+
var import_log8 = require("@dxos/log");
|
|
50
80
|
var import_ws = __toESM(require("ws"));
|
|
51
|
-
var
|
|
52
|
-
var
|
|
53
|
-
var
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
81
|
+
var import_async7 = require("@dxos/async");
|
|
82
|
+
var import_log9 = require("@dxos/log");
|
|
83
|
+
var diff = (previous, next, comparator) => {
|
|
84
|
+
const remaining = [
|
|
85
|
+
...previous
|
|
86
|
+
];
|
|
87
|
+
const result = {
|
|
88
|
+
added: [],
|
|
89
|
+
updated: [],
|
|
90
|
+
removed: remaining
|
|
91
|
+
};
|
|
92
|
+
for (const object of next) {
|
|
93
|
+
const index = remaining.findIndex((item) => comparator(item, object));
|
|
94
|
+
if (index === -1) {
|
|
95
|
+
result.added.push(object);
|
|
96
|
+
} else {
|
|
97
|
+
result.updated.push(remaining[index]);
|
|
98
|
+
remaining.splice(index, 1);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
return result;
|
|
102
|
+
};
|
|
103
|
+
var intersection = (a, b, comparator) => a.filter((a2) => b.find((b2) => comparator(a2, b2)) !== void 0);
|
|
104
|
+
var __dxlog_file = "/home/runner/work/dxos/dxos/packages/core/functions/src/function/function-registry.ts";
|
|
105
|
+
var FunctionRegistry = class extends import_context.Resource {
|
|
106
|
+
constructor(_client) {
|
|
107
|
+
super();
|
|
108
|
+
this._client = _client;
|
|
109
|
+
this._functionBySpaceKey = new import_util.ComplexMap(import_keys.PublicKey.hash);
|
|
110
|
+
this.registered = new import_async.Event();
|
|
111
|
+
}
|
|
112
|
+
getFunctions(space) {
|
|
113
|
+
return this._functionBySpaceKey.get(space.key) ?? [];
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Loads function definitions from the manifest into the space.
|
|
117
|
+
* We first load all the definitions from the space to deduplicate by functionId.
|
|
118
|
+
*/
|
|
119
|
+
async register(space, functions) {
|
|
120
|
+
(0, import_log.log)("register", {
|
|
121
|
+
space: space.key,
|
|
122
|
+
functions: functions?.length ?? 0
|
|
123
|
+
}, {
|
|
124
|
+
F: __dxlog_file,
|
|
125
|
+
L: 39,
|
|
126
|
+
S: this,
|
|
127
|
+
C: (f, a) => f(...a)
|
|
128
|
+
});
|
|
129
|
+
if (!functions?.length) {
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
if (!space.db.graph.runtimeSchemaRegistry.hasSchema(import_chunk_3VSJ57ZZ.FunctionDef)) {
|
|
133
|
+
space.db.graph.runtimeSchemaRegistry.registerSchema(import_chunk_3VSJ57ZZ.FunctionDef);
|
|
134
|
+
}
|
|
135
|
+
const { objects: existing } = await space.db.query(import_echo.Filter.schema(import_chunk_3VSJ57ZZ.FunctionDef)).run();
|
|
136
|
+
const { added, removed } = diff(existing, functions, (a, b) => a.uri === b.uri);
|
|
137
|
+
added.forEach((def) => space.db.add((0, import_echo.create)(import_chunk_3VSJ57ZZ.FunctionDef, def)));
|
|
138
|
+
removed.forEach((def) => space.db.remove(def));
|
|
139
|
+
}
|
|
140
|
+
async _open() {
|
|
141
|
+
const spacesSubscription = this._client.spaces.subscribe(async (spaces) => {
|
|
142
|
+
for (const space of spaces) {
|
|
143
|
+
if (this._functionBySpaceKey.has(space.key)) {
|
|
144
|
+
continue;
|
|
145
|
+
}
|
|
146
|
+
const registered = [];
|
|
147
|
+
this._functionBySpaceKey.set(space.key, registered);
|
|
148
|
+
await space.waitUntilReady();
|
|
149
|
+
if (this._ctx.disposed) {
|
|
150
|
+
break;
|
|
151
|
+
}
|
|
152
|
+
this._ctx.onDispose(space.db.query(import_echo.Filter.schema(import_chunk_3VSJ57ZZ.FunctionDef)).subscribe(({ objects }) => {
|
|
153
|
+
const { added } = diff(registered, objects, (a, b) => a.uri === b.uri);
|
|
154
|
+
if (added.length > 0) {
|
|
155
|
+
registered.push(...added);
|
|
156
|
+
this.registered.emit({
|
|
157
|
+
space,
|
|
158
|
+
added
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
}));
|
|
162
|
+
}
|
|
163
|
+
});
|
|
164
|
+
this._ctx.onDispose(() => spacesSubscription.unsubscribe());
|
|
165
|
+
}
|
|
166
|
+
async _close(_) {
|
|
167
|
+
this._functionBySpaceKey.clear();
|
|
168
|
+
}
|
|
169
|
+
};
|
|
170
|
+
var __dxlog_file2 = "/home/runner/work/dxos/dxos/packages/core/functions/src/handler.ts";
|
|
67
171
|
var subscriptionHandler = (handler) => {
|
|
68
172
|
return ({ event: { data }, context, ...rest }) => {
|
|
69
173
|
const { client } = context;
|
|
70
174
|
const space = data.spaceKey ? client.spaces.get(import_client.PublicKey.from(data.spaceKey)) : void 0;
|
|
71
|
-
const objects = space ? data.objects?.map((id) => space.db.getObjectById(id)).filter(
|
|
175
|
+
const objects = space ? data.objects?.map((id) => space.db.getObjectById(id)).filter(import_util2.nonNullable) : [];
|
|
72
176
|
if (!!data.spaceKey && !space) {
|
|
73
|
-
|
|
177
|
+
import_log2.log.warn("invalid space", {
|
|
74
178
|
data
|
|
75
179
|
}, {
|
|
76
|
-
F:
|
|
180
|
+
F: __dxlog_file2,
|
|
77
181
|
L: 91,
|
|
78
182
|
S: void 0,
|
|
79
183
|
C: (f, a) => f(...a)
|
|
80
184
|
});
|
|
81
185
|
} else {
|
|
82
|
-
|
|
186
|
+
import_log2.log.info("handler", {
|
|
83
187
|
space: space?.key.truncate(),
|
|
84
188
|
objects: objects?.length
|
|
85
189
|
}, {
|
|
86
|
-
F:
|
|
190
|
+
F: __dxlog_file2,
|
|
87
191
|
L: 93,
|
|
88
192
|
S: void 0,
|
|
89
193
|
C: (f, a) => f(...a)
|
|
@@ -102,15 +206,28 @@ var subscriptionHandler = (handler) => {
|
|
|
102
206
|
});
|
|
103
207
|
};
|
|
104
208
|
};
|
|
105
|
-
var
|
|
209
|
+
var __dxlog_file3 = "/home/runner/work/dxos/dxos/packages/core/functions/src/runtime/dev-server.ts";
|
|
106
210
|
var DevServer = class {
|
|
107
|
-
|
|
108
|
-
constructor(_client, _options) {
|
|
211
|
+
constructor(_client, _functionsRegistry, _options) {
|
|
109
212
|
this._client = _client;
|
|
213
|
+
this._functionsRegistry = _functionsRegistry;
|
|
110
214
|
this._options = _options;
|
|
215
|
+
this._ctx = createContext();
|
|
111
216
|
this._handlers = {};
|
|
112
217
|
this._seq = 0;
|
|
113
|
-
this.update = new
|
|
218
|
+
this.update = new import_async2.Event();
|
|
219
|
+
this._functionsRegistry.registered.on(async ({ added }) => {
|
|
220
|
+
added.forEach((def) => this._load(def));
|
|
221
|
+
await this._safeUpdateRegistration();
|
|
222
|
+
(0, import_log3.log)("new functions loaded", {
|
|
223
|
+
added
|
|
224
|
+
}, {
|
|
225
|
+
F: __dxlog_file3,
|
|
226
|
+
L: 52,
|
|
227
|
+
S: this,
|
|
228
|
+
C: (f, a) => f(...a)
|
|
229
|
+
});
|
|
230
|
+
});
|
|
114
231
|
}
|
|
115
232
|
get stats() {
|
|
116
233
|
return {
|
|
@@ -119,8 +236,8 @@ var DevServer = class {
|
|
|
119
236
|
}
|
|
120
237
|
get endpoint() {
|
|
121
238
|
(0, import_invariant.invariant)(this._port, void 0, {
|
|
122
|
-
F:
|
|
123
|
-
L:
|
|
239
|
+
F: __dxlog_file3,
|
|
240
|
+
L: 63,
|
|
124
241
|
S: this,
|
|
125
242
|
A: [
|
|
126
243
|
"this._port",
|
|
@@ -135,45 +252,32 @@ var DevServer = class {
|
|
|
135
252
|
get functions() {
|
|
136
253
|
return Object.values(this._handlers);
|
|
137
254
|
}
|
|
138
|
-
async initialize() {
|
|
139
|
-
for (const def of this._options.manifest.functions) {
|
|
140
|
-
try {
|
|
141
|
-
await this._load(def);
|
|
142
|
-
} catch (err) {
|
|
143
|
-
import_log2.log.error("parsing function (check manifest)", err, {
|
|
144
|
-
F: __dxlog_file2,
|
|
145
|
-
L: 71,
|
|
146
|
-
S: this,
|
|
147
|
-
C: (f, a) => f(...a)
|
|
148
|
-
});
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
255
|
async start() {
|
|
153
256
|
(0, import_invariant.invariant)(!this._server, void 0, {
|
|
154
|
-
F:
|
|
155
|
-
L:
|
|
257
|
+
F: __dxlog_file3,
|
|
258
|
+
L: 76,
|
|
156
259
|
S: this,
|
|
157
260
|
A: [
|
|
158
261
|
"!this._server",
|
|
159
262
|
""
|
|
160
263
|
]
|
|
161
264
|
});
|
|
162
|
-
|
|
163
|
-
F:
|
|
164
|
-
L:
|
|
265
|
+
import_log3.log.info("starting...", void 0, {
|
|
266
|
+
F: __dxlog_file3,
|
|
267
|
+
L: 77,
|
|
165
268
|
S: this,
|
|
166
269
|
C: (f, a) => f(...a)
|
|
167
270
|
});
|
|
271
|
+
this._ctx = createContext();
|
|
168
272
|
const app = (0, import_express.default)();
|
|
169
273
|
app.use(import_express.default.json());
|
|
170
274
|
app.post("/:path", async (req, res) => {
|
|
171
275
|
const { path: path2 } = req.params;
|
|
172
276
|
try {
|
|
173
|
-
|
|
277
|
+
import_log3.log.info("calling", {
|
|
174
278
|
path: path2
|
|
175
279
|
}, {
|
|
176
|
-
F:
|
|
280
|
+
F: __dxlog_file3,
|
|
177
281
|
L: 87,
|
|
178
282
|
S: this,
|
|
179
283
|
C: (f, a) => f(...a)
|
|
@@ -185,8 +289,8 @@ var DevServer = class {
|
|
|
185
289
|
res.statusCode = await this.invoke("/" + path2, req.body);
|
|
186
290
|
res.end();
|
|
187
291
|
} catch (err) {
|
|
188
|
-
|
|
189
|
-
F:
|
|
292
|
+
import_log3.log.catch(err, void 0, {
|
|
293
|
+
F: __dxlog_file3,
|
|
190
294
|
L: 97,
|
|
191
295
|
S: this,
|
|
192
296
|
C: (f, a) => f(...a)
|
|
@@ -206,64 +310,61 @@ var DevServer = class {
|
|
|
206
310
|
this._server = app.listen(this._port);
|
|
207
311
|
try {
|
|
208
312
|
const { registrationId, endpoint } = await this._client.services.services.FunctionRegistryService.register({
|
|
209
|
-
endpoint: this.endpoint
|
|
210
|
-
functions: this.functions.map(({ def: { id, path: path2 } }) => ({
|
|
211
|
-
id,
|
|
212
|
-
path: path2
|
|
213
|
-
}))
|
|
313
|
+
endpoint: this.endpoint
|
|
214
314
|
});
|
|
215
|
-
|
|
315
|
+
import_log3.log.info("registered", {
|
|
216
316
|
endpoint
|
|
217
317
|
}, {
|
|
218
|
-
F:
|
|
219
|
-
L:
|
|
318
|
+
F: __dxlog_file3,
|
|
319
|
+
L: 112,
|
|
220
320
|
S: this,
|
|
221
321
|
C: (f, a) => f(...a)
|
|
222
322
|
});
|
|
223
323
|
this._proxy = endpoint;
|
|
224
324
|
this._functionServiceRegistration = registrationId;
|
|
325
|
+
await this._functionsRegistry.open(this._ctx);
|
|
225
326
|
} catch (err) {
|
|
226
327
|
await this.stop();
|
|
227
328
|
throw new Error("FunctionRegistryService not available (check plugin is configured).");
|
|
228
329
|
}
|
|
229
|
-
|
|
330
|
+
import_log3.log.info("started", {
|
|
230
331
|
port: this._port
|
|
231
332
|
}, {
|
|
232
|
-
F:
|
|
233
|
-
L:
|
|
333
|
+
F: __dxlog_file3,
|
|
334
|
+
L: 123,
|
|
234
335
|
S: this,
|
|
235
336
|
C: (f, a) => f(...a)
|
|
236
337
|
});
|
|
237
338
|
}
|
|
238
339
|
async stop() {
|
|
239
340
|
(0, import_invariant.invariant)(this._server, void 0, {
|
|
240
|
-
F:
|
|
241
|
-
L:
|
|
341
|
+
F: __dxlog_file3,
|
|
342
|
+
L: 127,
|
|
242
343
|
S: this,
|
|
243
344
|
A: [
|
|
244
345
|
"this._server",
|
|
245
346
|
""
|
|
246
347
|
]
|
|
247
348
|
});
|
|
248
|
-
|
|
249
|
-
F:
|
|
250
|
-
L:
|
|
349
|
+
import_log3.log.info("stopping...", void 0, {
|
|
350
|
+
F: __dxlog_file3,
|
|
351
|
+
L: 128,
|
|
251
352
|
S: this,
|
|
252
353
|
C: (f, a) => f(...a)
|
|
253
354
|
});
|
|
254
|
-
const trigger = new
|
|
355
|
+
const trigger = new import_async2.Trigger();
|
|
255
356
|
this._server.close(async () => {
|
|
256
|
-
|
|
257
|
-
F:
|
|
258
|
-
L:
|
|
357
|
+
import_log3.log.info("server stopped", void 0, {
|
|
358
|
+
F: __dxlog_file3,
|
|
359
|
+
L: 132,
|
|
259
360
|
S: this,
|
|
260
361
|
C: (f, a) => f(...a)
|
|
261
362
|
});
|
|
262
363
|
try {
|
|
263
364
|
if (this._functionServiceRegistration) {
|
|
264
365
|
(0, import_invariant.invariant)(this._client.services.services.FunctionRegistryService, void 0, {
|
|
265
|
-
F:
|
|
266
|
-
L:
|
|
366
|
+
F: __dxlog_file3,
|
|
367
|
+
L: 135,
|
|
267
368
|
S: this,
|
|
268
369
|
A: [
|
|
269
370
|
"this._client.services.services.FunctionRegistryService",
|
|
@@ -273,11 +374,11 @@ var DevServer = class {
|
|
|
273
374
|
await this._client.services.services.FunctionRegistryService.unregister({
|
|
274
375
|
registrationId: this._functionServiceRegistration
|
|
275
376
|
});
|
|
276
|
-
|
|
377
|
+
import_log3.log.info("unregistered", {
|
|
277
378
|
registrationId: this._functionServiceRegistration
|
|
278
379
|
}, {
|
|
279
|
-
F:
|
|
280
|
-
L:
|
|
380
|
+
F: __dxlog_file3,
|
|
381
|
+
L: 140,
|
|
281
382
|
S: this,
|
|
282
383
|
C: (f, a) => f(...a)
|
|
283
384
|
});
|
|
@@ -292,9 +393,9 @@ var DevServer = class {
|
|
|
292
393
|
await trigger.wait();
|
|
293
394
|
this._port = void 0;
|
|
294
395
|
this._server = void 0;
|
|
295
|
-
|
|
296
|
-
F:
|
|
297
|
-
L:
|
|
396
|
+
import_log3.log.info("stopped", void 0, {
|
|
397
|
+
F: __dxlog_file3,
|
|
398
|
+
L: 154,
|
|
298
399
|
S: this,
|
|
299
400
|
C: (f, a) => f(...a)
|
|
300
401
|
});
|
|
@@ -302,58 +403,85 @@ var DevServer = class {
|
|
|
302
403
|
/**
|
|
303
404
|
* Load function.
|
|
304
405
|
*/
|
|
305
|
-
async _load(def, force
|
|
306
|
-
const {
|
|
406
|
+
async _load(def, force) {
|
|
407
|
+
const { uri, route, handler } = def;
|
|
307
408
|
const filePath = (0, import_node_path.join)(this._options.baseDir, handler);
|
|
308
|
-
|
|
309
|
-
|
|
409
|
+
import_log3.log.info("loading", {
|
|
410
|
+
uri,
|
|
310
411
|
force
|
|
311
412
|
}, {
|
|
312
|
-
F:
|
|
313
|
-
L:
|
|
413
|
+
F: __dxlog_file3,
|
|
414
|
+
L: 163,
|
|
314
415
|
S: this,
|
|
315
416
|
C: (f, a) => f(...a)
|
|
316
417
|
});
|
|
317
418
|
if (force) {
|
|
318
|
-
Object.keys(__require.cache).filter((key) => key.startsWith(filePath)).forEach((key) => {
|
|
319
|
-
delete __require.cache[key];
|
|
419
|
+
Object.keys(import_chunk_3VSJ57ZZ.__require.cache).filter((key) => key.startsWith(filePath)).forEach((key) => {
|
|
420
|
+
delete import_chunk_3VSJ57ZZ.__require.cache[key];
|
|
320
421
|
});
|
|
321
422
|
}
|
|
322
|
-
const module2 = __require(filePath);
|
|
423
|
+
const module2 = (0, import_chunk_3VSJ57ZZ.__require)(filePath);
|
|
323
424
|
if (typeof module2.default !== "function") {
|
|
324
|
-
throw new Error(`Handler must export default function: ${
|
|
425
|
+
throw new Error(`Handler must export default function: ${uri}`);
|
|
325
426
|
}
|
|
326
|
-
this._handlers[
|
|
427
|
+
this._handlers[route] = {
|
|
327
428
|
def,
|
|
328
429
|
handler: module2.default
|
|
329
430
|
};
|
|
330
431
|
}
|
|
432
|
+
async _safeUpdateRegistration() {
|
|
433
|
+
(0, import_invariant.invariant)(this._functionServiceRegistration, void 0, {
|
|
434
|
+
F: __dxlog_file3,
|
|
435
|
+
L: 185,
|
|
436
|
+
S: this,
|
|
437
|
+
A: [
|
|
438
|
+
"this._functionServiceRegistration",
|
|
439
|
+
""
|
|
440
|
+
]
|
|
441
|
+
});
|
|
442
|
+
try {
|
|
443
|
+
await this._client.services.services.FunctionRegistryService.updateRegistration({
|
|
444
|
+
registrationId: this._functionServiceRegistration,
|
|
445
|
+
functions: this.functions.map(({ def: { id, route } }) => ({
|
|
446
|
+
id,
|
|
447
|
+
route
|
|
448
|
+
}))
|
|
449
|
+
});
|
|
450
|
+
} catch (e) {
|
|
451
|
+
import_log3.log.catch(e, void 0, {
|
|
452
|
+
F: __dxlog_file3,
|
|
453
|
+
L: 192,
|
|
454
|
+
S: this,
|
|
455
|
+
C: (f, a) => f(...a)
|
|
456
|
+
});
|
|
457
|
+
}
|
|
458
|
+
}
|
|
331
459
|
/**
|
|
332
460
|
* Invoke function.
|
|
333
461
|
*/
|
|
334
462
|
async invoke(path2, data) {
|
|
335
463
|
const seq = ++this._seq;
|
|
336
464
|
const now = Date.now();
|
|
337
|
-
|
|
465
|
+
import_log3.log.info("req", {
|
|
338
466
|
seq,
|
|
339
467
|
path: path2
|
|
340
468
|
}, {
|
|
341
|
-
F:
|
|
342
|
-
L:
|
|
469
|
+
F: __dxlog_file3,
|
|
470
|
+
L: 203,
|
|
343
471
|
S: this,
|
|
344
472
|
C: (f, a) => f(...a)
|
|
345
473
|
});
|
|
346
474
|
const statusCode = await this._invoke(path2, {
|
|
347
475
|
data
|
|
348
476
|
});
|
|
349
|
-
|
|
477
|
+
import_log3.log.info("res", {
|
|
350
478
|
seq,
|
|
351
479
|
path: path2,
|
|
352
480
|
statusCode,
|
|
353
481
|
duration: Date.now() - now
|
|
354
482
|
}, {
|
|
355
|
-
F:
|
|
356
|
-
L:
|
|
483
|
+
F: __dxlog_file3,
|
|
484
|
+
L: 206,
|
|
357
485
|
S: this,
|
|
358
486
|
C: (f, a) => f(...a)
|
|
359
487
|
});
|
|
@@ -363,8 +491,8 @@ var DevServer = class {
|
|
|
363
491
|
async _invoke(path2, event) {
|
|
364
492
|
const { handler } = this._handlers[path2] ?? {};
|
|
365
493
|
(0, import_invariant.invariant)(handler, `invalid path: ${path2}`, {
|
|
366
|
-
F:
|
|
367
|
-
L:
|
|
494
|
+
F: __dxlog_file3,
|
|
495
|
+
L: 213,
|
|
368
496
|
S: this,
|
|
369
497
|
A: [
|
|
370
498
|
"handler",
|
|
@@ -390,111 +518,98 @@ var DevServer = class {
|
|
|
390
518
|
return statusCode;
|
|
391
519
|
}
|
|
392
520
|
};
|
|
393
|
-
var
|
|
521
|
+
var createContext = () => new import_context2.Context({
|
|
522
|
+
name: "DevServer"
|
|
523
|
+
});
|
|
524
|
+
var __dxlog_file4 = "/home/runner/work/dxos/dxos/packages/core/functions/src/runtime/scheduler.ts";
|
|
394
525
|
var Scheduler = class {
|
|
395
|
-
constructor(
|
|
396
|
-
this.
|
|
397
|
-
this.
|
|
526
|
+
constructor(functions, triggers, _options = {}) {
|
|
527
|
+
this.functions = functions;
|
|
528
|
+
this.triggers = triggers;
|
|
398
529
|
this._options = _options;
|
|
399
|
-
this.
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
530
|
+
this._ctx = createContext2();
|
|
531
|
+
this._callMutex = new import_async3.Mutex();
|
|
532
|
+
this.functions.registered.on(async ({ space, added }) => {
|
|
533
|
+
await this._safeActivateTriggers(space, this.triggers.getInactiveTriggers(space), added);
|
|
534
|
+
});
|
|
535
|
+
this.triggers.registered.on(async ({ space, triggers: triggers2 }) => {
|
|
536
|
+
await this._safeActivateTriggers(space, triggers2, this.functions.getFunctions(space));
|
|
537
|
+
});
|
|
406
538
|
}
|
|
407
539
|
async start() {
|
|
408
|
-
this.
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
await this.mount(new import_context.Context(), space, trigger);
|
|
413
|
-
}
|
|
414
|
-
}
|
|
415
|
-
});
|
|
540
|
+
await this._ctx.dispose();
|
|
541
|
+
this._ctx = createContext2();
|
|
542
|
+
await this.functions.open(this._ctx);
|
|
543
|
+
await this.triggers.open(this._ctx);
|
|
416
544
|
}
|
|
417
545
|
async stop() {
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
546
|
+
await this._ctx.dispose();
|
|
547
|
+
await this.functions.close();
|
|
548
|
+
await this.triggers.close();
|
|
421
549
|
}
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
const def = this._manifest.functions.find((config) => config.id === trigger.function);
|
|
431
|
-
(0, import_invariant2.invariant)(def, `Function not found: ${trigger.function}`, {
|
|
432
|
-
F: __dxlog_file3,
|
|
433
|
-
L: 76,
|
|
434
|
-
S: this,
|
|
435
|
-
A: [
|
|
436
|
-
"def",
|
|
437
|
-
"`Function not found: ${trigger.function}`"
|
|
438
|
-
]
|
|
550
|
+
// TODO(burdon): Remove and update registries directly.
|
|
551
|
+
async register(space, manifest) {
|
|
552
|
+
await this.functions.register(space, manifest.functions);
|
|
553
|
+
await this.triggers.register(space, manifest);
|
|
554
|
+
}
|
|
555
|
+
async _safeActivateTriggers(space, triggers, functions) {
|
|
556
|
+
const mountTasks = triggers.map((trigger) => {
|
|
557
|
+
return this.activate(space, functions, trigger);
|
|
439
558
|
});
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
space: space.key,
|
|
448
|
-
trigger
|
|
559
|
+
await Promise.all(mountTasks).catch(import_log4.log.catch);
|
|
560
|
+
}
|
|
561
|
+
async activate(space, functions, fnTrigger) {
|
|
562
|
+
const definition = functions.find((def) => def.uri === fnTrigger.function);
|
|
563
|
+
if (!definition) {
|
|
564
|
+
import_log4.log.info("function is not found for trigger", {
|
|
565
|
+
fnTrigger
|
|
449
566
|
}, {
|
|
450
|
-
F:
|
|
451
|
-
L:
|
|
567
|
+
F: __dxlog_file4,
|
|
568
|
+
L: 78,
|
|
452
569
|
S: this,
|
|
453
570
|
C: (f, a) => f(...a)
|
|
454
571
|
});
|
|
455
|
-
|
|
456
|
-
return;
|
|
457
|
-
}
|
|
458
|
-
if (trigger.timer) {
|
|
459
|
-
await this._createTimer(ctx, space, def, trigger);
|
|
460
|
-
}
|
|
461
|
-
if (trigger.webhook) {
|
|
462
|
-
await this._createWebhook(ctx, space, def, trigger);
|
|
463
|
-
}
|
|
464
|
-
if (trigger.websocket) {
|
|
465
|
-
await this._createWebsocket(ctx, space, def, trigger);
|
|
466
|
-
}
|
|
467
|
-
if (trigger.subscription) {
|
|
468
|
-
await this._createSubscription(ctx, space, def, trigger);
|
|
469
|
-
}
|
|
470
|
-
}
|
|
471
|
-
}
|
|
472
|
-
async unmount(id, spaceKey) {
|
|
473
|
-
const key = {
|
|
474
|
-
id,
|
|
475
|
-
spaceKey
|
|
476
|
-
};
|
|
477
|
-
const { ctx } = this._mounts.get(key) ?? {};
|
|
478
|
-
if (ctx) {
|
|
479
|
-
this._mounts.delete(key);
|
|
480
|
-
await ctx.dispose();
|
|
572
|
+
return;
|
|
481
573
|
}
|
|
574
|
+
await this.triggers.activate({
|
|
575
|
+
space
|
|
576
|
+
}, fnTrigger, async (args) => {
|
|
577
|
+
return this._callMutex.executeSynchronized(() => {
|
|
578
|
+
return this._execFunction(definition, fnTrigger, {
|
|
579
|
+
meta: fnTrigger.meta,
|
|
580
|
+
data: {
|
|
581
|
+
...args,
|
|
582
|
+
spaceKey: space.key
|
|
583
|
+
}
|
|
584
|
+
});
|
|
585
|
+
});
|
|
586
|
+
});
|
|
587
|
+
(0, import_log4.log)("activated trigger", {
|
|
588
|
+
space: space.key,
|
|
589
|
+
trigger: fnTrigger
|
|
590
|
+
}, {
|
|
591
|
+
F: __dxlog_file4,
|
|
592
|
+
L: 91,
|
|
593
|
+
S: this,
|
|
594
|
+
C: (f, a) => f(...a)
|
|
595
|
+
});
|
|
482
596
|
}
|
|
483
|
-
async _execFunction(def, trigger, data) {
|
|
597
|
+
async _execFunction(def, trigger, { data, meta }) {
|
|
484
598
|
let status = 0;
|
|
485
599
|
try {
|
|
486
|
-
const payload = Object.assign({}, {
|
|
487
|
-
meta
|
|
600
|
+
const payload = Object.assign({}, meta && {
|
|
601
|
+
meta
|
|
488
602
|
}, data);
|
|
489
603
|
const { endpoint, callback } = this._options;
|
|
490
604
|
if (endpoint) {
|
|
491
|
-
const url = import_node_path2.default.join(endpoint, def.
|
|
492
|
-
|
|
493
|
-
function: def.
|
|
494
|
-
url
|
|
605
|
+
const url = import_node_path2.default.join(endpoint, def.route);
|
|
606
|
+
import_log4.log.info("exec", {
|
|
607
|
+
function: def.uri,
|
|
608
|
+
url,
|
|
609
|
+
triggerType: trigger.spec.type
|
|
495
610
|
}, {
|
|
496
|
-
F:
|
|
497
|
-
L:
|
|
611
|
+
F: __dxlog_file4,
|
|
612
|
+
L: 108,
|
|
498
613
|
S: this,
|
|
499
614
|
C: (f, a) => f(...a)
|
|
500
615
|
});
|
|
@@ -507,11 +622,11 @@ var Scheduler = class {
|
|
|
507
622
|
});
|
|
508
623
|
status = response.status;
|
|
509
624
|
} else if (callback) {
|
|
510
|
-
|
|
511
|
-
function: def.
|
|
625
|
+
import_log4.log.info("exec", {
|
|
626
|
+
function: def.uri
|
|
512
627
|
}, {
|
|
513
|
-
F:
|
|
514
|
-
L:
|
|
628
|
+
F: __dxlog_file4,
|
|
629
|
+
L: 119,
|
|
515
630
|
S: this,
|
|
516
631
|
C: (f, a) => f(...a)
|
|
517
632
|
});
|
|
@@ -520,22 +635,22 @@ var Scheduler = class {
|
|
|
520
635
|
if (status && status >= 400) {
|
|
521
636
|
throw new Error(`Response: ${status}`);
|
|
522
637
|
}
|
|
523
|
-
|
|
524
|
-
function: def.
|
|
638
|
+
import_log4.log.info("done", {
|
|
639
|
+
function: def.uri,
|
|
525
640
|
status
|
|
526
641
|
}, {
|
|
527
|
-
F:
|
|
528
|
-
L:
|
|
642
|
+
F: __dxlog_file4,
|
|
643
|
+
L: 129,
|
|
529
644
|
S: this,
|
|
530
645
|
C: (f, a) => f(...a)
|
|
531
646
|
});
|
|
532
647
|
} catch (err) {
|
|
533
|
-
|
|
534
|
-
function: def.
|
|
648
|
+
import_log4.log.error("error", {
|
|
649
|
+
function: def.uri,
|
|
535
650
|
error: err.message
|
|
536
651
|
}, {
|
|
537
|
-
F:
|
|
538
|
-
L:
|
|
652
|
+
F: __dxlog_file4,
|
|
653
|
+
L: 131,
|
|
539
654
|
S: this,
|
|
540
655
|
C: (f, a) => f(...a)
|
|
541
656
|
});
|
|
@@ -543,334 +658,408 @@ var Scheduler = class {
|
|
|
543
658
|
}
|
|
544
659
|
return status;
|
|
545
660
|
}
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
661
|
+
};
|
|
662
|
+
var createContext2 = () => new import_context3.Context({
|
|
663
|
+
name: "FunctionScheduler"
|
|
664
|
+
});
|
|
665
|
+
var __dxlog_file5 = "/home/runner/work/dxos/dxos/packages/core/functions/src/trigger/type/subscription-trigger.ts";
|
|
666
|
+
var createSubscriptionTrigger = async (ctx, triggerCtx, spec, callback) => {
|
|
667
|
+
const objectIds = /* @__PURE__ */ new Set();
|
|
668
|
+
const task = new import_async5.UpdateScheduler(ctx, async () => {
|
|
669
|
+
if (objectIds.size > 0) {
|
|
670
|
+
const objects = Array.from(objectIds);
|
|
671
|
+
objectIds.clear();
|
|
672
|
+
await callback({
|
|
673
|
+
objects
|
|
674
|
+
});
|
|
675
|
+
}
|
|
676
|
+
}, {
|
|
677
|
+
maxFrequency: 4
|
|
678
|
+
});
|
|
679
|
+
const subscriptions = [];
|
|
680
|
+
const subscription = (0, import_echo_db.createSubscription)(({ added, updated }) => {
|
|
681
|
+
const sizeBefore = objectIds.size;
|
|
682
|
+
for (const object of added) {
|
|
683
|
+
objectIds.add(object.id);
|
|
684
|
+
}
|
|
685
|
+
for (const object of updated) {
|
|
686
|
+
objectIds.add(object.id);
|
|
687
|
+
}
|
|
688
|
+
if (objectIds.size > sizeBefore) {
|
|
689
|
+
import_log6.log.info("updated", {
|
|
690
|
+
added: added.length,
|
|
691
|
+
updated: updated.length
|
|
692
|
+
}, {
|
|
693
|
+
F: __dxlog_file5,
|
|
694
|
+
L: 45,
|
|
695
|
+
S: void 0,
|
|
696
|
+
C: (f, a) => f(...a)
|
|
697
|
+
});
|
|
698
|
+
task.trigger();
|
|
699
|
+
}
|
|
700
|
+
});
|
|
701
|
+
subscriptions.push(() => subscription.unsubscribe());
|
|
702
|
+
const { filter, options: { deep, delay } = {} } = spec;
|
|
703
|
+
const update = ({ objects }) => {
|
|
704
|
+
subscription.update(objects);
|
|
705
|
+
if (deep) {
|
|
706
|
+
import_log6.log.info("update", {
|
|
707
|
+
objects: objects.length
|
|
708
|
+
}, {
|
|
709
|
+
F: __dxlog_file5,
|
|
710
|
+
L: 59,
|
|
711
|
+
S: void 0,
|
|
712
|
+
C: (f, a) => f(...a)
|
|
713
|
+
});
|
|
714
|
+
for (const object of objects) {
|
|
715
|
+
const content = object.content;
|
|
716
|
+
if (content instanceof import_types.TextV0Type) {
|
|
717
|
+
subscriptions.push((0, import_echo_db.getAutomergeObjectCore)(content).updates.on((0, import_async5.debounce)(() => subscription.update([
|
|
718
|
+
object
|
|
719
|
+
]), 1e3)));
|
|
720
|
+
}
|
|
721
|
+
}
|
|
722
|
+
}
|
|
723
|
+
};
|
|
724
|
+
const query = triggerCtx.space.db.query(import_echo_db.Filter.or(filter.map(({ type, props }) => import_echo_db.Filter.typename(type, props))));
|
|
725
|
+
subscriptions.push(query.subscribe(delay ? (0, import_async5.debounce)(update, delay) : update));
|
|
726
|
+
ctx.onDispose(() => {
|
|
727
|
+
subscriptions.forEach((unsubscribe) => unsubscribe());
|
|
728
|
+
});
|
|
729
|
+
};
|
|
730
|
+
var __dxlog_file6 = "/home/runner/work/dxos/dxos/packages/core/functions/src/trigger/type/timer-trigger.ts";
|
|
731
|
+
var createTimerTrigger = async (ctx, triggerContext, spec, callback) => {
|
|
732
|
+
const task = new import_async6.DeferredTask(ctx, async () => {
|
|
733
|
+
await callback({});
|
|
734
|
+
});
|
|
735
|
+
let last = 0;
|
|
736
|
+
let run = 0;
|
|
737
|
+
const job = import_cron.CronJob.from({
|
|
738
|
+
cronTime: spec.cron,
|
|
739
|
+
runOnInit: false,
|
|
740
|
+
onTick: () => {
|
|
741
|
+
const now = Date.now();
|
|
742
|
+
const delta = last ? now - last : 0;
|
|
743
|
+
last = now;
|
|
744
|
+
run++;
|
|
745
|
+
import_log7.log.info("tick", {
|
|
746
|
+
space: triggerContext.space.key.truncate(),
|
|
747
|
+
count: run,
|
|
748
|
+
delta
|
|
749
|
+
}, {
|
|
750
|
+
F: __dxlog_file6,
|
|
751
|
+
L: 37,
|
|
752
|
+
S: void 0,
|
|
753
|
+
C: (f, a) => f(...a)
|
|
754
|
+
});
|
|
755
|
+
task.schedule();
|
|
756
|
+
}
|
|
757
|
+
});
|
|
758
|
+
job.start();
|
|
759
|
+
ctx.onDispose(() => job.stop());
|
|
760
|
+
};
|
|
761
|
+
var __dxlog_file7 = "/home/runner/work/dxos/dxos/packages/core/functions/src/trigger/type/webhook-trigger.ts";
|
|
762
|
+
var createWebhookTrigger = async (ctx, _, spec, callback) => {
|
|
763
|
+
const server = import_node_http.default.createServer(async (req, res) => {
|
|
764
|
+
if (req.method !== spec.method) {
|
|
765
|
+
res.statusCode = 405;
|
|
766
|
+
return res.end();
|
|
767
|
+
}
|
|
768
|
+
res.statusCode = await callback({});
|
|
769
|
+
res.end();
|
|
770
|
+
});
|
|
771
|
+
const port = await (0, import_get_port_please2.getPort)({
|
|
772
|
+
random: true
|
|
773
|
+
});
|
|
774
|
+
server.listen(port, () => {
|
|
775
|
+
import_log8.log.info("started webhook", {
|
|
776
|
+
port
|
|
556
777
|
}, {
|
|
557
|
-
F:
|
|
558
|
-
L:
|
|
559
|
-
S:
|
|
778
|
+
F: __dxlog_file7,
|
|
779
|
+
L: 40,
|
|
780
|
+
S: void 0,
|
|
560
781
|
C: (f, a) => f(...a)
|
|
561
782
|
});
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
783
|
+
spec.port = port;
|
|
784
|
+
});
|
|
785
|
+
ctx.onDispose(() => {
|
|
786
|
+
server.close();
|
|
787
|
+
});
|
|
788
|
+
};
|
|
789
|
+
var __dxlog_file8 = "/home/runner/work/dxos/dxos/packages/core/functions/src/trigger/type/websocket-trigger.ts";
|
|
790
|
+
var createWebsocketTrigger = async (ctx, triggerCtx, spec, callback, options = {
|
|
791
|
+
retryDelay: 2,
|
|
792
|
+
maxAttempts: 5
|
|
793
|
+
}) => {
|
|
794
|
+
const { url, init } = spec;
|
|
795
|
+
let ws;
|
|
796
|
+
for (let attempt = 1; attempt <= options.maxAttempts; attempt++) {
|
|
797
|
+
const open = new import_async7.Trigger();
|
|
798
|
+
ws = new import_ws.default(url);
|
|
799
|
+
Object.assign(ws, {
|
|
800
|
+
onopen: () => {
|
|
801
|
+
import_log9.log.info("opened", {
|
|
802
|
+
url
|
|
582
803
|
}, {
|
|
583
|
-
F:
|
|
584
|
-
L:
|
|
585
|
-
S:
|
|
804
|
+
F: __dxlog_file8,
|
|
805
|
+
L: 39,
|
|
806
|
+
S: void 0,
|
|
807
|
+
C: (f, a) => f(...a)
|
|
808
|
+
});
|
|
809
|
+
if (spec.init) {
|
|
810
|
+
ws.send(new TextEncoder().encode(JSON.stringify(init)));
|
|
811
|
+
}
|
|
812
|
+
open.wake(true);
|
|
813
|
+
},
|
|
814
|
+
onclose: (event) => {
|
|
815
|
+
import_log9.log.info("closed", {
|
|
816
|
+
url,
|
|
817
|
+
code: event.code
|
|
818
|
+
}, {
|
|
819
|
+
F: __dxlog_file8,
|
|
820
|
+
L: 48,
|
|
821
|
+
S: void 0,
|
|
822
|
+
C: (f, a) => f(...a)
|
|
823
|
+
});
|
|
824
|
+
if (event.code === 1006) {
|
|
825
|
+
setTimeout(async () => {
|
|
826
|
+
import_log9.log.info(`reconnecting in ${options.retryDelay}s...`, {
|
|
827
|
+
url
|
|
828
|
+
}, {
|
|
829
|
+
F: __dxlog_file8,
|
|
830
|
+
L: 53,
|
|
831
|
+
S: void 0,
|
|
832
|
+
C: (f, a) => f(...a)
|
|
833
|
+
});
|
|
834
|
+
await createWebsocketTrigger(ctx, triggerCtx, spec, callback, options);
|
|
835
|
+
}, options.retryDelay * 1e3);
|
|
836
|
+
}
|
|
837
|
+
open.wake(false);
|
|
838
|
+
},
|
|
839
|
+
onerror: (event) => {
|
|
840
|
+
import_log9.log.catch(event.error, {
|
|
841
|
+
url
|
|
842
|
+
}, {
|
|
843
|
+
F: __dxlog_file8,
|
|
844
|
+
L: 62,
|
|
845
|
+
S: void 0,
|
|
586
846
|
C: (f, a) => f(...a)
|
|
587
847
|
});
|
|
588
|
-
|
|
848
|
+
},
|
|
849
|
+
onmessage: async (event) => {
|
|
850
|
+
try {
|
|
851
|
+
import_log9.log.info("message", void 0, {
|
|
852
|
+
F: __dxlog_file8,
|
|
853
|
+
L: 67,
|
|
854
|
+
S: void 0,
|
|
855
|
+
C: (f, a) => f(...a)
|
|
856
|
+
});
|
|
857
|
+
const data = JSON.parse(new TextDecoder().decode(event.data));
|
|
858
|
+
await callback({
|
|
859
|
+
data
|
|
860
|
+
});
|
|
861
|
+
} catch (err) {
|
|
862
|
+
import_log9.log.catch(err, {
|
|
863
|
+
url
|
|
864
|
+
}, {
|
|
865
|
+
F: __dxlog_file8,
|
|
866
|
+
L: 71,
|
|
867
|
+
S: void 0,
|
|
868
|
+
C: (f, a) => f(...a)
|
|
869
|
+
});
|
|
870
|
+
}
|
|
589
871
|
}
|
|
590
872
|
});
|
|
591
|
-
|
|
592
|
-
|
|
873
|
+
const isOpen = await open.wait();
|
|
874
|
+
if (isOpen) {
|
|
875
|
+
break;
|
|
876
|
+
} else {
|
|
877
|
+
const wait = Math.pow(attempt, 2) * options.retryDelay;
|
|
878
|
+
if (attempt < options.maxAttempts) {
|
|
879
|
+
import_log9.log.warn(`failed to connect; trying again in ${wait}s`, {
|
|
880
|
+
attempt
|
|
881
|
+
}, {
|
|
882
|
+
F: __dxlog_file8,
|
|
883
|
+
L: 82,
|
|
884
|
+
S: void 0,
|
|
885
|
+
C: (f, a) => f(...a)
|
|
886
|
+
});
|
|
887
|
+
await (0, import_async7.sleep)(wait * 1e3);
|
|
888
|
+
}
|
|
889
|
+
}
|
|
593
890
|
}
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
891
|
+
ctx.onDispose(() => {
|
|
892
|
+
ws?.close();
|
|
893
|
+
});
|
|
894
|
+
};
|
|
895
|
+
var __dxlog_file9 = "/home/runner/work/dxos/dxos/packages/core/functions/src/trigger/trigger-registry.ts";
|
|
896
|
+
var triggerHandlers = {
|
|
897
|
+
subscription: createSubscriptionTrigger,
|
|
898
|
+
timer: createTimerTrigger,
|
|
899
|
+
webhook: createWebhookTrigger,
|
|
900
|
+
websocket: createWebsocketTrigger
|
|
901
|
+
};
|
|
902
|
+
var TriggerRegistry = class extends import_context4.Resource {
|
|
903
|
+
constructor(_client, _options) {
|
|
904
|
+
super();
|
|
905
|
+
this._client = _client;
|
|
906
|
+
this._options = _options;
|
|
907
|
+
this._triggersBySpaceKey = new import_util3.ComplexMap(import_keys2.PublicKey.hash);
|
|
908
|
+
this.registered = new import_async4.Event();
|
|
909
|
+
this.removed = new import_async4.Event();
|
|
910
|
+
}
|
|
911
|
+
getActiveTriggers(space) {
|
|
912
|
+
return this._getTriggers(space, (t) => t.activationCtx != null);
|
|
913
|
+
}
|
|
914
|
+
getInactiveTriggers(space) {
|
|
915
|
+
return this._getTriggers(space, (t) => t.activationCtx == null);
|
|
916
|
+
}
|
|
917
|
+
async activate(triggerCtx, trigger, callback) {
|
|
918
|
+
(0, import_log5.log)("activate", {
|
|
919
|
+
space: triggerCtx.space.key,
|
|
600
920
|
trigger
|
|
601
921
|
}, {
|
|
602
|
-
F:
|
|
603
|
-
L:
|
|
922
|
+
F: __dxlog_file9,
|
|
923
|
+
L: 75,
|
|
604
924
|
S: this,
|
|
605
925
|
C: (f, a) => f(...a)
|
|
606
926
|
});
|
|
607
|
-
const
|
|
608
|
-
|
|
609
|
-
if (req.method !== spec.method) {
|
|
610
|
-
res.statusCode = 405;
|
|
611
|
-
return res.end();
|
|
612
|
-
}
|
|
613
|
-
res.statusCode = await this._execFunction(def, trigger, {
|
|
614
|
-
spaceKey: space.key
|
|
615
|
-
});
|
|
616
|
-
res.end();
|
|
617
|
-
});
|
|
618
|
-
const port = await (0, import_get_port_please2.getPort)({
|
|
619
|
-
random: true
|
|
927
|
+
const activationCtx = new import_context4.Context({
|
|
928
|
+
name: `trigger_${trigger.function}`
|
|
620
929
|
});
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
});
|
|
632
|
-
ctx.onDispose(() => {
|
|
633
|
-
server.close();
|
|
930
|
+
this._ctx.onDispose(() => activationCtx.dispose());
|
|
931
|
+
const registeredTrigger = this._triggersBySpaceKey.get(triggerCtx.space.key)?.find((reg) => reg.trigger.id === trigger.id);
|
|
932
|
+
(0, import_invariant2.invariant)(registeredTrigger, `Trigger is not registered: ${trigger.function}`, {
|
|
933
|
+
F: __dxlog_file9,
|
|
934
|
+
L: 81,
|
|
935
|
+
S: this,
|
|
936
|
+
A: [
|
|
937
|
+
"registeredTrigger",
|
|
938
|
+
"`Trigger is not registered: ${trigger.function}`"
|
|
939
|
+
]
|
|
634
940
|
});
|
|
941
|
+
registeredTrigger.activationCtx = activationCtx;
|
|
942
|
+
try {
|
|
943
|
+
const options = this._options?.[trigger.spec.type];
|
|
944
|
+
await triggerHandlers[trigger.spec.type](activationCtx, triggerCtx, trigger.spec, callback, options);
|
|
945
|
+
} catch (err) {
|
|
946
|
+
delete registeredTrigger.activationCtx;
|
|
947
|
+
throw err;
|
|
948
|
+
}
|
|
635
949
|
}
|
|
636
950
|
/**
|
|
637
|
-
*
|
|
638
|
-
* NOTE: The port must be unique, so the same hook cannot be used for multiple spaces.
|
|
951
|
+
* Loads triggers from the manifest into the space.
|
|
639
952
|
*/
|
|
640
|
-
async
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
}) {
|
|
644
|
-
import_log3.log.info("websocket", {
|
|
645
|
-
space: space.key,
|
|
646
|
-
trigger
|
|
953
|
+
async register(space, manifest) {
|
|
954
|
+
(0, import_log5.log)("register", {
|
|
955
|
+
space: space.key
|
|
647
956
|
}, {
|
|
648
|
-
F:
|
|
649
|
-
L:
|
|
957
|
+
F: __dxlog_file9,
|
|
958
|
+
L: 97,
|
|
650
959
|
S: this,
|
|
651
960
|
C: (f, a) => f(...a)
|
|
652
961
|
});
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
L: 269,
|
|
681
|
-
S: this,
|
|
682
|
-
C: (f, a) => f(...a)
|
|
683
|
-
});
|
|
684
|
-
if (event.code === 1006) {
|
|
685
|
-
setTimeout(async () => {
|
|
686
|
-
import_log3.log.info(`reconnecting in ${options.retryDelay}s...`, {
|
|
687
|
-
url
|
|
688
|
-
}, {
|
|
689
|
-
F: __dxlog_file3,
|
|
690
|
-
L: 274,
|
|
691
|
-
S: this,
|
|
692
|
-
C: (f, a) => f(...a)
|
|
693
|
-
});
|
|
694
|
-
await this._createWebsocket(ctx, space, def, trigger, options);
|
|
695
|
-
}, options.retryDelay * 1e3);
|
|
696
|
-
}
|
|
697
|
-
open.wake(false);
|
|
698
|
-
},
|
|
699
|
-
onerror: (event) => {
|
|
700
|
-
import_log3.log.catch(event.error, {
|
|
701
|
-
url
|
|
702
|
-
}, {
|
|
703
|
-
F: __dxlog_file3,
|
|
704
|
-
L: 283,
|
|
705
|
-
S: this,
|
|
706
|
-
C: (f, a) => f(...a)
|
|
707
|
-
});
|
|
708
|
-
},
|
|
709
|
-
onmessage: async (event) => {
|
|
710
|
-
try {
|
|
711
|
-
const data = JSON.parse(new TextDecoder().decode(event.data));
|
|
712
|
-
await this._execFunction(def, trigger, {
|
|
713
|
-
spaceKey: space.key,
|
|
714
|
-
data
|
|
715
|
-
});
|
|
716
|
-
} catch (err) {
|
|
717
|
-
import_log3.log.catch(err, {
|
|
718
|
-
url
|
|
719
|
-
}, {
|
|
720
|
-
F: __dxlog_file3,
|
|
721
|
-
L: 291,
|
|
722
|
-
S: this,
|
|
723
|
-
C: (f, a) => f(...a)
|
|
724
|
-
});
|
|
725
|
-
}
|
|
962
|
+
if (!manifest.triggers?.length) {
|
|
963
|
+
return;
|
|
964
|
+
}
|
|
965
|
+
if (!space.db.graph.runtimeSchemaRegistry.hasSchema(import_chunk_3VSJ57ZZ.FunctionTrigger)) {
|
|
966
|
+
space.db.graph.runtimeSchemaRegistry.registerSchema(import_chunk_3VSJ57ZZ.FunctionTrigger);
|
|
967
|
+
}
|
|
968
|
+
const { objects: existing } = await space.db.query(import_echo2.Filter.schema(import_chunk_3VSJ57ZZ.FunctionTrigger)).run();
|
|
969
|
+
const { added, removed } = diff(existing, manifest.triggers, (a, b) => {
|
|
970
|
+
const keys = b[import_echo_schema.ECHO_ATTR_META]?.keys ?? [
|
|
971
|
+
(0, import_echo_schema.foreignKey)("manifest", [
|
|
972
|
+
b.function,
|
|
973
|
+
b.spec.type
|
|
974
|
+
].join("-"))
|
|
975
|
+
];
|
|
976
|
+
return intersection((0, import_echo2.getMeta)(a)?.keys ?? [], keys, import_echo_schema.foreignKeyEquals).length > 0;
|
|
977
|
+
});
|
|
978
|
+
added.forEach((trigger) => {
|
|
979
|
+
const { meta, object } = (0, import_echo_schema.splitMeta)(trigger);
|
|
980
|
+
space.db.add((0, import_echo2.create)(import_chunk_3VSJ57ZZ.FunctionTrigger, object, meta));
|
|
981
|
+
});
|
|
982
|
+
removed.forEach((trigger) => space.db.remove(trigger));
|
|
983
|
+
}
|
|
984
|
+
async _open() {
|
|
985
|
+
const spaceListSubscription = this._client.spaces.subscribe(async (spaces) => {
|
|
986
|
+
for (const space of spaces) {
|
|
987
|
+
if (this._triggersBySpaceKey.has(space.key)) {
|
|
988
|
+
continue;
|
|
726
989
|
}
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
const wait = Math.pow(attempt, 2) * options.retryDelay;
|
|
733
|
-
if (attempt < options.maxAttempts) {
|
|
734
|
-
import_log3.log.warn(`failed to connect; trying again in ${wait}s`, {
|
|
735
|
-
attempt
|
|
736
|
-
}, {
|
|
737
|
-
F: __dxlog_file3,
|
|
738
|
-
L: 302,
|
|
739
|
-
S: this,
|
|
740
|
-
C: (f, a) => f(...a)
|
|
741
|
-
});
|
|
742
|
-
await (0, import_async2.sleep)(wait * 1e3);
|
|
990
|
+
const registered = [];
|
|
991
|
+
this._triggersBySpaceKey.set(space.key, registered);
|
|
992
|
+
await space.waitUntilReady();
|
|
993
|
+
if (this._ctx.disposed) {
|
|
994
|
+
break;
|
|
743
995
|
}
|
|
996
|
+
const functionsSubscription = space.db.query(import_echo2.Filter.schema(import_chunk_3VSJ57ZZ.FunctionTrigger)).subscribe(async (triggers) => {
|
|
997
|
+
await this._handleRemovedTriggers(space, triggers.objects, registered);
|
|
998
|
+
this._handleNewTriggers(space, triggers.objects, registered);
|
|
999
|
+
});
|
|
1000
|
+
this._ctx.onDispose(functionsSubscription);
|
|
744
1001
|
}
|
|
745
|
-
}
|
|
746
|
-
ctx.onDispose(() => {
|
|
747
|
-
ws?.close();
|
|
748
1002
|
});
|
|
1003
|
+
this._ctx.onDispose(() => spaceListSubscription.unsubscribe());
|
|
749
1004
|
}
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
trigger
|
|
757
|
-
}, {
|
|
758
|
-
F: __dxlog_file3,
|
|
759
|
-
L: 317,
|
|
760
|
-
S: this,
|
|
761
|
-
C: (f, a) => f(...a)
|
|
1005
|
+
async _close(_) {
|
|
1006
|
+
this._triggersBySpaceKey.clear();
|
|
1007
|
+
}
|
|
1008
|
+
_handleNewTriggers(space, allTriggers, registered) {
|
|
1009
|
+
const newTriggers = allTriggers.filter((candidate) => {
|
|
1010
|
+
return registered.find((reg) => reg.trigger.id === candidate.id) == null;
|
|
762
1011
|
});
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
1012
|
+
if (newTriggers.length > 0) {
|
|
1013
|
+
const newRegisteredTriggers = newTriggers.map((trigger) => ({
|
|
1014
|
+
trigger
|
|
1015
|
+
}));
|
|
1016
|
+
registered.push(...newRegisteredTriggers);
|
|
1017
|
+
(0, import_log5.log)("registered new triggers", () => ({
|
|
767
1018
|
spaceKey: space.key,
|
|
768
|
-
|
|
769
|
-
})
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
const subscription = (0, import_echo.createSubscription)(({ added, updated }) => {
|
|
773
|
-
import_log3.log.info("updated", {
|
|
774
|
-
added: added.length,
|
|
775
|
-
updated: updated.length
|
|
776
|
-
}, {
|
|
777
|
-
F: __dxlog_file3,
|
|
778
|
-
L: 329,
|
|
1019
|
+
functions: newTriggers.map((t) => t.function)
|
|
1020
|
+
}), {
|
|
1021
|
+
F: __dxlog_file9,
|
|
1022
|
+
L: 159,
|
|
779
1023
|
S: this,
|
|
780
1024
|
C: (f, a) => f(...a)
|
|
781
1025
|
});
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
objects: objects.length
|
|
797
|
-
}, {
|
|
798
|
-
F: __dxlog_file3,
|
|
799
|
-
L: 349,
|
|
800
|
-
S: this,
|
|
801
|
-
C: (f, a) => f(...a)
|
|
802
|
-
});
|
|
803
|
-
for (const object of objects) {
|
|
804
|
-
const content = object.content;
|
|
805
|
-
if (content instanceof import_types.TextV0Type) {
|
|
806
|
-
subscriptions.push((0, import_echo.getAutomergeObjectCore)(content).updates.on((0, import_async2.debounce)(() => subscription.update([
|
|
807
|
-
object
|
|
808
|
-
]), 1e3)));
|
|
809
|
-
}
|
|
810
|
-
}
|
|
1026
|
+
this.registered.emit({
|
|
1027
|
+
space,
|
|
1028
|
+
triggers: newTriggers
|
|
1029
|
+
});
|
|
1030
|
+
}
|
|
1031
|
+
}
|
|
1032
|
+
async _handleRemovedTriggers(space, allTriggers, registered) {
|
|
1033
|
+
const removed = [];
|
|
1034
|
+
for (let i = registered.length - 1; i >= 0; i--) {
|
|
1035
|
+
const wasRemoved = allTriggers.find((trigger) => trigger.id === registered[i].trigger.id) == null;
|
|
1036
|
+
if (wasRemoved) {
|
|
1037
|
+
const unregistered = registered.splice(i, 1)[0];
|
|
1038
|
+
await unregistered.activationCtx?.dispose();
|
|
1039
|
+
removed.push(unregistered.trigger);
|
|
811
1040
|
}
|
|
812
|
-
}
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
1041
|
+
}
|
|
1042
|
+
if (removed.length > 0) {
|
|
1043
|
+
this.removed.emit({
|
|
1044
|
+
space,
|
|
1045
|
+
triggers: removed
|
|
1046
|
+
});
|
|
1047
|
+
}
|
|
1048
|
+
}
|
|
1049
|
+
_getTriggers(space, predicate) {
|
|
1050
|
+
const allSpaceTriggers = this._triggersBySpaceKey.get(space.key) ?? [];
|
|
1051
|
+
return allSpaceTriggers.filter(predicate).map((trigger) => trigger.trigger);
|
|
818
1052
|
}
|
|
819
1053
|
};
|
|
820
|
-
var TimerTriggerSchema = S.struct({
|
|
821
|
-
cron: S.string
|
|
822
|
-
});
|
|
823
|
-
var WebhookTriggerSchema = S.mutable(S.struct({
|
|
824
|
-
method: S.string,
|
|
825
|
-
// Assigned port.
|
|
826
|
-
port: S.optional(S.number)
|
|
827
|
-
}));
|
|
828
|
-
var WebsocketTriggerSchema = S.struct({
|
|
829
|
-
url: S.string,
|
|
830
|
-
init: S.optional(S.record(S.string, S.any))
|
|
831
|
-
});
|
|
832
|
-
var SubscriptionTriggerSchema = S.struct({
|
|
833
|
-
spaceKey: S.optional(S.string),
|
|
834
|
-
// TODO(burdon): Define query DSL.
|
|
835
|
-
filter: S.array(S.struct({
|
|
836
|
-
type: S.string,
|
|
837
|
-
props: S.optional(S.record(S.string, S.any))
|
|
838
|
-
})),
|
|
839
|
-
options: S.optional(S.struct({
|
|
840
|
-
// Watch changes to object (not just creation).
|
|
841
|
-
deep: S.optional(S.boolean),
|
|
842
|
-
// Debounce changes (delay in ms).
|
|
843
|
-
delay: S.optional(S.number)
|
|
844
|
-
}))
|
|
845
|
-
});
|
|
846
|
-
var FunctionTriggerSchema = S.struct({
|
|
847
|
-
function: S.string.pipe(S.description("Function ID/URI.")),
|
|
848
|
-
// Context passed to function.
|
|
849
|
-
meta: S.optional(S.record(S.string, S.any)),
|
|
850
|
-
// Triggers.
|
|
851
|
-
timer: S.optional(TimerTriggerSchema),
|
|
852
|
-
webhook: S.optional(WebhookTriggerSchema),
|
|
853
|
-
websocket: S.optional(WebsocketTriggerSchema),
|
|
854
|
-
subscription: S.optional(SubscriptionTriggerSchema)
|
|
855
|
-
});
|
|
856
|
-
var FunctionDefSchema = S.struct({
|
|
857
|
-
id: S.string,
|
|
858
|
-
// name: S.string,
|
|
859
|
-
description: S.optional(S.string),
|
|
860
|
-
// TODO(burdon): Rename route?
|
|
861
|
-
path: S.string,
|
|
862
|
-
// TODO(burdon): NPM/GitHub/Docker/CF URL?
|
|
863
|
-
handler: S.string
|
|
864
|
-
});
|
|
865
|
-
var FunctionManifestSchema = S.struct({
|
|
866
|
-
functions: S.mutable(S.array(FunctionDefSchema)),
|
|
867
|
-
triggers: S.optional(S.mutable(S.array(FunctionTriggerSchema)))
|
|
868
|
-
});
|
|
869
1054
|
// Annotate the CommonJS export names for ESM import in node:
|
|
870
1055
|
0 && (module.exports = {
|
|
871
1056
|
DevServer,
|
|
1057
|
+
FunctionDef,
|
|
872
1058
|
FunctionManifestSchema,
|
|
1059
|
+
FunctionRegistry,
|
|
1060
|
+
FunctionTrigger,
|
|
873
1061
|
Scheduler,
|
|
1062
|
+
TriggerRegistry,
|
|
874
1063
|
subscriptionHandler
|
|
875
1064
|
});
|
|
876
1065
|
//# sourceMappingURL=index.cjs.map
|