@dxos/compute 0.8.4-main.84f28bd → 0.8.4-main.ae835ea
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.
- package/dist/lib/browser/{chunk-2PBHA7EI.mjs → chunk-CY35BVJC.mjs} +104 -69
- package/dist/lib/browser/chunk-CY35BVJC.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +1 -1
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/testing/index.mjs +29 -6
- package/dist/lib/browser/testing/index.mjs.map +4 -4
- package/dist/lib/node-esm/{chunk-GTPQNWA3.mjs → chunk-BECNONV7.mjs} +104 -69
- package/dist/lib/node-esm/chunk-BECNONV7.mjs.map +7 -0
- package/dist/lib/node-esm/index.mjs +1 -1
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/lib/node-esm/testing/index.mjs +29 -6
- package/dist/lib/node-esm/testing/index.mjs.map +4 -4
- package/dist/types/src/compute-graph-registry.d.ts +10 -7
- package/dist/types/src/compute-graph-registry.d.ts.map +1 -1
- package/dist/types/src/compute-graph-registry.test.d.ts +2 -0
- package/dist/types/src/compute-graph-registry.test.d.ts.map +1 -0
- package/dist/types/src/compute-graph.d.ts +5 -2
- package/dist/types/src/compute-graph.d.ts.map +1 -1
- package/dist/types/src/compute-node.d.ts +1 -2
- package/dist/types/src/compute-node.d.ts.map +1 -1
- package/dist/types/src/functions/async-function.d.ts +13 -11
- package/dist/types/src/functions/async-function.d.ts.map +1 -1
- package/dist/types/src/functions/edge-function.d.ts +3 -3
- package/dist/types/src/functions/edge-function.d.ts.map +1 -1
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/testing/index.d.ts +1 -0
- package/dist/types/src/testing/index.d.ts.map +1 -1
- package/dist/types/src/testing/test-builder.d.ts +1 -1
- package/dist/types/src/testing/test-builder.d.ts.map +1 -1
- package/dist/types/src/testing/test-plugin.d.ts +4 -5
- package/dist/types/src/testing/test-plugin.d.ts.map +1 -1
- package/dist/types/src/testing/test-runtime.d.ts +10 -0
- package/dist/types/src/testing/test-runtime.d.ts.map +1 -0
- package/dist/types/src/types/hyperformula.d.ts +3 -6
- package/dist/types/src/types/hyperformula.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +24 -28
- package/src/compute-graph-registry.test.ts +138 -0
- package/src/compute-graph-registry.ts +20 -13
- package/src/compute-graph.test.ts +5 -6
- package/src/compute-graph.ts +20 -13
- package/src/compute-node.ts +2 -4
- package/src/functions/async-function.ts +21 -16
- package/src/functions/edge-function.ts +25 -22
- package/src/hyperformula.test.ts +2 -2
- package/src/index.ts +0 -27
- package/src/testing/index.ts +1 -0
- package/src/testing/test-builder.ts +8 -2
- package/src/testing/test-plugin.ts +2 -4
- package/src/testing/test-runtime.ts +38 -0
- package/src/testing/util.ts +1 -1
- package/src/types/hyperformula.ts +8 -8
- package/src/types/types.test.ts +2 -2
- package/dist/lib/browser/chunk-2PBHA7EI.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-GTPQNWA3.mjs.map +0 -7
- 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
|
|
5
|
-
"mappings": ";;;;;;AAIA,SAASA,cAAkC;AAC3C,SAAuBC,gBAAgB;AACvC,SAASC,iBAAiB
|
|
6
|
-
"names": ["Client", "Resource", "invariant", "TestBuilder", "Resource", "
|
|
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;MAAEL;IAAU,CAAA,EAAGM,KAC3CC,cAAQC,UAAUC,YAAY,GAC9BF,cAAQG,mBAAmBC,gBAAgB,CAAA,CAAE,CAAA,GAC7CJ,cAAQK,gBAAgBH,YAAY,GACpCF,cAAQM,aA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", "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", "_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 "
|
|
4
|
+
import { DetailedCellError, ExportedCellChange } from "@dxos/vendor-hyperformula";
|
|
5
5
|
|
|
6
6
|
// src/types/types.ts
|
|
7
7
|
import { invariant } from "@dxos/invariant";
|
|
@@ -79,10 +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 "
|
|
82
|
+
import { DetailedCellError as DetailedCellError2 } from "@dxos/vendor-hyperformula";
|
|
83
83
|
var ComputeNode = class extends Resource {
|
|
84
|
+
_graph;
|
|
85
|
+
sheetId;
|
|
86
|
+
update = new Event();
|
|
84
87
|
constructor(_graph, sheetId) {
|
|
85
|
-
super(), this._graph = _graph, this.sheetId = sheetId
|
|
88
|
+
super(), this._graph = _graph, this.sheetId = sheetId;
|
|
86
89
|
}
|
|
87
90
|
get graph() {
|
|
88
91
|
return this._graph;
|
|
@@ -122,14 +125,16 @@ var ComputeNode = class extends Resource {
|
|
|
122
125
|
import defaultsDeep from "lodash.defaultsdeep";
|
|
123
126
|
import { debounce } from "@dxos/async";
|
|
124
127
|
import { log } from "@dxos/log";
|
|
125
|
-
import { CellError,
|
|
128
|
+
import { CellError, EmptyValue, ErrorType, FunctionPlugin } from "@dxos/vendor-hyperformula";
|
|
126
129
|
var __dxlog_file2 = "/__w/dxos/dxos/packages/core/compute/src/functions/async-function.ts";
|
|
127
130
|
var defaultFunctionContextOptions = {
|
|
128
131
|
defaultTtl: 5e3,
|
|
129
|
-
debounceDelay: 200
|
|
130
|
-
remoteFunctionUrl: "https://edge.dxos.workers.dev/functions"
|
|
132
|
+
debounceDelay: 200
|
|
131
133
|
};
|
|
132
134
|
var FunctionContext = class _FunctionContext {
|
|
135
|
+
_hf;
|
|
136
|
+
_runtime;
|
|
137
|
+
_space;
|
|
133
138
|
// Mangle name with params.
|
|
134
139
|
static createInvocationKey(name, ...args) {
|
|
135
140
|
return JSON.stringify({
|
|
@@ -137,13 +142,22 @@ var FunctionContext = class _FunctionContext {
|
|
|
137
142
|
...args
|
|
138
143
|
});
|
|
139
144
|
}
|
|
140
|
-
|
|
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) {
|
|
141
158
|
this._hf = _hf;
|
|
159
|
+
this._runtime = _runtime;
|
|
142
160
|
this._space = _space;
|
|
143
|
-
this._cache = /* @__PURE__ */ new Map();
|
|
144
|
-
this._pending = /* @__PURE__ */ new Map();
|
|
145
|
-
this._subscriptions = /* @__PURE__ */ new Map();
|
|
146
|
-
this._invocations = {};
|
|
147
161
|
this._options = defaultsDeep(_options ?? {}, defaultFunctionContextOptions);
|
|
148
162
|
this._onUpdate = debounce((update) => {
|
|
149
163
|
log("update", update, {
|
|
@@ -159,15 +173,15 @@ var FunctionContext = class _FunctionContext {
|
|
|
159
173
|
get space() {
|
|
160
174
|
return this._space;
|
|
161
175
|
}
|
|
162
|
-
get remoteFunctionUrl() {
|
|
163
|
-
return this._options.remoteFunctionUrl;
|
|
164
|
-
}
|
|
165
176
|
get info() {
|
|
166
177
|
return {
|
|
167
178
|
cache: this._cache.size,
|
|
168
179
|
invocations: this._invocations
|
|
169
180
|
};
|
|
170
181
|
}
|
|
182
|
+
get runtime() {
|
|
183
|
+
return this._runtime;
|
|
184
|
+
}
|
|
171
185
|
flush() {
|
|
172
186
|
this._cache.clear();
|
|
173
187
|
this._invocations = {};
|
|
@@ -263,13 +277,15 @@ var AsyncFunctionPlugin = class extends FunctionPlugin {
|
|
|
263
277
|
|
|
264
278
|
// src/functions/edge-function.ts
|
|
265
279
|
import { effect } from "@preact/signals-core";
|
|
266
|
-
import
|
|
267
|
-
import
|
|
268
|
-
import {
|
|
269
|
-
import {
|
|
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 { ComputeEventLogger, Function, FunctionInvocationService, TracingService } from "@dxos/functions";
|
|
285
|
+
import { FunctionDefinition } from "@dxos/functions";
|
|
270
286
|
import { log as log2 } from "@dxos/log";
|
|
271
287
|
import { isNonNullable } from "@dxos/util";
|
|
272
|
-
import { CellError as CellError2, ErrorType as ErrorType2, FunctionArgumentType } from "
|
|
288
|
+
import { CellError as CellError2, ErrorType as ErrorType2, FunctionArgumentType } from "@dxos/vendor-hyperformula";
|
|
273
289
|
var __dxlog_file3 = "/__w/dxos/dxos/packages/core/compute/src/functions/edge-function.ts";
|
|
274
290
|
var EDGE_FUNCTION_NAME = "DX";
|
|
275
291
|
var FUNCTION_TTL = 1e4;
|
|
@@ -280,7 +296,7 @@ var EdgeFunctionPlugin = class extends AsyncFunctionPlugin {
|
|
|
280
296
|
if (!space) {
|
|
281
297
|
return new CellError2(ErrorType2.REF, "Missing space");
|
|
282
298
|
}
|
|
283
|
-
const { objects: [fn] } = await space.db.query(Filter.type(
|
|
299
|
+
const { objects: [fn] } = await space.db.query(Filter.type(Function.Function, {
|
|
284
300
|
binding
|
|
285
301
|
})).run();
|
|
286
302
|
if (!fn) {
|
|
@@ -288,7 +304,7 @@ var EdgeFunctionPlugin = class extends AsyncFunctionPlugin {
|
|
|
288
304
|
binding
|
|
289
305
|
}, {
|
|
290
306
|
F: __dxlog_file3,
|
|
291
|
-
L:
|
|
307
|
+
L: 43,
|
|
292
308
|
S: this,
|
|
293
309
|
C: (f, a) => f(...a)
|
|
294
310
|
});
|
|
@@ -300,7 +316,7 @@ var EdgeFunctionPlugin = class extends AsyncFunctionPlugin {
|
|
|
300
316
|
fn
|
|
301
317
|
}, {
|
|
302
318
|
F: __dxlog_file3,
|
|
303
|
-
L:
|
|
319
|
+
L: 49,
|
|
304
320
|
S: this,
|
|
305
321
|
C: (f, a) => f(...a)
|
|
306
322
|
});
|
|
@@ -311,32 +327,24 @@ var EdgeFunctionPlugin = class extends AsyncFunctionPlugin {
|
|
|
311
327
|
});
|
|
312
328
|
this.context.createSubscription(ast.procedureName, unsubscribe);
|
|
313
329
|
}
|
|
314
|
-
const
|
|
330
|
+
const runtime = this.context.runtime;
|
|
331
|
+
const functionDef = FunctionDefinition.deserialize(fn);
|
|
332
|
+
let input;
|
|
315
333
|
if (fn.inputSchema) {
|
|
316
334
|
const schema = toEffectSchema(fn.inputSchema);
|
|
317
|
-
SchemaAST.getPropertySignatures(schema.ast)
|
|
318
|
-
|
|
335
|
+
const props = SchemaAST.getPropertySignatures(schema.ast);
|
|
336
|
+
input = {};
|
|
337
|
+
props.forEach(({ name }, index) => {
|
|
338
|
+
input[name.toString()] = args[index];
|
|
319
339
|
});
|
|
320
340
|
} else {
|
|
321
|
-
|
|
341
|
+
input = {
|
|
342
|
+
args: args.filter(isNonNullable)
|
|
343
|
+
};
|
|
322
344
|
}
|
|
323
|
-
const
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
headers: {
|
|
327
|
-
"Content-Type": "application/json"
|
|
328
|
-
},
|
|
329
|
-
body: JSON.stringify(body)
|
|
330
|
-
});
|
|
331
|
-
const result = await response.text();
|
|
332
|
-
log2("function executed", {
|
|
333
|
-
result
|
|
334
|
-
}, {
|
|
335
|
-
F: __dxlog_file3,
|
|
336
|
-
L: 74,
|
|
337
|
-
S: this,
|
|
338
|
-
C: (f, a) => f(...a)
|
|
339
|
-
});
|
|
345
|
+
const result = runtime.runPromise(Effect.gen(function* () {
|
|
346
|
+
return yield* FunctionInvocationService.invokeFunction(functionDef, input);
|
|
347
|
+
}).pipe(Effect.provide(ComputeEventLogger.layerFromTracing), Effect.provide(TracingService.layerNoop)));
|
|
340
348
|
return result;
|
|
341
349
|
};
|
|
342
350
|
return this.runAsyncFunction(ast, state, handler(true), {
|
|
@@ -2773,17 +2781,18 @@ var defaultFunctions = [
|
|
|
2773
2781
|
];
|
|
2774
2782
|
|
|
2775
2783
|
// src/compute-graph.ts
|
|
2784
|
+
import { effect as effect2 } from "@preact/signals-core";
|
|
2776
2785
|
import { Event as Event2 } from "@dxos/async";
|
|
2777
2786
|
import { Filter as Filter2, fullyQualifiedId } from "@dxos/client/echo";
|
|
2778
2787
|
import { FQ_ID_LENGTH } from "@dxos/client/echo";
|
|
2779
2788
|
import { Resource as Resource2 } from "@dxos/context";
|
|
2780
|
-
import { getTypename } from "@dxos/echo
|
|
2781
|
-
import {
|
|
2789
|
+
import { getTypename } from "@dxos/echo/internal";
|
|
2790
|
+
import { Function as Function2 } from "@dxos/functions";
|
|
2782
2791
|
import { invariant as invariant2 } from "@dxos/invariant";
|
|
2783
2792
|
import { PublicKey } from "@dxos/keys";
|
|
2784
2793
|
import { log as log3 } from "@dxos/log";
|
|
2785
2794
|
import { isNonNullable as isNonNullable2 } from "@dxos/util";
|
|
2786
|
-
import { ExportedCellChange as ExportedCellChange2 } from "
|
|
2795
|
+
import { ExportedCellChange as ExportedCellChange2 } from "@dxos/vendor-hyperformula";
|
|
2787
2796
|
var __dxlog_file4 = "/__w/dxos/dxos/packages/core/compute/src/compute-graph.ts";
|
|
2788
2797
|
var UNKNOWN_BINDING = "__UNKNOWN__";
|
|
2789
2798
|
var createSheetName = ({ type, id }) => `${type}@${id}`;
|
|
@@ -2797,9 +2806,21 @@ var parseSheetName = (name) => {
|
|
|
2797
2806
|
};
|
|
2798
2807
|
};
|
|
2799
2808
|
var ComputeGraph = class extends Resource2 {
|
|
2800
|
-
|
|
2801
|
-
|
|
2802
|
-
|
|
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, {
|
|
2803
2824
|
...this._options,
|
|
2804
2825
|
onUpdate: (update) => {
|
|
2805
2826
|
this._options?.onUpdate?.(update);
|
|
@@ -2855,7 +2876,7 @@ var ComputeGraph = class extends Resource2 {
|
|
|
2855
2876
|
getOrCreateNode(name) {
|
|
2856
2877
|
invariant2(name.length, void 0, {
|
|
2857
2878
|
F: __dxlog_file4,
|
|
2858
|
-
L:
|
|
2879
|
+
L: 131,
|
|
2859
2880
|
S: this,
|
|
2860
2881
|
A: [
|
|
2861
2882
|
"name.length",
|
|
@@ -2868,7 +2889,7 @@ var ComputeGraph = class extends Resource2 {
|
|
|
2868
2889
|
sheet: name
|
|
2869
2890
|
}, {
|
|
2870
2891
|
F: __dxlog_file4,
|
|
2871
|
-
L:
|
|
2892
|
+
L: 133,
|
|
2872
2893
|
S: this,
|
|
2873
2894
|
C: (f, a) => f(...a)
|
|
2874
2895
|
});
|
|
@@ -2877,7 +2898,7 @@ var ComputeGraph = class extends Resource2 {
|
|
|
2877
2898
|
const sheetId = this._hf.getSheetId(name);
|
|
2878
2899
|
invariant2(sheetId !== void 0, void 0, {
|
|
2879
2900
|
F: __dxlog_file4,
|
|
2880
|
-
L:
|
|
2901
|
+
L: 138,
|
|
2881
2902
|
S: this,
|
|
2882
2903
|
A: [
|
|
2883
2904
|
"sheetId !== undefined",
|
|
@@ -2965,14 +2986,18 @@ var ComputeGraph = class extends Resource2 {
|
|
|
2965
2986
|
}
|
|
2966
2987
|
async _open() {
|
|
2967
2988
|
if (this._space) {
|
|
2968
|
-
const query = this._space.db.query(Filter2.type(
|
|
2969
|
-
const unsubscribe = query.subscribe(
|
|
2970
|
-
|
|
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);
|
|
2971
2993
|
this.update.emit({
|
|
2972
2994
|
type: "functionsUpdated"
|
|
2973
2995
|
});
|
|
2974
2996
|
});
|
|
2975
|
-
this._ctx.onDispose(
|
|
2997
|
+
this._ctx.onDispose(() => {
|
|
2998
|
+
unsubscribe();
|
|
2999
|
+
dispose();
|
|
3000
|
+
});
|
|
2976
3001
|
}
|
|
2977
3002
|
}
|
|
2978
3003
|
async _close() {
|
|
@@ -2987,24 +3012,24 @@ import defaultsDeep2 from "lodash.defaultsdeep";
|
|
|
2987
3012
|
import { Resource as Resource3 } from "@dxos/context";
|
|
2988
3013
|
import { invariant as invariant3 } from "@dxos/invariant";
|
|
2989
3014
|
import { log as log4 } from "@dxos/log";
|
|
2990
|
-
import { HyperFormula } from "
|
|
3015
|
+
import { HyperFormula } from "@dxos/vendor-hyperformula";
|
|
2991
3016
|
var __dxlog_file5 = "/__w/dxos/dxos/packages/core/compute/src/compute-graph-registry.ts";
|
|
2992
|
-
var defaultOptions = {
|
|
2993
|
-
licenseKey: "gpl-v3"
|
|
2994
|
-
};
|
|
2995
3017
|
var defaultPlugins = [
|
|
2996
3018
|
{
|
|
2997
3019
|
plugin: EdgeFunctionPlugin,
|
|
2998
3020
|
translations: EdgeFunctionPluginTranslations
|
|
2999
3021
|
}
|
|
3000
3022
|
];
|
|
3023
|
+
var defaultOptions = {
|
|
3024
|
+
licenseKey: "gpl-v3"
|
|
3025
|
+
};
|
|
3001
3026
|
var ComputeGraphRegistry = class extends Resource3 {
|
|
3002
|
-
|
|
3003
|
-
|
|
3004
|
-
|
|
3027
|
+
_graphs = /* @__PURE__ */ new Map();
|
|
3028
|
+
_options;
|
|
3029
|
+
constructor(options) {
|
|
3005
3030
|
super();
|
|
3006
|
-
this._graphs = /* @__PURE__ */ new Map();
|
|
3007
3031
|
this._options = defaultsDeep2({}, options, defaultOptions);
|
|
3032
|
+
this._options.plugins = this._options.plugins ?? defaultPlugins;
|
|
3008
3033
|
this._options.plugins?.forEach(({ plugin, translations }) => {
|
|
3009
3034
|
HyperFormula.registerFunctionPlugin(plugin, translations);
|
|
3010
3035
|
});
|
|
@@ -3019,7 +3044,7 @@ var ComputeGraphRegistry = class extends Resource3 {
|
|
|
3019
3044
|
space: space.id
|
|
3020
3045
|
}, {
|
|
3021
3046
|
F: __dxlog_file5,
|
|
3022
|
-
L:
|
|
3047
|
+
L: 73,
|
|
3023
3048
|
S: this,
|
|
3024
3049
|
C: (f, a) => f(...a)
|
|
3025
3050
|
});
|
|
@@ -3030,7 +3055,7 @@ var ComputeGraphRegistry = class extends Resource3 {
|
|
|
3030
3055
|
createGraph(space) {
|
|
3031
3056
|
invariant3(!this._graphs.has(space.id), `ComputeGraph already exists for space: ${space.id}`, {
|
|
3032
3057
|
F: __dxlog_file5,
|
|
3033
|
-
L:
|
|
3058
|
+
L: 81,
|
|
3034
3059
|
S: this,
|
|
3035
3060
|
A: [
|
|
3036
3061
|
"!this._graphs.has(space.id)",
|
|
@@ -3038,7 +3063,17 @@ var ComputeGraphRegistry = class extends Resource3 {
|
|
|
3038
3063
|
]
|
|
3039
3064
|
});
|
|
3040
3065
|
const hf = HyperFormula.buildEmpty(this._options);
|
|
3041
|
-
|
|
3066
|
+
invariant3(this._options.computeRuntime, "ComputeRuntime is required", {
|
|
3067
|
+
F: __dxlog_file5,
|
|
3068
|
+
L: 83,
|
|
3069
|
+
S: this,
|
|
3070
|
+
A: [
|
|
3071
|
+
"this._options.computeRuntime",
|
|
3072
|
+
"'ComputeRuntime is required'"
|
|
3073
|
+
]
|
|
3074
|
+
});
|
|
3075
|
+
const runtime = this._options.computeRuntime.getRuntime(space.id);
|
|
3076
|
+
const graph = new ComputeGraph(hf, runtime, space, this._options);
|
|
3042
3077
|
this._graphs.set(space.id, graph);
|
|
3043
3078
|
return graph;
|
|
3044
3079
|
}
|
|
@@ -3073,8 +3108,8 @@ export {
|
|
|
3073
3108
|
createSheetName,
|
|
3074
3109
|
parseSheetName,
|
|
3075
3110
|
ComputeGraph,
|
|
3076
|
-
defaultOptions,
|
|
3077
3111
|
defaultPlugins,
|
|
3112
|
+
defaultOptions,
|
|
3078
3113
|
ComputeGraphRegistry
|
|
3079
3114
|
};
|
|
3080
|
-
//# sourceMappingURL=chunk-
|
|
3115
|
+
//# sourceMappingURL=chunk-BECNONV7.mjs.map
|