@dxos/functions 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 +5 -7
- package/dist/lib/neutral/index.mjs +599 -0
- package/dist/lib/neutral/index.mjs.map +7 -0
- package/dist/lib/neutral/meta.json +1 -0
- package/dist/types/src/index.d.ts +2 -7
- package/dist/types/src/index.d.ts.map +1 -1
- 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/functions-ai-http-client.test.d.ts +2 -0
- package/dist/types/src/protocol/functions-ai-http-client.test.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 +24 -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 +10 -0
- package/dist/types/src/sdk.d.ts.map +1 -0
- package/dist/types/src/services/credentials.d.ts +17 -38
- package/dist/types/src/services/credentials.d.ts.map +1 -1
- package/dist/types/src/services/function-invocation-service.d.ts +6 -19
- package/dist/types/src/services/function-invocation-service.d.ts.map +1 -1
- package/dist/types/src/services/index.d.ts +1 -6
- package/dist/types/src/services/index.d.ts.map +1 -1
- package/dist/types/src/services/queues.d.ts +1 -46
- package/dist/types/src/services/queues.d.ts.map +1 -1
- package/dist/types/src/services/tracing.d.ts +2 -56
- package/dist/types/src/services/tracing.d.ts.map +1 -1
- package/dist/types/src/types/index.d.ts +1 -4
- 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 +26 -61
- package/src/index.ts +2 -7
- package/src/protocol/functions-ai-http-client.test.ts +105 -0
- package/src/protocol/functions-ai-http-client.ts +141 -0
- package/src/{executor → protocol}/index.ts +1 -1
- package/src/protocol/protocol.test.ts +58 -0
- package/src/protocol/protocol.ts +452 -0
- package/src/sdk.ts +31 -0
- package/src/services/credentials.ts +81 -110
- package/src/services/function-invocation-service.ts +19 -70
- package/src/services/index.ts +1 -6
- package/src/services/queues.ts +1 -80
- package/src/services/tracing.ts +1 -136
- package/src/types/index.ts +1 -4
- 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/index.mjs +0 -1346
- package/dist/lib/browser/index.mjs.map +0 -7
- package/dist/lib/browser/meta.json +0 -1
- 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/index.mjs +0 -1347
- package/dist/lib/node-esm/index.mjs.map +0 -7
- package/dist/lib/node-esm/meta.json +0 -1
- 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/errors.d.ts +0 -137
- package/dist/types/src/errors.d.ts.map +0 -1
- package/dist/types/src/example/fib.d.ts +0 -7
- package/dist/types/src/example/fib.d.ts.map +0 -1
- package/dist/types/src/example/forex-effect.d.ts +0 -3
- package/dist/types/src/example/forex-effect.d.ts.map +0 -1
- package/dist/types/src/example/index.d.ts +0 -12
- package/dist/types/src/example/index.d.ts.map +0 -1
- package/dist/types/src/example/reply.d.ts +0 -3
- package/dist/types/src/example/reply.d.ts.map +0 -1
- package/dist/types/src/example/sleep.d.ts +0 -5
- package/dist/types/src/example/sleep.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/event-logger.d.ts +0 -75
- package/dist/types/src/services/event-logger.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/types/Function.d.ts +0 -47
- package/dist/types/src/types/Function.d.ts.map +0 -1
- package/dist/types/src/types/Script.d.ts +0 -28
- package/dist/types/src/types/Script.d.ts.map +0 -1
- package/dist/types/src/types/Trigger.d.ts +0 -139
- package/dist/types/src/types/Trigger.d.ts.map +0 -1
- package/dist/types/src/types/TriggerEvent.d.ts +0 -44
- package/dist/types/src/types/TriggerEvent.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/errors.ts +0 -21
- package/src/example/fib.ts +0 -32
- package/src/example/forex-effect.ts +0 -40
- package/src/example/index.ts +0 -13
- package/src/example/reply.ts +0 -21
- package/src/example/sleep.ts +0 -24
- package/src/executor/executor.ts +0 -58
- package/src/handler.ts +0 -226
- package/src/services/database.ts +0 -175
- package/src/services/event-logger.ts +0 -121
- 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/types/Function.ts +0 -51
- package/src/types/Script.ts +0 -33
- package/src/types/Trigger.ts +0 -139
- package/src/types/TriggerEvent.ts +0 -62
- package/src/url.ts +0 -55
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Script.d.ts","sourceRoot":"","sources":["../../../../src/types/Script.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AAExC,OAAO,EAAE,GAAG,EAAO,IAAI,EAAE,MAAM,YAAY,CAAC;AAI5C;;GAEG;AACH,eAAO,MAAM,MAAM;;;;;;;GAalB,CAAC;AACF,MAAM,WAAW,MAAO,SAAQ,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,MAAM,CAAC;CAAG;AAEpE,KAAK,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,SAAS,CAAC,OAAO,MAAM,CAAC,EAAE,QAAQ,CAAC,GAAG;IAAE,MAAM,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC;AAEhF,eAAO,MAAM,IAAI,GAAI,uBAA2B,KAAU;;;;;;;EACmB,CAAC"}
|
|
@@ -1,139 +0,0 @@
|
|
|
1
|
-
import * as Schema from 'effect/Schema';
|
|
2
|
-
import { Obj, QueryAST, Type } from '@dxos/echo';
|
|
3
|
-
import { Expando, Ref } from '@dxos/echo/internal';
|
|
4
|
-
/**
|
|
5
|
-
* Type discriminator for TriggerType.
|
|
6
|
-
* Every spec has a type field of type TriggerKind that we can use to understand which type we're working with.
|
|
7
|
-
* https://www.typescriptlang.org/docs/handbook/2/narrowing.html#discriminated-unions
|
|
8
|
-
*/
|
|
9
|
-
export declare const Kinds: readonly ["email", "queue", "subscription", "timer", "webhook"];
|
|
10
|
-
export type Kind = (typeof Kinds)[number];
|
|
11
|
-
export declare const EmailSpec: Schema.mutable<Schema.Struct<{
|
|
12
|
-
kind: Schema.Literal<["email"]>;
|
|
13
|
-
}>>;
|
|
14
|
-
export type EmailSpec = Schema.Schema.Type<typeof EmailSpec>;
|
|
15
|
-
export declare const QueueSpec: Schema.mutable<Schema.Struct<{
|
|
16
|
-
kind: Schema.Literal<["queue"]>;
|
|
17
|
-
queue: Schema.refine<string, typeof Schema.NonEmptyString>;
|
|
18
|
-
}>>;
|
|
19
|
-
export type QueueSpec = Schema.Schema.Type<typeof QueueSpec>;
|
|
20
|
-
/**
|
|
21
|
-
* Subscription.
|
|
22
|
-
*/
|
|
23
|
-
export declare const SubscriptionSpec: Schema.mutable<Schema.Struct<{
|
|
24
|
-
kind: Schema.Literal<["subscription"]>;
|
|
25
|
-
query: Schema.mutable<Schema.Struct<{
|
|
26
|
-
raw: Schema.optional<Schema.SchemaClass<string, string, never>>;
|
|
27
|
-
ast: Schema.Schema<QueryAST.QuerySelectClause | QueryAST.QueryFilterClause | QueryAST.QueryReferenceTraversalClause | QueryAST.QueryIncomingReferencesClause | QueryAST.QueryRelationClause | QueryAST.QueryRelationTraversalClause | QueryAST.QueryUnionClause | QueryAST.QuerySetDifferenceClause | QueryAST.QueryOrderClause | QueryAST.QueryOptionsClause, QueryAST.QuerySelectClause | QueryAST.QueryFilterClause | QueryAST.QueryReferenceTraversalClause | QueryAST.QueryIncomingReferencesClause | QueryAST.QueryRelationClause | QueryAST.QueryRelationTraversalClause | QueryAST.QueryUnionClause | QueryAST.QuerySetDifferenceClause | QueryAST.QueryOrderClause | QueryAST.QueryOptionsClause, never>;
|
|
28
|
-
}>>;
|
|
29
|
-
options: Schema.optional<Schema.Struct<{
|
|
30
|
-
deep: Schema.optional<Schema.SchemaClass<boolean, boolean, never>>;
|
|
31
|
-
delay: Schema.optional<Schema.SchemaClass<number, number, never>>;
|
|
32
|
-
}>>;
|
|
33
|
-
}>>;
|
|
34
|
-
export type SubscriptionSpec = Schema.Schema.Type<typeof SubscriptionSpec>;
|
|
35
|
-
/**
|
|
36
|
-
* Cron timer.
|
|
37
|
-
*/
|
|
38
|
-
export declare const TimerSpec: Schema.mutable<Schema.Struct<{
|
|
39
|
-
kind: Schema.Literal<["timer"]>;
|
|
40
|
-
cron: Schema.SchemaClass<string, string, never>;
|
|
41
|
-
}>>;
|
|
42
|
-
export type TimerSpec = Schema.Schema.Type<typeof TimerSpec>;
|
|
43
|
-
/**
|
|
44
|
-
* Webhook.
|
|
45
|
-
*/
|
|
46
|
-
export declare const WebhookSpec: Schema.mutable<Schema.Struct<{
|
|
47
|
-
kind: Schema.Literal<["webhook"]>;
|
|
48
|
-
method: Schema.optional<Schema.SchemaClass<string, string, never>>;
|
|
49
|
-
port: Schema.optional<Schema.SchemaClass<number, number, never>>;
|
|
50
|
-
}>>;
|
|
51
|
-
export type WebhookSpec = Schema.Schema.Type<typeof WebhookSpec>;
|
|
52
|
-
/**
|
|
53
|
-
* Trigger schema.
|
|
54
|
-
*/
|
|
55
|
-
export declare const Spec: Schema.Union<[Schema.mutable<Schema.Struct<{
|
|
56
|
-
kind: Schema.Literal<["email"]>;
|
|
57
|
-
}>>, Schema.mutable<Schema.Struct<{
|
|
58
|
-
kind: Schema.Literal<["queue"]>;
|
|
59
|
-
queue: Schema.refine<string, typeof Schema.NonEmptyString>;
|
|
60
|
-
}>>, Schema.mutable<Schema.Struct<{
|
|
61
|
-
kind: Schema.Literal<["subscription"]>;
|
|
62
|
-
query: Schema.mutable<Schema.Struct<{
|
|
63
|
-
raw: Schema.optional<Schema.SchemaClass<string, string, never>>;
|
|
64
|
-
ast: Schema.Schema<QueryAST.QuerySelectClause | QueryAST.QueryFilterClause | QueryAST.QueryReferenceTraversalClause | QueryAST.QueryIncomingReferencesClause | QueryAST.QueryRelationClause | QueryAST.QueryRelationTraversalClause | QueryAST.QueryUnionClause | QueryAST.QuerySetDifferenceClause | QueryAST.QueryOrderClause | QueryAST.QueryOptionsClause, QueryAST.QuerySelectClause | QueryAST.QueryFilterClause | QueryAST.QueryReferenceTraversalClause | QueryAST.QueryIncomingReferencesClause | QueryAST.QueryRelationClause | QueryAST.QueryRelationTraversalClause | QueryAST.QueryUnionClause | QueryAST.QuerySetDifferenceClause | QueryAST.QueryOrderClause | QueryAST.QueryOptionsClause, never>;
|
|
65
|
-
}>>;
|
|
66
|
-
options: Schema.optional<Schema.Struct<{
|
|
67
|
-
deep: Schema.optional<Schema.SchemaClass<boolean, boolean, never>>;
|
|
68
|
-
delay: Schema.optional<Schema.SchemaClass<number, number, never>>;
|
|
69
|
-
}>>;
|
|
70
|
-
}>>, Schema.mutable<Schema.Struct<{
|
|
71
|
-
kind: Schema.Literal<["timer"]>;
|
|
72
|
-
cron: Schema.SchemaClass<string, string, never>;
|
|
73
|
-
}>>, Schema.mutable<Schema.Struct<{
|
|
74
|
-
kind: Schema.Literal<["webhook"]>;
|
|
75
|
-
method: Schema.optional<Schema.SchemaClass<string, string, never>>;
|
|
76
|
-
port: Schema.optional<Schema.SchemaClass<number, number, never>>;
|
|
77
|
-
}>>]>;
|
|
78
|
-
export type Spec = Schema.Schema.Type<typeof Spec>;
|
|
79
|
-
/**
|
|
80
|
-
* Function trigger.
|
|
81
|
-
* Function is invoked with the `payload` passed as input data.
|
|
82
|
-
* The event that triggers the function is available in the function context.
|
|
83
|
-
*/
|
|
84
|
-
declare const Trigger_: Type.obj<Schema.Struct<{
|
|
85
|
-
/**
|
|
86
|
-
* Function or workflow to invoke.
|
|
87
|
-
*/
|
|
88
|
-
function: Schema.optional<Schema.SchemaClass<Ref<Expando>, import("@dxos/echo-protocol").EncodedReference, never>>;
|
|
89
|
-
/**
|
|
90
|
-
* Only used for workflowSchema.
|
|
91
|
-
* Specifies the input node in the circuit.
|
|
92
|
-
* @deprecated Remove and enforce a single input node in all compute graphSchema.
|
|
93
|
-
*/
|
|
94
|
-
inputNodeId: Schema.optional<Schema.SchemaClass<string, string, never>>;
|
|
95
|
-
enabled: Schema.optional<Schema.SchemaClass<boolean, boolean, never>>;
|
|
96
|
-
spec: Schema.optional<Schema.Union<[Schema.mutable<Schema.Struct<{
|
|
97
|
-
kind: Schema.Literal<["email"]>;
|
|
98
|
-
}>>, Schema.mutable<Schema.Struct<{
|
|
99
|
-
kind: Schema.Literal<["queue"]>;
|
|
100
|
-
queue: Schema.refine<string, typeof Schema.NonEmptyString>;
|
|
101
|
-
}>>, Schema.mutable<Schema.Struct<{
|
|
102
|
-
kind: Schema.Literal<["subscription"]>;
|
|
103
|
-
query: Schema.mutable<Schema.Struct<{
|
|
104
|
-
raw: Schema.optional<Schema.SchemaClass<string, string, never>>;
|
|
105
|
-
ast: Schema.Schema<QueryAST.QuerySelectClause | QueryAST.QueryFilterClause | QueryAST.QueryReferenceTraversalClause | QueryAST.QueryIncomingReferencesClause | QueryAST.QueryRelationClause | QueryAST.QueryRelationTraversalClause | QueryAST.QueryUnionClause | QueryAST.QuerySetDifferenceClause | QueryAST.QueryOrderClause | QueryAST.QueryOptionsClause, QueryAST.QuerySelectClause | QueryAST.QueryFilterClause | QueryAST.QueryReferenceTraversalClause | QueryAST.QueryIncomingReferencesClause | QueryAST.QueryRelationClause | QueryAST.QueryRelationTraversalClause | QueryAST.QueryUnionClause | QueryAST.QuerySetDifferenceClause | QueryAST.QueryOrderClause | QueryAST.QueryOptionsClause, never>;
|
|
106
|
-
}>>;
|
|
107
|
-
options: Schema.optional<Schema.Struct<{
|
|
108
|
-
deep: Schema.optional<Schema.SchemaClass<boolean, boolean, never>>;
|
|
109
|
-
delay: Schema.optional<Schema.SchemaClass<number, number, never>>;
|
|
110
|
-
}>>;
|
|
111
|
-
}>>, Schema.mutable<Schema.Struct<{
|
|
112
|
-
kind: Schema.Literal<["timer"]>;
|
|
113
|
-
cron: Schema.SchemaClass<string, string, never>;
|
|
114
|
-
}>>, Schema.mutable<Schema.Struct<{
|
|
115
|
-
kind: Schema.Literal<["webhook"]>;
|
|
116
|
-
method: Schema.optional<Schema.SchemaClass<string, string, never>>;
|
|
117
|
-
port: Schema.optional<Schema.SchemaClass<number, number, never>>;
|
|
118
|
-
}>>]>>;
|
|
119
|
-
/**
|
|
120
|
-
* Passed as the input data to the function.
|
|
121
|
-
* Must match the function's input schema.
|
|
122
|
-
*
|
|
123
|
-
* @example
|
|
124
|
-
* {
|
|
125
|
-
* item: '{{$.trigger.event}}',
|
|
126
|
-
* instructions: 'Summarize and perform entity-extraction'
|
|
127
|
-
* mailbox: { '/': 'dxn:echo:AAA:ZZZ' }
|
|
128
|
-
* }
|
|
129
|
-
*/
|
|
130
|
-
input: Schema.optional<Schema.mutable<Schema.Record$<typeof Schema.String, typeof Schema.Any>>>;
|
|
131
|
-
}>>;
|
|
132
|
-
export interface Trigger extends Schema.Schema.Type<typeof Trigger_> {
|
|
133
|
-
}
|
|
134
|
-
export interface TriggerEncoded extends Schema.Schema.Encoded<typeof Trigger_> {
|
|
135
|
-
}
|
|
136
|
-
export declare const Trigger: Schema.Schema<Trigger, TriggerEncoded>;
|
|
137
|
-
export declare const make: (props: Obj.MakeProps<typeof Trigger>) => import("@dxos/live-object").Live<Trigger>;
|
|
138
|
-
export {};
|
|
139
|
-
//# sourceMappingURL=Trigger.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Trigger.d.ts","sourceRoot":"","sources":["../../../../src/types/Trigger.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AAGxC,OAAO,EAAE,GAAG,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AACjD,OAAO,EAAE,OAAO,EAAuB,GAAG,EAAE,MAAM,qBAAqB,CAAC;AAGxE;;;;GAIG;AACH,eAAO,MAAM,KAAK,iEAAkE,CAAC;AACrF,MAAM,MAAM,IAAI,GAAG,CAAC,OAAO,KAAK,CAAC,CAAC,MAAM,CAAC,CAAC;AAI1C,eAAO,MAAM,SAAS;;GAEC,CAAC;AACxB,MAAM,MAAM,SAAS,GAAG,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,SAAS,CAAC,CAAC;AAE7D,eAAO,MAAM,SAAS;;;GAKC,CAAC;AACxB,MAAM,MAAM,SAAS,GAAG,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,SAAS,CAAC,CAAC;AAE7D;;GAEG;AACH,eAAO,MAAM,gBAAgB;;;;;;;;;;GAcN,CAAC;AACxB,MAAM,MAAM,gBAAgB,GAAG,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,gBAAgB,CAAC,CAAC;AAE3E;;GAEG;AACH,eAAO,MAAM,SAAS;;;GAMC,CAAC;AACxB,MAAM,MAAM,SAAS,GAAG,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,SAAS,CAAC,CAAC;AAE7D;;GAEG;AACH,eAAO,MAAM,WAAW;;;;GAaD,CAAC;AACxB,MAAM,MAAM,WAAW,GAAG,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,WAAW,CAAC,CAAC;AAEjE;;GAEG;AACH,eAAO,MAAM,IAAI;;;;;;;;;;;;;;;;;;;;;;KAEf,CAAC;AACH,MAAM,MAAM,IAAI,GAAG,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,IAAI,CAAC,CAAC;AAEnD;;;;GAIG;AACH,QAAA,MAAM,QAAQ;IACZ;;OAEG;;IAIH;;;;OAIG;;;;;;;;;;;;;;;;;;;;;;;;;;IAOH;;;;;;;;;;OAUG;;GAOJ,CAAC;AACF,MAAM,WAAW,OAAQ,SAAQ,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,QAAQ,CAAC;CAAG;AACvE,MAAM,WAAW,cAAe,SAAQ,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,OAAO,QAAQ,CAAC;CAAG;AACjF,eAAO,MAAM,OAAO,EAAE,MAAM,CAAC,MAAM,CAAC,OAAO,EAAE,cAAc,CAAY,CAAC;AAExE,eAAO,MAAM,IAAI,GAAI,OAAO,GAAG,CAAC,SAAS,CAAC,OAAO,OAAO,CAAC,8CAA6B,CAAC"}
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import * as Schema from 'effect/Schema';
|
|
2
|
-
import { Type } from '@dxos/echo';
|
|
3
|
-
export type TriggerEvent = EmailEvent | QueueEvent | SubscriptionEvent | TimerEvent | WebhookEvent;
|
|
4
|
-
export declare const EmailEvent: Schema.mutable<Schema.Struct<{
|
|
5
|
-
from: typeof Schema.String;
|
|
6
|
-
to: typeof Schema.String;
|
|
7
|
-
subject: typeof Schema.String;
|
|
8
|
-
created: typeof Schema.String;
|
|
9
|
-
body: typeof Schema.String;
|
|
10
|
-
}>>;
|
|
11
|
-
export type EmailEvent = Schema.Schema.Type<typeof EmailEvent>;
|
|
12
|
-
export declare const QueueEvent: Schema.mutable<Schema.Struct<{
|
|
13
|
-
queue: Schema.refine<string, typeof Schema.NonEmptyString>;
|
|
14
|
-
item: typeof Schema.Any;
|
|
15
|
-
cursor: typeof Schema.String;
|
|
16
|
-
}>>;
|
|
17
|
-
export type QueueEvent = Schema.Schema.Type<typeof QueueEvent>;
|
|
18
|
-
export declare const SubscriptionEvent: Schema.mutable<Schema.Struct<{
|
|
19
|
-
/**
|
|
20
|
-
* Type of the mutation.
|
|
21
|
-
*/
|
|
22
|
-
type: typeof Schema.String;
|
|
23
|
-
/**
|
|
24
|
-
* Reference to the object that was changed or created.
|
|
25
|
-
*/
|
|
26
|
-
subject: Type.ref<Type.obj<Schema.Struct<{}>>>;
|
|
27
|
-
/**
|
|
28
|
-
* @deprecated
|
|
29
|
-
*/
|
|
30
|
-
changedObjectId: Schema.optional<typeof Schema.String>;
|
|
31
|
-
}>>;
|
|
32
|
-
export type SubscriptionEvent = Schema.Schema.Type<typeof SubscriptionEvent>;
|
|
33
|
-
export declare const TimerEvent: Schema.mutable<Schema.Struct<{
|
|
34
|
-
tick: typeof Schema.Number;
|
|
35
|
-
}>>;
|
|
36
|
-
export type TimerEvent = Schema.Schema.Type<typeof TimerEvent>;
|
|
37
|
-
export declare const WebhookEvent: Schema.mutable<Schema.Struct<{
|
|
38
|
-
url: typeof Schema.String;
|
|
39
|
-
method: Schema.Literal<["GET", "POST"]>;
|
|
40
|
-
headers: Schema.Record$<typeof Schema.String, typeof Schema.String>;
|
|
41
|
-
bodyText: typeof Schema.String;
|
|
42
|
-
}>>;
|
|
43
|
-
export type WebhookEvent = Schema.Schema.Type<typeof WebhookEvent>;
|
|
44
|
-
//# sourceMappingURL=TriggerEvent.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"TriggerEvent.d.ts","sourceRoot":"","sources":["../../../../src/types/TriggerEvent.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AAExC,OAAO,EAAY,IAAI,EAAE,MAAM,YAAY,CAAC;AAE5C,MAAM,MAAM,YAAY,GAAG,UAAU,GAAG,UAAU,GAAG,iBAAiB,GAAG,UAAU,GAAG,YAAY,CAAC;AAGnG,eAAO,MAAM,UAAU;;;;;;GAQtB,CAAC;AACF,MAAM,MAAM,UAAU,GAAG,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,UAAU,CAAC,CAAC;AAE/D,eAAO,MAAM,UAAU;;;;GAMtB,CAAC;AACF,MAAM,MAAM,UAAU,GAAG,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,UAAU,CAAC,CAAC;AAE/D,eAAO,MAAM,iBAAiB;IAC5B;;OAEG;;IAIH;;OAEG;;IAGH;;OAEG;;GAEkB,CAAC;AACxB,MAAM,MAAM,iBAAiB,GAAG,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,iBAAiB,CAAC,CAAC;AAE7E,eAAO,MAAM,UAAU;;GAAyD,CAAC;AACjF,MAAM,MAAM,UAAU,GAAG,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,UAAU,CAAC,CAAC;AAE/D,eAAO,MAAM,YAAY;;;;;GAOxB,CAAC;AACF,MAAM,MAAM,YAAY,GAAG,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,YAAY,CAAC,CAAC"}
|
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
|
-
});
|