@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.
Files changed (114) hide show
  1. package/dist/lib/browser/{SheetContainer-VISF3VUB.mjs → SheetContainer-LG77O4RM.mjs} +11 -10
  2. package/dist/lib/browser/SheetContainer-LG77O4RM.mjs.map +7 -0
  3. package/dist/lib/browser/{chunk-ZLJ2GRE2.mjs → chunk-CHQAW4F4.mjs} +55 -33
  4. package/dist/lib/browser/chunk-CHQAW4F4.mjs.map +7 -0
  5. package/dist/lib/browser/{chunk-Z2XOOC2R.mjs → chunk-GSV5QNLD.mjs} +183 -159
  6. package/dist/lib/browser/chunk-GSV5QNLD.mjs.map +7 -0
  7. package/dist/lib/browser/graph-M4IQ76QX.mjs +33 -0
  8. package/dist/lib/browser/index.mjs +37 -15
  9. package/dist/lib/browser/index.mjs.map +4 -4
  10. package/dist/lib/browser/meta.json +1 -1
  11. package/dist/lib/node/{SheetContainer-2MEALQWW.cjs → SheetContainer-OZ7DHH4L.cjs} +18 -17
  12. package/dist/lib/node/SheetContainer-OZ7DHH4L.cjs.map +7 -0
  13. package/dist/lib/node/{chunk-6DQABRGJ.cjs → chunk-5FTFZL5W.cjs} +57 -35
  14. package/dist/lib/node/chunk-5FTFZL5W.cjs.map +7 -0
  15. package/dist/lib/node/{chunk-P5QYYEHQ.cjs → chunk-5XPK2V4A.cjs} +186 -158
  16. package/dist/lib/node/chunk-5XPK2V4A.cjs.map +7 -0
  17. package/dist/lib/node/graph-Q3N2X26H.cjs +55 -0
  18. package/dist/lib/node/graph-Q3N2X26H.cjs.map +7 -0
  19. package/dist/lib/node/index.cjs +38 -18
  20. package/dist/lib/node/index.cjs.map +4 -4
  21. package/dist/lib/node/meta.json +1 -1
  22. package/dist/lib/node-esm/{SheetContainer-RPSUSXWS.mjs → SheetContainer-4XS2G25Z.mjs} +11 -10
  23. package/dist/lib/node-esm/SheetContainer-4XS2G25Z.mjs.map +7 -0
  24. package/dist/lib/node-esm/{chunk-4MM7THJW.mjs → chunk-5WPZCXNS.mjs} +183 -159
  25. package/dist/lib/node-esm/chunk-5WPZCXNS.mjs.map +7 -0
  26. package/dist/lib/node-esm/{chunk-5RLTCIE2.mjs → chunk-KK3XL37M.mjs} +55 -33
  27. package/dist/lib/node-esm/chunk-KK3XL37M.mjs.map +7 -0
  28. package/dist/lib/node-esm/graph-SMPUMOV2.mjs +34 -0
  29. package/dist/lib/node-esm/index.mjs +37 -15
  30. package/dist/lib/node-esm/index.mjs.map +4 -4
  31. package/dist/lib/node-esm/meta.json +1 -1
  32. package/dist/types/src/SheetPlugin.d.ts.map +1 -1
  33. package/dist/types/src/components/CellEditor/CellEditor.stories.d.ts.map +1 -1
  34. package/dist/types/src/components/CellEditor/extension.d.ts.map +1 -1
  35. package/dist/types/src/components/Sheet/Sheet.d.ts.map +1 -1
  36. package/dist/types/src/components/Sheet/Sheet.stories.d.ts.map +1 -1
  37. package/dist/types/src/components/SheetContainer.d.ts.map +1 -1
  38. package/dist/types/src/components/index.d.ts.map +1 -1
  39. package/dist/types/src/extensions/compute.d.ts +2 -5
  40. package/dist/types/src/extensions/compute.d.ts.map +1 -1
  41. package/dist/types/src/extensions/compute.stories.d.ts.map +1 -1
  42. package/dist/types/src/graph/compute-graph-registry.d.ts +34 -0
  43. package/dist/types/src/graph/compute-graph-registry.d.ts.map +1 -0
  44. package/dist/types/src/graph/compute-graph.d.ts +13 -33
  45. package/dist/types/src/graph/compute-graph.d.ts.map +1 -1
  46. package/dist/types/src/graph/compute-node.d.ts.map +1 -1
  47. package/dist/types/src/graph/{async-function.d.ts → functions/async-function.d.ts} +6 -3
  48. package/dist/types/src/graph/functions/async-function.d.ts.map +1 -0
  49. package/dist/types/src/graph/functions/edge-function.d.ts +21 -0
  50. package/dist/types/src/graph/functions/edge-function.d.ts.map +1 -0
  51. package/dist/types/src/graph/functions/function-defs.d.ts.map +1 -0
  52. package/dist/types/src/graph/functions/index.d.ts +4 -0
  53. package/dist/types/src/graph/functions/index.d.ts.map +1 -0
  54. package/dist/types/src/graph/index.d.ts +2 -1
  55. package/dist/types/src/graph/index.d.ts.map +1 -1
  56. package/dist/types/src/graph/testing/index.d.ts +2 -1
  57. package/dist/types/src/graph/testing/index.d.ts.map +1 -1
  58. package/dist/types/src/graph/testing/test-builder.d.ts +15 -0
  59. package/dist/types/src/graph/testing/test-builder.d.ts.map +1 -0
  60. package/dist/types/src/graph/testing/test-plugin.d.ts +36 -0
  61. package/dist/types/src/graph/testing/test-plugin.d.ts.map +1 -0
  62. package/dist/types/src/hooks/useComputeGraph.d.ts.map +1 -1
  63. package/dist/types/src/model/sheet-model.d.ts.map +1 -1
  64. package/dist/types/src/model/sheet-model.test.d.ts +2 -0
  65. package/dist/types/src/model/sheet-model.test.d.ts.map +1 -0
  66. package/package.json +40 -39
  67. package/src/SheetPlugin.tsx +12 -10
  68. package/src/components/CellEditor/CellEditor.stories.tsx +1 -2
  69. package/src/components/CellEditor/extension.test.ts +0 -1
  70. package/src/components/CellEditor/extension.ts +4 -3
  71. package/src/components/Sheet/Sheet.stories.tsx +2 -2
  72. package/src/components/Sheet/Sheet.tsx +30 -14
  73. package/src/components/SheetContainer.tsx +11 -13
  74. package/src/extensions/compute.stories.tsx +9 -11
  75. package/src/extensions/compute.ts +66 -50
  76. package/src/graph/compute-graph-registry.ts +90 -0
  77. package/src/graph/compute-graph.stories.tsx +2 -2
  78. package/src/graph/compute-graph.test.ts +31 -71
  79. package/src/graph/compute-graph.ts +45 -116
  80. package/src/graph/compute-node.ts +1 -0
  81. package/src/graph/{async-function.ts → functions/async-function.ts} +10 -9
  82. package/src/graph/{edge-function.ts → functions/edge-function.ts} +13 -11
  83. package/src/graph/functions/index.ts +7 -0
  84. package/src/graph/hyperformula.test.ts +1 -2
  85. package/src/graph/index.ts +2 -1
  86. package/src/graph/testing/index.ts +2 -1
  87. package/src/graph/testing/test-builder.ts +54 -0
  88. package/src/graph/testing/{custom-function.ts → test-plugin.ts} +38 -12
  89. package/src/hooks/useComputeGraph.ts +8 -1
  90. package/src/model/sheet-model.test.ts +59 -0
  91. package/src/model/sheet-model.ts +4 -2
  92. package/dist/lib/browser/SheetContainer-VISF3VUB.mjs.map +0 -7
  93. package/dist/lib/browser/chunk-Z2XOOC2R.mjs.map +0 -7
  94. package/dist/lib/browser/chunk-ZLJ2GRE2.mjs.map +0 -7
  95. package/dist/lib/browser/graph-4XFKIHRL.mjs +0 -21
  96. package/dist/lib/node/SheetContainer-2MEALQWW.cjs.map +0 -7
  97. package/dist/lib/node/chunk-6DQABRGJ.cjs.map +0 -7
  98. package/dist/lib/node/chunk-P5QYYEHQ.cjs.map +0 -7
  99. package/dist/lib/node/graph-2LRDUXBZ.cjs +0 -43
  100. package/dist/lib/node/graph-2LRDUXBZ.cjs.map +0 -7
  101. package/dist/lib/node-esm/SheetContainer-RPSUSXWS.mjs.map +0 -7
  102. package/dist/lib/node-esm/chunk-4MM7THJW.mjs.map +0 -7
  103. package/dist/lib/node-esm/chunk-5RLTCIE2.mjs.map +0 -7
  104. package/dist/lib/node-esm/graph-WG5EKOMO.mjs +0 -22
  105. package/dist/types/src/graph/async-function.d.ts.map +0 -1
  106. package/dist/types/src/graph/edge-function.d.ts +0 -20
  107. package/dist/types/src/graph/edge-function.d.ts.map +0 -1
  108. package/dist/types/src/graph/function-defs.d.ts.map +0 -1
  109. package/dist/types/src/graph/testing/custom-function.d.ts +0 -23
  110. package/dist/types/src/graph/testing/custom-function.d.ts.map +0 -1
  111. /package/dist/lib/browser/{graph-4XFKIHRL.mjs.map → graph-M4IQ76QX.mjs.map} +0 -0
  112. /package/dist/lib/node-esm/{graph-WG5EKOMO.mjs.map → graph-SMPUMOV2.mjs.map} +0 -0
  113. /package/dist/types/src/graph/{function-defs.d.ts → functions/function-defs.d.ts} +0 -0
  114. /package/src/graph/{function-defs.ts → functions/function-defs.ts} +0 -0
@@ -26,34 +26,40 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
26
26
  mod
27
27
  ));
28
28
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
- var chunk_P5QYYEHQ_exports = {};
30
- __export(chunk_P5QYYEHQ_exports, {
29
+ var chunk_5XPK2V4A_exports = {};
30
+ __export(chunk_5XPK2V4A_exports, {
31
+ AsyncFunctionPlugin: () => AsyncFunctionPlugin,
31
32
  ComputeGraph: () => ComputeGraph,
32
33
  ComputeGraphRegistry: () => ComputeGraphRegistry,
33
34
  ComputeNode: () => ComputeNode,
35
+ EDGE_FUNCTION_NAME: () => EDGE_FUNCTION_NAME,
36
+ EdgeFunctionPlugin: () => EdgeFunctionPlugin,
37
+ EdgeFunctionPluginTranslations: () => EdgeFunctionPluginTranslations,
38
+ FunctionContext: () => FunctionContext,
34
39
  createSheetName: () => createSheetName,
40
+ defaultFunctionContextOptions: () => defaultFunctionContextOptions,
35
41
  defaultFunctions: () => defaultFunctions,
36
42
  defaultOptions: () => defaultOptions,
37
43
  defaultPlugins: () => defaultPlugins,
38
- getSheetId: () => getSheetId
44
+ parseSheetName: () => parseSheetName
39
45
  });
40
- module.exports = __toCommonJS(chunk_P5QYYEHQ_exports);
41
- var import_lodash = __toESM(require("lodash.defaultsdeep"));
46
+ module.exports = __toCommonJS(chunk_5XPK2V4A_exports);
42
47
  var import_async = require("@dxos/async");
43
48
  var import_echo = require("@dxos/client/echo");
44
49
  var import_context = require("@dxos/context");
50
+ var import_echo_schema = require("@dxos/echo-schema");
45
51
  var import_invariant = require("@dxos/invariant");
46
52
  var import_keys = require("@dxos/keys");
47
53
  var import_log = require("@dxos/log");
48
54
  var import_types = require("@dxos/plugin-script/types");
49
55
  var import_util = require("@dxos/util");
50
56
  var import_hyperformula = require("#hyperformula");
51
- var import_lodash2 = __toESM(require("lodash.defaultsdeep"));
52
57
  var import_async2 = require("@dxos/async");
53
- var import_log2 = require("@dxos/log");
58
+ var import_context2 = require("@dxos/context");
54
59
  var import_hyperformula2 = require("#hyperformula");
60
+ var import_lodash = __toESM(require("lodash.defaultsdeep"));
55
61
  var import_async3 = require("@dxos/async");
56
- var import_context2 = require("@dxos/context");
62
+ var import_log2 = require("@dxos/log");
57
63
  var import_hyperformula3 = require("#hyperformula");
58
64
  var import_signals_core = require("@preact/signals-core");
59
65
  var import_echo2 = require("@dxos/client/echo");
@@ -62,10 +68,55 @@ var import_edge = require("@dxos/plugin-script/edge");
62
68
  var import_types2 = require("@dxos/plugin-script/types");
63
69
  var import_util2 = require("@dxos/util");
64
70
  var import_hyperformula4 = require("#hyperformula");
65
- var __dxlog_file = "/home/runner/work/dxos/dxos/packages/plugins/plugin-sheet/src/graph/async-function.ts";
71
+ var import_lodash2 = __toESM(require("lodash.defaultsdeep"));
72
+ var import_context3 = require("@dxos/context");
73
+ var import_invariant2 = require("@dxos/invariant");
74
+ var import_log4 = require("@dxos/log");
75
+ var import_hyperformula5 = require("#hyperformula");
76
+ var ComputeNode = class extends import_context2.Resource {
77
+ constructor(_graph, sheetId) {
78
+ super();
79
+ this._graph = _graph;
80
+ this.sheetId = sheetId;
81
+ this.update = new import_async2.Event();
82
+ }
83
+ get graph() {
84
+ return this._graph;
85
+ }
86
+ clear() {
87
+ this._graph.hf.clearSheet(this.sheetId);
88
+ }
89
+ getValue(cell) {
90
+ const value = this._graph.hf.getCellValue({
91
+ sheet: this.sheetId,
92
+ row: cell.row,
93
+ col: cell.col
94
+ });
95
+ if (value instanceof import_hyperformula2.DetailedCellError) {
96
+ return null;
97
+ }
98
+ return value;
99
+ }
100
+ setValue(cell, value) {
101
+ const mappedValue = typeof value === "string" && value.charAt(0) === "=" ? this._graph.mapFormulaToNative(value) : value;
102
+ this._graph.hf.setCellContents({
103
+ sheet: this.sheetId,
104
+ row: cell.row,
105
+ col: cell.col
106
+ }, [
107
+ [
108
+ mappedValue
109
+ ]
110
+ ]);
111
+ }
112
+ // TODO(burdon): Load data into sheet.
113
+ async _open() {
114
+ }
115
+ };
116
+ var __dxlog_file = "/home/runner/work/dxos/dxos/packages/plugins/plugin-sheet/src/graph/functions/async-function.ts";
66
117
  var defaultFunctionContextOptions = {
67
118
  defaultTtl: 5e3,
68
- recalculationDelay: 200,
119
+ debounceDelay: 200,
69
120
  remoteFunctionUrl: "https://edge.dxos.workers.dev/functions"
70
121
  };
71
122
  var FunctionContext = class _FunctionContext {
@@ -83,11 +134,11 @@ var FunctionContext = class _FunctionContext {
83
134
  this._pending = /* @__PURE__ */ new Map();
84
135
  this._subscriptions = /* @__PURE__ */ new Map();
85
136
  this._invocations = {};
86
- this._options = (0, import_lodash2.default)(_options ?? {}, defaultFunctionContextOptions);
87
- this._onUpdate = (0, import_async2.debounce)((update) => {
137
+ this._options = (0, import_lodash.default)(_options ?? {}, defaultFunctionContextOptions);
138
+ this._onUpdate = (0, import_async3.debounce)((update) => {
88
139
  this._hf.resumeEvaluation();
89
140
  this._options.onUpdate?.(update);
90
- }, this._options.recalculationDelay);
141
+ }, this._options.debounceDelay);
91
142
  }
92
143
  get space() {
93
144
  return this._space;
@@ -137,7 +188,7 @@ var FunctionContext = class _FunctionContext {
137
188
  value: value2
138
189
  }, {
139
190
  F: __dxlog_file,
140
- L: 145,
191
+ L: 143,
141
192
  S: this,
142
193
  C: (f, a) => f(...a)
143
194
  });
@@ -151,12 +202,12 @@ var FunctionContext = class _FunctionContext {
151
202
  err
152
203
  }, {
153
204
  F: __dxlog_file,
154
- L: 149,
205
+ L: 147,
155
206
  S: this,
156
207
  C: (f, a) => f(...a)
157
208
  });
158
209
  this._cache.set(invocationKey, {
159
- value: new import_hyperformula2.CellError(import_hyperformula2.ErrorType.ERROR, "Function failed."),
210
+ value: new import_hyperformula3.CellError(import_hyperformula3.ErrorType.ERROR, "Function failed."),
160
211
  ts: Date.now()
161
212
  });
162
213
  } finally {
@@ -171,68 +222,33 @@ var FunctionContext = class _FunctionContext {
171
222
  cache: value
172
223
  }, {
173
224
  F: __dxlog_file,
174
- L: 157,
225
+ L: 155,
175
226
  S: this,
176
227
  C: (f, a) => f(...a)
177
228
  });
178
229
  return value;
179
230
  }
180
231
  };
181
- var FunctionPluginAsync = class extends import_hyperformula2.FunctionPlugin {
232
+ var AsyncFunctionPlugin = class extends import_hyperformula3.FunctionPlugin {
182
233
  get context() {
183
234
  return this.config.context;
184
235
  }
236
+ /**
237
+ * Immediately returns cached value then runs the async function.
238
+ */
185
239
  runAsyncFunction(ast, state, cb, options) {
186
240
  const { procedureName } = ast;
187
241
  const metadata = this.metadata(procedureName);
188
242
  return this.runFunction(ast.args, state, metadata, (...args) => {
189
- return this.context.invokeFunction(procedureName, state, args, cb, options) ?? import_hyperformula2.EmptyValue;
190
- });
191
- }
192
- };
193
- var ComputeNode = class extends import_context2.Resource {
194
- constructor(_graph, sheetId) {
195
- super();
196
- this._graph = _graph;
197
- this.sheetId = sheetId;
198
- this.update = new import_async3.Event();
199
- }
200
- get graph() {
201
- return this._graph;
202
- }
203
- clear() {
204
- this._graph.hf.clearSheet(this.sheetId);
205
- }
206
- getValue(cell) {
207
- const value = this._graph.hf.getCellValue({
208
- sheet: this.sheetId,
209
- row: cell.row,
210
- col: cell.col
243
+ return this.context.invokeFunction(procedureName, state, args, cb, options) ?? import_hyperformula3.EmptyValue;
211
244
  });
212
- if (value instanceof import_hyperformula3.DetailedCellError) {
213
- return null;
214
- }
215
- return value;
216
- }
217
- setValue(cell, value) {
218
- const mappedValue = typeof value === "string" && value.charAt(0) === "=" ? this._graph.mapFormulaToNative(value) : value;
219
- this._graph.hf.setCellContents({
220
- sheet: this.sheetId,
221
- row: cell.row,
222
- col: cell.col
223
- }, [
224
- [
225
- mappedValue
226
- ]
227
- ]);
228
- }
229
- async _open() {
230
245
  }
231
246
  };
232
- var __dxlog_file2 = "/home/runner/work/dxos/dxos/packages/plugins/plugin-sheet/src/graph/edge-function.ts";
233
- var EDGE_FUNCTION_TTL = 1e4;
234
- var EdgeFunctionPlugin = class extends FunctionPluginAsync {
235
- edge(ast, state) {
247
+ var __dxlog_file2 = "/home/runner/work/dxos/dxos/packages/plugins/plugin-sheet/src/graph/functions/edge-function.ts";
248
+ var EDGE_FUNCTION_NAME = "DX";
249
+ var FUNCTION_TTL = 1e4;
250
+ var EdgeFunctionPlugin = class extends AsyncFunctionPlugin {
251
+ dx(ast, state) {
236
252
  const handler = (subscribe = false) => async (binding, ...args) => {
237
253
  const space = this.context.space;
238
254
  if (!space) {
@@ -246,7 +262,7 @@ var EdgeFunctionPlugin = class extends FunctionPluginAsync {
246
262
  binding
247
263
  }, {
248
264
  F: __dxlog_file2,
249
- L: 39,
265
+ L: 41,
250
266
  S: this,
251
267
  C: (f, a) => f(...a)
252
268
  });
@@ -258,13 +274,13 @@ var EdgeFunctionPlugin = class extends FunctionPluginAsync {
258
274
  fn
259
275
  }, {
260
276
  F: __dxlog_file2,
261
- L: 45,
277
+ L: 47,
262
278
  S: this,
263
279
  C: (f, a) => f(...a)
264
280
  });
265
281
  const _ = fn?.version;
266
282
  this.runAsyncFunction(ast, state, handler(false), {
267
- ttl: EDGE_FUNCTION_TTL
283
+ ttl: FUNCTION_TTL
268
284
  });
269
285
  });
270
286
  this.context.createSubscription(ast.procedureName, unsubscribe);
@@ -282,13 +298,13 @@ var EdgeFunctionPlugin = class extends FunctionPluginAsync {
282
298
  return await result.text();
283
299
  };
284
300
  return this.runAsyncFunction(ast, state, handler(true), {
285
- ttl: EDGE_FUNCTION_TTL
301
+ ttl: FUNCTION_TTL
286
302
  });
287
303
  }
288
304
  };
289
305
  EdgeFunctionPlugin.implementedFunctions = {
290
- EDGE: {
291
- method: "edge",
306
+ [EDGE_FUNCTION_NAME]: {
307
+ method: "dx",
292
308
  parameters: [
293
309
  // Binding
294
310
  {
@@ -333,10 +349,10 @@ EdgeFunctionPlugin.implementedFunctions = {
333
349
  };
334
350
  var EdgeFunctionPluginTranslations = {
335
351
  enGB: {
336
- EDGE: "EDGE"
352
+ [EDGE_FUNCTION_NAME]: "Remote function"
337
353
  },
338
354
  enUS: {
339
- EDGE: "EDGE"
355
+ [EDGE_FUNCTION_NAME]: "Remote function"
340
356
  }
341
357
  };
342
358
  var defaultFunctions = [
@@ -2713,69 +2729,15 @@ var defaultFunctions = [
2713
2729
  ];
2714
2730
  var __dxlog_file3 = "/home/runner/work/dxos/dxos/packages/plugins/plugin-sheet/src/graph/compute-graph.ts";
2715
2731
  var OBJECT_ID_LENGTH = 60;
2716
- var CUSTOM_FUNCTION = "ECHO";
2717
- var defaultOptions = {
2718
- licenseKey: "gpl-v3"
2719
- };
2720
- var defaultPlugins = [
2721
- {
2722
- plugin: EdgeFunctionPlugin,
2723
- translations: EdgeFunctionPluginTranslations
2724
- }
2725
- ];
2726
- var PREFIX = "__";
2727
- var createSheetName = (id) => `${PREFIX}${id}`;
2728
- var getSheetId = (name) => name.startsWith(PREFIX) ? name.slice(PREFIX.length) : void 0;
2729
- var ComputeGraphRegistry = class extends import_context.Resource {
2730
- constructor(options = {
2731
- plugins: defaultPlugins
2732
- }) {
2733
- super();
2734
- this._graphs = /* @__PURE__ */ new Map();
2735
- this._options = (0, import_lodash.default)({}, options, defaultOptions);
2736
- this._options.plugins?.forEach(({ plugin, translations }) => {
2737
- import_hyperformula.HyperFormula.registerFunctionPlugin(plugin, translations);
2738
- });
2739
- }
2740
- getGraph(spaceId) {
2741
- return this._graphs.get(spaceId);
2742
- }
2743
- async getOrCreateGraph(space) {
2744
- let graph = this.getGraph(space.id);
2745
- if (!graph) {
2746
- import_log.log.info("create graph", {
2747
- space: space.id
2748
- }, {
2749
- F: __dxlog_file3,
2750
- L: 93,
2751
- S: this,
2752
- C: (f, a) => f(...a)
2753
- });
2754
- graph = await this.createGraph(space);
2755
- }
2756
- return graph;
2757
- }
2758
- async createGraph(space) {
2759
- (0, import_invariant.invariant)(!this._graphs.has(space.id), `ComputeGraph already exists for space: ${space.id}`, {
2760
- F: __dxlog_file3,
2761
- L: 101,
2762
- S: this,
2763
- A: [
2764
- "!this._graphs.has(space.id)",
2765
- "`ComputeGraph already exists for space: ${space.id}`"
2766
- ]
2767
- });
2768
- const hf = import_hyperformula.HyperFormula.buildEmpty(this._options);
2769
- const graph = new ComputeGraph(hf, space, this._options);
2770
- this._graphs.set(space.id, graph);
2771
- await graph.open();
2772
- return graph;
2773
- }
2774
- async _close() {
2775
- for (const graph of this._graphs.values()) {
2776
- await graph.close();
2777
- }
2778
- }
2732
+ var createSheetName = ({ type, id }) => `${type}@${id}`;
2733
+ var parseSheetName = (name) => {
2734
+ const [type, id] = name.split("@");
2735
+ return id ? {
2736
+ type,
2737
+ id
2738
+ } : {
2739
+ id: type
2740
+ };
2779
2741
  };
2780
2742
  var ComputeGraph = class extends import_context.Resource {
2781
2743
  constructor(_hf, _space, _options) {
@@ -2785,7 +2747,7 @@ var ComputeGraph = class extends import_context.Resource {
2785
2747
  this._options = _options;
2786
2748
  this.id = `graph-${import_keys.PublicKey.random().truncate()}`;
2787
2749
  this._nodes = /* @__PURE__ */ new Map();
2788
- this._functions = [];
2750
+ this._remoteFunctions = [];
2789
2751
  this.update = new import_async.Event();
2790
2752
  this.context = new FunctionContext(this._hf, this._space, this._options);
2791
2753
  this._hf.updateConfig({
@@ -2811,10 +2773,6 @@ var ComputeGraph = class extends import_context.Resource {
2811
2773
  get hf() {
2812
2774
  return this._hf;
2813
2775
  }
2814
- // refresh() {
2815
- // log('refresh', { id: this.id });
2816
- // this.update.emit();
2817
- // }
2818
2776
  getFunctions({ standard, echo } = {
2819
2777
  standard: true,
2820
2778
  echo: true
@@ -2823,7 +2781,7 @@ var ComputeGraph = class extends import_context.Resource {
2823
2781
  ...standard ? this._hf.getRegisteredFunctionNames().map((name) => defaultFunctions.find((fn) => fn.name === name) ?? {
2824
2782
  name
2825
2783
  }) : [],
2826
- ...echo ? this._functions.map((fn) => ({
2784
+ ...echo ? this._remoteFunctions.map((fn) => ({
2827
2785
  name: fn.binding
2828
2786
  })) : []
2829
2787
  ];
@@ -2836,10 +2794,10 @@ var ComputeGraph = class extends import_context.Resource {
2836
2794
  // This would enable on-the-fly instantiation of new models when then are referenced.
2837
2795
  // E.g., Cross-object reference would be stored as "ObjectId!A1"
2838
2796
  // The graph would then load the object and create a ComputeNode (model) of the appropriate type.
2839
- async getOrCreateNode(name) {
2797
+ getOrCreateNode(name) {
2840
2798
  (0, import_invariant.invariant)(name.length, void 0, {
2841
2799
  F: __dxlog_file3,
2842
- L: 193,
2800
+ L: 117,
2843
2801
  S: this,
2844
2802
  A: [
2845
2803
  "name.length",
@@ -2849,10 +2807,10 @@ var ComputeGraph = class extends import_context.Resource {
2849
2807
  if (!this._hf.doesSheetExist(name)) {
2850
2808
  import_log.log.info("created node", {
2851
2809
  space: this._space?.id,
2852
- name
2810
+ sheet: name
2853
2811
  }, {
2854
2812
  F: __dxlog_file3,
2855
- L: 195,
2813
+ L: 119,
2856
2814
  S: this,
2857
2815
  C: (f, a) => f(...a)
2858
2816
  });
@@ -2861,7 +2819,7 @@ var ComputeGraph = class extends import_context.Resource {
2861
2819
  const sheetId = this._hf.getSheetId(name);
2862
2820
  (0, import_invariant.invariant)(sheetId !== void 0, void 0, {
2863
2821
  F: __dxlog_file3,
2864
- L: 201,
2822
+ L: 124,
2865
2823
  S: this,
2866
2824
  A: [
2867
2825
  "sheetId !== undefined",
@@ -2869,7 +2827,6 @@ var ComputeGraph = class extends import_context.Resource {
2869
2827
  ]
2870
2828
  });
2871
2829
  const node = new ComputeNode(this, sheetId);
2872
- await node.open();
2873
2830
  this._nodes.set(sheetId, node);
2874
2831
  return node;
2875
2832
  }
@@ -2881,25 +2838,29 @@ var ComputeGraph = class extends import_context.Resource {
2881
2838
  return formula.replace(/['"]?([ \w]+)['"]?!/, (_match, name) => {
2882
2839
  if (name) {
2883
2840
  const objects = this._hf.getSheetNames().map((name2) => {
2884
- const id = getSheetId(name2);
2885
- return id ? this._space?.db.getObjectById(id) : void 0;
2841
+ const { type, id } = parseSheetName(name2);
2842
+ return type && id ? this._space?.db.getObjectById(id) : void 0;
2886
2843
  }).filter(import_util.nonNullable);
2887
2844
  for (const obj of objects) {
2888
- if (obj.name === name || obj.title === name) {
2889
- return `${createSheetName(obj.id)}!`;
2845
+ if (obj.name === name) {
2846
+ const type = (0, import_echo_schema.getTypename)(obj);
2847
+ return `'${createSheetName({
2848
+ type,
2849
+ id: obj.id
2850
+ })}'!`;
2890
2851
  }
2891
2852
  }
2892
2853
  }
2893
2854
  return `${name}!`;
2894
2855
  }).replace(/(\w+)\((.*)\)/g, (match, binding, args) => {
2895
- const fn = this._functions.find((fn2) => fn2.binding === binding);
2856
+ const fn = this._remoteFunctions.find((fn2) => fn2.binding === binding);
2896
2857
  if (!fn) {
2897
2858
  return match;
2898
2859
  }
2899
2860
  if (args.trim() === "") {
2900
- return `${CUSTOM_FUNCTION}("${binding}")`;
2861
+ return `${EDGE_FUNCTION_NAME}("${binding}")`;
2901
2862
  } else {
2902
- return `${CUSTOM_FUNCTION}("${binding}", ${args})`;
2863
+ return `${EDGE_FUNCTION_NAME}("${binding}", ${args})`;
2903
2864
  }
2904
2865
  });
2905
2866
  }
@@ -2909,10 +2870,10 @@ var ComputeGraph = class extends import_context.Resource {
2909
2870
  */
2910
2871
  mapFunctionBindingToId(formula) {
2911
2872
  return formula.replace(/(\w+)\((.*)\)/g, (match, binding, args) => {
2912
- if (binding === CUSTOM_FUNCTION || defaultFunctions.find((fn2) => fn2.name === binding)) {
2873
+ if (binding === EDGE_FUNCTION_NAME || defaultFunctions.find((fn2) => fn2.name === binding)) {
2913
2874
  return match;
2914
2875
  }
2915
- const fn = this._functions.find((fn2) => fn2.binding === binding);
2876
+ const fn = this._remoteFunctions.find((fn2) => fn2.binding === binding);
2916
2877
  if (fn) {
2917
2878
  const id = (0, import_echo.fullyQualifiedId)(fn);
2918
2879
  return `${id}(${args})`;
@@ -2931,7 +2892,7 @@ var ComputeGraph = class extends import_context.Resource {
2931
2892
  if (id.length !== OBJECT_ID_LENGTH) {
2932
2893
  return match;
2933
2894
  }
2934
- const fn = this._functions.find((fn2) => (0, import_echo.fullyQualifiedId)(fn2) === id);
2895
+ const fn = this._remoteFunctions.find((fn2) => (0, import_echo.fullyQualifiedId)(fn2) === id);
2935
2896
  if (fn?.binding) {
2936
2897
  return `${fn.binding}(${args})`;
2937
2898
  } else {
@@ -2943,7 +2904,7 @@ var ComputeGraph = class extends import_context.Resource {
2943
2904
  if (this._space) {
2944
2905
  const query = this._space.db.query(import_echo.Filter.schema(import_types.FunctionType));
2945
2906
  const unsubscribe = query.subscribe(({ objects }) => {
2946
- this._functions = objects.filter(({ binding }) => binding);
2907
+ this._remoteFunctions = objects.filter(({ binding }) => binding);
2947
2908
  this.update.emit({
2948
2909
  type: "functionsUpdated"
2949
2910
  });
@@ -2957,15 +2918,82 @@ var ComputeGraph = class extends import_context.Resource {
2957
2918
  }
2958
2919
  }
2959
2920
  };
2921
+ var __dxlog_file4 = "/home/runner/work/dxos/dxos/packages/plugins/plugin-sheet/src/graph/compute-graph-registry.ts";
2922
+ var defaultOptions = {
2923
+ licenseKey: "gpl-v3"
2924
+ };
2925
+ var defaultPlugins = [
2926
+ {
2927
+ plugin: EdgeFunctionPlugin,
2928
+ translations: EdgeFunctionPluginTranslations
2929
+ }
2930
+ ];
2931
+ var ComputeGraphRegistry = class extends import_context3.Resource {
2932
+ constructor(options = {
2933
+ plugins: defaultPlugins
2934
+ }) {
2935
+ super();
2936
+ this._graphs = /* @__PURE__ */ new Map();
2937
+ this._options = (0, import_lodash2.default)({}, options, defaultOptions);
2938
+ this._options.plugins?.forEach(({ plugin, translations }) => {
2939
+ import_hyperformula5.HyperFormula.registerFunctionPlugin(plugin, translations);
2940
+ });
2941
+ }
2942
+ getGraph(spaceId) {
2943
+ return this._graphs.get(spaceId);
2944
+ }
2945
+ getOrCreateGraph(space) {
2946
+ let graph = this._graphs.get(space.id);
2947
+ if (!graph) {
2948
+ (0, import_log4.log)("create graph", {
2949
+ space: space.id
2950
+ }, {
2951
+ F: __dxlog_file4,
2952
+ L: 69,
2953
+ S: this,
2954
+ C: (f, a) => f(...a)
2955
+ });
2956
+ graph = this.createGraph(space);
2957
+ }
2958
+ return graph;
2959
+ }
2960
+ createGraph(space) {
2961
+ (0, import_invariant2.invariant)(!this._graphs.has(space.id), `ComputeGraph already exists for space: ${space.id}`, {
2962
+ F: __dxlog_file4,
2963
+ L: 77,
2964
+ S: this,
2965
+ A: [
2966
+ "!this._graphs.has(space.id)",
2967
+ "`ComputeGraph already exists for space: ${space.id}`"
2968
+ ]
2969
+ });
2970
+ const hf = import_hyperformula5.HyperFormula.buildEmpty(this._options);
2971
+ const graph = new ComputeGraph(hf, space, this._options);
2972
+ this._graphs.set(space.id, graph);
2973
+ return graph;
2974
+ }
2975
+ async _close() {
2976
+ for (const graph of this._graphs.values()) {
2977
+ await graph.close();
2978
+ }
2979
+ this._graphs.clear();
2980
+ }
2981
+ };
2960
2982
  // Annotate the CommonJS export names for ESM import in node:
2961
2983
  0 && (module.exports = {
2984
+ AsyncFunctionPlugin,
2962
2985
  ComputeGraph,
2963
2986
  ComputeGraphRegistry,
2964
2987
  ComputeNode,
2988
+ EDGE_FUNCTION_NAME,
2989
+ EdgeFunctionPlugin,
2990
+ EdgeFunctionPluginTranslations,
2991
+ FunctionContext,
2965
2992
  createSheetName,
2993
+ defaultFunctionContextOptions,
2966
2994
  defaultFunctions,
2967
2995
  defaultOptions,
2968
2996
  defaultPlugins,
2969
- getSheetId
2997
+ parseSheetName
2970
2998
  });
2971
- //# sourceMappingURL=chunk-P5QYYEHQ.cjs.map
2999
+ //# sourceMappingURL=chunk-5XPK2V4A.cjs.map