express-zod-api 6.0.3 → 6.1.0-beta3

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/CHANGELOG.md CHANGED
@@ -2,6 +2,71 @@
2
2
 
3
3
  ## Version 6
4
4
 
5
+ ### v6.1.0-beta3
6
+
7
+ - Feature #403 improvements (API Client Generator):
8
+ - `ExpressZodAPIClient` now accepts a function parameter of `Implementation` type.
9
+ - Its parameter `path` now contains substitutions of path params.
10
+ - Path params are being substituted by `ExpressZodAPIClient.provide()`.
11
+ - Call signature remains.
12
+
13
+ ```typescript
14
+ // example frontend using the most simple Implementation based on fetch
15
+ import { ExpressZodAPIClient } from "./client.ts";
16
+
17
+ const client = new ExpressZodAPIClient(async (method, path, params) => {
18
+ const searchParams =
19
+ method === "get" ? `?${new URLSearchParams(params)}` : "";
20
+ const response = await fetch(`https://example.com${path}${searchParams}`, {
21
+ method,
22
+ body: method === "get" ? undefined : JSON.stringify(params),
23
+ });
24
+ return response.json();
25
+ });
26
+
27
+ client.provide("get", "/v1/user/retrieve", { id: "10" });
28
+ ```
29
+
30
+ ### v6.1.0-beta2
31
+
32
+ - Fixing bugs and taking into account path params for feature #403 (API Client Generator).
33
+
34
+ ### v6.1.0-beta1
35
+
36
+ - This is a beta release of a new feature for public testing.
37
+ - Feature #403: API Client Generator.
38
+ - A new way of informing the frontend about the I/O types of endpoints is proposed.
39
+ - The new approach offers automatic generation of a client based on routing to a typescript file.
40
+ - The generated client is flexibly configured on the frontend using a provider function that directly makes a
41
+ request to the endpoint using the libraries and methods of your choice.
42
+ - The client asserts the type request and response.
43
+ - More details coming soon.
44
+
45
+ ```typescript
46
+ // example client-generator.ts
47
+ import fs from "fs";
48
+ import { Client } from "express-zod-api";
49
+
50
+ fs.writeFileSync("./frontend/client.ts", new Client(routing).print(), "utf-8");
51
+ ```
52
+
53
+ ```typescript
54
+ // example frontend using the most simple provider based on fetch
55
+ import { ExpressZodAPIClient } from "./client.ts";
56
+
57
+ const client = new ExpressZodAPIClient(async (method, path, params) => {
58
+ const urlParams =
59
+ method === "get" ? new URLSearchParams(params).toString() : "";
60
+ const response = await fetch(`https://example.com${path}?${urlParams}`, {
61
+ method,
62
+ body: method === "get" ? undefined : JSON.stringify(params),
63
+ });
64
+ return response.json();
65
+ });
66
+
67
+ client.provide("get", "/v1/user/retrieve", { id: "10" });
68
+ ```
69
+
5
70
  ### v6.0.3
6
71
 
7
72
  - `zod` version is 3.14.4.
@@ -0,0 +1,24 @@
1
+ import ts from "typescript";
2
+ export declare const f: ts.NodeFactory;
3
+ export declare const exportModifier: ts.ModifierToken<ts.SyntaxKind.ExportKeyword>[];
4
+ export declare const publicReadonlyModifier: (ts.ModifierToken<ts.SyntaxKind.PublicKeyword> | ts.ModifierToken<ts.SyntaxKind.ReadonlyKeyword>)[];
5
+ export declare const protectedReadonlyModifier: (ts.ModifierToken<ts.SyntaxKind.ReadonlyKeyword> | ts.ModifierToken<ts.SyntaxKind.ProtectedKeyword>)[];
6
+ export declare const makeTemplate: (names: (ts.Identifier | string)[]) => ts.TemplateLiteralTypeNode;
7
+ export declare const parametricIndexNode: ts.TemplateLiteralTypeNode;
8
+ export declare const makeParam: (name: string, type?: ts.TypeNode | undefined, mod?: ts.Modifier[] | undefined) => ts.ParameterDeclaration;
9
+ export declare const makeParams: (params: Record<string, ts.TypeNode | undefined>, mod?: ts.Modifier[] | undefined) => ts.ParameterDeclaration[];
10
+ export declare const makeRecord: (key: ts.Identifier | ts.KeywordTypeSyntaxKind, value: ts.KeywordTypeSyntaxKind) => ts.ExpressionWithTypeArguments;
11
+ export declare const makeEmptyInitializingConstructor: (params: ts.ParameterDeclaration[]) => ts.ConstructorDeclaration;
12
+ export declare const makeQuotedProp: (name: string, ref: string) => ts.PropertySignature;
13
+ export declare const makeConst: (name: string, value: ts.Expression) => ts.VariableDeclarationList;
14
+ export declare const makePublicLiteralType: (name: string, literals: string[]) => ts.TypeAliasDeclaration;
15
+ export declare const makePublicType: (name: string, value: ts.TypeNode) => ts.TypeAliasDeclaration;
16
+ export declare const makePublicReadonlyProp: (name: string, type: ts.TypeNode, exp: ts.Expression) => ts.PropertyDeclaration;
17
+ export declare const makePublicClass: (name: string, constructor: ts.ConstructorDeclaration, props?: ts.PropertyDeclaration[]) => ts.ClassDeclaration;
18
+ export declare const makeIndexedPromise: (type: ts.Identifier, index: ts.TypeNode) => ts.TypeReferenceNode;
19
+ export declare const makeAnyPromise: () => ts.TypeReferenceNode;
20
+ export declare const makePublicExtendedInterface: (name: string, extender: ts.HeritageClause[], props: ts.PropertySignature[]) => ts.InterfaceDeclaration;
21
+ export declare const makeTypeParams: (params: Record<string, ts.Identifier>) => ts.TypeParameterDeclaration[];
22
+ export declare const makeImplementationCallFn: (params: string[], args: ts.Expression[]) => ts.ArrowFunction;
23
+ export declare const makeObjectKeysReducer: (obj: string, exp: ts.Expression, initial: ts.Expression) => ts.CallExpression;
24
+ export declare const cleanId: (path: string, method: string, suffix: string) => string;
@@ -0,0 +1,77 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.cleanId = exports.makeObjectKeysReducer = exports.makeImplementationCallFn = exports.makeTypeParams = exports.makePublicExtendedInterface = exports.makeAnyPromise = exports.makeIndexedPromise = exports.makePublicClass = exports.makePublicReadonlyProp = exports.makePublicType = exports.makePublicLiteralType = exports.makeConst = exports.makeQuotedProp = exports.makeEmptyInitializingConstructor = exports.makeRecord = exports.makeParams = exports.makeParam = exports.parametricIndexNode = exports.makeTemplate = exports.protectedReadonlyModifier = exports.publicReadonlyModifier = exports.exportModifier = exports.f = void 0;
7
+ const typescript_1 = __importDefault(require("typescript"));
8
+ exports.f = typescript_1.default.factory;
9
+ exports.exportModifier = [exports.f.createModifier(typescript_1.default.SyntaxKind.ExportKeyword)];
10
+ exports.publicReadonlyModifier = [
11
+ exports.f.createModifier(typescript_1.default.SyntaxKind.PublicKeyword),
12
+ exports.f.createModifier(typescript_1.default.SyntaxKind.ReadonlyKeyword),
13
+ ];
14
+ exports.protectedReadonlyModifier = [
15
+ exports.f.createModifier(typescript_1.default.SyntaxKind.ProtectedKeyword),
16
+ exports.f.createModifier(typescript_1.default.SyntaxKind.ReadonlyKeyword),
17
+ ];
18
+ const emptyPrefix = exports.f.createTemplateHead("");
19
+ const emptyEnding = exports.f.createTemplateTail("");
20
+ const spacingSuffix = exports.f.createTemplateMiddle(" ");
21
+ const makeTemplate = (names) => exports.f.createTemplateLiteralType(emptyPrefix, names.map((name, index) => exports.f.createTemplateLiteralTypeSpan(exports.f.createTypeReferenceNode(name), index === names.length - 1 ? emptyEnding : spacingSuffix)));
22
+ exports.makeTemplate = makeTemplate;
23
+ exports.parametricIndexNode = (0, exports.makeTemplate)(["M", "P"]);
24
+ const makeParam = (name, type, mod) => exports.f.createParameterDeclaration(undefined, mod, undefined, name, undefined, type);
25
+ exports.makeParam = makeParam;
26
+ const makeParams = (params, mod) => Object.keys(params).reduce((acc, name) => acc.concat((0, exports.makeParam)(name, params[name], mod)), []);
27
+ exports.makeParams = makeParams;
28
+ const makeRecord = (key, value) => exports.f.createExpressionWithTypeArguments(exports.f.createIdentifier("Record"), [
29
+ typeof key === "number"
30
+ ? exports.f.createKeywordTypeNode(key)
31
+ : exports.f.createTypeReferenceNode(key),
32
+ exports.f.createKeywordTypeNode(value),
33
+ ]);
34
+ exports.makeRecord = makeRecord;
35
+ const makeEmptyInitializingConstructor = (params) => exports.f.createConstructorDeclaration(undefined, undefined, params, exports.f.createBlock([]));
36
+ exports.makeEmptyInitializingConstructor = makeEmptyInitializingConstructor;
37
+ const makeQuotedProp = (name, ref) => exports.f.createPropertySignature(undefined, `"${name}"`, undefined, exports.f.createTypeReferenceNode(ref));
38
+ exports.makeQuotedProp = makeQuotedProp;
39
+ const makeConst = (name, value) => exports.f.createVariableDeclarationList([exports.f.createVariableDeclaration(name, undefined, undefined, value)], typescript_1.default.NodeFlags.Const);
40
+ exports.makeConst = makeConst;
41
+ const makePublicLiteralType = (name, literals) => exports.f.createTypeAliasDeclaration(undefined, exports.exportModifier, name, undefined, exports.f.createUnionTypeNode(literals.map((option) => exports.f.createLiteralTypeNode(exports.f.createStringLiteral(option)))));
42
+ exports.makePublicLiteralType = makePublicLiteralType;
43
+ const makePublicType = (name, value) => exports.f.createTypeAliasDeclaration(undefined, exports.exportModifier, name, undefined, value);
44
+ exports.makePublicType = makePublicType;
45
+ const makePublicReadonlyProp = (name, type, exp) => exports.f.createPropertyDeclaration(undefined, exports.publicReadonlyModifier, name, undefined, type, exp);
46
+ exports.makePublicReadonlyProp = makePublicReadonlyProp;
47
+ const makePublicClass = (name, constructor, props = []) => exports.f.createClassDeclaration(undefined, exports.exportModifier, name, undefined, undefined, [constructor, ...props]);
48
+ exports.makePublicClass = makePublicClass;
49
+ const makeIndexedPromise = (type, index) => exports.f.createTypeReferenceNode("Promise", [
50
+ exports.f.createIndexedAccessTypeNode(exports.f.createTypeReferenceNode(type), index),
51
+ ]);
52
+ exports.makeIndexedPromise = makeIndexedPromise;
53
+ const makeAnyPromise = () => exports.f.createTypeReferenceNode("Promise", [
54
+ exports.f.createKeywordTypeNode(typescript_1.default.SyntaxKind.AnyKeyword),
55
+ ]);
56
+ exports.makeAnyPromise = makeAnyPromise;
57
+ const makePublicExtendedInterface = (name, extender, props) => exports.f.createInterfaceDeclaration(undefined, exports.exportModifier, name, undefined, extender, props);
58
+ exports.makePublicExtendedInterface = makePublicExtendedInterface;
59
+ const makeTypeParams = (params) => Object.keys(params).reduce((acc, name) => acc.concat(exports.f.createTypeParameterDeclaration(name, exports.f.createTypeReferenceNode(params[name]))), []);
60
+ exports.makeTypeParams = makeTypeParams;
61
+ const makeImplementationCallFn = (params, args) => exports.f.createArrowFunction(undefined, undefined, params.map((key) => (0, exports.makeParam)(key)), undefined, undefined, exports.f.createCallExpression(exports.f.createPropertyAccessExpression(exports.f.createThis(), "implementation"), undefined, args));
62
+ exports.makeImplementationCallFn = makeImplementationCallFn;
63
+ const makeObjectKeysReducer = (obj, exp, initial) => exports.f.createCallExpression(exports.f.createPropertyAccessExpression(exports.f.createCallExpression(exports.f.createPropertyAccessExpression(exports.f.createIdentifier("Object"), "keys"), undefined, [exports.f.createIdentifier(obj)]), "reduce"), undefined, [
64
+ exports.f.createArrowFunction(undefined, undefined, (0, exports.makeParams)({ acc: undefined, key: undefined }), undefined, undefined, exp),
65
+ initial,
66
+ ]);
67
+ exports.makeObjectKeysReducer = makeObjectKeysReducer;
68
+ const cleanId = (path, method, suffix) => {
69
+ return [method]
70
+ .concat(path.split("/"))
71
+ .concat(suffix)
72
+ .map((entry) => entry.replace(/[^A-Z0-9]/i, ""))
73
+ .map((entry) => entry.slice(0, 1).toUpperCase() + entry.slice(1).toLowerCase())
74
+ .join("");
75
+ };
76
+ exports.cleanId = cleanId;
77
+ //# sourceMappingURL=client-helpers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client-helpers.js","sourceRoot":"","sources":["../src/client-helpers.ts"],"names":[],"mappings":";;;;;;AAAA,4DAA4B;AAEf,QAAA,CAAC,GAAG,oBAAE,CAAC,OAAO,CAAC;AAEf,QAAA,cAAc,GAAG,CAAC,SAAC,CAAC,cAAc,CAAC,oBAAE,CAAC,UAAU,CAAC,aAAa,CAAC,CAAC,CAAC;AAEjE,QAAA,sBAAsB,GAAG;IACpC,SAAC,CAAC,cAAc,CAAC,oBAAE,CAAC,UAAU,CAAC,aAAa,CAAC;IAC7C,SAAC,CAAC,cAAc,CAAC,oBAAE,CAAC,UAAU,CAAC,eAAe,CAAC;CAChD,CAAC;AAEW,QAAA,yBAAyB,GAAG;IACvC,SAAC,CAAC,cAAc,CAAC,oBAAE,CAAC,UAAU,CAAC,gBAAgB,CAAC;IAChD,SAAC,CAAC,cAAc,CAAC,oBAAE,CAAC,UAAU,CAAC,eAAe,CAAC;CAChD,CAAC;AAEF,MAAM,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AQ,CACT,EACD,SAAS,EACT;IACE,SAAC,CAAC,mBAAmB,CACnB,SAAS,EACT,SAAS,EACT,IAAA,kBAAU,EAAC,EAAE,GAAG,EAAE,SAAS,EAAE,GAAG,EAAE,SAAS,EAAE,CAAC,EAC9C,SAAS,EACT,SAAS,EACT,GAAG,CACJ;IACD,OAAO;CACR,CACF,CAAC;AA1BS,QAAA,qBAAqB,yBA0B9B;AAEG,MAAM,OAAO,GAAG,CAAC,IAAY,EAAE,MAAc,EAAE,MAAc,EAAE,EAAE;IACtE,OAAO,CAAC,MAAM,CAAC;SACZ,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;SACvB,MAAM,CAAC,MAAM,CAAC;SACd,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,YAAY,EAAE,EAAE,CAAC,CAAC;SAC/C,GAAG,CACF,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,WAAW,EAAE,GAAG,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,CAC1E;SACA,IAAI,CAAC,EAAE,CAAC,CAAC;AACd,CAAC,CAAC;AATW,QAAA,OAAO,WASlB"}
@@ -0,0 +1,15 @@
1
+ import ts from "typescript";
2
+ import { Routing } from "./routing";
3
+ interface Registry {
4
+ [METHOD_PATH: string]: Record<"in" | "out", string> & {
5
+ isJson: boolean;
6
+ };
7
+ }
8
+ export declare class Client {
9
+ protected agg: ts.Node[];
10
+ protected registry: Registry;
11
+ protected paths: string[];
12
+ constructor(routing: Routing);
13
+ print(printerOptions?: ts.PrinterOptions): string;
14
+ }
15
+ export {};
package/dist/client.js ADDED
@@ -0,0 +1,108 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.Client = void 0;
7
+ const typescript_1 = __importDefault(require("typescript"));
8
+ const zod_to_ts_1 = require("zod-to-ts");
9
+ const client_helpers_1 = require("./client-helpers");
10
+ const method_1 = require("./method");
11
+ const mime_1 = require("./mime");
12
+ const routing_1 = require("./routing");
13
+ class Client {
14
+ constructor(routing) {
15
+ this.agg = [];
16
+ this.registry = {};
17
+ this.paths = [];
18
+ (0, routing_1.routingCycle)({
19
+ routing,
20
+ endpointCb: (endpoint, path, method) => {
21
+ const inputId = (0, client_helpers_1.cleanId)(path, method, "input");
22
+ const responseId = (0, client_helpers_1.cleanId)(path, method, "response");
23
+ const input = (0, zod_to_ts_1.zodToTs)(endpoint.getInputSchema(), inputId, {
24
+ resolveNativeEnums: true,
25
+ });
26
+ const response = (0, zod_to_ts_1.zodToTs)(endpoint
27
+ .getPositiveResponseSchema()
28
+ .or(endpoint.getNegativeResponseSchema()), responseId, { resolveNativeEnums: true });
29
+ const inputAlias = (0, zod_to_ts_1.createTypeAlias)(input.node, inputId);
30
+ const responseAlias = (0, zod_to_ts_1.createTypeAlias)(response.node, responseId);
31
+ this.agg.push(...input.store.nativeEnums, ...response.store.nativeEnums);
32
+ this.agg.push(inputAlias);
33
+ this.agg.push(responseAlias);
34
+ if (method !== "options") {
35
+ this.paths.push(path);
36
+ this.registry[`${method} ${path}`] = {
37
+ in: inputId,
38
+ out: responseId,
39
+ isJson: endpoint.getPositiveMimeTypes().includes(mime_1.mimeJson),
40
+ };
41
+ }
42
+ },
43
+ });
44
+ const pathNode = (0, client_helpers_1.makePublicLiteralType)("Path", this.paths);
45
+ const methodNode = (0, client_helpers_1.makePublicLiteralType)("Method", method_1.methods);
46
+ const methodPathNode = (0, client_helpers_1.makePublicType)("MethodPath", (0, client_helpers_1.makeTemplate)([methodNode.name, pathNode.name]));
47
+ const extenderClause = [
48
+ client_helpers_1.f.createHeritageClause(typescript_1.default.SyntaxKind.ExtendsKeyword, [
49
+ (0, client_helpers_1.makeRecord)(methodPathNode.name, typescript_1.default.SyntaxKind.AnyKeyword),
50
+ ]),
51
+ ];
52
+ const inputNode = (0, client_helpers_1.makePublicExtendedInterface)("Input", extenderClause, Object.keys(this.registry).map((methodPath) => (0, client_helpers_1.makeQuotedProp)(methodPath, this.registry[methodPath].in)));
53
+ const responseNode = (0, client_helpers_1.makePublicExtendedInterface)("Response", extenderClause, Object.keys(this.registry).map((methodPath) => (0, client_helpers_1.makeQuotedProp)(methodPath, this.registry[methodPath].out)));
54
+ const jsonEndpointsNode = client_helpers_1.f.createVariableStatement(client_helpers_1.exportModifier, (0, client_helpers_1.makeConst)("jsonEndpoints", client_helpers_1.f.createObjectLiteralExpression(Object.keys(this.registry)
55
+ .filter((methodPath) => this.registry[methodPath].isJson)
56
+ .map((methodPath) => client_helpers_1.f.createPropertyAssignment(`"${methodPath}"`, client_helpers_1.f.createTrue())))));
57
+ const providerNode = (0, client_helpers_1.makePublicType)("Provider", client_helpers_1.f.createFunctionTypeNode((0, client_helpers_1.makeTypeParams)({ M: methodNode.name, P: pathNode.name }), (0, client_helpers_1.makeParams)({
58
+ method: client_helpers_1.f.createTypeReferenceNode("M"),
59
+ path: client_helpers_1.f.createTypeReferenceNode("P"),
60
+ params: client_helpers_1.f.createIndexedAccessTypeNode(client_helpers_1.f.createTypeReferenceNode(inputNode.name), client_helpers_1.parametricIndexNode),
61
+ }), (0, client_helpers_1.makeIndexedPromise)(responseNode.name, client_helpers_1.parametricIndexNode)));
62
+ const implementationNode = (0, client_helpers_1.makePublicType)("Implementation", client_helpers_1.f.createFunctionTypeNode(undefined, (0, client_helpers_1.makeParams)({
63
+ method: client_helpers_1.f.createTypeReferenceNode(methodNode.name),
64
+ path: client_helpers_1.f.createKeywordTypeNode(typescript_1.default.SyntaxKind.StringKeyword),
65
+ params: (0, client_helpers_1.makeRecord)(typescript_1.default.SyntaxKind.StringKeyword, typescript_1.default.SyntaxKind.AnyKeyword),
66
+ }), (0, client_helpers_1.makeAnyPromise)()));
67
+ const clientNode = (0, client_helpers_1.makePublicClass)("ExpressZodAPIClient", (0, client_helpers_1.makeEmptyInitializingConstructor)([
68
+ (0, client_helpers_1.makeParam)("implementation", client_helpers_1.f.createTypeReferenceNode(implementationNode.name), client_helpers_1.protectedReadonlyModifier),
69
+ ]), [
70
+ (0, client_helpers_1.makePublicReadonlyProp)("provide", client_helpers_1.f.createTypeReferenceNode(providerNode.name), (0, client_helpers_1.makeImplementationCallFn)(["method", "path", "params"], [
71
+ client_helpers_1.f.createIdentifier("method"),
72
+ (0, client_helpers_1.makeObjectKeysReducer)("params", client_helpers_1.f.createCallExpression(client_helpers_1.f.createPropertyAccessExpression(client_helpers_1.f.createIdentifier("acc"), "replace"), undefined, [
73
+ client_helpers_1.f.createTemplateExpression(client_helpers_1.f.createTemplateHead(":"), [
74
+ client_helpers_1.f.createTemplateSpan(client_helpers_1.f.createIdentifier("key"), client_helpers_1.f.createTemplateTail("")),
75
+ ]),
76
+ client_helpers_1.f.createElementAccessExpression(client_helpers_1.f.createIdentifier("params"), client_helpers_1.f.createIdentifier("key")),
77
+ ]), client_helpers_1.f.createIdentifier("path")),
78
+ client_helpers_1.f.createIdentifier("params"),
79
+ ])),
80
+ ]);
81
+ typescript_1.default.addSyntheticLeadingComment(clientNode, typescript_1.default.SyntaxKind.MultiLineCommentTrivia, "\n" +
82
+ "export const exampleImplementation: Implementation = async (\n" +
83
+ " method,\n" +
84
+ " path,\n" +
85
+ " params\n" +
86
+ ") => {\n" +
87
+ " const searchParams =\n" +
88
+ ' method === "get" ? `?${new URLSearchParams(params)}` : "";\n' +
89
+ " const response = await fetch(`https://example.com${path}${searchParams}`, {\n" +
90
+ " method,\n" +
91
+ ' body: method === "get" ? undefined : JSON.stringify(params),\n' +
92
+ " });\n" +
93
+ " if (`${method} ${path}` in jsonEndpoints) {\n" +
94
+ " return response.json();\n" +
95
+ " }\n" +
96
+ " return response.text();\n" +
97
+ "};\n" +
98
+ "\n" +
99
+ "const client = new ExpressZodAPIClient(exampleImplementation);\n" +
100
+ 'client.provide("get", "/v1/user/retrieve", { id: "10" });\n', true);
101
+ this.agg.push(pathNode, methodNode, methodPathNode, inputNode, responseNode, jsonEndpointsNode, providerNode, implementationNode, clientNode);
102
+ }
103
+ print(printerOptions) {
104
+ return this.agg.map((node) => (0, zod_to_ts_1.printNode)(node, printerOptions)).join("\n\n");
105
+ }
106
+ }
107
+ exports.Client = Client;
108
+ //# sourceMappingURL=client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":";;;;;;AAAA,4DAA4B;AAC5B,yCAAgE;AAChE,qDAuB0B;AAC1B,qCAAmC;AACnC,iCAAkC;AAClC,uCAAkD;AAMlD,MAAa,MAAM;IAKjB,YAAY,OAAgB;QAJlB,QAAG,GAAc,EAAE,CAAC;QACpB,aAAQ,GAAa,EAAE,CAAC;QACxB,UAAK,GAAa,EAAE,CAAC;QAG7B,IAAA,sBAAY,EAAC;YACX,OAAO;YACP,UAAU,EAAE,CAAC,QAAQ,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE;gBACrC,MAAM,OAAO,GAAG,IAAA,wBAAO,EAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;gBAC/C,MAAM,UAAU,GAAG,IAAA,wBAAO,EAAC,IAAI,EAAE,MAAM,EAAE,UAAU,CAAC,CAAC;gBACrD,MAAM,KAAK,GAAG,IAAA,mBAAO,EAAC,QAAQ,CAAC,cAAc,EAAE,EAAE,OAAO,EAAE;oBACxD,kBAAkB,EAAE,IAAI;iBACzB,CAAC,CAAC;gBACH,MAAM,QAAQ,GAAG,IAAA,mBAAO,EACtB,QAAQ;qBACL,yBAAyB,EAAE;qBAC3B,EAAE,CAAC,QAAQ,CAAC,yBAAyB,EAAE,CAAC,EAC3C,UAAU,EACV,EAAE,kBAAkB,EAAE,IAAI,EAAE,CAC7B,CAAC;gBACF,MAAM,UAAU,GAAG,IAAA,2BAAe,EAAC,K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AAA,qBAAS,EAAC,IAAI,EAAE,cAAc,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IAC9E,CAAC;CACF;AA7MD,wBA6MC"}
@@ -16,6 +16,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  exports.dateOut = exports.dateIn = exports.date = exports.upload = exports.file = void 0;
18
18
  const zod_1 = require("zod");
19
+ const zod_to_ts_1 = require("zod-to-ts");
19
20
  const date_in_schema_1 = require("./date-in-schema");
20
21
  const date_out_schema_1 = require("./date-out-schema");
21
22
  const file_schema_1 = require("./file-schema");
@@ -28,6 +29,8 @@ exports.upload = upload_schema_1.ZodUpload.create;
28
29
  * @deprecated Please use z.dateIn() or z.dateOut() within IO schemas
29
30
  * */
30
31
  exports.date = zod_1.ZodDate.create;
31
- exports.dateIn = date_in_schema_1.ZodDateIn.create;
32
- exports.dateOut = date_out_schema_1.ZodDateOut.create;
32
+ const dateIn = (...params) => (0, zod_to_ts_1.withGetType)(date_in_schema_1.ZodDateIn.create(...params), (ts) => ts.factory.createKeywordTypeNode(ts.SyntaxKind.StringKeyword));
33
+ exports.dateIn = dateIn;
34
+ const dateOut = (...params) => (0, zod_to_ts_1.withGetType)(date_out_schema_1.ZodDateOut.create(...params), (ts) => ts.factory.createKeywordTypeNode(ts.SyntaxKind.StringKeyword));
35
+ exports.dateOut = dateOut;
33
36
  //# sourceMappingURL=extend-zod.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"extend-zod.js","sourceRoot":"","sources":["../src/extend-zod.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,6BAA8B;AAC9B,qDAA6C;AAC7C,uDAA+C;AAC/C,+CAAwC;AACxC,mDAA4C;AAE5C,sCAAoB;AACP,QAAA,IAAI,GAAG,qBAAO,CAAC,MAAM,CAAC;AACtB,QAAA,MAAM,GAAG,yBAAS,CAAC,MAAM,CAAC;AAEvC;;;KAGK;AACQ,QAAA,IAAI,GAAG,aAAO,CAAC,MAAM,CAAC;AACtB,QAAA,MAAM,GAAG,0BAAS,CAAC,MAAM,CAAC;AAC1B,QAAA,OAAO,GAAG,4BAAU,CAAC,MAAM,CAAC"}
1
+ {"version":3,"file":"extend-zod.js","sourceRoot":"","sources":["../src/extend-zod.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,6BAA8B;AAC9B,yCAAwC;AACxC,qDAA6C;AAC7C,uDAA+C;AAC/C,+CAAwC;AACxC,mDAA4C;AAE5C,sCAAoB;AACP,QAAA,IAAI,GAAG,qBAAO,CAAC,MAAM,CAAC;AACtB,QAAA,MAAM,GAAG,yBAAS,CAAC,MAAM,CAAC;AAEvC;;;KAGK;AACQ,QAAA,IAAI,GAAG,aAAO,CAAC,MAAM,CAAC;AAC5B,MAAM,MAAM,GAAG,CAAC,GAAG,MAA2C,EAAE,EAAE,CACvE,IAAA,uBAAW,EAAC,0BAAS,CAAC,MAAM,CAAC,GAAG,MAAM,CAAC,EAAE,CAAC,EAAE,EAAE,EAAE,CAC9C,EAAE,CAAC,OAAO,CAAC,qBAAqB,CAAC,EAAE,CAAC,UAAU,CAAC,aAAa,CAAC,CAC9D,CAAC;AAHS,QAAA,MAAM,UAGf;AACG,MAAM,OAAO,GAAG,CAAC,GAAG,MAA4C,EAAE,EAAE,CACzE,IAAA,uBAAW,EAAC,4BAAU,CAAC,MAAM,CAAC,GAAG,MAAM,CAAC,EAAE,CAAC,EAAE,EAAE,EAAE,CAC/C,EAAE,CAAC,OAAO,CAAC,qBAAqB,CAAC,EAAE,CAAC,UAAU,CAAC,aAAa,CAAC,CAC9D,CAAC;AAHS,QAAA,OAAO,WAGhB"}
package/dist/index.d.ts CHANGED
@@ -15,6 +15,7 @@ export { OpenAPI } from "./open-api";
15
15
  export { OpenAPIError, DependsOnMethodError, RoutingError } from "./errors";
16
16
  export { withMeta } from "./metadata";
17
17
  export { testEndpoint } from "./mock";
18
+ export { Client } from "./client";
18
19
  import * as z from "./extend-zod";
19
20
  import createHttpError from "http-errors";
20
21
  export { createHttpError, z };
package/dist/index.js CHANGED
@@ -26,7 +26,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
26
26
  return (mod && mod.__esModule) ? mod : { "default": mod };
27
27
  };
28
28
  Object.defineProperty(exports, "__esModule", { value: true });
29
- exports.z = exports.createHttpError = exports.testEndpoint = exports.withMeta = exports.RoutingError = exports.DependsOnMethodError = exports.OpenAPIError = exports.OpenAPI = exports.attachRouting = exports.createServer = exports.ServeStatic = exports.DependsOnMethod = exports.defaultResultHandler = exports.createResultHandler = exports.createMiddleware = exports.createLogger = exports.createApiResponse = exports.markOutput = exports.defaultEndpointsFactory = exports.EndpointsFactory = exports.AbstractEndpoint = exports.createConfig = void 0;
29
+ exports.z = exports.createHttpError = exports.Client = exports.testEndpoint = exports.withMeta = exports.RoutingError = exports.DependsOnMethodError = exports.OpenAPIError = exports.OpenAPI = exports.attachRouting = exports.createServer = exports.ServeStatic = exports.DependsOnMethod = exports.defaultResultHandler = exports.createResultHandler = exports.createMiddleware = exports.createLogger = exports.createApiResponse = exports.markOutput = exports.defaultEndpointsFactory = exports.EndpointsFactory = exports.AbstractEndpoint = exports.createConfig = void 0;
30
30
  var config_type_1 = require("./config-type");
31
31
  Object.defineProperty(exports, "createConfig", { enumerable: true, get: function () { return config_type_1.createConfig; } });
32
32
  var endpoint_1 = require("./endpoint");
@@ -62,6 +62,8 @@ var metadata_1 = require("./metadata");
62
62
  Object.defineProperty(exports, "withMeta", { enumerable: true, get: function () { return metadata_1.withMeta; } });
63
63
  var mock_1 = require("./mock");
64
64
  Object.defineProperty(exports, "testEndpoint", { enumerable: true, get: function () { return mock_1.testEndpoint; } });
65
+ var client_1 = require("./client");
66
+ Object.defineProperty(exports, "Client", { enumerable: true, get: function () { return client_1.Client; } });
65
67
  const z = __importStar(require("./extend-zod"));
66
68
  exports.z = z;
67
69
  const http_errors_1 = __importDefault(require("http-errors"));
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,6CAA2D;AAAlD,2GAAA,YAAY,OAAA;AACrB,uCAKoB;AAJlB,4GAAA,gBAAgB,OAAA;AAMlB,yDAAgF;AAAvE,qHAAA,gBAAgB,OAAA;AAAE,4HAAA,uBAAuB,OAAA;AAClD,mDAAoE;AAArC,4GAAA,UAAU,OAAA;AACzC,+CAAmD;AAA1C,iHAAA,iBAAiB,OAAA;AAC1B,mCAAwC;AAA/B,sGAAA,YAAY,OAAA;AACrB,2CAAgD;AAAvC,8GAAA,gBAAgB,OAAA;AACzB,mDAA6E;AAApE,qHAAA,mBAAmB,OAAA;AAAE,sHAAA,oBAAoB,OAAA;AAClD,yDAAsD;AAA7C,oHAAA,eAAe,OAAA;AACxB,+CAA6C;AAApC,2GAAA,WAAW,OAAA;AAEpB,mCAAuD;AAA9C,sGAAA,YAAY,OAAA;AAAE,uGAAA,aAAa,OAAA;AACpC,uCAAqC;AAA5B,mGAAA,OAAO,OAAA;AAChB,mCAA4E;AAAnE,sGAAA,YAAY,OAAA;AAAE,8GAAA,oBAAoB,OAAA;AAAE,sGAAA,YAAY,OAAA;AACzD,uCAAsC;AAA7B,oGAAA,QAAQ,OAAA;AACjB,+BAAsC;AAA7B,oGAAA,YAAY,OAAA;AAErB,gDAAkC;AAGR,cAAC;AAF3B,8DAA0C;AAEjC,0BAFF,qBAAe,CAEE"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,6CAA2D;AAAlD,2GAAA,YAAY,OAAA;AACrB,uCAKoB;AAJlB,4GAAA,gBAAgB,OAAA;AAMlB,yDAAgF;AAAvE,qHAAA,gBAAgB,OAAA;AAAE,4HAAA,uBAAuB,OAAA;AAClD,mDAAoE;AAArC,4GAAA,UAAU,OAAA;AACzC,+CAAmD;AAA1C,iHAAA,iBAAiB,OAAA;AAC1B,mCAAwC;AAA/B,sGAAA,YAAY,OAAA;AACrB,2CAAgD;AAAvC,8GAAA,gBAAgB,OAAA;AACzB,mDAA6E;AAApE,qHAAA,mBAAmB,OAAA;AAAE,sHAAA,oBAAoB,OAAA;AAClD,yDAAsD;AAA7C,oHAAA,eAAe,OAAA;AACxB,+CAA6C;AAApC,2GAAA,WAAW,OAAA;AAEpB,mCAAuD;AAA9C,sGAAA,YAAY,OAAA;AAAE,uGAAA,aAAa,OAAA;AACpC,uCAAqC;AAA5B,mGAAA,OAAO,OAAA;AAChB,mCAA4E;AAAnE,sGAAA,YAAY,OAAA;AAAE,8GAAA,oBAAoB,OAAA;AAAE,sGAAA,YAAY,OAAA;AACzD,uCAAsC;AAA7B,oGAAA,QAAQ,OAAA;AACjB,+BAAsC;AAA7B,oGAAA,YAAY,OAAA;AACrB,mCAAkC;AAAzB,gGAAA,MAAM,OAAA;AAEf,gDAAkC;AAGR,cAAC;AAF3B,8DAA0C;AAEjC,0BAFF,qBAAe,CAEE"}
package/dist/method.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  export declare type Method = "get" | "post" | "put" | "delete" | "patch";
2
+ export declare const methods: Method[];
2
3
  export declare type AuxMethod = "options";
3
4
  export declare type MethodsDefinition<M extends Method> = {
4
5
  methods: M[];
package/dist/method.js CHANGED
@@ -1,3 +1,5 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.methods = void 0;
4
+ exports.methods = ["get", "post", "put", "delete", "patch"];
3
5
  //# sourceMappingURL=method.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"method.js","sourceRoot":"","sources":["../src/method.ts"],"names":[],"mappings":""}
1
+ {"version":3,"file":"method.js","sourceRoot":"","sources":["../src/method.ts"],"names":[],"mappings":";;;AACa,QAAA,OAAO,GAAa,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,QAAQ,EAAE,OAAO,CAAC,CAAC"}
@@ -0,0 +1,53 @@
1
+ import ts from "typescript";
2
+ export const f = ts.factory;
3
+ export const exportModifier = [f.createModifier(ts.SyntaxKind.ExportKeyword)];
4
+ export const publicReadonlyModifier = [
5
+ f.createModifier(ts.SyntaxKind.PublicKeyword),
6
+ f.createModifier(ts.SyntaxKind.ReadonlyKeyword),
7
+ ];
8
+ export const protectedReadonlyModifier = [
9
+ f.createModifier(ts.SyntaxKind.ProtectedKeyword),
10
+ f.createModifier(ts.SyntaxKind.ReadonlyKeyword),
11
+ ];
12
+ const emptyPrefix = f.createTemplateHead("");
13
+ const emptyEnding = f.createTemplateTail("");
14
+ const spacingSuffix = f.createTemplateMiddle(" ");
15
+ export const makeTemplate = (names) => f.createTemplateLiteralType(emptyPrefix, names.map((name, index) => f.createTemplateLiteralTypeSpan(f.createTypeReferenceNode(name), index === names.length - 1 ? emptyEnding : spacingSuffix)));
16
+ export const parametricIndexNode = makeTemplate(["M", "P"]);
17
+ export const makeParam = (name, type, mod) => f.createParameterDeclaration(undefined, mod, undefined, name, undefined, type);
18
+ export const makeParams = (params, mod) => Object.keys(params).reduce((acc, name) => acc.concat(makeParam(name, params[name], mod)), []);
19
+ export const makeRecord = (key, value) => f.createExpressionWithTypeArguments(f.createIdentifier("Record"), [
20
+ typeof key === "number"
21
+ ? f.createKeywordTypeNode(key)
22
+ : f.createTypeReferenceNode(key),
23
+ f.createKeywordTypeNode(value),
24
+ ]);
25
+ export const makeEmptyInitializingConstructor = (params) => f.createConstructorDeclaration(undefined, undefined, params, f.createBlock([]));
26
+ export const makeQuotedProp = (name, ref) => f.createPropertySignature(undefined, `"${name}"`, undefined, f.createTypeReferenceNode(ref));
27
+ export const makeConst = (name, value) => f.createVariableDeclarationList([f.createVariableDeclaration(name, undefined, undefined, value)], ts.NodeFlags.Const);
28
+ export const makePublicLiteralType = (name, literals) => f.createTypeAliasDeclaration(undefined, exportModifier, name, undefined, f.createUnionTypeNode(literals.map((option) => f.createLiteralTypeNode(f.createStringLiteral(option)))));
29
+ export const makePublicType = (name, value) => f.createTypeAliasDeclaration(undefined, exportModifier, name, undefined, value);
30
+ export const makePublicReadonlyProp = (name, type, exp) => f.createPropertyDeclaration(undefined, publicReadonlyModifier, name, undefined, type, exp);
31
+ export const makePublicClass = (name, constructor, props = []) => f.createClassDeclaration(undefined, exportModifier, name, undefined, undefined, [constructor, ...props]);
32
+ export const makeIndexedPromise = (type, index) => f.createTypeReferenceNode("Promise", [
33
+ f.createIndexedAccessTypeNode(f.createTypeReferenceNode(type), index),
34
+ ]);
35
+ export const makeAnyPromise = () => f.createTypeReferenceNode("Promise", [
36
+ f.createKeywordTypeNode(ts.SyntaxKind.AnyKeyword),
37
+ ]);
38
+ export const makePublicExtendedInterface = (name, extender, props) => f.createInterfaceDeclaration(undefined, exportModifier, name, undefined, extender, props);
39
+ export const makeTypeParams = (params) => Object.keys(params).reduce((acc, name) => acc.concat(f.createTypeParameterDeclaration(name, f.createTypeReferenceNode(params[name]))), []);
40
+ export const makeImplementationCallFn = (params, args) => f.createArrowFunction(undefined, undefined, params.map((key) => makeParam(key)), undefined, undefined, f.createCallExpression(f.createPropertyAccessExpression(f.createThis(), "implementation"), undefined, args));
41
+ export const makeObjectKeysReducer = (obj, exp, initial) => f.createCallExpression(f.createPropertyAccessExpression(f.createCallExpression(f.createPropertyAccessExpression(f.createIdentifier("Object"), "keys"), undefined, [f.createIdentifier(obj)]), "reduce"), undefined, [
42
+ f.createArrowFunction(undefined, undefined, makeParams({ acc: undefined, key: undefined }), undefined, undefined, exp),
43
+ initial,
44
+ ]);
45
+ export const cleanId = (path, method, suffix) => {
46
+ return [method]
47
+ .concat(path.split("/"))
48
+ .concat(suffix)
49
+ .map((entry) => entry.replace(/[^A-Z0-9]/i, ""))
50
+ .map((entry) => entry.slice(0, 1).toUpperCase() + entry.slice(1).toLowerCase())
51
+ .join("");
52
+ };
53
+ //# sourceMappingURL=client-helpers.js.map
@@ -0,0 +1 @@
1
+ {"version":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+ import { createTypeAlias, printNode, zodToTs } from "zod-to-ts";
3
+ import { cleanId, exportModifier, f, makeAnyPromise, makeConst, makeEmptyInitializingConstructor, makeImplementationCallFn, makeIndexedPromise, makeObjectKeysReducer, makeParam, makeParams, makePublicClass, makePublicExtendedInterface, makePublicLiteralType, makePublicReadonlyProp, makePublicType, makeQuotedProp, makeRecord, makeTemplate, makeTypeParams, parametricIndexNode, protectedReadonlyModifier, } from "./client-helpers.js";
4
+ import { methods } from "./method.js";
5
+ import { mimeJson } from "./mime.js";
6
+ import { routingCycle } from "./routing.js";
7
+ export class Client {
8
+ constructor(routing) {
9
+ this.agg = [];
10
+ this.registry = {};
11
+ this.paths = [];
12
+ routingCycle({
13
+ routing,
14
+ endpointCb: (endpoint, path, method) => {
15
+ const inputId = cleanId(path, method, "input");
16
+ const responseId = cleanId(path, method, "response");
17
+ const input = zodToTs(endpoint.getInputSchema(), inputId, {
18
+ resolveNativeEnums: true,
19
+ });
20
+ const response = zodToTs(endpoint
21
+ .getPositiveResponseSchema()
22
+ .or(endpoint.getNegativeResponseSchema()), responseId, { resolveNativeEnums: true });
23
+ const inputAlias = createTypeAlias(input.node, inputId);
24
+ const responseAlias = createTypeAlias(response.node, responseId);
25
+ this.agg.push(...input.store.nativeEnums, ...response.store.nativeEnums);
26
+ this.agg.push(inputAlias);
27
+ this.agg.push(responseAlias);
28
+ if (method !== "options") {
29
+ this.paths.push(path);
30
+ this.registry[`${method} ${path}`] = {
31
+ in: inputId,
32
+ out: responseId,
33
+ isJson: endpoint.getPositiveMimeTypes().includes(mimeJson),
34
+ };
35
+ }
36
+ },
37
+ });
38
+ const pathNode = makePublicLiteralType("Path", this.paths);
39
+ const methodNode = makePublicLiteralType("Method", methods);
40
+ const methodPathNode = makePublicType("MethodPath", makeTemplate([methodNode.name, pathNode.name]));
41
+ const extenderClause = [
42
+ f.createHeritageClause(ts.SyntaxKind.ExtendsKeyword, [
43
+ makeRecord(methodPathNode.name, ts.SyntaxKind.AnyKeyword),
44
+ ]),
45
+ ];
46
+ const inputNode = makePublicExtendedInterface("Input", extenderClause, Object.keys(this.registry).map((methodPath) => makeQuotedProp(methodPath, this.registry[methodPath].in)));
47
+ const responseNode = makePublicExtendedInterface("Response", extenderClause, Object.keys(this.registry).map((methodPath) => makeQuotedProp(methodPath, this.registry[methodPath].out)));
48
+ const jsonEndpointsNode = f.createVariableStatement(exportModifier, makeConst("jsonEndpoints", f.createObjectLiteralExpression(Object.keys(this.registry)
49
+ .filter((methodPath) => this.registry[methodPath].isJson)
50
+ .map((methodPath) => f.createPropertyAssignment(`"${methodPath}"`, f.createTrue())))));
51
+ const providerNode = makePublicType("Provider", f.createFunctionTypeNode(makeTypeParams({ M: methodNode.name, P: pathNode.name }), makeParams({
52
+ method: f.createTypeReferenceNode("M"),
53
+ path: f.createTypeReferenceNode("P"),
54
+ params: f.createIndexedAccessTypeNode(f.createTypeReferenceNode(inputNode.name), parametricIndexNode),
55
+ }), makeIndexedPromise(responseNode.name, parametricIndexNode)));
56
+ const implementationNode = makePublicType("Implementation", f.createFunctionTypeNode(undefined, makeParams({
57
+ method: f.createTypeReferenceNode(methodNode.name),
58
+ path: f.createKeywordTypeNode(ts.SyntaxKind.StringKeyword),
59
+ params: makeRecord(ts.SyntaxKind.StringKeyword, ts.SyntaxKind.AnyKeyword),
60
+ }), makeAnyPromise()));
61
+ const clientNode = makePublicClass("ExpressZodAPIClient", makeEmptyInitializingConstructor([
62
+ makeParam("implementation", f.createTypeReferenceNode(implementationNode.name), protectedReadonlyModifier),
63
+ ]), [
64
+ makePublicReadonlyProp("provide", f.createTypeReferenceNode(providerNode.name), makeImplementationCallFn(["method", "path", "params"], [
65
+ f.createIdentifier("method"),
66
+ makeObjectKeysReducer("params", f.createCallExpression(f.createPropertyAccessExpression(f.createIdentifier("acc"), "replace"), undefined, [
67
+ f.createTemplateExpression(f.createTemplateHead(":"), [
68
+ f.createTemplateSpan(f.createIdentifier("key"), f.createTemplateTail("")),
69
+ ]),
70
+ f.createElementAccessExpression(f.createIdentifier("params"), f.createIdentifier("key")),
71
+ ]), f.createIdentifier("path")),
72
+ f.createIdentifier("params"),
73
+ ])),
74
+ ]);
75
+ ts.addSyntheticLeadingComment(clientNode, ts.SyntaxKind.MultiLineCommentTrivia, "\n" +
76
+ "export const exampleImplementation: Implementation = async (\n" +
77
+ " method,\n" +
78
+ " path,\n" +
79
+ " params\n" +
80
+ ") => {\n" +
81
+ " const searchParams =\n" +
82
+ ' method === "get" ? `?${new URLSearchParams(params)}` : "";\n' +
83
+ " const response = await fetch(`https://example.com${path}${searchParams}`, {\n" +
84
+ " method,\n" +
85
+ ' body: method === "get" ? undefined : JSON.stringify(params),\n' +
86
+ " });\n" +
87
+ " if (`${method} ${path}` in jsonEndpoints) {\n" +
88
+ " return response.json();\n" +
89
+ " }\n" +
90
+ " return response.text();\n" +
91
+ "};\n" +
92
+ "\n" +
93
+ "const client = new ExpressZodAPIClient(exampleImplementation);\n" +
94
+ 'client.provide("get", "/v1/user/retrieve", { id: "10" });\n', true);
95
+ this.agg.push(pathNode, methodNode, methodPathNode, inputNode, responseNode, jsonEndpointsNode, providerNode, implementationNode, clientNode);
96
+ }
97
+ print(printerOptions) {
98
+ return this.agg.map((node) => printNode(node, printerOptions)).join("\n\n");
99
+ }
100
+ }
101
+ //# sourceMappingURL=client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,YAAY,CAAC;AAC5B,OAAO,EAAE,eAAe,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAChE,OAAO,EACL,OAAO,EACP,cAAc,EACd,CAAC,EACD,cAAc,EACd,SAAS,EACT,gCAAgC,EAChC,wBAAwB,EACxB,kBAAkB,EAClB,qBAAqB,EACrB,SAAS,EACT,UAAU,EACV,eAAe,EACf,2BAA2B,EAC3B,qBAAqB,EACrB,sBAAsB,EACtB,cAAc,EACd,cAA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CACF,EACD,CAAC,CAAC,gBAAgB,CAAC,MAAM,CAAC,CAC3B;gBACD,CAAC,CAAC,gBAAgB,CAAC,QAAQ,CAAC;aAC7B,CACF,CACF;SACF,CACF,CAAC;QAEF,EAAE,CAAC,0BAA0B,CAC3B,UAAU,EACV,EAAE,CAAC,UAAU,CAAC,sBAAsB,EACpC,IAAI;YACF,gEAAgE;YAChE,aAAa;YACb,WAAW;YACX,YAAY;YACZ,UAAU;YACV,0BAA0B;YAC1B,kEAAkE;YAClE,iFAAiF;YACjF,eAAe;YACf,oEAAoE;YACpE,SAAS;YACT,iDAAiD;YACjD,+BAA+B;YAC/B,OAAO;YACP,6BAA6B;YAC7B,MAAM;YACN,IAAI;YACJ,kEAAkE;YAClE,6DAA6D,EAC/D,IAAI,CACL,CAAC;QAEF,IAAI,CAAC,GAAG,CAAC,IAAI,CACX,QAAQ,EACR,UAAU,EACV,cAAc,EACd,SAAS,EACT,YAAY,EACZ,iBAAiB,EACjB,YAAY,EACZ,kBAAkB,EAClB,UAAU,CACX,CAAC;IACJ,CAAC;IAEM,KAAK,CAAC,cAAkC;QAC7C,OAAO,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,SAAS,CAAC,IAAI,EAAE,cAAc,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IAC9E,CAAC;CACF"}
@@ -1,4 +1,5 @@
1
1
  import { ZodDate } from "zod";
2
+ import { withGetType } from "zod-to-ts";
2
3
  import { ZodDateIn } from "./date-in-schema.js";
3
4
  import { ZodDateOut } from "./date-out-schema.js";
4
5
  import { ZodFile } from "./file-schema.js";
@@ -11,6 +12,6 @@ export const upload = ZodUpload.create;
11
12
  * @deprecated Please use z.dateIn() or z.dateOut() within IO schemas
12
13
  * */
13
14
  export const date = ZodDate.create;
14
- export const dateIn = ZodDateIn.create;
15
- export const dateOut = ZodDateOut.create;
15
+ export const dateIn = (...params) => withGetType(ZodDateIn.create(...params), (ts) => ts.factory.createKeywordTypeNode(ts.SyntaxKind.StringKeyword));
16
+ export const dateOut = (...params) => withGetType(ZodDateOut.create(...params), (ts) => ts.factory.createKeywordTypeNode(ts.SyntaxKind.StringKeyword));
16
17
  //# sourceMappingURL=extend-zod.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"extend-zod.js","sourceRoot":"","sources":["../src/extend-zod.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,KAAK,CAAC;AAC9B,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC7C,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAC/C,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AACxC,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAE5C,cAAc,KAAK,CAAC;AACpB,MAAM,CAAC,MAAM,IAAI,GAAG,OAAO,CAAC,MAAM,CAAC;AACnC,MAAM,CAAC,MAAM,MAAM,GAAG,SAAS,CAAC,MAAM,CAAC;AAEvC;;;KAGK;AACL,MAAM,CAAC,MAAM,IAAI,GAAG,OAAO,CAAC,MAAM,CAAC;AACnC,MAAM,CAAC,MAAM,MAAM,GAAG,SAAS,CAAC,MAAM,CAAC;AACvC,MAAM,CAAC,MAAM,OAAO,GAAG,UAAU,CAAC,MAAM,CAAC"}
1
+ {"version":3,"file":"extend-zod.js","sourceRoot":"","sources":["../src/extend-zod.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,KAAK,CAAC;AAC9B,OAAO,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AACxC,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC7C,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAC/C,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AACxC,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAE5C,cAAc,KAAK,CAAC;AACpB,MAAM,CAAC,MAAM,IAAI,GAAG,OAAO,CAAC,MAAM,CAAC;AACnC,MAAM,CAAC,MAAM,MAAM,GAAG,SAAS,CAAC,MAAM,CAAC;AAEvC;;;KAGK;AACL,MAAM,CAAC,MAAM,IAAI,GAAG,OAAO,CAAC,MAAM,CAAC;AACnC,MAAM,CAAC,MAAM,MAAM,GAAG,CAAC,GAAG,MAA2C,EAAE,EAAE,CACvE,WAAW,CAAC,SAAS,CAAC,MAAM,CAAC,GAAG,MAAM,CAAC,EAAE,CAAC,EAAE,EAAE,EAAE,CAC9C,EAAE,CAAC,OAAO,CAAC,qBAAqB,CAAC,EAAE,CAAC,UAAU,CAAC,aAAa,CAAC,CAC9D,CAAC;AACJ,MAAM,CAAC,MAAM,OAAO,GAAG,CAAC,GAAG,MAA4C,EAAE,EAAE,CACzE,WAAW,CAAC,UAAU,CAAC,MAAM,CAAC,GAAG,MAAM,CAAC,EAAE,CAAC,EAAE,EAAE,EAAE,CAC/C,EAAE,CAAC,OAAO,CAAC,qBAAqB,CAAC,EAAE,CAAC,UAAU,CAAC,aAAa,CAAC,CAC9D,CAAC"}
package/dist-esm/index.js CHANGED
@@ -13,6 +13,7 @@ export { OpenAPI } from "./open-api.js";
13
13
  export { OpenAPIError, DependsOnMethodError, RoutingError } from "./errors.js";
14
14
  export { withMeta } from "./metadata.js";
15
15
  export { testEndpoint } from "./mock.js";
16
+ export { Client } from "./client.js";
16
17
  import * as z from "./extend-zod.js";
17
18
  import createHttpError from "http-errors";
18
19
  export { createHttpError, z };
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAgB,MAAM,eAAe,CAAC;AAC3D,OAAO,EACL,gBAAgB,GAIjB,MAAM,YAAY,CAAC;AAEpB,OAAO,EAAE,gBAAgB,EAAE,uBAAuB,EAAE,MAAM,qBAAqB,CAAC;AAChF,OAAO,EAAwB,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AE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AAC7E,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AACtD,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAE7C,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACvD,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AACrC,OAAO,EAAE,YAAY,EAAE,oBAAoB,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAC5E,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AACtC,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAElC,OAAO,KAAK,CAAC,MAAM,cAAc,CAAC;AAClC,OAAO,eAAe,MAAM,aAAa,CAAC;AAE1C,OAAO,EAAE,eAAe,EAAE,CAAC,EAAE,CAAC"}
@@ -1,2 +1,2 @@
1
- export {};
1
+ export const methods = ["get", "post", "put", "delete", "patch"];
2
2
  //# sourceMappingURL=method.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"method.js","sourceRoot":"","sources":["../src/method.ts"],"names":[],"mappings":""}
1
+ {"version":3,"file":"method.js","sourceRoot":"","sources":["../src/method.ts"],"names":[],"mappings":"AACA,MAAM,CAAC,MAAM,OAAO,GAAa,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,QAAQ,EAAE,OAAO,CAAC,CAAC"}
@@ -1 +1 @@
1
- {"type":"module","version":"6.0.3"}
1
+ {"type":"module","version":"6.1.0-beta3"}
package/package.json CHANGED
@@ -1,15 +1,16 @@
1
1
  {
2
2
  "name": "express-zod-api",
3
- "version": "6.0.3",
3
+ "version": "6.1.0-beta3",
4
4
  "description": "A Typescript library to help you get an API server up and running with I/O schema validation and custom middlewares in minutes.",
5
5
  "license": "MIT",
6
6
  "scripts": {
7
7
  "start": "ts-node example/index.ts",
8
- "build": "yarn build:cleanup && yarn build:compile && yarn build:esm && yarn build:swagger && yarn build:license",
9
- "build:cleanup": "rm -rf ./dist ./dist-esm example/example.swagger.yaml ./LICENSE",
8
+ "build": "yarn build:cleanup && yarn build:compile && yarn build:esm && yarn build:swagger && yarn build:client && yarn build:license",
9
+ "build:cleanup": "rm -rf ./dist ./dist-esm example/example.swagger.yaml example/example.client.ts ./LICENSE",
10
10
  "build:compile": "tsc --build tsconfig.build.json",
11
11
  "build:esm": "tsc --build tsconfig.esm.json && ts-node tools/esm-package.ts && ts-node tools/esm-extensions.ts",
12
12
  "build:swagger": "ts-node example/generate-open-api-schema.ts > example/example.swagger.yaml",
13
+ "build:client": "ts-node example/generate-client.ts > example/example.client.ts && yarn prettier example/example.client.ts --write",
13
14
  "build:license": "ts-node tools/license.ts > ./LICENSE",
14
15
  "build:intTest": "ts-node tools/integration-test.ts && yarn install --cwd ./tests/integration",
15
16
  "build:esmTest": "ts-node tools/esm-test.ts && yarn install --cwd ./tests/esm && ts-node tools/esm-test-package.ts",
@@ -21,7 +22,7 @@
21
22
  "test:badge": "yarn make-coverage-badge --output-path ./coverage.svg",
22
23
  "lint": "yarn eslint ./src ./example ./tests && yarn prettier *.md --check",
23
24
  "mdfix": "yarn prettier *.md --write",
24
- "precommit": "yarn lint && yarn test && yarn build && git add example/example.swagger.yaml ./LICENSE ./coverage.svg",
25
+ "precommit": "yarn lint && yarn test && yarn build && git add example/example.swagger.yaml example/example.client.ts ./LICENSE ./coverage.svg",
25
26
  "prepublishOnly": "yarn lint && yarn test && yarn build",
26
27
  "postversion": "git push && git push --tags",
27
28
  "install_hooks": "husky install"
@@ -48,11 +49,13 @@
48
49
  "ramda": "0.28.0",
49
50
  "triple-beam": "1.3.0",
50
51
  "winston": "3.7.2",
51
- "zod": "3.14.4"
52
+ "zod": "3.14.4",
53
+ "zod-to-ts": "0.2.2"
52
54
  },
53
55
  "peerDependencies": {
54
56
  "@types/jest": "*",
55
- "jest": ">=25 <28"
57
+ "jest": ">=25 <28",
58
+ "typescript": "^4.1"
56
59
  },
57
60
  "peerDependenciesMeta": {
58
61
  "jest": {
@@ -60,6 +63,9 @@
60
63
  },
61
64
  "@types/jest": {
62
65
  "optional": true
66
+ },
67
+ "typescript": {
68
+ "optional": true
63
69
  }
64
70
  },
65
71
  "devDependencies": {
@@ -88,7 +94,7 @@
88
94
  "ts-jest": "^27.0.7",
89
95
  "ts-node": "^10.4.0",
90
96
  "tsd": "^0.20.0",
91
- "typescript": "^4.5.2",
97
+ "typescript": "^4.6.3",
92
98
  "winston-transport": "^4.4.0"
93
99
  },
94
100
  "engines": {