@junobuild/functions-tools 0.4.0-next-2026-03-12
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 +108 -0
- package/dist/node/index.mjs +123 -0
- package/dist/node/index.mjs.map +7 -0
- package/dist/types/api/idl/index.d.ts +7 -0
- package/dist/types/api/idl/services/inspector.services.d.ts +7 -0
- package/dist/types/api/idl/services/parser.services.d.ts +7 -0
- package/dist/types/api/idl/types/method-signature.d.ts +5 -0
- package/dist/types/api/idl/types/transformer-options.d.ts +4 -0
- package/dist/types/converters/_converters.d.ts +11 -0
- package/dist/types/converters/_types.d.ts +42 -0
- package/dist/types/converters/index.d.ts +3 -0
- package/dist/types/converters/zod-to-candid.d.ts +9 -0
- package/dist/types/converters/zod-to-idl.d.ts +20 -0
- package/dist/types/converters/zod-to-rust.d.ts +19 -0
- package/dist/types/converters/zod-to-zod.d.ts +18 -0
- package/dist/types/functions/_constants.d.ts +1 -0
- package/dist/types/functions/index.d.ts +11 -0
- package/dist/types/functions/services/parser.services.d.ts +5 -0
- package/dist/types/index.d.ts +3 -0
- package/package.json +61 -0
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { TransformerOptions } from './types/transformer-options';
|
|
2
|
+
export type * from './types/transformer-options';
|
|
3
|
+
export declare const generateApi: ({ inputFile, outputFile, transformerOptions }: {
|
|
4
|
+
inputFile: string;
|
|
5
|
+
outputFile: string;
|
|
6
|
+
transformerOptions: TransformerOptions;
|
|
7
|
+
}) => Promise<void>;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { MethodSignature } from '../types/method-signature';
|
|
2
|
+
import type { TransformerOptions } from '../types/transformer-options';
|
|
3
|
+
export declare const parseApi: ({ methods: signatures, imports, transformerOptions: { coreLib, outputLanguage } }: {
|
|
4
|
+
methods: MethodSignature[];
|
|
5
|
+
imports: string[];
|
|
6
|
+
transformerOptions: TransformerOptions;
|
|
7
|
+
}) => string;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import * as z from 'zod';
|
|
2
|
+
import type { SputnikSchema } from './_types';
|
|
3
|
+
export interface SputnikSchemaResult {
|
|
4
|
+
id: string;
|
|
5
|
+
schema: SputnikSchema;
|
|
6
|
+
isTopLevelOptional: boolean;
|
|
7
|
+
}
|
|
8
|
+
export declare const jsonToSputnikSchema: ({ id, zodSchema }: {
|
|
9
|
+
id: string;
|
|
10
|
+
zodSchema: z.ZodType;
|
|
11
|
+
}) => SputnikSchemaResult;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type { core } from 'zod';
|
|
2
|
+
export type JSONSchemaOutput = core.ZodStandardJSONSchemaPayload<any>;
|
|
3
|
+
export type JSONSchema = core.JSONSchema.BaseSchema;
|
|
4
|
+
export type SputnikSchema = {
|
|
5
|
+
kind: 'text';
|
|
6
|
+
} | {
|
|
7
|
+
kind: 'bool';
|
|
8
|
+
} | {
|
|
9
|
+
kind: 'float64';
|
|
10
|
+
} | {
|
|
11
|
+
kind: 'int32';
|
|
12
|
+
} | {
|
|
13
|
+
kind: 'nat';
|
|
14
|
+
} | {
|
|
15
|
+
kind: 'opt';
|
|
16
|
+
inner: SputnikSchema;
|
|
17
|
+
} | {
|
|
18
|
+
kind: 'vec';
|
|
19
|
+
inner: SputnikSchema;
|
|
20
|
+
} | {
|
|
21
|
+
kind: 'record';
|
|
22
|
+
fields: {
|
|
23
|
+
name: string;
|
|
24
|
+
type: SputnikSchema;
|
|
25
|
+
}[];
|
|
26
|
+
} | {
|
|
27
|
+
kind: 'tuple';
|
|
28
|
+
members: SputnikSchema[];
|
|
29
|
+
} | {
|
|
30
|
+
kind: 'indexedTuple';
|
|
31
|
+
members: SputnikSchema[];
|
|
32
|
+
} | {
|
|
33
|
+
kind: 'variant';
|
|
34
|
+
tags: string[];
|
|
35
|
+
} | {
|
|
36
|
+
kind: 'variantRecords';
|
|
37
|
+
members: SputnikSchema[];
|
|
38
|
+
} | {
|
|
39
|
+
kind: 'principal';
|
|
40
|
+
} | {
|
|
41
|
+
kind: 'uint8array';
|
|
42
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { z } from 'zod';
|
|
2
|
+
/**
|
|
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
|
+
*
|
|
8
|
+
*/
|
|
9
|
+
export declare const zodToCandid: (inputs: Record<string, z.ZodType>) => string;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { IDL } from '@icp-sdk/core/candid';
|
|
2
|
+
import type { z } from 'zod';
|
|
3
|
+
export interface IdlResult {
|
|
4
|
+
baseName: string;
|
|
5
|
+
idl: IDL.Type;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Converts a Zod schema to a Candid IDL type for use with `IDL.encode` and `IDL.decode`.
|
|
9
|
+
*
|
|
10
|
+
* @param {string} id - The base name used to generate the IDL type name.
|
|
11
|
+
* @param {z.ZodType} schema - The Zod schema to convert.
|
|
12
|
+
* @param {'Args' | 'Result'} suffix - Whether this represents function arguments or a return type.
|
|
13
|
+
* @returns {IdlResult} An object containing the generated IDL type and the base type name.
|
|
14
|
+
*
|
|
15
|
+
*/
|
|
16
|
+
export declare const zodToIdl: ({ id, schema, suffix }: {
|
|
17
|
+
id: string;
|
|
18
|
+
schema: z.ZodType;
|
|
19
|
+
suffix: "Args" | "Result";
|
|
20
|
+
}) => IdlResult;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { z } from 'zod';
|
|
2
|
+
export interface RustResult {
|
|
3
|
+
baseName: string;
|
|
4
|
+
code: string;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Converts a Zod schema to a Rust type definition string.
|
|
8
|
+
*
|
|
9
|
+
* @param {string} id - The base name used to generate the Rust struct or type alias 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 {RustResult} An object containing the generated Rust code and the base type name.
|
|
13
|
+
*
|
|
14
|
+
*/
|
|
15
|
+
export declare const zodToRust: ({ id, schema, suffix }: {
|
|
16
|
+
id: string;
|
|
17
|
+
schema: z.ZodType;
|
|
18
|
+
suffix: "Args" | "Result";
|
|
19
|
+
}) => RustResult;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { z } from 'zod';
|
|
2
|
+
export interface ZodResult {
|
|
3
|
+
baseName: string;
|
|
4
|
+
code: string;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Converts a Zod schema to a Zod schema source code string.
|
|
8
|
+
*
|
|
9
|
+
* @param {string} id - The base name used to generate the schema constant 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 {ZodResult} An object containing the generated code and the base type name.
|
|
13
|
+
*/
|
|
14
|
+
export declare const zodToZod: ({ id, schema, suffix }: {
|
|
15
|
+
id: string;
|
|
16
|
+
schema: z.ZodType;
|
|
17
|
+
suffix: "Args" | "Result";
|
|
18
|
+
}) => ZodResult;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const FUNCTION_NAMESPACE = "App";
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export interface GenerateFunctionsArgs {
|
|
2
|
+
outputFile: string;
|
|
3
|
+
code: Uint8Array;
|
|
4
|
+
}
|
|
5
|
+
export interface GenerateFunctionsData {
|
|
6
|
+
totalQueries: number;
|
|
7
|
+
totalUpdates: number;
|
|
8
|
+
outputPath: string;
|
|
9
|
+
}
|
|
10
|
+
export type GenerateFunctionsResult = GenerateFunctionsData | null;
|
|
11
|
+
export declare const generateFunctions: ({ code, outputFile }: GenerateFunctionsArgs) => Promise<GenerateFunctionsResult>;
|
package/package.json
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@junobuild/functions-tools",
|
|
3
|
+
"version": "0.4.0-next-2026-03-12",
|
|
4
|
+
"description": "Tools for generating Juno serverless functions code.",
|
|
5
|
+
"author": "David Dal Busco (https://daviddalbusco.com)",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"type": "module",
|
|
8
|
+
"main": "./dist/node/index.mjs",
|
|
9
|
+
"module": "./dist/node/index.mjs",
|
|
10
|
+
"types": "./dist/types/index.d.ts",
|
|
11
|
+
"exports": {
|
|
12
|
+
".": {
|
|
13
|
+
"import": {
|
|
14
|
+
"types": "./dist/types/index.d.ts",
|
|
15
|
+
"default": "./dist/node/index.mjs"
|
|
16
|
+
},
|
|
17
|
+
"require": {
|
|
18
|
+
"types": "./dist/types/index.d.ts",
|
|
19
|
+
"default": "./dist/node/index.mjs"
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
"files": [
|
|
24
|
+
"dist",
|
|
25
|
+
"README.md",
|
|
26
|
+
"LICENSE"
|
|
27
|
+
],
|
|
28
|
+
"scripts": {
|
|
29
|
+
"rmdir": "node ../../scripts/rmdir.mjs",
|
|
30
|
+
"ts-declaration": "tsc --emitDeclarationOnly --outDir dist/types",
|
|
31
|
+
"build": "npm run rmdir && mkdir -p dist && node esbuild.mjs && npm run ts-declaration",
|
|
32
|
+
"prepack": "npm run build"
|
|
33
|
+
},
|
|
34
|
+
"repository": {
|
|
35
|
+
"type": "git",
|
|
36
|
+
"url": "git+https://github.com/junobuild/juno-js.git",
|
|
37
|
+
"directory": "packages/functions-tools"
|
|
38
|
+
},
|
|
39
|
+
"bugs": {
|
|
40
|
+
"url": "https://github.com/junobuild/juno-js"
|
|
41
|
+
},
|
|
42
|
+
"keywords": [
|
|
43
|
+
"candid",
|
|
44
|
+
"parser",
|
|
45
|
+
"cli"
|
|
46
|
+
],
|
|
47
|
+
"homepage": "https://juno.build",
|
|
48
|
+
"peerDependencies": {
|
|
49
|
+
"@babel/core": "*",
|
|
50
|
+
"@babel/parser": "*",
|
|
51
|
+
"@babel/plugin-transform-modules-commonjs": "*",
|
|
52
|
+
"@babel/preset-typescript": "*",
|
|
53
|
+
"@babel/traverse": "*",
|
|
54
|
+
"@babel/types": "*",
|
|
55
|
+
"@dfinity/utils": "*",
|
|
56
|
+
"@junobuild/functions": "*",
|
|
57
|
+
"@junobuild/utils": "*",
|
|
58
|
+
"@junobuild/zod": "*",
|
|
59
|
+
"zod": "*"
|
|
60
|
+
}
|
|
61
|
+
}
|