@junobuild/functions-tools 0.4.0 → 0.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1 @@
1
+ export declare const templateNamespace = "export const %FUNCTION_NAMESPACE% = {\n\t%JS_FUNCTIONS%\n};";
@@ -1,6 +1,5 @@
1
- import type { TransformerOptions } from './types/transformer-options';
2
- export type * from './types/transformer-options';
3
- export declare const generateApi: ({ inputFile, outputFile, transformerOptions }: {
1
+ import type { TransformerOptions } from '../types/transformer-options';
2
+ export declare const generateIdlApi: ({ inputFile, outputFile, transformerOptions }: {
4
3
  inputFile: string;
5
4
  outputFile: string;
6
5
  transformerOptions: TransformerOptions;
@@ -1,5 +1,5 @@
1
+ import type { TransformerOptions } from '../../types/transformer-options';
1
2
  import type { MethodSignature } from '../types/method-signature';
2
- import type { TransformerOptions } from '../types/transformer-options';
3
3
  export declare const parseApi: ({ methods: signatures, imports, transformerOptions: { coreLib, outputLanguage } }: {
4
4
  methods: MethodSignature[];
5
5
  imports: string[];
@@ -0,0 +1,3 @@
1
+ export * from './idl';
2
+ export type * from './types/transformer-options';
3
+ export * from './zod';
@@ -0,0 +1,7 @@
1
+ import type { Query, Update } from '@junobuild/functions';
2
+ import type { TransformerOptions } from '../types/transformer-options';
3
+ export declare const generateZodApi: ({ functions, outputFile, transformerOptions }: {
4
+ functions: [string, Update | Query][];
5
+ outputFile: string;
6
+ transformerOptions: TransformerOptions;
7
+ }) => Promise<void>;
@@ -0,0 +1,5 @@
1
+ export declare const jsTemplateImports = "import {idlFactory} from './satellite.factory.did.js';\nimport {getSatelliteExtendedActor} from '@junobuild/%CORE_LIB%';\nimport {recursiveToNullable, recursiveFromNullable} from '@junobuild/zod';\nimport * as z from 'zod';";
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
+ 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
+ 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};";
5
+ export declare const jsTemplateNoArgsNoResult = "\nconst %JS_FUNCTION% = async () => {\n\tconst {%RS_FUNCTION%} = await getSatelliteExtendedActor({idlFactory});\n\tawait %RS_FUNCTION%();\n};";
@@ -0,0 +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/zod';\nimport * as z from 'zod';";
2
+ export declare const tsTemplateWithArgsWithResult = "\n%ARGS_ZOD%\n%RESULT_ZOD%\n\nconst %JS_FUNCTION% = async (args: z.infer<typeof %ARGS_SCHEMA%>): Promise<z.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: z.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<z.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
+ export declare const tsTemplateNoArgsNoResult = "\nconst %JS_FUNCTION% = async (): Promise<void> => {\n\tconst {%RS_FUNCTION%} = await getSatelliteExtendedActor<SatelliteActor>({idlFactory});\n\tawait %RS_FUNCTION%();\n};";
@@ -0,0 +1,6 @@
1
+ import type { Query, Update } from '@junobuild/functions';
2
+ import type { TransformerOptions } from '../../types/transformer-options';
3
+ export declare const parseZodApi: ({ functions: devFunctions, transformerOptions: { coreLib, outputLanguage } }: {
4
+ functions: [string, Update | Query][];
5
+ transformerOptions: TransformerOptions;
6
+ }) => string;
@@ -0,0 +1,2 @@
1
+ export declare const BACKEND_FUNCTION_NAMESPACE = "App";
2
+ export declare const FRONTEND_FUNCTION_NAMESPACE = "functions";
@@ -1,9 +1,18 @@
1
1
  import type { z } from 'zod';
2
+ export interface CandidResult {
3
+ baseName: string;
4
+ code: string;
5
+ }
2
6
  /**
3
- * Converts a record of Zod schemas to a Candid type definition string.
4
- *
5
- * @param {Record<string, z.ZodType>} inputs - A record mapping type names to Zod schemas.
6
- * @returns {string} A Candid type definition string, one `type` declaration per entry.
7
+ * Converts a Zod schema to a Candid type definition string.
7
8
  *
9
+ * @param {string} id - The base name used to generate the type name.
10
+ * @param {z.ZodType} schema - The Zod schema to convert.
11
+ * @param {'Args' | 'Result'} suffix - Whether this represents function arguments or a return type.
12
+ * @returns {CandidResult} An object containing the generated Candid type declaration and the base type name.
8
13
  */
9
- export declare const zodToCandid: (inputs: Record<string, z.ZodType>) => string;
14
+ export declare const zodToCandid: ({ id, schema, suffix }: {
15
+ id: string;
16
+ schema: z.ZodType;
17
+ suffix: "Args" | "Result";
18
+ }) => CandidResult;
@@ -0,0 +1,6 @@
1
+ import type { Query, Update } from '@junobuild/functions';
2
+ export declare const generateDid: ({ updates, queries, outputFile }: {
3
+ updates: [string, Update][];
4
+ queries: [string, Query][];
5
+ outputFile: string;
6
+ }) => Promise<void>;
@@ -0,0 +1,5 @@
1
+ import type { Query, Update } from '@junobuild/functions';
2
+ export declare const parseDidApi: ({ queries, updates }: {
3
+ updates: [string, Update][];
4
+ queries: [string, Query][];
5
+ }) => string;
@@ -1,10 +1,11 @@
1
+ import type { Query, Update } from '@junobuild/functions';
1
2
  export interface GenerateFunctionsArgs {
2
3
  outputFile: string;
3
4
  code: Uint8Array;
4
5
  }
5
6
  export interface GenerateFunctionsData {
6
- totalQueries: number;
7
- totalUpdates: number;
7
+ queries: [string, Query][];
8
+ updates: [string, Update][];
8
9
  outputPath: string;
9
10
  }
10
11
  export type GenerateFunctionsResult = GenerateFunctionsData | null;
@@ -1,3 +1,4 @@
1
- export * from './api/idl';
1
+ export * from './api';
2
2
  export * from './converters';
3
+ export * from './did';
3
4
  export * from './functions';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@junobuild/functions-tools",
3
- "version": "0.4.0",
3
+ "version": "0.4.1",
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.5.6",
57
- "@junobuild/utils": "*",
58
- "@junobuild/zod": "^0.0.1",
56
+ "@junobuild/functions": "^0.6",
57
+ "@junobuild/utils": "^0.3",
58
+ "@junobuild/zod": "^1",
59
59
  "zod": "^4.3"
60
60
  }
61
61
  }
@@ -1 +0,0 @@
1
- export declare const FUNCTION_NAMESPACE = "App";