@dxos/compute 0.8.4-main.5acf9ea → 0.8.4-main.5ea62a8

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.
@@ -80,10 +80,20 @@ var inRange = (range, cell) => {
80
80
  import { Event } from "@dxos/async";
81
81
  import { Resource } from "@dxos/context";
82
82
  import { DetailedCellError as DetailedCellError2 } from "#hyperformula";
83
- var ComputeNode = class extends Resource {
84
- constructor(_graph, sheetId) {
85
- super(), this._graph = _graph, this.sheetId = sheetId, this.update = new Event();
83
+ function _define_property(obj, key, value) {
84
+ if (key in obj) {
85
+ Object.defineProperty(obj, key, {
86
+ value,
87
+ enumerable: true,
88
+ configurable: true,
89
+ writable: true
90
+ });
91
+ } else {
92
+ obj[key] = value;
86
93
  }
94
+ return obj;
95
+ }
96
+ var ComputeNode = class extends Resource {
87
97
  get graph() {
88
98
  return this._graph;
89
99
  }
@@ -116,13 +126,29 @@ var ComputeNode = class extends Resource {
116
126
  // TODO(burdon): Load data into sheet.
117
127
  async _open() {
118
128
  }
129
+ constructor(_graph, sheetId) {
130
+ 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();
131
+ }
119
132
  };
120
133
 
121
134
  // src/functions/async-function.ts
122
135
  import defaultsDeep from "lodash.defaultsdeep";
123
136
  import { debounce } from "@dxos/async";
124
137
  import { log } from "@dxos/log";
125
- import { CellError, ErrorType, EmptyValue, FunctionPlugin } from "#hyperformula";
138
+ import { CellError, EmptyValue, ErrorType, FunctionPlugin } from "#hyperformula";
139
+ function _define_property2(obj, key, value) {
140
+ if (key in obj) {
141
+ Object.defineProperty(obj, key, {
142
+ value,
143
+ enumerable: true,
144
+ configurable: true,
145
+ writable: true
146
+ });
147
+ } else {
148
+ obj[key] = value;
149
+ }
150
+ return obj;
151
+ }
126
152
  var __dxlog_file2 = "/__w/dxos/dxos/packages/core/compute/src/functions/async-function.ts";
127
153
  var defaultFunctionContextOptions = {
128
154
  defaultTtl: 5e3,
@@ -137,25 +163,6 @@ var FunctionContext = class _FunctionContext {
137
163
  ...args
138
164
  });
139
165
  }
140
- constructor(_hf, _space, _options) {
141
- this._hf = _hf;
142
- this._space = _space;
143
- this._cache = /* @__PURE__ */ new Map();
144
- this._pending = /* @__PURE__ */ new Map();
145
- this._subscriptions = /* @__PURE__ */ new Map();
146
- this._invocations = {};
147
- this._options = defaultsDeep(_options ?? {}, defaultFunctionContextOptions);
148
- this._onUpdate = debounce((update) => {
149
- log("update", update, {
150
- F: __dxlog_file2,
151
- L: 86,
152
- S: this,
153
- C: (f, a) => f(...a)
154
- });
155
- this._hf.resumeEvaluation();
156
- this._options.onUpdate?.(update);
157
- }, this._options.debounceDelay);
158
- }
159
166
  get space() {
160
167
  return this._space;
161
168
  }
@@ -244,6 +251,33 @@ var FunctionContext = class _FunctionContext {
244
251
  });
245
252
  return value;
246
253
  }
254
+ constructor(_hf, _space, _options) {
255
+ _define_property2(this, "_hf", void 0);
256
+ _define_property2(this, "_space", void 0);
257
+ _define_property2(this, "_cache", void 0);
258
+ _define_property2(this, "_pending", void 0);
259
+ _define_property2(this, "_subscriptions", void 0);
260
+ _define_property2(this, "_invocations", void 0);
261
+ _define_property2(this, "_options", void 0);
262
+ _define_property2(this, "_onUpdate", void 0);
263
+ this._hf = _hf;
264
+ this._space = _space;
265
+ this._cache = /* @__PURE__ */ new Map();
266
+ this._pending = /* @__PURE__ */ new Map();
267
+ this._subscriptions = /* @__PURE__ */ new Map();
268
+ this._invocations = {};
269
+ this._options = defaultsDeep(_options ?? {}, defaultFunctionContextOptions);
270
+ this._onUpdate = debounce((update) => {
271
+ log("update", update, {
272
+ F: __dxlog_file2,
273
+ L: 86,
274
+ S: this,
275
+ C: (f, a) => f(...a)
276
+ });
277
+ this._hf.resumeEvaluation();
278
+ this._options.onUpdate?.(update);
279
+ }, this._options.debounceDelay);
280
+ }
247
281
  };
248
282
  var AsyncFunctionPlugin = class extends FunctionPlugin {
249
283
  get context() {
@@ -266,7 +300,7 @@ import { effect } from "@preact/signals-core";
266
300
  import { SchemaAST } from "effect";
267
301
  import { Filter, getMeta } from "@dxos/client/echo";
268
302
  import { toEffectSchema } from "@dxos/echo-schema";
269
- import { FunctionType, getUserFunctionUrlInMetadata } from "@dxos/functions";
303
+ import { FunctionType, getUserFunctionIdInMetadata } from "@dxos/functions";
270
304
  import { log as log2 } from "@dxos/log";
271
305
  import { isNonNullable } from "@dxos/util";
272
306
  import { CellError as CellError2, ErrorType as ErrorType2, FunctionArgumentType } from "#hyperformula";
@@ -320,8 +354,8 @@ var EdgeFunctionPlugin = class extends AsyncFunctionPlugin {
320
354
  } else {
321
355
  body.args = args.filter(isNonNullable);
322
356
  }
323
- const path = getUserFunctionUrlInMetadata(getMeta(fn));
324
- const response = await fetch(`${this.context.remoteFunctionUrl}${path}`, {
357
+ const id = getUserFunctionIdInMetadata(getMeta(fn));
358
+ const response = await fetch(`${this.context.remoteFunctionUrl}/${id}`, {
325
359
  method: "POST",
326
360
  headers: {
327
361
  "Content-Type": "application/json"
@@ -2784,6 +2818,19 @@ import { PublicKey } from "@dxos/keys";
2784
2818
  import { log as log3 } from "@dxos/log";
2785
2819
  import { isNonNullable as isNonNullable2 } from "@dxos/util";
2786
2820
  import { ExportedCellChange as ExportedCellChange2 } from "#hyperformula";
2821
+ function _define_property3(obj, key, value) {
2822
+ if (key in obj) {
2823
+ Object.defineProperty(obj, key, {
2824
+ value,
2825
+ enumerable: true,
2826
+ configurable: true,
2827
+ writable: true
2828
+ });
2829
+ } else {
2830
+ obj[key] = value;
2831
+ }
2832
+ return obj;
2833
+ }
2787
2834
  var __dxlog_file4 = "/__w/dxos/dxos/packages/core/compute/src/compute-graph.ts";
2788
2835
  var UNKNOWN_BINDING = "__UNKNOWN__";
2789
2836
  var createSheetName = ({ type, id }) => `${type}@${id}`;
@@ -2797,37 +2844,6 @@ var parseSheetName = (name) => {
2797
2844
  };
2798
2845
  };
2799
2846
  var ComputeGraph = class extends Resource2 {
2800
- constructor(_hf, _space, _options) {
2801
- 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();
2802
- this.context = new FunctionContext(this._hf, this._space, {
2803
- ...this._options,
2804
- onUpdate: (update) => {
2805
- this._options?.onUpdate?.(update);
2806
- this.update.emit({
2807
- type: "valuesUpdated"
2808
- });
2809
- }
2810
- });
2811
- this._hf.updateConfig({
2812
- context: this.context
2813
- });
2814
- const onValuesUpdate = (changes) => {
2815
- for (const change of changes) {
2816
- if (change instanceof ExportedCellChange2) {
2817
- const { sheet } = change;
2818
- const node = this._nodes.get(sheet);
2819
- if (node) {
2820
- node.update.emit({
2821
- type: "valuesUpdated",
2822
- change
2823
- });
2824
- }
2825
- }
2826
- }
2827
- };
2828
- this._hf.on("valuesUpdated", onValuesUpdate);
2829
- this._ctx.onDispose(() => this._hf.off("valuesUpdated", onValuesUpdate));
2830
- }
2831
2847
  get hf() {
2832
2848
  return this._hf;
2833
2849
  }
@@ -2980,6 +2996,40 @@ var ComputeGraph = class extends Resource2 {
2980
2996
  await node.close();
2981
2997
  }
2982
2998
  }
2999
+ constructor(_hf, _space, _options) {
3000
+ 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.
3001
+ _define_property3(this, "_nodes", void 0), // Cached function objects.
3002
+ _define_property3(this, "_remoteFunctions", void 0), _define_property3(this, "update", void 0), // The context is passed to all functions.
3003
+ _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();
3004
+ this.context = new FunctionContext(this._hf, this._space, {
3005
+ ...this._options,
3006
+ onUpdate: (update) => {
3007
+ this._options?.onUpdate?.(update);
3008
+ this.update.emit({
3009
+ type: "valuesUpdated"
3010
+ });
3011
+ }
3012
+ });
3013
+ this._hf.updateConfig({
3014
+ context: this.context
3015
+ });
3016
+ const onValuesUpdate = (changes) => {
3017
+ for (const change of changes) {
3018
+ if (change instanceof ExportedCellChange2) {
3019
+ const { sheet } = change;
3020
+ const node = this._nodes.get(sheet);
3021
+ if (node) {
3022
+ node.update.emit({
3023
+ type: "valuesUpdated",
3024
+ change
3025
+ });
3026
+ }
3027
+ }
3028
+ }
3029
+ };
3030
+ this._hf.on("valuesUpdated", onValuesUpdate);
3031
+ this._ctx.onDispose(() => this._hf.off("valuesUpdated", onValuesUpdate));
3032
+ }
2983
3033
  };
2984
3034
 
2985
3035
  // src/compute-graph-registry.ts
@@ -2988,6 +3038,19 @@ import { Resource as Resource3 } from "@dxos/context";
2988
3038
  import { invariant as invariant3 } from "@dxos/invariant";
2989
3039
  import { log as log4 } from "@dxos/log";
2990
3040
  import { HyperFormula } from "#hyperformula";
3041
+ function _define_property4(obj, key, value) {
3042
+ if (key in obj) {
3043
+ Object.defineProperty(obj, key, {
3044
+ value,
3045
+ enumerable: true,
3046
+ configurable: true,
3047
+ writable: true
3048
+ });
3049
+ } else {
3050
+ obj[key] = value;
3051
+ }
3052
+ return obj;
3053
+ }
2991
3054
  var __dxlog_file5 = "/__w/dxos/dxos/packages/core/compute/src/compute-graph-registry.ts";
2992
3055
  var defaultOptions = {
2993
3056
  licenseKey: "gpl-v3"
@@ -2999,16 +3062,6 @@ var defaultPlugins = [
2999
3062
  }
3000
3063
  ];
3001
3064
  var ComputeGraphRegistry = class extends Resource3 {
3002
- constructor(options = {
3003
- plugins: defaultPlugins
3004
- }) {
3005
- super();
3006
- this._graphs = /* @__PURE__ */ new Map();
3007
- this._options = defaultsDeep2({}, options, defaultOptions);
3008
- this._options.plugins?.forEach(({ plugin, translations }) => {
3009
- HyperFormula.registerFunctionPlugin(plugin, translations);
3010
- });
3011
- }
3012
3065
  getGraph(spaceId) {
3013
3066
  return this._graphs.get(spaceId);
3014
3067
  }
@@ -3048,6 +3101,15 @@ var ComputeGraphRegistry = class extends Resource3 {
3048
3101
  }
3049
3102
  this._graphs.clear();
3050
3103
  }
3104
+ constructor(options = {
3105
+ plugins: defaultPlugins
3106
+ }) {
3107
+ super(), _define_property4(this, "_graphs", /* @__PURE__ */ new Map()), _define_property4(this, "_options", void 0);
3108
+ this._options = defaultsDeep2({}, options, defaultOptions);
3109
+ this._options.plugins?.forEach(({ plugin, translations }) => {
3110
+ HyperFormula.registerFunctionPlugin(plugin, translations);
3111
+ });
3112
+ }
3051
3113
  };
3052
3114
 
3053
3115
  export {
@@ -3077,4 +3139,4 @@ export {
3077
3139
  defaultPlugins,
3078
3140
  ComputeGraphRegistry
3079
3141
  };
3080
- //# sourceMappingURL=chunk-DZMSWKOY.mjs.map
3142
+ //# sourceMappingURL=chunk-6GVHPKPB.mjs.map