@dxos/functions 0.5.3-next.57eca40 → 0.5.3-next.63cdcad
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 → chunk-4D4I3YMJ.mjs} +16 -11
- package/dist/lib/browser/chunk-4D4I3YMJ.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +206 -133
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/types.mjs +3 -1
- package/dist/lib/node/{chunk-3VSJ57ZZ.cjs → chunk-3UYUR5N5.cjs} +19 -13
- package/dist/lib/node/chunk-3UYUR5N5.cjs.map +7 -0
- package/dist/lib/node/index.cjs +216 -139
- package/dist/lib/node/index.cjs.map +4 -4
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node/types.cjs +6 -4
- package/dist/lib/node/types.cjs.map +2 -2
- package/dist/types/src/browser/index.d.ts +2 -0
- package/dist/types/src/browser/index.d.ts.map +1 -0
- package/dist/types/src/function/function-registry.d.ts.map +1 -1
- package/dist/types/src/handler.d.ts.map +1 -1
- package/dist/types/src/runtime/dev-server.d.ts.map +1 -1
- package/dist/types/src/runtime/scheduler.d.ts +1 -1
- package/dist/types/src/runtime/scheduler.d.ts.map +1 -1
- package/dist/types/src/testing/setup.d.ts.map +1 -1
- package/dist/types/src/trigger/trigger-registry.d.ts +2 -5
- package/dist/types/src/trigger/trigger-registry.d.ts.map +1 -1
- package/dist/types/src/trigger/type/subscription-trigger.d.ts.map +1 -1
- package/dist/types/src/trigger/type/timer-trigger.d.ts.map +1 -1
- package/dist/types/src/trigger/type/webhook-trigger.d.ts.map +1 -1
- package/dist/types/src/trigger/type/websocket-trigger.d.ts.map +1 -1
- package/dist/types/src/types.d.ts +46 -33
- package/dist/types/src/types.d.ts.map +1 -1
- package/package.json +14 -14
- package/schema/functions.json +5 -0
- package/src/browser/index.ts +5 -0
- package/src/function/function-registry.ts +5 -5
- package/src/runtime/dev-server.ts +3 -3
- package/src/runtime/scheduler.test.ts +14 -9
- package/src/runtime/scheduler.ts +14 -9
- package/src/testing/functions-integration.test.ts +1 -0
- package/src/testing/setup.ts +8 -10
- package/src/trigger/trigger-registry.test.ts +30 -13
- package/src/trigger/trigger-registry.ts +59 -37
- package/src/trigger/type/subscription-trigger.ts +13 -7
- package/src/trigger/type/timer-trigger.ts +4 -3
- package/src/trigger/type/webhook-trigger.ts +3 -2
- package/src/trigger/type/websocket-trigger.ts +4 -3
- package/src/types.ts +42 -30
- package/dist/lib/browser/chunk-366QG6IX.mjs.map +0 -7
- package/dist/lib/node/chunk-3VSJ57ZZ.cjs.map +0 -7
- package/dist/types/src/util.d.ts +0 -15
- package/dist/types/src/util.d.ts.map +0 -1
- package/dist/types/src/util.test.d.ts +0 -2
- package/dist/types/src/util.test.d.ts.map +0 -1
- package/src/util.test.ts +0 -43
- package/src/util.ts +0 -48
package/dist/lib/node/index.cjs
CHANGED
|
@@ -29,16 +29,17 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
29
29
|
var node_exports = {};
|
|
30
30
|
__export(node_exports, {
|
|
31
31
|
DevServer: () => DevServer,
|
|
32
|
-
|
|
33
|
-
|
|
32
|
+
FUNCTION_SCHEMA: () => import_chunk_3UYUR5N5.FUNCTION_SCHEMA,
|
|
33
|
+
FunctionDef: () => import_chunk_3UYUR5N5.FunctionDef,
|
|
34
|
+
FunctionManifestSchema: () => import_chunk_3UYUR5N5.FunctionManifestSchema,
|
|
34
35
|
FunctionRegistry: () => FunctionRegistry,
|
|
35
|
-
FunctionTrigger: () =>
|
|
36
|
+
FunctionTrigger: () => import_chunk_3UYUR5N5.FunctionTrigger,
|
|
36
37
|
Scheduler: () => Scheduler,
|
|
37
38
|
TriggerRegistry: () => TriggerRegistry,
|
|
38
39
|
subscriptionHandler: () => subscriptionHandler
|
|
39
40
|
});
|
|
40
41
|
module.exports = __toCommonJS(node_exports);
|
|
41
|
-
var
|
|
42
|
+
var import_chunk_3UYUR5N5 = require("./chunk-3UYUR5N5.cjs");
|
|
42
43
|
var import_async = require("@dxos/async");
|
|
43
44
|
var import_echo = require("@dxos/client/echo");
|
|
44
45
|
var import_context = require("@dxos/context");
|
|
@@ -69,6 +70,7 @@ var import_log5 = require("@dxos/log");
|
|
|
69
70
|
var import_util3 = require("@dxos/util");
|
|
70
71
|
var import_types = require("@braneframe/types");
|
|
71
72
|
var import_async5 = require("@dxos/async");
|
|
73
|
+
var import_echo3 = require("@dxos/client/echo");
|
|
72
74
|
var import_echo_db = require("@dxos/echo-db");
|
|
73
75
|
var import_log6 = require("@dxos/log");
|
|
74
76
|
var import_cron = require("cron");
|
|
@@ -80,27 +82,6 @@ var import_log8 = require("@dxos/log");
|
|
|
80
82
|
var import_ws = __toESM(require("ws"));
|
|
81
83
|
var import_async7 = require("@dxos/async");
|
|
82
84
|
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
85
|
var __dxlog_file = "/home/runner/work/dxos/dxos/packages/core/functions/src/function/function-registry.ts";
|
|
105
86
|
var FunctionRegistry = class extends import_context.Resource {
|
|
106
87
|
constructor(_client) {
|
|
@@ -122,22 +103,27 @@ var FunctionRegistry = class extends import_context.Resource {
|
|
|
122
103
|
functions: functions?.length ?? 0
|
|
123
104
|
}, {
|
|
124
105
|
F: __dxlog_file,
|
|
125
|
-
L:
|
|
106
|
+
L: 38,
|
|
126
107
|
S: this,
|
|
127
108
|
C: (f, a) => f(...a)
|
|
128
109
|
});
|
|
129
110
|
if (!functions?.length) {
|
|
130
111
|
return;
|
|
131
112
|
}
|
|
132
|
-
if (!space.db.graph.runtimeSchemaRegistry.hasSchema(
|
|
133
|
-
space.db.graph.runtimeSchemaRegistry.registerSchema(
|
|
113
|
+
if (!space.db.graph.runtimeSchemaRegistry.hasSchema(import_chunk_3UYUR5N5.FunctionDef)) {
|
|
114
|
+
space.db.graph.runtimeSchemaRegistry.registerSchema(import_chunk_3UYUR5N5.FunctionDef);
|
|
134
115
|
}
|
|
135
|
-
const { objects: existing } = await space.db.query(import_echo.Filter.schema(
|
|
136
|
-
const { added
|
|
137
|
-
added.forEach((def) => space.db.add((0, import_echo.create)(
|
|
138
|
-
removed.forEach((def) => space.db.remove(def));
|
|
116
|
+
const { objects: existing } = await space.db.query(import_echo.Filter.schema(import_chunk_3UYUR5N5.FunctionDef)).run();
|
|
117
|
+
const { added } = (0, import_util.diff)(existing, functions, (a, b) => a.uri === b.uri);
|
|
118
|
+
added.forEach((def) => space.db.add((0, import_echo.create)(import_chunk_3UYUR5N5.FunctionDef, def)));
|
|
139
119
|
}
|
|
140
120
|
async _open() {
|
|
121
|
+
import_log.log.info("opening...", void 0, {
|
|
122
|
+
F: __dxlog_file,
|
|
123
|
+
L: 54,
|
|
124
|
+
S: this,
|
|
125
|
+
C: (f, a) => f(...a)
|
|
126
|
+
});
|
|
141
127
|
const spacesSubscription = this._client.spaces.subscribe(async (spaces) => {
|
|
142
128
|
for (const space of spaces) {
|
|
143
129
|
if (this._functionBySpaceKey.has(space.key)) {
|
|
@@ -149,8 +135,8 @@ var FunctionRegistry = class extends import_context.Resource {
|
|
|
149
135
|
if (this._ctx.disposed) {
|
|
150
136
|
break;
|
|
151
137
|
}
|
|
152
|
-
this._ctx.onDispose(space.db.query(import_echo.Filter.schema(
|
|
153
|
-
const { added } = diff(registered, objects, (a, b) => a.uri === b.uri);
|
|
138
|
+
this._ctx.onDispose(space.db.query(import_echo.Filter.schema(import_chunk_3UYUR5N5.FunctionDef)).subscribe(({ objects }) => {
|
|
139
|
+
const { added } = (0, import_util.diff)(registered, objects, (a, b) => a.uri === b.uri);
|
|
154
140
|
if (added.length > 0) {
|
|
155
141
|
registered.push(...added);
|
|
156
142
|
this.registered.emit({
|
|
@@ -164,6 +150,12 @@ var FunctionRegistry = class extends import_context.Resource {
|
|
|
164
150
|
this._ctx.onDispose(() => spacesSubscription.unsubscribe());
|
|
165
151
|
}
|
|
166
152
|
async _close(_) {
|
|
153
|
+
import_log.log.info("closing...", void 0, {
|
|
154
|
+
F: __dxlog_file,
|
|
155
|
+
L: 87,
|
|
156
|
+
S: this,
|
|
157
|
+
C: (f, a) => f(...a)
|
|
158
|
+
});
|
|
167
159
|
this._functionBySpaceKey.clear();
|
|
168
160
|
}
|
|
169
161
|
};
|
|
@@ -223,7 +215,7 @@ var DevServer = class {
|
|
|
223
215
|
added
|
|
224
216
|
}, {
|
|
225
217
|
F: __dxlog_file3,
|
|
226
|
-
L:
|
|
218
|
+
L: 53,
|
|
227
219
|
S: this,
|
|
228
220
|
C: (f, a) => f(...a)
|
|
229
221
|
});
|
|
@@ -237,7 +229,7 @@ var DevServer = class {
|
|
|
237
229
|
get endpoint() {
|
|
238
230
|
(0, import_invariant.invariant)(this._port, void 0, {
|
|
239
231
|
F: __dxlog_file3,
|
|
240
|
-
L:
|
|
232
|
+
L: 64,
|
|
241
233
|
S: this,
|
|
242
234
|
A: [
|
|
243
235
|
"this._port",
|
|
@@ -255,7 +247,7 @@ var DevServer = class {
|
|
|
255
247
|
async start() {
|
|
256
248
|
(0, import_invariant.invariant)(!this._server, void 0, {
|
|
257
249
|
F: __dxlog_file3,
|
|
258
|
-
L:
|
|
250
|
+
L: 77,
|
|
259
251
|
S: this,
|
|
260
252
|
A: [
|
|
261
253
|
"!this._server",
|
|
@@ -264,7 +256,7 @@ var DevServer = class {
|
|
|
264
256
|
});
|
|
265
257
|
import_log3.log.info("starting...", void 0, {
|
|
266
258
|
F: __dxlog_file3,
|
|
267
|
-
L:
|
|
259
|
+
L: 78,
|
|
268
260
|
S: this,
|
|
269
261
|
C: (f, a) => f(...a)
|
|
270
262
|
});
|
|
@@ -278,7 +270,7 @@ var DevServer = class {
|
|
|
278
270
|
path: path2
|
|
279
271
|
}, {
|
|
280
272
|
F: __dxlog_file3,
|
|
281
|
-
L:
|
|
273
|
+
L: 88,
|
|
282
274
|
S: this,
|
|
283
275
|
C: (f, a) => f(...a)
|
|
284
276
|
});
|
|
@@ -291,7 +283,7 @@ var DevServer = class {
|
|
|
291
283
|
} catch (err) {
|
|
292
284
|
import_log3.log.catch(err, void 0, {
|
|
293
285
|
F: __dxlog_file3,
|
|
294
|
-
L:
|
|
286
|
+
L: 98,
|
|
295
287
|
S: this,
|
|
296
288
|
C: (f, a) => f(...a)
|
|
297
289
|
});
|
|
@@ -316,7 +308,7 @@ var DevServer = class {
|
|
|
316
308
|
endpoint
|
|
317
309
|
}, {
|
|
318
310
|
F: __dxlog_file3,
|
|
319
|
-
L:
|
|
311
|
+
L: 113,
|
|
320
312
|
S: this,
|
|
321
313
|
C: (f, a) => f(...a)
|
|
322
314
|
});
|
|
@@ -331,7 +323,7 @@ var DevServer = class {
|
|
|
331
323
|
port: this._port
|
|
332
324
|
}, {
|
|
333
325
|
F: __dxlog_file3,
|
|
334
|
-
L:
|
|
326
|
+
L: 124,
|
|
335
327
|
S: this,
|
|
336
328
|
C: (f, a) => f(...a)
|
|
337
329
|
});
|
|
@@ -339,7 +331,7 @@ var DevServer = class {
|
|
|
339
331
|
async stop() {
|
|
340
332
|
(0, import_invariant.invariant)(this._server, void 0, {
|
|
341
333
|
F: __dxlog_file3,
|
|
342
|
-
L:
|
|
334
|
+
L: 128,
|
|
343
335
|
S: this,
|
|
344
336
|
A: [
|
|
345
337
|
"this._server",
|
|
@@ -348,7 +340,7 @@ var DevServer = class {
|
|
|
348
340
|
});
|
|
349
341
|
import_log3.log.info("stopping...", void 0, {
|
|
350
342
|
F: __dxlog_file3,
|
|
351
|
-
L:
|
|
343
|
+
L: 129,
|
|
352
344
|
S: this,
|
|
353
345
|
C: (f, a) => f(...a)
|
|
354
346
|
});
|
|
@@ -356,7 +348,7 @@ var DevServer = class {
|
|
|
356
348
|
this._server.close(async () => {
|
|
357
349
|
import_log3.log.info("server stopped", void 0, {
|
|
358
350
|
F: __dxlog_file3,
|
|
359
|
-
L:
|
|
351
|
+
L: 133,
|
|
360
352
|
S: this,
|
|
361
353
|
C: (f, a) => f(...a)
|
|
362
354
|
});
|
|
@@ -364,7 +356,7 @@ var DevServer = class {
|
|
|
364
356
|
if (this._functionServiceRegistration) {
|
|
365
357
|
(0, import_invariant.invariant)(this._client.services.services.FunctionRegistryService, void 0, {
|
|
366
358
|
F: __dxlog_file3,
|
|
367
|
-
L:
|
|
359
|
+
L: 136,
|
|
368
360
|
S: this,
|
|
369
361
|
A: [
|
|
370
362
|
"this._client.services.services.FunctionRegistryService",
|
|
@@ -378,7 +370,7 @@ var DevServer = class {
|
|
|
378
370
|
registrationId: this._functionServiceRegistration
|
|
379
371
|
}, {
|
|
380
372
|
F: __dxlog_file3,
|
|
381
|
-
L:
|
|
373
|
+
L: 141,
|
|
382
374
|
S: this,
|
|
383
375
|
C: (f, a) => f(...a)
|
|
384
376
|
});
|
|
@@ -395,7 +387,7 @@ var DevServer = class {
|
|
|
395
387
|
this._server = void 0;
|
|
396
388
|
import_log3.log.info("stopped", void 0, {
|
|
397
389
|
F: __dxlog_file3,
|
|
398
|
-
L:
|
|
390
|
+
L: 155,
|
|
399
391
|
S: this,
|
|
400
392
|
C: (f, a) => f(...a)
|
|
401
393
|
});
|
|
@@ -411,16 +403,16 @@ var DevServer = class {
|
|
|
411
403
|
force
|
|
412
404
|
}, {
|
|
413
405
|
F: __dxlog_file3,
|
|
414
|
-
L:
|
|
406
|
+
L: 164,
|
|
415
407
|
S: this,
|
|
416
408
|
C: (f, a) => f(...a)
|
|
417
409
|
});
|
|
418
410
|
if (force) {
|
|
419
|
-
Object.keys(
|
|
420
|
-
delete
|
|
411
|
+
Object.keys(import_chunk_3UYUR5N5.__require.cache).filter((key) => key.startsWith(filePath)).forEach((key) => {
|
|
412
|
+
delete import_chunk_3UYUR5N5.__require.cache[key];
|
|
421
413
|
});
|
|
422
414
|
}
|
|
423
|
-
const module2 = (0,
|
|
415
|
+
const module2 = (0, import_chunk_3UYUR5N5.__require)(filePath);
|
|
424
416
|
if (typeof module2.default !== "function") {
|
|
425
417
|
throw new Error(`Handler must export default function: ${uri}`);
|
|
426
418
|
}
|
|
@@ -432,7 +424,7 @@ var DevServer = class {
|
|
|
432
424
|
async _safeUpdateRegistration() {
|
|
433
425
|
(0, import_invariant.invariant)(this._functionServiceRegistration, void 0, {
|
|
434
426
|
F: __dxlog_file3,
|
|
435
|
-
L:
|
|
427
|
+
L: 186,
|
|
436
428
|
S: this,
|
|
437
429
|
A: [
|
|
438
430
|
"this._functionServiceRegistration",
|
|
@@ -447,10 +439,10 @@ var DevServer = class {
|
|
|
447
439
|
route
|
|
448
440
|
}))
|
|
449
441
|
});
|
|
450
|
-
} catch (
|
|
451
|
-
import_log3.log.catch(
|
|
442
|
+
} catch (err) {
|
|
443
|
+
import_log3.log.catch(err, void 0, {
|
|
452
444
|
F: __dxlog_file3,
|
|
453
|
-
L:
|
|
445
|
+
L: 193,
|
|
454
446
|
S: this,
|
|
455
447
|
C: (f, a) => f(...a)
|
|
456
448
|
});
|
|
@@ -467,7 +459,7 @@ var DevServer = class {
|
|
|
467
459
|
path: path2
|
|
468
460
|
}, {
|
|
469
461
|
F: __dxlog_file3,
|
|
470
|
-
L:
|
|
462
|
+
L: 204,
|
|
471
463
|
S: this,
|
|
472
464
|
C: (f, a) => f(...a)
|
|
473
465
|
});
|
|
@@ -481,7 +473,7 @@ var DevServer = class {
|
|
|
481
473
|
duration: Date.now() - now
|
|
482
474
|
}, {
|
|
483
475
|
F: __dxlog_file3,
|
|
484
|
-
L:
|
|
476
|
+
L: 207,
|
|
485
477
|
S: this,
|
|
486
478
|
C: (f, a) => f(...a)
|
|
487
479
|
});
|
|
@@ -492,7 +484,7 @@ var DevServer = class {
|
|
|
492
484
|
const { handler } = this._handlers[path2] ?? {};
|
|
493
485
|
(0, import_invariant.invariant)(handler, `invalid path: ${path2}`, {
|
|
494
486
|
F: __dxlog_file3,
|
|
495
|
-
L:
|
|
487
|
+
L: 214,
|
|
496
488
|
S: this,
|
|
497
489
|
A: [
|
|
498
490
|
"handler",
|
|
@@ -528,7 +520,7 @@ var Scheduler = class {
|
|
|
528
520
|
this.triggers = triggers;
|
|
529
521
|
this._options = _options;
|
|
530
522
|
this._ctx = createContext2();
|
|
531
|
-
this.
|
|
523
|
+
this._functionUriToCallMutex = /* @__PURE__ */ new Map();
|
|
532
524
|
this.functions.registered.on(async ({ space, added }) => {
|
|
533
525
|
await this._safeActivateTriggers(space, this.triggers.getInactiveTriggers(space), added);
|
|
534
526
|
});
|
|
@@ -558,11 +550,11 @@ var Scheduler = class {
|
|
|
558
550
|
});
|
|
559
551
|
await Promise.all(mountTasks).catch(import_log4.log.catch);
|
|
560
552
|
}
|
|
561
|
-
async activate(space, functions,
|
|
562
|
-
const definition = functions.find((def) => def.uri ===
|
|
553
|
+
async activate(space, functions, trigger) {
|
|
554
|
+
const definition = functions.find((def) => def.uri === trigger.function);
|
|
563
555
|
if (!definition) {
|
|
564
556
|
import_log4.log.info("function is not found for trigger", {
|
|
565
|
-
|
|
557
|
+
trigger
|
|
566
558
|
}, {
|
|
567
559
|
F: __dxlog_file4,
|
|
568
560
|
L: 78,
|
|
@@ -571,12 +563,28 @@ var Scheduler = class {
|
|
|
571
563
|
});
|
|
572
564
|
return;
|
|
573
565
|
}
|
|
574
|
-
await this.triggers.activate({
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
566
|
+
await this.triggers.activate(space, trigger, async (args) => {
|
|
567
|
+
const mutex = this._functionUriToCallMutex.get(definition.uri) ?? new import_async3.Mutex();
|
|
568
|
+
this._functionUriToCallMutex.set(definition.uri, mutex);
|
|
569
|
+
import_log4.log.info("function triggered, waiting for mutex", {
|
|
570
|
+
uri: definition.uri
|
|
571
|
+
}, {
|
|
572
|
+
F: __dxlog_file4,
|
|
573
|
+
L: 86,
|
|
574
|
+
S: this,
|
|
575
|
+
C: (f, a) => f(...a)
|
|
576
|
+
});
|
|
577
|
+
return mutex.executeSynchronized(() => {
|
|
578
|
+
import_log4.log.info("mutex acquired", {
|
|
579
|
+
uri: definition.uri
|
|
580
|
+
}, {
|
|
581
|
+
F: __dxlog_file4,
|
|
582
|
+
L: 88,
|
|
583
|
+
S: this,
|
|
584
|
+
C: (f, a) => f(...a)
|
|
585
|
+
});
|
|
586
|
+
return this._execFunction(definition, trigger, {
|
|
587
|
+
meta: trigger.meta ?? {},
|
|
580
588
|
data: {
|
|
581
589
|
...args,
|
|
582
590
|
spaceKey: space.key
|
|
@@ -586,10 +594,10 @@ var Scheduler = class {
|
|
|
586
594
|
});
|
|
587
595
|
(0, import_log4.log)("activated trigger", {
|
|
588
596
|
space: space.key,
|
|
589
|
-
trigger
|
|
597
|
+
trigger
|
|
590
598
|
}, {
|
|
591
599
|
F: __dxlog_file4,
|
|
592
|
-
L:
|
|
600
|
+
L: 96,
|
|
593
601
|
S: this,
|
|
594
602
|
C: (f, a) => f(...a)
|
|
595
603
|
});
|
|
@@ -609,7 +617,7 @@ var Scheduler = class {
|
|
|
609
617
|
triggerType: trigger.spec.type
|
|
610
618
|
}, {
|
|
611
619
|
F: __dxlog_file4,
|
|
612
|
-
L:
|
|
620
|
+
L: 113,
|
|
613
621
|
S: this,
|
|
614
622
|
C: (f, a) => f(...a)
|
|
615
623
|
});
|
|
@@ -626,7 +634,7 @@ var Scheduler = class {
|
|
|
626
634
|
function: def.uri
|
|
627
635
|
}, {
|
|
628
636
|
F: __dxlog_file4,
|
|
629
|
-
L:
|
|
637
|
+
L: 124,
|
|
630
638
|
S: this,
|
|
631
639
|
C: (f, a) => f(...a)
|
|
632
640
|
});
|
|
@@ -640,7 +648,7 @@ var Scheduler = class {
|
|
|
640
648
|
status
|
|
641
649
|
}, {
|
|
642
650
|
F: __dxlog_file4,
|
|
643
|
-
L:
|
|
651
|
+
L: 134,
|
|
644
652
|
S: this,
|
|
645
653
|
C: (f, a) => f(...a)
|
|
646
654
|
});
|
|
@@ -650,7 +658,7 @@ var Scheduler = class {
|
|
|
650
658
|
error: err.message
|
|
651
659
|
}, {
|
|
652
660
|
F: __dxlog_file4,
|
|
653
|
-
L:
|
|
661
|
+
L: 136,
|
|
654
662
|
S: this,
|
|
655
663
|
C: (f, a) => f(...a)
|
|
656
664
|
});
|
|
@@ -663,7 +671,7 @@ var createContext2 = () => new import_context3.Context({
|
|
|
663
671
|
name: "FunctionScheduler"
|
|
664
672
|
});
|
|
665
673
|
var __dxlog_file5 = "/home/runner/work/dxos/dxos/packages/core/functions/src/trigger/type/subscription-trigger.ts";
|
|
666
|
-
var createSubscriptionTrigger = async (ctx,
|
|
674
|
+
var createSubscriptionTrigger = async (ctx, space, spec, callback) => {
|
|
667
675
|
const objectIds = /* @__PURE__ */ new Set();
|
|
668
676
|
const task = new import_async5.UpdateScheduler(ctx, async () => {
|
|
669
677
|
if (objectIds.size > 0) {
|
|
@@ -691,7 +699,7 @@ var createSubscriptionTrigger = async (ctx, triggerCtx, spec, callback) => {
|
|
|
691
699
|
updated: updated.length
|
|
692
700
|
}, {
|
|
693
701
|
F: __dxlog_file5,
|
|
694
|
-
L:
|
|
702
|
+
L: 47,
|
|
695
703
|
S: void 0,
|
|
696
704
|
C: (f, a) => f(...a)
|
|
697
705
|
});
|
|
@@ -701,16 +709,16 @@ var createSubscriptionTrigger = async (ctx, triggerCtx, spec, callback) => {
|
|
|
701
709
|
subscriptions.push(() => subscription.unsubscribe());
|
|
702
710
|
const { filter, options: { deep, delay } = {} } = spec;
|
|
703
711
|
const update = ({ objects }) => {
|
|
712
|
+
import_log6.log.info("update", {
|
|
713
|
+
objects: objects.length
|
|
714
|
+
}, {
|
|
715
|
+
F: __dxlog_file5,
|
|
716
|
+
L: 57,
|
|
717
|
+
S: void 0,
|
|
718
|
+
C: (f, a) => f(...a)
|
|
719
|
+
});
|
|
704
720
|
subscription.update(objects);
|
|
705
721
|
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
722
|
for (const object of objects) {
|
|
715
723
|
const content = object.content;
|
|
716
724
|
if (content instanceof import_types.TextV0Type) {
|
|
@@ -721,14 +729,24 @@ var createSubscriptionTrigger = async (ctx, triggerCtx, spec, callback) => {
|
|
|
721
729
|
}
|
|
722
730
|
}
|
|
723
731
|
};
|
|
724
|
-
|
|
725
|
-
|
|
732
|
+
import_log6.log.info("subscription", {
|
|
733
|
+
filter
|
|
734
|
+
}, {
|
|
735
|
+
F: __dxlog_file5,
|
|
736
|
+
L: 76,
|
|
737
|
+
S: void 0,
|
|
738
|
+
C: (f, a) => f(...a)
|
|
739
|
+
});
|
|
740
|
+
if (filter) {
|
|
741
|
+
const query = space.db.query(import_echo3.Filter.typename(filter[0].type, filter[0].props));
|
|
742
|
+
subscriptions.push(query.subscribe(delay ? (0, import_async5.debounce)(update, delay) : update));
|
|
743
|
+
}
|
|
726
744
|
ctx.onDispose(() => {
|
|
727
745
|
subscriptions.forEach((unsubscribe) => unsubscribe());
|
|
728
746
|
});
|
|
729
747
|
};
|
|
730
748
|
var __dxlog_file6 = "/home/runner/work/dxos/dxos/packages/core/functions/src/trigger/type/timer-trigger.ts";
|
|
731
|
-
var createTimerTrigger = async (ctx,
|
|
749
|
+
var createTimerTrigger = async (ctx, space, spec, callback) => {
|
|
732
750
|
const task = new import_async6.DeferredTask(ctx, async () => {
|
|
733
751
|
await callback({});
|
|
734
752
|
});
|
|
@@ -743,12 +761,12 @@ var createTimerTrigger = async (ctx, triggerContext, spec, callback) => {
|
|
|
743
761
|
last = now;
|
|
744
762
|
run++;
|
|
745
763
|
import_log7.log.info("tick", {
|
|
746
|
-
space:
|
|
764
|
+
space: space.key.truncate(),
|
|
747
765
|
count: run,
|
|
748
766
|
delta
|
|
749
767
|
}, {
|
|
750
768
|
F: __dxlog_file6,
|
|
751
|
-
L:
|
|
769
|
+
L: 38,
|
|
752
770
|
S: void 0,
|
|
753
771
|
C: (f, a) => f(...a)
|
|
754
772
|
});
|
|
@@ -759,7 +777,7 @@ var createTimerTrigger = async (ctx, triggerContext, spec, callback) => {
|
|
|
759
777
|
ctx.onDispose(() => job.stop());
|
|
760
778
|
};
|
|
761
779
|
var __dxlog_file7 = "/home/runner/work/dxos/dxos/packages/core/functions/src/trigger/type/webhook-trigger.ts";
|
|
762
|
-
var createWebhookTrigger = async (ctx,
|
|
780
|
+
var createWebhookTrigger = async (ctx, space, spec, callback) => {
|
|
763
781
|
const server = import_node_http.default.createServer(async (req, res) => {
|
|
764
782
|
if (req.method !== spec.method) {
|
|
765
783
|
res.statusCode = 405;
|
|
@@ -776,7 +794,7 @@ var createWebhookTrigger = async (ctx, _, spec, callback) => {
|
|
|
776
794
|
port
|
|
777
795
|
}, {
|
|
778
796
|
F: __dxlog_file7,
|
|
779
|
-
L:
|
|
797
|
+
L: 41,
|
|
780
798
|
S: void 0,
|
|
781
799
|
C: (f, a) => f(...a)
|
|
782
800
|
});
|
|
@@ -787,7 +805,7 @@ var createWebhookTrigger = async (ctx, _, spec, callback) => {
|
|
|
787
805
|
});
|
|
788
806
|
};
|
|
789
807
|
var __dxlog_file8 = "/home/runner/work/dxos/dxos/packages/core/functions/src/trigger/type/websocket-trigger.ts";
|
|
790
|
-
var createWebsocketTrigger = async (ctx,
|
|
808
|
+
var createWebsocketTrigger = async (ctx, space, spec, callback, options = {
|
|
791
809
|
retryDelay: 2,
|
|
792
810
|
maxAttempts: 5
|
|
793
811
|
}) => {
|
|
@@ -802,7 +820,7 @@ var createWebsocketTrigger = async (ctx, triggerCtx, spec, callback, options = {
|
|
|
802
820
|
url
|
|
803
821
|
}, {
|
|
804
822
|
F: __dxlog_file8,
|
|
805
|
-
L:
|
|
823
|
+
L: 40,
|
|
806
824
|
S: void 0,
|
|
807
825
|
C: (f, a) => f(...a)
|
|
808
826
|
});
|
|
@@ -817,7 +835,7 @@ var createWebsocketTrigger = async (ctx, triggerCtx, spec, callback, options = {
|
|
|
817
835
|
code: event.code
|
|
818
836
|
}, {
|
|
819
837
|
F: __dxlog_file8,
|
|
820
|
-
L:
|
|
838
|
+
L: 49,
|
|
821
839
|
S: void 0,
|
|
822
840
|
C: (f, a) => f(...a)
|
|
823
841
|
});
|
|
@@ -827,11 +845,11 @@ var createWebsocketTrigger = async (ctx, triggerCtx, spec, callback, options = {
|
|
|
827
845
|
url
|
|
828
846
|
}, {
|
|
829
847
|
F: __dxlog_file8,
|
|
830
|
-
L:
|
|
848
|
+
L: 54,
|
|
831
849
|
S: void 0,
|
|
832
850
|
C: (f, a) => f(...a)
|
|
833
851
|
});
|
|
834
|
-
await createWebsocketTrigger(ctx,
|
|
852
|
+
await createWebsocketTrigger(ctx, space, spec, callback, options);
|
|
835
853
|
}, options.retryDelay * 1e3);
|
|
836
854
|
}
|
|
837
855
|
open.wake(false);
|
|
@@ -841,7 +859,7 @@ var createWebsocketTrigger = async (ctx, triggerCtx, spec, callback, options = {
|
|
|
841
859
|
url
|
|
842
860
|
}, {
|
|
843
861
|
F: __dxlog_file8,
|
|
844
|
-
L:
|
|
862
|
+
L: 63,
|
|
845
863
|
S: void 0,
|
|
846
864
|
C: (f, a) => f(...a)
|
|
847
865
|
});
|
|
@@ -850,7 +868,7 @@ var createWebsocketTrigger = async (ctx, triggerCtx, spec, callback, options = {
|
|
|
850
868
|
try {
|
|
851
869
|
import_log9.log.info("message", void 0, {
|
|
852
870
|
F: __dxlog_file8,
|
|
853
|
-
L:
|
|
871
|
+
L: 68,
|
|
854
872
|
S: void 0,
|
|
855
873
|
C: (f, a) => f(...a)
|
|
856
874
|
});
|
|
@@ -863,7 +881,7 @@ var createWebsocketTrigger = async (ctx, triggerCtx, spec, callback, options = {
|
|
|
863
881
|
url
|
|
864
882
|
}, {
|
|
865
883
|
F: __dxlog_file8,
|
|
866
|
-
L:
|
|
884
|
+
L: 72,
|
|
867
885
|
S: void 0,
|
|
868
886
|
C: (f, a) => f(...a)
|
|
869
887
|
});
|
|
@@ -880,7 +898,7 @@ var createWebsocketTrigger = async (ctx, triggerCtx, spec, callback, options = {
|
|
|
880
898
|
attempt
|
|
881
899
|
}, {
|
|
882
900
|
F: __dxlog_file8,
|
|
883
|
-
L:
|
|
901
|
+
L: 83,
|
|
884
902
|
S: void 0,
|
|
885
903
|
C: (f, a) => f(...a)
|
|
886
904
|
});
|
|
@@ -914,24 +932,24 @@ var TriggerRegistry = class extends import_context4.Resource {
|
|
|
914
932
|
getInactiveTriggers(space) {
|
|
915
933
|
return this._getTriggers(space, (t) => t.activationCtx == null);
|
|
916
934
|
}
|
|
917
|
-
async activate(
|
|
935
|
+
async activate(space, trigger, callback) {
|
|
918
936
|
(0, import_log5.log)("activate", {
|
|
919
|
-
space:
|
|
937
|
+
space: space.key,
|
|
920
938
|
trigger
|
|
921
939
|
}, {
|
|
922
940
|
F: __dxlog_file9,
|
|
923
|
-
L:
|
|
941
|
+
L: 72,
|
|
924
942
|
S: this,
|
|
925
943
|
C: (f, a) => f(...a)
|
|
926
944
|
});
|
|
927
945
|
const activationCtx = new import_context4.Context({
|
|
928
|
-
name: `
|
|
946
|
+
name: `FunctionTrigger-${trigger.function}`
|
|
929
947
|
});
|
|
930
948
|
this._ctx.onDispose(() => activationCtx.dispose());
|
|
931
|
-
const registeredTrigger = this._triggersBySpaceKey.get(
|
|
949
|
+
const registeredTrigger = this._triggersBySpaceKey.get(space.key)?.find((reg) => reg.trigger.id === trigger.id);
|
|
932
950
|
(0, import_invariant2.invariant)(registeredTrigger, `Trigger is not registered: ${trigger.function}`, {
|
|
933
951
|
F: __dxlog_file9,
|
|
934
|
-
L:
|
|
952
|
+
L: 77,
|
|
935
953
|
S: this,
|
|
936
954
|
A: [
|
|
937
955
|
"registeredTrigger",
|
|
@@ -941,7 +959,7 @@ var TriggerRegistry = class extends import_context4.Resource {
|
|
|
941
959
|
registeredTrigger.activationCtx = activationCtx;
|
|
942
960
|
try {
|
|
943
961
|
const options = this._options?.[trigger.spec.type];
|
|
944
|
-
await triggerHandlers[trigger.spec.type](activationCtx,
|
|
962
|
+
await triggerHandlers[trigger.spec.type](activationCtx, space, trigger.spec, callback, options);
|
|
945
963
|
} catch (err) {
|
|
946
964
|
delete registeredTrigger.activationCtx;
|
|
947
965
|
throw err;
|
|
@@ -955,33 +973,55 @@ var TriggerRegistry = class extends import_context4.Resource {
|
|
|
955
973
|
space: space.key
|
|
956
974
|
}, {
|
|
957
975
|
F: __dxlog_file9,
|
|
958
|
-
L:
|
|
976
|
+
L: 93,
|
|
959
977
|
S: this,
|
|
960
978
|
C: (f, a) => f(...a)
|
|
961
979
|
});
|
|
962
980
|
if (!manifest.triggers?.length) {
|
|
963
981
|
return;
|
|
964
982
|
}
|
|
965
|
-
if (!space.db.graph.runtimeSchemaRegistry.hasSchema(
|
|
966
|
-
space.db.graph.runtimeSchemaRegistry.registerSchema(
|
|
983
|
+
if (!space.db.graph.runtimeSchemaRegistry.hasSchema(import_chunk_3UYUR5N5.FunctionTrigger)) {
|
|
984
|
+
space.db.graph.runtimeSchemaRegistry.registerSchema(import_chunk_3UYUR5N5.FunctionTrigger);
|
|
967
985
|
}
|
|
968
|
-
const
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
986
|
+
const manifestTriggers = manifest.triggers.map((trigger) => {
|
|
987
|
+
let keys = trigger[import_echo_schema.ECHO_ATTR_META]?.keys;
|
|
988
|
+
delete trigger[import_echo_schema.ECHO_ATTR_META];
|
|
989
|
+
if (!keys?.length) {
|
|
990
|
+
keys = [
|
|
991
|
+
(0, import_echo_schema.foreignKey)("manifest", [
|
|
992
|
+
trigger.function,
|
|
993
|
+
trigger.spec.type
|
|
994
|
+
].join(":"))
|
|
995
|
+
];
|
|
996
|
+
}
|
|
997
|
+
return (0, import_echo2.create)(import_chunk_3UYUR5N5.FunctionTrigger, trigger, {
|
|
998
|
+
keys
|
|
999
|
+
});
|
|
977
1000
|
});
|
|
1001
|
+
const { objects: existing } = await space.db.query(import_echo2.Filter.schema(import_chunk_3UYUR5N5.FunctionTrigger)).run();
|
|
1002
|
+
const { added } = (0, import_util3.diff)(existing, manifestTriggers, import_echo_schema.compareForeignKeys);
|
|
978
1003
|
added.forEach((trigger) => {
|
|
979
|
-
|
|
980
|
-
|
|
1004
|
+
space.db.add(trigger);
|
|
1005
|
+
import_log5.log.info("added", {
|
|
1006
|
+
meta: (0, import_echo2.getMeta)(trigger)
|
|
1007
|
+
}, {
|
|
1008
|
+
F: __dxlog_file9,
|
|
1009
|
+
L: 120,
|
|
1010
|
+
S: this,
|
|
1011
|
+
C: (f, a) => f(...a)
|
|
1012
|
+
});
|
|
981
1013
|
});
|
|
982
|
-
|
|
1014
|
+
if (added.length > 0) {
|
|
1015
|
+
await space.db.flush();
|
|
1016
|
+
}
|
|
983
1017
|
}
|
|
984
1018
|
async _open() {
|
|
1019
|
+
import_log5.log.info("open...", void 0, {
|
|
1020
|
+
F: __dxlog_file9,
|
|
1021
|
+
L: 129,
|
|
1022
|
+
S: this,
|
|
1023
|
+
C: (f, a) => f(...a)
|
|
1024
|
+
});
|
|
985
1025
|
const spaceListSubscription = this._client.spaces.subscribe(async (spaces) => {
|
|
986
1026
|
for (const space of spaces) {
|
|
987
1027
|
if (this._triggersBySpaceKey.has(space.key)) {
|
|
@@ -993,46 +1033,73 @@ var TriggerRegistry = class extends import_context4.Resource {
|
|
|
993
1033
|
if (this._ctx.disposed) {
|
|
994
1034
|
break;
|
|
995
1035
|
}
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1036
|
+
this._ctx.onDispose(space.db.query(import_echo2.Filter.schema(import_chunk_3UYUR5N5.FunctionTrigger)).subscribe(async ({ objects: current }) => {
|
|
1037
|
+
import_log5.log.info("update", {
|
|
1038
|
+
space: space.key,
|
|
1039
|
+
registered: registered.length,
|
|
1040
|
+
current: current.length
|
|
1041
|
+
}, {
|
|
1042
|
+
F: __dxlog_file9,
|
|
1043
|
+
L: 146,
|
|
1044
|
+
S: this,
|
|
1045
|
+
C: (f, a) => f(...a)
|
|
1046
|
+
});
|
|
1047
|
+
await this._handleRemovedTriggers(space, current, registered);
|
|
1048
|
+
this._handleNewTriggers(space, current, registered);
|
|
1049
|
+
}));
|
|
1001
1050
|
}
|
|
1002
1051
|
});
|
|
1003
1052
|
this._ctx.onDispose(() => spaceListSubscription.unsubscribe());
|
|
1053
|
+
import_log5.log.info("opened", void 0, {
|
|
1054
|
+
F: __dxlog_file9,
|
|
1055
|
+
L: 155,
|
|
1056
|
+
S: this,
|
|
1057
|
+
C: (f, a) => f(...a)
|
|
1058
|
+
});
|
|
1004
1059
|
}
|
|
1005
1060
|
async _close(_) {
|
|
1061
|
+
import_log5.log.info("close...", void 0, {
|
|
1062
|
+
F: __dxlog_file9,
|
|
1063
|
+
L: 159,
|
|
1064
|
+
S: this,
|
|
1065
|
+
C: (f, a) => f(...a)
|
|
1066
|
+
});
|
|
1006
1067
|
this._triggersBySpaceKey.clear();
|
|
1068
|
+
import_log5.log.info("closed", void 0, {
|
|
1069
|
+
F: __dxlog_file9,
|
|
1070
|
+
L: 161,
|
|
1071
|
+
S: this,
|
|
1072
|
+
C: (f, a) => f(...a)
|
|
1073
|
+
});
|
|
1007
1074
|
}
|
|
1008
|
-
_handleNewTriggers(space,
|
|
1009
|
-
const
|
|
1010
|
-
return registered.find((reg) => reg.trigger.id === candidate.id) == null;
|
|
1075
|
+
_handleNewTriggers(space, current, registered) {
|
|
1076
|
+
const added = current.filter((candidate) => {
|
|
1077
|
+
return candidate.enabled && registered.find((reg) => reg.trigger.id === candidate.id) == null;
|
|
1011
1078
|
});
|
|
1012
|
-
if (
|
|
1013
|
-
const newRegisteredTriggers =
|
|
1079
|
+
if (added.length > 0) {
|
|
1080
|
+
const newRegisteredTriggers = added.map((trigger) => ({
|
|
1014
1081
|
trigger
|
|
1015
1082
|
}));
|
|
1016
1083
|
registered.push(...newRegisteredTriggers);
|
|
1017
|
-
|
|
1084
|
+
import_log5.log.info("added", () => ({
|
|
1018
1085
|
spaceKey: space.key,
|
|
1019
|
-
|
|
1086
|
+
triggers: added.map((trigger) => trigger.function)
|
|
1020
1087
|
}), {
|
|
1021
1088
|
F: __dxlog_file9,
|
|
1022
|
-
L:
|
|
1089
|
+
L: 172,
|
|
1023
1090
|
S: this,
|
|
1024
1091
|
C: (f, a) => f(...a)
|
|
1025
1092
|
});
|
|
1026
1093
|
this.registered.emit({
|
|
1027
1094
|
space,
|
|
1028
|
-
triggers:
|
|
1095
|
+
triggers: added
|
|
1029
1096
|
});
|
|
1030
1097
|
}
|
|
1031
1098
|
}
|
|
1032
|
-
async _handleRemovedTriggers(space,
|
|
1099
|
+
async _handleRemovedTriggers(space, current, registered) {
|
|
1033
1100
|
const removed = [];
|
|
1034
1101
|
for (let i = registered.length - 1; i >= 0; i--) {
|
|
1035
|
-
const wasRemoved =
|
|
1102
|
+
const wasRemoved = current.filter((trigger) => trigger.enabled).find((trigger) => trigger.id === registered[i].trigger.id) == null;
|
|
1036
1103
|
if (wasRemoved) {
|
|
1037
1104
|
const unregistered = registered.splice(i, 1)[0];
|
|
1038
1105
|
await unregistered.activationCtx?.dispose();
|
|
@@ -1040,6 +1107,15 @@ var TriggerRegistry = class extends import_context4.Resource {
|
|
|
1040
1107
|
}
|
|
1041
1108
|
}
|
|
1042
1109
|
if (removed.length > 0) {
|
|
1110
|
+
import_log5.log.info("removed", () => ({
|
|
1111
|
+
spaceKey: space.key,
|
|
1112
|
+
triggers: removed.map((trigger) => trigger.function)
|
|
1113
|
+
}), {
|
|
1114
|
+
F: __dxlog_file9,
|
|
1115
|
+
L: 198,
|
|
1116
|
+
S: this,
|
|
1117
|
+
C: (f, a) => f(...a)
|
|
1118
|
+
});
|
|
1043
1119
|
this.removed.emit({
|
|
1044
1120
|
space,
|
|
1045
1121
|
triggers: removed
|
|
@@ -1054,6 +1130,7 @@ var TriggerRegistry = class extends import_context4.Resource {
|
|
|
1054
1130
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1055
1131
|
0 && (module.exports = {
|
|
1056
1132
|
DevServer,
|
|
1133
|
+
FUNCTION_SCHEMA,
|
|
1057
1134
|
FunctionDef,
|
|
1058
1135
|
FunctionManifestSchema,
|
|
1059
1136
|
FunctionRegistry,
|