@dxos/plugin-sheet 0.6.12-main.f9d0246 → 0.6.12-staging.e11e696
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/{SheetContainer-VISF3VUB.mjs → SheetContainer-LG77O4RM.mjs} +11 -10
- package/dist/lib/browser/SheetContainer-LG77O4RM.mjs.map +7 -0
- package/dist/lib/browser/{chunk-ZLJ2GRE2.mjs → chunk-CHQAW4F4.mjs} +55 -33
- package/dist/lib/browser/chunk-CHQAW4F4.mjs.map +7 -0
- package/dist/lib/browser/{chunk-Z2XOOC2R.mjs → chunk-GSV5QNLD.mjs} +183 -159
- package/dist/lib/browser/chunk-GSV5QNLD.mjs.map +7 -0
- package/dist/lib/browser/graph-M4IQ76QX.mjs +33 -0
- package/dist/lib/browser/index.mjs +37 -15
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node/{SheetContainer-2MEALQWW.cjs → SheetContainer-OZ7DHH4L.cjs} +18 -17
- package/dist/lib/node/SheetContainer-OZ7DHH4L.cjs.map +7 -0
- package/dist/lib/node/{chunk-6DQABRGJ.cjs → chunk-5FTFZL5W.cjs} +57 -35
- package/dist/lib/node/chunk-5FTFZL5W.cjs.map +7 -0
- package/dist/lib/node/{chunk-P5QYYEHQ.cjs → chunk-5XPK2V4A.cjs} +186 -158
- package/dist/lib/node/chunk-5XPK2V4A.cjs.map +7 -0
- package/dist/lib/node/graph-Q3N2X26H.cjs +55 -0
- package/dist/lib/node/graph-Q3N2X26H.cjs.map +7 -0
- package/dist/lib/node/index.cjs +38 -18
- package/dist/lib/node/index.cjs.map +4 -4
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node-esm/{SheetContainer-RPSUSXWS.mjs → SheetContainer-4XS2G25Z.mjs} +11 -10
- package/dist/lib/node-esm/SheetContainer-4XS2G25Z.mjs.map +7 -0
- package/dist/lib/node-esm/{chunk-4MM7THJW.mjs → chunk-5WPZCXNS.mjs} +183 -159
- package/dist/lib/node-esm/chunk-5WPZCXNS.mjs.map +7 -0
- package/dist/lib/node-esm/{chunk-5RLTCIE2.mjs → chunk-KK3XL37M.mjs} +55 -33
- package/dist/lib/node-esm/chunk-KK3XL37M.mjs.map +7 -0
- package/dist/lib/node-esm/graph-SMPUMOV2.mjs +34 -0
- package/dist/lib/node-esm/index.mjs +37 -15
- package/dist/lib/node-esm/index.mjs.map +4 -4
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/types/src/SheetPlugin.d.ts.map +1 -1
- package/dist/types/src/components/CellEditor/CellEditor.stories.d.ts.map +1 -1
- package/dist/types/src/components/CellEditor/extension.d.ts.map +1 -1
- package/dist/types/src/components/Sheet/Sheet.d.ts.map +1 -1
- package/dist/types/src/components/Sheet/Sheet.stories.d.ts.map +1 -1
- package/dist/types/src/components/SheetContainer.d.ts.map +1 -1
- package/dist/types/src/components/index.d.ts.map +1 -1
- package/dist/types/src/extensions/compute.d.ts +2 -5
- package/dist/types/src/extensions/compute.d.ts.map +1 -1
- package/dist/types/src/extensions/compute.stories.d.ts.map +1 -1
- package/dist/types/src/graph/compute-graph-registry.d.ts +34 -0
- package/dist/types/src/graph/compute-graph-registry.d.ts.map +1 -0
- package/dist/types/src/graph/compute-graph.d.ts +13 -33
- package/dist/types/src/graph/compute-graph.d.ts.map +1 -1
- package/dist/types/src/graph/compute-node.d.ts.map +1 -1
- package/dist/types/src/graph/{async-function.d.ts → functions/async-function.d.ts} +6 -3
- package/dist/types/src/graph/functions/async-function.d.ts.map +1 -0
- package/dist/types/src/graph/functions/edge-function.d.ts +21 -0
- package/dist/types/src/graph/functions/edge-function.d.ts.map +1 -0
- package/dist/types/src/graph/functions/function-defs.d.ts.map +1 -0
- package/dist/types/src/graph/functions/index.d.ts +4 -0
- package/dist/types/src/graph/functions/index.d.ts.map +1 -0
- package/dist/types/src/graph/index.d.ts +2 -1
- package/dist/types/src/graph/index.d.ts.map +1 -1
- package/dist/types/src/graph/testing/index.d.ts +2 -1
- package/dist/types/src/graph/testing/index.d.ts.map +1 -1
- package/dist/types/src/graph/testing/test-builder.d.ts +15 -0
- package/dist/types/src/graph/testing/test-builder.d.ts.map +1 -0
- package/dist/types/src/graph/testing/test-plugin.d.ts +36 -0
- package/dist/types/src/graph/testing/test-plugin.d.ts.map +1 -0
- package/dist/types/src/hooks/useComputeGraph.d.ts.map +1 -1
- package/dist/types/src/model/sheet-model.d.ts.map +1 -1
- package/dist/types/src/model/sheet-model.test.d.ts +2 -0
- package/dist/types/src/model/sheet-model.test.d.ts.map +1 -0
- package/package.json +40 -39
- package/src/SheetPlugin.tsx +12 -10
- package/src/components/CellEditor/CellEditor.stories.tsx +1 -2
- package/src/components/CellEditor/extension.test.ts +0 -1
- package/src/components/CellEditor/extension.ts +4 -3
- package/src/components/Sheet/Sheet.stories.tsx +2 -2
- package/src/components/Sheet/Sheet.tsx +30 -14
- package/src/components/SheetContainer.tsx +11 -13
- package/src/extensions/compute.stories.tsx +9 -11
- package/src/extensions/compute.ts +66 -50
- package/src/graph/compute-graph-registry.ts +90 -0
- package/src/graph/compute-graph.stories.tsx +2 -2
- package/src/graph/compute-graph.test.ts +31 -71
- package/src/graph/compute-graph.ts +45 -116
- package/src/graph/compute-node.ts +1 -0
- package/src/graph/{async-function.ts → functions/async-function.ts} +10 -9
- package/src/graph/{edge-function.ts → functions/edge-function.ts} +13 -11
- package/src/graph/functions/index.ts +7 -0
- package/src/graph/hyperformula.test.ts +1 -2
- package/src/graph/index.ts +2 -1
- package/src/graph/testing/index.ts +2 -1
- package/src/graph/testing/test-builder.ts +54 -0
- package/src/graph/testing/{custom-function.ts → test-plugin.ts} +38 -12
- package/src/hooks/useComputeGraph.ts +8 -1
- package/src/model/sheet-model.test.ts +59 -0
- package/src/model/sheet-model.ts +4 -2
- package/dist/lib/browser/SheetContainer-VISF3VUB.mjs.map +0 -7
- package/dist/lib/browser/chunk-Z2XOOC2R.mjs.map +0 -7
- package/dist/lib/browser/chunk-ZLJ2GRE2.mjs.map +0 -7
- package/dist/lib/browser/graph-4XFKIHRL.mjs +0 -21
- package/dist/lib/node/SheetContainer-2MEALQWW.cjs.map +0 -7
- package/dist/lib/node/chunk-6DQABRGJ.cjs.map +0 -7
- package/dist/lib/node/chunk-P5QYYEHQ.cjs.map +0 -7
- package/dist/lib/node/graph-2LRDUXBZ.cjs +0 -43
- package/dist/lib/node/graph-2LRDUXBZ.cjs.map +0 -7
- package/dist/lib/node-esm/SheetContainer-RPSUSXWS.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-4MM7THJW.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-5RLTCIE2.mjs.map +0 -7
- package/dist/lib/node-esm/graph-WG5EKOMO.mjs +0 -22
- package/dist/types/src/graph/async-function.d.ts.map +0 -1
- package/dist/types/src/graph/edge-function.d.ts +0 -20
- package/dist/types/src/graph/edge-function.d.ts.map +0 -1
- package/dist/types/src/graph/function-defs.d.ts.map +0 -1
- package/dist/types/src/graph/testing/custom-function.d.ts +0 -23
- package/dist/types/src/graph/testing/custom-function.d.ts.map +0 -1
- /package/dist/lib/browser/{graph-4XFKIHRL.mjs.map → graph-M4IQ76QX.mjs.map} +0 -0
- /package/dist/lib/node-esm/{graph-WG5EKOMO.mjs.map → graph-SMPUMOV2.mjs.map} +0 -0
- /package/dist/types/src/graph/{function-defs.d.ts → functions/function-defs.d.ts} +0 -0
- /package/src/graph/{function-defs.ts → functions/function-defs.ts} +0 -0
|
@@ -1,26 +1,71 @@
|
|
|
1
1
|
import { createRequire } from 'node:module';const require = createRequire(import.meta.url);
|
|
2
2
|
|
|
3
3
|
// packages/plugins/plugin-sheet/src/graph/compute-graph.ts
|
|
4
|
-
import defaultsDeep2 from "lodash.defaultsdeep";
|
|
5
4
|
import { Event as Event2 } from "@dxos/async";
|
|
6
5
|
import { Filter as Filter2, fullyQualifiedId } from "@dxos/client/echo";
|
|
7
6
|
import { Resource as Resource2 } from "@dxos/context";
|
|
7
|
+
import { getTypename } from "@dxos/echo-schema";
|
|
8
8
|
import { invariant } from "@dxos/invariant";
|
|
9
9
|
import { PublicKey } from "@dxos/keys";
|
|
10
10
|
import { log as log3 } from "@dxos/log";
|
|
11
11
|
import { FunctionType as FunctionType2 } from "@dxos/plugin-script/types";
|
|
12
12
|
import { nonNullable as nonNullable2 } from "@dxos/util";
|
|
13
|
-
import { ExportedCellChange
|
|
13
|
+
import { ExportedCellChange } from "#hyperformula";
|
|
14
14
|
|
|
15
|
-
// packages/plugins/plugin-sheet/src/graph/
|
|
15
|
+
// packages/plugins/plugin-sheet/src/graph/compute-node.ts
|
|
16
|
+
import { Event } from "@dxos/async";
|
|
17
|
+
import { Resource } from "@dxos/context";
|
|
18
|
+
import { DetailedCellError } from "#hyperformula";
|
|
19
|
+
var ComputeNode = class extends Resource {
|
|
20
|
+
constructor(_graph, sheetId) {
|
|
21
|
+
super();
|
|
22
|
+
this._graph = _graph;
|
|
23
|
+
this.sheetId = sheetId;
|
|
24
|
+
this.update = new Event();
|
|
25
|
+
}
|
|
26
|
+
get graph() {
|
|
27
|
+
return this._graph;
|
|
28
|
+
}
|
|
29
|
+
clear() {
|
|
30
|
+
this._graph.hf.clearSheet(this.sheetId);
|
|
31
|
+
}
|
|
32
|
+
getValue(cell) {
|
|
33
|
+
const value = this._graph.hf.getCellValue({
|
|
34
|
+
sheet: this.sheetId,
|
|
35
|
+
row: cell.row,
|
|
36
|
+
col: cell.col
|
|
37
|
+
});
|
|
38
|
+
if (value instanceof DetailedCellError) {
|
|
39
|
+
return null;
|
|
40
|
+
}
|
|
41
|
+
return value;
|
|
42
|
+
}
|
|
43
|
+
setValue(cell, value) {
|
|
44
|
+
const mappedValue = typeof value === "string" && value.charAt(0) === "=" ? this._graph.mapFormulaToNative(value) : value;
|
|
45
|
+
this._graph.hf.setCellContents({
|
|
46
|
+
sheet: this.sheetId,
|
|
47
|
+
row: cell.row,
|
|
48
|
+
col: cell.col
|
|
49
|
+
}, [
|
|
50
|
+
[
|
|
51
|
+
mappedValue
|
|
52
|
+
]
|
|
53
|
+
]);
|
|
54
|
+
}
|
|
55
|
+
// TODO(burdon): Load data into sheet.
|
|
56
|
+
async _open() {
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
// packages/plugins/plugin-sheet/src/graph/functions/async-function.ts
|
|
16
61
|
import defaultsDeep from "lodash.defaultsdeep";
|
|
17
62
|
import { debounce } from "@dxos/async";
|
|
18
63
|
import { log } from "@dxos/log";
|
|
19
64
|
import { CellError, ErrorType, EmptyValue, FunctionPlugin } from "#hyperformula";
|
|
20
|
-
var __dxlog_file = "/home/runner/work/dxos/dxos/packages/plugins/plugin-sheet/src/graph/async-function.ts";
|
|
65
|
+
var __dxlog_file = "/home/runner/work/dxos/dxos/packages/plugins/plugin-sheet/src/graph/functions/async-function.ts";
|
|
21
66
|
var defaultFunctionContextOptions = {
|
|
22
67
|
defaultTtl: 5e3,
|
|
23
|
-
|
|
68
|
+
debounceDelay: 200,
|
|
24
69
|
remoteFunctionUrl: "https://edge.dxos.workers.dev/functions"
|
|
25
70
|
};
|
|
26
71
|
var FunctionContext = class _FunctionContext {
|
|
@@ -42,7 +87,7 @@ var FunctionContext = class _FunctionContext {
|
|
|
42
87
|
this._onUpdate = debounce((update) => {
|
|
43
88
|
this._hf.resumeEvaluation();
|
|
44
89
|
this._options.onUpdate?.(update);
|
|
45
|
-
}, this._options.
|
|
90
|
+
}, this._options.debounceDelay);
|
|
46
91
|
}
|
|
47
92
|
get space() {
|
|
48
93
|
return this._space;
|
|
@@ -92,7 +137,7 @@ var FunctionContext = class _FunctionContext {
|
|
|
92
137
|
value: value2
|
|
93
138
|
}, {
|
|
94
139
|
F: __dxlog_file,
|
|
95
|
-
L:
|
|
140
|
+
L: 143,
|
|
96
141
|
S: this,
|
|
97
142
|
C: (f, a) => f(...a)
|
|
98
143
|
});
|
|
@@ -106,7 +151,7 @@ var FunctionContext = class _FunctionContext {
|
|
|
106
151
|
err
|
|
107
152
|
}, {
|
|
108
153
|
F: __dxlog_file,
|
|
109
|
-
L:
|
|
154
|
+
L: 147,
|
|
110
155
|
S: this,
|
|
111
156
|
C: (f, a) => f(...a)
|
|
112
157
|
});
|
|
@@ -126,17 +171,20 @@ var FunctionContext = class _FunctionContext {
|
|
|
126
171
|
cache: value
|
|
127
172
|
}, {
|
|
128
173
|
F: __dxlog_file,
|
|
129
|
-
L:
|
|
174
|
+
L: 155,
|
|
130
175
|
S: this,
|
|
131
176
|
C: (f, a) => f(...a)
|
|
132
177
|
});
|
|
133
178
|
return value;
|
|
134
179
|
}
|
|
135
180
|
};
|
|
136
|
-
var
|
|
181
|
+
var AsyncFunctionPlugin = class extends FunctionPlugin {
|
|
137
182
|
get context() {
|
|
138
183
|
return this.config.context;
|
|
139
184
|
}
|
|
185
|
+
/**
|
|
186
|
+
* Immediately returns cached value then runs the async function.
|
|
187
|
+
*/
|
|
140
188
|
runAsyncFunction(ast, state, cb, options) {
|
|
141
189
|
const { procedureName } = ast;
|
|
142
190
|
const metadata = this.metadata(procedureName);
|
|
@@ -146,51 +194,7 @@ var FunctionPluginAsync = class extends FunctionPlugin {
|
|
|
146
194
|
}
|
|
147
195
|
};
|
|
148
196
|
|
|
149
|
-
// packages/plugins/plugin-sheet/src/graph/
|
|
150
|
-
import { Event } from "@dxos/async";
|
|
151
|
-
import { Resource } from "@dxos/context";
|
|
152
|
-
import { DetailedCellError } from "#hyperformula";
|
|
153
|
-
var ComputeNode = class extends Resource {
|
|
154
|
-
constructor(_graph, sheetId) {
|
|
155
|
-
super();
|
|
156
|
-
this._graph = _graph;
|
|
157
|
-
this.sheetId = sheetId;
|
|
158
|
-
this.update = new Event();
|
|
159
|
-
}
|
|
160
|
-
get graph() {
|
|
161
|
-
return this._graph;
|
|
162
|
-
}
|
|
163
|
-
clear() {
|
|
164
|
-
this._graph.hf.clearSheet(this.sheetId);
|
|
165
|
-
}
|
|
166
|
-
getValue(cell) {
|
|
167
|
-
const value = this._graph.hf.getCellValue({
|
|
168
|
-
sheet: this.sheetId,
|
|
169
|
-
row: cell.row,
|
|
170
|
-
col: cell.col
|
|
171
|
-
});
|
|
172
|
-
if (value instanceof DetailedCellError) {
|
|
173
|
-
return null;
|
|
174
|
-
}
|
|
175
|
-
return value;
|
|
176
|
-
}
|
|
177
|
-
setValue(cell, value) {
|
|
178
|
-
const mappedValue = typeof value === "string" && value.charAt(0) === "=" ? this._graph.mapFormulaToNative(value) : value;
|
|
179
|
-
this._graph.hf.setCellContents({
|
|
180
|
-
sheet: this.sheetId,
|
|
181
|
-
row: cell.row,
|
|
182
|
-
col: cell.col
|
|
183
|
-
}, [
|
|
184
|
-
[
|
|
185
|
-
mappedValue
|
|
186
|
-
]
|
|
187
|
-
]);
|
|
188
|
-
}
|
|
189
|
-
async _open() {
|
|
190
|
-
}
|
|
191
|
-
};
|
|
192
|
-
|
|
193
|
-
// packages/plugins/plugin-sheet/src/graph/edge-function.ts
|
|
197
|
+
// packages/plugins/plugin-sheet/src/graph/functions/edge-function.ts
|
|
194
198
|
import { effect } from "@preact/signals-core";
|
|
195
199
|
import { Filter, getMeta } from "@dxos/client/echo";
|
|
196
200
|
import { log as log2 } from "@dxos/log";
|
|
@@ -198,10 +202,11 @@ import { getUserFunctionUrlInMetadata } from "@dxos/plugin-script/edge";
|
|
|
198
202
|
import { FunctionType } from "@dxos/plugin-script/types";
|
|
199
203
|
import { nonNullable } from "@dxos/util";
|
|
200
204
|
import { CellError as CellError2, ErrorType as ErrorType2, FunctionArgumentType } from "#hyperformula";
|
|
201
|
-
var __dxlog_file2 = "/home/runner/work/dxos/dxos/packages/plugins/plugin-sheet/src/graph/edge-function.ts";
|
|
202
|
-
var
|
|
203
|
-
var
|
|
204
|
-
|
|
205
|
+
var __dxlog_file2 = "/home/runner/work/dxos/dxos/packages/plugins/plugin-sheet/src/graph/functions/edge-function.ts";
|
|
206
|
+
var EDGE_FUNCTION_NAME = "DX";
|
|
207
|
+
var FUNCTION_TTL = 1e4;
|
|
208
|
+
var EdgeFunctionPlugin = class extends AsyncFunctionPlugin {
|
|
209
|
+
dx(ast, state) {
|
|
205
210
|
const handler = (subscribe = false) => async (binding, ...args) => {
|
|
206
211
|
const space = this.context.space;
|
|
207
212
|
if (!space) {
|
|
@@ -215,7 +220,7 @@ var EdgeFunctionPlugin = class extends FunctionPluginAsync {
|
|
|
215
220
|
binding
|
|
216
221
|
}, {
|
|
217
222
|
F: __dxlog_file2,
|
|
218
|
-
L:
|
|
223
|
+
L: 41,
|
|
219
224
|
S: this,
|
|
220
225
|
C: (f, a) => f(...a)
|
|
221
226
|
});
|
|
@@ -227,13 +232,13 @@ var EdgeFunctionPlugin = class extends FunctionPluginAsync {
|
|
|
227
232
|
fn
|
|
228
233
|
}, {
|
|
229
234
|
F: __dxlog_file2,
|
|
230
|
-
L:
|
|
235
|
+
L: 47,
|
|
231
236
|
S: this,
|
|
232
237
|
C: (f, a) => f(...a)
|
|
233
238
|
});
|
|
234
239
|
const _ = fn?.version;
|
|
235
240
|
this.runAsyncFunction(ast, state, handler(false), {
|
|
236
|
-
ttl:
|
|
241
|
+
ttl: FUNCTION_TTL
|
|
237
242
|
});
|
|
238
243
|
});
|
|
239
244
|
this.context.createSubscription(ast.procedureName, unsubscribe);
|
|
@@ -251,13 +256,13 @@ var EdgeFunctionPlugin = class extends FunctionPluginAsync {
|
|
|
251
256
|
return await result.text();
|
|
252
257
|
};
|
|
253
258
|
return this.runAsyncFunction(ast, state, handler(true), {
|
|
254
|
-
ttl:
|
|
259
|
+
ttl: FUNCTION_TTL
|
|
255
260
|
});
|
|
256
261
|
}
|
|
257
262
|
};
|
|
258
263
|
EdgeFunctionPlugin.implementedFunctions = {
|
|
259
|
-
|
|
260
|
-
method: "
|
|
264
|
+
[EDGE_FUNCTION_NAME]: {
|
|
265
|
+
method: "dx",
|
|
261
266
|
parameters: [
|
|
262
267
|
// Binding
|
|
263
268
|
{
|
|
@@ -302,14 +307,14 @@ EdgeFunctionPlugin.implementedFunctions = {
|
|
|
302
307
|
};
|
|
303
308
|
var EdgeFunctionPluginTranslations = {
|
|
304
309
|
enGB: {
|
|
305
|
-
|
|
310
|
+
[EDGE_FUNCTION_NAME]: "Remote function"
|
|
306
311
|
},
|
|
307
312
|
enUS: {
|
|
308
|
-
|
|
313
|
+
[EDGE_FUNCTION_NAME]: "Remote function"
|
|
309
314
|
}
|
|
310
315
|
};
|
|
311
316
|
|
|
312
|
-
// packages/plugins/plugin-sheet/src/graph/function-defs.ts
|
|
317
|
+
// packages/plugins/plugin-sheet/src/graph/functions/function-defs.ts
|
|
313
318
|
var defaultFunctions = [
|
|
314
319
|
// Array
|
|
315
320
|
{
|
|
@@ -2686,69 +2691,15 @@ var defaultFunctions = [
|
|
|
2686
2691
|
// packages/plugins/plugin-sheet/src/graph/compute-graph.ts
|
|
2687
2692
|
var __dxlog_file3 = "/home/runner/work/dxos/dxos/packages/plugins/plugin-sheet/src/graph/compute-graph.ts";
|
|
2688
2693
|
var OBJECT_ID_LENGTH = 60;
|
|
2689
|
-
var
|
|
2690
|
-
var
|
|
2691
|
-
|
|
2692
|
-
|
|
2693
|
-
|
|
2694
|
-
|
|
2695
|
-
|
|
2696
|
-
|
|
2697
|
-
}
|
|
2698
|
-
];
|
|
2699
|
-
var PREFIX = "__";
|
|
2700
|
-
var createSheetName = (id) => `${PREFIX}${id}`;
|
|
2701
|
-
var getSheetId = (name) => name.startsWith(PREFIX) ? name.slice(PREFIX.length) : void 0;
|
|
2702
|
-
var ComputeGraphRegistry = class extends Resource2 {
|
|
2703
|
-
constructor(options = {
|
|
2704
|
-
plugins: defaultPlugins
|
|
2705
|
-
}) {
|
|
2706
|
-
super();
|
|
2707
|
-
this._graphs = /* @__PURE__ */ new Map();
|
|
2708
|
-
this._options = defaultsDeep2({}, options, defaultOptions);
|
|
2709
|
-
this._options.plugins?.forEach(({ plugin, translations }) => {
|
|
2710
|
-
HyperFormula.registerFunctionPlugin(plugin, translations);
|
|
2711
|
-
});
|
|
2712
|
-
}
|
|
2713
|
-
getGraph(spaceId) {
|
|
2714
|
-
return this._graphs.get(spaceId);
|
|
2715
|
-
}
|
|
2716
|
-
async getOrCreateGraph(space) {
|
|
2717
|
-
let graph = this.getGraph(space.id);
|
|
2718
|
-
if (!graph) {
|
|
2719
|
-
log3.info("create graph", {
|
|
2720
|
-
space: space.id
|
|
2721
|
-
}, {
|
|
2722
|
-
F: __dxlog_file3,
|
|
2723
|
-
L: 93,
|
|
2724
|
-
S: this,
|
|
2725
|
-
C: (f, a) => f(...a)
|
|
2726
|
-
});
|
|
2727
|
-
graph = await this.createGraph(space);
|
|
2728
|
-
}
|
|
2729
|
-
return graph;
|
|
2730
|
-
}
|
|
2731
|
-
async createGraph(space) {
|
|
2732
|
-
invariant(!this._graphs.has(space.id), `ComputeGraph already exists for space: ${space.id}`, {
|
|
2733
|
-
F: __dxlog_file3,
|
|
2734
|
-
L: 101,
|
|
2735
|
-
S: this,
|
|
2736
|
-
A: [
|
|
2737
|
-
"!this._graphs.has(space.id)",
|
|
2738
|
-
"`ComputeGraph already exists for space: ${space.id}`"
|
|
2739
|
-
]
|
|
2740
|
-
});
|
|
2741
|
-
const hf = HyperFormula.buildEmpty(this._options);
|
|
2742
|
-
const graph = new ComputeGraph(hf, space, this._options);
|
|
2743
|
-
this._graphs.set(space.id, graph);
|
|
2744
|
-
await graph.open();
|
|
2745
|
-
return graph;
|
|
2746
|
-
}
|
|
2747
|
-
async _close() {
|
|
2748
|
-
for (const graph of this._graphs.values()) {
|
|
2749
|
-
await graph.close();
|
|
2750
|
-
}
|
|
2751
|
-
}
|
|
2694
|
+
var createSheetName = ({ type, id }) => `${type}@${id}`;
|
|
2695
|
+
var parseSheetName = (name) => {
|
|
2696
|
+
const [type, id] = name.split("@");
|
|
2697
|
+
return id ? {
|
|
2698
|
+
type,
|
|
2699
|
+
id
|
|
2700
|
+
} : {
|
|
2701
|
+
id: type
|
|
2702
|
+
};
|
|
2752
2703
|
};
|
|
2753
2704
|
var ComputeGraph = class extends Resource2 {
|
|
2754
2705
|
constructor(_hf, _space, _options) {
|
|
@@ -2758,7 +2709,7 @@ var ComputeGraph = class extends Resource2 {
|
|
|
2758
2709
|
this._options = _options;
|
|
2759
2710
|
this.id = `graph-${PublicKey.random().truncate()}`;
|
|
2760
2711
|
this._nodes = /* @__PURE__ */ new Map();
|
|
2761
|
-
this.
|
|
2712
|
+
this._remoteFunctions = [];
|
|
2762
2713
|
this.update = new Event2();
|
|
2763
2714
|
this.context = new FunctionContext(this._hf, this._space, this._options);
|
|
2764
2715
|
this._hf.updateConfig({
|
|
@@ -2784,10 +2735,6 @@ var ComputeGraph = class extends Resource2 {
|
|
|
2784
2735
|
get hf() {
|
|
2785
2736
|
return this._hf;
|
|
2786
2737
|
}
|
|
2787
|
-
// refresh() {
|
|
2788
|
-
// log('refresh', { id: this.id });
|
|
2789
|
-
// this.update.emit();
|
|
2790
|
-
// }
|
|
2791
2738
|
getFunctions({ standard, echo } = {
|
|
2792
2739
|
standard: true,
|
|
2793
2740
|
echo: true
|
|
@@ -2796,7 +2743,7 @@ var ComputeGraph = class extends Resource2 {
|
|
|
2796
2743
|
...standard ? this._hf.getRegisteredFunctionNames().map((name) => defaultFunctions.find((fn) => fn.name === name) ?? {
|
|
2797
2744
|
name
|
|
2798
2745
|
}) : [],
|
|
2799
|
-
...echo ? this.
|
|
2746
|
+
...echo ? this._remoteFunctions.map((fn) => ({
|
|
2800
2747
|
name: fn.binding
|
|
2801
2748
|
})) : []
|
|
2802
2749
|
];
|
|
@@ -2809,10 +2756,10 @@ var ComputeGraph = class extends Resource2 {
|
|
|
2809
2756
|
// This would enable on-the-fly instantiation of new models when then are referenced.
|
|
2810
2757
|
// E.g., Cross-object reference would be stored as "ObjectId!A1"
|
|
2811
2758
|
// The graph would then load the object and create a ComputeNode (model) of the appropriate type.
|
|
2812
|
-
|
|
2759
|
+
getOrCreateNode(name) {
|
|
2813
2760
|
invariant(name.length, void 0, {
|
|
2814
2761
|
F: __dxlog_file3,
|
|
2815
|
-
L:
|
|
2762
|
+
L: 117,
|
|
2816
2763
|
S: this,
|
|
2817
2764
|
A: [
|
|
2818
2765
|
"name.length",
|
|
@@ -2822,10 +2769,10 @@ var ComputeGraph = class extends Resource2 {
|
|
|
2822
2769
|
if (!this._hf.doesSheetExist(name)) {
|
|
2823
2770
|
log3.info("created node", {
|
|
2824
2771
|
space: this._space?.id,
|
|
2825
|
-
name
|
|
2772
|
+
sheet: name
|
|
2826
2773
|
}, {
|
|
2827
2774
|
F: __dxlog_file3,
|
|
2828
|
-
L:
|
|
2775
|
+
L: 119,
|
|
2829
2776
|
S: this,
|
|
2830
2777
|
C: (f, a) => f(...a)
|
|
2831
2778
|
});
|
|
@@ -2834,7 +2781,7 @@ var ComputeGraph = class extends Resource2 {
|
|
|
2834
2781
|
const sheetId = this._hf.getSheetId(name);
|
|
2835
2782
|
invariant(sheetId !== void 0, void 0, {
|
|
2836
2783
|
F: __dxlog_file3,
|
|
2837
|
-
L:
|
|
2784
|
+
L: 124,
|
|
2838
2785
|
S: this,
|
|
2839
2786
|
A: [
|
|
2840
2787
|
"sheetId !== undefined",
|
|
@@ -2842,7 +2789,6 @@ var ComputeGraph = class extends Resource2 {
|
|
|
2842
2789
|
]
|
|
2843
2790
|
});
|
|
2844
2791
|
const node = new ComputeNode(this, sheetId);
|
|
2845
|
-
await node.open();
|
|
2846
2792
|
this._nodes.set(sheetId, node);
|
|
2847
2793
|
return node;
|
|
2848
2794
|
}
|
|
@@ -2854,25 +2800,29 @@ var ComputeGraph = class extends Resource2 {
|
|
|
2854
2800
|
return formula.replace(/['"]?([ \w]+)['"]?!/, (_match, name) => {
|
|
2855
2801
|
if (name) {
|
|
2856
2802
|
const objects = this._hf.getSheetNames().map((name2) => {
|
|
2857
|
-
const id =
|
|
2858
|
-
return id ? this._space?.db.getObjectById(id) : void 0;
|
|
2803
|
+
const { type, id } = parseSheetName(name2);
|
|
2804
|
+
return type && id ? this._space?.db.getObjectById(id) : void 0;
|
|
2859
2805
|
}).filter(nonNullable2);
|
|
2860
2806
|
for (const obj of objects) {
|
|
2861
|
-
if (obj.name === name
|
|
2862
|
-
|
|
2807
|
+
if (obj.name === name) {
|
|
2808
|
+
const type = getTypename(obj);
|
|
2809
|
+
return `'${createSheetName({
|
|
2810
|
+
type,
|
|
2811
|
+
id: obj.id
|
|
2812
|
+
})}'!`;
|
|
2863
2813
|
}
|
|
2864
2814
|
}
|
|
2865
2815
|
}
|
|
2866
2816
|
return `${name}!`;
|
|
2867
2817
|
}).replace(/(\w+)\((.*)\)/g, (match, binding, args) => {
|
|
2868
|
-
const fn = this.
|
|
2818
|
+
const fn = this._remoteFunctions.find((fn2) => fn2.binding === binding);
|
|
2869
2819
|
if (!fn) {
|
|
2870
2820
|
return match;
|
|
2871
2821
|
}
|
|
2872
2822
|
if (args.trim() === "") {
|
|
2873
|
-
return `${
|
|
2823
|
+
return `${EDGE_FUNCTION_NAME}("${binding}")`;
|
|
2874
2824
|
} else {
|
|
2875
|
-
return `${
|
|
2825
|
+
return `${EDGE_FUNCTION_NAME}("${binding}", ${args})`;
|
|
2876
2826
|
}
|
|
2877
2827
|
});
|
|
2878
2828
|
}
|
|
@@ -2882,10 +2832,10 @@ var ComputeGraph = class extends Resource2 {
|
|
|
2882
2832
|
*/
|
|
2883
2833
|
mapFunctionBindingToId(formula) {
|
|
2884
2834
|
return formula.replace(/(\w+)\((.*)\)/g, (match, binding, args) => {
|
|
2885
|
-
if (binding ===
|
|
2835
|
+
if (binding === EDGE_FUNCTION_NAME || defaultFunctions.find((fn2) => fn2.name === binding)) {
|
|
2886
2836
|
return match;
|
|
2887
2837
|
}
|
|
2888
|
-
const fn = this.
|
|
2838
|
+
const fn = this._remoteFunctions.find((fn2) => fn2.binding === binding);
|
|
2889
2839
|
if (fn) {
|
|
2890
2840
|
const id = fullyQualifiedId(fn);
|
|
2891
2841
|
return `${id}(${args})`;
|
|
@@ -2904,7 +2854,7 @@ var ComputeGraph = class extends Resource2 {
|
|
|
2904
2854
|
if (id.length !== OBJECT_ID_LENGTH) {
|
|
2905
2855
|
return match;
|
|
2906
2856
|
}
|
|
2907
|
-
const fn = this.
|
|
2857
|
+
const fn = this._remoteFunctions.find((fn2) => fullyQualifiedId(fn2) === id);
|
|
2908
2858
|
if (fn?.binding) {
|
|
2909
2859
|
return `${fn.binding}(${args})`;
|
|
2910
2860
|
} else {
|
|
@@ -2916,7 +2866,7 @@ var ComputeGraph = class extends Resource2 {
|
|
|
2916
2866
|
if (this._space) {
|
|
2917
2867
|
const query = this._space.db.query(Filter2.schema(FunctionType2));
|
|
2918
2868
|
const unsubscribe = query.subscribe(({ objects }) => {
|
|
2919
|
-
this.
|
|
2869
|
+
this._remoteFunctions = objects.filter(({ binding }) => binding);
|
|
2920
2870
|
this.update.emit({
|
|
2921
2871
|
type: "functionsUpdated"
|
|
2922
2872
|
});
|
|
@@ -2931,14 +2881,88 @@ var ComputeGraph = class extends Resource2 {
|
|
|
2931
2881
|
}
|
|
2932
2882
|
};
|
|
2933
2883
|
|
|
2884
|
+
// packages/plugins/plugin-sheet/src/graph/compute-graph-registry.ts
|
|
2885
|
+
import defaultsDeep2 from "lodash.defaultsdeep";
|
|
2886
|
+
import { Resource as Resource3 } from "@dxos/context";
|
|
2887
|
+
import { invariant as invariant2 } from "@dxos/invariant";
|
|
2888
|
+
import { log as log4 } from "@dxos/log";
|
|
2889
|
+
import { HyperFormula } from "#hyperformula";
|
|
2890
|
+
var __dxlog_file4 = "/home/runner/work/dxos/dxos/packages/plugins/plugin-sheet/src/graph/compute-graph-registry.ts";
|
|
2891
|
+
var defaultOptions = {
|
|
2892
|
+
licenseKey: "gpl-v3"
|
|
2893
|
+
};
|
|
2894
|
+
var defaultPlugins = [
|
|
2895
|
+
{
|
|
2896
|
+
plugin: EdgeFunctionPlugin,
|
|
2897
|
+
translations: EdgeFunctionPluginTranslations
|
|
2898
|
+
}
|
|
2899
|
+
];
|
|
2900
|
+
var ComputeGraphRegistry = class extends Resource3 {
|
|
2901
|
+
constructor(options = {
|
|
2902
|
+
plugins: defaultPlugins
|
|
2903
|
+
}) {
|
|
2904
|
+
super();
|
|
2905
|
+
this._graphs = /* @__PURE__ */ new Map();
|
|
2906
|
+
this._options = defaultsDeep2({}, options, defaultOptions);
|
|
2907
|
+
this._options.plugins?.forEach(({ plugin, translations }) => {
|
|
2908
|
+
HyperFormula.registerFunctionPlugin(plugin, translations);
|
|
2909
|
+
});
|
|
2910
|
+
}
|
|
2911
|
+
getGraph(spaceId) {
|
|
2912
|
+
return this._graphs.get(spaceId);
|
|
2913
|
+
}
|
|
2914
|
+
getOrCreateGraph(space) {
|
|
2915
|
+
let graph = this._graphs.get(space.id);
|
|
2916
|
+
if (!graph) {
|
|
2917
|
+
log4("create graph", {
|
|
2918
|
+
space: space.id
|
|
2919
|
+
}, {
|
|
2920
|
+
F: __dxlog_file4,
|
|
2921
|
+
L: 69,
|
|
2922
|
+
S: this,
|
|
2923
|
+
C: (f, a) => f(...a)
|
|
2924
|
+
});
|
|
2925
|
+
graph = this.createGraph(space);
|
|
2926
|
+
}
|
|
2927
|
+
return graph;
|
|
2928
|
+
}
|
|
2929
|
+
createGraph(space) {
|
|
2930
|
+
invariant2(!this._graphs.has(space.id), `ComputeGraph already exists for space: ${space.id}`, {
|
|
2931
|
+
F: __dxlog_file4,
|
|
2932
|
+
L: 77,
|
|
2933
|
+
S: this,
|
|
2934
|
+
A: [
|
|
2935
|
+
"!this._graphs.has(space.id)",
|
|
2936
|
+
"`ComputeGraph already exists for space: ${space.id}`"
|
|
2937
|
+
]
|
|
2938
|
+
});
|
|
2939
|
+
const hf = HyperFormula.buildEmpty(this._options);
|
|
2940
|
+
const graph = new ComputeGraph(hf, space, this._options);
|
|
2941
|
+
this._graphs.set(space.id, graph);
|
|
2942
|
+
return graph;
|
|
2943
|
+
}
|
|
2944
|
+
async _close() {
|
|
2945
|
+
for (const graph of this._graphs.values()) {
|
|
2946
|
+
await graph.close();
|
|
2947
|
+
}
|
|
2948
|
+
this._graphs.clear();
|
|
2949
|
+
}
|
|
2950
|
+
};
|
|
2951
|
+
|
|
2934
2952
|
export {
|
|
2935
2953
|
ComputeNode,
|
|
2954
|
+
defaultFunctionContextOptions,
|
|
2955
|
+
FunctionContext,
|
|
2956
|
+
AsyncFunctionPlugin,
|
|
2957
|
+
EDGE_FUNCTION_NAME,
|
|
2958
|
+
EdgeFunctionPlugin,
|
|
2959
|
+
EdgeFunctionPluginTranslations,
|
|
2936
2960
|
defaultFunctions,
|
|
2961
|
+
createSheetName,
|
|
2962
|
+
parseSheetName,
|
|
2963
|
+
ComputeGraph,
|
|
2937
2964
|
defaultOptions,
|
|
2938
2965
|
defaultPlugins,
|
|
2939
|
-
|
|
2940
|
-
getSheetId,
|
|
2941
|
-
ComputeGraphRegistry,
|
|
2942
|
-
ComputeGraph
|
|
2966
|
+
ComputeGraphRegistry
|
|
2943
2967
|
};
|
|
2944
|
-
//# sourceMappingURL=chunk-
|
|
2968
|
+
//# sourceMappingURL=chunk-5WPZCXNS.mjs.map
|