ts-openapi-codegen 1.0.0-beta.2 → 1.0.0-beta.4
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/cli/generate/runGenerateOpenApi.d.ts.map +1 -1
- package/dist/cli/generate/runGenerateOpenApi.js +48 -32
- package/dist/cli/index.js +5 -1
- package/dist/cli/utils.d.ts +0 -1
- package/dist/cli/utils.d.ts.map +1 -1
- package/dist/cli/utils.js +0 -56
- package/dist/common/Enums.d.ts +10 -0
- package/dist/common/Enums.d.ts.map +1 -0
- package/dist/common/Enums.js +14 -0
- package/dist/common/Logger.d.ts +33 -0
- package/dist/common/Logger.d.ts.map +1 -0
- package/dist/common/Logger.js +117 -0
- package/dist/common/Options.d.ts +4 -4
- package/dist/common/Options.d.ts.map +1 -1
- package/dist/common/Utils.d.ts +2 -1
- package/dist/common/Utils.d.ts.map +1 -1
- package/dist/common/Utils.js +54 -0
- package/dist/common/VersionedSchema/MultiOptionsMigrationPlan.d.ts.map +1 -1
- package/dist/common/VersionedSchema/MultiOptionsMigrationPlan.js +1 -3
- package/dist/common/VersionedSchema/Types.d.ts +1 -1
- package/dist/common/VersionedSchema/Types.d.ts.map +1 -1
- package/dist/common/VersionedSchema/Utils/determineBestMatchingSchemaVersion.d.ts +9 -0
- package/dist/common/VersionedSchema/Utils/determineBestMatchingSchemaVersion.d.ts.map +1 -0
- package/dist/common/VersionedSchema/Utils/determineBestMatchingSchemaVersion.js +44 -0
- package/dist/common/VersionedSchema/Utils/generateKeyMappingForInvalidKeys.d.ts +2 -0
- package/dist/common/VersionedSchema/Utils/generateKeyMappingForInvalidKeys.d.ts.map +1 -0
- package/dist/common/VersionedSchema/Utils/generateKeyMappingForInvalidKeys.js +27 -0
- package/dist/common/VersionedSchema/Utils/getErrorFieldsFromValidation.d.ts +6 -0
- package/dist/common/VersionedSchema/Utils/getErrorFieldsFromValidation.d.ts.map +1 -0
- package/dist/common/VersionedSchema/Utils/getErrorFieldsFromValidation.js +7 -0
- package/dist/common/VersionedSchema/Utils/getUniqueKeysFromSchemas.d.ts +8 -0
- package/dist/common/VersionedSchema/Utils/getUniqueKeysFromSchemas.d.ts.map +1 -0
- package/dist/common/VersionedSchema/Utils/getUniqueKeysFromSchemas.js +17 -0
- package/dist/common/VersionedSchema/Utils/getUniqueObjectKeys.js +2 -2
- package/dist/common/VersionedSchema/Utils/joiHandlers.d.ts +3 -3
- package/dist/common/VersionedSchema/Utils/joiHandlers.d.ts.map +1 -1
- package/dist/common/VersionedSchema/Utils/joiHandlers.js +24 -17
- package/dist/common/VersionedSchema/Utils/{migrateToLatestVersion.d.ts → migrateDataToLatestSchemaVersion.d.ts} +5 -5
- package/dist/common/VersionedSchema/Utils/migrateDataToLatestSchemaVersion.d.ts.map +1 -0
- package/dist/common/VersionedSchema/Utils/migrateDataToLatestSchemaVersion.js +43 -0
- package/dist/common/VersionedSchema/Utils/replaceInvalidKeysWithMappedNames.d.ts +2 -0
- package/dist/common/VersionedSchema/Utils/replaceInvalidKeysWithMappedNames.d.ts.map +1 -0
- package/dist/common/VersionedSchema/Utils/replaceInvalidKeysWithMappedNames.js +18 -0
- package/dist/common/VersionedSchema/Utils/traverseObjectStructure.d.ts +3 -0
- package/dist/common/VersionedSchema/Utils/traverseObjectStructure.d.ts.map +1 -0
- package/dist/common/VersionedSchema/Utils/{traverseGeneric.js → traverseObjectStructure.js} +6 -4
- package/dist/common/VersionedSchema/Utils/validateAndSuggestKeyCorrections.d.ts +8 -0
- package/dist/common/VersionedSchema/Utils/validateAndSuggestKeyCorrections.d.ts.map +1 -0
- package/dist/common/VersionedSchema/Utils/validateAndSuggestKeyCorrections.js +44 -0
- package/dist/common/__tests__/__mock__/mockJoiSchema.d.ts +19 -0
- package/dist/common/__tests__/__mock__/mockJoiSchema.d.ts.map +1 -0
- package/dist/common/__tests__/__mock__/mockJoiSchema.js +14 -0
- package/dist/common/__tests__/convertArrayToObject.test.d.ts +2 -0
- package/dist/common/__tests__/convertArrayToObject.test.d.ts.map +1 -0
- package/dist/common/__tests__/convertArrayToObject.test.js +227 -0
- package/dist/common/__tests__/determineBestMatchingSchemaVersion.test.d.ts +2 -0
- package/dist/common/__tests__/determineBestMatchingSchemaVersion.test.d.ts.map +1 -0
- package/dist/common/__tests__/determineBestMatchingSchemaVersion.test.js +38 -0
- package/dist/common/__tests__/generateKeyMappingForInvalidKeys.test.d.ts +2 -0
- package/dist/common/__tests__/generateKeyMappingForInvalidKeys.test.d.ts.map +1 -0
- package/dist/common/__tests__/generateKeyMappingForInvalidKeys.test.js +22 -0
- package/dist/common/__tests__/getUniqueKeysFromSchemas.test.d.ts +2 -0
- package/dist/common/__tests__/getUniqueKeysFromSchemas.test.d.ts.map +1 -0
- package/dist/common/__tests__/getUniqueKeysFromSchemas.test.js +20 -0
- package/dist/common/__tests__/getUniqueObjectKeys.test.d.ts +2 -0
- package/dist/common/__tests__/getUniqueObjectKeys.test.d.ts.map +1 -0
- package/dist/common/__tests__/getUniqueObjectKeys.test.js +24 -0
- package/dist/common/__tests__/migrationForMultiOptions.test.js +84 -63
- package/dist/common/__tests__/migrationForOptions.test.js +27 -46
- package/dist/common/__tests__/replaceInvalidKeysWithMappedNames.test.d.ts +2 -0
- package/dist/common/__tests__/replaceInvalidKeysWithMappedNames.test.d.ts.map +1 -0
- package/dist/common/__tests__/replaceInvalidKeysWithMappedNames.test.js +25 -0
- package/dist/common/__tests__/validateAndSuggestKeyCorrections.test.d.ts +2 -0
- package/dist/common/__tests__/validateAndSuggestKeyCorrections.test.d.ts.map +1 -0
- package/dist/common/__tests__/validateAndSuggestKeyCorrections.test.js +25 -0
- package/dist/common/defaultOptions.d.ts.map +1 -1
- package/dist/common/defaultOptions.js +22 -2
- package/dist/core/index.d.ts +2 -2
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/index.js +41 -19
- package/dist/core/utils/precompileTemplates.js +9 -2
- package/dist/core/utils/prepareOptions.d.ts +2 -2
- package/dist/core/utils/prepareOptions.d.ts.map +1 -1
- package/dist/core/utils/writeClient.d.ts +4 -0
- package/dist/core/utils/writeClient.d.ts.map +1 -1
- package/dist/core/utils/writeClient.js +13 -0
- package/package.json +5 -2
- package/dist/common/VersionedSchema/Utils/getUniqueAllShemasKeys.d.ts +0 -8
- package/dist/common/VersionedSchema/Utils/getUniqueAllShemasKeys.d.ts.map +0 -1
- package/dist/common/VersionedSchema/Utils/getUniqueAllShemasKeys.js +0 -15
- package/dist/common/VersionedSchema/Utils/guessVersion.d.ts +0 -3
- package/dist/common/VersionedSchema/Utils/guessVersion.d.ts.map +0 -1
- package/dist/common/VersionedSchema/Utils/guessVersion.js +0 -16
- package/dist/common/VersionedSchema/Utils/migrateToLatestVersion.d.ts.map +0 -1
- package/dist/common/VersionedSchema/Utils/migrateToLatestVersion.js +0 -33
- package/dist/common/VersionedSchema/Utils/traverseGeneric.d.ts +0 -3
- package/dist/common/VersionedSchema/Utils/traverseGeneric.d.ts.map +0 -1
- package/dist/common/VersionedSchema/Utils/validateUnknownKeys.d.ts +0 -2
- package/dist/common/VersionedSchema/Utils/validateUnknownKeys.d.ts.map +0 -1
- package/dist/common/VersionedSchema/Utils/validateUnknownKeys.js +0 -32
- package/dist/common/__tests__/guessVersion.test.d.ts +0 -2
- package/dist/common/__tests__/guessVersion.test.d.ts.map +0 -1
- package/dist/common/__tests__/guessVersion.test.js +0 -26
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runGenerateOpenApi.d.ts","sourceRoot":"","sources":["../../../src/cli/generate/runGenerateOpenApi.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"runGenerateOpenApi.d.ts","sourceRoot":"","sources":["../../../src/cli/generate/runGenerateOpenApi.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAezC;;;GAGG;AACH,wBAAsB,kBAAkB,CAAC,OAAO,EAAE,YAAY,iBAsD7D"}
|
|
@@ -35,12 +35,14 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
36
|
exports.runGenerateOpenApi = runGenerateOpenApi;
|
|
37
37
|
const defaultOptions_1 = require("../../common/defaultOptions");
|
|
38
|
+
const Enums_1 = require("../../common/Enums");
|
|
39
|
+
const Logger_1 = require("../../common/Logger");
|
|
38
40
|
const Utils_1 = require("../../common/Utils");
|
|
39
41
|
const MultiOptionsMigrationPlan_1 = require("../../common/VersionedSchema/MultiOptionsMigrationPlan");
|
|
40
42
|
const MultiOptionsVersionedSchemas_1 = require("../../common/VersionedSchema/MultiOptionsVersionedSchemas");
|
|
41
43
|
const OptionsMigrationPlans_1 = require("../../common/VersionedSchema/OptionsMigrationPlans");
|
|
42
44
|
const OptionsVersionedSchemas_1 = require("../../common/VersionedSchema/OptionsVersionedSchemas");
|
|
43
|
-
const
|
|
45
|
+
const migrateDataToLatestSchemaVersion_1 = require("../../common/VersionedSchema/Utils/migrateDataToLatestSchemaVersion");
|
|
44
46
|
const OpenAPI = __importStar(require("../../core"));
|
|
45
47
|
const isInstanceOfMultiOptions_1 = require("../../core/utils/isInstanceOfMultiOptions");
|
|
46
48
|
/**
|
|
@@ -48,38 +50,52 @@ const isInstanceOfMultiOptions_1 = require("../../core/utils/isInstanceOfMultiOp
|
|
|
48
50
|
* @param options Options for starting generation.
|
|
49
51
|
*/
|
|
50
52
|
async function runGenerateOpenApi(options) {
|
|
51
|
-
const
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
53
|
+
const logger = new Logger_1.Logger({
|
|
54
|
+
level: Enums_1.ELogLevel.INFO,
|
|
55
|
+
instanceId: 'openapi-cli',
|
|
56
|
+
logOutput: Enums_1.ELogOutput.CONSOLE,
|
|
57
|
+
});
|
|
58
|
+
try {
|
|
59
|
+
const hasMinimumRequiredOptions = !!options.input && !!options.output;
|
|
60
|
+
if (hasMinimumRequiredOptions) {
|
|
61
|
+
const { error: defaultValuesError, value } = defaultOptions_1.defaultOptions.validate(options);
|
|
62
|
+
if (defaultValuesError) {
|
|
63
|
+
await OpenAPI.generate(value);
|
|
64
|
+
process.exit(0);
|
|
65
|
+
}
|
|
57
66
|
}
|
|
67
|
+
const configData = (0, Utils_1.loadConfigIfExists)();
|
|
68
|
+
if (!configData) {
|
|
69
|
+
logger.error('The configuration file is missing');
|
|
70
|
+
}
|
|
71
|
+
const preparedOptions = (0, Utils_1.convertArrayToObject)(configData);
|
|
72
|
+
const isMultiOptions = (0, isInstanceOfMultiOptions_1.isInstanceOfMultioptions)(preparedOptions);
|
|
73
|
+
const migratedOptions = isMultiOptions
|
|
74
|
+
? (0, migrateDataToLatestSchemaVersion_1.migrateDataToLatestSchemaVersion)({
|
|
75
|
+
rawInput: preparedOptions,
|
|
76
|
+
migrationPlans: MultiOptionsMigrationPlan_1.multiOptionsMigrationPlan,
|
|
77
|
+
versionedSchemas: MultiOptionsVersionedSchemas_1.multiOptionsVersionedSchema,
|
|
78
|
+
})
|
|
79
|
+
: (0, migrateDataToLatestSchemaVersion_1.migrateDataToLatestSchemaVersion)({
|
|
80
|
+
rawInput: preparedOptions,
|
|
81
|
+
migrationPlans: OptionsMigrationPlans_1.optionsMigrationPlans,
|
|
82
|
+
versionedSchemas: OptionsVersionedSchemas_1.optionsVersionedSchemas,
|
|
83
|
+
});
|
|
84
|
+
if (!migratedOptions) {
|
|
85
|
+
logger.error("Couldn't convert the set of options to the current version");
|
|
86
|
+
}
|
|
87
|
+
else {
|
|
88
|
+
const { value } = migratedOptions;
|
|
89
|
+
if (isMultiOptions) {
|
|
90
|
+
await OpenAPI.generate(value);
|
|
91
|
+
}
|
|
92
|
+
else {
|
|
93
|
+
await OpenAPI.generate(value);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
process.exit(0);
|
|
58
97
|
}
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
throw new Error('Error: The configuration file is missing');
|
|
62
|
-
}
|
|
63
|
-
const isMultiOptions = (0, isInstanceOfMultiOptions_1.isInstanceOfMultioptions)(configData);
|
|
64
|
-
const migratedOptions = isMultiOptions
|
|
65
|
-
? (0, migrateToLatestVersion_1.migrateToLatestVersion)({
|
|
66
|
-
rawInput: configData,
|
|
67
|
-
migrationPlans: MultiOptionsMigrationPlan_1.multiOptionsMigrationPlan,
|
|
68
|
-
versionedSchemas: MultiOptionsVersionedSchemas_1.multiOptionsVersionedSchema,
|
|
69
|
-
})
|
|
70
|
-
: (0, migrateToLatestVersion_1.migrateToLatestVersion)({
|
|
71
|
-
rawInput: configData,
|
|
72
|
-
migrationPlans: OptionsMigrationPlans_1.optionsMigrationPlans,
|
|
73
|
-
versionedSchemas: OptionsVersionedSchemas_1.optionsVersionedSchemas,
|
|
74
|
-
});
|
|
75
|
-
if (!migratedOptions) {
|
|
76
|
-
throw new Error('Error: Couldn\'t convert the set of options to the current version');
|
|
77
|
-
}
|
|
78
|
-
const { value } = migratedOptions;
|
|
79
|
-
if (isMultiOptions) {
|
|
80
|
-
await OpenAPI.generate(value);
|
|
81
|
-
}
|
|
82
|
-
else {
|
|
83
|
-
await OpenAPI.generate(value);
|
|
98
|
+
catch (error) {
|
|
99
|
+
logger.error(error.message);
|
|
84
100
|
}
|
|
85
101
|
}
|
package/dist/cli/index.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const commander_1 = require("commander");
|
|
4
|
+
const Enums_1 = require("../common/Enums");
|
|
5
|
+
const Enums_2 = require("../core/types/Enums");
|
|
4
6
|
const runGenerateOpenApi_1 = require("./generate/runGenerateOpenApi");
|
|
5
7
|
const APP_NAME = 'ts-openapi-codegen-cli';
|
|
6
8
|
const APP_VERSION = '1.0.0';
|
|
@@ -16,7 +18,7 @@ program
|
|
|
16
18
|
.option('-os, --outputServices <value>', 'Output directory for services')
|
|
17
19
|
.option('-om, --outputModels <value>', 'Output directory for models')
|
|
18
20
|
.option('-osm, --outputSchemas <value>', 'Output directory for schemas')
|
|
19
|
-
.
|
|
21
|
+
.addOption(new commander_1.Option('-c, --httpClient <value>', 'HTTP client to generate').choices([...Object.values(Enums_2.HttpClient)]).default(Enums_2.HttpClient.FETCH))
|
|
20
22
|
.option('--useOptions <value>', 'Use options instead of arguments', false)
|
|
21
23
|
.option('--useUnionTypes <value>', 'Use union types instead of enums', false)
|
|
22
24
|
.option('--exportCore <value>', 'Write core files to disk', true)
|
|
@@ -29,6 +31,8 @@ program
|
|
|
29
31
|
.option('--enumPrefix <value>', 'Prefix for enum model(default: "E")')
|
|
30
32
|
.option('--typePrefix <value>', 'Prefix for type model(default: "T")')
|
|
31
33
|
.option('--useCancelableRequest <value>', 'Use cancelled promise as returned data type in request(default: false)', false)
|
|
34
|
+
.addOption(new commander_1.Option('-l, --logLevel <level>', 'Logging level').choices([...Object.values(Enums_1.ELogLevel)]).default(Enums_1.ELogLevel.ERROR))
|
|
35
|
+
.addOption(new commander_1.Option('-t, --logTarget <target>', 'Target of logging').choices([...Object.values(Enums_1.ELogOutput)]).default(Enums_1.ELogOutput.CONSOLE))
|
|
32
36
|
.action(async (options) => {
|
|
33
37
|
await (0, runGenerateOpenApi_1.runGenerateOpenApi)(options);
|
|
34
38
|
});
|
package/dist/cli/utils.d.ts
CHANGED
package/dist/cli/utils.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/cli/utils.ts"],"names":[],"mappings":"
|
|
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"}
|
package/dist/cli/utils.js
CHANGED
|
@@ -1,46 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
|
-
};
|
|
38
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
3
|
exports.isNil = isNil;
|
|
40
4
|
exports.isValidJson = isValidJson;
|
|
41
|
-
exports.startGenerate = startGenerate;
|
|
42
|
-
const path_1 = __importDefault(require("path"));
|
|
43
|
-
const OpenAPI = __importStar(require("../core"));
|
|
44
5
|
/**
|
|
45
6
|
* Checks if `value` is `null` or `undefined`.
|
|
46
7
|
*
|
|
@@ -69,20 +30,3 @@ function isValidJson(value) {
|
|
|
69
30
|
return false;
|
|
70
31
|
}
|
|
71
32
|
}
|
|
72
|
-
function startGenerate(options) {
|
|
73
|
-
return OpenAPI.generate(options)
|
|
74
|
-
.then(() => {
|
|
75
|
-
console.group(`Generation from has been finished`);
|
|
76
|
-
const group = Array.isArray(options) ? options : Array.of(options);
|
|
77
|
-
group.forEach(option => {
|
|
78
|
-
console.log(`Generation from "${option.input}" was finished`);
|
|
79
|
-
console.log(`Output folder: ${path_1.default.resolve(process.cwd(), option.output)}`);
|
|
80
|
-
console.log('==================================');
|
|
81
|
-
});
|
|
82
|
-
console.groupEnd();
|
|
83
|
-
})
|
|
84
|
-
.catch((error) => {
|
|
85
|
-
console.log(error);
|
|
86
|
-
process.exit(1);
|
|
87
|
-
});
|
|
88
|
-
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Enums.d.ts","sourceRoot":"","sources":["../../src/common/Enums.ts"],"names":[],"mappings":"AAAA,oBAAY,SAAS;IACjB,IAAI,SAAS;IACb,IAAI,SAAS;IACb,KAAK,UAAU;CAClB;AACD,oBAAY,UAAU;IAClB,OAAO,YAAY;IACnB,IAAI,SAAS;CAChB"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ELogOutput = exports.ELogLevel = void 0;
|
|
4
|
+
var ELogLevel;
|
|
5
|
+
(function (ELogLevel) {
|
|
6
|
+
ELogLevel["INFO"] = "info";
|
|
7
|
+
ELogLevel["WARN"] = "warn";
|
|
8
|
+
ELogLevel["ERROR"] = "error";
|
|
9
|
+
})(ELogLevel || (exports.ELogLevel = ELogLevel = {}));
|
|
10
|
+
var ELogOutput;
|
|
11
|
+
(function (ELogOutput) {
|
|
12
|
+
ELogOutput["CONSOLE"] = "console";
|
|
13
|
+
ELogOutput["FILE"] = "file";
|
|
14
|
+
})(ELogOutput || (exports.ELogOutput = ELogOutput = {}));
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { ELogLevel, ELogOutput } from './Enums';
|
|
2
|
+
interface LoggerOptions {
|
|
3
|
+
/** Instance ID (letters/numbers/hyphens/handwriting only) */
|
|
4
|
+
instanceId: string;
|
|
5
|
+
/** The initial logging level */
|
|
6
|
+
level: ELogLevel;
|
|
7
|
+
/** Where to write: 'console' or 'file' */
|
|
8
|
+
logOutput: ELogOutput;
|
|
9
|
+
/** Folder for logs (only with LogOutput='file') */
|
|
10
|
+
/** Rotation parameters (only for LogOutput='file') */
|
|
11
|
+
rotate?: {
|
|
12
|
+
/** Template for the date in the file name */
|
|
13
|
+
datePattern?: string;
|
|
14
|
+
/** The maximum file size, for example '20m' */
|
|
15
|
+
maxSize?: string;
|
|
16
|
+
/** Do not store files for longer, for example '14d' */
|
|
17
|
+
maxFiles?: string;
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
export declare class Logger {
|
|
21
|
+
private _logger;
|
|
22
|
+
private _currentLevel;
|
|
23
|
+
private _instanceId;
|
|
24
|
+
constructor(options: LoggerOptions);
|
|
25
|
+
setLevel(level: ELogLevel): void;
|
|
26
|
+
error(message: string): void;
|
|
27
|
+
warn(message: string): void;
|
|
28
|
+
info(message: string, hasSeparator?: boolean): void;
|
|
29
|
+
forceInfo(message: string): void;
|
|
30
|
+
shutdownLogger(): void;
|
|
31
|
+
}
|
|
32
|
+
export {};
|
|
33
|
+
//# sourceMappingURL=Logger.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Logger.d.ts","sourceRoot":"","sources":["../../src/common/Logger.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAEhD,UAAU,aAAa;IACnB,6DAA6D;IAC7D,UAAU,EAAE,MAAM,CAAC;IACnB,gCAAgC;IAChC,KAAK,EAAE,SAAS,CAAC;IACjB,0CAA0C;IAC1C,SAAS,EAAE,UAAU,CAAC;IACtB,mDAAmD;IACnD,sDAAsD;IACtD,MAAM,CAAC,EAAE;QACL,6CAA6C;QAC7C,WAAW,CAAC,EAAE,MAAM,CAAC;QACrB,+CAA+C;QAC/C,OAAO,CAAC,EAAE,MAAM,CAAC;QACjB,uDAAuD;QACvD,QAAQ,CAAC,EAAE,MAAM,CAAC;KACrB,CAAC;CACL;AAED,qBAAa,MAAM;IACf,OAAO,CAAC,OAAO,CAAgB;IAC/B,OAAO,CAAC,aAAa,CAAY;IACjC,OAAO,CAAC,WAAW,CAAS;gBAEhB,OAAO,EAAE,aAAa;IA6C3B,QAAQ,CAAC,KAAK,EAAE,SAAS;IAKzB,KAAK,CAAC,OAAO,EAAE,MAAM;IAKrB,IAAI,CAAC,OAAO,EAAE,MAAM;IAIpB,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,YAAY,CAAC,EAAE,OAAO;IAO5C,SAAS,CAAC,OAAO,EAAE,MAAM;IAOzB,cAAc,IAAI,IAAI;CAahC"}
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.Logger = void 0;
|
|
40
|
+
const path = __importStar(require("path"));
|
|
41
|
+
const winston_1 = require("winston");
|
|
42
|
+
const winston_daily_rotate_file_1 = __importDefault(require("winston-daily-rotate-file"));
|
|
43
|
+
const Enums_1 = require("./Enums");
|
|
44
|
+
class Logger {
|
|
45
|
+
_logger;
|
|
46
|
+
_currentLevel;
|
|
47
|
+
_instanceId;
|
|
48
|
+
constructor(options) {
|
|
49
|
+
const { instanceId, level, logOutput, rotate = { datePattern: 'YYYY-MM-DD', maxSize: '20m', maxFiles: '14d' } } = options;
|
|
50
|
+
this._currentLevel = level;
|
|
51
|
+
this._instanceId = instanceId;
|
|
52
|
+
const chosenTransports = [];
|
|
53
|
+
if (logOutput === Enums_1.ELogOutput.CONSOLE) {
|
|
54
|
+
chosenTransports.push(new winston_1.transports.Console({
|
|
55
|
+
format: winston_1.format.combine(winston_1.format.colorize(), winston_1.format.timestamp({ format: 'YYYY-MM-DD HH:mm:ss' }), winston_1.format.printf(({ level, message, timestamp, label }) => {
|
|
56
|
+
return `[${level}] [${label}] ${timestamp}: ${message}`;
|
|
57
|
+
})),
|
|
58
|
+
}));
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
const logDir = path.join(process.cwd(), '__logs__');
|
|
62
|
+
chosenTransports.push(new winston_daily_rotate_file_1.default({
|
|
63
|
+
filename: path.join(logDir, 'app-%DATE%.log'),
|
|
64
|
+
datePattern: rotate.datePattern,
|
|
65
|
+
zippedArchive: true,
|
|
66
|
+
maxSize: rotate.maxSize,
|
|
67
|
+
maxFiles: rotate.maxFiles,
|
|
68
|
+
format: winston_1.format.combine(winston_1.format.timestamp({ format: 'YYYY-MM-DD HH:mm:ss' }), winston_1.format.printf(({ level, message, timestamp, label }) => {
|
|
69
|
+
return `[${level}] [${label}] ${timestamp}: ${message}`;
|
|
70
|
+
})),
|
|
71
|
+
}));
|
|
72
|
+
}
|
|
73
|
+
this._logger = (0, winston_1.createLogger)({
|
|
74
|
+
level: this._currentLevel,
|
|
75
|
+
levels: { error: 0, warn: 1, info: 2 },
|
|
76
|
+
format: winston_1.format.label({ label: this._instanceId }),
|
|
77
|
+
transports: chosenTransports,
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
setLevel(level) {
|
|
81
|
+
this._currentLevel = level;
|
|
82
|
+
this._logger.level = level;
|
|
83
|
+
}
|
|
84
|
+
error(message) {
|
|
85
|
+
this._logger.error(`Error: ${message}`);
|
|
86
|
+
process.exit(1);
|
|
87
|
+
}
|
|
88
|
+
warn(message) {
|
|
89
|
+
this._logger.warn(message);
|
|
90
|
+
}
|
|
91
|
+
info(message, hasSeparator) {
|
|
92
|
+
this._logger.info(message);
|
|
93
|
+
if (hasSeparator) {
|
|
94
|
+
this._logger.info('==========================================');
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
forceInfo(message) {
|
|
98
|
+
const originalLevel = this._logger.level;
|
|
99
|
+
this._logger.level = 'info';
|
|
100
|
+
this._logger.info(message);
|
|
101
|
+
this._logger.level = originalLevel;
|
|
102
|
+
}
|
|
103
|
+
shutdownLogger() {
|
|
104
|
+
if (this._logger) {
|
|
105
|
+
this._logger.close();
|
|
106
|
+
this._logger.transports.forEach(transport => {
|
|
107
|
+
if (typeof transport.close === 'function') {
|
|
108
|
+
transport.close();
|
|
109
|
+
}
|
|
110
|
+
if (typeof transport.end === 'function') {
|
|
111
|
+
transport.end();
|
|
112
|
+
}
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
exports.Logger = Logger;
|
package/dist/common/Options.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { HttpClient } from "../core/types/Enums";
|
|
2
|
-
export type
|
|
2
|
+
export type TOptions = {
|
|
3
3
|
input: string | Record<string, any>;
|
|
4
4
|
output: string;
|
|
5
5
|
outputCore?: string;
|
|
@@ -21,7 +21,7 @@ export type Options = {
|
|
|
21
21
|
typePrefix?: string;
|
|
22
22
|
useCancelableRequest?: boolean;
|
|
23
23
|
};
|
|
24
|
-
export type
|
|
25
|
-
items:
|
|
26
|
-
} & Omit<
|
|
24
|
+
export type TMultiOptions = {
|
|
25
|
+
items: TOptions[];
|
|
26
|
+
} & Omit<TOptions, 'input' | 'output'>;
|
|
27
27
|
//# sourceMappingURL=Options.d.ts.map
|
|
@@ -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,
|
|
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,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,oBAAoB,CAAC,EAAE,OAAO,CAAC;CAClC,CAAC;AAEF,MAAM,MAAM,aAAa,GAAG;IAC1B,KAAK,EAAE,QAAQ,EAAE,CAAC;CACnB,GAAG,IAAI,CAAC,QAAQ,EAAE,OAAO,GAAG,QAAQ,CAAC,CAAC"}
|
package/dist/common/Utils.d.ts
CHANGED
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
export declare function loadConfigIfExists(): Record<string, any> | null;
|
|
1
|
+
export declare function loadConfigIfExists(): Record<string, any> | Record<string, any>[] | null;
|
|
2
|
+
export declare function convertArrayToObject(optionsArr: Record<string, any> | Record<string, any>[] | null): Record<string, any>;
|
|
2
3
|
//# sourceMappingURL=Utils.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Utils.d.ts","sourceRoot":"","sources":["../../src/common/Utils.ts"],"names":[],"mappings":"AAOA,wBAAgB,kBAAkB
|
|
1
|
+
{"version":3,"file":"Utils.d.ts","sourceRoot":"","sources":["../../src/common/Utils.ts"],"names":[],"mappings":"AAOA,wBAAgB,kBAAkB,uDAYjC;AAED,wBAAgB,oBAAoB,CAAC,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,GAAG,IAAI,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CA6DxH"}
|
package/dist/common/Utils.js
CHANGED
|
@@ -4,6 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.loadConfigIfExists = loadConfigIfExists;
|
|
7
|
+
exports.convertArrayToObject = convertArrayToObject;
|
|
7
8
|
const fs_1 = __importDefault(require("fs"));
|
|
8
9
|
const utils_1 = require("../cli/utils");
|
|
9
10
|
const pathHelpers_1 = require("../core/utils/pathHelpers");
|
|
@@ -20,3 +21,56 @@ function loadConfigIfExists() {
|
|
|
20
21
|
}
|
|
21
22
|
return configData;
|
|
22
23
|
}
|
|
24
|
+
function convertArrayToObject(optionsArr) {
|
|
25
|
+
const emptyResult = {
|
|
26
|
+
items: [],
|
|
27
|
+
exportCore: undefined,
|
|
28
|
+
exportServices: undefined,
|
|
29
|
+
exportModels: undefined,
|
|
30
|
+
exportSchemas: undefined,
|
|
31
|
+
request: undefined,
|
|
32
|
+
useOptions: undefined,
|
|
33
|
+
useCancelableRequest: undefined,
|
|
34
|
+
};
|
|
35
|
+
if (!optionsArr) {
|
|
36
|
+
return emptyResult;
|
|
37
|
+
}
|
|
38
|
+
if (Array.isArray(optionsArr)) {
|
|
39
|
+
if (optionsArr.length === 0) {
|
|
40
|
+
return emptyResult;
|
|
41
|
+
}
|
|
42
|
+
const items = optionsArr.map(item => ({
|
|
43
|
+
input: item.input,
|
|
44
|
+
output: item.output,
|
|
45
|
+
outputCore: item.outputCore,
|
|
46
|
+
outputServices: item.outputServices,
|
|
47
|
+
outputModels: item.outputModels,
|
|
48
|
+
outputSchemas: item.outputSchemas,
|
|
49
|
+
}));
|
|
50
|
+
const firstItem = optionsArr[0];
|
|
51
|
+
const fieldsToExtract = [
|
|
52
|
+
'httpClient',
|
|
53
|
+
'useOptions',
|
|
54
|
+
'useUnionTypes',
|
|
55
|
+
'exportCore',
|
|
56
|
+
'exportServices',
|
|
57
|
+
'exportModels',
|
|
58
|
+
'exportSchemas',
|
|
59
|
+
'clean',
|
|
60
|
+
'request',
|
|
61
|
+
'interfacePrefix',
|
|
62
|
+
'enumPrefix',
|
|
63
|
+
'typePrefix',
|
|
64
|
+
'useCancelableRequest',
|
|
65
|
+
];
|
|
66
|
+
const extractedFields = fieldsToExtract.reduce((acc, field) => ({
|
|
67
|
+
...acc,
|
|
68
|
+
[field]: firstItem[field],
|
|
69
|
+
}), {});
|
|
70
|
+
return {
|
|
71
|
+
...extractedFields,
|
|
72
|
+
items,
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
return optionsArr;
|
|
76
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MultiOptionsMigrationPlan.d.ts","sourceRoot":"","sources":["../../../src/common/VersionedSchema/MultiOptionsMigrationPlan.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAC;AAE9C;;GAEG;AACH,eAAO,MAAM,yBAAyB,EAAE,mBAAmB,CAAC,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,
|
|
1
|
+
{"version":3,"file":"MultiOptionsMigrationPlan.d.ts","sourceRoot":"","sources":["../../../src/common/VersionedSchema/MultiOptionsMigrationPlan.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAC;AAE9C;;GAEG;AACH,eAAO,MAAM,yBAAyB,EAAE,mBAAmB,CAAC,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,EAyBpG,CAAC"}
|
|
@@ -8,11 +8,9 @@ exports.multiOptionsMigrationPlan = [
|
|
|
8
8
|
{
|
|
9
9
|
fromVersion: '1.0.0',
|
|
10
10
|
toVersion: '1.0.1',
|
|
11
|
-
migrate: ({
|
|
11
|
+
migrate: ({ client, ...otherProps }) => ({
|
|
12
12
|
...otherProps,
|
|
13
|
-
output,
|
|
14
13
|
httpClient: client,
|
|
15
|
-
items: items.map((el) => ({ ...el, output })),
|
|
16
14
|
}),
|
|
17
15
|
},
|
|
18
16
|
{
|
|
@@ -14,5 +14,5 @@ export type GuessVersion = {
|
|
|
14
14
|
version: string;
|
|
15
15
|
index: number;
|
|
16
16
|
};
|
|
17
|
-
export type TraverseHandler = (value: any, recurse: (v: any) => void, result:
|
|
17
|
+
export type TraverseHandler<T> = (value: any, recurse: (v: any) => void, result: T) => boolean;
|
|
18
18
|
//# sourceMappingURL=Types.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Types.d.ts","sourceRoot":"","sources":["../../../src/common/VersionedSchema/Types.ts"],"names":[],"mappings":"AAAA,OAAO,GAAG,MAAM,KAAK,CAAC;AAEtB,OAAO,EAAE,oBAAoB,EAAE,MAAM,SAAS,CAAC;AAE/C,MAAM,MAAM,eAAe,CAAC,CAAC,IAAI;IAC7B,MAAM,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;IACtB,IAAI,EAAE,oBAAoB,CAAC;IAC3B,OAAO,EAAE,MAAM,CAAC;CACnB,CAAA;AAED,MAAM,MAAM,mBAAmB,CAAC,IAAI,EAAE,EAAE,IAAI;IACxC,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,CAAC,KAAK,EAAE,IAAI,KAAK,EAAE,CAAC;CAChC,CAAA;AAED,MAAM,MAAM,YAAY,GAAG;IACvB,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,MAAM,CAAC;CACjB,CAAA;
|
|
1
|
+
{"version":3,"file":"Types.d.ts","sourceRoot":"","sources":["../../../src/common/VersionedSchema/Types.ts"],"names":[],"mappings":"AAAA,OAAO,GAAG,MAAM,KAAK,CAAC;AAEtB,OAAO,EAAE,oBAAoB,EAAE,MAAM,SAAS,CAAC;AAE/C,MAAM,MAAM,eAAe,CAAC,CAAC,IAAI;IAC7B,MAAM,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;IACtB,IAAI,EAAE,oBAAoB,CAAC;IAC3B,OAAO,EAAE,MAAM,CAAC;CACnB,CAAA;AAED,MAAM,MAAM,mBAAmB,CAAC,IAAI,EAAE,EAAE,IAAI;IACxC,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,CAAC,KAAK,EAAE,IAAI,KAAK,EAAE,CAAC;CAChC,CAAA;AAED,MAAM,MAAM,YAAY,GAAG;IACvB,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,MAAM,CAAC;CACjB,CAAA;AAGD,MAAM,MAAM,eAAe,CAAC,CAAC,IAAI,CAAC,KAAK,EAAE,GAAG,EAAE,OAAO,EAAE,CAAC,CAAC,EAAE,GAAG,KAAK,IAAI,EAAE,MAAM,EAAE,CAAC,KAAK,OAAO,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { VersionedSchema } from '../Types';
|
|
2
|
+
type VersionMatchResult = {
|
|
3
|
+
lastVersionIndex: number;
|
|
4
|
+
latestVersion: string;
|
|
5
|
+
firstVersion: string;
|
|
6
|
+
};
|
|
7
|
+
export declare function determineBestMatchingSchemaVersion(inputData: Record<string, any>, versionedSchemas: VersionedSchema<Record<string, any>>[]): VersionMatchResult;
|
|
8
|
+
export {};
|
|
9
|
+
//# sourceMappingURL=determineBestMatchingSchemaVersion.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"determineBestMatchingSchemaVersion.d.ts","sourceRoot":"","sources":["../../../../src/common/VersionedSchema/Utils/determineBestMatchingSchemaVersion.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAK3C,KAAK,kBAAkB,GAAG;IACtB,gBAAgB,EAAE,MAAM,CAAC;IACzB,aAAa,EAAE,MAAM,CAAC;IACtB,YAAY,EAAE,MAAM,CAAC;CACxB,CAAC;AAGF,wBAAgB,kCAAkC,CAAC,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,gBAAgB,EAAE,eAAe,CAAC,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,EAAE,GAAG,kBAAkB,CA4C/J"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.determineBestMatchingSchemaVersion = determineBestMatchingSchemaVersion;
|
|
4
|
+
const getErrorFieldsFromValidation_1 = require("./getErrorFieldsFromValidation");
|
|
5
|
+
const getUniqueKeysFromSchemas_1 = require("./getUniqueKeysFromSchemas");
|
|
6
|
+
const getUniqueObjectKeys_1 = require("./getUniqueObjectKeys");
|
|
7
|
+
// Determining the most appropriate schema version
|
|
8
|
+
function determineBestMatchingSchemaVersion(inputData, versionedSchemas) {
|
|
9
|
+
if (!versionedSchemas.length) {
|
|
10
|
+
throw new Error('The list of schemes cannot be empty');
|
|
11
|
+
}
|
|
12
|
+
const inputKeys = (0, getUniqueObjectKeys_1.getUniqueObjectKeys)(inputData);
|
|
13
|
+
const matchingSchemas = versionedSchemas
|
|
14
|
+
.map(({ schema, version }, idx) => {
|
|
15
|
+
const { error } = schema.validate(inputData, { allowUnknown: true });
|
|
16
|
+
const errorFields = (0, getErrorFieldsFromValidation_1.getErrorFieldsFromValidation)(error).filter(err => err.type !== 'any.only');
|
|
17
|
+
return errorFields.length === 0 ? { version, index: idx } : null;
|
|
18
|
+
})
|
|
19
|
+
.filter((match) => match !== null);
|
|
20
|
+
if (matchingSchemas.length > 0) {
|
|
21
|
+
const latestMatch = matchingSchemas.reduce((prev, curr) => (curr.index > prev.index ? curr : prev));
|
|
22
|
+
return {
|
|
23
|
+
lastVersionIndex: latestMatch.index,
|
|
24
|
+
latestVersion: latestMatch.version,
|
|
25
|
+
firstVersion: matchingSchemas[0].version,
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
const schemaMatches = versionedSchemas.map(({ schema, version }, idx) => {
|
|
29
|
+
const schemaKeys = (0, getUniqueKeysFromSchemas_1.getUniqueKeysFromSchemas)([schema]);
|
|
30
|
+
const { error } = schema.validate(inputData, { allowUnknown: true });
|
|
31
|
+
const errorFields = (0, getErrorFieldsFromValidation_1.getErrorFieldsFromValidation)(error).filter(err => err.type !== 'any.only');
|
|
32
|
+
const matchingKeys = inputKeys.filter(key => schemaKeys.has(key));
|
|
33
|
+
return { index: idx, version, errorFields, matchingKeys };
|
|
34
|
+
});
|
|
35
|
+
const bestMatch = schemaMatches.reduce((best, current) => {
|
|
36
|
+
const isBetterMatch = current.matchingKeys.length >= best.matchingKeys.length && current.errorFields.length <= best.errorFields.length;
|
|
37
|
+
return isBetterMatch ? current : best;
|
|
38
|
+
}, schemaMatches[0]);
|
|
39
|
+
return {
|
|
40
|
+
lastVersionIndex: bestMatch.index,
|
|
41
|
+
latestVersion: bestMatch.version,
|
|
42
|
+
firstVersion: bestMatch.version,
|
|
43
|
+
};
|
|
44
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generateKeyMappingForInvalidKeys.d.ts","sourceRoot":"","sources":["../../../../src/common/VersionedSchema/Utils/generateKeyMappingForInvalidKeys.ts"],"names":[],"mappings":"AAGA,wBAAgB,gCAAgC,CAAC,YAAY,EAAE,MAAM,EAAE,EAAE,WAAW,EAAE,GAAG,CAAC,MAAM,CAAC,GAAG,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAiBtH"}
|
|
@@ -0,0 +1,27 @@
|
|
|
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.generateKeyMappingForInvalidKeys = generateKeyMappingForInvalidKeys;
|
|
7
|
+
const leven_1 = __importDefault(require("leven"));
|
|
8
|
+
// Generating a key replacement card
|
|
9
|
+
function generateKeyMappingForInvalidKeys(rawInputKeys, allowedKeys) {
|
|
10
|
+
const result = new Map();
|
|
11
|
+
for (const key of rawInputKeys) {
|
|
12
|
+
if (!allowedKeys.has(key)) {
|
|
13
|
+
let bestMatch = null;
|
|
14
|
+
let bestDistance = Infinity;
|
|
15
|
+
for (const candidate of allowedKeys) {
|
|
16
|
+
const d = (0, leven_1.default)(key, candidate);
|
|
17
|
+
if (d < bestDistance && d <= 3) {
|
|
18
|
+
bestDistance = d;
|
|
19
|
+
bestMatch = candidate;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
if (bestMatch)
|
|
23
|
+
result.set(key, bestMatch);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
return result;
|
|
27
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getErrorFieldsFromValidation.d.ts","sourceRoot":"","sources":["../../../../src/common/VersionedSchema/Utils/getErrorFieldsFromValidation.ts"],"names":[],"mappings":"AAAA,OAAO,GAAG,MAAM,KAAK,CAAC;AAGtB,wBAAgB,4BAA4B,CAAC,KAAK,EAAE,GAAG,CAAC,eAAe,GAAG,SAAS;;;IAElF"}
|