@dxos/functions 0.7.4 → 0.7.5-feature-compute.4d9d99a
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/chunk-B3FGASHJ.mjs +125 -0
- package/dist/lib/browser/chunk-B3FGASHJ.mjs.map +7 -0
- package/dist/lib/browser/{chunk-Y2OPAP26.mjs → chunk-IP657FIW.mjs} +2 -2
- package/dist/lib/browser/chunk-PWSDZCXB.mjs +161 -0
- package/dist/lib/browser/chunk-PWSDZCXB.mjs.map +7 -0
- package/dist/lib/browser/chunk-XRCXIG74.mjs +12 -0
- package/dist/lib/browser/edge/index.mjs +21 -0
- package/dist/lib/browser/index.mjs +24 -3
- package/dist/lib/browser/index.mjs.map +1 -1
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/testing/index.mjs +5 -3
- package/dist/lib/browser/testing/index.mjs.map +1 -1
- package/dist/lib/browser/{types.mjs → types/index.mjs} +7 -2
- package/dist/lib/browser/types/index.mjs.map +7 -0
- package/dist/lib/node/chunk-2YCBLNMR.cjs +187 -0
- package/dist/lib/node/chunk-2YCBLNMR.cjs.map +7 -0
- package/dist/lib/node/{chunk-CCULBUSE.cjs → chunk-3HCN2EE6.cjs} +15 -15
- package/dist/lib/node/chunk-JEQ2X3Z6.cjs +34 -0
- package/dist/lib/node/chunk-JEQ2X3Z6.cjs.map +7 -0
- package/dist/lib/node/chunk-ZDG466QT.cjs +151 -0
- package/dist/lib/node/chunk-ZDG466QT.cjs.map +7 -0
- package/dist/lib/node/edge/index.cjs +42 -0
- package/dist/lib/node/edge/index.cjs.map +7 -0
- package/dist/lib/node/index.cjs +35 -15
- package/dist/lib/node/index.cjs.map +1 -1
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node/testing/index.cjs +11 -10
- package/dist/lib/node/testing/index.cjs.map +1 -1
- package/dist/lib/node/{types.cjs → types/index.cjs} +14 -9
- package/dist/lib/node/types/index.cjs.map +7 -0
- package/dist/lib/node-esm/chunk-CN74WOTT.mjs +125 -0
- package/dist/lib/node-esm/chunk-CN74WOTT.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-DHGBFXSZ.mjs +12 -0
- package/dist/lib/node-esm/chunk-DHGBFXSZ.mjs.map +7 -0
- package/dist/lib/node-esm/{chunk-GGGGWYP6.mjs → chunk-EK2U3CEM.mjs} +2 -2
- package/dist/lib/node-esm/chunk-WEI4UCRY.mjs +161 -0
- package/dist/lib/node-esm/chunk-WEI4UCRY.mjs.map +7 -0
- package/dist/lib/node-esm/edge/index.mjs +21 -0
- package/dist/lib/node-esm/edge/index.mjs.map +7 -0
- package/dist/lib/node-esm/index.mjs +24 -3
- package/dist/lib/node-esm/index.mjs.map +1 -1
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/lib/node-esm/testing/index.mjs +5 -3
- package/dist/lib/node-esm/testing/index.mjs.map +1 -1
- package/dist/lib/node-esm/{types.mjs → types/index.mjs} +7 -2
- package/dist/lib/node-esm/types/index.mjs.map +7 -0
- package/dist/types/src/edge/functions.d.ts +25 -0
- package/dist/types/src/edge/functions.d.ts.map +1 -0
- package/dist/types/src/edge/index.d.ts +2 -0
- package/dist/types/src/edge/index.d.ts.map +1 -0
- package/dist/types/src/index.d.ts +1 -0
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/testing/types.d.ts +3 -5
- package/dist/types/src/testing/types.d.ts.map +1 -1
- package/dist/types/src/translations.d.ts +9 -0
- package/dist/types/src/translations.d.ts.map +1 -0
- package/dist/types/src/types/index.d.ts +3 -0
- package/dist/types/src/types/index.d.ts.map +1 -0
- package/dist/types/src/types/schema.d.ts +55 -0
- package/dist/types/src/types/schema.d.ts.map +1 -0
- package/dist/types/src/{types.d.ts → types/types.d.ts} +76 -75
- package/dist/types/src/types/types.d.ts.map +1 -0
- package/dist/types/tsconfig.tsbuildinfo +1 -0
- package/package.json +27 -20
- package/src/edge/functions.ts +116 -0
- package/src/edge/index.ts +5 -0
- package/src/index.ts +1 -0
- package/src/translations.ts +15 -0
- package/src/trigger/trigger-registry.test.ts +3 -1
- package/src/types/index.ts +6 -0
- package/src/types/schema.ts +44 -0
- package/src/{types.ts → types/types.ts} +8 -0
- package/dist/lib/browser/chunk-N5D5R4Q4.mjs +0 -129
- package/dist/lib/browser/chunk-N5D5R4Q4.mjs.map +0 -7
- package/dist/lib/node/chunk-JMJCJ3SA.cjs +0 -156
- package/dist/lib/node/chunk-JMJCJ3SA.cjs.map +0 -7
- package/dist/lib/node/types.cjs.map +0 -7
- package/dist/lib/node-esm/chunk-2NACE6MJ.mjs +0 -129
- package/dist/lib/node-esm/chunk-2NACE6MJ.mjs.map +0 -7
- package/dist/types/src/types.d.ts.map +0 -1
- /package/dist/lib/browser/{chunk-Y2OPAP26.mjs.map → chunk-IP657FIW.mjs.map} +0 -0
- /package/dist/lib/browser/{types.mjs.map → chunk-XRCXIG74.mjs.map} +0 -0
- /package/dist/lib/{node-esm/types.mjs.map → browser/edge/index.mjs.map} +0 -0
- /package/dist/lib/node/{chunk-CCULBUSE.cjs.map → chunk-3HCN2EE6.cjs.map} +0 -0
- /package/dist/lib/node-esm/{chunk-GGGGWYP6.mjs.map → chunk-EK2U3CEM.mjs.map} +0 -0
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2024 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { type DID } from 'iso-did/types';
|
|
6
|
+
|
|
7
|
+
import { type Client } from '@dxos/client';
|
|
8
|
+
import { type ObjectMeta } from '@dxos/echo-schema';
|
|
9
|
+
import { EdgeHttpClient, type EdgeIdentity } from '@dxos/edge-client';
|
|
10
|
+
import { invariant } from '@dxos/invariant';
|
|
11
|
+
import type { PublicKey, SpaceId } from '@dxos/keys';
|
|
12
|
+
import { log } from '@dxos/log';
|
|
13
|
+
import { type UploadFunctionResponseBody } from '@dxos/protocols';
|
|
14
|
+
|
|
15
|
+
// TODO: use URL scheme for source?
|
|
16
|
+
const FUNCTIONS_META_KEY = 'dxos.org/service/function';
|
|
17
|
+
|
|
18
|
+
export const FUNCTIONS_PRESET_META_KEY = 'dxos.org/service/function-preset';
|
|
19
|
+
|
|
20
|
+
export type UploadWorkerArgs = {
|
|
21
|
+
client: Client;
|
|
22
|
+
name?: string;
|
|
23
|
+
source: string;
|
|
24
|
+
version: string;
|
|
25
|
+
functionId?: string;
|
|
26
|
+
spaceId: SpaceId;
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
export const uploadWorkerFunction = async ({
|
|
30
|
+
client,
|
|
31
|
+
name,
|
|
32
|
+
version,
|
|
33
|
+
source,
|
|
34
|
+
spaceId,
|
|
35
|
+
functionId,
|
|
36
|
+
}: UploadWorkerArgs): Promise<UploadFunctionResponseBody> => {
|
|
37
|
+
const edgeUrl = client.config.values.runtime?.services?.edge?.url;
|
|
38
|
+
invariant(edgeUrl, 'Edge is not configured.');
|
|
39
|
+
const edgeClient = new EdgeHttpClient(edgeUrl);
|
|
40
|
+
const edgeIdentity = createEdgeIdentity(client);
|
|
41
|
+
edgeClient.setIdentity(edgeIdentity);
|
|
42
|
+
const response = await edgeClient.uploadFunction({ spaceId, functionId }, { name, version, script: source });
|
|
43
|
+
|
|
44
|
+
log('Uploaded', {
|
|
45
|
+
functionId,
|
|
46
|
+
source,
|
|
47
|
+
name,
|
|
48
|
+
identityKey: edgeIdentity.identityKey,
|
|
49
|
+
response,
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
return response;
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
export const getUserFunctionUrlInMetadata = (meta: ObjectMeta) => {
|
|
56
|
+
return meta.keys.find((key) => key.source === FUNCTIONS_META_KEY)?.id;
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
export const setUserFunctionUrlInMetadata = (meta: ObjectMeta, functionUrl: string) => {
|
|
60
|
+
const key = meta.keys.find((key) => key.source === FUNCTIONS_META_KEY);
|
|
61
|
+
if (key) {
|
|
62
|
+
if (key.id !== functionUrl) {
|
|
63
|
+
throw new Error('Metadata mismatch');
|
|
64
|
+
}
|
|
65
|
+
} else {
|
|
66
|
+
meta.keys.push({ source: FUNCTIONS_META_KEY, id: functionUrl });
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
export const getInvocationUrl = (functionUrl: string, edgeUrl: string, options: InvocationOptions = {}) => {
|
|
71
|
+
const baseUrl = new URL('functions/', edgeUrl);
|
|
72
|
+
|
|
73
|
+
// Leading slashes cause the URL to be treated as an absolute path.
|
|
74
|
+
const relativeUrl = functionUrl.replace(/^\//, '');
|
|
75
|
+
const url = new URL(`./${relativeUrl}`, baseUrl.toString());
|
|
76
|
+
options.spaceId && url.searchParams.set('spaceId', options.spaceId);
|
|
77
|
+
options.subjectId && url.searchParams.set('subjectId', options.subjectId);
|
|
78
|
+
url.protocol = 'https';
|
|
79
|
+
return url.toString();
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
const createEdgeIdentity = (client: Client): EdgeIdentity => {
|
|
83
|
+
const identity = client.halo.identity.get();
|
|
84
|
+
const device = client.halo.device;
|
|
85
|
+
if (!identity || !device) {
|
|
86
|
+
throw new Error('Identity not available');
|
|
87
|
+
}
|
|
88
|
+
return {
|
|
89
|
+
identityKey: identity.identityKey.toHex(),
|
|
90
|
+
peerKey: device.deviceKey.toHex(),
|
|
91
|
+
presentCredentials: async ({ challenge }) => {
|
|
92
|
+
const identityService = client.services.services.IdentityService!;
|
|
93
|
+
const authCredential = await identityService.createAuthCredential();
|
|
94
|
+
return identityService.signPresentation({
|
|
95
|
+
presentation: { credentials: [authCredential] },
|
|
96
|
+
nonce: challenge,
|
|
97
|
+
});
|
|
98
|
+
},
|
|
99
|
+
};
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
export const incrementSemverPatch = (version: string): string => {
|
|
103
|
+
const [major, minor, patch] = version.split('.');
|
|
104
|
+
const patchNum = Number(patch);
|
|
105
|
+
invariant(!Number.isNaN(patchNum), 'Unexpected function version format.');
|
|
106
|
+
return [major, minor, String(patchNum + 1)].join('.');
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
export const publicKeyToDid = (key: PublicKey): DID => {
|
|
110
|
+
return `did:key:${key.toHex()}`;
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
export type InvocationOptions = {
|
|
114
|
+
spaceId?: SpaceId;
|
|
115
|
+
subjectId?: string;
|
|
116
|
+
};
|
package/src/index.ts
CHANGED
|
@@ -236,7 +236,9 @@ describe('trigger registry', () => {
|
|
|
236
236
|
const triggers = createTriggers(space, 3);
|
|
237
237
|
|
|
238
238
|
const triggerLoaded = new Trigger();
|
|
239
|
-
registry.registered.on((
|
|
239
|
+
registry.registered.on(() => {
|
|
240
|
+
triggerLoaded.wake();
|
|
241
|
+
});
|
|
240
242
|
|
|
241
243
|
const triggerRemoved = new Trigger<FunctionTrigger>();
|
|
242
244
|
registry.removed.on((fn) => {
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2024 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { JsonSchemaType, Ref, S, TypedObject } from '@dxos/echo-schema';
|
|
6
|
+
import { TextType } from '@dxos/schema';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Source script.
|
|
10
|
+
*/
|
|
11
|
+
export class ScriptType extends TypedObject({
|
|
12
|
+
typename: 'dxos.org/type/Script',
|
|
13
|
+
version: '0.1.0',
|
|
14
|
+
})({
|
|
15
|
+
// TODO(burdon): Change to URI?
|
|
16
|
+
name: S.optional(S.String),
|
|
17
|
+
description: S.optional(S.String),
|
|
18
|
+
// TODO(burdon): Change to hash of deployed content.
|
|
19
|
+
// Whether source has changed since last deploy.
|
|
20
|
+
changed: S.optional(S.Boolean),
|
|
21
|
+
source: Ref(TextType),
|
|
22
|
+
}) {}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Function deployment.
|
|
26
|
+
*/
|
|
27
|
+
// TODO(burdon): Move to core/functions.
|
|
28
|
+
export class FunctionType extends TypedObject({
|
|
29
|
+
typename: 'dxos.org/type/Function',
|
|
30
|
+
version: '0.1.0',
|
|
31
|
+
})({
|
|
32
|
+
// TODO(burdon): Rename to id/uri?
|
|
33
|
+
name: S.NonEmptyString,
|
|
34
|
+
version: S.String,
|
|
35
|
+
|
|
36
|
+
// Reference to a source script if it exists within ECHO.
|
|
37
|
+
// TODO(burdon): Don't ref ScriptType directly (core).
|
|
38
|
+
source: S.optional(Ref(ScriptType)),
|
|
39
|
+
|
|
40
|
+
inputSchema: S.optional(JsonSchemaType),
|
|
41
|
+
|
|
42
|
+
// Local binding to a function name.
|
|
43
|
+
binding: S.optional(S.String),
|
|
44
|
+
}) {}
|
|
@@ -13,6 +13,7 @@ export enum TriggerKind {
|
|
|
13
13
|
Timer = 'timer',
|
|
14
14
|
Webhook = 'webhook',
|
|
15
15
|
Subscription = 'subscription',
|
|
16
|
+
Email = 'email',
|
|
16
17
|
}
|
|
17
18
|
|
|
18
19
|
// TODO(burdon): Rename prop kind.
|
|
@@ -31,6 +32,12 @@ const TimerTriggerSchema = S.Struct({
|
|
|
31
32
|
|
|
32
33
|
export type TimerTrigger = S.Schema.Type<typeof TimerTriggerSchema>;
|
|
33
34
|
|
|
35
|
+
const EmailTriggerSchema = S.Struct({
|
|
36
|
+
type: S.Literal(TriggerKind.Email).annotations(typeLiteralAnnotations),
|
|
37
|
+
}).pipe(S.mutable);
|
|
38
|
+
|
|
39
|
+
export type EmailTrigger = S.Schema.Type<typeof EmailTriggerSchema>;
|
|
40
|
+
|
|
34
41
|
/**
|
|
35
42
|
* Webhook.
|
|
36
43
|
*/
|
|
@@ -84,6 +91,7 @@ export const TriggerSchema = S.Union(
|
|
|
84
91
|
TimerTriggerSchema,
|
|
85
92
|
WebhookTriggerSchema,
|
|
86
93
|
SubscriptionTriggerSchema,
|
|
94
|
+
EmailTriggerSchema,
|
|
87
95
|
).annotations({
|
|
88
96
|
[AST.TitleAnnotationId]: 'Trigger',
|
|
89
97
|
});
|
|
@@ -1,129 +0,0 @@
|
|
|
1
|
-
import "@dxos/node-std/globals";
|
|
2
|
-
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
3
|
-
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
4
|
-
}) : x)(function(x) {
|
|
5
|
-
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
6
|
-
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
7
|
-
});
|
|
8
|
-
|
|
9
|
-
// packages/core/functions/src/types.ts
|
|
10
|
-
import { AST, OptionsAnnotationId, RawObject, S, TypedObject } from "@dxos/echo-schema";
|
|
11
|
-
var TriggerKind;
|
|
12
|
-
(function(TriggerKind2) {
|
|
13
|
-
TriggerKind2["Timer"] = "timer";
|
|
14
|
-
TriggerKind2["Webhook"] = "webhook";
|
|
15
|
-
TriggerKind2["Subscription"] = "subscription";
|
|
16
|
-
})(TriggerKind || (TriggerKind = {}));
|
|
17
|
-
var typeLiteralAnnotations = {
|
|
18
|
-
[AST.TitleAnnotationId]: "Type"
|
|
19
|
-
};
|
|
20
|
-
var TimerTriggerSchema = S.Struct({
|
|
21
|
-
type: S.Literal("timer").annotations(typeLiteralAnnotations),
|
|
22
|
-
cron: S.String.annotations({
|
|
23
|
-
[AST.TitleAnnotationId]: "Cron",
|
|
24
|
-
[AST.ExamplesAnnotationId]: [
|
|
25
|
-
"0 0 * * *"
|
|
26
|
-
]
|
|
27
|
-
})
|
|
28
|
-
}).pipe(S.mutable);
|
|
29
|
-
var WebhookTriggerSchema = S.Struct({
|
|
30
|
-
type: S.Literal("webhook").annotations(typeLiteralAnnotations),
|
|
31
|
-
method: S.optional(S.String.annotations({
|
|
32
|
-
[AST.TitleAnnotationId]: "Method",
|
|
33
|
-
[OptionsAnnotationId]: [
|
|
34
|
-
"GET",
|
|
35
|
-
"POST"
|
|
36
|
-
]
|
|
37
|
-
})),
|
|
38
|
-
port: S.optional(S.Number.annotations({
|
|
39
|
-
[AST.TitleAnnotationId]: "Port"
|
|
40
|
-
}))
|
|
41
|
-
}).pipe(S.mutable);
|
|
42
|
-
var QuerySchema = S.Struct({
|
|
43
|
-
type: S.optional(S.String.annotations({
|
|
44
|
-
[AST.TitleAnnotationId]: "Type"
|
|
45
|
-
})),
|
|
46
|
-
props: S.optional(S.Record({
|
|
47
|
-
key: S.String,
|
|
48
|
-
value: S.Any
|
|
49
|
-
}))
|
|
50
|
-
}).annotations({
|
|
51
|
-
[AST.TitleAnnotationId]: "Query"
|
|
52
|
-
});
|
|
53
|
-
var SubscriptionTriggerSchema = S.Struct({
|
|
54
|
-
type: S.Literal("subscription").annotations(typeLiteralAnnotations),
|
|
55
|
-
// TODO(burdon): Define query DSL (from ECHO). Reconcile with Table.Query.
|
|
56
|
-
filter: QuerySchema,
|
|
57
|
-
options: S.optional(S.Struct({
|
|
58
|
-
// Watch changes to object (not just creation).
|
|
59
|
-
deep: S.optional(S.Boolean.annotations({
|
|
60
|
-
[AST.TitleAnnotationId]: "Nested"
|
|
61
|
-
})),
|
|
62
|
-
// Debounce changes (delay in ms).
|
|
63
|
-
delay: S.optional(S.Number.annotations({
|
|
64
|
-
[AST.TitleAnnotationId]: "Delay"
|
|
65
|
-
}))
|
|
66
|
-
}).annotations({
|
|
67
|
-
[AST.TitleAnnotationId]: "Options"
|
|
68
|
-
}))
|
|
69
|
-
}).pipe(S.mutable);
|
|
70
|
-
var TriggerSchema = S.Union(
|
|
71
|
-
//
|
|
72
|
-
TimerTriggerSchema,
|
|
73
|
-
WebhookTriggerSchema,
|
|
74
|
-
SubscriptionTriggerSchema
|
|
75
|
-
).annotations({
|
|
76
|
-
[AST.TitleAnnotationId]: "Trigger"
|
|
77
|
-
});
|
|
78
|
-
var FunctionTriggerSchema = S.Struct({
|
|
79
|
-
// TODO(burdon): What type does this reference.
|
|
80
|
-
function: S.optional(S.String.annotations({
|
|
81
|
-
[AST.TitleAnnotationId]: "Function"
|
|
82
|
-
})),
|
|
83
|
-
enabled: S.optional(S.Boolean.annotations({
|
|
84
|
-
[AST.TitleAnnotationId]: "Enabled"
|
|
85
|
-
})),
|
|
86
|
-
// TODO(burdon): Flatten entire schema.
|
|
87
|
-
spec: S.optional(TriggerSchema),
|
|
88
|
-
// TODO(burdon): Get meta from function.
|
|
89
|
-
// The `meta` property is merged into the event data passed to the function.
|
|
90
|
-
meta: S.optional(S.mutable(S.Record({
|
|
91
|
-
key: S.String,
|
|
92
|
-
value: S.Any
|
|
93
|
-
})))
|
|
94
|
-
});
|
|
95
|
-
var FunctionTrigger = class extends TypedObject({
|
|
96
|
-
typename: "dxos.org/type/FunctionTrigger",
|
|
97
|
-
version: "0.1.0"
|
|
98
|
-
})(FunctionTriggerSchema.fields) {
|
|
99
|
-
};
|
|
100
|
-
var FunctionDef = class extends TypedObject({
|
|
101
|
-
typename: "dxos.org/type/FunctionDef",
|
|
102
|
-
version: "0.1.0"
|
|
103
|
-
})({
|
|
104
|
-
uri: S.String,
|
|
105
|
-
description: S.optional(S.String),
|
|
106
|
-
route: S.String,
|
|
107
|
-
handler: S.String
|
|
108
|
-
}) {
|
|
109
|
-
};
|
|
110
|
-
var FunctionManifestSchema = S.Struct({
|
|
111
|
-
functions: S.optional(S.mutable(S.Array(RawObject(FunctionDef)))),
|
|
112
|
-
triggers: S.optional(S.mutable(S.Array(RawObject(FunctionTrigger))))
|
|
113
|
-
});
|
|
114
|
-
var FUNCTION_TYPES = [
|
|
115
|
-
FunctionDef,
|
|
116
|
-
FunctionTrigger
|
|
117
|
-
];
|
|
118
|
-
|
|
119
|
-
export {
|
|
120
|
-
__require,
|
|
121
|
-
TriggerKind,
|
|
122
|
-
TriggerSchema,
|
|
123
|
-
FunctionTriggerSchema,
|
|
124
|
-
FunctionTrigger,
|
|
125
|
-
FunctionDef,
|
|
126
|
-
FunctionManifestSchema,
|
|
127
|
-
FUNCTION_TYPES
|
|
128
|
-
};
|
|
129
|
-
//# sourceMappingURL=chunk-N5D5R4Q4.mjs.map
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../../src/types.ts"],
|
|
4
|
-
"sourcesContent": ["//\n// Copyright 2023 DXOS.org\n//\n\nimport { AST, OptionsAnnotationId, RawObject, S, TypedObject } from '@dxos/echo-schema';\n\n/**\n * Type discriminator for TriggerType.\n * Every spec has a type field of type TriggerKind that we can use to understand which type we're working with.\n * https://www.typescriptlang.org/docs/handbook/2/narrowing.html#discriminated-unions\n */\nexport enum TriggerKind {\n Timer = 'timer',\n Webhook = 'webhook',\n Subscription = 'subscription',\n}\n\n// TODO(burdon): Rename prop kind.\nconst typeLiteralAnnotations = { [AST.TitleAnnotationId]: 'Type' };\n\n/**\n * Cron timer.\n */\nconst TimerTriggerSchema = S.Struct({\n type: S.Literal(TriggerKind.Timer).annotations(typeLiteralAnnotations),\n cron: S.String.annotations({\n [AST.TitleAnnotationId]: 'Cron',\n [AST.ExamplesAnnotationId]: ['0 0 * * *'],\n }),\n}).pipe(S.mutable);\n\nexport type TimerTrigger = S.Schema.Type<typeof TimerTriggerSchema>;\n\n/**\n * Webhook.\n */\nconst WebhookTriggerSchema = S.Struct({\n type: S.Literal(TriggerKind.Webhook).annotations(typeLiteralAnnotations),\n method: S.optional(\n S.String.annotations({\n [AST.TitleAnnotationId]: 'Method',\n [OptionsAnnotationId]: ['GET', 'POST'],\n }),\n ),\n port: S.optional(\n S.Number.annotations({\n [AST.TitleAnnotationId]: 'Port',\n }),\n ),\n}).pipe(S.mutable);\n\nexport type WebhookTrigger = S.Schema.Type<typeof WebhookTriggerSchema>;\n\n// TODO(burdon): Use ECHO definition (from https://github.com/dxos/dxos/pull/8233).\nconst QuerySchema = S.Struct({\n type: S.optional(S.String.annotations({ [AST.TitleAnnotationId]: 'Type' })),\n props: S.optional(S.Record({ key: S.String, value: S.Any })),\n}).annotations({ [AST.TitleAnnotationId]: 'Query' });\n\n/**\n * Subscription.\n */\nconst SubscriptionTriggerSchema = S.Struct({\n type: S.Literal(TriggerKind.Subscription).annotations(typeLiteralAnnotations),\n // TODO(burdon): Define query DSL (from ECHO). Reconcile with Table.Query.\n filter: QuerySchema,\n options: S.optional(\n S.Struct({\n // Watch changes to object (not just creation).\n deep: S.optional(S.Boolean.annotations({ [AST.TitleAnnotationId]: 'Nested' })),\n // Debounce changes (delay in ms).\n delay: S.optional(S.Number.annotations({ [AST.TitleAnnotationId]: 'Delay' })),\n }).annotations({ [AST.TitleAnnotationId]: 'Options' }),\n ),\n}).pipe(S.mutable);\n\nexport type SubscriptionTrigger = S.Schema.Type<typeof SubscriptionTriggerSchema>;\n\n/**\n * Trigger schema (discriminated union).\n */\nexport const TriggerSchema = S.Union(\n //\n TimerTriggerSchema,\n WebhookTriggerSchema,\n SubscriptionTriggerSchema,\n).annotations({\n [AST.TitleAnnotationId]: 'Trigger',\n});\n\nexport type TriggerType = S.Schema.Type<typeof TriggerSchema>;\n\n/**\n * Function trigger.\n */\nexport const FunctionTriggerSchema = S.Struct({\n // TODO(burdon): What type does this reference.\n function: S.optional(S.String.annotations({ [AST.TitleAnnotationId]: 'Function' })),\n\n enabled: S.optional(S.Boolean.annotations({ [AST.TitleAnnotationId]: 'Enabled' })),\n\n // TODO(burdon): Flatten entire schema.\n spec: S.optional(TriggerSchema),\n\n // TODO(burdon): Get meta from function.\n // The `meta` property is merged into the event data passed to the function.\n meta: S.optional(S.mutable(S.Record({ key: S.String, value: S.Any }))),\n});\n\nexport type FunctionTriggerType = S.Schema.Type<typeof FunctionTriggerSchema>;\n\n/**\n * Function trigger.\n */\nexport class FunctionTrigger extends TypedObject({\n typename: 'dxos.org/type/FunctionTrigger',\n version: '0.1.0',\n})(FunctionTriggerSchema.fields) {}\n\n/**\n * Function definition.\n * @deprecated (Use dxos.org/type/Function)\n */\n// TODO(burdon): Reconcile with FunctionType.\nexport class FunctionDef extends TypedObject({\n typename: 'dxos.org/type/FunctionDef',\n version: '0.1.0',\n})({\n uri: S.String,\n description: S.optional(S.String),\n route: S.String,\n handler: S.String,\n}) {}\n\n/**\n * Function manifest file.\n */\nexport const FunctionManifestSchema = S.Struct({\n functions: S.optional(S.mutable(S.Array(RawObject(FunctionDef)))),\n triggers: S.optional(S.mutable(S.Array(RawObject(FunctionTrigger)))),\n});\n\nexport type FunctionManifest = S.Schema.Type<typeof FunctionManifestSchema>;\n\nexport const FUNCTION_TYPES = [FunctionDef, FunctionTrigger];\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;AAIA,SAASA,KAAKC,qBAAqBC,WAAWC,GAAGC,mBAAmB;;UAOxDC,cAAAA;;;;GAAAA,gBAAAA,cAAAA,CAAAA,EAAAA;AAOZ,IAAMC,yBAAyB;EAAE,CAACC,IAAIC,iBAAiB,GAAG;AAAO;AAKjE,IAAMC,qBAAqBC,EAAEC,OAAO;EAClCC,MAAMF,EAAEG,QAAO,OAAA,EAAoBC,YAAYR,sBAAAA;EAC/CS,MAAML,EAAEM,OAAOF,YAAY;IACzB,CAACP,IAAIC,iBAAiB,GAAG;IACzB,CAACD,IAAIU,oBAAoB,GAAG;MAAC;;EAC/B,CAAA;AACF,CAAA,EAAGC,KAAKR,EAAES,OAAO;AAOjB,IAAMC,uBAAuBV,EAAEC,OAAO;EACpCC,MAAMF,EAAEG,QAAO,SAAA,EAAsBC,YAAYR,sBAAAA;EACjDe,QAAQX,EAAEY,SACRZ,EAAEM,OAAOF,YAAY;IACnB,CAACP,IAAIC,iBAAiB,GAAG;IACzB,CAACe,mBAAAA,GAAsB;MAAC;MAAO;;EACjC,CAAA,CAAA;EAEFC,MAAMd,EAAEY,SACNZ,EAAEe,OAAOX,YAAY;IACnB,CAACP,IAAIC,iBAAiB,GAAG;EAC3B,CAAA,CAAA;AAEJ,CAAA,EAAGU,KAAKR,EAAES,OAAO;AAKjB,IAAMO,cAAchB,EAAEC,OAAO;EAC3BC,MAAMF,EAAEY,SAASZ,EAAEM,OAAOF,YAAY;IAAE,CAACP,IAAIC,iBAAiB,GAAG;EAAO,CAAA,CAAA;EACxEmB,OAAOjB,EAAEY,SAASZ,EAAEkB,OAAO;IAAEC,KAAKnB,EAAEM;IAAQc,OAAOpB,EAAEqB;EAAI,CAAA,CAAA;AAC3D,CAAA,EAAGjB,YAAY;EAAE,CAACP,IAAIC,iBAAiB,GAAG;AAAQ,CAAA;AAKlD,IAAMwB,4BAA4BtB,EAAEC,OAAO;EACzCC,MAAMF,EAAEG,QAAO,cAAA,EAA2BC,YAAYR,sBAAAA;;EAEtD2B,QAAQP;EACRQ,SAASxB,EAAEY,SACTZ,EAAEC,OAAO;;IAEPwB,MAAMzB,EAAEY,SAASZ,EAAE0B,QAAQtB,YAAY;MAAE,CAACP,IAAIC,iBAAiB,GAAG;IAAS,CAAA,CAAA;;IAE3E6B,OAAO3B,EAAEY,SAASZ,EAAEe,OAAOX,YAAY;MAAE,CAACP,IAAIC,iBAAiB,GAAG;IAAQ,CAAA,CAAA;EAC5E,CAAA,EAAGM,YAAY;IAAE,CAACP,IAAIC,iBAAiB,GAAG;EAAU,CAAA,CAAA;AAExD,CAAA,EAAGU,KAAKR,EAAES,OAAO;AAOV,IAAMmB,gBAAgB5B,EAAE6B;;EAE7B9B;EACAW;EACAY;AAAAA,EACAlB,YAAY;EACZ,CAACP,IAAIC,iBAAiB,GAAG;AAC3B,CAAA;AAOO,IAAMgC,wBAAwB9B,EAAEC,OAAO;;EAE5C8B,UAAU/B,EAAEY,SAASZ,EAAEM,OAAOF,YAAY;IAAE,CAACP,IAAIC,iBAAiB,GAAG;EAAW,CAAA,CAAA;EAEhFkC,SAAShC,EAAEY,SAASZ,EAAE0B,QAAQtB,YAAY;IAAE,CAACP,IAAIC,iBAAiB,GAAG;EAAU,CAAA,CAAA;;EAG/EmC,MAAMjC,EAAEY,SAASgB,aAAAA;;;EAIjBM,MAAMlC,EAAEY,SAASZ,EAAES,QAAQT,EAAEkB,OAAO;IAAEC,KAAKnB,EAAEM;IAAQc,OAAOpB,EAAEqB;EAAI,CAAA,CAAA,CAAA;AACpE,CAAA;AAOO,IAAMc,kBAAN,cAA8BC,YAAY;EAC/CC,UAAU;EACVC,SAAS;AACX,CAAA,EAAGR,sBAAsBS,MAAM,EAAA;AAAG;AAO3B,IAAMC,cAAN,cAA0BJ,YAAY;EAC3CC,UAAU;EACVC,SAAS;AACX,CAAA,EAAG;EACDG,KAAKzC,EAAEM;EACPoC,aAAa1C,EAAEY,SAASZ,EAAEM,MAAM;EAChCqC,OAAO3C,EAAEM;EACTsC,SAAS5C,EAAEM;AACb,CAAA,EAAA;AAAI;AAKG,IAAMuC,yBAAyB7C,EAAEC,OAAO;EAC7C6C,WAAW9C,EAAEY,SAASZ,EAAES,QAAQT,EAAE+C,MAAMC,UAAUR,WAAAA,CAAAA,CAAAA,CAAAA;EAClDS,UAAUjD,EAAEY,SAASZ,EAAES,QAAQT,EAAE+C,MAAMC,UAAUb,eAAAA,CAAAA,CAAAA,CAAAA;AACnD,CAAA;AAIO,IAAMe,iBAAiB;EAACV;EAAaL;;",
|
|
6
|
-
"names": ["AST", "OptionsAnnotationId", "RawObject", "S", "TypedObject", "TriggerKind", "typeLiteralAnnotations", "AST", "TitleAnnotationId", "TimerTriggerSchema", "S", "Struct", "type", "Literal", "annotations", "cron", "String", "ExamplesAnnotationId", "pipe", "mutable", "WebhookTriggerSchema", "method", "optional", "OptionsAnnotationId", "port", "Number", "QuerySchema", "props", "Record", "key", "value", "Any", "SubscriptionTriggerSchema", "filter", "options", "deep", "Boolean", "delay", "TriggerSchema", "Union", "FunctionTriggerSchema", "function", "enabled", "spec", "meta", "FunctionTrigger", "TypedObject", "typename", "version", "fields", "FunctionDef", "uri", "description", "route", "handler", "FunctionManifestSchema", "functions", "Array", "RawObject", "triggers", "FUNCTION_TYPES"]
|
|
7
|
-
}
|
|
@@ -1,156 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
var chunk_JMJCJ3SA_exports = {};
|
|
20
|
-
__export(chunk_JMJCJ3SA_exports, {
|
|
21
|
-
FUNCTION_TYPES: () => FUNCTION_TYPES,
|
|
22
|
-
FunctionDef: () => FunctionDef,
|
|
23
|
-
FunctionManifestSchema: () => FunctionManifestSchema,
|
|
24
|
-
FunctionTrigger: () => FunctionTrigger,
|
|
25
|
-
FunctionTriggerSchema: () => FunctionTriggerSchema,
|
|
26
|
-
TriggerKind: () => TriggerKind,
|
|
27
|
-
TriggerSchema: () => TriggerSchema,
|
|
28
|
-
__require: () => __require
|
|
29
|
-
});
|
|
30
|
-
module.exports = __toCommonJS(chunk_JMJCJ3SA_exports);
|
|
31
|
-
var import_echo_schema = require("@dxos/echo-schema");
|
|
32
|
-
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
33
|
-
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
34
|
-
}) : x)(function(x) {
|
|
35
|
-
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
36
|
-
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
37
|
-
});
|
|
38
|
-
var TriggerKind;
|
|
39
|
-
(function(TriggerKind2) {
|
|
40
|
-
TriggerKind2["Timer"] = "timer";
|
|
41
|
-
TriggerKind2["Webhook"] = "webhook";
|
|
42
|
-
TriggerKind2["Subscription"] = "subscription";
|
|
43
|
-
})(TriggerKind || (TriggerKind = {}));
|
|
44
|
-
var typeLiteralAnnotations = {
|
|
45
|
-
[import_echo_schema.AST.TitleAnnotationId]: "Type"
|
|
46
|
-
};
|
|
47
|
-
var TimerTriggerSchema = import_echo_schema.S.Struct({
|
|
48
|
-
type: import_echo_schema.S.Literal("timer").annotations(typeLiteralAnnotations),
|
|
49
|
-
cron: import_echo_schema.S.String.annotations({
|
|
50
|
-
[import_echo_schema.AST.TitleAnnotationId]: "Cron",
|
|
51
|
-
[import_echo_schema.AST.ExamplesAnnotationId]: [
|
|
52
|
-
"0 0 * * *"
|
|
53
|
-
]
|
|
54
|
-
})
|
|
55
|
-
}).pipe(import_echo_schema.S.mutable);
|
|
56
|
-
var WebhookTriggerSchema = import_echo_schema.S.Struct({
|
|
57
|
-
type: import_echo_schema.S.Literal("webhook").annotations(typeLiteralAnnotations),
|
|
58
|
-
method: import_echo_schema.S.optional(import_echo_schema.S.String.annotations({
|
|
59
|
-
[import_echo_schema.AST.TitleAnnotationId]: "Method",
|
|
60
|
-
[import_echo_schema.OptionsAnnotationId]: [
|
|
61
|
-
"GET",
|
|
62
|
-
"POST"
|
|
63
|
-
]
|
|
64
|
-
})),
|
|
65
|
-
port: import_echo_schema.S.optional(import_echo_schema.S.Number.annotations({
|
|
66
|
-
[import_echo_schema.AST.TitleAnnotationId]: "Port"
|
|
67
|
-
}))
|
|
68
|
-
}).pipe(import_echo_schema.S.mutable);
|
|
69
|
-
var QuerySchema = import_echo_schema.S.Struct({
|
|
70
|
-
type: import_echo_schema.S.optional(import_echo_schema.S.String.annotations({
|
|
71
|
-
[import_echo_schema.AST.TitleAnnotationId]: "Type"
|
|
72
|
-
})),
|
|
73
|
-
props: import_echo_schema.S.optional(import_echo_schema.S.Record({
|
|
74
|
-
key: import_echo_schema.S.String,
|
|
75
|
-
value: import_echo_schema.S.Any
|
|
76
|
-
}))
|
|
77
|
-
}).annotations({
|
|
78
|
-
[import_echo_schema.AST.TitleAnnotationId]: "Query"
|
|
79
|
-
});
|
|
80
|
-
var SubscriptionTriggerSchema = import_echo_schema.S.Struct({
|
|
81
|
-
type: import_echo_schema.S.Literal("subscription").annotations(typeLiteralAnnotations),
|
|
82
|
-
// TODO(burdon): Define query DSL (from ECHO). Reconcile with Table.Query.
|
|
83
|
-
filter: QuerySchema,
|
|
84
|
-
options: import_echo_schema.S.optional(import_echo_schema.S.Struct({
|
|
85
|
-
// Watch changes to object (not just creation).
|
|
86
|
-
deep: import_echo_schema.S.optional(import_echo_schema.S.Boolean.annotations({
|
|
87
|
-
[import_echo_schema.AST.TitleAnnotationId]: "Nested"
|
|
88
|
-
})),
|
|
89
|
-
// Debounce changes (delay in ms).
|
|
90
|
-
delay: import_echo_schema.S.optional(import_echo_schema.S.Number.annotations({
|
|
91
|
-
[import_echo_schema.AST.TitleAnnotationId]: "Delay"
|
|
92
|
-
}))
|
|
93
|
-
}).annotations({
|
|
94
|
-
[import_echo_schema.AST.TitleAnnotationId]: "Options"
|
|
95
|
-
}))
|
|
96
|
-
}).pipe(import_echo_schema.S.mutable);
|
|
97
|
-
var TriggerSchema = import_echo_schema.S.Union(
|
|
98
|
-
//
|
|
99
|
-
TimerTriggerSchema,
|
|
100
|
-
WebhookTriggerSchema,
|
|
101
|
-
SubscriptionTriggerSchema
|
|
102
|
-
).annotations({
|
|
103
|
-
[import_echo_schema.AST.TitleAnnotationId]: "Trigger"
|
|
104
|
-
});
|
|
105
|
-
var FunctionTriggerSchema = import_echo_schema.S.Struct({
|
|
106
|
-
// TODO(burdon): What type does this reference.
|
|
107
|
-
function: import_echo_schema.S.optional(import_echo_schema.S.String.annotations({
|
|
108
|
-
[import_echo_schema.AST.TitleAnnotationId]: "Function"
|
|
109
|
-
})),
|
|
110
|
-
enabled: import_echo_schema.S.optional(import_echo_schema.S.Boolean.annotations({
|
|
111
|
-
[import_echo_schema.AST.TitleAnnotationId]: "Enabled"
|
|
112
|
-
})),
|
|
113
|
-
// TODO(burdon): Flatten entire schema.
|
|
114
|
-
spec: import_echo_schema.S.optional(TriggerSchema),
|
|
115
|
-
// TODO(burdon): Get meta from function.
|
|
116
|
-
// The `meta` property is merged into the event data passed to the function.
|
|
117
|
-
meta: import_echo_schema.S.optional(import_echo_schema.S.mutable(import_echo_schema.S.Record({
|
|
118
|
-
key: import_echo_schema.S.String,
|
|
119
|
-
value: import_echo_schema.S.Any
|
|
120
|
-
})))
|
|
121
|
-
});
|
|
122
|
-
var FunctionTrigger = class extends (0, import_echo_schema.TypedObject)({
|
|
123
|
-
typename: "dxos.org/type/FunctionTrigger",
|
|
124
|
-
version: "0.1.0"
|
|
125
|
-
})(FunctionTriggerSchema.fields) {
|
|
126
|
-
};
|
|
127
|
-
var FunctionDef = class extends (0, import_echo_schema.TypedObject)({
|
|
128
|
-
typename: "dxos.org/type/FunctionDef",
|
|
129
|
-
version: "0.1.0"
|
|
130
|
-
})({
|
|
131
|
-
uri: import_echo_schema.S.String,
|
|
132
|
-
description: import_echo_schema.S.optional(import_echo_schema.S.String),
|
|
133
|
-
route: import_echo_schema.S.String,
|
|
134
|
-
handler: import_echo_schema.S.String
|
|
135
|
-
}) {
|
|
136
|
-
};
|
|
137
|
-
var FunctionManifestSchema = import_echo_schema.S.Struct({
|
|
138
|
-
functions: import_echo_schema.S.optional(import_echo_schema.S.mutable(import_echo_schema.S.Array((0, import_echo_schema.RawObject)(FunctionDef)))),
|
|
139
|
-
triggers: import_echo_schema.S.optional(import_echo_schema.S.mutable(import_echo_schema.S.Array((0, import_echo_schema.RawObject)(FunctionTrigger))))
|
|
140
|
-
});
|
|
141
|
-
var FUNCTION_TYPES = [
|
|
142
|
-
FunctionDef,
|
|
143
|
-
FunctionTrigger
|
|
144
|
-
];
|
|
145
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
146
|
-
0 && (module.exports = {
|
|
147
|
-
FUNCTION_TYPES,
|
|
148
|
-
FunctionDef,
|
|
149
|
-
FunctionManifestSchema,
|
|
150
|
-
FunctionTrigger,
|
|
151
|
-
FunctionTriggerSchema,
|
|
152
|
-
TriggerKind,
|
|
153
|
-
TriggerSchema,
|
|
154
|
-
__require
|
|
155
|
-
});
|
|
156
|
-
//# sourceMappingURL=chunk-JMJCJ3SA.cjs.map
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../../src/types.ts"],
|
|
4
|
-
"sourcesContent": ["//\n// Copyright 2023 DXOS.org\n//\n\nimport { AST, OptionsAnnotationId, RawObject, S, TypedObject } from '@dxos/echo-schema';\n\n/**\n * Type discriminator for TriggerType.\n * Every spec has a type field of type TriggerKind that we can use to understand which type we're working with.\n * https://www.typescriptlang.org/docs/handbook/2/narrowing.html#discriminated-unions\n */\nexport enum TriggerKind {\n Timer = 'timer',\n Webhook = 'webhook',\n Subscription = 'subscription',\n}\n\n// TODO(burdon): Rename prop kind.\nconst typeLiteralAnnotations = { [AST.TitleAnnotationId]: 'Type' };\n\n/**\n * Cron timer.\n */\nconst TimerTriggerSchema = S.Struct({\n type: S.Literal(TriggerKind.Timer).annotations(typeLiteralAnnotations),\n cron: S.String.annotations({\n [AST.TitleAnnotationId]: 'Cron',\n [AST.ExamplesAnnotationId]: ['0 0 * * *'],\n }),\n}).pipe(S.mutable);\n\nexport type TimerTrigger = S.Schema.Type<typeof TimerTriggerSchema>;\n\n/**\n * Webhook.\n */\nconst WebhookTriggerSchema = S.Struct({\n type: S.Literal(TriggerKind.Webhook).annotations(typeLiteralAnnotations),\n method: S.optional(\n S.String.annotations({\n [AST.TitleAnnotationId]: 'Method',\n [OptionsAnnotationId]: ['GET', 'POST'],\n }),\n ),\n port: S.optional(\n S.Number.annotations({\n [AST.TitleAnnotationId]: 'Port',\n }),\n ),\n}).pipe(S.mutable);\n\nexport type WebhookTrigger = S.Schema.Type<typeof WebhookTriggerSchema>;\n\n// TODO(burdon): Use ECHO definition (from https://github.com/dxos/dxos/pull/8233).\nconst QuerySchema = S.Struct({\n type: S.optional(S.String.annotations({ [AST.TitleAnnotationId]: 'Type' })),\n props: S.optional(S.Record({ key: S.String, value: S.Any })),\n}).annotations({ [AST.TitleAnnotationId]: 'Query' });\n\n/**\n * Subscription.\n */\nconst SubscriptionTriggerSchema = S.Struct({\n type: S.Literal(TriggerKind.Subscription).annotations(typeLiteralAnnotations),\n // TODO(burdon): Define query DSL (from ECHO). Reconcile with Table.Query.\n filter: QuerySchema,\n options: S.optional(\n S.Struct({\n // Watch changes to object (not just creation).\n deep: S.optional(S.Boolean.annotations({ [AST.TitleAnnotationId]: 'Nested' })),\n // Debounce changes (delay in ms).\n delay: S.optional(S.Number.annotations({ [AST.TitleAnnotationId]: 'Delay' })),\n }).annotations({ [AST.TitleAnnotationId]: 'Options' }),\n ),\n}).pipe(S.mutable);\n\nexport type SubscriptionTrigger = S.Schema.Type<typeof SubscriptionTriggerSchema>;\n\n/**\n * Trigger schema (discriminated union).\n */\nexport const TriggerSchema = S.Union(\n //\n TimerTriggerSchema,\n WebhookTriggerSchema,\n SubscriptionTriggerSchema,\n).annotations({\n [AST.TitleAnnotationId]: 'Trigger',\n});\n\nexport type TriggerType = S.Schema.Type<typeof TriggerSchema>;\n\n/**\n * Function trigger.\n */\nexport const FunctionTriggerSchema = S.Struct({\n // TODO(burdon): What type does this reference.\n function: S.optional(S.String.annotations({ [AST.TitleAnnotationId]: 'Function' })),\n\n enabled: S.optional(S.Boolean.annotations({ [AST.TitleAnnotationId]: 'Enabled' })),\n\n // TODO(burdon): Flatten entire schema.\n spec: S.optional(TriggerSchema),\n\n // TODO(burdon): Get meta from function.\n // The `meta` property is merged into the event data passed to the function.\n meta: S.optional(S.mutable(S.Record({ key: S.String, value: S.Any }))),\n});\n\nexport type FunctionTriggerType = S.Schema.Type<typeof FunctionTriggerSchema>;\n\n/**\n * Function trigger.\n */\nexport class FunctionTrigger extends TypedObject({\n typename: 'dxos.org/type/FunctionTrigger',\n version: '0.1.0',\n})(FunctionTriggerSchema.fields) {}\n\n/**\n * Function definition.\n * @deprecated (Use dxos.org/type/Function)\n */\n// TODO(burdon): Reconcile with FunctionType.\nexport class FunctionDef extends TypedObject({\n typename: 'dxos.org/type/FunctionDef',\n version: '0.1.0',\n})({\n uri: S.String,\n description: S.optional(S.String),\n route: S.String,\n handler: S.String,\n}) {}\n\n/**\n * Function manifest file.\n */\nexport const FunctionManifestSchema = S.Struct({\n functions: S.optional(S.mutable(S.Array(RawObject(FunctionDef)))),\n triggers: S.optional(S.mutable(S.Array(RawObject(FunctionTrigger)))),\n});\n\nexport type FunctionManifest = S.Schema.Type<typeof FunctionManifestSchema>;\n\nexport const FUNCTION_TYPES = [FunctionDef, FunctionTrigger];\n"],
|
|
5
|
-
"mappings": "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",
|
|
6
|
-
"names": ["TriggerKind", "typeLiteralAnnotations", "AST", "TitleAnnotationId", "TimerTriggerSchema", "S", "Struct", "type", "Literal", "annotations", "cron", "String", "ExamplesAnnotationId", "pipe", "mutable", "WebhookTriggerSchema", "method", "optional", "OptionsAnnotationId", "port", "Number", "QuerySchema", "props", "Record", "key", "value", "Any", "SubscriptionTriggerSchema", "filter", "options", "deep", "Boolean", "delay", "TriggerSchema", "Union", "FunctionTriggerSchema", "function", "enabled", "spec", "meta", "FunctionTrigger", "TypedObject", "typename", "version", "fields", "FunctionDef", "uri", "description", "route", "handler", "FunctionManifestSchema", "functions", "Array", "RawObject", "triggers", "FUNCTION_TYPES"]
|
|
7
|
-
}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["types.cjs"],
|
|
4
|
-
"sourcesContent": ["import {\n FUNCTION_TYPES,\n FunctionDef,\n FunctionManifestSchema,\n FunctionTrigger,\n FunctionTriggerSchema,\n TriggerKind,\n TriggerSchema\n} from \"./chunk-JMJCJ3SA.cjs\";\nexport {\n FUNCTION_TYPES,\n FunctionDef,\n FunctionManifestSchema,\n FunctionTrigger,\n FunctionTriggerSchema,\n TriggerKind,\n TriggerSchema\n};\n//# sourceMappingURL=types.cjs.map\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,4BAQO;",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|