@kravc/schema 2.8.0-alpha.6 → 2.8.0-alpha.8

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 (118) hide show
  1. package/dist/CredentialFactory.d.ts +5 -318
  2. package/dist/CredentialFactory.d.ts.map +1 -1
  3. package/dist/CredentialFactory.js +5 -317
  4. package/dist/CredentialFactory.js.map +1 -1
  5. package/dist/Schema.d.ts +15 -420
  6. package/dist/Schema.d.ts.map +1 -1
  7. package/dist/Schema.js +13 -384
  8. package/dist/Schema.js.map +1 -1
  9. package/dist/ValidationError.d.ts +3 -49
  10. package/dist/ValidationError.d.ts.map +1 -1
  11. package/dist/ValidationError.js +3 -48
  12. package/dist/ValidationError.js.map +1 -1
  13. package/dist/Validator.d.ts +6 -470
  14. package/dist/Validator.d.ts.map +1 -1
  15. package/dist/Validator.js +50 -478
  16. package/dist/Validator.js.map +1 -1
  17. package/dist/helpers/cleanupAttributes.d.ts +3 -32
  18. package/dist/helpers/cleanupAttributes.d.ts.map +1 -1
  19. package/dist/helpers/cleanupAttributes.js +1 -30
  20. package/dist/helpers/cleanupAttributes.js.map +1 -1
  21. package/dist/helpers/cleanupNulls.d.ts +1 -25
  22. package/dist/helpers/cleanupNulls.d.ts.map +1 -1
  23. package/dist/helpers/cleanupNulls.js +2 -61
  24. package/dist/helpers/cleanupNulls.js.map +1 -1
  25. package/dist/helpers/createSchemasMap.d.ts +2 -93
  26. package/dist/helpers/createSchemasMap.d.ts.map +1 -1
  27. package/dist/helpers/createSchemasMap.js +4 -162
  28. package/dist/helpers/createSchemasMap.js.map +1 -1
  29. package/dist/helpers/getReferenceIds.d.ts +1 -165
  30. package/dist/helpers/getReferenceIds.d.ts.map +1 -1
  31. package/dist/helpers/getReferenceIds.js +2 -166
  32. package/dist/helpers/getReferenceIds.js.map +1 -1
  33. package/dist/helpers/got.d.ts +2 -58
  34. package/dist/helpers/got.d.ts.map +1 -1
  35. package/dist/helpers/got.js +1 -57
  36. package/dist/helpers/got.js.map +1 -1
  37. package/dist/helpers/mapObjectProperties.d.ts +2 -144
  38. package/dist/helpers/mapObjectProperties.d.ts.map +1 -1
  39. package/dist/helpers/mapObjectProperties.js +1 -142
  40. package/dist/helpers/mapObjectProperties.js.map +1 -1
  41. package/dist/helpers/normalizeAttributes.d.ts +3 -211
  42. package/dist/helpers/normalizeAttributes.d.ts.map +1 -1
  43. package/dist/helpers/normalizeAttributes.js +1 -209
  44. package/dist/helpers/normalizeAttributes.js.map +1 -1
  45. package/dist/helpers/normalizeProperties.d.ts +1 -165
  46. package/dist/helpers/normalizeProperties.d.ts.map +1 -1
  47. package/dist/helpers/normalizeProperties.js +1 -164
  48. package/dist/helpers/normalizeProperties.js.map +1 -1
  49. package/dist/helpers/normalizeRequired.d.ts +1 -153
  50. package/dist/helpers/normalizeRequired.d.ts.map +1 -1
  51. package/dist/helpers/normalizeRequired.js +0 -151
  52. package/dist/helpers/normalizeRequired.js.map +1 -1
  53. package/dist/helpers/normalizeType.d.ts +1 -77
  54. package/dist/helpers/normalizeType.d.ts.map +1 -1
  55. package/dist/helpers/normalizeType.js +11 -139
  56. package/dist/helpers/normalizeType.js.map +1 -1
  57. package/dist/helpers/nullifyEmptyValues.d.ts +1 -135
  58. package/dist/helpers/nullifyEmptyValues.d.ts.map +1 -1
  59. package/dist/helpers/nullifyEmptyValues.js +13 -143
  60. package/dist/helpers/nullifyEmptyValues.js.map +1 -1
  61. package/dist/helpers/removeRequiredAndDefault.d.ts +2 -102
  62. package/dist/helpers/removeRequiredAndDefault.d.ts.map +1 -1
  63. package/dist/helpers/removeRequiredAndDefault.js +1 -100
  64. package/dist/helpers/removeRequiredAndDefault.js.map +1 -1
  65. package/dist/helpers/validateId.d.ts +1 -36
  66. package/dist/helpers/validateId.d.ts.map +1 -1
  67. package/dist/helpers/validateId.js +1 -36
  68. package/dist/helpers/validateId.js.map +1 -1
  69. package/dist/ld/documentLoader.d.ts +1 -1
  70. package/dist/ld/documentLoader.d.ts.map +1 -1
  71. package/dist/ld/documentLoader.js +1 -1
  72. package/dist/ld/documentLoader.js.map +1 -1
  73. package/dist/ld/getLinkedDataAttributeType.d.ts +1 -1
  74. package/dist/ld/getLinkedDataAttributeType.d.ts.map +1 -1
  75. package/dist/ld/getLinkedDataAttributeType.js +1 -1
  76. package/dist/ld/getLinkedDataAttributeType.js.map +1 -1
  77. package/dist/ld/getLinkedDataContext.d.ts +1 -1
  78. package/dist/ld/getLinkedDataContext.d.ts.map +1 -1
  79. package/dist/ld/getLinkedDataContext.js +1 -1
  80. package/dist/ld/getLinkedDataContext.js.map +1 -1
  81. package/package.json +2 -2
  82. package/src/CredentialFactory.ts +5 -318
  83. package/src/Schema.ts +17 -427
  84. package/src/ValidationError.ts +5 -52
  85. package/src/Validator.ts +19 -483
  86. package/src/__tests__/CredentialFactory.test.ts +1 -1
  87. package/src/__tests__/Schema.test.ts +3 -8
  88. package/src/__tests__/ValidationError.test.ts +4 -2
  89. package/src/__tests__/Validator.test.ts +21 -4
  90. package/src/helpers/__tests__/cleanupAttributes.test.ts +3 -1
  91. package/src/helpers/__tests__/createSchemasMap.test.ts +1 -1
  92. package/src/helpers/__tests__/mapObjectProperties.test.ts +2 -1
  93. package/src/helpers/__tests__/normalizeAttributes.test.ts +4 -2
  94. package/src/helpers/__tests__/normalizeProperties.test.ts +3 -1
  95. package/src/helpers/__tests__/normalizeRequired.test.ts +4 -9
  96. package/src/helpers/__tests__/nullifyEmptyValues.test.ts +43 -12
  97. package/src/helpers/__tests__/removeRequiredAndDefault.test.ts +3 -10
  98. package/src/helpers/cleanupAttributes.ts +6 -44
  99. package/src/helpers/cleanupNulls.ts +2 -63
  100. package/src/helpers/createSchemasMap.ts +4 -163
  101. package/src/helpers/getReferenceIds.ts +2 -173
  102. package/src/helpers/got.ts +3 -59
  103. package/src/helpers/mapObjectProperties.ts +4 -156
  104. package/src/helpers/normalizeAttributes.ts +7 -211
  105. package/src/helpers/normalizeProperties.ts +1 -172
  106. package/src/helpers/normalizeRequired.ts +1 -161
  107. package/src/helpers/normalizeType.ts +11 -139
  108. package/src/helpers/nullifyEmptyValues.ts +10 -145
  109. package/src/helpers/removeRequiredAndDefault.ts +1 -106
  110. package/src/helpers/validateId.ts +1 -36
  111. package/src/ld/documentLoader.ts +1 -1
  112. package/src/ld/getLinkedDataAttributeType.ts +1 -1
  113. package/src/ld/getLinkedDataContext.ts +1 -1
  114. package/src/{helpers/JsonSchema.ts → types.d.ts} +12 -16
  115. package/dist/helpers/JsonSchema.d.ts +0 -99
  116. package/dist/helpers/JsonSchema.d.ts.map +0 -1
  117. package/dist/helpers/JsonSchema.js +0 -3
  118. package/dist/helpers/JsonSchema.js.map +0 -1
@@ -5,36 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const lodash_1 = require("lodash");
7
7
  const got_1 = __importDefault(require("./got"));
8
- /**
9
- * Removes properties from an object that are not defined in the JSON schema.
10
- *
11
- * **Intent:**
12
- * This function ensures that objects conform to their schema definition by removing
13
- * any properties that are not explicitly defined in the schema. It performs a deep
14
- * cleanup, recursively processing nested objects, arrays, and schema references.
15
- *
16
- * **Use Cases:**
17
- * - **Third-party API integrations**: When integrating with external services (e.g., Telegram)
18
- * that may send additional fields you don't want to process, this function allows you
19
- * to define a minimal schema and automatically strip unwanted properties.
20
- * - **Data sanitization**: Clean up objects received from external sources or user input
21
- * before validation or processing, ensuring only expected fields are present.
22
- * - **Schema enforcement**: Enforce strict schema compliance by removing any properties
23
- * that don't match the defined schema structure.
24
- * - **Pre-validation cleanup**: Remove extraneous properties before schema validation to
25
- * prevent validation errors from unexpected fields.
26
- *
27
- * **Behavior:**
28
- * - Mutates the input object in-place (does not return a new object)
29
- * - Recursively processes nested objects, arrays, and schema references ($ref)
30
- * - Skips enum schemas (returns early without modification)
31
- * - Only processes object values (skips null, undefined, and primitive values)
32
- * - Handles array items by cleaning each object item according to the array's item schema
33
- *
34
- * @param object - The target object to clean up (mutated in-place)
35
- * @param jsonSchema - The JSON schema defining allowed properties
36
- * @param schemasMap - Optional map of schema IDs to schema definitions for resolving $ref references
37
- */
8
+ /** Removes properties from an object that are not defined in the JSON schema. */
38
9
  const cleanupAttributes = (object, jsonSchema, schemasMap = {}) => {
39
10
  const { enum: enumItems } = jsonSchema;
40
11
  const isEnum = !!enumItems;
@@ -1 +1 @@
1
- {"version":3,"file":"cleanupAttributes.js","sourceRoot":"","sources":["../../src/helpers/cleanupAttributes.ts"],"names":[],"mappings":";;;;;AAAA,mCAAqC;AAErC,gDAAwB;AAYxB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,MAAM,iBAAiB,GAAG,CACxB,MAAoB,EACpB,UAAsB,EACtB,aAA6B,EAAE,EAC/B,EAAE;IACF,MAAM,EAAE,IAAI,EAAE,SAAS,EAAE,GAAI,UAAyB,CAAC;IAEvD,MAAM,MAAM,GAAG,CAAC,CAAC,SAAS,CAAC;IAE3B,IAAI,MAAM,EAAE,CAAC;QACX,OAAO;IACT,CAAC;IAED,MAAM,YAAY,GAAI,UAA2B,CAAC;IAElD,qDAAqD;IACrD,IAAI,CAAC,YAAY,CAAC,UAAU,EAAE,CAAC;QAC7B,OAAO;IACT,CAAC;IAED,KAAK,MAAM,SAAS,IAAI,MAAM,EAAE,CAAC;QAC/B,MAAM,QAAQ,GAAG,YAAY,CAAC,UAAU,CAAC,SAAS,CAAC,CAAC;QAEpD,MAAM,mBAAmB,GAAG,IAAA,oBAAW,EAAC,QAAQ,CAAC,CAAC;QAElD,IAAI,mBAAmB,EAAE,CAAC;YACxB,yEAAyE;YACzE,OAAO,MAAM,CAAC,SAAS,CAAC,CAAC;YACzB,SAAS;QACX,CAAC;QAED,MAAM,EAAE,IAAI,EAAE,WAAW,EAAE,GAAI,QAAoC,CAAC;QAEpE,MAAM,WAAW,GAAG,CAAC,IAAA,oBAAW,EAAC,WAAW,CAAC,CAAC;QAE9C,IAAI,WAAW,E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AI,CAAC,CAAC;oBAEvB,IAAI,YAAY,EAAE,CAAC;wBACjB,iBAAiB,CAAC,IAAoB,EAAE,UAAU,EAAE,UAAU,CAAC,CAAC;oBAClE,CAAC;gBACH,CAAC;YACH,CAAC;QACH,CAAC;IACH,CAAC;AACH,CAAC,CAAC;AAEF,kBAAe,iBAAiB,CAAC"}
@@ -1,27 +1,3 @@
1
- /**
2
- * Returns a deep copy of the object with all null properties removed.
3
- *
4
- * This is the main exported function that creates a clone of the input object
5
- * and removes all null properties recursively before returning it.
6
- *
7
- * @param object - The object to clean (will be cloned, original is not modified)
8
- * @returns A new object with all null properties removed recursively
9
- *
10
- * @example
11
- * ```typescript
12
- * const dirty = {
13
- * name: 'John',
14
- * age: null,
15
- * address: {
16
- * street: 'Main St',
17
- * zip: null
18
- * }
19
- * };
20
- *
21
- * const clean = cleanupNulls(dirty);
22
- * // Result: { name: 'John', address: { street: 'Main St' } }
23
- * // Original 'dirty' object is unchanged
24
- * ```
25
- */
1
+ /** Returns a deep copy of the object with all null properties removed. */
26
2
  export default function (object: Record<string, unknown>): Record<string, unknown>;
27
3
  //# sourceMappingURL=cleanupNulls.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"cleanupNulls.d.ts","sourceRoot":"","sources":["../../src/helpers/cleanupNulls.ts"],"names":[],"mappings":"AA0EA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,MAAM,CAAC,OAAO,WAAW,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,2BAMvD"}
1
+ {"version":3,"file":"cleanupNulls.d.ts","sourceRoot":"","sources":["../../src/helpers/cleanupNulls.ts"],"names":[],"mappings":"AAqCA,0EAA0E;AAC1E,MAAM,CAAC,OAAO,WAAW,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,2BAMvD"}
@@ -3,42 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.default = default_1;
4
4
  const lodash_1 = require("lodash");
5
5
  const { isArray } = Array;
6
- /**
7
- * Recursively removes null properties from an object.
8
- *
9
- * **Intent:**
10
- * This function provides a deep cleanup of objects by removing all properties
11
- * that have `null` values. It's designed to sanitize objects before validation,
12
- * storage, or transmission by eliminating explicitly null fields.
13
- *
14
- * **Use Cases:**
15
- * - **Pre-validation cleanup**: Remove null values before schema validation to
16
- * prevent validation errors from optional fields that were explicitly set to null.
17
- * This is particularly useful when `shouldCleanupNulls` is enabled in the Validator,
18
- * allowing you to clean objects before `cleanupAttributes` removes undefined properties.
19
- * - **Data sanitization**: Clean objects received from external sources (APIs, user input,
20
- * databases) by removing null properties that may have been set during data transformation
21
- * or migration processes.
22
- * - **API response normalization**: Prepare objects for API responses by removing null fields,
23
- * reducing payload size and ensuring consistent data structures across different endpoints.
24
- * - **Database operations**: Clean objects before database storage or updates, removing
25
- * null fields that might cause issues with database constraints or indexing.
26
- * - **JSON serialization optimization**: Reduce JSON payload size by removing null properties
27
- * before serialization, which is especially beneficial for large objects or high-frequency
28
- * API calls.
29
- * - **Optional field handling**: Remove explicitly null optional fields that weren't provided
30
- * by the user, distinguishing between "field not provided" (undefined) and "field set to null".
31
- *
32
- * **Behavior:**
33
- * - Returns a deep clone of the input object (does not mutate the original)
34
- * - Recursively processes nested objects and arrays at all depth levels
35
- * - Only removes properties with `null` values (preserves `undefined`, `0`, `false`, `''`, etc.)
36
- * - Skips non-object values (returns early for primitives)
37
- * - Handles arrays by recursively processing each item
38
- * - Preserves object structure and non-null values exactly as they are
39
- *
40
- * @param target - The target object to clean (processed recursively, not mutated)
41
- */
6
+ /** Recursively removes null properties from an object. */
42
7
  const cleanupNulls = (target) => {
43
8
  const shouldSkip = !(0, lodash_1.isObject)(target);
44
9
  if (shouldSkip) {
@@ -62,31 +27,7 @@ const cleanupNulls = (target) => {
62
27
  }
63
28
  }
64
29
  };
65
- /**
66
- * Returns a deep copy of the object with all null properties removed.
67
- *
68
- * This is the main exported function that creates a clone of the input object
69
- * and removes all null properties recursively before returning it.
70
- *
71
- * @param object - The object to clean (will be cloned, original is not modified)
72
- * @returns A new object with all null properties removed recursively
73
- *
74
- * @example
75
- * ```typescript
76
- * const dirty = {
77
- * name: 'John',
78
- * age: null,
79
- * address: {
80
- * street: 'Main St',
81
- * zip: null
82
- * }
83
- * };
84
- *
85
- * const clean = cleanupNulls(dirty);
86
- * // Result: { name: 'John', address: { street: 'Main St' } }
87
- * // Original 'dirty' object is unchanged
88
- * ```
89
- */
30
+ /** Returns a deep copy of the object with all null properties removed. */
90
31
  function default_1(object) {
91
32
  const clone = (0, lodash_1.cloneDeep)(object);
92
33
  cleanupNulls(clone);
@@ -1 +1 @@
1
- {"version":3,"file":"cleanupNulls.js","sourceRoot":"","sources":["../../src/helpers/cleanupNulls.ts"],"names":[],"mappings":";;AAmGA,4BAMC;AAzGD,mCAA6C;AAI7C,MAAM,EAAE,OAAO,EAAE,GAAG,KAAK,CAAC;AAE1B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AACH,MAAM,YAAY,GAAG,CAAC,MAAoB,EAAE,EAAE;IAC5C,MAAM,UAAU,GAAG,CAAC,IAAA,iBAAQ,EAAC,MAAM,CAAC,CAAC;IAErC,IAAI,UAAU,EAAE,CAAC;QACf,OAAO;IACT,CAAC;IAED,KAAK,MAAM,GAAG,IAAI,MAAM,EAAE,CAAC;QACzB,MAAM,KAAK,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC;QAE1B,IAAI,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;YACnB,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;gBACzB,YAAY,CAAC,IAAI,CAAC,CAAC;YACrB,CAAC;YAED,SAAS;QACX,CAAC;QAED,IAAI,IAAA,iBAAQ,EAAC,KAAK,CAAC,EAAE,CAAC;YACpB,YAAY,CAAC,KAAgC,CAAC,CAAC;YAE/C,SAAS;QACX,CAAC;QAED,MAAM,MAAM,GAAG,KAAK,KAAK,IAAI,CAAC;QAE9B,IA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AAyB,MAA+B;IACtD,MAAM,KAAK,GAAG,IAAA,kBAAS,EAAC,MAAM,CAAC,CAAC;IAEhC,YAAY,CAAC,KAAK,CAAC,CAAC;IAEpB,OAAO,KAAK,CAAC;AACf,CAAC;AAAA,CAAC"}
@@ -1,98 +1,7 @@
1
1
  import Schema from '../Schema';
2
- /**
3
- * Reads schema source from YAML file and returns a Schema instance.
4
- *
5
- * **Intent:** Load and parse a single YAML schema file, extracting the schema ID
6
- * from the filename and creating a Schema instance for use in validation or
7
- * schema composition.
8
- *
9
- * **Use Cases:**
10
- * - Load individual schema files during application startup
11
- * - Parse YAML schema definitions into Schema instances
12
- * - Extract schema identifiers from file paths automatically
13
- * - Support both enum and properties-based schemas from YAML files
14
- *
15
- * @param yamlPath - Absolute or relative path to the YAML schema file
16
- * @returns A Schema instance with ID extracted from the filename (without .yaml extension)
17
- *
18
- * **Example:**
19
- * ```typescript
20
- * const schema = loadSync('/path/to/schemas/User.yaml');
21
- * // schema.id === 'User'
22
- * // schema.source contains the parsed YAML content
23
- * ```
24
- *
25
- * **Example - Enum Schema:**
26
- * ```typescript
27
- * const statusSchema = loadSync('/path/to/schemas/Status.yaml');
28
- * // If Status.yaml contains: { enum: ['PENDING', 'ACTIVE'] }
29
- * // statusSchema.isEnum === true
30
- * ```
31
- */
2
+ /** Reads schema source from YAML file and returns a Schema instance. */
32
3
  export declare const loadSync: (yamlPath: string) => Schema;
33
- /**
34
- * Creates a map of schemas by ID, loading from YAML files and merging with programmatic schemas.
35
- *
36
- * **Intent:** Build a centralized schema registry that combines file-based YAML schemas
37
- * with programmatically created Schema instances, providing a unified lookup mechanism
38
- * by schema ID. This enables hybrid schema management where some schemas are defined
39
- * in YAML files while others are created dynamically in code.
40
- *
41
- * **Use Cases:**
42
- * - Initialize schema registries for validators from both files and code
43
- * - Support schema composition where base schemas come from files and extended
44
- * schemas are created programmatically
45
- * - Enable schema overriding where programmatic schemas can replace file-based ones
46
- * - Build schema maps for credential factories or API validation systems
47
- * - Support development workflows where schemas evolve from YAML to code
48
- *
49
- * @param servicePath - Path to directory containing YAML schema files (searched recursively)
50
- * @param modules - Array of Schema instances or other values (non-Schema values are filtered out)
51
- * @returns Record mapping schema IDs to Schema instances, with modules schemas overriding YAML schemas
52
- *
53
- * **Example - Basic Usage:**
54
- * ```typescript
55
- * const schemasMap = createSchemasMap('/path/to/examples/schemas', []);
56
- * // Returns: {
57
- * // FavoriteItem: Schema { id: 'FavoriteItem', ... },
58
- * // Profile: Schema { id: 'Profile', ... },
59
- * // Status: Schema { id: 'Status', ... },
60
- * // Preferences: Schema { id: 'Preferences', ... }
61
- * // }
62
- * ```
63
- *
64
- * **Example - Merging Programmatic Schemas:**
65
- * ```typescript
66
- * const customSchema = new Schema(
67
- * { customField: { type: 'string' } },
68
- * 'CustomSchema'
69
- * );
70
- * const schemasMap = createSchemasMap('/path/to/schemas', [customSchema]);
71
- * // schemasMap contains both YAML schemas and CustomSchema
72
- * ```
73
- *
74
- * **Example - Overriding YAML Schemas:**
75
- * ```typescript
76
- * const updatedProfile = new Schema(
77
- * { name: { type: 'string' }, newField: { type: 'number' } },
78
- * 'Profile'
79
- * );
80
- * const schemasMap = createSchemasMap('/path/to/schemas', [updatedProfile]);
81
- * // schemasMap.Profile is the updatedProfile instance, not the YAML version
82
- * ```
83
- *
84
- * **Example - Filtering Non-Schema Values:**
85
- * ```typescript
86
- * const schema = new Schema({ field: { type: 'string' } }, 'Test');
87
- * const schemasMap = createSchemasMap('/path/to/schemas', [
88
- * schema,
89
- * 'not a schema',
90
- * { id: 'fake' },
91
- * null
92
- * ]);
93
- * // Only the Schema instance is included, other values are ignored
94
- * ```
95
- */
4
+ /** Creates a map of schemas by ID, loading from YAML files and merging with programmatic schemas. */
96
5
  declare const createSchemasMap: (servicePath: string, modules: unknown[]) => Record<string, Schema>;
97
6
  export default createSchemasMap;
98
7
  //# sourceMappingURL=createSchemasMap.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"createSchemasMap.d.ts","sourceRoot":"","sources":["../../src/helpers/createSchemasMap.ts"],"names":[],"mappings":"AACA,OAAO,MAAM,MAAM,WAAW,CAAC;AAM/B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,eAAO,MAAM,QAAQ,GAAI,UAAU,MAAM,WAUxC,CAAC;AAuFF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8DG;AACH,QAAA,MAAM,gBAAgB,GAAI,aAAa,MAAM,EAAE,SAAS,OAAO,EAAE,KAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAYxF,CAAC;AAEF,eAAe,gBAAgB,CAAC"}
1
+ {"version":3,"file":"createSchemasMap.d.ts","sourceRoot":"","sources":["../../src/helpers/createSchemasMap.ts"],"names":[],"mappings":"AACA,OAAO,MAAM,MAAM,WAAW,CAAC;AAK/B,wEAAwE;AACxE,eAAO,MAAM,QAAQ,GAAI,UAAU,MAAM,WAUxC,CAAC;AAoBF,qGAAqG;AACrG,QAAA,MAAM,gBAAgB,GAAI,aAAa,MAAM,EAAE,SAAS,OAAO,EAAE,KAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAYxF,CAAC;AAEF,eAAe,gBAAgB,CAAC"}
@@ -9,36 +9,7 @@ const Schema_1 = __importDefault(require("../Schema"));
9
9
  const js_yaml_1 = require("js-yaml");
10
10
  const lodash_1 = require("lodash");
11
11
  const fs_1 = require("fs");
12
- /**
13
- * Reads schema source from YAML file and returns a Schema instance.
14
- *
15
- * **Intent:** Load and parse a single YAML schema file, extracting the schema ID
16
- * from the filename and creating a Schema instance for use in validation or
17
- * schema composition.
18
- *
19
- * **Use Cases:**
20
- * - Load individual schema files during application startup
21
- * - Parse YAML schema definitions into Schema instances
22
- * - Extract schema identifiers from file paths automatically
23
- * - Support both enum and properties-based schemas from YAML files
24
- *
25
- * @param yamlPath - Absolute or relative path to the YAML schema file
26
- * @returns A Schema instance with ID extracted from the filename (without .yaml extension)
27
- *
28
- * **Example:**
29
- * ```typescript
30
- * const schema = loadSync('/path/to/schemas/User.yaml');
31
- * // schema.id === 'User'
32
- * // schema.source contains the parsed YAML content
33
- * ```
34
- *
35
- * **Example - Enum Schema:**
36
- * ```typescript
37
- * const statusSchema = loadSync('/path/to/schemas/Status.yaml');
38
- * // If Status.yaml contains: { enum: ['PENDING', 'ACTIVE'] }
39
- * // statusSchema.isEnum === true
40
- * ```
41
- */
12
+ /** Reads schema source from YAML file and returns a Schema instance. */
42
13
  const loadSync = (yamlPath) => {
43
14
  const schemaId = yamlPath
44
15
  .split('/')
@@ -49,145 +20,16 @@ const loadSync = (yamlPath) => {
49
20
  return new Schema_1.default(source, schemaId);
50
21
  };
51
22
  exports.loadSync = loadSync;
52
- /**
53
- * Recursively lists all files in a directory and its subdirectories.
54
- *
55
- * **Intent:** Traverse a directory tree and collect all file paths, enabling
56
- * discovery of schema files nested in subdirectories without manual path specification.
57
- *
58
- * **Use Cases:**
59
- * - Find all schema files in a directory structure
60
- * - Support organized schema layouts with nested folders
61
- * - Enable schema discovery without hardcoding file paths
62
- * - Prepare file list for filtering and processing
63
- *
64
- * @param servicePath - Path to the directory to traverse
65
- * @returns Array of absolute file paths found in the directory tree
66
- *
67
- * **Example:**
68
- * ```typescript
69
- * const files = listFilesSync('/path/to/schemas');
70
- * // Returns: [
71
- * // '/path/to/schemas/User.yaml',
72
- * // '/path/to/schemas/nested/Profile.yaml',
73
- * // '/path/to/schemas/nested/deep/Status.yaml'
74
- * // ]
75
- * ```
76
- *
77
- * **Example - Flat Directory:**
78
- * ```typescript
79
- * const files = listFilesSync('/path/to/schemas');
80
- * // Returns: [
81
- * // '/path/to/schemas/User.yaml',
82
- * // '/path/to/schemas/Profile.yaml'
83
- * // ]
84
- * ```
85
- */
23
+ /** Recursively lists all files in a directory and its subdirectories. */
86
24
  const listFilesSync = (servicePath) => (0, fs_1.readdirSync)(servicePath)
87
25
  .reduce((filePaths, fileName) => (0, fs_1.statSync)(path_1.default.join(servicePath, fileName)).isDirectory() ?
88
26
  filePaths.concat(listFilesSync(path_1.default.join(servicePath, fileName))) :
89
27
  filePaths.concat(path_1.default.join(servicePath, fileName)), []);
90
- /**
91
- * Reads all YAML schema files from a directory and creates Schema instances.
92
- *
93
- * **Intent:** Bulk load schema definitions from YAML files in a directory,
94
- * automatically discovering and parsing all schema files for use in schema
95
- * registries or validators.
96
- *
97
- * **Use Cases:**
98
- * - Load all schemas from a schemas directory at application startup
99
- * - Initialize schema registries from file-based definitions
100
- * - Support schema-as-code workflows where schemas are stored as YAML files
101
- * - Enable automatic schema discovery without manual registration
102
- *
103
- * @param servicePath - Path to the directory containing YAML schema files
104
- * @returns Array of Schema instances, one for each YAML file found
105
- *
106
- * **Example:**
107
- * ```typescript
108
- * const schemas = readSchemasSync('/path/to/examples/schemas');
109
- * // Returns: [
110
- * // Schema { id: 'FavoriteItem', ... },
111
- * // Schema { id: 'Profile', ... },
112
- * // Schema { id: 'Status', ... },
113
- * // Schema { id: 'Preferences', ... }
114
- * // ]
115
- * ```
116
- *
117
- * **Example - With Nested Directories:**
118
- * ```typescript
119
- * const schemas = readSchemasSync('/path/to/schemas');
120
- * // Automatically finds schemas in subdirectories:
121
- * // - /path/to/schemas/User.yaml
122
- * // - /path/to/schemas/nested/Profile.yaml
123
- * ```
124
- */
28
+ /** Reads all YAML schema files from a directory and creates Schema instances. */
125
29
  const readSchemasSync = (servicePath) => listFilesSync(servicePath)
126
30
  .filter((fileName) => fileName.endsWith('.yaml'))
127
31
  .map((schemaPath) => (0, exports.loadSync)(schemaPath));
128
- /**
129
- * Creates a map of schemas by ID, loading from YAML files and merging with programmatic schemas.
130
- *
131
- * **Intent:** Build a centralized schema registry that combines file-based YAML schemas
132
- * with programmatically created Schema instances, providing a unified lookup mechanism
133
- * by schema ID. This enables hybrid schema management where some schemas are defined
134
- * in YAML files while others are created dynamically in code.
135
- *
136
- * **Use Cases:**
137
- * - Initialize schema registries for validators from both files and code
138
- * - Support schema composition where base schemas come from files and extended
139
- * schemas are created programmatically
140
- * - Enable schema overriding where programmatic schemas can replace file-based ones
141
- * - Build schema maps for credential factories or API validation systems
142
- * - Support development workflows where schemas evolve from YAML to code
143
- *
144
- * @param servicePath - Path to directory containing YAML schema files (searched recursively)
145
- * @param modules - Array of Schema instances or other values (non-Schema values are filtered out)
146
- * @returns Record mapping schema IDs to Schema instances, with modules schemas overriding YAML schemas
147
- *
148
- * **Example - Basic Usage:**
149
- * ```typescript
150
- * const schemasMap = createSchemasMap('/path/to/examples/schemas', []);
151
- * // Returns: {
152
- * // FavoriteItem: Schema { id: 'FavoriteItem', ... },
153
- * // Profile: Schema { id: 'Profile', ... },
154
- * // Status: Schema { id: 'Status', ... },
155
- * // Preferences: Schema { id: 'Preferences', ... }
156
- * // }
157
- * ```
158
- *
159
- * **Example - Merging Programmatic Schemas:**
160
- * ```typescript
161
- * const customSchema = new Schema(
162
- * { customField: { type: 'string' } },
163
- * 'CustomSchema'
164
- * );
165
- * const schemasMap = createSchemasMap('/path/to/schemas', [customSchema]);
166
- * // schemasMap contains both YAML schemas and CustomSchema
167
- * ```
168
- *
169
- * **Example - Overriding YAML Schemas:**
170
- * ```typescript
171
- * const updatedProfile = new Schema(
172
- * { name: { type: 'string' }, newField: { type: 'number' } },
173
- * 'Profile'
174
- * );
175
- * const schemasMap = createSchemasMap('/path/to/schemas', [updatedProfile]);
176
- * // schemasMap.Profile is the updatedProfile instance, not the YAML version
177
- * ```
178
- *
179
- * **Example - Filtering Non-Schema Values:**
180
- * ```typescript
181
- * const schema = new Schema({ field: { type: 'string' } }, 'Test');
182
- * const schemasMap = createSchemasMap('/path/to/schemas', [
183
- * schema,
184
- * 'not a schema',
185
- * { id: 'fake' },
186
- * null
187
- * ]);
188
- * // Only the Schema instance is included, other values are ignored
189
- * ```
190
- */
32
+ /** Creates a map of schemas by ID, loading from YAML files and merging with programmatic schemas. */
191
33
  const createSchemasMap = (servicePath, modules) => {
192
34
  const yamlSchemas = readSchemasSync(servicePath);
193
35
  const schemasMap = (0, lodash_1.keyBy)(yamlSchemas, 'id');
@@ -1 +1 @@
1
- {"version":3,"file":"createSchemasMap.js","sourceRoot":"","sources":["../../src/helpers/createSchemasMap.ts"],"names":[],"mappings":";;;;;;AAAA,gDAAwB;AACxB,uDAA+B;AAC/B,qCAA+B;AAC/B,mCAA+B;AAE/B,2BAAyD;AAEzD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACI,MAAM,QAAQ,GAAG,CAAC,QAAgB,EAAE,EAAE;IAC3C,MAAM,QAAQ,GAAG,QAAQ;SACtB,KAAK,CAAC,GAAG,CAAC;SACV,OAAO,EAAE,CAAC,CAAC,CAAC;SACZ,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC;IAErB,MAAM,IAAI,GAAG,IAAA,iBAAY,EAAC,QAAQ,CAAC,CAAC;IACpC,MAAM,MAAM,GAAG,IAAA,cAAI,EAAC,IAAI,CAAC,QAAQ,EAAE,CAAkC,CAAC;IAEtE,OAAO,IAAI,gBAAM,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;AACtC,CAAC,CAAC;AAVW,QAAA,QAAQ,YAUnB;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,MAAM,aAAa,GAAG,CAAC,WAAmB,EAAY,EAAE,CACtD,IAAA,gBAAW,EAAC,WAAW,CAAC;KACrB,MAAM,CACL,CAAC,SAAmB,EAAE,QAAgB,EAAE,EAAE,CACxC,IAAA,aAAQ,EACN,cAAI,CAAC,IAAI,CAAC,WAAW,EAAE,QAAQ,CAAC,CAAC,CAAC,WAAW,EAAE,CAAC,CAAC;IAC/C,SAAS,CAAC,MAAM,CAAC,aAAa,CAAC,cAAI,CAAC,IAAI,CAAC,WAAW,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC;IACnE,SAAS,CAAC,MAAM,CAAC,cAAI,CAAC,IAAI,CAAC,WAAW,EAAE,QAAQ,CAAC,CACp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AAC;IACjD,MAAM,UAAU,GAAG,IAAA,cAAK,EAAC,WAAW,EAAE,IAAI,CAAC,CAAC;IAE5C,MAAM,OAAO,GAAG,OAAO;SACpB,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC,MAAM,YAAY,gBAAM,CAAC,CAAC;IAE9C,KAAK,MAAM,MAAM,IAAI,OAAO,EAAE,CAAC;QAC7B,UAAU,CAAC,MAAM,CAAC,EAAE,CAAC,GAAG,MAAM,CAAC;IACjC,CAAC;IAED,OAAO,UAAU,CAAC;AACpB,CAAC,CAAC;AAEF,kBAAe,gBAAgB,CAAC"}
@@ -1,169 +1,5 @@
1
1
  import Schema from '../Schema';
2
- /**
3
- * Recursively extracts all referenced schema IDs from a schema structure.
4
- *
5
- * **Intent:** Traverse a schema's entire structure (including nested objects and arrays)
6
- * to collect all schema IDs that are referenced via `$ref` properties. This enables
7
- * dependency resolution, schema bundling, and validation of schema completeness.
8
- *
9
- * **Use Cases:**
10
- * - **Dependency Resolution:** Identify all schemas that a given schema depends on,
11
- * ensuring they are loaded before validation
12
- * - **Schema Bundling:** Collect all related schemas into a single bundle for
13
- * distribution or storage
14
- * - **Validation Preparation:** Pre-load all referenced schemas to ensure complete
15
- * validation context
16
- * - **Dependency Graph Building:** Understand the relationships and dependencies
17
- * between schemas in a schema registry
18
- * - **Schema Analysis:** Analyze schema complexity by identifying all dependencies
19
- * - **Circular Reference Detection:** (Note: current implementation does not handle
20
- * circular references and will recurse infinitely)
21
- *
22
- * **Behavior:**
23
- * - Returns an empty array for enum schemas (they don't reference other schemas)
24
- * - Recursively traverses nested object properties
25
- * - Handles array items that reference schemas or contain object properties
26
- * - Follows nested references to collect transitive dependencies
27
- * - Returns unique schema IDs (deduplicates if same schema is referenced multiple times)
28
- * - Throws an error if a referenced schema is not found in the schemasMap
29
- *
30
- * **Example - Simple Reference:**
31
- * ```typescript
32
- * const userSchema = new Schema({
33
- * profile: { $ref: 'Profile' }
34
- * }, 'User');
35
- *
36
- * const profileSchema = new Schema({
37
- * name: { type: 'string' }
38
- * }, 'Profile');
39
- *
40
- * const schemasMap = { 'Profile': profileSchema };
41
- * const referenceIds = getReferenceIds(userSchema, schemasMap);
42
- * // Returns: ['Profile']
43
- * ```
44
- *
45
- * **Example - Multiple References:**
46
- * ```typescript
47
- * const orderSchema = new Schema({
48
- * customer: { $ref: 'Customer' },
49
- * product: { $ref: 'Product' },
50
- * shipping: { $ref: 'Address' }
51
- * }, 'Order');
52
- *
53
- * const schemasMap = {
54
- * 'Customer': customerSchema,
55
- * 'Product': productSchema,
56
- * 'Address': addressSchema
57
- * };
58
- * const referenceIds = getReferenceIds(orderSchema, schemasMap);
59
- * // Returns: ['Customer', 'Product', 'Address']
60
- * ```
61
- *
62
- * **Example - Nested References:**
63
- * ```typescript
64
- * const userSchema = new Schema({
65
- * profile: { $ref: 'Profile' }
66
- * }, 'User');
67
- *
68
- * const profileSchema = new Schema({
69
- * address: { $ref: 'Address' }
70
- * }, 'Profile');
71
- *
72
- * const addressSchema = new Schema({
73
- * street: { type: 'string' }
74
- * }, 'Address');
75
- *
76
- * const schemasMap = {
77
- * 'Profile': profileSchema,
78
- * 'Address': addressSchema
79
- * };
80
- * const referenceIds = getReferenceIds(userSchema, schemasMap);
81
- * // Returns: ['Profile', 'Address'] (includes transitive dependencies)
82
- * ```
83
- *
84
- * **Example - Array with Reference Items:**
85
- * ```typescript
86
- * const orderSchema = new Schema({
87
- * items: {
88
- * type: 'array',
89
- * items: { $ref: 'OrderItem' }
90
- * }
91
- * }, 'Order');
92
- *
93
- * const schemasMap = { 'OrderItem': orderItemSchema };
94
- * const referenceIds = getReferenceIds(orderSchema, schemasMap);
95
- * // Returns: ['OrderItem']
96
- * ```
97
- *
98
- * **Example - Nested Object Properties:**
99
- * ```typescript
100
- * const userSchema = new Schema({
101
- * contact: {
102
- * type: 'object',
103
- * properties: {
104
- * address: { $ref: 'Address' }
105
- * }
106
- * }
107
- * }, 'User');
108
- *
109
- * const schemasMap = { 'Address': addressSchema };
110
- * const referenceIds = getReferenceIds(userSchema, schemasMap);
111
- * // Returns: ['Address']
112
- * ```
113
- *
114
- * **Example - Complex Mixed Structure:**
115
- * ```typescript
116
- * const orderSchema = new Schema({
117
- * customer: { $ref: 'Customer' },
118
- * items: {
119
- * type: 'array',
120
- * items: {
121
- * type: 'object',
122
- * properties: {
123
- * product: { $ref: 'Product' }
124
- * }
125
- * }
126
- * },
127
- * shipping: {
128
- * type: 'object',
129
- * properties: {
130
- * address: { $ref: 'Address' }
131
- * }
132
- * }
133
- * }, 'Order');
134
- *
135
- * const schemasMap = {
136
- * 'Customer': customerSchema,
137
- * 'Product': productSchema,
138
- * 'Address': addressSchema
139
- * };
140
- * const referenceIds = getReferenceIds(orderSchema, schemasMap);
141
- * // Returns: ['Customer', 'Product', 'Address']
142
- * ```
143
- *
144
- * **Example - Duplicate References:**
145
- * ```typescript
146
- * const schema = new Schema({
147
- * field1: { $ref: 'SharedSchema' },
148
- * field2: { $ref: 'SharedSchema' }
149
- * }, 'Test');
150
- *
151
- * const schemasMap = { 'SharedSchema': sharedSchema };
152
- * const referenceIds = getReferenceIds(schema, schemasMap);
153
- * // Returns: ['SharedSchema'] (deduplicated)
154
- * ```
155
- *
156
- * @param schema - The schema to extract references from
157
- * @param schemasMap - A map of schema IDs to Schema instances, used to resolve
158
- * referenced schemas and traverse nested references
159
- * @returns An array of unique schema IDs that are referenced (directly or indirectly)
160
- * by the given schema
161
- * @throws Error if a referenced schema is not found in the schemasMap
162
- *
163
- * **Limitations:**
164
- * - Does not handle circular references (will cause infinite recursion)
165
- * - Requires all referenced schemas to be present in schemasMap
166
- */
2
+ /** Recursively extracts all referenced schema IDs from a schema structure. */
167
3
  declare const getReferenceIds: (schema: Schema, schemasMap: Record<string, Schema>) => string[];
168
4
  export default getReferenceIds;
169
5
  //# sourceMappingURL=getReferenceIds.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"getReferenceIds.d.ts","sourceRoot":"","sources":["../../src/helpers/getReferenceIds.ts"],"names":[],"mappings":"AAEA,OAAO,MAAM,MAAM,WAAW,CAAC;AAU/B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoKG;AACH,QAAA,MAAM,eAAe,GAAI,QAAQ,MAAM,EAAE,YAAY,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,KAAG,MAAM,EA6FnF,CAAC;AAEF,eAAe,eAAe,CAAC"}
1
+ {"version":3,"file":"getReferenceIds.d.ts","sourceRoot":"","sources":["../../src/helpers/getReferenceIds.ts"],"names":[],"mappings":"AAGA,OAAO,MAAM,MAAM,WAAW,CAAC;AAE/B,8EAA8E;AAC9E,QAAA,MAAM,eAAe,GAAI,QAAQ,MAAM,EAAE,YAAY,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,KAAG,MAAM,EA6FnF,CAAC;AAEF,eAAe,eAAe,CAAC"}