@junobuild/functions 0.7.2-next-2026-03-20.2 → 0.7.2-next-2026-03-22
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 +66 -57
- package/functions/query.d.ts +4 -0
- package/functions/schemas/function.d.ts +14 -0
- package/functions/update.d.ts +4 -0
- package/index.js +1 -1
- package/index.js.map +3 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -51,7 +51,7 @@ JavaScript and TypeScript utilities for [Juno] Serverless Functions.
|
|
|
51
51
|
- [getAccessKeys](#gear-getaccesskeys)
|
|
52
52
|
- [isWriteAccessKey](#gear-iswriteaccesskey)
|
|
53
53
|
- [isValidAccessKey](#gear-isvalidaccesskey)
|
|
54
|
-
- [
|
|
54
|
+
- [isAdminController](#gear-isadmincontroller)
|
|
55
55
|
- [setDocStore](#gear-setdocstore)
|
|
56
56
|
- [deleteDocStore](#gear-deletedocstore)
|
|
57
57
|
- [getDocStore](#gear-getdocstore)
|
|
@@ -433,7 +433,7 @@ Returns:
|
|
|
433
433
|
|
|
434
434
|
The list of admin acces keys.
|
|
435
435
|
|
|
436
|
-
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/sdk/
|
|
436
|
+
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/sdk/access-keys.sdk.ts#L15)
|
|
437
437
|
|
|
438
438
|
#### :gear: getAccessKeys
|
|
439
439
|
|
|
@@ -447,7 +447,7 @@ Returns:
|
|
|
447
447
|
|
|
448
448
|
The list of all access keys.
|
|
449
449
|
|
|
450
|
-
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/sdk/
|
|
450
|
+
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/sdk/access-keys.sdk.ts#L24)
|
|
451
451
|
|
|
452
452
|
#### :gear: isWriteAccessKey
|
|
453
453
|
|
|
@@ -466,7 +466,7 @@ Returns:
|
|
|
466
466
|
|
|
467
467
|
Whether the id is an access key with write permission.
|
|
468
468
|
|
|
469
|
-
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/sdk/
|
|
469
|
+
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/sdk/access-keys.sdk.ts#L36)
|
|
470
470
|
|
|
471
471
|
#### :gear: isValidAccessKey
|
|
472
472
|
|
|
@@ -485,15 +485,15 @@ Returns:
|
|
|
485
485
|
|
|
486
486
|
Whether the id is an access key.
|
|
487
487
|
|
|
488
|
-
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/sdk/
|
|
488
|
+
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/sdk/access-keys.sdk.ts#L56)
|
|
489
489
|
|
|
490
|
-
#### :gear:
|
|
490
|
+
#### :gear: isAdminController
|
|
491
491
|
|
|
492
|
-
Checks if the given id is an admin among the provided access keys.
|
|
492
|
+
Checks if the given id is an admin among the provided access keys and a controller as known on the Internet Computer.
|
|
493
493
|
|
|
494
|
-
| Function
|
|
495
|
-
|
|
|
496
|
-
| `
|
|
494
|
+
| Function | Type |
|
|
495
|
+
| ------------------- | ------------------------------------------- |
|
|
496
|
+
| `isAdminController` | `(params: AccessKeyCheckParams) => boolean` |
|
|
497
497
|
|
|
498
498
|
Parameters:
|
|
499
499
|
|
|
@@ -502,9 +502,9 @@ Parameters:
|
|
|
502
502
|
|
|
503
503
|
Returns:
|
|
504
504
|
|
|
505
|
-
Whether the id is an admin.
|
|
505
|
+
Whether the id is an admin and a controller of the Satellite on the Internet Computer.
|
|
506
506
|
|
|
507
|
-
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/sdk/
|
|
507
|
+
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/sdk/access-keys.sdk.ts#L76)
|
|
508
508
|
|
|
509
509
|
#### :gear: setDocStore
|
|
510
510
|
|
|
@@ -962,6 +962,7 @@ The current timestamp.
|
|
|
962
962
|
|
|
963
963
|
- [SatelliteEnvSchema](#gear-satelliteenvschema)
|
|
964
964
|
- [JUNO_FUNCTION_TYPE](#gear-juno_function_type)
|
|
965
|
+
- [CustomFunctionGuardSchema](#gear-customfunctionguardschema)
|
|
965
966
|
- [CustomFunctionWithArgsAndResultSchema](#gear-customfunctionwithargsandresultschema)
|
|
966
967
|
- [CustomFunctionWithArgsSchema](#gear-customfunctionwithargsschema)
|
|
967
968
|
- [CustomFunctionWithResultSchema](#gear-customfunctionwithresultschema)
|
|
@@ -1089,71 +1090,79 @@ Not intended for direct use by developers.
|
|
|
1089
1090
|
|
|
1090
1091
|
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/functions/constants.ts#L5)
|
|
1091
1092
|
|
|
1093
|
+
#### :gear: CustomFunctionGuardSchema
|
|
1094
|
+
|
|
1095
|
+
| Constant | Type |
|
|
1096
|
+
| --------------------------- | ------------------------------------------------------------------------------------------------------------------- |
|
|
1097
|
+
| `CustomFunctionGuardSchema` | `ZodCustom<$InferInnerFunctionType<$ZodFunctionArgs, ZodVoid>, $InferInnerFunctionType<$ZodFunctionArgs, ZodVoid>>` |
|
|
1098
|
+
|
|
1099
|
+
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/functions/schemas/function.ts#L15)
|
|
1100
|
+
|
|
1092
1101
|
#### :gear: CustomFunctionWithArgsAndResultSchema
|
|
1093
1102
|
|
|
1094
|
-
| Constant | Type
|
|
1095
|
-
| --------------------------------------- |
|
|
1096
|
-
| `CustomFunctionWithArgsAndResultSchema` | `ZodObject<{ args: ZodCustom<ZodObject<$ZodLooseShape, $strip>, ZodObject<$ZodLooseShape, $strip>>; result: ZodCustom<...>; handler: ZodCustom<...>; type: ZodEnum<...>; }, $strict>` |
|
|
1103
|
+
| Constant | Type |
|
|
1104
|
+
| --------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
1105
|
+
| `CustomFunctionWithArgsAndResultSchema` | `ZodObject<{ args: ZodCustom<ZodObject<$ZodLooseShape, $strip>, ZodObject<$ZodLooseShape, $strip>>; result: ZodCustom<...>; handler: ZodCustom<...>; guard: ZodOptional<...>; type: ZodEnum<...>; }, $strict>` |
|
|
1097
1106
|
|
|
1098
1107
|
References:
|
|
1099
1108
|
|
|
1100
1109
|
- CustomFunctionWithArgsAndResult
|
|
1101
1110
|
|
|
1102
|
-
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/functions/schemas/function.ts#
|
|
1111
|
+
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/functions/schemas/function.ts#L31)
|
|
1103
1112
|
|
|
1104
1113
|
#### :gear: CustomFunctionWithArgsSchema
|
|
1105
1114
|
|
|
1106
|
-
| Constant | Type
|
|
1107
|
-
| ------------------------------ |
|
|
1108
|
-
| `CustomFunctionWithArgsSchema` | `ZodObject<{ args: ZodCustom<ZodObject<$ZodLooseShape, $strip>, ZodObject<$ZodLooseShape, $strip>>; handler: ZodCustom<...>; type: ZodEnum<...>; }, $strict>` |
|
|
1115
|
+
| Constant | Type |
|
|
1116
|
+
| ------------------------------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
1117
|
+
| `CustomFunctionWithArgsSchema` | `ZodObject<{ args: ZodCustom<ZodObject<$ZodLooseShape, $strip>, ZodObject<$ZodLooseShape, $strip>>; handler: ZodCustom<...>; guard: ZodOptional<...>; type: ZodEnum<...>; }, $strict>` |
|
|
1109
1118
|
|
|
1110
1119
|
References:
|
|
1111
1120
|
|
|
1112
1121
|
- CustomFunctionWithArgs
|
|
1113
1122
|
|
|
1114
|
-
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/functions/schemas/function.ts#
|
|
1123
|
+
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/functions/schemas/function.ts#L47)
|
|
1115
1124
|
|
|
1116
1125
|
#### :gear: CustomFunctionWithResultSchema
|
|
1117
1126
|
|
|
1118
|
-
| Constant | Type
|
|
1119
|
-
| -------------------------------- |
|
|
1120
|
-
| `CustomFunctionWithResultSchema` | `ZodObject<{ result: ZodCustom<ZodObject<$ZodLooseShape, $strip>, ZodObject<$ZodLooseShape, $strip>>; handler: ZodCustom<...>; type: ZodEnum<...>; }, $strict>` |
|
|
1127
|
+
| Constant | Type |
|
|
1128
|
+
| -------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
1129
|
+
| `CustomFunctionWithResultSchema` | `ZodObject<{ result: ZodCustom<ZodObject<$ZodLooseShape, $strip>, ZodObject<$ZodLooseShape, $strip>>; handler: ZodCustom<...>; guard: ZodOptional<...>; type: ZodEnum<...>; }, $strict>` |
|
|
1121
1130
|
|
|
1122
1131
|
References:
|
|
1123
1132
|
|
|
1124
1133
|
- CustomFunctionWithResult
|
|
1125
1134
|
|
|
1126
|
-
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/functions/schemas/function.ts#
|
|
1135
|
+
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/functions/schemas/function.ts#L62)
|
|
1127
1136
|
|
|
1128
1137
|
#### :gear: CustomFunctionWithoutArgsAndResultSchema
|
|
1129
1138
|
|
|
1130
|
-
| Constant | Type
|
|
1131
|
-
| ------------------------------------------ |
|
|
1132
|
-
| `CustomFunctionWithoutArgsAndResultSchema` | `ZodObject<{ handler: ZodCustom<$InferInnerFunctionType<ZodTuple<[], null>, ZodUnion<readonly [ZodVoid, ZodPromise<ZodVoid>]>>, $InferInnerFunctionType<...>>; type: ZodEnum<...>; }, $strict>` |
|
|
1139
|
+
| Constant | Type |
|
|
1140
|
+
| ------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
|
|
1141
|
+
| `CustomFunctionWithoutArgsAndResultSchema` | `ZodObject<{ handler: ZodCustom<$InferInnerFunctionType<ZodTuple<[], null>, ZodUnion<readonly [ZodVoid, ZodPromise<ZodVoid>]>>, $InferInnerFunctionType<...>>; guard: ZodOptional<...>; type: ZodEnum<...>; }, $strict>` |
|
|
1133
1142
|
|
|
1134
1143
|
References:
|
|
1135
1144
|
|
|
1136
1145
|
- CustomFunctionWithoutArgsAndResult
|
|
1137
1146
|
|
|
1138
|
-
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/functions/schemas/function.ts#
|
|
1147
|
+
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/functions/schemas/function.ts#L77)
|
|
1139
1148
|
|
|
1140
1149
|
#### :gear: CustomFunctionSchema
|
|
1141
1150
|
|
|
1142
|
-
| Constant | Type
|
|
1143
|
-
| ---------------------- |
|
|
1144
|
-
| `CustomFunctionSchema` | `ZodUnion<readonly [ZodObject<{ args: ZodCustom<ZodObject<$ZodLooseShape, $strip>, ZodObject<$ZodLooseShape, $strip>>; result: ZodCustom<...>; handler: ZodCustom<...>; type: ZodEnum<...>; }, $strict>, ZodObject<...>, ZodObject<...>, ZodObject<...>]>` |
|
|
1151
|
+
| Constant | Type |
|
|
1152
|
+
| ---------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
1153
|
+
| `CustomFunctionSchema` | `ZodUnion<readonly [ZodObject<{ args: ZodCustom<ZodObject<$ZodLooseShape, $strip>, ZodObject<$ZodLooseShape, $strip>>; result: ZodCustom<...>; handler: ZodCustom<...>; guard: ZodOptional<...>; type: ZodEnum<...>; }, $strict>, ZodObject<...>, ZodObject<...>, ZodObject<...>]>` |
|
|
1145
1154
|
|
|
1146
1155
|
References:
|
|
1147
1156
|
|
|
1148
1157
|
- CustomFunction
|
|
1149
1158
|
|
|
1150
|
-
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/functions/schemas/function.ts#
|
|
1159
|
+
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/functions/schemas/function.ts#L91)
|
|
1151
1160
|
|
|
1152
1161
|
#### :gear: QuerySchema
|
|
1153
1162
|
|
|
1154
|
-
| Constant | Type
|
|
1155
|
-
| ------------- |
|
|
1156
|
-
| `QuerySchema` | `ZodUnion<readonly [ZodObject<{ type: ZodLiteral<"__juno_function_query">; args: ZodCustom<ZodObject<$ZodLooseShape, $strip>, ZodObject<$ZodLooseShape, $strip>>; result: ZodCustom<...>; handler: ZodCustom<...>; }, $strict>, ZodObject<...>, ZodObject<...>, ZodObject<...>]>` |
|
|
1163
|
+
| Constant | Type |
|
|
1164
|
+
| ------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
1165
|
+
| `QuerySchema` | `ZodUnion<readonly [ZodObject<{ type: ZodLiteral<"__juno_function_query">; args: ZodCustom<ZodObject<$ZodLooseShape, $strip>, ZodObject<$ZodLooseShape, $strip>>; result: ZodCustom<...>; handler: ZodCustom<...>; guard: ZodOptional<...>; }, $strict>, ZodObject<...>, ZodObject<...>, ZodObject<...>]>` |
|
|
1157
1166
|
|
|
1158
1167
|
References:
|
|
1159
1168
|
|
|
@@ -1163,9 +1172,9 @@ References:
|
|
|
1163
1172
|
|
|
1164
1173
|
#### :gear: UpdateSchema
|
|
1165
1174
|
|
|
1166
|
-
| Constant | Type
|
|
1167
|
-
| -------------- |
|
|
1168
|
-
| `UpdateSchema` | `ZodUnion<readonly [ZodObject<{ type: ZodLiteral<"__juno_function_update">; args: ZodCustom<ZodObject<$ZodLooseShape, $strip>, ZodObject<$ZodLooseShape, $strip>>; result: ZodCustom<...>; handler: ZodCustom<...>; }, $strict>, ZodObject<...>, ZodObject<...>, ZodObject<...>]>` |
|
|
1175
|
+
| Constant | Type |
|
|
1176
|
+
| -------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
1177
|
+
| `UpdateSchema` | `ZodUnion<readonly [ZodObject<{ type: ZodLiteral<"__juno_function_update">; args: ZodCustom<ZodObject<$ZodLooseShape, $strip>, ZodObject<$ZodLooseShape, $strip>>; result: ZodCustom<...>; handler: ZodCustom<...>; guard: ZodOptional<...>; }, $strict>, ZodObject<...>, ZodObject<...>, ZodObject<...>]>` |
|
|
1169
1178
|
|
|
1170
1179
|
References:
|
|
1171
1180
|
|
|
@@ -1939,7 +1948,7 @@ References:
|
|
|
1939
1948
|
|
|
1940
1949
|
- AccessKeyScope
|
|
1941
1950
|
|
|
1942
|
-
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/sdk/schemas/
|
|
1951
|
+
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/sdk/schemas/access-keys.ts#L15)
|
|
1943
1952
|
|
|
1944
1953
|
#### :gear: AccessKeyKindSchema
|
|
1945
1954
|
|
|
@@ -1951,7 +1960,7 @@ References:
|
|
|
1951
1960
|
|
|
1952
1961
|
- AccessKeyKind
|
|
1953
1962
|
|
|
1954
|
-
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/sdk/schemas/
|
|
1963
|
+
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/sdk/schemas/access-keys.ts#L25)
|
|
1955
1964
|
|
|
1956
1965
|
#### :gear: MetadataSchema
|
|
1957
1966
|
|
|
@@ -1963,7 +1972,7 @@ References:
|
|
|
1963
1972
|
|
|
1964
1973
|
- MetadataSchema
|
|
1965
1974
|
|
|
1966
|
-
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/sdk/schemas/
|
|
1975
|
+
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/sdk/schemas/access-keys.ts#L35)
|
|
1967
1976
|
|
|
1968
1977
|
#### :gear: AccessKeySchema
|
|
1969
1978
|
|
|
@@ -1975,7 +1984,7 @@ References:
|
|
|
1975
1984
|
|
|
1976
1985
|
- AccessKeySchema
|
|
1977
1986
|
|
|
1978
|
-
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/sdk/schemas/
|
|
1987
|
+
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/sdk/schemas/access-keys.ts#L45)
|
|
1979
1988
|
|
|
1980
1989
|
#### :gear: AccessKeyRecordSchema
|
|
1981
1990
|
|
|
@@ -1987,7 +1996,7 @@ References:
|
|
|
1987
1996
|
|
|
1988
1997
|
- AccessKeyRecordSchema
|
|
1989
1998
|
|
|
1990
|
-
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/sdk/schemas/
|
|
1999
|
+
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/sdk/schemas/access-keys.ts#L94)
|
|
1991
2000
|
|
|
1992
2001
|
#### :gear: AccessKeysSchema
|
|
1993
2002
|
|
|
@@ -1999,7 +2008,7 @@ References:
|
|
|
1999
2008
|
|
|
2000
2009
|
- AccessKeysSchema
|
|
2001
2010
|
|
|
2002
|
-
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/sdk/schemas/
|
|
2011
|
+
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/sdk/schemas/access-keys.ts#L104)
|
|
2003
2012
|
|
|
2004
2013
|
#### :gear: AccessKeyCheckParamsSchema
|
|
2005
2014
|
|
|
@@ -2011,7 +2020,7 @@ References:
|
|
|
2011
2020
|
|
|
2012
2021
|
- AccessKeyCheckParamsSchema
|
|
2013
2022
|
|
|
2014
|
-
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/sdk/schemas/
|
|
2023
|
+
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/sdk/schemas/access-keys.ts#L114)
|
|
2015
2024
|
|
|
2016
2025
|
#### :gear: CollectionParamsSchema
|
|
2017
2026
|
|
|
@@ -2374,7 +2383,7 @@ A serverless function with both input arguments and an output result.
|
|
|
2374
2383
|
| `result` | `ZodObject<TResult, $strip>` | A Zod schema describing the output result. |
|
|
2375
2384
|
| `handler` | `(args: $InferObjectOutput<TArgs, {}>) => $InferObjectOutput<TResult, {}> or Promise<$InferObjectOutput<TResult, {}>>` | The function handler. Can be synchronous or asynchronous. param: args - The input arguments.returns |
|
|
2376
2385
|
|
|
2377
|
-
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/functions/schemas/function.ts#
|
|
2386
|
+
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/functions/schemas/function.ts#L120)
|
|
2378
2387
|
|
|
2379
2388
|
#### :gear: CustomFunctionWithArgs
|
|
2380
2389
|
|
|
@@ -2385,7 +2394,7 @@ A serverless function with input arguments but no output result.
|
|
|
2385
2394
|
| `args` | `ZodObject<TArgs, $strip>` | A Zod schema describing the input arguments. |
|
|
2386
2395
|
| `handler` | `(args: $InferObjectOutput<TArgs, {}>) => void or Promise<void>` | The function handler. Can be synchronous or asynchronous. param: args - The input arguments.returns |
|
|
2387
2396
|
|
|
2388
|
-
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/functions/schemas/function.ts#
|
|
2397
|
+
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/functions/schemas/function.ts#L150)
|
|
2389
2398
|
|
|
2390
2399
|
#### :gear: CustomFunctionWithResult
|
|
2391
2400
|
|
|
@@ -2396,7 +2405,7 @@ A serverless function with an output result but no input arguments.
|
|
|
2396
2405
|
| `result` | `ZodObject<TResult, $strip>` | A Zod schema describing the output result. |
|
|
2397
2406
|
| `handler` | `() => $InferObjectOutput<TResult, {}> or Promise<$InferObjectOutput<TResult, {}>>` | The function handler. Can be synchronous or asynchronous. returns |
|
|
2398
2407
|
|
|
2399
|
-
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/functions/schemas/function.ts#
|
|
2408
|
+
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/functions/schemas/function.ts#L170)
|
|
2400
2409
|
|
|
2401
2410
|
#### :gear: CustomFunctionWithoutArgsAndResult
|
|
2402
2411
|
|
|
@@ -2406,7 +2415,7 @@ A serverless function with no input arguments and no output result.
|
|
|
2406
2415
|
| --------- | ----------------------------- | ----------------------------------------------------------------- |
|
|
2407
2416
|
| `handler` | `() => void or Promise<void>` | The function handler. Can be synchronous or asynchronous. returns |
|
|
2408
2417
|
|
|
2409
|
-
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/functions/schemas/function.ts#
|
|
2418
|
+
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/functions/schemas/function.ts#L189)
|
|
2410
2419
|
|
|
2411
2420
|
#### :gear: Collections
|
|
2412
2421
|
|
|
@@ -2676,7 +2685,7 @@ Represents an access key with access scope and associated metadata.
|
|
|
2676
2685
|
| `scope` | `"write" or "admin" or "submit"` | The scope assigned to the access key. |
|
|
2677
2686
|
| `kind` | `"automation" or "emulator" or undefined` | An optional kind identifier of the access key. |
|
|
2678
2687
|
|
|
2679
|
-
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/sdk/schemas/
|
|
2688
|
+
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/sdk/schemas/access-keys.ts#L59)
|
|
2680
2689
|
|
|
2681
2690
|
#### :gear: AccessKeyCheckParams
|
|
2682
2691
|
|
|
@@ -2687,7 +2696,7 @@ Represents the parameters required to perform an access key checks.
|
|
|
2687
2696
|
| `id` | `any` | The identity to verify against the access keys. |
|
|
2688
2697
|
| `accessKeys` | `AccessKeys` | The list of access keys to check against. |
|
|
2689
2698
|
|
|
2690
|
-
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/sdk/schemas/
|
|
2699
|
+
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/sdk/schemas/access-keys.ts#L122)
|
|
2691
2700
|
|
|
2692
2701
|
#### :gear: CollectionParams
|
|
2693
2702
|
|
|
@@ -2874,7 +2883,7 @@ of optional input arguments and output result.
|
|
|
2874
2883
|
| ---------------- | ---- | ------------------------------------------------------------------------------------------------------------------------------------------------------------ |
|
|
2875
2884
|
| `CustomFunction` | ` | CustomFunctionWithArgsAndResult<TArgs, TResult> or CustomFunctionWithArgs<TArgs> or CustomFunctionWithResult<TResult> or CustomFunctionWithoutArgsAndResult` |
|
|
2876
2885
|
|
|
2877
|
-
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/functions/schemas/function.ts#
|
|
2886
|
+
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/functions/schemas/function.ts#L205)
|
|
2878
2887
|
|
|
2879
2888
|
#### :gear: Query
|
|
2880
2889
|
|
|
@@ -3636,7 +3645,7 @@ Represents the permission scope of an access key.
|
|
|
3636
3645
|
| ---------------- | -------------------------------------- |
|
|
3637
3646
|
| `AccessKeyScope` | `z.infer<typeof AccessKeyScopeSchema>` |
|
|
3638
3647
|
|
|
3639
|
-
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/sdk/schemas/
|
|
3648
|
+
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/sdk/schemas/access-keys.ts#L20)
|
|
3640
3649
|
|
|
3641
3650
|
#### :gear: AccessKeyKind
|
|
3642
3651
|
|
|
@@ -3646,7 +3655,7 @@ Represents a specific kind of access key. Meant for informational purposes.
|
|
|
3646
3655
|
| --------------- | ------------------------------------- |
|
|
3647
3656
|
| `AccessKeyKind` | `z.infer<typeof AccessKeyKindSchema>` |
|
|
3648
3657
|
|
|
3649
|
-
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/sdk/schemas/
|
|
3658
|
+
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/sdk/schemas/access-keys.ts#L30)
|
|
3650
3659
|
|
|
3651
3660
|
#### :gear: Metadata
|
|
3652
3661
|
|
|
@@ -3656,7 +3665,7 @@ Represents a single metadata entry as a key-value tuple.
|
|
|
3656
3665
|
| ---------- | -------------------------------- |
|
|
3657
3666
|
| `Metadata` | `z.infer<typeof MetadataSchema>` |
|
|
3658
3667
|
|
|
3659
|
-
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/sdk/schemas/
|
|
3668
|
+
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/sdk/schemas/access-keys.ts#L40)
|
|
3660
3669
|
|
|
3661
3670
|
#### :gear: AccessKeyRecord
|
|
3662
3671
|
|
|
@@ -3666,7 +3675,7 @@ Represents a tuple containing the principal ID and associated access key data.
|
|
|
3666
3675
|
| ----------------- | --------------------------------------- |
|
|
3667
3676
|
| `AccessKeyRecord` | `z.infer<typeof AccessKeyRecordSchema>` |
|
|
3668
3677
|
|
|
3669
|
-
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/sdk/schemas/
|
|
3678
|
+
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/sdk/schemas/access-keys.ts#L99)
|
|
3670
3679
|
|
|
3671
3680
|
#### :gear: AccessKeys
|
|
3672
3681
|
|
|
@@ -3676,7 +3685,7 @@ Represents a list of access keys.
|
|
|
3676
3685
|
| ------------ | ----------------------------- |
|
|
3677
3686
|
| `AccessKeys` | `[RawPrincipal, AccessKey][]` |
|
|
3678
3687
|
|
|
3679
|
-
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/sdk/schemas/
|
|
3688
|
+
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/sdk/schemas/access-keys.ts#L109)
|
|
3680
3689
|
|
|
3681
3690
|
#### :gear: ListStoreParams
|
|
3682
3691
|
|
package/functions/query.d.ts
CHANGED
|
@@ -10,17 +10,21 @@ export declare const QuerySchema: z.ZodUnion<readonly [z.ZodObject<{
|
|
|
10
10
|
args: z.ZodCustom<z.ZodObject<z.core.$ZodLooseShape, z.core.$strip>, z.ZodObject<z.core.$ZodLooseShape, z.core.$strip>>;
|
|
11
11
|
result: z.ZodCustom<z.ZodObject<z.core.$ZodLooseShape, z.core.$strip>, z.ZodObject<z.core.$ZodLooseShape, z.core.$strip>>;
|
|
12
12
|
handler: z.ZodCustom<z.core.$InferInnerFunctionType<z.ZodTuple<[z.ZodUnknown], null>, z.ZodUnion<readonly [z.ZodUnknown, z.ZodPromise<z.ZodUnknown>]>>, z.core.$InferInnerFunctionType<z.ZodTuple<[z.ZodUnknown], null>, z.ZodUnion<readonly [z.ZodUnknown, z.ZodPromise<z.ZodUnknown>]>>>;
|
|
13
|
+
guard: z.ZodOptional<z.ZodCustom<z.core.$InferInnerFunctionType<z.core.$ZodFunctionArgs, z.ZodVoid>, z.core.$InferInnerFunctionType<z.core.$ZodFunctionArgs, z.ZodVoid>>>;
|
|
13
14
|
}, z.core.$strict>, z.ZodObject<{
|
|
14
15
|
type: z.ZodLiteral<"__juno_function_query">;
|
|
15
16
|
args: z.ZodCustom<z.ZodObject<z.core.$ZodLooseShape, z.core.$strip>, z.ZodObject<z.core.$ZodLooseShape, z.core.$strip>>;
|
|
16
17
|
handler: z.ZodCustom<z.core.$InferInnerFunctionType<z.ZodTuple<[z.ZodUnknown], null>, z.ZodUnion<readonly [z.ZodVoid, z.ZodPromise<z.ZodVoid>]>>, z.core.$InferInnerFunctionType<z.ZodTuple<[z.ZodUnknown], null>, z.ZodUnion<readonly [z.ZodVoid, z.ZodPromise<z.ZodVoid>]>>>;
|
|
18
|
+
guard: z.ZodOptional<z.ZodCustom<z.core.$InferInnerFunctionType<z.core.$ZodFunctionArgs, z.ZodVoid>, z.core.$InferInnerFunctionType<z.core.$ZodFunctionArgs, z.ZodVoid>>>;
|
|
17
19
|
}, z.core.$strict>, z.ZodObject<{
|
|
18
20
|
type: z.ZodLiteral<"__juno_function_query">;
|
|
19
21
|
result: z.ZodCustom<z.ZodObject<z.core.$ZodLooseShape, z.core.$strip>, z.ZodObject<z.core.$ZodLooseShape, z.core.$strip>>;
|
|
20
22
|
handler: z.ZodCustom<z.core.$InferInnerFunctionType<z.ZodTuple<[], null>, z.ZodUnion<readonly [z.ZodUnknown, z.ZodPromise<z.ZodUnknown>]>>, z.core.$InferInnerFunctionType<z.ZodTuple<[], null>, z.ZodUnion<readonly [z.ZodUnknown, z.ZodPromise<z.ZodUnknown>]>>>;
|
|
23
|
+
guard: z.ZodOptional<z.ZodCustom<z.core.$InferInnerFunctionType<z.core.$ZodFunctionArgs, z.ZodVoid>, z.core.$InferInnerFunctionType<z.core.$ZodFunctionArgs, z.ZodVoid>>>;
|
|
21
24
|
}, z.core.$strict>, z.ZodObject<{
|
|
22
25
|
type: z.ZodLiteral<"__juno_function_query">;
|
|
23
26
|
handler: z.ZodCustom<z.core.$InferInnerFunctionType<z.ZodTuple<[], null>, z.ZodUnion<readonly [z.ZodVoid, z.ZodPromise<z.ZodVoid>]>>, z.core.$InferInnerFunctionType<z.ZodTuple<[], null>, z.ZodUnion<readonly [z.ZodVoid, z.ZodPromise<z.ZodVoid>]>>>;
|
|
27
|
+
guard: z.ZodOptional<z.ZodCustom<z.core.$InferInnerFunctionType<z.core.$ZodFunctionArgs, z.ZodVoid>, z.core.$InferInnerFunctionType<z.core.$ZodFunctionArgs, z.ZodVoid>>>;
|
|
24
28
|
}, z.core.$strict>]>;
|
|
25
29
|
/**
|
|
26
30
|
* The input shape for defining a query serverless function.
|
|
@@ -5,6 +5,7 @@ import { JUNO_FUNCTION_TYPE } from '../constants';
|
|
|
5
5
|
* to discover the functions when parsing the code.
|
|
6
6
|
*/
|
|
7
7
|
export type CustomFunctionType = (typeof JUNO_FUNCTION_TYPE)[keyof typeof JUNO_FUNCTION_TYPE];
|
|
8
|
+
export declare const CustomFunctionGuardSchema: z.ZodCustom<z.core.$InferInnerFunctionType<z.core.$ZodFunctionArgs, z.ZodVoid>, z.core.$InferInnerFunctionType<z.core.$ZodFunctionArgs, z.ZodVoid>>;
|
|
8
9
|
/**
|
|
9
10
|
* @see CustomFunctionWithArgsAndResult
|
|
10
11
|
*/
|
|
@@ -12,6 +13,7 @@ export declare const CustomFunctionWithArgsAndResultSchema: z.ZodObject<{
|
|
|
12
13
|
args: z.ZodCustom<z.ZodObject<z.core.$ZodLooseShape, z.core.$strip>, z.ZodObject<z.core.$ZodLooseShape, z.core.$strip>>;
|
|
13
14
|
result: z.ZodCustom<z.ZodObject<z.core.$ZodLooseShape, z.core.$strip>, z.ZodObject<z.core.$ZodLooseShape, z.core.$strip>>;
|
|
14
15
|
handler: z.ZodCustom<z.core.$InferInnerFunctionType<z.ZodTuple<[z.ZodUnknown], null>, z.ZodUnion<readonly [z.ZodUnknown, z.ZodPromise<z.ZodUnknown>]>>, z.core.$InferInnerFunctionType<z.ZodTuple<[z.ZodUnknown], null>, z.ZodUnion<readonly [z.ZodUnknown, z.ZodPromise<z.ZodUnknown>]>>>;
|
|
16
|
+
guard: z.ZodOptional<z.ZodCustom<z.core.$InferInnerFunctionType<z.core.$ZodFunctionArgs, z.ZodVoid>, z.core.$InferInnerFunctionType<z.core.$ZodFunctionArgs, z.ZodVoid>>>;
|
|
15
17
|
type: z.ZodEnum<{
|
|
16
18
|
__juno_function_query: "__juno_function_query";
|
|
17
19
|
__juno_function_update: "__juno_function_update";
|
|
@@ -23,6 +25,7 @@ export declare const CustomFunctionWithArgsAndResultSchema: z.ZodObject<{
|
|
|
23
25
|
export declare const CustomFunctionWithArgsSchema: z.ZodObject<{
|
|
24
26
|
args: z.ZodCustom<z.ZodObject<z.core.$ZodLooseShape, z.core.$strip>, z.ZodObject<z.core.$ZodLooseShape, z.core.$strip>>;
|
|
25
27
|
handler: z.ZodCustom<z.core.$InferInnerFunctionType<z.ZodTuple<[z.ZodUnknown], null>, z.ZodUnion<readonly [z.ZodVoid, z.ZodPromise<z.ZodVoid>]>>, z.core.$InferInnerFunctionType<z.ZodTuple<[z.ZodUnknown], null>, z.ZodUnion<readonly [z.ZodVoid, z.ZodPromise<z.ZodVoid>]>>>;
|
|
28
|
+
guard: z.ZodOptional<z.ZodCustom<z.core.$InferInnerFunctionType<z.core.$ZodFunctionArgs, z.ZodVoid>, z.core.$InferInnerFunctionType<z.core.$ZodFunctionArgs, z.ZodVoid>>>;
|
|
26
29
|
type: z.ZodEnum<{
|
|
27
30
|
__juno_function_query: "__juno_function_query";
|
|
28
31
|
__juno_function_update: "__juno_function_update";
|
|
@@ -34,6 +37,7 @@ export declare const CustomFunctionWithArgsSchema: z.ZodObject<{
|
|
|
34
37
|
export declare const CustomFunctionWithResultSchema: z.ZodObject<{
|
|
35
38
|
result: z.ZodCustom<z.ZodObject<z.core.$ZodLooseShape, z.core.$strip>, z.ZodObject<z.core.$ZodLooseShape, z.core.$strip>>;
|
|
36
39
|
handler: z.ZodCustom<z.core.$InferInnerFunctionType<z.ZodTuple<[], null>, z.ZodUnion<readonly [z.ZodUnknown, z.ZodPromise<z.ZodUnknown>]>>, z.core.$InferInnerFunctionType<z.ZodTuple<[], null>, z.ZodUnion<readonly [z.ZodUnknown, z.ZodPromise<z.ZodUnknown>]>>>;
|
|
40
|
+
guard: z.ZodOptional<z.ZodCustom<z.core.$InferInnerFunctionType<z.core.$ZodFunctionArgs, z.ZodVoid>, z.core.$InferInnerFunctionType<z.core.$ZodFunctionArgs, z.ZodVoid>>>;
|
|
37
41
|
type: z.ZodEnum<{
|
|
38
42
|
__juno_function_query: "__juno_function_query";
|
|
39
43
|
__juno_function_update: "__juno_function_update";
|
|
@@ -44,6 +48,7 @@ export declare const CustomFunctionWithResultSchema: z.ZodObject<{
|
|
|
44
48
|
*/
|
|
45
49
|
export declare const CustomFunctionWithoutArgsAndResultSchema: z.ZodObject<{
|
|
46
50
|
handler: z.ZodCustom<z.core.$InferInnerFunctionType<z.ZodTuple<[], null>, z.ZodUnion<readonly [z.ZodVoid, z.ZodPromise<z.ZodVoid>]>>, z.core.$InferInnerFunctionType<z.ZodTuple<[], null>, z.ZodUnion<readonly [z.ZodVoid, z.ZodPromise<z.ZodVoid>]>>>;
|
|
51
|
+
guard: z.ZodOptional<z.ZodCustom<z.core.$InferInnerFunctionType<z.core.$ZodFunctionArgs, z.ZodVoid>, z.core.$InferInnerFunctionType<z.core.$ZodFunctionArgs, z.ZodVoid>>>;
|
|
47
52
|
type: z.ZodEnum<{
|
|
48
53
|
__juno_function_query: "__juno_function_query";
|
|
49
54
|
__juno_function_update: "__juno_function_update";
|
|
@@ -56,6 +61,7 @@ export declare const CustomFunctionSchema: z.ZodUnion<readonly [z.ZodObject<{
|
|
|
56
61
|
args: z.ZodCustom<z.ZodObject<z.core.$ZodLooseShape, z.core.$strip>, z.ZodObject<z.core.$ZodLooseShape, z.core.$strip>>;
|
|
57
62
|
result: z.ZodCustom<z.ZodObject<z.core.$ZodLooseShape, z.core.$strip>, z.ZodObject<z.core.$ZodLooseShape, z.core.$strip>>;
|
|
58
63
|
handler: z.ZodCustom<z.core.$InferInnerFunctionType<z.ZodTuple<[z.ZodUnknown], null>, z.ZodUnion<readonly [z.ZodUnknown, z.ZodPromise<z.ZodUnknown>]>>, z.core.$InferInnerFunctionType<z.ZodTuple<[z.ZodUnknown], null>, z.ZodUnion<readonly [z.ZodUnknown, z.ZodPromise<z.ZodUnknown>]>>>;
|
|
64
|
+
guard: z.ZodOptional<z.ZodCustom<z.core.$InferInnerFunctionType<z.core.$ZodFunctionArgs, z.ZodVoid>, z.core.$InferInnerFunctionType<z.core.$ZodFunctionArgs, z.ZodVoid>>>;
|
|
59
65
|
type: z.ZodEnum<{
|
|
60
66
|
__juno_function_query: "__juno_function_query";
|
|
61
67
|
__juno_function_update: "__juno_function_update";
|
|
@@ -63,6 +69,7 @@ export declare const CustomFunctionSchema: z.ZodUnion<readonly [z.ZodObject<{
|
|
|
63
69
|
}, z.core.$strict>, z.ZodObject<{
|
|
64
70
|
args: z.ZodCustom<z.ZodObject<z.core.$ZodLooseShape, z.core.$strip>, z.ZodObject<z.core.$ZodLooseShape, z.core.$strip>>;
|
|
65
71
|
handler: z.ZodCustom<z.core.$InferInnerFunctionType<z.ZodTuple<[z.ZodUnknown], null>, z.ZodUnion<readonly [z.ZodVoid, z.ZodPromise<z.ZodVoid>]>>, z.core.$InferInnerFunctionType<z.ZodTuple<[z.ZodUnknown], null>, z.ZodUnion<readonly [z.ZodVoid, z.ZodPromise<z.ZodVoid>]>>>;
|
|
72
|
+
guard: z.ZodOptional<z.ZodCustom<z.core.$InferInnerFunctionType<z.core.$ZodFunctionArgs, z.ZodVoid>, z.core.$InferInnerFunctionType<z.core.$ZodFunctionArgs, z.ZodVoid>>>;
|
|
66
73
|
type: z.ZodEnum<{
|
|
67
74
|
__juno_function_query: "__juno_function_query";
|
|
68
75
|
__juno_function_update: "__juno_function_update";
|
|
@@ -70,12 +77,14 @@ export declare const CustomFunctionSchema: z.ZodUnion<readonly [z.ZodObject<{
|
|
|
70
77
|
}, z.core.$strict>, z.ZodObject<{
|
|
71
78
|
result: z.ZodCustom<z.ZodObject<z.core.$ZodLooseShape, z.core.$strip>, z.ZodObject<z.core.$ZodLooseShape, z.core.$strip>>;
|
|
72
79
|
handler: z.ZodCustom<z.core.$InferInnerFunctionType<z.ZodTuple<[], null>, z.ZodUnion<readonly [z.ZodUnknown, z.ZodPromise<z.ZodUnknown>]>>, z.core.$InferInnerFunctionType<z.ZodTuple<[], null>, z.ZodUnion<readonly [z.ZodUnknown, z.ZodPromise<z.ZodUnknown>]>>>;
|
|
80
|
+
guard: z.ZodOptional<z.ZodCustom<z.core.$InferInnerFunctionType<z.core.$ZodFunctionArgs, z.ZodVoid>, z.core.$InferInnerFunctionType<z.core.$ZodFunctionArgs, z.ZodVoid>>>;
|
|
73
81
|
type: z.ZodEnum<{
|
|
74
82
|
__juno_function_query: "__juno_function_query";
|
|
75
83
|
__juno_function_update: "__juno_function_update";
|
|
76
84
|
}>;
|
|
77
85
|
}, z.core.$strict>, z.ZodObject<{
|
|
78
86
|
handler: z.ZodCustom<z.core.$InferInnerFunctionType<z.ZodTuple<[], null>, z.ZodUnion<readonly [z.ZodVoid, z.ZodPromise<z.ZodVoid>]>>, z.core.$InferInnerFunctionType<z.ZodTuple<[], null>, z.ZodUnion<readonly [z.ZodVoid, z.ZodPromise<z.ZodVoid>]>>>;
|
|
87
|
+
guard: z.ZodOptional<z.ZodCustom<z.core.$InferInnerFunctionType<z.core.$ZodFunctionArgs, z.ZodVoid>, z.core.$InferInnerFunctionType<z.core.$ZodFunctionArgs, z.ZodVoid>>>;
|
|
79
88
|
type: z.ZodEnum<{
|
|
80
89
|
__juno_function_query: "__juno_function_query";
|
|
81
90
|
__juno_function_update: "__juno_function_update";
|
|
@@ -89,6 +98,11 @@ interface CustomFunctionBase {
|
|
|
89
98
|
* The type of the function, either a query or an update.
|
|
90
99
|
*/
|
|
91
100
|
type: CustomFunctionType;
|
|
101
|
+
/**
|
|
102
|
+
* An optional function that runs before the function is executed.
|
|
103
|
+
* If the guard throws, the function is not executed.
|
|
104
|
+
*/
|
|
105
|
+
guard?: () => void;
|
|
92
106
|
}
|
|
93
107
|
/**
|
|
94
108
|
* A serverless function with both input arguments and an output result.
|
package/functions/update.d.ts
CHANGED
|
@@ -10,17 +10,21 @@ export declare const UpdateSchema: z.ZodUnion<readonly [z.ZodObject<{
|
|
|
10
10
|
args: z.ZodCustom<z.ZodObject<z.core.$ZodLooseShape, z.core.$strip>, z.ZodObject<z.core.$ZodLooseShape, z.core.$strip>>;
|
|
11
11
|
result: z.ZodCustom<z.ZodObject<z.core.$ZodLooseShape, z.core.$strip>, z.ZodObject<z.core.$ZodLooseShape, z.core.$strip>>;
|
|
12
12
|
handler: z.ZodCustom<z.core.$InferInnerFunctionType<z.ZodTuple<[z.ZodUnknown], null>, z.ZodUnion<readonly [z.ZodUnknown, z.ZodPromise<z.ZodUnknown>]>>, z.core.$InferInnerFunctionType<z.ZodTuple<[z.ZodUnknown], null>, z.ZodUnion<readonly [z.ZodUnknown, z.ZodPromise<z.ZodUnknown>]>>>;
|
|
13
|
+
guard: z.ZodOptional<z.ZodCustom<z.core.$InferInnerFunctionType<z.core.$ZodFunctionArgs, z.ZodVoid>, z.core.$InferInnerFunctionType<z.core.$ZodFunctionArgs, z.ZodVoid>>>;
|
|
13
14
|
}, z.core.$strict>, z.ZodObject<{
|
|
14
15
|
type: z.ZodLiteral<"__juno_function_update">;
|
|
15
16
|
args: z.ZodCustom<z.ZodObject<z.core.$ZodLooseShape, z.core.$strip>, z.ZodObject<z.core.$ZodLooseShape, z.core.$strip>>;
|
|
16
17
|
handler: z.ZodCustom<z.core.$InferInnerFunctionType<z.ZodTuple<[z.ZodUnknown], null>, z.ZodUnion<readonly [z.ZodVoid, z.ZodPromise<z.ZodVoid>]>>, z.core.$InferInnerFunctionType<z.ZodTuple<[z.ZodUnknown], null>, z.ZodUnion<readonly [z.ZodVoid, z.ZodPromise<z.ZodVoid>]>>>;
|
|
18
|
+
guard: z.ZodOptional<z.ZodCustom<z.core.$InferInnerFunctionType<z.core.$ZodFunctionArgs, z.ZodVoid>, z.core.$InferInnerFunctionType<z.core.$ZodFunctionArgs, z.ZodVoid>>>;
|
|
17
19
|
}, z.core.$strict>, z.ZodObject<{
|
|
18
20
|
type: z.ZodLiteral<"__juno_function_update">;
|
|
19
21
|
result: z.ZodCustom<z.ZodObject<z.core.$ZodLooseShape, z.core.$strip>, z.ZodObject<z.core.$ZodLooseShape, z.core.$strip>>;
|
|
20
22
|
handler: z.ZodCustom<z.core.$InferInnerFunctionType<z.ZodTuple<[], null>, z.ZodUnion<readonly [z.ZodUnknown, z.ZodPromise<z.ZodUnknown>]>>, z.core.$InferInnerFunctionType<z.ZodTuple<[], null>, z.ZodUnion<readonly [z.ZodUnknown, z.ZodPromise<z.ZodUnknown>]>>>;
|
|
23
|
+
guard: z.ZodOptional<z.ZodCustom<z.core.$InferInnerFunctionType<z.core.$ZodFunctionArgs, z.ZodVoid>, z.core.$InferInnerFunctionType<z.core.$ZodFunctionArgs, z.ZodVoid>>>;
|
|
21
24
|
}, z.core.$strict>, z.ZodObject<{
|
|
22
25
|
type: z.ZodLiteral<"__juno_function_update">;
|
|
23
26
|
handler: z.ZodCustom<z.core.$InferInnerFunctionType<z.ZodTuple<[], null>, z.ZodUnion<readonly [z.ZodVoid, z.ZodPromise<z.ZodVoid>]>>, z.core.$InferInnerFunctionType<z.ZodTuple<[], null>, z.ZodUnion<readonly [z.ZodVoid, z.ZodPromise<z.ZodVoid>]>>>;
|
|
27
|
+
guard: z.ZodOptional<z.ZodCustom<z.core.$InferInnerFunctionType<z.core.$ZodFunctionArgs, z.ZodVoid>, z.core.$InferInnerFunctionType<z.core.$ZodFunctionArgs, z.ZodVoid>>>;
|
|
24
28
|
}, z.core.$strict>]>;
|
|
25
29
|
/**
|
|
26
30
|
* The input shape for defining an update serverless function.
|
package/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{A as
|
|
1
|
+
import{A as $e,B as et,C as tt,D as ot,E as Q,F as N,a as ve,b as Ee,c as K,d as We,e as q,f as L,g as Qe,h as Ne,i as u,j as Me,k as V,l as X,m as Pe,n as Be,o as Ye,p as Ie,q as d,r as Je,s as $,t as ee,u as Ge,v as Ke,w as qe,x as Le,y as Ve,z as Xe}from"./chunk-X2OX4F6M.js";import{a as He}from"./chunk-JU5CZHLY.js";import"./chunk-4C666HHU.js";import*as s from"zod";import*as O from"zod";var x=O.record(O.string(),O.string());import*as te from"zod";var n=e=>te.custom(o=>typeof o=="function"&&e.implement(o));var i={QUERY:"__juno_function_query",UPDATE:"__juno_function_update"};import*as t from"zod";var U=t.strictObject({type:t.enum([i.QUERY,i.UPDATE])}),M=n(t.function({output:t.void()})),Z=t.strictObject({guard:M.optional()}),C=t.strictObject({...U.shape,...Z.shape,args:t.instanceof(t.ZodObject),result:t.instanceof(t.ZodObject),handler:n(t.function({input:t.tuple([t.unknown()]),output:t.union([t.unknown(),t.promise(t.unknown())])}))}),R=t.strictObject({...U.shape,...Z.shape,args:t.instanceof(t.ZodObject),handler:n(t.function({input:t.tuple([t.unknown()]),output:t.union([t.void(),t.promise(t.void())])}))}),F=t.strictObject({...U.shape,...Z.shape,result:t.instanceof(t.ZodObject),handler:n(t.function({input:t.tuple([]),output:t.union([t.unknown(),t.promise(t.unknown())])}))}),g=t.strictObject({...U.shape,...Z.shape,handler:n(t.function({input:t.tuple([]),output:t.union([t.void(),t.promise(t.void())])}))}),at=t.union([C,R,F,g]);var k=s.strictObject({type:s.literal(i.QUERY)}),b=s.union([s.strictObject({...C.shape,...k.shape}),s.strictObject({...R.shape,...k.shape}),s.strictObject({...F.shape,...k.shape}),s.strictObject({...g.shape,...k.shape})]),ye=e=>s.function({input:s.tuple([x]),output:e}),xt=e=>s.union([e,n(ye(e))]);function At(e){if(typeof e=="function")return a=>{let A={...e(a),type:i.QUERY};return b.parse(A),A};let o={...e,type:i.QUERY};return b.parse(o),o}import*as r from"zod";var j=r.strictObject({type:r.literal(i.UPDATE)}),w=r.union([r.strictObject({...C.shape,...j.shape}),r.strictObject({...R.shape,...j.shape}),r.strictObject({...F.shape,...j.shape}),r.strictObject({...g.shape,...j.shape})]),Se=e=>r.function({input:r.tuple([x]),output:e}),ft=e=>r.union([e,n(Se(e))]);function Dt(e){if(typeof e=="function")return a=>{let A={...e(a),type:i.UPDATE};return w.parse(A),A};let o={...e,type:i.UPDATE};return w.parse(o),o}import*as y from"zod";import*as z from"zod";var _=z.object({collections:z.array(z.string()).readonly()}).strict();import*as p from"zod";var c=e=>p.strictObject({caller:K,data:e}),oe=e=>n(p.function({input:p.tuple([e]),output:p.void()})),ne=e=>n(p.function({input:p.tuple([e]),output:p.promise(p.void()).or(p.void())}));import*as f from"zod";import*as H from"zod";var P=H.object({before:u.optional(),after:u}).strict(),se=H.object({current:u.optional(),proposed:V}).strict(),re=H.object({current:u.optional(),proposed:X}).strict();var T=e=>f.strictObject({collection:q,key:L,data:e}),ce=c(T(P)),pe=c(f.array(T(P))),B=c(T(u.optional())),Y=c(f.array(T(u.optional()))),I=c(f.array(T(u.optional()))),ae=c(T(se)),ie=c(T(re));import*as J from"zod";import*as ue from"zod";var le=ue.object({current:d.optional(),batch:$,commit_batch:ee}).strict();var me=c(d),de=c(d.optional()),xe=c(J.array(d.optional())),Ae=c(J.array(d.optional())),he=c(le),Te=c(d);var v=e=>_.extend({assert:oe(e)}).strict(),ze=v(ae),fe=v(ie),De=v(he),Oe=v(Te),Gt=y.union([ze,fe,De,Oe]),Ce=e=>y.function({input:y.tuple([x]),output:e}),Kt=e=>y.union([e,n(Ce(e))]);function qt(e){return e}import*as S from"zod";var l=e=>_.extend({run:ne(e)}).strict(),Re=l(ce),Fe=l(pe),no=l(B),so=l(Y),ro=l(I),ge=l(me),Ue=l(de),Ze=l(xe),ke=l(Ae),co=S.union([Re,Fe,B,Y,I,ge,Ue,Ze,ke]),be=e=>S.function({input:S.tuple([x]),output:e}),po=e=>S.union([e,n(be(e))]);function ao(e){return e}import{nonNullish as D}from"@dfinity/utils";import*as m from"zod";var G=m.union([b,w]),je=G.and(m.strictObject({guard:M}));globalThis.__juno_satellite_fn_guard_sync=e=>{je.parse(e).guard()};globalThis.__juno_satellite_fn_invoke_sync=(e,o)=>{G.parse(e);let a="args"in e&&e.args instanceof m.ZodType?e.args?.parse(D(o)?Q(o):void 0):void 0,W=D(a)?e.handler(a):e.handler(),h="result"in e&&e.result instanceof m.ZodType?e.result?.parse(W):void 0;globalThis.jsResult=D(h)?N(h):h};globalThis.__juno_satellite_fn_invoke_async=async(e,o)=>{G.parse(e);let a="args"in e&&e.args instanceof m.ZodType?e.args?.parse(D(o)?Q(o):void 0):void 0,W=await(async()=>D(a)?await e.handler(a):await e.handler())(),h="result"in e&&e.result instanceof m.ZodType?e.result?.parse(W):void 0;globalThis.jsResult=D(h)?N(h):h};import{jsonReplacer as we}from"@dfinity/utils";var E=e=>{let o=e.map(a=>typeof a=="object"?JSON.stringify(a,we):a).join(" ");globalThis.__ic_cdk_print(o)};globalThis.console={info(...e){E(e)},log(...e){E(e)},warn(...e){E(e)},error(...e){E(e)}};var _e=()=>(__juno_satellite_random()>>>0)/4294967296;globalThis.Math.random=_e;export{Te as AssertDeleteAssetContextSchema,Oe as AssertDeleteAssetSchema,ie as AssertDeleteDocContextSchema,fe as AssertDeleteDocSchema,Kt as AssertFnOrObjectSchema,Ce as AssertFnSchema,oe as AssertFunctionSchema,Gt as AssertSchema,ae as AssertSetDocContextSchema,ze as AssertSetDocSchema,he as AssertUploadAssetContextSchema,De as AssertUploadAssetSchema,Ke as AssetAccessTokenSchema,le as AssetAssertUploadSchema,Ie as AssetEncodingSchema,Ye as AssetKeySchema,Je as AssetNoContentSchema,d as AssetSchema,$ as BatchSchema,Be as BlobSchema,q as CollectionSchema,_ as CollectionsSchema,ee as CommitBatchSchema,M as CustomFunctionGuardSchema,at as CustomFunctionSchema,C as CustomFunctionWithArgsAndResultSchema,R as CustomFunctionWithArgsSchema,F as CustomFunctionWithResultSchema,g as CustomFunctionWithoutArgsAndResultSchema,X as DelDocSchema,Qe as DescriptionSchema,re as DocAssertDeleteSchema,se as DocAssertSetSchema,T as DocContextSchema,u as DocSchema,P as DocUpsertSchema,Ge as FullPathSchema,Pe as HeaderFieldsSchema,c as HookContextSchema,po as HookFnOrObjectSchema,be as HookFnSchema,co as HookSchema,L as KeySchema,Ve as ListMatcherSchema,$e as ListOrderFieldSchema,et as ListOrderSchema,Xe as ListPaginateSchema,tt as ListParamsSchema,de as OnDeleteAssetContextSchema,Ue as OnDeleteAssetSchema,B as OnDeleteDocContextSchema,no as OnDeleteDocSchema,Ae as OnDeleteFilteredAssetsContextSchema,ke as OnDeleteFilteredAssetsSchema,I as OnDeleteFilteredDocsContextSchema,ro as OnDeleteFilteredDocsSchema,xe as OnDeleteManyAssetsContextSchema,Ze as OnDeleteManyAssetsSchema,Y as OnDeleteManyDocsContextSchema,so as OnDeleteManyDocsSchema,ce as OnSetDocContextSchema,Re as OnSetDocSchema,pe as OnSetManyDocsContextSchema,Fe as OnSetManyDocsSchema,me as OnUploadAssetContextSchema,ge as OnUploadAssetSchema,qe as OptionAssetSchema,Me as OptionDocSchema,xt as QueryFnOrObjectSchema,ye as QueryFnSchema,b as QuerySchema,Ne as RawDataSchema,He as RawPrincipalSchema,K as RawUserIdSchema,ne as RunFunctionSchema,x as SatelliteEnvSchema,V as SetDocSchema,Le as TimestampMatcherSchema,ve as TimestampSchema,ft as UpdateFnOrObjectSchema,Se as UpdateFnSchema,w as UpdateSchema,We as UserIdSchema,Ee as VersionSchema,ot as createListResultsSchema,qt as defineAssert,ao as defineHook,At as defineQuery,Dt as defineUpdate};
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
package/index.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["src/functions/query.ts", "src/schemas/satellite.env.ts", "src/utils/zod.utils.ts", "src/functions/constants.ts", "src/functions/schemas/function.ts", "src/functions/update.ts", "src/hooks/assertions.ts", "src/hooks/schemas/collections.ts", "src/hooks/schemas/context.ts", "src/hooks/schemas/db/context.ts", "src/hooks/schemas/db/payload.ts", "src/hooks/schemas/storage/context.ts", "src/hooks/schemas/storage/payload.ts", "src/hooks/hooks.ts", "src/functions/wrappers.ts", "src/polyfills/console.polyfill.ts", "src/polyfills/random.polyfill.ts"],
|
|
4
|
-
"sourcesContent": ["import * as z from 'zod';\nimport {type SatelliteEnv, SatelliteEnvSchema} from '../schemas/satellite.env';\nimport {createFunctionSchema} from '../utils/zod.utils';\nimport {JUNO_FUNCTION_TYPE} from './constants';\nimport {\n type CustomFunctionWithArgs,\n type CustomFunctionWithArgsAndResult,\n type CustomFunctionWithoutArgsAndResult,\n type CustomFunctionWithResult,\n CustomFunctionWithArgsAndResultSchema,\n CustomFunctionWithArgsSchema,\n CustomFunctionWithoutArgsAndResultSchema,\n CustomFunctionWithResultSchema\n} from './schemas/function';\n\nconst QueryBaseSchema = z.strictObject({\n type: z.literal(JUNO_FUNCTION_TYPE.QUERY)\n});\n\n/**\n * @see Query\n */\nexport const QuerySchema = z.union([\n z.strictObject({\n ...CustomFunctionWithArgsAndResultSchema.shape,\n ...QueryBaseSchema.shape\n }),\n z.strictObject({\n ...CustomFunctionWithArgsSchema.shape,\n ...QueryBaseSchema.shape\n }),\n z.strictObject({\n ...CustomFunctionWithResultSchema.shape,\n ...QueryBaseSchema.shape\n }),\n z.strictObject({\n ...CustomFunctionWithoutArgsAndResultSchema.shape,\n ...QueryBaseSchema.shape\n })\n]);\n\n/**\n * The input shape for defining a query serverless function.\n * Does not include `type`, which is injected by `defineQuery`.\n */\nexport type Query<\n TArgs extends z.ZodRawShape = z.ZodRawShape,\n TResult extends z.ZodRawShape = z.ZodRawShape\n> =\n | Omit<CustomFunctionWithArgsAndResult<TArgs, TResult>, 'type'>\n | Omit<CustomFunctionWithArgs<TArgs>, 'type'>\n | Omit<CustomFunctionWithResult<TResult>, 'type'>\n | Omit<CustomFunctionWithoutArgsAndResult, 'type'>;\n\n/**\n * A query function definition with `type` injected by `defineQuery`.\n * Queries are read-only functions that do not modify state.\n */\nexport type QueryDefinition<\n TArgs extends z.ZodRawShape = z.ZodRawShape,\n TResult extends z.ZodRawShape = z.ZodRawShape\n> = Query<TArgs, TResult> & {\n type: typeof JUNO_FUNCTION_TYPE.QUERY;\n};\n\nexport const QueryFnSchema = <T extends z.ZodTypeAny>(querySchema: T) =>\n z.function({input: z.tuple([SatelliteEnvSchema]), output: querySchema});\n\n/**\n * A factory function that receives the satellite environment and returns a query definition.\n */\nexport type QueryFn<TArgs extends z.ZodRawShape, TResult extends z.ZodRawShape> = (\n env: SatelliteEnv\n) => Query<TArgs, TResult>;\n\nexport const QueryFnOrObjectSchema = <T extends z.ZodTypeAny>(querySchema: T) =>\n z.union([querySchema, createFunctionSchema(QueryFnSchema(querySchema))]);\n\n/**\n * A query definition or a factory function that returns one.\n */\nexport type QueryFnOrObject<TArgs extends z.ZodRawShape, TResult extends z.ZodRawShape> =\n | Query<TArgs, TResult>\n | QueryFn<TArgs, TResult>;\n\nexport function defineQuery<TArgs extends z.ZodRawShape, TResult extends z.ZodRawShape>(\n query: Query<TArgs, TResult>\n): QueryDefinition<TArgs, TResult>;\nexport function defineQuery<TArgs extends z.ZodRawShape, TResult extends z.ZodRawShape>(\n query: QueryFn<TArgs, TResult>\n): (env: SatelliteEnv) => QueryDefinition<TArgs, TResult>;\nexport function defineQuery<TArgs extends z.ZodRawShape, TResult extends z.ZodRawShape>(\n query: QueryFnOrObject<TArgs, TResult>\n): QueryDefinition<TArgs, TResult> | ((env: SatelliteEnv) => QueryDefinition<TArgs, TResult>);\nexport function defineQuery<TArgs extends z.ZodRawShape, TResult extends z.ZodRawShape>(\n query: Query<TArgs, TResult> | QueryFn<TArgs, TResult>\n): QueryDefinition<TArgs, TResult> | ((env: SatelliteEnv) => QueryDefinition<TArgs, TResult>) {\n if (typeof query === 'function') {\n return (env: SatelliteEnv) => {\n const result = {...query(env), type: JUNO_FUNCTION_TYPE.QUERY};\n QuerySchema.parse(result);\n return result;\n };\n }\n\n const result = {...query, type: JUNO_FUNCTION_TYPE.QUERY};\n QuerySchema.parse(result);\n return result;\n}\n", "import * as z from 'zod';\n\n/**\n * @see SatelliteEnv\n */\nexport const SatelliteEnvSchema = z.record(z.string(), z.string());\n\n/**\n * Placeholder for future environment-specific configurations.\n *\n * Currently unused, but it may support features such as:\n * - Defining the execution mode (e.g., staging or production).\n * - Providing environment-specific values like `ckBtcLedgerId` for test or production.\n */\nexport type SatelliteEnv = z.infer<typeof SatelliteEnvSchema>;\n", "import * as z from 'zod';\n\n/**\n * Wraps a Zod function schema so that parsing returns the **original function**\n * instead of Zod's wrapped validator.\n *\n * Why?\n * ----\n * In Zod v4, `z.function({...})` normally returns a wrapper that validates\n * both arguments and the return value **every time the function is called**.\n * If your function's return type is `void | Promise<void>`, Zod tries to\n * validate it synchronously, which can throw\n * \"Encountered Promise during synchronous parse\"\n * when the implementation is async.\n *\n * By using `.implement`, we tell Zod: \u201Cthis is the function that satisfies\n * the schema.\u201D That way the schema still validates the function shape at\n * parse time, but the returned value is the **original function** you passed\n * in \u2014 no runtime wrapper, no sync/async mismatch.\n *\n * Reference:\n * https://github.com/colinhacks/zod/issues/4143#issuecomment-2845134912\n *\n * Note: We need the function for this library, see following comment\n * https://github.com/colinhacks/zod/issues/4143#issuecomment-3335735535\n */\nexport const createFunctionSchema = <T extends z.ZodFunction>(schema: T) =>\n z.custom<Parameters<T['implement']>[0]>(\n (fn) => typeof fn === 'function' && schema.implement(fn as Parameters<T['implement']>[0])\n );\n", "/**\n * Internal constant used by Juno's tooling to discover serverless functions.\n * Not intended for direct use by developers.\n */\nexport const JUNO_FUNCTION_TYPE = {\n QUERY: '__juno_function_query',\n UPDATE: '__juno_function_update'\n} as const;\n", "import * as z from 'zod';\nimport {createFunctionSchema} from '../../utils/zod.utils';\nimport {JUNO_FUNCTION_TYPE} from '../constants';\n\n/**\n * The type of a serverless function. Not exposed to the developer. It allows the CLI\n * to discover the functions when parsing the code.\n */\nexport type CustomFunctionType = (typeof JUNO_FUNCTION_TYPE)[keyof typeof JUNO_FUNCTION_TYPE];\n\nconst CustomFunctionBaseSchema = z.strictObject({\n type: z.enum([JUNO_FUNCTION_TYPE.QUERY, JUNO_FUNCTION_TYPE.UPDATE])\n});\n\n/**\n * @see CustomFunctionWithArgsAndResult\n */\nexport const CustomFunctionWithArgsAndResultSchema = z.strictObject({\n ...CustomFunctionBaseSchema.shape,\n args: z.instanceof(z.ZodObject),\n result: z.instanceof(z.ZodObject),\n handler: createFunctionSchema(\n z.function({\n input: z.tuple([z.unknown()]),\n output: z.union([z.unknown(), z.promise(z.unknown())])\n })\n )\n});\n\n/**\n * @see CustomFunctionWithArgs\n */\nexport const CustomFunctionWithArgsSchema = z.strictObject({\n ...CustomFunctionBaseSchema.shape,\n args: z.instanceof(z.ZodObject),\n handler: createFunctionSchema(\n z.function({\n input: z.tuple([z.unknown()]),\n output: z.union([z.void(), z.promise(z.void())])\n })\n )\n});\n\n/**\n * @see CustomFunctionWithResult\n */\nexport const CustomFunctionWithResultSchema = z.strictObject({\n ...CustomFunctionBaseSchema.shape,\n result: z.instanceof(z.ZodObject),\n handler: createFunctionSchema(\n z.function({\n input: z.tuple([]),\n output: z.union([z.unknown(), z.promise(z.unknown())])\n })\n )\n});\n\n/**\n * @see CustomFunctionWithoutArgsAndResult\n */\nexport const CustomFunctionWithoutArgsAndResultSchema = z.strictObject({\n ...CustomFunctionBaseSchema.shape,\n handler: createFunctionSchema(\n z.function({\n input: z.tuple([]),\n output: z.union([z.void(), z.promise(z.void())])\n })\n )\n});\n\n/**\n * @see CustomFunction\n */\nexport const CustomFunctionSchema = z.union([\n CustomFunctionWithArgsAndResultSchema,\n CustomFunctionWithArgsSchema,\n CustomFunctionWithResultSchema,\n CustomFunctionWithoutArgsAndResultSchema\n]);\n\n/**\n * Base interface for all serverless function variants.\n */\ninterface CustomFunctionBase {\n /**\n * The type of the function, either a query or an update.\n */\n type: CustomFunctionType;\n}\n\n/**\n * A serverless function with both input arguments and an output result.\n *\n * @template TArgs - The type of the input arguments.\n * @template TResult - The type of the output result.\n */\nexport interface CustomFunctionWithArgsAndResult<\n TArgs extends z.ZodRawShape,\n TResult extends z.ZodRawShape\n> extends CustomFunctionBase {\n /**\n * A Zod schema describing the input arguments.\n */\n args: z.ZodObject<TArgs>;\n\n /**\n * A Zod schema describing the output result.\n */\n result: z.ZodObject<TResult>;\n\n /**\n * The function handler. Can be synchronous or asynchronous.\n *\n * @param {TArgs} args - The input arguments.\n * @returns {TResult | Promise<TResult>}\n */\n handler: (\n args: z.infer<z.ZodObject<TArgs>>\n ) => z.infer<z.ZodObject<TResult>> | Promise<z.infer<z.ZodObject<TResult>>>;\n}\n\n/**\n * A serverless function with input arguments but no output result.\n *\n * @template TArgs - The type of the input arguments.\n */\nexport interface CustomFunctionWithArgs<TArgs extends z.ZodRawShape> extends CustomFunctionBase {\n /**\n * A Zod schema describing the input arguments.\n */\n args: z.ZodObject<TArgs>;\n\n /**\n * The function handler. Can be synchronous or asynchronous.\n *\n * @param {TArgs} args - The input arguments.\n * @returns {void | Promise<void>}\n */\n handler: (args: z.infer<z.ZodObject<TArgs>>) => void | Promise<void>;\n}\n\n/**\n * A serverless function with an output result but no input arguments.\n *\n * @template TResult - The type of the output result.\n */\nexport interface CustomFunctionWithResult<\n TResult extends z.ZodRawShape\n> extends CustomFunctionBase {\n /**\n * A Zod schema describing the output result.\n */\n result: z.ZodObject<TResult>;\n\n /**\n * The function handler. Can be synchronous or asynchronous.\n *\n * @returns {TResult | Promise<TResult>}\n */\n handler: () => z.infer<z.ZodObject<TResult>> | Promise<z.infer<z.ZodObject<TResult>>>;\n}\n\n/**\n * A serverless function with no input arguments and no output result.\n */\nexport interface CustomFunctionWithoutArgsAndResult extends CustomFunctionBase {\n /**\n * The function handler. Can be synchronous or asynchronous.\n *\n * @returns {void | Promise<void>}\n */\n handler: () => void | Promise<void>;\n}\n\n/**\n * A serverless function definition. The four variants cover all combinations\n * of optional input arguments and output result.\n *\n * @template TArgs - The type of the input arguments.\n * @template TResult - The type of the output result.\n */\nexport type CustomFunction<\n TArgs extends z.ZodRawShape = z.ZodRawShape,\n TResult extends z.ZodRawShape = z.ZodRawShape\n> =\n | CustomFunctionWithArgsAndResult<TArgs, TResult>\n | CustomFunctionWithArgs<TArgs>\n | CustomFunctionWithResult<TResult>\n | CustomFunctionWithoutArgsAndResult;\n", "import * as z from 'zod';\nimport {type SatelliteEnv, SatelliteEnvSchema} from '../schemas/satellite.env';\nimport {createFunctionSchema} from '../utils/zod.utils';\nimport {JUNO_FUNCTION_TYPE} from './constants';\nimport {\n type CustomFunctionWithArgs,\n type CustomFunctionWithArgsAndResult,\n type CustomFunctionWithoutArgsAndResult,\n type CustomFunctionWithResult,\n CustomFunctionWithArgsAndResultSchema,\n CustomFunctionWithArgsSchema,\n CustomFunctionWithoutArgsAndResultSchema,\n CustomFunctionWithResultSchema\n} from './schemas/function';\n\nconst UpdateBaseSchema = z.strictObject({\n type: z.literal(JUNO_FUNCTION_TYPE.UPDATE)\n});\n\n/**\n * @see Update\n */\nexport const UpdateSchema = z.union([\n z.strictObject({\n ...CustomFunctionWithArgsAndResultSchema.shape,\n ...UpdateBaseSchema.shape\n }),\n z.strictObject({\n ...CustomFunctionWithArgsSchema.shape,\n ...UpdateBaseSchema.shape\n }),\n z.strictObject({\n ...CustomFunctionWithResultSchema.shape,\n ...UpdateBaseSchema.shape\n }),\n z.strictObject({\n ...CustomFunctionWithoutArgsAndResultSchema.shape,\n ...UpdateBaseSchema.shape\n })\n]);\n\n/**\n * The input shape for defining an update serverless function.\n * Does not include `type`, which is injected by `defineUpdate`.\n */\nexport type Update<\n TArgs extends z.ZodRawShape = z.ZodRawShape,\n TResult extends z.ZodRawShape = z.ZodRawShape\n> =\n | Omit<CustomFunctionWithArgsAndResult<TArgs, TResult>, 'type'>\n | Omit<CustomFunctionWithArgs<TArgs>, 'type'>\n | Omit<CustomFunctionWithResult<TResult>, 'type'>\n | Omit<CustomFunctionWithoutArgsAndResult, 'type'>;\n\n/**\n * A update function definition with `type` injected by `defineUpdate`.\n * Queries are read-only functions that do not modify state.\n */\nexport type UpdateDefinition<\n TArgs extends z.ZodRawShape = z.ZodRawShape,\n TResult extends z.ZodRawShape = z.ZodRawShape\n> = Update<TArgs, TResult> & {\n type: typeof JUNO_FUNCTION_TYPE.UPDATE;\n};\n\nexport const UpdateFnSchema = <T extends z.ZodTypeAny>(updateSchema: T) =>\n z.function({input: z.tuple([SatelliteEnvSchema]), output: updateSchema});\n\n/**\n * A factory function that receives the satellite environment and returns an update definition.\n */\nexport type UpdateFn<TArgs extends z.ZodRawShape, TResult extends z.ZodRawShape> = (\n env: SatelliteEnv\n) => Update<TArgs, TResult>;\n\nexport const UpdateFnOrObjectSchema = <T extends z.ZodTypeAny>(updateSchema: T) =>\n z.union([updateSchema, createFunctionSchema(UpdateFnSchema(updateSchema))]);\n\n/**\n * A update definition or a factory function that returns one.\n */\nexport type UpdateFnOrObject<TArgs extends z.ZodRawShape, TResult extends z.ZodRawShape> =\n | Update<TArgs, TResult>\n | UpdateFn<TArgs, TResult>;\n\nexport function defineUpdate<TArgs extends z.ZodRawShape, TResult extends z.ZodRawShape>(\n update: Update<TArgs, TResult>\n): UpdateDefinition<TArgs, TResult>;\nexport function defineUpdate<TArgs extends z.ZodRawShape, TResult extends z.ZodRawShape>(\n update: UpdateFn<TArgs, TResult>\n): (env: SatelliteEnv) => UpdateDefinition<TArgs, TResult>;\nexport function defineUpdate<TArgs extends z.ZodRawShape, TResult extends z.ZodRawShape>(\n update: UpdateFnOrObject<TArgs, TResult>\n): UpdateDefinition<TArgs, TResult> | ((env: SatelliteEnv) => UpdateDefinition<TArgs, TResult>);\nexport function defineUpdate<TArgs extends z.ZodRawShape, TResult extends z.ZodRawShape>(\n update: Update<TArgs, TResult> | UpdateFn<TArgs, TResult>\n): UpdateDefinition<TArgs, TResult> | ((env: SatelliteEnv) => UpdateDefinition<TArgs, TResult>) {\n if (typeof update === 'function') {\n return (env: SatelliteEnv) => {\n const result = {...update(env), type: JUNO_FUNCTION_TYPE.UPDATE};\n UpdateSchema.parse(result);\n return result;\n };\n }\n\n const result = {...update, type: JUNO_FUNCTION_TYPE.UPDATE};\n UpdateSchema.parse(result);\n return result;\n}\n", "import * as z from 'zod';\nimport {SatelliteEnvSchema} from '../schemas/satellite.env';\nimport {createFunctionSchema} from '../utils/zod.utils';\nimport {type Collections, CollectionsSchema} from './schemas/collections';\nimport {type AssertFunction, AssertFunctionSchema} from './schemas/context';\nimport {\n type AssertDeleteDocContext,\n AssertDeleteDocContextSchema,\n type AssertSetDocContext,\n AssertSetDocContextSchema\n} from './schemas/db/context';\nimport {\n type AssertDeleteAssetContext,\n AssertDeleteAssetContextSchema,\n type AssertUploadAssetContext,\n AssertUploadAssetContextSchema\n} from './schemas/storage/context';\n\n/**\n * @see OnAssert\n */\nconst OnAssertSchema = <T extends z.ZodTypeAny>(contextSchema: T) =>\n CollectionsSchema.extend({\n /**\n * A function that runs when the assertion is triggered for the specified collections.\n *\n * @param {T} context - Contains information about the affected document(s).\n * @returns {void} Resolves when the assertion completes.\n */\n assert: AssertFunctionSchema<T>(contextSchema)\n }).strict();\n\n/**\n * A generic schema for defining assertions related to collections.\n *\n * @template T - The type of context passed to the assertions when triggered.\n */\nexport type OnAssert<T> = Collections & {\n assert: AssertFunction<T>;\n};\n\n/**\n * @see AssertSetDoc\n */\nexport const AssertSetDocSchema = OnAssertSchema(AssertSetDocContextSchema);\n\n/**\n * An assertion that runs when a document is created or updated.\n */\nexport type AssertSetDoc = OnAssert<AssertSetDocContext>;\n\n/**\n * @see AssertDeleteDoc\n */\nexport const AssertDeleteDocSchema = OnAssertSchema(AssertDeleteDocContextSchema);\n\n/**\n * An assertion that runs when a document is deleted.\n */\nexport type AssertDeleteDoc = OnAssert<AssertDeleteDocContext>;\n\n/**\n * @see AssertUploadAsset\n */\nexport const AssertUploadAssetSchema = OnAssertSchema(AssertUploadAssetContextSchema);\n\n/**\n * An assertion that runs before an asset is uploaded.\n */\nexport type AssertUploadAsset = OnAssert<AssertUploadAssetContext>;\n\n/**\n * @see AssertDeleteAsset\n */\nexport const AssertDeleteAssetSchema = OnAssertSchema(AssertDeleteAssetContextSchema);\n\n/**\n * An assertion that runs before an asset is deleted.\n */\nexport type AssertDeleteAsset = OnAssert<AssertDeleteAssetContext>;\n\n/**\n * @see Assert\n */\nexport const AssertSchema = z.union([\n AssertSetDocSchema,\n AssertDeleteDocSchema,\n AssertUploadAssetSchema,\n AssertDeleteAssetSchema\n]);\n\n/**\n * All assertions definitions.\n */\nexport type Assert = AssertSetDoc | AssertDeleteDoc | AssertUploadAsset | AssertDeleteAsset;\n\nexport const AssertFnSchema = <T extends z.ZodTypeAny>(assertSchema: T) =>\n z.function({\n input: z.tuple([SatelliteEnvSchema]),\n output: assertSchema\n });\nexport type AssertFn<T extends Assert> = (assert: z.infer<typeof SatelliteEnvSchema>) => T;\n\nexport const AssertFnOrObjectSchema = <T extends z.ZodTypeAny>(assertSchema: T) =>\n z.union([assertSchema, createFunctionSchema(AssertFnSchema(assertSchema))]);\nexport type AssertFnOrObject<T extends Assert> = T | AssertFn<T>;\n\nexport function defineAssert<T extends Assert>(assert: T): T;\nexport function defineAssert<T extends Assert>(assert: AssertFn<T>): AssertFn<T>;\nexport function defineAssert<T extends Assert>(assert: AssertFnOrObject<T>): AssertFnOrObject<T>;\nexport function defineAssert<T extends Assert>(assert: AssertFnOrObject<T>): AssertFnOrObject<T> {\n return assert;\n}\n", "import * as z from 'zod';\nimport type {Collection} from '../../schemas/satellite';\n\n/**\n * @see Collections\n */\nexport const CollectionsSchema = z\n .object({\n collections: z.array(z.string()).readonly()\n })\n .strict();\n\n/**\n * Defines the collections where a hook or assertion should run.\n */\nexport interface Collections {\n /**\n * An array of collection names where the hook or assertion will run.\n * If empty, no hooks or assertions are triggered.\n */\n collections: readonly Collection[];\n}\n", "import * as z from 'zod';\nimport {type RawUserId, RawUserIdSchema} from '../../schemas/satellite';\nimport {createFunctionSchema} from '../../utils/zod.utils';\n\n/**\n * @see HookContext\n */\nexport const HookContextSchema = <T extends z.ZodTypeAny>(dataSchema: T) => {\n const schemaShape = {\n caller: RawUserIdSchema,\n data: dataSchema\n };\n\n return z.strictObject(schemaShape);\n};\n\n/**\n * Represents the context provided to hooks, containing information about the caller and related data.\n *\n * @template T - The type of data associated with the hook.\n */\nexport interface HookContext<T> {\n /**\n * The user who originally triggered the function that in turn triggered the hook.\n */\n caller: RawUserId;\n\n /**\n * The data associated with the hook execution.\n */\n data: T;\n}\n\n/**\n * @see AssertFunction\n */\nexport const AssertFunctionSchema = <T extends z.ZodTypeAny>(contextSchema: T) =>\n createFunctionSchema(z.function({input: z.tuple([contextSchema]), output: z.void()}));\n\n/**\n * Defines the `assert` function schema for assertions.\n *\n * The function takes a context argument and returns `void`.\n *\n * @template T - The type of context passed to the function.\n */\nexport type AssertFunction<T> = (context: T) => void;\n\n/**\n * @see RunFunction\n */\nexport const RunFunctionSchema = <T extends z.ZodTypeAny>(contextSchema: T) =>\n createFunctionSchema(\n z.function({input: z.tuple([contextSchema]), output: z.promise(z.void()).or(z.void())})\n );\n\n/**\n * Defines the `run` function schema for hooks.\n *\n * The function takes a context argument and returns either a `Promise<void>` or `void`.\n *\n * @template T - The type of context passed to the function.\n */\nexport type RunFunction<T> = (context: T) => void | Promise<void>;\n", "import * as z from 'zod';\nimport {DocSchema, type OptionDoc} from '../../../schemas/db';\nimport {type Collection, CollectionSchema, type Key, KeySchema} from '../../../schemas/satellite';\nimport {type HookContext, HookContextSchema} from '../context';\nimport {\n type DocAssertDelete,\n DocAssertDeleteSchema,\n type DocAssertSet,\n DocAssertSetSchema,\n type DocUpsert,\n DocUpsertSchema\n} from './payload';\n\n/**\n * @see DocContext\n */\nexport const DocContextSchema = <T extends z.ZodTypeAny>(dataSchema: T) => {\n const schemaShape = {\n collection: CollectionSchema,\n key: KeySchema,\n data: dataSchema\n };\n\n return z.strictObject(schemaShape);\n};\n\n/**\n * Represents the context of a document operation within a collection.\n *\n * @template T - The type of data associated with the document.\n */\nexport interface DocContext<T> {\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 * The data associated with the document operation.\n */\n data: T;\n}\n\n/**\n * @see OnSetDocContext\n */\nexport const OnSetDocContextSchema = HookContextSchema(DocContextSchema(DocUpsertSchema));\n\n/**\n * The context provided to the `onSetDoc` hook.\n *\n * This context contains information about the document being created or updated,\n * along with details about the user who triggered the operation.\n */\nexport type OnSetDocContext = HookContext<DocContext<DocUpsert>>;\n\n/**\n * @see OnSetManyDocsContext\n */\nexport const OnSetManyDocsContextSchema = HookContextSchema(\n z.array(DocContextSchema(DocUpsertSchema))\n);\n\n/**\n * The context provided to the `onSetManyDocs` hook.\n *\n * This context contains information about multiple documents being created or updated\n * in a single operation, along with details about the user who triggered it.\n */\nexport type OnSetManyDocsContext = HookContext<DocContext<DocUpsert>[]>;\n\n/**\n * @see OnDeleteDocContext\n */\nexport const OnDeleteDocContextSchema = HookContextSchema(DocContextSchema(DocSchema.optional()));\n\n/**\n * The context provided to the `onDeleteDoc` hook.\n *\n * This context contains information about a single document being deleted,\n * along with details about the user who triggered the operation.\n */\nexport type OnDeleteDocContext = HookContext<DocContext<OptionDoc>>;\n\n/**\n * @see OnDeleteManyDocsContext\n */\nexport const OnDeleteManyDocsContextSchema = HookContextSchema(\n z.array(DocContextSchema(DocSchema.optional()))\n);\n\n/**\n * The context provided to the `onDeleteManyDocs` hook.\n *\n * This context contains information about multiple documents being deleted,\n * along with details about the user who triggered the operation.\n */\nexport type OnDeleteManyDocsContext = HookContext<DocContext<OptionDoc>[]>;\n\n/**\n * @see OnDeleteFilteredDocsContext\n */\nexport const OnDeleteFilteredDocsContextSchema = HookContextSchema(\n z.array(DocContextSchema(DocSchema.optional()))\n);\n\n/**\n * The context provided to the `onDeleteFilteredDocs` hook.\n *\n * This context contains information about documents deleted as a result of a filter,\n * along with details about the user who triggered the operation.\n */\nexport type OnDeleteFilteredDocsContext = HookContext<DocContext<OptionDoc>[]>;\n\n/**\n * @see AssertSetDocContext\n */\nexport const AssertSetDocContextSchema = HookContextSchema(DocContextSchema(DocAssertSetSchema));\n\n/**\n * The context provided to the `assertDeleteDoc` hook.\n *\n * This context contains information about the document being validated before\n * it is created or updated. If validation fails, the developer should throw an error.\n */\nexport type AssertSetDocContext = HookContext<DocContext<DocAssertSet>>;\n\n/**\n * @see AssertDeleteDocContext\n */\nexport const AssertDeleteDocContextSchema = HookContextSchema(\n DocContextSchema(DocAssertDeleteSchema)\n);\n\n/**\n * The context provided to the `assertDeleteDoc` hook.\n *\n * This context contains information about the document being validated before\n * it is deleted. If validation fails, the developer should throw an error.\n */\nexport type AssertDeleteDocContext = HookContext<DocContext<DocAssertDelete>>;\n", "import * as z from 'zod';\nimport {\n type DelDoc,\n DelDocSchema,\n type Doc,\n DocSchema,\n type SetDoc,\n SetDocSchema\n} from '../../../schemas/db';\n\n/**\n * @see DocUpsert\n */\nexport const DocUpsertSchema = z\n .object({\n before: DocSchema.optional(),\n after: DocSchema\n })\n .strict();\n\n/**\n * Represents a document update operation.\n *\n * This is used in hooks where a document is either being created or updated.\n */\nexport interface DocUpsert {\n /**\n * The previous version of the document before the update.\n * Undefined if this is a new document.\n */\n before?: Doc;\n\n /**\n * The new version of the document after the update.\n */\n after: Doc;\n}\n/**\n * @see DocAssertSet\n */\nexport const DocAssertSetSchema = z\n .object({\n current: DocSchema.optional(),\n proposed: SetDocSchema\n })\n .strict();\n\n/**\n * Represents a validation check before setting a document.\n *\n * The developer can compare the `current` and `proposed` versions and\n * throw an error if their validation fails.\n */\nexport interface DocAssertSet {\n /**\n * The current version of the document before the operation.\n * Undefined if this is a new document.\n */\n current?: Doc;\n\n /**\n * The proposed version of the document.\n * This can be validated before allowing the operation.\n */\n proposed: SetDoc;\n}\n\n/**\n * @see DocAssertDelete\n */\nexport const DocAssertDeleteSchema = z\n .object({\n current: DocSchema.optional(),\n proposed: DelDocSchema\n })\n .strict();\n\n/**\n * Represents a validation check before deleting a document.\n *\n * The developer can compare the `current` and `proposed` versions and\n * throw an error if their validation fails.\n */\nexport interface DocAssertDelete {\n /**\n * The current version of the document before the operation.\n * Undefined if the document does not exist.\n */\n current?: Doc;\n\n /**\n * The proposed version of the document.\n * This can be validated before allowing the operation.\n */\n proposed: DelDoc;\n}\n", "import * as z from 'zod';\nimport {AssetSchema, type Asset} from '../../../schemas/storage';\nimport {HookContextSchema, type HookContext} from '../context';\nimport {AssetAssertUploadSchema, type AssetAssertUpload} from './payload';\n\n/**\n * @see OnUploadAssetContext\n */\nexport const OnUploadAssetContextSchema = HookContextSchema(AssetSchema);\n\n/**\n * Context for the `onUploadAsset` hook.\n *\n * This context contains information about the asset that was uploaded.\n */\nexport type OnUploadAssetContext = HookContext<Asset>;\n\n/**\n * @see OnDeleteAssetContext\n */\nexport const OnDeleteAssetContextSchema = HookContextSchema(AssetSchema.optional());\n\n/**\n * Context for the `onDeleteAsset` hook.\n *\n * This context contains information about a single asset being deleted, along with details about the user who triggered the operation.\n *\n * If undefined, the asset did not exist.\n */\nexport type OnDeleteAssetContext = HookContext<Asset | undefined>;\n\n/**\n * @see OnDeleteManyAssetsContext\n */\nexport const OnDeleteManyAssetsContextSchema = HookContextSchema(z.array(AssetSchema.optional()));\n\n/**\n * Context for the `onDeleteManyAssets` hook.\n *\n * This context contains information about multiple assets being potentially deleted, along with details about the user who triggered the operation.\n */\nexport type OnDeleteManyAssetsContext = HookContext<Array<Asset | undefined>>;\n\n/**\n * @see OnDeleteFilteredAssetsContext\n */\nexport const OnDeleteFilteredAssetsContextSchema = HookContextSchema(\n z.array(AssetSchema.optional())\n);\n\n/**\n * Context for the `onDeleteFilteredAssets` hook.\n *\n * This context contains information about documents deleted as a result of a filter, along with details about the user who triggered the operation.\n */\nexport type OnDeleteFilteredAssetsContext = HookContext<Array<Asset | undefined>>;\n\n/**\n * @see AssertUploadAssetContext\n */\nexport const AssertUploadAssetContextSchema = HookContextSchema(AssetAssertUploadSchema);\n\n/**\n * Context for the `assertUploadAsset` hook.\n *\n * This context contains information about the asset being validated before it is uploaded. If validation fails, the developer should throw an error.\n */\nexport type AssertUploadAssetContext = HookContext<AssetAssertUpload>;\n\n/**\n * @see AssertDeleteAssetContext\n */\nexport const AssertDeleteAssetContextSchema = HookContextSchema(AssetSchema);\n\n/**\n * Context for the `assertDeleteAsset` hook.\n *\n * This context contains information about the asset being validated before it is deleted. If validation fails, the developer should throw an error.\n */\nexport type AssertDeleteAssetContext = HookContext<Asset>;\n", "import * as z from 'zod';\nimport {\n type Asset,\n AssetSchema,\n type Batch,\n BatchSchema,\n type CommitBatch,\n CommitBatchSchema\n} from '../../../schemas/storage';\n\n/**\n * @see AssetAssertUpload\n */\nexport const AssetAssertUploadSchema = z\n .object({\n current: AssetSchema.optional(),\n batch: BatchSchema,\n commit_batch: CommitBatchSchema\n })\n .strict();\n\n/**\n * Represents a validation context before uploading an asset.\n */\nexport interface AssetAssertUpload {\n /**\n * The current asset already stored (if any).\n */\n current?: Asset;\n\n /**\n * The batch metadata being uploaded.\n */\n batch: Batch;\n\n /**\n * The commit data describing headers and chunk ids.\n */\n commit_batch: CommitBatch;\n}\n", "import * as z from 'zod';\nimport {SatelliteEnvSchema} from '../schemas/satellite.env';\nimport {createFunctionSchema} from '../utils/zod.utils';\nimport {type Collections, CollectionsSchema} from './schemas/collections';\nimport {type RunFunction, RunFunctionSchema} from './schemas/context';\nimport {\n type OnDeleteDocContext,\n OnDeleteDocContextSchema,\n type OnDeleteFilteredDocsContext,\n OnDeleteFilteredDocsContextSchema,\n type OnDeleteManyDocsContext,\n OnDeleteManyDocsContextSchema,\n type OnSetDocContext,\n OnSetDocContextSchema,\n type OnSetManyDocsContext,\n OnSetManyDocsContextSchema\n} from './schemas/db/context';\nimport {\n type OnDeleteAssetContext,\n OnDeleteAssetContextSchema,\n type OnDeleteFilteredAssetsContext,\n OnDeleteFilteredAssetsContextSchema,\n type OnDeleteManyAssetsContext,\n OnDeleteManyAssetsContextSchema,\n type OnUploadAssetContext,\n OnUploadAssetContextSchema\n} from './schemas/storage/context';\n\n/**\n * @see OnHook\n */\nconst OnHookSchema = <T extends z.ZodTypeAny>(contextSchema: T) =>\n CollectionsSchema.extend({\n run: RunFunctionSchema<T>(contextSchema)\n }).strict();\n\n/**\n * A generic schema for defining hooks related to collections.\n *\n * @template T - The type of context passed to the hook when triggered.\n */\nexport type OnHook<T> = Collections & {\n /**\n * A function that runs when the hook is triggered for the specified collections.\n *\n * @param {T} context - Contains information about the affected document(s).\n * @returns {Promise<void>} Resolves when the operation completes.\n */\n run: RunFunction<T>;\n};\n\n/**\n * @see OnSetDoc\n */\nexport const OnSetDocSchema = OnHookSchema(OnSetDocContextSchema);\n\n/**\n * A hook that runs when a document is created or updated.\n */\nexport type OnSetDoc = OnHook<OnSetDocContext>;\n\n/**\n * @see OnSetManyDocs\n */\nexport const OnSetManyDocsSchema = OnHookSchema(OnSetManyDocsContextSchema);\n\n/**\n * A hook that runs when multiple documents are created or updated.\n */\nexport type OnSetManyDocs = OnHook<OnSetManyDocsContext>;\n\n/**\n * @see OnDeleteDoc\n */\nexport const OnDeleteDocSchema = OnHookSchema(OnDeleteDocContextSchema);\n\n/**\n * A hook that runs when a single document is deleted.\n */\nexport type OnDeleteDoc = OnHook<OnDeleteDocContext>;\n\n/**\n * @see OnDeleteManyDocs\n */\nexport const OnDeleteManyDocsSchema = OnHookSchema(OnDeleteManyDocsContextSchema);\n\n/**\n * A hook that runs when multiple documents are deleted.\n */\nexport type OnDeleteManyDocs = OnHook<OnDeleteManyDocsContext>;\n\n/**\n * @see OnDeleteFilteredDocs\n */\nexport const OnDeleteFilteredDocsSchema = OnHookSchema(OnDeleteFilteredDocsContextSchema);\n\n/**\n * A hook that runs when a filtered set of documents is deleted based on query conditions.\n */\nexport type OnDeleteFilteredDocs = OnHook<OnDeleteFilteredDocsContext>;\n\n/**\n * @see OnUploadAsset\n */\nexport const OnUploadAssetSchema = OnHookSchema(OnUploadAssetContextSchema);\n\n/**\n * A hook that runs when a single asset is uploaded.\n */\nexport type OnUploadAsset = OnHook<OnUploadAssetContext>;\n\n/**\n * @see OnDeleteAsset\n */\nexport const OnDeleteAssetSchema = OnHookSchema(OnDeleteAssetContextSchema);\n\n/**\n * A hook that runs when a single asset is potentially deleted.\n */\nexport type OnDeleteAsset = OnHook<OnDeleteAssetContext>;\n\n/**\n * @see OnDeleteManyAssets\n */\nexport const OnDeleteManyAssetsSchema = OnHookSchema(OnDeleteManyAssetsContextSchema);\n\n/**\n * A hook that runs when multiple assets are potentially deleted.\n */\nexport type OnDeleteManyAssets = OnHook<OnDeleteManyAssetsContext>;\n\n/**\n * @see OnDeleteFilteredAssets\n */\nexport const OnDeleteFilteredAssetsSchema = OnHookSchema(OnDeleteFilteredAssetsContextSchema);\n\n/**\n * A hook that runs when a filtered set of assets is deleted based on query conditions.\n */\nexport type OnDeleteFilteredAssets = OnHook<OnDeleteFilteredAssetsContext>;\n\n/**\n * @see Hook\n */\nexport const HookSchema = z.union([\n OnSetDocSchema,\n OnSetManyDocsSchema,\n OnDeleteDocContextSchema,\n OnDeleteManyDocsContextSchema,\n OnDeleteFilteredDocsContextSchema,\n OnUploadAssetSchema,\n OnDeleteAssetSchema,\n OnDeleteManyAssetsSchema,\n OnDeleteFilteredAssetsSchema\n]);\n\n/**\n * All hooks definitions.\n */\nexport type Hook =\n | OnSetDoc\n | OnSetManyDocs\n | OnDeleteDoc\n | OnDeleteManyDocs\n | OnDeleteFilteredDocs\n | OnUploadAsset\n | OnDeleteAsset\n | OnDeleteManyAssets\n | OnDeleteFilteredAssets;\n\nexport const HookFnSchema = <T extends z.ZodTypeAny>(hookSchema: T) =>\n z.function({input: z.tuple([SatelliteEnvSchema]), output: hookSchema});\nexport type HookFn<T extends Hook> = (hook: z.infer<typeof SatelliteEnvSchema>) => T;\n\nexport const HookFnOrObjectSchema = <T extends z.ZodTypeAny>(hookSchema: T) =>\n z.union([hookSchema, createFunctionSchema(HookFnSchema(hookSchema))]);\nexport type HookFnOrObject<T extends Hook> = T | HookFn<T>;\n\nexport function defineHook<T extends Hook>(hook: T): T;\nexport function defineHook<T extends Hook>(hook: HookFn<T>): HookFn<T>;\nexport function defineHook<T extends Hook>(hook: HookFnOrObject<T>): HookFnOrObject<T>;\nexport function defineHook<T extends Hook>(hook: HookFnOrObject<T>): HookFnOrObject<T> {\n return hook;\n}\n", "import {nonNullish} from '@dfinity/utils';\nimport * as z from 'zod';\nimport {decodeDocData, encodeDocData} from '../sdk/serializer.sdk';\nimport {QuerySchema} from './query';\nimport {UpdateSchema} from './update';\n\nconst ConfigSchema = z.union([QuerySchema, UpdateSchema]);\ntype Config = z.infer<typeof ConfigSchema>;\n\n// eslint-disable-next-line local-rules/prefer-object-params\nglobalThis.__juno_satellite_fn_invoke_sync = (config: Config, raw?: Uint8Array<ArrayBuffer>) => {\n ConfigSchema.parse(config);\n\n const args =\n 'args' in config && config.args instanceof z.ZodType\n ? config.args?.parse(nonNullish(raw) ? decodeDocData(raw) : undefined)\n : undefined;\n\n const execute = () => {\n if (nonNullish(args)) {\n return (config.handler as (args: unknown) => unknown)(args);\n }\n\n return (config.handler as () => unknown)();\n };\n\n const result = execute();\n\n const parsed =\n 'result' in config && config.result instanceof z.ZodType\n ? config.result?.parse(result)\n : undefined;\n\n globalThis.jsResult = nonNullish(parsed) ? encodeDocData(parsed) : parsed;\n};\n\n// eslint-disable-next-line local-rules/prefer-object-params\nglobalThis.__juno_satellite_fn_invoke_async = async (\n config: Config,\n raw?: Uint8Array<ArrayBuffer>\n) => {\n ConfigSchema.parse(config);\n\n const args =\n 'args' in config && config.args instanceof z.ZodType\n ? config.args?.parse(nonNullish(raw) ? decodeDocData(raw) : undefined)\n : undefined;\n\n const execute = async () => {\n if (nonNullish(args)) {\n return await (config.handler as (args: unknown) => unknown)(args);\n }\n\n return await (config.handler as () => unknown)();\n };\n\n const result = await execute();\n\n const parsed =\n 'result' in config && config.result instanceof z.ZodType\n ? config.result?.parse(result)\n : undefined;\n\n globalThis.jsResult = nonNullish(parsed) ? encodeDocData(parsed) : parsed;\n};\n", "import {jsonReplacer} from '@dfinity/utils';\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nconst __juno_satellite_console_log = (v: any[]) => {\n const msg = v\n .map((arg) => (typeof arg === 'object' ? JSON.stringify(arg, jsonReplacer) : arg))\n .join(' ');\n\n globalThis.__ic_cdk_print(msg);\n};\n\n// @ts-expect-error We want to override the console\nglobalThis.console = {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n info(...v: any[]) {\n __juno_satellite_console_log(v);\n },\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n log(...v: any[]) {\n __juno_satellite_console_log(v);\n },\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n warn(...v: any[]) {\n __juno_satellite_console_log(v);\n },\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n error(...v: any[]) {\n __juno_satellite_console_log(v);\n }\n};\n", "/**\n * @see Math.random\n */\nconst random = (): number => {\n // __juno_satellite_random() returns a signed 32-bit int (i32)\n const value = __juno_satellite_random();\n\n // >>> 0 converts it to unsigned\n return (value >>> 0) / 2 ** 32;\n};\n\n/**\n * Overwrites Math.random with a pseudo-random number using the Satellite's internal RNG.\n *\n * \u26A0\uFE0F This function is not suitable for use cases requiring cryptographically secure or perfectly unpredictable randomness,\n * such as lotteries or gambling dApps.\n *\n * @returns {number} A pseudo-random 32-bit integer.\n *\n * @throws {Error} If the RNG has not been initialized.\n */\nglobalThis.Math.random = random;\n"],
|
|
5
|
-
"mappings": "
|
|
6
|
-
"names": ["z", "z", "SatelliteEnvSchema", "z", "createFunctionSchema", "schema", "fn", "JUNO_FUNCTION_TYPE", "z", "
|
|
4
|
+
"sourcesContent": ["import * as z from 'zod';\nimport {type SatelliteEnv, SatelliteEnvSchema} from '../schemas/satellite.env';\nimport {createFunctionSchema} from '../utils/zod.utils';\nimport {JUNO_FUNCTION_TYPE} from './constants';\nimport {\n type CustomFunctionWithArgs,\n type CustomFunctionWithArgsAndResult,\n type CustomFunctionWithoutArgsAndResult,\n type CustomFunctionWithResult,\n CustomFunctionWithArgsAndResultSchema,\n CustomFunctionWithArgsSchema,\n CustomFunctionWithoutArgsAndResultSchema,\n CustomFunctionWithResultSchema\n} from './schemas/function';\n\nconst QueryBaseSchema = z.strictObject({\n type: z.literal(JUNO_FUNCTION_TYPE.QUERY)\n});\n\n/**\n * @see Query\n */\nexport const QuerySchema = z.union([\n z.strictObject({\n ...CustomFunctionWithArgsAndResultSchema.shape,\n ...QueryBaseSchema.shape\n }),\n z.strictObject({\n ...CustomFunctionWithArgsSchema.shape,\n ...QueryBaseSchema.shape\n }),\n z.strictObject({\n ...CustomFunctionWithResultSchema.shape,\n ...QueryBaseSchema.shape\n }),\n z.strictObject({\n ...CustomFunctionWithoutArgsAndResultSchema.shape,\n ...QueryBaseSchema.shape\n })\n]);\n\n/**\n * The input shape for defining a query serverless function.\n * Does not include `type`, which is injected by `defineQuery`.\n */\nexport type Query<\n TArgs extends z.ZodRawShape = z.ZodRawShape,\n TResult extends z.ZodRawShape = z.ZodRawShape\n> =\n | Omit<CustomFunctionWithArgsAndResult<TArgs, TResult>, 'type'>\n | Omit<CustomFunctionWithArgs<TArgs>, 'type'>\n | Omit<CustomFunctionWithResult<TResult>, 'type'>\n | Omit<CustomFunctionWithoutArgsAndResult, 'type'>;\n\n/**\n * A query function definition with `type` injected by `defineQuery`.\n * Queries are read-only functions that do not modify state.\n */\nexport type QueryDefinition<\n TArgs extends z.ZodRawShape = z.ZodRawShape,\n TResult extends z.ZodRawShape = z.ZodRawShape\n> = Query<TArgs, TResult> & {\n type: typeof JUNO_FUNCTION_TYPE.QUERY;\n};\n\nexport const QueryFnSchema = <T extends z.ZodTypeAny>(querySchema: T) =>\n z.function({input: z.tuple([SatelliteEnvSchema]), output: querySchema});\n\n/**\n * A factory function that receives the satellite environment and returns a query definition.\n */\nexport type QueryFn<TArgs extends z.ZodRawShape, TResult extends z.ZodRawShape> = (\n env: SatelliteEnv\n) => Query<TArgs, TResult>;\n\nexport const QueryFnOrObjectSchema = <T extends z.ZodTypeAny>(querySchema: T) =>\n z.union([querySchema, createFunctionSchema(QueryFnSchema(querySchema))]);\n\n/**\n * A query definition or a factory function that returns one.\n */\nexport type QueryFnOrObject<TArgs extends z.ZodRawShape, TResult extends z.ZodRawShape> =\n | Query<TArgs, TResult>\n | QueryFn<TArgs, TResult>;\n\nexport function defineQuery<TArgs extends z.ZodRawShape, TResult extends z.ZodRawShape>(\n query: Query<TArgs, TResult>\n): QueryDefinition<TArgs, TResult>;\nexport function defineQuery<TArgs extends z.ZodRawShape, TResult extends z.ZodRawShape>(\n query: QueryFn<TArgs, TResult>\n): (env: SatelliteEnv) => QueryDefinition<TArgs, TResult>;\nexport function defineQuery<TArgs extends z.ZodRawShape, TResult extends z.ZodRawShape>(\n query: QueryFnOrObject<TArgs, TResult>\n): QueryDefinition<TArgs, TResult> | ((env: SatelliteEnv) => QueryDefinition<TArgs, TResult>);\nexport function defineQuery<TArgs extends z.ZodRawShape, TResult extends z.ZodRawShape>(\n query: Query<TArgs, TResult> | QueryFn<TArgs, TResult>\n): QueryDefinition<TArgs, TResult> | ((env: SatelliteEnv) => QueryDefinition<TArgs, TResult>) {\n if (typeof query === 'function') {\n return (env: SatelliteEnv) => {\n const result = {...query(env), type: JUNO_FUNCTION_TYPE.QUERY};\n QuerySchema.parse(result);\n return result;\n };\n }\n\n const result = {...query, type: JUNO_FUNCTION_TYPE.QUERY};\n QuerySchema.parse(result);\n return result;\n}\n", "import * as z from 'zod';\n\n/**\n * @see SatelliteEnv\n */\nexport const SatelliteEnvSchema = z.record(z.string(), z.string());\n\n/**\n * Placeholder for future environment-specific configurations.\n *\n * Currently unused, but it may support features such as:\n * - Defining the execution mode (e.g., staging or production).\n * - Providing environment-specific values like `ckBtcLedgerId` for test or production.\n */\nexport type SatelliteEnv = z.infer<typeof SatelliteEnvSchema>;\n", "import * as z from 'zod';\n\n/**\n * Wraps a Zod function schema so that parsing returns the **original function**\n * instead of Zod's wrapped validator.\n *\n * Why?\n * ----\n * In Zod v4, `z.function({...})` normally returns a wrapper that validates\n * both arguments and the return value **every time the function is called**.\n * If your function's return type is `void | Promise<void>`, Zod tries to\n * validate it synchronously, which can throw\n * \"Encountered Promise during synchronous parse\"\n * when the implementation is async.\n *\n * By using `.implement`, we tell Zod: \u201Cthis is the function that satisfies\n * the schema.\u201D That way the schema still validates the function shape at\n * parse time, but the returned value is the **original function** you passed\n * in \u2014 no runtime wrapper, no sync/async mismatch.\n *\n * Reference:\n * https://github.com/colinhacks/zod/issues/4143#issuecomment-2845134912\n *\n * Note: We need the function for this library, see following comment\n * https://github.com/colinhacks/zod/issues/4143#issuecomment-3335735535\n */\nexport const createFunctionSchema = <T extends z.ZodFunction>(schema: T) =>\n z.custom<Parameters<T['implement']>[0]>(\n (fn) => typeof fn === 'function' && schema.implement(fn as Parameters<T['implement']>[0])\n );\n", "/**\n * Internal constant used by Juno's tooling to discover serverless functions.\n * Not intended for direct use by developers.\n */\nexport const JUNO_FUNCTION_TYPE = {\n QUERY: '__juno_function_query',\n UPDATE: '__juno_function_update'\n} as const;\n", "import * as z from 'zod';\nimport {createFunctionSchema} from '../../utils/zod.utils';\nimport {JUNO_FUNCTION_TYPE} from '../constants';\n\n/**\n * The type of a serverless function. Not exposed to the developer. It allows the CLI\n * to discover the functions when parsing the code.\n */\nexport type CustomFunctionType = (typeof JUNO_FUNCTION_TYPE)[keyof typeof JUNO_FUNCTION_TYPE];\n\nconst CustomFunctionTypeSchema = z.strictObject({\n type: z.enum([JUNO_FUNCTION_TYPE.QUERY, JUNO_FUNCTION_TYPE.UPDATE])\n});\n\nexport const CustomFunctionGuardSchema = createFunctionSchema(\n z.function({\n output: z.void()\n })\n);\n\n/**\n * @see CustomFunctionBase\n */\nconst CustomFunctionBaseSchema = z.strictObject({\n guard: CustomFunctionGuardSchema.optional()\n});\n\n/**\n * @see CustomFunctionWithArgsAndResult\n */\nexport const CustomFunctionWithArgsAndResultSchema = z.strictObject({\n ...CustomFunctionTypeSchema.shape,\n ...CustomFunctionBaseSchema.shape,\n args: z.instanceof(z.ZodObject),\n result: z.instanceof(z.ZodObject),\n handler: createFunctionSchema(\n z.function({\n input: z.tuple([z.unknown()]),\n output: z.union([z.unknown(), z.promise(z.unknown())])\n })\n )\n});\n\n/**\n * @see CustomFunctionWithArgs\n */\nexport const CustomFunctionWithArgsSchema = z.strictObject({\n ...CustomFunctionTypeSchema.shape,\n ...CustomFunctionBaseSchema.shape,\n args: z.instanceof(z.ZodObject),\n handler: createFunctionSchema(\n z.function({\n input: z.tuple([z.unknown()]),\n output: z.union([z.void(), z.promise(z.void())])\n })\n )\n});\n\n/**\n * @see CustomFunctionWithResult\n */\nexport const CustomFunctionWithResultSchema = z.strictObject({\n ...CustomFunctionTypeSchema.shape,\n ...CustomFunctionBaseSchema.shape,\n result: z.instanceof(z.ZodObject),\n handler: createFunctionSchema(\n z.function({\n input: z.tuple([]),\n output: z.union([z.unknown(), z.promise(z.unknown())])\n })\n )\n});\n\n/**\n * @see CustomFunctionWithoutArgsAndResult\n */\nexport const CustomFunctionWithoutArgsAndResultSchema = z.strictObject({\n ...CustomFunctionTypeSchema.shape,\n ...CustomFunctionBaseSchema.shape,\n handler: createFunctionSchema(\n z.function({\n input: z.tuple([]),\n output: z.union([z.void(), z.promise(z.void())])\n })\n )\n});\n\n/**\n * @see CustomFunction\n */\nexport const CustomFunctionSchema = z.union([\n CustomFunctionWithArgsAndResultSchema,\n CustomFunctionWithArgsSchema,\n CustomFunctionWithResultSchema,\n CustomFunctionWithoutArgsAndResultSchema\n]);\n\n/**\n * Base interface for all serverless function variants.\n */\ninterface CustomFunctionBase {\n /**\n * The type of the function, either a query or an update.\n */\n type: CustomFunctionType;\n\n /**\n * An optional function that runs before the function is executed.\n * If the guard throws, the function is not executed.\n */\n guard?: () => void;\n}\n\n/**\n * A serverless function with both input arguments and an output result.\n *\n * @template TArgs - The type of the input arguments.\n * @template TResult - The type of the output result.\n */\nexport interface CustomFunctionWithArgsAndResult<\n TArgs extends z.ZodRawShape,\n TResult extends z.ZodRawShape\n> extends CustomFunctionBase {\n /**\n * A Zod schema describing the input arguments.\n */\n args: z.ZodObject<TArgs>;\n\n /**\n * A Zod schema describing the output result.\n */\n result: z.ZodObject<TResult>;\n\n /**\n * The function handler. Can be synchronous or asynchronous.\n *\n * @param {TArgs} args - The input arguments.\n * @returns {TResult | Promise<TResult>}\n */\n handler: (\n args: z.infer<z.ZodObject<TArgs>>\n ) => z.infer<z.ZodObject<TResult>> | Promise<z.infer<z.ZodObject<TResult>>>;\n}\n\n/**\n * A serverless function with input arguments but no output result.\n *\n * @template TArgs - The type of the input arguments.\n */\nexport interface CustomFunctionWithArgs<TArgs extends z.ZodRawShape> extends CustomFunctionBase {\n /**\n * A Zod schema describing the input arguments.\n */\n args: z.ZodObject<TArgs>;\n\n /**\n * The function handler. Can be synchronous or asynchronous.\n *\n * @param {TArgs} args - The input arguments.\n * @returns {void | Promise<void>}\n */\n handler: (args: z.infer<z.ZodObject<TArgs>>) => void | Promise<void>;\n}\n\n/**\n * A serverless function with an output result but no input arguments.\n *\n * @template TResult - The type of the output result.\n */\nexport interface CustomFunctionWithResult<\n TResult extends z.ZodRawShape\n> extends CustomFunctionBase {\n /**\n * A Zod schema describing the output result.\n */\n result: z.ZodObject<TResult>;\n\n /**\n * The function handler. Can be synchronous or asynchronous.\n *\n * @returns {TResult | Promise<TResult>}\n */\n handler: () => z.infer<z.ZodObject<TResult>> | Promise<z.infer<z.ZodObject<TResult>>>;\n}\n\n/**\n * A serverless function with no input arguments and no output result.\n */\nexport interface CustomFunctionWithoutArgsAndResult extends CustomFunctionBase {\n /**\n * The function handler. Can be synchronous or asynchronous.\n *\n * @returns {void | Promise<void>}\n */\n handler: () => void | Promise<void>;\n}\n\n/**\n * A serverless function definition. The four variants cover all combinations\n * of optional input arguments and output result.\n *\n * @template TArgs - The type of the input arguments.\n * @template TResult - The type of the output result.\n */\nexport type CustomFunction<\n TArgs extends z.ZodRawShape = z.ZodRawShape,\n TResult extends z.ZodRawShape = z.ZodRawShape\n> =\n | CustomFunctionWithArgsAndResult<TArgs, TResult>\n | CustomFunctionWithArgs<TArgs>\n | CustomFunctionWithResult<TResult>\n | CustomFunctionWithoutArgsAndResult;\n", "import * as z from 'zod';\nimport {type SatelliteEnv, SatelliteEnvSchema} from '../schemas/satellite.env';\nimport {createFunctionSchema} from '../utils/zod.utils';\nimport {JUNO_FUNCTION_TYPE} from './constants';\nimport {\n type CustomFunctionWithArgs,\n type CustomFunctionWithArgsAndResult,\n type CustomFunctionWithoutArgsAndResult,\n type CustomFunctionWithResult,\n CustomFunctionWithArgsAndResultSchema,\n CustomFunctionWithArgsSchema,\n CustomFunctionWithoutArgsAndResultSchema,\n CustomFunctionWithResultSchema\n} from './schemas/function';\n\nconst UpdateBaseSchema = z.strictObject({\n type: z.literal(JUNO_FUNCTION_TYPE.UPDATE)\n});\n\n/**\n * @see Update\n */\nexport const UpdateSchema = z.union([\n z.strictObject({\n ...CustomFunctionWithArgsAndResultSchema.shape,\n ...UpdateBaseSchema.shape\n }),\n z.strictObject({\n ...CustomFunctionWithArgsSchema.shape,\n ...UpdateBaseSchema.shape\n }),\n z.strictObject({\n ...CustomFunctionWithResultSchema.shape,\n ...UpdateBaseSchema.shape\n }),\n z.strictObject({\n ...CustomFunctionWithoutArgsAndResultSchema.shape,\n ...UpdateBaseSchema.shape\n })\n]);\n\n/**\n * The input shape for defining an update serverless function.\n * Does not include `type`, which is injected by `defineUpdate`.\n */\nexport type Update<\n TArgs extends z.ZodRawShape = z.ZodRawShape,\n TResult extends z.ZodRawShape = z.ZodRawShape\n> =\n | Omit<CustomFunctionWithArgsAndResult<TArgs, TResult>, 'type'>\n | Omit<CustomFunctionWithArgs<TArgs>, 'type'>\n | Omit<CustomFunctionWithResult<TResult>, 'type'>\n | Omit<CustomFunctionWithoutArgsAndResult, 'type'>;\n\n/**\n * A update function definition with `type` injected by `defineUpdate`.\n * Queries are read-only functions that do not modify state.\n */\nexport type UpdateDefinition<\n TArgs extends z.ZodRawShape = z.ZodRawShape,\n TResult extends z.ZodRawShape = z.ZodRawShape\n> = Update<TArgs, TResult> & {\n type: typeof JUNO_FUNCTION_TYPE.UPDATE;\n};\n\nexport const UpdateFnSchema = <T extends z.ZodTypeAny>(updateSchema: T) =>\n z.function({input: z.tuple([SatelliteEnvSchema]), output: updateSchema});\n\n/**\n * A factory function that receives the satellite environment and returns an update definition.\n */\nexport type UpdateFn<TArgs extends z.ZodRawShape, TResult extends z.ZodRawShape> = (\n env: SatelliteEnv\n) => Update<TArgs, TResult>;\n\nexport const UpdateFnOrObjectSchema = <T extends z.ZodTypeAny>(updateSchema: T) =>\n z.union([updateSchema, createFunctionSchema(UpdateFnSchema(updateSchema))]);\n\n/**\n * A update definition or a factory function that returns one.\n */\nexport type UpdateFnOrObject<TArgs extends z.ZodRawShape, TResult extends z.ZodRawShape> =\n | Update<TArgs, TResult>\n | UpdateFn<TArgs, TResult>;\n\nexport function defineUpdate<TArgs extends z.ZodRawShape, TResult extends z.ZodRawShape>(\n update: Update<TArgs, TResult>\n): UpdateDefinition<TArgs, TResult>;\nexport function defineUpdate<TArgs extends z.ZodRawShape, TResult extends z.ZodRawShape>(\n update: UpdateFn<TArgs, TResult>\n): (env: SatelliteEnv) => UpdateDefinition<TArgs, TResult>;\nexport function defineUpdate<TArgs extends z.ZodRawShape, TResult extends z.ZodRawShape>(\n update: UpdateFnOrObject<TArgs, TResult>\n): UpdateDefinition<TArgs, TResult> | ((env: SatelliteEnv) => UpdateDefinition<TArgs, TResult>);\nexport function defineUpdate<TArgs extends z.ZodRawShape, TResult extends z.ZodRawShape>(\n update: Update<TArgs, TResult> | UpdateFn<TArgs, TResult>\n): UpdateDefinition<TArgs, TResult> | ((env: SatelliteEnv) => UpdateDefinition<TArgs, TResult>) {\n if (typeof update === 'function') {\n return (env: SatelliteEnv) => {\n const result = {...update(env), type: JUNO_FUNCTION_TYPE.UPDATE};\n UpdateSchema.parse(result);\n return result;\n };\n }\n\n const result = {...update, type: JUNO_FUNCTION_TYPE.UPDATE};\n UpdateSchema.parse(result);\n return result;\n}\n", "import * as z from 'zod';\nimport {SatelliteEnvSchema} from '../schemas/satellite.env';\nimport {createFunctionSchema} from '../utils/zod.utils';\nimport {type Collections, CollectionsSchema} from './schemas/collections';\nimport {type AssertFunction, AssertFunctionSchema} from './schemas/context';\nimport {\n type AssertDeleteDocContext,\n AssertDeleteDocContextSchema,\n type AssertSetDocContext,\n AssertSetDocContextSchema\n} from './schemas/db/context';\nimport {\n type AssertDeleteAssetContext,\n AssertDeleteAssetContextSchema,\n type AssertUploadAssetContext,\n AssertUploadAssetContextSchema\n} from './schemas/storage/context';\n\n/**\n * @see OnAssert\n */\nconst OnAssertSchema = <T extends z.ZodTypeAny>(contextSchema: T) =>\n CollectionsSchema.extend({\n /**\n * A function that runs when the assertion is triggered for the specified collections.\n *\n * @param {T} context - Contains information about the affected document(s).\n * @returns {void} Resolves when the assertion completes.\n */\n assert: AssertFunctionSchema<T>(contextSchema)\n }).strict();\n\n/**\n * A generic schema for defining assertions related to collections.\n *\n * @template T - The type of context passed to the assertions when triggered.\n */\nexport type OnAssert<T> = Collections & {\n assert: AssertFunction<T>;\n};\n\n/**\n * @see AssertSetDoc\n */\nexport const AssertSetDocSchema = OnAssertSchema(AssertSetDocContextSchema);\n\n/**\n * An assertion that runs when a document is created or updated.\n */\nexport type AssertSetDoc = OnAssert<AssertSetDocContext>;\n\n/**\n * @see AssertDeleteDoc\n */\nexport const AssertDeleteDocSchema = OnAssertSchema(AssertDeleteDocContextSchema);\n\n/**\n * An assertion that runs when a document is deleted.\n */\nexport type AssertDeleteDoc = OnAssert<AssertDeleteDocContext>;\n\n/**\n * @see AssertUploadAsset\n */\nexport const AssertUploadAssetSchema = OnAssertSchema(AssertUploadAssetContextSchema);\n\n/**\n * An assertion that runs before an asset is uploaded.\n */\nexport type AssertUploadAsset = OnAssert<AssertUploadAssetContext>;\n\n/**\n * @see AssertDeleteAsset\n */\nexport const AssertDeleteAssetSchema = OnAssertSchema(AssertDeleteAssetContextSchema);\n\n/**\n * An assertion that runs before an asset is deleted.\n */\nexport type AssertDeleteAsset = OnAssert<AssertDeleteAssetContext>;\n\n/**\n * @see Assert\n */\nexport const AssertSchema = z.union([\n AssertSetDocSchema,\n AssertDeleteDocSchema,\n AssertUploadAssetSchema,\n AssertDeleteAssetSchema\n]);\n\n/**\n * All assertions definitions.\n */\nexport type Assert = AssertSetDoc | AssertDeleteDoc | AssertUploadAsset | AssertDeleteAsset;\n\nexport const AssertFnSchema = <T extends z.ZodTypeAny>(assertSchema: T) =>\n z.function({\n input: z.tuple([SatelliteEnvSchema]),\n output: assertSchema\n });\nexport type AssertFn<T extends Assert> = (assert: z.infer<typeof SatelliteEnvSchema>) => T;\n\nexport const AssertFnOrObjectSchema = <T extends z.ZodTypeAny>(assertSchema: T) =>\n z.union([assertSchema, createFunctionSchema(AssertFnSchema(assertSchema))]);\nexport type AssertFnOrObject<T extends Assert> = T | AssertFn<T>;\n\nexport function defineAssert<T extends Assert>(assert: T): T;\nexport function defineAssert<T extends Assert>(assert: AssertFn<T>): AssertFn<T>;\nexport function defineAssert<T extends Assert>(assert: AssertFnOrObject<T>): AssertFnOrObject<T>;\nexport function defineAssert<T extends Assert>(assert: AssertFnOrObject<T>): AssertFnOrObject<T> {\n return assert;\n}\n", "import * as z from 'zod';\nimport type {Collection} from '../../schemas/satellite';\n\n/**\n * @see Collections\n */\nexport const CollectionsSchema = z\n .object({\n collections: z.array(z.string()).readonly()\n })\n .strict();\n\n/**\n * Defines the collections where a hook or assertion should run.\n */\nexport interface Collections {\n /**\n * An array of collection names where the hook or assertion will run.\n * If empty, no hooks or assertions are triggered.\n */\n collections: readonly Collection[];\n}\n", "import * as z from 'zod';\nimport {type RawUserId, RawUserIdSchema} from '../../schemas/satellite';\nimport {createFunctionSchema} from '../../utils/zod.utils';\n\n/**\n * @see HookContext\n */\nexport const HookContextSchema = <T extends z.ZodTypeAny>(dataSchema: T) => {\n const schemaShape = {\n caller: RawUserIdSchema,\n data: dataSchema\n };\n\n return z.strictObject(schemaShape);\n};\n\n/**\n * Represents the context provided to hooks, containing information about the caller and related data.\n *\n * @template T - The type of data associated with the hook.\n */\nexport interface HookContext<T> {\n /**\n * The user who originally triggered the function that in turn triggered the hook.\n */\n caller: RawUserId;\n\n /**\n * The data associated with the hook execution.\n */\n data: T;\n}\n\n/**\n * @see AssertFunction\n */\nexport const AssertFunctionSchema = <T extends z.ZodTypeAny>(contextSchema: T) =>\n createFunctionSchema(z.function({input: z.tuple([contextSchema]), output: z.void()}));\n\n/**\n * Defines the `assert` function schema for assertions.\n *\n * The function takes a context argument and returns `void`.\n *\n * @template T - The type of context passed to the function.\n */\nexport type AssertFunction<T> = (context: T) => void;\n\n/**\n * @see RunFunction\n */\nexport const RunFunctionSchema = <T extends z.ZodTypeAny>(contextSchema: T) =>\n createFunctionSchema(\n z.function({input: z.tuple([contextSchema]), output: z.promise(z.void()).or(z.void())})\n );\n\n/**\n * Defines the `run` function schema for hooks.\n *\n * The function takes a context argument and returns either a `Promise<void>` or `void`.\n *\n * @template T - The type of context passed to the function.\n */\nexport type RunFunction<T> = (context: T) => void | Promise<void>;\n", "import * as z from 'zod';\nimport {DocSchema, type OptionDoc} from '../../../schemas/db';\nimport {type Collection, CollectionSchema, type Key, KeySchema} from '../../../schemas/satellite';\nimport {type HookContext, HookContextSchema} from '../context';\nimport {\n type DocAssertDelete,\n DocAssertDeleteSchema,\n type DocAssertSet,\n DocAssertSetSchema,\n type DocUpsert,\n DocUpsertSchema\n} from './payload';\n\n/**\n * @see DocContext\n */\nexport const DocContextSchema = <T extends z.ZodTypeAny>(dataSchema: T) => {\n const schemaShape = {\n collection: CollectionSchema,\n key: KeySchema,\n data: dataSchema\n };\n\n return z.strictObject(schemaShape);\n};\n\n/**\n * Represents the context of a document operation within a collection.\n *\n * @template T - The type of data associated with the document.\n */\nexport interface DocContext<T> {\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 * The data associated with the document operation.\n */\n data: T;\n}\n\n/**\n * @see OnSetDocContext\n */\nexport const OnSetDocContextSchema = HookContextSchema(DocContextSchema(DocUpsertSchema));\n\n/**\n * The context provided to the `onSetDoc` hook.\n *\n * This context contains information about the document being created or updated,\n * along with details about the user who triggered the operation.\n */\nexport type OnSetDocContext = HookContext<DocContext<DocUpsert>>;\n\n/**\n * @see OnSetManyDocsContext\n */\nexport const OnSetManyDocsContextSchema = HookContextSchema(\n z.array(DocContextSchema(DocUpsertSchema))\n);\n\n/**\n * The context provided to the `onSetManyDocs` hook.\n *\n * This context contains information about multiple documents being created or updated\n * in a single operation, along with details about the user who triggered it.\n */\nexport type OnSetManyDocsContext = HookContext<DocContext<DocUpsert>[]>;\n\n/**\n * @see OnDeleteDocContext\n */\nexport const OnDeleteDocContextSchema = HookContextSchema(DocContextSchema(DocSchema.optional()));\n\n/**\n * The context provided to the `onDeleteDoc` hook.\n *\n * This context contains information about a single document being deleted,\n * along with details about the user who triggered the operation.\n */\nexport type OnDeleteDocContext = HookContext<DocContext<OptionDoc>>;\n\n/**\n * @see OnDeleteManyDocsContext\n */\nexport const OnDeleteManyDocsContextSchema = HookContextSchema(\n z.array(DocContextSchema(DocSchema.optional()))\n);\n\n/**\n * The context provided to the `onDeleteManyDocs` hook.\n *\n * This context contains information about multiple documents being deleted,\n * along with details about the user who triggered the operation.\n */\nexport type OnDeleteManyDocsContext = HookContext<DocContext<OptionDoc>[]>;\n\n/**\n * @see OnDeleteFilteredDocsContext\n */\nexport const OnDeleteFilteredDocsContextSchema = HookContextSchema(\n z.array(DocContextSchema(DocSchema.optional()))\n);\n\n/**\n * The context provided to the `onDeleteFilteredDocs` hook.\n *\n * This context contains information about documents deleted as a result of a filter,\n * along with details about the user who triggered the operation.\n */\nexport type OnDeleteFilteredDocsContext = HookContext<DocContext<OptionDoc>[]>;\n\n/**\n * @see AssertSetDocContext\n */\nexport const AssertSetDocContextSchema = HookContextSchema(DocContextSchema(DocAssertSetSchema));\n\n/**\n * The context provided to the `assertDeleteDoc` hook.\n *\n * This context contains information about the document being validated before\n * it is created or updated. If validation fails, the developer should throw an error.\n */\nexport type AssertSetDocContext = HookContext<DocContext<DocAssertSet>>;\n\n/**\n * @see AssertDeleteDocContext\n */\nexport const AssertDeleteDocContextSchema = HookContextSchema(\n DocContextSchema(DocAssertDeleteSchema)\n);\n\n/**\n * The context provided to the `assertDeleteDoc` hook.\n *\n * This context contains information about the document being validated before\n * it is deleted. If validation fails, the developer should throw an error.\n */\nexport type AssertDeleteDocContext = HookContext<DocContext<DocAssertDelete>>;\n", "import * as z from 'zod';\nimport {\n type DelDoc,\n DelDocSchema,\n type Doc,\n DocSchema,\n type SetDoc,\n SetDocSchema\n} from '../../../schemas/db';\n\n/**\n * @see DocUpsert\n */\nexport const DocUpsertSchema = z\n .object({\n before: DocSchema.optional(),\n after: DocSchema\n })\n .strict();\n\n/**\n * Represents a document update operation.\n *\n * This is used in hooks where a document is either being created or updated.\n */\nexport interface DocUpsert {\n /**\n * The previous version of the document before the update.\n * Undefined if this is a new document.\n */\n before?: Doc;\n\n /**\n * The new version of the document after the update.\n */\n after: Doc;\n}\n/**\n * @see DocAssertSet\n */\nexport const DocAssertSetSchema = z\n .object({\n current: DocSchema.optional(),\n proposed: SetDocSchema\n })\n .strict();\n\n/**\n * Represents a validation check before setting a document.\n *\n * The developer can compare the `current` and `proposed` versions and\n * throw an error if their validation fails.\n */\nexport interface DocAssertSet {\n /**\n * The current version of the document before the operation.\n * Undefined if this is a new document.\n */\n current?: Doc;\n\n /**\n * The proposed version of the document.\n * This can be validated before allowing the operation.\n */\n proposed: SetDoc;\n}\n\n/**\n * @see DocAssertDelete\n */\nexport const DocAssertDeleteSchema = z\n .object({\n current: DocSchema.optional(),\n proposed: DelDocSchema\n })\n .strict();\n\n/**\n * Represents a validation check before deleting a document.\n *\n * The developer can compare the `current` and `proposed` versions and\n * throw an error if their validation fails.\n */\nexport interface DocAssertDelete {\n /**\n * The current version of the document before the operation.\n * Undefined if the document does not exist.\n */\n current?: Doc;\n\n /**\n * The proposed version of the document.\n * This can be validated before allowing the operation.\n */\n proposed: DelDoc;\n}\n", "import * as z from 'zod';\nimport {AssetSchema, type Asset} from '../../../schemas/storage';\nimport {HookContextSchema, type HookContext} from '../context';\nimport {AssetAssertUploadSchema, type AssetAssertUpload} from './payload';\n\n/**\n * @see OnUploadAssetContext\n */\nexport const OnUploadAssetContextSchema = HookContextSchema(AssetSchema);\n\n/**\n * Context for the `onUploadAsset` hook.\n *\n * This context contains information about the asset that was uploaded.\n */\nexport type OnUploadAssetContext = HookContext<Asset>;\n\n/**\n * @see OnDeleteAssetContext\n */\nexport const OnDeleteAssetContextSchema = HookContextSchema(AssetSchema.optional());\n\n/**\n * Context for the `onDeleteAsset` hook.\n *\n * This context contains information about a single asset being deleted, along with details about the user who triggered the operation.\n *\n * If undefined, the asset did not exist.\n */\nexport type OnDeleteAssetContext = HookContext<Asset | undefined>;\n\n/**\n * @see OnDeleteManyAssetsContext\n */\nexport const OnDeleteManyAssetsContextSchema = HookContextSchema(z.array(AssetSchema.optional()));\n\n/**\n * Context for the `onDeleteManyAssets` hook.\n *\n * This context contains information about multiple assets being potentially deleted, along with details about the user who triggered the operation.\n */\nexport type OnDeleteManyAssetsContext = HookContext<Array<Asset | undefined>>;\n\n/**\n * @see OnDeleteFilteredAssetsContext\n */\nexport const OnDeleteFilteredAssetsContextSchema = HookContextSchema(\n z.array(AssetSchema.optional())\n);\n\n/**\n * Context for the `onDeleteFilteredAssets` hook.\n *\n * This context contains information about documents deleted as a result of a filter, along with details about the user who triggered the operation.\n */\nexport type OnDeleteFilteredAssetsContext = HookContext<Array<Asset | undefined>>;\n\n/**\n * @see AssertUploadAssetContext\n */\nexport const AssertUploadAssetContextSchema = HookContextSchema(AssetAssertUploadSchema);\n\n/**\n * Context for the `assertUploadAsset` hook.\n *\n * This context contains information about the asset being validated before it is uploaded. If validation fails, the developer should throw an error.\n */\nexport type AssertUploadAssetContext = HookContext<AssetAssertUpload>;\n\n/**\n * @see AssertDeleteAssetContext\n */\nexport const AssertDeleteAssetContextSchema = HookContextSchema(AssetSchema);\n\n/**\n * Context for the `assertDeleteAsset` hook.\n *\n * This context contains information about the asset being validated before it is deleted. If validation fails, the developer should throw an error.\n */\nexport type AssertDeleteAssetContext = HookContext<Asset>;\n", "import * as z from 'zod';\nimport {\n type Asset,\n AssetSchema,\n type Batch,\n BatchSchema,\n type CommitBatch,\n CommitBatchSchema\n} from '../../../schemas/storage';\n\n/**\n * @see AssetAssertUpload\n */\nexport const AssetAssertUploadSchema = z\n .object({\n current: AssetSchema.optional(),\n batch: BatchSchema,\n commit_batch: CommitBatchSchema\n })\n .strict();\n\n/**\n * Represents a validation context before uploading an asset.\n */\nexport interface AssetAssertUpload {\n /**\n * The current asset already stored (if any).\n */\n current?: Asset;\n\n /**\n * The batch metadata being uploaded.\n */\n batch: Batch;\n\n /**\n * The commit data describing headers and chunk ids.\n */\n commit_batch: CommitBatch;\n}\n", "import * as z from 'zod';\nimport {SatelliteEnvSchema} from '../schemas/satellite.env';\nimport {createFunctionSchema} from '../utils/zod.utils';\nimport {type Collections, CollectionsSchema} from './schemas/collections';\nimport {type RunFunction, RunFunctionSchema} from './schemas/context';\nimport {\n type OnDeleteDocContext,\n OnDeleteDocContextSchema,\n type OnDeleteFilteredDocsContext,\n OnDeleteFilteredDocsContextSchema,\n type OnDeleteManyDocsContext,\n OnDeleteManyDocsContextSchema,\n type OnSetDocContext,\n OnSetDocContextSchema,\n type OnSetManyDocsContext,\n OnSetManyDocsContextSchema\n} from './schemas/db/context';\nimport {\n type OnDeleteAssetContext,\n OnDeleteAssetContextSchema,\n type OnDeleteFilteredAssetsContext,\n OnDeleteFilteredAssetsContextSchema,\n type OnDeleteManyAssetsContext,\n OnDeleteManyAssetsContextSchema,\n type OnUploadAssetContext,\n OnUploadAssetContextSchema\n} from './schemas/storage/context';\n\n/**\n * @see OnHook\n */\nconst OnHookSchema = <T extends z.ZodTypeAny>(contextSchema: T) =>\n CollectionsSchema.extend({\n run: RunFunctionSchema<T>(contextSchema)\n }).strict();\n\n/**\n * A generic schema for defining hooks related to collections.\n *\n * @template T - The type of context passed to the hook when triggered.\n */\nexport type OnHook<T> = Collections & {\n /**\n * A function that runs when the hook is triggered for the specified collections.\n *\n * @param {T} context - Contains information about the affected document(s).\n * @returns {Promise<void>} Resolves when the operation completes.\n */\n run: RunFunction<T>;\n};\n\n/**\n * @see OnSetDoc\n */\nexport const OnSetDocSchema = OnHookSchema(OnSetDocContextSchema);\n\n/**\n * A hook that runs when a document is created or updated.\n */\nexport type OnSetDoc = OnHook<OnSetDocContext>;\n\n/**\n * @see OnSetManyDocs\n */\nexport const OnSetManyDocsSchema = OnHookSchema(OnSetManyDocsContextSchema);\n\n/**\n * A hook that runs when multiple documents are created or updated.\n */\nexport type OnSetManyDocs = OnHook<OnSetManyDocsContext>;\n\n/**\n * @see OnDeleteDoc\n */\nexport const OnDeleteDocSchema = OnHookSchema(OnDeleteDocContextSchema);\n\n/**\n * A hook that runs when a single document is deleted.\n */\nexport type OnDeleteDoc = OnHook<OnDeleteDocContext>;\n\n/**\n * @see OnDeleteManyDocs\n */\nexport const OnDeleteManyDocsSchema = OnHookSchema(OnDeleteManyDocsContextSchema);\n\n/**\n * A hook that runs when multiple documents are deleted.\n */\nexport type OnDeleteManyDocs = OnHook<OnDeleteManyDocsContext>;\n\n/**\n * @see OnDeleteFilteredDocs\n */\nexport const OnDeleteFilteredDocsSchema = OnHookSchema(OnDeleteFilteredDocsContextSchema);\n\n/**\n * A hook that runs when a filtered set of documents is deleted based on query conditions.\n */\nexport type OnDeleteFilteredDocs = OnHook<OnDeleteFilteredDocsContext>;\n\n/**\n * @see OnUploadAsset\n */\nexport const OnUploadAssetSchema = OnHookSchema(OnUploadAssetContextSchema);\n\n/**\n * A hook that runs when a single asset is uploaded.\n */\nexport type OnUploadAsset = OnHook<OnUploadAssetContext>;\n\n/**\n * @see OnDeleteAsset\n */\nexport const OnDeleteAssetSchema = OnHookSchema(OnDeleteAssetContextSchema);\n\n/**\n * A hook that runs when a single asset is potentially deleted.\n */\nexport type OnDeleteAsset = OnHook<OnDeleteAssetContext>;\n\n/**\n * @see OnDeleteManyAssets\n */\nexport const OnDeleteManyAssetsSchema = OnHookSchema(OnDeleteManyAssetsContextSchema);\n\n/**\n * A hook that runs when multiple assets are potentially deleted.\n */\nexport type OnDeleteManyAssets = OnHook<OnDeleteManyAssetsContext>;\n\n/**\n * @see OnDeleteFilteredAssets\n */\nexport const OnDeleteFilteredAssetsSchema = OnHookSchema(OnDeleteFilteredAssetsContextSchema);\n\n/**\n * A hook that runs when a filtered set of assets is deleted based on query conditions.\n */\nexport type OnDeleteFilteredAssets = OnHook<OnDeleteFilteredAssetsContext>;\n\n/**\n * @see Hook\n */\nexport const HookSchema = z.union([\n OnSetDocSchema,\n OnSetManyDocsSchema,\n OnDeleteDocContextSchema,\n OnDeleteManyDocsContextSchema,\n OnDeleteFilteredDocsContextSchema,\n OnUploadAssetSchema,\n OnDeleteAssetSchema,\n OnDeleteManyAssetsSchema,\n OnDeleteFilteredAssetsSchema\n]);\n\n/**\n * All hooks definitions.\n */\nexport type Hook =\n | OnSetDoc\n | OnSetManyDocs\n | OnDeleteDoc\n | OnDeleteManyDocs\n | OnDeleteFilteredDocs\n | OnUploadAsset\n | OnDeleteAsset\n | OnDeleteManyAssets\n | OnDeleteFilteredAssets;\n\nexport const HookFnSchema = <T extends z.ZodTypeAny>(hookSchema: T) =>\n z.function({input: z.tuple([SatelliteEnvSchema]), output: hookSchema});\nexport type HookFn<T extends Hook> = (hook: z.infer<typeof SatelliteEnvSchema>) => T;\n\nexport const HookFnOrObjectSchema = <T extends z.ZodTypeAny>(hookSchema: T) =>\n z.union([hookSchema, createFunctionSchema(HookFnSchema(hookSchema))]);\nexport type HookFnOrObject<T extends Hook> = T | HookFn<T>;\n\nexport function defineHook<T extends Hook>(hook: T): T;\nexport function defineHook<T extends Hook>(hook: HookFn<T>): HookFn<T>;\nexport function defineHook<T extends Hook>(hook: HookFnOrObject<T>): HookFnOrObject<T>;\nexport function defineHook<T extends Hook>(hook: HookFnOrObject<T>): HookFnOrObject<T> {\n return hook;\n}\n", "import {nonNullish} from '@dfinity/utils';\nimport * as z from 'zod';\nimport {decodeDocData, encodeDocData} from '../sdk/serializer.sdk';\nimport {QuerySchema} from './query';\nimport {CustomFunctionGuardSchema} from './schemas/function';\nimport {UpdateSchema} from './update';\n\nconst ConfigSchema = z.union([QuerySchema, UpdateSchema]);\ntype Config = z.infer<typeof ConfigSchema>;\n\nconst ConfigWithGuardSchema = ConfigSchema.and(\n z.strictObject({\n guard: CustomFunctionGuardSchema\n })\n);\n\nglobalThis.__juno_satellite_fn_guard_sync = (config: Config) => {\n const configWithGuard = ConfigWithGuardSchema.parse(config);\n configWithGuard.guard();\n};\n\n// eslint-disable-next-line local-rules/prefer-object-params\nglobalThis.__juno_satellite_fn_invoke_sync = (config: Config, raw?: Uint8Array<ArrayBuffer>) => {\n ConfigSchema.parse(config);\n\n const args =\n 'args' in config && config.args instanceof z.ZodType\n ? config.args?.parse(nonNullish(raw) ? decodeDocData(raw) : undefined)\n : undefined;\n\n const execute = () => {\n if (nonNullish(args)) {\n return (config.handler as (args: unknown) => unknown)(args);\n }\n\n return (config.handler as () => unknown)();\n };\n\n const result = execute();\n\n const parsed =\n 'result' in config && config.result instanceof z.ZodType\n ? config.result?.parse(result)\n : undefined;\n\n globalThis.jsResult = nonNullish(parsed) ? encodeDocData(parsed) : parsed;\n};\n\n// eslint-disable-next-line local-rules/prefer-object-params\nglobalThis.__juno_satellite_fn_invoke_async = async (\n config: Config,\n raw?: Uint8Array<ArrayBuffer>\n) => {\n ConfigSchema.parse(config);\n\n const args =\n 'args' in config && config.args instanceof z.ZodType\n ? config.args?.parse(nonNullish(raw) ? decodeDocData(raw) : undefined)\n : undefined;\n\n const execute = async () => {\n if (nonNullish(args)) {\n return await (config.handler as (args: unknown) => unknown)(args);\n }\n\n return await (config.handler as () => unknown)();\n };\n\n const result = await execute();\n\n const parsed =\n 'result' in config && config.result instanceof z.ZodType\n ? config.result?.parse(result)\n : undefined;\n\n globalThis.jsResult = nonNullish(parsed) ? encodeDocData(parsed) : parsed;\n};\n", "import {jsonReplacer} from '@dfinity/utils';\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nconst __juno_satellite_console_log = (v: any[]) => {\n const msg = v\n .map((arg) => (typeof arg === 'object' ? JSON.stringify(arg, jsonReplacer) : arg))\n .join(' ');\n\n globalThis.__ic_cdk_print(msg);\n};\n\n// @ts-expect-error We want to override the console\nglobalThis.console = {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n info(...v: any[]) {\n __juno_satellite_console_log(v);\n },\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n log(...v: any[]) {\n __juno_satellite_console_log(v);\n },\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n warn(...v: any[]) {\n __juno_satellite_console_log(v);\n },\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n error(...v: any[]) {\n __juno_satellite_console_log(v);\n }\n};\n", "/**\n * @see Math.random\n */\nconst random = (): number => {\n // __juno_satellite_random() returns a signed 32-bit int (i32)\n const value = __juno_satellite_random();\n\n // >>> 0 converts it to unsigned\n return (value >>> 0) / 2 ** 32;\n};\n\n/**\n * Overwrites Math.random with a pseudo-random number using the Satellite's internal RNG.\n *\n * \u26A0\uFE0F This function is not suitable for use cases requiring cryptographically secure or perfectly unpredictable randomness,\n * such as lotteries or gambling dApps.\n *\n * @returns {number} A pseudo-random 32-bit integer.\n *\n * @throws {Error} If the RNG has not been initialized.\n */\nglobalThis.Math.random = random;\n"],
|
|
5
|
+
"mappings": "4VAAA,UAAYA,MAAO,MCAnB,UAAYC,MAAO,MAKZ,IAAMC,EAAuB,SAAS,SAAO,EAAK,SAAO,CAAC,ECLjE,UAAYC,OAAO,MA0BZ,IAAMC,EAAiDC,GAC1D,UACCC,GAAO,OAAOA,GAAO,YAAcD,EAAO,UAAUC,CAAmC,CAC1F,ECzBK,IAAMC,EAAqB,CAChC,MAAO,wBACP,OAAQ,wBACV,ECPA,UAAYC,MAAO,MAUnB,IAAMC,EAA6B,eAAa,CAC9C,KAAQ,OAAK,CAACC,EAAmB,MAAOA,EAAmB,MAAM,CAAC,CACpE,CAAC,EAEYC,EAA4BC,EACrC,WAAS,CACT,OAAU,OAAK,CACjB,CAAC,CACH,EAKMC,EAA6B,eAAa,CAC9C,MAAOF,EAA0B,SAAS,CAC5C,CAAC,EAKYG,EAA0C,eAAa,CAClE,GAAGL,EAAyB,MAC5B,GAAGI,EAAyB,MAC5B,KAAQ,aAAa,WAAS,EAC9B,OAAU,aAAa,WAAS,EAChC,QAASD,EACL,WAAS,CACT,MAAS,QAAM,CAAG,UAAQ,CAAC,CAAC,EAC5B,OAAU,QAAM,CAAG,UAAQ,EAAK,UAAU,UAAQ,CAAC,CAAC,CAAC,CACvD,CAAC,CACH,CACF,CAAC,EAKYG,EAAiC,eAAa,CACzD,GAAGN,EAAyB,MAC5B,GAAGI,EAAyB,MAC5B,KAAQ,aAAa,WAAS,EAC9B,QAASD,EACL,WAAS,CACT,MAAS,QAAM,CAAG,UAAQ,CAAC,CAAC,EAC5B,OAAU,QAAM,CAAG,OAAK,EAAK,UAAU,OAAK,CAAC,CAAC,CAAC,CACjD,CAAC,CACH,CACF,CAAC,EAKYI,EAAmC,eAAa,CAC3D,GAAGP,EAAyB,MAC5B,GAAGI,EAAyB,MAC5B,OAAU,aAAa,WAAS,EAChC,QAASD,EACL,WAAS,CACT,MAAS,QAAM,CAAC,CAAC,EACjB,OAAU,QAAM,CAAG,UAAQ,EAAK,UAAU,UAAQ,CAAC,CAAC,CAAC,CACvD,CAAC,CACH,CACF,CAAC,EAKYK,EAA6C,eAAa,CACrE,GAAGR,EAAyB,MAC5B,GAAGI,EAAyB,MAC5B,QAASD,EACL,WAAS,CACT,MAAS,QAAM,CAAC,CAAC,EACjB,OAAU,QAAM,CAAG,OAAK,EAAK,UAAU,OAAK,CAAC,CAAC,CAAC,CACjD,CAAC,CACH,CACF,CAAC,EAKYM,GAAyB,QAAM,CAC1CJ,EACAC,EACAC,EACAC,CACF,CAAC,EJhFD,IAAME,EAAoB,eAAa,CACrC,KAAQ,UAAQC,EAAmB,KAAK,CAC1C,CAAC,EAKYC,EAAgB,QAAM,CAC/B,eAAa,CACb,GAAGC,EAAsC,MACzC,GAAGH,EAAgB,KACrB,CAAC,EACC,eAAa,CACb,GAAGI,EAA6B,MAChC,GAAGJ,EAAgB,KACrB,CAAC,EACC,eAAa,CACb,GAAGK,EAA+B,MAClC,GAAGL,EAAgB,KACrB,CAAC,EACC,eAAa,CACb,GAAGM,EAAyC,MAC5C,GAAGN,EAAgB,KACrB,CAAC,CACH,CAAC,EA0BYO,GAAyCC,GAClD,WAAS,CAAC,MAAS,QAAM,CAACC,CAAkB,CAAC,EAAG,OAAQD,CAAW,CAAC,EAS3DE,GAAiDF,GAC1D,QAAM,CAACA,EAAaG,EAAqBJ,GAAcC,CAAW,CAAC,CAAC,CAAC,EAkBlE,SAASI,GACdC,EAC4F,CAC5F,GAAI,OAAOA,GAAU,WACnB,OAAQC,GAAsB,CAC5B,IAAMC,EAAS,CAAC,GAAGF,EAAMC,CAAG,EAAG,KAAMb,EAAmB,KAAK,EAC7D,OAAAC,EAAY,MAAMa,CAAM,EACjBA,CACT,EAGF,IAAMA,EAAS,CAAC,GAAGF,EAAO,KAAMZ,EAAmB,KAAK,EACxD,OAAAC,EAAY,MAAMa,CAAM,EACjBA,CACT,CK5GA,UAAYC,MAAO,MAenB,IAAMC,EAAqB,eAAa,CACtC,KAAQ,UAAQC,EAAmB,MAAM,CAC3C,CAAC,EAKYC,EAAiB,QAAM,CAChC,eAAa,CACb,GAAGC,EAAsC,MACzC,GAAGH,EAAiB,KACtB,CAAC,EACC,eAAa,CACb,GAAGI,EAA6B,MAChC,GAAGJ,EAAiB,KACtB,CAAC,EACC,eAAa,CACb,GAAGK,EAA+B,MAClC,GAAGL,EAAiB,KACtB,CAAC,EACC,eAAa,CACb,GAAGM,EAAyC,MAC5C,GAAGN,EAAiB,KACtB,CAAC,CACH,CAAC,EA0BYO,GAA0CC,GACnD,WAAS,CAAC,MAAS,QAAM,CAACC,CAAkB,CAAC,EAAG,OAAQD,CAAY,CAAC,EAS5DE,GAAkDF,GAC3D,QAAM,CAACA,EAAcG,EAAqBJ,GAAeC,CAAY,CAAC,CAAC,CAAC,EAkBrE,SAASI,GACdC,EAC8F,CAC9F,GAAI,OAAOA,GAAW,WACpB,OAAQC,GAAsB,CAC5B,IAAMC,EAAS,CAAC,GAAGF,EAAOC,CAAG,EAAG,KAAMb,EAAmB,MAAM,EAC/D,OAAAC,EAAa,MAAMa,CAAM,EAClBA,CACT,EAGF,IAAMA,EAAS,CAAC,GAAGF,EAAQ,KAAMZ,EAAmB,MAAM,EAC1D,OAAAC,EAAa,MAAMa,CAAM,EAClBA,CACT,CC5GA,UAAYC,MAAO,MCAnB,UAAY,MAAO,MAMZ,IAAMC,EACV,SAAO,CACN,YAAe,QAAQ,SAAO,CAAC,EAAE,SAAS,CAC5C,CAAC,EACA,OAAO,ECVV,UAAYC,MAAO,MAOZ,IAAMC,EAA6CC,GAM/C,eALW,CAClB,OAAQC,EACR,KAAMD,CACR,CAEiC,EAuBtBE,GAAgDC,GAC3DC,EAAuB,WAAS,CAAC,MAAS,QAAM,CAACD,CAAa,CAAC,EAAG,OAAU,OAAK,CAAC,CAAC,CAAC,EAczEE,GAA6CF,GACxDC,EACI,WAAS,CAAC,MAAS,QAAM,CAACD,CAAa,CAAC,EAAG,OAAU,UAAU,OAAK,CAAC,EAAE,GAAK,OAAK,CAAC,CAAC,CAAC,CACxF,ECtDF,UAAYG,MAAO,MCAnB,UAAYC,MAAO,MAaZ,IAAMC,EACV,SAAO,CACN,OAAQC,EAAU,SAAS,EAC3B,MAAOA,CACT,CAAC,EACA,OAAO,EAsBGC,GACV,SAAO,CACN,QAASD,EAAU,SAAS,EAC5B,SAAUE,CACZ,CAAC,EACA,OAAO,EAyBGC,GACV,SAAO,CACN,QAASH,EAAU,SAAS,EAC5B,SAAUI,CACZ,CAAC,EACA,OAAO,ED3DH,IAAMC,EAA4CC,GAO9C,eANW,CAClB,WAAYC,EACZ,IAAKC,EACL,KAAMF,CACR,CAEiC,EA4BtBG,GAAwBC,EAAkBL,EAAiBM,CAAe,CAAC,EAa3EC,GAA6BF,EACtC,QAAML,EAAiBM,CAAe,CAAC,CAC3C,EAaaE,EAA2BH,EAAkBL,EAAiBS,EAAU,SAAS,CAAC,CAAC,EAanFC,EAAgCL,EACzC,QAAML,EAAiBS,EAAU,SAAS,CAAC,CAAC,CAChD,EAaaE,EAAoCN,EAC7C,QAAML,EAAiBS,EAAU,SAAS,CAAC,CAAC,CAChD,EAaaG,GAA4BP,EAAkBL,EAAiBa,EAAkB,CAAC,EAalFC,GAA+BT,EAC1CL,EAAiBe,EAAqB,CACxC,EEzIA,UAAYC,MAAO,MCAnB,UAAYC,OAAO,MAaZ,IAAMC,GACV,UAAO,CACN,QAASC,EAAY,SAAS,EAC9B,MAAOC,EACP,aAAcC,EAChB,CAAC,EACA,OAAO,EDXH,IAAMC,GAA6BC,EAAkBC,CAAW,EAY1DC,GAA6BF,EAAkBC,EAAY,SAAS,CAAC,EAcrEE,GAAkCH,EAAoB,QAAMC,EAAY,SAAS,CAAC,CAAC,EAYnFG,GAAsCJ,EAC/C,QAAMC,EAAY,SAAS,CAAC,CAChC,EAYaI,GAAiCL,EAAkBM,EAAuB,EAY1EC,GAAiCP,EAAkBC,CAAW,ELnD3E,IAAMO,EAA0CC,GAC9CC,EAAkB,OAAO,CAOvB,OAAQC,GAAwBF,CAAa,CAC/C,CAAC,EAAE,OAAO,EAcCG,GAAqBJ,EAAeK,EAAyB,EAU7DC,GAAwBN,EAAeO,EAA4B,EAUnEC,GAA0BR,EAAeS,EAA8B,EAUvEC,GAA0BV,EAAeW,EAA8B,EAUvEC,GAAiB,QAAM,CAClCR,GACAE,GACAE,GACAE,EACF,CAAC,EAOYG,GAA0CC,GACnD,WAAS,CACT,MAAS,QAAM,CAACC,CAAkB,CAAC,EACnC,OAAQD,CACV,CAAC,EAGUE,GAAkDF,GAC3D,QAAM,CAACA,EAAcG,EAAqBJ,GAAeC,CAAY,CAAC,CAAC,CAAC,EAMrE,SAASI,GAA+BC,EAAkD,CAC/F,OAAOA,CACT,COhHA,UAAYC,MAAO,MA+BnB,IAAMC,EAAwCC,GAC5CC,EAAkB,OAAO,CACvB,IAAKC,GAAqBF,CAAa,CACzC,CAAC,EAAE,OAAO,EAoBCG,GAAiBJ,EAAaK,EAAqB,EAUnDC,GAAsBN,EAAaO,EAA0B,EAU7DC,GAAoBR,EAAaS,CAAwB,EAUzDC,GAAyBV,EAAaW,CAA6B,EAUnEC,GAA6BZ,EAAaa,CAAiC,EAU3EC,GAAsBd,EAAae,EAA0B,EAU7DC,GAAsBhB,EAAaiB,EAA0B,EAU7DC,GAA2BlB,EAAamB,EAA+B,EAUvEC,GAA+BpB,EAAaqB,EAAmC,EAU/EC,GAAe,QAAM,CAChClB,GACAE,GACAG,EACAE,EACAE,EACAC,GACAE,GACAE,GACAE,EACF,CAAC,EAgBYG,GAAwCC,GACjD,WAAS,CAAC,MAAS,QAAM,CAACC,CAAkB,CAAC,EAAG,OAAQD,CAAU,CAAC,EAG1DE,GAAgDF,GACzD,QAAM,CAACA,EAAYG,EAAqBJ,GAAaC,CAAU,CAAC,CAAC,CAAC,EAM/D,SAASI,GAA2BC,EAA4C,CACrF,OAAOA,CACT,CCvLA,OAAQ,cAAAC,MAAiB,iBACzB,UAAYC,MAAO,MAMnB,IAAMC,EAAiB,QAAM,CAACC,EAAaC,CAAY,CAAC,EAGlDC,GAAwBH,EAAa,IACvC,eAAa,CACb,MAAOI,CACT,CAAC,CACH,EAEA,WAAW,+BAAkCC,GAAmB,CACtCF,GAAsB,MAAME,CAAM,EAC1C,MAAM,CACxB,EAGA,WAAW,gCAAkC,CAACA,EAAgBC,IAAkC,CAC9FN,EAAa,MAAMK,CAAM,EAEzB,IAAME,EACJ,SAAUF,GAAUA,EAAO,gBAAkB,UACzCA,EAAO,MAAM,MAAMG,EAAWF,CAAG,EAAIG,EAAcH,CAAG,EAAI,MAAS,EACnE,OAUAI,EAPAF,EAAWD,CAAI,EACTF,EAAO,QAAuCE,CAAI,EAGpDF,EAAO,QAA0B,EAKrCM,EACJ,WAAYN,GAAUA,EAAO,kBAAoB,UAC7CA,EAAO,QAAQ,MAAMK,CAAM,EAC3B,OAEN,WAAW,SAAWF,EAAWG,CAAM,EAAIC,EAAcD,CAAM,EAAIA,CACrE,EAGA,WAAW,iCAAmC,MAC5CN,EACAC,IACG,CACHN,EAAa,MAAMK,CAAM,EAEzB,IAAME,EACJ,SAAUF,GAAUA,EAAO,gBAAkB,UACzCA,EAAO,MAAM,MAAMG,EAAWF,CAAG,EAAIG,EAAcH,CAAG,EAAI,MAAS,EACnE,OAUAI,EAAS,MARC,SACVF,EAAWD,CAAI,EACV,MAAOF,EAAO,QAAuCE,CAAI,EAG3D,MAAOF,EAAO,QAA0B,GAGpB,EAEvBM,EACJ,WAAYN,GAAUA,EAAO,kBAAoB,UAC7CA,EAAO,QAAQ,MAAMK,CAAM,EAC3B,OAEN,WAAW,SAAWF,EAAWG,CAAM,EAAIC,EAAcD,CAAM,EAAIA,CACrE,EC5EA,OAAQ,gBAAAE,OAAmB,iBAG3B,IAAMC,EAAgCC,GAAa,CACjD,IAAMC,EAAMD,EACT,IAAKE,GAAS,OAAOA,GAAQ,SAAW,KAAK,UAAUA,EAAKJ,EAAY,EAAII,CAAI,EAChF,KAAK,GAAG,EAEX,WAAW,eAAeD,CAAG,CAC/B,EAGA,WAAW,QAAU,CAEnB,QAAQD,EAAU,CAChBD,EAA6BC,CAAC,CAChC,EAEA,OAAOA,EAAU,CACfD,EAA6BC,CAAC,CAChC,EAEA,QAAQA,EAAU,CAChBD,EAA6BC,CAAC,CAChC,EAEA,SAASA,EAAU,CACjBD,EAA6BC,CAAC,CAChC,CACF,EC1BA,IAAMG,GAAS,KAEC,wBAAwB,IAGpB,GAAK,WAazB,WAAW,KAAK,OAASA",
|
|
6
|
+
"names": ["z", "z", "SatelliteEnvSchema", "z", "createFunctionSchema", "schema", "fn", "JUNO_FUNCTION_TYPE", "z", "CustomFunctionTypeSchema", "JUNO_FUNCTION_TYPE", "CustomFunctionGuardSchema", "createFunctionSchema", "CustomFunctionBaseSchema", "CustomFunctionWithArgsAndResultSchema", "CustomFunctionWithArgsSchema", "CustomFunctionWithResultSchema", "CustomFunctionWithoutArgsAndResultSchema", "CustomFunctionSchema", "QueryBaseSchema", "JUNO_FUNCTION_TYPE", "QuerySchema", "CustomFunctionWithArgsAndResultSchema", "CustomFunctionWithArgsSchema", "CustomFunctionWithResultSchema", "CustomFunctionWithoutArgsAndResultSchema", "QueryFnSchema", "querySchema", "SatelliteEnvSchema", "QueryFnOrObjectSchema", "createFunctionSchema", "defineQuery", "query", "env", "result", "z", "UpdateBaseSchema", "JUNO_FUNCTION_TYPE", "UpdateSchema", "CustomFunctionWithArgsAndResultSchema", "CustomFunctionWithArgsSchema", "CustomFunctionWithResultSchema", "CustomFunctionWithoutArgsAndResultSchema", "UpdateFnSchema", "updateSchema", "SatelliteEnvSchema", "UpdateFnOrObjectSchema", "createFunctionSchema", "defineUpdate", "update", "env", "result", "z", "CollectionsSchema", "z", "HookContextSchema", "dataSchema", "RawUserIdSchema", "AssertFunctionSchema", "contextSchema", "createFunctionSchema", "RunFunctionSchema", "z", "z", "DocUpsertSchema", "DocSchema", "DocAssertSetSchema", "SetDocSchema", "DocAssertDeleteSchema", "DelDocSchema", "DocContextSchema", "dataSchema", "CollectionSchema", "KeySchema", "OnSetDocContextSchema", "HookContextSchema", "DocUpsertSchema", "OnSetManyDocsContextSchema", "OnDeleteDocContextSchema", "DocSchema", "OnDeleteManyDocsContextSchema", "OnDeleteFilteredDocsContextSchema", "AssertSetDocContextSchema", "DocAssertSetSchema", "AssertDeleteDocContextSchema", "DocAssertDeleteSchema", "z", "z", "AssetAssertUploadSchema", "AssetSchema", "BatchSchema", "CommitBatchSchema", "OnUploadAssetContextSchema", "HookContextSchema", "AssetSchema", "OnDeleteAssetContextSchema", "OnDeleteManyAssetsContextSchema", "OnDeleteFilteredAssetsContextSchema", "AssertUploadAssetContextSchema", "AssetAssertUploadSchema", "AssertDeleteAssetContextSchema", "OnAssertSchema", "contextSchema", "CollectionsSchema", "AssertFunctionSchema", "AssertSetDocSchema", "AssertSetDocContextSchema", "AssertDeleteDocSchema", "AssertDeleteDocContextSchema", "AssertUploadAssetSchema", "AssertUploadAssetContextSchema", "AssertDeleteAssetSchema", "AssertDeleteAssetContextSchema", "AssertSchema", "AssertFnSchema", "assertSchema", "SatelliteEnvSchema", "AssertFnOrObjectSchema", "createFunctionSchema", "defineAssert", "assert", "z", "OnHookSchema", "contextSchema", "CollectionsSchema", "RunFunctionSchema", "OnSetDocSchema", "OnSetDocContextSchema", "OnSetManyDocsSchema", "OnSetManyDocsContextSchema", "OnDeleteDocSchema", "OnDeleteDocContextSchema", "OnDeleteManyDocsSchema", "OnDeleteManyDocsContextSchema", "OnDeleteFilteredDocsSchema", "OnDeleteFilteredDocsContextSchema", "OnUploadAssetSchema", "OnUploadAssetContextSchema", "OnDeleteAssetSchema", "OnDeleteAssetContextSchema", "OnDeleteManyAssetsSchema", "OnDeleteManyAssetsContextSchema", "OnDeleteFilteredAssetsSchema", "OnDeleteFilteredAssetsContextSchema", "HookSchema", "HookFnSchema", "hookSchema", "SatelliteEnvSchema", "HookFnOrObjectSchema", "createFunctionSchema", "defineHook", "hook", "nonNullish", "z", "ConfigSchema", "QuerySchema", "UpdateSchema", "ConfigWithGuardSchema", "CustomFunctionGuardSchema", "config", "raw", "args", "nonNullish", "decodeDocData", "result", "parsed", "encodeDocData", "jsonReplacer", "__juno_satellite_console_log", "v", "msg", "arg", "random"]
|
|
7
7
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@junobuild/functions",
|
|
3
|
-
"version": "0.7.2-next-2026-03-
|
|
3
|
+
"version": "0.7.2-next-2026-03-22",
|
|
4
4
|
"description": "JavaScript and TypeScript utilities for Juno Serverless Functions",
|
|
5
5
|
"author": "David Dal Busco (https://daviddalbusco.com)",
|
|
6
6
|
"license": "MIT",
|