@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.
@@ -1,50 +1,509 @@
1
- import type { RawUserId } from './core';
2
- import type { DocAssertSet, DocUpsert } from './datastore';
1
+ import * as z from 'zod';
3
2
  /**
4
- * Represents the context provided to hooks, containing information about the caller and related data.
5
- *
6
- * @template T - The type of data associated with the hook.
3
+ * @see HookContext
7
4
  */
8
- export interface HookContext<T> {
5
+ declare const HookContextSchema: <T extends z.ZodTypeAny>(dataSchema: T) => z.ZodObject<{
9
6
  /**
10
7
  * The user who originally triggered the function that in turn triggered the hook.
11
8
  */
12
- caller: RawUserId;
9
+ caller: z.ZodType<Uint8Array<ArrayBufferLike>, z.ZodTypeDef, Uint8Array<ArrayBufferLike>>;
13
10
  /**
14
11
  * The data associated with the hook execution.
15
12
  */
16
13
  data: T;
17
- }
14
+ }, "strict", z.ZodTypeAny, z.objectUtil.addQuestionMarks<z.baseObjectOutputType<{
15
+ /**
16
+ * The user who originally triggered the function that in turn triggered the hook.
17
+ */
18
+ caller: z.ZodType<Uint8Array<ArrayBufferLike>, z.ZodTypeDef, Uint8Array<ArrayBufferLike>>;
19
+ /**
20
+ * The data associated with the hook execution.
21
+ */
22
+ data: T;
23
+ }>, any> extends infer T_1 ? { [k in keyof T_1]: z.objectUtil.addQuestionMarks<z.baseObjectOutputType<{
24
+ /**
25
+ * The user who originally triggered the function that in turn triggered the hook.
26
+ */
27
+ caller: z.ZodType<Uint8Array<ArrayBufferLike>, z.ZodTypeDef, Uint8Array<ArrayBufferLike>>;
28
+ /**
29
+ * The data associated with the hook execution.
30
+ */
31
+ data: T;
32
+ }>, any>[k]; } : never, z.baseObjectInputType<{
33
+ /**
34
+ * The user who originally triggered the function that in turn triggered the hook.
35
+ */
36
+ caller: z.ZodType<Uint8Array<ArrayBufferLike>, z.ZodTypeDef, Uint8Array<ArrayBufferLike>>;
37
+ /**
38
+ * The data associated with the hook execution.
39
+ */
40
+ data: T;
41
+ }> extends infer T_2 ? { [k_1 in keyof T_2]: z.baseObjectInputType<{
42
+ /**
43
+ * The user who originally triggered the function that in turn triggered the hook.
44
+ */
45
+ caller: z.ZodType<Uint8Array<ArrayBufferLike>, z.ZodTypeDef, Uint8Array<ArrayBufferLike>>;
46
+ /**
47
+ * The data associated with the hook execution.
48
+ */
49
+ data: T;
50
+ }>[k_1]; } : never>;
18
51
  /**
19
- * Represents the context of a document operation within a collection.
52
+ * Represents the context provided to hooks, containing information about the caller and related data.
20
53
  *
21
- * @template T - The type of data associated with the document.
54
+ * @template T - The type of data associated with the hook.
55
+ */
56
+ export type HookContext<T extends z.ZodTypeAny> = z.infer<ReturnType<typeof HookContextSchema<T>>>;
57
+ /**
58
+ * @see DocContext
22
59
  */
23
- export interface DocContext<T> {
60
+ export declare const DocContextSchema: <T extends z.ZodTypeAny>(dataSchema: T) => z.ZodObject<{
61
+ /**
62
+ * The name of the collection where the document is stored.
63
+ */
64
+ collection: z.ZodString;
65
+ /**
66
+ * The unique key identifying the document within the collection.
67
+ */
68
+ key: z.ZodString;
69
+ /**
70
+ * The data associated with the document operation.
71
+ */
72
+ data: T;
73
+ }, "strict", z.ZodTypeAny, z.objectUtil.addQuestionMarks<z.baseObjectOutputType<{
74
+ /**
75
+ * The name of the collection where the document is stored.
76
+ */
77
+ collection: z.ZodString;
78
+ /**
79
+ * The unique key identifying the document within the collection.
80
+ */
81
+ key: z.ZodString;
82
+ /**
83
+ * The data associated with the document operation.
84
+ */
85
+ data: T;
86
+ }>, any> extends infer T_1 ? { [k in keyof T_1]: z.objectUtil.addQuestionMarks<z.baseObjectOutputType<{
24
87
  /**
25
88
  * The name of the collection where the document is stored.
26
89
  */
27
- collection: string;
90
+ collection: z.ZodString;
28
91
  /**
29
92
  * The unique key identifying the document within the collection.
30
93
  */
31
- key: string;
94
+ key: z.ZodString;
32
95
  /**
33
96
  * The data associated with the document operation.
34
97
  */
35
98
  data: T;
36
- }
99
+ }>, any>[k]; } : never, z.baseObjectInputType<{
100
+ /**
101
+ * The name of the collection where the document is stored.
102
+ */
103
+ collection: z.ZodString;
104
+ /**
105
+ * The unique key identifying the document within the collection.
106
+ */
107
+ key: z.ZodString;
108
+ /**
109
+ * The data associated with the document operation.
110
+ */
111
+ data: T;
112
+ }> extends infer T_2 ? { [k_1 in keyof T_2]: z.baseObjectInputType<{
113
+ /**
114
+ * The name of the collection where the document is stored.
115
+ */
116
+ collection: z.ZodString;
117
+ /**
118
+ * The unique key identifying the document within the collection.
119
+ */
120
+ key: z.ZodString;
121
+ /**
122
+ * The data associated with the document operation.
123
+ */
124
+ data: T;
125
+ }>[k_1]; } : never>;
126
+ /**
127
+ * Represents the context of a document operation within a collection.
128
+ *
129
+ * @template T - The type of data associated with the document.
130
+ */
131
+ export type DocContext<T extends z.ZodTypeAny> = z.infer<ReturnType<typeof DocContextSchema<T>>>;
132
+ /**
133
+ * @see OnSetDocContext
134
+ */
135
+ export declare const OnSetDocContextSchema: z.ZodObject<{
136
+ /**
137
+ * The user who originally triggered the function that in turn triggered the hook.
138
+ */
139
+ caller: z.ZodType<Uint8Array<ArrayBufferLike>, z.ZodTypeDef, Uint8Array<ArrayBufferLike>>;
140
+ /**
141
+ * The data associated with the hook execution.
142
+ */
143
+ data: z.ZodObject<{
144
+ /**
145
+ * The name of the collection where the document is stored.
146
+ */
147
+ collection: z.ZodString;
148
+ /**
149
+ * The unique key identifying the document within the collection.
150
+ */
151
+ key: z.ZodString;
152
+ /**
153
+ * The data associated with the document operation.
154
+ */
155
+ data: z.ZodObject<{
156
+ before: z.ZodOptional<z.ZodObject<{
157
+ owner: z.ZodType<Uint8Array<ArrayBufferLike>, z.ZodTypeDef, Uint8Array<ArrayBufferLike>>;
158
+ data: z.ZodType<Uint8Array<ArrayBufferLike>, z.ZodTypeDef, Uint8Array<ArrayBufferLike>>;
159
+ description: z.ZodOptional<z.ZodString>;
160
+ created_at: z.ZodBigInt;
161
+ updated_at: z.ZodBigInt;
162
+ version: z.ZodOptional<z.ZodBigInt>;
163
+ }, "strict", z.ZodTypeAny, {
164
+ owner: Uint8Array<ArrayBufferLike>;
165
+ data: Uint8Array<ArrayBufferLike>;
166
+ created_at: bigint;
167
+ updated_at: bigint;
168
+ description?: string | undefined;
169
+ version?: bigint | undefined;
170
+ }, {
171
+ owner: Uint8Array<ArrayBufferLike>;
172
+ data: Uint8Array<ArrayBufferLike>;
173
+ created_at: bigint;
174
+ updated_at: bigint;
175
+ description?: string | undefined;
176
+ version?: bigint | undefined;
177
+ }>>;
178
+ after: z.ZodObject<{
179
+ owner: z.ZodType<Uint8Array<ArrayBufferLike>, z.ZodTypeDef, Uint8Array<ArrayBufferLike>>;
180
+ data: z.ZodType<Uint8Array<ArrayBufferLike>, z.ZodTypeDef, Uint8Array<ArrayBufferLike>>;
181
+ description: z.ZodOptional<z.ZodString>;
182
+ created_at: z.ZodBigInt;
183
+ updated_at: z.ZodBigInt;
184
+ version: z.ZodOptional<z.ZodBigInt>;
185
+ }, "strict", z.ZodTypeAny, {
186
+ owner: Uint8Array<ArrayBufferLike>;
187
+ data: Uint8Array<ArrayBufferLike>;
188
+ created_at: bigint;
189
+ updated_at: bigint;
190
+ description?: string | undefined;
191
+ version?: bigint | undefined;
192
+ }, {
193
+ owner: Uint8Array<ArrayBufferLike>;
194
+ data: Uint8Array<ArrayBufferLike>;
195
+ created_at: bigint;
196
+ updated_at: bigint;
197
+ description?: string | undefined;
198
+ version?: bigint | undefined;
199
+ }>;
200
+ }, "strict", z.ZodTypeAny, {
201
+ after: {
202
+ owner: Uint8Array<ArrayBufferLike>;
203
+ data: Uint8Array<ArrayBufferLike>;
204
+ created_at: bigint;
205
+ updated_at: bigint;
206
+ description?: string | undefined;
207
+ version?: bigint | undefined;
208
+ };
209
+ before?: {
210
+ owner: Uint8Array<ArrayBufferLike>;
211
+ data: Uint8Array<ArrayBufferLike>;
212
+ created_at: bigint;
213
+ updated_at: bigint;
214
+ description?: string | undefined;
215
+ version?: bigint | undefined;
216
+ } | undefined;
217
+ }, {
218
+ after: {
219
+ owner: Uint8Array<ArrayBufferLike>;
220
+ data: Uint8Array<ArrayBufferLike>;
221
+ created_at: bigint;
222
+ updated_at: bigint;
223
+ description?: string | undefined;
224
+ version?: bigint | undefined;
225
+ };
226
+ before?: {
227
+ owner: Uint8Array<ArrayBufferLike>;
228
+ data: Uint8Array<ArrayBufferLike>;
229
+ created_at: bigint;
230
+ updated_at: bigint;
231
+ description?: string | undefined;
232
+ version?: bigint | undefined;
233
+ } | undefined;
234
+ }>;
235
+ }, "strict", z.ZodTypeAny, {
236
+ data: {
237
+ after: {
238
+ owner: Uint8Array<ArrayBufferLike>;
239
+ data: Uint8Array<ArrayBufferLike>;
240
+ created_at: bigint;
241
+ updated_at: bigint;
242
+ description?: string | undefined;
243
+ version?: bigint | undefined;
244
+ };
245
+ before?: {
246
+ owner: Uint8Array<ArrayBufferLike>;
247
+ data: Uint8Array<ArrayBufferLike>;
248
+ created_at: bigint;
249
+ updated_at: bigint;
250
+ description?: string | undefined;
251
+ version?: bigint | undefined;
252
+ } | undefined;
253
+ };
254
+ collection: string;
255
+ key: string;
256
+ }, {
257
+ data: {
258
+ after: {
259
+ owner: Uint8Array<ArrayBufferLike>;
260
+ data: Uint8Array<ArrayBufferLike>;
261
+ created_at: bigint;
262
+ updated_at: bigint;
263
+ description?: string | undefined;
264
+ version?: bigint | undefined;
265
+ };
266
+ before?: {
267
+ owner: Uint8Array<ArrayBufferLike>;
268
+ data: Uint8Array<ArrayBufferLike>;
269
+ created_at: bigint;
270
+ updated_at: bigint;
271
+ description?: string | undefined;
272
+ version?: bigint | undefined;
273
+ } | undefined;
274
+ };
275
+ collection: string;
276
+ key: string;
277
+ }>;
278
+ }, "strict", z.ZodTypeAny, {
279
+ data: {
280
+ data: {
281
+ after: {
282
+ owner: Uint8Array<ArrayBufferLike>;
283
+ data: Uint8Array<ArrayBufferLike>;
284
+ created_at: bigint;
285
+ updated_at: bigint;
286
+ description?: string | undefined;
287
+ version?: bigint | undefined;
288
+ };
289
+ before?: {
290
+ owner: Uint8Array<ArrayBufferLike>;
291
+ data: Uint8Array<ArrayBufferLike>;
292
+ created_at: bigint;
293
+ updated_at: bigint;
294
+ description?: string | undefined;
295
+ version?: bigint | undefined;
296
+ } | undefined;
297
+ };
298
+ collection: string;
299
+ key: string;
300
+ };
301
+ caller: Uint8Array<ArrayBufferLike>;
302
+ }, {
303
+ data: {
304
+ data: {
305
+ after: {
306
+ owner: Uint8Array<ArrayBufferLike>;
307
+ data: Uint8Array<ArrayBufferLike>;
308
+ created_at: bigint;
309
+ updated_at: bigint;
310
+ description?: string | undefined;
311
+ version?: bigint | undefined;
312
+ };
313
+ before?: {
314
+ owner: Uint8Array<ArrayBufferLike>;
315
+ data: Uint8Array<ArrayBufferLike>;
316
+ created_at: bigint;
317
+ updated_at: bigint;
318
+ description?: string | undefined;
319
+ version?: bigint | undefined;
320
+ } | undefined;
321
+ };
322
+ collection: string;
323
+ key: string;
324
+ };
325
+ caller: Uint8Array<ArrayBufferLike>;
326
+ }>;
37
327
  /**
38
328
  * The context provided to the `onSetDoc` hook.
39
329
  *
40
330
  * This context contains information about the document being created or updated,
41
331
  * along with details about the user who triggered the operation.
42
332
  */
43
- export type OnSetDocContext = HookContext<DocContext<DocUpsert>>;
333
+ export type OnSetDocContext = z.infer<typeof OnSetDocContextSchema>;
334
+ /**
335
+ * @see AssertSetDocContext
336
+ */
337
+ export declare const AssertSetDocContextSchema: z.ZodObject<{
338
+ /**
339
+ * The user who originally triggered the function that in turn triggered the hook.
340
+ */
341
+ caller: z.ZodType<Uint8Array<ArrayBufferLike>, z.ZodTypeDef, Uint8Array<ArrayBufferLike>>;
342
+ /**
343
+ * The data associated with the hook execution.
344
+ */
345
+ data: z.ZodObject<{
346
+ /**
347
+ * The name of the collection where the document is stored.
348
+ */
349
+ collection: z.ZodString;
350
+ /**
351
+ * The unique key identifying the document within the collection.
352
+ */
353
+ key: z.ZodString;
354
+ /**
355
+ * The data associated with the document operation.
356
+ */
357
+ data: z.ZodObject<{
358
+ current: z.ZodOptional<z.ZodObject<{
359
+ owner: z.ZodType<Uint8Array<ArrayBufferLike>, z.ZodTypeDef, Uint8Array<ArrayBufferLike>>;
360
+ data: z.ZodType<Uint8Array<ArrayBufferLike>, z.ZodTypeDef, Uint8Array<ArrayBufferLike>>;
361
+ description: z.ZodOptional<z.ZodString>;
362
+ created_at: z.ZodBigInt;
363
+ updated_at: z.ZodBigInt;
364
+ version: z.ZodOptional<z.ZodBigInt>;
365
+ }, "strict", z.ZodTypeAny, {
366
+ owner: Uint8Array<ArrayBufferLike>;
367
+ data: Uint8Array<ArrayBufferLike>;
368
+ created_at: bigint;
369
+ updated_at: bigint;
370
+ description?: string | undefined;
371
+ version?: bigint | undefined;
372
+ }, {
373
+ owner: Uint8Array<ArrayBufferLike>;
374
+ data: Uint8Array<ArrayBufferLike>;
375
+ created_at: bigint;
376
+ updated_at: bigint;
377
+ description?: string | undefined;
378
+ version?: bigint | undefined;
379
+ }>>;
380
+ proposed: z.ZodObject<{
381
+ data: z.ZodType<Uint8Array<ArrayBufferLike>, z.ZodTypeDef, Uint8Array<ArrayBufferLike>>;
382
+ description: z.ZodOptional<z.ZodString>;
383
+ version: z.ZodOptional<z.ZodBigInt>;
384
+ }, "strict", z.ZodTypeAny, {
385
+ data: Uint8Array<ArrayBufferLike>;
386
+ description?: string | undefined;
387
+ version?: bigint | undefined;
388
+ }, {
389
+ data: Uint8Array<ArrayBufferLike>;
390
+ description?: string | undefined;
391
+ version?: bigint | undefined;
392
+ }>;
393
+ }, "strict", z.ZodTypeAny, {
394
+ proposed: {
395
+ data: Uint8Array<ArrayBufferLike>;
396
+ description?: string | undefined;
397
+ version?: bigint | undefined;
398
+ };
399
+ current?: {
400
+ owner: Uint8Array<ArrayBufferLike>;
401
+ data: Uint8Array<ArrayBufferLike>;
402
+ created_at: bigint;
403
+ updated_at: bigint;
404
+ description?: string | undefined;
405
+ version?: bigint | undefined;
406
+ } | undefined;
407
+ }, {
408
+ proposed: {
409
+ data: Uint8Array<ArrayBufferLike>;
410
+ description?: string | undefined;
411
+ version?: bigint | undefined;
412
+ };
413
+ current?: {
414
+ owner: Uint8Array<ArrayBufferLike>;
415
+ data: Uint8Array<ArrayBufferLike>;
416
+ created_at: bigint;
417
+ updated_at: bigint;
418
+ description?: string | undefined;
419
+ version?: bigint | undefined;
420
+ } | undefined;
421
+ }>;
422
+ }, "strict", z.ZodTypeAny, {
423
+ data: {
424
+ proposed: {
425
+ data: Uint8Array<ArrayBufferLike>;
426
+ description?: string | undefined;
427
+ version?: bigint | undefined;
428
+ };
429
+ current?: {
430
+ owner: Uint8Array<ArrayBufferLike>;
431
+ data: Uint8Array<ArrayBufferLike>;
432
+ created_at: bigint;
433
+ updated_at: bigint;
434
+ description?: string | undefined;
435
+ version?: bigint | undefined;
436
+ } | undefined;
437
+ };
438
+ collection: string;
439
+ key: string;
440
+ }, {
441
+ data: {
442
+ proposed: {
443
+ data: Uint8Array<ArrayBufferLike>;
444
+ description?: string | undefined;
445
+ version?: bigint | undefined;
446
+ };
447
+ current?: {
448
+ owner: Uint8Array<ArrayBufferLike>;
449
+ data: Uint8Array<ArrayBufferLike>;
450
+ created_at: bigint;
451
+ updated_at: bigint;
452
+ description?: string | undefined;
453
+ version?: bigint | undefined;
454
+ } | undefined;
455
+ };
456
+ collection: string;
457
+ key: string;
458
+ }>;
459
+ }, "strict", z.ZodTypeAny, {
460
+ data: {
461
+ data: {
462
+ proposed: {
463
+ data: Uint8Array<ArrayBufferLike>;
464
+ description?: string | undefined;
465
+ version?: bigint | undefined;
466
+ };
467
+ current?: {
468
+ owner: Uint8Array<ArrayBufferLike>;
469
+ data: Uint8Array<ArrayBufferLike>;
470
+ created_at: bigint;
471
+ updated_at: bigint;
472
+ description?: string | undefined;
473
+ version?: bigint | undefined;
474
+ } | undefined;
475
+ };
476
+ collection: string;
477
+ key: string;
478
+ };
479
+ caller: Uint8Array<ArrayBufferLike>;
480
+ }, {
481
+ data: {
482
+ data: {
483
+ proposed: {
484
+ data: Uint8Array<ArrayBufferLike>;
485
+ description?: string | undefined;
486
+ version?: bigint | undefined;
487
+ };
488
+ current?: {
489
+ owner: Uint8Array<ArrayBufferLike>;
490
+ data: Uint8Array<ArrayBufferLike>;
491
+ created_at: bigint;
492
+ updated_at: bigint;
493
+ description?: string | undefined;
494
+ version?: bigint | undefined;
495
+ } | undefined;
496
+ };
497
+ collection: string;
498
+ key: string;
499
+ };
500
+ caller: Uint8Array<ArrayBufferLike>;
501
+ }>;
44
502
  /**
45
503
  * The context provided to the `assertSetDoc` hook.
46
504
  *
47
505
  * This context contains information about the document being validated before
48
506
  * it is created or updated. If validation fails, the developer should throw an error.
49
507
  */
50
- export type AssertSetDocContext = HookContext<DocContext<DocAssertSet>>;
508
+ export type AssertSetDocContext = z.infer<typeof AssertSetDocContextSchema>;
509
+ export {};
@@ -1,30 +1,51 @@
1
+ import * as z from 'zod';
2
+ /**
3
+ * @see Timestamp
4
+ */
5
+ export declare const TimestampSchema: z.ZodBigInt;
1
6
  /**
2
7
  * Represents a timestamp in nanoseconds since the Unix epoch.
3
8
  *
4
9
  * Used for tracking when events occur, such as document creation and updates.
5
10
  */
6
- export type Timestamp = bigint;
11
+ export type Timestamp = z.infer<typeof TimestampSchema>;
12
+ /**
13
+ * @see Version
14
+ */
15
+ export declare const VersionSchema: z.ZodBigInt;
7
16
  /**
8
17
  * Represents a version number for tracking changes.
9
18
  *
10
19
  * This is typically incremented with each update to ensure consistency.
11
20
  */
12
- export type Version = bigint;
21
+ export type Version = z.infer<typeof VersionSchema>;
22
+ /**
23
+ * @see RawData
24
+ */
25
+ export declare const RawDataSchema: z.ZodType<Uint8Array<ArrayBufferLike>, z.ZodTypeDef, Uint8Array<ArrayBufferLike>>;
13
26
  /**
14
27
  * Represents raw binary data.
15
28
  *
16
29
  * This is used to store unstructured data in a document.
17
30
  */
18
- export type RawData = Uint8Array;
31
+ export type RawData = z.infer<typeof RawDataSchema>;
32
+ /**
33
+ * @see RawPrincipal
34
+ */
35
+ export declare const RawPrincipalSchema: z.ZodType<Uint8Array<ArrayBufferLike>, z.ZodTypeDef, Uint8Array<ArrayBufferLike>>;
19
36
  /**
20
37
  * Represents a raw principal identifier.
21
38
  *
22
39
  * Principals are unique identities used in authentication and authorization.
23
40
  */
24
- export type RawPrincipal = Uint8Array;
41
+ export type RawPrincipal = z.infer<typeof RawPrincipalSchema>;
42
+ /**
43
+ * @see RawUserId
44
+ */
45
+ export declare const RawUserIdSchema: z.ZodType<Uint8Array<ArrayBufferLike>, z.ZodTypeDef, Uint8Array<ArrayBufferLike>>;
25
46
  /**
26
47
  * Represents a raw user identifier.
27
48
  *
28
49
  * This is a principal associated with a user.
29
50
  */
30
- export type RawUserId = RawPrincipal;
51
+ export type RawUserId = z.infer<typeof RawUserIdSchema>;