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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -44,7 +44,7 @@ export declare const SetDocStoreParamsSchema: z.ZodObject<{
44
44
  /**
45
45
  * The caller who initiate the document operation.
46
46
  */
47
- caller: z.ZodType<Uint8Array<ArrayBufferLike>, z.ZodTypeDef, Uint8Array<ArrayBufferLike>>;
47
+ caller: z.ZodUnion<[z.ZodType<Uint8Array<ArrayBufferLike>, z.ZodTypeDef, Uint8Array<ArrayBufferLike>>, z.ZodType<import("@dfinity/principal").Principal, z.ZodTypeDef, import("@dfinity/principal").Principal>]>;
48
48
  /**
49
49
  * The name of the collection where the document is stored.
50
50
  */
@@ -82,7 +82,7 @@ export declare const SetDocStoreParamsSchema: z.ZodObject<{
82
82
  version?: bigint | undefined;
83
83
  }>;
84
84
  }, "strict", z.ZodTypeAny, {
85
- caller: Uint8Array<ArrayBufferLike>;
85
+ caller: Uint8Array<ArrayBufferLike> | import("@dfinity/principal").Principal;
86
86
  collection: string;
87
87
  doc: {
88
88
  data: Uint8Array<ArrayBufferLike>;
@@ -91,7 +91,7 @@ export declare const SetDocStoreParamsSchema: z.ZodObject<{
91
91
  version?: bigint | undefined;
92
92
  };
93
93
  }, {
94
- caller: Uint8Array<ArrayBufferLike>;
94
+ caller: Uint8Array<ArrayBufferLike> | import("@dfinity/principal").Principal;
95
95
  collection: string;
96
96
  doc: {
97
97
  data: Uint8Array<ArrayBufferLike>;
@@ -1,4 +1,4 @@
1
- import type { RawData } from '../schemas/core';
1
+ import type { RawData } from '../schemas/db';
2
2
  /**
3
3
  * Decodes the raw data of a document into a JavaScript object.
4
4
  *
package/sdk.js CHANGED
@@ -1,2 +1,2 @@
1
- import{c as e,d as a,e as r,f as c,g as s,h as m}from"./chunk-OVO3T2DM.js";import*as t from"zod";var l=t.object({key:s,description:m.optional(),data:a,version:e.optional()}).strict(),S=t.object({caller:r,collection:c,doc:l}).strict();var R=o=>{S.parse(o);let{caller:i,collection:p,doc:n}=o,{key:_,...D}=n;__juno_satellite_datastore_set_doc_store(i,p,_,D)};import{jsonReplacer as f,jsonReviver as d}from"@dfinity/utils";var T=o=>JSON.parse(__juno_satellite_datastore_raw_data_to_text(o),d),u=o=>__juno_satellite_datastore_raw_data_from_text(JSON.stringify(o,f));export{l as SetDocSchema,S as SetDocStoreParamsSchema,T as decodeDocData,u as encodeDocData,R as setDocStore};
1
+ import{b as a,c as r,d as c,e as s,f as m,g as i,h as n}from"./chunk-LVVTFR6B.js";import"./chunk-CCKUQNB5.js";import{Principal as h}from"@dfinity/principal";import*as e from"zod";var f=e.object({key:m,description:i.optional(),data:n,version:a.optional()}).strict(),p=e.object({caller:r.or(c),collection:s,doc:f}).strict();var T=o=>{p.parse(o);let{caller:t,collection:S,doc:l}=o,{key:_,...D}=l,d=t instanceof h?t.toUint8Array():t;__juno_satellite_datastore_set_doc_store(d,S,_,D)};import{jsonReplacer as x,jsonReviver as y}from"@dfinity/utils";var U=o=>JSON.parse(__juno_satellite_datastore_raw_data_to_text(o),y),k=o=>__juno_satellite_datastore_raw_data_from_text(JSON.stringify(o,x));export{f as SetDocSchema,p as SetDocStoreParamsSchema,U as decodeDocData,k as encodeDocData,T as setDocStore};
2
2
  //# sourceMappingURL=sdk.js.map
package/sdk.js.map CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
- "sources": ["src/sdk/schemas/db.ts", "src/sdk/db.sdk.ts", "src/sdk/serializer.sdk.ts"],
4
- "sourcesContent": ["import * as z from 'zod';\nimport {\n CollectionSchema,\n KeySchema,\n RawDataSchema,\n RawUserIdSchema,\n VersionSchema\n} from '../../schemas/core';\nimport {DocDescriptionSchema} from '../../schemas/db';\n\n/**\n * @see SetDoc\n */\nexport const SetDocSchema = z\n .object({\n /**\n * The unique key identifying the document within the collection.\n */\n key: KeySchema,\n\n /**\n * An optional description of the document.\n */\n description: DocDescriptionSchema.optional(),\n\n /**\n * The raw data of the document.\n */\n data: RawDataSchema,\n\n /**\n * The expected version number to ensure consistency.\n * If provided, the operation will fail if the stored version does not match.\n */\n version: VersionSchema.optional()\n })\n .strict();\n\n/**\n * Represents a request to set or update a document.\n *\n * This is used when submitting new document data.\n */\nexport type SetDoc = z.infer<typeof SetDocSchema>;\n\n/**\n * @see SetDocStoreParams\n */\nexport const SetDocStoreParamsSchema = z\n .object({\n /**\n * The caller who initiate the document operation.\n */\n caller: RawUserIdSchema,\n\n /**\n * The name of the collection where the document is stored.\n */\n collection: CollectionSchema,\n\n /**\n * The data, key and other information required to create or update a document.\n */\n doc: SetDocSchema\n })\n .strict();\n\n/**\n * Represents the parameters required to store or update a document.\n *\n * This includes the document data along with metadata such as the caller,\n * collection, and key.\n */\nexport type SetDocStoreParams = z.infer<typeof SetDocStoreParamsSchema>;\n", "import {SetDocStoreParams, SetDocStoreParamsSchema} from './schemas/db';\n\n/**\n * Stores or updates a document in the datastore.\n *\n * The data must have been encoded - using encodeDocData - before calling this function.\n *\n * @param {SetDocStoreParams} params - The parameters required to store the document,\n * including the caller, collection, key, and document data.\n *\n * @throws {z.ZodError} If the provided parameters do not match the expected schema.\n * @throws {Error} If the Satellite fails at validating the submitted document before storing it.\n */\nexport const setDocStore = (params: SetDocStoreParams) => {\n SetDocStoreParamsSchema.parse(params);\n\n const {caller, collection, doc} = params;\n\n const {key, ...setDoc} = doc;\n\n __juno_satellite_datastore_set_doc_store(caller, collection, key, setDoc);\n};\n", "import {jsonReplacer, jsonReviver} from '@dfinity/utils';\nimport type {RawData} from '../schemas/core';\n\n/**\n * Decodes the raw data of a document into a JavaScript object.\n *\n * @template T The expected type of the decoded object.\n * @param {RawData} data - The raw data to be decoded.\n * @returns {T} The parsed JavaScript object.\n */\nexport const decodeDocData = <T>(data: RawData): T =>\n JSON.parse(__juno_satellite_datastore_raw_data_to_text(data), jsonReviver);\n\n/**\n * Encodes a JavaScript object into a raw data format to be applied to a document.\n *\n * @template T The type of the object to be encoded.\n * @param {T} data - The data to be encoded.\n * @returns {RawData} The serialized raw data.\n */\nexport const encodeDocData = <T>(data: T): RawData =>\n __juno_satellite_datastore_raw_data_from_text(JSON.stringify(data, jsonReplacer));\n"],
5
- "mappings": "2EAAA,UAAYA,MAAO,MAaZ,IAAMC,EACV,SAAO,CAIN,IAAKC,EAKL,YAAaC,EAAqB,SAAS,EAK3C,KAAMC,EAMN,QAASC,EAAc,SAAS,CAClC,CAAC,EACA,OAAO,EAYGC,EACV,SAAO,CAIN,OAAQC,EAKR,WAAYC,EAKZ,IAAKP,CACP,CAAC,EACA,OAAO,ECpDH,IAAMQ,EAAeC,GAA8B,CACxDC,EAAwB,MAAMD,CAAM,EAEpC,GAAM,CAAC,OAAAE,EAAQ,WAAAC,EAAY,IAAAC,CAAG,EAAIJ,EAE5B,CAAC,IAAAK,EAAK,GAAGC,CAAM,EAAIF,EAEzB,yCAAyCF,EAAQC,EAAYE,EAAKC,CAAM,CAC1E,ECrBA,OAAQ,gBAAAC,EAAc,eAAAC,MAAkB,iBAUjC,IAAMC,EAAoBC,GAC/B,KAAK,MAAM,4CAA4CA,CAAI,EAAGF,CAAW,EAS9DG,EAAoBD,GAC/B,8CAA8C,KAAK,UAAUA,EAAMH,CAAY,CAAC",
6
- "names": ["z", "SetDocSchema", "KeySchema", "DocDescriptionSchema", "RawDataSchema", "VersionSchema", "SetDocStoreParamsSchema", "RawUserIdSchema", "CollectionSchema", "setDocStore", "params", "SetDocStoreParamsSchema", "caller", "collection", "doc", "key", "setDoc", "jsonReplacer", "jsonReviver", "decodeDocData", "data", "encodeDocData"]
3
+ "sources": ["src/sdk/db.sdk.ts", "src/sdk/schemas/db.ts", "src/sdk/serializer.sdk.ts"],
4
+ "sourcesContent": ["import {Principal} from '@dfinity/principal';\nimport {SetDocStoreParams, SetDocStoreParamsSchema} from './schemas/db';\n\n/**\n * Stores or updates a document in the datastore.\n *\n * The data must have been encoded - using encodeDocData - before calling this function.\n *\n * @param {SetDocStoreParams} params - The parameters required to store the document,\n * including the caller, collection, key, and document data.\n *\n * @throws {z.ZodError} If the provided parameters do not match the expected schema.\n * @throws {Error} If the Satellite fails at validating the submitted document before storing it.\n */\nexport const setDocStore = (params: SetDocStoreParams) => {\n SetDocStoreParamsSchema.parse(params);\n\n const {caller: providedCaller, collection, doc} = params;\n\n const {key, ...setDoc} = doc;\n\n const caller =\n providedCaller instanceof Principal ? providedCaller.toUint8Array() : providedCaller;\n\n __juno_satellite_datastore_set_doc_store(caller, collection, key, setDoc);\n};\n", "import * as z from 'zod';\nimport {DocDescriptionSchema, RawDataSchema} from '../../schemas/db';\nimport {\n CollectionSchema,\n KeySchema,\n RawUserIdSchema,\n UserIdSchema,\n VersionSchema\n} from '../../schemas/satellite';\n\n/**\n * @see SetDoc\n */\nexport const SetDocSchema = z\n .object({\n /**\n * The unique key identifying the document within the collection.\n */\n key: KeySchema,\n\n /**\n * An optional description of the document.\n */\n description: DocDescriptionSchema.optional(),\n\n /**\n * The raw data of the document.\n */\n data: RawDataSchema,\n\n /**\n * The expected version number to ensure consistency.\n * If provided, the operation will fail if the stored version does not match.\n */\n version: VersionSchema.optional()\n })\n .strict();\n\n/**\n * Represents a request to set or update a document.\n *\n * This is used when submitting new document data.\n */\nexport type SetDoc = z.infer<typeof SetDocSchema>;\n\n/**\n * @see SetDocStoreParams\n */\nexport const SetDocStoreParamsSchema = z\n .object({\n /**\n * The caller who initiate the document operation.\n */\n caller: RawUserIdSchema.or(UserIdSchema),\n\n /**\n * The name of the collection where the document is stored.\n */\n collection: CollectionSchema,\n\n /**\n * The data, key and other information required to create or update a document.\n */\n doc: SetDocSchema\n })\n .strict();\n\n/**\n * Represents the parameters required to store or update a document.\n *\n * This includes the document data along with metadata such as the caller,\n * collection, and key.\n */\nexport type SetDocStoreParams = z.infer<typeof SetDocStoreParamsSchema>;\n", "import {jsonReplacer, jsonReviver} from '@dfinity/utils';\nimport type {RawData} from '../schemas/db';\n\n/**\n * Decodes the raw data of a document into a JavaScript object.\n *\n * @template T The expected type of the decoded object.\n * @param {RawData} data - The raw data to be decoded.\n * @returns {T} The parsed JavaScript object.\n */\nexport const decodeDocData = <T>(data: RawData): T =>\n JSON.parse(__juno_satellite_datastore_raw_data_to_text(data), jsonReviver);\n\n/**\n * Encodes a JavaScript object into a raw data format to be applied to a document.\n *\n * @template T The type of the object to be encoded.\n * @param {T} data - The data to be encoded.\n * @returns {RawData} The serialized raw data.\n */\nexport const encodeDocData = <T>(data: T): RawData =>\n __juno_satellite_datastore_raw_data_from_text(JSON.stringify(data, jsonReplacer));\n"],
5
+ "mappings": "8GAAA,OAAQ,aAAAA,MAAgB,qBCAxB,UAAYC,MAAO,MAaZ,IAAMC,EACV,SAAO,CAIN,IAAKC,EAKL,YAAaC,EAAqB,SAAS,EAK3C,KAAMC,EAMN,QAASC,EAAc,SAAS,CAClC,CAAC,EACA,OAAO,EAYGC,EACV,SAAO,CAIN,OAAQC,EAAgB,GAAGC,CAAY,EAKvC,WAAYC,EAKZ,IAAKR,CACP,CAAC,EACA,OAAO,EDnDH,IAAMS,EAAeC,GAA8B,CACxDC,EAAwB,MAAMD,CAAM,EAEpC,GAAM,CAAC,OAAQE,EAAgB,WAAAC,EAAY,IAAAC,CAAG,EAAIJ,EAE5C,CAAC,IAAAK,EAAK,GAAGC,CAAM,EAAIF,EAEnBG,EACJL,aAA0BM,EAAYN,EAAe,aAAa,EAAIA,EAExE,yCAAyCK,EAAQJ,EAAYE,EAAKC,CAAM,CAC1E,EEzBA,OAAQ,gBAAAG,EAAc,eAAAC,MAAkB,iBAUjC,IAAMC,EAAoBC,GAC/B,KAAK,MAAM,4CAA4CA,CAAI,EAAGF,CAAW,EAS9DG,EAAoBD,GAC/B,8CAA8C,KAAK,UAAUA,EAAMH,CAAY,CAAC",
6
+ "names": ["Principal", "z", "SetDocSchema", "KeySchema", "DocDescriptionSchema", "RawDataSchema", "VersionSchema", "SetDocStoreParamsSchema", "RawUserIdSchema", "UserIdSchema", "CollectionSchema", "setDocStore", "params", "SetDocStoreParamsSchema", "providedCaller", "collection", "doc", "key", "setDoc", "caller", "Principal", "jsonReplacer", "jsonReviver", "decodeDocData", "data", "encodeDocData"]
7
7
  }
package/src/global.d.ts CHANGED
@@ -1,4 +1,5 @@
1
- import type {RawData, RawPrincipal, RawUserId} from './schemas/core';
1
+ import {RawData} from './schemas/db';
2
+ import type {RawPrincipal, RawUserId} from './schemas/satellite';
2
3
  import type {SetDoc} from './sdk/schemas/db';
3
4
 
4
5
  declare global {
@@ -14,4 +15,9 @@ declare global {
14
15
 
15
16
  function __ic_cdk_id(): RawPrincipal;
16
17
  function __ic_cdk_print(msg: string): void;
18
+ function __ic_cdk_call_raw(
19
+ canisterId: RawPrincipal,
20
+ method: string,
21
+ args: Uint8Array<ArrayBuffer>
22
+ ): Promise<Uint8Array<ArrayBuffer>>;
17
23
  }
@@ -0,0 +1,2 @@
1
+ import { Principal } from '@dfinity/principal';
2
+ export declare const mockCanisterId: Principal;
package/chunk-OVO3T2DM.js DELETED
@@ -1,2 +0,0 @@
1
- import*as r from"zod";var i=r.custom(o=>o instanceof Uint8Array,{message:"Expected Uint8Array"});import*as e from"zod";var a=e.bigint(),c=e.bigint(),p=e.custom(o=>o instanceof Uint8Array,{message:"Expected Uint8Array"}),n=i,f=e.string(),h=e.string();import*as t from"zod";var m=t.string().max(1024),z=t.object({owner:n,data:p,description:m.optional(),created_at:a,updated_at:a,version:c.optional()}).strict();export{i as a,a as b,c,p as d,n as e,f,h as g,m as h,z as i};
2
- //# sourceMappingURL=chunk-OVO3T2DM.js.map
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["src/schemas/candid.ts", "src/schemas/core.ts", "src/schemas/db.ts"],
4
- "sourcesContent": ["import * as z from 'zod';\n\n/**\n * @see RawPrincipal\n */\nexport const RawPrincipalSchema = z.custom<Uint8Array>((val) => val instanceof Uint8Array, {\n message: 'Expected Uint8Array'\n});\n\n/**\n * Represents a raw principal identifier.\n *\n * Principals are unique identities used in authentication and authorization.\n */\nexport type RawPrincipal = z.infer<typeof RawPrincipalSchema>;\n", "import * as z from 'zod';\nimport {RawPrincipalSchema} from './candid';\n\n/**\n * @see Timestamp\n */\nexport const TimestampSchema = z.bigint();\n\n/**\n * Represents a timestamp in nanoseconds since the Unix epoch.\n *\n * Used for tracking when events occur, such as document creation and updates.\n */\nexport type Timestamp = z.infer<typeof TimestampSchema>;\n\n/**\n * @see Version\n */\nexport const VersionSchema = z.bigint();\n\n/**\n * Represents a version number for tracking changes.\n *\n * This is typically incremented with each update to ensure consistency.\n */\nexport type Version = z.infer<typeof VersionSchema>;\n\n/**\n * @see RawData\n */\nexport const RawDataSchema = z.custom<Uint8Array>((val) => val instanceof Uint8Array, {\n message: 'Expected Uint8Array'\n});\n\n/**\n * Represents raw binary data.\n *\n * This is used to store unstructured data in a document.\n */\nexport type RawData = z.infer<typeof RawDataSchema>;\n\n/**\n * @see RawUserId\n */\nexport const RawUserIdSchema = RawPrincipalSchema;\n\n/**\n * Represents a raw user identifier.\n *\n * This is a principal associated with a user.\n */\nexport type RawUserId = z.infer<typeof RawUserIdSchema>;\n\n/**\n * @see Collection\n */\nexport const CollectionSchema = z.string();\n\n/**\n * A collection name where data are stored.\n */\nexport type Collection = z.infer<typeof CollectionSchema>;\n\n/**\n * @see Key\n */\nexport const KeySchema = z.string();\n\n/**\n * A unique key identifier within a collection.\n */\nexport type Key = z.infer<typeof KeySchema>;\n", "import * as z from 'zod';\nimport {RawDataSchema, RawUserIdSchema, TimestampSchema, VersionSchema} from './core';\n\n/**\n * @see DocDescription\n */\nexport const DocDescriptionSchema = z.string().max(1024);\n\n/**\n * Represents a document description with a maximum length of 1024 characters.\n */\nexport type DocDescription = z.infer<typeof DocDescriptionSchema>;\n\n/**\n * @see Doc\n */\nexport const DocSchema = z\n .object({\n /**\n * The user who owns this document.\n */\n owner: RawUserIdSchema,\n\n /**\n * The raw data of the document.\n */\n data: RawDataSchema,\n\n /**\n * An optional description of the document.\n */\n description: DocDescriptionSchema.optional(),\n\n /**\n * The timestamp when the document was first created.\n */\n created_at: TimestampSchema,\n\n /**\n * The timestamp when the document was last updated.\n */\n updated_at: TimestampSchema,\n\n /**\n * The version number of the document, used for consistency checks.\n * If not provided, it's assumed to be the first version.\n */\n version: VersionSchema.optional()\n })\n .strict();\n\n/**\n * Represents a document stored in a collection.\n */\nexport type Doc = z.infer<typeof DocSchema>;\n"],
5
- "mappings": "AAAA,UAAYA,MAAO,MAKZ,IAAMC,EAAuB,SAAoBC,GAAQA,aAAe,WAAY,CACzF,QAAS,qBACX,CAAC,ECPD,UAAYC,MAAO,MAMZ,IAAMC,EAAoB,SAAO,EAY3BC,EAAkB,SAAO,EAYzBC,EAAkB,SAAoBC,GAAQA,aAAe,WAAY,CACpF,QAAS,qBACX,CAAC,EAYYC,EAAkBC,EAYlBC,EAAqB,SAAO,EAU5BC,EAAc,SAAO,EClElC,UAAYC,MAAO,MAMZ,IAAMC,EAAyB,SAAO,EAAE,IAAI,IAAI,EAU1CC,EACV,SAAO,CAIN,MAAOC,EAKP,KAAMC,EAKN,YAAaH,EAAqB,SAAS,EAK3C,WAAYI,EAKZ,WAAYA,EAMZ,QAASC,EAAc,SAAS,CAClC,CAAC,EACA,OAAO",
6
- "names": ["z", "RawPrincipalSchema", "val", "z", "TimestampSchema", "VersionSchema", "RawDataSchema", "val", "RawUserIdSchema", "RawPrincipalSchema", "CollectionSchema", "KeySchema", "z", "DocDescriptionSchema", "DocSchema", "RawUserIdSchema", "RawDataSchema", "TimestampSchema", "VersionSchema"]
7
- }
File without changes