@junobuild/functions 0.0.12 → 0.0.13-next-2025-04-01

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.
@@ -1,101 +1,59 @@
1
1
  import * as z from 'zod';
2
+ import { type DelDoc, type SetDoc } from '../../schemas/db';
3
+ import { type Collection, type Key, type RawUserId, type UserId } from '../../schemas/satellite';
2
4
  /**
3
- * @see SetDoc
5
+ * Represents the base parameters required to access the datastore and modify a document.
4
6
  */
5
- export declare const SetDocSchema: z.ZodObject<{
7
+ export interface DocStoreParams {
6
8
  /**
7
- * The unique key identifying the document within the collection.
8
- */
9
- key: z.ZodString;
10
- /**
11
- * An optional description of the document.
9
+ * The caller who initiate the document operation.
12
10
  */
13
- description: z.ZodOptional<z.ZodString>;
11
+ caller: RawUserId | UserId;
14
12
  /**
15
- * The raw data of the document.
13
+ * The name of the collection where the document is stored.
16
14
  */
17
- data: z.ZodType<Uint8Array<ArrayBufferLike>, z.ZodTypeDef, Uint8Array<ArrayBufferLike>>;
15
+ collection: Collection;
18
16
  /**
19
- * The expected version number to ensure consistency.
20
- * If provided, the operation will fail if the stored version does not match.
17
+ * The unique key identifying the document within the collection.
21
18
  */
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>;
19
+ key: Key;
20
+ }
40
21
  /**
41
22
  * @see SetDocStoreParams
42
23
  */
43
- export declare const SetDocStoreParamsSchema: z.ZodObject<{
44
- /**
45
- * The caller who initiate the document operation.
46
- */
24
+ export declare const SetDocStoreParamsSchema: z.ZodObject<z.objectUtil.extendShape<{
47
25
  caller: z.ZodUnion<[z.ZodType<Uint8Array<ArrayBufferLike>, z.ZodTypeDef, Uint8Array<ArrayBufferLike>>, z.ZodType<import("@dfinity/principal").Principal, z.ZodTypeDef, import("@dfinity/principal").Principal>]>;
48
- /**
49
- * The name of the collection where the document is stored.
50
- */
51
26
  collection: z.ZodString;
52
- /**
53
- * The data, key and other information required to create or update a document.
54
- */
27
+ key: z.ZodString;
28
+ }, {
55
29
  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
30
  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
- */
31
+ description: z.ZodOptional<z.ZodString>;
72
32
  version: z.ZodOptional<z.ZodBigInt>;
73
33
  }, "strict", z.ZodTypeAny, {
74
34
  data: Uint8Array<ArrayBufferLike>;
75
- key: string;
76
35
  description?: string | undefined;
77
36
  version?: bigint | undefined;
78
37
  }, {
79
38
  data: Uint8Array<ArrayBufferLike>;
80
- key: string;
81
39
  description?: string | undefined;
82
40
  version?: bigint | undefined;
83
41
  }>;
84
- }, "strict", z.ZodTypeAny, {
42
+ }>, "strict", z.ZodTypeAny, {
85
43
  caller: Uint8Array<ArrayBufferLike> | import("@dfinity/principal").Principal;
86
44
  collection: string;
45
+ key: string;
87
46
  doc: {
88
47
  data: Uint8Array<ArrayBufferLike>;
89
- key: string;
90
48
  description?: string | undefined;
91
49
  version?: bigint | undefined;
92
50
  };
93
51
  }, {
94
52
  caller: Uint8Array<ArrayBufferLike> | import("@dfinity/principal").Principal;
95
53
  collection: string;
54
+ key: string;
96
55
  doc: {
97
56
  data: Uint8Array<ArrayBufferLike>;
98
- key: string;
99
57
  description?: string | undefined;
100
58
  version?: bigint | undefined;
101
59
  };
@@ -106,4 +64,51 @@ export declare const SetDocStoreParamsSchema: z.ZodObject<{
106
64
  * This includes the document data along with metadata such as the caller,
107
65
  * collection, and key.
108
66
  */
109
- export type SetDocStoreParams = z.infer<typeof SetDocStoreParamsSchema>;
67
+ export type SetDocStoreParams = DocStoreParams & {
68
+ /**
69
+ * The data, optional description and version required to create or update a document.
70
+ */
71
+ doc: SetDoc;
72
+ };
73
+ /**
74
+ * @see DeleteDocStoreParams
75
+ */
76
+ export declare const DeleteDocStoreParamsSchema: z.ZodObject<z.objectUtil.extendShape<{
77
+ caller: z.ZodUnion<[z.ZodType<Uint8Array<ArrayBufferLike>, z.ZodTypeDef, Uint8Array<ArrayBufferLike>>, z.ZodType<import("@dfinity/principal").Principal, z.ZodTypeDef, import("@dfinity/principal").Principal>]>;
78
+ collection: z.ZodString;
79
+ key: z.ZodString;
80
+ }, {
81
+ doc: z.ZodObject<{
82
+ version: z.ZodOptional<z.ZodBigInt>;
83
+ }, "strict", z.ZodTypeAny, {
84
+ version?: bigint | undefined;
85
+ }, {
86
+ version?: bigint | undefined;
87
+ }>;
88
+ }>, "strict", z.ZodTypeAny, {
89
+ caller: Uint8Array<ArrayBufferLike> | import("@dfinity/principal").Principal;
90
+ collection: string;
91
+ key: string;
92
+ doc: {
93
+ version?: bigint | undefined;
94
+ };
95
+ }, {
96
+ caller: Uint8Array<ArrayBufferLike> | import("@dfinity/principal").Principal;
97
+ collection: string;
98
+ key: string;
99
+ doc: {
100
+ version?: bigint | undefined;
101
+ };
102
+ }>;
103
+ /**
104
+ * Represents the parameters required to delete a document.
105
+ *
106
+ * This includes the document version along with metadata such as the caller,
107
+ * collection, and key.
108
+ */
109
+ export type DeleteDocStoreParams = DocStoreParams & {
110
+ /**
111
+ * The version required to delete a document.
112
+ */
113
+ doc: DelDoc;
114
+ };
@@ -0,0 +1,10 @@
1
+ import { RawUserId, UserId } from '../../schemas/satellite';
2
+ /**
3
+ * Normalizes a user ID into a raw `Uint8Array` representation.
4
+ *
5
+ * @param {RawUserId | UserId} caller - The caller identity, either a raw `Uint8Array`
6
+ * or a `Principal` instance.
7
+ *
8
+ * @returns {RawUserId} The raw user ID as a `Uint8Array`.
9
+ */
10
+ export declare const normalizeCaller: (caller: RawUserId | UserId) => RawUserId;
package/sdk.d.ts CHANGED
@@ -1,3 +1,5 @@
1
+ export * from './sdk/controllers.sdk';
1
2
  export * from './sdk/db.sdk';
3
+ export * from './sdk/schemas/controllers';
2
4
  export * from './sdk/schemas/db';
3
5
  export * from './sdk/serializer.sdk';
package/sdk.js CHANGED
@@ -1,2 +1,2 @@
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};
1
+ import{a as c,c as s,d as n,e as _,f as S,k as C,l as x}from"./chunk-6G6FWQ45.js";import{b as d}from"./chunk-CCKUQNB5.js";import*as o from"zod";var P=o.enum(["write","admin"]),z=o.tuple([o.string(),o.string()]),R=o.object({metadata:o.array(z),created_at:c,updated_at:c,expires_at:c.optional(),scope:P}).strict(),U=o.tuple([d,R]),I=o.array(U),i=o.object({caller:s.or(n),controllers:I});import{Principal as w}from"@dfinity/principal";var l=e=>e instanceof w?e.toUint8Array():e;var B=()=>__juno_satellite_datastore_get_admin_controllers(),E=()=>__juno_satellite_datastore_get_controllers(),F=e=>{i.parse(e);let{caller:t,controllers:r}=e,a=l(t);return __juno_satellite_datastore_is_admin_controller(a,r)},G=e=>{i.parse(e);let{caller:t,controllers:r}=e,a=l(t);return __juno_satellite_datastore_is_controller(a,r)};import*as D from"zod";var f=D.object({caller:s.or(n),collection:_,key:S}),h=f.extend({doc:C}).strict(),y=f.extend({doc:x}).strict();var $=e=>{h.parse(e);let{caller:t,collection:r,key:a,doc:m}=e,p=l(t);__juno_satellite_datastore_set_doc_store(p,r,a,m)},ee=e=>{y.parse(e);let{caller:t,collection:r,key:a,doc:m}=e,p=l(t);__juno_satellite_datastore_delete_doc_store(p,r,a,m)};import{jsonReplacer as u,jsonReviver as j}from"@dfinity/utils";var re=e=>JSON.parse(__juno_satellite_datastore_raw_data_to_text(e),j),ae=e=>__juno_satellite_datastore_raw_data_from_text(JSON.stringify(e,u));export{i as ControllerCheckParamsSchema,U as ControllerRecordSchema,R as ControllerSchema,P as ControllerScopeSchema,I as ControllersSchema,y as DeleteDocStoreParamsSchema,z as MetadataSchema,h as SetDocStoreParamsSchema,re as decodeDocData,ee as deleteDocStore,ae as encodeDocData,B as getAdminControllers,E as getControllers,F as isAdminController,G as isController,$ 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/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"]
3
+ "sources": ["src/sdk/schemas/controllers.ts", "src/sdk/utils/caller.utils.ts", "src/sdk/controllers.sdk.ts", "src/sdk/schemas/db.ts", "src/sdk/db.sdk.ts", "src/sdk/serializer.sdk.ts"],
4
+ "sourcesContent": ["import * as z from 'zod';\nimport {RawPrincipalSchema} from '../../schemas/candid';\nimport {\n RawUserId,\n RawUserIdSchema,\n Timestamp,\n TimestampSchema,\n UserId,\n UserIdSchema\n} from '../../schemas/satellite';\n\n/**\n * @see ControllerScopeSchema\n */\nexport const ControllerScopeSchema = z.enum(['write', 'admin']);\n\n/**\n * Represents the permission scope of a controller.\n */\nexport type ControllerScope = z.infer<typeof ControllerScopeSchema>;\n\n/**\n * @see MetadataSchema\n */\nexport const MetadataSchema = z.tuple([z.string(), z.string()]);\n\n/**\n * Represents a single metadata entry as a key-value tuple.\n */\nexport type Metadata = z.infer<typeof MetadataSchema>;\n\n/**\n * @see ControllerSchema\n */\nexport const ControllerSchema = z\n .object({\n metadata: z.array(MetadataSchema),\n created_at: TimestampSchema,\n updated_at: TimestampSchema,\n expires_at: TimestampSchema.optional(),\n scope: ControllerScopeSchema\n })\n .strict();\n\n/**\n * Represents a controller with access scope and associated metadata.\n */\nexport interface Controller {\n /**\n * A list of key-value metadata pairs associated with the controller.\n */\n metadata: Metadata[];\n\n /**\n * The timestamp when the controller was created.\n */\n created_at: Timestamp;\n\n /**\n * The timestamp when the controller was last updated.\n */\n updated_at: Timestamp;\n\n /**\n * Optional expiration timestamp for the controller.\n * \uD83D\uDC49 It's a placeholder for future implementation.\n */\n expires_at?: Timestamp;\n\n /**\n * The scope assigned to the controller.\n */\n scope: ControllerScope;\n}\n\n/**\n * @see ControllerRecordSchema\n */\nexport const ControllerRecordSchema = z.tuple([RawPrincipalSchema, ControllerSchema]);\n\n/**\n * Represents a tuple containing the principal ID and associated controller data.\n */\nexport type ControllerRecord = z.infer<typeof ControllerRecordSchema>;\n\n/**\n * @see ControllersSchema\n */\nexport const ControllersSchema = z.array(ControllerRecordSchema);\n\n/**\n * Represents a list of controllers.\n */\nexport type Controllers = z.infer<typeof ControllersSchema>;\n\n/**\n * @see ControllerCheckParamsSchema\n */\nexport const ControllerCheckParamsSchema = z.object({\n caller: RawUserIdSchema.or(UserIdSchema),\n controllers: ControllersSchema\n});\n\n/**\n * Represents the parameters required to perform controller checks.\n */\nexport interface ControllerCheckParams {\n /**\n * The identity of the caller to verify against the controller list.\n */\n caller: RawUserId | UserId;\n\n /**\n * The list of controllers to check against.\n */\n controllers: Controllers;\n}\n", "import {Principal} from '@dfinity/principal';\nimport {RawUserId, UserId} from '../../schemas/satellite';\n\n/**\n * Normalizes a user ID into a raw `Uint8Array` representation.\n *\n * @param {RawUserId | UserId} caller - The caller identity, either a raw `Uint8Array`\n * or a `Principal` instance.\n *\n * @returns {RawUserId} The raw user ID as a `Uint8Array`.\n */\nexport const normalizeCaller = (caller: RawUserId | UserId): RawUserId => caller instanceof Principal ? caller.toUint8Array() : caller;\n", "import {\n ControllerCheckParams,\n ControllerCheckParamsSchema,\n Controllers\n} from './schemas/controllers';\nimport {normalizeCaller} from './utils/caller.utils';\n\n/**\n * Gets the list of admin controllers from the Satellite.\n *\n * @returns {Controllers} The list of admin controllers.\n *\n * @throws {z.ZodError} If the returned value does not match the expected schema.\n */\nexport const getAdminControllers = (): Controllers =>\n __juno_satellite_datastore_get_admin_controllers();\n\n/**\n * Gets the list of controllers from the Satellite.\n *\n * @returns {Controllers} The list of all controllers.\n *\n * @throws {z.ZodError} If the returned value does not match the expected schema.\n */\nexport const getControllers = (): Controllers => __juno_satellite_datastore_get_controllers();\n\n/**\n * Checks if the given caller is an admin among the provided controllers.\n *\n * @param {ControllerCheckParams} params - The parameters including the caller identity\n * and the list of controllers to verify against.\n *\n * @returns {boolean} Whether the caller is an admin.\n *\n * @throws {z.ZodError} If any input does not match the expected schema.\n */\nexport const isAdminController = (params: ControllerCheckParams): boolean => {\n ControllerCheckParamsSchema.parse(params);\n\n const {caller: providedCaller, controllers} = params;\n\n const caller = normalizeCaller(providedCaller);\n\n return __juno_satellite_datastore_is_admin_controller(caller, controllers);\n};\n\n/**\n * Checks if the given caller exists among the provided controllers.\n *\n * @param {ControllerCheckParams} params - The parameters including the caller identity\n * and the list of controllers to verify against.\n *\n * @returns {boolean} Whether the caller is a controller.\n *\n * @throws {z.ZodError} If any input does not match the expected schema.\n */\nexport const isController = (params: ControllerCheckParams): boolean => {\n ControllerCheckParamsSchema.parse(params);\n\n const {caller: providedCaller, controllers} = params;\n\n const caller = normalizeCaller(providedCaller);\n\n return __juno_satellite_datastore_is_controller(caller, controllers);\n};\n", "import * as z from 'zod';\nimport {type DelDoc, DelDocSchema, type SetDoc, SetDocSchema} from '../../schemas/db';\nimport {\n type Collection,\n CollectionSchema,\n type Key,\n KeySchema,\n type RawUserId,\n RawUserIdSchema,\n type UserId,\n UserIdSchema\n} from '../../schemas/satellite';\n\n/**\n * @see DocStoreParams\n */\nconst DocStoreParamsSchema = z.object({\n caller: RawUserIdSchema.or(UserIdSchema),\n collection: CollectionSchema,\n key: KeySchema\n});\n\n/**\n * Represents the base parameters required to access the datastore and modify a document.\n */\nexport interface DocStoreParams {\n /**\n * The caller who initiate the document operation.\n */\n caller: RawUserId | UserId;\n\n /**\n * The name of the collection where the document is stored.\n */\n collection: Collection;\n\n /**\n * The unique key identifying the document within the collection.\n */\n key: Key;\n}\n\n/**\n * @see SetDocStoreParams\n */\nexport const SetDocStoreParamsSchema = DocStoreParamsSchema.extend({\n doc: SetDocSchema\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 = DocStoreParams & {\n /**\n * The data, optional description and version required to create or update a document.\n */\n doc: SetDoc;\n};\n\n/**\n * @see DeleteDocStoreParams\n */\nexport const DeleteDocStoreParamsSchema = DocStoreParamsSchema.extend({\n doc: DelDocSchema\n}).strict();\n\n/**\n * Represents the parameters required to delete a document.\n *\n * This includes the document version along with metadata such as the caller,\n * collection, and key.\n */\nexport type DeleteDocStoreParams = DocStoreParams & {\n /**\n * The version required to delete a document.\n */\n doc: DelDoc;\n};\n", "import {\n DeleteDocStoreParams,\n DeleteDocStoreParamsSchema,\n SetDocStoreParams,\n SetDocStoreParamsSchema\n} from './schemas/db';\nimport {normalizeCaller} from './utils/caller.utils';\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, key, doc} = params;\n\n const caller = normalizeCaller(providedCaller);\n\n __juno_satellite_datastore_set_doc_store(caller, collection, key, doc);\n};\n\n/**\n * Delete a document in the datastore.\n *\n * @param {DeleteDocStoreParams} params - The parameters required to delete the document,\n * including the caller, collection, key, and version of the document.\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 request before deleting it.\n */\nexport const deleteDocStore = (params: DeleteDocStoreParams) => {\n DeleteDocStoreParamsSchema.parse(params);\n\n const {caller: providedCaller, collection, key, doc} = params;\n\n const caller = normalizeCaller(providedCaller);\n\n __juno_satellite_datastore_delete_doc_store(caller, collection, key, doc);\n};\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": "0HAAA,UAAYA,MAAO,MAcZ,IAAMC,EAA0B,OAAK,CAAC,QAAS,OAAO,CAAC,EAUjDC,EAAmB,QAAM,CAAG,SAAO,EAAK,SAAO,CAAC,CAAC,EAUjDC,EACV,SAAO,CACN,SAAY,QAAMD,CAAc,EAChC,WAAYE,EACZ,WAAYA,EACZ,WAAYA,EAAgB,SAAS,EACrC,MAAOH,CACT,CAAC,EACA,OAAO,EAoCGI,EAA2B,QAAM,CAACC,EAAoBH,CAAgB,CAAC,EAUvEI,EAAsB,QAAMF,CAAsB,EAUlDG,EAAgC,SAAO,CAClD,OAAQC,EAAgB,GAAGC,CAAY,EACvC,YAAaH,CACf,CAAC,ECrGD,OAAQ,aAAAI,MAAgB,qBAWjB,IAAMC,EAAmBC,GAA0CA,aAAkBF,EAAYE,EAAO,aAAa,EAAIA,ECGzH,IAAMC,EAAsB,IACjC,iDAAiD,EAStCC,EAAiB,IAAmB,2CAA2C,EAY/EC,EAAqBC,GAA2C,CAC3EC,EAA4B,MAAMD,CAAM,EAExC,GAAM,CAAC,OAAQE,EAAgB,YAAAC,CAAW,EAAIH,EAExCI,EAASC,EAAgBH,CAAc,EAE7C,OAAO,+CAA+CE,EAAQD,CAAW,CAC3E,EAYaG,EAAgBN,GAA2C,CACtEC,EAA4B,MAAMD,CAAM,EAExC,GAAM,CAAC,OAAQE,EAAgB,YAAAC,CAAW,EAAIH,EAExCI,EAASC,EAAgBH,CAAc,EAE7C,OAAO,yCAAyCE,EAAQD,CAAW,CACrE,EChEA,UAAYI,MAAO,MAgBnB,IAAMC,EAAyB,SAAO,CACpC,OAAQC,EAAgB,GAAGC,CAAY,EACvC,WAAYC,EACZ,IAAKC,CACP,CAAC,EAyBYC,EAA0BL,EAAqB,OAAO,CACjE,IAAKM,CACP,CAAC,EAAE,OAAO,EAkBGC,EAA6BP,EAAqB,OAAO,CACpE,IAAKQ,CACP,CAAC,EAAE,OAAO,EChDH,IAAMC,EAAeC,GAA8B,CACxDC,EAAwB,MAAMD,CAAM,EAEpC,GAAM,CAAC,OAAQE,EAAgB,WAAAC,EAAY,IAAAC,EAAK,IAAAC,CAAG,EAAIL,EAEjDM,EAASC,EAAgBL,CAAc,EAE7C,yCAAyCI,EAAQH,EAAYC,EAAKC,CAAG,CACvE,EAWaG,GAAkBR,GAAiC,CAC9DS,EAA2B,MAAMT,CAAM,EAEvC,GAAM,CAAC,OAAQE,EAAgB,WAAAC,EAAY,IAAAC,EAAK,IAAAC,CAAG,EAAIL,EAEjDM,EAASC,EAAgBL,CAAc,EAE7C,4CAA4CI,EAAQH,EAAYC,EAAKC,CAAG,CAC1E,EC9CA,OAAQ,gBAAAK,EAAc,eAAAC,MAAkB,iBAUjC,IAAMC,GAAoBC,GAC/B,KAAK,MAAM,4CAA4CA,CAAI,EAAGF,CAAW,EAS9DG,GAAoBD,GAC/B,8CAA8C,KAAK,UAAUA,EAAMH,CAAY,CAAC",
6
+ "names": ["z", "ControllerScopeSchema", "MetadataSchema", "ControllerSchema", "TimestampSchema", "ControllerRecordSchema", "RawPrincipalSchema", "ControllersSchema", "ControllerCheckParamsSchema", "RawUserIdSchema", "UserIdSchema", "Principal", "normalizeCaller", "caller", "getAdminControllers", "getControllers", "isAdminController", "params", "ControllerCheckParamsSchema", "providedCaller", "controllers", "caller", "normalizeCaller", "isController", "z", "DocStoreParamsSchema", "RawUserIdSchema", "UserIdSchema", "CollectionSchema", "KeySchema", "SetDocStoreParamsSchema", "SetDocSchema", "DeleteDocStoreParamsSchema", "DelDocSchema", "setDocStore", "params", "SetDocStoreParamsSchema", "providedCaller", "collection", "key", "doc", "caller", "normalizeCaller", "deleteDocStore", "DeleteDocStoreParamsSchema", "jsonReplacer", "jsonReviver", "decodeDocData", "data", "encodeDocData"]
7
7
  }
package/src/global.d.ts CHANGED
@@ -1,16 +1,33 @@
1
- import {RawData} from './schemas/db';
2
- import type {RawPrincipal, RawUserId} from './schemas/satellite';
3
- import type {SetDoc} from './sdk/schemas/db';
1
+ import type {DelDoc, RawData, SetDoc} from './schemas/db';
2
+ import type {Collection, Key, RawPrincipal, RawUserId} from './schemas/satellite';
3
+ import {Controllers} from './sdk/schemas/controllers';
4
4
 
5
5
  declare global {
6
6
  function __juno_satellite_datastore_raw_data_to_text(data: RawData): string;
7
7
  function __juno_satellite_datastore_raw_data_from_text(data: string): RawData;
8
8
 
9
+ function __juno_satellite_datastore_get_admin_controllers(): Controllers;
10
+ function __juno_satellite_datastore_get_controllers(): Controllers;
11
+ function __juno_satellite_datastore_is_admin_controller(
12
+ caller: RawUserId,
13
+ controllers: Controllers
14
+ ): boolean;
15
+ function __juno_satellite_datastore_is_controller(
16
+ caller: RawUserId,
17
+ controllers: Controllers
18
+ ): boolean;
19
+
9
20
  function __juno_satellite_datastore_set_doc_store(
10
21
  caller: RawUserId,
11
- collection: string,
12
- key: string,
13
- value: Omit<SetDoc, 'key'>
22
+ collection: Collection,
23
+ key: Key,
24
+ value: SetDoc
25
+ ): void;
26
+ function __juno_satellite_datastore_delete_doc_store(
27
+ caller: RawUserId,
28
+ collection: Collection,
29
+ key: Key,
30
+ value: DelDoc
14
31
  ): void;
15
32
 
16
33
  function __ic_cdk_id(): RawPrincipal;
@@ -0,0 +1,4 @@
1
+ import { Principal } from '@dfinity/principal';
2
+ export declare const mockUserIdText = "xlmdg-vkosz-ceopx-7wtgu-g3xmd-koiyc-awqaq-7modz-zf6r6-364rh-oqe";
3
+ export declare const mockUserIdPrincipal: Principal;
4
+ export declare const mockRawUserId: Uint8Array<ArrayBufferLike>;
package/chunk-LVVTFR6B.js DELETED
@@ -1,2 +0,0 @@
1
- import{a as r,b as a,c as p}from"./chunk-CCKUQNB5.js";import*as e from"zod";var o=e.bigint(),c=e.bigint(),i=a,h=p,S=e.string(),f=e.string();import*as t from"zod";var m=t.string().max(1024),n=r,d=t.object({owner:i,data:n,description:m.optional(),created_at:o,updated_at:o,version:c.optional()}).strict();export{o as a,c as b,i as c,h as d,S as e,f,m as g,n as h,d as i};
2
- //# sourceMappingURL=chunk-LVVTFR6B.js.map
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["src/schemas/satellite.ts", "src/schemas/db.ts"],
4
- "sourcesContent": ["import * as z from 'zod';\nimport {PrincipalSchema, RawPrincipalSchema} from './candid';\n\n/**\n * @see Timestamp\n */\nexport const TimestampSchema = z.bigint();\n\n/**\n * Represents a timestamp in nanoseconds since the Unix epoch.\n *\n * Used for tracking when events occur, such as document creation and updates.\n */\nexport type Timestamp = z.infer<typeof TimestampSchema>;\n\n/**\n * @see Version\n */\nexport const VersionSchema = z.bigint();\n\n/**\n * Represents a version number for tracking changes.\n *\n * This is typically incremented with each update to ensure consistency.\n */\nexport type Version = z.infer<typeof VersionSchema>;\n\n/**\n * @see RawUserId\n */\nexport const RawUserIdSchema = RawPrincipalSchema;\n\n/**\n * Represents a raw user identifier.\n *\n * This is a principal associated with a user.\n */\nexport type RawUserId = z.infer<typeof RawUserIdSchema>;\n\n/**\n * @see UserId\n */\nexport const UserIdSchema = PrincipalSchema;\n\n/**\n * Represents a user identifier.\n *\n * This is a principal associated with a user.\n */\nexport type UserId = z.infer<typeof UserIdSchema>;\n\n/**\n * @see Collection\n */\nexport const CollectionSchema = z.string();\n\n/**\n * A collection name where data are stored.\n */\nexport type Collection = z.infer<typeof CollectionSchema>;\n\n/**\n * @see Key\n */\nexport const KeySchema = z.string();\n\n/**\n * A unique key identifier within a collection.\n */\nexport type Key = z.infer<typeof KeySchema>;\n", "import * as z from 'zod';\nimport {Uint8ArraySchema} from './candid';\nimport {RawUserIdSchema, TimestampSchema, VersionSchema} from './satellite';\n\n/**\n * @see DocDescription\n */\nexport const DocDescriptionSchema = z.string().max(1024);\n\n/**\n * Represents a document description with a maximum length of 1024 characters.\n */\nexport type DocDescription = z.infer<typeof DocDescriptionSchema>;\n\n/**\n * @see RawData\n */\nexport const RawDataSchema = Uint8ArraySchema;\n\n/**\n * Represents raw binary data.\n *\n * This is used to store structured data in a document.\n */\nexport type RawData = z.infer<typeof Uint8ArraySchema>;\n\n/**\n * @see Doc\n */\nexport const DocSchema = z\n .object({\n /**\n * The user who owns this document.\n */\n owner: RawUserIdSchema,\n\n /**\n * The raw data of the document.\n */\n data: RawDataSchema,\n\n /**\n * An optional description of the document.\n */\n description: DocDescriptionSchema.optional(),\n\n /**\n * The timestamp when the document was first created.\n */\n created_at: TimestampSchema,\n\n /**\n * The timestamp when the document was last updated.\n */\n updated_at: TimestampSchema,\n\n /**\n * The version number of the document, used for consistency checks.\n * If not provided, it's assumed to be the first version.\n */\n version: VersionSchema.optional()\n })\n .strict();\n\n/**\n * Represents a document stored in a collection.\n */\nexport type Doc = z.infer<typeof DocSchema>;\n"],
5
- "mappings": "sDAAA,UAAYA,MAAO,MAMZ,IAAMC,EAAoB,SAAO,EAY3BC,EAAkB,SAAO,EAYzBC,EAAkBC,EAYlBC,EAAeC,EAYfC,EAAqB,SAAO,EAU5BC,EAAc,SAAO,EChElC,UAAYC,MAAO,MAOZ,IAAMC,EAAyB,SAAO,EAAE,IAAI,IAAI,EAU1CC,EAAgBC,EAYhBC,EACV,SAAO,CAIN,MAAOC,EAKP,KAAMH,EAKN,YAAaD,EAAqB,SAAS,EAK3C,WAAYK,EAKZ,WAAYA,EAMZ,QAASC,EAAc,SAAS,CAClC,CAAC,EACA,OAAO",
6
- "names": ["z", "TimestampSchema", "VersionSchema", "RawUserIdSchema", "RawPrincipalSchema", "UserIdSchema", "PrincipalSchema", "CollectionSchema", "KeySchema", "z", "DocDescriptionSchema", "RawDataSchema", "Uint8ArraySchema", "DocSchema", "RawUserIdSchema", "TimestampSchema", "VersionSchema"]
7
- }