@effect-app/infra 0.199.0 → 0.200.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 +30 -0
- package/_cjs/services/Repository/ext.cjs.map +1 -1
- package/_cjs/services/RepositoryBase.cjs +53 -38
- package/_cjs/services/RepositoryBase.cjs.map +1 -1
- package/dist/services/Repository/dsl.d.ts +3 -3
- package/dist/services/Repository/dsl.d.ts.map +1 -1
- package/dist/services/Repository/ext.d.ts +16 -16
- package/dist/services/Repository/ext.d.ts.map +1 -1
- package/dist/services/Repository/ext.js +1 -1
- package/dist/services/RepositoryBase.d.ts +82 -42
- package/dist/services/RepositoryBase.d.ts.map +1 -1
- package/dist/services/RepositoryBase.js +58 -41
- package/package.json +7 -7
- package/src/services/Repository/dsl.ts +6 -6
- package/src/services/Repository/ext.ts +6 -6
- package/src/services/RepositoryBase.ts +216 -123
|
@@ -29,7 +29,9 @@ import type { FixEnv, PureEnv } from "effect-app/Pure"
|
|
|
29
29
|
import { assignTag } from "effect-app/service"
|
|
30
30
|
import { type InvalidStateError, NotFoundError, type OptimisticConcurrencyException } from "../errors.js"
|
|
31
31
|
import type { FieldValues } from "../filter/types.js"
|
|
32
|
-
import { make as makeQuery,
|
|
32
|
+
import { make as makeQuery, page, query } from "./query.js"
|
|
33
|
+
import type { QAll, Query, QueryEnd, QueryProjection, QueryWhere } from "./query.js"
|
|
34
|
+
import * as Q2 from "./query.js"
|
|
33
35
|
import { ContextMapContainer } from "./Store/ContextMapContainer.js"
|
|
34
36
|
import * as Q from "./Store/filterApi/query.js"
|
|
35
37
|
|
|
@@ -94,6 +96,7 @@ export abstract class RepositoryBaseC<
|
|
|
94
96
|
events?: Iterable<Evt>
|
|
95
97
|
) => Effect<void>
|
|
96
98
|
|
|
99
|
+
/** @deprecated use q2 */
|
|
97
100
|
abstract readonly mapped: Mapped<PM, Omit<PM, "_etag">>
|
|
98
101
|
abstract readonly q2: {
|
|
99
102
|
<A, R, From extends FieldValues>(
|
|
@@ -176,7 +179,95 @@ export class RepositoryBaseC3<
|
|
|
176
179
|
return Effect.andThen(this.get(id), (_) => this.removeAndPublish([_]))
|
|
177
180
|
}
|
|
178
181
|
|
|
179
|
-
|
|
182
|
+
count(filter?: Filter<PM>) {
|
|
183
|
+
return Effect.map(
|
|
184
|
+
this.projectEffect(Effect.sync(() => ({ filter }))),
|
|
185
|
+
(_) => NonNegativeInt(_.length)
|
|
186
|
+
)
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
readonly save = (...items: NonEmptyArray<T>) => this.saveAndPublish(items)
|
|
190
|
+
|
|
191
|
+
readonly saveWithEvents = (events: Iterable<Evt>) => (...items: NonEmptyArray<T>) =>
|
|
192
|
+
this.saveAndPublish(items, events)
|
|
193
|
+
|
|
194
|
+
readonly q2AndSaveOnePure = <A, E2, R2, T2 extends T>(
|
|
195
|
+
q: (q: Query<Omit<PM, "_etag">>) => Query<Omit<PM, "_etag">> | QueryEnd<Omit<PM, "_etag">>,
|
|
196
|
+
pure: Effect<A, E2, FixEnv<R2, Evt, T, T2>>
|
|
197
|
+
) =>
|
|
198
|
+
this.q2(flow(q, page({ limit: 1 }))).pipe(
|
|
199
|
+
Effect.map(ReadonlyArray.toNonEmptyArray),
|
|
200
|
+
Effect.flatMap(Effect.mapError(() => new NotFoundError({ type: this.itemType, id: q }))),
|
|
201
|
+
Effect.andThen((_) => saveWithPure_(this, _[0], pure))
|
|
202
|
+
)
|
|
203
|
+
|
|
204
|
+
readonly q2AndSavePure = <A, E2, R2, T2 extends T>(
|
|
205
|
+
q: (q: Query<Omit<PM, "_etag">>) => Query<Omit<PM, "_etag">> | QueryEnd<Omit<PM, "_etag">>,
|
|
206
|
+
pure: Effect<A, E2, FixEnv<R2, Evt, readonly T[], readonly T2[]>>,
|
|
207
|
+
batchSize?: number
|
|
208
|
+
) =>
|
|
209
|
+
this.q2(flow(q, page({ limit: 1 }))).pipe(
|
|
210
|
+
Effect.andThen((_) =>
|
|
211
|
+
batchSize === undefined
|
|
212
|
+
? saveManyWithPure_(this, _, pure)
|
|
213
|
+
: saveManyWithPureBatched_(this, _, pure, batchSize)
|
|
214
|
+
)
|
|
215
|
+
)
|
|
216
|
+
|
|
217
|
+
/**
|
|
218
|
+
* NOTE: it's not as composable, only useful when the request is simple, and only this part needs request args.
|
|
219
|
+
*/
|
|
220
|
+
readonly handleByIdAndSaveWithPure = <Req extends { id: T["id"] }, Context, R, A, E, S2 extends T>(
|
|
221
|
+
pure: (req: Req, ctx: Context) => Effect<A, E, FixEnv<R, Evt, T, S2>>
|
|
222
|
+
) =>
|
|
223
|
+
(req: Req, ctx: Context) => byIdAndSaveWithPure(this, req.id)(pure(req, ctx))
|
|
224
|
+
|
|
225
|
+
saveManyWithPure = <
|
|
226
|
+
R,
|
|
227
|
+
A,
|
|
228
|
+
E,
|
|
229
|
+
S1 extends T,
|
|
230
|
+
S2 extends T
|
|
231
|
+
>(
|
|
232
|
+
items: Iterable<S1>,
|
|
233
|
+
pure: Effect<A, E, FixEnv<R, Evt, readonly S1[], readonly S2[]>>
|
|
234
|
+
) =>
|
|
235
|
+
saveAllWithEffectInt(
|
|
236
|
+
this,
|
|
237
|
+
runTerm(pure, [...items])
|
|
238
|
+
)
|
|
239
|
+
|
|
240
|
+
byIdAndSaveWithPure: {
|
|
241
|
+
<R, A, E, S2 extends T>(
|
|
242
|
+
id: T["id"],
|
|
243
|
+
pure: Effect<A, E, FixEnv<R, Evt, T, S2>>
|
|
244
|
+
): Effect<
|
|
245
|
+
A,
|
|
246
|
+
InvalidStateError | OptimisticConcurrencyException | NotFoundError<ItemType> | E,
|
|
247
|
+
Exclude<R, {
|
|
248
|
+
env: PureEnv<Evt, T, S2>
|
|
249
|
+
}>
|
|
250
|
+
>
|
|
251
|
+
} = (id, pure): any => get(this, id).pipe(Effect.flatMap((item) => saveWithPure_(this, item, pure)))
|
|
252
|
+
|
|
253
|
+
saveWithPure<
|
|
254
|
+
R,
|
|
255
|
+
A,
|
|
256
|
+
E,
|
|
257
|
+
S1 extends T,
|
|
258
|
+
S2 extends T
|
|
259
|
+
>(
|
|
260
|
+
item: S1,
|
|
261
|
+
pure: Effect<A, E, FixEnv<R, Evt, S1, S2>>
|
|
262
|
+
) {
|
|
263
|
+
return saveAllWithEffectInt(
|
|
264
|
+
this,
|
|
265
|
+
runTerm(pure, item)
|
|
266
|
+
.pipe(Effect.map(([item, events, a]) => [[item], events, a]))
|
|
267
|
+
)
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
/** @deprecated use q2 */
|
|
180
271
|
projectEffect<
|
|
181
272
|
R,
|
|
182
273
|
E,
|
|
@@ -193,6 +284,7 @@ export class RepositoryBaseC3<
|
|
|
193
284
|
R
|
|
194
285
|
>
|
|
195
286
|
): Effect<S[], E, R>
|
|
287
|
+
/** @deprecated use q2 */
|
|
196
288
|
projectEffect<
|
|
197
289
|
R,
|
|
198
290
|
E,
|
|
@@ -210,6 +302,7 @@ export class RepositoryBaseC3<
|
|
|
210
302
|
R
|
|
211
303
|
>
|
|
212
304
|
): Effect<Pick<PM, U>[], E, R>
|
|
305
|
+
/** @deprecated use q2 */
|
|
213
306
|
projectEffect<
|
|
214
307
|
R,
|
|
215
308
|
E,
|
|
@@ -238,6 +331,7 @@ export class RepositoryBaseC3<
|
|
|
238
331
|
))
|
|
239
332
|
}
|
|
240
333
|
|
|
334
|
+
/** @deprecated use q2 */
|
|
241
335
|
project<S = PM>(
|
|
242
336
|
map: {
|
|
243
337
|
filter?: Filter<PM>
|
|
@@ -246,6 +340,7 @@ export class RepositoryBaseC3<
|
|
|
246
340
|
skip?: number
|
|
247
341
|
}
|
|
248
342
|
): Effect<S[]>
|
|
343
|
+
/** @deprecated use q2 */
|
|
249
344
|
project<U extends keyof PM>(
|
|
250
345
|
map: {
|
|
251
346
|
filter?: Q.QueryBuilder<PM>
|
|
@@ -254,6 +349,7 @@ export class RepositoryBaseC3<
|
|
|
254
349
|
skip?: number
|
|
255
350
|
}
|
|
256
351
|
): Effect<Pick<PM, U>[]>
|
|
352
|
+
/** @deprecated use q2 */
|
|
257
353
|
project<
|
|
258
354
|
U extends keyof PM,
|
|
259
355
|
S = Pick<PM, U>
|
|
@@ -269,13 +365,7 @@ export class RepositoryBaseC3<
|
|
|
269
365
|
return this.projectEffect(Effect.sync(() => map))
|
|
270
366
|
}
|
|
271
367
|
|
|
272
|
-
|
|
273
|
-
return Effect.map(
|
|
274
|
-
this.projectEffect(Effect.sync(() => ({ filter }))),
|
|
275
|
-
(_) => NonNegativeInt(_.length)
|
|
276
|
-
)
|
|
277
|
-
}
|
|
278
|
-
|
|
368
|
+
/** @deprecated use q2 */
|
|
279
369
|
queryEffect<
|
|
280
370
|
R,
|
|
281
371
|
E,
|
|
@@ -292,10 +382,12 @@ export class RepositoryBaseC3<
|
|
|
292
382
|
))
|
|
293
383
|
}
|
|
294
384
|
|
|
385
|
+
/** @deprecated use q2 */
|
|
295
386
|
queryOneEffect<R, E>(
|
|
296
387
|
// TODO: think about collectPM, collectE, and collect(Parsed)
|
|
297
388
|
map: Effect<{ filter?: Filter<PM> }, E, R>
|
|
298
389
|
): Effect<T, E | NotFoundError<ItemType>, R>
|
|
390
|
+
/** @deprecated use q2 */
|
|
299
391
|
queryOneEffect<
|
|
300
392
|
R,
|
|
301
393
|
E,
|
|
@@ -304,6 +396,7 @@ export class RepositoryBaseC3<
|
|
|
304
396
|
// TODO: think about collectPM, collectE, and collect(Parsed)
|
|
305
397
|
map: Effect<{ filter?: Filter<PM>; collect: (t: T) => Option<S> }, E, R>
|
|
306
398
|
): Effect<S, E | NotFoundError<ItemType>, R>
|
|
399
|
+
/** @deprecated use q2 */
|
|
307
400
|
queryOneEffect<
|
|
308
401
|
R,
|
|
309
402
|
E,
|
|
@@ -331,6 +424,7 @@ export class RepositoryBaseC3<
|
|
|
331
424
|
))
|
|
332
425
|
}
|
|
333
426
|
|
|
427
|
+
/** @deprecated use q2 */
|
|
334
428
|
queryLegacy<S = T>(
|
|
335
429
|
// TODO: think about collectPM, collectE, and collect(Parsed)
|
|
336
430
|
map: { filter?: Filter<PM>; collect?: (t: T) => Option<S>; limit?: number; skip?: number }
|
|
@@ -338,24 +432,29 @@ export class RepositoryBaseC3<
|
|
|
338
432
|
return this.queryEffect(Effect.sync(() => map))
|
|
339
433
|
}
|
|
340
434
|
|
|
435
|
+
/** @deprecated use q2 */
|
|
341
436
|
query(
|
|
342
437
|
b: (fn: Q.FilterTest<PM>, fields: Q.Filter<PM, never>) => Q.QueryBuilder<PM>
|
|
343
438
|
) {
|
|
344
439
|
return this.queryEffect(Effect.sync(() => ({ filter: anyQb((_, fields) => b(_, fields as any)) })))
|
|
345
440
|
}
|
|
346
441
|
|
|
442
|
+
/** @deprecated use q2 */
|
|
347
443
|
queryOne<S = T>(
|
|
348
444
|
map: { filter?: Filter<PM>; collect: (t: T) => Option<S> }
|
|
349
445
|
): Effect<S, NotFoundError<ItemType>>
|
|
446
|
+
/** @deprecated use q2 */
|
|
350
447
|
queryOne(
|
|
351
448
|
map: { filter?: Filter<PM> }
|
|
352
449
|
): Effect<T, NotFoundError<ItemType>>
|
|
450
|
+
/** @deprecated use q2 */
|
|
353
451
|
queryOne<S = T>(
|
|
354
452
|
map: { filter?: Filter<PM>; collect?: (t: T) => Option<S> }
|
|
355
453
|
) {
|
|
356
454
|
return this.queryOneEffect(Effect.sync(() => map))
|
|
357
455
|
}
|
|
358
456
|
|
|
457
|
+
/** @deprecated */
|
|
359
458
|
queryAndSaveOnePureEffect<
|
|
360
459
|
R,
|
|
361
460
|
E,
|
|
@@ -372,6 +471,7 @@ export class RepositoryBaseC3<
|
|
|
372
471
|
env: PureEnv<Evt, S, S2>
|
|
373
472
|
}>
|
|
374
473
|
>
|
|
474
|
+
/** @deprecated */
|
|
375
475
|
queryAndSaveOnePureEffect<
|
|
376
476
|
R,
|
|
377
477
|
E
|
|
@@ -387,12 +487,13 @@ export class RepositoryBaseC3<
|
|
|
387
487
|
env: PureEnv<Evt, T, T2>
|
|
388
488
|
}>
|
|
389
489
|
>
|
|
490
|
+
/** @deprecated */
|
|
390
491
|
queryAndSaveOnePureEffect(
|
|
391
492
|
map: any
|
|
392
493
|
) {
|
|
393
494
|
return (pure: any) => Effect.flatMap(queryOneEffect(this, map), (_) => saveWithPure_(this, _, pure))
|
|
394
495
|
}
|
|
395
|
-
|
|
496
|
+
/** @deprecated */
|
|
396
497
|
queryAndSaveOnePure<
|
|
397
498
|
S extends T = T
|
|
398
499
|
>(
|
|
@@ -404,6 +505,7 @@ export class RepositoryBaseC3<
|
|
|
404
505
|
env: PureEnv<Evt, S, S2>
|
|
405
506
|
}>
|
|
406
507
|
>
|
|
508
|
+
/** @deprecated */
|
|
407
509
|
queryAndSaveOnePure(
|
|
408
510
|
map: { filter: Filter<PM> }
|
|
409
511
|
): <R2, A, E2, T2>(pure: Effect<A, E2, FixEnv<R2, Evt, T, T2>>) => Effect<
|
|
@@ -413,12 +515,13 @@ export class RepositoryBaseC3<
|
|
|
413
515
|
env: PureEnv<Evt, T, T2>
|
|
414
516
|
}>
|
|
415
517
|
>
|
|
518
|
+
/** @deprecated */
|
|
416
519
|
queryAndSaveOnePure<S = T>(
|
|
417
520
|
map: { filter: Filter<PM>; collect: (t: T) => Option<S> }
|
|
418
521
|
) {
|
|
419
522
|
return this.queryAndSaveOnePureEffect(Effect.sync(() => map))
|
|
420
523
|
}
|
|
421
|
-
|
|
524
|
+
/** @deprecated */
|
|
422
525
|
queryAndSavePureEffect<
|
|
423
526
|
R,
|
|
424
527
|
E,
|
|
@@ -426,10 +529,10 @@ export class RepositoryBaseC3<
|
|
|
426
529
|
>(
|
|
427
530
|
map: Effect<{ filter: Filter<PM>; collect?: (t: T) => Option<S>; limit?: number; skip?: number }, E, R>
|
|
428
531
|
) {
|
|
429
|
-
return <R2, A, E2, S2 extends T>(pure: Effect<A, E2, FixEnv<R2, Evt, S[], S2[]>>) =>
|
|
430
|
-
Effect.flatMap(queryEffect(this, map), (_) => this.
|
|
532
|
+
return <R2, A, E2, S2 extends T>(pure: Effect<A, E2, FixEnv<R2, Evt, readonly S[], readonly S2[]>>) =>
|
|
533
|
+
Effect.flatMap(queryEffect(this, map), (_) => this.saveManyWithPure(_, pure))
|
|
431
534
|
}
|
|
432
|
-
|
|
535
|
+
/** @deprecated */
|
|
433
536
|
queryAndSavePure<
|
|
434
537
|
S extends T = T
|
|
435
538
|
>(
|
|
@@ -438,92 +541,7 @@ export class RepositoryBaseC3<
|
|
|
438
541
|
return this.queryAndSavePureEffect(Effect.sync(() => map))
|
|
439
542
|
}
|
|
440
543
|
|
|
441
|
-
|
|
442
|
-
return <R, A, E, S1 extends T, S2 extends T>(pure: Effect<A, E, FixEnv<R, Evt, S1[], S2[]>>) =>
|
|
443
|
-
(items: Iterable<S1>) => saveManyWithPure_(this, items, pure)
|
|
444
|
-
}
|
|
445
|
-
|
|
446
|
-
byIdAndSaveWithPure(
|
|
447
|
-
id: T["id"]
|
|
448
|
-
): <R, A, E, S2 extends T>(
|
|
449
|
-
pure: Effect<A, E, FixEnv<R, Evt, T, S2>>
|
|
450
|
-
) => Effect<
|
|
451
|
-
A,
|
|
452
|
-
InvalidStateError | OptimisticConcurrencyException | NotFoundError<ItemType> | E,
|
|
453
|
-
Exclude<R, {
|
|
454
|
-
env: PureEnv<Evt, T, S2>
|
|
455
|
-
}>
|
|
456
|
-
>
|
|
457
|
-
byIdAndSaveWithPure<R, A, E, S2 extends T>(
|
|
458
|
-
id: T["id"],
|
|
459
|
-
pure: Effect<A, E, FixEnv<R, Evt, T, S2>>
|
|
460
|
-
): Effect<
|
|
461
|
-
A,
|
|
462
|
-
InvalidStateError | OptimisticConcurrencyException | NotFoundError<ItemType> | E,
|
|
463
|
-
Exclude<R, {
|
|
464
|
-
env: PureEnv<Evt, T, S2>
|
|
465
|
-
}>
|
|
466
|
-
>
|
|
467
|
-
byIdAndSaveWithPure<R, A, E, S2 extends T>(id: T["id"], pure?: Effect<A, E, FixEnv<R, Evt, T, S2>>) {
|
|
468
|
-
if (pure) return get(this, id).pipe(Effect.flatMap((item) => saveWithPure_(this, item, pure)))
|
|
469
|
-
return (pure: Effect<A, E, FixEnv<R, Evt, T, S2>>) =>
|
|
470
|
-
get(this, id).pipe(Effect.flatMap((item) => saveWithPure_(this, item, pure)))
|
|
471
|
-
}
|
|
472
|
-
|
|
473
|
-
/**
|
|
474
|
-
* NOTE: it's not as composable, only useful when the request is simple, and only this part needs request args.
|
|
475
|
-
*/
|
|
476
|
-
get handleByIdAndSaveWithPure() {
|
|
477
|
-
return <Req extends { id: T["id"] }, Context, R, A, E, S2 extends T>(
|
|
478
|
-
pure: (req: Req, ctx: Context) => Effect<A, E, FixEnv<R, Evt, T, S2>>
|
|
479
|
-
) =>
|
|
480
|
-
(req: Req, ctx: Context) => byIdAndSaveWithPure(this, req.id)(pure(req, ctx))
|
|
481
|
-
}
|
|
482
|
-
|
|
483
|
-
saveManyWithPure_<
|
|
484
|
-
R,
|
|
485
|
-
A,
|
|
486
|
-
E,
|
|
487
|
-
S1 extends T,
|
|
488
|
-
S2 extends T
|
|
489
|
-
>(
|
|
490
|
-
items: Iterable<S1>,
|
|
491
|
-
pure: Effect<A, E, FixEnv<R, Evt, S1[], S2[]>>
|
|
492
|
-
) {
|
|
493
|
-
return saveAllWithEffectInt(
|
|
494
|
-
this,
|
|
495
|
-
runTerm(pure, [...items])
|
|
496
|
-
)
|
|
497
|
-
}
|
|
498
|
-
|
|
499
|
-
saveWithPure_<
|
|
500
|
-
R,
|
|
501
|
-
A,
|
|
502
|
-
E,
|
|
503
|
-
S1 extends T,
|
|
504
|
-
S2 extends T
|
|
505
|
-
>(
|
|
506
|
-
item: S1,
|
|
507
|
-
pure: Effect<A, E, FixEnv<R, Evt, S1, S2>>
|
|
508
|
-
) {
|
|
509
|
-
return saveAllWithEffectInt(
|
|
510
|
-
this,
|
|
511
|
-
runTerm(pure, item)
|
|
512
|
-
.pipe(Effect.map(([item, events, a]) => [[item], events, a]))
|
|
513
|
-
)
|
|
514
|
-
}
|
|
515
|
-
|
|
516
|
-
saveAllWithEffectInt<
|
|
517
|
-
P extends T,
|
|
518
|
-
R,
|
|
519
|
-
E,
|
|
520
|
-
A
|
|
521
|
-
>(
|
|
522
|
-
gen: Effect<readonly [Iterable<P>, Iterable<Evt>, A], E, R>
|
|
523
|
-
) {
|
|
524
|
-
return Effect.flatMap(gen, ([items, events, a]) => Effect.map(this.saveAndPublish(items, events), () => a))
|
|
525
|
-
}
|
|
526
|
-
|
|
544
|
+
/** @deprecated use q2 */
|
|
527
545
|
queryAndSavePureEffectBatched<
|
|
528
546
|
R,
|
|
529
547
|
E,
|
|
@@ -533,10 +551,11 @@ export class RepositoryBaseC3<
|
|
|
533
551
|
map: Effect<{ filter: Filter<PM>; collect?: (t: T) => Option<S>; limit?: number; skip?: number }, E, R>,
|
|
534
552
|
batchSize = 100
|
|
535
553
|
) {
|
|
536
|
-
return <R2, A, E2, S2 extends T>(pure: Effect<A, E2, FixEnv<R2, Evt, S[], S2[]>>) =>
|
|
537
|
-
Effect.flatMap(queryEffect(this, map), (_) => this.
|
|
554
|
+
return <R2, A, E2, S2 extends T>(pure: Effect<A, E2, FixEnv<R2, Evt, readonly S[], readonly S2[]>>) =>
|
|
555
|
+
Effect.flatMap(queryEffect(this, map), (_) => this.saveManyWithPureBatched(_, pure, batchSize))
|
|
538
556
|
}
|
|
539
557
|
|
|
558
|
+
/** @deprecated use q2 */
|
|
540
559
|
queryAndSavePureBatched<
|
|
541
560
|
S extends T = T
|
|
542
561
|
>(
|
|
@@ -547,12 +566,8 @@ export class RepositoryBaseC3<
|
|
|
547
566
|
return this.queryAndSavePureEffectBatched(Effect.sync(() => map), batchSize)
|
|
548
567
|
}
|
|
549
568
|
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
(items: Iterable<S1>) => saveManyWithPureBatched_(this, items, pure, batchSize)
|
|
553
|
-
}
|
|
554
|
-
|
|
555
|
-
saveManyWithPureBatched_<
|
|
569
|
+
/** @deprecated use q2 */
|
|
570
|
+
saveManyWithPureBatched<
|
|
556
571
|
R,
|
|
557
572
|
A,
|
|
558
573
|
E,
|
|
@@ -560,7 +575,7 @@ export class RepositoryBaseC3<
|
|
|
560
575
|
S2 extends T
|
|
561
576
|
>(
|
|
562
577
|
items: Iterable<S1>,
|
|
563
|
-
pure: Effect<A, E, FixEnv<R, Evt, S1[], S2[]>>,
|
|
578
|
+
pure: Effect<A, E, FixEnv<R, Evt, readonly S1[], readonly S2[]>>,
|
|
564
579
|
batchSize = 100
|
|
565
580
|
) {
|
|
566
581
|
return Effect.forEach(
|
|
@@ -572,13 +587,6 @@ export class RepositoryBaseC3<
|
|
|
572
587
|
)
|
|
573
588
|
)
|
|
574
589
|
}
|
|
575
|
-
|
|
576
|
-
readonly save = (...items: NonEmptyArray<T>) => this.saveAndPublish(items)
|
|
577
|
-
|
|
578
|
-
readonly saveWithEvents = (
|
|
579
|
-
events: Iterable<Evt>
|
|
580
|
-
) =>
|
|
581
|
-
(...items: NonEmptyArray<T>) => this.saveAndPublish(items, events)
|
|
582
590
|
}
|
|
583
591
|
|
|
584
592
|
type Exact<A, B> = [A] extends [B] ? [B] extends [A] ? true : false : false
|
|
@@ -847,7 +855,8 @@ export function makeRepo<
|
|
|
847
855
|
return {
|
|
848
856
|
make,
|
|
849
857
|
Where: where,
|
|
850
|
-
Query: Q.QueryBuilder.make<PM>()
|
|
858
|
+
Query: Q.QueryBuilder.make<PM>(),
|
|
859
|
+
Q2: Q2.make<Omit<PM, "_etag">>()
|
|
851
860
|
}
|
|
852
861
|
}
|
|
853
862
|
}
|
|
@@ -1003,9 +1012,11 @@ export interface Repos<
|
|
|
1003
1012
|
},
|
|
1004
1013
|
f: (r: Repository<T, PM, Evt, ItemType>) => Out
|
|
1005
1014
|
): Effect<Out, E, StoreMaker | ContextMapContainer | R | RInitial | R2>
|
|
1006
|
-
/** @deprecated use `
|
|
1015
|
+
/** @deprecated use `Q2` instead */
|
|
1007
1016
|
readonly Where: ReturnType<typeof makeWhere<PM>>
|
|
1017
|
+
/** @deprecated use `Q2` instead */
|
|
1008
1018
|
readonly Query: ReturnType<typeof Q.QueryBuilder.make<PM>>
|
|
1019
|
+
readonly Q2: ReturnType<typeof Q2.make<PM>>
|
|
1009
1020
|
readonly type: Repository<T, PM, Evt, ItemType>
|
|
1010
1021
|
}
|
|
1011
1022
|
|
|
@@ -1026,6 +1037,7 @@ export interface RepoFunctions<T extends { id: unknown }, PM extends { id: strin
|
|
|
1026
1037
|
save: (...items: T[]) => Effect<void, InvalidStateError | OptimisticConcurrencyException, Service>
|
|
1027
1038
|
get: (id: T["id"]) => Effect<T, NotFoundError<ItemType>, Service>
|
|
1028
1039
|
|
|
1040
|
+
/** @deprecated use q2 */
|
|
1029
1041
|
query: (b: (fn: Q.FilterTest<PM>, fields: Q.Filter<PM, never>) => Q.QueryBuilder<PM>) => Effect<T[], never, Service>
|
|
1030
1042
|
queryLegacy: <S = T>(map: {
|
|
1031
1043
|
filter?: Filter<PM>
|
|
@@ -1034,8 +1046,64 @@ export interface RepoFunctions<T extends { id: unknown }, PM extends { id: strin
|
|
|
1034
1046
|
skip?: number
|
|
1035
1047
|
}) => Effect<S[], never, Service>
|
|
1036
1048
|
|
|
1049
|
+
/** @deprecated use q2 */
|
|
1037
1050
|
mapped: MM<Service, PM, Omit<PM, "_etag">>
|
|
1038
1051
|
|
|
1052
|
+
byIdAndSaveWithPure: {
|
|
1053
|
+
<R, A, E, S2 extends T>(
|
|
1054
|
+
id: T["id"],
|
|
1055
|
+
pure: Effect<A, E, FixEnv<R, never, T, S2>>
|
|
1056
|
+
): Effect<
|
|
1057
|
+
A,
|
|
1058
|
+
InvalidStateError | OptimisticConcurrencyException | E | NotFoundError<ItemType>,
|
|
1059
|
+
| Service
|
|
1060
|
+
| Exclude<R, {
|
|
1061
|
+
env: PureEnv<never, T, S2>
|
|
1062
|
+
}>
|
|
1063
|
+
>
|
|
1064
|
+
}
|
|
1065
|
+
|
|
1066
|
+
q2AndSaveOnePure: {
|
|
1067
|
+
<
|
|
1068
|
+
R2,
|
|
1069
|
+
A,
|
|
1070
|
+
E2,
|
|
1071
|
+
T2 extends T
|
|
1072
|
+
>(
|
|
1073
|
+
q: (initial: Query<Omit<PM, "_etag">>) =>
|
|
1074
|
+
| Query<Omit<PM, "_etag">>
|
|
1075
|
+
| QueryWhere<Omit<PM, "_etag">>,
|
|
1076
|
+
pure: Effect<A, E2, FixEnv<R2, Evt, T, T2>>
|
|
1077
|
+
): Effect<
|
|
1078
|
+
A,
|
|
1079
|
+
InvalidStateError | OptimisticConcurrencyException | E2 | NotFoundError<ItemType>,
|
|
1080
|
+
| Service
|
|
1081
|
+
| Exclude<R2, {
|
|
1082
|
+
env: PureEnv<Evt, T, T2>
|
|
1083
|
+
}>
|
|
1084
|
+
>
|
|
1085
|
+
}
|
|
1086
|
+
q2AndSavePure: {
|
|
1087
|
+
<
|
|
1088
|
+
R2,
|
|
1089
|
+
A,
|
|
1090
|
+
E2,
|
|
1091
|
+
T2 extends T
|
|
1092
|
+
>(
|
|
1093
|
+
q: (initial: Query<Omit<PM, "_etag">>) =>
|
|
1094
|
+
| Query<Omit<PM, "_etag">>
|
|
1095
|
+
| QueryWhere<Omit<PM, "_etag">>,
|
|
1096
|
+
pure: Effect<A, E2, FixEnv<R2, Evt, readonly T[], readonly T2[]>>
|
|
1097
|
+
): Effect<
|
|
1098
|
+
A,
|
|
1099
|
+
InvalidStateError | OptimisticConcurrencyException | E2,
|
|
1100
|
+
| Service
|
|
1101
|
+
| Exclude<R2, {
|
|
1102
|
+
env: PureEnv<Evt, readonly T[], readonly T2[]>
|
|
1103
|
+
}>
|
|
1104
|
+
>
|
|
1105
|
+
}
|
|
1106
|
+
|
|
1039
1107
|
readonly q2: {
|
|
1040
1108
|
<A, R, From extends FieldValues>(
|
|
1041
1109
|
q: (initial: Query<Omit<PM, "_etag">>) => QueryProjection<Omit<PM, "_etag"> extends From ? From : never, A, R>
|
|
@@ -1053,14 +1121,39 @@ export interface RepoFunctions<T extends { id: unknown }, PM extends { id: strin
|
|
|
1053
1121
|
|
|
1054
1122
|
const makeRepoFunctions = (tag: any) => {
|
|
1055
1123
|
const { all } = Effect.serviceConstants(tag) as any
|
|
1056
|
-
const {
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1124
|
+
const {
|
|
1125
|
+
byIdAndSaveWithPure,
|
|
1126
|
+
find,
|
|
1127
|
+
get,
|
|
1128
|
+
q2,
|
|
1129
|
+
q2AndSaveOnePure,
|
|
1130
|
+
q2AndSavePure,
|
|
1131
|
+
query,
|
|
1132
|
+
queryLegacy,
|
|
1133
|
+
removeAndPublish,
|
|
1134
|
+
removeById,
|
|
1135
|
+
save,
|
|
1136
|
+
saveAndPublish
|
|
1137
|
+
} = Effect.serviceFunctions(tag) as any
|
|
1060
1138
|
|
|
1061
1139
|
const mapped = (s: any) => tag.map((_: any) => _.mapped(s))
|
|
1062
1140
|
|
|
1063
|
-
return {
|
|
1141
|
+
return {
|
|
1142
|
+
all,
|
|
1143
|
+
byIdAndSaveWithPure,
|
|
1144
|
+
find,
|
|
1145
|
+
removeById,
|
|
1146
|
+
saveAndPublish,
|
|
1147
|
+
removeAndPublish,
|
|
1148
|
+
save,
|
|
1149
|
+
get,
|
|
1150
|
+
query,
|
|
1151
|
+
queryLegacy,
|
|
1152
|
+
q2,
|
|
1153
|
+
mapped,
|
|
1154
|
+
q2AndSaveOnePure,
|
|
1155
|
+
q2AndSavePure
|
|
1156
|
+
}
|
|
1064
1157
|
}
|
|
1065
1158
|
|
|
1066
1159
|
export const RepositoryBaseImpl = <Service>() => {
|