@junobuild/functions 0.0.11-next-2025-03-21 → 0.0.12-next-2025-03-27

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 CHANGED
@@ -74,7 +74,7 @@ JavaScript and TypeScript utilities for [Juno] Serverless Functions.
74
74
  | ---------------- | ----------------------------------------------------------------------------------------------------------------------- |
75
75
  | `AssertFnSchema` | `<T extends z.ZodTypeAny>(assertSchema: T) => ZodFunction<ZodTuple<[ZodRecord<ZodString, ZodUnknown>], ZodUnknown>, T>` |
76
76
 
77
- [:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/hooks/db/assertions.ts#L44)
77
+ [:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/hooks/db/assertions.ts#L53)
78
78
 
79
79
  #### :gear: AssertFnOrObjectSchema
80
80
 
@@ -82,7 +82,7 @@ JavaScript and TypeScript utilities for [Juno] Serverless Functions.
82
82
  | ------------------------ | -------------------------------------------------------------------------------------------------------------------------------------- |
83
83
  | `AssertFnOrObjectSchema` | `<T extends z.ZodTypeAny>(assertSchema: T) => ZodUnion<[T, ZodFunction<ZodTuple<[ZodRecord<ZodString, ZodUnknown>], ZodUnknown>, T>]>` |
84
84
 
85
- [:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/hooks/db/assertions.ts#L48)
85
+ [:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/hooks/db/assertions.ts#L57)
86
86
 
87
87
  #### :gear: defineAssert
88
88
 
@@ -90,7 +90,7 @@ JavaScript and TypeScript utilities for [Juno] Serverless Functions.
90
90
  | -------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
91
91
  | `defineAssert` | `{ <T extends Assert>(assert: T): T; <T extends Assert>(assert: AssertFn<T>): AssertFn<T>; <T extends Assert>(assert: AssertFnOrObject<T>): AssertFnOrObject<T>; }` |
92
92
 
93
- [:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/hooks/db/assertions.ts#L52)
93
+ [:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/hooks/db/assertions.ts#L61)
94
94
 
95
95
  #### :gear: defineAssert
96
96
 
@@ -98,7 +98,7 @@ JavaScript and TypeScript utilities for [Juno] Serverless Functions.
98
98
  | -------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
99
99
  | `defineAssert` | `{ <T extends Assert>(assert: T): T; <T extends Assert>(assert: AssertFn<T>): AssertFn<T>; <T extends Assert>(assert: AssertFnOrObject<T>): AssertFnOrObject<T>; }` |
100
100
 
101
- [:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/hooks/db/assertions.ts#L53)
101
+ [:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/hooks/db/assertions.ts#L62)
102
102
 
103
103
  #### :gear: defineAssert
104
104
 
@@ -106,7 +106,7 @@ JavaScript and TypeScript utilities for [Juno] Serverless Functions.
106
106
  | -------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
107
107
  | `defineAssert` | `{ <T extends Assert>(assert: T): T; <T extends Assert>(assert: AssertFn<T>): AssertFn<T>; <T extends Assert>(assert: AssertFnOrObject<T>): AssertFnOrObject<T>; }` |
108
108
 
109
- [:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/hooks/db/assertions.ts#L54)
109
+ [:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/hooks/db/assertions.ts#L63)
110
110
 
111
111
  #### :gear: defineAssert
112
112
 
@@ -114,7 +114,7 @@ JavaScript and TypeScript utilities for [Juno] Serverless Functions.
114
114
  | -------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
115
115
  | `defineAssert` | `{ <T extends Assert>(assert: T): T; <T extends Assert>(assert: AssertFn<T>): AssertFn<T>; <T extends Assert>(assert: AssertFnOrObject<T>): AssertFnOrObject<T>; }` |
116
116
 
117
- [:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/hooks/db/assertions.ts#L55)
117
+ [:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/hooks/db/assertions.ts#L64)
118
118
 
119
119
  #### :gear: HookFnSchema
120
120
 
@@ -256,12 +256,16 @@ the Principal of the executing canister.
256
256
  - [RawDataSchema](#gear-rawdataschema)
257
257
  - [DocSchema](#gear-docschema)
258
258
  - [DocUpsertSchema](#gear-docupsertschema)
259
- - [ProposedDocSchema](#gear-proposeddocschema)
259
+ - [SetDocSchema](#gear-setdocschema)
260
+ - [DelDocSchema](#gear-deldocschema)
260
261
  - [DocAssertSetSchema](#gear-docassertsetschema)
262
+ - [DocAssertDeleteSchema](#gear-docassertdeleteschema)
261
263
  - [OnSetDocContextSchema](#gear-onsetdoccontextschema)
262
264
  - [AssertSetDocContextSchema](#gear-assertsetdoccontextschema)
265
+ - [AssertDeleteDocContextSchema](#gear-assertdeletedoccontextschema)
263
266
  - [SatelliteEnvSchema](#gear-satelliteenvschema)
264
267
  - [AssertSetDocSchema](#gear-assertsetdocschema)
268
+ - [AssertDeleteDocSchema](#gear-assertdeletedocschema)
265
269
  - [AssertSchema](#gear-assertschema)
266
270
  - [OnSetDocSchema](#gear-onsetdocschema)
267
271
  - [HookSchema](#gear-hookschema)
@@ -387,21 +391,37 @@ A schema that validates a value is an Uint8Array.
387
391
 
388
392
  [:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/hooks/schemas/db/payload.ts#L8)
389
393
 
390
- #### :gear: ProposedDocSchema
394
+ #### :gear: SetDocSchema
391
395
 
392
- | Constant | Type |
393
- | ------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
394
- | `ProposedDocSchema` | `ZodObject<{ data: ZodType<Uint8Array<ArrayBufferLike>, ZodTypeDef, Uint8Array<ArrayBufferLike>>; description: ZodOptional<...>; version: ZodOptional<...>; }, "strict", ZodTypeAny, { ...; }, { ...; }>` |
396
+ | Constant | Type |
397
+ | -------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
398
+ | `SetDocSchema` | `ZodObject<{ data: ZodType<Uint8Array<ArrayBufferLike>, ZodTypeDef, Uint8Array<ArrayBufferLike>>; description: ZodOptional<...>; version: ZodOptional<...>; }, "strict", ZodTypeAny, { ...; }, { ...; }>` |
395
399
 
396
400
  [:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/hooks/schemas/db/payload.ts#L33)
397
401
 
402
+ #### :gear: DelDocSchema
403
+
404
+ | Constant | Type |
405
+ | -------------- | ----------------------------------------------------------------------------------------------------------------------------------------------- |
406
+ | `DelDocSchema` | `ZodObject<{ version: ZodOptional<ZodBigInt>; }, "strict", ZodTypeAny, { version?: bigint or undefined; }, { version?: bigint or undefined; }>` |
407
+
408
+ [:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/hooks/schemas/db/payload.ts#L61)
409
+
398
410
  #### :gear: DocAssertSetSchema
399
411
 
400
412
  | Constant | Type |
401
413
  | -------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
402
414
  | `DocAssertSetSchema` | `ZodObject<{ current: ZodOptional<ZodObject<{ owner: ZodType<Uint8Array<ArrayBufferLike>, ZodTypeDef, Uint8Array<ArrayBufferLike>>; ... 4 more ...; version: ZodOptional<...>; }, "strict", ZodTypeAny, { ...; }, { ...; }>>; proposed: ZodObject<...>; }, "strict", ZodTypeAny, { ...; }, { ...; }>` |
403
415
 
404
- [:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/hooks/schemas/db/payload.ts#L61)
416
+ [:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/hooks/schemas/db/payload.ts#L79)
417
+
418
+ #### :gear: DocAssertDeleteSchema
419
+
420
+ | Constant | Type |
421
+ | ----------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
422
+ | `DocAssertDeleteSchema` | `ZodObject<{ current: ZodOptional<ZodObject<{ owner: ZodType<Uint8Array<ArrayBufferLike>, ZodTypeDef, Uint8Array<ArrayBufferLike>>; ... 4 more ...; version: ZodOptional<...>; }, "strict", ZodTypeAny, { ...; }, { ...; }>>; proposed: ZodObject<...>; }, "strict", ZodTypeAny, { ...; }, { ...; }>` |
423
+
424
+ [:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/hooks/schemas/db/payload.ts#L106)
405
425
 
406
426
  #### :gear: OnSetDocContextSchema
407
427
 
@@ -419,6 +439,14 @@ A schema that validates a value is an Uint8Array.
419
439
 
420
440
  [:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/hooks/schemas/db/context.ts#L61)
421
441
 
442
+ #### :gear: AssertDeleteDocContextSchema
443
+
444
+ | Constant | Type |
445
+ | ------------------------------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
446
+ | `AssertDeleteDocContextSchema` | `ZodObject<{ caller: ZodType<Uint8Array<ArrayBufferLike>, ZodTypeDef, Uint8Array<ArrayBufferLike>>; data: ZodObject<...>; }, "strict", ZodTypeAny, baseObjectOutputType<...>, baseObjectInputType<...>>` |
447
+
448
+ [:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/hooks/schemas/db/context.ts#L74)
449
+
422
450
  #### :gear: SatelliteEnvSchema
423
451
 
424
452
  | Constant | Type |
@@ -435,13 +463,21 @@ A schema that validates a value is an Uint8Array.
435
463
 
436
464
  [:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/hooks/db/assertions.ts#L26)
437
465
 
466
+ #### :gear: AssertDeleteDocSchema
467
+
468
+ | Constant | Type |
469
+ | ----------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
470
+ | `AssertDeleteDocSchema` | `ZodObject<extendShape<{ collections: ZodReadonly<ZodArray<ZodString, "many">>; }, { assert: ZodFunction<ZodTuple<[ZodObject<{ caller: ZodType<Uint8Array<ArrayBufferLike>, ZodTypeDef, Uint8Array<...>>; data: ZodObject<...>; }, "strict", ZodTypeAny, baseObjectOutputType<...>, baseObjectInputType<...>>], ZodUnknown>, Z...` |
471
+
472
+ [:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/hooks/db/assertions.ts#L36)
473
+
438
474
  #### :gear: AssertSchema
439
475
 
440
476
  | Constant | Type |
441
477
  | -------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
442
- | `AssertSchema` | `ZodObject<extendShape<{ collections: ZodReadonly<ZodArray<ZodString, "many">>; }, { assert: ZodFunction<ZodTuple<[ZodObject<{ caller: ZodType<Uint8Array<ArrayBufferLike>, ZodTypeDef, Uint8Array<...>>; data: ZodObject<...>; }, "strict", ZodTypeAny, baseObjectOutputType<...>, baseObjectInputType<...>>], ZodUnknown>, Z...` |
478
+ | `AssertSchema` | `ZodUnion<[ZodObject<extendShape<{ collections: ZodReadonly<ZodArray<ZodString, "many">>; }, { assert: ZodFunction<ZodTuple<[ZodObject<{ caller: ZodType<Uint8Array<ArrayBufferLike>, ZodTypeDef, Uint8Array<...>>; data: ZodObject<...>; }, "strict", ZodTypeAny, baseObjectOutputType<...>, baseObjectInputType<...>>], ZodU...` |
443
479
 
444
- [:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/hooks/db/assertions.ts#L37)
480
+ [:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/hooks/db/assertions.ts#L46)
445
481
 
446
482
  #### :gear: OnSetDocSchema
447
483
 
@@ -539,13 +575,17 @@ Schema for encoding the call arguments.
539
575
  - [RawData](#gear-rawdata)
540
576
  - [Doc](#gear-doc)
541
577
  - [DocUpsert](#gear-docupsert)
542
- - [ProposedDoc](#gear-proposeddoc)
578
+ - [SetDoc](#gear-setdoc)
579
+ - [DelDoc](#gear-deldoc)
543
580
  - [DocAssertSet](#gear-docassertset)
581
+ - [DocAssertDelete](#gear-docassertdelete)
544
582
  - [DocContext](#gear-doccontext)
545
583
  - [OnSetDocContext](#gear-onsetdoccontext)
546
584
  - [AssertSetDocContext](#gear-assertsetdoccontext)
585
+ - [AssertDeleteDocContext](#gear-assertdeletedoccontext)
547
586
  - [SatelliteEnv](#gear-satelliteenv)
548
587
  - [AssertSetDoc](#gear-assertsetdoc)
588
+ - [AssertDeleteDoc](#gear-assertdeletedoc)
549
589
  - [Assert](#gear-assert)
550
590
  - [AssertFn](#gear-assertfn)
551
591
  - [AssertFnOrObject](#gear-assertfnorobject)
@@ -737,17 +777,28 @@ This is used in hooks where a document is either being created or updated.
737
777
 
738
778
  [:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/hooks/schemas/db/payload.ts#L28)
739
779
 
740
- #### :gear: ProposedDoc
780
+ #### :gear: SetDoc
741
781
 
742
- Represents the proposed version of a document.
782
+ Represents the proposed version of a document to be created or updated.
743
783
  This can be validated before allowing the operation.
744
784
 
745
- | Type | Type |
746
- | ------------- | ----------------------------------- |
747
- | `ProposedDoc` | `z.infer<typeof ProposedDocSchema>` |
785
+ | Type | Type |
786
+ | -------- | ------------------------------ |
787
+ | `SetDoc` | `z.infer<typeof SetDocSchema>` |
748
788
 
749
789
  [:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/hooks/schemas/db/payload.ts#L56)
750
790
 
791
+ #### :gear: DelDoc
792
+
793
+ Represents the proposed version of a document to be deleted.
794
+ This can be validated before allowing the operation.
795
+
796
+ | Type | Type |
797
+ | -------- | ------------------------------ |
798
+ | `DelDoc` | `z.infer<typeof SetDocSchema>` |
799
+
800
+ [:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/hooks/schemas/db/payload.ts#L74)
801
+
751
802
  #### :gear: DocAssertSet
752
803
 
753
804
  Represents a validation check before setting a document.
@@ -759,7 +810,20 @@ throw an error if their validation fails.
759
810
  | -------------- | ------------------------------------ |
760
811
  | `DocAssertSet` | `z.infer<typeof DocAssertSetSchema>` |
761
812
 
762
- [:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/hooks/schemas/db/payload.ts#L83)
813
+ [:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/hooks/schemas/db/payload.ts#L101)
814
+
815
+ #### :gear: DocAssertDelete
816
+
817
+ Represents a validation check before deleting a document.
818
+
819
+ The developer can compare the `current` and `proposed` versions and
820
+ throw an error if their validation fails.
821
+
822
+ | Type | Type |
823
+ | ----------------- | --------------------------------------- |
824
+ | `DocAssertDelete` | `z.infer<typeof DocAssertDeleteSchema>` |
825
+
826
+ [:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/hooks/schemas/db/payload.ts#L128)
763
827
 
764
828
  #### :gear: DocContext
765
829
 
@@ -786,7 +850,7 @@ along with details about the user who triggered the operation.
786
850
 
787
851
  #### :gear: AssertSetDocContext
788
852
 
789
- The context provided to the `assertSetDoc` hook.
853
+ The context provided to the `assertDeleteDoc` hook.
790
854
 
791
855
  This context contains information about the document being validated before
792
856
  it is created or updated. If validation fails, the developer should throw an error.
@@ -797,6 +861,19 @@ it is created or updated. If validation fails, the developer should throw an err
797
861
 
798
862
  [:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/hooks/schemas/db/context.ts#L69)
799
863
 
864
+ #### :gear: AssertDeleteDocContext
865
+
866
+ The context provided to the `assertDeleteDoc` hook.
867
+
868
+ This context contains information about the document being validated before
869
+ it is deleted. If validation fails, the developer should throw an error.
870
+
871
+ | Type | Type |
872
+ | ------------------------ | ---------------------------------------------- |
873
+ | `AssertDeleteDocContext` | `z.infer<typeof AssertDeleteDocContextSchema>` |
874
+
875
+ [:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/hooks/schemas/db/context.ts#L84)
876
+
800
877
  #### :gear: SatelliteEnv
801
878
 
802
879
  Placeholder for future environment-specific configurations.
@@ -822,6 +899,16 @@ An assertion that runs when a document is created or updated.
822
899
 
823
900
  [:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/hooks/db/assertions.ts#L31)
824
901
 
902
+ #### :gear: AssertDeleteDoc
903
+
904
+ An assertion that runs when a document is deleted.
905
+
906
+ | Type | Type |
907
+ | ----------------- | --------------------------------------- |
908
+ | `AssertDeleteDoc` | `z.infer<typeof AssertDeleteDocSchema>` |
909
+
910
+ [:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/hooks/db/assertions.ts#L41)
911
+
825
912
  #### :gear: Assert
826
913
 
827
914
  All assertions definitions.
@@ -830,7 +917,7 @@ All assertions definitions.
830
917
  | -------- | ------------------------------ |
831
918
  | `Assert` | `z.infer<typeof AssertSchema>` |
832
919
 
833
- [:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/hooks/db/assertions.ts#L42)
920
+ [:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/hooks/db/assertions.ts#L51)
834
921
 
835
922
  #### :gear: AssertFn
836
923
 
@@ -838,7 +925,7 @@ All assertions definitions.
838
925
  | ---------- | --------------------------------------------------- |
839
926
  | `AssertFn` | `(assert: z.infer<typeof SatelliteEnvSchema>) => T` |
840
927
 
841
- [:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/hooks/db/assertions.ts#L46)
928
+ [:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/hooks/db/assertions.ts#L55)
842
929
 
843
930
  #### :gear: AssertFnOrObject
844
931
 
@@ -846,7 +933,7 @@ All assertions definitions.
846
933
  | ------------------ | ------------------ |
847
934
  | `AssertFnOrObject` | `T or AssertFn<T>` |
848
935
 
849
- [:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/hooks/db/assertions.ts#L50)
936
+ [:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/hooks/db/assertions.ts#L59)
850
937
 
851
938
  #### :gear: OnSetDoc
852
939