@dxos/compute 0.8.3 → 0.8.4-main.1da679c
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-UGMCTYCW.mjs → chunk-XQYPCRZP.mjs} +156 -94
- package/dist/lib/browser/chunk-XQYPCRZP.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 +25 -12
- package/dist/lib/browser/testing/index.mjs.map +3 -3
- package/dist/lib/node-esm/{chunk-WIABMPQE.mjs → chunk-2XWWSGAU.mjs} +156 -94
- package/dist/lib/node-esm/chunk-2XWWSGAU.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 +25 -12
- package/dist/lib/node-esm/testing/index.mjs.map +3 -3
- package/dist/types/src/compute-graph-registry.d.ts +2 -4
- package/dist/types/src/compute-graph-registry.d.ts.map +1 -1
- package/dist/types/src/compute-graph.d.ts +1 -1
- 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 +6 -6
- 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/testing/test-plugin.d.ts +4 -5
- package/dist/types/src/testing/test-plugin.d.ts.map +1 -1
- 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 +25 -35
- package/src/compute-graph-registry.ts +3 -5
- package/src/compute-graph.test.ts +2 -2
- package/src/compute-graph.ts +5 -6
- package/src/compute-node.ts +2 -4
- package/src/functions/async-function.ts +12 -8
- package/src/functions/edge-function.ts +6 -6
- package/src/hyperformula.test.ts +2 -2
- package/src/testing/test-plugin.ts +2 -4
- 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-UGMCTYCW.mjs.map +0 -7
- package/dist/lib/node/chunk-KCYHSFFU.cjs +0 -3120
- package/dist/lib/node/chunk-KCYHSFFU.cjs.map +0 -7
- package/dist/lib/node/index.cjs +0 -77
- package/dist/lib/node/index.cjs.map +0 -7
- package/dist/lib/node/meta.json +0 -1
- package/dist/lib/node/testing/index.cjs +0 -188
- package/dist/lib/node/testing/index.cjs.map +0 -7
- package/dist/lib/node-esm/chunk-WIABMPQE.mjs.map +0 -7
- package/dist/vendor/hyperformula.mjs +0 -37145
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
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 {
|
|
5
|
-
"mappings": ";;;;;;AAIA,SAASA,cAAkC;AAC3C,SAAuBC,gBAAgB;AACvC,SAASC,iBAAiB
|
|
6
|
-
"names": ["Client", "Resource", "invariant", "TestBuilder", "Resource", "
|
|
4
|
+
"sourcesContent": ["//\n// Copyright 2024 DXOS.org\n//\n\nimport { Client, type ClientOptions } from '@dxos/client';\nimport { type Context, Resource } from '@dxos/context';\nimport { invariant } from '@dxos/invariant';\n\nimport { type ComputeGraphOptions, ComputeGraphRegistry } from '../compute-graph-registry';\n\nexport type TestBuilderOptions = ClientOptions & ComputeGraphOptions;\n\n// TODO(burdon): Reconcile with @dxos/client/testing.\nexport class TestBuilder extends Resource {\n private _client?: Client;\n private _registry?: ComputeGraphRegistry;\n\n constructor(private readonly _options: TestBuilderOptions = {}) {\n super();\n }\n\n get ctx(): Context {\n return this._ctx;\n }\n\n get client(): Client {\n invariant(this._client);\n return this._client;\n }\n\n get registry(): ComputeGraphRegistry {\n invariant(this._registry);\n return this._registry;\n }\n\n override async _open(): Promise<void> {\n const client = new Client(this._options);\n await client.initialize();\n await client.halo.createIdentity();\n this._client = client;\n this._ctx.onDispose(async () => {\n await client.destroy();\n this._client = undefined;\n });\n\n const registry = new ComputeGraphRegistry(this._options);\n await registry.open();\n this._registry = registry;\n this._ctx.onDispose(async () => {\n await registry.close();\n this._registry = undefined;\n });\n }\n}\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport { getDeep } from '@dxos/util';\nimport { type InterpreterState, type ProcedureAst } from '@dxos/vendor-hyperformula';\nimport { FunctionArgumentType } from '@dxos/vendor-hyperformula';\n\nimport { type ComputeGraphPlugin } from '../compute-graph-registry';\nimport { type AsyncFunction, AsyncFunctionPlugin } from '../functions';\nimport { parseNumberString } from '../util';\n\n/**\n * Testing functions run locally (not run via EDGE).\n * https://hyperformula.handsontable.com/guide/custom-functions.html#add-a-simple-custom-function\n */\nexport class TestPlugin extends AsyncFunctionPlugin {\n /**\n * Simple local function returns input value.\n */\n test(ast: ProcedureAst, state: InterpreterState) {\n const handler: AsyncFunction = async (_value) => {\n return _value;\n };\n\n return this.runAsyncFunction(ast, state, handler);\n }\n\n /**\n * Simple local function returns random number.\n */\n random(ast: ProcedureAst, state: InterpreterState) {\n const handler: AsyncFunction = async () => {\n return Math.random();\n };\n\n return this.runAsyncFunction(ast, state, handler);\n }\n\n /**\n * Async HTTP function.\n */\n crypto(ast: ProcedureAst, state: InterpreterState) {\n const handler: AsyncFunction = async (_currency) => {\n const currency = (_currency || 'USD').toUpperCase();\n const result = await fetch(`https://api.coindesk.com/v1/bpi/currentprice/${currency}.json`);\n const data = await result.json();\n const rate = getDeep<string>(data, ['bpi', currency, 'rate']);\n if (!rate) {\n return NaN;\n }\n\n return parseNumberString(rate);\n };\n\n return this.runAsyncFunction(ast, state, handler, { ttl: 10_000 });\n }\n}\n\nTestPlugin.implementedFunctions = {\n TEST: {\n method: 'test',\n parameters: [{ argumentType: FunctionArgumentType.NUMBER, optionalArg: false }],\n isVolatile: true,\n },\n\n RANDOM: {\n method: 'random',\n parameters: [],\n isVolatile: true,\n },\n\n CRYPTO: {\n method: 'crypto',\n parameters: [{ argumentType: FunctionArgumentType.STRING, optionalArg: true }],\n isVolatile: true,\n },\n};\n\nexport const TestPluginTranslations = {\n enGB: {\n TEST: 'Returns input value',\n RANDOM: 'Random number',\n CRYPTO: 'Crypto token value',\n },\n enUS: {\n TEST: 'Returns input value',\n RANDOM: 'Random number',\n CRYPTO: 'Crypto token value',\n },\n};\n\nexport const testFunctionPlugins: ComputeGraphPlugin[] = [\n {\n plugin: TestPlugin,\n translations: TestPluginTranslations,\n },\n];\n", "//\n// Copyright 2024 DXOS.org\n//\n\n// TODO(burdon): Factor out.\nexport const parseNumberString = (str: string): number => {\n return parseFloat(str.replace(/[^\\d.]/g, ''));\n};\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport { HyperFormula } from '@dxos/vendor-hyperformula';\n\nexport const getRegisteredFunctionNames = () => {\n return HyperFormula.buildEmpty({ licenseKey: 'gpl-v3' }).getRegisteredFunctionNames();\n};\n"],
|
|
5
|
+
"mappings": "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",
|
|
6
|
+
"names": ["Client", "Resource", "invariant", "TestBuilder", "Resource", "ctx", "_ctx", "client", "invariant", "_client", "registry", "_registry", "_open", "Client", "_options", "initialize", "halo", "createIdentity", "onDispose", "destroy", "undefined", "ComputeGraphRegistry", "open", "close", "getDeep", "FunctionArgumentType", "parseNumberString", "str", "parseFloat", "replace", "TestPlugin", "AsyncFunctionPlugin", "test", "ast", "state", "handler", "_value", "runAsyncFunction", "random", "Math", "crypto", "_currency", "currency", "toUpperCase", "result", "fetch", "data", "json", "rate", "getDeep", "NaN", "parseNumberString", "ttl", "implementedFunctions", "TEST", "method", "parameters", "argumentType", "FunctionArgumentType", "NUMBER", "optionalArg", "isVolatile", "RANDOM", "CRYPTO", "STRING", "TestPluginTranslations", "enGB", "enUS", "testFunctionPlugins", "plugin", "translations", "HyperFormula", "getRegisteredFunctionNames", "HyperFormula", "buildEmpty", "licenseKey"]
|
|
7
7
|
}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { createRequire } from 'node:module';const require = createRequire(import.meta.url);
|
|
2
2
|
|
|
3
|
-
//
|
|
4
|
-
import { DetailedCellError, ExportedCellChange } from "
|
|
3
|
+
// src/types/hyperformula.ts
|
|
4
|
+
import { DetailedCellError, ExportedCellChange } from "@dxos/vendor-hyperformula";
|
|
5
5
|
|
|
6
|
-
//
|
|
6
|
+
// src/types/types.ts
|
|
7
7
|
import { invariant } from "@dxos/invariant";
|
|
8
|
-
var __dxlog_file = "/
|
|
8
|
+
var __dxlog_file = "/__w/dxos/dxos/packages/core/compute/src/types/types.ts";
|
|
9
9
|
var RANGE_NOTATION = /^[A-Z]+[0-9]+(:[A-Z]+[0-9]+)?$/;
|
|
10
10
|
var isFormula = (value) => typeof value === "string" && value.charAt(0) === "=";
|
|
11
11
|
var cellEquals = (a, b) => {
|
|
@@ -76,14 +76,24 @@ var inRange = (range, cell) => {
|
|
|
76
76
|
return col >= cMin && col <= cMax && row >= rMin && row <= rMax;
|
|
77
77
|
};
|
|
78
78
|
|
|
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 "
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
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;
|
|
86
93
|
}
|
|
94
|
+
return obj;
|
|
95
|
+
}
|
|
96
|
+
var ComputeNode = class extends Resource {
|
|
87
97
|
get graph() {
|
|
88
98
|
return this._graph;
|
|
89
99
|
}
|
|
@@ -116,14 +126,30 @@ var ComputeNode = class extends Resource {
|
|
|
116
126
|
// TODO(burdon): Load data into sheet.
|
|
117
127
|
async _open() {
|
|
118
128
|
}
|
|
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
|
+
}
|
|
119
132
|
};
|
|
120
133
|
|
|
121
|
-
//
|
|
134
|
+
// src/functions/async-function.ts
|
|
122
135
|
import defaultsDeep from "lodash.defaultsdeep";
|
|
123
136
|
import { debounce } from "@dxos/async";
|
|
124
137
|
import { log } from "@dxos/log";
|
|
125
|
-
import { CellError,
|
|
126
|
-
|
|
138
|
+
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
|
+
var __dxlog_file2 = "/__w/dxos/dxos/packages/core/compute/src/functions/async-function.ts";
|
|
127
153
|
var defaultFunctionContextOptions = {
|
|
128
154
|
defaultTtl: 5e3,
|
|
129
155
|
debounceDelay: 200,
|
|
@@ -137,25 +163,6 @@ var FunctionContext = class _FunctionContext {
|
|
|
137
163
|
...args
|
|
138
164
|
});
|
|
139
165
|
}
|
|
140
|
-
constructor(_hf, _space, _options) {
|
|
141
|
-
this._hf = _hf;
|
|
142
|
-
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
|
-
this._options = defaultsDeep(_options ?? {}, defaultFunctionContextOptions);
|
|
148
|
-
this._onUpdate = debounce((update) => {
|
|
149
|
-
log("update", update, {
|
|
150
|
-
F: __dxlog_file2,
|
|
151
|
-
L: 86,
|
|
152
|
-
S: this,
|
|
153
|
-
C: (f, a) => f(...a)
|
|
154
|
-
});
|
|
155
|
-
this._hf.resumeEvaluation();
|
|
156
|
-
this._options.onUpdate?.(update);
|
|
157
|
-
}, this._options.debounceDelay);
|
|
158
|
-
}
|
|
159
166
|
get space() {
|
|
160
167
|
return this._space;
|
|
161
168
|
}
|
|
@@ -204,7 +211,7 @@ var FunctionContext = class _FunctionContext {
|
|
|
204
211
|
value: value2
|
|
205
212
|
}, {
|
|
206
213
|
F: __dxlog_file2,
|
|
207
|
-
L:
|
|
214
|
+
L: 143,
|
|
208
215
|
S: this,
|
|
209
216
|
C: (f, a) => f(...a)
|
|
210
217
|
});
|
|
@@ -218,7 +225,7 @@ var FunctionContext = class _FunctionContext {
|
|
|
218
225
|
err
|
|
219
226
|
}, {
|
|
220
227
|
F: __dxlog_file2,
|
|
221
|
-
L:
|
|
228
|
+
L: 147,
|
|
222
229
|
S: this,
|
|
223
230
|
C: (f, a) => f(...a)
|
|
224
231
|
});
|
|
@@ -238,12 +245,39 @@ var FunctionContext = class _FunctionContext {
|
|
|
238
245
|
cache: value
|
|
239
246
|
}, {
|
|
240
247
|
F: __dxlog_file2,
|
|
241
|
-
L:
|
|
248
|
+
L: 155,
|
|
242
249
|
S: this,
|
|
243
250
|
C: (f, a) => f(...a)
|
|
244
251
|
});
|
|
245
252
|
return value;
|
|
246
253
|
}
|
|
254
|
+
constructor(_hf, _space, _options) {
|
|
255
|
+
_define_property2(this, "_hf", void 0);
|
|
256
|
+
_define_property2(this, "_space", void 0);
|
|
257
|
+
_define_property2(this, "_cache", void 0);
|
|
258
|
+
_define_property2(this, "_pending", void 0);
|
|
259
|
+
_define_property2(this, "_subscriptions", void 0);
|
|
260
|
+
_define_property2(this, "_invocations", void 0);
|
|
261
|
+
_define_property2(this, "_options", void 0);
|
|
262
|
+
_define_property2(this, "_onUpdate", void 0);
|
|
263
|
+
this._hf = _hf;
|
|
264
|
+
this._space = _space;
|
|
265
|
+
this._cache = /* @__PURE__ */ new Map();
|
|
266
|
+
this._pending = /* @__PURE__ */ new Map();
|
|
267
|
+
this._subscriptions = /* @__PURE__ */ new Map();
|
|
268
|
+
this._invocations = {};
|
|
269
|
+
this._options = defaultsDeep(_options ?? {}, defaultFunctionContextOptions);
|
|
270
|
+
this._onUpdate = debounce((update) => {
|
|
271
|
+
log("update", update, {
|
|
272
|
+
F: __dxlog_file2,
|
|
273
|
+
L: 85,
|
|
274
|
+
S: this,
|
|
275
|
+
C: (f, a) => f(...a)
|
|
276
|
+
});
|
|
277
|
+
this._hf.resumeEvaluation();
|
|
278
|
+
this._options.onUpdate?.(update);
|
|
279
|
+
}, this._options.debounceDelay);
|
|
280
|
+
}
|
|
247
281
|
};
|
|
248
282
|
var AsyncFunctionPlugin = class extends FunctionPlugin {
|
|
249
283
|
get context() {
|
|
@@ -261,16 +295,16 @@ var AsyncFunctionPlugin = class extends FunctionPlugin {
|
|
|
261
295
|
}
|
|
262
296
|
};
|
|
263
297
|
|
|
264
|
-
//
|
|
298
|
+
// src/functions/edge-function.ts
|
|
265
299
|
import { effect } from "@preact/signals-core";
|
|
266
300
|
import { SchemaAST } from "effect";
|
|
267
301
|
import { Filter, getMeta } from "@dxos/client/echo";
|
|
268
302
|
import { toEffectSchema } from "@dxos/echo-schema";
|
|
269
|
-
import { FunctionType,
|
|
303
|
+
import { FunctionType, getUserFunctionIdInMetadata } from "@dxos/functions";
|
|
270
304
|
import { log as log2 } from "@dxos/log";
|
|
271
305
|
import { isNonNullable } from "@dxos/util";
|
|
272
|
-
import { CellError as CellError2, ErrorType as ErrorType2, FunctionArgumentType } from "
|
|
273
|
-
var __dxlog_file3 = "/
|
|
306
|
+
import { CellError as CellError2, ErrorType as ErrorType2, FunctionArgumentType } from "@dxos/vendor-hyperformula";
|
|
307
|
+
var __dxlog_file3 = "/__w/dxos/dxos/packages/core/compute/src/functions/edge-function.ts";
|
|
274
308
|
var EDGE_FUNCTION_NAME = "DX";
|
|
275
309
|
var FUNCTION_TTL = 1e4;
|
|
276
310
|
var EdgeFunctionPlugin = class extends AsyncFunctionPlugin {
|
|
@@ -320,8 +354,8 @@ var EdgeFunctionPlugin = class extends AsyncFunctionPlugin {
|
|
|
320
354
|
} else {
|
|
321
355
|
body.args = args.filter(isNonNullable);
|
|
322
356
|
}
|
|
323
|
-
const
|
|
324
|
-
const response = await fetch(`${this.context.remoteFunctionUrl}
|
|
357
|
+
const id = getUserFunctionIdInMetadata(getMeta(fn));
|
|
358
|
+
const response = await fetch(`${this.context.remoteFunctionUrl}/${id}`, {
|
|
325
359
|
method: "POST",
|
|
326
360
|
headers: {
|
|
327
361
|
"Content-Type": "application/json"
|
|
@@ -398,7 +432,7 @@ var EdgeFunctionPluginTranslations = {
|
|
|
398
432
|
}
|
|
399
433
|
};
|
|
400
434
|
|
|
401
|
-
//
|
|
435
|
+
// src/functions/function-defs.ts
|
|
402
436
|
var defaultFunctions = [
|
|
403
437
|
// Array
|
|
404
438
|
{
|
|
@@ -2772,7 +2806,7 @@ var defaultFunctions = [
|
|
|
2772
2806
|
}
|
|
2773
2807
|
];
|
|
2774
2808
|
|
|
2775
|
-
//
|
|
2809
|
+
// src/compute-graph.ts
|
|
2776
2810
|
import { Event as Event2 } from "@dxos/async";
|
|
2777
2811
|
import { Filter as Filter2, fullyQualifiedId } from "@dxos/client/echo";
|
|
2778
2812
|
import { FQ_ID_LENGTH } from "@dxos/client/echo";
|
|
@@ -2783,8 +2817,21 @@ import { invariant as invariant2 } from "@dxos/invariant";
|
|
|
2783
2817
|
import { PublicKey } from "@dxos/keys";
|
|
2784
2818
|
import { log as log3 } from "@dxos/log";
|
|
2785
2819
|
import { isNonNullable as isNonNullable2 } from "@dxos/util";
|
|
2786
|
-
import { ExportedCellChange as ExportedCellChange2 } from "
|
|
2787
|
-
|
|
2820
|
+
import { ExportedCellChange as ExportedCellChange2 } from "@dxos/vendor-hyperformula";
|
|
2821
|
+
function _define_property3(obj, key, value) {
|
|
2822
|
+
if (key in obj) {
|
|
2823
|
+
Object.defineProperty(obj, key, {
|
|
2824
|
+
value,
|
|
2825
|
+
enumerable: true,
|
|
2826
|
+
configurable: true,
|
|
2827
|
+
writable: true
|
|
2828
|
+
});
|
|
2829
|
+
} else {
|
|
2830
|
+
obj[key] = value;
|
|
2831
|
+
}
|
|
2832
|
+
return obj;
|
|
2833
|
+
}
|
|
2834
|
+
var __dxlog_file4 = "/__w/dxos/dxos/packages/core/compute/src/compute-graph.ts";
|
|
2788
2835
|
var UNKNOWN_BINDING = "__UNKNOWN__";
|
|
2789
2836
|
var createSheetName = ({ type, id }) => `${type}@${id}`;
|
|
2790
2837
|
var parseSheetName = (name) => {
|
|
@@ -2797,37 +2844,6 @@ var parseSheetName = (name) => {
|
|
|
2797
2844
|
};
|
|
2798
2845
|
};
|
|
2799
2846
|
var ComputeGraph = class extends Resource2 {
|
|
2800
|
-
constructor(_hf, _space, _options) {
|
|
2801
|
-
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();
|
|
2802
|
-
this.context = new FunctionContext(this._hf, this._space, {
|
|
2803
|
-
...this._options,
|
|
2804
|
-
onUpdate: (update) => {
|
|
2805
|
-
this._options?.onUpdate?.(update);
|
|
2806
|
-
this.update.emit({
|
|
2807
|
-
type: "valuesUpdated"
|
|
2808
|
-
});
|
|
2809
|
-
}
|
|
2810
|
-
});
|
|
2811
|
-
this._hf.updateConfig({
|
|
2812
|
-
context: this.context
|
|
2813
|
-
});
|
|
2814
|
-
const onValuesUpdate = (changes) => {
|
|
2815
|
-
for (const change of changes) {
|
|
2816
|
-
if (change instanceof ExportedCellChange2) {
|
|
2817
|
-
const { sheet } = change;
|
|
2818
|
-
const node = this._nodes.get(sheet);
|
|
2819
|
-
if (node) {
|
|
2820
|
-
node.update.emit({
|
|
2821
|
-
type: "valuesUpdated",
|
|
2822
|
-
change
|
|
2823
|
-
});
|
|
2824
|
-
}
|
|
2825
|
-
}
|
|
2826
|
-
}
|
|
2827
|
-
};
|
|
2828
|
-
this._hf.on("valuesUpdated", onValuesUpdate);
|
|
2829
|
-
this._ctx.onDispose(() => this._hf.off("valuesUpdated", onValuesUpdate));
|
|
2830
|
-
}
|
|
2831
2847
|
get hf() {
|
|
2832
2848
|
return this._hf;
|
|
2833
2849
|
}
|
|
@@ -2855,7 +2871,7 @@ var ComputeGraph = class extends Resource2 {
|
|
|
2855
2871
|
getOrCreateNode(name) {
|
|
2856
2872
|
invariant2(name.length, void 0, {
|
|
2857
2873
|
F: __dxlog_file4,
|
|
2858
|
-
L:
|
|
2874
|
+
L: 127,
|
|
2859
2875
|
S: this,
|
|
2860
2876
|
A: [
|
|
2861
2877
|
"name.length",
|
|
@@ -2868,7 +2884,7 @@ var ComputeGraph = class extends Resource2 {
|
|
|
2868
2884
|
sheet: name
|
|
2869
2885
|
}, {
|
|
2870
2886
|
F: __dxlog_file4,
|
|
2871
|
-
L:
|
|
2887
|
+
L: 129,
|
|
2872
2888
|
S: this,
|
|
2873
2889
|
C: (f, a) => f(...a)
|
|
2874
2890
|
});
|
|
@@ -2877,7 +2893,7 @@ var ComputeGraph = class extends Resource2 {
|
|
|
2877
2893
|
const sheetId = this._hf.getSheetId(name);
|
|
2878
2894
|
invariant2(sheetId !== void 0, void 0, {
|
|
2879
2895
|
F: __dxlog_file4,
|
|
2880
|
-
L:
|
|
2896
|
+
L: 134,
|
|
2881
2897
|
S: this,
|
|
2882
2898
|
A: [
|
|
2883
2899
|
"sheetId !== undefined",
|
|
@@ -2980,15 +2996,62 @@ var ComputeGraph = class extends Resource2 {
|
|
|
2980
2996
|
await node.close();
|
|
2981
2997
|
}
|
|
2982
2998
|
}
|
|
2999
|
+
constructor(_hf, _space, _options) {
|
|
3000
|
+
super(), _define_property3(this, "_hf", void 0), _define_property3(this, "_space", void 0), _define_property3(this, "_options", void 0), _define_property3(this, "id", void 0), // Map of nodes indexed by sheet number.
|
|
3001
|
+
_define_property3(this, "_nodes", void 0), // Cached function objects.
|
|
3002
|
+
_define_property3(this, "_remoteFunctions", void 0), _define_property3(this, "update", void 0), // The context is passed to all functions.
|
|
3003
|
+
_define_property3(this, "context", void 0), this._hf = _hf, this._space = _space, this._options = _options, this.id = `graph-${PublicKey.random().truncate()}`, this._nodes = /* @__PURE__ */ new Map(), this._remoteFunctions = [], this.update = new Event2();
|
|
3004
|
+
this.context = new FunctionContext(this._hf, this._space, {
|
|
3005
|
+
...this._options,
|
|
3006
|
+
onUpdate: (update) => {
|
|
3007
|
+
this._options?.onUpdate?.(update);
|
|
3008
|
+
this.update.emit({
|
|
3009
|
+
type: "valuesUpdated"
|
|
3010
|
+
});
|
|
3011
|
+
}
|
|
3012
|
+
});
|
|
3013
|
+
this._hf.updateConfig({
|
|
3014
|
+
context: this.context
|
|
3015
|
+
});
|
|
3016
|
+
const onValuesUpdate = (changes) => {
|
|
3017
|
+
for (const change of changes) {
|
|
3018
|
+
if (change instanceof ExportedCellChange2) {
|
|
3019
|
+
const { sheet } = change;
|
|
3020
|
+
const node = this._nodes.get(sheet);
|
|
3021
|
+
if (node) {
|
|
3022
|
+
node.update.emit({
|
|
3023
|
+
type: "valuesUpdated",
|
|
3024
|
+
change
|
|
3025
|
+
});
|
|
3026
|
+
}
|
|
3027
|
+
}
|
|
3028
|
+
}
|
|
3029
|
+
};
|
|
3030
|
+
this._hf.on("valuesUpdated", onValuesUpdate);
|
|
3031
|
+
this._ctx.onDispose(() => this._hf.off("valuesUpdated", onValuesUpdate));
|
|
3032
|
+
}
|
|
2983
3033
|
};
|
|
2984
3034
|
|
|
2985
|
-
//
|
|
3035
|
+
// src/compute-graph-registry.ts
|
|
2986
3036
|
import defaultsDeep2 from "lodash.defaultsdeep";
|
|
2987
3037
|
import { Resource as Resource3 } from "@dxos/context";
|
|
2988
3038
|
import { invariant as invariant3 } from "@dxos/invariant";
|
|
2989
3039
|
import { log as log4 } from "@dxos/log";
|
|
2990
|
-
import { HyperFormula } from "
|
|
2991
|
-
|
|
3040
|
+
import { HyperFormula } from "@dxos/vendor-hyperformula";
|
|
3041
|
+
function _define_property4(obj, key, value) {
|
|
3042
|
+
if (key in obj) {
|
|
3043
|
+
Object.defineProperty(obj, key, {
|
|
3044
|
+
value,
|
|
3045
|
+
enumerable: true,
|
|
3046
|
+
configurable: true,
|
|
3047
|
+
writable: true
|
|
3048
|
+
});
|
|
3049
|
+
} else {
|
|
3050
|
+
obj[key] = value;
|
|
3051
|
+
}
|
|
3052
|
+
return obj;
|
|
3053
|
+
}
|
|
3054
|
+
var __dxlog_file5 = "/__w/dxos/dxos/packages/core/compute/src/compute-graph-registry.ts";
|
|
2992
3055
|
var defaultOptions = {
|
|
2993
3056
|
licenseKey: "gpl-v3"
|
|
2994
3057
|
};
|
|
@@ -2999,16 +3062,6 @@ var defaultPlugins = [
|
|
|
2999
3062
|
}
|
|
3000
3063
|
];
|
|
3001
3064
|
var ComputeGraphRegistry = class extends Resource3 {
|
|
3002
|
-
constructor(options = {
|
|
3003
|
-
plugins: defaultPlugins
|
|
3004
|
-
}) {
|
|
3005
|
-
super();
|
|
3006
|
-
this._graphs = /* @__PURE__ */ new Map();
|
|
3007
|
-
this._options = defaultsDeep2({}, options, defaultOptions);
|
|
3008
|
-
this._options.plugins?.forEach(({ plugin, translations }) => {
|
|
3009
|
-
HyperFormula.registerFunctionPlugin(plugin, translations);
|
|
3010
|
-
});
|
|
3011
|
-
}
|
|
3012
3065
|
getGraph(spaceId) {
|
|
3013
3066
|
return this._graphs.get(spaceId);
|
|
3014
3067
|
}
|
|
@@ -3019,7 +3072,7 @@ var ComputeGraphRegistry = class extends Resource3 {
|
|
|
3019
3072
|
space: space.id
|
|
3020
3073
|
}, {
|
|
3021
3074
|
F: __dxlog_file5,
|
|
3022
|
-
L:
|
|
3075
|
+
L: 67,
|
|
3023
3076
|
S: this,
|
|
3024
3077
|
C: (f, a) => f(...a)
|
|
3025
3078
|
});
|
|
@@ -3030,7 +3083,7 @@ var ComputeGraphRegistry = class extends Resource3 {
|
|
|
3030
3083
|
createGraph(space) {
|
|
3031
3084
|
invariant3(!this._graphs.has(space.id), `ComputeGraph already exists for space: ${space.id}`, {
|
|
3032
3085
|
F: __dxlog_file5,
|
|
3033
|
-
L:
|
|
3086
|
+
L: 75,
|
|
3034
3087
|
S: this,
|
|
3035
3088
|
A: [
|
|
3036
3089
|
"!this._graphs.has(space.id)",
|
|
@@ -3048,6 +3101,15 @@ var ComputeGraphRegistry = class extends Resource3 {
|
|
|
3048
3101
|
}
|
|
3049
3102
|
this._graphs.clear();
|
|
3050
3103
|
}
|
|
3104
|
+
constructor(options = {
|
|
3105
|
+
plugins: defaultPlugins
|
|
3106
|
+
}) {
|
|
3107
|
+
super(), _define_property4(this, "_graphs", /* @__PURE__ */ new Map()), _define_property4(this, "_options", void 0);
|
|
3108
|
+
this._options = defaultsDeep2({}, options, defaultOptions);
|
|
3109
|
+
this._options.plugins?.forEach(({ plugin, translations }) => {
|
|
3110
|
+
HyperFormula.registerFunctionPlugin(plugin, translations);
|
|
3111
|
+
});
|
|
3112
|
+
}
|
|
3051
3113
|
};
|
|
3052
3114
|
|
|
3053
3115
|
export {
|
|
@@ -3077,4 +3139,4 @@ export {
|
|
|
3077
3139
|
defaultPlugins,
|
|
3078
3140
|
ComputeGraphRegistry
|
|
3079
3141
|
};
|
|
3080
|
-
//# sourceMappingURL=chunk-
|
|
3142
|
+
//# sourceMappingURL=chunk-2XWWSGAU.mjs.map
|