@dxos/functions 0.7.0 → 0.7.1-staging.7f6f91c

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 (51) hide show
  1. package/dist/lib/browser/{chunk-7QJNOQ6N.mjs → chunk-FWIFI2MH.mjs} +57 -32
  2. package/dist/lib/browser/chunk-FWIFI2MH.mjs.map +7 -0
  3. package/dist/lib/browser/{chunk-L7H5DE53.mjs → chunk-QX2SGAWR.mjs} +28 -21
  4. package/dist/lib/browser/chunk-QX2SGAWR.mjs.map +7 -0
  5. package/dist/lib/browser/index.mjs +9 -5
  6. package/dist/lib/browser/index.mjs.map +1 -1
  7. package/dist/lib/browser/meta.json +1 -1
  8. package/dist/lib/browser/testing/index.mjs +6 -6
  9. package/dist/lib/browser/testing/index.mjs.map +3 -3
  10. package/dist/lib/browser/types.mjs +9 -5
  11. package/dist/lib/node/{chunk-TNG3Z74V.cjs → chunk-GKDHAWCP.cjs} +61 -34
  12. package/dist/lib/node/chunk-GKDHAWCP.cjs.map +7 -0
  13. package/dist/lib/node/{chunk-3KJEM5VR.cjs → chunk-OKV7IWWB.cjs} +41 -34
  14. package/dist/lib/node/chunk-OKV7IWWB.cjs.map +7 -0
  15. package/dist/lib/node/index.cjs +17 -13
  16. package/dist/lib/node/index.cjs.map +1 -1
  17. package/dist/lib/node/meta.json +1 -1
  18. package/dist/lib/node/testing/index.cjs +13 -13
  19. package/dist/lib/node/testing/index.cjs.map +2 -2
  20. package/dist/lib/node/types.cjs +11 -7
  21. package/dist/lib/node/types.cjs.map +2 -2
  22. package/dist/lib/node-esm/{chunk-DMTGUST2.mjs → chunk-SPHZ5SOR.mjs} +28 -21
  23. package/dist/lib/node-esm/chunk-SPHZ5SOR.mjs.map +7 -0
  24. package/dist/lib/node-esm/{chunk-SLC6ICH2.mjs → chunk-YSKH6PBN.mjs} +57 -32
  25. package/dist/lib/node-esm/chunk-YSKH6PBN.mjs.map +7 -0
  26. package/dist/lib/node-esm/index.mjs +9 -5
  27. package/dist/lib/node-esm/index.mjs.map +1 -1
  28. package/dist/lib/node-esm/meta.json +1 -1
  29. package/dist/lib/node-esm/testing/index.mjs +6 -6
  30. package/dist/lib/node-esm/testing/index.mjs.map +3 -3
  31. package/dist/lib/node-esm/types.mjs +9 -5
  32. package/dist/types/src/trigger/trigger-registry.d.ts +3 -3
  33. package/dist/types/src/trigger/trigger-registry.d.ts.map +1 -1
  34. package/dist/types/src/types.d.ts +137 -72
  35. package/dist/types/src/types.d.ts.map +1 -1
  36. package/package.json +17 -16
  37. package/schema/functions.json +2 -2
  38. package/src/runtime/scheduler.test.ts +1 -1
  39. package/src/runtime/scheduler.ts +1 -1
  40. package/src/testing/functions-integration.test.ts +1 -1
  41. package/src/testing/util.ts +2 -2
  42. package/src/trigger/trigger-registry.test.ts +7 -9
  43. package/src/trigger/trigger-registry.ts +7 -8
  44. package/src/trigger/type/subscription-trigger.ts +2 -2
  45. package/src/types.ts +70 -36
  46. package/dist/lib/browser/chunk-7QJNOQ6N.mjs.map +0 -7
  47. package/dist/lib/browser/chunk-L7H5DE53.mjs.map +0 -7
  48. package/dist/lib/node/chunk-3KJEM5VR.cjs.map +0 -7
  49. package/dist/lib/node/chunk-TNG3Z74V.cjs.map +0 -7
  50. package/dist/lib/node-esm/chunk-DMTGUST2.mjs.map +0 -7
  51. package/dist/lib/node-esm/chunk-SLC6ICH2.mjs.map +0 -7
@@ -1,67 +1,113 @@
1
1
  import { S } from '@dxos/echo-schema';
2
2
  /**
3
- * Type discriminator for TriggerSpec.
4
- * Every spec has a type field of type FunctionTriggerType that we can use to understand which
5
- * type we're working with.
3
+ * Type discriminator for TriggerType.
4
+ * Every spec has a type field of type TriggerKind that we can use to understand which type we're working with.
6
5
  * https://www.typescriptlang.org/docs/handbook/2/narrowing.html#discriminated-unions
7
6
  */
8
- export type FunctionTriggerType = 'subscription' | 'timer' | 'webhook' | 'websocket';
7
+ export type TriggerKind = 'timer' | 'webhook' | 'websocket' | 'subscription';
8
+ /**
9
+ * Cron timer.
10
+ */
9
11
  declare const TimerTriggerSchema: S.mutable<S.Struct<{
10
12
  type: S.Literal<["timer"]>;
11
- cron: typeof S.String;
13
+ cron: S.refine<string, S.Schema<string, string, never>>;
12
14
  }>>;
13
15
  export type TimerTrigger = S.Schema.Type<typeof TimerTriggerSchema>;
16
+ /**
17
+ * Webhook.
18
+ */
14
19
  declare const WebhookTriggerSchema: S.mutable<S.Struct<{
15
20
  type: S.Literal<["webhook"]>;
16
21
  method: typeof S.String;
17
22
  port: S.optional<typeof S.Number>;
18
23
  }>>;
19
24
  export type WebhookTrigger = S.Schema.Type<typeof WebhookTriggerSchema>;
25
+ /**
26
+ * Websocket.
27
+ * @deprecated
28
+ */
20
29
  declare const WebsocketTriggerSchema: S.mutable<S.Struct<{
21
30
  type: S.Literal<["websocket"]>;
22
31
  url: typeof S.String;
23
32
  init: S.optional<S.Record$<typeof S.String, typeof S.Any>>;
24
33
  }>>;
25
34
  export type WebsocketTrigger = S.Schema.Type<typeof WebsocketTriggerSchema>;
35
+ /**
36
+ * Subscription.
37
+ */
26
38
  declare const SubscriptionTriggerSchema: S.mutable<S.Struct<{
27
39
  type: S.Literal<["subscription"]>;
28
- filter: S.Array$<S.Struct<{
29
- type: typeof S.String;
40
+ filter: S.Struct<{
41
+ type: S.optional<S.SchemaClass<string, string, never>>;
30
42
  props: S.optional<S.Record$<typeof S.String, typeof S.Any>>;
31
- }>>;
43
+ }>;
32
44
  options: S.optional<S.Struct<{
33
- deep: S.optional<typeof S.Boolean>;
34
- delay: S.optional<typeof S.Number>;
45
+ deep: S.optional<S.SchemaClass<boolean, boolean, never>>;
46
+ delay: S.optional<S.SchemaClass<number, number, never>>;
35
47
  }>>;
36
48
  }>>;
37
49
  export type SubscriptionTrigger = S.Schema.Type<typeof SubscriptionTriggerSchema>;
38
- export type TriggerSpec = TimerTrigger | WebhookTrigger | WebsocketTrigger | SubscriptionTrigger;
39
- declare const FunctionDef_base: import("@dxos/echo-schema").AbstractTypedObject<{
40
- handler: string;
41
- uri: string;
42
- description?: string | undefined;
43
- route: string;
44
- } & {
45
- id: string;
46
- }, S.Struct.Encoded<{
47
- uri: typeof S.String;
48
- description: S.optional<typeof S.String>;
49
- route: typeof S.String;
50
- handler: typeof S.String;
51
- }>>;
52
50
  /**
53
- * Function definition.
51
+ * Trigger schema (discriminated union).
54
52
  */
55
- export declare class FunctionDef extends FunctionDef_base {
56
- }
53
+ export declare const TriggerSchema: S.Union<[S.mutable<S.Struct<{
54
+ type: S.Literal<["timer"]>;
55
+ cron: S.refine<string, S.Schema<string, string, never>>;
56
+ }>>, S.mutable<S.Struct<{
57
+ type: S.Literal<["webhook"]>;
58
+ method: typeof S.String;
59
+ port: S.optional<typeof S.Number>;
60
+ }>>, S.mutable<S.Struct<{
61
+ type: S.Literal<["websocket"]>;
62
+ url: typeof S.String;
63
+ init: S.optional<S.Record$<typeof S.String, typeof S.Any>>;
64
+ }>>, S.mutable<S.Struct<{
65
+ type: S.Literal<["subscription"]>;
66
+ filter: S.Struct<{
67
+ type: S.optional<S.SchemaClass<string, string, never>>;
68
+ props: S.optional<S.Record$<typeof S.String, typeof S.Any>>;
69
+ }>;
70
+ options: S.optional<S.Struct<{
71
+ deep: S.optional<S.SchemaClass<boolean, boolean, never>>;
72
+ delay: S.optional<S.SchemaClass<number, number, never>>;
73
+ }>>;
74
+ }>>]>;
75
+ export type TriggerType = S.Schema.Type<typeof TriggerSchema>;
76
+ /**
77
+ * Function trigger.
78
+ */
79
+ export declare const FunctionTriggerSchema: S.Struct<{
80
+ function: S.optional<S.SchemaClass<string, string, never>>;
81
+ enabled: S.optional<S.SchemaClass<boolean, boolean, never>>;
82
+ spec: S.optional<S.Union<[S.mutable<S.Struct<{
83
+ type: S.Literal<["timer"]>;
84
+ cron: S.refine<string, S.Schema<string, string, never>>;
85
+ }>>, S.mutable<S.Struct<{
86
+ type: S.Literal<["webhook"]>;
87
+ method: typeof S.String;
88
+ port: S.optional<typeof S.Number>;
89
+ }>>, S.mutable<S.Struct<{
90
+ type: S.Literal<["websocket"]>;
91
+ url: typeof S.String;
92
+ init: S.optional<S.Record$<typeof S.String, typeof S.Any>>;
93
+ }>>, S.mutable<S.Struct<{
94
+ type: S.Literal<["subscription"]>;
95
+ filter: S.Struct<{
96
+ type: S.optional<S.SchemaClass<string, string, never>>;
97
+ props: S.optional<S.Record$<typeof S.String, typeof S.Any>>;
98
+ }>;
99
+ options: S.optional<S.Struct<{
100
+ deep: S.optional<S.SchemaClass<boolean, boolean, never>>;
101
+ delay: S.optional<S.SchemaClass<number, number, never>>;
102
+ }>>;
103
+ }>>]>>;
104
+ meta: S.optional<S.mutable<S.Record$<typeof S.String, typeof S.Any>>>;
105
+ }>;
106
+ export type FunctionTriggerType = S.Schema.Type<typeof FunctionTriggerSchema>;
57
107
  declare const FunctionTrigger_base: import("@dxos/echo-schema").AbstractTypedObject<{
58
- function: string;
59
- name?: string | undefined;
108
+ function?: string | undefined;
60
109
  enabled?: boolean | undefined;
61
- meta?: {
62
- [x: string]: any;
63
- } | undefined;
64
- spec: {
110
+ spec?: {
65
111
  type: "timer";
66
112
  cron: string;
67
113
  } | {
@@ -75,28 +121,29 @@ declare const FunctionTrigger_base: import("@dxos/echo-schema").AbstractTypedObj
75
121
  readonly [x: string]: any;
76
122
  } | undefined;
77
123
  } | {
78
- filter: readonly {
79
- readonly type: string;
124
+ filter: {
125
+ readonly type?: string | undefined;
80
126
  readonly props?: {
81
127
  readonly [x: string]: any;
82
128
  } | undefined;
83
- }[];
129
+ };
84
130
  type: "subscription";
85
131
  options?: {
86
132
  readonly deep?: boolean | undefined;
87
133
  readonly delay?: number | undefined;
88
134
  } | undefined;
89
- };
135
+ } | undefined;
136
+ meta?: {
137
+ [x: string]: any;
138
+ } | undefined;
90
139
  } & {
91
140
  id: string;
92
141
  }, S.Struct.Encoded<{
93
- name: S.optional<typeof S.String>;
94
- enabled: S.optional<typeof S.Boolean>;
95
- function: S.SchemaClass<string, string, never>;
96
- meta: S.optional<S.mutable<S.Record$<typeof S.String, typeof S.Any>>>;
97
- spec: S.Union<[S.mutable<S.Struct<{
142
+ readonly function: S.optional<S.SchemaClass<string, string, never>>;
143
+ readonly enabled: S.optional<S.SchemaClass<boolean, boolean, never>>;
144
+ readonly spec: S.optional<S.Union<[S.mutable<S.Struct<{
98
145
  type: S.Literal<["timer"]>;
99
- cron: typeof S.String;
146
+ cron: S.refine<string, S.Schema<string, string, never>>;
100
147
  }>>, S.mutable<S.Struct<{
101
148
  type: S.Literal<["webhook"]>;
102
149
  method: typeof S.String;
@@ -107,21 +154,41 @@ declare const FunctionTrigger_base: import("@dxos/echo-schema").AbstractTypedObj
107
154
  init: S.optional<S.Record$<typeof S.String, typeof S.Any>>;
108
155
  }>>, S.mutable<S.Struct<{
109
156
  type: S.Literal<["subscription"]>;
110
- filter: S.Array$<S.Struct<{
111
- type: typeof S.String;
157
+ filter: S.Struct<{
158
+ type: S.optional<S.SchemaClass<string, string, never>>;
112
159
  props: S.optional<S.Record$<typeof S.String, typeof S.Any>>;
113
- }>>;
160
+ }>;
114
161
  options: S.optional<S.Struct<{
115
- deep: S.optional<typeof S.Boolean>;
116
- delay: S.optional<typeof S.Number>;
162
+ deep: S.optional<S.SchemaClass<boolean, boolean, never>>;
163
+ delay: S.optional<S.SchemaClass<number, number, never>>;
117
164
  }>>;
118
- }>>]>;
165
+ }>>]>>;
166
+ readonly meta: S.optional<S.mutable<S.Record$<typeof S.String, typeof S.Any>>>;
119
167
  }>>;
120
168
  /**
121
169
  * Function trigger.
122
170
  */
123
171
  export declare class FunctionTrigger extends FunctionTrigger_base {
124
172
  }
173
+ declare const FunctionDef_base: import("@dxos/echo-schema").AbstractTypedObject<{
174
+ handler: string;
175
+ uri: string;
176
+ description?: string | undefined;
177
+ route: string;
178
+ } & {
179
+ id: string;
180
+ }, S.Struct.Encoded<{
181
+ uri: typeof S.String;
182
+ description: S.optional<typeof S.String>;
183
+ route: typeof S.String;
184
+ handler: typeof S.String;
185
+ }>>;
186
+ /**
187
+ * Function definition.
188
+ * @deprecated (Use dxos.org/type/Function)
189
+ */
190
+ export declare class FunctionDef extends FunctionDef_base {
191
+ }
125
192
  /**
126
193
  * Function manifest file.
127
194
  */
@@ -140,13 +207,9 @@ export declare const FunctionManifestSchema: S.Struct<{
140
207
  handler: typeof S.String;
141
208
  }>, never>>>>;
142
209
  triggers: S.optional<S.mutable<S.Array$<S.Schema<{
143
- function: string;
144
- name?: string | undefined;
210
+ function?: string | undefined;
145
211
  enabled?: boolean | undefined;
146
- meta?: {
147
- [x: string]: any;
148
- } | undefined;
149
- spec: {
212
+ spec?: {
150
213
  type: "timer";
151
214
  cron: string;
152
215
  } | {
@@ -160,28 +223,29 @@ export declare const FunctionManifestSchema: S.Struct<{
160
223
  readonly [x: string]: any;
161
224
  } | undefined;
162
225
  } | {
163
- filter: readonly {
164
- readonly type: string;
226
+ filter: {
227
+ readonly type?: string | undefined;
165
228
  readonly props?: {
166
229
  readonly [x: string]: any;
167
230
  } | undefined;
168
- }[];
231
+ };
169
232
  type: "subscription";
170
233
  options?: {
171
234
  readonly deep?: boolean | undefined;
172
235
  readonly delay?: number | undefined;
173
236
  } | undefined;
174
- };
237
+ } | undefined;
238
+ meta?: {
239
+ [x: string]: any;
240
+ } | undefined;
175
241
  } & {
176
242
  "@meta"?: import("@dxos/echo-schema").ObjectMeta;
177
243
  }, S.Struct.Encoded<{
178
- name: S.optional<typeof S.String>;
179
- enabled: S.optional<typeof S.Boolean>;
180
- function: S.SchemaClass<string, string, never>;
181
- meta: S.optional<S.mutable<S.Record$<typeof S.String, typeof S.Any>>>;
182
- spec: S.Union<[S.mutable<S.Struct<{
244
+ readonly function: S.optional<S.SchemaClass<string, string, never>>;
245
+ readonly enabled: S.optional<S.SchemaClass<boolean, boolean, never>>;
246
+ readonly spec: S.optional<S.Union<[S.mutable<S.Struct<{
183
247
  type: S.Literal<["timer"]>;
184
- cron: typeof S.String;
248
+ cron: S.refine<string, S.Schema<string, string, never>>;
185
249
  }>>, S.mutable<S.Struct<{
186
250
  type: S.Literal<["webhook"]>;
187
251
  method: typeof S.String;
@@ -192,18 +256,19 @@ export declare const FunctionManifestSchema: S.Struct<{
192
256
  init: S.optional<S.Record$<typeof S.String, typeof S.Any>>;
193
257
  }>>, S.mutable<S.Struct<{
194
258
  type: S.Literal<["subscription"]>;
195
- filter: S.Array$<S.Struct<{
196
- type: typeof S.String;
259
+ filter: S.Struct<{
260
+ type: S.optional<S.SchemaClass<string, string, never>>;
197
261
  props: S.optional<S.Record$<typeof S.String, typeof S.Any>>;
198
- }>>;
262
+ }>;
199
263
  options: S.optional<S.Struct<{
200
- deep: S.optional<typeof S.Boolean>;
201
- delay: S.optional<typeof S.Number>;
264
+ deep: S.optional<S.SchemaClass<boolean, boolean, never>>;
265
+ delay: S.optional<S.SchemaClass<number, number, never>>;
202
266
  }>>;
203
- }>>]>;
267
+ }>>]>>;
268
+ readonly meta: S.optional<S.mutable<S.Record$<typeof S.String, typeof S.Any>>>;
204
269
  }>, never>>>>;
205
270
  }>;
206
271
  export type FunctionManifest = S.Schema.Type<typeof FunctionManifestSchema>;
207
- export declare const FUNCTION_SCHEMA: (typeof FunctionDef | typeof FunctionTrigger)[];
272
+ export declare const FUNCTION_TYPES: (typeof FunctionTrigger | typeof FunctionDef)[];
208
273
  export {};
209
274
  //# sourceMappingURL=types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/types.ts"],"names":[],"mappings":"AAIA,OAAO,EAAa,CAAC,EAAe,MAAM,mBAAmB,CAAC;AAE9D;;;;;GAKG;AACH,MAAM,MAAM,mBAAmB,GAAG,cAAc,GAAG,OAAO,GAAG,SAAS,GAAG,WAAW,CAAC;AAErF,QAAA,MAAM,kBAAkB;;;GAGN,CAAC;AAEnB,MAAM,MAAM,YAAY,GAAG,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,kBAAkB,CAAC,CAAC;AAEpE,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;;;;;;;EAGjC,CAAC;AAEH,MAAM,MAAM,gBAAgB,GAAG,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,sBAAsB,CAAC,CAAC;AAE5E,eAAO,MAAM,cAAc,iDAAiC,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dxos/functions",
3
- "version": "0.7.0",
3
+ "version": "0.7.1-staging.7f6f91c",
4
4
  "description": "Functions API and runtime.",
5
5
  "homepage": "https://dxos.org",
6
6
  "bugs": "https://github.com/dxos/dxos/issues",
@@ -41,30 +41,31 @@
41
41
  "src"
42
42
  ],
43
43
  "dependencies": {
44
- "@effect/schema": "^0.75.1",
44
+ "@effect/schema": "^0.75.5",
45
45
  "@preact/signals-core": "^1.6.0",
46
46
  "cron": "^3.1.6",
47
- "effect": "^3.9.1",
47
+ "effect": "^3.9.2",
48
48
  "express": "^4.19.2",
49
49
  "get-port-please": "^3.1.1",
50
50
  "ws": "^8.14.2",
51
- "@dxos/async": "0.7.0",
52
- "@dxos/context": "0.7.0",
53
- "@dxos/client": "0.7.0",
54
- "@dxos/echo-db": "0.7.0",
55
- "@dxos/echo-protocol": "0.7.0",
56
- "@dxos/echo-schema": "0.7.0",
57
- "@dxos/invariant": "0.7.0",
58
- "@dxos/keys": "0.7.0",
59
- "@dxos/log": "0.7.0",
60
- "@dxos/node-std": "0.7.0",
61
- "@dxos/util": "0.7.0",
62
- "@dxos/protocols": "0.7.0"
51
+ "@dxos/async": "0.7.1-staging.7f6f91c",
52
+ "@dxos/client": "0.7.1-staging.7f6f91c",
53
+ "@dxos/context": "0.7.1-staging.7f6f91c",
54
+ "@dxos/echo-protocol": "0.7.1-staging.7f6f91c",
55
+ "@dxos/echo-schema": "0.7.1-staging.7f6f91c",
56
+ "@dxos/echo-db": "0.7.1-staging.7f6f91c",
57
+ "@dxos/keys": "0.7.1-staging.7f6f91c",
58
+ "@dxos/invariant": "0.7.1-staging.7f6f91c",
59
+ "@dxos/log": "0.7.1-staging.7f6f91c",
60
+ "@dxos/protocols": "0.7.1-staging.7f6f91c",
61
+ "@dxos/node-std": "0.7.1-staging.7f6f91c",
62
+ "@dxos/schema": "0.7.1-staging.7f6f91c",
63
+ "@dxos/util": "0.7.1-staging.7f6f91c"
63
64
  },
64
65
  "devDependencies": {
65
66
  "@types/express": "^4.17.17",
66
67
  "@types/ws": "^7.4.0",
67
- "@dxos/agent": "0.7.0"
68
+ "@dxos/agent": "0.7.1-staging.7f6f91c"
68
69
  },
69
70
  "publishConfig": {
70
71
  "access": "public"
@@ -48,7 +48,7 @@
48
48
  "properties": {
49
49
  "function": {
50
50
  "type": "string",
51
- "description": "Function URI.",
51
+ "description": "Function",
52
52
  "title": "string"
53
53
  },
54
54
  "enabled": {
@@ -208,4 +208,4 @@
208
208
  "title": "object"
209
209
  }
210
210
  }
211
- }
211
+ }
@@ -175,7 +175,7 @@ describe('scheduler', () => {
175
175
  enabled: true,
176
176
  spec: {
177
177
  type: 'subscription',
178
- filter: [{ type: TestType.typename }],
178
+ filter: { type: TestType.typename },
179
179
  },
180
180
  },
181
181
  ],
@@ -136,7 +136,7 @@ export class Scheduler {
136
136
  if (endpoint) {
137
137
  // TODO(burdon): Move out of scheduler (generalize as callback).
138
138
  const url = path.join(endpoint, def.route);
139
- log.info('exec', { function: def.uri, url, triggerType: trigger.spec.type });
139
+ log.info('exec', { function: def.uri, url, triggerType: trigger.spec?.type });
140
140
  const response = await fetch(url, {
141
141
  method: 'POST',
142
142
  headers: {
@@ -43,7 +43,7 @@ describe.skip('functions e2e', () => {
43
43
  meta: triggerMeta,
44
44
  spec: {
45
45
  type: 'subscription',
46
- filter: [{ type: TestType.typename }],
46
+ filter: { type: TestType.typename },
47
47
  },
48
48
  }),
49
49
  );
@@ -12,9 +12,9 @@ import { FunctionTrigger } from '../types';
12
12
 
13
13
  export const triggerWebhook = async (space: Space, uri: string) => {
14
14
  const trigger = (
15
- await space.db.query(Filter.schema(FunctionTrigger, (t: FunctionTrigger) => t.function === uri)).run()
15
+ await space.db.query(Filter.schema(FunctionTrigger, (trigger: FunctionTrigger) => trigger.function === uri)).run()
16
16
  ).objects[0];
17
- invariant(trigger.spec.type === 'webhook');
17
+ invariant(trigger.spec?.type === 'webhook');
18
18
  void fetch(`http://localhost:${trigger.spec.port}`);
19
19
  };
20
20
 
@@ -48,11 +48,9 @@ const manifest: FunctionManifest = {
48
48
  enabled: true,
49
49
  spec: {
50
50
  type: 'subscription',
51
- filter: [
52
- {
53
- type: TestType.typename,
54
- },
55
- ],
51
+ filter: {
52
+ type: TestType.typename,
53
+ },
56
54
  },
57
55
  },
58
56
  ],
@@ -111,13 +109,13 @@ describe('trigger registry', () => {
111
109
 
112
110
  const callbackInvoked = new Trigger();
113
111
  const { objects: allTriggers } = await space.db.query(Filter.schema(FunctionTrigger)).run();
114
- const webhookTrigger = allTriggers.find((trigger: FunctionTrigger) => trigger.spec.type === 'webhook')!;
112
+ const webhookTrigger = allTriggers.find((trigger: FunctionTrigger) => trigger.spec?.type === 'webhook')!;
115
113
  await registry.activate(space, webhookTrigger, async () => {
116
114
  callbackInvoked.wake();
117
115
  return 200;
118
116
  });
119
117
 
120
- setTimeout(() => triggerWebhook(space, webhookTrigger.function));
118
+ setTimeout(() => triggerWebhook(space, webhookTrigger.function!));
121
119
  await callbackInvoked.wait();
122
120
  });
123
121
 
@@ -150,7 +148,7 @@ describe('trigger registry', () => {
150
148
  await waitForInactiveTriggers(registry, space);
151
149
 
152
150
  const { objects: allTriggers } = await space.db.query(Filter.schema(FunctionTrigger)).run();
153
- const echoTrigger = allTriggers.find((trigger: FunctionTrigger) => trigger.spec.type === 'subscription')!;
151
+ const echoTrigger = allTriggers.find((trigger: FunctionTrigger) => trigger.spec?.type === 'subscription')!;
154
152
  let count = 0;
155
153
  await registry.activate(space, echoTrigger, async () => {
156
154
  count++;
@@ -177,7 +175,7 @@ describe('trigger registry', () => {
177
175
  await waitForInactiveTriggers(registry, space);
178
176
 
179
177
  const { objects: allTriggers } = await space.db.query(Filter.schema(FunctionTrigger)).run();
180
- const echoTrigger = allTriggers.find((trigger: FunctionTrigger) => trigger.spec.type === 'subscription')!;
178
+ const echoTrigger = allTriggers.find((trigger: FunctionTrigger) => trigger.spec?.type === 'subscription')!;
181
179
  let count = 0;
182
180
  await registry.activate(space, echoTrigger, async () => {
183
181
  count++;
@@ -12,15 +12,15 @@ import { PublicKey } from '@dxos/keys';
12
12
  import { log } from '@dxos/log';
13
13
  import { ComplexMap, diff } from '@dxos/util';
14
14
 
15
- import { createSubscriptionTrigger, createTimerTrigger, createWebsocketTrigger } from './type';
16
- import { type FunctionManifest, FunctionTrigger, type FunctionTriggerType, type TriggerSpec } from '../types';
15
+ import { createSubscriptionTrigger, createTimerTrigger } from './type';
16
+ import { type FunctionManifest, FunctionTrigger, type TriggerKind, type TriggerType } from '../types';
17
17
 
18
18
  type ResponseCode = number;
19
19
 
20
20
  export type TriggerCallback = (args: object) => Promise<ResponseCode>;
21
21
 
22
22
  // TODO(burdon): Make object?
23
- export type TriggerFactory<Spec extends TriggerSpec, Options = any> = (
23
+ export type TriggerFactory<Spec extends TriggerType, Options = any> = (
24
24
  ctx: Context,
25
25
  space: Space,
26
26
  spec: Spec,
@@ -28,15 +28,13 @@ export type TriggerFactory<Spec extends TriggerSpec, Options = any> = (
28
28
  options?: Options,
29
29
  ) => Promise<void>;
30
30
 
31
- export type TriggerFactoryMap = Record<FunctionTriggerType, TriggerFactory<any>>;
31
+ export type TriggerFactoryMap = Partial<Record<TriggerKind, TriggerFactory<any>>>;
32
32
 
33
33
  const triggerFactory: TriggerFactoryMap = {
34
- subscription: createSubscriptionTrigger,
35
34
  timer: createTimerTrigger,
36
35
  // TODO(burdon): Cannot use in browser.
37
36
  // webhook: createWebhookTrigger,
38
- webhook: null as any,
39
- websocket: createWebsocketTrigger,
37
+ subscription: createSubscriptionTrigger,
40
38
  };
41
39
 
42
40
  export type TriggerEvent = {
@@ -84,6 +82,7 @@ export class TriggerRegistry extends Resource {
84
82
 
85
83
  try {
86
84
  // Create trigger.
85
+ invariant(trigger.spec);
87
86
  const options = this._options?.[trigger.spec.type];
88
87
  const createTrigger = triggerFactory[trigger.spec.type];
89
88
  invariant(createTrigger, `Trigger factory not found: ${trigger.spec.type}`);
@@ -112,7 +111,7 @@ export class TriggerRegistry extends Resource {
112
111
  let keys = trigger[ECHO_ATTR_META]?.keys;
113
112
  delete trigger[ECHO_ATTR_META];
114
113
  if (!keys?.length) {
115
- keys = [foreignKey('manifest', [trigger.function, trigger.spec.type].join(':'))];
114
+ keys = [foreignKey('manifest', [trigger.function, trigger.spec?.type].join(':'))];
116
115
  }
117
116
 
118
117
  return create(FunctionTrigger, trigger, { keys });
@@ -73,8 +73,8 @@ export const createSubscriptionTrigger: TriggerFactory<SubscriptionTrigger> = as
73
73
  // TODO(burdon): [Bug]: not updated when document is deleted (either top or hierarchically).
74
74
  log.info('subscription', { filter });
75
75
  // const query = triggerCtx.space.db.query(Filter.or(filter.map(({ type, props }) => Filter.typename(type, props))));
76
- if (filter) {
77
- const query = space.db.query(Filter.typename(filter[0].type, filter[0].props));
76
+ if (filter.type) {
77
+ const query = space.db.query(Filter.typename(filter.type, filter.props));
78
78
  subscriptions.push(query.subscribe(delay ? debounce(update, delay) : update));
79
79
  }
80
80