@dxos/functions 0.8.2-main.12df754 → 0.8.2-main.2f9c567

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 (168) hide show
  1. package/dist/lib/browser/bundler/index.mjs +0 -3
  2. package/dist/lib/browser/bundler/index.mjs.map +1 -1
  3. package/dist/lib/browser/edge/index.mjs +63 -7
  4. package/dist/lib/browser/edge/index.mjs.map +4 -4
  5. package/dist/lib/browser/index.mjs +367 -99
  6. package/dist/lib/browser/index.mjs.map +4 -4
  7. package/dist/lib/browser/meta.json +1 -1
  8. package/dist/lib/node/bundler/index.cjs +0 -1
  9. package/dist/lib/node/bundler/index.cjs.map +1 -1
  10. package/dist/lib/node/edge/index.cjs +65 -5
  11. package/dist/lib/node/edge/index.cjs.map +4 -4
  12. package/dist/lib/node/index.cjs +382 -94
  13. package/dist/lib/node/index.cjs.map +4 -4
  14. package/dist/lib/node/meta.json +1 -1
  15. package/dist/lib/node-esm/bundler/index.mjs +0 -1
  16. package/dist/lib/node-esm/bundler/index.mjs.map +1 -1
  17. package/dist/lib/node-esm/edge/index.mjs +64 -6
  18. package/dist/lib/node-esm/edge/index.mjs.map +4 -4
  19. package/dist/lib/node-esm/index.mjs +367 -97
  20. package/dist/lib/node-esm/index.mjs.map +4 -4
  21. package/dist/lib/node-esm/meta.json +1 -1
  22. package/dist/types/src/edge/index.d.ts.map +1 -1
  23. package/dist/types/src/handler.d.ts +12 -61
  24. package/dist/types/src/handler.d.ts.map +1 -1
  25. package/dist/types/src/index.d.ts +3 -3
  26. package/dist/types/src/index.d.ts.map +1 -1
  27. package/dist/types/src/schema.d.ts +57 -0
  28. package/dist/types/src/schema.d.ts.map +1 -0
  29. package/dist/types/src/trace.d.ts +148 -0
  30. package/dist/types/src/trace.d.ts.map +1 -0
  31. package/dist/types/src/{types/types.d.ts → types.d.ts} +191 -49
  32. package/dist/types/src/types.d.ts.map +1 -0
  33. package/dist/types/src/url.d.ts.map +1 -0
  34. package/package.json +20 -36
  35. package/src/edge/index.ts +4 -0
  36. package/src/handler.ts +14 -118
  37. package/src/index.ts +4 -5
  38. package/src/schema.ts +53 -0
  39. package/src/{types/trace.ts → trace.ts} +33 -31
  40. package/src/translations.ts +1 -1
  41. package/src/types.ts +214 -0
  42. package/dist/lib/browser/chunk-2YE6S7XY.mjs +0 -360
  43. package/dist/lib/browser/chunk-2YE6S7XY.mjs.map +0 -7
  44. package/dist/lib/browser/chunk-7CHDHCV3.mjs +0 -482
  45. package/dist/lib/browser/chunk-7CHDHCV3.mjs.map +0 -7
  46. package/dist/lib/browser/chunk-LT4LR4VU.mjs +0 -72
  47. package/dist/lib/browser/chunk-LT4LR4VU.mjs.map +0 -7
  48. package/dist/lib/browser/chunk-XRCXIG74.mjs +0 -12
  49. package/dist/lib/browser/chunk-XRCXIG74.mjs.map +0 -7
  50. package/dist/lib/browser/testing/index.mjs +0 -670
  51. package/dist/lib/browser/testing/index.mjs.map +0 -7
  52. package/dist/lib/browser/types/index.mjs +0 -51
  53. package/dist/lib/browser/types/index.mjs.map +0 -7
  54. package/dist/lib/node/chunk-FBIUZ7SD.cjs +0 -496
  55. package/dist/lib/node/chunk-FBIUZ7SD.cjs.map +0 -7
  56. package/dist/lib/node/chunk-JEQ2X3Z6.cjs +0 -34
  57. package/dist/lib/node/chunk-JEQ2X3Z6.cjs.map +0 -7
  58. package/dist/lib/node/chunk-NXZNXVT3.cjs +0 -94
  59. package/dist/lib/node/chunk-NXZNXVT3.cjs.map +0 -7
  60. package/dist/lib/node/chunk-SV5NRE5L.cjs +0 -395
  61. package/dist/lib/node/chunk-SV5NRE5L.cjs.map +0 -7
  62. package/dist/lib/node/testing/index.cjs +0 -687
  63. package/dist/lib/node/testing/index.cjs.map +0 -7
  64. package/dist/lib/node/types/index.cjs +0 -72
  65. package/dist/lib/node/types/index.cjs.map +0 -7
  66. package/dist/lib/node-esm/chunk-3XMJFSID.mjs +0 -360
  67. package/dist/lib/node-esm/chunk-3XMJFSID.mjs.map +0 -7
  68. package/dist/lib/node-esm/chunk-C6YINTWG.mjs +0 -482
  69. package/dist/lib/node-esm/chunk-C6YINTWG.mjs.map +0 -7
  70. package/dist/lib/node-esm/chunk-DHGBFXSZ.mjs +0 -12
  71. package/dist/lib/node-esm/chunk-DHGBFXSZ.mjs.map +0 -7
  72. package/dist/lib/node-esm/chunk-O2SXVYU5.mjs +0 -72
  73. package/dist/lib/node-esm/chunk-O2SXVYU5.mjs.map +0 -7
  74. package/dist/lib/node-esm/testing/index.mjs +0 -670
  75. package/dist/lib/node-esm/testing/index.mjs.map +0 -7
  76. package/dist/lib/node-esm/types/index.mjs +0 -51
  77. package/dist/lib/node-esm/types/index.mjs.map +0 -7
  78. package/dist/types/src/browser/index.d.ts +0 -2
  79. package/dist/types/src/browser/index.d.ts.map +0 -1
  80. package/dist/types/src/function/function-registry.d.ts +0 -25
  81. package/dist/types/src/function/function-registry.d.ts.map +0 -1
  82. package/dist/types/src/function/function-registry.test.d.ts +0 -2
  83. package/dist/types/src/function/function-registry.test.d.ts.map +0 -1
  84. package/dist/types/src/function/index.d.ts +0 -2
  85. package/dist/types/src/function/index.d.ts.map +0 -1
  86. package/dist/types/src/runtime/dev-server.d.ts +0 -52
  87. package/dist/types/src/runtime/dev-server.d.ts.map +0 -1
  88. package/dist/types/src/runtime/dev-server.test.d.ts +0 -2
  89. package/dist/types/src/runtime/dev-server.test.d.ts.map +0 -1
  90. package/dist/types/src/runtime/index.d.ts +0 -3
  91. package/dist/types/src/runtime/index.d.ts.map +0 -1
  92. package/dist/types/src/runtime/scheduler.d.ts +0 -34
  93. package/dist/types/src/runtime/scheduler.d.ts.map +0 -1
  94. package/dist/types/src/runtime/scheduler.test.d.ts +0 -2
  95. package/dist/types/src/runtime/scheduler.test.d.ts.map +0 -1
  96. package/dist/types/src/testing/functions-integration.test.d.ts +0 -2
  97. package/dist/types/src/testing/functions-integration.test.d.ts.map +0 -1
  98. package/dist/types/src/testing/index.d.ts +0 -5
  99. package/dist/types/src/testing/index.d.ts.map +0 -1
  100. package/dist/types/src/testing/manifest.d.ts +0 -3
  101. package/dist/types/src/testing/manifest.d.ts.map +0 -1
  102. package/dist/types/src/testing/plugin-init.d.ts +0 -6
  103. package/dist/types/src/testing/plugin-init.d.ts.map +0 -1
  104. package/dist/types/src/testing/setup.d.ts +0 -15
  105. package/dist/types/src/testing/setup.d.ts.map +0 -1
  106. package/dist/types/src/testing/test/handler.d.ts +0 -4
  107. package/dist/types/src/testing/test/handler.d.ts.map +0 -1
  108. package/dist/types/src/testing/test/index.d.ts +0 -3
  109. package/dist/types/src/testing/test/index.d.ts.map +0 -1
  110. package/dist/types/src/testing/types.d.ts +0 -10
  111. package/dist/types/src/testing/types.d.ts.map +0 -1
  112. package/dist/types/src/testing/util.d.ts +0 -5
  113. package/dist/types/src/testing/util.d.ts.map +0 -1
  114. package/dist/types/src/trigger/index.d.ts +0 -3
  115. package/dist/types/src/trigger/index.d.ts.map +0 -1
  116. package/dist/types/src/trigger/trigger-registry.d.ts +0 -38
  117. package/dist/types/src/trigger/trigger-registry.d.ts.map +0 -1
  118. package/dist/types/src/trigger/trigger-registry.test.d.ts +0 -2
  119. package/dist/types/src/trigger/trigger-registry.test.d.ts.map +0 -1
  120. package/dist/types/src/trigger/type/index.d.ts +0 -3
  121. package/dist/types/src/trigger/type/index.d.ts.map +0 -1
  122. package/dist/types/src/trigger/type/subscription-trigger.d.ts +0 -4
  123. package/dist/types/src/trigger/type/subscription-trigger.d.ts.map +0 -1
  124. package/dist/types/src/trigger/type/timer-trigger.d.ts +0 -4
  125. package/dist/types/src/trigger/type/timer-trigger.d.ts.map +0 -1
  126. package/dist/types/src/trigger/type/webhook-trigger.d.ts +0 -4
  127. package/dist/types/src/trigger/type/webhook-trigger.d.ts.map +0 -1
  128. package/dist/types/src/types/index.d.ts +0 -5
  129. package/dist/types/src/types/index.d.ts.map +0 -1
  130. package/dist/types/src/types/schema.d.ts +0 -53
  131. package/dist/types/src/types/schema.d.ts.map +0 -1
  132. package/dist/types/src/types/trace.d.ts +0 -146
  133. package/dist/types/src/types/trace.d.ts.map +0 -1
  134. package/dist/types/src/types/types.d.ts.map +0 -1
  135. package/dist/types/src/types/url.d.ts.map +0 -1
  136. package/dist/types/tools/schema.d.ts +0 -2
  137. package/dist/types/tools/schema.d.ts.map +0 -1
  138. package/schema/functions.json +0 -211
  139. package/src/browser/index.ts +0 -5
  140. package/src/function/function-registry.test.ts +0 -118
  141. package/src/function/function-registry.ts +0 -104
  142. package/src/function/index.ts +0 -5
  143. package/src/runtime/dev-server.test.ts +0 -79
  144. package/src/runtime/dev-server.ts +0 -240
  145. package/src/runtime/index.ts +0 -6
  146. package/src/runtime/scheduler.test.ts +0 -152
  147. package/src/runtime/scheduler.ts +0 -170
  148. package/src/testing/functions-integration.test.ts +0 -65
  149. package/src/testing/index.ts +0 -8
  150. package/src/testing/manifest.ts +0 -15
  151. package/src/testing/plugin-init.ts +0 -20
  152. package/src/testing/setup.ts +0 -109
  153. package/src/testing/test/handler.ts +0 -15
  154. package/src/testing/test/index.ts +0 -7
  155. package/src/testing/types.ts +0 -9
  156. package/src/testing/util.ts +0 -26
  157. package/src/trigger/index.ts +0 -6
  158. package/src/trigger/trigger-registry.test.ts +0 -278
  159. package/src/trigger/trigger-registry.ts +0 -218
  160. package/src/trigger/type/index.ts +0 -7
  161. package/src/trigger/type/subscription-trigger.ts +0 -84
  162. package/src/trigger/type/timer-trigger.ts +0 -48
  163. package/src/trigger/type/webhook-trigger.ts +0 -48
  164. package/src/types/index.ts +0 -8
  165. package/src/types/schema.ts +0 -46
  166. package/src/types/types.ts +0 -163
  167. /package/dist/types/src/{types/url.d.ts → url.d.ts} +0 -0
  168. /package/src/{types/url.ts → url.ts} +0 -0
@@ -1,4 +1,6 @@
1
- import { S } from '@dxos/echo-schema';
1
+ import { Schema as S } from 'effect';
2
+ import { Expando, Ref } from '@dxos/echo-schema';
3
+ import { FunctionType } from './schema';
2
4
  /**
3
5
  * Type discriminator for TriggerType.
4
6
  * Every spec has a type field of type TriggerKind that we can use to understand which type we're working with.
@@ -79,11 +81,53 @@ export declare const TriggerSchema: S.Union<[S.mutable<S.Struct<{
79
81
  queue: S.refine<string, typeof S.NonEmptyString>;
80
82
  }>>]>;
81
83
  export type TriggerType = S.Schema.Type<typeof TriggerSchema>;
84
+ export type EventType = EmailTriggerOutput | WebhookTriggerOutput | QueueTriggerOutput | SubscriptionTriggerOutput | TimerTriggerOutput;
85
+ export declare const EmailTriggerOutput: S.mutable<S.Struct<{
86
+ from: typeof S.String;
87
+ to: typeof S.String;
88
+ subject: typeof S.String;
89
+ created: typeof S.String;
90
+ body: typeof S.String;
91
+ }>>;
92
+ export type EmailTriggerOutput = S.Schema.Type<typeof EmailTriggerOutput>;
93
+ export declare const WebhookTriggerOutput: S.mutable<S.Struct<{
94
+ url: typeof S.String;
95
+ method: S.Literal<["GET", "POST"]>;
96
+ headers: S.Record$<typeof S.String, typeof S.String>;
97
+ bodyText: typeof S.String;
98
+ }>>;
99
+ export type WebhookTriggerOutput = S.Schema.Type<typeof WebhookTriggerOutput>;
100
+ export declare const QueueTriggerOutput: S.mutable<S.Struct<{
101
+ queue: S.refine<string, typeof S.NonEmptyString>;
102
+ item: typeof S.Any;
103
+ cursor: typeof S.String;
104
+ }>>;
105
+ export type QueueTriggerOutput = S.Schema.Type<typeof QueueTriggerOutput>;
106
+ export declare const SubscriptionTriggerOutput: S.mutable<S.Struct<{
107
+ type: typeof S.String;
108
+ changedObjectId: typeof S.String;
109
+ }>>;
110
+ export type SubscriptionTriggerOutput = S.Schema.Type<typeof SubscriptionTriggerOutput>;
111
+ export declare const TimerTriggerOutput: S.mutable<S.Struct<{
112
+ tick: typeof S.Number;
113
+ }>>;
114
+ export type TimerTriggerOutput = S.Schema.Type<typeof TimerTriggerOutput>;
82
115
  /**
83
116
  * Function trigger.
117
+ * Function is invoked with the `payload` passed as input data.
118
+ * The event that triggers the function is available in the function context.
84
119
  */
85
120
  export declare const FunctionTriggerSchema: S.Struct<{
86
- function: S.optional<S.SchemaClass<string, string, never>>;
121
+ /**
122
+ * Function or workflow to invoke.
123
+ */
124
+ function: S.optional<S.SchemaClass<Ref<Expando>, import("@dxos/echo-protocol").EncodedReference, never>>;
125
+ /**
126
+ * Only used for workflows.
127
+ * Specifies the input node in the circuit.
128
+ * @deprecated Remove and enforce a single input node in all compute graphs.
129
+ */
130
+ inputNodeId: S.optional<S.SchemaClass<string, string, never>>;
87
131
  enabled: S.optional<S.SchemaClass<boolean, boolean, never>>;
88
132
  spec: S.optional<S.Union<[S.mutable<S.Struct<{
89
133
  type: S.Literal<[TriggerKind.Timer]>;
@@ -108,13 +152,33 @@ export declare const FunctionTriggerSchema: S.Struct<{
108
152
  type: S.Literal<[TriggerKind.Queue]>;
109
153
  queue: S.refine<string, typeof S.NonEmptyString>;
110
154
  }>>]>>;
111
- meta: S.optional<S.mutable<S.Record$<typeof S.String, typeof S.Any>>>;
155
+ /**
156
+ * Passed as the input data to the function.
157
+ * Must match the function's input schema.
158
+ *
159
+ * @example
160
+ * {
161
+ * item: '{{$.trigger.event}}',
162
+ * instructions: 'Summarize and perform entity-extraction'
163
+ * mailbox: { '/': 'dxn:echo:AAA:ZZZ' }
164
+ * }
165
+ */
166
+ input: S.optional<S.mutable<S.Record$<typeof S.String, typeof S.Any>>>;
112
167
  }>;
113
168
  export type FunctionTriggerType = S.Schema.Type<typeof FunctionTriggerSchema>;
114
- declare const FunctionTrigger_base: import("@dxos/echo-schema").TypedObjectPrototype<import("@dxos/echo-schema").TypedObjectFields<{
115
- readonly function: S.optional<S.SchemaClass<string, string, never>>;
116
- readonly enabled: S.optional<S.SchemaClass<boolean, boolean, never>>;
117
- readonly spec: S.optional<S.Union<[S.mutable<S.Struct<{
169
+ declare const FunctionTrigger_base: import("@dxos/echo-schema").TypedObjectPrototype<import("@dxos/echo-schema").TypedObjectFields<Readonly<{
170
+ /**
171
+ * Function or workflow to invoke.
172
+ */
173
+ function: S.optional<S.SchemaClass<Ref<Expando>, import("@dxos/echo-protocol").EncodedReference, never>>;
174
+ /**
175
+ * Only used for workflows.
176
+ * Specifies the input node in the circuit.
177
+ * @deprecated Remove and enforce a single input node in all compute graphs.
178
+ */
179
+ inputNodeId: S.optional<S.SchemaClass<string, string, never>>;
180
+ enabled: S.optional<S.SchemaClass<boolean, boolean, never>>;
181
+ spec: S.optional<S.Union<[S.mutable<S.Struct<{
118
182
  type: S.Literal<[TriggerKind.Timer]>;
119
183
  cron: S.SchemaClass<string, string, never>;
120
184
  }>>, S.mutable<S.Struct<{
@@ -137,11 +201,31 @@ declare const FunctionTrigger_base: import("@dxos/echo-schema").TypedObjectProto
137
201
  type: S.Literal<[TriggerKind.Queue]>;
138
202
  queue: S.refine<string, typeof S.NonEmptyString>;
139
203
  }>>]>>;
140
- readonly meta: S.optional<S.mutable<S.Record$<typeof S.String, typeof S.Any>>>;
141
- }, import("@dxos/echo-schema").TypedObjectOptions>, S.Struct.Encoded<{
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<{
204
+ /**
205
+ * Passed as the input data to the function.
206
+ * Must match the function's input schema.
207
+ *
208
+ * @example
209
+ * {
210
+ * item: '{{$.trigger.event}}',
211
+ * instructions: 'Summarize and perform entity-extraction'
212
+ * mailbox: { '/': 'dxn:echo:AAA:ZZZ' }
213
+ * }
214
+ */
215
+ input: S.optional<S.mutable<S.Record$<typeof S.String, typeof S.Any>>>;
216
+ }>, import("@dxos/echo-schema").TypedObjectOptions>, S.Struct.Encoded<Readonly<{
217
+ /**
218
+ * Function or workflow to invoke.
219
+ */
220
+ function: S.optional<S.SchemaClass<Ref<Expando>, import("@dxos/echo-protocol").EncodedReference, never>>;
221
+ /**
222
+ * Only used for workflows.
223
+ * Specifies the input node in the circuit.
224
+ * @deprecated Remove and enforce a single input node in all compute graphs.
225
+ */
226
+ inputNodeId: S.optional<S.SchemaClass<string, string, never>>;
227
+ enabled: S.optional<S.SchemaClass<boolean, boolean, never>>;
228
+ spec: S.optional<S.Union<[S.mutable<S.Struct<{
145
229
  type: S.Literal<[TriggerKind.Timer]>;
146
230
  cron: S.SchemaClass<string, string, never>;
147
231
  }>>, S.mutable<S.Struct<{
@@ -164,49 +248,76 @@ declare const FunctionTrigger_base: import("@dxos/echo-schema").TypedObjectProto
164
248
  type: S.Literal<[TriggerKind.Queue]>;
165
249
  queue: S.refine<string, typeof S.NonEmptyString>;
166
250
  }>>]>>;
167
- readonly meta: S.optional<S.mutable<S.Record$<typeof S.String, typeof S.Any>>>;
168
- }>>;
251
+ /**
252
+ * Passed as the input data to the function.
253
+ * Must match the function's input schema.
254
+ *
255
+ * @example
256
+ * {
257
+ * item: '{{$.trigger.event}}',
258
+ * instructions: 'Summarize and perform entity-extraction'
259
+ * mailbox: { '/': 'dxn:echo:AAA:ZZZ' }
260
+ * }
261
+ */
262
+ input: S.optional<S.mutable<S.Record$<typeof S.String, typeof S.Any>>>;
263
+ }>>>;
169
264
  /**
170
265
  * Function trigger.
171
266
  */
172
267
  export declare class FunctionTrigger extends FunctionTrigger_base {
173
268
  }
174
- declare const FunctionDef_base: import("@dxos/echo-schema").TypedObjectPrototype<import("@dxos/echo-schema").TypedObjectFields<{
175
- uri: typeof S.String;
176
- description: S.optional<typeof S.String>;
177
- route: typeof S.String;
178
- handler: typeof S.String;
179
- }, import("@dxos/echo-schema").TypedObjectOptions>, S.Struct.Encoded<{
180
- uri: typeof S.String;
181
- description: S.optional<typeof S.String>;
182
- route: typeof S.String;
183
- handler: typeof S.String;
184
- }>>;
185
- /**
186
- * Function definition.
187
- * @deprecated (Use dxos.org/type/Function)
188
- */
189
- export declare class FunctionDef extends FunctionDef_base {
190
- }
191
269
  /**
192
270
  * Function manifest file.
193
271
  */
194
272
  export declare const FunctionManifestSchema: S.Struct<{
195
273
  functions: S.optional<S.mutable<S.Array$<S.Schema<import("@dxos/echo-schema").ExcludeId<import("@dxos/echo-schema").TypedObjectFields<{
196
- uri: typeof S.String;
274
+ name: typeof S.NonEmptyString;
275
+ version: typeof S.String;
197
276
  description: S.optional<typeof S.String>;
198
- route: typeof S.String;
199
- handler: typeof S.String;
277
+ source: S.optional<import("@dxos/echo-schema").Ref$<{
278
+ readonly id: string;
279
+ name?: string | undefined;
280
+ description?: string | undefined;
281
+ changed?: boolean | undefined;
282
+ source: Ref<{
283
+ readonly id: string;
284
+ content: string;
285
+ }>;
286
+ }>>;
287
+ inputSchema: S.optional<S.Schema<import("@dxos/echo-schema").JsonSchemaType, import("@dxos/echo-schema").JsonSchemaType, never>>;
288
+ outputSchema: S.optional<S.Schema<import("@dxos/echo-schema").JsonSchemaType, import("@dxos/echo-schema").JsonSchemaType, never>>;
289
+ binding: S.optional<typeof S.String>;
200
290
  }, import("@dxos/echo-schema").TypedObjectOptions>> & import("@dxos/echo-schema").WithMeta, S.Struct.Encoded<{
201
- uri: typeof S.String;
291
+ name: typeof S.NonEmptyString;
292
+ version: typeof S.String;
202
293
  description: S.optional<typeof S.String>;
203
- route: typeof S.String;
204
- handler: typeof S.String;
294
+ source: S.optional<import("@dxos/echo-schema").Ref$<{
295
+ readonly id: string;
296
+ name?: string | undefined;
297
+ description?: string | undefined;
298
+ changed?: boolean | undefined;
299
+ source: Ref<{
300
+ readonly id: string;
301
+ content: string;
302
+ }>;
303
+ }>>;
304
+ inputSchema: S.optional<S.Schema<import("@dxos/echo-schema").JsonSchemaType, import("@dxos/echo-schema").JsonSchemaType, never>>;
305
+ outputSchema: S.optional<S.Schema<import("@dxos/echo-schema").JsonSchemaType, import("@dxos/echo-schema").JsonSchemaType, never>>;
306
+ binding: S.optional<typeof S.String>;
205
307
  }>, never>>>>;
206
- triggers: S.optional<S.mutable<S.Array$<S.Schema<import("@dxos/echo-schema").ExcludeId<import("@dxos/echo-schema").TypedObjectFields<{
207
- readonly function: S.optional<S.SchemaClass<string, string, never>>;
208
- readonly enabled: S.optional<S.SchemaClass<boolean, boolean, never>>;
209
- readonly spec: S.optional<S.Union<[S.mutable<S.Struct<{
308
+ triggers: S.optional<S.mutable<S.Array$<S.Schema<import("@dxos/echo-schema").ExcludeId<import("@dxos/echo-schema").TypedObjectFields<Readonly<{
309
+ /**
310
+ * Function or workflow to invoke.
311
+ */
312
+ function: S.optional<S.SchemaClass<Ref<Expando>, import("@dxos/echo-protocol").EncodedReference, never>>;
313
+ /**
314
+ * Only used for workflows.
315
+ * Specifies the input node in the circuit.
316
+ * @deprecated Remove and enforce a single input node in all compute graphs.
317
+ */
318
+ inputNodeId: S.optional<S.SchemaClass<string, string, never>>;
319
+ enabled: S.optional<S.SchemaClass<boolean, boolean, never>>;
320
+ spec: S.optional<S.Union<[S.mutable<S.Struct<{
210
321
  type: S.Literal<[TriggerKind.Timer]>;
211
322
  cron: S.SchemaClass<string, string, never>;
212
323
  }>>, S.mutable<S.Struct<{
@@ -229,11 +340,31 @@ export declare const FunctionManifestSchema: S.Struct<{
229
340
  type: S.Literal<[TriggerKind.Queue]>;
230
341
  queue: S.refine<string, typeof S.NonEmptyString>;
231
342
  }>>]>>;
232
- readonly meta: S.optional<S.mutable<S.Record$<typeof S.String, typeof S.Any>>>;
233
- }, import("@dxos/echo-schema").TypedObjectOptions>> & import("@dxos/echo-schema").WithMeta, S.Struct.Encoded<{
234
- readonly function: S.optional<S.SchemaClass<string, string, never>>;
235
- readonly enabled: S.optional<S.SchemaClass<boolean, boolean, never>>;
236
- readonly spec: S.optional<S.Union<[S.mutable<S.Struct<{
343
+ /**
344
+ * Passed as the input data to the function.
345
+ * Must match the function's input schema.
346
+ *
347
+ * @example
348
+ * {
349
+ * item: '{{$.trigger.event}}',
350
+ * instructions: 'Summarize and perform entity-extraction'
351
+ * mailbox: { '/': 'dxn:echo:AAA:ZZZ' }
352
+ * }
353
+ */
354
+ input: S.optional<S.mutable<S.Record$<typeof S.String, typeof S.Any>>>;
355
+ }>, import("@dxos/echo-schema").TypedObjectOptions>> & import("@dxos/echo-schema").WithMeta, S.Struct.Encoded<Readonly<{
356
+ /**
357
+ * Function or workflow to invoke.
358
+ */
359
+ function: S.optional<S.SchemaClass<Ref<Expando>, import("@dxos/echo-protocol").EncodedReference, never>>;
360
+ /**
361
+ * Only used for workflows.
362
+ * Specifies the input node in the circuit.
363
+ * @deprecated Remove and enforce a single input node in all compute graphs.
364
+ */
365
+ inputNodeId: S.optional<S.SchemaClass<string, string, never>>;
366
+ enabled: S.optional<S.SchemaClass<boolean, boolean, never>>;
367
+ spec: S.optional<S.Union<[S.mutable<S.Struct<{
237
368
  type: S.Literal<[TriggerKind.Timer]>;
238
369
  cron: S.SchemaClass<string, string, never>;
239
370
  }>>, S.mutable<S.Struct<{
@@ -256,10 +387,21 @@ export declare const FunctionManifestSchema: S.Struct<{
256
387
  type: S.Literal<[TriggerKind.Queue]>;
257
388
  queue: S.refine<string, typeof S.NonEmptyString>;
258
389
  }>>]>>;
259
- readonly meta: S.optional<S.mutable<S.Record$<typeof S.String, typeof S.Any>>>;
260
- }>, never>>>>;
390
+ /**
391
+ * Passed as the input data to the function.
392
+ * Must match the function's input schema.
393
+ *
394
+ * @example
395
+ * {
396
+ * item: '{{$.trigger.event}}',
397
+ * instructions: 'Summarize and perform entity-extraction'
398
+ * mailbox: { '/': 'dxn:echo:AAA:ZZZ' }
399
+ * }
400
+ */
401
+ input: S.optional<S.mutable<S.Record$<typeof S.String, typeof S.Any>>>;
402
+ }>>, never>>>>;
261
403
  }>;
262
404
  export type FunctionManifest = S.Schema.Type<typeof FunctionManifestSchema>;
263
- export declare const FUNCTION_TYPES: (typeof FunctionTrigger | typeof FunctionDef)[];
405
+ export declare const FUNCTION_TYPES: (typeof FunctionType | typeof FunctionTrigger)[];
264
406
  export {};
265
407
  //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/types.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,MAAM,IAAI,CAAC,EAAa,MAAM,QAAQ,CAAC;AAEhD,OAAO,EAAE,OAAO,EAAyC,GAAG,EAAa,MAAM,mBAAmB,CAAC;AAEnG,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAExC;;;;GAIG;AACH,oBAAY,WAAW;IACrB,KAAK,UAAU;IACf,OAAO,YAAY;IACnB,YAAY,iBAAiB;IAC7B,KAAK,UAAU;IACf,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,QAAA,MAAM,kBAAkB;;;GAGN,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;AACH,MAAM,MAAM,WAAW,GAAG,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,aAAa,CAAC,CAAC;AAE9D,MAAM,MAAM,SAAS,GACjB,kBAAkB,GAClB,oBAAoB,GACpB,kBAAkB,GAClB,yBAAyB,GACzB,kBAAkB,CAAC;AAGvB,eAAO,MAAM,kBAAkB;;;;;;GAQ9B,CAAC;AACF,MAAM,MAAM,kBAAkB,GAAG,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,kBAAkB,CAAC,CAAC;AAE1E,eAAO,MAAM,oBAAoB;;;;;GAOhC,CAAC;AACF,MAAM,MAAM,oBAAoB,GAAG,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,oBAAoB,CAAC,CAAC;AAE9E,eAAO,MAAM,kBAAkB;;;;GAM9B,CAAC;AACF,MAAM,MAAM,kBAAkB,GAAG,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,kBAAkB,CAAC,CAAC;AAE1E,eAAO,MAAM,yBAAyB;;;GAAqE,CAAC;AAC5G,MAAM,MAAM,yBAAyB,GAAG,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,yBAAyB,CAAC,CAAC;AAExF,eAAO,MAAM,kBAAkB;;GAA0C,CAAC;AAC1E,MAAM,MAAM,kBAAkB,GAAG,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,kBAAkB,CAAC,CAAC;AAE1E;;;;GAIG;AACH,eAAO,MAAM,qBAAqB;IAChC;;OAEG;;IAIH;;;;OAIG;;;;;;;;;;;;;;;;;;;;;;;;;;IAOH;;;;;;;;;;OAUG;;EAEH,CAAC;AAEH,MAAM,MAAM,mBAAmB,GAAG,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,qBAAqB,CAAC,CAAC;;IA/B5E;;OAEG;;IAIH;;;;OAIG;;;;;;;;;;;;;;;;;;;;;;;;;;IAOH;;;;;;;;;;OAUG;;;IA3BH;;OAEG;;IAIH;;;;OAIG;;;;;;;;;;;;;;;;;;;;;;;;;;IAOH;;;;;;;;;;OAUG;;;AAML;;GAEG;AACH,qBAAa,eAAgB,SAAQ,oBAGL;CAAG;AAInC;;GAEG;AACH,eAAO,MAAM,sBAAsB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;QA9CjC;;WAEG;;QAIH;;;;WAIG;;;;;;;;;;;;;;;;;;;;;;;;;;QAOH;;;;;;;;;;WAUG;;;QA3BH;;WAEG;;QAIH;;;;WAIG;;;;;;;;;;;;;;;;;;;;;;;;;;QAOH;;;;;;;;;;WAUG;;;EAsBH,CAAC;AACH,MAAM,MAAM,gBAAgB,GAAG,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,sBAAsB,CAAC,CAAC;AAE5E,eAAO,MAAM,cAAc,kDAAkC,CAAC"}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"url.d.ts","sourceRoot":"","sources":["../../../src/url.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,UAAU,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAE,KAAK,OAAO,EAAE,MAAM,YAAY,CAAC;AAK1C,eAAO,MAAM,yBAAyB,qCAAqC,CAAC;AAM5E,eAAO,MAAM,4BAA4B,SAAU,UAAU,uBAE5D,CAAC;AAEF,eAAO,MAAM,4BAA4B,SAAU,UAAU,eAAe,MAAM,SASjF,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,eAAe,YAAa,OAAO,MAAM;IAAE,UAAU,EAAE,MAAM,CAAA;CAAE,WAAmC,CAAC;AAEhH,eAAO,MAAM,gBAAgB,gBAAiB,MAAM,WAAW,MAAM,YAAW,iBAAiB,WAUhG,CAAC;AAEF,MAAM,MAAM,iBAAiB,GAAG;IAC9B,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dxos/functions",
3
- "version": "0.8.2-main.12df754",
3
+ "version": "0.8.2-main.2f9c567",
4
4
  "description": "Functions API and runtime.",
5
5
  "homepage": "https://dxos.org",
6
6
  "bugs": "https://github.com/dxos/dxos/issues",
@@ -23,16 +23,6 @@
23
23
  "types": "./dist/types/src/edge/index.d.ts",
24
24
  "browser": "./dist/lib/browser/edge/index.mjs",
25
25
  "node": "./dist/lib/node-esm/edge/index.mjs"
26
- },
27
- "./testing": {
28
- "types": "./dist/types/src/testing/index.d.ts",
29
- "browser": "./dist/lib/browser/testing/index.mjs",
30
- "node": "./dist/lib/node-esm/testing/index.mjs"
31
- },
32
- "./types": {
33
- "types": "./dist/types/src/types/index.d.ts",
34
- "browser": "./dist/lib/browser/types/index.mjs",
35
- "node": "./dist/lib/node-esm/types/index.mjs"
36
26
  }
37
27
  },
38
28
  "types": "dist/types/src/index.d.ts",
@@ -43,12 +33,6 @@
43
33
  ],
44
34
  "edge": [
45
35
  "dist/types/src/edge/index.d.ts"
46
- ],
47
- "testing": [
48
- "dist/types/src/testing/index.d.ts"
49
- ],
50
- "types": [
51
- "dist/types/src/types/index.d.ts"
52
36
  ]
53
37
  }
54
38
  },
@@ -61,34 +45,34 @@
61
45
  "@preact/signals-core": "^1.6.0",
62
46
  "cron": "^3.1.6",
63
47
  "cron-schedule": "^5.0.4",
64
- "effect": "3.13.3",
48
+ "effect": "3.14.21",
65
49
  "esbuild-wasm": "^0.16.14",
66
50
  "express": "^4.19.2",
67
51
  "get-port-please": "^3.1.1",
68
52
  "iso-did": "^1.6.0",
69
53
  "ws": "^8.14.2",
70
- "@dxos/assistant": "0.8.2-main.12df754",
71
- "@dxos/async": "0.8.2-main.12df754",
72
- "@dxos/client": "0.8.2-main.12df754",
73
- "@dxos/context": "0.8.2-main.12df754",
74
- "@dxos/crypto": "0.8.2-main.12df754",
75
- "@dxos/echo-protocol": "0.8.2-main.12df754",
76
- "@dxos/echo-db": "0.8.2-main.12df754",
77
- "@dxos/edge-client": "0.8.2-main.12df754",
78
- "@dxos/echo-schema": "0.8.2-main.12df754",
79
- "@dxos/invariant": "0.8.2-main.12df754",
80
- "@dxos/keys": "0.8.2-main.12df754",
81
- "@dxos/live-object": "0.8.2-main.12df754",
82
- "@dxos/log": "0.8.2-main.12df754",
83
- "@dxos/node-std": "0.8.2-main.12df754",
84
- "@dxos/util": "0.8.2-main.12df754",
85
- "@dxos/protocols": "0.8.2-main.12df754",
86
- "@dxos/schema": "0.8.2-main.12df754"
54
+ "@dxos/assistant": "0.8.2-main.2f9c567",
55
+ "@dxos/async": "0.8.2-main.2f9c567",
56
+ "@dxos/client": "0.8.2-main.2f9c567",
57
+ "@dxos/context": "0.8.2-main.2f9c567",
58
+ "@dxos/echo-db": "0.8.2-main.2f9c567",
59
+ "@dxos/echo-schema": "0.8.2-main.2f9c567",
60
+ "@dxos/echo-protocol": "0.8.2-main.2f9c567",
61
+ "@dxos/edge-client": "0.8.2-main.2f9c567",
62
+ "@dxos/crypto": "0.8.2-main.2f9c567",
63
+ "@dxos/invariant": "0.8.2-main.2f9c567",
64
+ "@dxos/keys": "0.8.2-main.2f9c567",
65
+ "@dxos/log": "0.8.2-main.2f9c567",
66
+ "@dxos/node-std": "0.8.2-main.2f9c567",
67
+ "@dxos/live-object": "0.8.2-main.2f9c567",
68
+ "@dxos/protocols": "0.8.2-main.2f9c567",
69
+ "@dxos/schema": "0.8.2-main.2f9c567",
70
+ "@dxos/util": "0.8.2-main.2f9c567"
87
71
  },
88
72
  "devDependencies": {
89
73
  "@types/express": "^4.17.17",
90
74
  "@types/ws": "^7.4.0",
91
- "@dxos/agent": "0.8.2-main.12df754"
75
+ "@dxos/agent": "0.8.2-main.2f9c567"
92
76
  },
93
77
  "publishConfig": {
94
78
  "access": "public"
package/src/edge/index.ts CHANGED
@@ -2,4 +2,8 @@
2
2
  // Copyright 2024 DXOS.org
3
3
  //
4
4
 
5
+ // NOTE: This module is separate because it uses the edge client.
6
+ // This means it cannot be used on edge itself.
7
+ // TODO(wittjosiah): Factor out.
8
+
5
9
  export * from './functions';
package/src/handler.ts CHANGED
@@ -6,14 +6,10 @@ import { Schema as S } from 'effect';
6
6
  import { type Effect } from 'effect';
7
7
 
8
8
  import { type AIServiceClient } from '@dxos/assistant';
9
- import { type Client, PublicKey } from '@dxos/client';
10
- import { type Space } from '@dxos/client/echo';
11
- import type { CoreDatabase, EchoDatabase, ReactiveEchoObject } from '@dxos/echo-db';
9
+ import type { CoreDatabase, EchoDatabase } from '@dxos/echo-db';
12
10
  import { type HasId } from '@dxos/echo-schema';
13
11
  import { type SpaceId, type DXN } from '@dxos/keys';
14
- import { log } from '@dxos/log';
15
12
  import { type QueryResult } from '@dxos/protocols';
16
- import { isNonNullable } from '@dxos/util';
17
13
 
18
14
  // TODO(burdon): Model after http request. Ref Lambda/OpenFaaS.
19
15
  // https://docs.aws.amazon.com/lambda/latest/dg/typescript-handler.html
@@ -23,13 +19,18 @@ import { isNonNullable } from '@dxos/util';
23
19
  /**
24
20
  * Function handler.
25
21
  */
26
- export type FunctionHandler<TData = {}, TMeta = {}, TOutput = any> = (params: {
22
+ export type FunctionHandler<TData = {}, TOutput = any> = (params: {
23
+ /**
24
+ * Services and context available to the function.
25
+ */
27
26
  context: FunctionContext;
28
- event: FunctionEvent<TData, TMeta>;
27
+
29
28
  /**
30
- * @deprecated
29
+ * Data passed as the input to the function.
30
+ * Must match the function's input schema.
31
+ * This will be the payload from the trigger or other data passed into the function in a workflow.
31
32
  */
32
- response: FunctionResponse;
33
+ data: TData;
33
34
  }) => TOutput | Promise<TOutput> | Effect.Effect<TOutput, any>;
34
35
 
35
36
  /**
@@ -44,17 +45,6 @@ export interface FunctionContext {
44
45
  space: SpaceAPI | undefined;
45
46
 
46
47
  ai: AIServiceClient;
47
-
48
- /**
49
- * @deprecated
50
- */
51
- // TODO(burdon): Limit access to individual space.
52
- client: Client;
53
- /**
54
- * @deprecated
55
- */
56
- // TODO(burdon): Replace with storage service abstraction.
57
- dataDir?: string;
58
48
  }
59
49
 
60
50
  export interface FunctionContextAi {
@@ -62,28 +52,6 @@ export interface FunctionContextAi {
62
52
  run(model: string, inputs: any, options?: any): Promise<any>;
63
53
  }
64
54
 
65
- /**
66
- * Event payload.
67
- */
68
- // TODO(dmaretskyi): Update type definitions to match the actual payload.
69
- export type FunctionEvent<TData = {}, TMeta = {}> = {
70
- data: FunctionEventMeta<TMeta> & TData;
71
- };
72
-
73
- /**
74
- * Metadata from trigger.
75
- */
76
- export type FunctionEventMeta<TMeta = {}> = {
77
- meta: TMeta;
78
- };
79
-
80
- /**
81
- * Function response.
82
- */
83
- export type FunctionResponse = {
84
- status(code: number): FunctionResponse;
85
- };
86
-
87
55
  //
88
56
  // API.
89
57
  //
@@ -109,27 +77,19 @@ export interface SpaceAPI {
109
77
  get queues(): QueuesAPI;
110
78
  }
111
79
 
112
- // TODO(wittjosiah): Fix this.
113
80
  const __assertFunctionSpaceIsCompatibleWithTheClientSpace = () => {
114
- // const _: SpaceAPI = {} as Space;
115
- };
116
-
117
- export type FunctionDefinition = {
118
- description?: string;
119
- inputSchema: S.Schema.AnyNoContext;
120
- outputSchema?: S.Schema.AnyNoContext;
121
- handler: FunctionHandler<any>;
81
+ const _: SpaceAPI = {} as SpaceAPI;
122
82
  };
123
83
 
124
- export type DefineFunctionParams<T, O = any> = {
84
+ export type FunctionDefinition<T = {}, O = any> = {
125
85
  description?: string;
126
86
  inputSchema: S.Schema<T, any>;
127
87
  outputSchema?: S.Schema<O, any>;
128
- handler: FunctionHandler<T, any, O>;
88
+ handler: FunctionHandler<T, O>;
129
89
  };
130
90
 
131
91
  // TODO(dmaretskyi): Bind input type to function handler.
132
- export const defineFunction = <T, O>(params: DefineFunctionParams<T, O>): FunctionDefinition => {
92
+ export const defineFunction = <T, O>(params: FunctionDefinition<T, O>): FunctionDefinition<T, O> => {
133
93
  if (!S.isSchema(params.inputSchema)) {
134
94
  throw new Error('Input schema must be a valid schema');
135
95
  }
@@ -144,67 +104,3 @@ export const defineFunction = <T, O>(params: DefineFunctionParams<T, O>): Functi
144
104
  handler: params.handler,
145
105
  };
146
106
  };
147
-
148
- //
149
- // Subscription utils.
150
- //
151
-
152
- export type RawSubscriptionData = {
153
- spaceKey?: string;
154
- objects?: string[];
155
- };
156
-
157
- export type SubscriptionData = {
158
- space?: Space;
159
- objects?: ReactiveEchoObject<any>[];
160
- };
161
-
162
- /**
163
- * Handler wrapper for subscription events; extracts space and objects.
164
- *
165
- * To test:
166
- * ```
167
- * curl -s -X POST -H "Content-Type: application/json" --data '{"space": "0446...1cbb"}' http://localhost:7100/dev/email-extractor
168
- * ```
169
- *
170
- * NOTE: Get space key from devtools or `dx space list --json`
171
- */
172
- // TODO(burdon): Evolve into plugin definition like Composer.
173
- export const subscriptionHandler = <TMeta>(
174
- handler: FunctionHandler<SubscriptionData, TMeta>,
175
- types?: S.Schema.AnyNoContext[],
176
- ): FunctionHandler<RawSubscriptionData, TMeta> => {
177
- return async ({ event: { data }, context, response, ...rest }) => {
178
- const { client } = context;
179
- const space = data.spaceKey ? client.spaces.get(PublicKey.from(data.spaceKey)) : undefined;
180
- if (!space) {
181
- log.error('Invalid space');
182
- return response.status(500);
183
- }
184
-
185
- registerTypes(space, types);
186
- const objects = space
187
- ? data.objects
188
- ?.map<ReactiveEchoObject<any> | undefined>((id) => space!.db.getObjectById(id))
189
- .filter(isNonNullable)
190
- : [];
191
-
192
- if (!!data.spaceKey && !space) {
193
- log.warn('invalid space', { data });
194
- } else {
195
- log.info('handler', { space: space?.key.truncate(), objects: objects?.length });
196
- }
197
-
198
- return handler({ event: { data: { ...data, space, objects } }, context, response, ...rest });
199
- };
200
- };
201
-
202
- // TODO(burdon): Evolve types as part of function metadata.
203
- const registerTypes = (space: Space, types: S.Schema.AnyNoContext[] = []) => {
204
- const registry = space.db.graph.schemaRegistry;
205
- for (const type of types) {
206
- if (!registry.hasSchema(type)) {
207
- registry.addSchema([type]);
208
- }
209
- }
210
- };
package/src/index.ts CHANGED
@@ -1,10 +1,9 @@
1
1
  //
2
- // Copyright 2023 DXOS.org
2
+ // Copyright 2024 DXOS.org
3
3
  //
4
4
 
5
- export * from './edge';
6
- export * from './function';
7
5
  export * from './handler';
8
- // export * from './runtime';
9
- export * from './trigger';
6
+ export * from './schema';
7
+ export * from './trace';
10
8
  export * from './types';
9
+ export * from './url';
package/src/schema.ts ADDED
@@ -0,0 +1,53 @@
1
+ //
2
+ // Copyright 2024 DXOS.org
3
+ //
4
+
5
+ import { Schema } from 'effect';
6
+
7
+ import { EchoObject, JsonSchemaType, LabelAnnotationId, Ref, TypedObject } from '@dxos/echo-schema';
8
+ import { DataType } from '@dxos/schema';
9
+
10
+ /**
11
+ * Source script.
12
+ */
13
+ export const ScriptType = Schema.Struct({
14
+ name: Schema.optional(Schema.String),
15
+ description: Schema.optional(Schema.String),
16
+ // TODO(burdon): Change to hash of deployed content.
17
+ // Whether source has changed since last deploy.
18
+ changed: Schema.optional(Schema.Boolean),
19
+ source: Ref(DataType.Text),
20
+ })
21
+ .annotations({ [LabelAnnotationId]: 'name' })
22
+ .pipe(
23
+ EchoObject({
24
+ typename: 'dxos.org/type/Script',
25
+ version: '0.1.0',
26
+ }),
27
+ );
28
+
29
+ export type ScriptType = Schema.Schema.Type<typeof ScriptType>;
30
+
31
+ /**
32
+ * Function deployment.
33
+ */
34
+ export class FunctionType extends TypedObject({
35
+ typename: 'dxos.org/type/Function',
36
+ version: '0.1.0',
37
+ })({
38
+ // TODO(burdon): Rename to id/uri?
39
+ name: Schema.NonEmptyString,
40
+ version: Schema.String,
41
+
42
+ description: Schema.optional(Schema.String),
43
+
44
+ // Reference to a source script if it exists within ECHO.
45
+ // TODO(burdon): Don't ref ScriptType directly (core).
46
+ source: Schema.optional(Ref(ScriptType)),
47
+
48
+ inputSchema: Schema.optional(JsonSchemaType),
49
+ outputSchema: Schema.optional(JsonSchemaType),
50
+
51
+ // Local binding to a function name.
52
+ binding: Schema.optional(Schema.String),
53
+ }) {}