@kubb/core 4.22.0 → 4.22.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/utils.d.ts CHANGED
@@ -1,226 +1,3 @@
1
- import { t as __name } from "./chunk-iVr_oF3V.js";
2
- import { F as AsyncEventEmitter, j as PossiblePromise } from "./types-Dv2RimvH.js";
3
- import { n as getBarrelFiles } from "./getBarrelFiles-D_2NWu2Q.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
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 };
package/dist/utils.js CHANGED
@@ -1,265 +1,4 @@
1
- import { t as __name } from "./chunk-iVr_oF3V.js";
2
- import { a as getElapsedMs, i as formatMs, l as getUniqueName, n as URLPath, o as AsyncEventEmitter, r as formatHrtime, t as getBarrelFiles, u as setUniqueName } from "./getBarrelFiles-gRyVPFBP.js";
3
- import { m as camelCase } from "./transformers-8ju9ixkG.js";
4
- import path from "node:path";
5
- import { orderBy } from "natural-orderby";
6
- import { fileURLToPath } from "node:url";
7
- import { readFileSync } from "node:fs";
8
- import dns from "node:dns";
9
- import createJiti from "jiti";
1
+ import { C as setUniqueName, S as getUniqueName, _ as formatMs, a as isPromise, c as getNestedAccessor, d as executeIfOnline, f as isOnline, g as formatHrtime, h as URLPath, i as renderTemplate, l as getBarrelFiles, m as buildJSDoc, n as serializePluginOptions, o as isPromiseFulfilledResult, p as Cache, r as resolveModuleSource, s as isPromiseRejectedResult, t as timeout, u as FunctionParams, v as getElapsedMs, y as AsyncEventEmitter } from "./utils-C3cuilmF.js";
2
+ import "./transformers-8ju9ixkG.js";
10
3
 
11
- //#region src/utils/buildJSDoc.ts
12
- /**
13
- * Builds a JSDoc comment block with custom indentation.
14
- * @param comments - Array of comment strings to include in the JSDoc block
15
- * @param options - Configuration options for formatting
16
- * @returns Formatted JSDoc string or fallback string if no comments
17
- */
18
- function buildJSDoc(comments, options = {}) {
19
- const { indent = " * ", suffix = "\n ", fallback = " " } = options;
20
- if (comments.length === 0) return fallback;
21
- return `/**\n${comments.map((c) => `${indent}${c}`).join("\n")}\n */${suffix}`;
22
- }
23
-
24
- //#endregion
25
- //#region src/utils/Cache.ts
26
- var Cache = class {
27
- #buffer = /* @__PURE__ */ new Map();
28
- async get(key) {
29
- return this.#buffer.get(key) ?? null;
30
- }
31
- async set(key, value) {
32
- this.#buffer.set(key, value);
33
- }
34
- async delete(key) {
35
- this.#buffer.delete(key);
36
- }
37
- async clear() {
38
- this.#buffer.clear();
39
- }
40
- async keys() {
41
- return [...this.#buffer.keys()];
42
- }
43
- async values() {
44
- return [...this.#buffer.values()];
45
- }
46
- async flush() {}
47
- };
48
-
49
- //#endregion
50
- //#region src/utils/checkOnlineStatus.ts
51
- /**
52
- * Check if the system has internet connectivity
53
- * Uses DNS lookup to well-known stable domains as a lightweight connectivity test
54
- */
55
- async function isOnline() {
56
- for (const domain of [
57
- "dns.google.com",
58
- "cloudflare.com",
59
- "one.one.one.one"
60
- ]) try {
61
- await dns.promises.resolve(domain);
62
- return true;
63
- } catch {}
64
- return false;
65
- }
66
- /**
67
- * Execute a function only if online, otherwise silently skip
68
- */
69
- async function executeIfOnline(fn) {
70
- if (!await isOnline()) return null;
71
- try {
72
- return await fn();
73
- } catch {
74
- return null;
75
- }
76
- }
77
-
78
- //#endregion
79
- //#region src/utils/FunctionParams.ts
80
- /**
81
- * @deprecated
82
- */
83
- var FunctionParams = class FunctionParams {
84
- #items = [];
85
- constructor() {
86
- return this;
87
- }
88
- get items() {
89
- return this.#items.flat();
90
- }
91
- add(item) {
92
- if (!item) return this;
93
- if (Array.isArray(item)) {
94
- item.filter(Boolean).forEach((it) => {
95
- this.#items.push(it);
96
- });
97
- return this;
98
- }
99
- this.#items.push(item);
100
- return this;
101
- }
102
- static #orderItems(items) {
103
- return orderBy(items.filter(Boolean), [(v) => {
104
- if (Array.isArray(v)) return;
105
- return !v.default;
106
- }, (v) => {
107
- if (Array.isArray(v)) return;
108
- return v.required ?? true;
109
- }], ["desc", "desc"]);
110
- }
111
- static #addParams(acc, item) {
112
- const { enabled = true, name, type, required = true, ...rest } = item;
113
- if (!enabled) return acc;
114
- if (!name) {
115
- acc.push(`${type}${rest.default ? ` = ${rest.default}` : ""}`);
116
- return acc;
117
- }
118
- const parameterName = name.startsWith("{") ? name : camelCase(name);
119
- if (type) if (required) acc.push(`${parameterName}: ${type}${rest.default ? ` = ${rest.default}` : ""}`);
120
- else acc.push(`${parameterName}?: ${type}`);
121
- else acc.push(`${parameterName}`);
122
- return acc;
123
- }
124
- static toObject(items) {
125
- let type = [];
126
- let name = [];
127
- const enabled = items.every((item) => item.enabled) ? items.at(0)?.enabled : true;
128
- const required = items.every((item) => item.required) ?? true;
129
- items.forEach((item) => {
130
- name = FunctionParams.#addParams(name, {
131
- ...item,
132
- type: void 0
133
- });
134
- if (items.some((item$1) => item$1.type)) type = FunctionParams.#addParams(type, item);
135
- });
136
- return {
137
- name: `{ ${name.join(", ")} }`,
138
- type: type.length ? `{ ${type.join("; ")} }` : void 0,
139
- enabled,
140
- required
141
- };
142
- }
143
- toObject() {
144
- const items = FunctionParams.#orderItems(this.#items).flat();
145
- return FunctionParams.toObject(items);
146
- }
147
- static toString(items) {
148
- return FunctionParams.#orderItems(items).reduce((acc, item) => {
149
- if (Array.isArray(item)) {
150
- if (item.length <= 0) return acc;
151
- const subItems = FunctionParams.#orderItems(item);
152
- const objectItem = FunctionParams.toObject(subItems);
153
- return FunctionParams.#addParams(acc, objectItem);
154
- }
155
- return FunctionParams.#addParams(acc, item);
156
- }, []).join(", ");
157
- }
158
- toString() {
159
- const items = FunctionParams.#orderItems(this.#items);
160
- return FunctionParams.toString(items);
161
- }
162
- };
163
-
164
- //#endregion
165
- //#region src/utils/getNestedAccessor.ts
166
- /**
167
- * Converts a param path (string with dot notation or array of strings) to a JavaScript accessor expression.
168
- * @param param - The param path, e.g., 'pagination.next.id' or ['pagination', 'next', 'id']
169
- * @param accessor - The base accessor, e.g., 'lastPage' or 'firstPage'
170
- * @returns A JavaScript accessor expression, e.g., "lastPage?.['pagination']?.['next']?.['id']", or undefined if param is empty
171
- *
172
- * @example
173
- * ```ts
174
- * getNestedAccessor('pagination.next.id', 'lastPage')
175
- * // returns: "lastPage?.['pagination']?.['next']?.['id']"
176
- *
177
- * getNestedAccessor(['pagination', 'next', 'id'], 'lastPage')
178
- * // returns: "lastPage?.['pagination']?.['next']?.['id']"
179
- *
180
- * getNestedAccessor('', 'lastPage')
181
- * // returns: undefined
182
- * ```
183
- */
184
- function getNestedAccessor(param, accessor) {
185
- const parts = Array.isArray(param) ? param : param.split(".");
186
- if (parts.length === 0 || parts.length === 1 && parts[0] === "") return;
187
- return parts.reduce((acc, part) => `${acc}?.['${part}']`, accessor);
188
- }
189
-
190
- //#endregion
191
- //#region src/utils/promise.ts
192
- function isPromise(result) {
193
- return !!result && typeof result?.then === "function";
194
- }
195
- function isPromiseFulfilledResult(result) {
196
- return result.status === "fulfilled";
197
- }
198
- function isPromiseRejectedResult(result) {
199
- return result.status === "rejected";
200
- }
201
-
202
- //#endregion
203
- //#region src/utils/renderTemplate.ts
204
- function renderTemplate(template, data = void 0) {
205
- if (!data || !Object.keys(data).length) return template.replace(/{{(.*?)}}/g, "");
206
- return template.match(/{{(.*?)}}/g)?.reduce((prev, curr) => {
207
- const index = curr.split(/{{|}}/).filter(Boolean)[0]?.trim();
208
- if (index === void 0) return prev;
209
- const value = data[index];
210
- if (value === void 0) return prev;
211
- return prev.replace(curr, () => {
212
- if (typeof value === "boolean") return `${value.toString()}` || "false";
213
- return value || "";
214
- }).trim();
215
- }, template) || "";
216
- }
217
-
218
- //#endregion
219
- //#region src/utils/resolveModuleSource.ts
220
- function resolveModuleSource(pkgName) {
221
- const parentURL = import.meta.url;
222
- const resolved = createJiti(parentURL).esmResolve(pkgName, parentURL);
223
- const filePath = resolved.startsWith("file:") ? fileURLToPath(resolved) : resolved;
224
- return {
225
- path: filePath,
226
- source: readFileSync(filePath, { encoding: "utf-8" }),
227
- ext: path.extname(filePath)
228
- };
229
- }
230
-
231
- //#endregion
232
- //#region src/utils/serializePluginOptions.ts
233
- /**
234
- * Serialize plugin options for safe JSON transport.
235
- * Strips functions, symbols, and undefined values recursively.
236
- */
237
- function serializePluginOptions(options) {
238
- if (options === null || options === void 0) return {};
239
- if (typeof options !== "object") return options;
240
- if (Array.isArray(options)) return options.map(serializePluginOptions);
241
- const serialized = {};
242
- for (const [key, value] of Object.entries(options)) {
243
- if (typeof value === "function" || typeof value === "symbol" || value === void 0) continue;
244
- if (typeof value === "object" && value !== null) serialized[key] = serializePluginOptions(value);
245
- else serialized[key] = value;
246
- }
247
- return serialized;
248
- }
249
-
250
- //#endregion
251
- //#region src/utils/timeout.ts
252
- async function timeout(ms) {
253
- return new Promise((resolve$1) => {
254
- const timeout$1 = setTimeout(() => {
255
- resolve$1(timeout$1);
256
- }, ms);
257
- }).then((timeout$1) => {
258
- clearTimeout(timeout$1);
259
- return true;
260
- });
261
- }
262
-
263
- //#endregion
264
- export { AsyncEventEmitter, Cache, FunctionParams, URLPath, buildJSDoc, executeIfOnline, formatHrtime, formatMs, getBarrelFiles, getElapsedMs, getNestedAccessor, getUniqueName, isOnline, isPromise, isPromiseFulfilledResult, isPromiseRejectedResult, renderTemplate, resolveModuleSource, serializePluginOptions, setUniqueName, timeout };
265
- //# sourceMappingURL=utils.js.map
4
+ export { AsyncEventEmitter, Cache, FunctionParams, URLPath, buildJSDoc, executeIfOnline, formatHrtime, formatMs, getBarrelFiles, getElapsedMs, getNestedAccessor, getUniqueName, isOnline, isPromise, isPromiseFulfilledResult, isPromiseRejectedResult, renderTemplate, resolveModuleSource, serializePluginOptions, setUniqueName, timeout };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kubb/core",
3
- "version": "4.22.0",
3
+ "version": "4.22.2",
4
4
  "description": "Core functionality for Kubb's plugin-based code generation system, providing the foundation for transforming OpenAPI specifications.",
5
5
  "keywords": [
6
6
  "typescript",
@@ -70,6 +70,7 @@
70
70
  },
71
71
  "files": [
72
72
  "src",
73
+ "schemas",
73
74
  "dist",
74
75
  "*.d.ts",
75
76
  "*.d.cts",