@junobuild/functions 0.0.13 → 0.0.14
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 +217 -26
- package/{chunk-6G6FWQ45.js → chunk-367GY4VX.js} +1 -1
- package/chunk-367GY4VX.js.map +7 -0
- package/global.d.ts +12 -0
- package/hooks/assertions.d.ts +40 -40
- package/hooks/schemas/db/context.d.ts +1 -1
- package/hooks/schemas/storage/context.d.ts +12 -12
- package/hooks/schemas/storage/payload.d.ts +4 -4
- package/index.js +1 -1
- package/index.js.map +1 -1
- package/package.json +1 -1
- package/schemas/satellite.d.ts +1 -1
- package/schemas/storage.d.ts +2 -2
- package/sdk/controllers.sdk.d.ts +39 -0
- package/sdk/schemas/controllers.d.ts +174 -0
- package/sdk/schemas/db.d.ts +1 -1
- package/sdk/utils/caller.utils.d.ts +10 -0
- package/sdk.d.ts +2 -0
- package/sdk.js +1 -1
- package/sdk.js.map +4 -4
- package/src/global.d.ts +12 -0
- package/tests/mocks/controllers.mocks.d.ts +4 -0
- package/chunk-6G6FWQ45.js.map +0 -7
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
import * as z from 'zod';
|
|
2
|
+
import { RawUserId, Timestamp, UserId } from '../../schemas/satellite';
|
|
3
|
+
/**
|
|
4
|
+
* @see ControllerScopeSchema
|
|
5
|
+
*/
|
|
6
|
+
export declare const ControllerScopeSchema: z.ZodEnum<["write", "admin"]>;
|
|
7
|
+
/**
|
|
8
|
+
* Represents the permission scope of a controller.
|
|
9
|
+
*/
|
|
10
|
+
export type ControllerScope = z.infer<typeof ControllerScopeSchema>;
|
|
11
|
+
/**
|
|
12
|
+
* @see MetadataSchema
|
|
13
|
+
*/
|
|
14
|
+
export declare const MetadataSchema: z.ZodTuple<[z.ZodString, z.ZodString], null>;
|
|
15
|
+
/**
|
|
16
|
+
* Represents a single metadata entry as a key-value tuple.
|
|
17
|
+
*/
|
|
18
|
+
export type Metadata = z.infer<typeof MetadataSchema>;
|
|
19
|
+
/**
|
|
20
|
+
* @see ControllerSchema
|
|
21
|
+
*/
|
|
22
|
+
export declare const ControllerSchema: z.ZodObject<{
|
|
23
|
+
metadata: z.ZodArray<z.ZodTuple<[z.ZodString, z.ZodString], null>, "many">;
|
|
24
|
+
created_at: z.ZodBigInt;
|
|
25
|
+
updated_at: z.ZodBigInt;
|
|
26
|
+
expires_at: z.ZodOptional<z.ZodBigInt>;
|
|
27
|
+
scope: z.ZodEnum<["write", "admin"]>;
|
|
28
|
+
}, "strict", z.ZodTypeAny, {
|
|
29
|
+
created_at: bigint;
|
|
30
|
+
updated_at: bigint;
|
|
31
|
+
metadata: [string, string][];
|
|
32
|
+
scope: "write" | "admin";
|
|
33
|
+
expires_at?: bigint | undefined;
|
|
34
|
+
}, {
|
|
35
|
+
created_at: bigint;
|
|
36
|
+
updated_at: bigint;
|
|
37
|
+
metadata: [string, string][];
|
|
38
|
+
scope: "write" | "admin";
|
|
39
|
+
expires_at?: bigint | undefined;
|
|
40
|
+
}>;
|
|
41
|
+
/**
|
|
42
|
+
* Represents a controller with access scope and associated metadata.
|
|
43
|
+
*/
|
|
44
|
+
export interface Controller {
|
|
45
|
+
/**
|
|
46
|
+
* A list of key-value metadata pairs associated with the controller.
|
|
47
|
+
*/
|
|
48
|
+
metadata: Metadata[];
|
|
49
|
+
/**
|
|
50
|
+
* The timestamp when the controller was created.
|
|
51
|
+
*/
|
|
52
|
+
created_at: Timestamp;
|
|
53
|
+
/**
|
|
54
|
+
* The timestamp when the controller was last updated.
|
|
55
|
+
*/
|
|
56
|
+
updated_at: Timestamp;
|
|
57
|
+
/**
|
|
58
|
+
* Optional expiration timestamp for the controller.
|
|
59
|
+
* 👉 It's a placeholder for future implementation.
|
|
60
|
+
*/
|
|
61
|
+
expires_at?: Timestamp;
|
|
62
|
+
/**
|
|
63
|
+
* The scope assigned to the controller.
|
|
64
|
+
*/
|
|
65
|
+
scope: ControllerScope;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* @see ControllerRecordSchema
|
|
69
|
+
*/
|
|
70
|
+
export declare const ControllerRecordSchema: z.ZodTuple<[z.ZodType<Uint8Array<ArrayBufferLike>, z.ZodTypeDef, Uint8Array<ArrayBufferLike>>, z.ZodObject<{
|
|
71
|
+
metadata: z.ZodArray<z.ZodTuple<[z.ZodString, z.ZodString], null>, "many">;
|
|
72
|
+
created_at: z.ZodBigInt;
|
|
73
|
+
updated_at: z.ZodBigInt;
|
|
74
|
+
expires_at: z.ZodOptional<z.ZodBigInt>;
|
|
75
|
+
scope: z.ZodEnum<["write", "admin"]>;
|
|
76
|
+
}, "strict", z.ZodTypeAny, {
|
|
77
|
+
created_at: bigint;
|
|
78
|
+
updated_at: bigint;
|
|
79
|
+
metadata: [string, string][];
|
|
80
|
+
scope: "write" | "admin";
|
|
81
|
+
expires_at?: bigint | undefined;
|
|
82
|
+
}, {
|
|
83
|
+
created_at: bigint;
|
|
84
|
+
updated_at: bigint;
|
|
85
|
+
metadata: [string, string][];
|
|
86
|
+
scope: "write" | "admin";
|
|
87
|
+
expires_at?: bigint | undefined;
|
|
88
|
+
}>], null>;
|
|
89
|
+
/**
|
|
90
|
+
* Represents a tuple containing the principal ID and associated controller data.
|
|
91
|
+
*/
|
|
92
|
+
export type ControllerRecord = z.infer<typeof ControllerRecordSchema>;
|
|
93
|
+
/**
|
|
94
|
+
* @see ControllersSchema
|
|
95
|
+
*/
|
|
96
|
+
export declare const ControllersSchema: z.ZodArray<z.ZodTuple<[z.ZodType<Uint8Array<ArrayBufferLike>, z.ZodTypeDef, Uint8Array<ArrayBufferLike>>, z.ZodObject<{
|
|
97
|
+
metadata: z.ZodArray<z.ZodTuple<[z.ZodString, z.ZodString], null>, "many">;
|
|
98
|
+
created_at: z.ZodBigInt;
|
|
99
|
+
updated_at: z.ZodBigInt;
|
|
100
|
+
expires_at: z.ZodOptional<z.ZodBigInt>;
|
|
101
|
+
scope: z.ZodEnum<["write", "admin"]>;
|
|
102
|
+
}, "strict", z.ZodTypeAny, {
|
|
103
|
+
created_at: bigint;
|
|
104
|
+
updated_at: bigint;
|
|
105
|
+
metadata: [string, string][];
|
|
106
|
+
scope: "write" | "admin";
|
|
107
|
+
expires_at?: bigint | undefined;
|
|
108
|
+
}, {
|
|
109
|
+
created_at: bigint;
|
|
110
|
+
updated_at: bigint;
|
|
111
|
+
metadata: [string, string][];
|
|
112
|
+
scope: "write" | "admin";
|
|
113
|
+
expires_at?: bigint | undefined;
|
|
114
|
+
}>], null>, "many">;
|
|
115
|
+
/**
|
|
116
|
+
* Represents a list of controllers.
|
|
117
|
+
*/
|
|
118
|
+
export type Controllers = z.infer<typeof ControllersSchema>;
|
|
119
|
+
/**
|
|
120
|
+
* @see ControllerCheckParamsSchema
|
|
121
|
+
*/
|
|
122
|
+
export declare const ControllerCheckParamsSchema: z.ZodObject<{
|
|
123
|
+
caller: z.ZodUnion<[z.ZodType<Uint8Array<ArrayBufferLike>, z.ZodTypeDef, Uint8Array<ArrayBufferLike>>, z.ZodType<import("@dfinity/principal").Principal, z.ZodTypeDef, import("@dfinity/principal").Principal>]>;
|
|
124
|
+
controllers: z.ZodArray<z.ZodTuple<[z.ZodType<Uint8Array<ArrayBufferLike>, z.ZodTypeDef, Uint8Array<ArrayBufferLike>>, z.ZodObject<{
|
|
125
|
+
metadata: z.ZodArray<z.ZodTuple<[z.ZodString, z.ZodString], null>, "many">;
|
|
126
|
+
created_at: z.ZodBigInt;
|
|
127
|
+
updated_at: z.ZodBigInt;
|
|
128
|
+
expires_at: z.ZodOptional<z.ZodBigInt>;
|
|
129
|
+
scope: z.ZodEnum<["write", "admin"]>;
|
|
130
|
+
}, "strict", z.ZodTypeAny, {
|
|
131
|
+
created_at: bigint;
|
|
132
|
+
updated_at: bigint;
|
|
133
|
+
metadata: [string, string][];
|
|
134
|
+
scope: "write" | "admin";
|
|
135
|
+
expires_at?: bigint | undefined;
|
|
136
|
+
}, {
|
|
137
|
+
created_at: bigint;
|
|
138
|
+
updated_at: bigint;
|
|
139
|
+
metadata: [string, string][];
|
|
140
|
+
scope: "write" | "admin";
|
|
141
|
+
expires_at?: bigint | undefined;
|
|
142
|
+
}>], null>, "many">;
|
|
143
|
+
}, "strip", z.ZodTypeAny, {
|
|
144
|
+
caller: Uint8Array<ArrayBufferLike> | import("@dfinity/principal").Principal;
|
|
145
|
+
controllers: [Uint8Array<ArrayBufferLike>, {
|
|
146
|
+
created_at: bigint;
|
|
147
|
+
updated_at: bigint;
|
|
148
|
+
metadata: [string, string][];
|
|
149
|
+
scope: "write" | "admin";
|
|
150
|
+
expires_at?: bigint | undefined;
|
|
151
|
+
}][];
|
|
152
|
+
}, {
|
|
153
|
+
caller: Uint8Array<ArrayBufferLike> | import("@dfinity/principal").Principal;
|
|
154
|
+
controllers: [Uint8Array<ArrayBufferLike>, {
|
|
155
|
+
created_at: bigint;
|
|
156
|
+
updated_at: bigint;
|
|
157
|
+
metadata: [string, string][];
|
|
158
|
+
scope: "write" | "admin";
|
|
159
|
+
expires_at?: bigint | undefined;
|
|
160
|
+
}][];
|
|
161
|
+
}>;
|
|
162
|
+
/**
|
|
163
|
+
* Represents the parameters required to perform controller checks.
|
|
164
|
+
*/
|
|
165
|
+
export interface ControllerCheckParams {
|
|
166
|
+
/**
|
|
167
|
+
* The identity of the caller to verify against the controller list.
|
|
168
|
+
*/
|
|
169
|
+
caller: RawUserId | UserId;
|
|
170
|
+
/**
|
|
171
|
+
* The list of controllers to check against.
|
|
172
|
+
*/
|
|
173
|
+
controllers: Controllers;
|
|
174
|
+
}
|
package/sdk/schemas/db.d.ts
CHANGED
|
@@ -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
package/sdk.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{c as s,d as
|
|
1
|
+
import{a as c,c as s,d as n,e as _,f as S,k as C,l as x}from"./chunk-367GY4VX.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/
|
|
4
|
-
"sourcesContent": ["import {
|
|
5
|
-
"mappings": "
|
|
6
|
-
"names": ["Principal", "z", "DocStoreParamsSchema", "RawUserIdSchema", "UserIdSchema", "CollectionSchema", "KeySchema", "SetDocStoreParamsSchema", "SetDocSchema", "DeleteDocStoreParamsSchema", "DelDocSchema", "setDocStore", "params", "SetDocStoreParamsSchema", "providedCaller", "collection", "key", "doc", "caller", "
|
|
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 =>\n 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 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,GAC9BA,aAAkBF,EAAYE,EAAO,aAAa,EAAIA,ECEjD,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,10 +1,22 @@
|
|
|
1
1
|
import type {DelDoc, RawData, SetDoc} from './schemas/db';
|
|
2
2
|
import type {Collection, Key, RawPrincipal, RawUserId} from './schemas/satellite';
|
|
3
|
+
import {Controllers} from './sdk/schemas/controllers';
|
|
3
4
|
|
|
4
5
|
declare global {
|
|
5
6
|
function __juno_satellite_datastore_raw_data_to_text(data: RawData): string;
|
|
6
7
|
function __juno_satellite_datastore_raw_data_from_text(data: string): RawData;
|
|
7
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
|
+
|
|
8
20
|
function __juno_satellite_datastore_set_doc_store(
|
|
9
21
|
caller: RawUserId,
|
|
10
22
|
collection: Collection,
|
|
@@ -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-6G6FWQ45.js.map
DELETED
|
@@ -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\n/**\n * @see Description\n */\nexport const DescriptionSchema = z.string().max(1024);\n\n/**\n * Represents a description with a maximum length of 1024 characters.\n * Used for document and asset fields which can be useful for search purpose.\n */\nexport type Description = z.infer<typeof DescriptionSchema>;\n", "import * as z from 'zod';\nimport {Uint8ArraySchema} from './candid';\nimport {\n Description,\n DescriptionSchema,\n type RawUserId,\n RawUserIdSchema,\n type Timestamp,\n TimestampSchema,\n type Version,\n VersionSchema\n} from './satellite';\n\n/**\n * @see RawData\n */\nexport const RawDataSchema = Uint8ArraySchema;\n\n/**\n * Represents raw binary data.\n *\n * This is used to store structured data in a document.\n */\nexport type RawData = z.infer<typeof Uint8ArraySchema>;\n\n/**\n * @see Doc\n */\nexport const DocSchema = z\n .object({\n owner: RawUserIdSchema,\n data: RawDataSchema,\n description: DescriptionSchema.optional(),\n created_at: TimestampSchema,\n updated_at: TimestampSchema,\n version: VersionSchema.optional()\n })\n .strict();\n\n/**\n * Represents a document stored in a collection.\n */\nexport interface Doc {\n /**\n * The user who owns this document.\n */\n owner: RawUserId;\n\n /**\n * The raw data of the document.\n */\n data: RawData;\n\n /**\n * An optional description of the document.\n */\n description?: Description;\n\n /**\n * The timestamp when the document was first created.\n */\n created_at: Timestamp;\n\n /**\n * The timestamp when the document was last updated.\n */\n updated_at: Timestamp;\n\n /**\n * The version number of the document, used for consistency checks.\n * If not provided, it's assumed to be the first version.\n */\n version?: Version;\n}\n\n/**\n * @see OptionDoc\n */\nexport const OptionDocSchema = DocSchema.optional();\n\n/**\n * A shorthand for a document that might or not be defined.\n */\nexport type OptionDoc = Doc | undefined;\n\n/**\n * @see SetDoc\n */\nexport const SetDocSchema = z\n .object({\n data: RawDataSchema,\n description: DescriptionSchema.optional(),\n version: VersionSchema.optional()\n })\n .strict();\n\n/**\n * Represents the proposed version of a document to be created or updated.\n * This can be validated before allowing the operation.\n */\nexport interface SetDoc {\n /**\n * The raw data of the document.\n */\n data: RawData;\n\n /**\n * An optional description of the document.\n */\n description?: Description;\n\n /**\n * The expected version number to ensure consistency.\n */\n version?: Version;\n}\n\n/**\n * @see DelDoc\n */\nexport const DelDocSchema = z\n .object({\n version: VersionSchema.optional()\n })\n .strict();\n\n/**\n * Represents the proposed version of a document to be deleted.\n * This can be validated before allowing the operation.\n */\nexport interface DelDoc {\n /**\n * The expected version number to ensure consistency.\n */\n version?: Version;\n}\n"],
|
|
5
|
-
"mappings": "4CAAA,UAAYA,MAAO,MAMZ,IAAMC,EAAoB,SAAO,EAY3BC,EAAkB,SAAO,EAYzBC,EAAkBC,EAYlBC,EAAeC,EAYfC,EAAqB,SAAO,EAU5BC,EAAc,SAAO,EAUrBC,EAAsB,SAAO,EAAE,IAAI,IAAI,EC1EpD,UAAYC,MAAO,MAgBZ,IAAMC,EAAgBC,EAYhBC,EACV,SAAO,CACN,MAAOC,EACP,KAAMH,EACN,YAAaI,EAAkB,SAAS,EACxC,WAAYC,EACZ,WAAYA,EACZ,QAASC,EAAc,SAAS,CAClC,CAAC,EACA,OAAO,EAyCGC,EAAkBL,EAAU,SAAS,EAUrCM,EACV,SAAO,CACN,KAAMR,EACN,YAAaI,EAAkB,SAAS,EACxC,QAASE,EAAc,SAAS,CAClC,CAAC,EACA,OAAO,EA0BGG,EACV,SAAO,CACN,QAASH,EAAc,SAAS,CAClC,CAAC,EACA,OAAO",
|
|
6
|
-
"names": ["z", "TimestampSchema", "VersionSchema", "RawUserIdSchema", "RawPrincipalSchema", "UserIdSchema", "PrincipalSchema", "CollectionSchema", "KeySchema", "DescriptionSchema", "z", "RawDataSchema", "Uint8ArraySchema", "DocSchema", "RawUserIdSchema", "DescriptionSchema", "TimestampSchema", "VersionSchema", "OptionDocSchema", "SetDocSchema", "DelDocSchema"]
|
|
7
|
-
}
|