@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.
- package/esm/dsl/GeneratedValueList.d.ts +158 -0
- package/esm/dsl/GeneratedValueList.d.ts.map +1 -1
- package/esm/dsl/GeneratedValueList.js +158 -0
- package/esm/dsl/Stringable.d.ts +76 -0
- package/esm/dsl/Stringable.d.ts.map +1 -1
- package/esm/dsl/Stringable.js +75 -0
- package/esm/helpers/collateExamples.d.ts +150 -0
- package/esm/helpers/collateExamples.d.ts.map +1 -1
- package/esm/helpers/collateExamples.js +145 -0
- package/esm/helpers/formatNumber.d.ts +95 -0
- package/esm/helpers/formatNumber.d.ts.map +1 -1
- package/esm/helpers/formatNumber.js +95 -0
- package/esm/helpers/generationStats.d.ts +287 -1
- package/esm/helpers/generationStats.d.ts.map +1 -1
- package/esm/helpers/generationStats.js +266 -0
- package/esm/helpers/isEmpty.d.ts +62 -0
- package/esm/helpers/isEmpty.d.ts.map +1 -1
- package/esm/helpers/isEmpty.js +62 -0
- package/esm/helpers/isImported.d.ts +80 -0
- package/esm/helpers/isImported.d.ts.map +1 -1
- package/esm/helpers/isImported.js +80 -0
- package/esm/helpers/naming.d.ts +65 -1
- package/esm/helpers/naming.d.ts.map +1 -1
- package/esm/helpers/naming.js +65 -1
- package/esm/helpers/parseModuleName.d.ts +175 -0
- package/esm/helpers/parseModuleName.d.ts.map +1 -1
- package/esm/helpers/parseModuleName.js +153 -0
- package/esm/helpers/toResolvedArtifactPath.d.ts +145 -0
- package/esm/helpers/toResolvedArtifactPath.d.ts.map +1 -1
- package/esm/helpers/toResolvedArtifactPath.js +140 -0
- package/esm/oas/example/Example.d.ts +81 -1
- package/esm/oas/example/Example.d.ts.map +1 -1
- package/esm/oas/example/Example.js +74 -1
- package/esm/oas/header/Header.d.ts +217 -1
- package/esm/oas/header/Header.d.ts.map +1 -1
- package/esm/oas/header/Header.js +207 -1
- package/esm/oas/info/Info.d.ts +72 -0
- package/esm/oas/info/Info.d.ts.map +1 -1
- package/esm/oas/info/Info.js +62 -0
- package/esm/oas/mediaType/MediaType.d.ts +85 -0
- package/esm/oas/mediaType/MediaType.d.ts.map +1 -1
- package/esm/oas/mediaType/MediaType.js +77 -0
- package/esm/oas/pathItem/PathItem.d.ts +92 -0
- package/esm/oas/pathItem/PathItem.d.ts.map +1 -1
- package/esm/oas/pathItem/PathItem.js +85 -0
- package/esm/oas/requestBody/RequestBody.d.ts +264 -0
- package/esm/oas/requestBody/RequestBody.d.ts.map +1 -1
- package/esm/oas/requestBody/RequestBody.js +257 -0
- package/esm/oas/schema/Schema.d.ts +117 -0
- package/esm/oas/schema/Schema.d.ts.map +1 -1
- package/esm/typescript/identifiers.d.ts +159 -0
- package/esm/typescript/identifiers.d.ts.map +1 -1
- package/esm/typescript/identifiers.js +159 -0
- package/esm/typescript/withDescription.d.ts +119 -0
- package/esm/typescript/withDescription.d.ts.map +1 -1
- package/esm/typescript/withDescription.js +119 -0
- package/package.json +1 -1
- package/script/dsl/GeneratedValueList.d.ts +158 -0
- package/script/dsl/GeneratedValueList.d.ts.map +1 -1
- package/script/dsl/GeneratedValueList.js +158 -0
- package/script/dsl/Stringable.d.ts +76 -0
- package/script/dsl/Stringable.d.ts.map +1 -1
- package/script/dsl/Stringable.js +75 -0
- package/script/helpers/collateExamples.d.ts +150 -0
- package/script/helpers/collateExamples.d.ts.map +1 -1
- package/script/helpers/collateExamples.js +145 -0
- package/script/helpers/formatNumber.d.ts +95 -0
- package/script/helpers/formatNumber.d.ts.map +1 -1
- package/script/helpers/formatNumber.js +95 -0
- package/script/helpers/generationStats.d.ts +287 -1
- package/script/helpers/generationStats.d.ts.map +1 -1
- package/script/helpers/generationStats.js +266 -0
- package/script/helpers/isEmpty.d.ts +62 -0
- package/script/helpers/isEmpty.d.ts.map +1 -1
- package/script/helpers/isEmpty.js +62 -0
- package/script/helpers/isImported.d.ts +80 -0
- package/script/helpers/isImported.d.ts.map +1 -1
- package/script/helpers/isImported.js +80 -0
- package/script/helpers/naming.d.ts +65 -1
- package/script/helpers/naming.d.ts.map +1 -1
- package/script/helpers/naming.js +65 -1
- package/script/helpers/parseModuleName.d.ts +175 -0
- package/script/helpers/parseModuleName.d.ts.map +1 -1
- package/script/helpers/parseModuleName.js +153 -0
- package/script/helpers/toResolvedArtifactPath.d.ts +145 -0
- package/script/helpers/toResolvedArtifactPath.d.ts.map +1 -1
- package/script/helpers/toResolvedArtifactPath.js +140 -0
- package/script/oas/example/Example.d.ts +81 -1
- package/script/oas/example/Example.d.ts.map +1 -1
- package/script/oas/example/Example.js +74 -1
- package/script/oas/header/Header.d.ts +217 -1
- package/script/oas/header/Header.d.ts.map +1 -1
- package/script/oas/header/Header.js +207 -1
- package/script/oas/info/Info.d.ts +72 -0
- package/script/oas/info/Info.d.ts.map +1 -1
- package/script/oas/info/Info.js +62 -0
- package/script/oas/mediaType/MediaType.d.ts +85 -0
- package/script/oas/mediaType/MediaType.d.ts.map +1 -1
- package/script/oas/mediaType/MediaType.js +77 -0
- package/script/oas/pathItem/PathItem.d.ts +92 -0
- package/script/oas/pathItem/PathItem.d.ts.map +1 -1
- package/script/oas/pathItem/PathItem.js +85 -0
- package/script/oas/requestBody/RequestBody.d.ts +264 -0
- package/script/oas/requestBody/RequestBody.d.ts.map +1 -1
- package/script/oas/requestBody/RequestBody.js +257 -0
- package/script/oas/schema/Schema.d.ts +117 -0
- package/script/oas/schema/Schema.d.ts.map +1 -1
- package/script/typescript/identifiers.d.ts +159 -0
- package/script/typescript/identifiers.d.ts.map +1 -1
- package/script/typescript/identifiers.js +159 -0
- package/script/typescript/withDescription.d.ts +119 -0
- package/script/typescript/withDescription.d.ts.map +1 -1
- package/script/typescript/withDescription.js +119 -0
package/esm/helpers/naming.js
CHANGED
|
@@ -1,22 +1,86 @@
|
|
|
1
1
|
import { camelCase } from 'lodash-es';
|
|
2
2
|
import { match } from 'ts-pattern';
|
|
3
|
+
/**
|
|
4
|
+
* Determines the endpoint type based on HTTP method.
|
|
5
|
+
*
|
|
6
|
+
* @param operation - The OpenAPI operation to analyze
|
|
7
|
+
* @returns 'query' for GET operations, 'mutation' for all others
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```typescript
|
|
11
|
+
* const getOp = new OasOperation({ method: 'get', path: '/users' });
|
|
12
|
+
* console.log(toEndpointType(getOp)); // 'query'
|
|
13
|
+
*
|
|
14
|
+
* const postOp = new OasOperation({ method: 'post', path: '/users' });
|
|
15
|
+
* console.log(toEndpointType(postOp)); // 'mutation'
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
3
18
|
export const toEndpointType = (operation) => {
|
|
4
19
|
return operation.method === 'get' ? 'query' : 'mutation';
|
|
5
20
|
};
|
|
6
|
-
/**
|
|
21
|
+
/**
|
|
22
|
+
* Generates endpoint name in the `camelCase{method}Api{path}` format.
|
|
23
|
+
*
|
|
24
|
+
* @param operation - The OpenAPI operation
|
|
25
|
+
* @returns Camel-cased endpoint name
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* ```typescript
|
|
29
|
+
* const op = new OasOperation({ method: 'post', path: '/users/{id}/profile' });
|
|
30
|
+
* console.log(toEndpointName(op)); // 'createApiUsersIdProfile'
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
7
33
|
export const toEndpointName = (operation) => {
|
|
8
34
|
const { path, method } = operation;
|
|
9
35
|
const verb = toMethodVerb(method);
|
|
10
36
|
return camelCase(`${verb}Api${path}`);
|
|
11
37
|
};
|
|
38
|
+
/**
|
|
39
|
+
* Generates response type name for an operation.
|
|
40
|
+
*
|
|
41
|
+
* @param operation - The OpenAPI operation
|
|
42
|
+
* @returns Response type name with 'Response' suffix
|
|
43
|
+
*
|
|
44
|
+
* @example
|
|
45
|
+
* ```typescript
|
|
46
|
+
* const op = new OasOperation({ method: 'get', path: '/users' });
|
|
47
|
+
* console.log(toResponseName(op)); // 'getApiUsersResponse'
|
|
48
|
+
* ```
|
|
49
|
+
*/
|
|
12
50
|
export const toResponseName = (operation) => {
|
|
13
51
|
const operationName = toEndpointName(operation);
|
|
14
52
|
return `${operationName}Response`;
|
|
15
53
|
};
|
|
54
|
+
/**
|
|
55
|
+
* Generates arguments type name for an operation.
|
|
56
|
+
*
|
|
57
|
+
* @param operation - The OpenAPI operation
|
|
58
|
+
* @returns Arguments type name with 'Args' suffix
|
|
59
|
+
*
|
|
60
|
+
* @example
|
|
61
|
+
* ```typescript
|
|
62
|
+
* const op = new OasOperation({ method: 'put', path: '/users/{id}' });
|
|
63
|
+
* console.log(toArgsName(op)); // 'updateApiUsersIdArgs'
|
|
64
|
+
* ```
|
|
65
|
+
*/
|
|
16
66
|
export const toArgsName = (operation) => {
|
|
17
67
|
const operationName = toEndpointName(operation);
|
|
18
68
|
return `${operationName}Args`;
|
|
19
69
|
};
|
|
70
|
+
/**
|
|
71
|
+
* Converts HTTP method to a descriptive verb.
|
|
72
|
+
*
|
|
73
|
+
* @param method - HTTP method
|
|
74
|
+
* @returns Descriptive verb for the method
|
|
75
|
+
*
|
|
76
|
+
* @example
|
|
77
|
+
* ```typescript
|
|
78
|
+
* console.log(toMethodVerb('post')); // 'Create'
|
|
79
|
+
* console.log(toMethodVerb('put')); // 'Update'
|
|
80
|
+
* console.log(toMethodVerb('get')); // 'get'
|
|
81
|
+
* console.log(toMethodVerb('delete')); // 'delete'
|
|
82
|
+
* ```
|
|
83
|
+
*/
|
|
20
84
|
export const toMethodVerb = (method) => {
|
|
21
85
|
return match(method)
|
|
22
86
|
.with('post', () => 'Create')
|
|
@@ -1,8 +1,183 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Represents the parsed components of a module name.
|
|
3
|
+
*
|
|
4
|
+
* This type breaks down a module name into its constituent parts,
|
|
5
|
+
* supporting various formats used in different package managers
|
|
6
|
+
* and registries (npm, JSR, Deno, etc.).
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```typescript
|
|
10
|
+
* // For 'jsr:@std/path@1.0.0'
|
|
11
|
+
* const parsed: ParsedModuleName = {
|
|
12
|
+
* scheme: 'jsr',
|
|
13
|
+
* scopeName: '@std',
|
|
14
|
+
* packageName: 'path',
|
|
15
|
+
* version: '1.0.0'
|
|
16
|
+
* };
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
1
19
|
export type ParsedModuleName = {
|
|
20
|
+
/** The module scheme (e.g., 'npm', 'jsr', 'https') */
|
|
2
21
|
scheme: string | null;
|
|
22
|
+
/** The scope name for scoped packages (e.g., '@std', '@company') */
|
|
3
23
|
scopeName: string | null;
|
|
24
|
+
/** The package name (the main identifier) */
|
|
4
25
|
packageName: string;
|
|
26
|
+
/** The version specifier (e.g., '1.0.0', '^2.3.4') */
|
|
5
27
|
version: string | null;
|
|
6
28
|
};
|
|
29
|
+
/**
|
|
30
|
+
* Parses a module name string into its component parts.
|
|
31
|
+
*
|
|
32
|
+
* This utility function decomposes module names from various formats into
|
|
33
|
+
* structured components, handling schemes, scopes, versions, and package names.
|
|
34
|
+
* It supports formats used by npm, JSR, Deno, and other package managers.
|
|
35
|
+
*
|
|
36
|
+
* The parser handles complex module name patterns including:
|
|
37
|
+
* - Scheme prefixes (jsr:, npm:, https:)
|
|
38
|
+
* - Scoped packages (@scope/package)
|
|
39
|
+
* - Version specifiers (@version)
|
|
40
|
+
* - Combinations of the above
|
|
41
|
+
*
|
|
42
|
+
* @param moduleName - The module name string to parse
|
|
43
|
+
* @returns Parsed components of the module name
|
|
44
|
+
*
|
|
45
|
+
* @example Basic package names
|
|
46
|
+
* ```typescript
|
|
47
|
+
* import { parseModuleName } from '@skmtc/core';
|
|
48
|
+
*
|
|
49
|
+
* // Simple package name
|
|
50
|
+
* const simple = parseModuleName('lodash');
|
|
51
|
+
* // {
|
|
52
|
+
* // scheme: null,
|
|
53
|
+
* // scopeName: null,
|
|
54
|
+
* // packageName: 'lodash',
|
|
55
|
+
* // version: null
|
|
56
|
+
* // }
|
|
57
|
+
*
|
|
58
|
+
* // Package with version
|
|
59
|
+
* const versioned = parseModuleName('lodash@4.17.21');
|
|
60
|
+
* // {
|
|
61
|
+
* // scheme: null,
|
|
62
|
+
* // scopeName: null,
|
|
63
|
+
* // packageName: 'lodash',
|
|
64
|
+
* // version: '4.17.21'
|
|
65
|
+
* // }
|
|
66
|
+
* ```
|
|
67
|
+
*
|
|
68
|
+
* @example Scoped packages
|
|
69
|
+
* ```typescript
|
|
70
|
+
* // Scoped package
|
|
71
|
+
* const scoped = parseModuleName('@company/utils');
|
|
72
|
+
* // {
|
|
73
|
+
* // scheme: null,
|
|
74
|
+
* // scopeName: '@company',
|
|
75
|
+
* // packageName: 'utils',
|
|
76
|
+
* // version: null
|
|
77
|
+
* // }
|
|
78
|
+
*
|
|
79
|
+
* // Scoped package with version
|
|
80
|
+
* const scopedVersioned = parseModuleName('@company/utils@2.0.0');
|
|
81
|
+
* // {
|
|
82
|
+
* // scheme: null,
|
|
83
|
+
* // scopeName: '@company',
|
|
84
|
+
* // packageName: 'utils',
|
|
85
|
+
* // version: '2.0.0'
|
|
86
|
+
* // }
|
|
87
|
+
* ```
|
|
88
|
+
*
|
|
89
|
+
* @example Scheme-prefixed modules
|
|
90
|
+
* ```typescript
|
|
91
|
+
* // JSR module
|
|
92
|
+
* const jsrModule = parseModuleName('jsr:@std/path@1.0.0');
|
|
93
|
+
* // {
|
|
94
|
+
* // scheme: 'jsr',
|
|
95
|
+
* // scopeName: '@std',
|
|
96
|
+
* // packageName: 'path',
|
|
97
|
+
* // version: '1.0.0'
|
|
98
|
+
* // }
|
|
99
|
+
*
|
|
100
|
+
* // npm module with scheme
|
|
101
|
+
* const npmModule = parseModuleName('npm:lodash@^4.17.0');
|
|
102
|
+
* // {
|
|
103
|
+
* // scheme: 'npm',
|
|
104
|
+
* // scopeName: null,
|
|
105
|
+
* // packageName: 'lodash',
|
|
106
|
+
* // version: '^4.17.0'
|
|
107
|
+
* // }
|
|
108
|
+
*
|
|
109
|
+
* // HTTPS module
|
|
110
|
+
* const httpsModule = parseModuleName('https:example.com/package@v1.2.3');
|
|
111
|
+
* // {
|
|
112
|
+
* // scheme: 'https',
|
|
113
|
+
* // scopeName: null,
|
|
114
|
+
* // packageName: 'example.com/package',
|
|
115
|
+
* // version: 'v1.2.3'
|
|
116
|
+
* // }
|
|
117
|
+
* ```
|
|
118
|
+
*
|
|
119
|
+
* @example Complex parsing scenarios
|
|
120
|
+
* ```typescript
|
|
121
|
+
* // Multiple levels in package name
|
|
122
|
+
* const nested = parseModuleName('npm:@babel/plugin-transform-runtime@^7.0.0');
|
|
123
|
+
* // {
|
|
124
|
+
* // scheme: 'npm',
|
|
125
|
+
* // scopeName: '@babel',
|
|
126
|
+
* // packageName: 'plugin-transform-runtime',
|
|
127
|
+
* // version: '^7.0.0'
|
|
128
|
+
* // }
|
|
129
|
+
*
|
|
130
|
+
* // Version ranges and pre-release versions
|
|
131
|
+
* const prerelease = parseModuleName('jsr:@deno/std@1.0.0-rc.1');
|
|
132
|
+
* // {
|
|
133
|
+
* // scheme: 'jsr',
|
|
134
|
+
* // scopeName: '@deno',
|
|
135
|
+
* // packageName: 'std',
|
|
136
|
+
* // version: '1.0.0-rc.1'
|
|
137
|
+
* // }
|
|
138
|
+
* ```
|
|
139
|
+
*
|
|
140
|
+
* @example Usage in dependency management
|
|
141
|
+
* ```typescript
|
|
142
|
+
* class DependencyManager {
|
|
143
|
+
* processDependency(moduleSpec: string) {
|
|
144
|
+
* const parsed = parseModuleName(moduleSpec);
|
|
145
|
+
*
|
|
146
|
+
* console.log(`Processing ${parsed.packageName}`);
|
|
147
|
+
*
|
|
148
|
+
* if (parsed.scheme) {
|
|
149
|
+
* console.log(`Using ${parsed.scheme} registry`);
|
|
150
|
+
* }
|
|
151
|
+
*
|
|
152
|
+
* if (parsed.scopeName) {
|
|
153
|
+
* console.log(`Scoped package: ${parsed.scopeName}/${parsed.packageName}`);
|
|
154
|
+
* }
|
|
155
|
+
*
|
|
156
|
+
* if (parsed.version) {
|
|
157
|
+
* console.log(`Version constraint: ${parsed.version}`);
|
|
158
|
+
* }
|
|
159
|
+
*
|
|
160
|
+
* return this.resolvePackage(parsed);
|
|
161
|
+
* }
|
|
162
|
+
* }
|
|
163
|
+
* ```
|
|
164
|
+
*
|
|
165
|
+
* @example Building module URLs
|
|
166
|
+
* ```typescript
|
|
167
|
+
* function buildModuleUrl(moduleSpec: string): string {
|
|
168
|
+
* const parsed = parseModuleName(moduleSpec);
|
|
169
|
+
*
|
|
170
|
+
* switch (parsed.scheme) {
|
|
171
|
+
* case 'jsr':
|
|
172
|
+
* return `https://jsr.io/${parsed.scopeName}/${parsed.packageName}`;
|
|
173
|
+
* case 'npm':
|
|
174
|
+
* const scope = parsed.scopeName ? `${parsed.scopeName}/` : '';
|
|
175
|
+
* return `https://npmjs.com/package/${scope}${parsed.packageName}`;
|
|
176
|
+
* default:
|
|
177
|
+
* return `https://deno.land/x/${parsed.packageName}`;
|
|
178
|
+
* }
|
|
179
|
+
* }
|
|
180
|
+
* ```
|
|
181
|
+
*/
|
|
7
182
|
export declare const parseModuleName: (moduleName: string) => ParsedModuleName;
|
|
8
183
|
//# sourceMappingURL=parseModuleName.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parseModuleName.d.ts","sourceRoot":"","sources":["../../src/helpers/parseModuleName.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,gBAAgB,GAAG;IAC7B,MAAM,EAAE,MAAM,GAAG,IAAI,CAAA;IACrB,SAAS,EAAE,MAAM,GAAG,IAAI,CAAA;IACxB,WAAW,EAAE,MAAM,CAAA;IACnB,OAAO,EAAE,MAAM,GAAG,IAAI,CAAA;CACvB,CAAA;AAED,eAAO,MAAM,eAAe,GAAI,YAAY,MAAM,KAAG,gBAgCpD,CAAA"}
|
|
1
|
+
{"version":3,"file":"parseModuleName.d.ts","sourceRoot":"","sources":["../../src/helpers/parseModuleName.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,MAAM,gBAAgB,GAAG;IAC7B,sDAAsD;IACtD,MAAM,EAAE,MAAM,GAAG,IAAI,CAAA;IACrB,oEAAoE;IACpE,SAAS,EAAE,MAAM,GAAG,IAAI,CAAA;IACxB,6CAA6C;IAC7C,WAAW,EAAE,MAAM,CAAA;IACnB,sDAAsD;IACtD,OAAO,EAAE,MAAM,GAAG,IAAI,CAAA;CACvB,CAAA;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwJG;AACH,eAAO,MAAM,eAAe,GAAI,YAAY,MAAM,KAAG,gBAgCpD,CAAA"}
|
|
@@ -1,3 +1,156 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Parses a module name string into its component parts.
|
|
3
|
+
*
|
|
4
|
+
* This utility function decomposes module names from various formats into
|
|
5
|
+
* structured components, handling schemes, scopes, versions, and package names.
|
|
6
|
+
* It supports formats used by npm, JSR, Deno, and other package managers.
|
|
7
|
+
*
|
|
8
|
+
* The parser handles complex module name patterns including:
|
|
9
|
+
* - Scheme prefixes (jsr:, npm:, https:)
|
|
10
|
+
* - Scoped packages (@scope/package)
|
|
11
|
+
* - Version specifiers (@version)
|
|
12
|
+
* - Combinations of the above
|
|
13
|
+
*
|
|
14
|
+
* @param moduleName - The module name string to parse
|
|
15
|
+
* @returns Parsed components of the module name
|
|
16
|
+
*
|
|
17
|
+
* @example Basic package names
|
|
18
|
+
* ```typescript
|
|
19
|
+
* import { parseModuleName } from '@skmtc/core';
|
|
20
|
+
*
|
|
21
|
+
* // Simple package name
|
|
22
|
+
* const simple = parseModuleName('lodash');
|
|
23
|
+
* // {
|
|
24
|
+
* // scheme: null,
|
|
25
|
+
* // scopeName: null,
|
|
26
|
+
* // packageName: 'lodash',
|
|
27
|
+
* // version: null
|
|
28
|
+
* // }
|
|
29
|
+
*
|
|
30
|
+
* // Package with version
|
|
31
|
+
* const versioned = parseModuleName('lodash@4.17.21');
|
|
32
|
+
* // {
|
|
33
|
+
* // scheme: null,
|
|
34
|
+
* // scopeName: null,
|
|
35
|
+
* // packageName: 'lodash',
|
|
36
|
+
* // version: '4.17.21'
|
|
37
|
+
* // }
|
|
38
|
+
* ```
|
|
39
|
+
*
|
|
40
|
+
* @example Scoped packages
|
|
41
|
+
* ```typescript
|
|
42
|
+
* // Scoped package
|
|
43
|
+
* const scoped = parseModuleName('@company/utils');
|
|
44
|
+
* // {
|
|
45
|
+
* // scheme: null,
|
|
46
|
+
* // scopeName: '@company',
|
|
47
|
+
* // packageName: 'utils',
|
|
48
|
+
* // version: null
|
|
49
|
+
* // }
|
|
50
|
+
*
|
|
51
|
+
* // Scoped package with version
|
|
52
|
+
* const scopedVersioned = parseModuleName('@company/utils@2.0.0');
|
|
53
|
+
* // {
|
|
54
|
+
* // scheme: null,
|
|
55
|
+
* // scopeName: '@company',
|
|
56
|
+
* // packageName: 'utils',
|
|
57
|
+
* // version: '2.0.0'
|
|
58
|
+
* // }
|
|
59
|
+
* ```
|
|
60
|
+
*
|
|
61
|
+
* @example Scheme-prefixed modules
|
|
62
|
+
* ```typescript
|
|
63
|
+
* // JSR module
|
|
64
|
+
* const jsrModule = parseModuleName('jsr:@std/path@1.0.0');
|
|
65
|
+
* // {
|
|
66
|
+
* // scheme: 'jsr',
|
|
67
|
+
* // scopeName: '@std',
|
|
68
|
+
* // packageName: 'path',
|
|
69
|
+
* // version: '1.0.0'
|
|
70
|
+
* // }
|
|
71
|
+
*
|
|
72
|
+
* // npm module with scheme
|
|
73
|
+
* const npmModule = parseModuleName('npm:lodash@^4.17.0');
|
|
74
|
+
* // {
|
|
75
|
+
* // scheme: 'npm',
|
|
76
|
+
* // scopeName: null,
|
|
77
|
+
* // packageName: 'lodash',
|
|
78
|
+
* // version: '^4.17.0'
|
|
79
|
+
* // }
|
|
80
|
+
*
|
|
81
|
+
* // HTTPS module
|
|
82
|
+
* const httpsModule = parseModuleName('https:example.com/package@v1.2.3');
|
|
83
|
+
* // {
|
|
84
|
+
* // scheme: 'https',
|
|
85
|
+
* // scopeName: null,
|
|
86
|
+
* // packageName: 'example.com/package',
|
|
87
|
+
* // version: 'v1.2.3'
|
|
88
|
+
* // }
|
|
89
|
+
* ```
|
|
90
|
+
*
|
|
91
|
+
* @example Complex parsing scenarios
|
|
92
|
+
* ```typescript
|
|
93
|
+
* // Multiple levels in package name
|
|
94
|
+
* const nested = parseModuleName('npm:@babel/plugin-transform-runtime@^7.0.0');
|
|
95
|
+
* // {
|
|
96
|
+
* // scheme: 'npm',
|
|
97
|
+
* // scopeName: '@babel',
|
|
98
|
+
* // packageName: 'plugin-transform-runtime',
|
|
99
|
+
* // version: '^7.0.0'
|
|
100
|
+
* // }
|
|
101
|
+
*
|
|
102
|
+
* // Version ranges and pre-release versions
|
|
103
|
+
* const prerelease = parseModuleName('jsr:@deno/std@1.0.0-rc.1');
|
|
104
|
+
* // {
|
|
105
|
+
* // scheme: 'jsr',
|
|
106
|
+
* // scopeName: '@deno',
|
|
107
|
+
* // packageName: 'std',
|
|
108
|
+
* // version: '1.0.0-rc.1'
|
|
109
|
+
* // }
|
|
110
|
+
* ```
|
|
111
|
+
*
|
|
112
|
+
* @example Usage in dependency management
|
|
113
|
+
* ```typescript
|
|
114
|
+
* class DependencyManager {
|
|
115
|
+
* processDependency(moduleSpec: string) {
|
|
116
|
+
* const parsed = parseModuleName(moduleSpec);
|
|
117
|
+
*
|
|
118
|
+
* console.log(`Processing ${parsed.packageName}`);
|
|
119
|
+
*
|
|
120
|
+
* if (parsed.scheme) {
|
|
121
|
+
* console.log(`Using ${parsed.scheme} registry`);
|
|
122
|
+
* }
|
|
123
|
+
*
|
|
124
|
+
* if (parsed.scopeName) {
|
|
125
|
+
* console.log(`Scoped package: ${parsed.scopeName}/${parsed.packageName}`);
|
|
126
|
+
* }
|
|
127
|
+
*
|
|
128
|
+
* if (parsed.version) {
|
|
129
|
+
* console.log(`Version constraint: ${parsed.version}`);
|
|
130
|
+
* }
|
|
131
|
+
*
|
|
132
|
+
* return this.resolvePackage(parsed);
|
|
133
|
+
* }
|
|
134
|
+
* }
|
|
135
|
+
* ```
|
|
136
|
+
*
|
|
137
|
+
* @example Building module URLs
|
|
138
|
+
* ```typescript
|
|
139
|
+
* function buildModuleUrl(moduleSpec: string): string {
|
|
140
|
+
* const parsed = parseModuleName(moduleSpec);
|
|
141
|
+
*
|
|
142
|
+
* switch (parsed.scheme) {
|
|
143
|
+
* case 'jsr':
|
|
144
|
+
* return `https://jsr.io/${parsed.scopeName}/${parsed.packageName}`;
|
|
145
|
+
* case 'npm':
|
|
146
|
+
* const scope = parsed.scopeName ? `${parsed.scopeName}/` : '';
|
|
147
|
+
* return `https://npmjs.com/package/${scope}${parsed.packageName}`;
|
|
148
|
+
* default:
|
|
149
|
+
* return `https://deno.land/x/${parsed.packageName}`;
|
|
150
|
+
* }
|
|
151
|
+
* }
|
|
152
|
+
* ```
|
|
153
|
+
*/
|
|
1
154
|
export const parseModuleName = (moduleName) => {
|
|
2
155
|
const result = {
|
|
3
156
|
scheme: null,
|
|
@@ -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;
|
|
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"}
|