@dxos/functions 0.8.4-main.fd6878d → 0.8.4-main.fffef41
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 +788 -361
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node-esm/index.mjs +788 -361
- 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/example/fib.d.ts +7 -0
- 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/example/reply.d.ts +3 -0
- package/dist/types/src/example/reply.d.ts.map +1 -0
- package/dist/types/src/example/sleep.d.ts +5 -0
- 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 +17 -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 +34 -6
- 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/types/url.d.ts +12 -0
- package/dist/types/src/types/url.d.ts.map +1 -0
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +18 -72
- package/src/errors.ts +13 -5
- package/src/example/fib.ts +32 -0
- package/src/example/forex-effect.ts +40 -0
- package/src/example/index.ts +13 -0
- package/src/example/reply.ts +21 -0
- package/src/example/sleep.ts +24 -0
- 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 +51 -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 +81 -17
- package/src/types/Function.ts +62 -0
- 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 -248
- package/dist/lib/browser/bundler/index.mjs.map +0 -7
- package/dist/lib/browser/chunk-M2OIFLGE.mjs +0 -486
- package/dist/lib/browser/chunk-M2OIFLGE.mjs.map +0 -7
- package/dist/lib/browser/edge/index.mjs +0 -69
- package/dist/lib/browser/edge/index.mjs.map +0 -7
- package/dist/lib/browser/testing/index.mjs +0 -59
- package/dist/lib/browser/testing/index.mjs.map +0 -7
- package/dist/lib/node-esm/bundler/index.mjs +0 -250
- package/dist/lib/node-esm/bundler/index.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-K7REX6H4.mjs +0 -488
- package/dist/lib/node-esm/chunk-K7REX6H4.mjs.map +0 -7
- package/dist/lib/node-esm/edge/index.mjs +0 -71
- package/dist/lib/node-esm/edge/index.mjs.map +0 -7
- package/dist/lib/node-esm/testing/index.mjs +0 -60
- package/dist/lib/node-esm/testing/index.mjs.map +0 -7
- package/dist/types/src/bundler/bundler.d.ts +0 -50
- 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 -16
- 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/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 -38
- package/dist/types/src/schema.d.ts.map +0 -1
- package/dist/types/src/services/database.d.ts +0 -79
- 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 -10
- 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/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/types.d.ts +0 -411
- package/dist/types/src/types.d.ts.map +0 -1
- package/dist/types/src/url.d.ts +0 -17
- package/dist/types/src/url.d.ts.map +0 -1
- package/src/bundler/bundler.test.ts +0 -59
- package/src/bundler/bundler.ts +0 -292
- package/src/bundler/index.ts +0 -5
- package/src/edge/functions.ts +0 -64
- package/src/edge/index.ts +0 -9
- package/src/executor/executor.ts +0 -54
- package/src/handler.ts +0 -122
- package/src/schema.ts +0 -57
- package/src/services/database.ts +0 -116
- package/src/services/local-function-execution.ts +0 -74
- package/src/services/remote-function-execution-service.ts +0 -66
- 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 -31
- package/src/testing/logger.ts +0 -16
- package/src/testing/services.ts +0 -115
- package/src/trace.ts +0 -178
- package/src/translations.ts +0 -20
- package/src/types.ts +0 -211
- package/src/url.ts +0 -52
package/src/trace.ts
DELETED
|
@@ -1,178 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright 2025 DXOS.org
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
import { Schema } from 'effect';
|
|
6
|
-
|
|
7
|
-
import { type Ref, Type } from '@dxos/echo';
|
|
8
|
-
import { Queue } from '@dxos/echo-db';
|
|
9
|
-
import { ObjectId } from '@dxos/echo-schema';
|
|
10
|
-
import { log } from '@dxos/log';
|
|
11
|
-
|
|
12
|
-
import { FunctionTrigger, type FunctionTriggerType } from './types';
|
|
13
|
-
|
|
14
|
-
export enum InvocationOutcome {
|
|
15
|
-
SUCCESS = 'success',
|
|
16
|
-
FAILURE = 'failure',
|
|
17
|
-
PENDING = 'pending',
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
// TODO(burdon): Convert to extensible discriminated union of EDGE events.
|
|
21
|
-
export enum InvocationTraceEventType {
|
|
22
|
-
START = 'start',
|
|
23
|
-
END = 'end',
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
export const TraceEventException = Schema.Struct({
|
|
27
|
-
timestampMs: Schema.Number,
|
|
28
|
-
message: Schema.String,
|
|
29
|
-
name: Schema.String,
|
|
30
|
-
stack: Schema.optional(Schema.String),
|
|
31
|
-
});
|
|
32
|
-
export type TraceEventException = Schema.Schema.Type<typeof TraceEventException>;
|
|
33
|
-
|
|
34
|
-
export const InvocationTraceStartEvent = Schema.Struct({
|
|
35
|
-
/**
|
|
36
|
-
* Queue message id.
|
|
37
|
-
*/
|
|
38
|
-
id: ObjectId,
|
|
39
|
-
type: Schema.Literal(InvocationTraceEventType.START),
|
|
40
|
-
/**
|
|
41
|
-
* Invocation id, the same for invocation start and end events.
|
|
42
|
-
*/
|
|
43
|
-
invocationId: ObjectId,
|
|
44
|
-
/**
|
|
45
|
-
* Event generation time.
|
|
46
|
-
*/
|
|
47
|
-
timestampMs: Schema.Number,
|
|
48
|
-
/**
|
|
49
|
-
* Data passed to function / workflow as an argument.
|
|
50
|
-
*/
|
|
51
|
-
// TODO(burdon): Input schema?
|
|
52
|
-
input: Schema.Object,
|
|
53
|
-
/**
|
|
54
|
-
* Queue for function/workflow invocation events.
|
|
55
|
-
*/
|
|
56
|
-
invocationTraceQueue: Type.Ref(Queue),
|
|
57
|
-
/**
|
|
58
|
-
* DXN of the invoked function/workflow.
|
|
59
|
-
*/
|
|
60
|
-
invocationTarget: Type.Ref(Type.Expando),
|
|
61
|
-
/**
|
|
62
|
-
* Present for automatic invocations.
|
|
63
|
-
*/
|
|
64
|
-
trigger: Schema.optional(Type.Ref(FunctionTrigger)),
|
|
65
|
-
}).pipe(Type.Obj({ typename: 'dxos.org/type/InvocationTraceStart', version: '0.1.0' }));
|
|
66
|
-
|
|
67
|
-
export type InvocationTraceStartEvent = Schema.Schema.Type<typeof InvocationTraceStartEvent>;
|
|
68
|
-
|
|
69
|
-
export const InvocationTraceEndEvent = Schema.Struct({
|
|
70
|
-
/**
|
|
71
|
-
* Trace event id.
|
|
72
|
-
*/
|
|
73
|
-
id: ObjectId,
|
|
74
|
-
type: Schema.Literal(InvocationTraceEventType.END),
|
|
75
|
-
/**
|
|
76
|
-
* Invocation id, will be the same for invocation start and end.
|
|
77
|
-
*/
|
|
78
|
-
invocationId: ObjectId,
|
|
79
|
-
/**
|
|
80
|
-
* Event generation time.
|
|
81
|
-
*/
|
|
82
|
-
// TODO(burdon): Remove ms suffix.
|
|
83
|
-
timestampMs: Schema.Number,
|
|
84
|
-
outcome: Schema.Enums(InvocationOutcome),
|
|
85
|
-
exception: Schema.optional(TraceEventException),
|
|
86
|
-
}).pipe(Type.Obj({ typename: 'dxos.org/type/InvocationTraceEnd', version: '0.1.0' }));
|
|
87
|
-
|
|
88
|
-
export type InvocationTraceEndEvent = Schema.Schema.Type<typeof InvocationTraceEndEvent>;
|
|
89
|
-
|
|
90
|
-
export type InvocationTraceEvent = InvocationTraceStartEvent | InvocationTraceEndEvent;
|
|
91
|
-
|
|
92
|
-
export const TraceEventLog = Schema.Struct({
|
|
93
|
-
timestampMs: Schema.Number,
|
|
94
|
-
level: Schema.String,
|
|
95
|
-
message: Schema.String,
|
|
96
|
-
context: Schema.optional(Schema.Object),
|
|
97
|
-
});
|
|
98
|
-
|
|
99
|
-
export const TraceEvent = Schema.Struct({
|
|
100
|
-
id: ObjectId,
|
|
101
|
-
// TODO(burdon): Need enum/numeric result (not string).
|
|
102
|
-
outcome: Schema.String,
|
|
103
|
-
truncated: Schema.Boolean,
|
|
104
|
-
/** Time when the event was persisted. */
|
|
105
|
-
ingestionTimestamp: Schema.Number,
|
|
106
|
-
logs: Schema.Array(TraceEventLog),
|
|
107
|
-
exceptions: Schema.Array(TraceEventException),
|
|
108
|
-
}).pipe(Type.Obj({ typename: 'dxos.org/type/TraceEvent', version: '0.1.0' }));
|
|
109
|
-
|
|
110
|
-
export type TraceEvent = Schema.Schema.Type<typeof TraceEvent>;
|
|
111
|
-
|
|
112
|
-
/**
|
|
113
|
-
* InvocationTrace event format.
|
|
114
|
-
* This is the combined format of InvocationTraceStartEvent and InvocationTraceEndEvents for UI consumption.
|
|
115
|
-
*/
|
|
116
|
-
export type InvocationSpan = {
|
|
117
|
-
id: string;
|
|
118
|
-
timestampMs: number;
|
|
119
|
-
outcome: InvocationOutcome;
|
|
120
|
-
input: object;
|
|
121
|
-
durationMs: number;
|
|
122
|
-
invocationTraceQueue: Ref.Ref<Queue>;
|
|
123
|
-
invocationTarget: Ref.Ref<Type.Expando>;
|
|
124
|
-
trigger?: Ref.Ref<FunctionTriggerType>;
|
|
125
|
-
exception?: TraceEventException;
|
|
126
|
-
};
|
|
127
|
-
|
|
128
|
-
export const createInvocationSpans = (items?: InvocationTraceEvent[]): InvocationSpan[] => {
|
|
129
|
-
if (!items) {
|
|
130
|
-
return [];
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
const eventsByInvocationId = new Map<string, { start?: InvocationTraceStartEvent; end?: InvocationTraceEndEvent }>();
|
|
134
|
-
for (const event of items) {
|
|
135
|
-
if (!('invocationId' in event)) {
|
|
136
|
-
// Skip legacy format entries.
|
|
137
|
-
continue;
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
const invocationId = event.invocationId;
|
|
141
|
-
const entry = eventsByInvocationId.get(invocationId) || { start: undefined, end: undefined };
|
|
142
|
-
if (event.type === InvocationTraceEventType.START) {
|
|
143
|
-
entry.start = event as InvocationTraceStartEvent;
|
|
144
|
-
} else if (event.type === InvocationTraceEventType.END) {
|
|
145
|
-
entry.end = event as InvocationTraceEndEvent;
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
eventsByInvocationId.set(invocationId, entry);
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
const now = Date.now();
|
|
152
|
-
const result: InvocationSpan[] = [];
|
|
153
|
-
|
|
154
|
-
// Create spans for each invocation
|
|
155
|
-
for (const [invocationId, { start, end }] of eventsByInvocationId.entries()) {
|
|
156
|
-
if (!start) {
|
|
157
|
-
// No start event, can't create a meaningful span
|
|
158
|
-
log.warn('found end event without matching start', { invocationId });
|
|
159
|
-
continue;
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
const isInProgress = end === undefined;
|
|
163
|
-
|
|
164
|
-
result.push({
|
|
165
|
-
id: invocationId,
|
|
166
|
-
timestampMs: start.timestampMs,
|
|
167
|
-
durationMs: isInProgress ? now - start.timestampMs : end!.timestampMs - start.timestampMs,
|
|
168
|
-
outcome: end?.outcome ?? InvocationOutcome.PENDING,
|
|
169
|
-
exception: end?.exception,
|
|
170
|
-
input: start.input,
|
|
171
|
-
invocationTraceQueue: start.invocationTraceQueue,
|
|
172
|
-
invocationTarget: start.invocationTarget,
|
|
173
|
-
trigger: start.trigger,
|
|
174
|
-
});
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
return result;
|
|
178
|
-
};
|
package/src/translations.ts
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright 2023 DXOS.org
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
import { type Resource } from 'i18next';
|
|
6
|
-
|
|
7
|
-
import { ScriptType } from './schema';
|
|
8
|
-
|
|
9
|
-
export const translations = [
|
|
10
|
-
{
|
|
11
|
-
'en-US': {
|
|
12
|
-
[ScriptType.typename]: {
|
|
13
|
-
'typename label': 'Script',
|
|
14
|
-
'typename label_zero': 'Scripts',
|
|
15
|
-
'typename label_one': 'Script',
|
|
16
|
-
'typename label_other': 'Scripts',
|
|
17
|
-
},
|
|
18
|
-
},
|
|
19
|
-
},
|
|
20
|
-
] as const satisfies Resource[];
|
package/src/types.ts
DELETED
|
@@ -1,211 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright 2023 DXOS.org
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
import { Schema, SchemaAST } from 'effect';
|
|
6
|
-
|
|
7
|
-
import { Expando, OptionsAnnotationId, RawObject, Ref, TypedObject } from '@dxos/echo-schema';
|
|
8
|
-
import { DXN } from '@dxos/keys';
|
|
9
|
-
|
|
10
|
-
import { FunctionType } from './schema';
|
|
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 enum TriggerKind {
|
|
18
|
-
Timer = 'timer',
|
|
19
|
-
Webhook = 'webhook',
|
|
20
|
-
Subscription = 'subscription',
|
|
21
|
-
Email = 'email',
|
|
22
|
-
Queue = 'queue',
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
const kindLiteralAnnotations = { title: 'Kind' };
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* Cron timer.
|
|
29
|
-
*/
|
|
30
|
-
const TimerTriggerSchema = Schema.Struct({
|
|
31
|
-
kind: Schema.Literal(TriggerKind.Timer).annotations(kindLiteralAnnotations),
|
|
32
|
-
cron: Schema.String.annotations({
|
|
33
|
-
title: 'Cron',
|
|
34
|
-
[SchemaAST.ExamplesAnnotationId]: ['0 0 * * *'],
|
|
35
|
-
}),
|
|
36
|
-
}).pipe(Schema.mutable);
|
|
37
|
-
export type TimerTrigger = Schema.Schema.Type<typeof TimerTriggerSchema>;
|
|
38
|
-
|
|
39
|
-
const EmailTriggerSchema = Schema.Struct({
|
|
40
|
-
kind: Schema.Literal(TriggerKind.Email).annotations(kindLiteralAnnotations),
|
|
41
|
-
}).pipe(Schema.mutable);
|
|
42
|
-
export type EmailTrigger = Schema.Schema.Type<typeof EmailTriggerSchema>;
|
|
43
|
-
|
|
44
|
-
const QueueTriggerSchema = Schema.Struct({
|
|
45
|
-
kind: Schema.Literal(TriggerKind.Queue).annotations(kindLiteralAnnotations),
|
|
46
|
-
queue: DXN.Schema,
|
|
47
|
-
}).pipe(Schema.mutable);
|
|
48
|
-
export type QueueTrigger = Schema.Schema.Type<typeof QueueTriggerSchema>;
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
* Webhook.
|
|
52
|
-
*/
|
|
53
|
-
const WebhookTriggerSchema = Schema.Struct({
|
|
54
|
-
kind: Schema.Literal(TriggerKind.Webhook).annotations(kindLiteralAnnotations),
|
|
55
|
-
method: Schema.optional(
|
|
56
|
-
Schema.String.annotations({
|
|
57
|
-
title: 'Method',
|
|
58
|
-
[OptionsAnnotationId]: ['GET', 'POST'],
|
|
59
|
-
}),
|
|
60
|
-
),
|
|
61
|
-
port: Schema.optional(
|
|
62
|
-
Schema.Number.annotations({
|
|
63
|
-
title: 'Port',
|
|
64
|
-
}),
|
|
65
|
-
),
|
|
66
|
-
}).pipe(Schema.mutable);
|
|
67
|
-
export type WebhookTrigger = Schema.Schema.Type<typeof WebhookTriggerSchema>;
|
|
68
|
-
|
|
69
|
-
// TODO(burdon): Use ECHO definition (from https://github.com/dxos/dxos/pull/8233).
|
|
70
|
-
const QuerySchema = Schema.Struct({
|
|
71
|
-
type: Schema.optional(Schema.String.annotations({ title: 'Type' })),
|
|
72
|
-
props: Schema.optional(Schema.Record({ key: Schema.String, value: Schema.Any })),
|
|
73
|
-
}).annotations({ title: 'Query' });
|
|
74
|
-
|
|
75
|
-
/**
|
|
76
|
-
* Subscription.
|
|
77
|
-
*/
|
|
78
|
-
const SubscriptionTriggerSchema = Schema.Struct({
|
|
79
|
-
kind: Schema.Literal(TriggerKind.Subscription).annotations(kindLiteralAnnotations),
|
|
80
|
-
// TODO(burdon): Define query DSL (from ECHO). Reconcile with Table.Query.
|
|
81
|
-
filter: QuerySchema,
|
|
82
|
-
options: Schema.optional(
|
|
83
|
-
Schema.Struct({
|
|
84
|
-
// Watch changes to object (not just creation).
|
|
85
|
-
deep: Schema.optional(Schema.Boolean.annotations({ title: 'Nested' })),
|
|
86
|
-
// Debounce changes (delay in ms).
|
|
87
|
-
delay: Schema.optional(Schema.Number.annotations({ title: 'Delay' })),
|
|
88
|
-
}).annotations({ title: 'Options' }),
|
|
89
|
-
),
|
|
90
|
-
}).pipe(Schema.mutable);
|
|
91
|
-
export type SubscriptionTrigger = Schema.Schema.Type<typeof SubscriptionTriggerSchema>;
|
|
92
|
-
|
|
93
|
-
/**
|
|
94
|
-
* Trigger schema (discriminated union).
|
|
95
|
-
*/
|
|
96
|
-
export const TriggerSchema = Schema.Union(
|
|
97
|
-
TimerTriggerSchema,
|
|
98
|
-
WebhookTriggerSchema,
|
|
99
|
-
SubscriptionTriggerSchema,
|
|
100
|
-
EmailTriggerSchema,
|
|
101
|
-
QueueTriggerSchema,
|
|
102
|
-
).annotations({
|
|
103
|
-
title: 'Trigger',
|
|
104
|
-
});
|
|
105
|
-
export type TriggerType = Schema.Schema.Type<typeof TriggerSchema>;
|
|
106
|
-
|
|
107
|
-
export type EventType =
|
|
108
|
-
| EmailTriggerOutput
|
|
109
|
-
| WebhookTriggerOutput
|
|
110
|
-
| QueueTriggerOutput
|
|
111
|
-
| SubscriptionTriggerOutput
|
|
112
|
-
| TimerTriggerOutput;
|
|
113
|
-
|
|
114
|
-
// TODO(burdon): Reuse trigger schema from @dxos/functions (TriggerType).
|
|
115
|
-
export const EmailTriggerOutput = Schema.mutable(
|
|
116
|
-
Schema.Struct({
|
|
117
|
-
from: Schema.String,
|
|
118
|
-
to: Schema.String,
|
|
119
|
-
subject: Schema.String,
|
|
120
|
-
created: Schema.String,
|
|
121
|
-
body: Schema.String,
|
|
122
|
-
}),
|
|
123
|
-
);
|
|
124
|
-
export type EmailTriggerOutput = Schema.Schema.Type<typeof EmailTriggerOutput>;
|
|
125
|
-
|
|
126
|
-
export const WebhookTriggerOutput = Schema.mutable(
|
|
127
|
-
Schema.Struct({
|
|
128
|
-
url: Schema.String,
|
|
129
|
-
method: Schema.Literal('GET', 'POST'),
|
|
130
|
-
headers: Schema.Record({ key: Schema.String, value: Schema.String }),
|
|
131
|
-
bodyText: Schema.String,
|
|
132
|
-
}),
|
|
133
|
-
);
|
|
134
|
-
export type WebhookTriggerOutput = Schema.Schema.Type<typeof WebhookTriggerOutput>;
|
|
135
|
-
|
|
136
|
-
export const QueueTriggerOutput = Schema.mutable(
|
|
137
|
-
Schema.Struct({
|
|
138
|
-
queue: DXN.Schema,
|
|
139
|
-
item: Schema.Any,
|
|
140
|
-
cursor: Schema.String,
|
|
141
|
-
}),
|
|
142
|
-
);
|
|
143
|
-
export type QueueTriggerOutput = Schema.Schema.Type<typeof QueueTriggerOutput>;
|
|
144
|
-
|
|
145
|
-
export const SubscriptionTriggerOutput = Schema.mutable(
|
|
146
|
-
Schema.Struct({ type: Schema.String, changedObjectId: Schema.String }),
|
|
147
|
-
);
|
|
148
|
-
export type SubscriptionTriggerOutput = Schema.Schema.Type<typeof SubscriptionTriggerOutput>;
|
|
149
|
-
|
|
150
|
-
export const TimerTriggerOutput = Schema.mutable(Schema.Struct({ tick: Schema.Number }));
|
|
151
|
-
export type TimerTriggerOutput = Schema.Schema.Type<typeof TimerTriggerOutput>;
|
|
152
|
-
|
|
153
|
-
/**
|
|
154
|
-
* Function trigger.
|
|
155
|
-
* Function is invoked with the `payload` passed as input data.
|
|
156
|
-
* The event that triggers the function is available in the function context.
|
|
157
|
-
*/
|
|
158
|
-
export const FunctionTriggerSchema = Schema.Struct({
|
|
159
|
-
/**
|
|
160
|
-
* Function or workflow to invoke.
|
|
161
|
-
*/
|
|
162
|
-
// TODO(dmaretskyi): Can be a Ref(FunctionType) or Ref(ComputeGraphType).
|
|
163
|
-
function: Schema.optional(Ref(Expando).annotations({ title: 'Function' })),
|
|
164
|
-
|
|
165
|
-
/**
|
|
166
|
-
* Only used for workflowSchema.
|
|
167
|
-
* Specifies the input node in the circuit.
|
|
168
|
-
* @deprecated Remove and enforce a single input node in all compute graphSchema.
|
|
169
|
-
*/
|
|
170
|
-
inputNodeId: Schema.optional(Schema.String.annotations({ title: 'Input Node ID' })),
|
|
171
|
-
|
|
172
|
-
enabled: Schema.optional(Schema.Boolean.annotations({ title: 'Enabled' })),
|
|
173
|
-
|
|
174
|
-
spec: Schema.optional(TriggerSchema),
|
|
175
|
-
|
|
176
|
-
/**
|
|
177
|
-
* Passed as the input data to the function.
|
|
178
|
-
* Must match the function's input schema.
|
|
179
|
-
*
|
|
180
|
-
* @example
|
|
181
|
-
* {
|
|
182
|
-
* item: '{{$.trigger.event}}',
|
|
183
|
-
* instructions: 'Summarize and perform entity-extraction'
|
|
184
|
-
* mailbox: { '/': 'dxn:echo:AAA:ZZZ' }
|
|
185
|
-
* }
|
|
186
|
-
*/
|
|
187
|
-
input: Schema.optional(Schema.mutable(Schema.Record({ key: Schema.String, value: Schema.Any }))),
|
|
188
|
-
});
|
|
189
|
-
|
|
190
|
-
export type FunctionTriggerType = Schema.Schema.Type<typeof FunctionTriggerSchema>;
|
|
191
|
-
|
|
192
|
-
/**
|
|
193
|
-
* Function trigger.
|
|
194
|
-
*/
|
|
195
|
-
export class FunctionTrigger extends TypedObject({
|
|
196
|
-
typename: 'dxos.org/type/FunctionTrigger',
|
|
197
|
-
version: '0.2.0',
|
|
198
|
-
})(FunctionTriggerSchema.fields) {}
|
|
199
|
-
|
|
200
|
-
// TODO(wittjosiah): Remove?
|
|
201
|
-
|
|
202
|
-
/**
|
|
203
|
-
* Function manifest file.
|
|
204
|
-
*/
|
|
205
|
-
export const FunctionManifestSchema = Schema.Struct({
|
|
206
|
-
functions: Schema.optional(Schema.mutable(Schema.Array(RawObject(FunctionType)))),
|
|
207
|
-
triggers: Schema.optional(Schema.mutable(Schema.Array(RawObject(FunctionTrigger)))),
|
|
208
|
-
});
|
|
209
|
-
export type FunctionManifest = Schema.Schema.Type<typeof FunctionManifestSchema>;
|
|
210
|
-
|
|
211
|
-
export const FUNCTION_TYPES = [FunctionType, FunctionTrigger];
|
package/src/url.ts
DELETED
|
@@ -1,52 +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
|
-
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
|
-
export const getUserFunctionUrlInMetadata = (meta: ObjectMeta) => {
|
|
18
|
-
return meta.keys.find((key) => key.source === FUNCTIONS_META_KEY)?.id;
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
export const setUserFunctionUrlInMetadata = (meta: ObjectMeta, functionUrl: string) => {
|
|
22
|
-
const key = meta.keys.find((key) => key.source === FUNCTIONS_META_KEY);
|
|
23
|
-
if (key) {
|
|
24
|
-
if (key.id !== functionUrl) {
|
|
25
|
-
throw new Error('Metadata mismatch');
|
|
26
|
-
}
|
|
27
|
-
} else {
|
|
28
|
-
meta.keys.push({ source: FUNCTIONS_META_KEY, id: functionUrl });
|
|
29
|
-
}
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* NOTE: functionId is backend ID, not ECHO object id.
|
|
34
|
-
*/
|
|
35
|
-
export const makeFunctionUrl = (fn: { functionId: string }) => `/${fn.functionId}`;
|
|
36
|
-
|
|
37
|
-
export const getInvocationUrl = (functionUrl: string, edgeUrl: string, options: InvocationOptions = {}) => {
|
|
38
|
-
const baseUrl = new URL('functions/', edgeUrl);
|
|
39
|
-
|
|
40
|
-
// Leading slashes cause the URL to be treated as an absolute path.
|
|
41
|
-
const relativeUrl = functionUrl.replace(/^\//, '');
|
|
42
|
-
const url = new URL(`./${relativeUrl}`, baseUrl.toString());
|
|
43
|
-
options.spaceId && url.searchParams.set('spaceId', options.spaceId);
|
|
44
|
-
options.subjectId && url.searchParams.set('subjectId', options.subjectId);
|
|
45
|
-
url.protocol = isSecure(url.protocol) ? 'https' : 'http';
|
|
46
|
-
return url.toString();
|
|
47
|
-
};
|
|
48
|
-
|
|
49
|
-
export type InvocationOptions = {
|
|
50
|
-
spaceId?: SpaceId;
|
|
51
|
-
subjectId?: string;
|
|
52
|
-
};
|