@skmtc/core 0.0.785 → 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 (93) 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/dsl/Identifier.d.ts +152 -0
  11. package/esm/dsl/Identifier.d.ts.map +1 -1
  12. package/esm/dsl/Identifier.js +152 -0
  13. package/esm/dsl/Import.d.ts +221 -0
  14. package/esm/dsl/Import.d.ts.map +1 -1
  15. package/esm/dsl/Import.js +202 -0
  16. package/esm/dsl/operation/OperationBase.d.ts +181 -1
  17. package/esm/dsl/operation/OperationBase.d.ts.map +1 -1
  18. package/esm/dsl/operation/OperationBase.js +181 -1
  19. package/esm/oas/array/Array.d.ts +109 -1
  20. package/esm/oas/array/Array.d.ts.map +1 -1
  21. package/esm/oas/array/Array.js +93 -1
  22. package/esm/oas/document/Document.d.ts +155 -1
  23. package/esm/oas/document/Document.d.ts.map +1 -1
  24. package/esm/oas/document/Document.js +141 -2
  25. package/esm/oas/integer/Integer.d.ts +98 -0
  26. package/esm/oas/integer/Integer.d.ts.map +1 -1
  27. package/esm/oas/integer/Integer.js +80 -0
  28. package/esm/oas/object/Object.d.ts +255 -10
  29. package/esm/oas/object/Object.d.ts.map +1 -1
  30. package/esm/oas/object/Object.js +229 -10
  31. package/esm/oas/string/String.d.ts +103 -1
  32. package/esm/oas/string/String.d.ts.map +1 -1
  33. package/esm/oas/string/String.js +87 -1
  34. package/esm/types/Brand.d.ts +74 -0
  35. package/esm/types/Brand.d.ts.map +1 -1
  36. package/esm/types/Brand.js +9 -0
  37. package/esm/types/GeneratorKeys.d.ts +336 -0
  38. package/esm/types/GeneratorKeys.d.ts.map +1 -1
  39. package/esm/types/GeneratorKeys.js +243 -0
  40. package/esm/types/GeneratorType.d.ts +119 -0
  41. package/esm/types/GeneratorType.d.ts.map +1 -1
  42. package/esm/types/Method.d.ts +109 -0
  43. package/esm/types/Method.d.ts.map +1 -1
  44. package/esm/types/Method.js +84 -0
  45. package/esm/types/RefName.d.ts +61 -0
  46. package/esm/types/RefName.d.ts.map +1 -1
  47. package/package.json +1 -1
  48. package/script/dsl/ContentSettings.d.ts +164 -0
  49. package/script/dsl/ContentSettings.d.ts.map +1 -1
  50. package/script/dsl/ContentSettings.js +151 -0
  51. package/script/dsl/Definition.d.ts +199 -0
  52. package/script/dsl/Definition.d.ts.map +1 -1
  53. package/script/dsl/Definition.js +189 -0
  54. package/script/dsl/EntityType.d.ts +83 -0
  55. package/script/dsl/EntityType.d.ts.map +1 -1
  56. package/script/dsl/EntityType.js +83 -0
  57. package/script/dsl/Identifier.d.ts +152 -0
  58. package/script/dsl/Identifier.d.ts.map +1 -1
  59. package/script/dsl/Identifier.js +152 -0
  60. package/script/dsl/Import.d.ts +221 -0
  61. package/script/dsl/Import.d.ts.map +1 -1
  62. package/script/dsl/Import.js +202 -0
  63. package/script/dsl/operation/OperationBase.d.ts +181 -1
  64. package/script/dsl/operation/OperationBase.d.ts.map +1 -1
  65. package/script/dsl/operation/OperationBase.js +181 -1
  66. package/script/oas/array/Array.d.ts +109 -1
  67. package/script/oas/array/Array.d.ts.map +1 -1
  68. package/script/oas/array/Array.js +93 -1
  69. package/script/oas/document/Document.d.ts +155 -1
  70. package/script/oas/document/Document.d.ts.map +1 -1
  71. package/script/oas/document/Document.js +141 -2
  72. package/script/oas/integer/Integer.d.ts +98 -0
  73. package/script/oas/integer/Integer.d.ts.map +1 -1
  74. package/script/oas/integer/Integer.js +80 -0
  75. package/script/oas/object/Object.d.ts +255 -10
  76. package/script/oas/object/Object.d.ts.map +1 -1
  77. package/script/oas/object/Object.js +229 -10
  78. package/script/oas/string/String.d.ts +103 -1
  79. package/script/oas/string/String.d.ts.map +1 -1
  80. package/script/oas/string/String.js +87 -1
  81. package/script/types/Brand.d.ts +74 -0
  82. package/script/types/Brand.d.ts.map +1 -1
  83. package/script/types/Brand.js +9 -0
  84. package/script/types/GeneratorKeys.d.ts +336 -0
  85. package/script/types/GeneratorKeys.d.ts.map +1 -1
  86. package/script/types/GeneratorKeys.js +243 -0
  87. package/script/types/GeneratorType.d.ts +119 -0
  88. package/script/types/GeneratorType.d.ts.map +1 -1
  89. package/script/types/Method.d.ts +109 -0
  90. package/script/types/Method.d.ts.map +1 -1
  91. package/script/types/Method.js +84 -0
  92. package/script/types/RefName.d.ts +61 -0
  93. package/script/types/RefName.d.ts.map +1 -1
@@ -2,21 +2,108 @@ import "../../_dnt.polyfills.js";
2
2
  import type { OasRef } from '../ref/Ref.js';
3
3
  import type { ToJsonSchemaOptions } from '../schema/Schema.js';
4
4
  import type { OpenAPIV3 } from 'openapi-types';
5
+ /**
6
+ * Constructor fields for {@link OasString}.
7
+ *
8
+ * @template Nullable - Whether the string value can be null
9
+ */
5
10
  export type StringFields<Nullable extends boolean | undefined> = {
11
+ /** A short summary of the string schema */
6
12
  title?: string;
13
+ /** A description of the string schema */
7
14
  description?: string;
15
+ /** String format (e.g., 'email', 'date-time', 'uri') */
8
16
  format?: string;
17
+ /** Default value for the string */
9
18
  default?: Nullable extends true ? string | null | undefined : string | undefined;
19
+ /** Regular expression pattern for validation */
10
20
  pattern?: string;
21
+ /** Array of allowed enum values */
11
22
  enums?: Nullable extends true ? (string | null)[] | undefined : string[] | undefined;
23
+ /** Maximum length constraint */
12
24
  maxLength?: number;
25
+ /** Minimum length constraint */
13
26
  minLength?: number;
27
+ /** Whether the string value can be null */
14
28
  nullable?: Nullable;
29
+ /** Custom extension fields (x-* properties) */
15
30
  extensionFields?: Record<string, unknown>;
31
+ /** Example value for the string */
16
32
  example?: Nullable extends true ? string | null | undefined : string | undefined;
17
33
  };
18
34
  /**
19
- * Object representing a string in the OpenAPI Specification.
35
+ * Represents a string schema in the OpenAPI Specification.
36
+ *
37
+ * `OasString` handles string type definitions with comprehensive validation
38
+ * constraints including format validation, length limits, pattern matching,
39
+ * and enum restrictions. It supports nullable types and provides JSON Schema
40
+ * conversion for validation purposes.
41
+ *
42
+ * This class is used throughout the OAS processing pipeline to represent
43
+ * string fields in API schemas, parameters, and request/response bodies.
44
+ *
45
+ * ## Key Features
46
+ *
47
+ * - **Format Validation**: Support for standard formats (email, date-time, uri, etc.)
48
+ * - **Length Constraints**: Minimum and maximum length validation
49
+ * - **Pattern Matching**: Regular expression validation
50
+ * - **Enum Values**: Restricted sets of allowed values
51
+ * - **Nullable Support**: Type-safe nullable string handling
52
+ * - **JSON Schema**: Conversion to standard JSON Schema format
53
+ *
54
+ * @template Nullable - Whether the string value can be null
55
+ *
56
+ * @example Basic string schema
57
+ * ```typescript
58
+ * import { OasString } from '@skmtc/core';
59
+ *
60
+ * const basicString = new OasString({
61
+ * title: 'User Name',
62
+ * description: 'The full name of the user',
63
+ * minLength: 1,
64
+ * maxLength: 100
65
+ * });
66
+ * ```
67
+ *
68
+ * @example Email format validation
69
+ * ```typescript
70
+ * const emailString = new OasString({
71
+ * title: 'Email Address',
72
+ * description: 'Valid email address',
73
+ * format: 'email',
74
+ * example: 'user@example.com'
75
+ * });
76
+ * ```
77
+ *
78
+ * @example Enum with allowed values
79
+ * ```typescript
80
+ * const statusString = new OasString({
81
+ * title: 'Status',
82
+ * description: 'Current status of the item',
83
+ * enums: ['pending', 'approved', 'rejected'],
84
+ * default: 'pending'
85
+ * });
86
+ * ```
87
+ *
88
+ * @example Pattern validation
89
+ * ```typescript
90
+ * const phoneString = new OasString({
91
+ * title: 'Phone Number',
92
+ * description: 'US phone number format',
93
+ * pattern: '^\\+?1?[2-9]\\d{2}[2-9]\\d{2}\\d{4}$',
94
+ * example: '+15551234567'
95
+ * });
96
+ * ```
97
+ *
98
+ * @example Nullable string
99
+ * ```typescript
100
+ * const nullableString = new OasString<true>({
101
+ * title: 'Optional Note',
102
+ * description: 'Optional note that can be null',
103
+ * nullable: true,
104
+ * default: null
105
+ * });
106
+ * ```
20
107
  */
21
108
  export declare class OasString<Nullable extends boolean | undefined = boolean | undefined> {
22
109
  /**
@@ -68,6 +155,21 @@ export declare class OasString<Nullable extends boolean | undefined = boolean |
68
155
  * The default value of the string.
69
156
  */
70
157
  default: Nullable extends true ? string | null | undefined : string | undefined;
158
+ /**
159
+ * Creates a new OasString instance.
160
+ *
161
+ * @param fields - String schema configuration fields
162
+ *
163
+ * @example
164
+ * ```typescript
165
+ * const userIdString = new OasString({
166
+ * title: 'User ID',
167
+ * description: 'Unique identifier for user',
168
+ * format: 'uuid',
169
+ * example: '123e4567-e89b-12d3-a456-426614174000'
170
+ * });
171
+ * ```
172
+ */
71
173
  constructor(fields?: StringFields<Nullable>);
72
174
  isRef(): this is OasRef<'schema'>;
73
175
  resolve(): OasString<Nullable>;
@@ -1 +1 @@
1
- {"version":3,"file":"String.d.ts","sourceRoot":"","sources":["../../../src/oas/string/String.ts"],"names":[],"mappings":"AAAA,OAAO,yBAAyB,CAAC;AACjC,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,eAAe,CAAA;AAC3C,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAA;AAC9D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,eAAe,CAAA;AAE9C,MAAM,MAAM,YAAY,CAAC,QAAQ,SAAS,OAAO,GAAG,SAAS,IAAI;IAC/D,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,OAAO,CAAC,EAAE,QAAQ,SAAS,IAAI,GAAG,MAAM,GAAG,IAAI,GAAG,SAAS,GAAG,MAAM,GAAG,SAAS,CAAA;IAChF,OA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,CAAA;IAC9B,qCAAqC;IACrC,eAAe,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS,CAAA;IACpD,gCAAgC;IAChC,OAAO,EAAE,QAAQ,SAAS,IAAI,GAAG,MAAM,GAAG,IAAI,GAAG,SAAS,GAAG,MAAM,GAAG,SAAS,CAAA;IAC/E;;OAEG;IACH,OAAO,EAAE,MAAM,GAAG,SAAS,CAAA;IAC3B;;OAEG;IACH,OAAO,EAAE,QAAQ,SAAS,IAAI,GAAG,MAAM,GAAG,IAAI,GAAG,SAAS,GAAG,MAAM,GAAG,SAAS,CAAA;IAE/E;;;;;;;;;;;;;;OAcG;gBACS,MAAM,GAAE,YAAY,CAAC,QAAQ,CAAM;IAc/C,KAAK,IAAI,IAAI,IAAI,MAAM,CAAC,QAAQ,CAAC;IAIjC,OAAO,IAAI,SAAS,CAAC,QAAQ,CAAC;IAI9B,WAAW,IAAI,SAAS,CAAC,QAAQ,CAAC;IAKlC,YAAY,CAAC,OAAO,CAAC,EAAE,mBAAmB,GAAG,SAAS,CAAC,oBAAoB;CAe5E"}
@@ -1,8 +1,94 @@
1
1
  import "../../_dnt.polyfills.js";
2
2
  /**
3
- * Object representing a string in the OpenAPI Specification.
3
+ * Represents a string schema in the OpenAPI Specification.
4
+ *
5
+ * `OasString` handles string type definitions with comprehensive validation
6
+ * constraints including format validation, length limits, pattern matching,
7
+ * and enum restrictions. It supports nullable types and provides JSON Schema
8
+ * conversion for validation purposes.
9
+ *
10
+ * This class is used throughout the OAS processing pipeline to represent
11
+ * string fields in API schemas, parameters, and request/response bodies.
12
+ *
13
+ * ## Key Features
14
+ *
15
+ * - **Format Validation**: Support for standard formats (email, date-time, uri, etc.)
16
+ * - **Length Constraints**: Minimum and maximum length validation
17
+ * - **Pattern Matching**: Regular expression validation
18
+ * - **Enum Values**: Restricted sets of allowed values
19
+ * - **Nullable Support**: Type-safe nullable string handling
20
+ * - **JSON Schema**: Conversion to standard JSON Schema format
21
+ *
22
+ * @template Nullable - Whether the string value can be null
23
+ *
24
+ * @example Basic string schema
25
+ * ```typescript
26
+ * import { OasString } from '@skmtc/core';
27
+ *
28
+ * const basicString = new OasString({
29
+ * title: 'User Name',
30
+ * description: 'The full name of the user',
31
+ * minLength: 1,
32
+ * maxLength: 100
33
+ * });
34
+ * ```
35
+ *
36
+ * @example Email format validation
37
+ * ```typescript
38
+ * const emailString = new OasString({
39
+ * title: 'Email Address',
40
+ * description: 'Valid email address',
41
+ * format: 'email',
42
+ * example: 'user@example.com'
43
+ * });
44
+ * ```
45
+ *
46
+ * @example Enum with allowed values
47
+ * ```typescript
48
+ * const statusString = new OasString({
49
+ * title: 'Status',
50
+ * description: 'Current status of the item',
51
+ * enums: ['pending', 'approved', 'rejected'],
52
+ * default: 'pending'
53
+ * });
54
+ * ```
55
+ *
56
+ * @example Pattern validation
57
+ * ```typescript
58
+ * const phoneString = new OasString({
59
+ * title: 'Phone Number',
60
+ * description: 'US phone number format',
61
+ * pattern: '^\\+?1?[2-9]\\d{2}[2-9]\\d{2}\\d{4}$',
62
+ * example: '+15551234567'
63
+ * });
64
+ * ```
65
+ *
66
+ * @example Nullable string
67
+ * ```typescript
68
+ * const nullableString = new OasString<true>({
69
+ * title: 'Optional Note',
70
+ * description: 'Optional note that can be null',
71
+ * nullable: true,
72
+ * default: null
73
+ * });
74
+ * ```
4
75
  */
5
76
  export class OasString {
77
+ /**
78
+ * Creates a new OasString instance.
79
+ *
80
+ * @param fields - String schema configuration fields
81
+ *
82
+ * @example
83
+ * ```typescript
84
+ * const userIdString = new OasString({
85
+ * title: 'User ID',
86
+ * description: 'Unique identifier for user',
87
+ * format: 'uuid',
88
+ * example: '123e4567-e89b-12d3-a456-426614174000'
89
+ * });
90
+ * ```
91
+ */
6
92
  constructor(fields = {}) {
7
93
  /**
8
94
  * Object is part the 'schema' set which is used
@@ -1,5 +1,79 @@
1
+ /**
2
+ * Unique symbol used for branding types.
3
+ *
4
+ * This symbol is used internally by the {@link Brand} type to create
5
+ * unique branded types that are structurally identical but nominally
6
+ * distinct from their base types.
7
+ *
8
+ * @internal
9
+ */
1
10
  import "../_dnt.polyfills.js";
2
11
  declare const brand: unique symbol;
12
+ /**
13
+ * Creates a branded type from a base type.
14
+ *
15
+ * Brand types (also known as nominal types or opaque types) are TypeScript
16
+ * types that are structurally identical to their base type but are treated
17
+ * as distinct types by the type system. This prevents accidental mixing of
18
+ * values that should be kept separate.
19
+ *
20
+ * The SKMTC system uses branded types extensively to ensure type safety
21
+ * when working with identifiers, keys, and other string-based values that
22
+ * have specific semantic meaning.
23
+ *
24
+ * @template T - The base type to brand
25
+ * @template TBrand - The brand identifier (usually a string literal)
26
+ *
27
+ * @example Basic branded type usage
28
+ * ```typescript
29
+ * import { Brand } from '@skmtc/core';
30
+ *
31
+ * type UserId = Brand<string, 'UserId'>;
32
+ * type ProductId = Brand<string, 'ProductId'>;
33
+ *
34
+ * const userId: UserId = 'user-123' as UserId;
35
+ * const productId: ProductId = 'prod-456' as ProductId;
36
+ *
37
+ * function getUser(id: UserId) {
38
+ * // Function expects a UserId, not just any string
39
+ * return `User with ID: ${id}`;
40
+ * }
41
+ *
42
+ * getUser(userId); // ✅ Works - correct type
43
+ * getUser(productId); // ❌ TypeScript error - ProductId is not UserId
44
+ * getUser('user-789'); // ❌ TypeScript error - string is not UserId
45
+ * ```
46
+ *
47
+ * @example SKMTC branded types
48
+ * ```typescript
49
+ * // RefName ensures schema reference safety
50
+ * type RefName = Brand<string, 'RefName'>;
51
+ * const schemaRef: RefName = 'User' as RefName;
52
+ *
53
+ * // GeneratorKey ensures generator identification safety
54
+ * type OperationGeneratorKey = Brand<string, 'OperationGeneratorKey'>;
55
+ * const opKey: OperationGeneratorKey = 'api-client|/users|get' as OperationGeneratorKey;
56
+ * ```
57
+ *
58
+ * @example Runtime behavior
59
+ * ```typescript
60
+ * type EmailAddress = Brand<string, 'EmailAddress'>;
61
+ *
62
+ * const email: EmailAddress = 'user@example.com' as EmailAddress;
63
+ *
64
+ * // At runtime, branded types are just their base type
65
+ * console.log(typeof email); // 'string'
66
+ * console.log(email); // 'user@example.com'
67
+ *
68
+ * // But TypeScript enforces the brand at compile time
69
+ * function sendEmail(to: EmailAddress) {
70
+ * // Implementation
71
+ * }
72
+ *
73
+ * sendEmail(email); // ✅ Works
74
+ * sendEmail('test@example.com'); // ❌ Error - needs EmailAddress brand
75
+ * ```
76
+ */
3
77
  export type Brand<T, TBrand> = T & {
4
78
  [brand]: TBrand;
5
79
  };
@@ -1 +1 @@
1
- {"version":3,"file":"Brand.d.ts","sourceRoot":"","sources":["../../src/types/Brand.ts"],"names":[],"mappings":"AAAA,OAAO,sBAAsB,CAAC;AAC9B,OAAO,CAAC,MAAM,KAAK,EAAE,OAAO,MAAM,CAAA;AAElC,MAAM,MAAM,KAAK,CAAC,CAAC,EAAE,MAAM,IAAI,CAAC,GAAG;IAAE,CAAC,KAAK,CAAC,EAAE,MAAM,CAAA;CAAE,CAAA"}
1
+ {"version":3,"file":"Brand.d.ts","sourceRoot":"","sources":["../../src/types/Brand.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,sBAAsB,CAAC;AAE9B,OAAO,CAAC,MAAM,KAAK,EAAE,OAAO,MAAM,CAAA;AAElC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgEG;AACH,MAAM,MAAM,KAAK,CAAC,CAAC,EAAE,MAAM,IAAI,CAAC,GAAG;IAAE,CAAC,KAAK,CAAC,EAAE,MAAM,CAAA;CAAE,CAAA"}
@@ -1 +1,10 @@
1
+ /**
2
+ * Unique symbol used for branding types.
3
+ *
4
+ * This symbol is used internally by the {@link Brand} type to create
5
+ * unique branded types that are structurally identical but nominally
6
+ * distinct from their base types.
7
+ *
8
+ * @internal
9
+ */
1
10
  import "../_dnt.polyfills.js";