@junobuild/functions 0.0.7 → 0.0.8
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 +153 -69
- package/chunk-MKW7CALF.js +2 -0
- package/chunk-MKW7CALF.js.map +7 -0
- package/hooks/schemas/context.d.ts +24 -0
- package/ic-cdk.js +1 -6
- package/ic-cdk.js.map +4 -4
- package/index.js +1 -1
- package/index.js.map +4 -4
- package/package.json +5 -1
- package/schemas/candid.d.ts +10 -3
- package/schemas/core.d.ts +10 -0
- package/sdk/schemas/db.d.ts +3 -3
- package/sdk.js +1 -1
- package/sdk.js.map +4 -4
- package/chunk-OVO3T2DM.js +0 -2
- package/chunk-OVO3T2DM.js.map +0 -7
package/README.md
CHANGED
|
@@ -15,6 +15,8 @@ JavaScript and TypeScript utilities for [Juno] Serverless Functions.
|
|
|
15
15
|
### :toolbox: Functions
|
|
16
16
|
|
|
17
17
|
- [HookContextSchema](#gear-hookcontextschema)
|
|
18
|
+
- [AssertFunctionSchema](#gear-assertfunctionschema)
|
|
19
|
+
- [RunFunctionSchema](#gear-runfunctionschema)
|
|
18
20
|
- [DocContextSchema](#gear-doccontextschema)
|
|
19
21
|
- [AssertFnSchema](#gear-assertfnschema)
|
|
20
22
|
- [AssertFnOrObjectSchema](#gear-assertfnorobjectschema)
|
|
@@ -41,6 +43,22 @@ JavaScript and TypeScript utilities for [Juno] Serverless Functions.
|
|
|
41
43
|
|
|
42
44
|
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/hooks/schemas/context.ts#L7)
|
|
43
45
|
|
|
46
|
+
#### :gear: AssertFunctionSchema
|
|
47
|
+
|
|
48
|
+
| Function | Type |
|
|
49
|
+
| ---------------------- | ----------------------------------------------------------------------------------------------- |
|
|
50
|
+
| `AssertFunctionSchema` | `<T extends z.ZodTypeAny>(contextSchema: T) => ZodFunction<ZodTuple<[T], ZodUnknown>, ZodVoid>` |
|
|
51
|
+
|
|
52
|
+
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/hooks/schemas/context.ts#L32)
|
|
53
|
+
|
|
54
|
+
#### :gear: RunFunctionSchema
|
|
55
|
+
|
|
56
|
+
| Function | Type |
|
|
57
|
+
| ------------------- | ----------------------------------------------------------------------------------------------------------- |
|
|
58
|
+
| `RunFunctionSchema` | `<T extends z.ZodTypeAny>(contextSchema: T) => ZodFunction<ZodTuple<[T], ZodUnknown>, ZodPromise<ZodVoid>>` |
|
|
59
|
+
|
|
60
|
+
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/hooks/schemas/context.ts#L47)
|
|
61
|
+
|
|
44
62
|
#### :gear: DocContextSchema
|
|
45
63
|
|
|
46
64
|
| Function | Type |
|
|
@@ -55,7 +73,7 @@ JavaScript and TypeScript utilities for [Juno] Serverless Functions.
|
|
|
55
73
|
| ---------------- | ----------------------------------------------------------------------------------------------------------------------- |
|
|
56
74
|
| `AssertFnSchema` | `<T extends z.ZodTypeAny>(assertSchema: T) => ZodFunction<ZodTuple<[ZodRecord<ZodString, ZodUnknown>], ZodUnknown>, T>` |
|
|
57
75
|
|
|
58
|
-
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/hooks/db/assertions.ts#
|
|
76
|
+
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/hooks/db/assertions.ts#L44)
|
|
59
77
|
|
|
60
78
|
#### :gear: AssertFnOrObjectSchema
|
|
61
79
|
|
|
@@ -63,7 +81,7 @@ JavaScript and TypeScript utilities for [Juno] Serverless Functions.
|
|
|
63
81
|
| ------------------------ | -------------------------------------------------------------------------------------------------------------------------------------- |
|
|
64
82
|
| `AssertFnOrObjectSchema` | `<T extends z.ZodTypeAny>(assertSchema: T) => ZodUnion<[T, ZodFunction<ZodTuple<[ZodRecord<ZodString, ZodUnknown>], ZodUnknown>, T>]>` |
|
|
65
83
|
|
|
66
|
-
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/hooks/db/assertions.ts#
|
|
84
|
+
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/hooks/db/assertions.ts#L48)
|
|
67
85
|
|
|
68
86
|
#### :gear: defineAssert
|
|
69
87
|
|
|
@@ -71,7 +89,7 @@ JavaScript and TypeScript utilities for [Juno] Serverless Functions.
|
|
|
71
89
|
| -------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
72
90
|
| `defineAssert` | `{ <T extends Assert>(assert: T): T; <T extends Assert>(assert: AssertFn<T>): AssertFn<T>; <T extends Assert>(assert: AssertFnOrObject<T>): AssertFnOrObject<T>; }` |
|
|
73
91
|
|
|
74
|
-
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/hooks/db/assertions.ts#
|
|
92
|
+
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/hooks/db/assertions.ts#L52)
|
|
75
93
|
|
|
76
94
|
#### :gear: defineAssert
|
|
77
95
|
|
|
@@ -79,7 +97,7 @@ JavaScript and TypeScript utilities for [Juno] Serverless Functions.
|
|
|
79
97
|
| -------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
80
98
|
| `defineAssert` | `{ <T extends Assert>(assert: T): T; <T extends Assert>(assert: AssertFn<T>): AssertFn<T>; <T extends Assert>(assert: AssertFnOrObject<T>): AssertFnOrObject<T>; }` |
|
|
81
99
|
|
|
82
|
-
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/hooks/db/assertions.ts#
|
|
100
|
+
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/hooks/db/assertions.ts#L53)
|
|
83
101
|
|
|
84
102
|
#### :gear: defineAssert
|
|
85
103
|
|
|
@@ -87,7 +105,7 @@ JavaScript and TypeScript utilities for [Juno] Serverless Functions.
|
|
|
87
105
|
| -------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
88
106
|
| `defineAssert` | `{ <T extends Assert>(assert: T): T; <T extends Assert>(assert: AssertFn<T>): AssertFn<T>; <T extends Assert>(assert: AssertFnOrObject<T>): AssertFnOrObject<T>; }` |
|
|
89
107
|
|
|
90
|
-
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/hooks/db/assertions.ts#
|
|
108
|
+
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/hooks/db/assertions.ts#L54)
|
|
91
109
|
|
|
92
110
|
#### :gear: defineAssert
|
|
93
111
|
|
|
@@ -95,7 +113,7 @@ JavaScript and TypeScript utilities for [Juno] Serverless Functions.
|
|
|
95
113
|
| -------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
96
114
|
| `defineAssert` | `{ <T extends Assert>(assert: T): T; <T extends Assert>(assert: AssertFn<T>): AssertFn<T>; <T extends Assert>(assert: AssertFnOrObject<T>): AssertFnOrObject<T>; }` |
|
|
97
115
|
|
|
98
|
-
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/hooks/db/assertions.ts#
|
|
116
|
+
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/hooks/db/assertions.ts#L55)
|
|
99
117
|
|
|
100
118
|
#### :gear: HookFnSchema
|
|
101
119
|
|
|
@@ -103,7 +121,7 @@ JavaScript and TypeScript utilities for [Juno] Serverless Functions.
|
|
|
103
121
|
| -------------- | --------------------------------------------------------------------------------------------------------------------- |
|
|
104
122
|
| `HookFnSchema` | `<T extends z.ZodTypeAny>(hookSchema: T) => ZodFunction<ZodTuple<[ZodRecord<ZodString, ZodUnknown>], ZodUnknown>, T>` |
|
|
105
123
|
|
|
106
|
-
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/hooks/db/hooks.ts#
|
|
124
|
+
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/hooks/db/hooks.ts#L44)
|
|
107
125
|
|
|
108
126
|
#### :gear: HookFnOrObjectSchema
|
|
109
127
|
|
|
@@ -111,7 +129,7 @@ JavaScript and TypeScript utilities for [Juno] Serverless Functions.
|
|
|
111
129
|
| ---------------------- | ------------------------------------------------------------------------------------------------------------------------------------ |
|
|
112
130
|
| `HookFnOrObjectSchema` | `<T extends z.ZodTypeAny>(hookSchema: T) => ZodUnion<[T, ZodFunction<ZodTuple<[ZodRecord<ZodString, ZodUnknown>], ZodUnknown>, T>]>` |
|
|
113
131
|
|
|
114
|
-
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/hooks/db/hooks.ts#
|
|
132
|
+
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/hooks/db/hooks.ts#L48)
|
|
115
133
|
|
|
116
134
|
#### :gear: defineHook
|
|
117
135
|
|
|
@@ -119,7 +137,7 @@ JavaScript and TypeScript utilities for [Juno] Serverless Functions.
|
|
|
119
137
|
| ------------ | ----------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
120
138
|
| `defineHook` | `{ <T extends Hook>(hook: T): T; <T extends Hook>(hook: HookFn<T>): HookFn<T>; <T extends Hook>(hook: HookFnOrObject<T>): HookFnOrObject<T>; }` |
|
|
121
139
|
|
|
122
|
-
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/hooks/db/hooks.ts#
|
|
140
|
+
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/hooks/db/hooks.ts#L52)
|
|
123
141
|
|
|
124
142
|
#### :gear: defineHook
|
|
125
143
|
|
|
@@ -127,7 +145,7 @@ JavaScript and TypeScript utilities for [Juno] Serverless Functions.
|
|
|
127
145
|
| ------------ | ----------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
128
146
|
| `defineHook` | `{ <T extends Hook>(hook: T): T; <T extends Hook>(hook: HookFn<T>): HookFn<T>; <T extends Hook>(hook: HookFnOrObject<T>): HookFnOrObject<T>; }` |
|
|
129
147
|
|
|
130
|
-
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/hooks/db/hooks.ts#
|
|
148
|
+
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/hooks/db/hooks.ts#L53)
|
|
131
149
|
|
|
132
150
|
#### :gear: defineHook
|
|
133
151
|
|
|
@@ -135,7 +153,7 @@ JavaScript and TypeScript utilities for [Juno] Serverless Functions.
|
|
|
135
153
|
| ------------ | ----------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
136
154
|
| `defineHook` | `{ <T extends Hook>(hook: T): T; <T extends Hook>(hook: HookFn<T>): HookFn<T>; <T extends Hook>(hook: HookFnOrObject<T>): HookFnOrObject<T>; }` |
|
|
137
155
|
|
|
138
|
-
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/hooks/db/hooks.ts#
|
|
156
|
+
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/hooks/db/hooks.ts#L54)
|
|
139
157
|
|
|
140
158
|
#### :gear: defineHook
|
|
141
159
|
|
|
@@ -143,7 +161,7 @@ JavaScript and TypeScript utilities for [Juno] Serverless Functions.
|
|
|
143
161
|
| ------------ | ----------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
144
162
|
| `defineHook` | `{ <T extends Hook>(hook: T): T; <T extends Hook>(hook: HookFn<T>): HookFn<T>; <T extends Hook>(hook: HookFnOrObject<T>): HookFnOrObject<T>; }` |
|
|
145
163
|
|
|
146
|
-
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/hooks/db/hooks.ts#
|
|
164
|
+
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/hooks/db/hooks.ts#L55)
|
|
147
165
|
|
|
148
166
|
#### :gear: setDocStore
|
|
149
167
|
|
|
@@ -151,16 +169,16 @@ Stores or updates a document in the datastore.
|
|
|
151
169
|
|
|
152
170
|
The data must have been encoded - using encodeDocData - before calling this function.
|
|
153
171
|
|
|
154
|
-
| Function | Type
|
|
155
|
-
| ------------- |
|
|
156
|
-
| `setDocStore` | `(params: { caller: Uint8Array<ArrayBufferLike
|
|
172
|
+
| Function | Type |
|
|
173
|
+
| ------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
174
|
+
| `setDocStore` | `(params: { caller: Uint8Array<ArrayBufferLike> or Principal; collection: string; doc: { data: Uint8Array<ArrayBufferLike>; key: string; description?: string or undefined; version?: bigint or undefined; }; }) => void` |
|
|
157
175
|
|
|
158
176
|
Parameters:
|
|
159
177
|
|
|
160
178
|
- `params`: - The parameters required to store the document,
|
|
161
179
|
including the caller, collection, key, and document data.
|
|
162
180
|
|
|
163
|
-
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/sdk/db.sdk.ts#
|
|
181
|
+
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/sdk/db.sdk.ts#L15)
|
|
164
182
|
|
|
165
183
|
#### :gear: decodeDocData
|
|
166
184
|
|
|
@@ -207,11 +225,13 @@ the Principal of the executing canister.
|
|
|
207
225
|
### :wrench: Constants
|
|
208
226
|
|
|
209
227
|
- [CollectionsSchema](#gear-collectionsschema)
|
|
228
|
+
- [RawPrincipalSchema](#gear-rawprincipalschema)
|
|
229
|
+
- [PrincipalSchema](#gear-principalschema)
|
|
210
230
|
- [TimestampSchema](#gear-timestampschema)
|
|
211
231
|
- [VersionSchema](#gear-versionschema)
|
|
212
232
|
- [RawDataSchema](#gear-rawdataschema)
|
|
213
|
-
- [RawPrincipalSchema](#gear-rawprincipalschema)
|
|
214
233
|
- [RawUserIdSchema](#gear-rawuseridschema)
|
|
234
|
+
- [UserIdSchema](#gear-useridschema)
|
|
215
235
|
- [CollectionSchema](#gear-collectionschema)
|
|
216
236
|
- [KeySchema](#gear-keyschema)
|
|
217
237
|
- [DocDescriptionSchema](#gear-docdescriptionschema)
|
|
@@ -237,13 +257,29 @@ the Principal of the executing canister.
|
|
|
237
257
|
|
|
238
258
|
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/hooks/schemas/collections.ts#L6)
|
|
239
259
|
|
|
260
|
+
#### :gear: RawPrincipalSchema
|
|
261
|
+
|
|
262
|
+
| Constant | Type |
|
|
263
|
+
| -------------------- | ------------------------------------------------------------------------------- |
|
|
264
|
+
| `RawPrincipalSchema` | `ZodType<Uint8Array<ArrayBufferLike>, ZodTypeDef, Uint8Array<ArrayBufferLike>>` |
|
|
265
|
+
|
|
266
|
+
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/schemas/candid.ts#L7)
|
|
267
|
+
|
|
268
|
+
#### :gear: PrincipalSchema
|
|
269
|
+
|
|
270
|
+
| Constant | Type |
|
|
271
|
+
| ----------------- | ------------------------------------------- |
|
|
272
|
+
| `PrincipalSchema` | `ZodType<Principal, ZodTypeDef, Principal>` |
|
|
273
|
+
|
|
274
|
+
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/schemas/candid.ts#L19)
|
|
275
|
+
|
|
240
276
|
#### :gear: TimestampSchema
|
|
241
277
|
|
|
242
278
|
| Constant | Type |
|
|
243
279
|
| ----------------- | ----------- |
|
|
244
280
|
| `TimestampSchema` | `ZodBigInt` |
|
|
245
281
|
|
|
246
|
-
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/schemas/core.ts#
|
|
282
|
+
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/schemas/core.ts#L7)
|
|
247
283
|
|
|
248
284
|
#### :gear: VersionSchema
|
|
249
285
|
|
|
@@ -251,7 +287,7 @@ the Principal of the executing canister.
|
|
|
251
287
|
| --------------- | ----------- |
|
|
252
288
|
| `VersionSchema` | `ZodBigInt` |
|
|
253
289
|
|
|
254
|
-
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/schemas/core.ts#
|
|
290
|
+
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/schemas/core.ts#L19)
|
|
255
291
|
|
|
256
292
|
#### :gear: RawDataSchema
|
|
257
293
|
|
|
@@ -259,15 +295,7 @@ the Principal of the executing canister.
|
|
|
259
295
|
| --------------- | ------------------------------------------------------------------------------- |
|
|
260
296
|
| `RawDataSchema` | `ZodType<Uint8Array<ArrayBufferLike>, ZodTypeDef, Uint8Array<ArrayBufferLike>>` |
|
|
261
297
|
|
|
262
|
-
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/schemas/core.ts#
|
|
263
|
-
|
|
264
|
-
#### :gear: RawPrincipalSchema
|
|
265
|
-
|
|
266
|
-
| Constant | Type |
|
|
267
|
-
| -------------------- | ------------------------------------------------------------------------------- |
|
|
268
|
-
| `RawPrincipalSchema` | `ZodType<Uint8Array<ArrayBufferLike>, ZodTypeDef, Uint8Array<ArrayBufferLike>>` |
|
|
269
|
-
|
|
270
|
-
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/schemas/core.ts#L44)
|
|
298
|
+
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/schemas/core.ts#L31)
|
|
271
299
|
|
|
272
300
|
#### :gear: RawUserIdSchema
|
|
273
301
|
|
|
@@ -275,7 +303,15 @@ the Principal of the executing canister.
|
|
|
275
303
|
| ----------------- | ------------------------------------------------------------------------------- |
|
|
276
304
|
| `RawUserIdSchema` | `ZodType<Uint8Array<ArrayBufferLike>, ZodTypeDef, Uint8Array<ArrayBufferLike>>` |
|
|
277
305
|
|
|
278
|
-
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/schemas/core.ts#
|
|
306
|
+
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/schemas/core.ts#L45)
|
|
307
|
+
|
|
308
|
+
#### :gear: UserIdSchema
|
|
309
|
+
|
|
310
|
+
| Constant | Type |
|
|
311
|
+
| -------------- | ------------------------------------------- |
|
|
312
|
+
| `UserIdSchema` | `ZodType<Principal, ZodTypeDef, Principal>` |
|
|
313
|
+
|
|
314
|
+
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/schemas/core.ts#L57)
|
|
279
315
|
|
|
280
316
|
#### :gear: CollectionSchema
|
|
281
317
|
|
|
@@ -283,7 +319,7 @@ the Principal of the executing canister.
|
|
|
283
319
|
| ------------------ | ----------- |
|
|
284
320
|
| `CollectionSchema` | `ZodString` |
|
|
285
321
|
|
|
286
|
-
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/schemas/core.ts#
|
|
322
|
+
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/schemas/core.ts#L69)
|
|
287
323
|
|
|
288
324
|
#### :gear: KeySchema
|
|
289
325
|
|
|
@@ -291,7 +327,7 @@ the Principal of the executing canister.
|
|
|
291
327
|
| ----------- | ----------- |
|
|
292
328
|
| `KeySchema` | `ZodString` |
|
|
293
329
|
|
|
294
|
-
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/schemas/core.ts#
|
|
330
|
+
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/schemas/core.ts#L79)
|
|
295
331
|
|
|
296
332
|
#### :gear: DocDescriptionSchema
|
|
297
333
|
|
|
@@ -363,7 +399,7 @@ the Principal of the executing canister.
|
|
|
363
399
|
| -------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
364
400
|
| `AssertSetDocSchema` | `ZodObject<extendShape<{ collections: ZodArray<ZodString, "many">; }, { assert: ZodFunction<ZodTuple<[ZodObject<{ caller: ZodType<Uint8Array<ArrayBufferLike>, ZodTypeDef, Uint8Array<...>>; data: ZodObject<...>; }, "strict", ZodTypeAny, { ...; }, { ...; }>], ZodUnknown>, ZodVoid>; }>, "strict", ZodTypeAny, { ...; }, {...` |
|
|
365
401
|
|
|
366
|
-
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/hooks/db/assertions.ts#
|
|
402
|
+
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/hooks/db/assertions.ts#L26)
|
|
367
403
|
|
|
368
404
|
#### :gear: AssertSchema
|
|
369
405
|
|
|
@@ -371,7 +407,7 @@ the Principal of the executing canister.
|
|
|
371
407
|
| -------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
372
408
|
| `AssertSchema` | `ZodObject<extendShape<{ collections: ZodArray<ZodString, "many">; }, { assert: ZodFunction<ZodTuple<[ZodObject<{ caller: ZodType<Uint8Array<ArrayBufferLike>, ZodTypeDef, Uint8Array<...>>; data: ZodObject<...>; }, "strict", ZodTypeAny, { ...; }, { ...; }>], ZodUnknown>, ZodVoid>; }>, "strict", ZodTypeAny, { ...; }, {...` |
|
|
373
409
|
|
|
374
|
-
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/hooks/db/assertions.ts#
|
|
410
|
+
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/hooks/db/assertions.ts#L37)
|
|
375
411
|
|
|
376
412
|
#### :gear: OnSetDocSchema
|
|
377
413
|
|
|
@@ -379,7 +415,7 @@ the Principal of the executing canister.
|
|
|
379
415
|
| ---------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
380
416
|
| `OnSetDocSchema` | `ZodObject<extendShape<{ collections: ZodArray<ZodString, "many">; }, { run: ZodFunction<ZodTuple<[ZodObject<{ caller: ZodType<Uint8Array<ArrayBufferLike>, ZodTypeDef, Uint8Array<...>>; data: ZodObject<...>; }, "strict", ZodTypeAny, { ...; }, { ...; }>], ZodUnknown>, ZodPromise<...>>; }>, "strict", ZodTypeAny, { ...;...` |
|
|
381
417
|
|
|
382
|
-
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/hooks/db/hooks.ts#
|
|
418
|
+
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/hooks/db/hooks.ts#L26)
|
|
383
419
|
|
|
384
420
|
#### :gear: HookSchema
|
|
385
421
|
|
|
@@ -387,7 +423,7 @@ the Principal of the executing canister.
|
|
|
387
423
|
| ------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
388
424
|
| `HookSchema` | `ZodObject<extendShape<{ collections: ZodArray<ZodString, "many">; }, { run: ZodFunction<ZodTuple<[ZodObject<{ caller: ZodType<Uint8Array<ArrayBufferLike>, ZodTypeDef, Uint8Array<...>>; data: ZodObject<...>; }, "strict", ZodTypeAny, { ...; }, { ...; }>], ZodUnknown>, ZodPromise<...>>; }>, "strict", ZodTypeAny, { ...;...` |
|
|
389
425
|
|
|
390
|
-
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/hooks/db/hooks.ts#
|
|
426
|
+
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/hooks/db/hooks.ts#L37)
|
|
391
427
|
|
|
392
428
|
#### :gear: SetDocSchema
|
|
393
429
|
|
|
@@ -395,27 +431,31 @@ the Principal of the executing canister.
|
|
|
395
431
|
| -------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
396
432
|
| `SetDocSchema` | `ZodObject<{ key: ZodString; description: ZodOptional<ZodString>; data: ZodType<Uint8Array<ArrayBufferLike>, ZodTypeDef, Uint8Array<...>>; version: ZodOptional<...>; }, "strict", ZodTypeAny, { ...; }, { ...; }>` |
|
|
397
433
|
|
|
398
|
-
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/sdk/schemas/db.ts#
|
|
434
|
+
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/sdk/schemas/db.ts#L15)
|
|
399
435
|
|
|
400
436
|
#### :gear: SetDocStoreParamsSchema
|
|
401
437
|
|
|
402
|
-
| Constant | Type
|
|
403
|
-
| ------------------------- |
|
|
404
|
-
| `SetDocStoreParamsSchema` | `ZodObject<{ caller: ZodType<Uint8Array<ArrayBufferLike>, ZodTypeDef, Uint8Array<ArrayBufferLike
|
|
438
|
+
| Constant | Type |
|
|
439
|
+
| ------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
440
|
+
| `SetDocStoreParamsSchema` | `ZodObject<{ caller: ZodUnion<[ZodType<Uint8Array<ArrayBufferLike>, ZodTypeDef, Uint8Array<ArrayBufferLike>>, ZodType<...>]>; collection: ZodString; doc: ZodObject<...>; }, "strict", ZodTypeAny, { ...; }, { ...; }>` |
|
|
405
441
|
|
|
406
|
-
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/sdk/schemas/db.ts#
|
|
442
|
+
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/sdk/schemas/db.ts#L50)
|
|
407
443
|
|
|
408
444
|
### :cocktail: Types
|
|
409
445
|
|
|
410
446
|
- [Collections](#gear-collections)
|
|
447
|
+
- [RawPrincipal](#gear-rawprincipal)
|
|
448
|
+
- [Principal](#gear-principal)
|
|
411
449
|
- [Timestamp](#gear-timestamp)
|
|
412
450
|
- [Version](#gear-version)
|
|
413
451
|
- [RawData](#gear-rawdata)
|
|
414
|
-
- [RawPrincipal](#gear-rawprincipal)
|
|
415
452
|
- [RawUserId](#gear-rawuserid)
|
|
453
|
+
- [UserId](#gear-userid)
|
|
416
454
|
- [Collection](#gear-collection)
|
|
417
455
|
- [Key](#gear-key)
|
|
418
456
|
- [HookContext](#gear-hookcontext)
|
|
457
|
+
- [AssertFunction](#gear-assertfunction)
|
|
458
|
+
- [RunFunction](#gear-runfunction)
|
|
419
459
|
- [DocDescription](#gear-docdescription)
|
|
420
460
|
- [Doc](#gear-doc)
|
|
421
461
|
- [DocUpsert](#gear-docupsert)
|
|
@@ -446,6 +486,26 @@ Defines the collections where a hook or assertion should run.
|
|
|
446
486
|
|
|
447
487
|
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/hooks/schemas/collections.ts#L18)
|
|
448
488
|
|
|
489
|
+
#### :gear: RawPrincipal
|
|
490
|
+
|
|
491
|
+
Represents a raw principal - a Uint8Array representation of a Principal.
|
|
492
|
+
|
|
493
|
+
| Type | Type |
|
|
494
|
+
| -------------- | ------------------------------------ |
|
|
495
|
+
| `RawPrincipal` | `z.infer<typeof RawPrincipalSchema>` |
|
|
496
|
+
|
|
497
|
+
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/schemas/candid.ts#L14)
|
|
498
|
+
|
|
499
|
+
#### :gear: Principal
|
|
500
|
+
|
|
501
|
+
Represents a principal - i.e. an object instantiated with the class Principal.
|
|
502
|
+
|
|
503
|
+
| Type | Type |
|
|
504
|
+
| ----------- | --------------------------------- |
|
|
505
|
+
| `Principal` | `z.infer<typeof PrincipalSchema>` |
|
|
506
|
+
|
|
507
|
+
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/schemas/candid.ts#L26)
|
|
508
|
+
|
|
449
509
|
#### :gear: Timestamp
|
|
450
510
|
|
|
451
511
|
Represents a timestamp in nanoseconds since the Unix epoch.
|
|
@@ -456,7 +516,7 @@ Used for tracking when events occur, such as document creation and updates.
|
|
|
456
516
|
| ----------- | --------------------------------- |
|
|
457
517
|
| `Timestamp` | `z.infer<typeof TimestampSchema>` |
|
|
458
518
|
|
|
459
|
-
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/schemas/core.ts#
|
|
519
|
+
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/schemas/core.ts#L14)
|
|
460
520
|
|
|
461
521
|
#### :gear: Version
|
|
462
522
|
|
|
@@ -468,7 +528,7 @@ This is typically incremented with each update to ensure consistency.
|
|
|
468
528
|
| --------- | ------------------------------- |
|
|
469
529
|
| `Version` | `z.infer<typeof VersionSchema>` |
|
|
470
530
|
|
|
471
|
-
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/schemas/core.ts#
|
|
531
|
+
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/schemas/core.ts#L26)
|
|
472
532
|
|
|
473
533
|
#### :gear: RawData
|
|
474
534
|
|
|
@@ -480,19 +540,7 @@ This is used to store unstructured data in a document.
|
|
|
480
540
|
| --------- | ------------------------------- |
|
|
481
541
|
| `RawData` | `z.infer<typeof RawDataSchema>` |
|
|
482
542
|
|
|
483
|
-
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/schemas/core.ts#
|
|
484
|
-
|
|
485
|
-
#### :gear: RawPrincipal
|
|
486
|
-
|
|
487
|
-
Represents a raw principal identifier.
|
|
488
|
-
|
|
489
|
-
Principals are unique identities used in authentication and authorization.
|
|
490
|
-
|
|
491
|
-
| Type | Type |
|
|
492
|
-
| -------------- | ------------------------------------ |
|
|
493
|
-
| `RawPrincipal` | `z.infer<typeof RawPrincipalSchema>` |
|
|
494
|
-
|
|
495
|
-
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/schemas/core.ts#L53)
|
|
543
|
+
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/schemas/core.ts#L40)
|
|
496
544
|
|
|
497
545
|
#### :gear: RawUserId
|
|
498
546
|
|
|
@@ -504,7 +552,19 @@ This is a principal associated with a user.
|
|
|
504
552
|
| ----------- | --------------------------------- |
|
|
505
553
|
| `RawUserId` | `z.infer<typeof RawUserIdSchema>` |
|
|
506
554
|
|
|
507
|
-
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/schemas/core.ts#
|
|
555
|
+
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/schemas/core.ts#L52)
|
|
556
|
+
|
|
557
|
+
#### :gear: UserId
|
|
558
|
+
|
|
559
|
+
Represents a user identifier.
|
|
560
|
+
|
|
561
|
+
This is a principal associated with a user.
|
|
562
|
+
|
|
563
|
+
| Type | Type |
|
|
564
|
+
| -------- | ------------------------------ |
|
|
565
|
+
| `UserId` | `z.infer<typeof UserIdSchema>` |
|
|
566
|
+
|
|
567
|
+
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/schemas/core.ts#L64)
|
|
508
568
|
|
|
509
569
|
#### :gear: Collection
|
|
510
570
|
|
|
@@ -514,7 +574,7 @@ A collection name where data are stored.
|
|
|
514
574
|
| ------------ | ---------------------------------- |
|
|
515
575
|
| `Collection` | `z.infer<typeof CollectionSchema>` |
|
|
516
576
|
|
|
517
|
-
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/schemas/core.ts#
|
|
577
|
+
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/schemas/core.ts#L74)
|
|
518
578
|
|
|
519
579
|
#### :gear: Key
|
|
520
580
|
|
|
@@ -524,7 +584,7 @@ A unique key identifier within a collection.
|
|
|
524
584
|
| ----- | --------------------------- |
|
|
525
585
|
| `Key` | `z.infer<typeof KeySchema>` |
|
|
526
586
|
|
|
527
|
-
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/schemas/core.ts#
|
|
587
|
+
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/schemas/core.ts#L84)
|
|
528
588
|
|
|
529
589
|
#### :gear: HookContext
|
|
530
590
|
|
|
@@ -536,6 +596,30 @@ Represents the context provided to hooks, containing information about the calle
|
|
|
536
596
|
|
|
537
597
|
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/hooks/schemas/context.ts#L27)
|
|
538
598
|
|
|
599
|
+
#### :gear: AssertFunction
|
|
600
|
+
|
|
601
|
+
Defines the `assert` function schema for assertions.
|
|
602
|
+
|
|
603
|
+
The function takes a context argument and returns `void`.
|
|
604
|
+
|
|
605
|
+
| Type | Type |
|
|
606
|
+
| ---------------- | ---------------------------------------------------------------- |
|
|
607
|
+
| `AssertFunction` | `z.infer<ReturnType<typeof AssertFunctionSchema<z.ZodType<T>>>>` |
|
|
608
|
+
|
|
609
|
+
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/hooks/schemas/context.ts#L42)
|
|
610
|
+
|
|
611
|
+
#### :gear: RunFunction
|
|
612
|
+
|
|
613
|
+
Defines the `run` function schema for hooks.
|
|
614
|
+
|
|
615
|
+
The function takes a context argument and returns a `Promise<void>`.
|
|
616
|
+
|
|
617
|
+
| Type | Type |
|
|
618
|
+
| ------------- | ------------------------------------------------------------- |
|
|
619
|
+
| `RunFunction` | `z.infer<ReturnType<typeof RunFunctionSchema<z.ZodType<T>>>>` |
|
|
620
|
+
|
|
621
|
+
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/hooks/schemas/context.ts#L57)
|
|
622
|
+
|
|
539
623
|
#### :gear: DocDescription
|
|
540
624
|
|
|
541
625
|
Represents a document description with a maximum length of 1024 characters.
|
|
@@ -651,7 +735,7 @@ An assertion that runs when a document is created or updated.
|
|
|
651
735
|
| -------------- | ------------------------------------ |
|
|
652
736
|
| `AssertSetDoc` | `z.infer<typeof AssertSetDocSchema>` |
|
|
653
737
|
|
|
654
|
-
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/hooks/db/assertions.ts#
|
|
738
|
+
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/hooks/db/assertions.ts#L31)
|
|
655
739
|
|
|
656
740
|
#### :gear: Assert
|
|
657
741
|
|
|
@@ -661,7 +745,7 @@ All assertions definitions.
|
|
|
661
745
|
| -------- | ------------------------------ |
|
|
662
746
|
| `Assert` | `z.infer<typeof AssertSchema>` |
|
|
663
747
|
|
|
664
|
-
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/hooks/db/assertions.ts#
|
|
748
|
+
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/hooks/db/assertions.ts#L42)
|
|
665
749
|
|
|
666
750
|
#### :gear: AssertFn
|
|
667
751
|
|
|
@@ -669,7 +753,7 @@ All assertions definitions.
|
|
|
669
753
|
| ---------- | --------------------------------------------------- |
|
|
670
754
|
| `AssertFn` | `(assert: z.infer<typeof SatelliteEnvSchema>) => T` |
|
|
671
755
|
|
|
672
|
-
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/hooks/db/assertions.ts#
|
|
756
|
+
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/hooks/db/assertions.ts#L46)
|
|
673
757
|
|
|
674
758
|
#### :gear: AssertFnOrObject
|
|
675
759
|
|
|
@@ -677,7 +761,7 @@ All assertions definitions.
|
|
|
677
761
|
| ------------------ | ------------------ |
|
|
678
762
|
| `AssertFnOrObject` | `T or AssertFn<T>` |
|
|
679
763
|
|
|
680
|
-
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/hooks/db/assertions.ts#
|
|
764
|
+
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/hooks/db/assertions.ts#L50)
|
|
681
765
|
|
|
682
766
|
#### :gear: OnSetDoc
|
|
683
767
|
|
|
@@ -687,7 +771,7 @@ A hook that runs when a document is created or updated.
|
|
|
687
771
|
| ---------- | -------------------------------- |
|
|
688
772
|
| `OnSetDoc` | `z.infer<typeof OnSetDocSchema>` |
|
|
689
773
|
|
|
690
|
-
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/hooks/db/hooks.ts#
|
|
774
|
+
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/hooks/db/hooks.ts#L31)
|
|
691
775
|
|
|
692
776
|
#### :gear: Hook
|
|
693
777
|
|
|
@@ -697,7 +781,7 @@ All hooks definitions.
|
|
|
697
781
|
| ------ | ---------------------------- |
|
|
698
782
|
| `Hook` | `z.infer<typeof HookSchema>` |
|
|
699
783
|
|
|
700
|
-
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/hooks/db/hooks.ts#
|
|
784
|
+
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/hooks/db/hooks.ts#L42)
|
|
701
785
|
|
|
702
786
|
#### :gear: HookFn
|
|
703
787
|
|
|
@@ -705,7 +789,7 @@ All hooks definitions.
|
|
|
705
789
|
| -------- | ------------------------------------------------- |
|
|
706
790
|
| `HookFn` | `(hook: z.infer<typeof SatelliteEnvSchema>) => T` |
|
|
707
791
|
|
|
708
|
-
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/hooks/db/hooks.ts#
|
|
792
|
+
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/hooks/db/hooks.ts#L46)
|
|
709
793
|
|
|
710
794
|
#### :gear: HookFnOrObject
|
|
711
795
|
|
|
@@ -713,7 +797,7 @@ All hooks definitions.
|
|
|
713
797
|
| ---------------- | ---------------- |
|
|
714
798
|
| `HookFnOrObject` | `T or HookFn<T>` |
|
|
715
799
|
|
|
716
|
-
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/hooks/db/hooks.ts#
|
|
800
|
+
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/hooks/db/hooks.ts#L50)
|
|
717
801
|
|
|
718
802
|
#### :gear: SetDoc
|
|
719
803
|
|
|
@@ -725,7 +809,7 @@ This is used when submitting new document data.
|
|
|
725
809
|
| -------- | ------------------------------ |
|
|
726
810
|
| `SetDoc` | `z.infer<typeof SetDocSchema>` |
|
|
727
811
|
|
|
728
|
-
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/sdk/schemas/db.ts#
|
|
812
|
+
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/sdk/schemas/db.ts#L45)
|
|
729
813
|
|
|
730
814
|
#### :gear: SetDocStoreParams
|
|
731
815
|
|
|
@@ -738,7 +822,7 @@ collection, and key.
|
|
|
738
822
|
| ------------------- | ----------------------------------------- |
|
|
739
823
|
| `SetDocStoreParams` | `z.infer<typeof SetDocStoreParamsSchema>` |
|
|
740
824
|
|
|
741
|
-
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/sdk/schemas/db.ts#
|
|
825
|
+
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/sdk/schemas/db.ts#L75)
|
|
742
826
|
|
|
743
827
|
<!-- TSDOC_END -->
|
|
744
828
|
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{Principal as s}from"@dfinity/principal";import*as r from"zod";var i=r.custom(t=>t instanceof Uint8Array,{message:"Expected a Uint8Array representation of a Principal"}),c=r.custom(t=>t instanceof s,{message:"Expected an instance of a Principal"});import*as e from"zod";var o=e.bigint(),p=e.bigint(),n=e.custom(t=>t instanceof Uint8Array,{message:"Expected Uint8Array"}),m=i,x=c,z=e.string(),l=e.string();import*as a from"zod";var f=a.string().max(1024),D=a.object({owner:m,data:n,description:f.optional(),created_at:o,updated_at:o,version:p.optional()}).strict();export{i as a,c as b,o as c,p as d,n as e,m as f,x as g,z as h,l as i,f as j,D as k};
|
|
2
|
+
//# sourceMappingURL=chunk-MKW7CALF.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["src/schemas/candid.ts", "src/schemas/core.ts", "src/schemas/db.ts"],
|
|
4
|
+
"sourcesContent": ["import {Principal as CandidPrincipal} from '@dfinity/principal';\nimport * as z from 'zod';\n\n/**\n * @see RawPrincipal\n */\nexport const RawPrincipalSchema = z.custom<Uint8Array>((val) => val instanceof Uint8Array, {\n message: 'Expected a Uint8Array representation of a Principal'\n});\n\n/**\n * Represents a raw principal - a Uint8Array representation of a Principal.\n */\nexport type RawPrincipal = z.infer<typeof RawPrincipalSchema>;\n\n/**\n * @see Principal\n */\nexport const PrincipalSchema = z.custom<CandidPrincipal>((val) => val instanceof CandidPrincipal, {\n message: 'Expected an instance of a Principal'\n});\n\n/**\n * Represents a principal - i.e. an object instantiated with the class Principal.\n */\nexport type Principal = z.infer<typeof PrincipalSchema>;\n", "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 RawData\n */\nexport const RawDataSchema = z.custom<Uint8Array>((val) => val instanceof Uint8Array, {\n message: 'Expected Uint8Array'\n});\n\n/**\n * Represents raw binary data.\n *\n * This is used to store unstructured data in a document.\n */\nexport type RawData = z.infer<typeof RawDataSchema>;\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 unique key identifier within a collection.\n */\nexport type Key = z.infer<typeof KeySchema>;\n", "import * as z from 'zod';\nimport {RawDataSchema, RawUserIdSchema, TimestampSchema, VersionSchema} from './core';\n\n/**\n * @see DocDescription\n */\nexport const DocDescriptionSchema = z.string().max(1024);\n\n/**\n * Represents a document description with a maximum length of 1024 characters.\n */\nexport type DocDescription = z.infer<typeof DocDescriptionSchema>;\n\n/**\n * @see Doc\n */\nexport const DocSchema = z\n .object({\n /**\n * The user who owns this document.\n */\n owner: RawUserIdSchema,\n\n /**\n * The raw data of the document.\n */\n data: RawDataSchema,\n\n /**\n * An optional description of the document.\n */\n description: DocDescriptionSchema.optional(),\n\n /**\n * The timestamp when the document was first created.\n */\n created_at: TimestampSchema,\n\n /**\n * The timestamp when the document was last updated.\n */\n updated_at: TimestampSchema,\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: VersionSchema.optional()\n })\n .strict();\n\n/**\n * Represents a document stored in a collection.\n */\nexport type Doc = z.infer<typeof DocSchema>;\n"],
|
|
5
|
+
"mappings": "AAAA,OAAQ,aAAaA,MAAsB,qBAC3C,UAAYC,MAAO,MAKZ,IAAMC,EAAuB,SAAoBC,GAAQA,aAAe,WAAY,CACzF,QAAS,qDACX,CAAC,EAUYC,EAAoB,SAAyBD,GAAQA,aAAeH,EAAiB,CAChG,QAAS,qCACX,CAAC,ECpBD,UAAYK,MAAO,MAMZ,IAAMC,EAAoB,SAAO,EAY3BC,EAAkB,SAAO,EAYzBC,EAAkB,SAAoBC,GAAQA,aAAe,WAAY,CACpF,QAAS,qBACX,CAAC,EAYYC,EAAkBC,EAYlBC,EAAeC,EAYfC,EAAqB,SAAO,EAU5BC,EAAc,SAAO,EC9ElC,UAAYC,MAAO,MAMZ,IAAMC,EAAyB,SAAO,EAAE,IAAI,IAAI,EAU1CC,EACV,SAAO,CAIN,MAAOC,EAKP,KAAMC,EAKN,YAAaH,EAAqB,SAAS,EAK3C,WAAYI,EAKZ,WAAYA,EAMZ,QAASC,EAAc,SAAS,CAClC,CAAC,EACA,OAAO",
|
|
6
|
+
"names": ["CandidPrincipal", "z", "RawPrincipalSchema", "val", "PrincipalSchema", "z", "TimestampSchema", "VersionSchema", "RawDataSchema", "val", "RawUserIdSchema", "RawPrincipalSchema", "UserIdSchema", "PrincipalSchema", "CollectionSchema", "KeySchema", "z", "DocDescriptionSchema", "DocSchema", "RawUserIdSchema", "RawDataSchema", "TimestampSchema", "VersionSchema"]
|
|
7
|
+
}
|
|
@@ -54,3 +54,27 @@ export declare const HookContextSchema: <T extends z.ZodTypeAny>(dataSchema: T)
|
|
|
54
54
|
* @template T - The type of data associated with the hook.
|
|
55
55
|
*/
|
|
56
56
|
export type HookContext<T extends z.ZodTypeAny> = z.infer<ReturnType<typeof HookContextSchema<T>>>;
|
|
57
|
+
/**
|
|
58
|
+
* @see AssertFunction
|
|
59
|
+
*/
|
|
60
|
+
export declare const AssertFunctionSchema: <T extends z.ZodTypeAny>(contextSchema: T) => z.ZodFunction<z.ZodTuple<[T], z.ZodUnknown>, z.ZodVoid>;
|
|
61
|
+
/**
|
|
62
|
+
* Defines the `assert` function schema for assertions.
|
|
63
|
+
*
|
|
64
|
+
* The function takes a context argument and returns `void`.
|
|
65
|
+
*
|
|
66
|
+
* @template T - The type of context passed to the function.
|
|
67
|
+
*/
|
|
68
|
+
export type AssertFunction<T> = z.infer<ReturnType<typeof AssertFunctionSchema<z.ZodType<T>>>>;
|
|
69
|
+
/**
|
|
70
|
+
* @see RunFunction
|
|
71
|
+
*/
|
|
72
|
+
export declare const RunFunctionSchema: <T extends z.ZodTypeAny>(contextSchema: T) => z.ZodFunction<z.ZodTuple<[T], z.ZodUnknown>, z.ZodPromise<z.ZodVoid>>;
|
|
73
|
+
/**
|
|
74
|
+
* Defines the `run` function schema for hooks.
|
|
75
|
+
*
|
|
76
|
+
* The function takes a context argument and returns a `Promise<void>`.
|
|
77
|
+
*
|
|
78
|
+
* @template T - The type of context passed to the function.
|
|
79
|
+
*/
|
|
80
|
+
export type RunFunction<T> = z.infer<ReturnType<typeof RunFunctionSchema<z.ZodType<T>>>>;
|
package/ic-cdk.js
CHANGED
|
@@ -1,7 +1,2 @@
|
|
|
1
|
-
var y="abcdefghijklmnopqrstuvwxyz234567",l=Object.create(null);for(let e=0;e<y.length;e++)l[y[e]]=e;l[0]=l.o;l[1]=l.i;function k(e){let t=0,n=0,r="";function o(c){return t<0?n|=c>>-t:n=c<<t&248,t>3?(t-=8,1):(t<4&&(r+=y[n>>3],t+=5),0)}for(let c=0;c<e.length;)c+=o(e[c]);return r+(t<0?y[n>>3]:"")}function O(e){let t=0,n=0,r=new Uint8Array(e.length*4/3|0),o=0;function c(x){let s=l[x.toLowerCase()];if(s===void 0)throw new Error(`Invalid character: ${JSON.stringify(x)}`);s<<=3,n|=s>>>t,t+=5,t>=8&&(r[o++]=n,t-=8,t>0?n=s<<5-t&255:n=0)}for(let x of e)c(x);return r.slice(0,o)}var V=new Uint32Array([0,1996959894,3993919788,2567524794,124634137,1886057615,3915621685,2657392035,249268274,2044508324,3772115230,2547177864,162941995,2125561021,3887607047,2428444049,498536548,1789927666,4089016648,2227061214,450548861,1843258603,4107580753,2211677639,325883990,1684777152,4251122042,2321926636,335633487,1661365465,4195302755,2366115317,997073096,1281953886,3579855332,2724688242,1006888145,1258607687,3524101629,2768942443,901097722,1119000684,3686517206,2898065728,853044451,1172266101,3705015759,2882616665,651767980,1373503546,3369554304,3218104598,565507253,1454621731,3485111705,3099436303,671266974,1594198024,3322730930,2970347812,795835527,1483230225,3244367275,3060149565,1994146192,31158534,2563907772,4023717930,1907459465,112637215,2680153253,3904427059,2013776290,251722036,2517215374,3775830040,2137656763,141376813,2439277719,3865271297,1802195444,476864866,2238001368,4066508878,1812370925,453092731,2181625025,4111451223,1706088902,314042704,2344532202,4240017532,1658658271,366619977,2362670323,4224994405,1303535960,984961486,2747007092,3569037538,1256170817,1037604311,2765210733,3554079995,1131014506,879679996,2909243462,3663771856,1141124467,855842277,2852801631,3708648649,1342533948,654459306,3188396048,3373015174,1466479909,544179635,3110523913,3462522015,1591671054,702138776,2966460450,3352799412,1504918807,783551873,3082640443,3233442989,3988292384,2596254646,62317068,1957810842,3939845945,2647816111,81470997,1943803523,3814918930,2489596804,225274430,2053790376,3826175755,2466906013,167816743,2097651377,4027552580,2265490386,503444072,1762050814,4150417245,2154129355,426522225,1852507879,4275313526,2312317920,282753626,1742555852,4189708143,2394877945,397917763,1622183637,3604390888,2714866558,953729732,1340076626,3518719985,2797360999,1068828381,1219638859,3624741850,2936675148,906185462,1090812512,3747672003,2825379669,829329135,1181335161,3412177804,3160834842,628085408,1382605366,3423369109,3138078467,570562233,1426400815,3317316542,2998733608,733239954,1555261956,3268935591,3050360625,752459403,1541320221,2607071920,3965973030,1969922972,40735498,2617837225,3943577151,1913087877,83908371,2512341634,3803740692,2075208622,213261112,2463272603,3855990285,2094854071,198958881,2262029012,4057260610,1759359992,534414190,2176718541,4139329115,1873836001,414664567,2282248934,4279200368,1711684554,285281116,2405801727,4167216745,1634467795,376229701,2685067896,3608007406,1308918612,956543938,2808555105,3495958263,1231636301,1047427035,2932959818,3654703836,1088359270,936918e3,2847714899,3736837829,1202900863,817233897,3183342108,3401237130,1404277552,615818150,3134207493,3453421203,1423857449,601450431,3009837614,3294710456,1567103746,711928724,3020668471,3272380065,1510334235,755167117]);function H(e){let t=new Uint8Array(e),n=-1;for(let r=0;r<t.length;r++){let c=(t[r]^n)&255;n=V[c]^n>>>8}return(n^-1)>>>0}function G(e){return e instanceof Uint8Array||e!=null&&typeof e=="object"&&e.constructor.name==="Uint8Array"}function L(e,...t){if(!G(e))throw new Error("Uint8Array expected");if(t.length>0&&!t.includes(e.length))throw new Error(`Uint8Array expected of length ${t}, not of length=${e.length}`)}function B(e,t=!0){if(e.destroyed)throw new Error("Hash instance has been destroyed");if(t&&e.finished)throw new Error("Hash#digest() has already been called")}function N(e,t){L(e);let n=t.outputLen;if(e.length<n)throw new Error(`digestInto() expects output buffer of length at least ${n}`)}var m=e=>new DataView(e.buffer,e.byteOffset,e.byteLength),d=(e,t)=>e<<32-t|e>>>t;var tt=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;function M(e){if(typeof e!="string")throw new Error(`utf8ToBytes expected string, got ${typeof e}`);return new Uint8Array(new TextEncoder().encode(e))}function T(e){return typeof e=="string"&&(e=M(e)),L(e),e}var w=class{clone(){return this._cloneInto()}},et={}.toString;function j(e){let t=r=>e().update(T(r)).digest(),n=e();return t.outputLen=n.outputLen,t.blockLen=n.blockLen,t.create=()=>e(),t}function R(e,t,n,r){if(typeof e.setBigUint64=="function")return e.setBigUint64(t,n,r);let o=BigInt(32),c=BigInt(4294967295),x=Number(n>>o&c),s=Number(n&c),f=r?4:0,a=r?0:4;e.setUint32(t+f,x,r),e.setUint32(t+a,s,r)}var F=(e,t,n)=>e&t^~e&n,v=(e,t,n)=>e&t^e&n^t&n,_=class extends w{constructor(t,n,r,o){super(),this.blockLen=t,this.outputLen=n,this.padOffset=r,this.isLE=o,this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.buffer=new Uint8Array(t),this.view=m(this.buffer)}update(t){B(this);let{view:n,buffer:r,blockLen:o}=this;t=T(t);let c=t.length;for(let x=0;x<c;){let s=Math.min(o-this.pos,c-x);if(s===o){let f=m(t);for(;o<=c-x;x+=o)this.process(f,x);continue}r.set(t.subarray(x,x+s),this.pos),this.pos+=s,x+=s,this.pos===o&&(this.process(n,0),this.pos=0)}return this.length+=t.length,this.roundClean(),this}digestInto(t){B(this),N(t,this),this.finished=!0;let{buffer:n,view:r,blockLen:o,isLE:c}=this,{pos:x}=this;n[x++]=128,this.buffer.subarray(x).fill(0),this.padOffset>o-x&&(this.process(r,0),x=0);for(let i=x;i<o;i++)n[i]=0;R(r,o-8,BigInt(this.length*8),c),this.process(r,0);let s=m(t),f=this.outputLen;if(f%4)throw new Error("_sha2: outputLen should be aligned to 32bit");let a=f/4,b=this.get();if(a>b.length)throw new Error("_sha2: outputLen bigger than state");for(let i=0;i<a;i++)s.setUint32(4*i,b[i],c)}digest(){let{buffer:t,outputLen:n}=this;this.digestInto(t);let r=t.slice(0,n);return this.destroy(),r}_cloneInto(t){t||(t=new this.constructor),t.set(...this.get());let{blockLen:n,buffer:r,length:o,finished:c,destroyed:x,pos:s}=this;return t.length=o,t.pos=s,t.finished=c,t.destroyed=x,o%n&&t.buffer.set(r),t}};var q=new Uint32Array([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),u=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),h=new Uint32Array(64),S=class extends _{constructor(){super(64,32,8,!1),this.A=u[0]|0,this.B=u[1]|0,this.C=u[2]|0,this.D=u[3]|0,this.E=u[4]|0,this.F=u[5]|0,this.G=u[6]|0,this.H=u[7]|0}get(){let{A:t,B:n,C:r,D:o,E:c,F:x,G:s,H:f}=this;return[t,n,r,o,c,x,s,f]}set(t,n,r,o,c,x,s,f){this.A=t|0,this.B=n|0,this.C=r|0,this.D=o|0,this.E=c|0,this.F=x|0,this.G=s|0,this.H=f|0}process(t,n){for(let i=0;i<16;i++,n+=4)h[i]=t.getUint32(n,!1);for(let i=16;i<64;i++){let g=h[i-15],p=h[i-2],I=d(g,7)^d(g,18)^g>>>3,E=d(p,17)^d(p,19)^p>>>10;h[i]=E+h[i-7]+I+h[i-16]|0}let{A:r,B:o,C:c,D:x,E:s,F:f,G:a,H:b}=this;for(let i=0;i<64;i++){let g=d(s,6)^d(s,11)^d(s,25),p=b+g+F(s,f,a)+q[i]+h[i]|0,E=(d(r,2)^d(r,13)^d(r,22))+v(r,o,c)|0;b=a,a=f,f=s,s=x+p|0,x=c,c=o,o=r,r=p+E|0}r=r+this.A|0,o=o+this.B|0,c=c+this.C|0,x=x+this.D|0,s=s+this.E|0,f=f+this.F|0,a=a+this.G|0,b=b+this.H|0,this.set(r,o,c,x,s,f,a,b)}roundClean(){h.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}},C=class extends S{constructor(){super(),this.A=-1056596264,this.B=914150663,this.C=812702999,this.D=-150054599,this.E=-4191439,this.F=1750603025,this.G=1694076839,this.H=-1090891868,this.outputLen=28}};var D=j(()=>new C);function P(e){return D.create().update(new Uint8Array(e)).digest()}var A="__principal__",J=2,$=4,W="aaaaa-aa",X=e=>{var t;return new Uint8Array(((t=e.match(/.{1,2}/g))!==null&&t!==void 0?t:[]).map(n=>parseInt(n,16)))},K=e=>e.reduce((t,n)=>t+n.toString(16).padStart(2,"0"),""),U=class e{constructor(t){this._arr=t,this._isPrincipal=!0}static anonymous(){return new this(new Uint8Array([$]))}static managementCanister(){return this.fromHex(W)}static selfAuthenticating(t){let n=P(t);return new this(new Uint8Array([...n,J]))}static from(t){if(typeof t=="string")return e.fromText(t);if(Object.getPrototypeOf(t)===Uint8Array.prototype)return new e(t);if(typeof t=="object"&&t!==null&&t._isPrincipal===!0)return new e(t._arr);throw new Error(`Impossible to convert ${JSON.stringify(t)} to Principal.`)}static fromHex(t){return new this(X(t))}static fromText(t){let n=t;if(t.includes(A)){let x=JSON.parse(t);A in x&&(n=x[A])}let r=n.toLowerCase().replace(/-/g,""),o=O(r);o=o.slice(4,o.length);let c=new this(o);if(c.toText()!==n)throw new Error(`Principal "${c.toText()}" does not have a valid checksum (original value "${n}" may not be a valid Principal ID).`);return c}static fromUint8Array(t){return new this(t)}isAnonymous(){return this._arr.byteLength===1&&this._arr[0]===$}toUint8Array(){return this._arr}toHex(){return K(this._arr).toUpperCase()}toText(){let t=new ArrayBuffer(4);new DataView(t).setUint32(0,H(this._arr));let r=new Uint8Array(t),o=Uint8Array.from(this._arr),c=new Uint8Array([...r,...o]),s=k(c).match(/.{1,5}/g);if(!s)throw new Error;return s.join("-")}toString(){return this.toText()}toJSON(){return{[A]:this.toText()}}compareTo(t){for(let n=0;n<Math.min(this._arr.length,t._arr.length);n++){if(this._arr[n]<t._arr[n])return"lt";if(this._arr[n]>t._arr[n])return"gt"}return this._arr.length<t._arr.length?"lt":this._arr.length>t._arr.length?"gt":"eq"}ltEq(t){let n=this.compareTo(t);return n=="lt"||n=="eq"}gtEq(t){let n=this.compareTo(t);return n=="gt"||n=="eq"}};var lt=()=>U.fromUint8Array(__ic_cdk_id());export{lt as id};
|
|
2
|
-
/*! Bundled license information:
|
|
3
|
-
|
|
4
|
-
@noble/hashes/esm/utils.js:
|
|
5
|
-
(*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
|
|
6
|
-
*/
|
|
1
|
+
import{Principal as r}from"@dfinity/principal";var c=()=>r.fromUint8Array(__ic_cdk_id());export{c as id};
|
|
7
2
|
//# sourceMappingURL=ic-cdk.js.map
|
package/ic-cdk.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["
|
|
4
|
-
"sourcesContent": ["const alphabet = 'abcdefghijklmnopqrstuvwxyz234567';\n\n// Build a lookup table for decoding.\nconst lookupTable: Record<string, number> = Object.create(null);\nfor (let i = 0; i < alphabet.length; i++) {\n lookupTable[alphabet[i]] = i;\n}\n\n// Add aliases for rfc4648.\nlookupTable['0'] = lookupTable.o;\nlookupTable['1'] = lookupTable.i;\n\n/**\n * @param input The input array to encode.\n * @returns A Base32 string encoding the input.\n */\nexport function encode(input: Uint8Array): string {\n // How many bits will we skip from the first byte.\n let skip = 0;\n // 5 high bits, carry from one byte to the next.\n let bits = 0;\n\n // The output string in base32.\n let output = '';\n\n function encodeByte(byte: number) {\n if (skip < 0) {\n // we have a carry from the previous byte\n bits |= byte >> -skip;\n } else {\n // no carry\n bits = (byte << skip) & 248;\n }\n\n if (skip > 3) {\n // Not enough data to produce a character, get us another one\n skip -= 8;\n return 1;\n }\n\n if (skip < 4) {\n // produce a character\n output += alphabet[bits >> 3];\n skip += 5;\n }\n\n return 0;\n }\n\n for (let i = 0; i < input.length; ) {\n i += encodeByte(input[i]);\n }\n\n return output + (skip < 0 ? alphabet[bits >> 3] : '');\n}\n\n/**\n * @param input The base32 encoded string to decode.\n */\nexport function decode(input: string): Uint8Array {\n // how many bits we have from the previous character.\n let skip = 0;\n // current byte we're producing.\n let byte = 0;\n\n const output = new Uint8Array(((input.length * 4) / 3) | 0);\n let o = 0;\n\n function decodeChar(char: string) {\n // Consume a character from the stream, store\n // the output in this.output. As before, better\n // to use update().\n let val = lookupTable[char.toLowerCase()];\n if (val === undefined) {\n throw new Error(`Invalid character: ${JSON.stringify(char)}`);\n }\n\n // move to the high bits\n val <<= 3;\n byte |= val >>> skip;\n skip += 5;\n\n if (skip >= 8) {\n // We have enough bytes to produce an output\n output[o++] = byte;\n skip -= 8;\n\n if (skip > 0) {\n byte = (val << (5 - skip)) & 255;\n } else {\n byte = 0;\n }\n }\n }\n\n for (const c of input) {\n decodeChar(c);\n }\n\n return output.slice(0, o);\n}\n", "// This file is translated to JavaScript from\n// https://lxp32.github.io/docs/a-simple-example-crc32-calculation/\nconst lookUpTable: Uint32Array = new Uint32Array([\n 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, 0x706af48f, 0xe963a535, 0x9e6495a3,\n 0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988, 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, 0x90bf1d91,\n 0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de, 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7,\n 0x136c9856, 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9, 0xfa0f3d63, 0x8d080df5,\n 0x3b6e20c8, 0x4c69105e, 0xd56041e4, 0xa2677172, 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b,\n 0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3, 0x45df5c75, 0xdcd60dcf, 0xabd13d59,\n 0x26d930ac, 0x51de003a, 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423, 0xcfba9599, 0xb8bda50f,\n 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924, 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d,\n 0x76dc4190, 0x01db7106, 0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f, 0x9fbfe4a5, 0xe8b8d433,\n 0x7807c9a2, 0x0f00f934, 0x9609a88e, 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01,\n 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, 0x6c0695ed, 0x1b01a57b, 0x8208f4c1, 0xf50fc457,\n 0x65b0d9c6, 0x12b7e950, 0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3, 0xfbd44c65,\n 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2, 0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb,\n 0x4369e96a, 0x346ed9fc, 0xad678846, 0xda60b8d0, 0x44042d73, 0x33031de5, 0xaa0a4c5f, 0xdd0d7cc9,\n 0x5005713c, 0x270241aa, 0xbe0b1010, 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f,\n 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17, 0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad,\n 0xedb88320, 0x9abfb3b6, 0x03b6e20c, 0x74b1d29a, 0xead54739, 0x9dd277af, 0x04db2615, 0x73dc1683,\n 0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8, 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1,\n 0xf00f9344, 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb, 0x196c3671, 0x6e6b06e7,\n 0xfed41b76, 0x89d32be0, 0x10da7a5a, 0x67dd4acc, 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5,\n 0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1, 0xa6bc5767, 0x3fb506dd, 0x48b2364b,\n 0xd80d2bda, 0xaf0a1b4c, 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55, 0x316e8eef, 0x4669be79,\n 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236, 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f,\n 0xc5ba3bbe, 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31, 0x2cd99e8b, 0x5bdeae1d,\n 0x9b64c2b0, 0xec63f226, 0x756aa39c, 0x026d930a, 0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713,\n 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, 0x92d28e9b, 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21,\n 0x86d3d2d4, 0xf1d4e242, 0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1, 0x18b74777,\n 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c, 0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45,\n 0xa00ae278, 0xd70dd2ee, 0x4e048354, 0x3903b3c2, 0xa7672661, 0xd06016f7, 0x4969474d, 0x3e6e77db,\n 0xaed16a4a, 0xd9d65adc, 0x40df0b66, 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9,\n 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605, 0xcdd70693, 0x54de5729, 0x23d967bf,\n 0xb3667a2e, 0xc4614ab8, 0x5d681b02, 0x2a6f2b94, 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d,\n]);\n\n/**\n * Calculate the CRC32 of an ArrayBufferLike.\n * @param buf The BufferLike to calculate the CRC32 of.\n */\nexport function getCrc32(buf: ArrayBufferLike): number {\n const b = new Uint8Array(buf);\n let crc = -1;\n\n for (let i = 0; i < b.length; i++) {\n const byte = b[i];\n const t = (byte ^ crc) & 0xff;\n crc = lookUpTable[t] ^ (crc >>> 8);\n }\n\n return (crc ^ -1) >>> 0;\n}\n", "function number(n: number) {\n if (!Number.isSafeInteger(n) || n < 0) throw new Error(`positive integer expected, not ${n}`);\n}\n\nfunction bool(b: boolean) {\n if (typeof b !== 'boolean') throw new Error(`boolean expected, not ${b}`);\n}\n\n// copied from utils\nexport function isBytes(a: unknown): a is Uint8Array {\n return (\n a instanceof Uint8Array ||\n (a != null && typeof a === 'object' && a.constructor.name === 'Uint8Array')\n );\n}\n\nfunction bytes(b: Uint8Array | undefined, ...lengths: number[]) {\n if (!isBytes(b)) throw new Error('Uint8Array expected');\n if (lengths.length > 0 && !lengths.includes(b.length))\n throw new Error(`Uint8Array expected of length ${lengths}, not of length=${b.length}`);\n}\n\ntype Hash = {\n (data: Uint8Array): Uint8Array;\n blockLen: number;\n outputLen: number;\n create: any;\n};\nfunction hash(h: Hash) {\n if (typeof h !== 'function' || typeof h.create !== 'function')\n throw new Error('Hash should be wrapped by utils.wrapConstructor');\n number(h.outputLen);\n number(h.blockLen);\n}\n\nfunction exists(instance: any, checkFinished = true) {\n if (instance.destroyed) throw new Error('Hash instance has been destroyed');\n if (checkFinished && instance.finished) throw new Error('Hash#digest() has already been called');\n}\nfunction output(out: any, instance: any) {\n bytes(out);\n const min = instance.outputLen;\n if (out.length < min) {\n throw new Error(`digestInto() expects output buffer of length at least ${min}`);\n }\n}\n\nexport { number, bool, bytes, hash, exists, output };\n\nconst assert = { number, bool, bytes, hash, exists, output };\nexport default assert;\n", "/*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */\n\n// We use WebCrypto aka globalThis.crypto, which exists in browsers and node.js 16+.\n// node.js versions earlier than v19 don't declare it in global scope.\n// For node.js, package.json#exports field mapping rewrites import\n// from `crypto` to `cryptoNode`, which imports native module.\n// Makes the utils un-importable in browsers without a bundler.\n// Once node.js 18 is deprecated (2025-04-30), we can just drop the import.\nimport { crypto } from '@noble/hashes/crypto';\nimport { bytes as abytes } from './_assert.js';\n// export { isBytes } from './_assert.js';\n// We can't reuse isBytes from _assert, because somehow this causes huge perf issues\nexport function isBytes(a: unknown): a is Uint8Array {\n return (\n a instanceof Uint8Array ||\n (a != null && typeof a === 'object' && a.constructor.name === 'Uint8Array')\n );\n}\n\n// prettier-ignore\nexport type TypedArray = Int8Array | Uint8ClampedArray | Uint8Array |\n Uint16Array | Int16Array | Uint32Array | Int32Array;\n\n// Cast array to different type\nexport const u8 = (arr: TypedArray) => new Uint8Array(arr.buffer, arr.byteOffset, arr.byteLength);\nexport const u32 = (arr: TypedArray) =>\n new Uint32Array(arr.buffer, arr.byteOffset, Math.floor(arr.byteLength / 4));\n\n// Cast array to view\nexport const createView = (arr: TypedArray) =>\n new DataView(arr.buffer, arr.byteOffset, arr.byteLength);\n\n// The rotate right (circular right shift) operation for uint32\nexport const rotr = (word: number, shift: number) => (word << (32 - shift)) | (word >>> shift);\n// The rotate left (circular left shift) operation for uint32\nexport const rotl = (word: number, shift: number) =>\n (word << shift) | ((word >>> (32 - shift)) >>> 0);\n\nexport const isLE = new Uint8Array(new Uint32Array([0x11223344]).buffer)[0] === 0x44;\n// The byte swap operation for uint32\nexport const byteSwap = (word: number) =>\n ((word << 24) & 0xff000000) |\n ((word << 8) & 0xff0000) |\n ((word >>> 8) & 0xff00) |\n ((word >>> 24) & 0xff);\n// Conditionally byte swap if on a big-endian platform\nexport const byteSwapIfBE = isLE ? (n: number) => n : (n: number) => byteSwap(n);\n\n// In place byte swap for Uint32Array\nexport function byteSwap32(arr: Uint32Array) {\n for (let i = 0; i < arr.length; i++) {\n arr[i] = byteSwap(arr[i]);\n }\n}\n\n// Array where index 0xf0 (240) is mapped to string 'f0'\nconst hexes = /* @__PURE__ */ Array.from({ length: 256 }, (_, i) =>\n i.toString(16).padStart(2, '0')\n);\n/**\n * @example bytesToHex(Uint8Array.from([0xca, 0xfe, 0x01, 0x23])) // 'cafe0123'\n */\nexport function bytesToHex(bytes: Uint8Array): string {\n abytes(bytes);\n // pre-caching improves the speed 6x\n let hex = '';\n for (let i = 0; i < bytes.length; i++) {\n hex += hexes[bytes[i]];\n }\n return hex;\n}\n\n// We use optimized technique to convert hex string to byte array\nconst asciis = { _0: 48, _9: 57, _A: 65, _F: 70, _a: 97, _f: 102 } as const;\nfunction asciiToBase16(char: number): number | undefined {\n if (char >= asciis._0 && char <= asciis._9) return char - asciis._0;\n if (char >= asciis._A && char <= asciis._F) return char - (asciis._A - 10);\n if (char >= asciis._a && char <= asciis._f) return char - (asciis._a - 10);\n return;\n}\n\n/**\n * @example hexToBytes('cafe0123') // Uint8Array.from([0xca, 0xfe, 0x01, 0x23])\n */\nexport function hexToBytes(hex: string): Uint8Array {\n if (typeof hex !== 'string') throw new Error('hex string expected, got ' + typeof hex);\n const hl = hex.length;\n const al = hl / 2;\n if (hl % 2) throw new Error('padded hex string expected, got unpadded hex of length ' + hl);\n const array = new Uint8Array(al);\n for (let ai = 0, hi = 0; ai < al; ai++, hi += 2) {\n const n1 = asciiToBase16(hex.charCodeAt(hi));\n const n2 = asciiToBase16(hex.charCodeAt(hi + 1));\n if (n1 === undefined || n2 === undefined) {\n const char = hex[hi] + hex[hi + 1];\n throw new Error('hex string expected, got non-hex character \"' + char + '\" at index ' + hi);\n }\n array[ai] = n1 * 16 + n2;\n }\n return array;\n}\n\n// There is no setImmediate in browser and setTimeout is slow.\n// call of async fn will return Promise, which will be fullfiled only on\n// next scheduler queue processing step and this is exactly what we need.\nexport const nextTick = async () => {};\n\n// Returns control to thread each 'tick' ms to avoid blocking\nexport async function asyncLoop(iters: number, tick: number, cb: (i: number) => void) {\n let ts = Date.now();\n for (let i = 0; i < iters; i++) {\n cb(i);\n // Date.now() is not monotonic, so in case if clock goes backwards we return return control too\n const diff = Date.now() - ts;\n if (diff >= 0 && diff < tick) continue;\n await nextTick();\n ts += diff;\n }\n}\n\n// Global symbols in both browsers and Node.js since v11\n// See https://github.com/microsoft/TypeScript/issues/31535\ndeclare const TextEncoder: any;\n\n/**\n * @example utf8ToBytes('abc') // new Uint8Array([97, 98, 99])\n */\nexport function utf8ToBytes(str: string): Uint8Array {\n if (typeof str !== 'string') throw new Error(`utf8ToBytes expected string, got ${typeof str}`);\n return new Uint8Array(new TextEncoder().encode(str)); // https://bugzil.la/1681809\n}\n\nexport type Input = Uint8Array | string;\n/**\n * Normalizes (non-hex) string or Uint8Array to Uint8Array.\n * Warning: when Uint8Array is passed, it would NOT get copied.\n * Keep in mind for future mutable operations.\n */\nexport function toBytes(data: Input): Uint8Array {\n if (typeof data === 'string') data = utf8ToBytes(data);\n abytes(data);\n return data;\n}\n\n/**\n * Copies several Uint8Arrays into one.\n */\nexport function concatBytes(...arrays: Uint8Array[]): Uint8Array {\n let sum = 0;\n for (let i = 0; i < arrays.length; i++) {\n const a = arrays[i];\n abytes(a);\n sum += a.length;\n }\n const res = new Uint8Array(sum);\n for (let i = 0, pad = 0; i < arrays.length; i++) {\n const a = arrays[i];\n res.set(a, pad);\n pad += a.length;\n }\n return res;\n}\n\n// For runtime check if class implements interface\nexport abstract class Hash<T extends Hash<T>> {\n abstract blockLen: number; // Bytes per block\n abstract outputLen: number; // Bytes in output\n abstract update(buf: Input): this;\n // Writes digest into buf\n abstract digestInto(buf: Uint8Array): void;\n abstract digest(): Uint8Array;\n /**\n * Resets internal state. Makes Hash instance unusable.\n * Reset is impossible for keyed hashes if key is consumed into state. If digest is not consumed\n * by user, they will need to manually call `destroy()` when zeroing is necessary.\n */\n abstract destroy(): void;\n /**\n * Clones hash instance. Unsafe: doesn't check whether `to` is valid. Can be used as `clone()`\n * when no options are passed.\n * Reasons to use `_cloneInto` instead of clone: 1) performance 2) reuse instance => all internal\n * buffers are overwritten => causes buffer overwrite which is used for digest in some cases.\n * There are no guarantees for clean-up because it's impossible in JS.\n */\n abstract _cloneInto(to?: T): T;\n // Safe version that clones internal state\n clone(): T {\n return this._cloneInto();\n }\n}\n\n/**\n * XOF: streaming API to read digest in chunks.\n * Same as 'squeeze' in keccak/k12 and 'seek' in blake3, but more generic name.\n * When hash used in XOF mode it is up to user to call '.destroy' afterwards, since we cannot\n * destroy state, next call can require more bytes.\n */\nexport type HashXOF<T extends Hash<T>> = Hash<T> & {\n xof(bytes: number): Uint8Array; // Read 'bytes' bytes from digest stream\n xofInto(buf: Uint8Array): Uint8Array; // read buf.length bytes from digest stream into buf\n};\n\nconst toStr = {}.toString;\ntype EmptyObj = {};\nexport function checkOpts<T1 extends EmptyObj, T2 extends EmptyObj>(\n defaults: T1,\n opts?: T2\n): T1 & T2 {\n if (opts !== undefined && toStr.call(opts) !== '[object Object]')\n throw new Error('Options should be object or undefined');\n const merged = Object.assign(defaults, opts);\n return merged as T1 & T2;\n}\n\nexport type CHash = ReturnType<typeof wrapConstructor>;\n\nexport function wrapConstructor<T extends Hash<T>>(hashCons: () => Hash<T>) {\n const hashC = (msg: Input): Uint8Array => hashCons().update(toBytes(msg)).digest();\n const tmp = hashCons();\n hashC.outputLen = tmp.outputLen;\n hashC.blockLen = tmp.blockLen;\n hashC.create = () => hashCons();\n return hashC;\n}\n\nexport function wrapConstructorWithOpts<H extends Hash<H>, T extends Object>(\n hashCons: (opts?: T) => Hash<H>\n) {\n const hashC = (msg: Input, opts?: T): Uint8Array => hashCons(opts).update(toBytes(msg)).digest();\n const tmp = hashCons({} as T);\n hashC.outputLen = tmp.outputLen;\n hashC.blockLen = tmp.blockLen;\n hashC.create = (opts: T) => hashCons(opts);\n return hashC;\n}\n\nexport function wrapXOFConstructorWithOpts<H extends HashXOF<H>, T extends Object>(\n hashCons: (opts?: T) => HashXOF<H>\n) {\n const hashC = (msg: Input, opts?: T): Uint8Array => hashCons(opts).update(toBytes(msg)).digest();\n const tmp = hashCons({} as T);\n hashC.outputLen = tmp.outputLen;\n hashC.blockLen = tmp.blockLen;\n hashC.create = (opts: T) => hashCons(opts);\n return hashC;\n}\n\n/**\n * Secure PRNG. Uses `crypto.getRandomValues`, which defers to OS.\n */\nexport function randomBytes(bytesLength = 32): Uint8Array {\n if (crypto && typeof crypto.getRandomValues === 'function') {\n return crypto.getRandomValues(new Uint8Array(bytesLength));\n }\n // Legacy Node.js compatibility\n if (crypto && typeof crypto.randomBytes === 'function') {\n return crypto.randomBytes(bytesLength);\n }\n throw new Error('crypto.getRandomValues must be defined');\n}\n", "import { exists, output } from './_assert.js';\nimport { Hash, createView, Input, toBytes } from './utils.js';\n\n/**\n * Polyfill for Safari 14\n */\nfunction setBigUint64(view: DataView, byteOffset: number, value: bigint, isLE: boolean): void {\n if (typeof view.setBigUint64 === 'function') return view.setBigUint64(byteOffset, value, isLE);\n const _32n = BigInt(32);\n const _u32_max = BigInt(0xffffffff);\n const wh = Number((value >> _32n) & _u32_max);\n const wl = Number(value & _u32_max);\n const h = isLE ? 4 : 0;\n const l = isLE ? 0 : 4;\n view.setUint32(byteOffset + h, wh, isLE);\n view.setUint32(byteOffset + l, wl, isLE);\n}\n\n/**\n * Choice: a ? b : c\n */\nexport const Chi = (a: number, b: number, c: number) => (a & b) ^ (~a & c);\n\n/**\n * Majority function, true if any two inputs is true\n */\nexport const Maj = (a: number, b: number, c: number) => (a & b) ^ (a & c) ^ (b & c);\n\n/**\n * Merkle-Damgard hash construction base class.\n * Could be used to create MD5, RIPEMD, SHA1, SHA2.\n */\nexport abstract class HashMD<T extends HashMD<T>> extends Hash<T> {\n protected abstract process(buf: DataView, offset: number): void;\n protected abstract get(): number[];\n protected abstract set(...args: number[]): void;\n abstract destroy(): void;\n protected abstract roundClean(): void;\n // For partial updates less than block size\n protected buffer: Uint8Array;\n protected view: DataView;\n protected finished = false;\n protected length = 0;\n protected pos = 0;\n protected destroyed = false;\n\n constructor(\n readonly blockLen: number,\n public outputLen: number,\n readonly padOffset: number,\n readonly isLE: boolean\n ) {\n super();\n this.buffer = new Uint8Array(blockLen);\n this.view = createView(this.buffer);\n }\n update(data: Input): this {\n exists(this);\n const { view, buffer, blockLen } = this;\n data = toBytes(data);\n const len = data.length;\n for (let pos = 0; pos < len; ) {\n const take = Math.min(blockLen - this.pos, len - pos);\n // Fast path: we have at least one block in input, cast it to view and process\n if (take === blockLen) {\n const dataView = createView(data);\n for (; blockLen <= len - pos; pos += blockLen) this.process(dataView, pos);\n continue;\n }\n buffer.set(data.subarray(pos, pos + take), this.pos);\n this.pos += take;\n pos += take;\n if (this.pos === blockLen) {\n this.process(view, 0);\n this.pos = 0;\n }\n }\n this.length += data.length;\n this.roundClean();\n return this;\n }\n digestInto(out: Uint8Array) {\n exists(this);\n output(out, this);\n this.finished = true;\n // Padding\n // We can avoid allocation of buffer for padding completely if it\n // was previously not allocated here. But it won't change performance.\n const { buffer, view, blockLen, isLE } = this;\n let { pos } = this;\n // append the bit '1' to the message\n buffer[pos++] = 0b10000000;\n this.buffer.subarray(pos).fill(0);\n // we have less than padOffset left in buffer, so we cannot put length in\n // current block, need process it and pad again\n if (this.padOffset > blockLen - pos) {\n this.process(view, 0);\n pos = 0;\n }\n // Pad until full block byte with zeros\n for (let i = pos; i < blockLen; i++) buffer[i] = 0;\n // Note: sha512 requires length to be 128bit integer, but length in JS will overflow before that\n // You need to write around 2 exabytes (u64_max / 8 / (1024**6)) for this to happen.\n // So we just write lowest 64 bits of that value.\n setBigUint64(view, blockLen - 8, BigInt(this.length * 8), isLE);\n this.process(view, 0);\n const oview = createView(out);\n const len = this.outputLen;\n // NOTE: we do division by 4 later, which should be fused in single op with modulo by JIT\n if (len % 4) throw new Error('_sha2: outputLen should be aligned to 32bit');\n const outLen = len / 4;\n const state = this.get();\n if (outLen > state.length) throw new Error('_sha2: outputLen bigger than state');\n for (let i = 0; i < outLen; i++) oview.setUint32(4 * i, state[i], isLE);\n }\n digest() {\n const { buffer, outputLen } = this;\n this.digestInto(buffer);\n const res = buffer.slice(0, outputLen);\n this.destroy();\n return res;\n }\n _cloneInto(to?: T): T {\n to ||= new (this.constructor as any)() as T;\n to.set(...this.get());\n const { blockLen, buffer, length, finished, destroyed, pos } = this;\n to.length = length;\n to.pos = pos;\n to.finished = finished;\n to.destroyed = destroyed;\n if (length % blockLen) to.buffer.set(buffer);\n return to;\n }\n}\n", "import { HashMD, Chi, Maj } from './_md.js';\nimport { rotr, wrapConstructor } from './utils.js';\n\n// SHA2-256 need to try 2^128 hashes to execute birthday attack.\n// BTC network is doing 2^67 hashes/sec as per early 2023.\n\n// Round constants:\n// first 32 bits of the fractional parts of the cube roots of the first 64 primes 2..311)\n// prettier-ignore\nconst SHA256_K = /* @__PURE__ */ new Uint32Array([\n 0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,\n 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,\n 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,\n 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,\n 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13, 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,\n 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3, 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,\n 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,\n 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2\n]);\n\n// Initial state:\n// first 32 bits of the fractional parts of the square roots of the first 8 primes 2..19\n// prettier-ignore\nconst SHA256_IV = /* @__PURE__ */ new Uint32Array([\n 0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a, 0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19\n]);\n\n// Temporary buffer, not used to store anything between runs\n// Named this way because it matches specification.\nconst SHA256_W = /* @__PURE__ */ new Uint32Array(64);\nexport class SHA256 extends HashMD<SHA256> {\n // We cannot use array here since array allows indexing by variable\n // which means optimizer/compiler cannot use registers.\n A = SHA256_IV[0] | 0;\n B = SHA256_IV[1] | 0;\n C = SHA256_IV[2] | 0;\n D = SHA256_IV[3] | 0;\n E = SHA256_IV[4] | 0;\n F = SHA256_IV[5] | 0;\n G = SHA256_IV[6] | 0;\n H = SHA256_IV[7] | 0;\n\n constructor() {\n super(64, 32, 8, false);\n }\n protected get(): [number, number, number, number, number, number, number, number] {\n const { A, B, C, D, E, F, G, H } = this;\n return [A, B, C, D, E, F, G, H];\n }\n // prettier-ignore\n protected set(\n A: number, B: number, C: number, D: number, E: number, F: number, G: number, H: number\n ) {\n this.A = A | 0;\n this.B = B | 0;\n this.C = C | 0;\n this.D = D | 0;\n this.E = E | 0;\n this.F = F | 0;\n this.G = G | 0;\n this.H = H | 0;\n }\n protected process(view: DataView, offset: number): void {\n // Extend the first 16 words into the remaining 48 words w[16..63] of the message schedule array\n for (let i = 0; i < 16; i++, offset += 4) SHA256_W[i] = view.getUint32(offset, false);\n for (let i = 16; i < 64; i++) {\n const W15 = SHA256_W[i - 15];\n const W2 = SHA256_W[i - 2];\n const s0 = rotr(W15, 7) ^ rotr(W15, 18) ^ (W15 >>> 3);\n const s1 = rotr(W2, 17) ^ rotr(W2, 19) ^ (W2 >>> 10);\n SHA256_W[i] = (s1 + SHA256_W[i - 7] + s0 + SHA256_W[i - 16]) | 0;\n }\n // Compression function main loop, 64 rounds\n let { A, B, C, D, E, F, G, H } = this;\n for (let i = 0; i < 64; i++) {\n const sigma1 = rotr(E, 6) ^ rotr(E, 11) ^ rotr(E, 25);\n const T1 = (H + sigma1 + Chi(E, F, G) + SHA256_K[i] + SHA256_W[i]) | 0;\n const sigma0 = rotr(A, 2) ^ rotr(A, 13) ^ rotr(A, 22);\n const T2 = (sigma0 + Maj(A, B, C)) | 0;\n H = G;\n G = F;\n F = E;\n E = (D + T1) | 0;\n D = C;\n C = B;\n B = A;\n A = (T1 + T2) | 0;\n }\n // Add the compressed chunk to the current hash value\n A = (A + this.A) | 0;\n B = (B + this.B) | 0;\n C = (C + this.C) | 0;\n D = (D + this.D) | 0;\n E = (E + this.E) | 0;\n F = (F + this.F) | 0;\n G = (G + this.G) | 0;\n H = (H + this.H) | 0;\n this.set(A, B, C, D, E, F, G, H);\n }\n protected roundClean() {\n SHA256_W.fill(0);\n }\n destroy() {\n this.set(0, 0, 0, 0, 0, 0, 0, 0);\n this.buffer.fill(0);\n }\n}\n// Constants from https://nvlpubs.nist.gov/nistpubs/FIPS/NIST.FIPS.180-4.pdf\nclass SHA224 extends SHA256 {\n A = 0xc1059ed8 | 0;\n B = 0x367cd507 | 0;\n C = 0x3070dd17 | 0;\n D = 0xf70e5939 | 0;\n E = 0xffc00b31 | 0;\n F = 0x68581511 | 0;\n G = 0x64f98fa7 | 0;\n H = 0xbefa4fa4 | 0;\n constructor() {\n super();\n this.outputLen = 28;\n }\n}\n\n/**\n * SHA2-256 hash function\n * @param message - data that would be hashed\n */\nexport const sha256 = /* @__PURE__ */ wrapConstructor(() => new SHA256());\n/**\n * SHA2-224 hash function\n */\nexport const sha224 = /* @__PURE__ */ wrapConstructor(() => new SHA224());\n", "import { sha224 as jsSha224 } from '@noble/hashes/sha256';\n\n/**\n * Returns the SHA224 hash of the buffer.\n * @param data Arraybuffer to encode\n */\nexport function sha224(data: ArrayBuffer): Uint8Array {\n return jsSha224.create().update(new Uint8Array(data)).digest();\n}\n", "import { decode, encode } from './utils/base32';\nimport { getCrc32 } from './utils/getCrc';\nimport { sha224 } from './utils/sha224';\n\nexport const JSON_KEY_PRINCIPAL = '__principal__';\nconst SELF_AUTHENTICATING_SUFFIX = 2;\nconst ANONYMOUS_SUFFIX = 4;\n\nconst MANAGEMENT_CANISTER_PRINCIPAL_HEX_STR = 'aaaaa-aa';\n\nconst fromHexString = (hexString: string) =>\n new Uint8Array((hexString.match(/.{1,2}/g) ?? []).map(byte => parseInt(byte, 16)));\n\nconst toHexString = (bytes: Uint8Array) =>\n bytes.reduce((str, byte) => str + byte.toString(16).padStart(2, '0'), '');\n\nexport type JsonnablePrincipal = {\n [JSON_KEY_PRINCIPAL]: string;\n};\n\nexport class Principal {\n public static anonymous(): Principal {\n return new this(new Uint8Array([ANONYMOUS_SUFFIX]));\n }\n\n /**\n * Utility method, returning the principal representing the management canister, decoded from the hex string `'aaaaa-aa'`\n * @returns {Principal} principal of the management canister\n */\n public static managementCanister(): Principal {\n return this.fromHex(MANAGEMENT_CANISTER_PRINCIPAL_HEX_STR);\n }\n\n public static selfAuthenticating(publicKey: Uint8Array): Principal {\n const sha = sha224(publicKey);\n return new this(new Uint8Array([...sha, SELF_AUTHENTICATING_SUFFIX]));\n }\n\n public static from(other: unknown): Principal {\n if (typeof other === 'string') {\n return Principal.fromText(other);\n } else if (Object.getPrototypeOf(other) === Uint8Array.prototype) {\n return new Principal(other as Uint8Array);\n } else if (\n typeof other === 'object' &&\n other !== null &&\n (other as Principal)._isPrincipal === true\n ) {\n return new Principal((other as Principal)._arr);\n }\n\n throw new Error(`Impossible to convert ${JSON.stringify(other)} to Principal.`);\n }\n\n public static fromHex(hex: string): Principal {\n return new this(fromHexString(hex));\n }\n\n public static fromText(text: string): Principal {\n let maybePrincipal = text;\n // If formatted as JSON string, parse it first\n if (text.includes(JSON_KEY_PRINCIPAL)) {\n const obj = JSON.parse(text);\n if (JSON_KEY_PRINCIPAL in obj) {\n maybePrincipal = obj[JSON_KEY_PRINCIPAL];\n }\n }\n\n const canisterIdNoDash = maybePrincipal.toLowerCase().replace(/-/g, '');\n\n let arr = decode(canisterIdNoDash);\n arr = arr.slice(4, arr.length);\n\n const principal = new this(arr);\n if (principal.toText() !== maybePrincipal) {\n throw new Error(\n `Principal \"${principal.toText()}\" does not have a valid checksum (original value \"${maybePrincipal}\" may not be a valid Principal ID).`,\n );\n }\n\n return principal;\n }\n\n public static fromUint8Array(arr: Uint8Array): Principal {\n return new this(arr);\n }\n\n public readonly _isPrincipal = true;\n\n protected constructor(private _arr: Uint8Array) {}\n\n public isAnonymous(): boolean {\n return this._arr.byteLength === 1 && this._arr[0] === ANONYMOUS_SUFFIX;\n }\n\n public toUint8Array(): Uint8Array {\n return this._arr;\n }\n\n public toHex(): string {\n return toHexString(this._arr).toUpperCase();\n }\n\n public toText(): string {\n const checksumArrayBuf = new ArrayBuffer(4);\n const view = new DataView(checksumArrayBuf);\n view.setUint32(0, getCrc32(this._arr));\n const checksum = new Uint8Array(checksumArrayBuf);\n\n const bytes = Uint8Array.from(this._arr);\n const array = new Uint8Array([...checksum, ...bytes]);\n\n const result = encode(array);\n const matches = result.match(/.{1,5}/g);\n if (!matches) {\n // This should only happen if there's no character, which is unreachable.\n throw new Error();\n }\n return matches.join('-');\n }\n\n public toString(): string {\n return this.toText();\n }\n\n /**\n * Serializes to JSON\n * @returns {JsonnablePrincipal} a JSON object with a single key, {@link JSON_KEY_PRINCIPAL}, whose value is the principal as a string\n */\n public toJSON(): JsonnablePrincipal {\n return { [JSON_KEY_PRINCIPAL]: this.toText() };\n }\n\n /**\n * Utility method taking a Principal to compare against. Used for determining canister ranges in certificate verification\n * @param {Principal} other - a {@link Principal} to compare\n * @returns {'lt' | 'eq' | 'gt'} `'lt' | 'eq' | 'gt'` a string, representing less than, equal to, or greater than\n */\n public compareTo(other: Principal): 'lt' | 'eq' | 'gt' {\n for (let i = 0; i < Math.min(this._arr.length, other._arr.length); i++) {\n if (this._arr[i] < other._arr[i]) return 'lt';\n else if (this._arr[i] > other._arr[i]) return 'gt';\n }\n // Here, at least one principal is a prefix of the other principal (they could be the same)\n if (this._arr.length < other._arr.length) return 'lt';\n if (this._arr.length > other._arr.length) return 'gt';\n return 'eq';\n }\n\n /**\n * Utility method checking whether a provided Principal is less than or equal to the current one using the {@link Principal.compareTo} method\n * @param other a {@link Principal} to compare\n * @returns {boolean} boolean\n */\n public ltEq(other: Principal): boolean {\n const cmp = this.compareTo(other);\n return cmp == 'lt' || cmp == 'eq';\n }\n\n /**\n * Utility method checking whether a provided Principal is greater than or equal to the current one using the {@link Principal.compareTo} method\n * @param other a {@link Principal} to compare\n * @returns {boolean} boolean\n */\n public gtEq(other: Principal): boolean {\n const cmp = this.compareTo(other);\n return cmp == 'gt' || cmp == 'eq';\n }\n}\n", "import {Principal} from '@dfinity/principal';\n\n/**\n * Retrieves the Satellite's Principal ID.\n *\n * This function is a JavaScript binding for the Rust function\n * [`ic_cdk::id()`](https://docs.rs/ic-cdk/latest/ic_cdk/fn.id.html), which returns\n * the Principal of the executing canister.\n *\n * @returns {Principal} The Principal ID of the Satellite.\n */\nexport const id = (): Principal => {\n const principal = Principal.fromUint8Array(__ic_cdk_id());\n\n // We assume the Principal is always built using the global function and is therefore always valid.\n // In other words, we do not validate it to conserve resources and optimize performance.\n\n return principal;\n};\n"],
|
|
5
|
-
"mappings": "AAAA,IAAMA,EAAW,mCAGXC,EAAsC,OAAO,OAAO,IAAI,EAC9D,QAASC,EAAI,EAAGA,EAAIF,EAAS,OAAQE,IACnCD,EAAYD,EAASE,CAAC,CAAC,EAAIA,EAI7BD,EAAY,CAAG,EAAIA,EAAY,EAC/BA,EAAY,CAAG,EAAIA,EAAY,EAMzB,SAAUE,EAAOC,EAAiB,CAEtC,IAAIC,EAAO,EAEPC,EAAO,EAGPC,EAAS,GAEb,SAASC,EAAWC,EAAY,CAS9B,OARIJ,EAAO,EAETC,GAAQG,GAAQ,CAACJ,EAGjBC,EAAQG,GAAQJ,EAAQ,IAGtBA,EAAO,GAETA,GAAQ,EACD,IAGLA,EAAO,IAETE,GAAUP,EAASM,GAAQ,CAAC,EAC5BD,GAAQ,GAGH,EACT,CAEA,QAASH,EAAI,EAAGA,EAAIE,EAAM,QACxBF,GAAKM,EAAWJ,EAAMF,CAAC,CAAC,EAG1B,OAAOK,GAAUF,EAAO,EAAIL,EAASM,GAAQ,CAAC,EAAI,GACpD,CAKM,SAAUI,EAAON,EAAa,CAElC,IAAIC,EAAO,EAEPI,EAAO,EAELF,E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CAACC,EAEH,MAAM,IAAI,MAEZ,OAAOA,EAAQ,KAAK,GAAG,CACzB,CAEO,UAAQ,CACb,OAAO,KAAK,OAAM,CACpB,CAMO,QAAM,CACX,MAAO,CAAE,CAAC9B,CAAkB,EAAG,KAAK,OAAM,CAAE,CAC9C,CAOO,UAAUiB,EAAgB,CAC/B,QAASe,EAAI,EAAGA,EAAI,KAAK,IAAI,KAAK,KAAK,OAAQf,EAAM,KAAK,MAAM,EAAGe,IAAK,CACtE,GAAI,KAAK,KAAKA,CAAC,EAAIf,EAAM,KAAKe,CAAC,EAAG,MAAO,KACpC,GAAI,KAAK,KAAKA,CAAC,EAAIf,EAAM,KAAKe,CAAC,EAAG,MAAO,KAGhD,OAAI,KAAK,KAAK,OAASf,EAAM,KAAK,OAAe,KAC7C,KAAK,KAAK,OAASA,EAAM,KAAK,OAAe,KAC1C,IACT,CAOO,KAAKA,EAAgB,CAC1B,IAAMgB,EAAM,KAAK,UAAUhB,CAAK,EAChC,OAAOgB,GAAO,MAAQA,GAAO,IAC/B,CAOO,KAAKhB,EAAgB,CAC1B,IAAMgB,EAAM,KAAK,UAAUhB,CAAK,EAChC,OAAOgB,GAAO,MAAQA,GAAO,IAC/B,GC5JK,IAAMC,GAAK,IACEC,EAAU,eAAe,YAAY,CAAC",
|
|
6
|
-
"names": ["
|
|
3
|
+
"sources": ["src/ic-cdk/id.ts"],
|
|
4
|
+
"sourcesContent": ["import {Principal} from '@dfinity/principal';\n\n/**\n * Retrieves the Satellite's Principal ID.\n *\n * This function is a JavaScript binding for the Rust function\n * [`ic_cdk::id()`](https://docs.rs/ic-cdk/latest/ic_cdk/fn.id.html), which returns\n * the Principal of the executing canister.\n *\n * @returns {Principal} The Principal ID of the Satellite.\n */\nexport const id = (): Principal => {\n const principal = Principal.fromUint8Array(__ic_cdk_id());\n\n // We assume the Principal is always built using the global function and is therefore always valid.\n // In other words, we do not validate it to conserve resources and optimize performance.\n\n return principal;\n};\n"],
|
|
5
|
+
"mappings": "AAAA,OAAQ,aAAAA,MAAgB,qBAWjB,IAAMC,EAAK,IACED,EAAU,eAAe,YAAY,CAAC",
|
|
6
|
+
"names": ["Principal", "id"]
|
|
7
7
|
}
|
package/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{a as
|
|
1
|
+
import{a as U,b as w,c as P,d as T,e as S,f as y,g as I,h as d,i as h,j as z,k as r}from"./chunk-MKW7CALF.js";import*as i from"zod";import*as o from"zod";var n=o.object({collections:o.array(o.string()).min(1)}).strict();import*as t from"zod";var f=e=>t.object({caller:y,data:e}).strict(),A=e=>t.function().args(e).returns(t.void()),l=e=>t.function().args(e).returns(t.promise(t.void()));import*as O from"zod";import*as s from"zod";var u=s.object({before:r.optional(),after:r}).strict(),j=s.object({data:S,description:z.optional(),version:T.optional()}).strict(),k=s.object({current:r.optional(),proposed:j}).strict();var D=e=>O.object({collection:d,key:h,data:e}).strict(),F=f(D(u)),H=f(D(k));import*as c from"zod";var p=c.record(c.unknown());var C=e=>n.extend({assert:A(e)}).strict(),Z=C(H),te=Z,R=e=>i.function().args(p).returns(e),oe=e=>i.union([e,R(e)]);function re(e){return e}import*as m from"zod";var v=e=>n.extend({run:l(e)}).strict(),g=v(F),me=g,_=e=>m.function().args(p).returns(e),ae=e=>m.union([e,_(e)]);function xe(e){return e}import{jsonReplacer as E}from"@dfinity/utils";var a=e=>{let b=e.map(x=>typeof x=="object"?JSON.stringify(x,E):x).join(" ");globalThis.__ic_cdk_print(b)};globalThis.console={info(...e){a(e)},log(...e){a(e)},warn(...e){a(e)},error(...e){a(e)}};export{oe as AssertFnOrObjectSchema,R as AssertFnSchema,A as AssertFunctionSchema,te as AssertSchema,H as AssertSetDocContextSchema,Z as AssertSetDocSchema,d as CollectionSchema,n as CollectionsSchema,k as DocAssertSetSchema,D as DocContextSchema,u as DocUpsertSchema,f as HookContextSchema,ae as HookFnOrObjectSchema,_ as HookFnSchema,me as HookSchema,h as KeySchema,F as OnSetDocContextSchema,g as OnSetDocSchema,w as PrincipalSchema,j as ProposedDocSchema,S as RawDataSchema,U as RawPrincipalSchema,y as RawUserIdSchema,l as RunFunctionSchema,p as SatelliteEnvSchema,P as TimestampSchema,I as UserIdSchema,T as VersionSchema,re as defineAssert,xe as defineHook};
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
package/index.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["src/hooks/db/assertions.ts", "src/hooks/schemas/collections.ts", "src/hooks/schemas/
|
|
4
|
-
"sourcesContent": ["import * as z from 'zod';\nimport {CollectionsSchema} from '../schemas/collections';\nimport {AssertSetDocContextSchema} from '../schemas/db/context';\nimport {SatelliteEnvSchema} from '../schemas/satellite.env';\n\n/**\n * A generic schema for defining assertions related to collections.\n *\n * @template T - The type of context passed to the assertions when triggered.\n */\nconst OnAssertSchema = <T extends z.ZodTypeAny>(contextSchema: T) =>\n CollectionsSchema.extend({\n /**\n * A function that runs when the assertion is triggered for the specified collections.\n *\n * @param {T} context - Contains information about the affected document(s).\n * @returns {void} Resolves when the assertion completes.\n */\n assert: z.function().args(contextSchema).returns(z.void())\n }).strict();\n\n/**\n * @see AssertSetDoc\n */\nexport const AssertSetDocSchema = OnAssertSchema(AssertSetDocContextSchema);\n\n/**\n * An assertion that runs when a document is created or updated.\n */\nexport type AssertSetDoc = z.infer<typeof AssertSetDocSchema>;\n\n// TODO: to be extended\n/**\n * @see Assert\n */\nexport const AssertSchema = AssertSetDocSchema;\n\n/**\n * All assertions definitions.\n */\nexport type Assert = z.infer<typeof AssertSchema>;\n\nexport const AssertFnSchema = <T extends z.ZodTypeAny>(assertSchema: T) =>\n z.function().args(SatelliteEnvSchema).returns(assertSchema);\nexport type AssertFn<T extends Assert> = (assert: z.infer<typeof SatelliteEnvSchema>) => T;\n\nexport const AssertFnOrObjectSchema = <T extends z.ZodTypeAny>(assertSchema: T) =>\n z.union([assertSchema, AssertFnSchema(assertSchema)]);\nexport type AssertFnOrObject<T extends Assert> = T | AssertFn<T>;\n\nexport function defineAssert<T extends Assert>(assert: T): T;\nexport function defineAssert<T extends Assert>(assert: AssertFn<T>): AssertFn<T>;\nexport function defineAssert<T extends Assert>(assert: AssertFnOrObject<T>): AssertFnOrObject<T>;\nexport function defineAssert<T extends Assert>(assert: AssertFnOrObject<T>): AssertFnOrObject<T> {\n return assert;\n}\n", "import * as z from 'zod';\n\n/**\n * @see Collections\n */\nexport const CollectionsSchema = z\n .object({\n /**\n * An array containing at least one collection name where the hook or assertion will be executed.\n */\n collections: z.array(z.string()).min(1)\n })\n .strict();\n\n/**\n * Defines the collections where a hook or assertion should run.\n */\nexport type Collections = z.infer<typeof CollectionsSchema>;\n", "import * as z from 'zod';\nimport {CollectionSchema, KeySchema} from '../../../schemas/core';\nimport {HookContextSchema} from '../context';\nimport {DocAssertSetSchema, DocUpsertSchema} from './payload';\n\n/**\n * @see DocContext\n */\nexport const DocContextSchema = <T extends z.ZodTypeAny>(dataSchema: T) =>\n z\n .object({\n /**\n * The name of the collection where the document is stored.\n */\n collection: CollectionSchema,\n\n /**\n * The unique key identifying the document within the collection.\n */\n key: KeySchema,\n\n /**\n * The data associated with the document operation.\n */\n data: dataSchema\n })\n .strict();\n\n/**\n * Represents the context of a document operation within a collection.\n *\n * @template T - The type of data associated with the document.\n */\nexport type DocContext<T extends z.ZodTypeAny> = z.infer<ReturnType<typeof DocContextSchema<T>>>;\n\n/**\n * @see OnSetDocContext\n */\nexport const OnSetDocContextSchema = HookContextSchema(DocContextSchema(DocUpsertSchema));\n\n/**\n * The context provided to the `onSetDoc` hook.\n *\n * This context contains information about the document being created or updated,\n * along with details about the user who triggered the operation.\n */\nexport type OnSetDocContext = z.infer<typeof OnSetDocContextSchema>;\n\n/**\n * @see AssertSetDocContext\n */\nexport const AssertSetDocContextSchema = HookContextSchema(DocContextSchema(DocAssertSetSchema));\n\n/**\n * The context provided to the `assertSetDoc` hook.\n *\n * This context contains information about the document being validated before\n * it is created or updated. If validation fails, the developer should throw an error.\n */\nexport type AssertSetDocContext = z.infer<typeof AssertSetDocContextSchema>;\n", "import * as z from 'zod';\nimport {RawUserIdSchema} from '../../schemas/core';\n\n/**\n * @see HookContext\n */\nexport const HookContextSchema = <T extends z.ZodTypeAny>(dataSchema: T) =>\n z\n .object({\n /**\n * The user who originally triggered the function that in turn triggered the hook.\n */\n caller: RawUserIdSchema,\n\n /**\n * The data associated with the hook execution.\n */\n data: dataSchema\n })\n .strict();\n\n/**\n * Represents the context provided to hooks, containing information about the caller and related data.\n *\n * @template T - The type of data associated with the hook.\n */\nexport type HookContext<T extends z.ZodTypeAny> = z.infer<ReturnType<typeof HookContextSchema<T>>>;\n", "import * as z from 'zod';\nimport {RawDataSchema, VersionSchema} from '../../../schemas/core';\nimport {DocDescriptionSchema, DocSchema} from '../../../schemas/db';\n\n/**\n * @see DocUpsert\n */\nexport const DocUpsertSchema = z\n .object({\n /**\n * The previous version of the document before the update.\n * Undefined if this is a new document.\n */\n before: DocSchema.optional(),\n\n /**\n * The new version of the document after the update.\n */\n after: DocSchema\n })\n .strict();\n\n/**\n * Represents a document update operation.\n *\n * This is used in hooks where a document is either being created or updated.\n */\nexport type DocUpsert = z.infer<typeof DocUpsertSchema>;\n\n/**\n * @see ProposedDoc\n */\nexport const ProposedDocSchema = z\n .object({\n /**\n * The raw data of the document.\n */\n data: RawDataSchema,\n\n /**\n * An optional description of the document.\n */\n description: DocDescriptionSchema.optional(),\n\n /**\n * The expected version number to ensure consistency.\n */\n version: VersionSchema.optional()\n })\n .strict();\n\n/**\n * Represents the proposed version of a document.\n * This can be validated before allowing the operation.\n */\nexport type ProposedDoc = z.infer<typeof ProposedDocSchema>;\n\n/**\n * @see DocAssertSet\n */\nexport const DocAssertSetSchema = z\n .object({\n /**\n * The current version of the document before the operation.\n * Undefined if this is a new document.\n */\n current: DocSchema.optional(),\n\n /**\n * The proposed version of the document.\n * This can be validated before allowing the operation.\n */\n proposed: ProposedDocSchema\n })\n .strict();\n\n/**\n * Represents a validation check before setting a document.\n *\n * The developer can compare the `current` and `proposed` versions and\n * throw an error if their validation fails.\n */\nexport type DocAssertSet = z.infer<typeof DocAssertSetSchema>;\n", "import * as z from 'zod';\n\n/**\n * @see SatelliteEnv\n */\nexport const SatelliteEnvSchema = z.record(z.unknown());\n\n/**\n * Placeholder for future environment-specific configurations.\n *\n * Currently unused, but it may support features such as:\n * - Defining the execution mode (e.g., staging or production).\n * - Providing environment-specific values like `ckBtcLedgerId` for test or production.\n */\nexport type SatelliteEnv = z.infer<typeof SatelliteEnvSchema>;\n", "import * as z from 'zod';\nimport {CollectionsSchema} from '../schemas/collections';\nimport {OnSetDocContextSchema} from '../schemas/db/context';\nimport {SatelliteEnvSchema} from '../schemas/satellite.env';\n\n/**\n * A generic schema for defining hooks related to collections.\n *\n * @template T - The type of context passed to the hook when triggered.\n */\nconst OnHookSchema = <T extends z.ZodTypeAny>(contextSchema: T) =>\n CollectionsSchema.extend({\n /**\n * A function that runs when the hook is triggered for the specified collections.\n *\n * @param {T} context - Contains information about the affected document(s).\n * @returns {Promise<void>} Resolves when the operation completes.\n */\n run: z.function().args(contextSchema).returns(z.promise(z.void()))\n }).strict();\n\n/**\n * @see OnSetDoc\n */\nexport const OnSetDocSchema = OnHookSchema(OnSetDocContextSchema);\n\n/**\n * A hook that runs when a document is created or updated.\n */\nexport type OnSetDoc = z.infer<typeof OnSetDocSchema>;\n\n// TODO: to be extended\n/**\n * @see Hook\n */\nexport const HookSchema = OnSetDocSchema;\n\n/**\n * All hooks definitions.\n */\nexport type Hook = z.infer<typeof HookSchema>;\n\nexport const HookFnSchema = <T extends z.ZodTypeAny>(hookSchema: T) =>\n z.function().args(SatelliteEnvSchema).returns(hookSchema);\nexport type HookFn<T extends Hook> = (hook: z.infer<typeof SatelliteEnvSchema>) => T;\n\nexport const HookFnOrObjectSchema = <T extends z.ZodTypeAny>(hookSchema: T) =>\n z.union([hookSchema, HookFnSchema(hookSchema)]);\nexport type HookFnOrObject<T extends Hook> = T | HookFn<T>;\n\nexport function defineHook<T extends Hook>(hook: T): T;\nexport function defineHook<T extends Hook>(hook: HookFn<T>): HookFn<T>;\nexport function defineHook<T extends Hook>(hook: HookFnOrObject<T>): HookFnOrObject<T>;\nexport function defineHook<T extends Hook>(hook: HookFnOrObject<T>): HookFnOrObject<T> {\n return hook;\n}\n", "import {jsonReplacer} from '@dfinity/utils';\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nconst __juno_satellite_console_log = (v: any[]) => {\n const msg = v\n .map((arg) => (typeof arg === 'object' ? JSON.stringify(arg, jsonReplacer) : arg))\n .join(' ');\n\n globalThis.__ic_cdk_print(msg);\n};\n\n// @ts-expect-error We want to override the console\nglobalThis.console = {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n info(...v: any[]) {\n __juno_satellite_console_log(v);\n },\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n log(...v: any[]) {\n __juno_satellite_console_log(v);\n },\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n warn(...v: any[]) {\n __juno_satellite_console_log(v);\n },\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n error(...v: any[]) {\n __juno_satellite_console_log(v);\n }\n};\n"],
|
|
5
|
-
"mappings": "
|
|
6
|
-
"names": ["z", "z", "CollectionsSchema", "z", "HookContextSchema", "dataSchema", "RawUserIdSchema", "z", "DocUpsertSchema", "DocSchema", "ProposedDocSchema", "RawDataSchema", "DocDescriptionSchema", "VersionSchema", "DocAssertSetSchema", "DocContextSchema", "dataSchema", "CollectionSchema", "KeySchema", "OnSetDocContextSchema", "HookContextSchema", "DocUpsertSchema", "AssertSetDocContextSchema", "DocAssertSetSchema", "z", "SatelliteEnvSchema", "OnAssertSchema", "contextSchema", "CollectionsSchema", "AssertSetDocSchema", "AssertSetDocContextSchema", "AssertSchema", "AssertFnSchema", "assertSchema", "SatelliteEnvSchema", "AssertFnOrObjectSchema", "defineAssert", "assert", "z", "OnHookSchema", "contextSchema", "CollectionsSchema", "OnSetDocSchema", "OnSetDocContextSchema", "HookSchema", "HookFnSchema", "hookSchema", "SatelliteEnvSchema", "HookFnOrObjectSchema", "defineHook", "hook", "jsonReplacer", "__juno_satellite_console_log", "v", "msg", "arg"]
|
|
3
|
+
"sources": ["src/hooks/db/assertions.ts", "src/hooks/schemas/collections.ts", "src/hooks/schemas/context.ts", "src/hooks/schemas/db/context.ts", "src/hooks/schemas/db/payload.ts", "src/hooks/schemas/satellite.env.ts", "src/hooks/db/hooks.ts", "src/polyfills/console.polyfill.ts"],
|
|
4
|
+
"sourcesContent": ["import * as z from 'zod';\nimport {CollectionsSchema} from '../schemas/collections';\nimport {AssertFunctionSchema} from '../schemas/context';\nimport {AssertSetDocContextSchema} from '../schemas/db/context';\nimport {SatelliteEnvSchema} from '../schemas/satellite.env';\n\n/**\n * A generic schema for defining assertions related to collections.\n *\n * @template T - The type of context passed to the assertions when triggered.\n */\nconst OnAssertSchema = <T extends z.ZodTypeAny>(contextSchema: T) =>\n CollectionsSchema.extend({\n /**\n * A function that runs when the assertion is triggered for the specified collections.\n *\n * @param {T} context - Contains information about the affected document(s).\n * @returns {void} Resolves when the assertion completes.\n */\n assert: AssertFunctionSchema<T>(contextSchema)\n }).strict();\n\n/**\n * @see AssertSetDoc\n */\nexport const AssertSetDocSchema = OnAssertSchema(AssertSetDocContextSchema);\n\n/**\n * An assertion that runs when a document is created or updated.\n */\nexport type AssertSetDoc = z.infer<typeof AssertSetDocSchema>;\n\n// TODO: to be extended\n/**\n * @see Assert\n */\nexport const AssertSchema = AssertSetDocSchema;\n\n/**\n * All assertions definitions.\n */\nexport type Assert = z.infer<typeof AssertSchema>;\n\nexport const AssertFnSchema = <T extends z.ZodTypeAny>(assertSchema: T) =>\n z.function().args(SatelliteEnvSchema).returns(assertSchema);\nexport type AssertFn<T extends Assert> = (assert: z.infer<typeof SatelliteEnvSchema>) => T;\n\nexport const AssertFnOrObjectSchema = <T extends z.ZodTypeAny>(assertSchema: T) =>\n z.union([assertSchema, AssertFnSchema(assertSchema)]);\nexport type AssertFnOrObject<T extends Assert> = T | AssertFn<T>;\n\nexport function defineAssert<T extends Assert>(assert: T): T;\nexport function defineAssert<T extends Assert>(assert: AssertFn<T>): AssertFn<T>;\nexport function defineAssert<T extends Assert>(assert: AssertFnOrObject<T>): AssertFnOrObject<T>;\nexport function defineAssert<T extends Assert>(assert: AssertFnOrObject<T>): AssertFnOrObject<T> {\n return assert;\n}\n", "import * as z from 'zod';\n\n/**\n * @see Collections\n */\nexport const CollectionsSchema = z\n .object({\n /**\n * An array containing at least one collection name where the hook or assertion will be executed.\n */\n collections: z.array(z.string()).min(1)\n })\n .strict();\n\n/**\n * Defines the collections where a hook or assertion should run.\n */\nexport type Collections = z.infer<typeof CollectionsSchema>;\n", "import * as z from 'zod';\nimport {RawUserIdSchema} from '../../schemas/core';\n\n/**\n * @see HookContext\n */\nexport const HookContextSchema = <T extends z.ZodTypeAny>(dataSchema: T) =>\n z\n .object({\n /**\n * The user who originally triggered the function that in turn triggered the hook.\n */\n caller: RawUserIdSchema,\n\n /**\n * The data associated with the hook execution.\n */\n data: dataSchema\n })\n .strict();\n\n/**\n * Represents the context provided to hooks, containing information about the caller and related data.\n *\n * @template T - The type of data associated with the hook.\n */\nexport type HookContext<T extends z.ZodTypeAny> = z.infer<ReturnType<typeof HookContextSchema<T>>>;\n\n/**\n * @see AssertFunction\n */\nexport const AssertFunctionSchema = <T extends z.ZodTypeAny>(contextSchema: T) =>\n z.function().args(contextSchema).returns(z.void());\n\n/**\n * Defines the `assert` function schema for assertions.\n *\n * The function takes a context argument and returns `void`.\n *\n * @template T - The type of context passed to the function.\n */\nexport type AssertFunction<T> = z.infer<ReturnType<typeof AssertFunctionSchema<z.ZodType<T>>>>;\n\n/**\n * @see RunFunction\n */\nexport const RunFunctionSchema = <T extends z.ZodTypeAny>(contextSchema: T) =>\n z.function().args(contextSchema).returns(z.promise(z.void()));\n\n/**\n * Defines the `run` function schema for hooks.\n *\n * The function takes a context argument and returns a `Promise<void>`.\n *\n * @template T - The type of context passed to the function.\n */\nexport type RunFunction<T> = z.infer<ReturnType<typeof RunFunctionSchema<z.ZodType<T>>>>;\n", "import * as z from 'zod';\nimport {CollectionSchema, KeySchema} from '../../../schemas/core';\nimport {HookContextSchema} from '../context';\nimport {DocAssertSetSchema, DocUpsertSchema} from './payload';\n\n/**\n * @see DocContext\n */\nexport const DocContextSchema = <T extends z.ZodTypeAny>(dataSchema: T) =>\n z\n .object({\n /**\n * The name of the collection where the document is stored.\n */\n collection: CollectionSchema,\n\n /**\n * The unique key identifying the document within the collection.\n */\n key: KeySchema,\n\n /**\n * The data associated with the document operation.\n */\n data: dataSchema\n })\n .strict();\n\n/**\n * Represents the context of a document operation within a collection.\n *\n * @template T - The type of data associated with the document.\n */\nexport type DocContext<T extends z.ZodTypeAny> = z.infer<ReturnType<typeof DocContextSchema<T>>>;\n\n/**\n * @see OnSetDocContext\n */\nexport const OnSetDocContextSchema = HookContextSchema(DocContextSchema(DocUpsertSchema));\n\n/**\n * The context provided to the `onSetDoc` hook.\n *\n * This context contains information about the document being created or updated,\n * along with details about the user who triggered the operation.\n */\nexport type OnSetDocContext = z.infer<typeof OnSetDocContextSchema>;\n\n/**\n * @see AssertSetDocContext\n */\nexport const AssertSetDocContextSchema = HookContextSchema(DocContextSchema(DocAssertSetSchema));\n\n/**\n * The context provided to the `assertSetDoc` hook.\n *\n * This context contains information about the document being validated before\n * it is created or updated. If validation fails, the developer should throw an error.\n */\nexport type AssertSetDocContext = z.infer<typeof AssertSetDocContextSchema>;\n", "import * as z from 'zod';\nimport {RawDataSchema, VersionSchema} from '../../../schemas/core';\nimport {DocDescriptionSchema, DocSchema} from '../../../schemas/db';\n\n/**\n * @see DocUpsert\n */\nexport const DocUpsertSchema = z\n .object({\n /**\n * The previous version of the document before the update.\n * Undefined if this is a new document.\n */\n before: DocSchema.optional(),\n\n /**\n * The new version of the document after the update.\n */\n after: DocSchema\n })\n .strict();\n\n/**\n * Represents a document update operation.\n *\n * This is used in hooks where a document is either being created or updated.\n */\nexport type DocUpsert = z.infer<typeof DocUpsertSchema>;\n\n/**\n * @see ProposedDoc\n */\nexport const ProposedDocSchema = z\n .object({\n /**\n * The raw data of the document.\n */\n data: RawDataSchema,\n\n /**\n * An optional description of the document.\n */\n description: DocDescriptionSchema.optional(),\n\n /**\n * The expected version number to ensure consistency.\n */\n version: VersionSchema.optional()\n })\n .strict();\n\n/**\n * Represents the proposed version of a document.\n * This can be validated before allowing the operation.\n */\nexport type ProposedDoc = z.infer<typeof ProposedDocSchema>;\n\n/**\n * @see DocAssertSet\n */\nexport const DocAssertSetSchema = z\n .object({\n /**\n * The current version of the document before the operation.\n * Undefined if this is a new document.\n */\n current: DocSchema.optional(),\n\n /**\n * The proposed version of the document.\n * This can be validated before allowing the operation.\n */\n proposed: ProposedDocSchema\n })\n .strict();\n\n/**\n * Represents a validation check before setting a document.\n *\n * The developer can compare the `current` and `proposed` versions and\n * throw an error if their validation fails.\n */\nexport type DocAssertSet = z.infer<typeof DocAssertSetSchema>;\n", "import * as z from 'zod';\n\n/**\n * @see SatelliteEnv\n */\nexport const SatelliteEnvSchema = z.record(z.unknown());\n\n/**\n * Placeholder for future environment-specific configurations.\n *\n * Currently unused, but it may support features such as:\n * - Defining the execution mode (e.g., staging or production).\n * - Providing environment-specific values like `ckBtcLedgerId` for test or production.\n */\nexport type SatelliteEnv = z.infer<typeof SatelliteEnvSchema>;\n", "import * as z from 'zod';\nimport {CollectionsSchema} from '../schemas/collections';\nimport {RunFunctionSchema} from '../schemas/context';\nimport {OnSetDocContextSchema} from '../schemas/db/context';\nimport {SatelliteEnvSchema} from '../schemas/satellite.env';\n\n/**\n * A generic schema for defining hooks related to collections.\n *\n * @template T - The type of context passed to the hook when triggered.\n */\nconst OnHookSchema = <T extends z.ZodTypeAny>(contextSchema: T) =>\n CollectionsSchema.extend({\n /**\n * A function that runs when the hook is triggered for the specified collections.\n *\n * @param {T} context - Contains information about the affected document(s).\n * @returns {Promise<void>} Resolves when the operation completes.\n */\n run: RunFunctionSchema<T>(contextSchema)\n }).strict();\n\n/**\n * @see OnSetDoc\n */\nexport const OnSetDocSchema = OnHookSchema(OnSetDocContextSchema);\n\n/**\n * A hook that runs when a document is created or updated.\n */\nexport type OnSetDoc = z.infer<typeof OnSetDocSchema>;\n\n// TODO: to be extended\n/**\n * @see Hook\n */\nexport const HookSchema = OnSetDocSchema;\n\n/**\n * All hooks definitions.\n */\nexport type Hook = z.infer<typeof HookSchema>;\n\nexport const HookFnSchema = <T extends z.ZodTypeAny>(hookSchema: T) =>\n z.function().args(SatelliteEnvSchema).returns(hookSchema);\nexport type HookFn<T extends Hook> = (hook: z.infer<typeof SatelliteEnvSchema>) => T;\n\nexport const HookFnOrObjectSchema = <T extends z.ZodTypeAny>(hookSchema: T) =>\n z.union([hookSchema, HookFnSchema(hookSchema)]);\nexport type HookFnOrObject<T extends Hook> = T | HookFn<T>;\n\nexport function defineHook<T extends Hook>(hook: T): T;\nexport function defineHook<T extends Hook>(hook: HookFn<T>): HookFn<T>;\nexport function defineHook<T extends Hook>(hook: HookFnOrObject<T>): HookFnOrObject<T>;\nexport function defineHook<T extends Hook>(hook: HookFnOrObject<T>): HookFnOrObject<T> {\n return hook;\n}\n", "import {jsonReplacer} from '@dfinity/utils';\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nconst __juno_satellite_console_log = (v: any[]) => {\n const msg = v\n .map((arg) => (typeof arg === 'object' ? JSON.stringify(arg, jsonReplacer) : arg))\n .join(' ');\n\n globalThis.__ic_cdk_print(msg);\n};\n\n// @ts-expect-error We want to override the console\nglobalThis.console = {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n info(...v: any[]) {\n __juno_satellite_console_log(v);\n },\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n log(...v: any[]) {\n __juno_satellite_console_log(v);\n },\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n warn(...v: any[]) {\n __juno_satellite_console_log(v);\n },\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n error(...v: any[]) {\n __juno_satellite_console_log(v);\n }\n};\n"],
|
|
5
|
+
"mappings": "8GAAA,UAAYA,MAAO,MCAnB,UAAYC,MAAO,MAKZ,IAAMC,EACV,SAAO,CAIN,YAAe,QAAQ,SAAO,CAAC,EAAE,IAAI,CAAC,CACxC,CAAC,EACA,OAAO,ECZV,UAAYC,MAAO,MAMZ,IAAMC,EAA6CC,GAErD,SAAO,CAIN,OAAQC,EAKR,KAAMD,CACR,CAAC,EACA,OAAO,EAYCE,EAAgDC,GACzD,WAAS,EAAE,KAAKA,CAAa,EAAE,QAAU,OAAK,CAAC,EActCC,EAA6CD,GACtD,WAAS,EAAE,KAAKA,CAAa,EAAE,QAAU,UAAU,OAAK,CAAC,CAAC,EC/C9D,UAAYE,MAAO,MCAnB,UAAYC,MAAO,MAOZ,IAAMC,EACV,SAAO,CAKN,OAAQC,EAAU,SAAS,EAK3B,MAAOA,CACT,CAAC,EACA,OAAO,EAYGC,EACV,SAAO,CAIN,KAAMC,EAKN,YAAaC,EAAqB,SAAS,EAK3C,QAASC,EAAc,SAAS,CAClC,CAAC,EACA,OAAO,EAWGC,EACV,SAAO,CAKN,QAASL,EAAU,SAAS,EAM5B,SAAUC,CACZ,CAAC,EACA,OAAO,EDlEH,IAAMK,EAA4CC,GAEpD,SAAO,CAIN,WAAYC,EAKZ,IAAKC,EAKL,KAAMF,CACR,CAAC,EACA,OAAO,EAYCG,EAAwBC,EAAkBL,EAAiBM,CAAe,CAAC,EAa3EC,EAA4BF,EAAkBL,EAAiBQ,CAAkB,CAAC,EEnD/F,UAAYC,MAAO,MAKZ,IAAMC,EAAuB,SAAS,UAAQ,CAAC,ELMtD,IAAMC,EAA0CC,GAC9CC,EAAkB,OAAO,CAOvB,OAAQC,EAAwBF,CAAa,CAC/C,CAAC,EAAE,OAAO,EAKCG,EAAqBJ,EAAeK,CAAyB,EAW7DC,GAAeF,EAOfG,EAA0CC,GACnD,WAAS,EAAE,KAAKC,CAAkB,EAAE,QAAQD,CAAY,EAG/CE,GAAkDF,GAC3D,QAAM,CAACA,EAAcD,EAAeC,CAAY,CAAC,CAAC,EAM/C,SAASG,GAA+BC,EAAkD,CAC/F,OAAOA,CACT,CMxDA,UAAYC,MAAO,MAWnB,IAAMC,EAAwCC,GAC5CC,EAAkB,OAAO,CAOvB,IAAKC,EAAqBF,CAAa,CACzC,CAAC,EAAE,OAAO,EAKCG,EAAiBJ,EAAaK,CAAqB,EAWnDC,GAAaF,EAObG,EAAwCC,GACjD,WAAS,EAAE,KAAKC,CAAkB,EAAE,QAAQD,CAAU,EAG7CE,GAAgDF,GACzD,QAAM,CAACA,EAAYD,EAAaC,CAAU,CAAC,CAAC,EAMzC,SAASG,GAA2BC,EAA4C,CACrF,OAAOA,CACT,CCxDA,OAAQ,gBAAAC,MAAmB,iBAG3B,IAAMC,EAAgCC,GAAa,CACjD,IAAMC,EAAMD,EACT,IAAKE,GAAS,OAAOA,GAAQ,SAAW,KAAK,UAAUA,EAAKJ,CAAY,EAAII,CAAI,EAChF,KAAK,GAAG,EAEX,WAAW,eAAeD,CAAG,CAC/B,EAGA,WAAW,QAAU,CAEnB,QAAQD,EAAU,CAChBD,EAA6BC,CAAC,CAChC,EAEA,OAAOA,EAAU,CACfD,EAA6BC,CAAC,CAChC,EAEA,QAAQA,EAAU,CAChBD,EAA6BC,CAAC,CAChC,EAEA,SAASA,EAAU,CACjBD,EAA6BC,CAAC,CAChC,CACF",
|
|
6
|
+
"names": ["z", "z", "CollectionsSchema", "z", "HookContextSchema", "dataSchema", "RawUserIdSchema", "AssertFunctionSchema", "contextSchema", "RunFunctionSchema", "z", "z", "DocUpsertSchema", "DocSchema", "ProposedDocSchema", "RawDataSchema", "DocDescriptionSchema", "VersionSchema", "DocAssertSetSchema", "DocContextSchema", "dataSchema", "CollectionSchema", "KeySchema", "OnSetDocContextSchema", "HookContextSchema", "DocUpsertSchema", "AssertSetDocContextSchema", "DocAssertSetSchema", "z", "SatelliteEnvSchema", "OnAssertSchema", "contextSchema", "CollectionsSchema", "AssertFunctionSchema", "AssertSetDocSchema", "AssertSetDocContextSchema", "AssertSchema", "AssertFnSchema", "assertSchema", "SatelliteEnvSchema", "AssertFnOrObjectSchema", "defineAssert", "assert", "z", "OnHookSchema", "contextSchema", "CollectionsSchema", "RunFunctionSchema", "OnSetDocSchema", "OnSetDocContextSchema", "HookSchema", "HookFnSchema", "hookSchema", "SatelliteEnvSchema", "HookFnOrObjectSchema", "defineHook", "hook", "jsonReplacer", "__juno_satellite_console_log", "v", "msg", "arg"]
|
|
7
7
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@junobuild/functions",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.8",
|
|
4
4
|
"description": "JavaScript and TypeScript utilities for Juno Serverless Functions",
|
|
5
5
|
"author": "David Dal Busco (https://daviddalbusco.com)",
|
|
6
6
|
"license": "MIT",
|
|
@@ -46,6 +46,10 @@
|
|
|
46
46
|
},
|
|
47
47
|
"homepage": "https://juno.build",
|
|
48
48
|
"peerDependencies": {
|
|
49
|
+
"@dfinity/agent": "^2.3.0",
|
|
50
|
+
"@dfinity/candid": "^2.3.0",
|
|
51
|
+
"@dfinity/identity": "^2.3.0",
|
|
52
|
+
"@dfinity/principal": "^2.3.0",
|
|
49
53
|
"@dfinity/utils": "^2",
|
|
50
54
|
"zod": "^3"
|
|
51
55
|
}
|
package/schemas/candid.d.ts
CHANGED
|
@@ -1,11 +1,18 @@
|
|
|
1
|
+
import { Principal as CandidPrincipal } from '@dfinity/principal';
|
|
1
2
|
import * as z from 'zod';
|
|
2
3
|
/**
|
|
3
4
|
* @see RawPrincipal
|
|
4
5
|
*/
|
|
5
6
|
export declare const RawPrincipalSchema: z.ZodType<Uint8Array<ArrayBufferLike>, z.ZodTypeDef, Uint8Array<ArrayBufferLike>>;
|
|
6
7
|
/**
|
|
7
|
-
* Represents a raw principal
|
|
8
|
-
*
|
|
9
|
-
* Principals are unique identities used in authentication and authorization.
|
|
8
|
+
* Represents a raw principal - a Uint8Array representation of a Principal.
|
|
10
9
|
*/
|
|
11
10
|
export type RawPrincipal = z.infer<typeof RawPrincipalSchema>;
|
|
11
|
+
/**
|
|
12
|
+
* @see Principal
|
|
13
|
+
*/
|
|
14
|
+
export declare const PrincipalSchema: z.ZodType<CandidPrincipal, z.ZodTypeDef, CandidPrincipal>;
|
|
15
|
+
/**
|
|
16
|
+
* Represents a principal - i.e. an object instantiated with the class Principal.
|
|
17
|
+
*/
|
|
18
|
+
export type Principal = z.infer<typeof PrincipalSchema>;
|
package/schemas/core.d.ts
CHANGED
|
@@ -39,6 +39,16 @@ export declare const RawUserIdSchema: z.ZodType<Uint8Array<ArrayBufferLike>, z.Z
|
|
|
39
39
|
* This is a principal associated with a user.
|
|
40
40
|
*/
|
|
41
41
|
export type RawUserId = z.infer<typeof RawUserIdSchema>;
|
|
42
|
+
/**
|
|
43
|
+
* @see UserId
|
|
44
|
+
*/
|
|
45
|
+
export declare const UserIdSchema: z.ZodType<import("@dfinity/principal").Principal, z.ZodTypeDef, import("@dfinity/principal").Principal>;
|
|
46
|
+
/**
|
|
47
|
+
* Represents a user identifier.
|
|
48
|
+
*
|
|
49
|
+
* This is a principal associated with a user.
|
|
50
|
+
*/
|
|
51
|
+
export type UserId = z.infer<typeof UserIdSchema>;
|
|
42
52
|
/**
|
|
43
53
|
* @see Collection
|
|
44
54
|
*/
|
package/sdk/schemas/db.d.ts
CHANGED
|
@@ -44,7 +44,7 @@ export declare const SetDocStoreParamsSchema: z.ZodObject<{
|
|
|
44
44
|
/**
|
|
45
45
|
* The caller who initiate the document operation.
|
|
46
46
|
*/
|
|
47
|
-
caller: z.ZodType<Uint8Array<ArrayBufferLike>, z.ZodTypeDef, Uint8Array<ArrayBufferLike
|
|
47
|
+
caller: z.ZodUnion<[z.ZodType<Uint8Array<ArrayBufferLike>, z.ZodTypeDef, Uint8Array<ArrayBufferLike>>, z.ZodType<import("@dfinity/principal").Principal, z.ZodTypeDef, import("@dfinity/principal").Principal>]>;
|
|
48
48
|
/**
|
|
49
49
|
* The name of the collection where the document is stored.
|
|
50
50
|
*/
|
|
@@ -82,7 +82,7 @@ export declare const SetDocStoreParamsSchema: z.ZodObject<{
|
|
|
82
82
|
version?: bigint | undefined;
|
|
83
83
|
}>;
|
|
84
84
|
}, "strict", z.ZodTypeAny, {
|
|
85
|
-
caller: Uint8Array<ArrayBufferLike
|
|
85
|
+
caller: Uint8Array<ArrayBufferLike> | import("@dfinity/principal").Principal;
|
|
86
86
|
collection: string;
|
|
87
87
|
doc: {
|
|
88
88
|
data: Uint8Array<ArrayBufferLike>;
|
|
@@ -91,7 +91,7 @@ export declare const SetDocStoreParamsSchema: z.ZodObject<{
|
|
|
91
91
|
version?: bigint | undefined;
|
|
92
92
|
};
|
|
93
93
|
}, {
|
|
94
|
-
caller: Uint8Array<ArrayBufferLike
|
|
94
|
+
caller: Uint8Array<ArrayBufferLike> | import("@dfinity/principal").Principal;
|
|
95
95
|
collection: string;
|
|
96
96
|
doc: {
|
|
97
97
|
data: Uint8Array<ArrayBufferLike>;
|
package/sdk.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{d as r,e as a,f as c,g as s,h as m,i,j as n}from"./chunk-MKW7CALF.js";import{Principal as h}from"@dfinity/principal";import*as e from"zod";var f=e.object({key:i,description:n.optional(),data:a,version:r.optional()}).strict(),p=e.object({caller:c.or(s),collection:m,doc:f}).strict();var T=o=>{p.parse(o);let{caller:t,collection:S,doc:l}=o,{key:_,...D}=l,d=t instanceof h?t.toUint8Array():t;__juno_satellite_datastore_set_doc_store(d,S,_,D)};import{jsonReplacer as x,jsonReviver as y}from"@dfinity/utils";var b=o=>JSON.parse(__juno_satellite_datastore_raw_data_to_text(o),y),k=o=>__juno_satellite_datastore_raw_data_from_text(JSON.stringify(o,x));export{f as SetDocSchema,p as SetDocStoreParamsSchema,b as decodeDocData,k as encodeDocData,T as setDocStore};
|
|
2
2
|
//# sourceMappingURL=sdk.js.map
|
package/sdk.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["src/sdk/
|
|
4
|
-
"sourcesContent": ["import * as z from 'zod';\nimport {\n CollectionSchema,\n KeySchema,\n RawDataSchema,\n RawUserIdSchema,\n VersionSchema\n} from '../../schemas/core';\nimport {DocDescriptionSchema} from '../../schemas/db';\n\n/**\n * @see SetDoc\n */\nexport const SetDocSchema = z\n .object({\n /**\n * The unique key identifying the document within the collection.\n */\n key: KeySchema,\n\n /**\n * An optional description of the document.\n */\n description: DocDescriptionSchema.optional(),\n\n /**\n * The raw data of the document.\n */\n data: RawDataSchema,\n\n /**\n * The expected version number to ensure consistency.\n * If provided, the operation will fail if the stored version does not match.\n */\n version: VersionSchema.optional()\n })\n .strict();\n\n/**\n * Represents a request to set or update a document.\n *\n * This is used when submitting new document data.\n */\nexport type SetDoc = z.infer<typeof SetDocSchema>;\n\n/**\n * @see SetDocStoreParams\n */\nexport const SetDocStoreParamsSchema = z\n .object({\n /**\n * The caller who initiate the document operation.\n */\n caller: RawUserIdSchema,\n\n /**\n * The name of the collection where the document is stored.\n */\n collection: CollectionSchema,\n\n /**\n * The data, key and other information required to create or update a document.\n */\n doc: SetDocSchema\n })\n .strict();\n\n/**\n * Represents the parameters required to store or update a document.\n *\n * This includes the document data along with metadata such as the caller,\n * collection, and key.\n */\nexport type SetDocStoreParams = z.infer<typeof SetDocStoreParamsSchema>;\n", "import {
|
|
5
|
-
"mappings": "
|
|
6
|
-
"names": ["z", "SetDocSchema", "KeySchema", "DocDescriptionSchema", "RawDataSchema", "VersionSchema", "SetDocStoreParamsSchema", "RawUserIdSchema", "CollectionSchema", "setDocStore", "params", "SetDocStoreParamsSchema", "
|
|
3
|
+
"sources": ["src/sdk/db.sdk.ts", "src/sdk/schemas/db.ts", "src/sdk/serializer.sdk.ts"],
|
|
4
|
+
"sourcesContent": ["import {Principal} from '@dfinity/principal';\nimport {SetDocStoreParams, SetDocStoreParamsSchema} from './schemas/db';\n\n/**\n * Stores or updates a document in the datastore.\n *\n * The data must have been encoded - using encodeDocData - before calling this function.\n *\n * @param {SetDocStoreParams} params - The parameters required to store the document,\n * including the caller, collection, key, and document data.\n *\n * @throws {z.ZodError} If the provided parameters do not match the expected schema.\n * @throws {Error} If the Satellite fails at validating the submitted document before storing it.\n */\nexport const setDocStore = (params: SetDocStoreParams) => {\n SetDocStoreParamsSchema.parse(params);\n\n const {caller: providedCaller, collection, doc} = params;\n\n const {key, ...setDoc} = doc;\n\n const caller =\n providedCaller instanceof Principal ? providedCaller.toUint8Array() : providedCaller;\n\n __juno_satellite_datastore_set_doc_store(caller, collection, key, setDoc);\n};\n", "import * as z from 'zod';\nimport {\n CollectionSchema,\n KeySchema,\n RawDataSchema,\n RawUserIdSchema,\n UserIdSchema,\n VersionSchema\n} from '../../schemas/core';\nimport {DocDescriptionSchema} from '../../schemas/db';\n\n/**\n * @see SetDoc\n */\nexport const SetDocSchema = z\n .object({\n /**\n * The unique key identifying the document within the collection.\n */\n key: KeySchema,\n\n /**\n * An optional description of the document.\n */\n description: DocDescriptionSchema.optional(),\n\n /**\n * The raw data of the document.\n */\n data: RawDataSchema,\n\n /**\n * The expected version number to ensure consistency.\n * If provided, the operation will fail if the stored version does not match.\n */\n version: VersionSchema.optional()\n })\n .strict();\n\n/**\n * Represents a request to set or update a document.\n *\n * This is used when submitting new document data.\n */\nexport type SetDoc = z.infer<typeof SetDocSchema>;\n\n/**\n * @see SetDocStoreParams\n */\nexport const SetDocStoreParamsSchema = z\n .object({\n /**\n * The caller who initiate the document operation.\n */\n caller: RawUserIdSchema.or(UserIdSchema),\n\n /**\n * The name of the collection where the document is stored.\n */\n collection: CollectionSchema,\n\n /**\n * The data, key and other information required to create or update a document.\n */\n doc: SetDocSchema\n })\n .strict();\n\n/**\n * Represents the parameters required to store or update a document.\n *\n * This includes the document data along with metadata such as the caller,\n * collection, and key.\n */\nexport type SetDocStoreParams = z.infer<typeof SetDocStoreParamsSchema>;\n", "import {jsonReplacer, jsonReviver} from '@dfinity/utils';\nimport type {RawData} from '../schemas/core';\n\n/**\n * Decodes the raw data of a document into a JavaScript object.\n *\n * @template T The expected type of the decoded object.\n * @param {RawData} data - The raw data to be decoded.\n * @returns {T} The parsed JavaScript object.\n */\nexport const decodeDocData = <T>(data: RawData): T =>\n JSON.parse(__juno_satellite_datastore_raw_data_to_text(data), jsonReviver);\n\n/**\n * Encodes a JavaScript object into a raw data format to be applied to a document.\n *\n * @template T The type of the object to be encoded.\n * @param {T} data - The data to be encoded.\n * @returns {RawData} The serialized raw data.\n */\nexport const encodeDocData = <T>(data: T): RawData =>\n __juno_satellite_datastore_raw_data_from_text(JSON.stringify(data, jsonReplacer));\n"],
|
|
5
|
+
"mappings": "6EAAA,OAAQ,aAAAA,MAAgB,qBCAxB,UAAYC,MAAO,MAcZ,IAAMC,EACV,SAAO,CAIN,IAAKC,EAKL,YAAaC,EAAqB,SAAS,EAK3C,KAAMC,EAMN,QAASC,EAAc,SAAS,CAClC,CAAC,EACA,OAAO,EAYGC,EACV,SAAO,CAIN,OAAQC,EAAgB,GAAGC,CAAY,EAKvC,WAAYC,EAKZ,IAAKR,CACP,CAAC,EACA,OAAO,EDpDH,IAAMS,EAAeC,GAA8B,CACxDC,EAAwB,MAAMD,CAAM,EAEpC,GAAM,CAAC,OAAQE,EAAgB,WAAAC,EAAY,IAAAC,CAAG,EAAIJ,EAE5C,CAAC,IAAAK,EAAK,GAAGC,CAAM,EAAIF,EAEnBG,EACJL,aAA0BM,EAAYN,EAAe,aAAa,EAAIA,EAExE,yCAAyCK,EAAQJ,EAAYE,EAAKC,CAAM,CAC1E,EEzBA,OAAQ,gBAAAG,EAAc,eAAAC,MAAkB,iBAUjC,IAAMC,EAAoBC,GAC/B,KAAK,MAAM,4CAA4CA,CAAI,EAAGF,CAAW,EAS9DG,EAAoBD,GAC/B,8CAA8C,KAAK,UAAUA,EAAMH,CAAY,CAAC",
|
|
6
|
+
"names": ["Principal", "z", "SetDocSchema", "KeySchema", "DocDescriptionSchema", "RawDataSchema", "VersionSchema", "SetDocStoreParamsSchema", "RawUserIdSchema", "UserIdSchema", "CollectionSchema", "setDocStore", "params", "SetDocStoreParamsSchema", "providedCaller", "collection", "doc", "key", "setDoc", "caller", "Principal", "jsonReplacer", "jsonReviver", "decodeDocData", "data", "encodeDocData"]
|
|
7
7
|
}
|
package/chunk-OVO3T2DM.js
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import*as r from"zod";var i=r.custom(o=>o instanceof Uint8Array,{message:"Expected Uint8Array"});import*as e from"zod";var a=e.bigint(),c=e.bigint(),p=e.custom(o=>o instanceof Uint8Array,{message:"Expected Uint8Array"}),n=i,f=e.string(),h=e.string();import*as t from"zod";var m=t.string().max(1024),z=t.object({owner:n,data:p,description:m.optional(),created_at:a,updated_at:a,version:c.optional()}).strict();export{i as a,a as b,c,p as d,n as e,f,h as g,m as h,z as i};
|
|
2
|
-
//# sourceMappingURL=chunk-OVO3T2DM.js.map
|
package/chunk-OVO3T2DM.js.map
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["src/schemas/candid.ts", "src/schemas/core.ts", "src/schemas/db.ts"],
|
|
4
|
-
"sourcesContent": ["import * as z from 'zod';\n\n/**\n * @see RawPrincipal\n */\nexport const RawPrincipalSchema = z.custom<Uint8Array>((val) => val instanceof Uint8Array, {\n message: 'Expected Uint8Array'\n});\n\n/**\n * Represents a raw principal identifier.\n *\n * Principals are unique identities used in authentication and authorization.\n */\nexport type RawPrincipal = z.infer<typeof RawPrincipalSchema>;\n", "import * as z from 'zod';\nimport {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 RawData\n */\nexport const RawDataSchema = z.custom<Uint8Array>((val) => val instanceof Uint8Array, {\n message: 'Expected Uint8Array'\n});\n\n/**\n * Represents raw binary data.\n *\n * This is used to store unstructured data in a document.\n */\nexport type RawData = z.infer<typeof RawDataSchema>;\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 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 unique key identifier within a collection.\n */\nexport type Key = z.infer<typeof KeySchema>;\n", "import * as z from 'zod';\nimport {RawDataSchema, RawUserIdSchema, TimestampSchema, VersionSchema} from './core';\n\n/**\n * @see DocDescription\n */\nexport const DocDescriptionSchema = z.string().max(1024);\n\n/**\n * Represents a document description with a maximum length of 1024 characters.\n */\nexport type DocDescription = z.infer<typeof DocDescriptionSchema>;\n\n/**\n * @see Doc\n */\nexport const DocSchema = z\n .object({\n /**\n * The user who owns this document.\n */\n owner: RawUserIdSchema,\n\n /**\n * The raw data of the document.\n */\n data: RawDataSchema,\n\n /**\n * An optional description of the document.\n */\n description: DocDescriptionSchema.optional(),\n\n /**\n * The timestamp when the document was first created.\n */\n created_at: TimestampSchema,\n\n /**\n * The timestamp when the document was last updated.\n */\n updated_at: TimestampSchema,\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: VersionSchema.optional()\n })\n .strict();\n\n/**\n * Represents a document stored in a collection.\n */\nexport type Doc = z.infer<typeof DocSchema>;\n"],
|
|
5
|
-
"mappings": "AAAA,UAAYA,MAAO,MAKZ,IAAMC,EAAuB,SAAoBC,GAAQA,aAAe,WAAY,CACzF,QAAS,qBACX,CAAC,ECPD,UAAYC,MAAO,MAMZ,IAAMC,EAAoB,SAAO,EAY3BC,EAAkB,SAAO,EAYzBC,EAAkB,SAAoBC,GAAQA,aAAe,WAAY,CACpF,QAAS,qBACX,CAAC,EAYYC,EAAkBC,EAYlBC,EAAqB,SAAO,EAU5BC,EAAc,SAAO,EClElC,UAAYC,MAAO,MAMZ,IAAMC,EAAyB,SAAO,EAAE,IAAI,IAAI,EAU1CC,EACV,SAAO,CAIN,MAAOC,EAKP,KAAMC,EAKN,YAAaH,EAAqB,SAAS,EAK3C,WAAYI,EAKZ,WAAYA,EAMZ,QAASC,EAAc,SAAS,CAClC,CAAC,EACA,OAAO",
|
|
6
|
-
"names": ["z", "RawPrincipalSchema", "val", "z", "TimestampSchema", "VersionSchema", "RawDataSchema", "val", "RawUserIdSchema", "RawPrincipalSchema", "CollectionSchema", "KeySchema", "z", "DocDescriptionSchema", "DocSchema", "RawUserIdSchema", "RawDataSchema", "TimestampSchema", "VersionSchema"]
|
|
7
|
-
}
|