express-zod-api 6.0.2 → 6.1.0-beta2
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 +45 -0
- package/dist/client-helpers.d.ts +21 -0
- package/dist/client-helpers.js +62 -0
- package/dist/client-helpers.js.map +1 -0
- package/dist/client.d.ts +15 -0
- package/dist/client.js +91 -0
- package/dist/client.js.map +1 -0
- package/dist/extend-zod.js +5 -2
- package/dist/extend-zod.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +3 -1
- package/dist/index.js.map +1 -1
- package/dist/method.d.ts +1 -0
- package/dist/method.js +2 -0
- package/dist/method.js.map +1 -1
- package/dist-esm/client-helpers.js +40 -0
- package/dist-esm/client-helpers.js.map +1 -0
- package/dist-esm/client.js +84 -0
- package/dist-esm/client.js.map +1 -0
- package/dist-esm/extend-zod.js +3 -2
- package/dist-esm/extend-zod.js.map +1 -1
- package/dist-esm/index.js +1 -0
- package/dist-esm/index.js.map +1 -1
- package/dist-esm/method.js +1 -1
- package/dist-esm/method.js.map +1 -1
- package/dist-esm/package.json +1 -1
- package/package.json +17 -11
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,51 @@
|
|
|
2
2
|
|
|
3
3
|
## Version 6
|
|
4
4
|
|
|
5
|
+
### v6.1.0-beta2
|
|
6
|
+
|
|
7
|
+
- Fixing bugs and taking into account path params for feature #403 (API Client Generator).
|
|
8
|
+
|
|
9
|
+
### v6.1.0-beta1
|
|
10
|
+
|
|
11
|
+
- This is a beta release of a new feature for public testing.
|
|
12
|
+
- Feature #403: API Client Generator.
|
|
13
|
+
- A new way of informing the frontend about the I/O types of endpoints is proposed.
|
|
14
|
+
- The new approach offers automatic generation of a client based on routing to a typescript file.
|
|
15
|
+
- The generated client is flexibly configured on the frontend using a provider function that directly makes a
|
|
16
|
+
request to the endpoint using the libraries and methods of your choice.
|
|
17
|
+
- The client asserts the type request and response.
|
|
18
|
+
- More details coming soon.
|
|
19
|
+
|
|
20
|
+
```typescript
|
|
21
|
+
// example client-generator.ts
|
|
22
|
+
import fs from "fs";
|
|
23
|
+
import { Client } from "express-zod-api";
|
|
24
|
+
|
|
25
|
+
fs.writeFileSync("./frontend/client.ts", new Client(routing).print(), "utf-8");
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
```typescript
|
|
29
|
+
// example frontend using the most simple provider based on fetch
|
|
30
|
+
import { ExpressZodAPIClient } from "./client.ts";
|
|
31
|
+
|
|
32
|
+
const client = new ExpressZodAPIClient(async (method, path, params) => {
|
|
33
|
+
const urlParams =
|
|
34
|
+
method === "get" ? new URLSearchParams(params).toString() : "";
|
|
35
|
+
const response = await fetch(`https://example.com${path}?${urlParams}`, {
|
|
36
|
+
method,
|
|
37
|
+
body: method === "get" ? undefined : JSON.stringify(params),
|
|
38
|
+
});
|
|
39
|
+
return response.json();
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
client.provide("get", "/v1/user/retrieve", { id: "10" });
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
### v6.0.3
|
|
46
|
+
|
|
47
|
+
- `zod` version is 3.14.4.
|
|
48
|
+
- `winston` version is 3.7.2.
|
|
49
|
+
|
|
5
50
|
### v6.0.2
|
|
6
51
|
|
|
7
52
|
- `zod` version is 3.14.3.
|
|
@@ -0,0 +1,21 @@
|
|
|
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 makeTemplate: (names: (ts.Identifier | string)[]) => ts.TemplateLiteralTypeNode;
|
|
6
|
+
export declare const parametricIndexNode: ts.TemplateLiteralTypeNode;
|
|
7
|
+
export declare const makeParam: (name: string, type: ts.TypeNode, mod?: ts.Modifier[] | undefined) => ts.ParameterDeclaration;
|
|
8
|
+
export declare const makeParams: (params: Record<string, ts.TypeNode>, mod?: ts.Modifier[] | undefined) => ts.ParameterDeclaration[];
|
|
9
|
+
export declare const makeRecord: (key: ts.Identifier, value: ts.KeywordTypeSyntaxKind) => ts.ExpressionWithTypeArguments;
|
|
10
|
+
export declare const makeInitializingConstructor: (params: ts.ParameterDeclaration[], statements: ts.Statement[]) => ts.ConstructorDeclaration;
|
|
11
|
+
export declare const makeClassPropAssignment: (prop: string, param: string) => ts.ExpressionStatement;
|
|
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 makePublicReadonlyEmptyProp: (name: string, type: ts.TypeNode) => 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 makePublicExtendedInterface: (name: string, extender: ts.HeritageClause[], props: ts.PropertySignature[]) => ts.InterfaceDeclaration;
|
|
20
|
+
export declare const makeTypeParams: (params: Record<string, ts.Identifier>) => ts.TypeParameterDeclaration[];
|
|
21
|
+
export declare const cleanId: (path: string, method: string, suffix: string) => string;
|
|
@@ -0,0 +1,62 @@
|
|
|
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.makeTypeParams = exports.makePublicExtendedInterface = exports.makeIndexedPromise = exports.makePublicClass = exports.makePublicReadonlyEmptyProp = exports.makePublicType = exports.makePublicLiteralType = exports.makeConst = exports.makeQuotedProp = exports.makeClassPropAssignment = exports.makeInitializingConstructor = exports.makeRecord = exports.makeParams = exports.makeParam = exports.parametricIndexNode = exports.makeTemplate = 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
|
+
const emptyPrefix = exports.f.createTemplateHead("");
|
|
15
|
+
const emptyEnding = exports.f.createTemplateTail("");
|
|
16
|
+
const spacingSuffix = exports.f.createTemplateMiddle(" ");
|
|
17
|
+
const makeTemplate = (names) => exports.f.createTemplateLiteralType(emptyPrefix, names.map((name, index) => exports.f.createTemplateLiteralTypeSpan(exports.f.createTypeReferenceNode(name), index === names.length - 1 ? emptyEnding : spacingSuffix)));
|
|
18
|
+
exports.makeTemplate = makeTemplate;
|
|
19
|
+
exports.parametricIndexNode = (0, exports.makeTemplate)(["M", "P"]);
|
|
20
|
+
const makeParam = (name, type, mod) => exports.f.createParameterDeclaration(undefined, mod, undefined, name, undefined, type);
|
|
21
|
+
exports.makeParam = makeParam;
|
|
22
|
+
const makeParams = (params, mod) => Object.keys(params).reduce((acc, name) => acc.concat((0, exports.makeParam)(name, params[name], mod)), []);
|
|
23
|
+
exports.makeParams = makeParams;
|
|
24
|
+
const makeRecord = (key, value) => exports.f.createExpressionWithTypeArguments(exports.f.createIdentifier("Record"), [
|
|
25
|
+
exports.f.createTypeReferenceNode(key),
|
|
26
|
+
exports.f.createKeywordTypeNode(value),
|
|
27
|
+
]);
|
|
28
|
+
exports.makeRecord = makeRecord;
|
|
29
|
+
const makeInitializingConstructor = (params, statements) => exports.f.createConstructorDeclaration(undefined, undefined, params, exports.f.createBlock(statements, true));
|
|
30
|
+
exports.makeInitializingConstructor = makeInitializingConstructor;
|
|
31
|
+
const makeClassPropAssignment = (prop, param) => exports.f.createExpressionStatement(exports.f.createBinaryExpression(exports.f.createPropertyAccessExpression(exports.f.createThis(), prop), typescript_1.default.SyntaxKind.EqualsToken, exports.f.createIdentifier(param)));
|
|
32
|
+
exports.makeClassPropAssignment = makeClassPropAssignment;
|
|
33
|
+
const makeQuotedProp = (name, ref) => exports.f.createPropertySignature(undefined, `"${name}"`, undefined, exports.f.createTypeReferenceNode(ref));
|
|
34
|
+
exports.makeQuotedProp = makeQuotedProp;
|
|
35
|
+
const makeConst = (name, value) => exports.f.createVariableDeclarationList([exports.f.createVariableDeclaration(name, undefined, undefined, value)], typescript_1.default.NodeFlags.Const);
|
|
36
|
+
exports.makeConst = makeConst;
|
|
37
|
+
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)))));
|
|
38
|
+
exports.makePublicLiteralType = makePublicLiteralType;
|
|
39
|
+
const makePublicType = (name, value) => exports.f.createTypeAliasDeclaration(undefined, exports.exportModifier, name, undefined, value);
|
|
40
|
+
exports.makePublicType = makePublicType;
|
|
41
|
+
const makePublicReadonlyEmptyProp = (name, type) => exports.f.createPropertyDeclaration(undefined, exports.publicReadonlyModifier, name, undefined, type, undefined);
|
|
42
|
+
exports.makePublicReadonlyEmptyProp = makePublicReadonlyEmptyProp;
|
|
43
|
+
const makePublicClass = (name, constructor, props = []) => exports.f.createClassDeclaration(undefined, exports.exportModifier, name, undefined, undefined, [constructor, ...props]);
|
|
44
|
+
exports.makePublicClass = makePublicClass;
|
|
45
|
+
const makeIndexedPromise = (type, index) => exports.f.createTypeReferenceNode("Promise", [
|
|
46
|
+
exports.f.createIndexedAccessTypeNode(exports.f.createTypeReferenceNode(type), index),
|
|
47
|
+
]);
|
|
48
|
+
exports.makeIndexedPromise = makeIndexedPromise;
|
|
49
|
+
const makePublicExtendedInterface = (name, extender, props) => exports.f.createInterfaceDeclaration(undefined, exports.exportModifier, name, undefined, extender, props);
|
|
50
|
+
exports.makePublicExtendedInterface = makePublicExtendedInterface;
|
|
51
|
+
const makeTypeParams = (params) => Object.keys(params).reduce((acc, name) => acc.concat(exports.f.createTypeParameterDeclaration(name, exports.f.createTypeReferenceNode(params[name]))), []);
|
|
52
|
+
exports.makeTypeParams = makeTypeParams;
|
|
53
|
+
const cleanId = (path, method, suffix) => {
|
|
54
|
+
return [method]
|
|
55
|
+
.concat(path.split("/"))
|
|
56
|
+
.concat(suffix)
|
|
57
|
+
.map((entry) => entry.replace(/[^A-Z0-9]/i, ""))
|
|
58
|
+
.map((entry) => entry.slice(0, 1).toUpperCase() + entry.slice(1).toLowerCase())
|
|
59
|
+
.join("");
|
|
60
|
+
};
|
|
61
|
+
exports.cleanId = cleanId;
|
|
62
|
+
//# 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,e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
+
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,91 @@
|
|
|
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 clientNode = (0, client_helpers_1.makePublicClass)("ExpressZodAPIClient", (0, client_helpers_1.makeInitializingConstructor)([(0, client_helpers_1.makeParam)("provider", client_helpers_1.f.createTypeReferenceNode(providerNode.name))], [(0, client_helpers_1.makeClassPropAssignment)("provide", "provider")]), [
|
|
63
|
+
(0, client_helpers_1.makePublicReadonlyEmptyProp)("provide", client_helpers_1.f.createTypeReferenceNode(providerNode.name)),
|
|
64
|
+
]);
|
|
65
|
+
typescript_1.default.addSyntheticLeadingComment(clientNode, typescript_1.default.SyntaxKind.MultiLineCommentTrivia, "\n" +
|
|
66
|
+
"export const exampleProvider: Provider = async (method, path, params) => {\n" +
|
|
67
|
+
" const pathWithParams =\n" +
|
|
68
|
+
" Object.keys(params).reduce(\n" +
|
|
69
|
+
" (acc, key) => acc.replace(`:${key}`, params[key]),\n" +
|
|
70
|
+
" path\n" +
|
|
71
|
+
' ) + (method === "get" ? `?${new URLSearchParams(params)}` : "");\n' +
|
|
72
|
+
" const response = await fetch(`https://example.com${pathWithParams}`, {" +
|
|
73
|
+
" method,\n" +
|
|
74
|
+
' body: method === "get" ? undefined : JSON.stringify(params),\n' +
|
|
75
|
+
" });\n" +
|
|
76
|
+
" if (`${method} ${path}` in jsonEndpoints) {\n" +
|
|
77
|
+
" return response.json();\n" +
|
|
78
|
+
" }\n" +
|
|
79
|
+
" return response.text();\n" +
|
|
80
|
+
"};\n" +
|
|
81
|
+
"\n" +
|
|
82
|
+
`const client = new ${clientNode.name.text}(exampleProvider);\n` +
|
|
83
|
+
'client.provide("get", "/v1/user/retrieve", { id: "10" });\n', true);
|
|
84
|
+
this.agg.push(pathNode, methodNode, methodPathNode, inputNode, responseNode, jsonEndpointsNode, providerNode, clientNode);
|
|
85
|
+
}
|
|
86
|
+
print(printerOptions) {
|
|
87
|
+
return this.agg.map((node) => (0, zod_to_ts_1.printNode)(node, printerOptions)).join("\n\n");
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
exports.Client = Client;
|
|
91
|
+
//# 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,qDAoB0B;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,GA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EAAoE;YACpE,SAAS;YACT,iDAAiD;YACjD,+BAA+B;YAC/B,OAAO;YACP,6BAA6B;YAC7B,MAAM;YACN,IAAI;YACJ,sBAAsB,UAAU,CAAC,IAAK,CAAC,IAAI,sBAAsB;YACjE,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,UAAU,CACX,CAAC;IACJ,CAAC;IAEM,KAAK,CAAC,cAAkC;QAC7C,OAAO,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAA,qBAAS,EAAC,IAAI,EAAE,cAAc,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IAC9E,CAAC;CACF;AA1JD,wBA0JC"}
|
package/dist/extend-zod.js
CHANGED
|
@@ -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
|
-
|
|
32
|
-
exports.
|
|
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
|
package/dist/extend-zod.js.map
CHANGED
|
@@ -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;
|
|
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;AAAp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cAAC;AAF3B,8DAA0C;AAEjC,0BAFF,qBAAe,CAEE"}
|
package/dist/method.d.ts
CHANGED
package/dist/method.js
CHANGED
package/dist/method.js.map
CHANGED
|
@@ -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,40 @@
|
|
|
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
|
+
const emptyPrefix = f.createTemplateHead("");
|
|
9
|
+
const emptyEnding = f.createTemplateTail("");
|
|
10
|
+
const spacingSuffix = f.createTemplateMiddle(" ");
|
|
11
|
+
export const makeTemplate = (names) => f.createTemplateLiteralType(emptyPrefix, names.map((name, index) => f.createTemplateLiteralTypeSpan(f.createTypeReferenceNode(name), index === names.length - 1 ? emptyEnding : spacingSuffix)));
|
|
12
|
+
export const parametricIndexNode = makeTemplate(["M", "P"]);
|
|
13
|
+
export const makeParam = (name, type, mod) => f.createParameterDeclaration(undefined, mod, undefined, name, undefined, type);
|
|
14
|
+
export const makeParams = (params, mod) => Object.keys(params).reduce((acc, name) => acc.concat(makeParam(name, params[name], mod)), []);
|
|
15
|
+
export const makeRecord = (key, value) => f.createExpressionWithTypeArguments(f.createIdentifier("Record"), [
|
|
16
|
+
f.createTypeReferenceNode(key),
|
|
17
|
+
f.createKeywordTypeNode(value),
|
|
18
|
+
]);
|
|
19
|
+
export const makeInitializingConstructor = (params, statements) => f.createConstructorDeclaration(undefined, undefined, params, f.createBlock(statements, true));
|
|
20
|
+
export const makeClassPropAssignment = (prop, param) => f.createExpressionStatement(f.createBinaryExpression(f.createPropertyAccessExpression(f.createThis(), prop), ts.SyntaxKind.EqualsToken, f.createIdentifier(param)));
|
|
21
|
+
export const makeQuotedProp = (name, ref) => f.createPropertySignature(undefined, `"${name}"`, undefined, f.createTypeReferenceNode(ref));
|
|
22
|
+
export const makeConst = (name, value) => f.createVariableDeclarationList([f.createVariableDeclaration(name, undefined, undefined, value)], ts.NodeFlags.Const);
|
|
23
|
+
export const makePublicLiteralType = (name, literals) => f.createTypeAliasDeclaration(undefined, exportModifier, name, undefined, f.createUnionTypeNode(literals.map((option) => f.createLiteralTypeNode(f.createStringLiteral(option)))));
|
|
24
|
+
export const makePublicType = (name, value) => f.createTypeAliasDeclaration(undefined, exportModifier, name, undefined, value);
|
|
25
|
+
export const makePublicReadonlyEmptyProp = (name, type) => f.createPropertyDeclaration(undefined, publicReadonlyModifier, name, undefined, type, undefined);
|
|
26
|
+
export const makePublicClass = (name, constructor, props = []) => f.createClassDeclaration(undefined, exportModifier, name, undefined, undefined, [constructor, ...props]);
|
|
27
|
+
export const makeIndexedPromise = (type, index) => f.createTypeReferenceNode("Promise", [
|
|
28
|
+
f.createIndexedAccessTypeNode(f.createTypeReferenceNode(type), index),
|
|
29
|
+
]);
|
|
30
|
+
export const makePublicExtendedInterface = (name, extender, props) => f.createInterfaceDeclaration(undefined, exportModifier, name, undefined, extender, props);
|
|
31
|
+
export const makeTypeParams = (params) => Object.keys(params).reduce((acc, name) => acc.concat(f.createTypeParameterDeclaration(name, f.createTypeReferenceNode(params[name]))), []);
|
|
32
|
+
export const cleanId = (path, method, suffix) => {
|
|
33
|
+
return [method]
|
|
34
|
+
.concat(path.split("/"))
|
|
35
|
+
.concat(suffix)
|
|
36
|
+
.map((entry) => entry.replace(/[^A-Z0-9]/i, ""))
|
|
37
|
+
.map((entry) => entry.slice(0, 1).toUpperCase() + entry.slice(1).toLowerCase())
|
|
38
|
+
.join("");
|
|
39
|
+
};
|
|
40
|
+
//# sourceMappingURL=client-helpers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client-helpers.js","sourceRoot":"","sources":["../src/client-helpers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,YAAY,CAAC;AAE5B,MAAM,CAAC,MAAM,CAAC,GAAG,EAAE,CAAC,OAAO,CAAC;AAE5B,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,CAAC,CAAC,cAAc,CAAC,EAAE,CAAC,UAAU,CAAC,aAAa,CAAC,CAAC,CAAC;AAE9E,MAAM,CAAC,MAAM,sBAAsB,GAAG;IACpC,CAAC,CAAC,cAAc,CAAC,EAAE,CAAC,UAAU,CAAC,aAAa,CAAC;IAC7C,CAAC,CAAC,cAAc,CAAC,EAAE,CAAC,UAAU,CAAC,eAAe,CAAC;CAChD,CAAC;AAEF,MAAM,WAAW,GAAG,CAAC,CAAC,kBAAkB,CAAC,EAAE,CAAC,CAAC;AAE7C,MAAM,WAAW,GAAG,CAAC,CAAC,kBAAkB,CAAC,EAAE,CAAC,CAAC;AAE7C,MAAM,aAAa,GAAG,CAAC,CAAC,oBAAoB,CAAC,GAAG,CAAC,CAAC;AAElD,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,KAAiC,EAAE,EAAE,CAChE,CAAC,CAAC,yBAAyB,CACzB,WAAW,EACX,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CACxB,CAAC,CAAC,6BAA6B,CAC7B,CAAC,CAAC,uBAAuB,CAAC,IAAI,CAAC,EAC/B,KAAK,KAAK,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,aAAa,CACzD,CACF,CACF,CAAC;AAEJ,MAAM,CAAC,MAAM,mBAAmB,GAAG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O,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"}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
import { createTypeAlias, printNode, zodToTs } from "zod-to-ts";
|
|
3
|
+
import { cleanId, exportModifier, f, makeConst, makeInitializingConstructor, makeIndexedPromise, makeParam, makeParams, makePublicClass, makePublicExtendedInterface, makePublicLiteralType, makePublicReadonlyEmptyProp, makePublicType, makeQuotedProp, makeRecord, makeTemplate, makeTypeParams, parametricIndexNode, makeClassPropAssignment, } 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 clientNode = makePublicClass("ExpressZodAPIClient", makeInitializingConstructor([makeParam("provider", f.createTypeReferenceNode(providerNode.name))], [makeClassPropAssignment("provide", "provider")]), [
|
|
57
|
+
makePublicReadonlyEmptyProp("provide", f.createTypeReferenceNode(providerNode.name)),
|
|
58
|
+
]);
|
|
59
|
+
ts.addSyntheticLeadingComment(clientNode, ts.SyntaxKind.MultiLineCommentTrivia, "\n" +
|
|
60
|
+
"export const exampleProvider: Provider = async (method, path, params) => {\n" +
|
|
61
|
+
" const pathWithParams =\n" +
|
|
62
|
+
" Object.keys(params).reduce(\n" +
|
|
63
|
+
" (acc, key) => acc.replace(`:${key}`, params[key]),\n" +
|
|
64
|
+
" path\n" +
|
|
65
|
+
' ) + (method === "get" ? `?${new URLSearchParams(params)}` : "");\n' +
|
|
66
|
+
" const response = await fetch(`https://example.com${pathWithParams}`, {" +
|
|
67
|
+
" method,\n" +
|
|
68
|
+
' body: method === "get" ? undefined : JSON.stringify(params),\n' +
|
|
69
|
+
" });\n" +
|
|
70
|
+
" if (`${method} ${path}` in jsonEndpoints) {\n" +
|
|
71
|
+
" return response.json();\n" +
|
|
72
|
+
" }\n" +
|
|
73
|
+
" return response.text();\n" +
|
|
74
|
+
"};\n" +
|
|
75
|
+
"\n" +
|
|
76
|
+
`const client = new ${clientNode.name.text}(exampleProvider);\n` +
|
|
77
|
+
'client.provide("get", "/v1/user/retrieve", { id: "10" });\n', true);
|
|
78
|
+
this.agg.push(pathNode, methodNode, methodPathNode, inputNode, responseNode, jsonEndpointsNode, providerNode, clientNode);
|
|
79
|
+
}
|
|
80
|
+
print(printerOptions) {
|
|
81
|
+
return this.agg.map((node) => printNode(node, printerOptions)).join("\n\n");
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
//# sourceMappingURL=client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3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AC,CAAC,IAAI,EAAE,EAAE,CAAC,SAAS,CAAC,IAAI,EAAE,cAAc,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IAC9E,CAAC;CACF"}
|
package/dist-esm/extend-zod.js
CHANGED
|
@@ -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,CA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,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 };
|
package/dist-esm/index.js.map
CHANGED
|
@@ -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,UAAU,EAAE,MAAM,kBAAkB,CAAC;AACpE,OAAO,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AACnD,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AACxC,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAChD,OAAO,EAAE,mBAAmB,EAAE,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,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
+
export const methods = ["get", "post", "put", "delete", "patch"];
|
|
2
2
|
//# sourceMappingURL=method.js.map
|
package/dist-esm/method.js.map
CHANGED
|
@@ -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"}
|
package/dist-esm/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"type":"module","version":"6.0
|
|
1
|
+
{"type":"module","version":"6.1.0-beta2"}
|
package/package.json
CHANGED
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "express-zod-api",
|
|
3
|
-
"version": "6.0
|
|
3
|
+
"version": "6.1.0-beta2",
|
|
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"
|
|
@@ -47,12 +48,14 @@
|
|
|
47
48
|
"openapi3-ts": "2.0.2",
|
|
48
49
|
"ramda": "0.28.0",
|
|
49
50
|
"triple-beam": "1.3.0",
|
|
50
|
-
"winston": "3.
|
|
51
|
-
"zod": "3.14.
|
|
51
|
+
"winston": "3.7.2",
|
|
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": {
|
|
@@ -75,7 +81,7 @@
|
|
|
75
81
|
"cors": "^2.8.5",
|
|
76
82
|
"eslint": "^8.2.0",
|
|
77
83
|
"eslint-config-airbnb-base": "^15.0.0",
|
|
78
|
-
"eslint-config-airbnb-typescript": "^
|
|
84
|
+
"eslint-config-airbnb-typescript": "^17.0.0",
|
|
79
85
|
"eslint-config-prettier": "^8.3.0",
|
|
80
86
|
"eslint-plugin-import": "^2.25.3",
|
|
81
87
|
"eslint-plugin-prettier": "^4.0.0",
|
|
@@ -84,11 +90,11 @@
|
|
|
84
90
|
"jest": "^27.3.1",
|
|
85
91
|
"make-coverage-badge": "^1.2.0",
|
|
86
92
|
"node-fetch": "^2.6.5",
|
|
87
|
-
"prettier": "2.6.
|
|
93
|
+
"prettier": "2.6.2",
|
|
88
94
|
"ts-jest": "^27.0.7",
|
|
89
95
|
"ts-node": "^10.4.0",
|
|
90
|
-
"tsd": "^0.
|
|
91
|
-
"typescript": "^4.
|
|
96
|
+
"tsd": "^0.20.0",
|
|
97
|
+
"typescript": "^4.6.3",
|
|
92
98
|
"winston-transport": "^4.4.0"
|
|
93
99
|
},
|
|
94
100
|
"engines": {
|