@dxos/compute 0.8.4-main.f9ba587 → 0.8.4-main.fcc0d83b33

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 (81) hide show
  1. package/README.md +36 -1
  2. package/dist/lib/neutral/index.mjs +5 -0
  3. package/dist/lib/neutral/index.mjs.map +7 -0
  4. package/dist/lib/neutral/meta.json +1 -0
  5. package/dist/types/src/index.d.ts +3 -5
  6. package/dist/types/src/index.d.ts.map +1 -1
  7. package/dist/types/src/umbrella.test.d.ts +2 -0
  8. package/dist/types/src/umbrella.test.d.ts.map +1 -0
  9. package/dist/types/tsconfig.tsbuildinfo +1 -1
  10. package/package.json +14 -48
  11. package/src/index.ts +8 -33
  12. package/src/umbrella.test.ts +47 -0
  13. package/dist/lib/browser/chunk-2PBHA7EI.mjs +0 -3078
  14. package/dist/lib/browser/chunk-2PBHA7EI.mjs.map +0 -7
  15. package/dist/lib/browser/index.mjs +0 -55
  16. package/dist/lib/browser/index.mjs.map +0 -7
  17. package/dist/lib/browser/meta.json +0 -1
  18. package/dist/lib/browser/testing/index.mjs +0 -173
  19. package/dist/lib/browser/testing/index.mjs.map +0 -7
  20. package/dist/lib/node-esm/chunk-GTPQNWA3.mjs +0 -3080
  21. package/dist/lib/node-esm/chunk-GTPQNWA3.mjs.map +0 -7
  22. package/dist/lib/node-esm/index.mjs +0 -56
  23. package/dist/lib/node-esm/index.mjs.map +0 -7
  24. package/dist/lib/node-esm/meta.json +0 -1
  25. package/dist/lib/node-esm/testing/index.mjs +0 -174
  26. package/dist/lib/node-esm/testing/index.mjs.map +0 -7
  27. package/dist/types/src/compute-graph-registry.d.ts +0 -34
  28. package/dist/types/src/compute-graph-registry.d.ts.map +0 -1
  29. package/dist/types/src/compute-graph.d.ts +0 -64
  30. package/dist/types/src/compute-graph.d.ts.map +0 -1
  31. package/dist/types/src/compute-graph.test.d.ts +0 -2
  32. package/dist/types/src/compute-graph.test.d.ts.map +0 -1
  33. package/dist/types/src/compute-node.d.ts +0 -25
  34. package/dist/types/src/compute-node.d.ts.map +0 -1
  35. package/dist/types/src/functions/async-function.d.ts +0 -66
  36. package/dist/types/src/functions/async-function.d.ts.map +0 -1
  37. package/dist/types/src/functions/edge-function.d.ts +0 -20
  38. package/dist/types/src/functions/edge-function.d.ts.map +0 -1
  39. package/dist/types/src/functions/function-defs.d.ts +0 -11
  40. package/dist/types/src/functions/function-defs.d.ts.map +0 -1
  41. package/dist/types/src/functions/index.d.ts +0 -4
  42. package/dist/types/src/functions/index.d.ts.map +0 -1
  43. package/dist/types/src/hyperformula.test.d.ts +0 -2
  44. package/dist/types/src/hyperformula.test.d.ts.map +0 -1
  45. package/dist/types/src/testing/index.d.ts +0 -4
  46. package/dist/types/src/testing/index.d.ts.map +0 -1
  47. package/dist/types/src/testing/test-builder.d.ts +0 -15
  48. package/dist/types/src/testing/test-builder.d.ts.map +0 -1
  49. package/dist/types/src/testing/test-plugin.d.ts +0 -36
  50. package/dist/types/src/testing/test-plugin.d.ts.map +0 -1
  51. package/dist/types/src/testing/util.d.ts +0 -2
  52. package/dist/types/src/testing/util.d.ts.map +0 -1
  53. package/dist/types/src/types/hyperformula.d.ts +0 -11
  54. package/dist/types/src/types/hyperformula.d.ts.map +0 -1
  55. package/dist/types/src/types/index.d.ts +0 -3
  56. package/dist/types/src/types/index.d.ts.map +0 -1
  57. package/dist/types/src/types/types.d.ts +0 -20
  58. package/dist/types/src/types/types.d.ts.map +0 -1
  59. package/dist/types/src/types/types.test.d.ts +0 -2
  60. package/dist/types/src/types/types.test.d.ts.map +0 -1
  61. package/dist/types/src/util.d.ts +0 -2
  62. package/dist/types/src/util.d.ts.map +0 -1
  63. package/dist/vendor/hyperformula.mjs +0 -36400
  64. package/src/compute-graph-registry.ts +0 -90
  65. package/src/compute-graph.test.ts +0 -88
  66. package/src/compute-graph.ts +0 -259
  67. package/src/compute-node.ts +0 -61
  68. package/src/functions/async-function.ts +0 -179
  69. package/src/functions/edge-function.ts +0 -111
  70. package/src/functions/function-defs.ts +0 -2427
  71. package/src/functions/index.ts +0 -7
  72. package/src/hyperformula.test.ts +0 -14
  73. package/src/testing/index.ts +0 -7
  74. package/src/testing/test-builder.ts +0 -54
  75. package/src/testing/test-plugin.ts +0 -100
  76. package/src/testing/util.ts +0 -9
  77. package/src/types/hyperformula.ts +0 -19
  78. package/src/types/index.ts +0 -6
  79. package/src/types/types.test.ts +0 -91
  80. package/src/types/types.ts +0 -80
  81. package/src/util.ts +0 -8
@@ -1,111 +0,0 @@
1
- //
2
- // Copyright 2024 DXOS.org
3
- //
4
-
5
- import { effect } from '@preact/signals-core';
6
- import { SchemaAST } from 'effect';
7
- import { type InterpreterState } from 'hyperformula/typings/interpreter/InterpreterState';
8
- import { type ProcedureAst } from 'hyperformula/typings/parser';
9
-
10
- import { Filter, getMeta } from '@dxos/client/echo';
11
- import { toEffectSchema } from '@dxos/echo-schema';
12
- import { FunctionType, getUserFunctionUrlInMetadata } from '@dxos/functions';
13
- import { log } from '@dxos/log';
14
- import { isNonNullable } from '@dxos/util';
15
-
16
- import { CellError, ErrorType, FunctionArgumentType } from '#hyperformula';
17
- import { type AsyncFunction, AsyncFunctionPlugin } from './async-function';
18
-
19
- export const EDGE_FUNCTION_NAME = 'DX';
20
-
21
- const FUNCTION_TTL = 10_000;
22
-
23
- /**
24
- * A hyperformula function plugin for calling remote (EDGE) functions.
25
- * https://hyperformula.handsontable.com/guide/custom-functions.html#add-a-simple-custom-function
26
- */
27
- export class EdgeFunctionPlugin extends AsyncFunctionPlugin {
28
- dx(ast: ProcedureAst, state: InterpreterState) {
29
- const handler =
30
- (subscribe = false): AsyncFunction =>
31
- async (binding: string, ...args: any) => {
32
- const space = this.context.space;
33
- if (!space) {
34
- return new CellError(ErrorType.REF, 'Missing space');
35
- }
36
-
37
- const {
38
- objects: [fn],
39
- } = await space.db.query(Filter.type(FunctionType, { binding })).run();
40
- if (!fn) {
41
- log.info('Function not found', { binding });
42
- return new CellError(ErrorType.REF, 'Function not found');
43
- }
44
-
45
- if (subscribe) {
46
- const unsubscribe = effect(() => {
47
- log('function changed', { fn });
48
- const _ = fn?.version;
49
-
50
- // TODO(wittjosiah): `ttl` should be 0 to force a recalculation when a new version is deployed.
51
- // This needs a ttl to prevent a binding change from causing the function not to be found.
52
- this.runAsyncFunction(ast, state, handler(false), { ttl: FUNCTION_TTL });
53
- });
54
-
55
- this.context.createSubscription(ast.procedureName, unsubscribe);
56
- }
57
-
58
- const body: Record<string, any> = {};
59
- if (fn.inputSchema) {
60
- const schema = toEffectSchema(fn.inputSchema);
61
- SchemaAST.getPropertySignatures(schema.ast).forEach(({ name }, index) => {
62
- body[name.toString()] = args[index];
63
- });
64
- } else {
65
- body.args = args.filter(isNonNullable);
66
- }
67
- const path = getUserFunctionUrlInMetadata(getMeta(fn));
68
- const response = await fetch(`${this.context.remoteFunctionUrl}${path}`, {
69
- method: 'POST',
70
- headers: { 'Content-Type': 'application/json' },
71
- body: JSON.stringify(body),
72
- });
73
- const result = await response.text();
74
- log('function executed', { result });
75
-
76
- return result;
77
- };
78
-
79
- return this.runAsyncFunction(ast, state, handler(true), { ttl: FUNCTION_TTL });
80
- }
81
- }
82
-
83
- EdgeFunctionPlugin.implementedFunctions = {
84
- [EDGE_FUNCTION_NAME]: {
85
- method: 'dx',
86
- parameters: [
87
- // Binding
88
- { argumentType: FunctionArgumentType.STRING },
89
-
90
- // Remote function arguments (currently supporting up to 8).
91
- { argumentType: FunctionArgumentType.ANY, optionalArg: true },
92
- { argumentType: FunctionArgumentType.ANY, optionalArg: true },
93
- { argumentType: FunctionArgumentType.ANY, optionalArg: true },
94
- { argumentType: FunctionArgumentType.ANY, optionalArg: true },
95
- { argumentType: FunctionArgumentType.ANY, optionalArg: true },
96
- { argumentType: FunctionArgumentType.ANY, optionalArg: true },
97
- { argumentType: FunctionArgumentType.ANY, optionalArg: true },
98
- { argumentType: FunctionArgumentType.ANY, optionalArg: true },
99
- ],
100
- isVolatile: true,
101
- },
102
- };
103
-
104
- export const EdgeFunctionPluginTranslations = {
105
- enGB: {
106
- [EDGE_FUNCTION_NAME]: 'Remote function',
107
- },
108
- enUS: {
109
- [EDGE_FUNCTION_NAME]: 'Remote function',
110
- },
111
- };