@dxos/functions 0.5.9-main.a22f041 → 0.5.9-main.a2de4fa

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.
Files changed (34) hide show
  1. package/dist/lib/browser/{chunk-G7PWVLC5.mjs → chunk-ROZT7SSI.mjs} +57 -36
  2. package/dist/lib/browser/chunk-ROZT7SSI.mjs.map +7 -0
  3. package/dist/lib/browser/{chunk-ERWZ4JUZ.mjs → chunk-YSDC6YCF.mjs} +2 -2
  4. package/dist/lib/browser/{chunk-ERWZ4JUZ.mjs.map → chunk-YSDC6YCF.mjs.map} +2 -2
  5. package/dist/lib/browser/index.mjs +2 -2
  6. package/dist/lib/browser/meta.json +1 -1
  7. package/dist/lib/browser/testing/index.mjs +3 -3
  8. package/dist/lib/browser/testing/index.mjs.map +2 -2
  9. package/dist/lib/browser/types.mjs +1 -1
  10. package/dist/lib/node/{chunk-BLLSDTKZ.cjs → chunk-3E6PY6JH.cjs} +5 -5
  11. package/dist/lib/node/{chunk-BLLSDTKZ.cjs.map → chunk-3E6PY6JH.cjs.map} +2 -2
  12. package/dist/lib/node/{chunk-BW7KSYIH.cjs → chunk-H5Q2TXOA.cjs} +76 -55
  13. package/dist/lib/node/chunk-H5Q2TXOA.cjs.map +7 -0
  14. package/dist/lib/node/index.cjs +10 -10
  15. package/dist/lib/node/meta.json +1 -1
  16. package/dist/lib/node/testing/index.cjs +10 -10
  17. package/dist/lib/node/testing/index.cjs.map +2 -2
  18. package/dist/lib/node/types.cjs +5 -5
  19. package/dist/lib/node/types.cjs.map +1 -1
  20. package/dist/types/src/runtime/dev-server.d.ts +2 -1
  21. package/dist/types/src/runtime/dev-server.d.ts.map +1 -1
  22. package/dist/types/src/runtime/scheduler.d.ts +8 -1
  23. package/dist/types/src/runtime/scheduler.d.ts.map +1 -1
  24. package/dist/types/src/testing/setup.d.ts +1 -1
  25. package/package.json +15 -14
  26. package/src/runtime/dev-server.test.ts +3 -3
  27. package/src/runtime/dev-server.ts +6 -3
  28. package/src/runtime/scheduler.ts +29 -6
  29. package/src/testing/functions-integration.test.ts +1 -1
  30. package/src/testing/setup.ts +1 -1
  31. package/src/trigger/type/subscription-trigger.ts +2 -2
  32. package/src/types.ts +1 -1
  33. package/dist/lib/browser/chunk-G7PWVLC5.mjs.map +0 -7
  34. package/dist/lib/node/chunk-BW7KSYIH.cjs.map +0 -7
@@ -26,15 +26,15 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
26
26
  mod
27
27
  ));
28
28
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
- var chunk_BW7KSYIH_exports = {};
30
- __export(chunk_BW7KSYIH_exports, {
29
+ var chunk_H5Q2TXOA_exports = {};
30
+ __export(chunk_H5Q2TXOA_exports, {
31
31
  DevServer: () => DevServer,
32
32
  FunctionRegistry: () => FunctionRegistry,
33
33
  Scheduler: () => Scheduler,
34
34
  TriggerRegistry: () => TriggerRegistry
35
35
  });
36
- module.exports = __toCommonJS(chunk_BW7KSYIH_exports);
37
- var import_chunk_BLLSDTKZ = require("./chunk-BLLSDTKZ.cjs");
36
+ module.exports = __toCommonJS(chunk_H5Q2TXOA_exports);
37
+ var import_chunk_3E6PY6JH = require("./chunk-3E6PY6JH.cjs");
38
38
  var import_async = require("@dxos/async");
39
39
  var import_echo = require("@dxos/client/echo");
40
40
  var import_context = require("@dxos/context");
@@ -50,10 +50,12 @@ var import_invariant = require("@dxos/invariant");
50
50
  var import_log2 = require("@dxos/log");
51
51
  var import_node_path2 = __toESM(require("node:path"));
52
52
  var import_async3 = require("@dxos/async");
53
+ var import_echo2 = require("@dxos/client/echo");
53
54
  var import_context3 = require("@dxos/context");
55
+ var import_echo_protocol = require("@dxos/echo-protocol");
54
56
  var import_log3 = require("@dxos/log");
55
57
  var import_async4 = require("@dxos/async");
56
- var import_echo2 = require("@dxos/client/echo");
58
+ var import_echo3 = require("@dxos/client/echo");
57
59
  var import_context4 = require("@dxos/context");
58
60
  var import_echo_schema = require("@dxos/echo-schema");
59
61
  var import_invariant2 = require("@dxos/invariant");
@@ -62,7 +64,7 @@ var import_log4 = require("@dxos/log");
62
64
  var import_util2 = require("@dxos/util");
63
65
  var import_types = require("@braneframe/types");
64
66
  var import_async5 = require("@dxos/async");
65
- var import_echo3 = require("@dxos/client/echo");
67
+ var import_echo4 = require("@dxos/client/echo");
66
68
  var import_echo_db = require("@dxos/echo-db");
67
69
  var import_log5 = require("@dxos/log");
68
70
  var import_cron = require("cron");
@@ -113,14 +115,14 @@ var FunctionRegistry = class extends import_context.Resource {
113
115
  if (!functions?.length) {
114
116
  return;
115
117
  }
116
- if (!space.db.graph.schemaRegistry.hasSchema(import_chunk_BLLSDTKZ.FunctionDef)) {
118
+ if (!space.db.graph.schemaRegistry.hasSchema(import_chunk_3E6PY6JH.FunctionDef)) {
117
119
  space.db.graph.schemaRegistry.addSchema([
118
- import_chunk_BLLSDTKZ.FunctionDef
120
+ import_chunk_3E6PY6JH.FunctionDef
119
121
  ]);
120
122
  }
121
- const { objects: existing } = await space.db.query(import_echo.Filter.schema(import_chunk_BLLSDTKZ.FunctionDef)).run();
123
+ const { objects: existing } = await space.db.query(import_echo.Filter.schema(import_chunk_3E6PY6JH.FunctionDef)).run();
122
124
  const { added } = (0, import_util.diff)(existing, functions, (a, b) => a.uri === b.uri);
123
- added.forEach((def) => space.db.add((0, import_echo.create)(import_chunk_BLLSDTKZ.FunctionDef, def)));
125
+ added.forEach((def) => space.db.add((0, import_echo.create)(import_chunk_3E6PY6JH.FunctionDef, def)));
124
126
  }
125
127
  async _open() {
126
128
  import_log.log.info("opening...", void 0, {
@@ -140,7 +142,7 @@ var FunctionRegistry = class extends import_context.Resource {
140
142
  if (this._ctx.disposed) {
141
143
  break;
142
144
  }
143
- this._ctx.onDispose(space.db.query(import_echo.Filter.schema(import_chunk_BLLSDTKZ.FunctionDef)).subscribe(({ objects }) => {
145
+ this._ctx.onDispose(space.db.query(import_echo.Filter.schema(import_chunk_3E6PY6JH.FunctionDef)).subscribe(({ objects }) => {
144
146
  const { added } = (0, import_util.diff)(registered, objects, (a, b) => a.uri === b.uri);
145
147
  if (added.length > 0) {
146
148
  registered.push(...added);
@@ -165,6 +167,7 @@ var FunctionRegistry = class extends import_context.Resource {
165
167
  }
166
168
  };
167
169
  var __dxlog_file2 = "/home/runner/work/dxos/dxos/packages/core/functions/src/runtime/dev-server.ts";
170
+ var FN_TIMEOUT = 2e4;
168
171
  var DevServer = class {
169
172
  constructor(_client, _functionsRegistry, _options) {
170
173
  this._client = _client;
@@ -183,7 +186,7 @@ var DevServer = class {
183
186
  get endpoint() {
184
187
  (0, import_invariant.invariant)(this._port, void 0, {
185
188
  F: __dxlog_file2,
186
- L: 57,
189
+ L: 60,
187
190
  S: this,
188
191
  A: [
189
192
  "this._port",
@@ -201,7 +204,7 @@ var DevServer = class {
201
204
  async start() {
202
205
  (0, import_invariant.invariant)(!this._server, void 0, {
203
206
  F: __dxlog_file2,
204
- L: 70,
207
+ L: 73,
205
208
  S: this,
206
209
  A: [
207
210
  "!this._server",
@@ -210,7 +213,7 @@ var DevServer = class {
210
213
  });
211
214
  import_log2.log.info("starting...", void 0, {
212
215
  F: __dxlog_file2,
213
- L: 71,
216
+ L: 74,
214
217
  S: this,
215
218
  C: (f, a) => f(...a)
216
219
  });
@@ -224,7 +227,7 @@ var DevServer = class {
224
227
  path: path2
225
228
  }, {
226
229
  F: __dxlog_file2,
227
- L: 81,
230
+ L: 84,
228
231
  S: this,
229
232
  C: (f, a) => f(...a)
230
233
  });
@@ -232,12 +235,12 @@ var DevServer = class {
232
235
  const { def } = this._handlers["/" + path2];
233
236
  await this._load(def, true);
234
237
  }
235
- res.statusCode = await (0, import_async2.asyncTimeout)(this.invoke("/" + path2, req.body), 2e4);
238
+ res.statusCode = await (0, import_async2.asyncTimeout)(this.invoke("/" + path2, req.body), FN_TIMEOUT);
236
239
  res.end();
237
240
  } catch (err) {
238
241
  import_log2.log.catch(err, void 0, {
239
242
  F: __dxlog_file2,
240
- L: 91,
243
+ L: 94,
241
244
  S: this,
242
245
  C: (f, a) => f(...a)
243
246
  });
@@ -262,7 +265,7 @@ var DevServer = class {
262
265
  endpoint
263
266
  }, {
264
267
  F: __dxlog_file2,
265
- L: 106,
268
+ L: 109,
266
269
  S: this,
267
270
  C: (f, a) => f(...a)
268
271
  });
@@ -278,7 +281,7 @@ var DevServer = class {
278
281
  port: this._port
279
282
  }, {
280
283
  F: __dxlog_file2,
281
- L: 118,
284
+ L: 121,
282
285
  S: this,
283
286
  C: (f, a) => f(...a)
284
287
  });
@@ -289,7 +292,7 @@ var DevServer = class {
289
292
  }
290
293
  import_log2.log.info("stopping...", void 0, {
291
294
  F: __dxlog_file2,
292
- L: 126,
295
+ L: 129,
293
296
  S: this,
294
297
  C: (f, a) => f(...a)
295
298
  });
@@ -298,7 +301,7 @@ var DevServer = class {
298
301
  this._server.close(async () => {
299
302
  import_log2.log.info("server stopped", void 0, {
300
303
  F: __dxlog_file2,
301
- L: 131,
304
+ L: 134,
302
305
  S: this,
303
306
  C: (f, a) => f(...a)
304
307
  });
@@ -306,7 +309,7 @@ var DevServer = class {
306
309
  if (this._functionServiceRegistration) {
307
310
  (0, import_invariant.invariant)(this._client.services.services.FunctionRegistryService, void 0, {
308
311
  F: __dxlog_file2,
309
- L: 134,
312
+ L: 137,
310
313
  S: this,
311
314
  A: [
312
315
  "this._client.services.services.FunctionRegistryService",
@@ -320,7 +323,7 @@ var DevServer = class {
320
323
  registrationId: this._functionServiceRegistration
321
324
  }, {
322
325
  F: __dxlog_file2,
323
- L: 139,
326
+ L: 142,
324
327
  S: this,
325
328
  C: (f, a) => f(...a)
326
329
  });
@@ -337,7 +340,7 @@ var DevServer = class {
337
340
  this._server = void 0;
338
341
  import_log2.log.info("stopped", void 0, {
339
342
  F: __dxlog_file2,
340
- L: 153,
343
+ L: 156,
341
344
  S: this,
342
345
  C: (f, a) => f(...a)
343
346
  });
@@ -349,7 +352,7 @@ var DevServer = class {
349
352
  newFunctions
350
353
  }, {
351
354
  F: __dxlog_file2,
352
- L: 159,
355
+ L: 162,
353
356
  S: this,
354
357
  C: (f, a) => f(...a)
355
358
  });
@@ -365,16 +368,16 @@ var DevServer = class {
365
368
  force
366
369
  }, {
367
370
  F: __dxlog_file2,
368
- L: 168,
371
+ L: 171,
369
372
  S: this,
370
373
  C: (f, a) => f(...a)
371
374
  });
372
375
  if (force) {
373
- Object.keys(import_chunk_BLLSDTKZ.__require.cache).filter((key) => key.startsWith(filePath)).forEach((key) => {
374
- delete import_chunk_BLLSDTKZ.__require.cache[key];
376
+ Object.keys(import_chunk_3E6PY6JH.__require.cache).filter((key) => key.startsWith(filePath)).forEach((key) => {
377
+ delete import_chunk_3E6PY6JH.__require.cache[key];
375
378
  });
376
379
  }
377
- const module2 = (0, import_chunk_BLLSDTKZ.__require)(filePath);
380
+ const module2 = (0, import_chunk_3E6PY6JH.__require)(filePath);
378
381
  if (typeof module2.default !== "function") {
379
382
  throw new Error(`Handler must export default function: ${uri}`);
380
383
  }
@@ -386,7 +389,7 @@ var DevServer = class {
386
389
  async _safeUpdateRegistration() {
387
390
  (0, import_invariant.invariant)(this._functionServiceRegistration, void 0, {
388
391
  F: __dxlog_file2,
389
- L: 190,
392
+ L: 193,
390
393
  S: this,
391
394
  A: [
392
395
  "this._functionServiceRegistration",
@@ -404,7 +407,7 @@ var DevServer = class {
404
407
  } catch (err) {
405
408
  import_log2.log.catch(err, void 0, {
406
409
  F: __dxlog_file2,
407
- L: 197,
410
+ L: 200,
408
411
  S: this,
409
412
  C: (f, a) => f(...a)
410
413
  });
@@ -421,7 +424,7 @@ var DevServer = class {
421
424
  path: path2
422
425
  }, {
423
426
  F: __dxlog_file2,
424
- L: 208,
427
+ L: 211,
425
428
  S: this,
426
429
  C: (f, a) => f(...a)
427
430
  });
@@ -435,7 +438,7 @@ var DevServer = class {
435
438
  duration: Date.now() - now
436
439
  }, {
437
440
  F: __dxlog_file2,
438
- L: 211,
441
+ L: 214,
439
442
  S: this,
440
443
  C: (f, a) => f(...a)
441
444
  });
@@ -446,7 +449,7 @@ var DevServer = class {
446
449
  const { handler } = this._handlers[path2] ?? {};
447
450
  (0, import_invariant.invariant)(handler, `invalid path: ${path2}`, {
448
451
  F: __dxlog_file2,
449
- L: 218,
452
+ L: 221,
450
453
  S: this,
451
454
  A: [
452
455
  "handler",
@@ -501,7 +504,7 @@ var Scheduler = class {
501
504
  await this.functions.close();
502
505
  await this.triggers.close();
503
506
  }
504
- // TODO(burdon): Remove and update registries directly.
507
+ // TODO(burdon): Remove and update registries directly?
505
508
  async register(space, manifest) {
506
509
  await this.functions.register(space, manifest.functions);
507
510
  await this.triggers.register(space, manifest);
@@ -512,6 +515,9 @@ var Scheduler = class {
512
515
  });
513
516
  await Promise.all(mountTasks).catch(import_log3.log.catch);
514
517
  }
518
+ /**
519
+ * Activate trigger.
520
+ */
515
521
  async activate(space, functions, trigger) {
516
522
  const definition = functions.find((def) => def.uri === trigger.function);
517
523
  if (!definition) {
@@ -519,7 +525,7 @@ var Scheduler = class {
519
525
  trigger
520
526
  }, {
521
527
  F: __dxlog_file3,
522
- L: 78,
528
+ L: 83,
523
529
  S: this,
524
530
  C: (f, a) => f(...a)
525
531
  });
@@ -532,21 +538,33 @@ var Scheduler = class {
532
538
  uri: definition.uri
533
539
  }, {
534
540
  F: __dxlog_file3,
535
- L: 86,
541
+ L: 91,
536
542
  S: this,
537
543
  C: (f, a) => f(...a)
538
544
  });
539
- return mutex.executeSynchronized(() => {
545
+ return mutex.executeSynchronized(async () => {
540
546
  import_log3.log.info("mutex acquired", {
541
547
  uri: definition.uri
542
548
  }, {
543
549
  F: __dxlog_file3,
544
- L: 88,
550
+ L: 93,
545
551
  S: this,
546
552
  C: (f, a) => f(...a)
547
553
  });
554
+ await (0, import_echo2.loadObjectReferences)(trigger, (t) => Object.values(t.meta ?? {}));
555
+ const meta = {};
556
+ for (const [key, value] of Object.entries(trigger.meta ?? {})) {
557
+ if (value instanceof import_echo_protocol.Reference) {
558
+ const object = await space.db.loadObjectById(value.objectId);
559
+ if (object) {
560
+ meta[key] = object;
561
+ }
562
+ } else {
563
+ meta[key] = value;
564
+ }
565
+ }
548
566
  return this._execFunction(definition, trigger, {
549
- meta: trigger.meta ?? {},
567
+ meta,
550
568
  data: {
551
569
  ...args,
552
570
  spaceKey: space.key
@@ -559,12 +577,15 @@ var Scheduler = class {
559
577
  trigger
560
578
  }, {
561
579
  F: __dxlog_file3,
562
- L: 96,
580
+ L: 116,
563
581
  S: this,
564
582
  C: (f, a) => f(...a)
565
583
  });
566
584
  }
567
- async _execFunction(def, trigger, { data, meta }) {
585
+ /**
586
+ * Invoke function RPC.
587
+ */
588
+ async _execFunction(def, trigger, { meta, data }) {
568
589
  let status = 0;
569
590
  try {
570
591
  const payload = Object.assign({}, meta && {
@@ -579,7 +600,7 @@ var Scheduler = class {
579
600
  triggerType: trigger.spec.type
580
601
  }, {
581
602
  F: __dxlog_file3,
582
- L: 113,
603
+ L: 136,
583
604
  S: this,
584
605
  C: (f, a) => f(...a)
585
606
  });
@@ -596,7 +617,7 @@ var Scheduler = class {
596
617
  function: def.uri
597
618
  }, {
598
619
  F: __dxlog_file3,
599
- L: 124,
620
+ L: 147,
600
621
  S: this,
601
622
  C: (f, a) => f(...a)
602
623
  });
@@ -610,7 +631,7 @@ var Scheduler = class {
610
631
  status
611
632
  }, {
612
633
  F: __dxlog_file3,
613
- L: 134,
634
+ L: 157,
614
635
  S: this,
615
636
  C: (f, a) => f(...a)
616
637
  });
@@ -620,7 +641,7 @@ var Scheduler = class {
620
641
  error: err.message
621
642
  }, {
622
643
  F: __dxlog_file3,
623
- L: 136,
644
+ L: 159,
624
645
  S: this,
625
646
  C: (f, a) => f(...a)
626
647
  });
@@ -683,7 +704,7 @@ var createSubscriptionTrigger = async (ctx, space, spec, callback) => {
683
704
  if (deep) {
684
705
  for (const object of objects) {
685
706
  const content = object.content;
686
- if (content instanceof import_types.TextV0Type) {
707
+ if (content instanceof import_types.TextType) {
687
708
  subscriptions.push((0, import_echo_db.getObjectCore)(content).updates.on((0, import_async5.debounce)(() => subscription.update([
688
709
  object
689
710
  ]), 1e3)));
@@ -700,7 +721,7 @@ var createSubscriptionTrigger = async (ctx, space, spec, callback) => {
700
721
  C: (f, a) => f(...a)
701
722
  });
702
723
  if (filter) {
703
- const query = space.db.query(import_echo3.Filter.typename(filter[0].type, filter[0].props));
724
+ const query = space.db.query(import_echo4.Filter.typename(filter[0].type, filter[0].props));
704
725
  subscriptions.push(query.subscribe(delay ? (0, import_async5.debounce)(update, delay) : update));
705
726
  }
706
727
  ctx.onDispose(() => {
@@ -947,9 +968,9 @@ var TriggerRegistry = class extends import_context4.Resource {
947
968
  if (!manifest.triggers?.length) {
948
969
  return;
949
970
  }
950
- if (!space.db.graph.schemaRegistry.hasSchema(import_chunk_BLLSDTKZ.FunctionTrigger)) {
971
+ if (!space.db.graph.schemaRegistry.hasSchema(import_chunk_3E6PY6JH.FunctionTrigger)) {
951
972
  space.db.graph.schemaRegistry.addSchema([
952
- import_chunk_BLLSDTKZ.FunctionTrigger
973
+ import_chunk_3E6PY6JH.FunctionTrigger
953
974
  ]);
954
975
  }
955
976
  const manifestTriggers = manifest.triggers.map((trigger) => {
@@ -963,16 +984,16 @@ var TriggerRegistry = class extends import_context4.Resource {
963
984
  ].join(":"))
964
985
  ];
965
986
  }
966
- return (0, import_echo2.create)(import_chunk_BLLSDTKZ.FunctionTrigger, trigger, {
987
+ return (0, import_echo3.create)(import_chunk_3E6PY6JH.FunctionTrigger, trigger, {
967
988
  keys
968
989
  });
969
990
  });
970
- const { objects: existing } = await space.db.query(import_echo2.Filter.schema(import_chunk_BLLSDTKZ.FunctionTrigger)).run();
991
+ const { objects: existing } = await space.db.query(import_echo3.Filter.schema(import_chunk_3E6PY6JH.FunctionTrigger)).run();
971
992
  const { added } = (0, import_util2.diff)(existing, manifestTriggers, import_echo_schema.compareForeignKeys);
972
993
  added.forEach((trigger) => {
973
994
  space.db.add(trigger);
974
995
  import_log4.log.info("added", {
975
- meta: (0, import_echo2.getMeta)(trigger)
996
+ meta: (0, import_echo3.getMeta)(trigger)
976
997
  }, {
977
998
  F: __dxlog_file8,
978
999
  L: 120,
@@ -1002,7 +1023,7 @@ var TriggerRegistry = class extends import_context4.Resource {
1002
1023
  if (this._ctx.disposed) {
1003
1024
  break;
1004
1025
  }
1005
- this._ctx.onDispose(space.db.query(import_echo2.Filter.schema(import_chunk_BLLSDTKZ.FunctionTrigger)).subscribe(async ({ objects: current }) => {
1026
+ this._ctx.onDispose(space.db.query(import_echo3.Filter.schema(import_chunk_3E6PY6JH.FunctionTrigger)).subscribe(async ({ objects: current }) => {
1006
1027
  import_log4.log.info("update", {
1007
1028
  space: space.key,
1008
1029
  registered: registered.length,
@@ -1103,4 +1124,4 @@ var TriggerRegistry = class extends import_context4.Resource {
1103
1124
  Scheduler,
1104
1125
  TriggerRegistry
1105
1126
  });
1106
- //# sourceMappingURL=chunk-BW7KSYIH.cjs.map
1127
+ //# sourceMappingURL=chunk-H5Q2TXOA.cjs.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/function/function-registry.ts", "../../../src/runtime/dev-server.ts", "../../../src/runtime/scheduler.ts", "../../../src/trigger/trigger-registry.ts", "../../../src/trigger/type/subscription-trigger.ts", "../../../src/trigger/type/timer-trigger.ts", "../../../src/trigger/type/webhook-trigger.ts", "../../../src/trigger/type/websocket-trigger.ts"],
4
+ "sourcesContent": ["//\n// Copyright 2024 DXOS.org\n//\n\nimport { Event } from '@dxos/async';\nimport { type Client } from '@dxos/client';\nimport { create, Filter, type Space } from '@dxos/client/echo';\nimport { type Context, Resource } from '@dxos/context';\nimport { PublicKey } from '@dxos/keys';\nimport { log } from '@dxos/log';\nimport { ComplexMap, diff } from '@dxos/util';\n\nimport { FunctionDef, type FunctionManifest } from '../types';\n\nexport type FunctionsRegisteredEvent = {\n space: Space;\n added: FunctionDef[];\n};\n\nexport class FunctionRegistry extends Resource {\n private readonly _functionBySpaceKey = new ComplexMap<PublicKey, FunctionDef[]>(PublicKey.hash);\n\n public readonly registered = new Event<FunctionsRegisteredEvent>();\n\n constructor(private readonly _client: Client) {\n super();\n }\n\n public getFunctions(space: Space): FunctionDef[] {\n return this._functionBySpaceKey.get(space.key) ?? [];\n }\n\n public getUniqueByUri(): FunctionDef[] {\n const uniqueByUri = [...this._functionBySpaceKey.values()]\n .flatMap((defs) => defs)\n .reduce((acc, v) => {\n acc.set(v.uri, v);\n return acc;\n }, new Map<string, FunctionDef>());\n return [...uniqueByUri.values()];\n }\n\n /**\n * Loads function definitions from the manifest into the space.\n * We first load all the definitions from the space to deduplicate by functionId.\n */\n public async register(space: Space, functions: FunctionManifest['functions']): Promise<void> {\n log('register', { space: space.key, functions: functions?.length ?? 0 });\n if (!functions?.length) {\n return;\n }\n if (!space.db.graph.schemaRegistry.hasSchema(FunctionDef)) {\n space.db.graph.schemaRegistry.addSchema([FunctionDef]);\n }\n\n // Sync definitions.\n const { objects: existing } = await space.db.query(Filter.schema(FunctionDef)).run();\n const { added } = diff(existing, functions, (a, b) => a.uri === b.uri);\n // TODO(burdon): Update existing templates.\n added.forEach((def) => space.db.add(create(FunctionDef, def)));\n }\n\n protected override async _open(): Promise<void> {\n log.info('opening...');\n const spacesSubscription = this._client.spaces.subscribe(async (spaces) => {\n for (const space of spaces) {\n if (this._functionBySpaceKey.has(space.key)) {\n continue;\n }\n\n const registered: FunctionDef[] = [];\n this._functionBySpaceKey.set(space.key, registered);\n await space.waitUntilReady();\n if (this._ctx.disposed) {\n break;\n }\n\n // Subscribe to updates.\n this._ctx.onDispose(\n space.db.query(Filter.schema(FunctionDef)).subscribe(({ objects }) => {\n const { added } = diff(registered, objects, (a, b) => a.uri === b.uri);\n // TODO(burdon): Update and remove.\n if (added.length > 0) {\n registered.push(...added);\n this.registered.emit({ space, added });\n }\n }),\n );\n }\n });\n\n // TODO(burdon): API: Normalize unsubscribe methods.\n this._ctx.onDispose(() => spacesSubscription.unsubscribe());\n }\n\n protected override async _close(_: Context): Promise<void> {\n log.info('closing...');\n this._functionBySpaceKey.clear();\n }\n}\n", "//\n// Copyright 2023 DXOS.org\n//\n\nimport express from 'express';\nimport { getPort } from 'get-port-please';\nimport type http from 'http';\nimport { join } from 'node:path';\n\nimport { asyncTimeout, Event, Trigger } from '@dxos/async';\nimport { type Client } from '@dxos/client';\nimport { Context } from '@dxos/context';\nimport { invariant } from '@dxos/invariant';\nimport { log } from '@dxos/log';\n\nimport { type FunctionRegistry } from '../function';\nimport { type FunctionContext, type FunctionEvent, type FunctionHandler, type FunctionResponse } from '../handler';\nimport { type FunctionDef } from '../types';\n\nconst FN_TIMEOUT = 20_000;\n\nexport type DevServerOptions = {\n baseDir: string;\n port?: number;\n reload?: boolean;\n dataDir?: string;\n};\n\n/**\n * Functions dev server provides a local HTTP server for loading and invoking functions.\n * Functions are executed in the context of an authenticated client.\n */\nexport class DevServer {\n private _ctx = createContext();\n\n // Function handlers indexed by name (URL path).\n private readonly _handlers: Record<string, { def: FunctionDef; handler: FunctionHandler<any> }> = {};\n\n private _server?: http.Server;\n private _port?: number;\n private _functionServiceRegistration?: string;\n private _proxy?: string;\n private _seq = 0;\n\n public readonly update = new Event<number>();\n\n constructor(\n private readonly _client: Client,\n private readonly _functionsRegistry: FunctionRegistry,\n private readonly _options: DevServerOptions,\n ) {}\n\n get stats() {\n return {\n seq: this._seq,\n };\n }\n\n get endpoint() {\n invariant(this._port);\n return `http://localhost:${this._port}`;\n }\n\n get proxy() {\n return this._proxy;\n }\n\n get functions() {\n return Object.values(this._handlers);\n }\n\n async start() {\n invariant(!this._server);\n log.info('starting...');\n this._ctx = createContext();\n\n // TODO(burdon): Change to hono.\n const app = express();\n app.use(express.json());\n\n app.post('/:path', async (req, res) => {\n const { path } = req.params;\n try {\n log.info('calling', { path });\n if (this._options.reload) {\n const { def } = this._handlers['/' + path];\n await this._load(def, true);\n }\n\n // TODO(burdon): Get function context.\n res.statusCode = await asyncTimeout(this.invoke('/' + path, req.body), FN_TIMEOUT);\n res.end();\n } catch (err: any) {\n log.catch(err);\n res.statusCode = 500;\n res.end();\n }\n });\n\n this._port = this._options.port ?? (await getPort({ host: 'localhost', port: 7200, portRange: [7200, 7299] }));\n this._server = app.listen(this._port);\n\n try {\n // Register functions.\n const { registrationId, endpoint } = await this._client.services.services.FunctionRegistryService!.register({\n endpoint: this.endpoint,\n });\n\n log.info('registered', { endpoint });\n this._proxy = endpoint;\n this._functionServiceRegistration = registrationId;\n\n // Open after registration, so that it can be updated with the list of function definitions.\n await this._handleNewFunctions(this._functionsRegistry.getUniqueByUri());\n this._ctx.onDispose(this._functionsRegistry.registered.on(({ added }) => this._handleNewFunctions(added)));\n } catch (err: any) {\n await this.stop();\n throw new Error('FunctionRegistryService not available (check plugin is configured).');\n }\n\n log.info('started', { port: this._port });\n }\n\n async stop() {\n if (!this._server) {\n return;\n }\n\n log.info('stopping...');\n await this._ctx.dispose();\n\n const trigger = new Trigger();\n this._server.close(async () => {\n log.info('server stopped');\n try {\n if (this._functionServiceRegistration) {\n invariant(this._client.services.services.FunctionRegistryService);\n await this._client.services.services.FunctionRegistryService.unregister({\n registrationId: this._functionServiceRegistration,\n });\n\n log.info('unregistered', { registrationId: this._functionServiceRegistration });\n this._functionServiceRegistration = undefined;\n this._proxy = undefined;\n }\n\n trigger.wake();\n } catch (err) {\n trigger.throw(err as Error);\n }\n });\n\n await trigger.wait();\n this._port = undefined;\n this._server = undefined;\n log.info('stopped');\n }\n\n private async _handleNewFunctions(newFunctions: FunctionDef[]) {\n newFunctions.forEach((def) => this._load(def));\n await this._safeUpdateRegistration();\n log('new functions loaded', { newFunctions });\n }\n\n /**\n * Load function.\n */\n private async _load(def: FunctionDef, force?: boolean | undefined) {\n const { uri, route, handler } = def;\n const filePath = join(this._options.baseDir, handler);\n log.info('loading', { uri, force });\n\n // Remove from cache.\n if (force) {\n Object.keys(require.cache)\n .filter((key) => key.startsWith(filePath))\n .forEach((key) => {\n delete require.cache[key];\n });\n }\n\n // TODO(burdon): Import types.\n // eslint-disable-next-line @typescript-eslint/no-var-requires\n const module = require(filePath);\n if (typeof module.default !== 'function') {\n throw new Error(`Handler must export default function: ${uri}`);\n }\n\n this._handlers[route] = { def, handler: module.default };\n }\n\n private async _safeUpdateRegistration(): Promise<void> {\n invariant(this._functionServiceRegistration);\n try {\n await this._client.services.services.FunctionRegistryService!.updateRegistration({\n registrationId: this._functionServiceRegistration,\n functions: this.functions.map(({ def: { id, route } }) => ({ id, route })),\n });\n } catch (err) {\n log.catch(err);\n }\n }\n\n /**\n * Invoke function.\n */\n public async invoke(path: string, data: any): Promise<number> {\n const seq = ++this._seq;\n const now = Date.now();\n\n log.info('req', { seq, path });\n const statusCode = await this._invoke(path, { data });\n\n log.info('res', { seq, path, statusCode, duration: Date.now() - now });\n this.update.emit(statusCode);\n return statusCode;\n }\n\n private async _invoke(path: string, event: FunctionEvent) {\n const { handler } = this._handlers[path] ?? {};\n invariant(handler, `invalid path: ${path}`);\n const context: FunctionContext = {\n client: this._client,\n dataDir: this._options.dataDir,\n };\n\n let statusCode = 200;\n const response: FunctionResponse = {\n status: (code: number) => {\n statusCode = code;\n return response;\n },\n };\n\n await handler({ context, event, response });\n return statusCode;\n }\n}\n\nconst createContext = () => new Context({ name: 'DevServer' });\n", "//\n// Copyright 2023 DXOS.org\n//\n\nimport path from 'node:path';\n\nimport { Mutex } from '@dxos/async';\nimport { loadObjectReferences, type Space } from '@dxos/client/echo';\nimport { Context } from '@dxos/context';\nimport { Reference } from '@dxos/echo-protocol';\nimport { log } from '@dxos/log';\n\nimport { type FunctionRegistry } from '../function';\nimport { type FunctionEventMeta } from '../handler';\nimport { type TriggerRegistry } from '../trigger';\nimport { type FunctionDef, type FunctionManifest, type FunctionTrigger } from '../types';\n\nexport type Callback = (data: any) => Promise<void | number>;\n\nexport type SchedulerOptions = {\n endpoint?: string;\n callback?: Callback;\n};\n\n/**\n * The scheduler triggers function execution based on various trigger configurations.\n * Functions are scheduled within the context of a specific space.\n */\nexport class Scheduler {\n private _ctx = createContext();\n\n private readonly _functionUriToCallMutex = new Map<string, Mutex>();\n\n constructor(\n public readonly functions: FunctionRegistry,\n public readonly triggers: TriggerRegistry,\n private readonly _options: SchedulerOptions = {},\n ) {\n this.functions.registered.on(async ({ space, added }) => {\n await this._safeActivateTriggers(space, this.triggers.getInactiveTriggers(space), added);\n });\n this.triggers.registered.on(async ({ space, triggers }) => {\n await this._safeActivateTriggers(space, triggers, this.functions.getFunctions(space));\n });\n }\n\n async start() {\n await this._ctx.dispose();\n this._ctx = createContext();\n await this.functions.open(this._ctx);\n await this.triggers.open(this._ctx);\n }\n\n async stop() {\n await this._ctx.dispose();\n await this.functions.close();\n await this.triggers.close();\n }\n\n // TODO(burdon): Remove and update registries directly?\n public async register(space: Space, manifest: FunctionManifest) {\n await this.functions.register(space, manifest.functions);\n await this.triggers.register(space, manifest);\n }\n\n private async _safeActivateTriggers(\n space: Space,\n triggers: FunctionTrigger[],\n functions: FunctionDef[],\n ): Promise<void> {\n const mountTasks = triggers.map((trigger) => {\n return this.activate(space, functions, trigger);\n });\n await Promise.all(mountTasks).catch(log.catch);\n }\n\n /**\n * Activate trigger.\n */\n private async activate(space: Space, functions: FunctionDef[], trigger: FunctionTrigger) {\n const definition = functions.find((def) => def.uri === trigger.function);\n if (!definition) {\n log.info('function is not found for trigger', { trigger });\n return;\n }\n\n await this.triggers.activate(space, trigger, async (args) => {\n const mutex = this._functionUriToCallMutex.get(definition.uri) ?? new Mutex();\n this._functionUriToCallMutex.set(definition.uri, mutex);\n\n log.info('function triggered, waiting for mutex', { uri: definition.uri });\n return mutex.executeSynchronized(async () => {\n log.info('mutex acquired', { uri: definition.uri });\n\n // Load potential references in meta properties to serialize.\n await loadObjectReferences(trigger, (t) => Object.values(t.meta ?? {}));\n const meta: FunctionTrigger['meta'] = {};\n for (const [key, value] of Object.entries(trigger.meta ?? {})) {\n if (value instanceof Reference) {\n const object = await space.db.loadObjectById(value.objectId);\n if (object) {\n meta[key] = object;\n }\n } else {\n meta[key] = value;\n }\n }\n\n return this._execFunction(definition, trigger, {\n meta,\n data: { ...args, spaceKey: space.key },\n });\n });\n });\n\n log('activated trigger', { space: space.key, trigger });\n }\n\n /**\n * Invoke function RPC.\n */\n private async _execFunction<TData, TMeta>(\n def: FunctionDef,\n trigger: FunctionTrigger,\n { meta, data }: { meta?: TMeta; data: TData },\n ): Promise<number> {\n let status = 0;\n try {\n // TODO(burdon): Pass in Space key (common context)?\n const payload = Object.assign({}, meta && ({ meta } satisfies FunctionEventMeta<TMeta>), data);\n\n const { endpoint, callback } = this._options;\n if (endpoint) {\n // TODO(burdon): Move out of scheduler (generalize as callback).\n const url = path.join(endpoint, def.route);\n log.info('exec', { function: def.uri, url, triggerType: trigger.spec.type });\n const response = await fetch(url, {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n },\n body: JSON.stringify(payload),\n });\n\n status = response.status;\n } else if (callback) {\n log.info('exec', { function: def.uri });\n status = (await callback(payload)) ?? 200;\n }\n\n // Check errors.\n if (status && status >= 400) {\n throw new Error(`Response: ${status}`);\n }\n\n // const result = await response.json();\n log.info('done', { function: def.uri, status });\n } catch (err: any) {\n log.error('error', { function: def.uri, error: err.message });\n status = 500;\n }\n\n return status;\n }\n}\n\nconst createContext = () => new Context({ name: 'FunctionScheduler' });\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport { Event } from '@dxos/async';\nimport { type Client } from '@dxos/client';\nimport { create, Filter, getMeta, type Space } from '@dxos/client/echo';\nimport { Context, Resource } from '@dxos/context';\nimport { compareForeignKeys, ECHO_ATTR_META, foreignKey } from '@dxos/echo-schema';\nimport { invariant } from '@dxos/invariant';\nimport { PublicKey } from '@dxos/keys';\nimport { log } from '@dxos/log';\nimport { ComplexMap, diff } from '@dxos/util';\n\nimport { createSubscriptionTrigger, createTimerTrigger, createWebhookTrigger, createWebsocketTrigger } from './type';\nimport { type FunctionManifest, FunctionTrigger, type FunctionTriggerType, type TriggerSpec } from '../types';\n\ntype ResponseCode = number;\n\nexport type TriggerCallback = (args: object) => Promise<ResponseCode>;\n\n// TODO(burdon): Make object?\nexport type TriggerFactory<Spec extends TriggerSpec, Options = any> = (\n ctx: Context,\n space: Space,\n spec: Spec,\n callback: TriggerCallback,\n options?: Options,\n) => Promise<void>;\n\nexport type TriggerHandlerMap = { [type in FunctionTriggerType]: TriggerFactory<any> };\n\nconst triggerHandlers: TriggerHandlerMap = {\n subscription: createSubscriptionTrigger,\n timer: createTimerTrigger,\n webhook: createWebhookTrigger,\n websocket: createWebsocketTrigger,\n};\n\nexport type TriggerEvent = {\n space: Space;\n triggers: FunctionTrigger[];\n};\n\ntype RegisteredTrigger = {\n activationCtx?: Context;\n trigger: FunctionTrigger;\n};\n\nexport class TriggerRegistry extends Resource {\n private readonly _triggersBySpaceKey = new ComplexMap<PublicKey, RegisteredTrigger[]>(PublicKey.hash);\n\n public readonly registered = new Event<TriggerEvent>();\n public readonly removed = new Event<TriggerEvent>();\n\n constructor(\n private readonly _client: Client,\n private readonly _options?: TriggerHandlerMap,\n ) {\n super();\n }\n\n public getActiveTriggers(space: Space): FunctionTrigger[] {\n return this._getTriggers(space, (t) => t.activationCtx != null);\n }\n\n public getInactiveTriggers(space: Space): FunctionTrigger[] {\n return this._getTriggers(space, (t) => t.activationCtx == null);\n }\n\n async activate(space: Space, trigger: FunctionTrigger, callback: TriggerCallback): Promise<void> {\n log('activate', { space: space.key, trigger });\n\n const activationCtx = new Context({ name: `FunctionTrigger-${trigger.function}` });\n this._ctx.onDispose(() => activationCtx.dispose());\n const registeredTrigger = this._triggersBySpaceKey.get(space.key)?.find((reg) => reg.trigger.id === trigger.id);\n invariant(registeredTrigger, `Trigger is not registered: ${trigger.function}`);\n registeredTrigger.activationCtx = activationCtx;\n\n try {\n const options = this._options?.[trigger.spec.type];\n await triggerHandlers[trigger.spec.type](activationCtx, space, trigger.spec, callback, options);\n } catch (err) {\n delete registeredTrigger.activationCtx;\n throw err;\n }\n }\n\n /**\n * Loads triggers from the manifest into the space.\n */\n public async register(space: Space, manifest: FunctionManifest): Promise<void> {\n log('register', { space: space.key });\n if (!manifest.triggers?.length) {\n return;\n }\n\n if (!space.db.graph.schemaRegistry.hasSchema(FunctionTrigger)) {\n space.db.graph.schemaRegistry.addSchema([FunctionTrigger]);\n }\n\n // Create FK to enable syncing if none are set (NOTE: Possible collision).\n const manifestTriggers = manifest.triggers.map((trigger) => {\n let keys = trigger[ECHO_ATTR_META]?.keys;\n delete trigger[ECHO_ATTR_META];\n if (!keys?.length) {\n keys = [foreignKey('manifest', [trigger.function, trigger.spec.type].join(':'))];\n }\n\n return create(FunctionTrigger, trigger, { keys });\n });\n\n // Sync triggers.\n const { objects: existing } = await space.db.query(Filter.schema(FunctionTrigger)).run();\n const { added } = diff(existing, manifestTriggers, compareForeignKeys);\n\n // TODO(burdon): Update existing.\n added.forEach((trigger) => {\n space.db.add(trigger);\n log.info('added', { meta: getMeta(trigger) });\n });\n\n if (added.length > 0) {\n await space.db.flush();\n }\n }\n\n protected override async _open(): Promise<void> {\n log.info('open...');\n const spaceListSubscription = this._client.spaces.subscribe(async (spaces) => {\n for (const space of spaces) {\n if (this._triggersBySpaceKey.has(space.key)) {\n continue;\n }\n\n const registered: RegisteredTrigger[] = [];\n this._triggersBySpaceKey.set(space.key, registered);\n await space.waitUntilReady();\n if (this._ctx.disposed) {\n break;\n }\n\n // Subscribe to updates.\n this._ctx.onDispose(\n space.db.query(Filter.schema(FunctionTrigger)).subscribe(async ({ objects: current }) => {\n log.info('update', { space: space.key, registered: registered.length, current: current.length });\n await this._handleRemovedTriggers(space, current, registered);\n this._handleNewTriggers(space, current, registered);\n }),\n );\n }\n });\n\n this._ctx.onDispose(() => spaceListSubscription.unsubscribe());\n log.info('opened');\n }\n\n protected override async _close(_: Context): Promise<void> {\n log.info('close...');\n this._triggersBySpaceKey.clear();\n log.info('closed');\n }\n\n private _handleNewTriggers(space: Space, current: FunctionTrigger[], registered: RegisteredTrigger[]) {\n const added = current.filter((candidate) => {\n return candidate.enabled && registered.find((reg) => reg.trigger.id === candidate.id) == null;\n });\n\n if (added.length > 0) {\n const newRegisteredTriggers: RegisteredTrigger[] = added.map((trigger) => ({ trigger }));\n registered.push(...newRegisteredTriggers);\n log.info('added', () => ({\n spaceKey: space.key,\n triggers: added.map((trigger) => trigger.function),\n }));\n\n this.registered.emit({ space, triggers: added });\n }\n }\n\n private async _handleRemovedTriggers(\n space: Space,\n current: FunctionTrigger[],\n registered: RegisteredTrigger[],\n ): Promise<void> {\n const removed: FunctionTrigger[] = [];\n for (let i = registered.length - 1; i >= 0; i--) {\n const wasRemoved =\n current.filter((trigger) => trigger.enabled).find((trigger) => trigger.id === registered[i].trigger.id) == null;\n if (wasRemoved) {\n const unregistered = registered.splice(i, 1)[0];\n await unregistered.activationCtx?.dispose();\n removed.push(unregistered.trigger);\n }\n }\n\n if (removed.length > 0) {\n log.info('removed', () => ({\n spaceKey: space.key,\n triggers: removed.map((trigger) => trigger.function),\n }));\n\n this.removed.emit({ space, triggers: removed });\n }\n }\n\n private _getTriggers(space: Space, predicate: (trigger: RegisteredTrigger) => boolean): FunctionTrigger[] {\n const allSpaceTriggers = this._triggersBySpaceKey.get(space.key) ?? [];\n return allSpaceTriggers.filter(predicate).map((trigger) => trigger.trigger);\n }\n}\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport { TextType } from '@braneframe/types';\nimport { debounce, UpdateScheduler } from '@dxos/async';\nimport { Filter, type Space } from '@dxos/client/echo';\nimport { type Context } from '@dxos/context';\nimport { createSubscription, getObjectCore, type Query } from '@dxos/echo-db';\nimport { log } from '@dxos/log';\n\nimport type { SubscriptionTrigger } from '../../types';\nimport { type TriggerCallback, type TriggerFactory } from '../trigger-registry';\n\nexport const createSubscriptionTrigger: TriggerFactory<SubscriptionTrigger> = async (\n ctx: Context,\n space: Space,\n spec: SubscriptionTrigger,\n callback: TriggerCallback,\n) => {\n const objectIds = new Set<string>();\n const task = new UpdateScheduler(\n ctx,\n async () => {\n if (objectIds.size > 0) {\n const objects = Array.from(objectIds);\n objectIds.clear();\n await callback({ objects });\n }\n },\n { maxFrequency: 4 },\n );\n\n // TODO(burdon): Factor out diff.\n // TODO(burdon): Don't fire initially?\n // TODO(burdon): Create queue. Only allow one invocation per trigger at a time?\n const subscriptions: (() => void)[] = [];\n const subscription = createSubscription(({ added, updated }) => {\n const sizeBefore = objectIds.size;\n for (const object of added) {\n objectIds.add(object.id);\n }\n for (const object of updated) {\n objectIds.add(object.id);\n }\n if (objectIds.size > sizeBefore) {\n log.info('updated', { added: added.length, updated: updated.length });\n task.trigger();\n }\n });\n\n subscriptions.push(() => subscription.unsubscribe());\n\n // TODO(burdon): Disable trigger if keeps failing.\n const { filter, options: { deep, delay } = {} } = spec;\n const update = ({ objects }: Query) => {\n log.info('update', { objects: objects.length });\n subscription.update(objects);\n\n // TODO(burdon): Hack to monitor changes to Document's text object.\n if (deep) {\n for (const object of objects) {\n const content = object.content;\n if (content instanceof TextType) {\n subscriptions.push(getObjectCore(content).updates.on(debounce(() => subscription.update([object]), 1_000)));\n }\n }\n }\n };\n\n // TODO(burdon): OR not working.\n // TODO(burdon): [Bug]: all callbacks are fired on the first mutation.\n // TODO(burdon): [Bug]: not updated when document is deleted (either top or hierarchically).\n log.info('subscription', { filter });\n // const query = triggerCtx.space.db.query(Filter.or(filter.map(({ type, props }) => Filter.typename(type, props))));\n if (filter) {\n const query = space.db.query(Filter.typename(filter[0].type, filter[0].props));\n subscriptions.push(query.subscribe(delay ? debounce(update, delay) : update));\n }\n\n ctx.onDispose(() => {\n subscriptions.forEach((unsubscribe) => unsubscribe());\n });\n};\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport { CronJob } from 'cron';\n\nimport { DeferredTask } from '@dxos/async';\nimport { type Space } from '@dxos/client/echo';\nimport { type Context } from '@dxos/context';\nimport { log } from '@dxos/log';\n\nimport type { TimerTrigger } from '../../types';\nimport { type TriggerCallback, type TriggerFactory } from '../trigger-registry';\n\nexport const createTimerTrigger: TriggerFactory<TimerTrigger> = async (\n ctx: Context,\n space: Space,\n spec: TimerTrigger,\n callback: TriggerCallback,\n) => {\n const task = new DeferredTask(ctx, async () => {\n await callback({});\n });\n\n let last = 0;\n let run = 0;\n // https://www.npmjs.com/package/cron#constructor\n const job = CronJob.from({\n cronTime: spec.cron,\n runOnInit: false,\n onTick: () => {\n // TODO(burdon): Check greater than 30s (use cron-parser).\n const now = Date.now();\n const delta = last ? now - last : 0;\n last = now;\n\n run++;\n log.info('tick', { space: space.key.truncate(), count: run, delta });\n task.schedule();\n },\n });\n\n job.start();\n ctx.onDispose(() => job.stop());\n};\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport { getPort } from 'get-port-please';\nimport http from 'node:http';\n\nimport { type Space } from '@dxos/client/echo';\nimport { type Context } from '@dxos/context';\nimport { log } from '@dxos/log';\n\nimport type { WebhookTrigger } from '../../types';\nimport { type TriggerCallback, type TriggerFactory } from '../trigger-registry';\n\nexport const createWebhookTrigger: TriggerFactory<WebhookTrigger> = async (\n ctx: Context,\n space: Space,\n spec: WebhookTrigger,\n callback: TriggerCallback,\n) => {\n // TODO(burdon): Enable POST hook with payload.\n const server = http.createServer(async (req, res) => {\n if (req.method !== spec.method) {\n res.statusCode = 405;\n return res.end();\n }\n res.statusCode = await callback({});\n res.end();\n });\n\n // TODO(burdon): Not used.\n // const DEF_PORT_RANGE = { min: 7500, max: 7599 };\n // const portRange = Object.assign({}, trigger.port, DEF_PORT_RANGE) as WebhookTrigger['port'];\n const port = await getPort({\n random: true,\n // portRange: [portRange!.min, portRange!.max],\n });\n\n // TODO(burdon): Update trigger object with actual port.\n server.listen(port, () => {\n log.info('started webhook', { port });\n spec.port = port;\n });\n\n ctx.onDispose(() => {\n server.close();\n });\n};\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport WebSocket from 'ws';\n\nimport { sleep, Trigger } from '@dxos/async';\nimport { type Space } from '@dxos/client/echo';\nimport { type Context } from '@dxos/context';\nimport { log } from '@dxos/log';\n\nimport { type WebsocketTrigger } from '../../types';\nimport { type TriggerCallback, type TriggerFactory } from '../trigger-registry';\n\ninterface WebsocketTriggerOptions {\n retryDelay: number;\n maxAttempts: number;\n}\n\n/**\n * Websocket.\n * NOTE: The port must be unique, so the same hook cannot be used for multiple spaces.\n */\nexport const createWebsocketTrigger: TriggerFactory<WebsocketTrigger, WebsocketTriggerOptions> = async (\n ctx: Context,\n space: Space,\n spec: WebsocketTrigger,\n callback: TriggerCallback,\n options: WebsocketTriggerOptions = { retryDelay: 2, maxAttempts: 5 },\n) => {\n const { url, init } = spec;\n\n let wasOpen = false;\n let ws: WebSocket;\n for (let attempt = 1; attempt <= options.maxAttempts; attempt++) {\n const open = new Trigger<boolean>();\n\n ws = new WebSocket(url);\n Object.assign(ws, {\n onopen: () => {\n log.info('opened', { url });\n if (spec.init) {\n ws.send(new TextEncoder().encode(JSON.stringify(init)));\n }\n\n open.wake(true);\n },\n\n onclose: (event) => {\n log.info('closed', { url, code: event.code });\n // Reconnect if server closes (e.g., CF restart).\n // https://developer.mozilla.org/en-US/docs/Web/API/CloseEvent/code\n if (event.code === 1006 && wasOpen && !ctx.disposed) {\n setTimeout(async () => {\n log.info(`reconnecting in ${options.retryDelay}s...`, { url });\n await createWebsocketTrigger(ctx, space, spec, callback, options);\n }, options.retryDelay * 1_000);\n }\n open.wake(false);\n },\n\n onerror: (event) => {\n log.catch(event.error, { url });\n open.wake(false);\n },\n\n onmessage: async (event) => {\n try {\n log.info('message');\n const data = JSON.parse(new TextDecoder().decode(event.data as Uint8Array));\n await callback({ data });\n } catch (err) {\n log.catch(err, { url });\n }\n },\n } satisfies Partial<WebSocket>);\n\n const isOpen = await open.wait();\n if (ctx.disposed) {\n break;\n }\n if (isOpen) {\n wasOpen = true;\n break;\n }\n const wait = Math.pow(attempt, 2) * options.retryDelay;\n if (attempt < options.maxAttempts) {\n log.warn(`failed to connect; trying again in ${wait}s`, { attemp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B,CAAA;AACnC,aAASoB,IAAI3R,WAAWoB,SAAS,GAAGuQ,KAAK,GAAGA,KAAK;AAC/C,YAAMC,aACJP,QAAQvJ,OAAO,CAACnB,YAAYA,QAAQ8K,OAAO,EAAE1H,KAAK,CAACpD,YAAYA,QAAQyB,OAAOpI,WAAW2R,CAAAA,EAAGhL,QAAQyB,EAAE,KAAK;AAC7G,UAAIwJ,YAAY;AACd,cAAMC,eAAe7R,WAAW8R,OAAOH,GAAG,CAAA,EAAG,CAAA;AAC7C,cAAME,aAAanB,eAAehK,QAAAA;AAClC6J,gBAAQpN,KAAK0O,aAAalL,OAAO;MACnC;IACF;AAEA,QAAI4J,QAAQnP,SAAS,GAAG;AACtBD,kBAAAA,IAAIuB,KAAK,WAAW,OAAO;QACzBqI,UAAU5K,MAAME;QAChB+I,UAAUmH,QAAQpI,IAAI,CAACxB,YAAYA,QAAQqD,QAAQ;MACrD,IAAA;;;;;;AAEA,WAAKuG,QAAQnN,KAAK;QAAEjD;QAAOiJ,UAAUmH;MAAQ,CAAA;IAC/C;EACF;EAEQE,aAAatQ,OAAc4R,WAAuE;AACxG,UAAMC,mBAAmB,KAAK1B,oBAAoBlQ,IAAID,MAAME,GAAG,KAAK,CAAA;AACpE,WAAO2R,iBAAiBlK,OAAOiK,SAAAA,EAAW5J,IAAI,CAACxB,YAAYA,QAAQA,OAAO;EAC5E;AACF;",
6
+ "names": ["import_async", "import_context", "import_log", "import_node_path", "import_echo", "import_invariant", "import_keys", "import_util", "import_get_port_please", "FunctionRegistry", "Resource", "constructor", "_client", "_functionBySpaceKey", "ComplexMap", "PublicKey", "hash", "registered", "Event", "getFunctions", "space", "get", "key", "getUniqueByUri", "uniqueByUri", "values", "flatMap", "defs", "reduce", "acc", "v", "set", "uri", "Map", "register", "functions", "log", "length", "db", "graph", "schemaRegistry", "hasSchema", "FunctionDef", "addSchema", "objects", "existing", "query", "Filter", "schema", "run", "added", "diff", "a", "b", "forEach", "def", "add", "create", "_open", "info", "spacesSubscription", "spaces", "subscribe", "has", "waitUntilReady", "_ctx", "disposed", "onDispose", "push", "emit", "unsubscribe", "_close", "_", "clear", "FN_TIMEOUT", "DevServer", "_functionsRegistry", "_options", "createContext", "_handlers", "_seq", "update", "stats", "seq", "endpoint", "invariant", "_port", "proxy", "_proxy", "Object", "start", "_server", "app", "express", "use", "json", "post", "req", "res", "path", "params", "reload", "_load", "statusCode", "asyncTimeout", "invoke", "body", "end", "err", "catch", "port", "getPort", "host", "portRange", "listen", "registrationId", "services", "FunctionRegistryService", "_functionServiceRegistration", "_handleNewFunctions", "on", "stop", "Error", "dispose", "trigger", "Trigger", "close", "unregister", "undefined", "wake", "throw", "wait", "newFunctions", "_safeUpdateRegistration", "force", "route", "handler", "filePath", "join", "baseDir", "keys", "require", "cache", "filter", "startsWith", "module", "default", "updateRegistration", "map", "id", "data", "now", "Date", "_invoke", "duration", "event", "context", "client", "dataDir", "response", "status", "code", "Context", "name", "Scheduler", "triggers", "_functionUriToCallMutex", "_safeActivateTriggers", "getInactiveTriggers", "open", "manifest", "mountTasks", "activate", "Promise", "all", "definition", "find", "function", "args", "mutex", "Mutex", "executeSynchronized", "loadObjectReferences", "t", "meta", "value", "entries", "Reference", "object", "loadObjectById", "objectId", "_execFunction", "spaceKey", "payload", "assign", "callback", "url", "triggerType", "spec", "type", "fetch", "method", "headers", "JSON", "stringify", "error", "message", "createSubscriptionTrigger", "ctx", "objectIds", "Set", "task", "UpdateScheduler", "size", "Array", "from", "maxFrequency", "subscriptions", "subscription", "createSubscription", "updated", "sizeBefore", "options", "deep", "delay", "content", "TextType", "getObjectCore", "updates", "debounce", "typename", "props", "createTimerTrigger", "DeferredTask", "last", "job", "CronJob", "cronTime", "cron", "runOnInit", "onTick", "delta", "truncate", "count", "schedule", "createWebhookTrigger", "server", "http", "createServer", "random", "createWebsocketTrigger", "retryDelay", "maxAttempts", "init", "wasOpen", "ws", "attempt", "WebSocket", "onopen", "send", "TextEncoder", "encode", "onclose", "setTimeout", "onerror", "onmessage", "parse", "TextDecoder", "decode", "isOpen", "Math", "pow", "warn", "sleep", "triggerHandlers", "timer", "webhook", "websocket", "TriggerRegistry", "_triggersBySpaceKey", "removed", "getActiveTriggers", "_getTriggers", "activationCtx", "registeredTrigger", "reg", "FunctionTrigger", "manifestTriggers", "ECHO_ATTR_META", "foreignKey", "compareForeignKeys", "getMeta", "flush", "spaceListSubscription", "current", "_handleRemovedTriggers", "_handleNewTriggers", "candidate", "enabled", "newRegisteredTriggers", "i", "wasRemoved", "unregistered", "splice", "predicate", "allSpaceTriggers"]
7
+ }
@@ -18,19 +18,19 @@ var __copyProps = (to, from, except, desc) => {
18
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
19
  var node_exports = {};
20
20
  __export(node_exports, {
21
- DevServer: () => import_chunk_BW7KSYIH.DevServer,
22
- FUNCTION_SCHEMA: () => import_chunk_BLLSDTKZ.FUNCTION_SCHEMA,
23
- FunctionDef: () => import_chunk_BLLSDTKZ.FunctionDef,
24
- FunctionManifestSchema: () => import_chunk_BLLSDTKZ.FunctionManifestSchema,
25
- FunctionRegistry: () => import_chunk_BW7KSYIH.FunctionRegistry,
26
- FunctionTrigger: () => import_chunk_BLLSDTKZ.FunctionTrigger,
27
- Scheduler: () => import_chunk_BW7KSYIH.Scheduler,
28
- TriggerRegistry: () => import_chunk_BW7KSYIH.TriggerRegistry,
21
+ DevServer: () => import_chunk_H5Q2TXOA.DevServer,
22
+ FUNCTION_SCHEMA: () => import_chunk_3E6PY6JH.FUNCTION_SCHEMA,
23
+ FunctionDef: () => import_chunk_3E6PY6JH.FunctionDef,
24
+ FunctionManifestSchema: () => import_chunk_3E6PY6JH.FunctionManifestSchema,
25
+ FunctionRegistry: () => import_chunk_H5Q2TXOA.FunctionRegistry,
26
+ FunctionTrigger: () => import_chunk_3E6PY6JH.FunctionTrigger,
27
+ Scheduler: () => import_chunk_H5Q2TXOA.Scheduler,
28
+ TriggerRegistry: () => import_chunk_H5Q2TXOA.TriggerRegistry,
29
29
  subscriptionHandler: () => subscriptionHandler
30
30
  });
31
31
  module.exports = __toCommonJS(node_exports);
32
- var import_chunk_BW7KSYIH = require("./chunk-BW7KSYIH.cjs");
33
- var import_chunk_BLLSDTKZ = require("./chunk-BLLSDTKZ.cjs");
32
+ var import_chunk_H5Q2TXOA = require("./chunk-H5Q2TXOA.cjs");
33
+ var import_chunk_3E6PY6JH = require("./chunk-3E6PY6JH.cjs");
34
34
  var import_client = require("@dxos/client");
35
35
  var import_log = require("@dxos/log");
36
36
  var import_util = require("@dxos/util");