@dxos/functions 0.7.4 → 0.7.5-labs.071a3e2

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 (87) hide show
  1. package/dist/lib/browser/{chunk-Y2OPAP26.mjs → chunk-FTGUA7ZJ.mjs} +2 -2
  2. package/dist/lib/browser/chunk-R4ERZ4GX.mjs +162 -0
  3. package/dist/lib/browser/chunk-R4ERZ4GX.mjs.map +7 -0
  4. package/dist/lib/browser/chunk-XRCXIG74.mjs +12 -0
  5. package/dist/lib/browser/chunk-YJEIETRB.mjs +128 -0
  6. package/dist/lib/browser/chunk-YJEIETRB.mjs.map +7 -0
  7. package/dist/lib/browser/edge/index.mjs +21 -0
  8. package/dist/lib/browser/index.mjs +27 -6
  9. package/dist/lib/browser/index.mjs.map +2 -2
  10. package/dist/lib/browser/meta.json +1 -1
  11. package/dist/lib/browser/testing/index.mjs +5 -3
  12. package/dist/lib/browser/testing/index.mjs.map +1 -1
  13. package/dist/lib/browser/{types.mjs → types/index.mjs} +7 -2
  14. package/dist/lib/browser/types/index.mjs.map +7 -0
  15. package/dist/lib/node/chunk-4WNFTPH7.cjs +188 -0
  16. package/dist/lib/node/chunk-4WNFTPH7.cjs.map +7 -0
  17. package/dist/lib/node/chunk-JEQ2X3Z6.cjs +34 -0
  18. package/dist/lib/node/chunk-JEQ2X3Z6.cjs.map +7 -0
  19. package/dist/lib/node/chunk-MZMHE4DC.cjs +154 -0
  20. package/dist/lib/node/chunk-MZMHE4DC.cjs.map +7 -0
  21. package/dist/lib/node/{chunk-CCULBUSE.cjs → chunk-NC6L7H5C.cjs} +15 -15
  22. package/dist/lib/node/edge/index.cjs +42 -0
  23. package/dist/lib/node/edge/index.cjs.map +7 -0
  24. package/dist/lib/node/index.cjs +38 -18
  25. package/dist/lib/node/index.cjs.map +2 -2
  26. package/dist/lib/node/meta.json +1 -1
  27. package/dist/lib/node/testing/index.cjs +11 -10
  28. package/dist/lib/node/testing/index.cjs.map +1 -1
  29. package/dist/lib/node/{types.cjs → types/index.cjs} +14 -9
  30. package/dist/lib/node/types/index.cjs.map +7 -0
  31. package/dist/lib/node-esm/chunk-DHGBFXSZ.mjs +12 -0
  32. package/dist/lib/node-esm/chunk-DHGBFXSZ.mjs.map +7 -0
  33. package/dist/lib/node-esm/{chunk-GGGGWYP6.mjs → chunk-FK2RGYVS.mjs} +2 -2
  34. package/dist/lib/node-esm/chunk-T2KBXTMR.mjs +128 -0
  35. package/dist/lib/node-esm/chunk-T2KBXTMR.mjs.map +7 -0
  36. package/dist/lib/node-esm/chunk-UOQLFLOW.mjs +162 -0
  37. package/dist/lib/node-esm/chunk-UOQLFLOW.mjs.map +7 -0
  38. package/dist/lib/node-esm/edge/index.mjs +21 -0
  39. package/dist/lib/node-esm/edge/index.mjs.map +7 -0
  40. package/dist/lib/node-esm/index.mjs +27 -6
  41. package/dist/lib/node-esm/index.mjs.map +2 -2
  42. package/dist/lib/node-esm/meta.json +1 -1
  43. package/dist/lib/node-esm/testing/index.mjs +5 -3
  44. package/dist/lib/node-esm/testing/index.mjs.map +1 -1
  45. package/dist/lib/node-esm/{types.mjs → types/index.mjs} +7 -2
  46. package/dist/lib/node-esm/types/index.mjs.map +7 -0
  47. package/dist/types/src/edge/functions.d.ts +25 -0
  48. package/dist/types/src/edge/functions.d.ts.map +1 -0
  49. package/dist/types/src/edge/index.d.ts +2 -0
  50. package/dist/types/src/edge/index.d.ts.map +1 -0
  51. package/dist/types/src/handler.d.ts.map +1 -1
  52. package/dist/types/src/index.d.ts +1 -0
  53. package/dist/types/src/index.d.ts.map +1 -1
  54. package/dist/types/src/testing/types.d.ts +3 -5
  55. package/dist/types/src/testing/types.d.ts.map +1 -1
  56. package/dist/types/src/translations.d.ts +9 -0
  57. package/dist/types/src/translations.d.ts.map +1 -0
  58. package/dist/types/src/types/index.d.ts +3 -0
  59. package/dist/types/src/types/index.d.ts.map +1 -0
  60. package/dist/types/src/types/schema.d.ts +57 -0
  61. package/dist/types/src/types/schema.d.ts.map +1 -0
  62. package/dist/types/src/{types.d.ts → types/types.d.ts} +76 -75
  63. package/dist/types/src/types/types.d.ts.map +1 -0
  64. package/dist/types/tsconfig.tsbuildinfo +1 -0
  65. package/package.json +27 -20
  66. package/src/edge/functions.ts +120 -0
  67. package/src/edge/index.ts +5 -0
  68. package/src/handler.ts +1 -0
  69. package/src/index.ts +1 -0
  70. package/src/translations.ts +15 -0
  71. package/src/trigger/trigger-registry.test.ts +3 -1
  72. package/src/types/index.ts +6 -0
  73. package/src/types/schema.ts +46 -0
  74. package/src/{types.ts → types/types.ts} +8 -0
  75. package/dist/lib/browser/chunk-N5D5R4Q4.mjs +0 -129
  76. package/dist/lib/browser/chunk-N5D5R4Q4.mjs.map +0 -7
  77. package/dist/lib/node/chunk-JMJCJ3SA.cjs +0 -156
  78. package/dist/lib/node/chunk-JMJCJ3SA.cjs.map +0 -7
  79. package/dist/lib/node/types.cjs.map +0 -7
  80. package/dist/lib/node-esm/chunk-2NACE6MJ.mjs +0 -129
  81. package/dist/lib/node-esm/chunk-2NACE6MJ.mjs.map +0 -7
  82. package/dist/types/src/types.d.ts.map +0 -1
  83. /package/dist/lib/browser/{chunk-Y2OPAP26.mjs.map → chunk-FTGUA7ZJ.mjs.map} +0 -0
  84. /package/dist/lib/browser/{types.mjs.map → chunk-XRCXIG74.mjs.map} +0 -0
  85. /package/dist/lib/{node-esm/types.mjs.map → browser/edge/index.mjs.map} +0 -0
  86. /package/dist/lib/node/{chunk-CCULBUSE.cjs.map → chunk-NC6L7H5C.cjs.map} +0 -0
  87. /package/dist/lib/node-esm/{chunk-GGGGWYP6.mjs.map → chunk-FK2RGYVS.mjs.map} +0 -0
@@ -7,7 +7,8 @@ import { S } from '@dxos/echo-schema';
7
7
  export declare enum TriggerKind {
8
8
  Timer = "timer",
9
9
  Webhook = "webhook",
10
- Subscription = "subscription"
10
+ Subscription = "subscription",
11
+ Email = "email"
11
12
  }
12
13
  /**
13
14
  * Cron timer.
@@ -17,6 +18,10 @@ declare const TimerTriggerSchema: S.mutable<S.Struct<{
17
18
  cron: S.SchemaClass<string, string, never>;
18
19
  }>>;
19
20
  export type TimerTrigger = S.Schema.Type<typeof TimerTriggerSchema>;
21
+ declare const EmailTriggerSchema: S.mutable<S.Struct<{
22
+ type: S.Literal<[TriggerKind.Email]>;
23
+ }>>;
24
+ export type EmailTrigger = S.Schema.Type<typeof EmailTriggerSchema>;
20
25
  /**
21
26
  * Webhook.
22
27
  */
@@ -61,6 +66,8 @@ export declare const TriggerSchema: S.Union<[S.mutable<S.Struct<{
61
66
  deep: S.optional<S.SchemaClass<boolean, boolean, never>>;
62
67
  delay: S.optional<S.SchemaClass<number, number, never>>;
63
68
  }>>;
69
+ }>>, S.mutable<S.Struct<{
70
+ type: S.Literal<[TriggerKind.Email]>;
64
71
  }>>]>;
65
72
  export type TriggerType = S.Schema.Type<typeof TriggerSchema>;
66
73
  /**
@@ -86,39 +93,13 @@ export declare const FunctionTriggerSchema: S.Struct<{
86
93
  deep: S.optional<S.SchemaClass<boolean, boolean, never>>;
87
94
  delay: S.optional<S.SchemaClass<number, number, never>>;
88
95
  }>>;
96
+ }>>, S.mutable<S.Struct<{
97
+ type: S.Literal<[TriggerKind.Email]>;
89
98
  }>>]>>;
90
99
  meta: S.optional<S.mutable<S.Record$<typeof S.String, typeof S.Any>>>;
91
100
  }>;
92
101
  export type FunctionTriggerType = S.Schema.Type<typeof FunctionTriggerSchema>;
93
- declare const FunctionTrigger_base: import("@dxos/echo-schema").AbstractTypedObject<{
94
- function?: string | undefined;
95
- enabled?: boolean | undefined;
96
- spec?: {
97
- type: TriggerKind.Timer;
98
- cron: string;
99
- } | {
100
- type: TriggerKind.Webhook;
101
- method?: string | undefined;
102
- port?: number | undefined;
103
- } | {
104
- filter: {
105
- readonly type?: string | undefined;
106
- readonly props?: {
107
- readonly [x: string]: any;
108
- } | undefined;
109
- };
110
- type: TriggerKind.Subscription;
111
- options?: {
112
- readonly deep?: boolean | undefined;
113
- readonly delay?: number | undefined;
114
- } | undefined;
115
- } | undefined;
116
- meta?: {
117
- [x: string]: any;
118
- } | undefined;
119
- } & {
120
- id: string;
121
- }, S.Struct.Encoded<{
102
+ declare const FunctionTrigger_base: import("@dxos/echo-schema").TypedObjectPrototype<import("packages/core/echo/echo-schema/dist/types/src/object/common").TypedObjectFields<{
122
103
  readonly function: S.optional<S.SchemaClass<string, string, never>>;
123
104
  readonly enabled: S.optional<S.SchemaClass<boolean, boolean, never>>;
124
105
  readonly spec: S.optional<S.Union<[S.mutable<S.Struct<{
@@ -138,6 +119,32 @@ declare const FunctionTrigger_base: import("@dxos/echo-schema").AbstractTypedObj
138
119
  deep: S.optional<S.SchemaClass<boolean, boolean, never>>;
139
120
  delay: S.optional<S.SchemaClass<number, number, never>>;
140
121
  }>>;
122
+ }>>, S.mutable<S.Struct<{
123
+ type: S.Literal<[TriggerKind.Email]>;
124
+ }>>]>>;
125
+ readonly meta: S.optional<S.mutable<S.Record$<typeof S.String, typeof S.Any>>>;
126
+ }, import("packages/core/echo/echo-schema/dist/types/src/object/common").TypedObjectOptions>, S.Struct.Encoded<{
127
+ readonly function: S.optional<S.SchemaClass<string, string, never>>;
128
+ readonly enabled: S.optional<S.SchemaClass<boolean, boolean, never>>;
129
+ readonly spec: S.optional<S.Union<[S.mutable<S.Struct<{
130
+ type: S.Literal<[TriggerKind.Timer]>;
131
+ cron: S.SchemaClass<string, string, never>;
132
+ }>>, S.mutable<S.Struct<{
133
+ type: S.Literal<[TriggerKind.Webhook]>;
134
+ method: S.optional<S.SchemaClass<string, string, never>>;
135
+ port: S.optional<S.SchemaClass<number, number, never>>;
136
+ }>>, S.mutable<S.Struct<{
137
+ type: S.Literal<[TriggerKind.Subscription]>;
138
+ filter: S.Struct<{
139
+ type: S.optional<S.SchemaClass<string, string, never>>;
140
+ props: S.optional<S.Record$<typeof S.String, typeof S.Any>>;
141
+ }>;
142
+ options: S.optional<S.Struct<{
143
+ deep: S.optional<S.SchemaClass<boolean, boolean, never>>;
144
+ delay: S.optional<S.SchemaClass<number, number, never>>;
145
+ }>>;
146
+ }>>, S.mutable<S.Struct<{
147
+ type: S.Literal<[TriggerKind.Email]>;
141
148
  }>>]>>;
142
149
  readonly meta: S.optional<S.mutable<S.Record$<typeof S.String, typeof S.Any>>>;
143
150
  }>>;
@@ -146,14 +153,12 @@ declare const FunctionTrigger_base: import("@dxos/echo-schema").AbstractTypedObj
146
153
  */
147
154
  export declare class FunctionTrigger extends FunctionTrigger_base {
148
155
  }
149
- declare const FunctionDef_base: import("@dxos/echo-schema").AbstractTypedObject<{
150
- handler: string;
151
- uri: string;
152
- description?: string | undefined;
153
- route: string;
154
- } & {
155
- id: string;
156
- }, S.Struct.Encoded<{
156
+ declare const FunctionDef_base: import("@dxos/echo-schema").TypedObjectPrototype<import("packages/core/echo/echo-schema/dist/types/src/object/common").TypedObjectFields<{
157
+ uri: typeof S.String;
158
+ description: S.optional<typeof S.String>;
159
+ route: typeof S.String;
160
+ handler: typeof S.String;
161
+ }, import("packages/core/echo/echo-schema/dist/types/src/object/common").TypedObjectOptions>, S.Struct.Encoded<{
157
162
  uri: typeof S.String;
158
163
  description: S.optional<typeof S.String>;
159
164
  route: typeof S.String;
@@ -169,48 +174,42 @@ export declare class FunctionDef extends FunctionDef_base {
169
174
  * Function manifest file.
170
175
  */
171
176
  export declare const FunctionManifestSchema: S.Struct<{
172
- functions: S.optional<S.mutable<S.Array$<S.Schema<import("@dxos/echo-schema").ExcludeId<{
173
- handler: string;
174
- uri: string;
175
- description?: string | undefined;
176
- route: string;
177
- } & {
178
- id: string;
179
- }> & import("@dxos/echo-schema").WithMeta, S.Struct.Encoded<{
177
+ functions: S.optional<S.mutable<S.Array$<S.Schema<import("@dxos/echo-schema").ExcludeId<import("packages/core/echo/echo-schema/dist/types/src/object/common").TypedObjectFields<{
178
+ uri: typeof S.String;
179
+ description: S.optional<typeof S.String>;
180
+ route: typeof S.String;
181
+ handler: typeof S.String;
182
+ }, import("packages/core/echo/echo-schema/dist/types/src/object/common").TypedObjectOptions>> & import("@dxos/echo-schema").WithMeta, S.Struct.Encoded<{
180
183
  uri: typeof S.String;
181
184
  description: S.optional<typeof S.String>;
182
185
  route: typeof S.String;
183
186
  handler: typeof S.String;
184
187
  }>, never>>>>;
185
- triggers: S.optional<S.mutable<S.Array$<S.Schema<import("@dxos/echo-schema").ExcludeId<{
186
- function?: string | undefined;
187
- enabled?: boolean | undefined;
188
- spec?: {
189
- type: TriggerKind.Timer;
190
- cron: string;
191
- } | {
192
- type: TriggerKind.Webhook;
193
- method?: string | undefined;
194
- port?: number | undefined;
195
- } | {
196
- filter: {
197
- readonly type?: string | undefined;
198
- readonly props?: {
199
- readonly [x: string]: any;
200
- } | undefined;
201
- };
202
- type: TriggerKind.Subscription;
203
- options?: {
204
- readonly deep?: boolean | undefined;
205
- readonly delay?: number | undefined;
206
- } | undefined;
207
- } | undefined;
208
- meta?: {
209
- [x: string]: any;
210
- } | undefined;
211
- } & {
212
- id: string;
213
- }> & import("@dxos/echo-schema").WithMeta, S.Struct.Encoded<{
188
+ triggers: S.optional<S.mutable<S.Array$<S.Schema<import("@dxos/echo-schema").ExcludeId<import("packages/core/echo/echo-schema/dist/types/src/object/common").TypedObjectFields<{
189
+ readonly function: S.optional<S.SchemaClass<string, string, never>>;
190
+ readonly enabled: S.optional<S.SchemaClass<boolean, boolean, never>>;
191
+ readonly spec: S.optional<S.Union<[S.mutable<S.Struct<{
192
+ type: S.Literal<[TriggerKind.Timer]>;
193
+ cron: S.SchemaClass<string, string, never>;
194
+ }>>, S.mutable<S.Struct<{
195
+ type: S.Literal<[TriggerKind.Webhook]>;
196
+ method: S.optional<S.SchemaClass<string, string, never>>;
197
+ port: S.optional<S.SchemaClass<number, number, never>>;
198
+ }>>, S.mutable<S.Struct<{
199
+ type: S.Literal<[TriggerKind.Subscription]>;
200
+ filter: S.Struct<{
201
+ type: S.optional<S.SchemaClass<string, string, never>>;
202
+ props: S.optional<S.Record$<typeof S.String, typeof S.Any>>;
203
+ }>;
204
+ options: S.optional<S.Struct<{
205
+ deep: S.optional<S.SchemaClass<boolean, boolean, never>>;
206
+ delay: S.optional<S.SchemaClass<number, number, never>>;
207
+ }>>;
208
+ }>>, S.mutable<S.Struct<{
209
+ type: S.Literal<[TriggerKind.Email]>;
210
+ }>>]>>;
211
+ readonly meta: S.optional<S.mutable<S.Record$<typeof S.String, typeof S.Any>>>;
212
+ }, import("packages/core/echo/echo-schema/dist/types/src/object/common").TypedObjectOptions>> & import("@dxos/echo-schema").WithMeta, S.Struct.Encoded<{
214
213
  readonly function: S.optional<S.SchemaClass<string, string, never>>;
215
214
  readonly enabled: S.optional<S.SchemaClass<boolean, boolean, never>>;
216
215
  readonly spec: S.optional<S.Union<[S.mutable<S.Struct<{
@@ -230,6 +229,8 @@ export declare const FunctionManifestSchema: S.Struct<{
230
229
  deep: S.optional<S.SchemaClass<boolean, boolean, never>>;
231
230
  delay: S.optional<S.SchemaClass<number, number, never>>;
232
231
  }>>;
232
+ }>>, S.mutable<S.Struct<{
233
+ type: S.Literal<[TriggerKind.Email]>;
233
234
  }>>]>>;
234
235
  readonly meta: S.optional<S.mutable<S.Record$<typeof S.String, typeof S.Any>>>;
235
236
  }>, never>>>>;
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/types/types.ts"],"names":[],"mappings":"AAIA,OAAO,EAAuC,CAAC,EAAe,MAAM,mBAAmB,CAAC;AAExF;;;;GAIG;AACH,oBAAY,WAAW;IACrB,KAAK,UAAU;IACf,OAAO,YAAY;IACnB,YAAY,iBAAiB;IAC7B,KAAK,UAAU;CAChB;AAKD;;GAEG;AACH,QAAA,MAAM,kBAAkB;;;GAMN,CAAC;AAEnB,MAAM,MAAM,YAAY,GAAG,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,kBAAkB,CAAC,CAAC;AAEpE,QAAA,MAAM,kBAAkB;;GAEN,CAAC;AAEnB,MAAM,MAAM,YAAY,GAAG,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,kBAAkB,CAAC,CAAC;AAEpE;;GAEG;AACH,QAAA,MAAM,oBAAoB;;;;GAaR,CAAC;AAEnB,MAAM,MAAM,cAAc,GAAG,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,oBAAoB,CAAC,CAAC;AAQxE;;GAEG;AACH,QAAA,MAAM,yBAAyB;;;;;;;;;;GAYb,CAAC;AAEnB,MAAM,MAAM,mBAAmB,GAAG,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,yBAAyB,CAAC,CAAC;AAElF;;GAEG;AACH,eAAO,MAAM,aAAa;;;;;;;;;;;;;;;;;;;KAQxB,CAAC;AAEH,MAAM,MAAM,WAAW,GAAG,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,aAAa,CAAC,CAAC;AAE9D;;GAEG;AACH,eAAO,MAAM,qBAAqB;;;;;;;;;;;;;;;;;;;;;;;;EAYhC,CAAC;AAEH,MAAM,MAAM,mBAAmB,GAAG,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,qBAAqB,CAAC,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAE9E;;GAEG;AACH,qBAAa,eAAgB,SAAQ,oBAGL;CAAG;;;;;;;;;;;;AAEnC;;;GAGG;AAEH,qBAAa,WAAY,SAAQ,gBAQ/B;CAAG;AAEL;;GAEG;AACH,eAAO,MAAM,sBAAsB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAGjC,CAAC;AAEH,MAAM,MAAM,gBAAgB,GAAG,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,sBAAsB,CAAC,CAAC;AAE5E,eAAO,MAAM,cAAc,iDAAiC,CAAC"}
@@ -0,0 +1 @@
1
+ {"version":"5.7.3"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dxos/functions",
3
- "version": "0.7.4",
3
+ "version": "0.7.5-labs.071a3e2",
4
4
  "description": "Functions API and runtime.",
5
5
  "homepage": "https://dxos.org",
6
6
  "bugs": "https://github.com/dxos/dxos/issues",
@@ -13,15 +13,20 @@
13
13
  "browser": "./dist/lib/browser/index.mjs",
14
14
  "node": "./dist/lib/node-esm/index.mjs"
15
15
  },
16
+ "./edge": {
17
+ "types": "./dist/types/src/edge/index.d.ts",
18
+ "browser": "./dist/lib/browser/edge/index.mjs",
19
+ "node": "./dist/lib/node-esm/edge/index.mjs"
20
+ },
16
21
  "./testing": {
17
22
  "types": "./dist/types/src/testing/index.d.ts",
18
23
  "browser": "./dist/lib/browser/testing/index.mjs",
19
24
  "node": "./dist/lib/node-esm/testing/index.mjs"
20
25
  },
21
26
  "./types": {
22
- "types": "./dist/types/src/types.d.ts",
23
- "browser": "./dist/lib/browser/types.mjs",
24
- "node": "./dist/lib/node-esm/types.mjs"
27
+ "types": "./dist/types/src/types/index.d.ts",
28
+ "browser": "./dist/lib/browser/types/index.mjs",
29
+ "node": "./dist/lib/node-esm/types/index.mjs"
25
30
  }
26
31
  },
27
32
  "types": "dist/types/src/index.d.ts",
@@ -44,29 +49,31 @@
44
49
  "@effect/schema": "^0.75.5",
45
50
  "@preact/signals-core": "^1.6.0",
46
51
  "cron": "^3.1.6",
47
- "effect": "^3.9.2",
52
+ "effect": "^3.12.3",
48
53
  "express": "^4.19.2",
49
54
  "get-port-please": "^3.1.1",
55
+ "iso-did": "^1.6.0",
50
56
  "ws": "^8.14.2",
51
- "@dxos/async": "0.7.4",
52
- "@dxos/client": "0.7.4",
53
- "@dxos/context": "0.7.4",
54
- "@dxos/echo-db": "0.7.4",
55
- "@dxos/echo-protocol": "0.7.4",
56
- "@dxos/invariant": "0.7.4",
57
- "@dxos/echo-schema": "0.7.4",
58
- "@dxos/keys": "0.7.4",
59
- "@dxos/log": "0.7.4",
60
- "@dxos/live-object": "0.7.4",
61
- "@dxos/protocols": "0.7.4",
62
- "@dxos/schema": "0.7.4",
63
- "@dxos/util": "0.7.4",
64
- "@dxos/node-std": "0.7.4"
57
+ "@dxos/async": "0.7.5-labs.071a3e2",
58
+ "@dxos/context": "0.7.5-labs.071a3e2",
59
+ "@dxos/client": "0.7.5-labs.071a3e2",
60
+ "@dxos/echo-db": "0.7.5-labs.071a3e2",
61
+ "@dxos/echo-schema": "0.7.5-labs.071a3e2",
62
+ "@dxos/edge-client": "0.7.5-labs.071a3e2",
63
+ "@dxos/invariant": "0.7.5-labs.071a3e2",
64
+ "@dxos/echo-protocol": "0.7.5-labs.071a3e2",
65
+ "@dxos/keys": "0.7.5-labs.071a3e2",
66
+ "@dxos/log": "0.7.5-labs.071a3e2",
67
+ "@dxos/live-object": "0.7.5-labs.071a3e2",
68
+ "@dxos/node-std": "0.7.5-labs.071a3e2",
69
+ "@dxos/protocols": "0.7.5-labs.071a3e2",
70
+ "@dxos/schema": "0.7.5-labs.071a3e2",
71
+ "@dxos/util": "0.7.5-labs.071a3e2"
65
72
  },
66
73
  "devDependencies": {
67
74
  "@types/express": "^4.17.17",
68
75
  "@types/ws": "^7.4.0",
69
- "@dxos/agent": "0.7.4"
76
+ "@dxos/agent": "0.7.5-labs.071a3e2"
70
77
  },
71
78
  "publishConfig": {
72
79
  "access": "public"
@@ -0,0 +1,120 @@
1
+ //
2
+ // Copyright 2024 DXOS.org
3
+ //
4
+
5
+ import { type DID } from 'iso-did/types';
6
+
7
+ import { type Client } from '@dxos/client';
8
+ import { type ObjectMeta } from '@dxos/echo-schema';
9
+ import { EdgeHttpClient, type EdgeIdentity } from '@dxos/edge-client';
10
+ import { invariant } from '@dxos/invariant';
11
+ import type { PublicKey, SpaceId } from '@dxos/keys';
12
+ import { log } from '@dxos/log';
13
+ import { type UploadFunctionResponseBody } from '@dxos/protocols';
14
+
15
+ // TODO: use URL scheme for source?
16
+ const FUNCTIONS_META_KEY = 'dxos.org/service/function';
17
+
18
+ export const FUNCTIONS_PRESET_META_KEY = 'dxos.org/service/function-preset';
19
+
20
+ export type UploadWorkerArgs = {
21
+ client: Client;
22
+ name?: string;
23
+ source: string;
24
+ version: string;
25
+ functionId?: string;
26
+ spaceId: SpaceId;
27
+ };
28
+
29
+ export const uploadWorkerFunction = async ({
30
+ client,
31
+ name,
32
+ version,
33
+ source,
34
+ spaceId,
35
+ functionId,
36
+ }: UploadWorkerArgs): Promise<UploadFunctionResponseBody> => {
37
+ const edgeUrl = client.config.values.runtime?.services?.edge?.url;
38
+ invariant(edgeUrl, 'Edge is not configured.');
39
+ const edgeClient = new EdgeHttpClient(edgeUrl);
40
+ const edgeIdentity = createEdgeIdentity(client);
41
+ edgeClient.setIdentity(edgeIdentity);
42
+ const response = await edgeClient.uploadFunction({ spaceId, functionId }, { name, version, script: source });
43
+
44
+ log('Uploaded', {
45
+ functionId,
46
+ source,
47
+ name,
48
+ identityKey: edgeIdentity.identityKey,
49
+ response,
50
+ });
51
+
52
+ return response;
53
+ };
54
+
55
+ export const getUserFunctionUrlInMetadata = (meta: ObjectMeta) => {
56
+ return meta.keys.find((key) => key.source === FUNCTIONS_META_KEY)?.id;
57
+ };
58
+
59
+ export const setUserFunctionUrlInMetadata = (meta: ObjectMeta, functionUrl: string) => {
60
+ const key = meta.keys.find((key) => key.source === FUNCTIONS_META_KEY);
61
+ if (key) {
62
+ if (key.id !== functionUrl) {
63
+ throw new Error('Metadata mismatch');
64
+ }
65
+ } else {
66
+ meta.keys.push({ source: FUNCTIONS_META_KEY, id: functionUrl });
67
+ }
68
+ };
69
+
70
+ export const getInvocationUrl = (functionUrl: string, edgeUrl: string, options: InvocationOptions = {}) => {
71
+ const baseUrl = new URL('functions/', edgeUrl);
72
+
73
+ // Leading slashes cause the URL to be treated as an absolute path.
74
+ const relativeUrl = functionUrl.replace(/^\//, '');
75
+ const url = new URL(`./${relativeUrl}`, baseUrl.toString());
76
+ options.spaceId && url.searchParams.set('spaceId', options.spaceId);
77
+ options.subjectId && url.searchParams.set('subjectId', options.subjectId);
78
+ url.protocol = isSecure(url.protocol) ? 'https' : 'http';
79
+ return url.toString();
80
+ };
81
+
82
+ const isSecure = (protocol: string) => {
83
+ return protocol === 'https:' || protocol === 'wss:';
84
+ };
85
+
86
+ const createEdgeIdentity = (client: Client): EdgeIdentity => {
87
+ const identity = client.halo.identity.get();
88
+ const device = client.halo.device;
89
+ if (!identity || !device) {
90
+ throw new Error('Identity not available');
91
+ }
92
+ return {
93
+ identityKey: identity.identityKey.toHex(),
94
+ peerKey: device.deviceKey.toHex(),
95
+ presentCredentials: async ({ challenge }) => {
96
+ const identityService = client.services.services.IdentityService!;
97
+ const authCredential = await identityService.createAuthCredential();
98
+ return identityService.signPresentation({
99
+ presentation: { credentials: [authCredential] },
100
+ nonce: challenge,
101
+ });
102
+ },
103
+ };
104
+ };
105
+
106
+ export const incrementSemverPatch = (version: string): string => {
107
+ const [major, minor, patch] = version.split('.');
108
+ const patchNum = Number(patch);
109
+ invariant(!Number.isNaN(patchNum), 'Unexpected function version format.');
110
+ return [major, minor, String(patchNum + 1)].join('.');
111
+ };
112
+
113
+ export const publicKeyToDid = (key: PublicKey): DID => {
114
+ return `did:key:${key.toHex()}`;
115
+ };
116
+
117
+ export type InvocationOptions = {
118
+ spaceId?: SpaceId;
119
+ subjectId?: string;
120
+ };
@@ -0,0 +1,5 @@
1
+ //
2
+ // Copyright 2024 DXOS.org
3
+ //
4
+
5
+ export * from './functions';
package/src/handler.ts CHANGED
@@ -61,6 +61,7 @@ export interface FunctionContextAi {
61
61
  /**
62
62
  * Event payload.
63
63
  */
64
+ // TODO(dmaretskyi): Update type definitions to match the actual payload.
64
65
  export type FunctionEvent<TData = {}, TMeta = {}> = {
65
66
  data: FunctionEventMeta<TMeta> & TData;
66
67
  };
package/src/index.ts CHANGED
@@ -2,6 +2,7 @@
2
2
  // Copyright 2023 DXOS.org
3
3
  //
4
4
 
5
+ export * from './edge';
5
6
  export * from './function';
6
7
  export * from './handler';
7
8
  // export * from './runtime';
@@ -0,0 +1,15 @@
1
+ //
2
+ // Copyright 2023 DXOS.org
3
+ //
4
+
5
+ import { ScriptType } from './types';
6
+
7
+ export default [
8
+ {
9
+ 'en-US': {
10
+ [ScriptType.typename]: {
11
+ 'typename label': 'Script',
12
+ },
13
+ },
14
+ },
15
+ ];
@@ -236,7 +236,9 @@ describe('trigger registry', () => {
236
236
  const triggers = createTriggers(space, 3);
237
237
 
238
238
  const triggerLoaded = new Trigger();
239
- registry.registered.on((fn) => triggerLoaded.wake());
239
+ registry.registered.on(() => {
240
+ triggerLoaded.wake();
241
+ });
240
242
 
241
243
  const triggerRemoved = new Trigger<FunctionTrigger>();
242
244
  registry.removed.on((fn) => {
@@ -0,0 +1,6 @@
1
+ //
2
+ // Copyright 2024 DXOS.org
3
+ //
4
+
5
+ export * from './schema';
6
+ export * from './types';
@@ -0,0 +1,46 @@
1
+ //
2
+ // Copyright 2024 DXOS.org
3
+ //
4
+
5
+ import { JsonSchemaType, Ref, S, TypedObject } from '@dxos/echo-schema';
6
+ import { TextType } from '@dxos/schema';
7
+
8
+ /**
9
+ * Source script.
10
+ */
11
+ export class ScriptType extends TypedObject({
12
+ typename: 'dxos.org/type/Script',
13
+ version: '0.1.0',
14
+ })({
15
+ // TODO(burdon): Change to URI?
16
+ name: S.optional(S.String),
17
+ description: S.optional(S.String),
18
+ // TODO(burdon): Change to hash of deployed content.
19
+ // Whether source has changed since last deploy.
20
+ changed: S.optional(S.Boolean),
21
+ source: Ref(TextType),
22
+ }) {}
23
+
24
+ /**
25
+ * Function deployment.
26
+ */
27
+ // TODO(burdon): Move to core/functions.
28
+ export class FunctionType extends TypedObject({
29
+ typename: 'dxos.org/type/Function',
30
+ version: '0.1.0',
31
+ })({
32
+ // TODO(burdon): Rename to id/uri?
33
+ name: S.NonEmptyString,
34
+ version: S.String,
35
+
36
+ description: S.optional(S.String),
37
+
38
+ // Reference to a source script if it exists within ECHO.
39
+ // TODO(burdon): Don't ref ScriptType directly (core).
40
+ source: S.optional(Ref(ScriptType)),
41
+
42
+ inputSchema: S.optional(JsonSchemaType),
43
+
44
+ // Local binding to a function name.
45
+ binding: S.optional(S.String),
46
+ }) {}
@@ -13,6 +13,7 @@ export enum TriggerKind {
13
13
  Timer = 'timer',
14
14
  Webhook = 'webhook',
15
15
  Subscription = 'subscription',
16
+ Email = 'email',
16
17
  }
17
18
 
18
19
  // TODO(burdon): Rename prop kind.
@@ -31,6 +32,12 @@ const TimerTriggerSchema = S.Struct({
31
32
 
32
33
  export type TimerTrigger = S.Schema.Type<typeof TimerTriggerSchema>;
33
34
 
35
+ const EmailTriggerSchema = S.Struct({
36
+ type: S.Literal(TriggerKind.Email).annotations(typeLiteralAnnotations),
37
+ }).pipe(S.mutable);
38
+
39
+ export type EmailTrigger = S.Schema.Type<typeof EmailTriggerSchema>;
40
+
34
41
  /**
35
42
  * Webhook.
36
43
  */
@@ -84,6 +91,7 @@ export const TriggerSchema = S.Union(
84
91
  TimerTriggerSchema,
85
92
  WebhookTriggerSchema,
86
93
  SubscriptionTriggerSchema,
94
+ EmailTriggerSchema,
87
95
  ).annotations({
88
96
  [AST.TitleAnnotationId]: 'Trigger',
89
97
  });