zod-to-x 2.1.0-dev.2 → 2.1.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/dist/converters/protobuf_v3/options.d.ts +0 -5
- package/dist/converters/protobuf_v3/options.js +0 -1
- package/dist/converters/protobuf_v3/runner.d.ts +1 -1
- package/dist/converters/protobuf_v3/runner.js +2 -5
- package/dist/core/transpiler.d.ts +4 -5
- package/dist/core/transpiler.js +1 -10
- package/dist/transpilers/cpp/runner.d.ts +1 -1
- package/dist/transpilers/cpp/runner.js +1 -1
- package/dist/transpilers/typescript/runner.d.ts +1 -1
- package/dist/transpilers/typescript/runner.js +1 -1
- package/package.json +1 -1
|
@@ -15,10 +15,5 @@ export interface IZod2ProtoV3Opt extends IZodToXOpt {
|
|
|
15
15
|
* output will be more compact. Default is false.
|
|
16
16
|
*/
|
|
17
17
|
encodeDoubleAsInt?: boolean;
|
|
18
|
-
/**
|
|
19
|
-
* ProtoV3 fields are optional by default, but this setting makes the "optional" keyword
|
|
20
|
-
* explicit improving compatibility with ProtoV2. Default is false.
|
|
21
|
-
*/
|
|
22
|
-
useExplicitOptional?: boolean;
|
|
23
18
|
}
|
|
24
19
|
export declare const defaultOpts: IZod2ProtoV3Opt;
|
|
@@ -17,4 +17,4 @@ import { IZod2ProtoV3Opt } from "./options";
|
|
|
17
17
|
* @returns The Protocol Buffers v3 definition as a string.
|
|
18
18
|
*/
|
|
19
19
|
export declare function zod2ProtoV3(schema: ZodObject<any> | ZodDiscriminatedUnion | ZodUnion<any>, // TODO: fix any to force only ZodObjects
|
|
20
|
-
opt?: Pick<IZod2AstOpt, "strict"> & Pick<IZod2ProtoV3Opt, "packageName" | "keepKeys" | "header" | "indent" | "includeComments" | "encodeDoubleAsInt"
|
|
20
|
+
opt?: Pick<IZod2AstOpt, "strict"> & Pick<IZod2ProtoV3Opt, "packageName" | "keepKeys" | "header" | "indent" | "includeComments" | "encodeDoubleAsInt">): string;
|
|
@@ -26,11 +26,11 @@ const allowedKeyTypes = [
|
|
|
26
26
|
class Zod2ProtoV3 extends core_1.Zod2X {
|
|
27
27
|
constructor(opt = {}) {
|
|
28
28
|
super(Object.assign(Object.assign({}, options_1.defaultOpts), opt));
|
|
29
|
-
this.commentKey = "//";
|
|
30
29
|
this.getUnionType = () => {
|
|
31
30
|
/** Covered by "transpileUnion" method */
|
|
32
31
|
return "";
|
|
33
32
|
};
|
|
33
|
+
this.getComment = (data, indent = "") => `${indent}// ${data}`;
|
|
34
34
|
this.getBooleanType = () => "bool";
|
|
35
35
|
this.getStringType = () => "string";
|
|
36
36
|
this.getNumberType = (isInt, range) => {
|
|
@@ -171,10 +171,7 @@ class Zod2ProtoV3 extends core_1.Zod2X {
|
|
|
171
171
|
// Avoid duplicated descriptions for transpiled items.
|
|
172
172
|
this.addComment(value.description, `\n${this.indent[1]}`);
|
|
173
173
|
}
|
|
174
|
-
|
|
175
|
-
? `optional ${this.getAttributeType(value)}`
|
|
176
|
-
: this.getAttributeType(value);
|
|
177
|
-
this.push1(`${fieldType} ${this._adaptField(key)} = ${index + 1};`);
|
|
174
|
+
this.push1(`${this.getAttributeType(value)} ${this._adaptField(key)} = ${index + 1};`);
|
|
178
175
|
});
|
|
179
176
|
this.push0("}\n");
|
|
180
177
|
}
|
|
@@ -35,7 +35,6 @@ export declare abstract class Zod2X<T extends IZodToXOpt> {
|
|
|
35
35
|
protected preImports: Set<string>;
|
|
36
36
|
protected imports: Set<string>;
|
|
37
37
|
protected postImports: Set<string>;
|
|
38
|
-
protected abstract readonly commentKey: string;
|
|
39
38
|
protected opt: Partial<T>;
|
|
40
39
|
protected constructor(opt: Partial<T>);
|
|
41
40
|
/**
|
|
@@ -69,6 +68,10 @@ export declare abstract class Zod2X<T extends IZodToXOpt> {
|
|
|
69
68
|
* @param aliasOf
|
|
70
69
|
*/
|
|
71
70
|
protected abstract addExtendedType(name: string, parentNamespace: string, aliasOf: string): void;
|
|
71
|
+
/**
|
|
72
|
+
* Returns a comment.
|
|
73
|
+
*/
|
|
74
|
+
protected abstract getComment(data: string, indent?: string): string;
|
|
72
75
|
/**
|
|
73
76
|
* Returns the keyword representing a string type in the target language.
|
|
74
77
|
*/
|
|
@@ -171,10 +174,6 @@ export declare abstract class Zod2X<T extends IZodToXOpt> {
|
|
|
171
174
|
* @param data - The AST node representing the aliased type.
|
|
172
175
|
*/
|
|
173
176
|
protected abstract transpileAliasedType(data: ASTAliasedTypes): void;
|
|
174
|
-
/**
|
|
175
|
-
* Returns a comment.
|
|
176
|
-
*/
|
|
177
|
-
protected getComment: (data: string, indent?: string) => string;
|
|
178
177
|
/**
|
|
179
178
|
* Determines if the given type token can be transpiled into the target language.
|
|
180
179
|
* @param token - The type token to check.
|
package/dist/core/transpiler.js
CHANGED
|
@@ -13,15 +13,6 @@ const string_utils_1 = __importDefault(require("../utils/string_utils"));
|
|
|
13
13
|
*/
|
|
14
14
|
class Zod2X {
|
|
15
15
|
constructor(opt) {
|
|
16
|
-
/**
|
|
17
|
-
* Returns a comment.
|
|
18
|
-
*/
|
|
19
|
-
this.getComment = (data, indent = "") => {
|
|
20
|
-
return data
|
|
21
|
-
.split("\n")
|
|
22
|
-
.map((line) => `${indent}${this.commentKey} ${line}`)
|
|
23
|
-
.join("\n");
|
|
24
|
-
};
|
|
25
16
|
// Push with indentation helpers
|
|
26
17
|
this.push0 = (data) => this.output.push(`${this.indent[0]}${data}`);
|
|
27
18
|
this.push1 = (data) => this.output.push(`${this.indent[1]}${data}`);
|
|
@@ -217,7 +208,7 @@ class Zod2X {
|
|
|
217
208
|
_getHeader() {
|
|
218
209
|
const header = [];
|
|
219
210
|
if (this.opt.header) {
|
|
220
|
-
header.push(this.
|
|
211
|
+
header.push(...this.opt.header.split("\n").map((i) => this.getComment(i)));
|
|
221
212
|
header.push("");
|
|
222
213
|
}
|
|
223
214
|
if (this.preImports.size > 0) {
|
|
@@ -4,7 +4,6 @@ import { IZod2CppOpt } from "./options";
|
|
|
4
4
|
* @description Transpiler for Zod schemas to C++11 code.
|
|
5
5
|
*/
|
|
6
6
|
export declare class Zod2Cpp extends Zod2X<IZod2CppOpt> {
|
|
7
|
-
protected readonly commentKey = "//";
|
|
8
7
|
protected serializers: string[];
|
|
9
8
|
protected useBoost: boolean;
|
|
10
9
|
protected lib: {
|
|
@@ -32,6 +31,7 @@ export declare class Zod2Cpp extends Zod2X<IZod2CppOpt> {
|
|
|
32
31
|
protected getGenericTemplatesTranslation(data: ASTNode): string | undefined;
|
|
33
32
|
protected checkExtendedTypeInclusion(data: ASTNode, type?: "union" | "alias"): boolean;
|
|
34
33
|
protected runAfter(): void;
|
|
34
|
+
protected getComment: (data: string, indent?: string) => string;
|
|
35
35
|
protected getDateType: () => string;
|
|
36
36
|
protected getBooleanType: () => string;
|
|
37
37
|
protected getStringType: () => string;
|
|
@@ -16,11 +16,11 @@ const options_1 = require("./options");
|
|
|
16
16
|
class Zod2Cpp extends core_1.Zod2X {
|
|
17
17
|
constructor(opt = {}) {
|
|
18
18
|
super(Object.assign(Object.assign({}, options_1.defaultOpts), opt));
|
|
19
|
-
this.commentKey = "//";
|
|
20
19
|
this.getIntersectionType = () => {
|
|
21
20
|
/** Covered by "transpileIntersection" method */
|
|
22
21
|
return "";
|
|
23
22
|
};
|
|
23
|
+
this.getComment = (data, indent = "") => `${indent}// ${data}`;
|
|
24
24
|
this.getDateType = () => this.getStringType(); // Representing ISO date as a string
|
|
25
25
|
this.getBooleanType = () => "bool";
|
|
26
26
|
this.getStringType = () => {
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { ASTAliasedTypes, ASTEnum, ASTIntersection, ASTNode, ASTObject, ASTUnion, Zod2X } from "../../core";
|
|
2
2
|
import { IZod2TsOpt } from "./options";
|
|
3
3
|
export declare class Zod2Ts extends Zod2X<IZod2TsOpt> {
|
|
4
|
-
protected readonly commentKey = "//";
|
|
5
4
|
constructor(opt?: IZod2TsOpt);
|
|
6
5
|
protected runAfter(): void;
|
|
7
6
|
protected runBefore(): void;
|
|
@@ -14,6 +13,7 @@ export declare class Zod2Ts extends Zod2X<IZod2TsOpt> {
|
|
|
14
13
|
}): void;
|
|
15
14
|
protected getGenericTemplatesTranslation(data: ASTNode): string | undefined;
|
|
16
15
|
protected checkExtendedTypeInclusion(data: ASTNode, type?: "alias" | "union" | "d-union"): boolean;
|
|
16
|
+
protected getComment: (data: string, indent?: string) => string;
|
|
17
17
|
protected getAnyType: () => string;
|
|
18
18
|
protected getBooleanType: () => string;
|
|
19
19
|
protected getDateType: () => string;
|
|
@@ -10,7 +10,7 @@ const options_1 = require("./options");
|
|
|
10
10
|
class Zod2Ts extends core_1.Zod2X {
|
|
11
11
|
constructor(opt = {}) {
|
|
12
12
|
super(Object.assign(Object.assign({}, options_1.defaultOpts), opt));
|
|
13
|
-
this.
|
|
13
|
+
this.getComment = (data, indent = "") => `${indent}// ${data}`;
|
|
14
14
|
this.getAnyType = () => "any";
|
|
15
15
|
this.getBooleanType = () => "boolean";
|
|
16
16
|
this.getDateType = () => "Date";
|