@junobuild/functions 0.0.8 → 0.0.9-next-2025-03-18

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -6,7 +6,7 @@
6
6
  [npm-license]: https://img.shields.io/npm/l/@junobuild/functions
7
7
  [npm-license-url]: https://github.com/junobuild/juno-js/blob/main/LICENSE
8
8
 
9
- # Juno Config
9
+ # Juno Functions
10
10
 
11
11
  JavaScript and TypeScript utilities for [Juno] Serverless Functions.
12
12
 
@@ -33,6 +33,7 @@ JavaScript and TypeScript utilities for [Juno] Serverless Functions.
33
33
  - [setDocStore](#gear-setdocstore)
34
34
  - [decodeDocData](#gear-decodedocdata)
35
35
  - [encodeDocData](#gear-encodedocdata)
36
+ - [call](#gear-call)
36
37
  - [id](#gear-id)
37
38
 
38
39
  #### :gear: HookContextSchema
@@ -208,6 +209,23 @@ Parameters:
208
209
 
209
210
  [:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/sdk/serializer.sdk.ts#L21)
210
211
 
212
+ #### :gear: call
213
+
214
+ Makes an asynchronous call to a canister on the Internet Computer.
215
+
216
+ This function encodes the provided arguments using Candid, performs the canister call,
217
+ and decodes the response based on the expected result types.
218
+
219
+ | Function | Type |
220
+ | -------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
221
+ | `call` | `<T>(params: { canisterId: Uint8Array<ArrayBufferLike> or Principal; method: string; args?: [Type<unknown>, unknown][] or undefined; result?: Type<unknown> or undefined; }) => Promise<...>` |
222
+
223
+ Parameters:
224
+
225
+ - `params`: - The parameters required for the canister call
226
+
227
+ [:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/ic-cdk/call.ic-cdk.ts#L20)
228
+
211
229
  #### :gear: id
212
230
 
213
231
  Retrieves the Satellite's Principal ID.
@@ -220,21 +238,22 @@ the Principal of the executing canister.
220
238
  | -------- | ----------------- |
221
239
  | `id` | `() => Principal` |
222
240
 
223
- [:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/ic-cdk/id.ts#L12)
241
+ [:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/ic-cdk/id.ic-cdk.ts#L12)
224
242
 
225
243
  ### :wrench: Constants
226
244
 
227
245
  - [CollectionsSchema](#gear-collectionsschema)
246
+ - [Uint8ArraySchema](#gear-uint8arrayschema)
228
247
  - [RawPrincipalSchema](#gear-rawprincipalschema)
229
248
  - [PrincipalSchema](#gear-principalschema)
230
249
  - [TimestampSchema](#gear-timestampschema)
231
250
  - [VersionSchema](#gear-versionschema)
232
- - [RawDataSchema](#gear-rawdataschema)
233
251
  - [RawUserIdSchema](#gear-rawuseridschema)
234
252
  - [UserIdSchema](#gear-useridschema)
235
253
  - [CollectionSchema](#gear-collectionschema)
236
254
  - [KeySchema](#gear-keyschema)
237
255
  - [DocDescriptionSchema](#gear-docdescriptionschema)
256
+ - [RawDataSchema](#gear-rawdataschema)
238
257
  - [DocSchema](#gear-docschema)
239
258
  - [DocUpsertSchema](#gear-docupsertschema)
240
259
  - [ProposedDocSchema](#gear-proposeddocschema)
@@ -248,22 +267,37 @@ the Principal of the executing canister.
248
267
  - [HookSchema](#gear-hookschema)
249
268
  - [SetDocSchema](#gear-setdocschema)
250
269
  - [SetDocStoreParamsSchema](#gear-setdocstoreparamsschema)
270
+ - [IDLTypeSchema](#gear-idltypeschema)
271
+ - [CallArgSchema](#gear-callargschema)
272
+ - [CallArgsSchema](#gear-callargsschema)
273
+ - [CallResultSchema](#gear-callresultschema)
274
+ - [CallParamsSchema](#gear-callparamsschema)
251
275
 
252
276
  #### :gear: CollectionsSchema
253
277
 
254
- | Constant | Type |
255
- | ------------------- | ---------------------------------------------------------------------------------------------------------------------------------------- |
256
- | `CollectionsSchema` | `ZodObject<{ collections: ZodArray<ZodString, "many">; }, "strict", ZodTypeAny, { collections: string[]; }, { collections: string[]; }>` |
278
+ | Constant | Type |
279
+ | ------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
280
+ | `CollectionsSchema` | `ZodObject<{ collections: ZodReadonly<ZodArray<ZodString, "many">>; }, "strict", ZodTypeAny, { collections: readonly string[]; }, { collections: readonly string[]; }>` |
257
281
 
258
282
  [:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/hooks/schemas/collections.ts#L6)
259
283
 
284
+ #### :gear: Uint8ArraySchema
285
+
286
+ A schema that validates a value is an Uint8Array.
287
+
288
+ | Constant | Type |
289
+ | ------------------ | ------------------------------------------------------------------------------- |
290
+ | `Uint8ArraySchema` | `ZodType<Uint8Array<ArrayBufferLike>, ZodTypeDef, Uint8Array<ArrayBufferLike>>` |
291
+
292
+ [:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/schemas/candid.ts#L7)
293
+
260
294
  #### :gear: RawPrincipalSchema
261
295
 
262
296
  | Constant | Type |
263
297
  | -------------------- | ------------------------------------------------------------------------------- |
264
298
  | `RawPrincipalSchema` | `ZodType<Uint8Array<ArrayBufferLike>, ZodTypeDef, Uint8Array<ArrayBufferLike>>` |
265
299
 
266
- [:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/schemas/candid.ts#L7)
300
+ [:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/schemas/candid.ts#L14)
267
301
 
268
302
  #### :gear: PrincipalSchema
269
303
 
@@ -271,7 +305,7 @@ the Principal of the executing canister.
271
305
  | ----------------- | ------------------------------------------- |
272
306
  | `PrincipalSchema` | `ZodType<Principal, ZodTypeDef, Principal>` |
273
307
 
274
- [:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/schemas/candid.ts#L19)
308
+ [:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/schemas/candid.ts#L24)
275
309
 
276
310
  #### :gear: TimestampSchema
277
311
 
@@ -279,7 +313,7 @@ the Principal of the executing canister.
279
313
  | ----------------- | ----------- |
280
314
  | `TimestampSchema` | `ZodBigInt` |
281
315
 
282
- [:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/schemas/core.ts#L7)
316
+ [:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/schemas/satellite.ts#L7)
283
317
 
284
318
  #### :gear: VersionSchema
285
319
 
@@ -287,15 +321,7 @@ the Principal of the executing canister.
287
321
  | --------------- | ----------- |
288
322
  | `VersionSchema` | `ZodBigInt` |
289
323
 
290
- [:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/schemas/core.ts#L19)
291
-
292
- #### :gear: RawDataSchema
293
-
294
- | Constant | Type |
295
- | --------------- | ------------------------------------------------------------------------------- |
296
- | `RawDataSchema` | `ZodType<Uint8Array<ArrayBufferLike>, ZodTypeDef, Uint8Array<ArrayBufferLike>>` |
297
-
298
- [:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/schemas/core.ts#L31)
324
+ [:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/schemas/satellite.ts#L19)
299
325
 
300
326
  #### :gear: RawUserIdSchema
301
327
 
@@ -303,7 +329,7 @@ the Principal of the executing canister.
303
329
  | ----------------- | ------------------------------------------------------------------------------- |
304
330
  | `RawUserIdSchema` | `ZodType<Uint8Array<ArrayBufferLike>, ZodTypeDef, Uint8Array<ArrayBufferLike>>` |
305
331
 
306
- [:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/schemas/core.ts#L45)
332
+ [:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/schemas/satellite.ts#L31)
307
333
 
308
334
  #### :gear: UserIdSchema
309
335
 
@@ -311,7 +337,7 @@ the Principal of the executing canister.
311
337
  | -------------- | ------------------------------------------- |
312
338
  | `UserIdSchema` | `ZodType<Principal, ZodTypeDef, Principal>` |
313
339
 
314
- [:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/schemas/core.ts#L57)
340
+ [:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/schemas/satellite.ts#L43)
315
341
 
316
342
  #### :gear: CollectionSchema
317
343
 
@@ -319,7 +345,7 @@ the Principal of the executing canister.
319
345
  | ------------------ | ----------- |
320
346
  | `CollectionSchema` | `ZodString` |
321
347
 
322
- [:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/schemas/core.ts#L69)
348
+ [:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/schemas/satellite.ts#L55)
323
349
 
324
350
  #### :gear: KeySchema
325
351
 
@@ -327,7 +353,7 @@ the Principal of the executing canister.
327
353
  | ----------- | ----------- |
328
354
  | `KeySchema` | `ZodString` |
329
355
 
330
- [:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/schemas/core.ts#L79)
356
+ [:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/schemas/satellite.ts#L65)
331
357
 
332
358
  #### :gear: DocDescriptionSchema
333
359
 
@@ -335,7 +361,15 @@ the Principal of the executing canister.
335
361
  | ---------------------- | ----------- |
336
362
  | `DocDescriptionSchema` | `ZodString` |
337
363
 
338
- [:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/schemas/db.ts#L7)
364
+ [:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/schemas/db.ts#L8)
365
+
366
+ #### :gear: RawDataSchema
367
+
368
+ | Constant | Type |
369
+ | --------------- | ------------------------------------------------------------------------------- |
370
+ | `RawDataSchema` | `ZodType<Uint8Array<ArrayBufferLike>, ZodTypeDef, Uint8Array<ArrayBufferLike>>` |
371
+
372
+ [:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/schemas/db.ts#L18)
339
373
 
340
374
  #### :gear: DocSchema
341
375
 
@@ -343,7 +377,7 @@ the Principal of the executing canister.
343
377
  | ----------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
344
378
  | `DocSchema` | `ZodObject<{ owner: ZodType<Uint8Array<ArrayBufferLike>, ZodTypeDef, Uint8Array<ArrayBufferLike>>; ... 4 more ...; version: ZodOptional<...>; }, "strict", ZodTypeAny, { ...; }, { ...; }>` |
345
379
 
346
- [:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/schemas/db.ts#L17)
380
+ [:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/schemas/db.ts#L30)
347
381
 
348
382
  #### :gear: DocUpsertSchema
349
383
 
@@ -397,7 +431,7 @@ the Principal of the executing canister.
397
431
 
398
432
  | Constant | Type |
399
433
  | -------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
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, { ...; }, {...` |
434
+ | `AssertSetDocSchema` | `ZodObject<extendShape<{ collections: ZodReadonly<ZodArray<ZodString, "many">>; }, { assert: ZodFunction<ZodTuple<[ZodObject<{ caller: ZodType<Uint8Array<ArrayBufferLike>, ZodTypeDef, Uint8Array<...>>; data: ZodObject<...>; }, "strict", ZodTypeAny, { ...; }, { ...; }>], ZodUnknown>, ZodVoid>; }>, "strict", ZodTypeAny...` |
401
435
 
402
436
  [:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/hooks/db/assertions.ts#L26)
403
437
 
@@ -405,7 +439,7 @@ the Principal of the executing canister.
405
439
 
406
440
  | Constant | Type |
407
441
  | -------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
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, { ...; }, {...` |
442
+ | `AssertSchema` | `ZodObject<extendShape<{ collections: ZodReadonly<ZodArray<ZodString, "many">>; }, { assert: ZodFunction<ZodTuple<[ZodObject<{ caller: ZodType<Uint8Array<ArrayBufferLike>, ZodTypeDef, Uint8Array<...>>; data: ZodObject<...>; }, "strict", ZodTypeAny, { ...; }, { ...; }>], ZodUnknown>, ZodVoid>; }>, "strict", ZodTypeAny...` |
409
443
 
410
444
  [:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/hooks/db/assertions.ts#L37)
411
445
 
@@ -413,7 +447,7 @@ the Principal of the executing canister.
413
447
 
414
448
  | Constant | Type |
415
449
  | ---------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
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, { ...;...` |
450
+ | `OnSetDocSchema` | `ZodObject<extendShape<{ collections: ZodReadonly<ZodArray<ZodString, "many">>; }, { run: ZodFunction<ZodTuple<[ZodObject<{ caller: ZodType<Uint8Array<ArrayBufferLike>, ZodTypeDef, Uint8Array<...>>; data: ZodObject<...>; }, "strict", ZodTypeAny, { ...; }, { ...; }>], ZodUnknown>, ZodPromise<...>>; }>, "strict", ZodTy...` |
417
451
 
418
452
  [:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/hooks/db/hooks.ts#L26)
419
453
 
@@ -421,7 +455,7 @@ the Principal of the executing canister.
421
455
 
422
456
  | Constant | Type |
423
457
  | ------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
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, { ...;...` |
458
+ | `HookSchema` | `ZodObject<extendShape<{ collections: ZodReadonly<ZodArray<ZodString, "many">>; }, { run: ZodFunction<ZodTuple<[ZodObject<{ caller: ZodType<Uint8Array<ArrayBufferLike>, ZodTypeDef, Uint8Array<...>>; data: ZodObject<...>; }, "strict", ZodTypeAny, { ...; }, { ...; }>], ZodUnknown>, ZodPromise<...>>; }>, "strict", ZodTy...` |
425
459
 
426
460
  [:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/hooks/db/hooks.ts#L37)
427
461
 
@@ -431,7 +465,7 @@ the Principal of the executing canister.
431
465
  | -------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
432
466
  | `SetDocSchema` | `ZodObject<{ key: ZodString; description: ZodOptional<ZodString>; data: ZodType<Uint8Array<ArrayBufferLike>, ZodTypeDef, Uint8Array<...>>; version: ZodOptional<...>; }, "strict", ZodTypeAny, { ...; }, { ...; }>` |
433
467
 
434
- [:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/sdk/schemas/db.ts#L15)
468
+ [:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/sdk/schemas/db.ts#L14)
435
469
 
436
470
  #### :gear: SetDocStoreParamsSchema
437
471
 
@@ -439,7 +473,53 @@ the Principal of the executing canister.
439
473
  | ------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
440
474
  | `SetDocStoreParamsSchema` | `ZodObject<{ caller: ZodUnion<[ZodType<Uint8Array<ArrayBufferLike>, ZodTypeDef, Uint8Array<ArrayBufferLike>>, ZodType<...>]>; collection: ZodString; doc: ZodObject<...>; }, "strict", ZodTypeAny, { ...; }, { ...; }>` |
441
475
 
442
- [:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/sdk/schemas/db.ts#L50)
476
+ [:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/sdk/schemas/db.ts#L49)
477
+
478
+ #### :gear: IDLTypeSchema
479
+
480
+ | Constant | Type |
481
+ | --------------- | --------------------------------------------------- |
482
+ | `IDLTypeSchema` | `ZodType<Type<unknown>, ZodTypeDef, Type<unknown>>` |
483
+
484
+ [:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/ic-cdk/schemas/call.ts#L8)
485
+
486
+ #### :gear: CallArgSchema
487
+
488
+ | Constant | Type |
489
+ | --------------- | --------------------------------------------------------------------------------- |
490
+ | `CallArgSchema` | `ZodTuple<[ZodType<Type<unknown>, ZodTypeDef, Type<unknown>>, ZodUnknown], null>` |
491
+
492
+ [:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/ic-cdk/schemas/call.ts#L20)
493
+
494
+ #### :gear: CallArgsSchema
495
+
496
+ Schema for encoding the call arguments.
497
+
498
+ | Constant | Type |
499
+ | ---------------- | --------------------------------------------------------------------------------------------------- |
500
+ | `CallArgsSchema` | `ZodArray<ZodTuple<[ZodType<Type<unknown>, ZodTypeDef, Type<unknown>>, ZodUnknown], null>, "many">` |
501
+
502
+ [:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/ic-cdk/schemas/call.ts#L32)
503
+
504
+ #### :gear: CallResultSchema
505
+
506
+ | Constant | Type |
507
+ | ------------------ | --------------------------------------------------- |
508
+ | `CallResultSchema` | `ZodType<Type<unknown>, ZodTypeDef, Type<unknown>>` |
509
+
510
+ [:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/ic-cdk/schemas/call.ts#L48)
511
+
512
+ #### :gear: CallParamsSchema
513
+
514
+ | Constant | Type |
515
+ | ------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
516
+ | `CallParamsSchema` | `ZodObject<{ canisterId: ZodUnion<[ZodType<Uint8Array<ArrayBufferLike>, ZodTypeDef, Uint8Array<ArrayBufferLike>>, ZodType<...>]>; method: ZodString; args: ZodOptional<...>; result: ZodOptional<...>; }, "strip", ZodTypeAny, { ...; }, { ...; }>` |
517
+
518
+ [:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/ic-cdk/schemas/call.ts#L58)
519
+
520
+ ### :factory: CallResponseLengthError
521
+
522
+ [:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/ic-cdk/types/errors.ts#L1)
443
523
 
444
524
  ### :cocktail: Types
445
525
 
@@ -448,7 +528,6 @@ the Principal of the executing canister.
448
528
  - [Principal](#gear-principal)
449
529
  - [Timestamp](#gear-timestamp)
450
530
  - [Version](#gear-version)
451
- - [RawData](#gear-rawdata)
452
531
  - [RawUserId](#gear-rawuserid)
453
532
  - [UserId](#gear-userid)
454
533
  - [Collection](#gear-collection)
@@ -457,6 +536,7 @@ the Principal of the executing canister.
457
536
  - [AssertFunction](#gear-assertfunction)
458
537
  - [RunFunction](#gear-runfunction)
459
538
  - [DocDescription](#gear-docdescription)
539
+ - [RawData](#gear-rawdata)
460
540
  - [Doc](#gear-doc)
461
541
  - [DocUpsert](#gear-docupsert)
462
542
  - [ProposedDoc](#gear-proposeddoc)
@@ -475,6 +555,11 @@ the Principal of the executing canister.
475
555
  - [HookFnOrObject](#gear-hookfnorobject)
476
556
  - [SetDoc](#gear-setdoc)
477
557
  - [SetDocStoreParams](#gear-setdocstoreparams)
558
+ - [IDLType](#gear-idltype)
559
+ - [CallArg](#gear-callarg)
560
+ - [CallArgs](#gear-callargs)
561
+ - [CallResult](#gear-callresult)
562
+ - [CallParams](#gear-callparams)
478
563
 
479
564
  #### :gear: Collections
480
565
 
@@ -494,7 +579,7 @@ Represents a raw principal - a Uint8Array representation of a Principal.
494
579
  | -------------- | ------------------------------------ |
495
580
  | `RawPrincipal` | `z.infer<typeof RawPrincipalSchema>` |
496
581
 
497
- [:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/schemas/candid.ts#L14)
582
+ [:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/schemas/candid.ts#L19)
498
583
 
499
584
  #### :gear: Principal
500
585
 
@@ -504,7 +589,7 @@ Represents a principal - i.e. an object instantiated with the class Principal.
504
589
  | ----------- | --------------------------------- |
505
590
  | `Principal` | `z.infer<typeof PrincipalSchema>` |
506
591
 
507
- [:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/schemas/candid.ts#L26)
592
+ [:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/schemas/candid.ts#L31)
508
593
 
509
594
  #### :gear: Timestamp
510
595
 
@@ -516,7 +601,7 @@ Used for tracking when events occur, such as document creation and updates.
516
601
  | ----------- | --------------------------------- |
517
602
  | `Timestamp` | `z.infer<typeof TimestampSchema>` |
518
603
 
519
- [:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/schemas/core.ts#L14)
604
+ [:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/schemas/satellite.ts#L14)
520
605
 
521
606
  #### :gear: Version
522
607
 
@@ -528,19 +613,7 @@ This is typically incremented with each update to ensure consistency.
528
613
  | --------- | ------------------------------- |
529
614
  | `Version` | `z.infer<typeof VersionSchema>` |
530
615
 
531
- [:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/schemas/core.ts#L26)
532
-
533
- #### :gear: RawData
534
-
535
- Represents raw binary data.
536
-
537
- This is used to store unstructured data in a document.
538
-
539
- | Type | Type |
540
- | --------- | ------------------------------- |
541
- | `RawData` | `z.infer<typeof RawDataSchema>` |
542
-
543
- [:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/schemas/core.ts#L40)
616
+ [:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/schemas/satellite.ts#L26)
544
617
 
545
618
  #### :gear: RawUserId
546
619
 
@@ -552,7 +625,7 @@ This is a principal associated with a user.
552
625
  | ----------- | --------------------------------- |
553
626
  | `RawUserId` | `z.infer<typeof RawUserIdSchema>` |
554
627
 
555
- [:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/schemas/core.ts#L52)
628
+ [:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/schemas/satellite.ts#L38)
556
629
 
557
630
  #### :gear: UserId
558
631
 
@@ -564,7 +637,7 @@ This is a principal associated with a user.
564
637
  | -------- | ------------------------------ |
565
638
  | `UserId` | `z.infer<typeof UserIdSchema>` |
566
639
 
567
- [:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/schemas/core.ts#L64)
640
+ [:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/schemas/satellite.ts#L50)
568
641
 
569
642
  #### :gear: Collection
570
643
 
@@ -574,7 +647,7 @@ A collection name where data are stored.
574
647
  | ------------ | ---------------------------------- |
575
648
  | `Collection` | `z.infer<typeof CollectionSchema>` |
576
649
 
577
- [:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/schemas/core.ts#L74)
650
+ [:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/schemas/satellite.ts#L60)
578
651
 
579
652
  #### :gear: Key
580
653
 
@@ -584,7 +657,7 @@ A unique key identifier within a collection.
584
657
  | ----- | --------------------------- |
585
658
  | `Key` | `z.infer<typeof KeySchema>` |
586
659
 
587
- [:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/schemas/core.ts#L84)
660
+ [:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/schemas/satellite.ts#L70)
588
661
 
589
662
  #### :gear: HookContext
590
663
 
@@ -628,7 +701,19 @@ Represents a document description with a maximum length of 1024 characters.
628
701
  | ---------------- | -------------------------------------- |
629
702
  | `DocDescription` | `z.infer<typeof DocDescriptionSchema>` |
630
703
 
631
- [:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/schemas/db.ts#L12)
704
+ [:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/schemas/db.ts#L13)
705
+
706
+ #### :gear: RawData
707
+
708
+ Represents raw binary data.
709
+
710
+ This is used to store structured data in a document.
711
+
712
+ | Type | Type |
713
+ | --------- | ---------------------------------- |
714
+ | `RawData` | `z.infer<typeof Uint8ArraySchema>` |
715
+
716
+ [:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/schemas/db.ts#L25)
632
717
 
633
718
  #### :gear: Doc
634
719
 
@@ -638,7 +723,7 @@ Represents a document stored in a collection.
638
723
  | ----- | --------------------------- |
639
724
  | `Doc` | `z.infer<typeof DocSchema>` |
640
725
 
641
- [:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/schemas/db.ts#L55)
726
+ [:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/schemas/db.ts#L68)
642
727
 
643
728
  #### :gear: DocUpsert
644
729
 
@@ -809,7 +894,7 @@ This is used when submitting new document data.
809
894
  | -------- | ------------------------------ |
810
895
  | `SetDoc` | `z.infer<typeof SetDocSchema>` |
811
896
 
812
- [:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/sdk/schemas/db.ts#L45)
897
+ [:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/sdk/schemas/db.ts#L44)
813
898
 
814
899
  #### :gear: SetDocStoreParams
815
900
 
@@ -822,7 +907,63 @@ collection, and key.
822
907
  | ------------------- | ----------------------------------------- |
823
908
  | `SetDocStoreParams` | `z.infer<typeof SetDocStoreParamsSchema>` |
824
909
 
825
- [:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/sdk/schemas/db.ts#L75)
910
+ [:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/sdk/schemas/db.ts#L74)
911
+
912
+ #### :gear: IDLType
913
+
914
+ Custom validation function to verify if a value is an instance of `IDL.Type` from `@dfinity/candid`.
915
+
916
+ | Type | Type |
917
+ | --------- | ------------------------------- |
918
+ | `IDLType` | `z.infer<typeof IDLTypeSchema>` |
919
+
920
+ [:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/ic-cdk/schemas/call.ts#L15)
921
+
922
+ #### :gear: CallArg
923
+
924
+ A call argument consisting of its IDL type and corresponding value.
925
+
926
+ | Type | Type |
927
+ | --------- | ------------------------------- |
928
+ | `CallArg` | `z.infer<typeof CallArgSchema>` |
929
+
930
+ [:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/ic-cdk/schemas/call.ts#L25)
931
+
932
+ #### :gear: CallArgs
933
+
934
+ Represents the arguments for a canister call on the IC.
935
+
936
+ Requests and responses on the IC are encoded using Candid.
937
+ This schema ensures that each argument is provided with both its type and value
938
+ for proper encoding.
939
+
940
+ The order of arguments is preserved for the function call.
941
+
942
+ | Type | Type |
943
+ | ---------- | -------------------------------- |
944
+ | `CallArgs` | `z.infer<typeof CallArgsSchema>` |
945
+
946
+ [:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/ic-cdk/schemas/call.ts#L43)
947
+
948
+ #### :gear: CallResult
949
+
950
+ Defines the type used to decode the result of a canister call.
951
+
952
+ | Type | Type |
953
+ | ------------ | ---------------------------------- |
954
+ | `CallResult` | `z.infer<typeof CallResultSchema>` |
955
+
956
+ [:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/ic-cdk/schemas/call.ts#L53)
957
+
958
+ #### :gear: CallParams
959
+
960
+ Type representing the parameters required to make a canister call.
961
+
962
+ | Type | Type |
963
+ | ------------ | ---------------------------------- |
964
+ | `CallParams` | `z.infer<typeof CallParamsSchema>` |
965
+
966
+ [:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/ic-cdk/schemas/call.ts#L83)
826
967
 
827
968
  <!-- TSDOC_END -->
828
969
 
@@ -0,0 +1,2 @@
1
+ import{Principal as r}from"@dfinity/principal";import*as i from"zod";var n=i.custom(a=>a instanceof Uint8Array,{message:"Expected Uint8Array"}),c=n,t=i.custom(a=>a instanceof r,{message:"Expected an instance of a Principal"});export{n as a,c as b,t as c};
2
+ //# sourceMappingURL=chunk-CCKUQNB5.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["src/schemas/candid.ts"],
4
+ "sourcesContent": ["import {Principal as CandidPrincipal} from '@dfinity/principal';\nimport * as z from 'zod';\n\n/**\n * A schema that validates a value is an Uint8Array.\n */\nexport const Uint8ArraySchema = z.custom<Uint8Array>((val) => val instanceof Uint8Array, {\n message: 'Expected Uint8Array'\n});\n\n/**\n * @see RawPrincipal\n */\nexport const RawPrincipalSchema = Uint8ArraySchema;\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"],
5
+ "mappings": "AAAA,OAAQ,aAAaA,MAAsB,qBAC3C,UAAYC,MAAO,MAKZ,IAAMC,EAAqB,SAAoBC,GAAQA,aAAe,WAAY,CACvF,QAAS,qBACX,CAAC,EAKYC,EAAqBF,EAUrBG,EAAoB,SAAyBF,GAAQA,aAAeH,EAAiB,CAChG,QAAS,qCACX,CAAC",
6
+ "names": ["CandidPrincipal", "z", "Uint8ArraySchema", "val", "RawPrincipalSchema", "PrincipalSchema"]
7
+ }
@@ -0,0 +1,2 @@
1
+ import{a as r,b as a,c as p}from"./chunk-CCKUQNB5.js";import*as e from"zod";var o=e.bigint(),c=e.bigint(),i=a,h=p,S=e.string(),f=e.string();import*as t from"zod";var m=t.string().max(1024),n=r,d=t.object({owner:i,data:n,description:m.optional(),created_at:o,updated_at:o,version:c.optional()}).strict();export{o as a,c as b,i as c,h as d,S as e,f,m as g,n as h,d as i};
2
+ //# sourceMappingURL=chunk-LVVTFR6B.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["src/schemas/satellite.ts", "src/schemas/db.ts"],
4
+ "sourcesContent": ["import * as z from 'zod';\nimport {PrincipalSchema, RawPrincipalSchema} from './candid';\n\n/**\n * @see Timestamp\n */\nexport const TimestampSchema = z.bigint();\n\n/**\n * Represents a timestamp in nanoseconds since the Unix epoch.\n *\n * Used for tracking when events occur, such as document creation and updates.\n */\nexport type Timestamp = z.infer<typeof TimestampSchema>;\n\n/**\n * @see Version\n */\nexport const VersionSchema = z.bigint();\n\n/**\n * Represents a version number for tracking changes.\n *\n * This is typically incremented with each update to ensure consistency.\n */\nexport type Version = z.infer<typeof VersionSchema>;\n\n/**\n * @see RawUserId\n */\nexport const RawUserIdSchema = RawPrincipalSchema;\n\n/**\n * Represents a raw user identifier.\n *\n * This is a principal associated with a user.\n */\nexport type RawUserId = z.infer<typeof RawUserIdSchema>;\n\n/**\n * @see UserId\n */\nexport const UserIdSchema = PrincipalSchema;\n\n/**\n * Represents a user identifier.\n *\n * This is a principal associated with a user.\n */\nexport type UserId = z.infer<typeof UserIdSchema>;\n\n/**\n * @see Collection\n */\nexport const CollectionSchema = z.string();\n\n/**\n * A collection name where data are stored.\n */\nexport type Collection = z.infer<typeof CollectionSchema>;\n\n/**\n * @see Key\n */\nexport const KeySchema = z.string();\n\n/**\n * A unique key identifier within a collection.\n */\nexport type Key = z.infer<typeof KeySchema>;\n", "import * as z from 'zod';\nimport {Uint8ArraySchema} from './candid';\nimport {RawUserIdSchema, TimestampSchema, VersionSchema} from './satellite';\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 RawData\n */\nexport const RawDataSchema = Uint8ArraySchema;\n\n/**\n * Represents raw binary data.\n *\n * This is used to store structured data in a document.\n */\nexport type RawData = z.infer<typeof Uint8ArraySchema>;\n\n/**\n * @see Doc\n */\nexport const DocSchema = z\n .object({\n /**\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": "sDAAA,UAAYA,MAAO,MAMZ,IAAMC,EAAoB,SAAO,EAY3BC,EAAkB,SAAO,EAYzBC,EAAkBC,EAYlBC,EAAeC,EAYfC,EAAqB,SAAO,EAU5BC,EAAc,SAAO,EChElC,UAAYC,MAAO,MAOZ,IAAMC,EAAyB,SAAO,EAAE,IAAI,IAAI,EAU1CC,EAAgBC,EAYhBC,EACV,SAAO,CAIN,MAAOC,EAKP,KAAMH,EAKN,YAAaD,EAAqB,SAAS,EAK3C,WAAYK,EAKZ,WAAYA,EAMZ,QAASC,EAAc,SAAS,CAClC,CAAC,EACA,OAAO",
6
+ "names": ["z", "TimestampSchema", "VersionSchema", "RawUserIdSchema", "RawPrincipalSchema", "UserIdSchema", "PrincipalSchema", "CollectionSchema", "KeySchema", "z", "DocDescriptionSchema", "RawDataSchema", "Uint8ArraySchema", "DocSchema", "RawUserIdSchema", "TimestampSchema", "VersionSchema"]
7
+ }
package/global.d.ts CHANGED
@@ -1,4 +1,5 @@
1
- import type {RawData, RawPrincipal, RawUserId} from './schemas/core';
1
+ import {RawData} from './schemas/db';
2
+ import type {RawPrincipal, RawUserId} from './schemas/satellite';
2
3
  import type {SetDoc} from './sdk/schemas/db';
3
4
 
4
5
  declare global {
@@ -14,4 +15,9 @@ declare global {
14
15
 
15
16
  function __ic_cdk_id(): RawPrincipal;
16
17
  function __ic_cdk_print(msg: string): void;
18
+ function __ic_cdk_call_raw(
19
+ canisterId: RawPrincipal,
20
+ method: string,
21
+ args: Uint8Array<ArrayBuffer>
22
+ ): Promise<Uint8Array<ArrayBuffer>>;
17
23
  }
@@ -4,7 +4,7 @@ import { SatelliteEnvSchema } from '../schemas/satellite.env';
4
4
  * @see AssertSetDoc
5
5
  */
6
6
  export declare const AssertSetDocSchema: z.ZodObject<z.objectUtil.extendShape<{
7
- collections: z.ZodArray<z.ZodString, "many">;
7
+ collections: z.ZodReadonly<z.ZodArray<z.ZodString, "many">>;
8
8
  }, {
9
9
  /**
10
10
  * A function that runs when the assertion is triggered for the specified collections.
@@ -163,7 +163,7 @@ export declare const AssertSetDocSchema: z.ZodObject<z.objectUtil.extendShape<{
163
163
  caller: Uint8Array<ArrayBufferLike>;
164
164
  }>], z.ZodUnknown>, z.ZodVoid>;
165
165
  }>, "strict", z.ZodTypeAny, {
166
- collections: string[];
166
+ collections: readonly string[];
167
167
  assert: (args_0: {
168
168
  data: {
169
169
  data: {
@@ -187,7 +187,7 @@ export declare const AssertSetDocSchema: z.ZodObject<z.objectUtil.extendShape<{
187
187
  caller: Uint8Array<ArrayBufferLike>;
188
188
  }, ...args: unknown[]) => void;
189
189
  }, {
190
- collections: string[];
190
+ collections: readonly string[];
191
191
  assert: (args_0: {
192
192
  data: {
193
193
  data: {
@@ -219,7 +219,7 @@ export type AssertSetDoc = z.infer<typeof AssertSetDocSchema>;
219
219
  * @see Assert
220
220
  */
221
221
  export declare const AssertSchema: z.ZodObject<z.objectUtil.extendShape<{
222
- collections: z.ZodArray<z.ZodString, "many">;
222
+ collections: z.ZodReadonly<z.ZodArray<z.ZodString, "many">>;
223
223
  }, {
224
224
  /**
225
225
  * A function that runs when the assertion is triggered for the specified collections.
@@ -378,7 +378,7 @@ export declare const AssertSchema: z.ZodObject<z.objectUtil.extendShape<{
378
378
  caller: Uint8Array<ArrayBufferLike>;
379
379
  }>], z.ZodUnknown>, z.ZodVoid>;
380
380
  }>, "strict", z.ZodTypeAny, {
381
- collections: string[];
381
+ collections: readonly string[];
382
382
  assert: (args_0: {
383
383
  data: {
384
384
  data: {
@@ -402,7 +402,7 @@ export declare const AssertSchema: z.ZodObject<z.objectUtil.extendShape<{
402
402
  caller: Uint8Array<ArrayBufferLike>;
403
403
  }, ...args: unknown[]) => void;
404
404
  }, {
405
- collections: string[];
405
+ collections: readonly string[];
406
406
  assert: (args_0: {
407
407
  data: {
408
408
  data: {
@@ -4,7 +4,7 @@ import { SatelliteEnvSchema } from '../schemas/satellite.env';
4
4
  * @see OnSetDoc
5
5
  */
6
6
  export declare const OnSetDocSchema: z.ZodObject<z.objectUtil.extendShape<{
7
- collections: z.ZodArray<z.ZodString, "many">;
7
+ collections: z.ZodReadonly<z.ZodArray<z.ZodString, "many">>;
8
8
  }, {
9
9
  /**
10
10
  * A function that runs when the hook is triggered for the specified collections.
@@ -190,7 +190,7 @@ export declare const OnSetDocSchema: z.ZodObject<z.objectUtil.extendShape<{
190
190
  caller: Uint8Array<ArrayBufferLike>;
191
191
  }>], z.ZodUnknown>, z.ZodPromise<z.ZodVoid>>;
192
192
  }>, "strict", z.ZodTypeAny, {
193
- collections: string[];
193
+ collections: readonly string[];
194
194
  run: (args_0: {
195
195
  data: {
196
196
  data: {
@@ -217,7 +217,7 @@ export declare const OnSetDocSchema: z.ZodObject<z.objectUtil.extendShape<{
217
217
  caller: Uint8Array<ArrayBufferLike>;
218
218
  }, ...args: unknown[]) => Promise<void>;
219
219
  }, {
220
- collections: string[];
220
+ collections: readonly string[];
221
221
  run: (args_0: {
222
222
  data: {
223
223
  data: {
@@ -252,7 +252,7 @@ export type OnSetDoc = z.infer<typeof OnSetDocSchema>;
252
252
  * @see Hook
253
253
  */
254
254
  export declare const HookSchema: z.ZodObject<z.objectUtil.extendShape<{
255
- collections: z.ZodArray<z.ZodString, "many">;
255
+ collections: z.ZodReadonly<z.ZodArray<z.ZodString, "many">>;
256
256
  }, {
257
257
  /**
258
258
  * A function that runs when the hook is triggered for the specified collections.
@@ -438,7 +438,7 @@ export declare const HookSchema: z.ZodObject<z.objectUtil.extendShape<{
438
438
  caller: Uint8Array<ArrayBufferLike>;
439
439
  }>], z.ZodUnknown>, z.ZodPromise<z.ZodVoid>>;
440
440
  }>, "strict", z.ZodTypeAny, {
441
- collections: string[];
441
+ collections: readonly string[];
442
442
  run: (args_0: {
443
443
  data: {
444
444
  data: {
@@ -465,7 +465,7 @@ export declare const HookSchema: z.ZodObject<z.objectUtil.extendShape<{
465
465
  caller: Uint8Array<ArrayBufferLike>;
466
466
  }, ...args: unknown[]) => Promise<void>;
467
467
  }, {
468
- collections: string[];
468
+ collections: readonly string[];
469
469
  run: (args_0: {
470
470
  data: {
471
471
  data: {
@@ -6,11 +6,11 @@ export declare const CollectionsSchema: z.ZodObject<{
6
6
  /**
7
7
  * An array containing at least one collection name where the hook or assertion will be executed.
8
8
  */
9
- collections: z.ZodArray<z.ZodString, "many">;
9
+ collections: z.ZodReadonly<z.ZodArray<z.ZodString, "many">>;
10
10
  }, "strict", z.ZodTypeAny, {
11
- collections: string[];
11
+ collections: readonly string[];
12
12
  }, {
13
- collections: string[];
13
+ collections: readonly string[];
14
14
  }>;
15
15
  /**
16
16
  * Defines the collections where a hook or assertion should run.
@@ -0,0 +1,15 @@
1
+ import { CallParams } from './schemas/call';
2
+ /**
3
+ * Makes an asynchronous call to a canister on the Internet Computer.
4
+ *
5
+ * This function encodes the provided arguments using Candid, performs the canister call,
6
+ * and decodes the response based on the expected result types.
7
+ *
8
+ * @template T - The expected return type of the canister call.
9
+ * @param {CallParams} params - The parameters required for the canister call
10
+ * @returns {Promise<T | undefined>} A promise resolving to the decoded result of the call.
11
+ * Returns `undefined` if the canister response is empty.
12
+ * @throws {ZodError} If the provided parameters do not match the expected schema.
13
+ * @throws {Error} If the canister call fails.
14
+ */
15
+ export declare const call: <T>(params: CallParams) => Promise<T>;
@@ -0,0 +1,77 @@
1
+ import { IDL } from '@dfinity/candid';
2
+ import * as z from 'zod';
3
+ /**
4
+ * @see IDLType
5
+ */
6
+ export declare const IDLTypeSchema: z.ZodType<IDL.Type<unknown>, z.ZodTypeDef, IDL.Type<unknown>>;
7
+ /**
8
+ * Custom validation function to verify if a value is an instance of `IDL.Type` from `@dfinity/candid`.
9
+ */
10
+ export type IDLType = z.infer<typeof IDLTypeSchema>;
11
+ /**
12
+ * @see CallArg
13
+ */
14
+ export declare const CallArgSchema: z.ZodTuple<[z.ZodType<IDL.Type<unknown>, z.ZodTypeDef, IDL.Type<unknown>>, z.ZodUnknown], null>;
15
+ /**
16
+ * A call argument consisting of its IDL type and corresponding value.
17
+ */
18
+ export type CallArg = z.infer<typeof CallArgSchema>;
19
+ /**
20
+ * Schema for encoding the call arguments.
21
+ *
22
+ * @see CallArgs
23
+ */
24
+ export declare const CallArgsSchema: z.ZodArray<z.ZodTuple<[z.ZodType<IDL.Type<unknown>, z.ZodTypeDef, IDL.Type<unknown>>, z.ZodUnknown], null>, "many">;
25
+ /**
26
+ * Represents the arguments for a canister call on the IC.
27
+ *
28
+ * Requests and responses on the IC are encoded using Candid.
29
+ * This schema ensures that each argument is provided with both its type and value
30
+ * for proper encoding.
31
+ *
32
+ * The order of arguments is preserved for the function call.
33
+ */
34
+ export type CallArgs = z.infer<typeof CallArgsSchema>;
35
+ /**
36
+ * @see CallResult
37
+ */
38
+ export declare const CallResultSchema: z.ZodType<IDL.Type<unknown>, z.ZodTypeDef, IDL.Type<unknown>>;
39
+ /**
40
+ * Defines the type used to decode the result of a canister call.
41
+ */
42
+ export type CallResult = z.infer<typeof CallResultSchema>;
43
+ /**
44
+ * @see CallParams
45
+ */
46
+ export declare const CallParamsSchema: z.ZodObject<{
47
+ /**
48
+ * The target canister's ID.
49
+ */
50
+ canisterId: z.ZodUnion<[z.ZodType<Uint8Array<ArrayBufferLike>, z.ZodTypeDef, Uint8Array<ArrayBufferLike>>, z.ZodType<import("@dfinity/principal").Principal, z.ZodTypeDef, import("@dfinity/principal").Principal>]>;
51
+ /**
52
+ * The name of the method to call.
53
+ */
54
+ method: z.ZodString;
55
+ /**
56
+ * The arguments, including types and values, for the canister call.
57
+ */
58
+ args: z.ZodOptional<z.ZodArray<z.ZodTuple<[z.ZodType<IDL.Type<unknown>, z.ZodTypeDef, IDL.Type<unknown>>, z.ZodUnknown], null>, "many">>;
59
+ /**
60
+ * The expected result type used for decoding the response.
61
+ */
62
+ result: z.ZodOptional<z.ZodType<IDL.Type<unknown>, z.ZodTypeDef, IDL.Type<unknown>>>;
63
+ }, "strip", z.ZodTypeAny, {
64
+ canisterId: Uint8Array<ArrayBufferLike> | import("@dfinity/principal").Principal;
65
+ method: string;
66
+ args?: [IDL.Type<unknown>, unknown][] | undefined;
67
+ result?: IDL.Type<unknown> | undefined;
68
+ }, {
69
+ canisterId: Uint8Array<ArrayBufferLike> | import("@dfinity/principal").Principal;
70
+ method: string;
71
+ args?: [IDL.Type<unknown>, unknown][] | undefined;
72
+ result?: IDL.Type<unknown> | undefined;
73
+ }>;
74
+ /**
75
+ * Type representing the parameters required to make a canister call.
76
+ */
77
+ export type CallParams = z.infer<typeof CallParamsSchema>;
@@ -0,0 +1,3 @@
1
+ export declare class CallResponseLengthError extends Error {
2
+ constructor();
3
+ }
package/ic-cdk.d.ts CHANGED
@@ -1 +1,4 @@
1
- export * from './ic-cdk/id';
1
+ export * from './ic-cdk/call.ic-cdk';
2
+ export * from './ic-cdk/id.ic-cdk';
3
+ export * from './ic-cdk/schemas/call';
4
+ export * from './ic-cdk/types/errors';
package/ic-cdk.js CHANGED
@@ -1,2 +1,2 @@
1
- import{Principal as r}from"@dfinity/principal";var c=()=>r.fromUint8Array(__ic_cdk_id());export{c as id};
1
+ import{b as n,c as s}from"./chunk-CCKUQNB5.js";import{IDL as c}from"@dfinity/candid";import{Principal as D}from"@dfinity/principal";import{toNullable as L}from"@dfinity/utils";import{IDL as z}from"@dfinity/candid";import*as r from"zod";var p=r.custom(e=>e instanceof z.Type,{message:"Invalid IDL.Type"}),A=r.tuple([p,r.unknown()]),P=r.array(A),w=p,l=r.object({canisterId:n.or(s),method:r.string().min(1),args:P.optional(),result:w.optional()});var t=class extends Error{constructor(){super(),this.message="More than one object returned by the response. This is unexpected."}};var q=async e=>{l.parse(e);let{canisterId:o,method:i,args:m,result:f}=e,y=o instanceof D?o.toUint8Array():o,[u,d]=(m??[]).reduce(([C,I],[T,S])=>[[...C,T],[...I,S]],[[],[]]),h=new Uint8Array(c.encode([...u],[...d])),x=await __ic_cdk_call_raw(y,i,h),a=c.decode(L(f),x.buffer);if(a.length>1)throw new t;let[g]=a;return g};import{Principal as _}from"@dfinity/principal";var H=()=>_.fromUint8Array(__ic_cdk_id());export{A as CallArgSchema,P as CallArgsSchema,l as CallParamsSchema,t as CallResponseLengthError,w as CallResultSchema,p as IDLTypeSchema,q as call,H as id};
2
2
  //# sourceMappingURL=ic-cdk.js.map
package/ic-cdk.js.map CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
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"]
3
+ "sources": ["src/ic-cdk/call.ic-cdk.ts", "src/ic-cdk/schemas/call.ts", "src/ic-cdk/types/errors.ts", "src/ic-cdk/id.ic-cdk.ts"],
4
+ "sourcesContent": ["import {IDL} from '@dfinity/candid';\nimport {Principal} from '@dfinity/principal';\nimport {toNullable} from '@dfinity/utils';\nimport {CallParams, CallParamsSchema, IDLType} from './schemas/call';\nimport {CallResponseLengthError} from './types/errors';\n\n/**\n * Makes an asynchronous call to a canister on the Internet Computer.\n *\n * This function encodes the provided arguments using Candid, performs the canister call,\n * and decodes the response based on the expected result types.\n *\n * @template T - The expected return type of the canister call.\n * @param {CallParams} params - The parameters required for the canister call\n * @returns {Promise<T | undefined>} A promise resolving to the decoded result of the call.\n * Returns `undefined` if the canister response is empty.\n * @throws {ZodError} If the provided parameters do not match the expected schema.\n * @throws {Error} If the canister call fails.\n */\nexport const call = async <T>(params: CallParams): Promise<T> => {\n CallParamsSchema.parse(params);\n\n const {canisterId: providedCanisterId, method, args: providedArgs, result: resultType} = params;\n\n const canisterId =\n providedCanisterId instanceof Principal\n ? providedCanisterId.toUint8Array()\n : providedCanisterId;\n\n const [argsTypes, argsValues] = (providedArgs ?? []).reduce<[IDLType[], unknown[]]>(\n ([argsTypes, argsValues], [type, value]) => [\n [...argsTypes, type],\n [...argsValues, value]\n ],\n [[], []]\n );\n\n const args = new Uint8Array(IDL.encode([...argsTypes], [...argsValues]));\n\n const bytes: Uint8Array<ArrayBuffer> = await __ic_cdk_call_raw(canisterId, method, args);\n\n const result = IDL.decode(toNullable(resultType), bytes.buffer);\n\n // We have no test covering this use case because decode seems to never return more than one element, as we never specify more than one return type.\n if (result.length > 1) {\n throw new CallResponseLengthError();\n }\n\n const [response] = result as unknown as [T];\n return response;\n};\n", "import {IDL} from '@dfinity/candid';\nimport * as z from 'zod';\nimport {PrincipalSchema, RawPrincipalSchema} from '../../schemas/candid';\n\n/**\n * @see IDLType\n */\nexport const IDLTypeSchema = z.custom<IDL.Type<unknown>>((val) => val instanceof IDL.Type, {\n message: 'Invalid IDL.Type'\n});\n\n/**\n * Custom validation function to verify if a value is an instance of `IDL.Type` from `@dfinity/candid`.\n */\nexport type IDLType = z.infer<typeof IDLTypeSchema>;\n\n/**\n * @see CallArg\n */\nexport const CallArgSchema = z.tuple([IDLTypeSchema, z.unknown()]);\n\n/**\n * A call argument consisting of its IDL type and corresponding value.\n */\nexport type CallArg = z.infer<typeof CallArgSchema>;\n\n/**\n * Schema for encoding the call arguments.\n *\n * @see CallArgs\n */\nexport const CallArgsSchema = z.array(CallArgSchema);\n\n/**\n * Represents the arguments for a canister call on the IC.\n *\n * Requests and responses on the IC are encoded using Candid.\n * This schema ensures that each argument is provided with both its type and value\n * for proper encoding.\n *\n * The order of arguments is preserved for the function call.\n */\nexport type CallArgs = z.infer<typeof CallArgsSchema>;\n\n/**\n * @see CallResult\n */\nexport const CallResultSchema = IDLTypeSchema;\n\n/**\n * Defines the type used to decode the result of a canister call.\n */\nexport type CallResult = z.infer<typeof CallResultSchema>;\n\n/**\n * @see CallParams\n */\nexport const CallParamsSchema = z.object({\n /**\n * The target canister's ID.\n */\n canisterId: RawPrincipalSchema.or(PrincipalSchema),\n\n /**\n * The name of the method to call.\n */\n method: z.string().min(1),\n\n /**\n * The arguments, including types and values, for the canister call.\n */\n args: CallArgsSchema.optional(),\n\n /**\n * The expected result type used for decoding the response.\n */\n result: CallResultSchema.optional()\n});\n\n/**\n * Type representing the parameters required to make a canister call.\n */\nexport type CallParams = z.infer<typeof CallParamsSchema>;\n", "export class CallResponseLengthError extends Error {\n constructor() {\n super();\n\n this.message = 'More than one object returned by the response. This is unexpected.';\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": "+CAAA,OAAQ,OAAAA,MAAU,kBAClB,OAAQ,aAAAC,MAAgB,qBACxB,OAAQ,cAAAC,MAAiB,iBCFzB,OAAQ,OAAAC,MAAU,kBAClB,UAAYC,MAAO,MAMZ,IAAMC,EAAkB,SAA2BC,GAAQA,aAAeC,EAAI,KAAM,CACzF,QAAS,kBACX,CAAC,EAUYC,EAAkB,QAAM,CAACH,EAAiB,UAAQ,CAAC,CAAC,EAYpDI,EAAmB,QAAMD,CAAa,EAgBtCE,EAAmBL,EAUnBM,EAAqB,SAAO,CAIvC,WAAYC,EAAmB,GAAGC,CAAe,EAKjD,OAAU,SAAO,EAAE,IAAI,CAAC,EAKxB,KAAMJ,EAAe,SAAS,EAK9B,OAAQC,EAAiB,SAAS,CACpC,CAAC,EC7EM,IAAMI,EAAN,cAAsC,KAAM,CACjD,aAAc,CACZ,MAAM,EAEN,KAAK,QAAU,oEACjB,CACF,EFaO,IAAMC,EAAO,MAAUC,GAAmC,CAC/DC,EAAiB,MAAMD,CAAM,EAE7B,GAAM,CAAC,WAAYE,EAAoB,OAAAC,EAAQ,KAAMC,EAAc,OAAQC,CAAU,EAAIL,EAEnFM,EACJJ,aAA8BK,EAC1BL,EAAmB,aAAa,EAChCA,EAEA,CAACM,EAAWC,CAAU,GAAKL,GAAgB,CAAC,GAAG,OACnD,CAAC,CAACI,EAAWC,CAAU,EAAG,CAACC,EAAMC,CAAK,IAAM,CAC1C,CAAC,GAAGH,EAAWE,CAAI,EACnB,CAAC,GAAGD,EAAYE,CAAK,CACvB,EACA,CAAC,CAAC,EAAG,CAAC,CAAC,CACT,EAEMC,EAAO,IAAI,WAAWC,EAAI,OAAO,CAAC,GAAGL,CAAS,EAAG,CAAC,GAAGC,CAAU,CAAC,CAAC,EAEjEK,EAAiC,MAAM,kBAAkBR,EAAYH,EAAQS,CAAI,EAEjFG,EAASF,EAAI,OAAOG,EAAWX,CAAU,EAAGS,EAAM,MAAM,EAG9D,GAAIC,EAAO,OAAS,EAClB,MAAM,IAAIE,EAGZ,GAAM,CAACC,CAAQ,EAAIH,EACnB,OAAOG,CACT,EGlDA,OAAQ,aAAAC,MAAgB,qBAWjB,IAAMC,EAAK,IACED,EAAU,eAAe,YAAY,CAAC",
6
+ "names": ["IDL", "Principal", "toNullable", "IDL", "z", "IDLTypeSchema", "val", "IDL", "CallArgSchema", "CallArgsSchema", "CallResultSchema", "CallParamsSchema", "RawPrincipalSchema", "PrincipalSchema", "CallResponseLengthError", "call", "params", "CallParamsSchema", "providedCanisterId", "method", "providedArgs", "resultType", "canisterId", "Principal", "argsTypes", "argsValues", "type", "value", "args", "IDL", "bytes", "result", "toNullable", "CallResponseLengthError", "response", "Principal", "id"]
7
7
  }
package/index.d.ts CHANGED
@@ -6,5 +6,6 @@ export * from './hooks/schemas/db/context';
6
6
  export * from './hooks/schemas/db/payload';
7
7
  export * from './hooks/schemas/satellite.env';
8
8
  export * from './schemas/candid';
9
- export * from './schemas/core';
9
+ export * from './schemas/db';
10
+ export * from './schemas/satellite';
10
11
  import './polyfills/console.polyfill';
package/index.js CHANGED
@@ -1,2 +1,2 @@
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};
1
+ import{a as I,b as T,c as S,d as J,e as y,f as d,g as h,h as z,i as r}from"./chunk-LVVTFR6B.js";import{a as U,b as w,c as P}from"./chunk-CCKUQNB5.js";import*as i from"zod";import*as o from"zod";var n=o.object({collections:o.array(o.string()).min(1).readonly()}).strict();import*as t from"zod";var f=e=>t.object({caller:S,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:z,description:h.optional(),version:T.optional()}).strict(),k=s.object({current:r.optional(),proposed:j}).strict();var D=e=>O.object({collection:y,key:d,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),oe=Z,R=e=>i.function().args(p).returns(e),re=e=>i.union([e,R(e)]);function ne(e){return e}import*as m from"zod";var v=e=>n.extend({run:l(e)}).strict(),g=v(F),ae=g,_=e=>m.function().args(p).returns(e),xe=e=>m.union([e,_(e)]);function fe(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{re as AssertFnOrObjectSchema,R as AssertFnSchema,A as AssertFunctionSchema,oe as AssertSchema,H as AssertSetDocContextSchema,Z as AssertSetDocSchema,y as CollectionSchema,n as CollectionsSchema,k as DocAssertSetSchema,D as DocContextSchema,h as DocDescriptionSchema,r as DocSchema,u as DocUpsertSchema,f as HookContextSchema,xe as HookFnOrObjectSchema,_ as HookFnSchema,ae as HookSchema,d as KeySchema,F as OnSetDocContextSchema,g as OnSetDocSchema,P as PrincipalSchema,j as ProposedDocSchema,z as RawDataSchema,w as RawPrincipalSchema,S as RawUserIdSchema,l as RunFunctionSchema,p as SatelliteEnvSchema,I as TimestampSchema,U as Uint8ArraySchema,J as UserIdSchema,T as VersionSchema,ne as defineAssert,fe as defineHook};
2
2
  //# sourceMappingURL=index.js.map
package/index.js.map CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
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",
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).readonly()\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/satellite';\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/satellite';\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 {DocDescriptionSchema, DocSchema, RawDataSchema} from '../../../schemas/db';\nimport {VersionSchema} from '../../../schemas/satellite';\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": "sJAAA,UAAYA,MAAO,MCAnB,UAAYC,MAAO,MAKZ,IAAMC,EACV,SAAO,CAIN,YAAe,QAAQ,SAAO,CAAC,EAAE,IAAI,CAAC,EAAE,SAAS,CACnD,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
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.8",
3
+ "version": "0.0.9-next-2025-03-18",
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,11 +46,11 @@
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",
53
- "@dfinity/utils": "^2",
54
- "zod": "^3"
49
+ "@dfinity/agent": "*",
50
+ "@dfinity/candid": "*",
51
+ "@dfinity/identity": "*",
52
+ "@dfinity/principal": "*",
53
+ "@dfinity/utils": "*",
54
+ "zod": "*"
55
55
  }
56
- }
56
+ }
@@ -1,5 +1,9 @@
1
1
  import { Principal as CandidPrincipal } from '@dfinity/principal';
2
2
  import * as z from 'zod';
3
+ /**
4
+ * A schema that validates a value is an Uint8Array.
5
+ */
6
+ export declare const Uint8ArraySchema: z.ZodType<Uint8Array<ArrayBufferLike>, z.ZodTypeDef, Uint8Array<ArrayBufferLike>>;
3
7
  /**
4
8
  * @see RawPrincipal
5
9
  */
package/schemas/db.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import * as z from 'zod';
2
+ import { Uint8ArraySchema } from './candid';
2
3
  /**
3
4
  * @see DocDescription
4
5
  */
@@ -7,6 +8,16 @@ export declare const DocDescriptionSchema: z.ZodString;
7
8
  * Represents a document description with a maximum length of 1024 characters.
8
9
  */
9
10
  export type DocDescription = z.infer<typeof DocDescriptionSchema>;
11
+ /**
12
+ * @see RawData
13
+ */
14
+ export declare const RawDataSchema: z.ZodType<Uint8Array<ArrayBufferLike>, z.ZodTypeDef, Uint8Array<ArrayBufferLike>>;
15
+ /**
16
+ * Represents raw binary data.
17
+ *
18
+ * This is used to store structured data in a document.
19
+ */
20
+ export type RawData = z.infer<typeof Uint8ArraySchema>;
10
21
  /**
11
22
  * @see Doc
12
23
  */
@@ -19,16 +19,6 @@ export declare const VersionSchema: z.ZodBigInt;
19
19
  * This is typically incremented with each update to ensure consistency.
20
20
  */
21
21
  export type Version = z.infer<typeof VersionSchema>;
22
- /**
23
- * @see RawData
24
- */
25
- export declare const RawDataSchema: z.ZodType<Uint8Array<ArrayBufferLike>, z.ZodTypeDef, Uint8Array<ArrayBufferLike>>;
26
- /**
27
- * Represents raw binary data.
28
- *
29
- * This is used to store unstructured data in a document.
30
- */
31
- export type RawData = z.infer<typeof RawDataSchema>;
32
22
  /**
33
23
  * @see RawUserId
34
24
  */
@@ -1,4 +1,4 @@
1
- import type { RawData } from '../schemas/core';
1
+ import type { RawData } from '../schemas/db';
2
2
  /**
3
3
  * Decodes the raw data of a document into a JavaScript object.
4
4
  *
package/sdk.js CHANGED
@@ -1,2 +1,2 @@
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};
1
+ import{b as a,c as r,d as c,e as s,f as m,g as i,h as n}from"./chunk-LVVTFR6B.js";import"./chunk-CCKUQNB5.js";import{Principal as h}from"@dfinity/principal";import*as e from"zod";var f=e.object({key:m,description:i.optional(),data:n,version:a.optional()}).strict(),p=e.object({caller:r.or(c),collection:s,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 U=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,U 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
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",
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 {DocDescriptionSchema, RawDataSchema} from '../../schemas/db';\nimport {\n CollectionSchema,\n KeySchema,\n RawUserIdSchema,\n UserIdSchema,\n VersionSchema\n} from '../../schemas/satellite';\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/db';\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": "8GAAA,OAAQ,aAAAA,MAAgB,qBCAxB,UAAYC,MAAO,MAaZ,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,EDnDH,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
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/src/global.d.ts CHANGED
@@ -1,4 +1,5 @@
1
- import type {RawData, RawPrincipal, RawUserId} from './schemas/core';
1
+ import {RawData} from './schemas/db';
2
+ import type {RawPrincipal, RawUserId} from './schemas/satellite';
2
3
  import type {SetDoc} from './sdk/schemas/db';
3
4
 
4
5
  declare global {
@@ -14,4 +15,9 @@ declare global {
14
15
 
15
16
  function __ic_cdk_id(): RawPrincipal;
16
17
  function __ic_cdk_print(msg: string): void;
18
+ function __ic_cdk_call_raw(
19
+ canisterId: RawPrincipal,
20
+ method: string,
21
+ args: Uint8Array<ArrayBuffer>
22
+ ): Promise<Uint8Array<ArrayBuffer>>;
17
23
  }
@@ -0,0 +1,2 @@
1
+ import { Principal } from '@dfinity/principal';
2
+ export declare const mockCanisterId: Principal;
package/chunk-MKW7CALF.js DELETED
@@ -1,2 +0,0 @@
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
@@ -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 {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
- }
File without changes