@dxos/functions 0.8.2-main.2f9c567 → 0.8.2-main.36232bc

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 +3 -0
  2. package/dist/lib/browser/bundler/index.mjs.map +1 -1
  3. package/dist/lib/browser/chunk-2YE6S7XY.mjs +360 -0
  4. package/dist/lib/browser/chunk-2YE6S7XY.mjs.map +7 -0
  5. package/dist/lib/browser/chunk-7CHDHCV3.mjs +482 -0
  6. package/dist/lib/browser/chunk-7CHDHCV3.mjs.map +7 -0
  7. package/dist/lib/browser/chunk-LT4LR4VU.mjs +72 -0
  8. package/dist/lib/browser/chunk-LT4LR4VU.mjs.map +7 -0
  9. package/dist/lib/browser/chunk-XRCXIG74.mjs +12 -0
  10. package/dist/lib/browser/chunk-XRCXIG74.mjs.map +7 -0
  11. package/dist/lib/browser/edge/index.mjs +7 -63
  12. package/dist/lib/browser/edge/index.mjs.map +4 -4
  13. package/dist/lib/browser/index.mjs +99 -367
  14. package/dist/lib/browser/index.mjs.map +4 -4
  15. package/dist/lib/browser/meta.json +1 -1
  16. package/dist/lib/browser/testing/index.mjs +670 -0
  17. package/dist/lib/browser/testing/index.mjs.map +7 -0
  18. package/dist/lib/browser/types/index.mjs +51 -0
  19. package/dist/lib/browser/types/index.mjs.map +7 -0
  20. package/dist/lib/node/bundler/index.cjs +1 -0
  21. package/dist/lib/node/bundler/index.cjs.map +1 -1
  22. package/dist/lib/node/chunk-FBIUZ7SD.cjs +496 -0
  23. package/dist/lib/node/chunk-FBIUZ7SD.cjs.map +7 -0
  24. package/dist/lib/node/chunk-JEQ2X3Z6.cjs +34 -0
  25. package/dist/lib/node/chunk-JEQ2X3Z6.cjs.map +7 -0
  26. package/dist/lib/node/chunk-NXZNXVT3.cjs +94 -0
  27. package/dist/lib/node/chunk-NXZNXVT3.cjs.map +7 -0
  28. package/dist/lib/node/chunk-SV5NRE5L.cjs +395 -0
  29. package/dist/lib/node/chunk-SV5NRE5L.cjs.map +7 -0
  30. package/dist/lib/node/edge/index.cjs +5 -65
  31. package/dist/lib/node/edge/index.cjs.map +4 -4
  32. package/dist/lib/node/index.cjs +94 -382
  33. package/dist/lib/node/index.cjs.map +4 -4
  34. package/dist/lib/node/meta.json +1 -1
  35. package/dist/lib/node/testing/index.cjs +687 -0
  36. package/dist/lib/node/testing/index.cjs.map +7 -0
  37. package/dist/lib/node/types/index.cjs +72 -0
  38. package/dist/lib/node/types/index.cjs.map +7 -0
  39. package/dist/lib/node-esm/bundler/index.mjs +1 -0
  40. package/dist/lib/node-esm/bundler/index.mjs.map +1 -1
  41. package/dist/lib/node-esm/chunk-3XMJFSID.mjs +360 -0
  42. package/dist/lib/node-esm/chunk-3XMJFSID.mjs.map +7 -0
  43. package/dist/lib/node-esm/chunk-C6YINTWG.mjs +482 -0
  44. package/dist/lib/node-esm/chunk-C6YINTWG.mjs.map +7 -0
  45. package/dist/lib/node-esm/chunk-DHGBFXSZ.mjs +12 -0
  46. package/dist/lib/node-esm/chunk-DHGBFXSZ.mjs.map +7 -0
  47. package/dist/lib/node-esm/chunk-O2SXVYU5.mjs +72 -0
  48. package/dist/lib/node-esm/chunk-O2SXVYU5.mjs.map +7 -0
  49. package/dist/lib/node-esm/edge/index.mjs +6 -64
  50. package/dist/lib/node-esm/edge/index.mjs.map +4 -4
  51. package/dist/lib/node-esm/index.mjs +97 -367
  52. package/dist/lib/node-esm/index.mjs.map +4 -4
  53. package/dist/lib/node-esm/meta.json +1 -1
  54. package/dist/lib/node-esm/testing/index.mjs +670 -0
  55. package/dist/lib/node-esm/testing/index.mjs.map +7 -0
  56. package/dist/lib/node-esm/types/index.mjs +51 -0
  57. package/dist/lib/node-esm/types/index.mjs.map +7 -0
  58. package/dist/types/src/browser/index.d.ts +2 -0
  59. package/dist/types/src/browser/index.d.ts.map +1 -0
  60. package/dist/types/src/edge/index.d.ts.map +1 -1
  61. package/dist/types/src/function/function-registry.d.ts +25 -0
  62. package/dist/types/src/function/function-registry.d.ts.map +1 -0
  63. package/dist/types/src/function/function-registry.test.d.ts +2 -0
  64. package/dist/types/src/function/function-registry.test.d.ts.map +1 -0
  65. package/dist/types/src/function/index.d.ts +2 -0
  66. package/dist/types/src/function/index.d.ts.map +1 -0
  67. package/dist/types/src/handler.d.ts +61 -12
  68. package/dist/types/src/handler.d.ts.map +1 -1
  69. package/dist/types/src/index.d.ts +3 -3
  70. package/dist/types/src/index.d.ts.map +1 -1
  71. package/dist/types/src/runtime/dev-server.d.ts +52 -0
  72. package/dist/types/src/runtime/dev-server.d.ts.map +1 -0
  73. package/dist/types/src/runtime/dev-server.test.d.ts +2 -0
  74. package/dist/types/src/runtime/dev-server.test.d.ts.map +1 -0
  75. package/dist/types/src/runtime/index.d.ts +3 -0
  76. package/dist/types/src/runtime/index.d.ts.map +1 -0
  77. package/dist/types/src/runtime/scheduler.d.ts +34 -0
  78. package/dist/types/src/runtime/scheduler.d.ts.map +1 -0
  79. package/dist/types/src/runtime/scheduler.test.d.ts +2 -0
  80. package/dist/types/src/runtime/scheduler.test.d.ts.map +1 -0
  81. package/dist/types/src/testing/functions-integration.test.d.ts +2 -0
  82. package/dist/types/src/testing/functions-integration.test.d.ts.map +1 -0
  83. package/dist/types/src/testing/index.d.ts +5 -0
  84. package/dist/types/src/testing/index.d.ts.map +1 -0
  85. package/dist/types/src/testing/manifest.d.ts +3 -0
  86. package/dist/types/src/testing/manifest.d.ts.map +1 -0
  87. package/dist/types/src/testing/plugin-init.d.ts +6 -0
  88. package/dist/types/src/testing/plugin-init.d.ts.map +1 -0
  89. package/dist/types/src/testing/setup.d.ts +15 -0
  90. package/dist/types/src/testing/setup.d.ts.map +1 -0
  91. package/dist/types/src/testing/test/handler.d.ts +4 -0
  92. package/dist/types/src/testing/test/handler.d.ts.map +1 -0
  93. package/dist/types/src/testing/test/index.d.ts +3 -0
  94. package/dist/types/src/testing/test/index.d.ts.map +1 -0
  95. package/dist/types/src/testing/types.d.ts +10 -0
  96. package/dist/types/src/testing/types.d.ts.map +1 -0
  97. package/dist/types/src/testing/util.d.ts +5 -0
  98. package/dist/types/src/testing/util.d.ts.map +1 -0
  99. package/dist/types/src/trigger/index.d.ts +3 -0
  100. package/dist/types/src/trigger/index.d.ts.map +1 -0
  101. package/dist/types/src/trigger/trigger-registry.d.ts +38 -0
  102. package/dist/types/src/trigger/trigger-registry.d.ts.map +1 -0
  103. package/dist/types/src/trigger/trigger-registry.test.d.ts +2 -0
  104. package/dist/types/src/trigger/trigger-registry.test.d.ts.map +1 -0
  105. package/dist/types/src/trigger/type/index.d.ts +3 -0
  106. package/dist/types/src/trigger/type/index.d.ts.map +1 -0
  107. package/dist/types/src/trigger/type/subscription-trigger.d.ts +4 -0
  108. package/dist/types/src/trigger/type/subscription-trigger.d.ts.map +1 -0
  109. package/dist/types/src/trigger/type/timer-trigger.d.ts +4 -0
  110. package/dist/types/src/trigger/type/timer-trigger.d.ts.map +1 -0
  111. package/dist/types/src/trigger/type/webhook-trigger.d.ts +4 -0
  112. package/dist/types/src/trigger/type/webhook-trigger.d.ts.map +1 -0
  113. package/dist/types/src/types/index.d.ts +5 -0
  114. package/dist/types/src/types/index.d.ts.map +1 -0
  115. package/dist/types/src/types/schema.d.ts +53 -0
  116. package/dist/types/src/types/schema.d.ts.map +1 -0
  117. package/dist/types/src/types/trace.d.ts +146 -0
  118. package/dist/types/src/types/trace.d.ts.map +1 -0
  119. package/dist/types/src/{types.d.ts → types/types.d.ts} +49 -191
  120. package/dist/types/src/types/types.d.ts.map +1 -0
  121. package/dist/types/src/types/url.d.ts.map +1 -0
  122. package/dist/types/tools/schema.d.ts +2 -0
  123. package/dist/types/tools/schema.d.ts.map +1 -0
  124. package/package.json +36 -20
  125. package/schema/functions.json +211 -0
  126. package/src/browser/index.ts +5 -0
  127. package/src/edge/index.ts +0 -4
  128. package/src/function/function-registry.test.ts +118 -0
  129. package/src/function/function-registry.ts +104 -0
  130. package/src/function/index.ts +5 -0
  131. package/src/handler.ts +118 -14
  132. package/src/index.ts +5 -4
  133. package/src/runtime/dev-server.test.ts +79 -0
  134. package/src/runtime/dev-server.ts +240 -0
  135. package/src/runtime/index.ts +6 -0
  136. package/src/runtime/scheduler.test.ts +152 -0
  137. package/src/runtime/scheduler.ts +170 -0
  138. package/src/testing/functions-integration.test.ts +65 -0
  139. package/src/testing/index.ts +8 -0
  140. package/src/testing/manifest.ts +15 -0
  141. package/src/testing/plugin-init.ts +20 -0
  142. package/src/testing/setup.ts +109 -0
  143. package/src/testing/test/handler.ts +15 -0
  144. package/src/testing/test/index.ts +7 -0
  145. package/src/testing/types.ts +9 -0
  146. package/src/testing/util.ts +26 -0
  147. package/src/translations.ts +1 -1
  148. package/src/trigger/index.ts +6 -0
  149. package/src/trigger/trigger-registry.test.ts +278 -0
  150. package/src/trigger/trigger-registry.ts +218 -0
  151. package/src/trigger/type/index.ts +7 -0
  152. package/src/trigger/type/subscription-trigger.ts +84 -0
  153. package/src/trigger/type/timer-trigger.ts +48 -0
  154. package/src/trigger/type/webhook-trigger.ts +48 -0
  155. package/src/types/index.ts +8 -0
  156. package/src/types/schema.ts +46 -0
  157. package/src/{trace.ts → types/trace.ts} +31 -33
  158. package/src/types/types.ts +163 -0
  159. package/dist/types/src/schema.d.ts +0 -57
  160. package/dist/types/src/schema.d.ts.map +0 -1
  161. package/dist/types/src/trace.d.ts +0 -148
  162. package/dist/types/src/trace.d.ts.map +0 -1
  163. package/dist/types/src/types.d.ts.map +0 -1
  164. package/dist/types/src/url.d.ts.map +0 -1
  165. package/src/schema.ts +0 -53
  166. package/src/types.ts +0 -214
  167. /package/dist/types/src/{url.d.ts → types/url.d.ts} +0 -0
  168. /package/src/{url.ts → types/url.ts} +0 -0
@@ -0,0 +1,94 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var chunk_NXZNXVT3_exports = {};
20
+ __export(chunk_NXZNXVT3_exports, {
21
+ incrementSemverPatch: () => incrementSemverPatch,
22
+ publicKeyToDid: () => publicKeyToDid,
23
+ uploadWorkerFunction: () => uploadWorkerFunction
24
+ });
25
+ module.exports = __toCommonJS(chunk_NXZNXVT3_exports);
26
+ var import_edge = require("@dxos/client/edge");
27
+ var import_edge_client = require("@dxos/edge-client");
28
+ var import_invariant = require("@dxos/invariant");
29
+ var import_log = require("@dxos/log");
30
+ var __dxlog_file = "/home/runner/work/dxos/dxos/packages/core/functions/src/edge/functions.ts";
31
+ var uploadWorkerFunction = async ({ client, spaceId, version, source, name, functionId }) => {
32
+ const edgeUrl = client.config.values.runtime?.services?.edge?.url;
33
+ (0, import_invariant.invariant)(edgeUrl, "Edge is not configured.", {
34
+ F: __dxlog_file,
35
+ L: 33,
36
+ S: void 0,
37
+ A: [
38
+ "edgeUrl",
39
+ "'Edge is not configured.'"
40
+ ]
41
+ });
42
+ const edgeClient = new import_edge_client.EdgeHttpClient(edgeUrl);
43
+ const edgeIdentity = (0, import_edge.createEdgeIdentity)(client);
44
+ edgeClient.setIdentity(edgeIdentity);
45
+ const response = await edgeClient.uploadFunction({
46
+ spaceId,
47
+ functionId
48
+ }, {
49
+ name,
50
+ version,
51
+ script: source
52
+ });
53
+ import_log.log.info("Uploaded", {
54
+ identityKey: edgeIdentity.identityKey,
55
+ functionId,
56
+ name,
57
+ source: source.length,
58
+ response
59
+ }, {
60
+ F: __dxlog_file,
61
+ L: 40,
62
+ S: void 0,
63
+ C: (f, a) => f(...a)
64
+ });
65
+ return response;
66
+ };
67
+ var incrementSemverPatch = (version) => {
68
+ const [major, minor, patch] = version.split(".");
69
+ const patchNum = Number(patch);
70
+ (0, import_invariant.invariant)(!Number.isNaN(patchNum), `Unexpected function version format: ${version}`, {
71
+ F: __dxlog_file,
72
+ L: 54,
73
+ S: void 0,
74
+ A: [
75
+ "!Number.isNaN(patchNum)",
76
+ "`Unexpected function version format: ${version}`"
77
+ ]
78
+ });
79
+ return [
80
+ major,
81
+ minor,
82
+ String(patchNum + 1)
83
+ ].join(".");
84
+ };
85
+ var publicKeyToDid = (key) => {
86
+ return `did:key:${key.toHex()}`;
87
+ };
88
+ // Annotate the CommonJS export names for ESM import in node:
89
+ 0 && (module.exports = {
90
+ incrementSemverPatch,
91
+ publicKeyToDid,
92
+ uploadWorkerFunction
93
+ });
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
+ }
@@ -0,0 +1,395 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var chunk_SV5NRE5L_exports = {};
20
+ __export(chunk_SV5NRE5L_exports, {
21
+ FUNCTIONS_PRESET_META_KEY: () => FUNCTIONS_PRESET_META_KEY,
22
+ FUNCTION_TYPES: () => FUNCTION_TYPES,
23
+ FunctionDef: () => FunctionDef,
24
+ FunctionManifestSchema: () => FunctionManifestSchema,
25
+ FunctionTrigger: () => FunctionTrigger,
26
+ FunctionTriggerSchema: () => FunctionTriggerSchema,
27
+ FunctionType: () => FunctionType,
28
+ InvocationOutcome: () => InvocationOutcome,
29
+ InvocationTraceEndEvent: () => InvocationTraceEndEvent,
30
+ InvocationTraceEventType: () => InvocationTraceEventType,
31
+ InvocationTraceStartEvent: () => InvocationTraceStartEvent,
32
+ ScriptType: () => ScriptType,
33
+ TraceEvent: () => TraceEvent,
34
+ TraceEventException: () => TraceEventException,
35
+ TraceEventLog: () => TraceEventLog,
36
+ TriggerKind: () => TriggerKind,
37
+ TriggerSchema: () => TriggerSchema,
38
+ createInvocationSpans: () => createInvocationSpans,
39
+ getInvocationUrl: () => getInvocationUrl,
40
+ getUserFunctionUrlInMetadata: () => getUserFunctionUrlInMetadata,
41
+ makeFunctionUrl: () => makeFunctionUrl,
42
+ setUserFunctionUrlInMetadata: () => setUserFunctionUrlInMetadata
43
+ });
44
+ module.exports = __toCommonJS(chunk_SV5NRE5L_exports);
45
+ var import_echo_schema = require("@dxos/echo-schema");
46
+ var import_schema = require("@dxos/schema");
47
+ var import_echo_schema2 = require("@dxos/echo-schema");
48
+ var import_echo_schema3 = require("@dxos/echo-schema");
49
+ var import_log = require("@dxos/log");
50
+ var ScriptType = import_echo_schema.S.Struct({
51
+ name: import_echo_schema.S.optional(import_echo_schema.S.String),
52
+ description: import_echo_schema.S.optional(import_echo_schema.S.String),
53
+ // TODO(burdon): Change to hash of deployed content.
54
+ // Whether source has changed since last deploy.
55
+ changed: import_echo_schema.S.optional(import_echo_schema.S.Boolean),
56
+ source: (0, import_echo_schema.Ref)(import_schema.TextType)
57
+ }).annotations({
58
+ [import_echo_schema.LabelAnnotationId]: "name"
59
+ }).pipe((0, import_echo_schema.EchoObject)({
60
+ typename: "dxos.org/type/Script",
61
+ version: "0.1.0"
62
+ }));
63
+ var FunctionType = class extends (0, import_echo_schema.TypedObject)({
64
+ typename: "dxos.org/type/Function",
65
+ version: "0.1.0"
66
+ })({
67
+ // TODO(burdon): Rename to id/uri?
68
+ name: import_echo_schema.S.NonEmptyString,
69
+ version: import_echo_schema.S.String,
70
+ description: import_echo_schema.S.optional(import_echo_schema.S.String),
71
+ // Reference to a source script if it exists within ECHO.
72
+ // TODO(burdon): Don't ref ScriptType directly (core).
73
+ source: import_echo_schema.S.optional((0, import_echo_schema.Ref)(ScriptType)),
74
+ inputSchema: import_echo_schema.S.optional(import_echo_schema.JsonSchemaType),
75
+ outputSchema: import_echo_schema.S.optional(import_echo_schema.JsonSchemaType),
76
+ // Local binding to a function name.
77
+ binding: import_echo_schema.S.optional(import_echo_schema.S.String)
78
+ }) {
79
+ };
80
+ var TriggerKind;
81
+ (function(TriggerKind2) {
82
+ TriggerKind2["Timer"] = "timer";
83
+ TriggerKind2["Webhook"] = "webhook";
84
+ TriggerKind2["Subscription"] = "subscription";
85
+ TriggerKind2["Email"] = "email";
86
+ TriggerKind2["Queue"] = "queue";
87
+ })(TriggerKind || (TriggerKind = {}));
88
+ var typeLiteralAnnotations = {
89
+ [import_echo_schema2.AST.TitleAnnotationId]: "Type"
90
+ };
91
+ var TimerTriggerSchema = import_echo_schema2.S.Struct({
92
+ type: import_echo_schema2.S.Literal("timer").annotations(typeLiteralAnnotations),
93
+ cron: import_echo_schema2.S.String.annotations({
94
+ [import_echo_schema2.AST.TitleAnnotationId]: "Cron",
95
+ [import_echo_schema2.AST.ExamplesAnnotationId]: [
96
+ "0 0 * * *"
97
+ ]
98
+ })
99
+ }).pipe(import_echo_schema2.S.mutable);
100
+ var EmailTriggerSchema = import_echo_schema2.S.Struct({
101
+ type: import_echo_schema2.S.Literal("email").annotations(typeLiteralAnnotations)
102
+ }).pipe(import_echo_schema2.S.mutable);
103
+ var QueueTriggerSchema = import_echo_schema2.S.Struct({
104
+ type: import_echo_schema2.S.Literal("queue").annotations(typeLiteralAnnotations),
105
+ queue: import_echo_schema2.DXN
106
+ }).pipe(import_echo_schema2.S.mutable);
107
+ var WebhookTriggerSchema = import_echo_schema2.S.Struct({
108
+ type: import_echo_schema2.S.Literal("webhook").annotations(typeLiteralAnnotations),
109
+ method: import_echo_schema2.S.optional(import_echo_schema2.S.String.annotations({
110
+ [import_echo_schema2.AST.TitleAnnotationId]: "Method",
111
+ [import_echo_schema2.OptionsAnnotationId]: [
112
+ "GET",
113
+ "POST"
114
+ ]
115
+ })),
116
+ port: import_echo_schema2.S.optional(import_echo_schema2.S.Number.annotations({
117
+ [import_echo_schema2.AST.TitleAnnotationId]: "Port"
118
+ }))
119
+ }).pipe(import_echo_schema2.S.mutable);
120
+ var QuerySchema = import_echo_schema2.S.Struct({
121
+ type: import_echo_schema2.S.optional(import_echo_schema2.S.String.annotations({
122
+ [import_echo_schema2.AST.TitleAnnotationId]: "Type"
123
+ })),
124
+ props: import_echo_schema2.S.optional(import_echo_schema2.S.Record({
125
+ key: import_echo_schema2.S.String,
126
+ value: import_echo_schema2.S.Any
127
+ }))
128
+ }).annotations({
129
+ [import_echo_schema2.AST.TitleAnnotationId]: "Query"
130
+ });
131
+ var SubscriptionTriggerSchema = import_echo_schema2.S.Struct({
132
+ type: import_echo_schema2.S.Literal("subscription").annotations(typeLiteralAnnotations),
133
+ // TODO(burdon): Define query DSL (from ECHO). Reconcile with Table.Query.
134
+ filter: QuerySchema,
135
+ options: import_echo_schema2.S.optional(import_echo_schema2.S.Struct({
136
+ // Watch changes to object (not just creation).
137
+ deep: import_echo_schema2.S.optional(import_echo_schema2.S.Boolean.annotations({
138
+ [import_echo_schema2.AST.TitleAnnotationId]: "Nested"
139
+ })),
140
+ // Debounce changes (delay in ms).
141
+ delay: import_echo_schema2.S.optional(import_echo_schema2.S.Number.annotations({
142
+ [import_echo_schema2.AST.TitleAnnotationId]: "Delay"
143
+ }))
144
+ }).annotations({
145
+ [import_echo_schema2.AST.TitleAnnotationId]: "Options"
146
+ }))
147
+ }).pipe(import_echo_schema2.S.mutable);
148
+ var TriggerSchema = import_echo_schema2.S.Union(TimerTriggerSchema, WebhookTriggerSchema, SubscriptionTriggerSchema, EmailTriggerSchema, QueueTriggerSchema).annotations({
149
+ [import_echo_schema2.AST.TitleAnnotationId]: "Trigger"
150
+ });
151
+ var FunctionTriggerSchema = import_echo_schema2.S.Struct({
152
+ // TODO(burdon): What type does this reference.
153
+ // TODO(wittjosiah): This should probably be a Ref?
154
+ function: import_echo_schema2.S.optional(import_echo_schema2.S.String.annotations({
155
+ [import_echo_schema2.AST.TitleAnnotationId]: "Function"
156
+ })),
157
+ enabled: import_echo_schema2.S.optional(import_echo_schema2.S.Boolean.annotations({
158
+ [import_echo_schema2.AST.TitleAnnotationId]: "Enabled"
159
+ })),
160
+ // TODO(burdon): Flatten entire schema.
161
+ spec: import_echo_schema2.S.optional(TriggerSchema),
162
+ // TODO(burdon): Get schema as partial from function.
163
+ // TODO(wittjosiah): Rename to payload.
164
+ // The `meta` property is merged into the event data passed to the function.
165
+ meta: import_echo_schema2.S.optional(import_echo_schema2.S.mutable(import_echo_schema2.S.Record({
166
+ key: import_echo_schema2.S.String,
167
+ value: import_echo_schema2.S.Any
168
+ })))
169
+ });
170
+ var FunctionTrigger = class extends (0, import_echo_schema2.TypedObject)({
171
+ typename: "dxos.org/type/FunctionTrigger",
172
+ version: "0.1.0"
173
+ })(FunctionTriggerSchema.fields) {
174
+ };
175
+ var FunctionDef = class extends (0, import_echo_schema2.TypedObject)({
176
+ typename: "dxos.org/type/FunctionDef",
177
+ version: "0.1.0"
178
+ })({
179
+ uri: import_echo_schema2.S.String,
180
+ description: import_echo_schema2.S.optional(import_echo_schema2.S.String),
181
+ route: import_echo_schema2.S.String,
182
+ handler: import_echo_schema2.S.String
183
+ }) {
184
+ };
185
+ var FunctionManifestSchema = import_echo_schema2.S.Struct({
186
+ functions: import_echo_schema2.S.optional(import_echo_schema2.S.mutable(import_echo_schema2.S.Array((0, import_echo_schema2.RawObject)(FunctionDef)))),
187
+ triggers: import_echo_schema2.S.optional(import_echo_schema2.S.mutable(import_echo_schema2.S.Array((0, import_echo_schema2.RawObject)(FunctionTrigger))))
188
+ });
189
+ var FUNCTION_TYPES = [
190
+ FunctionDef,
191
+ FunctionTrigger
192
+ ];
193
+ var __dxlog_file = "/home/runner/work/dxos/dxos/packages/core/functions/src/types/trace.ts";
194
+ var InvocationOutcome;
195
+ (function(InvocationOutcome2) {
196
+ InvocationOutcome2["SUCCESS"] = "success";
197
+ InvocationOutcome2["FAILURE"] = "failure";
198
+ InvocationOutcome2["PENDING"] = "pending";
199
+ })(InvocationOutcome || (InvocationOutcome = {}));
200
+ var InvocationTraceEventType;
201
+ (function(InvocationTraceEventType2) {
202
+ InvocationTraceEventType2["START"] = "start";
203
+ InvocationTraceEventType2["END"] = "end";
204
+ })(InvocationTraceEventType || (InvocationTraceEventType = {}));
205
+ var TraceEventException = import_echo_schema3.S.Struct({
206
+ timestampMs: import_echo_schema3.S.Number,
207
+ message: import_echo_schema3.S.String,
208
+ name: import_echo_schema3.S.String,
209
+ stack: import_echo_schema3.S.optional(import_echo_schema3.S.String)
210
+ });
211
+ var InvocationTraceStartEvent = import_echo_schema3.S.Struct({
212
+ /**
213
+ * Queue message id.
214
+ */
215
+ id: import_echo_schema3.ObjectId,
216
+ type: import_echo_schema3.S.Literal("start"),
217
+ /**
218
+ * Invocation id, the same for invocation start and end events.
219
+ */
220
+ invocationId: import_echo_schema3.ObjectId,
221
+ /**
222
+ * Event generation time.
223
+ */
224
+ timestampMs: import_echo_schema3.S.Number,
225
+ /**
226
+ * Data passed to function / workflow as an argument.
227
+ */
228
+ // TODO(burdon): Input schema?
229
+ input: import_echo_schema3.S.Object,
230
+ /**
231
+ * Queue DXN for function/workflow invocation events.
232
+ */
233
+ // TODO(burdon): Need reference type for queue. vs. string?
234
+ invocationTraceQueue: (0, import_echo_schema3.Ref)(import_echo_schema3.Expando),
235
+ /**
236
+ * DXN of the invoked function/workflow.
237
+ */
238
+ invocationTarget: (0, import_echo_schema3.Ref)(import_echo_schema3.Expando),
239
+ /**
240
+ * Present for automatic invocations.
241
+ */
242
+ trigger: import_echo_schema3.S.optional((0, import_echo_schema3.Ref)(FunctionTrigger))
243
+ }).pipe((0, import_echo_schema3.EchoObject)({
244
+ typename: "dxos.org/type/InvocationTraceStart",
245
+ version: "0.1.0"
246
+ }));
247
+ var InvocationTraceEndEvent = import_echo_schema3.S.Struct({
248
+ /**
249
+ * Trace event id.
250
+ */
251
+ id: import_echo_schema3.ObjectId,
252
+ type: import_echo_schema3.S.Literal("end"),
253
+ /**
254
+ * Invocation id, will be the same for invocation start and end.
255
+ */
256
+ invocationId: import_echo_schema3.ObjectId,
257
+ /**
258
+ * Event generation time.
259
+ */
260
+ // TODO(burdon): Remove ms suffix.
261
+ timestampMs: import_echo_schema3.S.Number,
262
+ outcome: import_echo_schema3.S.Enums(InvocationOutcome),
263
+ exception: import_echo_schema3.S.optional(TraceEventException)
264
+ }).pipe((0, import_echo_schema3.EchoObject)({
265
+ typename: "dxos.org/type/InvocationTraceEnd",
266
+ version: "0.1.0"
267
+ }));
268
+ var TraceEventLog = import_echo_schema3.S.Struct({
269
+ timestampMs: import_echo_schema3.S.Number,
270
+ level: import_echo_schema3.S.String,
271
+ message: import_echo_schema3.S.String,
272
+ context: import_echo_schema3.S.optional(import_echo_schema3.S.Object)
273
+ });
274
+ var TraceEvent = import_echo_schema3.S.Struct({
275
+ id: import_echo_schema3.ObjectId,
276
+ // TODO(burdon): Need enum/numeric result (not string).
277
+ outcome: import_echo_schema3.S.String,
278
+ truncated: import_echo_schema3.S.Boolean,
279
+ /**
280
+ * Time when the event was persisted.
281
+ */
282
+ ingestionTimestampMs: import_echo_schema3.S.Number,
283
+ logs: import_echo_schema3.S.Array(TraceEventLog),
284
+ exceptions: import_echo_schema3.S.Array(TraceEventException)
285
+ }).pipe((0, import_echo_schema3.EchoObject)({
286
+ typename: "dxos.org/type/TraceEvent",
287
+ version: "0.1.0"
288
+ }));
289
+ var createInvocationSpans = (items) => {
290
+ if (!items) {
291
+ return [];
292
+ }
293
+ const eventsByInvocationId = /* @__PURE__ */ new Map();
294
+ for (const event of items) {
295
+ if (!("invocationId" in event)) {
296
+ continue;
297
+ }
298
+ const invocationId = event.invocationId;
299
+ const entry = eventsByInvocationId.get(invocationId) || {
300
+ start: void 0,
301
+ end: void 0
302
+ };
303
+ if (event.type === "start") {
304
+ entry.start = event;
305
+ } else if (event.type === "end") {
306
+ entry.end = event;
307
+ }
308
+ eventsByInvocationId.set(invocationId, entry);
309
+ }
310
+ const now = Date.now();
311
+ const result = [];
312
+ for (const [invocationId, { start, end }] of eventsByInvocationId.entries()) {
313
+ if (!start) {
314
+ import_log.log.warn("found end event without matching start", {
315
+ invocationId
316
+ }, {
317
+ F: __dxlog_file,
318
+ L: 158,
319
+ S: void 0,
320
+ C: (f, a) => f(...a)
321
+ });
322
+ continue;
323
+ }
324
+ const isInProgress = end === void 0;
325
+ result.push({
326
+ id: invocationId,
327
+ timestampMs: start.timestampMs,
328
+ durationMs: isInProgress ? now - start.timestampMs : end.timestampMs - start.timestampMs,
329
+ outcome: end?.outcome ?? "pending",
330
+ exception: end?.exception,
331
+ input: start.input,
332
+ invocationTraceQueue: start.invocationTraceQueue,
333
+ invocationTarget: start.invocationTarget,
334
+ trigger: start.trigger
335
+ });
336
+ }
337
+ return result;
338
+ };
339
+ var FUNCTIONS_META_KEY = "dxos.org/service/function";
340
+ var FUNCTIONS_PRESET_META_KEY = "dxos.org/service/function-preset";
341
+ var isSecure = (protocol) => {
342
+ return protocol === "https:" || protocol === "wss:";
343
+ };
344
+ var getUserFunctionUrlInMetadata = (meta) => {
345
+ return meta.keys.find((key) => key.source === FUNCTIONS_META_KEY)?.id;
346
+ };
347
+ var setUserFunctionUrlInMetadata = (meta, functionUrl) => {
348
+ const key = meta.keys.find((key2) => key2.source === FUNCTIONS_META_KEY);
349
+ if (key) {
350
+ if (key.id !== functionUrl) {
351
+ throw new Error("Metadata mismatch");
352
+ }
353
+ } else {
354
+ meta.keys.push({
355
+ source: FUNCTIONS_META_KEY,
356
+ id: functionUrl
357
+ });
358
+ }
359
+ };
360
+ var makeFunctionUrl = (spaceId, fn) => `/${spaceId}/${fn.functionId}`;
361
+ var getInvocationUrl = (functionUrl, edgeUrl, options = {}) => {
362
+ const baseUrl = new URL("functions/", edgeUrl);
363
+ const relativeUrl = functionUrl.replace(/^\//, "");
364
+ const url = new URL(`./${relativeUrl}`, baseUrl.toString());
365
+ options.spaceId && url.searchParams.set("spaceId", options.spaceId);
366
+ options.subjectId && url.searchParams.set("subjectId", options.subjectId);
367
+ url.protocol = isSecure(url.protocol) ? "https" : "http";
368
+ return url.toString();
369
+ };
370
+ // Annotate the CommonJS export names for ESM import in node:
371
+ 0 && (module.exports = {
372
+ FUNCTIONS_PRESET_META_KEY,
373
+ FUNCTION_TYPES,
374
+ FunctionDef,
375
+ FunctionManifestSchema,
376
+ FunctionTrigger,
377
+ FunctionTriggerSchema,
378
+ FunctionType,
379
+ InvocationOutcome,
380
+ InvocationTraceEndEvent,
381
+ InvocationTraceEventType,
382
+ InvocationTraceStartEvent,
383
+ ScriptType,
384
+ TraceEvent,
385
+ TraceEventException,
386
+ TraceEventLog,
387
+ TriggerKind,
388
+ TriggerSchema,
389
+ createInvocationSpans,
390
+ getInvocationUrl,
391
+ getUserFunctionUrlInMetadata,
392
+ makeFunctionUrl,
393
+ setUserFunctionUrlInMetadata
394
+ });
395
+ //# sourceMappingURL=chunk-SV5NRE5L.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\n/**\n * NOTE: functionId is backend ID, not ECHO object id.\n */\nexport const makeFunctionUrl = (spaceId: SpaceId, fn: { functionId: string }) => `/${spaceId}/${fn.functionId}`;\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 = {\n spaceId?: SpaceId;\n subjectId?: string;\n};\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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AQA,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;AAKO,IAAME,kBAAkB,CAACC,SAAkBC,OAA+B,IAAID,OAAAA,IAAWC,GAAGC,UAAU;AAEtG,IAAMC,mBAAmB,CAACN,aAAqBO,SAAiBrF,UAA6B,CAAC,MAAC;AACpG,QAAMsF,UAAU,IAAIC,IAAI,cAAcF,OAAAA;AAGtC,QAAMG,cAAcV,YAAYW,QAAQ,OAAO,EAAA;AAC/C,QAAMC,MAAM,IAAIH,IAAI,KAAKC,WAAAA,IAAeF,QAAQK,SAAQ,CAAA;AACxD3F,UAAQiF,WAAWS,IAAIE,aAAahC,IAAI,WAAW5D,QAAQiF,OAAO;AAClEjF,UAAQ6F,aAAaH,IAAIE,aAAahC,IAAI,aAAa5D,QAAQ6F,SAAS;AACxEH,MAAIjB,WAAWD,SAASkB,IAAIjB,QAAQ,IAAI,UAAU;AAClD,SAAOiB,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", "makeFunctionUrl", "spaceId", "fn", "functionId", "getInvocationUrl", "edgeUrl", "baseUrl", "URL", "relativeUrl", "replace", "url", "toString", "searchParams", "subjectId"]
7
+ }
@@ -18,73 +18,13 @@ 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: () => incrementSemverPatch,
22
- publicKeyToDid: () => publicKeyToDid,
23
- uploadWorkerFunction: () => 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_edge = require("@dxos/client/edge");
27
- var import_edge_client = require("@dxos/edge-client");
28
- var import_invariant = require("@dxos/invariant");
29
- var import_log = require("@dxos/log");
30
- var __dxlog_file = "/home/runner/work/dxos/dxos/packages/core/functions/src/edge/functions.ts";
31
- var uploadWorkerFunction = async ({ client, spaceId, version, source, name, functionId }) => {
32
- const edgeUrl = client.config.values.runtime?.services?.edge?.url;
33
- (0, import_invariant.invariant)(edgeUrl, "Edge is not configured.", {
34
- F: __dxlog_file,
35
- L: 33,
36
- S: void 0,
37
- A: [
38
- "edgeUrl",
39
- "'Edge is not configured.'"
40
- ]
41
- });
42
- const edgeClient = new import_edge_client.EdgeHttpClient(edgeUrl);
43
- const edgeIdentity = (0, import_edge.createEdgeIdentity)(client);
44
- edgeClient.setIdentity(edgeIdentity);
45
- const response = await edgeClient.uploadFunction({
46
- spaceId,
47
- functionId
48
- }, {
49
- name,
50
- version,
51
- script: source
52
- });
53
- import_log.log.info("Uploaded", {
54
- identityKey: edgeIdentity.identityKey,
55
- functionId,
56
- name,
57
- source: source.length,
58
- response
59
- }, {
60
- F: __dxlog_file,
61
- L: 40,
62
- S: void 0,
63
- C: (f, a) => f(...a)
64
- });
65
- return response;
66
- };
67
- var incrementSemverPatch = (version) => {
68
- const [major, minor, patch] = version.split(".");
69
- const patchNum = Number(patch);
70
- (0, import_invariant.invariant)(!Number.isNaN(patchNum), `Unexpected function version format: ${version}`, {
71
- F: __dxlog_file,
72
- L: 54,
73
- S: void 0,
74
- A: [
75
- "!Number.isNaN(patchNum)",
76
- "`Unexpected function version format: ${version}`"
77
- ]
78
- });
79
- return [
80
- major,
81
- minor,
82
- String(patchNum + 1)
83
- ].join(".");
84
- };
85
- var publicKeyToDid = (key) => {
86
- return `did:key:${key.toHex()}`;
87
- };
26
+ var import_chunk_NXZNXVT3 = require("../chunk-NXZNXVT3.cjs");
27
+ var import_chunk_JEQ2X3Z6 = require("../chunk-JEQ2X3Z6.cjs");
88
28
  // Annotate the CommonJS export names for ESM import in node:
89
29
  0 && (module.exports = {
90
30
  incrementSemverPatch,
@@ -1,7 +1,7 @@
1
1
  {
2
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"]
3
+ "sources": ["index.cjs"],
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
+ "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,4BAIO;AACP,4BAAO;",
6
+ "names": []
7
7
  }