@dxos/compute 0.8.4-main.406dc2a → 0.8.4-main.422d1c7879
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-C7KLV2IU.mjs → neutral/chunk-JRV42MW3.mjs} +120 -163
- package/dist/lib/neutral/chunk-JRV42MW3.mjs.map +7 -0
- package/dist/lib/{browser → neutral}/index.mjs +1 -1
- package/dist/lib/neutral/meta.json +1 -0
- package/dist/lib/{browser → neutral}/testing/index.mjs +37 -24
- package/dist/lib/neutral/testing/index.mjs.map +7 -0
- package/dist/types/src/compute-graph-registry.d.ts +2 -2
- package/dist/types/src/compute-graph-registry.d.ts.map +1 -1
- package/dist/types/src/compute-graph.d.ts +7 -7
- package/dist/types/src/compute-graph.d.ts.map +1 -1
- package/dist/types/src/functions/async-function.d.ts +3 -3
- package/dist/types/src/functions/async-function.d.ts.map +1 -1
- 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/test-builder.d.ts.map +1 -1
- package/dist/types/src/testing/test-runtime.d.ts +2 -2
- package/dist/types/src/testing/test-runtime.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +29 -34
- package/src/compute-graph-registry.test.ts +51 -22
- package/src/compute-graph-registry.ts +2 -2
- package/src/compute-graph.test.ts +61 -10
- package/src/compute-graph.ts +37 -33
- package/src/functions/async-function.ts +2 -2
- package/src/functions/edge-function.ts +13 -19
- package/src/index.ts +0 -27
- package/src/testing/test-builder.ts +0 -1
- package/src/testing/test-runtime.ts +30 -15
- package/dist/lib/browser/chunk-C7KLV2IU.mjs.map +0 -7
- package/dist/lib/browser/meta.json +0 -1
- package/dist/lib/browser/testing/index.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-K37OSZ5O.mjs +0 -3146
- package/dist/lib/node-esm/chunk-K37OSZ5O.mjs.map +0 -7
- package/dist/lib/node-esm/index.mjs +0 -56
- package/dist/lib/node-esm/index.mjs.map +0 -7
- package/dist/lib/node-esm/meta.json +0 -1
- package/dist/lib/node-esm/testing/index.mjs +0 -207
- package/dist/lib/node-esm/testing/index.mjs.map +0 -7
- /package/dist/lib/{browser → neutral}/index.mjs.map +0 -0
|
@@ -78,20 +78,13 @@ var inRange = (range, cell) => {
|
|
|
78
78
|
import { Event } from "@dxos/async";
|
|
79
79
|
import { Resource } from "@dxos/context";
|
|
80
80
|
import { DetailedCellError as DetailedCellError2 } from "@dxos/vendor-hyperformula";
|
|
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
|
-
}
|
|
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,9 +117,6 @@ 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
|
|
@@ -134,25 +124,15 @@ import defaultsDeep from "lodash.defaultsdeep";
|
|
|
134
124
|
import { debounce } from "@dxos/async";
|
|
135
125
|
import { log } from "@dxos/log";
|
|
136
126
|
import { CellError, EmptyValue, ErrorType, FunctionPlugin } from "@dxos/vendor-hyperformula";
|
|
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
|
-
}
|
|
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
130
|
debounceDelay: 200
|
|
154
131
|
};
|
|
155
132
|
var FunctionContext = class _FunctionContext {
|
|
133
|
+
_hf;
|
|
134
|
+
_runtime;
|
|
135
|
+
_space;
|
|
156
136
|
// Mangle name with params.
|
|
157
137
|
static createInvocationKey(name, ...args) {
|
|
158
138
|
return JSON.stringify({
|
|
@@ -160,6 +140,34 @@ var FunctionContext = class _FunctionContext {
|
|
|
160
140
|
...args
|
|
161
141
|
});
|
|
162
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
|
+
}
|
|
163
171
|
get space() {
|
|
164
172
|
return this._space;
|
|
165
173
|
}
|
|
@@ -248,35 +256,6 @@ var FunctionContext = class _FunctionContext {
|
|
|
248
256
|
});
|
|
249
257
|
return value;
|
|
250
258
|
}
|
|
251
|
-
constructor(_hf, _runtime, _space, _options) {
|
|
252
|
-
_define_property2(this, "_hf", void 0);
|
|
253
|
-
_define_property2(this, "_runtime", 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._runtime = _runtime;
|
|
263
|
-
this._space = _space;
|
|
264
|
-
this._cache = /* @__PURE__ */ new Map();
|
|
265
|
-
this._pending = /* @__PURE__ */ new Map();
|
|
266
|
-
this._subscriptions = /* @__PURE__ */ new Map();
|
|
267
|
-
this._invocations = {};
|
|
268
|
-
this._options = defaultsDeep(_options ?? {}, defaultFunctionContextOptions);
|
|
269
|
-
this._onUpdate = debounce((update) => {
|
|
270
|
-
log("update", update, {
|
|
271
|
-
F: __dxlog_file2,
|
|
272
|
-
L: 86,
|
|
273
|
-
S: this,
|
|
274
|
-
C: (f, a) => f(...a)
|
|
275
|
-
});
|
|
276
|
-
this._hf.resumeEvaluation();
|
|
277
|
-
this._options.onUpdate?.(update);
|
|
278
|
-
}, this._options.debounceDelay);
|
|
279
|
-
}
|
|
280
259
|
};
|
|
281
260
|
var AsyncFunctionPlugin = class extends FunctionPlugin {
|
|
282
261
|
get context() {
|
|
@@ -295,14 +274,12 @@ var AsyncFunctionPlugin = class extends FunctionPlugin {
|
|
|
295
274
|
};
|
|
296
275
|
|
|
297
276
|
// src/functions/edge-function.ts
|
|
298
|
-
import { effect } from "@preact/signals-core";
|
|
299
277
|
import * as Effect from "effect/Effect";
|
|
300
278
|
import * as SchemaAST from "effect/SchemaAST";
|
|
301
279
|
import { Filter } from "@dxos/client/echo";
|
|
302
|
-
import {
|
|
303
|
-
import { ComputeEventLogger, FunctionInvocationService, FunctionType, TracingService } from "@dxos/functions";
|
|
304
|
-
import { FunctionDefinition } from "@dxos/functions";
|
|
280
|
+
import { JsonSchema, Obj } from "@dxos/echo";
|
|
305
281
|
import { log as log2 } from "@dxos/log";
|
|
282
|
+
import { Operation } from "@dxos/operation";
|
|
306
283
|
import { isNonNullable } from "@dxos/util";
|
|
307
284
|
import { CellError as CellError2, ErrorType as ErrorType2, FunctionArgumentType } from "@dxos/vendor-hyperformula";
|
|
308
285
|
var __dxlog_file3 = "/__w/dxos/dxos/packages/core/compute/src/functions/edge-function.ts";
|
|
@@ -315,7 +292,7 @@ var EdgeFunctionPlugin = class extends AsyncFunctionPlugin {
|
|
|
315
292
|
if (!space) {
|
|
316
293
|
return new CellError2(ErrorType2.REF, "Missing space");
|
|
317
294
|
}
|
|
318
|
-
const
|
|
295
|
+
const [fn] = await space.db.query(Filter.type(Operation.PersistentOperation, {
|
|
319
296
|
binding
|
|
320
297
|
})).run();
|
|
321
298
|
if (!fn) {
|
|
@@ -323,23 +300,22 @@ var EdgeFunctionPlugin = class extends AsyncFunctionPlugin {
|
|
|
323
300
|
binding
|
|
324
301
|
}, {
|
|
325
302
|
F: __dxlog_file3,
|
|
326
|
-
L:
|
|
303
|
+
L: 39,
|
|
327
304
|
S: this,
|
|
328
305
|
C: (f, a) => f(...a)
|
|
329
306
|
});
|
|
330
307
|
return new CellError2(ErrorType2.REF, "Function not found");
|
|
331
308
|
}
|
|
332
309
|
if (subscribe) {
|
|
333
|
-
const unsubscribe =
|
|
310
|
+
const unsubscribe = Obj.subscribe(fn, () => {
|
|
334
311
|
log2("function changed", {
|
|
335
312
|
fn
|
|
336
313
|
}, {
|
|
337
314
|
F: __dxlog_file3,
|
|
338
|
-
L:
|
|
315
|
+
L: 45,
|
|
339
316
|
S: this,
|
|
340
317
|
C: (f, a) => f(...a)
|
|
341
318
|
});
|
|
342
|
-
const _ = fn?.version;
|
|
343
319
|
this.runAsyncFunction(ast, state, handler(false), {
|
|
344
320
|
ttl: FUNCTION_TTL
|
|
345
321
|
});
|
|
@@ -347,10 +323,10 @@ var EdgeFunctionPlugin = class extends AsyncFunctionPlugin {
|
|
|
347
323
|
this.context.createSubscription(ast.procedureName, unsubscribe);
|
|
348
324
|
}
|
|
349
325
|
const runtime = this.context.runtime;
|
|
350
|
-
const functionDef =
|
|
326
|
+
const functionDef = Operation.deserialize(fn);
|
|
351
327
|
let input;
|
|
352
328
|
if (fn.inputSchema) {
|
|
353
|
-
const schema = toEffectSchema(fn.inputSchema);
|
|
329
|
+
const schema = JsonSchema.toEffectSchema(fn.inputSchema);
|
|
354
330
|
const props = SchemaAST.getPropertySignatures(schema.ast);
|
|
355
331
|
input = {};
|
|
356
332
|
props.forEach(({ name }, index) => {
|
|
@@ -361,9 +337,7 @@ var EdgeFunctionPlugin = class extends AsyncFunctionPlugin {
|
|
|
361
337
|
args: args.filter(isNonNullable)
|
|
362
338
|
};
|
|
363
339
|
}
|
|
364
|
-
const result = runtime.runPromise(
|
|
365
|
-
return yield* FunctionInvocationService.invokeFunction(functionDef, input);
|
|
366
|
-
}).pipe(Effect.provide(ComputeEventLogger.layerFromTracing), Effect.provide(TracingService.layerNoop)));
|
|
340
|
+
const result = runtime.runPromise(Operation.invoke(functionDef, input).pipe(Effect.orDie));
|
|
367
341
|
return result;
|
|
368
342
|
};
|
|
369
343
|
return this.runAsyncFunction(ast, state, handler(true), {
|
|
@@ -2801,29 +2775,15 @@ var defaultFunctions = [
|
|
|
2801
2775
|
|
|
2802
2776
|
// src/compute-graph.ts
|
|
2803
2777
|
import { Event as Event2 } from "@dxos/async";
|
|
2804
|
-
import { Filter as Filter2
|
|
2805
|
-
import { FQ_ID_LENGTH } from "@dxos/client/echo";
|
|
2778
|
+
import { Filter as Filter2 } from "@dxos/client/echo";
|
|
2806
2779
|
import { Resource as Resource2 } from "@dxos/context";
|
|
2807
|
-
import {
|
|
2808
|
-
import { FunctionType as FunctionType2 } from "@dxos/functions";
|
|
2780
|
+
import { Obj as Obj2 } from "@dxos/echo";
|
|
2809
2781
|
import { invariant as invariant2 } from "@dxos/invariant";
|
|
2810
2782
|
import { PublicKey } from "@dxos/keys";
|
|
2811
2783
|
import { log as log3 } from "@dxos/log";
|
|
2784
|
+
import { Operation as Operation2 } from "@dxos/operation";
|
|
2812
2785
|
import { isNonNullable as isNonNullable2 } from "@dxos/util";
|
|
2813
2786
|
import { ExportedCellChange as ExportedCellChange2 } from "@dxos/vendor-hyperformula";
|
|
2814
|
-
function _define_property3(obj, key, value) {
|
|
2815
|
-
if (key in obj) {
|
|
2816
|
-
Object.defineProperty(obj, key, {
|
|
2817
|
-
value,
|
|
2818
|
-
enumerable: true,
|
|
2819
|
-
configurable: true,
|
|
2820
|
-
writable: true
|
|
2821
|
-
});
|
|
2822
|
-
} else {
|
|
2823
|
-
obj[key] = value;
|
|
2824
|
-
}
|
|
2825
|
-
return obj;
|
|
2826
|
-
}
|
|
2827
2787
|
var __dxlog_file4 = "/__w/dxos/dxos/packages/core/compute/src/compute-graph.ts";
|
|
2828
2788
|
var UNKNOWN_BINDING = "__UNKNOWN__";
|
|
2829
2789
|
var createSheetName = ({ type, id }) => `${type}@${id}`;
|
|
@@ -2837,6 +2797,49 @@ var parseSheetName = (name) => {
|
|
|
2837
2797
|
};
|
|
2838
2798
|
};
|
|
2839
2799
|
var ComputeGraph = class extends Resource2 {
|
|
2800
|
+
_hf;
|
|
2801
|
+
_runtime;
|
|
2802
|
+
_space;
|
|
2803
|
+
_options;
|
|
2804
|
+
id = `graph-${PublicKey.random().truncate()}`;
|
|
2805
|
+
// Map of nodes indexed by sheet number.
|
|
2806
|
+
_nodes = /* @__PURE__ */ new Map();
|
|
2807
|
+
// Cached function objects.
|
|
2808
|
+
_remoteFunctions = [];
|
|
2809
|
+
update = new Event2();
|
|
2810
|
+
// The context is passed to all functions.
|
|
2811
|
+
context;
|
|
2812
|
+
constructor(_hf, _runtime, _space, _options) {
|
|
2813
|
+
super(), this._hf = _hf, this._runtime = _runtime, this._space = _space, this._options = _options;
|
|
2814
|
+
this.context = new FunctionContext(this._hf, this._runtime, this._space, {
|
|
2815
|
+
...this._options,
|
|
2816
|
+
onUpdate: (update) => {
|
|
2817
|
+
this._options?.onUpdate?.(update);
|
|
2818
|
+
this.update.emit({
|
|
2819
|
+
type: "valuesUpdated"
|
|
2820
|
+
});
|
|
2821
|
+
}
|
|
2822
|
+
});
|
|
2823
|
+
this._hf.updateConfig({
|
|
2824
|
+
context: this.context
|
|
2825
|
+
});
|
|
2826
|
+
const onValuesUpdate = (changes) => {
|
|
2827
|
+
for (const change of changes) {
|
|
2828
|
+
if (change instanceof ExportedCellChange2) {
|
|
2829
|
+
const { sheet } = change;
|
|
2830
|
+
const node = this._nodes.get(sheet);
|
|
2831
|
+
if (node) {
|
|
2832
|
+
node.update.emit({
|
|
2833
|
+
type: "valuesUpdated",
|
|
2834
|
+
change
|
|
2835
|
+
});
|
|
2836
|
+
}
|
|
2837
|
+
}
|
|
2838
|
+
}
|
|
2839
|
+
};
|
|
2840
|
+
this._hf.on("valuesUpdated", onValuesUpdate);
|
|
2841
|
+
this._ctx.onDispose(() => this._hf.off("valuesUpdated", onValuesUpdate));
|
|
2842
|
+
}
|
|
2840
2843
|
get hf() {
|
|
2841
2844
|
return this._hf;
|
|
2842
2845
|
}
|
|
@@ -2864,7 +2867,7 @@ var ComputeGraph = class extends Resource2 {
|
|
|
2864
2867
|
getOrCreateNode(name) {
|
|
2865
2868
|
invariant2(name.length, void 0, {
|
|
2866
2869
|
F: __dxlog_file4,
|
|
2867
|
-
L:
|
|
2870
|
+
L: 132,
|
|
2868
2871
|
S: this,
|
|
2869
2872
|
A: [
|
|
2870
2873
|
"name.length",
|
|
@@ -2877,7 +2880,7 @@ var ComputeGraph = class extends Resource2 {
|
|
|
2877
2880
|
sheet: name
|
|
2878
2881
|
}, {
|
|
2879
2882
|
F: __dxlog_file4,
|
|
2880
|
-
L:
|
|
2883
|
+
L: 134,
|
|
2881
2884
|
S: this,
|
|
2882
2885
|
C: (f, a) => f(...a)
|
|
2883
2886
|
});
|
|
@@ -2886,7 +2889,7 @@ var ComputeGraph = class extends Resource2 {
|
|
|
2886
2889
|
const sheetId = this._hf.getSheetId(name);
|
|
2887
2890
|
invariant2(sheetId !== void 0, void 0, {
|
|
2888
2891
|
F: __dxlog_file4,
|
|
2889
|
-
L:
|
|
2892
|
+
L: 139,
|
|
2890
2893
|
S: this,
|
|
2891
2894
|
A: [
|
|
2892
2895
|
"sheetId !== undefined",
|
|
@@ -2910,7 +2913,7 @@ var ComputeGraph = class extends Resource2 {
|
|
|
2910
2913
|
}).filter(isNonNullable2);
|
|
2911
2914
|
for (const obj of objects) {
|
|
2912
2915
|
if (obj.name === name) {
|
|
2913
|
-
const type = getTypename(obj);
|
|
2916
|
+
const type = Obj2.getTypename(obj);
|
|
2914
2917
|
return `'${createSheetName({
|
|
2915
2918
|
type,
|
|
2916
2919
|
id: obj.id
|
|
@@ -2932,8 +2935,8 @@ var ComputeGraph = class extends Resource2 {
|
|
|
2932
2935
|
});
|
|
2933
2936
|
}
|
|
2934
2937
|
/**
|
|
2935
|
-
* Map from binding to fully qualified ECHO
|
|
2936
|
-
* E.g., HELLO() => spaceId:objectId()
|
|
2938
|
+
* Map from binding to fully qualified ECHO DXN (to store).
|
|
2939
|
+
* E.g., HELLO() => dxn:echo:spaceId:objectId()
|
|
2937
2940
|
*/
|
|
2938
2941
|
mapFunctionBindingToId(formula) {
|
|
2939
2942
|
return formula.replace(/(\w+)\((.*)\)/g, (match, binding, args) => {
|
|
@@ -2942,7 +2945,7 @@ var ComputeGraph = class extends Resource2 {
|
|
|
2942
2945
|
}
|
|
2943
2946
|
const fn = this._remoteFunctions.find((fn2) => fn2.binding === binding);
|
|
2944
2947
|
if (fn) {
|
|
2945
|
-
const id =
|
|
2948
|
+
const id = Obj2.getDXN(fn).toString();
|
|
2946
2949
|
return `${id}(${args})`;
|
|
2947
2950
|
} else {
|
|
2948
2951
|
return match;
|
|
@@ -2950,16 +2953,13 @@ var ComputeGraph = class extends Resource2 {
|
|
|
2950
2953
|
});
|
|
2951
2954
|
}
|
|
2952
2955
|
/**
|
|
2953
|
-
* Map from fully qualified ECHO
|
|
2954
|
-
* E.g., spaceId:objectId() => HELLO()
|
|
2956
|
+
* Map from fully qualified ECHO DXN to binding (from store).
|
|
2957
|
+
* E.g., dxn:echo:spaceId:objectId() => HELLO()
|
|
2955
2958
|
*/
|
|
2956
2959
|
mapFunctionBindingFromId(formula) {
|
|
2957
|
-
const binding = formula.replace(/(
|
|
2958
|
-
const
|
|
2959
|
-
|
|
2960
|
-
return match;
|
|
2961
|
-
}
|
|
2962
|
-
const fn = this._remoteFunctions.find((fn2) => fullyQualifiedId(fn2) === id);
|
|
2960
|
+
const binding = formula.replace(/dxn:([^:]+):([^:(]+):([a-zA-Z0-9]+)\((.*)\)/g, (_match, kind, spaceTag, objectId, args) => {
|
|
2961
|
+
const dxn = `dxn:${kind}:${spaceTag}:${objectId}`;
|
|
2962
|
+
const fn = this._remoteFunctions.find((fn2) => Obj2.getDXN(fn2).toString() === dxn);
|
|
2963
2963
|
if (fn?.binding) {
|
|
2964
2964
|
return `${fn.binding}(${args})`;
|
|
2965
2965
|
} else {
|
|
@@ -2974,12 +2974,14 @@ var ComputeGraph = class extends Resource2 {
|
|
|
2974
2974
|
}
|
|
2975
2975
|
async _open() {
|
|
2976
2976
|
if (this._space) {
|
|
2977
|
-
const query = this._space.db.query(Filter2.type(
|
|
2978
|
-
const unsubscribe = query.subscribe((
|
|
2979
|
-
this._remoteFunctions =
|
|
2977
|
+
const query = this._space.db.query(Filter2.type(Operation2.PersistentOperation));
|
|
2978
|
+
const unsubscribe = query.subscribe(() => {
|
|
2979
|
+
this._remoteFunctions = query.results.filter((fn) => fn.binding);
|
|
2980
2980
|
this.update.emit({
|
|
2981
2981
|
type: "functionsUpdated"
|
|
2982
2982
|
});
|
|
2983
|
+
}, {
|
|
2984
|
+
fire: true
|
|
2983
2985
|
});
|
|
2984
2986
|
this._ctx.onDispose(unsubscribe);
|
|
2985
2987
|
}
|
|
@@ -2989,40 +2991,6 @@ var ComputeGraph = class extends Resource2 {
|
|
|
2989
2991
|
await node.close();
|
|
2990
2992
|
}
|
|
2991
2993
|
}
|
|
2992
|
-
constructor(_hf, _runtime, _space, _options) {
|
|
2993
|
-
super(), _define_property3(this, "_hf", void 0), _define_property3(this, "_runtime", void 0), _define_property3(this, "_space", void 0), _define_property3(this, "_options", void 0), _define_property3(this, "id", void 0), // Map of nodes indexed by sheet number.
|
|
2994
|
-
_define_property3(this, "_nodes", void 0), // Cached function objects.
|
|
2995
|
-
_define_property3(this, "_remoteFunctions", void 0), _define_property3(this, "update", void 0), // The context is passed to all functions.
|
|
2996
|
-
_define_property3(this, "context", void 0), this._hf = _hf, this._runtime = _runtime, this._space = _space, this._options = _options, this.id = `graph-${PublicKey.random().truncate()}`, this._nodes = /* @__PURE__ */ new Map(), this._remoteFunctions = [], this.update = new Event2();
|
|
2997
|
-
this.context = new FunctionContext(this._hf, this._runtime, this._space, {
|
|
2998
|
-
...this._options,
|
|
2999
|
-
onUpdate: (update) => {
|
|
3000
|
-
this._options?.onUpdate?.(update);
|
|
3001
|
-
this.update.emit({
|
|
3002
|
-
type: "valuesUpdated"
|
|
3003
|
-
});
|
|
3004
|
-
}
|
|
3005
|
-
});
|
|
3006
|
-
this._hf.updateConfig({
|
|
3007
|
-
context: this.context
|
|
3008
|
-
});
|
|
3009
|
-
const onValuesUpdate = (changes) => {
|
|
3010
|
-
for (const change of changes) {
|
|
3011
|
-
if (change instanceof ExportedCellChange2) {
|
|
3012
|
-
const { sheet } = change;
|
|
3013
|
-
const node = this._nodes.get(sheet);
|
|
3014
|
-
if (node) {
|
|
3015
|
-
node.update.emit({
|
|
3016
|
-
type: "valuesUpdated",
|
|
3017
|
-
change
|
|
3018
|
-
});
|
|
3019
|
-
}
|
|
3020
|
-
}
|
|
3021
|
-
}
|
|
3022
|
-
};
|
|
3023
|
-
this._hf.on("valuesUpdated", onValuesUpdate);
|
|
3024
|
-
this._ctx.onDispose(() => this._hf.off("valuesUpdated", onValuesUpdate));
|
|
3025
|
-
}
|
|
3026
2994
|
};
|
|
3027
2995
|
|
|
3028
2996
|
// src/compute-graph-registry.ts
|
|
@@ -3031,19 +2999,6 @@ import { Resource as Resource3 } from "@dxos/context";
|
|
|
3031
2999
|
import { invariant as invariant3 } from "@dxos/invariant";
|
|
3032
3000
|
import { log as log4 } from "@dxos/log";
|
|
3033
3001
|
import { HyperFormula } from "@dxos/vendor-hyperformula";
|
|
3034
|
-
function _define_property4(obj, key, value) {
|
|
3035
|
-
if (key in obj) {
|
|
3036
|
-
Object.defineProperty(obj, key, {
|
|
3037
|
-
value,
|
|
3038
|
-
enumerable: true,
|
|
3039
|
-
configurable: true,
|
|
3040
|
-
writable: true
|
|
3041
|
-
});
|
|
3042
|
-
} else {
|
|
3043
|
-
obj[key] = value;
|
|
3044
|
-
}
|
|
3045
|
-
return obj;
|
|
3046
|
-
}
|
|
3047
3002
|
var __dxlog_file5 = "/__w/dxos/dxos/packages/core/compute/src/compute-graph-registry.ts";
|
|
3048
3003
|
var defaultPlugins = [
|
|
3049
3004
|
{
|
|
@@ -3055,6 +3010,16 @@ var defaultOptions = {
|
|
|
3055
3010
|
licenseKey: "gpl-v3"
|
|
3056
3011
|
};
|
|
3057
3012
|
var ComputeGraphRegistry = class extends Resource3 {
|
|
3013
|
+
_graphs = /* @__PURE__ */ new Map();
|
|
3014
|
+
_options;
|
|
3015
|
+
constructor(options) {
|
|
3016
|
+
super();
|
|
3017
|
+
this._options = defaultsDeep2({}, options, defaultOptions);
|
|
3018
|
+
this._options.plugins = this._options.plugins ?? defaultPlugins;
|
|
3019
|
+
this._options.plugins?.forEach(({ plugin, translations }) => {
|
|
3020
|
+
HyperFormula.registerFunctionPlugin(plugin, translations);
|
|
3021
|
+
});
|
|
3022
|
+
}
|
|
3058
3023
|
getGraph(spaceId) {
|
|
3059
3024
|
return this._graphs.get(spaceId);
|
|
3060
3025
|
}
|
|
@@ -3104,14 +3069,6 @@ var ComputeGraphRegistry = class extends Resource3 {
|
|
|
3104
3069
|
}
|
|
3105
3070
|
this._graphs.clear();
|
|
3106
3071
|
}
|
|
3107
|
-
constructor(options) {
|
|
3108
|
-
super(), _define_property4(this, "_graphs", /* @__PURE__ */ new Map()), _define_property4(this, "_options", void 0);
|
|
3109
|
-
this._options = defaultsDeep2({}, options, defaultOptions);
|
|
3110
|
-
this._options.plugins = this._options.plugins ?? defaultPlugins;
|
|
3111
|
-
this._options.plugins?.forEach(({ plugin, translations }) => {
|
|
3112
|
-
HyperFormula.registerFunctionPlugin(plugin, translations);
|
|
3113
|
-
});
|
|
3114
|
-
}
|
|
3115
3072
|
};
|
|
3116
3073
|
|
|
3117
3074
|
export {
|
|
@@ -3141,4 +3098,4 @@ export {
|
|
|
3141
3098
|
defaultOptions,
|
|
3142
3099
|
ComputeGraphRegistry
|
|
3143
3100
|
};
|
|
3144
|
-
//# sourceMappingURL=chunk-
|
|
3101
|
+
//# sourceMappingURL=chunk-JRV42MW3.mjs.map
|