@junobuild/functions 0.0.2 → 0.0.4

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,85 +1,364 @@
1
- import type { RawData, RawUserId, Timestamp, Version } from './core';
1
+ import * as z from 'zod';
2
2
  /**
3
- * Represents a document update operation.
4
- *
5
- * This is used in hooks where a document is either being created or updated.
3
+ * @see DocDescription
4
+ */
5
+ export declare const DocDescriptionSchema: z.ZodString;
6
+ /**
7
+ * Represents a document description with a maximum length of 1024 characters.
6
8
  */
7
- export interface DocUpsert {
9
+ export type DocDescription = z.infer<typeof DocDescriptionSchema>;
10
+ /**
11
+ * @see Doc
12
+ */
13
+ export declare const DocSchema: z.ZodObject<{
8
14
  /**
9
- * The previous version of the document before the update.
10
- * Undefined if this is a new document.
15
+ * The user who owns this document.
11
16
  */
12
- before?: Doc;
17
+ owner: z.ZodType<Uint8Array<ArrayBufferLike>, z.ZodTypeDef, Uint8Array<ArrayBufferLike>>;
13
18
  /**
14
- * The new version of the document after the update.
19
+ * The raw data of the document.
15
20
  */
16
- after: Doc;
17
- }
18
- /**
19
- * Represents a validation check before setting a document.
20
- *
21
- * The developer can compare the `current` and `proposed` versions and
22
- * throw an error if their validation fails.
23
- */
24
- export interface DocAssertSet {
21
+ data: z.ZodType<Uint8Array<ArrayBuffer>, z.ZodTypeDef, Uint8Array<ArrayBuffer>>;
25
22
  /**
26
- * The current version of the document before the operation.
27
- * Undefined if this is a new document.
23
+ * An optional description of the document.
28
24
  */
29
- current?: Doc;
25
+ description: z.ZodOptional<z.ZodString>;
30
26
  /**
31
- * The proposed version of the document.
32
- * This can be validated before allowing the operation.
27
+ * The timestamp when the document was first created.
28
+ */
29
+ created_at: z.ZodBigInt;
30
+ /**
31
+ * The timestamp when the document was last updated.
33
32
  */
34
- proposed: SetDoc;
35
- }
33
+ updated_at: z.ZodBigInt;
34
+ /**
35
+ * The version number of the document, used for consistency checks.
36
+ * If not provided, it's assumed to be the first version.
37
+ */
38
+ version: z.ZodOptional<z.ZodBigInt>;
39
+ }, "strict", z.ZodTypeAny, {
40
+ owner: Uint8Array<ArrayBufferLike>;
41
+ data: Uint8Array<ArrayBuffer>;
42
+ created_at: bigint;
43
+ updated_at: bigint;
44
+ description?: string | undefined;
45
+ version?: bigint | undefined;
46
+ }, {
47
+ owner: Uint8Array<ArrayBufferLike>;
48
+ data: Uint8Array<ArrayBuffer>;
49
+ created_at: bigint;
50
+ updated_at: bigint;
51
+ description?: string | undefined;
52
+ version?: bigint | undefined;
53
+ }>;
36
54
  /**
37
55
  * Represents a document stored in a collection.
38
56
  */
39
- export interface Doc {
57
+ export type Doc = z.infer<typeof DocSchema>;
58
+ /**
59
+ * @see DocUpsert
60
+ */
61
+ export declare const DocUpsertSchema: z.ZodObject<{
40
62
  /**
41
- * The user who owns this document.
63
+ * The previous version of the document before the update.
64
+ * Undefined if this is a new document.
42
65
  */
43
- owner: RawUserId;
66
+ before: z.ZodOptional<z.ZodObject<{
67
+ /**
68
+ * The user who owns this document.
69
+ */
70
+ owner: z.ZodType<Uint8Array<ArrayBufferLike>, z.ZodTypeDef, Uint8Array<ArrayBufferLike>>;
71
+ /**
72
+ * The raw data of the document.
73
+ */
74
+ data: z.ZodType<Uint8Array<ArrayBuffer>, z.ZodTypeDef, Uint8Array<ArrayBuffer>>;
75
+ /**
76
+ * An optional description of the document.
77
+ */
78
+ description: z.ZodOptional<z.ZodString>;
79
+ /**
80
+ * The timestamp when the document was first created.
81
+ */
82
+ created_at: z.ZodBigInt;
83
+ /**
84
+ * The timestamp when the document was last updated.
85
+ */
86
+ updated_at: z.ZodBigInt;
87
+ /**
88
+ * The version number of the document, used for consistency checks.
89
+ * If not provided, it's assumed to be the first version.
90
+ */
91
+ version: z.ZodOptional<z.ZodBigInt>;
92
+ }, "strict", z.ZodTypeAny, {
93
+ owner: Uint8Array<ArrayBufferLike>;
94
+ data: Uint8Array<ArrayBuffer>;
95
+ created_at: bigint;
96
+ updated_at: bigint;
97
+ description?: string | undefined;
98
+ version?: bigint | undefined;
99
+ }, {
100
+ owner: Uint8Array<ArrayBufferLike>;
101
+ data: Uint8Array<ArrayBuffer>;
102
+ created_at: bigint;
103
+ updated_at: bigint;
104
+ description?: string | undefined;
105
+ version?: bigint | undefined;
106
+ }>>;
107
+ /**
108
+ * The new version of the document after the update.
109
+ */
110
+ after: z.ZodObject<{
111
+ /**
112
+ * The user who owns this document.
113
+ */
114
+ owner: z.ZodType<Uint8Array<ArrayBufferLike>, z.ZodTypeDef, Uint8Array<ArrayBufferLike>>;
115
+ /**
116
+ * The raw data of the document.
117
+ */
118
+ data: z.ZodType<Uint8Array<ArrayBuffer>, z.ZodTypeDef, Uint8Array<ArrayBuffer>>;
119
+ /**
120
+ * An optional description of the document.
121
+ */
122
+ description: z.ZodOptional<z.ZodString>;
123
+ /**
124
+ * The timestamp when the document was first created.
125
+ */
126
+ created_at: z.ZodBigInt;
127
+ /**
128
+ * The timestamp when the document was last updated.
129
+ */
130
+ updated_at: z.ZodBigInt;
131
+ /**
132
+ * The version number of the document, used for consistency checks.
133
+ * If not provided, it's assumed to be the first version.
134
+ */
135
+ version: z.ZodOptional<z.ZodBigInt>;
136
+ }, "strict", z.ZodTypeAny, {
137
+ owner: Uint8Array<ArrayBufferLike>;
138
+ data: Uint8Array<ArrayBuffer>;
139
+ created_at: bigint;
140
+ updated_at: bigint;
141
+ description?: string | undefined;
142
+ version?: bigint | undefined;
143
+ }, {
144
+ owner: Uint8Array<ArrayBufferLike>;
145
+ data: Uint8Array<ArrayBuffer>;
146
+ created_at: bigint;
147
+ updated_at: bigint;
148
+ description?: string | undefined;
149
+ version?: bigint | undefined;
150
+ }>;
151
+ }, "strict", z.ZodTypeAny, {
152
+ after: {
153
+ owner: Uint8Array<ArrayBufferLike>;
154
+ data: Uint8Array<ArrayBuffer>;
155
+ created_at: bigint;
156
+ updated_at: bigint;
157
+ description?: string | undefined;
158
+ version?: bigint | undefined;
159
+ };
160
+ before?: {
161
+ owner: Uint8Array<ArrayBufferLike>;
162
+ data: Uint8Array<ArrayBuffer>;
163
+ created_at: bigint;
164
+ updated_at: bigint;
165
+ description?: string | undefined;
166
+ version?: bigint | undefined;
167
+ } | undefined;
168
+ }, {
169
+ after: {
170
+ owner: Uint8Array<ArrayBufferLike>;
171
+ data: Uint8Array<ArrayBuffer>;
172
+ created_at: bigint;
173
+ updated_at: bigint;
174
+ description?: string | undefined;
175
+ version?: bigint | undefined;
176
+ };
177
+ before?: {
178
+ owner: Uint8Array<ArrayBufferLike>;
179
+ data: Uint8Array<ArrayBuffer>;
180
+ created_at: bigint;
181
+ updated_at: bigint;
182
+ description?: string | undefined;
183
+ version?: bigint | undefined;
184
+ } | undefined;
185
+ }>;
186
+ /**
187
+ * Represents a document update operation.
188
+ *
189
+ * This is used in hooks where a document is either being created or updated.
190
+ */
191
+ export type DocUpsert = z.infer<typeof DocUpsertSchema>;
192
+ /**
193
+ * @see ProposedDoc
194
+ */
195
+ export declare const ProposedDocSchema: z.ZodObject<{
44
196
  /**
45
197
  * The raw data of the document.
46
198
  */
47
- data: RawData;
199
+ data: z.ZodType<Uint8Array<ArrayBuffer>, z.ZodTypeDef, Uint8Array<ArrayBuffer>>;
48
200
  /**
49
201
  * An optional description of the document.
50
202
  */
51
- description?: string;
203
+ description: z.ZodOptional<z.ZodString>;
52
204
  /**
53
- * The timestamp when the document was first created.
205
+ * The expected version number to ensure consistency.
54
206
  */
55
- created_at: Timestamp;
207
+ version: z.ZodOptional<z.ZodBigInt>;
208
+ }, "strict", z.ZodTypeAny, {
209
+ data: Uint8Array<ArrayBuffer>;
210
+ description?: string | undefined;
211
+ version?: bigint | undefined;
212
+ }, {
213
+ data: Uint8Array<ArrayBuffer>;
214
+ description?: string | undefined;
215
+ version?: bigint | undefined;
216
+ }>;
217
+ /**
218
+ * Represents the proposed version of a document.
219
+ * This can be validated before allowing the operation.
220
+ */
221
+ export type ProposedDoc = z.infer<typeof ProposedDocSchema>;
222
+ /**
223
+ * @see DocAssertSet
224
+ */
225
+ export declare const DocAssertSetSchema: z.ZodObject<{
56
226
  /**
57
- * The timestamp when the document was last updated.
227
+ * The current version of the document before the operation.
228
+ * Undefined if this is a new document.
58
229
  */
59
- updated_at: Timestamp;
230
+ current: z.ZodOptional<z.ZodObject<{
231
+ /**
232
+ * The user who owns this document.
233
+ */
234
+ owner: z.ZodType<Uint8Array<ArrayBufferLike>, z.ZodTypeDef, Uint8Array<ArrayBufferLike>>;
235
+ /**
236
+ * The raw data of the document.
237
+ */
238
+ data: z.ZodType<Uint8Array<ArrayBuffer>, z.ZodTypeDef, Uint8Array<ArrayBuffer>>;
239
+ /**
240
+ * An optional description of the document.
241
+ */
242
+ description: z.ZodOptional<z.ZodString>;
243
+ /**
244
+ * The timestamp when the document was first created.
245
+ */
246
+ created_at: z.ZodBigInt;
247
+ /**
248
+ * The timestamp when the document was last updated.
249
+ */
250
+ updated_at: z.ZodBigInt;
251
+ /**
252
+ * The version number of the document, used for consistency checks.
253
+ * If not provided, it's assumed to be the first version.
254
+ */
255
+ version: z.ZodOptional<z.ZodBigInt>;
256
+ }, "strict", z.ZodTypeAny, {
257
+ owner: Uint8Array<ArrayBufferLike>;
258
+ data: Uint8Array<ArrayBuffer>;
259
+ created_at: bigint;
260
+ updated_at: bigint;
261
+ description?: string | undefined;
262
+ version?: bigint | undefined;
263
+ }, {
264
+ owner: Uint8Array<ArrayBufferLike>;
265
+ data: Uint8Array<ArrayBuffer>;
266
+ created_at: bigint;
267
+ updated_at: bigint;
268
+ description?: string | undefined;
269
+ version?: bigint | undefined;
270
+ }>>;
60
271
  /**
61
- * The version number of the document, used for consistency checks.
62
- * If not provided, it's assumed to be the first version.
272
+ * The proposed version of the document.
273
+ * This can be validated before allowing the operation.
63
274
  */
64
- version?: Version;
65
- }
275
+ proposed: z.ZodObject<{
276
+ /**
277
+ * The raw data of the document.
278
+ */
279
+ data: z.ZodType<Uint8Array<ArrayBuffer>, z.ZodTypeDef, Uint8Array<ArrayBuffer>>;
280
+ /**
281
+ * An optional description of the document.
282
+ */
283
+ description: z.ZodOptional<z.ZodString>;
284
+ /**
285
+ * The expected version number to ensure consistency.
286
+ */
287
+ version: z.ZodOptional<z.ZodBigInt>;
288
+ }, "strict", z.ZodTypeAny, {
289
+ data: Uint8Array<ArrayBuffer>;
290
+ description?: string | undefined;
291
+ version?: bigint | undefined;
292
+ }, {
293
+ data: Uint8Array<ArrayBuffer>;
294
+ description?: string | undefined;
295
+ version?: bigint | undefined;
296
+ }>;
297
+ }, "strict", z.ZodTypeAny, {
298
+ proposed: {
299
+ data: Uint8Array<ArrayBuffer>;
300
+ description?: string | undefined;
301
+ version?: bigint | undefined;
302
+ };
303
+ current?: {
304
+ owner: Uint8Array<ArrayBufferLike>;
305
+ data: Uint8Array<ArrayBuffer>;
306
+ created_at: bigint;
307
+ updated_at: bigint;
308
+ description?: string | undefined;
309
+ version?: bigint | undefined;
310
+ } | undefined;
311
+ }, {
312
+ proposed: {
313
+ data: Uint8Array<ArrayBuffer>;
314
+ description?: string | undefined;
315
+ version?: bigint | undefined;
316
+ };
317
+ current?: {
318
+ owner: Uint8Array<ArrayBufferLike>;
319
+ data: Uint8Array<ArrayBuffer>;
320
+ created_at: bigint;
321
+ updated_at: bigint;
322
+ description?: string | undefined;
323
+ version?: bigint | undefined;
324
+ } | undefined;
325
+ }>;
66
326
  /**
67
- * Represents a request to set or update a document.
327
+ * Represents a validation check before setting a document.
68
328
  *
69
- * This is used when submitting new document data.
329
+ * The developer can compare the `current` and `proposed` versions and
330
+ * throw an error if their validation fails.
331
+ */
332
+ export type DocAssertSet = z.infer<typeof DocAssertSetSchema>;
333
+ /**
334
+ * @see SetDoc
70
335
  */
71
- export interface SetDoc {
336
+ export declare const SetDocSchema: z.ZodObject<{
72
337
  /**
73
338
  * The raw data of the document.
74
339
  */
75
- data: RawData;
340
+ data: z.ZodType<Uint8Array<ArrayBuffer>, z.ZodTypeDef, Uint8Array<ArrayBuffer>>;
76
341
  /**
77
342
  * An optional description of the document.
78
343
  */
79
- description?: string;
344
+ description: z.ZodOptional<z.ZodString>;
80
345
  /**
81
346
  * The expected version number to ensure consistency.
82
347
  * If provided, the operation will fail if the stored version does not match.
83
348
  */
84
- version?: Version;
85
- }
349
+ version: z.ZodOptional<z.ZodBigInt>;
350
+ }, "strict", z.ZodTypeAny, {
351
+ data: Uint8Array<ArrayBuffer>;
352
+ description?: string | undefined;
353
+ version?: bigint | undefined;
354
+ }, {
355
+ data: Uint8Array<ArrayBuffer>;
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>;
@@ -1,8 +1,9 @@
1
- export type * from './configs/collection.config';
2
- export type * from './configs/satellite.config';
3
- export type * from './hooks/context';
4
- export type * from './hooks/core';
5
- export type * from './hooks/datastore';
6
1
  export * from './configs/assert.config';
2
+ export * from './configs/collections.config';
7
3
  export * from './configs/hook.config';
4
+ export * from './configs/satellite.config';
5
+ export * from './hooks/context';
6
+ export * from './hooks/core';
7
+ export * from './hooks/datastore';
8
8
  export * from './sdk/datastore.sdk';
9
+ import './polyfills/console.polyfill';
@@ -0,0 +1 @@
1
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@junobuild/functions",
3
- "version": "0.0.2",
3
+ "version": "0.0.4",
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,6 +37,7 @@
37
37
  },
38
38
  "homepage": "https://juno.build",
39
39
  "peerDependencies": {
40
- "@dfinity/utils": "^2"
40
+ "@dfinity/utils": "^2",
41
+ "zod": "^3"
41
42
  }
42
43
  }
@@ -1,9 +0,0 @@
1
- /**
2
- * Defines the collections where a hook or assertion should run.
3
- */
4
- export interface CollectionsConfig {
5
- /**
6
- * A list of collection names where the hook or assertion will be executed.
7
- */
8
- collections: string[];
9
- }