@dxos/edge-compute 0.0.0

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 (70) hide show
  1. package/LICENSE +105 -0
  2. package/dist/lib/neutral/bundler/index.mjs +213 -0
  3. package/dist/lib/neutral/bundler/index.mjs.map +7 -0
  4. package/dist/lib/neutral/chunk-J5LGTIGS.mjs +10 -0
  5. package/dist/lib/neutral/chunk-J5LGTIGS.mjs.map +7 -0
  6. package/dist/lib/neutral/chunk-RN6KVGN4.mjs +63 -0
  7. package/dist/lib/neutral/chunk-RN6KVGN4.mjs.map +7 -0
  8. package/dist/lib/neutral/index.mjs +343 -0
  9. package/dist/lib/neutral/index.mjs.map +7 -0
  10. package/dist/lib/neutral/meta.json +1 -0
  11. package/dist/lib/neutral/native/index.mjs +186 -0
  12. package/dist/lib/neutral/native/index.mjs.map +7 -0
  13. package/dist/lib/neutral/testing/index.mjs +41 -0
  14. package/dist/lib/neutral/testing/index.mjs.map +7 -0
  15. package/dist/types/src/EdgeOperationInvoker.d.ts +21 -0
  16. package/dist/types/src/EdgeOperationInvoker.d.ts.map +1 -0
  17. package/dist/types/src/EdgeProcessManager.d.ts +14 -0
  18. package/dist/types/src/EdgeProcessManager.d.ts.map +1 -0
  19. package/dist/types/src/EdgeTriggerManager.d.ts +14 -0
  20. package/dist/types/src/EdgeTriggerManager.d.ts.map +1 -0
  21. package/dist/types/src/FunctionsServiceClient.d.ts +65 -0
  22. package/dist/types/src/FunctionsServiceClient.d.ts.map +1 -0
  23. package/dist/types/src/bundler/bundler.d.ts +38 -0
  24. package/dist/types/src/bundler/bundler.d.ts.map +1 -0
  25. package/dist/types/src/bundler/bundler.test.d.ts +2 -0
  26. package/dist/types/src/bundler/bundler.test.d.ts.map +1 -0
  27. package/dist/types/src/bundler/index.d.ts +2 -0
  28. package/dist/types/src/bundler/index.d.ts.map +1 -0
  29. package/dist/types/src/bundler/plugins/embedded-vendored-packages.d.ts +3 -0
  30. package/dist/types/src/bundler/plugins/embedded-vendored-packages.d.ts.map +1 -0
  31. package/dist/types/src/bundler/plugins/http-plugin-esbuild.d.ts +34 -0
  32. package/dist/types/src/bundler/plugins/http-plugin-esbuild.d.ts.map +1 -0
  33. package/dist/types/src/bundler/plugins/index.d.ts +4 -0
  34. package/dist/types/src/bundler/plugins/index.d.ts.map +1 -0
  35. package/dist/types/src/bundler/plugins/r2-vendored-packages.d.ts +5 -0
  36. package/dist/types/src/bundler/plugins/r2-vendored-packages.d.ts.map +1 -0
  37. package/dist/types/src/edge-client.d.ts +39 -0
  38. package/dist/types/src/edge-client.d.ts.map +1 -0
  39. package/dist/types/src/index.d.ts +6 -0
  40. package/dist/types/src/index.d.ts.map +1 -0
  41. package/dist/types/src/native/bundler.d.ts +15 -0
  42. package/dist/types/src/native/bundler.d.ts.map +1 -0
  43. package/dist/types/src/native/index.d.ts +2 -0
  44. package/dist/types/src/native/index.d.ts.map +1 -0
  45. package/dist/types/src/testing/index.d.ts +2 -0
  46. package/dist/types/src/testing/index.d.ts.map +1 -0
  47. package/dist/types/src/testing/logger.d.ts +4 -0
  48. package/dist/types/src/testing/logger.d.ts.map +1 -0
  49. package/dist/types/src/testing/services.d.ts +53 -0
  50. package/dist/types/src/testing/services.d.ts.map +1 -0
  51. package/dist/types/tsconfig.tsbuildinfo +1 -0
  52. package/package.json +95 -0
  53. package/src/EdgeOperationInvoker.ts +65 -0
  54. package/src/EdgeProcessManager.ts +47 -0
  55. package/src/EdgeTriggerManager.ts +70 -0
  56. package/src/FunctionsServiceClient.ts +189 -0
  57. package/src/bundler/bundler.test.ts +108 -0
  58. package/src/bundler/bundler.ts +232 -0
  59. package/src/bundler/index.ts +5 -0
  60. package/src/bundler/plugins/embedded-vendored-packages.ts +39 -0
  61. package/src/bundler/plugins/http-plugin-esbuild.ts +77 -0
  62. package/src/bundler/plugins/index.ts +7 -0
  63. package/src/bundler/plugins/r2-vendored-packages.ts +35 -0
  64. package/src/edge-client.ts +156 -0
  65. package/src/index.ts +9 -0
  66. package/src/native/bundler.ts +231 -0
  67. package/src/native/index.ts +5 -0
  68. package/src/testing/index.ts +5 -0
  69. package/src/testing/logger.ts +14 -0
  70. package/src/testing/services.ts +95 -0
@@ -0,0 +1,343 @@
1
+ import {
2
+ __export
3
+ } from "./chunk-J5LGTIGS.mjs";
4
+
5
+ // src/edge-client.ts
6
+ import * as Array from "effect/Array";
7
+ import * as Function$ from "effect/Function";
8
+ import * as Order from "effect/Order";
9
+ import { createEdgeIdentity } from "@dxos/client/edge";
10
+ import { Operation } from "@dxos/compute";
11
+ import { FUNCTIONS_META_KEY, setUserFunctionIdInMetadata } from "@dxos/compute-runtime";
12
+ import { Obj } from "@dxos/echo";
13
+ import { EdgeHttpClient } from "@dxos/edge-client";
14
+ import { invariant } from "@dxos/invariant";
15
+ import { log } from "@dxos/log";
16
+ import { safeParseJson } from "@dxos/util";
17
+ var __dxlog_file = "/Users/dmaretskyi/Code/dxos/dxos/packages/core/compute/edge-compute/src/edge-client.ts";
18
+ var createEdgeClient = (client) => {
19
+ const edgeUrl = client.config.values.runtime?.services?.edge?.url;
20
+ invariant(edgeUrl, "Edge is not configured.", { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 17, S: void 0, A: ["edgeUrl", "'Edge is not configured.'"] });
21
+ const edgeClient = new EdgeHttpClient(edgeUrl);
22
+ const edgeIdentity = createEdgeIdentity(client);
23
+ edgeClient.setIdentity(edgeIdentity);
24
+ return edgeClient;
25
+ };
26
+ var uploadWorkerFunction = async (ctx, { client, version, name, functionId, ownerUri, entryPoint, assets }) => {
27
+ log("uploading function", {
28
+ functionId,
29
+ name,
30
+ version,
31
+ ownerUri
32
+ }, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 26, S: void 0 });
33
+ const edgeClient = createEdgeClient(client);
34
+ const response = await edgeClient.uploadFunction(ctx, {
35
+ functionId
36
+ }, {
37
+ name,
38
+ version,
39
+ ownerUri,
40
+ entryPoint,
41
+ assets
42
+ });
43
+ log("uploaded", {
44
+ identityKey: client.halo.identity.get()?.identityKey,
45
+ did: client.halo.identity.get()?.did,
46
+ functionId,
47
+ name,
48
+ version,
49
+ response
50
+ }, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 43, S: void 0 });
51
+ return response;
52
+ };
53
+ var getDeployedFunctions = async (ctx, client, dedupe = false) => {
54
+ const edgeClient = createEdgeClient(client);
55
+ const result = await edgeClient.listFunctions(ctx);
56
+ const functions = result.uploadedFunctions.flatMap((record) => {
57
+ const latest = record.latestVersion ?? {};
58
+ const versionMeta = safeParseJson(latest.versionMetaJSON);
59
+ if (!versionMeta) {
60
+ return [];
61
+ }
62
+ const fn = Obj.make(Operation.PersistentOperation, {
63
+ [Obj.Meta]: {
64
+ key: versionMeta.key,
65
+ version: latest?.version ?? "0.0.0"
66
+ },
67
+ name: versionMeta.name ?? versionMeta.key ?? record.id,
68
+ updated: record?.updated !== void 0 ? new Date(record.updated).toISOString() : void 0,
69
+ description: versionMeta.description,
70
+ inputSchema: versionMeta.inputSchema,
71
+ outputSchema: versionMeta.outputSchema
72
+ });
73
+ Obj.update(fn, (fn2) => setUserFunctionIdInMetadata(Obj.getMeta(fn2), record.id));
74
+ return [
75
+ fn
76
+ ];
77
+ });
78
+ if (dedupe) {
79
+ return Function$.pipe(functions, Array.filter((_) => Obj.getMeta(_).key !== void 0), Array.sort(Order.reverse(Order.mapInput(Order.string, (_) => _.updated ?? ""))), Array.dedupeWith((self, that) => Obj.getMeta(self).key === Obj.getMeta(that).key), Array.sort(Order.mapInput(Order.string, (_) => Obj.getMeta(_).key ?? "")));
80
+ } else {
81
+ return functions;
82
+ }
83
+ };
84
+ var invokeFunction = async (ctx, edgeClient, fn, input, { spaceId, cpuTimeLimit, subrequestsLimit } = {}) => {
85
+ const functionId = Obj.getMeta(fn).keys.find((key) => key.source === FUNCTIONS_META_KEY)?.id;
86
+ if (!functionId) {
87
+ throw new Error("No identifier for the function at the EDGE service");
88
+ }
89
+ const cleanedId = functionId.replace(/^\//, "");
90
+ return await edgeClient.invokeFunction(ctx, {
91
+ functionId: cleanedId,
92
+ spaceId,
93
+ cpuTimeLimit,
94
+ subrequestsLimit
95
+ }, input);
96
+ };
97
+ var incrementSemverPatch = (version) => {
98
+ const [major, minor, patch] = version.split(".");
99
+ const patchNum = Number(patch);
100
+ invariant(!Number.isNaN(patchNum), `Unexpected function version format: ${version}`, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 106, S: void 0, A: ["!Number.isNaN(patchNum)", "`Unexpected function version format: ${version}`"] });
101
+ return [
102
+ major,
103
+ minor,
104
+ String(patchNum + 1)
105
+ ].join(".");
106
+ };
107
+ var publicKeyToDid = (key) => {
108
+ return `did:key:${key.toHex()}`;
109
+ };
110
+
111
+ // src/EdgeOperationInvoker.ts
112
+ var EdgeOperationInvoker_exports = {};
113
+ __export(EdgeOperationInvoker_exports, {
114
+ fromClient: () => fromClient,
115
+ fromEdgeClient: () => fromEdgeClient,
116
+ layer: () => layer
117
+ });
118
+ import * as Effect from "effect/Effect";
119
+ import * as Layer from "effect/Layer";
120
+ import { ClientService } from "@dxos/client";
121
+ import { FunctionError } from "@dxos/compute";
122
+ import { RemoteOperationInvoker } from "@dxos/compute-runtime";
123
+ var make = (getEdgeClient, spaceId) => ({
124
+ invoke: (ctx, deployedId, input) => Effect.gen(function* () {
125
+ const cleanedId = deployedId.replace(/^\//, "");
126
+ return yield* Effect.promise(() => getEdgeClient().invokeFunction(ctx, {
127
+ functionId: cleanedId,
128
+ spaceId
129
+ }, input)).pipe(Effect.mapError(FunctionError.wrap()), Effect.orDie);
130
+ })
131
+ });
132
+ var fromEdgeClient = (edgeClient, spaceId) => Layer.succeed(RemoteOperationInvoker.Service, make(() => edgeClient, spaceId));
133
+ var fromClient = (client, spaceId) => {
134
+ let cached;
135
+ return Layer.succeed(RemoteOperationInvoker.Service, make(() => cached ??= createEdgeClient(client), spaceId));
136
+ };
137
+ var layer = (spaceId) => Layer.effect(RemoteOperationInvoker.Service, Effect.gen(function* () {
138
+ const client = yield* ClientService;
139
+ let cached;
140
+ return make(() => cached ??= createEdgeClient(client), spaceId);
141
+ }));
142
+
143
+ // src/EdgeProcessManager.ts
144
+ var EdgeProcessManager_exports = {};
145
+ __export(EdgeProcessManager_exports, {
146
+ fromClient: () => fromClient2,
147
+ layer: () => layer2
148
+ });
149
+ import { Atom, Registry } from "@effect-atom/atom";
150
+ import * as Effect2 from "effect/Effect";
151
+ import * as Layer2 from "effect/Layer";
152
+ import { RemoteProcessManager } from "@dxos/compute-runtime";
153
+ var make2 = () => Layer2.effect(RemoteProcessManager.Service, Effect2.gen(function* () {
154
+ const registry = yield* Registry.AtomRegistry;
155
+ const processTreeAtom = Atom.make([]);
156
+ registry.mount(processTreeAtom);
157
+ return {
158
+ processTree: Effect2.sync(() => registry.get(processTreeAtom)),
159
+ processTreeAtom
160
+ };
161
+ }));
162
+ var fromClient2 = (_client) => make2();
163
+ var layer2 = make2();
164
+
165
+ // src/EdgeTriggerManager.ts
166
+ var EdgeTriggerManager_exports = {};
167
+ __export(EdgeTriggerManager_exports, {
168
+ fromClient: () => fromClient3,
169
+ layer: () => layer3
170
+ });
171
+ import { Atom as Atom2, Registry as Registry2 } from "@effect-atom/atom";
172
+ import * as Effect3 from "effect/Effect";
173
+ import * as Layer3 from "effect/Layer";
174
+ import { ClientService as ClientService2 } from "@dxos/client";
175
+ import { RemoteTriggerManager } from "@dxos/compute-runtime";
176
+ var make3 = (_spaceId) => Layer3.effect(RemoteTriggerManager.Service, Effect3.gen(function* () {
177
+ const registry = yield* Registry2.AtomRegistry;
178
+ const triggers = Atom2.make([]);
179
+ registry.mount(triggers);
180
+ return {
181
+ triggers,
182
+ invokeTrigger: () => Effect3.die(new Error("Remote (EDGE) trigger invocation is not supported"))
183
+ };
184
+ }));
185
+ var fromClient3 = (_client, spaceId) => make3(spaceId);
186
+ var layer3 = (spaceId) => Layer3.effect(RemoteTriggerManager.Service, Effect3.gen(function* () {
187
+ yield* ClientService2;
188
+ const registry = yield* Registry2.AtomRegistry;
189
+ const triggers = Atom2.make([]);
190
+ registry.mount(triggers);
191
+ return {
192
+ triggers,
193
+ invokeTrigger: () => Effect3.die(new Error("Remote (EDGE) trigger invocation is not supported"))
194
+ };
195
+ }));
196
+
197
+ // src/FunctionsServiceClient.ts
198
+ import { FunctionError as FunctionError2, Operation as Operation2 } from "@dxos/compute";
199
+ import { FUNCTIONS_META_KEY as FUNCTIONS_META_KEY2 } from "@dxos/compute-runtime";
200
+ import { FunctionServiceError } from "@dxos/compute-runtime";
201
+ import { Obj as Obj2 } from "@dxos/echo";
202
+ import { invariant as invariant2 } from "@dxos/invariant";
203
+ import { log as log2 } from "@dxos/log";
204
+ import { safeParseJson as safeParseJson2 } from "@dxos/util";
205
+ var __dxlog_file2 = "/Users/dmaretskyi/Code/dxos/dxos/packages/core/compute/edge-compute/src/FunctionsServiceClient.ts";
206
+ var FunctionsServiceClient = class _FunctionsServiceClient {
207
+ static fromClient(client) {
208
+ return new _FunctionsServiceClient(createEdgeClient(client));
209
+ }
210
+ #edgeClient;
211
+ constructor(edgeClient) {
212
+ this.#edgeClient = edgeClient;
213
+ }
214
+ /**
215
+ * Deploys a function to the EDGE service.
216
+ */
217
+ async deploy(ctx, request) {
218
+ try {
219
+ invariant2(Object.keys(request.assets).every((path) => !path.startsWith("/")), "Asset paths must be relative", { "~LogMeta": "~LogMeta", F: __dxlog_file2, L: 24, S: this, A: ["Object.keys(request.assets).every((path)=>!path.startsWith('/'))", "'Asset paths must be relative'"] });
220
+ const response = await this.#edgeClient.uploadFunction(ctx, {
221
+ functionId: request.functionId
222
+ }, {
223
+ name: request.name,
224
+ version: request.version,
225
+ ownerUri: request.ownerUri,
226
+ entryPoint: request.entryPoint,
227
+ assets: request.assets,
228
+ runtime: request.runtime
229
+ }, {
230
+ retry: {
231
+ count: 3
232
+ },
233
+ auth: true
234
+ });
235
+ log2.verbose("deploy result", {
236
+ ...response
237
+ }, { "~LogMeta": "~LogMeta", F: __dxlog_file2, L: 40, S: this });
238
+ return Obj2.make(Operation2.PersistentOperation, {
239
+ [Obj2.Meta]: {
240
+ keys: [
241
+ {
242
+ source: FUNCTIONS_META_KEY2,
243
+ id: response.functionId
244
+ }
245
+ ],
246
+ key: response.meta.key,
247
+ version: response.version
248
+ },
249
+ name: response.meta.name ?? "Unnamed function",
250
+ description: response.meta.description,
251
+ inputSchema: response.meta.inputSchema,
252
+ outputSchema: response.meta.outputSchema
253
+ });
254
+ } catch (error) {
255
+ throw FunctionServiceError.wrap({
256
+ message: "Failed to deploy function",
257
+ ifTypeDiffers: true
258
+ })(error);
259
+ }
260
+ }
261
+ /**
262
+ * Queries the EDGE service for deployed functions.
263
+ */
264
+ // TODO(dmaretskyi): Add query filters.
265
+ async query(ctx) {
266
+ try {
267
+ const response = await this.#edgeClient.listFunctions(ctx);
268
+ return response.uploadedFunctions.flatMap((record) => {
269
+ const latest = record.latestVersion ?? {};
270
+ const versionMeta = safeParseJson2(latest.versionMetaJSON);
271
+ if (!versionMeta) {
272
+ return [];
273
+ }
274
+ const fn = Obj2.make(Operation2.PersistentOperation, {
275
+ [Obj2.Meta]: {
276
+ keys: [
277
+ {
278
+ source: FUNCTIONS_META_KEY2,
279
+ id: record.id
280
+ }
281
+ ],
282
+ key: versionMeta.key,
283
+ version: latest?.version ?? "0.0.0"
284
+ },
285
+ name: versionMeta.name ?? versionMeta.key ?? record.id,
286
+ updated: record?.updated !== void 0 ? new Date(record.updated).toISOString() : void 0,
287
+ description: versionMeta.description,
288
+ inputSchema: versionMeta.inputSchema,
289
+ outputSchema: versionMeta.outputSchema
290
+ });
291
+ return [
292
+ fn
293
+ ];
294
+ });
295
+ } catch (error) {
296
+ throw FunctionServiceError.wrap({
297
+ message: "Failed to query functions",
298
+ ifTypeDiffers: true
299
+ })(error);
300
+ }
301
+ }
302
+ async invoke(ctx, func, input, options) {
303
+ const functionId = Obj2.getMeta(func).keys.find((key) => key.source === FUNCTIONS_META_KEY2)?.id;
304
+ if (!functionId) {
305
+ throw new FunctionServiceError({
306
+ message: "No identifier for the function at the EDGE service"
307
+ });
308
+ }
309
+ const cleanedId = functionId.replace(/^\//, "");
310
+ try {
311
+ return await this.#edgeClient.invokeFunction(ctx, {
312
+ functionId: cleanedId,
313
+ spaceId: options?.spaceId,
314
+ cpuTimeLimit: options?.cpuTimeLimit,
315
+ subrequestsLimit: options?.subrequestsLimit
316
+ }, input);
317
+ } catch (error) {
318
+ throw FunctionError2.wrap({
319
+ message: "Failed to invoke function",
320
+ ifTypeDiffers: true
321
+ })(error);
322
+ }
323
+ }
324
+ async forceRunCronTrigger(ctx, spaceId, triggerId) {
325
+ return await this.#edgeClient.forceRunCronTrigger(ctx, spaceId, triggerId);
326
+ }
327
+ async getTriggersDispatcherStatus(ctx, spaceId) {
328
+ return this.#edgeClient.getTriggersDispatcherStatus(ctx, spaceId);
329
+ }
330
+ };
331
+ export {
332
+ EdgeOperationInvoker_exports as EdgeOperationInvoker,
333
+ EdgeProcessManager_exports as EdgeProcessManager,
334
+ EdgeTriggerManager_exports as EdgeTriggerManager,
335
+ FunctionsServiceClient,
336
+ createEdgeClient,
337
+ getDeployedFunctions,
338
+ incrementSemverPatch,
339
+ invokeFunction,
340
+ publicKeyToDid,
341
+ uploadWorkerFunction
342
+ };
343
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/edge-client.ts", "../../../src/EdgeOperationInvoker.ts", "../../../src/EdgeProcessManager.ts", "../../../src/EdgeTriggerManager.ts", "../../../src/FunctionsServiceClient.ts"],
4
+ "sourcesContent": ["//\n// Copyright 2024 DXOS.org\n//\n\nimport * as Array from 'effect/Array';\nimport * as Function$ from 'effect/Function';\nimport * as Order from 'effect/Order';\nimport { type DID } from 'iso-did/types';\n\nimport { type Client } from '@dxos/client';\nimport { createEdgeIdentity } from '@dxos/client/edge';\nimport { Operation } from '@dxos/compute';\nimport { FUNCTIONS_META_KEY, setUserFunctionIdInMetadata } from '@dxos/compute-runtime';\nimport { Context } from '@dxos/context';\nimport { Obj } from '@dxos/echo';\nimport { EdgeHttpClient } from '@dxos/edge-client';\nimport { invariant } from '@dxos/invariant';\nimport { type PublicKey, type SpaceId } from '@dxos/keys';\nimport { log } from '@dxos/log';\nimport { type UploadFunctionResponseBody } from '@dxos/protocols';\nimport { safeParseJson } from '@dxos/util';\n\n/** @deprecated Use {@link FunctionsServiceClient} instead. */\nexport type UploadWorkerArgs = {\n client: Client;\n version: string;\n name?: string;\n functionId?: string;\n /** Owner identity DID (`did:halo:…`). */\n ownerUri: string;\n entryPoint: string;\n assets: Record<string, Uint8Array>;\n};\n\n/** @deprecated Migrate to `client.edge`. */\nexport const createEdgeClient = (client: Client): EdgeHttpClient => {\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 return edgeClient;\n};\n\n/**\n * @deprecated Use {@link FunctionsServiceClient} instead.\n */\nexport const uploadWorkerFunction = async (\n ctx: Context,\n { client, version, name, functionId, ownerUri, entryPoint, assets }: UploadWorkerArgs,\n): Promise<UploadFunctionResponseBody> => {\n log('uploading function', { functionId, name, version, ownerUri });\n const edgeClient = createEdgeClient(client);\n const response = await edgeClient.uploadFunction(\n ctx,\n { functionId },\n { name, version, ownerUri, entryPoint, assets },\n );\n\n // TODO(burdon): Edge service log.\n log('uploaded', {\n identityKey: client.halo.identity.get()?.identityKey,\n did: client.halo.identity.get()?.did,\n functionId,\n name,\n version,\n response,\n });\n\n return response;\n};\n\n/**\n * @deprecated Use {@link FunctionsServiceClient} instead.\n */\nexport const getDeployedFunctions = async (\n ctx: Context,\n client: Client,\n dedupe = false,\n): Promise<Operation.PersistentOperation[]> => {\n const edgeClient = createEdgeClient(client);\n const result = await edgeClient.listFunctions(ctx);\n const functions: Operation.PersistentOperation[] = result.uploadedFunctions.flatMap((record: any) => {\n // Record shape is determined by EDGE API. We defensively parse.\n const latest = record.latestVersion ?? {};\n const versionMeta = safeParseJson<any>(latest.versionMetaJSON);\n if (!versionMeta) {\n return [];\n }\n const fn = Obj.make(Operation.PersistentOperation, {\n [Obj.Meta]: {\n key: versionMeta.key,\n version: latest?.version ?? '0.0.0',\n },\n name: versionMeta.name ?? versionMeta.key ?? record.id,\n updated: record?.updated !== undefined ? new Date(record.updated).toISOString() : undefined,\n description: versionMeta.description,\n inputSchema: versionMeta.inputSchema,\n outputSchema: versionMeta.outputSchema,\n });\n\n Obj.update(fn, (fn) => setUserFunctionIdInMetadata(Obj.getMeta(fn), record.id));\n return [fn];\n });\n\n if (dedupe) {\n return Function$.pipe(\n functions,\n Array.filter((_) => Obj.getMeta(_).key !== undefined),\n Array.sort(Order.reverse(Order.mapInput(Order.string, (_: Operation.PersistentOperation) => _.updated ?? ''))),\n Array.dedupeWith((self, that) => Obj.getMeta(self).key === Obj.getMeta(that).key),\n Array.sort(Order.mapInput(Order.string, (_: Operation.PersistentOperation) => Obj.getMeta(_).key ?? '')),\n );\n } else {\n return functions;\n }\n};\n\n/**\n * @deprecated Use {@link FunctionsServiceClient} instead.\n */\nexport const invokeFunction = async (\n ctx: Context,\n edgeClient: EdgeHttpClient,\n fn: Operation.PersistentOperation,\n input: unknown,\n {\n spaceId,\n cpuTimeLimit,\n subrequestsLimit,\n }: { spaceId?: SpaceId; cpuTimeLimit?: number; subrequestsLimit?: number } = {},\n) => {\n const functionId = Obj.getMeta(fn).keys.find((key) => key.source === FUNCTIONS_META_KEY)?.id;\n if (!functionId) {\n throw new Error('No identifier for the function at the EDGE service');\n }\n // COMPAT: Previously functionId was a URL `/<guid>`. Now it's just the `<guid>`.\n const cleanedId = functionId.replace(/^\\//, '');\n return await edgeClient.invokeFunction(\n ctx,\n { functionId: cleanedId, spaceId, cpuTimeLimit, subrequestsLimit },\n input,\n );\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", "//\n// Copyright 2026 DXOS.org\n//\n\n// @import-as-namespace\n\nimport * as Effect from 'effect/Effect';\nimport * as Layer from 'effect/Layer';\n\nimport { type Client, ClientService } from '@dxos/client';\nimport { FunctionError } from '@dxos/compute';\nimport { RemoteOperationInvoker } from '@dxos/compute-runtime';\nimport { type Context as DxosContext } from '@dxos/context';\nimport { type SpaceId } from '@dxos/keys';\n\nimport { createEdgeClient } from './edge-client';\n\ntype EdgeClient = ReturnType<typeof createEdgeClient>;\n\nconst make = (getEdgeClient: () => EdgeClient, spaceId?: SpaceId): RemoteOperationInvoker.Invoker => ({\n invoke: <I, O>(ctx: DxosContext, deployedId: string, input: I): Effect.Effect<O> =>\n Effect.gen(function* () {\n const cleanedId = deployedId.replace(/^\\//, '');\n return yield* Effect.promise(() =>\n getEdgeClient().invokeFunction(ctx, { functionId: cleanedId, spaceId }, input),\n ).pipe(Effect.mapError(FunctionError.wrap()), Effect.orDie);\n }),\n});\n\n/**\n * For tests: provide a pre-built edge client.\n */\nexport const fromEdgeClient = (\n edgeClient: EdgeClient,\n spaceId?: SpaceId,\n): Layer.Layer<RemoteOperationInvoker.Service> =>\n Layer.succeed(\n RemoteOperationInvoker.Service,\n make(() => edgeClient, spaceId),\n );\n\n/**\n * Build from a `Client`, deferring edge-client creation until first invoke\n * (identity may be absent at boot).\n */\nexport const fromClient = (client: Client, spaceId?: SpaceId): Layer.Layer<RemoteOperationInvoker.Service> => {\n let cached: EdgeClient | undefined;\n return Layer.succeed(\n RemoteOperationInvoker.Service,\n make(() => (cached ??= createEdgeClient(client)), spaceId),\n );\n};\n\n/**\n * Build from the ambient `ClientService`.\n */\nexport const layer = (spaceId?: SpaceId): Layer.Layer<RemoteOperationInvoker.Service, never, ClientService> =>\n Layer.effect(\n RemoteOperationInvoker.Service,\n Effect.gen(function* () {\n const client = yield* ClientService;\n let cached: EdgeClient | undefined;\n return make(() => (cached ??= createEdgeClient(client)), spaceId);\n }),\n );\n", "//\n// Copyright 2026 DXOS.org\n//\n\n// @import-as-namespace\n\nimport { Atom, Registry } from '@effect-atom/atom';\nimport * as Effect from 'effect/Effect';\nimport * as Layer from 'effect/Layer';\n\nimport { type Client } from '@dxos/client';\nimport { type Process } from '@dxos/compute';\nimport { RemoteProcessManager } from '@dxos/compute-runtime';\n\n/**\n * EDGE implementation of {@link RemoteProcessManager.Service}.\n *\n * The EDGE worker exposes no process-tree endpoint yet (see Decision D3), so\n * this currently returns an empty tree. Once an endpoint lands, poll it into\n * `processTreeAtom` here.\n */\nconst make = (): Layer.Layer<RemoteProcessManager.Service, never, Registry.AtomRegistry> =>\n Layer.effect(\n RemoteProcessManager.Service,\n Effect.gen(function* () {\n const registry = yield* Registry.AtomRegistry;\n // TODO(edge): Populate from an EDGE process-tree endpoint once available.\n const processTreeAtom = Atom.make<readonly Process.Info[]>([]);\n registry.mount(processTreeAtom);\n return {\n processTree: Effect.sync(() => registry.get(processTreeAtom)),\n processTreeAtom,\n } satisfies RemoteProcessManager.Manager;\n }),\n );\n\n/**\n * Build from a `Client`. Currently ignores the client until an EDGE\n * process-tree endpoint exists.\n */\nexport const fromClient = (_client: Client): Layer.Layer<RemoteProcessManager.Service, never, Registry.AtomRegistry> =>\n make();\n\n/**\n * Empty EDGE process manager (no endpoint yet).\n */\nexport const layer: Layer.Layer<RemoteProcessManager.Service, never, Registry.AtomRegistry> = make();\n", "//\n// Copyright 2026 DXOS.org\n//\n\n// @import-as-namespace\n\nimport { Atom, Registry } from '@effect-atom/atom';\nimport * as Effect from 'effect/Effect';\nimport * as Layer from 'effect/Layer';\n\nimport { type Client, ClientService } from '@dxos/client';\nimport { type Trigger } from '@dxos/compute';\nimport { RemoteTriggerManager } from '@dxos/compute-runtime';\nimport { type SpaceId } from '@dxos/keys';\n\n/**\n * EDGE implementation of {@link RemoteTriggerManager.Service}.\n *\n * Edge triggers are ECHO objects replicated into the local database, so the\n * aggregate {@link TriggerMonitor} already surfaces them (marked\n * `environment: 'edge'`) from that database view; the `triggers` atom here is\n * therefore left empty to avoid double-counting. It exists as the seam through\n * which EDGE dispatcher runtime status can be layered in once a mapping to\n * {@link Trigger.State} is available.\n *\n * `invokeTrigger` is not yet supported over the wire (edge triggers run\n * autonomously on the EDGE dispatcher).\n */\nconst make = (_spaceId?: SpaceId): Layer.Layer<RemoteTriggerManager.Service, never, Registry.AtomRegistry> =>\n Layer.effect(\n RemoteTriggerManager.Service,\n Effect.gen(function* () {\n const registry = yield* Registry.AtomRegistry;\n // TODO(edge): Poll `EdgeHttpClient.getTriggersDispatcherStatus` and enrich edge trigger state here.\n const triggers = Atom.make<readonly Trigger.State[]>([]);\n registry.mount(triggers);\n return {\n triggers,\n invokeTrigger: () => Effect.die(new Error('Remote (EDGE) trigger invocation is not supported')),\n } satisfies RemoteTriggerManager.Manager;\n }),\n );\n\n/**\n * Build from a `Client`.\n */\nexport const fromClient = (\n _client: Client,\n spaceId?: SpaceId,\n): Layer.Layer<RemoteTriggerManager.Service, never, Registry.AtomRegistry> => make(spaceId);\n\n/**\n * Build from the ambient `ClientService`.\n */\nexport const layer = (\n spaceId?: SpaceId,\n): Layer.Layer<RemoteTriggerManager.Service, never, Registry.AtomRegistry | ClientService> =>\n Layer.effect(\n RemoteTriggerManager.Service,\n Effect.gen(function* () {\n yield* ClientService;\n const registry = yield* Registry.AtomRegistry;\n const triggers = Atom.make<readonly Trigger.State[]>([]);\n registry.mount(triggers);\n return {\n triggers,\n invokeTrigger: () => Effect.die(new Error('Remote (EDGE) trigger invocation is not supported')),\n } satisfies RemoteTriggerManager.Manager;\n }),\n );\n", "//\n// Copyright 2025 DXOS.org\n//\n\nimport { type Client } from '@dxos/client';\nimport { FunctionError, Operation } from '@dxos/compute';\nimport { FUNCTIONS_META_KEY } from '@dxos/compute-runtime';\nimport { FunctionServiceError } from '@dxos/compute-runtime';\nimport { type Context } from '@dxos/context';\nimport { Obj } from '@dxos/echo';\nimport { type EdgeHttpClient, type TriggersDispatcherStatus } from '@dxos/edge-client';\nimport { invariant } from '@dxos/invariant';\nimport { type EntityId, type SpaceId } from '@dxos/keys';\nimport { log } from '@dxos/log';\nimport { type FunctionRuntimeKind, type SerializedError } from '@dxos/protocols';\nimport { safeParseJson } from '@dxos/util';\n\nimport { createEdgeClient } from './edge-client';\n\n// TODO(wittjosiah): Copied from @dxos/functions-simulator-cloudflare.\nexport type InvokeResult =\n | {\n _kind: 'success';\n /**\n * The output of the function.\n */\n result: unknown;\n }\n | {\n _kind: 'error';\n error: SerializedError;\n };\n\nexport type FunctionDeployOptions = {\n name?: string;\n version: string;\n\n /** Service-side function id in case this function is a re-upload of a previous version. */\n functionId?: string;\n\n /** Owner identity DID (`did:halo:…`). Must equal the authenticated presenter DID. */\n ownerUri: string;\n\n runtime?: FunctionRuntimeKind;\n\n /** Path of the entry point file in the assets table. */\n entryPoint: string;\n\n assets: {\n // TODO(dmaretskyi): Allow passing strings and setting mime-type.\n [path: string]: Uint8Array;\n };\n};\n\nexport type FunctionInvokeOptions = {\n /**\n * Space in which the function is invoked.\n * Binds the Database.Service injected into the function to this space.\n * Without this, the function will not have access to any database.\n */\n spaceId?: SpaceId;\n\n /**\n * CPU time limit in milliseconds.\n * See Cloudflare docs for details.\n */\n cpuTimeLimit?: number;\n\n /**\n * Maximum number of subrequests.\n * See Cloudflare docs for details.\n */\n subrequestsLimit?: number;\n};\n\nexport class FunctionsServiceClient {\n static fromClient(client: Client) {\n return new FunctionsServiceClient(createEdgeClient(client));\n }\n\n #edgeClient: EdgeHttpClient;\n\n constructor(edgeClient: EdgeHttpClient) {\n this.#edgeClient = edgeClient;\n }\n\n /**\n * Deploys a function to the EDGE service.\n */\n async deploy(ctx: Context, request: FunctionDeployOptions): Promise<Operation.PersistentOperation> {\n try {\n invariant(\n Object.keys(request.assets).every((path) => !path.startsWith('/')),\n 'Asset paths must be relative',\n );\n const response = await this.#edgeClient.uploadFunction(\n ctx,\n { functionId: request.functionId },\n {\n name: request.name,\n version: request.version,\n ownerUri: request.ownerUri,\n entryPoint: request.entryPoint,\n assets: request.assets,\n runtime: request.runtime,\n },\n { retry: { count: 3 }, auth: true },\n );\n log.verbose('deploy result', { ...response });\n\n return Obj.make(Operation.PersistentOperation, {\n [Obj.Meta]: {\n keys: [{ source: FUNCTIONS_META_KEY, id: response.functionId }],\n key: response.meta.key,\n version: response.version,\n },\n name: response.meta.name ?? 'Unnamed function',\n description: response.meta.description,\n inputSchema: response.meta.inputSchema,\n outputSchema: response.meta.outputSchema,\n });\n } catch (error) {\n throw FunctionServiceError.wrap({ message: 'Failed to deploy function', ifTypeDiffers: true })(error);\n }\n }\n\n /**\n * Queries the EDGE service for deployed functions.\n */\n // TODO(dmaretskyi): Add query filters.\n async query(ctx: Context): Promise<Operation.PersistentOperation[]> {\n try {\n const response = await this.#edgeClient.listFunctions(ctx);\n return response.uploadedFunctions.flatMap((record: any) => {\n const latest = record.latestVersion ?? {};\n const versionMeta = safeParseJson<any>(latest.versionMetaJSON);\n if (!versionMeta) {\n return [];\n }\n const fn = Obj.make(Operation.PersistentOperation, {\n [Obj.Meta]: {\n keys: [{ source: FUNCTIONS_META_KEY, id: record.id }],\n key: versionMeta.key,\n version: latest?.version ?? '0.0.0',\n },\n name: versionMeta.name ?? versionMeta.key ?? record.id,\n updated: record?.updated !== undefined ? new Date(record.updated).toISOString() : undefined,\n description: versionMeta.description,\n inputSchema: versionMeta.inputSchema,\n outputSchema: versionMeta.outputSchema,\n });\n return [fn];\n });\n } catch (error) {\n throw FunctionServiceError.wrap({ message: 'Failed to query functions', ifTypeDiffers: true })(error);\n }\n }\n\n async invoke(ctx: Context, func: Operation.PersistentOperation, input: unknown, options?: FunctionInvokeOptions) {\n const functionId = Obj.getMeta(func).keys.find((key) => key.source === FUNCTIONS_META_KEY)?.id;\n if (!functionId) {\n throw new FunctionServiceError({ message: 'No identifier for the function at the EDGE service' });\n }\n // COMPAT: Previously functionId was a URL `/<guid>`. Now it's just the `<guid>`.\n const cleanedId = functionId.replace(/^\\//, '');\n try {\n return await this.#edgeClient.invokeFunction(\n ctx,\n {\n functionId: cleanedId,\n spaceId: options?.spaceId,\n cpuTimeLimit: options?.cpuTimeLimit,\n subrequestsLimit: options?.subrequestsLimit,\n },\n input,\n );\n } catch (error) {\n throw FunctionError.wrap({ message: 'Failed to invoke function', ifTypeDiffers: true })(error);\n }\n }\n\n async forceRunCronTrigger(ctx: Context, spaceId: SpaceId, triggerId: EntityId): Promise<InvokeResult> {\n return (await this.#edgeClient.forceRunCronTrigger(ctx, spaceId, triggerId)) as InvokeResult;\n }\n\n async getTriggersDispatcherStatus(ctx: Context, spaceId: SpaceId): Promise<TriggersDispatcherStatus> {\n return this.#edgeClient.getTriggersDispatcherStatus(ctx, spaceId);\n }\n}\n"],
5
+ "mappings": ";;;;;AAIA,YAAYA,WAAW;AACvB,YAAYC,eAAe;AAC3B,YAAYC,WAAW;AAIvB,SAASC,0BAA0B;AACnC,SAASC,iBAAiB;AAC1B,SAASC,oBAAoBC,mCAAmC;AAEhE,SAASC,WAAW;AACpB,SAASC,sBAAsB;AAC/B,SAASC,iBAAiB;AAE1B,SAASC,WAAW;AAEpB,SAASC,qBAAqB;AAc9B,IAAA,eAAA;AAGqB,IAAA,mBAAA,CAAA,WAAA;AACnB,QAAMC,UAAAA,OAAiBJ,OAAAA,OAAAA,SAAeK,UAAAA,MAAAA;AACtC,YAAMC,SAAAA,2BAAkCC,EAAAA,YAAAA,YAAAA,GAAAA,cAAAA,GAAAA,IAAAA,GAAAA,QAAAA,GAAAA,CAAAA,WAAAA,2BAAAA,EAAAA,CAAAA;AACxCH,QAAAA,aAAWI,IAAYF,eAAAA,OAAAA;AACvB,QAAA,eAAOF,mBAAAA,MAAAA;AACP,aAAA,YAAA,Y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createEdgeIdentity", "Operation", "FUNCTIONS_META_KEY", "setUserFunctionIdInMetadata", "Obj", "EdgeHttpClient", "invariant", "log", "safeParseJson", "edgeClient", "edgeUrl", "edgeIdentity", "client", "setIdentity", "functionId", "name", "version", "ownerUri", "response", "uploadFunction", "ctx", "entryPoint", "assets", "did", "halo", "result", "listFunctions", "functions", "uploadedFunctions", "latest", "record", "versionMeta", "key", "updated", "description", "inputSchema", "outputSchema", "update", "fn", "dedupe", "Error", "cleanedId", "spaceId", "cpuTimeLimit", "subrequestsLimit", "input", "patchNum", "patch", "Number", "isNaN", "major", "minor", "String", "join", "Effect", "Layer", "ClientService", "FunctionError", "RemoteOperationInvoker", "make", "getEdgeClient", "spaceId", "invoke", "ctx", "deployedId", "input", "gen", "cleanedId", "replace", "promise", "invokeFunction", "functionId", "pipe", "mapError", "FunctionError", "wrap", "orDie", "fromEdgeClient", "edgeClient", "succeed", "RemoteOperationInvoker", "Service", "fromClient", "client", "cached", "createEdgeClient", "layer", "effect", "ClientService", "fromClient", "layer", "Atom", "Registry", "Effect", "Layer", "RemoteProcessManager", "make", "effect", "Service", "gen", "registry", "AtomRegistry", "processTreeAtom", "mount", "processTree", "sync", "get", "_client", "fromClient", "layer", "Atom", "Registry", "Effect", "Layer", "ClientService", "RemoteTriggerManager", "make", "_spaceId", "effect", "Service", "gen", "registry", "AtomRegistry", "triggers", "mount", "invokeTrigger", "die", "Error", "_client", "spaceId", "FunctionError", "Operation", "FUNCTIONS_META_KEY", "FunctionServiceError", "Obj", "invariant", "log", "safeParseJson", "__dxlog_file", "FunctionsServiceClient", "invariant", "Object", "functionId", "request", "name", "ownerUri", "entryPoint", "assets", "runtime", "retry", "auth", "verbose", "log", "Obj", "keys", "Operation", "FUNCTIONS_META_KEY", "key", "version", "response", "description", "inputSchema", "outputSchema", "message", "ifTypeDiffers", "error", "latest", "record", "latestVersion", "versionMeta", "safeParseJson", "versionMetaJSON", "updated", "FunctionServiceError", "invokeFunction", "spaceId", "options", "cpuTimeLimit", "subrequestsLimit", "input", "FunctionError", "getTriggersDispatcherStatus", "ctx"]
7
+ }
@@ -0,0 +1 @@
1
+ {"inputs":{"src/bundler/plugins/http-plugin-esbuild.ts":{"bytes":10003,"imports":[{"path":"@effect/platform/FetchHttpClient","kind":"import-statement","external":true},{"path":"@effect/platform/HttpClient","kind":"import-statement","external":true},{"path":"effect/Duration","kind":"import-statement","external":true},{"path":"effect/Effect","kind":"import-statement","external":true},{"path":"effect/Function","kind":"import-statement","external":true},{"path":"effect/Schedule","kind":"import-statement","external":true},{"path":"@dxos/effect","kind":"import-statement","external":true},{"path":"@dxos/errors","kind":"import-statement","external":true}],"format":"esm"},"src/bundler/plugins/r2-vendored-packages.ts":{"bytes":3171,"imports":[],"format":"esm"},"src/bundler/bundler.ts":{"bytes":24892,"imports":[{"path":"esbuild-wasm","kind":"import-statement","external":true},{"path":"@dxos/crypto","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/util","kind":"import-statement","external":true},{"path":"src/bundler/plugins/http-plugin-esbuild.ts","kind":"import-statement","original":"./plugins/http-plugin-esbuild"},{"path":"src/bundler/plugins/r2-vendored-packages.ts","kind":"import-statement","original":"./plugins/r2-vendored-packages"}],"format":"esm"},"src/bundler/index.ts":{"bytes":375,"imports":[{"path":"src/bundler/bundler.ts","kind":"import-statement","original":"./bundler"}],"format":"esm"},"src/edge-client.ts":{"bytes":17931,"imports":[{"path":"effect/Array","kind":"import-statement","external":true},{"path":"effect/Function","kind":"import-statement","external":true},{"path":"effect/Order","kind":"import-statement","external":true},{"path":"@dxos/client/edge","kind":"import-statement","external":true},{"path":"@dxos/compute","kind":"import-statement","external":true},{"path":"@dxos/compute-runtime","kind":"import-statement","external":true},{"path":"@dxos/echo","kind":"import-statement","external":true},{"path":"@dxos/edge-client","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/log","kind":"import-statement","external":true},{"path":"@dxos/util","kind":"import-statement","external":true}],"format":"esm"},"src/EdgeOperationInvoker.ts":{"bytes":6481,"imports":[{"path":"effect/Effect","kind":"import-statement","external":true},{"path":"effect/Layer","kind":"import-statement","external":true},{"path":"@dxos/client","kind":"import-statement","external":true},{"path":"@dxos/compute","kind":"import-statement","external":true},{"path":"@dxos/compute-runtime","kind":"import-statement","external":true},{"path":"src/edge-client.ts","kind":"import-statement","original":"./edge-client"}],"format":"esm"},"src/EdgeProcessManager.ts":{"bytes":4538,"imports":[{"path":"@effect-atom/atom","kind":"import-statement","external":true},{"path":"effect/Effect","kind":"import-statement","external":true},{"path":"effect/Layer","kind":"import-statement","external":true},{"path":"@dxos/compute-runtime","kind":"import-statement","external":true}],"format":"esm"},"src/EdgeTriggerManager.ts":{"bytes":6979,"imports":[{"path":"@effect-atom/atom","kind":"import-statement","external":true},{"path":"effect/Effect","kind":"import-statement","external":true},{"path":"effect/Layer","kind":"import-statement","external":true},{"path":"@dxos/client","kind":"import-statement","external":true},{"path":"@dxos/compute-runtime","kind":"import-statement","external":true}],"format":"esm"},"src/FunctionsServiceClient.ts":{"bytes":19668,"imports":[{"path":"@dxos/compute","kind":"import-statement","external":true},{"path":"@dxos/compute-runtime","kind":"import-statement","external":true},{"path":"@dxos/compute-runtime","kind":"import-statement","external":true},{"path":"@dxos/echo","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/log","kind":"import-statement","external":true},{"path":"@dxos/util","kind":"import-statement","external":true},{"path":"src/edge-client.ts","kind":"import-statement","original":"./edge-client"}],"format":"esm"},"src/index.ts":{"bytes":1173,"imports":[{"path":"src/edge-client.ts","kind":"import-statement","original":"./edge-client"},{"path":"src/EdgeOperationInvoker.ts","kind":"import-statement","original":"./EdgeOperationInvoker"},{"path":"src/EdgeProcessManager.ts","kind":"import-statement","original":"./EdgeProcessManager"},{"path":"src/EdgeTriggerManager.ts","kind":"import-statement","original":"./EdgeTriggerManager"},{"path":"src/FunctionsServiceClient.ts","kind":"import-statement","original":"./FunctionsServiceClient"}],"format":"esm"},"src/native/bundler.ts":{"bytes":25080,"imports":[{"path":"effect/Array","kind":"import-statement","external":true},{"path":"effect/Function","kind":"import-statement","external":true},{"path":"effect/Order","kind":"import-statement","external":true},{"path":"effect/Record","kind":"import-statement","external":true},{"path":"esbuild","kind":"import-statement","external":true},{"path":"@dxos/node-std/fs","kind":"import-statement","external":true},{"path":"@dxos/node-std/fs/promises","kind":"import-statement","external":true},{"path":"@dxos/node-std/fs/promises","kind":"import-statement","external":true},{"path":"@dxos/node-std/path","kind":"import-statement","external":true},{"path":"@dxos/errors","kind":"import-statement","external":true},{"path":"@dxos/keys","kind":"import-statement","external":true},{"path":"@dxos/util","kind":"import-statement","external":true},{"path":"src/bundler/plugins/http-plugin-esbuild.ts","kind":"import-statement","original":"../bundler/plugins/http-plugin-esbuild"}],"format":"esm"},"src/native/index.ts":{"bytes":375,"imports":[{"path":"src/native/bundler.ts","kind":"import-statement","original":"./bundler"}],"format":"esm"},"src/testing/logger.ts":{"bytes":1480,"imports":[{"path":"@dxos/compute","kind":"import-statement","external":true},{"path":"@dxos/log","kind":"import-statement","external":true}],"format":"esm"},"src/testing/services.ts":{"bytes":5854,"imports":[{"path":"@dxos/compute-runtime","kind":"import-statement","external":true},{"path":"@dxos/compute-runtime","kind":"import-statement","external":true},{"path":"@dxos/echo","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"src/testing/logger.ts","kind":"import-statement","original":"./logger"}],"format":"esm"},"src/testing/index.ts":{"bytes":376,"imports":[{"path":"src/testing/services.ts","kind":"import-statement","original":"./services"}],"format":"esm"}},"outputs":{"dist/lib/neutral/bundler/index.mjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":12558},"dist/lib/neutral/bundler/index.mjs":{"imports":[{"path":"dist/lib/neutral/chunk-RN6KVGN4.mjs","kind":"import-statement"},{"path":"dist/lib/neutral/chunk-J5LGTIGS.mjs","kind":"import-statement"},{"path":"esbuild-wasm","kind":"import-statement","external":true},{"path":"@dxos/crypto","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/util","kind":"import-statement","external":true}],"exports":["bundleFunction","initializeBundler"],"entryPoint":"src/bundler/index.ts","inputs":{"src/bundler/bundler.ts":{"bytesInOutput":6217},"src/bundler/plugins/r2-vendored-packages.ts":{"bytesInOutput":535},"src/bundler/index.ts":{"bytesInOutput":0}},"bytes":7025},"dist/lib/neutral/index.mjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":27643},"dist/lib/neutral/index.mjs":{"imports":[{"path":"dist/lib/neutral/chunk-J5LGTIGS.mjs","kind":"import-statement"},{"path":"effect/Array","kind":"import-statement","external":true},{"path":"effect/Function","kind":"import-statement","external":true},{"path":"effect/Order","kind":"import-statement","external":true},{"path":"@dxos/client/edge","kind":"import-statement","external":true},{"path":"@dxos/compute","kind":"import-statement","external":true},{"path":"@dxos/compute-runtime","kind":"import-statement","external":true},{"path":"@dxos/echo","kind":"import-statement","external":true},{"path":"@dxos/edge-client","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/log","kind":"import-statement","external":true},{"path":"@dxos/util","kind":"import-statement","external":true},{"path":"effect/Effect","kind":"import-statement","external":true},{"path":"effect/Layer","kind":"import-statement","external":true},{"path":"@dxos/client","kind":"import-statement","external":true},{"path":"@dxos/compute","kind":"import-statement","external":true},{"path":"@dxos/compute-runtime","kind":"import-statement","external":true},{"path":"@effect-atom/atom","kind":"import-statement","external":true},{"path":"effect/Effect","kind":"import-statement","external":true},{"path":"effect/Layer","kind":"import-statement","external":true},{"path":"@dxos/compute-runtime","kind":"import-statement","external":true},{"path":"@effect-atom/atom","kind":"import-statement","external":true},{"path":"effect/Effect","kind":"import-statement","external":true},{"path":"effect/Layer","kind":"import-statement","external":true},{"path":"@dxos/client","kind":"import-statement","external":true},{"path":"@dxos/compute-runtime","kind":"import-statement","external":true},{"path":"@dxos/compute","kind":"import-statement","external":true},{"path":"@dxos/compute-runtime","kind":"import-statement","external":true},{"path":"@dxos/compute-runtime","kind":"import-statement","external":true},{"path":"@dxos/echo","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/log","kind":"import-statement","external":true},{"path":"@dxos/util","kind":"import-statement","external":true}],"exports":["EdgeOperationInvoker","EdgeProcessManager","EdgeTriggerManager","FunctionsServiceClient","createEdgeClient","getDeployedFunctions","incrementSemverPatch","invokeFunction","publicKeyToDid","uploadWorkerFunction"],"entryPoint":"src/index.ts","inputs":{"src/edge-client.ts":{"bytesInOutput":4148},"src/index.ts":{"bytesInOutput":0},"src/EdgeOperationInvoker.ts":{"bytesInOutput":1294},"src/EdgeProcessManager.ts":{"bytesInOutput":716},"src/EdgeTriggerManager.ts":{"bytesInOutput":1190},"src/FunctionsServiceClient.ts":{"bytesInOutput":4722}},"bytes":12630},"dist/lib/neutral/native/index.mjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":13078},"dist/lib/neutral/native/index.mjs":{"imports":[{"path":"dist/lib/neutral/chunk-RN6KVGN4.mjs","kind":"import-statement"},{"path":"dist/lib/neutral/chunk-J5LGTIGS.mjs","kind":"import-statement"},{"path":"effect/Array","kind":"import-statement","external":true},{"path":"effect/Function","kind":"import-statement","external":true},{"path":"effect/Order","kind":"import-statement","external":true},{"path":"effect/Record","kind":"import-statement","external":true},{"path":"esbuild","kind":"import-statement","external":true},{"path":"@dxos/node-std/fs","kind":"import-statement","external":true},{"path":"@dxos/node-std/fs/promises","kind":"import-statement","external":true},{"path":"@dxos/node-std/fs/promises","kind":"import-statement","external":true},{"path":"@dxos/node-std/path","kind":"import-statement","external":true},{"path":"@dxos/errors","kind":"import-statement","external":true},{"path":"@dxos/keys","kind":"import-statement","external":true},{"path":"@dxos/util","kind":"import-statement","external":true}],"exports":["bundleFunction"],"entryPoint":"src/native/index.ts","inputs":{"src/native/bundler.ts":{"bytesInOutput":6138},"src/native/index.ts":{"bytesInOutput":0}},"bytes":6314},"dist/lib/neutral/chunk-RN6KVGN4.mjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":4964},"dist/lib/neutral/chunk-RN6KVGN4.mjs":{"imports":[{"path":"@effect/platform/FetchHttpClient","kind":"import-statement","external":true},{"path":"@effect/platform/HttpClient","kind":"import-statement","external":true},{"path":"effect/Duration","kind":"import-statement","external":true},{"path":"effect/Effect","kind":"import-statement","external":true},{"path":"effect/Function","kind":"import-statement","external":true},{"path":"effect/Schedule","kind":"import-statement","external":true},{"path":"@dxos/effect","kind":"import-statement","external":true},{"path":"@dxos/errors","kind":"import-statement","external":true}],"exports":["httpPlugin"],"inputs":{"src/bundler/plugins/http-plugin-esbuild.ts":{"bytesInOutput":1888}},"bytes":2004},"dist/lib/neutral/testing/index.mjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":4170},"dist/lib/neutral/testing/index.mjs":{"imports":[{"path":"dist/lib/neutral/chunk-J5LGTIGS.mjs","kind":"import-statement"},{"path":"@dxos/compute-runtime","kind":"import-statement","external":true},{"path":"@dxos/compute-runtime","kind":"import-statement","external":true},{"path":"@dxos/echo","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/compute","kind":"import-statement","external":true},{"path":"@dxos/log","kind":"import-statement","external":true}],"exports":["createTestServices"],"entryPoint":"src/testing/index.ts","inputs":{"src/testing/services.ts":{"bytesInOutput":911},"src/testing/logger.ts":{"bytesInOutput":385},"src/testing/index.ts":{"bytesInOutput":0}},"bytes":1478},"dist/lib/neutral/chunk-J5LGTIGS.mjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":93},"dist/lib/neutral/chunk-J5LGTIGS.mjs":{"imports":[],"exports":["__export"],"inputs":{},"bytes":235}}}
@@ -0,0 +1,186 @@
1
+ import {
2
+ httpPlugin
3
+ } from "../chunk-RN6KVGN4.mjs";
4
+ import "../chunk-J5LGTIGS.mjs";
5
+
6
+ // src/native/bundler.ts
7
+ import * as Array from "effect/Array";
8
+ import * as Function from "effect/Function";
9
+ import * as Order from "effect/Order";
10
+ import * as Record from "effect/Record";
11
+ import { build } from "esbuild";
12
+ import { statSync } from "@dxos/node-std/fs";
13
+ import { writeFile } from "@dxos/node-std/fs/promises";
14
+ import * as fs from "@dxos/node-std/fs/promises";
15
+ import { basename, dirname, join, relative, resolve } from "@dxos/node-std/path";
16
+ import { BaseError } from "@dxos/errors";
17
+ import { PublicKey } from "@dxos/keys";
18
+ import { Unit, trim } from "@dxos/util";
19
+ var bundleFunction = async (options) => {
20
+ const outdir = `/tmp/dxos-functions-bundle-${(/* @__PURE__ */ new Date()).toISOString()}-${PublicKey.random().toHex()}`;
21
+ const gitDir = findGitDir(dirname(options.entryPoint));
22
+ const result = await build({
23
+ entryPoints: {
24
+ // Gets mapped to `index.js` by esbuild.
25
+ index: "dxos:entrypoint"
26
+ },
27
+ bundle: true,
28
+ format: "esm",
29
+ platform: "browser",
30
+ conditions: [
31
+ "workerd",
32
+ "worker",
33
+ "browser"
34
+ ],
35
+ outdir,
36
+ metafile: true,
37
+ treeShaking: true,
38
+ sourcemap: true,
39
+ splitting: true,
40
+ logOverride: {
41
+ "ignored-bare-import": "silent"
42
+ },
43
+ loader: {
44
+ ".wasm": "copy"
45
+ },
46
+ external: [
47
+ "node:*",
48
+ "cloudflare:workers",
49
+ "functions-service:user-script"
50
+ ],
51
+ plugins: [
52
+ httpPlugin,
53
+ {
54
+ name: "entrypoint",
55
+ setup: (build2) => {
56
+ build2.onResolve({
57
+ filter: /^dxos:entrypoint$/
58
+ }, () => ({
59
+ path: "dxos:entrypoint",
60
+ namespace: "dxos:entrypoint"
61
+ }));
62
+ build2.onLoad({
63
+ filter: /^dxos:entrypoint$/,
64
+ namespace: "dxos:entrypoint"
65
+ }, () => ({
66
+ contents: trim`
67
+ export default {
68
+ fetch: async (...args) => {
69
+ const { wrapFunctionHandler } = await import('@dxos/compute-runtime');
70
+ const { wrapHandlerForCloudflare, setupFunctionsLogger } = await import('@dxos/functions-runtime-cloudflare');
71
+ const { default: handler } = await import('${options.entryPoint}');
72
+
73
+ setupFunctionsLogger();
74
+
75
+ //
76
+ // Wrapper to make the function cloudflare-compatible.
77
+ //
78
+ return wrapHandlerForCloudflare(wrapFunctionHandler(handler))(...args);
79
+ },
80
+ };
81
+ `,
82
+ resolveDir: new URL(".", import.meta.url).pathname
83
+ }));
84
+ }
85
+ },
86
+ {
87
+ name: "metafile",
88
+ setup: (build2) => {
89
+ build2.onEnd(async (result2) => {
90
+ await writeFile(join(build2.initialOptions.outdir, "metafile.json"), JSON.stringify(result2.metafile, null, 2));
91
+ await writeFile(join(build2.initialOptions.outdir, "manifest.json"), JSON.stringify({
92
+ files: Object.keys(result2.metafile.outputs).map((path) => ({
93
+ name: relative(build2.initialOptions.outdir, path)
94
+ }))
95
+ }, null, 2));
96
+ });
97
+ }
98
+ }
99
+ ]
100
+ });
101
+ if (result.errors.length > 0) {
102
+ throw new BundleCreationError(result.errors);
103
+ }
104
+ const assetPaths = Object.keys(result.metafile.outputs).map((path) => relative(outdir, path));
105
+ const assets = Function.pipe(await Promise.all(assetPaths.map((path) => fs.readFile(join(outdir, path)))), Array.zipWith(assetPaths, (content, path) => [
106
+ path,
107
+ content
108
+ ]), Record.fromEntries);
109
+ if (options.verbose) {
110
+ console.log("Function compiled");
111
+ console.log("Metafile path:", `${outdir}/metafile.json`);
112
+ console.log("Assets:\n");
113
+ console.log(Object.entries(result.metafile.outputs).sort((a, b) => b[1].bytes - a[1].bytes).map(([path, desc]) => `${formatBytes(desc.bytes).padEnd(10)} - ${relative(outdir, path)} ${basename(path) === "index.js" ? " (entry point)" : ""}`).join("\n"));
114
+ const filesInOutput = Function.pipe(result.metafile.outputs, Record.values, Array.flatMap((_) => Record.toEntries(_.inputs)));
115
+ const moduleInOutput = Function.pipe(result.metafile.inputs, Record.values, Array.flatMap((_) => _.imports), Array.filter((_) => !!_.original?.match(/^@[a-zA-Z]+/)), Array.filter((_) => !!filesInOutput.find(([name]) => name === _.path)), Array.map((_) => _.original), Array.dedupe, Array.sort(Order.string));
116
+ console.log(`Modules in output:
117
+ ${moduleInOutput.map((_) => ` - ${_}`).join("\n")}`);
118
+ }
119
+ for (const path of Object.keys(assets)) {
120
+ if (path.endsWith(".map")) {
121
+ const content = assets[path];
122
+ const map2 = JSON.parse(new TextDecoder().decode(content));
123
+ const processedMap = postprocessSourceMap(map2, outdir, gitDir);
124
+ assets[path] = Buffer.from(JSON.stringify(processedMap));
125
+ }
126
+ }
127
+ return {
128
+ entryPoint: "index.js",
129
+ assets
130
+ };
131
+ };
132
+ var BundleCreationError = class extends BaseError.extend("BundleCreationError", "Bundle creation failed") {
133
+ constructor(errors) {
134
+ super({
135
+ context: {
136
+ errors
137
+ }
138
+ });
139
+ }
140
+ };
141
+ var formatBytes = (bytes) => {
142
+ if (bytes < Unit.Kilobyte(1).unit.quotient) {
143
+ return Unit.Byte(bytes).toString();
144
+ }
145
+ if (bytes < Unit.Megabyte(1).unit.quotient) {
146
+ return Unit.Kilobyte(bytes).toString();
147
+ }
148
+ if (bytes < Unit.Gigabyte(1).unit.quotient) {
149
+ return Unit.Megabyte(bytes).toString();
150
+ }
151
+ return Unit.Gigabyte(bytes).toString();
152
+ };
153
+ var findGitDir = (startPath) => {
154
+ let current = startPath;
155
+ while (current !== "/") {
156
+ const gitPath = join(current, ".git");
157
+ try {
158
+ if (statSync(gitPath).isDirectory()) {
159
+ return gitPath;
160
+ }
161
+ } catch {
162
+ }
163
+ current = dirname(current);
164
+ }
165
+ return null;
166
+ };
167
+ var postprocessSourceMap = (map2, outDir, gitDir) => {
168
+ if (!gitDir) {
169
+ return map2;
170
+ }
171
+ if (map2.sources && Array.isArray(map2.sources)) {
172
+ map2.sources = map2.sources.map((source) => {
173
+ const resolved = resolve(outDir, source);
174
+ if (resolved.startsWith(dirname(gitDir))) {
175
+ const rel = relative(dirname(gitDir), resolved);
176
+ return rel;
177
+ }
178
+ return source;
179
+ });
180
+ }
181
+ return map2;
182
+ };
183
+ export {
184
+ bundleFunction
185
+ };
186
+ //# sourceMappingURL=index.mjs.map