@dxos/compute 0.8.4-main.b97322e → 0.8.4-main.bcb3aa67d6

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 (59) hide show
  1. package/dist/lib/{browser/chunk-AURNYRCC.mjs → neutral/chunk-23PT47U5.mjs} +112 -86
  2. package/dist/lib/neutral/chunk-23PT47U5.mjs.map +7 -0
  3. package/dist/lib/{browser → neutral}/index.mjs +1 -1
  4. package/dist/lib/neutral/meta.json +1 -0
  5. package/dist/lib/{browser → neutral}/testing/index.mjs +31 -6
  6. package/dist/lib/neutral/testing/index.mjs.map +7 -0
  7. package/dist/types/src/compute-graph-registry.d.ts +10 -7
  8. package/dist/types/src/compute-graph-registry.d.ts.map +1 -1
  9. package/dist/types/src/compute-graph-registry.test.d.ts +2 -0
  10. package/dist/types/src/compute-graph-registry.test.d.ts.map +1 -0
  11. package/dist/types/src/compute-graph.d.ts +10 -7
  12. package/dist/types/src/compute-graph.d.ts.map +1 -1
  13. package/dist/types/src/compute-node.d.ts +1 -2
  14. package/dist/types/src/compute-node.d.ts.map +1 -1
  15. package/dist/types/src/functions/async-function.d.ts +13 -11
  16. package/dist/types/src/functions/async-function.d.ts.map +1 -1
  17. package/dist/types/src/functions/edge-function.d.ts +3 -3
  18. package/dist/types/src/functions/edge-function.d.ts.map +1 -1
  19. package/dist/types/src/index.d.ts.map +1 -1
  20. package/dist/types/src/testing/index.d.ts +1 -0
  21. package/dist/types/src/testing/index.d.ts.map +1 -1
  22. package/dist/types/src/testing/test-builder.d.ts +1 -1
  23. package/dist/types/src/testing/test-builder.d.ts.map +1 -1
  24. package/dist/types/src/testing/test-plugin.d.ts +4 -5
  25. package/dist/types/src/testing/test-plugin.d.ts.map +1 -1
  26. package/dist/types/src/testing/test-runtime.d.ts +10 -0
  27. package/dist/types/src/testing/test-runtime.d.ts.map +1 -0
  28. package/dist/types/src/types/hyperformula.d.ts +3 -6
  29. package/dist/types/src/types/hyperformula.d.ts.map +1 -1
  30. package/dist/types/tsconfig.tsbuildinfo +1 -1
  31. package/package.json +31 -33
  32. package/src/compute-graph-registry.test.ts +167 -0
  33. package/src/compute-graph-registry.ts +20 -14
  34. package/src/compute-graph.test.ts +63 -13
  35. package/src/compute-graph.ts +44 -38
  36. package/src/compute-node.ts +2 -5
  37. package/src/functions/async-function.ts +21 -16
  38. package/src/functions/edge-function.ts +33 -32
  39. package/src/hyperformula.test.ts +2 -2
  40. package/src/index.ts +0 -27
  41. package/src/testing/index.ts +1 -0
  42. package/src/testing/test-builder.ts +8 -2
  43. package/src/testing/test-plugin.ts +2 -5
  44. package/src/testing/test-runtime.ts +36 -0
  45. package/src/testing/util.ts +1 -1
  46. package/src/types/hyperformula.ts +8 -8
  47. package/src/types/types.test.ts +2 -2
  48. package/dist/lib/browser/chunk-AURNYRCC.mjs.map +0 -7
  49. package/dist/lib/browser/meta.json +0 -1
  50. package/dist/lib/browser/testing/index.mjs.map +0 -7
  51. package/dist/lib/node-esm/chunk-DZMSWKOY.mjs +0 -3080
  52. package/dist/lib/node-esm/chunk-DZMSWKOY.mjs.map +0 -7
  53. package/dist/lib/node-esm/index.mjs +0 -56
  54. package/dist/lib/node-esm/index.mjs.map +0 -7
  55. package/dist/lib/node-esm/meta.json +0 -1
  56. package/dist/lib/node-esm/testing/index.mjs +0 -174
  57. package/dist/lib/node-esm/testing/index.mjs.map +0 -7
  58. package/dist/vendor/hyperformula.mjs +0 -36400
  59. /package/dist/lib/{browser → neutral}/index.mjs.map +0 -0
package/package.json CHANGED
@@ -1,29 +1,27 @@
1
1
  {
2
2
  "name": "@dxos/compute",
3
- "version": "0.8.4-main.b97322e",
3
+ "version": "0.8.4-main.bcb3aa67d6",
4
4
  "description": "Low-level compute API",
5
5
  "homepage": "https://dxos.org",
6
6
  "bugs": "https://github.com/dxos/dxos/issues",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "https://github.com/dxos/dxos"
10
+ },
7
11
  "license": "MIT",
8
12
  "author": "DXOS.org",
9
13
  "sideEffects": true,
10
14
  "type": "module",
11
- "imports": {
12
- "#hyperformula": {
13
- "types": "hyperformula",
14
- "default": "./dist/vendor/hyperformula.mjs"
15
- }
16
- },
17
15
  "exports": {
18
16
  ".": {
17
+ "source": "./src/index.ts",
19
18
  "types": "./dist/types/src/index.d.ts",
20
- "browser": "./dist/lib/browser/index.mjs",
21
- "node": "./dist/lib/node-esm/index.mjs"
19
+ "default": "./dist/lib/neutral/index.mjs"
22
20
  },
23
21
  "./testing": {
22
+ "source": "./src/testing/index.ts",
24
23
  "types": "./dist/types/src/testing/index.d.ts",
25
- "browser": "./dist/lib/browser/testing/index.mjs",
26
- "node": "./dist/lib/node-esm/testing/index.mjs"
24
+ "default": "./dist/lib/neutral/testing/index.mjs"
27
25
  }
28
26
  },
29
27
  "types": "dist/types/src/index.d.ts",
@@ -39,35 +37,35 @@
39
37
  "src"
40
38
  ],
41
39
  "dependencies": {
42
- "@preact/signals-core": "^1.9.0",
43
- "effect": "3.17.0",
44
- "hyperformula": "^2.7.1",
40
+ "effect": "3.20.0",
45
41
  "lodash.defaultsdeep": "^4.6.1",
46
- "@dxos/async": "0.8.4-main.b97322e",
47
- "@dxos/client": "0.8.4-main.b97322e",
48
- "@dxos/debug": "0.8.4-main.b97322e",
49
- "@dxos/context": "0.8.4-main.b97322e",
50
- "@dxos/echo": "0.8.4-main.b97322e",
51
- "@dxos/echo-db": "0.8.4-main.b97322e",
52
- "@dxos/echo-schema": "0.8.4-main.b97322e",
53
- "@dxos/functions": "0.8.4-main.b97322e",
54
- "@dxos/invariant": "0.8.4-main.b97322e",
55
- "@dxos/keys": "0.8.4-main.b97322e",
56
- "@dxos/log": "0.8.4-main.b97322e",
57
- "@dxos/live-object": "0.8.4-main.b97322e",
58
- "@dxos/protocols": "0.8.4-main.b97322e",
59
- "@dxos/schema": "0.8.4-main.b97322e",
60
- "@dxos/util": "0.8.4-main.b97322e"
42
+ "@dxos/async": "0.8.4-main.bcb3aa67d6",
43
+ "@dxos/context": "0.8.4-main.bcb3aa67d6",
44
+ "@dxos/debug": "0.8.4-main.bcb3aa67d6",
45
+ "@dxos/echo": "0.8.4-main.bcb3aa67d6",
46
+ "@dxos/ai": "0.8.4-main.bcb3aa67d6",
47
+ "@dxos/client": "0.8.4-main.bcb3aa67d6",
48
+ "@dxos/functions": "0.8.4-main.bcb3aa67d6",
49
+ "@dxos/invariant": "0.8.4-main.bcb3aa67d6",
50
+ "@dxos/keys": "0.8.4-main.bcb3aa67d6",
51
+ "@dxos/functions-runtime": "0.8.4-main.bcb3aa67d6",
52
+ "@dxos/operation": "0.8.4-main.bcb3aa67d6",
53
+ "@dxos/log": "0.8.4-main.bcb3aa67d6",
54
+ "@dxos/schema": "0.8.4-main.bcb3aa67d6",
55
+ "@dxos/vendor-hyperformula": "0.8.4-main.bcb3aa67d6",
56
+ "@dxos/plugin-automation": "0.8.4-main.bcb3aa67d6",
57
+ "@dxos/util": "0.8.4-main.bcb3aa67d6",
58
+ "@dxos/protocols": "0.8.4-main.bcb3aa67d6"
61
59
  },
62
60
  "devDependencies": {
63
61
  "@tldraw/indices": "^2.0.0-alpha.14",
64
62
  "@types/lodash.defaultsdeep": "^4.6.6",
65
- "@dxos/echo-db": "0.8.4-main.b97322e",
66
- "@dxos/random": "0.8.4-main.b97322e",
67
- "@dxos/echo-schema": "0.8.4-main.b97322e"
63
+ "@dxos/echo": "0.8.4-main.bcb3aa67d6",
64
+ "@dxos/echo-db": "0.8.4-main.bcb3aa67d6",
65
+ "@dxos/random": "0.8.4-main.bcb3aa67d6"
68
66
  },
69
67
  "peerDependencies": {
70
- "effect": "^3.13.3"
68
+ "effect": "3.20.0"
71
69
  },
72
70
  "publishConfig": {
73
71
  "access": "public"
@@ -0,0 +1,167 @@
1
+ //
2
+ // Copyright 2025 DXOS.org
3
+ //
4
+
5
+ import * as Effect from 'effect/Effect';
6
+ import * as Schema from 'effect/Schema';
7
+ import { describe, expect, onTestFinished, test } from 'vitest';
8
+
9
+ import { Trigger } from '@dxos/async';
10
+ import { Obj } from '@dxos/echo';
11
+ import { Operation, OperationHandlerSet } from '@dxos/operation';
12
+
13
+ import { ComputeGraphRegistry, defaultPlugins } from './compute-graph-registry';
14
+ import { TestBuilder, createMockedComputeRuntimeProvider } from './testing';
15
+
16
+ const AddDefinition = Operation.make({
17
+ meta: {
18
+ key: 'add',
19
+ name: 'add',
20
+ description: 'Adds two numbers',
21
+ },
22
+ input: Schema.Struct({ a: Schema.Number, b: Schema.Number }),
23
+ output: Schema.Number,
24
+ services: [],
25
+ });
26
+
27
+ const add = AddDefinition.pipe(
28
+ Operation.withHandler(
29
+ Effect.fn(function* ({ a, b }) {
30
+ return a + b;
31
+ }),
32
+ ),
33
+ );
34
+
35
+ describe('ComputeGraphRegistry', () => {
36
+ test('invokes user function through compute graph', async () => {
37
+ const computeRuntime = createMockedComputeRuntimeProvider({
38
+ functions: OperationHandlerSet.make(add),
39
+ });
40
+ const testBuilder = new TestBuilder({
41
+ types: [Operation.PersistentOperation],
42
+ computeRuntime,
43
+ });
44
+ await testBuilder.open();
45
+ onTestFinished(async () => {
46
+ await testBuilder.close();
47
+ });
48
+
49
+ const space = await testBuilder.client.spaces.create();
50
+
51
+ // Register Edge function plugin and runtime in the registry.
52
+ const registry = new ComputeGraphRegistry({
53
+ plugins: defaultPlugins,
54
+ computeRuntime,
55
+ });
56
+ await registry.open();
57
+ onTestFinished(async () => {
58
+ await registry.close();
59
+ });
60
+
61
+ const graph = registry.createGraph(space);
62
+ await graph.open();
63
+ onTestFinished(async () => {
64
+ await graph.close();
65
+ });
66
+
67
+ const functionObj = Operation.serialize(add);
68
+ Obj.change(functionObj, (obj) => {
69
+ obj.binding = 'ADD';
70
+ });
71
+ space.db.add(functionObj);
72
+
73
+ const node = await graph.getOrCreateNode('sheet').open();
74
+
75
+ // Wait for value update after async invocation completes.
76
+ const trigger = new Trigger<number>();
77
+ node.update.on(() => {
78
+ const value = node.getValue({ row: 0, col: 0 });
79
+ if (typeof value === 'number') {
80
+ trigger.wake(value);
81
+ }
82
+ });
83
+
84
+ // Set formula using binding; graph will map to DX("ADD", ...)
85
+ node.setValue({ row: 0, col: 0 }, '=ADD(2, 3)');
86
+
87
+ const result = await trigger.wait();
88
+ expect(result).to.equal(5);
89
+
90
+ // Sanity check: mapping to fully qualified id works as well.
91
+ const bindingId = graph.mapFunctionBindingToId('ADD(2, 3)');
92
+ expect(bindingId.startsWith(`${Obj.getDXN(functionObj).toString()}`)).to.be.true;
93
+ });
94
+
95
+ test('adding a function binding updates autocomplete and enables execution', async () => {
96
+ const computeRuntime = createMockedComputeRuntimeProvider({
97
+ functions: OperationHandlerSet.make(add),
98
+ });
99
+ const testBuilder = new TestBuilder({
100
+ types: [Operation.PersistentOperation],
101
+ computeRuntime,
102
+ });
103
+ await testBuilder.open();
104
+ onTestFinished(async () => {
105
+ await testBuilder.close();
106
+ });
107
+
108
+ const space = await testBuilder.client.spaces.create();
109
+
110
+ const registry = new ComputeGraphRegistry({
111
+ plugins: defaultPlugins,
112
+ computeRuntime,
113
+ });
114
+ await registry.open();
115
+ onTestFinished(async () => {
116
+ await registry.close();
117
+ });
118
+
119
+ const graph = registry.createGraph(space);
120
+ await graph.open();
121
+ onTestFinished(async () => {
122
+ await graph.close();
123
+ });
124
+
125
+ // Initially there should be no echo functions.
126
+ expect(graph.getFunctions({ standard: false, echo: true }).length).to.equal(0);
127
+
128
+ // Subscribe for function updates.
129
+ const functionsUpdated = new Trigger<void>();
130
+ const unsubscribe = graph.update.on((e) => {
131
+ if (e.type === 'functionsUpdated') {
132
+ functionsUpdated.wake();
133
+ }
134
+ });
135
+ onTestFinished(unsubscribe);
136
+
137
+ const functionObj = Operation.serialize(add);
138
+ Obj.change(functionObj, (obj) => {
139
+ obj.binding = 'ADD';
140
+ });
141
+ space.db.add(functionObj);
142
+
143
+ await functionsUpdated.wait();
144
+
145
+ // Autocomplete should now include the binding.
146
+ const echoFunctions = graph.getFunctions({ standard: false, echo: true }).map((fn) => fn.name);
147
+ expect(echoFunctions).toContain('ADD');
148
+
149
+ // And the binding should execute when used in a formula.
150
+ const node = await graph.getOrCreateNode('sheet').open();
151
+ onTestFinished(async () => {
152
+ await node.close();
153
+ });
154
+
155
+ const valueSettled = new Trigger<number>();
156
+ node.update.on(() => {
157
+ const value = node.getValue({ row: 0, col: 0 });
158
+ if (typeof value === 'number') {
159
+ valueSettled.wake(value);
160
+ }
161
+ });
162
+
163
+ node.setValue({ row: 0, col: 0 }, '=ADD(2, 3)');
164
+ const result = await valueSettled.wait();
165
+ expect(result).to.equal(5);
166
+ });
167
+ });
@@ -2,17 +2,16 @@
2
2
  // Copyright 2024 DXOS.org
3
3
  //
4
4
 
5
- import type { FunctionPluginDefinition } from 'hyperformula';
6
- import type { ConfigParams } from 'hyperformula/typings/ConfigParams';
7
- import type { FunctionTranslationsPackage } from 'hyperformula/typings/interpreter';
5
+ import type * as ManagedRuntime from 'effect/ManagedRuntime';
8
6
  import defaultsDeep from 'lodash.defaultsdeep';
9
7
 
10
- import { type SpaceId, type Space } from '@dxos/client/echo';
8
+ import { type Space, type SpaceId } from '@dxos/client/echo';
11
9
  import { Resource } from '@dxos/context';
10
+ import { type FunctionInvocationService } from '@dxos/functions';
12
11
  import { invariant } from '@dxos/invariant';
13
12
  import { log } from '@dxos/log';
14
-
15
- import { HyperFormula } from '#hyperformula';
13
+ import type { ConfigParams, FunctionPluginDefinition, FunctionTranslationsPackage } from '@dxos/vendor-hyperformula';
14
+ import { HyperFormula } from '@dxos/vendor-hyperformula';
16
15
 
17
16
  import { ComputeGraph } from './compute-graph';
18
17
  import { EdgeFunctionPlugin, EdgeFunctionPluginTranslations, type FunctionContextOptions } from './functions';
@@ -22,15 +21,16 @@ export type ComputeGraphPlugin = {
22
21
  translations: FunctionTranslationsPackage;
23
22
  };
24
23
 
24
+ export type FunctionsRuntimeProvider = {
25
+ getRuntime(spaceId: SpaceId): ManagedRuntime.ManagedRuntime<FunctionInvocationService, never>;
26
+ };
27
+
25
28
  export type ComputeGraphOptions = {
26
29
  plugins?: ComputeGraphPlugin[];
30
+ computeRuntime: FunctionsRuntimeProvider;
27
31
  } & Partial<FunctionContextOptions> &
28
32
  Partial<ConfigParams>;
29
33
 
30
- export const defaultOptions: ComputeGraphOptions = {
31
- licenseKey: 'gpl-v3',
32
- };
33
-
34
34
  export const defaultPlugins: ComputeGraphPlugin[] = [
35
35
  {
36
36
  plugin: EdgeFunctionPlugin,
@@ -38,23 +38,26 @@ export const defaultPlugins: ComputeGraphPlugin[] = [
38
38
  },
39
39
  ];
40
40
 
41
+ export const defaultOptions: Partial<ComputeGraphOptions> = {
42
+ licenseKey: 'gpl-v3',
43
+ };
44
+
41
45
  /**
42
46
  * Manages a collection of ComputeGraph instances for each space.
43
47
  *
44
48
  * [ComputePlugin] => [ComputeGraphRegistry] => [ComputeGraph(Space)] => [ComputeNode(Object)]
45
49
  *
46
50
  * NOTE: The ComputeGraphRegistry manages the hierarchy of resources via its root Context.
47
- * NOTE: The package.json file defines the packaged #hyperformula module.
48
51
  */
49
52
  // TODO(burdon): Move graph into separate plugin; isolate HF deps.
50
53
  export class ComputeGraphRegistry extends Resource {
51
54
  private readonly _graphs = new Map<SpaceId, ComputeGraph>();
52
-
53
55
  private readonly _options: ComputeGraphOptions;
54
56
 
55
- constructor(options: ComputeGraphOptions = { plugins: defaultPlugins }) {
57
+ constructor(options: ComputeGraphOptions) {
56
58
  super();
57
59
  this._options = defaultsDeep({}, options, defaultOptions);
60
+ this._options.plugins = this._options.plugins ?? defaultPlugins;
58
61
  this._options.plugins?.forEach(({ plugin, translations }) => {
59
62
  HyperFormula.registerFunctionPlugin(plugin, translations);
60
63
  });
@@ -77,7 +80,10 @@ export class ComputeGraphRegistry extends Resource {
77
80
  createGraph(space: Space): ComputeGraph {
78
81
  invariant(!this._graphs.has(space.id), `ComputeGraph already exists for space: ${space.id}`);
79
82
  const hf = HyperFormula.buildEmpty(this._options);
80
- const graph = new ComputeGraph(hf, space, this._options);
83
+ invariant(this._options.computeRuntime, 'ComputeRuntime is required');
84
+ const runtime = this._options.computeRuntime.getRuntime(space.id);
85
+
86
+ const graph = new ComputeGraph(hf, runtime, space, this._options);
81
87
  this._graphs.set(space.id, graph);
82
88
  return graph;
83
89
  }
@@ -2,22 +2,20 @@
2
2
  // Copyright 2024 DXOS.org
3
3
  //
4
4
 
5
- import { type CellValue } from 'hyperformula';
6
5
  import { afterEach, beforeEach, describe, expect, test } from 'vitest';
7
6
 
8
7
  import { Trigger } from '@dxos/async';
9
- import { fullyQualifiedId } from '@dxos/client/echo';
10
8
  import { Obj } from '@dxos/echo';
11
- import { FunctionType } from '@dxos/functions';
12
-
13
- import { DetailedCellError } from '#hyperformula';
9
+ import { Operation } from '@dxos/operation';
10
+ import { type CellValue } from '@dxos/vendor-hyperformula';
11
+ import { DetailedCellError } from '@dxos/vendor-hyperformula';
14
12
 
15
13
  import { TestBuilder } from './testing';
16
14
 
17
15
  describe('ComputeGraph', () => {
18
16
  let testBuilder: TestBuilder;
19
17
  beforeEach(async () => {
20
- testBuilder = new TestBuilder({ types: [FunctionType] });
18
+ testBuilder = new TestBuilder({ types: [Operation.PersistentOperation] });
21
19
  await testBuilder.open();
22
20
  });
23
21
  afterEach(async () => {
@@ -32,13 +30,45 @@ describe('ComputeGraph', () => {
32
30
  // Create script.
33
31
  const trigger = new Trigger();
34
32
  graph.update.once(() => trigger.wake());
35
- const functionObject = space.db.add(Obj.make(FunctionType, { name: 'test', version: '0.0.1', binding: 'TEST' }));
33
+ const functionObject = space.db.add(
34
+ Obj.make(Operation.PersistentOperation, { name: 'test', version: '0.0.1', binding: 'TEST' }),
35
+ );
36
36
  await trigger.wait();
37
37
  const functions = graph.getFunctions({ echo: true });
38
38
  expect(functions).to.toHaveLength(1);
39
39
 
40
40
  const id = graph.mapFunctionBindingToId('TEST()');
41
- expect(id).to.eq(`${fullyQualifiedId(functionObject)}()`);
41
+ expect(id).to.eq(`${Obj.getDXN(functionObject).toString()}()`);
42
+
43
+ const restored = graph.mapFunctionBindingFromId(id);
44
+ expect(restored).to.eq('TEST()');
45
+ });
46
+
47
+ test('map functions roundtrip with args', async () => {
48
+ const space = await testBuilder.client.spaces.create();
49
+ const graph = testBuilder.registry.createGraph(space);
50
+ await graph.open();
51
+
52
+ const trigger = new Trigger();
53
+ graph.update.once(() => trigger.wake());
54
+ space.db.add(Obj.make(Operation.PersistentOperation, { name: 'forex', version: '0.0.1', binding: 'FOREX' }));
55
+ await trigger.wait();
56
+
57
+ const stored = graph.mapFunctionBindingToId('=FOREX(C6,C7)');
58
+ expect(stored).to.include('dxn:echo:');
59
+ expect(stored).not.to.include('FOREX');
60
+
61
+ const restored = graph.mapFunctionBindingFromId(stored);
62
+ expect(restored).to.eq('=FOREX(C6,C7)');
63
+ });
64
+
65
+ test('map functions unknown binding returns undefined', async () => {
66
+ const space = await testBuilder.client.spaces.create();
67
+ const graph = testBuilder.registry.createGraph(space);
68
+ await graph.open();
69
+
70
+ const result = graph.mapFunctionBindingFromId('=dxn:echo:@:01ABCDEF01ABCDEF01ABCDEF01(A1,B1)');
71
+ expect(result).to.be.undefined;
42
72
  });
43
73
 
44
74
  test('cross-node references', async () => {
@@ -53,22 +83,38 @@ describe('ComputeGraph', () => {
53
83
  {
54
84
  node1.graph.hf.setCellContents({ sheet: node1.sheetId, row: 0, col: 0 }, [[100, 200, 300, '=SUM(A1:C1)']]);
55
85
  node2.graph.hf.setCellContents({ sheet: node2.sheetId, row: 0, col: 0 }, "='node-1'!D1");
56
- const value1 = node1.graph.hf.getCellValue({ sheet: node1.sheetId, col: 3, row: 0 });
57
- const value2 = node2.graph.hf.getCellValue({ sheet: node2.sheetId, col: 0, row: 0 });
86
+ const value1 = node1.graph.hf.getCellValue({
87
+ sheet: node1.sheetId,
88
+ col: 3,
89
+ row: 0,
90
+ });
91
+ const value2 = node2.graph.hf.getCellValue({
92
+ sheet: node2.sheetId,
93
+ col: 0,
94
+ row: 0,
95
+ });
58
96
  expect(value1).to.eq(value2);
59
97
  }
60
98
 
61
99
  // Get updated event.
62
100
  const trigger = new Trigger<CellValue>();
63
101
  node2.update.on(({ change }) => {
64
- const value = node2.graph.hf.getCellValue({ sheet: node2.sheetId, col: 0, row: 0 });
102
+ const value = node2.graph.hf.getCellValue({
103
+ sheet: node2.sheetId,
104
+ col: 0,
105
+ row: 0,
106
+ });
65
107
  expect(value).to.eq(change?.newValue);
66
108
  trigger.wake(value);
67
109
  });
68
110
 
69
111
  {
70
112
  node1.graph.hf.setCellContents({ sheet: node1.sheetId, row: 0, col: 0 }, 400);
71
- const value1 = node1.graph.hf.getCellValue({ sheet: node1.sheetId, col: 3, row: 0 });
113
+ const value1 = node1.graph.hf.getCellValue({
114
+ sheet: node1.sheetId,
115
+ col: 3,
116
+ row: 0,
117
+ });
72
118
  const value2 = await trigger.wait();
73
119
  expect(value1).to.eq(value2);
74
120
  }
@@ -82,7 +128,11 @@ describe('ComputeGraph', () => {
82
128
 
83
129
  const node1 = await graph.getOrCreateNode('node-1').open();
84
130
  node1.graph.hf.setCellContents({ sheet: node1.sheetId, row: 0, col: 0 }, "='node-2'!A1");
85
- const value1 = node1.graph.hf.getCellValue({ sheet: node1.sheetId, col: 0, row: 0 });
131
+ const value1 = node1.graph.hf.getCellValue({
132
+ sheet: node1.sheetId,
133
+ col: 0,
134
+ row: 0,
135
+ });
86
136
  expect(value1).to.be.instanceof(DetailedCellError);
87
137
  expect((value1 as DetailedCellError).type).to.eq('REF');
88
138
  });
@@ -2,28 +2,28 @@
2
2
  // Copyright 2024 DXOS.org
3
3
  //
4
4
 
5
- import { type Listeners } from 'hyperformula/typings/Emitter';
5
+ import type * as ManagedRuntime from 'effect/ManagedRuntime';
6
6
 
7
7
  import { Event } from '@dxos/async';
8
- import { type Space, Filter, fullyQualifiedId } from '@dxos/client/echo';
9
- import { FQ_ID_LENGTH } from '@dxos/client/echo';
8
+ import { Filter, type Space } from '@dxos/client/echo';
10
9
  import { Resource } from '@dxos/context';
11
- import { getTypename } from '@dxos/echo-schema';
12
- import { FunctionType } from '@dxos/functions';
10
+ import { Obj } from '@dxos/echo';
11
+ import { type FunctionInvocationService } from '@dxos/functions';
12
+ import { Operation } from '@dxos/operation';
13
13
  import { invariant } from '@dxos/invariant';
14
14
  import { PublicKey } from '@dxos/keys';
15
15
  import { log } from '@dxos/log';
16
16
  import { isNonNullable } from '@dxos/util';
17
-
18
- import { ExportedCellChange, type HyperFormula } from '#hyperformula';
17
+ import type { Listeners } from '@dxos/vendor-hyperformula';
18
+ import { ExportedCellChange, type HyperFormula } from '@dxos/vendor-hyperformula';
19
19
 
20
20
  import { ComputeNode } from './compute-node';
21
21
  import {
22
- defaultFunctions,
22
+ EDGE_FUNCTION_NAME,
23
23
  FunctionContext,
24
24
  type FunctionContextOptions,
25
25
  type FunctionDefinition,
26
- EDGE_FUNCTION_NAME,
26
+ defaultFunctions,
27
27
  } from './functions';
28
28
 
29
29
  // TODO(burdon): Factor out compute-graph.
@@ -37,7 +37,7 @@ type ObjectRef = { type: string; id: string };
37
37
 
38
38
  /**
39
39
  * Marker for sheets that are managed by an ECHO object.
40
- * Sheet ID: `dxos.org/type/SheetType@1234`
40
+ * Sheet ID: `org.dxos.type.sheet-type@1234`
41
41
  */
42
42
  export const createSheetName = ({ type, id }: ObjectRef) => `${type}@${id}`;
43
43
  export const parseSheetName = (name: string): Partial<ObjectRef> => {
@@ -60,7 +60,7 @@ export class ComputeGraph extends Resource {
60
60
  private readonly _nodes = new Map<number, ComputeNode>();
61
61
 
62
62
  // Cached function objects.
63
- private _remoteFunctions: FunctionType[] = [];
63
+ private _remoteFunctions: Operation.PersistentOperation[] = [];
64
64
 
65
65
  public readonly update = new Event<{ type: ComputeGraphEvent }>();
66
66
 
@@ -69,12 +69,13 @@ export class ComputeGraph extends Resource {
69
69
 
70
70
  constructor(
71
71
  private readonly _hf: HyperFormula,
72
+ private readonly _runtime: ManagedRuntime.ManagedRuntime<FunctionInvocationService, never>,
72
73
  private readonly _space?: Space,
73
74
  private readonly _options?: Partial<FunctionContextOptions>,
74
75
  ) {
75
76
  super();
76
77
 
77
- this.context = new FunctionContext(this._hf, this._space, {
78
+ this.context = new FunctionContext(this._hf, this._runtime, this._space, {
78
79
  ...this._options,
79
80
  onUpdate: (update) => {
80
81
  this._options?.onUpdate?.(update);
@@ -105,7 +106,10 @@ export class ComputeGraph extends Resource {
105
106
  }
106
107
 
107
108
  getFunctions(
108
- { standard, echo }: { standard?: boolean; echo?: boolean } = { standard: true, echo: true },
109
+ { standard, echo }: { standard?: boolean; echo?: boolean } = {
110
+ standard: true,
111
+ echo: true,
112
+ },
109
113
  ): FunctionDefinition[] {
110
114
  return [
111
115
  ...(standard
@@ -149,7 +153,7 @@ export class ComputeGraph extends Resource {
149
153
  formula
150
154
  //
151
155
  // Map cross-sheet references by name onto sheet stored by ECHO object/model.
152
- // Example: "Test Sheet"!A0 => "dxos.org/type/SheetType@1234"!A0
156
+ // Example: "Test Sheet"!A0 => "org.dxos.type.sheet-type@1234"!A0
153
157
  // https://hyperformula.handsontable.com/guide/cell-references.html#cell-references
154
158
  //
155
159
  .replace(/['"]?([ \w]+)['"]?!/, (_match, name) => {
@@ -165,7 +169,7 @@ export class ComputeGraph extends Resource {
165
169
 
166
170
  for (const obj of objects) {
167
171
  if (obj.name === name) {
168
- const type = getTypename(obj)!;
172
+ const type = Obj.getTypename(obj)!;
169
173
  // NOTE: Names must be single quoted.
170
174
  return `'${createSheetName({ type, id: obj.id })}'!`;
171
175
  }
@@ -194,8 +198,8 @@ export class ComputeGraph extends Resource {
194
198
  }
195
199
 
196
200
  /**
197
- * Map from binding to fully qualified ECHO ID (to store).
198
- * E.g., HELLO() => spaceId:objectId()
201
+ * Map from binding to fully qualified ECHO DXN (to store).
202
+ * E.g., HELLO() => dxn:echo:spaceId:objectId()
199
203
  */
200
204
  mapFunctionBindingToId(formula: string): string {
201
205
  return formula.replace(/(\w+)\((.*)\)/g, (match, binding, args) => {
@@ -205,7 +209,7 @@ export class ComputeGraph extends Resource {
205
209
 
206
210
  const fn = this._remoteFunctions.find((fn) => fn.binding === binding);
207
211
  if (fn) {
208
- const id = fullyQualifiedId(fn);
212
+ const id = Obj.getDXN(fn).toString();
209
213
  return `${id}(${args})`;
210
214
  } else {
211
215
  return match;
@@ -214,23 +218,22 @@ export class ComputeGraph extends Resource {
214
218
  }
215
219
 
216
220
  /**
217
- * Map from fully qualified ECHO ID to binding (from store).
218
- * E.g., spaceId:objectId() => HELLO()
221
+ * Map from fully qualified ECHO DXN to binding (from store).
222
+ * E.g., dxn:echo:spaceId:objectId() => HELLO()
219
223
  */
220
224
  mapFunctionBindingFromId(formula: string): string | undefined {
221
- const binding = formula.replace(/(\w+):([a-zA-Z0-9]+)\((.*)\)/g, (match, spaceId, objectId, args) => {
222
- const id = `${spaceId}:${objectId}`;
223
- if (id.length !== FQ_ID_LENGTH) {
224
- return match;
225
- }
226
-
227
- const fn = this._remoteFunctions.find((fn) => fullyQualifiedId(fn) === id);
228
- if (fn?.binding) {
229
- return `${fn.binding}(${args})`;
230
- } else {
231
- return UNKNOWN_BINDING;
232
- }
233
- });
225
+ const binding = formula.replace(
226
+ /dxn:([^:]+):([^:(]+):([a-zA-Z0-9]+)\((.*)\)/g,
227
+ (_match, kind, spaceTag, objectId, args) => {
228
+ const dxn = `dxn:${kind}:${spaceTag}:${objectId}`;
229
+ const fn = this._remoteFunctions.find((fn) => Obj.getDXN(fn).toString() === dxn);
230
+ if (fn?.binding) {
231
+ return `${fn.binding}(${args})`;
232
+ } else {
233
+ return UNKNOWN_BINDING;
234
+ }
235
+ },
236
+ );
234
237
 
235
238
  if (binding.startsWith(`=${UNKNOWN_BINDING}`)) {
236
239
  return undefined;
@@ -242,11 +245,14 @@ export class ComputeGraph extends Resource {
242
245
  protected override async _open(): Promise<void> {
243
246
  if (this._space) {
244
247
  // Subscribe to remote function definitions.
245
- const query = this._space.db.query(Filter.type(FunctionType));
246
- const unsubscribe = query.subscribe(({ objects }) => {
247
- this._remoteFunctions = objects.filter(({ binding }) => binding);
248
- this.update.emit({ type: 'functionsUpdated' });
249
- });
248
+ const query = this._space.db.query(Filter.type(Operation.PersistentOperation));
249
+ const unsubscribe = query.subscribe(
250
+ () => {
251
+ this._remoteFunctions = query.results.filter((fn) => fn.binding);
252
+ this.update.emit({ type: 'functionsUpdated' });
253
+ },
254
+ { fire: true },
255
+ );
250
256
 
251
257
  this._ctx.onDispose(unsubscribe);
252
258
  }
@@ -2,13 +2,10 @@
2
2
  // Copyright 2024 DXOS.org
3
3
  //
4
4
 
5
- import { type Listeners } from 'hyperformula/typings/Emitter';
6
- import { type ExportedCellChange } from 'hyperformula/typings/Exporter';
7
-
8
5
  import { Event } from '@dxos/async';
9
6
  import { Resource } from '@dxos/context';
10
-
11
- import { DetailedCellError } from '#hyperformula';
7
+ import { type ExportedCellChange, type Listeners } from '@dxos/vendor-hyperformula';
8
+ import { DetailedCellError } from '@dxos/vendor-hyperformula';
12
9
 
13
10
  import { type ComputeGraph } from './compute-graph';
14
11
  import { type CellAddress, type CellScalarValue, isFormula } from './types';