@dxos/functions 0.8.4-main.5ea62a8 → 0.8.4-main.72ec0f3
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 +769 -407
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node-esm/index.mjs +769 -407
- 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 +87 -28
- package/dist/types/src/errors.d.ts.map +1 -1
- package/dist/types/src/{examples → example}/fib.d.ts +1 -1
- package/dist/types/src/example/fib.d.ts.map +1 -0
- package/dist/types/src/example/forex-effect.d.ts +3 -0
- package/dist/types/src/example/forex-effect.d.ts.map +1 -0
- package/dist/types/src/example/index.d.ts +12 -0
- package/dist/types/src/example/index.d.ts.map +1 -0
- package/dist/types/src/{examples → example}/reply.d.ts +1 -1
- package/dist/types/src/example/reply.d.ts.map +1 -0
- package/dist/types/src/{examples → example}/sleep.d.ts +1 -1
- package/dist/types/src/example/sleep.d.ts.map +1 -0
- package/dist/types/src/index.d.ts +5 -7
- package/dist/types/src/index.d.ts.map +1 -1
- 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 +89 -0
- package/dist/types/src/sdk.d.ts.map +1 -0
- package/dist/types/src/services/credentials.d.ts +7 -3
- package/dist/types/src/services/credentials.d.ts.map +1 -1
- package/dist/types/src/services/event-logger.d.ts +20 -5
- package/dist/types/src/services/event-logger.d.ts.map +1 -1
- package/dist/types/src/services/function-invocation-service.d.ts +11 -0
- package/dist/types/src/services/function-invocation-service.d.ts.map +1 -0
- package/dist/types/src/services/index.d.ts +6 -6
- package/dist/types/src/services/index.d.ts.map +1 -1
- package/dist/types/src/services/queues.d.ts +4 -1
- package/dist/types/src/services/queues.d.ts.map +1 -1
- package/dist/types/src/services/tracing.d.ts +10 -12
- package/dist/types/src/services/tracing.d.ts.map +1 -1
- package/dist/types/src/types/Function.d.ts +58 -0
- package/dist/types/src/types/Function.d.ts.map +1 -0
- package/dist/types/src/types/Script.d.ts +28 -0
- package/dist/types/src/types/Script.d.ts.map +1 -0
- package/dist/types/src/types/Trigger.d.ts +139 -0
- package/dist/types/src/types/Trigger.d.ts.map +1 -0
- package/dist/types/src/types/TriggerEvent.d.ts +44 -0
- package/dist/types/src/types/TriggerEvent.d.ts.map +1 -0
- package/dist/types/src/types/index.d.ts +6 -0
- package/dist/types/src/types/index.d.ts.map +1 -0
- package/dist/types/src/{url.d.ts → types/url.d.ts} +1 -10
- package/dist/types/src/types/url.d.ts.map +1 -0
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +17 -72
- package/src/errors.ts +13 -5
- package/src/{examples → example}/fib.ts +5 -3
- package/src/example/forex-effect.ts +40 -0
- package/src/example/index.ts +13 -0
- package/src/{examples → example}/reply.ts +6 -3
- package/src/{examples → example}/sleep.ts +5 -3
- package/src/index.ts +5 -9
- package/src/{executor → protocol}/index.ts +1 -1
- package/src/protocol/protocol.test.ts +59 -0
- package/src/protocol/protocol.ts +145 -0
- package/src/sdk.ts +226 -0
- package/src/services/credentials.ts +12 -6
- package/src/services/event-logger.ts +12 -3
- package/src/services/function-invocation-service.ts +23 -0
- package/src/services/index.ts +7 -6
- package/src/services/queues.ts +8 -1
- package/src/services/tracing.ts +26 -52
- package/src/{schema.ts → types/Function.ts} +20 -26
- package/src/types/Script.ts +33 -0
- package/src/types/Trigger.ts +139 -0
- package/src/types/TriggerEvent.ts +62 -0
- package/src/types/index.ts +9 -0
- package/src/types/url.ts +31 -0
- package/dist/lib/browser/bundler/index.mjs +0 -263
- package/dist/lib/browser/bundler/index.mjs.map +0 -7
- package/dist/lib/browser/chunk-7NQ77AIQ.mjs +0 -618
- package/dist/lib/browser/chunk-7NQ77AIQ.mjs.map +0 -7
- package/dist/lib/browser/edge/index.mjs +0 -81
- package/dist/lib/browser/edge/index.mjs.map +0 -7
- package/dist/lib/browser/testing/index.mjs +0 -122
- package/dist/lib/browser/testing/index.mjs.map +0 -7
- package/dist/lib/node-esm/bundler/index.mjs +0 -265
- package/dist/lib/node-esm/bundler/index.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-KCGC6QQT.mjs +0 -620
- package/dist/lib/node-esm/chunk-KCGC6QQT.mjs.map +0 -7
- package/dist/lib/node-esm/edge/index.mjs +0 -83
- package/dist/lib/node-esm/edge/index.mjs.map +0 -7
- package/dist/lib/node-esm/testing/index.mjs +0 -123
- 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/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/examples/fib.d.ts.map +0 -1
- package/dist/types/src/examples/reply.d.ts.map +0 -1
- package/dist/types/src/examples/sleep.d.ts.map +0 -1
- package/dist/types/src/executor/executor.d.ts +0 -11
- 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 -65
- package/dist/types/src/handler.d.ts.map +0 -1
- package/dist/types/src/schema.d.ts +0 -43
- package/dist/types/src/schema.d.ts.map +0 -1
- package/dist/types/src/services/database.d.ts +0 -98
- package/dist/types/src/services/database.d.ts.map +0 -1
- package/dist/types/src/services/local-function-execution.d.ts +0 -12
- 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 -15
- package/dist/types/src/services/remote-function-execution-service.d.ts.map +0 -1
- package/dist/types/src/services/service-container.d.ts +0 -56
- package/dist/types/src/services/service-container.d.ts.map +0 -1
- package/dist/types/src/services/service-registry.d.ts +0 -29
- 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 -14
- 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 -150
- 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/types.d.ts +0 -328
- package/dist/types/src/types.d.ts.map +0 -1
- package/dist/types/src/url.d.ts.map +0 -1
- package/src/bundler/bundler.test.ts +0 -58
- package/src/bundler/bundler.ts +0 -291
- package/src/bundler/index.ts +0 -5
- package/src/edge/functions.ts +0 -67
- package/src/edge/index.ts +0 -9
- package/src/executor/executor.ts +0 -54
- package/src/handler.ts +0 -122
- package/src/services/database.ts +0 -170
- package/src/services/local-function-execution.ts +0 -77
- package/src/services/remote-function-execution-service.ts +0 -46
- package/src/services/service-container.ts +0 -114
- package/src/services/service-registry.test.ts +0 -42
- package/src/services/service-registry.ts +0 -59
- package/src/testing/index.ts +0 -6
- package/src/testing/layer.ts +0 -97
- package/src/testing/logger.ts +0 -16
- 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/types.ts +0 -203
- package/src/url.ts +0 -55
|
@@ -1,328 +0,0 @@
|
|
|
1
|
-
import { Schema } from 'effect';
|
|
2
|
-
import { Type } from '@dxos/echo';
|
|
3
|
-
import { Expando, Ref } from '@dxos/echo-schema';
|
|
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 TriggerKinds: readonly ["timer", "webhook", "subscription", "email", "queue"];
|
|
10
|
-
export type TriggerKind = (typeof TriggerKinds)[number];
|
|
11
|
-
/**
|
|
12
|
-
* Cron timer.
|
|
13
|
-
*/
|
|
14
|
-
declare const TimerTriggerSchema: Schema.mutable<Schema.Struct<{
|
|
15
|
-
kind: Schema.Literal<["timer"]>;
|
|
16
|
-
cron: Schema.SchemaClass<string, string, never>;
|
|
17
|
-
}>>;
|
|
18
|
-
export type TimerTrigger = Schema.Schema.Type<typeof TimerTriggerSchema>;
|
|
19
|
-
declare const EmailTriggerSchema: Schema.mutable<Schema.Struct<{
|
|
20
|
-
kind: Schema.Literal<["email"]>;
|
|
21
|
-
}>>;
|
|
22
|
-
export type EmailTrigger = Schema.Schema.Type<typeof EmailTriggerSchema>;
|
|
23
|
-
declare const QueueTriggerSchema: Schema.mutable<Schema.Struct<{
|
|
24
|
-
kind: Schema.Literal<["queue"]>;
|
|
25
|
-
queue: Schema.refine<string, typeof Schema.NonEmptyString>;
|
|
26
|
-
}>>;
|
|
27
|
-
export type QueueTrigger = Schema.Schema.Type<typeof QueueTriggerSchema>;
|
|
28
|
-
/**
|
|
29
|
-
* Webhook.
|
|
30
|
-
*/
|
|
31
|
-
declare const WebhookTriggerSchema: Schema.mutable<Schema.Struct<{
|
|
32
|
-
kind: Schema.Literal<["webhook"]>;
|
|
33
|
-
method: Schema.optional<Schema.SchemaClass<string, string, never>>;
|
|
34
|
-
port: Schema.optional<Schema.SchemaClass<number, number, never>>;
|
|
35
|
-
}>>;
|
|
36
|
-
export type WebhookTrigger = Schema.Schema.Type<typeof WebhookTriggerSchema>;
|
|
37
|
-
/**
|
|
38
|
-
* Subscription.
|
|
39
|
-
*/
|
|
40
|
-
declare const SubscriptionTriggerSchema: Schema.mutable<Schema.Struct<{
|
|
41
|
-
kind: Schema.Literal<["subscription"]>;
|
|
42
|
-
filter: Schema.Struct<{
|
|
43
|
-
type: Schema.optional<Schema.SchemaClass<string, string, never>>;
|
|
44
|
-
props: Schema.optional<Schema.Record$<typeof Schema.String, typeof Schema.Any>>;
|
|
45
|
-
}>;
|
|
46
|
-
options: Schema.optional<Schema.Struct<{
|
|
47
|
-
deep: Schema.optional<Schema.SchemaClass<boolean, boolean, never>>;
|
|
48
|
-
delay: Schema.optional<Schema.SchemaClass<number, number, never>>;
|
|
49
|
-
}>>;
|
|
50
|
-
}>>;
|
|
51
|
-
export type SubscriptionTrigger = Schema.Schema.Type<typeof SubscriptionTriggerSchema>;
|
|
52
|
-
/**
|
|
53
|
-
* Trigger schema (discriminated union).
|
|
54
|
-
*/
|
|
55
|
-
export declare const TriggerSchema: Schema.Union<[Schema.mutable<Schema.Struct<{
|
|
56
|
-
kind: Schema.Literal<["timer"]>;
|
|
57
|
-
cron: Schema.SchemaClass<string, string, never>;
|
|
58
|
-
}>>, Schema.mutable<Schema.Struct<{
|
|
59
|
-
kind: Schema.Literal<["webhook"]>;
|
|
60
|
-
method: Schema.optional<Schema.SchemaClass<string, string, never>>;
|
|
61
|
-
port: Schema.optional<Schema.SchemaClass<number, number, never>>;
|
|
62
|
-
}>>, Schema.mutable<Schema.Struct<{
|
|
63
|
-
kind: Schema.Literal<["subscription"]>;
|
|
64
|
-
filter: Schema.Struct<{
|
|
65
|
-
type: Schema.optional<Schema.SchemaClass<string, string, never>>;
|
|
66
|
-
props: Schema.optional<Schema.Record$<typeof Schema.String, typeof Schema.Any>>;
|
|
67
|
-
}>;
|
|
68
|
-
options: Schema.optional<Schema.Struct<{
|
|
69
|
-
deep: Schema.optional<Schema.SchemaClass<boolean, boolean, never>>;
|
|
70
|
-
delay: Schema.optional<Schema.SchemaClass<number, number, never>>;
|
|
71
|
-
}>>;
|
|
72
|
-
}>>, Schema.mutable<Schema.Struct<{
|
|
73
|
-
kind: Schema.Literal<["email"]>;
|
|
74
|
-
}>>, Schema.mutable<Schema.Struct<{
|
|
75
|
-
kind: Schema.Literal<["queue"]>;
|
|
76
|
-
queue: Schema.refine<string, typeof Schema.NonEmptyString>;
|
|
77
|
-
}>>]>;
|
|
78
|
-
export type TriggerType = Schema.Schema.Type<typeof TriggerSchema>;
|
|
79
|
-
export type EventType = EmailTriggerOutput | WebhookTriggerOutput | QueueTriggerOutput | SubscriptionTriggerOutput | TimerTriggerOutput;
|
|
80
|
-
export declare const EmailTriggerOutput: Schema.mutable<Schema.Struct<{
|
|
81
|
-
from: typeof Schema.String;
|
|
82
|
-
to: typeof Schema.String;
|
|
83
|
-
subject: typeof Schema.String;
|
|
84
|
-
created: typeof Schema.String;
|
|
85
|
-
body: typeof Schema.String;
|
|
86
|
-
}>>;
|
|
87
|
-
export type EmailTriggerOutput = Schema.Schema.Type<typeof EmailTriggerOutput>;
|
|
88
|
-
export declare const WebhookTriggerOutput: Schema.mutable<Schema.Struct<{
|
|
89
|
-
url: typeof Schema.String;
|
|
90
|
-
method: Schema.Literal<["GET", "POST"]>;
|
|
91
|
-
headers: Schema.Record$<typeof Schema.String, typeof Schema.String>;
|
|
92
|
-
bodyText: typeof Schema.String;
|
|
93
|
-
}>>;
|
|
94
|
-
export type WebhookTriggerOutput = Schema.Schema.Type<typeof WebhookTriggerOutput>;
|
|
95
|
-
export declare const QueueTriggerOutput: Schema.mutable<Schema.Struct<{
|
|
96
|
-
queue: Schema.refine<string, typeof Schema.NonEmptyString>;
|
|
97
|
-
item: typeof Schema.Any;
|
|
98
|
-
cursor: typeof Schema.String;
|
|
99
|
-
}>>;
|
|
100
|
-
export type QueueTriggerOutput = Schema.Schema.Type<typeof QueueTriggerOutput>;
|
|
101
|
-
export declare const SubscriptionTriggerOutput: Schema.mutable<Schema.Struct<{
|
|
102
|
-
type: typeof Schema.String;
|
|
103
|
-
changedObjectId: typeof Schema.String;
|
|
104
|
-
}>>;
|
|
105
|
-
export type SubscriptionTriggerOutput = Schema.Schema.Type<typeof SubscriptionTriggerOutput>;
|
|
106
|
-
export declare const TimerTriggerOutput: Schema.mutable<Schema.Struct<{
|
|
107
|
-
tick: typeof Schema.Number;
|
|
108
|
-
}>>;
|
|
109
|
-
export type TimerTriggerOutput = Schema.Schema.Type<typeof TimerTriggerOutput>;
|
|
110
|
-
/**
|
|
111
|
-
* Function trigger.
|
|
112
|
-
* Function is invoked with the `payload` passed as input data.
|
|
113
|
-
* The event that triggers the function is available in the function context.
|
|
114
|
-
*/
|
|
115
|
-
export declare const FunctionTrigger: Type.obj<Schema.Struct<{
|
|
116
|
-
/**
|
|
117
|
-
* Function or workflow to invoke.
|
|
118
|
-
*/
|
|
119
|
-
function: Schema.optional<Schema.SchemaClass<Ref<Expando>, import("@dxos/echo-protocol").EncodedReference, never>>;
|
|
120
|
-
/**
|
|
121
|
-
* Only used for workflowSchema.
|
|
122
|
-
* Specifies the input node in the circuit.
|
|
123
|
-
* @deprecated Remove and enforce a single input node in all compute graphSchema.
|
|
124
|
-
*/
|
|
125
|
-
inputNodeId: Schema.optional<Schema.SchemaClass<string, string, never>>;
|
|
126
|
-
enabled: Schema.optional<Schema.SchemaClass<boolean, boolean, never>>;
|
|
127
|
-
spec: Schema.optional<Schema.Union<[Schema.mutable<Schema.Struct<{
|
|
128
|
-
kind: Schema.Literal<["timer"]>;
|
|
129
|
-
cron: Schema.SchemaClass<string, string, never>;
|
|
130
|
-
}>>, Schema.mutable<Schema.Struct<{
|
|
131
|
-
kind: Schema.Literal<["webhook"]>;
|
|
132
|
-
method: Schema.optional<Schema.SchemaClass<string, string, never>>;
|
|
133
|
-
port: Schema.optional<Schema.SchemaClass<number, number, never>>;
|
|
134
|
-
}>>, Schema.mutable<Schema.Struct<{
|
|
135
|
-
kind: Schema.Literal<["subscription"]>;
|
|
136
|
-
filter: Schema.Struct<{
|
|
137
|
-
type: Schema.optional<Schema.SchemaClass<string, string, never>>;
|
|
138
|
-
props: Schema.optional<Schema.Record$<typeof Schema.String, typeof Schema.Any>>;
|
|
139
|
-
}>;
|
|
140
|
-
options: Schema.optional<Schema.Struct<{
|
|
141
|
-
deep: Schema.optional<Schema.SchemaClass<boolean, boolean, never>>;
|
|
142
|
-
delay: Schema.optional<Schema.SchemaClass<number, number, never>>;
|
|
143
|
-
}>>;
|
|
144
|
-
}>>, Schema.mutable<Schema.Struct<{
|
|
145
|
-
kind: Schema.Literal<["email"]>;
|
|
146
|
-
}>>, Schema.mutable<Schema.Struct<{
|
|
147
|
-
kind: Schema.Literal<["queue"]>;
|
|
148
|
-
queue: Schema.refine<string, typeof Schema.NonEmptyString>;
|
|
149
|
-
}>>]>>;
|
|
150
|
-
/**
|
|
151
|
-
* Passed as the input data to the function.
|
|
152
|
-
* Must match the function's input schema.
|
|
153
|
-
*
|
|
154
|
-
* @example
|
|
155
|
-
* {
|
|
156
|
-
* item: '{{$.trigger.event}}',
|
|
157
|
-
* instructions: 'Summarize and perform entity-extraction'
|
|
158
|
-
* mailbox: { '/': 'dxn:echo:AAA:ZZZ' }
|
|
159
|
-
* }
|
|
160
|
-
*/
|
|
161
|
-
input: Schema.optional<Schema.mutable<Schema.Record$<typeof Schema.String, typeof Schema.Any>>>;
|
|
162
|
-
}>>;
|
|
163
|
-
export type FunctionTrigger = Schema.Schema.Type<typeof FunctionTrigger>;
|
|
164
|
-
/**
|
|
165
|
-
* Function manifest file.
|
|
166
|
-
*/
|
|
167
|
-
export declare const FunctionManifestSchema: Schema.Struct<{
|
|
168
|
-
functions: Schema.optional<Schema.mutable<Schema.Array$<Schema.Schema<import("@dxos/echo-schema").ExcludeId<Type.OfKind<import("@dxos/echo-schema").EntityKind.Object> & {
|
|
169
|
-
description?: string | undefined;
|
|
170
|
-
version: string;
|
|
171
|
-
source?: Ref<Type.OfKind<import("@dxos/echo-schema").EntityKind.Object> & {
|
|
172
|
-
description?: string | undefined;
|
|
173
|
-
source: Ref<Type.OfKind<import("@dxos/echo-schema").EntityKind.Object> & {
|
|
174
|
-
content: string;
|
|
175
|
-
}>;
|
|
176
|
-
name?: string | undefined;
|
|
177
|
-
changed?: boolean | undefined;
|
|
178
|
-
}> | undefined;
|
|
179
|
-
name: string;
|
|
180
|
-
key?: string | undefined;
|
|
181
|
-
inputSchema?: Type.JsonSchema | undefined;
|
|
182
|
-
outputSchema?: Type.JsonSchema | undefined;
|
|
183
|
-
binding?: string | undefined;
|
|
184
|
-
}> & import("@dxos/echo-schema").WithMeta, {
|
|
185
|
-
id: string;
|
|
186
|
-
version: string;
|
|
187
|
-
name: string;
|
|
188
|
-
description?: string | undefined;
|
|
189
|
-
source?: import("@dxos/echo-protocol").EncodedReference | undefined;
|
|
190
|
-
key?: string | undefined;
|
|
191
|
-
inputSchema?: Type.JsonSchema | undefined;
|
|
192
|
-
outputSchema?: Type.JsonSchema | undefined;
|
|
193
|
-
binding?: string | undefined;
|
|
194
|
-
}, never>>>>;
|
|
195
|
-
triggers: Schema.optional<Schema.mutable<Schema.Array$<Schema.Schema<import("@dxos/echo-schema").ExcludeId<Type.OfKind<import("@dxos/echo-schema").EntityKind.Object> & {
|
|
196
|
-
function?: Ref<Expando> | undefined;
|
|
197
|
-
input?: {
|
|
198
|
-
[x: string]: any;
|
|
199
|
-
} | undefined;
|
|
200
|
-
inputNodeId?: string | undefined;
|
|
201
|
-
enabled?: boolean | undefined;
|
|
202
|
-
spec?: {
|
|
203
|
-
kind: "timer";
|
|
204
|
-
cron: string;
|
|
205
|
-
} | {
|
|
206
|
-
kind: "email";
|
|
207
|
-
} | {
|
|
208
|
-
kind: "queue";
|
|
209
|
-
queue: string;
|
|
210
|
-
} | {
|
|
211
|
-
kind: "webhook";
|
|
212
|
-
method?: string | undefined;
|
|
213
|
-
port?: number | undefined;
|
|
214
|
-
} | {
|
|
215
|
-
filter: {
|
|
216
|
-
readonly type?: string | undefined;
|
|
217
|
-
readonly props?: {
|
|
218
|
-
readonly [x: string]: any;
|
|
219
|
-
} | undefined;
|
|
220
|
-
};
|
|
221
|
-
kind: "subscription";
|
|
222
|
-
options?: {
|
|
223
|
-
readonly deep?: boolean | undefined;
|
|
224
|
-
readonly delay?: number | undefined;
|
|
225
|
-
} | undefined;
|
|
226
|
-
} | undefined;
|
|
227
|
-
}> & import("@dxos/echo-schema").WithMeta, {
|
|
228
|
-
id: string;
|
|
229
|
-
function?: import("@dxos/echo-protocol").EncodedReference | undefined;
|
|
230
|
-
input?: {
|
|
231
|
-
[x: string]: any;
|
|
232
|
-
} | undefined;
|
|
233
|
-
inputNodeId?: string | undefined;
|
|
234
|
-
enabled?: boolean | undefined;
|
|
235
|
-
spec?: {
|
|
236
|
-
kind: "timer";
|
|
237
|
-
cron: string;
|
|
238
|
-
} | {
|
|
239
|
-
kind: "email";
|
|
240
|
-
} | {
|
|
241
|
-
kind: "queue";
|
|
242
|
-
queue: string;
|
|
243
|
-
} | {
|
|
244
|
-
kind: "webhook";
|
|
245
|
-
method?: string | undefined;
|
|
246
|
-
port?: number | undefined;
|
|
247
|
-
} | {
|
|
248
|
-
filter: {
|
|
249
|
-
readonly type?: string | undefined;
|
|
250
|
-
readonly props?: {
|
|
251
|
-
readonly [x: string]: any;
|
|
252
|
-
} | undefined;
|
|
253
|
-
};
|
|
254
|
-
kind: "subscription";
|
|
255
|
-
options?: {
|
|
256
|
-
readonly deep?: boolean | undefined;
|
|
257
|
-
readonly delay?: number | undefined;
|
|
258
|
-
} | undefined;
|
|
259
|
-
} | undefined;
|
|
260
|
-
}, never>>>>;
|
|
261
|
-
}>;
|
|
262
|
-
export type FunctionManifest = Schema.Schema.Type<typeof FunctionManifestSchema>;
|
|
263
|
-
export declare const FUNCTION_TYPES: (Type.obj<Schema.Struct<{
|
|
264
|
-
key: Schema.optional<typeof Schema.String>;
|
|
265
|
-
name: typeof Schema.NonEmptyString;
|
|
266
|
-
version: typeof Schema.String;
|
|
267
|
-
description: Schema.optional<typeof Schema.String>;
|
|
268
|
-
source: Schema.optional<import("@dxos/echo-schema").Ref$<Type.OfKind<import("@dxos/echo-schema").EntityKind.Object> & {
|
|
269
|
-
description?: string | undefined;
|
|
270
|
-
source: Ref<Type.OfKind<import("@dxos/echo-schema").EntityKind.Object> & {
|
|
271
|
-
content: string;
|
|
272
|
-
}>;
|
|
273
|
-
name?: string | undefined;
|
|
274
|
-
changed?: boolean | undefined;
|
|
275
|
-
}>>;
|
|
276
|
-
inputSchema: Schema.optional<Schema.Schema<Type.JsonSchema, Type.JsonSchema, never>>;
|
|
277
|
-
outputSchema: Schema.optional<Schema.Schema<Type.JsonSchema, Type.JsonSchema, never>>;
|
|
278
|
-
binding: Schema.optional<typeof Schema.String>;
|
|
279
|
-
}>> | Type.obj<Schema.Struct<{
|
|
280
|
-
/**
|
|
281
|
-
* Function or workflow to invoke.
|
|
282
|
-
*/
|
|
283
|
-
function: Schema.optional<Schema.SchemaClass<Ref<Expando>, import("@dxos/echo-protocol").EncodedReference, never>>;
|
|
284
|
-
/**
|
|
285
|
-
* Only used for workflowSchema.
|
|
286
|
-
* Specifies the input node in the circuit.
|
|
287
|
-
* @deprecated Remove and enforce a single input node in all compute graphSchema.
|
|
288
|
-
*/
|
|
289
|
-
inputNodeId: Schema.optional<Schema.SchemaClass<string, string, never>>;
|
|
290
|
-
enabled: Schema.optional<Schema.SchemaClass<boolean, boolean, never>>;
|
|
291
|
-
spec: Schema.optional<Schema.Union<[Schema.mutable<Schema.Struct<{
|
|
292
|
-
kind: Schema.Literal<["timer"]>;
|
|
293
|
-
cron: Schema.SchemaClass<string, string, never>;
|
|
294
|
-
}>>, Schema.mutable<Schema.Struct<{
|
|
295
|
-
kind: Schema.Literal<["webhook"]>;
|
|
296
|
-
method: Schema.optional<Schema.SchemaClass<string, string, never>>;
|
|
297
|
-
port: Schema.optional<Schema.SchemaClass<number, number, never>>;
|
|
298
|
-
}>>, Schema.mutable<Schema.Struct<{
|
|
299
|
-
kind: Schema.Literal<["subscription"]>;
|
|
300
|
-
filter: Schema.Struct<{
|
|
301
|
-
type: Schema.optional<Schema.SchemaClass<string, string, never>>;
|
|
302
|
-
props: Schema.optional<Schema.Record$<typeof Schema.String, typeof Schema.Any>>;
|
|
303
|
-
}>;
|
|
304
|
-
options: Schema.optional<Schema.Struct<{
|
|
305
|
-
deep: Schema.optional<Schema.SchemaClass<boolean, boolean, never>>;
|
|
306
|
-
delay: Schema.optional<Schema.SchemaClass<number, number, never>>;
|
|
307
|
-
}>>;
|
|
308
|
-
}>>, Schema.mutable<Schema.Struct<{
|
|
309
|
-
kind: Schema.Literal<["email"]>;
|
|
310
|
-
}>>, Schema.mutable<Schema.Struct<{
|
|
311
|
-
kind: Schema.Literal<["queue"]>;
|
|
312
|
-
queue: Schema.refine<string, typeof Schema.NonEmptyString>;
|
|
313
|
-
}>>]>>;
|
|
314
|
-
/**
|
|
315
|
-
* Passed as the input data to the function.
|
|
316
|
-
* Must match the function's input schema.
|
|
317
|
-
*
|
|
318
|
-
* @example
|
|
319
|
-
* {
|
|
320
|
-
* item: '{{$.trigger.event}}',
|
|
321
|
-
* instructions: 'Summarize and perform entity-extraction'
|
|
322
|
-
* mailbox: { '/': 'dxn:echo:AAA:ZZZ' }
|
|
323
|
-
* }
|
|
324
|
-
*/
|
|
325
|
-
input: Schema.optional<Schema.mutable<Schema.Record$<typeof Schema.String, typeof Schema.Any>>>;
|
|
326
|
-
}>>)[];
|
|
327
|
-
export {};
|
|
328
|
-
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/types.ts"],"names":[],"mappings":"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"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"url.d.ts","sourceRoot":"","sources":["../../../src/url.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,UAAU,EAAE,MAAM,mBAAmB,CAAC;AACpD,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,291 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright 2023 DXOS.org
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
import { FetchHttpClient, HttpClient } from '@effect/platform';
|
|
6
|
-
import { Duration, Effect, Schedule, pipe } from 'effect';
|
|
7
|
-
import { type BuildOptions, type BuildResult, type Loader, type Plugin, build, initialize } from 'esbuild-wasm';
|
|
8
|
-
|
|
9
|
-
import { subtleCrypto } from '@dxos/crypto';
|
|
10
|
-
import { runAndForwardErrors } from '@dxos/effect';
|
|
11
|
-
import { invariant } from '@dxos/invariant';
|
|
12
|
-
import { log } from '@dxos/log';
|
|
13
|
-
|
|
14
|
-
export type Import = {
|
|
15
|
-
moduleUrl: string;
|
|
16
|
-
defaultImport: boolean;
|
|
17
|
-
namedImports: string[];
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
export type BundleOptions = {
|
|
21
|
-
/**
|
|
22
|
-
* Source code to bundle.
|
|
23
|
-
*/
|
|
24
|
-
source: string;
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
export type BundleResult =
|
|
28
|
-
| {
|
|
29
|
-
timestamp: number;
|
|
30
|
-
sourceHash: Buffer;
|
|
31
|
-
error: unknown;
|
|
32
|
-
}
|
|
33
|
-
| {
|
|
34
|
-
timestamp: number;
|
|
35
|
-
sourceHash: Buffer;
|
|
36
|
-
imports: Import[];
|
|
37
|
-
entryPoint: string;
|
|
38
|
-
asset: Uint8Array;
|
|
39
|
-
bundle: string;
|
|
40
|
-
};
|
|
41
|
-
|
|
42
|
-
export type BundlerOptions = {
|
|
43
|
-
platform: BuildOptions['platform'];
|
|
44
|
-
sandboxedModules: string[];
|
|
45
|
-
remoteModules: Record<string, string>;
|
|
46
|
-
};
|
|
47
|
-
|
|
48
|
-
let initialized: Promise<void>;
|
|
49
|
-
export const initializeBundler = async (options: { wasmUrl: string }) => {
|
|
50
|
-
await (initialized ??= initialize({
|
|
51
|
-
wasmURL: options.wasmUrl,
|
|
52
|
-
}));
|
|
53
|
-
};
|
|
54
|
-
|
|
55
|
-
/**
|
|
56
|
-
* ESBuild bundler.
|
|
57
|
-
*/
|
|
58
|
-
export class Bundler {
|
|
59
|
-
constructor(private readonly _options: BundlerOptions) {}
|
|
60
|
-
|
|
61
|
-
async bundle({ source }: BundleOptions): Promise<BundleResult> {
|
|
62
|
-
const { sandboxedModules: providedModules, ...options } = this._options;
|
|
63
|
-
const sourceHash = Buffer.from(await subtleCrypto.digest('SHA-256', Buffer.from(source)));
|
|
64
|
-
|
|
65
|
-
if (this._options.platform === 'browser') {
|
|
66
|
-
invariant(initialized, 'Compiler not initialized.');
|
|
67
|
-
await initialized;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
const imports = source ? analyzeSourceFileImports(source) : [];
|
|
71
|
-
|
|
72
|
-
// https://esbuild.github.io/api/#build
|
|
73
|
-
try {
|
|
74
|
-
const result = await build({
|
|
75
|
-
platform: options.platform,
|
|
76
|
-
conditions: ['workerd', 'browser'],
|
|
77
|
-
metafile: true,
|
|
78
|
-
write: false,
|
|
79
|
-
entryPoints: {
|
|
80
|
-
// Gets mapped to `userFunc.js` by esbuild.
|
|
81
|
-
userFunc: 'memory:main.tsx',
|
|
82
|
-
},
|
|
83
|
-
bundle: true,
|
|
84
|
-
format: 'esm',
|
|
85
|
-
plugins: [
|
|
86
|
-
{
|
|
87
|
-
name: 'memory',
|
|
88
|
-
setup: (build) => {
|
|
89
|
-
build.onResolve({ filter: /^\.\/runtime\.js$/ }, ({ path }) => {
|
|
90
|
-
return { path, external: true };
|
|
91
|
-
});
|
|
92
|
-
|
|
93
|
-
build.onResolve({ filter: /^dxos:functions$/ }, ({ path }) => {
|
|
94
|
-
return { path: './runtime.js', external: true };
|
|
95
|
-
});
|
|
96
|
-
|
|
97
|
-
build.onResolve({ filter: /^memory:/ }, ({ path }) => {
|
|
98
|
-
return { path: path.split(':')[1], namespace: 'memory' };
|
|
99
|
-
});
|
|
100
|
-
|
|
101
|
-
build.onLoad({ filter: /.*/, namespace: 'memory' }, ({ path }) => {
|
|
102
|
-
if (path === 'main.tsx') {
|
|
103
|
-
return {
|
|
104
|
-
contents: source,
|
|
105
|
-
loader: 'tsx',
|
|
106
|
-
};
|
|
107
|
-
}
|
|
108
|
-
});
|
|
109
|
-
|
|
110
|
-
for (const module of providedModules) {
|
|
111
|
-
build.onResolve({ filter: new RegExp(`^${module}$`) }, ({ path }) => {
|
|
112
|
-
return { path, namespace: 'injected-module' };
|
|
113
|
-
});
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
build.onLoad({ filter: /.*/, namespace: 'injected-module' }, ({ path }) => {
|
|
117
|
-
const namedImports = imports.find((entry) => entry.moduleIdentifier === path)?.namedImports ?? [];
|
|
118
|
-
return {
|
|
119
|
-
contents: `
|
|
120
|
-
const { ${namedImports.join(',')} } = window.__DXOS_SANDBOX_MODULES__[${JSON.stringify(path)}];
|
|
121
|
-
export { ${namedImports.join(',')} };
|
|
122
|
-
export default window.__DXOS_SANDBOX_MODULES__[${JSON.stringify(path)}].default;
|
|
123
|
-
`,
|
|
124
|
-
loader: 'tsx',
|
|
125
|
-
};
|
|
126
|
-
});
|
|
127
|
-
},
|
|
128
|
-
},
|
|
129
|
-
httpPlugin,
|
|
130
|
-
],
|
|
131
|
-
});
|
|
132
|
-
|
|
133
|
-
log('compile complete', result.metafile);
|
|
134
|
-
|
|
135
|
-
const entryPoint = 'userFunc.js';
|
|
136
|
-
return {
|
|
137
|
-
timestamp: Date.now(),
|
|
138
|
-
sourceHash,
|
|
139
|
-
imports: this.analyzeImports(result),
|
|
140
|
-
entryPoint,
|
|
141
|
-
asset: result.outputFiles![0].contents,
|
|
142
|
-
bundle: result.outputFiles![0].text,
|
|
143
|
-
};
|
|
144
|
-
} catch (err) {
|
|
145
|
-
return { timestamp: Date.now(), sourceHash, error: err };
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
// TODO(dmaretskyi): In the future we can replace the compiler with SWC with plugins running in WASM.
|
|
150
|
-
analyzeImports(result: BuildResult): Import[] {
|
|
151
|
-
invariant(result.outputFiles);
|
|
152
|
-
|
|
153
|
-
// TODO(dmaretskyi): Support import aliases and wildcard imports.
|
|
154
|
-
const parsedImports = allMatches(IMPORT_REGEX, result.outputFiles[0].text);
|
|
155
|
-
return Object.values(result.metafile!.outputs)[0].imports.map((entry): Import => {
|
|
156
|
-
const namedImports: string[] = [];
|
|
157
|
-
const parsedImport = parsedImports.find((capture) => capture?.[4] === entry.path);
|
|
158
|
-
if (parsedImport?.[2]) {
|
|
159
|
-
NAMED_IMPORTS_REGEX.lastIndex = 0;
|
|
160
|
-
const namedImportsMatch = NAMED_IMPORTS_REGEX.exec(parsedImport[2]);
|
|
161
|
-
if (namedImportsMatch) {
|
|
162
|
-
namedImportsMatch[1].split(',').forEach((importName) => {
|
|
163
|
-
namedImports.push(importName.trim());
|
|
164
|
-
});
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
return {
|
|
169
|
-
moduleUrl: entry.path,
|
|
170
|
-
defaultImport: !!parsedImport?.[1],
|
|
171
|
-
namedImports,
|
|
172
|
-
};
|
|
173
|
-
});
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
analyzeSourceFileImports(code: string): {
|
|
177
|
-
defaultImportName: string;
|
|
178
|
-
namedImports: string[];
|
|
179
|
-
wildcardImportName: string;
|
|
180
|
-
moduleIdentifier: string;
|
|
181
|
-
quotes: string;
|
|
182
|
-
}[] {
|
|
183
|
-
// TODO(dmaretskyi): Support import aliases and wildcard imports.
|
|
184
|
-
const parsedImports = allMatches(IMPORT_REGEX, code);
|
|
185
|
-
return parsedImports.map((capture) => {
|
|
186
|
-
return {
|
|
187
|
-
defaultImportName: capture[1],
|
|
188
|
-
namedImports: capture[2]?.split(',').map((importName) => importName.trim()),
|
|
189
|
-
wildcardImportName: capture[3],
|
|
190
|
-
moduleIdentifier: capture[4],
|
|
191
|
-
quotes: capture[5],
|
|
192
|
-
};
|
|
193
|
-
});
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
// https://regex101.com/r/FEN5ks/1
|
|
198
|
-
// https://stackoverflow.com/a/73265022
|
|
199
|
-
// $1 = default import name (can be non-existent)
|
|
200
|
-
// $2 = destructured exports (can be non-existent)
|
|
201
|
-
// $3 = wildcard import name (can be non-existent)
|
|
202
|
-
// $4 = module identifier
|
|
203
|
-
// $5 = quotes used (either ' or ")
|
|
204
|
-
const IMPORT_REGEX =
|
|
205
|
-
/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;
|
|
206
|
-
|
|
207
|
-
const NAMED_IMPORTS_REGEX = /[ \n\t]*{((?:[ \n\t]*[^ \n\t"'{}]+[ \n\t]*,?)+)}[ \n\t]*/gm;
|
|
208
|
-
|
|
209
|
-
const allMatches = (regex: RegExp, str: string) => {
|
|
210
|
-
let match;
|
|
211
|
-
const matches = [];
|
|
212
|
-
regex.lastIndex = 0;
|
|
213
|
-
while ((match = regex.exec(str))) {
|
|
214
|
-
matches.push(match);
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
return matches;
|
|
218
|
-
};
|
|
219
|
-
|
|
220
|
-
type ParsedImport = {
|
|
221
|
-
defaultImportName?: string;
|
|
222
|
-
namedImports: string[];
|
|
223
|
-
wildcardImportName?: string;
|
|
224
|
-
moduleIdentifier: string;
|
|
225
|
-
quotes: string;
|
|
226
|
-
};
|
|
227
|
-
|
|
228
|
-
const analyzeSourceFileImports = (code: string): ParsedImport[] => {
|
|
229
|
-
// TODO(dmaretskyi): Support import aliases and wildcard imports.
|
|
230
|
-
const parsedImports = allMatches(IMPORT_REGEX, code);
|
|
231
|
-
return parsedImports.map((capture) => {
|
|
232
|
-
return {
|
|
233
|
-
defaultImportName: capture[1],
|
|
234
|
-
namedImports: capture[2]
|
|
235
|
-
?.trim()
|
|
236
|
-
.slice(1, -1)
|
|
237
|
-
.split(',')
|
|
238
|
-
.map((importName) => importName.trim()),
|
|
239
|
-
wildcardImportName: capture[3],
|
|
240
|
-
moduleIdentifier: capture[4],
|
|
241
|
-
quotes: capture[5],
|
|
242
|
-
};
|
|
243
|
-
});
|
|
244
|
-
};
|
|
245
|
-
|
|
246
|
-
const MAX_RETRIES = 5;
|
|
247
|
-
const INITIAL_DELAY = 1_000;
|
|
248
|
-
|
|
249
|
-
const httpPlugin: Plugin = {
|
|
250
|
-
name: 'http',
|
|
251
|
-
setup: (build) => {
|
|
252
|
-
// Intercept import paths starting with "http:" and "https:" so esbuild doesn't attempt to map them to a file system location.
|
|
253
|
-
// Tag them with the "http-url" namespace to associate them with this plugin.
|
|
254
|
-
build.onResolve({ filter: /^https?:\/\// }, (args) => ({
|
|
255
|
-
path: args.path,
|
|
256
|
-
namespace: 'http-url',
|
|
257
|
-
}));
|
|
258
|
-
|
|
259
|
-
// We also want to intercept all import paths inside downloaded files and resolve them against the original URL.
|
|
260
|
-
// All of these files will be in the "http-url" namespace.
|
|
261
|
-
// Make sure to keep the newly resolved URL in the "http-url" namespace so imports inside it will also be resolved as URLs recursively.
|
|
262
|
-
build.onResolve({ filter: /.*/, namespace: 'http-url' }, (args) => ({
|
|
263
|
-
path: new URL(args.path, args.importer).toString(),
|
|
264
|
-
namespace: 'http-url',
|
|
265
|
-
}));
|
|
266
|
-
|
|
267
|
-
// When a URL is loaded, we want to actually download the content from the internet.
|
|
268
|
-
// 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.
|
|
269
|
-
build.onLoad({ filter: /.*/, namespace: 'http-url' }, async (args) => {
|
|
270
|
-
return Effect.gen(function* () {
|
|
271
|
-
const response = yield* HttpClient.get(args.path);
|
|
272
|
-
if (response.status !== 200) {
|
|
273
|
-
throw new Error(`failed to fetch: ${response.status}`);
|
|
274
|
-
}
|
|
275
|
-
|
|
276
|
-
const text = yield* response.text;
|
|
277
|
-
return { contents: text, loader: 'jsx' as Loader };
|
|
278
|
-
}).pipe(
|
|
279
|
-
Effect.retry(
|
|
280
|
-
pipe(
|
|
281
|
-
Schedule.exponential(Duration.millis(INITIAL_DELAY)),
|
|
282
|
-
Schedule.jittered,
|
|
283
|
-
Schedule.intersect(Schedule.recurs(MAX_RETRIES - 1)),
|
|
284
|
-
),
|
|
285
|
-
),
|
|
286
|
-
Effect.provide(FetchHttpClient.layer),
|
|
287
|
-
runAndForwardErrors,
|
|
288
|
-
);
|
|
289
|
-
});
|
|
290
|
-
},
|
|
291
|
-
};
|