@dxos/functions 0.8.1-staging.5be625a → 0.8.1-staging.97aedb1

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 (53) hide show
  1. package/dist/lib/browser/{chunk-OREUICVD.mjs → chunk-HI7YZO2K.mjs} +2 -2
  2. package/dist/lib/browser/{chunk-B747D6L6.mjs → chunk-LT4LR4VU.mjs} +9 -9
  3. package/dist/lib/browser/chunk-LT4LR4VU.mjs.map +7 -0
  4. package/dist/lib/browser/{chunk-LHCAYQLL.mjs → chunk-RVSG6WTL.mjs} +64 -35
  5. package/dist/lib/browser/chunk-RVSG6WTL.mjs.map +7 -0
  6. package/dist/lib/browser/edge/index.mjs +1 -1
  7. package/dist/lib/browser/index.mjs +3 -3
  8. package/dist/lib/browser/meta.json +1 -1
  9. package/dist/lib/browser/testing/index.mjs +2 -2
  10. package/dist/lib/browser/types/index.mjs +1 -1
  11. package/dist/lib/node/{chunk-UQZH4J6S.cjs → chunk-DSUGRAAL.cjs} +67 -38
  12. package/dist/lib/node/chunk-DSUGRAAL.cjs.map +7 -0
  13. package/dist/lib/node/{chunk-D4T2DS7U.cjs → chunk-NXZNXVT3.cjs} +12 -12
  14. package/dist/lib/node/chunk-NXZNXVT3.cjs.map +7 -0
  15. package/dist/lib/node/{chunk-ZSHBAXJA.cjs → chunk-RXMCVAMJ.cjs} +15 -15
  16. package/dist/lib/node/edge/index.cjs +4 -4
  17. package/dist/lib/node/edge/index.cjs.map +1 -1
  18. package/dist/lib/node/index.cjs +31 -31
  19. package/dist/lib/node/meta.json +1 -1
  20. package/dist/lib/node/testing/index.cjs +7 -7
  21. package/dist/lib/node/types/index.cjs +22 -22
  22. package/dist/lib/node/types/index.cjs.map +1 -1
  23. package/dist/lib/node-esm/{chunk-YCBKVXQU.mjs → chunk-HBD2FZXO.mjs} +64 -35
  24. package/dist/lib/node-esm/chunk-HBD2FZXO.mjs.map +7 -0
  25. package/dist/lib/node-esm/{chunk-D43PP2YW.mjs → chunk-O2SXVYU5.mjs} +9 -9
  26. package/dist/lib/node-esm/chunk-O2SXVYU5.mjs.map +7 -0
  27. package/dist/lib/node-esm/{chunk-ZX523EY4.mjs → chunk-SQSJO5HI.mjs} +2 -2
  28. package/dist/lib/node-esm/edge/index.mjs +1 -1
  29. package/dist/lib/node-esm/index.mjs +3 -3
  30. package/dist/lib/node-esm/meta.json +1 -1
  31. package/dist/lib/node-esm/testing/index.mjs +2 -2
  32. package/dist/lib/node-esm/types/index.mjs +1 -1
  33. package/dist/types/src/edge/functions.d.ts +3 -3
  34. package/dist/types/src/edge/functions.d.ts.map +1 -1
  35. package/dist/types/src/types/schema.d.ts +2 -2
  36. package/dist/types/src/types/schema.d.ts.map +1 -1
  37. package/dist/types/src/types/trace.d.ts +3 -2
  38. package/dist/types/src/types/trace.d.ts.map +1 -1
  39. package/dist/types/src/types/types.d.ts.map +1 -1
  40. package/package.json +18 -18
  41. package/src/edge/functions.ts +10 -8
  42. package/src/types/schema.ts +3 -5
  43. package/src/types/trace.ts +53 -28
  44. package/src/types/types.ts +2 -1
  45. package/dist/lib/browser/chunk-B747D6L6.mjs.map +0 -7
  46. package/dist/lib/browser/chunk-LHCAYQLL.mjs.map +0 -7
  47. package/dist/lib/node/chunk-D4T2DS7U.cjs.map +0 -7
  48. package/dist/lib/node/chunk-UQZH4J6S.cjs.map +0 -7
  49. package/dist/lib/node-esm/chunk-D43PP2YW.mjs.map +0 -7
  50. package/dist/lib/node-esm/chunk-YCBKVXQU.mjs.map +0 -7
  51. /package/dist/lib/browser/{chunk-OREUICVD.mjs.map → chunk-HI7YZO2K.mjs.map} +0 -0
  52. /package/dist/lib/node/{chunk-ZSHBAXJA.cjs.map → chunk-RXMCVAMJ.cjs.map} +0 -0
  53. /package/dist/lib/node-esm/{chunk-ZX523EY4.mjs.map → chunk-SQSJO5HI.mjs.map} +0 -0
@@ -16,8 +16,8 @@ var __copyProps = (to, from, except, desc) => {
16
16
  return to;
17
17
  };
18
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
- var chunk_UQZH4J6S_exports = {};
20
- __export(chunk_UQZH4J6S_exports, {
19
+ var chunk_DSUGRAAL_exports = {};
20
+ __export(chunk_DSUGRAAL_exports, {
21
21
  FUNCTIONS_PRESET_META_KEY: () => FUNCTIONS_PRESET_META_KEY,
22
22
  FUNCTION_TYPES: () => FUNCTION_TYPES,
23
23
  FunctionDef: () => FunctionDef,
@@ -40,7 +40,7 @@ __export(chunk_UQZH4J6S_exports, {
40
40
  getUserFunctionUrlInMetadata: () => getUserFunctionUrlInMetadata,
41
41
  setUserFunctionUrlInMetadata: () => setUserFunctionUrlInMetadata
42
42
  });
43
- module.exports = __toCommonJS(chunk_UQZH4J6S_exports);
43
+ module.exports = __toCommonJS(chunk_DSUGRAAL_exports);
44
44
  var import_echo_schema = require("@dxos/echo-schema");
45
45
  var import_schema = require("@dxos/schema");
46
46
  var import_echo_schema2 = require("@dxos/echo-schema");
@@ -55,7 +55,10 @@ var ScriptType = import_echo_schema.S.Struct({
55
55
  source: (0, import_echo_schema.Ref)(import_schema.TextType)
56
56
  }).annotations({
57
57
  [import_echo_schema.LabelAnnotationId]: "name"
58
- }).pipe((0, import_echo_schema.EchoObject)("dxos.org/type/Script", "0.1.0"));
58
+ }).pipe((0, import_echo_schema.EchoObject)({
59
+ typename: "dxos.org/type/Script",
60
+ version: "0.1.0"
61
+ }));
59
62
  var FunctionType = class extends (0, import_echo_schema.TypedObject)({
60
63
  typename: "dxos.org/type/Function",
61
64
  version: "0.1.0"
@@ -155,7 +158,8 @@ var FunctionTriggerSchema = import_echo_schema2.S.Struct({
155
158
  })),
156
159
  // TODO(burdon): Flatten entire schema.
157
160
  spec: import_echo_schema2.S.optional(TriggerSchema),
158
- // TODO(burdon): Get meta from function.
161
+ // TODO(burdon): Get schema as partial from function.
162
+ // TODO(wittjosiah): Rename to payload.
159
163
  // The `meta` property is merged into the event data passed to the function.
160
164
  meta: import_echo_schema2.S.optional(import_echo_schema2.S.mutable(import_echo_schema2.S.Record({
161
165
  key: import_echo_schema2.S.String,
@@ -190,6 +194,7 @@ var InvocationOutcome;
190
194
  (function(InvocationOutcome2) {
191
195
  InvocationOutcome2["SUCCESS"] = "success";
192
196
  InvocationOutcome2["FAILURE"] = "failure";
197
+ InvocationOutcome2["PENDING"] = "pending";
193
198
  })(InvocationOutcome || (InvocationOutcome = {}));
194
199
  var InvocationTraceEventType;
195
200
  (function(InvocationTraceEventType2) {
@@ -219,10 +224,12 @@ var InvocationTraceStartEvent = import_echo_schema3.S.Struct({
219
224
  /**
220
225
  * Data passed to function / workflow as an argument.
221
226
  */
227
+ // TODO(burdon): Input schema?
222
228
  input: import_echo_schema3.S.Object,
223
229
  /**
224
230
  * Queue DXN for function/workflow invocation events.
225
231
  */
232
+ // TODO(burdon): Need reference type for queue. vs. string?
226
233
  invocationTraceQueue: (0, import_echo_schema3.Ref)(import_echo_schema3.Expando),
227
234
  /**
228
235
  * DXN of the invoked function/workflow.
@@ -232,7 +239,10 @@ var InvocationTraceStartEvent = import_echo_schema3.S.Struct({
232
239
  * Present for automatic invocations.
233
240
  */
234
241
  trigger: import_echo_schema3.S.optional((0, import_echo_schema3.Ref)(FunctionTrigger))
235
- }).pipe((0, import_echo_schema3.EchoObject)("dxos.org/type/InvocationTraceStart", "0.1.0"));
242
+ }).pipe((0, import_echo_schema3.EchoObject)({
243
+ typename: "dxos.org/type/InvocationTraceStart",
244
+ version: "0.1.0"
245
+ }));
236
246
  var InvocationTraceEndEvent = import_echo_schema3.S.Struct({
237
247
  /**
238
248
  * Trace event id.
@@ -246,10 +256,14 @@ var InvocationTraceEndEvent = import_echo_schema3.S.Struct({
246
256
  /**
247
257
  * Event generation time.
248
258
  */
259
+ // TODO(burdon): Remove ms suffix.
249
260
  timestampMs: import_echo_schema3.S.Number,
250
261
  outcome: import_echo_schema3.S.Enums(InvocationOutcome),
251
262
  exception: import_echo_schema3.S.optional(TraceEventException)
252
- }).pipe((0, import_echo_schema3.EchoObject)("dxos.org/type/InvocationTraceEnd", "0.1.0"));
263
+ }).pipe((0, import_echo_schema3.EchoObject)({
264
+ typename: "dxos.org/type/InvocationTraceEnd",
265
+ version: "0.1.0"
266
+ }));
253
267
  var TraceEventLog = import_echo_schema3.S.Struct({
254
268
  timestampMs: import_echo_schema3.S.Number,
255
269
  level: import_echo_schema3.S.String,
@@ -258,6 +272,7 @@ var TraceEventLog = import_echo_schema3.S.Struct({
258
272
  });
259
273
  var TraceEvent = import_echo_schema3.S.Struct({
260
274
  id: import_echo_schema3.ObjectId,
275
+ // TODO(burdon): Need enum/numeric result (not string).
261
276
  outcome: import_echo_schema3.S.String,
262
277
  truncated: import_echo_schema3.S.Boolean,
263
278
  /**
@@ -266,43 +281,57 @@ var TraceEvent = import_echo_schema3.S.Struct({
266
281
  ingestionTimestampMs: import_echo_schema3.S.Number,
267
282
  logs: import_echo_schema3.S.Array(TraceEventLog),
268
283
  exceptions: import_echo_schema3.S.Array(TraceEventException)
269
- }).pipe((0, import_echo_schema3.EchoObject)("dxos.org/type/TraceEvent", "0.1.0"));
284
+ }).pipe((0, import_echo_schema3.EchoObject)({
285
+ typename: "dxos.org/type/TraceEvent",
286
+ version: "0.1.0"
287
+ }));
270
288
  var createInvocationSpans = (items) => {
271
289
  if (!items) {
272
290
  return [];
273
291
  }
274
- const startEvents = /* @__PURE__ */ new Map();
292
+ const eventsByInvocationId = /* @__PURE__ */ new Map();
293
+ for (const event of items) {
294
+ if (!("invocationId" in event)) {
295
+ continue;
296
+ }
297
+ const invocationId = event.invocationId;
298
+ const entry = eventsByInvocationId.get(invocationId) || {
299
+ start: void 0,
300
+ end: void 0
301
+ };
302
+ if (event.type === "start") {
303
+ entry.start = event;
304
+ } else if (event.type === "end") {
305
+ entry.end = event;
306
+ }
307
+ eventsByInvocationId.set(invocationId, entry);
308
+ }
309
+ const now = Date.now();
275
310
  const result = [];
276
- for (const item of items) {
277
- if (item.type === "start") {
278
- startEvents.set(item.invocationId, item);
279
- } else if (item.type === "end") {
280
- const matchingStart = startEvents.get(item.invocationId);
281
- if (!matchingStart) {
282
- import_log.log.warn("end event without matching start", {
283
- item
284
- }, {
285
- F: __dxlog_file,
286
- L: 133,
287
- S: void 0,
288
- C: (f, a) => f(...a)
289
- });
290
- continue;
291
- }
292
- result.push({
293
- id: item.invocationId,
294
- durationMs: item.timestampMs - matchingStart.timestampMs,
295
- timestampMs: item.timestampMs,
296
- outcome: item.outcome,
297
- exception: item.exception,
298
- trigger: matchingStart.trigger,
299
- input: matchingStart.input,
300
- invocationTraceQueue: matchingStart.invocationTraceQueue,
301
- invocationTarget: matchingStart.invocationTarget
311
+ for (const [invocationId, { start, end }] of eventsByInvocationId.entries()) {
312
+ if (!start) {
313
+ import_log.log.warn("found end event without matching start", {
314
+ invocationId
315
+ }, {
316
+ F: __dxlog_file,
317
+ L: 158,
318
+ S: void 0,
319
+ C: (f, a) => f(...a)
302
320
  });
303
- } else {
304
- result.push(item);
321
+ continue;
305
322
  }
323
+ const isInProgress = end === void 0;
324
+ result.push({
325
+ id: invocationId,
326
+ timestampMs: start.timestampMs,
327
+ durationMs: isInProgress ? now - start.timestampMs : end.timestampMs - start.timestampMs,
328
+ outcome: end?.outcome ?? "pending",
329
+ exception: end?.exception,
330
+ input: start.input,
331
+ invocationTraceQueue: start.invocationTraceQueue,
332
+ invocationTarget: start.invocationTarget,
333
+ trigger: start.trigger
334
+ });
306
335
  }
307
336
  return result;
308
337
  };
@@ -360,4 +389,4 @@ var getInvocationUrl = (functionUrl, edgeUrl, options = {}) => {
360
389
  getUserFunctionUrlInMetadata,
361
390
  setUserFunctionUrlInMetadata
362
391
  });
363
- //# sourceMappingURL=chunk-UQZH4J6S.cjs.map
392
+ //# sourceMappingURL=chunk-DSUGRAAL.cjs.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/types/schema.ts", "../../../src/types/types.ts", "../../../src/types/trace.ts", "../../../src/types/url.ts"],
4
+ "sourcesContent": ["//\n// Copyright 2024 DXOS.org\n//\n\nimport { EchoObject, JsonSchemaType, LabelAnnotationId, Ref, S, TypedObject } from '@dxos/echo-schema';\nimport { TextType } from '@dxos/schema';\n\n/**\n * Source script.\n */\nexport const ScriptType = S.Struct({\n name: S.optional(S.String),\n description: S.optional(S.String),\n // TODO(burdon): Change to hash of deployed content.\n // Whether source has changed since last deploy.\n changed: S.optional(S.Boolean),\n source: Ref(TextType),\n})\n .annotations({ [LabelAnnotationId]: 'name' })\n .pipe(EchoObject({ typename: 'dxos.org/type/Script', version: '0.1.0' }));\n\nexport type ScriptType = S.Schema.Type<typeof ScriptType>;\n\n/**\n * Function deployment.\n */\nexport class FunctionType extends TypedObject({\n typename: 'dxos.org/type/Function',\n version: '0.1.0',\n})({\n // TODO(burdon): Rename to id/uri?\n name: S.NonEmptyString,\n version: S.String,\n\n description: S.optional(S.String),\n\n // Reference to a source script if it exists within ECHO.\n // TODO(burdon): Don't ref ScriptType directly (core).\n source: S.optional(Ref(ScriptType)),\n\n inputSchema: S.optional(JsonSchemaType),\n outputSchema: S.optional(JsonSchemaType),\n\n // Local binding to a function name.\n binding: S.optional(S.String),\n}) {}\n", "//\n// Copyright 2023 DXOS.org\n//\n\nimport { AST, OptionsAnnotationId, RawObject, S, TypedObject, DXN } from '@dxos/echo-schema';\n\n/**\n * Type discriminator for TriggerType.\n * Every spec has a type field of type TriggerKind that we can use to understand which type we're working with.\n * https://www.typescriptlang.org/docs/handbook/2/narrowing.html#discriminated-unions\n */\nexport enum TriggerKind {\n Timer = 'timer',\n Webhook = 'webhook',\n Subscription = 'subscription',\n Email = 'email',\n Queue = 'queue',\n}\n\n// TODO(burdon): Rename prop kind.\nconst typeLiteralAnnotations = { [AST.TitleAnnotationId]: 'Type' };\n\n/**\n * Cron timer.\n */\nconst TimerTriggerSchema = S.Struct({\n type: S.Literal(TriggerKind.Timer).annotations(typeLiteralAnnotations),\n cron: S.String.annotations({\n [AST.TitleAnnotationId]: 'Cron',\n [AST.ExamplesAnnotationId]: ['0 0 * * *'],\n }),\n}).pipe(S.mutable);\n\nexport type TimerTrigger = S.Schema.Type<typeof TimerTriggerSchema>;\n\nconst EmailTriggerSchema = S.Struct({\n type: S.Literal(TriggerKind.Email).annotations(typeLiteralAnnotations),\n}).pipe(S.mutable);\n\nexport type EmailTrigger = S.Schema.Type<typeof EmailTriggerSchema>;\n\nconst QueueTriggerSchema = S.Struct({\n type: S.Literal(TriggerKind.Queue).annotations(typeLiteralAnnotations),\n queue: DXN,\n}).pipe(S.mutable);\n\nexport type QueueTrigger = S.Schema.Type<typeof QueueTriggerSchema>;\n\n/**\n * Webhook.\n */\nconst WebhookTriggerSchema = S.Struct({\n type: S.Literal(TriggerKind.Webhook).annotations(typeLiteralAnnotations),\n method: S.optional(\n S.String.annotations({\n [AST.TitleAnnotationId]: 'Method',\n [OptionsAnnotationId]: ['GET', 'POST'],\n }),\n ),\n port: S.optional(\n S.Number.annotations({\n [AST.TitleAnnotationId]: 'Port',\n }),\n ),\n}).pipe(S.mutable);\n\nexport type WebhookTrigger = S.Schema.Type<typeof WebhookTriggerSchema>;\n\n// TODO(burdon): Use ECHO definition (from https://github.com/dxos/dxos/pull/8233).\nconst QuerySchema = S.Struct({\n type: S.optional(S.String.annotations({ [AST.TitleAnnotationId]: 'Type' })),\n props: S.optional(S.Record({ key: S.String, value: S.Any })),\n}).annotations({ [AST.TitleAnnotationId]: 'Query' });\n\n/**\n * Subscription.\n */\nconst SubscriptionTriggerSchema = S.Struct({\n type: S.Literal(TriggerKind.Subscription).annotations(typeLiteralAnnotations),\n // TODO(burdon): Define query DSL (from ECHO). Reconcile with Table.Query.\n filter: QuerySchema,\n options: S.optional(\n S.Struct({\n // Watch changes to object (not just creation).\n deep: S.optional(S.Boolean.annotations({ [AST.TitleAnnotationId]: 'Nested' })),\n // Debounce changes (delay in ms).\n delay: S.optional(S.Number.annotations({ [AST.TitleAnnotationId]: 'Delay' })),\n }).annotations({ [AST.TitleAnnotationId]: 'Options' }),\n ),\n}).pipe(S.mutable);\n\nexport type SubscriptionTrigger = S.Schema.Type<typeof SubscriptionTriggerSchema>;\n\n/**\n * Trigger schema (discriminated union).\n */\nexport const TriggerSchema = S.Union(\n TimerTriggerSchema,\n WebhookTriggerSchema,\n SubscriptionTriggerSchema,\n EmailTriggerSchema,\n QueueTriggerSchema,\n).annotations({\n [AST.TitleAnnotationId]: 'Trigger',\n});\n\nexport type TriggerType = S.Schema.Type<typeof TriggerSchema>;\n\n/**\n * Function trigger.\n */\nexport const FunctionTriggerSchema = S.Struct({\n // TODO(burdon): What type does this reference.\n // TODO(wittjosiah): This should probably be a Ref?\n function: S.optional(S.String.annotations({ [AST.TitleAnnotationId]: 'Function' })),\n\n enabled: S.optional(S.Boolean.annotations({ [AST.TitleAnnotationId]: 'Enabled' })),\n\n // TODO(burdon): Flatten entire schema.\n spec: S.optional(TriggerSchema),\n\n // TODO(burdon): Get schema as partial from function.\n // TODO(wittjosiah): Rename to payload.\n // The `meta` property is merged into the event data passed to the function.\n meta: S.optional(S.mutable(S.Record({ key: S.String, value: S.Any }))),\n});\n\nexport type FunctionTriggerType = S.Schema.Type<typeof FunctionTriggerSchema>;\n\n/**\n * Function trigger.\n */\nexport class FunctionTrigger extends TypedObject({\n typename: 'dxos.org/type/FunctionTrigger',\n version: '0.1.0',\n})(FunctionTriggerSchema.fields) {}\n\n/**\n * Function definition.\n * @deprecated (Use dxos.org/type/Function)\n */\n// TODO(burdon): Reconcile with FunctionType.\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 handler: S.String,\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\nexport const FUNCTION_TYPES = [FunctionDef, FunctionTrigger];\n", "//\n// Copyright 2025 DXOS.org\n//\n\nimport { EchoObject, Expando, ObjectId, Ref, S } from '@dxos/echo-schema';\nimport { log } from '@dxos/log';\n\nimport { FunctionTrigger, type FunctionTriggerType } from './types';\n\nexport enum InvocationOutcome {\n SUCCESS = 'success',\n FAILURE = 'failure',\n PENDING = 'pending',\n}\n\n// TODO(burdon): Convert to extensible discriminated union of EDGE events.\nexport enum InvocationTraceEventType {\n START = 'start',\n END = 'end',\n}\n\nexport const TraceEventException = S.Struct({\n timestampMs: S.Number,\n message: S.String,\n name: S.String,\n stack: S.optional(S.String),\n});\nexport type TraceEventException = S.Schema.Type<typeof TraceEventException>;\n\nexport const InvocationTraceStartEvent = S.Struct({\n /**\n * Queue message id.\n */\n id: ObjectId,\n type: S.Literal(InvocationTraceEventType.START),\n /**\n * Invocation id, the same for invocation start and end events.\n */\n invocationId: ObjectId,\n /**\n * Event generation time.\n */\n timestampMs: S.Number,\n /**\n * Data passed to function / workflow as an argument.\n */\n // TODO(burdon): Input schema?\n input: S.Object,\n /**\n * Queue DXN for function/workflow invocation events.\n */\n // TODO(burdon): Need reference type for queue. vs. string?\n invocationTraceQueue: Ref(Expando),\n /**\n * DXN of the invoked function/workflow.\n */\n invocationTarget: Ref(Expando),\n /**\n * Present for automatic invocations.\n */\n trigger: S.optional(Ref(FunctionTrigger)),\n}).pipe(EchoObject({ typename: 'dxos.org/type/InvocationTraceStart', version: '0.1.0' }));\n\nexport type InvocationTraceStartEvent = S.Schema.Type<typeof InvocationTraceStartEvent>;\n\nexport const InvocationTraceEndEvent = S.Struct({\n /**\n * Trace event id.\n */\n id: ObjectId,\n type: S.Literal(InvocationTraceEventType.END),\n /**\n * Invocation id, will be the same for invocation start and end.\n */\n invocationId: ObjectId,\n /**\n * Event generation time.\n */\n // TODO(burdon): Remove ms suffix.\n timestampMs: S.Number,\n outcome: S.Enums(InvocationOutcome),\n exception: S.optional(TraceEventException),\n}).pipe(EchoObject({ typename: 'dxos.org/type/InvocationTraceEnd', version: '0.1.0' }));\n\nexport type InvocationTraceEndEvent = S.Schema.Type<typeof InvocationTraceEndEvent>;\n\nexport type InvocationTraceEvent = InvocationTraceStartEvent | InvocationTraceEndEvent;\n\nexport const TraceEventLog = S.Struct({\n timestampMs: S.Number,\n level: S.String,\n message: S.String,\n context: S.optional(S.Object),\n});\n\nexport const TraceEvent = S.Struct({\n id: ObjectId,\n // TODO(burdon): Need enum/numeric result (not string).\n outcome: S.String,\n truncated: S.Boolean,\n /**\n * Time when the event was persisted.\n */\n ingestionTimestampMs: S.Number,\n logs: S.Array(TraceEventLog),\n exceptions: S.Array(TraceEventException),\n}).pipe(EchoObject({ typename: 'dxos.org/type/TraceEvent', version: '0.1.0' }));\n\nexport type TraceEvent = S.Schema.Type<typeof TraceEvent>;\n\n/**\n * Deprecated InvocationTrace event format.\n * @deprecated\n */\n// TODO(burdon): Remove.\nexport type InvocationSpan = {\n id: string;\n timestampMs: number;\n outcome: InvocationOutcome;\n input: object;\n durationMs: number;\n invocationTraceQueue: Ref<Expando>;\n invocationTarget: Ref<Expando>;\n trigger?: Ref<FunctionTriggerType>;\n exception?: TraceEventException;\n};\n\nexport const createInvocationSpans = (items?: InvocationTraceEvent[]): InvocationSpan[] => {\n if (!items) {\n return [];\n }\n\n const eventsByInvocationId = new Map<string, { start?: InvocationTraceStartEvent; end?: InvocationTraceEndEvent }>();\n for (const event of items) {\n if (!('invocationId' in event)) {\n // Skip legacy format entries.\n continue;\n }\n\n const invocationId = event.invocationId;\n const entry = eventsByInvocationId.get(invocationId) || { start: undefined, end: undefined };\n if (event.type === InvocationTraceEventType.START) {\n entry.start = event as InvocationTraceStartEvent;\n } else if (event.type === InvocationTraceEventType.END) {\n entry.end = event as InvocationTraceEndEvent;\n }\n\n eventsByInvocationId.set(invocationId, entry);\n }\n\n const now = Date.now();\n const result: InvocationSpan[] = [];\n\n // Create spans for each invocation\n for (const [invocationId, { start, end }] of eventsByInvocationId.entries()) {\n if (!start) {\n // No start event, can't create a meaningful span\n log.warn('found end event without matching start', { invocationId });\n continue;\n }\n\n const isInProgress = end === undefined;\n\n result.push({\n id: invocationId,\n timestampMs: start.timestampMs,\n durationMs: isInProgress ? now - start.timestampMs : end!.timestampMs - start.timestampMs,\n outcome: end?.outcome ?? InvocationOutcome.PENDING,\n exception: end?.exception,\n input: start.input,\n invocationTraceQueue: start.invocationTraceQueue,\n invocationTarget: start.invocationTarget,\n trigger: start.trigger,\n });\n }\n\n return result;\n};\n", "//\n// Copyright 2025 DXOS.org\n//\n\nimport { type ObjectMeta } from '@dxos/echo-schema';\nimport { type SpaceId } from '@dxos/keys';\n\n// TODO: use URL scheme for source?\nconst FUNCTIONS_META_KEY = 'dxos.org/service/function';\n\nexport const FUNCTIONS_PRESET_META_KEY = 'dxos.org/service/function-preset';\n\nconst isSecure = (protocol: string) => {\n return protocol === 'https:' || protocol === 'wss:';\n};\n\nexport const getUserFunctionUrlInMetadata = (meta: ObjectMeta) => {\n return meta.keys.find((key) => key.source === FUNCTIONS_META_KEY)?.id;\n};\n\nexport const setUserFunctionUrlInMetadata = (meta: ObjectMeta, functionUrl: string) => {\n const key = meta.keys.find((key) => key.source === FUNCTIONS_META_KEY);\n if (key) {\n if (key.id !== functionUrl) {\n throw new Error('Metadata mismatch');\n }\n } else {\n meta.keys.push({ source: FUNCTIONS_META_KEY, id: functionUrl });\n }\n};\n\nexport const getInvocationUrl = (functionUrl: string, edgeUrl: string, options: InvocationOptions = {}) => {\n const baseUrl = new URL('functions/', edgeUrl);\n\n // Leading slashes cause the URL to be treated as an absolute path.\n const relativeUrl = functionUrl.replace(/^\\//, '');\n const url = new URL(`./${relativeUrl}`, baseUrl.toString());\n options.spaceId && url.searchParams.set('spaceId', options.spaceId);\n options.subjectId && url.searchParams.set('subjectId', options.subjectId);\n url.protocol = isSecure(url.protocol) ? 'https' : 'http';\n return url.toString();\n};\n\nexport type InvocationOptions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,aAAa;AAC/C;AAEO,IAAMC,+BAA+B,CAACjE,SAAAA;AAC3C,SAAOA,KAAKkE,KAAKC,KAAK,CAACjF,QAAQA,IAAItC,WAAWiH,kBAAAA,GAAqBzC;AACrE;AAEO,IAAMgD,+BAA+B,CAACpE,MAAkBqE,gBAAAA;AAC7D,QAAMnF,MAAMc,KAAKkE,KAAKC,KAAK,CAACjF,SAAQA,KAAItC,WAAWiH,kBAAAA;AACnD,MAAI3E,KAAK;AACP,QAAIA,IAAIkC,OAAOiD,aAAa;AAC1B,YAAM,IAAIC,MAAM,mBAAA;IAClB;EACF,OAAO;AACLtE,SAAKkE,KAAKP,KAAK;MAAE/G,QAAQiH;MAAoBzC,IAAIiD;IAAY,CAAA;EAC/D;AACF;AAEO,IAAME,mBAAmB,CAACF,aAAqBG,SAAiBjF,UAA6B,CAAC,MAAC;AACpG,QAAMkF,UAAU,IAAIC,IAAI,cAAcF,OAAAA;AAGtC,QAAMG,cAAcN,YAAYO,QAAQ,OAAO,EAAA;AAC/C,QAAMC,MAAM,IAAIH,IAAI,KAAKC,WAAAA,IAAeF,QAAQK,SAAQ,CAAA;AACxDvF,UAAQwF,WAAWF,IAAIG,aAAa7B,IAAI,WAAW5D,QAAQwF,OAAO;AAClExF,UAAQ0F,aAAaJ,IAAIG,aAAa7B,IAAI,aAAa5D,QAAQ0F,SAAS;AACxEJ,MAAIb,WAAWD,SAASc,IAAIb,QAAQ,IAAI,UAAU;AAClD,SAAOa,IAAIC,SAAQ;AACrB;",
6
+ "names": ["import_echo_schema", "ScriptType", "S", "Struct", "name", "optional", "String", "description", "changed", "Boolean", "source", "Ref", "TextType", "annotations", "LabelAnnotationId", "pipe", "EchoObject", "typename", "version", "FunctionType", "TypedObject", "NonEmptyString", "inputSchema", "JsonSchemaType", "outputSchema", "binding", "TriggerKind", "typeLiteralAnnotations", "AST", "TitleAnnotationId", "TimerTriggerSchema", "type", "Literal", "cron", "ExamplesAnnotationId", "mutable", "EmailTriggerSchema", "QueueTriggerSchema", "queue", "DXN", "WebhookTriggerSchema", "method", "OptionsAnnotationId", "port", "Number", "QuerySchema", "props", "Record", "key", "value", "Any", "SubscriptionTriggerSchema", "filter", "options", "deep", "delay", "TriggerSchema", "Union", "FunctionTriggerSchema", "function", "enabled", "spec", "meta", "FunctionTrigger", "fields", "FunctionDef", "uri", "route", "handler", "FunctionManifestSchema", "functions", "Array", "RawObject", "triggers", "FUNCTION_TYPES", "InvocationOutcome", "InvocationTraceEventType", "TraceEventException", "timestampMs", "message", "stack", "InvocationTraceStartEvent", "id", "ObjectId", "invocationId", "input", "Object", "invocationTraceQueue", "Expando", "invocationTarget", "trigger", "InvocationTraceEndEvent", "outcome", "Enums", "exception", "TraceEventLog", "level", "context", "TraceEvent", "truncated", "ingestionTimestampMs", "logs", "exceptions", "createInvocationSpans", "items", "eventsByInvocationId", "Map", "event", "entry", "get", "start", "undefined", "end", "set", "now", "Date", "result", "entries", "log", "warn", "isInProgress", "push", "durationMs", "FUNCTIONS_META_KEY", "FUNCTIONS_PRESET_META_KEY", "isSecure", "protocol", "getUserFunctionUrlInMetadata", "keys", "find", "setUserFunctionUrlInMetadata", "functionUrl", "Error", "getInvocationUrl", "edgeUrl", "baseUrl", "URL", "relativeUrl", "replace", "url", "toString", "spaceId", "searchParams", "subjectId"]
7
+ }
@@ -16,19 +16,19 @@ var __copyProps = (to, from, except, desc) => {
16
16
  return to;
17
17
  };
18
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
- var chunk_D4T2DS7U_exports = {};
20
- __export(chunk_D4T2DS7U_exports, {
19
+ var chunk_NXZNXVT3_exports = {};
20
+ __export(chunk_NXZNXVT3_exports, {
21
21
  incrementSemverPatch: () => incrementSemverPatch,
22
22
  publicKeyToDid: () => publicKeyToDid,
23
23
  uploadWorkerFunction: () => uploadWorkerFunction
24
24
  });
25
- module.exports = __toCommonJS(chunk_D4T2DS7U_exports);
25
+ module.exports = __toCommonJS(chunk_NXZNXVT3_exports);
26
26
  var import_edge = require("@dxos/client/edge");
27
27
  var import_edge_client = require("@dxos/edge-client");
28
28
  var import_invariant = require("@dxos/invariant");
29
29
  var import_log = require("@dxos/log");
30
30
  var __dxlog_file = "/home/runner/work/dxos/dxos/packages/core/functions/src/edge/functions.ts";
31
- var uploadWorkerFunction = async ({ client, name, version, source, spaceId, functionId }) => {
31
+ var uploadWorkerFunction = async ({ client, spaceId, version, source, name, functionId }) => {
32
32
  const edgeUrl = client.config.values.runtime?.services?.edge?.url;
33
33
  (0, import_invariant.invariant)(edgeUrl, "Edge is not configured.", {
34
34
  F: __dxlog_file,
@@ -50,15 +50,15 @@ var uploadWorkerFunction = async ({ client, name, version, source, spaceId, func
50
50
  version,
51
51
  script: source
52
52
  });
53
- (0, import_log.log)("Uploaded", {
53
+ import_log.log.info("Uploaded", {
54
+ identityKey: edgeIdentity.identityKey,
54
55
  functionId,
55
- source,
56
56
  name,
57
- identityKey: edgeIdentity.identityKey,
57
+ source: source.length,
58
58
  response
59
59
  }, {
60
60
  F: __dxlog_file,
61
- L: 39,
61
+ L: 40,
62
62
  S: void 0,
63
63
  C: (f, a) => f(...a)
64
64
  });
@@ -67,13 +67,13 @@ var uploadWorkerFunction = async ({ client, name, version, source, spaceId, func
67
67
  var incrementSemverPatch = (version) => {
68
68
  const [major, minor, patch] = version.split(".");
69
69
  const patchNum = Number(patch);
70
- (0, import_invariant.invariant)(!Number.isNaN(patchNum), "Unexpected function version format.", {
70
+ (0, import_invariant.invariant)(!Number.isNaN(patchNum), `Unexpected function version format: ${version}`, {
71
71
  F: __dxlog_file,
72
- L: 53,
72
+ L: 54,
73
73
  S: void 0,
74
74
  A: [
75
75
  "!Number.isNaN(patchNum)",
76
- "'Unexpected function version format.'"
76
+ "`Unexpected function version format: ${version}`"
77
77
  ]
78
78
  });
79
79
  return [
@@ -91,4 +91,4 @@ var publicKeyToDid = (key) => {
91
91
  publicKeyToDid,
92
92
  uploadWorkerFunction
93
93
  });
94
- //# sourceMappingURL=chunk-D4T2DS7U.cjs.map
94
+ //# sourceMappingURL=chunk-NXZNXVT3.cjs.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/edge/functions.ts"],
4
+ "sourcesContent": ["//\n// Copyright 2024 DXOS.org\n//\n\nimport { type DID } from 'iso-did/types';\n\nimport { type Client } from '@dxos/client';\nimport { createEdgeIdentity } from '@dxos/client/edge';\nimport { EdgeHttpClient } from '@dxos/edge-client';\nimport { invariant } from '@dxos/invariant';\nimport type { PublicKey, SpaceId } from '@dxos/keys';\nimport { log } from '@dxos/log';\nimport { type UploadFunctionResponseBody } from '@dxos/protocols';\n\nexport type UploadWorkerArgs = {\n client: Client;\n spaceId: SpaceId;\n source: string;\n version: string;\n name?: string;\n functionId?: string;\n};\n\nexport const uploadWorkerFunction = async ({\n client,\n spaceId,\n version,\n source,\n name,\n functionId,\n}: UploadWorkerArgs): Promise<UploadFunctionResponseBody> => {\n const edgeUrl = client.config.values.runtime?.services?.edge?.url;\n invariant(edgeUrl, 'Edge is not configured.');\n const edgeClient = new EdgeHttpClient(edgeUrl);\n const edgeIdentity = createEdgeIdentity(client);\n edgeClient.setIdentity(edgeIdentity);\n const response = await edgeClient.uploadFunction({ spaceId, functionId }, { name, version, script: source });\n\n // TODO(burdon): Edge service log.\n log.info('Uploaded', {\n identityKey: edgeIdentity.identityKey,\n functionId,\n name,\n source: source.length,\n response,\n });\n\n return response;\n};\n\nexport const incrementSemverPatch = (version: string): string => {\n const [major, minor, patch] = version.split('.');\n const patchNum = Number(patch);\n invariant(!Number.isNaN(patchNum), `Unexpected function version format: ${version}`);\n return [major, minor, String(patchNum + 1)].join('.');\n};\n\n// TODO(burdon): Factor out.\nexport const publicKeyToDid = (key: PublicKey): DID => {\n return `did:key:${key.toHex()}`;\n};\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;AAOA,kBAAmC;AACnC,yBAA+B;AAC/B,uBAA0B;AAE1B,iBAAoB;;AAYb,IAAMA,uBAAuB,OAAO,EACzCC,QACAC,SACAC,SACAC,QACAC,MACAC,WAAU,MACO;AACjB,QAAMC,UAAUN,OAAOO,OAAOC,OAAOC,SAASC,UAAUC,MAAMC;AAC9DC,kCAAUP,SAAS,2BAAA;;;;;;;;;AACnB,QAAMQ,aAAa,IAAIC,kCAAeT,OAAAA;AACtC,QAAMU,mBAAeC,gCAAmBjB,MAAAA;AACxCc,aAAWI,YAAYF,YAAAA;AACvB,QAAMG,WAAW,MAAML,WAAWM,eAAe;IAAEnB;IAASI;EAAW,GAAG;IAAED;IAAMF;IAASmB,QAAQlB;EAAO,CAAA;AAG1GmB,iBAAIC,KAAK,YAAY;IACnBC,aAAaR,aAAaQ;IAC1BnB;IACAD;IACAD,QAAQA,OAAOsB;IACfN;EACF,GAAA;;;;;;AAEA,SAAOA;AACT;AAEO,IAAMO,uBAAuB,CAACxB,YAAAA;AACnC,QAAM,CAACyB,OAAOC,OAAOC,KAAAA,IAAS3B,QAAQ4B,MAAM,GAAA;AAC5C,QAAMC,WAAWC,OAAOH,KAAAA;AACxBhB,kCAAU,CAACmB,OAAOC,MAAMF,QAAAA,GAAW,uCAAuC7B,OAAAA,IAAS;;;;;;;;;AACnF,SAAO;IAACyB;IAAOC;IAAOM,OAAOH,WAAW,CAAA;IAAII,KAAK,GAAA;AACnD;AAGO,IAAMC,iBAAiB,CAACC,QAAAA;AAC7B,SAAO,WAAWA,IAAIC,MAAK,CAAA;AAC7B;",
6
+ "names": ["uploadWorkerFunction", "client", "spaceId", "version", "source", "name", "functionId", "edgeUrl", "config", "values", "runtime", "services", "edge", "url", "invariant", "edgeClient", "EdgeHttpClient", "edgeIdentity", "createEdgeIdentity", "setIdentity", "response", "uploadFunction", "script", "log", "info", "identityKey", "length", "incrementSemverPatch", "major", "minor", "patch", "split", "patchNum", "Number", "isNaN", "String", "join", "publicKeyToDid", "key", "toHex"]
7
+ }
@@ -16,15 +16,15 @@ var __copyProps = (to, from, except, desc) => {
16
16
  return to;
17
17
  };
18
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
- var chunk_ZSHBAXJA_exports = {};
20
- __export(chunk_ZSHBAXJA_exports, {
19
+ var chunk_RXMCVAMJ_exports = {};
20
+ __export(chunk_RXMCVAMJ_exports, {
21
21
  FunctionRegistry: () => FunctionRegistry,
22
22
  TriggerRegistry: () => TriggerRegistry,
23
23
  createSubscriptionTrigger: () => createSubscriptionTrigger,
24
24
  createTimerTrigger: () => createTimerTrigger
25
25
  });
26
- module.exports = __toCommonJS(chunk_ZSHBAXJA_exports);
27
- var import_chunk_UQZH4J6S = require("./chunk-UQZH4J6S.cjs");
26
+ module.exports = __toCommonJS(chunk_RXMCVAMJ_exports);
27
+ var import_chunk_DSUGRAAL = require("./chunk-DSUGRAAL.cjs");
28
28
  var import_async = require("@dxos/async");
29
29
  var import_echo = require("@dxos/client/echo");
30
30
  var import_context = require("@dxos/context");
@@ -85,14 +85,14 @@ var FunctionRegistry = class extends import_context.Resource {
85
85
  if (!functions?.length) {
86
86
  return;
87
87
  }
88
- if (!space.db.graph.schemaRegistry.hasSchema(import_chunk_UQZH4J6S.FunctionDef)) {
88
+ if (!space.db.graph.schemaRegistry.hasSchema(import_chunk_DSUGRAAL.FunctionDef)) {
89
89
  space.db.graph.schemaRegistry.addSchema([
90
- import_chunk_UQZH4J6S.FunctionDef
90
+ import_chunk_DSUGRAAL.FunctionDef
91
91
  ]);
92
92
  }
93
- const { objects: existing } = await space.db.query(import_echo.Filter.schema(import_chunk_UQZH4J6S.FunctionDef)).run();
93
+ const { objects: existing } = await space.db.query(import_echo.Filter.schema(import_chunk_DSUGRAAL.FunctionDef)).run();
94
94
  const { added } = (0, import_util.diff)(existing, functions, (a, b) => a.uri === b.uri);
95
- added.forEach((def) => space.db.add((0, import_echo.create)(import_chunk_UQZH4J6S.FunctionDef, def)));
95
+ added.forEach((def) => space.db.add((0, import_echo.create)(import_chunk_DSUGRAAL.FunctionDef, def)));
96
96
  if (added.length > 0) {
97
97
  await space.db.flush({
98
98
  indexes: true,
@@ -118,7 +118,7 @@ var FunctionRegistry = class extends import_context.Resource {
118
118
  if (this._ctx.disposed) {
119
119
  break;
120
120
  }
121
- this._ctx.onDispose(space.db.query(import_echo.Filter.schema(import_chunk_UQZH4J6S.FunctionDef)).subscribe(({ objects }) => {
121
+ this._ctx.onDispose(space.db.query(import_echo.Filter.schema(import_chunk_DSUGRAAL.FunctionDef)).subscribe(({ objects }) => {
122
122
  const { added } = (0, import_util.diff)(registered, objects, (a, b) => a.uri === b.uri);
123
123
  if (added.length > 0) {
124
124
  registered.push(...added);
@@ -337,9 +337,9 @@ var TriggerRegistry = class extends import_context2.Resource {
337
337
  if (!manifest.triggers?.length) {
338
338
  return;
339
339
  }
340
- if (!space.db.graph.schemaRegistry.hasSchema(import_chunk_UQZH4J6S.FunctionTrigger)) {
340
+ if (!space.db.graph.schemaRegistry.hasSchema(import_chunk_DSUGRAAL.FunctionTrigger)) {
341
341
  space.db.graph.schemaRegistry.addSchema([
342
- import_chunk_UQZH4J6S.FunctionTrigger
342
+ import_chunk_DSUGRAAL.FunctionTrigger
343
343
  ]);
344
344
  }
345
345
  const manifestTriggers = manifest.triggers.map((trigger) => {
@@ -353,11 +353,11 @@ var TriggerRegistry = class extends import_context2.Resource {
353
353
  ].join(":"))
354
354
  ];
355
355
  }
356
- return (0, import_echo3.create)(import_chunk_UQZH4J6S.FunctionTrigger, trigger, {
356
+ return (0, import_echo3.create)(import_chunk_DSUGRAAL.FunctionTrigger, trigger, {
357
357
  keys
358
358
  });
359
359
  });
360
- const { objects: existing } = await space.db.query(import_echo3.Filter.schema(import_chunk_UQZH4J6S.FunctionTrigger)).run();
360
+ const { objects: existing } = await space.db.query(import_echo3.Filter.schema(import_chunk_DSUGRAAL.FunctionTrigger)).run();
361
361
  const { added } = (0, import_util2.diff)(existing, manifestTriggers, import_echo3.compareForeignKeys);
362
362
  added.forEach((trigger) => {
363
363
  space.db.add(trigger);
@@ -392,7 +392,7 @@ var TriggerRegistry = class extends import_context2.Resource {
392
392
  if (this._ctx.disposed) {
393
393
  break;
394
394
  }
395
- this._ctx.onDispose(space.db.query(import_echo3.Filter.schema(import_chunk_UQZH4J6S.FunctionTrigger)).subscribe(async ({ objects: current }) => {
395
+ this._ctx.onDispose(space.db.query(import_echo3.Filter.schema(import_chunk_DSUGRAAL.FunctionTrigger)).subscribe(async ({ objects: current }) => {
396
396
  import_log4.log.info("update", {
397
397
  space: space.key,
398
398
  registered: registered.length,
@@ -493,4 +493,4 @@ var TriggerRegistry = class extends import_context2.Resource {
493
493
  createSubscriptionTrigger,
494
494
  createTimerTrigger
495
495
  });
496
- //# sourceMappingURL=chunk-ZSHBAXJA.cjs.map
496
+ //# sourceMappingURL=chunk-RXMCVAMJ.cjs.map
@@ -18,12 +18,12 @@ var __copyProps = (to, from, except, desc) => {
18
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
19
  var edge_exports = {};
20
20
  __export(edge_exports, {
21
- incrementSemverPatch: () => import_chunk_D4T2DS7U.incrementSemverPatch,
22
- publicKeyToDid: () => import_chunk_D4T2DS7U.publicKeyToDid,
23
- uploadWorkerFunction: () => import_chunk_D4T2DS7U.uploadWorkerFunction
21
+ incrementSemverPatch: () => import_chunk_NXZNXVT3.incrementSemverPatch,
22
+ publicKeyToDid: () => import_chunk_NXZNXVT3.publicKeyToDid,
23
+ uploadWorkerFunction: () => import_chunk_NXZNXVT3.uploadWorkerFunction
24
24
  });
25
25
  module.exports = __toCommonJS(edge_exports);
26
- var import_chunk_D4T2DS7U = require("../chunk-D4T2DS7U.cjs");
26
+ var import_chunk_NXZNXVT3 = require("../chunk-NXZNXVT3.cjs");
27
27
  var import_chunk_JEQ2X3Z6 = require("../chunk-JEQ2X3Z6.cjs");
28
28
  // Annotate the CommonJS export names for ESM import in node:
29
29
  0 && (module.exports = {
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["index.cjs"],
4
- "sourcesContent": ["import {\n incrementSemverPatch,\n publicKeyToDid,\n uploadWorkerFunction\n} from \"../chunk-D4T2DS7U.cjs\";\nimport \"../chunk-JEQ2X3Z6.cjs\";\nexport {\n incrementSemverPatch,\n publicKeyToDid,\n uploadWorkerFunction\n};\n//# sourceMappingURL=index.cjs.map\n"],
4
+ "sourcesContent": ["import {\n incrementSemverPatch,\n publicKeyToDid,\n uploadWorkerFunction\n} from \"../chunk-NXZNXVT3.cjs\";\nimport \"../chunk-JEQ2X3Z6.cjs\";\nexport {\n incrementSemverPatch,\n publicKeyToDid,\n uploadWorkerFunction\n};\n//# sourceMappingURL=index.cjs.map\n"],
5
5
  "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,4BAIO;AACP,4BAAO;",
6
6
  "names": []
7
7
  }
@@ -18,41 +18,41 @@ var __copyProps = (to, from, except, desc) => {
18
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
19
  var node_exports = {};
20
20
  __export(node_exports, {
21
- FUNCTIONS_PRESET_META_KEY: () => import_chunk_UQZH4J6S.FUNCTIONS_PRESET_META_KEY,
22
- FUNCTION_TYPES: () => import_chunk_UQZH4J6S.FUNCTION_TYPES,
23
- FunctionDef: () => import_chunk_UQZH4J6S.FunctionDef,
24
- FunctionManifestSchema: () => import_chunk_UQZH4J6S.FunctionManifestSchema,
25
- FunctionRegistry: () => import_chunk_ZSHBAXJA.FunctionRegistry,
26
- FunctionTrigger: () => import_chunk_UQZH4J6S.FunctionTrigger,
27
- FunctionTriggerSchema: () => import_chunk_UQZH4J6S.FunctionTriggerSchema,
28
- FunctionType: () => import_chunk_UQZH4J6S.FunctionType,
29
- InvocationOutcome: () => import_chunk_UQZH4J6S.InvocationOutcome,
30
- InvocationTraceEndEvent: () => import_chunk_UQZH4J6S.InvocationTraceEndEvent,
31
- InvocationTraceEventType: () => import_chunk_UQZH4J6S.InvocationTraceEventType,
32
- InvocationTraceStartEvent: () => import_chunk_UQZH4J6S.InvocationTraceStartEvent,
33
- ScriptType: () => import_chunk_UQZH4J6S.ScriptType,
34
- TraceEvent: () => import_chunk_UQZH4J6S.TraceEvent,
35
- TraceEventException: () => import_chunk_UQZH4J6S.TraceEventException,
36
- TraceEventLog: () => import_chunk_UQZH4J6S.TraceEventLog,
37
- TriggerKind: () => import_chunk_UQZH4J6S.TriggerKind,
38
- TriggerRegistry: () => import_chunk_ZSHBAXJA.TriggerRegistry,
39
- TriggerSchema: () => import_chunk_UQZH4J6S.TriggerSchema,
40
- createInvocationSpans: () => import_chunk_UQZH4J6S.createInvocationSpans,
41
- createSubscriptionTrigger: () => import_chunk_ZSHBAXJA.createSubscriptionTrigger,
42
- createTimerTrigger: () => import_chunk_ZSHBAXJA.createTimerTrigger,
21
+ FUNCTIONS_PRESET_META_KEY: () => import_chunk_DSUGRAAL.FUNCTIONS_PRESET_META_KEY,
22
+ FUNCTION_TYPES: () => import_chunk_DSUGRAAL.FUNCTION_TYPES,
23
+ FunctionDef: () => import_chunk_DSUGRAAL.FunctionDef,
24
+ FunctionManifestSchema: () => import_chunk_DSUGRAAL.FunctionManifestSchema,
25
+ FunctionRegistry: () => import_chunk_RXMCVAMJ.FunctionRegistry,
26
+ FunctionTrigger: () => import_chunk_DSUGRAAL.FunctionTrigger,
27
+ FunctionTriggerSchema: () => import_chunk_DSUGRAAL.FunctionTriggerSchema,
28
+ FunctionType: () => import_chunk_DSUGRAAL.FunctionType,
29
+ InvocationOutcome: () => import_chunk_DSUGRAAL.InvocationOutcome,
30
+ InvocationTraceEndEvent: () => import_chunk_DSUGRAAL.InvocationTraceEndEvent,
31
+ InvocationTraceEventType: () => import_chunk_DSUGRAAL.InvocationTraceEventType,
32
+ InvocationTraceStartEvent: () => import_chunk_DSUGRAAL.InvocationTraceStartEvent,
33
+ ScriptType: () => import_chunk_DSUGRAAL.ScriptType,
34
+ TraceEvent: () => import_chunk_DSUGRAAL.TraceEvent,
35
+ TraceEventException: () => import_chunk_DSUGRAAL.TraceEventException,
36
+ TraceEventLog: () => import_chunk_DSUGRAAL.TraceEventLog,
37
+ TriggerKind: () => import_chunk_DSUGRAAL.TriggerKind,
38
+ TriggerRegistry: () => import_chunk_RXMCVAMJ.TriggerRegistry,
39
+ TriggerSchema: () => import_chunk_DSUGRAAL.TriggerSchema,
40
+ createInvocationSpans: () => import_chunk_DSUGRAAL.createInvocationSpans,
41
+ createSubscriptionTrigger: () => import_chunk_RXMCVAMJ.createSubscriptionTrigger,
42
+ createTimerTrigger: () => import_chunk_RXMCVAMJ.createTimerTrigger,
43
43
  defineFunction: () => defineFunction,
44
- getInvocationUrl: () => import_chunk_UQZH4J6S.getInvocationUrl,
45
- getUserFunctionUrlInMetadata: () => import_chunk_UQZH4J6S.getUserFunctionUrlInMetadata,
46
- incrementSemverPatch: () => import_chunk_D4T2DS7U.incrementSemverPatch,
47
- publicKeyToDid: () => import_chunk_D4T2DS7U.publicKeyToDid,
48
- setUserFunctionUrlInMetadata: () => import_chunk_UQZH4J6S.setUserFunctionUrlInMetadata,
44
+ getInvocationUrl: () => import_chunk_DSUGRAAL.getInvocationUrl,
45
+ getUserFunctionUrlInMetadata: () => import_chunk_DSUGRAAL.getUserFunctionUrlInMetadata,
46
+ incrementSemverPatch: () => import_chunk_NXZNXVT3.incrementSemverPatch,
47
+ publicKeyToDid: () => import_chunk_NXZNXVT3.publicKeyToDid,
48
+ setUserFunctionUrlInMetadata: () => import_chunk_DSUGRAAL.setUserFunctionUrlInMetadata,
49
49
  subscriptionHandler: () => subscriptionHandler,
50
- uploadWorkerFunction: () => import_chunk_D4T2DS7U.uploadWorkerFunction
50
+ uploadWorkerFunction: () => import_chunk_NXZNXVT3.uploadWorkerFunction
51
51
  });
52
52
  module.exports = __toCommonJS(node_exports);
53
- var import_chunk_D4T2DS7U = require("./chunk-D4T2DS7U.cjs");
54
- var import_chunk_ZSHBAXJA = require("./chunk-ZSHBAXJA.cjs");
55
- var import_chunk_UQZH4J6S = require("./chunk-UQZH4J6S.cjs");
53
+ var import_chunk_NXZNXVT3 = require("./chunk-NXZNXVT3.cjs");
54
+ var import_chunk_RXMCVAMJ = require("./chunk-RXMCVAMJ.cjs");
55
+ var import_chunk_DSUGRAAL = require("./chunk-DSUGRAAL.cjs");
56
56
  var import_chunk_JEQ2X3Z6 = require("./chunk-JEQ2X3Z6.cjs");
57
57
  var import_effect = require("effect");
58
58
  var import_client = require("@dxos/client");