@react-querybuilder/core 8.9.2 → 8.11.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 (113) hide show
  1. package/dist/{arrayUtils-BF1P8iHS.mjs → arrayUtils-A_OXU9W1.mjs} +3 -75
  2. package/dist/arrayUtils-A_OXU9W1.mjs.map +1 -0
  3. package/dist/arrayUtils-QxZOZTf6.js +73 -0
  4. package/dist/arrayUtils-QxZOZTf6.js.map +1 -0
  5. package/dist/basic-DEc65Kng.d.mts +363 -0
  6. package/dist/basic-Dd_M2f3M.d.ts +363 -0
  7. package/dist/cjs/react-querybuilder_core.cjs.development.d.ts +806 -1366
  8. package/dist/cjs/react-querybuilder_core.cjs.development.js +455 -116
  9. package/dist/cjs/react-querybuilder_core.cjs.development.js.map +1 -1
  10. package/dist/cjs/react-querybuilder_core.cjs.production.d.ts +806 -1366
  11. package/dist/cjs/react-querybuilder_core.cjs.production.js +1 -1
  12. package/dist/cjs/react-querybuilder_core.cjs.production.js.map +1 -1
  13. package/dist/{convertQuery-H7RhQiIc.mjs → convertQuery-CqX3rPvj.mjs} +3 -3
  14. package/dist/{convertQuery-H7RhQiIc.mjs.map → convertQuery-CqX3rPvj.mjs.map} +1 -1
  15. package/dist/{export-DyrnTh6K.d.ts → export-Dy4FckB-.d.ts} +7 -6
  16. package/dist/{export-r-V7bU31.d.mts → export-t1V2N8pz.d.mts} +7 -6
  17. package/dist/formatQuery.d.mts +3 -2
  18. package/dist/formatQuery.d.ts +3 -2
  19. package/dist/formatQuery.js +217 -87
  20. package/dist/formatQuery.js.map +1 -1
  21. package/dist/formatQuery.mjs +217 -87
  22. package/dist/formatQuery.mjs.map +1 -1
  23. package/dist/{import-Cksobmln.d.ts → import-Cz8canKo.d.mts} +3 -3
  24. package/dist/{import-BwbbP4oU.d.mts → import-DtS9Ocx5.d.ts} +3 -3
  25. package/dist/{isRuleGroup-CnhYpLOM.mjs → isRuleGroup-CYcfPgbg.mjs} +2 -2
  26. package/dist/{isRuleGroup-CnhYpLOM.mjs.map → isRuleGroup-CYcfPgbg.mjs.map} +1 -1
  27. package/dist/lexer-C53tqS2p.js +406 -0
  28. package/dist/lexer-C53tqS2p.js.map +1 -0
  29. package/dist/{optGroupUtils-CXLgyg2i.js → optGroupUtils-B0hTpodo.js} +114 -1
  30. package/dist/optGroupUtils-B0hTpodo.js.map +1 -0
  31. package/dist/{optGroupUtils-Duv-M8rf.mjs → optGroupUtils-VeZ3k7-1.mjs} +86 -3
  32. package/dist/optGroupUtils-VeZ3k7-1.mjs.map +1 -0
  33. package/dist/parseCEL.d.mts +292 -11
  34. package/dist/parseCEL.d.ts +292 -11
  35. package/dist/parseCEL.js +874 -1125
  36. package/dist/parseCEL.js.map +1 -1
  37. package/dist/parseCEL.mjs +828 -1126
  38. package/dist/parseCEL.mjs.map +1 -1
  39. package/dist/parseJSONata.d.mts +3 -2
  40. package/dist/parseJSONata.d.ts +3 -2
  41. package/dist/parseJSONata.js +49 -77
  42. package/dist/parseJSONata.js.map +1 -1
  43. package/dist/parseJSONata.mjs +4 -5
  44. package/dist/parseJSONata.mjs.map +1 -1
  45. package/dist/parseJsonLogic.d.mts +4 -3
  46. package/dist/parseJsonLogic.d.ts +4 -3
  47. package/dist/parseJsonLogic.js +5 -6
  48. package/dist/parseJsonLogic.js.map +1 -1
  49. package/dist/parseJsonLogic.mjs +5 -6
  50. package/dist/parseJsonLogic.mjs.map +1 -1
  51. package/dist/parseMongoDB.d.mts +3 -2
  52. package/dist/parseMongoDB.d.ts +3 -2
  53. package/dist/parseMongoDB.js +15 -16
  54. package/dist/parseMongoDB.js.map +1 -1
  55. package/dist/parseMongoDB.mjs +5 -6
  56. package/dist/parseMongoDB.mjs.map +1 -1
  57. package/dist/{parseNumber-BtGKa58z.mjs → parseNumber-CXdMVNFx.mjs} +2 -2
  58. package/dist/{parseNumber-BtGKa58z.mjs.map → parseNumber-CXdMVNFx.mjs.map} +1 -1
  59. package/dist/{parseNumber-Bcys1kOH.js → parseNumber-D4iQDxK-.js} +1 -1
  60. package/dist/{parseNumber-Bcys1kOH.js.map → parseNumber-D4iQDxK-.js.map} +1 -1
  61. package/dist/parseSQL.d.mts +3 -2
  62. package/dist/parseSQL.d.ts +3 -2
  63. package/dist/parseSQL.js +2691 -3036
  64. package/dist/parseSQL.js.map +1 -1
  65. package/dist/parseSQL.mjs +2691 -3037
  66. package/dist/parseSQL.mjs.map +1 -1
  67. package/dist/parseSpEL.d.mts +3 -2
  68. package/dist/parseSpEL.d.ts +3 -2
  69. package/dist/parseSpEL.js +7 -9
  70. package/dist/parseSpEL.js.map +1 -1
  71. package/dist/parseSpEL.mjs +5 -6
  72. package/dist/parseSpEL.mjs.map +1 -1
  73. package/dist/{prepareQueryObjects-BqFEs4eV.js → prepareQueryObjects-BOUWfel5.js} +4 -5
  74. package/dist/prepareQueryObjects-BOUWfel5.js.map +1 -0
  75. package/dist/{prepareQueryObjects-CS6Wmhmf.mjs → prepareQueryObjects-DPCC-iHp.mjs} +6 -7
  76. package/dist/prepareQueryObjects-DPCC-iHp.mjs.map +1 -0
  77. package/dist/query-builder-layout.css +1 -1
  78. package/dist/query-builder-layout.css.map +1 -1
  79. package/dist/query-builder.css +1 -1
  80. package/dist/query-builder.css.map +1 -1
  81. package/dist/react-querybuilder_core.d.mts +806 -1366
  82. package/dist/react-querybuilder_core.legacy-esm.d.ts +806 -1366
  83. package/dist/react-querybuilder_core.legacy-esm.js +455 -114
  84. package/dist/react-querybuilder_core.legacy-esm.js.map +1 -1
  85. package/dist/react-querybuilder_core.mjs +448 -117
  86. package/dist/react-querybuilder_core.mjs.map +1 -1
  87. package/dist/react-querybuilder_core.production.d.mts +806 -1366
  88. package/dist/react-querybuilder_core.production.mjs +1 -1
  89. package/dist/react-querybuilder_core.production.mjs.map +1 -1
  90. package/dist/styles/_layout.scss +61 -17
  91. package/dist/styles/_main.scss +22 -4
  92. package/dist/{transformQuery-FL_nlpp5.js → transformQuery-CWDPogO5.js} +1 -1
  93. package/dist/{transformQuery-FL_nlpp5.js.map → transformQuery-CWDPogO5.js.map} +1 -1
  94. package/dist/{transformQuery-DdMvmrCh.mjs → transformQuery-DCCpjtyq.mjs} +3 -3
  95. package/dist/{transformQuery-DdMvmrCh.mjs.map → transformQuery-DCCpjtyq.mjs.map} +1 -1
  96. package/dist/transformQuery.d.mts +1 -1
  97. package/dist/transformQuery.d.ts +1 -1
  98. package/dist/transformQuery.js +1 -1
  99. package/dist/transformQuery.mjs +2 -2
  100. package/package.json +14 -12
  101. package/dist/arrayUtils-BF1P8iHS.mjs.map +0 -1
  102. package/dist/arrayUtils-D5EoIsKP.js +0 -164
  103. package/dist/arrayUtils-D5EoIsKP.js.map +0 -1
  104. package/dist/basic-BfD-7CN3.d.mts +0 -1235
  105. package/dist/basic-C8xXKHIA.d.ts +0 -1235
  106. package/dist/objectUtils-BBZSfZJz.js +0 -17
  107. package/dist/objectUtils-BBZSfZJz.js.map +0 -1
  108. package/dist/objectUtils-BtWdcZVG.mjs +0 -11
  109. package/dist/objectUtils-BtWdcZVG.mjs.map +0 -1
  110. package/dist/optGroupUtils-CXLgyg2i.js.map +0 -1
  111. package/dist/optGroupUtils-Duv-M8rf.mjs.map +0 -1
  112. package/dist/prepareQueryObjects-BqFEs4eV.js.map +0 -1
  113. package/dist/prepareQueryObjects-CS6Wmhmf.mjs.map +0 -1
@@ -1,1235 +0,0 @@
1
- //#region src/types/type-fest/is-equal.d.ts
2
- /**
3
- Returns a boolean for whether the two given types are equal.
4
-
5
- @link https://github.com/microsoft/TypeScript/issues/27024#issuecomment-421529650
6
- @link https://stackoverflow.com/questions/68961864/how-does-the-equals-work-in-typescript/68963796#68963796
7
-
8
- Use-cases:
9
- - If you want to make a conditional branch based on the result of a comparison of two types.
10
-
11
- @example
12
- ```
13
- import type {IsEqual} from 'type-fest';
14
-
15
- // This type returns a boolean for whether the given array includes the given item.
16
- // `IsEqual` is used to compare the given array at position 0 and the given item and then return true if they are equal.
17
- type Includes<Value extends readonly any[], Item> =
18
- Value extends readonly [Value[0], ...infer rest]
19
- ? IsEqual<Value[0], Item> extends true
20
- ? true
21
- : Includes<rest, Item>
22
- : false;
23
- ```
24
-
25
- @group type-fest
26
- */
27
- type IsEqual<A, B> = (<G>() => G extends A & G | G ? 1 : 2) extends (<G>() => G extends B & G | G ? 1 : 2) ? true : false;
28
- //#endregion
29
- //#region src/types/type-fest/is-never.d.ts
30
- /**
31
- Returns a boolean for whether the given type is `never`.
32
-
33
- @link https://github.com/microsoft/TypeScript/issues/31751#issuecomment-498526919
34
- @link https://stackoverflow.com/a/53984913/10292952
35
- @link https://www.zhenghao.io/posts/ts-never
36
-
37
- Useful in type utilities, such as checking if something does not occur.
38
-
39
- @example
40
- ```
41
- import type {IsNever, And} from 'type-fest';
42
-
43
- // https://github.com/andnp/SimplyTyped/blob/master/src/types/strings.ts
44
- type AreStringsEqual<A extends string, B extends string> =
45
- And<
46
- IsNever<Exclude<A, B>> extends true ? true : false,
47
- IsNever<Exclude<B, A>> extends true ? true : false
48
- >;
49
-
50
- type EndIfEqual<I extends string, O extends string> =
51
- AreStringsEqual<I, O> extends true
52
- ? never
53
- : void;
54
-
55
- function endIfEqual<I extends string, O extends string>(input: I, output: O): EndIfEqual<I, O> {
56
- if (input === output) {
57
- process.exit(0);
58
- }
59
- }
60
-
61
- endIfEqual('abc', 'abc');
62
- //=> never
63
-
64
- endIfEqual('abc', '123');
65
- //=> void
66
- ```
67
-
68
- @group type-fest
69
- */
70
- type IsNever<T> = [T] extends [never] ? true : false;
71
- //#endregion
72
- //#region src/types/type-fest/if-never.d.ts
73
- /**
74
- An if-else-like type that resolves depending on whether the given type is `never`.
75
-
76
- @see {@link IsNever}
77
-
78
- @example
79
- ```
80
- import type {IfNever} from 'type-fest';
81
-
82
- type ShouldBeTrue = IfNever<never>;
83
- //=> true
84
-
85
- type ShouldBeBar = IfNever<'not never', 'foo', 'bar'>;
86
- //=> 'bar'
87
- ```
88
-
89
- @group type-fest
90
- */
91
- type IfNever$1<T, TypeIfNever = true, TypeIfNotNever = false> = (IsNever<T> extends true ? TypeIfNever : TypeIfNotNever);
92
- //#endregion
93
- //#region src/types/type-fest/unknown-array.d.ts
94
- /**
95
- Represents an array with `unknown` value.
96
-
97
- Use case: You want a type that all arrays can be assigned to, but you don't care about the value.
98
-
99
- @example
100
- ```
101
- import type {UnknownArray} from 'type-fest';
102
-
103
- type IsArray<T> = T extends UnknownArray ? true : false;
104
-
105
- type A = IsArray<['foo']>;
106
- //=> true
107
-
108
- type B = IsArray<readonly number[]>;
109
- //=> true
110
-
111
- type C = IsArray<string>;
112
- //=> false
113
- ```
114
-
115
- @group type-fest
116
- */
117
- type UnknownArray = readonly unknown[];
118
- //#endregion
119
- //#region src/types/type-fest/internal/array.d.ts
120
-
121
- /**
122
- Returns whether the given array `T` is readonly.
123
-
124
- @group type-fest
125
- */
126
- type IsArrayReadonly<T extends UnknownArray> = IfNever$1<T, false, T extends unknown[] ? false : true>;
127
- /**
128
- An if-else-like type that resolves depending on whether the given array is readonly.
129
-
130
- @see {@link IsArrayReadonly}
131
-
132
- @example
133
- ```
134
- import type {ArrayTail} from 'type-fest';
135
-
136
- type ReadonlyPreservingArrayTail<TArray extends readonly unknown[]> =
137
- ArrayTail<TArray> extends infer Tail
138
- ? IfArrayReadonly<TArray, Readonly<Tail>, Tail>
139
- : never;
140
-
141
- type ReadonlyTail = ReadonlyPreservingArrayTail<readonly [string, number, boolean]>;
142
- //=> readonly [number, boolean]
143
-
144
- type NonReadonlyTail = ReadonlyPreservingArrayTail<[string, number, boolean]>;
145
- //=> [number, boolean]
146
-
147
- type ShouldBeTrue = IfArrayReadonly<readonly unknown[]>;
148
- //=> true
149
-
150
- type ShouldBeBar = IfArrayReadonly<unknown[], 'foo', 'bar'>;
151
- //=> 'bar'
152
- ```
153
-
154
- @group type-fest
155
- */
156
- type IfArrayReadonly<T extends UnknownArray, TypeIfArrayReadonly = true, TypeIfNotArrayReadonly = false> = IsArrayReadonly<T> extends infer Result ? Result extends true ? TypeIfArrayReadonly : TypeIfNotArrayReadonly : never;
157
- //#endregion
158
- //#region src/types/type-fest/is-any.d.ts
159
- type NoInfer<T> = T extends infer U ? U : never;
160
- /**
161
- Returns a boolean for whether the given type is `any`.
162
-
163
- @link https://stackoverflow.com/a/49928360/1490091
164
-
165
- Useful in type utilities, such as disallowing `any`s to be passed to a function.
166
-
167
- @example
168
- ```
169
- import type {IsAny} from 'type-fest';
170
-
171
- const typedObject = {a: 1, b: 2} as const;
172
- const anyObject: any = {a: 1, b: 2};
173
-
174
- function get<O extends (IsAny<O> extends true ? {} : Record<string, number>), K extends keyof O = keyof O>(obj: O, key: K) {
175
- return obj[key];
176
- }
177
-
178
- const typedA = get(typedObject, 'a');
179
- //=> 1
180
-
181
- const anyA = get(anyObject, 'a');
182
- //=> any
183
- ```
184
-
185
- @group type-fest
186
- */
187
- type IsAny<T> = 0 extends 1 & NoInfer<T> ? true : false;
188
- //#endregion
189
- //#region src/types/type-fest/simplify.d.ts
190
- /**
191
- Useful to flatten the type output to improve type hints shown in editors. And also to transform an interface into a type to aide with assignability.
192
-
193
- @example
194
- ```
195
- import type {Simplify} from 'type-fest';
196
-
197
- type PositionProps = {
198
- top: number;
199
- left: number;
200
- };
201
-
202
- type SizeProps = {
203
- width: number;
204
- height: number;
205
- };
206
-
207
- // In your editor, hovering over `Props` will show a flattened object with all the properties.
208
- type Props = Simplify<PositionProps & SizeProps>;
209
- ```
210
-
211
- Sometimes it is desired to pass a value as a function argument that has a different type. At first inspection it may seem assignable, and then you discover it is not because the `value`'s type definition was defined as an interface. In the following example, `fn` requires an argument of type `Record<string, unknown>`. If the value is defined as a literal, then it is assignable. And if the `value` is defined as type using the `Simplify` utility the value is assignable. But if the `value` is defined as an interface, it is not assignable because the interface is not sealed and elsewhere a non-string property could be added to the interface.
212
-
213
- If the type definition must be an interface (perhaps it was defined in a third-party npm package), then the `value` can be defined as `const value: Simplify<SomeInterface> = ...`. Then `value` will be assignable to the `fn` argument. Or the `value` can be cast as `Simplify<SomeInterface>` if you can't re-declare the `value`.
214
-
215
- @example
216
- ```
217
- import type {Simplify} from 'type-fest';
218
-
219
- interface SomeInterface {
220
- foo: number;
221
- bar?: string;
222
- baz: number | undefined;
223
- }
224
-
225
- type SomeType = {
226
- foo: number;
227
- bar?: string;
228
- baz: number | undefined;
229
- };
230
-
231
- const literal = {foo: 123, bar: 'hello', baz: 456};
232
- const someType: SomeType = literal;
233
- const someInterface: SomeInterface = literal;
234
-
235
- function fn(object: Record<string, unknown>): void {}
236
-
237
- fn(literal); // Good: literal object type is sealed
238
- fn(someType); // Good: type is sealed
239
- fn(someInterface); // Error: Index signature for type 'string' is missing in type 'someInterface'. Because `interface` can be re-opened
240
- fn(someInterface as Simplify<SomeInterface>); // Good: transform an `interface` into a `type`
241
- ```
242
-
243
- @link https://github.com/microsoft/TypeScript/issues/15300
244
- @see SimplifyDeep
245
-
246
- @group type-fest
247
- */
248
- type Simplify<T> = { [KeyType in keyof T]: T[KeyType] } & {};
249
- //#endregion
250
- //#region src/types/type-fest/union-to-intersection.d.ts
251
- /**
252
- Convert a union type to an intersection type using [distributive conditional types](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-8.html#distributive-conditional-types).
253
-
254
- Inspired by [this Stack Overflow answer](https://stackoverflow.com/a/50375286/2172153).
255
-
256
- @example
257
- ```
258
- import type {UnionToIntersection} from 'type-fest';
259
-
260
- type Union = {the(): void} | {great(arg: string): void} | {escape: boolean};
261
-
262
- type Intersection = UnionToIntersection<Union>;
263
- //=> {the(): void; great(arg: string): void; escape: boolean};
264
- ```
265
-
266
- A more applicable example which could make its way into your library code follows.
267
-
268
- @example
269
- ```
270
- import type {UnionToIntersection} from 'type-fest';
271
-
272
- class CommandOne {
273
- commands: {
274
- a1: () => undefined,
275
- b1: () => undefined,
276
- }
277
- }
278
-
279
- class CommandTwo {
280
- commands: {
281
- a2: (argA: string) => undefined,
282
- b2: (argB: string) => undefined,
283
- }
284
- }
285
-
286
- const union = [new CommandOne(), new CommandTwo()].map(instance => instance.commands);
287
- type Union = typeof union;
288
- //=> {a1(): void; b1(): void} | {a2(argA: string): void; b2(argB: string): void}
289
-
290
- type Intersection = UnionToIntersection<Union>;
291
- //=> {a1(): void; b1(): void; a2(argA: string): void; b2(argB: string): void}
292
- ```
293
-
294
- @group type-fest
295
- */
296
- type UnionToIntersection<Union> = (Union extends unknown ? (distributedUnion: Union) => void : never) extends ((mergedIntersection: infer Intersection) => void) ? Intersection & Union : never;
297
- //#endregion
298
- //#region src/types/type-fest/keys-of-union.d.ts
299
- /**
300
- Create a union of all keys from a given type, even those exclusive to specific union members.
301
-
302
- Unlike the native `keyof` keyword, which returns keys present in **all** union members, this type returns keys from **any** member.
303
-
304
- @link https://stackoverflow.com/a/49402091
305
-
306
- @example
307
- ```
308
- import type {KeysOfUnion} from 'type-fest';
309
-
310
- type A = {
311
- common: string;
312
- a: number;
313
- };
314
-
315
- type B = {
316
- common: string;
317
- b: string;
318
- };
319
-
320
- type C = {
321
- common: string;
322
- c: boolean;
323
- };
324
-
325
- type Union = A | B | C;
326
-
327
- type CommonKeys = keyof Union;
328
- //=> 'common'
329
-
330
- type AllKeys = KeysOfUnion<Union>;
331
- //=> 'common' | 'a' | 'b' | 'c'
332
- ```
333
-
334
- @group type-fest
335
- */
336
- type KeysOfUnion<ObjectType> = keyof UnionToIntersection<ObjectType extends unknown ? Record<keyof ObjectType, never> : never>;
337
- //#endregion
338
- //#region src/types/type-fest/optional-keys-of.d.ts
339
- /**
340
- Extract all optional keys from the given type.
341
-
342
- This is useful when you want to create a new type that contains different type values for the optional keys only.
343
-
344
- @example
345
- ```
346
- import type {OptionalKeysOf, Except} from 'type-fest';
347
-
348
- interface User {
349
- name: string;
350
- surname: string;
351
-
352
- luckyNumber?: number;
353
- }
354
-
355
- const REMOVE_FIELD = Symbol('remove field symbol');
356
- type UpdateOperation<Entity extends object> = Except<Partial<Entity>, OptionalKeysOf<Entity>> & {
357
- [Key in OptionalKeysOf<Entity>]?: Entity[Key] | typeof REMOVE_FIELD;
358
- };
359
-
360
- const update1: UpdateOperation<User> = {
361
- name: 'Alice'
362
- };
363
-
364
- const update2: UpdateOperation<User> = {
365
- name: 'Bob',
366
- luckyNumber: REMOVE_FIELD
367
- };
368
- ```
369
-
370
- @group type-fest
371
- */
372
- type OptionalKeysOf<BaseType extends object> = BaseType extends unknown ? (keyof { [Key in keyof BaseType as BaseType extends Record<Key, BaseType[Key]> ? never : Key]: never }) & (keyof BaseType) : never;
373
- //#endregion
374
- //#region src/types/type-fest/required-keys-of.d.ts
375
- /**
376
- Extract all required keys from the given type.
377
-
378
- This is useful when you want to create a new type that contains different type values for the required keys only or use the list of keys for validation purposes, etc...
379
-
380
- @example
381
- ```
382
- import type {RequiredKeysOf} from 'type-fest';
383
-
384
- declare function createValidation<Entity extends object, Key extends RequiredKeysOf<Entity> = RequiredKeysOf<Entity>>(field: Key, validator: (value: Entity[Key]) => boolean): ValidatorFn;
385
-
386
- interface User {
387
- name: string;
388
- surname: string;
389
-
390
- luckyNumber?: number;
391
- }
392
-
393
- const validator1 = createValidation<User>('name', value => value.length < 25);
394
- const validator2 = createValidation<User>('surname', value => value.length < 25);
395
- ```
396
-
397
- @group type-fest
398
- */
399
- type RequiredKeysOf<BaseType extends object> = BaseType extends unknown ? Exclude<keyof BaseType, OptionalKeysOf<BaseType>> : never;
400
- //#endregion
401
- //#region src/types/type-fest/omit-index-signature.d.ts
402
- /**
403
- Omit any index signatures from the given object type, leaving only explicitly defined properties.
404
-
405
- This is the counterpart of `PickIndexSignature`.
406
-
407
- Use-cases:
408
- - Remove overly permissive signatures from third-party types.
409
-
410
- This type was taken from this [StackOverflow answer](https://stackoverflow.com/a/68261113/420747).
411
-
412
- It relies on the fact that an empty object (`{}`) is assignable to an object with just an index signature, like `Record<string, unknown>`, but not to an object with explicitly defined keys, like `Record<'foo' | 'bar', unknown>`.
413
-
414
- (The actual value type, `unknown`, is irrelevant and could be any type. Only the key type matters.)
415
-
416
- ```
417
- const indexed: Record<string, unknown> = {}; // Allowed
418
-
419
- const keyed: Record<'foo', unknown> = {}; // Error
420
- // => TS2739: Type '{}' is missing the following properties from type 'Record<"foo" | "bar", unknown>': foo, bar
421
- ```
422
-
423
- Instead of causing a type error like the above, you can also use a [conditional type](https://www.typescriptlang.org/docs/handbook/2/conditional-types.html) to test whether a type is assignable to another:
424
-
425
- ```
426
- type Indexed = {} extends Record<string, unknown>
427
- ? '✅ `{}` is assignable to `Record<string, unknown>`'
428
- : '❌ `{}` is NOT assignable to `Record<string, unknown>`';
429
- // => '✅ `{}` is assignable to `Record<string, unknown>`'
430
-
431
- type Keyed = {} extends Record<'foo' | 'bar', unknown>
432
- ? "✅ `{}` is assignable to `Record<'foo' | 'bar', unknown>`"
433
- : "❌ `{}` is NOT assignable to `Record<'foo' | 'bar', unknown>`";
434
- // => "❌ `{}` is NOT assignable to `Record<'foo' | 'bar', unknown>`"
435
- ```
436
-
437
- Using a [mapped type](https://www.typescriptlang.org/docs/handbook/2/mapped-types.html#further-exploration), you can then check for each `KeyType` of `ObjectType`...
438
-
439
- ```
440
- import type {OmitIndexSignature} from 'type-fest';
441
-
442
- type OmitIndexSignature<ObjectType> = {
443
- [KeyType in keyof ObjectType // Map each key of `ObjectType`...
444
- ]: ObjectType[KeyType]; // ...to its original value, i.e. `OmitIndexSignature<Foo> == Foo`.
445
- };
446
- ```
447
-
448
- ...whether an empty object (`{}`) would be assignable to an object with that `KeyType` (`Record<KeyType, unknown>`)...
449
-
450
- ```
451
- import type {OmitIndexSignature} from 'type-fest';
452
-
453
- type OmitIndexSignature<ObjectType> = {
454
- [KeyType in keyof ObjectType
455
- // Is `{}` assignable to `Record<KeyType, unknown>`?
456
- as {} extends Record<KeyType, unknown>
457
- ? ... // ✅ `{}` is assignable to `Record<KeyType, unknown>`
458
- : ... // ❌ `{}` is NOT assignable to `Record<KeyType, unknown>`
459
- ]: ObjectType[KeyType];
460
- };
461
- ```
462
-
463
- If `{}` is assignable, it means that `KeyType` is an index signature and we want to remove it. If it is not assignable, `KeyType` is a "real" key and we want to keep it.
464
-
465
- @example
466
- ```
467
- import type {OmitIndexSignature} from 'type-fest';
468
-
469
- interface Example {
470
- // These index signatures will be removed.
471
- [x: string]: any
472
- [x: number]: any
473
- [x: symbol]: any
474
- [x: `head-${string}`]: string
475
- [x: `${string}-tail`]: string
476
- [x: `head-${string}-tail`]: string
477
- [x: `${bigint}`]: string
478
- [x: `embedded-${number}`]: string
479
-
480
- // These explicitly defined keys will remain.
481
- foo: 'bar';
482
- qux?: 'baz';
483
- }
484
-
485
- type ExampleWithoutIndexSignatures = OmitIndexSignature<Example>;
486
- // => { foo: 'bar'; qux?: 'baz' | undefined; }
487
- ```
488
-
489
- @see PickIndexSignature
490
-
491
- @group type-fest
492
- */
493
- type OmitIndexSignature<ObjectType> = { [KeyType in keyof ObjectType as {} extends Record<KeyType, unknown> ? never : KeyType]: ObjectType[KeyType] };
494
- //#endregion
495
- //#region src/types/type-fest/pick-index-signature.d.ts
496
- /**
497
- Pick only index signatures from the given object type, leaving out all explicitly defined properties.
498
-
499
- This is the counterpart of `OmitIndexSignature`.
500
-
501
- @example
502
- ```
503
- import type {PickIndexSignature} from 'type-fest';
504
-
505
- declare const symbolKey: unique symbol;
506
-
507
- type Example = {
508
- // These index signatures will remain.
509
- [x: string]: unknown;
510
- [x: number]: unknown;
511
- [x: symbol]: unknown;
512
- [x: `head-${string}`]: string;
513
- [x: `${string}-tail`]: string;
514
- [x: `head-${string}-tail`]: string;
515
- [x: `${bigint}`]: string;
516
- [x: `embedded-${number}`]: string;
517
-
518
- // These explicitly defined keys will be removed.
519
- ['kebab-case-key']: string;
520
- [symbolKey]: string;
521
- foo: 'bar';
522
- qux?: 'baz';
523
- };
524
-
525
- type ExampleIndexSignature = PickIndexSignature<Example>;
526
- // {
527
- // [x: string]: unknown;
528
- // [x: number]: unknown;
529
- // [x: symbol]: unknown;
530
- // [x: `head-${string}`]: string;
531
- // [x: `${string}-tail`]: string;
532
- // [x: `head-${string}-tail`]: string;
533
- // [x: `${bigint}`]: string;
534
- // [x: `embedded-${number}`]: string;
535
- // }
536
- ```
537
-
538
- @see OmitIndexSignature
539
-
540
- @group type-fest
541
- */
542
- type PickIndexSignature<ObjectType> = { [KeyType in keyof ObjectType as {} extends Record<KeyType, unknown> ? KeyType : never]: ObjectType[KeyType] };
543
- //#endregion
544
- //#region src/types/type-fest/merge.d.ts
545
- type SimpleMerge<Destination, Source> = { [Key in keyof Destination as Key extends keyof Source ? never : Key]: Destination[Key] } & Source;
546
- /**
547
- Merge two types into a new type. Keys of the second type overrides keys of the first type.
548
-
549
- @example
550
- ```
551
- import type {Merge} from 'type-fest';
552
-
553
- interface Foo {
554
- [x: string]: unknown;
555
- [x: number]: unknown;
556
- foo: string;
557
- bar: symbol;
558
- }
559
-
560
- type Bar = {
561
- [x: number]: number;
562
- [x: symbol]: unknown;
563
- bar: Date;
564
- baz: boolean;
565
- };
566
-
567
- export type FooBar = Merge<Foo, Bar>;
568
- // => {
569
- // [x: string]: unknown;
570
- // [x: number]: number;
571
- // [x: symbol]: unknown;
572
- // foo: string;
573
- // bar: Date;
574
- // baz: boolean;
575
- // }
576
- ```
577
-
578
- @group type-fest
579
- */
580
- type Merge<Destination, Source> = Simplify<SimpleMerge<PickIndexSignature<Destination>, PickIndexSignature<Source>> & SimpleMerge<OmitIndexSignature<Destination>, OmitIndexSignature<Source>>>;
581
- //#endregion
582
- //#region src/types/type-fest/if-any.d.ts
583
- /**
584
- An if-else-like type that resolves depending on whether the given type is `any`.
585
-
586
- @see {@link IsAny}
587
-
588
- @example
589
- ```
590
- import type {IfAny} from 'type-fest';
591
-
592
- type ShouldBeTrue = IfAny<any>;
593
- //=> true
594
-
595
- type ShouldBeBar = IfAny<'not any', 'foo', 'bar'>;
596
- //=> 'bar'
597
- ```
598
-
599
- @group type-fest
600
- */
601
- type IfAny$1<T, TypeIfAny = true, TypeIfNotAny = false> = (IsAny<T> extends true ? TypeIfAny : TypeIfNotAny);
602
- //#endregion
603
- //#region src/types/type-fest/internal/type.d.ts
604
- /**
605
- An if-else-like type that resolves depending on whether the given type is `any` or `never`.
606
-
607
- @example
608
- ```
609
- // When `T` is a NOT `any` or `never` (like `string`) => Returns `IfNotAnyOrNever` branch
610
- type A = IfNotAnyOrNever<string, 'VALID', 'IS_ANY', 'IS_NEVER'>;
611
- //=> 'VALID'
612
-
613
- // When `T` is `any` => Returns `IfAny` branch
614
- type B = IfNotAnyOrNever<any, 'VALID', 'IS_ANY', 'IS_NEVER'>;
615
- //=> 'IS_ANY'
616
-
617
- // When `T` is `never` => Returns `IfNever` branch
618
- type C = IfNotAnyOrNever<never, 'VALID', 'IS_ANY', 'IS_NEVER'>;
619
- //=> 'IS_NEVER'
620
- ```
621
-
622
- @group type-fest
623
- */
624
- type IfNotAnyOrNever<T, IfNotAnyOrNever, IfAny = any, IfNever = never> = IsAny<T> extends true ? IfAny : IsNever<T> extends true ? IfNever : IfNotAnyOrNever;
625
- //#endregion
626
- //#region src/types/type-fest/internal/object.d.ts
627
- /**
628
- Works similar to the built-in `Pick` utility type, except for the following differences:
629
- - Distributes over union types and allows picking keys from any member of the union type.
630
- - Primitives types are returned as-is.
631
- - Picks all keys if `Keys` is `any`.
632
- - Doesn't pick `number` from a `string` index signature.
633
-
634
- @example
635
- ```
636
- type ImageUpload = {
637
- url: string;
638
- size: number;
639
- thumbnailUrl: string;
640
- };
641
-
642
- type VideoUpload = {
643
- url: string;
644
- duration: number;
645
- encodingFormat: string;
646
- };
647
-
648
- // Distributes over union types and allows picking keys from any member of the union type
649
- type MediaDisplay = HomomorphicPick<ImageUpload | VideoUpload, "url" | "size" | "duration">;
650
- //=> {url: string; size: number} | {url: string; duration: number}
651
-
652
- // Primitive types are returned as-is
653
- type Primitive = HomomorphicPick<string | number, 'toUpperCase' | 'toString'>;
654
- //=> string | number
655
-
656
- // Picks all keys if `Keys` is `any`
657
- type Any = HomomorphicPick<{a: 1; b: 2} | {c: 3}, any>;
658
- //=> {a: 1; b: 2} | {c: 3}
659
-
660
- // Doesn't pick `number` from a `string` index signature
661
- type IndexSignature = HomomorphicPick<{[k: string]: unknown}, number>;
662
- //=> {}
663
-
664
- @group type-fest
665
- */
666
- type HomomorphicPick<T, Keys extends KeysOfUnion<T>> = { [P in keyof T as Extract<P, Keys>]: T[P] };
667
- /**
668
- Merges user specified options with default options.
669
-
670
- @example
671
- ```
672
- type PathsOptions = {maxRecursionDepth?: number; leavesOnly?: boolean};
673
- type DefaultPathsOptions = {maxRecursionDepth: 10; leavesOnly: false};
674
- type SpecifiedOptions = {leavesOnly: true};
675
-
676
- type Result = ApplyDefaultOptions<PathsOptions, DefaultPathsOptions, SpecifiedOptions>;
677
- //=> {maxRecursionDepth: 10; leavesOnly: true}
678
- ```
679
-
680
- @example
681
- ```
682
- // Complains if default values are not provided for optional options
683
-
684
- type PathsOptions = {maxRecursionDepth?: number; leavesOnly?: boolean};
685
- type DefaultPathsOptions = {maxRecursionDepth: 10};
686
- type SpecifiedOptions = {};
687
-
688
- type Result = ApplyDefaultOptions<PathsOptions, DefaultPathsOptions, SpecifiedOptions>;
689
- // ~~~~~~~~~~~~~~~~~~~
690
- // Property 'leavesOnly' is missing in type 'DefaultPathsOptions' but required in type '{ maxRecursionDepth: number; leavesOnly: boolean; }'.
691
- ```
692
-
693
- @example
694
- ```
695
- // Complains if an option's default type does not conform to the expected type
696
-
697
- type PathsOptions = {maxRecursionDepth?: number; leavesOnly?: boolean};
698
- type DefaultPathsOptions = {maxRecursionDepth: 10; leavesOnly: 'no'};
699
- type SpecifiedOptions = {};
700
-
701
- type Result = ApplyDefaultOptions<PathsOptions, DefaultPathsOptions, SpecifiedOptions>;
702
- // ~~~~~~~~~~~~~~~~~~~
703
- // Types of property 'leavesOnly' are incompatible. Type 'string' is not assignable to type 'boolean'.
704
- ```
705
-
706
- @example
707
- ```
708
- // Complains if an option's specified type does not conform to the expected type
709
-
710
- type PathsOptions = {maxRecursionDepth?: number; leavesOnly?: boolean};
711
- type DefaultPathsOptions = {maxRecursionDepth: 10; leavesOnly: false};
712
- type SpecifiedOptions = {leavesOnly: 'yes'};
713
-
714
- type Result = ApplyDefaultOptions<PathsOptions, DefaultPathsOptions, SpecifiedOptions>;
715
- // ~~~~~~~~~~~~~~~~
716
- // Types of property 'leavesOnly' are incompatible. Type 'string' is not assignable to type 'boolean'.
717
- ```
718
-
719
- @group type-fest
720
- */
721
- type ApplyDefaultOptions<Options extends object, Defaults extends Simplify<Omit<Required<Options>, RequiredKeysOf<Options>> & Partial<Record<RequiredKeysOf<Options>, never>>>, SpecifiedOptions extends Options> = IfAny$1<SpecifiedOptions, Defaults, IfNever$1<SpecifiedOptions, Defaults, Simplify<Merge<Defaults, { [Key in keyof SpecifiedOptions as Key extends OptionalKeysOf<Options> ? Extract<SpecifiedOptions[Key], undefined> extends never ? Key : never : Key]: SpecifiedOptions[Key] }> & Required<Options>>>>;
722
- //#endregion
723
- //#region src/types/type-fest/except.d.ts
724
- /**
725
- Filter out keys from an object.
726
-
727
- Returns `never` if `Exclude` is strictly equal to `Key`.
728
- Returns `never` if `Key` extends `Exclude`.
729
- Returns `Key` otherwise.
730
-
731
- @example
732
- ```
733
- type Filtered = Filter<'foo', 'foo'>;
734
- //=> never
735
- ```
736
-
737
- @example
738
- ```
739
- type Filtered = Filter<'bar', string>;
740
- //=> never
741
- ```
742
-
743
- @example
744
- ```
745
- type Filtered = Filter<'bar', 'foo'>;
746
- //=> 'bar'
747
- ```
748
-
749
- @see {Except}
750
- */
751
- type Filter<KeyType, ExcludeType> = IsEqual<KeyType, ExcludeType> extends true ? never : (KeyType extends ExcludeType ? never : KeyType);
752
- type ExceptOptions = {
753
- /**
754
- Disallow assigning non-specified properties.
755
-
756
- Note that any omitted properties in the resulting type will be present in autocomplete as `undefined`.
757
-
758
- @default false
759
- */
760
- requireExactProps?: boolean;
761
- };
762
- type DefaultExceptOptions = {
763
- requireExactProps: false;
764
- };
765
- /**
766
- Create a type from an object type without certain keys.
767
-
768
- We recommend setting the `requireExactProps` option to `true`.
769
-
770
- This type is a stricter version of [`Omit`](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-5.html#the-omit-helper-type). The `Omit` type does not restrict the omitted keys to be keys present on the given type, while `Except` does. The benefits of a stricter type are avoiding typos and allowing the compiler to pick up on rename refactors automatically.
771
-
772
- This type was proposed to the TypeScript team, which declined it, saying they prefer that libraries implement stricter versions of the built-in types ([microsoft/TypeScript#30825](https://github.com/microsoft/TypeScript/issues/30825#issuecomment-523668235)).
773
-
774
- @example
775
- ```
776
- import type {Except} from 'type-fest';
777
-
778
- type Foo = {
779
- a: number;
780
- b: string;
781
- };
782
-
783
- type FooWithoutA = Except<Foo, 'a'>;
784
- //=> {b: string}
785
-
786
- const fooWithoutA: FooWithoutA = {a: 1, b: '2'};
787
- //=> errors: 'a' does not exist in type '{ b: string; }'
788
-
789
- type FooWithoutB = Except<Foo, 'b', {requireExactProps: true}>;
790
- //=> {a: number} & Partial<Record<"b", never>>
791
-
792
- const fooWithoutB: FooWithoutB = {a: 1, b: '2'};
793
- //=> errors at 'b': Type 'string' is not assignable to type 'undefined'.
794
-
795
- // The `Omit` utility type doesn't work when omitting specific keys from objects containing index signatures.
796
-
797
- // Consider the following example:
798
-
799
- type UserData = {
800
- [metadata: string]: string;
801
- email: string;
802
- name: string;
803
- role: 'admin' | 'user';
804
- };
805
-
806
- // `Omit` clearly doesn't behave as expected in this case:
807
- type PostPayload = Omit<UserData, 'email'>;
808
- //=> type PostPayload = { [x: string]: string; [x: number]: string; }
809
-
810
- // In situations like this, `Except` works better.
811
- // It simply removes the `email` key while preserving all the other keys.
812
- type PostPayload = Except<UserData, 'email'>;
813
- //=> type PostPayload = { [x: string]: string; name: string; role: 'admin' | 'user'; }
814
- ```
815
-
816
- @group type-fest
817
- */
818
- type Except<ObjectType, KeysType extends keyof ObjectType, Options extends ExceptOptions = {}> = _Except<ObjectType, KeysType, ApplyDefaultOptions<ExceptOptions, DefaultExceptOptions, Options>>;
819
- type _Except<ObjectType, KeysType extends keyof ObjectType, Options extends Required<ExceptOptions>> = { [KeyType in keyof ObjectType as Filter<KeyType, KeysType>]: ObjectType[KeyType] } & (Options["requireExactProps"] extends true ? Partial<Record<KeysType, never>> : {});
820
- //#endregion
821
- //#region src/types/type-fest/require-at-least-one.d.ts
822
- /**
823
- Create a type that requires at least one of the given keys. The remaining keys are kept as is.
824
-
825
- @example
826
- ```
827
- import type {RequireAtLeastOne} from 'type-fest';
828
-
829
- type Responder = {
830
- text?: () => string;
831
- json?: () => string;
832
- secure?: boolean;
833
- };
834
-
835
- const responder: RequireAtLeastOne<Responder, 'text' | 'json'> = {
836
- json: () => '{"message": "ok"}',
837
- secure: true
838
- };
839
- ```
840
-
841
- @group type-fest
842
- */
843
- type RequireAtLeastOne<ObjectType, KeysType extends keyof ObjectType = keyof ObjectType> = IfNotAnyOrNever<ObjectType, IfNever$1<KeysType, never, _RequireAtLeastOne<ObjectType, IfAny$1<KeysType, keyof ObjectType, KeysType>>>>;
844
- type _RequireAtLeastOne<ObjectType, KeysType extends keyof ObjectType> = { [Key in KeysType]-?: Required<Pick<ObjectType, Key>> & Partial<Pick<ObjectType, Exclude<KeysType, Key>>> }[KeysType] & Except<ObjectType, KeysType>;
845
- //#endregion
846
- //#region src/types/type-fest/set-required.d.ts
847
- /**
848
- Create a type that makes the given keys required. The remaining keys are kept as is. The sister of the `SetOptional` type.
849
-
850
- Use-case: You want to define a single model where the only thing that changes is whether or not some of the keys are required.
851
-
852
- @example
853
- ```
854
- import type {SetRequired} from 'type-fest';
855
-
856
- type Foo = {
857
- a?: number;
858
- b: string;
859
- c?: boolean;
860
- }
861
-
862
- type SomeRequired = SetRequired<Foo, 'b' | 'c'>;
863
- // type SomeRequired = {
864
- // a?: number;
865
- // b: string; // Was already required and still is.
866
- // c: boolean; // Is now required.
867
- // }
868
-
869
- // Set specific indices in an array to be required.
870
- type ArrayExample = SetRequired<[number?, number?, number?], 0 | 1>;
871
- //=> [number, number, number?]
872
- ```
873
-
874
- @group type-fest
875
- */
876
- type SetRequired<BaseType, Keys extends keyof BaseType> = BaseType extends UnknownArray ? SetArrayRequired<BaseType, Keys> extends infer ResultantArray ? IfArrayReadonly<BaseType, Readonly<ResultantArray>, ResultantArray> : never : Simplify<Except<BaseType, Keys> & Required<HomomorphicPick<BaseType, Keys>>>;
877
- /**
878
- Remove the optional modifier from the specified keys in an array.
879
- */
880
- type SetArrayRequired<TArray extends UnknownArray, Keys, Counter extends any[] = [], Accumulator extends UnknownArray = []> = TArray extends unknown ? keyof TArray & `${number}` extends never ? [...Accumulator, ...TArray] : TArray extends readonly [(infer First)?, ...infer Rest] ? "0" extends OptionalKeysOf<TArray> ? `${Counter["length"]}` extends `${Keys & (string | number)}` ? SetArrayRequired<Rest, Keys, [...Counter, any], [...Accumulator, First]> : [...Accumulator, ...TArray] : SetArrayRequired<Rest, Keys, [...Counter, any], [...Accumulator, TArray[0]]> : never : never;
881
- //#endregion
882
- //#region src/types/options.d.ts
883
- /**
884
- * Adds an `unknown` index property to an interface.
885
- */
886
- type WithUnknownIndex<T> = T & {
887
- [key: string]: unknown;
888
- };
889
- /**
890
- * Do not use this type directly; use {@link Option}, {@link ValueOption},
891
- * or {@link FullOption} instead. For specific option types, you can use
892
- * {@link FullField}, {@link FullOperator}, or {@link FullCombinator},
893
- * all of which extend {@link FullOption}.
894
- *
895
- * @group Option Lists
896
- */
897
- interface BaseOption<N extends string = string> {
898
- name?: N;
899
- value?: N;
900
- label: string;
901
- disabled?: boolean;
902
- }
903
- /**
904
- * A generic option. Used directly in {@link OptionList} or
905
- * as the child element of an {@link OptionGroup}.
906
- *
907
- * @group Option Lists
908
- */
909
- type Option<N extends string = string> = Simplify<WithUnknownIndex<SetRequired<BaseOption<N>, "name">>>;
910
- /**
911
- * A generic {@link Option} with either a `name` or `value` as its primary identifier.
912
- * {@link OptionList}-type props on the {@link QueryBuilder} component accept this type,
913
- * but corresponding props passed down to subcomponents will always be translated
914
- * to {@link FullOption} first.
915
- *
916
- * @group Option Lists
917
- */
918
- type FlexibleOption<N extends string = string> = Simplify<WithUnknownIndex<RequireAtLeastOne<BaseOption<N>, "name" | "value">>>;
919
- /**
920
- * Utility type to turn an {@link Option}, {@link ValueOption}, or {@link BaseOption}
921
- * into a {@link FlexibleOption}.
922
- *
923
- * @group Option Lists
924
- */
925
- type ToFlexibleOption<Opt extends BaseOption | string> = WithUnknownIndex<RequireAtLeastOne<Opt extends string ? FlexibleOption<Opt> : Opt, "name" | "value">>;
926
- /**
927
- * A generic {@link Option} requiring both `name` _and_ `value` properties.
928
- * Props that extend {@link OptionList} accept {@link BaseOption}, but
929
- * corresponding props sent to subcomponents will always be translated to this
930
- * type first to ensure both `name` and `value` are available.
931
- *
932
- * NOTE: Do not extend from this type directly. Use {@link BaseFullOption}
933
- * (optionally wrapped in {@link WithUnknownIndex}) instead, otherwise
934
- * the `unknown` index property will cause issues. See {@link Option} and
935
- * {@link ValueOption} for examples.
936
- *
937
- * @group Option Lists
938
- */
939
- type FullOption<N extends string = string> = Simplify<WithUnknownIndex<SetRequired<BaseOption<N>, "name" | "value">>>;
940
- /**
941
- * This type is identical to {@link FullOption} but without the `unknown` index
942
- * property. Extend from this type instead of {@link FullOption} directly.
943
- *
944
- * @group Option Lists
945
- */
946
- type BaseFullOption<N extends string = string> = Simplify<SetRequired<BaseOption<N>, "name" | "value">>;
947
- /**
948
- * Utility type to turn an {@link Option}, {@link ValueOption} or
949
- * {@link BaseOption} into a {@link FullOption}.
950
- *
951
- * @group Option Lists
952
- */
953
- type ToFullOption<Opt extends BaseOption> = Opt extends BaseFullOption ? Opt : Opt extends BaseOption<infer IdentifierType> ? WithUnknownIndex<Opt & FullOption<IdentifierType>> : never;
954
- /**
955
- * A group of {@link Option}s, usually within an {@link OptionList}.
956
- *
957
- * @group Option Lists
958
- */
959
- interface OptionGroup<Opt extends BaseOption = FlexibleOption> {
960
- label: string;
961
- options: WithUnknownIndex<Opt>[];
962
- }
963
- /**
964
- * A group of {@link BaseOption}s, usually within a {@link FlexibleOptionList}.
965
- *
966
- * @group Option Lists
967
- */
968
- type FlexibleOptionGroup<Opt extends BaseOption | string = BaseOption> = {
969
- label: string;
970
- options: (Opt extends BaseFullOption ? Opt : ToFlexibleOption<Opt>)[];
971
- };
972
- /**
973
- * Either an array of {@link Option}s or an array of {@link OptionGroup}s.
974
- *
975
- * @group Option Lists
976
- */
977
- type OptionList<Opt extends Option = Option> = Opt[] | OptionGroup<Opt>[];
978
- /**
979
- * An array of options or option groups, like {@link OptionList} but the option type
980
- * may use either `name` or `value` as the primary identifier.
981
- *
982
- * @group Option Lists
983
- */
984
- type FlexibleOptionList<Opt extends BaseOption> = ToFlexibleOption<Opt>[] | FlexibleOptionGroup<ToFlexibleOption<Opt>>[];
985
- /**
986
- * An array of options or option groups, like {@link OptionList}, but using
987
- * {@link FullOption} instead of {@link Option}. This means that every member is
988
- * guaranteed to have both `name` and `value`.
989
- *
990
- * @group Option Lists
991
- */
992
- type FullOptionList<Opt extends BaseOption> = Opt extends BaseFullOption ? Opt[] | OptionGroup<Opt>[] : ToFullOption<Opt>[] | OptionGroup<ToFullOption<Opt>>[];
993
- //#endregion
994
- //#region src/types/ruleGroups.d.ts
995
- /**
996
- * Properties common to both rules and groups.
997
- */
998
- interface CommonRuleAndGroupProperties {
999
- path?: Path;
1000
- id?: string;
1001
- disabled?: boolean;
1002
- }
1003
- /**
1004
- * The main rule type. The `field`, `operator`, and `value` properties
1005
- * can be narrowed with generics.
1006
- */
1007
- interface RuleType<F extends string = string, O extends string = string, V = any, C extends string = string> extends CommonRuleAndGroupProperties {
1008
- field: F;
1009
- operator: O;
1010
- value: V;
1011
- valueSource?: ValueSource;
1012
- match?: MatchConfig;
1013
- /**
1014
- * Only used when adding a rule to a query that uses independent combinators.
1015
- */
1016
- combinatorPreceding?: C;
1017
- }
1018
- /**
1019
- * The main rule group type. This type is used for query definitions as well as
1020
- * all sub-groups of queries.
1021
- */
1022
- interface RuleGroupType<R extends RuleType = RuleType, C extends string = string> extends CommonRuleAndGroupProperties {
1023
- combinator: C;
1024
- rules: RuleGroupArray<RuleGroupType<R, C>, R>;
1025
- not?: boolean;
1026
- }
1027
- /**
1028
- * The type of the `rules` array in a {@link RuleGroupType}.
1029
- */
1030
- type RuleGroupArray<RG extends RuleGroupType = RuleGroupType, R extends RuleType = RuleType> = (R | RG)[];
1031
- /**
1032
- * The type of the `rules` array in a {@link DefaultRuleGroupType}.
1033
- */
1034
- type DefaultRuleGroupArray<F extends string = string> = RuleGroupArray<DefaultRuleGroupType, DefaultRuleType<F>>;
1035
- /**
1036
- * {@link RuleGroupType} with the `combinator` property limited to
1037
- * {@link DefaultCombinatorNameExtended} and `rules` limited to {@link DefaultRuleType}.
1038
- */
1039
- type DefaultRuleGroupType<F extends string = string> = RuleGroupType<DefaultRuleType<F>, DefaultCombinatorNameExtended> & {
1040
- rules: DefaultRuleGroupArray<F>;
1041
- };
1042
- /**
1043
- * {@link RuleType} with the `operator` property limited to {@link DefaultOperatorName}.
1044
- */
1045
- type DefaultRuleType<F extends string = string> = RuleType<F, DefaultOperatorName>;
1046
- /**
1047
- * Default allowed values for the `combinator` property.
1048
- *
1049
- * @group Option Lists
1050
- */
1051
- type DefaultCombinatorName = "and" | "or";
1052
- /**
1053
- * Default allowed values for the `combinator` property, plus `"xor"`.
1054
- *
1055
- * @group Option Lists
1056
- */
1057
- type DefaultCombinatorNameExtended = DefaultCombinatorName | "xor";
1058
- /**
1059
- * Default values for the `operator` property.
1060
- *
1061
- * @group Option Lists
1062
- */
1063
- type DefaultOperatorName = "=" | "!=" | "<" | ">" | "<=" | ">=" | "contains" | "beginsWith" | "endsWith" | "doesNotContain" | "doesNotBeginWith" | "doesNotEndWith" | "null" | "notNull" | "in" | "notIn" | "between" | "notBetween";
1064
- //#endregion
1065
- //#region src/types/ruleGroupsIC.utils.d.ts
1066
- type MAXIMUM_ALLOWED_BOUNDARY = 80;
1067
- type MappedTuple<Tuple extends Array<unknown>, Result extends Array<unknown> = [], Count extends ReadonlyArray<number> = []> = Count["length"] extends MAXIMUM_ALLOWED_BOUNDARY ? Result : Tuple extends [] ? [] : Result extends [] ? MappedTuple<Tuple, Tuple, [...Count, 1]> : MappedTuple<Tuple, Result | [...Result, ...Tuple], [...Count, 1]>;
1068
- //#endregion
1069
- //#region src/types/ruleGroupsIC.d.ts
1070
- /**
1071
- * The main rule group interface when using independent combinators. This type is used
1072
- * for query definitions as well as all sub-groups of queries.
1073
- */
1074
- interface RuleGroupTypeIC<R extends RuleType = RuleType, C extends string = string> extends Except<RuleGroupType<R, C>, "combinator" | "rules"> {
1075
- combinator?: undefined;
1076
- rules: RuleGroupICArray<RuleGroupTypeIC<R, C>, R, C>;
1077
- /**
1078
- * Only used when adding a rule to a query that uses independent combinators
1079
- */
1080
- combinatorPreceding?: C;
1081
- }
1082
- /**
1083
- * Shorthand for "either {@link RuleGroupType} or {@link RuleGroupTypeIC}".
1084
- */
1085
- type RuleGroupTypeAny<R extends RuleType = RuleType, C extends string = string> = RuleGroupType<R, C> | RuleGroupTypeIC<R, C>;
1086
- /**
1087
- * The type of the `rules` array in a {@link RuleGroupTypeIC}.
1088
- */
1089
- type RuleGroupICArray<RG extends RuleGroupTypeIC = RuleGroupTypeIC, R extends RuleType = RuleType, C extends string = string> = [R | RG] | [R | RG, ...MappedTuple<[C, R | RG]>] | ((R | RG)[] & {
1090
- length: 0;
1091
- });
1092
- /**
1093
- * The type of the `rules` array in a {@link DefaultRuleGroupTypeIC}.
1094
- */
1095
- type DefaultRuleGroupICArray<F extends string = string> = RuleGroupICArray<DefaultRuleGroupTypeIC<F>, DefaultRuleType<F>, DefaultCombinatorName>;
1096
- /**
1097
- * {@link RuleGroupTypeIC} with combinators limited to
1098
- * {@link DefaultCombinatorName} and rules limited to {@link DefaultRuleType}.
1099
- */
1100
- interface DefaultRuleGroupTypeIC<F extends string = string> extends RuleGroupTypeIC<DefaultRuleType<F>> {
1101
- rules: DefaultRuleGroupICArray<F>;
1102
- }
1103
- //#endregion
1104
- //#region src/types/validation.d.ts
1105
- /**
1106
- * Object with a `valid` boolean value and optional `reasons`.
1107
- */
1108
- interface ValidationResult {
1109
- valid: boolean;
1110
- reasons?: any[];
1111
- }
1112
- /**
1113
- * Map of rule/group `id` to its respective {@link ValidationResult}.
1114
- */
1115
- type ValidationMap = Record<string, boolean | ValidationResult>;
1116
- /**
1117
- * Function that validates a query.
1118
- */
1119
- type QueryValidator = (query: RuleGroupTypeAny) => boolean | ValidationMap;
1120
- /**
1121
- * Function that validates a rule.
1122
- */
1123
- type RuleValidator = (rule: RuleType) => boolean | ValidationResult;
1124
- //#endregion
1125
- //#region src/types/basic.d.ts
1126
- /**
1127
- * @see https://react-querybuilder.js.org/docs/tips/path
1128
- */
1129
- type Path = number[];
1130
- /**
1131
- * String of classnames, array of classname strings, or object where the
1132
- * keys are classnames and those with truthy values will be included.
1133
- * Suitable for passing to the `clsx` package.
1134
- */
1135
- type Classname = string | string[] | Record<string, any>;
1136
- /**
1137
- * A source for the `value` property of a rule.
1138
- */
1139
- type ValueSource = "value" | "field";
1140
- /**
1141
- * Type of {@link ValueEditor} that will be displayed.
1142
- */
1143
- type ValueEditorType = "text" | "select" | "checkbox" | "radio" | "textarea" | "switch" | "multiselect" | null;
1144
- /**
1145
- * A valid array of potential value sources.
1146
- *
1147
- * @see {@link ValueSource}
1148
- */
1149
- type ValueSources = ["value"] | ["value", "field"] | ["field", "value"] | ["field"];
1150
- type ValueSourceFlexibleOptions = ToFlexibleOptionArrays<ValueSources>;
1151
- type ToFlexibleOptionArrays<Sources extends readonly string[]> = Sources extends unknown ? { [K in keyof Sources]: FlexibleOption<Sources[K]> } : never;
1152
- type WithOptionalClassName<T> = T & {
1153
- className?: Classname;
1154
- };
1155
- /**
1156
- * HTML5 input types
1157
- */
1158
- type InputType = "button" | "checkbox" | "color" | "date" | "datetime-local" | "email" | "file" | "hidden" | "image" | "month" | "number" | "password" | "radio" | "range" | "reset" | "search" | "submit" | "tel" | "text" | "time" | "url" | "week" | "bigint" | (string & {});
1159
- /**
1160
- * Quantification mode describing how many elements of the value array must pass
1161
- * the filter for the rule itself to pass.
1162
- *
1163
- * For "atLeast", "atMost", and "exactly", the threshold value will be converted to
1164
- * a percentage if the number is less than 1. Non-numeric values and numbers less
1165
- * than 0 will be ignored.
1166
- */
1167
- interface MatchConfig {
1168
- mode: MatchMode;
1169
- threshold?: number | null | undefined;
1170
- }
1171
- type MatchMode = "all" | "some" | "none" | "atLeast" | "atMost" | "exactly";
1172
- /**
1173
- * Base for all Field types/interfaces.
1174
- */
1175
- interface BaseFullField<FieldName extends string = string, OperatorName extends string = string, ValueName extends string = string, OperatorObj extends FullOption = FullOption<OperatorName>, ValueObj extends FullOption = FullOption<ValueName>> extends WithOptionalClassName<BaseFullOption<FieldName>> {
1176
- id?: string;
1177
- operators?: FlexibleOptionList<OperatorObj> | OperatorName[] | FlexibleOption<OperatorName>[] | (OperatorName | FlexibleOption<OperatorName>)[];
1178
- valueEditorType?: ValueEditorType | ((operator: OperatorName) => ValueEditorType);
1179
- valueSources?: ValueSources | ValueSourceFlexibleOptions | ((operator: OperatorName) => ValueSources | ValueSourceFlexibleOptions);
1180
- inputType?: InputType | null;
1181
- values?: FlexibleOptionList<ValueObj>;
1182
- matchModes?: boolean | MatchMode[] | FlexibleOption<MatchMode>[];
1183
- /** Properties of items in the value. */
1184
- subproperties?: FlexibleOptionList<FullField>;
1185
- defaultOperator?: OperatorName;
1186
- defaultValue?: any;
1187
- placeholder?: string;
1188
- validator?: RuleValidator;
1189
- comparator?: string | ((f: FullField, operator: string) => boolean);
1190
- }
1191
- /**
1192
- * Full field definition used in the `fields` prop of {@link QueryBuilder}.
1193
- * This type requires both `name` and `value`, but the `fields` prop itself
1194
- * can use a {@link FlexibleOption} where only one of `name` or `value` is
1195
- * required (along with `label`), or {@link Field} where only `name` and
1196
- * `label` are required.
1197
- *
1198
- * The `name`/`value`, `operators`, and `values` properties of this interface
1199
- * can be narrowed with generics.
1200
- *
1201
- * @group Option Lists
1202
- */
1203
- type FullField<FieldName extends string = string, OperatorName extends string = string, ValueName extends string = string, OperatorObj extends FullOption = FullOption<OperatorName>, ValueObj extends FullOption = FullOption<ValueName>> = Simplify<FullOption<FieldName> & BaseFullField<FieldName, OperatorName, ValueName, OperatorObj, ValueObj>>;
1204
- /**
1205
- * Allowed values of the {@link FullOperator} property `arity`. A value of `"unary"` or
1206
- * a number less than two will cause the default {@link ValueEditor} to render `null`.
1207
- */
1208
- type Arity = number | "unary" | "binary" | "ternary";
1209
- /**
1210
- * Full operator definition used in the `operators`/`getOperators` props of
1211
- * {@link QueryBuilder}. This type requires both `name` and `value`, but the
1212
- * `operators`/`getOperators` props themselves can use a {@link FlexibleOption}
1213
- * where only one of `name` or `value` is required, or {@link FullOperator} where
1214
- * only `name` is required.
1215
- *
1216
- * The `name`/`value` properties of this interface can be narrowed with generics.
1217
- *
1218
- * @group Option Lists
1219
- */
1220
- interface FullOperator<N extends string = string> extends WithOptionalClassName<FullOption<N>> {
1221
- arity?: Arity;
1222
- }
1223
- type ParseNumberMethodName = "enhanced" | "native" | "strict";
1224
- /**
1225
- * Parsing algorithms used by {@link parseNumber}.
1226
- */
1227
-
1228
- type ParseNumbersModerationLevel = "-limited" | "";
1229
- /**
1230
- * Options for the `parseNumbers` prop of {@link QueryBuilder}.
1231
- */
1232
- type ParseNumbersPropConfig = boolean | `${ParseNumberMethodName}${ParseNumbersModerationLevel}`;
1233
- //#endregion
1234
- export { DefaultOperatorName, DefaultRuleGroupType, DefaultRuleGroupTypeIC, Except, FlexibleOptionList, FullField, FullOperator, FullOptionList, InputType, OptionList, ParseNumbersPropConfig, QueryValidator, RuleGroupType, RuleGroupTypeAny, RuleGroupTypeIC, RuleType, RuleValidator, SetRequired, ValidationMap, ValidationResult, ValueSource, ValueSources };
1235
- //# sourceMappingURL=basic-BfD-7CN3.d.mts.map