@dxos/compute 0.8.4-main.dedc0f3 → 0.8.4-main.ead640a
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 → chunk-C7KLV2IU.mjs} +60 -56
- package/dist/lib/browser/chunk-C7KLV2IU.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +1 -1
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/testing/index.mjs +24 -4
- package/dist/lib/browser/testing/index.mjs.map +4 -4
- package/dist/lib/node-esm/{chunk-2XWWSGAU.mjs → chunk-K37OSZ5O.mjs} +60 -56
- package/dist/lib/node-esm/chunk-K37OSZ5O.mjs.map +7 -0
- package/dist/lib/node-esm/index.mjs +1 -1
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/lib/node-esm/testing/index.mjs +24 -4
- package/dist/lib/node-esm/testing/index.mjs.map +4 -4
- 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/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 +22 -22
- package/src/compute-graph-registry.test.ts +138 -0
- package/src/compute-graph-registry.ts +17 -8
- package/src/compute-graph.ts +7 -4
- package/src/functions/async-function.ts +13 -12
- package/src/functions/edge-function.ts +21 -18
- package/src/testing/index.ts +1 -0
- package/src/testing/test-builder.ts +8 -2
- package/src/testing/test-runtime.ts +38 -0
- package/dist/lib/browser/chunk-XQYPCRZP.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-2XWWSGAU.mjs.map +0 -7
|
@@ -150,8 +150,7 @@ function _define_property2(obj, key, value) {
|
|
|
150
150
|
var __dxlog_file2 = "/__w/dxos/dxos/packages/core/compute/src/functions/async-function.ts";
|
|
151
151
|
var defaultFunctionContextOptions = {
|
|
152
152
|
defaultTtl: 5e3,
|
|
153
|
-
debounceDelay: 200
|
|
154
|
-
remoteFunctionUrl: "https://edge.dxos.workers.dev/functions"
|
|
153
|
+
debounceDelay: 200
|
|
155
154
|
};
|
|
156
155
|
var FunctionContext = class _FunctionContext {
|
|
157
156
|
// Mangle name with params.
|
|
@@ -164,15 +163,15 @@ var FunctionContext = class _FunctionContext {
|
|
|
164
163
|
get space() {
|
|
165
164
|
return this._space;
|
|
166
165
|
}
|
|
167
|
-
get remoteFunctionUrl() {
|
|
168
|
-
return this._options.remoteFunctionUrl;
|
|
169
|
-
}
|
|
170
166
|
get info() {
|
|
171
167
|
return {
|
|
172
168
|
cache: this._cache.size,
|
|
173
169
|
invocations: this._invocations
|
|
174
170
|
};
|
|
175
171
|
}
|
|
172
|
+
get runtime() {
|
|
173
|
+
return this._runtime;
|
|
174
|
+
}
|
|
176
175
|
flush() {
|
|
177
176
|
this._cache.clear();
|
|
178
177
|
this._invocations = {};
|
|
@@ -209,7 +208,7 @@ var FunctionContext = class _FunctionContext {
|
|
|
209
208
|
value: value2
|
|
210
209
|
}, {
|
|
211
210
|
F: __dxlog_file2,
|
|
212
|
-
L:
|
|
211
|
+
L: 144,
|
|
213
212
|
S: this,
|
|
214
213
|
C: (f, a) => f(...a)
|
|
215
214
|
});
|
|
@@ -223,7 +222,7 @@ var FunctionContext = class _FunctionContext {
|
|
|
223
222
|
err
|
|
224
223
|
}, {
|
|
225
224
|
F: __dxlog_file2,
|
|
226
|
-
L:
|
|
225
|
+
L: 148,
|
|
227
226
|
S: this,
|
|
228
227
|
C: (f, a) => f(...a)
|
|
229
228
|
});
|
|
@@ -243,14 +242,15 @@ var FunctionContext = class _FunctionContext {
|
|
|
243
242
|
cache: value
|
|
244
243
|
}, {
|
|
245
244
|
F: __dxlog_file2,
|
|
246
|
-
L:
|
|
245
|
+
L: 156,
|
|
247
246
|
S: this,
|
|
248
247
|
C: (f, a) => f(...a)
|
|
249
248
|
});
|
|
250
249
|
return value;
|
|
251
250
|
}
|
|
252
|
-
constructor(_hf, _space, _options) {
|
|
251
|
+
constructor(_hf, _runtime, _space, _options) {
|
|
253
252
|
_define_property2(this, "_hf", void 0);
|
|
253
|
+
_define_property2(this, "_runtime", void 0);
|
|
254
254
|
_define_property2(this, "_space", void 0);
|
|
255
255
|
_define_property2(this, "_cache", void 0);
|
|
256
256
|
_define_property2(this, "_pending", void 0);
|
|
@@ -259,6 +259,7 @@ var FunctionContext = class _FunctionContext {
|
|
|
259
259
|
_define_property2(this, "_options", void 0);
|
|
260
260
|
_define_property2(this, "_onUpdate", void 0);
|
|
261
261
|
this._hf = _hf;
|
|
262
|
+
this._runtime = _runtime;
|
|
262
263
|
this._space = _space;
|
|
263
264
|
this._cache = /* @__PURE__ */ new Map();
|
|
264
265
|
this._pending = /* @__PURE__ */ new Map();
|
|
@@ -268,7 +269,7 @@ var FunctionContext = class _FunctionContext {
|
|
|
268
269
|
this._onUpdate = debounce((update) => {
|
|
269
270
|
log("update", update, {
|
|
270
271
|
F: __dxlog_file2,
|
|
271
|
-
L:
|
|
272
|
+
L: 86,
|
|
272
273
|
S: this,
|
|
273
274
|
C: (f, a) => f(...a)
|
|
274
275
|
});
|
|
@@ -295,10 +296,12 @@ var AsyncFunctionPlugin = class extends FunctionPlugin {
|
|
|
295
296
|
|
|
296
297
|
// src/functions/edge-function.ts
|
|
297
298
|
import { effect } from "@preact/signals-core";
|
|
298
|
-
import
|
|
299
|
-
import
|
|
300
|
-
import {
|
|
301
|
-
import {
|
|
299
|
+
import * as Effect from "effect/Effect";
|
|
300
|
+
import * as SchemaAST from "effect/SchemaAST";
|
|
301
|
+
import { Filter } from "@dxos/client/echo";
|
|
302
|
+
import { toEffectSchema } from "@dxos/echo/internal";
|
|
303
|
+
import { ComputeEventLogger, FunctionInvocationService, FunctionType, TracingService } from "@dxos/functions";
|
|
304
|
+
import { FunctionDefinition } from "@dxos/functions";
|
|
302
305
|
import { log as log2 } from "@dxos/log";
|
|
303
306
|
import { isNonNullable } from "@dxos/util";
|
|
304
307
|
import { CellError as CellError2, ErrorType as ErrorType2, FunctionArgumentType } from "@dxos/vendor-hyperformula";
|
|
@@ -320,7 +323,7 @@ var EdgeFunctionPlugin = class extends AsyncFunctionPlugin {
|
|
|
320
323
|
binding
|
|
321
324
|
}, {
|
|
322
325
|
F: __dxlog_file3,
|
|
323
|
-
L:
|
|
326
|
+
L: 43,
|
|
324
327
|
S: this,
|
|
325
328
|
C: (f, a) => f(...a)
|
|
326
329
|
});
|
|
@@ -332,7 +335,7 @@ var EdgeFunctionPlugin = class extends AsyncFunctionPlugin {
|
|
|
332
335
|
fn
|
|
333
336
|
}, {
|
|
334
337
|
F: __dxlog_file3,
|
|
335
|
-
L:
|
|
338
|
+
L: 49,
|
|
336
339
|
S: this,
|
|
337
340
|
C: (f, a) => f(...a)
|
|
338
341
|
});
|
|
@@ -343,32 +346,24 @@ var EdgeFunctionPlugin = class extends AsyncFunctionPlugin {
|
|
|
343
346
|
});
|
|
344
347
|
this.context.createSubscription(ast.procedureName, unsubscribe);
|
|
345
348
|
}
|
|
346
|
-
const
|
|
349
|
+
const runtime = this.context.runtime;
|
|
350
|
+
const functionDef = FunctionDefinition.deserialize(fn);
|
|
351
|
+
let input;
|
|
347
352
|
if (fn.inputSchema) {
|
|
348
353
|
const schema = toEffectSchema(fn.inputSchema);
|
|
349
|
-
SchemaAST.getPropertySignatures(schema.ast)
|
|
350
|
-
|
|
354
|
+
const props = SchemaAST.getPropertySignatures(schema.ast);
|
|
355
|
+
input = {};
|
|
356
|
+
props.forEach(({ name }, index) => {
|
|
357
|
+
input[name.toString()] = args[index];
|
|
351
358
|
});
|
|
352
359
|
} else {
|
|
353
|
-
|
|
360
|
+
input = {
|
|
361
|
+
args: args.filter(isNonNullable)
|
|
362
|
+
};
|
|
354
363
|
}
|
|
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
|
-
});
|
|
364
|
+
const result = runtime.runPromise(Effect.gen(function* () {
|
|
365
|
+
return yield* FunctionInvocationService.invokeFunction(functionDef, input);
|
|
366
|
+
}).pipe(Effect.provide(ComputeEventLogger.layerFromTracing), Effect.provide(TracingService.layerNoop)));
|
|
372
367
|
return result;
|
|
373
368
|
};
|
|
374
369
|
return this.runAsyncFunction(ast, state, handler(true), {
|
|
@@ -2809,7 +2804,7 @@ import { Event as Event2 } from "@dxos/async";
|
|
|
2809
2804
|
import { Filter as Filter2, fullyQualifiedId } from "@dxos/client/echo";
|
|
2810
2805
|
import { FQ_ID_LENGTH } from "@dxos/client/echo";
|
|
2811
2806
|
import { Resource as Resource2 } from "@dxos/context";
|
|
2812
|
-
import { getTypename } from "@dxos/echo
|
|
2807
|
+
import { getTypename } from "@dxos/echo/internal";
|
|
2813
2808
|
import { FunctionType as FunctionType2 } from "@dxos/functions";
|
|
2814
2809
|
import { invariant as invariant2 } from "@dxos/invariant";
|
|
2815
2810
|
import { PublicKey } from "@dxos/keys";
|
|
@@ -2869,7 +2864,7 @@ var ComputeGraph = class extends Resource2 {
|
|
|
2869
2864
|
getOrCreateNode(name) {
|
|
2870
2865
|
invariant2(name.length, void 0, {
|
|
2871
2866
|
F: __dxlog_file4,
|
|
2872
|
-
L:
|
|
2867
|
+
L: 130,
|
|
2873
2868
|
S: this,
|
|
2874
2869
|
A: [
|
|
2875
2870
|
"name.length",
|
|
@@ -2882,7 +2877,7 @@ var ComputeGraph = class extends Resource2 {
|
|
|
2882
2877
|
sheet: name
|
|
2883
2878
|
}, {
|
|
2884
2879
|
F: __dxlog_file4,
|
|
2885
|
-
L:
|
|
2880
|
+
L: 132,
|
|
2886
2881
|
S: this,
|
|
2887
2882
|
C: (f, a) => f(...a)
|
|
2888
2883
|
});
|
|
@@ -2891,7 +2886,7 @@ var ComputeGraph = class extends Resource2 {
|
|
|
2891
2886
|
const sheetId = this._hf.getSheetId(name);
|
|
2892
2887
|
invariant2(sheetId !== void 0, void 0, {
|
|
2893
2888
|
F: __dxlog_file4,
|
|
2894
|
-
L:
|
|
2889
|
+
L: 137,
|
|
2895
2890
|
S: this,
|
|
2896
2891
|
A: [
|
|
2897
2892
|
"sheetId !== undefined",
|
|
@@ -2994,12 +2989,12 @@ var ComputeGraph = class extends Resource2 {
|
|
|
2994
2989
|
await node.close();
|
|
2995
2990
|
}
|
|
2996
2991
|
}
|
|
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.
|
|
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.
|
|
2999
2994
|
_define_property3(this, "_nodes", void 0), // Cached function objects.
|
|
3000
2995
|
_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, {
|
|
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, {
|
|
3003
2998
|
...this._options,
|
|
3004
2999
|
onUpdate: (update) => {
|
|
3005
3000
|
this._options?.onUpdate?.(update);
|
|
@@ -3050,15 +3045,15 @@ function _define_property4(obj, key, value) {
|
|
|
3050
3045
|
return obj;
|
|
3051
3046
|
}
|
|
3052
3047
|
var __dxlog_file5 = "/__w/dxos/dxos/packages/core/compute/src/compute-graph-registry.ts";
|
|
3053
|
-
var defaultOptions = {
|
|
3054
|
-
licenseKey: "gpl-v3"
|
|
3055
|
-
};
|
|
3056
3048
|
var defaultPlugins = [
|
|
3057
3049
|
{
|
|
3058
3050
|
plugin: EdgeFunctionPlugin,
|
|
3059
3051
|
translations: EdgeFunctionPluginTranslations
|
|
3060
3052
|
}
|
|
3061
3053
|
];
|
|
3054
|
+
var defaultOptions = {
|
|
3055
|
+
licenseKey: "gpl-v3"
|
|
3056
|
+
};
|
|
3062
3057
|
var ComputeGraphRegistry = class extends Resource3 {
|
|
3063
3058
|
getGraph(spaceId) {
|
|
3064
3059
|
return this._graphs.get(spaceId);
|
|
@@ -3070,7 +3065,7 @@ var ComputeGraphRegistry = class extends Resource3 {
|
|
|
3070
3065
|
space: space.id
|
|
3071
3066
|
}, {
|
|
3072
3067
|
F: __dxlog_file5,
|
|
3073
|
-
L:
|
|
3068
|
+
L: 73,
|
|
3074
3069
|
S: this,
|
|
3075
3070
|
C: (f, a) => f(...a)
|
|
3076
3071
|
});
|
|
@@ -3081,7 +3076,7 @@ var ComputeGraphRegistry = class extends Resource3 {
|
|
|
3081
3076
|
createGraph(space) {
|
|
3082
3077
|
invariant3(!this._graphs.has(space.id), `ComputeGraph already exists for space: ${space.id}`, {
|
|
3083
3078
|
F: __dxlog_file5,
|
|
3084
|
-
L:
|
|
3079
|
+
L: 81,
|
|
3085
3080
|
S: this,
|
|
3086
3081
|
A: [
|
|
3087
3082
|
"!this._graphs.has(space.id)",
|
|
@@ -3089,7 +3084,17 @@ var ComputeGraphRegistry = class extends Resource3 {
|
|
|
3089
3084
|
]
|
|
3090
3085
|
});
|
|
3091
3086
|
const hf = HyperFormula.buildEmpty(this._options);
|
|
3092
|
-
|
|
3087
|
+
invariant3(this._options.computeRuntime, "ComputeRuntime is required", {
|
|
3088
|
+
F: __dxlog_file5,
|
|
3089
|
+
L: 83,
|
|
3090
|
+
S: this,
|
|
3091
|
+
A: [
|
|
3092
|
+
"this._options.computeRuntime",
|
|
3093
|
+
"'ComputeRuntime is required'"
|
|
3094
|
+
]
|
|
3095
|
+
});
|
|
3096
|
+
const runtime = this._options.computeRuntime.getRuntime(space.id);
|
|
3097
|
+
const graph = new ComputeGraph(hf, runtime, space, this._options);
|
|
3093
3098
|
this._graphs.set(space.id, graph);
|
|
3094
3099
|
return graph;
|
|
3095
3100
|
}
|
|
@@ -3099,11 +3104,10 @@ var ComputeGraphRegistry = class extends Resource3 {
|
|
|
3099
3104
|
}
|
|
3100
3105
|
this._graphs.clear();
|
|
3101
3106
|
}
|
|
3102
|
-
constructor(options
|
|
3103
|
-
plugins: defaultPlugins
|
|
3104
|
-
}) {
|
|
3107
|
+
constructor(options) {
|
|
3105
3108
|
super(), _define_property4(this, "_graphs", /* @__PURE__ */ new Map()), _define_property4(this, "_options", void 0);
|
|
3106
3109
|
this._options = defaultsDeep2({}, options, defaultOptions);
|
|
3110
|
+
this._options.plugins = this._options.plugins ?? defaultPlugins;
|
|
3107
3111
|
this._options.plugins?.forEach(({ plugin, translations }) => {
|
|
3108
3112
|
HyperFormula.registerFunctionPlugin(plugin, translations);
|
|
3109
3113
|
});
|
|
@@ -3133,8 +3137,8 @@ export {
|
|
|
3133
3137
|
createSheetName,
|
|
3134
3138
|
parseSheetName,
|
|
3135
3139
|
ComputeGraph,
|
|
3136
|
-
defaultOptions,
|
|
3137
3140
|
defaultPlugins,
|
|
3141
|
+
defaultOptions,
|
|
3138
3142
|
ComputeGraphRegistry
|
|
3139
3143
|
};
|
|
3140
|
-
//# sourceMappingURL=chunk-
|
|
3144
|
+
//# sourceMappingURL=chunk-C7KLV2IU.mjs.map
|