// ets_tracing: off import * as A from "@effect-ts/core/Collections/Immutable/Chunk" import * as HM from "@effect-ts/core/Collections/Immutable/HashMap" import { _R } from "@effect-ts/core/Effect" import * as O from "@effect-ts/core/Option" import type { DataSource } from "../../DataSource/index.js" import type { BlockedRequest } from "../BlockedRequest/index.js" /** * A `Sequential[R]` maintains a mapping from data sources to batches of * requests from those data sources that must be executed sequentially. */ export class Sequential { readonly [_R]!: (r: R) => void constructor( public readonly map: HM.HashMap< DataSource, A.Chunk>> > ) {} } /** * Combines this collection of batches of requests that must be executed * sequentially with that collection of batches of requests that must be * executed sequentially to return a new collection of batches of requests * that must be executed sequentially. */ export function add(that: Sequential) { return (self: Sequential): Sequential => add_(self, that) } /** * Combines this collection of batches of requests that must be executed * sequentially with that collection of batches of requests that must be * executed sequentially to return a new collection of batches of requests * that must be executed sequentially. */ export function add_( self: Sequential, that: Sequential ): Sequential { return new Sequential( HM.reduceWithIndex_(that.map, self.map, (map, k, v) => HM.set_( map, k, O.fold_( HM.get_(map, k), () => A.empty(), (_) => A.concat_(_, v) ) ) ) ) } /** * Returns whether this collection of batches of requests is empty. */ export function isEmpty(self: Sequential) { return HM.isEmpty(self.map) } /** * Returns a collection of the data sources that the batches of requests in * this collection are from. */ export function keys(self: Sequential): Iterable> { return HM.keys(self.map) } /** * Converts this collection of batches requests that must be executed * sequentially to an `Iterable` containing mappings from data sources to * batches of requests from those data sources. */ export function toIterable( self: Sequential ): Iterable, A.Chunk>>]> { return self.map as any }