@@ -263,6 +263,10 @@ export const extendRepo = <
263263 request : ( id : T [ IdKey ] ) => Effect . request ( _request ( { id } ) , requestResolver ) ,
264264 get,
265265 log : ( evt : Evt ) => AnyPureDSL . log ( evt ) ,
266+ /**
267+ * Enables chunked writes for large batches via `options.batch`.
268+ * Note: batching breaks transactional properties because chunks are saved independently.
269+ */
266270 save : ( ( itemOrItems : T | NonEmptyReadonlyArray < T > , options ?: BatchOptions ) => {
267271 const items = asReadonlyArray ( itemOrItems )
268272 const batchSize = getBatchSize ( options ?. batch )
@@ -274,23 +278,19 @@ export const extendRepo = <
274278 ( batch ) => repo . saveAndPublish ( batch ) ,
275279 { discard : true }
276280 )
277- } ) as {
278- ( item : T , options ?: BatchOptions ) : Effect . Effect <
279- void ,
280- InvalidStateError | OptimisticConcurrencyException ,
281- RSchema | RPublish
282- >
283- ( items : NonEmptyReadonlyArray < T > , options ?: BatchOptions ) : Effect . Effect <
284- void ,
285- InvalidStateError | OptimisticConcurrencyException ,
286- RSchema | RPublish
287- >
288- /**
289- * Enables chunked writes for large batches.
290- * Note: batching breaks transactional properties because chunks are saved independently.
291- */
292- } ,
281+ } ) as (
282+ itemOrItems : T | NonEmptyReadonlyArray < T > ,
283+ options ?: BatchOptions
284+ ) => Effect . Effect <
285+ void ,
286+ InvalidStateError | OptimisticConcurrencyException ,
287+ RSchema | RPublish
288+ > ,
293289 saveWithEvents : ( events : Iterable < Evt > ) => ( ...items : NonEmptyArray < T > ) => repo . saveAndPublish ( items , events ) ,
290+ /**
291+ * Enables chunked deletes for large batches via `options.batch`.
292+ * Note: batching breaks transactional properties because chunks are removed independently.
293+ */
294294 remove : ( ( itemOrItems : T | NonEmptyReadonlyArray < T > , options ?: BatchOptions ) => {
295295 const items = asReadonlyArray ( itemOrItems )
296296 const batchSize = getBatchSize ( options ?. batch )
@@ -302,14 +302,29 @@ export const extendRepo = <
302302 ( batch ) => repo . removeAndPublish ( batch ) ,
303303 { discard : true }
304304 )
305- } ) as {
306- ( item : T , options ?: BatchOptions ) : Effect . Effect < void , never , RSchema | RPublish >
307- ( items : NonEmptyReadonlyArray < T > , options ?: BatchOptions ) : Effect . Effect < void , never , RSchema | RPublish >
308- /**
309- * Enables chunked deletes for large batches.
310- * Note: batching breaks transactional properties because chunks are removed independently.
311- */
312- } ,
305+ } ) as (
306+ itemOrItems : T | NonEmptyReadonlyArray < T > ,
307+ options ?: BatchOptions
308+ ) => Effect . Effect < void , never , RSchema | RPublish > ,
309+ /**
310+ * Enables chunked deletes for large batches via `options.batch`.
311+ * Note: batching breaks transactional properties because chunks are removed independently.
312+ */
313+ removeById : ( ( idOrIds : T [ IdKey ] | NonEmptyReadonlyArray < T [ IdKey ] > , options ?: BatchOptions ) => {
314+ const ids = asReadonlyArray ( idOrIds ) as NonEmptyReadonlyArray < T [ IdKey ] >
315+ const batchSize = getBatchSize ( options ?. batch )
316+ if ( batchSize === undefined ) {
317+ return repo . removeById ( ids )
318+ }
319+ return Effect . forEach (
320+ Array . chunksOf ( ids , batchSize ) ,
321+ ( batch ) => repo . removeById ( batch ) ,
322+ { discard : true }
323+ )
324+ } ) as (
325+ idOrIds : T [ IdKey ] | NonEmptyReadonlyArray < T [ IdKey ] > ,
326+ options ?: BatchOptions
327+ ) => Effect . Effect < void , never , RSchema > ,
313328 queryAndSavePure,
314329 saveManyWithPure,
315330 byIdAndSaveWithPure,
0 commit comments