@dxos/compute 0.8.4-main.28f8d3d → 0.8.4-main.2c6827d

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 (55) hide show
  1. package/dist/lib/browser/{chunk-X2FWMHD4.mjs → chunk-CPBXT2HX.mjs} +87 -80
  2. package/dist/lib/browser/chunk-CPBXT2HX.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 +27 -6
  6. package/dist/lib/browser/testing/index.mjs.map +4 -4
  7. package/dist/lib/node-esm/{chunk-RP7HSSCA.mjs → chunk-D3RM3FQW.mjs} +87 -80
  8. package/dist/lib/node-esm/chunk-D3RM3FQW.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 +27 -6
  12. package/dist/lib/node-esm/testing/index.mjs.map +4 -4
  13. package/dist/types/src/compute-graph-registry.d.ts +9 -6
  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 +5 -2
  18. package/dist/types/src/compute-graph.d.ts.map +1 -1
  19. package/dist/types/src/compute-node.d.ts +1 -2
  20. package/dist/types/src/compute-node.d.ts.map +1 -1
  21. package/dist/types/src/functions/async-function.d.ts +13 -11
  22. package/dist/types/src/functions/async-function.d.ts.map +1 -1
  23. package/dist/types/src/functions/edge-function.d.ts +3 -3
  24. package/dist/types/src/functions/edge-function.d.ts.map +1 -1
  25. package/dist/types/src/index.d.ts.map +1 -1
  26. package/dist/types/src/testing/index.d.ts +1 -0
  27. package/dist/types/src/testing/index.d.ts.map +1 -1
  28. package/dist/types/src/testing/test-builder.d.ts +1 -1
  29. package/dist/types/src/testing/test-builder.d.ts.map +1 -1
  30. package/dist/types/src/testing/test-plugin.d.ts +4 -5
  31. package/dist/types/src/testing/test-plugin.d.ts.map +1 -1
  32. package/dist/types/src/testing/test-runtime.d.ts +10 -0
  33. package/dist/types/src/testing/test-runtime.d.ts.map +1 -0
  34. package/dist/types/src/types/hyperformula.d.ts +3 -6
  35. package/dist/types/src/types/hyperformula.d.ts.map +1 -1
  36. package/dist/types/tsconfig.tsbuildinfo +1 -1
  37. package/package.json +23 -29
  38. package/src/compute-graph-registry.test.ts +154 -0
  39. package/src/compute-graph-registry.ts +19 -13
  40. package/src/compute-graph.test.ts +31 -13
  41. package/src/compute-graph.ts +25 -15
  42. package/src/compute-node.ts +2 -5
  43. package/src/functions/async-function.ts +20 -15
  44. package/src/functions/edge-function.ts +25 -23
  45. package/src/hyperformula.test.ts +1 -1
  46. package/src/index.ts +0 -27
  47. package/src/testing/index.ts +1 -0
  48. package/src/testing/test-builder.ts +8 -2
  49. package/src/testing/test-plugin.ts +2 -5
  50. package/src/testing/test-runtime.ts +33 -0
  51. package/src/testing/util.ts +1 -1
  52. package/src/types/hyperformula.ts +8 -8
  53. package/dist/lib/browser/chunk-X2FWMHD4.mjs.map +0 -7
  54. package/dist/lib/node-esm/chunk-RP7HSSCA.mjs.map +0 -7
  55. package/dist/vendor/hyperformula.mjs +0 -36400
@@ -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 { type InterpreterState } from 'hyperformula/typings/interpreter/InterpreterState';\nimport { type ProcedureAst } from 'hyperformula/typings/parser';\n\nimport { getDeep } from '@dxos/util';\n\nimport { FunctionArgumentType } from '#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 'hyperformula';\n\nexport const getRegisteredFunctionNames = () => {\n return HyperFormula.buildEmpty({ licenseKey: 'gpl-v3' }).getRegisteredFunctionNames();\n};\n"],
5
- "mappings": ";;;;;;AAIA,SAASA,cAAkC;AAC3C,SAAuBC,gBAAgB;AACvC,SAASC,iBAAiB;;AAOnB,IAAMC,cAAN,cAA0BC,SAAAA;;EACvBC;EACAC;EAER,YAA6BC,WAA+B,CAAC,GAAG;AAC9D,UAAK,GAAA,KADsBA,WAAAA;EAE7B;EAEA,IAAIC,MAAe;AACjB,WAAO,KAAKC;EACd;EAEA,IAAIC,SAAiB;AACnBC,cAAU,KAAKN,SAAO,QAAA;;;;;;;;;AACtB,WAAO,KAAKA;EACd;EAEA,IAAIO,W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C;QAAOJ;QAAU;OAAO;AAC5D,UAAI,CAACM,MAAM;AACT,eAAOE;MACT;AAEA,aAAOC,kBAAkBH,IAAAA;IAC3B;AAEA,WAAO,KAAKX,iBAAiBJ,KAAKC,OAAOC,SAAS;MAAEiB,KAAK;IAAO,CAAA;EAClE;AACF;AAEAtB,WAAWuB,uBAAuB;EAChCC,MAAM;IACJC,QAAQ;IACRC,YAAY;MAAC;QAAEC,cAAcC,qBAAqBC;QAAQC,aAAa;MAAM;;IAC7EC,YAAY;EACd;EAEAC,QAAQ;IACNP,QAAQ;IACRC,YAAY,CAAA;IACZK,YAAY;EACd;EAEAE,QAAQ;IACNR,QAAQ;IACRC,YAAY;MAAC;QAAEC,cAAcC,qBAAqBM;QAAQJ,aAAa;MAAK;;IAC5EC,YAAY;EACd;AACF;AAEO,IAAMI,yBAAyB;EACpCC,MAAM;IACJZ,MAAM;IACNQ,QAAQ;IACRC,QAAQ;EACV;EACAI,MAAM;IACJb,MAAM;IACNQ,QAAQ;IACRC,QAAQ;EACV;AACF;AAEO,IAAMK,sBAA4C;EACvD;IACEC,QAAQvC;IACRwC,cAAcL;EAChB;;;;AE/FF,SAASM,oBAAoB;AAEtB,IAAMC,6BAA6B,MAAA;AACxC,SAAOC,aAAaC,WAAW;IAAEC,YAAY;EAAS,CAAA,EAAGH,2BAA0B;AACrF;",
6
- "names": ["Client", "Resource", "invariant", "TestBuilder", "Resource", "_client", "_registry", "_options", "ctx", "_ctx", "client", "invariant", "registry", "_open", "Client", "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 { CredentialsService, DatabaseService, 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(DatabaseService.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": ";;;;;;AAIA,SAASA,cAAkC;AAC3C,SAAuBC,gBAAgB;AACvC,SAASC,iBAAiB;;;ACF1B,YAAYC,WAAW;AACvB,YAAYC,oBAAoB;AAEhC,SAASC,iBAAiB;AAE1B,SAASC,oBAAoBC,iBAA0CC,oBAAoB;AAC3F,SAASC,0CAA0C;AAQ5C,IAAMC,qCAAqC,CAAC,EACjDC,UAAS,IACmC,CAAC,MAAC;AAC9C,SAAO;IACLC,YAAY,CAACC,aAC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IACRwC,cAAcL;EAChB;;;;AE5FF,SAASM,oBAAoB;AAEtB,IAAMC,6BAA6B,MAAA;AACxC,SAAOC,aAAaC,WAAW;IAAEC,YAAY;EAAS,CAAA,EAAGH,2BAA0B;AACrF;",
6
+ "names": ["Client", "Resource", "invariant", "Layer", "ManagedRuntime", "AiService", "CredentialsService", "DatabaseService", "QueueService", "FunctionInvocationServiceLayerTest", "createMockedComputeRuntimeProvider", "functions", "getRuntime", "_spaceId", "make", "FunctionInvocationServiceLayerTest", "pipe", "provide", "AiService", "notAvailable", "CredentialsService", "configuredLayer", "DatabaseService", "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
  }
@@ -1,7 +1,7 @@
1
1
  import { createRequire } from 'node:module';const require = createRequire(import.meta.url);
2
2
 
3
3
  // src/types/hyperformula.ts
4
- import { DetailedCellError, ExportedCellChange } from "#hyperformula";
4
+ import { DetailedCellError, ExportedCellChange } from "@dxos/vendor-hyperformula";
5
5
 
6
6
  // src/types/types.ts
7
7
  import { invariant } from "@dxos/invariant";
@@ -79,13 +79,13 @@ var inRange = (range, cell) => {
79
79
  // src/compute-node.ts
80
80
  import { Event } from "@dxos/async";
81
81
  import { Resource } from "@dxos/context";
82
- import { DetailedCellError as DetailedCellError2 } from "#hyperformula";
82
+ import { DetailedCellError as DetailedCellError2 } from "@dxos/vendor-hyperformula";
83
83
  var ComputeNode = class extends Resource {
84
84
  _graph;
85
85
  sheetId;
86
- update;
86
+ update = new Event();
87
87
  constructor(_graph, sheetId) {
88
- super(), this._graph = _graph, this.sheetId = sheetId, this.update = new Event();
88
+ super(), this._graph = _graph, this.sheetId = sheetId;
89
89
  }
90
90
  get graph() {
91
91
  return this._graph;
@@ -125,15 +125,15 @@ var ComputeNode = class extends Resource {
125
125
  import defaultsDeep from "lodash.defaultsdeep";
126
126
  import { debounce } from "@dxos/async";
127
127
  import { log } from "@dxos/log";
128
- import { CellError, EmptyValue, ErrorType, FunctionPlugin } from "#hyperformula";
128
+ import { CellError, EmptyValue, ErrorType, FunctionPlugin } from "@dxos/vendor-hyperformula";
129
129
  var __dxlog_file2 = "/__w/dxos/dxos/packages/core/compute/src/functions/async-function.ts";
130
130
  var defaultFunctionContextOptions = {
131
131
  defaultTtl: 5e3,
132
- debounceDelay: 200,
133
- remoteFunctionUrl: "https://edge.dxos.workers.dev/functions"
132
+ debounceDelay: 200
134
133
  };
135
134
  var FunctionContext = class _FunctionContext {
136
135
  _hf;
136
+ _runtime;
137
137
  _space;
138
138
  // Mangle name with params.
139
139
  static createInvocationKey(name, ...args) {
@@ -144,23 +144,20 @@ var FunctionContext = class _FunctionContext {
144
144
  }
145
145
  // TODO(wittjosiah): Persist cached values.
146
146
  // Cached values for cell.
147
- _cache;
147
+ _cache = /* @__PURE__ */ new Map();
148
148
  // Active requests.
149
- _pending;
149
+ _pending = /* @__PURE__ */ new Map();
150
150
  // Query subscriptions.
151
- _subscriptions;
151
+ _subscriptions = /* @__PURE__ */ new Map();
152
152
  // Invocation count.
153
- _invocations;
153
+ _invocations = {};
154
154
  _options;
155
155
  // Debounced update handler.
156
156
  _onUpdate;
157
- constructor(_hf, _space, _options) {
157
+ constructor(_hf, _runtime, _space, _options) {
158
158
  this._hf = _hf;
159
+ this._runtime = _runtime;
159
160
  this._space = _space;
160
- this._cache = /* @__PURE__ */ new Map();
161
- this._pending = /* @__PURE__ */ new Map();
162
- this._subscriptions = /* @__PURE__ */ new Map();
163
- this._invocations = {};
164
161
  this._options = defaultsDeep(_options ?? {}, defaultFunctionContextOptions);
165
162
  this._onUpdate = debounce((update) => {
166
163
  log("update", update, {
@@ -176,15 +173,15 @@ var FunctionContext = class _FunctionContext {
176
173
  get space() {
177
174
  return this._space;
178
175
  }
179
- get remoteFunctionUrl() {
180
- return this._options.remoteFunctionUrl;
181
- }
182
176
  get info() {
183
177
  return {
184
178
  cache: this._cache.size,
185
179
  invocations: this._invocations
186
180
  };
187
181
  }
182
+ get runtime() {
183
+ return this._runtime;
184
+ }
188
185
  flush() {
189
186
  this._cache.clear();
190
187
  this._invocations = {};
@@ -280,13 +277,15 @@ var AsyncFunctionPlugin = class extends FunctionPlugin {
280
277
 
281
278
  // src/functions/edge-function.ts
282
279
  import { effect } from "@preact/signals-core";
283
- import { SchemaAST } from "effect";
284
- import { Filter, getMeta } from "@dxos/client/echo";
285
- import { toEffectSchema } from "@dxos/echo-schema";
286
- import { FunctionType, getUserFunctionUrlInMetadata } from "@dxos/functions";
280
+ import * as Effect from "effect/Effect";
281
+ import * as SchemaAST from "effect/SchemaAST";
282
+ import { Filter } from "@dxos/client/echo";
283
+ import { toEffectSchema } from "@dxos/echo/internal";
284
+ import { Function, FunctionInvocationService, TracingService } from "@dxos/functions";
285
+ import { FunctionDefinition } from "@dxos/functions";
287
286
  import { log as log2 } from "@dxos/log";
288
287
  import { isNonNullable } from "@dxos/util";
289
- import { CellError as CellError2, ErrorType as ErrorType2, FunctionArgumentType } from "#hyperformula";
288
+ import { CellError as CellError2, ErrorType as ErrorType2, FunctionArgumentType } from "@dxos/vendor-hyperformula";
290
289
  var __dxlog_file3 = "/__w/dxos/dxos/packages/core/compute/src/functions/edge-function.ts";
291
290
  var EDGE_FUNCTION_NAME = "DX";
292
291
  var FUNCTION_TTL = 1e4;
@@ -297,7 +296,7 @@ var EdgeFunctionPlugin = class extends AsyncFunctionPlugin {
297
296
  if (!space) {
298
297
  return new CellError2(ErrorType2.REF, "Missing space");
299
298
  }
300
- const { objects: [fn] } = await space.db.query(Filter.type(FunctionType, {
299
+ const { objects: [fn] } = await space.db.query(Filter.type(Function.Function, {
301
300
  binding
302
301
  })).run();
303
302
  if (!fn) {
@@ -305,7 +304,7 @@ var EdgeFunctionPlugin = class extends AsyncFunctionPlugin {
305
304
  binding
306
305
  }, {
307
306
  F: __dxlog_file3,
308
- L: 42,
307
+ L: 43,
309
308
  S: this,
310
309
  C: (f, a) => f(...a)
311
310
  });
@@ -317,7 +316,7 @@ var EdgeFunctionPlugin = class extends AsyncFunctionPlugin {
317
316
  fn
318
317
  }, {
319
318
  F: __dxlog_file3,
320
- L: 48,
319
+ L: 49,
321
320
  S: this,
322
321
  C: (f, a) => f(...a)
323
322
  });
@@ -328,32 +327,24 @@ var EdgeFunctionPlugin = class extends AsyncFunctionPlugin {
328
327
  });
329
328
  this.context.createSubscription(ast.procedureName, unsubscribe);
330
329
  }
331
- const body = {};
330
+ const runtime = this.context.runtime;
331
+ const functionDef = FunctionDefinition.deserialize(fn);
332
+ let input;
332
333
  if (fn.inputSchema) {
333
334
  const schema = toEffectSchema(fn.inputSchema);
334
- SchemaAST.getPropertySignatures(schema.ast).forEach(({ name }, index) => {
335
- body[name.toString()] = args[index];
335
+ const props = SchemaAST.getPropertySignatures(schema.ast);
336
+ input = {};
337
+ props.forEach(({ name }, index) => {
338
+ input[name.toString()] = args[index];
336
339
  });
337
340
  } else {
338
- body.args = args.filter(isNonNullable);
341
+ input = {
342
+ args: args.filter(isNonNullable)
343
+ };
339
344
  }
340
- const path = getUserFunctionUrlInMetadata(getMeta(fn));
341
- const response = await fetch(`${this.context.remoteFunctionUrl}${path}`, {
342
- method: "POST",
343
- headers: {
344
- "Content-Type": "application/json"
345
- },
346
- body: JSON.stringify(body)
347
- });
348
- const result = await response.text();
349
- log2("function executed", {
350
- result
351
- }, {
352
- F: __dxlog_file3,
353
- L: 75,
354
- S: this,
355
- C: (f, a) => f(...a)
356
- });
345
+ const result = runtime.runPromise(Effect.gen(function* () {
346
+ return yield* FunctionInvocationService.invokeFunction(functionDef, input);
347
+ }).pipe(Effect.provide(TracingService.layerNoop)));
357
348
  return result;
358
349
  };
359
350
  return this.runAsyncFunction(ast, state, handler(true), {
@@ -2790,17 +2781,19 @@ var defaultFunctions = [
2790
2781
  ];
2791
2782
 
2792
2783
  // src/compute-graph.ts
2784
+ import { effect as effect2 } from "@preact/signals-core";
2793
2785
  import { Event as Event2 } from "@dxos/async";
2794
- import { Filter as Filter2, fullyQualifiedId } from "@dxos/client/echo";
2786
+ import { Filter as Filter2 } from "@dxos/client/echo";
2795
2787
  import { FQ_ID_LENGTH } from "@dxos/client/echo";
2796
2788
  import { Resource as Resource2 } from "@dxos/context";
2797
- import { getTypename } from "@dxos/echo-schema";
2798
- import { FunctionType as FunctionType2 } from "@dxos/functions";
2789
+ import { Obj } from "@dxos/echo";
2790
+ import { getTypename } from "@dxos/echo/internal";
2791
+ import { Function as Function2 } from "@dxos/functions";
2799
2792
  import { invariant as invariant2 } from "@dxos/invariant";
2800
2793
  import { PublicKey } from "@dxos/keys";
2801
2794
  import { log as log3 } from "@dxos/log";
2802
2795
  import { isNonNullable as isNonNullable2 } from "@dxos/util";
2803
- import { ExportedCellChange as ExportedCellChange2 } from "#hyperformula";
2796
+ import { ExportedCellChange as ExportedCellChange2 } from "@dxos/vendor-hyperformula";
2804
2797
  var __dxlog_file4 = "/__w/dxos/dxos/packages/core/compute/src/compute-graph.ts";
2805
2798
  var UNKNOWN_BINDING = "__UNKNOWN__";
2806
2799
  var createSheetName = ({ type, id }) => `${type}@${id}`;
@@ -2815,19 +2808,20 @@ var parseSheetName = (name) => {
2815
2808
  };
2816
2809
  var ComputeGraph = class extends Resource2 {
2817
2810
  _hf;
2811
+ _runtime;
2818
2812
  _space;
2819
2813
  _options;
2820
- id;
2814
+ id = `graph-${PublicKey.random().truncate()}`;
2821
2815
  // Map of nodes indexed by sheet number.
2822
- _nodes;
2816
+ _nodes = /* @__PURE__ */ new Map();
2823
2817
  // Cached function objects.
2824
- _remoteFunctions;
2825
- update;
2818
+ _remoteFunctions = [];
2819
+ update = new Event2();
2826
2820
  // The context is passed to all functions.
2827
2821
  context;
2828
- constructor(_hf, _space, _options) {
2829
- super(), 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();
2830
- this.context = new FunctionContext(this._hf, this._space, {
2822
+ constructor(_hf, _runtime, _space, _options) {
2823
+ super(), this._hf = _hf, this._runtime = _runtime, this._space = _space, this._options = _options;
2824
+ this.context = new FunctionContext(this._hf, this._runtime, this._space, {
2831
2825
  ...this._options,
2832
2826
  onUpdate: (update) => {
2833
2827
  this._options?.onUpdate?.(update);
@@ -2883,7 +2877,7 @@ var ComputeGraph = class extends Resource2 {
2883
2877
  getOrCreateNode(name) {
2884
2878
  invariant2(name.length, void 0, {
2885
2879
  F: __dxlog_file4,
2886
- L: 129,
2880
+ L: 135,
2887
2881
  S: this,
2888
2882
  A: [
2889
2883
  "name.length",
@@ -2896,7 +2890,7 @@ var ComputeGraph = class extends Resource2 {
2896
2890
  sheet: name
2897
2891
  }, {
2898
2892
  F: __dxlog_file4,
2899
- L: 131,
2893
+ L: 137,
2900
2894
  S: this,
2901
2895
  C: (f, a) => f(...a)
2902
2896
  });
@@ -2905,7 +2899,7 @@ var ComputeGraph = class extends Resource2 {
2905
2899
  const sheetId = this._hf.getSheetId(name);
2906
2900
  invariant2(sheetId !== void 0, void 0, {
2907
2901
  F: __dxlog_file4,
2908
- L: 136,
2902
+ L: 142,
2909
2903
  S: this,
2910
2904
  A: [
2911
2905
  "sheetId !== undefined",
@@ -2961,7 +2955,7 @@ var ComputeGraph = class extends Resource2 {
2961
2955
  }
2962
2956
  const fn = this._remoteFunctions.find((fn2) => fn2.binding === binding);
2963
2957
  if (fn) {
2964
- const id = fullyQualifiedId(fn);
2958
+ const id = Obj.getDXN(fn).toString();
2965
2959
  return `${id}(${args})`;
2966
2960
  } else {
2967
2961
  return match;
@@ -2978,7 +2972,7 @@ var ComputeGraph = class extends Resource2 {
2978
2972
  if (id.length !== FQ_ID_LENGTH) {
2979
2973
  return match;
2980
2974
  }
2981
- const fn = this._remoteFunctions.find((fn2) => fullyQualifiedId(fn2) === id);
2975
+ const fn = this._remoteFunctions.find((fn2) => Obj.getDXN(fn2).toString() === id);
2982
2976
  if (fn?.binding) {
2983
2977
  return `${fn.binding}(${args})`;
2984
2978
  } else {
@@ -2993,14 +2987,18 @@ var ComputeGraph = class extends Resource2 {
2993
2987
  }
2994
2988
  async _open() {
2995
2989
  if (this._space) {
2996
- const query = this._space.db.query(Filter2.type(FunctionType2));
2997
- const unsubscribe = query.subscribe(({ objects }) => {
2998
- this._remoteFunctions = objects.filter(({ binding }) => binding);
2990
+ const query = this._space.db.query(Filter2.type(Function2.Function));
2991
+ const unsubscribe = query.subscribe();
2992
+ const dispose = effect2(() => {
2993
+ this._remoteFunctions = query.objects.filter(({ binding }) => binding);
2999
2994
  this.update.emit({
3000
2995
  type: "functionsUpdated"
3001
2996
  });
3002
2997
  });
3003
- this._ctx.onDispose(unsubscribe);
2998
+ this._ctx.onDispose(() => {
2999
+ unsubscribe();
3000
+ dispose();
3001
+ });
3004
3002
  }
3005
3003
  }
3006
3004
  async _close() {
@@ -3015,25 +3013,24 @@ import defaultsDeep2 from "lodash.defaultsdeep";
3015
3013
  import { Resource as Resource3 } from "@dxos/context";
3016
3014
  import { invariant as invariant3 } from "@dxos/invariant";
3017
3015
  import { log as log4 } from "@dxos/log";
3018
- import { HyperFormula } from "#hyperformula";
3016
+ import { HyperFormula } from "@dxos/vendor-hyperformula";
3019
3017
  var __dxlog_file5 = "/__w/dxos/dxos/packages/core/compute/src/compute-graph-registry.ts";
3020
- var defaultOptions = {
3021
- licenseKey: "gpl-v3"
3022
- };
3023
3018
  var defaultPlugins = [
3024
3019
  {
3025
3020
  plugin: EdgeFunctionPlugin,
3026
3021
  translations: EdgeFunctionPluginTranslations
3027
3022
  }
3028
3023
  ];
3024
+ var defaultOptions = {
3025
+ licenseKey: "gpl-v3"
3026
+ };
3029
3027
  var ComputeGraphRegistry = class extends Resource3 {
3030
3028
  _graphs = /* @__PURE__ */ new Map();
3031
3029
  _options;
3032
- constructor(options = {
3033
- plugins: defaultPlugins
3034
- }) {
3030
+ constructor(options) {
3035
3031
  super();
3036
3032
  this._options = defaultsDeep2({}, options, defaultOptions);
3033
+ this._options.plugins = this._options.plugins ?? defaultPlugins;
3037
3034
  this._options.plugins?.forEach(({ plugin, translations }) => {
3038
3035
  HyperFormula.registerFunctionPlugin(plugin, translations);
3039
3036
  });
@@ -3048,7 +3045,7 @@ var ComputeGraphRegistry = class extends Resource3 {
3048
3045
  space: space.id
3049
3046
  }, {
3050
3047
  F: __dxlog_file5,
3051
- L: 70,
3048
+ L: 73,
3052
3049
  S: this,
3053
3050
  C: (f, a) => f(...a)
3054
3051
  });
@@ -3059,7 +3056,7 @@ var ComputeGraphRegistry = class extends Resource3 {
3059
3056
  createGraph(space) {
3060
3057
  invariant3(!this._graphs.has(space.id), `ComputeGraph already exists for space: ${space.id}`, {
3061
3058
  F: __dxlog_file5,
3062
- L: 78,
3059
+ L: 81,
3063
3060
  S: this,
3064
3061
  A: [
3065
3062
  "!this._graphs.has(space.id)",
@@ -3067,7 +3064,17 @@ var ComputeGraphRegistry = class extends Resource3 {
3067
3064
  ]
3068
3065
  });
3069
3066
  const hf = HyperFormula.buildEmpty(this._options);
3070
- const graph = new ComputeGraph(hf, space, this._options);
3067
+ invariant3(this._options.computeRuntime, "ComputeRuntime is required", {
3068
+ F: __dxlog_file5,
3069
+ L: 83,
3070
+ S: this,
3071
+ A: [
3072
+ "this._options.computeRuntime",
3073
+ "'ComputeRuntime is required'"
3074
+ ]
3075
+ });
3076
+ const runtime = this._options.computeRuntime.getRuntime(space.id);
3077
+ const graph = new ComputeGraph(hf, runtime, space, this._options);
3071
3078
  this._graphs.set(space.id, graph);
3072
3079
  return graph;
3073
3080
  }
@@ -3102,8 +3109,8 @@ export {
3102
3109
  createSheetName,
3103
3110
  parseSheetName,
3104
3111
  ComputeGraph,
3105
- defaultOptions,
3106
3112
  defaultPlugins,
3113
+ defaultOptions,
3107
3114
  ComputeGraphRegistry
3108
3115
  };
3109
- //# sourceMappingURL=chunk-RP7HSSCA.mjs.map
3116
+ //# sourceMappingURL=chunk-D3RM3FQW.mjs.map