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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,109 @@
1
+ import * as z from 'zod';
2
+ /**
3
+ * @see SetDoc
4
+ */
5
+ export declare const SetDocSchema: z.ZodObject<{
6
+ /**
7
+ * The unique key identifying the document within the collection.
8
+ */
9
+ key: z.ZodString;
10
+ /**
11
+ * An optional description of the document.
12
+ */
13
+ description: z.ZodOptional<z.ZodString>;
14
+ /**
15
+ * The raw data of the document.
16
+ */
17
+ data: z.ZodType<Uint8Array<ArrayBufferLike>, z.ZodTypeDef, Uint8Array<ArrayBufferLike>>;
18
+ /**
19
+ * The expected version number to ensure consistency.
20
+ * If provided, the operation will fail if the stored version does not match.
21
+ */
22
+ version: z.ZodOptional<z.ZodBigInt>;
23
+ }, "strict", z.ZodTypeAny, {
24
+ data: Uint8Array<ArrayBufferLike>;
25
+ key: string;
26
+ description?: string | undefined;
27
+ version?: bigint | undefined;
28
+ }, {
29
+ data: Uint8Array<ArrayBufferLike>;
30
+ key: string;
31
+ description?: string | undefined;
32
+ version?: bigint | undefined;
33
+ }>;
34
+ /**
35
+ * Represents a request to set or update a document.
36
+ *
37
+ * This is used when submitting new document data.
38
+ */
39
+ export type SetDoc = z.infer<typeof SetDocSchema>;
40
+ /**
41
+ * @see SetDocStoreParams
42
+ */
43
+ export declare const SetDocStoreParamsSchema: z.ZodObject<{
44
+ /**
45
+ * The caller who initiate the document operation.
46
+ */
47
+ caller: z.ZodType<Uint8Array<ArrayBufferLike>, z.ZodTypeDef, Uint8Array<ArrayBufferLike>>;
48
+ /**
49
+ * The name of the collection where the document is stored.
50
+ */
51
+ collection: z.ZodString;
52
+ /**
53
+ * The data, key and other information required to create or update a document.
54
+ */
55
+ doc: z.ZodObject<{
56
+ /**
57
+ * The unique key identifying the document within the collection.
58
+ */
59
+ key: z.ZodString;
60
+ /**
61
+ * An optional description of the document.
62
+ */
63
+ description: z.ZodOptional<z.ZodString>;
64
+ /**
65
+ * The raw data of the document.
66
+ */
67
+ data: z.ZodType<Uint8Array<ArrayBufferLike>, z.ZodTypeDef, Uint8Array<ArrayBufferLike>>;
68
+ /**
69
+ * The expected version number to ensure consistency.
70
+ * If provided, the operation will fail if the stored version does not match.
71
+ */
72
+ version: z.ZodOptional<z.ZodBigInt>;
73
+ }, "strict", z.ZodTypeAny, {
74
+ data: Uint8Array<ArrayBufferLike>;
75
+ key: string;
76
+ description?: string | undefined;
77
+ version?: bigint | undefined;
78
+ }, {
79
+ data: Uint8Array<ArrayBufferLike>;
80
+ key: string;
81
+ description?: string | undefined;
82
+ version?: bigint | undefined;
83
+ }>;
84
+ }, "strict", z.ZodTypeAny, {
85
+ caller: Uint8Array<ArrayBufferLike>;
86
+ collection: string;
87
+ doc: {
88
+ data: Uint8Array<ArrayBufferLike>;
89
+ key: string;
90
+ description?: string | undefined;
91
+ version?: bigint | undefined;
92
+ };
93
+ }, {
94
+ caller: Uint8Array<ArrayBufferLike>;
95
+ collection: string;
96
+ doc: {
97
+ data: Uint8Array<ArrayBufferLike>;
98
+ key: string;
99
+ description?: string | undefined;
100
+ version?: bigint | undefined;
101
+ };
102
+ }>;
103
+ /**
104
+ * Represents the parameters required to store or update a document.
105
+ *
106
+ * This includes the document data along with metadata such as the caller,
107
+ * collection, and key.
108
+ */
109
+ export type SetDocStoreParams = z.infer<typeof SetDocStoreParamsSchema>;
@@ -1,9 +1,9 @@
1
- export * from './configs/assert.config';
1
+ export * from './configs/assertions';
2
2
  export * from './configs/collections.config';
3
- export * from './configs/hook.config';
4
- export * from './configs/satellite.config';
3
+ export * from './configs/hooks';
4
+ export * from './configs/satellite.env';
5
5
  export * from './hooks/context';
6
6
  export * from './hooks/core';
7
7
  export * from './hooks/datastore';
8
- export * from './sdk/datastore.sdk';
8
+ export * from './sdk/serializer.sdk';
9
9
  import './polyfills/console.polyfill';
@@ -1,3 +1,13 @@
1
- import type { RawData } from '../hooks/core';
2
- export declare const decodeDocData: <T>(data: RawData) => T;
3
- export declare const encodeDocData: <T>(data: T) => RawData;
1
+ import { SetDocStoreParams } from '../hooks/sdk';
2
+ /**
3
+ * Stores or updates a document in the datastore.
4
+ *
5
+ * The data must have been encoded - using encodeDocData - before calling this function.
6
+ *
7
+ * @param {SetDocStoreParams} params - The parameters required to store the document,
8
+ * including the caller, collection, key, and document data.
9
+ *
10
+ * @throws {z.ZodError} If the provided parameters do not match the expected schema.
11
+ * @throws {Error} If the Satellite fails at validating the submitted document before storing it.
12
+ */
13
+ export declare const setDocStore: (params: SetDocStoreParams) => void;
@@ -0,0 +1,17 @@
1
+ import type { RawData } from '../hooks/core';
2
+ /**
3
+ * Decodes the raw data of a document into a JavaScript object.
4
+ *
5
+ * @template T The expected type of the decoded object.
6
+ * @param {RawData} data - The raw data to be decoded.
7
+ * @returns {T} The parsed JavaScript object.
8
+ */
9
+ export declare const decodeDocData: <T>(data: RawData) => T;
10
+ /**
11
+ * Encodes a JavaScript object into a raw data format to be applied to a document.
12
+ *
13
+ * @template T The type of the object to be encoded.
14
+ * @param {T} data - The data to be encoded.
15
+ * @returns {RawData} The serialized raw data.
16
+ */
17
+ export declare const encodeDocData: <T>(data: T) => RawData;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@junobuild/functions",
3
- "version": "0.0.4",
3
+ "version": "0.0.6-next-2025-03-15",
4
4
  "description": "JavaScript and TypeScript utilities for Juno Serverless Functions",
5
5
  "author": "David Dal Busco (https://daviddalbusco.com)",
6
6
  "license": "MIT",
@@ -37,7 +37,7 @@
37
37
  },
38
38
  "homepage": "https://juno.build",
39
39
  "peerDependencies": {
40
- "@dfinity/utils": "^2",
41
- "zod": "^3"
40
+ "@dfinity/utils": "*",
41
+ "zod": "*"
42
42
  }
43
- }
43
+ }