@skmtc/core 0.0.786 → 0.0.788
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/esm/context/GenerateContext.d.ts +95 -0
- package/esm/context/GenerateContext.d.ts.map +1 -1
- package/esm/context/GenerateContext.js +95 -0
- package/esm/dsl/ContentSettings.d.ts +164 -0
- package/esm/dsl/ContentSettings.d.ts.map +1 -1
- package/esm/dsl/ContentSettings.js +151 -0
- package/esm/dsl/Definition.d.ts +199 -0
- package/esm/dsl/Definition.d.ts.map +1 -1
- package/esm/dsl/Definition.js +189 -0
- package/esm/dsl/EntityType.d.ts +83 -0
- package/esm/dsl/EntityType.d.ts.map +1 -1
- package/esm/dsl/EntityType.js +83 -0
- package/esm/dsl/JsonFile.d.ts +162 -0
- package/esm/dsl/JsonFile.d.ts.map +1 -1
- package/esm/dsl/JsonFile.js +157 -0
- package/esm/oas/array/Array.d.ts +109 -1
- package/esm/oas/array/Array.d.ts.map +1 -1
- package/esm/oas/array/Array.js +93 -1
- package/esm/oas/integer/Integer.d.ts +98 -0
- package/esm/oas/integer/Integer.d.ts.map +1 -1
- package/esm/oas/integer/Integer.js +80 -0
- package/esm/oas/operation/Operation.d.ts +107 -1
- package/esm/oas/operation/Operation.d.ts.map +1 -1
- package/esm/oas/operation/Operation.js +107 -1
- package/esm/oas/ref/Ref.d.ts +86 -0
- package/esm/oas/ref/Ref.d.ts.map +1 -1
- package/esm/oas/ref/Ref.js +86 -0
- package/esm/oas/string/String.d.ts +103 -1
- package/esm/oas/string/String.d.ts.map +1 -1
- package/esm/oas/string/String.js +87 -1
- package/esm/types/Brand.d.ts +74 -0
- package/esm/types/Brand.d.ts.map +1 -1
- package/esm/types/Brand.js +9 -0
- package/esm/types/RefName.d.ts +61 -0
- package/esm/types/RefName.d.ts.map +1 -1
- package/package.json +1 -1
- package/script/context/GenerateContext.d.ts +95 -0
- package/script/context/GenerateContext.d.ts.map +1 -1
- package/script/context/GenerateContext.js +95 -0
- package/script/dsl/ContentSettings.d.ts +164 -0
- package/script/dsl/ContentSettings.d.ts.map +1 -1
- package/script/dsl/ContentSettings.js +151 -0
- package/script/dsl/Definition.d.ts +199 -0
- package/script/dsl/Definition.d.ts.map +1 -1
- package/script/dsl/Definition.js +189 -0
- package/script/dsl/EntityType.d.ts +83 -0
- package/script/dsl/EntityType.d.ts.map +1 -1
- package/script/dsl/EntityType.js +83 -0
- package/script/dsl/JsonFile.d.ts +162 -0
- package/script/dsl/JsonFile.d.ts.map +1 -1
- package/script/dsl/JsonFile.js +157 -0
- package/script/oas/array/Array.d.ts +109 -1
- package/script/oas/array/Array.d.ts.map +1 -1
- package/script/oas/array/Array.js +93 -1
- package/script/oas/integer/Integer.d.ts +98 -0
- package/script/oas/integer/Integer.d.ts.map +1 -1
- package/script/oas/integer/Integer.js +80 -0
- package/script/oas/operation/Operation.d.ts +107 -1
- package/script/oas/operation/Operation.d.ts.map +1 -1
- package/script/oas/operation/Operation.js +107 -1
- package/script/oas/ref/Ref.d.ts +86 -0
- package/script/oas/ref/Ref.d.ts.map +1 -1
- package/script/oas/ref/Ref.js +86 -0
- package/script/oas/string/String.d.ts +103 -1
- package/script/oas/string/String.d.ts.map +1 -1
- package/script/oas/string/String.js +87 -1
- package/script/types/Brand.d.ts +74 -0
- package/script/types/Brand.d.ts.map +1 -1
- package/script/types/Brand.js +9 -0
- package/script/types/RefName.d.ts +61 -0
- 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
|
-
*
|
|
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,GA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,GAAG,SAAS,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"}
|
package/esm/oas/string/String.js
CHANGED
|
@@ -1,8 +1,94 @@
|
|
|
1
1
|
import "../../_dnt.polyfills.js";
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
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
|
package/esm/types/Brand.d.ts
CHANGED
|
@@ -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
|
};
|
package/esm/types/Brand.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Brand.d.ts","sourceRoot":"","sources":["../../src/types/Brand.ts"],"names":[],"mappings":"AAAA,OAAO,sBAAsB,CAAC;
|
|
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"}
|
package/esm/types/Brand.js
CHANGED
|
@@ -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";
|
package/esm/types/RefName.d.ts
CHANGED
|
@@ -1,4 +1,65 @@
|
|
|
1
1
|
import "../_dnt.polyfills.js";
|
|
2
2
|
import type { Brand } from './Brand.js';
|
|
3
|
+
/**
|
|
4
|
+
* Branded type representing a reference name for OpenAPI schemas.
|
|
5
|
+
*
|
|
6
|
+
* `RefName` is a branded string type that ensures type safety when working
|
|
7
|
+
* with schema reference names throughout the SKMTC system. It prevents
|
|
8
|
+
* accidental mixing of regular strings with schema reference identifiers.
|
|
9
|
+
*
|
|
10
|
+
* Reference names typically correspond to keys in the OpenAPI `components.schemas`
|
|
11
|
+
* section and are used to create cross-references between different parts
|
|
12
|
+
* of the schema definition.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```typescript
|
|
16
|
+
* import { RefName } from '@skmtc/core';
|
|
17
|
+
*
|
|
18
|
+
* // RefName is extracted from OpenAPI schema references
|
|
19
|
+
* const userRefName: RefName = 'User' as RefName;
|
|
20
|
+
* const productRefName: RefName = 'Product' as RefName;
|
|
21
|
+
*
|
|
22
|
+
* // Used in schema references
|
|
23
|
+
* const userRef = new OasRef({
|
|
24
|
+
* refName: userRefName, // Type-safe reference name
|
|
25
|
+
* ref: '#/components/schemas/User'
|
|
26
|
+
* });
|
|
27
|
+
* ```
|
|
28
|
+
*
|
|
29
|
+
* @example In generator contexts
|
|
30
|
+
* ```typescript
|
|
31
|
+
* class ModelGenerator extends ModelBase {
|
|
32
|
+
* constructor(args: { refName: RefName; ... }) {
|
|
33
|
+
* super(args);
|
|
34
|
+
* // this.refName is guaranteed to be a valid schema reference
|
|
35
|
+
* }
|
|
36
|
+
*
|
|
37
|
+
* toDefinition(): Definition {
|
|
38
|
+
* // RefName ensures we're working with valid schema identifiers
|
|
39
|
+
* const schemaName = this.refName; // Type: RefName
|
|
40
|
+
* return new Definition({
|
|
41
|
+
* identifier: Identifier.createType(schemaName),
|
|
42
|
+
* // ...
|
|
43
|
+
* });
|
|
44
|
+
* }
|
|
45
|
+
* }
|
|
46
|
+
* ```
|
|
47
|
+
*
|
|
48
|
+
* @example Type safety benefits
|
|
49
|
+
* ```typescript
|
|
50
|
+
* function processSchema(refName: RefName) {
|
|
51
|
+
* // RefName brand ensures this is a valid schema reference
|
|
52
|
+
* console.log(`Processing schema: ${refName}`);
|
|
53
|
+
* }
|
|
54
|
+
*
|
|
55
|
+
* const validRef: RefName = 'User' as RefName;
|
|
56
|
+
* const regularString = 'just a string';
|
|
57
|
+
*
|
|
58
|
+
* processSchema(validRef); // ✅ Works - RefName type
|
|
59
|
+
* processSchema(regularString); // ❌ TypeScript error - string is not RefName
|
|
60
|
+
* ```
|
|
61
|
+
*
|
|
62
|
+
* @see {@link Brand} for the underlying branding mechanism
|
|
63
|
+
*/
|
|
3
64
|
export type RefName = Brand<string, 'RefName'>;
|
|
4
65
|
//# sourceMappingURL=RefName.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RefName.d.ts","sourceRoot":"","sources":["../../src/types/RefName.ts"],"names":[],"mappings":"AAAA,OAAO,sBAAsB,CAAC;AAC9B,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,YAAY,CAAA;AAEvC,MAAM,MAAM,OAAO,GAAG,KAAK,CAAC,MAAM,EAAE,SAAS,CAAC,CAAA"}
|
|
1
|
+
{"version":3,"file":"RefName.d.ts","sourceRoot":"","sources":["../../src/types/RefName.ts"],"names":[],"mappings":"AAAA,OAAO,sBAAsB,CAAC;AAC9B,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,YAAY,CAAA;AAEvC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4DG;AACH,MAAM,MAAM,OAAO,GAAG,KAAK,CAAC,MAAM,EAAE,SAAS,CAAC,CAAA"}
|
package/package.json
CHANGED
|
@@ -114,6 +114,101 @@ type GenerateResult = {
|
|
|
114
114
|
previews: Record<string, Record<string, Preview>>;
|
|
115
115
|
mappings: Record<string, Record<string, Mapping>>;
|
|
116
116
|
};
|
|
117
|
+
/**
|
|
118
|
+
* The generation context for the second phase of the SKMTC transformation pipeline.
|
|
119
|
+
*
|
|
120
|
+
* `GenerateContext` manages the transformation of parsed OAS (OpenAPI Schema) objects
|
|
121
|
+
* into code artifacts using pluggable generators. It provides APIs for model and operation
|
|
122
|
+
* generation, file management, dependency tracking, and artifact registration.
|
|
123
|
+
*
|
|
124
|
+
* ## Key Responsibilities
|
|
125
|
+
*
|
|
126
|
+
* - **Generator Orchestration**: Executes pluggable model and operation generators
|
|
127
|
+
* - **Schema Processing**: Provides utilities for working with OAS schemas and references
|
|
128
|
+
* - **File Management**: Handles file creation, imports, exports, and dependencies
|
|
129
|
+
* - **Artifact Registration**: Collects generated definitions and files for rendering
|
|
130
|
+
* - **Type System Integration**: Bridges OAS types with generator-specific type systems
|
|
131
|
+
* - **Settings Management**: Handles skipping logic and client customizations
|
|
132
|
+
*
|
|
133
|
+
* ## Generator Integration
|
|
134
|
+
*
|
|
135
|
+
* The context works with two main types of generators:
|
|
136
|
+
* - **Model Generators**: Transform schema definitions into type definitions
|
|
137
|
+
* - **Operation Generators**: Transform API operations into client functions
|
|
138
|
+
*
|
|
139
|
+
* @example Basic usage in a model generator
|
|
140
|
+
* ```typescript
|
|
141
|
+
* import { ModelBase } from '@skmtc/core';
|
|
142
|
+
*
|
|
143
|
+
* class TypeScriptInterface extends ModelBase {
|
|
144
|
+
* generate(): Definition {
|
|
145
|
+
* const schema = this.context.getSchema(this.refName);
|
|
146
|
+
*
|
|
147
|
+
* return new Definition({
|
|
148
|
+
* context: this.context,
|
|
149
|
+
* identifier: Identifier.createType(this.refName),
|
|
150
|
+
* description: schema.description,
|
|
151
|
+
* value: {
|
|
152
|
+
* generatorKey: this.generatorKey,
|
|
153
|
+
* content: this.generateInterfaceBody(schema)
|
|
154
|
+
* }
|
|
155
|
+
* });
|
|
156
|
+
* }
|
|
157
|
+
* }
|
|
158
|
+
* ```
|
|
159
|
+
*
|
|
160
|
+
* @example Operation generator usage
|
|
161
|
+
* ```typescript
|
|
162
|
+
* class ApiClientGenerator extends OperationBase {
|
|
163
|
+
* generate(): Definition {
|
|
164
|
+
* const operation = this.context.getOperation(this.path, this.method);
|
|
165
|
+
*
|
|
166
|
+
* const functionName = this.context.createOperationName(this.path, this.method);
|
|
167
|
+
*
|
|
168
|
+
* return new Definition({
|
|
169
|
+
* context: this.context,
|
|
170
|
+
* identifier: Identifier.createVariable(functionName),
|
|
171
|
+
* value: {
|
|
172
|
+
* generatorKey: this.generatorKey,
|
|
173
|
+
* content: this.generateClientFunction(operation)
|
|
174
|
+
* }
|
|
175
|
+
* });
|
|
176
|
+
* }
|
|
177
|
+
* }
|
|
178
|
+
* ```
|
|
179
|
+
*
|
|
180
|
+
* @example Schema and type system integration
|
|
181
|
+
* ```typescript
|
|
182
|
+
* class MyGenerator extends ModelBase {
|
|
183
|
+
* generate(): Definition {
|
|
184
|
+
* const schema = this.context.getSchema(this.refName);
|
|
185
|
+
*
|
|
186
|
+
* // Transform schema using type system
|
|
187
|
+
* const typeOutput = this.context.transformSchema(schema, {
|
|
188
|
+
* stringType: 'string',
|
|
189
|
+
* numberType: 'number',
|
|
190
|
+
* arrayType: (items) => `Array<${items}>`
|
|
191
|
+
* });
|
|
192
|
+
*
|
|
193
|
+
* // Register dependencies
|
|
194
|
+
* if (schema.hasReferences()) {
|
|
195
|
+
* this.context.addImportsToFile('./models/types.ts', {
|
|
196
|
+
* './common': ['BaseModel']
|
|
197
|
+
* });
|
|
198
|
+
* }
|
|
199
|
+
*
|
|
200
|
+
* return new Definition({
|
|
201
|
+
* context: this.context,
|
|
202
|
+
* identifier: Identifier.createType(this.refName),
|
|
203
|
+
* value: {
|
|
204
|
+
* generatorKey: this.generatorKey,
|
|
205
|
+
* content: typeOutput.content
|
|
206
|
+
* }
|
|
207
|
+
* });
|
|
208
|
+
* }
|
|
209
|
+
* }
|
|
210
|
+
* ```
|
|
211
|
+
*/
|
|
117
212
|
export declare class GenerateContext {
|
|
118
213
|
#private;
|
|
119
214
|
oasDocument: OasDocument;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GenerateContext.d.ts","sourceRoot":"","sources":["../../src/context/GenerateContext.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAA;AAErD,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAA;AACjD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAA;AAC9D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAA;AACxD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAA;AAE/C,OAAO,KAAK,EAAE,cAAc,EAAyC,MAAM,sBAAsB,CAAA;AACjG,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAA;AAChD,OAAO,KAAK,EAAmB,mBAAmB,EAAE,MAAM,2BAA2B,CAAA;AACrF,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAA;AACjE,OAAO,KAAK,EAAe,eAAe,EAAE,MAAM,uBAAuB,CAAA;AAGzE,OAAO,KAAK,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAA;AAChF,OAAO,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAA;AAC3D,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAA;AAElD,OAAO,KAAK,KAAK,GAAG,MAAM,yCAAyC,CAAA;AACnE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAA;AACrD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAEjD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAA;AACtD,OAAO,KAAK,EACV,cAAc,EACd,eAAe,EACf,UAAU,EACV,gBAAgB,EACjB,MAAM,wBAAwB,CAAA;AAC/B,OAAO,EAAE,QAAQ,EAAE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AE,QAAQ,GAAG,UAAU,GAAG,SAAS;CAOvE;AAED,KAAK,qBAAqB,GAAG;IAC3B,SAAS,EAAE,YAAY,CAAA;IACvB,WAAW,EAAE,MAAM,CAAA;CACpB,CAAA;AAED,eAAO,MAAM,iBAAiB,GAAI,4BAG/B,qBAAqB,KAAG,eAKzB,CAAA;AAEF,KAAK,iBAAiB,GAAG;IACvB,OAAO,EAAE,OAAO,CAAA;IAChB,WAAW,EAAE,MAAM,CAAA;CACpB,CAAA;AAED,eAAO,MAAM,aAAa,GAAI,0BAA0B,iBAAiB,KAAG,WAI1E,CAAA"}
|
|
@@ -62,6 +62,101 @@ const File_js_1 = require("../dsl/File.js");
|
|
|
62
62
|
const JsonFile_js_1 = require("../dsl/JsonFile.js");
|
|
63
63
|
const tiny_invariant_1 = __importDefault(require("tiny-invariant"));
|
|
64
64
|
const ts_pattern_1 = require("ts-pattern");
|
|
65
|
+
/**
|
|
66
|
+
* The generation context for the second phase of the SKMTC transformation pipeline.
|
|
67
|
+
*
|
|
68
|
+
* `GenerateContext` manages the transformation of parsed OAS (OpenAPI Schema) objects
|
|
69
|
+
* into code artifacts using pluggable generators. It provides APIs for model and operation
|
|
70
|
+
* generation, file management, dependency tracking, and artifact registration.
|
|
71
|
+
*
|
|
72
|
+
* ## Key Responsibilities
|
|
73
|
+
*
|
|
74
|
+
* - **Generator Orchestration**: Executes pluggable model and operation generators
|
|
75
|
+
* - **Schema Processing**: Provides utilities for working with OAS schemas and references
|
|
76
|
+
* - **File Management**: Handles file creation, imports, exports, and dependencies
|
|
77
|
+
* - **Artifact Registration**: Collects generated definitions and files for rendering
|
|
78
|
+
* - **Type System Integration**: Bridges OAS types with generator-specific type systems
|
|
79
|
+
* - **Settings Management**: Handles skipping logic and client customizations
|
|
80
|
+
*
|
|
81
|
+
* ## Generator Integration
|
|
82
|
+
*
|
|
83
|
+
* The context works with two main types of generators:
|
|
84
|
+
* - **Model Generators**: Transform schema definitions into type definitions
|
|
85
|
+
* - **Operation Generators**: Transform API operations into client functions
|
|
86
|
+
*
|
|
87
|
+
* @example Basic usage in a model generator
|
|
88
|
+
* ```typescript
|
|
89
|
+
* import { ModelBase } from '@skmtc/core';
|
|
90
|
+
*
|
|
91
|
+
* class TypeScriptInterface extends ModelBase {
|
|
92
|
+
* generate(): Definition {
|
|
93
|
+
* const schema = this.context.getSchema(this.refName);
|
|
94
|
+
*
|
|
95
|
+
* return new Definition({
|
|
96
|
+
* context: this.context,
|
|
97
|
+
* identifier: Identifier.createType(this.refName),
|
|
98
|
+
* description: schema.description,
|
|
99
|
+
* value: {
|
|
100
|
+
* generatorKey: this.generatorKey,
|
|
101
|
+
* content: this.generateInterfaceBody(schema)
|
|
102
|
+
* }
|
|
103
|
+
* });
|
|
104
|
+
* }
|
|
105
|
+
* }
|
|
106
|
+
* ```
|
|
107
|
+
*
|
|
108
|
+
* @example Operation generator usage
|
|
109
|
+
* ```typescript
|
|
110
|
+
* class ApiClientGenerator extends OperationBase {
|
|
111
|
+
* generate(): Definition {
|
|
112
|
+
* const operation = this.context.getOperation(this.path, this.method);
|
|
113
|
+
*
|
|
114
|
+
* const functionName = this.context.createOperationName(this.path, this.method);
|
|
115
|
+
*
|
|
116
|
+
* return new Definition({
|
|
117
|
+
* context: this.context,
|
|
118
|
+
* identifier: Identifier.createVariable(functionName),
|
|
119
|
+
* value: {
|
|
120
|
+
* generatorKey: this.generatorKey,
|
|
121
|
+
* content: this.generateClientFunction(operation)
|
|
122
|
+
* }
|
|
123
|
+
* });
|
|
124
|
+
* }
|
|
125
|
+
* }
|
|
126
|
+
* ```
|
|
127
|
+
*
|
|
128
|
+
* @example Schema and type system integration
|
|
129
|
+
* ```typescript
|
|
130
|
+
* class MyGenerator extends ModelBase {
|
|
131
|
+
* generate(): Definition {
|
|
132
|
+
* const schema = this.context.getSchema(this.refName);
|
|
133
|
+
*
|
|
134
|
+
* // Transform schema using type system
|
|
135
|
+
* const typeOutput = this.context.transformSchema(schema, {
|
|
136
|
+
* stringType: 'string',
|
|
137
|
+
* numberType: 'number',
|
|
138
|
+
* arrayType: (items) => `Array<${items}>`
|
|
139
|
+
* });
|
|
140
|
+
*
|
|
141
|
+
* // Register dependencies
|
|
142
|
+
* if (schema.hasReferences()) {
|
|
143
|
+
* this.context.addImportsToFile('./models/types.ts', {
|
|
144
|
+
* './common': ['BaseModel']
|
|
145
|
+
* });
|
|
146
|
+
* }
|
|
147
|
+
*
|
|
148
|
+
* return new Definition({
|
|
149
|
+
* context: this.context,
|
|
150
|
+
* identifier: Identifier.createType(this.refName),
|
|
151
|
+
* value: {
|
|
152
|
+
* generatorKey: this.generatorKey,
|
|
153
|
+
* content: typeOutput.content
|
|
154
|
+
* }
|
|
155
|
+
* });
|
|
156
|
+
* }
|
|
157
|
+
* }
|
|
158
|
+
* ```
|
|
159
|
+
*/
|
|
65
160
|
class GenerateContext {
|
|
66
161
|
constructor({ oasDocument, settings, logger, captureCurrentResult, stackTrail, toGeneratorConfigMap }) {
|
|
67
162
|
_GenerateContext_instances.add(this);
|