@effect-app/infra 1.1.15 → 1.2.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/CHANGELOG.md +6 -0
- package/_cjs/services/QueueMaker/memQueue.cjs +4 -1
- package/_cjs/services/QueueMaker/memQueue.cjs.map +1 -1
- package/_cjs/services/QueueMaker/sbqueue.cjs +4 -1
- package/_cjs/services/QueueMaker/sbqueue.cjs.map +1 -1
- package/_cjs/services/RepositoryBase.cjs +1 -1
- package/_cjs/services/RepositoryBase.cjs.map +1 -1
- package/_cjs/services/Store/Cosmos.cjs +2 -5
- package/_cjs/services/Store/Cosmos.cjs.map +1 -1
- package/_cjs/services/Store/Memory.cjs +1 -1
- package/_cjs/services/Store/Memory.cjs.map +1 -1
- package/_cjs/services/Store/filterApi/query.cjs +0 -167
- package/_cjs/services/Store/filterApi/query.cjs.map +1 -1
- package/_cjs/services/Store/service.cjs.map +1 -1
- package/_cjs/services/Store/utils.cjs +1 -1
- package/_cjs/services/Store/utils.cjs.map +1 -1
- package/_cjs/services/query/dsl.cjs +1 -1
- package/_cjs/services/query/dsl.cjs.map +1 -1
- package/_cjs/services/query/new-kid-interpreter.cjs +14 -10
- package/_cjs/services/query/new-kid-interpreter.cjs.map +1 -1
- package/dist/services/QueueMaker/memQueue.d.ts.map +1 -1
- package/dist/services/QueueMaker/memQueue.js +5 -2
- package/dist/services/QueueMaker/sbqueue.d.ts.map +1 -1
- package/dist/services/QueueMaker/sbqueue.js +5 -2
- package/dist/services/RepositoryBase.d.ts +2 -2
- package/dist/services/RepositoryBase.d.ts.map +1 -1
- package/dist/services/RepositoryBase.js +2 -2
- package/dist/services/Store/Cosmos.js +3 -3
- package/dist/services/Store/Memory.js +2 -2
- package/dist/services/Store/filterApi/query.d.ts +3 -44
- package/dist/services/Store/filterApi/query.d.ts.map +1 -1
- package/dist/services/Store/filterApi/query.js +2 -136
- package/dist/services/Store/service.d.ts +3 -4
- package/dist/services/Store/service.d.ts.map +1 -1
- package/dist/services/Store/service.js +1 -1
- package/dist/services/Store/utils.d.ts +1 -1
- package/dist/services/Store/utils.d.ts.map +1 -1
- package/dist/services/Store/utils.js +2 -2
- package/dist/services/query/dsl.d.ts +22 -3
- package/dist/services/query/dsl.d.ts.map +1 -1
- package/dist/services/query/dsl.js +2 -2
- package/dist/services/query/new-kid-interpreter.d.ts +2 -2
- package/dist/services/query/new-kid-interpreter.d.ts.map +1 -1
- package/dist/services/query/new-kid-interpreter.js +13 -11
- package/package.json +2 -12
- package/src/services/QueueMaker/memQueue.ts +6 -1
- package/src/services/QueueMaker/sbqueue.ts +4 -1
- package/src/services/RepositoryBase.ts +1 -7
- package/src/services/Store/Cosmos.ts +2 -2
- package/src/services/Store/Memory.ts +3 -3
- package/src/services/Store/filterApi/query.ts +22 -231
- package/src/services/Store/service.ts +3 -4
- package/src/services/Store/utils.ts +2 -2
- package/src/services/query/dsl.ts +191 -16
- package/src/services/query/new-kid-interpreter.ts +16 -13
- package/test/query.test.ts +2 -5
- package/_cjs/services/Store/filterApi/proxy.cjs +0 -40
- package/_cjs/services/Store/filterApi/proxy.cjs.map +0 -1
- package/dist/services/Store/filterApi/proxy.d.ts +0 -41
- package/dist/services/Store/filterApi/proxy.d.ts.map +0 -1
- package/dist/services/Store/filterApi/proxy.js +0 -41
- package/src/services/Store/filterApi/proxy.ts +0 -109
- package/test/filterApi.test.ts +0 -268
- package/vitest.config.ts.timestamp-1711656440838-19c636fe320df.mjs +0 -0
- package/vitest.config.ts.timestamp-1711724061890-6ecedb0a07fdd.mjs +0 -0
- package/vitest.config.ts.timestamp-1711743489537-da8d9e5f66c9f.mjs +0 -0
- package/vitest.config.ts.timestamp-1711744615239-dcf257a844e01.mjs +0 -37
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
4
4
|
import type { FieldValues } from "@effect-app/infra/filter/types"
|
|
5
5
|
import type { FieldPath, FieldPathValue } from "@effect-app/infra/filter/types/path/eager"
|
|
6
|
-
import type { Ops } from "@effect-app/infra/services/Store/filterApi/
|
|
6
|
+
import type { Ops } from "@effect-app/infra/services/Store/filterApi/query"
|
|
7
7
|
import type { NonNegativeInt } from "@effect-app/schema"
|
|
8
8
|
import type { Option, Pipeable, S } from "effect-app"
|
|
9
9
|
import { Data, flow } from "effect-app"
|
|
@@ -85,7 +85,7 @@ export class Initial<TFieldValues extends FieldValues> extends Data.TaggedClass(
|
|
|
85
85
|
|
|
86
86
|
export class Where<TFieldValues extends FieldValues> extends Data.TaggedClass("where")<{
|
|
87
87
|
current: Query<TFieldValues>
|
|
88
|
-
operation: [string, Ops, any] | [string, any]
|
|
88
|
+
operation: [string, Ops, any] | [string, any] | ((q: Query<TFieldValues>) => QueryWhere<TFieldValues>)
|
|
89
89
|
}> implements QueryWhere<TFieldValues> {
|
|
90
90
|
readonly [QId]!: any
|
|
91
91
|
|
|
@@ -181,7 +181,8 @@ export class Project<A, TFieldValues extends FieldValues, R, TType extends "one"
|
|
|
181
181
|
|
|
182
182
|
export const make: <TFieldValues extends FieldValues>() => Query<TFieldValues> = () => new Initial()
|
|
183
183
|
|
|
184
|
-
export const where: FilterWhere = (...operation: any[]) => (current: any) =>
|
|
184
|
+
export const where: FilterWhere = (...operation: any[]) => (current: any) =>
|
|
185
|
+
new Where({ current, operation: typeof operation[0] === "function" ? flow(...operation as [any]) : operation } as any)
|
|
185
186
|
|
|
186
187
|
export const and: FilterContinuation = (...operation: any[]) => (current: any) =>
|
|
187
188
|
new And({ current, operation: typeof operation[0] === "function" ? flow(...operation as [any]) : operation } as any)
|
|
@@ -322,19 +323,193 @@ export type FilterWheres = {
|
|
|
322
323
|
) => QueryWhere<TFieldValues>
|
|
323
324
|
}
|
|
324
325
|
|
|
325
|
-
export type FilterWhere =
|
|
326
|
-
|
|
327
|
-
TFieldValues extends FieldValues
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
326
|
+
export type FilterWhere =
|
|
327
|
+
& {
|
|
328
|
+
<TFieldValues extends FieldValues>(
|
|
329
|
+
fb: (current: Query<TFieldValues>) => QueryWhere<TFieldValues>
|
|
330
|
+
): (current: Query<TFieldValues>) => QueryWhere<TFieldValues>
|
|
331
|
+
|
|
332
|
+
<TFieldValues extends FieldValues>(
|
|
333
|
+
fb: (current: Query<TFieldValues>) => QueryWhere<TFieldValues>,
|
|
334
|
+
fc: (query: QueryWhere<TFieldValues>) => QueryWhere<TFieldValues>
|
|
335
|
+
): (current: Query<TFieldValues>) => QueryWhere<TFieldValues>
|
|
336
|
+
|
|
337
|
+
<TFieldValues extends FieldValues>(
|
|
338
|
+
fb: (current: Query<TFieldValues>) => QueryWhere<TFieldValues>,
|
|
339
|
+
fc: (query: QueryWhere<TFieldValues>) => QueryWhere<TFieldValues>,
|
|
340
|
+
fd: (query: QueryWhere<TFieldValues>) => QueryWhere<TFieldValues>
|
|
341
|
+
): (current: Query<TFieldValues>) => QueryWhere<TFieldValues>
|
|
342
|
+
|
|
343
|
+
<TFieldValues extends FieldValues>(
|
|
344
|
+
fb: (current: Query<TFieldValues>) => QueryWhere<TFieldValues>,
|
|
345
|
+
fc: (query: QueryWhere<TFieldValues>) => QueryWhere<TFieldValues>,
|
|
346
|
+
fd: (query: QueryWhere<TFieldValues>) => QueryWhere<TFieldValues>,
|
|
347
|
+
fe: (query: QueryWhere<TFieldValues>) => QueryWhere<TFieldValues>
|
|
348
|
+
): (current: Query<TFieldValues>) => QueryWhere<TFieldValues>
|
|
349
|
+
|
|
350
|
+
<TFieldValues extends FieldValues>(
|
|
351
|
+
fb: (current: Query<TFieldValues>) => QueryWhere<TFieldValues>,
|
|
352
|
+
fc: (query: QueryWhere<TFieldValues>) => QueryWhere<TFieldValues>,
|
|
353
|
+
fd: (query: QueryWhere<TFieldValues>) => QueryWhere<TFieldValues>,
|
|
354
|
+
fe: (query: QueryWhere<TFieldValues>) => QueryWhere<TFieldValues>,
|
|
355
|
+
ff: (query: QueryWhere<TFieldValues>) => QueryWhere<TFieldValues>
|
|
356
|
+
): (current: Query<TFieldValues>) => QueryWhere<TFieldValues>
|
|
357
|
+
<TFieldValues extends FieldValues>(
|
|
358
|
+
fb: (current: Query<TFieldValues>) => QueryWhere<TFieldValues>,
|
|
359
|
+
fc: (query: QueryWhere<TFieldValues>) => QueryWhere<TFieldValues>,
|
|
360
|
+
fd: (query: QueryWhere<TFieldValues>) => QueryWhere<TFieldValues>,
|
|
361
|
+
fe: (query: QueryWhere<TFieldValues>) => QueryWhere<TFieldValues>,
|
|
362
|
+
fg: (query: QueryWhere<TFieldValues>) => QueryWhere<TFieldValues>
|
|
363
|
+
): (current: Query<TFieldValues>) => QueryWhere<TFieldValues>
|
|
364
|
+
<TFieldValues extends FieldValues>(
|
|
365
|
+
fb: (current: Query<TFieldValues>) => QueryWhere<TFieldValues>,
|
|
366
|
+
fc: (query: QueryWhere<TFieldValues>) => QueryWhere<TFieldValues>,
|
|
367
|
+
fd: (query: QueryWhere<TFieldValues>) => QueryWhere<TFieldValues>,
|
|
368
|
+
fe: (query: QueryWhere<TFieldValues>) => QueryWhere<TFieldValues>,
|
|
369
|
+
fg: (query: QueryWhere<TFieldValues>) => QueryWhere<TFieldValues>,
|
|
370
|
+
fh: (query: QueryWhere<TFieldValues>) => QueryWhere<TFieldValues>
|
|
371
|
+
): (current: Query<TFieldValues>) => QueryWhere<TFieldValues>
|
|
372
|
+
<TFieldValues extends FieldValues>(
|
|
373
|
+
fb: (current: Query<TFieldValues>) => QueryWhere<TFieldValues>,
|
|
374
|
+
fc: (query: QueryWhere<TFieldValues>) => QueryWhere<TFieldValues>,
|
|
375
|
+
fd: (query: QueryWhere<TFieldValues>) => QueryWhere<TFieldValues>,
|
|
376
|
+
fe: (query: QueryWhere<TFieldValues>) => QueryWhere<TFieldValues>,
|
|
377
|
+
fg: (query: QueryWhere<TFieldValues>) => QueryWhere<TFieldValues>,
|
|
378
|
+
fh: (query: QueryWhere<TFieldValues>) => QueryWhere<TFieldValues>,
|
|
379
|
+
fi: (query: QueryWhere<TFieldValues>) => QueryWhere<TFieldValues>
|
|
380
|
+
): (current: Query<TFieldValues>) => QueryWhere<TFieldValues>
|
|
381
|
+
<TFieldValues extends FieldValues>(
|
|
382
|
+
fb: (current: Query<TFieldValues>) => QueryWhere<TFieldValues>,
|
|
383
|
+
fc: (query: QueryWhere<TFieldValues>) => QueryWhere<TFieldValues>,
|
|
384
|
+
fd: (query: QueryWhere<TFieldValues>) => QueryWhere<TFieldValues>,
|
|
385
|
+
fe: (query: QueryWhere<TFieldValues>) => QueryWhere<TFieldValues>,
|
|
386
|
+
fg: (query: QueryWhere<TFieldValues>) => QueryWhere<TFieldValues>,
|
|
387
|
+
fh: (query: QueryWhere<TFieldValues>) => QueryWhere<TFieldValues>,
|
|
388
|
+
fi: (query: QueryWhere<TFieldValues>) => QueryWhere<TFieldValues>,
|
|
389
|
+
fj: (query: QueryWhere<TFieldValues>) => QueryWhere<TFieldValues>
|
|
390
|
+
): (current: Query<TFieldValues>) => QueryWhere<TFieldValues>
|
|
391
|
+
<TFieldValues extends FieldValues>(
|
|
392
|
+
fb: (current: Query<TFieldValues>) => QueryWhere<TFieldValues>,
|
|
393
|
+
fc: (query: QueryWhere<TFieldValues>) => QueryWhere<TFieldValues>,
|
|
394
|
+
fd: (query: QueryWhere<TFieldValues>) => QueryWhere<TFieldValues>,
|
|
395
|
+
fe: (query: QueryWhere<TFieldValues>) => QueryWhere<TFieldValues>,
|
|
396
|
+
fg: (query: QueryWhere<TFieldValues>) => QueryWhere<TFieldValues>,
|
|
397
|
+
fh: (query: QueryWhere<TFieldValues>) => QueryWhere<TFieldValues>,
|
|
398
|
+
fi: (query: QueryWhere<TFieldValues>) => QueryWhere<TFieldValues>,
|
|
399
|
+
fj: (query: QueryWhere<TFieldValues>) => QueryWhere<TFieldValues>,
|
|
400
|
+
fk: (query: QueryWhere<TFieldValues>) => QueryWhere<TFieldValues>
|
|
401
|
+
): (current: Query<TFieldValues>) => QueryWhere<TFieldValues>
|
|
402
|
+
<TFieldValues extends FieldValues>(
|
|
403
|
+
fb: (current: Query<TFieldValues>) => QueryWhere<TFieldValues>,
|
|
404
|
+
fc: (query: QueryWhere<TFieldValues>) => QueryWhere<TFieldValues>,
|
|
405
|
+
fd: (query: QueryWhere<TFieldValues>) => QueryWhere<TFieldValues>,
|
|
406
|
+
fe: (query: QueryWhere<TFieldValues>) => QueryWhere<TFieldValues>,
|
|
407
|
+
fg: (query: QueryWhere<TFieldValues>) => QueryWhere<TFieldValues>,
|
|
408
|
+
fh: (query: QueryWhere<TFieldValues>) => QueryWhere<TFieldValues>,
|
|
409
|
+
fi: (query: QueryWhere<TFieldValues>) => QueryWhere<TFieldValues>,
|
|
410
|
+
fj: (query: QueryWhere<TFieldValues>) => QueryWhere<TFieldValues>,
|
|
411
|
+
fk: (query: QueryWhere<TFieldValues>) => QueryWhere<TFieldValues>,
|
|
412
|
+
fl: (query: QueryWhere<TFieldValues>) => QueryWhere<TFieldValues>
|
|
413
|
+
): (current: Query<TFieldValues>) => QueryWhere<TFieldValues>
|
|
414
|
+
<TFieldValues extends FieldValues>(
|
|
415
|
+
fb: (current: Query<TFieldValues>) => QueryWhere<TFieldValues>,
|
|
416
|
+
fc: (query: QueryWhere<TFieldValues>) => QueryWhere<TFieldValues>,
|
|
417
|
+
fd: (query: QueryWhere<TFieldValues>) => QueryWhere<TFieldValues>,
|
|
418
|
+
fe: (query: QueryWhere<TFieldValues>) => QueryWhere<TFieldValues>,
|
|
419
|
+
fg: (query: QueryWhere<TFieldValues>) => QueryWhere<TFieldValues>,
|
|
420
|
+
fh: (query: QueryWhere<TFieldValues>) => QueryWhere<TFieldValues>,
|
|
421
|
+
fi: (query: QueryWhere<TFieldValues>) => QueryWhere<TFieldValues>,
|
|
422
|
+
fj: (query: QueryWhere<TFieldValues>) => QueryWhere<TFieldValues>,
|
|
423
|
+
fk: (query: QueryWhere<TFieldValues>) => QueryWhere<TFieldValues>,
|
|
424
|
+
fl: (query: QueryWhere<TFieldValues>) => QueryWhere<TFieldValues>,
|
|
425
|
+
fm: (query: QueryWhere<TFieldValues>) => QueryWhere<TFieldValues>
|
|
426
|
+
): (current: Query<TFieldValues>) => QueryWhere<TFieldValues>
|
|
427
|
+
<TFieldValues extends FieldValues>(
|
|
428
|
+
fb: (current: Query<TFieldValues>) => QueryWhere<TFieldValues>,
|
|
429
|
+
fc: (query: QueryWhere<TFieldValues>) => QueryWhere<TFieldValues>,
|
|
430
|
+
fd: (query: QueryWhere<TFieldValues>) => QueryWhere<TFieldValues>,
|
|
431
|
+
fe: (query: QueryWhere<TFieldValues>) => QueryWhere<TFieldValues>,
|
|
432
|
+
fg: (query: QueryWhere<TFieldValues>) => QueryWhere<TFieldValues>,
|
|
433
|
+
fh: (query: QueryWhere<TFieldValues>) => QueryWhere<TFieldValues>,
|
|
434
|
+
fi: (query: QueryWhere<TFieldValues>) => QueryWhere<TFieldValues>,
|
|
435
|
+
fj: (query: QueryWhere<TFieldValues>) => QueryWhere<TFieldValues>,
|
|
436
|
+
fk: (query: QueryWhere<TFieldValues>) => QueryWhere<TFieldValues>,
|
|
437
|
+
fl: (query: QueryWhere<TFieldValues>) => QueryWhere<TFieldValues>,
|
|
438
|
+
fm: (query: QueryWhere<TFieldValues>) => QueryWhere<TFieldValues>,
|
|
439
|
+
fn: (query: QueryWhere<TFieldValues>) => QueryWhere<TFieldValues>
|
|
440
|
+
): (current: Query<TFieldValues>) => QueryWhere<TFieldValues>
|
|
441
|
+
}
|
|
442
|
+
& {
|
|
443
|
+
<
|
|
444
|
+
TFieldValues extends FieldValues,
|
|
445
|
+
TFieldName extends FieldPath<TFieldValues>,
|
|
446
|
+
V extends FieldPathValue<TFieldValues, TFieldName>
|
|
447
|
+
>(f: {
|
|
448
|
+
path: TFieldName
|
|
449
|
+
op: Ops
|
|
450
|
+
value: V
|
|
451
|
+
}): (
|
|
452
|
+
current: Query<TFieldValues>
|
|
453
|
+
) => QueryWhere<TFieldValues>
|
|
454
|
+
}
|
|
455
|
+
& FilterWheres
|
|
456
|
+
& {
|
|
457
|
+
<
|
|
458
|
+
TFieldValues extends FieldValues,
|
|
459
|
+
TFieldName extends FieldPath<TFieldValues>,
|
|
460
|
+
V extends FieldPathValue<TFieldValues, TFieldName>
|
|
461
|
+
>(
|
|
462
|
+
path: TFieldName,
|
|
463
|
+
value: V
|
|
464
|
+
): (
|
|
465
|
+
current: Query<TFieldValues>
|
|
466
|
+
) => QueryWhere<TFieldValues>
|
|
467
|
+
// breaks flow pipe type inference
|
|
468
|
+
// <
|
|
469
|
+
// TFieldValues extends FieldValues,
|
|
470
|
+
// TFieldName extends FieldPath<TFieldValues>,
|
|
471
|
+
// V extends FieldPathValue<TFieldValues, TFieldName>
|
|
472
|
+
// >(
|
|
473
|
+
// path: TFieldName,
|
|
474
|
+
// op: "neq",
|
|
475
|
+
// value: V
|
|
476
|
+
// ): (
|
|
477
|
+
// current: Query<TFieldValues>
|
|
478
|
+
// ) => QueryWhere<TFieldValues>
|
|
479
|
+
<
|
|
480
|
+
TFieldValues extends FieldValues,
|
|
481
|
+
TFieldName extends FieldPath<TFieldValues>,
|
|
482
|
+
V extends FieldPathValue<TFieldValues, TFieldName>
|
|
483
|
+
>(
|
|
484
|
+
path: TFieldName,
|
|
485
|
+
op: "gt" | "gte" | "lt" | "lte" | "neq",
|
|
486
|
+
value: V // only numbers?
|
|
487
|
+
): (
|
|
488
|
+
current: Query<TFieldValues>
|
|
489
|
+
) => QueryWhere<TFieldValues>
|
|
490
|
+
<
|
|
491
|
+
TFieldValues extends FieldValues,
|
|
492
|
+
TFieldName extends FieldPath<TFieldValues>,
|
|
493
|
+
V extends string
|
|
494
|
+
>(
|
|
495
|
+
path: TFieldName,
|
|
496
|
+
op: "startsWith" | "endsWith" | "contains" | "notContains" | "notStartsWith" | "notEndsWith",
|
|
497
|
+
value: V
|
|
498
|
+
): (
|
|
499
|
+
current: Query<TFieldValues>
|
|
500
|
+
) => QueryWhere<TFieldValues>
|
|
501
|
+
<
|
|
502
|
+
TFieldValues extends FieldValues,
|
|
503
|
+
TFieldName extends FieldPath<TFieldValues>,
|
|
504
|
+
V extends FieldPathValue<TFieldValues, TFieldName>
|
|
505
|
+
>(
|
|
506
|
+
path: TFieldName,
|
|
507
|
+
op: "in" | "notIn",
|
|
508
|
+
value: readonly V[]
|
|
509
|
+
): (
|
|
510
|
+
current: Query<TFieldValues>
|
|
511
|
+
) => QueryWhere<TFieldValues>
|
|
512
|
+
}
|
|
338
513
|
|
|
339
514
|
export type FilterContinuations = {
|
|
340
515
|
<
|
|
@@ -6,7 +6,7 @@ import { dropUndefinedT } from "effect-app/utils"
|
|
|
6
6
|
import type { FieldValues } from "../../filter/types.js"
|
|
7
7
|
import type { FieldPath } from "../../filter/types/path/eager.js"
|
|
8
8
|
import { make, type Q, type QAll } from "../query.js"
|
|
9
|
-
import type { FilterResult
|
|
9
|
+
import type { FilterResult } from "../Store/filterApi/query.js"
|
|
10
10
|
|
|
11
11
|
type Result<TFieldValues extends FieldValues, A = TFieldValues, R = never> = {
|
|
12
12
|
filter: FilterResult[]
|
|
@@ -51,14 +51,20 @@ const interpret = <TFieldValues extends FieldValues, A = TFieldValues, R = never
|
|
|
51
51
|
},
|
|
52
52
|
where: ({ current, operation }) => {
|
|
53
53
|
upd(interpret(current))
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
t: "where",
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
54
|
+
if (typeof operation === "function") {
|
|
55
|
+
data.filter.push(
|
|
56
|
+
{ t: "where-scope", result: interpret(operation(make())).filter }
|
|
57
|
+
)
|
|
58
|
+
} else {
|
|
59
|
+
data.filter.push(
|
|
60
|
+
{
|
|
61
|
+
t: "where",
|
|
62
|
+
path: operation[0],
|
|
63
|
+
op: operation.length === 2 ? "eq" : operation[1],
|
|
64
|
+
value: operation.length === 2 ? operation[1] : operation[2]
|
|
65
|
+
}
|
|
66
|
+
)
|
|
67
|
+
}
|
|
62
68
|
},
|
|
63
69
|
and: ({ current, operation }) => {
|
|
64
70
|
upd(interpret(current))
|
|
@@ -153,10 +159,7 @@ export const toFilter = <
|
|
|
153
159
|
ttype: a.ttype,
|
|
154
160
|
mode: a.mode ?? "transform",
|
|
155
161
|
filter: a.filter.length
|
|
156
|
-
?
|
|
157
|
-
type: "new-kid" as const,
|
|
158
|
-
build: () => a.filter
|
|
159
|
-
} as QueryBuilder<any>
|
|
162
|
+
? a.filter
|
|
160
163
|
: undefined
|
|
161
164
|
})
|
|
162
165
|
}
|
package/test/query.test.ts
CHANGED
|
@@ -60,7 +60,7 @@ it("merge", () => {
|
|
|
60
60
|
|
|
61
61
|
const merge = (b: any) => (a: any) => pipe(a, and(() => b))
|
|
62
62
|
|
|
63
|
-
const r = pipe(a, merge(b), toFilter, (_) => _.filter
|
|
63
|
+
const r = pipe(a, merge(b), toFilter, (_) => _.filter)
|
|
64
64
|
|
|
65
65
|
// TODO: instead this should probably scope the first where/or together e.g (where x, or y) and (...)
|
|
66
66
|
const expected = make().pipe(
|
|
@@ -68,7 +68,7 @@ it("merge", () => {
|
|
|
68
68
|
or("c", "d"),
|
|
69
69
|
and(where("d", "e"), or("f", "g")),
|
|
70
70
|
toFilter,
|
|
71
|
-
(_) => _.filter
|
|
71
|
+
(_) => _.filter
|
|
72
72
|
)
|
|
73
73
|
|
|
74
74
|
console.log(JSON.stringify({ r, expected }, undefined, 2))
|
|
@@ -79,9 +79,6 @@ it("works", () => {
|
|
|
79
79
|
console.log("raw", inspect(q, undefined, 25))
|
|
80
80
|
const interpreted = toFilter(q)
|
|
81
81
|
console.log("interpreted", inspect(interpreted, undefined, 25))
|
|
82
|
-
const filtersBuilt = interpreted.filter.build()
|
|
83
|
-
console
|
|
84
|
-
.log("filtersBuilt", inspect(filtersBuilt, undefined, 25))
|
|
85
82
|
|
|
86
83
|
const processed = memFilter(interpreted)(items.map((_) => S.encodeSync(Something)(_)))
|
|
87
84
|
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.makeProxy = void 0;
|
|
7
|
-
const ops = ["contains", "startsWith", "endsWith", "notContains", "notStartsWith", "notEndsWith", "in", "notIn", "eq", "neq", "gte", "gt", "lt", "lte"];
|
|
8
|
-
const makeProxy = parentProp => new Proxy(Object.assign(() => {}, {
|
|
9
|
-
_proxies: {}
|
|
10
|
-
}), {
|
|
11
|
-
apply(_target, _thisArg, argArray) {
|
|
12
|
-
return {
|
|
13
|
-
op: "eq",
|
|
14
|
-
value: argArray[0],
|
|
15
|
-
path: parentProp
|
|
16
|
-
};
|
|
17
|
-
},
|
|
18
|
-
get(target, prop) {
|
|
19
|
-
if (typeof prop !== "string") return undefined;
|
|
20
|
-
if (target._proxies[prop]) {
|
|
21
|
-
return target._proxies[prop];
|
|
22
|
-
}
|
|
23
|
-
if (ops.includes(prop)) {
|
|
24
|
-
return value => ({
|
|
25
|
-
op: prop,
|
|
26
|
-
path: parentProp,
|
|
27
|
-
value
|
|
28
|
-
});
|
|
29
|
-
}
|
|
30
|
-
let fullProp = prop;
|
|
31
|
-
if (parentProp) {
|
|
32
|
-
fullProp = `${parentProp}.${prop}`;
|
|
33
|
-
}
|
|
34
|
-
const p = makeProxy(fullProp);
|
|
35
|
-
target._proxies[prop] = p;
|
|
36
|
-
return p;
|
|
37
|
-
}
|
|
38
|
-
});
|
|
39
|
-
exports.makeProxy = makeProxy;
|
|
40
|
-
//# sourceMappingURL=proxy.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"proxy.cjs","names":["ops","makeProxy","parentProp","Proxy","Object","assign","_proxies","apply","_target","_thisArg","argArray","op","value","path","get","target","prop","undefined","includes","fullProp","p","exports"],"sources":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CAAApB,SAAA,GAAAA,SAAA","ignoreList":[]}
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import type { FieldValues } from "../../../filter/types.js";
|
|
2
|
-
import type { FieldPath } from "../../../filter/types/path/eager.js";
|
|
3
|
-
type NullOrUndefined<T, Fallback> = null extends T ? null : undefined extends T ? null : Fallback;
|
|
4
|
-
export type InOps = "in" | "notIn";
|
|
5
|
-
export type OtherOps = "endsWith" | "startsWith" | "notEndsWith" | "notStartsWith" | "contains" | "notContains" | "includes" | "notIncludes" | "eq" | "neq" | "gt" | "gte" | "lt" | "lte";
|
|
6
|
-
export type Ops = OtherOps | InOps;
|
|
7
|
-
type F<T extends FieldValues> = {
|
|
8
|
-
path: FieldPath<T>;
|
|
9
|
-
op: OtherOps;
|
|
10
|
-
value: string;
|
|
11
|
-
};
|
|
12
|
-
type FIn<T extends FieldValues> = {
|
|
13
|
-
op: InOps;
|
|
14
|
-
path: FieldPath<T>;
|
|
15
|
-
value: readonly string[];
|
|
16
|
-
};
|
|
17
|
-
type G<T extends FieldValues, Val> = {
|
|
18
|
-
(value: Val): F<T>;
|
|
19
|
-
startsWith: (value: string) => F<T>;
|
|
20
|
-
notStartsWith: (value: string) => F<T>;
|
|
21
|
-
endsWith: (value: string) => F<T>;
|
|
22
|
-
notEndsWith: (value: string) => F<T>;
|
|
23
|
-
contains: (value: string) => F<T>;
|
|
24
|
-
notContains: (value: string) => F<T>;
|
|
25
|
-
includes: (value: string) => F<T>;
|
|
26
|
-
notIncludes: (value: string) => F<T>;
|
|
27
|
-
in: (...value: readonly Val[]) => FIn<T>;
|
|
28
|
-
notIn: (...value: readonly Val[]) => FIn<T>;
|
|
29
|
-
eq: (value: Val) => F<T>;
|
|
30
|
-
neq: (value: Val) => F<T>;
|
|
31
|
-
gt: (value: Val) => F<T>;
|
|
32
|
-
gte: (value: Val) => F<T>;
|
|
33
|
-
lt: (value: Val) => F<T>;
|
|
34
|
-
lte: (value: Val) => F<T>;
|
|
35
|
-
};
|
|
36
|
-
export type Filter<T extends FieldValues, Ext = never> = {
|
|
37
|
-
[K in keyof T]-?: [T[K]] extends [Record<any, any> | undefined | null] ? Filter<T[K], NullOrUndefined<T[K], Ext>> & G<T, T[K] | Ext> : [T[K]] extends [Record<any, any>] ? Filter<T[K], NullOrUndefined<T[K], Ext>> & G<T, T[K] | Ext> : G<T, T[K] | Ext>;
|
|
38
|
-
};
|
|
39
|
-
export declare const makeProxy: (parentProp?: string) => any;
|
|
40
|
-
export {};
|
|
41
|
-
//# sourceMappingURL=proxy.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"proxy.d.ts","sourceRoot":"","sources":["../../../../src/services/Store/filterApi/proxy.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAA;AAC3D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,qCAAqC,CAAA;AAEpE,KAAK,eAAe,CAAC,CAAC,EAAE,QAAQ,IAAI,IAAI,SAAS,CAAC,GAAG,IAAI,GAAG,SAAS,SAAS,CAAC,GAAG,IAAI,GAAG,QAAQ,CAAA;AAEjG,MAAM,MAAM,KAAK,GACb,IAAI,GACJ,OAAO,CAAA;AAEX,MAAM,MAAM,QAAQ,GAChB,UAAU,GACV,YAAY,GACZ,aAAa,GACb,eAAe,GACf,UAAU,GACV,aAAa,GACb,UAAU,GACV,aAAa,GACb,IAAI,GACJ,KAAK,GACL,IAAI,GACJ,KAAK,GACL,IAAI,GACJ,KAAK,CAAA;AAGT,MAAM,MAAM,GAAG,GAAG,QAAQ,GAAG,KAAK,CAAA;AAClC,KAAK,CAAC,CAAC,CAAC,SAAS,WAAW,IAAI;IAC9B,IAAI,EAAE,SAAS,CAAC,CAAC,CAAC,CAAA;IAClB,EAAE,EAAE,QAAQ,CAAA;IACZ,KAAK,EAAE,MAAM,CAAA;CACd,CAAA;AAED,KAAK,GAAG,CAAC,CAAC,SAAS,WAAW,IAAI;IAChC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",
|
|
3
|
-
"startsWith",
|
|
4
|
-
"endsWith",
|
|
5
|
-
"notContains",
|
|
6
|
-
"notStartsWith",
|
|
7
|
-
"notEndsWith",
|
|
8
|
-
"in",
|
|
9
|
-
"notIn",
|
|
10
|
-
"eq",
|
|
11
|
-
"neq",
|
|
12
|
-
"gte",
|
|
13
|
-
"gt",
|
|
14
|
-
"lt",
|
|
15
|
-
"lte"
|
|
16
|
-
];
|
|
17
|
-
export const makeProxy = (parentProp) => new Proxy(Object.assign(() => { }, {
|
|
18
|
-
_proxies: {}
|
|
19
|
-
}), {
|
|
20
|
-
apply(_target, _thisArg, argArray) {
|
|
21
|
-
return ({ op: "eq", value: argArray[0], path: parentProp });
|
|
22
|
-
},
|
|
23
|
-
get(target, prop) {
|
|
24
|
-
if (typeof prop !== "string")
|
|
25
|
-
return undefined;
|
|
26
|
-
if (target._proxies[prop]) {
|
|
27
|
-
return target._proxies[prop];
|
|
28
|
-
}
|
|
29
|
-
if (ops.includes(prop)) {
|
|
30
|
-
return (value) => ({ op: prop, path: parentProp, value });
|
|
31
|
-
}
|
|
32
|
-
let fullProp = prop;
|
|
33
|
-
if (parentProp) {
|
|
34
|
-
fullProp = `${parentProp}.${prop}`;
|
|
35
|
-
}
|
|
36
|
-
const p = makeProxy(fullProp);
|
|
37
|
-
target._proxies[prop] = p;
|
|
38
|
-
return p;
|
|
39
|
-
}
|
|
40
|
-
});
|
|
41
|
-
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoicHJveHkuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi8uLi9zcmMvc2VydmljZXMvU3RvcmUvZmlsdGVyQXBpL3Byb3h5LnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQWlFQSxNQUFNLEdBQUcsR0FBVTtJQUNqQixVQUFVO0lBQ1YsWUFBWTtJQUNaLFVBQVU7SUFDVixhQUFhO0lBQ2IsZUFBZTtJQUN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csSUFBSSxDQUFBO1FBQ25CLElBQUksVUFBVSxFQUFFLENBQUM7WUFDZixRQUFRLEdBQUcsR0FBRyxVQUFVLElBQUksSUFBSSxFQUFFLENBQUE7UUFDcEMsQ0FBQztRQUNELE1BQU0sQ0FBQyxHQUFHLFNBQVMsQ0FBQyxRQUFRLENBQUMsQ0FBQTtRQUM3QixNQUFNLENBQUMsUUFBUSxDQUFDLElBQUksQ0FBQyxHQUFHLENBQUMsQ0FBQTtRQUN6QixPQUFPLENBQUMsQ0FBQTtJQUNWLENBQUM7Q0FDRixDQUNGLENBQUEifQ==
|
|
@@ -1,109 +0,0 @@
|
|
|
1
|
-
import type { FieldValues } from "../../../filter/types.js"
|
|
2
|
-
import type { FieldPath } from "../../../filter/types/path/eager.js"
|
|
3
|
-
|
|
4
|
-
type NullOrUndefined<T, Fallback> = null extends T ? null : undefined extends T ? null : Fallback
|
|
5
|
-
|
|
6
|
-
export type InOps =
|
|
7
|
-
| "in"
|
|
8
|
-
| "notIn"
|
|
9
|
-
|
|
10
|
-
export type OtherOps =
|
|
11
|
-
| "endsWith"
|
|
12
|
-
| "startsWith"
|
|
13
|
-
| "notEndsWith"
|
|
14
|
-
| "notStartsWith"
|
|
15
|
-
| "contains"
|
|
16
|
-
| "notContains"
|
|
17
|
-
| "includes"
|
|
18
|
-
| "notIncludes"
|
|
19
|
-
| "eq"
|
|
20
|
-
| "neq"
|
|
21
|
-
| "gt"
|
|
22
|
-
| "gte"
|
|
23
|
-
| "lt"
|
|
24
|
-
| "lte"
|
|
25
|
-
|
|
26
|
-
// TODO: includes | notIncludes
|
|
27
|
-
export type Ops = OtherOps | InOps
|
|
28
|
-
type F<T extends FieldValues> = {
|
|
29
|
-
path: FieldPath<T>
|
|
30
|
-
op: OtherOps
|
|
31
|
-
value: string
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
type FIn<T extends FieldValues> = {
|
|
35
|
-
op: InOps
|
|
36
|
-
path: FieldPath<T>
|
|
37
|
-
value: readonly string[]
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
type G<T extends FieldValues, Val> = {
|
|
41
|
-
(value: Val): F<T>
|
|
42
|
-
startsWith: (value: string) => F<T>
|
|
43
|
-
notStartsWith: (value: string) => F<T>
|
|
44
|
-
endsWith: (value: string) => F<T>
|
|
45
|
-
notEndsWith: (value: string) => F<T>
|
|
46
|
-
contains: (value: string) => F<T>
|
|
47
|
-
notContains: (value: string) => F<T>
|
|
48
|
-
includes: (value: string) => F<T>
|
|
49
|
-
notIncludes: (value: string) => F<T>
|
|
50
|
-
in: (...value: readonly Val[]) => FIn<T>
|
|
51
|
-
notIn: (...value: readonly Val[]) => FIn<T>
|
|
52
|
-
eq: (value: Val) => F<T>
|
|
53
|
-
neq: (value: Val) => F<T>
|
|
54
|
-
gt: (value: Val) => F<T>
|
|
55
|
-
gte: (value: Val) => F<T>
|
|
56
|
-
lt: (value: Val) => F<T>
|
|
57
|
-
lte: (value: Val) => F<T>
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
export type Filter<T extends FieldValues, Ext = never> = {
|
|
61
|
-
[K in keyof T]-?: [T[K]] extends [Record<any, any> | undefined | null]
|
|
62
|
-
? Filter<T[K], NullOrUndefined<T[K], Ext>> & G<T, T[K] | Ext>
|
|
63
|
-
: [T[K]] extends [Record<any, any>] ? Filter<T[K], NullOrUndefined<T[K], Ext>> & G<T, T[K] | Ext>
|
|
64
|
-
: G<T, T[K] | Ext>
|
|
65
|
-
}
|
|
66
|
-
const ops: Ops[] = [
|
|
67
|
-
"contains",
|
|
68
|
-
"startsWith",
|
|
69
|
-
"endsWith",
|
|
70
|
-
"notContains",
|
|
71
|
-
"notStartsWith",
|
|
72
|
-
"notEndsWith",
|
|
73
|
-
"in",
|
|
74
|
-
"notIn",
|
|
75
|
-
"eq",
|
|
76
|
-
"neq",
|
|
77
|
-
"gte",
|
|
78
|
-
"gt",
|
|
79
|
-
"lt",
|
|
80
|
-
"lte"
|
|
81
|
-
]
|
|
82
|
-
export const makeProxy = (parentProp?: string): any =>
|
|
83
|
-
new Proxy(
|
|
84
|
-
Object.assign(() => {}, {
|
|
85
|
-
_proxies: {} as Record<string, any>
|
|
86
|
-
}),
|
|
87
|
-
{
|
|
88
|
-
apply(_target, _thisArg, argArray) {
|
|
89
|
-
return ({ op: "eq", value: argArray[0], path: parentProp })
|
|
90
|
-
},
|
|
91
|
-
get(target, prop) {
|
|
92
|
-
if (typeof prop !== "string") return undefined
|
|
93
|
-
if (target._proxies[prop]) {
|
|
94
|
-
return target._proxies[prop]
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
if (ops.includes(prop as any)) {
|
|
98
|
-
return (value: any) => ({ op: prop, path: parentProp, value })
|
|
99
|
-
}
|
|
100
|
-
let fullProp = prop
|
|
101
|
-
if (parentProp) {
|
|
102
|
-
fullProp = `${parentProp}.${prop}`
|
|
103
|
-
}
|
|
104
|
-
const p = makeProxy(fullProp)
|
|
105
|
-
target._proxies[prop] = p
|
|
106
|
-
return p
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
)
|