@gqlbase/plugins 0.1.2 → 0.1.4
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/appsync/AppSyncSchemaGeneratorPlugin/AppSyncSchemaGeneratorPlugin.d.ts.map +1 -1
- package/dist/appsync/AppSyncSchemaGeneratorPlugin/AppSyncSchemaGeneratorPlugin.js +2 -3
- package/dist/appsync/AppSyncSchemaGeneratorPlugin/AppSyncSchemaGeneratorPlugin.js.map +1 -1
- package/dist/appsync/AppSyncSchemaGeneratorPlugin/AppSyncSchemaGeneratorPlugin.utils.d.ts +0 -3
- package/dist/appsync/AppSyncSchemaGeneratorPlugin/AppSyncSchemaGeneratorPlugin.utils.d.ts.map +1 -1
- package/dist/appsync/AppSyncSchemaGeneratorPlugin/AppSyncSchemaGeneratorPlugin.utils.js +1 -7
- package/dist/appsync/AppSyncSchemaGeneratorPlugin/AppSyncSchemaGeneratorPlugin.utils.js.map +1 -1
- package/dist/base/ModelPlugin/ModelPlugin.d.ts +1 -0
- package/dist/base/ModelPlugin/ModelPlugin.d.ts.map +1 -1
- package/dist/base/ModelPlugin/ModelPlugin.js +36 -15
- package/dist/base/ModelPlugin/ModelPlugin.js.map +1 -1
- package/dist/base/ModelPlugin/ModelPlugin.utils.d.ts +4 -3
- package/dist/base/ModelPlugin/ModelPlugin.utils.d.ts.map +1 -1
- package/dist/base/ModelPlugin/ModelPlugin.utils.js +14 -8
- package/dist/base/ModelPlugin/ModelPlugin.utils.js.map +1 -1
- package/dist/base/ModelTypesGeneratorPlugin/ModelTypesGeneratorPlugin.d.ts +7 -11
- package/dist/base/ModelTypesGeneratorPlugin/ModelTypesGeneratorPlugin.d.ts.map +1 -1
- package/dist/base/ModelTypesGeneratorPlugin/ModelTypesGeneratorPlugin.js +26 -98
- package/dist/base/ModelTypesGeneratorPlugin/ModelTypesGeneratorPlugin.js.map +1 -1
- package/dist/base/RelationsPlugin/RelationsPlugin.d.ts.map +1 -1
- package/dist/base/RelationsPlugin/RelationsPlugin.js +7 -2
- package/dist/base/RelationsPlugin/RelationsPlugin.js.map +1 -1
- package/dist/base/TypesGeneratorBase/TypesGeneratorBase.d.ts +2 -2
- package/dist/base/TypesGeneratorBase/TypesGeneratorBase.d.ts.map +1 -1
- package/dist/base/TypesGeneratorBase/TypesGeneratorBase.js +3 -4
- package/dist/base/TypesGeneratorBase/TypesGeneratorBase.js.map +1 -1
- package/dist/base/UtilitiesPlugin/UtilitiesPlugin.d.ts +1 -1
- package/dist/base/UtilitiesPlugin/UtilitiesPlugin.d.ts.map +1 -1
- package/dist/base/UtilitiesPlugin/UtilitiesPlugin.js +26 -30
- package/dist/base/UtilitiesPlugin/UtilitiesPlugin.js.map +1 -1
- package/dist/base/UtilitiesPlugin/UtilitiesPlugin.utils.d.ts +12 -1
- package/dist/base/UtilitiesPlugin/UtilitiesPlugin.utils.d.ts.map +1 -1
- package/dist/base/UtilitiesPlugin/UtilitiesPlugin.utils.js +27 -0
- package/dist/base/UtilitiesPlugin/UtilitiesPlugin.utils.js.map +1 -1
- package/dist/base/UtilitiesPlugin/index.d.ts +1 -1
- package/dist/base/UtilitiesPlugin/index.d.ts.map +1 -1
- package/dist/base/UtilitiesPlugin/index.js +1 -1
- package/dist/base/UtilitiesPlugin/index.js.map +1 -1
- package/dist/middy/MiddyAppSyncGraphQLPlugin/MiddyAppSyncGraphQLPlugin.d.ts.map +1 -1
- package/dist/middy/MiddyAppSyncGraphQLPlugin/MiddyAppSyncGraphQLPlugin.js +17 -5
- package/dist/middy/MiddyAppSyncGraphQLPlugin/MiddyAppSyncGraphQLPlugin.js.map +1 -1
- package/dist/middy/MiddyAppSyncGraphQLPlugin/MiddyAppSyncGraphQLPlugin.utils.d.ts +6 -0
- package/dist/middy/MiddyAppSyncGraphQLPlugin/MiddyAppSyncGraphQLPlugin.utils.d.ts.map +1 -1
- package/dist/middy/MiddyAppSyncGraphQLPlugin/MiddyAppSyncGraphQLPlugin.utils.js.map +1 -1
- package/dist/zod/ZodSchemaGeneratorPlugin/ZodSchemaGeneratorPlugin.d.ts +68 -0
- package/dist/zod/ZodSchemaGeneratorPlugin/ZodSchemaGeneratorPlugin.d.ts.map +1 -0
- package/dist/zod/ZodSchemaGeneratorPlugin/ZodSchemaGeneratorPlugin.js +300 -0
- package/dist/zod/ZodSchemaGeneratorPlugin/ZodSchemaGeneratorPlugin.js.map +1 -0
- package/dist/zod/ZodSchemaGeneratorPlugin/ZodSchemaGeneratorPlugin.utils.d.ts +17 -0
- package/dist/zod/ZodSchemaGeneratorPlugin/ZodSchemaGeneratorPlugin.utils.d.ts.map +1 -0
- package/dist/zod/ZodSchemaGeneratorPlugin/ZodSchemaGeneratorPlugin.utils.js +24 -0
- package/dist/zod/ZodSchemaGeneratorPlugin/ZodSchemaGeneratorPlugin.utils.js.map +1 -0
- package/dist/zod/ZodSchemaGeneratorPlugin/index.d.ts +2 -0
- package/dist/zod/ZodSchemaGeneratorPlugin/index.d.ts.map +1 -0
- package/dist/zod/ZodSchemaGeneratorPlugin/index.js +2 -0
- package/dist/zod/ZodSchemaGeneratorPlugin/index.js.map +1 -0
- package/dist/zod/index.d.ts +2 -0
- package/dist/zod/index.d.ts.map +1 -0
- package/dist/zod/index.js +2 -0
- package/dist/zod/index.js.map +1 -0
- package/package.json +4 -13
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { ITransformerContext, TransformerPluginBase } from "@gqlbase/core";
|
|
2
|
+
import { DefinitionNode } from "@gqlbase/core/definition";
|
|
3
|
+
import { ZodSchemaGeneratorPluginOptions } from "./ZodSchemaGeneratorPlugin.utils.js";
|
|
4
|
+
/**
|
|
5
|
+
* Generates Zod schemas for the defined types in the GraphQL schema. This can be used for runtime validation of data against the schema.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```graphql
|
|
9
|
+
* # schema.graphql
|
|
10
|
+
* enum UserRole {
|
|
11
|
+
* ADMIN
|
|
12
|
+
* USER
|
|
13
|
+
* }
|
|
14
|
+
*
|
|
15
|
+
* type User {
|
|
16
|
+
* id: ID!
|
|
17
|
+
* name: String! `@constraint(min: 3, max: 50)`
|
|
18
|
+
* email: String!
|
|
19
|
+
* role: UserRole!
|
|
20
|
+
* }
|
|
21
|
+
* ```
|
|
22
|
+
*
|
|
23
|
+
* ```typescript
|
|
24
|
+
* // generated/zod/validators.typegen.ts
|
|
25
|
+
* import { z } from "zod";
|
|
26
|
+
*
|
|
27
|
+
* export const UserRoleSchema = z.enum(["ADMIN", "USER"]);
|
|
28
|
+
*
|
|
29
|
+
* export const UserSchema = z.object({
|
|
30
|
+
* id: z.string(),
|
|
31
|
+
* name: z.string().min(3).max(50),
|
|
32
|
+
* email: z.string(),
|
|
33
|
+
* role: UserRoleSchema,
|
|
34
|
+
* });
|
|
35
|
+
* ```
|
|
36
|
+
*/
|
|
37
|
+
export declare class ZodSchemaGeneratorPlugin extends TransformerPluginBase {
|
|
38
|
+
private nodes;
|
|
39
|
+
private options;
|
|
40
|
+
constructor(context: ITransformerContext, options?: ZodSchemaGeneratorPluginOptions);
|
|
41
|
+
private _getContent;
|
|
42
|
+
private _zCall;
|
|
43
|
+
private _chainCall;
|
|
44
|
+
private _parseZodExpression;
|
|
45
|
+
private _createScalarZodExpression;
|
|
46
|
+
private _applyConstraints;
|
|
47
|
+
private _applyNullable;
|
|
48
|
+
private _createOutputFieldZodExpression;
|
|
49
|
+
private _createInputFieldZodExpression;
|
|
50
|
+
private _createObjectFieldProperties;
|
|
51
|
+
private _createInputFieldProperties;
|
|
52
|
+
private _createSchemaConstDeclaration;
|
|
53
|
+
private _getSelfReferenceFields;
|
|
54
|
+
private _generateEnum;
|
|
55
|
+
private _generateObject;
|
|
56
|
+
private _generateInputObject;
|
|
57
|
+
private _generateUnion;
|
|
58
|
+
before(): void;
|
|
59
|
+
match(definition: DefinitionNode): boolean;
|
|
60
|
+
generate(definition: DefinitionNode): void;
|
|
61
|
+
output(): {
|
|
62
|
+
zodSchemas: string;
|
|
63
|
+
} | {
|
|
64
|
+
zodSchemas?: undefined;
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
export declare const zodSchemaGeneratorPlugin: (options?: ZodSchemaGeneratorPluginOptions | undefined) => import("@gqlbase/core").IPluginFactory;
|
|
68
|
+
//# sourceMappingURL=ZodSchemaGeneratorPlugin.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ZodSchemaGeneratorPlugin.d.ts","sourceRoot":"","sources":["../../../src/zod/ZodSchemaGeneratorPlugin/ZodSchemaGeneratorPlugin.ts"],"names":[],"mappings":"AACA,OAAO,EAAuB,mBAAmB,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAC;AAIhG,OAAO,EACL,cAAc,EAoBf,MAAM,0BAA0B,CAAC;AAWlC,OAAO,EAGL,+BAA+B,EAChC,MAAM,qCAAqC,CAAC;AAE7C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AAEH,qBAAa,wBAAyB,SAAQ,qBAAqB;IACjE,OAAO,CAAC,KAAK,CAAiB;IAC9B,OAAO,CAAC,OAAO,CAA4C;gBAE/C,OAAO,EAAE,mBAAmB,EAAE,OAAO,GAAE,+BAAoC;IAKvF,OAAO,CAAC,WAAW;IAiBnB,OAAO,CAAC,MAAM;IAWd,OAAO,CAAC,UAAU;IAYlB,OAAO,CAAC,mBAAmB;IAY3B,OAAO,CAAC,0BAA0B;IA2ClC,OAAO,CAAC,iBAAiB;IA0BzB,OAAO,CAAC,cAAc;IAKtB,OAAO,CAAC,+BAA+B;IA+BvC,OAAO,CAAC,8BAA8B;IAoCtC,OAAO,CAAC,4BAA4B;IAyBpC,OAAO,CAAC,2BAA2B;IAsBnC,OAAO,CAAC,6BAA6B;IAsBrC,OAAO,CAAC,uBAAuB;IAY/B,OAAO,CAAC,aAAa;IAerB,OAAO,CAAC,eAAe;IAUvB,OAAO,CAAC,oBAAoB;IA6C5B,OAAO,CAAC,cAAc;IAiBf,MAAM;IAoBN,KAAK,CAAC,UAAU,EAAE,cAAc,GAAG,OAAO;IAS1C,QAAQ,CAAC,UAAU,EAAE,cAAc;IAsBnC,MAAM;;;;;CAYd;AAED,eAAO,MAAM,wBAAwB,mGAAgD,CAAC"}
|
|
@@ -0,0 +1,300 @@
|
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
import { createPluginFactory, TransformerPluginBase } from "@gqlbase/core";
|
|
3
|
+
import { isBuildInScalar } from "@gqlbase/shared/definition";
|
|
4
|
+
import { createFileHeaders } from "@gqlbase/shared/codegen";
|
|
5
|
+
import { getTypeHint, isInternal } from "@gqlbase/core/plugins";
|
|
6
|
+
import { InputObjectNode, isDirectiveDefinitionNode, isEnumNode, isInputObjectNode, isInterfaceNode, isNullableTypeNode, isObjectNode, isOperationNode, isScalarNode, isUnionNode, ListTypeNode, NonNullTypeNode, } from "@gqlbase/core/definition";
|
|
7
|
+
import { TransformerPluginExecutionError } from "@gqlbase/shared/errors";
|
|
8
|
+
import { isBaseScalar } from "../../base/ScalarsPlugin/ScalarsPlugin.utils.js";
|
|
9
|
+
import { hasConstraints, parseConstraints, isServerOnly, isWriteOnly, } from "../../base/UtilitiesPlugin/index.js";
|
|
10
|
+
import { isSemanticNullable } from "../../base/RfcFeaturesPlugin/index.js";
|
|
11
|
+
import { isRelationField } from "../../base/RelationsPlugin/index.js";
|
|
12
|
+
import { CUSTOM_SCALAR_ZOD_MAP, mergeOptions, } from "./ZodSchemaGeneratorPlugin.utils.js";
|
|
13
|
+
/**
|
|
14
|
+
* Generates Zod schemas for the defined types in the GraphQL schema. This can be used for runtime validation of data against the schema.
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```graphql
|
|
18
|
+
* # schema.graphql
|
|
19
|
+
* enum UserRole {
|
|
20
|
+
* ADMIN
|
|
21
|
+
* USER
|
|
22
|
+
* }
|
|
23
|
+
*
|
|
24
|
+
* type User {
|
|
25
|
+
* id: ID!
|
|
26
|
+
* name: String! `@constraint(min: 3, max: 50)`
|
|
27
|
+
* email: String!
|
|
28
|
+
* role: UserRole!
|
|
29
|
+
* }
|
|
30
|
+
* ```
|
|
31
|
+
*
|
|
32
|
+
* ```typescript
|
|
33
|
+
* // generated/zod/validators.typegen.ts
|
|
34
|
+
* import { z } from "zod";
|
|
35
|
+
*
|
|
36
|
+
* export const UserRoleSchema = z.enum(["ADMIN", "USER"]);
|
|
37
|
+
*
|
|
38
|
+
* export const UserSchema = z.object({
|
|
39
|
+
* id: z.string(),
|
|
40
|
+
* name: z.string().min(3).max(50),
|
|
41
|
+
* email: z.string(),
|
|
42
|
+
* role: UserRoleSchema,
|
|
43
|
+
* });
|
|
44
|
+
* ```
|
|
45
|
+
*/
|
|
46
|
+
export class ZodSchemaGeneratorPlugin extends TransformerPluginBase {
|
|
47
|
+
nodes = [];
|
|
48
|
+
options;
|
|
49
|
+
constructor(context, options = {}) {
|
|
50
|
+
super("ZodSchemaGeneratorPlugin", context);
|
|
51
|
+
this.options = mergeOptions(options);
|
|
52
|
+
}
|
|
53
|
+
_getContent() {
|
|
54
|
+
const file = ts.createSourceFile(this.options.fileName,
|
|
55
|
+
/*sourceText*/ "", ts.ScriptTarget.Latest,
|
|
56
|
+
/*setParentNodes*/ false, ts.ScriptKind.TS);
|
|
57
|
+
const printer = ts.createPrinter({
|
|
58
|
+
newLine: ts.NewLineKind.CarriageReturnLineFeed,
|
|
59
|
+
removeComments: false,
|
|
60
|
+
});
|
|
61
|
+
return printer.printList(ts.ListFormat.MultiLine, ts.factory.createNodeArray(this.nodes), file);
|
|
62
|
+
}
|
|
63
|
+
_zCall(name, args = []) {
|
|
64
|
+
return ts.factory.createCallExpression(ts.factory.createPropertyAccessExpression(ts.factory.createIdentifier("z"), ts.factory.createIdentifier(name)), undefined, args);
|
|
65
|
+
}
|
|
66
|
+
_chainCall(expr, method, args = []) {
|
|
67
|
+
return ts.factory.createCallExpression(ts.factory.createPropertyAccessExpression(expr, ts.factory.createIdentifier(method)), undefined, args);
|
|
68
|
+
}
|
|
69
|
+
_parseZodExpression(zodCode) {
|
|
70
|
+
const sourceFile = ts.createSourceFile("temp.ts", zodCode, ts.ScriptTarget.Latest, false);
|
|
71
|
+
const statement = sourceFile.statements[0];
|
|
72
|
+
if (ts.isExpressionStatement(statement)) {
|
|
73
|
+
return statement.expression;
|
|
74
|
+
}
|
|
75
|
+
throw new TransformerPluginExecutionError(this.name, `Failed to parse Zod expression: ${zodCode}`);
|
|
76
|
+
}
|
|
77
|
+
_createScalarZodExpression(typeName, suffix = "Schema") {
|
|
78
|
+
if (isBuildInScalar(typeName)) {
|
|
79
|
+
switch (typeName) {
|
|
80
|
+
case "ID":
|
|
81
|
+
case "String":
|
|
82
|
+
return this._zCall("string");
|
|
83
|
+
case "Int":
|
|
84
|
+
return this._zCall("int");
|
|
85
|
+
case "Float":
|
|
86
|
+
return this._zCall("number");
|
|
87
|
+
case "Boolean":
|
|
88
|
+
return this._zCall("boolean");
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
if (isBaseScalar(typeName)) {
|
|
92
|
+
const zodCode = CUSTOM_SCALAR_ZOD_MAP[typeName];
|
|
93
|
+
return this._parseZodExpression(zodCode);
|
|
94
|
+
}
|
|
95
|
+
const typeDef = this.context.document.getNodeOrThrow(typeName);
|
|
96
|
+
if (isScalarNode(typeDef)) {
|
|
97
|
+
const hint = getTypeHint(typeDef);
|
|
98
|
+
switch (hint) {
|
|
99
|
+
case "id":
|
|
100
|
+
case "string":
|
|
101
|
+
return this._zCall("string");
|
|
102
|
+
case "number":
|
|
103
|
+
return this._zCall("number");
|
|
104
|
+
case "boolean":
|
|
105
|
+
return this._zCall("boolean");
|
|
106
|
+
case "object":
|
|
107
|
+
return this._parseZodExpression("z.record(z.string(), z.unknown())");
|
|
108
|
+
case "unknown":
|
|
109
|
+
default:
|
|
110
|
+
return this._zCall("unknown");
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
return ts.factory.createIdentifier(`${typeName}${suffix}`);
|
|
114
|
+
}
|
|
115
|
+
_applyConstraints(expr, field) {
|
|
116
|
+
if (!hasConstraints(field)) {
|
|
117
|
+
return expr;
|
|
118
|
+
}
|
|
119
|
+
const constraints = parseConstraints(field);
|
|
120
|
+
let result = expr;
|
|
121
|
+
if (constraints.min !== undefined) {
|
|
122
|
+
result = this._chainCall(result, "min", [ts.factory.createNumericLiteral(constraints.min)]);
|
|
123
|
+
}
|
|
124
|
+
if (constraints.max !== undefined) {
|
|
125
|
+
result = this._chainCall(result, "max", [ts.factory.createNumericLiteral(constraints.max)]);
|
|
126
|
+
}
|
|
127
|
+
if (constraints.pattern !== undefined) {
|
|
128
|
+
result = this._chainCall(result, "regex", [
|
|
129
|
+
ts.factory.createRegularExpressionLiteral(`/${constraints.pattern}/`),
|
|
130
|
+
]);
|
|
131
|
+
}
|
|
132
|
+
return result;
|
|
133
|
+
}
|
|
134
|
+
_applyNullable(expr, level) {
|
|
135
|
+
const nullable = this._chainCall(expr, "nullable");
|
|
136
|
+
return level === 0 ? this._chainCall(nullable, "optional") : nullable;
|
|
137
|
+
}
|
|
138
|
+
_createOutputFieldZodExpression(field, fieldType, level = 0) {
|
|
139
|
+
if (fieldType instanceof NonNullTypeNode) {
|
|
140
|
+
return this._createOutputFieldZodExpression(field, fieldType.type, level);
|
|
141
|
+
}
|
|
142
|
+
if (fieldType instanceof ListTypeNode) {
|
|
143
|
+
const elementExpr = this._createOutputFieldZodExpression(field, fieldType.type, level + 1);
|
|
144
|
+
let arrayExpr = this._zCall("array", [elementExpr]);
|
|
145
|
+
if (isSemanticNullable(field, level)) {
|
|
146
|
+
arrayExpr = this._applyNullable(arrayExpr, level);
|
|
147
|
+
}
|
|
148
|
+
return arrayExpr;
|
|
149
|
+
}
|
|
150
|
+
// Named type (leaf)
|
|
151
|
+
let expr = this._createScalarZodExpression(fieldType.name);
|
|
152
|
+
expr = this._applyConstraints(expr, field);
|
|
153
|
+
if (isSemanticNullable(field, level)) {
|
|
154
|
+
expr = this._applyNullable(expr, level);
|
|
155
|
+
}
|
|
156
|
+
return expr;
|
|
157
|
+
}
|
|
158
|
+
_createInputFieldZodExpression(field, fieldType, level = 0, suffix = "Schema") {
|
|
159
|
+
if (fieldType instanceof NonNullTypeNode) {
|
|
160
|
+
return this._createInputFieldZodExpression(field, fieldType.type, level, suffix);
|
|
161
|
+
}
|
|
162
|
+
if (fieldType instanceof ListTypeNode) {
|
|
163
|
+
const elementExpr = this._createInputFieldZodExpression(field, fieldType.type, level + 1, suffix);
|
|
164
|
+
let arrayExpr = this._zCall("array", [elementExpr]);
|
|
165
|
+
if (isNullableTypeNode(field.type, level)) {
|
|
166
|
+
arrayExpr = this._applyNullable(arrayExpr, level);
|
|
167
|
+
}
|
|
168
|
+
return arrayExpr;
|
|
169
|
+
}
|
|
170
|
+
let expr = this._createScalarZodExpression(fieldType.name, suffix);
|
|
171
|
+
expr = this._applyConstraints(expr, field);
|
|
172
|
+
if (isNullableTypeNode(field.type, level)) {
|
|
173
|
+
expr = this._applyNullable(expr, level);
|
|
174
|
+
}
|
|
175
|
+
return expr;
|
|
176
|
+
}
|
|
177
|
+
_createObjectFieldProperties(definition) {
|
|
178
|
+
const properties = [];
|
|
179
|
+
for (const field of definition.fields ?? []) {
|
|
180
|
+
if (isInternal(field) ||
|
|
181
|
+
isWriteOnly(field) ||
|
|
182
|
+
isServerOnly(field) ||
|
|
183
|
+
isRelationField(field)) {
|
|
184
|
+
continue;
|
|
185
|
+
}
|
|
186
|
+
const zodExpr = this._createOutputFieldZodExpression(field, field.type);
|
|
187
|
+
properties.push(ts.factory.createPropertyAssignment(ts.factory.createIdentifier(field.name), zodExpr));
|
|
188
|
+
}
|
|
189
|
+
return properties;
|
|
190
|
+
}
|
|
191
|
+
_createInputFieldProperties(definition, excludes = [], suffix = "Schema") {
|
|
192
|
+
const properties = [];
|
|
193
|
+
for (const field of definition.fields ?? []) {
|
|
194
|
+
if (excludes.includes(field.name)) {
|
|
195
|
+
continue;
|
|
196
|
+
}
|
|
197
|
+
const zodExpr = this._createInputFieldZodExpression(field, field.type, 0, suffix);
|
|
198
|
+
properties.push(ts.factory.createPropertyAssignment(ts.factory.createIdentifier(field.name), zodExpr));
|
|
199
|
+
}
|
|
200
|
+
return properties;
|
|
201
|
+
}
|
|
202
|
+
_createSchemaConstDeclaration(name, initializer, suffix = "Schema", exported = true) {
|
|
203
|
+
return ts.factory.createVariableStatement(exported ? [ts.factory.createModifier(ts.SyntaxKind.ExportKeyword)] : undefined, ts.factory.createVariableDeclarationList([
|
|
204
|
+
ts.factory.createVariableDeclaration(ts.factory.createIdentifier(`${name}${suffix}`), undefined, undefined, initializer),
|
|
205
|
+
], ts.NodeFlags.Const));
|
|
206
|
+
}
|
|
207
|
+
_getSelfReferenceFields(definition) {
|
|
208
|
+
const selfRefs = [];
|
|
209
|
+
for (const field of definition.fields ?? []) {
|
|
210
|
+
if (field.type.getTypeName() === definition.name) {
|
|
211
|
+
selfRefs.push(field);
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
return selfRefs;
|
|
215
|
+
}
|
|
216
|
+
_generateEnum(definition) {
|
|
217
|
+
if (!definition.values?.length) {
|
|
218
|
+
throw new TransformerPluginExecutionError(this.name, `Enum type ${definition.name} must have at least one value.`);
|
|
219
|
+
}
|
|
220
|
+
const args = definition.values.map((v) => ts.factory.createStringLiteral(v.name));
|
|
221
|
+
const initializer = this._zCall("enum", [ts.factory.createArrayLiteralExpression(args)]);
|
|
222
|
+
this.nodes.push(this._createSchemaConstDeclaration(definition.name, initializer));
|
|
223
|
+
}
|
|
224
|
+
_generateObject(definition) {
|
|
225
|
+
const properties = this._createObjectFieldProperties(definition);
|
|
226
|
+
const initializer = this._zCall("object", [
|
|
227
|
+
ts.factory.createObjectLiteralExpression(properties, true),
|
|
228
|
+
]);
|
|
229
|
+
this.nodes.push(this._createSchemaConstDeclaration(definition.name, initializer));
|
|
230
|
+
}
|
|
231
|
+
_generateInputObject(definition) {
|
|
232
|
+
const selfRefs = this._getSelfReferenceFields(definition);
|
|
233
|
+
if (selfRefs.length > 0) {
|
|
234
|
+
const properties = this._createInputFieldProperties(definition, selfRefs.map((f) => f.name));
|
|
235
|
+
const base = this._zCall("object", [
|
|
236
|
+
ts.factory.createObjectLiteralExpression(properties, true),
|
|
237
|
+
]);
|
|
238
|
+
const extension = InputObjectNode.create(definition.name, undefined, undefined, selfRefs);
|
|
239
|
+
const initializer = ts.factory.createCallExpression(ts.factory.createPropertyAccessExpression(ts.factory.createIdentifier(`${definition.name}Base`), ts.factory.createIdentifier("extend")), undefined, [
|
|
240
|
+
ts.factory.createObjectLiteralExpression(this._createInputFieldProperties(extension, undefined, "Base"), true),
|
|
241
|
+
]);
|
|
242
|
+
this.nodes.push(this._createSchemaConstDeclaration(definition.name, base, "Base", false), this._createSchemaConstDeclaration(definition.name, initializer));
|
|
243
|
+
return;
|
|
244
|
+
}
|
|
245
|
+
const properties = this._createInputFieldProperties(definition);
|
|
246
|
+
const initializer = this._zCall("object", [
|
|
247
|
+
ts.factory.createObjectLiteralExpression(properties, true),
|
|
248
|
+
]);
|
|
249
|
+
this.nodes.push(this._createSchemaConstDeclaration(definition.name, initializer));
|
|
250
|
+
}
|
|
251
|
+
_generateUnion(definition) {
|
|
252
|
+
if (!definition.types?.length) {
|
|
253
|
+
throw new TransformerPluginExecutionError(this.name, `Union type ${definition.name} must have at least one member type.`);
|
|
254
|
+
}
|
|
255
|
+
const memberRefs = definition.types.map((type) => ts.factory.createIdentifier(`${type.name}Schema`));
|
|
256
|
+
const initializer = this._zCall("union", [ts.factory.createArrayLiteralExpression(memberRefs)]);
|
|
257
|
+
this.nodes.push(this._createSchemaConstDeclaration(definition.name, initializer));
|
|
258
|
+
}
|
|
259
|
+
before() {
|
|
260
|
+
const headers = createFileHeaders();
|
|
261
|
+
this.nodes = [...headers];
|
|
262
|
+
// import * as z from "zod/v4";
|
|
263
|
+
this.nodes.push(ts.factory.createImportDeclaration(undefined, ts.factory.createImportClause(undefined, undefined, ts.factory.createNamespaceImport(ts.factory.createIdentifier("z"))), ts.factory.createStringLiteral("zod/v4"), undefined), ts.factory.createIdentifier("\n"));
|
|
264
|
+
}
|
|
265
|
+
match(definition) {
|
|
266
|
+
return (!isOperationNode(definition) &&
|
|
267
|
+
!isInternal(definition) &&
|
|
268
|
+
!isScalarNode(definition) &&
|
|
269
|
+
!isDirectiveDefinitionNode(definition));
|
|
270
|
+
}
|
|
271
|
+
generate(definition) {
|
|
272
|
+
if (isEnumNode(definition)) {
|
|
273
|
+
return this._generateEnum(definition);
|
|
274
|
+
}
|
|
275
|
+
if (isObjectNode(definition)) {
|
|
276
|
+
return this._generateObject(definition);
|
|
277
|
+
}
|
|
278
|
+
if (isInterfaceNode(definition)) {
|
|
279
|
+
return this._generateObject(definition);
|
|
280
|
+
}
|
|
281
|
+
if (isInputObjectNode(definition)) {
|
|
282
|
+
return this._generateInputObject(definition);
|
|
283
|
+
}
|
|
284
|
+
if (isUnionNode(definition)) {
|
|
285
|
+
return this._generateUnion(definition);
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
output() {
|
|
289
|
+
const content = this._getContent();
|
|
290
|
+
this.context.files.push({
|
|
291
|
+
type: "ts",
|
|
292
|
+
path: `zod/${this.options.fileName}`,
|
|
293
|
+
filename: this.options.fileName,
|
|
294
|
+
content,
|
|
295
|
+
});
|
|
296
|
+
return this.options.emitOutput ? { zodSchemas: content } : {};
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
export const zodSchemaGeneratorPlugin = createPluginFactory(ZodSchemaGeneratorPlugin);
|
|
300
|
+
//# sourceMappingURL=ZodSchemaGeneratorPlugin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ZodSchemaGeneratorPlugin.js","sourceRoot":"","sources":["../../../src/zod/ZodSchemaGeneratorPlugin/ZodSchemaGeneratorPlugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,YAAY,CAAC;AAC5B,OAAO,EAAE,mBAAmB,EAAuB,qB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AAI,eAAe,CAAC,UAAU,CAAC,EAAE,CAAC;YAChC,OAAO,IAAI,CAAC,eAAe,CAAC,UAAU,CAAC,CAAC;QAC1C,CAAC;QAED,IAAI,iBAAiB,CAAC,UAAU,CAAC,EAAE,CAAC;YAClC,OAAO,IAAI,CAAC,oBAAoB,CAAC,UAAU,CAAC,CAAC;QAC/C,CAAC;QAED,IAAI,WAAW,CAAC,UAAU,CAAC,EAAE,CAAC;YAC5B,OAAO,IAAI,CAAC,cAAc,CAAC,UAAU,CAAC,CAAC;QACzC,CAAC;IACH,CAAC;IAEM,MAAM;QACX,MAAM,OAAO,GAAG,IAAI,CAAC,WAAW,EAAE,CAAC;QAEnC,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC;YACtB,IAAI,EAAE,IAAI;YACV,IAAI,EAAE,OAAO,IAAI,CAAC,OAAO,CAAC,QAAQ,EAAE;YACpC,QAAQ,EAAE,IAAI,CAAC,OAAO,CAAC,QAAQ;YAC/B,OAAO;SACR,CAAC,CAAC;QAEH,OAAO,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC,EAAE,UAAU,EAAE,OAAO,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;IAChE,CAAC;CACF;AAED,MAAM,CAAC,MAAM,wBAAwB,GAAG,mBAAmB,CAAC,wBAAwB,CAAC,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { type BaseScalarName } from "../../base/ScalarsPlugin/ScalarsPlugin.utils.js";
|
|
2
|
+
export interface ZodSchemaGeneratorPluginOptions {
|
|
3
|
+
/**
|
|
4
|
+
* The output file name for the generated schemas.
|
|
5
|
+
* @default "validators.typegen.ts"
|
|
6
|
+
*/
|
|
7
|
+
fileName?: string;
|
|
8
|
+
/**
|
|
9
|
+
* Whether to include the generated schemas in the output object.
|
|
10
|
+
* @default false
|
|
11
|
+
*/
|
|
12
|
+
emitOutput?: boolean;
|
|
13
|
+
}
|
|
14
|
+
export declare const DEFAULT_OPTIONS: Required<ZodSchemaGeneratorPluginOptions>;
|
|
15
|
+
export declare const mergeOptions: (options?: ZodSchemaGeneratorPluginOptions) => Required<ZodSchemaGeneratorPluginOptions>;
|
|
16
|
+
export declare const CUSTOM_SCALAR_ZOD_MAP: Record<BaseScalarName, string>;
|
|
17
|
+
//# sourceMappingURL=ZodSchemaGeneratorPlugin.utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ZodSchemaGeneratorPlugin.utils.d.ts","sourceRoot":"","sources":["../../../src/zod/ZodSchemaGeneratorPlugin/ZodSchemaGeneratorPlugin.utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAc,KAAK,cAAc,EAAE,MAAM,iDAAiD,CAAC;AAElG,MAAM,WAAW,+BAA+B;IAC9C;;;OAGG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAElB;;;OAGG;IACH,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB;AAED,eAAO,MAAM,eAAe,EAAE,QAAQ,CAAC,+BAA+B,CAG5D,CAAC;AAEX,eAAO,MAAM,YAAY,GACvB,UAAU,+BAA+B,KACxC,QAAQ,CAAC,+BAA+B,CAK1C,CAAC;AAEF,eAAO,MAAM,qBAAqB,EAAE,MAAM,CAAC,cAAc,EAAE,MAAM,CAWhE,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { BaseScalar } from "../../base/ScalarsPlugin/ScalarsPlugin.utils.js";
|
|
2
|
+
export const DEFAULT_OPTIONS = {
|
|
3
|
+
fileName: "validators.typegen.ts",
|
|
4
|
+
emitOutput: false,
|
|
5
|
+
};
|
|
6
|
+
export const mergeOptions = (options) => {
|
|
7
|
+
return {
|
|
8
|
+
...DEFAULT_OPTIONS,
|
|
9
|
+
...options,
|
|
10
|
+
};
|
|
11
|
+
};
|
|
12
|
+
export const CUSTOM_SCALAR_ZOD_MAP = {
|
|
13
|
+
[BaseScalar.DATE_TIME]: "z.iso.datetime()",
|
|
14
|
+
[BaseScalar.DATE]: "z.iso.date()",
|
|
15
|
+
[BaseScalar.TIME]: "z.iso.time()",
|
|
16
|
+
[BaseScalar.TIMESTAMP]: "z.number()",
|
|
17
|
+
[BaseScalar.UUID]: "z.uuid()",
|
|
18
|
+
[BaseScalar.URL]: "z.url()",
|
|
19
|
+
[BaseScalar.EMAIL_ADDRESS]: "z.email()",
|
|
20
|
+
[BaseScalar.PHONE_NUMBER]: "z.e164()",
|
|
21
|
+
[BaseScalar.IP_ADDRESS]: "z.ip()",
|
|
22
|
+
[BaseScalar.JSON]: "z.record(z.string(), z.unknown())",
|
|
23
|
+
};
|
|
24
|
+
//# sourceMappingURL=ZodSchemaGeneratorPlugin.utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ZodSchemaGeneratorPlugin.utils.js","sourceRoot":"","sources":["../../../src/zod/ZodSchemaGeneratorPlugin/ZodSchemaGeneratorPlugin.utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAuB,MAAM,iDAAiD,CAAC;AAgBlG,MAAM,CAAC,MAAM,eAAe,GAA8C;IACxE,QAAQ,EAAE,uBAAuB;IACjC,UAAU,EAAE,KAAK;CACT,CAAC;AAEX,MAAM,CAAC,MAAM,YAAY,GAAG,CAC1B,OAAyC,EACE,EAAE;IAC7C,OAAO;QACL,GAAG,eAAe;QAClB,GAAG,OAAO;KACX,CAAC;AACJ,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,qBAAqB,GAAmC;IACnE,CAAC,UAAU,CAAC,SAAS,CAAC,EAAE,kBAAkB;IAC1C,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE,cAAc;IACjC,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE,cAAc;IACjC,CAAC,UAAU,CAAC,SAAS,CAAC,EAAE,YAAY;IACpC,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE,UAAU;IAC7B,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE,SAAS;IAC3B,CAAC,UAAU,CAAC,aAAa,CAAC,EAAE,WAAW;IACvC,CAAC,UAAU,CAAC,YAAY,CAAC,EAAE,UAAU;IACrC,CAAC,UAAU,CAAC,UAAU,CAAC,EAAE,QAAQ;IACjC,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE,mCAAmC;CACvD,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/zod/ZodSchemaGeneratorPlugin/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,wBAAwB,EACxB,wBAAwB,GACzB,MAAM,+BAA+B,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/zod/ZodSchemaGeneratorPlugin/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,wBAAwB,EACxB,wBAAwB,GACzB,MAAM,+BAA+B,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/zod/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,wBAAwB,EACxB,wBAAwB,GACzB,MAAM,wDAAwD,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/zod/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,wBAAwB,EACxB,wBAAwB,GACzB,MAAM,wDAAwD,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gqlbase/plugins",
|
|
3
3
|
"description": "Collection of plugins and presets for gqlbase, providing common transformations and utilities that can be used in GraphQL schema transformation processes.",
|
|
4
|
-
"version": "0.1.
|
|
4
|
+
"version": "0.1.4",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"type": "module",
|
|
7
7
|
"license": "MIT",
|
|
@@ -46,19 +46,10 @@
|
|
|
46
46
|
"test": "vitest run"
|
|
47
47
|
},
|
|
48
48
|
"dependencies": {
|
|
49
|
-
"@gqlbase/core": "^0.1.
|
|
50
|
-
"@gqlbase/shared": "^0.1.
|
|
51
|
-
},
|
|
52
|
-
"devDependencies": {
|
|
53
|
-
"@middy-appsync/graphql": "^0.1.1"
|
|
49
|
+
"@gqlbase/core": "^0.1.4",
|
|
50
|
+
"@gqlbase/shared": "^0.1.4"
|
|
54
51
|
},
|
|
55
52
|
"peerDependencies": {
|
|
56
|
-
"
|
|
57
|
-
"graphql": "^16.13.2"
|
|
58
|
-
},
|
|
59
|
-
"peerDependenciesMeta": {
|
|
60
|
-
"@middy-appsync/graphql": {
|
|
61
|
-
"optional": true
|
|
62
|
-
}
|
|
53
|
+
"typescript": "^5 || ^6"
|
|
63
54
|
}
|
|
64
55
|
}
|