@dxos/functions 0.8.4-main.ae835ea → 0.8.4-main.bc674ce
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/index.mjs +767 -884
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node-esm/index.mjs +767 -884
- package/dist/lib/node-esm/index.mjs.map +4 -4
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/types/src/errors.d.ts +44 -60
- package/dist/types/src/errors.d.ts.map +1 -1
- package/dist/types/src/example/fib.d.ts +1 -1
- package/dist/types/src/example/index.d.ts +3 -3
- package/dist/types/src/example/index.d.ts.map +1 -1
- package/dist/types/src/example/reply.d.ts +1 -1
- package/dist/types/src/example/sleep.d.ts +1 -1
- package/dist/types/src/index.d.ts +2 -5
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/operation-compatibility.test.d.ts +2 -0
- package/dist/types/src/operation-compatibility.test.d.ts.map +1 -0
- package/dist/types/src/protocol/functions-ai-http-client.d.ts +12 -0
- package/dist/types/src/protocol/functions-ai-http-client.d.ts.map +1 -0
- package/dist/types/src/protocol/index.d.ts +2 -0
- package/dist/types/src/protocol/index.d.ts.map +1 -0
- package/dist/types/src/protocol/protocol.d.ts +7 -0
- package/dist/types/src/protocol/protocol.d.ts.map +1 -0
- package/dist/types/src/protocol/protocol.test.d.ts +2 -0
- package/dist/types/src/protocol/protocol.test.d.ts.map +1 -0
- package/dist/types/src/sdk.d.ts +114 -0
- package/dist/types/src/sdk.d.ts.map +1 -0
- package/dist/types/src/services/credentials.d.ts +6 -4
- package/dist/types/src/services/credentials.d.ts.map +1 -1
- package/dist/types/src/services/event-logger.d.ts +33 -27
- package/dist/types/src/services/event-logger.d.ts.map +1 -1
- package/dist/types/src/services/function-invocation-service.d.ts +7 -19
- package/dist/types/src/services/function-invocation-service.d.ts.map +1 -1
- package/dist/types/src/services/index.d.ts +2 -4
- package/dist/types/src/services/index.d.ts.map +1 -1
- package/dist/types/src/services/queues.d.ts +4 -4
- package/dist/types/src/services/queues.d.ts.map +1 -1
- package/dist/types/src/services/tracing.d.ts +41 -12
- package/dist/types/src/services/tracing.d.ts.map +1 -1
- package/dist/types/src/types/Function.d.ts +40 -35
- package/dist/types/src/types/Function.d.ts.map +1 -1
- package/dist/types/src/types/Script.d.ts +9 -16
- package/dist/types/src/types/Script.d.ts.map +1 -1
- package/dist/types/src/types/Trigger.d.ts +58 -76
- package/dist/types/src/types/Trigger.d.ts.map +1 -1
- package/dist/types/src/types/TriggerEvent.d.ts +43 -13
- package/dist/types/src/types/TriggerEvent.d.ts.map +1 -1
- package/dist/types/src/types/index.d.ts +1 -0
- package/dist/types/src/types/index.d.ts.map +1 -1
- package/dist/types/src/types/url.d.ts +13 -0
- package/dist/types/src/types/url.d.ts.map +1 -0
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +23 -58
- package/src/errors.ts +4 -4
- package/src/example/fib.ts +1 -1
- package/src/example/reply.ts +1 -1
- package/src/example/sleep.ts +1 -1
- package/src/index.ts +2 -5
- package/src/operation-compatibility.test.ts +185 -0
- package/src/protocol/functions-ai-http-client.ts +67 -0
- package/src/{executor → protocol}/index.ts +1 -1
- package/src/protocol/protocol.test.ts +59 -0
- package/src/protocol/protocol.ts +262 -0
- package/src/{handler.ts → sdk.ts} +129 -66
- package/src/services/credentials.ts +32 -17
- package/src/services/event-logger.ts +10 -4
- package/src/services/function-invocation-service.ts +23 -70
- package/src/services/index.ts +2 -4
- package/src/services/queues.ts +5 -7
- package/src/services/tracing.ts +68 -44
- package/src/types/Function.ts +39 -8
- package/src/types/Script.ts +10 -9
- package/src/types/Trigger.ts +18 -14
- package/src/types/TriggerEvent.ts +29 -29
- package/src/types/index.ts +1 -0
- package/src/types/url.ts +32 -0
- package/dist/lib/browser/bundler/index.mjs +0 -256
- package/dist/lib/browser/bundler/index.mjs.map +0 -7
- package/dist/lib/browser/chunk-J5LGTIGS.mjs +0 -10
- package/dist/lib/browser/chunk-J5LGTIGS.mjs.map +0 -7
- package/dist/lib/browser/chunk-M6EXIREF.mjs +0 -610
- package/dist/lib/browser/chunk-M6EXIREF.mjs.map +0 -7
- package/dist/lib/browser/edge/index.mjs +0 -83
- package/dist/lib/browser/edge/index.mjs.map +0 -7
- package/dist/lib/browser/testing/index.mjs +0 -131
- package/dist/lib/browser/testing/index.mjs.map +0 -7
- package/dist/lib/node-esm/bundler/index.mjs +0 -257
- package/dist/lib/node-esm/bundler/index.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-HSLMI22Q.mjs +0 -11
- package/dist/lib/node-esm/chunk-HSLMI22Q.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-P3IATZMZ.mjs +0 -612
- package/dist/lib/node-esm/chunk-P3IATZMZ.mjs.map +0 -7
- package/dist/lib/node-esm/edge/index.mjs +0 -84
- package/dist/lib/node-esm/edge/index.mjs.map +0 -7
- package/dist/lib/node-esm/testing/index.mjs +0 -132
- package/dist/lib/node-esm/testing/index.mjs.map +0 -7
- package/dist/types/src/bundler/bundler.d.ts +0 -49
- package/dist/types/src/bundler/bundler.d.ts.map +0 -1
- package/dist/types/src/bundler/bundler.test.d.ts +0 -2
- package/dist/types/src/bundler/bundler.test.d.ts.map +0 -1
- package/dist/types/src/bundler/index.d.ts +0 -2
- package/dist/types/src/bundler/index.d.ts.map +0 -1
- package/dist/types/src/e2e/deploy.test.d.ts +0 -2
- package/dist/types/src/e2e/deploy.test.d.ts.map +0 -1
- package/dist/types/src/edge/functions.d.ts +0 -17
- package/dist/types/src/edge/functions.d.ts.map +0 -1
- package/dist/types/src/edge/index.d.ts +0 -2
- package/dist/types/src/edge/index.d.ts.map +0 -1
- package/dist/types/src/executor/executor.d.ts +0 -14
- package/dist/types/src/executor/executor.d.ts.map +0 -1
- package/dist/types/src/executor/index.d.ts +0 -2
- package/dist/types/src/executor/index.d.ts.map +0 -1
- package/dist/types/src/handler.d.ts +0 -102
- package/dist/types/src/handler.d.ts.map +0 -1
- package/dist/types/src/services/database.d.ts +0 -67
- package/dist/types/src/services/database.d.ts.map +0 -1
- package/dist/types/src/services/function-invocation-service.test.d.ts +0 -2
- package/dist/types/src/services/function-invocation-service.test.d.ts.map +0 -1
- package/dist/types/src/services/local-function-execution.d.ts +0 -34
- package/dist/types/src/services/local-function-execution.d.ts.map +0 -1
- package/dist/types/src/services/remote-function-execution-service.d.ts +0 -22
- package/dist/types/src/services/remote-function-execution-service.d.ts.map +0 -1
- package/dist/types/src/services/service-container.d.ts +0 -57
- package/dist/types/src/services/service-container.d.ts.map +0 -1
- package/dist/types/src/services/service-registry.d.ts +0 -31
- package/dist/types/src/services/service-registry.d.ts.map +0 -1
- package/dist/types/src/services/service-registry.test.d.ts +0 -2
- package/dist/types/src/services/service-registry.test.d.ts.map +0 -1
- package/dist/types/src/testing/index.d.ts +0 -3
- package/dist/types/src/testing/index.d.ts.map +0 -1
- package/dist/types/src/testing/layer.d.ts +0 -18
- package/dist/types/src/testing/layer.d.ts.map +0 -1
- package/dist/types/src/testing/logger.d.ts +0 -5
- package/dist/types/src/testing/logger.d.ts.map +0 -1
- package/dist/types/src/testing/persist-database.test.d.ts +0 -2
- package/dist/types/src/testing/persist-database.test.d.ts.map +0 -1
- package/dist/types/src/testing/services.d.ts +0 -59
- package/dist/types/src/testing/services.d.ts.map +0 -1
- package/dist/types/src/trace.d.ts +0 -122
- package/dist/types/src/trace.d.ts.map +0 -1
- package/dist/types/src/translations.d.ts +0 -12
- package/dist/types/src/translations.d.ts.map +0 -1
- package/dist/types/src/triggers/index.d.ts +0 -4
- package/dist/types/src/triggers/index.d.ts.map +0 -1
- package/dist/types/src/triggers/input-builder.d.ts +0 -3
- package/dist/types/src/triggers/input-builder.d.ts.map +0 -1
- package/dist/types/src/triggers/invocation-tracer.d.ts +0 -37
- package/dist/types/src/triggers/invocation-tracer.d.ts.map +0 -1
- package/dist/types/src/triggers/trigger-dispatcher.d.ts +0 -78
- package/dist/types/src/triggers/trigger-dispatcher.d.ts.map +0 -1
- package/dist/types/src/triggers/trigger-dispatcher.test.d.ts +0 -2
- package/dist/types/src/triggers/trigger-dispatcher.test.d.ts.map +0 -1
- package/dist/types/src/triggers/trigger-state-store.d.ts +0 -28
- package/dist/types/src/triggers/trigger-state-store.d.ts.map +0 -1
- package/dist/types/src/url.d.ts +0 -21
- package/dist/types/src/url.d.ts.map +0 -1
- package/src/bundler/bundler.test.ts +0 -58
- package/src/bundler/bundler.ts +0 -295
- package/src/bundler/index.ts +0 -5
- package/src/e2e/deploy.test.ts +0 -69
- package/src/edge/functions.ts +0 -67
- package/src/edge/index.ts +0 -9
- package/src/executor/executor.ts +0 -58
- package/src/services/database.ts +0 -175
- package/src/services/function-invocation-service.test.ts +0 -81
- package/src/services/local-function-execution.ts +0 -153
- package/src/services/remote-function-execution-service.ts +0 -63
- package/src/services/service-container.ts +0 -115
- package/src/services/service-registry.test.ts +0 -45
- package/src/services/service-registry.ts +0 -63
- package/src/testing/index.ts +0 -6
- package/src/testing/layer.ts +0 -114
- package/src/testing/logger.ts +0 -17
- package/src/testing/persist-database.test.ts +0 -87
- package/src/testing/services.ts +0 -115
- package/src/trace.ts +0 -178
- package/src/translations.ts +0 -20
- package/src/triggers/index.ts +0 -7
- package/src/triggers/input-builder.ts +0 -35
- package/src/triggers/invocation-tracer.ts +0 -101
- package/src/triggers/trigger-dispatcher.test.ts +0 -664
- package/src/triggers/trigger-dispatcher.ts +0 -521
- package/src/triggers/trigger-state-store.ts +0 -61
- package/src/url.ts +0 -55
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
import * as Context from 'effect/Context';
|
|
2
|
-
import * as Duration from 'effect/Duration';
|
|
3
|
-
import * as Effect from 'effect/Effect';
|
|
4
|
-
import * as Exit from 'effect/Exit';
|
|
5
|
-
import * as Layer from 'effect/Layer';
|
|
6
|
-
import { DatabaseService, FunctionInvocationService, QueueService } from '../services';
|
|
7
|
-
import { Trigger, type TriggerEvent } from '../types';
|
|
8
|
-
import { InvocationTracer } from './invocation-tracer';
|
|
9
|
-
import { TriggerStateStore } from './trigger-state-store';
|
|
10
|
-
export type TimeControl = 'natural' | 'manual';
|
|
11
|
-
export interface TriggerDispatcherOptions {
|
|
12
|
-
/**
|
|
13
|
-
* Time control mode.
|
|
14
|
-
* - 'natural': Use real time.
|
|
15
|
-
* - 'manual': Use internal clock for testing.
|
|
16
|
-
*/
|
|
17
|
-
timeControl: TimeControl;
|
|
18
|
-
/**
|
|
19
|
-
* Starting time for manual time control mode.
|
|
20
|
-
* @default current time
|
|
21
|
-
*/
|
|
22
|
-
startingTime?: Date;
|
|
23
|
-
/**
|
|
24
|
-
* Poll interval for cron triggers in 'natural' time control mode.
|
|
25
|
-
* @default 1 second
|
|
26
|
-
*/
|
|
27
|
-
livePollInterval?: Duration.Duration;
|
|
28
|
-
}
|
|
29
|
-
export interface InvokeTriggerOptions {
|
|
30
|
-
trigger: Trigger.Trigger;
|
|
31
|
-
event: TriggerEvent.TriggerEvent;
|
|
32
|
-
}
|
|
33
|
-
export interface TriggerExecutionResult {
|
|
34
|
-
triggerId: string;
|
|
35
|
-
result: Exit.Exit<unknown>;
|
|
36
|
-
}
|
|
37
|
-
type TriggerDispatcherServices = FunctionInvocationService | TriggerStateStore | InvocationTracer | QueueService | DatabaseService;
|
|
38
|
-
declare const TriggerDispatcher_base: Context.TagClass<TriggerDispatcher, "@dxos/functions/TriggerDispatcher", {
|
|
39
|
-
readonly timeControl: TimeControl;
|
|
40
|
-
readonly running: boolean;
|
|
41
|
-
/**
|
|
42
|
-
* Start the trigger dispatcher.
|
|
43
|
-
* Will automatically invoke triggers.
|
|
44
|
-
*/
|
|
45
|
-
start(): Effect.Effect<void, never, TriggerDispatcherServices>;
|
|
46
|
-
/**
|
|
47
|
-
* Stop the trigger dispatcher.
|
|
48
|
-
*/
|
|
49
|
-
stop(): Effect.Effect<void>;
|
|
50
|
-
/**
|
|
51
|
-
* Refresh triggers.
|
|
52
|
-
*/
|
|
53
|
-
refreshTriggers(): Effect.Effect<void, never, DatabaseService>;
|
|
54
|
-
/**
|
|
55
|
-
* Manually invoke a specific trigger.
|
|
56
|
-
*/
|
|
57
|
-
invokeTrigger(options: InvokeTriggerOptions): Effect.Effect<TriggerExecutionResult, never, TriggerDispatcherServices>;
|
|
58
|
-
/**
|
|
59
|
-
* Invoke all scheduled triggers who are due.
|
|
60
|
-
*/
|
|
61
|
-
invokeScheduledTriggers(opts?: {
|
|
62
|
-
kinds?: Trigger.Kind[];
|
|
63
|
-
}): Effect.Effect<TriggerExecutionResult[], never, TriggerDispatcherServices>;
|
|
64
|
-
/**
|
|
65
|
-
* Advance the internal clock (manual time control only).
|
|
66
|
-
* Note: Does not invoke triggers.
|
|
67
|
-
*/
|
|
68
|
-
advanceTime(duration: Duration.Duration): Effect.Effect<void>;
|
|
69
|
-
/**
|
|
70
|
-
* Get current time based on time control mode.
|
|
71
|
-
*/
|
|
72
|
-
getCurrentTime(): Date;
|
|
73
|
-
}>;
|
|
74
|
-
export declare class TriggerDispatcher extends TriggerDispatcher_base {
|
|
75
|
-
static layer: (options: Omit<TriggerDispatcherOptions, "database">) => Layer.Layer<TriggerDispatcher, never, never>;
|
|
76
|
-
}
|
|
77
|
-
export {};
|
|
78
|
-
//# sourceMappingURL=trigger-dispatcher.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"trigger-dispatcher.d.ts","sourceRoot":"","sources":["../../../../src/triggers/trigger-dispatcher.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,OAAO,MAAM,gBAAgB,CAAC;AAE1C,OAAO,KAAK,QAAQ,MAAM,iBAAiB,CAAC;AAC5C,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AAExC,OAAO,KAAK,IAAI,MAAM,aAAa,CAAC;AAEpC,OAAO,KAAK,KAAK,MAAM,cAAc,CAAC;AAYtC,OAAO,EAEL,eAAe,EACf,yBAAyB,EACzB,YAAY,EAEb,MAAM,aAAa,CAAC;AACrB,OAAO,EAAY,OAAO,EAAE,KAAK,YAAY,EAAE,MAAM,UAAU,CAAC;AAGhE,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AACvD,OAAO,EAAqB,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAE7E,MAAM,MAAM,WAAW,GAAG,SAAS,GAAG,QAAQ,CAAC;AAE/C,MAAM,WAAW,wBAAwB;IACvC;;;;OAIG;IACH,WAAW,EAAE,WAAW,CAAC;IAEzB;;;OAGG;IACH,YAAY,CAAC,EAAE,IAAI,CAAC;IAEpB;;;OAGG;IACH,gBAAgB,CAAC,EAAE,QAAQ,CAAC,QAAQ,CAAC;CACtC;AAED,MAAM,WAAW,oBAAoB;IACnC,OAAO,EAAE,OAAO,CAAC,OAAO,CAAC;IACzB,KAAK,EAAE,YAAY,CAAC,YAAY,CAAC;CAClC;AACD,MAAM,WAAW,sBAAsB;IACrC,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;CAC5B;AAYD,KAAK,yBAAyB,GAC1B,yBAAyB,GAEzB,iBAAiB,GACjB,gBAAgB,GAChB,YAAY,GACZ,eAAe,CAAC;;0BAKM,WAAW;sBAElB,OAAO;IAEtB;;;OAGG;aACM,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,KAAK,EAAE,yBAAyB,CAAC;IAE9D;;OAEG;YACK,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC;IAE3B;;OAEG;uBACgB,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,KAAK,EAAE,eAAe,CAAC;IAE9D;;OAEG;2BAEQ,oBAAoB,GAC5B,MAAM,CAAC,MAAM,CAAC,sBAAsB,EAAE,KAAK,EAAE,yBAAyB,CAAC;IAE1E;;OAEG;mCAC4B;QAC7B,KAAK,CAAC,EAAE,OAAO,CAAC,IAAI,EAAE,CAAC;KACxB,GAAG,MAAM,CAAC,MAAM,CAAC,sBAAsB,EAAE,EAAE,KAAK,EAAE,yBAAyB,CAAC;IAE7E;;;OAGG;0BACmB,QAAQ,CAAC,QAAQ,GAAG,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC;IAE7D;;OAEG;sBACe,IAAI;;AA9C1B,qBAAa,iBAAkB,SAAQ,sBAgDpC;IACD,MAAM,CAAC,KAAK,GAAI,SAAS,IAAI,CAAC,wBAAwB,EAAE,UAAU,CAAC,kDAM/D;CACL"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"trigger-dispatcher.test.d.ts","sourceRoot":"","sources":["../../../../src/triggers/trigger-dispatcher.test.ts"],"names":[],"mappings":""}
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import * as KeyValueStore from '@effect/platform/KeyValueStore';
|
|
2
|
-
import * as Context from 'effect/Context';
|
|
3
|
-
import * as Effect from 'effect/Effect';
|
|
4
|
-
import * as Layer from 'effect/Layer';
|
|
5
|
-
import * as Schema from 'effect/Schema';
|
|
6
|
-
import { ObjectId } from '@dxos/keys';
|
|
7
|
-
import { TriggerStateNotFoundError } from '../errors';
|
|
8
|
-
export declare const TriggerState: Schema.Struct<{
|
|
9
|
-
version: Schema.Literal<["1"]>;
|
|
10
|
-
triggerId: typeof Schema.String;
|
|
11
|
-
state: Schema.optional<Schema.TaggedStruct<"subscription", {
|
|
12
|
-
processedVersions: Schema.Record$<import("@dxos/keys").ObjectIdClass, typeof Schema.String>;
|
|
13
|
-
}>>;
|
|
14
|
-
}>;
|
|
15
|
-
export interface TriggerState extends Schema.Schema.Type<typeof TriggerState> {
|
|
16
|
-
}
|
|
17
|
-
declare const TriggerStateStore_base: Context.TagClass<TriggerStateStore, "@dxos/functions/TriggerStateStore", {
|
|
18
|
-
getState(triggerId: ObjectId): Effect.Effect<TriggerState, TriggerStateNotFoundError>;
|
|
19
|
-
saveState(state: TriggerState): Effect.Effect<void>;
|
|
20
|
-
}>;
|
|
21
|
-
export declare class TriggerStateStore extends TriggerStateStore_base {
|
|
22
|
-
static getState: (triggerId: string) => Effect.Effect<TriggerState, TriggerStateNotFoundError, TriggerStateStore>;
|
|
23
|
-
static saveState: (state: TriggerState) => Effect.Effect<void, never, TriggerStateStore>;
|
|
24
|
-
static layerKv: Layer.Layer<TriggerStateStore, never, KeyValueStore.KeyValueStore>;
|
|
25
|
-
static layerMemory: Layer.Layer<TriggerStateStore, never, never>;
|
|
26
|
-
}
|
|
27
|
-
export {};
|
|
28
|
-
//# sourceMappingURL=trigger-state-store.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"trigger-state-store.d.ts","sourceRoot":"","sources":["../../../../src/triggers/trigger-state-store.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,aAAa,MAAM,gCAAgC,CAAC;AAChE,OAAO,KAAK,OAAO,MAAM,gBAAgB,CAAC;AAC1C,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AACxC,OAAO,KAAK,KAAK,MAAM,cAAc,CAAC;AAEtC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AAExC,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAEtC,OAAO,EAAE,yBAAyB,EAAE,MAAM,WAAW,CAAC;AAEtD,eAAO,MAAM,YAAY;;;;;;EAUvB,CAAC;AACH,MAAM,WAAW,YAAa,SAAQ,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,YAAY,CAAC;CAAG;;wBAKxD,QAAQ,GAAG,MAAM,CAAC,MAAM,CAAC,YAAY,EAAE,yBAAyB,CAAC;qBACpE,YAAY,GAAG,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC;;AAJvD,qBAAa,iBAAkB,SAAQ,sBAMpC;IACD,MAAM,CAAC,QAAQ,mGAAsE;IACrF,MAAM,CAAC,SAAS,yEAAuE;IAEvF,MAAM,CAAC,OAAO,qEAmBZ;IAEF,MAAM,CAAC,WAAW,+CAA4E;CAC/F"}
|
package/dist/types/src/url.d.ts
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { type ObjectMeta } from '@dxos/echo/internal';
|
|
2
|
-
import { type SpaceId } from '@dxos/keys';
|
|
3
|
-
export declare const FUNCTIONS_META_KEY = "dxos.org/service/function";
|
|
4
|
-
export declare const FUNCTIONS_PRESET_META_KEY = "dxos.org/service/function-preset";
|
|
5
|
-
/**
|
|
6
|
-
* NOTE: functionId is backend ID, not ECHO object id.
|
|
7
|
-
*/
|
|
8
|
-
export declare const getUserFunctionIdInMetadata: (meta: ObjectMeta) => string | undefined;
|
|
9
|
-
/**
|
|
10
|
-
* NOTE: functionId is backend ID, not ECHO object id.
|
|
11
|
-
*/
|
|
12
|
-
export declare const setUserFunctionIdInMetadata: (meta: ObjectMeta, functionId: string) => void;
|
|
13
|
-
/**
|
|
14
|
-
* NOTE: functionId is backend ID, not ECHO object id.
|
|
15
|
-
*/
|
|
16
|
-
export declare const getInvocationUrl: (functionId: string, edgeUrl: string, options?: InvocationOptions) => string;
|
|
17
|
-
export type InvocationOptions = {
|
|
18
|
-
spaceId?: SpaceId;
|
|
19
|
-
subjectId?: string;
|
|
20
|
-
};
|
|
21
|
-
//# sourceMappingURL=url.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"url.d.ts","sourceRoot":"","sources":["../../../src/url.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,UAAU,EAAE,MAAM,qBAAqB,CAAC;AACtD,OAAO,EAAE,KAAK,OAAO,EAAE,MAAM,YAAY,CAAC;AAG1C,eAAO,MAAM,kBAAkB,8BAA8B,CAAC;AAE9D,eAAO,MAAM,yBAAyB,qCAAqC,CAAC;AAM5E;;GAEG;AACH,eAAO,MAAM,2BAA2B,GAAI,MAAM,UAAU,uBAE3D,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,2BAA2B,GAAI,MAAM,UAAU,EAAE,YAAY,MAAM,SAS/E,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,gBAAgB,GAAI,YAAY,MAAM,EAAE,SAAS,MAAM,EAAE,UAAS,iBAAsB,WASpG,CAAC;AAEF,MAAM,MAAM,iBAAiB,GAAG;IAC9B,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,CAAC"}
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright 2022 DXOS.org
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
// @ts-ignore
|
|
6
|
-
import wasmUrl from 'esbuild-wasm/esbuild.wasm?url';
|
|
7
|
-
import { assert, beforeAll, describe, expect, test } from 'vitest';
|
|
8
|
-
|
|
9
|
-
import { isNode } from '@dxos/util';
|
|
10
|
-
|
|
11
|
-
import { Bundler, initializeBundler } from './bundler';
|
|
12
|
-
|
|
13
|
-
describe('Bundler', () => {
|
|
14
|
-
beforeAll(async () => {
|
|
15
|
-
if (!isNode()) {
|
|
16
|
-
await initializeBundler({ wasmUrl });
|
|
17
|
-
}
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
test('Basic', async () => {
|
|
21
|
-
const bundler = new Bundler({ platform: 'node', sandboxedModules: [], remoteModules: {} });
|
|
22
|
-
const result = await bundler.bundle({ source: 'const x = 100' }); // TODO(burdon): Test import.
|
|
23
|
-
assert(!('error' in result), 'error should not exist');
|
|
24
|
-
expect(result.asset).toBeDefined();
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
test('Import', async () => {
|
|
28
|
-
const bundler = new Bundler({ platform: 'node', sandboxedModules: [], remoteModules: {} });
|
|
29
|
-
const result = await bundler.bundle({
|
|
30
|
-
source: `
|
|
31
|
-
import { Filter } from './runtime.js';
|
|
32
|
-
|
|
33
|
-
const query = Filter.typename('dxos.org/type/Example');
|
|
34
|
-
`,
|
|
35
|
-
});
|
|
36
|
-
assert(!('error' in result), 'error should not exist');
|
|
37
|
-
expect(result.asset).toBeDefined();
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
// TODO(dmaretskyi): Flaky on CI.
|
|
41
|
-
test.skip('HTTPS Import', async () => {
|
|
42
|
-
const bundler = new Bundler({ platform: 'node', sandboxedModules: [], remoteModules: {} });
|
|
43
|
-
const result = await bundler.bundle({
|
|
44
|
-
source: `
|
|
45
|
-
import { invariant } from 'https://esm.sh/@dxos/invariant';
|
|
46
|
-
invariant(true);
|
|
47
|
-
`,
|
|
48
|
-
});
|
|
49
|
-
assert(!('error' in result), 'error should not exist');
|
|
50
|
-
expect(result.asset).toBeDefined();
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
test('Error', async () => {
|
|
54
|
-
const bundler = new Bundler({ platform: 'node', sandboxedModules: [], remoteModules: {} });
|
|
55
|
-
const result = await bundler.bundle({ source: "import missing from './module'; missing();" });
|
|
56
|
-
assert('error' in result, 'error should exist');
|
|
57
|
-
});
|
|
58
|
-
});
|
package/src/bundler/bundler.ts
DELETED
|
@@ -1,295 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright 2023 DXOS.org
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
import * as FetchHttpClient from '@effect/platform/FetchHttpClient';
|
|
6
|
-
import * as HttpClient from '@effect/platform/HttpClient';
|
|
7
|
-
import * as Duration from 'effect/Duration';
|
|
8
|
-
import * as Effect from 'effect/Effect';
|
|
9
|
-
import * as Function from 'effect/Function';
|
|
10
|
-
import * as Schedule from 'effect/Schedule';
|
|
11
|
-
import { type BuildOptions, type BuildResult, type Loader, type Plugin, build, initialize } from 'esbuild-wasm';
|
|
12
|
-
|
|
13
|
-
import { subtleCrypto } from '@dxos/crypto';
|
|
14
|
-
import { runAndForwardErrors } from '@dxos/effect';
|
|
15
|
-
import { invariant } from '@dxos/invariant';
|
|
16
|
-
import { log } from '@dxos/log';
|
|
17
|
-
|
|
18
|
-
export type Import = {
|
|
19
|
-
moduleUrl: string;
|
|
20
|
-
defaultImport: boolean;
|
|
21
|
-
namedImports: string[];
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
export type BundleOptions = {
|
|
25
|
-
/**
|
|
26
|
-
* Source code to bundle.
|
|
27
|
-
*/
|
|
28
|
-
source: string;
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
export type BundleResult =
|
|
32
|
-
| {
|
|
33
|
-
timestamp: number;
|
|
34
|
-
sourceHash: Buffer;
|
|
35
|
-
error: unknown;
|
|
36
|
-
}
|
|
37
|
-
| {
|
|
38
|
-
timestamp: number;
|
|
39
|
-
sourceHash: Buffer;
|
|
40
|
-
imports: Import[];
|
|
41
|
-
entryPoint: string;
|
|
42
|
-
asset: Uint8Array;
|
|
43
|
-
bundle: string;
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
export type BundlerOptions = {
|
|
47
|
-
platform: BuildOptions['platform'];
|
|
48
|
-
sandboxedModules: string[];
|
|
49
|
-
remoteModules: Record<string, string>;
|
|
50
|
-
};
|
|
51
|
-
|
|
52
|
-
let initialized: Promise<void>;
|
|
53
|
-
export const initializeBundler = async (options: { wasmUrl: string }) => {
|
|
54
|
-
await (initialized ??= initialize({
|
|
55
|
-
wasmURL: options.wasmUrl,
|
|
56
|
-
}));
|
|
57
|
-
};
|
|
58
|
-
|
|
59
|
-
/**
|
|
60
|
-
* ESBuild bundler.
|
|
61
|
-
*/
|
|
62
|
-
export class Bundler {
|
|
63
|
-
constructor(private readonly _options: BundlerOptions) {}
|
|
64
|
-
|
|
65
|
-
async bundle({ source }: BundleOptions): Promise<BundleResult> {
|
|
66
|
-
const { sandboxedModules: providedModules, ...options } = this._options;
|
|
67
|
-
const sourceHash = Buffer.from(await subtleCrypto.digest('SHA-256', Buffer.from(source)));
|
|
68
|
-
|
|
69
|
-
if (this._options.platform === 'browser') {
|
|
70
|
-
invariant(initialized, 'Compiler not initialized.');
|
|
71
|
-
await initialized;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
const imports = source ? analyzeSourceFileImports(source) : [];
|
|
75
|
-
|
|
76
|
-
// https://esbuild.github.io/api/#build
|
|
77
|
-
try {
|
|
78
|
-
const result = await build({
|
|
79
|
-
platform: options.platform,
|
|
80
|
-
conditions: ['workerd', 'browser'],
|
|
81
|
-
metafile: true,
|
|
82
|
-
write: false,
|
|
83
|
-
entryPoints: {
|
|
84
|
-
// Gets mapped to `userFunc.js` by esbuild.
|
|
85
|
-
userFunc: 'memory:main.tsx',
|
|
86
|
-
},
|
|
87
|
-
bundle: true,
|
|
88
|
-
format: 'esm',
|
|
89
|
-
plugins: [
|
|
90
|
-
{
|
|
91
|
-
name: 'memory',
|
|
92
|
-
setup: (build) => {
|
|
93
|
-
build.onResolve({ filter: /^\.\/runtime\.js$/ }, ({ path }) => {
|
|
94
|
-
return { path, external: true };
|
|
95
|
-
});
|
|
96
|
-
|
|
97
|
-
build.onResolve({ filter: /^dxos:functions$/ }, ({ path }) => {
|
|
98
|
-
return { path: './runtime.js', external: true };
|
|
99
|
-
});
|
|
100
|
-
|
|
101
|
-
build.onResolve({ filter: /^memory:/ }, ({ path }) => {
|
|
102
|
-
return { path: path.split(':')[1], namespace: 'memory' };
|
|
103
|
-
});
|
|
104
|
-
|
|
105
|
-
build.onLoad({ filter: /.*/, namespace: 'memory' }, ({ path }) => {
|
|
106
|
-
if (path === 'main.tsx') {
|
|
107
|
-
return {
|
|
108
|
-
contents: source,
|
|
109
|
-
loader: 'tsx',
|
|
110
|
-
};
|
|
111
|
-
}
|
|
112
|
-
});
|
|
113
|
-
|
|
114
|
-
for (const module of providedModules) {
|
|
115
|
-
build.onResolve({ filter: new RegExp(`^${module}$`) }, ({ path }) => {
|
|
116
|
-
return { path, namespace: 'injected-module' };
|
|
117
|
-
});
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
build.onLoad({ filter: /.*/, namespace: 'injected-module' }, ({ path }) => {
|
|
121
|
-
const namedImports = imports.find((entry) => entry.moduleIdentifier === path)?.namedImports ?? [];
|
|
122
|
-
return {
|
|
123
|
-
contents: `
|
|
124
|
-
const { ${namedImports.join(',')} } = window.__DXOS_SANDBOX_MODULES__[${JSON.stringify(path)}];
|
|
125
|
-
export { ${namedImports.join(',')} };
|
|
126
|
-
export default window.__DXOS_SANDBOX_MODULES__[${JSON.stringify(path)}].default;
|
|
127
|
-
`,
|
|
128
|
-
loader: 'tsx',
|
|
129
|
-
};
|
|
130
|
-
});
|
|
131
|
-
},
|
|
132
|
-
},
|
|
133
|
-
httpPlugin,
|
|
134
|
-
],
|
|
135
|
-
});
|
|
136
|
-
|
|
137
|
-
log('compile complete', result.metafile);
|
|
138
|
-
|
|
139
|
-
const entryPoint = 'userFunc.js';
|
|
140
|
-
return {
|
|
141
|
-
timestamp: Date.now(),
|
|
142
|
-
sourceHash,
|
|
143
|
-
imports: this.analyzeImports(result),
|
|
144
|
-
entryPoint,
|
|
145
|
-
asset: result.outputFiles![0].contents,
|
|
146
|
-
bundle: result.outputFiles![0].text,
|
|
147
|
-
};
|
|
148
|
-
} catch (err) {
|
|
149
|
-
return { timestamp: Date.now(), sourceHash, error: err };
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
// TODO(dmaretskyi): In the future we can replace the compiler with SWC with plugins running in WASM.
|
|
154
|
-
analyzeImports(result: BuildResult): Import[] {
|
|
155
|
-
invariant(result.outputFiles);
|
|
156
|
-
|
|
157
|
-
// TODO(dmaretskyi): Support import aliases and wildcard imports.
|
|
158
|
-
const parsedImports = allMatches(IMPORT_REGEX, result.outputFiles[0].text);
|
|
159
|
-
return Object.values(result.metafile!.outputs)[0].imports.map((entry): Import => {
|
|
160
|
-
const namedImports: string[] = [];
|
|
161
|
-
const parsedImport = parsedImports.find((capture) => capture?.[4] === entry.path);
|
|
162
|
-
if (parsedImport?.[2]) {
|
|
163
|
-
NAMED_IMPORTS_REGEX.lastIndex = 0;
|
|
164
|
-
const namedImportsMatch = NAMED_IMPORTS_REGEX.exec(parsedImport[2]);
|
|
165
|
-
if (namedImportsMatch) {
|
|
166
|
-
namedImportsMatch[1].split(',').forEach((importName) => {
|
|
167
|
-
namedImports.push(importName.trim());
|
|
168
|
-
});
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
return {
|
|
173
|
-
moduleUrl: entry.path,
|
|
174
|
-
defaultImport: !!parsedImport?.[1],
|
|
175
|
-
namedImports,
|
|
176
|
-
};
|
|
177
|
-
});
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
analyzeSourceFileImports(code: string): {
|
|
181
|
-
defaultImportName: string;
|
|
182
|
-
namedImports: string[];
|
|
183
|
-
wildcardImportName: string;
|
|
184
|
-
moduleIdentifier: string;
|
|
185
|
-
quotes: string;
|
|
186
|
-
}[] {
|
|
187
|
-
// TODO(dmaretskyi): Support import aliases and wildcard imports.
|
|
188
|
-
const parsedImports = allMatches(IMPORT_REGEX, code);
|
|
189
|
-
return parsedImports.map((capture) => {
|
|
190
|
-
return {
|
|
191
|
-
defaultImportName: capture[1],
|
|
192
|
-
namedImports: capture[2]?.split(',').map((importName) => importName.trim()),
|
|
193
|
-
wildcardImportName: capture[3],
|
|
194
|
-
moduleIdentifier: capture[4],
|
|
195
|
-
quotes: capture[5],
|
|
196
|
-
};
|
|
197
|
-
});
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
// https://regex101.com/r/FEN5ks/1
|
|
202
|
-
// https://stackoverflow.com/a/73265022
|
|
203
|
-
// $1 = default import name (can be non-existent)
|
|
204
|
-
// $2 = destructured exports (can be non-existent)
|
|
205
|
-
// $3 = wildcard import name (can be non-existent)
|
|
206
|
-
// $4 = module identifier
|
|
207
|
-
// $5 = quotes used (either ' or ")
|
|
208
|
-
const IMPORT_REGEX =
|
|
209
|
-
/import(?:(?:(?:[ \n\t]+([^ *\n\t{},]+)[ \n\t]*(?:,|[ \n\t]+))?([ \n\t]*{(?:[ \n\t]*[^ \n\t"'{}]+[ \n\t]*,?)+})?[ \n\t]*)|[ \n\t]*\*[ \n\t]*as[ \n\t]+([^ \n\t{}]+)[ \n\t]+)from[ \n\t]*(?:['"])([^'"\n]+)(['"])/gm;
|
|
210
|
-
|
|
211
|
-
const NAMED_IMPORTS_REGEX = /[ \n\t]*{((?:[ \n\t]*[^ \n\t"'{}]+[ \n\t]*,?)+)}[ \n\t]*/gm;
|
|
212
|
-
|
|
213
|
-
const allMatches = (regex: RegExp, str: string) => {
|
|
214
|
-
let match;
|
|
215
|
-
const matches = [];
|
|
216
|
-
regex.lastIndex = 0;
|
|
217
|
-
while ((match = regex.exec(str))) {
|
|
218
|
-
matches.push(match);
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
return matches;
|
|
222
|
-
};
|
|
223
|
-
|
|
224
|
-
type ParsedImport = {
|
|
225
|
-
defaultImportName?: string;
|
|
226
|
-
namedImports: string[];
|
|
227
|
-
wildcardImportName?: string;
|
|
228
|
-
moduleIdentifier: string;
|
|
229
|
-
quotes: string;
|
|
230
|
-
};
|
|
231
|
-
|
|
232
|
-
const analyzeSourceFileImports = (code: string): ParsedImport[] => {
|
|
233
|
-
// TODO(dmaretskyi): Support import aliases and wildcard imports.
|
|
234
|
-
const parsedImports = allMatches(IMPORT_REGEX, code);
|
|
235
|
-
return parsedImports.map((capture) => {
|
|
236
|
-
return {
|
|
237
|
-
defaultImportName: capture[1],
|
|
238
|
-
namedImports: capture[2]
|
|
239
|
-
?.trim()
|
|
240
|
-
.slice(1, -1)
|
|
241
|
-
.split(',')
|
|
242
|
-
.map((importName) => importName.trim()),
|
|
243
|
-
wildcardImportName: capture[3],
|
|
244
|
-
moduleIdentifier: capture[4],
|
|
245
|
-
quotes: capture[5],
|
|
246
|
-
};
|
|
247
|
-
});
|
|
248
|
-
};
|
|
249
|
-
|
|
250
|
-
const MAX_RETRIES = 5;
|
|
251
|
-
const INITIAL_DELAY = 1_000;
|
|
252
|
-
|
|
253
|
-
const httpPlugin: Plugin = {
|
|
254
|
-
name: 'http',
|
|
255
|
-
setup: (build) => {
|
|
256
|
-
// Intercept import paths starting with "http:" and "https:" so esbuild doesn't attempt to map them to a file system location.
|
|
257
|
-
// Tag them with the "http-url" namespace to associate them with this plugin.
|
|
258
|
-
build.onResolve({ filter: /^https?:\/\// }, (args) => ({
|
|
259
|
-
path: args.path,
|
|
260
|
-
namespace: 'http-url',
|
|
261
|
-
}));
|
|
262
|
-
|
|
263
|
-
// We also want to intercept all import paths inside downloaded files and resolve them against the original URL.
|
|
264
|
-
// All of these files will be in the "http-url" namespace.
|
|
265
|
-
// Make sure to keep the newly resolved URL in the "http-url" namespace so imports inside it will also be resolved as URLs recursively.
|
|
266
|
-
build.onResolve({ filter: /.*/, namespace: 'http-url' }, (args) => ({
|
|
267
|
-
path: new URL(args.path, args.importer).toString(),
|
|
268
|
-
namespace: 'http-url',
|
|
269
|
-
}));
|
|
270
|
-
|
|
271
|
-
// When a URL is loaded, we want to actually download the content from the internet.
|
|
272
|
-
// This has just enough logic to be able to handle the example import from unpkg.com but in reality this would probably need to be more complex.
|
|
273
|
-
build.onLoad({ filter: /.*/, namespace: 'http-url' }, async (args) => {
|
|
274
|
-
return Effect.gen(function* () {
|
|
275
|
-
const response = yield* HttpClient.get(args.path);
|
|
276
|
-
if (response.status !== 200) {
|
|
277
|
-
throw new Error(`failed to fetch: ${response.status}`);
|
|
278
|
-
}
|
|
279
|
-
|
|
280
|
-
const text = yield* response.text;
|
|
281
|
-
return { contents: text, loader: 'jsx' as Loader };
|
|
282
|
-
}).pipe(
|
|
283
|
-
Effect.retry(
|
|
284
|
-
Function.pipe(
|
|
285
|
-
Schedule.exponential(Duration.millis(INITIAL_DELAY)),
|
|
286
|
-
Schedule.jittered,
|
|
287
|
-
Schedule.intersect(Schedule.recurs(MAX_RETRIES - 1)),
|
|
288
|
-
),
|
|
289
|
-
),
|
|
290
|
-
Effect.provide(FetchHttpClient.layer),
|
|
291
|
-
runAndForwardErrors,
|
|
292
|
-
);
|
|
293
|
-
});
|
|
294
|
-
},
|
|
295
|
-
};
|
package/src/bundler/index.ts
DELETED
package/src/e2e/deploy.test.ts
DELETED
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright 2025 DXOS.org
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
import { readFile } from 'node:fs/promises';
|
|
6
|
-
|
|
7
|
-
import { describe, expect, test } from 'vitest';
|
|
8
|
-
|
|
9
|
-
import { Client, Config } from '@dxos/client';
|
|
10
|
-
import { createEdgeIdentity } from '@dxos/client/edge';
|
|
11
|
-
import { Bundler } from '@dxos/functions/bundler';
|
|
12
|
-
import { uploadWorkerFunction } from '@dxos/functions/edge';
|
|
13
|
-
import { invariant } from '@dxos/invariant';
|
|
14
|
-
import { log } from '@dxos/log';
|
|
15
|
-
|
|
16
|
-
describe.runIf(process.env.DX_TEST_TAGS?.includes('functions-e2e'))('Functions deployment', () => {
|
|
17
|
-
test('deploys FOREX (effect) function and invokes it via EDGE (main)', { timeout: 120_000 }, async () => {
|
|
18
|
-
const config = new Config({
|
|
19
|
-
version: 1,
|
|
20
|
-
runtime: {
|
|
21
|
-
services: {
|
|
22
|
-
edge: { url: 'https://edge-main.dxos.workers.dev' },
|
|
23
|
-
},
|
|
24
|
-
},
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
const client = new Client({ config });
|
|
28
|
-
await client.initialize();
|
|
29
|
-
await client.halo.createIdentity();
|
|
30
|
-
|
|
31
|
-
const space = await client.spaces.create();
|
|
32
|
-
await space.waitUntilReady();
|
|
33
|
-
|
|
34
|
-
// Inline echo function source.
|
|
35
|
-
const source = await readFile(new URL('../examples/forex-effect.ts', import.meta.url), 'utf-8');
|
|
36
|
-
|
|
37
|
-
// Bundle and upload.
|
|
38
|
-
const bundler = new Bundler({ platform: 'node', sandboxedModules: [], remoteModules: {} });
|
|
39
|
-
const buildResult = await bundler.bundle({ source });
|
|
40
|
-
if ('error' in buildResult) {
|
|
41
|
-
throw buildResult.error ?? new Error('Bundle creation failed');
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
const { functionId } = await uploadWorkerFunction({
|
|
45
|
-
client,
|
|
46
|
-
ownerPublicKey: space.key,
|
|
47
|
-
version: '0.0.1',
|
|
48
|
-
entryPoint: buildResult.entryPoint,
|
|
49
|
-
assets: { [buildResult.entryPoint]: buildResult.asset },
|
|
50
|
-
name: 'e2e-echo',
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
expect(functionId).toBeDefined();
|
|
54
|
-
|
|
55
|
-
// Invoke deployed function via EDGE directly.
|
|
56
|
-
const edgeClient = client.edge;
|
|
57
|
-
invariant(edgeClient, 'edgeClient is required');
|
|
58
|
-
edgeClient.setIdentity(createEdgeIdentity(client));
|
|
59
|
-
|
|
60
|
-
const input = { from: 'USD', to: 'EUR' };
|
|
61
|
-
const result = await edgeClient.invokeFunction({ functionId }, input);
|
|
62
|
-
log.info('>>> result', { result, functionId });
|
|
63
|
-
const resultNumber = Number(result);
|
|
64
|
-
expect(resultNumber).toBeGreaterThan(0);
|
|
65
|
-
expect(resultNumber).toBeLessThan(100);
|
|
66
|
-
|
|
67
|
-
await client.destroy();
|
|
68
|
-
});
|
|
69
|
-
});
|
package/src/edge/functions.ts
DELETED
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright 2024 DXOS.org
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
import { type DID } from 'iso-did/types';
|
|
6
|
-
|
|
7
|
-
import { type Client } from '@dxos/client';
|
|
8
|
-
import { createEdgeIdentity } from '@dxos/client/edge';
|
|
9
|
-
import { EdgeHttpClient } from '@dxos/edge-client';
|
|
10
|
-
import { invariant } from '@dxos/invariant';
|
|
11
|
-
import { type PublicKey } from '@dxos/keys';
|
|
12
|
-
import { log } from '@dxos/log';
|
|
13
|
-
import { type UploadFunctionResponseBody } from '@dxos/protocols';
|
|
14
|
-
|
|
15
|
-
export type UploadWorkerArgs = {
|
|
16
|
-
client: Client;
|
|
17
|
-
version: string;
|
|
18
|
-
name?: string;
|
|
19
|
-
functionId?: string;
|
|
20
|
-
ownerPublicKey: PublicKey;
|
|
21
|
-
entryPoint: string;
|
|
22
|
-
assets: Record<string, Uint8Array>;
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
export const uploadWorkerFunction = async ({
|
|
26
|
-
client,
|
|
27
|
-
version,
|
|
28
|
-
name,
|
|
29
|
-
functionId,
|
|
30
|
-
ownerPublicKey,
|
|
31
|
-
entryPoint,
|
|
32
|
-
assets,
|
|
33
|
-
}: UploadWorkerArgs): Promise<UploadFunctionResponseBody> => {
|
|
34
|
-
log('uploading function', { functionId, name, version, ownerPublicKey });
|
|
35
|
-
const edgeUrl = client.config.values.runtime?.services?.edge?.url;
|
|
36
|
-
invariant(edgeUrl, 'Edge is not configured.');
|
|
37
|
-
const edgeClient = new EdgeHttpClient(edgeUrl);
|
|
38
|
-
const edgeIdentity = createEdgeIdentity(client);
|
|
39
|
-
edgeClient.setIdentity(edgeIdentity);
|
|
40
|
-
const response = await edgeClient.uploadFunction(
|
|
41
|
-
{ functionId },
|
|
42
|
-
{ name, version, ownerPublicKey: ownerPublicKey.toHex(), entryPoint, assets },
|
|
43
|
-
);
|
|
44
|
-
|
|
45
|
-
// TODO(burdon): Edge service log.
|
|
46
|
-
log('uploaded', {
|
|
47
|
-
identityKey: edgeIdentity.identityKey,
|
|
48
|
-
functionId,
|
|
49
|
-
name,
|
|
50
|
-
version,
|
|
51
|
-
response,
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
return response;
|
|
55
|
-
};
|
|
56
|
-
|
|
57
|
-
export const incrementSemverPatch = (version: string): string => {
|
|
58
|
-
const [major, minor, patch] = version.split('.');
|
|
59
|
-
const patchNum = Number(patch);
|
|
60
|
-
invariant(!Number.isNaN(patchNum), `Unexpected function version format: ${version}`);
|
|
61
|
-
return [major, minor, String(patchNum + 1)].join('.');
|
|
62
|
-
};
|
|
63
|
-
|
|
64
|
-
// TODO(burdon): Factor out.
|
|
65
|
-
export const publicKeyToDid = (key: PublicKey): DID => {
|
|
66
|
-
return `did:key:${key.toHex()}`;
|
|
67
|
-
};
|