ts-openapi-codegen 2.0.0-beta.11 → 2.0.0-beta.13
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/index.js +2 -3
- package/dist/cli/previewChanges/previewChanges.d.ts.map +1 -1
- package/dist/cli/previewChanges/previewChanges.js +112 -32
- package/dist/cli/previewChanges/utils/updateOutputPaths.d.ts.map +1 -1
- package/dist/cli/previewChanges/utils/updateOutputPaths.js +6 -0
- package/dist/common/VersionedSchema/AllVersionedSchemas/AllMigrationPlans.d.ts +1 -1
- package/dist/common/VersionedSchema/AllVersionedSchemas/AllMigrationPlans.js +6 -6
- package/dist/common/VersionedSchema/Utils/__mocks__/compatibilityCases.d.ts.map +1 -1
- package/dist/common/VersionedSchema/Utils/__mocks__/compatibilityCases.js +13 -0
- package/dist/common/VersionedSchema/Utils/__tests__/allUtils.test.d.ts +2 -0
- package/dist/common/VersionedSchema/Utils/__tests__/allUtils.test.d.ts.map +1 -0
- package/dist/common/VersionedSchema/Utils/__tests__/allUtils.test.js +185 -0
- package/dist/common/VersionedSchema/Utils/__tests__/compareShapes.test.js +20 -3
- package/dist/common/VersionedSchema/Utils/__tests__/migrateDataToLatestSchemaVersion.test.js +18 -0
- package/dist/common/VersionedSchema/Utils/determineBestMatchingSchemaVersion.d.ts +4 -0
- package/dist/common/VersionedSchema/Utils/determineBestMatchingSchemaVersion.d.ts.map +1 -1
- package/dist/common/VersionedSchema/Utils/determineBestMatchingSchemaVersion.js +68 -23
- package/dist/common/VersionedSchema/Utils/getUniqueKeysFromSchemas.d.ts +1 -1
- package/dist/common/VersionedSchema/Utils/getUniqueKeysFromSchemas.js +1 -1
- package/dist/common/VersionedSchema/Utils/migrateDataToLatestSchemaVersion.d.ts +10 -0
- package/dist/common/VersionedSchema/Utils/migrateDataToLatestSchemaVersion.d.ts.map +1 -1
- package/dist/common/VersionedSchema/Utils/migrateDataToLatestSchemaVersion.js +31 -14
- package/dist/core/types/base/Templates.model.d.ts +1 -1
- package/dist/core/types/base/Templates.model.d.ts.map +1 -1
- package/dist/core/utils/registerHandlebarTemplates.d.ts.map +1 -1
- package/dist/core/utils/registerHandlebarTemplates.js +42 -41
- package/dist/templatesCompiled/client/exportClient.js +1 -1
- package/dist/templatesCompiled/client/exportSchema.d.ts +5 -1
- package/dist/templatesCompiled/client/exportSchema.d.ts.map +1 -1
- package/dist/templatesCompiled/client/exportSchema.js +37 -7
- package/dist/templatesCompiled/client/joi/exportSchema.js +3 -3
- package/dist/templatesCompiled/client/joi/partials/joiSchema.js +7 -7
- package/dist/templatesCompiled/client/joi/partials/joiSchemaComposition.js +4 -4
- package/dist/templatesCompiled/client/joi/partials/joiSchemaInterface.js +3 -3
- package/dist/templatesCompiled/client/jsonschema/exportSchema.js +3 -3
- package/dist/templatesCompiled/client/jsonschema/partials/jsonschemaSchema.js +7 -7
- package/dist/templatesCompiled/client/jsonschema/partials/jsonschemaSchemaArray.js +5 -5
- package/dist/templatesCompiled/client/jsonschema/partials/jsonschemaSchemaComposition.js +2 -2
- package/dist/templatesCompiled/client/jsonschema/partials/jsonschemaSchemaDictionary.js +5 -5
- package/dist/templatesCompiled/client/jsonschema/partials/jsonschemaSchemaInterface.js +2 -2
- package/dist/templatesCompiled/client/yup/exportSchema.js +1 -1
- package/dist/templatesCompiled/client/yup/partials/yupSchema.js +7 -7
- package/dist/templatesCompiled/client/yup/partials/yupSchemaComposition.js +4 -4
- package/dist/templatesCompiled/client/yup/partials/yupSchemaInterface.js +3 -3
- package/dist/templatesCompiled/client/zod/exportSchema.js +1 -1
- package/dist/templatesCompiled/client/zod/partials/zodSchema.js +7 -7
- package/dist/templatesCompiled/client/zod/partials/zodSchemaArray.js +8 -8
- package/dist/templatesCompiled/client/zod/partials/zodSchemaComposition.js +9 -9
- package/dist/templatesCompiled/client/zod/partials/zodSchemaDictionary.js +4 -4
- package/dist/templatesCompiled/client/zod/partials/zodSchemaInterface.js +3 -3
- package/package.json +2 -2
package/dist/cli/index.js
CHANGED
|
@@ -77,7 +77,7 @@ program
|
|
|
77
77
|
await updateNotifier.checkAndNotify();
|
|
78
78
|
})
|
|
79
79
|
.action(async (options) => {
|
|
80
|
-
await (0, checkConfig_1.checkConfig)(options
|
|
80
|
+
await (0, checkConfig_1.checkConfig)(options);
|
|
81
81
|
});
|
|
82
82
|
/**
|
|
83
83
|
* update - Команда для обновления конфигурационного файла
|
|
@@ -129,8 +129,7 @@ program
|
|
|
129
129
|
await (0, previewChanges_1.previewChanges)(options);
|
|
130
130
|
});
|
|
131
131
|
program.exitOverride();
|
|
132
|
-
|
|
133
|
-
// program.showSuggestionAfterError(false);
|
|
132
|
+
program.showSuggestionAfterError(false);
|
|
134
133
|
// Парсирование аргументов с обработкой ошибок
|
|
135
134
|
try {
|
|
136
135
|
program.parse(process.argv);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"previewChanges.d.ts","sourceRoot":"","sources":["../../../src/cli/previewChanges/previewChanges.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"previewChanges.d.ts","sourceRoot":"","sources":["../../../src/cli/previewChanges/previewChanges.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAmHzC;;;;GAIG;AACH,wBAAsB,cAAc,CAAC,OAAO,EAAE,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC,CAoLzE"}
|
|
@@ -51,36 +51,100 @@ const formatDiff_1 = require("./utils/formatDiff");
|
|
|
51
51
|
const isDirectoryEmpty_1 = require("./utils/isDirectoryEmpty");
|
|
52
52
|
const readDirectoryRecursive_1 = require("./utils/readDirectoryRecursive");
|
|
53
53
|
const updateOutputPaths_1 = require("./utils/updateOutputPaths");
|
|
54
|
+
function buildSummary(changes) {
|
|
55
|
+
const added = [];
|
|
56
|
+
const removed = [];
|
|
57
|
+
const modified = [];
|
|
58
|
+
for (const change of changes) {
|
|
59
|
+
if (change.status === 'added') {
|
|
60
|
+
added.push(change.file);
|
|
61
|
+
continue;
|
|
62
|
+
}
|
|
63
|
+
if (change.status === 'removed') {
|
|
64
|
+
removed.push(change.file);
|
|
65
|
+
continue;
|
|
66
|
+
}
|
|
67
|
+
modified.push(change.file);
|
|
68
|
+
}
|
|
69
|
+
added.sort();
|
|
70
|
+
removed.sort();
|
|
71
|
+
modified.sort();
|
|
72
|
+
return {
|
|
73
|
+
added,
|
|
74
|
+
removed,
|
|
75
|
+
modified,
|
|
76
|
+
total: changes.length,
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
function toFileLink(filePath) {
|
|
80
|
+
return `./${filePath}.md`;
|
|
81
|
+
}
|
|
82
|
+
function toCategoryMarkdown(title, files) {
|
|
83
|
+
const lines = [`# ${title}`, ''];
|
|
84
|
+
if (files.length === 0) {
|
|
85
|
+
lines.push('_No files_', '');
|
|
86
|
+
return lines.join('\n');
|
|
87
|
+
}
|
|
88
|
+
for (const file of files) {
|
|
89
|
+
lines.push(`- [${file}](${toFileLink(file)})`);
|
|
90
|
+
}
|
|
91
|
+
lines.push('');
|
|
92
|
+
return lines.join('\n');
|
|
93
|
+
}
|
|
94
|
+
function toSummaryMarkdown(summary) {
|
|
95
|
+
return [
|
|
96
|
+
'# Preview Changes Summary',
|
|
97
|
+
'',
|
|
98
|
+
`Total changes: ${summary.total}`,
|
|
99
|
+
`Added files: ${summary.added.length}`,
|
|
100
|
+
`Removed files: ${summary.removed.length}`,
|
|
101
|
+
`Modified files: ${summary.modified.length}`,
|
|
102
|
+
'',
|
|
103
|
+
'## Reports',
|
|
104
|
+
'- [Added files](./added-files.md)',
|
|
105
|
+
'- [Removed files](./removed-files.md)',
|
|
106
|
+
'- [Modified files](./modified-files.md)',
|
|
107
|
+
'',
|
|
108
|
+
'## Added',
|
|
109
|
+
...summary.added.map(file => `- [${file}](${toFileLink(file)})`),
|
|
110
|
+
'',
|
|
111
|
+
'## Removed',
|
|
112
|
+
...summary.removed.map(file => `- [${file}](${toFileLink(file)})`),
|
|
113
|
+
'',
|
|
114
|
+
'## Modified',
|
|
115
|
+
...summary.modified.map(file => `- [${file}](${toFileLink(file)})`),
|
|
116
|
+
'',
|
|
117
|
+
].join('\n');
|
|
118
|
+
}
|
|
54
119
|
/**
|
|
55
120
|
* Основная функция для предпросмотра изменений
|
|
56
121
|
*
|
|
57
122
|
* TODO: Добавить проверку опций команды перед выполнением
|
|
58
123
|
*/
|
|
59
124
|
async function previewChanges(options) {
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
Consts_1.APP_LOGGER.error(validationResult.errors.join('\n'));
|
|
63
|
-
process.exit(1);
|
|
64
|
-
}
|
|
65
|
-
const { openapiConfig, generatedDir, previewDir, diffDir } = validationResult.data;
|
|
66
|
-
const resolvedGeneratedDir = (0, pathHelpers_1.resolveHelper)(process.cwd(), generatedDir || '');
|
|
67
|
-
const resolvedPreviewDir = (0, pathHelpers_1.resolveHelper)(process.cwd(), previewDir || '');
|
|
68
|
-
const resolvedDiffDir = (0, pathHelpers_1.resolveHelper)(process.cwd(), diffDir || '');
|
|
125
|
+
let exitCode = 0;
|
|
126
|
+
let resolvedPreviewDir = '';
|
|
69
127
|
let previewDirCreated = false;
|
|
70
128
|
try {
|
|
129
|
+
const validationResult = (0, validateZodOptions_1.validateZodOptions)(schemas_1.previewChangesSchema, options);
|
|
130
|
+
if (!validationResult.success) {
|
|
131
|
+
Consts_1.APP_LOGGER.error(validationResult.errors.join('\n'));
|
|
132
|
+
exitCode = 1;
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
const { openapiConfig, generatedDir, previewDir, diffDir } = validationResult.data;
|
|
136
|
+
const resolvedGeneratedDir = (0, pathHelpers_1.resolveHelper)(process.cwd(), generatedDir || '');
|
|
137
|
+
resolvedPreviewDir = (0, pathHelpers_1.resolveHelper)(process.cwd(), previewDir || '');
|
|
138
|
+
const resolvedDiffDir = (0, pathHelpers_1.resolveHelper)(process.cwd(), diffDir || '');
|
|
71
139
|
// 1. Проверка директории со сгенерированным кодом
|
|
72
140
|
if (await (0, isDirectoryEmpty_1.isDirectoryEmpty)(resolvedGeneratedDir)) {
|
|
73
141
|
Consts_1.APP_LOGGER.info(`Directory "${generatedDir}" is empty or does not exist. Nothing to compare.`);
|
|
74
|
-
|
|
142
|
+
return;
|
|
75
143
|
}
|
|
76
|
-
// 2.
|
|
77
|
-
await fileSystemHelpers_1.fileSystemHelpers.mkdir(resolvedPreviewDir);
|
|
78
|
-
previewDirCreated = true;
|
|
79
|
-
// 3. Загрузка конфигурации
|
|
144
|
+
// 2. Загрузка конфигурации
|
|
80
145
|
const configData = (0, loadConfigIfExists_1.loadConfigIfExists)(openapiConfig);
|
|
81
146
|
if (!configData) {
|
|
82
|
-
|
|
83
|
-
process.exit(1);
|
|
147
|
+
throw new Error('The configuration file is missing');
|
|
84
148
|
}
|
|
85
149
|
const preparedOptions = (0, convertArrayToObject_1.convertArrayToObject)(configData);
|
|
86
150
|
// Миграция опций
|
|
@@ -91,9 +155,12 @@ async function previewChanges(options) {
|
|
|
91
155
|
migrationMode: Enums_1.EMigrationMode.GENERATE_OPENAPI,
|
|
92
156
|
});
|
|
93
157
|
if (!migratedOptions) {
|
|
94
|
-
|
|
95
|
-
process.exit(1);
|
|
158
|
+
throw new Error("Couldn't convert the set of options to the current version");
|
|
96
159
|
}
|
|
160
|
+
// 3. Подготовка и создание временной директории preview
|
|
161
|
+
await fileSystemHelpers_1.fileSystemHelpers.rmdir(resolvedPreviewDir);
|
|
162
|
+
await fileSystemHelpers_1.fileSystemHelpers.mkdir(resolvedPreviewDir);
|
|
163
|
+
previewDirCreated = true;
|
|
97
164
|
// 4. Обновление путей output для генерации в preview директорию
|
|
98
165
|
const migratedValue = migratedOptions.value;
|
|
99
166
|
const previewOptions = (0, updateOutputPaths_1.updateOutputPaths)(migratedValue, previewDir || '', generatedDir || '');
|
|
@@ -104,13 +171,15 @@ async function previewChanges(options) {
|
|
|
104
171
|
Consts_1.APP_LOGGER.info('Comparing files...');
|
|
105
172
|
const oldFiles = await (0, readDirectoryRecursive_1.readDirectoryRecursive)(resolvedGeneratedDir);
|
|
106
173
|
const newFiles = await (0, readDirectoryRecursive_1.readDirectoryRecursive)(resolvedPreviewDir);
|
|
107
|
-
const
|
|
174
|
+
const oldFileSet = new Set(oldFiles);
|
|
175
|
+
const newFileSet = new Set(newFiles);
|
|
176
|
+
const allFiles = new Set([...oldFileSet, ...newFileSet]);
|
|
108
177
|
const changes = [];
|
|
109
|
-
for (const file of allFiles) {
|
|
178
|
+
for (const file of [...allFiles].sort()) {
|
|
110
179
|
const oldPath = (0, pathHelpers_1.joinHelper)(resolvedGeneratedDir, file);
|
|
111
180
|
const newPath = (0, pathHelpers_1.joinHelper)(resolvedPreviewDir, file);
|
|
112
|
-
const oldExists =
|
|
113
|
-
const newExists =
|
|
181
|
+
const oldExists = oldFileSet.has(file);
|
|
182
|
+
const newExists = newFileSet.has(file);
|
|
114
183
|
if (oldExists && newExists) {
|
|
115
184
|
// Файл существует в обеих директориях - сравниваем
|
|
116
185
|
const fileDiff = await (0, compareFiles_1.compareFiles)(oldPath, newPath);
|
|
@@ -142,6 +211,7 @@ async function previewChanges(options) {
|
|
|
142
211
|
}
|
|
143
212
|
// 7. Сохранение результатов в diff директорию
|
|
144
213
|
if (changes.length > 0) {
|
|
214
|
+
await fileSystemHelpers_1.fileSystemHelpers.rmdir(resolvedDiffDir);
|
|
145
215
|
await fileSystemHelpers_1.fileSystemHelpers.mkdir(resolvedDiffDir);
|
|
146
216
|
for (const change of changes) {
|
|
147
217
|
const diffFilePath = (0, pathHelpers_1.joinHelper)(resolvedDiffDir, `${change.file}.md`);
|
|
@@ -160,30 +230,40 @@ async function previewChanges(options) {
|
|
|
160
230
|
await fileSystemHelpers_1.fileSystemHelpers.writeFile(diffFilePath, diffContent, 'utf-8');
|
|
161
231
|
Consts_1.APP_LOGGER.info(`Diff saved: ${diffFilePath}`);
|
|
162
232
|
}
|
|
233
|
+
const summary = buildSummary(changes);
|
|
234
|
+
await fileSystemHelpers_1.fileSystemHelpers.writeFile((0, pathHelpers_1.joinHelper)(resolvedDiffDir, 'added-files.md'), toCategoryMarkdown('Added Files', summary.added), 'utf-8');
|
|
235
|
+
await fileSystemHelpers_1.fileSystemHelpers.writeFile((0, pathHelpers_1.joinHelper)(resolvedDiffDir, 'removed-files.md'), toCategoryMarkdown('Removed Files', summary.removed), 'utf-8');
|
|
236
|
+
await fileSystemHelpers_1.fileSystemHelpers.writeFile((0, pathHelpers_1.joinHelper)(resolvedDiffDir, 'modified-files.md'), toCategoryMarkdown('Modified Files', summary.modified), 'utf-8');
|
|
237
|
+
await fileSystemHelpers_1.fileSystemHelpers.writeFile((0, pathHelpers_1.joinHelper)(resolvedDiffDir, 'summary.json'), JSON.stringify(summary, null, 2), 'utf-8');
|
|
238
|
+
await fileSystemHelpers_1.fileSystemHelpers.writeFile((0, pathHelpers_1.joinHelper)(resolvedDiffDir, 'summary.md'), toSummaryMarkdown(summary), 'utf-8');
|
|
163
239
|
Consts_1.APP_LOGGER.info(`\nTotal changes: ${changes.length}`);
|
|
164
240
|
Consts_1.APP_LOGGER.info(`Diff files saved to: ${diffDir}`);
|
|
165
241
|
}
|
|
166
242
|
else {
|
|
243
|
+
await fileSystemHelpers_1.fileSystemHelpers.rmdir(resolvedDiffDir);
|
|
167
244
|
Consts_1.APP_LOGGER.info('No changes detected. All files are identical.');
|
|
168
245
|
}
|
|
169
|
-
// 8. Удаление временной директории preview
|
|
170
|
-
Consts_1.APP_LOGGER.info(`Cleaning up preview directory: ${previewDir}`);
|
|
171
|
-
await fileSystemHelpers_1.fileSystemHelpers.rmdir(resolvedPreviewDir);
|
|
172
|
-
previewDirCreated = false;
|
|
173
|
-
process.exit(0);
|
|
174
246
|
}
|
|
175
247
|
catch (error) {
|
|
176
|
-
|
|
177
|
-
|
|
248
|
+
exitCode = 1;
|
|
249
|
+
Consts_1.APP_LOGGER.error(error.message);
|
|
250
|
+
}
|
|
251
|
+
finally {
|
|
252
|
+
if (previewDirCreated || resolvedPreviewDir) {
|
|
178
253
|
try {
|
|
179
|
-
|
|
180
|
-
|
|
254
|
+
if (resolvedPreviewDir) {
|
|
255
|
+
Consts_1.APP_LOGGER.info(`Cleaning up preview directory: ${resolvedPreviewDir}`);
|
|
256
|
+
await fileSystemHelpers_1.fileSystemHelpers.rmdir(resolvedPreviewDir);
|
|
257
|
+
}
|
|
181
258
|
}
|
|
182
259
|
catch (cleanupError) {
|
|
183
260
|
Consts_1.APP_LOGGER.error(`Failed to cleanup preview directory: ${cleanupError.message}`);
|
|
261
|
+
exitCode = 1;
|
|
184
262
|
}
|
|
185
263
|
}
|
|
186
|
-
|
|
264
|
+
}
|
|
265
|
+
if (exitCode !== 0) {
|
|
187
266
|
process.exit(1);
|
|
188
267
|
}
|
|
268
|
+
process.exit(0);
|
|
189
269
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"updateOutputPaths.d.ts","sourceRoot":"","sources":["../../../../src/cli/previewChanges/utils/updateOutputPaths.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"updateOutputPaths.d.ts","sourceRoot":"","sources":["../../../../src/cli/previewChanges/utils/updateOutputPaths.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAG1D;;;;;;GAMG;AACH,wBAAgB,iBAAiB,CAC7B,OAAO,EAAE,WAAW,EACpB,UAAU,EAAE,MAAM,EAClB,YAAY,EAAE,MAAM,GACrB,WAAW,CA6Ib"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.updateOutputPaths = updateOutputPaths;
|
|
4
|
+
const path_1 = require("path");
|
|
4
5
|
const pathHelpers_1 = require("../../../common/utils/pathHelpers");
|
|
5
6
|
/**
|
|
6
7
|
* Обновляет пути output в опциях для генерации в preview директорию
|
|
@@ -23,6 +24,11 @@ function updateOutputPaths(options, previewDir, generatedDir) {
|
|
|
23
24
|
if (relativePath.startsWith('./')) {
|
|
24
25
|
relativePath = relativePath.substring(2);
|
|
25
26
|
}
|
|
27
|
+
// Если путь выходит за пределы generatedDir, используем basename для безопасного переноса
|
|
28
|
+
if (relativePath.startsWith('../')) {
|
|
29
|
+
const outputBaseName = (0, path_1.basename)(resolvedOldPath);
|
|
30
|
+
return (0, pathHelpers_1.joinHelper)(previewDir, outputBaseName);
|
|
31
|
+
}
|
|
26
32
|
// Если путь пустой или равен текущей директории, возвращаем previewDir
|
|
27
33
|
if (!relativePath || relativePath === '' || relativePath === './') {
|
|
28
34
|
return previewDir;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { SchemaMigrationPlan } from '../Types';
|
|
2
2
|
/**
|
|
3
3
|
* Unified migration plan that includes all migrations from all schema types.
|
|
4
|
-
* Migrates from any old version to the latest
|
|
4
|
+
* Migrates from any old version to the latest UNIFIED_OPTIONS_v1 schema.
|
|
5
5
|
* Reuses existing migration plans to avoid code duplication.
|
|
6
6
|
*/
|
|
7
7
|
export declare const allMigrationPlans: SchemaMigrationPlan<Record<string, any>, Record<string, any>>[];
|
|
@@ -22,26 +22,26 @@ function addVersionPrefixToMigrationPlans(plans, prefix) {
|
|
|
22
22
|
}
|
|
23
23
|
/**
|
|
24
24
|
* Unified migration plan that includes all migrations from all schema types.
|
|
25
|
-
* Migrates from any old version to the latest
|
|
25
|
+
* Migrates from any old version to the latest UNIFIED_OPTIONS_v1 schema.
|
|
26
26
|
* Reuses existing migration plans to avoid code duplication.
|
|
27
27
|
*/
|
|
28
28
|
exports.allMigrationPlans = [
|
|
29
29
|
// ===== OPTIONS migrations (with prefix) =====
|
|
30
30
|
...addVersionPrefixToMigrationPlans(OptionsMigrationPlans_1.optionsMigrationPlans, 'OPTIONS'),
|
|
31
31
|
// Migration from OPTIONS latest version to UNIFIED v1
|
|
32
|
-
(0, createTrivialMigration_1.createTrivialMigration)(`OPTIONS_${(0, getLatestVersionFromMigrationPlans_1.getLatestVersionFromMigrationPlans)(OptionsMigrationPlans_1.optionsMigrationPlans)}`, '
|
|
32
|
+
(0, createTrivialMigration_1.createTrivialMigration)(`OPTIONS_${(0, getLatestVersionFromMigrationPlans_1.getLatestVersionFromMigrationPlans)(OptionsMigrationPlans_1.optionsMigrationPlans)}`, 'UNIFIED_OPTIONS_v1', 'Migrate from OPTIONS to UNIFIED schema'),
|
|
33
33
|
// ===== MULTI_OPTIONS migrations (with prefix) =====
|
|
34
34
|
...addVersionPrefixToMigrationPlans(MultiOptionsMigrationPlan_1.multiOptionsMigrationPlan, 'MULTI_OPTIONS'),
|
|
35
35
|
// Migration from MULTI_OPTIONS latest version to UNIFIED v1
|
|
36
|
-
(0, createTrivialMigration_1.createTrivialMigration)(`MULTI_OPTIONS_${(0, getLatestVersionFromMigrationPlans_1.getLatestVersionFromMigrationPlans)(MultiOptionsMigrationPlan_1.multiOptionsMigrationPlan)}`, '
|
|
37
|
-
(0, createFieldTransformationMigration_1.createFieldTransformationMigration)('
|
|
36
|
+
(0, createTrivialMigration_1.createTrivialMigration)(`MULTI_OPTIONS_${(0, getLatestVersionFromMigrationPlans_1.getLatestVersionFromMigrationPlans)(MultiOptionsMigrationPlan_1.multiOptionsMigrationPlan)}`, 'UNIFIED_OPTIONS_v1', 'Migrate from MULTI_OPTIONS to UNIFIED schema'),
|
|
37
|
+
(0, createFieldTransformationMigration_1.createFieldTransformationMigration)('UNIFIED_OPTIONS_v1', 'UNIFIED_OPTIONS_v2', ({ includeSchemasFiles, ...otherProps }) => {
|
|
38
38
|
return { ...otherProps, validationLibrary: !includeSchemasFiles ? ValidationLibrary_enum_1.ValidationLibrary.NONE : undefined };
|
|
39
39
|
}, 'Transforms includeSchemasFiles to validationLibrary: if includeSchemasFiles is false, sets validationLibrary to NONE'),
|
|
40
|
-
(0, createDefaultFieldsMigration_1.createDefaultFieldsMigration)('
|
|
40
|
+
(0, createDefaultFieldsMigration_1.createDefaultFieldsMigration)('UNIFIED_OPTIONS_v2', 'UNIFIED_OPTIONS_v3', {
|
|
41
41
|
logLevel: Enums_1.ELogLevel.ERROR,
|
|
42
42
|
logTarget: Enums_1.ELogOutput.CONSOLE
|
|
43
43
|
}),
|
|
44
|
-
(0, createDefaultFieldsMigration_1.createDefaultFieldsMigration)('
|
|
44
|
+
(0, createDefaultFieldsMigration_1.createDefaultFieldsMigration)('UNIFIED_OPTIONS_v3', 'UNIFIED_OPTIONS_v4', {
|
|
45
45
|
emptySchemaStrategy: EmptySchemaStrategy_enum_1.EmptySchemaStrategy.KEEP
|
|
46
46
|
})
|
|
47
47
|
];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"compatibilityCases.d.ts","sourceRoot":"","sources":["../../../../../src/common/VersionedSchema/Utils/__mocks__/compatibilityCases.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AACnD,OAAO,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAEtD,KAAK,iBAAiB,GAAG;IACrB,IAAI,EAAE,oBAAoB,CAAC;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,EAAE,EAAE,MAAM,CAAC;IACX,MAAM,EAAE,kBAAkB,EAAE,CAAC;CAChC,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,kBAAkB,EAAE,iBAAiB,
|
|
1
|
+
{"version":3,"file":"compatibilityCases.d.ts","sourceRoot":"","sources":["../../../../../src/common/VersionedSchema/Utils/__mocks__/compatibilityCases.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AACnD,OAAO,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAEtD,KAAK,iBAAiB,GAAG;IACrB,IAAI,EAAE,oBAAoB,CAAC;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,EAAE,EAAE,MAAM,CAAC;IACX,MAAM,EAAE,kBAAkB,EAAE,CAAC;CAChC,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,kBAAkB,EAAE,iBAAiB,EA8FjD,CAAC"}
|
|
@@ -54,6 +54,19 @@ exports.compatibilityCases = [
|
|
|
54
54
|
to: 'v3',
|
|
55
55
|
expect: [{ type: 'added', key: 'useCancelableRequest' }],
|
|
56
56
|
},
|
|
57
|
+
{
|
|
58
|
+
type: Enums_1.EVersionedSchemaType.MULTI_OPTIONS,
|
|
59
|
+
from: 'v3',
|
|
60
|
+
to: 'v4',
|
|
61
|
+
expect: [
|
|
62
|
+
{ type: 'removed', key: 'output' },
|
|
63
|
+
{ type: 'removed', key: 'outputCore' },
|
|
64
|
+
{ type: 'removed', key: 'outputServices' },
|
|
65
|
+
{ type: 'removed', key: 'outputModels' },
|
|
66
|
+
{ type: 'removed', key: 'outputSchemas' },
|
|
67
|
+
{ type: 'removed', key: 'input' },
|
|
68
|
+
],
|
|
69
|
+
},
|
|
57
70
|
{
|
|
58
71
|
type: Enums_1.EVersionedSchemaType.MULTI_OPTIONS,
|
|
59
72
|
from: 'v4',
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"allUtils.test.d.ts","sourceRoot":"","sources":["../../../../../src/common/VersionedSchema/Utils/__tests__/allUtils.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,185 @@
|
|
|
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
|
+
/* eslint-disable simple-import-sort/imports */
|
|
7
|
+
const node_assert_1 = __importDefault(require("node:assert"));
|
|
8
|
+
const node_test_1 = require("node:test");
|
|
9
|
+
const zod_1 = require("zod");
|
|
10
|
+
const Enums_1 = require("../../Enums");
|
|
11
|
+
const buildVersionedSchema_1 = require("../buildVersionedSchema");
|
|
12
|
+
const createDefaultFieldsMigration_1 = require("../createDefaultFieldsMigration");
|
|
13
|
+
const createFieldTransformationMigration_1 = require("../createFieldTransformationMigration");
|
|
14
|
+
const createTrivialMigration_1 = require("../createTrivialMigration");
|
|
15
|
+
const determineBestMatchingSchemaVersion_1 = require("../determineBestMatchingSchemaVersion");
|
|
16
|
+
const generateKeyMappingForInvalidKeys_1 = require("../generateKeyMappingForInvalidKeys");
|
|
17
|
+
const getCurrentErrorMessage_1 = require("../getCurrentErrorMessage");
|
|
18
|
+
const getKeyByMapValue_1 = require("../getKeyByMapValue");
|
|
19
|
+
const getLatestVersionFromMigrationPlans_1 = require("../getLatestVersionFromMigrationPlans");
|
|
20
|
+
const getUniqueKeysFromSchemas_1 = require("../getUniqueKeysFromSchemas");
|
|
21
|
+
const getUniqueObjectKeys_1 = require("../getUniqueObjectKeys");
|
|
22
|
+
const replaceInvalidKeysWithMappedNames_1 = require("../replaceInvalidKeysWithMappedNames");
|
|
23
|
+
const validateAndSuggestKeyCorrections_1 = require("../validateAndSuggestKeyCorrections");
|
|
24
|
+
(0, node_test_1.describe)('@unit: buildVersionedSchema', () => {
|
|
25
|
+
(0, node_test_1.test)('builds schema metadata without refine', () => {
|
|
26
|
+
const base = zod_1.z.object({ input: zod_1.z.string() });
|
|
27
|
+
const result = (0, buildVersionedSchema_1.buildVersionedSchema)({
|
|
28
|
+
base,
|
|
29
|
+
version: 'v1',
|
|
30
|
+
type: Enums_1.EVersionedSchemaType.OPTIONS,
|
|
31
|
+
});
|
|
32
|
+
node_assert_1.default.strictEqual(result.baseSchema, base);
|
|
33
|
+
node_assert_1.default.strictEqual(result.version, 'v1');
|
|
34
|
+
node_assert_1.default.strictEqual(result.type, Enums_1.EVersionedSchemaType.OPTIONS);
|
|
35
|
+
node_assert_1.default.deepStrictEqual(result.schema.parse({ input: 'ok' }), { input: 'ok' });
|
|
36
|
+
});
|
|
37
|
+
(0, node_test_1.test)('applies refine when provided', () => {
|
|
38
|
+
const base = zod_1.z.object({ input: zod_1.z.string(), output: zod_1.z.string() });
|
|
39
|
+
const schema = (0, buildVersionedSchema_1.buildVersionedSchema)({
|
|
40
|
+
base,
|
|
41
|
+
version: 'v2',
|
|
42
|
+
type: Enums_1.EVersionedSchemaType.OPTIONS,
|
|
43
|
+
refine: (data, ctx) => {
|
|
44
|
+
if (data.input === data.output) {
|
|
45
|
+
ctx.addIssue({
|
|
46
|
+
code: 'custom',
|
|
47
|
+
message: 'input and output must be different',
|
|
48
|
+
path: ['output'],
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
},
|
|
52
|
+
}).schema;
|
|
53
|
+
const result = schema.safeParse({ input: 'same', output: 'same' });
|
|
54
|
+
node_assert_1.default.strictEqual(result.success, false);
|
|
55
|
+
});
|
|
56
|
+
});
|
|
57
|
+
(0, node_test_1.describe)('@unit: migration plan helpers', () => {
|
|
58
|
+
(0, node_test_1.test)('createDefaultFieldsMigration merges default values', () => {
|
|
59
|
+
const plan = (0, createDefaultFieldsMigration_1.createDefaultFieldsMigration)('v1', 'v2', { enabled: true });
|
|
60
|
+
node_assert_1.default.strictEqual(plan.fromVersion, 'v1');
|
|
61
|
+
node_assert_1.default.strictEqual(plan.toVersion, 'v2');
|
|
62
|
+
node_assert_1.default.deepStrictEqual(plan.migrate({ name: 'demo' }), { name: 'demo', enabled: true });
|
|
63
|
+
node_assert_1.default.match(plan.description ?? '', /enabled/);
|
|
64
|
+
});
|
|
65
|
+
(0, node_test_1.test)('createFieldTransformationMigration keeps custom migrate and custom description', () => {
|
|
66
|
+
const plan = (0, createFieldTransformationMigration_1.createFieldTransformationMigration)('v1', 'v2', ({ oldField, ...rest }) => ({ ...rest, newField: oldField }), 'rename oldField');
|
|
67
|
+
node_assert_1.default.strictEqual(plan.fromVersion, 'v1');
|
|
68
|
+
node_assert_1.default.strictEqual(plan.toVersion, 'v2');
|
|
69
|
+
node_assert_1.default.strictEqual(plan.description, 'rename oldField');
|
|
70
|
+
node_assert_1.default.deepStrictEqual(plan.migrate({ oldField: 'x', other: 1 }), { other: 1, newField: 'x' });
|
|
71
|
+
});
|
|
72
|
+
(0, node_test_1.test)('createTrivialMigration copies object as-is', () => {
|
|
73
|
+
const plan = (0, createTrivialMigration_1.createTrivialMigration)('v3', 'v4');
|
|
74
|
+
const source = { a: 1 };
|
|
75
|
+
const migrated = plan.migrate(source);
|
|
76
|
+
node_assert_1.default.deepStrictEqual(migrated, source);
|
|
77
|
+
node_assert_1.default.notStrictEqual(migrated, source);
|
|
78
|
+
node_assert_1.default.match(plan.description ?? '', /Trivial migration/);
|
|
79
|
+
});
|
|
80
|
+
});
|
|
81
|
+
(0, node_test_1.describe)('@unit: determineBestMatchingSchemaVersion', () => {
|
|
82
|
+
const mk = (schema, version) => ({
|
|
83
|
+
schema,
|
|
84
|
+
baseSchema: zod_1.z.object({}),
|
|
85
|
+
version,
|
|
86
|
+
type: Enums_1.EVersionedSchemaType.OPTIONS,
|
|
87
|
+
});
|
|
88
|
+
(0, node_test_1.test)('throws on empty schema list', () => {
|
|
89
|
+
node_assert_1.default.throws(() => (0, determineBestMatchingSchemaVersion_1.determineBestMatchingSchemaVersion)({}, []), /cannot be empty/i);
|
|
90
|
+
});
|
|
91
|
+
(0, node_test_1.test)('returns latest from multiple valid matches', () => {
|
|
92
|
+
const versionedSchemas = [
|
|
93
|
+
mk(zod_1.z.object({ a: zod_1.z.string() }), 'v1'),
|
|
94
|
+
mk(zod_1.z.object({ a: zod_1.z.string(), b: zod_1.z.string().optional() }), 'v2'),
|
|
95
|
+
];
|
|
96
|
+
const result = (0, determineBestMatchingSchemaVersion_1.determineBestMatchingSchemaVersion)({ a: 'ok' }, versionedSchemas);
|
|
97
|
+
node_assert_1.default.deepStrictEqual(result, {
|
|
98
|
+
lastVersionIndex: 1,
|
|
99
|
+
latestVersion: 'v2',
|
|
100
|
+
firstVersion: 'v1',
|
|
101
|
+
});
|
|
102
|
+
});
|
|
103
|
+
(0, node_test_1.test)('falls back to the best key/error balance when no full match', () => {
|
|
104
|
+
const versionedSchemas = [
|
|
105
|
+
mk(zod_1.z.object({ a: zod_1.z.string() }), 'v1'),
|
|
106
|
+
mk(zod_1.z.object({ b: zod_1.z.string() }), 'v2'),
|
|
107
|
+
];
|
|
108
|
+
const result = (0, determineBestMatchingSchemaVersion_1.determineBestMatchingSchemaVersion)({ a: 1 }, versionedSchemas);
|
|
109
|
+
node_assert_1.default.deepStrictEqual(result, {
|
|
110
|
+
lastVersionIndex: 0,
|
|
111
|
+
latestVersion: 'v1',
|
|
112
|
+
firstVersion: 'v1',
|
|
113
|
+
});
|
|
114
|
+
});
|
|
115
|
+
});
|
|
116
|
+
(0, node_test_1.describe)('@unit: key mapping and validation helpers', () => {
|
|
117
|
+
(0, node_test_1.test)('generateKeyMappingForInvalidKeys maps close invalid keys', () => {
|
|
118
|
+
const mapping = (0, generateKeyMappingForInvalidKeys_1.generateKeyMappingForInvalidKeys)(['nmae', 'title', 'unknown'], new Set(['name', 'title']));
|
|
119
|
+
node_assert_1.default.deepStrictEqual(Array.from(mapping.entries()), [['nmae', 'name']]);
|
|
120
|
+
});
|
|
121
|
+
(0, node_test_1.test)('validateAndSuggestKeyCorrections throws with suggestion', () => {
|
|
122
|
+
node_assert_1.default.throws(() => (0, validateAndSuggestKeyCorrections_1.validateAndSuggestKeyCorrections)(['nmae'], new Set(['name'])), /Perhaps you meant "name"/);
|
|
123
|
+
});
|
|
124
|
+
(0, node_test_1.test)('validateAndSuggestKeyCorrections does not throw for valid keys', () => {
|
|
125
|
+
node_assert_1.default.doesNotThrow(() => (0, validateAndSuggestKeyCorrections_1.validateAndSuggestKeyCorrections)(['name'], new Set(['name'])));
|
|
126
|
+
});
|
|
127
|
+
});
|
|
128
|
+
(0, node_test_1.describe)('@unit: getCurrentErrorMessage and getKeyByMapValue', () => {
|
|
129
|
+
(0, node_test_1.test)('getKeyByMapValue finds key by value', () => {
|
|
130
|
+
const key = (0, getKeyByMapValue_1.getKeyByMapValue)(new Map([['nmae', '--name']]), '--name');
|
|
131
|
+
node_assert_1.default.strictEqual(key, 'nmae');
|
|
132
|
+
});
|
|
133
|
+
(0, node_test_1.test)('getCurrentErrorMessage does nothing when no issues', () => {
|
|
134
|
+
node_assert_1.default.doesNotThrow(() => {
|
|
135
|
+
(0, getCurrentErrorMessage_1.getCurrentErrorMessage)({ issues: [], message: '' }, new Map());
|
|
136
|
+
});
|
|
137
|
+
});
|
|
138
|
+
(0, node_test_1.test)('getCurrentErrorMessage throws deduplicated transformed message', () => {
|
|
139
|
+
const error = {
|
|
140
|
+
message: '--name is invalid',
|
|
141
|
+
issues: [
|
|
142
|
+
{ path: ['name'], message: 'wrong value' },
|
|
143
|
+
{ path: ['name'], message: 'wrong value' },
|
|
144
|
+
],
|
|
145
|
+
};
|
|
146
|
+
node_assert_1.default.throws(() => (0, getCurrentErrorMessage_1.getCurrentErrorMessage)(error, new Map([['nmae', '--name']])), /nmae is invalid/);
|
|
147
|
+
});
|
|
148
|
+
});
|
|
149
|
+
(0, node_test_1.describe)('@unit: collection helpers', () => {
|
|
150
|
+
(0, node_test_1.test)('getLatestVersionFromMigrationPlans returns toVersion of last plan', () => {
|
|
151
|
+
const version = (0, getLatestVersionFromMigrationPlans_1.getLatestVersionFromMigrationPlans)([
|
|
152
|
+
(0, createTrivialMigration_1.createTrivialMigration)('v1', 'v2'),
|
|
153
|
+
(0, createTrivialMigration_1.createTrivialMigration)('v2', 'v3'),
|
|
154
|
+
]);
|
|
155
|
+
node_assert_1.default.strictEqual(version, 'v3');
|
|
156
|
+
});
|
|
157
|
+
(0, node_test_1.test)('getLatestVersionFromMigrationPlans throws for empty list', () => {
|
|
158
|
+
node_assert_1.default.throws(() => (0, getLatestVersionFromMigrationPlans_1.getLatestVersionFromMigrationPlans)([]), /empty/i);
|
|
159
|
+
});
|
|
160
|
+
(0, node_test_1.test)('getUniqueKeysFromSchemas returns keys from root and nested objects', () => {
|
|
161
|
+
const keys = (0, getUniqueKeysFromSchemas_1.getUniqueKeysFromSchemas)([
|
|
162
|
+
zod_1.z.object({
|
|
163
|
+
a: zod_1.z.string(),
|
|
164
|
+
nested: zod_1.z.object({ inner: zod_1.z.number() }),
|
|
165
|
+
}),
|
|
166
|
+
zod_1.z.object({ b: zod_1.z.boolean() }),
|
|
167
|
+
]);
|
|
168
|
+
node_assert_1.default.deepStrictEqual(Array.from(keys).sort(), ['a', 'b', 'inner', 'nested']);
|
|
169
|
+
});
|
|
170
|
+
(0, node_test_1.test)('getUniqueObjectKeys returns unique keys for nested object and arrays', () => {
|
|
171
|
+
const keys = (0, getUniqueObjectKeys_1.getUniqueObjectKeys)({
|
|
172
|
+
a: 1,
|
|
173
|
+
nested: { b: 2 },
|
|
174
|
+
items: [{ c: 3 }, { a: 4 }],
|
|
175
|
+
});
|
|
176
|
+
node_assert_1.default.deepStrictEqual(keys, ['a', 'nested', 'b', 'items', 'c']);
|
|
177
|
+
});
|
|
178
|
+
(0, node_test_1.test)('replaceInvalidKeysWithMappedNames replaces keys recursively for arrays', () => {
|
|
179
|
+
const replaced = (0, replaceInvalidKeysWithMappedNames_1.replaceInvalidKeysWithMappedNames)([{ nmae: 'a' }, { nmae: 'b', extra: [{ nmae: 'c' }] }], new Map([['nmae', 'name']]));
|
|
180
|
+
node_assert_1.default.deepStrictEqual(replaced, [
|
|
181
|
+
{ name: 'a' },
|
|
182
|
+
{ name: 'b', extra: [{ name: 'c' }] },
|
|
183
|
+
]);
|
|
184
|
+
});
|
|
185
|
+
});
|
|
@@ -9,14 +9,31 @@ const node_assert_1 = __importDefault(require("node:assert"));
|
|
|
9
9
|
const compareShapes_1 = require("../compareShapes");
|
|
10
10
|
const AllVersionedSchemas_1 = require("../../../VersionedSchema/AllVersionedSchemas/AllVersionedSchemas");
|
|
11
11
|
const compatibilityCases_1 = require("../__mocks__/compatibilityCases");
|
|
12
|
+
(0, node_test_1.default)('@unit: schema versions compatibility cases must cover all adjacent transitions', () => {
|
|
13
|
+
const cases = new Set(compatibilityCases_1.compatibilityCases.map(testCase => `${testCase.type}:${testCase.from}->${testCase.to}`));
|
|
14
|
+
const transitions = new Set();
|
|
15
|
+
for (let idx = 0; idx < AllVersionedSchemas_1.allVersionedSchemas.length - 1; idx++) {
|
|
16
|
+
const current = AllVersionedSchemas_1.allVersionedSchemas[idx];
|
|
17
|
+
const next = AllVersionedSchemas_1.allVersionedSchemas[idx + 1];
|
|
18
|
+
if (current.type !== next.type) {
|
|
19
|
+
continue;
|
|
20
|
+
}
|
|
21
|
+
const from = current.version.split('_').at(-1);
|
|
22
|
+
const to = next.version.split('_').at(-1);
|
|
23
|
+
if (!from || !to) {
|
|
24
|
+
continue;
|
|
25
|
+
}
|
|
26
|
+
transitions.add(`${current.type}:${from}->${to}`);
|
|
27
|
+
}
|
|
28
|
+
node_assert_1.default.deepStrictEqual([...cases].sort(), [...transitions].sort(), 'compatibilityCases must include all adjacent schema transitions');
|
|
29
|
+
});
|
|
12
30
|
(0, node_test_1.default)('@unit: schema versions compatibility', () => {
|
|
13
31
|
for (const testCase of compatibilityCases_1.compatibilityCases) {
|
|
14
32
|
const { type, from, to, expect } = testCase;
|
|
15
33
|
const prev = AllVersionedSchemas_1.allVersionedSchemas.find(vs => vs.type === type && vs.version === `${type}_${from}`)?.baseSchema;
|
|
16
34
|
const next = AllVersionedSchemas_1.allVersionedSchemas.find(vs => vs.type === type && vs.version === `${type}_${to}`)?.baseSchema;
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
}
|
|
35
|
+
node_assert_1.default.ok(prev, `Previous schema was not found for ${type} ${from}`);
|
|
36
|
+
node_assert_1.default.ok(next, `Next schema was not found for ${type} ${to}`);
|
|
20
37
|
const issues = (0, compareShapes_1.compareShapes)(prev, next);
|
|
21
38
|
node_assert_1.default.deepStrictEqual(issues, expect, `${type} ${from} → ${to} mismatch`);
|
|
22
39
|
}
|
package/dist/common/VersionedSchema/Utils/__tests__/migrateDataToLatestSchemaVersion.test.js
CHANGED
|
@@ -73,3 +73,21 @@ const migrateDataToLatestSchemaVersion_1 = require("../migrateDataToLatestSchema
|
|
|
73
73
|
node_assert_1.default.strictEqual(result?.value.httpClient, 'fetch');
|
|
74
74
|
node_assert_1.default.strictEqual(result?.value.validationLibrary, ValidationLibrary_enum_1.ValidationLibrary.NONE);
|
|
75
75
|
});
|
|
76
|
+
(0, node_test_1.default)('@unit: migrateDataToLatestSchemaVersion (all schemas: chooses old options branch before unified)', () => {
|
|
77
|
+
const rawInput = {
|
|
78
|
+
input: './spec.json',
|
|
79
|
+
output: './dist',
|
|
80
|
+
httpClient: 'fetch',
|
|
81
|
+
exportCore: true,
|
|
82
|
+
};
|
|
83
|
+
const result = (0, migrateDataToLatestSchemaVersion_1.migrateDataToLatestSchemaVersion)({
|
|
84
|
+
rawInput,
|
|
85
|
+
migrationPlans: AllMigrationPlans_1.allMigrationPlans,
|
|
86
|
+
versionedSchemas: AllVersionedSchemas_1.allVersionedSchemas,
|
|
87
|
+
migrationMode: Enums_1.EMigrationMode.VALIDATE_CONFIG,
|
|
88
|
+
});
|
|
89
|
+
node_assert_1.default.ok(result);
|
|
90
|
+
node_assert_1.default.strictEqual(result?.schemaType, Enums_2.EVersionedSchemaType.UNIFIED_OPTIONS);
|
|
91
|
+
node_assert_1.default.strictEqual(result?.schemaVersion, 'UNIFIED_OPTIONS_v4');
|
|
92
|
+
node_assert_1.default.ok(result?.guessedVersion.latestVersion.startsWith('OPTIONS_'));
|
|
93
|
+
});
|
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
import { VersionedSchema, VersionMatchResult } from '../Types';
|
|
3
|
+
/**
|
|
4
|
+
* Determines the best matching schema version for input data.
|
|
5
|
+
* `invalid_value` issues are intentionally ignored to allow migration from older enum/value variants.
|
|
6
|
+
*/
|
|
3
7
|
export declare function determineBestMatchingSchemaVersion(inputData: Record<string, any>, versionedSchemas: VersionedSchema<z.ZodTypeAny>[]): VersionMatchResult;
|
|
4
8
|
//# sourceMappingURL=determineBestMatchingSchemaVersion.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"determineBestMatchingSchemaVersion.d.ts","sourceRoot":"","sources":["../../../../src/common/VersionedSchema/Utils/determineBestMatchingSchemaVersion.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;
|
|
1
|
+
{"version":3,"file":"determineBestMatchingSchemaVersion.d.ts","sourceRoot":"","sources":["../../../../src/common/VersionedSchema/Utils/determineBestMatchingSchemaVersion.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAIxB,OAAO,EAAE,eAAe,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAC;AAiE/D;;;GAGG;AACH,wBAAgB,kCAAkC,CAAC,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,gBAAgB,EAAE,eAAe,CAAC,CAAC,CAAC,UAAU,CAAC,EAAE,GAAG,kBAAkB,CAgDxJ"}
|