@dxos/functions 0.5.3-main.79e0565 → 0.5.3-main.7f770b6

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 (36) hide show
  1. package/dist/lib/browser/chunk-P3HPDHNI.mjs +86 -0
  2. package/dist/lib/browser/chunk-P3HPDHNI.mjs.map +7 -0
  3. package/dist/lib/browser/index.mjs +90 -120
  4. package/dist/lib/browser/index.mjs.map +4 -4
  5. package/dist/lib/browser/meta.json +1 -1
  6. package/dist/lib/browser/types.mjs +14 -0
  7. package/dist/lib/browser/types.mjs.map +7 -0
  8. package/dist/lib/node/chunk-KTLM3JNV.cjs +103 -0
  9. package/dist/lib/node/chunk-KTLM3JNV.cjs.map +7 -0
  10. package/dist/lib/node/index.cjs +105 -127
  11. package/dist/lib/node/index.cjs.map +4 -4
  12. package/dist/lib/node/meta.json +1 -1
  13. package/dist/lib/node/types.cjs +35 -0
  14. package/dist/lib/node/types.cjs.map +7 -0
  15. package/dist/types/src/browser/index.d.ts +2 -0
  16. package/dist/types/src/browser/index.d.ts.map +1 -0
  17. package/dist/types/src/function/function-registry.d.ts.map +1 -1
  18. package/dist/types/src/handler.d.ts.map +1 -1
  19. package/dist/types/src/runtime/scheduler.d.ts +1 -1
  20. package/dist/types/src/runtime/scheduler.d.ts.map +1 -1
  21. package/dist/types/src/trigger/trigger-registry.d.ts.map +1 -1
  22. package/dist/types/src/types.d.ts +31 -30
  23. package/dist/types/src/types.d.ts.map +1 -1
  24. package/package.json +30 -16
  25. package/src/browser/index.ts +5 -0
  26. package/src/function/function-registry.ts +5 -5
  27. package/src/runtime/dev-server.ts +1 -1
  28. package/src/runtime/scheduler.ts +7 -2
  29. package/src/trigger/trigger-registry.ts +23 -11
  30. package/src/types.ts +36 -27
  31. package/dist/types/src/util.d.ts +0 -15
  32. package/dist/types/src/util.d.ts.map +0 -1
  33. package/dist/types/src/util.test.d.ts +0 -2
  34. package/dist/types/src/util.test.d.ts.map +0 -1
  35. package/src/util.test.ts +0 -43
  36. package/src/util.ts +0 -48
@@ -0,0 +1,86 @@
1
+ import "@dxos/node-std/globals";
2
+ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
3
+ get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
4
+ }) : x)(function(x) {
5
+ if (typeof require !== "undefined")
6
+ return require.apply(this, arguments);
7
+ throw Error('Dynamic require of "' + x + '" is not supported');
8
+ });
9
+
10
+ // inject-globals:@inject-globals
11
+ import {
12
+ global,
13
+ Buffer as Buffer2,
14
+ process
15
+ } from "@dxos/node-std/inject-globals";
16
+
17
+ // packages/core/functions/src/types.ts
18
+ import { RawObject, S, TypedObject } from "@dxos/echo-schema";
19
+ var SubscriptionTriggerSchema = S.mutable(S.struct({
20
+ type: S.literal("subscription"),
21
+ // TODO(burdon): Define query DSL (from ECHO).
22
+ filter: S.array(S.struct({
23
+ type: S.string,
24
+ props: S.optional(S.record(S.string, S.any))
25
+ })),
26
+ options: S.optional(S.struct({
27
+ // Watch changes to object (not just creation).
28
+ deep: S.optional(S.boolean),
29
+ // Debounce changes (delay in ms).
30
+ delay: S.optional(S.number)
31
+ }))
32
+ }));
33
+ var TimerTriggerSchema = S.mutable(S.struct({
34
+ type: S.literal("timer"),
35
+ cron: S.string
36
+ }));
37
+ var WebhookTriggerSchema = S.mutable(S.struct({
38
+ type: S.literal("webhook"),
39
+ method: S.string,
40
+ // Assigned port.
41
+ port: S.optional(S.number)
42
+ }));
43
+ var WebsocketTriggerSchema = S.mutable(S.struct({
44
+ type: S.literal("websocket"),
45
+ url: S.string,
46
+ init: S.optional(S.record(S.string, S.any))
47
+ }));
48
+ var TriggerSpecSchema = S.union(TimerTriggerSchema, WebhookTriggerSchema, WebsocketTriggerSchema, SubscriptionTriggerSchema);
49
+ var FunctionDef = class extends TypedObject({
50
+ typename: "dxos.org/type/FunctionDef",
51
+ version: "0.1.0"
52
+ })({
53
+ uri: S.string,
54
+ description: S.optional(S.string),
55
+ route: S.string,
56
+ // TODO(burdon): NPM/GitHub/Docker/CF URL?
57
+ handler: S.string
58
+ }) {
59
+ };
60
+ var FunctionTrigger = class extends TypedObject({
61
+ typename: "dxos.org/type/FunctionTrigger",
62
+ version: "0.1.0"
63
+ })({
64
+ function: S.string.pipe(S.description("Function URI.")),
65
+ // Context is merged into the event data passed to the function.
66
+ meta: S.optional(S.object),
67
+ spec: TriggerSpecSchema
68
+ }) {
69
+ };
70
+ var FunctionManifestSchema = S.struct({
71
+ functions: S.optional(S.mutable(S.array(RawObject(FunctionDef)))),
72
+ triggers: S.optional(S.mutable(S.array(RawObject(FunctionTrigger))))
73
+ });
74
+ var FUNCTION_SCHEMA = [
75
+ FunctionDef,
76
+ FunctionTrigger
77
+ ];
78
+
79
+ export {
80
+ __require,
81
+ FunctionDef,
82
+ FunctionTrigger,
83
+ FunctionManifestSchema,
84
+ FUNCTION_SCHEMA
85
+ };
86
+ //# sourceMappingURL=chunk-P3HPDHNI.mjs.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/types.ts"],
4
+ "sourcesContent": ["//\n// Copyright 2023 DXOS.org\n//\n\nimport { RawObject, S, TypedObject } from '@dxos/echo-schema';\n\n/**\n * Type discriminator for TriggerSpec.\n * Every spec has a type field of type FunctionTriggerType that we can use to understand which\n * type we're working with.\n * https://www.typescriptlang.org/docs/handbook/2/narrowing.html#discriminated-unions\n */\nexport type FunctionTriggerType = 'subscription' | 'timer' | 'webhook' | 'websocket';\n\nconst SubscriptionTriggerSchema = S.mutable(\n S.struct({\n type: S.literal('subscription'),\n // TODO(burdon): Define query DSL (from ECHO).\n filter: S.array(\n S.struct({\n type: S.string,\n props: S.optional(S.record(S.string, S.any)),\n }),\n ),\n options: S.optional(\n S.struct({\n // Watch changes to object (not just creation).\n deep: S.optional(S.boolean),\n // Debounce changes (delay in ms).\n delay: S.optional(S.number),\n }),\n ),\n }),\n);\n\nexport type SubscriptionTrigger = S.Schema.Type<typeof SubscriptionTriggerSchema>;\n\nconst TimerTriggerSchema = S.mutable(\n S.struct({\n type: S.literal('timer'),\n cron: S.string,\n }),\n);\n\nexport type TimerTrigger = S.Schema.Type<typeof TimerTriggerSchema>;\n\nconst WebhookTriggerSchema = S.mutable(\n S.struct({\n type: S.literal('webhook'),\n method: S.string,\n // Assigned port.\n port: S.optional(S.number),\n }),\n);\n\nexport type WebhookTrigger = S.Schema.Type<typeof WebhookTriggerSchema>;\n\nconst WebsocketTriggerSchema = S.mutable(\n S.struct({\n type: S.literal('websocket'),\n url: S.string,\n init: S.optional(S.record(S.string, S.any)),\n }),\n);\n\nexport type WebsocketTrigger = S.Schema.Type<typeof WebsocketTriggerSchema>;\n\nconst TriggerSpecSchema = S.union(\n TimerTriggerSchema,\n WebhookTriggerSchema,\n WebsocketTriggerSchema,\n SubscriptionTriggerSchema,\n);\n\nexport type TriggerSpec = TimerTrigger | WebhookTrigger | WebsocketTrigger | SubscriptionTrigger;\n\n/**\n * Function definition.\n */\nexport class FunctionDef extends TypedObject({\n typename: 'dxos.org/type/FunctionDef',\n version: '0.1.0',\n})({\n uri: S.string,\n description: S.optional(S.string),\n route: S.string,\n // TODO(burdon): NPM/GitHub/Docker/CF URL?\n handler: S.string,\n}) {}\n\nexport class FunctionTrigger extends TypedObject({\n typename: 'dxos.org/type/FunctionTrigger',\n version: '0.1.0',\n})({\n function: S.string.pipe(S.description('Function URI.')),\n // Context is merged into the event data passed to the function.\n meta: S.optional(S.object),\n spec: TriggerSpecSchema,\n}) {}\n\n/**\n * Function manifest file.\n */\nexport const FunctionManifestSchema = S.struct({\n functions: S.optional(S.mutable(S.array(RawObject(FunctionDef)))),\n triggers: S.optional(S.mutable(S.array(RawObject(FunctionTrigger)))),\n});\n\nexport type FunctionManifest = S.Schema.Type<typeof FunctionManifestSchema>;\n\n// TODO(burdon): Standards?\nexport const FUNCTION_SCHEMA = [FunctionDef, FunctionTrigger];\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;AAIA,SAASA,WAAWC,GAAGC,mBAAmB;AAU1C,IAAMC,4BAA4BC,EAAEC,QAClCD,EAAEE,OAAO;EACPC,MAAMH,EAAEI,QAAQ,cAAA;;EAEhBC,QAAQL,EAAEM,MACRN,EAAEE,OAAO;IACPC,MAAMH,EAAEO;IACRC,OAAOR,EAAES,SAAST,EAAEU,OAAOV,EAAEO,QAAQP,EAAEW,GAAG,CAAA;EAC5C,CAAA,CAAA;EAEFC,SAASZ,EAAES,SACTT,EAAEE,OAAO;;IAEPW,MAAMb,EAAES,SAAST,EAAEc,OAAO;;IAE1BC,OAAOf,EAAES,SAAST,EAAEgB,MAAM;EAC5B,CAAA,CAAA;AAEJ,CAAA,CAAA;AAKF,IAAMC,qBAAqBjB,EAAEC,QAC3BD,EAAEE,OAAO;EACPC,MAAMH,EAAEI,QAAQ,OAAA;EAChBc,MAAMlB,EAAEO;AACV,CAAA,CAAA;AAKF,IAAMY,uBAAuBnB,EAAEC,QAC7BD,EAAEE,OAAO;EACPC,MAAMH,EAAEI,QAAQ,SAAA;EAChBgB,QAAQpB,EAAEO;;EAEVc,MAAMrB,EAAES,SAAST,EAAEgB,MAAM;AAC3B,CAAA,CAAA;AAKF,IAAMM,yBAAyBtB,EAAEC,QAC/BD,EAAEE,OAAO;EACPC,MAAMH,EAAEI,QAAQ,WAAA;EAChBmB,KAAKvB,EAAEO;EACPiB,MAAMxB,EAAES,SAAST,EAAEU,OAAOV,EAAEO,QAAQP,EAAEW,GAAG,CAAA;AAC3C,CAAA,CAAA;AAKF,IAAMc,oBAAoBzB,EAAE0B,MAC1BT,oBACAE,sBACAG,wBACAvB,yBAAAA;AAQK,IAAM4B,cAAN,cAA0BC,YAAY;EAC3CC,UAAU;EACVC,SAAS;AACX,CAAA,EAAG;EACDC,KAAK/B,EAAEO;EACPyB,aAAahC,EAAES,SAAST,EAAEO,MAAM;EAChC0B,OAAOjC,EAAEO;;EAET2B,SAASlC,EAAEO;AACb,CAAA,EAAA;AAAI;AAEG,IAAM4B,kBAAN,cAA8BP,YAAY;EAC/CC,UAAU;EACVC,SAAS;AACX,CAAA,EAAG;EACDM,UAAUpC,EAAEO,OAAO8B,KAAKrC,EAAEgC,YAAY,eAAA,CAAA;;EAEtCM,MAAMtC,EAAES,SAAST,EAAEuC,MAAM;EACzBC,MAAMf;AACR,CAAA,EAAA;AAAI;AAKG,IAAMgB,yBAAyBzC,EAAEE,OAAO;EAC7CwC,WAAW1C,EAAES,SAAST,EAAEC,QAAQD,EAAEM,MAAMqC,UAAUhB,WAAAA,CAAAA,CAAAA,CAAAA;EAClDiB,UAAU5C,EAAES,SAAST,EAAEC,QAAQD,EAAEM,MAAMqC,UAAUR,eAAAA,CAAAA,CAAAA,CAAAA;AACnD,CAAA;AAKO,IAAMU,kBAAkB;EAAClB;EAAaQ;;",
6
+ "names": ["RawObject", "S", "TypedObject", "SubscriptionTriggerSchema", "S", "mutable", "struct", "type", "literal", "filter", "array", "string", "props", "optional", "record", "any", "options", "deep", "boolean", "delay", "number", "TimerTriggerSchema", "cron", "WebhookTriggerSchema", "method", "port", "WebsocketTriggerSchema", "url", "init", "TriggerSpecSchema", "union", "FunctionDef", "TypedObject", "typename", "version", "uri", "description", "route", "handler", "FunctionTrigger", "function", "pipe", "meta", "object", "spec", "FunctionManifestSchema", "functions", "RawObject", "triggers", "FUNCTION_SCHEMA"]
7
+ }
@@ -1,18 +1,11 @@
1
1
  import "@dxos/node-std/globals";
2
- var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
3
- get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
4
- }) : x)(function(x) {
5
- if (typeof require !== "undefined")
6
- return require.apply(this, arguments);
7
- throw Error('Dynamic require of "' + x + '" is not supported');
8
- });
9
-
10
- // inject-globals:@inject-globals
11
2
  import {
12
- global,
13
- Buffer as Buffer2,
14
- process
15
- } from "@dxos/node-std/inject-globals";
3
+ FUNCTION_SCHEMA,
4
+ FunctionDef,
5
+ FunctionManifestSchema,
6
+ FunctionTrigger,
7
+ __require
8
+ } from "./chunk-P3HPDHNI.mjs";
16
9
 
17
10
  // packages/core/functions/src/function/function-registry.ts
18
11
  import { Event } from "@dxos/async";
@@ -20,90 +13,7 @@ import { create, Filter } from "@dxos/client/echo";
20
13
  import { Resource } from "@dxos/context";
21
14
  import { PublicKey } from "@dxos/keys";
22
15
  import { log } from "@dxos/log";
23
- import { ComplexMap } from "@dxos/util";
24
-
25
- // packages/core/functions/src/types.ts
26
- import { RawObject, S, TypedObject } from "@dxos/echo-schema";
27
- var SubscriptionTriggerSchema = S.struct({
28
- type: S.literal("subscription"),
29
- // TODO(burdon): Define query DSL (from ECHO).
30
- filter: S.array(S.struct({
31
- type: S.string,
32
- props: S.optional(S.record(S.string, S.any))
33
- })),
34
- options: S.optional(S.struct({
35
- // Watch changes to object (not just creation).
36
- deep: S.optional(S.boolean),
37
- // Debounce changes (delay in ms).
38
- delay: S.optional(S.number)
39
- }))
40
- });
41
- var TimerTriggerSchema = S.struct({
42
- type: S.literal("timer"),
43
- cron: S.string
44
- });
45
- var WebhookTriggerSchema = S.mutable(S.struct({
46
- type: S.literal("webhook"),
47
- method: S.string,
48
- // Assigned port.
49
- port: S.optional(S.number)
50
- }));
51
- var WebsocketTriggerSchema = S.struct({
52
- type: S.literal("websocket"),
53
- url: S.string,
54
- init: S.optional(S.record(S.string, S.any))
55
- });
56
- var TriggerSpecSchema = S.union(TimerTriggerSchema, WebhookTriggerSchema, WebsocketTriggerSchema, SubscriptionTriggerSchema);
57
- var FunctionDef = class extends TypedObject({
58
- typename: "dxos.org/type/FunctionDef",
59
- version: "0.1.0"
60
- })({
61
- uri: S.string,
62
- description: S.optional(S.string),
63
- route: S.string,
64
- // TODO(burdon): NPM/GitHub/Docker/CF URL?
65
- handler: S.string
66
- }) {
67
- };
68
- var FunctionTrigger = class extends TypedObject({
69
- typename: "dxos.org/type/FunctionTrigger",
70
- version: "0.1.0"
71
- })({
72
- function: S.string.pipe(S.description("Function URI.")),
73
- // Context is merged into the event data passed to the function.
74
- meta: S.optional(S.object),
75
- spec: TriggerSpecSchema
76
- }) {
77
- };
78
- var FunctionManifestSchema = S.struct({
79
- functions: S.optional(S.mutable(S.array(RawObject(FunctionDef)))),
80
- triggers: S.optional(S.mutable(S.array(RawObject(FunctionTrigger))))
81
- });
82
-
83
- // packages/core/functions/src/util.ts
84
- var diff = (previous, next, comparator) => {
85
- const remaining = [
86
- ...previous
87
- ];
88
- const result = {
89
- added: [],
90
- updated: [],
91
- removed: remaining
92
- };
93
- for (const object of next) {
94
- const index = remaining.findIndex((item) => comparator(item, object));
95
- if (index === -1) {
96
- result.added.push(object);
97
- } else {
98
- result.updated.push(remaining[index]);
99
- remaining.splice(index, 1);
100
- }
101
- }
102
- return result;
103
- };
104
- var intersection = (a, b, comparator) => a.filter((a2) => b.find((b2) => comparator(a2, b2)) !== void 0);
105
-
106
- // packages/core/functions/src/function/function-registry.ts
16
+ import { ComplexMap, diff } from "@dxos/util";
107
17
  var __dxlog_file = "/home/runner/work/dxos/dxos/packages/core/functions/src/function/function-registry.ts";
108
18
  var FunctionRegistry = class extends Resource {
109
19
  constructor(_client) {
@@ -125,7 +35,7 @@ var FunctionRegistry = class extends Resource {
125
35
  functions: functions?.length ?? 0
126
36
  }, {
127
37
  F: __dxlog_file,
128
- L: 39,
38
+ L: 38,
129
39
  S: this,
130
40
  C: (f, a) => f(...a)
131
41
  });
@@ -136,11 +46,16 @@ var FunctionRegistry = class extends Resource {
136
46
  space.db.graph.runtimeSchemaRegistry.registerSchema(FunctionDef);
137
47
  }
138
48
  const { objects: existing } = await space.db.query(Filter.schema(FunctionDef)).run();
139
- const { added, removed } = diff(existing, functions, (a, b) => a.uri === b.uri);
49
+ const { added } = diff(existing, functions, (a, b) => a.uri === b.uri);
140
50
  added.forEach((def) => space.db.add(create(FunctionDef, def)));
141
- removed.forEach((def) => space.db.remove(def));
142
51
  }
143
52
  async _open() {
53
+ log.info("opening...", void 0, {
54
+ F: __dxlog_file,
55
+ L: 54,
56
+ S: this,
57
+ C: (f, a) => f(...a)
58
+ });
144
59
  const spacesSubscription = this._client.spaces.subscribe(async (spaces) => {
145
60
  for (const space of spaces) {
146
61
  if (this._functionBySpaceKey.has(space.key)) {
@@ -167,6 +82,12 @@ var FunctionRegistry = class extends Resource {
167
82
  this._ctx.onDispose(() => spacesSubscription.unsubscribe());
168
83
  }
169
84
  async _close(_) {
85
+ log.info("closing...", void 0, {
86
+ F: __dxlog_file,
87
+ L: 87,
88
+ S: this,
89
+ C: (f, a) => f(...a)
90
+ });
170
91
  this._functionBySpaceKey.clear();
171
92
  }
172
93
  };
@@ -420,7 +341,7 @@ var DevServer = class {
420
341
  /**
421
342
  * Load function.
422
343
  */
423
- async _load(def, force = false) {
344
+ async _load(def, force) {
424
345
  const { uri, route, handler } = def;
425
346
  const filePath = join(this._options.baseDir, handler);
426
347
  log3.info("loading", {
@@ -551,7 +472,7 @@ var Scheduler = class {
551
472
  this.triggers = triggers;
552
473
  this._options = _options;
553
474
  this._ctx = createContext2();
554
- this._callMutex = new Mutex();
475
+ this._functionUriToCallMutex = /* @__PURE__ */ new Map();
555
476
  this.functions.registered.on(async ({ space, added }) => {
556
477
  await this._safeActivateTriggers(space, this.triggers.getInactiveTriggers(space), added);
557
478
  });
@@ -597,7 +518,25 @@ var Scheduler = class {
597
518
  await this.triggers.activate({
598
519
  space
599
520
  }, fnTrigger, async (args) => {
600
- return this._callMutex.executeSynchronized(() => {
521
+ const mutex = this._functionUriToCallMutex.get(definition.uri) ?? new Mutex();
522
+ this._functionUriToCallMutex.set(definition.uri, mutex);
523
+ log4.info("function triggered, waiting for mutex", {
524
+ uri: definition.uri
525
+ }, {
526
+ F: __dxlog_file4,
527
+ L: 86,
528
+ S: this,
529
+ C: (f, a) => f(...a)
530
+ });
531
+ return mutex.executeSynchronized(() => {
532
+ log4.info("mutex acquired", {
533
+ uri: definition.uri
534
+ }, {
535
+ F: __dxlog_file4,
536
+ L: 88,
537
+ S: this,
538
+ C: (f, a) => f(...a)
539
+ });
601
540
  return this._execFunction(definition, fnTrigger, {
602
541
  meta: fnTrigger.meta,
603
542
  data: {
@@ -612,7 +551,7 @@ var Scheduler = class {
612
551
  trigger: fnTrigger
613
552
  }, {
614
553
  F: __dxlog_file4,
615
- L: 91,
554
+ L: 96,
616
555
  S: this,
617
556
  C: (f, a) => f(...a)
618
557
  });
@@ -632,7 +571,7 @@ var Scheduler = class {
632
571
  triggerType: trigger.spec.type
633
572
  }, {
634
573
  F: __dxlog_file4,
635
- L: 108,
574
+ L: 113,
636
575
  S: this,
637
576
  C: (f, a) => f(...a)
638
577
  });
@@ -649,7 +588,7 @@ var Scheduler = class {
649
588
  function: def.uri
650
589
  }, {
651
590
  F: __dxlog_file4,
652
- L: 119,
591
+ L: 124,
653
592
  S: this,
654
593
  C: (f, a) => f(...a)
655
594
  });
@@ -663,7 +602,7 @@ var Scheduler = class {
663
602
  status
664
603
  }, {
665
604
  F: __dxlog_file4,
666
- L: 129,
605
+ L: 134,
667
606
  S: this,
668
607
  C: (f, a) => f(...a)
669
608
  });
@@ -673,7 +612,7 @@ var Scheduler = class {
673
612
  error: err.message
674
613
  }, {
675
614
  F: __dxlog_file4,
676
- L: 131,
615
+ L: 136,
677
616
  S: this,
678
617
  C: (f, a) => f(...a)
679
618
  });
@@ -694,7 +633,7 @@ import { ECHO_ATTR_META, foreignKey, foreignKeyEquals, splitMeta } from "@dxos/e
694
633
  import { invariant as invariant2 } from "@dxos/invariant";
695
634
  import { PublicKey as PublicKey3 } from "@dxos/keys";
696
635
  import { log as log9 } from "@dxos/log";
697
- import { ComplexMap as ComplexMap2 } from "@dxos/util";
636
+ import { ComplexMap as ComplexMap2, diff as diff2, intersection } from "@dxos/util";
698
637
 
699
638
  // packages/core/functions/src/trigger/type/subscription-trigger.ts
700
639
  import { TextV0Type } from "@braneframe/types";
@@ -976,7 +915,7 @@ var TriggerRegistry = class extends Resource2 {
976
915
  trigger
977
916
  }, {
978
917
  F: __dxlog_file9,
979
- L: 75,
918
+ L: 74,
980
919
  S: this,
981
920
  C: (f, a) => f(...a)
982
921
  });
@@ -987,7 +926,7 @@ var TriggerRegistry = class extends Resource2 {
987
926
  const registeredTrigger = this._triggersBySpaceKey.get(triggerCtx.space.key)?.find((reg) => reg.trigger.id === trigger.id);
988
927
  invariant2(registeredTrigger, `Trigger is not registered: ${trigger.function}`, {
989
928
  F: __dxlog_file9,
990
- L: 81,
929
+ L: 80,
991
930
  S: this,
992
931
  A: [
993
932
  "registeredTrigger",
@@ -1011,7 +950,7 @@ var TriggerRegistry = class extends Resource2 {
1011
950
  space: space.key
1012
951
  }, {
1013
952
  F: __dxlog_file9,
1014
- L: 97,
953
+ L: 96,
1015
954
  S: this,
1016
955
  C: (f, a) => f(...a)
1017
956
  });
@@ -1022,7 +961,7 @@ var TriggerRegistry = class extends Resource2 {
1022
961
  space.db.graph.runtimeSchemaRegistry.registerSchema(FunctionTrigger);
1023
962
  }
1024
963
  const { objects: existing } = await space.db.query(Filter3.schema(FunctionTrigger)).run();
1025
- const { added, removed } = diff(existing, manifest.triggers, (a, b) => {
964
+ const { added } = diff2(existing, manifest.triggers, (a, b) => {
1026
965
  const keys = b[ECHO_ATTR_META]?.keys ?? [
1027
966
  foreignKey("manifest", [
1028
967
  b.function,
@@ -1035,9 +974,14 @@ var TriggerRegistry = class extends Resource2 {
1035
974
  const { meta, object } = splitMeta(trigger);
1036
975
  space.db.add(create2(FunctionTrigger, object, meta));
1037
976
  });
1038
- removed.forEach((trigger) => space.db.remove(trigger));
1039
977
  }
1040
978
  async _open() {
979
+ log9.info("open...", void 0, {
980
+ F: __dxlog_file9,
981
+ L: 121,
982
+ S: this,
983
+ C: (f, a) => f(...a)
984
+ });
1041
985
  const spaceListSubscription = this._client.spaces.subscribe(async (spaces) => {
1042
986
  for (const space of spaces) {
1043
987
  if (this._triggersBySpaceKey.has(space.key)) {
@@ -1049,16 +993,30 @@ var TriggerRegistry = class extends Resource2 {
1049
993
  if (this._ctx.disposed) {
1050
994
  break;
1051
995
  }
1052
- const functionsSubscription = space.db.query(Filter3.schema(FunctionTrigger)).subscribe(async (triggers) => {
996
+ this._ctx.onDispose(space.db.query(Filter3.schema(FunctionTrigger)).subscribe(async (triggers) => {
997
+ log9.info("update", {
998
+ space: space.key,
999
+ triggers: triggers.objects.length
1000
+ }, {
1001
+ F: __dxlog_file9,
1002
+ L: 138,
1003
+ S: this,
1004
+ C: (f, a) => f(...a)
1005
+ });
1053
1006
  await this._handleRemovedTriggers(space, triggers.objects, registered);
1054
1007
  this._handleNewTriggers(space, triggers.objects, registered);
1055
- });
1056
- this._ctx.onDispose(functionsSubscription);
1008
+ }));
1057
1009
  }
1058
1010
  });
1059
1011
  this._ctx.onDispose(() => spaceListSubscription.unsubscribe());
1060
1012
  }
1061
1013
  async _close(_) {
1014
+ log9.info("close...", void 0, {
1015
+ F: __dxlog_file9,
1016
+ L: 150,
1017
+ S: this,
1018
+ C: (f, a) => f(...a)
1019
+ });
1062
1020
  this._triggersBySpaceKey.clear();
1063
1021
  }
1064
1022
  _handleNewTriggers(space, allTriggers, registered) {
@@ -1070,12 +1028,12 @@ var TriggerRegistry = class extends Resource2 {
1070
1028
  trigger
1071
1029
  }));
1072
1030
  registered.push(...newRegisteredTriggers);
1073
- log9("registered new triggers", () => ({
1031
+ log9.info("added", () => ({
1074
1032
  spaceKey: space.key,
1075
- functions: newTriggers.map((t) => t.function)
1033
+ triggers: newTriggers.map((trigger) => trigger.function)
1076
1034
  }), {
1077
1035
  F: __dxlog_file9,
1078
- L: 159,
1036
+ L: 162,
1079
1037
  S: this,
1080
1038
  C: (f, a) => f(...a)
1081
1039
  });
@@ -1090,6 +1048,17 @@ var TriggerRegistry = class extends Resource2 {
1090
1048
  for (let i = registered.length - 1; i >= 0; i--) {
1091
1049
  const wasRemoved = allTriggers.find((trigger) => trigger.id === registered[i].trigger.id) == null;
1092
1050
  if (wasRemoved) {
1051
+ if (removed.length) {
1052
+ log9.info("removed", () => ({
1053
+ spaceKey: space.key,
1054
+ triggers: removed.map((trigger) => trigger.function)
1055
+ }), {
1056
+ F: __dxlog_file9,
1057
+ L: 181,
1058
+ S: this,
1059
+ C: (f, a) => f(...a)
1060
+ });
1061
+ }
1093
1062
  const unregistered = registered.splice(i, 1)[0];
1094
1063
  await unregistered.activationCtx?.dispose();
1095
1064
  removed.push(unregistered.trigger);
@@ -1109,6 +1078,7 @@ var TriggerRegistry = class extends Resource2 {
1109
1078
  };
1110
1079
  export {
1111
1080
  DevServer,
1081
+ FUNCTION_SCHEMA,
1112
1082
  FunctionDef,
1113
1083
  FunctionManifestSchema,
1114
1084
  FunctionRegistry,