@dxos/functions 0.8.4-main.e098934 → 0.8.4-main.e8ec1fe
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 +714 -1062
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node-esm/index.mjs +714 -1062
- 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 +28 -36
- 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 +4 -8
- 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 +3 -1
- package/dist/types/src/services/queues.d.ts.map +1 -1
- package/dist/types/src/services/tracing.d.ts +9 -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 +16 -70
- 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 +4 -8
- 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 +3 -1
- package/src/services/tracing.ts +24 -56
- 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 -265
- package/dist/lib/browser/bundler/index.mjs.map +0 -7
- package/dist/lib/browser/chunk-D2XO7XXY.mjs +0 -611
- package/dist/lib/browser/chunk-D2XO7XXY.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/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-Z4CJ62WS.mjs +0 -613
- package/dist/lib/node-esm/chunk-Z4CJ62WS.mjs.map +0 -7
- package/dist/lib/node-esm/edge/index.mjs +0 -84
- package/dist/lib/node-esm/edge/index.mjs.map +0 -7
- package/dist/lib/node-esm/testing/index.mjs +0 -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/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.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 -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 -63
- package/dist/types/src/services/database.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.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/examples/index.ts +0 -7
- package/src/executor/executor.ts +0 -54
- package/src/handler.ts +0 -201
- package/src/services/database.ts +0 -171
- 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
package/src/types.ts
DELETED
|
@@ -1,200 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright 2023 DXOS.org
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
import { Schema, SchemaAST } from 'effect';
|
|
6
|
-
|
|
7
|
-
import { QueryAST, Type } from '@dxos/echo';
|
|
8
|
-
import { Expando, OptionsAnnotationId, RawObject, Ref } from '@dxos/echo-schema';
|
|
9
|
-
import { DXN } from '@dxos/keys';
|
|
10
|
-
|
|
11
|
-
import { FunctionType } from './schema';
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Type discriminator for TriggerType.
|
|
15
|
-
* Every spec has a type field of type TriggerKind that we can use to understand which type we're working with.
|
|
16
|
-
* https://www.typescriptlang.org/docs/handbook/2/narrowing.html#discriminated-unions
|
|
17
|
-
*/
|
|
18
|
-
export const TriggerKinds = ['timer', 'webhook', 'subscription', 'email', 'queue'] as const;
|
|
19
|
-
export type TriggerKind = (typeof TriggerKinds)[number];
|
|
20
|
-
|
|
21
|
-
const kindLiteralAnnotations = { title: 'Kind' };
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* Cron timer.
|
|
25
|
-
*/
|
|
26
|
-
const TimerTriggerSchema = Schema.Struct({
|
|
27
|
-
kind: Schema.Literal('timer').annotations(kindLiteralAnnotations),
|
|
28
|
-
cron: Schema.String.annotations({
|
|
29
|
-
title: 'Cron',
|
|
30
|
-
[SchemaAST.ExamplesAnnotationId]: ['0 0 * * *'],
|
|
31
|
-
}),
|
|
32
|
-
}).pipe(Schema.mutable);
|
|
33
|
-
export type TimerTrigger = Schema.Schema.Type<typeof TimerTriggerSchema>;
|
|
34
|
-
|
|
35
|
-
const EmailTriggerSchema = Schema.Struct({
|
|
36
|
-
kind: Schema.Literal('email').annotations(kindLiteralAnnotations),
|
|
37
|
-
}).pipe(Schema.mutable);
|
|
38
|
-
export type EmailTrigger = Schema.Schema.Type<typeof EmailTriggerSchema>;
|
|
39
|
-
|
|
40
|
-
const QueueTriggerSchema = Schema.Struct({
|
|
41
|
-
kind: Schema.Literal('queue').annotations(kindLiteralAnnotations),
|
|
42
|
-
|
|
43
|
-
// TODO(dmaretskyi): Change to a reference.
|
|
44
|
-
queue: DXN.Schema,
|
|
45
|
-
}).pipe(Schema.mutable);
|
|
46
|
-
export type QueueTrigger = Schema.Schema.Type<typeof QueueTriggerSchema>;
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
* Webhook.
|
|
50
|
-
*/
|
|
51
|
-
const WebhookTriggerSchema = Schema.Struct({
|
|
52
|
-
kind: Schema.Literal('webhook').annotations(kindLiteralAnnotations),
|
|
53
|
-
method: Schema.optional(
|
|
54
|
-
Schema.String.annotations({
|
|
55
|
-
title: 'Method',
|
|
56
|
-
[OptionsAnnotationId]: ['GET', 'POST'],
|
|
57
|
-
}),
|
|
58
|
-
),
|
|
59
|
-
port: Schema.optional(
|
|
60
|
-
Schema.Number.annotations({
|
|
61
|
-
title: 'Port',
|
|
62
|
-
}),
|
|
63
|
-
),
|
|
64
|
-
}).pipe(Schema.mutable);
|
|
65
|
-
export type WebhookTrigger = Schema.Schema.Type<typeof WebhookTriggerSchema>;
|
|
66
|
-
|
|
67
|
-
/**
|
|
68
|
-
* Subscription.
|
|
69
|
-
*/
|
|
70
|
-
const SubscriptionTriggerSchema = Schema.Struct({
|
|
71
|
-
kind: Schema.Literal('subscription').annotations(kindLiteralAnnotations),
|
|
72
|
-
query: QueryAST.Query.annotations({ title: 'Query' }),
|
|
73
|
-
options: Schema.optional(
|
|
74
|
-
Schema.Struct({
|
|
75
|
-
// Watch changes to object (not just creation).
|
|
76
|
-
deep: Schema.optional(Schema.Boolean.annotations({ title: 'Nested' })),
|
|
77
|
-
// Debounce changes (delay in ms).
|
|
78
|
-
delay: Schema.optional(Schema.Number.annotations({ title: 'Delay' })),
|
|
79
|
-
}).annotations({ title: 'Options' }),
|
|
80
|
-
),
|
|
81
|
-
}).pipe(Schema.mutable);
|
|
82
|
-
export type SubscriptionTrigger = Schema.Schema.Type<typeof SubscriptionTriggerSchema>;
|
|
83
|
-
|
|
84
|
-
/**
|
|
85
|
-
* Trigger schema (discriminated union).
|
|
86
|
-
*/
|
|
87
|
-
export const TriggerSchema = Schema.Union(
|
|
88
|
-
TimerTriggerSchema,
|
|
89
|
-
WebhookTriggerSchema,
|
|
90
|
-
SubscriptionTriggerSchema,
|
|
91
|
-
EmailTriggerSchema,
|
|
92
|
-
QueueTriggerSchema,
|
|
93
|
-
).annotations({
|
|
94
|
-
title: 'Trigger',
|
|
95
|
-
});
|
|
96
|
-
export type TriggerType = Schema.Schema.Type<typeof TriggerSchema>;
|
|
97
|
-
|
|
98
|
-
export type EventType =
|
|
99
|
-
| EmailTriggerOutput
|
|
100
|
-
| WebhookTriggerOutput
|
|
101
|
-
| QueueTriggerOutput
|
|
102
|
-
| SubscriptionTriggerOutput
|
|
103
|
-
| TimerTriggerOutput;
|
|
104
|
-
|
|
105
|
-
// TODO(burdon): Reuse trigger schema from @dxos/functions (TriggerType).
|
|
106
|
-
export const EmailTriggerOutput = Schema.mutable(
|
|
107
|
-
Schema.Struct({
|
|
108
|
-
from: Schema.String,
|
|
109
|
-
to: Schema.String,
|
|
110
|
-
subject: Schema.String,
|
|
111
|
-
created: Schema.String,
|
|
112
|
-
body: Schema.String,
|
|
113
|
-
}),
|
|
114
|
-
);
|
|
115
|
-
export type EmailTriggerOutput = Schema.Schema.Type<typeof EmailTriggerOutput>;
|
|
116
|
-
|
|
117
|
-
export const WebhookTriggerOutput = Schema.mutable(
|
|
118
|
-
Schema.Struct({
|
|
119
|
-
url: Schema.String,
|
|
120
|
-
method: Schema.Literal('GET', 'POST'),
|
|
121
|
-
headers: Schema.Record({ key: Schema.String, value: Schema.String }),
|
|
122
|
-
bodyText: Schema.String,
|
|
123
|
-
}),
|
|
124
|
-
);
|
|
125
|
-
export type WebhookTriggerOutput = Schema.Schema.Type<typeof WebhookTriggerOutput>;
|
|
126
|
-
|
|
127
|
-
export const QueueTriggerOutput = Schema.mutable(
|
|
128
|
-
Schema.Struct({
|
|
129
|
-
queue: DXN.Schema,
|
|
130
|
-
item: Schema.Any,
|
|
131
|
-
cursor: Schema.String,
|
|
132
|
-
}),
|
|
133
|
-
);
|
|
134
|
-
export type QueueTriggerOutput = Schema.Schema.Type<typeof QueueTriggerOutput>;
|
|
135
|
-
|
|
136
|
-
export const SubscriptionTriggerOutput = Schema.mutable(
|
|
137
|
-
Schema.Struct({ type: Schema.String, changedObjectId: Schema.String }),
|
|
138
|
-
);
|
|
139
|
-
export type SubscriptionTriggerOutput = Schema.Schema.Type<typeof SubscriptionTriggerOutput>;
|
|
140
|
-
|
|
141
|
-
export const TimerTriggerOutput = Schema.mutable(Schema.Struct({ tick: Schema.Number }));
|
|
142
|
-
export type TimerTriggerOutput = Schema.Schema.Type<typeof TimerTriggerOutput>;
|
|
143
|
-
|
|
144
|
-
/**
|
|
145
|
-
* Function trigger.
|
|
146
|
-
* Function is invoked with the `payload` passed as input data.
|
|
147
|
-
* The event that triggers the function is available in the function context.
|
|
148
|
-
*/
|
|
149
|
-
const FunctionTrigger_ = Schema.Struct({
|
|
150
|
-
/**
|
|
151
|
-
* Function or workflow to invoke.
|
|
152
|
-
*/
|
|
153
|
-
// TODO(dmaretskyi): Can be a Ref(FunctionType) or Ref(ComputeGraphType).
|
|
154
|
-
function: Schema.optional(Ref(Expando).annotations({ title: 'Function' })),
|
|
155
|
-
|
|
156
|
-
/**
|
|
157
|
-
* Only used for workflowSchema.
|
|
158
|
-
* Specifies the input node in the circuit.
|
|
159
|
-
* @deprecated Remove and enforce a single input node in all compute graphSchema.
|
|
160
|
-
*/
|
|
161
|
-
inputNodeId: Schema.optional(Schema.String.annotations({ title: 'Input Node ID' })),
|
|
162
|
-
|
|
163
|
-
enabled: Schema.optional(Schema.Boolean.annotations({ title: 'Enabled' })),
|
|
164
|
-
|
|
165
|
-
spec: Schema.optional(TriggerSchema),
|
|
166
|
-
|
|
167
|
-
/**
|
|
168
|
-
* Passed as the input data to the function.
|
|
169
|
-
* Must match the function's input schema.
|
|
170
|
-
*
|
|
171
|
-
* @example
|
|
172
|
-
* {
|
|
173
|
-
* item: '{{$.trigger.event}}',
|
|
174
|
-
* instructions: 'Summarize and perform entity-extraction'
|
|
175
|
-
* mailbox: { '/': 'dxn:echo:AAA:ZZZ' }
|
|
176
|
-
* }
|
|
177
|
-
*/
|
|
178
|
-
input: Schema.optional(Schema.mutable(Schema.Record({ key: Schema.String, value: Schema.Any }))),
|
|
179
|
-
}).pipe(
|
|
180
|
-
Type.Obj({
|
|
181
|
-
typename: 'dxos.org/type/FunctionTrigger',
|
|
182
|
-
version: '0.2.0',
|
|
183
|
-
}),
|
|
184
|
-
);
|
|
185
|
-
export interface FunctionTrigger extends Schema.Schema.Type<typeof FunctionTrigger_> {}
|
|
186
|
-
export interface FunctionTriggerEncoded extends Schema.Schema.Encoded<typeof FunctionTrigger_> {}
|
|
187
|
-
export const FunctionTrigger: Schema.Schema<FunctionTrigger, FunctionTriggerEncoded> = FunctionTrigger_;
|
|
188
|
-
|
|
189
|
-
// TODO(wittjosiah): Remove?
|
|
190
|
-
|
|
191
|
-
/**
|
|
192
|
-
* Function manifest file.
|
|
193
|
-
*/
|
|
194
|
-
export const FunctionManifestSchema = Schema.Struct({
|
|
195
|
-
functions: Schema.optional(Schema.mutable(Schema.Array(RawObject(FunctionType)))),
|
|
196
|
-
triggers: Schema.optional(Schema.mutable(Schema.Array(RawObject(FunctionTrigger)))),
|
|
197
|
-
});
|
|
198
|
-
export type FunctionManifest = Schema.Schema.Type<typeof FunctionManifestSchema>;
|
|
199
|
-
|
|
200
|
-
export const FUNCTION_TYPES = [FunctionType, FunctionTrigger];
|
package/src/url.ts
DELETED
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright 2025 DXOS.org
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
import { type ObjectMeta } from '@dxos/echo-schema';
|
|
6
|
-
import { type SpaceId } from '@dxos/keys';
|
|
7
|
-
|
|
8
|
-
// TODO: use URL scheme for source?
|
|
9
|
-
export const FUNCTIONS_META_KEY = 'dxos.org/service/function';
|
|
10
|
-
|
|
11
|
-
export const FUNCTIONS_PRESET_META_KEY = 'dxos.org/service/function-preset';
|
|
12
|
-
|
|
13
|
-
const isSecure = (protocol: string) => {
|
|
14
|
-
return protocol === 'https:' || protocol === 'wss:';
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* NOTE: functionId is backend ID, not ECHO object id.
|
|
19
|
-
*/
|
|
20
|
-
export const getUserFunctionIdInMetadata = (meta: ObjectMeta) => {
|
|
21
|
-
return meta.keys.find((key) => key.source === FUNCTIONS_META_KEY)?.id;
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* NOTE: functionId is backend ID, not ECHO object id.
|
|
26
|
-
*/
|
|
27
|
-
export const setUserFunctionIdInMetadata = (meta: ObjectMeta, functionId: string) => {
|
|
28
|
-
const key = meta.keys.find((key) => key.source === FUNCTIONS_META_KEY);
|
|
29
|
-
if (key) {
|
|
30
|
-
if (key.id !== functionId) {
|
|
31
|
-
throw new Error('Metadata mismatch');
|
|
32
|
-
}
|
|
33
|
-
} else {
|
|
34
|
-
meta.keys.push({ source: FUNCTIONS_META_KEY, id: functionId });
|
|
35
|
-
}
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* NOTE: functionId is backend ID, not ECHO object id.
|
|
40
|
-
*/
|
|
41
|
-
export const getInvocationUrl = (functionId: string, edgeUrl: string, options: InvocationOptions = {}) => {
|
|
42
|
-
const baseUrl = new URL('functions/', edgeUrl);
|
|
43
|
-
|
|
44
|
-
// Leading slashes cause the URL to be treated as an absolute path.
|
|
45
|
-
const url = new URL(`./${functionId}`, baseUrl.toString());
|
|
46
|
-
options.spaceId && url.searchParams.set('spaceId', options.spaceId);
|
|
47
|
-
options.subjectId && url.searchParams.set('subjectId', options.subjectId);
|
|
48
|
-
url.protocol = isSecure(url.protocol) ? 'https' : 'http';
|
|
49
|
-
return url.toString();
|
|
50
|
-
};
|
|
51
|
-
|
|
52
|
-
export type InvocationOptions = {
|
|
53
|
-
spaceId?: SpaceId;
|
|
54
|
-
subjectId?: string;
|
|
55
|
-
};
|