ts-openapi-codegen 1.0.0-beta.4 → 1.0.0-beta.6

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.
Files changed (92) hide show
  1. package/README.md +35 -1
  2. package/dist/cli/chekOpenApiConfig/chekOpenApiConfig.d.ts +5 -0
  3. package/dist/cli/chekOpenApiConfig/chekOpenApiConfig.d.ts.map +1 -0
  4. package/dist/cli/chekOpenApiConfig/chekOpenApiConfig.js +40 -0
  5. package/dist/cli/index.js +47 -5
  6. package/dist/cli/utils.d.ts +5 -0
  7. package/dist/cli/utils.d.ts.map +1 -1
  8. package/dist/cli/utils.js +22 -0
  9. package/dist/common/Options.d.ts +1 -0
  10. package/dist/common/Options.d.ts.map +1 -1
  11. package/dist/common/UpdateNotifier.d.ts +24 -0
  12. package/dist/common/UpdateNotifier.d.ts.map +1 -0
  13. package/dist/common/UpdateNotifier.js +120 -0
  14. package/dist/common/__tests__/mergeObjectSchemas.test.js +1 -1
  15. package/dist/core/Context.d.ts +10 -1
  16. package/dist/core/Context.d.ts.map +1 -1
  17. package/dist/core/Context.js +8 -1
  18. package/dist/core/{utils/writeClient.d.ts → WriteClient.d.ts} +13 -6
  19. package/dist/core/WriteClient.d.ts.map +1 -0
  20. package/dist/core/{utils/writeClient.js → WriteClient.js} +69 -78
  21. package/dist/core/__tests__/WriteClient.test.d.ts +2 -0
  22. package/dist/core/__tests__/WriteClient.test.d.ts.map +1 -0
  23. package/dist/core/{utils/__tests__/writeClient.test.js → __tests__/WriteClient.test.js} +8 -8
  24. package/dist/core/api/v2/parser/__tests__/getType.test.js +3 -3
  25. package/dist/core/api/v2/parser/getOperationParameters.d.ts.map +1 -1
  26. package/dist/core/api/v2/parser/getOperationParameters.js +9 -7
  27. package/dist/core/api/v3/parser/__tests__/getType.test.js +3 -3
  28. package/dist/core/api/v3/parser/getOperation.d.ts.map +1 -1
  29. package/dist/core/api/v3/parser/getOperation.js +4 -2
  30. package/dist/core/api/v3/parser/getOperationParameters.d.ts.map +1 -1
  31. package/dist/core/api/v3/parser/getOperationParameters.js +9 -7
  32. package/dist/core/index.d.ts.map +1 -1
  33. package/dist/core/index.js +5 -4
  34. package/dist/core/types/Consts.d.ts +10 -0
  35. package/dist/core/types/Consts.d.ts.map +1 -1
  36. package/dist/core/types/Consts.js +11 -1
  37. package/dist/core/types/Models.d.ts +3 -0
  38. package/dist/core/types/Models.d.ts.map +1 -1
  39. package/dist/core/utils/__mocks__/createOperationParameter.d.ts +3 -0
  40. package/dist/core/utils/__mocks__/createOperationParameter.d.ts.map +1 -0
  41. package/dist/core/utils/__mocks__/createOperationParameter.js +28 -0
  42. package/dist/core/utils/__tests__/sortByRequiredExtended.test.d.ts +2 -0
  43. package/dist/core/utils/__tests__/sortByRequiredExtended.test.d.ts.map +1 -0
  44. package/dist/core/utils/__tests__/sortByRequiredExtended.test.js +145 -0
  45. package/dist/core/utils/__tests__/sortByRequiredSimple.test.d.ts +2 -0
  46. package/dist/core/utils/__tests__/sortByRequiredSimple.test.d.ts.map +1 -0
  47. package/dist/core/utils/__tests__/sortByRequiredSimple.test.js +80 -0
  48. package/dist/core/utils/__tests__/writeClientCore.test.js +2 -2
  49. package/dist/core/utils/__tests__/writeClientIndex.test.js +2 -2
  50. package/dist/core/utils/__tests__/writeClientModels.test.js +2 -2
  51. package/dist/core/utils/__tests__/writeClientSchemas.test.js +2 -2
  52. package/dist/core/utils/__tests__/writeClientServices.test.js +2 -2
  53. package/dist/core/utils/getOpenApiSpec.d.ts.map +1 -1
  54. package/dist/core/utils/getOpenApiSpec.js +0 -7
  55. package/dist/core/utils/getPropertyGroupExtended.d.ts +4 -0
  56. package/dist/core/utils/getPropertyGroupExtended.d.ts.map +1 -0
  57. package/dist/core/utils/getPropertyGroupExtended.js +10 -0
  58. package/dist/core/utils/getPropertyGroupSimple.d.ts +3 -0
  59. package/dist/core/utils/getPropertyGroupSimple.d.ts.map +1 -0
  60. package/dist/core/utils/getPropertyGroupSimple.js +9 -0
  61. package/dist/core/utils/precompileTemplates.js +1 -1
  62. package/dist/core/utils/prepareAlias.d.ts +7 -0
  63. package/dist/core/utils/prepareAlias.d.ts.map +1 -0
  64. package/dist/core/utils/prepareAlias.js +24 -0
  65. package/dist/core/utils/registerHandlebarTemplates.d.ts.map +1 -1
  66. package/dist/core/utils/registerHandlebarTemplates.js +2 -0
  67. package/dist/core/utils/sortByRequiredExtended.d.ts +3 -0
  68. package/dist/core/utils/sortByRequiredExtended.d.ts.map +1 -0
  69. package/dist/core/utils/sortByRequiredExtended.js +15 -0
  70. package/dist/core/utils/sortByRequiredSimple.d.ts +3 -0
  71. package/dist/core/utils/sortByRequiredSimple.d.ts.map +1 -0
  72. package/dist/core/utils/sortByRequiredSimple.js +10 -0
  73. package/dist/core/utils/sortModelByName.d.ts +3 -0
  74. package/dist/core/utils/sortModelByName.d.ts.map +1 -0
  75. package/dist/core/utils/sortModelByName.js +12 -0
  76. package/dist/templatesCompiled/partials/isReadOnly.d.ts +1 -1
  77. package/dist/templatesCompiled/partials/isReadOnly.d.ts.map +1 -1
  78. package/dist/templatesCompiled/partials/isReadOnly.js +1 -2
  79. package/dist/templatesCompiled/partials/isRequiredDefinition.d.ts +9 -0
  80. package/dist/templatesCompiled/partials/isRequiredDefinition.d.ts.map +1 -0
  81. package/dist/templatesCompiled/partials/isRequiredDefinition.js +27 -0
  82. package/dist/templatesCompiled/partials/parametersDefinition.js +1 -1
  83. package/package.json +9 -1
  84. package/dist/core/utils/__tests__/sortByRequired.test.d.ts +0 -2
  85. package/dist/core/utils/__tests__/sortByRequired.test.d.ts.map +0 -1
  86. package/dist/core/utils/__tests__/sortByRequired.test.js +0 -108
  87. package/dist/core/utils/__tests__/writeClient.test.d.ts +0 -2
  88. package/dist/core/utils/__tests__/writeClient.test.d.ts.map +0 -1
  89. package/dist/core/utils/sortByRequired.d.ts +0 -3
  90. package/dist/core/utils/sortByRequired.d.ts.map +0 -1
  91. package/dist/core/utils/sortByRequired.js +0 -18
  92. package/dist/core/utils/writeClient.d.ts.map +0 -1
package/README.md CHANGED
@@ -57,7 +57,7 @@ $ openapi --help
57
57
  -os, --outputServices <value> Output directory for services
58
58
  -om, --outputModels <value> Output directory for models
59
59
  -osm, --outputSchemas <value> Output directory for schemas
60
- -c, --client <value> HTTP client to generate [fetch, xhr, node] (default: "fetch")
60
+ -c, --httpClient <value> HTTP client to generate [fetch, xhr, node] (default: "fetch")
61
61
  --useOptions <value> Use options instead of arguments (default: false)
62
62
  --useUnionTypes <value> Use union types instead of enums (default: false)
63
63
  --exportCore <value> Write core files to disk (default: true)
@@ -69,6 +69,7 @@ $ openapi --help
69
69
  --enumPrefix <value> Prefix for enum model(default: "E")
70
70
  --typePrefix <value> Prefix for type model(default: "T")
71
71
  --useCancelableRequest Use cancelled promise as returned data type in request(default: false)
72
+ -s, --sortByRequired Property sorting strategy: simplified or extended
72
73
 
73
74
  Examples
74
75
  $ openapi --input ./spec.json
@@ -389,6 +390,39 @@ const MyForm = () => (
389
390
 
390
391
  ```
391
392
 
393
+ ### Cancelable promise `--useCancelableRequest`
394
+ By default, the OpenAPI generator generates services for accessing the API that use non-cancellable requests. Therefore, we have added the ability to switch the generator to generate canceled API requests. To do this, use the flag `--useCancelableRequest`.
395
+ An example of a cancelled request would look like this:
396
+
397
+ ```typescript
398
+ export function request<T>(config: TOpenAPIConfig, options: ApiRequestOptions): CancelablePromise<T> {
399
+ return new CancelablePromise(async(resolve, reject, onCancel) => {
400
+ const url = `${config.BASE}${options.path}`.replace('{api-version}', config.VERSION);
401
+ try {
402
+ if (!onCancel.isCancelled) {
403
+ const response = await sendRequest(options, url, config, onCancel);
404
+ const responseBody = await getResponseBody(response);
405
+ const responseHeader = getResponseHeader(response, options.responseHeader);
406
+ const result: ApiResult = {
407
+ url,
408
+ ok: response.ok,
409
+ status: response.status,
410
+ statusText: response.statusText,
411
+ body: responseHeader || responseBody,
412
+ };
413
+
414
+ catchErrors(options, result);
415
+ resolve(result.body);
416
+ }
417
+ } catch (e) {
418
+ reject(e);
419
+ }
420
+ });
421
+ }
422
+ ```
423
+
424
+ ### Sorting strategy for function arguments `--sortByRequired`
425
+ By default, the OpenAPI generator sorts the parameters of service functions according to a simplified scheme. If you need a more strict sorting option, then you need to use the sortByRequired flag. The simplified sorting option is similar to the one used in version 0.2.3 of the OpenAPI generator. This flag allows you to upgrade to a new version of the generator if you are "stuck" on version 0.2.3.
392
426
 
393
427
  ### Enum with custom names and descriptions
394
428
  You can use `x-enum-varnames` and `x-enum-descriptions` in your spec to generate enum with custom names and descriptions.
@@ -0,0 +1,5 @@
1
+ /**
2
+ * The function checks whether the configuration file data is filled in correctly
3
+ */
4
+ export declare function chekOpenApiConfig(): void;
5
+ //# sourceMappingURL=chekOpenApiConfig.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"chekOpenApiConfig.d.ts","sourceRoot":"","sources":["../../../src/cli/chekOpenApiConfig/chekOpenApiConfig.ts"],"names":[],"mappings":"AAQA;;GAEG;AACH,wBAAgB,iBAAiB,SA4BhC"}
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.chekOpenApiConfig = chekOpenApiConfig;
4
+ const Enums_1 = require("../../common/Enums");
5
+ const Logger_1 = require("../../common/Logger");
6
+ const Utils_1 = require("../../common/Utils");
7
+ const MultiOptionsVersionedSchemas_1 = require("../../common/VersionedSchema/MultiOptionsVersionedSchemas");
8
+ const OptionsVersionedSchemas_1 = require("../../common/VersionedSchema/OptionsVersionedSchemas");
9
+ const getErrorFieldsFromValidation_1 = require("../../common/VersionedSchema/Utils/getErrorFieldsFromValidation");
10
+ const isInstanceOfMultiOptions_1 = require("../../core/utils/isInstanceOfMultiOptions");
11
+ /**
12
+ * The function checks whether the configuration file data is filled in correctly
13
+ */
14
+ function chekOpenApiConfig() {
15
+ const logger = new Logger_1.Logger({
16
+ level: Enums_1.ELogLevel.INFO,
17
+ instanceId: 'check-openapi-config',
18
+ logOutput: Enums_1.ELogOutput.CONSOLE,
19
+ });
20
+ try {
21
+ const configData = (0, Utils_1.loadConfigIfExists)();
22
+ if (!configData) {
23
+ logger.error('The configuration file is missing');
24
+ }
25
+ const preparedOptions = (0, Utils_1.convertArrayToObject)(configData);
26
+ const isMultiOptions = (0, isInstanceOfMultiOptions_1.isInstanceOfMultioptions)(preparedOptions);
27
+ const currentMigrationPlan = isMultiOptions ? MultiOptionsVersionedSchemas_1.multiOptionsVersionedSchema : OptionsVersionedSchemas_1.optionsVersionedSchemas;
28
+ const currentSchema = currentMigrationPlan
29
+ .map((sch, idx) => ({ ...sch, index: idx + 1 }))
30
+ .reduce((prev, curr) => (curr.index > prev.index ? curr : prev));
31
+ const { error } = currentSchema.schema.validate(preparedOptions);
32
+ if (error) {
33
+ const details = (0, getErrorFieldsFromValidation_1.getErrorFieldsFromValidation)(error).map((e) => `${e.path}: ${e.type}`).join(',');
34
+ logger.error(`The configuration file data is specified incorrectly: ${details}`);
35
+ }
36
+ }
37
+ catch (error) {
38
+ logger.error(error.message);
39
+ }
40
+ }
package/dist/cli/index.js CHANGED
@@ -1,17 +1,30 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
6
  const commander_1 = require("commander");
7
+ const fs_1 = __importDefault(require("fs"));
8
+ const path_1 = __importDefault(require("path"));
4
9
  const Enums_1 = require("../common/Enums");
10
+ const Logger_1 = require("../common/Logger");
11
+ const UpdateNotifier_1 = require("../common/UpdateNotifier");
5
12
  const Enums_2 = require("../core/types/Enums");
13
+ const chekOpenApiConfig_1 = require("./chekOpenApiConfig/chekOpenApiConfig");
6
14
  const runGenerateOpenApi_1 = require("./generate/runGenerateOpenApi");
7
- const APP_NAME = 'ts-openapi-codegen-cli';
8
- const APP_VERSION = '1.0.0';
15
+ const utils_1 = require("./utils");
16
+ const packageDetails = JSON.parse(fs_1.default.readFileSync(path_1.default.join(__dirname, '../../package.json'), 'utf-8'));
17
+ const APP_NAME = packageDetails.name || 'ts-openapi-codegen-cli';
18
+ const APP_VERSION = packageDetails.version || '1.0.0';
19
+ const APP_DESCRIPTION = packageDetails.description || 'Description';
20
+ const updateNotifier = new UpdateNotifier_1.UpdateNotifier(APP_NAME, APP_VERSION);
9
21
  const program = new commander_1.Command();
10
- program.version(APP_VERSION).name(APP_NAME).description('Описание').addHelpText('before', 'Дополнительный текст');
22
+ program.version(APP_VERSION).name(APP_NAME).description(APP_DESCRIPTION).addHelpText('before', (0, utils_1.getCLIName)(APP_NAME));
11
23
  program
12
24
  .command('generate')
25
+ .description('Starts code generation based on the provided opeanpi specifications')
26
+ .addHelpText('before', (0, utils_1.getCLIName)(APP_NAME))
13
27
  .usage('[options]')
14
- .version(APP_VERSION)
15
28
  .option('-i, --input <value>', 'OpenAPI specification, can be a path, url or string content (required)', '')
16
29
  .option('-o, --output <value>', 'Output directory (required)', '')
17
30
  .option('-oc, --outputCore <value>', 'Output directory for core files')
@@ -33,7 +46,36 @@ program
33
46
  .option('--useCancelableRequest <value>', 'Use cancelled promise as returned data type in request(default: false)', false)
34
47
  .addOption(new commander_1.Option('-l, --logLevel <level>', 'Logging level').choices([...Object.values(Enums_1.ELogLevel)]).default(Enums_1.ELogLevel.ERROR))
35
48
  .addOption(new commander_1.Option('-t, --logTarget <target>', 'Target of logging').choices([...Object.values(Enums_1.ELogOutput)]).default(Enums_1.ELogOutput.CONSOLE))
49
+ .option('-s, --sortByRequired', 'Property sorting strategy: simplified or extended')
50
+ .hook('preAction', () => {
51
+ updateNotifier.checkAndNotify();
52
+ })
36
53
  .action(async (options) => {
37
54
  await (0, runGenerateOpenApi_1.runGenerateOpenApi)(options);
38
55
  });
39
- program.parse(process.argv);
56
+ program
57
+ .command('check-openapi-config')
58
+ .description('Starts checking whether the configuration file data is filled in correctly.')
59
+ .addHelpText('before', (0, utils_1.getCLIName)(APP_NAME))
60
+ .hook('preAction', () => {
61
+ updateNotifier.checkAndNotify();
62
+ })
63
+ .action(() => {
64
+ (0, chekOpenApiConfig_1.chekOpenApiConfig)();
65
+ });
66
+ try {
67
+ program.parse(process.argv);
68
+ }
69
+ catch (error) {
70
+ if (error.code === 'commander.unknownOption') {
71
+ const errorMessage = error?.message ?? '';
72
+ if (errorMessage) {
73
+ const logger = new Logger_1.Logger({
74
+ level: Enums_1.ELogLevel.INFO,
75
+ instanceId: 'check-openapi-config',
76
+ logOutput: Enums_1.ELogOutput.CONSOLE,
77
+ });
78
+ logger.error(errorMessage);
79
+ }
80
+ }
81
+ }
@@ -16,4 +16,9 @@
16
16
  */
17
17
  export declare function isNil(value: any): boolean;
18
18
  export declare function isValidJson(value: any): boolean;
19
+ /**
20
+ * Returns the stylized package name to display in the terminal
21
+ * @param appName Package name
22
+ */
23
+ export declare function getCLIName(appName: string): string;
19
24
  //# sourceMappingURL=utils.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/cli/utils.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,KAAK,CAAC,KAAK,EAAE,GAAG,WAE/B;AAED,wBAAgB,WAAW,CAAC,KAAK,EAAE,GAAG,WAOrC"}
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/cli/utils.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,KAAK,CAAC,KAAK,EAAE,GAAG,WAE/B;AAED,wBAAgB,WAAW,CAAC,KAAK,EAAE,GAAG,WAOrC;AAED;;;GAGG;AACH,wBAAgB,UAAU,CAAC,OAAO,EAAE,MAAM,UAazC"}
package/dist/cli/utils.js CHANGED
@@ -1,7 +1,12 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
6
  exports.isNil = isNil;
4
7
  exports.isValidJson = isValidJson;
8
+ exports.getCLIName = getCLIName;
9
+ const figlet_1 = __importDefault(require("figlet"));
5
10
  /**
6
11
  * Checks if `value` is `null` or `undefined`.
7
12
  *
@@ -30,3 +35,20 @@ function isValidJson(value) {
30
35
  return false;
31
36
  }
32
37
  }
38
+ /**
39
+ * Returns the stylized package name to display in the terminal
40
+ * @param appName Package name
41
+ */
42
+ function getCLIName(appName) {
43
+ const name = figlet_1.default.textSync(appName, {
44
+ horizontalLayout: 'default',
45
+ verticalLayout: 'default',
46
+ width: 75,
47
+ whitespaceBreak: true,
48
+ });
49
+ return `
50
+
51
+ ${name}
52
+
53
+ `;
54
+ }
@@ -20,6 +20,7 @@ export type TOptions = {
20
20
  enumPrefix?: string;
21
21
  typePrefix?: string;
22
22
  useCancelableRequest?: boolean;
23
+ sortByRequired?: boolean;
23
24
  };
24
25
  export type TMultiOptions = {
25
26
  items: TOptions[];
@@ -1 +1 @@
1
- {"version":3,"file":"Options.d.ts","sourceRoot":"","sources":["../../src/common/Options.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAEjD,MAAM,MAAM,QAAQ,GAAG;IACnB,KAAK,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IACpC,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,UAAU,CAAC,EAAE,UAAU,CAAC;IACxB,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB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C;IACzB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,oBAAoB,CAAC,EAAE,OAAO,CAAC;IAC/B,cAAc,CAAC,EAAE,OAAO,CAAC;CAC5B,CAAC;AAEF,MAAM,MAAM,aAAa,GAAG;IAC1B,KAAK,EAAE,QAAQ,EAAE,CAAC;CACnB,GAAG,IAAI,CAAC,QAAQ,EAAE,OAAO,GAAG,QAAQ,CAAC,CAAC"}
@@ -0,0 +1,24 @@
1
+ /**
2
+ * A class for tracking the release of a newer version of the generator
3
+ */
4
+ export declare class UpdateNotifier {
5
+ private _packageName;
6
+ private _packageVersion;
7
+ private _configStore;
8
+ private _packageStoreInfo;
9
+ private _logger;
10
+ constructor(packageName: string, packageVersion: string);
11
+ /**
12
+ * Requests the latest version of the generator via npm
13
+ */
14
+ private fetchNpmPackageInfo;
15
+ /**
16
+ * Checks for updates and writes useful information to the cache
17
+ */
18
+ private checkUpdate;
19
+ /**
20
+ * Checks for updates and notifies about the possibility to install a new version.
21
+ */
22
+ checkAndNotify(): void;
23
+ }
24
+ //# sourceMappingURL=UpdateNotifier.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"UpdateNotifier.d.ts","sourceRoot":"","sources":["../../src/common/UpdateNotifier.ts"],"names":[],"mappings":"AAqBA;;GAEG;AACH,qBAAa,cAAc;IACvB,OAAO,CAAC,YAAY,CAAS;IAC7B,OAAO,CAAC,eAAe,CAAS;IAChC,OAAO,CAAC,YAAY,CAA4B;IAChD,OAAO,CAAC,iBAAiB,CAAkC;IAC3D,OAAO,CAAC,OAAO,CAAS;gBAEZ,WAAW,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM;IA0BvD;;OAEG;IACH,OAAO,CAAC,mBAAmB;IAkB3B;;OAEG;IACH,OAAO,CAAC,WAAW;IAwBnB;;OAEG;IACH,cAAc;CAmCjB"}
@@ -0,0 +1,120 @@
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.UpdateNotifier = void 0;
7
+ const boxen_1 = __importDefault(require("boxen"));
8
+ const chalk_1 = __importDefault(require("chalk"));
9
+ const child_process_1 = require("child_process");
10
+ const configstore_1 = __importDefault(require("configstore"));
11
+ const semver_1 = __importDefault(require("semver"));
12
+ const Enums_1 = require("./Enums");
13
+ const Logger_1 = require("./Logger");
14
+ // one week
15
+ const UPDATE_CHECK_INTERVAL = 1000 * 60 * 60 * 24 * 7;
16
+ const INCLUDED_RELEASE_TYPES = ['major', 'minor'];
17
+ /**
18
+ * A class for tracking the release of a newer version of the generator
19
+ */
20
+ class UpdateNotifier {
21
+ _packageName;
22
+ _packageVersion;
23
+ _configStore = null;
24
+ _packageStoreInfo = null;
25
+ _logger;
26
+ constructor(packageName, packageVersion) {
27
+ this._logger = new Logger_1.Logger({
28
+ instanceId: '',
29
+ level: Enums_1.ELogLevel.INFO,
30
+ logOutput: Enums_1.ELogOutput.CONSOLE,
31
+ });
32
+ if (!packageName || !packageVersion) {
33
+ this._logger.warn(`
34
+ The necessary parameters for checking the version are not specified.
35
+ Current values packageName: ${packageName}, packageVersion: ${packageVersion}
36
+ `);
37
+ }
38
+ this._packageName = packageName;
39
+ this._packageVersion = packageVersion;
40
+ try {
41
+ this._configStore = new configstore_1.default(`-${this._packageName}`, {
42
+ lastUpdateCheck: Date.now(),
43
+ });
44
+ }
45
+ catch {
46
+ this._logger.warn('The settings store has not been created. The package update will be checked more often than once every 1 week!');
47
+ }
48
+ }
49
+ /**
50
+ * Requests the latest version of the generator via npm
51
+ */
52
+ fetchNpmPackageInfo() {
53
+ try {
54
+ const latestVersion = (0, child_process_1.execSync)(`npm view ${this._packageName} version`).toString().trim();
55
+ const releaseType = semver_1.default.diff(this._packageVersion, latestVersion);
56
+ return {
57
+ currentVersion: this._packageVersion,
58
+ differenceType: releaseType,
59
+ latestVersion,
60
+ packageName: this._packageName,
61
+ };
62
+ }
63
+ catch {
64
+ this._logger.warn("Couldn't get information about the latest current version");
65
+ return null;
66
+ }
67
+ }
68
+ /**
69
+ * Checks for updates and writes useful information to the cache
70
+ */
71
+ checkUpdate() {
72
+ if (!this._configStore) {
73
+ return;
74
+ }
75
+ this._packageStoreInfo = this._configStore.get('package_store_info');
76
+ if (this._packageStoreInfo) {
77
+ this._packageStoreInfo.currentVersion = this._packageVersion;
78
+ // clean cache
79
+ this._configStore.delete('package_store_info');
80
+ }
81
+ if (Date.now() - this._configStore.get('lastUpdateCheck') < UPDATE_CHECK_INTERVAL) {
82
+ return;
83
+ }
84
+ const fetchInfo = this.fetchNpmPackageInfo();
85
+ this._configStore.set('lastUpdateCheck', Date.now());
86
+ if (fetchInfo?.differenceType && INCLUDED_RELEASE_TYPES.includes(fetchInfo.differenceType)) {
87
+ this._configStore.set('package_store_info', fetchInfo);
88
+ }
89
+ }
90
+ /**
91
+ * Checks for updates and notifies about the possibility to install a new version.
92
+ */
93
+ checkAndNotify() {
94
+ if (!this._configStore) {
95
+ this._logger.warn("Couldn't get information about the latest current version");
96
+ this._logger.shutdownLogger();
97
+ return;
98
+ }
99
+ this.checkUpdate();
100
+ if (!this._packageStoreInfo || !semver_1.default.gt(this._packageStoreInfo.latestVersion, this._packageStoreInfo.currentVersion)) {
101
+ return;
102
+ }
103
+ const { packageName, currentVersion, latestVersion } = this._packageStoreInfo;
104
+ const scriptText = chalk_1.default.yellowBright(`npm i -D ${packageName}@${latestVersion}`);
105
+ const message = `
106
+ An update is available: ${chalk_1.default.gray(currentVersion)} -> ${chalk_1.default.greenBright(latestVersion)}}
107
+ Run ${scriptText} to update
108
+ `;
109
+ console.log((0, boxen_1.default)(message, {
110
+ borderColor: 'cyanBright',
111
+ margin: 1,
112
+ padding: 1,
113
+ title: 'Pay attention',
114
+ titleAlignment: 'center',
115
+ textAlignment: 'center',
116
+ }));
117
+ this._logger.shutdownLogger();
118
+ }
119
+ }
120
+ exports.UpdateNotifier = UpdateNotifier;
@@ -27,7 +27,7 @@ const mergeObjectSchemas_1 = require("../VersionedSchema/Utils/mergeObjectSchema
27
27
  };
28
28
  const invalidData = {
29
29
  input: 'source/path',
30
- httpClient: 'invalid-client', // Некорректное значение для httpClient
30
+ httpClient: 'invalid-client',
31
31
  };
32
32
  node_assert_1.default.equal(OptionsSchemaV2_1.optionsSchemaV2.validate(validData).error, null, 'Valid data should pass optionsSchemaV2 validation');
33
33
  node_assert_1.default.notEqual(OptionsSchemaV2_1.optionsSchemaV2.validate(invalidData).error, null, 'Invalid data should fail optionsSchemaV2 validation');
@@ -1,6 +1,12 @@
1
1
  import { JSONSchema4Type, JSONSchema6Type, JSONSchema7Type } from 'json-schema';
2
2
  import RefParser from 'json-schema-ref-parser';
3
3
  import { IOutput, Prefix } from './types/Models';
4
+ type TContextProps = {
5
+ input: string | Record<string, any>;
6
+ output: IOutput;
7
+ prefix?: Prefix;
8
+ sortByRequired?: boolean;
9
+ };
4
10
  /**
5
11
  * A Context wich can share a data between methods
6
12
  */
@@ -9,7 +15,8 @@ export declare class Context {
9
15
  private _root;
10
16
  private _output;
11
17
  prefix: Prefix;
12
- constructor(input: string | Record<string, any>, output: IOutput, prefix?: Prefix);
18
+ private _sortByRequired;
19
+ constructor({ input, output, prefix, sortByRequired }: TContextProps);
13
20
  addRefs(refs: RefParser.$Refs): Context;
14
21
  values(...types: string[]): Record<string, any>;
15
22
  get($ref: string): JSONSchema4Type | JSONSchema6Type | JSONSchema7Type;
@@ -17,5 +24,7 @@ export declare class Context {
17
24
  exists($ref: string): boolean;
18
25
  fileName(): string;
19
26
  get output(): IOutput;
27
+ get sortByRequired(): boolean;
20
28
  }
29
+ export {};
21
30
  //# sourceMappingURL=Context.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"Context.d.ts","sourceRoot":"","sources":["../../src/core/Context.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,eAAe,EAAE,eAAe,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C,EAAE,OAAO,CAAC;CAC5B,CAAA;AAED;;GAEG;AACH,qBAAa,OAAO;IAChB,OAAO,CAAC,KAAK,CAA8B;IAC3C,OAAO,CAAC,KAAK,CAAoB;IACjC,OAAO,CAAC,OAAO,CAAU;IAClB,MAAM,EAAE,MAAM,CAInB;IAEF,OAAO,CAAC,eAAe,CAAkB;gBAE7B,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,cAAc,EAAE,EAAE,aAAa;IAmB7D,OAAO,CAAC,IAAI,EAAE,SAAS,CAAC,KAAK,GAAG,OAAO;IAKvC,MAAM,CAAC,GAAG,KAAK,EAAE,MAAM,EAAE,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC;IAO/C,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,eAAe,GAAG,eAAe,GAAG,eAAe;IAOtE,KAAK,CAAC,GAAG,KAAK,EAAE,MAAM,EAAE,GAAG,MAAM,EAAE;IAOnC,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO;IAO7B,QAAQ,IAAI,MAAM;IAOzB,IAAW,MAAM,YAKhB;IAED,IAAW,cAAc,YAExB;CACJ"}
@@ -16,7 +16,8 @@ class Context {
16
16
  enum: 'E',
17
17
  type: 'T',
18
18
  };
19
- constructor(input, output, prefix) {
19
+ _sortByRequired = false;
20
+ constructor({ input, output, prefix, sortByRequired }) {
20
21
  this._output = output;
21
22
  this._refs = {};
22
23
  if ((0, isString_1.isString)(input)) {
@@ -28,6 +29,9 @@ class Context {
28
29
  if (prefix) {
29
30
  this.prefix = prefix;
30
31
  }
32
+ if (sortByRequired !== undefined && sortByRequired !== null) {
33
+ this._sortByRequired = sortByRequired;
34
+ }
31
35
  return this;
32
36
  }
33
37
  addRefs(refs) {
@@ -70,5 +74,8 @@ class Context {
70
74
  }
71
75
  return this._output;
72
76
  }
77
+ get sortByRequired() {
78
+ return this._sortByRequired;
79
+ }
73
80
  }
74
81
  exports.Context = Context;
@@ -1,8 +1,8 @@
1
- import { Logger } from '../../common/Logger';
2
- import { HttpClient } from '../types/Enums';
3
- import { IOutput } from '../types/Models';
4
- import type { Client } from '../types/shared/Client.model';
5
- import { Templates } from './registerHandlebarTemplates';
1
+ import { Logger } from '../common/Logger';
2
+ import { HttpClient } from './types/Enums';
3
+ import { IOutput } from './types/Models';
4
+ import type { Client } from './types/shared/Client.model';
5
+ import { Templates } from './utils/registerHandlebarTemplates';
6
6
  /**
7
7
  * @param client Client object with all the models, services, etc.
8
8
  * @param templates Templates wrapper with all loaded Handlebars templates
@@ -84,6 +84,13 @@ export declare class WriteClient {
84
84
  writeClientIndex(options: IWriteClientIndex): Promise<void>;
85
85
  combineAndWrite(): Promise<void>;
86
86
  get logger(): Logger;
87
+ private buildClientIndexMap;
88
+ private finalizeAndWright;
89
+ private getOutputPath;
90
+ private ensureClientIndex;
91
+ private isSameModel;
92
+ private isSameShema;
93
+ private isSomeService;
87
94
  }
88
95
  export {};
89
- //# sourceMappingURL=writeClient.d.ts.map
96
+ //# sourceMappingURL=WriteClient.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"WriteClient.d.ts","sourceRoot":"","sources":["../../src/core/WriteClient.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAC1C,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AACzC,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,6BAA6B,CAAC;AAI1D,OAAO,EAAE,SAAS,EAAE,MAAM,oCAAoC,CAAC;AAU/D;;;;;;;;;;;;;;GAcG;AACH,UAAU,YAAY;IAClB,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,SAAS,CAAC;IACrB,WAAW,EAAE,OAAO,CAAC;IACrB,UAAU,EAAE,UAAU,CAAC;IACvB,UAAU,EAAE,OAAO,CAAC;IACpB,aAAa,EAAE,OAAO,CAAC;I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