@dxos/functions 0.8.4-main.ae835ea → 0.8.4-main.bc2380dfbc
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +102 -5
- package/README.md +5 -7
- package/dist/lib/neutral/index.mjs +599 -0
- package/dist/lib/neutral/index.mjs.map +7 -0
- package/dist/lib/neutral/meta.json +1 -0
- package/dist/types/src/index.d.ts +2 -7
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/protocol/functions-ai-http-client.d.ts +12 -0
- package/dist/types/src/protocol/functions-ai-http-client.d.ts.map +1 -0
- package/dist/types/src/protocol/functions-ai-http-client.test.d.ts +2 -0
- package/dist/types/src/protocol/functions-ai-http-client.test.d.ts.map +1 -0
- package/dist/types/src/protocol/index.d.ts +2 -0
- package/dist/types/src/protocol/index.d.ts.map +1 -0
- package/dist/types/src/protocol/protocol.d.ts +24 -0
- package/dist/types/src/protocol/protocol.d.ts.map +1 -0
- package/dist/types/src/protocol/protocol.test.d.ts +2 -0
- package/dist/types/src/protocol/protocol.test.d.ts.map +1 -0
- package/dist/types/src/sdk.d.ts +10 -0
- package/dist/types/src/sdk.d.ts.map +1 -0
- package/dist/types/src/services/credentials.d.ts +17 -38
- package/dist/types/src/services/credentials.d.ts.map +1 -1
- package/dist/types/src/services/function-invocation-service.d.ts +6 -19
- package/dist/types/src/services/function-invocation-service.d.ts.map +1 -1
- package/dist/types/src/services/index.d.ts +1 -6
- package/dist/types/src/services/index.d.ts.map +1 -1
- package/dist/types/src/services/queues.d.ts +1 -46
- package/dist/types/src/services/queues.d.ts.map +1 -1
- package/dist/types/src/services/tracing.d.ts +2 -56
- package/dist/types/src/services/tracing.d.ts.map +1 -1
- package/dist/types/src/types/index.d.ts +1 -4
- package/dist/types/src/types/index.d.ts.map +1 -1
- package/dist/types/src/types/url.d.ts +13 -0
- package/dist/types/src/types/url.d.ts.map +1 -0
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +26 -61
- package/src/index.ts +2 -7
- package/src/protocol/functions-ai-http-client.test.ts +105 -0
- package/src/protocol/functions-ai-http-client.ts +141 -0
- package/src/{executor → protocol}/index.ts +1 -1
- package/src/protocol/protocol.test.ts +58 -0
- package/src/protocol/protocol.ts +452 -0
- package/src/sdk.ts +31 -0
- package/src/services/credentials.ts +81 -110
- package/src/services/function-invocation-service.ts +19 -70
- package/src/services/index.ts +1 -6
- package/src/services/queues.ts +1 -80
- package/src/services/tracing.ts +1 -136
- package/src/types/index.ts +1 -4
- package/src/types/url.ts +32 -0
- package/dist/lib/browser/bundler/index.mjs +0 -256
- package/dist/lib/browser/bundler/index.mjs.map +0 -7
- package/dist/lib/browser/chunk-J5LGTIGS.mjs +0 -10
- package/dist/lib/browser/chunk-J5LGTIGS.mjs.map +0 -7
- package/dist/lib/browser/chunk-M6EXIREF.mjs +0 -610
- package/dist/lib/browser/chunk-M6EXIREF.mjs.map +0 -7
- package/dist/lib/browser/edge/index.mjs +0 -83
- package/dist/lib/browser/edge/index.mjs.map +0 -7
- package/dist/lib/browser/index.mjs +0 -1346
- package/dist/lib/browser/index.mjs.map +0 -7
- package/dist/lib/browser/meta.json +0 -1
- package/dist/lib/browser/testing/index.mjs +0 -131
- package/dist/lib/browser/testing/index.mjs.map +0 -7
- package/dist/lib/node-esm/bundler/index.mjs +0 -257
- package/dist/lib/node-esm/bundler/index.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-HSLMI22Q.mjs +0 -11
- package/dist/lib/node-esm/chunk-HSLMI22Q.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-P3IATZMZ.mjs +0 -612
- package/dist/lib/node-esm/chunk-P3IATZMZ.mjs.map +0 -7
- package/dist/lib/node-esm/edge/index.mjs +0 -84
- package/dist/lib/node-esm/edge/index.mjs.map +0 -7
- package/dist/lib/node-esm/index.mjs +0 -1347
- package/dist/lib/node-esm/index.mjs.map +0 -7
- package/dist/lib/node-esm/meta.json +0 -1
- package/dist/lib/node-esm/testing/index.mjs +0 -132
- package/dist/lib/node-esm/testing/index.mjs.map +0 -7
- package/dist/types/src/bundler/bundler.d.ts +0 -49
- package/dist/types/src/bundler/bundler.d.ts.map +0 -1
- package/dist/types/src/bundler/bundler.test.d.ts +0 -2
- package/dist/types/src/bundler/bundler.test.d.ts.map +0 -1
- package/dist/types/src/bundler/index.d.ts +0 -2
- package/dist/types/src/bundler/index.d.ts.map +0 -1
- package/dist/types/src/e2e/deploy.test.d.ts +0 -2
- package/dist/types/src/e2e/deploy.test.d.ts.map +0 -1
- package/dist/types/src/edge/functions.d.ts +0 -17
- package/dist/types/src/edge/functions.d.ts.map +0 -1
- package/dist/types/src/edge/index.d.ts +0 -2
- package/dist/types/src/edge/index.d.ts.map +0 -1
- package/dist/types/src/errors.d.ts +0 -137
- package/dist/types/src/errors.d.ts.map +0 -1
- package/dist/types/src/example/fib.d.ts +0 -7
- package/dist/types/src/example/fib.d.ts.map +0 -1
- package/dist/types/src/example/forex-effect.d.ts +0 -3
- package/dist/types/src/example/forex-effect.d.ts.map +0 -1
- package/dist/types/src/example/index.d.ts +0 -12
- package/dist/types/src/example/index.d.ts.map +0 -1
- package/dist/types/src/example/reply.d.ts +0 -3
- package/dist/types/src/example/reply.d.ts.map +0 -1
- package/dist/types/src/example/sleep.d.ts +0 -5
- package/dist/types/src/example/sleep.d.ts.map +0 -1
- package/dist/types/src/executor/executor.d.ts +0 -14
- package/dist/types/src/executor/executor.d.ts.map +0 -1
- package/dist/types/src/executor/index.d.ts +0 -2
- package/dist/types/src/executor/index.d.ts.map +0 -1
- package/dist/types/src/handler.d.ts +0 -102
- package/dist/types/src/handler.d.ts.map +0 -1
- package/dist/types/src/services/database.d.ts +0 -67
- package/dist/types/src/services/database.d.ts.map +0 -1
- package/dist/types/src/services/event-logger.d.ts +0 -75
- package/dist/types/src/services/event-logger.d.ts.map +0 -1
- package/dist/types/src/services/function-invocation-service.test.d.ts +0 -2
- package/dist/types/src/services/function-invocation-service.test.d.ts.map +0 -1
- package/dist/types/src/services/local-function-execution.d.ts +0 -34
- package/dist/types/src/services/local-function-execution.d.ts.map +0 -1
- package/dist/types/src/services/remote-function-execution-service.d.ts +0 -22
- package/dist/types/src/services/remote-function-execution-service.d.ts.map +0 -1
- package/dist/types/src/services/service-container.d.ts +0 -57
- package/dist/types/src/services/service-container.d.ts.map +0 -1
- package/dist/types/src/services/service-registry.d.ts +0 -31
- package/dist/types/src/services/service-registry.d.ts.map +0 -1
- package/dist/types/src/services/service-registry.test.d.ts +0 -2
- package/dist/types/src/services/service-registry.test.d.ts.map +0 -1
- package/dist/types/src/testing/index.d.ts +0 -3
- package/dist/types/src/testing/index.d.ts.map +0 -1
- package/dist/types/src/testing/layer.d.ts +0 -18
- package/dist/types/src/testing/layer.d.ts.map +0 -1
- package/dist/types/src/testing/logger.d.ts +0 -5
- package/dist/types/src/testing/logger.d.ts.map +0 -1
- package/dist/types/src/testing/persist-database.test.d.ts +0 -2
- package/dist/types/src/testing/persist-database.test.d.ts.map +0 -1
- package/dist/types/src/testing/services.d.ts +0 -59
- package/dist/types/src/testing/services.d.ts.map +0 -1
- package/dist/types/src/trace.d.ts +0 -122
- package/dist/types/src/trace.d.ts.map +0 -1
- package/dist/types/src/translations.d.ts +0 -12
- package/dist/types/src/translations.d.ts.map +0 -1
- package/dist/types/src/triggers/index.d.ts +0 -4
- package/dist/types/src/triggers/index.d.ts.map +0 -1
- package/dist/types/src/triggers/input-builder.d.ts +0 -3
- package/dist/types/src/triggers/input-builder.d.ts.map +0 -1
- package/dist/types/src/triggers/invocation-tracer.d.ts +0 -37
- package/dist/types/src/triggers/invocation-tracer.d.ts.map +0 -1
- package/dist/types/src/triggers/trigger-dispatcher.d.ts +0 -78
- package/dist/types/src/triggers/trigger-dispatcher.d.ts.map +0 -1
- package/dist/types/src/triggers/trigger-dispatcher.test.d.ts +0 -2
- package/dist/types/src/triggers/trigger-dispatcher.test.d.ts.map +0 -1
- package/dist/types/src/triggers/trigger-state-store.d.ts +0 -28
- package/dist/types/src/triggers/trigger-state-store.d.ts.map +0 -1
- package/dist/types/src/types/Function.d.ts +0 -47
- package/dist/types/src/types/Function.d.ts.map +0 -1
- package/dist/types/src/types/Script.d.ts +0 -28
- package/dist/types/src/types/Script.d.ts.map +0 -1
- package/dist/types/src/types/Trigger.d.ts +0 -139
- package/dist/types/src/types/Trigger.d.ts.map +0 -1
- package/dist/types/src/types/TriggerEvent.d.ts +0 -44
- package/dist/types/src/types/TriggerEvent.d.ts.map +0 -1
- package/dist/types/src/url.d.ts +0 -21
- package/dist/types/src/url.d.ts.map +0 -1
- package/src/bundler/bundler.test.ts +0 -58
- package/src/bundler/bundler.ts +0 -295
- package/src/bundler/index.ts +0 -5
- package/src/e2e/deploy.test.ts +0 -69
- package/src/edge/functions.ts +0 -67
- package/src/edge/index.ts +0 -9
- package/src/errors.ts +0 -21
- package/src/example/fib.ts +0 -32
- package/src/example/forex-effect.ts +0 -40
- package/src/example/index.ts +0 -13
- package/src/example/reply.ts +0 -21
- package/src/example/sleep.ts +0 -24
- package/src/executor/executor.ts +0 -58
- package/src/handler.ts +0 -226
- package/src/services/database.ts +0 -175
- package/src/services/event-logger.ts +0 -121
- package/src/services/function-invocation-service.test.ts +0 -81
- package/src/services/local-function-execution.ts +0 -153
- package/src/services/remote-function-execution-service.ts +0 -63
- package/src/services/service-container.ts +0 -115
- package/src/services/service-registry.test.ts +0 -45
- package/src/services/service-registry.ts +0 -63
- package/src/testing/index.ts +0 -6
- package/src/testing/layer.ts +0 -114
- package/src/testing/logger.ts +0 -17
- package/src/testing/persist-database.test.ts +0 -87
- package/src/testing/services.ts +0 -115
- package/src/trace.ts +0 -178
- package/src/translations.ts +0 -20
- package/src/triggers/index.ts +0 -7
- package/src/triggers/input-builder.ts +0 -35
- package/src/triggers/invocation-tracer.ts +0 -101
- package/src/triggers/trigger-dispatcher.test.ts +0 -664
- package/src/triggers/trigger-dispatcher.ts +0 -521
- package/src/triggers/trigger-state-store.ts +0 -61
- package/src/types/Function.ts +0 -51
- package/src/types/Script.ts +0 -33
- package/src/types/Trigger.ts +0 -139
- package/src/types/TriggerEvent.ts +0 -62
- package/src/url.ts +0 -55
package/src/types/Trigger.ts
DELETED
|
@@ -1,139 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright 2023 DXOS.org
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
import * as Schema from 'effect/Schema';
|
|
6
|
-
import * as SchemaAST from 'effect/SchemaAST';
|
|
7
|
-
|
|
8
|
-
import { Obj, QueryAST, Type } from '@dxos/echo';
|
|
9
|
-
import { Expando, OptionsAnnotationId, Ref } from '@dxos/echo/internal';
|
|
10
|
-
import { DXN } from '@dxos/keys';
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Type discriminator for TriggerType.
|
|
14
|
-
* Every spec has a type field of type TriggerKind that we can use to understand which type we're working with.
|
|
15
|
-
* https://www.typescriptlang.org/docs/handbook/2/narrowing.html#discriminated-unions
|
|
16
|
-
*/
|
|
17
|
-
export const Kinds = ['email', 'queue', 'subscription', 'timer', 'webhook'] as const;
|
|
18
|
-
export type Kind = (typeof Kinds)[number];
|
|
19
|
-
|
|
20
|
-
const kindLiteralAnnotations = { title: 'Kind' };
|
|
21
|
-
|
|
22
|
-
export const EmailSpec = Schema.Struct({
|
|
23
|
-
kind: Schema.Literal('email').annotations(kindLiteralAnnotations),
|
|
24
|
-
}).pipe(Schema.mutable);
|
|
25
|
-
export type EmailSpec = Schema.Schema.Type<typeof EmailSpec>;
|
|
26
|
-
|
|
27
|
-
export const QueueSpec = Schema.Struct({
|
|
28
|
-
kind: Schema.Literal('queue').annotations(kindLiteralAnnotations),
|
|
29
|
-
|
|
30
|
-
// TODO(dmaretskyi): Change to a reference.
|
|
31
|
-
queue: DXN.Schema,
|
|
32
|
-
}).pipe(Schema.mutable);
|
|
33
|
-
export type QueueSpec = Schema.Schema.Type<typeof QueueSpec>;
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* Subscription.
|
|
37
|
-
*/
|
|
38
|
-
export const SubscriptionSpec = Schema.Struct({
|
|
39
|
-
kind: Schema.Literal('subscription').annotations(kindLiteralAnnotations),
|
|
40
|
-
query: Schema.Struct({
|
|
41
|
-
raw: Schema.optional(Schema.String.annotations({ title: 'Query' })),
|
|
42
|
-
ast: QueryAST.Query,
|
|
43
|
-
}).pipe(Schema.mutable),
|
|
44
|
-
options: Schema.optional(
|
|
45
|
-
Schema.Struct({
|
|
46
|
-
// Watch changes to object (not just creation).
|
|
47
|
-
deep: Schema.optional(Schema.Boolean.annotations({ title: 'Nested' })),
|
|
48
|
-
// Debounce changes (delay in ms).
|
|
49
|
-
delay: Schema.optional(Schema.Number.annotations({ title: 'Delay' })),
|
|
50
|
-
}).annotations({ title: 'Options' }),
|
|
51
|
-
),
|
|
52
|
-
}).pipe(Schema.mutable);
|
|
53
|
-
export type SubscriptionSpec = Schema.Schema.Type<typeof SubscriptionSpec>;
|
|
54
|
-
|
|
55
|
-
/**
|
|
56
|
-
* Cron timer.
|
|
57
|
-
*/
|
|
58
|
-
export const TimerSpec = Schema.Struct({
|
|
59
|
-
kind: Schema.Literal('timer').annotations(kindLiteralAnnotations),
|
|
60
|
-
cron: Schema.String.annotations({
|
|
61
|
-
title: 'Cron',
|
|
62
|
-
[SchemaAST.ExamplesAnnotationId]: ['0 0 * * *'],
|
|
63
|
-
}),
|
|
64
|
-
}).pipe(Schema.mutable);
|
|
65
|
-
export type TimerSpec = Schema.Schema.Type<typeof TimerSpec>;
|
|
66
|
-
|
|
67
|
-
/**
|
|
68
|
-
* Webhook.
|
|
69
|
-
*/
|
|
70
|
-
export const WebhookSpec = Schema.Struct({
|
|
71
|
-
kind: Schema.Literal('webhook').annotations(kindLiteralAnnotations),
|
|
72
|
-
method: Schema.optional(
|
|
73
|
-
Schema.String.annotations({
|
|
74
|
-
title: 'Method',
|
|
75
|
-
[OptionsAnnotationId]: ['GET', 'POST'],
|
|
76
|
-
}),
|
|
77
|
-
),
|
|
78
|
-
port: Schema.optional(
|
|
79
|
-
Schema.Number.annotations({
|
|
80
|
-
title: 'Port',
|
|
81
|
-
}),
|
|
82
|
-
),
|
|
83
|
-
}).pipe(Schema.mutable);
|
|
84
|
-
export type WebhookSpec = Schema.Schema.Type<typeof WebhookSpec>;
|
|
85
|
-
|
|
86
|
-
/**
|
|
87
|
-
* Trigger schema.
|
|
88
|
-
*/
|
|
89
|
-
export const Spec = Schema.Union(EmailSpec, QueueSpec, SubscriptionSpec, TimerSpec, WebhookSpec).annotations({
|
|
90
|
-
title: 'Trigger',
|
|
91
|
-
});
|
|
92
|
-
export type Spec = Schema.Schema.Type<typeof Spec>;
|
|
93
|
-
|
|
94
|
-
/**
|
|
95
|
-
* Function trigger.
|
|
96
|
-
* Function is invoked with the `payload` passed as input data.
|
|
97
|
-
* The event that triggers the function is available in the function context.
|
|
98
|
-
*/
|
|
99
|
-
const Trigger_ = Schema.Struct({
|
|
100
|
-
/**
|
|
101
|
-
* Function or workflow to invoke.
|
|
102
|
-
*/
|
|
103
|
-
// TODO(dmaretskyi): Can be a Ref(FunctionType) or Ref(ComputeGraphType).
|
|
104
|
-
function: Schema.optional(Ref(Expando).annotations({ title: 'Function' })),
|
|
105
|
-
|
|
106
|
-
/**
|
|
107
|
-
* Only used for workflowSchema.
|
|
108
|
-
* Specifies the input node in the circuit.
|
|
109
|
-
* @deprecated Remove and enforce a single input node in all compute graphSchema.
|
|
110
|
-
*/
|
|
111
|
-
inputNodeId: Schema.optional(Schema.String.annotations({ title: 'Input Node ID' })),
|
|
112
|
-
|
|
113
|
-
enabled: Schema.optional(Schema.Boolean.annotations({ title: 'Enabled' })),
|
|
114
|
-
|
|
115
|
-
spec: Schema.optional(Spec),
|
|
116
|
-
|
|
117
|
-
/**
|
|
118
|
-
* Passed as the input data to the function.
|
|
119
|
-
* Must match the function's input schema.
|
|
120
|
-
*
|
|
121
|
-
* @example
|
|
122
|
-
* {
|
|
123
|
-
* item: '{{$.trigger.event}}',
|
|
124
|
-
* instructions: 'Summarize and perform entity-extraction'
|
|
125
|
-
* mailbox: { '/': 'dxn:echo:AAA:ZZZ' }
|
|
126
|
-
* }
|
|
127
|
-
*/
|
|
128
|
-
input: Schema.optional(Schema.mutable(Schema.Record({ key: Schema.String, value: Schema.Any }))),
|
|
129
|
-
}).pipe(
|
|
130
|
-
Type.Obj({
|
|
131
|
-
typename: 'dxos.org/type/Trigger',
|
|
132
|
-
version: '0.1.0',
|
|
133
|
-
}),
|
|
134
|
-
);
|
|
135
|
-
export interface Trigger extends Schema.Schema.Type<typeof Trigger_> {}
|
|
136
|
-
export interface TriggerEncoded extends Schema.Schema.Encoded<typeof Trigger_> {}
|
|
137
|
-
export const Trigger: Schema.Schema<Trigger, TriggerEncoded> = Trigger_;
|
|
138
|
-
|
|
139
|
-
export const make = (props: Obj.MakeProps<typeof Trigger>) => Obj.make(Trigger, props);
|
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright 2025 DXOS.org
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
import * as Schema from 'effect/Schema';
|
|
6
|
-
|
|
7
|
-
import { DXN, Obj, Type } from '@dxos/echo';
|
|
8
|
-
|
|
9
|
-
export type TriggerEvent = EmailEvent | QueueEvent | SubscriptionEvent | TimerEvent | WebhookEvent;
|
|
10
|
-
|
|
11
|
-
// TODO(burdon): Reuse trigger schema from @dxos/functions (TriggerType).
|
|
12
|
-
export const EmailEvent = Schema.mutable(
|
|
13
|
-
Schema.Struct({
|
|
14
|
-
from: Schema.String,
|
|
15
|
-
to: Schema.String,
|
|
16
|
-
subject: Schema.String,
|
|
17
|
-
created: Schema.String,
|
|
18
|
-
body: Schema.String,
|
|
19
|
-
}),
|
|
20
|
-
);
|
|
21
|
-
export type EmailEvent = Schema.Schema.Type<typeof EmailEvent>;
|
|
22
|
-
|
|
23
|
-
export const QueueEvent = Schema.mutable(
|
|
24
|
-
Schema.Struct({
|
|
25
|
-
queue: DXN.Schema,
|
|
26
|
-
item: Schema.Any,
|
|
27
|
-
cursor: Schema.String,
|
|
28
|
-
}),
|
|
29
|
-
);
|
|
30
|
-
export type QueueEvent = Schema.Schema.Type<typeof QueueEvent>;
|
|
31
|
-
|
|
32
|
-
export const SubscriptionEvent = Schema.Struct({
|
|
33
|
-
/**
|
|
34
|
-
* Type of the mutation.
|
|
35
|
-
*/
|
|
36
|
-
// TODO(dmaretskyi): Specify enum.
|
|
37
|
-
type: Schema.String,
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* Reference to the object that was changed or created.
|
|
41
|
-
*/
|
|
42
|
-
subject: Type.Ref(Obj.Any),
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* @deprecated
|
|
46
|
-
*/
|
|
47
|
-
changedObjectId: Schema.optional(Schema.String),
|
|
48
|
-
}).pipe(Schema.mutable);
|
|
49
|
-
export type SubscriptionEvent = Schema.Schema.Type<typeof SubscriptionEvent>;
|
|
50
|
-
|
|
51
|
-
export const TimerEvent = Schema.mutable(Schema.Struct({ tick: Schema.Number }));
|
|
52
|
-
export type TimerEvent = Schema.Schema.Type<typeof TimerEvent>;
|
|
53
|
-
|
|
54
|
-
export const WebhookEvent = Schema.mutable(
|
|
55
|
-
Schema.Struct({
|
|
56
|
-
url: Schema.String,
|
|
57
|
-
method: Schema.Literal('GET', 'POST'),
|
|
58
|
-
headers: Schema.Record({ key: Schema.String, value: Schema.String }),
|
|
59
|
-
bodyText: Schema.String,
|
|
60
|
-
}),
|
|
61
|
-
);
|
|
62
|
-
export type WebhookEvent = Schema.Schema.Type<typeof WebhookEvent>;
|
package/src/url.ts
DELETED
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright 2025 DXOS.org
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
import { type ObjectMeta } from '@dxos/echo/internal';
|
|
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
|
-
};
|