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