@dxos/compute 0.8.4-main.5ad4a44 → 0.8.4-main.66e292d

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.
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
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 {\n CredentialsService,\n DatabaseService,\n type FunctionDefinition,\n FunctionInvocationService,\n QueueService,\n} from '@dxos/functions';\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, any>[] } = {}): FunctionsRuntimeProvider => {\n return {\n getRuntime: (_spaceId: SpaceId) =>\n ManagedRuntime.make(\n FunctionInvocationService.layerTest({ 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,SACEC,oBACAC,iBAEAC,2BACAC,oBACK;AAQA,IAAMC,qCAAqC,CAAC,EACjDC,UAAS,IACyC,CAAC,MAAC;AACpD,SAAO;IACLC,YAAY,CAACC,aACIC,oBACbC,0BAA0BC,UAAU;M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MAAM;IACNQ,QAAQ;IACRC,QAAQ;EACV;AACF;AAEO,IAAMK,sBAA4C;EACvD;IACEC,QAAQvC;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", "FunctionInvocationService", "QueueService", "createMockedComputeRuntimeProvider", "functions", "getRuntime", "_spaceId", "make", "FunctionInvocationService", "layerTest", "pipe", "provide", "AiService", "notAvailable", "CredentialsService", "configuredLayer", "DatabaseService", "QueueService", "TestBuilder", "Resource", "ctx", "_ctx", "client", "invariant", "_client", "registry", "_registry", "_open", "Client", "_options", "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"]
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,aACIC,oBACbC,mCAAmC;MAAEJ;IAAU,CAAA,EAAGK,KAC1CC,cAAQC,UAAUC,YAAY,GAC9BF,cAAQG,mBAAmBC,gBAAgB,CAAA,CAAE,CAAA,GAC7CJ,cAAQK,gBAAgBH,YAAY,GACpCF,cAAQM,aAAaJ,YAAY,CAAA,CAAA;EAG/C;AACF;;;;ADjBO,IAAMK,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,WAAiC;A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,OAAOG,KAAI;AAC9B,YAAMC,OAAOC,QAAgBH,MAAM;QAAC;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;;;;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
  }
@@ -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,25 +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
132
  debounceDelay: 200
156
133
  };
157
134
  var FunctionContext = class _FunctionContext {
135
+ _hf;
136
+ _runtime;
137
+ _space;
158
138
  // Mangle name with params.
159
139
  static createInvocationKey(name, ...args) {
160
140
  return JSON.stringify({
@@ -162,6 +142,34 @@ var FunctionContext = class _FunctionContext {
162
142
  ...args
163
143
  });
164
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
+ }
165
173
  get space() {
166
174
  return this._space;
167
175
  }
@@ -250,35 +258,6 @@ var FunctionContext = class _FunctionContext {
250
258
  });
251
259
  return value;
252
260
  }
253
- constructor(_hf, _runtime, _space, _options) {
254
- _define_property2(this, "_hf", void 0);
255
- _define_property2(this, "_runtime", 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._runtime = _runtime;
265
- this._space = _space;
266
- this._cache = /* @__PURE__ */ new Map();
267
- this._pending = /* @__PURE__ */ new Map();
268
- this._subscriptions = /* @__PURE__ */ new Map();
269
- this._invocations = {};
270
- this._options = defaultsDeep(_options ?? {}, defaultFunctionContextOptions);
271
- this._onUpdate = debounce((update) => {
272
- log("update", update, {
273
- F: __dxlog_file2,
274
- L: 86,
275
- S: this,
276
- C: (f, a) => f(...a)
277
- });
278
- this._hf.resumeEvaluation();
279
- this._options.onUpdate?.(update);
280
- }, this._options.debounceDelay);
281
- }
282
261
  };
283
262
  var AsyncFunctionPlugin = class extends FunctionPlugin {
284
263
  get context() {
@@ -301,8 +280,8 @@ import { effect } from "@preact/signals-core";
301
280
  import * as Effect from "effect/Effect";
302
281
  import * as SchemaAST from "effect/SchemaAST";
303
282
  import { Filter } from "@dxos/client/echo";
304
- import { toEffectSchema } from "@dxos/echo/internal";
305
- import { ComputeEventLogger, FunctionInvocationService, FunctionType, TracingService } from "@dxos/functions";
283
+ import { JsonSchema } from "@dxos/echo";
284
+ import { Function, FunctionInvocationService, TracingService } from "@dxos/functions";
306
285
  import { FunctionDefinition } from "@dxos/functions";
307
286
  import { log as log2 } from "@dxos/log";
308
287
  import { isNonNullable } from "@dxos/util";
@@ -317,7 +296,7 @@ var EdgeFunctionPlugin = class extends AsyncFunctionPlugin {
317
296
  if (!space) {
318
297
  return new CellError2(ErrorType2.REF, "Missing space");
319
298
  }
320
- const { objects: [fn] } = await space.db.query(Filter.type(FunctionType, {
299
+ const { objects: [fn] } = await space.db.query(Filter.type(Function.Function, {
321
300
  binding
322
301
  })).run();
323
302
  if (!fn) {
@@ -352,7 +331,7 @@ var EdgeFunctionPlugin = class extends AsyncFunctionPlugin {
352
331
  const functionDef = FunctionDefinition.deserialize(fn);
353
332
  let input;
354
333
  if (fn.inputSchema) {
355
- const schema = toEffectSchema(fn.inputSchema);
334
+ const schema = JsonSchema.toEffectSchema(fn.inputSchema);
356
335
  const props = SchemaAST.getPropertySignatures(schema.ast);
357
336
  input = {};
358
337
  props.forEach(({ name }, index) => {
@@ -365,7 +344,7 @@ var EdgeFunctionPlugin = class extends AsyncFunctionPlugin {
365
344
  }
366
345
  const result = runtime.runPromise(Effect.gen(function* () {
367
346
  return yield* FunctionInvocationService.invokeFunction(functionDef, input);
368
- }).pipe(Effect.provide(ComputeEventLogger.layerFromTracing), Effect.provide(TracingService.layerNoop)));
347
+ }).pipe(Effect.provide(TracingService.layerNoop)));
369
348
  return result;
370
349
  };
371
350
  return this.runAsyncFunction(ast, state, handler(true), {
@@ -2802,30 +2781,18 @@ var defaultFunctions = [
2802
2781
  ];
2803
2782
 
2804
2783
  // src/compute-graph.ts
2784
+ import { effect as effect2 } from "@preact/signals-core";
2805
2785
  import { Event as Event2 } from "@dxos/async";
2806
- import { Filter as Filter2, fullyQualifiedId } from "@dxos/client/echo";
2786
+ import { Filter as Filter2 } from "@dxos/client/echo";
2807
2787
  import { FQ_ID_LENGTH } from "@dxos/client/echo";
2808
2788
  import { Resource as Resource2 } from "@dxos/context";
2809
- import { getTypename } from "@dxos/echo/internal";
2810
- import { FunctionType as FunctionType2 } from "@dxos/functions";
2789
+ import { Obj } from "@dxos/echo";
2790
+ import { Function as Function2 } from "@dxos/functions";
2811
2791
  import { invariant as invariant2 } from "@dxos/invariant";
2812
2792
  import { PublicKey } from "@dxos/keys";
2813
2793
  import { log as log3 } from "@dxos/log";
2814
2794
  import { isNonNullable as isNonNullable2 } from "@dxos/util";
2815
2795
  import { ExportedCellChange as ExportedCellChange2 } from "@dxos/vendor-hyperformula";
2816
- function _define_property3(obj, key, value) {
2817
- if (key in obj) {
2818
- Object.defineProperty(obj, key, {
2819
- value,
2820
- enumerable: true,
2821
- configurable: true,
2822
- writable: true
2823
- });
2824
- } else {
2825
- obj[key] = value;
2826
- }
2827
- return obj;
2828
- }
2829
2796
  var __dxlog_file4 = "/__w/dxos/dxos/packages/core/compute/src/compute-graph.ts";
2830
2797
  var UNKNOWN_BINDING = "__UNKNOWN__";
2831
2798
  var createSheetName = ({ type, id }) => `${type}@${id}`;
@@ -2839,6 +2806,49 @@ var parseSheetName = (name) => {
2839
2806
  };
2840
2807
  };
2841
2808
  var ComputeGraph = class extends Resource2 {
2809
+ _hf;
2810
+ _runtime;
2811
+ _space;
2812
+ _options;
2813
+ id = `graph-${PublicKey.random().truncate()}`;
2814
+ // Map of nodes indexed by sheet number.
2815
+ _nodes = /* @__PURE__ */ new Map();
2816
+ // Cached function objects.
2817
+ _remoteFunctions = [];
2818
+ update = new Event2();
2819
+ // The context is passed to all functions.
2820
+ context;
2821
+ constructor(_hf, _runtime, _space, _options) {
2822
+ super(), this._hf = _hf, this._runtime = _runtime, this._space = _space, this._options = _options;
2823
+ this.context = new FunctionContext(this._hf, this._runtime, this._space, {
2824
+ ...this._options,
2825
+ onUpdate: (update) => {
2826
+ this._options?.onUpdate?.(update);
2827
+ this.update.emit({
2828
+ type: "valuesUpdated"
2829
+ });
2830
+ }
2831
+ });
2832
+ this._hf.updateConfig({
2833
+ context: this.context
2834
+ });
2835
+ const onValuesUpdate = (changes) => {
2836
+ for (const change of changes) {
2837
+ if (change instanceof ExportedCellChange2) {
2838
+ const { sheet } = change;
2839
+ const node = this._nodes.get(sheet);
2840
+ if (node) {
2841
+ node.update.emit({
2842
+ type: "valuesUpdated",
2843
+ change
2844
+ });
2845
+ }
2846
+ }
2847
+ }
2848
+ };
2849
+ this._hf.on("valuesUpdated", onValuesUpdate);
2850
+ this._ctx.onDispose(() => this._hf.off("valuesUpdated", onValuesUpdate));
2851
+ }
2842
2852
  get hf() {
2843
2853
  return this._hf;
2844
2854
  }
@@ -2866,7 +2876,7 @@ var ComputeGraph = class extends Resource2 {
2866
2876
  getOrCreateNode(name) {
2867
2877
  invariant2(name.length, void 0, {
2868
2878
  F: __dxlog_file4,
2869
- L: 130,
2879
+ L: 134,
2870
2880
  S: this,
2871
2881
  A: [
2872
2882
  "name.length",
@@ -2879,7 +2889,7 @@ var ComputeGraph = class extends Resource2 {
2879
2889
  sheet: name
2880
2890
  }, {
2881
2891
  F: __dxlog_file4,
2882
- L: 132,
2892
+ L: 136,
2883
2893
  S: this,
2884
2894
  C: (f, a) => f(...a)
2885
2895
  });
@@ -2888,7 +2898,7 @@ var ComputeGraph = class extends Resource2 {
2888
2898
  const sheetId = this._hf.getSheetId(name);
2889
2899
  invariant2(sheetId !== void 0, void 0, {
2890
2900
  F: __dxlog_file4,
2891
- L: 137,
2901
+ L: 141,
2892
2902
  S: this,
2893
2903
  A: [
2894
2904
  "sheetId !== undefined",
@@ -2912,7 +2922,7 @@ var ComputeGraph = class extends Resource2 {
2912
2922
  }).filter(isNonNullable2);
2913
2923
  for (const obj of objects) {
2914
2924
  if (obj.name === name) {
2915
- const type = getTypename(obj);
2925
+ const type = Obj.getTypename(obj);
2916
2926
  return `'${createSheetName({
2917
2927
  type,
2918
2928
  id: obj.id
@@ -2944,7 +2954,7 @@ var ComputeGraph = class extends Resource2 {
2944
2954
  }
2945
2955
  const fn = this._remoteFunctions.find((fn2) => fn2.binding === binding);
2946
2956
  if (fn) {
2947
- const id = fullyQualifiedId(fn);
2957
+ const id = Obj.getDXN(fn).toString();
2948
2958
  return `${id}(${args})`;
2949
2959
  } else {
2950
2960
  return match;
@@ -2961,7 +2971,7 @@ var ComputeGraph = class extends Resource2 {
2961
2971
  if (id.length !== FQ_ID_LENGTH) {
2962
2972
  return match;
2963
2973
  }
2964
- const fn = this._remoteFunctions.find((fn2) => fullyQualifiedId(fn2) === id);
2974
+ const fn = this._remoteFunctions.find((fn2) => Obj.getDXN(fn2).toString() === id);
2965
2975
  if (fn?.binding) {
2966
2976
  return `${fn.binding}(${args})`;
2967
2977
  } else {
@@ -2976,14 +2986,18 @@ var ComputeGraph = class extends Resource2 {
2976
2986
  }
2977
2987
  async _open() {
2978
2988
  if (this._space) {
2979
- const query = this._space.db.query(Filter2.type(FunctionType2));
2980
- const unsubscribe = query.subscribe(({ objects }) => {
2981
- this._remoteFunctions = objects.filter(({ binding }) => binding);
2989
+ const query = this._space.db.query(Filter2.type(Function2.Function));
2990
+ const unsubscribe = query.subscribe();
2991
+ const dispose = effect2(() => {
2992
+ this._remoteFunctions = query.objects.filter(({ binding }) => binding);
2982
2993
  this.update.emit({
2983
2994
  type: "functionsUpdated"
2984
2995
  });
2985
2996
  });
2986
- this._ctx.onDispose(unsubscribe);
2997
+ this._ctx.onDispose(() => {
2998
+ unsubscribe();
2999
+ dispose();
3000
+ });
2987
3001
  }
2988
3002
  }
2989
3003
  async _close() {
@@ -2991,40 +3005,6 @@ var ComputeGraph = class extends Resource2 {
2991
3005
  await node.close();
2992
3006
  }
2993
3007
  }
2994
- constructor(_hf, _runtime, _space, _options) {
2995
- super(), _define_property3(this, "_hf", void 0), _define_property3(this, "_runtime", 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.
2996
- _define_property3(this, "_nodes", void 0), // Cached function objects.
2997
- _define_property3(this, "_remoteFunctions", void 0), _define_property3(this, "update", void 0), // The context is passed to all functions.
2998
- _define_property3(this, "context", void 0), this._hf = _hf, this._runtime = _runtime, this._space = _space, this._options = _options, this.id = `graph-${PublicKey.random().truncate()}`, this._nodes = /* @__PURE__ */ new Map(), this._remoteFunctions = [], this.update = new Event2();
2999
- this.context = new FunctionContext(this._hf, this._runtime, this._space, {
3000
- ...this._options,
3001
- onUpdate: (update) => {
3002
- this._options?.onUpdate?.(update);
3003
- this.update.emit({
3004
- type: "valuesUpdated"
3005
- });
3006
- }
3007
- });
3008
- this._hf.updateConfig({
3009
- context: this.context
3010
- });
3011
- const onValuesUpdate = (changes) => {
3012
- for (const change of changes) {
3013
- if (change instanceof ExportedCellChange2) {
3014
- const { sheet } = change;
3015
- const node = this._nodes.get(sheet);
3016
- if (node) {
3017
- node.update.emit({
3018
- type: "valuesUpdated",
3019
- change
3020
- });
3021
- }
3022
- }
3023
- }
3024
- };
3025
- this._hf.on("valuesUpdated", onValuesUpdate);
3026
- this._ctx.onDispose(() => this._hf.off("valuesUpdated", onValuesUpdate));
3027
- }
3028
3008
  };
3029
3009
 
3030
3010
  // src/compute-graph-registry.ts
@@ -3033,19 +3013,6 @@ import { Resource as Resource3 } from "@dxos/context";
3033
3013
  import { invariant as invariant3 } from "@dxos/invariant";
3034
3014
  import { log as log4 } from "@dxos/log";
3035
3015
  import { HyperFormula } from "@dxos/vendor-hyperformula";
3036
- function _define_property4(obj, key, value) {
3037
- if (key in obj) {
3038
- Object.defineProperty(obj, key, {
3039
- value,
3040
- enumerable: true,
3041
- configurable: true,
3042
- writable: true
3043
- });
3044
- } else {
3045
- obj[key] = value;
3046
- }
3047
- return obj;
3048
- }
3049
3016
  var __dxlog_file5 = "/__w/dxos/dxos/packages/core/compute/src/compute-graph-registry.ts";
3050
3017
  var defaultPlugins = [
3051
3018
  {
@@ -3057,6 +3024,16 @@ var defaultOptions = {
3057
3024
  licenseKey: "gpl-v3"
3058
3025
  };
3059
3026
  var ComputeGraphRegistry = class extends Resource3 {
3027
+ _graphs = /* @__PURE__ */ new Map();
3028
+ _options;
3029
+ constructor(options) {
3030
+ super();
3031
+ this._options = defaultsDeep2({}, options, defaultOptions);
3032
+ this._options.plugins = this._options.plugins ?? defaultPlugins;
3033
+ this._options.plugins?.forEach(({ plugin, translations }) => {
3034
+ HyperFormula.registerFunctionPlugin(plugin, translations);
3035
+ });
3036
+ }
3060
3037
  getGraph(spaceId) {
3061
3038
  return this._graphs.get(spaceId);
3062
3039
  }
@@ -3106,14 +3083,6 @@ var ComputeGraphRegistry = class extends Resource3 {
3106
3083
  }
3107
3084
  this._graphs.clear();
3108
3085
  }
3109
- constructor(options) {
3110
- super(), _define_property4(this, "_graphs", /* @__PURE__ */ new Map()), _define_property4(this, "_options", void 0);
3111
- this._options = defaultsDeep2({}, options, defaultOptions);
3112
- this._options.plugins = this._options.plugins ?? defaultPlugins;
3113
- this._options.plugins?.forEach(({ plugin, translations }) => {
3114
- HyperFormula.registerFunctionPlugin(plugin, translations);
3115
- });
3116
- }
3117
3086
  };
3118
3087
 
3119
3088
  export {
@@ -3143,4 +3112,4 @@ export {
3143
3112
  defaultOptions,
3144
3113
  ComputeGraphRegistry
3145
3114
  };
3146
- //# sourceMappingURL=chunk-K37OSZ5O.mjs.map
3115
+ //# sourceMappingURL=chunk-QDJ6J7GT.mjs.map