@ucdjs-internal/shared 0.1.1-beta.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/LICENSE +21 -0
- package/README.md +78 -0
- package/dist/index.d.mts +403 -0
- package/dist/index.mjs +914 -0
- package/package.json +64 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025-PRESENT Lucas Nørgård
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
# @ucdjs-internal/shared
|
|
2
|
+
|
|
3
|
+
[![npm version][npm-version-src]][npm-version-href]
|
|
4
|
+
[![npm downloads][npm-downloads-src]][npm-downloads-href]
|
|
5
|
+
[![codecov][codecov-src]][codecov-href]
|
|
6
|
+
|
|
7
|
+
> [!IMPORTANT]
|
|
8
|
+
> This is an internal package. It may change without warning and is not subject to semantic versioning. Use at your own risk.
|
|
9
|
+
|
|
10
|
+
A collection of utility functions and filesystem bridge implementations for the UCD project.
|
|
11
|
+
|
|
12
|
+
## Installation
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
npm install @ucdjs-internal/shared
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
## Usage
|
|
19
|
+
|
|
20
|
+
### Path Filtering
|
|
21
|
+
|
|
22
|
+
Creates a filter function that checks if a file path should be included or excluded based on glob patterns.
|
|
23
|
+
|
|
24
|
+
```typescript
|
|
25
|
+
import { createPathFilter } from "@ucdjs-internal/shared";
|
|
26
|
+
|
|
27
|
+
const filter = createPathFilter(["*.txt", "!*Test*"]);
|
|
28
|
+
filter("Data.txt"); // true
|
|
29
|
+
filter("DataTest.txt"); // false
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
#### PathFilter Methods
|
|
33
|
+
|
|
34
|
+
The `PathFilter` object provides additional methods:
|
|
35
|
+
|
|
36
|
+
```typescript
|
|
37
|
+
const filter = createPathFilter(["*.js"]);
|
|
38
|
+
|
|
39
|
+
// Extend with additional patterns
|
|
40
|
+
filter.extend(["*.ts", "!*.test.*"]);
|
|
41
|
+
|
|
42
|
+
// Get current patterns
|
|
43
|
+
const patterns = filter.patterns(); // ['*.js', '*.ts', '!*.test.*']
|
|
44
|
+
|
|
45
|
+
// Use with extra filters temporarily
|
|
46
|
+
filter("app.js", ["!src/**"]); // Apply extra exclusions
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
### Preconfigured Filters
|
|
50
|
+
|
|
51
|
+
Pre-defined filter patterns for common exclusions:
|
|
52
|
+
|
|
53
|
+
```typescript
|
|
54
|
+
import { createPathFilter, PRECONFIGURED_FILTERS } from "@ucdjs-internal/shared";
|
|
55
|
+
|
|
56
|
+
const filter = createPathFilter([
|
|
57
|
+
"*.txt",
|
|
58
|
+
PRECONFIGURED_FILTERS.EXCLUDE_TEST_FILES,
|
|
59
|
+
PRECONFIGURED_FILTERS.EXCLUDE_README_FILES,
|
|
60
|
+
PRECONFIGURED_FILTERS.EXCLUDE_HTML_FILES
|
|
61
|
+
]);
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
Available filters:
|
|
65
|
+
- `EXCLUDE_TEST_FILES`: Excludes files containing "Test" in their name
|
|
66
|
+
- `EXCLUDE_README_FILES`: Excludes ReadMe.txt files
|
|
67
|
+
- `EXCLUDE_HTML_FILES`: Excludes all HTML files
|
|
68
|
+
|
|
69
|
+
## 📄 License
|
|
70
|
+
|
|
71
|
+
Published under [MIT License](./LICENSE).
|
|
72
|
+
|
|
73
|
+
[npm-version-src]: https://img.shields.io/npm/v/@ucdjs-internal/shared?style=flat&colorA=18181B&colorB=4169E1
|
|
74
|
+
[npm-version-href]: https://npmjs.com/package/@ucdjs-internal/shared
|
|
75
|
+
[npm-downloads-src]: https://img.shields.io/npm/dm/@ucdjs-internal/shared?style=flat&colorA=18181B&colorB=4169E1
|
|
76
|
+
[npm-downloads-href]: https://npmjs.com/package/@ucdjs-internal/shared
|
|
77
|
+
[codecov-src]: https://img.shields.io/codecov/c/gh/ucdjs/ucd?style=flat&colorA=18181B&colorB=4169E1
|
|
78
|
+
[codecov-href]: https://codecov.io/gh/ucdjs/ucd
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,403 @@
|
|
|
1
|
+
import { Debugger } from "obug";
|
|
2
|
+
import { PicomatchOptions } from "picomatch";
|
|
3
|
+
import { ApiError, UCDWellKnownConfig, UnicodeFileTreeNodeWithoutLastModified } from "@ucdjs/schemas";
|
|
4
|
+
import { ZodType } from "zod";
|
|
5
|
+
|
|
6
|
+
//#region src/async/promise-concurrency.d.ts
|
|
7
|
+
type ConcurrencyLimitFn = <Args extends unknown[], T>(fn: (...args: Args) => PromiseLike<T> | T, ...args: Args) => Promise<T>;
|
|
8
|
+
declare function ensureIsPositiveConcurrency(concurrency: unknown, ErrorClazz: new (message: string) => Error): void;
|
|
9
|
+
/**
|
|
10
|
+
* Creates a concurrency limiter that restricts the number of concurrent executions.
|
|
11
|
+
*
|
|
12
|
+
* @param {number} concurrency - The maximum number of concurrent executions allowed.
|
|
13
|
+
* @returns {} A function that wraps any function to enforce the concurrency limit
|
|
14
|
+
* @throws {Error} When concurrency is not a positive integer
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```typescript
|
|
18
|
+
* import { createConcurrencyLimiter } from "@ucdjs-internal/shared";
|
|
19
|
+
*
|
|
20
|
+
* const limiter = createConcurrencyLimiter(2);
|
|
21
|
+
*
|
|
22
|
+
* // Only 2 of these will run concurrently
|
|
23
|
+
* const results = await Promise.all([
|
|
24
|
+
* limiter(fetchData, "url1"),
|
|
25
|
+
* limiter(fetchData, "url2"),
|
|
26
|
+
* limiter(fetchData, "url3"),
|
|
27
|
+
* limiter(fetchData, "url4")
|
|
28
|
+
* ]);
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
declare function createConcurrencyLimiter(concurrency: number): ConcurrencyLimitFn;
|
|
32
|
+
//#endregion
|
|
33
|
+
//#region src/async/try-catch.d.ts
|
|
34
|
+
type OperationSuccess<T> = readonly [data: T, error: null];
|
|
35
|
+
type OperationFailure<E> = readonly [data: null, error: E];
|
|
36
|
+
type OperationResult<T, E> = OperationSuccess<T> | OperationFailure<E>;
|
|
37
|
+
declare function wrapTry<T, E = Error>(operation: Promise<T>): Promise<OperationResult<T, E>>;
|
|
38
|
+
declare function wrapTry<_T, E = Error>(operation: () => never): OperationResult<never, E>;
|
|
39
|
+
declare function wrapTry<T, E = Error>(operation: () => Promise<T>): Promise<OperationResult<T, E>>;
|
|
40
|
+
declare function wrapTry<T, E = Error>(operation: () => T): OperationResult<T, E>;
|
|
41
|
+
type InferErrorType<TTry, TErr> = TErr extends readonly never[] ? TTry extends readonly (infer E)[] ? E[] : TTry extends (infer E)[] ? E[] : TErr : TErr extends readonly [] ? TTry extends readonly (infer E)[] ? E[] : TTry extends (infer E)[] ? E[] : TErr : TErr;
|
|
42
|
+
declare function tryOr<TTry, TErr = TTry>(config: {
|
|
43
|
+
try: Promise<TTry>;
|
|
44
|
+
err: (error: unknown) => Promise<TErr>;
|
|
45
|
+
}): Promise<TTry | InferErrorType<TTry, TErr>>;
|
|
46
|
+
declare function tryOr<TTry, TErr = TTry>(config: {
|
|
47
|
+
try: Promise<TTry>;
|
|
48
|
+
err: (error: unknown) => TErr;
|
|
49
|
+
}): Promise<TTry | InferErrorType<TTry, TErr>>;
|
|
50
|
+
declare function tryOr<TTry, TErr = TTry>(config: {
|
|
51
|
+
try: () => Promise<TTry>;
|
|
52
|
+
err: (error: unknown) => Promise<TErr>;
|
|
53
|
+
}): Promise<TTry | InferErrorType<TTry, TErr>>;
|
|
54
|
+
declare function tryOr<TTry, TErr = TTry>(config: {
|
|
55
|
+
try: () => Promise<TTry>;
|
|
56
|
+
err: (error: unknown) => TErr;
|
|
57
|
+
}): Promise<TTry | InferErrorType<TTry, TErr>>;
|
|
58
|
+
declare function tryOr<TTry, TErr = TTry>(config: {
|
|
59
|
+
try: () => TTry;
|
|
60
|
+
err: (error: unknown) => Promise<TErr>;
|
|
61
|
+
}): Promise<TTry | InferErrorType<TTry, TErr>>;
|
|
62
|
+
declare function tryOr<TTry, TErr = TTry>(config: {
|
|
63
|
+
try: () => TTry;
|
|
64
|
+
err: (error: unknown) => TErr;
|
|
65
|
+
}): TTry | InferErrorType<TTry, TErr>;
|
|
66
|
+
//#endregion
|
|
67
|
+
//#region src/debugger.d.ts
|
|
68
|
+
declare function createDebugger(namespace: `ucdjs:${string}`): Debugger | undefined;
|
|
69
|
+
//#endregion
|
|
70
|
+
//#region src/fetch/error.d.ts
|
|
71
|
+
declare class FetchError<T = any> extends Error {
|
|
72
|
+
readonly request?: RequestInfo;
|
|
73
|
+
readonly options?: FetchOptions;
|
|
74
|
+
readonly response?: FetchResponse<T>;
|
|
75
|
+
readonly data?: T;
|
|
76
|
+
readonly status?: number;
|
|
77
|
+
readonly statusText?: string;
|
|
78
|
+
constructor(message: string, opts?: {
|
|
79
|
+
cause: unknown;
|
|
80
|
+
});
|
|
81
|
+
static from<T = any, R extends ResponseType = ResponseType>(ctx: FetchContext<T, R>): FetchError<T>;
|
|
82
|
+
}
|
|
83
|
+
declare class FetchSchemaValidationError<T = any> extends FetchError<T> {
|
|
84
|
+
readonly issues?: unknown;
|
|
85
|
+
constructor(message: string, opts?: {
|
|
86
|
+
cause: unknown;
|
|
87
|
+
issues?: unknown;
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
//#endregion
|
|
91
|
+
//#region src/fetch/types.d.ts
|
|
92
|
+
interface CustomFetch {
|
|
93
|
+
<T = any, R extends ResponseType = "json">(request: RequestInfo, options?: FetchOptions<R, T>): Promise<FetchResponse<MappedResponseType<R, T>>>;
|
|
94
|
+
safe: <T = any, R extends ResponseType = "json">(request: RequestInfo, options?: FetchOptions<R, T>) => Promise<SafeFetchResponse<MappedResponseType<R, T>>>;
|
|
95
|
+
}
|
|
96
|
+
interface ResponseMap {
|
|
97
|
+
blob: Blob;
|
|
98
|
+
text: string;
|
|
99
|
+
arrayBuffer: ArrayBuffer;
|
|
100
|
+
stream: ReadableStream<Uint8Array>;
|
|
101
|
+
}
|
|
102
|
+
type ResponseType = keyof ResponseMap | "json";
|
|
103
|
+
type MappedResponseType<R extends ResponseType, JsonType = any> = R extends keyof ResponseMap ? ResponseMap[R] : JsonType;
|
|
104
|
+
interface SafeFetchResponse<T = any> {
|
|
105
|
+
data: T | null;
|
|
106
|
+
error: FetchError<T> | FetchSchemaValidationError<T> | null;
|
|
107
|
+
response?: FetchResponse<T>;
|
|
108
|
+
}
|
|
109
|
+
interface FetchResponse<T> extends Response {
|
|
110
|
+
data?: T;
|
|
111
|
+
}
|
|
112
|
+
interface FetchOptions<R extends ResponseType = ResponseType, T = any> extends Omit<RequestInit, "body"> {
|
|
113
|
+
body?: RequestInit["body"] | Record<string, any>;
|
|
114
|
+
parseAs?: R;
|
|
115
|
+
/**
|
|
116
|
+
* Zod schema to validate the response data against.
|
|
117
|
+
* If validation fails, an error will be returned/thrown.
|
|
118
|
+
*
|
|
119
|
+
* TODO(@luxass): figure out how we can hide the true value of
|
|
120
|
+
* `schema` from the user. Since it is very large, it can be
|
|
121
|
+
* confusing to see it in error messages.
|
|
122
|
+
*/
|
|
123
|
+
schema?: ZodType<T>;
|
|
124
|
+
/**
|
|
125
|
+
* @experimental Set to "half" to enable duplex streaming.
|
|
126
|
+
* Will be automatically set to "half" when using a ReadableStream as body.
|
|
127
|
+
* @see https://fetch.spec.whatwg.org/#enumdef-requestduplex
|
|
128
|
+
*/
|
|
129
|
+
duplex?: "half" | undefined;
|
|
130
|
+
/** timeout in milliseconds */
|
|
131
|
+
timeout?: number;
|
|
132
|
+
retry?: number | false;
|
|
133
|
+
/** Delay between retries in milliseconds. */
|
|
134
|
+
retryDelay?: number | ((context: FetchContext<T, R> & {
|
|
135
|
+
retryAttempt: number;
|
|
136
|
+
}) => number);
|
|
137
|
+
/** Default is [408, 409, 425, 429, 500, 502, 503, 504] */
|
|
138
|
+
retryStatusCodes?: number[];
|
|
139
|
+
}
|
|
140
|
+
interface FetchContext<T = any, R extends ResponseType = ResponseType> {
|
|
141
|
+
request: RequestInfo;
|
|
142
|
+
options: FetchOptions<R> & {
|
|
143
|
+
headers: Headers;
|
|
144
|
+
};
|
|
145
|
+
response?: FetchResponse<MappedResponseType<R, T>>;
|
|
146
|
+
error?: Error;
|
|
147
|
+
}
|
|
148
|
+
//#endregion
|
|
149
|
+
//#region src/fetch/fetch.d.ts
|
|
150
|
+
declare const customFetch: CustomFetch;
|
|
151
|
+
//#endregion
|
|
152
|
+
//#region src/files.d.ts
|
|
153
|
+
/**
|
|
154
|
+
* Normalizes an API file-tree path to a version-relative path suitable for filtering.
|
|
155
|
+
*
|
|
156
|
+
* This strips:
|
|
157
|
+
* - Leading/trailing slashes
|
|
158
|
+
* - Version prefix (e.g., "16.0.0/")
|
|
159
|
+
* - "ucd/" prefix for versions that have it
|
|
160
|
+
*
|
|
161
|
+
* @param {string} version - The Unicode version string
|
|
162
|
+
* @param {string} rawPath - The raw path from the API file tree (e.g., "/16.0.0/ucd/Blocks.txt")
|
|
163
|
+
* @returns {string} The normalized path (e.g., "Blocks.txt")
|
|
164
|
+
*
|
|
165
|
+
* @example
|
|
166
|
+
* ```typescript
|
|
167
|
+
* normalizePathForFiltering("16.0.0", "/16.0.0/ucd/Blocks.txt");
|
|
168
|
+
* // Returns: "Blocks.txt"
|
|
169
|
+
*
|
|
170
|
+
* normalizePathForFiltering("16.0.0", "/16.0.0/ucd/auxiliary/GraphemeBreakProperty.txt");
|
|
171
|
+
* // Returns: "auxiliary/GraphemeBreakProperty.txt"
|
|
172
|
+
* ```
|
|
173
|
+
*/
|
|
174
|
+
declare function normalizePathForFiltering(version: string, rawPath: string): string;
|
|
175
|
+
/**
|
|
176
|
+
* Creates a normalized view of a file tree for filtering purposes.
|
|
177
|
+
*
|
|
178
|
+
* This recursively maps all `path` properties to version-relative paths,
|
|
179
|
+
* so that filter patterns like "Blocks.txt" or "auxiliary/**" will match
|
|
180
|
+
* against paths like "/16.0.0/ucd/Blocks.txt".
|
|
181
|
+
*
|
|
182
|
+
* @template {UnicodeFileTreeNodeWithoutLastModified} T - A tree node type that extends the base TreeNode interface
|
|
183
|
+
* @param {string} version - The Unicode version string
|
|
184
|
+
* @param {T[]} entries - Array of file tree nodes from the API
|
|
185
|
+
* @returns {T[]} A new tree with normalized paths suitable for filtering
|
|
186
|
+
*
|
|
187
|
+
* @example
|
|
188
|
+
* ```typescript
|
|
189
|
+
* const apiTree = [{ type: "file", name: "Blocks.txt", path: "/16.0.0/ucd/Blocks.txt" }];
|
|
190
|
+
* const normalizedTree = normalizeTreeForFiltering("16.0.0", apiTree);
|
|
191
|
+
* // Returns: [{ type: "file", name: "Blocks.txt", path: "Blocks.txt" }]
|
|
192
|
+
* ```
|
|
193
|
+
*/
|
|
194
|
+
declare function normalizeTreeForFiltering<T extends UnicodeFileTreeNodeWithoutLastModified>(version: string, entries: T[]): T[];
|
|
195
|
+
/**
|
|
196
|
+
* Recursively find a node (file or directory) by its path in the tree.
|
|
197
|
+
*
|
|
198
|
+
* @template T - A tree node type that extends the base TreeNode interface
|
|
199
|
+
* @param {T[]} entries - Array of file tree nodes that may contain nested children
|
|
200
|
+
* @param {string} targetPath - The path to search for
|
|
201
|
+
* @returns {T | undefined} The found node or undefined
|
|
202
|
+
*/
|
|
203
|
+
declare function findFileByPath<T extends UnicodeFileTreeNodeWithoutLastModified>(entries: T[], targetPath: string): T | undefined;
|
|
204
|
+
/**
|
|
205
|
+
* Recursively flattens a hierarchical file structure into an array of file paths.
|
|
206
|
+
*
|
|
207
|
+
* @template T - A tree node type that extends the base TreeNode interface
|
|
208
|
+
* @param {T[]} entries - Array of file tree nodes that may contain nested children
|
|
209
|
+
* @param {string} [prefix] - Optional path prefix to prepend to each file path (default: "")
|
|
210
|
+
* @returns {string[]} Array of flattened file paths as strings
|
|
211
|
+
*
|
|
212
|
+
* @example
|
|
213
|
+
* ```typescript
|
|
214
|
+
* import { flattenFilePaths } from "@ucdjs-internal/shared";
|
|
215
|
+
*
|
|
216
|
+
* const files = [
|
|
217
|
+
* { type: "directory", name: "folder1", path: "/folder1", children: [{ type: "file", name: "file1.txt", path: "/folder1/file1.txt" }] },
|
|
218
|
+
* { type: "file", name: "file2.txt", path: "/file2.txt" }
|
|
219
|
+
* ];
|
|
220
|
+
* const paths = flattenFilePaths(files);
|
|
221
|
+
* // Returns: ["/folder1/file1.txt", "/file2.txt"]
|
|
222
|
+
* ```
|
|
223
|
+
*/
|
|
224
|
+
declare function flattenFilePaths<T extends UnicodeFileTreeNodeWithoutLastModified>(entries: T[], prefix?: string): string[];
|
|
225
|
+
//#endregion
|
|
226
|
+
//#region src/filter.d.ts
|
|
227
|
+
/**
|
|
228
|
+
* File extensions excluded by default in createPathFilter.
|
|
229
|
+
* These are archive and document formats that are typically not needed for Unicode data processing.
|
|
230
|
+
*/
|
|
231
|
+
declare const DEFAULT_EXCLUDED_EXTENSIONS: readonly [".zip", ".tar", ".gz", ".bz2", ".xz", ".7z", ".rar", ".pdf"];
|
|
232
|
+
/**
|
|
233
|
+
* Predefined filter patterns for common file exclusions.
|
|
234
|
+
* These constants can be used with `createPathFilter` to easily exclude common file types.
|
|
235
|
+
*
|
|
236
|
+
* @example
|
|
237
|
+
* ```ts
|
|
238
|
+
* import { createPathFilter, PRECONFIGURED_FILTERS } from '@ucdjs-internal/shared';
|
|
239
|
+
*
|
|
240
|
+
* const filter = createPathFilter({
|
|
241
|
+
* include: ['*.txt'],
|
|
242
|
+
* exclude: [
|
|
243
|
+
* ...PRECONFIGURED_FILTERS.TEST_FILES,
|
|
244
|
+
* ...PRECONFIGURED_FILTERS.README_FILES
|
|
245
|
+
* ]
|
|
246
|
+
* });
|
|
247
|
+
* ```
|
|
248
|
+
*/
|
|
249
|
+
declare const PRECONFIGURED_FILTERS: {
|
|
250
|
+
/** Excludes files containing "Test" in their name (e.g., DataTest.txt, TestFile.js) */readonly TEST_FILES: readonly ["**/*Test*"]; /** Excludes ReadMe.txt files from any directory */
|
|
251
|
+
readonly README_FILES: readonly ["**/ReadMe.txt"]; /** Excludes all HTML files */
|
|
252
|
+
readonly HTML_FILES: readonly ["**/*.html"];
|
|
253
|
+
};
|
|
254
|
+
type PathFilterFn = (path: string, extraOptions?: Pick<PathFilterOptions, "include" | "exclude">) => boolean;
|
|
255
|
+
interface PathFilter extends PathFilterFn {
|
|
256
|
+
extend: (additionalOptions: Pick<PathFilterOptions, "include" | "exclude">) => void;
|
|
257
|
+
patterns: () => Readonly<PathFilterOptions>;
|
|
258
|
+
}
|
|
259
|
+
interface PathFilterOptions {
|
|
260
|
+
/**
|
|
261
|
+
* Glob patterns for files to include.
|
|
262
|
+
* If empty or not set, includes everything using "**" pattern
|
|
263
|
+
*/
|
|
264
|
+
include?: string[];
|
|
265
|
+
/**
|
|
266
|
+
* Glob patterns for files to exclude.
|
|
267
|
+
* These override include patterns
|
|
268
|
+
*/
|
|
269
|
+
exclude?: string[];
|
|
270
|
+
/**
|
|
271
|
+
* Whether to disable default exclusions (.zip, .pdf).
|
|
272
|
+
* If true, no default exclusions will be applied.
|
|
273
|
+
*
|
|
274
|
+
* @default false
|
|
275
|
+
*/
|
|
276
|
+
disableDefaultExclusions?: boolean;
|
|
277
|
+
}
|
|
278
|
+
/**
|
|
279
|
+
* Creates a filter function that checks if a file path should be included or excluded
|
|
280
|
+
* based on the provided filter configuration.
|
|
281
|
+
*
|
|
282
|
+
* @param {PathFilterOptions} options - Configuration object with include/exclude patterns
|
|
283
|
+
* @returns {PathFilter} A function that takes a path and returns true if the path should be included, false otherwise
|
|
284
|
+
*
|
|
285
|
+
* @example
|
|
286
|
+
* ```ts
|
|
287
|
+
* import { createPathFilter, PRECONFIGURED_FILTERS } from '@ucdjs-internal/shared';
|
|
288
|
+
*
|
|
289
|
+
* // Include specific files, exclude others
|
|
290
|
+
* const filter = createPathFilter({
|
|
291
|
+
* include: ['src/**\/*.{js,ts}', 'test/**\/*.{test.js}'],
|
|
292
|
+
* exclude: ['**\/node_modules/**', '**\/*.generated.*']
|
|
293
|
+
* });
|
|
294
|
+
*
|
|
295
|
+
* // If include is empty/not set, includes everything
|
|
296
|
+
* const excludeOnly = createPathFilter({
|
|
297
|
+
* exclude: ['**\/node_modules/**', '**\/dist/**']
|
|
298
|
+
* });
|
|
299
|
+
*
|
|
300
|
+
* // Using preconfigured filters
|
|
301
|
+
* const withPresets = createPathFilter({
|
|
302
|
+
* include: ['src/**\/*.txt'],
|
|
303
|
+
* exclude: [
|
|
304
|
+
* ...PRECONFIGURED_FILTERS.TEST_FILES,
|
|
305
|
+
* ]
|
|
306
|
+
* });
|
|
307
|
+
* ```
|
|
308
|
+
*/
|
|
309
|
+
declare function createPathFilter(options?: PathFilterOptions): PathFilter;
|
|
310
|
+
declare function filterTreeStructure<T extends UnicodeFileTreeNodeWithoutLastModified>(pathFilter: PathFilter, entries: T[], extraOptions?: Pick<PathFilterOptions, "include" | "exclude">): T[];
|
|
311
|
+
//#endregion
|
|
312
|
+
//#region src/glob.d.ts
|
|
313
|
+
/**
|
|
314
|
+
* Default picomatch options used across the shared package.
|
|
315
|
+
* These options ensure consistent glob matching behavior:
|
|
316
|
+
* - `nocase: true` - Case-insensitive matching
|
|
317
|
+
* - `dot: true` - Match dotfiles (files starting with `.`)
|
|
318
|
+
*/
|
|
319
|
+
declare const DEFAULT_PICOMATCH_OPTIONS: PicomatchOptions;
|
|
320
|
+
interface GlobMatchOptions {
|
|
321
|
+
/**
|
|
322
|
+
* Whether matching should be case-insensitive.
|
|
323
|
+
* @default true
|
|
324
|
+
*/
|
|
325
|
+
nocase?: boolean;
|
|
326
|
+
/**
|
|
327
|
+
* Whether to match dotfiles.
|
|
328
|
+
* @default true
|
|
329
|
+
*/
|
|
330
|
+
dot?: boolean;
|
|
331
|
+
}
|
|
332
|
+
declare function matchGlob(pattern: string, value: string, options?: GlobMatchOptions): boolean;
|
|
333
|
+
type GlobMatchFn = (value: string) => boolean;
|
|
334
|
+
declare function createGlobMatcher(pattern: string, options?: GlobMatchOptions): GlobMatchFn;
|
|
335
|
+
interface GlobValidationLimits {
|
|
336
|
+
maxLength?: number;
|
|
337
|
+
maxSegments?: number;
|
|
338
|
+
maxBraceExpansions?: number;
|
|
339
|
+
maxStars?: number;
|
|
340
|
+
maxQuestions?: number;
|
|
341
|
+
}
|
|
342
|
+
declare function isValidGlobPattern(pattern: string, limits?: GlobValidationLimits): boolean;
|
|
343
|
+
//#endregion
|
|
344
|
+
//#region src/guards.d.ts
|
|
345
|
+
/**
|
|
346
|
+
* Type guard function that checks if an unknown value is an ApiError object.
|
|
347
|
+
*
|
|
348
|
+
* This function performs runtime type checking to determine if the provided value
|
|
349
|
+
* conforms to the ApiError interface structure by verifying the presence of
|
|
350
|
+
* required properties: message, status, and timestamp.
|
|
351
|
+
*
|
|
352
|
+
* @param {unknown} error - The unknown value to check against the ApiError type
|
|
353
|
+
* @returns {error is ApiError} True if the value is an ApiError, false otherwise
|
|
354
|
+
*
|
|
355
|
+
* @example
|
|
356
|
+
* ```typescript
|
|
357
|
+
* import { isApiError } from "@ucdjs-internal/shared";
|
|
358
|
+
* import { client } from "@ucdjs/client";
|
|
359
|
+
*
|
|
360
|
+
* const { error, data } = await client.GET("/api/v1/versions");
|
|
361
|
+
* if (isApiError(error)) {
|
|
362
|
+
* console.error("API Error:", error.message);
|
|
363
|
+
* }
|
|
364
|
+
* ```
|
|
365
|
+
*/
|
|
366
|
+
declare function isApiError(error: unknown): error is ApiError;
|
|
367
|
+
//#endregion
|
|
368
|
+
//#region src/json.d.ts
|
|
369
|
+
/**
|
|
370
|
+
* Safely parses a JSON string into an object of type T.
|
|
371
|
+
* Returns null if the parsing fails.
|
|
372
|
+
*
|
|
373
|
+
* @template T - The expected type of the parsed JSON
|
|
374
|
+
* @param {string} content - The JSON string to parse
|
|
375
|
+
* @returns {T | null} The parsed object of type T or null if parsing fails
|
|
376
|
+
*/
|
|
377
|
+
declare function safeJsonParse<T>(content: string): T | null;
|
|
378
|
+
//#endregion
|
|
379
|
+
//#region src/ucd-config.d.ts
|
|
380
|
+
/**
|
|
381
|
+
* Fetches and validates the UCD well-known configuration from a server
|
|
382
|
+
*
|
|
383
|
+
* @param {string} baseUrl - The base URL of the UCD server
|
|
384
|
+
* @returns {Promise<UCDWellKnownConfig>} The validated well-known configuration
|
|
385
|
+
* @throws {Error} If the config cannot be fetched or is invalid
|
|
386
|
+
*/
|
|
387
|
+
declare function discoverEndpointsFromConfig(baseUrl: string): Promise<UCDWellKnownConfig>;
|
|
388
|
+
/**
|
|
389
|
+
* Return the default UCD well-known configuration used by the library.
|
|
390
|
+
*
|
|
391
|
+
* This function returns the build-time injected __UCD_ENDPOINT_DEFAULT_CONFIG__ if present;
|
|
392
|
+
* otherwise it falls back to a hard-coded default object containing a version and
|
|
393
|
+
* the common API endpoint paths for files, manifest and versions.
|
|
394
|
+
*
|
|
395
|
+
* The returned value conforms to the UCDWellKnownConfig schema and is used when
|
|
396
|
+
* discovery via discoverEndpointsFromConfig() is not possible or a local default
|
|
397
|
+
* is required.
|
|
398
|
+
*
|
|
399
|
+
* @returns {UCDWellKnownConfig} The default well-known configuration.
|
|
400
|
+
*/
|
|
401
|
+
declare function getDefaultUCDEndpointConfig(): UCDWellKnownConfig;
|
|
402
|
+
//#endregion
|
|
403
|
+
export { ConcurrencyLimitFn, DEFAULT_EXCLUDED_EXTENSIONS, DEFAULT_PICOMATCH_OPTIONS, type FetchOptions, type FetchResponse, type GlobMatchFn, type GlobMatchOptions, OperationFailure, OperationResult, OperationSuccess, PRECONFIGURED_FILTERS, type PathFilter, type PathFilterOptions, type SafeFetchResponse, createConcurrencyLimiter, createDebugger, createGlobMatcher, createPathFilter, customFetch, discoverEndpointsFromConfig, ensureIsPositiveConcurrency, filterTreeStructure, findFileByPath, flattenFilePaths, getDefaultUCDEndpointConfig, isApiError, isValidGlobPattern, matchGlob, normalizePathForFiltering, normalizeTreeForFiltering, safeJsonParse, tryOr, wrapTry };
|