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