ts-openapi-codegen 1.0.0-beta.3 → 1.0.0-beta.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (128) hide show
  1. package/README.md +35 -1
  2. package/dist/cli/generate/runGenerateOpenApi.js +3 -3
  3. package/dist/cli/index.js +2 -1
  4. package/dist/common/Options.d.ts +1 -0
  5. package/dist/common/Options.d.ts.map +1 -1
  6. package/dist/common/VersionedSchema/Types.d.ts +1 -1
  7. package/dist/common/VersionedSchema/Types.d.ts.map +1 -1
  8. package/dist/common/VersionedSchema/Utils/determineBestMatchingSchemaVersion.d.ts +9 -0
  9. package/dist/common/VersionedSchema/Utils/determineBestMatchingSchemaVersion.d.ts.map +1 -0
  10. package/dist/common/VersionedSchema/Utils/determineBestMatchingSchemaVersion.js +44 -0
  11. package/dist/common/VersionedSchema/Utils/generateKeyMappingForInvalidKeys.d.ts +2 -0
  12. package/dist/common/VersionedSchema/Utils/generateKeyMappingForInvalidKeys.d.ts.map +1 -0
  13. package/dist/common/VersionedSchema/Utils/generateKeyMappingForInvalidKeys.js +27 -0
  14. package/dist/common/VersionedSchema/Utils/getErrorFieldsFromValidation.d.ts +6 -0
  15. package/dist/common/VersionedSchema/Utils/getErrorFieldsFromValidation.d.ts.map +1 -0
  16. package/dist/common/VersionedSchema/Utils/getErrorFieldsFromValidation.js +7 -0
  17. package/dist/common/VersionedSchema/Utils/{getUniqueAllShemasKeys.d.ts → getUniqueKeysFromSchemas.d.ts} +3 -3
  18. package/dist/common/VersionedSchema/Utils/getUniqueKeysFromSchemas.d.ts.map +1 -0
  19. package/dist/common/VersionedSchema/Utils/{getUniqueAllShemasKeys.js → getUniqueKeysFromSchemas.js} +4 -4
  20. package/dist/common/VersionedSchema/Utils/getUniqueObjectKeys.js +2 -2
  21. package/dist/common/VersionedSchema/Utils/joiHandlers.d.ts +3 -3
  22. package/dist/common/VersionedSchema/Utils/joiHandlers.d.ts.map +1 -1
  23. package/dist/common/VersionedSchema/Utils/joiHandlers.js +24 -17
  24. package/dist/common/VersionedSchema/Utils/{migrateToLatestVersion.d.ts → migrateDataToLatestSchemaVersion.d.ts} +5 -5
  25. package/dist/common/VersionedSchema/Utils/migrateDataToLatestSchemaVersion.d.ts.map +1 -0
  26. package/dist/common/VersionedSchema/Utils/migrateDataToLatestSchemaVersion.js +43 -0
  27. package/dist/common/VersionedSchema/Utils/replaceInvalidKeysWithMappedNames.d.ts +2 -0
  28. package/dist/common/VersionedSchema/Utils/replaceInvalidKeysWithMappedNames.d.ts.map +1 -0
  29. package/dist/common/VersionedSchema/Utils/replaceInvalidKeysWithMappedNames.js +18 -0
  30. package/dist/common/VersionedSchema/Utils/traverseObjectStructure.d.ts +3 -0
  31. package/dist/common/VersionedSchema/Utils/traverseObjectStructure.d.ts.map +1 -0
  32. package/dist/common/VersionedSchema/Utils/{traverseGeneric.js → traverseObjectStructure.js} +6 -4
  33. package/dist/common/VersionedSchema/Utils/validateAndSuggestKeyCorrections.d.ts +8 -0
  34. package/dist/common/VersionedSchema/Utils/validateAndSuggestKeyCorrections.d.ts.map +1 -0
  35. package/dist/common/VersionedSchema/Utils/validateAndSuggestKeyCorrections.js +44 -0
  36. package/dist/common/__tests__/__mock__/mockJoiSchema.d.ts +19 -0
  37. package/dist/common/__tests__/__mock__/mockJoiSchema.d.ts.map +1 -0
  38. package/dist/common/__tests__/__mock__/mockJoiSchema.js +14 -0
  39. package/dist/common/__tests__/determineBestMatchingSchemaVersion.test.d.ts +2 -0
  40. package/dist/common/__tests__/determineBestMatchingSchemaVersion.test.d.ts.map +1 -0
  41. package/dist/common/__tests__/determineBestMatchingSchemaVersion.test.js +38 -0
  42. package/dist/common/__tests__/generateKeyMappingForInvalidKeys.test.d.ts +2 -0
  43. package/dist/common/__tests__/generateKeyMappingForInvalidKeys.test.d.ts.map +1 -0
  44. package/dist/common/__tests__/generateKeyMappingForInvalidKeys.test.js +22 -0
  45. package/dist/common/__tests__/getUniqueKeysFromSchemas.test.d.ts +2 -0
  46. package/dist/common/__tests__/getUniqueKeysFromSchemas.test.d.ts.map +1 -0
  47. package/dist/common/__tests__/getUniqueKeysFromSchemas.test.js +20 -0
  48. package/dist/common/__tests__/getUniqueObjectKeys.test.d.ts +2 -0
  49. package/dist/common/__tests__/getUniqueObjectKeys.test.d.ts.map +1 -0
  50. package/dist/common/__tests__/getUniqueObjectKeys.test.js +24 -0
  51. package/dist/common/__tests__/mergeObjectSchemas.test.js +1 -1
  52. package/dist/common/__tests__/migrationForMultiOptions.test.js +85 -70
  53. package/dist/common/__tests__/migrationForOptions.test.js +28 -48
  54. package/dist/common/__tests__/replaceInvalidKeysWithMappedNames.test.d.ts +2 -0
  55. package/dist/common/__tests__/replaceInvalidKeysWithMappedNames.test.d.ts.map +1 -0
  56. package/dist/common/__tests__/replaceInvalidKeysWithMappedNames.test.js +25 -0
  57. package/dist/common/__tests__/validateAndSuggestKeyCorrections.test.d.ts +2 -0
  58. package/dist/common/__tests__/validateAndSuggestKeyCorrections.test.d.ts.map +1 -0
  59. package/dist/common/__tests__/validateAndSuggestKeyCorrections.test.js +25 -0
  60. package/dist/core/Context.d.ts +10 -1
  61. package/dist/core/Context.d.ts.map +1 -1
  62. package/dist/core/Context.js +8 -1
  63. package/dist/core/api/v2/parser/__tests__/getType.test.js +3 -3
  64. package/dist/core/api/v2/parser/getOperationParameters.d.ts.map +1 -1
  65. package/dist/core/api/v2/parser/getOperationParameters.js +9 -7
  66. package/dist/core/api/v3/parser/__tests__/getType.test.js +3 -3
  67. package/dist/core/api/v3/parser/getOperation.d.ts.map +1 -1
  68. package/dist/core/api/v3/parser/getOperation.js +4 -2
  69. package/dist/core/api/v3/parser/getOperationParameters.d.ts.map +1 -1
  70. package/dist/core/api/v3/parser/getOperationParameters.js +9 -7
  71. package/dist/core/index.d.ts.map +1 -1
  72. package/dist/core/index.js +3 -2
  73. package/dist/core/types/Consts.d.ts +10 -0
  74. package/dist/core/types/Consts.d.ts.map +1 -1
  75. package/dist/core/types/Consts.js +11 -1
  76. package/dist/core/types/Models.d.ts +3 -0
  77. package/dist/core/types/Models.d.ts.map +1 -1
  78. package/dist/core/utils/__mocks__/createOperationParameter.d.ts +3 -0
  79. package/dist/core/utils/__mocks__/createOperationParameter.d.ts.map +1 -0
  80. package/dist/core/utils/__mocks__/createOperationParameter.js +28 -0
  81. package/dist/core/utils/__tests__/sortByRequiredExtended.test.d.ts +2 -0
  82. package/dist/core/utils/__tests__/sortByRequiredExtended.test.d.ts.map +1 -0
  83. package/dist/core/utils/__tests__/sortByRequiredExtended.test.js +145 -0
  84. package/dist/core/utils/__tests__/sortByRequiredSimple.test.d.ts +2 -0
  85. package/dist/core/utils/__tests__/sortByRequiredSimple.test.d.ts.map +1 -0
  86. package/dist/core/utils/__tests__/sortByRequiredSimple.test.js +80 -0
  87. package/dist/core/utils/__tests__/writeClient.test.js +3 -3
  88. package/dist/core/utils/__tests__/writeClientCore.test.js +2 -2
  89. package/dist/core/utils/__tests__/writeClientIndex.test.js +2 -2
  90. package/dist/core/utils/__tests__/writeClientModels.test.js +2 -2
  91. package/dist/core/utils/__tests__/writeClientSchemas.test.js +2 -2
  92. package/dist/core/utils/__tests__/writeClientServices.test.js +2 -2
  93. package/dist/core/utils/getOpenApiSpec.d.ts.map +1 -1
  94. package/dist/core/utils/getOpenApiSpec.js +0 -7
  95. package/dist/core/utils/getPropertyGroupExtended.d.ts +4 -0
  96. package/dist/core/utils/getPropertyGroupExtended.d.ts.map +1 -0
  97. package/dist/core/utils/getPropertyGroupExtended.js +10 -0
  98. package/dist/core/utils/getPropertyGroupSimple.d.ts +3 -0
  99. package/dist/core/utils/getPropertyGroupSimple.d.ts.map +1 -0
  100. package/dist/core/utils/getPropertyGroupSimple.js +9 -0
  101. package/dist/core/utils/precompileTemplates.js +1 -1
  102. package/dist/core/utils/sortByRequiredExtended.d.ts +3 -0
  103. package/dist/core/utils/sortByRequiredExtended.d.ts.map +1 -0
  104. package/dist/core/utils/sortByRequiredExtended.js +15 -0
  105. package/dist/core/utils/sortByRequiredSimple.d.ts +3 -0
  106. package/dist/core/utils/sortByRequiredSimple.d.ts.map +1 -0
  107. package/dist/core/utils/sortByRequiredSimple.js +10 -0
  108. package/package.json +1 -1
  109. package/dist/common/VersionedSchema/Utils/getUniqueAllShemasKeys.d.ts.map +0 -1
  110. package/dist/common/VersionedSchema/Utils/guessVersion.d.ts +0 -3
  111. package/dist/common/VersionedSchema/Utils/guessVersion.d.ts.map +0 -1
  112. package/dist/common/VersionedSchema/Utils/guessVersion.js +0 -16
  113. package/dist/common/VersionedSchema/Utils/migrateToLatestVersion.d.ts.map +0 -1
  114. package/dist/common/VersionedSchema/Utils/migrateToLatestVersion.js +0 -34
  115. package/dist/common/VersionedSchema/Utils/traverseGeneric.d.ts +0 -3
  116. package/dist/common/VersionedSchema/Utils/traverseGeneric.d.ts.map +0 -1
  117. package/dist/common/VersionedSchema/Utils/validateUnknownKeys.d.ts +0 -2
  118. package/dist/common/VersionedSchema/Utils/validateUnknownKeys.d.ts.map +0 -1
  119. package/dist/common/VersionedSchema/Utils/validateUnknownKeys.js +0 -32
  120. package/dist/common/__tests__/guessVersion.test.d.ts +0 -2
  121. package/dist/common/__tests__/guessVersion.test.d.ts.map +0 -1
  122. package/dist/common/__tests__/guessVersion.test.js +0 -26
  123. package/dist/core/utils/__tests__/sortByRequired.test.d.ts +0 -2
  124. package/dist/core/utils/__tests__/sortByRequired.test.d.ts.map +0 -1
  125. package/dist/core/utils/__tests__/sortByRequired.test.js +0 -108
  126. package/dist/core/utils/sortByRequired.d.ts +0 -3
  127. package/dist/core/utils/sortByRequired.d.ts.map +0 -1
  128. package/dist/core/utils/sortByRequired.js +0 -18
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.
@@ -42,7 +42,7 @@ const MultiOptionsMigrationPlan_1 = require("../../common/VersionedSchema/MultiO
42
42
  const MultiOptionsVersionedSchemas_1 = require("../../common/VersionedSchema/MultiOptionsVersionedSchemas");
43
43
  const OptionsMigrationPlans_1 = require("../../common/VersionedSchema/OptionsMigrationPlans");
44
44
  const OptionsVersionedSchemas_1 = require("../../common/VersionedSchema/OptionsVersionedSchemas");
45
- const migrateToLatestVersion_1 = require("../../common/VersionedSchema/Utils/migrateToLatestVersion");
45
+ const migrateDataToLatestSchemaVersion_1 = require("../../common/VersionedSchema/Utils/migrateDataToLatestSchemaVersion");
46
46
  const OpenAPI = __importStar(require("../../core"));
47
47
  const isInstanceOfMultiOptions_1 = require("../../core/utils/isInstanceOfMultiOptions");
48
48
  /**
@@ -71,12 +71,12 @@ async function runGenerateOpenApi(options) {
71
71
  const preparedOptions = (0, Utils_1.convertArrayToObject)(configData);
72
72
  const isMultiOptions = (0, isInstanceOfMultiOptions_1.isInstanceOfMultioptions)(preparedOptions);
73
73
  const migratedOptions = isMultiOptions
74
- ? (0, migrateToLatestVersion_1.migrateToLatestVersion)({
74
+ ? (0, migrateDataToLatestSchemaVersion_1.migrateDataToLatestSchemaVersion)({
75
75
  rawInput: preparedOptions,
76
76
  migrationPlans: MultiOptionsMigrationPlan_1.multiOptionsMigrationPlan,
77
77
  versionedSchemas: MultiOptionsVersionedSchemas_1.multiOptionsVersionedSchema,
78
78
  })
79
- : (0, migrateToLatestVersion_1.migrateToLatestVersion)({
79
+ : (0, migrateDataToLatestSchemaVersion_1.migrateDataToLatestSchemaVersion)({
80
80
  rawInput: preparedOptions,
81
81
  migrationPlans: OptionsMigrationPlans_1.optionsMigrationPlans,
82
82
  versionedSchemas: OptionsVersionedSchemas_1.optionsVersionedSchemas,
package/dist/cli/index.js CHANGED
@@ -7,7 +7,7 @@ const runGenerateOpenApi_1 = require("./generate/runGenerateOpenApi");
7
7
  const APP_NAME = 'ts-openapi-codegen-cli';
8
8
  const APP_VERSION = '1.0.0';
9
9
  const program = new commander_1.Command();
10
- program.version(APP_VERSION).name(APP_NAME).description('Описание').addHelpText('before', 'Дополнительный текст');
10
+ program.version(APP_VERSION).name(APP_NAME).description('Description').addHelpText('before', 'Additional text');
11
11
  program
12
12
  .command('generate')
13
13
  .usage('[options]')
@@ -33,6 +33,7 @@ program
33
33
  .option('--useCancelableRequest <value>', 'Use cancelled promise as returned data type in request(default: false)', false)
34
34
  .addOption(new commander_1.Option('-l, --logLevel <level>', 'Logging level').choices([...Object.values(Enums_1.ELogLevel)]).default(Enums_1.ELogLevel.ERROR))
35
35
  .addOption(new commander_1.Option('-t, --logTarget <target>', 'Target of logging').choices([...Object.values(Enums_1.ELogOutput)]).default(Enums_1.ELogOutput.CONSOLE))
36
+ .option('-s, --sortByRequired', 'Property sorting strategy: simplified or extended')
36
37
  .action(async (options) => {
37
38
  await (0, runGenerateOpenApi_1.runGenerateOpenApi)(options);
38
39
  });
@@ -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,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"}
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;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"}
@@ -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: Set<string>) => boolean;
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;AAED,MAAM,MAAM,eAAe,GAAG,CAC5B,KAAK,EAAE,GAAG,EACV,OAAO,EAAE,CAAC,CAAC,EAAE,GAAG,KAAK,IAAI,EACzB,MAAM,EAAE,GAAG,CAAC,MAAM,CAAC,KAChB,OAAO,CAAC"}
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,2 @@
1
+ export declare function generateKeyMappingForInvalidKeys(rawInputKeys: string[], allowedKeys: Set<string>): Map<string, string>;
2
+ //# sourceMappingURL=generateKeyMappingForInvalidKeys.d.ts.map
@@ -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,6 @@
1
+ import Joi from 'joi';
2
+ export declare function getErrorFieldsFromValidation(error: Joi.ValidationError | undefined): {
3
+ path: string;
4
+ type: string;
5
+ }[];
6
+ //# sourceMappingURL=getErrorFieldsFromValidation.d.ts.map
@@ -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"}
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getErrorFieldsFromValidation = getErrorFieldsFromValidation;
4
+ // Auxiliary function for getting error fields from the Joi validation result
5
+ function getErrorFieldsFromValidation(error) {
6
+ return error?.details.map(detail => ({ path: Array.isArray(detail.path) ? detail.path.join('.') : detail.path, type: detail.type })) ?? [];
7
+ }
@@ -1,8 +1,8 @@
1
- import Joi from "joi";
1
+ import Joi from 'joi';
2
2
  /**
3
3
  * Get all the unique parameter keys of all Joi schemes in the array
4
4
  * @param schemas array of joi schemes
5
5
  * @returns All the unique parameter keys of all Joi schemes in the array
6
6
  */
7
- export declare function getUniqueAllShemasKeys(schemas: Joi.Schema[]): Set<string>;
8
- //# sourceMappingURL=getUniqueAllShemasKeys.d.ts.map
7
+ export declare function getUniqueKeysFromSchemas(schemas: Joi.Schema[]): Set<string>;
8
+ //# sourceMappingURL=getUniqueKeysFromSchemas.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getUniqueKeysFromSchemas.d.ts","sourceRoot":"","sources":["../../../../src/common/VersionedSchema/Utils/getUniqueKeysFromSchemas.ts"],"names":[],"mappings":"AAAA,OAAO,GAAG,MAAM,KAAK,CAAC;AAKtB;;;;GAIG;AACH,wBAAgB,wBAAwB,CAAC,OAAO,EAAE,GAAG,CAAC,MAAM,EAAE,eAQ7D"}
@@ -1,17 +1,17 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getUniqueAllShemasKeys = getUniqueAllShemasKeys;
3
+ exports.getUniqueKeysFromSchemas = getUniqueKeysFromSchemas;
4
4
  const joiHandlers_1 = require("./joiHandlers");
5
- const traverseGeneric_1 = require("./traverseGeneric");
5
+ const traverseObjectStructure_1 = require("./traverseObjectStructure");
6
6
  /**
7
7
  * Get all the unique parameter keys of all Joi schemes in the array
8
8
  * @param schemas array of joi schemes
9
9
  * @returns All the unique parameter keys of all Joi schemes in the array
10
10
  */
11
- function getUniqueAllShemasKeys(schemas) {
11
+ function getUniqueKeysFromSchemas(schemas) {
12
12
  const result = new Set();
13
13
  for (const schema of schemas) {
14
- (0, traverseGeneric_1.traverseGeneric)(schema, [joiHandlers_1.joiSchemaHandler, joiHandlers_1.joiDescHandler], result);
14
+ (0, traverseObjectStructure_1.traverseObjectStructure)(schema, [joiHandlers_1.handleJoiSchema, joiHandlers_1.handleJoiDescription], result);
15
15
  }
16
16
  return result;
17
17
  }
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getUniqueObjectKeys = getUniqueObjectKeys;
4
- const traverseGeneric_1 = require("./traverseGeneric");
4
+ const traverseObjectStructure_1 = require("./traverseObjectStructure");
5
5
  /**
6
6
  * Get unique keys from object properties (set of options)
7
7
  * @param rawInput object properties (set of options)
@@ -9,6 +9,6 @@ const traverseGeneric_1 = require("./traverseGeneric");
9
9
  */
10
10
  function getUniqueObjectKeys(rawInput) {
11
11
  const result = new Set();
12
- (0, traverseGeneric_1.traverseGeneric)(rawInput, [], result);
12
+ (0, traverseObjectStructure_1.traverseObjectStructure)(rawInput, [], result);
13
13
  return Array.from(result);
14
14
  }
@@ -1,6 +1,6 @@
1
- import { TraverseHandler } from "../Types";
1
+ import { TraverseHandler } from '../Types';
2
2
  /** Handler for Joi.Schema: only the launch remains .describe() */
3
- export declare const joiSchemaHandler: TraverseHandler;
3
+ export declare const handleJoiSchema: TraverseHandler<Set<string>>;
4
4
  /** Handler for the result of describe(): pulls out only the real keys of the field */
5
- export declare const joiDescHandler: TraverseHandler;
5
+ export declare const handleJoiDescription: TraverseHandler<Set<string>>;
6
6
  //# sourceMappingURL=joiHandlers.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"joiHandlers.d.ts","sourceRoot":"","sources":["../../../../src/common/VersionedSchema/Utils/joiHandlers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAE3C,kEAAkE;AAClE,eAAO,MAAM,gBAAgB,EAAE,eAM9B,CAAC;AAEF,sFAAsF;AACtF,eAAO,MAAM,cAAc,EAAE,eAsC5B,CAAC"}
1
+ {"version":3,"file":"joiHandlers.d.ts","sourceRoot":"","sources":["../../../../src/common/VersionedSchema/Utils/joiHandlers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAE3C,kEAAkE;AAClE,eAAO,MAAM,eAAe,EAAE,eAAe,CAAC,GAAG,CAAC,MAAM,CAAC,CAOxD,CAAC;AAEF,sFAAsF;AACtF,eAAO,MAAM,oBAAoB,EAAE,eAAe,CAAC,GAAG,CAAC,MAAM,CAAC,CAgD7D,CAAC"}
@@ -1,52 +1,59 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.joiDescHandler = exports.joiSchemaHandler = void 0;
3
+ exports.handleJoiDescription = exports.handleJoiSchema = void 0;
4
4
  /** Handler for Joi.Schema: only the launch remains .describe() */
5
- const joiSchemaHandler = (value, recurse) => {
5
+ const handleJoiSchema = (value, recurse) => {
6
6
  if (value && typeof value.describe === 'function') {
7
7
  recurse(value.describe());
8
- return true; // then the default bypass to the scheme itself is not needed.
8
+ // then the default bypass to the scheme itself is not needed.
9
+ return true;
9
10
  }
10
11
  return false;
11
12
  };
12
- exports.joiSchemaHandler = joiSchemaHandler;
13
+ exports.handleJoiSchema = handleJoiSchema;
13
14
  /** Handler for the result of describe(): pulls out only the real keys of the field */
14
- const joiDescHandler = (value, recurse, result) => {
15
+ const handleJoiDescription = (value, recurse, result) => {
15
16
  if (!value || typeof value !== 'object') {
16
17
  return false;
17
18
  }
18
- let did = false;
19
+ let processed = false;
19
20
  // only if there are keys/items/matches/patterns, we assume that this description
20
21
  if (value.keys && typeof value.keys === 'object') {
21
- did = true;
22
+ processed = true;
22
23
  for (const key of Object.keys(value.keys)) {
23
24
  result.add(key);
24
25
  recurse(value.keys[key]);
25
26
  }
26
27
  }
27
28
  if (Array.isArray(value.items)) {
28
- did = true;
29
- for (const item of value.items)
29
+ processed = true;
30
+ for (const item of value.items) {
30
31
  recurse(item);
32
+ }
31
33
  }
32
34
  if (Array.isArray(value.matches)) {
33
- did = true;
35
+ processed = true;
34
36
  for (const m of value.matches) {
35
- if (m.schema)
37
+ if (m.schema) {
36
38
  recurse(m.schema);
37
- if (m.then)
39
+ }
40
+ if (m.then) {
38
41
  recurse(m.then);
39
- if (m.otherwise)
42
+ }
43
+ if (m.otherwise) {
40
44
  recurse(m.otherwise);
45
+ }
41
46
  }
42
47
  }
43
48
  if (Array.isArray(value.patterns)) {
44
- did = true;
49
+ processed = true;
45
50
  for (const p of value.patterns) {
46
- if (p.rule)
51
+ if (p.rule) {
47
52
  recurse(p.rule);
53
+ }
48
54
  }
49
55
  }
50
- return did; // if this is the description, the default bypass is not needed.
56
+ // if this is the description, the default bypass is not needed.
57
+ return processed;
51
58
  };
52
- exports.joiDescHandler = joiDescHandler;
59
+ exports.handleJoiDescription = handleJoiDescription;
@@ -1,15 +1,15 @@
1
- import { EVersionedSchemaType } from "../Enums";
2
- import { SchemaMigrationPlan, VersionedSchema } from "../Types";
1
+ import { EVersionedSchemaType } from '../Enums';
2
+ import { SchemaMigrationPlan, VersionedSchema } from '../Types';
3
3
  type MigrateToLatestProps = {
4
4
  rawInput: Record<string, any>;
5
- versionedSchemas: VersionedSchema<Record<string, any>>[];
6
5
  migrationPlans: SchemaMigrationPlan<Record<string, any>, Record<string, any>>[];
6
+ versionedSchemas: VersionedSchema<Record<string, any>>[];
7
7
  };
8
8
  type MigrateToLatestResult = {
9
9
  value: Record<string, any>;
10
10
  schemaVersion: string;
11
11
  schemaType: EVersionedSchemaType;
12
12
  };
13
- export declare function migrateToLatestVersion({ rawInput, migrationPlans, versionedSchemas }: MigrateToLatestProps): MigrateToLatestResult | null;
13
+ export declare function migrateDataToLatestSchemaVersion({ rawInput, migrationPlans, versionedSchemas }: MigrateToLatestProps): MigrateToLatestResult | null;
14
14
  export {};
15
- //# sourceMappingURL=migrateToLatestVersion.d.ts.map
15
+ //# sourceMappingURL=migrateDataToLatestSchemaVersion.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"migrateDataToLatestSchemaVersion.d.ts","sourceRoot":"","sources":["../../../../src/common/VersionedSchema/Utils/migrateDataToLatestSchemaVersion.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,UAAU,CAAC;AAChD,OAAO,EAAE,mBAAmB,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAQhE,KAAK,oBAAoB,GAAG;IACxB,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC9B,cAAc,EAAE,mBAAmB,CAAC,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,EAAE,CAAC;IAChF,gBAAgB,EAAE,eAAe,CAAC,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,EAAE,CAAC;CAC5D,CAAC;AAEF,KAAK,qBAAqB,GAAG;IACzB,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC3B,aAAa,EAAE,MAAM,CAAC;IACtB,UAAU,EAAE,oBAAoB,CAAC;CACpC,CAAC;AAEF,wBAAgB,gCAAgC,CAAC,EAAE,QAAQ,EAAE,cAAc,EAAE,gBAAgB,EAAE,EAAE,oBAAoB,GAAG,qBAAqB,GAAG,IAAI,CAwCnJ"}
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.migrateDataToLatestSchemaVersion = migrateDataToLatestSchemaVersion;
4
+ const determineBestMatchingSchemaVersion_1 = require("./determineBestMatchingSchemaVersion");
5
+ const generateKeyMappingForInvalidKeys_1 = require("./generateKeyMappingForInvalidKeys");
6
+ const getUniqueKeysFromSchemas_1 = require("./getUniqueKeysFromSchemas");
7
+ const getUniqueObjectKeys_1 = require("./getUniqueObjectKeys");
8
+ const replaceInvalidKeysWithMappedNames_1 = require("./replaceInvalidKeysWithMappedNames");
9
+ const validateAndSuggestKeyCorrections_1 = require("./validateAndSuggestKeyCorrections");
10
+ function migrateDataToLatestSchemaVersion({ rawInput, migrationPlans, versionedSchemas }) {
11
+ const schemas = versionedSchemas.map(el => el.schema);
12
+ const allUniqueKeysFromSchemas = (0, getUniqueKeysFromSchemas_1.getUniqueKeysFromSchemas)(schemas);
13
+ const allUniqueKeysFromRawInput = (0, getUniqueObjectKeys_1.getUniqueObjectKeys)(rawInput);
14
+ (0, validateAndSuggestKeyCorrections_1.validateAndSuggestKeyCorrections)(allUniqueKeysFromRawInput, allUniqueKeysFromSchemas);
15
+ const guessedVersion = (0, determineBestMatchingSchemaVersion_1.determineBestMatchingSchemaVersion)(rawInput, versionedSchemas);
16
+ const guessedValidationSchema = schemas[guessedVersion.lastVersionIndex];
17
+ const schemaPossibleKeys = (0, getUniqueKeysFromSchemas_1.getUniqueKeysFromSchemas)([guessedValidationSchema]);
18
+ const replacingKeysMap = (0, generateKeyMappingForInvalidKeys_1.generateKeyMappingForInvalidKeys)(allUniqueKeysFromRawInput, schemaPossibleKeys);
19
+ let currentData = replacingKeysMap.size ? (0, replaceInvalidKeysWithMappedNames_1.replaceInvalidKeysWithMappedNames)(rawInput, replacingKeysMap) : rawInput;
20
+ for (let idx = guessedVersion.lastVersionIndex; idx < versionedSchemas.length - 1; idx++) {
21
+ const fromVersion = versionedSchemas[idx].version;
22
+ const migrationPlan = migrationPlans.find(p => p.fromVersion === fromVersion);
23
+ if (!migrationPlan) {
24
+ throw new Error(`No migration plan from ${fromVersion}`);
25
+ }
26
+ try {
27
+ const migratedRaw = migrationPlan.migrate(currentData);
28
+ const { error } = versionedSchemas[idx + 1].schema.validate(migratedRaw, { allowUnknown: false });
29
+ if (error) {
30
+ throw new Error(`Error during post-migration validation ${fromVersion}->${migrationPlan.toVersion}: ${error.message}`);
31
+ }
32
+ currentData = { ...migratedRaw };
33
+ }
34
+ catch (e) {
35
+ throw new Error(e.message);
36
+ }
37
+ }
38
+ const currentSchema = versionedSchemas[versionedSchemas.length - 1];
39
+ const { error, value } = currentSchema.schema.validate(currentData, { allowUnknown: false });
40
+ if (error)
41
+ return null;
42
+ return { value, schemaVersion: currentSchema.version, schemaType: currentSchema.type };
43
+ }
@@ -0,0 +1,2 @@
1
+ export declare function replaceInvalidKeysWithMappedNames(input: Record<string, any> | Record<string, any>[], keyMap: Map<string, string>): Record<string, any> | Record<string, any>[];
2
+ //# sourceMappingURL=replaceInvalidKeysWithMappedNames.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"replaceInvalidKeysWithMappedNames.d.ts","sourceRoot":"","sources":["../../../../src/common/VersionedSchema/Utils/replaceInvalidKeysWithMappedNames.ts"],"names":[],"mappings":"AAEA,wBAAgB,iCAAiC,CAC7C,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,EAClD,MAAM,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,GAC5B,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,CAe7C"}
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.replaceInvalidKeysWithMappedNames = replaceInvalidKeysWithMappedNames;
4
+ // Replacing incorrect keys
5
+ function replaceInvalidKeysWithMappedNames(input, keyMap) {
6
+ if (!input) {
7
+ throw new Error("The input data cannot be null or undefined.");
8
+ }
9
+ if (Array.isArray(input)) {
10
+ return input.map(item => replaceInvalidKeysWithMappedNames(item, keyMap));
11
+ }
12
+ const replacedKeys = Object.entries(input).map(([key, value]) => {
13
+ const newKey = keyMap.get(key) ?? key;
14
+ const newValue = Array.isArray(value) ? replaceInvalidKeysWithMappedNames(value, keyMap) : value;
15
+ return [newKey, newValue];
16
+ });
17
+ return Object.fromEntries(replacedKeys);
18
+ }
@@ -0,0 +1,3 @@
1
+ import { TraverseHandler } from "../Types";
2
+ export declare function traverseObjectStructure<T>(root: any, handlers: TraverseHandler<T>[], result: T): void;
3
+ //# sourceMappingURL=traverseObjectStructure.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"traverseObjectStructure.d.ts","sourceRoot":"","sources":["../../../../src/common/VersionedSchema/Utils/traverseObjectStructure.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAE3C,wBAAgB,uBAAuB,CAAC,CAAC,EACvC,IAAI,EAAE,GAAG,EACT,QAAQ,EAAE,eAAe,CAAC,CAAC,CAAC,EAAE,EAC9B,MAAM,EAAE,CAAC,QA6BV"}
@@ -1,8 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.traverseGeneric = traverseGeneric;
4
- function traverseGeneric(root, handlers, result) {
5
- const recurse = (v) => traverseGeneric(v, handlers, result);
3
+ exports.traverseObjectStructure = traverseObjectStructure;
4
+ function traverseObjectStructure(root, handlers, result) {
5
+ const recurse = (v) => traverseObjectStructure(v, handlers, result);
6
6
  // We try "special" handlers
7
7
  let handled = false;
8
8
  for (const handler of handlers) {
@@ -21,7 +21,9 @@ function traverseGeneric(root, handlers, result) {
21
21
  }
22
22
  else {
23
23
  for (const key of Object.keys(root)) {
24
- result.add(key);
24
+ if (result instanceof Set) {
25
+ result.add(key);
26
+ }
25
27
  recurse(root[key]);
26
28
  }
27
29
  }
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Optimized unknown key verification function using Levenshtein distance map.
3
+ *
4
+ * @param rawInputKeys Array of raw input keys
5
+ * @param allowedKeys Set of allowed (required) keys
6
+ */
7
+ export declare function validateAndSuggestKeyCorrections(rawInputKeys: string[], allowedKeys: Set<string>): void;
8
+ //# sourceMappingURL=validateAndSuggestKeyCorrections.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validateAndSuggestKeyCorrections.d.ts","sourceRoot":"","sources":["../../../../src/common/VersionedSchema/Utils/validateAndSuggestKeyCorrections.ts"],"names":[],"mappings":"AAEA;;;;;GAKG;AACH,wBAAgB,gCAAgC,CAAC,YAAY,EAAE,MAAM,EAAE,EAAE,WAAW,EAAE,GAAG,CAAC,MAAM,CAAC,QAiChG"}
@@ -0,0 +1,44 @@
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.validateAndSuggestKeyCorrections = validateAndSuggestKeyCorrections;
7
+ const leven_1 = __importDefault(require("leven"));
8
+ /**
9
+ * Optimized unknown key verification function using Levenshtein distance map.
10
+ *
11
+ * @param rawInputKeys Array of raw input keys
12
+ * @param allowedKeys Set of allowed (required) keys
13
+ */
14
+ function validateAndSuggestKeyCorrections(rawInputKeys, allowedKeys) {
15
+ const errors = [];
16
+ const distanceMap = new Map();
17
+ // Creating a distance map once for all keys
18
+ for (const key of rawInputKeys) {
19
+ if (!allowedKeys.has(key)) {
20
+ let bestMatch = null;
21
+ let bestDistance = Infinity;
22
+ for (const candidate of allowedKeys) {
23
+ const d = (0, leven_1.default)(key, candidate);
24
+ if (d < bestDistance) {
25
+ bestDistance = d;
26
+ bestMatch = candidate;
27
+ }
28
+ }
29
+ distanceMap.set(key, { bestMatch, bestDistance });
30
+ }
31
+ }
32
+ // Generating error messages
33
+ for (const [key, { bestMatch, bestDistance }] of distanceMap) {
34
+ if (bestMatch && bestDistance <= 3) {
35
+ errors.push(`The "${key}" field is not recognized. Perhaps you meant "${bestMatch}".`);
36
+ }
37
+ else {
38
+ errors.push(`The "${key}" field is not recognized.`);
39
+ }
40
+ }
41
+ if (errors.length) {
42
+ throw new Error(errors.join('\n'));
43
+ }
44
+ }
@@ -0,0 +1,19 @@
1
+ export declare const mockJoiSchema: (keys: string[], isValid: boolean, errors?: {
2
+ path: string;
3
+ type: string;
4
+ }[], isArray?: boolean) => {
5
+ validate: (input: any, options: any) => {
6
+ error: {
7
+ details: {
8
+ path: string;
9
+ type: string;
10
+ }[];
11
+ } | null;
12
+ value: any;
13
+ };
14
+ describe: () => {
15
+ keys: {} | undefined;
16
+ items: {}[] | undefined;
17
+ };
18
+ };
19
+ //# sourceMappingURL=mockJoiSchema.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mockJoiSchema.d.ts","sourceRoot":"","sources":["../../../../src/common/__tests__/__mock__/mockJoiSchema.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,aAAa,GAAI,MAAM,MAAM,EAAE,EAAE,SAAS,OAAO,EAAE,SAAQ;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,EAAO,EAAE,iBAAe;sBACxG,GAAG,WAAW,GAAG;;;sBADyC,MAAM;sBAAQ,MAAM;;;;;;;;;CASlG,CAAC"}