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