@dxos/compute 0.8.3 → 0.8.4-main.1f223c7

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 (49) hide show
  1. package/dist/lib/browser/{chunk-UGMCTYCW.mjs → chunk-XQYPCRZP.mjs} +156 -94
  2. package/dist/lib/browser/chunk-XQYPCRZP.mjs.map +7 -0
  3. package/dist/lib/browser/index.mjs +1 -1
  4. package/dist/lib/browser/meta.json +1 -1
  5. package/dist/lib/browser/testing/index.mjs +25 -12
  6. package/dist/lib/browser/testing/index.mjs.map +3 -3
  7. package/dist/lib/node-esm/{chunk-WIABMPQE.mjs → chunk-2XWWSGAU.mjs} +156 -94
  8. package/dist/lib/node-esm/chunk-2XWWSGAU.mjs.map +7 -0
  9. package/dist/lib/node-esm/index.mjs +1 -1
  10. package/dist/lib/node-esm/meta.json +1 -1
  11. package/dist/lib/node-esm/testing/index.mjs +25 -12
  12. package/dist/lib/node-esm/testing/index.mjs.map +3 -3
  13. package/dist/types/src/compute-graph-registry.d.ts +2 -4
  14. package/dist/types/src/compute-graph-registry.d.ts.map +1 -1
  15. package/dist/types/src/compute-graph.d.ts +1 -1
  16. package/dist/types/src/compute-graph.d.ts.map +1 -1
  17. package/dist/types/src/compute-node.d.ts +1 -2
  18. package/dist/types/src/compute-node.d.ts.map +1 -1
  19. package/dist/types/src/functions/async-function.d.ts +6 -6
  20. package/dist/types/src/functions/async-function.d.ts.map +1 -1
  21. package/dist/types/src/functions/edge-function.d.ts +3 -3
  22. package/dist/types/src/functions/edge-function.d.ts.map +1 -1
  23. package/dist/types/src/testing/test-plugin.d.ts +4 -5
  24. package/dist/types/src/testing/test-plugin.d.ts.map +1 -1
  25. package/dist/types/src/types/hyperformula.d.ts +3 -6
  26. package/dist/types/src/types/hyperformula.d.ts.map +1 -1
  27. package/dist/types/tsconfig.tsbuildinfo +1 -1
  28. package/package.json +25 -35
  29. package/src/compute-graph-registry.ts +3 -5
  30. package/src/compute-graph.test.ts +2 -2
  31. package/src/compute-graph.ts +5 -6
  32. package/src/compute-node.ts +2 -4
  33. package/src/functions/async-function.ts +12 -8
  34. package/src/functions/edge-function.ts +6 -6
  35. package/src/hyperformula.test.ts +2 -2
  36. package/src/testing/test-plugin.ts +2 -4
  37. package/src/testing/util.ts +1 -1
  38. package/src/types/hyperformula.ts +8 -8
  39. package/src/types/types.test.ts +2 -2
  40. package/dist/lib/browser/chunk-UGMCTYCW.mjs.map +0 -7
  41. package/dist/lib/node/chunk-KCYHSFFU.cjs +0 -3120
  42. package/dist/lib/node/chunk-KCYHSFFU.cjs.map +0 -7
  43. package/dist/lib/node/index.cjs +0 -77
  44. package/dist/lib/node/index.cjs.map +0 -7
  45. package/dist/lib/node/meta.json +0 -1
  46. package/dist/lib/node/testing/index.cjs +0 -188
  47. package/dist/lib/node/testing/index.cjs.map +0 -7
  48. package/dist/lib/node-esm/chunk-WIABMPQE.mjs.map +0 -7
  49. package/dist/vendor/hyperformula.mjs +0 -37145
@@ -1,9 +1,9 @@
1
- // packages/core/compute/src/types/hyperformula.ts
2
- import { DetailedCellError, ExportedCellChange } from "#hyperformula";
1
+ // src/types/hyperformula.ts
2
+ import { DetailedCellError, ExportedCellChange } from "@dxos/vendor-hyperformula";
3
3
 
4
- // packages/core/compute/src/types/types.ts
4
+ // src/types/types.ts
5
5
  import { invariant } from "@dxos/invariant";
6
- var __dxlog_file = "/home/runner/work/dxos/dxos/packages/core/compute/src/types/types.ts";
6
+ var __dxlog_file = "/__w/dxos/dxos/packages/core/compute/src/types/types.ts";
7
7
  var RANGE_NOTATION = /^[A-Z]+[0-9]+(:[A-Z]+[0-9]+)?$/;
8
8
  var isFormula = (value) => typeof value === "string" && value.charAt(0) === "=";
9
9
  var cellEquals = (a, b) => {
@@ -74,14 +74,24 @@ var inRange = (range, cell) => {
74
74
  return col >= cMin && col <= cMax && row >= rMin && row <= rMax;
75
75
  };
76
76
 
77
- // packages/core/compute/src/compute-node.ts
77
+ // src/compute-node.ts
78
78
  import { Event } from "@dxos/async";
79
79
  import { Resource } from "@dxos/context";
80
- import { DetailedCellError as DetailedCellError2 } from "#hyperformula";
81
- var ComputeNode = class extends Resource {
82
- constructor(_graph, sheetId) {
83
- super(), this._graph = _graph, this.sheetId = sheetId, this.update = new Event();
80
+ import { DetailedCellError as DetailedCellError2 } from "@dxos/vendor-hyperformula";
81
+ function _define_property(obj, key, value) {
82
+ if (key in obj) {
83
+ Object.defineProperty(obj, key, {
84
+ value,
85
+ enumerable: true,
86
+ configurable: true,
87
+ writable: true
88
+ });
89
+ } else {
90
+ obj[key] = value;
84
91
  }
92
+ return obj;
93
+ }
94
+ var ComputeNode = class extends Resource {
85
95
  get graph() {
86
96
  return this._graph;
87
97
  }
@@ -114,14 +124,30 @@ var ComputeNode = class extends Resource {
114
124
  // TODO(burdon): Load data into sheet.
115
125
  async _open() {
116
126
  }
127
+ constructor(_graph, sheetId) {
128
+ super(), _define_property(this, "_graph", void 0), _define_property(this, "sheetId", void 0), _define_property(this, "update", void 0), this._graph = _graph, this.sheetId = sheetId, this.update = new Event();
129
+ }
117
130
  };
118
131
 
119
- // packages/core/compute/src/functions/async-function.ts
132
+ // src/functions/async-function.ts
120
133
  import defaultsDeep from "lodash.defaultsdeep";
121
134
  import { debounce } from "@dxos/async";
122
135
  import { log } from "@dxos/log";
123
- import { CellError, ErrorType, EmptyValue, FunctionPlugin } from "#hyperformula";
124
- var __dxlog_file2 = "/home/runner/work/dxos/dxos/packages/core/compute/src/functions/async-function.ts";
136
+ import { CellError, EmptyValue, ErrorType, FunctionPlugin } from "@dxos/vendor-hyperformula";
137
+ function _define_property2(obj, key, value) {
138
+ if (key in obj) {
139
+ Object.defineProperty(obj, key, {
140
+ value,
141
+ enumerable: true,
142
+ configurable: true,
143
+ writable: true
144
+ });
145
+ } else {
146
+ obj[key] = value;
147
+ }
148
+ return obj;
149
+ }
150
+ var __dxlog_file2 = "/__w/dxos/dxos/packages/core/compute/src/functions/async-function.ts";
125
151
  var defaultFunctionContextOptions = {
126
152
  defaultTtl: 5e3,
127
153
  debounceDelay: 200,
@@ -135,25 +161,6 @@ var FunctionContext = class _FunctionContext {
135
161
  ...args
136
162
  });
137
163
  }
138
- constructor(_hf, _space, _options) {
139
- this._hf = _hf;
140
- this._space = _space;
141
- this._cache = /* @__PURE__ */ new Map();
142
- this._pending = /* @__PURE__ */ new Map();
143
- this._subscriptions = /* @__PURE__ */ new Map();
144
- this._invocations = {};
145
- this._options = defaultsDeep(_options ?? {}, defaultFunctionContextOptions);
146
- this._onUpdate = debounce((update) => {
147
- log("update", update, {
148
- F: __dxlog_file2,
149
- L: 86,
150
- S: this,
151
- C: (f, a) => f(...a)
152
- });
153
- this._hf.resumeEvaluation();
154
- this._options.onUpdate?.(update);
155
- }, this._options.debounceDelay);
156
- }
157
164
  get space() {
158
165
  return this._space;
159
166
  }
@@ -202,7 +209,7 @@ var FunctionContext = class _FunctionContext {
202
209
  value: value2
203
210
  }, {
204
211
  F: __dxlog_file2,
205
- L: 144,
212
+ L: 143,
206
213
  S: this,
207
214
  C: (f, a) => f(...a)
208
215
  });
@@ -216,7 +223,7 @@ var FunctionContext = class _FunctionContext {
216
223
  err
217
224
  }, {
218
225
  F: __dxlog_file2,
219
- L: 148,
226
+ L: 147,
220
227
  S: this,
221
228
  C: (f, a) => f(...a)
222
229
  });
@@ -236,12 +243,39 @@ var FunctionContext = class _FunctionContext {
236
243
  cache: value
237
244
  }, {
238
245
  F: __dxlog_file2,
239
- L: 156,
246
+ L: 155,
240
247
  S: this,
241
248
  C: (f, a) => f(...a)
242
249
  });
243
250
  return value;
244
251
  }
252
+ constructor(_hf, _space, _options) {
253
+ _define_property2(this, "_hf", void 0);
254
+ _define_property2(this, "_space", void 0);
255
+ _define_property2(this, "_cache", void 0);
256
+ _define_property2(this, "_pending", void 0);
257
+ _define_property2(this, "_subscriptions", void 0);
258
+ _define_property2(this, "_invocations", void 0);
259
+ _define_property2(this, "_options", void 0);
260
+ _define_property2(this, "_onUpdate", void 0);
261
+ this._hf = _hf;
262
+ this._space = _space;
263
+ this._cache = /* @__PURE__ */ new Map();
264
+ this._pending = /* @__PURE__ */ new Map();
265
+ this._subscriptions = /* @__PURE__ */ new Map();
266
+ this._invocations = {};
267
+ this._options = defaultsDeep(_options ?? {}, defaultFunctionContextOptions);
268
+ this._onUpdate = debounce((update) => {
269
+ log("update", update, {
270
+ F: __dxlog_file2,
271
+ L: 85,
272
+ S: this,
273
+ C: (f, a) => f(...a)
274
+ });
275
+ this._hf.resumeEvaluation();
276
+ this._options.onUpdate?.(update);
277
+ }, this._options.debounceDelay);
278
+ }
245
279
  };
246
280
  var AsyncFunctionPlugin = class extends FunctionPlugin {
247
281
  get context() {
@@ -259,16 +293,16 @@ var AsyncFunctionPlugin = class extends FunctionPlugin {
259
293
  }
260
294
  };
261
295
 
262
- // packages/core/compute/src/functions/edge-function.ts
296
+ // src/functions/edge-function.ts
263
297
  import { effect } from "@preact/signals-core";
264
298
  import { SchemaAST } from "effect";
265
299
  import { Filter, getMeta } from "@dxos/client/echo";
266
300
  import { toEffectSchema } from "@dxos/echo-schema";
267
- import { FunctionType, getUserFunctionUrlInMetadata } from "@dxos/functions";
301
+ import { FunctionType, getUserFunctionIdInMetadata } from "@dxos/functions";
268
302
  import { log as log2 } from "@dxos/log";
269
303
  import { isNonNullable } from "@dxos/util";
270
- import { CellError as CellError2, ErrorType as ErrorType2, FunctionArgumentType } from "#hyperformula";
271
- var __dxlog_file3 = "/home/runner/work/dxos/dxos/packages/core/compute/src/functions/edge-function.ts";
304
+ import { CellError as CellError2, ErrorType as ErrorType2, FunctionArgumentType } from "@dxos/vendor-hyperformula";
305
+ var __dxlog_file3 = "/__w/dxos/dxos/packages/core/compute/src/functions/edge-function.ts";
272
306
  var EDGE_FUNCTION_NAME = "DX";
273
307
  var FUNCTION_TTL = 1e4;
274
308
  var EdgeFunctionPlugin = class extends AsyncFunctionPlugin {
@@ -318,8 +352,8 @@ var EdgeFunctionPlugin = class extends AsyncFunctionPlugin {
318
352
  } else {
319
353
  body.args = args.filter(isNonNullable);
320
354
  }
321
- const path = getUserFunctionUrlInMetadata(getMeta(fn));
322
- const response = await fetch(`${this.context.remoteFunctionUrl}${path}`, {
355
+ const id = getUserFunctionIdInMetadata(getMeta(fn));
356
+ const response = await fetch(`${this.context.remoteFunctionUrl}/${id}`, {
323
357
  method: "POST",
324
358
  headers: {
325
359
  "Content-Type": "application/json"
@@ -396,7 +430,7 @@ var EdgeFunctionPluginTranslations = {
396
430
  }
397
431
  };
398
432
 
399
- // packages/core/compute/src/functions/function-defs.ts
433
+ // src/functions/function-defs.ts
400
434
  var defaultFunctions = [
401
435
  // Array
402
436
  {
@@ -2770,7 +2804,7 @@ var defaultFunctions = [
2770
2804
  }
2771
2805
  ];
2772
2806
 
2773
- // packages/core/compute/src/compute-graph.ts
2807
+ // src/compute-graph.ts
2774
2808
  import { Event as Event2 } from "@dxos/async";
2775
2809
  import { Filter as Filter2, fullyQualifiedId } from "@dxos/client/echo";
2776
2810
  import { FQ_ID_LENGTH } from "@dxos/client/echo";
@@ -2781,8 +2815,21 @@ import { invariant as invariant2 } from "@dxos/invariant";
2781
2815
  import { PublicKey } from "@dxos/keys";
2782
2816
  import { log as log3 } from "@dxos/log";
2783
2817
  import { isNonNullable as isNonNullable2 } from "@dxos/util";
2784
- import { ExportedCellChange as ExportedCellChange2 } from "#hyperformula";
2785
- var __dxlog_file4 = "/home/runner/work/dxos/dxos/packages/core/compute/src/compute-graph.ts";
2818
+ import { ExportedCellChange as ExportedCellChange2 } from "@dxos/vendor-hyperformula";
2819
+ function _define_property3(obj, key, value) {
2820
+ if (key in obj) {
2821
+ Object.defineProperty(obj, key, {
2822
+ value,
2823
+ enumerable: true,
2824
+ configurable: true,
2825
+ writable: true
2826
+ });
2827
+ } else {
2828
+ obj[key] = value;
2829
+ }
2830
+ return obj;
2831
+ }
2832
+ var __dxlog_file4 = "/__w/dxos/dxos/packages/core/compute/src/compute-graph.ts";
2786
2833
  var UNKNOWN_BINDING = "__UNKNOWN__";
2787
2834
  var createSheetName = ({ type, id }) => `${type}@${id}`;
2788
2835
  var parseSheetName = (name) => {
@@ -2795,37 +2842,6 @@ var parseSheetName = (name) => {
2795
2842
  };
2796
2843
  };
2797
2844
  var ComputeGraph = class extends Resource2 {
2798
- constructor(_hf, _space, _options) {
2799
- super(), 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();
2800
- this.context = new FunctionContext(this._hf, this._space, {
2801
- ...this._options,
2802
- onUpdate: (update) => {
2803
- this._options?.onUpdate?.(update);
2804
- this.update.emit({
2805
- type: "valuesUpdated"
2806
- });
2807
- }
2808
- });
2809
- this._hf.updateConfig({
2810
- context: this.context
2811
- });
2812
- const onValuesUpdate = (changes) => {
2813
- for (const change of changes) {
2814
- if (change instanceof ExportedCellChange2) {
2815
- const { sheet } = change;
2816
- const node = this._nodes.get(sheet);
2817
- if (node) {
2818
- node.update.emit({
2819
- type: "valuesUpdated",
2820
- change
2821
- });
2822
- }
2823
- }
2824
- }
2825
- };
2826
- this._hf.on("valuesUpdated", onValuesUpdate);
2827
- this._ctx.onDispose(() => this._hf.off("valuesUpdated", onValuesUpdate));
2828
- }
2829
2845
  get hf() {
2830
2846
  return this._hf;
2831
2847
  }
@@ -2853,7 +2869,7 @@ var ComputeGraph = class extends Resource2 {
2853
2869
  getOrCreateNode(name) {
2854
2870
  invariant2(name.length, void 0, {
2855
2871
  F: __dxlog_file4,
2856
- L: 128,
2872
+ L: 127,
2857
2873
  S: this,
2858
2874
  A: [
2859
2875
  "name.length",
@@ -2866,7 +2882,7 @@ var ComputeGraph = class extends Resource2 {
2866
2882
  sheet: name
2867
2883
  }, {
2868
2884
  F: __dxlog_file4,
2869
- L: 130,
2885
+ L: 129,
2870
2886
  S: this,
2871
2887
  C: (f, a) => f(...a)
2872
2888
  });
@@ -2875,7 +2891,7 @@ var ComputeGraph = class extends Resource2 {
2875
2891
  const sheetId = this._hf.getSheetId(name);
2876
2892
  invariant2(sheetId !== void 0, void 0, {
2877
2893
  F: __dxlog_file4,
2878
- L: 135,
2894
+ L: 134,
2879
2895
  S: this,
2880
2896
  A: [
2881
2897
  "sheetId !== undefined",
@@ -2978,15 +2994,62 @@ var ComputeGraph = class extends Resource2 {
2978
2994
  await node.close();
2979
2995
  }
2980
2996
  }
2997
+ constructor(_hf, _space, _options) {
2998
+ super(), _define_property3(this, "_hf", void 0), _define_property3(this, "_space", void 0), _define_property3(this, "_options", void 0), _define_property3(this, "id", void 0), // Map of nodes indexed by sheet number.
2999
+ _define_property3(this, "_nodes", void 0), // Cached function objects.
3000
+ _define_property3(this, "_remoteFunctions", void 0), _define_property3(this, "update", void 0), // The context is passed to all functions.
3001
+ _define_property3(this, "context", void 0), this._hf = _hf, this._space = _space, this._options = _options, this.id = `graph-${PublicKey.random().truncate()}`, this._nodes = /* @__PURE__ */ new Map(), this._remoteFunctions = [], this.update = new Event2();
3002
+ this.context = new FunctionContext(this._hf, this._space, {
3003
+ ...this._options,
3004
+ onUpdate: (update) => {
3005
+ this._options?.onUpdate?.(update);
3006
+ this.update.emit({
3007
+ type: "valuesUpdated"
3008
+ });
3009
+ }
3010
+ });
3011
+ this._hf.updateConfig({
3012
+ context: this.context
3013
+ });
3014
+ const onValuesUpdate = (changes) => {
3015
+ for (const change of changes) {
3016
+ if (change instanceof ExportedCellChange2) {
3017
+ const { sheet } = change;
3018
+ const node = this._nodes.get(sheet);
3019
+ if (node) {
3020
+ node.update.emit({
3021
+ type: "valuesUpdated",
3022
+ change
3023
+ });
3024
+ }
3025
+ }
3026
+ }
3027
+ };
3028
+ this._hf.on("valuesUpdated", onValuesUpdate);
3029
+ this._ctx.onDispose(() => this._hf.off("valuesUpdated", onValuesUpdate));
3030
+ }
2981
3031
  };
2982
3032
 
2983
- // packages/core/compute/src/compute-graph-registry.ts
3033
+ // src/compute-graph-registry.ts
2984
3034
  import defaultsDeep2 from "lodash.defaultsdeep";
2985
3035
  import { Resource as Resource3 } from "@dxos/context";
2986
3036
  import { invariant as invariant3 } from "@dxos/invariant";
2987
3037
  import { log as log4 } from "@dxos/log";
2988
- import { HyperFormula } from "#hyperformula";
2989
- var __dxlog_file5 = "/home/runner/work/dxos/dxos/packages/core/compute/src/compute-graph-registry.ts";
3038
+ import { HyperFormula } from "@dxos/vendor-hyperformula";
3039
+ function _define_property4(obj, key, value) {
3040
+ if (key in obj) {
3041
+ Object.defineProperty(obj, key, {
3042
+ value,
3043
+ enumerable: true,
3044
+ configurable: true,
3045
+ writable: true
3046
+ });
3047
+ } else {
3048
+ obj[key] = value;
3049
+ }
3050
+ return obj;
3051
+ }
3052
+ var __dxlog_file5 = "/__w/dxos/dxos/packages/core/compute/src/compute-graph-registry.ts";
2990
3053
  var defaultOptions = {
2991
3054
  licenseKey: "gpl-v3"
2992
3055
  };
@@ -2997,16 +3060,6 @@ var defaultPlugins = [
2997
3060
  }
2998
3061
  ];
2999
3062
  var ComputeGraphRegistry = class extends Resource3 {
3000
- constructor(options = {
3001
- plugins: defaultPlugins
3002
- }) {
3003
- super();
3004
- this._graphs = /* @__PURE__ */ new Map();
3005
- this._options = defaultsDeep2({}, options, defaultOptions);
3006
- this._options.plugins?.forEach(({ plugin, translations }) => {
3007
- HyperFormula.registerFunctionPlugin(plugin, translations);
3008
- });
3009
- }
3010
3063
  getGraph(spaceId) {
3011
3064
  return this._graphs.get(spaceId);
3012
3065
  }
@@ -3017,7 +3070,7 @@ var ComputeGraphRegistry = class extends Resource3 {
3017
3070
  space: space.id
3018
3071
  }, {
3019
3072
  F: __dxlog_file5,
3020
- L: 69,
3073
+ L: 67,
3021
3074
  S: this,
3022
3075
  C: (f, a) => f(...a)
3023
3076
  });
@@ -3028,7 +3081,7 @@ var ComputeGraphRegistry = class extends Resource3 {
3028
3081
  createGraph(space) {
3029
3082
  invariant3(!this._graphs.has(space.id), `ComputeGraph already exists for space: ${space.id}`, {
3030
3083
  F: __dxlog_file5,
3031
- L: 77,
3084
+ L: 75,
3032
3085
  S: this,
3033
3086
  A: [
3034
3087
  "!this._graphs.has(space.id)",
@@ -3046,6 +3099,15 @@ var ComputeGraphRegistry = class extends Resource3 {
3046
3099
  }
3047
3100
  this._graphs.clear();
3048
3101
  }
3102
+ constructor(options = {
3103
+ plugins: defaultPlugins
3104
+ }) {
3105
+ super(), _define_property4(this, "_graphs", /* @__PURE__ */ new Map()), _define_property4(this, "_options", void 0);
3106
+ this._options = defaultsDeep2({}, options, defaultOptions);
3107
+ this._options.plugins?.forEach(({ plugin, translations }) => {
3108
+ HyperFormula.registerFunctionPlugin(plugin, translations);
3109
+ });
3110
+ }
3049
3111
  };
3050
3112
 
3051
3113
  export {
@@ -3075,4 +3137,4 @@ export {
3075
3137
  defaultPlugins,
3076
3138
  ComputeGraphRegistry
3077
3139
  };
3078
- //# sourceMappingURL=chunk-UGMCTYCW.mjs.map
3140
+ //# sourceMappingURL=chunk-XQYPCRZP.mjs.map