react-query-lightbase-codegen 1.0.2 → 1.0.5

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.
@@ -0,0 +1,81 @@
1
+ import chalk from 'chalk';
2
+ import { readFileSync, writeFileSync, readdir, mkdirSync } from 'fs';
3
+ import { join, parse } from 'path';
4
+ import { convertSwaggerFile } from './convertSwaggerFile.js';
5
+ import { createHook } from './generateHooks.js';
6
+ import { generateImports } from './generateImports.js';
7
+ import { generateSchemas } from './generateSchemas.js';
8
+ export function importSpecs({ sourceDirectory, exportDirectory, apiDirectory, queryClientDir, headerFilters, overrides, }) {
9
+ readdir(sourceDirectory, function (err, filenames) {
10
+ if (err) {
11
+ console.log(err);
12
+ throw err;
13
+ }
14
+ filenames.map(async (filename) => {
15
+ try {
16
+ const data = readFileSync(join(process.cwd(), sourceDirectory + '/' + filename), 'utf-8');
17
+ const { ext } = parse(sourceDirectory + '/' + filename);
18
+ const format = ['.yaml', '.yml'].includes(ext.toLowerCase()) ? 'yaml' : 'json';
19
+ let spec = await convertSwaggerFile(data, format);
20
+ const schemaName = `useQueries${filename.split('.')[0]}.schema`;
21
+ const hooksName = `useQueries${filename.split('.')[0]}`;
22
+ const name = filename.split('.')[0];
23
+ mkdirSync(join(process.cwd(), `${exportDirectory}/${name}`), { recursive: true });
24
+ const operationIds = [];
25
+ let hooks = '';
26
+ let schemaImportsArray = [];
27
+ let collectedQueryImports = [];
28
+ Object.entries(spec.paths).forEach(([route, verbs]) => {
29
+ Object.entries(verbs).forEach(([verb, operation]) => {
30
+ if (['get', 'post', 'patch', 'put', 'delete'].includes(verb) && !operation.deprecated) {
31
+ const { implementation, imports, queryImports } = createHook({
32
+ operation,
33
+ verb,
34
+ route: (spec.basePath || '') + route,
35
+ operationIds,
36
+ parameters: verbs.parameters,
37
+ schemasComponents: spec.components,
38
+ headerFilters,
39
+ overrides,
40
+ });
41
+ hooks += implementation;
42
+ imports.forEach((element) => {
43
+ const formattedImport = element.replace('[]', '');
44
+ if (!schemaImportsArray.includes(formattedImport) &&
45
+ element !== 'void' &&
46
+ element !== 'string' &&
47
+ !element.includes('{')) {
48
+ schemaImportsArray.push(formattedImport);
49
+ }
50
+ });
51
+ queryImports.forEach((element) => {
52
+ if (!schemaImportsArray.includes(element)) {
53
+ collectedQueryImports.push(element);
54
+ }
55
+ });
56
+ }
57
+ });
58
+ });
59
+ const imports = generateImports({
60
+ apiDirectory,
61
+ queryClientDir,
62
+ schemaName,
63
+ schemaImports: schemaImportsArray,
64
+ queryImports: collectedQueryImports,
65
+ });
66
+ writeFileSync(join(process.cwd(), `${exportDirectory}/${name}/${hooksName}.tsx`), imports + hooks);
67
+ const schemas = generateSchemas({ spec });
68
+ writeFileSync(join(process.cwd(), `${exportDirectory}/${name}/${schemaName}.tsx`), schemas);
69
+ console.log(chalk.green(`🎉 [${filename}] Your OpenAPI spec has been converted into react query hooks`));
70
+ }
71
+ catch (error) {
72
+ if (error.code === 'EISDIR') {
73
+ console.log(chalk.red('nested folder structure not supported'));
74
+ return;
75
+ }
76
+ console.log(chalk.red(`[${filename}]:`), chalk.red(error));
77
+ }
78
+ });
79
+ });
80
+ }
81
+ //# sourceMappingURL=importSpecs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"importSpecs.js","sourceRoot":"","sources":["../src/importSpecs.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,IAAI,CAAC;AAErE,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,MAAM,CAAC;AACnC,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAC7D,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAChD,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB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CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC"}
@@ -0,0 +1,3 @@
1
+ import { convertSwaggerFile } from './convertSwaggerFile.js';
2
+ import { importSpecs } from './importSpecs.js';
3
+ export { importSpecs, convertSwaggerFile };
package/dist/index.js ADDED
@@ -0,0 +1,4 @@
1
+ import { convertSwaggerFile } from './convertSwaggerFile.js';
2
+ import { importSpecs } from './importSpecs.js';
3
+ export { importSpecs, convertSwaggerFile };
4
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAC7D,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAE,WAAW,EAAE,kBAAkB,EAAE,CAAC"}
@@ -0,0 +1,24 @@
1
+ import { ReferenceObject, RequestBodyObject, ResponseObject, SchemaObject } from 'openapi3-ts';
2
+ export declare const getDocs: (data: ReferenceObject | {
3
+ description?: string;
4
+ }) => string;
5
+ /**
6
+ * Discriminator helper for `ReferenceObject`
7
+ */
8
+ export declare const isReference: (property: any) => property is ReferenceObject;
9
+ /**
10
+ * Return the typescript equivalent of open-api data type
11
+ */
12
+ export declare const getScalar: (item: SchemaObject) => string;
13
+ /**
14
+ * Resolve the value of a schema object to a proper type definition.
15
+ */
16
+ export declare const resolveValue: (schema: SchemaObject) => string;
17
+ /**
18
+ * Format a description to code documentation.
19
+ */
20
+ export declare const formatDescription: (description?: string) => string;
21
+ /**
22
+ * Extract responses / request types from open-api specs
23
+ */
24
+ export declare const getResReqTypes: (responsesOrRequests: Array<[string, ResponseObject | ReferenceObject | RequestBodyObject]>) => string;
package/dist/utils.js ADDED
@@ -0,0 +1,157 @@
1
+ import lodash from 'lodash';
2
+ const { uniq, isEmpty } = lodash;
3
+ import pasCase from 'case';
4
+ const { pascal } = pasCase;
5
+ export const getDocs = (data) => isReference(data) ? '' : formatDescription(data.description);
6
+ /**
7
+ * Discriminator helper for `ReferenceObject`
8
+ */
9
+ export const isReference = (property) => {
10
+ return Boolean(property.$ref);
11
+ };
12
+ /**
13
+ * Return the typescript equivalent of open-api data type
14
+ */
15
+ export const getScalar = (item) => {
16
+ const nullable = item.nullable ? ' | null' : '';
17
+ switch (item.type) {
18
+ case 'number':
19
+ case 'integer':
20
+ return 'number' + nullable;
21
+ case 'boolean':
22
+ return 'boolean' + nullable;
23
+ case 'array':
24
+ return getArray(item) + nullable;
25
+ case 'string':
26
+ return (item.enum ? `"${item.enum.join(`" | "`)}"` : 'string') + nullable;
27
+ case 'object':
28
+ default:
29
+ return getObject(item) + nullable;
30
+ }
31
+ };
32
+ /**
33
+ * Return the output type from the $ref
34
+ */
35
+ const getRef = ($ref) => {
36
+ if ($ref.startsWith('#/components/schemas')) {
37
+ return pascal($ref.replace('#/components/schemas/', ''));
38
+ }
39
+ else if ($ref.startsWith('#/components/responses')) {
40
+ return pascal($ref.replace('#/components/responses/', '')) + 'Response';
41
+ }
42
+ else if ($ref.startsWith('#/components/parameters')) {
43
+ return pascal($ref.replace('#/components/parameters/', '')) + 'Parameter';
44
+ }
45
+ else if ($ref.startsWith('#/components/requestBodies')) {
46
+ return pascal($ref.replace('#/components/requestBodies/', '')) + 'RequestBody';
47
+ }
48
+ else {
49
+ throw new Error('This library only resolve $ref that are include into `#/components/*` for now');
50
+ }
51
+ };
52
+ /**
53
+ * Return the output type from an array
54
+ */
55
+ const getArray = (item) => {
56
+ if (item.items) {
57
+ if (!isReference(item.items) && (item.items.oneOf || item.items.allOf || item.items.enum)) {
58
+ return `(${resolveValue(item.items)})[]`;
59
+ }
60
+ else {
61
+ return `${resolveValue(item.items)}[]`;
62
+ }
63
+ }
64
+ else {
65
+ throw new Error('All arrays must have an `items` key define');
66
+ }
67
+ };
68
+ /**
69
+ * Return the output type from an object
70
+ */
71
+ const getObject = (item) => {
72
+ if (isReference(item)) {
73
+ return getRef(item.$ref);
74
+ }
75
+ if (item.allOf) {
76
+ return item.allOf.map(resolveValue).join(' & ');
77
+ }
78
+ if (item.oneOf) {
79
+ return item.oneOf.map(resolveValue).join(' | ');
80
+ }
81
+ if (!item.type && !item.properties && !item.additionalProperties) {
82
+ return '{}';
83
+ }
84
+ // Free form object (https://swagger.io/docs/specification/data-models/data-types/#free-form)
85
+ if (item.type === 'object' &&
86
+ !item.properties &&
87
+ (!item.additionalProperties || item.additionalProperties === true || isEmpty(item.additionalProperties))) {
88
+ return '{[key: string]: any}';
89
+ }
90
+ const IdentifierRegexp = /^[a-zA-Z_$][a-zA-Z0-9_$]*$/;
91
+ // Consolidation of item.properties & item.additionalProperties
92
+ let output = '{\n';
93
+ if (item.properties) {
94
+ output += Object.entries(item.properties)
95
+ .map(([key, prop]) => {
96
+ const doc = getDocs(prop);
97
+ const isRequired = (item.required || []).includes(key);
98
+ const processedKey = IdentifierRegexp.test(key) ? key : `"${key}"`;
99
+ return `${doc}\n${processedKey}${isRequired ? '' : '?'}: ${resolveValue(prop)};`;
100
+ })
101
+ .join('');
102
+ }
103
+ if (item.additionalProperties) {
104
+ if (item.properties) {
105
+ output += '\n';
106
+ }
107
+ output += `} & { [key: string]: ${item.additionalProperties === true ? 'any' : resolveValue(item.additionalProperties)}`;
108
+ }
109
+ if (item.properties || item.additionalProperties) {
110
+ if (output === '{\n') {
111
+ return '{}';
112
+ }
113
+ return output + '\n}';
114
+ }
115
+ return item.type === 'object' ? '{[key: string]: any}' : 'any';
116
+ };
117
+ /**
118
+ * Resolve the value of a schema object to a proper type definition.
119
+ */
120
+ export const resolveValue = (schema) => isReference(schema) ? getRef(schema.$ref) : getScalar(schema);
121
+ /**
122
+ * Format a description to code documentation.
123
+ */
124
+ export const formatDescription = (description) => {
125
+ if (!description) {
126
+ return '';
127
+ }
128
+ return `\n/**\n${description
129
+ .split('\n')
130
+ .map((i) => `* ${i}`)
131
+ .join('\n')}\n */`;
132
+ };
133
+ /**
134
+ * Extract responses / request types from open-api specs
135
+ */
136
+ export const getResReqTypes = (responsesOrRequests) => {
137
+ return uniq(responsesOrRequests.map(([_, res]) => {
138
+ if (!res) {
139
+ return;
140
+ }
141
+ if (isReference(res)) {
142
+ return getRef(res.$ref);
143
+ }
144
+ if (res.content) {
145
+ for (let contentType of Object.keys(res.content)) {
146
+ if (contentType.startsWith('application/json') ||
147
+ contentType.startsWith('application/octet-stream')) {
148
+ const schema = res.content[contentType].schema;
149
+ return resolveValue(schema);
150
+ }
151
+ }
152
+ return;
153
+ }
154
+ return;
155
+ })).join(' | ');
156
+ };
157
+ //# sourceMappingURL=utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,QAAQ,CAAC;AAC5B,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,GAAG,MAAM,CAAC;AACjC,OAAO,OAAO,MAAM,MAAM,CAAC;AAE3B,MAAM,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC;AAI3B,MAAM,CAAC,MAAM,OAAO,GAAG,CAAC,IAAgD,EAAE,EAAE,CAC1E,WAAW,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,iBAAiB,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;AAC/D;;GAEG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,QAAa,EAA+B,EAAE;IACxE,OAAO,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;AAChC,CAAC,CAAC;AAEF;;GAEG;AACH,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,IAAkB,EAAE,EAAE;IAC9C,MAAM,QAAQ,GAAG,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC;IAEhD,QAAQ,IAAI,CAAC,IAAI,EAAE;QACjB,KAAK,QAAQ,CAAC;QACd,KAAK,SAAS;YACZ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,EAClD;oBACA,MAAM,MAAM,GAAG,GAAG,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC,MAAO,CAAC;oBAEhD,OAAO,YAAY,CAAC,MAAM,CAAC,CAAC;iBAC7B;aACF;YACD,OAAO;SACR;QAED,OAAO;IACT,CAAC,CAAC,CACH,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;AAChB,CAAC,CAAC"}
package/package.json CHANGED
@@ -1,12 +1,13 @@
1
1
  {
2
2
  "name": "react-query-lightbase-codegen",
3
3
  "description": "Fully typed react query code generation tool based on openApi specifications",
4
- "version": "1.0.2",
4
+ "version": "1.0.5",
5
5
  "license": "MIT",
6
6
  "type": "module",
7
7
  "exports": "./dist/index.js",
8
8
  "files": [
9
- "lib/"
9
+ "src",
10
+ "dist"
10
11
  ],
11
12
  "keywords": [
12
13
  "rest",
@@ -37,6 +38,7 @@
37
38
  "lint": "eslint . --ext .js,.jsx,.ts,.tsx",
38
39
  "tsc": "tsc -p tsconfig.json",
39
40
  "test": "yarn tsc && node test/script.mjs && prettier --check ./test/generated/**/*.tsx --write && eslint ./test/generated/**/*.tsx --fix",
41
+ "deploy": "tsc && semantic-release --no-ci",
40
42
  "prepare": "husky install"
41
43
  },
42
44
  "dependencies": {
@@ -0,0 +1,25 @@
1
+ import { OpenAPIObject } from 'openapi3-ts';
2
+ import swagger2openapi from 'swagger2openapi';
3
+ import yaml from 'js-yaml';
4
+
5
+ /**
6
+ * Import and parse the openapi spec from a yaml/json
7
+ */
8
+ export const convertSwaggerFile = (data: string, extension: 'yaml' | 'json'): Promise<OpenAPIObject> => {
9
+ const schema = extension === 'yaml' ? yaml.load(data) : JSON.parse(data);
10
+ return new Promise((resolve, reject) => {
11
+ if (!schema.openapi || !schema.openapi.startsWith('3.')) {
12
+ swagger2openapi.convertObj(schema, {}, (err, convertedObj) => {
13
+ if (err) {
14
+ reject(err);
15
+ } else {
16
+ // @ts-ignore
17
+ convertedObj.openapi.basePath = convertedObj.original.basePath;
18
+ resolve(convertedObj.openapi);
19
+ }
20
+ });
21
+ } else {
22
+ resolve(schema);
23
+ }
24
+ });
25
+ };