@dxos/compute 0.8.4-main.5ea62a8 → 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.
- package/dist/lib/browser/{chunk-OFPP3ZEX.mjs → chunk-ILJV45WQ.mjs} +159 -186
- package/dist/lib/browser/{chunk-OFPP3ZEX.mjs.map → chunk-ILJV45WQ.mjs.map} +3 -3
- package/dist/lib/browser/index.mjs +1 -1
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/testing/index.mjs +33 -22
- package/dist/lib/browser/testing/index.mjs.map +4 -4
- package/dist/lib/node-esm/{chunk-6GVHPKPB.mjs → chunk-QDJ6J7GT.mjs} +159 -186
- package/dist/lib/node-esm/{chunk-6GVHPKPB.mjs.map → chunk-QDJ6J7GT.mjs.map} +3 -3
- 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 +33 -22
- package/dist/lib/node-esm/testing/index.mjs.map +4 -4
- package/dist/types/src/compute-graph-registry.d.ts +9 -6
- 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 +23 -29
- package/src/compute-graph-registry.test.ts +154 -0
- package/src/compute-graph-registry.ts +19 -13
- package/src/compute-graph.test.ts +31 -13
- package/src/compute-graph.ts +25 -16
- package/src/compute-node.ts +2 -5
- package/src/functions/async-function.ts +20 -15
- package/src/functions/edge-function.ts +26 -24
- package/src/hyperformula.test.ts +1 -1
- 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 -5
- package/src/testing/test-runtime.ts +33 -0
- package/src/testing/util.ts +1 -1
- package/src/types/hyperformula.ts +8 -8
- package/dist/vendor/hyperformula.mjs +0 -36400
|
@@ -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,21 +79,14 @@ 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 "
|
|
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
|
-
}
|
|
82
|
+
import { DetailedCellError as DetailedCellError2 } from "@dxos/vendor-hyperformula";
|
|
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,36 +119,22 @@ 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
|
|
135
125
|
import defaultsDeep from "lodash.defaultsdeep";
|
|
136
126
|
import { debounce } from "@dxos/async";
|
|
137
127
|
import { log } from "@dxos/log";
|
|
138
|
-
import { CellError, EmptyValue, ErrorType, FunctionPlugin } from "
|
|
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
|
-
}
|
|
128
|
+
import { CellError, EmptyValue, ErrorType, FunctionPlugin } from "@dxos/vendor-hyperformula";
|
|
152
129
|
var __dxlog_file2 = "/__w/dxos/dxos/packages/core/compute/src/functions/async-function.ts";
|
|
153
130
|
var defaultFunctionContextOptions = {
|
|
154
131
|
defaultTtl: 5e3,
|
|
155
|
-
debounceDelay: 200
|
|
156
|
-
remoteFunctionUrl: "https://edge.dxos.workers.dev/functions"
|
|
132
|
+
debounceDelay: 200
|
|
157
133
|
};
|
|
158
134
|
var FunctionContext = class _FunctionContext {
|
|
135
|
+
_hf;
|
|
136
|
+
_runtime;
|
|
137
|
+
_space;
|
|
159
138
|
// Mangle name with params.
|
|
160
139
|
static createInvocationKey(name, ...args) {
|
|
161
140
|
return JSON.stringify({
|
|
@@ -163,18 +142,46 @@ var FunctionContext = class _FunctionContext {
|
|
|
163
142
|
...args
|
|
164
143
|
});
|
|
165
144
|
}
|
|
145
|
+
// TODO(wittjosiah): Persist cached values.
|
|
146
|
+
// Cached values for cell.
|
|
147
|
+
_cache = /* @__PURE__ */ new Map();
|
|
148
|
+
// Active requests.
|
|
149
|
+
_pending = /* @__PURE__ */ new Map();
|
|
150
|
+
// Query subscriptions.
|
|
151
|
+
_subscriptions = /* @__PURE__ */ new Map();
|
|
152
|
+
// Invocation count.
|
|
153
|
+
_invocations = {};
|
|
154
|
+
_options;
|
|
155
|
+
// Debounced update handler.
|
|
156
|
+
_onUpdate;
|
|
157
|
+
constructor(_hf, _runtime, _space, _options) {
|
|
158
|
+
this._hf = _hf;
|
|
159
|
+
this._runtime = _runtime;
|
|
160
|
+
this._space = _space;
|
|
161
|
+
this._options = defaultsDeep(_options ?? {}, defaultFunctionContextOptions);
|
|
162
|
+
this._onUpdate = debounce((update) => {
|
|
163
|
+
log("update", update, {
|
|
164
|
+
F: __dxlog_file2,
|
|
165
|
+
L: 86,
|
|
166
|
+
S: this,
|
|
167
|
+
C: (f, a) => f(...a)
|
|
168
|
+
});
|
|
169
|
+
this._hf.resumeEvaluation();
|
|
170
|
+
this._options.onUpdate?.(update);
|
|
171
|
+
}, this._options.debounceDelay);
|
|
172
|
+
}
|
|
166
173
|
get space() {
|
|
167
174
|
return this._space;
|
|
168
175
|
}
|
|
169
|
-
get remoteFunctionUrl() {
|
|
170
|
-
return this._options.remoteFunctionUrl;
|
|
171
|
-
}
|
|
172
176
|
get info() {
|
|
173
177
|
return {
|
|
174
178
|
cache: this._cache.size,
|
|
175
179
|
invocations: this._invocations
|
|
176
180
|
};
|
|
177
181
|
}
|
|
182
|
+
get runtime() {
|
|
183
|
+
return this._runtime;
|
|
184
|
+
}
|
|
178
185
|
flush() {
|
|
179
186
|
this._cache.clear();
|
|
180
187
|
this._invocations = {};
|
|
@@ -251,33 +258,6 @@ var FunctionContext = class _FunctionContext {
|
|
|
251
258
|
});
|
|
252
259
|
return value;
|
|
253
260
|
}
|
|
254
|
-
constructor(_hf, _space, _options) {
|
|
255
|
-
_define_property2(this, "_hf", void 0);
|
|
256
|
-
_define_property2(this, "_space", void 0);
|
|
257
|
-
_define_property2(this, "_cache", void 0);
|
|
258
|
-
_define_property2(this, "_pending", void 0);
|
|
259
|
-
_define_property2(this, "_subscriptions", void 0);
|
|
260
|
-
_define_property2(this, "_invocations", void 0);
|
|
261
|
-
_define_property2(this, "_options", void 0);
|
|
262
|
-
_define_property2(this, "_onUpdate", void 0);
|
|
263
|
-
this._hf = _hf;
|
|
264
|
-
this._space = _space;
|
|
265
|
-
this._cache = /* @__PURE__ */ new Map();
|
|
266
|
-
this._pending = /* @__PURE__ */ new Map();
|
|
267
|
-
this._subscriptions = /* @__PURE__ */ new Map();
|
|
268
|
-
this._invocations = {};
|
|
269
|
-
this._options = defaultsDeep(_options ?? {}, defaultFunctionContextOptions);
|
|
270
|
-
this._onUpdate = debounce((update) => {
|
|
271
|
-
log("update", update, {
|
|
272
|
-
F: __dxlog_file2,
|
|
273
|
-
L: 86,
|
|
274
|
-
S: this,
|
|
275
|
-
C: (f, a) => f(...a)
|
|
276
|
-
});
|
|
277
|
-
this._hf.resumeEvaluation();
|
|
278
|
-
this._options.onUpdate?.(update);
|
|
279
|
-
}, this._options.debounceDelay);
|
|
280
|
-
}
|
|
281
261
|
};
|
|
282
262
|
var AsyncFunctionPlugin = class extends FunctionPlugin {
|
|
283
263
|
get context() {
|
|
@@ -297,13 +277,15 @@ var AsyncFunctionPlugin = class extends FunctionPlugin {
|
|
|
297
277
|
|
|
298
278
|
// src/functions/edge-function.ts
|
|
299
279
|
import { effect } from "@preact/signals-core";
|
|
300
|
-
import
|
|
301
|
-
import
|
|
302
|
-
import {
|
|
303
|
-
import {
|
|
280
|
+
import * as Effect from "effect/Effect";
|
|
281
|
+
import * as SchemaAST from "effect/SchemaAST";
|
|
282
|
+
import { Filter } from "@dxos/client/echo";
|
|
283
|
+
import { JsonSchema } from "@dxos/echo";
|
|
284
|
+
import { Function, FunctionInvocationService, TracingService } from "@dxos/functions";
|
|
285
|
+
import { FunctionDefinition } from "@dxos/functions";
|
|
304
286
|
import { log as log2 } from "@dxos/log";
|
|
305
287
|
import { isNonNullable } from "@dxos/util";
|
|
306
|
-
import { CellError as CellError2, ErrorType as ErrorType2, FunctionArgumentType } from "
|
|
288
|
+
import { CellError as CellError2, ErrorType as ErrorType2, FunctionArgumentType } from "@dxos/vendor-hyperformula";
|
|
307
289
|
var __dxlog_file3 = "/__w/dxos/dxos/packages/core/compute/src/functions/edge-function.ts";
|
|
308
290
|
var EDGE_FUNCTION_NAME = "DX";
|
|
309
291
|
var FUNCTION_TTL = 1e4;
|
|
@@ -314,7 +296,7 @@ var EdgeFunctionPlugin = class extends AsyncFunctionPlugin {
|
|
|
314
296
|
if (!space) {
|
|
315
297
|
return new CellError2(ErrorType2.REF, "Missing space");
|
|
316
298
|
}
|
|
317
|
-
const { objects: [fn] } = await space.db.query(Filter.type(
|
|
299
|
+
const { objects: [fn] } = await space.db.query(Filter.type(Function.Function, {
|
|
318
300
|
binding
|
|
319
301
|
})).run();
|
|
320
302
|
if (!fn) {
|
|
@@ -322,7 +304,7 @@ var EdgeFunctionPlugin = class extends AsyncFunctionPlugin {
|
|
|
322
304
|
binding
|
|
323
305
|
}, {
|
|
324
306
|
F: __dxlog_file3,
|
|
325
|
-
L:
|
|
307
|
+
L: 43,
|
|
326
308
|
S: this,
|
|
327
309
|
C: (f, a) => f(...a)
|
|
328
310
|
});
|
|
@@ -334,7 +316,7 @@ var EdgeFunctionPlugin = class extends AsyncFunctionPlugin {
|
|
|
334
316
|
fn
|
|
335
317
|
}, {
|
|
336
318
|
F: __dxlog_file3,
|
|
337
|
-
L:
|
|
319
|
+
L: 49,
|
|
338
320
|
S: this,
|
|
339
321
|
C: (f, a) => f(...a)
|
|
340
322
|
});
|
|
@@ -345,32 +327,24 @@ var EdgeFunctionPlugin = class extends AsyncFunctionPlugin {
|
|
|
345
327
|
});
|
|
346
328
|
this.context.createSubscription(ast.procedureName, unsubscribe);
|
|
347
329
|
}
|
|
348
|
-
const
|
|
330
|
+
const runtime = this.context.runtime;
|
|
331
|
+
const functionDef = FunctionDefinition.deserialize(fn);
|
|
332
|
+
let input;
|
|
349
333
|
if (fn.inputSchema) {
|
|
350
|
-
const schema = toEffectSchema(fn.inputSchema);
|
|
351
|
-
SchemaAST.getPropertySignatures(schema.ast)
|
|
352
|
-
|
|
334
|
+
const schema = JsonSchema.toEffectSchema(fn.inputSchema);
|
|
335
|
+
const props = SchemaAST.getPropertySignatures(schema.ast);
|
|
336
|
+
input = {};
|
|
337
|
+
props.forEach(({ name }, index) => {
|
|
338
|
+
input[name.toString()] = args[index];
|
|
353
339
|
});
|
|
354
340
|
} else {
|
|
355
|
-
|
|
341
|
+
input = {
|
|
342
|
+
args: args.filter(isNonNullable)
|
|
343
|
+
};
|
|
356
344
|
}
|
|
357
|
-
const
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
headers: {
|
|
361
|
-
"Content-Type": "application/json"
|
|
362
|
-
},
|
|
363
|
-
body: JSON.stringify(body)
|
|
364
|
-
});
|
|
365
|
-
const result = await response.text();
|
|
366
|
-
log2("function executed", {
|
|
367
|
-
result
|
|
368
|
-
}, {
|
|
369
|
-
F: __dxlog_file3,
|
|
370
|
-
L: 75,
|
|
371
|
-
S: this,
|
|
372
|
-
C: (f, a) => f(...a)
|
|
373
|
-
});
|
|
345
|
+
const result = runtime.runPromise(Effect.gen(function* () {
|
|
346
|
+
return yield* FunctionInvocationService.invokeFunction(functionDef, input);
|
|
347
|
+
}).pipe(Effect.provide(TracingService.layerNoop)));
|
|
374
348
|
return result;
|
|
375
349
|
};
|
|
376
350
|
return this.runAsyncFunction(ast, state, handler(true), {
|
|
@@ -2807,30 +2781,18 @@ var defaultFunctions = [
|
|
|
2807
2781
|
];
|
|
2808
2782
|
|
|
2809
2783
|
// src/compute-graph.ts
|
|
2784
|
+
import { effect as effect2 } from "@preact/signals-core";
|
|
2810
2785
|
import { Event as Event2 } from "@dxos/async";
|
|
2811
|
-
import { Filter as Filter2
|
|
2786
|
+
import { Filter as Filter2 } from "@dxos/client/echo";
|
|
2812
2787
|
import { FQ_ID_LENGTH } from "@dxos/client/echo";
|
|
2813
2788
|
import { Resource as Resource2 } from "@dxos/context";
|
|
2814
|
-
import {
|
|
2815
|
-
import {
|
|
2789
|
+
import { Obj } from "@dxos/echo";
|
|
2790
|
+
import { Function as Function2 } from "@dxos/functions";
|
|
2816
2791
|
import { invariant as invariant2 } from "@dxos/invariant";
|
|
2817
2792
|
import { PublicKey } from "@dxos/keys";
|
|
2818
2793
|
import { log as log3 } from "@dxos/log";
|
|
2819
2794
|
import { isNonNullable as isNonNullable2 } from "@dxos/util";
|
|
2820
|
-
import { ExportedCellChange as ExportedCellChange2 } from "
|
|
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
|
-
}
|
|
2795
|
+
import { ExportedCellChange as ExportedCellChange2 } from "@dxos/vendor-hyperformula";
|
|
2834
2796
|
var __dxlog_file4 = "/__w/dxos/dxos/packages/core/compute/src/compute-graph.ts";
|
|
2835
2797
|
var UNKNOWN_BINDING = "__UNKNOWN__";
|
|
2836
2798
|
var createSheetName = ({ type, id }) => `${type}@${id}`;
|
|
@@ -2844,6 +2806,49 @@ var parseSheetName = (name) => {
|
|
|
2844
2806
|
};
|
|
2845
2807
|
};
|
|
2846
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
|
+
}
|
|
2847
2852
|
get hf() {
|
|
2848
2853
|
return this._hf;
|
|
2849
2854
|
}
|
|
@@ -2871,7 +2876,7 @@ var ComputeGraph = class extends Resource2 {
|
|
|
2871
2876
|
getOrCreateNode(name) {
|
|
2872
2877
|
invariant2(name.length, void 0, {
|
|
2873
2878
|
F: __dxlog_file4,
|
|
2874
|
-
L:
|
|
2879
|
+
L: 134,
|
|
2875
2880
|
S: this,
|
|
2876
2881
|
A: [
|
|
2877
2882
|
"name.length",
|
|
@@ -2884,7 +2889,7 @@ var ComputeGraph = class extends Resource2 {
|
|
|
2884
2889
|
sheet: name
|
|
2885
2890
|
}, {
|
|
2886
2891
|
F: __dxlog_file4,
|
|
2887
|
-
L:
|
|
2892
|
+
L: 136,
|
|
2888
2893
|
S: this,
|
|
2889
2894
|
C: (f, a) => f(...a)
|
|
2890
2895
|
});
|
|
@@ -2893,7 +2898,7 @@ var ComputeGraph = class extends Resource2 {
|
|
|
2893
2898
|
const sheetId = this._hf.getSheetId(name);
|
|
2894
2899
|
invariant2(sheetId !== void 0, void 0, {
|
|
2895
2900
|
F: __dxlog_file4,
|
|
2896
|
-
L:
|
|
2901
|
+
L: 141,
|
|
2897
2902
|
S: this,
|
|
2898
2903
|
A: [
|
|
2899
2904
|
"sheetId !== undefined",
|
|
@@ -2917,7 +2922,7 @@ var ComputeGraph = class extends Resource2 {
|
|
|
2917
2922
|
}).filter(isNonNullable2);
|
|
2918
2923
|
for (const obj of objects) {
|
|
2919
2924
|
if (obj.name === name) {
|
|
2920
|
-
const type = getTypename(obj);
|
|
2925
|
+
const type = Obj.getTypename(obj);
|
|
2921
2926
|
return `'${createSheetName({
|
|
2922
2927
|
type,
|
|
2923
2928
|
id: obj.id
|
|
@@ -2949,7 +2954,7 @@ var ComputeGraph = class extends Resource2 {
|
|
|
2949
2954
|
}
|
|
2950
2955
|
const fn = this._remoteFunctions.find((fn2) => fn2.binding === binding);
|
|
2951
2956
|
if (fn) {
|
|
2952
|
-
const id =
|
|
2957
|
+
const id = Obj.getDXN(fn).toString();
|
|
2953
2958
|
return `${id}(${args})`;
|
|
2954
2959
|
} else {
|
|
2955
2960
|
return match;
|
|
@@ -2966,7 +2971,7 @@ var ComputeGraph = class extends Resource2 {
|
|
|
2966
2971
|
if (id.length !== FQ_ID_LENGTH) {
|
|
2967
2972
|
return match;
|
|
2968
2973
|
}
|
|
2969
|
-
const fn = this._remoteFunctions.find((fn2) =>
|
|
2974
|
+
const fn = this._remoteFunctions.find((fn2) => Obj.getDXN(fn2).toString() === id);
|
|
2970
2975
|
if (fn?.binding) {
|
|
2971
2976
|
return `${fn.binding}(${args})`;
|
|
2972
2977
|
} else {
|
|
@@ -2981,14 +2986,18 @@ var ComputeGraph = class extends Resource2 {
|
|
|
2981
2986
|
}
|
|
2982
2987
|
async _open() {
|
|
2983
2988
|
if (this._space) {
|
|
2984
|
-
const query = this._space.db.query(Filter2.type(
|
|
2985
|
-
const unsubscribe = query.subscribe(
|
|
2986
|
-
|
|
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);
|
|
2987
2993
|
this.update.emit({
|
|
2988
2994
|
type: "functionsUpdated"
|
|
2989
2995
|
});
|
|
2990
2996
|
});
|
|
2991
|
-
this._ctx.onDispose(
|
|
2997
|
+
this._ctx.onDispose(() => {
|
|
2998
|
+
unsubscribe();
|
|
2999
|
+
dispose();
|
|
3000
|
+
});
|
|
2992
3001
|
}
|
|
2993
3002
|
}
|
|
2994
3003
|
async _close() {
|
|
@@ -2996,40 +3005,6 @@ var ComputeGraph = class extends Resource2 {
|
|
|
2996
3005
|
await node.close();
|
|
2997
3006
|
}
|
|
2998
3007
|
}
|
|
2999
|
-
constructor(_hf, _space, _options) {
|
|
3000
|
-
super(), _define_property3(this, "_hf", void 0), _define_property3(this, "_space", void 0), _define_property3(this, "_options", void 0), _define_property3(this, "id", void 0), // Map of nodes indexed by sheet number.
|
|
3001
|
-
_define_property3(this, "_nodes", void 0), // Cached function objects.
|
|
3002
|
-
_define_property3(this, "_remoteFunctions", void 0), _define_property3(this, "update", void 0), // The context is passed to all functions.
|
|
3003
|
-
_define_property3(this, "context", void 0), this._hf = _hf, this._space = _space, this._options = _options, this.id = `graph-${PublicKey.random().truncate()}`, this._nodes = /* @__PURE__ */ new Map(), this._remoteFunctions = [], this.update = new Event2();
|
|
3004
|
-
this.context = new FunctionContext(this._hf, this._space, {
|
|
3005
|
-
...this._options,
|
|
3006
|
-
onUpdate: (update) => {
|
|
3007
|
-
this._options?.onUpdate?.(update);
|
|
3008
|
-
this.update.emit({
|
|
3009
|
-
type: "valuesUpdated"
|
|
3010
|
-
});
|
|
3011
|
-
}
|
|
3012
|
-
});
|
|
3013
|
-
this._hf.updateConfig({
|
|
3014
|
-
context: this.context
|
|
3015
|
-
});
|
|
3016
|
-
const onValuesUpdate = (changes) => {
|
|
3017
|
-
for (const change of changes) {
|
|
3018
|
-
if (change instanceof ExportedCellChange2) {
|
|
3019
|
-
const { sheet } = change;
|
|
3020
|
-
const node = this._nodes.get(sheet);
|
|
3021
|
-
if (node) {
|
|
3022
|
-
node.update.emit({
|
|
3023
|
-
type: "valuesUpdated",
|
|
3024
|
-
change
|
|
3025
|
-
});
|
|
3026
|
-
}
|
|
3027
|
-
}
|
|
3028
|
-
}
|
|
3029
|
-
};
|
|
3030
|
-
this._hf.on("valuesUpdated", onValuesUpdate);
|
|
3031
|
-
this._ctx.onDispose(() => this._hf.off("valuesUpdated", onValuesUpdate));
|
|
3032
|
-
}
|
|
3033
3008
|
};
|
|
3034
3009
|
|
|
3035
3010
|
// src/compute-graph-registry.ts
|
|
@@ -3037,31 +3012,28 @@ import defaultsDeep2 from "lodash.defaultsdeep";
|
|
|
3037
3012
|
import { Resource as Resource3 } from "@dxos/context";
|
|
3038
3013
|
import { invariant as invariant3 } from "@dxos/invariant";
|
|
3039
3014
|
import { log as log4 } from "@dxos/log";
|
|
3040
|
-
import { HyperFormula } from "
|
|
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
|
-
}
|
|
3015
|
+
import { HyperFormula } from "@dxos/vendor-hyperformula";
|
|
3054
3016
|
var __dxlog_file5 = "/__w/dxos/dxos/packages/core/compute/src/compute-graph-registry.ts";
|
|
3055
|
-
var defaultOptions = {
|
|
3056
|
-
licenseKey: "gpl-v3"
|
|
3057
|
-
};
|
|
3058
3017
|
var defaultPlugins = [
|
|
3059
3018
|
{
|
|
3060
3019
|
plugin: EdgeFunctionPlugin,
|
|
3061
3020
|
translations: EdgeFunctionPluginTranslations
|
|
3062
3021
|
}
|
|
3063
3022
|
];
|
|
3023
|
+
var defaultOptions = {
|
|
3024
|
+
licenseKey: "gpl-v3"
|
|
3025
|
+
};
|
|
3064
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
|
+
}
|
|
3065
3037
|
getGraph(spaceId) {
|
|
3066
3038
|
return this._graphs.get(spaceId);
|
|
3067
3039
|
}
|
|
@@ -3072,7 +3044,7 @@ var ComputeGraphRegistry = class extends Resource3 {
|
|
|
3072
3044
|
space: space.id
|
|
3073
3045
|
}, {
|
|
3074
3046
|
F: __dxlog_file5,
|
|
3075
|
-
L:
|
|
3047
|
+
L: 73,
|
|
3076
3048
|
S: this,
|
|
3077
3049
|
C: (f, a) => f(...a)
|
|
3078
3050
|
});
|
|
@@ -3083,7 +3055,7 @@ var ComputeGraphRegistry = class extends Resource3 {
|
|
|
3083
3055
|
createGraph(space) {
|
|
3084
3056
|
invariant3(!this._graphs.has(space.id), `ComputeGraph already exists for space: ${space.id}`, {
|
|
3085
3057
|
F: __dxlog_file5,
|
|
3086
|
-
L:
|
|
3058
|
+
L: 81,
|
|
3087
3059
|
S: this,
|
|
3088
3060
|
A: [
|
|
3089
3061
|
"!this._graphs.has(space.id)",
|
|
@@ -3091,7 +3063,17 @@ var ComputeGraphRegistry = class extends Resource3 {
|
|
|
3091
3063
|
]
|
|
3092
3064
|
});
|
|
3093
3065
|
const hf = HyperFormula.buildEmpty(this._options);
|
|
3094
|
-
|
|
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);
|
|
3095
3077
|
this._graphs.set(space.id, graph);
|
|
3096
3078
|
return graph;
|
|
3097
3079
|
}
|
|
@@ -3101,15 +3083,6 @@ var ComputeGraphRegistry = class extends Resource3 {
|
|
|
3101
3083
|
}
|
|
3102
3084
|
this._graphs.clear();
|
|
3103
3085
|
}
|
|
3104
|
-
constructor(options = {
|
|
3105
|
-
plugins: defaultPlugins
|
|
3106
|
-
}) {
|
|
3107
|
-
super(), _define_property4(this, "_graphs", /* @__PURE__ */ new Map()), _define_property4(this, "_options", void 0);
|
|
3108
|
-
this._options = defaultsDeep2({}, options, defaultOptions);
|
|
3109
|
-
this._options.plugins?.forEach(({ plugin, translations }) => {
|
|
3110
|
-
HyperFormula.registerFunctionPlugin(plugin, translations);
|
|
3111
|
-
});
|
|
3112
|
-
}
|
|
3113
3086
|
};
|
|
3114
3087
|
|
|
3115
3088
|
export {
|
|
@@ -3135,8 +3108,8 @@ export {
|
|
|
3135
3108
|
createSheetName,
|
|
3136
3109
|
parseSheetName,
|
|
3137
3110
|
ComputeGraph,
|
|
3138
|
-
defaultOptions,
|
|
3139
3111
|
defaultPlugins,
|
|
3112
|
+
defaultOptions,
|
|
3140
3113
|
ComputeGraphRegistry
|
|
3141
3114
|
};
|
|
3142
|
-
//# sourceMappingURL=chunk-
|
|
3115
|
+
//# sourceMappingURL=chunk-QDJ6J7GT.mjs.map
|