@oscarpalmer/jhunal 0.17.0 → 0.18.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.
Files changed (40) hide show
  1. package/dist/constants.d.mts +28 -15
  2. package/dist/constants.mjs +31 -14
  3. package/dist/helpers.d.mts +8 -1
  4. package/dist/helpers.mjs +68 -3
  5. package/dist/index.d.mts +284 -240
  6. package/dist/index.mjs +188 -50
  7. package/dist/models/infer.model.d.mts +66 -0
  8. package/dist/models/infer.model.mjs +1 -0
  9. package/dist/models/misc.model.d.mts +153 -0
  10. package/dist/models/misc.model.mjs +1 -0
  11. package/dist/models/schema.plain.model.d.mts +92 -0
  12. package/dist/models/schema.plain.model.mjs +1 -0
  13. package/dist/models/schema.typed.model.d.mts +96 -0
  14. package/dist/models/schema.typed.model.mjs +1 -0
  15. package/dist/models/transform.model.d.mts +59 -0
  16. package/dist/models/transform.model.mjs +1 -0
  17. package/dist/models/validation.model.d.mts +81 -0
  18. package/dist/models/validation.model.mjs +21 -0
  19. package/dist/schematic.d.mts +15 -1
  20. package/dist/schematic.mjs +7 -12
  21. package/dist/validation/property.validation.d.mts +1 -1
  22. package/dist/validation/property.validation.mjs +21 -17
  23. package/dist/validation/value.validation.d.mts +2 -2
  24. package/dist/validation/value.validation.mjs +63 -11
  25. package/package.json +2 -2
  26. package/src/constants.ts +84 -19
  27. package/src/helpers.ts +162 -4
  28. package/src/index.ts +3 -1
  29. package/src/models/infer.model.ts +105 -0
  30. package/src/models/misc.model.ts +212 -0
  31. package/src/models/schema.plain.model.ts +110 -0
  32. package/src/models/schema.typed.model.ts +109 -0
  33. package/src/models/transform.model.ts +85 -0
  34. package/src/models/validation.model.ts +123 -0
  35. package/src/schematic.ts +24 -13
  36. package/src/validation/property.validation.ts +41 -36
  37. package/src/validation/value.validation.ts +115 -15
  38. package/dist/models.d.mts +0 -484
  39. package/dist/models.mjs +0 -13
  40. package/src/models.ts +0 -665
package/src/models.ts DELETED
@@ -1,665 +0,0 @@
1
- import type {Constructor, GenericCallback, PlainObject, Simplify} from '@oscarpalmer/atoms/models';
2
- import {ERROR_NAME} from './constants';
3
- import type {Schematic} from './schematic';
4
-
5
- /**
6
- * Removes duplicate types from a tuple, preserving first occurrence order
7
- *
8
- * @template Value - Tuple to deduplicate
9
- * @template Seen - Accumulator for already-seen types _(internal)_
10
- *
11
- * @example
12
- * ```ts
13
- * // DeduplicateTuple<['string', 'number', 'string']>
14
- * // => ['string', 'number']
15
- * ```
16
- */
17
- type DeduplicateTuple<Value extends unknown[], Seen extends unknown[] = []> = Value extends [
18
- infer Head,
19
- ...infer Tail,
20
- ]
21
- ? Head extends Seen[number]
22
- ? DeduplicateTuple<Tail, Seen>
23
- : DeduplicateTuple<Tail, [...Seen, Head]>
24
- : Seen;
25
-
26
- /**
27
- * Recursively extracts {@link ValueName} strings from a type, unwrapping arrays and readonly arrays
28
- *
29
- * @template Value - Type to extract value names from
30
- *
31
- * @example
32
- * ```ts
33
- * // ExtractValueNames<'string'> => 'string'
34
- * // ExtractValueNames<['string', 'number']> => 'string' | 'number'
35
- * ```
36
- */
37
- type ExtractValueNames<Value> = Value extends ValueName
38
- ? Value
39
- : Value extends (infer Item)[]
40
- ? ExtractValueNames<Item>
41
- : Value extends readonly (infer Item)[]
42
- ? ExtractValueNames<Item>
43
- : never;
44
-
45
- /**
46
- * Infers the TypeScript type from a {@link Schema} definition
47
- *
48
- * @template Model - Schema to infer types from
49
- *
50
- * @example
51
- * ```ts
52
- * const userSchema = {
53
- * name: 'string',
54
- * age: 'number',
55
- * address: { $required: false, $type: 'string' },
56
- * } satisfies Schema;
57
- *
58
- * type User = Infer<typeof userSchema>;
59
- * // { name: string; age: number; address?: string }
60
- * ```
61
- */
62
- export type Infer<Model extends Schema> = Simplify<
63
- {
64
- [Key in InferRequiredKeys<Model>]: InferSchemaEntry<Model[Key]>;
65
- } & {
66
- [Key in InferOptionalKeys<Model>]?: InferSchemaEntry<Model[Key]>;
67
- }
68
- >;
69
-
70
- /**
71
- * Extracts keys from a {@link Schema} whose entries are optional _(i.e., `$required` is `false`)_
72
- *
73
- * @template Model - {@link Schema} to extract optional keys from
74
- */
75
- type InferOptionalKeys<Model extends Schema> = keyof {
76
- [Key in keyof Model as IsOptionalProperty<Model[Key]> extends true ? Key : never]: never;
77
- };
78
-
79
- /**
80
- * Infers the TypeScript type of a {@link SchemaProperty}'s `$type` field, unwrapping arrays to infer their item type
81
- *
82
- * @template Value - `$type` value _(single or array)_
83
- */
84
- type InferPropertyType<Value> = Value extends (infer Item)[]
85
- ? InferPropertyValue<Item>
86
- : InferPropertyValue<Value>;
87
-
88
- /**
89
- * Maps a single type definition to its TypeScript equivalent
90
- *
91
- * Resolves, in order: {@link Constructor} instances, {@link Schematic} models, {@link ValueName} strings, and nested {@link Schema} objects
92
- *
93
- * @template Value - single type definition
94
- */
95
- type InferPropertyValue<Value> =
96
- Value extends Constructor<infer Instance>
97
- ? Instance
98
- : Value extends Schematic<infer Model>
99
- ? Model
100
- : Value extends ValueName
101
- ? Values[Value & ValueName]
102
- : Value extends Schema
103
- ? Infer<Value>
104
- : never;
105
-
106
- /**
107
- * Extracts keys from a {@link Schema} whose entries are required _(i.e., `$required` is not `false`)_
108
- *
109
- * @template Model - Schema to extract required keys from
110
- */
111
- type InferRequiredKeys<Model extends Schema> = keyof {
112
- [Key in keyof Model as IsOptionalProperty<Model[Key]> extends true ? never : Key]: never;
113
- };
114
-
115
- /**
116
- * Infers the type for a top-level {@link Schema} entry, unwrapping arrays to infer their item type
117
- *
118
- * @template Value - Schema entry value _(single or array)_
119
- */
120
- type InferSchemaEntry<Value> = Value extends (infer Item)[]
121
- ? InferSchemaEntryValue<Item>
122
- : InferSchemaEntryValue<Value>;
123
-
124
- /**
125
- * Resolves a single schema entry to its TypeScript type
126
- *
127
- * Handles, in order: {@link Constructor} instances, {@link Schematic} models, {@link SchemaProperty} objects, {@link NestedSchema} objects, {@link ValueName} strings, and plain {@link Schema} objects
128
- *
129
- * @template Value - single schema entry
130
- */
131
- type InferSchemaEntryValue<Value> =
132
- Value extends Constructor<infer Instance>
133
- ? Instance
134
- : Value extends Schematic<infer Model>
135
- ? Model
136
- : Value extends SchemaProperty
137
- ? InferPropertyType<Value['$type']>
138
- : Value extends PlainSchema
139
- ? Infer<Value & Schema>
140
- : Value extends ValueName
141
- ? Values[Value & ValueName]
142
- : Value extends Schema
143
- ? Infer<Value>
144
- : never;
145
-
146
- /**
147
- * Determines whether a schema entry is optional
148
- *
149
- * Returns `true` if the entry is a {@link SchemaProperty} or {@link NestedSchema} with `$required` set to `false`; otherwise returns `false`
150
- *
151
- * @template Value - Schema entry to check
152
- */
153
- type IsOptionalProperty<Value> = Value extends SchemaProperty
154
- ? Value['$required'] extends false
155
- ? true
156
- : false
157
- : false;
158
-
159
- /**
160
- * Extracts the last member from a union type by leveraging intersection of function return types
161
- *
162
- * @template Value - Union type
163
- */
164
- type LastOfUnion<Value> =
165
- UnionToIntersection<Value extends unknown ? () => Value : never> extends () => infer Item
166
- ? Item
167
- : never;
168
-
169
- /**
170
- * Maps each element of a tuple through {@link ToValueType}
171
- *
172
- * @template Value - Tuple of types to map
173
- */
174
- type MapToValueTypes<Value extends unknown[]> = Value extends [infer Head, ...infer Tail]
175
- ? [ToValueType<Head>, ...MapToValueTypes<Tail>]
176
- : [];
177
-
178
- /**
179
- * Maps each element of a tuple through {@link ToSchemaPropertyTypeEach}
180
- *
181
- * @template Value - Tuple of types to map
182
- */
183
- type MapToSchemaPropertyTypes<Value extends unknown[]> = Value extends [infer Head, ...infer Tail]
184
- ? [ToSchemaPropertyTypeEach<Head>, ...MapToSchemaPropertyTypes<Tail>]
185
- : [];
186
-
187
- /**
188
- * Extracts keys from an object type that are optional
189
- *
190
- * @template Value - Object type to inspect
191
- */
192
- type OptionalKeys<Value> = {
193
- [Key in keyof Value]-?: {} extends Pick<Value, Key> ? Key : never;
194
- }[keyof Value];
195
-
196
- /**
197
- * A generic schema allowing {@link NestedSchema}, {@link SchemaEntry}, or arrays of {@link SchemaEntry} as values
198
- */
199
- type PlainSchema = {
200
- [key: string]: PlainSchema | SchemaEntry | SchemaEntry[] | undefined;
201
- } & {
202
- $required?: never;
203
- $type?: never;
204
- $validators?: never;
205
- };
206
-
207
- /**
208
- * A map of optional validator functions keyed by {@link ValueName}, used to add custom validation to {@link SchemaProperty} definitions
209
- *
210
- * Each key may hold a single validator or an array of validators that receive the typed value
211
- *
212
- * @template Value - `$type` value(s) to derive validator keys from
213
- *
214
- * @example
215
- * ```ts
216
- * const validators: PropertyValidators<'string'> = {
217
- * string: (value) => value.length > 0,
218
- * };
219
- * ```
220
- */
221
- type PropertyValidators<Value> = {
222
- [Key in ExtractValueNames<Value>]?:
223
- | ((value: Values[Key]) => boolean)
224
- | Array<(value: Values[Key]) => boolean>;
225
- };
226
-
227
- /**
228
- * Extracts keys from an object type that are required _(i.e., not optional)_
229
- *
230
- * @template Value - Object type to inspect
231
- */
232
- type RequiredKeys<Value> = Exclude<keyof Value, OptionalKeys<Value>>;
233
-
234
- /**
235
- * A schema for validating objects
236
- *
237
- * @example
238
- * ```ts
239
- * const schema: Schema = {
240
- * name: 'string',
241
- * age: 'number',
242
- * tags: ['string', 'number'],
243
- * };
244
- * ```
245
- */
246
- export type Schema = SchemaIndex;
247
-
248
- /**
249
- * A union of all valid types for a single schema entry
250
- *
251
- * Can be a {@link Constructor}, nested {@link Schema}, {@link SchemaProperty}, {@link Schematic}, {@link ValueName} string, or a custom validator function
252
- */
253
- type SchemaEntry =
254
- | Constructor
255
- | PlainSchema
256
- | SchemaProperty
257
- | Schematic<unknown>
258
- | ValueName
259
- | ((value: unknown) => boolean);
260
-
261
- /**
262
- * Index signature interface backing {@link Schema}, allowing string-keyed entries of {@link NestedSchema}, {@link SchemaEntry}, or arrays of {@link SchemaEntry}
263
- */
264
- interface SchemaIndex {
265
- [key: string]: PlainSchema | SchemaEntry | SchemaEntry[];
266
- }
267
-
268
- /**
269
- * A property definition with explicit type(s), an optional requirement flag, and optional validators
270
- *
271
- * @example
272
- * ```ts
273
- * const prop: SchemaProperty = {
274
- * $required: false,
275
- * $type: ['string', 'number'],
276
- * $validators: {
277
- * string: (v) => v.length > 0,
278
- * number: (v) => v > 0,
279
- * },
280
- * };
281
- * ```
282
- */
283
- export type SchemaProperty = {
284
- /**
285
- * Whether the property is required _(defaults to `true`)_
286
- */
287
- $required?: boolean;
288
- /**
289
- * The type(s) the property value must match; a single {@link SchemaPropertyType} or an array
290
- */
291
- $type: SchemaPropertyType | SchemaPropertyType[];
292
- /**
293
- * Optional validators keyed by {@link ValueName}, applied during validation
294
- */
295
- $validators?: PropertyValidators<SchemaPropertyType | SchemaPropertyType[]>;
296
- };
297
-
298
- /**
299
- * A union of valid types for a {@link SchemaProperty}'s `$type` field
300
- *
301
- * Can be a {@link Constructor}, {@link PlainSchema}, {@link Schematic}, {@link ValueName} string, or a custom validator function
302
- */
303
- type SchemaPropertyType =
304
- | Constructor
305
- | PlainSchema
306
- | Schematic<unknown>
307
- | ValueName
308
- | ((value: unknown) => boolean);
309
-
310
- /**
311
- * A custom error class for schematic validation failures
312
- */
313
- export class SchematicError extends Error {
314
- constructor(message: string) {
315
- super(message);
316
-
317
- this.name = ERROR_NAME;
318
- }
319
- }
320
-
321
- /**
322
- * Converts a type into its corresponding {@link SchemaPropertyType}-representation
323
- *
324
- * Deduplicates and unwraps single-element tuples via {@link UnwrapSingle}
325
- *
326
- * @template Value - type to convert
327
- */
328
- type ToSchemaPropertyType<Value> = UnwrapSingle<
329
- DeduplicateTuple<MapToSchemaPropertyTypes<UnionToTuple<Value>>>
330
- >;
331
-
332
- /**
333
- * Converts a single type to its schema property equivalent
334
- *
335
- * {@link NestedSchema} values have `$required` stripped, plain objects become {@link TypedSchema}, and primitives go through {@link ToValueType}
336
- *
337
- * @template Value - type to convert
338
- */
339
- type ToSchemaPropertyTypeEach<Value> = Value extends PlainObject
340
- ? TypedSchema<Value>
341
- : ToValueType<Value>;
342
-
343
- /**
344
- * Converts a type into its corresponding {@link ValueName}-representation
345
- *
346
- * Deduplicates and unwraps single-element tuples via {@link UnwrapSingle}
347
- *
348
- * @template Value - type to convert
349
- */
350
- type ToSchemaType<Value> = UnwrapSingle<DeduplicateTuple<MapToValueTypes<UnionToTuple<Value>>>>;
351
-
352
- /**
353
- * Maps a type to its {@link ValueName} string equivalent
354
- *
355
- * Resolves {@link Schematic} types as-is, then performs a reverse-lookup against {@link Values} _(excluding `'object'`)_ to find a matching key. If no match is found, `object` types resolve to `'object'` or a type-guard function, and all other unrecognised types resolve to a type-guard function
356
- *
357
- * @template Value - type to map
358
- *
359
- * @example
360
- * ```ts
361
- * // ToValueType<string> => 'string'
362
- * // ToValueType<number[]> => 'array'
363
- * // ToValueType<Date> => 'date'
364
- * ```
365
- */
366
- type ToValueType<Value> =
367
- Value extends Schematic<any>
368
- ? Value
369
- : {
370
- [Key in keyof Omit<Values, 'object'>]: Value extends Values[Key] ? Key : never;
371
- }[keyof Omit<Values, 'object'>] extends infer Match
372
- ? [Match] extends [never]
373
- ? Value extends object
374
- ? 'object' | ((value: unknown) => value is Value)
375
- : (value: unknown) => value is Value
376
- : Match
377
- : never;
378
-
379
- /**
380
- * Generates all permutations of a tuple type
381
- *
382
- * Used by {@link UnwrapSingle} to allow schema types in any order for small tuples _(length ≤ 5)_
383
- *
384
- * @template Tuple - Tuple to permute
385
- * @template Elput - Accumulator for the current permutation _(internal; name is Tuple backwards)_
386
- *
387
- * @example
388
- * ```ts
389
- * // TuplePermutations<['string', 'number']>
390
- * // => ['string', 'number'] | ['number', 'string']
391
- * ```
392
- */
393
- type TuplePermutations<
394
- Tuple extends unknown[],
395
- Elput extends unknown[] = [],
396
- > = Tuple['length'] extends 0
397
- ? Elput
398
- : {
399
- [Key in keyof Tuple]: TuplePermutations<
400
- TupleRemoveAt<Tuple, Key & `${number}`>,
401
- [...Elput, Tuple[Key]]
402
- >;
403
- }[keyof Tuple & `${number}`];
404
-
405
- /**
406
- * Removes the element at a given index from a tuple
407
- *
408
- * Used internally by {@link TuplePermutations}
409
- *
410
- * @template Items - Tuple to remove from
411
- * @template Item - Stringified index to remove
412
- * @template Prefix - Accumulator for elements before the target _(internal)_
413
- */
414
- type TupleRemoveAt<
415
- Items extends unknown[],
416
- Item extends string,
417
- Prefix extends unknown[] = [],
418
- > = Items extends [infer Head, ...infer Tail]
419
- ? `${Prefix['length']}` extends Item
420
- ? [...Prefix, ...Tail]
421
- : TupleRemoveAt<Tail, Item, [...Prefix, Head]>
422
- : Prefix;
423
-
424
- /**
425
- * A typed optional property definition generated by {@link TypedSchema} for optional keys, with `$required` set to `false` and excludes `undefined` from the type
426
- *
427
- * @template Value - Property's type _(including `undefined`)_
428
- *
429
- * @example
430
- * ```ts
431
- * // For `{ name?: string }`, the `name` key produces:
432
- * // TypedPropertyOptional<string | undefined>
433
- * // => { $required: false; $type: 'string'; ... }
434
- * ```
435
- */
436
- export type TypedPropertyOptional<Value> = {
437
- /**
438
- * The property is not required
439
- */
440
- $required: false;
441
- /**
442
- * The type(s) of the property
443
- */
444
- $type: ToSchemaPropertyType<Exclude<Value, undefined>>;
445
- /**
446
- * Custom validators for the property and its types
447
- */
448
- $validators?: PropertyValidators<ToSchemaPropertyType<Exclude<Value, undefined>>>;
449
- };
450
-
451
- /**
452
- * A typed required property definition generated by {@link TypedSchema} for required keys, with `$required` defaulting to `true`
453
- *
454
- * @template Value - Property's type
455
- *
456
- * @example
457
- * ```ts
458
- * // For `{ name: string }`, the `name` key produces:
459
- * // TypedPropertyRequired<string>
460
- * // => { $required?: true; $type: 'string'; ... }
461
- * ```
462
- */
463
- export type TypedPropertyRequired<Value> = {
464
- /**
465
- * The property is required _(defaults to `true`)_
466
- */
467
- $required?: true;
468
- /**
469
- * The type(s) of the property
470
- */
471
- $type: ToSchemaPropertyType<Value>;
472
- /**
473
- * Custom validators for the property and its types
474
- */
475
- $validators?: PropertyValidators<ToSchemaPropertyType<Value>>;
476
- };
477
-
478
- /**
479
- * Creates a schema type constrained to match a TypeScript type
480
- *
481
- * Required keys map to {@link ToSchemaType} or {@link TypedPropertyRequired}; plain object values may also use {@link Schematic}. Optional keys map to {@link TypedPropertyOptional} or, for plain objects, {@link TypedSchemaOptional}
482
- *
483
- * @template Model - Object type to generate a schema for
484
- *
485
- * @example
486
- * ```ts
487
- * type User = { name: string; age: number; bio?: string };
488
- *
489
- * const schema: TypedSchema<User> = {
490
- * name: 'string',
491
- * age: 'number',
492
- * bio: { $required: false, $type: 'string' },
493
- * };
494
- * ```
495
- */
496
- export type TypedSchema<Model extends PlainObject> = Simplify<
497
- {
498
- [Key in RequiredKeys<Model>]: Model[Key] extends PlainObject
499
- ? TypedSchemaRequired<Model[Key]> | Schematic<Model[Key]>
500
- : ToSchemaType<Model[Key]> | TypedPropertyRequired<Model[Key]>;
501
- } & {
502
- [Key in OptionalKeys<Model>]: Exclude<Model[Key], undefined> extends PlainObject
503
- ?
504
- | TypedSchemaOptional<Exclude<Model[Key], undefined>>
505
- | Schematic<Exclude<Model[Key], undefined>>
506
- : TypedPropertyOptional<Model[Key]>;
507
- }
508
- >;
509
-
510
- /**
511
- * A {@link TypedSchema} variant for optional nested objects, with `$required` fixed to `false`
512
- *
513
- * @template Model - Nested object type
514
- */
515
- type TypedSchemaOptional<Model extends PlainObject> = {
516
- $required: false;
517
- } & TypedSchema<Model>;
518
-
519
- /**
520
- * A {@link TypedSchema} variant for required nested objects, with `$required` defaulting to `true`
521
- *
522
- * @template Model - Nested object type
523
- */
524
- type TypedSchemaRequired<Model extends PlainObject> = {
525
- $required?: true;
526
- } & TypedSchema<Model>;
527
-
528
- /**
529
- * Converts a union type into an intersection
530
- *
531
- * Uses the contravariance of function parameter types to collapse a union into an intersection
532
- *
533
- * @template Value - Union type to convert
534
- *
535
- * @example
536
- * ```ts
537
- * // UnionToIntersection<{ a: 1 } | { b: 2 }>
538
- * // => { a: 1 } & { b: 2 }
539
- * ```
540
- */
541
- type UnionToIntersection<Value> = (Value extends unknown ? (value: Value) => void : never) extends (
542
- value: infer Item,
543
- ) => void
544
- ? Item
545
- : never;
546
-
547
- /**
548
- * Converts a union type into an ordered tuple
549
- *
550
- * Repeatedly extracts the {@link LastOfUnion} member and prepends it to the accumulator
551
- *
552
- * @template Value - Union type to convert
553
- * @template Items - Accumulator for the resulting tuple _(internal)_
554
- *
555
- * @example
556
- * ```ts
557
- * // UnionToTuple<'a' | 'b' | 'c'>
558
- * // => ['a', 'b', 'c']
559
- * ```
560
- */
561
- type UnionToTuple<Value, Items extends unknown[] = []> = [Value] extends [never]
562
- ? Items
563
- : UnionToTuple<Exclude<Value, LastOfUnion<Value>>, [LastOfUnion<Value>, ...Items]>;
564
-
565
- /**
566
- * Unwraps a single-element tuple to its inner type
567
- *
568
- * For tuples of length 2–5, returns all {@link TuplePermutations} to allow types in any order. Longer tuples are returned as-is
569
- *
570
- * @template Value - Tuple to potentially unwrap
571
- *
572
- * @example
573
- * ```ts
574
- * // UnwrapSingle<['string']> => 'string'
575
- * // UnwrapSingle<['string', 'number']> => ['string', 'number'] | ['number', 'string']
576
- * ```
577
- */
578
- type UnwrapSingle<Value extends unknown[]> = Value extends [infer Only]
579
- ? Only
580
- : Value['length'] extends 1 | 2 | 3 | 4 | 5
581
- ? TuplePermutations<Value>
582
- : Value;
583
-
584
- /**
585
- * The runtime representation of a parsed schema property, used internally during validation
586
- *
587
- * @example
588
- * ```ts
589
- * const parsed: ValidatedProperty = {
590
- * key: 'age',
591
- * required: true,
592
- * types: ['number'],
593
- * validators: { number: [(v) => v > 0] },
594
- * };
595
- * ```
596
- */
597
- export type ValidatedProperty = {
598
- /**
599
- * The property name in the schema
600
- */
601
- key: string;
602
- /**
603
- * Whether the property is required
604
- */
605
- required: boolean;
606
- /**
607
- * The allowed types for this property
608
- */
609
- types: ValidatedPropertyType[];
610
- /**
611
- * Custom validators grouped by {@link ValueName}
612
- */
613
- validators: ValidatedPropertyValidators;
614
- };
615
-
616
- /**
617
- * A union of valid types for a {@link ValidatedProperty}'s `types` array
618
- *
619
- * Can be a callback _(custom validator)_, a {@link Schematic}, a nested {@link ValidatedProperty}, or a {@link ValueName} string
620
- */
621
- export type ValidatedPropertyType =
622
- | GenericCallback
623
- | Schematic<unknown>
624
- | ValidatedProperty
625
- | ValueName;
626
-
627
- /**
628
- * A map of validator functions keyed by {@link ValueName}, used at runtime in {@link ValidatedProperty}
629
- *
630
- * Each key holds an array of validator functions that receive an `unknown` value and return a `boolean`
631
- */
632
- export type ValidatedPropertyValidators = {
633
- [Key in ValueName]?: Array<(value: unknown) => boolean>;
634
- };
635
-
636
- /**
637
- * Basic value types
638
- */
639
- export type ValueName = keyof Values;
640
-
641
- /**
642
- * Maps type name strings to their TypeScript equivalents
643
- *
644
- * Used by the type system to resolve {@link ValueName} strings into actual types
645
- *
646
- * @example
647
- * ```ts
648
- * // Values['string'] => string
649
- * // Values['date'] => Date
650
- * // Values['null'] => null
651
- * ```
652
- */
653
- export type Values = {
654
- array: unknown[];
655
- bigint: bigint;
656
- boolean: boolean;
657
- date: Date;
658
- function: Function;
659
- null: null;
660
- number: number;
661
- object: object;
662
- string: string;
663
- symbol: symbol;
664
- undefined: undefined;
665
- };