@dxos/functions 0.5.3-main.59db342 → 0.5.3-main.61bbff4
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 +829 -265
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node/index.cjs +817 -266
- package/dist/lib/node/index.cjs.map +4 -4
- package/dist/lib/node/meta.json +1 -1
- package/dist/types/src/handler.d.ts +33 -12
- package/dist/types/src/handler.d.ts.map +1 -1
- package/dist/types/src/index.d.ts +3 -1
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/registry/function-registry.d.ts +24 -0
- package/dist/types/src/registry/function-registry.d.ts.map +1 -0
- package/dist/types/src/registry/function-registry.test.d.ts +2 -0
- package/dist/types/src/registry/function-registry.test.d.ts.map +1 -0
- package/dist/types/src/registry/index.d.ts +2 -0
- package/dist/types/src/registry/index.d.ts.map +1 -0
- package/dist/types/src/runtime/dev-server.d.ts +15 -7
- package/dist/types/src/runtime/dev-server.d.ts.map +1 -1
- package/dist/types/src/runtime/dev-server.test.d.ts +2 -0
- package/dist/types/src/runtime/dev-server.test.d.ts.map +1 -0
- package/dist/types/src/runtime/scheduler.d.ts +14 -15
- package/dist/types/src/runtime/scheduler.d.ts.map +1 -1
- package/dist/types/src/testing/functions-integration.test.d.ts +2 -0
- package/dist/types/src/testing/functions-integration.test.d.ts.map +1 -0
- package/dist/types/src/testing/index.d.ts +4 -0
- package/dist/types/src/testing/index.d.ts.map +1 -0
- package/dist/types/src/testing/setup.d.ts +5 -0
- package/dist/types/src/testing/setup.d.ts.map +1 -0
- package/dist/types/src/testing/test/handler.d.ts +4 -0
- package/dist/types/src/testing/test/handler.d.ts.map +1 -0
- package/dist/types/src/testing/test/index.d.ts +3 -0
- package/dist/types/src/testing/test/index.d.ts.map +1 -0
- package/dist/types/src/testing/types.d.ts +9 -0
- package/dist/types/src/testing/types.d.ts.map +1 -0
- package/dist/types/src/testing/util.d.ts +3 -0
- package/dist/types/src/testing/util.d.ts.map +1 -0
- package/dist/types/src/trigger/index.d.ts +2 -0
- package/dist/types/src/trigger/index.d.ts.map +1 -0
- package/dist/types/src/trigger/trigger-registry.d.ts +40 -0
- package/dist/types/src/trigger/trigger-registry.d.ts.map +1 -0
- package/dist/types/src/trigger/trigger-registry.test.d.ts +2 -0
- package/dist/types/src/trigger/trigger-registry.test.d.ts.map +1 -0
- package/dist/types/src/trigger/type/index.d.ts +5 -0
- package/dist/types/src/trigger/type/index.d.ts.map +1 -0
- package/dist/types/src/trigger/type/subscription-trigger.d.ts +4 -0
- package/dist/types/src/trigger/type/subscription-trigger.d.ts.map +1 -0
- package/dist/types/src/trigger/type/timer-trigger.d.ts +4 -0
- package/dist/types/src/trigger/type/timer-trigger.d.ts.map +1 -0
- package/dist/types/src/trigger/type/webhook-trigger.d.ts +4 -0
- package/dist/types/src/trigger/type/webhook-trigger.d.ts.map +1 -0
- package/dist/types/src/trigger/type/websocket-trigger.d.ts +13 -0
- package/dist/types/src/trigger/type/websocket-trigger.d.ts.map +1 -0
- package/dist/types/src/types.d.ts +188 -0
- package/dist/types/src/types.d.ts.map +1 -0
- package/dist/types/tools/schema.d.ts +2 -0
- package/dist/types/tools/schema.d.ts.map +1 -0
- package/package.json +23 -11
- package/schema/functions.json +197 -0
- package/src/handler.ts +56 -26
- package/src/index.ts +3 -1
- package/src/registry/function-registry.test.ts +105 -0
- package/src/registry/function-registry.ts +84 -0
- package/src/registry/index.ts +5 -0
- package/src/runtime/dev-server.test.ts +60 -0
- package/src/runtime/dev-server.ts +104 -52
- package/src/runtime/scheduler.test.ts +154 -21
- package/src/runtime/scheduler.ts +76 -152
- package/src/testing/functions-integration.test.ts +99 -0
- package/src/testing/index.ts +7 -0
- package/src/testing/setup.ts +45 -0
- package/src/testing/test/handler.ts +15 -0
- package/src/testing/test/index.ts +7 -0
- package/src/testing/types.ts +9 -0
- package/src/testing/util.ts +16 -0
- package/src/trigger/index.ts +5 -0
- package/src/trigger/trigger-registry.test.ts +229 -0
- package/src/trigger/trigger-registry.ts +176 -0
- package/src/trigger/type/index.ts +8 -0
- package/src/trigger/type/subscription-trigger.ts +73 -0
- package/src/trigger/type/timer-trigger.ts +44 -0
- package/src/trigger/type/webhook-trigger.ts +47 -0
- package/src/trigger/type/websocket-trigger.ts +91 -0
- package/src/types.ts +101 -0
- package/dist/types/src/manifest.d.ts +0 -26
- package/dist/types/src/manifest.d.ts.map +0 -1
- package/src/manifest.ts +0 -42
package/src/types.ts
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2023 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { AST, S, TypedObject } from '@dxos/echo-schema';
|
|
6
|
+
|
|
7
|
+
// TODO(burdon): Factor out.
|
|
8
|
+
const omitEchoId = <T>(schema: S.Schema<T>): S.Schema<Omit<T, 'id'>> => S.make(AST.omit(schema.ast, ['id']));
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Type discriminator for TriggerSpec.
|
|
12
|
+
* Every spec has a type field of type FunctionTriggerType that we can use to understand which
|
|
13
|
+
* type we're working with.
|
|
14
|
+
* https://www.typescriptlang.org/docs/handbook/2/narrowing.html#discriminated-unions
|
|
15
|
+
*/
|
|
16
|
+
export type FunctionTriggerType = 'subscription' | 'timer' | 'webhook' | 'websocket';
|
|
17
|
+
|
|
18
|
+
const SubscriptionTriggerSchema = S.struct({
|
|
19
|
+
type: S.literal('subscription'),
|
|
20
|
+
// TODO(burdon): Define query DSL.
|
|
21
|
+
filter: S.array(
|
|
22
|
+
S.struct({
|
|
23
|
+
type: S.string,
|
|
24
|
+
props: S.optional(S.record(S.string, S.any)),
|
|
25
|
+
}),
|
|
26
|
+
),
|
|
27
|
+
options: S.optional(
|
|
28
|
+
S.struct({
|
|
29
|
+
// Watch changes to object (not just creation).
|
|
30
|
+
deep: S.optional(S.boolean),
|
|
31
|
+
// Debounce changes (delay in ms).
|
|
32
|
+
delay: S.optional(S.number),
|
|
33
|
+
}),
|
|
34
|
+
),
|
|
35
|
+
});
|
|
36
|
+
export type SubscriptionTrigger = S.Schema.Type<typeof SubscriptionTriggerSchema>;
|
|
37
|
+
|
|
38
|
+
const TimerTriggerSchema = S.struct({
|
|
39
|
+
type: S.literal('timer'),
|
|
40
|
+
cron: S.string,
|
|
41
|
+
});
|
|
42
|
+
export type TimerTrigger = S.Schema.Type<typeof TimerTriggerSchema>;
|
|
43
|
+
|
|
44
|
+
const WebhookTriggerSchema = S.mutable(
|
|
45
|
+
S.struct({
|
|
46
|
+
type: S.literal('webhook'),
|
|
47
|
+
method: S.string,
|
|
48
|
+
// Assigned port.
|
|
49
|
+
port: S.optional(S.number),
|
|
50
|
+
}),
|
|
51
|
+
);
|
|
52
|
+
export type WebhookTrigger = S.Schema.Type<typeof WebhookTriggerSchema>;
|
|
53
|
+
|
|
54
|
+
const WebsocketTriggerSchema = S.struct({
|
|
55
|
+
type: S.literal('websocket'),
|
|
56
|
+
url: S.string,
|
|
57
|
+
init: S.optional(S.record(S.string, S.any)),
|
|
58
|
+
});
|
|
59
|
+
export type WebsocketTrigger = S.Schema.Type<typeof WebsocketTriggerSchema>;
|
|
60
|
+
|
|
61
|
+
const TriggerSpecSchema = S.union(
|
|
62
|
+
TimerTriggerSchema,
|
|
63
|
+
WebhookTriggerSchema,
|
|
64
|
+
WebsocketTriggerSchema,
|
|
65
|
+
SubscriptionTriggerSchema,
|
|
66
|
+
);
|
|
67
|
+
export type TriggerSpec = TimerTrigger | WebhookTrigger | WebsocketTrigger | SubscriptionTrigger;
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Function definition.
|
|
71
|
+
*/
|
|
72
|
+
export class FunctionDef extends TypedObject({
|
|
73
|
+
typename: 'dxos.org/type/FunctionDef',
|
|
74
|
+
version: '0.1.0',
|
|
75
|
+
})({
|
|
76
|
+
uri: S.string,
|
|
77
|
+
description: S.optional(S.string),
|
|
78
|
+
route: S.string,
|
|
79
|
+
// TODO(burdon): NPM/GitHub/Docker/CF URL?
|
|
80
|
+
handler: S.string,
|
|
81
|
+
}) {}
|
|
82
|
+
|
|
83
|
+
export class FunctionTrigger extends TypedObject({
|
|
84
|
+
typename: 'dxos.org/type/FunctionTrigger',
|
|
85
|
+
version: '0.1.0',
|
|
86
|
+
})({
|
|
87
|
+
function: S.string.pipe(S.description('Function ID/URI.')),
|
|
88
|
+
// Context passed to a function.
|
|
89
|
+
meta: S.optional(S.record(S.string, S.any)),
|
|
90
|
+
spec: TriggerSpecSchema,
|
|
91
|
+
}) {}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Function manifest file.
|
|
95
|
+
*/
|
|
96
|
+
export const FunctionManifestSchema = S.struct({
|
|
97
|
+
functions: S.optional(S.mutable(S.array(omitEchoId(FunctionDef)))),
|
|
98
|
+
triggers: S.optional(S.mutable(S.array(omitEchoId(FunctionTrigger)))),
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
export type FunctionManifest = S.Schema.Type<typeof FunctionManifestSchema>;
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
export type FunctionDef = {
|
|
2
|
-
id: string;
|
|
3
|
-
name: string;
|
|
4
|
-
handler: string;
|
|
5
|
-
description?: string;
|
|
6
|
-
};
|
|
7
|
-
export type TriggerSubscription = {
|
|
8
|
-
type: string;
|
|
9
|
-
spaceKey: string;
|
|
10
|
-
props?: Record<string, any>;
|
|
11
|
-
deep?: boolean;
|
|
12
|
-
delay?: number;
|
|
13
|
-
};
|
|
14
|
-
export type FunctionTrigger = {
|
|
15
|
-
function: string;
|
|
16
|
-
schedule?: string;
|
|
17
|
-
subscriptions?: TriggerSubscription[];
|
|
18
|
-
};
|
|
19
|
-
/**
|
|
20
|
-
* Function manifest file.
|
|
21
|
-
*/
|
|
22
|
-
export type FunctionManifest = {
|
|
23
|
-
functions: FunctionDef[];
|
|
24
|
-
triggers: FunctionTrigger[];
|
|
25
|
-
};
|
|
26
|
-
//# sourceMappingURL=manifest.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"manifest.d.ts","sourceRoot":"","sources":["../../../src/manifest.ts"],"names":[],"mappings":"AAOA,MAAM,MAAM,WAAW,GAAG;IAExB,EAAE,EAAE,MAAM,CAAC;IAEX,IAAI,EAAE,MAAM,CAAC;IAEb,OAAO,EAAE,MAAM,CAAC;IAChB,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB,CAAC;AAGF,MAAM,MAAM,mBAAmB,GAAG;IAChC,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC5B,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB,CAAC;AAKF,MAAM,MAAM,eAAe,GAAG;IAC5B,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,aAAa,CAAC,EAAE,mBAAmB,EAAE,CAAC;CACvC,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,gBAAgB,GAAG;IAC7B,SAAS,EAAE,WAAW,EAAE,CAAC;IACzB,QAAQ,EAAE,eAAe,EAAE,CAAC;CAC7B,CAAC"}
|
package/src/manifest.ts
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright 2023 DXOS.org
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
// Lambda-like function definitions.
|
|
6
|
-
// See: https://www.serverless.com/framework/docs/providers/aws/guide/serverless.yml/#functions
|
|
7
|
-
|
|
8
|
-
export type FunctionDef = {
|
|
9
|
-
// FQ function name.
|
|
10
|
-
id: string;
|
|
11
|
-
// URL path.
|
|
12
|
-
name: string;
|
|
13
|
-
// File path of handler.
|
|
14
|
-
handler: string;
|
|
15
|
-
description?: string;
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
// TODO(burdon): Query DSL.
|
|
19
|
-
export type TriggerSubscription = {
|
|
20
|
-
type: string;
|
|
21
|
-
spaceKey: string;
|
|
22
|
-
props?: Record<string, any>;
|
|
23
|
-
deep?: boolean; // Watch changes to object (not just creation).
|
|
24
|
-
delay?: number;
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
// TODO(burdon): Generalize binding.
|
|
28
|
-
// https://www.npmjs.com/package/aws-lambda
|
|
29
|
-
// https://docs.aws.amazon.com/lambda/latest/dg/typescript-handler.html
|
|
30
|
-
export type FunctionTrigger = {
|
|
31
|
-
function: string;
|
|
32
|
-
schedule?: string;
|
|
33
|
-
subscriptions?: TriggerSubscription[];
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* Function manifest file.
|
|
38
|
-
*/
|
|
39
|
-
export type FunctionManifest = {
|
|
40
|
-
functions: FunctionDef[];
|
|
41
|
-
triggers: FunctionTrigger[];
|
|
42
|
-
};
|