@kubb/core 5.18.8 → 5.19.1
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/index.cjs +94 -78
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +75 -2
- package/dist/index.d.ts +75 -2
- package/dist/index.js +94 -78
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.d.cts
CHANGED
|
@@ -37,6 +37,57 @@ export declare function pascalCase(text: string, { prefix, suffix }?: Options$1)
|
|
|
37
37
|
* ```
|
|
38
38
|
*/
|
|
39
39
|
type PossiblePromise<T> = Promise<T> | T;
|
|
40
|
+
type Store<TKey, TValue> = {
|
|
41
|
+
has(key: TKey): boolean;
|
|
42
|
+
get(key: TKey): TValue | undefined;
|
|
43
|
+
set(key: TKey, value: TValue): unknown;
|
|
44
|
+
};
|
|
45
|
+
/**
|
|
46
|
+
* Returns the value cached under `key` in `store`, computing and storing it on the first call.
|
|
47
|
+
* Pass a `WeakMap` for object keys, so an entry goes away with its key, or a `Map` for primitive
|
|
48
|
+
* keys. A cached `null` or `undefined` counts as a hit, so `compute` runs once per key.
|
|
49
|
+
*
|
|
50
|
+
* @example
|
|
51
|
+
* `const refs = memo(refCache, node, () => collectRefs(node))`
|
|
52
|
+
*/
|
|
53
|
+
declare function memo$1<TKey, TValue>(store: Store<TKey, TValue>, key: TKey, compute: () => TValue): TValue;
|
|
54
|
+
declare namespace memo$1 {
|
|
55
|
+
export { createStore as create };
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Creates a store for `memo`. With no options it is a `Map`. Each option changes one thing:
|
|
59
|
+
*
|
|
60
|
+
* - `weak` holds the keys weakly, in a `WeakMap`, so an entry goes away with its key.
|
|
61
|
+
* - `max` bounds the store: it empties itself before the entry that would pass `max`, which keeps a
|
|
62
|
+
* cache in a long-running process from growing without end. `max: 1` keeps only the last entry.
|
|
63
|
+
*
|
|
64
|
+
* @example
|
|
65
|
+
* `const patterns = memo.create<string, RegExp>()`
|
|
66
|
+
*
|
|
67
|
+
* @example Freed with its key
|
|
68
|
+
* `const refs = memo.create<SchemaNode, Array<string>>({ weak: true })`
|
|
69
|
+
*
|
|
70
|
+
* @example Bounded
|
|
71
|
+
* `const names = memo.create<string, string>({ max: 100_000 })`
|
|
72
|
+
*
|
|
73
|
+
* @example Many values per key
|
|
74
|
+
* ```ts
|
|
75
|
+
* const filesByPlugin = memo.create<string, Array<string>>()
|
|
76
|
+
* memo(filesByPlugin, 'plugin-ts', () => []).push('models.ts')
|
|
77
|
+
* ```
|
|
78
|
+
*/
|
|
79
|
+
declare function createStore<TKey, TValue>(options?: {
|
|
80
|
+
weak?: false;
|
|
81
|
+
max?: undefined;
|
|
82
|
+
}): Map<TKey, TValue>;
|
|
83
|
+
declare function createStore<TKey extends WeakKey, TValue>(options: {
|
|
84
|
+
weak: true;
|
|
85
|
+
max?: undefined;
|
|
86
|
+
}): WeakMap<TKey, TValue>;
|
|
87
|
+
declare function createStore<TKey, TValue>(options: {
|
|
88
|
+
max: number;
|
|
89
|
+
weak?: false;
|
|
90
|
+
}): Store<TKey, TValue>;
|
|
40
91
|
/** A union of known literals that still accepts any other value of `Base`, without collapsing
|
|
41
92
|
* the literals away. Editors keep autocompleting the known members while arbitrary strings stay
|
|
42
93
|
* assignable.
|
|
@@ -923,6 +974,7 @@ type Memo = <TKey extends MemoKey, TValue extends MemoValue<TKey>>(key: TKey, co
|
|
|
923
974
|
type Options = {
|
|
924
975
|
hooks: Hookable<KubbHooks>;
|
|
925
976
|
signal?: AbortSignal;
|
|
977
|
+
fileRefs?: Array<string>;
|
|
926
978
|
/**
|
|
927
979
|
* Passed to `fileManager.write` so files the output passes already normalized are left alone.
|
|
928
980
|
*/
|
|
@@ -3250,9 +3302,13 @@ type Adapter<TOptions extends AdapterFactoryOptions = AdapterFactoryOptions> = {
|
|
|
3250
3302
|
* every ref node pointing at a renamed schema, so `ast.ref.getName` and `resolver.imports`
|
|
3251
3303
|
* resolve a `$ref` to the file that is actually generated. Refs that keep their pointer's
|
|
3252
3304
|
* last segment need no stamp.
|
|
3305
|
+
*
|
|
3306
|
+
* With `fileRefs`, a `$ref` may only read local files inside those folders, for a host that does
|
|
3307
|
+
* not trust the spec. An empty list allows none. Unset, a `$ref` reads any file.
|
|
3253
3308
|
*/
|
|
3254
3309
|
parse: (source: AdapterSource, options?: {
|
|
3255
3310
|
signal?: AbortSignal;
|
|
3311
|
+
fileRefs?: Array<string>;
|
|
3256
3312
|
}) => PossiblePromise<InputNode>;
|
|
3257
3313
|
/**
|
|
3258
3314
|
* Validate the document at the given path or URL.
|
|
@@ -3344,8 +3400,20 @@ export declare function setMacros(macros: ReadonlyArray<Macro>): void;
|
|
|
3344
3400
|
export declare function injectFile(file: UserFileNode): void;
|
|
3345
3401
|
/**
|
|
3346
3402
|
* Returns a value computed once per build and shared by every plugin, like `ctx.memo`.
|
|
3403
|
+
*
|
|
3404
|
+
* Pass a store first to cache in it instead, with no build needed: a `Map` or `WeakMap`, or one
|
|
3405
|
+
* from `memo.create`.
|
|
3406
|
+
*
|
|
3407
|
+
* @example Once per build
|
|
3408
|
+
* `const names = memo('myPlugin:names', () => collectNames(schemas))`
|
|
3409
|
+
*
|
|
3410
|
+
* @example In your own store
|
|
3411
|
+
* ```ts
|
|
3412
|
+
* const cache = memo.create<ast.SchemaNode, Array<string>>({ weak: true })
|
|
3413
|
+
* const refs = memo(cache, node, () => collectRefs(node))
|
|
3414
|
+
* ```
|
|
3347
3415
|
*/
|
|
3348
|
-
export declare const memo: Memo;
|
|
3416
|
+
export declare const memo: Memo & typeof memo$1;
|
|
3349
3417
|
/**
|
|
3350
3418
|
* Returns the options the user passed to the plugin being set up, like `ctx.options`.
|
|
3351
3419
|
*/
|
|
@@ -3398,6 +3466,10 @@ type CreateKubbOptions = {
|
|
|
3398
3466
|
* Stops the build at the next safe checkpoint.
|
|
3399
3467
|
*/
|
|
3400
3468
|
signal?: AbortSignal;
|
|
3469
|
+
/**
|
|
3470
|
+
* The only folders a `$ref` in the input may read local files from. Unset, a `$ref` reads any file.
|
|
3471
|
+
*/
|
|
3472
|
+
fileRefs?: Array<string>;
|
|
3401
3473
|
};
|
|
3402
3474
|
type ConfigGenerateResult = GenerateResult & {
|
|
3403
3475
|
kubb: Kubb$1;
|
|
@@ -3628,7 +3700,7 @@ export declare function createResolver<T extends PluginType>(options: ResolverOp
|
|
|
3628
3700
|
/**
|
|
3629
3701
|
* Fetches one commit of a git repository into a temporary directory with a shallow `git fetch`,
|
|
3630
3702
|
* so any host and the user's own git credentials work, and relative `$ref` files resolve.
|
|
3631
|
-
* Resolves to the spec path on disk and a `dispose` that deletes the checkout.
|
|
3703
|
+
* Resolves to the spec path on disk, the checkout `dir`, and a `dispose` that deletes the checkout.
|
|
3632
3704
|
*
|
|
3633
3705
|
* With `publicOnly`, the repository must be an https URL on public addresses, the fetch connects to
|
|
3634
3706
|
* the addresses checked, and it does not follow a redirect. `authorization` adds that header to this
|
|
@@ -3639,6 +3711,7 @@ export declare function checkoutGitInput(input: string, signal?: AbortSignal, {
|
|
|
3639
3711
|
authorization?: string;
|
|
3640
3712
|
}): Promise<{
|
|
3641
3713
|
path: string;
|
|
3714
|
+
dir: string;
|
|
3642
3715
|
dispose: () => Promise<void>;
|
|
3643
3716
|
}>;
|
|
3644
3717
|
/**
|
package/dist/index.d.ts
CHANGED
|
@@ -37,6 +37,57 @@ export declare function pascalCase(text: string, { prefix, suffix }?: Options$1)
|
|
|
37
37
|
* ```
|
|
38
38
|
*/
|
|
39
39
|
type PossiblePromise<T> = Promise<T> | T;
|
|
40
|
+
type Store<TKey, TValue> = {
|
|
41
|
+
has(key: TKey): boolean;
|
|
42
|
+
get(key: TKey): TValue | undefined;
|
|
43
|
+
set(key: TKey, value: TValue): unknown;
|
|
44
|
+
};
|
|
45
|
+
/**
|
|
46
|
+
* Returns the value cached under `key` in `store`, computing and storing it on the first call.
|
|
47
|
+
* Pass a `WeakMap` for object keys, so an entry goes away with its key, or a `Map` for primitive
|
|
48
|
+
* keys. A cached `null` or `undefined` counts as a hit, so `compute` runs once per key.
|
|
49
|
+
*
|
|
50
|
+
* @example
|
|
51
|
+
* `const refs = memo(refCache, node, () => collectRefs(node))`
|
|
52
|
+
*/
|
|
53
|
+
declare function memo$1<TKey, TValue>(store: Store<TKey, TValue>, key: TKey, compute: () => TValue): TValue;
|
|
54
|
+
declare namespace memo$1 {
|
|
55
|
+
export { createStore as create };
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Creates a store for `memo`. With no options it is a `Map`. Each option changes one thing:
|
|
59
|
+
*
|
|
60
|
+
* - `weak` holds the keys weakly, in a `WeakMap`, so an entry goes away with its key.
|
|
61
|
+
* - `max` bounds the store: it empties itself before the entry that would pass `max`, which keeps a
|
|
62
|
+
* cache in a long-running process from growing without end. `max: 1` keeps only the last entry.
|
|
63
|
+
*
|
|
64
|
+
* @example
|
|
65
|
+
* `const patterns = memo.create<string, RegExp>()`
|
|
66
|
+
*
|
|
67
|
+
* @example Freed with its key
|
|
68
|
+
* `const refs = memo.create<SchemaNode, Array<string>>({ weak: true })`
|
|
69
|
+
*
|
|
70
|
+
* @example Bounded
|
|
71
|
+
* `const names = memo.create<string, string>({ max: 100_000 })`
|
|
72
|
+
*
|
|
73
|
+
* @example Many values per key
|
|
74
|
+
* ```ts
|
|
75
|
+
* const filesByPlugin = memo.create<string, Array<string>>()
|
|
76
|
+
* memo(filesByPlugin, 'plugin-ts', () => []).push('models.ts')
|
|
77
|
+
* ```
|
|
78
|
+
*/
|
|
79
|
+
declare function createStore<TKey, TValue>(options?: {
|
|
80
|
+
weak?: false;
|
|
81
|
+
max?: undefined;
|
|
82
|
+
}): Map<TKey, TValue>;
|
|
83
|
+
declare function createStore<TKey extends WeakKey, TValue>(options: {
|
|
84
|
+
weak: true;
|
|
85
|
+
max?: undefined;
|
|
86
|
+
}): WeakMap<TKey, TValue>;
|
|
87
|
+
declare function createStore<TKey, TValue>(options: {
|
|
88
|
+
max: number;
|
|
89
|
+
weak?: false;
|
|
90
|
+
}): Store<TKey, TValue>;
|
|
40
91
|
/** A union of known literals that still accepts any other value of `Base`, without collapsing
|
|
41
92
|
* the literals away. Editors keep autocompleting the known members while arbitrary strings stay
|
|
42
93
|
* assignable.
|
|
@@ -923,6 +974,7 @@ type Memo = <TKey extends MemoKey, TValue extends MemoValue<TKey>>(key: TKey, co
|
|
|
923
974
|
type Options = {
|
|
924
975
|
hooks: Hookable<KubbHooks>;
|
|
925
976
|
signal?: AbortSignal;
|
|
977
|
+
fileRefs?: Array<string>;
|
|
926
978
|
/**
|
|
927
979
|
* Passed to `fileManager.write` so files the output passes already normalized are left alone.
|
|
928
980
|
*/
|
|
@@ -3250,9 +3302,13 @@ type Adapter<TOptions extends AdapterFactoryOptions = AdapterFactoryOptions> = {
|
|
|
3250
3302
|
* every ref node pointing at a renamed schema, so `ast.ref.getName` and `resolver.imports`
|
|
3251
3303
|
* resolve a `$ref` to the file that is actually generated. Refs that keep their pointer's
|
|
3252
3304
|
* last segment need no stamp.
|
|
3305
|
+
*
|
|
3306
|
+
* With `fileRefs`, a `$ref` may only read local files inside those folders, for a host that does
|
|
3307
|
+
* not trust the spec. An empty list allows none. Unset, a `$ref` reads any file.
|
|
3253
3308
|
*/
|
|
3254
3309
|
parse: (source: AdapterSource, options?: {
|
|
3255
3310
|
signal?: AbortSignal;
|
|
3311
|
+
fileRefs?: Array<string>;
|
|
3256
3312
|
}) => PossiblePromise<InputNode>;
|
|
3257
3313
|
/**
|
|
3258
3314
|
* Validate the document at the given path or URL.
|
|
@@ -3344,8 +3400,20 @@ export declare function setMacros(macros: ReadonlyArray<Macro>): void;
|
|
|
3344
3400
|
export declare function injectFile(file: UserFileNode): void;
|
|
3345
3401
|
/**
|
|
3346
3402
|
* Returns a value computed once per build and shared by every plugin, like `ctx.memo`.
|
|
3403
|
+
*
|
|
3404
|
+
* Pass a store first to cache in it instead, with no build needed: a `Map` or `WeakMap`, or one
|
|
3405
|
+
* from `memo.create`.
|
|
3406
|
+
*
|
|
3407
|
+
* @example Once per build
|
|
3408
|
+
* `const names = memo('myPlugin:names', () => collectNames(schemas))`
|
|
3409
|
+
*
|
|
3410
|
+
* @example In your own store
|
|
3411
|
+
* ```ts
|
|
3412
|
+
* const cache = memo.create<ast.SchemaNode, Array<string>>({ weak: true })
|
|
3413
|
+
* const refs = memo(cache, node, () => collectRefs(node))
|
|
3414
|
+
* ```
|
|
3347
3415
|
*/
|
|
3348
|
-
export declare const memo: Memo;
|
|
3416
|
+
export declare const memo: Memo & typeof memo$1;
|
|
3349
3417
|
/**
|
|
3350
3418
|
* Returns the options the user passed to the plugin being set up, like `ctx.options`.
|
|
3351
3419
|
*/
|
|
@@ -3398,6 +3466,10 @@ type CreateKubbOptions = {
|
|
|
3398
3466
|
* Stops the build at the next safe checkpoint.
|
|
3399
3467
|
*/
|
|
3400
3468
|
signal?: AbortSignal;
|
|
3469
|
+
/**
|
|
3470
|
+
* The only folders a `$ref` in the input may read local files from. Unset, a `$ref` reads any file.
|
|
3471
|
+
*/
|
|
3472
|
+
fileRefs?: Array<string>;
|
|
3401
3473
|
};
|
|
3402
3474
|
type ConfigGenerateResult = GenerateResult & {
|
|
3403
3475
|
kubb: Kubb$1;
|
|
@@ -3628,7 +3700,7 @@ export declare function createResolver<T extends PluginType>(options: ResolverOp
|
|
|
3628
3700
|
/**
|
|
3629
3701
|
* Fetches one commit of a git repository into a temporary directory with a shallow `git fetch`,
|
|
3630
3702
|
* so any host and the user's own git credentials work, and relative `$ref` files resolve.
|
|
3631
|
-
* Resolves to the spec path on disk and a `dispose` that deletes the checkout.
|
|
3703
|
+
* Resolves to the spec path on disk, the checkout `dir`, and a `dispose` that deletes the checkout.
|
|
3632
3704
|
*
|
|
3633
3705
|
* With `publicOnly`, the repository must be an https URL on public addresses, the fetch connects to
|
|
3634
3706
|
* the addresses checked, and it does not follow a redirect. `authorization` adds that header to this
|
|
@@ -3639,6 +3711,7 @@ export declare function checkoutGitInput(input: string, signal?: AbortSignal, {
|
|
|
3639
3711
|
authorization?: string;
|
|
3640
3712
|
}): Promise<{
|
|
3641
3713
|
path: string;
|
|
3714
|
+
dir: string;
|
|
3642
3715
|
dispose: () => Promise<void>;
|
|
3643
3716
|
}>;
|
|
3644
3717
|
/**
|
package/dist/index.js
CHANGED
|
@@ -21,7 +21,65 @@ var __name = (target, value) => __defProp(target, "name", {
|
|
|
21
21
|
configurable: true
|
|
22
22
|
});
|
|
23
23
|
// package.json
|
|
24
|
-
var version = "5.
|
|
24
|
+
var version = "5.19.1";
|
|
25
|
+
// ../../internals/utils/src/promise.ts
|
|
26
|
+
/**
|
|
27
|
+
* Returns the value cached under `key` in `store`, computing and storing it on the first call.
|
|
28
|
+
* Pass a `WeakMap` for object keys, so an entry goes away with its key, or a `Map` for primitive
|
|
29
|
+
* keys. A cached `null` or `undefined` counts as a hit, so `compute` runs once per key.
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* `const refs = memo(refCache, node, () => collectRefs(node))`
|
|
33
|
+
*/
|
|
34
|
+
function memo$1(store, key, compute) {
|
|
35
|
+
const cached = store.get(key);
|
|
36
|
+
if (cached !== void 0 || store.has(key)) return cached;
|
|
37
|
+
const value = compute();
|
|
38
|
+
store.set(key, value);
|
|
39
|
+
return value;
|
|
40
|
+
}
|
|
41
|
+
__name(memo$1, "memo");
|
|
42
|
+
function createStore({ weak, max } = {}) {
|
|
43
|
+
if (weak) return /* @__PURE__ */ new WeakMap();
|
|
44
|
+
const entry = /* @__PURE__ */ new Map();
|
|
45
|
+
if (max === void 0) return entry;
|
|
46
|
+
const set = (key, value) => {
|
|
47
|
+
if (entry.size >= max) entry.clear();
|
|
48
|
+
entry.set(key, value);
|
|
49
|
+
};
|
|
50
|
+
if (max !== 1) return {
|
|
51
|
+
has: (key) => entry.has(key),
|
|
52
|
+
get: (key) => entry.get(key),
|
|
53
|
+
set
|
|
54
|
+
};
|
|
55
|
+
const touch = (key) => {
|
|
56
|
+
if (!entry.has(key)) return false;
|
|
57
|
+
set(key, entry.get(key));
|
|
58
|
+
return true;
|
|
59
|
+
};
|
|
60
|
+
return {
|
|
61
|
+
has: touch,
|
|
62
|
+
get: (key) => touch(key) ? entry.get(key) : void 0,
|
|
63
|
+
set
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
memo$1.create = createStore;
|
|
67
|
+
/**
|
|
68
|
+
* Runs `run` over every item with at most `limit` in flight. Workers share one iterator, so each
|
|
69
|
+
* takes the next item the moment it frees up instead of waiting for a batch to drain.
|
|
70
|
+
*
|
|
71
|
+
* @example
|
|
72
|
+
* ```ts
|
|
73
|
+
* await inParallel({ items: files, limit: 50, run: (file) => storage.writeItem(file.path, file.source) })
|
|
74
|
+
* ```
|
|
75
|
+
*/
|
|
76
|
+
async function inParallel({ items, limit, run }) {
|
|
77
|
+
const queue = items.entries();
|
|
78
|
+
const worker = async () => {
|
|
79
|
+
for (const [index, item] of queue) await run(item, index);
|
|
80
|
+
};
|
|
81
|
+
await Promise.all(Array.from({ length: Math.min(limit, items.length) }, () => worker()));
|
|
82
|
+
}
|
|
25
83
|
// ../../internals/utils/src/casing.ts
|
|
26
84
|
/**
|
|
27
85
|
* Shared implementation for camelCase and PascalCase conversion.
|
|
@@ -36,16 +94,10 @@ function convert(text, pascal) {
|
|
|
36
94
|
return (i === 0 && !pascal ? word.charAt(0).toLowerCase() : word.charAt(0).toUpperCase()) + word.slice(1);
|
|
37
95
|
}).join("").replace(/[^a-zA-Z0-9]/g, "");
|
|
38
96
|
}
|
|
39
|
-
const cache =
|
|
40
|
-
const cacheLimit = 1e5;
|
|
97
|
+
const cache = memo$1.create({ max: 1e5 });
|
|
41
98
|
function toCamelOrPascal(text, pascal) {
|
|
42
99
|
const key = `${pascal ? "P" : "c"}${text}`;
|
|
43
|
-
|
|
44
|
-
if (cached !== void 0) return cached;
|
|
45
|
-
const result = convert(text, pascal);
|
|
46
|
-
if (cache.size >= cacheLimit) cache.clear();
|
|
47
|
-
cache.set(key, result);
|
|
48
|
-
return result;
|
|
100
|
+
return memo$1(cache, key, () => convert(text, pascal));
|
|
49
101
|
}
|
|
50
102
|
/**
|
|
51
103
|
* Converts `text` to camelCase.
|
|
@@ -342,59 +394,6 @@ function isPathInside(path, parent) {
|
|
|
342
394
|
const rel = relative(resolvedParent, resolvedPath);
|
|
343
395
|
return rel !== "" && !rel.startsWith("..") && !isAbsolute(rel);
|
|
344
396
|
}
|
|
345
|
-
// ../../internals/utils/src/promise.ts
|
|
346
|
-
/**
|
|
347
|
-
* Returns the value cached under `key` in `store`, computing and storing it on the first call.
|
|
348
|
-
* Pass a `WeakMap` for object keys, so an entry goes away with its key, or a `Map` for primitive
|
|
349
|
-
* keys. A cached `null` or `undefined` counts as a hit, so `compute` runs once per key.
|
|
350
|
-
*
|
|
351
|
-
* @example
|
|
352
|
-
* `const refs = memo(refCache, node, () => collectRefs(node))`
|
|
353
|
-
*/
|
|
354
|
-
function memo$1(store, key, compute) {
|
|
355
|
-
const cached = store.get(key);
|
|
356
|
-
if (cached !== void 0 || store.has(key)) return cached;
|
|
357
|
-
const value = compute();
|
|
358
|
-
store.set(key, value);
|
|
359
|
-
return value;
|
|
360
|
-
}
|
|
361
|
-
__name(memo$1, "memo");
|
|
362
|
-
function createStore({ type }) {
|
|
363
|
-
if (type === "weak") return /* @__PURE__ */ new WeakMap();
|
|
364
|
-
const entry = /* @__PURE__ */ new Map();
|
|
365
|
-
if (type === "map") return entry;
|
|
366
|
-
const set = (key, value) => {
|
|
367
|
-
entry.clear();
|
|
368
|
-
entry.set(key, value);
|
|
369
|
-
};
|
|
370
|
-
const touch = (key) => {
|
|
371
|
-
if (!entry.has(key)) return false;
|
|
372
|
-
set(key, entry.get(key));
|
|
373
|
-
return true;
|
|
374
|
-
};
|
|
375
|
-
return {
|
|
376
|
-
has: touch,
|
|
377
|
-
get: (key) => touch(key) ? entry.get(key) : void 0,
|
|
378
|
-
set
|
|
379
|
-
};
|
|
380
|
-
}
|
|
381
|
-
memo$1.create = createStore;
|
|
382
|
-
/**
|
|
383
|
-
* Runs `run` over every item with at most `limit` in flight. Workers share one iterator, so each
|
|
384
|
-
* takes the next item the moment it frees up instead of waiting for a batch to drain.
|
|
385
|
-
*
|
|
386
|
-
* @example
|
|
387
|
-
* ```ts
|
|
388
|
-
* await inParallel({ items: files, limit: 50, run: (file) => storage.writeItem(file.path, file.source) })
|
|
389
|
-
* ```
|
|
390
|
-
*/
|
|
391
|
-
async function inParallel({ items, limit, run }) {
|
|
392
|
-
const queue = items.entries();
|
|
393
|
-
const worker = async () => {
|
|
394
|
-
for (const [index, item] of queue) await run(item, index);
|
|
395
|
-
};
|
|
396
|
-
await Promise.all(Array.from({ length: Math.min(limit, items.length) }, () => worker()));
|
|
397
|
-
}
|
|
398
397
|
// ../../internals/utils/src/tools.ts
|
|
399
398
|
/**
|
|
400
399
|
* CLI command descriptors for each supported code formatter.
|
|
@@ -1394,8 +1393,20 @@ function injectFile(file) {
|
|
|
1394
1393
|
}
|
|
1395
1394
|
/**
|
|
1396
1395
|
* Returns a value computed once per build and shared by every plugin, like `ctx.memo`.
|
|
1396
|
+
*
|
|
1397
|
+
* Pass a store first to cache in it instead, with no build needed: a `Map` or `WeakMap`, or one
|
|
1398
|
+
* from `memo.create`.
|
|
1399
|
+
*
|
|
1400
|
+
* @example Once per build
|
|
1401
|
+
* `const names = memo('myPlugin:names', () => collectNames(schemas))`
|
|
1402
|
+
*
|
|
1403
|
+
* @example In your own store
|
|
1404
|
+
* ```ts
|
|
1405
|
+
* const cache = memo.create<ast.SchemaNode, Array<string>>({ weak: true })
|
|
1406
|
+
* const refs = memo(cache, node, () => collectRefs(node))
|
|
1407
|
+
* ```
|
|
1397
1408
|
*/
|
|
1398
|
-
const memo = (
|
|
1409
|
+
const memo = Object.assign((...args) => args.length === 3 ? memo$1(...args) : requireContext("memo").memo(...args), { create: memo$1.create });
|
|
1399
1410
|
/**
|
|
1400
1411
|
* Returns the options the user passed to the plugin being set up, like `ctx.options`.
|
|
1401
1412
|
*/
|
|
@@ -1599,7 +1610,7 @@ function gitAuthEnv(env, { repo, authorization }) {
|
|
|
1599
1610
|
/**
|
|
1600
1611
|
* Fetches one commit of a git repository into a temporary directory with a shallow `git fetch`,
|
|
1601
1612
|
* so any host and the user's own git credentials work, and relative `$ref` files resolve.
|
|
1602
|
-
* Resolves to the spec path on disk and a `dispose` that deletes the checkout.
|
|
1613
|
+
* Resolves to the spec path on disk, the checkout `dir`, and a `dispose` that deletes the checkout.
|
|
1603
1614
|
*
|
|
1604
1615
|
* With `publicOnly`, the repository must be an https URL on public addresses, the fetch connects to
|
|
1605
1616
|
* the addresses checked, and it does not follow a redirect. `authorization` adds that header to this
|
|
@@ -1674,6 +1685,7 @@ async function checkoutGitInput(input, signal, { publicOnly = false, authorizati
|
|
|
1674
1685
|
}
|
|
1675
1686
|
return {
|
|
1676
1687
|
path: specPath,
|
|
1688
|
+
dir,
|
|
1677
1689
|
dispose
|
|
1678
1690
|
};
|
|
1679
1691
|
}
|
|
@@ -1756,9 +1768,9 @@ function inputToAdapterSource(config) {
|
|
|
1756
1768
|
};
|
|
1757
1769
|
}
|
|
1758
1770
|
// src/resolveOptions.ts
|
|
1759
|
-
const patterns =
|
|
1760
|
-
const methodPatterns =
|
|
1761
|
-
const nodeCaches =
|
|
1771
|
+
const patterns = memo$1.create();
|
|
1772
|
+
const methodPatterns = memo$1.create();
|
|
1773
|
+
const nodeCaches = memo$1.create({ weak: true });
|
|
1762
1774
|
function testPattern(value, pattern) {
|
|
1763
1775
|
if (typeof pattern === "string") return memo$1(patterns, pattern, () => new RegExp(pattern)).test(value);
|
|
1764
1776
|
return value.match(pattern) !== null;
|
|
@@ -1889,12 +1901,12 @@ var Resolver = class Resolver {
|
|
|
1889
1901
|
/** The built-in machinery, untouched by `name`/`file` overrides and built once since the driver reads it per node. */
|
|
1890
1902
|
default;
|
|
1891
1903
|
#options;
|
|
1892
|
-
#memo =
|
|
1904
|
+
#memo = memo$1.create();
|
|
1893
1905
|
#usedNames = /* @__PURE__ */ new Set();
|
|
1894
|
-
#stringNames =
|
|
1906
|
+
#stringNames = memo$1.create();
|
|
1895
1907
|
#arrayNames = createNameNode();
|
|
1896
|
-
#outputDirs =
|
|
1897
|
-
#importPaths =
|
|
1908
|
+
#outputDirs = memo$1.create({ weak: true });
|
|
1909
|
+
#importPaths = memo$1.create({ weak: true });
|
|
1898
1910
|
#tagParents = /* @__PURE__ */ new Map();
|
|
1899
1911
|
#baseName;
|
|
1900
1912
|
#filePath;
|
|
@@ -2701,7 +2713,7 @@ var KubbDriver = class {
|
|
|
2701
2713
|
*/
|
|
2702
2714
|
fileManager = new FileManager();
|
|
2703
2715
|
plugins = /* @__PURE__ */ new Map();
|
|
2704
|
-
#memo =
|
|
2716
|
+
#memo = memo$1.create();
|
|
2705
2717
|
/**
|
|
2706
2718
|
* Removers for every listener the driver added (plugin, generator) so `dispose()` can detach
|
|
2707
2719
|
* them in one pass. External `hooks.hook(...)` listeners are not tracked.
|
|
@@ -2805,7 +2817,10 @@ var KubbDriver = class {
|
|
|
2805
2817
|
this.inputNode = await this.adapter.parse(checkout ? {
|
|
2806
2818
|
type: "path",
|
|
2807
2819
|
path: checkout.path
|
|
2808
|
-
} : source, {
|
|
2820
|
+
} : source, {
|
|
2821
|
+
signal: this.options.signal,
|
|
2822
|
+
fileRefs: checkout && this.options.fileRefs ? [...this.options.fileRefs, checkout.dir] : this.options.fileRefs
|
|
2823
|
+
});
|
|
2809
2824
|
} catch (caughtError) {
|
|
2810
2825
|
throw new Diagnostics.Error(Diagnostics.fromExtension(caughtError, {
|
|
2811
2826
|
kind: "adapter",
|
|
@@ -3543,7 +3558,7 @@ const cacheStorage = createStorage(({ root = process.cwd() }) => {
|
|
|
3543
3558
|
* ```
|
|
3544
3559
|
*/
|
|
3545
3560
|
var Hookable = class {
|
|
3546
|
-
#listeners =
|
|
3561
|
+
#listeners = memo$1.create();
|
|
3547
3562
|
/**
|
|
3548
3563
|
* Calls `hookName` and awaits all registered listeners sequentially.
|
|
3549
3564
|
* Throws if any listener rejects, wrapping the cause in an error that names the hook.
|
|
@@ -3575,9 +3590,7 @@ var Hookable = class {
|
|
|
3575
3590
|
* ```
|
|
3576
3591
|
*/
|
|
3577
3592
|
hook(hookName, handler) {
|
|
3578
|
-
|
|
3579
|
-
if (!listeners) this.#listeners.set(hookName, listeners = /* @__PURE__ */ new Set());
|
|
3580
|
-
listeners.add(handler);
|
|
3593
|
+
memo$1(this.#listeners, hookName, () => /* @__PURE__ */ new Set()).add(handler);
|
|
3581
3594
|
return () => this.removeHook(hookName, handler);
|
|
3582
3595
|
}
|
|
3583
3596
|
/**
|
|
@@ -3876,10 +3889,12 @@ var Kubb = class Kubb {
|
|
|
3876
3889
|
#driver = null;
|
|
3877
3890
|
#manifest = null;
|
|
3878
3891
|
#signal;
|
|
3892
|
+
#fileRefs;
|
|
3879
3893
|
constructor(userConfig, options = {}) {
|
|
3880
3894
|
this.config = resolveConfig(userConfig);
|
|
3881
3895
|
this.hooks = options.hooks ?? new Hookable();
|
|
3882
3896
|
this.#signal = options.signal;
|
|
3897
|
+
this.#fileRefs = options.fileRefs;
|
|
3883
3898
|
}
|
|
3884
3899
|
/**
|
|
3885
3900
|
* Generates every config of a `defineConfig([...])` array in order and yields each result as its config finishes, so
|
|
@@ -3943,7 +3958,8 @@ var Kubb = class Kubb {
|
|
|
3943
3958
|
hooks: this.hooks,
|
|
3944
3959
|
manifest,
|
|
3945
3960
|
signal,
|
|
3946
|
-
cleanPath
|
|
3961
|
+
cleanPath,
|
|
3962
|
+
fileRefs: this.#fileRefs
|
|
3947
3963
|
});
|
|
3948
3964
|
await driver.setup();
|
|
3949
3965
|
this.#driver = driver;
|