@dxos/compute 0.8.4-main.67995b8 → 0.8.4-main.72ec0f3
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-AURNYRCC.mjs → chunk-CPBXT2HX.mjs} +108 -72
- package/dist/lib/browser/chunk-CPBXT2HX.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +1 -1
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/testing/index.mjs +30 -6
- package/dist/lib/browser/testing/index.mjs.map +4 -4
- package/dist/lib/node-esm/{chunk-DZMSWKOY.mjs → chunk-D3RM3FQW.mjs} +108 -72
- package/dist/lib/node-esm/chunk-D3RM3FQW.mjs.map +7 -0
- package/dist/lib/node-esm/index.mjs +1 -1
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/lib/node-esm/testing/index.mjs +30 -6
- package/dist/lib/node-esm/testing/index.mjs.map +4 -4
- package/dist/types/src/compute-graph-registry.d.ts +10 -7
- package/dist/types/src/compute-graph-registry.d.ts.map +1 -1
- package/dist/types/src/compute-graph-registry.test.d.ts +2 -0
- package/dist/types/src/compute-graph-registry.test.d.ts.map +1 -0
- package/dist/types/src/compute-graph.d.ts +5 -2
- package/dist/types/src/compute-graph.d.ts.map +1 -1
- package/dist/types/src/compute-node.d.ts +1 -2
- package/dist/types/src/compute-node.d.ts.map +1 -1
- package/dist/types/src/functions/async-function.d.ts +13 -11
- package/dist/types/src/functions/async-function.d.ts.map +1 -1
- package/dist/types/src/functions/edge-function.d.ts +3 -3
- 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/index.d.ts +1 -0
- package/dist/types/src/testing/index.d.ts.map +1 -1
- package/dist/types/src/testing/test-builder.d.ts +1 -1
- package/dist/types/src/testing/test-builder.d.ts.map +1 -1
- package/dist/types/src/testing/test-plugin.d.ts +4 -5
- package/dist/types/src/testing/test-plugin.d.ts.map +1 -1
- package/dist/types/src/testing/test-runtime.d.ts +10 -0
- package/dist/types/src/testing/test-runtime.d.ts.map +1 -0
- package/dist/types/src/types/hyperformula.d.ts +3 -6
- package/dist/types/src/types/hyperformula.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +27 -33
- package/src/compute-graph-registry.test.ts +154 -0
- package/src/compute-graph-registry.ts +20 -14
- package/src/compute-graph.test.ts +31 -13
- package/src/compute-graph.ts +27 -17
- package/src/compute-node.ts +2 -5
- package/src/functions/async-function.ts +21 -16
- package/src/functions/edge-function.ts +25 -23
- package/src/hyperformula.test.ts +2 -2
- package/src/index.ts +0 -27
- package/src/testing/index.ts +1 -0
- package/src/testing/test-builder.ts +8 -2
- package/src/testing/test-plugin.ts +2 -5
- package/src/testing/test-runtime.ts +33 -0
- package/src/testing/util.ts +1 -1
- package/src/types/hyperformula.ts +8 -8
- package/src/types/types.test.ts +2 -2
- package/dist/lib/browser/chunk-AURNYRCC.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-DZMSWKOY.mjs.map +0 -7
- package/dist/vendor/hyperformula.mjs +0 -36400
|
@@ -3,17 +3,18 @@
|
|
|
3
3
|
//
|
|
4
4
|
|
|
5
5
|
import { effect } from '@preact/signals-core';
|
|
6
|
-
import
|
|
7
|
-
import
|
|
8
|
-
import { type ProcedureAst } from 'hyperformula/typings/parser';
|
|
6
|
+
import * as Effect from 'effect/Effect';
|
|
7
|
+
import * as SchemaAST from 'effect/SchemaAST';
|
|
9
8
|
|
|
10
|
-
import { Filter
|
|
11
|
-
import { toEffectSchema } from '@dxos/echo
|
|
12
|
-
import {
|
|
9
|
+
import { Filter } from '@dxos/client/echo';
|
|
10
|
+
import { toEffectSchema } from '@dxos/echo/internal';
|
|
11
|
+
import { Function, FunctionInvocationService, TracingService } from '@dxos/functions';
|
|
12
|
+
import { FunctionDefinition } from '@dxos/functions';
|
|
13
13
|
import { log } from '@dxos/log';
|
|
14
14
|
import { isNonNullable } from '@dxos/util';
|
|
15
|
-
|
|
16
|
-
import {
|
|
15
|
+
import { type ProcedureAst } from '@dxos/vendor-hyperformula';
|
|
16
|
+
import { type InterpreterState } from '@dxos/vendor-hyperformula';
|
|
17
|
+
import { CellError, ErrorType, FunctionArgumentType } from '@dxos/vendor-hyperformula';
|
|
17
18
|
|
|
18
19
|
import { type AsyncFunction, AsyncFunctionPlugin } from './async-function';
|
|
19
20
|
|
|
@@ -37,7 +38,7 @@ export class EdgeFunctionPlugin extends AsyncFunctionPlugin {
|
|
|
37
38
|
|
|
38
39
|
const {
|
|
39
40
|
objects: [fn],
|
|
40
|
-
} = await space.db.query(Filter.type(
|
|
41
|
+
} = await space.db.query(Filter.type(Function.Function, { binding })).run();
|
|
41
42
|
if (!fn) {
|
|
42
43
|
log.info('Function not found', { binding });
|
|
43
44
|
return new CellError(ErrorType.REF, 'Function not found');
|
|
@@ -56,25 +57,26 @@ export class EdgeFunctionPlugin extends AsyncFunctionPlugin {
|
|
|
56
57
|
this.context.createSubscription(ast.procedureName, unsubscribe);
|
|
57
58
|
}
|
|
58
59
|
|
|
59
|
-
const
|
|
60
|
+
const runtime = this.context.runtime;
|
|
61
|
+
const functionDef = FunctionDefinition.deserialize(fn);
|
|
62
|
+
// If input schema exists, construct an object from args using the schema props order, otherwise pass { args }.
|
|
63
|
+
let input: any;
|
|
60
64
|
if (fn.inputSchema) {
|
|
61
65
|
const schema = toEffectSchema(fn.inputSchema);
|
|
62
|
-
SchemaAST.getPropertySignatures(schema.ast)
|
|
63
|
-
|
|
66
|
+
const props = SchemaAST.getPropertySignatures(schema.ast);
|
|
67
|
+
input = {} as any;
|
|
68
|
+
props.forEach(({ name }, index) => {
|
|
69
|
+
input[name.toString()] = args[index];
|
|
64
70
|
});
|
|
65
71
|
} else {
|
|
66
|
-
|
|
72
|
+
input = { args: args.filter(isNonNullable) };
|
|
67
73
|
}
|
|
68
|
-
const
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
const result = await response.text();
|
|
75
|
-
log('function executed', { result });
|
|
76
|
-
|
|
77
|
-
return result;
|
|
74
|
+
const result = runtime.runPromise(
|
|
75
|
+
Effect.gen(function* () {
|
|
76
|
+
return yield* FunctionInvocationService.invokeFunction(functionDef, input);
|
|
77
|
+
}).pipe(Effect.provide(TracingService.layerNoop)),
|
|
78
|
+
);
|
|
79
|
+
return result as any;
|
|
78
80
|
};
|
|
79
81
|
|
|
80
82
|
return this.runAsyncFunction(ast, state, handler(true), { ttl: FUNCTION_TTL });
|
package/src/hyperformula.test.ts
CHANGED
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
// Copyright 2024 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import { describe,
|
|
5
|
+
import { describe, expect, test } from 'vitest';
|
|
6
6
|
|
|
7
|
-
import { HyperFormula } from '
|
|
7
|
+
import { HyperFormula } from '@dxos/vendor-hyperformula';
|
|
8
8
|
|
|
9
9
|
describe('hyperformula', () => {
|
|
10
10
|
test('sanity test', async () => {
|
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';
|
package/src/testing/index.ts
CHANGED
|
@@ -8,7 +8,9 @@ import { invariant } from '@dxos/invariant';
|
|
|
8
8
|
|
|
9
9
|
import { type ComputeGraphOptions, ComputeGraphRegistry } from '../compute-graph-registry';
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
import { createMockedComputeRuntimeProvider } from './test-runtime';
|
|
12
|
+
|
|
13
|
+
export type TestBuilderOptions = ClientOptions & Partial<ComputeGraphOptions>;
|
|
12
14
|
|
|
13
15
|
// TODO(burdon): Reconcile with @dxos/client/testing.
|
|
14
16
|
export class TestBuilder extends Resource {
|
|
@@ -43,7 +45,11 @@ export class TestBuilder extends Resource {
|
|
|
43
45
|
this._client = undefined;
|
|
44
46
|
});
|
|
45
47
|
|
|
46
|
-
const registry = new ComputeGraphRegistry(
|
|
48
|
+
const registry = new ComputeGraphRegistry({
|
|
49
|
+
...this._options,
|
|
50
|
+
// Provide a default runtime provider for tests if not supplied.
|
|
51
|
+
computeRuntime: this._options.computeRuntime ?? createMockedComputeRuntimeProvider(),
|
|
52
|
+
});
|
|
47
53
|
await registry.open();
|
|
48
54
|
this._registry = registry;
|
|
49
55
|
this._ctx.onDispose(async () => {
|
|
@@ -2,12 +2,9 @@
|
|
|
2
2
|
// Copyright 2024 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import { type InterpreterState } from 'hyperformula/typings/interpreter/InterpreterState';
|
|
6
|
-
import { type ProcedureAst } from 'hyperformula/typings/parser';
|
|
7
|
-
|
|
8
5
|
import { getDeep } from '@dxos/util';
|
|
9
|
-
|
|
10
|
-
import { FunctionArgumentType } from '
|
|
6
|
+
import { type InterpreterState, type ProcedureAst } from '@dxos/vendor-hyperformula';
|
|
7
|
+
import { FunctionArgumentType } from '@dxos/vendor-hyperformula';
|
|
11
8
|
|
|
12
9
|
import { type ComputeGraphPlugin } from '../compute-graph-registry';
|
|
13
10
|
import { type AsyncFunction, AsyncFunctionPlugin } from '../functions';
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import * as Layer from 'effect/Layer';
|
|
6
|
+
import * as ManagedRuntime from 'effect/ManagedRuntime';
|
|
7
|
+
|
|
8
|
+
import { AiService } from '@dxos/ai';
|
|
9
|
+
import { type SpaceId } from '@dxos/client/echo';
|
|
10
|
+
import { CredentialsService, DatabaseService, type FunctionDefinition, QueueService } from '@dxos/functions';
|
|
11
|
+
import { FunctionInvocationServiceLayerTest } from '@dxos/functions-runtime/testing';
|
|
12
|
+
|
|
13
|
+
import { type FunctionsRuntimeProvider } from '../compute-graph-registry';
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Minimal compute runtime provider for tests and Storybook.
|
|
17
|
+
* Will cause errors if used for actual runtime.
|
|
18
|
+
*/
|
|
19
|
+
export const createMockedComputeRuntimeProvider = ({
|
|
20
|
+
functions,
|
|
21
|
+
}: { functions?: FunctionDefinition.Any[] } = {}): FunctionsRuntimeProvider => {
|
|
22
|
+
return {
|
|
23
|
+
getRuntime: (_spaceId: SpaceId) =>
|
|
24
|
+
ManagedRuntime.make(
|
|
25
|
+
FunctionInvocationServiceLayerTest({ functions }).pipe(
|
|
26
|
+
Layer.provide(AiService.notAvailable),
|
|
27
|
+
Layer.provide(CredentialsService.configuredLayer([])),
|
|
28
|
+
Layer.provide(DatabaseService.notAvailable),
|
|
29
|
+
Layer.provide(QueueService.notAvailable),
|
|
30
|
+
),
|
|
31
|
+
),
|
|
32
|
+
};
|
|
33
|
+
};
|
package/src/testing/util.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// Copyright 2024 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import { HyperFormula } from 'hyperformula';
|
|
5
|
+
import { HyperFormula } from '@dxos/vendor-hyperformula';
|
|
6
6
|
|
|
7
7
|
export const getRegisteredFunctionNames = () => {
|
|
8
8
|
return HyperFormula.buildEmpty({ licenseKey: 'gpl-v3' }).getRegisteredFunctionNames();
|
|
@@ -2,16 +2,16 @@
|
|
|
2
2
|
// Copyright 2024 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
5
|
+
import {
|
|
6
|
+
type SimpleCellAddress,
|
|
7
|
+
type SimpleCellRange,
|
|
8
|
+
type SimpleDate,
|
|
9
|
+
type SimpleDateTime,
|
|
10
|
+
} from '@dxos/vendor-hyperformula';
|
|
11
|
+
import { DetailedCellError, ExportedCellChange } from '@dxos/vendor-hyperformula';
|
|
11
12
|
|
|
12
13
|
/**
|
|
13
|
-
*
|
|
14
|
-
* so we pre-bundle hyperformula and place it in the vendor directory of this package.
|
|
14
|
+
* Re-exported from vendored hyperformula package.
|
|
15
15
|
*/
|
|
16
16
|
|
|
17
17
|
export { DetailedCellError, ExportedCellChange };
|
package/src/types/types.test.ts
CHANGED
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
// Copyright 2024 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import { getIndices,
|
|
5
|
+
import { getIndices, getIndicesAbove, getIndicesBelow, getIndicesBetween, sortByIndex } from '@tldraw/indices';
|
|
6
6
|
import { describe, expect, test } from 'vitest';
|
|
7
7
|
|
|
8
|
-
import {
|
|
8
|
+
import { addressFromA1Notation, addressToA1Notation, inRange, rangeFromA1Notation, rangeToA1Notation } from './types';
|
|
9
9
|
|
|
10
10
|
describe('cell', () => {
|
|
11
11
|
test('posToA1Notation', () => {
|