@dxos/compute 0.8.4-main.c4373fc → 0.8.4-main.c85a9c8dae
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/chunk-C7KLV2IU.mjs → neutral/chunk-KGBGT4NT.mjs} +111 -149
- package/dist/lib/neutral/chunk-KGBGT4NT.mjs.map +7 -0
- package/dist/lib/{browser → neutral}/index.mjs +1 -1
- package/dist/lib/neutral/meta.json +1 -0
- package/dist/lib/{browser → neutral}/testing/index.mjs +12 -20
- package/dist/lib/neutral/testing/index.mjs.map +7 -0
- package/dist/types/src/compute-graph.d.ts.map +1 -1
- package/dist/types/src/functions/edge-function.d.ts.map +1 -1
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/testing/test-runtime.d.ts +1 -1
- package/dist/types/src/testing/test-runtime.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +28 -27
- package/src/compute-graph-registry.test.ts +32 -12
- package/src/compute-graph.test.ts +29 -10
- package/src/compute-graph.ts +14 -11
- package/src/functions/edge-function.ts +12 -13
- package/src/index.ts +0 -27
- package/src/testing/test-runtime.ts +7 -10
- package/dist/lib/browser/chunk-C7KLV2IU.mjs.map +0 -7
- package/dist/lib/browser/meta.json +0 -1
- package/dist/lib/browser/testing/index.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-K37OSZ5O.mjs +0 -3146
- package/dist/lib/node-esm/chunk-K37OSZ5O.mjs.map +0 -7
- package/dist/lib/node-esm/index.mjs +0 -56
- package/dist/lib/node-esm/index.mjs.map +0 -7
- package/dist/lib/node-esm/meta.json +0 -1
- package/dist/lib/node-esm/testing/index.mjs +0 -207
- package/dist/lib/node-esm/testing/index.mjs.map +0 -7
- /package/dist/lib/{browser → neutral}/index.mjs.map +0 -0
package/package.json
CHANGED
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dxos/compute",
|
|
3
|
-
"version": "0.8.4-main.
|
|
3
|
+
"version": "0.8.4-main.c85a9c8dae",
|
|
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,
|
|
@@ -12,14 +16,12 @@
|
|
|
12
16
|
".": {
|
|
13
17
|
"source": "./src/index.ts",
|
|
14
18
|
"types": "./dist/types/src/index.d.ts",
|
|
15
|
-
"
|
|
16
|
-
"node": "./dist/lib/node-esm/index.mjs"
|
|
19
|
+
"default": "./dist/lib/neutral/index.mjs"
|
|
17
20
|
},
|
|
18
21
|
"./testing": {
|
|
19
22
|
"source": "./src/testing/index.ts",
|
|
20
23
|
"types": "./dist/types/src/testing/index.d.ts",
|
|
21
|
-
"
|
|
22
|
-
"node": "./dist/lib/node-esm/testing/index.mjs"
|
|
24
|
+
"default": "./dist/lib/neutral/testing/index.mjs"
|
|
23
25
|
}
|
|
24
26
|
},
|
|
25
27
|
"types": "dist/types/src/index.d.ts",
|
|
@@ -35,35 +37,34 @@
|
|
|
35
37
|
"src"
|
|
36
38
|
],
|
|
37
39
|
"dependencies": {
|
|
38
|
-
"
|
|
39
|
-
"effect": "3.18.3",
|
|
40
|
+
"effect": "3.19.16",
|
|
40
41
|
"lodash.defaultsdeep": "^4.6.1",
|
|
41
|
-
"@dxos/
|
|
42
|
-
"@dxos/
|
|
43
|
-
"@dxos/context": "0.8.4-main.
|
|
44
|
-
"@dxos/
|
|
45
|
-
"@dxos/functions": "0.8.4-main.
|
|
46
|
-
"@dxos/
|
|
47
|
-
"@dxos/
|
|
48
|
-
"@dxos/invariant": "0.8.4-main.
|
|
49
|
-
"@dxos/
|
|
50
|
-
"@dxos/
|
|
51
|
-
"@dxos/
|
|
52
|
-
"@dxos/
|
|
53
|
-
"@dxos/
|
|
54
|
-
"@dxos/schema": "0.8.4-main.
|
|
55
|
-
"@dxos/
|
|
56
|
-
"@dxos/
|
|
42
|
+
"@dxos/async": "0.8.4-main.c85a9c8dae",
|
|
43
|
+
"@dxos/client": "0.8.4-main.c85a9c8dae",
|
|
44
|
+
"@dxos/context": "0.8.4-main.c85a9c8dae",
|
|
45
|
+
"@dxos/echo": "0.8.4-main.c85a9c8dae",
|
|
46
|
+
"@dxos/functions": "0.8.4-main.c85a9c8dae",
|
|
47
|
+
"@dxos/functions-runtime": "0.8.4-main.c85a9c8dae",
|
|
48
|
+
"@dxos/debug": "0.8.4-main.c85a9c8dae",
|
|
49
|
+
"@dxos/invariant": "0.8.4-main.c85a9c8dae",
|
|
50
|
+
"@dxos/keys": "0.8.4-main.c85a9c8dae",
|
|
51
|
+
"@dxos/log": "0.8.4-main.c85a9c8dae",
|
|
52
|
+
"@dxos/plugin-automation": "0.8.4-main.c85a9c8dae",
|
|
53
|
+
"@dxos/protocols": "0.8.4-main.c85a9c8dae",
|
|
54
|
+
"@dxos/util": "0.8.4-main.c85a9c8dae",
|
|
55
|
+
"@dxos/schema": "0.8.4-main.c85a9c8dae",
|
|
56
|
+
"@dxos/vendor-hyperformula": "0.8.4-main.c85a9c8dae",
|
|
57
|
+
"@dxos/ai": "0.8.4-main.c85a9c8dae"
|
|
57
58
|
},
|
|
58
59
|
"devDependencies": {
|
|
59
60
|
"@tldraw/indices": "^2.0.0-alpha.14",
|
|
60
61
|
"@types/lodash.defaultsdeep": "^4.6.6",
|
|
61
|
-
"@dxos/echo": "0.8.4-main.
|
|
62
|
-
"@dxos/
|
|
63
|
-
"@dxos/
|
|
62
|
+
"@dxos/echo": "0.8.4-main.c85a9c8dae",
|
|
63
|
+
"@dxos/echo-db": "0.8.4-main.c85a9c8dae",
|
|
64
|
+
"@dxos/random": "0.8.4-main.c85a9c8dae"
|
|
64
65
|
},
|
|
65
66
|
"peerDependencies": {
|
|
66
|
-
"effect": "
|
|
67
|
+
"effect": "3.19.16"
|
|
67
68
|
},
|
|
68
69
|
"publishConfig": {
|
|
69
70
|
"access": "public"
|
|
@@ -6,8 +6,8 @@ import * as Schema from 'effect/Schema';
|
|
|
6
6
|
import { describe, expect, onTestFinished, test } from 'vitest';
|
|
7
7
|
|
|
8
8
|
import { Trigger } from '@dxos/async';
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
9
|
+
import { Obj } from '@dxos/echo';
|
|
10
|
+
import { Function, FunctionDefinition } from '@dxos/functions';
|
|
11
11
|
|
|
12
12
|
import { ComputeGraphRegistry, defaultPlugins } from './compute-graph-registry';
|
|
13
13
|
import { TestBuilder, createMockedComputeRuntimeProvider } from './testing';
|
|
@@ -23,8 +23,13 @@ describe('ComputeGraphRegistry', () => {
|
|
|
23
23
|
});
|
|
24
24
|
|
|
25
25
|
test('invokes user function through compute graph', async () => {
|
|
26
|
-
const computeRuntime = createMockedComputeRuntimeProvider({
|
|
27
|
-
|
|
26
|
+
const computeRuntime = createMockedComputeRuntimeProvider({
|
|
27
|
+
functions: [add],
|
|
28
|
+
});
|
|
29
|
+
const testBuilder = new TestBuilder({
|
|
30
|
+
types: [Function.Function],
|
|
31
|
+
computeRuntime,
|
|
32
|
+
});
|
|
28
33
|
await testBuilder.open();
|
|
29
34
|
onTestFinished(async () => {
|
|
30
35
|
await testBuilder.close();
|
|
@@ -33,7 +38,10 @@ describe('ComputeGraphRegistry', () => {
|
|
|
33
38
|
const space = await testBuilder.client.spaces.create();
|
|
34
39
|
|
|
35
40
|
// Register Edge function plugin and runtime in the registry.
|
|
36
|
-
const registry = new ComputeGraphRegistry({
|
|
41
|
+
const registry = new ComputeGraphRegistry({
|
|
42
|
+
plugins: defaultPlugins,
|
|
43
|
+
computeRuntime,
|
|
44
|
+
});
|
|
37
45
|
await registry.open();
|
|
38
46
|
onTestFinished(async () => {
|
|
39
47
|
await registry.close();
|
|
@@ -47,7 +55,9 @@ describe('ComputeGraphRegistry', () => {
|
|
|
47
55
|
|
|
48
56
|
// Create a function object in ECHO with binding that maps to DX calls.
|
|
49
57
|
const functionObj = FunctionDefinition.serialize(add);
|
|
50
|
-
functionObj
|
|
58
|
+
Obj.change(functionObj, (f) => {
|
|
59
|
+
f.binding = 'ADD';
|
|
60
|
+
});
|
|
51
61
|
space.db.add(functionObj);
|
|
52
62
|
|
|
53
63
|
const node = await graph.getOrCreateNode('sheet').open();
|
|
@@ -69,12 +79,17 @@ describe('ComputeGraphRegistry', () => {
|
|
|
69
79
|
|
|
70
80
|
// Sanity check: mapping to fully qualified id works as well.
|
|
71
81
|
const bindingId = graph.mapFunctionBindingToId('ADD(2, 3)');
|
|
72
|
-
expect(bindingId.startsWith(`${
|
|
82
|
+
expect(bindingId.startsWith(`${Obj.getDXN(functionObj).toString()}`)).to.be.true;
|
|
73
83
|
});
|
|
74
84
|
|
|
75
85
|
test('adding a function binding updates autocomplete and enables execution', async () => {
|
|
76
|
-
const computeRuntime = createMockedComputeRuntimeProvider({
|
|
77
|
-
|
|
86
|
+
const computeRuntime = createMockedComputeRuntimeProvider({
|
|
87
|
+
functions: [add],
|
|
88
|
+
});
|
|
89
|
+
const testBuilder = new TestBuilder({
|
|
90
|
+
types: [Function.Function],
|
|
91
|
+
computeRuntime,
|
|
92
|
+
});
|
|
78
93
|
await testBuilder.open();
|
|
79
94
|
onTestFinished(async () => {
|
|
80
95
|
await testBuilder.close();
|
|
@@ -82,7 +97,10 @@ describe('ComputeGraphRegistry', () => {
|
|
|
82
97
|
|
|
83
98
|
const space = await testBuilder.client.spaces.create();
|
|
84
99
|
|
|
85
|
-
const registry = new ComputeGraphRegistry({
|
|
100
|
+
const registry = new ComputeGraphRegistry({
|
|
101
|
+
plugins: defaultPlugins,
|
|
102
|
+
computeRuntime,
|
|
103
|
+
});
|
|
86
104
|
await registry.open();
|
|
87
105
|
onTestFinished(async () => {
|
|
88
106
|
await registry.close();
|
|
@@ -108,13 +126,15 @@ describe('ComputeGraphRegistry', () => {
|
|
|
108
126
|
|
|
109
127
|
// Add a bound function to the space; graph should pick it up.
|
|
110
128
|
const functionObj = FunctionDefinition.serialize(add);
|
|
111
|
-
functionObj
|
|
129
|
+
Obj.change(functionObj, (f) => {
|
|
130
|
+
f.binding = 'ADD';
|
|
131
|
+
});
|
|
112
132
|
space.db.add(functionObj);
|
|
113
133
|
|
|
114
134
|
await functionsUpdated.wait();
|
|
115
135
|
|
|
116
136
|
// Autocomplete should now include the binding.
|
|
117
|
-
const echoFunctions = graph.getFunctions({ standard: false, echo: true }).map((
|
|
137
|
+
const echoFunctions = graph.getFunctions({ standard: false, echo: true }).map((fn) => fn.name);
|
|
118
138
|
expect(echoFunctions).toContain('ADD');
|
|
119
139
|
|
|
120
140
|
// And the binding should execute when used in a formula.
|
|
@@ -5,9 +5,8 @@
|
|
|
5
5
|
import { afterEach, beforeEach, describe, expect, test } from 'vitest';
|
|
6
6
|
|
|
7
7
|
import { Trigger } from '@dxos/async';
|
|
8
|
-
import { fullyQualifiedId } from '@dxos/client/echo';
|
|
9
8
|
import { Obj } from '@dxos/echo';
|
|
10
|
-
import {
|
|
9
|
+
import { Function } from '@dxos/functions';
|
|
11
10
|
import { type CellValue } from '@dxos/vendor-hyperformula';
|
|
12
11
|
import { DetailedCellError } from '@dxos/vendor-hyperformula';
|
|
13
12
|
|
|
@@ -16,7 +15,7 @@ import { TestBuilder } from './testing';
|
|
|
16
15
|
describe('ComputeGraph', () => {
|
|
17
16
|
let testBuilder: TestBuilder;
|
|
18
17
|
beforeEach(async () => {
|
|
19
|
-
testBuilder = new TestBuilder({ types: [
|
|
18
|
+
testBuilder = new TestBuilder({ types: [Function.Function] });
|
|
20
19
|
await testBuilder.open();
|
|
21
20
|
});
|
|
22
21
|
afterEach(async () => {
|
|
@@ -31,13 +30,13 @@ describe('ComputeGraph', () => {
|
|
|
31
30
|
// Create script.
|
|
32
31
|
const trigger = new Trigger();
|
|
33
32
|
graph.update.once(() => trigger.wake());
|
|
34
|
-
const functionObject = space.db.add(
|
|
33
|
+
const functionObject = space.db.add(Function.make({ name: 'test', version: '0.0.1', binding: 'TEST' }));
|
|
35
34
|
await trigger.wait();
|
|
36
35
|
const functions = graph.getFunctions({ echo: true });
|
|
37
36
|
expect(functions).to.toHaveLength(1);
|
|
38
37
|
|
|
39
38
|
const id = graph.mapFunctionBindingToId('TEST()');
|
|
40
|
-
expect(id).to.eq(`${
|
|
39
|
+
expect(id).to.eq(`${Obj.getDXN(functionObject).toString()}()`);
|
|
41
40
|
});
|
|
42
41
|
|
|
43
42
|
test('cross-node references', async () => {
|
|
@@ -52,22 +51,38 @@ describe('ComputeGraph', () => {
|
|
|
52
51
|
{
|
|
53
52
|
node1.graph.hf.setCellContents({ sheet: node1.sheetId, row: 0, col: 0 }, [[100, 200, 300, '=SUM(A1:C1)']]);
|
|
54
53
|
node2.graph.hf.setCellContents({ sheet: node2.sheetId, row: 0, col: 0 }, "='node-1'!D1");
|
|
55
|
-
const value1 = node1.graph.hf.getCellValue({
|
|
56
|
-
|
|
54
|
+
const value1 = node1.graph.hf.getCellValue({
|
|
55
|
+
sheet: node1.sheetId,
|
|
56
|
+
col: 3,
|
|
57
|
+
row: 0,
|
|
58
|
+
});
|
|
59
|
+
const value2 = node2.graph.hf.getCellValue({
|
|
60
|
+
sheet: node2.sheetId,
|
|
61
|
+
col: 0,
|
|
62
|
+
row: 0,
|
|
63
|
+
});
|
|
57
64
|
expect(value1).to.eq(value2);
|
|
58
65
|
}
|
|
59
66
|
|
|
60
67
|
// Get updated event.
|
|
61
68
|
const trigger = new Trigger<CellValue>();
|
|
62
69
|
node2.update.on(({ change }) => {
|
|
63
|
-
const value = node2.graph.hf.getCellValue({
|
|
70
|
+
const value = node2.graph.hf.getCellValue({
|
|
71
|
+
sheet: node2.sheetId,
|
|
72
|
+
col: 0,
|
|
73
|
+
row: 0,
|
|
74
|
+
});
|
|
64
75
|
expect(value).to.eq(change?.newValue);
|
|
65
76
|
trigger.wake(value);
|
|
66
77
|
});
|
|
67
78
|
|
|
68
79
|
{
|
|
69
80
|
node1.graph.hf.setCellContents({ sheet: node1.sheetId, row: 0, col: 0 }, 400);
|
|
70
|
-
const value1 = node1.graph.hf.getCellValue({
|
|
81
|
+
const value1 = node1.graph.hf.getCellValue({
|
|
82
|
+
sheet: node1.sheetId,
|
|
83
|
+
col: 3,
|
|
84
|
+
row: 0,
|
|
85
|
+
});
|
|
71
86
|
const value2 = await trigger.wait();
|
|
72
87
|
expect(value1).to.eq(value2);
|
|
73
88
|
}
|
|
@@ -81,7 +96,11 @@ describe('ComputeGraph', () => {
|
|
|
81
96
|
|
|
82
97
|
const node1 = await graph.getOrCreateNode('node-1').open();
|
|
83
98
|
node1.graph.hf.setCellContents({ sheet: node1.sheetId, row: 0, col: 0 }, "='node-2'!A1");
|
|
84
|
-
const value1 = node1.graph.hf.getCellValue({
|
|
99
|
+
const value1 = node1.graph.hf.getCellValue({
|
|
100
|
+
sheet: node1.sheetId,
|
|
101
|
+
col: 0,
|
|
102
|
+
row: 0,
|
|
103
|
+
});
|
|
85
104
|
expect(value1).to.be.instanceof(DetailedCellError);
|
|
86
105
|
expect((value1 as DetailedCellError).type).to.eq('REF');
|
|
87
106
|
});
|
package/src/compute-graph.ts
CHANGED
|
@@ -5,11 +5,11 @@
|
|
|
5
5
|
import type * as ManagedRuntime from 'effect/ManagedRuntime';
|
|
6
6
|
|
|
7
7
|
import { Event } from '@dxos/async';
|
|
8
|
-
import { Filter, type Space
|
|
8
|
+
import { Filter, type Space } from '@dxos/client/echo';
|
|
9
9
|
import { FQ_ID_LENGTH } from '@dxos/client/echo';
|
|
10
10
|
import { Resource } from '@dxos/context';
|
|
11
|
-
import {
|
|
12
|
-
import { type FunctionInvocationService
|
|
11
|
+
import { Obj } from '@dxos/echo';
|
|
12
|
+
import { Function, type FunctionInvocationService } from '@dxos/functions';
|
|
13
13
|
import { invariant } from '@dxos/invariant';
|
|
14
14
|
import { PublicKey } from '@dxos/keys';
|
|
15
15
|
import { log } from '@dxos/log';
|
|
@@ -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:
|
|
63
|
+
private _remoteFunctions: Function.Function[] = [];
|
|
64
64
|
|
|
65
65
|
public readonly update = new Event<{ type: ComputeGraphEvent }>();
|
|
66
66
|
|
|
@@ -106,7 +106,10 @@ export class ComputeGraph extends Resource {
|
|
|
106
106
|
}
|
|
107
107
|
|
|
108
108
|
getFunctions(
|
|
109
|
-
{ standard, echo }: { standard?: boolean; echo?: boolean } = {
|
|
109
|
+
{ standard, echo }: { standard?: boolean; echo?: boolean } = {
|
|
110
|
+
standard: true,
|
|
111
|
+
echo: true,
|
|
112
|
+
},
|
|
110
113
|
): FunctionDefinition[] {
|
|
111
114
|
return [
|
|
112
115
|
...(standard
|
|
@@ -166,7 +169,7 @@ export class ComputeGraph extends Resource {
|
|
|
166
169
|
|
|
167
170
|
for (const obj of objects) {
|
|
168
171
|
if (obj.name === name) {
|
|
169
|
-
const type = getTypename(obj)!;
|
|
172
|
+
const type = Obj.getTypename(obj)!;
|
|
170
173
|
// NOTE: Names must be single quoted.
|
|
171
174
|
return `'${createSheetName({ type, id: obj.id })}'!`;
|
|
172
175
|
}
|
|
@@ -206,7 +209,7 @@ export class ComputeGraph extends Resource {
|
|
|
206
209
|
|
|
207
210
|
const fn = this._remoteFunctions.find((fn) => fn.binding === binding);
|
|
208
211
|
if (fn) {
|
|
209
|
-
const id =
|
|
212
|
+
const id = Obj.getDXN(fn).toString();
|
|
210
213
|
return `${id}(${args})`;
|
|
211
214
|
} else {
|
|
212
215
|
return match;
|
|
@@ -225,7 +228,7 @@ export class ComputeGraph extends Resource {
|
|
|
225
228
|
return match;
|
|
226
229
|
}
|
|
227
230
|
|
|
228
|
-
const fn = this._remoteFunctions.find((fn) =>
|
|
231
|
+
const fn = this._remoteFunctions.find((fn) => Obj.getDXN(fn).toString() === id);
|
|
229
232
|
if (fn?.binding) {
|
|
230
233
|
return `${fn.binding}(${args})`;
|
|
231
234
|
} else {
|
|
@@ -243,9 +246,9 @@ export class ComputeGraph extends Resource {
|
|
|
243
246
|
protected override async _open(): Promise<void> {
|
|
244
247
|
if (this._space) {
|
|
245
248
|
// Subscribe to remote function definitions.
|
|
246
|
-
const query = this._space.db.query(Filter.type(
|
|
247
|
-
const unsubscribe = query.subscribe((
|
|
248
|
-
this._remoteFunctions =
|
|
249
|
+
const query = this._space.db.query(Filter.type(Function.Function));
|
|
250
|
+
const unsubscribe = query.subscribe(() => {
|
|
251
|
+
this._remoteFunctions = query.results.filter((fn) => fn.binding);
|
|
249
252
|
this.update.emit({ type: 'functionsUpdated' });
|
|
250
253
|
});
|
|
251
254
|
|
|
@@ -2,13 +2,12 @@
|
|
|
2
2
|
// Copyright 2024 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import { effect } from '@preact/signals-core';
|
|
6
5
|
import * as Effect from 'effect/Effect';
|
|
7
6
|
import * as SchemaAST from 'effect/SchemaAST';
|
|
8
7
|
|
|
9
8
|
import { Filter } from '@dxos/client/echo';
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
9
|
+
import { JsonSchema, Obj } from '@dxos/echo';
|
|
10
|
+
import { Function, FunctionInvocationService, TracingService } from '@dxos/functions';
|
|
12
11
|
import { FunctionDefinition } from '@dxos/functions';
|
|
13
12
|
import { log } from '@dxos/log';
|
|
14
13
|
import { isNonNullable } from '@dxos/util';
|
|
@@ -36,22 +35,20 @@ export class EdgeFunctionPlugin extends AsyncFunctionPlugin {
|
|
|
36
35
|
return new CellError(ErrorType.REF, 'Missing space');
|
|
37
36
|
}
|
|
38
37
|
|
|
39
|
-
const {
|
|
40
|
-
objects: [fn],
|
|
41
|
-
} = await space.db.query(Filter.type(FunctionType, { binding })).run();
|
|
38
|
+
const [fn] = await space.db.query(Filter.type(Function.Function, { binding })).run();
|
|
42
39
|
if (!fn) {
|
|
43
40
|
log.info('Function not found', { binding });
|
|
44
41
|
return new CellError(ErrorType.REF, 'Function not found');
|
|
45
42
|
}
|
|
46
43
|
|
|
47
44
|
if (subscribe) {
|
|
48
|
-
const unsubscribe =
|
|
45
|
+
const unsubscribe = Obj.subscribe(fn, () => {
|
|
49
46
|
log('function changed', { fn });
|
|
50
|
-
const _ = fn?.version;
|
|
51
|
-
|
|
52
47
|
// TODO(wittjosiah): `ttl` should be 0 to force a recalculation when a new version is deployed.
|
|
53
48
|
// This needs a ttl to prevent a binding change from causing the function not to be found.
|
|
54
|
-
this.runAsyncFunction(ast, state, handler(false), {
|
|
49
|
+
this.runAsyncFunction(ast, state, handler(false), {
|
|
50
|
+
ttl: FUNCTION_TTL,
|
|
51
|
+
});
|
|
55
52
|
});
|
|
56
53
|
|
|
57
54
|
this.context.createSubscription(ast.procedureName, unsubscribe);
|
|
@@ -62,7 +59,7 @@ export class EdgeFunctionPlugin extends AsyncFunctionPlugin {
|
|
|
62
59
|
// If input schema exists, construct an object from args using the schema props order, otherwise pass { args }.
|
|
63
60
|
let input: any;
|
|
64
61
|
if (fn.inputSchema) {
|
|
65
|
-
const schema = toEffectSchema(fn.inputSchema);
|
|
62
|
+
const schema = JsonSchema.toEffectSchema(fn.inputSchema);
|
|
66
63
|
const props = SchemaAST.getPropertySignatures(schema.ast);
|
|
67
64
|
input = {} as any;
|
|
68
65
|
props.forEach(({ name }, index) => {
|
|
@@ -74,12 +71,14 @@ export class EdgeFunctionPlugin extends AsyncFunctionPlugin {
|
|
|
74
71
|
const result = runtime.runPromise(
|
|
75
72
|
Effect.gen(function* () {
|
|
76
73
|
return yield* FunctionInvocationService.invokeFunction(functionDef, input);
|
|
77
|
-
}).pipe(Effect.provide(
|
|
74
|
+
}).pipe(Effect.provide(TracingService.layerNoop)),
|
|
78
75
|
);
|
|
79
76
|
return result as any;
|
|
80
77
|
};
|
|
81
78
|
|
|
82
|
-
return this.runAsyncFunction(ast, state, handler(true), {
|
|
79
|
+
return this.runAsyncFunction(ast, state, handler(true), {
|
|
80
|
+
ttl: FUNCTION_TTL,
|
|
81
|
+
});
|
|
83
82
|
}
|
|
84
83
|
}
|
|
85
84
|
|
package/src/index.ts
CHANGED
|
@@ -2,33 +2,6 @@
|
|
|
2
2
|
// Copyright 2024 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
// TODO(burdon): Separate hyperformula (client compute) from remote/edge functions.
|
|
6
|
-
|
|
7
|
-
// TODO(burdon): Reconcile: types.
|
|
8
|
-
// - dxos/graph
|
|
9
|
-
// - dxos/compute
|
|
10
|
-
// - dxos/functions
|
|
11
|
-
// - dxos/assistant
|
|
12
|
-
// - dxos/plugin-automation
|
|
13
|
-
// - dxos/plugin-script
|
|
14
|
-
// - dxos/plugin-sheet
|
|
15
|
-
|
|
16
|
-
// TODO(burdon): Tech debt.
|
|
17
|
-
// - move hyperformula defs from sheet to compute.
|
|
18
|
-
// - standard from ./types exports for plugins.
|
|
19
|
-
// - dxos/agent
|
|
20
|
-
// - dxos/agent-functions
|
|
21
|
-
// - dxos/mosaic, dxos-card
|
|
22
|
-
|
|
23
|
-
// TODO(burdon): Reconcile UX.
|
|
24
|
-
// - dxos/plugin-explorer
|
|
25
|
-
// - dxos/plugin-canvas
|
|
26
|
-
// - dxos/gem-*
|
|
27
|
-
|
|
28
|
-
// TODO(burdon): Next
|
|
29
|
-
// - dxos/plugin-search
|
|
30
|
-
// - dxos/plugin-threads
|
|
31
|
-
|
|
32
5
|
export * from './compute-graph';
|
|
33
6
|
export * from './compute-graph-registry';
|
|
34
7
|
export * from './compute-node';
|
|
@@ -7,13 +7,9 @@ import * as ManagedRuntime from 'effect/ManagedRuntime';
|
|
|
7
7
|
|
|
8
8
|
import { AiService } from '@dxos/ai';
|
|
9
9
|
import { type SpaceId } from '@dxos/client/echo';
|
|
10
|
-
import {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
type FunctionDefinition,
|
|
14
|
-
FunctionInvocationService,
|
|
15
|
-
QueueService,
|
|
16
|
-
} from '@dxos/functions';
|
|
10
|
+
import { Database, Feed } from '@dxos/echo';
|
|
11
|
+
import { CredentialsService, type FunctionDefinition, QueueService } from '@dxos/functions';
|
|
12
|
+
import { FunctionInvocationServiceLayerTest } from '@dxos/functions-runtime/testing';
|
|
17
13
|
|
|
18
14
|
import { type FunctionsRuntimeProvider } from '../compute-graph-registry';
|
|
19
15
|
|
|
@@ -23,15 +19,16 @@ import { type FunctionsRuntimeProvider } from '../compute-graph-registry';
|
|
|
23
19
|
*/
|
|
24
20
|
export const createMockedComputeRuntimeProvider = ({
|
|
25
21
|
functions,
|
|
26
|
-
}: { functions?: FunctionDefinition
|
|
22
|
+
}: { functions?: FunctionDefinition.Any[] } = {}): FunctionsRuntimeProvider => {
|
|
27
23
|
return {
|
|
28
24
|
getRuntime: (_spaceId: SpaceId) =>
|
|
29
25
|
ManagedRuntime.make(
|
|
30
|
-
|
|
26
|
+
FunctionInvocationServiceLayerTest({ functions }).pipe(
|
|
31
27
|
Layer.provide(AiService.notAvailable),
|
|
32
28
|
Layer.provide(CredentialsService.configuredLayer([])),
|
|
33
|
-
Layer.provide(
|
|
29
|
+
Layer.provide(Database.notAvailable),
|
|
34
30
|
Layer.provide(QueueService.notAvailable),
|
|
31
|
+
Layer.provide(Feed.notAvailable),
|
|
35
32
|
),
|
|
36
33
|
),
|
|
37
34
|
};
|