@rexeus/typeweaver-types 0.7.0 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +6 -63
- package/dist/index.mjs +6 -63
- package/dist/index.mjs.map +1 -1
- package/dist/lib/ResponseValidator.d.ts +21 -7
- package/dist/lib/ResponseValidator.js +40 -2
- package/dist/templates/Request.ejs +0 -24
- package/dist/templates/Response.ejs +18 -60
- package/dist/templates/ResponseValidator.ejs +13 -85
- package/dist/templates/SharedResponse.ejs +16 -28
- package/package.json +7 -7
package/dist/index.cjs
CHANGED
|
@@ -55,72 +55,15 @@ var RequestGenerator = class {
|
|
|
55
55
|
for (const [, entityResource] of Object.entries(context.resources.entityResources)) for (const definition of entityResource.operations) this.writeRequestType(templateFilePath, definition, context);
|
|
56
56
|
}
|
|
57
57
|
static writeRequestType(templateFilePath, operationResource, context) {
|
|
58
|
-
const {
|
|
59
|
-
const { request, operationId, method, responses } = definition;
|
|
58
|
+
const { request, operationId, method } = operationResource.definition;
|
|
60
59
|
const { header, query, param, body } = request;
|
|
61
|
-
const headerTsType = header ? _rexeus_typeweaver_zod_to_ts.TsTypePrinter.print(_rexeus_typeweaver_zod_to_ts.TsTypeNode.fromZod(header)) : void 0;
|
|
62
|
-
const queryTsType = query ? _rexeus_typeweaver_zod_to_ts.TsTypePrinter.print(_rexeus_typeweaver_zod_to_ts.TsTypeNode.fromZod(query)) : void 0;
|
|
63
|
-
const paramTsType = param ? _rexeus_typeweaver_zod_to_ts.TsTypePrinter.print(_rexeus_typeweaver_zod_to_ts.TsTypeNode.fromZod(param)) : void 0;
|
|
64
|
-
const bodyTsType = body ? _rexeus_typeweaver_zod_to_ts.TsTypePrinter.print(_rexeus_typeweaver_zod_to_ts.TsTypeNode.fromZod(body)) : void 0;
|
|
65
|
-
const pascalCaseOperationId = case$1.default.pascal(operationId);
|
|
66
|
-
const sourcePath = _rexeus_typeweaver_gen.Path.relative(outputDir, `${operationResource.sourceDir}/${node_path.default.relative(operationResource.sourceDir, operationResource.sourceFile).replace(/\.ts$/, "")}`);
|
|
67
|
-
const ownSuccessResponses = [];
|
|
68
|
-
const ownErrorResponses = [];
|
|
69
|
-
const sharedSuccessResponses = [];
|
|
70
|
-
const sharedErrorResponses = [];
|
|
71
|
-
const entityErrorResponses = [];
|
|
72
|
-
for (const response of responses) {
|
|
73
|
-
const { statusCode, name, isReference } = response;
|
|
74
|
-
if (isReference) {
|
|
75
|
-
const sharedResponse = context.resources.sharedResponseResources.find((resource) => resource.name === name);
|
|
76
|
-
if (sharedResponse) {
|
|
77
|
-
const responsePath = _rexeus_typeweaver_gen.Path.relative(outputDir, `${sharedResponse.outputDir}/${node_path.default.basename(sharedResponse.outputFileName, ".ts")}`);
|
|
78
|
-
if (statusCode >= 200 && statusCode < 300) sharedSuccessResponses.push({
|
|
79
|
-
name,
|
|
80
|
-
path: responsePath
|
|
81
|
-
});
|
|
82
|
-
else sharedErrorResponses.push({
|
|
83
|
-
name,
|
|
84
|
-
path: responsePath
|
|
85
|
-
});
|
|
86
|
-
} else {
|
|
87
|
-
const entityResponse = (context.resources.entityResources[operationResource.entityName]?.responses)?.find((r) => r.name === name);
|
|
88
|
-
if (!entityResponse) throw new Error(`Shared response '${response.name}' not found in shared or entity resources`);
|
|
89
|
-
const responsePath = _rexeus_typeweaver_gen.Path.relative(outputDir, `${entityResponse.outputDir}/${node_path.default.basename(entityResponse.outputFileName, ".ts")}`);
|
|
90
|
-
if (statusCode >= 200 && statusCode < 300) sharedSuccessResponses.push({
|
|
91
|
-
name,
|
|
92
|
-
path: responsePath
|
|
93
|
-
});
|
|
94
|
-
else entityErrorResponses.push({
|
|
95
|
-
name,
|
|
96
|
-
path: responsePath
|
|
97
|
-
});
|
|
98
|
-
}
|
|
99
|
-
continue;
|
|
100
|
-
}
|
|
101
|
-
const assembledResponse = { name };
|
|
102
|
-
if (statusCode >= 200 && statusCode < 300) ownSuccessResponses.push(assembledResponse);
|
|
103
|
-
else ownErrorResponses.push(assembledResponse);
|
|
104
|
-
}
|
|
105
60
|
const content = context.renderTemplate(templateFilePath, {
|
|
106
|
-
pascalCaseOperationId,
|
|
107
|
-
operationId,
|
|
108
|
-
coreDir: context.coreDir,
|
|
109
|
-
sourcePath,
|
|
110
|
-
headerTsType,
|
|
111
|
-
queryTsType,
|
|
112
|
-
paramTsType,
|
|
113
|
-
bodyTsType,
|
|
61
|
+
pascalCaseOperationId: case$1.default.pascal(operationId),
|
|
114
62
|
method,
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
entityErrorResponses,
|
|
120
|
-
responseFile: _rexeus_typeweaver_gen.Path.relative(outputDir, `${outputDir}/${node_path.default.basename(outputResponseFileName, ".ts")}`),
|
|
121
|
-
responseValidationFile: _rexeus_typeweaver_gen.Path.relative(outputDir, `${outputDir}/${node_path.default.basename(outputResponseValidationFileName, ".ts")}`),
|
|
122
|
-
hasErrorResponses: ownErrorResponses.length > 0 || entityErrorResponses.length > 0 || sharedErrorResponses.length > 0,
|
|
123
|
-
hasSuccessResponses: ownSuccessResponses.length > 0 || sharedSuccessResponses.length > 0
|
|
63
|
+
headerTsType: header ? _rexeus_typeweaver_zod_to_ts.TsTypePrinter.print(_rexeus_typeweaver_zod_to_ts.TsTypeNode.fromZod(header)) : void 0,
|
|
64
|
+
queryTsType: query ? _rexeus_typeweaver_zod_to_ts.TsTypePrinter.print(_rexeus_typeweaver_zod_to_ts.TsTypeNode.fromZod(query)) : void 0,
|
|
65
|
+
paramTsType: param ? _rexeus_typeweaver_zod_to_ts.TsTypePrinter.print(_rexeus_typeweaver_zod_to_ts.TsTypeNode.fromZod(param)) : void 0,
|
|
66
|
+
bodyTsType: body ? _rexeus_typeweaver_zod_to_ts.TsTypePrinter.print(_rexeus_typeweaver_zod_to_ts.TsTypeNode.fromZod(body)) : void 0
|
|
124
67
|
});
|
|
125
68
|
const relativePath = node_path.default.relative(context.outputDir, operationResource.outputRequestFile);
|
|
126
69
|
context.writeFile(relativePath, content);
|
package/dist/index.mjs
CHANGED
|
@@ -30,72 +30,15 @@ var RequestGenerator = class {
|
|
|
30
30
|
for (const [, entityResource] of Object.entries(context.resources.entityResources)) for (const definition of entityResource.operations) this.writeRequestType(templateFilePath, definition, context);
|
|
31
31
|
}
|
|
32
32
|
static writeRequestType(templateFilePath, operationResource, context) {
|
|
33
|
-
const {
|
|
34
|
-
const { request, operationId, method, responses } = definition;
|
|
33
|
+
const { request, operationId, method } = operationResource.definition;
|
|
35
34
|
const { header, query, param, body } = request;
|
|
36
|
-
const headerTsType = header ? TsTypePrinter.print(TsTypeNode.fromZod(header)) : void 0;
|
|
37
|
-
const queryTsType = query ? TsTypePrinter.print(TsTypeNode.fromZod(query)) : void 0;
|
|
38
|
-
const paramTsType = param ? TsTypePrinter.print(TsTypeNode.fromZod(param)) : void 0;
|
|
39
|
-
const bodyTsType = body ? TsTypePrinter.print(TsTypeNode.fromZod(body)) : void 0;
|
|
40
|
-
const pascalCaseOperationId = Case.pascal(operationId);
|
|
41
|
-
const sourcePath = Path.relative(outputDir, `${operationResource.sourceDir}/${path.relative(operationResource.sourceDir, operationResource.sourceFile).replace(/\.ts$/, "")}`);
|
|
42
|
-
const ownSuccessResponses = [];
|
|
43
|
-
const ownErrorResponses = [];
|
|
44
|
-
const sharedSuccessResponses = [];
|
|
45
|
-
const sharedErrorResponses = [];
|
|
46
|
-
const entityErrorResponses = [];
|
|
47
|
-
for (const response of responses) {
|
|
48
|
-
const { statusCode, name, isReference } = response;
|
|
49
|
-
if (isReference) {
|
|
50
|
-
const sharedResponse = context.resources.sharedResponseResources.find((resource) => resource.name === name);
|
|
51
|
-
if (sharedResponse) {
|
|
52
|
-
const responsePath = Path.relative(outputDir, `${sharedResponse.outputDir}/${path.basename(sharedResponse.outputFileName, ".ts")}`);
|
|
53
|
-
if (statusCode >= 200 && statusCode < 300) sharedSuccessResponses.push({
|
|
54
|
-
name,
|
|
55
|
-
path: responsePath
|
|
56
|
-
});
|
|
57
|
-
else sharedErrorResponses.push({
|
|
58
|
-
name,
|
|
59
|
-
path: responsePath
|
|
60
|
-
});
|
|
61
|
-
} else {
|
|
62
|
-
const entityResponse = (context.resources.entityResources[operationResource.entityName]?.responses)?.find((r) => r.name === name);
|
|
63
|
-
if (!entityResponse) throw new Error(`Shared response '${response.name}' not found in shared or entity resources`);
|
|
64
|
-
const responsePath = Path.relative(outputDir, `${entityResponse.outputDir}/${path.basename(entityResponse.outputFileName, ".ts")}`);
|
|
65
|
-
if (statusCode >= 200 && statusCode < 300) sharedSuccessResponses.push({
|
|
66
|
-
name,
|
|
67
|
-
path: responsePath
|
|
68
|
-
});
|
|
69
|
-
else entityErrorResponses.push({
|
|
70
|
-
name,
|
|
71
|
-
path: responsePath
|
|
72
|
-
});
|
|
73
|
-
}
|
|
74
|
-
continue;
|
|
75
|
-
}
|
|
76
|
-
const assembledResponse = { name };
|
|
77
|
-
if (statusCode >= 200 && statusCode < 300) ownSuccessResponses.push(assembledResponse);
|
|
78
|
-
else ownErrorResponses.push(assembledResponse);
|
|
79
|
-
}
|
|
80
35
|
const content = context.renderTemplate(templateFilePath, {
|
|
81
|
-
pascalCaseOperationId,
|
|
82
|
-
operationId,
|
|
83
|
-
coreDir: context.coreDir,
|
|
84
|
-
sourcePath,
|
|
85
|
-
headerTsType,
|
|
86
|
-
queryTsType,
|
|
87
|
-
paramTsType,
|
|
88
|
-
bodyTsType,
|
|
36
|
+
pascalCaseOperationId: Case.pascal(operationId),
|
|
89
37
|
method,
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
entityErrorResponses,
|
|
95
|
-
responseFile: Path.relative(outputDir, `${outputDir}/${path.basename(outputResponseFileName, ".ts")}`),
|
|
96
|
-
responseValidationFile: Path.relative(outputDir, `${outputDir}/${path.basename(outputResponseValidationFileName, ".ts")}`),
|
|
97
|
-
hasErrorResponses: ownErrorResponses.length > 0 || entityErrorResponses.length > 0 || sharedErrorResponses.length > 0,
|
|
98
|
-
hasSuccessResponses: ownSuccessResponses.length > 0 || sharedSuccessResponses.length > 0
|
|
38
|
+
headerTsType: header ? TsTypePrinter.print(TsTypeNode.fromZod(header)) : void 0,
|
|
39
|
+
queryTsType: query ? TsTypePrinter.print(TsTypeNode.fromZod(query)) : void 0,
|
|
40
|
+
paramTsType: param ? TsTypePrinter.print(TsTypeNode.fromZod(param)) : void 0,
|
|
41
|
+
bodyTsType: body ? TsTypePrinter.print(TsTypeNode.fromZod(body)) : void 0
|
|
99
42
|
});
|
|
100
43
|
const relativePath = path.relative(context.outputDir, operationResource.outputRequestFile);
|
|
101
44
|
context.writeFile(relativePath, content);
|