@junobuild/functions 0.0.13 → 0.0.14
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 +217 -26
- package/{chunk-6G6FWQ45.js → chunk-367GY4VX.js} +1 -1
- package/chunk-367GY4VX.js.map +7 -0
- package/global.d.ts +12 -0
- package/hooks/assertions.d.ts +40 -40
- package/hooks/schemas/db/context.d.ts +1 -1
- package/hooks/schemas/storage/context.d.ts +12 -12
- package/hooks/schemas/storage/payload.d.ts +4 -4
- package/index.js +1 -1
- package/index.js.map +1 -1
- package/package.json +1 -1
- package/schemas/satellite.d.ts +1 -1
- package/schemas/storage.d.ts +2 -2
- package/sdk/controllers.sdk.d.ts +39 -0
- package/sdk/schemas/controllers.d.ts +174 -0
- package/sdk/schemas/db.d.ts +1 -1
- package/sdk/utils/caller.utils.d.ts +10 -0
- package/sdk.d.ts +2 -0
- package/sdk.js +1 -1
- package/sdk.js.map +4 -4
- package/src/global.d.ts +12 -0
- package/tests/mocks/controllers.mocks.d.ts +4 -0
- package/chunk-6G6FWQ45.js.map +0 -7
package/README.md
CHANGED
|
@@ -30,6 +30,11 @@ JavaScript and TypeScript utilities for [Juno] Serverless Functions.
|
|
|
30
30
|
- [defineHook](#gear-definehook)
|
|
31
31
|
- [defineHook](#gear-definehook)
|
|
32
32
|
- [defineHook](#gear-definehook)
|
|
33
|
+
- [normalizeCaller](#gear-normalizecaller)
|
|
34
|
+
- [getAdminControllers](#gear-getadmincontrollers)
|
|
35
|
+
- [getControllers](#gear-getcontrollers)
|
|
36
|
+
- [isAdminController](#gear-isadmincontroller)
|
|
37
|
+
- [isController](#gear-iscontroller)
|
|
33
38
|
- [setDocStore](#gear-setdocstore)
|
|
34
39
|
- [deleteDocStore](#gear-deletedocstore)
|
|
35
40
|
- [decodeDocData](#gear-decodedocdata)
|
|
@@ -123,7 +128,7 @@ JavaScript and TypeScript utilities for [Juno] Serverless Functions.
|
|
|
123
128
|
| -------------- | --------------------------------------------------------------------------------------------------------------------- |
|
|
124
129
|
| `HookFnSchema` | `<T extends z.ZodTypeAny>(hookSchema: T) => ZodFunction<ZodTuple<[ZodRecord<ZodString, ZodUnknown>], ZodUnknown>, T>` |
|
|
125
130
|
|
|
126
|
-
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/hooks/hooks.ts#
|
|
131
|
+
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/hooks/hooks.ts#L170)
|
|
127
132
|
|
|
128
133
|
#### :gear: HookFnOrObjectSchema
|
|
129
134
|
|
|
@@ -131,7 +136,7 @@ JavaScript and TypeScript utilities for [Juno] Serverless Functions.
|
|
|
131
136
|
| ---------------------- | ------------------------------------------------------------------------------------------------------------------------------------ |
|
|
132
137
|
| `HookFnOrObjectSchema` | `<T extends z.ZodTypeAny>(hookSchema: T) => ZodUnion<[T, ZodFunction<ZodTuple<[ZodRecord<ZodString, ZodUnknown>], ZodUnknown>, T>]>` |
|
|
133
138
|
|
|
134
|
-
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/hooks/hooks.ts#
|
|
139
|
+
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/hooks/hooks.ts#L174)
|
|
135
140
|
|
|
136
141
|
#### :gear: defineHook
|
|
137
142
|
|
|
@@ -139,7 +144,7 @@ JavaScript and TypeScript utilities for [Juno] Serverless Functions.
|
|
|
139
144
|
| ------------ | ----------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
140
145
|
| `defineHook` | `{ <T extends Hook>(hook: T): T; <T extends Hook>(hook: HookFn<T>): HookFn<T>; <T extends Hook>(hook: HookFnOrObject<T>): HookFnOrObject<T>; }` |
|
|
141
146
|
|
|
142
|
-
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/hooks/hooks.ts#
|
|
147
|
+
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/hooks/hooks.ts#L178)
|
|
143
148
|
|
|
144
149
|
#### :gear: defineHook
|
|
145
150
|
|
|
@@ -147,7 +152,7 @@ JavaScript and TypeScript utilities for [Juno] Serverless Functions.
|
|
|
147
152
|
| ------------ | ----------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
148
153
|
| `defineHook` | `{ <T extends Hook>(hook: T): T; <T extends Hook>(hook: HookFn<T>): HookFn<T>; <T extends Hook>(hook: HookFnOrObject<T>): HookFnOrObject<T>; }` |
|
|
149
154
|
|
|
150
|
-
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/hooks/hooks.ts#
|
|
155
|
+
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/hooks/hooks.ts#L179)
|
|
151
156
|
|
|
152
157
|
#### :gear: defineHook
|
|
153
158
|
|
|
@@ -155,7 +160,7 @@ JavaScript and TypeScript utilities for [Juno] Serverless Functions.
|
|
|
155
160
|
| ------------ | ----------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
156
161
|
| `defineHook` | `{ <T extends Hook>(hook: T): T; <T extends Hook>(hook: HookFn<T>): HookFn<T>; <T extends Hook>(hook: HookFnOrObject<T>): HookFnOrObject<T>; }` |
|
|
157
162
|
|
|
158
|
-
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/hooks/hooks.ts#
|
|
163
|
+
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/hooks/hooks.ts#L180)
|
|
159
164
|
|
|
160
165
|
#### :gear: defineHook
|
|
161
166
|
|
|
@@ -163,7 +168,72 @@ JavaScript and TypeScript utilities for [Juno] Serverless Functions.
|
|
|
163
168
|
| ------------ | ----------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
164
169
|
| `defineHook` | `{ <T extends Hook>(hook: T): T; <T extends Hook>(hook: HookFn<T>): HookFn<T>; <T extends Hook>(hook: HookFnOrObject<T>): HookFnOrObject<T>; }` |
|
|
165
170
|
|
|
166
|
-
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/hooks/hooks.ts#
|
|
171
|
+
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/hooks/hooks.ts#L181)
|
|
172
|
+
|
|
173
|
+
#### :gear: normalizeCaller
|
|
174
|
+
|
|
175
|
+
Normalizes a user ID into a raw `Uint8Array` representation.
|
|
176
|
+
|
|
177
|
+
| Function | Type |
|
|
178
|
+
| ----------------- | ----------------------------------------------------------------------------------- |
|
|
179
|
+
| `normalizeCaller` | `(caller: Uint8Array<ArrayBufferLike> or Principal) => Uint8Array<ArrayBufferLike>` |
|
|
180
|
+
|
|
181
|
+
Parameters:
|
|
182
|
+
|
|
183
|
+
- `caller`: - The caller identity, either a raw `Uint8Array`
|
|
184
|
+
or a `Principal` instance.
|
|
185
|
+
|
|
186
|
+
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/sdk/utils/caller.utils.ts#L12)
|
|
187
|
+
|
|
188
|
+
#### :gear: getAdminControllers
|
|
189
|
+
|
|
190
|
+
Gets the list of admin controllers from the Satellite.
|
|
191
|
+
|
|
192
|
+
| Function | Type |
|
|
193
|
+
| --------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
194
|
+
| `getAdminControllers` | `() => [Uint8Array<ArrayBufferLike>, { created_at: bigint; updated_at: bigint; metadata: [string, string][]; scope: "write" or "admin"; expires_at?: bigint or undefined; }][]` |
|
|
195
|
+
|
|
196
|
+
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/sdk/controllers.sdk.ts#L15)
|
|
197
|
+
|
|
198
|
+
#### :gear: getControllers
|
|
199
|
+
|
|
200
|
+
Gets the list of controllers from the Satellite.
|
|
201
|
+
|
|
202
|
+
| Function | Type |
|
|
203
|
+
| ---------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
204
|
+
| `getControllers` | `() => [Uint8Array<ArrayBufferLike>, { created_at: bigint; updated_at: bigint; metadata: [string, string][]; scope: "write" or "admin"; expires_at?: bigint or undefined; }][]` |
|
|
205
|
+
|
|
206
|
+
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/sdk/controllers.sdk.ts#L25)
|
|
207
|
+
|
|
208
|
+
#### :gear: isAdminController
|
|
209
|
+
|
|
210
|
+
Checks if the given caller is an admin among the provided controllers.
|
|
211
|
+
|
|
212
|
+
| Function | Type |
|
|
213
|
+
| ------------------- | -------------------------------------------- |
|
|
214
|
+
| `isAdminController` | `(params: ControllerCheckParams) => boolean` |
|
|
215
|
+
|
|
216
|
+
Parameters:
|
|
217
|
+
|
|
218
|
+
- `params`: - The parameters including the caller identity
|
|
219
|
+
and the list of controllers to verify against.
|
|
220
|
+
|
|
221
|
+
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/sdk/controllers.sdk.ts#L37)
|
|
222
|
+
|
|
223
|
+
#### :gear: isController
|
|
224
|
+
|
|
225
|
+
Checks if the given caller exists among the provided controllers.
|
|
226
|
+
|
|
227
|
+
| Function | Type |
|
|
228
|
+
| -------------- | -------------------------------------------- |
|
|
229
|
+
| `isController` | `(params: ControllerCheckParams) => boolean` |
|
|
230
|
+
|
|
231
|
+
Parameters:
|
|
232
|
+
|
|
233
|
+
- `params`: - The parameters including the caller identity
|
|
234
|
+
and the list of controllers to verify against.
|
|
235
|
+
|
|
236
|
+
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/sdk/controllers.sdk.ts#L57)
|
|
167
237
|
|
|
168
238
|
#### :gear: setDocStore
|
|
169
239
|
|
|
@@ -195,7 +265,7 @@ Parameters:
|
|
|
195
265
|
- `params`: - The parameters required to delete the document,
|
|
196
266
|
including the caller, collection, key, and version of the document.
|
|
197
267
|
|
|
198
|
-
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/sdk/db.sdk.ts#
|
|
268
|
+
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/sdk/db.sdk.ts#L39)
|
|
199
269
|
|
|
200
270
|
#### :gear: decodeDocData
|
|
201
271
|
|
|
@@ -310,6 +380,12 @@ the Principal of the executing canister.
|
|
|
310
380
|
- [OnDeleteManyAssetsSchema](#gear-ondeletemanyassetsschema)
|
|
311
381
|
- [OnDeleteFilteredAssetsSchema](#gear-ondeletefilteredassetsschema)
|
|
312
382
|
- [HookSchema](#gear-hookschema)
|
|
383
|
+
- [ControllerScopeSchema](#gear-controllerscopeschema)
|
|
384
|
+
- [MetadataSchema](#gear-metadataschema)
|
|
385
|
+
- [ControllerSchema](#gear-controllerschema)
|
|
386
|
+
- [ControllerRecordSchema](#gear-controllerrecordschema)
|
|
387
|
+
- [ControllersSchema](#gear-controllersschema)
|
|
388
|
+
- [ControllerCheckParamsSchema](#gear-controllercheckparamsschema)
|
|
313
389
|
- [SetDocStoreParamsSchema](#gear-setdocstoreparamsschema)
|
|
314
390
|
- [DeleteDocStoreParamsSchema](#gear-deletedocstoreparamsschema)
|
|
315
391
|
- [IDLTypeSchema](#gear-idltypeschema)
|
|
@@ -736,6 +812,54 @@ A schema that validates a value is an Uint8Array.
|
|
|
736
812
|
|
|
737
813
|
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/hooks/hooks.ts#L144)
|
|
738
814
|
|
|
815
|
+
#### :gear: ControllerScopeSchema
|
|
816
|
+
|
|
817
|
+
| Constant | Type |
|
|
818
|
+
| ----------------------- | ----------------------------- |
|
|
819
|
+
| `ControllerScopeSchema` | `ZodEnum<["write", "admin"]>` |
|
|
820
|
+
|
|
821
|
+
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/sdk/schemas/controllers.ts#L15)
|
|
822
|
+
|
|
823
|
+
#### :gear: MetadataSchema
|
|
824
|
+
|
|
825
|
+
| Constant | Type |
|
|
826
|
+
| ---------------- | ---------------------------------------- |
|
|
827
|
+
| `MetadataSchema` | `ZodTuple<[ZodString, ZodString], null>` |
|
|
828
|
+
|
|
829
|
+
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/sdk/schemas/controllers.ts#L25)
|
|
830
|
+
|
|
831
|
+
#### :gear: ControllerSchema
|
|
832
|
+
|
|
833
|
+
| Constant | Type |
|
|
834
|
+
| ------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
835
|
+
| `ControllerSchema` | `ZodObject<{ metadata: ZodArray<ZodTuple<[ZodString, ZodString], null>, "many">; created_at: ZodBigInt; updated_at: ZodBigInt; expires_at: ZodOptional<...>; scope: ZodEnum<...>; }, "strict", ZodTypeAny, { ...; }, { ...; }>` |
|
|
836
|
+
|
|
837
|
+
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/sdk/schemas/controllers.ts#L35)
|
|
838
|
+
|
|
839
|
+
#### :gear: ControllerRecordSchema
|
|
840
|
+
|
|
841
|
+
| Constant | Type |
|
|
842
|
+
| ------------------------ | ----------------------------------------------------------------------------------------------------------------- |
|
|
843
|
+
| `ControllerRecordSchema` | `ZodTuple<[ZodType<Uint8Array<ArrayBufferLike>, ZodTypeDef, Uint8Array<ArrayBufferLike>>, ZodObject<...>], null>` |
|
|
844
|
+
|
|
845
|
+
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/sdk/schemas/controllers.ts#L79)
|
|
846
|
+
|
|
847
|
+
#### :gear: ControllersSchema
|
|
848
|
+
|
|
849
|
+
| Constant | Type |
|
|
850
|
+
| ------------------- | ----------------------------------------------------------------------------------------------------------------------------------- |
|
|
851
|
+
| `ControllersSchema` | `ZodArray<ZodTuple<[ZodType<Uint8Array<ArrayBufferLike>, ZodTypeDef, Uint8Array<ArrayBufferLike>>, ZodObject<...>], null>, "many">` |
|
|
852
|
+
|
|
853
|
+
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/sdk/schemas/controllers.ts#L89)
|
|
854
|
+
|
|
855
|
+
#### :gear: ControllerCheckParamsSchema
|
|
856
|
+
|
|
857
|
+
| Constant | Type |
|
|
858
|
+
| ----------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
|
|
859
|
+
| `ControllerCheckParamsSchema` | `ZodObject<{ caller: ZodUnion<[ZodType<Uint8Array<ArrayBufferLike>, ZodTypeDef, Uint8Array<ArrayBufferLike>>, ZodType<...>]>; controllers: ZodArray<...>; }, "strip", ZodTypeAny, { ...; }, { ...; }>` |
|
|
860
|
+
|
|
861
|
+
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/sdk/schemas/controllers.ts#L99)
|
|
862
|
+
|
|
739
863
|
#### :gear: SetDocStoreParamsSchema
|
|
740
864
|
|
|
741
865
|
| Constant | Type |
|
|
@@ -815,6 +939,8 @@ Schema for encoding the call arguments.
|
|
|
815
939
|
- [Batch](#gear-batch)
|
|
816
940
|
- [CommitBatch](#gear-commitbatch)
|
|
817
941
|
- [AssetAssertUpload](#gear-assetassertupload)
|
|
942
|
+
- [Controller](#gear-controller)
|
|
943
|
+
- [ControllerCheckParams](#gear-controllercheckparams)
|
|
818
944
|
- [DocStoreParams](#gear-docstoreparams)
|
|
819
945
|
- [CallParams](#gear-callparams)
|
|
820
946
|
|
|
@@ -907,11 +1033,11 @@ throw an error if their validation fails.
|
|
|
907
1033
|
|
|
908
1034
|
Represents the context of a document operation within a collection.
|
|
909
1035
|
|
|
910
|
-
| Property | Type | Description
|
|
911
|
-
| ------------ | -------- |
|
|
912
|
-
| `collection` | `string` | The name of the collection where the document is stored.
|
|
913
|
-
| `key` | `string` | The
|
|
914
|
-
| `data` | `T` | The data associated with the document operation.
|
|
1036
|
+
| Property | Type | Description |
|
|
1037
|
+
| ------------ | -------- | -------------------------------------------------------- |
|
|
1038
|
+
| `collection` | `string` | The name of the collection where the document is stored. |
|
|
1039
|
+
| `key` | `string` | The key identifying the document within the collection. |
|
|
1040
|
+
| `data` | `T` | The data associated with the document operation. |
|
|
915
1041
|
|
|
916
1042
|
#### :gear: AssetKey
|
|
917
1043
|
|
|
@@ -981,15 +1107,36 @@ Represents a validation context before uploading an asset.
|
|
|
981
1107
|
| `batch` | `Batch` | The batch metadata being uploaded. |
|
|
982
1108
|
| `commit_batch` | `CommitBatch` | The commit data describing headers and chunk ids. |
|
|
983
1109
|
|
|
1110
|
+
#### :gear: Controller
|
|
1111
|
+
|
|
1112
|
+
Represents a controller with access scope and associated metadata.
|
|
1113
|
+
|
|
1114
|
+
| Property | Type | Description |
|
|
1115
|
+
| ------------ | --------------------- | -------------------------------------------------------------------------------------------------- |
|
|
1116
|
+
| `metadata` | `[string, string][]` | A list of key-value metadata pairs associated with the controller. |
|
|
1117
|
+
| `created_at` | `bigint` | The timestamp when the controller was created. |
|
|
1118
|
+
| `updated_at` | `bigint` | The timestamp when the controller was last updated. |
|
|
1119
|
+
| `expires_at` | `bigint or undefined` | Optional expiration timestamp for the controller. 👉 It's a placeholder for future implementation. |
|
|
1120
|
+
| `scope` | `"write" or "admin"` | The scope assigned to the controller. |
|
|
1121
|
+
|
|
1122
|
+
#### :gear: ControllerCheckParams
|
|
1123
|
+
|
|
1124
|
+
Represents the parameters required to perform controller checks.
|
|
1125
|
+
|
|
1126
|
+
| Property | Type | Description |
|
|
1127
|
+
| ------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------- |
|
|
1128
|
+
| `caller` | `Uint8Array<ArrayBufferLike> or Principal` | The identity of the caller to verify against the controller list. |
|
|
1129
|
+
| `controllers` | `[Uint8Array<ArrayBufferLike>, { created_at: bigint; updated_at: bigint; metadata: [string, string][]; scope: "write" or "admin"; expires_at?: bigint or undefined; }][]` | The list of controllers to check against. |
|
|
1130
|
+
|
|
984
1131
|
#### :gear: DocStoreParams
|
|
985
1132
|
|
|
986
1133
|
Represents the base parameters required to access the datastore and modify a document.
|
|
987
1134
|
|
|
988
|
-
| Property | Type | Description
|
|
989
|
-
| ------------ | ------------------------------------------ |
|
|
990
|
-
| `caller` | `Uint8Array<ArrayBufferLike> or Principal` | The caller who initiate the document operation.
|
|
991
|
-
| `collection` | `string` | The name of the collection where the document is stored.
|
|
992
|
-
| `key` | `string` | The
|
|
1135
|
+
| Property | Type | Description |
|
|
1136
|
+
| ------------ | ------------------------------------------ | -------------------------------------------------------- |
|
|
1137
|
+
| `caller` | `Uint8Array<ArrayBufferLike> or Principal` | The caller who initiate the document operation. |
|
|
1138
|
+
| `collection` | `string` | The name of the collection where the document is stored. |
|
|
1139
|
+
| `key` | `string` | The key identifying the document within the collection. |
|
|
993
1140
|
|
|
994
1141
|
#### :gear: CallParams
|
|
995
1142
|
|
|
@@ -1060,6 +1207,10 @@ Type representing the parameters required to make a canister call.
|
|
|
1060
1207
|
- [Hook](#gear-hook)
|
|
1061
1208
|
- [HookFn](#gear-hookfn)
|
|
1062
1209
|
- [HookFnOrObject](#gear-hookfnorobject)
|
|
1210
|
+
- [ControllerScope](#gear-controllerscope)
|
|
1211
|
+
- [Metadata](#gear-metadata)
|
|
1212
|
+
- [ControllerRecord](#gear-controllerrecord)
|
|
1213
|
+
- [Controllers](#gear-controllers)
|
|
1063
1214
|
- [SetDocStoreParams](#gear-setdocstoreparams)
|
|
1064
1215
|
- [DeleteDocStoreParams](#gear-deletedocstoreparams)
|
|
1065
1216
|
- [IDLType](#gear-idltype)
|
|
@@ -1147,7 +1298,7 @@ A collection name where data are stored.
|
|
|
1147
1298
|
|
|
1148
1299
|
#### :gear: Key
|
|
1149
1300
|
|
|
1150
|
-
A
|
|
1301
|
+
A key identifier within a collection.
|
|
1151
1302
|
|
|
1152
1303
|
| Type | Type |
|
|
1153
1304
|
| ----- | --------------------------- |
|
|
@@ -1526,9 +1677,9 @@ An assertion that runs before an asset is deleted.
|
|
|
1526
1677
|
|
|
1527
1678
|
All assertions definitions.
|
|
1528
1679
|
|
|
1529
|
-
| Type | Type
|
|
1530
|
-
| -------- |
|
|
1531
|
-
| `Assert` | `AssertSetDoc or AssertDeleteDoc` |
|
|
1680
|
+
| Type | Type |
|
|
1681
|
+
| -------- | --------------------------------------------------------------------------- |
|
|
1682
|
+
| `Assert` | `AssertSetDoc or AssertDeleteDoc or AssertUploadAsset or AssertDeleteAsset` |
|
|
1532
1683
|
|
|
1533
1684
|
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/hooks/assertions.ts#L94)
|
|
1534
1685
|
|
|
@@ -1652,9 +1803,9 @@ A hook that runs when a filtered set of assets is deleted based on query conditi
|
|
|
1652
1803
|
|
|
1653
1804
|
All hooks definitions.
|
|
1654
1805
|
|
|
1655
|
-
| Type | Type
|
|
1656
|
-
| ------ |
|
|
1657
|
-
| `Hook` | `OnSetDoc or OnSetManyDocs or OnDeleteDoc or OnDeleteManyDocs or OnDeleteFilteredDocs` |
|
|
1806
|
+
| Type | Type |
|
|
1807
|
+
| ------ | ---- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
1808
|
+
| `Hook` | ` | OnSetDoc or OnSetManyDocs or OnDeleteDoc or OnDeleteManyDocs or OnDeleteFilteredDocs or OnUploadAsset or OnDeleteAsset or OnDeleteManyAssets or OnDeleteFilteredAssets` |
|
|
1658
1809
|
|
|
1659
1810
|
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/hooks/hooks.ts#L159)
|
|
1660
1811
|
|
|
@@ -1664,7 +1815,7 @@ All hooks definitions.
|
|
|
1664
1815
|
| -------- | ------------------------------------------------- |
|
|
1665
1816
|
| `HookFn` | `(hook: z.infer<typeof SatelliteEnvSchema>) => T` |
|
|
1666
1817
|
|
|
1667
|
-
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/hooks/hooks.ts#
|
|
1818
|
+
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/hooks/hooks.ts#L172)
|
|
1668
1819
|
|
|
1669
1820
|
#### :gear: HookFnOrObject
|
|
1670
1821
|
|
|
@@ -1672,7 +1823,47 @@ All hooks definitions.
|
|
|
1672
1823
|
| ---------------- | ---------------- |
|
|
1673
1824
|
| `HookFnOrObject` | `T or HookFn<T>` |
|
|
1674
1825
|
|
|
1675
|
-
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/hooks/hooks.ts#
|
|
1826
|
+
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/hooks/hooks.ts#L176)
|
|
1827
|
+
|
|
1828
|
+
#### :gear: ControllerScope
|
|
1829
|
+
|
|
1830
|
+
Represents the permission scope of a controller.
|
|
1831
|
+
|
|
1832
|
+
| Type | Type |
|
|
1833
|
+
| ----------------- | --------------------------------------- |
|
|
1834
|
+
| `ControllerScope` | `z.infer<typeof ControllerScopeSchema>` |
|
|
1835
|
+
|
|
1836
|
+
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/sdk/schemas/controllers.ts#L20)
|
|
1837
|
+
|
|
1838
|
+
#### :gear: Metadata
|
|
1839
|
+
|
|
1840
|
+
Represents a single metadata entry as a key-value tuple.
|
|
1841
|
+
|
|
1842
|
+
| Type | Type |
|
|
1843
|
+
| ---------- | -------------------------------- |
|
|
1844
|
+
| `Metadata` | `z.infer<typeof MetadataSchema>` |
|
|
1845
|
+
|
|
1846
|
+
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/sdk/schemas/controllers.ts#L30)
|
|
1847
|
+
|
|
1848
|
+
#### :gear: ControllerRecord
|
|
1849
|
+
|
|
1850
|
+
Represents a tuple containing the principal ID and associated controller data.
|
|
1851
|
+
|
|
1852
|
+
| Type | Type |
|
|
1853
|
+
| ------------------ | ---------------------------------------- |
|
|
1854
|
+
| `ControllerRecord` | `z.infer<typeof ControllerRecordSchema>` |
|
|
1855
|
+
|
|
1856
|
+
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/sdk/schemas/controllers.ts#L84)
|
|
1857
|
+
|
|
1858
|
+
#### :gear: Controllers
|
|
1859
|
+
|
|
1860
|
+
Represents a list of controllers.
|
|
1861
|
+
|
|
1862
|
+
| Type | Type |
|
|
1863
|
+
| ------------- | ----------------------------------- |
|
|
1864
|
+
| `Controllers` | `z.infer<typeof ControllersSchema>` |
|
|
1865
|
+
|
|
1866
|
+
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/sdk/schemas/controllers.ts#L94)
|
|
1676
1867
|
|
|
1677
1868
|
#### :gear: SetDocStoreParams
|
|
1678
1869
|
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import{a,b as p,c}from"./chunk-CCKUQNB5.js";import*as e from"zod";var r=e.bigint(),t=e.bigint(),n=p,h=c,d=e.string(),f=e.string(),i=e.string().max(1024);import*as o from"zod";var s=a,m=o.object({owner:n,data:s,description:i.optional(),created_at:r,updated_at:r,version:t.optional()}).strict(),l=m.optional(),w=o.object({data:s,description:i.optional(),version:t.optional()}).strict(),R=o.object({version:t.optional()}).strict();export{r as a,t as b,n as c,h as d,d as e,f,i as g,s as h,m as i,l as j,w as k,R as l};
|
|
2
|
-
//# sourceMappingURL=chunk-
|
|
2
|
+
//# sourceMappingURL=chunk-367GY4VX.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["src/schemas/satellite.ts", "src/schemas/db.ts"],
|
|
4
|
+
"sourcesContent": ["import * as z from 'zod';\nimport {PrincipalSchema, RawPrincipalSchema} from './candid';\n\n/**\n * @see Timestamp\n */\nexport const TimestampSchema = z.bigint();\n\n/**\n * Represents a timestamp in nanoseconds since the Unix epoch.\n *\n * Used for tracking when events occur, such as document creation and updates.\n */\nexport type Timestamp = z.infer<typeof TimestampSchema>;\n\n/**\n * @see Version\n */\nexport const VersionSchema = z.bigint();\n\n/**\n * Represents a version number for tracking changes.\n *\n * This is typically incremented with each update to ensure consistency.\n */\nexport type Version = z.infer<typeof VersionSchema>;\n\n/**\n * @see RawUserId\n */\nexport const RawUserIdSchema = RawPrincipalSchema;\n\n/**\n * Represents a raw user identifier.\n *\n * This is a principal associated with a user.\n */\nexport type RawUserId = z.infer<typeof RawUserIdSchema>;\n\n/**\n * @see UserId\n */\nexport const UserIdSchema = PrincipalSchema;\n\n/**\n * Represents a user identifier.\n *\n * This is a principal associated with a user.\n */\nexport type UserId = z.infer<typeof UserIdSchema>;\n\n/**\n * @see Collection\n */\nexport const CollectionSchema = z.string();\n\n/**\n * A collection name where data are stored.\n */\nexport type Collection = z.infer<typeof CollectionSchema>;\n\n/**\n * @see Key\n */\nexport const KeySchema = z.string();\n\n/**\n * A key identifier within a collection.\n */\nexport type Key = z.infer<typeof KeySchema>;\n\n/**\n * @see Description\n */\nexport const DescriptionSchema = z.string().max(1024);\n\n/**\n * Represents a description with a maximum length of 1024 characters.\n * Used for document and asset fields which can be useful for search purpose.\n */\nexport type Description = z.infer<typeof DescriptionSchema>;\n", "import * as z from 'zod';\nimport {Uint8ArraySchema} from './candid';\nimport {\n Description,\n DescriptionSchema,\n type RawUserId,\n RawUserIdSchema,\n type Timestamp,\n TimestampSchema,\n type Version,\n VersionSchema\n} from './satellite';\n\n/**\n * @see RawData\n */\nexport const RawDataSchema = Uint8ArraySchema;\n\n/**\n * Represents raw binary data.\n *\n * This is used to store structured data in a document.\n */\nexport type RawData = z.infer<typeof Uint8ArraySchema>;\n\n/**\n * @see Doc\n */\nexport const DocSchema = z\n .object({\n owner: RawUserIdSchema,\n data: RawDataSchema,\n description: DescriptionSchema.optional(),\n created_at: TimestampSchema,\n updated_at: TimestampSchema,\n version: VersionSchema.optional()\n })\n .strict();\n\n/**\n * Represents a document stored in a collection.\n */\nexport interface Doc {\n /**\n * The user who owns this document.\n */\n owner: RawUserId;\n\n /**\n * The raw data of the document.\n */\n data: RawData;\n\n /**\n * An optional description of the document.\n */\n description?: Description;\n\n /**\n * The timestamp when the document was first created.\n */\n created_at: Timestamp;\n\n /**\n * The timestamp when the document was last updated.\n */\n updated_at: Timestamp;\n\n /**\n * The version number of the document, used for consistency checks.\n * If not provided, it's assumed to be the first version.\n */\n version?: Version;\n}\n\n/**\n * @see OptionDoc\n */\nexport const OptionDocSchema = DocSchema.optional();\n\n/**\n * A shorthand for a document that might or not be defined.\n */\nexport type OptionDoc = Doc | undefined;\n\n/**\n * @see SetDoc\n */\nexport const SetDocSchema = z\n .object({\n data: RawDataSchema,\n description: DescriptionSchema.optional(),\n version: VersionSchema.optional()\n })\n .strict();\n\n/**\n * Represents the proposed version of a document to be created or updated.\n * This can be validated before allowing the operation.\n */\nexport interface SetDoc {\n /**\n * The raw data of the document.\n */\n data: RawData;\n\n /**\n * An optional description of the document.\n */\n description?: Description;\n\n /**\n * The expected version number to ensure consistency.\n */\n version?: Version;\n}\n\n/**\n * @see DelDoc\n */\nexport const DelDocSchema = z\n .object({\n version: VersionSchema.optional()\n })\n .strict();\n\n/**\n * Represents the proposed version of a document to be deleted.\n * This can be validated before allowing the operation.\n */\nexport interface DelDoc {\n /**\n * The expected version number to ensure consistency.\n */\n version?: Version;\n}\n"],
|
|
5
|
+
"mappings": "4CAAA,UAAYA,MAAO,MAMZ,IAAMC,EAAoB,SAAO,EAY3BC,EAAkB,SAAO,EAYzBC,EAAkBC,EAYlBC,EAAeC,EAYfC,EAAqB,SAAO,EAU5BC,EAAc,SAAO,EAUrBC,EAAsB,SAAO,EAAE,IAAI,IAAI,EC1EpD,UAAYC,MAAO,MAgBZ,IAAMC,EAAgBC,EAYhBC,EACV,SAAO,CACN,MAAOC,EACP,KAAMH,EACN,YAAaI,EAAkB,SAAS,EACxC,WAAYC,EACZ,WAAYA,EACZ,QAASC,EAAc,SAAS,CAClC,CAAC,EACA,OAAO,EAyCGC,EAAkBL,EAAU,SAAS,EAUrCM,EACV,SAAO,CACN,KAAMR,EACN,YAAaI,EAAkB,SAAS,EACxC,QAASE,EAAc,SAAS,CAClC,CAAC,EACA,OAAO,EA0BGG,EACV,SAAO,CACN,QAASH,EAAc,SAAS,CAClC,CAAC,EACA,OAAO",
|
|
6
|
+
"names": ["z", "TimestampSchema", "VersionSchema", "RawUserIdSchema", "RawPrincipalSchema", "UserIdSchema", "PrincipalSchema", "CollectionSchema", "KeySchema", "DescriptionSchema", "z", "RawDataSchema", "Uint8ArraySchema", "DocSchema", "RawUserIdSchema", "DescriptionSchema", "TimestampSchema", "VersionSchema", "OptionDocSchema", "SetDocSchema", "DelDocSchema"]
|
|
7
|
+
}
|
package/global.d.ts
CHANGED
|
@@ -1,10 +1,22 @@
|
|
|
1
1
|
import type {DelDoc, RawData, SetDoc} from './schemas/db';
|
|
2
2
|
import type {Collection, Key, RawPrincipal, RawUserId} from './schemas/satellite';
|
|
3
|
+
import {Controllers} from './sdk/schemas/controllers';
|
|
3
4
|
|
|
4
5
|
declare global {
|
|
5
6
|
function __juno_satellite_datastore_raw_data_to_text(data: RawData): string;
|
|
6
7
|
function __juno_satellite_datastore_raw_data_from_text(data: string): RawData;
|
|
7
8
|
|
|
9
|
+
function __juno_satellite_datastore_get_admin_controllers(): Controllers;
|
|
10
|
+
function __juno_satellite_datastore_get_controllers(): Controllers;
|
|
11
|
+
function __juno_satellite_datastore_is_admin_controller(
|
|
12
|
+
caller: RawUserId,
|
|
13
|
+
controllers: Controllers
|
|
14
|
+
): boolean;
|
|
15
|
+
function __juno_satellite_datastore_is_controller(
|
|
16
|
+
caller: RawUserId,
|
|
17
|
+
controllers: Controllers
|
|
18
|
+
): boolean;
|
|
19
|
+
|
|
8
20
|
function __juno_satellite_datastore_set_doc_store(
|
|
9
21
|
caller: RawUserId,
|
|
10
22
|
collection: Collection,
|