@effect-app/infra 0.203.1 → 0.204.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.
@@ -397,8 +397,9 @@ export function makeRepo<
397
397
  return Effect
398
398
  .gen(function*($) {
399
399
  const rctx = yield* $(Effect.context<R>())
400
- const encode = flow(S.encode(schema), Effect.provide(rctx))
400
+ const encodeMany = flow(S.encode(S.array(schema)), Effect.provide(rctx), Effect.withSpan("encodeMany"))
401
401
  const decode = flow(S.decode(schema), Effect.provide(rctx))
402
+ const decodeMany = flow(S.decode(S.array(schema)), Effect.provide(rctx), Effect.withSpan("decodeMany"))
402
403
 
403
404
  const store = yield* $(mkStore(args.makeInitial, args.config))
404
405
  const { get } = yield* $(ContextMapContainer)
@@ -420,10 +421,12 @@ export function makeRepo<
420
421
  })
421
422
  ))
422
423
 
423
- const all = Effect.flatMap(
424
- allE,
425
- (_) => Effect.forEach(_, (_) => decode(_), { concurrency: "inherit", batching: true }).pipe(Effect.orDie)
426
- )
424
+ const all = Effect
425
+ .flatMap(
426
+ allE,
427
+ (_) => decodeMany(_).pipe(Effect.orDie)
428
+ )
429
+ .pipe(Effect.map((_) => _ as T[]))
427
430
 
428
431
  const structSchema = schema as unknown as { struct: typeof schema }
429
432
  const i = ("struct" in structSchema ? structSchema["struct"] : schema).pipe((_) =>
@@ -488,12 +491,7 @@ export function makeRepo<
488
491
  .pipe(Effect.asUnit)
489
492
 
490
493
  const saveAll = (a: Iterable<T>) =>
491
- Effect
492
- .forEach(
493
- Array.from(a),
494
- (_) => encode(_),
495
- { concurrency: "inherit", batching: true }
496
- )
494
+ encodeMany(Array.from(a))
497
495
  .pipe(
498
496
  Effect.orDie,
499
497
  Effect.andThen(saveAllE)
@@ -515,9 +513,7 @@ export function makeRepo<
515
513
  return Effect.gen(function*($) {
516
514
  const { get, set } = yield* $(cms)
517
515
  const it = [...a]
518
- const items = yield* $(
519
- Effect.forEach(it, (_) => encode(_), { concurrency: "inherit", batching: true }).pipe(Effect.orDie)
520
- )
516
+ const items = yield* $(encodeMany(it).pipe(Effect.orDie))
521
517
  // TODO: we should have a batchRemove on store so the adapter can actually batch...
522
518
  for (const e of items) {
523
519
  yield* $(store.remove(mapToPersistenceModel(e, get)))
@@ -562,7 +558,6 @@ export function makeRepo<
562
558
  ? r.utils.parseMany2(_, a.schema as any)
563
559
  : r.utils.parseMany(_)
564
560
  )
565
- .pipe(Effect.withSpan("parseMany"))
566
561
  )
567
562
  return pipe(
568
563
  a.ttype === "one"
@@ -594,18 +589,16 @@ export function makeRepo<
594
589
  */
595
590
  utils: {
596
591
  parseMany: (items) =>
597
- Effect.flatMap(cms, (cm) =>
598
- Effect
599
- .forEach(items, (_) => decode(mapReverse(_, cm.set)), { concurrency: "inherit", batching: true })
600
- .pipe(Effect.orDie)),
592
+ Effect
593
+ .flatMap(cms, (cm) =>
594
+ decodeMany(items.map((_) => mapReverse(_, cm.set)))
595
+ .pipe(Effect.orDie, Effect.withSpan("parseMany"))),
601
596
  parseMany2: (items, schema) =>
602
- Effect.flatMap(cms, (cm) =>
603
- Effect
604
- .forEach(items, (_) => S.decode(schema)(mapReverse(_, cm.set) as any), {
605
- concurrency: "inherit",
606
- batching: true
607
- })
608
- .pipe(Effect.orDie)),
597
+ Effect
598
+ .flatMap(cms, (cm) =>
599
+ S
600
+ .decode(S.array(schema))(items.map((_) => mapReverse(_, cm.set) as unknown as Omit<PM, "_etag">))
601
+ .pipe(Effect.orDie, Effect.withSpan("parseMany2"))),
609
602
  filter: <U extends keyof PM = keyof PM>(args: FilterArgs<PM, U>) =>
610
603
  store
611
604
  .filter(args)
@@ -620,7 +613,6 @@ export function makeRepo<
620
613
  )
621
614
  },
622
615
  mapped: <A, R>(schema: S.Schema<A, any, R>) => {
623
- // const enc = S.encode(schema)
624
616
  const dec = S.decode(schema)
625
617
  const encMany = S.encode(S.array(schema))
626
618
  const decMany = S.decode(S.array(schema))