@skmtc/core 0.0.791 → 0.0.793

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 (113) hide show
  1. package/esm/dsl/GeneratedValueList.d.ts +158 -0
  2. package/esm/dsl/GeneratedValueList.d.ts.map +1 -1
  3. package/esm/dsl/GeneratedValueList.js +158 -0
  4. package/esm/dsl/Stringable.d.ts +76 -0
  5. package/esm/dsl/Stringable.d.ts.map +1 -1
  6. package/esm/dsl/Stringable.js +75 -0
  7. package/esm/helpers/collateExamples.d.ts +150 -0
  8. package/esm/helpers/collateExamples.d.ts.map +1 -1
  9. package/esm/helpers/collateExamples.js +145 -0
  10. package/esm/helpers/formatNumber.d.ts +95 -0
  11. package/esm/helpers/formatNumber.d.ts.map +1 -1
  12. package/esm/helpers/formatNumber.js +95 -0
  13. package/esm/helpers/generationStats.d.ts +287 -1
  14. package/esm/helpers/generationStats.d.ts.map +1 -1
  15. package/esm/helpers/generationStats.js +266 -0
  16. package/esm/helpers/isEmpty.d.ts +62 -0
  17. package/esm/helpers/isEmpty.d.ts.map +1 -1
  18. package/esm/helpers/isEmpty.js +62 -0
  19. package/esm/helpers/isImported.d.ts +80 -0
  20. package/esm/helpers/isImported.d.ts.map +1 -1
  21. package/esm/helpers/isImported.js +80 -0
  22. package/esm/helpers/naming.d.ts +65 -1
  23. package/esm/helpers/naming.d.ts.map +1 -1
  24. package/esm/helpers/naming.js +65 -1
  25. package/esm/helpers/parseModuleName.d.ts +175 -0
  26. package/esm/helpers/parseModuleName.d.ts.map +1 -1
  27. package/esm/helpers/parseModuleName.js +153 -0
  28. package/esm/helpers/toResolvedArtifactPath.d.ts +145 -0
  29. package/esm/helpers/toResolvedArtifactPath.d.ts.map +1 -1
  30. package/esm/helpers/toResolvedArtifactPath.js +140 -0
  31. package/esm/oas/example/Example.d.ts +81 -1
  32. package/esm/oas/example/Example.d.ts.map +1 -1
  33. package/esm/oas/example/Example.js +74 -1
  34. package/esm/oas/header/Header.d.ts +217 -1
  35. package/esm/oas/header/Header.d.ts.map +1 -1
  36. package/esm/oas/header/Header.js +207 -1
  37. package/esm/oas/info/Info.d.ts +72 -0
  38. package/esm/oas/info/Info.d.ts.map +1 -1
  39. package/esm/oas/info/Info.js +62 -0
  40. package/esm/oas/mediaType/MediaType.d.ts +85 -0
  41. package/esm/oas/mediaType/MediaType.d.ts.map +1 -1
  42. package/esm/oas/mediaType/MediaType.js +77 -0
  43. package/esm/oas/pathItem/PathItem.d.ts +92 -0
  44. package/esm/oas/pathItem/PathItem.d.ts.map +1 -1
  45. package/esm/oas/pathItem/PathItem.js +85 -0
  46. package/esm/oas/requestBody/RequestBody.d.ts +264 -0
  47. package/esm/oas/requestBody/RequestBody.d.ts.map +1 -1
  48. package/esm/oas/requestBody/RequestBody.js +257 -0
  49. package/esm/oas/schema/Schema.d.ts +117 -0
  50. package/esm/oas/schema/Schema.d.ts.map +1 -1
  51. package/esm/typescript/identifiers.d.ts +159 -0
  52. package/esm/typescript/identifiers.d.ts.map +1 -1
  53. package/esm/typescript/identifiers.js +159 -0
  54. package/esm/typescript/withDescription.d.ts +119 -0
  55. package/esm/typescript/withDescription.d.ts.map +1 -1
  56. package/esm/typescript/withDescription.js +119 -0
  57. package/package.json +1 -1
  58. package/script/dsl/GeneratedValueList.d.ts +158 -0
  59. package/script/dsl/GeneratedValueList.d.ts.map +1 -1
  60. package/script/dsl/GeneratedValueList.js +158 -0
  61. package/script/dsl/Stringable.d.ts +76 -0
  62. package/script/dsl/Stringable.d.ts.map +1 -1
  63. package/script/dsl/Stringable.js +75 -0
  64. package/script/helpers/collateExamples.d.ts +150 -0
  65. package/script/helpers/collateExamples.d.ts.map +1 -1
  66. package/script/helpers/collateExamples.js +145 -0
  67. package/script/helpers/formatNumber.d.ts +95 -0
  68. package/script/helpers/formatNumber.d.ts.map +1 -1
  69. package/script/helpers/formatNumber.js +95 -0
  70. package/script/helpers/generationStats.d.ts +287 -1
  71. package/script/helpers/generationStats.d.ts.map +1 -1
  72. package/script/helpers/generationStats.js +266 -0
  73. package/script/helpers/isEmpty.d.ts +62 -0
  74. package/script/helpers/isEmpty.d.ts.map +1 -1
  75. package/script/helpers/isEmpty.js +62 -0
  76. package/script/helpers/isImported.d.ts +80 -0
  77. package/script/helpers/isImported.d.ts.map +1 -1
  78. package/script/helpers/isImported.js +80 -0
  79. package/script/helpers/naming.d.ts +65 -1
  80. package/script/helpers/naming.d.ts.map +1 -1
  81. package/script/helpers/naming.js +65 -1
  82. package/script/helpers/parseModuleName.d.ts +175 -0
  83. package/script/helpers/parseModuleName.d.ts.map +1 -1
  84. package/script/helpers/parseModuleName.js +153 -0
  85. package/script/helpers/toResolvedArtifactPath.d.ts +145 -0
  86. package/script/helpers/toResolvedArtifactPath.d.ts.map +1 -1
  87. package/script/helpers/toResolvedArtifactPath.js +140 -0
  88. package/script/oas/example/Example.d.ts +81 -1
  89. package/script/oas/example/Example.d.ts.map +1 -1
  90. package/script/oas/example/Example.js +74 -1
  91. package/script/oas/header/Header.d.ts +217 -1
  92. package/script/oas/header/Header.d.ts.map +1 -1
  93. package/script/oas/header/Header.js +207 -1
  94. package/script/oas/info/Info.d.ts +72 -0
  95. package/script/oas/info/Info.d.ts.map +1 -1
  96. package/script/oas/info/Info.js +62 -0
  97. package/script/oas/mediaType/MediaType.d.ts +85 -0
  98. package/script/oas/mediaType/MediaType.d.ts.map +1 -1
  99. package/script/oas/mediaType/MediaType.js +77 -0
  100. package/script/oas/pathItem/PathItem.d.ts +92 -0
  101. package/script/oas/pathItem/PathItem.d.ts.map +1 -1
  102. package/script/oas/pathItem/PathItem.js +85 -0
  103. package/script/oas/requestBody/RequestBody.d.ts +264 -0
  104. package/script/oas/requestBody/RequestBody.d.ts.map +1 -1
  105. package/script/oas/requestBody/RequestBody.js +257 -0
  106. package/script/oas/schema/Schema.d.ts +117 -0
  107. package/script/oas/schema/Schema.d.ts.map +1 -1
  108. package/script/typescript/identifiers.d.ts +159 -0
  109. package/script/typescript/identifiers.d.ts.map +1 -1
  110. package/script/typescript/identifiers.js +159 -0
  111. package/script/typescript/withDescription.d.ts +119 -0
  112. package/script/typescript/withDescription.d.ts.map +1 -1
  113. package/script/typescript/withDescription.js +119 -0
@@ -2,6 +2,263 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.OasRequestBody = void 0;
4
4
  require("../../_dnt.polyfills.js");
5
+ /**
6
+ * Represents a Request Body Object in the OpenAPI Specification.
7
+ *
8
+ * The `OasRequestBody` class encapsulates the definition of a request body that
9
+ * can be sent with HTTP operations. It supports multiple content types, schema
10
+ * validation, and can be marked as required or optional. Request bodies are
11
+ * commonly used with POST, PUT, PATCH, and sometimes DELETE operations.
12
+ *
13
+ * This class provides comprehensive support for request body definitions with
14
+ * typed content, multiple media type representations, and proper validation.
15
+ *
16
+ * ## Key Features
17
+ *
18
+ * - **Multiple Content Types**: Support for JSON, XML, form data, binary, and more
19
+ * - **Schema Validation**: Typed request bodies through schema definitions
20
+ * - **Required/Optional**: Control whether the request body is mandatory
21
+ * - **Reference Support**: Can reference reusable request body components
22
+ * - **Documentation**: Rich description support for API documentation
23
+ * - **Media Type Flexibility**: Different schemas for different content types
24
+ *
25
+ * @example Basic JSON request body
26
+ * ```typescript
27
+ * import { OasRequestBody, OasMediaType, OasObject, OasString } from '@skmtc/core';
28
+ *
29
+ * const createUserRequest = new OasRequestBody({
30
+ * description: 'User data for creating a new user account',
31
+ * required: true,
32
+ * content: {
33
+ * 'application/json': new OasMediaType({
34
+ * schema: new OasObject({
35
+ * properties: {
36
+ * name: new OasString({
37
+ * description: 'Full name',
38
+ * minLength: 1,
39
+ * maxLength: 100
40
+ * }),
41
+ * email: new OasString({
42
+ * format: 'email',
43
+ * description: 'Email address'
44
+ * }),
45
+ * password: new OasString({
46
+ * minLength: 8,
47
+ * description: 'Account password'
48
+ * })
49
+ * },
50
+ * required: ['name', 'email', 'password']
51
+ * })
52
+ * })
53
+ * }
54
+ * });
55
+ * ```
56
+ *
57
+ * @example Multiple content types
58
+ * ```typescript
59
+ * const multiFormatRequest = new OasRequestBody({
60
+ * description: 'Product data in multiple formats',
61
+ * required: true,
62
+ * content: {
63
+ * 'application/json': new OasMediaType({
64
+ * schema: new OasRef({ $ref: '#/components/schemas/Product' })
65
+ * }),
66
+ * 'application/xml': new OasMediaType({
67
+ * schema: new OasObject({
68
+ * properties: {
69
+ * product: new OasRef({ $ref: '#/components/schemas/Product' })
70
+ * }
71
+ * })
72
+ * }),
73
+ * 'application/x-www-form-urlencoded': new OasMediaType({
74
+ * schema: new OasObject({
75
+ * properties: {
76
+ * name: new OasString(),
77
+ * price: new OasNumber({ format: 'double' }),
78
+ * category_id: new OasInteger()
79
+ * }
80
+ * })
81
+ * })
82
+ * }
83
+ * });
84
+ * ```
85
+ *
86
+ * @example File upload request body
87
+ * ```typescript
88
+ * const fileUploadRequest = new OasRequestBody({
89
+ * description: 'File upload with metadata',
90
+ * required: true,
91
+ * content: {
92
+ * 'multipart/form-data': new OasMediaType({
93
+ * schema: new OasObject({
94
+ * properties: {
95
+ * file: new OasString({
96
+ * format: 'binary',
97
+ * description: 'The file to upload'
98
+ * }),
99
+ * filename: new OasString({
100
+ * description: 'Original filename'
101
+ * }),
102
+ * description: new OasString({
103
+ * description: 'File description',
104
+ * required: false
105
+ * }),
106
+ * tags: new OasArray({
107
+ * items: new OasString(),
108
+ * description: 'File tags'
109
+ * })
110
+ * },
111
+ * required: ['file', 'filename']
112
+ * })
113
+ * }),
114
+ * 'application/octet-stream': new OasMediaType({
115
+ * schema: new OasString({
116
+ * format: 'binary',
117
+ * description: 'Raw binary file content'
118
+ * })
119
+ * })
120
+ * }
121
+ * });
122
+ * ```
123
+ *
124
+ * @example Optional request body for updates
125
+ * ```typescript
126
+ * const updateUserRequest = new OasRequestBody({
127
+ * description: 'Partial user data for updates (all fields optional)',
128
+ * required: false, // Request body itself is optional
129
+ * content: {
130
+ * 'application/json': new OasMediaType({
131
+ * schema: new OasObject({
132
+ * properties: {
133
+ * name: new OasString({ description: 'Updated name' }),
134
+ * email: new OasString({
135
+ * format: 'email',
136
+ * description: 'Updated email'
137
+ * }),
138
+ * bio: new OasString({ description: 'User biography' }),
139
+ * preferences: new OasObject({
140
+ * properties: {
141
+ * notifications: new OasBoolean(),
142
+ * theme: new OasString({ enum: ['light', 'dark'] })
143
+ * }
144
+ * })
145
+ * }
146
+ * // No required fields - all updates are optional
147
+ * })
148
+ * })
149
+ * }
150
+ * });
151
+ * ```
152
+ *
153
+ * @example Complex nested data structures
154
+ * ```typescript
155
+ * const orderRequest = new OasRequestBody({
156
+ * description: 'Complete order with items and shipping',
157
+ * required: true,
158
+ * content: {
159
+ * 'application/json': new OasMediaType({
160
+ * schema: new OasObject({
161
+ * properties: {
162
+ * customer: new OasObject({
163
+ * properties: {
164
+ * id: new OasString(),
165
+ * email: new OasString({ format: 'email' })
166
+ * },
167
+ * required: ['id']
168
+ * }),
169
+ * items: new OasArray({
170
+ * items: new OasObject({
171
+ * properties: {
172
+ * productId: new OasString(),
173
+ * quantity: new OasInteger({ minimum: 1 }),
174
+ * customizations: new OasArray({
175
+ * items: new OasString()
176
+ * })
177
+ * },
178
+ * required: ['productId', 'quantity']
179
+ * }),
180
+ * minItems: 1
181
+ * }),
182
+ * shipping: new OasObject({
183
+ * properties: {
184
+ * address: new OasRef({ $ref: '#/components/schemas/Address' }),
185
+ * method: new OasString({ enum: ['standard', 'express', 'overnight'] }),
186
+ * instructions: new OasString()
187
+ * },
188
+ * required: ['address', 'method']
189
+ * }),
190
+ * couponCode: new OasString({ description: 'Optional discount code' })
191
+ * },
192
+ * required: ['customer', 'items', 'shipping']
193
+ * })
194
+ * })
195
+ * }
196
+ * });
197
+ * ```
198
+ *
199
+ * @example Form data with validation
200
+ * ```typescript
201
+ * const registrationForm = new OasRequestBody({
202
+ * description: 'User registration form data',
203
+ * required: true,
204
+ * content: {
205
+ * 'application/x-www-form-urlencoded': new OasMediaType({
206
+ * schema: new OasObject({
207
+ * properties: {
208
+ * username: new OasString({
209
+ * pattern: '^[a-zA-Z0-9_]{3,20}$',
210
+ * description: 'Alphanumeric username, 3-20 characters'
211
+ * }),
212
+ * email: new OasString({
213
+ * format: 'email',
214
+ * description: 'Valid email address'
215
+ * }),
216
+ * password: new OasString({
217
+ * minLength: 8,
218
+ * description: 'Password, minimum 8 characters'
219
+ * }),
220
+ * confirmPassword: new OasString({
221
+ * description: 'Password confirmation'
222
+ * }),
223
+ * agreeToTerms: new OasBoolean({
224
+ * enum: [true],
225
+ * description: 'Must accept terms of service'
226
+ * })
227
+ * },
228
+ * required: ['username', 'email', 'password', 'confirmPassword', 'agreeToTerms']
229
+ * })
230
+ * })
231
+ * }
232
+ * });
233
+ * ```
234
+ *
235
+ * @example Using in operation definitions
236
+ * ```typescript
237
+ * const createProductOperation = new OasOperation({
238
+ * path: '/products',
239
+ * method: 'post',
240
+ * requestBody: createUserRequest,
241
+ * responses: {
242
+ * '201': new OasResponse({
243
+ * description: 'Product created successfully',
244
+ * content: {
245
+ * 'application/json': new OasMediaType({
246
+ * schema: new OasRef({ $ref: '#/components/schemas/Product' })
247
+ * })
248
+ * }
249
+ * }),
250
+ * '400': new OasResponse({
251
+ * description: 'Invalid request data',
252
+ * content: {
253
+ * 'application/json': new OasMediaType({
254
+ * schema: new OasRef({ $ref: '#/components/schemas/ValidationError' })
255
+ * })
256
+ * }
257
+ * })
258
+ * }
259
+ * });
260
+ * ```
261
+ */
5
262
  class OasRequestBody {
6
263
  constructor(fields) {
7
264
  Object.defineProperty(this, "oasType", {
@@ -7,8 +7,125 @@ import type { OasObject } from '../object/Object.js';
7
7
  import type { OasString } from '../string/String.js';
8
8
  import type { OasUnknown } from '../unknown/Unknown.js';
9
9
  import type { OasUnion } from '../union/Union.js';
10
+ /**
11
+ * Union type representing all possible OpenAPI Schema objects in the SKMTC system.
12
+ *
13
+ * `OasSchema` is the fundamental type for representing any OpenAPI schema definition
14
+ * after it has been parsed and processed by the SKMTC pipeline. It encompasses all
15
+ * JSON Schema types supported by OpenAPI 3.x specifications, providing type-safe
16
+ * access to schema properties and validation constraints.
17
+ *
18
+ * This union type is used throughout the system for schema processing, type generation,
19
+ * and validation. Each variant corresponds to a specific JSON Schema type with its
20
+ * own set of properties and validation rules.
21
+ *
22
+ * ## Supported Schema Types
23
+ *
24
+ * - **{@link OasArray}**: Array schemas with item type definitions and constraints
25
+ * - **{@link OasBoolean}**: Boolean schemas with optional default values
26
+ * - **{@link OasInteger}**: Integer schemas with numeric constraints and formats
27
+ * - **{@link OasNumber}**: Number schemas with numeric constraints and formats
28
+ * - **{@link OasObject}**: Object schemas with properties, required fields, and constraints
29
+ * - **{@link OasString}**: String schemas with length constraints, patterns, and formats
30
+ * - **{@link OasUnknown}**: Schemas with unknown or mixed types
31
+ * - **{@link OasUnion}**: Union schemas representing oneOf/anyOf/allOf constructs
32
+ *
33
+ * @example Type checking and processing
34
+ * ```typescript
35
+ * import type { OasSchema } from '@skmtc/core';
36
+ *
37
+ * function processSchema(schema: OasSchema): string {
38
+ * if (schema.type === 'object') {
39
+ * // TypeScript knows this is OasObject
40
+ * return `Object with ${Object.keys(schema.properties || {}).length} properties`;
41
+ * } else if (schema.type === 'array') {
42
+ * // TypeScript knows this is OasArray
43
+ * return `Array of ${schema.items.type} items`;
44
+ * } else if (schema.type === 'string') {
45
+ * // TypeScript knows this is OasString
46
+ * return `String${schema.format ? ` (${schema.format})` : ''}`;
47
+ * }
48
+ * // Handle other types...
49
+ * return `${schema.type} type`;
50
+ * }
51
+ * ```
52
+ *
53
+ * @example Schema validation and constraints
54
+ * ```typescript
55
+ * function validateSchemaConstraints(schema: OasSchema, value: unknown): boolean {
56
+ * switch (schema.type) {
57
+ * case 'string':
58
+ * if (typeof value !== 'string') return false;
59
+ * if (schema.minLength && value.length < schema.minLength) return false;
60
+ * if (schema.maxLength && value.length > schema.maxLength) return false;
61
+ * if (schema.pattern && !new RegExp(schema.pattern).test(value)) return false;
62
+ * return true;
63
+ *
64
+ * case 'integer':
65
+ * case 'number':
66
+ * if (typeof value !== 'number') return false;
67
+ * if (schema.minimum && value < schema.minimum) return false;
68
+ * if (schema.maximum && value > schema.maximum) return false;
69
+ * return true;
70
+ *
71
+ * case 'array':
72
+ * if (!Array.isArray(value)) return false;
73
+ * if (schema.minItems && value.length < schema.minItems) return false;
74
+ * if (schema.maxItems && value.length > schema.maxItems) return false;
75
+ * return true;
76
+ *
77
+ * default:
78
+ * return true;
79
+ * }
80
+ * }
81
+ * ```
82
+ *
83
+ * @example Code generation based on schema type
84
+ * ```typescript
85
+ * class TypeScriptGenerator {
86
+ * generateType(schema: OasSchema): string {
87
+ * switch (schema.type) {
88
+ * case 'object':
89
+ * return this.generateInterface(schema);
90
+ * case 'array':
91
+ * return `Array<${this.generateType(schema.items)}>`;
92
+ * case 'string':
93
+ * if (schema.enums) {
94
+ * return schema.enums.map(e => `'${e}'`).join(' | ');
95
+ * }
96
+ * return 'string';
97
+ * case 'integer':
98
+ * case 'number':
99
+ * return 'number';
100
+ * case 'boolean':
101
+ * return 'boolean';
102
+ * case 'union':
103
+ * return schema.variants.map(v => this.generateType(v)).join(' | ');
104
+ * default:
105
+ * return 'unknown';
106
+ * }
107
+ * }
108
+ * }
109
+ * ```
110
+ */
10
111
  export type OasSchema = OasArray | OasBoolean | OasInteger | OasNumber | OasObject | OasString | OasUnknown | OasUnion;
112
+ /**
113
+ * Configuration options for JSON Schema conversion operations.
114
+ *
115
+ * These options control how OAS schemas are converted back to JSON Schema format,
116
+ * particularly around reference resolution and schema inlining behavior.
117
+ *
118
+ * @example
119
+ * ```typescript
120
+ * const options: ToJsonSchemaOptions = {
121
+ * resolve: true // Resolve $ref references during conversion
122
+ * };
123
+ *
124
+ * const jsonSchema = schema.toJsonSchema(options);
125
+ * ```
126
+ */
11
127
  export type ToJsonSchemaOptions = {
128
+ /** Whether to resolve $ref references during conversion (default: false) */
12
129
  resolve: boolean;
13
130
  };
14
131
  //# sourceMappingURL=Schema.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"Schema.d.ts","sourceRoot":"","sources":["../../../src/oas/schema/Schema.ts"],"names":[],"mappings":"AAAA,OAAO,yBAAyB,CAAC;AACjC,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAA;AACjD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAA;AACvD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAA;AACvD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAA;AACpD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAA;AACpD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAA;AACpD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAA;AACvD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAA;AAEjD,MAAM,MAAM,SAAS,GACjB,QAAQ,GACR,UAAU,GACV,UAAU,GACV,SAAS,GACT,SAAS,GACT,SAAS,GACT,UAAU,GACV,QAAQ,CAAA;AAEZ,MAAM,MAAM,mBAAmB,GAAG;IAChC,OAAO,EAAE,OAAO,CAAA;CACjB,CAAA"}
1
+ {"version":3,"file":"Schema.d.ts","sourceRoot":"","sources":["../../../src/oas/schema/Schema.ts"],"names":[],"mappings":"AAAA,OAAO,yBAAyB,CAAC;AACjC,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAA;AACjD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAA;AACvD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAA;AACvD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAA;AACpD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAA;AACpD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAA;AACpD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAA;AACvD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAA;AAEjD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoGG;AACH,MAAM,MAAM,SAAS,GACjB,QAAQ,GACR,UAAU,GACV,UAAU,GACV,SAAS,GACT,SAAS,GACT,SAAS,GACT,UAAU,GACV,QAAQ,CAAA;AAEZ;;;;;;;;;;;;;;GAcG;AACH,MAAM,MAAM,mBAAmB,GAAG;IAChC,4EAA4E;IAC5E,OAAO,EAAE,OAAO,CAAA;CACjB,CAAA"}
@@ -1,3 +1,162 @@
1
+ /**
2
+ * Safely formats a key for use in object literals, adding quotes if needed.
3
+ *
4
+ * This function determines whether a property key needs to be quoted in JavaScript/TypeScript
5
+ * object literals based on identifier naming rules. Valid identifiers are left unquoted,
6
+ * while invalid identifiers (containing spaces, special characters, starting with numbers, etc.)
7
+ * are wrapped in single quotes.
8
+ *
9
+ * @param key - The property key to format
10
+ * @returns The key as-is if it's a valid identifier, otherwise wrapped in quotes
11
+ *
12
+ * @example Valid identifiers (no quotes needed)
13
+ * ```typescript
14
+ * import { handleKey } from '@skmtc/core';
15
+ *
16
+ * console.log(handleKey('name')); // 'name'
17
+ * console.log(handleKey('userName')); // 'userName'
18
+ * console.log(handleKey('_private')); // '_private'
19
+ * console.log(handleKey('$special')); // '$special'
20
+ * ```
21
+ *
22
+ * @example Invalid identifiers (quotes added)
23
+ * ```typescript
24
+ * console.log(handleKey('first-name')); // "'first-name'"
25
+ * console.log(handleKey('2nd-place')); // "'2nd-place'"
26
+ * console.log(handleKey('user name')); // "'user name'"
27
+ * console.log(handleKey('api-key')); // "'api-key'"
28
+ * console.log(handleKey('data.nested')); // "'data.nested'"
29
+ * ```
30
+ *
31
+ * @example Usage in object generation
32
+ * ```typescript
33
+ * class ObjectGenerator {
34
+ * generateObjectLiteral(properties: Record<string, string>) {
35
+ * const props = Object.entries(properties)
36
+ * .map(([key, value]) => `${handleKey(key)}: ${value}`)
37
+ * .join(', ');
38
+ *
39
+ * return `{ ${props} }`;
40
+ * }
41
+ * }
42
+ *
43
+ * const generator = new ObjectGenerator();
44
+ * const result = generator.generateObjectLiteral({
45
+ * 'name': 'string',
46
+ * 'first-name': 'string',
47
+ * 'age': 'number'
48
+ * });
49
+ *
50
+ * console.log(result);
51
+ * // { name: string, 'first-name': string, age: number }
52
+ * ```
53
+ *
54
+ * @example TypeScript interface generation
55
+ * ```typescript
56
+ * function generateInterface(name: string, properties: Record<string, string>) {
57
+ * const props = Object.entries(properties)
58
+ * .map(([key, type]) => ` ${handleKey(key)}: ${type};`)
59
+ * .join('\n');
60
+ *
61
+ * return `interface ${name} {\n${props}\n}`;
62
+ * }
63
+ *
64
+ * const userInterface = generateInterface('User', {
65
+ * 'id': 'string',
66
+ * 'first-name': 'string',
67
+ * 'last_name': 'string',
68
+ * '2fa-enabled': 'boolean'
69
+ * });
70
+ *
71
+ * console.log(userInterface);
72
+ * // interface User {
73
+ * // id: string;
74
+ * // 'first-name': string;
75
+ * // last_name: string;
76
+ * // '2fa-enabled': boolean;
77
+ * // }
78
+ * ```
79
+ */
1
80
  export declare const handleKey: (key: string) => string;
81
+ /**
82
+ * Safely formats property access, using dot notation or bracket notation as appropriate.
83
+ *
84
+ * This function generates the appropriate property access syntax for JavaScript/TypeScript
85
+ * code. Valid identifiers use dot notation (`parent.property`), while invalid identifiers
86
+ * use bracket notation (`parent['property']`).
87
+ *
88
+ * @param name - The property name to access
89
+ * @param parent - The parent object expression
90
+ * @returns Properly formatted property access expression
91
+ *
92
+ * @example Valid identifiers (dot notation)
93
+ * ```typescript
94
+ * import { handlePropertyName } from '@skmtc/core';
95
+ *
96
+ * console.log(handlePropertyName('name', 'user')); // 'user.name'
97
+ * console.log(handlePropertyName('firstName', 'user')); // 'user.firstName'
98
+ * console.log(handlePropertyName('_id', 'document')); // 'document._id'
99
+ * console.log(handlePropertyName('$meta', 'data')); // 'data.$meta'
100
+ * ```
101
+ *
102
+ * @example Invalid identifiers (bracket notation)
103
+ * ```typescript
104
+ * console.log(handlePropertyName('first-name', 'user')); // "user['first-name']"
105
+ * console.log(handlePropertyName('2nd-place', 'result')); // "result['2nd-place']"
106
+ * console.log(handlePropertyName('user name', 'form')); // "form['user name']"
107
+ * console.log(handlePropertyName('api-key', 'config')); // "config['api-key']"
108
+ * ```
109
+ *
110
+ * @example Usage in accessor generation
111
+ * ```typescript
112
+ * class PropertyAccessor {
113
+ * generateGetter(objectName: string, propertyPath: string[]) {
114
+ * return propertyPath.reduce((acc, prop) =>
115
+ * handlePropertyName(prop, acc), objectName
116
+ * );
117
+ * }
118
+ * }
119
+ *
120
+ * const accessor = new PropertyAccessor();
121
+ * const path1 = accessor.generateGetter('data', ['user', 'profile', 'firstName']);
122
+ * const path2 = accessor.generateGetter('config', ['api-settings', 'retry-count']);
123
+ *
124
+ * console.log(path1); // 'data.user.profile.firstName'
125
+ * console.log(path2); // "config['api-settings']['retry-count']"
126
+ * ```
127
+ *
128
+ * @example Complex object navigation
129
+ * ```typescript
130
+ * function generateObjectAccess(base: string, properties: string[]) {
131
+ * let result = base;
132
+ *
133
+ * for (const prop of properties) {
134
+ * result = handlePropertyName(prop, result);
135
+ * }
136
+ *
137
+ * return result;
138
+ * }
139
+ *
140
+ * const access1 = generateObjectAccess('response', ['data', 'user-info', 'name']);
141
+ * const access2 = generateObjectAccess('settings', ['ui', 'theme', 'darkMode']);
142
+ *
143
+ * console.log(access1); // "response.data['user-info'].name"
144
+ * console.log(access2); // "settings.ui.theme.darkMode"
145
+ * ```
146
+ *
147
+ * @example Function generation
148
+ * ```typescript
149
+ * function generatePropertyGetter(objName: string, propName: string) {
150
+ * const access = handlePropertyName(propName, objName);
151
+ * return `function get${propName.replace(/[^a-zA-Z0-9]/g, '')}() { return ${access}; }`;
152
+ * }
153
+ *
154
+ * const getter1 = generatePropertyGetter('user', 'firstName');
155
+ * const getter2 = generatePropertyGetter('config', 'api-key');
156
+ *
157
+ * console.log(getter1); // "function getfirstName() { return user.firstName; }"
158
+ * console.log(getter2); // "function getapikey() { return config['api-key']; }"
159
+ * ```
160
+ */
2
161
  export declare const handlePropertyName: (name: string, parent: string) => string;
3
162
  //# sourceMappingURL=identifiers.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"identifiers.d.ts","sourceRoot":"","sources":["../../src/typescript/identifiers.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,SAAS,GAAI,KAAK,MAAM,KAAG,MAEvC,CAAA;AAED,eAAO,MAAM,kBAAkB,GAAI,MAAM,MAAM,EAAE,QAAQ,MAAM,KAAG,MAEjE,CAAA"}
1
+ {"version":3,"file":"identifiers.d.ts","sourceRoot":"","sources":["../../src/typescript/identifiers.ts"],"names":[],"mappings":"AAGA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8EG;AACH,eAAO,MAAM,SAAS,GAAI,KAAK,MAAM,KAAG,MAEvC,CAAA;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+EG;AACH,eAAO,MAAM,kBAAkB,GAAI,MAAM,MAAM,EAAE,QAAQ,MAAM,KAAG,MAEjE,CAAA"}