@kubb/core 4.5.0 → 4.5.2
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/dist/EventEmitter-3-rxpjGN.cjs +32 -0
- package/dist/EventEmitter-3-rxpjGN.cjs.map +1 -0
- package/dist/EventEmitter-IlDflnd2.js +25 -0
- package/dist/EventEmitter-IlDflnd2.js.map +1 -0
- package/dist/getBarrelFiles-B9LswRVo.d.cts +37 -0
- package/dist/getBarrelFiles-CB-XIF32.d.ts +37 -0
- package/dist/getBarrelFiles-D7p4n7Ug.js +962 -0
- package/dist/getBarrelFiles-D7p4n7Ug.js.map +1 -0
- package/dist/getBarrelFiles-o9ETjpTV.cjs +1017 -0
- package/dist/getBarrelFiles-o9ETjpTV.cjs.map +1 -0
- package/dist/hooks.d.cts +1 -2
- package/dist/hooks.d.ts +2 -3
- package/dist/index.cjs +83 -953
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +45 -62
- package/dist/index.d.ts +46 -63
- package/dist/index.js +51 -921
- package/dist/index.js.map +1 -1
- package/dist/{logger-Bxe022ug.js → logger-BGuor9Uu.js} +5 -26
- package/dist/logger-BGuor9Uu.js.map +1 -0
- package/dist/{logger-BIzTtBYJ.cjs → logger-CLbtdL9m.cjs} +4 -32
- package/dist/logger-CLbtdL9m.cjs.map +1 -0
- package/dist/{logger-BwhJWK-H.d.ts → logger-weazBKCW.d.ts} +1 -1
- package/dist/logger.cjs +2 -1
- package/dist/logger.d.ts +1 -1
- package/dist/logger.js +2 -1
- package/dist/{prompt-D5DZPtWc.cjs → prompt-39QFDCh6.cjs} +1 -1
- package/dist/{prompt-D5DZPtWc.cjs.map → prompt-39QFDCh6.cjs.map} +1 -1
- package/dist/{prompt-xM0onfy8.js → prompt-CIYhgpSM.js} +1 -1
- package/dist/{prompt-xM0onfy8.js.map → prompt-CIYhgpSM.js.map} +1 -1
- package/dist/{transformers-CeNW0G32.js → transformers-BaV4FwQd.js} +1 -1
- package/dist/{transformers-CeNW0G32.js.map → transformers-BaV4FwQd.js.map} +1 -1
- package/dist/{transformers-DWLXDYKb.cjs → transformers-BpnIvSiH.cjs} +1 -1
- package/dist/{transformers-DWLXDYKb.cjs.map → transformers-BpnIvSiH.cjs.map} +1 -1
- package/dist/transformers.cjs +1 -1
- package/dist/transformers.js +1 -1
- package/dist/{types-CyDeSlGF.d.ts → types-CqYAL0CK.d.ts} +29 -38
- package/dist/{types-CVONMhN_.d.cts → types-DqHtLxpp.d.cts} +28 -37
- package/dist/utils.cjs +7 -5
- package/dist/utils.cjs.map +1 -1
- package/dist/utils.d.cts +4 -2
- package/dist/utils.d.ts +4 -2
- package/dist/utils.js +4 -3
- package/dist/utils.js.map +1 -1
- package/package.json +4 -4
- package/src/BarrelManager.ts +1 -1
- package/src/PluginManager.ts +74 -76
- package/src/build.ts +24 -13
- package/src/config.ts +35 -29
- package/src/definePlugin.ts +12 -0
- package/src/index.ts +5 -5
- package/src/types.ts +19 -40
- package/src/utils/AsyncEventEmitter.ts +45 -0
- package/src/utils/TreeNode.ts +1 -1
- package/src/utils/__snapshots__/barrel.json +147 -0
- package/src/{FileManager.ts → utils/getBarrelFiles.ts} +4 -11
- package/src/utils/index.ts +1 -0
- package/dist/URLPath-DbWtfVa1.js +0 -116
- package/dist/URLPath-DbWtfVa1.js.map +0 -1
- package/dist/URLPath-Dir2mxRT.cjs +0 -133
- package/dist/URLPath-Dir2mxRT.cjs.map +0 -1
- package/dist/logger-BIzTtBYJ.cjs.map +0 -1
- package/dist/logger-Bxe022ug.js.map +0 -1
- package/dist/types-DCR_QgGt.d.ts +0 -5
- package/dist/types-DueAg3XP.d.cts +0 -5
- package/src/plugin.ts +0 -80
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { EventEmitter as NodeEventEmitter } from 'node:events'
|
|
2
|
+
|
|
3
|
+
export class AsyncEventEmitter<TEvents extends Record<string, any>> {
|
|
4
|
+
constructor(maxListener = 100) {
|
|
5
|
+
this.#emitter.setMaxListeners(maxListener)
|
|
6
|
+
}
|
|
7
|
+
#emitter = new NodeEventEmitter()
|
|
8
|
+
|
|
9
|
+
async emit<TEventName extends keyof TEvents & string>(eventName: TEventName, ...eventArgs: TEvents[TEventName]): Promise<void> {
|
|
10
|
+
const listeners = this.#emitter.listeners(eventName) as Array<(...args: TEvents[TEventName]) => any>
|
|
11
|
+
|
|
12
|
+
if (listeners.length === 0) {
|
|
13
|
+
return undefined
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
await Promise.all(
|
|
17
|
+
listeners.map(async (listener) => {
|
|
18
|
+
try {
|
|
19
|
+
return await listener(...eventArgs)
|
|
20
|
+
} catch (err) {
|
|
21
|
+
console.error(`Error in async listener for "${eventName}":`, err)
|
|
22
|
+
}
|
|
23
|
+
}),
|
|
24
|
+
)
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
on<TEventName extends keyof TEvents & string>(eventName: TEventName, handler: (...eventArg: TEvents[TEventName]) => void): void {
|
|
28
|
+
this.#emitter.on(eventName, handler as any)
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
onOnce<TEventName extends keyof TEvents & string>(eventName: TEventName, handler: (...eventArgs: TEvents[TEventName]) => void): void {
|
|
32
|
+
const wrapper = (...args: TEvents[TEventName]) => {
|
|
33
|
+
this.off(eventName, wrapper)
|
|
34
|
+
handler(...args)
|
|
35
|
+
}
|
|
36
|
+
this.on(eventName, wrapper)
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
off<TEventName extends keyof TEvents & string>(eventName: TEventName, handler: (...eventArg: TEvents[TEventName]) => void): void {
|
|
40
|
+
this.#emitter.off(eventName, handler as any)
|
|
41
|
+
}
|
|
42
|
+
removeAll(): void {
|
|
43
|
+
this.#emitter.removeAllListeners()
|
|
44
|
+
}
|
|
45
|
+
}
|
package/src/utils/TreeNode.ts
CHANGED
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
[
|
|
2
|
+
{
|
|
3
|
+
"path": "src/test.ts",
|
|
4
|
+
"baseName": "test.ts",
|
|
5
|
+
"sources": [
|
|
6
|
+
{
|
|
7
|
+
"name": "test",
|
|
8
|
+
"value": "export const test = 2;",
|
|
9
|
+
"isExportable": true,
|
|
10
|
+
"isIndexable": true
|
|
11
|
+
}
|
|
12
|
+
],
|
|
13
|
+
"id": "81188fa6e8155e286766a6f3ca74e3eaf1e65e4aca7c0c2788e588b32c591288",
|
|
14
|
+
"name": "test",
|
|
15
|
+
"extname": ".ts",
|
|
16
|
+
"imports": [],
|
|
17
|
+
"exports": [],
|
|
18
|
+
"meta": {}
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
"path": "src/index.ts",
|
|
22
|
+
"baseName": "index.ts",
|
|
23
|
+
"exports": [
|
|
24
|
+
{
|
|
25
|
+
"path": "./sub/hello.ts"
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
"path": "./sub/world.ts"
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
"path": "./test.ts"
|
|
32
|
+
}
|
|
33
|
+
],
|
|
34
|
+
"sources": [
|
|
35
|
+
{
|
|
36
|
+
"name": "test",
|
|
37
|
+
"value": "",
|
|
38
|
+
"isExportable": false,
|
|
39
|
+
"isIndexable": false
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
"name": "hello",
|
|
43
|
+
"value": "",
|
|
44
|
+
"isExportable": false,
|
|
45
|
+
"isIndexable": false
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
"name": "world",
|
|
49
|
+
"value": "",
|
|
50
|
+
"isExportable": false,
|
|
51
|
+
"isIndexable": false
|
|
52
|
+
}
|
|
53
|
+
],
|
|
54
|
+
"id": "a2a171449d862fe29692ce031981047d7ab755ae7f84c707aef80701b3ea0c80",
|
|
55
|
+
"name": "index",
|
|
56
|
+
"extname": ".ts",
|
|
57
|
+
"imports": [],
|
|
58
|
+
"meta": {}
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
"path": "src/sub/hello.ts",
|
|
62
|
+
"baseName": "hello.ts",
|
|
63
|
+
"sources": [
|
|
64
|
+
{
|
|
65
|
+
"name": "hello",
|
|
66
|
+
"value": "export const hello = 2;",
|
|
67
|
+
"isExportable": true,
|
|
68
|
+
"isIndexable": true
|
|
69
|
+
}
|
|
70
|
+
],
|
|
71
|
+
"id": "9e2eb758d04ed285d5eb44154f8ce82fafc1a45f3454ec50e776a6ad2923bdbc",
|
|
72
|
+
"name": "hello",
|
|
73
|
+
"extname": ".ts",
|
|
74
|
+
"imports": [],
|
|
75
|
+
"exports": [],
|
|
76
|
+
"meta": {}
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
"path": "src/sub/world.ts",
|
|
80
|
+
"baseName": "world.ts",
|
|
81
|
+
"sources": [
|
|
82
|
+
{
|
|
83
|
+
"name": "world",
|
|
84
|
+
"value": "export const world = 2;",
|
|
85
|
+
"isExportable": true,
|
|
86
|
+
"isIndexable": true
|
|
87
|
+
}
|
|
88
|
+
],
|
|
89
|
+
"id": "8875e1f9f216417bf0cd05cf4a1a49f430094b0700574b1db6e4e2406feeb850",
|
|
90
|
+
"name": "world",
|
|
91
|
+
"extname": ".ts",
|
|
92
|
+
"imports": [],
|
|
93
|
+
"exports": [],
|
|
94
|
+
"meta": {}
|
|
95
|
+
},
|
|
96
|
+
{
|
|
97
|
+
"path": "src/sub/index.ts",
|
|
98
|
+
"baseName": "index.ts",
|
|
99
|
+
"sources": [
|
|
100
|
+
{
|
|
101
|
+
"name": "hello",
|
|
102
|
+
"value": ""
|
|
103
|
+
},
|
|
104
|
+
{
|
|
105
|
+
"name": "world",
|
|
106
|
+
"value": ""
|
|
107
|
+
},
|
|
108
|
+
{
|
|
109
|
+
"name": "hello",
|
|
110
|
+
"value": "",
|
|
111
|
+
"isExportable": false,
|
|
112
|
+
"isIndexable": false
|
|
113
|
+
},
|
|
114
|
+
{
|
|
115
|
+
"name": "world",
|
|
116
|
+
"value": "",
|
|
117
|
+
"isExportable": false,
|
|
118
|
+
"isIndexable": false
|
|
119
|
+
}
|
|
120
|
+
],
|
|
121
|
+
"exports": [
|
|
122
|
+
{
|
|
123
|
+
"path": "./hello.ts"
|
|
124
|
+
},
|
|
125
|
+
{
|
|
126
|
+
"path": "./world.ts"
|
|
127
|
+
},
|
|
128
|
+
{
|
|
129
|
+
"name": [
|
|
130
|
+
"hello"
|
|
131
|
+
],
|
|
132
|
+
"path": "./sub/hello.ts"
|
|
133
|
+
},
|
|
134
|
+
{
|
|
135
|
+
"name": [
|
|
136
|
+
"world"
|
|
137
|
+
],
|
|
138
|
+
"path": "./sub/world.ts"
|
|
139
|
+
}
|
|
140
|
+
],
|
|
141
|
+
"id": "00d9bb747968e55db50fa82465b2f0678d957e9befeaff84a70e431486a8a132",
|
|
142
|
+
"name": "index",
|
|
143
|
+
"extname": ".ts",
|
|
144
|
+
"imports": [],
|
|
145
|
+
"meta": {}
|
|
146
|
+
}
|
|
147
|
+
]
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { join } from 'node:path'
|
|
2
2
|
import type { KubbFile } from '@kubb/fabric-core/types'
|
|
3
|
-
import { BarrelManager } from '
|
|
4
|
-
import type { Logger } from '
|
|
5
|
-
import type { BarrelType, Plugin } from '
|
|
3
|
+
import { BarrelManager } from '../BarrelManager.ts'
|
|
4
|
+
import type { Logger } from '../logger.ts'
|
|
5
|
+
import type { BarrelType, Plugin } from '../types.ts'
|
|
6
6
|
|
|
7
7
|
export type FileMetaBase = {
|
|
8
8
|
pluginKey?: Plugin['key']
|
|
@@ -29,13 +29,6 @@ type AddIndexesProps = {
|
|
|
29
29
|
meta?: FileMetaBase
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
-
export function getMode(path: string | undefined | null): KubbFile.Mode {
|
|
33
|
-
if (!path) {
|
|
34
|
-
return 'split'
|
|
35
|
-
}
|
|
36
|
-
return extname(path) ? 'single' : 'split'
|
|
37
|
-
}
|
|
38
|
-
|
|
39
32
|
function trimExtName(text: string): string {
|
|
40
33
|
return text.replace(/\.[^/.]+$/, '')
|
|
41
34
|
}
|
package/src/utils/index.ts
CHANGED
package/dist/URLPath-DbWtfVa1.js
DELETED
|
@@ -1,116 +0,0 @@
|
|
|
1
|
-
import { m as camelCase, v as isValidVarName } from "./transformers-CeNW0G32.js";
|
|
2
|
-
|
|
3
|
-
//#region src/utils/uniqueName.ts
|
|
4
|
-
function getUniqueName(originalName, data) {
|
|
5
|
-
let used = data[originalName] || 0;
|
|
6
|
-
if (used) {
|
|
7
|
-
data[originalName] = ++used;
|
|
8
|
-
originalName += used;
|
|
9
|
-
}
|
|
10
|
-
data[originalName] = 1;
|
|
11
|
-
return originalName;
|
|
12
|
-
}
|
|
13
|
-
function setUniqueName(originalName, data) {
|
|
14
|
-
let used = data[originalName] || 0;
|
|
15
|
-
if (used) {
|
|
16
|
-
data[originalName] = ++used;
|
|
17
|
-
return originalName;
|
|
18
|
-
}
|
|
19
|
-
data[originalName] = 1;
|
|
20
|
-
return originalName;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
//#endregion
|
|
24
|
-
//#region src/utils/URLPath.ts
|
|
25
|
-
var URLPath = class {
|
|
26
|
-
path;
|
|
27
|
-
#options;
|
|
28
|
-
constructor(path, options = {}) {
|
|
29
|
-
this.path = path;
|
|
30
|
-
this.#options = options;
|
|
31
|
-
return this;
|
|
32
|
-
}
|
|
33
|
-
/**
|
|
34
|
-
* Convert Swagger path to URLPath(syntax of Express)
|
|
35
|
-
* @example /pet/{petId} => /pet/:petId
|
|
36
|
-
*/
|
|
37
|
-
get URL() {
|
|
38
|
-
return this.toURLPath();
|
|
39
|
-
}
|
|
40
|
-
get isURL() {
|
|
41
|
-
try {
|
|
42
|
-
if (new URL(this.path)?.href) return true;
|
|
43
|
-
} catch (_error) {
|
|
44
|
-
return false;
|
|
45
|
-
}
|
|
46
|
-
return false;
|
|
47
|
-
}
|
|
48
|
-
/**
|
|
49
|
-
* Convert Swagger path to template literals/ template strings(camelcase)
|
|
50
|
-
* @example /pet/{petId} => `/pet/${petId}`
|
|
51
|
-
* @example /account/monetary-accountID => `/account/${monetaryAccountId}`
|
|
52
|
-
* @example /account/userID => `/account/${userId}`
|
|
53
|
-
*/
|
|
54
|
-
get template() {
|
|
55
|
-
return this.toTemplateString();
|
|
56
|
-
}
|
|
57
|
-
get object() {
|
|
58
|
-
return this.toObject();
|
|
59
|
-
}
|
|
60
|
-
get params() {
|
|
61
|
-
return this.getParams();
|
|
62
|
-
}
|
|
63
|
-
toObject({ type = "path", replacer, stringify } = {}) {
|
|
64
|
-
const object = {
|
|
65
|
-
url: type === "path" ? this.toURLPath() : this.toTemplateString({ replacer }),
|
|
66
|
-
params: this.getParams()
|
|
67
|
-
};
|
|
68
|
-
if (stringify) {
|
|
69
|
-
if (type === "template") return JSON.stringify(object).replaceAll("'", "").replaceAll(`"`, "");
|
|
70
|
-
if (object.params) return `{ url: '${object.url}', params: ${JSON.stringify(object.params).replaceAll("'", "").replaceAll(`"`, "")} }`;
|
|
71
|
-
return `{ url: '${object.url}' }`;
|
|
72
|
-
}
|
|
73
|
-
return object;
|
|
74
|
-
}
|
|
75
|
-
/**
|
|
76
|
-
* Convert Swagger path to template literals/ template strings(camelcase)
|
|
77
|
-
* @example /pet/{petId} => `/pet/${petId}`
|
|
78
|
-
* @example /account/monetary-accountID => `/account/${monetaryAccountId}`
|
|
79
|
-
* @example /account/userID => `/account/${userId}`
|
|
80
|
-
*/
|
|
81
|
-
toTemplateString({ prefix = "", replacer } = {}) {
|
|
82
|
-
const found = this.path.match(/{(\w|-)*}/g);
|
|
83
|
-
let newPath = this.path.replaceAll("{", "${");
|
|
84
|
-
if (found) newPath = found.reduce((prev, path) => {
|
|
85
|
-
const pathWithoutBrackets = path.replaceAll("{", "").replaceAll("}", "");
|
|
86
|
-
let param = isValidVarName(pathWithoutBrackets) ? pathWithoutBrackets : camelCase(pathWithoutBrackets);
|
|
87
|
-
if (this.#options.casing === "camelcase") param = camelCase(param);
|
|
88
|
-
return prev.replace(path, `\${${replacer ? replacer(param) : param}}`);
|
|
89
|
-
}, this.path);
|
|
90
|
-
return `\`${prefix}${newPath}\``;
|
|
91
|
-
}
|
|
92
|
-
getParams(replacer) {
|
|
93
|
-
const found = this.path.match(/{(\w|-)*}/g);
|
|
94
|
-
if (!found) return;
|
|
95
|
-
const params = {};
|
|
96
|
-
found.forEach((item) => {
|
|
97
|
-
item = item.replaceAll("{", "").replaceAll("}", "");
|
|
98
|
-
let param = isValidVarName(item) ? item : camelCase(item);
|
|
99
|
-
if (this.#options.casing === "camelcase") param = camelCase(param);
|
|
100
|
-
const key = replacer ? replacer(param) : param;
|
|
101
|
-
params[key] = key;
|
|
102
|
-
}, this.path);
|
|
103
|
-
return params;
|
|
104
|
-
}
|
|
105
|
-
/**
|
|
106
|
-
* Convert Swagger path to URLPath(syntax of Express)
|
|
107
|
-
* @example /pet/{petId} => /pet/:petId
|
|
108
|
-
*/
|
|
109
|
-
toURLPath() {
|
|
110
|
-
return this.path.replaceAll("{", ":").replaceAll("}", "");
|
|
111
|
-
}
|
|
112
|
-
};
|
|
113
|
-
|
|
114
|
-
//#endregion
|
|
115
|
-
export { getUniqueName as n, setUniqueName as r, URLPath as t };
|
|
116
|
-
//# sourceMappingURL=URLPath-DbWtfVa1.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"URLPath-DbWtfVa1.js","names":["#options","params: Record<string, string>"],"sources":["../src/utils/uniqueName.ts","../src/utils/URLPath.ts"],"sourcesContent":["export function getUniqueName(originalName: string, data: Record<string, number>): string {\n let used = data[originalName] || 0\n if (used) {\n data[originalName] = ++used\n originalName += used\n }\n data[originalName] = 1\n return originalName\n}\n\nexport function setUniqueName(originalName: string, data: Record<string, number>): string {\n let used = data[originalName] || 0\n if (used) {\n data[originalName] = ++used\n\n return originalName\n }\n data[originalName] = 1\n return originalName\n}\n","import { camelCase, isValidVarName } from '../transformers'\n\nexport type URLObject = {\n url: string\n params?: Record<string, string>\n}\n\ntype ObjectOptions = {\n type?: 'path' | 'template'\n replacer?: (pathParam: string) => string\n stringify?: boolean\n}\n\ntype Options = {\n casing?: 'camelcase'\n}\n\nexport class URLPath {\n path: string\n #options: Options\n\n constructor(path: string, options: Options = {}) {\n this.path = path\n this.#options = options\n\n return this\n }\n\n /**\n * Convert Swagger path to URLPath(syntax of Express)\n * @example /pet/{petId} => /pet/:petId\n */\n get URL(): string {\n return this.toURLPath()\n }\n get isURL(): boolean {\n try {\n const url = new URL(this.path)\n if (url?.href) {\n return true\n }\n } catch (_error) {\n return false\n }\n return false\n }\n\n /**\n * Convert Swagger path to template literals/ template strings(camelcase)\n * @example /pet/{petId} => `/pet/${petId}`\n * @example /account/monetary-accountID => `/account/${monetaryAccountId}`\n * @example /account/userID => `/account/${userId}`\n */\n get template(): string {\n return this.toTemplateString()\n }\n get object(): URLObject | string {\n return this.toObject()\n }\n get params(): Record<string, string> | undefined {\n return this.getParams()\n }\n\n toObject({ type = 'path', replacer, stringify }: ObjectOptions = {}): URLObject | string {\n const object = {\n url: type === 'path' ? this.toURLPath() : this.toTemplateString({ replacer }),\n params: this.getParams(),\n }\n\n if (stringify) {\n if (type === 'template') {\n return JSON.stringify(object).replaceAll(\"'\", '').replaceAll(`\"`, '')\n }\n\n if (object.params) {\n return `{ url: '${object.url}', params: ${JSON.stringify(object.params).replaceAll(\"'\", '').replaceAll(`\"`, '')} }`\n }\n\n return `{ url: '${object.url}' }`\n }\n\n return object\n }\n\n /**\n * Convert Swagger path to template literals/ template strings(camelcase)\n * @example /pet/{petId} => `/pet/${petId}`\n * @example /account/monetary-accountID => `/account/${monetaryAccountId}`\n * @example /account/userID => `/account/${userId}`\n */\n toTemplateString({ prefix = '', replacer }: { prefix?: string; replacer?: (pathParam: string) => string } = {}): string {\n const regex = /{(\\w|-)*}/g\n const found = this.path.match(regex)\n let newPath = this.path.replaceAll('{', '${')\n\n if (found) {\n newPath = found.reduce((prev, path) => {\n const pathWithoutBrackets = path.replaceAll('{', '').replaceAll('}', '')\n\n let param = isValidVarName(pathWithoutBrackets) ? pathWithoutBrackets : camelCase(pathWithoutBrackets)\n\n if (this.#options.casing === 'camelcase') {\n param = camelCase(param)\n }\n\n return prev.replace(path, `\\${${replacer ? replacer(param) : param}}`)\n }, this.path)\n }\n\n return `\\`${prefix}${newPath}\\``\n }\n\n getParams(replacer?: (pathParam: string) => string): Record<string, string> | undefined {\n const regex = /{(\\w|-)*}/g\n const found = this.path.match(regex)\n\n if (!found) {\n return undefined\n }\n\n const params: Record<string, string> = {}\n found.forEach((item) => {\n item = item.replaceAll('{', '').replaceAll('}', '')\n\n let param = isValidVarName(item) ? item : camelCase(item)\n\n if (this.#options.casing === 'camelcase') {\n param = camelCase(param)\n }\n\n const key = replacer ? replacer(param) : param\n\n params[key] = key\n }, this.path)\n\n return params\n }\n\n /**\n * Convert Swagger path to URLPath(syntax of Express)\n * @example /pet/{petId} => /pet/:petId\n */\n toURLPath(): string {\n return this.path.replaceAll('{', ':').replaceAll('}', '')\n }\n}\n"],"mappings":";;;AAAA,SAAgB,cAAc,cAAsB,MAAsC;CACxF,IAAI,OAAO,KAAK,iBAAiB;AACjC,KAAI,MAAM;AACR,OAAK,gBAAgB,EAAE;AACvB,kBAAgB;;AAElB,MAAK,gBAAgB;AACrB,QAAO;;AAGT,SAAgB,cAAc,cAAsB,MAAsC;CACxF,IAAI,OAAO,KAAK,iBAAiB;AACjC,KAAI,MAAM;AACR,OAAK,gBAAgB,EAAE;AAEvB,SAAO;;AAET,MAAK,gBAAgB;AACrB,QAAO;;;;;ACDT,IAAa,UAAb,MAAqB;CACnB;CACA;CAEA,YAAY,MAAc,UAAmB,EAAE,EAAE;AAC/C,OAAK,OAAO;AACZ,QAAKA,UAAW;AAEhB,SAAO;;;;;;CAOT,IAAI,MAAc;AAChB,SAAO,KAAK,WAAW;;CAEzB,IAAI,QAAiB;AACnB,MAAI;AAEF,OADY,IAAI,IAAI,KAAK,KAAK,EACrB,KACP,QAAO;WAE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EpC,MAAI,CAAC,MACH;EAGF,MAAMC,SAAiC,EAAE;AACzC,QAAM,SAAS,SAAS;AACtB,UAAO,KAAK,WAAW,KAAK,GAAG,CAAC,WAAW,KAAK,GAAG;GAEnD,IAAI,QAAQ,eAAe,KAAK,GAAG,OAAO,UAAU,KAAK;AAEzD,OAAI,MAAKD,QAAS,WAAW,YAC3B,SAAQ,UAAU,MAAM;GAG1B,MAAM,MAAM,WAAW,SAAS,MAAM,GAAG;AAEzC,UAAO,OAAO;KACb,KAAK,KAAK;AAEb,SAAO;;;;;;CAOT,YAAoB;AAClB,SAAO,KAAK,KAAK,WAAW,KAAK,IAAI,CAAC,WAAW,KAAK,GAAG"}
|
|
@@ -1,133 +0,0 @@
|
|
|
1
|
-
const require_transformers = require('./transformers-DWLXDYKb.cjs');
|
|
2
|
-
|
|
3
|
-
//#region src/utils/uniqueName.ts
|
|
4
|
-
function getUniqueName(originalName, data) {
|
|
5
|
-
let used = data[originalName] || 0;
|
|
6
|
-
if (used) {
|
|
7
|
-
data[originalName] = ++used;
|
|
8
|
-
originalName += used;
|
|
9
|
-
}
|
|
10
|
-
data[originalName] = 1;
|
|
11
|
-
return originalName;
|
|
12
|
-
}
|
|
13
|
-
function setUniqueName(originalName, data) {
|
|
14
|
-
let used = data[originalName] || 0;
|
|
15
|
-
if (used) {
|
|
16
|
-
data[originalName] = ++used;
|
|
17
|
-
return originalName;
|
|
18
|
-
}
|
|
19
|
-
data[originalName] = 1;
|
|
20
|
-
return originalName;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
//#endregion
|
|
24
|
-
//#region src/utils/URLPath.ts
|
|
25
|
-
var URLPath = class {
|
|
26
|
-
path;
|
|
27
|
-
#options;
|
|
28
|
-
constructor(path, options = {}) {
|
|
29
|
-
this.path = path;
|
|
30
|
-
this.#options = options;
|
|
31
|
-
return this;
|
|
32
|
-
}
|
|
33
|
-
/**
|
|
34
|
-
* Convert Swagger path to URLPath(syntax of Express)
|
|
35
|
-
* @example /pet/{petId} => /pet/:petId
|
|
36
|
-
*/
|
|
37
|
-
get URL() {
|
|
38
|
-
return this.toURLPath();
|
|
39
|
-
}
|
|
40
|
-
get isURL() {
|
|
41
|
-
try {
|
|
42
|
-
if (new URL(this.path)?.href) return true;
|
|
43
|
-
} catch (_error) {
|
|
44
|
-
return false;
|
|
45
|
-
}
|
|
46
|
-
return false;
|
|
47
|
-
}
|
|
48
|
-
/**
|
|
49
|
-
* Convert Swagger path to template literals/ template strings(camelcase)
|
|
50
|
-
* @example /pet/{petId} => `/pet/${petId}`
|
|
51
|
-
* @example /account/monetary-accountID => `/account/${monetaryAccountId}`
|
|
52
|
-
* @example /account/userID => `/account/${userId}`
|
|
53
|
-
*/
|
|
54
|
-
get template() {
|
|
55
|
-
return this.toTemplateString();
|
|
56
|
-
}
|
|
57
|
-
get object() {
|
|
58
|
-
return this.toObject();
|
|
59
|
-
}
|
|
60
|
-
get params() {
|
|
61
|
-
return this.getParams();
|
|
62
|
-
}
|
|
63
|
-
toObject({ type = "path", replacer, stringify } = {}) {
|
|
64
|
-
const object = {
|
|
65
|
-
url: type === "path" ? this.toURLPath() : this.toTemplateString({ replacer }),
|
|
66
|
-
params: this.getParams()
|
|
67
|
-
};
|
|
68
|
-
if (stringify) {
|
|
69
|
-
if (type === "template") return JSON.stringify(object).replaceAll("'", "").replaceAll(`"`, "");
|
|
70
|
-
if (object.params) return `{ url: '${object.url}', params: ${JSON.stringify(object.params).replaceAll("'", "").replaceAll(`"`, "")} }`;
|
|
71
|
-
return `{ url: '${object.url}' }`;
|
|
72
|
-
}
|
|
73
|
-
return object;
|
|
74
|
-
}
|
|
75
|
-
/**
|
|
76
|
-
* Convert Swagger path to template literals/ template strings(camelcase)
|
|
77
|
-
* @example /pet/{petId} => `/pet/${petId}`
|
|
78
|
-
* @example /account/monetary-accountID => `/account/${monetaryAccountId}`
|
|
79
|
-
* @example /account/userID => `/account/${userId}`
|
|
80
|
-
*/
|
|
81
|
-
toTemplateString({ prefix = "", replacer } = {}) {
|
|
82
|
-
const found = this.path.match(/{(\w|-)*}/g);
|
|
83
|
-
let newPath = this.path.replaceAll("{", "${");
|
|
84
|
-
if (found) newPath = found.reduce((prev, path) => {
|
|
85
|
-
const pathWithoutBrackets = path.replaceAll("{", "").replaceAll("}", "");
|
|
86
|
-
let param = require_transformers.isValidVarName(pathWithoutBrackets) ? pathWithoutBrackets : require_transformers.camelCase(pathWithoutBrackets);
|
|
87
|
-
if (this.#options.casing === "camelcase") param = require_transformers.camelCase(param);
|
|
88
|
-
return prev.replace(path, `\${${replacer ? replacer(param) : param}}`);
|
|
89
|
-
}, this.path);
|
|
90
|
-
return `\`${prefix}${newPath}\``;
|
|
91
|
-
}
|
|
92
|
-
getParams(replacer) {
|
|
93
|
-
const found = this.path.match(/{(\w|-)*}/g);
|
|
94
|
-
if (!found) return;
|
|
95
|
-
const params = {};
|
|
96
|
-
found.forEach((item) => {
|
|
97
|
-
item = item.replaceAll("{", "").replaceAll("}", "");
|
|
98
|
-
let param = require_transformers.isValidVarName(item) ? item : require_transformers.camelCase(item);
|
|
99
|
-
if (this.#options.casing === "camelcase") param = require_transformers.camelCase(param);
|
|
100
|
-
const key = replacer ? replacer(param) : param;
|
|
101
|
-
params[key] = key;
|
|
102
|
-
}, this.path);
|
|
103
|
-
return params;
|
|
104
|
-
}
|
|
105
|
-
/**
|
|
106
|
-
* Convert Swagger path to URLPath(syntax of Express)
|
|
107
|
-
* @example /pet/{petId} => /pet/:petId
|
|
108
|
-
*/
|
|
109
|
-
toURLPath() {
|
|
110
|
-
return this.path.replaceAll("{", ":").replaceAll("}", "");
|
|
111
|
-
}
|
|
112
|
-
};
|
|
113
|
-
|
|
114
|
-
//#endregion
|
|
115
|
-
Object.defineProperty(exports, 'URLPath', {
|
|
116
|
-
enumerable: true,
|
|
117
|
-
get: function () {
|
|
118
|
-
return URLPath;
|
|
119
|
-
}
|
|
120
|
-
});
|
|
121
|
-
Object.defineProperty(exports, 'getUniqueName', {
|
|
122
|
-
enumerable: true,
|
|
123
|
-
get: function () {
|
|
124
|
-
return getUniqueName;
|
|
125
|
-
}
|
|
126
|
-
});
|
|
127
|
-
Object.defineProperty(exports, 'setUniqueName', {
|
|
128
|
-
enumerable: true,
|
|
129
|
-
get: function () {
|
|
130
|
-
return setUniqueName;
|
|
131
|
-
}
|
|
132
|
-
});
|
|
133
|
-
//# sourceMappingURL=URLPath-Dir2mxRT.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"URLPath-Dir2mxRT.cjs","names":["#options","isValidVarName","camelCase","params: Record<string, string>"],"sources":["../src/utils/uniqueName.ts","../src/utils/URLPath.ts"],"sourcesContent":["export function getUniqueName(originalName: string, data: Record<string, number>): string {\n let used = data[originalName] || 0\n if (used) {\n data[originalName] = ++used\n originalName += used\n }\n data[originalName] = 1\n return originalName\n}\n\nexport function setUniqueName(originalName: string, data: Record<string, number>): string {\n let used = data[originalName] || 0\n if (used) {\n data[originalName] = ++used\n\n return originalName\n }\n data[originalName] = 1\n return originalName\n}\n","import { camelCase, isValidVarName } from '../transformers'\n\nexport type URLObject = {\n url: string\n params?: Record<string, string>\n}\n\ntype ObjectOptions = {\n type?: 'path' | 'template'\n replacer?: (pathParam: string) => string\n stringify?: boolean\n}\n\ntype Options = {\n casing?: 'camelcase'\n}\n\nexport class URLPath {\n path: string\n #options: Options\n\n constructor(path: string, options: Options = {}) {\n this.path = path\n this.#options = options\n\n return this\n }\n\n /**\n * Convert Swagger path to URLPath(syntax of Express)\n * @example /pet/{petId} => /pet/:petId\n */\n get URL(): string {\n return this.toURLPath()\n }\n get isURL(): boolean {\n try {\n const url = new URL(this.path)\n if (url?.href) {\n return true\n }\n } catch (_error) {\n return false\n }\n return false\n }\n\n /**\n * Convert Swagger path to template literals/ template strings(camelcase)\n * @example /pet/{petId} => `/pet/${petId}`\n * @example /account/monetary-accountID => `/account/${monetaryAccountId}`\n * @example /account/userID => `/account/${userId}`\n */\n get template(): string {\n return this.toTemplateString()\n }\n get object(): URLObject | string {\n return this.toObject()\n }\n get params(): Record<string, string> | undefined {\n return this.getParams()\n }\n\n toObject({ type = 'path', replacer, stringify }: ObjectOptions = {}): URLObject | string {\n const object = {\n url: type === 'path' ? this.toURLPath() : this.toTemplateString({ replacer }),\n params: this.getParams(),\n }\n\n if (stringify) {\n if (type === 'template') {\n return JSON.stringify(object).replaceAll(\"'\", '').replaceAll(`\"`, '')\n }\n\n if (object.params) {\n return `{ url: '${object.url}', params: ${JSON.stringify(object.params).replaceAll(\"'\", '').replaceAll(`\"`, '')} }`\n }\n\n return `{ url: '${object.url}' }`\n }\n\n return object\n }\n\n /**\n * Convert Swagger path to template literals/ template strings(camelcase)\n * @example /pet/{petId} => `/pet/${petId}`\n * @example /account/monetary-accountID => `/account/${monetaryAccountId}`\n * @example /account/userID => `/account/${userId}`\n */\n toTemplateString({ prefix = '', replacer }: { prefix?: string; replacer?: (pathParam: string) => string } = {}): string {\n const regex = /{(\\w|-)*}/g\n const found = this.path.match(regex)\n let newPath = this.path.replaceAll('{', '${')\n\n if (found) {\n newPath = found.reduce((prev, path) => {\n const pathWithoutBrackets = path.replaceAll('{', '').replaceAll('}', '')\n\n let param = isValidVarName(pathWithoutBrackets) ? pathWithoutBrackets : camelCase(pathWithoutBrackets)\n\n if (this.#options.casing === 'camelcase') {\n param = camelCase(param)\n }\n\n return prev.replace(path, `\\${${replacer ? replacer(param) : param}}`)\n }, this.path)\n }\n\n return `\\`${prefix}${newPath}\\``\n }\n\n getParams(replacer?: (pathParam: string) => string): Record<string, string> | undefined {\n const regex = /{(\\w|-)*}/g\n const found = this.path.match(regex)\n\n if (!found) {\n return undefined\n }\n\n const params: Record<string, string> = {}\n found.forEach((item) => {\n item = item.replaceAll('{', '').replaceAll('}', '')\n\n let param = isValidVarName(item) ? item : camelCase(item)\n\n if (this.#options.casing === 'camelcase') {\n param = camelCase(param)\n }\n\n const key = replacer ? replacer(param) : param\n\n params[key] = key\n }, this.path)\n\n return params\n }\n\n /**\n * Convert Swagger path to URLPath(syntax of Express)\n * @example /pet/{petId} => /pet/:petId\n */\n toURLPath(): string {\n return this.path.replaceAll('{', ':').replaceAll('}', '')\n }\n}\n"],"mappings":";;;AAAA,SAAgB,cAAc,cAAsB,MAAsC;CACxF,IAAI,OAAO,KAAK,iBAAiB;AACjC,KAAI,MAAM;AACR,OAAK,gBAAgB,EAAE;AACvB,kBAAgB;;AAElB,MAAK,gBAAgB;AACrB,QAAO;;AAGT,SAAgB,cAAc,cAAsB,MAAsC;CACxF,IAAI,OAAO,KAAK,iBAAiB;AACjC,KAAI,MAAM;AACR,OAAK,gBAAgB,EAAE;AAEvB,SAAO;;AAET,MAAK,gBAAgB;AACrB,QAAO;;;;;ACDT,IAAa,UAAb,MAAqB;CACnB;CACA;CAEA,YAAY,MAAc,UAAmB,EAAE,EAAE;AAC/C,OAAK,OAAO;AACZ,QAAKA,UAAW;AAEhB,SAAO;;;;;;CAOT,IAAI,MAAc;AAChB,SAAO,KAAK,WAAW;;CAEzB,IAAI,QAAiB;AACnB,MAAI;AAEF,OADY,IAAI,IAAI,KAAK,KAAK,EACrB,KACP,QAAO;WAEF,QAAQ;AACf,UAAO;;AAET,SAAO;;;;;;;;CAST,IAAI,WAAmB;AACrB,SAAO,KAAK,kBAAkB;;CAEhC,IAAI,SAA6B;AAC/B,SAAO,KAAK,UAAU;;CAExB,IAAI,SAA6C;AAC/C,SAAO,KAAK,WAAW;;CAGzB,SAAS,EAAE,OAAO,QAAQ,UAAU,cAA6B,EAAE,EAAsB;EACvF,MAAM,SAAS;GACb,KAAK,SAAS,SAAS,KAAK,WAAW,GAAG,KAAK,iBAAiB,EAAE,UAAU,CAAC;GAC7E,QAAQ,KAAK,WAAW;GACzB;AAED,MAAI,WAAW;AACb,OAAI,SAAS,WACX,QAAO,KAAK,UAAU,OAAO,CAAC,WAAW,KAAK,GAAG,CAAC,WAAW,KAAK,GAAG;AAGvE,OAAI,OAAO,OACT,QAAO,WAAW,OAAO,IAAI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