@dxos/functions 0.7.0 → 0.7.1-staging.7f6f91c
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-7QJNOQ6N.mjs → chunk-FWIFI2MH.mjs} +57 -32
- package/dist/lib/browser/chunk-FWIFI2MH.mjs.map +7 -0
- package/dist/lib/browser/{chunk-L7H5DE53.mjs → chunk-QX2SGAWR.mjs} +28 -21
- package/dist/lib/browser/chunk-QX2SGAWR.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +9 -5
- package/dist/lib/browser/index.mjs.map +1 -1
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/testing/index.mjs +6 -6
- package/dist/lib/browser/testing/index.mjs.map +3 -3
- package/dist/lib/browser/types.mjs +9 -5
- package/dist/lib/node/{chunk-TNG3Z74V.cjs → chunk-GKDHAWCP.cjs} +61 -34
- package/dist/lib/node/chunk-GKDHAWCP.cjs.map +7 -0
- package/dist/lib/node/{chunk-3KJEM5VR.cjs → chunk-OKV7IWWB.cjs} +41 -34
- package/dist/lib/node/chunk-OKV7IWWB.cjs.map +7 -0
- package/dist/lib/node/index.cjs +17 -13
- package/dist/lib/node/index.cjs.map +1 -1
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node/testing/index.cjs +13 -13
- package/dist/lib/node/testing/index.cjs.map +2 -2
- package/dist/lib/node/types.cjs +11 -7
- package/dist/lib/node/types.cjs.map +2 -2
- package/dist/lib/node-esm/{chunk-DMTGUST2.mjs → chunk-SPHZ5SOR.mjs} +28 -21
- package/dist/lib/node-esm/chunk-SPHZ5SOR.mjs.map +7 -0
- package/dist/lib/node-esm/{chunk-SLC6ICH2.mjs → chunk-YSKH6PBN.mjs} +57 -32
- package/dist/lib/node-esm/chunk-YSKH6PBN.mjs.map +7 -0
- package/dist/lib/node-esm/index.mjs +9 -5
- 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 +6 -6
- package/dist/lib/node-esm/testing/index.mjs.map +3 -3
- package/dist/lib/node-esm/types.mjs +9 -5
- package/dist/types/src/trigger/trigger-registry.d.ts +3 -3
- package/dist/types/src/trigger/trigger-registry.d.ts.map +1 -1
- package/dist/types/src/types.d.ts +137 -72
- package/dist/types/src/types.d.ts.map +1 -1
- package/package.json +17 -16
- package/schema/functions.json +2 -2
- package/src/runtime/scheduler.test.ts +1 -1
- package/src/runtime/scheduler.ts +1 -1
- package/src/testing/functions-integration.test.ts +1 -1
- package/src/testing/util.ts +2 -2
- package/src/trigger/trigger-registry.test.ts +7 -9
- package/src/trigger/trigger-registry.ts +7 -8
- package/src/trigger/type/subscription-trigger.ts +2 -2
- package/src/types.ts +70 -36
- package/dist/lib/browser/chunk-7QJNOQ6N.mjs.map +0 -7
- package/dist/lib/browser/chunk-L7H5DE53.mjs.map +0 -7
- package/dist/lib/node/chunk-3KJEM5VR.cjs.map +0 -7
- package/dist/lib/node/chunk-TNG3Z74V.cjs.map +0 -7
- package/dist/lib/node-esm/chunk-DMTGUST2.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-SLC6ICH2.mjs.map +0 -7
|
@@ -1,67 +1,113 @@
|
|
|
1
1
|
import { S } from '@dxos/echo-schema';
|
|
2
2
|
/**
|
|
3
|
-
* Type discriminator for
|
|
4
|
-
* Every spec has a type field of type
|
|
5
|
-
* type we're working with.
|
|
3
|
+
* Type discriminator for TriggerType.
|
|
4
|
+
* Every spec has a type field of type TriggerKind that we can use to understand which type we're working with.
|
|
6
5
|
* https://www.typescriptlang.org/docs/handbook/2/narrowing.html#discriminated-unions
|
|
7
6
|
*/
|
|
8
|
-
export type
|
|
7
|
+
export type TriggerKind = 'timer' | 'webhook' | 'websocket' | 'subscription';
|
|
8
|
+
/**
|
|
9
|
+
* Cron timer.
|
|
10
|
+
*/
|
|
9
11
|
declare const TimerTriggerSchema: S.mutable<S.Struct<{
|
|
10
12
|
type: S.Literal<["timer"]>;
|
|
11
|
-
cron:
|
|
13
|
+
cron: S.refine<string, S.Schema<string, string, never>>;
|
|
12
14
|
}>>;
|
|
13
15
|
export type TimerTrigger = S.Schema.Type<typeof TimerTriggerSchema>;
|
|
16
|
+
/**
|
|
17
|
+
* Webhook.
|
|
18
|
+
*/
|
|
14
19
|
declare const WebhookTriggerSchema: S.mutable<S.Struct<{
|
|
15
20
|
type: S.Literal<["webhook"]>;
|
|
16
21
|
method: typeof S.String;
|
|
17
22
|
port: S.optional<typeof S.Number>;
|
|
18
23
|
}>>;
|
|
19
24
|
export type WebhookTrigger = S.Schema.Type<typeof WebhookTriggerSchema>;
|
|
25
|
+
/**
|
|
26
|
+
* Websocket.
|
|
27
|
+
* @deprecated
|
|
28
|
+
*/
|
|
20
29
|
declare const WebsocketTriggerSchema: S.mutable<S.Struct<{
|
|
21
30
|
type: S.Literal<["websocket"]>;
|
|
22
31
|
url: typeof S.String;
|
|
23
32
|
init: S.optional<S.Record$<typeof S.String, typeof S.Any>>;
|
|
24
33
|
}>>;
|
|
25
34
|
export type WebsocketTrigger = S.Schema.Type<typeof WebsocketTriggerSchema>;
|
|
35
|
+
/**
|
|
36
|
+
* Subscription.
|
|
37
|
+
*/
|
|
26
38
|
declare const SubscriptionTriggerSchema: S.mutable<S.Struct<{
|
|
27
39
|
type: S.Literal<["subscription"]>;
|
|
28
|
-
filter: S.
|
|
29
|
-
type:
|
|
40
|
+
filter: S.Struct<{
|
|
41
|
+
type: S.optional<S.SchemaClass<string, string, never>>;
|
|
30
42
|
props: S.optional<S.Record$<typeof S.String, typeof S.Any>>;
|
|
31
|
-
}
|
|
43
|
+
}>;
|
|
32
44
|
options: S.optional<S.Struct<{
|
|
33
|
-
deep: S.optional<
|
|
34
|
-
delay: S.optional<
|
|
45
|
+
deep: S.optional<S.SchemaClass<boolean, boolean, never>>;
|
|
46
|
+
delay: S.optional<S.SchemaClass<number, number, never>>;
|
|
35
47
|
}>>;
|
|
36
48
|
}>>;
|
|
37
49
|
export type SubscriptionTrigger = S.Schema.Type<typeof SubscriptionTriggerSchema>;
|
|
38
|
-
export type TriggerSpec = TimerTrigger | WebhookTrigger | WebsocketTrigger | SubscriptionTrigger;
|
|
39
|
-
declare const FunctionDef_base: import("@dxos/echo-schema").AbstractTypedObject<{
|
|
40
|
-
handler: string;
|
|
41
|
-
uri: string;
|
|
42
|
-
description?: string | undefined;
|
|
43
|
-
route: string;
|
|
44
|
-
} & {
|
|
45
|
-
id: string;
|
|
46
|
-
}, S.Struct.Encoded<{
|
|
47
|
-
uri: typeof S.String;
|
|
48
|
-
description: S.optional<typeof S.String>;
|
|
49
|
-
route: typeof S.String;
|
|
50
|
-
handler: typeof S.String;
|
|
51
|
-
}>>;
|
|
52
50
|
/**
|
|
53
|
-
*
|
|
51
|
+
* Trigger schema (discriminated union).
|
|
54
52
|
*/
|
|
55
|
-
export declare
|
|
56
|
-
|
|
53
|
+
export declare const TriggerSchema: S.Union<[S.mutable<S.Struct<{
|
|
54
|
+
type: S.Literal<["timer"]>;
|
|
55
|
+
cron: S.refine<string, S.Schema<string, string, never>>;
|
|
56
|
+
}>>, S.mutable<S.Struct<{
|
|
57
|
+
type: S.Literal<["webhook"]>;
|
|
58
|
+
method: typeof S.String;
|
|
59
|
+
port: S.optional<typeof S.Number>;
|
|
60
|
+
}>>, S.mutable<S.Struct<{
|
|
61
|
+
type: S.Literal<["websocket"]>;
|
|
62
|
+
url: typeof S.String;
|
|
63
|
+
init: S.optional<S.Record$<typeof S.String, typeof S.Any>>;
|
|
64
|
+
}>>, S.mutable<S.Struct<{
|
|
65
|
+
type: S.Literal<["subscription"]>;
|
|
66
|
+
filter: S.Struct<{
|
|
67
|
+
type: S.optional<S.SchemaClass<string, string, never>>;
|
|
68
|
+
props: S.optional<S.Record$<typeof S.String, typeof S.Any>>;
|
|
69
|
+
}>;
|
|
70
|
+
options: S.optional<S.Struct<{
|
|
71
|
+
deep: S.optional<S.SchemaClass<boolean, boolean, never>>;
|
|
72
|
+
delay: S.optional<S.SchemaClass<number, number, never>>;
|
|
73
|
+
}>>;
|
|
74
|
+
}>>]>;
|
|
75
|
+
export type TriggerType = S.Schema.Type<typeof TriggerSchema>;
|
|
76
|
+
/**
|
|
77
|
+
* Function trigger.
|
|
78
|
+
*/
|
|
79
|
+
export declare const FunctionTriggerSchema: S.Struct<{
|
|
80
|
+
function: S.optional<S.SchemaClass<string, string, never>>;
|
|
81
|
+
enabled: S.optional<S.SchemaClass<boolean, boolean, never>>;
|
|
82
|
+
spec: S.optional<S.Union<[S.mutable<S.Struct<{
|
|
83
|
+
type: S.Literal<["timer"]>;
|
|
84
|
+
cron: S.refine<string, S.Schema<string, string, never>>;
|
|
85
|
+
}>>, S.mutable<S.Struct<{
|
|
86
|
+
type: S.Literal<["webhook"]>;
|
|
87
|
+
method: typeof S.String;
|
|
88
|
+
port: S.optional<typeof S.Number>;
|
|
89
|
+
}>>, S.mutable<S.Struct<{
|
|
90
|
+
type: S.Literal<["websocket"]>;
|
|
91
|
+
url: typeof S.String;
|
|
92
|
+
init: S.optional<S.Record$<typeof S.String, typeof S.Any>>;
|
|
93
|
+
}>>, S.mutable<S.Struct<{
|
|
94
|
+
type: S.Literal<["subscription"]>;
|
|
95
|
+
filter: S.Struct<{
|
|
96
|
+
type: S.optional<S.SchemaClass<string, string, never>>;
|
|
97
|
+
props: S.optional<S.Record$<typeof S.String, typeof S.Any>>;
|
|
98
|
+
}>;
|
|
99
|
+
options: S.optional<S.Struct<{
|
|
100
|
+
deep: S.optional<S.SchemaClass<boolean, boolean, never>>;
|
|
101
|
+
delay: S.optional<S.SchemaClass<number, number, never>>;
|
|
102
|
+
}>>;
|
|
103
|
+
}>>]>>;
|
|
104
|
+
meta: S.optional<S.mutable<S.Record$<typeof S.String, typeof S.Any>>>;
|
|
105
|
+
}>;
|
|
106
|
+
export type FunctionTriggerType = S.Schema.Type<typeof FunctionTriggerSchema>;
|
|
57
107
|
declare const FunctionTrigger_base: import("@dxos/echo-schema").AbstractTypedObject<{
|
|
58
|
-
function
|
|
59
|
-
name?: string | undefined;
|
|
108
|
+
function?: string | undefined;
|
|
60
109
|
enabled?: boolean | undefined;
|
|
61
|
-
|
|
62
|
-
[x: string]: any;
|
|
63
|
-
} | undefined;
|
|
64
|
-
spec: {
|
|
110
|
+
spec?: {
|
|
65
111
|
type: "timer";
|
|
66
112
|
cron: string;
|
|
67
113
|
} | {
|
|
@@ -75,28 +121,29 @@ declare const FunctionTrigger_base: import("@dxos/echo-schema").AbstractTypedObj
|
|
|
75
121
|
readonly [x: string]: any;
|
|
76
122
|
} | undefined;
|
|
77
123
|
} | {
|
|
78
|
-
filter:
|
|
79
|
-
readonly type
|
|
124
|
+
filter: {
|
|
125
|
+
readonly type?: string | undefined;
|
|
80
126
|
readonly props?: {
|
|
81
127
|
readonly [x: string]: any;
|
|
82
128
|
} | undefined;
|
|
83
|
-
}
|
|
129
|
+
};
|
|
84
130
|
type: "subscription";
|
|
85
131
|
options?: {
|
|
86
132
|
readonly deep?: boolean | undefined;
|
|
87
133
|
readonly delay?: number | undefined;
|
|
88
134
|
} | undefined;
|
|
89
|
-
};
|
|
135
|
+
} | undefined;
|
|
136
|
+
meta?: {
|
|
137
|
+
[x: string]: any;
|
|
138
|
+
} | undefined;
|
|
90
139
|
} & {
|
|
91
140
|
id: string;
|
|
92
141
|
}, S.Struct.Encoded<{
|
|
93
|
-
|
|
94
|
-
enabled: S.optional<
|
|
95
|
-
|
|
96
|
-
meta: S.optional<S.mutable<S.Record$<typeof S.String, typeof S.Any>>>;
|
|
97
|
-
spec: S.Union<[S.mutable<S.Struct<{
|
|
142
|
+
readonly function: S.optional<S.SchemaClass<string, string, never>>;
|
|
143
|
+
readonly enabled: S.optional<S.SchemaClass<boolean, boolean, never>>;
|
|
144
|
+
readonly spec: S.optional<S.Union<[S.mutable<S.Struct<{
|
|
98
145
|
type: S.Literal<["timer"]>;
|
|
99
|
-
cron:
|
|
146
|
+
cron: S.refine<string, S.Schema<string, string, never>>;
|
|
100
147
|
}>>, S.mutable<S.Struct<{
|
|
101
148
|
type: S.Literal<["webhook"]>;
|
|
102
149
|
method: typeof S.String;
|
|
@@ -107,21 +154,41 @@ declare const FunctionTrigger_base: import("@dxos/echo-schema").AbstractTypedObj
|
|
|
107
154
|
init: S.optional<S.Record$<typeof S.String, typeof S.Any>>;
|
|
108
155
|
}>>, S.mutable<S.Struct<{
|
|
109
156
|
type: S.Literal<["subscription"]>;
|
|
110
|
-
filter: S.
|
|
111
|
-
type:
|
|
157
|
+
filter: S.Struct<{
|
|
158
|
+
type: S.optional<S.SchemaClass<string, string, never>>;
|
|
112
159
|
props: S.optional<S.Record$<typeof S.String, typeof S.Any>>;
|
|
113
|
-
}
|
|
160
|
+
}>;
|
|
114
161
|
options: S.optional<S.Struct<{
|
|
115
|
-
deep: S.optional<
|
|
116
|
-
delay: S.optional<
|
|
162
|
+
deep: S.optional<S.SchemaClass<boolean, boolean, never>>;
|
|
163
|
+
delay: S.optional<S.SchemaClass<number, number, never>>;
|
|
117
164
|
}>>;
|
|
118
|
-
}>>]
|
|
165
|
+
}>>]>>;
|
|
166
|
+
readonly meta: S.optional<S.mutable<S.Record$<typeof S.String, typeof S.Any>>>;
|
|
119
167
|
}>>;
|
|
120
168
|
/**
|
|
121
169
|
* Function trigger.
|
|
122
170
|
*/
|
|
123
171
|
export declare class FunctionTrigger extends FunctionTrigger_base {
|
|
124
172
|
}
|
|
173
|
+
declare const FunctionDef_base: import("@dxos/echo-schema").AbstractTypedObject<{
|
|
174
|
+
handler: string;
|
|
175
|
+
uri: string;
|
|
176
|
+
description?: string | undefined;
|
|
177
|
+
route: string;
|
|
178
|
+
} & {
|
|
179
|
+
id: string;
|
|
180
|
+
}, S.Struct.Encoded<{
|
|
181
|
+
uri: typeof S.String;
|
|
182
|
+
description: S.optional<typeof S.String>;
|
|
183
|
+
route: typeof S.String;
|
|
184
|
+
handler: typeof S.String;
|
|
185
|
+
}>>;
|
|
186
|
+
/**
|
|
187
|
+
* Function definition.
|
|
188
|
+
* @deprecated (Use dxos.org/type/Function)
|
|
189
|
+
*/
|
|
190
|
+
export declare class FunctionDef extends FunctionDef_base {
|
|
191
|
+
}
|
|
125
192
|
/**
|
|
126
193
|
* Function manifest file.
|
|
127
194
|
*/
|
|
@@ -140,13 +207,9 @@ export declare const FunctionManifestSchema: S.Struct<{
|
|
|
140
207
|
handler: typeof S.String;
|
|
141
208
|
}>, never>>>>;
|
|
142
209
|
triggers: S.optional<S.mutable<S.Array$<S.Schema<{
|
|
143
|
-
function
|
|
144
|
-
name?: string | undefined;
|
|
210
|
+
function?: string | undefined;
|
|
145
211
|
enabled?: boolean | undefined;
|
|
146
|
-
|
|
147
|
-
[x: string]: any;
|
|
148
|
-
} | undefined;
|
|
149
|
-
spec: {
|
|
212
|
+
spec?: {
|
|
150
213
|
type: "timer";
|
|
151
214
|
cron: string;
|
|
152
215
|
} | {
|
|
@@ -160,28 +223,29 @@ export declare const FunctionManifestSchema: S.Struct<{
|
|
|
160
223
|
readonly [x: string]: any;
|
|
161
224
|
} | undefined;
|
|
162
225
|
} | {
|
|
163
|
-
filter:
|
|
164
|
-
readonly type
|
|
226
|
+
filter: {
|
|
227
|
+
readonly type?: string | undefined;
|
|
165
228
|
readonly props?: {
|
|
166
229
|
readonly [x: string]: any;
|
|
167
230
|
} | undefined;
|
|
168
|
-
}
|
|
231
|
+
};
|
|
169
232
|
type: "subscription";
|
|
170
233
|
options?: {
|
|
171
234
|
readonly deep?: boolean | undefined;
|
|
172
235
|
readonly delay?: number | undefined;
|
|
173
236
|
} | undefined;
|
|
174
|
-
};
|
|
237
|
+
} | undefined;
|
|
238
|
+
meta?: {
|
|
239
|
+
[x: string]: any;
|
|
240
|
+
} | undefined;
|
|
175
241
|
} & {
|
|
176
242
|
"@meta"?: import("@dxos/echo-schema").ObjectMeta;
|
|
177
243
|
}, S.Struct.Encoded<{
|
|
178
|
-
|
|
179
|
-
enabled: S.optional<
|
|
180
|
-
|
|
181
|
-
meta: S.optional<S.mutable<S.Record$<typeof S.String, typeof S.Any>>>;
|
|
182
|
-
spec: S.Union<[S.mutable<S.Struct<{
|
|
244
|
+
readonly function: S.optional<S.SchemaClass<string, string, never>>;
|
|
245
|
+
readonly enabled: S.optional<S.SchemaClass<boolean, boolean, never>>;
|
|
246
|
+
readonly spec: S.optional<S.Union<[S.mutable<S.Struct<{
|
|
183
247
|
type: S.Literal<["timer"]>;
|
|
184
|
-
cron:
|
|
248
|
+
cron: S.refine<string, S.Schema<string, string, never>>;
|
|
185
249
|
}>>, S.mutable<S.Struct<{
|
|
186
250
|
type: S.Literal<["webhook"]>;
|
|
187
251
|
method: typeof S.String;
|
|
@@ -192,18 +256,19 @@ export declare const FunctionManifestSchema: S.Struct<{
|
|
|
192
256
|
init: S.optional<S.Record$<typeof S.String, typeof S.Any>>;
|
|
193
257
|
}>>, S.mutable<S.Struct<{
|
|
194
258
|
type: S.Literal<["subscription"]>;
|
|
195
|
-
filter: S.
|
|
196
|
-
type:
|
|
259
|
+
filter: S.Struct<{
|
|
260
|
+
type: S.optional<S.SchemaClass<string, string, never>>;
|
|
197
261
|
props: S.optional<S.Record$<typeof S.String, typeof S.Any>>;
|
|
198
|
-
}
|
|
262
|
+
}>;
|
|
199
263
|
options: S.optional<S.Struct<{
|
|
200
|
-
deep: S.optional<
|
|
201
|
-
delay: S.optional<
|
|
264
|
+
deep: S.optional<S.SchemaClass<boolean, boolean, never>>;
|
|
265
|
+
delay: S.optional<S.SchemaClass<number, number, never>>;
|
|
202
266
|
}>>;
|
|
203
|
-
}>>]
|
|
267
|
+
}>>]>>;
|
|
268
|
+
readonly meta: S.optional<S.mutable<S.Record$<typeof S.String, typeof S.Any>>>;
|
|
204
269
|
}>, never>>>>;
|
|
205
270
|
}>;
|
|
206
271
|
export type FunctionManifest = S.Schema.Type<typeof FunctionManifestSchema>;
|
|
207
|
-
export declare const
|
|
272
|
+
export declare const FUNCTION_TYPES: (typeof FunctionTrigger | typeof FunctionDef)[];
|
|
208
273
|
export {};
|
|
209
274
|
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/types.ts"],"names":[],"mappings":"AAIA,OAAO,
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/types.ts"],"names":[],"mappings":"AAIA,OAAO,EAAkB,CAAC,EAAe,MAAM,mBAAmB,CAAC;AAEnE;;;;GAIG;AACH,MAAM,MAAM,WAAW,GAAG,OAAO,GAAG,SAAS,GAAG,WAAW,GAAG,cAAc,CAAC;AAK7E;;GAEG;AACH,QAAA,MAAM,kBAAkB;;;GAMN,CAAC;AAEnB,MAAM,MAAM,YAAY,GAAG,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,kBAAkB,CAAC,CAAC;AAEpE;;GAEG;AACH,QAAA,MAAM,oBAAoB;;;;GAKR,CAAC;AAEnB,MAAM,MAAM,cAAc,GAAG,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,oBAAoB,CAAC,CAAC;AAExE;;;GAGG;AACH,QAAA,MAAM,sBAAsB;;;;GAIV,CAAC;AAEnB,MAAM,MAAM,gBAAgB,GAAG,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,sBAAsB,CAAC,CAAC;AAQ5E;;GAEG;AACH,QAAA,MAAM,yBAAyB;;;;;;;;;;GAYb,CAAC;AAEnB,MAAM,MAAM,mBAAmB,GAAG,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,yBAAyB,CAAC,CAAC;AAElF;;GAEG;AACH,eAAO,MAAM,aAAa;;;;;;;;;;;;;;;;;;;;;KAK2B,CAAC;AAEtD,MAAM,MAAM,WAAW,GAAG,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,aAAa,CAAC,CAAC;AAE9D;;GAEG;AACH,eAAO,MAAM,qBAAqB;;;;;;;;;;;;;;;;;;;;;;;;;;EAWhC,CAAC;AAEH,MAAM,MAAM,mBAAmB,GAAG,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,qBAAqB,CAAC,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAE9E;;GAEG;AACH,qBAAa,eAAgB,SAAQ,oBAGL;CAAG;;;;;;;;;;;;;;AAEnC;;;GAGG;AAEH,qBAAa,WAAY,SAAQ,gBAQ/B;CAAG;AAEL;;GAEG;AACH,eAAO,MAAM,sBAAsB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAGjC,CAAC;AAEH,MAAM,MAAM,gBAAgB,GAAG,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,sBAAsB,CAAC,CAAC;AAE5E,eAAO,MAAM,cAAc,iDAAiC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dxos/functions",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.1-staging.7f6f91c",
|
|
4
4
|
"description": "Functions API and runtime.",
|
|
5
5
|
"homepage": "https://dxos.org",
|
|
6
6
|
"bugs": "https://github.com/dxos/dxos/issues",
|
|
@@ -41,30 +41,31 @@
|
|
|
41
41
|
"src"
|
|
42
42
|
],
|
|
43
43
|
"dependencies": {
|
|
44
|
-
"@effect/schema": "^0.75.
|
|
44
|
+
"@effect/schema": "^0.75.5",
|
|
45
45
|
"@preact/signals-core": "^1.6.0",
|
|
46
46
|
"cron": "^3.1.6",
|
|
47
|
-
"effect": "^3.9.
|
|
47
|
+
"effect": "^3.9.2",
|
|
48
48
|
"express": "^4.19.2",
|
|
49
49
|
"get-port-please": "^3.1.1",
|
|
50
50
|
"ws": "^8.14.2",
|
|
51
|
-
"@dxos/async": "0.7.
|
|
52
|
-
"@dxos/
|
|
53
|
-
"@dxos/
|
|
54
|
-
"@dxos/echo-
|
|
55
|
-
"@dxos/echo-
|
|
56
|
-
"@dxos/echo-
|
|
57
|
-
"@dxos/
|
|
58
|
-
"@dxos/
|
|
59
|
-
"@dxos/log": "0.7.
|
|
60
|
-
"@dxos/
|
|
61
|
-
"@dxos/
|
|
62
|
-
"@dxos/
|
|
51
|
+
"@dxos/async": "0.7.1-staging.7f6f91c",
|
|
52
|
+
"@dxos/client": "0.7.1-staging.7f6f91c",
|
|
53
|
+
"@dxos/context": "0.7.1-staging.7f6f91c",
|
|
54
|
+
"@dxos/echo-protocol": "0.7.1-staging.7f6f91c",
|
|
55
|
+
"@dxos/echo-schema": "0.7.1-staging.7f6f91c",
|
|
56
|
+
"@dxos/echo-db": "0.7.1-staging.7f6f91c",
|
|
57
|
+
"@dxos/keys": "0.7.1-staging.7f6f91c",
|
|
58
|
+
"@dxos/invariant": "0.7.1-staging.7f6f91c",
|
|
59
|
+
"@dxos/log": "0.7.1-staging.7f6f91c",
|
|
60
|
+
"@dxos/protocols": "0.7.1-staging.7f6f91c",
|
|
61
|
+
"@dxos/node-std": "0.7.1-staging.7f6f91c",
|
|
62
|
+
"@dxos/schema": "0.7.1-staging.7f6f91c",
|
|
63
|
+
"@dxos/util": "0.7.1-staging.7f6f91c"
|
|
63
64
|
},
|
|
64
65
|
"devDependencies": {
|
|
65
66
|
"@types/express": "^4.17.17",
|
|
66
67
|
"@types/ws": "^7.4.0",
|
|
67
|
-
"@dxos/agent": "0.7.
|
|
68
|
+
"@dxos/agent": "0.7.1-staging.7f6f91c"
|
|
68
69
|
},
|
|
69
70
|
"publishConfig": {
|
|
70
71
|
"access": "public"
|
package/schema/functions.json
CHANGED
package/src/runtime/scheduler.ts
CHANGED
|
@@ -136,7 +136,7 @@ export class Scheduler {
|
|
|
136
136
|
if (endpoint) {
|
|
137
137
|
// TODO(burdon): Move out of scheduler (generalize as callback).
|
|
138
138
|
const url = path.join(endpoint, def.route);
|
|
139
|
-
log.info('exec', { function: def.uri, url, triggerType: trigger.spec
|
|
139
|
+
log.info('exec', { function: def.uri, url, triggerType: trigger.spec?.type });
|
|
140
140
|
const response = await fetch(url, {
|
|
141
141
|
method: 'POST',
|
|
142
142
|
headers: {
|
package/src/testing/util.ts
CHANGED
|
@@ -12,9 +12,9 @@ import { FunctionTrigger } from '../types';
|
|
|
12
12
|
|
|
13
13
|
export const triggerWebhook = async (space: Space, uri: string) => {
|
|
14
14
|
const trigger = (
|
|
15
|
-
await space.db.query(Filter.schema(FunctionTrigger, (
|
|
15
|
+
await space.db.query(Filter.schema(FunctionTrigger, (trigger: FunctionTrigger) => trigger.function === uri)).run()
|
|
16
16
|
).objects[0];
|
|
17
|
-
invariant(trigger.spec
|
|
17
|
+
invariant(trigger.spec?.type === 'webhook');
|
|
18
18
|
void fetch(`http://localhost:${trigger.spec.port}`);
|
|
19
19
|
};
|
|
20
20
|
|
|
@@ -48,11 +48,9 @@ const manifest: FunctionManifest = {
|
|
|
48
48
|
enabled: true,
|
|
49
49
|
spec: {
|
|
50
50
|
type: 'subscription',
|
|
51
|
-
filter:
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
},
|
|
55
|
-
],
|
|
51
|
+
filter: {
|
|
52
|
+
type: TestType.typename,
|
|
53
|
+
},
|
|
56
54
|
},
|
|
57
55
|
},
|
|
58
56
|
],
|
|
@@ -111,13 +109,13 @@ describe('trigger registry', () => {
|
|
|
111
109
|
|
|
112
110
|
const callbackInvoked = new Trigger();
|
|
113
111
|
const { objects: allTriggers } = await space.db.query(Filter.schema(FunctionTrigger)).run();
|
|
114
|
-
const webhookTrigger = allTriggers.find((trigger: FunctionTrigger) => trigger.spec
|
|
112
|
+
const webhookTrigger = allTriggers.find((trigger: FunctionTrigger) => trigger.spec?.type === 'webhook')!;
|
|
115
113
|
await registry.activate(space, webhookTrigger, async () => {
|
|
116
114
|
callbackInvoked.wake();
|
|
117
115
|
return 200;
|
|
118
116
|
});
|
|
119
117
|
|
|
120
|
-
setTimeout(() => triggerWebhook(space, webhookTrigger.function));
|
|
118
|
+
setTimeout(() => triggerWebhook(space, webhookTrigger.function!));
|
|
121
119
|
await callbackInvoked.wait();
|
|
122
120
|
});
|
|
123
121
|
|
|
@@ -150,7 +148,7 @@ describe('trigger registry', () => {
|
|
|
150
148
|
await waitForInactiveTriggers(registry, space);
|
|
151
149
|
|
|
152
150
|
const { objects: allTriggers } = await space.db.query(Filter.schema(FunctionTrigger)).run();
|
|
153
|
-
const echoTrigger = allTriggers.find((trigger: FunctionTrigger) => trigger.spec
|
|
151
|
+
const echoTrigger = allTriggers.find((trigger: FunctionTrigger) => trigger.spec?.type === 'subscription')!;
|
|
154
152
|
let count = 0;
|
|
155
153
|
await registry.activate(space, echoTrigger, async () => {
|
|
156
154
|
count++;
|
|
@@ -177,7 +175,7 @@ describe('trigger registry', () => {
|
|
|
177
175
|
await waitForInactiveTriggers(registry, space);
|
|
178
176
|
|
|
179
177
|
const { objects: allTriggers } = await space.db.query(Filter.schema(FunctionTrigger)).run();
|
|
180
|
-
const echoTrigger = allTriggers.find((trigger: FunctionTrigger) => trigger.spec
|
|
178
|
+
const echoTrigger = allTriggers.find((trigger: FunctionTrigger) => trigger.spec?.type === 'subscription')!;
|
|
181
179
|
let count = 0;
|
|
182
180
|
await registry.activate(space, echoTrigger, async () => {
|
|
183
181
|
count++;
|
|
@@ -12,15 +12,15 @@ import { PublicKey } from '@dxos/keys';
|
|
|
12
12
|
import { log } from '@dxos/log';
|
|
13
13
|
import { ComplexMap, diff } from '@dxos/util';
|
|
14
14
|
|
|
15
|
-
import { createSubscriptionTrigger, createTimerTrigger
|
|
16
|
-
import { type FunctionManifest, FunctionTrigger, type
|
|
15
|
+
import { createSubscriptionTrigger, createTimerTrigger } from './type';
|
|
16
|
+
import { type FunctionManifest, FunctionTrigger, type TriggerKind, type TriggerType } from '../types';
|
|
17
17
|
|
|
18
18
|
type ResponseCode = number;
|
|
19
19
|
|
|
20
20
|
export type TriggerCallback = (args: object) => Promise<ResponseCode>;
|
|
21
21
|
|
|
22
22
|
// TODO(burdon): Make object?
|
|
23
|
-
export type TriggerFactory<Spec extends
|
|
23
|
+
export type TriggerFactory<Spec extends TriggerType, Options = any> = (
|
|
24
24
|
ctx: Context,
|
|
25
25
|
space: Space,
|
|
26
26
|
spec: Spec,
|
|
@@ -28,15 +28,13 @@ export type TriggerFactory<Spec extends TriggerSpec, Options = any> = (
|
|
|
28
28
|
options?: Options,
|
|
29
29
|
) => Promise<void>;
|
|
30
30
|
|
|
31
|
-
export type TriggerFactoryMap = Record<
|
|
31
|
+
export type TriggerFactoryMap = Partial<Record<TriggerKind, TriggerFactory<any>>>;
|
|
32
32
|
|
|
33
33
|
const triggerFactory: TriggerFactoryMap = {
|
|
34
|
-
subscription: createSubscriptionTrigger,
|
|
35
34
|
timer: createTimerTrigger,
|
|
36
35
|
// TODO(burdon): Cannot use in browser.
|
|
37
36
|
// webhook: createWebhookTrigger,
|
|
38
|
-
|
|
39
|
-
websocket: createWebsocketTrigger,
|
|
37
|
+
subscription: createSubscriptionTrigger,
|
|
40
38
|
};
|
|
41
39
|
|
|
42
40
|
export type TriggerEvent = {
|
|
@@ -84,6 +82,7 @@ export class TriggerRegistry extends Resource {
|
|
|
84
82
|
|
|
85
83
|
try {
|
|
86
84
|
// Create trigger.
|
|
85
|
+
invariant(trigger.spec);
|
|
87
86
|
const options = this._options?.[trigger.spec.type];
|
|
88
87
|
const createTrigger = triggerFactory[trigger.spec.type];
|
|
89
88
|
invariant(createTrigger, `Trigger factory not found: ${trigger.spec.type}`);
|
|
@@ -112,7 +111,7 @@ export class TriggerRegistry extends Resource {
|
|
|
112
111
|
let keys = trigger[ECHO_ATTR_META]?.keys;
|
|
113
112
|
delete trigger[ECHO_ATTR_META];
|
|
114
113
|
if (!keys?.length) {
|
|
115
|
-
keys = [foreignKey('manifest', [trigger.function, trigger.spec
|
|
114
|
+
keys = [foreignKey('manifest', [trigger.function, trigger.spec?.type].join(':'))];
|
|
116
115
|
}
|
|
117
116
|
|
|
118
117
|
return create(FunctionTrigger, trigger, { keys });
|
|
@@ -73,8 +73,8 @@ export const createSubscriptionTrigger: TriggerFactory<SubscriptionTrigger> = as
|
|
|
73
73
|
// TODO(burdon): [Bug]: not updated when document is deleted (either top or hierarchically).
|
|
74
74
|
log.info('subscription', { filter });
|
|
75
75
|
// const query = triggerCtx.space.db.query(Filter.or(filter.map(({ type, props }) => Filter.typename(type, props))));
|
|
76
|
-
if (filter) {
|
|
77
|
-
const query = space.db.query(Filter.typename(filter
|
|
76
|
+
if (filter.type) {
|
|
77
|
+
const query = space.db.query(Filter.typename(filter.type, filter.props));
|
|
78
78
|
subscriptions.push(query.subscribe(delay ? debounce(update, delay) : update));
|
|
79
79
|
}
|
|
80
80
|
|