@dxos/compute 0.8.4-main.1da679c → 0.8.4-main.21d9917

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 (42) hide show
  1. package/dist/lib/browser/{chunk-XQYPCRZP.mjs → chunk-KGBGT4NT.mjs} +151 -185
  2. package/dist/lib/browser/chunk-KGBGT4NT.mjs.map +7 -0
  3. package/dist/lib/browser/index.mjs +1 -1
  4. package/dist/lib/browser/meta.json +1 -1
  5. package/dist/lib/browser/testing/index.mjs +32 -20
  6. package/dist/lib/browser/testing/index.mjs.map +4 -4
  7. package/dist/lib/node-esm/{chunk-2XWWSGAU.mjs → chunk-2MATJWLB.mjs} +151 -185
  8. package/dist/lib/node-esm/chunk-2MATJWLB.mjs.map +7 -0
  9. package/dist/lib/node-esm/index.mjs +1 -1
  10. package/dist/lib/node-esm/meta.json +1 -1
  11. package/dist/lib/node-esm/testing/index.mjs +32 -20
  12. package/dist/lib/node-esm/testing/index.mjs.map +4 -4
  13. package/dist/types/src/compute-graph-registry.d.ts +8 -3
  14. package/dist/types/src/compute-graph-registry.d.ts.map +1 -1
  15. package/dist/types/src/compute-graph-registry.test.d.ts +2 -0
  16. package/dist/types/src/compute-graph-registry.test.d.ts.map +1 -0
  17. package/dist/types/src/compute-graph.d.ts +4 -1
  18. package/dist/types/src/compute-graph.d.ts.map +1 -1
  19. package/dist/types/src/functions/async-function.d.ts +11 -9
  20. package/dist/types/src/functions/async-function.d.ts.map +1 -1
  21. package/dist/types/src/functions/edge-function.d.ts.map +1 -1
  22. package/dist/types/src/index.d.ts.map +1 -1
  23. package/dist/types/src/testing/index.d.ts +1 -0
  24. package/dist/types/src/testing/index.d.ts.map +1 -1
  25. package/dist/types/src/testing/test-builder.d.ts +1 -1
  26. package/dist/types/src/testing/test-builder.d.ts.map +1 -1
  27. package/dist/types/src/testing/test-runtime.d.ts +10 -0
  28. package/dist/types/src/testing/test-runtime.d.ts.map +1 -0
  29. package/dist/types/tsconfig.tsbuildinfo +1 -1
  30. package/package.json +26 -23
  31. package/src/compute-graph-registry.test.ts +158 -0
  32. package/src/compute-graph-registry.ts +17 -8
  33. package/src/compute-graph.test.ts +29 -10
  34. package/src/compute-graph.ts +19 -13
  35. package/src/functions/async-function.ts +13 -12
  36. package/src/functions/edge-function.ts +30 -28
  37. package/src/index.ts +0 -27
  38. package/src/testing/index.ts +1 -0
  39. package/src/testing/test-builder.ts +8 -2
  40. package/src/testing/test-runtime.ts +34 -0
  41. package/dist/lib/browser/chunk-XQYPCRZP.mjs.map +0 -7
  42. package/dist/lib/node-esm/chunk-2XWWSGAU.mjs.map +0 -7
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
- "sources": ["../../../../src/testing/test-builder.ts", "../../../../src/testing/test-plugin.ts", "../../../../src/util.ts", "../../../../src/testing/util.ts"],
4
- "sourcesContent": ["//\n// Copyright 2024 DXOS.org\n//\n\nimport { Client, type ClientOptions } from '@dxos/client';\nimport { type Context, Resource } from '@dxos/context';\nimport { invariant } from '@dxos/invariant';\n\nimport { type ComputeGraphOptions, ComputeGraphRegistry } from '../compute-graph-registry';\n\nexport type TestBuilderOptions = ClientOptions & ComputeGraphOptions;\n\n// TODO(burdon): Reconcile with @dxos/client/testing.\nexport class TestBuilder extends Resource {\n private _client?: Client;\n private _registry?: ComputeGraphRegistry;\n\n constructor(private readonly _options: TestBuilderOptions = {}) {\n super();\n }\n\n get ctx(): Context {\n return this._ctx;\n }\n\n get client(): Client {\n invariant(this._client);\n return this._client;\n }\n\n get registry(): ComputeGraphRegistry {\n invariant(this._registry);\n return this._registry;\n }\n\n override async _open(): Promise<void> {\n const client = new Client(this._options);\n await client.initialize();\n await client.halo.createIdentity();\n this._client = client;\n this._ctx.onDispose(async () => {\n await client.destroy();\n this._client = undefined;\n });\n\n const registry = new ComputeGraphRegistry(this._options);\n await registry.open();\n this._registry = registry;\n this._ctx.onDispose(async () => {\n await registry.close();\n this._registry = undefined;\n });\n }\n}\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport { getDeep } from '@dxos/util';\nimport { type InterpreterState, type ProcedureAst } from '@dxos/vendor-hyperformula';\nimport { FunctionArgumentType } from '@dxos/vendor-hyperformula';\n\nimport { type ComputeGraphPlugin } from '../compute-graph-registry';\nimport { type AsyncFunction, AsyncFunctionPlugin } from '../functions';\nimport { parseNumberString } from '../util';\n\n/**\n * Testing functions run locally (not run via EDGE).\n * https://hyperformula.handsontable.com/guide/custom-functions.html#add-a-simple-custom-function\n */\nexport class TestPlugin extends AsyncFunctionPlugin {\n /**\n * Simple local function returns input value.\n */\n test(ast: ProcedureAst, state: InterpreterState) {\n const handler: AsyncFunction = async (_value) => {\n return _value;\n };\n\n return this.runAsyncFunction(ast, state, handler);\n }\n\n /**\n * Simple local function returns random number.\n */\n random(ast: ProcedureAst, state: InterpreterState) {\n const handler: AsyncFunction = async () => {\n return Math.random();\n };\n\n return this.runAsyncFunction(ast, state, handler);\n }\n\n /**\n * Async HTTP function.\n */\n crypto(ast: ProcedureAst, state: InterpreterState) {\n const handler: AsyncFunction = async (_currency) => {\n const currency = (_currency || 'USD').toUpperCase();\n const result = await fetch(`https://api.coindesk.com/v1/bpi/currentprice/${currency}.json`);\n const data = await result.json();\n const rate = getDeep<string>(data, ['bpi', currency, 'rate']);\n if (!rate) {\n return NaN;\n }\n\n return parseNumberString(rate);\n };\n\n return this.runAsyncFunction(ast, state, handler, { ttl: 10_000 });\n }\n}\n\nTestPlugin.implementedFunctions = {\n TEST: {\n method: 'test',\n parameters: [{ argumentType: FunctionArgumentType.NUMBER, optionalArg: false }],\n isVolatile: true,\n },\n\n RANDOM: {\n method: 'random',\n parameters: [],\n isVolatile: true,\n },\n\n CRYPTO: {\n method: 'crypto',\n parameters: [{ argumentType: FunctionArgumentType.STRING, optionalArg: true }],\n isVolatile: true,\n },\n};\n\nexport const TestPluginTranslations = {\n enGB: {\n TEST: 'Returns input value',\n RANDOM: 'Random number',\n CRYPTO: 'Crypto token value',\n },\n enUS: {\n TEST: 'Returns input value',\n RANDOM: 'Random number',\n CRYPTO: 'Crypto token value',\n },\n};\n\nexport const testFunctionPlugins: ComputeGraphPlugin[] = [\n {\n plugin: TestPlugin,\n translations: TestPluginTranslations,\n },\n];\n", "//\n// Copyright 2024 DXOS.org\n//\n\n// TODO(burdon): Factor out.\nexport const parseNumberString = (str: string): number => {\n return parseFloat(str.replace(/[^\\d.]/g, ''));\n};\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport { HyperFormula } from '@dxos/vendor-hyperformula';\n\nexport const getRegisteredFunctionNames = () => {\n return HyperFormula.buildEmpty({ licenseKey: 'gpl-v3' }).getRegisteredFunctionNames();\n};\n"],
5
- "mappings": "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",
6
- "names": ["Client", "Resource", "invariant", "TestBuilder", "Resource", "ctx", "_ctx", "client", "invariant", "_client", "registry", "_registry", "_open", "Client", "_options", "initialize", "halo", "createIdentity", "onDispose", "destroy", "undefined", "ComputeGraphRegistry", "open", "close", "getDeep", "FunctionArgumentType", "parseNumberString", "str", "parseFloat", "replace", "TestPlugin", "AsyncFunctionPlugin", "test", "ast", "state", "handler", "_value", "runAsyncFunction", "random", "Math", "crypto", "_currency", "currency", "toUpperCase", "result", "fetch", "data", "json", "rate", "getDeep", "NaN", "parseNumberString", "ttl", "implementedFunctions", "TEST", "method", "parameters", "argumentType", "FunctionArgumentType", "NUMBER", "optionalArg", "isVolatile", "RANDOM", "CRYPTO", "STRING", "TestPluginTranslations", "enGB", "enUS", "testFunctionPlugins", "plugin", "translations", "HyperFormula", "getRegisteredFunctionNames", "HyperFormula", "buildEmpty", "licenseKey"]
3
+ "sources": ["../../../../src/testing/test-builder.ts", "../../../../src/testing/test-runtime.ts", "../../../../src/testing/test-plugin.ts", "../../../../src/util.ts", "../../../../src/testing/util.ts"],
4
+ "sourcesContent": ["//\n// Copyright 2024 DXOS.org\n//\n\nimport { Client, type ClientOptions } from '@dxos/client';\nimport { type Context, Resource } from '@dxos/context';\nimport { invariant } from '@dxos/invariant';\n\nimport { type ComputeGraphOptions, ComputeGraphRegistry } from '../compute-graph-registry';\n\nimport { createMockedComputeRuntimeProvider } from './test-runtime';\n\nexport type TestBuilderOptions = ClientOptions & Partial<ComputeGraphOptions>;\n\n// TODO(burdon): Reconcile with @dxos/client/testing.\nexport class TestBuilder extends Resource {\n private _client?: Client;\n private _registry?: ComputeGraphRegistry;\n\n constructor(private readonly _options: TestBuilderOptions = {}) {\n super();\n }\n\n get ctx(): Context {\n return this._ctx;\n }\n\n get client(): Client {\n invariant(this._client);\n return this._client;\n }\n\n get registry(): ComputeGraphRegistry {\n invariant(this._registry);\n return this._registry;\n }\n\n override async _open(): Promise<void> {\n const client = new Client(this._options);\n await client.initialize();\n await client.halo.createIdentity();\n this._client = client;\n this._ctx.onDispose(async () => {\n await client.destroy();\n this._client = undefined;\n });\n\n const registry = new ComputeGraphRegistry({\n ...this._options,\n // Provide a default runtime provider for tests if not supplied.\n computeRuntime: this._options.computeRuntime ?? createMockedComputeRuntimeProvider(),\n });\n await registry.open();\n this._registry = registry;\n this._ctx.onDispose(async () => {\n await registry.close();\n this._registry = undefined;\n });\n }\n}\n", "//\n// Copyright 2025 DXOS.org\n//\n\nimport * as Layer from 'effect/Layer';\nimport * as ManagedRuntime from 'effect/ManagedRuntime';\n\nimport { AiService } from '@dxos/ai';\nimport { type SpaceId } from '@dxos/client/echo';\nimport { Database } from '@dxos/echo';\nimport { CredentialsService, type FunctionDefinition, QueueService } from '@dxos/functions';\nimport { FunctionInvocationServiceLayerTest } from '@dxos/functions-runtime/testing';\n\nimport { type FunctionsRuntimeProvider } from '../compute-graph-registry';\n\n/**\n * Minimal compute runtime provider for tests and Storybook.\n * Will cause errors if used for actual runtime.\n */\nexport const createMockedComputeRuntimeProvider = ({\n functions,\n}: { functions?: FunctionDefinition.Any[] } = {}): FunctionsRuntimeProvider => {\n return {\n getRuntime: (_spaceId: SpaceId) =>\n ManagedRuntime.make(\n FunctionInvocationServiceLayerTest({ functions }).pipe(\n Layer.provide(AiService.notAvailable),\n Layer.provide(CredentialsService.configuredLayer([])),\n Layer.provide(Database.Service.notAvailable),\n Layer.provide(QueueService.notAvailable),\n ),\n ),\n };\n};\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport { getDeep } from '@dxos/util';\nimport { type InterpreterState, type ProcedureAst } from '@dxos/vendor-hyperformula';\nimport { FunctionArgumentType } from '@dxos/vendor-hyperformula';\n\nimport { type ComputeGraphPlugin } from '../compute-graph-registry';\nimport { type AsyncFunction, AsyncFunctionPlugin } from '../functions';\nimport { parseNumberString } from '../util';\n\n/**\n * Testing functions run locally (not run via EDGE).\n * https://hyperformula.handsontable.com/guide/custom-functions.html#add-a-simple-custom-function\n */\nexport class TestPlugin extends AsyncFunctionPlugin {\n /**\n * Simple local function returns input value.\n */\n test(ast: ProcedureAst, state: InterpreterState) {\n const handler: AsyncFunction = async (_value) => {\n return _value;\n };\n\n return this.runAsyncFunction(ast, state, handler);\n }\n\n /**\n * Simple local function returns random number.\n */\n random(ast: ProcedureAst, state: InterpreterState) {\n const handler: AsyncFunction = async () => {\n return Math.random();\n };\n\n return this.runAsyncFunction(ast, state, handler);\n }\n\n /**\n * Async HTTP function.\n */\n crypto(ast: ProcedureAst, state: InterpreterState) {\n const handler: AsyncFunction = async (_currency) => {\n const currency = (_currency || 'USD').toUpperCase();\n const result = await fetch(`https://api.coindesk.com/v1/bpi/currentprice/${currency}.json`);\n const data = await result.json();\n const rate = getDeep<string>(data, ['bpi', currency, 'rate']);\n if (!rate) {\n return NaN;\n }\n\n return parseNumberString(rate);\n };\n\n return this.runAsyncFunction(ast, state, handler, { ttl: 10_000 });\n }\n}\n\nTestPlugin.implementedFunctions = {\n TEST: {\n method: 'test',\n parameters: [{ argumentType: FunctionArgumentType.NUMBER, optionalArg: false }],\n isVolatile: true,\n },\n\n RANDOM: {\n method: 'random',\n parameters: [],\n isVolatile: true,\n },\n\n CRYPTO: {\n method: 'crypto',\n parameters: [{ argumentType: FunctionArgumentType.STRING, optionalArg: true }],\n isVolatile: true,\n },\n};\n\nexport const TestPluginTranslations = {\n enGB: {\n TEST: 'Returns input value',\n RANDOM: 'Random number',\n CRYPTO: 'Crypto token value',\n },\n enUS: {\n TEST: 'Returns input value',\n RANDOM: 'Random number',\n CRYPTO: 'Crypto token value',\n },\n};\n\nexport const testFunctionPlugins: ComputeGraphPlugin[] = [\n {\n plugin: TestPlugin,\n translations: TestPluginTranslations,\n },\n];\n", "//\n// Copyright 2024 DXOS.org\n//\n\n// TODO(burdon): Factor out.\nexport const parseNumberString = (str: string): number => {\n return parseFloat(str.replace(/[^\\d.]/g, ''));\n};\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport { HyperFormula } from '@dxos/vendor-hyperformula';\n\nexport const getRegisteredFunctionNames = () => {\n return HyperFormula.buildEmpty({ licenseKey: 'gpl-v3' }).getRegisteredFunctionNames();\n};\n"],
5
+ "mappings": "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",
6
+ "names": ["Client", "Resource", "invariant", "Layer", "ManagedRuntime", "AiService", "Database", "CredentialsService", "QueueService", "FunctionInvocationServiceLayerTest", "createMockedComputeRuntimeProvider", "functions", "getRuntime", "_spaceId", "make", "FunctionInvocationServiceLayerTest", "pipe", "provide", "AiService", "notAvailable", "CredentialsService", "configuredLayer", "Database", "Service", "QueueService", "TestBuilder", "Resource", "_client", "_registry", "_options", "ctx", "_ctx", "client", "invariant", "registry", "_open", "Client", "initialize", "halo", "createIdentity", "onDispose", "destroy", "undefined", "ComputeGraphRegistry", "computeRuntime", "createMockedComputeRuntimeProvider", "open", "close", "getDeep", "FunctionArgumentType", "parseNumberString", "str", "parseFloat", "replace", "TestPlugin", "AsyncFunctionPlugin", "test", "ast", "state", "handler", "_value", "runAsyncFunction", "random", "Math", "crypto", "_currency", "currency", "toUpperCase", "result", "fetch", "data", "json", "rate", "getDeep", "NaN", "parseNumberString", "ttl", "implementedFunctions", "TEST", "method", "parameters", "argumentType", "FunctionArgumentType", "NUMBER", "optionalArg", "isVolatile", "RANDOM", "CRYPTO", "STRING", "TestPluginTranslations", "enGB", "enUS", "testFunctionPlugins", "plugin", "translations", "HyperFormula", "getRegisteredFunctionNames", "HyperFormula", "buildEmpty", "licenseKey"]
7
7
  }
@@ -80,20 +80,13 @@ var inRange = (range, cell) => {
80
80
  import { Event } from "@dxos/async";
81
81
  import { Resource } from "@dxos/context";
82
82
  import { DetailedCellError as DetailedCellError2 } from "@dxos/vendor-hyperformula";
83
- function _define_property(obj, key, value) {
84
- if (key in obj) {
85
- Object.defineProperty(obj, key, {
86
- value,
87
- enumerable: true,
88
- configurable: true,
89
- writable: true
90
- });
91
- } else {
92
- obj[key] = value;
93
- }
94
- return obj;
95
- }
96
83
  var ComputeNode = class extends Resource {
84
+ _graph;
85
+ sheetId;
86
+ update = new Event();
87
+ constructor(_graph, sheetId) {
88
+ super(), this._graph = _graph, this.sheetId = sheetId;
89
+ }
97
90
  get graph() {
98
91
  return this._graph;
99
92
  }
@@ -126,9 +119,6 @@ var ComputeNode = class extends Resource {
126
119
  // TODO(burdon): Load data into sheet.
127
120
  async _open() {
128
121
  }
129
- constructor(_graph, sheetId) {
130
- super(), _define_property(this, "_graph", void 0), _define_property(this, "sheetId", void 0), _define_property(this, "update", void 0), this._graph = _graph, this.sheetId = sheetId, this.update = new Event();
131
- }
132
122
  };
133
123
 
134
124
  // src/functions/async-function.ts
@@ -136,26 +126,15 @@ import defaultsDeep from "lodash.defaultsdeep";
136
126
  import { debounce } from "@dxos/async";
137
127
  import { log } from "@dxos/log";
138
128
  import { CellError, EmptyValue, ErrorType, FunctionPlugin } from "@dxos/vendor-hyperformula";
139
- function _define_property2(obj, key, value) {
140
- if (key in obj) {
141
- Object.defineProperty(obj, key, {
142
- value,
143
- enumerable: true,
144
- configurable: true,
145
- writable: true
146
- });
147
- } else {
148
- obj[key] = value;
149
- }
150
- return obj;
151
- }
152
129
  var __dxlog_file2 = "/__w/dxos/dxos/packages/core/compute/src/functions/async-function.ts";
153
130
  var defaultFunctionContextOptions = {
154
131
  defaultTtl: 5e3,
155
- debounceDelay: 200,
156
- remoteFunctionUrl: "https://edge.dxos.workers.dev/functions"
132
+ debounceDelay: 200
157
133
  };
158
134
  var FunctionContext = class _FunctionContext {
135
+ _hf;
136
+ _runtime;
137
+ _space;
159
138
  // Mangle name with params.
160
139
  static createInvocationKey(name, ...args) {
161
140
  return JSON.stringify({
@@ -163,18 +142,46 @@ var FunctionContext = class _FunctionContext {
163
142
  ...args
164
143
  });
165
144
  }
145
+ // TODO(wittjosiah): Persist cached values.
146
+ // Cached values for cell.
147
+ _cache = /* @__PURE__ */ new Map();
148
+ // Active requests.
149
+ _pending = /* @__PURE__ */ new Map();
150
+ // Query subscriptions.
151
+ _subscriptions = /* @__PURE__ */ new Map();
152
+ // Invocation count.
153
+ _invocations = {};
154
+ _options;
155
+ // Debounced update handler.
156
+ _onUpdate;
157
+ constructor(_hf, _runtime, _space, _options) {
158
+ this._hf = _hf;
159
+ this._runtime = _runtime;
160
+ this._space = _space;
161
+ this._options = defaultsDeep(_options ?? {}, defaultFunctionContextOptions);
162
+ this._onUpdate = debounce((update) => {
163
+ log("update", update, {
164
+ F: __dxlog_file2,
165
+ L: 86,
166
+ S: this,
167
+ C: (f, a) => f(...a)
168
+ });
169
+ this._hf.resumeEvaluation();
170
+ this._options.onUpdate?.(update);
171
+ }, this._options.debounceDelay);
172
+ }
166
173
  get space() {
167
174
  return this._space;
168
175
  }
169
- get remoteFunctionUrl() {
170
- return this._options.remoteFunctionUrl;
171
- }
172
176
  get info() {
173
177
  return {
174
178
  cache: this._cache.size,
175
179
  invocations: this._invocations
176
180
  };
177
181
  }
182
+ get runtime() {
183
+ return this._runtime;
184
+ }
178
185
  flush() {
179
186
  this._cache.clear();
180
187
  this._invocations = {};
@@ -211,7 +218,7 @@ var FunctionContext = class _FunctionContext {
211
218
  value: value2
212
219
  }, {
213
220
  F: __dxlog_file2,
214
- L: 143,
221
+ L: 144,
215
222
  S: this,
216
223
  C: (f, a) => f(...a)
217
224
  });
@@ -225,7 +232,7 @@ var FunctionContext = class _FunctionContext {
225
232
  err
226
233
  }, {
227
234
  F: __dxlog_file2,
228
- L: 147,
235
+ L: 148,
229
236
  S: this,
230
237
  C: (f, a) => f(...a)
231
238
  });
@@ -245,39 +252,12 @@ var FunctionContext = class _FunctionContext {
245
252
  cache: value
246
253
  }, {
247
254
  F: __dxlog_file2,
248
- L: 155,
255
+ L: 156,
249
256
  S: this,
250
257
  C: (f, a) => f(...a)
251
258
  });
252
259
  return value;
253
260
  }
254
- constructor(_hf, _space, _options) {
255
- _define_property2(this, "_hf", void 0);
256
- _define_property2(this, "_space", void 0);
257
- _define_property2(this, "_cache", void 0);
258
- _define_property2(this, "_pending", void 0);
259
- _define_property2(this, "_subscriptions", void 0);
260
- _define_property2(this, "_invocations", void 0);
261
- _define_property2(this, "_options", void 0);
262
- _define_property2(this, "_onUpdate", void 0);
263
- this._hf = _hf;
264
- this._space = _space;
265
- this._cache = /* @__PURE__ */ new Map();
266
- this._pending = /* @__PURE__ */ new Map();
267
- this._subscriptions = /* @__PURE__ */ new Map();
268
- this._invocations = {};
269
- this._options = defaultsDeep(_options ?? {}, defaultFunctionContextOptions);
270
- this._onUpdate = debounce((update) => {
271
- log("update", update, {
272
- F: __dxlog_file2,
273
- L: 85,
274
- S: this,
275
- C: (f, a) => f(...a)
276
- });
277
- this._hf.resumeEvaluation();
278
- this._options.onUpdate?.(update);
279
- }, this._options.debounceDelay);
280
- }
281
261
  };
282
262
  var AsyncFunctionPlugin = class extends FunctionPlugin {
283
263
  get context() {
@@ -296,11 +276,12 @@ var AsyncFunctionPlugin = class extends FunctionPlugin {
296
276
  };
297
277
 
298
278
  // src/functions/edge-function.ts
299
- import { effect } from "@preact/signals-core";
300
- import { SchemaAST } from "effect";
301
- import { Filter, getMeta } from "@dxos/client/echo";
302
- import { toEffectSchema } from "@dxos/echo-schema";
303
- import { FunctionType, getUserFunctionIdInMetadata } from "@dxos/functions";
279
+ import * as Effect from "effect/Effect";
280
+ import * as SchemaAST from "effect/SchemaAST";
281
+ import { Filter } from "@dxos/client/echo";
282
+ import { JsonSchema, Obj } from "@dxos/echo";
283
+ import { Function, FunctionInvocationService, TracingService } from "@dxos/functions";
284
+ import { FunctionDefinition } from "@dxos/functions";
304
285
  import { log as log2 } from "@dxos/log";
305
286
  import { isNonNullable } from "@dxos/util";
306
287
  import { CellError as CellError2, ErrorType as ErrorType2, FunctionArgumentType } from "@dxos/vendor-hyperformula";
@@ -314,7 +295,7 @@ var EdgeFunctionPlugin = class extends AsyncFunctionPlugin {
314
295
  if (!space) {
315
296
  return new CellError2(ErrorType2.REF, "Missing space");
316
297
  }
317
- const { objects: [fn] } = await space.db.query(Filter.type(FunctionType, {
298
+ const [fn] = await space.db.query(Filter.type(Function.Function, {
318
299
  binding
319
300
  })).run();
320
301
  if (!fn) {
@@ -322,55 +303,46 @@ var EdgeFunctionPlugin = class extends AsyncFunctionPlugin {
322
303
  binding
323
304
  }, {
324
305
  F: __dxlog_file3,
325
- L: 41,
306
+ L: 40,
326
307
  S: this,
327
308
  C: (f, a) => f(...a)
328
309
  });
329
310
  return new CellError2(ErrorType2.REF, "Function not found");
330
311
  }
331
312
  if (subscribe) {
332
- const unsubscribe = effect(() => {
313
+ const unsubscribe = Obj.subscribe(fn, () => {
333
314
  log2("function changed", {
334
315
  fn
335
316
  }, {
336
317
  F: __dxlog_file3,
337
- L: 47,
318
+ L: 46,
338
319
  S: this,
339
320
  C: (f, a) => f(...a)
340
321
  });
341
- const _ = fn?.version;
342
322
  this.runAsyncFunction(ast, state, handler(false), {
343
323
  ttl: FUNCTION_TTL
344
324
  });
345
325
  });
346
326
  this.context.createSubscription(ast.procedureName, unsubscribe);
347
327
  }
348
- const body = {};
328
+ const runtime = this.context.runtime;
329
+ const functionDef = FunctionDefinition.deserialize(fn);
330
+ let input;
349
331
  if (fn.inputSchema) {
350
- const schema = toEffectSchema(fn.inputSchema);
351
- SchemaAST.getPropertySignatures(schema.ast).forEach(({ name }, index) => {
352
- body[name.toString()] = args[index];
332
+ const schema = JsonSchema.toEffectSchema(fn.inputSchema);
333
+ const props = SchemaAST.getPropertySignatures(schema.ast);
334
+ input = {};
335
+ props.forEach(({ name }, index) => {
336
+ input[name.toString()] = args[index];
353
337
  });
354
338
  } else {
355
- body.args = args.filter(isNonNullable);
339
+ input = {
340
+ args: args.filter(isNonNullable)
341
+ };
356
342
  }
357
- const id = getUserFunctionIdInMetadata(getMeta(fn));
358
- const response = await fetch(`${this.context.remoteFunctionUrl}/${id}`, {
359
- method: "POST",
360
- headers: {
361
- "Content-Type": "application/json"
362
- },
363
- body: JSON.stringify(body)
364
- });
365
- const result = await response.text();
366
- log2("function executed", {
367
- result
368
- }, {
369
- F: __dxlog_file3,
370
- L: 74,
371
- S: this,
372
- C: (f, a) => f(...a)
373
- });
343
+ const result = runtime.runPromise(Effect.gen(function* () {
344
+ return yield* FunctionInvocationService.invokeFunction(functionDef, input);
345
+ }).pipe(Effect.provide(TracingService.layerNoop)));
374
346
  return result;
375
347
  };
376
348
  return this.runAsyncFunction(ast, state, handler(true), {
@@ -2808,29 +2780,16 @@ var defaultFunctions = [
2808
2780
 
2809
2781
  // src/compute-graph.ts
2810
2782
  import { Event as Event2 } from "@dxos/async";
2811
- import { Filter as Filter2, fullyQualifiedId } from "@dxos/client/echo";
2783
+ import { Filter as Filter2 } from "@dxos/client/echo";
2812
2784
  import { FQ_ID_LENGTH } from "@dxos/client/echo";
2813
2785
  import { Resource as Resource2 } from "@dxos/context";
2814
- import { getTypename } from "@dxos/echo-schema";
2815
- import { FunctionType as FunctionType2 } from "@dxos/functions";
2786
+ import { Obj as Obj2 } from "@dxos/echo";
2787
+ import { Function as Function2 } from "@dxos/functions";
2816
2788
  import { invariant as invariant2 } from "@dxos/invariant";
2817
2789
  import { PublicKey } from "@dxos/keys";
2818
2790
  import { log as log3 } from "@dxos/log";
2819
2791
  import { isNonNullable as isNonNullable2 } from "@dxos/util";
2820
2792
  import { ExportedCellChange as ExportedCellChange2 } from "@dxos/vendor-hyperformula";
2821
- function _define_property3(obj, key, value) {
2822
- if (key in obj) {
2823
- Object.defineProperty(obj, key, {
2824
- value,
2825
- enumerable: true,
2826
- configurable: true,
2827
- writable: true
2828
- });
2829
- } else {
2830
- obj[key] = value;
2831
- }
2832
- return obj;
2833
- }
2834
2793
  var __dxlog_file4 = "/__w/dxos/dxos/packages/core/compute/src/compute-graph.ts";
2835
2794
  var UNKNOWN_BINDING = "__UNKNOWN__";
2836
2795
  var createSheetName = ({ type, id }) => `${type}@${id}`;
@@ -2844,6 +2803,49 @@ var parseSheetName = (name) => {
2844
2803
  };
2845
2804
  };
2846
2805
  var ComputeGraph = class extends Resource2 {
2806
+ _hf;
2807
+ _runtime;
2808
+ _space;
2809
+ _options;
2810
+ id = `graph-${PublicKey.random().truncate()}`;
2811
+ // Map of nodes indexed by sheet number.
2812
+ _nodes = /* @__PURE__ */ new Map();
2813
+ // Cached function objects.
2814
+ _remoteFunctions = [];
2815
+ update = new Event2();
2816
+ // The context is passed to all functions.
2817
+ context;
2818
+ constructor(_hf, _runtime, _space, _options) {
2819
+ super(), this._hf = _hf, this._runtime = _runtime, this._space = _space, this._options = _options;
2820
+ this.context = new FunctionContext(this._hf, this._runtime, this._space, {
2821
+ ...this._options,
2822
+ onUpdate: (update) => {
2823
+ this._options?.onUpdate?.(update);
2824
+ this.update.emit({
2825
+ type: "valuesUpdated"
2826
+ });
2827
+ }
2828
+ });
2829
+ this._hf.updateConfig({
2830
+ context: this.context
2831
+ });
2832
+ const onValuesUpdate = (changes) => {
2833
+ for (const change of changes) {
2834
+ if (change instanceof ExportedCellChange2) {
2835
+ const { sheet } = change;
2836
+ const node = this._nodes.get(sheet);
2837
+ if (node) {
2838
+ node.update.emit({
2839
+ type: "valuesUpdated",
2840
+ change
2841
+ });
2842
+ }
2843
+ }
2844
+ }
2845
+ };
2846
+ this._hf.on("valuesUpdated", onValuesUpdate);
2847
+ this._ctx.onDispose(() => this._hf.off("valuesUpdated", onValuesUpdate));
2848
+ }
2847
2849
  get hf() {
2848
2850
  return this._hf;
2849
2851
  }
@@ -2871,7 +2873,7 @@ var ComputeGraph = class extends Resource2 {
2871
2873
  getOrCreateNode(name) {
2872
2874
  invariant2(name.length, void 0, {
2873
2875
  F: __dxlog_file4,
2874
- L: 127,
2876
+ L: 133,
2875
2877
  S: this,
2876
2878
  A: [
2877
2879
  "name.length",
@@ -2884,7 +2886,7 @@ var ComputeGraph = class extends Resource2 {
2884
2886
  sheet: name
2885
2887
  }, {
2886
2888
  F: __dxlog_file4,
2887
- L: 129,
2889
+ L: 135,
2888
2890
  S: this,
2889
2891
  C: (f, a) => f(...a)
2890
2892
  });
@@ -2893,7 +2895,7 @@ var ComputeGraph = class extends Resource2 {
2893
2895
  const sheetId = this._hf.getSheetId(name);
2894
2896
  invariant2(sheetId !== void 0, void 0, {
2895
2897
  F: __dxlog_file4,
2896
- L: 134,
2898
+ L: 140,
2897
2899
  S: this,
2898
2900
  A: [
2899
2901
  "sheetId !== undefined",
@@ -2917,7 +2919,7 @@ var ComputeGraph = class extends Resource2 {
2917
2919
  }).filter(isNonNullable2);
2918
2920
  for (const obj of objects) {
2919
2921
  if (obj.name === name) {
2920
- const type = getTypename(obj);
2922
+ const type = Obj2.getTypename(obj);
2921
2923
  return `'${createSheetName({
2922
2924
  type,
2923
2925
  id: obj.id
@@ -2949,7 +2951,7 @@ var ComputeGraph = class extends Resource2 {
2949
2951
  }
2950
2952
  const fn = this._remoteFunctions.find((fn2) => fn2.binding === binding);
2951
2953
  if (fn) {
2952
- const id = fullyQualifiedId(fn);
2954
+ const id = Obj2.getDXN(fn).toString();
2953
2955
  return `${id}(${args})`;
2954
2956
  } else {
2955
2957
  return match;
@@ -2966,7 +2968,7 @@ var ComputeGraph = class extends Resource2 {
2966
2968
  if (id.length !== FQ_ID_LENGTH) {
2967
2969
  return match;
2968
2970
  }
2969
- const fn = this._remoteFunctions.find((fn2) => fullyQualifiedId(fn2) === id);
2971
+ const fn = this._remoteFunctions.find((fn2) => Obj2.getDXN(fn2).toString() === id);
2970
2972
  if (fn?.binding) {
2971
2973
  return `${fn.binding}(${args})`;
2972
2974
  } else {
@@ -2981,9 +2983,9 @@ var ComputeGraph = class extends Resource2 {
2981
2983
  }
2982
2984
  async _open() {
2983
2985
  if (this._space) {
2984
- const query = this._space.db.query(Filter2.type(FunctionType2));
2985
- const unsubscribe = query.subscribe(({ objects }) => {
2986
- this._remoteFunctions = objects.filter(({ binding }) => binding);
2986
+ const query = this._space.db.query(Filter2.type(Function2.Function));
2987
+ const unsubscribe = query.subscribe(() => {
2988
+ this._remoteFunctions = query.results.filter((fn) => fn.binding);
2987
2989
  this.update.emit({
2988
2990
  type: "functionsUpdated"
2989
2991
  });
@@ -2996,40 +2998,6 @@ var ComputeGraph = class extends Resource2 {
2996
2998
  await node.close();
2997
2999
  }
2998
3000
  }
2999
- constructor(_hf, _space, _options) {
3000
- super(), _define_property3(this, "_hf", void 0), _define_property3(this, "_space", void 0), _define_property3(this, "_options", void 0), _define_property3(this, "id", void 0), // Map of nodes indexed by sheet number.
3001
- _define_property3(this, "_nodes", void 0), // Cached function objects.
3002
- _define_property3(this, "_remoteFunctions", void 0), _define_property3(this, "update", void 0), // The context is passed to all functions.
3003
- _define_property3(this, "context", void 0), this._hf = _hf, this._space = _space, this._options = _options, this.id = `graph-${PublicKey.random().truncate()}`, this._nodes = /* @__PURE__ */ new Map(), this._remoteFunctions = [], this.update = new Event2();
3004
- this.context = new FunctionContext(this._hf, this._space, {
3005
- ...this._options,
3006
- onUpdate: (update) => {
3007
- this._options?.onUpdate?.(update);
3008
- this.update.emit({
3009
- type: "valuesUpdated"
3010
- });
3011
- }
3012
- });
3013
- this._hf.updateConfig({
3014
- context: this.context
3015
- });
3016
- const onValuesUpdate = (changes) => {
3017
- for (const change of changes) {
3018
- if (change instanceof ExportedCellChange2) {
3019
- const { sheet } = change;
3020
- const node = this._nodes.get(sheet);
3021
- if (node) {
3022
- node.update.emit({
3023
- type: "valuesUpdated",
3024
- change
3025
- });
3026
- }
3027
- }
3028
- }
3029
- };
3030
- this._hf.on("valuesUpdated", onValuesUpdate);
3031
- this._ctx.onDispose(() => this._hf.off("valuesUpdated", onValuesUpdate));
3032
- }
3033
3001
  };
3034
3002
 
3035
3003
  // src/compute-graph-registry.ts
@@ -3038,30 +3006,27 @@ import { Resource as Resource3 } from "@dxos/context";
3038
3006
  import { invariant as invariant3 } from "@dxos/invariant";
3039
3007
  import { log as log4 } from "@dxos/log";
3040
3008
  import { HyperFormula } from "@dxos/vendor-hyperformula";
3041
- function _define_property4(obj, key, value) {
3042
- if (key in obj) {
3043
- Object.defineProperty(obj, key, {
3044
- value,
3045
- enumerable: true,
3046
- configurable: true,
3047
- writable: true
3048
- });
3049
- } else {
3050
- obj[key] = value;
3051
- }
3052
- return obj;
3053
- }
3054
3009
  var __dxlog_file5 = "/__w/dxos/dxos/packages/core/compute/src/compute-graph-registry.ts";
3055
- var defaultOptions = {
3056
- licenseKey: "gpl-v3"
3057
- };
3058
3010
  var defaultPlugins = [
3059
3011
  {
3060
3012
  plugin: EdgeFunctionPlugin,
3061
3013
  translations: EdgeFunctionPluginTranslations
3062
3014
  }
3063
3015
  ];
3016
+ var defaultOptions = {
3017
+ licenseKey: "gpl-v3"
3018
+ };
3064
3019
  var ComputeGraphRegistry = class extends Resource3 {
3020
+ _graphs = /* @__PURE__ */ new Map();
3021
+ _options;
3022
+ constructor(options) {
3023
+ super();
3024
+ this._options = defaultsDeep2({}, options, defaultOptions);
3025
+ this._options.plugins = this._options.plugins ?? defaultPlugins;
3026
+ this._options.plugins?.forEach(({ plugin, translations }) => {
3027
+ HyperFormula.registerFunctionPlugin(plugin, translations);
3028
+ });
3029
+ }
3065
3030
  getGraph(spaceId) {
3066
3031
  return this._graphs.get(spaceId);
3067
3032
  }
@@ -3072,7 +3037,7 @@ var ComputeGraphRegistry = class extends Resource3 {
3072
3037
  space: space.id
3073
3038
  }, {
3074
3039
  F: __dxlog_file5,
3075
- L: 67,
3040
+ L: 73,
3076
3041
  S: this,
3077
3042
  C: (f, a) => f(...a)
3078
3043
  });
@@ -3083,7 +3048,7 @@ var ComputeGraphRegistry = class extends Resource3 {
3083
3048
  createGraph(space) {
3084
3049
  invariant3(!this._graphs.has(space.id), `ComputeGraph already exists for space: ${space.id}`, {
3085
3050
  F: __dxlog_file5,
3086
- L: 75,
3051
+ L: 81,
3087
3052
  S: this,
3088
3053
  A: [
3089
3054
  "!this._graphs.has(space.id)",
@@ -3091,7 +3056,17 @@ var ComputeGraphRegistry = class extends Resource3 {
3091
3056
  ]
3092
3057
  });
3093
3058
  const hf = HyperFormula.buildEmpty(this._options);
3094
- const graph = new ComputeGraph(hf, space, this._options);
3059
+ invariant3(this._options.computeRuntime, "ComputeRuntime is required", {
3060
+ F: __dxlog_file5,
3061
+ L: 83,
3062
+ S: this,
3063
+ A: [
3064
+ "this._options.computeRuntime",
3065
+ "'ComputeRuntime is required'"
3066
+ ]
3067
+ });
3068
+ const runtime = this._options.computeRuntime.getRuntime(space.id);
3069
+ const graph = new ComputeGraph(hf, runtime, space, this._options);
3095
3070
  this._graphs.set(space.id, graph);
3096
3071
  return graph;
3097
3072
  }
@@ -3101,15 +3076,6 @@ var ComputeGraphRegistry = class extends Resource3 {
3101
3076
  }
3102
3077
  this._graphs.clear();
3103
3078
  }
3104
- constructor(options = {
3105
- plugins: defaultPlugins
3106
- }) {
3107
- super(), _define_property4(this, "_graphs", /* @__PURE__ */ new Map()), _define_property4(this, "_options", void 0);
3108
- this._options = defaultsDeep2({}, options, defaultOptions);
3109
- this._options.plugins?.forEach(({ plugin, translations }) => {
3110
- HyperFormula.registerFunctionPlugin(plugin, translations);
3111
- });
3112
- }
3113
3079
  };
3114
3080
 
3115
3081
  export {
@@ -3135,8 +3101,8 @@ export {
3135
3101
  createSheetName,
3136
3102
  parseSheetName,
3137
3103
  ComputeGraph,
3138
- defaultOptions,
3139
3104
  defaultPlugins,
3105
+ defaultOptions,
3140
3106
  ComputeGraphRegistry
3141
3107
  };
3142
- //# sourceMappingURL=chunk-2XWWSGAU.mjs.map
3108
+ //# sourceMappingURL=chunk-2MATJWLB.mjs.map