@effect-app/infra 0.202.0 → 0.202.2
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 +15 -0
- package/_cjs/services/RepositoryBase.cjs +21 -88
- package/_cjs/services/RepositoryBase.cjs.map +1 -1
- package/_cjs/services/Store/filterApi/query.cjs +2 -0
- package/_cjs/services/Store/filterApi/query.cjs.map +1 -1
- package/_cjs/services/query.test.cjs +2 -2
- package/_cjs/services/query.test.cjs.map +1 -1
- package/dist/services/RepositoryBase.d.ts +26 -149
- package/dist/services/RepositoryBase.d.ts.map +1 -1
- package/dist/services/RepositoryBase.js +24 -87
- package/dist/services/Store/filterApi/query.d.ts +2 -0
- package/dist/services/Store/filterApi/query.d.ts.map +1 -1
- package/dist/services/Store/filterApi/query.js +3 -1
- package/package.json +4 -4
- package/src/services/RepositoryBase.ts +36 -324
- package/src/services/Store/filterApi/query.ts +2 -0
- package/src/services/query.test.ts +2 -2
|
@@ -9,7 +9,6 @@ import {
|
|
|
9
9
|
byIdAndSaveWithPure,
|
|
10
10
|
get,
|
|
11
11
|
queryEffect,
|
|
12
|
-
queryOneEffect,
|
|
13
12
|
type Repository,
|
|
14
13
|
saveAllWithEffectInt,
|
|
15
14
|
saveManyWithPure_,
|
|
@@ -35,15 +34,15 @@ import { type InvalidStateError, NotFoundError, type OptimisticConcurrencyExcept
|
|
|
35
34
|
import type { FieldValues } from "../filter/types.js"
|
|
36
35
|
import { make as makeQuery } from "./query.js"
|
|
37
36
|
import type { QAll, Query, QueryEnd, QueryProjection, QueryWhere } from "./query.js"
|
|
38
|
-
import * as
|
|
37
|
+
import * as Q from "./query.js"
|
|
39
38
|
import { ContextMapContainer } from "./Store/ContextMapContainer.js"
|
|
40
|
-
import * as
|
|
39
|
+
import * as QB from "./Store/filterApi/query.js"
|
|
41
40
|
|
|
42
41
|
export interface Mapped1<PM extends { id: string }, X, R> {
|
|
43
42
|
all: Effect<X[], ParseResult.ParseError, R>
|
|
44
43
|
save: (...xes: readonly X[]) => Effect<void, OptimisticConcurrencyException | ParseResult.ParseError, R>
|
|
45
44
|
query: (
|
|
46
|
-
b: (fn:
|
|
45
|
+
b: (fn: QB.FilterTest<PM>, fields: QB.Filter<PM, never>) => QB.QueryBuilder<PM>
|
|
47
46
|
) => Effect<X[], ParseResult.ParseError, R>
|
|
48
47
|
find: (id: PM["id"]) => Effect<Option<X>, ParseResult.ParseError, R>
|
|
49
48
|
}
|
|
@@ -52,7 +51,7 @@ export interface Mapped1<PM extends { id: string }, X, R> {
|
|
|
52
51
|
export interface Mapped2<PM extends { id: string }, X, R> {
|
|
53
52
|
all: Effect<X[], ParseResult.ParseError, R>
|
|
54
53
|
query: (
|
|
55
|
-
b: (fn:
|
|
54
|
+
b: (fn: QB.FilterTest<PM>, fields: QB.Filter<PM, never>) => QB.QueryBuilder<PM>
|
|
56
55
|
) => Effect<X[], ParseResult.ParseError, R>
|
|
57
56
|
}
|
|
58
57
|
|
|
@@ -100,9 +99,9 @@ export abstract class RepositoryBaseC<
|
|
|
100
99
|
events?: Iterable<Evt>
|
|
101
100
|
) => Effect<void>
|
|
102
101
|
|
|
103
|
-
/** @deprecated use
|
|
102
|
+
/** @deprecated use query */
|
|
104
103
|
abstract readonly mapped: Mapped<PM, Omit<PM, "_etag">>
|
|
105
|
-
abstract readonly
|
|
104
|
+
abstract readonly query: {
|
|
106
105
|
<A, R, From extends FieldValues, TType extends "one" | "many" | "count" = "many">(
|
|
107
106
|
q: (
|
|
108
107
|
initial: Query<Omit<PM, "_etag">>
|
|
@@ -154,7 +153,7 @@ export class RepositoryBaseC2<
|
|
|
154
153
|
this.utils = this.impl.utils
|
|
155
154
|
this.changeFeed = this.impl.changeFeed
|
|
156
155
|
this.mapped = this.impl.mapped
|
|
157
|
-
this.
|
|
156
|
+
this.query = this.impl.query
|
|
158
157
|
}
|
|
159
158
|
// makes super calls a compiler error, as it should
|
|
160
159
|
override saveAndPublish
|
|
@@ -164,11 +163,9 @@ export class RepositoryBaseC2<
|
|
|
164
163
|
override utils
|
|
165
164
|
override changeFeed
|
|
166
165
|
override mapped
|
|
167
|
-
override
|
|
166
|
+
override query
|
|
168
167
|
}
|
|
169
168
|
|
|
170
|
-
const anyQb = Q.QueryBuilder.make<any>()
|
|
171
|
-
|
|
172
169
|
export class RepositoryBaseC3<
|
|
173
170
|
T extends { id: unknown },
|
|
174
171
|
PM extends PersistenceModelType<string>,
|
|
@@ -189,19 +186,12 @@ export class RepositoryBaseC3<
|
|
|
189
186
|
return Effect.andThen(this.get(id), (_) => this.removeAndPublish([_]))
|
|
190
187
|
}
|
|
191
188
|
|
|
192
|
-
count(filter?: Filter<PM>) {
|
|
193
|
-
return Effect.map(
|
|
194
|
-
this.projectEffect(Effect.sync(() => ({ filter }))),
|
|
195
|
-
(_) => NonNegativeInt(_.length)
|
|
196
|
-
)
|
|
197
|
-
}
|
|
198
|
-
|
|
199
189
|
readonly save = (...items: NonEmptyArray<T>) => this.saveAndPublish(items)
|
|
200
190
|
|
|
201
191
|
readonly saveWithEvents = (events: Iterable<Evt>) => (...items: NonEmptyArray<T>) =>
|
|
202
192
|
this.saveAndPublish(items, events)
|
|
203
193
|
|
|
204
|
-
readonly
|
|
194
|
+
readonly queryAndSavePure: {
|
|
205
195
|
<A, E2, R2, T2 extends T>(
|
|
206
196
|
q: (
|
|
207
197
|
q: Query<Omit<PM, "_etag">>
|
|
@@ -240,7 +230,7 @@ export class RepositoryBaseC3<
|
|
|
240
230
|
}>
|
|
241
231
|
>
|
|
242
232
|
} = (q: any, pure: any, batchSize?: any) =>
|
|
243
|
-
this.
|
|
233
|
+
this.query(q).pipe(
|
|
244
234
|
Effect.andThen((_) =>
|
|
245
235
|
Array.isArray(_)
|
|
246
236
|
? batchSize === undefined
|
|
@@ -303,114 +293,12 @@ export class RepositoryBaseC3<
|
|
|
303
293
|
)
|
|
304
294
|
}
|
|
305
295
|
|
|
306
|
-
/** @deprecated use
|
|
307
|
-
|
|
308
|
-
R,
|
|
309
|
-
E,
|
|
310
|
-
S = PM
|
|
311
|
-
>(
|
|
312
|
-
map: Effect<
|
|
313
|
-
{
|
|
314
|
-
filter?: Filter<PM> | undefined
|
|
315
|
-
collect?: ((t: PM) => Option<S>) | undefined
|
|
316
|
-
limit?: number | undefined
|
|
317
|
-
skip?: number | undefined
|
|
318
|
-
},
|
|
319
|
-
E,
|
|
320
|
-
R
|
|
321
|
-
>
|
|
322
|
-
): Effect<S[], E, R>
|
|
323
|
-
/** @deprecated use q2 */
|
|
324
|
-
projectEffect<
|
|
325
|
-
R,
|
|
326
|
-
E,
|
|
327
|
-
U extends keyof PM,
|
|
328
|
-
S = PM
|
|
329
|
-
>(
|
|
330
|
-
map: Effect<
|
|
331
|
-
{
|
|
332
|
-
filter?: Q.QueryBuilder<PM> | undefined
|
|
333
|
-
collect?: ((t: PM) => Option<S>) | undefined
|
|
334
|
-
limit?: number | undefined
|
|
335
|
-
skip?: number | undefined
|
|
336
|
-
},
|
|
337
|
-
E,
|
|
338
|
-
R
|
|
339
|
-
>
|
|
340
|
-
): Effect<Pick<PM, U>[], E, R>
|
|
341
|
-
/** @deprecated use q2 */
|
|
342
|
-
projectEffect<
|
|
343
|
-
R,
|
|
344
|
-
E,
|
|
345
|
-
U extends keyof PM,
|
|
346
|
-
S = Pick<PM, U>
|
|
347
|
-
>(
|
|
348
|
-
map: Effect<
|
|
349
|
-
{
|
|
350
|
-
filter?: Filter<PM> | undefined
|
|
351
|
-
select?: NonEmptyReadonlyArray<U> | undefined
|
|
352
|
-
collect?: ((t: PM) => Option<S>) | undefined
|
|
353
|
-
limit?: number | undefined
|
|
354
|
-
skip?: number | undefined
|
|
355
|
-
},
|
|
356
|
-
E,
|
|
357
|
-
R
|
|
358
|
-
>
|
|
359
|
-
): Effect<S[], E, R> {
|
|
360
|
-
// TODO: a projection that gets sent to the db instead.
|
|
361
|
-
return Effect.flatMap(map, (f) =>
|
|
362
|
-
Effect.map(
|
|
363
|
-
this
|
|
364
|
-
.utils
|
|
365
|
-
.filter(f),
|
|
366
|
-
(_) => f.collect ? ReadonlyArray.filterMap(_, f.collect) : _ as unknown as S[]
|
|
367
|
-
))
|
|
368
|
-
}
|
|
369
|
-
|
|
370
|
-
/** @deprecated use q2 */
|
|
371
|
-
project<S = PM>(
|
|
372
|
-
map: {
|
|
373
|
-
filter?: Filter<PM>
|
|
374
|
-
collect?: (t: PM) => Option<S>
|
|
375
|
-
limit?: number
|
|
376
|
-
skip?: number
|
|
377
|
-
}
|
|
378
|
-
): Effect<S[]>
|
|
379
|
-
/** @deprecated use q2 */
|
|
380
|
-
project<U extends keyof PM>(
|
|
381
|
-
map: {
|
|
382
|
-
filter?: Q.QueryBuilder<PM>
|
|
383
|
-
select: NonEmptyReadonlyArray<U>
|
|
384
|
-
limit?: number
|
|
385
|
-
skip?: number
|
|
386
|
-
}
|
|
387
|
-
): Effect<Pick<PM, U>[]>
|
|
388
|
-
/** @deprecated use q2 */
|
|
389
|
-
project<
|
|
390
|
-
U extends keyof PM,
|
|
391
|
-
S = Pick<PM, U>
|
|
392
|
-
>(
|
|
393
|
-
map: {
|
|
394
|
-
filter?: Filter<PM>
|
|
395
|
-
select?: NonEmptyReadonlyArray<U>
|
|
396
|
-
collect?: (t: Pick<PM, U>) => Option<S>
|
|
397
|
-
limit?: number
|
|
398
|
-
skip?: number
|
|
399
|
-
}
|
|
400
|
-
): Effect<S[]> {
|
|
401
|
-
return this.projectEffect(Effect.sync(() => map))
|
|
402
|
-
}
|
|
403
|
-
|
|
404
|
-
/** @deprecated use q2 */
|
|
405
|
-
queryEffect<
|
|
406
|
-
R,
|
|
407
|
-
E,
|
|
408
|
-
S = T
|
|
409
|
-
>(
|
|
296
|
+
/** @deprecated use query */
|
|
297
|
+
queryLegacy<S = T>(
|
|
410
298
|
// TODO: think about collectPM, collectE, and collect(Parsed)
|
|
411
|
-
|
|
299
|
+
_map: { filter?: Filter<PM>; collect?: (t: T) => Option<S>; limit?: number; skip?: number }
|
|
412
300
|
) {
|
|
413
|
-
return Effect.flatMap(
|
|
301
|
+
return Effect.flatMap(Effect.sync(() => _map), (f) =>
|
|
414
302
|
(f.filter ? this.utils.filter(f) : this.utils.all)
|
|
415
303
|
.pipe(
|
|
416
304
|
Effect.flatMap((_) => this.utils.parseMany(_)),
|
|
@@ -418,180 +306,7 @@ export class RepositoryBaseC3<
|
|
|
418
306
|
))
|
|
419
307
|
}
|
|
420
308
|
|
|
421
|
-
/** @deprecated use
|
|
422
|
-
queryOneEffect<R, E>(
|
|
423
|
-
// TODO: think about collectPM, collectE, and collect(Parsed)
|
|
424
|
-
map: Effect<{ filter?: Filter<PM> }, E, R>
|
|
425
|
-
): Effect<T, E | NotFoundError<ItemType>, R>
|
|
426
|
-
/** @deprecated use q2 */
|
|
427
|
-
queryOneEffect<
|
|
428
|
-
R,
|
|
429
|
-
E,
|
|
430
|
-
S = T
|
|
431
|
-
>(
|
|
432
|
-
// TODO: think about collectPM, collectE, and collect(Parsed)
|
|
433
|
-
map: Effect<{ filter?: Filter<PM>; collect: (t: T) => Option<S> }, E, R>
|
|
434
|
-
): Effect<S, E | NotFoundError<ItemType>, R>
|
|
435
|
-
/** @deprecated use q2 */
|
|
436
|
-
queryOneEffect<
|
|
437
|
-
R,
|
|
438
|
-
E,
|
|
439
|
-
S = T
|
|
440
|
-
>(
|
|
441
|
-
// TODO: think about collectPM, collectE, and collect(Parsed)
|
|
442
|
-
map: Effect<{ filter?: Filter<PM>; collect?: (t: T) => Option<S> }, E, R>
|
|
443
|
-
): Effect<S, E | NotFoundError<ItemType>, R> {
|
|
444
|
-
return Effect.flatMap(map, (f) =>
|
|
445
|
-
(f.filter ? this.utils.filter({ filter: f.filter, limit: 1 }) : this.utils.all)
|
|
446
|
-
.pipe(
|
|
447
|
-
Effect.flatMap((_) => this.utils.parseMany(_)),
|
|
448
|
-
Effect
|
|
449
|
-
.flatMap((_) =>
|
|
450
|
-
toNonEmptyArray(
|
|
451
|
-
f.collect
|
|
452
|
-
? ReadonlyArray.filterMap(_, f.collect)
|
|
453
|
-
: _ as unknown[] as S[]
|
|
454
|
-
)
|
|
455
|
-
.pipe(
|
|
456
|
-
Effect.mapError(() => new NotFoundError<ItemType>({ type: this.itemType, id: f.filter })),
|
|
457
|
-
Effect.map((_) => _[0])
|
|
458
|
-
)
|
|
459
|
-
)
|
|
460
|
-
))
|
|
461
|
-
}
|
|
462
|
-
|
|
463
|
-
/** @deprecated use q2 */
|
|
464
|
-
queryLegacy<S = T>(
|
|
465
|
-
// TODO: think about collectPM, collectE, and collect(Parsed)
|
|
466
|
-
map: { filter?: Filter<PM>; collect?: (t: T) => Option<S>; limit?: number; skip?: number }
|
|
467
|
-
) {
|
|
468
|
-
return this.queryEffect(Effect.sync(() => map))
|
|
469
|
-
}
|
|
470
|
-
|
|
471
|
-
/** @deprecated use q2 */
|
|
472
|
-
query(
|
|
473
|
-
b: (fn: Q.FilterTest<PM>, fields: Q.Filter<PM, never>) => Q.QueryBuilder<PM>
|
|
474
|
-
) {
|
|
475
|
-
return this.queryEffect(Effect.sync(() => ({ filter: anyQb((_, fields) => b(_, fields as any)) })))
|
|
476
|
-
}
|
|
477
|
-
|
|
478
|
-
/** @deprecated use q2 */
|
|
479
|
-
queryOne<S = T>(
|
|
480
|
-
map: { filter?: Filter<PM>; collect: (t: T) => Option<S> }
|
|
481
|
-
): Effect<S, NotFoundError<ItemType>>
|
|
482
|
-
/** @deprecated use q2 */
|
|
483
|
-
queryOne(
|
|
484
|
-
map: { filter?: Filter<PM> }
|
|
485
|
-
): Effect<T, NotFoundError<ItemType>>
|
|
486
|
-
/** @deprecated use q2 */
|
|
487
|
-
queryOne<S = T>(
|
|
488
|
-
map: { filter?: Filter<PM>; collect?: (t: T) => Option<S> }
|
|
489
|
-
) {
|
|
490
|
-
return this.queryOneEffect(Effect.sync(() => map))
|
|
491
|
-
}
|
|
492
|
-
|
|
493
|
-
/** @deprecated */
|
|
494
|
-
queryAndSaveOnePureEffect<
|
|
495
|
-
R,
|
|
496
|
-
E,
|
|
497
|
-
S extends T = T
|
|
498
|
-
>(
|
|
499
|
-
map: Effect<{ filter: Filter<PM>; collect: (t: T) => Option<S>; limit?: number; skip?: number }, E, R>
|
|
500
|
-
): <R2, A, E2, S2 extends T>(
|
|
501
|
-
pure: Effect<A, E2, FixEnv<R2, Evt, S, S2>>
|
|
502
|
-
) => Effect<
|
|
503
|
-
A,
|
|
504
|
-
InvalidStateError | OptimisticConcurrencyException | E | E2 | NotFoundError<ItemType>,
|
|
505
|
-
| R
|
|
506
|
-
| Exclude<R2, {
|
|
507
|
-
env: PureEnv<Evt, S, S2>
|
|
508
|
-
}>
|
|
509
|
-
>
|
|
510
|
-
/** @deprecated */
|
|
511
|
-
queryAndSaveOnePureEffect<
|
|
512
|
-
R,
|
|
513
|
-
E
|
|
514
|
-
>(
|
|
515
|
-
map: Effect<{ filter: Filter<PM> }, E, R>
|
|
516
|
-
): <R2, A, E2, T2 extends T>(
|
|
517
|
-
pure: Effect<A, E2, FixEnv<R2, Evt, T, T2>>
|
|
518
|
-
) => Effect<
|
|
519
|
-
A,
|
|
520
|
-
InvalidStateError | OptimisticConcurrencyException | E | E2 | NotFoundError<ItemType>,
|
|
521
|
-
| R
|
|
522
|
-
| Exclude<R2, {
|
|
523
|
-
env: PureEnv<Evt, T, T2>
|
|
524
|
-
}>
|
|
525
|
-
>
|
|
526
|
-
/** @deprecated */
|
|
527
|
-
queryAndSaveOnePureEffect(
|
|
528
|
-
map: any
|
|
529
|
-
) {
|
|
530
|
-
return (pure: any) => Effect.flatMap(queryOneEffect(this, map), (_) => saveWithPure_(this, _, pure))
|
|
531
|
-
}
|
|
532
|
-
/** @deprecated */
|
|
533
|
-
queryAndSaveOnePure<
|
|
534
|
-
S extends T = T
|
|
535
|
-
>(
|
|
536
|
-
map: { filter: Filter<PM>; collect: (t: T) => Option<S>; limit?: number; skip?: number }
|
|
537
|
-
): <R2, A, E2, S2>(pure: Effect<A, E2, FixEnv<R2, Evt, S, S2>>) => Effect<
|
|
538
|
-
A,
|
|
539
|
-
InvalidStateError | OptimisticConcurrencyException | E2 | NotFoundError<ItemType>,
|
|
540
|
-
Exclude<R2, {
|
|
541
|
-
env: PureEnv<Evt, S, S2>
|
|
542
|
-
}>
|
|
543
|
-
>
|
|
544
|
-
/** @deprecated */
|
|
545
|
-
queryAndSaveOnePure(
|
|
546
|
-
map: { filter: Filter<PM> }
|
|
547
|
-
): <R2, A, E2, T2>(pure: Effect<A, E2, FixEnv<R2, Evt, T, T2>>) => Effect<
|
|
548
|
-
A,
|
|
549
|
-
InvalidStateError | OptimisticConcurrencyException | E2 | NotFoundError<ItemType>,
|
|
550
|
-
Exclude<R2, {
|
|
551
|
-
env: PureEnv<Evt, T, T2>
|
|
552
|
-
}>
|
|
553
|
-
>
|
|
554
|
-
/** @deprecated */
|
|
555
|
-
queryAndSaveOnePure<S = T>(
|
|
556
|
-
map: { filter: Filter<PM>; collect: (t: T) => Option<S> }
|
|
557
|
-
) {
|
|
558
|
-
return this.queryAndSaveOnePureEffect(Effect.sync(() => map))
|
|
559
|
-
}
|
|
560
|
-
/** @deprecated */
|
|
561
|
-
queryAndSavePureEffect<
|
|
562
|
-
R,
|
|
563
|
-
E,
|
|
564
|
-
S extends T = T
|
|
565
|
-
>(
|
|
566
|
-
map: Effect<{ filter: Filter<PM>; collect?: (t: T) => Option<S>; limit?: number; skip?: number }, E, R>
|
|
567
|
-
) {
|
|
568
|
-
return <R2, A, E2, S2 extends T>(pure: Effect<A, E2, FixEnv<R2, Evt, readonly S[], readonly S2[]>>) =>
|
|
569
|
-
Effect.flatMap(queryEffect(this, map), (_) => this.saveManyWithPure(_, pure))
|
|
570
|
-
}
|
|
571
|
-
/** @deprecated */
|
|
572
|
-
queryAndSavePure<
|
|
573
|
-
S extends T = T
|
|
574
|
-
>(
|
|
575
|
-
map: { filter: Filter<PM>; collect?: (t: T) => Option<S>; limit?: number; skip?: number }
|
|
576
|
-
) {
|
|
577
|
-
return this.queryAndSavePureEffect(Effect.sync(() => map))
|
|
578
|
-
}
|
|
579
|
-
|
|
580
|
-
/** @deprecated use q2 */
|
|
581
|
-
queryAndSavePureEffectBatched<
|
|
582
|
-
R,
|
|
583
|
-
E,
|
|
584
|
-
S extends T = T
|
|
585
|
-
>(
|
|
586
|
-
// TODO: think about collectPM, collectE, and collect(Parsed)
|
|
587
|
-
map: Effect<{ filter: Filter<PM>; collect?: (t: T) => Option<S>; limit?: number; skip?: number }, E, R>,
|
|
588
|
-
batchSize = 100
|
|
589
|
-
) {
|
|
590
|
-
return <R2, A, E2, S2 extends T>(pure: Effect<A, E2, FixEnv<R2, Evt, readonly S[], readonly S2[]>>) =>
|
|
591
|
-
Effect.flatMap(queryEffect(this, map), (_) => this.saveManyWithPureBatched(_, pure, batchSize))
|
|
592
|
-
}
|
|
593
|
-
|
|
594
|
-
/** @deprecated use q2 */
|
|
309
|
+
/** @deprecated use query */
|
|
595
310
|
queryAndSavePureBatched<
|
|
596
311
|
S extends T = T
|
|
597
312
|
>(
|
|
@@ -599,10 +314,11 @@ export class RepositoryBaseC3<
|
|
|
599
314
|
map: { filter: Filter<PM>; collect?: (t: T) => Option<S>; limit?: number; skip?: number },
|
|
600
315
|
batchSize = 100
|
|
601
316
|
) {
|
|
602
|
-
return
|
|
317
|
+
return <R2, A, E2, S2 extends T>(pure: Effect<A, E2, FixEnv<R2, Evt, readonly S[], readonly S2[]>>) =>
|
|
318
|
+
Effect.flatMap(queryEffect(this, Effect.succeed(map)), (_) => this.saveManyWithPureBatched(_, pure, batchSize))
|
|
603
319
|
}
|
|
604
320
|
|
|
605
|
-
/** @deprecated use
|
|
321
|
+
/** @deprecated use query */
|
|
606
322
|
saveManyWithPureBatched<
|
|
607
323
|
R,
|
|
608
324
|
A,
|
|
@@ -836,7 +552,7 @@ export function makeRepo<
|
|
|
836
552
|
A,
|
|
837
553
|
R
|
|
838
554
|
>(q: QAll<PM, A, R>) => {
|
|
839
|
-
const a =
|
|
555
|
+
const a = Q.toFilter(q)
|
|
840
556
|
const eff = a.mode === "raw" ? r.utils.filter(a) : Effect.flatMap(
|
|
841
557
|
r.utils.filter(a),
|
|
842
558
|
(_) =>
|
|
@@ -933,7 +649,7 @@ export function makeRepo<
|
|
|
933
649
|
all,
|
|
934
650
|
saveAndPublish,
|
|
935
651
|
removeAndPublish,
|
|
936
|
-
|
|
652
|
+
query: (q: any) => query(typeof q === "function" ? q(makeQuery()) : q) as any
|
|
937
653
|
}
|
|
938
654
|
return r
|
|
939
655
|
})
|
|
@@ -945,8 +661,8 @@ export function makeRepo<
|
|
|
945
661
|
return {
|
|
946
662
|
make,
|
|
947
663
|
Where: where,
|
|
948
|
-
Query:
|
|
949
|
-
|
|
664
|
+
Query: QB.QueryBuilder.make<PM>(),
|
|
665
|
+
Q: Q.make<Omit<PM, "_etag">>()
|
|
950
666
|
}
|
|
951
667
|
}
|
|
952
668
|
}
|
|
@@ -1102,11 +818,11 @@ export interface Repos<
|
|
|
1102
818
|
},
|
|
1103
819
|
f: (r: Repository<T, PM, Evt, ItemType>) => Out
|
|
1104
820
|
): Effect<Out, E, StoreMaker | ContextMapContainer | R | RInitial | R2>
|
|
1105
|
-
/** @deprecated use `
|
|
821
|
+
/** @deprecated use `Q` instead */
|
|
1106
822
|
readonly Where: ReturnType<typeof makeWhere<PM>>
|
|
1107
|
-
/** @deprecated use `
|
|
1108
|
-
readonly Query: ReturnType<typeof
|
|
1109
|
-
readonly
|
|
823
|
+
/** @deprecated use `Q` instead */
|
|
824
|
+
readonly Query: ReturnType<typeof QB.QueryBuilder.make<PM>>
|
|
825
|
+
readonly Q: ReturnType<typeof Q.make<PM>>
|
|
1110
826
|
readonly type: Repository<T, PM, Evt, ItemType>
|
|
1111
827
|
}
|
|
1112
828
|
|
|
@@ -1127,9 +843,7 @@ export interface RepoFunctions<T extends { id: unknown }, PM extends { id: strin
|
|
|
1127
843
|
save: (...items: T[]) => Effect<void, InvalidStateError | OptimisticConcurrencyException, Service>
|
|
1128
844
|
get: (id: T["id"]) => Effect<T, NotFoundError<ItemType>, Service>
|
|
1129
845
|
|
|
1130
|
-
/** @deprecated use
|
|
1131
|
-
query: (b: (fn: Q.FilterTest<PM>, fields: Q.Filter<PM, never>) => Q.QueryBuilder<PM>) => Effect<T[], never, Service>
|
|
1132
|
-
/** @deprecated use q2 */
|
|
846
|
+
/** @deprecated use query */
|
|
1133
847
|
queryLegacy: <S = T>(map: {
|
|
1134
848
|
filter?: Filter<PM>
|
|
1135
849
|
collect?: (t: T) => Option<S>
|
|
@@ -1137,7 +851,7 @@ export interface RepoFunctions<T extends { id: unknown }, PM extends { id: strin
|
|
|
1137
851
|
skip?: number
|
|
1138
852
|
}) => Effect<S[], never, Service>
|
|
1139
853
|
|
|
1140
|
-
/** @deprecated use
|
|
854
|
+
/** @deprecated use query */
|
|
1141
855
|
mapped: MM<Service, PM, Omit<PM, "_etag">>
|
|
1142
856
|
|
|
1143
857
|
byIdAndSaveWithPure: {
|
|
@@ -1154,7 +868,7 @@ export interface RepoFunctions<T extends { id: unknown }, PM extends { id: strin
|
|
|
1154
868
|
>
|
|
1155
869
|
}
|
|
1156
870
|
|
|
1157
|
-
|
|
871
|
+
queryAndSavePure: {
|
|
1158
872
|
<A, E2, R2, T2 extends T>(
|
|
1159
873
|
q: (
|
|
1160
874
|
q: Query<Omit<PM, "_etag">>
|
|
@@ -1197,7 +911,7 @@ export interface RepoFunctions<T extends { id: unknown }, PM extends { id: strin
|
|
|
1197
911
|
>
|
|
1198
912
|
}
|
|
1199
913
|
|
|
1200
|
-
readonly
|
|
914
|
+
readonly query: {
|
|
1201
915
|
<A, R, From extends FieldValues, TType extends "one" | "many" | "count" = "many">(
|
|
1202
916
|
q: (
|
|
1203
917
|
initial: Query<Omit<PM, "_etag">>
|
|
@@ -1228,9 +942,8 @@ const makeRepoFunctions = (tag: any) => {
|
|
|
1228
942
|
byIdAndSaveWithPure,
|
|
1229
943
|
find,
|
|
1230
944
|
get,
|
|
1231
|
-
q2,
|
|
1232
|
-
q2AndSavePure,
|
|
1233
945
|
query,
|
|
946
|
+
queryAndSavePure,
|
|
1234
947
|
queryLegacy,
|
|
1235
948
|
removeAndPublish,
|
|
1236
949
|
removeById,
|
|
@@ -1251,9 +964,8 @@ const makeRepoFunctions = (tag: any) => {
|
|
|
1251
964
|
get,
|
|
1252
965
|
query,
|
|
1253
966
|
queryLegacy,
|
|
1254
|
-
q2,
|
|
1255
967
|
mapped,
|
|
1256
|
-
|
|
968
|
+
queryAndSavePure
|
|
1257
969
|
}
|
|
1258
970
|
}
|
|
1259
971
|
|
|
@@ -1293,8 +1005,8 @@ export const RepositoryBaseImpl = <Service>() => {
|
|
|
1293
1005
|
static readonly makeWith = ((a: any, b: any) => Effect.map(mkRepo.make(a), b)) as any
|
|
1294
1006
|
|
|
1295
1007
|
static readonly Where = makeWhere<PM>()
|
|
1296
|
-
static readonly Query =
|
|
1297
|
-
static readonly
|
|
1008
|
+
static readonly Query = QB.QueryBuilder.make<PM>()
|
|
1009
|
+
static readonly Q = Q.make<From>()
|
|
1298
1010
|
static readonly type: Repository<T, PM, Evt, ItemType> = undefined as any
|
|
1299
1011
|
}
|
|
1300
1012
|
|
|
@@ -1342,8 +1054,8 @@ export const RepositoryDefaultImpl = <Service>() => {
|
|
|
1342
1054
|
static readonly makeWith = ((a: any, b: any) => Effect.map(mkRepo.make(a), b)) as any
|
|
1343
1055
|
|
|
1344
1056
|
static readonly Where = makeWhere<PM>()
|
|
1345
|
-
static readonly Query =
|
|
1346
|
-
static readonly
|
|
1057
|
+
static readonly Query = QB.QueryBuilder.make<PM>()
|
|
1058
|
+
static readonly Q = Q.make<From>()
|
|
1347
1059
|
|
|
1348
1060
|
static readonly type: Repository<T, PM, Evt, ItemType> = undefined as any
|
|
1349
1061
|
}
|
|
@@ -160,7 +160,9 @@ export const makeFilter = <TFieldValues extends FieldValues>() => {
|
|
|
160
160
|
return { all, fields }
|
|
161
161
|
}
|
|
162
162
|
|
|
163
|
+
/** @deprecated use Q */
|
|
163
164
|
export const QueryBuilder = {
|
|
165
|
+
/** @deprecated use Q */
|
|
164
166
|
make: <TFieldValues extends FieldValues>(): (
|
|
165
167
|
fn: (f: FilterTest<TFieldValues>, fields: Filter<TFieldValues>) => QueryBuilder<TFieldValues>
|
|
166
168
|
) => QueryBuilder<TFieldValues> => {
|
|
@@ -58,10 +58,10 @@ it.skip("works with repo", () => {
|
|
|
58
58
|
"test",
|
|
59
59
|
s
|
|
60
60
|
) {}
|
|
61
|
-
const q1 = TestRepo.
|
|
61
|
+
const q1 = TestRepo.query(() => q)
|
|
62
62
|
|
|
63
63
|
// same as above, but with the `flow` helper
|
|
64
|
-
const q2 = TestRepo.
|
|
64
|
+
const q2 = TestRepo.query(flow(
|
|
65
65
|
where("displayName", "Verona"),
|
|
66
66
|
or(flow(
|
|
67
67
|
where("displayName", "Riley"),
|