@junobuild/functions 0.0.3 → 0.0.4

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.
@@ -1,28 +1,505 @@
1
- import type { OnSetDocContext } from '../hooks/context';
2
- import type { CollectionsConfig } from './collection.config';
3
- import type { SatelliteConfigEnv } from './satellite.config';
1
+ import * as z from 'zod';
2
+ import { SatelliteConfigEnvSchema } from './satellite.config';
4
3
  /**
5
- * The generic configuration for hooks that manage collections.
4
+ * @see OnSetDocConfig
6
5
  */
7
- export interface OnHookConfig extends CollectionsConfig {
8
- onSetDoc: never;
9
- }
6
+ export declare const OnSetDocConfigSchema: z.ZodObject<z.objectUtil.extendShape<{
7
+ collections: z.ZodArray<z.ZodString, "many">;
8
+ }, {
9
+ /**
10
+ * A function that runs when the hook is triggered for the specified collections.
11
+ *
12
+ * @param {T} context - Contains information about the affected document(s).
13
+ * @returns {Promise<void>} Resolves when the operation completes.
14
+ */
15
+ run: z.ZodFunction<z.ZodTuple<[z.ZodObject<{
16
+ caller: z.ZodType<Uint8Array<ArrayBufferLike>, z.ZodTypeDef, Uint8Array<ArrayBufferLike>>;
17
+ data: z.ZodObject<{
18
+ collection: z.ZodString;
19
+ key: z.ZodString;
20
+ data: z.ZodObject<{
21
+ before: z.ZodOptional<z.ZodObject<{
22
+ owner: z.ZodType<Uint8Array<ArrayBufferLike>, z.ZodTypeDef, Uint8Array<ArrayBufferLike>>;
23
+ data: z.ZodType<Uint8Array<ArrayBuffer>, z.ZodTypeDef, Uint8Array<ArrayBuffer>>;
24
+ description: z.ZodOptional<z.ZodString>;
25
+ created_at: z.ZodBigInt;
26
+ updated_at: z.ZodBigInt;
27
+ version: z.ZodOptional<z.ZodBigInt>;
28
+ }, "strict", z.ZodTypeAny, {
29
+ owner: Uint8Array<ArrayBufferLike>;
30
+ data: Uint8Array<ArrayBuffer>;
31
+ created_at: bigint;
32
+ updated_at: bigint;
33
+ description?: string | undefined;
34
+ version?: bigint | undefined;
35
+ }, {
36
+ owner: Uint8Array<ArrayBufferLike>;
37
+ data: Uint8Array<ArrayBuffer>;
38
+ created_at: bigint;
39
+ updated_at: bigint;
40
+ description?: string | undefined;
41
+ version?: bigint | undefined;
42
+ }>>;
43
+ after: z.ZodObject<{
44
+ owner: z.ZodType<Uint8Array<ArrayBufferLike>, z.ZodTypeDef, Uint8Array<ArrayBufferLike>>;
45
+ data: z.ZodType<Uint8Array<ArrayBuffer>, z.ZodTypeDef, Uint8Array<ArrayBuffer>>;
46
+ description: z.ZodOptional<z.ZodString>;
47
+ created_at: z.ZodBigInt;
48
+ updated_at: z.ZodBigInt;
49
+ version: z.ZodOptional<z.ZodBigInt>;
50
+ }, "strict", z.ZodTypeAny, {
51
+ owner: Uint8Array<ArrayBufferLike>;
52
+ data: Uint8Array<ArrayBuffer>;
53
+ created_at: bigint;
54
+ updated_at: bigint;
55
+ description?: string | undefined;
56
+ version?: bigint | undefined;
57
+ }, {
58
+ owner: Uint8Array<ArrayBufferLike>;
59
+ data: Uint8Array<ArrayBuffer>;
60
+ created_at: bigint;
61
+ updated_at: bigint;
62
+ description?: string | undefined;
63
+ version?: bigint | undefined;
64
+ }>;
65
+ }, "strict", z.ZodTypeAny, {
66
+ after: {
67
+ owner: Uint8Array<ArrayBufferLike>;
68
+ data: Uint8Array<ArrayBuffer>;
69
+ created_at: bigint;
70
+ updated_at: bigint;
71
+ description?: string | undefined;
72
+ version?: bigint | undefined;
73
+ };
74
+ before?: {
75
+ owner: Uint8Array<ArrayBufferLike>;
76
+ data: Uint8Array<ArrayBuffer>;
77
+ created_at: bigint;
78
+ updated_at: bigint;
79
+ description?: string | undefined;
80
+ version?: bigint | undefined;
81
+ } | undefined;
82
+ }, {
83
+ after: {
84
+ owner: Uint8Array<ArrayBufferLike>;
85
+ data: Uint8Array<ArrayBuffer>;
86
+ created_at: bigint;
87
+ updated_at: bigint;
88
+ description?: string | undefined;
89
+ version?: bigint | undefined;
90
+ };
91
+ before?: {
92
+ owner: Uint8Array<ArrayBufferLike>;
93
+ data: Uint8Array<ArrayBuffer>;
94
+ created_at: bigint;
95
+ updated_at: bigint;
96
+ description?: string | undefined;
97
+ version?: bigint | undefined;
98
+ } | undefined;
99
+ }>;
100
+ }, "strict", z.ZodTypeAny, {
101
+ data: {
102
+ after: {
103
+ owner: Uint8Array<ArrayBufferLike>;
104
+ data: Uint8Array<ArrayBuffer>;
105
+ created_at: bigint;
106
+ updated_at: bigint;
107
+ description?: string | undefined;
108
+ version?: bigint | undefined;
109
+ };
110
+ before?: {
111
+ owner: Uint8Array<ArrayBufferLike>;
112
+ data: Uint8Array<ArrayBuffer>;
113
+ created_at: bigint;
114
+ updated_at: bigint;
115
+ description?: string | undefined;
116
+ version?: bigint | undefined;
117
+ } | undefined;
118
+ };
119
+ collection: string;
120
+ key: string;
121
+ }, {
122
+ data: {
123
+ after: {
124
+ owner: Uint8Array<ArrayBufferLike>;
125
+ data: Uint8Array<ArrayBuffer>;
126
+ created_at: bigint;
127
+ updated_at: bigint;
128
+ description?: string | undefined;
129
+ version?: bigint | undefined;
130
+ };
131
+ before?: {
132
+ owner: Uint8Array<ArrayBufferLike>;
133
+ data: Uint8Array<ArrayBuffer>;
134
+ created_at: bigint;
135
+ updated_at: bigint;
136
+ description?: string | undefined;
137
+ version?: bigint | undefined;
138
+ } | undefined;
139
+ };
140
+ collection: string;
141
+ key: string;
142
+ }>;
143
+ }, "strict", z.ZodTypeAny, {
144
+ data: {
145
+ data: {
146
+ after: {
147
+ owner: Uint8Array<ArrayBufferLike>;
148
+ data: Uint8Array<ArrayBuffer>;
149
+ created_at: bigint;
150
+ updated_at: bigint;
151
+ description?: string | undefined;
152
+ version?: bigint | undefined;
153
+ };
154
+ before?: {
155
+ owner: Uint8Array<ArrayBufferLike>;
156
+ data: Uint8Array<ArrayBuffer>;
157
+ created_at: bigint;
158
+ updated_at: bigint;
159
+ description?: string | undefined;
160
+ version?: bigint | undefined;
161
+ } | undefined;
162
+ };
163
+ collection: string;
164
+ key: string;
165
+ };
166
+ caller: Uint8Array<ArrayBufferLike>;
167
+ }, {
168
+ data: {
169
+ data: {
170
+ after: {
171
+ owner: Uint8Array<ArrayBufferLike>;
172
+ data: Uint8Array<ArrayBuffer>;
173
+ created_at: bigint;
174
+ updated_at: bigint;
175
+ description?: string | undefined;
176
+ version?: bigint | undefined;
177
+ };
178
+ before?: {
179
+ owner: Uint8Array<ArrayBufferLike>;
180
+ data: Uint8Array<ArrayBuffer>;
181
+ created_at: bigint;
182
+ updated_at: bigint;
183
+ description?: string | undefined;
184
+ version?: bigint | undefined;
185
+ } | undefined;
186
+ };
187
+ collection: string;
188
+ key: string;
189
+ };
190
+ caller: Uint8Array<ArrayBufferLike>;
191
+ }>], z.ZodUnknown>, z.ZodPromise<z.ZodVoid>>;
192
+ }>, "strict", z.ZodTypeAny, {
193
+ collections: string[];
194
+ run: (args_0: {
195
+ data: {
196
+ data: {
197
+ after: {
198
+ owner: Uint8Array<ArrayBufferLike>;
199
+ data: Uint8Array<ArrayBuffer>;
200
+ created_at: bigint;
201
+ updated_at: bigint;
202
+ description?: string | undefined;
203
+ version?: bigint | undefined;
204
+ };
205
+ before?: {
206
+ owner: Uint8Array<ArrayBufferLike>;
207
+ data: Uint8Array<ArrayBuffer>;
208
+ created_at: bigint;
209
+ updated_at: bigint;
210
+ description?: string | undefined;
211
+ version?: bigint | undefined;
212
+ } | undefined;
213
+ };
214
+ collection: string;
215
+ key: string;
216
+ };
217
+ caller: Uint8Array<ArrayBufferLike>;
218
+ }, ...args: unknown[]) => Promise<void>;
219
+ }, {
220
+ collections: string[];
221
+ run: (args_0: {
222
+ data: {
223
+ data: {
224
+ after: {
225
+ owner: Uint8Array<ArrayBufferLike>;
226
+ data: Uint8Array<ArrayBuffer>;
227
+ created_at: bigint;
228
+ updated_at: bigint;
229
+ description?: string | undefined;
230
+ version?: bigint | undefined;
231
+ };
232
+ before?: {
233
+ owner: Uint8Array<ArrayBufferLike>;
234
+ data: Uint8Array<ArrayBuffer>;
235
+ created_at: bigint;
236
+ updated_at: bigint;
237
+ description?: string | undefined;
238
+ version?: bigint | undefined;
239
+ } | undefined;
240
+ };
241
+ collection: string;
242
+ key: string;
243
+ };
244
+ caller: Uint8Array<ArrayBufferLike>;
245
+ }, ...args: unknown[]) => Promise<void>;
246
+ }>;
10
247
  /**
11
- * A configuration object that includes the `onSetDoc` function.
12
- * This function is called when a document is created or updated.
248
+ * Configuration for a hook that runs when a document is created or updated.
13
249
  */
14
- export interface OnSetDocConfig extends Omit<OnHookConfig, 'onSetDoc'> {
250
+ export type OnSetDocConfig = z.infer<typeof OnSetDocConfigSchema>;
251
+ /**
252
+ * @see HookConfig
253
+ */
254
+ export declare const HookConfigSchema: z.ZodObject<z.objectUtil.extendShape<{
255
+ collections: z.ZodArray<z.ZodString, "many">;
256
+ }, {
15
257
  /**
16
- * A function that runs when a document is set in the Datastore.
258
+ * A function that runs when the hook is triggered for the specified collections.
17
259
  *
18
- * @param {OnSetDocContext} context - Provides details about the document being saved.
19
- * @returns {Promise<void>} Resolves when your operation is complete.
260
+ * @param {T} context - Contains information about the affected document(s).
261
+ * @returns {Promise<void>} Resolves when the operation completes.
20
262
  */
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;
263
+ run: z.ZodFunction<z.ZodTuple<[z.ZodObject<{
264
+ caller: z.ZodType<Uint8Array<ArrayBufferLike>, z.ZodTypeDef, Uint8Array<ArrayBufferLike>>;
265
+ data: z.ZodObject<{
266
+ collection: z.ZodString;
267
+ key: z.ZodString;
268
+ data: z.ZodObject<{
269
+ before: z.ZodOptional<z.ZodObject<{
270
+ owner: z.ZodType<Uint8Array<ArrayBufferLike>, z.ZodTypeDef, Uint8Array<ArrayBufferLike>>;
271
+ data: z.ZodType<Uint8Array<ArrayBuffer>, z.ZodTypeDef, Uint8Array<ArrayBuffer>>;
272
+ description: z.ZodOptional<z.ZodString>;
273
+ created_at: z.ZodBigInt;
274
+ updated_at: z.ZodBigInt;
275
+ version: z.ZodOptional<z.ZodBigInt>;
276
+ }, "strict", z.ZodTypeAny, {
277
+ owner: Uint8Array<ArrayBufferLike>;
278
+ data: Uint8Array<ArrayBuffer>;
279
+ created_at: bigint;
280
+ updated_at: bigint;
281
+ description?: string | undefined;
282
+ version?: bigint | undefined;
283
+ }, {
284
+ owner: Uint8Array<ArrayBufferLike>;
285
+ data: Uint8Array<ArrayBuffer>;
286
+ created_at: bigint;
287
+ updated_at: bigint;
288
+ description?: string | undefined;
289
+ version?: bigint | undefined;
290
+ }>>;
291
+ after: z.ZodObject<{
292
+ owner: z.ZodType<Uint8Array<ArrayBufferLike>, z.ZodTypeDef, Uint8Array<ArrayBufferLike>>;
293
+ data: z.ZodType<Uint8Array<ArrayBuffer>, z.ZodTypeDef, Uint8Array<ArrayBuffer>>;
294
+ description: z.ZodOptional<z.ZodString>;
295
+ created_at: z.ZodBigInt;
296
+ updated_at: z.ZodBigInt;
297
+ version: z.ZodOptional<z.ZodBigInt>;
298
+ }, "strict", z.ZodTypeAny, {
299
+ owner: Uint8Array<ArrayBufferLike>;
300
+ data: Uint8Array<ArrayBuffer>;
301
+ created_at: bigint;
302
+ updated_at: bigint;
303
+ description?: string | undefined;
304
+ version?: bigint | undefined;
305
+ }, {
306
+ owner: Uint8Array<ArrayBufferLike>;
307
+ data: Uint8Array<ArrayBuffer>;
308
+ created_at: bigint;
309
+ updated_at: bigint;
310
+ description?: string | undefined;
311
+ version?: bigint | undefined;
312
+ }>;
313
+ }, "strict", z.ZodTypeAny, {
314
+ after: {
315
+ owner: Uint8Array<ArrayBufferLike>;
316
+ data: Uint8Array<ArrayBuffer>;
317
+ created_at: bigint;
318
+ updated_at: bigint;
319
+ description?: string | undefined;
320
+ version?: bigint | undefined;
321
+ };
322
+ before?: {
323
+ owner: Uint8Array<ArrayBufferLike>;
324
+ data: Uint8Array<ArrayBuffer>;
325
+ created_at: bigint;
326
+ updated_at: bigint;
327
+ description?: string | undefined;
328
+ version?: bigint | undefined;
329
+ } | undefined;
330
+ }, {
331
+ after: {
332
+ owner: Uint8Array<ArrayBufferLike>;
333
+ data: Uint8Array<ArrayBuffer>;
334
+ created_at: bigint;
335
+ updated_at: bigint;
336
+ description?: string | undefined;
337
+ version?: bigint | undefined;
338
+ };
339
+ before?: {
340
+ owner: Uint8Array<ArrayBufferLike>;
341
+ data: Uint8Array<ArrayBuffer>;
342
+ created_at: bigint;
343
+ updated_at: bigint;
344
+ description?: string | undefined;
345
+ version?: bigint | undefined;
346
+ } | undefined;
347
+ }>;
348
+ }, "strict", z.ZodTypeAny, {
349
+ data: {
350
+ after: {
351
+ owner: Uint8Array<ArrayBufferLike>;
352
+ data: Uint8Array<ArrayBuffer>;
353
+ created_at: bigint;
354
+ updated_at: bigint;
355
+ description?: string | undefined;
356
+ version?: bigint | undefined;
357
+ };
358
+ before?: {
359
+ owner: Uint8Array<ArrayBufferLike>;
360
+ data: Uint8Array<ArrayBuffer>;
361
+ created_at: bigint;
362
+ updated_at: bigint;
363
+ description?: string | undefined;
364
+ version?: bigint | undefined;
365
+ } | undefined;
366
+ };
367
+ collection: string;
368
+ key: string;
369
+ }, {
370
+ data: {
371
+ after: {
372
+ owner: Uint8Array<ArrayBufferLike>;
373
+ data: Uint8Array<ArrayBuffer>;
374
+ created_at: bigint;
375
+ updated_at: bigint;
376
+ description?: string | undefined;
377
+ version?: bigint | undefined;
378
+ };
379
+ before?: {
380
+ owner: Uint8Array<ArrayBufferLike>;
381
+ data: Uint8Array<ArrayBuffer>;
382
+ created_at: bigint;
383
+ updated_at: bigint;
384
+ description?: string | undefined;
385
+ version?: bigint | undefined;
386
+ } | undefined;
387
+ };
388
+ collection: string;
389
+ key: string;
390
+ }>;
391
+ }, "strict", z.ZodTypeAny, {
392
+ data: {
393
+ data: {
394
+ after: {
395
+ owner: Uint8Array<ArrayBufferLike>;
396
+ data: Uint8Array<ArrayBuffer>;
397
+ created_at: bigint;
398
+ updated_at: bigint;
399
+ description?: string | undefined;
400
+ version?: bigint | undefined;
401
+ };
402
+ before?: {
403
+ owner: Uint8Array<ArrayBufferLike>;
404
+ data: Uint8Array<ArrayBuffer>;
405
+ created_at: bigint;
406
+ updated_at: bigint;
407
+ description?: string | undefined;
408
+ version?: bigint | undefined;
409
+ } | undefined;
410
+ };
411
+ collection: string;
412
+ key: string;
413
+ };
414
+ caller: Uint8Array<ArrayBufferLike>;
415
+ }, {
416
+ data: {
417
+ data: {
418
+ after: {
419
+ owner: Uint8Array<ArrayBufferLike>;
420
+ data: Uint8Array<ArrayBuffer>;
421
+ created_at: bigint;
422
+ updated_at: bigint;
423
+ description?: string | undefined;
424
+ version?: bigint | undefined;
425
+ };
426
+ before?: {
427
+ owner: Uint8Array<ArrayBufferLike>;
428
+ data: Uint8Array<ArrayBuffer>;
429
+ created_at: bigint;
430
+ updated_at: bigint;
431
+ description?: string | undefined;
432
+ version?: bigint | undefined;
433
+ } | undefined;
434
+ };
435
+ collection: string;
436
+ key: string;
437
+ };
438
+ caller: Uint8Array<ArrayBufferLike>;
439
+ }>], z.ZodUnknown>, z.ZodPromise<z.ZodVoid>>;
440
+ }>, "strict", z.ZodTypeAny, {
441
+ collections: string[];
442
+ run: (args_0: {
443
+ data: {
444
+ data: {
445
+ after: {
446
+ owner: Uint8Array<ArrayBufferLike>;
447
+ data: Uint8Array<ArrayBuffer>;
448
+ created_at: bigint;
449
+ updated_at: bigint;
450
+ description?: string | undefined;
451
+ version?: bigint | undefined;
452
+ };
453
+ before?: {
454
+ owner: Uint8Array<ArrayBufferLike>;
455
+ data: Uint8Array<ArrayBuffer>;
456
+ created_at: bigint;
457
+ updated_at: bigint;
458
+ description?: string | undefined;
459
+ version?: bigint | undefined;
460
+ } | undefined;
461
+ };
462
+ collection: string;
463
+ key: string;
464
+ };
465
+ caller: Uint8Array<ArrayBufferLike>;
466
+ }, ...args: unknown[]) => Promise<void>;
467
+ }, {
468
+ collections: string[];
469
+ run: (args_0: {
470
+ data: {
471
+ data: {
472
+ after: {
473
+ owner: Uint8Array<ArrayBufferLike>;
474
+ data: Uint8Array<ArrayBuffer>;
475
+ created_at: bigint;
476
+ updated_at: bigint;
477
+ description?: string | undefined;
478
+ version?: bigint | undefined;
479
+ };
480
+ before?: {
481
+ owner: Uint8Array<ArrayBufferLike>;
482
+ data: Uint8Array<ArrayBuffer>;
483
+ created_at: bigint;
484
+ updated_at: bigint;
485
+ description?: string | undefined;
486
+ version?: bigint | undefined;
487
+ } | undefined;
488
+ };
489
+ collection: string;
490
+ key: string;
491
+ };
492
+ caller: Uint8Array<ArrayBufferLike>;
493
+ }, ...args: unknown[]) => Promise<void>;
494
+ }>;
495
+ /**
496
+ * All possible config for assertions.
497
+ */
498
+ export type HookConfig = z.infer<typeof HookConfigSchema>;
499
+ export declare const HookFnSchema: <T extends z.ZodTypeAny>(hookConfigSchema: T) => z.ZodFunction<z.ZodTuple<[z.ZodRecord<z.ZodString, z.ZodUnknown>], z.ZodUnknown>, T>;
500
+ export type HookFn<T extends HookConfig> = (config: z.infer<typeof SatelliteConfigEnvSchema>) => T;
501
+ export declare const HookFnOrObjectSchema: <T extends z.ZodTypeAny>(hookConfigSchema: T) => z.ZodUnion<[T, z.ZodFunction<z.ZodTuple<[z.ZodRecord<z.ZodString, z.ZodUnknown>], z.ZodUnknown>, T>]>;
502
+ export type HookFnOrObject<T extends HookConfig> = T | HookFn<T>;
503
+ export declare function defineHook<T extends HookConfig>(config: T): T;
504
+ export declare function defineHook<T extends HookConfig>(config: HookFn<T>): HookFn<T>;
505
+ export declare function defineHook<T extends HookConfig>(config: HookFnOrObject<T>): HookFnOrObject<T>;
@@ -1,3 +1,4 @@
1
+ import * as z from 'zod';
1
2
  /**
2
3
  * Placeholder for future environment-specific configurations.
3
4
  *
@@ -5,4 +6,6 @@
5
6
  * - Defining the execution mode (e.g., staging or production).
6
7
  * - Providing environment-specific values like `ckBtcLedgerId` for test or production.
7
8
  */
8
- export type SatelliteConfigEnv = object;
9
+ export declare const SatelliteConfigEnvSchema: z.ZodRecord<z.ZodString, z.ZodUnknown>;
10
+ /** @typedef {z.infer<typeof SatelliteConfigEnvSchema>} SatelliteConfigEnv */
11
+ export type SatelliteConfigEnv = z.infer<typeof SatelliteConfigEnvSchema>;