@dxos/compute 0.8.4-main.1f223c7 → 0.8.4-main.2244d791bb
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-XQYPCRZP.mjs → neutral/chunk-KGBGT4NT.mjs} +151 -185
- package/dist/lib/neutral/chunk-KGBGT4NT.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 +32 -20
- package/dist/lib/neutral/testing/index.mjs.map +7 -0
- package/dist/types/src/compute-graph-registry.d.ts +8 -3
- 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 +4 -1
- package/dist/types/src/compute-graph.d.ts.map +1 -1
- package/dist/types/src/functions/async-function.d.ts +11 -9
- 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/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-runtime.d.ts +10 -0
- package/dist/types/src/testing/test-runtime.d.ts.map +1 -0
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +28 -27
- package/src/compute-graph-registry.test.ts +158 -0
- package/src/compute-graph-registry.ts +17 -8
- package/src/compute-graph.test.ts +29 -10
- package/src/compute-graph.ts +19 -13
- package/src/functions/async-function.ts +13 -12
- package/src/functions/edge-function.ts +30 -28
- 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-runtime.ts +34 -0
- package/dist/lib/browser/chunk-XQYPCRZP.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-2XWWSGAU.mjs +0 -3142
- package/dist/lib/node-esm/chunk-2XWWSGAU.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 -187
- 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,26 +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
|
-
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 = {};
|
|
@@ -209,7 +216,7 @@ var FunctionContext = class _FunctionContext {
|
|
|
209
216
|
value: value2
|
|
210
217
|
}, {
|
|
211
218
|
F: __dxlog_file2,
|
|
212
|
-
L:
|
|
219
|
+
L: 144,
|
|
213
220
|
S: this,
|
|
214
221
|
C: (f, a) => f(...a)
|
|
215
222
|
});
|
|
@@ -223,7 +230,7 @@ var FunctionContext = class _FunctionContext {
|
|
|
223
230
|
err
|
|
224
231
|
}, {
|
|
225
232
|
F: __dxlog_file2,
|
|
226
|
-
L:
|
|
233
|
+
L: 148,
|
|
227
234
|
S: this,
|
|
228
235
|
C: (f, a) => f(...a)
|
|
229
236
|
});
|
|
@@ -243,39 +250,12 @@ var FunctionContext = class _FunctionContext {
|
|
|
243
250
|
cache: value
|
|
244
251
|
}, {
|
|
245
252
|
F: __dxlog_file2,
|
|
246
|
-
L:
|
|
253
|
+
L: 156,
|
|
247
254
|
S: this,
|
|
248
255
|
C: (f, a) => f(...a)
|
|
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: 85,
|
|
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() {
|
|
@@ -294,11 +274,12 @@ var AsyncFunctionPlugin = class extends FunctionPlugin {
|
|
|
294
274
|
};
|
|
295
275
|
|
|
296
276
|
// src/functions/edge-function.ts
|
|
297
|
-
import
|
|
298
|
-
import
|
|
299
|
-
import { Filter
|
|
300
|
-
import {
|
|
301
|
-
import {
|
|
277
|
+
import * as Effect from "effect/Effect";
|
|
278
|
+
import * as SchemaAST from "effect/SchemaAST";
|
|
279
|
+
import { Filter } from "@dxos/client/echo";
|
|
280
|
+
import { JsonSchema, Obj } from "@dxos/echo";
|
|
281
|
+
import { Function, FunctionInvocationService, TracingService } from "@dxos/functions";
|
|
282
|
+
import { FunctionDefinition } from "@dxos/functions";
|
|
302
283
|
import { log as log2 } from "@dxos/log";
|
|
303
284
|
import { isNonNullable } from "@dxos/util";
|
|
304
285
|
import { CellError as CellError2, ErrorType as ErrorType2, FunctionArgumentType } from "@dxos/vendor-hyperformula";
|
|
@@ -312,7 +293,7 @@ var EdgeFunctionPlugin = class extends AsyncFunctionPlugin {
|
|
|
312
293
|
if (!space) {
|
|
313
294
|
return new CellError2(ErrorType2.REF, "Missing space");
|
|
314
295
|
}
|
|
315
|
-
const
|
|
296
|
+
const [fn] = await space.db.query(Filter.type(Function.Function, {
|
|
316
297
|
binding
|
|
317
298
|
})).run();
|
|
318
299
|
if (!fn) {
|
|
@@ -320,55 +301,46 @@ var EdgeFunctionPlugin = class extends AsyncFunctionPlugin {
|
|
|
320
301
|
binding
|
|
321
302
|
}, {
|
|
322
303
|
F: __dxlog_file3,
|
|
323
|
-
L:
|
|
304
|
+
L: 40,
|
|
324
305
|
S: this,
|
|
325
306
|
C: (f, a) => f(...a)
|
|
326
307
|
});
|
|
327
308
|
return new CellError2(ErrorType2.REF, "Function not found");
|
|
328
309
|
}
|
|
329
310
|
if (subscribe) {
|
|
330
|
-
const unsubscribe =
|
|
311
|
+
const unsubscribe = Obj.subscribe(fn, () => {
|
|
331
312
|
log2("function changed", {
|
|
332
313
|
fn
|
|
333
314
|
}, {
|
|
334
315
|
F: __dxlog_file3,
|
|
335
|
-
L:
|
|
316
|
+
L: 46,
|
|
336
317
|
S: this,
|
|
337
318
|
C: (f, a) => f(...a)
|
|
338
319
|
});
|
|
339
|
-
const _ = fn?.version;
|
|
340
320
|
this.runAsyncFunction(ast, state, handler(false), {
|
|
341
321
|
ttl: FUNCTION_TTL
|
|
342
322
|
});
|
|
343
323
|
});
|
|
344
324
|
this.context.createSubscription(ast.procedureName, unsubscribe);
|
|
345
325
|
}
|
|
346
|
-
const
|
|
326
|
+
const runtime = this.context.runtime;
|
|
327
|
+
const functionDef = FunctionDefinition.deserialize(fn);
|
|
328
|
+
let input;
|
|
347
329
|
if (fn.inputSchema) {
|
|
348
|
-
const schema = toEffectSchema(fn.inputSchema);
|
|
349
|
-
SchemaAST.getPropertySignatures(schema.ast)
|
|
350
|
-
|
|
330
|
+
const schema = JsonSchema.toEffectSchema(fn.inputSchema);
|
|
331
|
+
const props = SchemaAST.getPropertySignatures(schema.ast);
|
|
332
|
+
input = {};
|
|
333
|
+
props.forEach(({ name }, index) => {
|
|
334
|
+
input[name.toString()] = args[index];
|
|
351
335
|
});
|
|
352
336
|
} else {
|
|
353
|
-
|
|
337
|
+
input = {
|
|
338
|
+
args: args.filter(isNonNullable)
|
|
339
|
+
};
|
|
354
340
|
}
|
|
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: 74,
|
|
369
|
-
S: this,
|
|
370
|
-
C: (f, a) => f(...a)
|
|
371
|
-
});
|
|
341
|
+
const result = runtime.runPromise(Effect.gen(function* () {
|
|
342
|
+
return yield* FunctionInvocationService.invokeFunction(functionDef, input);
|
|
343
|
+
}).pipe(Effect.provide(TracingService.layerNoop)));
|
|
372
344
|
return result;
|
|
373
345
|
};
|
|
374
346
|
return this.runAsyncFunction(ast, state, handler(true), {
|
|
@@ -2806,29 +2778,16 @@ var defaultFunctions = [
|
|
|
2806
2778
|
|
|
2807
2779
|
// src/compute-graph.ts
|
|
2808
2780
|
import { Event as Event2 } from "@dxos/async";
|
|
2809
|
-
import { Filter as Filter2
|
|
2781
|
+
import { Filter as Filter2 } from "@dxos/client/echo";
|
|
2810
2782
|
import { FQ_ID_LENGTH } from "@dxos/client/echo";
|
|
2811
2783
|
import { Resource as Resource2 } from "@dxos/context";
|
|
2812
|
-
import {
|
|
2813
|
-
import {
|
|
2784
|
+
import { Obj as Obj2 } from "@dxos/echo";
|
|
2785
|
+
import { Function as Function2 } from "@dxos/functions";
|
|
2814
2786
|
import { invariant as invariant2 } from "@dxos/invariant";
|
|
2815
2787
|
import { PublicKey } from "@dxos/keys";
|
|
2816
2788
|
import { log as log3 } from "@dxos/log";
|
|
2817
2789
|
import { isNonNullable as isNonNullable2 } from "@dxos/util";
|
|
2818
2790
|
import { ExportedCellChange as ExportedCellChange2 } from "@dxos/vendor-hyperformula";
|
|
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
|
-
}
|
|
2832
2791
|
var __dxlog_file4 = "/__w/dxos/dxos/packages/core/compute/src/compute-graph.ts";
|
|
2833
2792
|
var UNKNOWN_BINDING = "__UNKNOWN__";
|
|
2834
2793
|
var createSheetName = ({ type, id }) => `${type}@${id}`;
|
|
@@ -2842,6 +2801,49 @@ var parseSheetName = (name) => {
|
|
|
2842
2801
|
};
|
|
2843
2802
|
};
|
|
2844
2803
|
var ComputeGraph = class extends Resource2 {
|
|
2804
|
+
_hf;
|
|
2805
|
+
_runtime;
|
|
2806
|
+
_space;
|
|
2807
|
+
_options;
|
|
2808
|
+
id = `graph-${PublicKey.random().truncate()}`;
|
|
2809
|
+
// Map of nodes indexed by sheet number.
|
|
2810
|
+
_nodes = /* @__PURE__ */ new Map();
|
|
2811
|
+
// Cached function objects.
|
|
2812
|
+
_remoteFunctions = [];
|
|
2813
|
+
update = new Event2();
|
|
2814
|
+
// The context is passed to all functions.
|
|
2815
|
+
context;
|
|
2816
|
+
constructor(_hf, _runtime, _space, _options) {
|
|
2817
|
+
super(), this._hf = _hf, this._runtime = _runtime, this._space = _space, this._options = _options;
|
|
2818
|
+
this.context = new FunctionContext(this._hf, this._runtime, this._space, {
|
|
2819
|
+
...this._options,
|
|
2820
|
+
onUpdate: (update) => {
|
|
2821
|
+
this._options?.onUpdate?.(update);
|
|
2822
|
+
this.update.emit({
|
|
2823
|
+
type: "valuesUpdated"
|
|
2824
|
+
});
|
|
2825
|
+
}
|
|
2826
|
+
});
|
|
2827
|
+
this._hf.updateConfig({
|
|
2828
|
+
context: this.context
|
|
2829
|
+
});
|
|
2830
|
+
const onValuesUpdate = (changes) => {
|
|
2831
|
+
for (const change of changes) {
|
|
2832
|
+
if (change instanceof ExportedCellChange2) {
|
|
2833
|
+
const { sheet } = change;
|
|
2834
|
+
const node = this._nodes.get(sheet);
|
|
2835
|
+
if (node) {
|
|
2836
|
+
node.update.emit({
|
|
2837
|
+
type: "valuesUpdated",
|
|
2838
|
+
change
|
|
2839
|
+
});
|
|
2840
|
+
}
|
|
2841
|
+
}
|
|
2842
|
+
}
|
|
2843
|
+
};
|
|
2844
|
+
this._hf.on("valuesUpdated", onValuesUpdate);
|
|
2845
|
+
this._ctx.onDispose(() => this._hf.off("valuesUpdated", onValuesUpdate));
|
|
2846
|
+
}
|
|
2845
2847
|
get hf() {
|
|
2846
2848
|
return this._hf;
|
|
2847
2849
|
}
|
|
@@ -2869,7 +2871,7 @@ var ComputeGraph = class extends Resource2 {
|
|
|
2869
2871
|
getOrCreateNode(name) {
|
|
2870
2872
|
invariant2(name.length, void 0, {
|
|
2871
2873
|
F: __dxlog_file4,
|
|
2872
|
-
L:
|
|
2874
|
+
L: 133,
|
|
2873
2875
|
S: this,
|
|
2874
2876
|
A: [
|
|
2875
2877
|
"name.length",
|
|
@@ -2882,7 +2884,7 @@ var ComputeGraph = class extends Resource2 {
|
|
|
2882
2884
|
sheet: name
|
|
2883
2885
|
}, {
|
|
2884
2886
|
F: __dxlog_file4,
|
|
2885
|
-
L:
|
|
2887
|
+
L: 135,
|
|
2886
2888
|
S: this,
|
|
2887
2889
|
C: (f, a) => f(...a)
|
|
2888
2890
|
});
|
|
@@ -2891,7 +2893,7 @@ var ComputeGraph = class extends Resource2 {
|
|
|
2891
2893
|
const sheetId = this._hf.getSheetId(name);
|
|
2892
2894
|
invariant2(sheetId !== void 0, void 0, {
|
|
2893
2895
|
F: __dxlog_file4,
|
|
2894
|
-
L:
|
|
2896
|
+
L: 140,
|
|
2895
2897
|
S: this,
|
|
2896
2898
|
A: [
|
|
2897
2899
|
"sheetId !== undefined",
|
|
@@ -2915,7 +2917,7 @@ var ComputeGraph = class extends Resource2 {
|
|
|
2915
2917
|
}).filter(isNonNullable2);
|
|
2916
2918
|
for (const obj of objects) {
|
|
2917
2919
|
if (obj.name === name) {
|
|
2918
|
-
const type = getTypename(obj);
|
|
2920
|
+
const type = Obj2.getTypename(obj);
|
|
2919
2921
|
return `'${createSheetName({
|
|
2920
2922
|
type,
|
|
2921
2923
|
id: obj.id
|
|
@@ -2947,7 +2949,7 @@ var ComputeGraph = class extends Resource2 {
|
|
|
2947
2949
|
}
|
|
2948
2950
|
const fn = this._remoteFunctions.find((fn2) => fn2.binding === binding);
|
|
2949
2951
|
if (fn) {
|
|
2950
|
-
const id =
|
|
2952
|
+
const id = Obj2.getDXN(fn).toString();
|
|
2951
2953
|
return `${id}(${args})`;
|
|
2952
2954
|
} else {
|
|
2953
2955
|
return match;
|
|
@@ -2964,7 +2966,7 @@ var ComputeGraph = class extends Resource2 {
|
|
|
2964
2966
|
if (id.length !== FQ_ID_LENGTH) {
|
|
2965
2967
|
return match;
|
|
2966
2968
|
}
|
|
2967
|
-
const fn = this._remoteFunctions.find((fn2) =>
|
|
2969
|
+
const fn = this._remoteFunctions.find((fn2) => Obj2.getDXN(fn2).toString() === id);
|
|
2968
2970
|
if (fn?.binding) {
|
|
2969
2971
|
return `${fn.binding}(${args})`;
|
|
2970
2972
|
} else {
|
|
@@ -2979,9 +2981,9 @@ var ComputeGraph = class extends Resource2 {
|
|
|
2979
2981
|
}
|
|
2980
2982
|
async _open() {
|
|
2981
2983
|
if (this._space) {
|
|
2982
|
-
const query = this._space.db.query(Filter2.type(
|
|
2983
|
-
const unsubscribe = query.subscribe((
|
|
2984
|
-
this._remoteFunctions =
|
|
2984
|
+
const query = this._space.db.query(Filter2.type(Function2.Function));
|
|
2985
|
+
const unsubscribe = query.subscribe(() => {
|
|
2986
|
+
this._remoteFunctions = query.results.filter((fn) => fn.binding);
|
|
2985
2987
|
this.update.emit({
|
|
2986
2988
|
type: "functionsUpdated"
|
|
2987
2989
|
});
|
|
@@ -2994,40 +2996,6 @@ var ComputeGraph = class extends Resource2 {
|
|
|
2994
2996
|
await node.close();
|
|
2995
2997
|
}
|
|
2996
2998
|
}
|
|
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
2999
|
};
|
|
3032
3000
|
|
|
3033
3001
|
// src/compute-graph-registry.ts
|
|
@@ -3036,30 +3004,27 @@ import { Resource as Resource3 } from "@dxos/context";
|
|
|
3036
3004
|
import { invariant as invariant3 } from "@dxos/invariant";
|
|
3037
3005
|
import { log as log4 } from "@dxos/log";
|
|
3038
3006
|
import { HyperFormula } from "@dxos/vendor-hyperformula";
|
|
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
|
-
}
|
|
3052
3007
|
var __dxlog_file5 = "/__w/dxos/dxos/packages/core/compute/src/compute-graph-registry.ts";
|
|
3053
|
-
var defaultOptions = {
|
|
3054
|
-
licenseKey: "gpl-v3"
|
|
3055
|
-
};
|
|
3056
3008
|
var defaultPlugins = [
|
|
3057
3009
|
{
|
|
3058
3010
|
plugin: EdgeFunctionPlugin,
|
|
3059
3011
|
translations: EdgeFunctionPluginTranslations
|
|
3060
3012
|
}
|
|
3061
3013
|
];
|
|
3014
|
+
var defaultOptions = {
|
|
3015
|
+
licenseKey: "gpl-v3"
|
|
3016
|
+
};
|
|
3062
3017
|
var ComputeGraphRegistry = class extends Resource3 {
|
|
3018
|
+
_graphs = /* @__PURE__ */ new Map();
|
|
3019
|
+
_options;
|
|
3020
|
+
constructor(options) {
|
|
3021
|
+
super();
|
|
3022
|
+
this._options = defaultsDeep2({}, options, defaultOptions);
|
|
3023
|
+
this._options.plugins = this._options.plugins ?? defaultPlugins;
|
|
3024
|
+
this._options.plugins?.forEach(({ plugin, translations }) => {
|
|
3025
|
+
HyperFormula.registerFunctionPlugin(plugin, translations);
|
|
3026
|
+
});
|
|
3027
|
+
}
|
|
3063
3028
|
getGraph(spaceId) {
|
|
3064
3029
|
return this._graphs.get(spaceId);
|
|
3065
3030
|
}
|
|
@@ -3070,7 +3035,7 @@ var ComputeGraphRegistry = class extends Resource3 {
|
|
|
3070
3035
|
space: space.id
|
|
3071
3036
|
}, {
|
|
3072
3037
|
F: __dxlog_file5,
|
|
3073
|
-
L:
|
|
3038
|
+
L: 73,
|
|
3074
3039
|
S: this,
|
|
3075
3040
|
C: (f, a) => f(...a)
|
|
3076
3041
|
});
|
|
@@ -3081,7 +3046,7 @@ var ComputeGraphRegistry = class extends Resource3 {
|
|
|
3081
3046
|
createGraph(space) {
|
|
3082
3047
|
invariant3(!this._graphs.has(space.id), `ComputeGraph already exists for space: ${space.id}`, {
|
|
3083
3048
|
F: __dxlog_file5,
|
|
3084
|
-
L:
|
|
3049
|
+
L: 81,
|
|
3085
3050
|
S: this,
|
|
3086
3051
|
A: [
|
|
3087
3052
|
"!this._graphs.has(space.id)",
|
|
@@ -3089,7 +3054,17 @@ var ComputeGraphRegistry = class extends Resource3 {
|
|
|
3089
3054
|
]
|
|
3090
3055
|
});
|
|
3091
3056
|
const hf = HyperFormula.buildEmpty(this._options);
|
|
3092
|
-
|
|
3057
|
+
invariant3(this._options.computeRuntime, "ComputeRuntime is required", {
|
|
3058
|
+
F: __dxlog_file5,
|
|
3059
|
+
L: 83,
|
|
3060
|
+
S: this,
|
|
3061
|
+
A: [
|
|
3062
|
+
"this._options.computeRuntime",
|
|
3063
|
+
"'ComputeRuntime is required'"
|
|
3064
|
+
]
|
|
3065
|
+
});
|
|
3066
|
+
const runtime = this._options.computeRuntime.getRuntime(space.id);
|
|
3067
|
+
const graph = new ComputeGraph(hf, runtime, space, this._options);
|
|
3093
3068
|
this._graphs.set(space.id, graph);
|
|
3094
3069
|
return graph;
|
|
3095
3070
|
}
|
|
@@ -3099,15 +3074,6 @@ var ComputeGraphRegistry = class extends Resource3 {
|
|
|
3099
3074
|
}
|
|
3100
3075
|
this._graphs.clear();
|
|
3101
3076
|
}
|
|
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
3077
|
};
|
|
3112
3078
|
|
|
3113
3079
|
export {
|
|
@@ -3133,8 +3099,8 @@ export {
|
|
|
3133
3099
|
createSheetName,
|
|
3134
3100
|
parseSheetName,
|
|
3135
3101
|
ComputeGraph,
|
|
3136
|
-
defaultOptions,
|
|
3137
3102
|
defaultPlugins,
|
|
3103
|
+
defaultOptions,
|
|
3138
3104
|
ComputeGraphRegistry
|
|
3139
3105
|
};
|
|
3140
|
-
//# sourceMappingURL=chunk-
|
|
3106
|
+
//# sourceMappingURL=chunk-KGBGT4NT.mjs.map
|