@dxos/compute 0.8.4-main.9be5663bfe → 0.8.4-main.abd8ff62ef
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 +36 -1
- package/dist/lib/neutral/StorageService.mjs +22 -0
- package/dist/lib/neutral/StorageService.mjs.map +7 -0
- package/dist/lib/neutral/chunk-4N4JAXCP.mjs +17 -0
- package/dist/lib/neutral/chunk-4N4JAXCP.mjs.map +7 -0
- package/dist/lib/neutral/chunk-DDEBBRCI.mjs +62 -0
- package/dist/lib/neutral/chunk-DDEBBRCI.mjs.map +7 -0
- package/dist/lib/neutral/chunk-FEABF5XY.mjs +25 -0
- package/dist/lib/neutral/chunk-FEABF5XY.mjs.map +7 -0
- package/dist/lib/neutral/chunk-H6EHIVDN.mjs +21 -0
- package/dist/lib/neutral/chunk-H6EHIVDN.mjs.map +7 -0
- package/dist/lib/neutral/chunk-J5LGTIGS.mjs +10 -0
- package/dist/lib/neutral/chunk-J5LGTIGS.mjs.map +7 -0
- package/dist/lib/neutral/chunk-N462A6NO.mjs +138 -0
- package/dist/lib/neutral/chunk-N462A6NO.mjs.map +7 -0
- package/dist/lib/neutral/chunk-QPCDM7MF.mjs +179 -0
- package/dist/lib/neutral/chunk-QPCDM7MF.mjs.map +7 -0
- package/dist/lib/neutral/chunk-S24LL2D5.mjs +52 -0
- package/dist/lib/neutral/chunk-S24LL2D5.mjs.map +7 -0
- package/dist/lib/neutral/fib-HDHBZHPE.mjs +10 -0
- package/dist/lib/neutral/fib-HDHBZHPE.mjs.map +7 -0
- package/dist/lib/neutral/index.mjs +1030 -51
- package/dist/lib/neutral/index.mjs.map +4 -4
- package/dist/lib/neutral/meta.json +1 -1
- package/dist/lib/neutral/reply-XSQMXAPX.mjs +10 -0
- package/dist/lib/neutral/reply-XSQMXAPX.mjs.map +7 -0
- package/dist/lib/neutral/sleep-WHTJQ56P.mjs +10 -0
- package/dist/lib/neutral/sleep-WHTJQ56P.mjs.map +7 -0
- package/dist/lib/neutral/testing/index.mjs +27 -193
- package/dist/lib/neutral/testing/index.mjs.map +4 -4
- package/dist/types/src/Blueprint.d.ts +148 -0
- package/dist/types/src/Blueprint.d.ts.map +1 -0
- package/dist/types/src/Credential.d.ts +27 -0
- package/dist/types/src/Credential.d.ts.map +1 -0
- package/dist/types/src/Operation.d.ts +303 -0
- package/dist/types/src/Operation.d.ts.map +1 -0
- package/dist/types/src/OperationHandlerSet.d.ts +60 -0
- package/dist/types/src/OperationHandlerSet.d.ts.map +1 -0
- package/dist/types/src/OperationRegistry.d.ts +23 -0
- package/dist/types/src/OperationRegistry.d.ts.map +1 -0
- package/dist/types/src/Process.d.ts +247 -0
- package/dist/types/src/Process.d.ts.map +1 -0
- package/dist/types/src/Routine.d.ts +61 -0
- package/dist/types/src/Routine.d.ts.map +1 -0
- package/dist/types/src/Script.d.ts +22 -0
- package/dist/types/src/Script.d.ts.map +1 -0
- package/dist/types/src/ServiceResolver.d.ts +74 -0
- package/dist/types/src/ServiceResolver.d.ts.map +1 -0
- package/dist/types/src/StorageService.d.ts +58 -0
- package/dist/types/src/StorageService.d.ts.map +1 -0
- package/dist/types/src/Template.d.ts +56 -0
- package/dist/types/src/Template.d.ts.map +1 -0
- package/dist/types/src/Trace.d.ts +174 -0
- package/dist/types/src/Trace.d.ts.map +1 -0
- package/dist/types/src/Trigger.d.ts +150 -0
- package/dist/types/src/Trigger.d.ts.map +1 -0
- package/dist/types/src/TriggerEvent.d.ts +75 -0
- package/dist/types/src/TriggerEvent.d.ts.map +1 -0
- package/dist/types/src/errors.d.ts +239 -0
- package/dist/types/src/errors.d.ts.map +1 -0
- package/dist/types/src/index.d.ts +15 -5
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/testing/definitions.d.ts +11 -0
- package/dist/types/src/testing/definitions.d.ts.map +1 -0
- package/dist/types/src/testing/fib.d.ts +8 -0
- package/dist/types/src/testing/fib.d.ts.map +1 -0
- package/dist/types/src/testing/index.d.ts +6 -4
- package/dist/types/src/testing/index.d.ts.map +1 -1
- package/dist/types/src/testing/reply.d.ts +4 -0
- package/dist/types/src/testing/reply.d.ts.map +1 -0
- package/dist/types/src/testing/sleep.d.ts +6 -0
- package/dist/types/src/testing/sleep.d.ts.map +1 -0
- package/dist/types/src/umbrella.test.d.ts +2 -0
- package/dist/types/src/umbrella.test.d.ts.map +1 -0
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +20 -34
- package/src/Blueprint.ts +221 -0
- package/src/Credential.ts +51 -0
- package/src/Operation.ts +513 -0
- package/src/OperationHandlerSet.ts +132 -0
- package/src/OperationRegistry.ts +48 -0
- package/src/Process.ts +490 -0
- package/src/Routine.ts +84 -0
- package/src/Script.ts +38 -0
- package/src/ServiceResolver.ts +174 -0
- package/src/StorageService.ts +99 -0
- package/src/Template.ts +105 -0
- package/src/Trace.ts +231 -0
- package/src/Trigger.ts +207 -0
- package/src/TriggerEvent.ts +62 -0
- package/src/errors.ts +50 -0
- package/src/index.ts +16 -6
- package/src/testing/definitions.ts +49 -0
- package/src/testing/fib.ts +22 -0
- package/src/testing/index.ts +13 -5
- package/src/testing/reply.ts +18 -0
- package/src/testing/sleep.ts +16 -0
- package/src/umbrella.test.ts +51 -0
- package/dist/lib/neutral/chunk-36MMQLBR.mjs +0 -3104
- package/dist/lib/neutral/chunk-36MMQLBR.mjs.map +0 -7
- package/dist/types/src/compute-graph-registry.d.ts +0 -37
- package/dist/types/src/compute-graph-registry.d.ts.map +0 -1
- package/dist/types/src/compute-graph-registry.test.d.ts +0 -2
- package/dist/types/src/compute-graph-registry.test.d.ts.map +0 -1
- package/dist/types/src/compute-graph.d.ts +0 -67
- package/dist/types/src/compute-graph.d.ts.map +0 -1
- package/dist/types/src/compute-graph.test.d.ts +0 -2
- package/dist/types/src/compute-graph.test.d.ts.map +0 -1
- package/dist/types/src/compute-node.d.ts +0 -24
- package/dist/types/src/compute-node.d.ts.map +0 -1
- package/dist/types/src/functions/async-function.d.ts +0 -68
- package/dist/types/src/functions/async-function.d.ts.map +0 -1
- package/dist/types/src/functions/edge-function.d.ts +0 -20
- package/dist/types/src/functions/edge-function.d.ts.map +0 -1
- package/dist/types/src/functions/function-defs.d.ts +0 -11
- package/dist/types/src/functions/function-defs.d.ts.map +0 -1
- package/dist/types/src/functions/index.d.ts +0 -4
- package/dist/types/src/functions/index.d.ts.map +0 -1
- package/dist/types/src/hyperformula.test.d.ts +0 -2
- package/dist/types/src/hyperformula.test.d.ts.map +0 -1
- package/dist/types/src/testing/test-builder.d.ts +0 -15
- package/dist/types/src/testing/test-builder.d.ts.map +0 -1
- package/dist/types/src/testing/test-plugin.d.ts +0 -35
- package/dist/types/src/testing/test-plugin.d.ts.map +0 -1
- package/dist/types/src/testing/test-runtime.d.ts +0 -10
- package/dist/types/src/testing/test-runtime.d.ts.map +0 -1
- package/dist/types/src/testing/util.d.ts +0 -2
- package/dist/types/src/testing/util.d.ts.map +0 -1
- package/dist/types/src/types/hyperformula.d.ts +0 -8
- package/dist/types/src/types/hyperformula.d.ts.map +0 -1
- package/dist/types/src/types/index.d.ts +0 -3
- package/dist/types/src/types/index.d.ts.map +0 -1
- package/dist/types/src/types/types.d.ts +0 -20
- package/dist/types/src/types/types.d.ts.map +0 -1
- package/dist/types/src/types/types.test.d.ts +0 -2
- package/dist/types/src/types/types.test.d.ts.map +0 -1
- package/dist/types/src/util.d.ts +0 -2
- package/dist/types/src/util.d.ts.map +0 -1
- package/src/compute-graph-registry.test.ts +0 -167
- package/src/compute-graph-registry.ts +0 -97
- package/src/compute-graph.test.ts +0 -139
- package/src/compute-graph.ts +0 -266
- package/src/compute-node.ts +0 -59
- package/src/functions/async-function.ts +0 -184
- package/src/functions/edge-function.ts +0 -113
- package/src/functions/function-defs.ts +0 -2427
- package/src/functions/index.ts +0 -7
- package/src/hyperformula.test.ts +0 -14
- package/src/testing/test-builder.ts +0 -59
- package/src/testing/test-plugin.ts +0 -98
- package/src/testing/test-runtime.ts +0 -36
- package/src/testing/util.ts +0 -9
- package/src/types/hyperformula.ts +0 -19
- package/src/types/index.ts +0 -6
- package/src/types/types.test.ts +0 -91
- package/src/types/types.ts +0 -80
- package/src/util.ts +0 -8
package/src/Trigger.ts
ADDED
|
@@ -0,0 +1,207 @@
|
|
|
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 { Annotation, Feed, Obj, QueryAST, Ref, Type, type Query } from '@dxos/echo';
|
|
9
|
+
import { OptionsAnnotationId, SystemTypeAnnotation } from '@dxos/echo/internal';
|
|
10
|
+
import { failedInvariant } from '@dxos/invariant';
|
|
11
|
+
import { DXN } from '@dxos/keys';
|
|
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 Kinds = ['email', 'queue', 'subscription', 'timer', 'webhook'] as const;
|
|
19
|
+
export type Kind = (typeof Kinds)[number];
|
|
20
|
+
|
|
21
|
+
const kindLiteralAnnotations = { title: 'Kind' };
|
|
22
|
+
|
|
23
|
+
export const EmailSpec = Schema.Struct({
|
|
24
|
+
kind: Schema.Literal('email').annotations(kindLiteralAnnotations),
|
|
25
|
+
});
|
|
26
|
+
export type EmailSpec = Schema.Schema.Type<typeof EmailSpec>;
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Construct an Email trigger spec.
|
|
30
|
+
*/
|
|
31
|
+
export const specEmail = (): EmailSpec => ({ kind: 'email' });
|
|
32
|
+
|
|
33
|
+
// TODO(burdon): Change to Feed.
|
|
34
|
+
// TODO(wittjosiah): Remove. Migrate to Subscription triggers once EDGE supports them for feed queries.
|
|
35
|
+
export const QueueSpec = Schema.Struct({
|
|
36
|
+
kind: Schema.Literal('queue').annotations(kindLiteralAnnotations),
|
|
37
|
+
|
|
38
|
+
// TODO(dmaretskyi): Rename to `feed` and change to a reference.
|
|
39
|
+
queue: DXN.Schema,
|
|
40
|
+
});
|
|
41
|
+
export type QueueSpec = Schema.Schema.Type<typeof QueueSpec>;
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Construct a Queue trigger spec from a queue DXN string.
|
|
45
|
+
*/
|
|
46
|
+
export const specQueue = (queueDxn: string): QueueSpec => ({
|
|
47
|
+
kind: 'queue',
|
|
48
|
+
queue: queueDxn,
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Construct a Queue trigger spec from a Feed object.
|
|
53
|
+
*/
|
|
54
|
+
export const specFeed = (feed: Feed.Feed): QueueSpec =>
|
|
55
|
+
specQueue(Feed.getQueueDxn(feed)?.toString() ?? failedInvariant(new Error('Could not extract DXN from feed')));
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Subscription.
|
|
59
|
+
*/
|
|
60
|
+
export const SubscriptionSpec = Schema.Struct({
|
|
61
|
+
kind: Schema.Literal('subscription').annotations(kindLiteralAnnotations),
|
|
62
|
+
query: Schema.Struct({
|
|
63
|
+
raw: Schema.optional(Schema.String.annotations({ title: 'Query' })),
|
|
64
|
+
ast: QueryAST.Query,
|
|
65
|
+
}),
|
|
66
|
+
options: Schema.optional(
|
|
67
|
+
Schema.Struct({
|
|
68
|
+
// Watch changes to object (not just creation).
|
|
69
|
+
deep: Schema.optional(Schema.Boolean.annotations({ title: 'Nested' })),
|
|
70
|
+
// Debounce changes (delay in ms).
|
|
71
|
+
delay: Schema.optional(Schema.Number.annotations({ title: 'Delay' })),
|
|
72
|
+
}).annotations({ title: 'Options' }),
|
|
73
|
+
),
|
|
74
|
+
});
|
|
75
|
+
export type SubscriptionSpec = Schema.Schema.Type<typeof SubscriptionSpec>;
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Construct a Subscription trigger spec from a Query object.
|
|
79
|
+
*/
|
|
80
|
+
export const specSubscription = (
|
|
81
|
+
query: Query.Query<any>,
|
|
82
|
+
options?: { deep?: boolean; delay?: number },
|
|
83
|
+
): SubscriptionSpec => ({
|
|
84
|
+
kind: 'subscription',
|
|
85
|
+
query: {
|
|
86
|
+
ast: query.ast,
|
|
87
|
+
},
|
|
88
|
+
options: options
|
|
89
|
+
? {
|
|
90
|
+
deep: options.deep,
|
|
91
|
+
delay: options.delay,
|
|
92
|
+
}
|
|
93
|
+
: undefined,
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Cron timer.
|
|
98
|
+
*/
|
|
99
|
+
export const TimerSpec = Schema.Struct({
|
|
100
|
+
kind: Schema.Literal('timer').annotations(kindLiteralAnnotations),
|
|
101
|
+
cron: Schema.String.annotations({
|
|
102
|
+
title: 'Cron',
|
|
103
|
+
[SchemaAST.ExamplesAnnotationId]: ['0 0 * * *'],
|
|
104
|
+
}),
|
|
105
|
+
});
|
|
106
|
+
export type TimerSpec = Schema.Schema.Type<typeof TimerSpec>;
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Construct a Timer trigger spec from a cron string.
|
|
110
|
+
*/
|
|
111
|
+
export const specTimer = (cron: string): TimerSpec => ({ kind: 'timer', cron });
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Webhook.
|
|
115
|
+
*/
|
|
116
|
+
export const WebhookSpec = Schema.Struct({
|
|
117
|
+
kind: Schema.Literal('webhook').annotations(kindLiteralAnnotations),
|
|
118
|
+
method: Schema.optional(
|
|
119
|
+
Schema.String.annotations({
|
|
120
|
+
title: 'Method',
|
|
121
|
+
[OptionsAnnotationId]: ['GET', 'POST'],
|
|
122
|
+
}),
|
|
123
|
+
),
|
|
124
|
+
port: Schema.optional(
|
|
125
|
+
Schema.Number.annotations({
|
|
126
|
+
title: 'Port',
|
|
127
|
+
}),
|
|
128
|
+
),
|
|
129
|
+
});
|
|
130
|
+
export type WebhookSpec = Schema.Schema.Type<typeof WebhookSpec>;
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* Construct a Webhook trigger spec from a method and port.
|
|
134
|
+
*/
|
|
135
|
+
export const specWebhook = (opts?: { method?: string; port?: number }): WebhookSpec => ({
|
|
136
|
+
kind: 'webhook',
|
|
137
|
+
method: opts?.method,
|
|
138
|
+
port: opts?.port,
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* Trigger schema.
|
|
143
|
+
*/
|
|
144
|
+
export const Spec = Schema.Union(EmailSpec, QueueSpec, SubscriptionSpec, TimerSpec, WebhookSpec).annotations({
|
|
145
|
+
title: 'Trigger',
|
|
146
|
+
});
|
|
147
|
+
export type Spec = Schema.Schema.Type<typeof Spec>;
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* Function trigger.
|
|
151
|
+
* Function is invoked with the `payload` passed as input data.
|
|
152
|
+
* The event that triggers the function is available in the function context.
|
|
153
|
+
*/
|
|
154
|
+
const TriggerSchema = Schema.Struct({
|
|
155
|
+
/**
|
|
156
|
+
* Function or workflow to invoke.
|
|
157
|
+
*/
|
|
158
|
+
// TODO(dmaretskyi): Can be a Ref(FunctionType) or Ref(ComputeGraphType).
|
|
159
|
+
function: Schema.optional(Ref.Ref(Obj.Unknown).annotations({ title: 'Function' })),
|
|
160
|
+
|
|
161
|
+
/**
|
|
162
|
+
* Only used for workflowSchema.
|
|
163
|
+
* Specifies the input node in the circuit.
|
|
164
|
+
* @deprecated Remove and enforce a single input node in all compute graphSchema.
|
|
165
|
+
*/
|
|
166
|
+
inputNodeId: Schema.optional(Schema.String.annotations({ title: 'Input Node ID' })),
|
|
167
|
+
|
|
168
|
+
// TODO(burdon): NO BOOLEAN PROPERTIES (enabld/disabled/paused, etc.)
|
|
169
|
+
// Need lint rule; or agent rule to require PR review for "boolean" key word.
|
|
170
|
+
enabled: Schema.optional(Schema.Boolean.annotations({ title: 'Enabled' })),
|
|
171
|
+
|
|
172
|
+
spec: Schema.optional(Spec),
|
|
173
|
+
|
|
174
|
+
concurrency: Schema.optional(
|
|
175
|
+
Schema.Number.annotations({
|
|
176
|
+
title: 'Concurrency',
|
|
177
|
+
default: 1,
|
|
178
|
+
description:
|
|
179
|
+
'Maximum number of concurrent invocations of the trigger. For Feed triggers, this will process Feed items in parallel.',
|
|
180
|
+
}),
|
|
181
|
+
),
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
* Passed as the input data to the function.
|
|
185
|
+
* Must match the function's input schema.
|
|
186
|
+
*
|
|
187
|
+
* @example
|
|
188
|
+
* {
|
|
189
|
+
* item: '{{event.item}}',
|
|
190
|
+
* instructions: 'Summarize and perform entity-extraction'
|
|
191
|
+
* mailbox: { '/': 'dxn:echo:AAA:ZZZ' }
|
|
192
|
+
* }
|
|
193
|
+
*/
|
|
194
|
+
input: Schema.optional(Schema.Record({ key: Schema.String, value: Schema.Any })),
|
|
195
|
+
}).pipe(
|
|
196
|
+
Type.object({
|
|
197
|
+
typename: 'org.dxos.type.trigger',
|
|
198
|
+
version: '0.1.0',
|
|
199
|
+
}),
|
|
200
|
+
Annotation.IconAnnotation.set({ icon: 'ph--lightning--regular', hue: 'yellow' }),
|
|
201
|
+
SystemTypeAnnotation.set(true),
|
|
202
|
+
);
|
|
203
|
+
|
|
204
|
+
export interface Trigger extends Schema.Schema.Type<typeof TriggerSchema> {}
|
|
205
|
+
export const Trigger: Type.Obj<Trigger> = TriggerSchema as any;
|
|
206
|
+
|
|
207
|
+
export const make = (props: Obj.MakeProps<typeof Trigger>) => Obj.make(Trigger, props);
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import * as Schema from 'effect/Schema';
|
|
6
|
+
|
|
7
|
+
import { DXN, Obj, Ref } from '@dxos/echo';
|
|
8
|
+
|
|
9
|
+
// TODO(wittjosiah): Review this type.
|
|
10
|
+
// - Should be discriminated union.
|
|
11
|
+
// - Should be more consistent (e.g. subject vs item).
|
|
12
|
+
// - Should re-use schemas if possible.
|
|
13
|
+
|
|
14
|
+
// TODO(burdon): Reuse trigger schema from @dxos/functions (TriggerType).
|
|
15
|
+
export const EmailEvent = Schema.Struct({
|
|
16
|
+
from: Schema.String,
|
|
17
|
+
to: Schema.String,
|
|
18
|
+
subject: Schema.String,
|
|
19
|
+
created: Schema.String,
|
|
20
|
+
body: Schema.String,
|
|
21
|
+
});
|
|
22
|
+
export type EmailEvent = Schema.Schema.Type<typeof EmailEvent>;
|
|
23
|
+
|
|
24
|
+
export const QueueEvent = Schema.Struct({
|
|
25
|
+
queue: DXN.Schema,
|
|
26
|
+
item: Schema.Any,
|
|
27
|
+
cursor: Schema.String,
|
|
28
|
+
});
|
|
29
|
+
export type QueueEvent = Schema.Schema.Type<typeof QueueEvent>;
|
|
30
|
+
|
|
31
|
+
export const SubscriptionEvent = Schema.Struct({
|
|
32
|
+
/**
|
|
33
|
+
* Type of the mutation.
|
|
34
|
+
*/
|
|
35
|
+
// TODO(dmaretskyi): Specify enum.
|
|
36
|
+
type: Schema.String,
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Reference to the object that was changed or created.
|
|
40
|
+
*/
|
|
41
|
+
subject: Ref.Ref(Obj.Unknown),
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* @deprecated
|
|
45
|
+
*/
|
|
46
|
+
changedObjectId: Schema.optional(Schema.String),
|
|
47
|
+
});
|
|
48
|
+
export type SubscriptionEvent = Schema.Schema.Type<typeof SubscriptionEvent>;
|
|
49
|
+
|
|
50
|
+
export const TimerEvent = Schema.Struct({ tick: Schema.Number });
|
|
51
|
+
export type TimerEvent = Schema.Schema.Type<typeof TimerEvent>;
|
|
52
|
+
|
|
53
|
+
export const WebhookEvent = Schema.Struct({
|
|
54
|
+
url: Schema.String,
|
|
55
|
+
method: Schema.Literal('GET', 'POST'),
|
|
56
|
+
headers: Schema.Record({ key: Schema.String, value: Schema.String }),
|
|
57
|
+
bodyText: Schema.String,
|
|
58
|
+
});
|
|
59
|
+
export type WebhookEvent = Schema.Schema.Type<typeof WebhookEvent>;
|
|
60
|
+
|
|
61
|
+
export const TriggerEvent = Schema.Union(EmailEvent, QueueEvent, SubscriptionEvent, TimerEvent, WebhookEvent);
|
|
62
|
+
export type TriggerEvent = Schema.Schema.Type<typeof TriggerEvent>;
|
package/src/errors.ts
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { BaseError, type BaseErrorOptions } from '@dxos/errors';
|
|
6
|
+
|
|
7
|
+
// Errors from @dxos/operation.
|
|
8
|
+
|
|
9
|
+
export class InvokerNotInitializedError extends BaseError.extend(
|
|
10
|
+
'InvokerNotInitializedError',
|
|
11
|
+
'Invoker not initialized',
|
|
12
|
+
) {
|
|
13
|
+
constructor() {
|
|
14
|
+
super();
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export class NoHandlerError extends BaseError.extend('NoHandlerError', 'No handler found for operation. ') {
|
|
19
|
+
constructor(operationKey: string) {
|
|
20
|
+
super({ context: { operationKey } });
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// Errors from @dxos/functions.
|
|
25
|
+
|
|
26
|
+
export class ServiceNotAvailableError extends BaseError.extend('ServiceNotAvailable', 'Service not available') {
|
|
27
|
+
constructor(service: string, options?: Omit<BaseErrorOptions, 'context'>) {
|
|
28
|
+
super({ context: { service }, ...options, message: `Service not available: ${service}` });
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export class FunctionNotFoundError extends BaseError.extend('FunctionNotFound', 'Function not found') {
|
|
33
|
+
constructor(functionKey: string, options?: Omit<BaseErrorOptions, 'context'>) {
|
|
34
|
+
super({ context: { function: functionKey }, ...options });
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export class FunctionError extends BaseError.extend('FunctionError', 'Function invocation error') {}
|
|
39
|
+
|
|
40
|
+
export class InvalidOperationInputError extends BaseError.extend(
|
|
41
|
+
'InvalidOperationInput',
|
|
42
|
+
'Operation input did not match schema',
|
|
43
|
+
) {}
|
|
44
|
+
|
|
45
|
+
export class InvalidOperationOutputError extends BaseError.extend(
|
|
46
|
+
'InvalidOperationOutput',
|
|
47
|
+
'Operation output did not match schema',
|
|
48
|
+
) {}
|
|
49
|
+
|
|
50
|
+
export class TriggerStateNotFoundError extends BaseError.extend('TriggerStateNotFound', 'Trigger state not found') {}
|
package/src/index.ts
CHANGED
|
@@ -1,9 +1,19 @@
|
|
|
1
1
|
//
|
|
2
|
-
// Copyright
|
|
2
|
+
// Copyright 2026 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
export * from './
|
|
6
|
-
export * from './
|
|
7
|
-
export * from './
|
|
8
|
-
export * from './
|
|
9
|
-
export * from './
|
|
5
|
+
export * as Blueprint from './Blueprint';
|
|
6
|
+
export * as Credential from './Credential';
|
|
7
|
+
export * from './errors';
|
|
8
|
+
export * as Operation from './Operation';
|
|
9
|
+
export * as OperationHandlerSet from './OperationHandlerSet';
|
|
10
|
+
export * as OperationRegistry from './OperationRegistry';
|
|
11
|
+
export * as Process from './Process';
|
|
12
|
+
export * as Routine from './Routine';
|
|
13
|
+
export * as Script from './Script';
|
|
14
|
+
export * as ServiceResolver from './ServiceResolver';
|
|
15
|
+
export * as StorageService from './StorageService';
|
|
16
|
+
export * as Template from './Template';
|
|
17
|
+
export * as Trace from './Trace';
|
|
18
|
+
export * as Trigger from './Trigger';
|
|
19
|
+
export * as TriggerEvent from './TriggerEvent';
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import * as Schema from 'effect/Schema';
|
|
6
|
+
|
|
7
|
+
import * as Operation from '../Operation';
|
|
8
|
+
|
|
9
|
+
export const Fibonacci = Operation.make({
|
|
10
|
+
meta: {
|
|
11
|
+
key: 'org.example.function.fib',
|
|
12
|
+
name: 'Fibonacci',
|
|
13
|
+
description: 'Function that calculates a Fibonacci number',
|
|
14
|
+
},
|
|
15
|
+
input: Schema.Struct({
|
|
16
|
+
iterations: Schema.optional(Schema.Number).annotations({
|
|
17
|
+
description: 'Number of iterations',
|
|
18
|
+
default: 100_000,
|
|
19
|
+
}),
|
|
20
|
+
}),
|
|
21
|
+
output: Schema.Struct({
|
|
22
|
+
result: Schema.String,
|
|
23
|
+
}),
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
export const Reply = Operation.make({
|
|
27
|
+
meta: {
|
|
28
|
+
key: 'org.example.function.reply',
|
|
29
|
+
name: 'Reply',
|
|
30
|
+
description: 'Function that echoes the input',
|
|
31
|
+
},
|
|
32
|
+
input: Schema.Any,
|
|
33
|
+
output: Schema.Any,
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
export const Sleep = Operation.make({
|
|
37
|
+
meta: {
|
|
38
|
+
key: 'org.example.function.sleep',
|
|
39
|
+
name: 'Sleep',
|
|
40
|
+
description: 'Function that sleeps for a given amount of time',
|
|
41
|
+
},
|
|
42
|
+
input: Schema.Struct({
|
|
43
|
+
duration: Schema.optional(Schema.Number).annotations({
|
|
44
|
+
description: 'Milliseconds to sleep',
|
|
45
|
+
default: 100_000,
|
|
46
|
+
}),
|
|
47
|
+
}),
|
|
48
|
+
output: Schema.Void,
|
|
49
|
+
});
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import * as Effect from 'effect/Effect';
|
|
6
|
+
|
|
7
|
+
import * as Operation from '../Operation';
|
|
8
|
+
import { Fibonacci } from './definitions';
|
|
9
|
+
|
|
10
|
+
export default Fibonacci.pipe(
|
|
11
|
+
Operation.withHandler(
|
|
12
|
+
Effect.fn(function* ({ iterations = 100_000 }) {
|
|
13
|
+
let a = 0n;
|
|
14
|
+
let b = 1n;
|
|
15
|
+
for (let i = 0; i < iterations; i++) {
|
|
16
|
+
a += b;
|
|
17
|
+
b = a - b;
|
|
18
|
+
}
|
|
19
|
+
return { result: a.toString() };
|
|
20
|
+
}),
|
|
21
|
+
),
|
|
22
|
+
);
|
package/src/testing/index.ts
CHANGED
|
@@ -1,8 +1,16 @@
|
|
|
1
1
|
//
|
|
2
|
-
// Copyright
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
export
|
|
8
|
-
export
|
|
5
|
+
import * as OperationHandlerSet from '../OperationHandlerSet';
|
|
6
|
+
|
|
7
|
+
export { Fibonacci, Reply, Sleep } from './definitions';
|
|
8
|
+
export { default as FibonacciHandler } from './fib';
|
|
9
|
+
export { default as ReplyHandler } from './reply';
|
|
10
|
+
export { default as SleepHandler } from './sleep';
|
|
11
|
+
|
|
12
|
+
export const ExampleHandlers = OperationHandlerSet.lazy(
|
|
13
|
+
() => import('./fib'),
|
|
14
|
+
() => import('./reply'),
|
|
15
|
+
() => import('./sleep'),
|
|
16
|
+
);
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import * as Console from 'effect/Console';
|
|
6
|
+
import * as Effect from 'effect/Effect';
|
|
7
|
+
|
|
8
|
+
import * as Operation from '../Operation';
|
|
9
|
+
import { Reply } from './definitions';
|
|
10
|
+
|
|
11
|
+
export default Reply.pipe(
|
|
12
|
+
Operation.withHandler(
|
|
13
|
+
Effect.fn(function* (input) {
|
|
14
|
+
yield* Console.log('reply', { input });
|
|
15
|
+
return input;
|
|
16
|
+
}),
|
|
17
|
+
),
|
|
18
|
+
);
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import * as Effect from 'effect/Effect';
|
|
6
|
+
|
|
7
|
+
import * as Operation from '../Operation';
|
|
8
|
+
import { Sleep } from './definitions';
|
|
9
|
+
|
|
10
|
+
export default Sleep.pipe(
|
|
11
|
+
Operation.withHandler(
|
|
12
|
+
Effect.fn(function* ({ duration = 100_000 }) {
|
|
13
|
+
yield* Effect.sleep(duration);
|
|
14
|
+
}),
|
|
15
|
+
),
|
|
16
|
+
);
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2026 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { describe, test } from 'vitest';
|
|
6
|
+
|
|
7
|
+
import {
|
|
8
|
+
Blueprint,
|
|
9
|
+
Credential,
|
|
10
|
+
FunctionNotFoundError,
|
|
11
|
+
Operation,
|
|
12
|
+
OperationHandlerSet,
|
|
13
|
+
OperationRegistry,
|
|
14
|
+
Process,
|
|
15
|
+
Routine,
|
|
16
|
+
Script,
|
|
17
|
+
ServiceResolver,
|
|
18
|
+
StorageService,
|
|
19
|
+
Template,
|
|
20
|
+
Trace,
|
|
21
|
+
Trigger,
|
|
22
|
+
TriggerEvent,
|
|
23
|
+
} from './index';
|
|
24
|
+
|
|
25
|
+
describe('umbrella re-exports', () => {
|
|
26
|
+
test('top-level re-exports preserve source-package namespace nesting', ({ expect }) => {
|
|
27
|
+
// Operation primitives.
|
|
28
|
+
expect(Operation).toBeDefined();
|
|
29
|
+
expect(OperationHandlerSet).toBeDefined();
|
|
30
|
+
expect(OperationRegistry).toBeDefined();
|
|
31
|
+
|
|
32
|
+
// Blueprint primitives.
|
|
33
|
+
expect(Blueprint).toBeDefined();
|
|
34
|
+
expect(Blueprint.make).toBeTypeOf('function');
|
|
35
|
+
expect(Routine).toBeDefined();
|
|
36
|
+
expect(Template).toBeDefined();
|
|
37
|
+
|
|
38
|
+
// Function primitives.
|
|
39
|
+
expect(Process).toBeDefined();
|
|
40
|
+
expect(Trigger).toBeDefined();
|
|
41
|
+
expect(TriggerEvent).toBeDefined();
|
|
42
|
+
expect(Script).toBeDefined();
|
|
43
|
+
expect(Trace).toBeDefined();
|
|
44
|
+
expect(ServiceResolver).toBeDefined();
|
|
45
|
+
expect(StorageService).toBeDefined();
|
|
46
|
+
expect(Credential).toBeDefined();
|
|
47
|
+
|
|
48
|
+
// Error classes exported top-level.
|
|
49
|
+
expect(FunctionNotFoundError).toBeDefined();
|
|
50
|
+
});
|
|
51
|
+
});
|