@skmtc/core 0.0.792 → 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 (71) 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/parseModuleName.d.ts +175 -0
  23. package/esm/helpers/parseModuleName.d.ts.map +1 -1
  24. package/esm/helpers/parseModuleName.js +153 -0
  25. package/esm/helpers/toResolvedArtifactPath.d.ts +145 -0
  26. package/esm/helpers/toResolvedArtifactPath.d.ts.map +1 -1
  27. package/esm/helpers/toResolvedArtifactPath.js +140 -0
  28. package/esm/oas/schema/Schema.d.ts +117 -0
  29. package/esm/oas/schema/Schema.d.ts.map +1 -1
  30. package/esm/typescript/identifiers.d.ts +159 -0
  31. package/esm/typescript/identifiers.d.ts.map +1 -1
  32. package/esm/typescript/identifiers.js +159 -0
  33. package/esm/typescript/withDescription.d.ts +119 -0
  34. package/esm/typescript/withDescription.d.ts.map +1 -1
  35. package/esm/typescript/withDescription.js +119 -0
  36. package/package.json +1 -1
  37. package/script/dsl/GeneratedValueList.d.ts +158 -0
  38. package/script/dsl/GeneratedValueList.d.ts.map +1 -1
  39. package/script/dsl/GeneratedValueList.js +158 -0
  40. package/script/dsl/Stringable.d.ts +76 -0
  41. package/script/dsl/Stringable.d.ts.map +1 -1
  42. package/script/dsl/Stringable.js +75 -0
  43. package/script/helpers/collateExamples.d.ts +150 -0
  44. package/script/helpers/collateExamples.d.ts.map +1 -1
  45. package/script/helpers/collateExamples.js +145 -0
  46. package/script/helpers/formatNumber.d.ts +95 -0
  47. package/script/helpers/formatNumber.d.ts.map +1 -1
  48. package/script/helpers/formatNumber.js +95 -0
  49. package/script/helpers/generationStats.d.ts +287 -1
  50. package/script/helpers/generationStats.d.ts.map +1 -1
  51. package/script/helpers/generationStats.js +266 -0
  52. package/script/helpers/isEmpty.d.ts +62 -0
  53. package/script/helpers/isEmpty.d.ts.map +1 -1
  54. package/script/helpers/isEmpty.js +62 -0
  55. package/script/helpers/isImported.d.ts +80 -0
  56. package/script/helpers/isImported.d.ts.map +1 -1
  57. package/script/helpers/isImported.js +80 -0
  58. package/script/helpers/parseModuleName.d.ts +175 -0
  59. package/script/helpers/parseModuleName.d.ts.map +1 -1
  60. package/script/helpers/parseModuleName.js +153 -0
  61. package/script/helpers/toResolvedArtifactPath.d.ts +145 -0
  62. package/script/helpers/toResolvedArtifactPath.d.ts.map +1 -1
  63. package/script/helpers/toResolvedArtifactPath.js +140 -0
  64. package/script/oas/schema/Schema.d.ts +117 -0
  65. package/script/oas/schema/Schema.d.ts.map +1 -1
  66. package/script/typescript/identifiers.d.ts +159 -0
  67. package/script/typescript/identifiers.d.ts.map +1 -1
  68. package/script/typescript/identifiers.js +159 -0
  69. package/script/typescript/withDescription.d.ts +119 -0
  70. package/script/typescript/withDescription.d.ts.map +1 -1
  71. package/script/typescript/withDescription.js +119 -0
@@ -1,8 +1,153 @@
1
1
  import "../_dnt.polyfills.js";
2
+ /**
3
+ * Arguments for resolving artifact file paths.
4
+ */
2
5
  type ToResolvedArtifactPathArgs = {
6
+ /** The base directory path for resolving relative paths */
3
7
  basePath: string | undefined;
8
+ /** The destination path for the artifact file */
4
9
  destinationPath: string;
5
10
  };
11
+ /**
12
+ * Resolves artifact destination paths relative to a base directory.
13
+ *
14
+ * This utility function combines a base path with a destination path to create
15
+ * the final resolved file path for generated artifacts. It handles special path
16
+ * prefixes (like '@/') and provides sensible defaults when no base path is specified.
17
+ *
18
+ * The function is used throughout the rendering pipeline to determine the final
19
+ * file system locations for generated code artifacts, ensuring consistent path
20
+ * resolution across different operating systems and deployment scenarios.
21
+ *
22
+ * @param args - Path resolution configuration
23
+ * @param args.basePath - Base directory path (defaults to './' if undefined)
24
+ * @param args.destinationPath - Destination path for the artifact
25
+ * @returns The resolved absolute or relative path for the artifact
26
+ *
27
+ * @example Basic path resolution
28
+ * ```typescript
29
+ * import { toResolvedArtifactPath } from '@skmtc/core';
30
+ *
31
+ * // With explicit base path
32
+ * const resolved1 = toResolvedArtifactPath({
33
+ * basePath: './src/generated',
34
+ * destinationPath: 'models/User.ts'
35
+ * });
36
+ * console.log(resolved1); // './src/generated/models/User.ts'
37
+ *
38
+ * // With undefined base path (uses default)
39
+ * const resolved2 = toResolvedArtifactPath({
40
+ * basePath: undefined,
41
+ * destinationPath: 'types.ts'
42
+ * });
43
+ * console.log(resolved2); // './types.ts'
44
+ * ```
45
+ *
46
+ * @example Special path prefix handling
47
+ * ```typescript
48
+ * // '@/' prefix gets stripped and resolved relative to base
49
+ * const resolved = toResolvedArtifactPath({
50
+ * basePath: './output',
51
+ * destinationPath: '@/api/models.ts'
52
+ * });
53
+ * console.log(resolved); // './output/api/models.ts'
54
+ *
55
+ * // Regular paths work normally
56
+ * const normal = toResolvedArtifactPath({
57
+ * basePath: './build',
58
+ * destinationPath: 'components/Button.tsx'
59
+ * });
60
+ * console.log(normal); // './build/components/Button.tsx'
61
+ * ```
62
+ *
63
+ * @example Cross-platform path resolution
64
+ * ```typescript
65
+ * // Works consistently across platforms
66
+ * const windowsPath = toResolvedArtifactPath({
67
+ * basePath: 'C:\\projects\\app\\dist',
68
+ * destinationPath: 'utils/helpers.js'
69
+ * });
70
+ *
71
+ * const unixPath = toResolvedArtifactPath({
72
+ * basePath: '/home/user/projects/app/dist',
73
+ * destinationPath: 'utils/helpers.js'
74
+ * });
75
+ * ```
76
+ *
77
+ * @example Usage in file generation
78
+ * ```typescript
79
+ * class ArtifactWriter {
80
+ * writeArtifact(
81
+ * content: string,
82
+ * destination: string,
83
+ * baseDir?: string
84
+ * ) {
85
+ * const resolvedPath = toResolvedArtifactPath({
86
+ * basePath: baseDir,
87
+ * destinationPath: destination
88
+ * });
89
+ *
90
+ * console.log(`Writing to: ${resolvedPath}`);
91
+ * return Deno.writeTextFile(resolvedPath, content);
92
+ * }
93
+ * }
94
+ *
95
+ * const writer = new ArtifactWriter();
96
+ * await writer.writeArtifact(
97
+ * 'export const greeting = "Hello";',
98
+ * '@/constants.ts',
99
+ * './src/generated'
100
+ * );
101
+ * // Writes to: ./src/generated/constants.ts
102
+ * ```
103
+ *
104
+ * @example Integration with rendering pipeline
105
+ * ```typescript
106
+ * class FileRenderer {
107
+ * renderFiles(
108
+ * files: Map<string, File>,
109
+ * outputDir: string
110
+ * ): Record<string, string> {
111
+ * const artifacts: Record<string, string> = {};
112
+ *
113
+ * for (const [destPath, file] of files) {
114
+ * const resolvedPath = toResolvedArtifactPath({
115
+ * basePath: outputDir,
116
+ * destinationPath: destPath
117
+ * });
118
+ *
119
+ * artifacts[resolvedPath] = file.toString();
120
+ * }
121
+ *
122
+ * return artifacts;
123
+ * }
124
+ * }
125
+ * ```
126
+ *
127
+ * @example Dynamic base path resolution
128
+ * ```typescript
129
+ * function resolveForEnvironment(
130
+ * destination: string,
131
+ * env: 'development' | 'production'
132
+ * ): string {
133
+ * const basePaths = {
134
+ * development: './dev-output',
135
+ * production: './dist'
136
+ * };
137
+ *
138
+ * return toResolvedArtifactPath({
139
+ * basePath: basePaths[env],
140
+ * destinationPath: destination
141
+ * });
142
+ * }
143
+ *
144
+ * const devPath = resolveForEnvironment('api.ts', 'development');
145
+ * const prodPath = resolveForEnvironment('api.ts', 'production');
146
+ *
147
+ * console.log(devPath); // './dev-output/api.ts'
148
+ * console.log(prodPath); // './dist/api.ts'
149
+ * ```
150
+ */
6
151
  export declare const toResolvedArtifactPath: ({ basePath, destinationPath }: ToResolvedArtifactPathArgs) => string;
7
152
  export {};
8
153
  //# sourceMappingURL=toResolvedArtifactPath.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"toResolvedArtifactPath.d.ts","sourceRoot":"","sources":["../../src/helpers/toResolvedArtifactPath.ts"],"names":[],"mappings":"AAAA,OAAO,sBAAsB,CAAC;AAE9B,KAAK,0BAA0B,GAAG;IAChC,QAAQ,EAAE,MAAM,GAAG,SAAS,CAAA;IAC5B,eAAe,EAAE,MAAM,CAAA;CACxB,CAAA;AAED,eAAO,MAAM,sBAAsB,GAAI,+BAGpC,0BAA0B,KAAG,MAE/B,CAAA"}
1
+ {"version":3,"file":"toResolvedArtifactPath.d.ts","sourceRoot":"","sources":["../../src/helpers/toResolvedArtifactPath.ts"],"names":[],"mappings":"AAAA,OAAO,sBAAsB,CAAC;AAG9B;;GAEG;AACH,KAAK,0BAA0B,GAAG;IAChC,2DAA2D;IAC3D,QAAQ,EAAE,MAAM,GAAG,SAAS,CAAA;IAC5B,iDAAiD;IACjD,eAAe,EAAE,MAAM,CAAA;CACxB,CAAA;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2IG;AACH,eAAO,MAAM,sBAAsB,GAAI,+BAGpC,0BAA0B,KAAG,MAE/B,CAAA"}
@@ -3,6 +3,146 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.toResolvedArtifactPath = void 0;
4
4
  require("../_dnt.polyfills.js");
5
5
  const join_js_1 = require("../deps/jsr.io/@std/path/1.1.2/join.js");
6
+ /**
7
+ * Resolves artifact destination paths relative to a base directory.
8
+ *
9
+ * This utility function combines a base path with a destination path to create
10
+ * the final resolved file path for generated artifacts. It handles special path
11
+ * prefixes (like '@/') and provides sensible defaults when no base path is specified.
12
+ *
13
+ * The function is used throughout the rendering pipeline to determine the final
14
+ * file system locations for generated code artifacts, ensuring consistent path
15
+ * resolution across different operating systems and deployment scenarios.
16
+ *
17
+ * @param args - Path resolution configuration
18
+ * @param args.basePath - Base directory path (defaults to './' if undefined)
19
+ * @param args.destinationPath - Destination path for the artifact
20
+ * @returns The resolved absolute or relative path for the artifact
21
+ *
22
+ * @example Basic path resolution
23
+ * ```typescript
24
+ * import { toResolvedArtifactPath } from '@skmtc/core';
25
+ *
26
+ * // With explicit base path
27
+ * const resolved1 = toResolvedArtifactPath({
28
+ * basePath: './src/generated',
29
+ * destinationPath: 'models/User.ts'
30
+ * });
31
+ * console.log(resolved1); // './src/generated/models/User.ts'
32
+ *
33
+ * // With undefined base path (uses default)
34
+ * const resolved2 = toResolvedArtifactPath({
35
+ * basePath: undefined,
36
+ * destinationPath: 'types.ts'
37
+ * });
38
+ * console.log(resolved2); // './types.ts'
39
+ * ```
40
+ *
41
+ * @example Special path prefix handling
42
+ * ```typescript
43
+ * // '@/' prefix gets stripped and resolved relative to base
44
+ * const resolved = toResolvedArtifactPath({
45
+ * basePath: './output',
46
+ * destinationPath: '@/api/models.ts'
47
+ * });
48
+ * console.log(resolved); // './output/api/models.ts'
49
+ *
50
+ * // Regular paths work normally
51
+ * const normal = toResolvedArtifactPath({
52
+ * basePath: './build',
53
+ * destinationPath: 'components/Button.tsx'
54
+ * });
55
+ * console.log(normal); // './build/components/Button.tsx'
56
+ * ```
57
+ *
58
+ * @example Cross-platform path resolution
59
+ * ```typescript
60
+ * // Works consistently across platforms
61
+ * const windowsPath = toResolvedArtifactPath({
62
+ * basePath: 'C:\\projects\\app\\dist',
63
+ * destinationPath: 'utils/helpers.js'
64
+ * });
65
+ *
66
+ * const unixPath = toResolvedArtifactPath({
67
+ * basePath: '/home/user/projects/app/dist',
68
+ * destinationPath: 'utils/helpers.js'
69
+ * });
70
+ * ```
71
+ *
72
+ * @example Usage in file generation
73
+ * ```typescript
74
+ * class ArtifactWriter {
75
+ * writeArtifact(
76
+ * content: string,
77
+ * destination: string,
78
+ * baseDir?: string
79
+ * ) {
80
+ * const resolvedPath = toResolvedArtifactPath({
81
+ * basePath: baseDir,
82
+ * destinationPath: destination
83
+ * });
84
+ *
85
+ * console.log(`Writing to: ${resolvedPath}`);
86
+ * return Deno.writeTextFile(resolvedPath, content);
87
+ * }
88
+ * }
89
+ *
90
+ * const writer = new ArtifactWriter();
91
+ * await writer.writeArtifact(
92
+ * 'export const greeting = "Hello";',
93
+ * '@/constants.ts',
94
+ * './src/generated'
95
+ * );
96
+ * // Writes to: ./src/generated/constants.ts
97
+ * ```
98
+ *
99
+ * @example Integration with rendering pipeline
100
+ * ```typescript
101
+ * class FileRenderer {
102
+ * renderFiles(
103
+ * files: Map<string, File>,
104
+ * outputDir: string
105
+ * ): Record<string, string> {
106
+ * const artifacts: Record<string, string> = {};
107
+ *
108
+ * for (const [destPath, file] of files) {
109
+ * const resolvedPath = toResolvedArtifactPath({
110
+ * basePath: outputDir,
111
+ * destinationPath: destPath
112
+ * });
113
+ *
114
+ * artifacts[resolvedPath] = file.toString();
115
+ * }
116
+ *
117
+ * return artifacts;
118
+ * }
119
+ * }
120
+ * ```
121
+ *
122
+ * @example Dynamic base path resolution
123
+ * ```typescript
124
+ * function resolveForEnvironment(
125
+ * destination: string,
126
+ * env: 'development' | 'production'
127
+ * ): string {
128
+ * const basePaths = {
129
+ * development: './dev-output',
130
+ * production: './dist'
131
+ * };
132
+ *
133
+ * return toResolvedArtifactPath({
134
+ * basePath: basePaths[env],
135
+ * destinationPath: destination
136
+ * });
137
+ * }
138
+ *
139
+ * const devPath = resolveForEnvironment('api.ts', 'development');
140
+ * const prodPath = resolveForEnvironment('api.ts', 'production');
141
+ *
142
+ * console.log(devPath); // './dev-output/api.ts'
143
+ * console.log(prodPath); // './dist/api.ts'
144
+ * ```
145
+ */
6
146
  const toResolvedArtifactPath = ({ basePath, destinationPath }) => {
7
147
  return (0, join_js_1.join)(basePath ?? './', destinationPath.replace(/^@\//, ''));
8
148
  };
@@ -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"}