@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
package/script/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
|
};
|
|
@@ -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/script/types/Brand.js
CHANGED
|
@@ -1,3 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
/**
|
|
4
|
+
* Unique symbol used for branding types.
|
|
5
|
+
*
|
|
6
|
+
* This symbol is used internally by the {@link Brand} type to create
|
|
7
|
+
* unique branded types that are structurally identical but nominally
|
|
8
|
+
* distinct from their base types.
|
|
9
|
+
*
|
|
10
|
+
* @internal
|
|
11
|
+
*/
|
|
3
12
|
require("../_dnt.polyfills.js");
|
|
@@ -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"}
|