@skmtc/core 0.0.793 → 0.0.795
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/StackTrail.d.ts +293 -0
- package/esm/context/StackTrail.d.ts.map +1 -1
- package/esm/context/StackTrail.js +294 -0
- package/esm/helpers/ResultsLog.d.ts +193 -0
- package/esm/helpers/ResultsLog.d.ts.map +1 -1
- package/esm/helpers/ResultsLog.js +213 -0
- package/esm/helpers/tracer.d.ts +124 -0
- package/esm/helpers/tracer.d.ts.map +1 -1
- package/esm/helpers/tracer.js +124 -0
- package/esm/types/Modifiers.d.ts +68 -0
- package/esm/types/Modifiers.d.ts.map +1 -1
- package/esm/types/TypeSystem.d.ts +419 -0
- package/esm/types/TypeSystem.d.ts.map +1 -1
- package/esm/typescript/FunctionParameter.d.ts +313 -0
- package/esm/typescript/FunctionParameter.d.ts.map +1 -1
- package/esm/typescript/FunctionParameter.js +328 -0
- package/esm/typescript/PathParams.d.ts +198 -0
- package/esm/typescript/PathParams.d.ts.map +1 -1
- package/esm/typescript/PathParams.js +190 -0
- package/esm/typescript/ReactRouterPathParams.d.ts +190 -0
- package/esm/typescript/ReactRouterPathParams.d.ts.map +1 -1
- package/esm/typescript/ReactRouterPathParams.js +183 -0
- package/esm/typescript/keyValues.d.ts +125 -0
- package/esm/typescript/keyValues.d.ts.map +1 -1
- package/esm/typescript/keyValues.js +125 -1
- package/esm/typescript/toPathParams.d.ts +179 -0
- package/esm/typescript/toPathParams.d.ts.map +1 -1
- package/esm/typescript/toPathParams.js +179 -0
- package/esm/typescript/toPathTemplate.d.ts +114 -0
- package/esm/typescript/toPathTemplate.d.ts.map +1 -1
- package/esm/typescript/toPathTemplate.js +114 -0
- package/package.json +1 -1
- package/script/context/StackTrail.d.ts +293 -0
- package/script/context/StackTrail.d.ts.map +1 -1
- package/script/context/StackTrail.js +294 -0
- package/script/helpers/ResultsLog.d.ts +193 -0
- package/script/helpers/ResultsLog.d.ts.map +1 -1
- package/script/helpers/ResultsLog.js +213 -0
- package/script/helpers/tracer.d.ts +124 -0
- package/script/helpers/tracer.d.ts.map +1 -1
- package/script/helpers/tracer.js +124 -0
- package/script/types/Modifiers.d.ts +68 -0
- package/script/types/Modifiers.d.ts.map +1 -1
- package/script/types/TypeSystem.d.ts +419 -0
- package/script/types/TypeSystem.d.ts.map +1 -1
- package/script/typescript/FunctionParameter.d.ts +313 -0
- package/script/typescript/FunctionParameter.d.ts.map +1 -1
- package/script/typescript/FunctionParameter.js +328 -0
- package/script/typescript/PathParams.d.ts +198 -0
- package/script/typescript/PathParams.d.ts.map +1 -1
- package/script/typescript/PathParams.js +190 -0
- package/script/typescript/ReactRouterPathParams.d.ts +190 -0
- package/script/typescript/ReactRouterPathParams.d.ts.map +1 -1
- package/script/typescript/ReactRouterPathParams.js +183 -0
- package/script/typescript/keyValues.d.ts +125 -0
- package/script/typescript/keyValues.d.ts.map +1 -1
- package/script/typescript/keyValues.js +125 -1
- package/script/typescript/toPathParams.d.ts +179 -0
- package/script/typescript/toPathParams.d.ts.map +1 -1
- package/script/typescript/toPathParams.js +179 -0
- package/script/typescript/toPathTemplate.d.ts +114 -0
- package/script/typescript/toPathTemplate.d.ts.map +1 -1
- package/script/typescript/toPathTemplate.js +114 -0
|
@@ -1,2 +1,116 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Converts OpenAPI path parameters into JavaScript template literal syntax.
|
|
3
|
+
*
|
|
4
|
+
* This utility function transforms OpenAPI path syntax (using curly braces) into
|
|
5
|
+
* JavaScript template literal syntax (using ${} expressions). It's essential for
|
|
6
|
+
* generating URL builders, API client methods, and other dynamic path construction
|
|
7
|
+
* code where OpenAPI path parameters need to be interpolated at runtime.
|
|
8
|
+
*
|
|
9
|
+
* The function supports both simple parameter substitution and qualified parameter
|
|
10
|
+
* access (when parameters come from an object property).
|
|
11
|
+
*
|
|
12
|
+
* @param path - OpenAPI path string with {parameter} syntax
|
|
13
|
+
* @param queryArg - Optional object name to qualify parameter access
|
|
14
|
+
* @returns Template literal string with ${} parameter syntax
|
|
15
|
+
*
|
|
16
|
+
* @example Basic path parameter conversion
|
|
17
|
+
* ```typescript
|
|
18
|
+
* import { toPathTemplate } from '@skmtc/core';
|
|
19
|
+
*
|
|
20
|
+
* const template = toPathTemplate('/users/{id}/posts/{postId}');
|
|
21
|
+
* console.log(template); // '/users/${id}/posts/${postId}'
|
|
22
|
+
*
|
|
23
|
+
* // Usage in generated code:
|
|
24
|
+
* // const url = `/users/${id}/posts/${postId}`;
|
|
25
|
+
* ```
|
|
26
|
+
*
|
|
27
|
+
* @example With query argument qualification
|
|
28
|
+
* ```typescript
|
|
29
|
+
* const template = toPathTemplate('/users/{id}/posts/{postId}', 'params');
|
|
30
|
+
* console.log(template); // '/users/${params.id}/posts/${params.postId}'
|
|
31
|
+
*
|
|
32
|
+
* // Usage in generated code:
|
|
33
|
+
* // function buildUrl(params: {id: string, postId: string}) {
|
|
34
|
+
* // return `/users/${params.id}/posts/${params.postId}`;
|
|
35
|
+
* // }
|
|
36
|
+
* ```
|
|
37
|
+
*
|
|
38
|
+
* @example API client method generation
|
|
39
|
+
* ```typescript
|
|
40
|
+
* class ApiClientGenerator {
|
|
41
|
+
* generateMethod(path: string, method: string) {
|
|
42
|
+
* const template = toPathTemplate(path, 'args');
|
|
43
|
+
*
|
|
44
|
+
* return `
|
|
45
|
+
* async ${method}(args: PathParams) {
|
|
46
|
+
* const url = \`${template}\`;
|
|
47
|
+
* return this.request('${method.toUpperCase()}', url);
|
|
48
|
+
* }`;
|
|
49
|
+
* }
|
|
50
|
+
* }
|
|
51
|
+
*
|
|
52
|
+
* const generator = new ApiClientGenerator();
|
|
53
|
+
* const method = generator.generateMethod('/users/{userId}/profile', 'getProfile');
|
|
54
|
+
*
|
|
55
|
+
* console.log(method);
|
|
56
|
+
* // async getProfile(args: PathParams) {
|
|
57
|
+
* // const url = `/users/${args.userId}/profile`;
|
|
58
|
+
* // return this.request('GET', url);
|
|
59
|
+
* // }
|
|
60
|
+
* ```
|
|
61
|
+
*
|
|
62
|
+
* @example URL builder generation
|
|
63
|
+
* ```typescript
|
|
64
|
+
* function generateUrlBuilder(endpoints: Array<{name: string, path: string}>) {
|
|
65
|
+
* const builders = endpoints.map(endpoint => {
|
|
66
|
+
* const template = toPathTemplate(endpoint.path);
|
|
67
|
+
*
|
|
68
|
+
* return `${endpoint.name}: (${extractParams(endpoint.path)}) => \`${template}\``;
|
|
69
|
+
* });
|
|
70
|
+
*
|
|
71
|
+
* return `export const urls = {\n ${builders.join(',\n ')}\n};`;
|
|
72
|
+
* }
|
|
73
|
+
*
|
|
74
|
+
* const urlBuilder = generateUrlBuilder([
|
|
75
|
+
* { name: 'user', path: '/users/{id}' },
|
|
76
|
+
* { name: 'userPosts', path: '/users/{id}/posts/{postId}' }
|
|
77
|
+
* ]);
|
|
78
|
+
*
|
|
79
|
+
* // Generates:
|
|
80
|
+
* // export const urls = {
|
|
81
|
+
* // user: (id) => `/users/${id}`,
|
|
82
|
+
* // userPosts: (id, postId) => `/users/${id}/posts/${postId}`
|
|
83
|
+
* // };
|
|
84
|
+
* ```
|
|
85
|
+
*
|
|
86
|
+
* @example React Router integration
|
|
87
|
+
* ```typescript
|
|
88
|
+
* function generateRouteComponent(path: string, componentName: string) {
|
|
89
|
+
* const template = toPathTemplate(path, 'params');
|
|
90
|
+
*
|
|
91
|
+
* return `
|
|
92
|
+
* function ${componentName}() {
|
|
93
|
+
* const params = useParams();
|
|
94
|
+
* const apiUrl = \`/api${template}\`;
|
|
95
|
+
*
|
|
96
|
+
* // Use apiUrl for data fetching
|
|
97
|
+
* return <div>Content for {apiUrl}</div>;
|
|
98
|
+
* }`;
|
|
99
|
+
* }
|
|
100
|
+
* ```
|
|
101
|
+
*
|
|
102
|
+
* @example Complex nested parameters
|
|
103
|
+
* ```typescript
|
|
104
|
+
* const complexPath = '/organizations/{orgId}/projects/{projectId}/issues/{issueId}/comments/{commentId}';
|
|
105
|
+
*
|
|
106
|
+
* const simple = toPathTemplate(complexPath);
|
|
107
|
+
* console.log(simple);
|
|
108
|
+
* // '/organizations/${orgId}/projects/${projectId}/issues/${issueId}/comments/${commentId}'
|
|
109
|
+
*
|
|
110
|
+
* const qualified = toPathTemplate(complexPath, 'pathParams');
|
|
111
|
+
* console.log(qualified);
|
|
112
|
+
* // '/organizations/${pathParams.orgId}/projects/${pathParams.projectId}/issues/${pathParams.issueId}/comments/${pathParams.commentId}'
|
|
113
|
+
* ```
|
|
114
|
+
*/
|
|
1
115
|
export declare const toPathTemplate: (path: string, queryArg?: string) => string;
|
|
2
116
|
//# sourceMappingURL=toPathTemplate.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"toPathTemplate.d.ts","sourceRoot":"","sources":["../../src/typescript/toPathTemplate.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,cAAc,GAAI,MAAM,MAAM,EAAE,WAAW,MAAM,KAAG,MAKhE,CAAA"}
|
|
1
|
+
{"version":3,"file":"toPathTemplate.d.ts","sourceRoot":"","sources":["../../src/typescript/toPathTemplate.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiHG;AACH,eAAO,MAAM,cAAc,GAAI,MAAM,MAAM,EAAE,WAAW,MAAM,KAAG,MAKhE,CAAA"}
|
|
@@ -1,6 +1,120 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.toPathTemplate = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Converts OpenAPI path parameters into JavaScript template literal syntax.
|
|
6
|
+
*
|
|
7
|
+
* This utility function transforms OpenAPI path syntax (using curly braces) into
|
|
8
|
+
* JavaScript template literal syntax (using ${} expressions). It's essential for
|
|
9
|
+
* generating URL builders, API client methods, and other dynamic path construction
|
|
10
|
+
* code where OpenAPI path parameters need to be interpolated at runtime.
|
|
11
|
+
*
|
|
12
|
+
* The function supports both simple parameter substitution and qualified parameter
|
|
13
|
+
* access (when parameters come from an object property).
|
|
14
|
+
*
|
|
15
|
+
* @param path - OpenAPI path string with {parameter} syntax
|
|
16
|
+
* @param queryArg - Optional object name to qualify parameter access
|
|
17
|
+
* @returns Template literal string with ${} parameter syntax
|
|
18
|
+
*
|
|
19
|
+
* @example Basic path parameter conversion
|
|
20
|
+
* ```typescript
|
|
21
|
+
* import { toPathTemplate } from '@skmtc/core';
|
|
22
|
+
*
|
|
23
|
+
* const template = toPathTemplate('/users/{id}/posts/{postId}');
|
|
24
|
+
* console.log(template); // '/users/${id}/posts/${postId}'
|
|
25
|
+
*
|
|
26
|
+
* // Usage in generated code:
|
|
27
|
+
* // const url = `/users/${id}/posts/${postId}`;
|
|
28
|
+
* ```
|
|
29
|
+
*
|
|
30
|
+
* @example With query argument qualification
|
|
31
|
+
* ```typescript
|
|
32
|
+
* const template = toPathTemplate('/users/{id}/posts/{postId}', 'params');
|
|
33
|
+
* console.log(template); // '/users/${params.id}/posts/${params.postId}'
|
|
34
|
+
*
|
|
35
|
+
* // Usage in generated code:
|
|
36
|
+
* // function buildUrl(params: {id: string, postId: string}) {
|
|
37
|
+
* // return `/users/${params.id}/posts/${params.postId}`;
|
|
38
|
+
* // }
|
|
39
|
+
* ```
|
|
40
|
+
*
|
|
41
|
+
* @example API client method generation
|
|
42
|
+
* ```typescript
|
|
43
|
+
* class ApiClientGenerator {
|
|
44
|
+
* generateMethod(path: string, method: string) {
|
|
45
|
+
* const template = toPathTemplate(path, 'args');
|
|
46
|
+
*
|
|
47
|
+
* return `
|
|
48
|
+
* async ${method}(args: PathParams) {
|
|
49
|
+
* const url = \`${template}\`;
|
|
50
|
+
* return this.request('${method.toUpperCase()}', url);
|
|
51
|
+
* }`;
|
|
52
|
+
* }
|
|
53
|
+
* }
|
|
54
|
+
*
|
|
55
|
+
* const generator = new ApiClientGenerator();
|
|
56
|
+
* const method = generator.generateMethod('/users/{userId}/profile', 'getProfile');
|
|
57
|
+
*
|
|
58
|
+
* console.log(method);
|
|
59
|
+
* // async getProfile(args: PathParams) {
|
|
60
|
+
* // const url = `/users/${args.userId}/profile`;
|
|
61
|
+
* // return this.request('GET', url);
|
|
62
|
+
* // }
|
|
63
|
+
* ```
|
|
64
|
+
*
|
|
65
|
+
* @example URL builder generation
|
|
66
|
+
* ```typescript
|
|
67
|
+
* function generateUrlBuilder(endpoints: Array<{name: string, path: string}>) {
|
|
68
|
+
* const builders = endpoints.map(endpoint => {
|
|
69
|
+
* const template = toPathTemplate(endpoint.path);
|
|
70
|
+
*
|
|
71
|
+
* return `${endpoint.name}: (${extractParams(endpoint.path)}) => \`${template}\``;
|
|
72
|
+
* });
|
|
73
|
+
*
|
|
74
|
+
* return `export const urls = {\n ${builders.join(',\n ')}\n};`;
|
|
75
|
+
* }
|
|
76
|
+
*
|
|
77
|
+
* const urlBuilder = generateUrlBuilder([
|
|
78
|
+
* { name: 'user', path: '/users/{id}' },
|
|
79
|
+
* { name: 'userPosts', path: '/users/{id}/posts/{postId}' }
|
|
80
|
+
* ]);
|
|
81
|
+
*
|
|
82
|
+
* // Generates:
|
|
83
|
+
* // export const urls = {
|
|
84
|
+
* // user: (id) => `/users/${id}`,
|
|
85
|
+
* // userPosts: (id, postId) => `/users/${id}/posts/${postId}`
|
|
86
|
+
* // };
|
|
87
|
+
* ```
|
|
88
|
+
*
|
|
89
|
+
* @example React Router integration
|
|
90
|
+
* ```typescript
|
|
91
|
+
* function generateRouteComponent(path: string, componentName: string) {
|
|
92
|
+
* const template = toPathTemplate(path, 'params');
|
|
93
|
+
*
|
|
94
|
+
* return `
|
|
95
|
+
* function ${componentName}() {
|
|
96
|
+
* const params = useParams();
|
|
97
|
+
* const apiUrl = \`/api${template}\`;
|
|
98
|
+
*
|
|
99
|
+
* // Use apiUrl for data fetching
|
|
100
|
+
* return <div>Content for {apiUrl}</div>;
|
|
101
|
+
* }`;
|
|
102
|
+
* }
|
|
103
|
+
* ```
|
|
104
|
+
*
|
|
105
|
+
* @example Complex nested parameters
|
|
106
|
+
* ```typescript
|
|
107
|
+
* const complexPath = '/organizations/{orgId}/projects/{projectId}/issues/{issueId}/comments/{commentId}';
|
|
108
|
+
*
|
|
109
|
+
* const simple = toPathTemplate(complexPath);
|
|
110
|
+
* console.log(simple);
|
|
111
|
+
* // '/organizations/${orgId}/projects/${projectId}/issues/${issueId}/comments/${commentId}'
|
|
112
|
+
*
|
|
113
|
+
* const qualified = toPathTemplate(complexPath, 'pathParams');
|
|
114
|
+
* console.log(qualified);
|
|
115
|
+
* // '/organizations/${pathParams.orgId}/projects/${pathParams.projectId}/issues/${pathParams.issueId}/comments/${pathParams.commentId}'
|
|
116
|
+
* ```
|
|
117
|
+
*/
|
|
4
118
|
const toPathTemplate = (path, queryArg) => {
|
|
5
119
|
return `${path.replaceAll(/{([^}]*)}/g, queryArg ? '${' + queryArg + '.$1}' : '${$1}')}`;
|
|
6
120
|
};
|