@kubb/core 4.22.3 → 4.24.0

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.
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.cjs","names":["#buffer","dns","#items","#orderItems","#addParams","camelCase","item","path","timeout"],"sources":["../src/utils/buildJSDoc.ts","../src/utils/Cache.ts","../src/utils/checkOnlineStatus.ts","../src/utils/FunctionParams.ts","../src/utils/getNestedAccessor.ts","../src/utils/promise.ts","../src/utils/renderTemplate.ts","../src/utils/resolveModuleSource.ts","../src/utils/serializePluginOptions.ts","../src/utils/timeout.ts"],"sourcesContent":["/**\n * Builds a JSDoc comment block with custom indentation.\n * @param comments - Array of comment strings to include in the JSDoc block\n * @param options - Configuration options for formatting\n * @returns Formatted JSDoc string or fallback string if no comments\n */\nexport function buildJSDoc(\n comments: Array<string>,\n options: {\n /**\n * String to use for indenting each line of the JSDoc comment\n * @default ' * ' (3 spaces + asterisk + space)\n */\n indent?: string\n /**\n * String to append after the closing JSDoc tag\n * @default '\\n ' (newline + 2 spaces)\n */\n suffix?: string\n /**\n * String to return when there are no comments\n * @default ' ' (2 spaces)\n */\n fallback?: string\n } = {},\n): string {\n const { indent = ' * ', suffix = '\\n ', fallback = ' ' } = options\n\n if (comments.length === 0) {\n return fallback\n }\n\n return `/**\\n${comments.map((c) => `${indent}${c}`).join('\\n')}\\n */${suffix}`\n}\n","export class Cache<T> {\n #buffer = new Map<string, T>()\n\n async get(key: string): Promise<T | null> {\n return this.#buffer.get(key) ?? null\n }\n\n async set(key: string, value: T): Promise<void> {\n this.#buffer.set(key, value)\n }\n\n async delete(key: string): Promise<void> {\n this.#buffer.delete(key)\n }\n\n async clear(): Promise<void> {\n this.#buffer.clear()\n }\n\n async keys(): Promise<string[]> {\n return [...this.#buffer.keys()]\n }\n\n async values(): Promise<T[]> {\n return [...this.#buffer.values()]\n }\n\n async flush(): Promise<void> {\n // No-op for base cache\n }\n}\n","import dns from 'node:dns'\n\n/**\n * Check if the system has internet connectivity\n * Uses DNS lookup to well-known stable domains as a lightweight connectivity test\n */\nexport async function isOnline(): Promise<boolean> {\n const testDomains = [\n 'dns.google.com', // Google Public DNS\n 'cloudflare.com', // Cloudflare\n 'one.one.one.one', // Cloudflare DNS\n ]\n\n for (const domain of testDomains) {\n try {\n await dns.promises.resolve(domain)\n return true\n } catch {\n // Try next domain\n }\n }\n\n return false\n}\n\n/**\n * Execute a function only if online, otherwise silently skip\n */\nexport async function executeIfOnline<T>(fn: () => Promise<T>): Promise<T | null> {\n const online = await isOnline()\n if (!online) {\n return null\n }\n\n try {\n return await fn()\n } catch {\n return null\n }\n}\n","import { orderBy } from 'natural-orderby'\n\nimport { camelCase } from '../transformers/casing.ts'\n\ntype FunctionParamsASTWithoutType = {\n name?: string\n type?: string\n /**\n * @default true\n */\n required?: boolean\n /**\n * @default true\n */\n enabled?: boolean\n default?: string\n}\n\ntype FunctionParamsASTWithType = {\n name?: never\n type: string\n /**\n * @default true\n */\n required?: boolean\n /**\n * @default true\n */\n enabled?: boolean\n default?: string\n}\n/**\n * @deprecated\n */\nexport type FunctionParamsAST = FunctionParamsASTWithoutType | FunctionParamsASTWithType\n\n/**\n * @deprecated\n */\nexport class FunctionParams {\n #items: Array<FunctionParamsAST | FunctionParamsAST[]> = []\n constructor() {\n return this\n }\n\n get items(): FunctionParamsAST[] {\n return this.#items.flat()\n }\n\n add(item: FunctionParamsAST | Array<FunctionParamsAST | FunctionParamsAST[] | undefined> | undefined): FunctionParams {\n if (!item) {\n return this\n }\n\n if (Array.isArray(item)) {\n item.filter(Boolean).forEach((it) => {\n this.#items.push(it)\n })\n return this\n }\n this.#items.push(item)\n\n return this\n }\n static #orderItems(items: Array<FunctionParamsAST | FunctionParamsAST[]>) {\n return orderBy(\n items.filter(Boolean),\n [\n (v) => {\n if (Array.isArray(v)) {\n return undefined\n }\n return !v.default\n },\n (v) => {\n if (Array.isArray(v)) {\n return undefined\n }\n return v.required ?? true\n },\n ],\n ['desc', 'desc'],\n )\n }\n\n static #addParams(acc: string[], item: FunctionParamsAST) {\n const { enabled = true, name, type, required = true, ...rest } = item\n\n if (!enabled) {\n return acc\n }\n\n if (!name) {\n // when name is not se we uses TypeScript generics\n acc.push(`${type}${rest.default ? ` = ${rest.default}` : ''}`)\n\n return acc\n }\n // TODO check whey we still need the camelcase here\n const parameterName = name.startsWith('{') ? name : camelCase(name)\n\n if (type) {\n if (required) {\n acc.push(`${parameterName}: ${type}${rest.default ? ` = ${rest.default}` : ''}`)\n } else {\n acc.push(`${parameterName}?: ${type}`)\n }\n } else {\n acc.push(`${parameterName}`)\n }\n\n return acc\n }\n\n static toObject(items: FunctionParamsAST[]): FunctionParamsAST {\n let type: string[] = []\n let name: string[] = []\n\n const enabled = items.every((item) => item.enabled) ? items.at(0)?.enabled : true\n const required = items.every((item) => item.required) ?? true\n\n items.forEach((item) => {\n name = FunctionParams.#addParams(name, { ...item, type: undefined })\n if (items.some((item) => item.type)) {\n type = FunctionParams.#addParams(type, item)\n }\n })\n\n return {\n name: `{ ${name.join(', ')} }`,\n type: type.length ? `{ ${type.join('; ')} }` : undefined,\n enabled,\n required,\n }\n }\n\n toObject(): FunctionParamsAST {\n const items = FunctionParams.#orderItems(this.#items).flat()\n\n return FunctionParams.toObject(items)\n }\n\n static toString(items: (FunctionParamsAST | FunctionParamsAST[])[]): string {\n const sortedData = FunctionParams.#orderItems(items)\n\n return sortedData\n .reduce((acc, item) => {\n if (Array.isArray(item)) {\n if (item.length <= 0) {\n return acc\n }\n const subItems = FunctionParams.#orderItems(item) as FunctionParamsAST[]\n const objectItem = FunctionParams.toObject(subItems)\n\n return FunctionParams.#addParams(acc, objectItem)\n }\n\n return FunctionParams.#addParams(acc, item)\n }, [] as string[])\n .join(', ')\n }\n\n toString(): string {\n const items = FunctionParams.#orderItems(this.#items)\n\n return FunctionParams.toString(items)\n }\n}\n","/**\n * Converts a param path (string with dot notation or array of strings) to a JavaScript accessor expression.\n * @param param - The param path, e.g., 'pagination.next.id' or ['pagination', 'next', 'id']\n * @param accessor - The base accessor, e.g., 'lastPage' or 'firstPage'\n * @returns A JavaScript accessor expression, e.g., \"lastPage?.['pagination']?.['next']?.['id']\", or undefined if param is empty\n *\n * @example\n * ```ts\n * getNestedAccessor('pagination.next.id', 'lastPage')\n * // returns: \"lastPage?.['pagination']?.['next']?.['id']\"\n *\n * getNestedAccessor(['pagination', 'next', 'id'], 'lastPage')\n * // returns: \"lastPage?.['pagination']?.['next']?.['id']\"\n *\n * getNestedAccessor('', 'lastPage')\n * // returns: undefined\n * ```\n */\nexport function getNestedAccessor(param: string | string[], accessor: string): string | undefined {\n const parts = Array.isArray(param) ? param : param.split('.')\n if (parts.length === 0 || (parts.length === 1 && parts[0] === '')) {\n return undefined\n }\n return parts.reduce((acc, part) => `${acc}?.['${part}']`, accessor)\n}\n","import type { PossiblePromise } from './types.ts'\n\nexport function isPromise<T>(result: PossiblePromise<T>): result is Promise<T> {\n return !!result && typeof (result as Promise<unknown>)?.then === 'function'\n}\n\nexport function isPromiseFulfilledResult<T = unknown>(result: PromiseSettledResult<unknown>): result is PromiseFulfilledResult<T> {\n return result.status === 'fulfilled'\n}\n\nexport function isPromiseRejectedResult<T>(result: PromiseSettledResult<unknown>): result is Omit<PromiseRejectedResult, 'reason'> & { reason: T } {\n return result.status === 'rejected'\n}\n","export function renderTemplate<TData extends Record<string, unknown> = Record<string, unknown>>(template: string, data: TData | undefined = undefined): string {\n if (!data || !Object.keys(data).length) {\n return template.replace(/{{(.*?)}}/g, '')\n }\n\n const matches = template.match(/{{(.*?)}}/g)\n\n return (\n matches?.reduce((prev, curr) => {\n const index = curr.split(/{{|}}/).filter(Boolean)[0]?.trim()\n if (index === undefined) {\n return prev\n }\n const value = data[index]\n\n if (value === undefined) {\n return prev\n }\n\n return prev\n .replace(curr, () => {\n if (typeof value === 'boolean') {\n return `${value.toString()}` || 'false'\n }\n\n return (value as string) || ''\n })\n .trim()\n }, template) || ''\n )\n}\n","import { readFileSync } from 'node:fs'\nimport path from 'node:path'\nimport { fileURLToPath } from 'node:url'\nimport createJiti from 'jiti'\n\nexport function resolveModuleSource(pkgName: string) {\n const parentURL = import.meta.url\n const jiti = createJiti(parentURL)\n\n const resolved = jiti.esmResolve(pkgName, parentURL)\n const filePath = resolved.startsWith('file:') ? fileURLToPath(resolved) : resolved\n const source = readFileSync(filePath, { encoding: 'utf-8' })\n const ext = path.extname(filePath)\n return { path: filePath, source, ext } as const\n}\n","/**\n * Serialize plugin options for safe JSON transport.\n * Strips functions, symbols, and undefined values recursively.\n */\nexport function serializePluginOptions(options: unknown): unknown {\n if (options === null || options === undefined) {\n return {}\n }\n if (typeof options !== 'object') {\n return options\n }\n if (Array.isArray(options)) {\n return options.map(serializePluginOptions)\n }\n\n const serialized: Record<string, unknown> = {}\n for (const [key, value] of Object.entries(options)) {\n if (typeof value === 'function' || typeof value === 'symbol' || value === undefined) {\n continue\n }\n if (typeof value === 'object' && value !== null) {\n serialized[key] = serializePluginOptions(value)\n } else {\n serialized[key] = value\n }\n }\n return serialized\n}\n","export async function timeout(ms: number): Promise<unknown> {\n return new Promise((resolve) => {\n const timeout = setTimeout(() => {\n resolve(timeout)\n }, ms)\n }).then((timeout) => {\n clearTimeout(timeout as NodeJS.Timeout)\n\n return true\n })\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAMA,SAAgB,WACd,UACA,UAgBI,EAAE,EACE;CACR,MAAM,EAAE,SAAS,SAAS,SAAS,QAAQ,WAAW,SAAS;AAE/D,KAAI,SAAS,WAAW,EACtB,QAAO;AAGT,QAAO,QAAQ,SAAS,KAAK,MAAM,GAAG,SAAS,IAAI,CAAC,KAAK,KAAK,CAAC,SAAS;;;;;AChC1E,IAAa,QAAb,MAAsB;CACpB,0BAAU,IAAI,KAAgB;CAE9B,MAAM,IAAI,KAAgC;AACxC,SAAO,MAAKA,OAAQ,IAAI,IAAI,IAAI;;CAGlC,MAAM,IAAI,KAAa,OAAyB;AAC9C,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UAAU,MAAM;AAGlC,UAAQ,SAAoB;IAC5B,CACD,MAAM;IACR,SAAS,IAAI;;;;;ACvBpB,SAAgB,oBAAoB,SAAiB;CACnD,MAAM;CAGN,MAAM,6BAFkB,UAAU,CAEZ,WAAW,SAAS,UAAU;CACpD,MAAM,WAAW,SAAS,WAAW,QAAQ,+BAAiB,SAAS,GAAG;AAG1E,QAAO;EAAE,MAAM;EAAU,kCAFG,UAAU,EAAE,UAAU,SAAS,CAAC;EAE3B,KADrBK,kBAAK,QAAQ,SAAS;EACI;;;;;;;;;ACTxC,SAAgB,uBAAuB,SAA2B;AAChE,KAAI,YAAY,QAAQ,YAAY,OAClC,QAAO,EAAE;AAEX,KAAI,OAAO,YAAY,SACrB,QAAO;AAET,KAAI,MAAM,QAAQ,QAAQ,CACxB,QAAO,QAAQ,IAAI,uBAAuB;CAG5C,MAAM,aAAsC,EAAE;AAC9C,MAAK,MAAM,CAAC,KAAK,UAAU,OAAO,QAAQ,QAAQ,EAAE;AAClD,MAAI,OAAO,UAAU,cAAc,OAAO,UAAU,YAAY,UAAU,OACxE;AAEF,MAAI,OAAO,UAAU,YAAY,UAAU,KACzC,YAAW,OAAO,uBAAuB,MAAM;MAE/C,YAAW,OAAO;;AAGtB,QAAO;;;;;AC1BT,eAAsB,QAAQ,IAA8B;AAC1D,QAAO,IAAI,SAAS,YAAY;EAC9B,MAAMC,YAAU,iBAAiB;AAC/B,WAAQA,UAAQ;KACf,GAAG;GACN,CAAC,MAAM,cAAY;AACnB,eAAaA,UAA0B;AAEvC,SAAO;GACP"}
package/dist/utils.d.cts CHANGED
@@ -1,3 +1,226 @@
1
- import { A as AsyncEventEmitter } from "./types-ulibr7zw.cjs";
2
- import { C as buildJSDoc, S as Cache, _ as getElapsedMs, a as timeout, b as executeIfOnline, c as renderTemplate, d as isPromiseRejectedResult, f as getNestedAccessor, g as formatMs, h as formatHrtime, i as URLPath, l as isPromise, m as getBarrelFiles, n as setUniqueName, o as serializePluginOptions, r as URLObject, s as resolveModuleSource, t as getUniqueName, u as isPromiseFulfilledResult, v as FunctionParams, x as isOnline, y as FunctionParamsAST } from "./index-BfAwjQCB.cjs";
3
- export { AsyncEventEmitter, Cache, FunctionParams, FunctionParamsAST, URLObject, URLPath, buildJSDoc, executeIfOnline, formatHrtime, formatMs, getBarrelFiles, getElapsedMs, getNestedAccessor, getUniqueName, isOnline, isPromise, isPromiseFulfilledResult, isPromiseRejectedResult, renderTemplate, resolveModuleSource, serializePluginOptions, setUniqueName, timeout };
1
+ import { t as __name } from "./chunk-DlpkT3g-.cjs";
2
+ import { A as AsyncEventEmitter, E as PossiblePromise } from "./types-ulibr7zw.cjs";
3
+ import { n as getBarrelFiles } from "./getBarrelFiles-D9yKoizv.cjs";
4
+
5
+ //#region src/utils/buildJSDoc.d.ts
6
+
7
+ /**
8
+ * Builds a JSDoc comment block with custom indentation.
9
+ * @param comments - Array of comment strings to include in the JSDoc block
10
+ * @param options - Configuration options for formatting
11
+ * @returns Formatted JSDoc string or fallback string if no comments
12
+ */
13
+ declare function buildJSDoc(comments: Array<string>, options?: {
14
+ /**
15
+ * String to use for indenting each line of the JSDoc comment
16
+ * @default ' * ' (3 spaces + asterisk + space)
17
+ */
18
+ indent?: string;
19
+ /**
20
+ * String to append after the closing JSDoc tag
21
+ * @default '\n ' (newline + 2 spaces)
22
+ */
23
+ suffix?: string;
24
+ /**
25
+ * String to return when there are no comments
26
+ * @default ' ' (2 spaces)
27
+ */
28
+ fallback?: string;
29
+ }): string;
30
+ //#endregion
31
+ //#region src/utils/Cache.d.ts
32
+ declare class Cache<T> {
33
+ #private;
34
+ get(key: string): Promise<T | null>;
35
+ set(key: string, value: T): Promise<void>;
36
+ delete(key: string): Promise<void>;
37
+ clear(): Promise<void>;
38
+ keys(): Promise<string[]>;
39
+ values(): Promise<T[]>;
40
+ flush(): Promise<void>;
41
+ }
42
+ //#endregion
43
+ //#region src/utils/checkOnlineStatus.d.ts
44
+ /**
45
+ * Check if the system has internet connectivity
46
+ * Uses DNS lookup to well-known stable domains as a lightweight connectivity test
47
+ */
48
+ declare function isOnline(): Promise<boolean>;
49
+ /**
50
+ * Execute a function only if online, otherwise silently skip
51
+ */
52
+ declare function executeIfOnline<T>(fn: () => Promise<T>): Promise<T | null>;
53
+ //#endregion
54
+ //#region src/utils/FunctionParams.d.ts
55
+ type FunctionParamsASTWithoutType = {
56
+ name?: string;
57
+ type?: string;
58
+ /**
59
+ * @default true
60
+ */
61
+ required?: boolean;
62
+ /**
63
+ * @default true
64
+ */
65
+ enabled?: boolean;
66
+ default?: string;
67
+ };
68
+ type FunctionParamsASTWithType = {
69
+ name?: never;
70
+ type: string;
71
+ /**
72
+ * @default true
73
+ */
74
+ required?: boolean;
75
+ /**
76
+ * @default true
77
+ */
78
+ enabled?: boolean;
79
+ default?: string;
80
+ };
81
+ /**
82
+ * @deprecated
83
+ */
84
+ type FunctionParamsAST = FunctionParamsASTWithoutType | FunctionParamsASTWithType;
85
+ /**
86
+ * @deprecated
87
+ */
88
+ declare class FunctionParams {
89
+ #private;
90
+ constructor();
91
+ get items(): FunctionParamsAST[];
92
+ add(item: FunctionParamsAST | Array<FunctionParamsAST | FunctionParamsAST[] | undefined> | undefined): FunctionParams;
93
+ static toObject(items: FunctionParamsAST[]): FunctionParamsAST;
94
+ toObject(): FunctionParamsAST;
95
+ static toString(items: (FunctionParamsAST | FunctionParamsAST[])[]): string;
96
+ toString(): string;
97
+ }
98
+ //#endregion
99
+ //#region src/utils/formatHrtime.d.ts
100
+ /**
101
+ * Calculates elapsed time in milliseconds from a high-resolution start time.
102
+ * Rounds to 2 decimal places to provide sub-millisecond precision without noise.
103
+ */
104
+ declare function getElapsedMs(hrStart: [number, number]): number;
105
+ /**
106
+ * Converts a millisecond duration into a human-readable string.
107
+ * Adjusts units (ms, s, m s) based on the magnitude of the duration.
108
+ */
109
+ declare function formatMs(ms: number): string;
110
+ /**
111
+ * Convenience helper to get and format elapsed time in one step.
112
+ */
113
+ declare function formatHrtime(hrStart: [number, number]): string;
114
+ //#endregion
115
+ //#region src/utils/getNestedAccessor.d.ts
116
+ /**
117
+ * Converts a param path (string with dot notation or array of strings) to a JavaScript accessor expression.
118
+ * @param param - The param path, e.g., 'pagination.next.id' or ['pagination', 'next', 'id']
119
+ * @param accessor - The base accessor, e.g., 'lastPage' or 'firstPage'
120
+ * @returns A JavaScript accessor expression, e.g., "lastPage?.['pagination']?.['next']?.['id']", or undefined if param is empty
121
+ *
122
+ * @example
123
+ * ```ts
124
+ * getNestedAccessor('pagination.next.id', 'lastPage')
125
+ * // returns: "lastPage?.['pagination']?.['next']?.['id']"
126
+ *
127
+ * getNestedAccessor(['pagination', 'next', 'id'], 'lastPage')
128
+ * // returns: "lastPage?.['pagination']?.['next']?.['id']"
129
+ *
130
+ * getNestedAccessor('', 'lastPage')
131
+ * // returns: undefined
132
+ * ```
133
+ */
134
+ declare function getNestedAccessor(param: string | string[], accessor: string): string | undefined;
135
+ //#endregion
136
+ //#region src/utils/promise.d.ts
137
+ declare function isPromise<T>(result: PossiblePromise<T>): result is Promise<T>;
138
+ declare function isPromiseFulfilledResult<T = unknown>(result: PromiseSettledResult<unknown>): result is PromiseFulfilledResult<T>;
139
+ declare function isPromiseRejectedResult<T>(result: PromiseSettledResult<unknown>): result is Omit<PromiseRejectedResult, 'reason'> & {
140
+ reason: T;
141
+ };
142
+ //#endregion
143
+ //#region src/utils/renderTemplate.d.ts
144
+ declare function renderTemplate<TData extends Record<string, unknown> = Record<string, unknown>>(template: string, data?: TData | undefined): string;
145
+ //#endregion
146
+ //#region src/utils/resolveModuleSource.d.ts
147
+ declare function resolveModuleSource(pkgName: string): {
148
+ readonly path: string;
149
+ readonly source: string;
150
+ readonly ext: string;
151
+ };
152
+ //#endregion
153
+ //#region src/utils/serializePluginOptions.d.ts
154
+ /**
155
+ * Serialize plugin options for safe JSON transport.
156
+ * Strips functions, symbols, and undefined values recursively.
157
+ */
158
+ declare function serializePluginOptions(options: unknown): unknown;
159
+ //#endregion
160
+ //#region src/utils/timeout.d.ts
161
+ declare function timeout(ms: number): Promise<unknown>;
162
+ //#endregion
163
+ //#region src/utils/URLPath.d.ts
164
+ type URLObject = {
165
+ url: string;
166
+ params?: Record<string, string>;
167
+ };
168
+ type ObjectOptions = {
169
+ type?: 'path' | 'template';
170
+ replacer?: (pathParam: string) => string;
171
+ stringify?: boolean;
172
+ };
173
+ type Options = {
174
+ casing?: 'camelcase';
175
+ };
176
+ declare class URLPath {
177
+ #private;
178
+ path: string;
179
+ constructor(path: string, options?: Options);
180
+ /**
181
+ * Convert Swagger path to URLPath(syntax of Express)
182
+ * @example /pet/{petId} => /pet/:petId
183
+ */
184
+ get URL(): string;
185
+ get isURL(): boolean;
186
+ /**
187
+ * Convert Swagger path to template literals/ template strings(camelcase)
188
+ * @example /pet/{petId} => `/pet/${petId}`
189
+ * @example /account/monetary-accountID => `/account/${monetaryAccountId}`
190
+ * @example /account/userID => `/account/${userId}`
191
+ */
192
+ get template(): string;
193
+ get object(): URLObject | string;
194
+ get params(): Record<string, string> | undefined;
195
+ toObject({
196
+ type,
197
+ replacer,
198
+ stringify
199
+ }?: ObjectOptions): URLObject | string;
200
+ /**
201
+ * Convert Swagger path to template literals/ template strings(camelcase)
202
+ * @example /pet/{petId} => `/pet/${petId}`
203
+ * @example /account/monetary-accountID => `/account/${monetaryAccountId}`
204
+ * @example /account/userID => `/account/${userId}`
205
+ */
206
+ toTemplateString({
207
+ prefix,
208
+ replacer
209
+ }?: {
210
+ prefix?: string;
211
+ replacer?: (pathParam: string) => string;
212
+ }): string;
213
+ getParams(replacer?: (pathParam: string) => string): Record<string, string> | undefined;
214
+ /**
215
+ * Convert Swagger path to URLPath(syntax of Express)
216
+ * @example /pet/{petId} => /pet/:petId
217
+ */
218
+ toURLPath(): string;
219
+ }
220
+ //#endregion
221
+ //#region src/utils/uniqueName.d.ts
222
+ declare function getUniqueName(originalName: string, data: Record<string, number>): string;
223
+ declare function setUniqueName(originalName: string, data: Record<string, number>): string;
224
+ //#endregion
225
+ export { AsyncEventEmitter, Cache, FunctionParams, type FunctionParamsAST, type URLObject, URLPath, buildJSDoc, executeIfOnline, formatHrtime, formatMs, getBarrelFiles, getElapsedMs, getNestedAccessor, getUniqueName, isOnline, isPromise, isPromiseFulfilledResult, isPromiseRejectedResult, renderTemplate, resolveModuleSource, serializePluginOptions, setUniqueName, timeout };
226
+ //# sourceMappingURL=utils.d.cts.map
package/dist/utils.d.ts CHANGED
@@ -1,3 +1,226 @@
1
- import { A as AsyncEventEmitter } from "./types-Cn3Gwsf3.js";
2
- import { C as buildJSDoc, S as Cache, _ as getElapsedMs, a as timeout, b as executeIfOnline, c as renderTemplate, d as isPromiseRejectedResult, f as getNestedAccessor, g as formatMs, h as formatHrtime, i as URLPath, l as isPromise, m as getBarrelFiles, n as setUniqueName, o as serializePluginOptions, r as URLObject, s as resolveModuleSource, t as getUniqueName, u as isPromiseFulfilledResult, v as FunctionParams, x as isOnline, y as FunctionParamsAST } from "./index-C0nP9vjm.js";
3
- export { AsyncEventEmitter, Cache, FunctionParams, FunctionParamsAST, URLObject, URLPath, buildJSDoc, executeIfOnline, formatHrtime, formatMs, getBarrelFiles, getElapsedMs, getNestedAccessor, getUniqueName, isOnline, isPromise, isPromiseFulfilledResult, isPromiseRejectedResult, renderTemplate, resolveModuleSource, serializePluginOptions, setUniqueName, timeout };
1
+ import { t as __name } from "./chunk-iVr_oF3V.js";
2
+ import { A as AsyncEventEmitter, E as PossiblePromise } from "./types-Cn3Gwsf3.js";
3
+ import { n as getBarrelFiles } from "./getBarrelFiles-CvaEQ7z_.js";
4
+
5
+ //#region src/utils/buildJSDoc.d.ts
6
+
7
+ /**
8
+ * Builds a JSDoc comment block with custom indentation.
9
+ * @param comments - Array of comment strings to include in the JSDoc block
10
+ * @param options - Configuration options for formatting
11
+ * @returns Formatted JSDoc string or fallback string if no comments
12
+ */
13
+ declare function buildJSDoc(comments: Array<string>, options?: {
14
+ /**
15
+ * String to use for indenting each line of the JSDoc comment
16
+ * @default ' * ' (3 spaces + asterisk + space)
17
+ */
18
+ indent?: string;
19
+ /**
20
+ * String to append after the closing JSDoc tag
21
+ * @default '\n ' (newline + 2 spaces)
22
+ */
23
+ suffix?: string;
24
+ /**
25
+ * String to return when there are no comments
26
+ * @default ' ' (2 spaces)
27
+ */
28
+ fallback?: string;
29
+ }): string;
30
+ //#endregion
31
+ //#region src/utils/Cache.d.ts
32
+ declare class Cache<T> {
33
+ #private;
34
+ get(key: string): Promise<T | null>;
35
+ set(key: string, value: T): Promise<void>;
36
+ delete(key: string): Promise<void>;
37
+ clear(): Promise<void>;
38
+ keys(): Promise<string[]>;
39
+ values(): Promise<T[]>;
40
+ flush(): Promise<void>;
41
+ }
42
+ //#endregion
43
+ //#region src/utils/checkOnlineStatus.d.ts
44
+ /**
45
+ * Check if the system has internet connectivity
46
+ * Uses DNS lookup to well-known stable domains as a lightweight connectivity test
47
+ */
48
+ declare function isOnline(): Promise<boolean>;
49
+ /**
50
+ * Execute a function only if online, otherwise silently skip
51
+ */
52
+ declare function executeIfOnline<T>(fn: () => Promise<T>): Promise<T | null>;
53
+ //#endregion
54
+ //#region src/utils/FunctionParams.d.ts
55
+ type FunctionParamsASTWithoutType = {
56
+ name?: string;
57
+ type?: string;
58
+ /**
59
+ * @default true
60
+ */
61
+ required?: boolean;
62
+ /**
63
+ * @default true
64
+ */
65
+ enabled?: boolean;
66
+ default?: string;
67
+ };
68
+ type FunctionParamsASTWithType = {
69
+ name?: never;
70
+ type: string;
71
+ /**
72
+ * @default true
73
+ */
74
+ required?: boolean;
75
+ /**
76
+ * @default true
77
+ */
78
+ enabled?: boolean;
79
+ default?: string;
80
+ };
81
+ /**
82
+ * @deprecated
83
+ */
84
+ type FunctionParamsAST = FunctionParamsASTWithoutType | FunctionParamsASTWithType;
85
+ /**
86
+ * @deprecated
87
+ */
88
+ declare class FunctionParams {
89
+ #private;
90
+ constructor();
91
+ get items(): FunctionParamsAST[];
92
+ add(item: FunctionParamsAST | Array<FunctionParamsAST | FunctionParamsAST[] | undefined> | undefined): FunctionParams;
93
+ static toObject(items: FunctionParamsAST[]): FunctionParamsAST;
94
+ toObject(): FunctionParamsAST;
95
+ static toString(items: (FunctionParamsAST | FunctionParamsAST[])[]): string;
96
+ toString(): string;
97
+ }
98
+ //#endregion
99
+ //#region src/utils/formatHrtime.d.ts
100
+ /**
101
+ * Calculates elapsed time in milliseconds from a high-resolution start time.
102
+ * Rounds to 2 decimal places to provide sub-millisecond precision without noise.
103
+ */
104
+ declare function getElapsedMs(hrStart: [number, number]): number;
105
+ /**
106
+ * Converts a millisecond duration into a human-readable string.
107
+ * Adjusts units (ms, s, m s) based on the magnitude of the duration.
108
+ */
109
+ declare function formatMs(ms: number): string;
110
+ /**
111
+ * Convenience helper to get and format elapsed time in one step.
112
+ */
113
+ declare function formatHrtime(hrStart: [number, number]): string;
114
+ //#endregion
115
+ //#region src/utils/getNestedAccessor.d.ts
116
+ /**
117
+ * Converts a param path (string with dot notation or array of strings) to a JavaScript accessor expression.
118
+ * @param param - The param path, e.g., 'pagination.next.id' or ['pagination', 'next', 'id']
119
+ * @param accessor - The base accessor, e.g., 'lastPage' or 'firstPage'
120
+ * @returns A JavaScript accessor expression, e.g., "lastPage?.['pagination']?.['next']?.['id']", or undefined if param is empty
121
+ *
122
+ * @example
123
+ * ```ts
124
+ * getNestedAccessor('pagination.next.id', 'lastPage')
125
+ * // returns: "lastPage?.['pagination']?.['next']?.['id']"
126
+ *
127
+ * getNestedAccessor(['pagination', 'next', 'id'], 'lastPage')
128
+ * // returns: "lastPage?.['pagination']?.['next']?.['id']"
129
+ *
130
+ * getNestedAccessor('', 'lastPage')
131
+ * // returns: undefined
132
+ * ```
133
+ */
134
+ declare function getNestedAccessor(param: string | string[], accessor: string): string | undefined;
135
+ //#endregion
136
+ //#region src/utils/promise.d.ts
137
+ declare function isPromise<T>(result: PossiblePromise<T>): result is Promise<T>;
138
+ declare function isPromiseFulfilledResult<T = unknown>(result: PromiseSettledResult<unknown>): result is PromiseFulfilledResult<T>;
139
+ declare function isPromiseRejectedResult<T>(result: PromiseSettledResult<unknown>): result is Omit<PromiseRejectedResult, 'reason'> & {
140
+ reason: T;
141
+ };
142
+ //#endregion
143
+ //#region src/utils/renderTemplate.d.ts
144
+ declare function renderTemplate<TData extends Record<string, unknown> = Record<string, unknown>>(template: string, data?: TData | undefined): string;
145
+ //#endregion
146
+ //#region src/utils/resolveModuleSource.d.ts
147
+ declare function resolveModuleSource(pkgName: string): {
148
+ readonly path: string;
149
+ readonly source: string;
150
+ readonly ext: string;
151
+ };
152
+ //#endregion
153
+ //#region src/utils/serializePluginOptions.d.ts
154
+ /**
155
+ * Serialize plugin options for safe JSON transport.
156
+ * Strips functions, symbols, and undefined values recursively.
157
+ */
158
+ declare function serializePluginOptions(options: unknown): unknown;
159
+ //#endregion
160
+ //#region src/utils/timeout.d.ts
161
+ declare function timeout(ms: number): Promise<unknown>;
162
+ //#endregion
163
+ //#region src/utils/URLPath.d.ts
164
+ type URLObject = {
165
+ url: string;
166
+ params?: Record<string, string>;
167
+ };
168
+ type ObjectOptions = {
169
+ type?: 'path' | 'template';
170
+ replacer?: (pathParam: string) => string;
171
+ stringify?: boolean;
172
+ };
173
+ type Options = {
174
+ casing?: 'camelcase';
175
+ };
176
+ declare class URLPath {
177
+ #private;
178
+ path: string;
179
+ constructor(path: string, options?: Options);
180
+ /**
181
+ * Convert Swagger path to URLPath(syntax of Express)
182
+ * @example /pet/{petId} => /pet/:petId
183
+ */
184
+ get URL(): string;
185
+ get isURL(): boolean;
186
+ /**
187
+ * Convert Swagger path to template literals/ template strings(camelcase)
188
+ * @example /pet/{petId} => `/pet/${petId}`
189
+ * @example /account/monetary-accountID => `/account/${monetaryAccountId}`
190
+ * @example /account/userID => `/account/${userId}`
191
+ */
192
+ get template(): string;
193
+ get object(): URLObject | string;
194
+ get params(): Record<string, string> | undefined;
195
+ toObject({
196
+ type,
197
+ replacer,
198
+ stringify
199
+ }?: ObjectOptions): URLObject | string;
200
+ /**
201
+ * Convert Swagger path to template literals/ template strings(camelcase)
202
+ * @example /pet/{petId} => `/pet/${petId}`
203
+ * @example /account/monetary-accountID => `/account/${monetaryAccountId}`
204
+ * @example /account/userID => `/account/${userId}`
205
+ */
206
+ toTemplateString({
207
+ prefix,
208
+ replacer
209
+ }?: {
210
+ prefix?: string;
211
+ replacer?: (pathParam: string) => string;
212
+ }): string;
213
+ getParams(replacer?: (pathParam: string) => string): Record<string, string> | undefined;
214
+ /**
215
+ * Convert Swagger path to URLPath(syntax of Express)
216
+ * @example /pet/{petId} => /pet/:petId
217
+ */
218
+ toURLPath(): string;
219
+ }
220
+ //#endregion
221
+ //#region src/utils/uniqueName.d.ts
222
+ declare function getUniqueName(originalName: string, data: Record<string, number>): string;
223
+ declare function setUniqueName(originalName: string, data: Record<string, number>): string;
224
+ //#endregion
225
+ export { AsyncEventEmitter, Cache, FunctionParams, type FunctionParamsAST, type URLObject, URLPath, buildJSDoc, executeIfOnline, formatHrtime, formatMs, getBarrelFiles, getElapsedMs, getNestedAccessor, getUniqueName, isOnline, isPromise, isPromiseFulfilledResult, isPromiseRejectedResult, renderTemplate, resolveModuleSource, serializePluginOptions, setUniqueName, timeout };
226
+ //# sourceMappingURL=utils.d.ts.map