@sdk-it/generic 0.9.0 → 0.10.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.js
CHANGED
|
@@ -11,22 +11,29 @@ import {
|
|
|
11
11
|
toSchema
|
|
12
12
|
} from "@sdk-it/core";
|
|
13
13
|
var returnToken = (node) => {
|
|
14
|
-
|
|
14
|
+
const tokens = [];
|
|
15
15
|
const visitor = (node2) => {
|
|
16
|
-
if (ts.
|
|
17
|
-
if (ts.
|
|
18
|
-
|
|
19
|
-
|
|
16
|
+
if (ts.isThrowStatement(node2)) {
|
|
17
|
+
if (ts.isNewExpression(node2.expression)) {
|
|
18
|
+
tokens.push({
|
|
19
|
+
token: `throw.new.${node2.expression.expression.getText()}`,
|
|
20
|
+
node: node2.expression
|
|
21
|
+
});
|
|
20
22
|
}
|
|
23
|
+
}
|
|
24
|
+
if (ts.isReturnStatement(node2) && node2.expression) {
|
|
21
25
|
if (ts.isCallExpression(node2.expression)) {
|
|
22
|
-
|
|
23
|
-
|
|
26
|
+
tokens.push({
|
|
27
|
+
token: node2.expression.expression.getText(),
|
|
28
|
+
node: node2.expression
|
|
29
|
+
});
|
|
24
30
|
}
|
|
31
|
+
return void 0;
|
|
25
32
|
}
|
|
26
33
|
return ts.forEachChild(node2, visitor);
|
|
27
34
|
};
|
|
28
35
|
ts.forEachChild(node, visitor);
|
|
29
|
-
return
|
|
36
|
+
return tokens;
|
|
30
37
|
};
|
|
31
38
|
var logger = debug("@sdk-it/generic");
|
|
32
39
|
var jsDocsTags = ["openapi", "tags", "description"];
|
|
@@ -92,13 +99,17 @@ function visit(node, responseAnalyzer2, paths) {
|
|
|
92
99
|
ts.isPropertyAssignment
|
|
93
100
|
);
|
|
94
101
|
const sourceFile = node.getSourceFile();
|
|
95
|
-
const
|
|
102
|
+
const tokens = returnToken(handler);
|
|
103
|
+
const responses = [];
|
|
104
|
+
for (const { token, node: node2 } of tokens) {
|
|
105
|
+
responses.push(...responseAnalyzer2(handler, token, node2));
|
|
106
|
+
}
|
|
96
107
|
paths.addPath(
|
|
97
108
|
operationName,
|
|
98
109
|
path,
|
|
99
110
|
method,
|
|
100
111
|
toSelectors(props),
|
|
101
|
-
|
|
112
|
+
responses,
|
|
102
113
|
sourceFile.fileName,
|
|
103
114
|
metadata.tags,
|
|
104
115
|
metadata.description
|
|
@@ -153,14 +164,14 @@ async function analyze(tsconfigPath, config) {
|
|
|
153
164
|
logger(`Visiting ${sourceFile.fileName}`);
|
|
154
165
|
visit(
|
|
155
166
|
sourceFile,
|
|
156
|
-
(handler, token) => {
|
|
167
|
+
(handler, token, node) => {
|
|
157
168
|
const responseAnalyzer2 = config.responseAnalyzer;
|
|
158
169
|
if (typeof responseAnalyzer2 !== "function") {
|
|
159
170
|
const naunce = responseAnalyzer2[token] || responseAnalyzer2["default"];
|
|
160
171
|
if (!naunce) {
|
|
161
172
|
throw new Error(`No response analyzer for token ${token}`);
|
|
162
173
|
}
|
|
163
|
-
return naunce(handler, typeDeriver);
|
|
174
|
+
return naunce(handler, typeDeriver, node);
|
|
164
175
|
}
|
|
165
176
|
return responseAnalyzer2(handler, typeDeriver);
|
|
166
177
|
},
|
|
@@ -232,6 +243,37 @@ function defaultResponseAnalyzer(handler, deriver) {
|
|
|
232
243
|
}
|
|
233
244
|
}
|
|
234
245
|
var responseAnalyzer = {
|
|
246
|
+
"throw.new.ProblemDetailsException": (handler, deriver, node) => {
|
|
247
|
+
if (ts2.isNewExpression(node)) {
|
|
248
|
+
const [problem] = node.arguments ?? [];
|
|
249
|
+
if (!ts2.isObjectLiteralExpression(problem)) {
|
|
250
|
+
return [];
|
|
251
|
+
}
|
|
252
|
+
const properties = problem.properties.reduce(
|
|
253
|
+
(acc, prop) => {
|
|
254
|
+
if (ts2.isPropertyAssignment(prop)) {
|
|
255
|
+
const key = prop.name.getText();
|
|
256
|
+
if (ts2.isLiteralExpression(prop.initializer)) {
|
|
257
|
+
acc[key] = prop.initializer.text;
|
|
258
|
+
} else {
|
|
259
|
+
acc[key] = prop.initializer.getText();
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
return acc;
|
|
263
|
+
},
|
|
264
|
+
{}
|
|
265
|
+
);
|
|
266
|
+
return [
|
|
267
|
+
{
|
|
268
|
+
contentType: "application/problem+json",
|
|
269
|
+
headers: [],
|
|
270
|
+
statusCode: properties.status,
|
|
271
|
+
response: problem ? deriver.serializeNode(problem) : void 0
|
|
272
|
+
}
|
|
273
|
+
];
|
|
274
|
+
}
|
|
275
|
+
return [];
|
|
276
|
+
},
|
|
235
277
|
default: defaultResponseAnalyzer
|
|
236
278
|
};
|
|
237
279
|
export {
|
package/dist/index.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/lib/generic.ts", "../src/lib/response-analyzer.ts"],
|
|
4
|
-
"sourcesContent": ["import debug from 'debug';\nimport type { ComponentsObject } from 'openapi3-ts/oas31';\nimport { camelcase } from 'stringcase';\nimport ts from 'typescript';\n\nimport {\n type OnOperation,\n Paths,\n type ResponseItem,\n type Selector,\n type SemanticSource,\n TypeDeriver,\n getProgram,\n isCallExpression,\n isHttpMethod,\n toSchema,\n} from '@sdk-it/core';\n\nexport const returnToken = (node: ts.ArrowFunction) => {\n let token = '';\n\n const visitor: ts.Visitor = (node) => {\n if (ts.isReturnStatement(node) && node.expression) {\n if (ts.isPropertyAccessExpression(node.expression)) {\n token = node.expression.getText();\n return undefined; // Once found, no need to continue visiting\n }\n if (ts.isCallExpression(node.expression)) {\n token = node.expression.expression.getText();\n return undefined; // Once found, no need to continue visiting\n }\n }\n return ts.forEachChild(node, visitor);\n };\n\n ts.forEachChild(node, visitor);\n return token;\n};\n\nconst logger = debug('@sdk-it/generic');\n\nconst jsDocsTags = ['openapi', 'tags', 'description'];\n\nfunction parseJSDocComment(node: ts.Node) {\n let tags: string[] = [];\n let name = '';\n let description = '';\n for (const tag of ts.getAllJSDocTags(node, (tag): tag is ts.JSDocTag =>\n jsDocsTags.includes(tag.tagName.text),\n )) {\n if (typeof tag.comment !== 'string') {\n continue;\n }\n switch (tag.tagName.text) {\n case 'openapi':\n name = tag.comment;\n break;\n case 'tags':\n tags = tag.comment.split(',').map((tag) => tag.trim());\n break;\n case 'description':\n description = tag.comment;\n break;\n }\n }\n return {\n name,\n tags,\n description,\n };\n}\n\nfunction visit(\n node: ts.Node,\n responseAnalyzer: (\n handler: ts.ArrowFunction,\n token: string,\n ) => ResponseItem[],\n paths: Paths,\n) {\n if (!ts.isCallExpression(node) || node.arguments.length < 2) {\n return moveOn();\n }\n if (\n !ts.isPropertyAccessExpression(node.expression) ||\n !ts.isIdentifier(node.expression.name) ||\n !isHttpMethod(node.expression.name.text)\n ) {\n return moveOn();\n }\n\n const [pathNode] = node.arguments;\n if (!ts.isStringLiteral(pathNode)) {\n return moveOn();\n }\n const method = node.expression.name.text;\n const path = pathNode.text;\n const validate = node.arguments.find((arg) =>\n isCallExpression(arg, 'validate'),\n );\n if (!validate) {\n return moveOn();\n }\n const handler = node.arguments.at(-1);\n if (!handler || !ts.isArrowFunction(handler)) {\n return moveOn();\n }\n\n const metadata = parseJSDocComment(node.parent);\n const operationName =\n metadata.name ||\n camelcase(`${method} ${path.replace(/[^a-zA-Z0-9]/g, '')}`);\n const selector = validate.arguments.find((arg) => ts.isArrowFunction(arg));\n if (\n !selector ||\n !ts.isParenthesizedExpression(selector.body) ||\n !ts.isObjectLiteralExpression(selector.body.expression)\n ) {\n return moveOn();\n }\n const props = selector.body.expression.properties.filter(\n ts.isPropertyAssignment,\n );\n\n const sourceFile = node.getSourceFile();\n const token = returnToken(handler);\n paths.addPath(\n operationName,\n path,\n method,\n toSelectors(props),\n responseAnalyzer(handler, token),\n sourceFile.fileName,\n metadata.tags,\n metadata.description,\n );\n\n function moveOn() {\n ts.forEachChild(node, (node) => visit(node, responseAnalyzer, paths));\n }\n}\n\nfunction toSelectors(props: ts.PropertyAssignment[]) {\n const selectors: Selector[] = [];\n for (const prop of props) {\n if (!ts.isObjectLiteralExpression(prop.initializer)) {\n continue;\n }\n const name = prop.name.getText();\n const select = prop.initializer.properties\n .filter(ts.isPropertyAssignment)\n .find((prop) => prop.name.getText() === 'select');\n if (!select) {\n console.warn(`No select found in ${name}`);\n continue;\n }\n const against = prop.initializer.properties\n .filter(ts.isPropertyAssignment)\n .find((prop) => prop.name.getText() === 'against');\n if (!against) {\n console.warn(`No against found in ${name}`);\n continue;\n }\n const [, source, selectText] = select.initializer.getText().split('.');\n selectors.push({\n name,\n nullable: against.initializer.getText().includes('nullable'),\n required: !against.initializer.getText().includes('optional'),\n select: selectText,\n against: against.initializer.getText(),\n source: source as SemanticSource,\n });\n }\n return selectors;\n}\ntype NaunceResponseAnalyzer = Record<string, ResponseAnalyzer>;\n\ntype ResponseAnalyzer = (\n handler: ts.ArrowFunction,\n deriver: TypeDeriver,\n) => ResponseItem[];\n\nexport async function analyze(\n tsconfigPath: string,\n config: {\n /**\n * Additional code to inject before resolving zod schemas\n */\n commonZodImport?: string;\n responseAnalyzer: ResponseAnalyzer | NaunceResponseAnalyzer;\n onOperation?: OnOperation;\n },\n) {\n logger(`Parsing tsconfig`);\n const program = getProgram(tsconfigPath);\n logger(`Program created`);\n const typeChecker = program.getTypeChecker();\n logger(`Type checker created`);\n const typeDeriver = new TypeDeriver(typeChecker);\n const paths = new Paths({\n commonZodImport: config.commonZodImport,\n onOperation: config.onOperation,\n });\n\n for (const sourceFile of program.getSourceFiles()) {\n logger(`Analyzing ${sourceFile.fileName}`);\n if (!sourceFile.isDeclarationFile) {\n logger(`Visiting ${sourceFile.fileName}`);\n visit(\n sourceFile,\n (handler, token) => {\n const responseAnalyzer = config.responseAnalyzer;\n if (typeof responseAnalyzer !== 'function') {\n const naunce =\n responseAnalyzer[token] || responseAnalyzer['default'];\n if (!naunce) {\n throw new Error(`No response analyzer for token ${token}`);\n }\n return naunce(handler, typeDeriver);\n }\n return responseAnalyzer(handler, typeDeriver);\n },\n paths,\n );\n }\n }\n\n const components: ComponentsObject = {\n schemas: Object.entries(typeDeriver.collector).reduce(\n (acc, [key, value]) => ({ ...acc, [key]: toSchema(value) }),\n {},\n ),\n };\n\n return {\n paths: await paths.getPaths(),\n components,\n };\n}\n\nexport type Serialized = ReturnType<typeof analyze>;\n", "import ts from 'typescript';\n\nimport type { ResponseItem, TypeDeriver } from '@sdk-it/core';\n\nconst handlerVisitor: (\n on: (\n node: ts.Node | undefined,\n statusCode: ts.Node | undefined,\n headers: ts.Node | undefined,\n contentType: string,\n ) => void,\n) => ts.Visitor = (callback) => {\n return (node: ts.Node) => {\n if (ts.isReturnStatement(node) && node.expression) {\n if (\n ts.isCallExpression(node.expression) &&\n ts.isPropertyAccessExpression(node.expression.expression)\n ) {\n const propAccess = node.expression.expression;\n if (\n ts.isIdentifier(propAccess.expression) &&\n propAccess.expression.text === 'output'\n ) {\n let contentType = 'application/json';\n const callerMethod = propAccess.name.text;\n const [body, statusCode, headers] = node.expression.arguments;\n if (callerMethod === 'attachment') {\n contentType = 'application/octet-stream';\n }\n if (!body) {\n contentType = 'empty';\n }\n callback(body, statusCode, headers, contentType);\n }\n }\n }\n return ts.forEachChild(node, handlerVisitor(callback));\n };\n};\n\nfunction toResponses(handler: ts.ArrowFunction, deriver: TypeDeriver) {\n const responsesList: ResponseItem[] = [];\n const visit = handlerVisitor((node, statusCode, headers, contentType) => {\n responsesList.push({\n headers: headers ? Object.keys(deriver.serializeNode(headers)) : [],\n contentType,\n statusCode: statusCode ? resolveStatusCode(statusCode) : '200',\n response: node ? deriver.serializeNode(node) : undefined,\n });\n });\n visit(handler.body);\n return responsesList;\n}\n\nfunction resolveStatusCode(node: ts.Node) {\n if (ts.isNumericLiteral(node)) {\n return node.text;\n }\n throw new Error(`Could not resolve status code`);\n}\n\nexport function defaultResponseAnalyzer(\n handler: ts.ArrowFunction,\n deriver: TypeDeriver,\n) {\n try {\n return toResponses(handler, deriver);\n } catch (error) {\n console.error('Error analyzing response\\n', handler.getText());\n throw error;\n }\n}\n\nexport const responseAnalyzer = {\n default: defaultResponseAnalyzer,\n};\n"],
|
|
5
|
-
"mappings": ";AAAA,OAAO,WAAW;AAElB,SAAS,iBAAiB;AAC1B,OAAO,QAAQ;AAEf;AAAA,
|
|
4
|
+
"sourcesContent": ["import debug from 'debug';\nimport type { ComponentsObject } from 'openapi3-ts/oas31';\nimport { camelcase } from 'stringcase';\nimport ts from 'typescript';\n\nimport {\n type NaunceResponseAnalyzer,\n type OnOperation,\n Paths,\n type ResponseAnalyzerFn,\n type ResponseItem,\n type Selector,\n type SemanticSource,\n TypeDeriver,\n getProgram,\n isCallExpression,\n isHttpMethod,\n toSchema,\n} from '@sdk-it/core';\n\nexport const returnToken = (node: ts.ArrowFunction) => {\n const tokens: { token: string; node: ts.Expression }[] = [];\n\n const visitor: ts.Visitor = (node) => {\n if (ts.isThrowStatement(node)) {\n if (ts.isNewExpression(node.expression)) {\n tokens.push({\n token: `throw.new.${node.expression.expression.getText()}`,\n node: node.expression,\n });\n }\n }\n\n if (ts.isReturnStatement(node) && node.expression) {\n if (ts.isCallExpression(node.expression)) {\n tokens.push({\n token: node.expression.expression.getText(),\n node: node.expression,\n });\n }\n return undefined;\n }\n\n return ts.forEachChild(node, visitor);\n };\n\n ts.forEachChild(node, visitor);\n return tokens;\n};\n\nconst logger = debug('@sdk-it/generic');\n\nconst jsDocsTags = ['openapi', 'tags', 'description'];\n\nfunction parseJSDocComment(node: ts.Node) {\n let tags: string[] = [];\n let name = '';\n let description = '';\n for (const tag of ts.getAllJSDocTags(node, (tag): tag is ts.JSDocTag =>\n jsDocsTags.includes(tag.tagName.text),\n )) {\n if (typeof tag.comment !== 'string') {\n continue;\n }\n switch (tag.tagName.text) {\n case 'openapi':\n name = tag.comment;\n break;\n case 'tags':\n tags = tag.comment.split(',').map((tag) => tag.trim());\n break;\n case 'description':\n description = tag.comment;\n break;\n }\n }\n return {\n name,\n tags,\n description,\n };\n}\n\nfunction visit(\n node: ts.Node,\n responseAnalyzer: (\n handler: ts.ArrowFunction,\n token: string,\n node: ts.Node,\n ) => ResponseItem[],\n paths: Paths,\n) {\n if (!ts.isCallExpression(node) || node.arguments.length < 2) {\n return moveOn();\n }\n if (\n !ts.isPropertyAccessExpression(node.expression) ||\n !ts.isIdentifier(node.expression.name) ||\n !isHttpMethod(node.expression.name.text)\n ) {\n return moveOn();\n }\n\n const [pathNode] = node.arguments;\n if (!ts.isStringLiteral(pathNode)) {\n return moveOn();\n }\n const method = node.expression.name.text;\n const path = pathNode.text;\n const validate = node.arguments.find((arg) =>\n isCallExpression(arg, 'validate'),\n );\n if (!validate) {\n return moveOn();\n }\n const handler = node.arguments.at(-1);\n if (!handler || !ts.isArrowFunction(handler)) {\n return moveOn();\n }\n\n const metadata = parseJSDocComment(node.parent);\n const operationName =\n metadata.name ||\n camelcase(`${method} ${path.replace(/[^a-zA-Z0-9]/g, '')}`);\n const selector = validate.arguments.find((arg) => ts.isArrowFunction(arg));\n if (\n !selector ||\n !ts.isParenthesizedExpression(selector.body) ||\n !ts.isObjectLiteralExpression(selector.body.expression)\n ) {\n return moveOn();\n }\n const props = selector.body.expression.properties.filter(\n ts.isPropertyAssignment,\n );\n\n const sourceFile = node.getSourceFile();\n const tokens = returnToken(handler);\n\n const responses: ResponseItem[] = [];\n for (const { token, node } of tokens) {\n responses.push(...responseAnalyzer(handler, token, node));\n }\n\n paths.addPath(\n operationName,\n path,\n method,\n toSelectors(props),\n responses,\n sourceFile.fileName,\n metadata.tags,\n metadata.description,\n );\n\n function moveOn() {\n ts.forEachChild(node, (node) => visit(node, responseAnalyzer, paths));\n }\n}\n\nfunction toSelectors(props: ts.PropertyAssignment[]) {\n const selectors: Selector[] = [];\n for (const prop of props) {\n if (!ts.isObjectLiteralExpression(prop.initializer)) {\n continue;\n }\n const name = prop.name.getText();\n const select = prop.initializer.properties\n .filter(ts.isPropertyAssignment)\n .find((prop) => prop.name.getText() === 'select');\n if (!select) {\n console.warn(`No select found in ${name}`);\n continue;\n }\n const against = prop.initializer.properties\n .filter(ts.isPropertyAssignment)\n .find((prop) => prop.name.getText() === 'against');\n if (!against) {\n console.warn(`No against found in ${name}`);\n continue;\n }\n const [, source, selectText] = select.initializer.getText().split('.');\n selectors.push({\n name,\n nullable: against.initializer.getText().includes('nullable'),\n required: !against.initializer.getText().includes('optional'),\n select: selectText,\n against: against.initializer.getText(),\n source: source as SemanticSource,\n });\n }\n return selectors;\n}\n\nexport async function analyze(\n tsconfigPath: string,\n config: {\n /**\n * Additional code to inject before resolving zod schemas\n */\n commonZodImport?: string;\n responseAnalyzer: ResponseAnalyzerFn | NaunceResponseAnalyzer;\n onOperation?: OnOperation;\n },\n) {\n logger(`Parsing tsconfig`);\n const program = getProgram(tsconfigPath);\n logger(`Program created`);\n const typeChecker = program.getTypeChecker();\n logger(`Type checker created`);\n const typeDeriver = new TypeDeriver(typeChecker);\n const paths = new Paths({\n commonZodImport: config.commonZodImport,\n onOperation: config.onOperation,\n });\n\n for (const sourceFile of program.getSourceFiles()) {\n logger(`Analyzing ${sourceFile.fileName}`);\n if (!sourceFile.isDeclarationFile) {\n logger(`Visiting ${sourceFile.fileName}`);\n visit(\n sourceFile,\n (handler, token, node) => {\n const responseAnalyzer = config.responseAnalyzer;\n if (typeof responseAnalyzer !== 'function') {\n const naunce =\n responseAnalyzer[token] || responseAnalyzer['default'];\n if (!naunce) {\n throw new Error(`No response analyzer for token ${token}`);\n }\n return naunce(handler, typeDeriver, node);\n }\n return responseAnalyzer(handler, typeDeriver);\n },\n paths,\n );\n }\n }\n\n const components: ComponentsObject = {\n schemas: Object.entries(typeDeriver.collector).reduce(\n (acc, [key, value]) => ({ ...acc, [key]: toSchema(value) }),\n {},\n ),\n };\n\n return {\n paths: await paths.getPaths(),\n components,\n };\n}\n\nexport type Serialized = ReturnType<typeof analyze>;\n", "import ts from 'typescript';\n\nimport type {\n NaunceResponseAnalyzer,\n ResponseItem,\n TypeDeriver,\n} from '@sdk-it/core';\n\nconst handlerVisitor: (\n on: (\n node: ts.Node | undefined,\n statusCode: ts.Node | undefined,\n headers: ts.Node | undefined,\n contentType: string,\n ) => void,\n) => ts.Visitor = (callback) => {\n return (node: ts.Node) => {\n if (ts.isReturnStatement(node) && node.expression) {\n if (\n ts.isCallExpression(node.expression) &&\n ts.isPropertyAccessExpression(node.expression.expression)\n ) {\n const propAccess = node.expression.expression;\n if (\n ts.isIdentifier(propAccess.expression) &&\n propAccess.expression.text === 'output'\n ) {\n let contentType = 'application/json';\n const callerMethod = propAccess.name.text;\n const [body, statusCode, headers] = node.expression.arguments;\n if (callerMethod === 'attachment') {\n contentType = 'application/octet-stream';\n }\n if (!body) {\n contentType = 'empty';\n }\n callback(body, statusCode, headers, contentType);\n }\n }\n }\n return ts.forEachChild(node, handlerVisitor(callback));\n };\n};\n\nfunction toResponses(handler: ts.ArrowFunction, deriver: TypeDeriver) {\n const responsesList: ResponseItem[] = [];\n const visit = handlerVisitor((node, statusCode, headers, contentType) => {\n responsesList.push({\n headers: headers ? Object.keys(deriver.serializeNode(headers)) : [],\n contentType,\n statusCode: statusCode ? resolveStatusCode(statusCode) : '200',\n response: node ? deriver.serializeNode(node) : undefined,\n });\n });\n visit(handler.body);\n return responsesList;\n}\n\nfunction resolveStatusCode(node: ts.Node) {\n if (ts.isNumericLiteral(node)) {\n return node.text;\n }\n throw new Error(`Could not resolve status code`);\n}\n\nexport function defaultResponseAnalyzer(\n handler: ts.ArrowFunction,\n deriver: TypeDeriver,\n) {\n try {\n return toResponses(handler, deriver);\n } catch (error) {\n console.error('Error analyzing response\\n', handler.getText());\n throw error;\n }\n}\n\nexport const responseAnalyzer: NaunceResponseAnalyzer = {\n 'throw.new.ProblemDetailsException': (handler, deriver, node) => {\n if (ts.isNewExpression(node)) {\n const [problem] = node.arguments ?? [];\n if (!ts.isObjectLiteralExpression(problem)) {\n return [];\n }\n const properties = problem.properties.reduce<Record<string, string>>(\n (acc, prop) => {\n if (ts.isPropertyAssignment(prop)) {\n const key = prop.name.getText();\n if (ts.isLiteralExpression(prop.initializer)) {\n acc[key] = prop.initializer.text;\n } else {\n acc[key] = prop.initializer.getText();\n }\n }\n return acc;\n },\n {},\n );\n return [\n {\n contentType: 'application/problem+json',\n headers: [],\n statusCode: properties.status,\n response: problem ? deriver.serializeNode(problem) : undefined,\n },\n ];\n }\n return [];\n },\n default: defaultResponseAnalyzer,\n};\n"],
|
|
5
|
+
"mappings": ";AAAA,OAAO,WAAW;AAElB,SAAS,iBAAiB;AAC1B,OAAO,QAAQ;AAEf;AAAA,EAGE;AAAA,EAKA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAEA,IAAM,cAAc,CAAC,SAA2B;AACrD,QAAM,SAAmD,CAAC;AAE1D,QAAM,UAAsB,CAACA,UAAS;AACpC,QAAI,GAAG,iBAAiBA,KAAI,GAAG;AAC7B,UAAI,GAAG,gBAAgBA,MAAK,UAAU,GAAG;AACvC,eAAO,KAAK;AAAA,UACV,OAAO,aAAaA,MAAK,WAAW,WAAW,QAAQ,CAAC;AAAA,UACxD,MAAMA,MAAK;AAAA,QACb,CAAC;AAAA,MACH;AAAA,IACF;AAEA,QAAI,GAAG,kBAAkBA,KAAI,KAAKA,MAAK,YAAY;AACjD,UAAI,GAAG,iBAAiBA,MAAK,UAAU,GAAG;AACxC,eAAO,KAAK;AAAA,UACV,OAAOA,MAAK,WAAW,WAAW,QAAQ;AAAA,UAC1C,MAAMA,MAAK;AAAA,QACb,CAAC;AAAA,MACH;AACA,aAAO;AAAA,IACT;AAEA,WAAO,GAAG,aAAaA,OAAM,OAAO;AAAA,EACtC;AAEA,KAAG,aAAa,MAAM,OAAO;AAC7B,SAAO;AACT;AAEA,IAAM,SAAS,MAAM,iBAAiB;AAEtC,IAAM,aAAa,CAAC,WAAW,QAAQ,aAAa;AAEpD,SAAS,kBAAkB,MAAe;AACxC,MAAI,OAAiB,CAAC;AACtB,MAAI,OAAO;AACX,MAAI,cAAc;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O,IAAI;AAAA,QACvD;AAAA,MACF;AAAA,IACF;AACA,WAAO,CAAC;AAAA,EACV;AAAA,EACA,SAAS;AACX;",
|
|
6
6
|
"names": ["node", "tag", "responseAnalyzer", "prop", "ts", "visit"]
|
|
7
7
|
}
|
package/dist/lib/generic.d.ts
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
import type { ComponentsObject } from 'openapi3-ts/oas31';
|
|
2
2
|
import ts from 'typescript';
|
|
3
|
-
import { type
|
|
4
|
-
export declare const returnToken: (node: ts.ArrowFunction) =>
|
|
5
|
-
|
|
6
|
-
|
|
3
|
+
import { type NaunceResponseAnalyzer, type OnOperation, type ResponseAnalyzerFn } from '@sdk-it/core';
|
|
4
|
+
export declare const returnToken: (node: ts.ArrowFunction) => {
|
|
5
|
+
token: string;
|
|
6
|
+
node: ts.Expression;
|
|
7
|
+
}[];
|
|
7
8
|
export declare function analyze(tsconfigPath: string, config: {
|
|
8
9
|
/**
|
|
9
10
|
* Additional code to inject before resolving zod schemas
|
|
10
11
|
*/
|
|
11
12
|
commonZodImport?: string;
|
|
12
|
-
responseAnalyzer:
|
|
13
|
+
responseAnalyzer: ResponseAnalyzerFn | NaunceResponseAnalyzer;
|
|
13
14
|
onOperation?: OnOperation;
|
|
14
15
|
}): Promise<{
|
|
15
16
|
paths: import("openapi3-ts/oas31").PathsObject;
|
|
16
17
|
components: ComponentsObject;
|
|
17
18
|
}>;
|
|
18
19
|
export type Serialized = ReturnType<typeof analyze>;
|
|
19
|
-
export {};
|
|
20
20
|
//# sourceMappingURL=generic.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generic.d.ts","sourceRoot":"","sources":["../../src/lib/generic.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAE1D,OAAO,EAAE,MAAM,YAAY,CAAC;AAE5B,OAAO,EACL,KAAK,WAAW,EAEhB,KAAK,
|
|
1
|
+
{"version":3,"file":"generic.d.ts","sourceRoot":"","sources":["../../src/lib/generic.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAE1D,OAAO,EAAE,MAAM,YAAY,CAAC;AAE5B,OAAO,EACL,KAAK,sBAAsB,EAC3B,KAAK,WAAW,EAEhB,KAAK,kBAAkB,EASxB,MAAM,cAAc,CAAC;AAEtB,eAAO,MAAM,WAAW,SAAU,EAAE,CAAC,aAAa;WACzB,MAAM;UAAQ,EAAE,CAAC,UAAU;GA2BnD,CAAC;AAkJF,wBAAsB,OAAO,CAC3B,YAAY,EAAE,MAAM,EACpB,MAAM,EAAE;IACN;;OAEG;IACH,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,gBAAgB,EAAE,kBAAkB,GAAG,sBAAsB,CAAC;IAC9D,WAAW,CAAC,EAAE,WAAW,CAAC;CAC3B;;;GA+CF;AAED,MAAM,MAAM,UAAU,GAAG,UAAU,CAAC,OAAO,OAAO,CAAC,CAAC"}
|
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
import ts from 'typescript';
|
|
2
|
-
import type { ResponseItem, TypeDeriver } from '@sdk-it/core';
|
|
2
|
+
import type { NaunceResponseAnalyzer, ResponseItem, TypeDeriver } from '@sdk-it/core';
|
|
3
3
|
export declare function defaultResponseAnalyzer(handler: ts.ArrowFunction, deriver: TypeDeriver): ResponseItem[];
|
|
4
|
-
export declare const responseAnalyzer:
|
|
5
|
-
default: typeof defaultResponseAnalyzer;
|
|
6
|
-
};
|
|
4
|
+
export declare const responseAnalyzer: NaunceResponseAnalyzer;
|
|
7
5
|
//# sourceMappingURL=response-analyzer.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"response-analyzer.d.ts","sourceRoot":"","sources":["../../src/lib/response-analyzer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,YAAY,CAAC;AAE5B,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"response-analyzer.d.ts","sourceRoot":"","sources":["../../src/lib/response-analyzer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,YAAY,CAAC;AAE5B,OAAO,KAAK,EACV,sBAAsB,EACtB,YAAY,EACZ,WAAW,EACZ,MAAM,cAAc,CAAC;AA2DtB,wBAAgB,uBAAuB,CACrC,OAAO,EAAE,EAAE,CAAC,aAAa,EACzB,OAAO,EAAE,WAAW,kBAQrB;AAED,eAAO,MAAM,gBAAgB,EAAE,sBAiC9B,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sdk-it/generic",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.10.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.js",
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
"!**/*.tsbuildinfo"
|
|
22
22
|
],
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@sdk-it/core": "0.
|
|
24
|
+
"@sdk-it/core": "0.10.0",
|
|
25
25
|
"stringcase": "^4.3.1",
|
|
26
26
|
"typescript": "^5.7.2",
|
|
27
27
|
"debug": "^4.4.0",
|