@dxos/functions 0.8.4-main.dedc0f3 → 0.8.4-main.dfabb4ec29
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/README.md +4 -6
- package/dist/lib/neutral/index.mjs +593 -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 +3 -9
- 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 +19 -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 +22 -39
- package/dist/types/src/services/credentials.d.ts.map +1 -1
- package/dist/types/src/services/function-invocation-service.d.ts +15 -0
- package/dist/types/src/services/function-invocation-service.d.ts.map +1 -0
- package/dist/types/src/services/index.d.ts +3 -7
- package/dist/types/src/services/index.d.ts.map +1 -1
- package/dist/types/src/services/queues.d.ts +1 -44
- package/dist/types/src/services/queues.d.ts.map +1 -1
- package/dist/types/src/services/tracing.d.ts +2 -54
- package/dist/types/src/services/tracing.d.ts.map +1 -1
- package/dist/types/src/types/index.d.ts +2 -0
- package/dist/types/src/types/index.d.ts.map +1 -0
- 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 +25 -72
- package/src/index.ts +3 -9
- 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 +428 -0
- package/src/sdk.ts +31 -0
- package/src/services/credentials.ts +90 -111
- package/src/services/function-invocation-service.ts +33 -0
- package/src/services/index.ts +3 -7
- package/src/services/queues.ts +1 -78
- package/src/services/tracing.ts +1 -133
- package/src/types/index.ts +5 -0
- package/src/types/url.ts +32 -0
- package/dist/lib/browser/bundler/index.mjs +0 -265
- package/dist/lib/browser/bundler/index.mjs.map +0 -7
- package/dist/lib/browser/chunk-ANP3DFCO.mjs +0 -623
- package/dist/lib/browser/chunk-ANP3DFCO.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/edge/index.mjs +0 -83
- package/dist/lib/browser/edge/index.mjs.map +0 -7
- package/dist/lib/browser/index.mjs +0 -1265
- 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 -129
- package/dist/lib/browser/testing/index.mjs.map +0 -7
- package/dist/lib/node-esm/bundler/index.mjs +0 -266
- 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-MPKVY7ZR.mjs +0 -625
- package/dist/lib/node-esm/chunk-MPKVY7ZR.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 -1266
- 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 -130
- 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/errors.d.ts +0 -137
- package/dist/types/src/errors.d.ts.map +0 -1
- package/dist/types/src/examples/fib.d.ts +0 -7
- package/dist/types/src/examples/fib.d.ts.map +0 -1
- package/dist/types/src/examples/index.d.ts +0 -4
- package/dist/types/src/examples/index.d.ts.map +0 -1
- package/dist/types/src/examples/reply.d.ts +0 -3
- package/dist/types/src/examples/reply.d.ts.map +0 -1
- package/dist/types/src/examples/sleep.d.ts +0 -5
- 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 -94
- 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/event-logger.d.ts +0 -72
- package/dist/types/src/services/event-logger.d.ts.map +0 -1
- package/dist/types/src/services/local-function-execution.d.ts +0 -25
- 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 -15
- 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 -35
- package/dist/types/src/triggers/invocation-tracer.d.ts.map +0 -1
- package/dist/types/src/triggers/trigger-dispatcher.d.ts +0 -75
- 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 -27
- package/dist/types/src/triggers/trigger-state-store.d.ts.map +0 -1
- package/dist/types/src/types.d.ts +0 -211
- package/dist/types/src/types.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 -291
- package/src/bundler/index.ts +0 -5
- package/src/edge/functions.ts +0 -67
- package/src/edge/index.ts +0 -9
- package/src/errors.ts +0 -21
- package/src/examples/fib.ts +0 -30
- package/src/examples/index.ts +0 -7
- package/src/examples/reply.ts +0 -18
- package/src/examples/sleep.ts +0 -22
- package/src/executor/executor.ts +0 -54
- package/src/handler.ts +0 -201
- package/src/schema.ts +0 -68
- package/src/services/database.ts +0 -170
- package/src/services/event-logger.ts +0 -118
- package/src/services/local-function-execution.ts +0 -114
- 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 -111
- 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/triggers/index.ts +0 -7
- package/src/triggers/input-builder.ts +0 -35
- package/src/triggers/invocation-tracer.ts +0 -99
- package/src/triggers/trigger-dispatcher.test.ts +0 -652
- package/src/triggers/trigger-dispatcher.ts +0 -512
- package/src/triggers/trigger-state-store.ts +0 -60
- package/src/types.ts +0 -200
- package/src/url.ts +0 -55
|
@@ -1,211 +0,0 @@
|
|
|
1
|
-
import { Schema } from 'effect';
|
|
2
|
-
import { QueryAST, 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
|
-
query: 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>;
|
|
43
|
-
options: Schema.optional<Schema.Struct<{
|
|
44
|
-
deep: Schema.optional<Schema.SchemaClass<boolean, boolean, never>>;
|
|
45
|
-
delay: Schema.optional<Schema.SchemaClass<number, number, never>>;
|
|
46
|
-
}>>;
|
|
47
|
-
}>>;
|
|
48
|
-
export type SubscriptionTrigger = Schema.Schema.Type<typeof SubscriptionTriggerSchema>;
|
|
49
|
-
/**
|
|
50
|
-
* Trigger schema (discriminated union).
|
|
51
|
-
*/
|
|
52
|
-
export declare const TriggerSchema: Schema.Union<[Schema.mutable<Schema.Struct<{
|
|
53
|
-
kind: Schema.Literal<["timer"]>;
|
|
54
|
-
cron: Schema.SchemaClass<string, string, never>;
|
|
55
|
-
}>>, Schema.mutable<Schema.Struct<{
|
|
56
|
-
kind: Schema.Literal<["webhook"]>;
|
|
57
|
-
method: Schema.optional<Schema.SchemaClass<string, string, never>>;
|
|
58
|
-
port: Schema.optional<Schema.SchemaClass<number, number, never>>;
|
|
59
|
-
}>>, Schema.mutable<Schema.Struct<{
|
|
60
|
-
kind: Schema.Literal<["subscription"]>;
|
|
61
|
-
query: 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>;
|
|
62
|
-
options: Schema.optional<Schema.Struct<{
|
|
63
|
-
deep: Schema.optional<Schema.SchemaClass<boolean, boolean, never>>;
|
|
64
|
-
delay: Schema.optional<Schema.SchemaClass<number, number, never>>;
|
|
65
|
-
}>>;
|
|
66
|
-
}>>, Schema.mutable<Schema.Struct<{
|
|
67
|
-
kind: Schema.Literal<["email"]>;
|
|
68
|
-
}>>, Schema.mutable<Schema.Struct<{
|
|
69
|
-
kind: Schema.Literal<["queue"]>;
|
|
70
|
-
queue: Schema.refine<string, typeof Schema.NonEmptyString>;
|
|
71
|
-
}>>]>;
|
|
72
|
-
export type TriggerType = Schema.Schema.Type<typeof TriggerSchema>;
|
|
73
|
-
export type EventType = EmailTriggerOutput | WebhookTriggerOutput | QueueTriggerOutput | SubscriptionTriggerOutput | TimerTriggerOutput;
|
|
74
|
-
export declare const EmailTriggerOutput: Schema.mutable<Schema.Struct<{
|
|
75
|
-
from: typeof Schema.String;
|
|
76
|
-
to: typeof Schema.String;
|
|
77
|
-
subject: typeof Schema.String;
|
|
78
|
-
created: typeof Schema.String;
|
|
79
|
-
body: typeof Schema.String;
|
|
80
|
-
}>>;
|
|
81
|
-
export type EmailTriggerOutput = Schema.Schema.Type<typeof EmailTriggerOutput>;
|
|
82
|
-
export declare const WebhookTriggerOutput: Schema.mutable<Schema.Struct<{
|
|
83
|
-
url: typeof Schema.String;
|
|
84
|
-
method: Schema.Literal<["GET", "POST"]>;
|
|
85
|
-
headers: Schema.Record$<typeof Schema.String, typeof Schema.String>;
|
|
86
|
-
bodyText: typeof Schema.String;
|
|
87
|
-
}>>;
|
|
88
|
-
export type WebhookTriggerOutput = Schema.Schema.Type<typeof WebhookTriggerOutput>;
|
|
89
|
-
export declare const QueueTriggerOutput: Schema.mutable<Schema.Struct<{
|
|
90
|
-
queue: Schema.refine<string, typeof Schema.NonEmptyString>;
|
|
91
|
-
item: typeof Schema.Any;
|
|
92
|
-
cursor: typeof Schema.String;
|
|
93
|
-
}>>;
|
|
94
|
-
export type QueueTriggerOutput = Schema.Schema.Type<typeof QueueTriggerOutput>;
|
|
95
|
-
export declare const SubscriptionTriggerOutput: Schema.mutable<Schema.Struct<{
|
|
96
|
-
type: typeof Schema.String;
|
|
97
|
-
changedObjectId: typeof Schema.String;
|
|
98
|
-
}>>;
|
|
99
|
-
export type SubscriptionTriggerOutput = Schema.Schema.Type<typeof SubscriptionTriggerOutput>;
|
|
100
|
-
export declare const TimerTriggerOutput: Schema.mutable<Schema.Struct<{
|
|
101
|
-
tick: typeof Schema.Number;
|
|
102
|
-
}>>;
|
|
103
|
-
export type TimerTriggerOutput = Schema.Schema.Type<typeof TimerTriggerOutput>;
|
|
104
|
-
/**
|
|
105
|
-
* Function trigger.
|
|
106
|
-
* Function is invoked with the `payload` passed as input data.
|
|
107
|
-
* The event that triggers the function is available in the function context.
|
|
108
|
-
*/
|
|
109
|
-
declare const FunctionTrigger_: Type.obj<Schema.Struct<{
|
|
110
|
-
/**
|
|
111
|
-
* Function or workflow to invoke.
|
|
112
|
-
*/
|
|
113
|
-
function: Schema.optional<Schema.SchemaClass<Ref<Expando>, import("@dxos/echo-protocol").EncodedReference, never>>;
|
|
114
|
-
/**
|
|
115
|
-
* Only used for workflowSchema.
|
|
116
|
-
* Specifies the input node in the circuit.
|
|
117
|
-
* @deprecated Remove and enforce a single input node in all compute graphSchema.
|
|
118
|
-
*/
|
|
119
|
-
inputNodeId: Schema.optional<Schema.SchemaClass<string, string, never>>;
|
|
120
|
-
enabled: Schema.optional<Schema.SchemaClass<boolean, boolean, never>>;
|
|
121
|
-
spec: Schema.optional<Schema.Union<[Schema.mutable<Schema.Struct<{
|
|
122
|
-
kind: Schema.Literal<["timer"]>;
|
|
123
|
-
cron: Schema.SchemaClass<string, string, never>;
|
|
124
|
-
}>>, Schema.mutable<Schema.Struct<{
|
|
125
|
-
kind: Schema.Literal<["webhook"]>;
|
|
126
|
-
method: Schema.optional<Schema.SchemaClass<string, string, never>>;
|
|
127
|
-
port: Schema.optional<Schema.SchemaClass<number, number, never>>;
|
|
128
|
-
}>>, Schema.mutable<Schema.Struct<{
|
|
129
|
-
kind: Schema.Literal<["subscription"]>;
|
|
130
|
-
query: 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>;
|
|
131
|
-
options: Schema.optional<Schema.Struct<{
|
|
132
|
-
deep: Schema.optional<Schema.SchemaClass<boolean, boolean, never>>;
|
|
133
|
-
delay: Schema.optional<Schema.SchemaClass<number, number, never>>;
|
|
134
|
-
}>>;
|
|
135
|
-
}>>, Schema.mutable<Schema.Struct<{
|
|
136
|
-
kind: Schema.Literal<["email"]>;
|
|
137
|
-
}>>, Schema.mutable<Schema.Struct<{
|
|
138
|
-
kind: Schema.Literal<["queue"]>;
|
|
139
|
-
queue: Schema.refine<string, typeof Schema.NonEmptyString>;
|
|
140
|
-
}>>]>>;
|
|
141
|
-
/**
|
|
142
|
-
* Passed as the input data to the function.
|
|
143
|
-
* Must match the function's input schema.
|
|
144
|
-
*
|
|
145
|
-
* @example
|
|
146
|
-
* {
|
|
147
|
-
* item: '{{$.trigger.event}}',
|
|
148
|
-
* instructions: 'Summarize and perform entity-extraction'
|
|
149
|
-
* mailbox: { '/': 'dxn:echo:AAA:ZZZ' }
|
|
150
|
-
* }
|
|
151
|
-
*/
|
|
152
|
-
input: Schema.optional<Schema.mutable<Schema.Record$<typeof Schema.String, typeof Schema.Any>>>;
|
|
153
|
-
}>>;
|
|
154
|
-
export interface FunctionTrigger extends Schema.Schema.Type<typeof FunctionTrigger_> {
|
|
155
|
-
}
|
|
156
|
-
export interface FunctionTriggerEncoded extends Schema.Schema.Encoded<typeof FunctionTrigger_> {
|
|
157
|
-
}
|
|
158
|
-
export declare const FunctionTrigger: Schema.Schema<FunctionTrigger, FunctionTriggerEncoded>;
|
|
159
|
-
/**
|
|
160
|
-
* Function manifest file.
|
|
161
|
-
*/
|
|
162
|
-
export declare const FunctionManifestSchema: Schema.Struct<{
|
|
163
|
-
functions: Schema.optional<Schema.mutable<Schema.Array$<Schema.Schema<import("@dxos/echo-schema").ExcludeId<Type.OfKind<import("@dxos/echo-schema").EntityKind.Object> & {
|
|
164
|
-
name: string;
|
|
165
|
-
description?: string | undefined;
|
|
166
|
-
source?: Ref<Type.OfKind<import("@dxos/echo-schema").EntityKind.Object> & {
|
|
167
|
-
name?: string | undefined;
|
|
168
|
-
description?: string | undefined;
|
|
169
|
-
changed?: boolean | undefined;
|
|
170
|
-
source: Ref<Type.OfKind<import("@dxos/echo-schema").EntityKind.Object> & {
|
|
171
|
-
content: string;
|
|
172
|
-
}>;
|
|
173
|
-
}> | undefined;
|
|
174
|
-
version: string;
|
|
175
|
-
key?: string | undefined;
|
|
176
|
-
inputSchema?: Type.JsonSchema | undefined;
|
|
177
|
-
outputSchema?: Type.JsonSchema | undefined;
|
|
178
|
-
binding?: string | undefined;
|
|
179
|
-
}> & import("@dxos/echo-schema").WithMeta, {
|
|
180
|
-
id: string;
|
|
181
|
-
name: string;
|
|
182
|
-
version: string;
|
|
183
|
-
description?: string | undefined;
|
|
184
|
-
source?: import("@dxos/echo-protocol").EncodedReference | undefined;
|
|
185
|
-
key?: string | undefined;
|
|
186
|
-
inputSchema?: Type.JsonSchema | undefined;
|
|
187
|
-
outputSchema?: Type.JsonSchema | undefined;
|
|
188
|
-
binding?: string | undefined;
|
|
189
|
-
}, never>>>>;
|
|
190
|
-
triggers: Schema.optional<Schema.mutable<Schema.Array$<Schema.Schema<import("@dxos/echo-schema").ExcludeId<FunctionTrigger> & import("@dxos/echo-schema").WithMeta, FunctionTriggerEncoded, never>>>>;
|
|
191
|
-
}>;
|
|
192
|
-
export type FunctionManifest = Schema.Schema.Type<typeof FunctionManifestSchema>;
|
|
193
|
-
export declare const FUNCTION_TYPES: (Type.obj<Schema.Struct<{
|
|
194
|
-
key: Schema.optional<typeof Schema.String>;
|
|
195
|
-
name: typeof Schema.NonEmptyString;
|
|
196
|
-
version: typeof Schema.String;
|
|
197
|
-
description: Schema.optional<typeof Schema.String>;
|
|
198
|
-
source: Schema.optional<import("@dxos/echo-schema").Ref$<Type.OfKind<import("@dxos/echo-schema").EntityKind.Object> & {
|
|
199
|
-
name?: string | undefined;
|
|
200
|
-
description?: string | undefined;
|
|
201
|
-
changed?: boolean | undefined;
|
|
202
|
-
source: Ref<Type.OfKind<import("@dxos/echo-schema").EntityKind.Object> & {
|
|
203
|
-
content: string;
|
|
204
|
-
}>;
|
|
205
|
-
}>>;
|
|
206
|
-
inputSchema: Schema.optional<Schema.Schema<Type.JsonSchema, Type.JsonSchema, never>>;
|
|
207
|
-
outputSchema: Schema.optional<Schema.Schema<Type.JsonSchema, Type.JsonSchema, never>>;
|
|
208
|
-
binding: Schema.optional<typeof Schema.String>;
|
|
209
|
-
}>> | Schema.Schema<FunctionTrigger, FunctionTriggerEncoded, never>)[];
|
|
210
|
-
export {};
|
|
211
|
-
//# 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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"}
|
package/dist/types/src/url.d.ts
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { type ObjectMeta } from '@dxos/echo-schema';
|
|
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,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
|
-
};
|
package/src/bundler/index.ts
DELETED
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
|
-
};
|