@junobuild/functions 0.2.0 → 0.2.2
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 +99 -0
- package/chunk-CCKUQNB5.js +2 -0
- package/chunk-CCKUQNB5.js.map +7 -0
- package/chunk-SFZECPH3.js +2 -0
- package/chunk-SFZECPH3.js.map +7 -0
- package/hooks/assertions.d.ts +1 -1
- package/hooks/hooks.d.ts +1 -1
- package/hooks/schemas/collections.d.ts +1 -1
- package/hooks/schemas/context.d.ts +1 -1
- package/hooks/schemas/db/context.d.ts +1 -1
- package/hooks/schemas/db/payload.d.ts +1 -1
- package/hooks/schemas/satellite.env.d.ts +1 -1
- package/hooks/schemas/storage/context.d.ts +1 -1
- package/hooks/schemas/storage/payload.d.ts +1 -1
- package/ic-cdk/schemas/call.d.ts +1 -1
- package/ic-cdk.js +1 -1
- package/ic-cdk.js.map +2 -2
- package/index.js +1 -1
- package/index.js.map +2 -2
- package/package.json +2 -2
- package/schemas/candid.d.ts +1 -1
- package/schemas/db.d.ts +1 -1
- package/schemas/list.d.ts +1 -1
- package/schemas/satellite.d.ts +1 -1
- package/schemas/storage.d.ts +1 -1
- package/sdk/schemas/collections.d.ts +1 -1
- package/sdk/schemas/controllers.d.ts +1 -1
- package/sdk/schemas/db.d.ts +140 -140
- package/sdk/schemas/params.d.ts +1 -1
- package/sdk/schemas/storage.d.ts +1 -1
- package/sdk.js +1 -1
- package/sdk.js.map +2 -2
- package/utils/zod.utils.d.ts +1 -1
- package/chunk-KY6LCVKU.js +0 -2
- package/chunk-KY6LCVKU.js.map +0 -7
- package/chunk-R6MTJSTE.js +0 -2
- package/chunk-R6MTJSTE.js.map +0 -7
package/README.md
CHANGED
|
@@ -219,6 +219,10 @@ Parameters:
|
|
|
219
219
|
- `caller`: - The caller identity, either a raw `Uint8Array`
|
|
220
220
|
or a `Principal` instance.
|
|
221
221
|
|
|
222
|
+
Returns:
|
|
223
|
+
|
|
224
|
+
The raw user ID as a `Uint8Array`.
|
|
225
|
+
|
|
222
226
|
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/sdk/utils/caller.utils.ts#L12)
|
|
223
227
|
|
|
224
228
|
#### :gear: getAdminControllers
|
|
@@ -229,6 +233,10 @@ Gets the list of admin controllers from the Satellite.
|
|
|
229
233
|
| --------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
230
234
|
| `getAdminControllers` | `() => [Uint8Array<ArrayBufferLike>, { metadata: [string, string][]; created_at: bigint; updated_at: bigint; scope: "write" or "admin" or "submit"; expires_at?: bigint or undefined; }][]` |
|
|
231
235
|
|
|
236
|
+
Returns:
|
|
237
|
+
|
|
238
|
+
The list of admin controllers.
|
|
239
|
+
|
|
232
240
|
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/sdk/controllers.sdk.ts#L15)
|
|
233
241
|
|
|
234
242
|
#### :gear: getControllers
|
|
@@ -239,6 +247,10 @@ Gets the list of controllers from the Satellite.
|
|
|
239
247
|
| ---------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
240
248
|
| `getControllers` | `() => [Uint8Array<ArrayBufferLike>, { metadata: [string, string][]; created_at: bigint; updated_at: bigint; scope: "write" or "admin" or "submit"; expires_at?: bigint or undefined; }][]` |
|
|
241
249
|
|
|
250
|
+
Returns:
|
|
251
|
+
|
|
252
|
+
The list of all controllers.
|
|
253
|
+
|
|
242
254
|
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/sdk/controllers.sdk.ts#L24)
|
|
243
255
|
|
|
244
256
|
#### :gear: isAdminController
|
|
@@ -254,6 +266,10 @@ Parameters:
|
|
|
254
266
|
- `params`: - The parameters including the caller identity
|
|
255
267
|
and the list of controllers to verify against.
|
|
256
268
|
|
|
269
|
+
Returns:
|
|
270
|
+
|
|
271
|
+
Whether the caller is an admin.
|
|
272
|
+
|
|
257
273
|
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/sdk/controllers.sdk.ts#L36)
|
|
258
274
|
|
|
259
275
|
#### :gear: isController
|
|
@@ -269,6 +285,10 @@ Parameters:
|
|
|
269
285
|
- `params`: - The parameters including the caller identity
|
|
270
286
|
and the list of controllers to verify against.
|
|
271
287
|
|
|
288
|
+
Returns:
|
|
289
|
+
|
|
290
|
+
Whether the caller is a controller.
|
|
291
|
+
|
|
272
292
|
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/sdk/controllers.sdk.ts#L56)
|
|
273
293
|
|
|
274
294
|
#### :gear: setDocStore
|
|
@@ -286,6 +306,11 @@ Parameters:
|
|
|
286
306
|
- `params`: - The parameters required to store the document,
|
|
287
307
|
including the caller, collection, key, and document data.
|
|
288
308
|
|
|
309
|
+
Returns:
|
|
310
|
+
|
|
311
|
+
The context of the stored or updated document,
|
|
312
|
+
including its key, collection, and both the previous and current versions of the document.
|
|
313
|
+
|
|
289
314
|
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/sdk/db.sdk.ts#L39)
|
|
290
315
|
|
|
291
316
|
#### :gear: deleteDocStore
|
|
@@ -301,6 +326,11 @@ Parameters:
|
|
|
301
326
|
- `params`: - The parameters required to delete the document,
|
|
302
327
|
including the caller, collection, key, and the expected version of the document.
|
|
303
328
|
|
|
329
|
+
Returns:
|
|
330
|
+
|
|
331
|
+
The context of the deleted document,
|
|
332
|
+
including its key, collection, and optionally the previous document data if it existed.
|
|
333
|
+
|
|
304
334
|
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/sdk/db.sdk.ts#L61)
|
|
305
335
|
|
|
306
336
|
#### :gear: getDocStore
|
|
@@ -315,6 +345,10 @@ Parameters:
|
|
|
315
345
|
|
|
316
346
|
- `params`: - The parameters required to get the document.
|
|
317
347
|
|
|
348
|
+
Returns:
|
|
349
|
+
|
|
350
|
+
The document if found, or undefined if not.
|
|
351
|
+
|
|
318
352
|
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/sdk/db.sdk.ts#L81)
|
|
319
353
|
|
|
320
354
|
#### :gear: listDocsStore
|
|
@@ -329,6 +363,10 @@ Parameters:
|
|
|
329
363
|
|
|
330
364
|
- `params`: - The parameters required to perform the list operation.
|
|
331
365
|
|
|
366
|
+
Returns:
|
|
367
|
+
|
|
368
|
+
A list result containing matching documents and pagination metadata.
|
|
369
|
+
|
|
332
370
|
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/sdk/db.sdk.ts#L101)
|
|
333
371
|
|
|
334
372
|
#### :gear: countCollectionDocsStore
|
|
@@ -343,6 +381,10 @@ Parameters:
|
|
|
343
381
|
|
|
344
382
|
- `params`: - The parameters required to count documents in the collection.
|
|
345
383
|
|
|
384
|
+
Returns:
|
|
385
|
+
|
|
386
|
+
The total number of documents in the specified collection.
|
|
387
|
+
|
|
346
388
|
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/sdk/db.sdk.ts#L121)
|
|
347
389
|
|
|
348
390
|
#### :gear: countDocsStore
|
|
@@ -357,6 +399,10 @@ Parameters:
|
|
|
357
399
|
|
|
358
400
|
- `params`: - The parameters required to perform the filtered count.
|
|
359
401
|
|
|
402
|
+
Returns:
|
|
403
|
+
|
|
404
|
+
The number of documents that match the provided filters.
|
|
405
|
+
|
|
360
406
|
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/sdk/db.sdk.ts#L139)
|
|
361
407
|
|
|
362
408
|
#### :gear: deleteDocsStore
|
|
@@ -385,6 +431,10 @@ Parameters:
|
|
|
385
431
|
|
|
386
432
|
- `params`: - The parameters required to perform the filtered deletion.
|
|
387
433
|
|
|
434
|
+
Returns:
|
|
435
|
+
|
|
436
|
+
The context resulting of the deletion of documents that match the provided filters.
|
|
437
|
+
|
|
388
438
|
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/sdk/db.sdk.ts#L175)
|
|
389
439
|
|
|
390
440
|
#### :gear: decodeDocData
|
|
@@ -399,6 +449,10 @@ Parameters:
|
|
|
399
449
|
|
|
400
450
|
- `data`: - The raw data to be decoded.
|
|
401
451
|
|
|
452
|
+
Returns:
|
|
453
|
+
|
|
454
|
+
The parsed JavaScript object.
|
|
455
|
+
|
|
402
456
|
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/sdk/serializer.sdk.ts#L11)
|
|
403
457
|
|
|
404
458
|
#### :gear: encodeDocData
|
|
@@ -413,6 +467,10 @@ Parameters:
|
|
|
413
467
|
|
|
414
468
|
- `data`: - The data to be encoded.
|
|
415
469
|
|
|
470
|
+
Returns:
|
|
471
|
+
|
|
472
|
+
The serialized raw data.
|
|
473
|
+
|
|
416
474
|
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/sdk/serializer.sdk.ts#L21)
|
|
417
475
|
|
|
418
476
|
#### :gear: countCollectionAssetsStore
|
|
@@ -427,6 +485,10 @@ Parameters:
|
|
|
427
485
|
|
|
428
486
|
- `params`: - The parameters required to count assets in the collection.
|
|
429
487
|
|
|
488
|
+
Returns:
|
|
489
|
+
|
|
490
|
+
The total number of assets in the specified collection.
|
|
491
|
+
|
|
430
492
|
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/sdk/storage.sdk.ts#L35)
|
|
431
493
|
|
|
432
494
|
#### :gear: countAssetsStore
|
|
@@ -441,6 +503,10 @@ Parameters:
|
|
|
441
503
|
|
|
442
504
|
- `params`: - The parameters required to perform the filtered count.
|
|
443
505
|
|
|
506
|
+
Returns:
|
|
507
|
+
|
|
508
|
+
The number of assets that match the provided filters.
|
|
509
|
+
|
|
444
510
|
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/sdk/storage.sdk.ts#L53)
|
|
445
511
|
|
|
446
512
|
#### :gear: setAssetHandler
|
|
@@ -469,6 +535,10 @@ Parameters:
|
|
|
469
535
|
|
|
470
536
|
- `params`: - The parameters required to delete the asset.
|
|
471
537
|
|
|
538
|
+
Returns:
|
|
539
|
+
|
|
540
|
+
The potentially deleted asset.
|
|
541
|
+
|
|
472
542
|
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/sdk/storage.sdk.ts#L89)
|
|
473
543
|
|
|
474
544
|
#### :gear: deleteAssetsStore
|
|
@@ -497,6 +567,10 @@ Parameters:
|
|
|
497
567
|
|
|
498
568
|
- `params`: - The parameters required to perform the filtered deletion.
|
|
499
569
|
|
|
570
|
+
Returns:
|
|
571
|
+
|
|
572
|
+
The potential asset resulting of the deletion that match the provided filters.
|
|
573
|
+
|
|
500
574
|
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/sdk/storage.sdk.ts#L125)
|
|
501
575
|
|
|
502
576
|
#### :gear: getAssetStore
|
|
@@ -511,6 +585,10 @@ Parameters:
|
|
|
511
585
|
|
|
512
586
|
- `params`: - The parameters required to get the asset.
|
|
513
587
|
|
|
588
|
+
Returns:
|
|
589
|
+
|
|
590
|
+
The asset if found, or undefined if not.
|
|
591
|
+
|
|
514
592
|
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/sdk/storage.sdk.ts#L147)
|
|
515
593
|
|
|
516
594
|
#### :gear: listAssetsStore
|
|
@@ -525,6 +603,10 @@ Parameters:
|
|
|
525
603
|
|
|
526
604
|
- `params`: - The parameters required to perform the list operation.
|
|
527
605
|
|
|
606
|
+
Returns:
|
|
607
|
+
|
|
608
|
+
A list result containing matching assets and pagination metadata.
|
|
609
|
+
|
|
528
610
|
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/sdk/storage.sdk.ts#L167)
|
|
529
611
|
|
|
530
612
|
#### :gear: getContentChunksStore
|
|
@@ -541,6 +623,10 @@ Parameters:
|
|
|
541
623
|
|
|
542
624
|
- `params`: - The parameters including encoding, chunk index, and memory type.
|
|
543
625
|
|
|
626
|
+
Returns:
|
|
627
|
+
|
|
628
|
+
The content chunk if found, or `undefined` if not.
|
|
629
|
+
|
|
544
630
|
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/sdk/storage.sdk.ts#L189)
|
|
545
631
|
|
|
546
632
|
#### :gear: call
|
|
@@ -558,6 +644,11 @@ Parameters:
|
|
|
558
644
|
|
|
559
645
|
- `params`: - The parameters required for the canister call
|
|
560
646
|
|
|
647
|
+
Returns:
|
|
648
|
+
|
|
649
|
+
A promise resolving to the decoded result of the call.
|
|
650
|
+
Returns `undefined` if the canister response is empty.
|
|
651
|
+
|
|
561
652
|
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/ic-cdk/call.ic-cdk.ts#L20)
|
|
562
653
|
|
|
563
654
|
#### :gear: id
|
|
@@ -572,6 +663,10 @@ the Principal of the executing canister.
|
|
|
572
663
|
| -------- | ----------------- |
|
|
573
664
|
| `id` | `() => Principal` |
|
|
574
665
|
|
|
666
|
+
Returns:
|
|
667
|
+
|
|
668
|
+
The Principal ID of the Satellite.
|
|
669
|
+
|
|
575
670
|
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/ic-cdk/id.ic-cdk.ts#L12)
|
|
576
671
|
|
|
577
672
|
#### :gear: time
|
|
@@ -586,6 +681,10 @@ the system time publicly exposed and verified part of the IC state tree
|
|
|
586
681
|
| -------- | -------------- |
|
|
587
682
|
| `time` | `() => bigint` |
|
|
588
683
|
|
|
684
|
+
Returns:
|
|
685
|
+
|
|
686
|
+
The current timestamp.
|
|
687
|
+
|
|
589
688
|
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/ic-cdk/time.ic-cdk.ts#L10)
|
|
590
689
|
|
|
591
690
|
### :wrench: Constants
|
|
@@ -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 s,b as h,c as l}from"./chunk-CCKUQNB5.js";import*as i from"zod";var o=i.bigint(),r=i.bigint(),n=h,O=l,y=i.string(),c=i.string(),a=i.string().max(1024);import*as p from"zod";var g=s,_=p.object({owner:n,data:g,description:a.optional(),created_at:o,updated_at:o,version:r.optional()}).strict(),H=_.optional(),V=p.object({data:g,description:a.optional(),version:r.optional()}).strict(),P=p.object({version:r.optional()}).strict();import*as e from"zod";var u=e.tuple([e.string(),e.string()]),x=e.array(u),T=s,A=T,D=e.instanceof(Uint8Array).refine(m=>m.length===32,{message:"Hash must be a Uint8Array of length 32"}),z=e.object({name:e.string(),full_path:e.string(),token:e.string().optional(),collection:y,owner:n,description:a.optional()}).strict(),S=e.object({modified:o,content_chunks:e.array(A),total_length:e.bigint(),sha256:D}),w=S.omit({content_chunks:!0}).strict(),d=e.enum(["identity","gzip","compress","deflate","br"]),f=e.object({key:z,headers:x,encodings:e.array(e.tuple([d,S])),created_at:o,updated_at:o,version:r.optional()}).strict(),q=f.omit({encodings:!0}).extend({encodings:e.array(e.tuple([d,w]))}).strict(),I=e.bigint(),Z=e.object({key:z,reference_id:I.optional(),expires_at:o,encoding_type:d.optional()}).strict(),U=e.bigint(),R=e.bigint(),G=e.object({batch_id:R,headers:x,chunk_ids:e.array(U)}).strict(),J=e.string(),Q=f.optional();import*as t from"zod";var b=t.union([t.object({equal:o}),t.object({greater_than:o}),t.object({less_than:o}),t.object({between:t.tuple([o,o])})]),k=t.object({key:c.optional(),description:a.optional(),created_at:b.optional(),updated_at:b.optional()}).strict(),j=t.object({start_after:c.optional(),limit:t.bigint().optional()}).strict(),C=t.enum(["keys","created_at","updated_at"]),L=t.object({desc:t.boolean(),field:C}).strict(),Y=t.object({matcher:k.optional(),paginate:j.optional(),order:L.optional(),owner:n.optional()}).strict(),$=m=>t.object({items:t.array(t.tuple([c,m])),items_length:t.bigint(),items_page:t.bigint().optional(),matches_length:t.bigint(),matches_pages:t.bigint().optional()}).strict();export{o as a,r as b,n as c,O as d,y as e,c as f,a as g,g as h,_ as i,H as j,V as k,P as l,x as m,T as n,z as o,S as p,f as q,q as r,Z as s,G as t,J as u,Q as v,b as w,k as x,j as y,C as z,L as A,Y as B,$ as C};
|
|
2
|
+
//# sourceMappingURL=chunk-SFZECPH3.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["src/schemas/satellite.ts", "src/schemas/db.ts", "src/schemas/storage.ts", "src/schemas/list.ts"],
|
|
4
|
+
"sourcesContent": ["import * as z from 'zod';\nimport {PrincipalSchema, RawPrincipalSchema} from './candid';\n\n/**\n * @see Timestamp\n */\nexport const TimestampSchema = z.bigint();\n\n/**\n * Represents a timestamp in nanoseconds since the Unix epoch.\n *\n * Used for tracking when events occur, such as document creation and updates.\n */\nexport type Timestamp = z.infer<typeof TimestampSchema>;\n\n/**\n * @see Version\n */\nexport const VersionSchema = z.bigint();\n\n/**\n * Represents a version number for tracking changes.\n *\n * This is typically incremented with each update to ensure consistency.\n */\nexport type Version = z.infer<typeof VersionSchema>;\n\n/**\n * @see RawUserId\n */\nexport const RawUserIdSchema = RawPrincipalSchema;\n\n/**\n * Represents a raw user identifier.\n *\n * This is a principal associated with a user.\n */\nexport type RawUserId = z.infer<typeof RawUserIdSchema>;\n\n/**\n * @see UserId\n */\nexport const UserIdSchema = PrincipalSchema;\n\n/**\n * Represents a user identifier.\n *\n * This is a principal associated with a user.\n */\nexport type UserId = z.infer<typeof UserIdSchema>;\n\n/**\n * @see Collection\n */\nexport const CollectionSchema = z.string();\n\n/**\n * A collection name where data are stored.\n */\nexport type Collection = z.infer<typeof CollectionSchema>;\n\n/**\n * @see Key\n */\nexport const KeySchema = z.string();\n\n/**\n * A key identifier within a collection.\n */\nexport type Key = z.infer<typeof KeySchema>;\n\n/**\n * @see Description\n */\nexport const DescriptionSchema = z.string().max(1024);\n\n/**\n * Represents a description with a maximum length of 1024 characters.\n * Used for document and asset fields which can be useful for search purpose.\n */\nexport type Description = z.infer<typeof DescriptionSchema>;\n", "import * as z from 'zod';\nimport {Uint8ArraySchema} from './candid';\nimport {\n type Description,\n DescriptionSchema,\n type RawUserId,\n RawUserIdSchema,\n type Timestamp,\n TimestampSchema,\n type Version,\n VersionSchema\n} from './satellite';\n\n/**\n * @see RawData\n */\nexport const RawDataSchema = Uint8ArraySchema;\n\n/**\n * Represents raw binary data.\n *\n * This is used to store structured data in a document.\n */\nexport type RawData = z.infer<typeof Uint8ArraySchema>;\n\n/**\n * @see Doc\n */\nexport const DocSchema = z\n .object({\n owner: RawUserIdSchema,\n data: RawDataSchema,\n description: DescriptionSchema.optional(),\n created_at: TimestampSchema,\n updated_at: TimestampSchema,\n version: VersionSchema.optional()\n })\n .strict();\n\n/**\n * Represents a document stored in a collection.\n */\nexport interface Doc {\n /**\n * The user who owns this document.\n */\n owner: RawUserId;\n\n /**\n * The raw data of the document.\n */\n data: RawData;\n\n /**\n * An optional description of the document.\n */\n description?: Description;\n\n /**\n * The timestamp when the document was first created.\n */\n created_at: Timestamp;\n\n /**\n * The timestamp when the document was last updated.\n */\n updated_at: Timestamp;\n\n /**\n * The version number of the document, used for consistency checks.\n * If not provided, it's assumed to be the first version.\n */\n version?: Version;\n}\n\n/**\n * @see OptionDoc\n */\nexport const OptionDocSchema = DocSchema.optional();\n\n/**\n * A shorthand for a document that might or not be defined.\n */\nexport type OptionDoc = Doc | undefined;\n\n/**\n * @see SetDoc\n */\nexport const SetDocSchema = z\n .object({\n data: RawDataSchema,\n description: DescriptionSchema.optional(),\n version: VersionSchema.optional()\n })\n .strict();\n\n/**\n * Represents the proposed version of a document to be created or updated.\n * This can be validated before allowing the operation.\n */\nexport interface SetDoc {\n /**\n * The raw data of the document.\n */\n data: RawData;\n\n /**\n * An optional description of the document.\n */\n description?: Description;\n\n /**\n * The expected version number to ensure consistency.\n */\n version?: Version;\n}\n\n/**\n * @see DelDoc\n */\nexport const DelDocSchema = z\n .object({\n version: VersionSchema.optional()\n })\n .strict();\n\n/**\n * Represents the proposed version of a document to be deleted.\n * This can be validated before allowing the operation.\n */\nexport interface DelDoc {\n /**\n * The expected version number to ensure consistency.\n */\n version?: Version;\n}\n", "import * as z from 'zod';\nimport {Uint8ArraySchema} from './candid';\nimport {\n type Collection,\n CollectionSchema,\n type Description,\n DescriptionSchema,\n type RawUserId,\n RawUserIdSchema,\n type Timestamp,\n TimestampSchema,\n type Version,\n VersionSchema\n} from './satellite';\n\n/**\n * @see HeaderField\n */\nconst HeaderFieldSchema = z.tuple([z.string(), z.string()]);\n\n/**\n * Represents a single HTTP header as a tuple of name and value.\n */\nexport type HeaderField = [string, string];\n\n/**\n * @see HeaderFields\n */\nexport const HeaderFieldsSchema = z.array(HeaderFieldSchema);\n\n/**\n * Represents a list of HTTP headers.\n */\nexport type HeaderFields = HeaderField[];\n\n/**\n * @see Blob\n */\nexport const BlobSchema = Uint8ArraySchema;\n\n/**\n * Binary content used in asset encoding.\n */\nexport type Blob = Uint8Array;\n\n/**\n * @see BlobOrKey\n */\nconst BlobOrKeySchema = BlobSchema;\n\n/**\n * When stable memory is used, chunks are saved within a StableBTreeMap and their keys - StableEncodingChunkKey - are saved for reference as serialized values\n */\nexport type BlobOrKey = Uint8Array;\n\n/**\n * @see Hash\n */\nconst HashSchema = z.instanceof(Uint8Array).refine((val) => val.length === 32, {\n message: 'Hash must be a Uint8Array of length 32'\n});\n\n/**\n * Represents a SHA-256 hash as a 32-byte binary value.\n */\nexport type Hash = Uint8Array;\n\n/**\n * @see AssetKey\n */\nexport const AssetKeySchema = z\n .object({\n name: z.string(),\n full_path: z.string(),\n token: z.string().optional(),\n collection: CollectionSchema,\n owner: RawUserIdSchema,\n description: DescriptionSchema.optional()\n })\n .strict();\n\n/**\n * Metadata identifying an asset within a collection and the storage system.\n */\nexport interface AssetKey {\n /**\n * The name of the asset (e.g., \"logo.png\").\n */\n name: string;\n\n /**\n * The full relative path of the asset (e.g., \"/images/logo.png\").\n */\n full_path: string;\n\n /**\n * Optional access token for the asset.\n * If set, can be used using a query parameter e.g. /full_path/?token=1223-3345-5564-3333\n */\n token?: string;\n\n /**\n * The collection to which this asset belongs.\n */\n collection: Collection;\n\n /**\n * The owner of the asset.\n */\n owner: RawUserId;\n\n /**\n * Optional description of the asset for indexing/search.\n */\n description?: Description;\n}\n\n/**\n * @see AssetEncoding\n */\nexport const AssetEncodingSchema = z.object({\n modified: TimestampSchema,\n content_chunks: z.array(BlobOrKeySchema),\n total_length: z.bigint(),\n sha256: HashSchema\n});\n\n/**\n * Represents a specific encoding of an asset, such as \"gzip\" or \"identity\" (no compression).\n */\nexport interface AssetEncoding {\n /**\n * Timestamp when the encoding was last modified.\n */\n modified: Timestamp;\n\n /**\n * Chunks of binary content or references to them.\n */\n content_chunks: BlobOrKey[];\n\n /**\n * Total byte size of the encoded content.\n */\n total_length: bigint;\n\n /**\n * SHA-256 hash of the encoded content.\n */\n sha256: Hash;\n}\n\n/**\n * @see AssetEncodingNoContent\n */\nconst AssetEncodingNoContentSchema = AssetEncodingSchema.omit({content_chunks: true}).strict();\n\n/**\n * Represents a specific encoding of an asset, such as \"gzip\" or \"identity\" (no compression), without the chunks.\n */\nexport type AssetEncodingNoContent = Omit<AssetEncoding, 'content_chunks'>;\n\n/**\n * @see EncodingType\n */\nconst EncodingTypeSchema = z.enum(['identity', 'gzip', 'compress', 'deflate', 'br']);\n\n/**\n * A string identifier representing a specific encoding format (e.g., \"gzip\", \"identity\").\n */\nexport type EncodingType = 'identity' | 'gzip' | 'compress' | 'deflate' | 'br';\n\n/**\n * @see Asset\n */\nexport const AssetSchema = z\n .object({\n key: AssetKeySchema,\n headers: HeaderFieldsSchema,\n encodings: z.array(z.tuple([EncodingTypeSchema, AssetEncodingSchema])),\n created_at: TimestampSchema,\n updated_at: TimestampSchema,\n version: VersionSchema.optional()\n })\n .strict();\n\n/**\n * A stored asset including its metadata, encodings, and timestamps.\n */\nexport interface Asset {\n /**\n * Metadata about the asset's identity and ownership.\n */\n key: AssetKey;\n\n /**\n * Optional HTTP headers associated with the asset.\n */\n headers: HeaderField[];\n\n /**\n * A mapping from encoding types (e.g., \"identity\", \"gzip\") to the corresponding encoded version.\n */\n encodings: [EncodingType, AssetEncoding][];\n\n /**\n * Timestamp when the asset was created.\n */\n created_at: Timestamp;\n\n /**\n * Timestamp when the asset was last updated.\n */\n updated_at: Timestamp;\n\n /**\n * Optional version number of the asset.\n */\n version?: Version;\n}\n\n/**\n * @see AssetNoContent\n */\nexport const AssetNoContentSchema = AssetSchema.omit({encodings: true})\n .extend({\n encodings: z.array(z.tuple([EncodingTypeSchema, AssetEncodingNoContentSchema]))\n })\n .strict();\n\n/**\n * A stored asset including its metadata, encodings without chunks, and timestamps.\n */\nexport type AssetNoContent = Omit<Asset, 'encodings'> & {\n encodings: [EncodingType, AssetEncodingNoContent][];\n};\n\n/**\n * @see ReferenceId\n */\nconst ReferenceIdSchema = z.bigint();\n\n/**\n * A unique reference identifier for batches.\n */\nexport type ReferenceId = bigint;\n\n/**\n * @see Batch\n */\nexport const BatchSchema = z\n .object({\n key: AssetKeySchema,\n reference_id: ReferenceIdSchema.optional(),\n expires_at: TimestampSchema,\n encoding_type: EncodingTypeSchema.optional()\n })\n .strict();\n\n/**\n * Represents a batch of chunks to be uploaded and committed to an asset.\n */\nexport interface Batch {\n /**\n * The metadata key for the asset being uploaded.\n */\n key: AssetKey;\n\n /**\n * Optional reference ID for tracking or validation.\n */\n reference_id?: ReferenceId;\n\n /**\n * Timestamp when this batch expires.\n */\n expires_at: Timestamp;\n\n /**\n * Optional encoding format (e.g., \"gzip\").\n */\n encoding_type?: EncodingType;\n}\n\n/**\n * @see ChunkId\n */\nconst ChunkIdSchema = z.bigint();\n\n/**\n * A unique identifier representing a single chunk of data.\n */\nexport type ChunkId = bigint;\n\n/**\n * @see BatchId\n */\nconst BatchIdSchema = z.bigint();\n\n/**\n * A unique identifier representing a batch of upload.\n */\nexport type BatchId = bigint;\n\n/**\n * @see CommitBatch\n */\nexport const CommitBatchSchema = z\n .object({\n batch_id: BatchIdSchema,\n headers: HeaderFieldsSchema,\n chunk_ids: z.array(ChunkIdSchema)\n })\n .strict();\n\n/**\n * Represents the final step in uploading an asset, committing the batch to storage.\n */\nexport interface CommitBatch {\n /**\n * The ID of the batch being committed.\n */\n batch_id: BatchId;\n\n /**\n * HTTP headers associated with this asset.\n */\n headers: HeaderField[];\n\n /**\n * List of chunk IDs that make up the asset content.\n */\n chunk_ids: ChunkId[];\n}\n\n/**\n * @see FullPath\n */\nexport const FullPathSchema = z.string();\n\n/**\n * Represents the relative path of an asset in storage.\n * For assets that are not part of the frontend app, the collection must be included at the root of the path.\n *\n * Example: `/images/a-sun-above-the-mountains.png`\n */\nexport type FullPath = string;\n\n/**\n * @see OptionAsset\n */\nexport const OptionAssetSchema = AssetSchema.optional();\n\n/**\n * A shorthand for an asset that might or not be defined.\n */\nexport type OptionAsset = Asset | undefined;\n", "import * as z from 'zod';\nimport {\n type Description,\n type Key,\n type RawUserId,\n type Timestamp,\n DescriptionSchema,\n KeySchema,\n RawUserIdSchema,\n TimestampSchema\n} from './satellite';\n\n/**\n * @see TimestampMatcher\n */\nexport const TimestampMatcherSchema = z.union([\n z.object({equal: TimestampSchema}),\n z.object({greater_than: TimestampSchema}),\n z.object({less_than: TimestampSchema}),\n z.object({between: z.tuple([TimestampSchema, TimestampSchema])})\n]);\n\n/**\n * TimestampMatcher matches a timestamp field using a specific strategy.\n */\nexport type TimestampMatcher =\n | {equal: Timestamp}\n | {greater_than: Timestamp}\n | {less_than: Timestamp}\n | {between: [Timestamp, Timestamp]};\n\n/**\n * @see ListMatcher\n */\nexport const ListMatcherSchema = z\n .object({\n key: KeySchema.optional(),\n description: DescriptionSchema.optional(),\n created_at: TimestampMatcherSchema.optional(),\n updated_at: TimestampMatcherSchema.optional()\n })\n .strict();\n\n/**\n * Matcher used to filter list results.\n */\nexport interface ListMatcher {\n key?: Key;\n description?: Description;\n created_at?: TimestampMatcher;\n updated_at?: TimestampMatcher;\n}\n\n/**\n * @see ListPaginate\n */\nexport const ListPaginateSchema = z\n .object({\n start_after: KeySchema.optional(),\n limit: z.bigint().optional()\n })\n .strict();\n\n/**\n * Optional pagination controls for listing.\n */\nexport interface ListPaginate {\n start_after?: Key;\n limit?: bigint;\n}\n\n/**\n * @see ListOrderField\n */\nexport const ListOrderFieldSchema = z.enum(['keys', 'created_at', 'updated_at']);\n\n/**\n * Enum representing possible fields to order by.\n */\nexport type ListOrderField = 'keys' | 'updated_at' | 'created_at';\n\n/**\n * @see ListOrder\n */\nexport const ListOrderSchema = z\n .object({\n desc: z.boolean(),\n field: ListOrderFieldSchema\n })\n .strict();\n\n/**\n * Ordering strategy for listing documents.\n */\nexport interface ListOrder {\n desc: boolean;\n field: ListOrderField;\n}\n\n/**\n * @see ListParams\n */\nexport const ListParamsSchema = z\n .object({\n matcher: ListMatcherSchema.optional(),\n paginate: ListPaginateSchema.optional(),\n order: ListOrderSchema.optional(),\n owner: RawUserIdSchema.optional()\n })\n .strict();\n\n/**\n * Full set of listing parameters.\n */\nexport interface ListParams {\n matcher?: ListMatcher;\n paginate?: ListPaginate;\n order?: ListOrder;\n owner?: RawUserId;\n}\n\n/**\n * Represents a list result.\n *\n * @template T - The type of the data returned per item.\n * @see JsListResults\n */\nexport const createListResultsSchema = <T extends z.ZodTypeAny>(itemData: T) =>\n z\n .object({\n items: z.array(z.tuple([KeySchema, itemData])),\n items_length: z.bigint(),\n items_page: z.bigint().optional(),\n matches_length: z.bigint(),\n matches_pages: z.bigint().optional()\n })\n .strict();\n\n/**\n * List results, parameterized by type of returned item.\n */\nexport interface ListResults<T> {\n items: [Key, T][];\n items_length: bigint;\n items_page?: bigint;\n matches_length: bigint;\n matches_pages?: bigint;\n}\n"],
|
|
5
|
+
"mappings": "sDAAA,UAAYA,MAAO,MAMZ,IAAMC,EAAoB,SAAO,EAY3BC,EAAkB,SAAO,EAYzBC,EAAkBC,EAYlBC,EAAeC,EAYfC,EAAqB,SAAO,EAU5BC,EAAc,SAAO,EAUrBC,EAAsB,SAAO,EAAE,IAAI,IAAI,EC1EpD,UAAYC,MAAO,MAgBZ,IAAMC,EAAgBC,EAYhBC,EACV,SAAO,CACN,MAAOC,EACP,KAAMH,EACN,YAAaI,EAAkB,SAAS,EACxC,WAAYC,EACZ,WAAYA,EACZ,QAASC,EAAc,SAAS,CAClC,CAAC,EACA,OAAO,EAyCGC,EAAkBL,EAAU,SAAS,EAUrCM,EAC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", "RawPrincipalSchema", "UserIdSchema", "PrincipalSchema", "CollectionSchema", "KeySchema", "DescriptionSchema", "z", "RawDataSchema", "Uint8ArraySchema", "DocSchema", "RawUserIdSchema", "DescriptionSchema", "TimestampSchema", "VersionSchema", "OptionDocSchema", "SetDocSchema", "DelDocSchema", "z", "HeaderFieldSchema", "HeaderFieldsSchema", "BlobSchema", "Uint8ArraySchema", "BlobOrKeySchema", "HashSchema", "val", "AssetKeySchema", "CollectionSchema", "RawUserIdSchema", "DescriptionSchema", "AssetEncodingSchema", "TimestampSchema", "AssetEncodingNoContentSchema", "EncodingTypeSchema", "AssetSchema", "VersionSchema", "AssetNoContentSchema", "ReferenceIdSchema", "BatchSchema", "ChunkIdSchema", "BatchIdSchema", "CommitBatchSchema", "FullPathSchema", "OptionAssetSchema", "z", "TimestampMatcherSchema", "TimestampSchema", "ListMatcherSchema", "KeySchema", "DescriptionSchema", "ListPaginateSchema", "ListOrderFieldSchema", "ListOrderSchema", "ListParamsSchema", "RawUserIdSchema", "createListResultsSchema", "itemData"]
|
|
7
|
+
}
|
package/hooks/assertions.d.ts
CHANGED
package/hooks/hooks.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import * as z from 'zod
|
|
1
|
+
import * as z from 'zod';
|
|
2
2
|
import { type Collections } from './schemas/collections';
|
|
3
3
|
import { type RunFunction } from './schemas/context';
|
|
4
4
|
import { type OnDeleteDocContext, type OnDeleteFilteredDocsContext, type OnDeleteManyDocsContext, type OnSetDocContext, type OnSetManyDocsContext } from './schemas/db/context';
|
package/ic-cdk/schemas/call.d.ts
CHANGED
package/ic-cdk.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{b as n,c as i}from"./chunk-
|
|
1
|
+
import{b as n,c as i}from"./chunk-CCKUQNB5.js";import{IDL as l}from"@dfinity/candid";import{Principal as z}from"@dfinity/principal";import{toNullable as D}from"@dfinity/utils";import{IDL as A}from"@dfinity/candid";import*as r from"zod";var p=r.custom(e=>e instanceof A.Type,{message:"Invalid IDL.Type"}),_=r.tuple([p,r.unknown()]),w=r.array(_),S=p,s=r.object({canisterId:n.or(i),method:r.string().min(1),args:w.optional(),result:S.optional()});var t=class extends Error{constructor(){super(),this.message="More than one object returned by the response. This is unexpected."}};var N=async e=>{s.parse(e);let{canisterId:o,method:c,args:m,result:f}=e,y=o instanceof z?o.toUint8Array():o,[d,u]=(m??[]).reduce(([C,I],[P,T])=>[[...C,P],[...I,T]],[[],[]]),h=new Uint8Array(l.encode([...d],[...u])),x=await __ic_cdk_call_raw(y,c,h),a=l.decode(D(f),x.buffer);if(a.length>1)throw new t;let[g]=a;return g};import{Principal as L}from"@dfinity/principal";var F=()=>L.fromUint8Array(__ic_cdk_id());var H=()=>__ic_cdk_time();export{_ as CallArgSchema,w as CallArgsSchema,s as CallParamsSchema,t as CallResponseLengthError,S as CallResultSchema,p as IDLTypeSchema,N as call,F as id,H as time};
|
|
2
2
|
//# sourceMappingURL=ic-cdk.js.map
|
package/ic-cdk.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
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", "src/ic-cdk/time.ic-cdk.ts"],
|
|
4
|
-
"sourcesContent": ["import {IDL} from '@dfinity/candid';\nimport {Principal} from '@dfinity/principal';\nimport {toNullable} from '@dfinity/utils';\nimport {type CallParams, type IDLType, CallParamsSchema} 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 type {Principal} from '@dfinity/principal';\nimport * as z from 'zod
|
|
5
|
-
"mappings": "+CAAA,OAAQ,OAAAA,MAAU,kBAClB,OAAQ,aAAAC,MAAgB,qBACxB,OAAQ,cAAAC,MAAiB,iBCFzB,OAAQ,OAAAC,MAAU,kBAElB,UAAYC,MAAO,
|
|
4
|
+
"sourcesContent": ["import {IDL} from '@dfinity/candid';\nimport {Principal} from '@dfinity/principal';\nimport {toNullable} from '@dfinity/utils';\nimport {type CallParams, type IDLType, CallParamsSchema} 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 type {Principal} from '@dfinity/principal';\nimport * as z from 'zod';\nimport {PrincipalSchema, type RawPrincipal, 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 canisterId: RawPrincipalSchema.or(PrincipalSchema),\n method: z.string().min(1),\n args: CallArgsSchema.optional(),\n result: CallResultSchema.optional()\n});\n\n/**\n * Type representing the parameters required to make a canister call.\n */\nexport interface CallParams {\n /**\n * The target canister's ID.\n */\n canisterId: RawPrincipal | Principal;\n\n /**\n * The name of the method to call. Minimum one character.\n */\n method: string;\n\n /**\n * The arguments, including types and values, for the canister call.\n */\n args?: CallArgs;\n\n /**\n * The expected result type used for decoding the response.\n */\n result?: CallResult;\n}\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", "/**\n * Gets current timestamp, in nanoseconds since the epoch (1970-01-01)\n *\n * This function is a JavaScript binding for the Rust function\n * [`ic_cdk::time()`](https://docs.rs/ic-cdk/latest/ic_cdk/api/fn.time.html), which returns\n * the system time publicly exposed and verified part of the IC state tree\n *\n * @returns {bigint} The current timestamp.\n */\nexport const time = (): bigint => __ic_cdk_time();\n"],
|
|
5
|
+
"mappings": "+CAAA,OAAQ,OAAAA,MAAU,kBAClB,OAAQ,aAAAC,MAAgB,qBACxB,OAAQ,cAAA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C,MAAgB,qBAWjB,IAAMC,EAAK,IACED,EAAU,eAAe,YAAY,CAAC,ECHnD,IAAME,EAAO,IAAc,cAAc",
|
|
6
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", "time"]
|
|
7
7
|
}
|
package/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{A as Ue,B as Me,C as je,a as ie,b as De,c as z,d as Ae,e as F,f as H,g as ye,h as Se,i as n,j as Oe,k as b,l as U,m as de,n as he,o as Ce,p as fe,q as r,r as Te,s as M,t as j,u as ue,v as ke,w as ze,x as Fe,y as He,z as be}from"./chunk-
|
|
1
|
+
import{A as Ue,B as Me,C as je,a as ie,b as De,c as z,d as Ae,e as F,f as H,g as ye,h as Se,i as n,j as Oe,k as b,l as U,m as de,n as he,o as Ce,p as fe,q as r,r as Te,s as M,t as j,u as ue,v as ke,w as ze,x as Fe,y as He,z as be}from"./chunk-SFZECPH3.js";import{a as xe,b as me,c as le}from"./chunk-CCKUQNB5.js";import*as a from"zod";import*as v from"zod";var c=e=>v.custom(i=>e.implement(i));import*as m from"zod";var A=m.object({collections:m.array(m.string()).readonly()}).strict();import*as o from"zod";var t=e=>o.strictObject({caller:z,data:e}),_=e=>c(o.function({input:o.tuple([e]),output:o.void()})),Z=e=>c(o.function({input:o.tuple([e]),output:o.promise(o.void()).or(o.void())}));import*as l from"zod";import*as y from"zod";var C=y.object({before:n.optional(),after:n}).strict(),R=y.object({current:n.optional(),proposed:b}).strict(),g=y.object({current:n.optional(),proposed:U}).strict();var p=e=>l.strictObject({collection:F,key:H,data:e}),E=t(p(C)),B=t(l.array(p(C))),f=t(p(n.optional())),T=t(l.array(p(n.optional()))),u=t(l.array(p(n.optional()))),w=t(p(R)),I=t(p(g));import*as D from"zod";var S=D.record(D.string(),D.string());import*as k from"zod";import*as K from"zod";var P=K.object({current:r.optional(),batch:M,commit_batch:j}).strict();var J=t(r),N=t(r.optional()),$=t(k.array(r.optional())),q=t(k.array(r.optional())),G=t(P),L=t(r);var O=e=>A.extend({assert:_(e)}).strict(),Q=O(w),V=O(I),W=O(G),X=O(L),nt=a.union([Q,V,W,X]),Y=e=>a.function({input:a.tuple([S]),output:e}),st=e=>a.union([e,c(Y(e))]);function rt(e){return e}import*as x from"zod";var s=e=>A.extend({run:Z(e)}).strict(),ee=s(E),te=s(B),Dt=s(f),At=s(T),yt=s(u),oe=s(J),ne=s(N),se=s($),re=s(q),St=x.union([ee,te,f,T,u,oe,ne,se,re]),ce=e=>x.function({input:x.tuple([S]),output:e}),Ot=e=>x.union([e,c(ce(e))]);function dt(e){return e}import{jsonReplacer as pe}from"@dfinity/utils";var d=e=>{let i=e.map(h=>typeof h=="object"?JSON.stringify(h,pe):h).join(" ");globalThis.__ic_cdk_print(i)};globalThis.console={info(...e){d(e)},log(...e){d(e)},warn(...e){d(e)},error(...e){d(e)}};var ae=()=>(__juno_satellite_random()>>>0)/4294967296;globalThis.Math.random=ae;export{L as AssertDeleteAssetContextSchema,X as AssertDeleteAssetSchema,I as AssertDeleteDocContextSchema,V as AssertDeleteDocSchema,st as AssertFnOrObjectSchema,Y as AssertFnSchema,_ as AssertFunctionSchema,nt as AssertSchema,w as AssertSetDocContextSchema,Q as AssertSetDocSchema,G as AssertUploadAssetContextSchema,W as AssertUploadAssetSchema,P as AssetAssertUploadSchema,fe as AssetEncodingSchema,Ce as AssetKeySchema,Te as AssetNoContentSchema,r as AssetSchema,M as BatchSchema,he as BlobSchema,F as CollectionSchema,A as CollectionsSchema,j as CommitBatchSchema,U as DelDocSchema,ye as DescriptionSchema,g as DocAssertDeleteSchema,R as DocAssertSetSchema,p as DocContextSchema,n as DocSchema,C as DocUpsertSchema,ue as FullPathSchema,de as HeaderFieldsSchema,t as HookContextSchema,Ot as HookFnOrObjectSchema,ce as HookFnSchema,St as HookSchema,H as KeySchema,Fe as ListMatcherSchema,be as ListOrderFieldSchema,Ue as ListOrderSchema,He as ListPaginateSchema,Me as ListParamsSchema,N as OnDeleteAssetContextSchema,ne as OnDeleteAssetSchema,f as OnDeleteDocContextSchema,Dt as OnDeleteDocSchema,q as OnDeleteFilteredAssetsContextSchema,re as OnDeleteFilteredAssetsSchema,u as OnDeleteFilteredDocsContextSchema,yt as OnDeleteFilteredDocsSchema,$ as OnDeleteManyAssetsContextSchema,se as OnDeleteManyAssetsSchema,T as OnDeleteManyDocsContextSchema,At as OnDeleteManyDocsSchema,E as OnSetDocContextSchema,ee as OnSetDocSchema,B as OnSetManyDocsContextSchema,te as OnSetManyDocsSchema,J as OnUploadAssetContextSchema,oe as OnUploadAssetSchema,ke as OptionAssetSchema,Oe as OptionDocSchema,le as PrincipalSchema,Se as RawDataSchema,me as RawPrincipalSchema,z as RawUserIdSchema,Z as RunFunctionSchema,S as SatelliteEnvSchema,b as SetDocSchema,ze as TimestampMatcherSchema,ie as TimestampSchema,xe as Uint8ArraySchema,Ae as UserIdSchema,De as VersionSchema,je as createListResultsSchema,rt as defineAssert,dt as defineHook};
|
|
2
2
|
//# sourceMappingURL=index.js.map
|