@junobuild/functions 0.0.5 → 0.0.6-next-2025-03-15

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
@@ -136,19 +136,31 @@ JavaScript and TypeScript utilities for [Juno] Serverless Functions.
136
136
 
137
137
  #### :gear: decodeDocData
138
138
 
139
+ Decodes the raw data of a document into a JavaScript object.
140
+
139
141
  | Function | Type |
140
142
  | --------------- | --------------------------------------------- |
141
143
  | `decodeDocData` | `<T>(data: Uint8Array<ArrayBufferLike>) => T` |
142
144
 
143
- [:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/sdk/datastore.sdk.ts#L4)
145
+ Parameters:
146
+
147
+ - `data`: - The raw data to be decoded.
148
+
149
+ [:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/sdk/serializer.sdk.ts#L11)
144
150
 
145
151
  #### :gear: encodeDocData
146
152
 
153
+ Encodes a JavaScript object into a raw data format to be applied to a document.
154
+
147
155
  | Function | Type |
148
156
  | --------------- | --------------------------------------------- |
149
157
  | `encodeDocData` | `<T>(data: T) => Uint8Array<ArrayBufferLike>` |
150
158
 
151
- [:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/sdk/datastore.sdk.ts#L7)
159
+ Parameters:
160
+
161
+ - `data`: - The data to be encoded.
162
+
163
+ [:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/sdk/serializer.sdk.ts#L21)
152
164
 
153
165
  ### :wrench: Constants
154
166
 
@@ -157,12 +169,13 @@ JavaScript and TypeScript utilities for [Juno] Serverless Functions.
157
169
  - [RawDataSchema](#gear-rawdataschema)
158
170
  - [RawPrincipalSchema](#gear-rawprincipalschema)
159
171
  - [RawUserIdSchema](#gear-rawuseridschema)
172
+ - [CollectionSchema](#gear-collectionschema)
173
+ - [KeySchema](#gear-keyschema)
160
174
  - [DocDescriptionSchema](#gear-docdescriptionschema)
161
175
  - [DocSchema](#gear-docschema)
162
176
  - [DocUpsertSchema](#gear-docupsertschema)
163
177
  - [ProposedDocSchema](#gear-proposeddocschema)
164
178
  - [DocAssertSetSchema](#gear-docassertsetschema)
165
- - [SetDocSchema](#gear-setdocschema)
166
179
  - [OnSetDocContextSchema](#gear-onsetdoccontextschema)
167
180
  - [AssertSetDocContextSchema](#gear-assertsetdoccontextschema)
168
181
  - [CollectionsConfigSchema](#gear-collectionsconfigschema)
@@ -212,6 +225,22 @@ JavaScript and TypeScript utilities for [Juno] Serverless Functions.
212
225
 
213
226
  [:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/hooks/core.ts#L58)
214
227
 
228
+ #### :gear: CollectionSchema
229
+
230
+ | Constant | Type |
231
+ | ------------------ | ----------- |
232
+ | `CollectionSchema` | `ZodString` |
233
+
234
+ [:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/hooks/core.ts#L70)
235
+
236
+ #### :gear: KeySchema
237
+
238
+ | Constant | Type |
239
+ | ----------- | ----------- |
240
+ | `KeySchema` | `ZodString` |
241
+
242
+ [:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/hooks/core.ts#L80)
243
+
215
244
  #### :gear: DocDescriptionSchema
216
245
 
217
246
  | Constant | Type |
@@ -252,14 +281,6 @@ JavaScript and TypeScript utilities for [Juno] Serverless Functions.
252
281
 
253
282
  [:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/hooks/datastore.ts#L113)
254
283
 
255
- #### :gear: SetDocSchema
256
-
257
- | Constant | Type |
258
- | -------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
259
- | `SetDocSchema` | `ZodObject<{ data: ZodType<Uint8Array<ArrayBufferLike>, ZodTypeDef, Uint8Array<ArrayBufferLike>>; description: ZodOptional<...>; version: ZodOptional<...>; }, "strict", ZodTypeAny, { ...; }, { ...; }>` |
260
-
261
- [:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/hooks/datastore.ts#L140)
262
-
263
284
  #### :gear: OnSetDocContextSchema
264
285
 
265
286
  | Constant | Type |
@@ -296,7 +317,7 @@ JavaScript and TypeScript utilities for [Juno] Serverless Functions.
296
317
 
297
318
  | Constant | Type |
298
319
  | -------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
299
- | `AssertSetDocSchema` | `ZodObject<extendShape<{ collections: ZodArray<ZodString, "many">; }, { assert: ZodFunction<ZodTuple<[ZodObject<{ caller: ZodType<Uint8Array<ArrayBufferLike>, ZodTypeDef, Uint8Array<...>>; data: ZodObject<...>; }, "strict", ZodTypeAny, { ...; }, { ...; }>], ZodUnknown>, ZodPromise<...>>; }>, "strict", ZodTypeAny, { ....` |
320
+ | `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, { ...; }, {...` |
300
321
 
301
322
  [:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/configs/assertions.ts#L25)
302
323
 
@@ -304,7 +325,7 @@ JavaScript and TypeScript utilities for [Juno] Serverless Functions.
304
325
 
305
326
  | Constant | Type |
306
327
  | -------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
307
- | `AssertSchema` | `ZodObject<extendShape<{ collections: ZodArray<ZodString, "many">; }, { assert: ZodFunction<ZodTuple<[ZodObject<{ caller: ZodType<Uint8Array<ArrayBufferLike>, ZodTypeDef, Uint8Array<...>>; data: ZodObject<...>; }, "strict", ZodTypeAny, { ...; }, { ...; }>], ZodUnknown>, ZodPromise<...>>; }>, "strict", ZodTypeAny, { ....` |
328
+ | `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, { ...; }, {...` |
308
329
 
309
330
  [:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/configs/assertions.ts#L36)
310
331
 
@@ -331,12 +352,13 @@ JavaScript and TypeScript utilities for [Juno] Serverless Functions.
331
352
  - [RawData](#gear-rawdata)
332
353
  - [RawPrincipal](#gear-rawprincipal)
333
354
  - [RawUserId](#gear-rawuserid)
355
+ - [Collection](#gear-collection)
356
+ - [Key](#gear-key)
334
357
  - [DocDescription](#gear-docdescription)
335
358
  - [Doc](#gear-doc)
336
359
  - [DocUpsert](#gear-docupsert)
337
360
  - [ProposedDoc](#gear-proposeddoc)
338
361
  - [DocAssertSet](#gear-docassertset)
339
- - [SetDoc](#gear-setdoc)
340
362
  - [HookContext](#gear-hookcontext)
341
363
  - [DocContext](#gear-doccontext)
342
364
  - [OnSetDocContext](#gear-onsetdoccontext)
@@ -412,6 +434,26 @@ This is a principal associated with a user.
412
434
 
413
435
  [:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/hooks/core.ts#L65)
414
436
 
437
+ #### :gear: Collection
438
+
439
+ A collection name where data are stored.
440
+
441
+ | Type | Type |
442
+ | ------------ | ---------------------------------- |
443
+ | `Collection` | `z.infer<typeof CollectionSchema>` |
444
+
445
+ [:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/hooks/core.ts#L75)
446
+
447
+ #### :gear: Key
448
+
449
+ A unique key identifier within a collection.
450
+
451
+ | Type | Type |
452
+ | ----- | --------------------------- |
453
+ | `Key` | `z.infer<typeof KeySchema>` |
454
+
455
+ [:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/hooks/core.ts#L85)
456
+
415
457
  #### :gear: DocDescription
416
458
 
417
459
  Represents a document description with a maximum length of 1024 characters.
@@ -468,18 +510,6 @@ throw an error if their validation fails.
468
510
 
469
511
  [:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/hooks/datastore.ts#L135)
470
512
 
471
- #### :gear: SetDoc
472
-
473
- Represents a request to set or update a document.
474
-
475
- This is used when submitting new document data.
476
-
477
- | Type | Type |
478
- | -------- | ------------------------------ |
479
- | `SetDoc` | `z.infer<typeof SetDocSchema>` |
480
-
481
- [:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/hooks/datastore.ts#L165)
482
-
483
513
  #### :gear: HookContext
484
514
 
485
515
  Represents the context provided to hooks, containing information about the caller and related data.
@@ -1,2 +1,2 @@
1
- import*as t from"zod";import*as s from"zod";import*as n from"zod";var T=n.bigint(),p=n.bigint(),a=n.custom(e=>e instanceof Uint8Array,{message:"Expected Uint8Array"}),j=n.custom(e=>e instanceof Uint8Array,{message:"Expected Uint8Array"}),i=j;import*as r from"zod";var z=r.string().max(1024),d=r.object({owner:i,data:a,description:z.optional(),created_at:T,updated_at:T,version:p.optional()}).strict(),h=r.object({before:d.optional(),after:d}).strict(),H=r.object({data:a,description:z.optional(),version:p.optional()}).strict(),l=r.object({current:d.optional(),proposed:H}).strict(),P=r.object({data:a,description:z.optional(),version:p.optional()}).strict();var A=e=>s.object({caller:i,data:e}).strict(),D=e=>s.object({collection:s.string(),key:s.string(),data:e}).strict(),O=A(D(h)),k=A(D(l));import*as c from"zod";var m=c.object({collections:c.array(c.string()).min(1)}).strict();import*as x from"zod";var f=x.record(x.unknown());var _=e=>m.extend({assert:t.function().args(e).returns(t.promise(t.void()))}).strict(),b=_(k),M=b,C=e=>t.function().args(f).returns(e),Q=e=>t.union([e,C(e)]);function W(e){return e}import*as o from"zod";var g=e=>m.extend({run:o.function().args(e).returns(o.promise(o.void()))}).strict(),F=g(O),te=F,w=e=>o.function().args(f).returns(e),oe=e=>o.union([e,w(e)]);function re(e){return e}import{jsonReplacer as R,jsonReviver as U}from"@dfinity/utils";var ce=e=>JSON.parse(__juno_satellite_datastore_raw_data_to_text(e),U),pe=e=>__juno_satellite_datastore_raw_data_from_text(JSON.stringify(e,R));import{jsonReplacer as v}from"@dfinity/utils";var S=e=>{let u=e.map(y=>typeof y=="object"?JSON.stringify(y,v):y).join(" ");globalThis.__ic_cdk_print(u)};globalThis.console={info(...e){S(e)},log(...e){S(e)},warn(...e){S(e)},error(...e){S(e)}};export{Q as AssertFnOrObjectSchema,C as AssertFnSchema,M as AssertSchema,k as AssertSetDocContextSchema,b as AssertSetDocSchema,m as CollectionsConfigSchema,l as DocAssertSetSchema,D as DocContextSchema,z as DocDescriptionSchema,d as DocSchema,h as DocUpsertSchema,oe as HookFnOrObjectSchema,w as HookFnSchema,te as HookSchema,O as OnSetDocContextSchema,F as OnSetDocSchema,H as ProposedDocSchema,a as RawDataSchema,j as RawPrincipalSchema,i as RawUserIdSchema,f as SatelliteEnvSchema,P as SetDocSchema,T as TimestampSchema,p as VersionSchema,ce as decodeDocData,W as defineAssert,re as defineHook,pe as encodeDocData};
1
+ import*as n from"zod";import*as d from"zod";import*as t from"zod";var f=t.bigint(),y=t.bigint(),S=t.custom(e=>e instanceof Uint8Array,{message:"Expected Uint8Array"}),j=t.custom(e=>e instanceof Uint8Array,{message:"Expected Uint8Array"}),c=j,h=t.string(),z=t.string();import*as r from"zod";var l=r.string().max(1024),T=r.object({owner:c,data:S,description:l.optional(),created_at:f,updated_at:f,version:y.optional()}).strict(),A=r.object({before:T.optional(),after:T}).strict(),_=r.object({data:S,description:l.optional(),version:y.optional()}).strict(),D=r.object({current:T.optional(),proposed:_}).strict();var O=e=>d.object({caller:c,data:e}).strict(),k=e=>d.object({collection:h,key:z,data:e}).strict(),u=O(k(A)),C=O(k(D));import*as s from"zod";var p=s.object({collections:s.array(s.string()).min(1)}).strict();import*as a from"zod";var i=a.record(a.unknown());var b=e=>p.extend({assert:n.function().args(e).returns(n.void())}).strict(),g=b(C),Q=g,F=e=>n.function().args(i).returns(e),W=e=>n.union([e,F(e)]);function X(e){return e}import*as o from"zod";var w=e=>p.extend({run:o.function().args(e).returns(o.promise(o.void()))}).strict(),R=w(u),oe=R,U=e=>o.function().args(i).returns(e),re=e=>o.union([e,U(e)]);function ne(e){return e}import{jsonReplacer as v,jsonReviver as Z}from"@dfinity/utils";var pe=e=>JSON.parse(__juno_satellite_datastore_raw_data_to_text(e),Z),ae=e=>__juno_satellite_datastore_raw_data_from_text(JSON.stringify(e,v));import{jsonReplacer as E}from"@dfinity/utils";var m=e=>{let H=e.map(x=>typeof x=="object"?JSON.stringify(x,E):x).join(" ");globalThis.__ic_cdk_print(H)};globalThis.console={info(...e){m(e)},log(...e){m(e)},warn(...e){m(e)},error(...e){m(e)}};export{W as AssertFnOrObjectSchema,F as AssertFnSchema,Q as AssertSchema,C as AssertSetDocContextSchema,g as AssertSetDocSchema,h as CollectionSchema,p as CollectionsConfigSchema,D as DocAssertSetSchema,k as DocContextSchema,l as DocDescriptionSchema,T as DocSchema,A as DocUpsertSchema,re as HookFnOrObjectSchema,U as HookFnSchema,oe as HookSchema,z as KeySchema,u as OnSetDocContextSchema,R as OnSetDocSchema,_ as ProposedDocSchema,S as RawDataSchema,j as RawPrincipalSchema,c as RawUserIdSchema,i as SatelliteEnvSchema,f as TimestampSchema,y as VersionSchema,pe as decodeDocData,X as defineAssert,ne as defineHook,ae as encodeDocData};
2
2
  //# sourceMappingURL=index.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
- "sources": ["../../src/configs/assertions.ts", "../../src/hooks/context.ts", "../../src/hooks/core.ts", "../../src/hooks/datastore.ts", "../../src/configs/collections.config.ts", "../../src/configs/satellite.env.ts", "../../src/configs/hooks.ts", "../../src/sdk/datastore.sdk.ts", "../../src/polyfills/console.polyfill.ts"],
4
- "sourcesContent": ["import * as z from 'zod';\nimport {AssertSetDocContextSchema} from '../hooks/context';\nimport {CollectionsConfigSchema} from './collections.config';\nimport {SatelliteEnvSchema} from './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 CollectionsConfigSchema.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 {Promise<void>} Resolves when the operation completes.\n */\n assert: z.function().args(contextSchema).returns(z.promise(z.void()))\n }).strict();\n\n/**\n * @see AssertSetDoc\n */\nexport const AssertSetDocSchema = OnAssertSchema(AssertSetDocContextSchema);\n\n/**\n * An assertion that runs when a document is created or updated.\n */\nexport type AssertSetDoc = z.infer<typeof AssertSetDocSchema>;\n\n// TODO: to be extended\n/**\n * @see Assert\n */\nexport const AssertSchema = AssertSetDocSchema;\n\n/**\n * All assertions definitions.\n */\nexport type Assert = z.infer<typeof AssertSchema>;\n\nexport const AssertFnSchema = <T extends z.ZodTypeAny>(assertSchema: T) =>\n z.function().args(SatelliteEnvSchema).returns(assertSchema);\nexport type AssertFn<T extends Assert> = (assert: z.infer<typeof SatelliteEnvSchema>) => T;\n\nexport const AssertFnOrObjectSchema = <T extends z.ZodTypeAny>(assertSchema: T) =>\n z.union([assertSchema, AssertFnSchema(assertSchema)]);\nexport type AssertFnOrObject<T extends Assert> = T | AssertFn<T>;\n\nexport function defineAssert<T extends Assert>(assert: T): T;\nexport function defineAssert<T extends Assert>(assert: AssertFn<T>): AssertFn<T>;\nexport function defineAssert<T extends Assert>(assert: AssertFnOrObject<T>): AssertFnOrObject<T>;\nexport function defineAssert<T extends Assert>(assert: AssertFnOrObject<T>): AssertFnOrObject<T> {\n return assert;\n}\n", "import * as z from 'zod';\nimport {RawUserIdSchema} from './core';\nimport {DocAssertSetSchema, DocUpsertSchema} from './datastore';\n\n/**\n * @see HookContext\n */\nconst 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 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: z.string(),\n\n /**\n * The unique key identifying the document within the collection.\n */\n key: z.string(),\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';\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 RawPrincipal\n */\nexport const RawPrincipalSchema = z.custom<Uint8Array>((val) => val instanceof Uint8Array, {\n message: 'Expected Uint8Array'\n});\n\n/**\n * Represents a raw principal identifier.\n *\n * Principals are unique identities used in authentication and authorization.\n */\nexport type RawPrincipal = z.infer<typeof RawPrincipalSchema>;\n\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", "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\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\n/**\n * @see SetDoc\n */\nexport const SetDocSchema = 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 * 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", "import * as z from 'zod';\n\n/**\n * @see CollectionsConfig\n */\nexport const CollectionsConfigSchema = 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 CollectionsConfig = z.infer<typeof CollectionsConfigSchema>;\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 {OnSetDocContextSchema} from '../hooks/context';\nimport {CollectionsConfigSchema} from './collections.config';\nimport {SatelliteEnvSchema} from './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 CollectionsConfigSchema.extend({\n /**\n * A function that runs when the hook is triggered for the specified collections.\n *\n * @param {T} context - Contains information about the affected document(s).\n * @returns {Promise<void>} Resolves when the operation completes.\n */\n run: z.function().args(contextSchema).returns(z.promise(z.void()))\n }).strict();\n\n/**\n * @see OnSetDoc\n */\nexport const OnSetDocSchema = OnHookSchema(OnSetDocContextSchema);\n\n/**\n * A hook that runs when a document is created or updated.\n */\nexport type OnSetDoc = z.infer<typeof OnSetDocSchema>;\n\n// TODO: to be extended\n/**\n * @see Hook\n */\nexport const HookSchema = OnSetDocSchema;\n\n/**\n * All hooks definitions.\n */\nexport type Hook = z.infer<typeof HookSchema>;\n\nexport const HookFnSchema = <T extends z.ZodTypeAny>(hookSchema: T) =>\n z.function().args(SatelliteEnvSchema).returns(hookSchema);\nexport type HookFn<T extends Hook> = (hook: z.infer<typeof SatelliteEnvSchema>) => T;\n\nexport const HookFnOrObjectSchema = <T extends z.ZodTypeAny>(hookSchema: T) =>\n z.union([hookSchema, HookFnSchema(hookSchema)]);\nexport type HookFnOrObject<T extends Hook> = T | HookFn<T>;\n\nexport function defineHook<T extends Hook>(hook: T): T;\nexport function defineHook<T extends Hook>(hook: HookFn<T>): HookFn<T>;\nexport function defineHook<T extends Hook>(hook: HookFnOrObject<T>): HookFnOrObject<T>;\nexport function defineHook<T extends Hook>(hook: HookFnOrObject<T>): HookFnOrObject<T> {\n return hook;\n}\n", "import {jsonReplacer, jsonReviver} from '@dfinity/utils';\nimport type {RawData} from '../hooks/core';\n\nexport const decodeDocData = <T>(data: RawData): T =>\n JSON.parse(__juno_satellite_datastore_raw_data_to_text(data), jsonReviver);\n\nexport const encodeDocData = <T>(data: T): RawData =>\n __juno_satellite_datastore_raw_data_from_text(JSON.stringify(data, jsonReplacer));\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": "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",
6
- "names": ["z", "z", "z", "TimestampSchema", "VersionSchema", "RawDataSchema", "val", "RawPrincipalSchema", "RawUserIdSchema", "z", "DocDescriptionSchema", "DocSchema", "RawUserIdSchema", "RawDataSchema", "TimestampSchema", "VersionSchema", "DocUpsertSchema", "ProposedDocSchema", "DocAssertSetSchema", "SetDocSchema", "HookContextSchema", "dataSchema", "RawUserIdSchema", "DocContextSchema", "OnSetDocContextSchema", "DocUpsertSchema", "AssertSetDocContextSchema", "DocAssertSetSchema", "z", "CollectionsConfigSchema", "z", "SatelliteEnvSchema", "OnAssertSchema", "contextSchema", "CollectionsConfigSchema", "AssertSetDocSchema", "AssertSetDocContextSchema", "AssertSchema", "AssertFnSchema", "assertSchema", "SatelliteEnvSchema", "AssertFnOrObjectSchema", "defineAssert", "assert", "z", "OnHookSchema", "contextSchema", "CollectionsConfigSchema", "OnSetDocSchema", "OnSetDocContextSchema", "HookSchema", "HookFnSchema", "hookSchema", "SatelliteEnvSchema", "HookFnOrObjectSchema", "defineHook", "hook", "jsonReplacer", "jsonReviver", "decodeDocData", "data", "encodeDocData", "jsonReplacer", "__juno_satellite_console_log", "v", "msg", "arg"]
3
+ "sources": ["../../src/configs/assertions.ts", "../../src/hooks/context.ts", "../../src/hooks/core.ts", "../../src/hooks/datastore.ts", "../../src/configs/collections.config.ts", "../../src/configs/satellite.env.ts", "../../src/configs/hooks.ts", "../../src/sdk/serializer.sdk.ts", "../../src/polyfills/console.polyfill.ts"],
4
+ "sourcesContent": ["import * as z from 'zod';\nimport {AssertSetDocContextSchema} from '../hooks/context';\nimport {CollectionsConfigSchema} from './collections.config';\nimport {SatelliteEnvSchema} from './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 CollectionsConfigSchema.extend({\n /**\n * A function that runs when the assertion is triggered for the specified collections.\n *\n * @param {T} context - Contains information about the affected document(s).\n * @returns {void} Resolves when the assertion completes.\n */\n assert: z.function().args(contextSchema).returns(z.void())\n }).strict();\n\n/**\n * @see AssertSetDoc\n */\nexport const AssertSetDocSchema = OnAssertSchema(AssertSetDocContextSchema);\n\n/**\n * An assertion that runs when a document is created or updated.\n */\nexport type AssertSetDoc = z.infer<typeof AssertSetDocSchema>;\n\n// TODO: to be extended\n/**\n * @see Assert\n */\nexport const AssertSchema = AssertSetDocSchema;\n\n/**\n * All assertions definitions.\n */\nexport type Assert = z.infer<typeof AssertSchema>;\n\nexport const AssertFnSchema = <T extends z.ZodTypeAny>(assertSchema: T) =>\n z.function().args(SatelliteEnvSchema).returns(assertSchema);\nexport type AssertFn<T extends Assert> = (assert: z.infer<typeof SatelliteEnvSchema>) => T;\n\nexport const AssertFnOrObjectSchema = <T extends z.ZodTypeAny>(assertSchema: T) =>\n z.union([assertSchema, AssertFnSchema(assertSchema)]);\nexport type AssertFnOrObject<T extends Assert> = T | AssertFn<T>;\n\nexport function defineAssert<T extends Assert>(assert: T): T;\nexport function defineAssert<T extends Assert>(assert: AssertFn<T>): AssertFn<T>;\nexport function defineAssert<T extends Assert>(assert: AssertFnOrObject<T>): AssertFnOrObject<T>;\nexport function defineAssert<T extends Assert>(assert: AssertFnOrObject<T>): AssertFnOrObject<T> {\n return assert;\n}\n", "import * as z from 'zod';\nimport {CollectionSchema, KeySchema, RawUserIdSchema} from './core';\nimport {DocAssertSetSchema, DocUpsertSchema} from './datastore';\n\n/**\n * @see HookContext\n */\nconst 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 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';\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 RawPrincipal\n */\nexport const RawPrincipalSchema = z.custom<Uint8Array>((val) => val instanceof Uint8Array, {\n message: 'Expected Uint8Array'\n});\n\n/**\n * Represents a raw principal identifier.\n *\n * Principals are unique identities used in authentication and authorization.\n */\nexport type RawPrincipal = z.infer<typeof RawPrincipalSchema>;\n\n/**\n * @see RawUserId\n */\nexport const RawUserIdSchema = RawPrincipalSchema;\n\n/**\n * Represents a raw user identifier.\n *\n * This is a principal associated with a user.\n */\nexport type RawUserId = z.infer<typeof RawUserIdSchema>;\n\n/**\n * @see Collection\n */\nexport const CollectionSchema = z.string();\n\n/**\n * A collection name where data are stored.\n */\nexport type Collection = z.infer<typeof CollectionSchema>;\n\n/**\n * @see Key\n */\nexport const KeySchema = z.string();\n\n/**\n * A unique key identifier within a collection.\n */\nexport type Key = z.infer<typeof KeySchema>;\n", "import * as z from 'zod';\nimport {RawDataSchema, RawUserIdSchema, TimestampSchema, VersionSchema} from './core';\n\n/**\n * @see DocDescription\n */\nexport const DocDescriptionSchema = z.string().max(1024);\n\n/**\n * Represents a document description with a maximum length of 1024 characters.\n */\nexport type DocDescription = z.infer<typeof DocDescriptionSchema>;\n\n/**\n * @see Doc\n */\nexport const DocSchema = z\n .object({\n /**\n * The user who owns this document.\n */\n owner: RawUserIdSchema,\n\n /**\n * The raw data of the document.\n */\n data: RawDataSchema,\n\n /**\n * An optional description of the document.\n */\n description: DocDescriptionSchema.optional(),\n\n /**\n * The timestamp when the document was first created.\n */\n created_at: TimestampSchema,\n\n /**\n * The timestamp when the document was last updated.\n */\n updated_at: TimestampSchema,\n\n /**\n * The version number of the document, used for consistency checks.\n * If not provided, it's assumed to be the first version.\n */\n version: VersionSchema.optional()\n })\n .strict();\n\n/**\n * Represents a document stored in a collection.\n */\nexport type Doc = z.infer<typeof DocSchema>;\n\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 CollectionsConfig\n */\nexport const CollectionsConfigSchema = 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 CollectionsConfig = z.infer<typeof CollectionsConfigSchema>;\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 {OnSetDocContextSchema} from '../hooks/context';\nimport {CollectionsConfigSchema} from './collections.config';\nimport {SatelliteEnvSchema} from './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 CollectionsConfigSchema.extend({\n /**\n * A function that runs when the hook is triggered for the specified collections.\n *\n * @param {T} context - Contains information about the affected document(s).\n * @returns {Promise<void>} Resolves when the operation completes.\n */\n run: z.function().args(contextSchema).returns(z.promise(z.void()))\n }).strict();\n\n/**\n * @see OnSetDoc\n */\nexport const OnSetDocSchema = OnHookSchema(OnSetDocContextSchema);\n\n/**\n * A hook that runs when a document is created or updated.\n */\nexport type OnSetDoc = z.infer<typeof OnSetDocSchema>;\n\n// TODO: to be extended\n/**\n * @see Hook\n */\nexport const HookSchema = OnSetDocSchema;\n\n/**\n * All hooks definitions.\n */\nexport type Hook = z.infer<typeof HookSchema>;\n\nexport const HookFnSchema = <T extends z.ZodTypeAny>(hookSchema: T) =>\n z.function().args(SatelliteEnvSchema).returns(hookSchema);\nexport type HookFn<T extends Hook> = (hook: z.infer<typeof SatelliteEnvSchema>) => T;\n\nexport const HookFnOrObjectSchema = <T extends z.ZodTypeAny>(hookSchema: T) =>\n z.union([hookSchema, HookFnSchema(hookSchema)]);\nexport type HookFnOrObject<T extends Hook> = T | HookFn<T>;\n\nexport function defineHook<T extends Hook>(hook: T): T;\nexport function defineHook<T extends Hook>(hook: HookFn<T>): HookFn<T>;\nexport function defineHook<T extends Hook>(hook: HookFnOrObject<T>): HookFnOrObject<T>;\nexport function defineHook<T extends Hook>(hook: HookFnOrObject<T>): HookFnOrObject<T> {\n return hook;\n}\n", "import {jsonReplacer, jsonReviver} from '@dfinity/utils';\nimport type {RawData} from '../hooks/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", "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": "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",
6
+ "names": ["z", "z", "z", "TimestampSchema", "VersionSchema", "RawDataSchema", "val", "RawPrincipalSchema", "RawUserIdSchema", "CollectionSchema", "KeySchema", "z", "DocDescriptionSchema", "DocSchema", "RawUserIdSchema", "RawDataSchema", "TimestampSchema", "VersionSchema", "DocUpsertSchema", "ProposedDocSchema", "DocAssertSetSchema", "HookContextSchema", "dataSchema", "RawUserIdSchema", "DocContextSchema", "CollectionSchema", "KeySchema", "OnSetDocContextSchema", "DocUpsertSchema", "AssertSetDocContextSchema", "DocAssertSetSchema", "z", "CollectionsConfigSchema", "z", "SatelliteEnvSchema", "OnAssertSchema", "contextSchema", "CollectionsConfigSchema", "AssertSetDocSchema", "AssertSetDocContextSchema", "AssertSchema", "AssertFnSchema", "assertSchema", "SatelliteEnvSchema", "AssertFnOrObjectSchema", "defineAssert", "assert", "z", "OnHookSchema", "contextSchema", "CollectionsConfigSchema", "OnSetDocSchema", "OnSetDocContextSchema", "HookSchema", "HookFnSchema", "hookSchema", "SatelliteEnvSchema", "HookFnOrObjectSchema", "defineHook", "hook", "jsonReplacer", "jsonReviver", "decodeDocData", "data", "encodeDocData", "jsonReplacer", "__juno_satellite_console_log", "v", "msg", "arg"]
7
7
  }
@@ -10,7 +10,7 @@ export declare const AssertSetDocSchema: z.ZodObject<z.objectUtil.extendShape<{
10
10
  * A function that runs when the assertion is triggered for the specified collections.
11
11
  *
12
12
  * @param {T} context - Contains information about the affected document(s).
13
- * @returns {Promise<void>} Resolves when the operation completes.
13
+ * @returns {void} Resolves when the assertion completes.
14
14
  */
15
15
  assert: z.ZodFunction<z.ZodTuple<[z.ZodObject<{
16
16
  caller: z.ZodType<Uint8Array<ArrayBufferLike>, z.ZodTypeDef, Uint8Array<ArrayBufferLike>>;
@@ -98,8 +98,8 @@ export declare const AssertSetDocSchema: z.ZodObject<z.objectUtil.extendShape<{
98
98
  version?: bigint | undefined;
99
99
  } | undefined;
100
100
  };
101
- collection: string;
102
101
  key: string;
102
+ collection: string;
103
103
  }, {
104
104
  data: {
105
105
  proposed: {
@@ -116,8 +116,8 @@ export declare const AssertSetDocSchema: z.ZodObject<z.objectUtil.extendShape<{
116
116
  version?: bigint | undefined;
117
117
  } | undefined;
118
118
  };
119
- collection: string;
120
119
  key: string;
120
+ collection: string;
121
121
  }>;
122
122
  }, "strict", z.ZodTypeAny, {
123
123
  data: {
@@ -136,8 +136,8 @@ export declare const AssertSetDocSchema: z.ZodObject<z.objectUtil.extendShape<{
136
136
  version?: bigint | undefined;
137
137
  } | undefined;
138
138
  };
139
- collection: string;
140
139
  key: string;
140
+ collection: string;
141
141
  };
142
142
  caller: Uint8Array<ArrayBufferLike>;
143
143
  }, {
@@ -157,11 +157,11 @@ export declare const AssertSetDocSchema: z.ZodObject<z.objectUtil.extendShape<{
157
157
  version?: bigint | undefined;
158
158
  } | undefined;
159
159
  };
160
- collection: string;
161
160
  key: string;
161
+ collection: string;
162
162
  };
163
163
  caller: Uint8Array<ArrayBufferLike>;
164
- }>], z.ZodUnknown>, z.ZodPromise<z.ZodVoid>>;
164
+ }>], z.ZodUnknown>, z.ZodVoid>;
165
165
  }>, "strict", z.ZodTypeAny, {
166
166
  collections: string[];
167
167
  assert: (args_0: {
@@ -181,11 +181,11 @@ export declare const AssertSetDocSchema: z.ZodObject<z.objectUtil.extendShape<{
181
181
  version?: bigint | undefined;
182
182
  } | undefined;
183
183
  };
184
- collection: string;
185
184
  key: string;
185
+ collection: string;
186
186
  };
187
187
  caller: Uint8Array<ArrayBufferLike>;
188
- }, ...args: unknown[]) => Promise<void>;
188
+ }, ...args: unknown[]) => void;
189
189
  }, {
190
190
  collections: string[];
191
191
  assert: (args_0: {
@@ -205,11 +205,11 @@ export declare const AssertSetDocSchema: z.ZodObject<z.objectUtil.extendShape<{
205
205
  version?: bigint | undefined;
206
206
  } | undefined;
207
207
  };
208
- collection: string;
209
208
  key: string;
209
+ collection: string;
210
210
  };
211
211
  caller: Uint8Array<ArrayBufferLike>;
212
- }, ...args: unknown[]) => Promise<void>;
212
+ }, ...args: unknown[]) => void;
213
213
  }>;
214
214
  /**
215
215
  * An assertion that runs when a document is created or updated.
@@ -225,7 +225,7 @@ export declare const AssertSchema: z.ZodObject<z.objectUtil.extendShape<{
225
225
  * A function that runs when the assertion is triggered for the specified collections.
226
226
  *
227
227
  * @param {T} context - Contains information about the affected document(s).
228
- * @returns {Promise<void>} Resolves when the operation completes.
228
+ * @returns {void} Resolves when the assertion completes.
229
229
  */
230
230
  assert: z.ZodFunction<z.ZodTuple<[z.ZodObject<{
231
231
  caller: z.ZodType<Uint8Array<ArrayBufferLike>, z.ZodTypeDef, Uint8Array<ArrayBufferLike>>;
@@ -313,8 +313,8 @@ export declare const AssertSchema: z.ZodObject<z.objectUtil.extendShape<{
313
313
  version?: bigint | undefined;
314
314
  } | undefined;
315
315
  };
316
- collection: string;
317
316
  key: string;
317
+ collection: string;
318
318
  }, {
319
319
  data: {
320
320
  proposed: {
@@ -331,8 +331,8 @@ export declare const AssertSchema: z.ZodObject<z.objectUtil.extendShape<{
331
331
  version?: bigint | undefined;
332
332
  } | undefined;
333
333
  };
334
- collection: string;
335
334
  key: string;
335
+ collection: string;
336
336
  }>;
337
337
  }, "strict", z.ZodTypeAny, {
338
338
  data: {
@@ -351,8 +351,8 @@ export declare const AssertSchema: z.ZodObject<z.objectUtil.extendShape<{
351
351
  version?: bigint | undefined;
352
352
  } | undefined;
353
353
  };
354
- collection: string;
355
354
  key: string;
355
+ collection: string;
356
356
  };
357
357
  caller: Uint8Array<ArrayBufferLike>;
358
358
  }, {
@@ -372,11 +372,11 @@ export declare const AssertSchema: z.ZodObject<z.objectUtil.extendShape<{
372
372
  version?: bigint | undefined;
373
373
  } | undefined;
374
374
  };
375
- collection: string;
376
375
  key: string;
376
+ collection: string;
377
377
  };
378
378
  caller: Uint8Array<ArrayBufferLike>;
379
- }>], z.ZodUnknown>, z.ZodPromise<z.ZodVoid>>;
379
+ }>], z.ZodUnknown>, z.ZodVoid>;
380
380
  }>, "strict", z.ZodTypeAny, {
381
381
  collections: string[];
382
382
  assert: (args_0: {
@@ -396,11 +396,11 @@ export declare const AssertSchema: z.ZodObject<z.objectUtil.extendShape<{
396
396
  version?: bigint | undefined;
397
397
  } | undefined;
398
398
  };
399
- collection: string;
400
399
  key: string;
400
+ collection: string;
401
401
  };
402
402
  caller: Uint8Array<ArrayBufferLike>;
403
- }, ...args: unknown[]) => Promise<void>;
403
+ }, ...args: unknown[]) => void;
404
404
  }, {
405
405
  collections: string[];
406
406
  assert: (args_0: {
@@ -420,11 +420,11 @@ export declare const AssertSchema: z.ZodObject<z.objectUtil.extendShape<{
420
420
  version?: bigint | undefined;
421
421
  } | undefined;
422
422
  };
423
- collection: string;
424
423
  key: string;
424
+ collection: string;
425
425
  };
426
426
  caller: Uint8Array<ArrayBufferLike>;
427
- }, ...args: unknown[]) => Promise<void>;
427
+ }, ...args: unknown[]) => void;
428
428
  }>;
429
429
  /**
430
430
  * All assertions definitions.
@@ -116,8 +116,8 @@ export declare const OnSetDocSchema: z.ZodObject<z.objectUtil.extendShape<{
116
116
  version?: bigint | undefined;
117
117
  } | undefined;
118
118
  };
119
- collection: string;
120
119
  key: string;
120
+ collection: string;
121
121
  }, {
122
122
  data: {
123
123
  after: {
@@ -137,8 +137,8 @@ export declare const OnSetDocSchema: z.ZodObject<z.objectUtil.extendShape<{
137
137
  version?: bigint | undefined;
138
138
  } | undefined;
139
139
  };
140
- collection: string;
141
140
  key: string;
141
+ collection: string;
142
142
  }>;
143
143
  }, "strict", z.ZodTypeAny, {
144
144
  data: {
@@ -160,8 +160,8 @@ export declare const OnSetDocSchema: z.ZodObject<z.objectUtil.extendShape<{
160
160
  version?: bigint | undefined;
161
161
  } | undefined;
162
162
  };
163
- collection: string;
164
163
  key: string;
164
+ collection: string;
165
165
  };
166
166
  caller: Uint8Array<ArrayBufferLike>;
167
167
  }, {
@@ -184,8 +184,8 @@ export declare const OnSetDocSchema: z.ZodObject<z.objectUtil.extendShape<{
184
184
  version?: bigint | undefined;
185
185
  } | undefined;
186
186
  };
187
- collection: string;
188
187
  key: string;
188
+ collection: string;
189
189
  };
190
190
  caller: Uint8Array<ArrayBufferLike>;
191
191
  }>], z.ZodUnknown>, z.ZodPromise<z.ZodVoid>>;
@@ -211,8 +211,8 @@ export declare const OnSetDocSchema: z.ZodObject<z.objectUtil.extendShape<{
211
211
  version?: bigint | undefined;
212
212
  } | undefined;
213
213
  };
214
- collection: string;
215
214
  key: string;
215
+ collection: string;
216
216
  };
217
217
  caller: Uint8Array<ArrayBufferLike>;
218
218
  }, ...args: unknown[]) => Promise<void>;
@@ -238,8 +238,8 @@ export declare const OnSetDocSchema: z.ZodObject<z.objectUtil.extendShape<{
238
238
  version?: bigint | undefined;
239
239
  } | undefined;
240
240
  };
241
- collection: string;
242
241
  key: string;
242
+ collection: string;
243
243
  };
244
244
  caller: Uint8Array<ArrayBufferLike>;
245
245
  }, ...args: unknown[]) => Promise<void>;
@@ -364,8 +364,8 @@ export declare const HookSchema: z.ZodObject<z.objectUtil.extendShape<{
364
364
  version?: bigint | undefined;
365
365
  } | undefined;
366
366
  };
367
- collection: string;
368
367
  key: string;
368
+ collection: string;
369
369
  }, {
370
370
  data: {
371
371
  after: {
@@ -385,8 +385,8 @@ export declare const HookSchema: z.ZodObject<z.objectUtil.extendShape<{
385
385
  version?: bigint | undefined;
386
386
  } | undefined;
387
387
  };
388
- collection: string;
389
388
  key: string;
389
+ collection: string;
390
390
  }>;
391
391
  }, "strict", z.ZodTypeAny, {
392
392
  data: {
@@ -408,8 +408,8 @@ export declare const HookSchema: z.ZodObject<z.objectUtil.extendShape<{
408
408
  version?: bigint | undefined;
409
409
  } | undefined;
410
410
  };
411
- collection: string;
412
411
  key: string;
412
+ collection: string;
413
413
  };
414
414
  caller: Uint8Array<ArrayBufferLike>;
415
415
  }, {
@@ -432,8 +432,8 @@ export declare const HookSchema: z.ZodObject<z.objectUtil.extendShape<{
432
432
  version?: bigint | undefined;
433
433
  } | undefined;
434
434
  };
435
- collection: string;
436
435
  key: string;
436
+ collection: string;
437
437
  };
438
438
  caller: Uint8Array<ArrayBufferLike>;
439
439
  }>], z.ZodUnknown>, z.ZodPromise<z.ZodVoid>>;
@@ -459,8 +459,8 @@ export declare const HookSchema: z.ZodObject<z.objectUtil.extendShape<{
459
459
  version?: bigint | undefined;
460
460
  } | undefined;
461
461
  };
462
- collection: string;
463
462
  key: string;
463
+ collection: string;
464
464
  };
465
465
  caller: Uint8Array<ArrayBufferLike>;
466
466
  }, ...args: unknown[]) => Promise<void>;
@@ -486,8 +486,8 @@ export declare const HookSchema: z.ZodObject<z.objectUtil.extendShape<{
486
486
  version?: bigint | undefined;
487
487
  } | undefined;
488
488
  };
489
- collection: string;
490
489
  key: string;
490
+ collection: string;
491
491
  };
492
492
  caller: Uint8Array<ArrayBufferLike>;
493
493
  }, ...args: unknown[]) => Promise<void>;
@@ -1,8 +1,16 @@
1
- import type {RawData} from './hooks/core';
1
+ import type {RawData, RawUserId} from './hooks/core';
2
+ import type {SetDoc} from './hooks/sdk';
2
3
 
3
4
  declare global {
4
5
  function __juno_satellite_datastore_raw_data_to_text(data: RawData): string;
5
6
  function __juno_satellite_datastore_raw_data_from_text(data: string): RawData;
6
7
 
8
+ function __juno_satellite_datastore_set_doc_store(
9
+ caller: RawUserId,
10
+ collection: string,
11
+ key: string,
12
+ value: Omit<SetDoc, 'key'>
13
+ ): void;
14
+
7
15
  function __ic_cdk_print(msg: string): void;
8
16
  }
@@ -251,8 +251,8 @@ export declare const OnSetDocContextSchema: z.ZodObject<{
251
251
  version?: bigint | undefined;
252
252
  } | undefined;
253
253
  };
254
- collection: string;
255
254
  key: string;
255
+ collection: string;
256
256
  }, {
257
257
  data: {
258
258
  after: {
@@ -272,8 +272,8 @@ export declare const OnSetDocContextSchema: z.ZodObject<{
272
272
  version?: bigint | undefined;
273
273
  } | undefined;
274
274
  };
275
- collection: string;
276
275
  key: string;
276
+ collection: string;
277
277
  }>;
278
278
  }, "strict", z.ZodTypeAny, {
279
279
  data: {
@@ -295,8 +295,8 @@ export declare const OnSetDocContextSchema: z.ZodObject<{
295
295
  version?: bigint | undefined;
296
296
  } | undefined;
297
297
  };
298
- collection: string;
299
298
  key: string;
299
+ collection: string;
300
300
  };
301
301
  caller: Uint8Array<ArrayBufferLike>;
302
302
  }, {
@@ -319,8 +319,8 @@ export declare const OnSetDocContextSchema: z.ZodObject<{
319
319
  version?: bigint | undefined;
320
320
  } | undefined;
321
321
  };
322
- collection: string;
323
322
  key: string;
323
+ collection: string;
324
324
  };
325
325
  caller: Uint8Array<ArrayBufferLike>;
326
326
  }>;
@@ -435,8 +435,8 @@ export declare const AssertSetDocContextSchema: z.ZodObject<{
435
435
  version?: bigint | undefined;
436
436
  } | undefined;
437
437
  };
438
- collection: string;
439
438
  key: string;
439
+ collection: string;
440
440
  }, {
441
441
  data: {
442
442
  proposed: {
@@ -453,8 +453,8 @@ export declare const AssertSetDocContextSchema: z.ZodObject<{
453
453
  version?: bigint | undefined;
454
454
  } | undefined;
455
455
  };
456
- collection: string;
457
456
  key: string;
457
+ collection: string;
458
458
  }>;
459
459
  }, "strict", z.ZodTypeAny, {
460
460
  data: {
@@ -473,8 +473,8 @@ export declare const AssertSetDocContextSchema: z.ZodObject<{
473
473
  version?: bigint | undefined;
474
474
  } | undefined;
475
475
  };
476
- collection: string;
477
476
  key: string;
477
+ collection: string;
478
478
  };
479
479
  caller: Uint8Array<ArrayBufferLike>;
480
480
  }, {
@@ -494,8 +494,8 @@ export declare const AssertSetDocContextSchema: z.ZodObject<{
494
494
  version?: bigint | undefined;
495
495
  } | undefined;
496
496
  };
497
- collection: string;
498
497
  key: string;
498
+ collection: string;
499
499
  };
500
500
  caller: Uint8Array<ArrayBufferLike>;
501
501
  }>;
@@ -49,3 +49,19 @@ export declare const RawUserIdSchema: z.ZodType<Uint8Array<ArrayBufferLike>, z.Z
49
49
  * This is a principal associated with a user.
50
50
  */
51
51
  export type RawUserId = z.infer<typeof RawUserIdSchema>;
52
+ /**
53
+ * @see Collection
54
+ */
55
+ export declare const CollectionSchema: z.ZodString;
56
+ /**
57
+ * A collection name where data are stored.
58
+ */
59
+ export type Collection = z.infer<typeof CollectionSchema>;
60
+ /**
61
+ * @see Key
62
+ */
63
+ export declare const KeySchema: z.ZodString;
64
+ /**
65
+ * A unique key identifier within a collection.
66
+ */
67
+ export type Key = z.infer<typeof KeySchema>;
@@ -330,35 +330,3 @@ export declare const DocAssertSetSchema: z.ZodObject<{
330
330
  * throw an error if their validation fails.
331
331
  */
332
332
  export type DocAssertSet = z.infer<typeof DocAssertSetSchema>;
333
- /**
334
- * @see SetDoc
335
- */
336
- export declare const SetDocSchema: z.ZodObject<{
337
- /**
338
- * The raw data of the document.
339
- */
340
- data: z.ZodType<Uint8Array<ArrayBufferLike>, z.ZodTypeDef, Uint8Array<ArrayBufferLike>>;
341
- /**
342
- * An optional description of the document.
343
- */
344
- description: z.ZodOptional<z.ZodString>;
345
- /**
346
- * The expected version number to ensure consistency.
347
- * If provided, the operation will fail if the stored version does not match.
348
- */
349
- version: z.ZodOptional<z.ZodBigInt>;
350
- }, "strict", z.ZodTypeAny, {
351
- data: Uint8Array<ArrayBufferLike>;
352
- description?: string | undefined;
353
- version?: bigint | undefined;
354
- }, {
355
- data: Uint8Array<ArrayBufferLike>;
356
- description?: string | undefined;
357
- version?: bigint | undefined;
358
- }>;
359
- /**
360
- * Represents a request to set or update a document.
361
- *
362
- * This is used when submitting new document data.
363
- */
364
- export type SetDoc = z.infer<typeof SetDocSchema>;
@@ -0,0 +1,109 @@
1
+ import * as z from 'zod';
2
+ /**
3
+ * @see SetDoc
4
+ */
5
+ export declare const SetDocSchema: z.ZodObject<{
6
+ /**
7
+ * The unique key identifying the document within the collection.
8
+ */
9
+ key: z.ZodString;
10
+ /**
11
+ * An optional description of the document.
12
+ */
13
+ description: z.ZodOptional<z.ZodString>;
14
+ /**
15
+ * The raw data of the document.
16
+ */
17
+ data: z.ZodType<Uint8Array<ArrayBufferLike>, z.ZodTypeDef, Uint8Array<ArrayBufferLike>>;
18
+ /**
19
+ * The expected version number to ensure consistency.
20
+ * If provided, the operation will fail if the stored version does not match.
21
+ */
22
+ version: z.ZodOptional<z.ZodBigInt>;
23
+ }, "strict", z.ZodTypeAny, {
24
+ data: Uint8Array<ArrayBufferLike>;
25
+ key: string;
26
+ description?: string | undefined;
27
+ version?: bigint | undefined;
28
+ }, {
29
+ data: Uint8Array<ArrayBufferLike>;
30
+ key: string;
31
+ description?: string | undefined;
32
+ version?: bigint | undefined;
33
+ }>;
34
+ /**
35
+ * Represents a request to set or update a document.
36
+ *
37
+ * This is used when submitting new document data.
38
+ */
39
+ export type SetDoc = z.infer<typeof SetDocSchema>;
40
+ /**
41
+ * @see SetDocStoreParams
42
+ */
43
+ export declare const SetDocStoreParamsSchema: z.ZodObject<{
44
+ /**
45
+ * The caller who initiate the document operation.
46
+ */
47
+ caller: z.ZodType<Uint8Array<ArrayBufferLike>, z.ZodTypeDef, Uint8Array<ArrayBufferLike>>;
48
+ /**
49
+ * The name of the collection where the document is stored.
50
+ */
51
+ collection: z.ZodString;
52
+ /**
53
+ * The data, key and other information required to create or update a document.
54
+ */
55
+ doc: z.ZodObject<{
56
+ /**
57
+ * The unique key identifying the document within the collection.
58
+ */
59
+ key: z.ZodString;
60
+ /**
61
+ * An optional description of the document.
62
+ */
63
+ description: z.ZodOptional<z.ZodString>;
64
+ /**
65
+ * The raw data of the document.
66
+ */
67
+ data: z.ZodType<Uint8Array<ArrayBufferLike>, z.ZodTypeDef, Uint8Array<ArrayBufferLike>>;
68
+ /**
69
+ * The expected version number to ensure consistency.
70
+ * If provided, the operation will fail if the stored version does not match.
71
+ */
72
+ version: z.ZodOptional<z.ZodBigInt>;
73
+ }, "strict", z.ZodTypeAny, {
74
+ data: Uint8Array<ArrayBufferLike>;
75
+ key: string;
76
+ description?: string | undefined;
77
+ version?: bigint | undefined;
78
+ }, {
79
+ data: Uint8Array<ArrayBufferLike>;
80
+ key: string;
81
+ description?: string | undefined;
82
+ version?: bigint | undefined;
83
+ }>;
84
+ }, "strict", z.ZodTypeAny, {
85
+ caller: Uint8Array<ArrayBufferLike>;
86
+ collection: string;
87
+ doc: {
88
+ data: Uint8Array<ArrayBufferLike>;
89
+ key: string;
90
+ description?: string | undefined;
91
+ version?: bigint | undefined;
92
+ };
93
+ }, {
94
+ caller: Uint8Array<ArrayBufferLike>;
95
+ collection: string;
96
+ doc: {
97
+ data: Uint8Array<ArrayBufferLike>;
98
+ key: string;
99
+ description?: string | undefined;
100
+ version?: bigint | undefined;
101
+ };
102
+ }>;
103
+ /**
104
+ * Represents the parameters required to store or update a document.
105
+ *
106
+ * This includes the document data along with metadata such as the caller,
107
+ * collection, and key.
108
+ */
109
+ export type SetDocStoreParams = z.infer<typeof SetDocStoreParamsSchema>;
@@ -5,5 +5,5 @@ export * from './configs/satellite.env';
5
5
  export * from './hooks/context';
6
6
  export * from './hooks/core';
7
7
  export * from './hooks/datastore';
8
- export * from './sdk/datastore.sdk';
8
+ export * from './sdk/serializer.sdk';
9
9
  import './polyfills/console.polyfill';
@@ -1,3 +1,13 @@
1
- import type { RawData } from '../hooks/core';
2
- export declare const decodeDocData: <T>(data: RawData) => T;
3
- export declare const encodeDocData: <T>(data: T) => RawData;
1
+ import { SetDocStoreParams } from '../hooks/sdk';
2
+ /**
3
+ * Stores or updates a document in the datastore.
4
+ *
5
+ * The data must have been encoded - using encodeDocData - before calling this function.
6
+ *
7
+ * @param {SetDocStoreParams} params - The parameters required to store the document,
8
+ * including the caller, collection, key, and document data.
9
+ *
10
+ * @throws {z.ZodError} If the provided parameters do not match the expected schema.
11
+ * @throws {Error} If the Satellite fails at validating the submitted document before storing it.
12
+ */
13
+ export declare const setDocStore: (params: SetDocStoreParams) => void;
@@ -0,0 +1,17 @@
1
+ import type { RawData } from '../hooks/core';
2
+ /**
3
+ * Decodes the raw data of a document into a JavaScript object.
4
+ *
5
+ * @template T The expected type of the decoded object.
6
+ * @param {RawData} data - The raw data to be decoded.
7
+ * @returns {T} The parsed JavaScript object.
8
+ */
9
+ export declare const decodeDocData: <T>(data: RawData) => T;
10
+ /**
11
+ * Encodes a JavaScript object into a raw data format to be applied to a document.
12
+ *
13
+ * @template T The type of the object to be encoded.
14
+ * @param {T} data - The data to be encoded.
15
+ * @returns {RawData} The serialized raw data.
16
+ */
17
+ export declare const encodeDocData: <T>(data: T) => RawData;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@junobuild/functions",
3
- "version": "0.0.5",
3
+ "version": "0.0.6-next-2025-03-15",
4
4
  "description": "JavaScript and TypeScript utilities for Juno Serverless Functions",
5
5
  "author": "David Dal Busco (https://daviddalbusco.com)",
6
6
  "license": "MIT",
@@ -37,7 +37,7 @@
37
37
  },
38
38
  "homepage": "https://juno.build",
39
39
  "peerDependencies": {
40
- "@dfinity/utils": "^2",
41
- "zod": "^3"
40
+ "@dfinity/utils": "*",
41
+ "zod": "*"
42
42
  }
43
- }
43
+ }