@junobuild/functions 0.0.3 → 0.0.5
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 +424 -195
- package/dist/browser/index.js +1 -1
- package/dist/browser/index.js.map +4 -4
- package/dist/types/configs/assertions.d.ts +439 -0
- package/dist/types/configs/collections.config.d.ts +18 -0
- package/dist/types/configs/hooks.d.ts +505 -0
- package/dist/types/configs/{satellite.config.d.ts → satellite.env.d.ts} +6 -1
- package/dist/types/hooks/context.d.ts +475 -16
- package/dist/types/hooks/core.d.ts +26 -5
- package/dist/types/hooks/datastore.d.ts +324 -45
- package/dist/types/index.d.ts +7 -7
- package/package.json +3 -2
- package/dist/types/configs/assert.config.d.ts +0 -30
- package/dist/types/configs/collection.config.d.ts +0 -9
- package/dist/types/configs/hook.config.d.ts +0 -28
|
@@ -1,85 +1,364 @@
|
|
|
1
|
-
import
|
|
1
|
+
import * as z from 'zod';
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
* @see DocDescription
|
|
4
|
+
*/
|
|
5
|
+
export declare const DocDescriptionSchema: z.ZodString;
|
|
6
|
+
/**
|
|
7
|
+
* Represents a document description with a maximum length of 1024 characters.
|
|
6
8
|
*/
|
|
7
|
-
export
|
|
9
|
+
export type DocDescription = z.infer<typeof DocDescriptionSchema>;
|
|
10
|
+
/**
|
|
11
|
+
* @see Doc
|
|
12
|
+
*/
|
|
13
|
+
export declare const DocSchema: z.ZodObject<{
|
|
8
14
|
/**
|
|
9
|
-
* The
|
|
10
|
-
* Undefined if this is a new document.
|
|
15
|
+
* The user who owns this document.
|
|
11
16
|
*/
|
|
12
|
-
|
|
17
|
+
owner: z.ZodType<Uint8Array<ArrayBufferLike>, z.ZodTypeDef, Uint8Array<ArrayBufferLike>>;
|
|
13
18
|
/**
|
|
14
|
-
* The
|
|
19
|
+
* The raw data of the document.
|
|
15
20
|
*/
|
|
16
|
-
|
|
17
|
-
}
|
|
18
|
-
/**
|
|
19
|
-
* Represents a validation check before setting a document.
|
|
20
|
-
*
|
|
21
|
-
* The developer can compare the `current` and `proposed` versions and
|
|
22
|
-
* throw an error if their validation fails.
|
|
23
|
-
*/
|
|
24
|
-
export interface DocAssertSet {
|
|
21
|
+
data: z.ZodType<Uint8Array<ArrayBufferLike>, z.ZodTypeDef, Uint8Array<ArrayBufferLike>>;
|
|
25
22
|
/**
|
|
26
|
-
*
|
|
27
|
-
* Undefined if this is a new document.
|
|
23
|
+
* An optional description of the document.
|
|
28
24
|
*/
|
|
29
|
-
|
|
25
|
+
description: z.ZodOptional<z.ZodString>;
|
|
30
26
|
/**
|
|
31
|
-
* The
|
|
32
|
-
|
|
27
|
+
* The timestamp when the document was first created.
|
|
28
|
+
*/
|
|
29
|
+
created_at: z.ZodBigInt;
|
|
30
|
+
/**
|
|
31
|
+
* The timestamp when the document was last updated.
|
|
33
32
|
*/
|
|
34
|
-
|
|
35
|
-
|
|
33
|
+
updated_at: z.ZodBigInt;
|
|
34
|
+
/**
|
|
35
|
+
* The version number of the document, used for consistency checks.
|
|
36
|
+
* If not provided, it's assumed to be the first version.
|
|
37
|
+
*/
|
|
38
|
+
version: z.ZodOptional<z.ZodBigInt>;
|
|
39
|
+
}, "strict", z.ZodTypeAny, {
|
|
40
|
+
owner: Uint8Array<ArrayBufferLike>;
|
|
41
|
+
data: Uint8Array<ArrayBufferLike>;
|
|
42
|
+
created_at: bigint;
|
|
43
|
+
updated_at: bigint;
|
|
44
|
+
description?: string | undefined;
|
|
45
|
+
version?: bigint | undefined;
|
|
46
|
+
}, {
|
|
47
|
+
owner: Uint8Array<ArrayBufferLike>;
|
|
48
|
+
data: Uint8Array<ArrayBufferLike>;
|
|
49
|
+
created_at: bigint;
|
|
50
|
+
updated_at: bigint;
|
|
51
|
+
description?: string | undefined;
|
|
52
|
+
version?: bigint | undefined;
|
|
53
|
+
}>;
|
|
36
54
|
/**
|
|
37
55
|
* Represents a document stored in a collection.
|
|
38
56
|
*/
|
|
39
|
-
export
|
|
57
|
+
export type Doc = z.infer<typeof DocSchema>;
|
|
58
|
+
/**
|
|
59
|
+
* @see DocUpsert
|
|
60
|
+
*/
|
|
61
|
+
export declare const DocUpsertSchema: z.ZodObject<{
|
|
40
62
|
/**
|
|
41
|
-
* The
|
|
63
|
+
* The previous version of the document before the update.
|
|
64
|
+
* Undefined if this is a new document.
|
|
42
65
|
*/
|
|
43
|
-
|
|
66
|
+
before: z.ZodOptional<z.ZodObject<{
|
|
67
|
+
/**
|
|
68
|
+
* The user who owns this document.
|
|
69
|
+
*/
|
|
70
|
+
owner: z.ZodType<Uint8Array<ArrayBufferLike>, z.ZodTypeDef, Uint8Array<ArrayBufferLike>>;
|
|
71
|
+
/**
|
|
72
|
+
* The raw data of the document.
|
|
73
|
+
*/
|
|
74
|
+
data: z.ZodType<Uint8Array<ArrayBufferLike>, z.ZodTypeDef, Uint8Array<ArrayBufferLike>>;
|
|
75
|
+
/**
|
|
76
|
+
* An optional description of the document.
|
|
77
|
+
*/
|
|
78
|
+
description: z.ZodOptional<z.ZodString>;
|
|
79
|
+
/**
|
|
80
|
+
* The timestamp when the document was first created.
|
|
81
|
+
*/
|
|
82
|
+
created_at: z.ZodBigInt;
|
|
83
|
+
/**
|
|
84
|
+
* The timestamp when the document was last updated.
|
|
85
|
+
*/
|
|
86
|
+
updated_at: z.ZodBigInt;
|
|
87
|
+
/**
|
|
88
|
+
* The version number of the document, used for consistency checks.
|
|
89
|
+
* If not provided, it's assumed to be the first version.
|
|
90
|
+
*/
|
|
91
|
+
version: z.ZodOptional<z.ZodBigInt>;
|
|
92
|
+
}, "strict", z.ZodTypeAny, {
|
|
93
|
+
owner: Uint8Array<ArrayBufferLike>;
|
|
94
|
+
data: Uint8Array<ArrayBufferLike>;
|
|
95
|
+
created_at: bigint;
|
|
96
|
+
updated_at: bigint;
|
|
97
|
+
description?: string | undefined;
|
|
98
|
+
version?: bigint | undefined;
|
|
99
|
+
}, {
|
|
100
|
+
owner: Uint8Array<ArrayBufferLike>;
|
|
101
|
+
data: Uint8Array<ArrayBufferLike>;
|
|
102
|
+
created_at: bigint;
|
|
103
|
+
updated_at: bigint;
|
|
104
|
+
description?: string | undefined;
|
|
105
|
+
version?: bigint | undefined;
|
|
106
|
+
}>>;
|
|
107
|
+
/**
|
|
108
|
+
* The new version of the document after the update.
|
|
109
|
+
*/
|
|
110
|
+
after: z.ZodObject<{
|
|
111
|
+
/**
|
|
112
|
+
* The user who owns this document.
|
|
113
|
+
*/
|
|
114
|
+
owner: z.ZodType<Uint8Array<ArrayBufferLike>, z.ZodTypeDef, Uint8Array<ArrayBufferLike>>;
|
|
115
|
+
/**
|
|
116
|
+
* The raw data of the document.
|
|
117
|
+
*/
|
|
118
|
+
data: z.ZodType<Uint8Array<ArrayBufferLike>, z.ZodTypeDef, Uint8Array<ArrayBufferLike>>;
|
|
119
|
+
/**
|
|
120
|
+
* An optional description of the document.
|
|
121
|
+
*/
|
|
122
|
+
description: z.ZodOptional<z.ZodString>;
|
|
123
|
+
/**
|
|
124
|
+
* The timestamp when the document was first created.
|
|
125
|
+
*/
|
|
126
|
+
created_at: z.ZodBigInt;
|
|
127
|
+
/**
|
|
128
|
+
* The timestamp when the document was last updated.
|
|
129
|
+
*/
|
|
130
|
+
updated_at: z.ZodBigInt;
|
|
131
|
+
/**
|
|
132
|
+
* The version number of the document, used for consistency checks.
|
|
133
|
+
* If not provided, it's assumed to be the first version.
|
|
134
|
+
*/
|
|
135
|
+
version: z.ZodOptional<z.ZodBigInt>;
|
|
136
|
+
}, "strict", z.ZodTypeAny, {
|
|
137
|
+
owner: Uint8Array<ArrayBufferLike>;
|
|
138
|
+
data: Uint8Array<ArrayBufferLike>;
|
|
139
|
+
created_at: bigint;
|
|
140
|
+
updated_at: bigint;
|
|
141
|
+
description?: string | undefined;
|
|
142
|
+
version?: bigint | undefined;
|
|
143
|
+
}, {
|
|
144
|
+
owner: Uint8Array<ArrayBufferLike>;
|
|
145
|
+
data: Uint8Array<ArrayBufferLike>;
|
|
146
|
+
created_at: bigint;
|
|
147
|
+
updated_at: bigint;
|
|
148
|
+
description?: string | undefined;
|
|
149
|
+
version?: bigint | undefined;
|
|
150
|
+
}>;
|
|
151
|
+
}, "strict", z.ZodTypeAny, {
|
|
152
|
+
after: {
|
|
153
|
+
owner: Uint8Array<ArrayBufferLike>;
|
|
154
|
+
data: Uint8Array<ArrayBufferLike>;
|
|
155
|
+
created_at: bigint;
|
|
156
|
+
updated_at: bigint;
|
|
157
|
+
description?: string | undefined;
|
|
158
|
+
version?: bigint | undefined;
|
|
159
|
+
};
|
|
160
|
+
before?: {
|
|
161
|
+
owner: Uint8Array<ArrayBufferLike>;
|
|
162
|
+
data: Uint8Array<ArrayBufferLike>;
|
|
163
|
+
created_at: bigint;
|
|
164
|
+
updated_at: bigint;
|
|
165
|
+
description?: string | undefined;
|
|
166
|
+
version?: bigint | undefined;
|
|
167
|
+
} | undefined;
|
|
168
|
+
}, {
|
|
169
|
+
after: {
|
|
170
|
+
owner: Uint8Array<ArrayBufferLike>;
|
|
171
|
+
data: Uint8Array<ArrayBufferLike>;
|
|
172
|
+
created_at: bigint;
|
|
173
|
+
updated_at: bigint;
|
|
174
|
+
description?: string | undefined;
|
|
175
|
+
version?: bigint | undefined;
|
|
176
|
+
};
|
|
177
|
+
before?: {
|
|
178
|
+
owner: Uint8Array<ArrayBufferLike>;
|
|
179
|
+
data: Uint8Array<ArrayBufferLike>;
|
|
180
|
+
created_at: bigint;
|
|
181
|
+
updated_at: bigint;
|
|
182
|
+
description?: string | undefined;
|
|
183
|
+
version?: bigint | undefined;
|
|
184
|
+
} | undefined;
|
|
185
|
+
}>;
|
|
186
|
+
/**
|
|
187
|
+
* Represents a document update operation.
|
|
188
|
+
*
|
|
189
|
+
* This is used in hooks where a document is either being created or updated.
|
|
190
|
+
*/
|
|
191
|
+
export type DocUpsert = z.infer<typeof DocUpsertSchema>;
|
|
192
|
+
/**
|
|
193
|
+
* @see ProposedDoc
|
|
194
|
+
*/
|
|
195
|
+
export declare const ProposedDocSchema: z.ZodObject<{
|
|
44
196
|
/**
|
|
45
197
|
* The raw data of the document.
|
|
46
198
|
*/
|
|
47
|
-
data:
|
|
199
|
+
data: z.ZodType<Uint8Array<ArrayBufferLike>, z.ZodTypeDef, Uint8Array<ArrayBufferLike>>;
|
|
48
200
|
/**
|
|
49
201
|
* An optional description of the document.
|
|
50
202
|
*/
|
|
51
|
-
description
|
|
203
|
+
description: z.ZodOptional<z.ZodString>;
|
|
52
204
|
/**
|
|
53
|
-
* The
|
|
205
|
+
* The expected version number to ensure consistency.
|
|
54
206
|
*/
|
|
55
|
-
|
|
207
|
+
version: z.ZodOptional<z.ZodBigInt>;
|
|
208
|
+
}, "strict", z.ZodTypeAny, {
|
|
209
|
+
data: Uint8Array<ArrayBufferLike>;
|
|
210
|
+
description?: string | undefined;
|
|
211
|
+
version?: bigint | undefined;
|
|
212
|
+
}, {
|
|
213
|
+
data: Uint8Array<ArrayBufferLike>;
|
|
214
|
+
description?: string | undefined;
|
|
215
|
+
version?: bigint | undefined;
|
|
216
|
+
}>;
|
|
217
|
+
/**
|
|
218
|
+
* Represents the proposed version of a document.
|
|
219
|
+
* This can be validated before allowing the operation.
|
|
220
|
+
*/
|
|
221
|
+
export type ProposedDoc = z.infer<typeof ProposedDocSchema>;
|
|
222
|
+
/**
|
|
223
|
+
* @see DocAssertSet
|
|
224
|
+
*/
|
|
225
|
+
export declare const DocAssertSetSchema: z.ZodObject<{
|
|
56
226
|
/**
|
|
57
|
-
* The
|
|
227
|
+
* The current version of the document before the operation.
|
|
228
|
+
* Undefined if this is a new document.
|
|
58
229
|
*/
|
|
59
|
-
|
|
230
|
+
current: z.ZodOptional<z.ZodObject<{
|
|
231
|
+
/**
|
|
232
|
+
* The user who owns this document.
|
|
233
|
+
*/
|
|
234
|
+
owner: z.ZodType<Uint8Array<ArrayBufferLike>, z.ZodTypeDef, Uint8Array<ArrayBufferLike>>;
|
|
235
|
+
/**
|
|
236
|
+
* The raw data of the document.
|
|
237
|
+
*/
|
|
238
|
+
data: z.ZodType<Uint8Array<ArrayBufferLike>, z.ZodTypeDef, Uint8Array<ArrayBufferLike>>;
|
|
239
|
+
/**
|
|
240
|
+
* An optional description of the document.
|
|
241
|
+
*/
|
|
242
|
+
description: z.ZodOptional<z.ZodString>;
|
|
243
|
+
/**
|
|
244
|
+
* The timestamp when the document was first created.
|
|
245
|
+
*/
|
|
246
|
+
created_at: z.ZodBigInt;
|
|
247
|
+
/**
|
|
248
|
+
* The timestamp when the document was last updated.
|
|
249
|
+
*/
|
|
250
|
+
updated_at: z.ZodBigInt;
|
|
251
|
+
/**
|
|
252
|
+
* The version number of the document, used for consistency checks.
|
|
253
|
+
* If not provided, it's assumed to be the first version.
|
|
254
|
+
*/
|
|
255
|
+
version: z.ZodOptional<z.ZodBigInt>;
|
|
256
|
+
}, "strict", z.ZodTypeAny, {
|
|
257
|
+
owner: Uint8Array<ArrayBufferLike>;
|
|
258
|
+
data: Uint8Array<ArrayBufferLike>;
|
|
259
|
+
created_at: bigint;
|
|
260
|
+
updated_at: bigint;
|
|
261
|
+
description?: string | undefined;
|
|
262
|
+
version?: bigint | undefined;
|
|
263
|
+
}, {
|
|
264
|
+
owner: Uint8Array<ArrayBufferLike>;
|
|
265
|
+
data: Uint8Array<ArrayBufferLike>;
|
|
266
|
+
created_at: bigint;
|
|
267
|
+
updated_at: bigint;
|
|
268
|
+
description?: string | undefined;
|
|
269
|
+
version?: bigint | undefined;
|
|
270
|
+
}>>;
|
|
60
271
|
/**
|
|
61
|
-
* The version
|
|
62
|
-
*
|
|
272
|
+
* The proposed version of the document.
|
|
273
|
+
* This can be validated before allowing the operation.
|
|
63
274
|
*/
|
|
64
|
-
|
|
65
|
-
|
|
275
|
+
proposed: z.ZodObject<{
|
|
276
|
+
/**
|
|
277
|
+
* The raw data of the document.
|
|
278
|
+
*/
|
|
279
|
+
data: z.ZodType<Uint8Array<ArrayBufferLike>, z.ZodTypeDef, Uint8Array<ArrayBufferLike>>;
|
|
280
|
+
/**
|
|
281
|
+
* An optional description of the document.
|
|
282
|
+
*/
|
|
283
|
+
description: z.ZodOptional<z.ZodString>;
|
|
284
|
+
/**
|
|
285
|
+
* The expected version number to ensure consistency.
|
|
286
|
+
*/
|
|
287
|
+
version: z.ZodOptional<z.ZodBigInt>;
|
|
288
|
+
}, "strict", z.ZodTypeAny, {
|
|
289
|
+
data: Uint8Array<ArrayBufferLike>;
|
|
290
|
+
description?: string | undefined;
|
|
291
|
+
version?: bigint | undefined;
|
|
292
|
+
}, {
|
|
293
|
+
data: Uint8Array<ArrayBufferLike>;
|
|
294
|
+
description?: string | undefined;
|
|
295
|
+
version?: bigint | undefined;
|
|
296
|
+
}>;
|
|
297
|
+
}, "strict", z.ZodTypeAny, {
|
|
298
|
+
proposed: {
|
|
299
|
+
data: Uint8Array<ArrayBufferLike>;
|
|
300
|
+
description?: string | undefined;
|
|
301
|
+
version?: bigint | undefined;
|
|
302
|
+
};
|
|
303
|
+
current?: {
|
|
304
|
+
owner: Uint8Array<ArrayBufferLike>;
|
|
305
|
+
data: Uint8Array<ArrayBufferLike>;
|
|
306
|
+
created_at: bigint;
|
|
307
|
+
updated_at: bigint;
|
|
308
|
+
description?: string | undefined;
|
|
309
|
+
version?: bigint | undefined;
|
|
310
|
+
} | undefined;
|
|
311
|
+
}, {
|
|
312
|
+
proposed: {
|
|
313
|
+
data: Uint8Array<ArrayBufferLike>;
|
|
314
|
+
description?: string | undefined;
|
|
315
|
+
version?: bigint | undefined;
|
|
316
|
+
};
|
|
317
|
+
current?: {
|
|
318
|
+
owner: Uint8Array<ArrayBufferLike>;
|
|
319
|
+
data: Uint8Array<ArrayBufferLike>;
|
|
320
|
+
created_at: bigint;
|
|
321
|
+
updated_at: bigint;
|
|
322
|
+
description?: string | undefined;
|
|
323
|
+
version?: bigint | undefined;
|
|
324
|
+
} | undefined;
|
|
325
|
+
}>;
|
|
66
326
|
/**
|
|
67
|
-
* Represents a
|
|
327
|
+
* Represents a validation check before setting a document.
|
|
68
328
|
*
|
|
69
|
-
*
|
|
329
|
+
* The developer can compare the `current` and `proposed` versions and
|
|
330
|
+
* throw an error if their validation fails.
|
|
331
|
+
*/
|
|
332
|
+
export type DocAssertSet = z.infer<typeof DocAssertSetSchema>;
|
|
333
|
+
/**
|
|
334
|
+
* @see SetDoc
|
|
70
335
|
*/
|
|
71
|
-
export
|
|
336
|
+
export declare const SetDocSchema: z.ZodObject<{
|
|
72
337
|
/**
|
|
73
338
|
* The raw data of the document.
|
|
74
339
|
*/
|
|
75
|
-
data:
|
|
340
|
+
data: z.ZodType<Uint8Array<ArrayBufferLike>, z.ZodTypeDef, Uint8Array<ArrayBufferLike>>;
|
|
76
341
|
/**
|
|
77
342
|
* An optional description of the document.
|
|
78
343
|
*/
|
|
79
|
-
description
|
|
344
|
+
description: z.ZodOptional<z.ZodString>;
|
|
80
345
|
/**
|
|
81
346
|
* The expected version number to ensure consistency.
|
|
82
347
|
* If provided, the operation will fail if the stored version does not match.
|
|
83
348
|
*/
|
|
84
|
-
version
|
|
85
|
-
}
|
|
349
|
+
version: z.ZodOptional<z.ZodBigInt>;
|
|
350
|
+
}, "strict", z.ZodTypeAny, {
|
|
351
|
+
data: Uint8Array<ArrayBufferLike>;
|
|
352
|
+
description?: string | undefined;
|
|
353
|
+
version?: bigint | undefined;
|
|
354
|
+
}, {
|
|
355
|
+
data: Uint8Array<ArrayBufferLike>;
|
|
356
|
+
description?: string | undefined;
|
|
357
|
+
version?: bigint | undefined;
|
|
358
|
+
}>;
|
|
359
|
+
/**
|
|
360
|
+
* Represents a request to set or update a document.
|
|
361
|
+
*
|
|
362
|
+
* This is used when submitting new document data.
|
|
363
|
+
*/
|
|
364
|
+
export type SetDoc = z.infer<typeof SetDocSchema>;
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
export
|
|
2
|
-
export
|
|
3
|
-
export
|
|
4
|
-
export
|
|
5
|
-
export
|
|
6
|
-
export * from './
|
|
7
|
-
export * from './
|
|
1
|
+
export * from './configs/assertions';
|
|
2
|
+
export * from './configs/collections.config';
|
|
3
|
+
export * from './configs/hooks';
|
|
4
|
+
export * from './configs/satellite.env';
|
|
5
|
+
export * from './hooks/context';
|
|
6
|
+
export * from './hooks/core';
|
|
7
|
+
export * from './hooks/datastore';
|
|
8
8
|
export * from './sdk/datastore.sdk';
|
|
9
9
|
import './polyfills/console.polyfill';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@junobuild/functions",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.5",
|
|
4
4
|
"description": "JavaScript and TypeScript utilities for Juno Serverless Functions",
|
|
5
5
|
"author": "David Dal Busco (https://daviddalbusco.com)",
|
|
6
6
|
"license": "MIT",
|
|
@@ -37,6 +37,7 @@
|
|
|
37
37
|
},
|
|
38
38
|
"homepage": "https://juno.build",
|
|
39
39
|
"peerDependencies": {
|
|
40
|
-
"@dfinity/utils": "^2"
|
|
40
|
+
"@dfinity/utils": "^2",
|
|
41
|
+
"zod": "^3"
|
|
41
42
|
}
|
|
42
43
|
}
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import type { AssertSetDocContext } from '../hooks/context';
|
|
2
|
-
import type { CollectionsConfig } from './collection.config';
|
|
3
|
-
import type { SatelliteConfigEnv } from './satellite.config';
|
|
4
|
-
/**
|
|
5
|
-
* The generic configuration for assertion hooks that manage collections.
|
|
6
|
-
*/
|
|
7
|
-
export interface AssertAssertConfig extends CollectionsConfig {
|
|
8
|
-
assertSetDoc: never;
|
|
9
|
-
}
|
|
10
|
-
/**
|
|
11
|
-
* A configuration object that includes the `assertSetDoc` function.
|
|
12
|
-
* This function is called to validate a document before it is created or updated.
|
|
13
|
-
*/
|
|
14
|
-
export interface AssertSetDocConfig extends Omit<AssertAssertConfig, 'assertSetDoc'> {
|
|
15
|
-
/**
|
|
16
|
-
* A function that runs synchronously before a document is set in the Datastore.
|
|
17
|
-
* This can be used to enforce your validation rules.
|
|
18
|
-
*
|
|
19
|
-
* @param {AssertSetDocContext} context - Provides details about the document being validated.
|
|
20
|
-
* @throws {Error} If your validation fails, throw an exception to prevent the document from being saved.
|
|
21
|
-
*
|
|
22
|
-
*/
|
|
23
|
-
assertSetDoc: (context: AssertSetDocContext) => void;
|
|
24
|
-
}
|
|
25
|
-
export type AssertConfig = AssertSetDocConfig;
|
|
26
|
-
export type AssertFn = (config: SatelliteConfigEnv) => AssertConfig;
|
|
27
|
-
export type AssertFnOrObject = AssertConfig | AssertFn;
|
|
28
|
-
export declare function defineAssert(config: AssertConfig): AssertConfig;
|
|
29
|
-
export declare function defineAssert(config: AssertFn): AssertFn;
|
|
30
|
-
export declare function defineAssert(config: AssertFnOrObject): AssertFnOrObject;
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import type { OnSetDocContext } from '../hooks/context';
|
|
2
|
-
import type { CollectionsConfig } from './collection.config';
|
|
3
|
-
import type { SatelliteConfigEnv } from './satellite.config';
|
|
4
|
-
/**
|
|
5
|
-
* The generic configuration for hooks that manage collections.
|
|
6
|
-
*/
|
|
7
|
-
export interface OnHookConfig extends CollectionsConfig {
|
|
8
|
-
onSetDoc: never;
|
|
9
|
-
}
|
|
10
|
-
/**
|
|
11
|
-
* A configuration object that includes the `onSetDoc` function.
|
|
12
|
-
* This function is called when a document is created or updated.
|
|
13
|
-
*/
|
|
14
|
-
export interface OnSetDocConfig extends Omit<OnHookConfig, 'onSetDoc'> {
|
|
15
|
-
/**
|
|
16
|
-
* A function that runs when a document is set in the Datastore.
|
|
17
|
-
*
|
|
18
|
-
* @param {OnSetDocContext} context - Provides details about the document being saved.
|
|
19
|
-
* @returns {Promise<void>} Resolves when your operation is complete.
|
|
20
|
-
*/
|
|
21
|
-
onSetDoc: (context: OnSetDocContext) => Promise<void>;
|
|
22
|
-
}
|
|
23
|
-
export type HookConfig = OnSetDocConfig;
|
|
24
|
-
export type HookFn = (config: SatelliteConfigEnv) => HookConfig;
|
|
25
|
-
export type HookFnOrObject = HookConfig | HookFn;
|
|
26
|
-
export declare function defineHook(config: HookConfig): HookConfig;
|
|
27
|
-
export declare function defineHook(config: HookFn): HookFn;
|
|
28
|
-
export declare function defineHook(config: HookFnOrObject): HookFnOrObject;
|