@junobuild/functions-tools 0.4.6 → 0.5.0
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 +6 -6
- package/dist/node/index.mjs +48 -55
- package/dist/node/index.mjs.map +4 -4
- package/dist/types/api/index.d.ts +1 -1
- package/dist/types/api/{zod → schema}/index.d.ts +1 -1
- package/dist/types/api/{zod → schema}/services/_javascript.templates.d.ts +1 -1
- package/dist/types/api/{zod → schema}/services/_typescript.templates.d.ts +4 -4
- package/dist/types/api/{zod → schema}/services/parser.services.d.ts +1 -1
- package/dist/types/converters/_types.d.ts +0 -3
- package/dist/types/converters/{zod-to-zod.d.ts → zod-to-schema.d.ts} +5 -5
- package/package.json +3 -3
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Query, Update } from '@junobuild/functions';
|
|
2
2
|
import type { TransformerOptions } from '../types/transformer-options';
|
|
3
|
-
export declare const
|
|
3
|
+
export declare const generateSchemaApi: ({ functions, outputFile, transformerOptions }: {
|
|
4
4
|
functions: [string, Update | Query][];
|
|
5
5
|
outputFile: string;
|
|
6
6
|
transformerOptions: TransformerOptions;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export declare const jsTemplateImports = "import {idlFactory} from './satellite.factory.did.js';\nimport {getSatelliteExtendedActor} from '@junobuild/%CORE_LIB%';\nimport {recursiveToNullable, recursiveFromNullable} from '@junobuild/
|
|
1
|
+
export declare const jsTemplateImports = "import {idlFactory} from './satellite.factory.did.js';\nimport {getSatelliteExtendedActor} from '@junobuild/%CORE_LIB%';\nimport {recursiveToNullable, recursiveFromNullable} from '@junobuild/schema/utils';\nimport {j} from '@junobuild/schema';";
|
|
2
2
|
export declare const jsTemplateWithArgsWithResult = "\n%ARGS_ZOD%\n%RESULT_ZOD%\n\nconst %JS_FUNCTION% = async (args) => {\n\tconst parsedArgs = %ARGS_SCHEMA%.parse(args);\n\tconst idlArgs = recursiveToNullable({schema: %ARGS_SCHEMA%, value: parsedArgs});\n\n\tconst {%RS_FUNCTION%} = await getSatelliteExtendedActor({idlFactory});\n\tconst idlResult = await %RS_FUNCTION%(idlArgs);\n\n\tconst result = recursiveFromNullable({schema: %RESULT_SCHEMA%, value: idlResult});\n\treturn %RESULT_SCHEMA%.parse(result);\n};";
|
|
3
3
|
export declare const jsTemplateWithArgsNoResult = "\n%ARGS_ZOD%\n\nconst %JS_FUNCTION% = async (args) => {\n\tconst parsedArgs = %ARGS_SCHEMA%.parse(args);\n\tconst idlArgs = recursiveToNullable({schema: %ARGS_SCHEMA%, value: parsedArgs});\n\n\tconst {%RS_FUNCTION%} = await getSatelliteExtendedActor({idlFactory});\n\tawait %RS_FUNCTION%(idlArgs);\n};";
|
|
4
4
|
export declare const jsTemplateNoArgsWithResult = "\n%RESULT_ZOD%\n\nconst %JS_FUNCTION% = async () => {\n\tconst {%RS_FUNCTION%} = await getSatelliteExtendedActor({idlFactory});\n\tconst idlResult = await %RS_FUNCTION%();\n\n\tconst result = recursiveFromNullable({schema: %RESULT_SCHEMA%, value: idlResult});\n\treturn %RESULT_SCHEMA%.parse(result);\n};";
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export declare const tsTemplateImports = "import type {_SERVICE as SatelliteActor} from './satellite.did';\nimport {idlFactory} from './satellite.factory.did.js';\nimport {getSatelliteExtendedActor} from '@junobuild/%CORE_LIB%';\nimport {recursiveToNullable, recursiveFromNullable} from '@junobuild/
|
|
2
|
-
export declare const tsTemplateWithArgsWithResult = "\n%ARGS_ZOD%\n%RESULT_ZOD%\n\nconst %JS_FUNCTION% = async (args:
|
|
3
|
-
export declare const tsTemplateWithArgsNoResult = "\n%ARGS_ZOD%\n\nconst %JS_FUNCTION% = async (args:
|
|
4
|
-
export declare const tsTemplateNoArgsWithResult = "\n%RESULT_ZOD%\n\nconst %JS_FUNCTION% = async (): Promise<
|
|
1
|
+
export declare const tsTemplateImports = "import type {_SERVICE as SatelliteActor} from './satellite.did';\nimport {idlFactory} from './satellite.factory.did.js';\nimport {getSatelliteExtendedActor} from '@junobuild/%CORE_LIB%';\nimport {recursiveToNullable, recursiveFromNullable} from '@junobuild/schema/utils';\nimport {j} from '@junobuild/schema';";
|
|
2
|
+
export declare const tsTemplateWithArgsWithResult = "\n%ARGS_ZOD%\n%RESULT_ZOD%\n\nconst %JS_FUNCTION% = async (args: j.infer<typeof %ARGS_SCHEMA%>): Promise<j.infer<typeof %RESULT_SCHEMA%>> => {\n\tconst parsedArgs = %ARGS_SCHEMA%.parse(args);\n\tconst idlArgs = recursiveToNullable({schema: %ARGS_SCHEMA%, value: parsedArgs});\n\n\tconst {%RS_FUNCTION%} = await getSatelliteExtendedActor<SatelliteActor>({idlFactory});\n\tconst idlResult = await %RS_FUNCTION%(idlArgs);\n\n\tconst result = recursiveFromNullable({schema: %RESULT_SCHEMA%, value: idlResult});\n\treturn %RESULT_SCHEMA%.parse(result);\n};";
|
|
3
|
+
export declare const tsTemplateWithArgsNoResult = "\n%ARGS_ZOD%\n\nconst %JS_FUNCTION% = async (args: j.infer<typeof %ARGS_SCHEMA%>): Promise<void> => {\n\tconst parsedArgs = %ARGS_SCHEMA%.parse(args);\n\tconst idlArgs = recursiveToNullable({schema: %ARGS_SCHEMA%, value: parsedArgs});\n\n\tconst {%RS_FUNCTION%} = await getSatelliteExtendedActor<SatelliteActor>({idlFactory});\n\tawait %RS_FUNCTION%(idlArgs);\n};";
|
|
4
|
+
export declare const tsTemplateNoArgsWithResult = "\n%RESULT_ZOD%\n\nconst %JS_FUNCTION% = async (): Promise<j.infer<typeof %RESULT_SCHEMA%>> => {\n\tconst {%RS_FUNCTION%} = await getSatelliteExtendedActor<SatelliteActor>({idlFactory});\n\tconst idlResult = await %RS_FUNCTION%();\n\n\tconst result = recursiveFromNullable({schema: %RESULT_SCHEMA%, value: idlResult});\n\treturn %RESULT_SCHEMA%.parse(result);\n};";
|
|
5
5
|
export declare const tsTemplateNoArgsNoResult = "\nconst %JS_FUNCTION% = async (): Promise<void> => {\n\tconst {%RS_FUNCTION%} = await getSatelliteExtendedActor<SatelliteActor>({idlFactory});\n\tawait %RS_FUNCTION%();\n};";
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Query, Update } from '@junobuild/functions';
|
|
2
2
|
import type { TransformerOptions } from '../../types/transformer-options';
|
|
3
|
-
export declare const
|
|
3
|
+
export declare const parseSchemaApi: ({ functions: devFunctions, transformerOptions: { coreLib, outputLanguage } }: {
|
|
4
4
|
functions: [string, Update | Query][];
|
|
5
5
|
transformerOptions: TransformerOptions;
|
|
6
6
|
}) => string;
|
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
import type { z } from 'zod';
|
|
2
|
-
export interface
|
|
2
|
+
export interface SchemaResult {
|
|
3
3
|
baseName: string;
|
|
4
4
|
code: string;
|
|
5
5
|
}
|
|
6
6
|
/**
|
|
7
|
-
* Converts a Zod schema to
|
|
7
|
+
* Converts a Zod schema to Juno schema source code.
|
|
8
8
|
*
|
|
9
9
|
* @param {string} id - The base name used to generate the schema constant name.
|
|
10
10
|
* @param {z.ZodType} schema - The Zod schema to convert.
|
|
11
11
|
* @param {'Args' | 'Result'} suffix - Whether this represents function arguments or a return type.
|
|
12
|
-
* @returns {
|
|
12
|
+
* @returns {SchemaResult} An object containing the generated code and the base type name.
|
|
13
13
|
*/
|
|
14
|
-
export declare const
|
|
14
|
+
export declare const zodToSchema: ({ id, schema, suffix }: {
|
|
15
15
|
id: string;
|
|
16
16
|
schema: z.ZodType;
|
|
17
17
|
suffix: "Args" | "Result";
|
|
18
|
-
}) =>
|
|
18
|
+
}) => SchemaResult;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@junobuild/functions-tools",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"description": "Tools for generating Juno serverless functions code.",
|
|
5
5
|
"author": "David Dal Busco (https://daviddalbusco.com)",
|
|
6
6
|
"license": "MIT",
|
|
@@ -53,9 +53,9 @@
|
|
|
53
53
|
"@babel/traverse": "7.28.4",
|
|
54
54
|
"@babel/types": "7.28.4",
|
|
55
55
|
"@dfinity/utils": "^4.1",
|
|
56
|
-
"@junobuild/functions": "^0.
|
|
56
|
+
"@junobuild/functions": "^0.7",
|
|
57
57
|
"@junobuild/utils": "^0.3",
|
|
58
|
-
"@junobuild/
|
|
58
|
+
"@junobuild/schema": "^1",
|
|
59
59
|
"zod": "^4.3"
|
|
60
60
|
}
|
|
61
61
|
}
|