@junobuild/functions 0.0.1 → 0.0.2
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 +382 -0
- package/dist/browser/index.js +1 -1
- package/dist/browser/index.js.map +4 -4
- package/dist/types/index.d.ts +2 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -12,6 +12,388 @@ JavaScript and TypeScript utilities for [Juno] Serverless Functions.
|
|
|
12
12
|
|
|
13
13
|
<!-- TSDOC_START -->
|
|
14
14
|
|
|
15
|
+
### :toolbox: Functions
|
|
16
|
+
|
|
17
|
+
- [defineAssert](#gear-defineassert)
|
|
18
|
+
- [defineAssert](#gear-defineassert)
|
|
19
|
+
- [defineAssert](#gear-defineassert)
|
|
20
|
+
- [defineAssert](#gear-defineassert)
|
|
21
|
+
- [defineHook](#gear-definehook)
|
|
22
|
+
- [defineHook](#gear-definehook)
|
|
23
|
+
- [defineHook](#gear-definehook)
|
|
24
|
+
- [defineHook](#gear-definehook)
|
|
25
|
+
- [decodeDocData](#gear-decodedocdata)
|
|
26
|
+
- [encodeDocData](#gear-encodedocdata)
|
|
27
|
+
|
|
28
|
+
#### :gear: defineAssert
|
|
29
|
+
|
|
30
|
+
| Function | Type |
|
|
31
|
+
| -------------- | ----------------------------------------------------------------------------------------------------------------------------------- |
|
|
32
|
+
| `defineAssert` | `{ (config: AssertSetDocConfig): AssertSetDocConfig; (config: AssertFn): AssertFn; (config: AssertFnOrObject): AssertFnOrObject; }` |
|
|
33
|
+
|
|
34
|
+
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/configs/assert.config.ts#L34)
|
|
35
|
+
|
|
36
|
+
#### :gear: defineAssert
|
|
37
|
+
|
|
38
|
+
| Function | Type |
|
|
39
|
+
| -------------- | ----------------------------------------------------------------------------------------------------------------------------------- |
|
|
40
|
+
| `defineAssert` | `{ (config: AssertSetDocConfig): AssertSetDocConfig; (config: AssertFn): AssertFn; (config: AssertFnOrObject): AssertFnOrObject; }` |
|
|
41
|
+
|
|
42
|
+
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/configs/assert.config.ts#L35)
|
|
43
|
+
|
|
44
|
+
#### :gear: defineAssert
|
|
45
|
+
|
|
46
|
+
| Function | Type |
|
|
47
|
+
| -------------- | ----------------------------------------------------------------------------------------------------------------------------------- |
|
|
48
|
+
| `defineAssert` | `{ (config: AssertSetDocConfig): AssertSetDocConfig; (config: AssertFn): AssertFn; (config: AssertFnOrObject): AssertFnOrObject; }` |
|
|
49
|
+
|
|
50
|
+
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/configs/assert.config.ts#L36)
|
|
51
|
+
|
|
52
|
+
#### :gear: defineAssert
|
|
53
|
+
|
|
54
|
+
| Function | Type |
|
|
55
|
+
| -------------- | ----------------------------------------------------------------------------------------------------------------------------------- |
|
|
56
|
+
| `defineAssert` | `{ (config: AssertSetDocConfig): AssertSetDocConfig; (config: AssertFn): AssertFn; (config: AssertFnOrObject): AssertFnOrObject; }` |
|
|
57
|
+
|
|
58
|
+
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/configs/assert.config.ts#L37)
|
|
59
|
+
|
|
60
|
+
#### :gear: defineHook
|
|
61
|
+
|
|
62
|
+
| Function | Type |
|
|
63
|
+
| ------------ | ------------------------------------------------------------------------------------------------------------------- |
|
|
64
|
+
| `defineHook` | `{ (config: OnSetDocConfig): OnSetDocConfig; (config: HookFn): HookFn; (config: HookFnOrObject): HookFnOrObject; }` |
|
|
65
|
+
|
|
66
|
+
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/configs/hook.config.ts#L32)
|
|
67
|
+
|
|
68
|
+
#### :gear: defineHook
|
|
69
|
+
|
|
70
|
+
| Function | Type |
|
|
71
|
+
| ------------ | ------------------------------------------------------------------------------------------------------------------- |
|
|
72
|
+
| `defineHook` | `{ (config: OnSetDocConfig): OnSetDocConfig; (config: HookFn): HookFn; (config: HookFnOrObject): HookFnOrObject; }` |
|
|
73
|
+
|
|
74
|
+
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/configs/hook.config.ts#L33)
|
|
75
|
+
|
|
76
|
+
#### :gear: defineHook
|
|
77
|
+
|
|
78
|
+
| Function | Type |
|
|
79
|
+
| ------------ | ------------------------------------------------------------------------------------------------------------------- |
|
|
80
|
+
| `defineHook` | `{ (config: OnSetDocConfig): OnSetDocConfig; (config: HookFn): HookFn; (config: HookFnOrObject): HookFnOrObject; }` |
|
|
81
|
+
|
|
82
|
+
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/configs/hook.config.ts#L34)
|
|
83
|
+
|
|
84
|
+
#### :gear: defineHook
|
|
85
|
+
|
|
86
|
+
| Function | Type |
|
|
87
|
+
| ------------ | ------------------------------------------------------------------------------------------------------------------- |
|
|
88
|
+
| `defineHook` | `{ (config: OnSetDocConfig): OnSetDocConfig; (config: HookFn): HookFn; (config: HookFnOrObject): HookFnOrObject; }` |
|
|
89
|
+
|
|
90
|
+
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/configs/hook.config.ts#L35)
|
|
91
|
+
|
|
92
|
+
#### :gear: decodeDocData
|
|
93
|
+
|
|
94
|
+
| Function | Type |
|
|
95
|
+
| --------------- | ------------------------- |
|
|
96
|
+
| `decodeDocData` | `<T>(data: RawData) => T` |
|
|
97
|
+
|
|
98
|
+
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/sdk/datastore.sdk.ts#L4)
|
|
99
|
+
|
|
100
|
+
#### :gear: encodeDocData
|
|
101
|
+
|
|
102
|
+
| Function | Type |
|
|
103
|
+
| --------------- | ------------------------- |
|
|
104
|
+
| `encodeDocData` | `<T>(data: T) => RawData` |
|
|
105
|
+
|
|
106
|
+
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/sdk/datastore.sdk.ts#L7)
|
|
107
|
+
|
|
108
|
+
### :tropical_drink: Interfaces
|
|
109
|
+
|
|
110
|
+
- [CollectionsConfig](#gear-collectionsconfig)
|
|
111
|
+
- [DocUpsert](#gear-docupsert)
|
|
112
|
+
- [DocAssertSet](#gear-docassertset)
|
|
113
|
+
- [Doc](#gear-doc)
|
|
114
|
+
- [SetDoc](#gear-setdoc)
|
|
115
|
+
- [HookContext](#gear-hookcontext)
|
|
116
|
+
- [DocContext](#gear-doccontext)
|
|
117
|
+
- [AssertAssertConfig](#gear-assertassertconfig)
|
|
118
|
+
- [AssertSetDocConfig](#gear-assertsetdocconfig)
|
|
119
|
+
- [OnHookConfig](#gear-onhookconfig)
|
|
120
|
+
- [OnSetDocConfig](#gear-onsetdocconfig)
|
|
121
|
+
|
|
122
|
+
#### :gear: CollectionsConfig
|
|
123
|
+
|
|
124
|
+
Defines the collections where a hook or assertion should run.
|
|
125
|
+
|
|
126
|
+
| Property | Type | Description |
|
|
127
|
+
| ------------- | ---------- | ------------------------------------------------------------------------ |
|
|
128
|
+
| `collections` | `string[]` | A list of collection names where the hook or assertion will be executed. |
|
|
129
|
+
|
|
130
|
+
#### :gear: DocUpsert
|
|
131
|
+
|
|
132
|
+
Represents a document update operation.
|
|
133
|
+
|
|
134
|
+
This is used in hooks where a document is either being created or updated.
|
|
135
|
+
|
|
136
|
+
| Property | Type | Description |
|
|
137
|
+
| -------- | ------------------ | -------------------------------------------------------------------------------------------- |
|
|
138
|
+
| `before` | `Doc or undefined` | The previous version of the document before the update. Undefined if this is a new document. |
|
|
139
|
+
| `after` | `Doc` | The new version of the document after the update. |
|
|
140
|
+
|
|
141
|
+
#### :gear: DocAssertSet
|
|
142
|
+
|
|
143
|
+
Represents a validation check before setting a document.
|
|
144
|
+
|
|
145
|
+
The developer can compare the `current` and `proposed` versions and
|
|
146
|
+
throw an error if their validation fails.
|
|
147
|
+
|
|
148
|
+
| Property | Type | Description |
|
|
149
|
+
| ---------- | ------------------ | ---------------------------------------------------------------------------------------------- |
|
|
150
|
+
| `current` | `Doc or undefined` | The current version of the document before the operation. Undefined if this is a new document. |
|
|
151
|
+
| `proposed` | `SetDoc` | The proposed version of the document. This can be validated before allowing the operation. |
|
|
152
|
+
|
|
153
|
+
#### :gear: Doc
|
|
154
|
+
|
|
155
|
+
Represents a document stored in a collection.
|
|
156
|
+
|
|
157
|
+
| Property | Type | Description |
|
|
158
|
+
| ------------- | --------------------- | ----------------------------------------------------------------------------------------------------------------------- |
|
|
159
|
+
| `owner` | `RawPrincipal` | The user who owns this document. |
|
|
160
|
+
| `data` | `RawData` | The raw data of the document. |
|
|
161
|
+
| `description` | `string or undefined` | An optional description of the document. |
|
|
162
|
+
| `created_at` | `bigint` | The timestamp when the document was first created. |
|
|
163
|
+
| `updated_at` | `bigint` | The timestamp when the document was last updated. |
|
|
164
|
+
| `version` | `bigint or undefined` | The version number of the document, used for consistency checks. If not provided, it's assumed to be the first version. |
|
|
165
|
+
|
|
166
|
+
#### :gear: SetDoc
|
|
167
|
+
|
|
168
|
+
Represents a request to set or update a document.
|
|
169
|
+
|
|
170
|
+
This is used when submitting new document data.
|
|
171
|
+
|
|
172
|
+
| Property | Type | Description |
|
|
173
|
+
| ------------- | --------------------- | ----------------------------------------------------------------------------------------------------------------------------- |
|
|
174
|
+
| `data` | `RawData` | The raw data of the document. |
|
|
175
|
+
| `description` | `string or undefined` | An optional description of the document. |
|
|
176
|
+
| `version` | `bigint or undefined` | The expected version number to ensure consistency. If provided, the operation will fail if the stored version does not match. |
|
|
177
|
+
|
|
178
|
+
#### :gear: HookContext
|
|
179
|
+
|
|
180
|
+
Represents the context provided to hooks, containing information about the caller and related data.
|
|
181
|
+
|
|
182
|
+
| Property | Type | Description |
|
|
183
|
+
| -------- | -------------- | ------------------------------------------------------------------------------- |
|
|
184
|
+
| `caller` | `RawPrincipal` | The user who originally triggered the function that in turn triggered the hook. |
|
|
185
|
+
| `data` | `T` | The data associated with the hook execution. |
|
|
186
|
+
|
|
187
|
+
#### :gear: DocContext
|
|
188
|
+
|
|
189
|
+
Represents the context of a document operation within a collection.
|
|
190
|
+
|
|
191
|
+
| Property | Type | Description |
|
|
192
|
+
| ------------ | -------- | -------------------------------------------------------------- |
|
|
193
|
+
| `collection` | `string` | The name of the collection where the document is stored. |
|
|
194
|
+
| `key` | `string` | The unique key identifying the document within the collection. |
|
|
195
|
+
| `data` | `T` | The data associated with the document operation. |
|
|
196
|
+
|
|
197
|
+
#### :gear: AssertAssertConfig
|
|
198
|
+
|
|
199
|
+
The generic configuration for assertion hooks that manage collections.
|
|
200
|
+
|
|
201
|
+
| Property | Type | Description |
|
|
202
|
+
| -------------- | ------- | ----------- |
|
|
203
|
+
| `assertSetDoc` | `never` | |
|
|
204
|
+
|
|
205
|
+
#### :gear: AssertSetDocConfig
|
|
206
|
+
|
|
207
|
+
A configuration object that includes the `assertSetDoc` function.
|
|
208
|
+
This function is called to validate a document before it is created or updated.
|
|
209
|
+
|
|
210
|
+
| Property | Type | Description |
|
|
211
|
+
| -------------- | ---------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
|
|
212
|
+
| `assertSetDoc` | `(context: AssertSetDocContext) => void` | A function that runs synchronously before a document is set in the Datastore. This can be used to enforce your validation rules. param: context - Provides details about the document being validated.throws: {Error} If your validation fails, throw an exception to prevent the document from being saved. |
|
|
213
|
+
|
|
214
|
+
#### :gear: OnHookConfig
|
|
215
|
+
|
|
216
|
+
The generic configuration for hooks that manage collections.
|
|
217
|
+
|
|
218
|
+
| Property | Type | Description |
|
|
219
|
+
| ---------- | ------- | ----------- |
|
|
220
|
+
| `onSetDoc` | `never` | |
|
|
221
|
+
|
|
222
|
+
#### :gear: OnSetDocConfig
|
|
223
|
+
|
|
224
|
+
A configuration object that includes the `onSetDoc` function.
|
|
225
|
+
This function is called when a document is created or updated.
|
|
226
|
+
|
|
227
|
+
| Property | Type | Description |
|
|
228
|
+
| ---------- | --------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
229
|
+
| `onSetDoc` | `(context: OnSetDocContext) => Promise<void>` | A function that runs when a document is set in the Datastore. param: context - Provides details about the document being saved.returns: Resolves when your operation is complete. |
|
|
230
|
+
|
|
231
|
+
### :cocktail: Types
|
|
232
|
+
|
|
233
|
+
- [SatelliteConfigEnv](#gear-satelliteconfigenv)
|
|
234
|
+
- [Timestamp](#gear-timestamp)
|
|
235
|
+
- [Version](#gear-version)
|
|
236
|
+
- [RawData](#gear-rawdata)
|
|
237
|
+
- [RawPrincipal](#gear-rawprincipal)
|
|
238
|
+
- [RawUserId](#gear-rawuserid)
|
|
239
|
+
- [OnSetDocContext](#gear-onsetdoccontext)
|
|
240
|
+
- [AssertSetDocContext](#gear-assertsetdoccontext)
|
|
241
|
+
- [AssertConfig](#gear-assertconfig)
|
|
242
|
+
- [AssertFn](#gear-assertfn)
|
|
243
|
+
- [AssertFnOrObject](#gear-assertfnorobject)
|
|
244
|
+
- [HookConfig](#gear-hookconfig)
|
|
245
|
+
- [HookFn](#gear-hookfn)
|
|
246
|
+
- [HookFnOrObject](#gear-hookfnorobject)
|
|
247
|
+
|
|
248
|
+
#### :gear: SatelliteConfigEnv
|
|
249
|
+
|
|
250
|
+
Placeholder for future environment-specific configurations.
|
|
251
|
+
|
|
252
|
+
Currently unused, but it may support features such as:
|
|
253
|
+
|
|
254
|
+
- Defining the execution mode (e.g., staging or production).
|
|
255
|
+
- Providing environment-specific values like `ckBtcLedgerId` for test or production.
|
|
256
|
+
|
|
257
|
+
| Type | Type |
|
|
258
|
+
| -------------------- | ---- |
|
|
259
|
+
| `SatelliteConfigEnv` | |
|
|
260
|
+
|
|
261
|
+
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/configs/satellite.config.ts#L8)
|
|
262
|
+
|
|
263
|
+
#### :gear: Timestamp
|
|
264
|
+
|
|
265
|
+
Represents a timestamp in nanoseconds since the Unix epoch.
|
|
266
|
+
|
|
267
|
+
Used for tracking when events occur, such as document creation and updates.
|
|
268
|
+
|
|
269
|
+
| Type | Type |
|
|
270
|
+
| ----------- | ---- |
|
|
271
|
+
| `Timestamp` | |
|
|
272
|
+
|
|
273
|
+
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/hooks/core.ts#L6)
|
|
274
|
+
|
|
275
|
+
#### :gear: Version
|
|
276
|
+
|
|
277
|
+
Represents a version number for tracking changes.
|
|
278
|
+
|
|
279
|
+
This is typically incremented with each update to ensure consistency.
|
|
280
|
+
|
|
281
|
+
| Type | Type |
|
|
282
|
+
| --------- | ---- |
|
|
283
|
+
| `Version` | |
|
|
284
|
+
|
|
285
|
+
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/hooks/core.ts#L13)
|
|
286
|
+
|
|
287
|
+
#### :gear: RawData
|
|
288
|
+
|
|
289
|
+
Represents raw binary data.
|
|
290
|
+
|
|
291
|
+
This is used to store unstructured data in a document.
|
|
292
|
+
|
|
293
|
+
| Type | Type |
|
|
294
|
+
| --------- | ------------ |
|
|
295
|
+
| `RawData` | `Uint8Array` |
|
|
296
|
+
|
|
297
|
+
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/hooks/core.ts#L20)
|
|
298
|
+
|
|
299
|
+
#### :gear: RawPrincipal
|
|
300
|
+
|
|
301
|
+
Represents a raw principal identifier.
|
|
302
|
+
|
|
303
|
+
Principals are unique identities used in authentication and authorization.
|
|
304
|
+
|
|
305
|
+
| Type | Type |
|
|
306
|
+
| -------------- | ------------ |
|
|
307
|
+
| `RawPrincipal` | `Uint8Array` |
|
|
308
|
+
|
|
309
|
+
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/hooks/core.ts#L27)
|
|
310
|
+
|
|
311
|
+
#### :gear: RawUserId
|
|
312
|
+
|
|
313
|
+
Represents a raw user identifier.
|
|
314
|
+
|
|
315
|
+
This is a principal associated with a user.
|
|
316
|
+
|
|
317
|
+
| Type | Type |
|
|
318
|
+
| ----------- | -------------- |
|
|
319
|
+
| `RawUserId` | `RawPrincipal` |
|
|
320
|
+
|
|
321
|
+
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/hooks/core.ts#L34)
|
|
322
|
+
|
|
323
|
+
#### :gear: OnSetDocContext
|
|
324
|
+
|
|
325
|
+
The context provided to the `onSetDoc` hook.
|
|
326
|
+
|
|
327
|
+
This context contains information about the document being created or updated,
|
|
328
|
+
along with details about the user who triggered the operation.
|
|
329
|
+
|
|
330
|
+
| Type | Type |
|
|
331
|
+
| ----------------- | ------------------------------------ |
|
|
332
|
+
| `OnSetDocContext` | `HookContext<DocContext<DocUpsert>>` |
|
|
333
|
+
|
|
334
|
+
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/hooks/context.ts#L49)
|
|
335
|
+
|
|
336
|
+
#### :gear: AssertSetDocContext
|
|
337
|
+
|
|
338
|
+
The context provided to the `assertSetDoc` hook.
|
|
339
|
+
|
|
340
|
+
This context contains information about the document being validated before
|
|
341
|
+
it is created or updated. If validation fails, the developer should throw an error.
|
|
342
|
+
|
|
343
|
+
| Type | Type |
|
|
344
|
+
| --------------------- | --------------------------------------- |
|
|
345
|
+
| `AssertSetDocContext` | `HookContext<DocContext<DocAssertSet>>` |
|
|
346
|
+
|
|
347
|
+
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/hooks/context.ts#L57)
|
|
348
|
+
|
|
349
|
+
#### :gear: AssertConfig
|
|
350
|
+
|
|
351
|
+
| Type | Type |
|
|
352
|
+
| -------------- | -------------------- |
|
|
353
|
+
| `AssertConfig` | `AssertSetDocConfig` |
|
|
354
|
+
|
|
355
|
+
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/configs/assert.config.ts#L28)
|
|
356
|
+
|
|
357
|
+
#### :gear: AssertFn
|
|
358
|
+
|
|
359
|
+
| Type | Type |
|
|
360
|
+
| ---------- | ---------------------------------------------- |
|
|
361
|
+
| `AssertFn` | `(config: SatelliteConfigEnv) => AssertConfig` |
|
|
362
|
+
|
|
363
|
+
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/configs/assert.config.ts#L30)
|
|
364
|
+
|
|
365
|
+
#### :gear: AssertFnOrObject
|
|
366
|
+
|
|
367
|
+
| Type | Type |
|
|
368
|
+
| ------------------ | -------------------------- |
|
|
369
|
+
| `AssertFnOrObject` | `AssertConfig or AssertFn` |
|
|
370
|
+
|
|
371
|
+
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/configs/assert.config.ts#L32)
|
|
372
|
+
|
|
373
|
+
#### :gear: HookConfig
|
|
374
|
+
|
|
375
|
+
| Type | Type |
|
|
376
|
+
| ------------ | ---------------- |
|
|
377
|
+
| `HookConfig` | `OnSetDocConfig` |
|
|
378
|
+
|
|
379
|
+
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/configs/hook.config.ts#L26)
|
|
380
|
+
|
|
381
|
+
#### :gear: HookFn
|
|
382
|
+
|
|
383
|
+
| Type | Type |
|
|
384
|
+
| -------- | -------------------------------------------- |
|
|
385
|
+
| `HookFn` | `(config: SatelliteConfigEnv) => HookConfig` |
|
|
386
|
+
|
|
387
|
+
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/configs/hook.config.ts#L28)
|
|
388
|
+
|
|
389
|
+
#### :gear: HookFnOrObject
|
|
390
|
+
|
|
391
|
+
| Type | Type |
|
|
392
|
+
| ---------------- | ---------------------- |
|
|
393
|
+
| `HookFnOrObject` | `HookConfig or HookFn` |
|
|
394
|
+
|
|
395
|
+
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/configs/hook.config.ts#L30)
|
|
396
|
+
|
|
15
397
|
<!-- TSDOC_END -->
|
|
16
398
|
|
|
17
399
|
## License
|
package/dist/browser/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{jsonReplacer as t,jsonReviver as e}from"@dfinity/utils";var
|
|
1
|
+
function n(o){return o}function i(o){return o}import{jsonReplacer as t,jsonReviver as e}from"@dfinity/utils";var c=o=>JSON.parse(__juno_satellite_datastore_raw_data_to_text(o),e),p=o=>__juno_satellite_datastore_raw_data_from_text(JSON.stringify(o,t));export{c as decodeDocData,n as defineAssert,i as defineHook,p as encodeDocData};
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["../../src/sdk/datastore.sdk.ts"],
|
|
4
|
-
"sourcesContent": ["import {jsonReplacer, jsonReviver} from '@dfinity/utils';\nimport type {RawData} from '../hooks/core';\n\nexport const decodeDocData = <T>(data: RawData): T =>\n JSON.parse(__juno_satellite_datastore_raw_data_to_text(data), jsonReviver);\n\nexport const encodeDocData = <T>(data: T): RawData =>\n __juno_satellite_datastore_raw_data_from_text(JSON.stringify(data, jsonReplacer));\n"],
|
|
5
|
-
"mappings": "
|
|
6
|
-
"names": ["jsonReplacer", "jsonReviver", "decodeDocData", "data", "encodeDocData"]
|
|
3
|
+
"sources": ["../../src/configs/assert.config.ts", "../../src/configs/hook.config.ts", "../../src/sdk/datastore.sdk.ts"],
|
|
4
|
+
"sourcesContent": ["import type {AssertSetDocContext} from '../hooks/context';\nimport type {CollectionsConfig} from './collection.config';\nimport type {SatelliteConfigEnv} from './satellite.config';\n\n/**\n * The generic configuration for assertion hooks that manage collections.\n */\nexport interface AssertAssertConfig extends CollectionsConfig {\n assertSetDoc: never;\n}\n\n/**\n * A configuration object that includes the `assertSetDoc` function.\n * This function is called to validate a document before it is created or updated.\n */\nexport interface AssertSetDocConfig extends Omit<AssertAssertConfig, 'assertSetDoc'> {\n /**\n * A function that runs synchronously before a document is set in the Datastore.\n * This can be used to enforce your validation rules.\n *\n * @param {AssertSetDocContext} context - Provides details about the document being validated.\n * @throws {Error} If your validation fails, throw an exception to prevent the document from being saved.\n *\n */\n assertSetDoc: (context: AssertSetDocContext) => void;\n}\n\nexport type AssertConfig = AssertSetDocConfig;\n\nexport type AssertFn = (config: SatelliteConfigEnv) => AssertConfig;\n\nexport type AssertFnOrObject = AssertConfig | AssertFn;\n\nexport function defineAssert(config: AssertConfig): AssertConfig;\nexport function defineAssert(config: AssertFn): AssertFn;\nexport function defineAssert(config: AssertFnOrObject): AssertFnOrObject;\nexport function defineAssert(config: AssertFnOrObject): AssertFnOrObject {\n return config;\n}\n", "import type {OnSetDocContext} from '../hooks/context';\nimport type {CollectionsConfig} from './collection.config';\nimport type {SatelliteConfigEnv} from './satellite.config';\n\n/**\n * The generic configuration for hooks that manage collections.\n */\nexport interface OnHookConfig extends CollectionsConfig {\n onSetDoc: never;\n}\n\n/**\n * A configuration object that includes the `onSetDoc` function.\n * This function is called when a document is created or updated.\n */\nexport interface OnSetDocConfig extends Omit<OnHookConfig, 'onSetDoc'> {\n /**\n * A function that runs when a document is set in the Datastore.\n *\n * @param {OnSetDocContext} context - Provides details about the document being saved.\n * @returns {Promise<void>} Resolves when your operation is complete.\n */\n onSetDoc: (context: OnSetDocContext) => Promise<void>;\n}\n\nexport type HookConfig = OnSetDocConfig; // TODO: to be extended\n\nexport type HookFn = (config: SatelliteConfigEnv) => HookConfig;\n\nexport type HookFnOrObject = HookConfig | HookFn;\n\nexport function defineHook(config: HookConfig): HookConfig;\nexport function defineHook(config: HookFn): HookFn;\nexport function defineHook(config: HookFnOrObject): HookFnOrObject;\nexport function defineHook(config: HookFnOrObject): HookFnOrObject {\n return config;\n}\n", "import {jsonReplacer, jsonReviver} from '@dfinity/utils';\nimport type {RawData} from '../hooks/core';\n\nexport const decodeDocData = <T>(data: RawData): T =>\n JSON.parse(__juno_satellite_datastore_raw_data_to_text(data), jsonReviver);\n\nexport const encodeDocData = <T>(data: T): RawData =>\n __juno_satellite_datastore_raw_data_from_text(JSON.stringify(data, jsonReplacer));\n"],
|
|
5
|
+
"mappings": "AAoCO,SAASA,EAAaC,EAA4C,CACvE,OAAOA,CACT,CCJO,SAASC,EAAWC,EAAwC,CACjE,OAAOA,CACT,CCpCA,OAAQ,gBAAAC,EAAc,eAAAC,MAAkB,iBAGjC,IAAMC,EAAoBC,GAC/B,KAAK,MAAM,4CAA4CA,CAAI,EAAGF,CAAW,EAE9DG,EAAoBD,GAC/B,8CAA8C,KAAK,UAAUA,EAAMH,CAAY,CAAC",
|
|
6
|
+
"names": ["defineAssert", "config", "defineHook", "config", "jsonReplacer", "jsonReviver", "decodeDocData", "data", "encodeDocData"]
|
|
7
7
|
}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
export type * from './configs/assert.config';
|
|
2
1
|
export type * from './configs/collection.config';
|
|
3
|
-
export type * from './configs/hook.config';
|
|
4
2
|
export type * from './configs/satellite.config';
|
|
5
3
|
export type * from './hooks/context';
|
|
6
4
|
export type * from './hooks/core';
|
|
7
5
|
export type * from './hooks/datastore';
|
|
6
|
+
export * from './configs/assert.config';
|
|
7
|
+
export * from './configs/hook.config';
|
|
8
8
|
export * from './sdk/datastore.sdk';
|
package/package.json
CHANGED