@dxos/compute 0.8.4-main.ae835ea → 0.8.4-main.bc2380dfbc
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/LICENSE +102 -5
- package/README.md +36 -1
- package/dist/lib/neutral/StorageService.mjs +22 -0
- package/dist/lib/neutral/chunk-AKVCVI6N.mjs +25 -0
- package/dist/lib/neutral/chunk-AKVCVI6N.mjs.map +7 -0
- package/dist/lib/neutral/chunk-J5LGTIGS.mjs +10 -0
- package/dist/lib/neutral/chunk-JTZYM2QW.mjs +144 -0
- package/dist/lib/neutral/chunk-JTZYM2QW.mjs.map +7 -0
- package/dist/lib/neutral/chunk-LRCABAWU.mjs +17 -0
- package/dist/lib/neutral/chunk-LRCABAWU.mjs.map +7 -0
- package/dist/lib/neutral/chunk-RCLYF66G.mjs +21 -0
- package/dist/lib/neutral/chunk-RCLYF66G.mjs.map +7 -0
- package/dist/lib/neutral/chunk-SEBWOTOU.mjs +235 -0
- package/dist/lib/neutral/chunk-SEBWOTOU.mjs.map +7 -0
- package/dist/lib/neutral/chunk-VSICPGGY.mjs +53 -0
- package/dist/lib/neutral/chunk-VSICPGGY.mjs.map +7 -0
- package/dist/lib/neutral/chunk-XEVFBI6S.mjs +62 -0
- package/dist/lib/neutral/chunk-XEVFBI6S.mjs.map +7 -0
- package/dist/lib/neutral/fib-ZSJYREBW.mjs +10 -0
- package/dist/lib/neutral/fib-ZSJYREBW.mjs.map +7 -0
- package/dist/lib/neutral/index.mjs +1146 -0
- package/dist/lib/neutral/index.mjs.map +7 -0
- package/dist/lib/neutral/meta.json +1 -0
- package/dist/lib/neutral/reply-YH3BVOUT.mjs +10 -0
- package/dist/lib/neutral/reply-YH3BVOUT.mjs.map +7 -0
- package/dist/lib/neutral/sleep-TSPIQ5EY.mjs +10 -0
- package/dist/lib/neutral/sleep-TSPIQ5EY.mjs.map +7 -0
- package/dist/lib/neutral/testing/index.mjs +32 -0
- package/dist/lib/neutral/testing/index.mjs.map +7 -0
- package/dist/types/src/Blueprint.d.ts +192 -0
- package/dist/types/src/Blueprint.d.ts.map +1 -0
- package/dist/types/src/Credential.d.ts +27 -0
- package/dist/types/src/Credential.d.ts.map +1 -0
- package/dist/types/src/McpServer.d.ts +27 -0
- package/dist/types/src/McpServer.d.ts.map +1 -0
- package/dist/types/src/Operation.d.ts +340 -0
- package/dist/types/src/Operation.d.ts.map +1 -0
- package/dist/types/src/OperationHandlerSet.d.ts +60 -0
- package/dist/types/src/OperationHandlerSet.d.ts.map +1 -0
- package/dist/types/src/OperationRegistry.d.ts +23 -0
- package/dist/types/src/OperationRegistry.d.ts.map +1 -0
- package/dist/types/src/Process.d.ts +247 -0
- package/dist/types/src/Process.d.ts.map +1 -0
- package/dist/types/src/Routine.d.ts +63 -0
- package/dist/types/src/Routine.d.ts.map +1 -0
- package/dist/types/src/Script.d.ts +22 -0
- package/dist/types/src/Script.d.ts.map +1 -0
- package/dist/types/src/ServiceResolver.d.ts +74 -0
- package/dist/types/src/ServiceResolver.d.ts.map +1 -0
- package/dist/types/src/StorageService.d.ts +58 -0
- package/dist/types/src/StorageService.d.ts.map +1 -0
- package/dist/types/src/Template.d.ts +62 -0
- package/dist/types/src/Template.d.ts.map +1 -0
- package/dist/types/src/Template.test.d.ts +2 -0
- package/dist/types/src/Template.test.d.ts.map +1 -0
- package/dist/types/src/Trace.d.ts +216 -0
- package/dist/types/src/Trace.d.ts.map +1 -0
- package/dist/types/src/Trigger.d.ts +150 -0
- package/dist/types/src/Trigger.d.ts.map +1 -0
- package/dist/types/src/TriggerEvent.d.ts +75 -0
- package/dist/types/src/TriggerEvent.d.ts.map +1 -0
- package/dist/types/src/errors.d.ts +308 -0
- package/dist/types/src/errors.d.ts.map +1 -0
- package/dist/types/src/index.d.ts +16 -5
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/testing/definitions.d.ts +11 -0
- package/dist/types/src/testing/definitions.d.ts.map +1 -0
- package/dist/types/src/testing/fib.d.ts +8 -0
- package/dist/types/src/testing/fib.d.ts.map +1 -0
- package/dist/types/src/testing/index.d.ts +6 -4
- package/dist/types/src/testing/index.d.ts.map +1 -1
- package/dist/types/src/testing/reply.d.ts +4 -0
- package/dist/types/src/testing/reply.d.ts.map +1 -0
- package/dist/types/src/testing/sleep.d.ts +6 -0
- package/dist/types/src/testing/sleep.d.ts.map +1 -0
- package/dist/types/src/umbrella.test.d.ts +2 -0
- package/dist/types/src/umbrella.test.d.ts.map +1 -0
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +28 -40
- package/src/Blueprint.ts +303 -0
- package/src/Credential.ts +53 -0
- package/src/McpServer.ts +44 -0
- package/src/Operation.ts +593 -0
- package/src/OperationHandlerSet.ts +134 -0
- package/src/OperationRegistry.ts +50 -0
- package/src/Process.ts +490 -0
- package/src/Routine.ts +75 -0
- package/src/Script.ts +40 -0
- package/src/ServiceResolver.ts +174 -0
- package/src/StorageService.ts +101 -0
- package/src/Template.test.ts +151 -0
- package/src/Template.ts +122 -0
- package/src/Trace.ts +283 -0
- package/src/Trigger.ts +209 -0
- package/src/TriggerEvent.ts +64 -0
- package/src/errors.ts +71 -0
- package/src/index.ts +18 -6
- package/src/testing/definitions.ts +49 -0
- package/src/testing/fib.ts +22 -0
- package/src/testing/index.ts +13 -5
- package/src/testing/reply.ts +18 -0
- package/src/testing/sleep.ts +16 -0
- package/src/umbrella.test.ts +51 -0
- package/dist/lib/browser/chunk-CY35BVJC.mjs +0 -3113
- package/dist/lib/browser/chunk-CY35BVJC.mjs.map +0 -7
- package/dist/lib/browser/index.mjs +0 -55
- package/dist/lib/browser/meta.json +0 -1
- package/dist/lib/browser/testing/index.mjs +0 -196
- package/dist/lib/browser/testing/index.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-BECNONV7.mjs +0 -3115
- package/dist/lib/node-esm/chunk-BECNONV7.mjs.map +0 -7
- package/dist/lib/node-esm/index.mjs +0 -56
- package/dist/lib/node-esm/meta.json +0 -1
- package/dist/lib/node-esm/testing/index.mjs +0 -197
- package/dist/lib/node-esm/testing/index.mjs.map +0 -7
- package/dist/types/src/compute-graph-registry.d.ts +0 -37
- package/dist/types/src/compute-graph-registry.d.ts.map +0 -1
- package/dist/types/src/compute-graph-registry.test.d.ts +0 -2
- package/dist/types/src/compute-graph-registry.test.d.ts.map +0 -1
- package/dist/types/src/compute-graph.d.ts +0 -67
- package/dist/types/src/compute-graph.d.ts.map +0 -1
- package/dist/types/src/compute-graph.test.d.ts +0 -2
- package/dist/types/src/compute-graph.test.d.ts.map +0 -1
- package/dist/types/src/compute-node.d.ts +0 -24
- package/dist/types/src/compute-node.d.ts.map +0 -1
- package/dist/types/src/functions/async-function.d.ts +0 -68
- package/dist/types/src/functions/async-function.d.ts.map +0 -1
- package/dist/types/src/functions/edge-function.d.ts +0 -20
- package/dist/types/src/functions/edge-function.d.ts.map +0 -1
- package/dist/types/src/functions/function-defs.d.ts +0 -11
- package/dist/types/src/functions/function-defs.d.ts.map +0 -1
- package/dist/types/src/functions/index.d.ts +0 -4
- package/dist/types/src/functions/index.d.ts.map +0 -1
- package/dist/types/src/hyperformula.test.d.ts +0 -2
- package/dist/types/src/hyperformula.test.d.ts.map +0 -1
- package/dist/types/src/testing/test-builder.d.ts +0 -15
- package/dist/types/src/testing/test-builder.d.ts.map +0 -1
- package/dist/types/src/testing/test-plugin.d.ts +0 -35
- package/dist/types/src/testing/test-plugin.d.ts.map +0 -1
- package/dist/types/src/testing/test-runtime.d.ts +0 -10
- package/dist/types/src/testing/test-runtime.d.ts.map +0 -1
- package/dist/types/src/testing/util.d.ts +0 -2
- package/dist/types/src/testing/util.d.ts.map +0 -1
- package/dist/types/src/types/hyperformula.d.ts +0 -8
- package/dist/types/src/types/hyperformula.d.ts.map +0 -1
- package/dist/types/src/types/index.d.ts +0 -3
- package/dist/types/src/types/index.d.ts.map +0 -1
- package/dist/types/src/types/types.d.ts +0 -20
- package/dist/types/src/types/types.d.ts.map +0 -1
- package/dist/types/src/types/types.test.d.ts +0 -2
- package/dist/types/src/types/types.test.d.ts.map +0 -1
- package/dist/types/src/util.d.ts +0 -2
- package/dist/types/src/util.d.ts.map +0 -1
- package/src/compute-graph-registry.test.ts +0 -138
- package/src/compute-graph-registry.ts +0 -97
- package/src/compute-graph.test.ts +0 -87
- package/src/compute-graph.ts +0 -266
- package/src/compute-node.ts +0 -59
- package/src/functions/async-function.ts +0 -184
- package/src/functions/edge-function.ts +0 -114
- package/src/functions/function-defs.ts +0 -2427
- package/src/functions/index.ts +0 -7
- package/src/hyperformula.test.ts +0 -14
- package/src/testing/test-builder.ts +0 -60
- package/src/testing/test-plugin.ts +0 -98
- package/src/testing/test-runtime.ts +0 -38
- package/src/testing/util.ts +0 -9
- package/src/types/hyperformula.ts +0 -19
- package/src/types/index.ts +0 -6
- package/src/types/types.test.ts +0 -91
- package/src/types/types.ts +0 -80
- package/src/util.ts +0 -8
- /package/dist/lib/{browser/index.mjs.map → neutral/StorageService.mjs.map} +0 -0
- /package/dist/lib/{node-esm/index.mjs.map → neutral/chunk-J5LGTIGS.mjs.map} +0 -0
|
@@ -1,184 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright 2024 DXOS.org
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
import type * as ManagedRuntime from 'effect/ManagedRuntime';
|
|
6
|
-
import defaultsDeep from 'lodash.defaultsdeep';
|
|
7
|
-
|
|
8
|
-
import { type CleanupFn, debounce } from '@dxos/async';
|
|
9
|
-
import type { Space } from '@dxos/client/echo';
|
|
10
|
-
import { type FunctionInvocationService } from '@dxos/functions';
|
|
11
|
-
import { log } from '@dxos/log';
|
|
12
|
-
import type { RawInterpreterValue, SimpleCellAddress } from '@dxos/vendor-hyperformula';
|
|
13
|
-
import type { InterpreterState } from '@dxos/vendor-hyperformula';
|
|
14
|
-
import type { InterpreterValue } from '@dxos/vendor-hyperformula';
|
|
15
|
-
import type { ProcedureAst } from '@dxos/vendor-hyperformula';
|
|
16
|
-
import { CellError, EmptyValue, ErrorType, FunctionPlugin, type HyperFormula } from '@dxos/vendor-hyperformula';
|
|
17
|
-
|
|
18
|
-
// TODO(burdon): Create API gateways:
|
|
19
|
-
// https://publicapis.io
|
|
20
|
-
// https://api-ninjas.com/api/cryptoprice
|
|
21
|
-
// https://developers.google.com/apis-explorer
|
|
22
|
-
// https://publicapis.io/coin-desk-api
|
|
23
|
-
|
|
24
|
-
export type AsyncFunction = (...args: any) => Promise<InterpreterValue>;
|
|
25
|
-
|
|
26
|
-
export type FunctionUpdateEvent = {
|
|
27
|
-
name: string;
|
|
28
|
-
cell: SimpleCellAddress;
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
export type FunctionOptions = {
|
|
32
|
-
ttl?: number;
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
export type FunctionContextOptions = {
|
|
36
|
-
defaultTtl: number;
|
|
37
|
-
debounceDelay: number;
|
|
38
|
-
onUpdate?: (update: FunctionUpdateEvent) => void;
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
export const defaultFunctionContextOptions: Pick<FunctionContextOptions, 'defaultTtl' | 'debounceDelay'> = {
|
|
42
|
-
defaultTtl: 5_000,
|
|
43
|
-
debounceDelay: 200,
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
* The context singleton for the model is passed into custom functions.
|
|
48
|
-
*
|
|
49
|
-
* HyperFormula does not support async functions.
|
|
50
|
-
* - https://hyperformula.handsontable.com/guide/custom-functions.html
|
|
51
|
-
* - https://hyperformula.handsontable.com/guide/known-limitations.html#known-limitations
|
|
52
|
-
* - https://github.com/handsontable/hyperformula/issues/892
|
|
53
|
-
*/
|
|
54
|
-
export class FunctionContext {
|
|
55
|
-
// Mangle name with params.
|
|
56
|
-
static createInvocationKey(name: string, ...args: any): string {
|
|
57
|
-
return JSON.stringify({ name, ...args });
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
// TODO(wittjosiah): Persist cached values.
|
|
61
|
-
// Cached values for cell.
|
|
62
|
-
private readonly _cache = new Map<string, { value: InterpreterValue; ts: number }>();
|
|
63
|
-
|
|
64
|
-
// Active requests.
|
|
65
|
-
private readonly _pending = new Map<string, number>();
|
|
66
|
-
|
|
67
|
-
// Query subscriptions.
|
|
68
|
-
private readonly _subscriptions = new Map<string, CleanupFn>();
|
|
69
|
-
|
|
70
|
-
// Invocation count.
|
|
71
|
-
private _invocations: Record<string, number> = {};
|
|
72
|
-
|
|
73
|
-
private readonly _options: FunctionContextOptions;
|
|
74
|
-
|
|
75
|
-
// Debounced update handler.
|
|
76
|
-
private readonly _onUpdate: (update: FunctionUpdateEvent) => void;
|
|
77
|
-
|
|
78
|
-
constructor(
|
|
79
|
-
private readonly _hf: HyperFormula,
|
|
80
|
-
private readonly _runtime: ManagedRuntime.ManagedRuntime<FunctionInvocationService, never>,
|
|
81
|
-
private readonly _space: Space | undefined,
|
|
82
|
-
_options?: Partial<FunctionContextOptions>,
|
|
83
|
-
) {
|
|
84
|
-
this._options = defaultsDeep(_options ?? {}, defaultFunctionContextOptions);
|
|
85
|
-
this._onUpdate = debounce((update) => {
|
|
86
|
-
log('update', update);
|
|
87
|
-
// TODO(burdon): Better way to trigger recalculation? (NOTE: rebuildAndRecalculate resets the undo history.)
|
|
88
|
-
this._hf.resumeEvaluation();
|
|
89
|
-
this._options.onUpdate?.(update);
|
|
90
|
-
}, this._options.debounceDelay);
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
get space() {
|
|
94
|
-
return this._space;
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
get info() {
|
|
98
|
-
return { cache: this._cache.size, invocations: this._invocations };
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
get runtime() {
|
|
102
|
-
return this._runtime;
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
flush(): void {
|
|
106
|
-
this._cache.clear();
|
|
107
|
-
this._invocations = {};
|
|
108
|
-
this._subscriptions.forEach((unsubscribe) => unsubscribe());
|
|
109
|
-
this._subscriptions.clear();
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
createSubscription(name: string, unsubscribe: CleanupFn): void {
|
|
113
|
-
this._subscriptions.get(name)?.();
|
|
114
|
-
this._subscriptions.set(name, unsubscribe);
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
/**
|
|
118
|
-
* Exec the function if TTL has expired.
|
|
119
|
-
* Return the cached value.
|
|
120
|
-
*/
|
|
121
|
-
invokeFunction(
|
|
122
|
-
name: string,
|
|
123
|
-
state: InterpreterState,
|
|
124
|
-
args: any[],
|
|
125
|
-
cb: AsyncFunction,
|
|
126
|
-
options?: FunctionOptions,
|
|
127
|
-
): InterpreterValue | undefined {
|
|
128
|
-
const ttl = options?.ttl ?? this._options.defaultTtl;
|
|
129
|
-
|
|
130
|
-
const { formulaAddress: cell } = state;
|
|
131
|
-
const invocationKey = FunctionContext.createInvocationKey(name, ...args);
|
|
132
|
-
const { value = undefined, ts = 0 } = this._cache.get(invocationKey) ?? {};
|
|
133
|
-
|
|
134
|
-
const now = Date.now();
|
|
135
|
-
const delta = now - ts;
|
|
136
|
-
if ((!ts || delta > ttl) && !this._pending.has(invocationKey)) {
|
|
137
|
-
this._pending.set(invocationKey, now);
|
|
138
|
-
setTimeout(async () => {
|
|
139
|
-
this._invocations[name] = (this._invocations[name] ?? 0) + 1;
|
|
140
|
-
try {
|
|
141
|
-
// Exec function.
|
|
142
|
-
const value = await cb(...args);
|
|
143
|
-
this._cache.set(invocationKey, { value, ts: Date.now() });
|
|
144
|
-
log('set', { cell, value });
|
|
145
|
-
this._onUpdate({ name, cell });
|
|
146
|
-
} catch (err) {
|
|
147
|
-
// TODO(burdon): Show error to user.
|
|
148
|
-
log.warn('failed', { cell, err });
|
|
149
|
-
this._cache.set(invocationKey, { value: new CellError(ErrorType.ERROR, 'Function failed.'), ts: Date.now() });
|
|
150
|
-
} finally {
|
|
151
|
-
this._pending.delete(invocationKey);
|
|
152
|
-
}
|
|
153
|
-
});
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
log.info('invoke', { cell, name, args, cache: value });
|
|
157
|
-
return value;
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
/**
|
|
162
|
-
* Base class for async functions.
|
|
163
|
-
*/
|
|
164
|
-
export class AsyncFunctionPlugin extends FunctionPlugin {
|
|
165
|
-
get context() {
|
|
166
|
-
return this.config.context as FunctionContext;
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
/**
|
|
170
|
-
* Immediately returns cached value then runs the async function.
|
|
171
|
-
*/
|
|
172
|
-
protected runAsyncFunction(
|
|
173
|
-
ast: ProcedureAst,
|
|
174
|
-
state: InterpreterState,
|
|
175
|
-
cb: AsyncFunction,
|
|
176
|
-
options?: FunctionOptions,
|
|
177
|
-
): RawInterpreterValue {
|
|
178
|
-
const { procedureName } = ast;
|
|
179
|
-
const metadata = this.metadata(procedureName);
|
|
180
|
-
return this.runFunction(ast.args, state, metadata, (...args: any) => {
|
|
181
|
-
return this.context.invokeFunction(procedureName, state, args, cb, options) ?? EmptyValue;
|
|
182
|
-
});
|
|
183
|
-
}
|
|
184
|
-
}
|
|
@@ -1,114 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright 2024 DXOS.org
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
import { effect } from '@preact/signals-core';
|
|
6
|
-
import * as Effect from 'effect/Effect';
|
|
7
|
-
import * as SchemaAST from 'effect/SchemaAST';
|
|
8
|
-
|
|
9
|
-
import { Filter } from '@dxos/client/echo';
|
|
10
|
-
import { toEffectSchema } from '@dxos/echo/internal';
|
|
11
|
-
import { ComputeEventLogger, Function, FunctionInvocationService, TracingService } from '@dxos/functions';
|
|
12
|
-
import { FunctionDefinition } from '@dxos/functions';
|
|
13
|
-
import { log } from '@dxos/log';
|
|
14
|
-
import { isNonNullable } from '@dxos/util';
|
|
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';
|
|
18
|
-
|
|
19
|
-
import { type AsyncFunction, AsyncFunctionPlugin } from './async-function';
|
|
20
|
-
|
|
21
|
-
export const EDGE_FUNCTION_NAME = 'DX';
|
|
22
|
-
|
|
23
|
-
const FUNCTION_TTL = 10_000;
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* A hyperformula function plugin for calling remote (EDGE) functions.
|
|
27
|
-
* https://hyperformula.handsontable.com/guide/custom-functions.html#add-a-simple-custom-function
|
|
28
|
-
*/
|
|
29
|
-
export class EdgeFunctionPlugin extends AsyncFunctionPlugin {
|
|
30
|
-
dx(ast: ProcedureAst, state: InterpreterState) {
|
|
31
|
-
const handler =
|
|
32
|
-
(subscribe = false): AsyncFunction =>
|
|
33
|
-
async (binding: string, ...args: any) => {
|
|
34
|
-
const space = this.context.space;
|
|
35
|
-
if (!space) {
|
|
36
|
-
return new CellError(ErrorType.REF, 'Missing space');
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
const {
|
|
40
|
-
objects: [fn],
|
|
41
|
-
} = await space.db.query(Filter.type(Function.Function, { binding })).run();
|
|
42
|
-
if (!fn) {
|
|
43
|
-
log.info('Function not found', { binding });
|
|
44
|
-
return new CellError(ErrorType.REF, 'Function not found');
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
if (subscribe) {
|
|
48
|
-
const unsubscribe = effect(() => {
|
|
49
|
-
log('function changed', { fn });
|
|
50
|
-
const _ = fn?.version;
|
|
51
|
-
|
|
52
|
-
// TODO(wittjosiah): `ttl` should be 0 to force a recalculation when a new version is deployed.
|
|
53
|
-
// This needs a ttl to prevent a binding change from causing the function not to be found.
|
|
54
|
-
this.runAsyncFunction(ast, state, handler(false), { ttl: FUNCTION_TTL });
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
this.context.createSubscription(ast.procedureName, unsubscribe);
|
|
58
|
-
}
|
|
59
|
-
|
|
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;
|
|
64
|
-
if (fn.inputSchema) {
|
|
65
|
-
const schema = toEffectSchema(fn.inputSchema);
|
|
66
|
-
const props = SchemaAST.getPropertySignatures(schema.ast);
|
|
67
|
-
input = {} as any;
|
|
68
|
-
props.forEach(({ name }, index) => {
|
|
69
|
-
input[name.toString()] = args[index];
|
|
70
|
-
});
|
|
71
|
-
} else {
|
|
72
|
-
input = { args: args.filter(isNonNullable) };
|
|
73
|
-
}
|
|
74
|
-
const result = runtime.runPromise(
|
|
75
|
-
Effect.gen(function* () {
|
|
76
|
-
return yield* FunctionInvocationService.invokeFunction(functionDef, input);
|
|
77
|
-
}).pipe(Effect.provide(ComputeEventLogger.layerFromTracing), Effect.provide(TracingService.layerNoop)),
|
|
78
|
-
);
|
|
79
|
-
return result as any;
|
|
80
|
-
};
|
|
81
|
-
|
|
82
|
-
return this.runAsyncFunction(ast, state, handler(true), { ttl: FUNCTION_TTL });
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
EdgeFunctionPlugin.implementedFunctions = {
|
|
87
|
-
[EDGE_FUNCTION_NAME]: {
|
|
88
|
-
method: 'dx',
|
|
89
|
-
parameters: [
|
|
90
|
-
// Binding
|
|
91
|
-
{ argumentType: FunctionArgumentType.STRING },
|
|
92
|
-
|
|
93
|
-
// Remote function arguments (currently supporting up to 8).
|
|
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
|
-
{ argumentType: FunctionArgumentType.ANY, optionalArg: true },
|
|
101
|
-
{ argumentType: FunctionArgumentType.ANY, optionalArg: true },
|
|
102
|
-
],
|
|
103
|
-
isVolatile: true,
|
|
104
|
-
},
|
|
105
|
-
};
|
|
106
|
-
|
|
107
|
-
export const EdgeFunctionPluginTranslations = {
|
|
108
|
-
enGB: {
|
|
109
|
-
[EDGE_FUNCTION_NAME]: 'Remote function',
|
|
110
|
-
},
|
|
111
|
-
enUS: {
|
|
112
|
-
[EDGE_FUNCTION_NAME]: 'Remote function',
|
|
113
|
-
},
|
|
114
|
-
};
|