@skmtc/core 0.0.786 → 0.0.787

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 (47) hide show
  1. package/esm/dsl/ContentSettings.d.ts +164 -0
  2. package/esm/dsl/ContentSettings.d.ts.map +1 -1
  3. package/esm/dsl/ContentSettings.js +151 -0
  4. package/esm/dsl/Definition.d.ts +199 -0
  5. package/esm/dsl/Definition.d.ts.map +1 -1
  6. package/esm/dsl/Definition.js +189 -0
  7. package/esm/dsl/EntityType.d.ts +83 -0
  8. package/esm/dsl/EntityType.d.ts.map +1 -1
  9. package/esm/dsl/EntityType.js +83 -0
  10. package/esm/oas/array/Array.d.ts +109 -1
  11. package/esm/oas/array/Array.d.ts.map +1 -1
  12. package/esm/oas/array/Array.js +93 -1
  13. package/esm/oas/integer/Integer.d.ts +98 -0
  14. package/esm/oas/integer/Integer.d.ts.map +1 -1
  15. package/esm/oas/integer/Integer.js +80 -0
  16. package/esm/oas/string/String.d.ts +103 -1
  17. package/esm/oas/string/String.d.ts.map +1 -1
  18. package/esm/oas/string/String.js +87 -1
  19. package/esm/types/Brand.d.ts +74 -0
  20. package/esm/types/Brand.d.ts.map +1 -1
  21. package/esm/types/Brand.js +9 -0
  22. package/esm/types/RefName.d.ts +61 -0
  23. package/esm/types/RefName.d.ts.map +1 -1
  24. package/package.json +1 -1
  25. package/script/dsl/ContentSettings.d.ts +164 -0
  26. package/script/dsl/ContentSettings.d.ts.map +1 -1
  27. package/script/dsl/ContentSettings.js +151 -0
  28. package/script/dsl/Definition.d.ts +199 -0
  29. package/script/dsl/Definition.d.ts.map +1 -1
  30. package/script/dsl/Definition.js +189 -0
  31. package/script/dsl/EntityType.d.ts +83 -0
  32. package/script/dsl/EntityType.d.ts.map +1 -1
  33. package/script/dsl/EntityType.js +83 -0
  34. package/script/oas/array/Array.d.ts +109 -1
  35. package/script/oas/array/Array.d.ts.map +1 -1
  36. package/script/oas/array/Array.js +93 -1
  37. package/script/oas/integer/Integer.d.ts +98 -0
  38. package/script/oas/integer/Integer.d.ts.map +1 -1
  39. package/script/oas/integer/Integer.js +80 -0
  40. package/script/oas/string/String.d.ts +103 -1
  41. package/script/oas/string/String.d.ts.map +1 -1
  42. package/script/oas/string/String.js +87 -1
  43. package/script/types/Brand.d.ts +74 -0
  44. package/script/types/Brand.d.ts.map +1 -1
  45. package/script/types/Brand.js +9 -0
  46. package/script/types/RefName.d.ts +61 -0
  47. package/script/types/RefName.d.ts.map +1 -1
@@ -3,27 +3,171 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Definition = void 0;
4
4
  const ContentBase_js_1 = require("./ContentBase.js");
5
5
  const withDescription_js_1 = require("../typescript/withDescription.js");
6
+ /**
7
+ * Represents a complete code definition in the SKMTC DSL system.
8
+ *
9
+ * The `Definition` class is the primary output unit of generators, representing
10
+ * a complete piece of generated code (like an interface, function, or constant).
11
+ * It combines an identifier, generated content, and optional metadata into a
12
+ * formatted code definition with proper TypeScript syntax.
13
+ *
14
+ * This class automatically handles export statements, type annotations, and
15
+ * JSDoc comment generation, making it the building block for all generated
16
+ * code artifacts.
17
+ *
18
+ * ## Key Features
19
+ *
20
+ * - **Automatic Exports**: Handles export keyword based on configuration
21
+ * - **Type Safety**: Preserves type information through generic parameters
22
+ * - **JSDoc Integration**: Automatic comment generation from descriptions
23
+ * - **Entity Type Support**: Handles different definition types (const, type, etc.)
24
+ * - **Identifier Management**: Integrates with the Identifier system for naming
25
+ *
26
+ * @template V - The type of generated value (preserves generator-specific types)
27
+ *
28
+ * @example Basic interface definition
29
+ * ```typescript
30
+ * import { Definition, Identifier } from '@skmtc/core';
31
+ *
32
+ * const userInterface = new Definition({
33
+ * context: generateContext,
34
+ * identifier: Identifier.createType('User'),
35
+ * description: 'Represents a user in the system',
36
+ * value: {
37
+ * generatorKey: 'typescript-interfaces',
38
+ * content: `{
39
+ * id: string;
40
+ * name: string;
41
+ * email: string;
42
+ * }`
43
+ * }
44
+ * });
45
+ *
46
+ * console.log(userInterface.toString());
47
+ * //
48
+ * // Represents a user in the system
49
+ * //
50
+ * // export type User = {
51
+ * // id: string;
52
+ * // name: string;
53
+ * // email: string;
54
+ * // };
55
+ * ```
56
+ *
57
+ * @example Function definition with parameters
58
+ * ```typescript
59
+ * const apiFunction = new Definition({
60
+ * context: generateContext,
61
+ * identifier: Identifier.createVariable('fetchUser', 'Promise<User>'),
62
+ * description: 'Fetches a user by ID from the API',
63
+ * value: {
64
+ * generatorKey: 'api-client',
65
+ * content: `async (id: string) => {
66
+ * const response = await fetch(\`/api/users/\${id}\`);
67
+ * return response.json();
68
+ * }`
69
+ * }
70
+ * });
71
+ *
72
+ * console.log(apiFunction.toString());
73
+ * //
74
+ * // Fetches a user by ID from the API
75
+ * //
76
+ * // export const fetchUser: Promise<User> = async (id: string) => {
77
+ * // const response = await fetch(`/api/users/${id}`);
78
+ * // return response.json();
79
+ * // };
80
+ * ```
81
+ *
82
+ * @example Non-exported definition
83
+ * ```typescript
84
+ * const helperFunction = new Definition({
85
+ * context: generateContext,
86
+ * identifier: Identifier.createVariable('validateEmail'),
87
+ * value: {
88
+ * generatorKey: 'utilities',
89
+ * content: `(email: string): boolean => {
90
+ * return /^[^\\s@]+@[^\\s@]+\\.[^\\s@]+$/.test(email);
91
+ * }`
92
+ * },
93
+ * noExport: true // Internal helper, not exported
94
+ * });
95
+ *
96
+ * console.log(helperFunction.toString());
97
+ * // const validateEmail = (email: string): boolean => {
98
+ * // return /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(email);
99
+ * // };
100
+ * ```
101
+ *
102
+ * @example Using in generator classes
103
+ * ```typescript
104
+ * import { ModelBase, Definition, Identifier } from '@skmtc/core';
105
+ *
106
+ * class TypeScriptInterface extends ModelBase {
107
+ * toDefinition(): Definition {
108
+ * const schema = this.context.getSchema(this.refName);
109
+ *
110
+ * return new Definition({
111
+ * context: this.context,
112
+ * identifier: Identifier.createType(this.refName),
113
+ * description: schema.description,
114
+ * value: {
115
+ * generatorKey: this.generatorKey,
116
+ * content: this.generateInterfaceBody(schema)
117
+ * }
118
+ * });
119
+ * }
120
+ * }
121
+ * ```
122
+ */
6
123
  class Definition extends ContentBase_js_1.ContentBase {
124
+ /**
125
+ * Creates a new Definition instance.
126
+ *
127
+ * @param args - Definition configuration
128
+ * @param args.context - Generation context for pipeline access
129
+ * @param args.identifier - The identifier (name and type info) for this definition
130
+ * @param args.value - The generated content value
131
+ * @param args.description - Optional description for JSDoc comments
132
+ * @param args.noExport - Whether to omit the export keyword (default: false)
133
+ *
134
+ * @example
135
+ * ```typescript
136
+ * const constant = new Definition({
137
+ * context: generateContext,
138
+ * identifier: Identifier.createVariable('API_BASE_URL', 'string'),
139
+ * description: 'Base URL for all API requests',
140
+ * value: {
141
+ * generatorKey: 'constants',
142
+ * content: "'https://api.example.com'"
143
+ * }
144
+ * });
145
+ * ```
146
+ */
7
147
  constructor({ context, identifier, value, description, noExport }) {
8
148
  super({ context, generatorKey: value.generatorKey });
149
+ /** The identifier for this definition */
9
150
  Object.defineProperty(this, "identifier", {
10
151
  enumerable: true,
11
152
  configurable: true,
12
153
  writable: true,
13
154
  value: void 0
14
155
  });
156
+ /** Optional description for JSDoc comments */
15
157
  Object.defineProperty(this, "description", {
16
158
  enumerable: true,
17
159
  configurable: true,
18
160
  writable: true,
19
161
  value: void 0
20
162
  });
163
+ /** The generated value content */
21
164
  Object.defineProperty(this, "value", {
22
165
  enumerable: true,
23
166
  configurable: true,
24
167
  writable: true,
25
168
  value: void 0
26
169
  });
170
+ /** Whether to skip the export keyword */
27
171
  Object.defineProperty(this, "noExport", {
28
172
  enumerable: true,
29
173
  configurable: true,
@@ -35,6 +179,51 @@ class Definition extends ContentBase_js_1.ContentBase {
35
179
  this.description = description;
36
180
  this.noExport = noExport;
37
181
  }
182
+ /**
183
+ * Generates the complete TypeScript definition code.
184
+ *
185
+ * This method produces a properly formatted TypeScript definition with:
186
+ * - Optional JSDoc comments from the description
187
+ * - Export keyword (unless noExport is true)
188
+ * - Entity type (const, type, function, etc.)
189
+ * - Identifier with optional type annotation
190
+ * - Generated value content
191
+ *
192
+ * The output follows TypeScript syntax conventions and can be written
193
+ * directly to a .ts file.
194
+ *
195
+ * @returns The complete TypeScript definition as a string
196
+ *
197
+ * @example Type definition
198
+ * ```typescript
199
+ * const typeDef = new Definition({
200
+ * context,
201
+ * identifier: Identifier.createType('Status'),
202
+ * description: 'Possible status values',
203
+ * value: { generatorKey: 'types', content: "'pending' | 'complete' | 'failed'" }
204
+ * });
205
+ *
206
+ * console.log(typeDef.toString());
207
+ * //
208
+ * // Possible status values
209
+ * //
210
+ * // export type Status = 'pending' | 'complete' | 'failed';
211
+ * ```
212
+ *
213
+ * @example Constant definition
214
+ * ```typescript
215
+ * const constDef = new Definition({
216
+ * context,
217
+ * identifier: Identifier.createVariable('DEFAULT_TIMEOUT', 'number'),
218
+ * value: { generatorKey: 'config', content: '5000' }
219
+ * });
220
+ *
221
+ * console.log(constDef.toString());
222
+ * // export const DEFAULT_TIMEOUT: number = 5000;
223
+ * ```
224
+ *
225
+ * @todo Move syntax to typescript package to enable language-agnostic use
226
+ */
38
227
  toString() {
39
228
  const identifier = this.identifier.typeName
40
229
  ? `${this.identifier.name}: ${this.identifier.typeName}`
@@ -1,6 +1,89 @@
1
+ /**
2
+ * Represents the type of a TypeScript entity for code generation.
3
+ *
4
+ * `EntityType` encapsulates the distinction between different kinds of
5
+ * TypeScript entities, specifically variables (which become `const` declarations)
6
+ * and types (which become `type` or `interface` declarations).
7
+ *
8
+ * This class is used by the {@link Identifier} system to ensure that
9
+ * generated code uses the correct TypeScript keywords and syntax patterns.
10
+ *
11
+ * @example Variable entity type
12
+ * ```typescript
13
+ * import { EntityType } from '@skmtc/core';
14
+ *
15
+ * const variableEntity = new EntityType('variable');
16
+ * console.log(variableEntity.toString()); // 'const'
17
+ *
18
+ * // Used in code generation:
19
+ * // const API_URL = 'https://api.example.com';
20
+ * ```
21
+ *
22
+ * @example Type entity type
23
+ * ```typescript
24
+ * const typeEntity = new EntityType('type');
25
+ * console.log(typeEntity.toString()); // 'type'
26
+ *
27
+ * // Used in code generation:
28
+ * // type User = { id: string; name: string; };
29
+ * ```
30
+ *
31
+ * @example Integration with Identifier
32
+ * ```typescript
33
+ * import { Identifier, EntityType } from '@skmtc/core';
34
+ *
35
+ * // Create a variable identifier (uses 'const' keyword)
36
+ * const varId = Identifier.createVariable('API_KEY', 'string');
37
+ * console.log(varId.entityType.toString()); // 'const'
38
+ *
39
+ * // Create a type identifier (uses 'type' keyword)
40
+ * const typeId = Identifier.createType('UserStatus');
41
+ * console.log(typeId.entityType.toString()); // 'type'
42
+ * ```
43
+ */
1
44
  export declare class EntityType {
45
+ /** The entity type discriminator */
2
46
  type: 'variable' | 'type';
47
+ /**
48
+ * Creates a new EntityType instance.
49
+ *
50
+ * @param type - The type of entity ('variable' for const declarations, 'type' for type declarations)
51
+ *
52
+ * @example
53
+ * ```typescript
54
+ * // For generating const declarations
55
+ * const constEntity = new EntityType('variable');
56
+ *
57
+ * // For generating type declarations
58
+ * const typeEntity = new EntityType('type');
59
+ * ```
60
+ */
3
61
  constructor(type: 'variable' | 'type');
62
+ /**
63
+ * Returns the appropriate TypeScript keyword for this entity type.
64
+ *
65
+ * This method maps the entity type to the correct TypeScript declaration
66
+ * keyword that should be used in generated code:
67
+ * - 'variable' entities become 'const' declarations
68
+ * - 'type' entities become 'type' declarations
69
+ *
70
+ * @returns The TypeScript keyword string ('const' or 'type')
71
+ *
72
+ * @example
73
+ * ```typescript
74
+ * const varEntity = new EntityType('variable');
75
+ * console.log(varEntity.toString()); // 'const'
76
+ *
77
+ * const typeEntity = new EntityType('type');
78
+ * console.log(typeEntity.toString()); // 'type'
79
+ *
80
+ * // Used in code generation:
81
+ * const keyword = entityType.toString();
82
+ * const declaration = `${keyword} ${identifier} = ${value};`;
83
+ * // Results in: "const API_URL = 'https://example.com';" or
84
+ * // Results in: "type Status = 'active' | 'inactive';"
85
+ * ```
86
+ */
4
87
  toString(): string;
5
88
  }
6
89
  //# sourceMappingURL=EntityType.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"EntityType.d.ts","sourceRoot":"","sources":["../../src/dsl/EntityType.ts"],"names":[],"mappings":"AAEA,qBAAa,UAAU;IACrB,IAAI,EAAE,UAAU,GAAG,MAAM,CAAA;gBACb,IAAI,EAAE,UAAU,GAAG,MAAM;IAIrC,QAAQ,IAAI,MAAM;CAMnB"}
1
+ {"version":3,"file":"EntityType.d.ts","sourceRoot":"","sources":["../../src/dsl/EntityType.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0CG;AACH,qBAAa,UAAU;IACrB,oCAAoC;IACpC,IAAI,EAAE,UAAU,GAAG,MAAM,CAAA;IAEzB;;;;;;;;;;;;;OAaG;gBACS,IAAI,EAAE,UAAU,GAAG,MAAM;IAIrC;;;;;;;;;;;;;;;;;;;;;;;;OAwBG;IACH,QAAQ,IAAI,MAAM;CAMnB"}
@@ -2,8 +2,66 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.EntityType = void 0;
4
4
  const ts_pattern_1 = require("ts-pattern");
5
+ /**
6
+ * Represents the type of a TypeScript entity for code generation.
7
+ *
8
+ * `EntityType` encapsulates the distinction between different kinds of
9
+ * TypeScript entities, specifically variables (which become `const` declarations)
10
+ * and types (which become `type` or `interface` declarations).
11
+ *
12
+ * This class is used by the {@link Identifier} system to ensure that
13
+ * generated code uses the correct TypeScript keywords and syntax patterns.
14
+ *
15
+ * @example Variable entity type
16
+ * ```typescript
17
+ * import { EntityType } from '@skmtc/core';
18
+ *
19
+ * const variableEntity = new EntityType('variable');
20
+ * console.log(variableEntity.toString()); // 'const'
21
+ *
22
+ * // Used in code generation:
23
+ * // const API_URL = 'https://api.example.com';
24
+ * ```
25
+ *
26
+ * @example Type entity type
27
+ * ```typescript
28
+ * const typeEntity = new EntityType('type');
29
+ * console.log(typeEntity.toString()); // 'type'
30
+ *
31
+ * // Used in code generation:
32
+ * // type User = { id: string; name: string; };
33
+ * ```
34
+ *
35
+ * @example Integration with Identifier
36
+ * ```typescript
37
+ * import { Identifier, EntityType } from '@skmtc/core';
38
+ *
39
+ * // Create a variable identifier (uses 'const' keyword)
40
+ * const varId = Identifier.createVariable('API_KEY', 'string');
41
+ * console.log(varId.entityType.toString()); // 'const'
42
+ *
43
+ * // Create a type identifier (uses 'type' keyword)
44
+ * const typeId = Identifier.createType('UserStatus');
45
+ * console.log(typeId.entityType.toString()); // 'type'
46
+ * ```
47
+ */
5
48
  class EntityType {
49
+ /**
50
+ * Creates a new EntityType instance.
51
+ *
52
+ * @param type - The type of entity ('variable' for const declarations, 'type' for type declarations)
53
+ *
54
+ * @example
55
+ * ```typescript
56
+ * // For generating const declarations
57
+ * const constEntity = new EntityType('variable');
58
+ *
59
+ * // For generating type declarations
60
+ * const typeEntity = new EntityType('type');
61
+ * ```
62
+ */
6
63
  constructor(type) {
64
+ /** The entity type discriminator */
7
65
  Object.defineProperty(this, "type", {
8
66
  enumerable: true,
9
67
  configurable: true,
@@ -12,6 +70,31 @@ class EntityType {
12
70
  });
13
71
  this.type = type;
14
72
  }
73
+ /**
74
+ * Returns the appropriate TypeScript keyword for this entity type.
75
+ *
76
+ * This method maps the entity type to the correct TypeScript declaration
77
+ * keyword that should be used in generated code:
78
+ * - 'variable' entities become 'const' declarations
79
+ * - 'type' entities become 'type' declarations
80
+ *
81
+ * @returns The TypeScript keyword string ('const' or 'type')
82
+ *
83
+ * @example
84
+ * ```typescript
85
+ * const varEntity = new EntityType('variable');
86
+ * console.log(varEntity.toString()); // 'const'
87
+ *
88
+ * const typeEntity = new EntityType('type');
89
+ * console.log(typeEntity.toString()); // 'type'
90
+ *
91
+ * // Used in code generation:
92
+ * const keyword = entityType.toString();
93
+ * const declaration = `${keyword} ${identifier} = ${value};`;
94
+ * // Results in: "const API_URL = 'https://example.com';" or
95
+ * // Results in: "type Status = 'active' | 'inactive';"
96
+ * ```
97
+ */
15
98
  toString() {
16
99
  return (0, ts_pattern_1.match)(this.type)
17
100
  .with('variable', () => 'const')
@@ -2,21 +2,129 @@ import "../../_dnt.polyfills.js";
2
2
  import type { OasSchema, ToJsonSchemaOptions } from '../schema/Schema.js';
3
3
  import type { OasRef } from '../ref/Ref.js';
4
4
  import type { OpenAPIV3 } from 'openapi-types';
5
+ /**
6
+ * Constructor fields for {@link OasArray}.
7
+ *
8
+ * @template Nullable - Whether the array value can be null
9
+ */
5
10
  export type ArrayFields<Nullable extends boolean | undefined> = {
11
+ /** Schema definition for array items */
6
12
  items: OasSchema | OasRef<'schema'>;
13
+ /** A short summary of the array schema */
7
14
  title?: string;
15
+ /** A description of the array schema */
8
16
  description?: string;
17
+ /** Whether the array value can be null */
9
18
  nullable?: Nullable;
19
+ /** Whether array items must be unique */
10
20
  uniqueItems?: boolean;
21
+ /** Custom extension fields (x-* properties) */
11
22
  extensionFields?: Record<string, unknown>;
23
+ /** Example array value */
12
24
  example?: Nullable extends true ? unknown[] | null | undefined : unknown[] | undefined;
25
+ /** Maximum number of items allowed */
13
26
  maxItems?: number;
27
+ /** Minimum number of items required */
14
28
  minItems?: number;
29
+ /** Array of allowed enum values for the entire array */
15
30
  enums?: Nullable extends true ? (unknown | null)[] | undefined : unknown[] | undefined;
31
+ /** Default value for the array */
16
32
  defaultValue?: Nullable extends true ? unknown[] | null | undefined : unknown[] | undefined;
17
33
  };
18
34
  /**
19
- * Object representing an array in the OpenAPI Specification.
35
+ * Represents an array schema in the OpenAPI Specification.
36
+ *
37
+ * `OasArray` handles array type definitions with comprehensive validation
38
+ * constraints including item count limits, uniqueness requirements, and
39
+ * item type specifications. It supports nested schemas and references
40
+ * for complex array structures.
41
+ *
42
+ * This class is used throughout the OAS processing pipeline to represent
43
+ * array fields in API schemas, including lists of objects, primitive arrays,
44
+ * and complex nested array structures.
45
+ *
46
+ * ## Key Features
47
+ *
48
+ * - **Item Type Definition**: Support for any schema type as array items
49
+ * - **Size Constraints**: Minimum and maximum item count validation
50
+ * - **Uniqueness Validation**: Ensure array items are unique (like Set behavior)
51
+ * - **Nested Schemas**: Support for complex nested array structures
52
+ * - **Reference Handling**: Seamless integration with schema references
53
+ * - **Nullable Support**: Type-safe nullable array handling
54
+ * - **JSON Schema**: Conversion to standard JSON Schema format
55
+ *
56
+ * @template Nullable - Whether the array value can be null
57
+ *
58
+ * @example String array
59
+ * ```typescript
60
+ * import { OasArray, OasString } from '@skmtc/core';
61
+ *
62
+ * const tagsArray = new OasArray({
63
+ * title: 'Tags',
64
+ * description: 'List of tags associated with the item',
65
+ * items: new OasString({ minLength: 1 }),
66
+ * minItems: 1,
67
+ * uniqueItems: true,
68
+ * example: ['javascript', 'typescript', 'react']
69
+ * });
70
+ * ```
71
+ *
72
+ * @example Object array with references
73
+ * ```typescript
74
+ * import { OasArray, OasRef } from '@skmtc/core';
75
+ *
76
+ * const usersArray = new OasArray({
77
+ * title: 'Users',
78
+ * description: 'List of user objects',
79
+ * items: new OasRef({ refName: 'User' }),
80
+ * maxItems: 100,
81
+ * example: [
82
+ * { id: 1, name: 'John' },
83
+ * { id: 2, name: 'Jane' }
84
+ * ]
85
+ * });
86
+ * ```
87
+ *
88
+ * @example Nested array (array of arrays)
89
+ * ```typescript
90
+ * const matrixArray = new OasArray({
91
+ * title: 'Matrix',
92
+ * description: '2D array of numbers',
93
+ * items: new OasArray({
94
+ * items: new OasInteger({ minimum: 0 })
95
+ * }),
96
+ * example: [
97
+ * [1, 2, 3],
98
+ * [4, 5, 6],
99
+ * [7, 8, 9]
100
+ * ]
101
+ * });
102
+ * ```
103
+ *
104
+ * @example Nullable array with constraints
105
+ * ```typescript
106
+ * const optionalIdsArray = new OasArray<true>({
107
+ * title: 'Optional IDs',
108
+ * description: 'Optional list of IDs',
109
+ * items: new OasInteger({ format: 'int64', minimum: 1 }),
110
+ * nullable: true,
111
+ * minItems: 0,
112
+ * maxItems: 10,
113
+ * defaultValue: null
114
+ * });
115
+ * ```
116
+ *
117
+ * @example Unique items validation
118
+ * ```typescript
119
+ * const uniqueEmailsArray = new OasArray({
120
+ * title: 'Email Recipients',
121
+ * description: 'List of unique email addresses',
122
+ * items: new OasString({ format: 'email' }),
123
+ * uniqueItems: true, // Ensures no duplicate emails
124
+ * minItems: 1,
125
+ * example: ['user1@example.com', 'user2@example.com']
126
+ * });
127
+ * ```
20
128
  */
21
129
  export declare class OasArray<Nullable extends boolean | undefined = boolean | undefined> {
22
130
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"Array.d.ts","sourceRoot":"","sources":["../../../src/oas/array/Array.ts"],"names":[],"mappings":"AAAA,OAAO,yBAAyB,CAAC;AACjC,OAAO,KAAK,EAAE,SAAS,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAA;AACzE,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,eAAe,CAAA;AAC3C,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,eAAe,CAAA;AAE9C,MAAM,MAAM,WAAW,CAAC,QAAQ,SAAS,OAAO,GAAG,SAAS,IAAI;IAC9D,KAAK,EAAE,SAAS,GAAG,MAAM,CAAC,QAAQ,CAAC,CAAA;IACnC,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,QAAQ,CAAC,EAAE,QAAQ,CAAA;IACnB,WAAW,CAAC,EAAE,OAAO,CAAA;IACrB,eAAe,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IACzC,OAAO,CAAC,EAAE,QAAQ,SAAS,IAAI,GAAG,OAAO,EAAE,GAAG,IAAI,GAAG,SAAS,GAAG,OAAO,EAAE,GAAG,SAAS,CAAA;IACtF,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,KAAK,CAAC,EAAE,QAAQ,SAAS,IAAI,GAAG,CAAC,OAAO,GAAG,IAAI,CAAC,EAAE,GAAG,SAAS,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IAE5B;;OAEG;IACH,KAAK,EAAE,QAAQ,SAAS,IAAI,GAAG,CAAC,OAAO,GAAG,IAAI,CAAC,EAAE,GAAG,SAAS,GAAG,OAAO,EAAE,GAAG,SAAS,CAAA;IAErF;;OAEG;IACH,YAAY,EAAE,QAAQ,SAAS,IAAI,GAAG,OAAO,EAAE,GAAG,IAAI,GAAG,SAAS,GAAG,OAAO,EAAE,GAAG,SAAS,CAAA;gBAE9E,MAAM,EAAE,WAAW,CAAC,QAAQ,CAAC;IAczC,KAAK,IAAI,IAAI,IAAI,MAAM,CAAC,QAAQ,CAAC;IAIjC,OAAO,IAAI,QAAQ,CAAC,QAAQ,CAAC;IAI7B,WAAW,IAAI,QAAQ,CAAC,QAAQ,CAAC;IAIjC,YAAY,CAAC,OAAO,EAAE,mBAAmB,GAAG,SAAS,CAAC,iBAAiB;CAexE"}
@@ -3,7 +3,99 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.OasArray = void 0;
4
4
  require("../../_dnt.polyfills.js");
5
5
  /**
6
- * Object representing an array in the OpenAPI Specification.
6
+ * Represents an array schema in the OpenAPI Specification.
7
+ *
8
+ * `OasArray` handles array type definitions with comprehensive validation
9
+ * constraints including item count limits, uniqueness requirements, and
10
+ * item type specifications. It supports nested schemas and references
11
+ * for complex array structures.
12
+ *
13
+ * This class is used throughout the OAS processing pipeline to represent
14
+ * array fields in API schemas, including lists of objects, primitive arrays,
15
+ * and complex nested array structures.
16
+ *
17
+ * ## Key Features
18
+ *
19
+ * - **Item Type Definition**: Support for any schema type as array items
20
+ * - **Size Constraints**: Minimum and maximum item count validation
21
+ * - **Uniqueness Validation**: Ensure array items are unique (like Set behavior)
22
+ * - **Nested Schemas**: Support for complex nested array structures
23
+ * - **Reference Handling**: Seamless integration with schema references
24
+ * - **Nullable Support**: Type-safe nullable array handling
25
+ * - **JSON Schema**: Conversion to standard JSON Schema format
26
+ *
27
+ * @template Nullable - Whether the array value can be null
28
+ *
29
+ * @example String array
30
+ * ```typescript
31
+ * import { OasArray, OasString } from '@skmtc/core';
32
+ *
33
+ * const tagsArray = new OasArray({
34
+ * title: 'Tags',
35
+ * description: 'List of tags associated with the item',
36
+ * items: new OasString({ minLength: 1 }),
37
+ * minItems: 1,
38
+ * uniqueItems: true,
39
+ * example: ['javascript', 'typescript', 'react']
40
+ * });
41
+ * ```
42
+ *
43
+ * @example Object array with references
44
+ * ```typescript
45
+ * import { OasArray, OasRef } from '@skmtc/core';
46
+ *
47
+ * const usersArray = new OasArray({
48
+ * title: 'Users',
49
+ * description: 'List of user objects',
50
+ * items: new OasRef({ refName: 'User' }),
51
+ * maxItems: 100,
52
+ * example: [
53
+ * { id: 1, name: 'John' },
54
+ * { id: 2, name: 'Jane' }
55
+ * ]
56
+ * });
57
+ * ```
58
+ *
59
+ * @example Nested array (array of arrays)
60
+ * ```typescript
61
+ * const matrixArray = new OasArray({
62
+ * title: 'Matrix',
63
+ * description: '2D array of numbers',
64
+ * items: new OasArray({
65
+ * items: new OasInteger({ minimum: 0 })
66
+ * }),
67
+ * example: [
68
+ * [1, 2, 3],
69
+ * [4, 5, 6],
70
+ * [7, 8, 9]
71
+ * ]
72
+ * });
73
+ * ```
74
+ *
75
+ * @example Nullable array with constraints
76
+ * ```typescript
77
+ * const optionalIdsArray = new OasArray<true>({
78
+ * title: 'Optional IDs',
79
+ * description: 'Optional list of IDs',
80
+ * items: new OasInteger({ format: 'int64', minimum: 1 }),
81
+ * nullable: true,
82
+ * minItems: 0,
83
+ * maxItems: 10,
84
+ * defaultValue: null
85
+ * });
86
+ * ```
87
+ *
88
+ * @example Unique items validation
89
+ * ```typescript
90
+ * const uniqueEmailsArray = new OasArray({
91
+ * title: 'Email Recipients',
92
+ * description: 'List of unique email addresses',
93
+ * items: new OasString({ format: 'email' }),
94
+ * uniqueItems: true, // Ensures no duplicate emails
95
+ * minItems: 1,
96
+ * example: ['user1@example.com', 'user2@example.com']
97
+ * });
98
+ * ```
7
99
  */
8
100
  class OasArray {
9
101
  constructor(fields) {