tyneq 1.0.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.
- package/LICENSE +21 -0
- package/README.md +319 -0
- package/dist/Lazy.cjs +762 -0
- package/dist/Lazy.cjs.map +1 -0
- package/dist/Lazy.js +691 -0
- package/dist/Lazy.js.map +1 -0
- package/dist/TyneqCachedTerminalOperator.cjs +4950 -0
- package/dist/TyneqCachedTerminalOperator.cjs.map +1 -0
- package/dist/TyneqCachedTerminalOperator.d.cts +724 -0
- package/dist/TyneqCachedTerminalOperator.d.cts.map +1 -0
- package/dist/TyneqCachedTerminalOperator.d.ts +724 -0
- package/dist/TyneqCachedTerminalOperator.d.ts.map +1 -0
- package/dist/TyneqCachedTerminalOperator.js +4741 -0
- package/dist/TyneqCachedTerminalOperator.js.map +1 -0
- package/dist/ValidationBuilder.cjs +80 -0
- package/dist/ValidationBuilder.cjs.map +1 -0
- package/dist/ValidationBuilder.d.cts +319 -0
- package/dist/ValidationBuilder.d.cts.map +1 -0
- package/dist/ValidationBuilder.d.ts +319 -0
- package/dist/ValidationBuilder.d.ts.map +1 -0
- package/dist/ValidationBuilder.js +69 -0
- package/dist/ValidationBuilder.js.map +1 -0
- package/dist/core.d.cts +1393 -0
- package/dist/core.d.cts.map +1 -0
- package/dist/core.d.ts +1393 -0
- package/dist/core.d.ts.map +1 -0
- package/dist/index.cjs +863 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +1038 -0
- package/dist/index.d.cts.map +1 -0
- package/dist/index.d.ts +1038 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +809 -0
- package/dist/index.js.map +1 -0
- package/dist/plugin/index.cjs +24 -0
- package/dist/plugin/index.d.cts +89 -0
- package/dist/plugin/index.d.cts.map +1 -0
- package/dist/plugin/index.d.ts +89 -0
- package/dist/plugin/index.d.ts.map +1 -0
- package/dist/plugin/index.js +2 -0
- package/dist/utility/index.cjs +9 -0
- package/dist/utility/index.d.cts +2 -0
- package/dist/utility/index.d.ts +2 -0
- package/dist/utility/index.js +3 -0
- package/package.json +96 -0
|
@@ -0,0 +1,319 @@
|
|
|
1
|
+
import { H as HasLength, Q as Optional, R as Factory, Z as Nullable, a as Enumerator, i as Enumerable, q as Maybe } from "./core.js";
|
|
2
|
+
|
|
3
|
+
//#region src/utility/ArgumentUtility.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* Facade for all argument validation guards.
|
|
6
|
+
*
|
|
7
|
+
* Every method accepts either a single-property object (`{ count }`) - where the
|
|
8
|
+
* property name becomes the error message's parameter name - or a raw value with
|
|
9
|
+
* an explicit `paramName` string. Prefer the object form; the name is inferred
|
|
10
|
+
* automatically via `nameof`.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```ts
|
|
14
|
+
* import { ArgumentUtility } from "tyneq/utility";
|
|
15
|
+
*
|
|
16
|
+
* function take(count: number) {
|
|
17
|
+
* ArgumentUtility.checkNonNegative({ count }); // throws ArgumentOutOfRangeError if count < 0
|
|
18
|
+
* ArgumentUtility.checkInteger({ count }); // throws ArgumentError if count is not an integer
|
|
19
|
+
* }
|
|
20
|
+
* ```
|
|
21
|
+
*
|
|
22
|
+
* @group Utilities
|
|
23
|
+
*/
|
|
24
|
+
declare class ArgumentUtility {
|
|
25
|
+
private constructor();
|
|
26
|
+
static checkNotNull<T>(param: Record<string, Nullable<T>>): asserts param is Record<string, T>;
|
|
27
|
+
static checkNotNull<T>(param: Nullable<T>, paramName: string): asserts param is T;
|
|
28
|
+
static checkNotUndefined<T>(param: Record<string, Maybe<T>>): asserts param is Record<string, T>;
|
|
29
|
+
static checkNotUndefined<T>(param: Maybe<T>, paramName: string): asserts param is T;
|
|
30
|
+
static checkNotOptional<T>(param: Record<string, Optional<T>>): asserts param is Record<string, T>;
|
|
31
|
+
static checkNotOptional<T>(param: Optional<T>, paramName: string): asserts param is T;
|
|
32
|
+
static checkNotNullOrEmpty<T extends HasLength>(param: Record<string, Nullable<T>>): asserts param is Record<string, T>;
|
|
33
|
+
static checkNotNullOrEmpty<T extends HasLength>(param: Nullable<T>, paramName: string): asserts param is T;
|
|
34
|
+
static checkNotOptionalOrEmpty<T extends HasLength>(param: Record<string, Optional<T>>): asserts param is Record<string, T>;
|
|
35
|
+
static checkNotOptionalOrEmpty<T extends HasLength>(param: Optional<T>, paramName: string): asserts param is T;
|
|
36
|
+
static checkNotNullOrWhiteSpace(param: Record<string, Optional<string>>): asserts param is Record<string, string>;
|
|
37
|
+
static checkNotNullOrWhiteSpace(param: Optional<string>, paramName: string): asserts param is string;
|
|
38
|
+
static checkNonNegative(param: Record<string, number>): void;
|
|
39
|
+
static checkNonNegative(param: number, paramName: string): void;
|
|
40
|
+
static checkPositive(param: Record<string, number>): void;
|
|
41
|
+
static checkPositive(param: number, paramName: string): void;
|
|
42
|
+
static checkNegative(param: Record<string, number>): void;
|
|
43
|
+
static checkNegative(param: number, paramName: string): void;
|
|
44
|
+
static checkNonPositive(param: Record<string, number>): void;
|
|
45
|
+
static checkNonPositive(param: number, paramName: string): void;
|
|
46
|
+
static checkInRange(param: Record<string, number>, min: number, max: number): void;
|
|
47
|
+
static checkInRange(param: number, min: number, max: number, paramName: string): void;
|
|
48
|
+
static checkInteger(param: Record<string, number>): void;
|
|
49
|
+
static checkInteger(param: number, paramName: string): void;
|
|
50
|
+
static checkFinite(param: Record<string, number>): void;
|
|
51
|
+
static checkFinite(param: number, paramName: string): void;
|
|
52
|
+
static checkNotNaN(param: Record<string, number>): void;
|
|
53
|
+
static checkNotNaN(param: number, paramName: string): void;
|
|
54
|
+
static checkSafeInteger(param: Record<string, number>): void;
|
|
55
|
+
static checkSafeInteger(param: number, paramName: string): void;
|
|
56
|
+
static checkArrayIndex(param: Record<string, number>, arrayLength?: number): void;
|
|
57
|
+
static checkArrayIndex(param: number, paramName: string, arrayLength?: number): void;
|
|
58
|
+
static checkFunction(param: Record<string, unknown>): asserts param is Record<string, Function>;
|
|
59
|
+
static checkFunction(param: unknown, paramName: string): asserts param is Function;
|
|
60
|
+
static checkIterable<T = unknown>(param: Record<string, unknown>): asserts param is Record<string, Iterable<T>>;
|
|
61
|
+
static checkIterable<T = unknown>(param: unknown, paramName: string): asserts param is Iterable<T>;
|
|
62
|
+
static checkIterator<T = unknown>(param: Record<string, unknown>): asserts param is Record<string, Iterator<T>>;
|
|
63
|
+
static checkIterator<T = unknown>(param: unknown, paramName: string): asserts param is Iterator<T>;
|
|
64
|
+
static checkEnumerable<T = unknown>(param: Record<string, unknown>): asserts param is Record<string, Enumerable<T>>;
|
|
65
|
+
static checkEnumerable<T = unknown>(param: unknown, paramName: string): asserts param is Enumerable<T>;
|
|
66
|
+
static checkEnumerator<T = unknown>(param: Record<string, unknown>): asserts param is Record<string, Enumerator<T>>;
|
|
67
|
+
static checkEnumerator<T = unknown>(param: unknown, paramName: string): asserts param is Enumerator<T>;
|
|
68
|
+
static checkInstanceOf<T>(param: Record<string, unknown>, constructor: new (...args: any[]) => T): asserts param is Record<string, T>;
|
|
69
|
+
static checkInstanceOf<T>(param: unknown, constructor: new (...args: any[]) => T, paramName: string): asserts param is T;
|
|
70
|
+
static checkHasLength(param: Record<string, unknown>): asserts param is Record<string, HasLength>;
|
|
71
|
+
static checkHasLength(param: unknown, paramName: string): asserts param is HasLength;
|
|
72
|
+
static check<T>(param: Record<string, T>, predicate: (v: T) => boolean, message: string): void;
|
|
73
|
+
static check<T>(param: T, paramName: string, predicate: (v: T) => boolean, message: string): void;
|
|
74
|
+
private static extractParameter;
|
|
75
|
+
}
|
|
76
|
+
//#endregion
|
|
77
|
+
//#region src/types/reflection.d.ts
|
|
78
|
+
/**
|
|
79
|
+
* Describes a method (function-valued own property) on a reflected target.
|
|
80
|
+
*
|
|
81
|
+
* @group Reflection
|
|
82
|
+
*/
|
|
83
|
+
interface MethodDescriptor {
|
|
84
|
+
readonly kind: "method";
|
|
85
|
+
readonly name: string | symbol;
|
|
86
|
+
/** The raw function value. */
|
|
87
|
+
readonly value: Function;
|
|
88
|
+
/** Calls the method with the given `this` context and arguments. */
|
|
89
|
+
readonly invoke: (thisArg: unknown, ...args: unknown[]) => unknown;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Describes a data property (non-function own value property) on a reflected target.
|
|
93
|
+
*
|
|
94
|
+
* @group Reflection
|
|
95
|
+
*/
|
|
96
|
+
interface DataDescriptor {
|
|
97
|
+
readonly kind: "data";
|
|
98
|
+
readonly name: string | symbol;
|
|
99
|
+
readonly value: unknown;
|
|
100
|
+
readonly writable: boolean;
|
|
101
|
+
readonly configurable: boolean;
|
|
102
|
+
readonly enumerable: boolean;
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Describes an accessor property (get and/or set) on a reflected target.
|
|
106
|
+
*
|
|
107
|
+
* @group Reflection
|
|
108
|
+
*/
|
|
109
|
+
interface AccessorDescriptor {
|
|
110
|
+
readonly kind: "accessor";
|
|
111
|
+
readonly name: string | symbol;
|
|
112
|
+
readonly get: Maybe<() => unknown>;
|
|
113
|
+
readonly set: Maybe<(value: unknown) => void>;
|
|
114
|
+
readonly configurable: boolean;
|
|
115
|
+
readonly enumerable: boolean;
|
|
116
|
+
/** `true` if the accessor defines a getter. */
|
|
117
|
+
readonly canRead: boolean;
|
|
118
|
+
/** `true` if the accessor defines a setter. */
|
|
119
|
+
readonly canWrite: boolean;
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* A discriminated union of all member descriptor types returned by {@link ReflectionContext}.
|
|
123
|
+
*
|
|
124
|
+
* Use `descriptor.kind` to narrow to the specific descriptor type.
|
|
125
|
+
*
|
|
126
|
+
* @group Reflection
|
|
127
|
+
*/
|
|
128
|
+
type MemberDescriptor = MethodDescriptor | DataDescriptor | AccessorDescriptor;
|
|
129
|
+
/**
|
|
130
|
+
* Options for the {@link reflect} factory.
|
|
131
|
+
*
|
|
132
|
+
* @group Reflection
|
|
133
|
+
*/
|
|
134
|
+
interface ReflectOptions {
|
|
135
|
+
/**
|
|
136
|
+
* When `true`, walks the full prototype chain and includes inherited members
|
|
137
|
+
* up to (but not including) `Object.prototype`.
|
|
138
|
+
*
|
|
139
|
+
* Equivalent to C# `BindingFlags.FlattenHierarchy`.
|
|
140
|
+
*
|
|
141
|
+
* @defaultValue false
|
|
142
|
+
*/
|
|
143
|
+
readonly inherited?: boolean;
|
|
144
|
+
/**
|
|
145
|
+
* When `true`, includes Symbol-keyed members in addition to string-keyed members.
|
|
146
|
+
*
|
|
147
|
+
* @defaultValue false
|
|
148
|
+
*/
|
|
149
|
+
readonly symbols?: boolean;
|
|
150
|
+
}
|
|
151
|
+
//#endregion
|
|
152
|
+
//#region src/utility/reflect.d.ts
|
|
153
|
+
/**
|
|
154
|
+
* The result of a {@link reflect} call. Provides typed access to the members of
|
|
155
|
+
* the reflected target.
|
|
156
|
+
*
|
|
157
|
+
* @group Reflection
|
|
158
|
+
*/
|
|
159
|
+
declare class ReflectionContext<_T extends object> {
|
|
160
|
+
private readonly proto;
|
|
161
|
+
private readonly options;
|
|
162
|
+
/** @internal */
|
|
163
|
+
constructor(proto: object, options: ReflectOptions);
|
|
164
|
+
/**
|
|
165
|
+
* Returns descriptors for all own (and optionally inherited) members,
|
|
166
|
+
* excluding `constructor`.
|
|
167
|
+
*/
|
|
168
|
+
members(): readonly MemberDescriptor[];
|
|
169
|
+
/**
|
|
170
|
+
* Returns descriptors for all method members (function-valued own properties),
|
|
171
|
+
* excluding `constructor`.
|
|
172
|
+
*/
|
|
173
|
+
methods(): readonly MethodDescriptor[];
|
|
174
|
+
/**
|
|
175
|
+
* Returns descriptors for all data members (non-function value properties).
|
|
176
|
+
*/
|
|
177
|
+
fields(): readonly DataDescriptor[];
|
|
178
|
+
/**
|
|
179
|
+
* Returns descriptors for all accessor members (get/set properties).
|
|
180
|
+
*/
|
|
181
|
+
accessors(): readonly AccessorDescriptor[];
|
|
182
|
+
/**
|
|
183
|
+
* Returns the descriptor for the named member, or `undefined` if not found.
|
|
184
|
+
*/
|
|
185
|
+
get(name: string | symbol): Maybe<MemberDescriptor>;
|
|
186
|
+
/**
|
|
187
|
+
* Returns `true` if a member with the given name exists on the target.
|
|
188
|
+
*/
|
|
189
|
+
has(name: string | symbol): boolean;
|
|
190
|
+
/**
|
|
191
|
+
* Returns the method descriptor for `name`, or throws {@link ReflectionError}
|
|
192
|
+
* if the member does not exist or is not a method.
|
|
193
|
+
*
|
|
194
|
+
* @throws {ReflectionError} when the member is absent or is not a method.
|
|
195
|
+
*/
|
|
196
|
+
getMethod(name: string | symbol): MethodDescriptor;
|
|
197
|
+
/**
|
|
198
|
+
* Returns the accessor descriptor for `name`, or throws {@link ReflectionError}
|
|
199
|
+
* if the member does not exist or is not an accessor.
|
|
200
|
+
*
|
|
201
|
+
* @throws {ReflectionError} when the member is absent or is not an accessor.
|
|
202
|
+
*/
|
|
203
|
+
getAccessor(name: string | symbol): AccessorDescriptor;
|
|
204
|
+
/**
|
|
205
|
+
* Returns `true` if a method with the given name exists on the target.
|
|
206
|
+
*
|
|
207
|
+
* Unlike {@link has}, this returns `false` if the member exists but is an accessor or data property.
|
|
208
|
+
*/
|
|
209
|
+
hasMethod(name: string | symbol): boolean;
|
|
210
|
+
/**
|
|
211
|
+
* Returns the method descriptor for `name`, or `undefined` if the member does not
|
|
212
|
+
* exist or is not a method. Never throws.
|
|
213
|
+
*/
|
|
214
|
+
tryGetMethod(name: string | symbol): Maybe<MethodDescriptor>;
|
|
215
|
+
private findDescriptor;
|
|
216
|
+
private collectDescriptors;
|
|
217
|
+
}
|
|
218
|
+
/**
|
|
219
|
+
* Creates a {@link ReflectionContext} for the given target.
|
|
220
|
+
*
|
|
221
|
+
* The `target` can be:
|
|
222
|
+
* - A **constructor function** - reflects the class prototype (instance members). Preferred form.
|
|
223
|
+
* - A **prototype object** (`MyClass.prototype`) - reflects it directly.
|
|
224
|
+
* - Any **object** - reflects the object's own properties directly.
|
|
225
|
+
*
|
|
226
|
+
* @example
|
|
227
|
+
* ```ts
|
|
228
|
+
* import { reflect } from "tyneq/utility";
|
|
229
|
+
*
|
|
230
|
+
* class Service {
|
|
231
|
+
* public name = "svc";
|
|
232
|
+
* public get label(): string { return this.name; }
|
|
233
|
+
* public run(): void { /* ... *\/ }
|
|
234
|
+
* }
|
|
235
|
+
*
|
|
236
|
+
* const ctx = reflect(Service);
|
|
237
|
+
*
|
|
238
|
+
* ctx.methods(); // -> [{ kind: "method", name: "run", ... }]
|
|
239
|
+
* ctx.accessors(); // -> [{ kind: "accessor", name: "label", canRead: true, canWrite: false, ... }]
|
|
240
|
+
*
|
|
241
|
+
* const m = ctx.getMethod("run");
|
|
242
|
+
* m.invoke(new Service()); // calls run()
|
|
243
|
+
* ```
|
|
244
|
+
*
|
|
245
|
+
* Walk the full prototype chain:
|
|
246
|
+
*
|
|
247
|
+
* ```ts
|
|
248
|
+
* const ctx = reflect(DerivedClass, { inherited: true });
|
|
249
|
+
* ctx.members(); // includes members from base classes too
|
|
250
|
+
* ```
|
|
251
|
+
*
|
|
252
|
+
* @group Reflection
|
|
253
|
+
*/
|
|
254
|
+
declare function reflect<T extends object>(target: (new (...args: any[]) => T) | T, options?: ReflectOptions): ReflectionContext<T>;
|
|
255
|
+
//#endregion
|
|
256
|
+
//#region src/utility/TypeGuardUtility.d.ts
|
|
257
|
+
/**
|
|
258
|
+
* Type guard predicates for Tyneq's core protocol types.
|
|
259
|
+
*
|
|
260
|
+
* @group Utilities
|
|
261
|
+
*/
|
|
262
|
+
declare class TypeGuardUtility {
|
|
263
|
+
private constructor();
|
|
264
|
+
static isIterable<T = unknown>(value: unknown): value is Iterable<T>;
|
|
265
|
+
static isIterator<T = unknown>(value: unknown): value is Iterator<T>;
|
|
266
|
+
static isIterableIterator<T = unknown>(value: unknown): value is IterableIterator<T>;
|
|
267
|
+
static isEnumerator<T = unknown>(value: unknown): value is Enumerator<T>;
|
|
268
|
+
static isEnumerable<T = unknown>(value: unknown): value is Enumerable<T>;
|
|
269
|
+
}
|
|
270
|
+
//#endregion
|
|
271
|
+
//#region src/utility/Lazy.d.ts
|
|
272
|
+
/**
|
|
273
|
+
* Utility class for lazy initialization of values.
|
|
274
|
+
*
|
|
275
|
+
* @group Utilities
|
|
276
|
+
*/
|
|
277
|
+
declare class Lazy<T> {
|
|
278
|
+
private readonly factory;
|
|
279
|
+
/** The lazily initialized value, or `undefined` if not yet initialized. */
|
|
280
|
+
private lazyValue;
|
|
281
|
+
/** Indicates whether the value has been initialized. */
|
|
282
|
+
private initialized;
|
|
283
|
+
constructor(factory: Factory<T, []>);
|
|
284
|
+
/** Returns the lazily initialized value, initializing it if necessary. */
|
|
285
|
+
get value(): T;
|
|
286
|
+
}
|
|
287
|
+
//#endregion
|
|
288
|
+
//#region src/utility/ValidationBuilder.d.ts
|
|
289
|
+
/**
|
|
290
|
+
* Accumulates validation errors and throws a single `ValidationError` containing all of them.
|
|
291
|
+
*
|
|
292
|
+
* Use when multiple independent arguments must be validated together so callers see all
|
|
293
|
+
* failures in one throw rather than one at a time.
|
|
294
|
+
*
|
|
295
|
+
* @example
|
|
296
|
+
* ```ts
|
|
297
|
+
* new ValidationBuilder()
|
|
298
|
+
* .check(() => ArgumentUtility.checkNotOptional({ selector }))
|
|
299
|
+
* .check(() => ArgumentUtility.checkPositive({ count }))
|
|
300
|
+
* .throwIfAny();
|
|
301
|
+
* ```
|
|
302
|
+
*
|
|
303
|
+
* @group Utilities
|
|
304
|
+
*/
|
|
305
|
+
declare class ValidationBuilder {
|
|
306
|
+
private readonly errors;
|
|
307
|
+
/**
|
|
308
|
+
* Runs `fn` and collects any thrown error message. Returns `this` for chaining.
|
|
309
|
+
*/
|
|
310
|
+
check(fn: () => void): this;
|
|
311
|
+
/**
|
|
312
|
+
* Throws a `ValidationError` with all collected messages if any `check` calls failed.
|
|
313
|
+
* Does nothing when no errors were collected.
|
|
314
|
+
*/
|
|
315
|
+
throwIfAny(): void;
|
|
316
|
+
}
|
|
317
|
+
//#endregion
|
|
318
|
+
export { reflect as a, MemberDescriptor as c, ArgumentUtility as d, ReflectionContext as i, MethodDescriptor as l, Lazy as n, AccessorDescriptor as o, TypeGuardUtility as r, DataDescriptor as s, ValidationBuilder as t, ReflectOptions as u };
|
|
319
|
+
//# sourceMappingURL=ValidationBuilder.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ValidationBuilder.d.ts","names":[],"sources":["../src/utility/ArgumentUtility.ts","../src/types/reflection.ts","../src/utility/reflect.ts","../src/utility/TypeGuardUtility.ts","../src/utility/Lazy.ts","../src/utility/ValidationBuilder.ts"],"mappings":";;;;AA6BA;;;;;;;;;;;;;;;;;;;cAAa,eAAA;EAAA,QACF,WAAA,CAAA;EAAA,OAGO,YAAA,GAAA,CAAgB,KAAA,EAAO,MAAA,SAAe,QAAA,CAAS,CAAA,aAAc,KAAA,IAAS,MAAA,SAAe,CAAA;EAAA,OACrF,YAAA,GAAA,CAAgB,KAAA,EAAO,QAAA,CAAS,CAAA,GAAI,SAAA,mBAA4B,KAAA,IAAS,CAAA;EAAA,OAOzE,iBAAA,GAAA,CAAqB,KAAA,EAAO,MAAA,SAAe,KAAA,CAAM,CAAA,aAAc,KAAA,IAAS,MAAA,SAAe,CAAA;EAAA,OACvF,iBAAA,GAAA,CAAqB,KAAA,EAAO,KAAA,CAAM,CAAA,GAAI,SAAA,mBAA4B,KAAA,IAAS,CAAA;EAAA,OAO3E,gBAAA,GAAA,CAAoB,KAAA,EAAO,MAAA,SAAe,QAAA,CAAS,CAAA,aAAc,KAAA,IAAS,MAAA,SAAe,CAAA;EAAA,OACzF,gBAAA,GAAA,CAAoB,KAAA,EAAO,QAAA,CAAS,CAAA,GAAI,SAAA,mBAA4B,KAAA,IAAS,CAAA;EAAA,OAO7E,mBAAA,WAA8B,SAAA,CAAA,CAAW,KAAA,EAAO,MAAA,SAAe,QAAA,CAAS,CAAA,aAAc,KAAA,IAAS,MAAA,SAAe,CAAA;EAAA,OAC9G,mBAAA,WAA8B,SAAA,CAAA,CAAW,KAAA,EAAO,QAA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EJwB4E;EAAA,QItB5E,WAAA;cAE4B,OAAA,EAAS,OAAA,CAAQ,CAAA;EJqBkC;EAAA,IIlB5E,KAAA,CAAA,GAAS,CAAA;AAAA;;;;;;AJaxB;;;;;;;;;;;;;cKXa,iBAAA;EAAA,iBACQ,MAAA;ELsBqE;;;EKjB/E,KAAA,CAAM,EAAA;ELyBoD;;;;EKX1D,UAAA,CAAA;AAAA"}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { u as ArgumentError } from "./Lazy.js";
|
|
2
|
+
//#region src/core/errors/argument/ValidationError.ts
|
|
3
|
+
/**
|
|
4
|
+
* Thrown when multiple argument validations fail simultaneously.
|
|
5
|
+
*
|
|
6
|
+
* @remarks
|
|
7
|
+
* `errors` contains one message per failed validation.
|
|
8
|
+
* Thrown by `ValidationBuilder.throwIfAny()` when at least one check failed.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```ts
|
|
12
|
+
* try { seq.someOperator(badArg1, badArg2); }
|
|
13
|
+
* catch (e) { if (e instanceof ValidationError) { console.log(e.errors); } }
|
|
14
|
+
* ```
|
|
15
|
+
*
|
|
16
|
+
* @see {@link ArgumentError}
|
|
17
|
+
* @group Errors
|
|
18
|
+
*/
|
|
19
|
+
var ValidationError = class extends ArgumentError {
|
|
20
|
+
/** The individual validation failure messages. */
|
|
21
|
+
errors;
|
|
22
|
+
constructor(errors) {
|
|
23
|
+
super(`${errors.length} validation error(s):\n${errors.map((e, i) => ` ${i + 1}. ${e}`).join("\n")}`);
|
|
24
|
+
this.errors = errors;
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
//#endregion
|
|
28
|
+
//#region src/utility/ValidationBuilder.ts
|
|
29
|
+
/**
|
|
30
|
+
* Accumulates validation errors and throws a single `ValidationError` containing all of them.
|
|
31
|
+
*
|
|
32
|
+
* Use when multiple independent arguments must be validated together so callers see all
|
|
33
|
+
* failures in one throw rather than one at a time.
|
|
34
|
+
*
|
|
35
|
+
* @example
|
|
36
|
+
* ```ts
|
|
37
|
+
* new ValidationBuilder()
|
|
38
|
+
* .check(() => ArgumentUtility.checkNotOptional({ selector }))
|
|
39
|
+
* .check(() => ArgumentUtility.checkPositive({ count }))
|
|
40
|
+
* .throwIfAny();
|
|
41
|
+
* ```
|
|
42
|
+
*
|
|
43
|
+
* @group Utilities
|
|
44
|
+
*/
|
|
45
|
+
var ValidationBuilder = class {
|
|
46
|
+
errors = [];
|
|
47
|
+
/**
|
|
48
|
+
* Runs `fn` and collects any thrown error message. Returns `this` for chaining.
|
|
49
|
+
*/
|
|
50
|
+
check(fn) {
|
|
51
|
+
try {
|
|
52
|
+
fn();
|
|
53
|
+
} catch (e) {
|
|
54
|
+
this.errors.push(e instanceof Error ? e.message : String(e));
|
|
55
|
+
}
|
|
56
|
+
return this;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Throws a `ValidationError` with all collected messages if any `check` calls failed.
|
|
60
|
+
* Does nothing when no errors were collected.
|
|
61
|
+
*/
|
|
62
|
+
throwIfAny() {
|
|
63
|
+
if (this.errors.length > 0) throw new ValidationError(this.errors);
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
//#endregion
|
|
67
|
+
export { ValidationError as n, ValidationBuilder as t };
|
|
68
|
+
|
|
69
|
+
//# sourceMappingURL=ValidationBuilder.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ValidationBuilder.js","names":[],"sources":["../src/core/errors/argument/ValidationError.ts","../src/utility/ValidationBuilder.ts"],"sourcesContent":["import { ArgumentError } from \"./ArgumentError\";\r\n\r\n/**\r\n * Thrown when multiple argument validations fail simultaneously.\r\n *\r\n * @remarks\r\n * `errors` contains one message per failed validation.\r\n * Thrown by `ValidationBuilder.throwIfAny()` when at least one check failed.\r\n *\r\n * @example\r\n * ```ts\r\n * try { seq.someOperator(badArg1, badArg2); }\r\n * catch (e) { if (e instanceof ValidationError) { console.log(e.errors); } }\r\n * ```\r\n *\r\n * @see {@link ArgumentError}\r\n * @group Errors\r\n */\r\nexport class ValidationError extends ArgumentError {\r\n /** The individual validation failure messages. */\r\n public readonly errors: readonly string[];\r\n\r\n public constructor(errors: readonly string[]) {\r\n super(\r\n `${errors.length} validation error(s):\\n${errors.map((e, i) => ` ${i + 1}. ${e}`).join(\"\\n\")}`\r\n );\r\n this.errors = errors;\r\n }\r\n}\r\n","import { ValidationError } from \"../core/errors/argument/ValidationError\";\r\n\r\n/**\r\n * Accumulates validation errors and throws a single `ValidationError` containing all of them.\r\n *\r\n * Use when multiple independent arguments must be validated together so callers see all\r\n * failures in one throw rather than one at a time.\r\n *\r\n * @example\r\n * ```ts\r\n * new ValidationBuilder()\r\n * .check(() => ArgumentUtility.checkNotOptional({ selector }))\r\n * .check(() => ArgumentUtility.checkPositive({ count }))\r\n * .throwIfAny();\r\n * ```\r\n *\r\n * @group Utilities\r\n */\r\nexport class ValidationBuilder {\r\n private readonly errors: string[] = [];\r\n\r\n /**\r\n * Runs `fn` and collects any thrown error message. Returns `this` for chaining.\r\n */\r\n public check(fn: () => void): this {\r\n try {\r\n fn();\r\n } catch (e) {\r\n this.errors.push(e instanceof Error ? e.message : String(e));\r\n }\r\n \r\n return this;\r\n }\r\n\r\n /**\r\n * Throws a `ValidationError` with all collected messages if any `check` calls failed.\r\n * Does nothing when no errors were collected.\r\n */\r\n public throwIfAny(): void {\r\n if (this.errors.length > 0) {\r\n throw new ValidationError(this.errors);\r\n }\r\n }\r\n}\r\n"],"mappings":";;;;;;;;;;;;;;;;;;AAkBA,IAAa,kBAAb,cAAqC,cAAc;;CAE/C;CAEA,YAAmB,QAA2B;AAC1C,QACI,GAAG,OAAO,OAAO,yBAAyB,OAAO,KAAK,GAAG,MAAM,KAAK,IAAI,EAAE,IAAI,IAAI,CAAC,KAAK,KAAK,GAChG;AACD,OAAK,SAAS;;;;;;;;;;;;;;;;;;;;;ACRtB,IAAa,oBAAb,MAA+B;CAC3B,SAAoC,EAAE;;;;CAKtC,MAAa,IAAsB;AAC/B,MAAI;AACA,OAAI;WACC,GAAG;AACR,QAAK,OAAO,KAAK,aAAa,QAAQ,EAAE,UAAU,OAAO,EAAE,CAAC;;AAGhE,SAAO;;;;;;CAOX,aAA0B;AACtB,MAAI,KAAK,OAAO,SAAS,EACrB,OAAM,IAAI,gBAAgB,KAAK,OAAO"}
|