From f2a035c71913f4eb0daccc50598490fca2f4cb89 Mon Sep 17 00:00:00 2001 From: BoYanZh Date: Thu, 15 Oct 2026 06:56:47 -0700 Subject: [PATCH 1/5] feat: v2 compaction hook, dynamic restart fallback, dual-config installer --- README.md | 15 +++++++++- eslint.config.js | 9 ++++++ package.json | 1 + scripts/install.mjs | 71 +++++++++++++++++++++++++++++++++++++++++++++ src/server.ts | 56 +++++++++++++++++++++++++++++++++++ src/state.ts | 29 ++++++++++++++++++ test/state.test.ts | 13 +++++++++ 7 files changed, 193 insertions(+), 1 deletion(-) create mode 100644 scripts/install.mjs diff --git a/README.md b/README.md index 4a4286f..6987bb7 100644 --- a/README.md +++ b/README.md @@ -92,7 +92,14 @@ For manual installation, add the package to both V2 plugin lists. OpenCode 2 does not read the V1 `tui.json` file. The server entrypoint is loaded from `opencode.json`; the sidebar and palette integration are loaded from the global `~/.config/opencode/cli.json`. -V2 supports the `/loop` command, all loop tools, persistent state, idle scheduling, dynamic loops, Plan-mode safety, session cleanup, and TUI sidebar/palette integration. The plugin does not yet integrate the V2 compaction hook. V2 still injects the active-loop system reminder before model dispatch, but cannot append the separate loop block directly to a compaction operation. +Use the bundled installer to update both V2 entries at once: + +```sh +bun scripts/install.mjs --global +bun scripts/install.mjs --project /path/to/project +``` + +V2 supports the `/loop` command, all loop tools, persistent state, idle scheduling, dynamic loops, Plan-mode safety, session cleanup, TUI sidebar/palette integration, and the `compaction` hook for preserving loops across compaction. Stale dynamic loops resume with a configurable fallback delay after restart (`dynamic_restart_mode: "fallback"`, default 20m) instead of stopping. ## Usage @@ -172,6 +179,8 @@ In OpenCode 1, server options use the package-and-options tuple in `opencode.jso "max_consecutive_failures": 5, "max_loop_age_days": 7, "dynamic_max_delay_seconds": 86400, + "dynamic_restart_mode": "fallback", + "dynamic_restart_fallback_seconds": 1200, "restricted_agents": ["plan"], "register_command": true, "command_name": "loop" @@ -197,6 +206,8 @@ In OpenCode 2, use the plugin object form: "max_consecutive_failures": 5, "max_loop_age_days": 7, "dynamic_max_delay_seconds": 86400, + "dynamic_restart_mode": "fallback", + "dynamic_restart_fallback_seconds": 1200, "restricted_agents": ["plan"], "register_command": true, "command_name": "loop" @@ -216,6 +227,8 @@ Defaults: - `max_consecutive_failures`: `5`; number of consecutive provider/model failures after which the loop is paused with an inspectable `blockedReason`. - `max_loop_age_days`: `7`; loops stop automatically after this age. Set `0` to disable expiry. - `dynamic_max_delay_seconds`: `86400`; upper clamp for `schedule_next_run` delays. +- `dynamic_restart_mode`: `"fallback"`; stale dynamic loops resume with a fallback delay after restart instead of stopping. Set `"stop"` for the legacy stop behavior. +- `dynamic_restart_fallback_seconds`: `1200`; fallback delay for stale dynamic loops, clamped to `[min_interval_seconds, dynamic_max_delay_seconds]`. - `restricted_agents`: `["plan"]`; iterations are deferred while the session's last prompt came from one of these agents. - `register_command`: `true` - `command_name`: `"loop"` diff --git a/eslint.config.js b/eslint.config.js index 0a612ea..f809cac 100644 --- a/eslint.config.js +++ b/eslint.config.js @@ -7,6 +7,15 @@ export default tseslint.config( }, js.configs.recommended, ...tseslint.configs.recommended, + { + files: ["scripts/**/*.mjs"], + languageOptions: { + globals: { + process: "readonly", + console: "readonly", + }, + }, + }, { files: ["**/*.{ts,tsx}"], languageOptions: { diff --git a/package.json b/package.json index c799e46..9b3185e 100644 --- a/package.json +++ b/package.json @@ -46,6 +46,7 @@ "clean": "rm -rf dist", "build": "bun run clean && bun build ./src/server.ts --outdir ./dist --target bun --external @opencode-ai/plugin --external zod", "ci:version": "bun scripts/resolve-ci-version.ts", + "install:global": "bun scripts/install.mjs --global", "lint": "eslint .", "pack:dry-run": "npm pack --dry-run", "test": "bun test", diff --git a/scripts/install.mjs b/scripts/install.mjs new file mode 100644 index 0000000..7560b6e --- /dev/null +++ b/scripts/install.mjs @@ -0,0 +1,71 @@ +import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs" +import { homedir } from "node:os" +import { dirname, join, resolve } from "node:path" + +const PACKAGE_NAME = "@prevalentware/opencode-loop-plugin" + +function configDir() { + if (process.env.XDG_CONFIG_HOME) return resolve(process.env.XDG_CONFIG_HOME, "opencode") + if (process.platform === "win32" && process.env.APPDATA) return join(process.env.APPDATA, "..", "Local", "opencode") + const base = process.platform === "win32" ? join(homedir(), "AppData", "Local") : join(homedir(), ".config") + return join(base, "opencode") +} + +function readJson(path) { + if (!existsSync(path)) return {} + try { + return JSON.parse(readFileSync(path, "utf8")) + } catch { + throw new Error(`invalid JSON: ${path}`) + } +} + +function ensurePluginList(value) { + if (value == null) return [] + if (Array.isArray(value)) return value + throw new Error(`"plugins" must be an array`) +} + +function pluginKey(entry) { + if (typeof entry === "string") return entry + if (entry && typeof entry === "object" && typeof entry.package === "string") return entry.package + return null +} + +function addPlugin(list, pkg) { + if (list.some((entry) => pluginKey(entry) === pkg)) return { list, added: false } + return { list: [...list, pkg], added: true } +} + +function writeJson(path, value) { + mkdirSync(dirname(path), { recursive: true }) + writeFileSync(path, `${JSON.stringify(value, null, 2)}\n`) +} + +function main() { + const args = process.argv.slice(2) + const projectDir = args.includes("--project") ? resolve(args[args.indexOf("--project") + 1] ?? ".") : null + const pkg = args.includes("--package") ? args[args.indexOf("--package") + 1] : PACKAGE_NAME + if (!pkg) throw new Error("missing package name") + + const targets = [] + if (projectDir) { + targets.push({ kind: "server(project)", path: join(projectDir, "opencode.json") }) + } else { + targets.push({ kind: "server(global)", path: join(configDir(), "opencode.json") }) + } + targets.push({ kind: "tui", path: join(configDir(), "cli.json") }) + + for (const target of targets) { + const current = readJson(target.path) + const { list, added } = addPlugin(ensurePluginList(current.plugins), pkg) + if (added) { + writeJson(target.path, { ...current, plugins: list }) + console.log(`added ${pkg} to ${target.kind}: ${target.path}`) + } else { + console.log(`already present in ${target.kind}: ${target.path}`) + } + } +} + +main() diff --git a/src/server.ts b/src/server.ts index 96c731e..d90f968 100644 --- a/src/server.ts +++ b/src/server.ts @@ -22,6 +22,7 @@ import { ownsSessionLease, parseInterval, pauseLoop, + rescheduleDynamicIfUnchanged, resumeLoop, scheduleNextRun, stopLoop, @@ -50,6 +51,8 @@ type Options = { max_loop_age_days?: number dynamic_max_delay_seconds?: number restricted_agents?: string[] + dynamic_restart_mode?: string + dynamic_restart_fallback_seconds?: number } type PendingDynamicTurn = { sessionID: string; sawBusy: boolean } @@ -64,6 +67,7 @@ const DEFAULT_MAX_FAILURE_BACKOFF_SECONDS = 60 * 60 const DEFAULT_MAX_CONSECUTIVE_FAILURES = 5 const DEFAULT_MAX_LOOP_AGE_DAYS = 7 const DEFAULT_DYNAMIC_MAX_DELAY_SECONDS = 24 * 60 * 60 +const DEFAULT_DYNAMIC_RESTART_FALLBACK_SECONDS = 20 * 60 const RUN_CLAIM_LEASE_MS = 30_000 const SESSION_LEASE_MS = 90_000 const SESSION_LEASE_HEARTBEAT_MS = 30_000 @@ -89,6 +93,20 @@ function restrictedAgentSet(options?: Options) { return new Set(names.map((name) => (typeof name === "string" ? name.trim().toLowerCase() : "")).filter(Boolean)) } +function dynamicRestartMode(options?: Options) { + return options?.dynamic_restart_mode?.trim().toLowerCase() === "stop" ? "stop" : "fallback" +} + +function dynamicRestartFallbackMs(options?: Options, minIntervalSeconds?: number, dynamicMaxDelaySeconds?: number) { + const fallbackSeconds = positiveNumberOr( + options?.dynamic_restart_fallback_seconds, + DEFAULT_DYNAMIC_RESTART_FALLBACK_SECONDS, + ) + const minMs = (minIntervalSeconds ?? DEFAULT_MIN_INTERVAL_SECONDS) * 1000 + const maxMs = (dynamicMaxDelaySeconds ?? DEFAULT_DYNAMIC_MAX_DELAY_SECONDS) * 1000 + return Math.min(Math.max(Math.round(fallbackSeconds * 1000), minMs), Math.max(maxMs, minMs)) +} + function registerDesktopCommand(config: Config, commandName: string, minIntervalSeconds: number) { config.command ??= {} if (config.command[commandName]) return @@ -154,6 +172,8 @@ const server: Plugin = async ({ client, directory }, options?: Options) => { const maxLoopAgeMs = nonNegativeNumberOr(options?.max_loop_age_days, DEFAULT_MAX_LOOP_AGE_DAYS) * 24 * 60 * 60 * 1000 const dynamicMaxDelaySeconds = positiveNumberOr(options?.dynamic_max_delay_seconds, DEFAULT_DYNAMIC_MAX_DELAY_SECONDS) const restrictedAgents = restrictedAgentSet(options) + const restartMode = dynamicRestartMode(options) + const restartFallbackMs = dynamicRestartFallbackMs(options, minIntervalSeconds, dynamicMaxDelaySeconds) let disposed = false const timers = new Map>() @@ -435,6 +455,16 @@ const server: Plugin = async ({ client, directory }, options?: Options) => { for (const [loopID, candidate] of staleDynamicCandidates) { if (candidate.sessionID !== sessionID) continue staleDynamicCandidates.delete(loopID) + if (restartMode === "fallback") { + const rescheduled = await rescheduleDynamicIfUnchanged( + loopID, candidate.updatedAt, restartFallbackMs, "restarted with fallback delay; reschedule or stop after this iteration", lease, + ).catch(() => null) + if (rescheduled) { + scheduleTimer(rescheduled) + await log("info", "Dynamic loop resumed with fallback delay after restart", { loopID }) + continue + } + } await stopLoopIfUnchanged( loopID, candidate.updatedAt, "not rescheduled before OpenCode restarted", lease, ) @@ -729,6 +759,8 @@ async function setupV2(context: PluginV2.Plugin.Context): Promise>() @@ -1041,6 +1073,19 @@ async function setupV2(context: PluginV2.Plugin.Context): Promise null) + if (rescheduled) { + scheduleTimer(rescheduled) + v2Log("info", "Dynamic loop resumed with fallback delay after restart", { + loopID, + sessionID, + }) + continue + } + } await stopLoopIfUnchanged( loopID, candidate.updatedAt, "not rescheduled before OpenCode restarted", lease, ) @@ -1180,6 +1225,17 @@ async function setupV2(context: PluginV2.Plugin.Context): Promise { + await observeSession(sessionCompaction.sessionID) + const loops = await openLoops(sessionCompaction.sessionID) + const contextText = compactionContext(loops) + if (!contextText) return + if (sessionCompaction.system.some((part) => part.type === "text" && part.text.includes(LOOP_SYSTEM_MARKER))) return + sessionCompaction.system.push({ type: "text", text: contextText }) + }), + ) + await rehydrate().catch(() => v2Log("error", "Failed to rehydrate loops", { category: "state" })) const leaseHeartbeat = setInterval(() => { for (const sessionID of new Set([...observedSessions, ...keepAliveSessions])) { diff --git a/src/state.ts b/src/state.ts index fab3ad0..2e94fcc 100644 --- a/src/state.ts +++ b/src/state.ts @@ -665,6 +665,35 @@ export async function stopLoopIfUnchanged( }) } +export async function rescheduleDynamicIfUnchanged( + loopID: string, + expectedUpdatedAt: number, + delayMs: number, + reason: string, + sessionLease?: SessionLease, +) { + const delay = positiveIntegerOrNull(Math.round(delayMs)) + if (delay == null) throw new Error("delay must be a positive number of milliseconds") + return mutate((state) => { + const loop = state.loops[loopID] + if (!loop || (sessionLease && !matchesSessionLease(state, sessionLease))) return null + if ( + loop.updatedAt !== expectedUpdatedAt || + loop.status !== "active" || + loop.mode !== "dynamic" || + loop.nextRunAt != null + ) { + return null + } + loop.scheduleRevision += 1 + loop.nextRunAt = now() + delay + loop.nextRetryAt = null + loop.lastReason = reason.trim().slice(0, 400) || loop.lastReason + loop.updatedAt = now() + return snapshot(loop) + }) +} + export async function stopLoopsForSession(sessionID: string, reason: string) { return mutate((state) => { const stopped: LoopSnapshot[] = [] diff --git a/test/state.test.ts b/test/state.test.ts index 6b5a3f3..1ccd509 100644 --- a/test/state.test.ts +++ b/test/state.test.ts @@ -22,6 +22,7 @@ import { recordRunSentClaimed, recordRunFailedClaimed, recordRunDeferredClaimed, + rescheduleDynamicIfUnchanged, stopLoopClaimed, recordRunFailed, recordRunSent, @@ -172,6 +173,18 @@ test("conditional dynamic cleanup ignores missing and changed loops", async () = expect((await getLoop(scheduled.id))?.status).toBe("active") }) +test("stale dynamic loops resume with fallback delay instead of stopping", async () => { + const created = await createLoop("ses_1", { prompt: "watch CI", mode: "dynamic" }) + const resumed = await rescheduleDynamicIfUnchanged(created.id, created.updatedAt, 120_000, "restart fallback") + expect(resumed?.nextRunAt).toBeGreaterThan(Date.now()) + expect(resumed?.status).toBe("active") + expect(resumed?.lastReason).toBe("restart fallback") + + const changed = (await getLoop(created.id))! + expect(await rescheduleDynamicIfUnchanged(created.id, created.updatedAt, 120_000, "stale")).toBeNull() + expect(changed.nextRunAt).not.toBeNull() +}) + test("serializes state mutations across processes", async () => { const script = ` import { createLoop } from "./src/state.ts" From 49760b26d15ef70778c34199c2c4016e7d9cc64c Mon Sep 17 00:00:00 2001 From: BoYanZh Date: Thu, 15 Oct 2026 07:11:46 -0700 Subject: [PATCH 2/5] build: refresh dist with v2 compaction hook and restart fallback --- dist/server.js | 34689 ++++++++++++++++++++++++----------------------- 1 file changed, 17383 insertions(+), 17306 deletions(-) diff --git a/dist/server.js b/dist/server.js index bfcfe5f..a0fbb0e 100644 --- a/dist/server.js +++ b/dist/server.js @@ -1,12 +1,16 @@ // @bun var __defProp = Object.defineProperty; +var __returnValue = (v) => v; +function __exportSetter(name, newValue) { + this[name] = __returnValue.bind(null, newValue); +} var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true, configurable: true, - set: (newValue) => all[name] = () => newValue + set: __exportSetter.bind(all, name) }); }; @@ -19,6 +23,23 @@ import { randomUUID } from "crypto"; import { chmod, mkdir, link, readFile, rename as rename3, rm, writeFile } from "fs/promises"; import { homedir } from "os"; import { dirname, join as join3 } from "path"; +// node_modules/effect/dist/esm/Data.js +var exports_Data = {}; +__export(exports_Data, { + unsafeStruct: () => unsafeStruct, + unsafeArray: () => unsafeArray, + tuple: () => tuple, + taggedEnum: () => taggedEnum, + tagged: () => tagged, + struct: () => struct2, + case: () => _case, + array: () => array3, + TaggedError: () => TaggedError, + TaggedClass: () => TaggedClass, + Structural: () => Structural2, + Error: () => Error2, + Class: () => Class +}); // node_modules/effect/dist/esm/Function.js var isFunction = (input) => typeof input === "function"; @@ -1278,17891 +1299,13541 @@ var dedupeWith = /* @__PURE__ */ dual(2, (self, isEquivalent) => { var dedupe = (self) => dedupeWith(self, equivalence()); var join = /* @__PURE__ */ dual(2, (self, sep) => fromIterable(self).join(sep)); -// node_modules/fast-check/lib/esm/stream/StreamHelpers.js -class Nil { - [Symbol.iterator]() { - return this; - } - next(value) { - return { value, done: true }; - } -} -Nil.nil = new Nil; -function nilHelper() { - return Nil.nil; -} -function* mapHelper(g, f) { - for (const v of g) { - yield f(v); - } -} -function* flatMapHelper(g, f) { - for (const v of g) { - yield* f(v); +// node_modules/effect/dist/esm/Chunk.js +var TypeId3 = /* @__PURE__ */ Symbol.for("effect/Chunk"); +function copy2(src, srcPos, dest, destPos, len) { + for (let i = srcPos;i < Math.min(src.length, srcPos + len); i++) { + dest[destPos + i - srcPos] = src[i]; } + return dest; } -function* filterHelper(g, f) { - for (const v of g) { - if (f(v)) { - yield v; +var emptyArray = []; +var getEquivalence4 = (isEquivalent) => make((self, that) => self.length === that.length && toReadonlyArray(self).every((value, i) => isEquivalent(value, unsafeGet2(that, i)))); +var _equivalence3 = /* @__PURE__ */ getEquivalence4(equals); +var ChunkProto = { + [TypeId3]: { + _A: (_) => _ + }, + toString() { + return format(this.toJSON()); + }, + toJSON() { + return { + _id: "Chunk", + values: toReadonlyArray(this).map(toJSON) + }; + }, + [NodeInspectSymbol]() { + return this.toJSON(); + }, + [symbol2](that) { + return isChunk(that) && _equivalence3(this, that); + }, + [symbol]() { + return cached(this, array2(toReadonlyArray(this))); + }, + [Symbol.iterator]() { + switch (this.backing._tag) { + case "IArray": { + return this.backing.array[Symbol.iterator](); + } + case "IEmpty": { + return emptyArray[Symbol.iterator](); + } + default: { + return toReadonlyArray(this)[Symbol.iterator](); + } } + }, + pipe() { + return pipeArguments(this, arguments); } -} -function* takeNHelper(g, n) { - for (let i = 0;i < n; ++i) { - const cur = g.next(); - if (cur.done) { +}; +var makeChunk = (backing) => { + const chunk = Object.create(ChunkProto); + chunk.backing = backing; + switch (backing._tag) { + case "IEmpty": { + chunk.length = 0; + chunk.depth = 0; + chunk.left = chunk; + chunk.right = chunk; break; } - yield cur.value; - } -} -function* takeWhileHelper(g, f) { - let cur = g.next(); - while (!cur.done && f(cur.value)) { - yield cur.value; - cur = g.next(); - } -} -function* joinHelper(g, others) { - for (let cur = g.next();!cur.done; cur = g.next()) { - yield cur.value; - } - for (const s of others) { - for (let cur = s.next();!cur.done; cur = s.next()) { - yield cur.value; + case "IConcat": { + chunk.length = backing.left.length + backing.right.length; + chunk.depth = 1 + Math.max(backing.left.depth, backing.right.depth); + chunk.left = backing.left; + chunk.right = backing.right; + break; } - } -} - -// node_modules/fast-check/lib/esm/stream/Stream.js -var safeSymbolIterator = Symbol.iterator; - -class Stream { - static nil() { - return new Stream(nilHelper()); - } - static of(...elements) { - return new Stream(elements[safeSymbolIterator]()); - } - constructor(g) { - this.g = g; - } - next() { - return this.g.next(); - } - [Symbol.iterator]() { - return this.g; - } - map(f) { - return new Stream(mapHelper(this.g, f)); - } - flatMap(f) { - return new Stream(flatMapHelper(this.g, f)); - } - dropWhile(f) { - let foundEligible = false; - function* helper(v) { - if (foundEligible || !f(v)) { - foundEligible = true; - yield v; - } + case "IArray": { + chunk.length = backing.array.length; + chunk.depth = 0; + chunk.left = _empty; + chunk.right = _empty; + break; } - return this.flatMap(helper); - } - drop(n) { - if (n <= 0) { - return this; + case "ISingleton": { + chunk.length = 1; + chunk.depth = 0; + chunk.left = _empty; + chunk.right = _empty; + break; } - let idx = 0; - function helper() { - return idx++ < n; + case "ISlice": { + chunk.length = backing.length; + chunk.depth = backing.chunk.depth + 1; + chunk.left = _empty; + chunk.right = _empty; + break; } - return this.dropWhile(helper); - } - takeWhile(f) { - return new Stream(takeWhileHelper(this.g, f)); } - take(n) { - return new Stream(takeNHelper(this.g, n)); - } - filter(f) { - return new Stream(filterHelper(this.g, f)); - } - every(f) { - for (const v of this.g) { - if (!f(v)) { - return false; - } + return chunk; +}; +var isChunk = (u) => hasProperty(u, TypeId3); +var _empty = /* @__PURE__ */ makeChunk({ + _tag: "IEmpty" +}); +var empty2 = () => _empty; +var make4 = (...as) => unsafeFromNonEmptyArray(as); +var of2 = (a) => makeChunk({ + _tag: "ISingleton", + a +}); +var fromIterable2 = (self) => isChunk(self) ? self : unsafeFromArray(fromIterable(self)); +var copyToArray = (self, array3, initial) => { + switch (self.backing._tag) { + case "IArray": { + copy2(self.backing.array, 0, array3, initial, self.length); + break; } - return true; - } - has(f) { - for (const v of this.g) { - if (f(v)) { - return [true, v]; + case "IConcat": { + copyToArray(self.left, array3, initial); + copyToArray(self.right, array3, initial + self.left.length); + break; + } + case "ISingleton": { + array3[initial] = self.backing.a; + break; + } + case "ISlice": { + let i = 0; + let j = initial; + while (i < self.length) { + array3[j] = unsafeGet2(self, i); + i += 1; + j += 1; } + break; } - return [false, null]; } - join(...others) { - return new Stream(joinHelper(this.g, others)); - } - getNthOrLast(nth) { - let remaining = nth; - let last2 = null; - for (const v of this.g) { - if (remaining-- === 0) - return v; - last2 = v; +}; +var toReadonlyArray_ = (self) => { + switch (self.backing._tag) { + case "IEmpty": { + return emptyArray; + } + case "IArray": { + return self.backing.array; + } + default: { + const arr = new Array(self.length); + copyToArray(self, arr, 0); + self.backing = { + _tag: "IArray", + array: arr + }; + self.left = _empty; + self.right = _empty; + self.depth = 0; + return arr; } - return last2; } -} -function stream(g) { - return new Stream(g); -} - -// node_modules/fast-check/lib/esm/check/symbols.js -var cloneMethod = Symbol.for("fast-check/cloneMethod"); -function hasCloneMethod(instance) { - return instance !== null && (typeof instance === "object" || typeof instance === "function") && cloneMethod in instance && typeof instance[cloneMethod] === "function"; -} -function cloneIfNeeded(instance) { - return hasCloneMethod(instance) ? instance[cloneMethod]() : instance; -} - -// node_modules/fast-check/lib/esm/check/arbitrary/definition/Value.js -var safeObjectDefineProperty = Object.defineProperty; - -class Value { - constructor(value_, context, customGetValue = undefined) { - this.value_ = value_; - this.context = context; - this.hasToBeCloned = customGetValue !== undefined || hasCloneMethod(value_); - this.readOnce = false; - if (this.hasToBeCloned) { - safeObjectDefineProperty(this, "value", { get: customGetValue !== undefined ? customGetValue : this.getValue }); - } else { - this.value = value_; +}; +var toReadonlyArray = toReadonlyArray_; +var reverseChunk = (self) => { + switch (self.backing._tag) { + case "IEmpty": + case "ISingleton": + return self; + case "IArray": { + return makeChunk({ + _tag: "IArray", + array: reverse(self.backing.array) + }); } - } - getValue() { - if (this.hasToBeCloned) { - if (!this.readOnce) { - this.readOnce = true; - return this.value_; - } - return this.value_[cloneMethod](); + case "IConcat": { + return makeChunk({ + _tag: "IConcat", + left: reverse2(self.backing.right), + right: reverse2(self.backing.left) + }); } - return this.value_; - } -} - -// node_modules/fast-check/lib/esm/check/arbitrary/definition/Arbitrary.js -var safeObjectAssign = Object.assign; - -class Arbitrary { - filter(refinement) { - return new FilterArbitrary(this, refinement); - } - map(mapper, unmapper) { - return new MapArbitrary(this, mapper, unmapper); - } - chain(chainer) { - return new ChainArbitrary(this, chainer); - } - noShrink() { - return new NoShrinkArbitrary(this); - } - noBias() { - return new NoBiasArbitrary(this); - } -} - -class ChainArbitrary extends Arbitrary { - constructor(arb, chainer) { - super(); - this.arb = arb; - this.chainer = chainer; - } - generate(mrng, biasFactor) { - const clonedMrng = mrng.clone(); - const src = this.arb.generate(mrng, biasFactor); - return this.valueChainer(src, mrng, clonedMrng, biasFactor); - } - canShrinkWithoutContext(value) { - return false; + case "ISlice": + return unsafeFromArray(reverse(toReadonlyArray(self))); } - shrink(value, context) { - if (this.isSafeContext(context)) { - return (!context.stoppedForOriginal ? this.arb.shrink(context.originalValue, context.originalContext).map((v) => this.valueChainer(v, context.clonedMrng.clone(), context.clonedMrng, context.originalBias)) : Stream.nil()).join(context.chainedArbitrary.shrink(value, context.chainedContext).map((dst) => { - const newContext = safeObjectAssign(safeObjectAssign({}, context), { - chainedContext: dst.context, - stoppedForOriginal: true - }); - return new Value(dst.value_, newContext); - })); +}; +var reverse2 = reverseChunk; +var get2 = /* @__PURE__ */ dual(2, (self, index) => index < 0 || index >= self.length ? none2() : some2(unsafeGet2(self, index))); +var unsafeFromArray = (self) => self.length === 0 ? empty2() : self.length === 1 ? of2(self[0]) : makeChunk({ + _tag: "IArray", + array: self +}); +var unsafeFromNonEmptyArray = (self) => unsafeFromArray(self); +var unsafeGet2 = /* @__PURE__ */ dual(2, (self, index) => { + switch (self.backing._tag) { + case "IEmpty": { + throw new Error(`Index out of bounds`); } - return Stream.nil(); - } - valueChainer(v, generateMrng, clonedMrng, biasFactor) { - const chainedArbitrary = this.chainer(v.value_); - const dst = chainedArbitrary.generate(generateMrng, biasFactor); - const context = { - originalBias: biasFactor, - originalValue: v.value_, - originalContext: v.context, - stoppedForOriginal: false, - chainedArbitrary, - chainedContext: dst.context, - clonedMrng - }; - return new Value(dst.value_, context); - } - isSafeContext(context) { - return context != null && typeof context === "object" && "originalBias" in context && "originalValue" in context && "originalContext" in context && "stoppedForOriginal" in context && "chainedArbitrary" in context && "chainedContext" in context && "clonedMrng" in context; - } -} - -class MapArbitrary extends Arbitrary { - constructor(arb, mapper, unmapper) { - super(); - this.arb = arb; - this.mapper = mapper; - this.unmapper = unmapper; - this.bindValueMapper = (v) => this.valueMapper(v); - } - generate(mrng, biasFactor) { - const g = this.arb.generate(mrng, biasFactor); - return this.valueMapper(g); - } - canShrinkWithoutContext(value) { - if (this.unmapper !== undefined) { - try { - const unmapped = this.unmapper(value); - return this.arb.canShrinkWithoutContext(unmapped); - } catch (_err) { - return false; + case "ISingleton": { + if (index !== 0) { + throw new Error(`Index out of bounds`); } + return self.backing.a; } - return false; - } - shrink(value, context) { - if (this.isSafeContext(context)) { - return this.arb.shrink(context.originalValue, context.originalContext).map(this.bindValueMapper); + case "IArray": { + if (index >= self.length || index < 0) { + throw new Error(`Index out of bounds`); + } + return self.backing.array[index]; } - if (this.unmapper !== undefined) { - const unmapped = this.unmapper(value); - return this.arb.shrink(unmapped, undefined).map(this.bindValueMapper); + case "IConcat": { + return index < self.left.length ? unsafeGet2(self.left, index) : unsafeGet2(self.right, index - self.left.length); } - return Stream.nil(); - } - mapperWithCloneIfNeeded(v) { - const sourceValue = v.value; - const mappedValue = this.mapper(sourceValue); - if (v.hasToBeCloned && (typeof mappedValue === "object" && mappedValue !== null || typeof mappedValue === "function") && Object.isExtensible(mappedValue) && !hasCloneMethod(mappedValue)) { - Object.defineProperty(mappedValue, cloneMethod, { get: () => () => this.mapperWithCloneIfNeeded(v)[0] }); + case "ISlice": { + return unsafeGet2(self.backing.chunk, index + self.backing.offset); } - return [mappedValue, sourceValue]; - } - valueMapper(v) { - const [mappedValue, sourceValue] = this.mapperWithCloneIfNeeded(v); - const context = { originalValue: sourceValue, originalContext: v.context }; - return new Value(mappedValue, context); - } - isSafeContext(context) { - return context != null && typeof context === "object" && "originalValue" in context && "originalContext" in context; - } -} - -class FilterArbitrary extends Arbitrary { - constructor(arb, refinement) { - super(); - this.arb = arb; - this.refinement = refinement; - this.bindRefinementOnValue = (v) => this.refinementOnValue(v); } - generate(mrng, biasFactor) { - while (true) { - const g = this.arb.generate(mrng, biasFactor); - if (this.refinementOnValue(g)) { - return g; +}); +var append2 = /* @__PURE__ */ dual(2, (self, a) => appendAll2(self, of2(a))); +var prepend2 = /* @__PURE__ */ dual(2, (self, elem) => appendAll2(of2(elem), self)); +var drop2 = /* @__PURE__ */ dual(2, (self, n) => { + if (n <= 0) { + return self; + } else if (n >= self.length) { + return _empty; + } else { + switch (self.backing._tag) { + case "ISlice": { + return makeChunk({ + _tag: "ISlice", + chunk: self.backing.chunk, + offset: self.backing.offset + n, + length: self.backing.length - n + }); + } + case "IConcat": { + if (n > self.left.length) { + return drop2(self.right, n - self.left.length); + } + return makeChunk({ + _tag: "IConcat", + left: drop2(self.left, n), + right: self.right + }); + } + default: { + return makeChunk({ + _tag: "ISlice", + chunk: self, + offset: n, + length: self.length - n + }); } } } - canShrinkWithoutContext(value) { - return this.arb.canShrinkWithoutContext(value) && this.refinement(value); - } - shrink(value, context) { - return this.arb.shrink(value, context).filter(this.bindRefinementOnValue); - } - refinementOnValue(v) { - return this.refinement(v.value); - } -} - -class NoShrinkArbitrary extends Arbitrary { - constructor(arb) { - super(); - this.arb = arb; - } - generate(mrng, biasFactor) { - return this.arb.generate(mrng, biasFactor); - } - canShrinkWithoutContext(value) { - return this.arb.canShrinkWithoutContext(value); - } - shrink(_value, _context) { - return Stream.nil(); - } - noShrink() { - return this; - } -} - -class NoBiasArbitrary extends Arbitrary { - constructor(arb) { - super(); - this.arb = arb; - } - generate(mrng, _biasFactor) { - return this.arb.generate(mrng, undefined); - } - canShrinkWithoutContext(value) { - return this.arb.canShrinkWithoutContext(value); - } - shrink(value, context) { - return this.arb.shrink(value, context); - } - noBias() { - return this; +}); +var appendAll2 = /* @__PURE__ */ dual(2, (self, that) => { + if (self.backing._tag === "IEmpty") { + return that; } -} - -// node_modules/fast-check/lib/esm/utils/apply.js -var untouchedApply = Function.prototype.apply; -var ApplySymbol = Symbol("apply"); -function safeExtractApply(f) { - try { - return f.apply; - } catch (err) { - return; + if (that.backing._tag === "IEmpty") { + return self; } -} -function safeApplyHacky(f, instance, args) { - const ff = f; - ff[ApplySymbol] = untouchedApply; - const out = ff[ApplySymbol](instance, args); - delete ff[ApplySymbol]; - return out; -} -function safeApply(f, instance, args) { - if (safeExtractApply(f) === untouchedApply) { - return f.apply(instance, args); + const diff = that.depth - self.depth; + if (Math.abs(diff) <= 1) { + return makeChunk({ + _tag: "IConcat", + left: self, + right: that + }); + } else if (diff < -1) { + if (self.left.depth >= self.right.depth) { + const nr = appendAll2(self.right, that); + return makeChunk({ + _tag: "IConcat", + left: self.left, + right: nr + }); + } else { + const nrr = appendAll2(self.right.right, that); + if (nrr.depth === self.depth - 3) { + const nr = makeChunk({ + _tag: "IConcat", + left: self.right.left, + right: nrr + }); + return makeChunk({ + _tag: "IConcat", + left: self.left, + right: nr + }); + } else { + const nl = makeChunk({ + _tag: "IConcat", + left: self.left, + right: self.right.left + }); + return makeChunk({ + _tag: "IConcat", + left: nl, + right: nrr + }); + } + } + } else { + if (that.right.depth >= that.left.depth) { + const nl = appendAll2(self, that.left); + return makeChunk({ + _tag: "IConcat", + left: nl, + right: that.right + }); + } else { + const nll = appendAll2(self, that.left.left); + if (nll.depth === that.depth - 3) { + const nl = makeChunk({ + _tag: "IConcat", + left: nll, + right: that.left.right + }); + return makeChunk({ + _tag: "IConcat", + left: nl, + right: that.right + }); + } else { + const nr = makeChunk({ + _tag: "IConcat", + left: that.left.right, + right: that.right + }); + return makeChunk({ + _tag: "IConcat", + left: nll, + right: nr + }); + } + } } - return safeApplyHacky(f, instance, args); -} +}); +var isEmpty = (self) => self.length === 0; +var isNonEmpty = (self) => self.length > 0; +var head2 = /* @__PURE__ */ get2(0); +var unsafeHead = (self) => unsafeGet2(self, 0); +var headNonEmpty2 = unsafeHead; +var tailNonEmpty2 = (self) => drop2(self, 1); -// node_modules/fast-check/lib/esm/utils/globals.js -var untouchedForEach = Array.prototype.forEach; -var untouchedIndexOf = Array.prototype.indexOf; -var untouchedJoin = Array.prototype.join; -var untouchedMap = Array.prototype.map; -var untouchedFilter = Array.prototype.filter; -var untouchedPush = Array.prototype.push; -var untouchedPop = Array.prototype.pop; -var untouchedSplice = Array.prototype.splice; -var untouchedSlice = Array.prototype.slice; -var untouchedSort = Array.prototype.sort; -var untouchedEvery = Array.prototype.every; -function extractIndexOf(instance) { - try { - return instance.indexOf; - } catch (err) { - return; - } -} -function extractMap(instance) { - try { - return instance.map; - } catch (err) { - return; - } -} -function extractPush(instance) { - try { - return instance.push; - } catch (err) { - return; - } -} -function extractSlice(instance) { - try { - return instance.slice; - } catch (err) { - return; +// node_modules/effect/dist/esm/internal/context.js +var TagTypeId = /* @__PURE__ */ Symbol.for("effect/Context/Tag"); +var ReferenceTypeId = /* @__PURE__ */ Symbol.for("effect/Context/Reference"); +var STMSymbolKey = "effect/STM"; +var STMTypeId = /* @__PURE__ */ Symbol.for(STMSymbolKey); +var TagProto = { + ...EffectPrototype, + _op: "Tag", + [STMTypeId]: effectVariance, + [TagTypeId]: { + _Service: (_) => _, + _Identifier: (_) => _ + }, + toString() { + return format(this.toJSON()); + }, + toJSON() { + return { + _id: "Tag", + key: this.key, + stack: this.stack + }; + }, + [NodeInspectSymbol]() { + return this.toJSON(); + }, + of(self) { + return self; + }, + context(self) { + return make5(this, self); } -} -function safeIndexOf(instance, ...args) { - if (extractIndexOf(instance) === untouchedIndexOf) { - return instance.indexOf(...args); +}; +var ReferenceProto = { + ...TagProto, + [ReferenceTypeId]: ReferenceTypeId +}; +var makeGenericTag = (key) => { + const limit = Error.stackTraceLimit; + Error.stackTraceLimit = 2; + const creationError = new Error; + Error.stackTraceLimit = limit; + const tag = Object.create(TagProto); + Object.defineProperty(tag, "stack", { + get() { + return creationError.stack; + } + }); + tag.key = key; + return tag; +}; +var Reference = () => (id, options) => { + const limit = Error.stackTraceLimit; + Error.stackTraceLimit = 2; + const creationError = new Error; + Error.stackTraceLimit = limit; + function ReferenceClass() {} + Object.setPrototypeOf(ReferenceClass, ReferenceProto); + ReferenceClass.key = id; + ReferenceClass.defaultValue = options.defaultValue; + Object.defineProperty(ReferenceClass, "stack", { + get() { + return creationError.stack; + } + }); + return ReferenceClass; +}; +var TypeId4 = /* @__PURE__ */ Symbol.for("effect/Context"); +var ContextProto = { + [TypeId4]: { + _Services: (_) => _ + }, + [symbol2](that) { + if (isContext(that)) { + if (this.unsafeMap.size === that.unsafeMap.size) { + for (const k of this.unsafeMap.keys()) { + if (!that.unsafeMap.has(k) || !equals(this.unsafeMap.get(k), that.unsafeMap.get(k))) { + return false; + } + } + return true; + } + } + return false; + }, + [symbol]() { + return cached(this, number2(this.unsafeMap.size)); + }, + pipe() { + return pipeArguments(this, arguments); + }, + toString() { + return format(this.toJSON()); + }, + toJSON() { + return { + _id: "Context", + services: Array.from(this.unsafeMap).map(toJSON) + }; + }, + [NodeInspectSymbol]() { + return this.toJSON(); } - return safeApply(untouchedIndexOf, instance, args); -} -function safeMap(instance, fn) { - if (extractMap(instance) === untouchedMap) { - return instance.map(fn); +}; +var makeContext = (unsafeMap) => { + const context = Object.create(ContextProto); + context.unsafeMap = unsafeMap; + return context; +}; +var serviceNotFoundError = (tag) => { + const error = new Error(`Service not found${tag.key ? `: ${String(tag.key)}` : ""}`); + if (tag.stack) { + const lines = tag.stack.split(` +`); + if (lines.length > 2) { + const afterAt = lines[2].match(/at (.*)/); + if (afterAt) { + error.message = error.message + ` (defined at ${afterAt[1]})`; + } + } } - return safeApply(untouchedMap, instance, [fn]); -} -function safePush(instance, ...args) { - if (extractPush(instance) === untouchedPush) { - return instance.push(...args); + if (error.stack) { + const lines = error.stack.split(` +`); + lines.splice(1, 3); + error.stack = lines.join(` +`); } - return safeApply(untouchedPush, instance, args); -} -function safeSlice(instance, ...args) { - if (extractSlice(instance) === untouchedSlice) { - return instance.slice(...args); + return error; +}; +var isContext = (u) => hasProperty(u, TypeId4); +var isTag = (u) => hasProperty(u, TagTypeId); +var isReference = (u) => hasProperty(u, ReferenceTypeId); +var _empty2 = /* @__PURE__ */ makeContext(/* @__PURE__ */ new Map); +var empty3 = () => _empty2; +var make5 = (tag, service) => makeContext(new Map([[tag.key, service]])); +var add = /* @__PURE__ */ dual(3, (self, tag, service) => { + const map4 = new Map(self.unsafeMap); + map4.set(tag.key, service); + return makeContext(map4); +}); +var defaultValueCache = /* @__PURE__ */ globalValue("effect/Context/defaultValueCache", () => new Map); +var getDefaultValue = (tag) => { + if (defaultValueCache.has(tag.key)) { + return defaultValueCache.get(tag.key); } - return safeApply(untouchedSlice, instance, args); -} -var untouchedGetTime = Date.prototype.getTime; -var untouchedToISOString = Date.prototype.toISOString; -var untouchedAdd = Set.prototype.add; -var untouchedHas = Set.prototype.has; -var untouchedSet = WeakMap.prototype.set; -var untouchedGet = WeakMap.prototype.get; -var untouchedMapSet = Map.prototype.set; -var untouchedMapGet = Map.prototype.get; -function extractMapSet(instance) { - try { - return instance.set; - } catch (err) { - return; + const value = tag.defaultValue(); + defaultValueCache.set(tag.key, value); + return value; +}; +var unsafeGetReference = (self, tag) => { + return self.unsafeMap.has(tag.key) ? self.unsafeMap.get(tag.key) : getDefaultValue(tag); +}; +var unsafeGet3 = /* @__PURE__ */ dual(2, (self, tag) => { + if (!self.unsafeMap.has(tag.key)) { + if (ReferenceTypeId in tag) + return getDefaultValue(tag); + throw serviceNotFoundError(tag); } -} -function extractMapGet(instance) { - try { - return instance.get; - } catch (err) { - return; + return self.unsafeMap.get(tag.key); +}); +var get3 = unsafeGet3; +var getOption = /* @__PURE__ */ dual(2, (self, tag) => { + if (!self.unsafeMap.has(tag.key)) { + return isReference(tag) ? some(getDefaultValue(tag)) : none; } -} -function safeMapSet(instance, key, value) { - if (extractMapSet(instance) === untouchedMapSet) { - return instance.set(key, value); + return some(self.unsafeMap.get(tag.key)); +}); +var merge2 = /* @__PURE__ */ dual(2, (self, that) => { + const map4 = new Map(self.unsafeMap); + for (const [tag, s] of that.unsafeMap) { + map4.set(tag, s); } - return safeApply(untouchedMapSet, instance, [key, value]); -} -function safeMapGet(instance, key) { - if (extractMapGet(instance) === untouchedMapGet) { - return instance.get(key); + return makeContext(map4); +}); +var mergeAll = (...ctxs) => { + const map4 = new Map; + for (let i = 0;i < ctxs.length; i++) { + ctxs[i].unsafeMap.forEach((value, key) => { + map4.set(key, value); + }); } - return safeApply(untouchedMapGet, instance, [key]); -} -var untouchedSplit = String.prototype.split; -var untouchedStartsWith = String.prototype.startsWith; -var untouchedEndsWith = String.prototype.endsWith; -var untouchedSubstring = String.prototype.substring; -var untouchedToLowerCase = String.prototype.toLowerCase; -var untouchedToUpperCase = String.prototype.toUpperCase; -var untouchedPadStart = String.prototype.padStart; -var untouchedCharCodeAt = String.prototype.charCodeAt; -var untouchedNormalize = String.prototype.normalize; -var untouchedReplace = String.prototype.replace; -var untouchedNumberToString = Number.prototype.toString; + return makeContext(map4); +}; -// node_modules/fast-check/lib/esm/stream/LazyIterableIterator.js -class LazyIterableIterator { - constructor(producer) { - this.producer = producer; - } - [Symbol.iterator]() { - if (this.it === undefined) { - this.it = this.producer(); +// node_modules/effect/dist/esm/Context.js +var GenericTag = makeGenericTag; +var isContext2 = isContext; +var isTag2 = isTag; +var empty4 = empty3; +var make6 = make5; +var add2 = add; +var get4 = get3; +var unsafeGet4 = unsafeGet3; +var getOption2 = getOption; +var merge3 = merge2; +var mergeAll2 = mergeAll; +var Reference2 = Reference; + +// node_modules/effect/dist/esm/Duration.js +var TypeId5 = /* @__PURE__ */ Symbol.for("effect/Duration"); +var bigint0 = /* @__PURE__ */ BigInt(0); +var bigint24 = /* @__PURE__ */ BigInt(24); +var bigint60 = /* @__PURE__ */ BigInt(60); +var bigint1e3 = /* @__PURE__ */ BigInt(1000); +var bigint1e6 = /* @__PURE__ */ BigInt(1e6); +var bigint1e9 = /* @__PURE__ */ BigInt(1e9); +var DURATION_REGEX = /^(-?\d+(?:\.\d+)?)\s+(nanos?|micros?|millis?|seconds?|minutes?|hours?|days?|weeks?)$/; +var decode = (input) => { + if (isDuration(input)) { + return input; + } else if (isNumber(input)) { + return millis(input); + } else if (isBigInt(input)) { + return nanos(input); + } else if (Array.isArray(input) && input.length === 2 && input.every(isNumber)) { + if (input[0] === -Infinity || input[1] === -Infinity || Number.isNaN(input[0]) || Number.isNaN(input[1])) { + return zero; } - return this.it; - } - next() { - if (this.it === undefined) { - this.it = this.producer(); + if (input[0] === Infinity || input[1] === Infinity) { + return infinity; } - return this.it.next(); - } -} -function makeLazy(producer) { - return new LazyIterableIterator(producer); -} - -// node_modules/fast-check/lib/esm/check/runner/configuration/GlobalParameters.js -var globalParameters = {}; -function readConfigureGlobal() { - return globalParameters; -} - -// node_modules/fast-check/lib/esm/arbitrary/_internals/helpers/BiasNumericRange.js -var safeMathFloor = Math.floor; -var safeMathLog = Math.log; -function integerLogLike(v) { - return safeMathFloor(safeMathLog(v) / safeMathLog(2)); -} -function biasNumericRange(min2, max2, logLike) { - if (min2 === max2) { - return [{ min: min2, max: max2 }]; - } - if (min2 < 0 && max2 > 0) { - const logMin = logLike(-min2); - const logMax = logLike(max2); - return [ - { min: -logMin, max: logMax }, - { min: max2 - logMax, max: max2 }, - { min: min2, max: min2 + logMin } - ]; - } - const logGap = logLike(max2 - min2); - const arbCloseToMin = { min: min2, max: min2 + logGap }; - const arbCloseToMax = { min: max2 - logGap, max: max2 }; - return min2 < 0 ? [arbCloseToMax, arbCloseToMin] : [arbCloseToMin, arbCloseToMax]; -} - -// node_modules/fast-check/lib/esm/arbitrary/_internals/helpers/ShrinkInteger.js -var safeMathCeil = Math.ceil; -var safeMathFloor2 = Math.floor; -function halvePosInteger(n) { - return safeMathFloor2(n / 2); -} -function halveNegInteger(n) { - return safeMathCeil(n / 2); -} -function shrinkInteger(current, target, tryTargetAsap) { - const realGap = current - target; - function* shrinkDecr() { - let previous = tryTargetAsap ? undefined : target; - const gap = tryTargetAsap ? realGap : halvePosInteger(realGap); - for (let toremove = gap;toremove > 0; toremove = halvePosInteger(toremove)) { - const next = toremove === realGap ? target : current - toremove; - yield new Value(next, previous); - previous = next; + return nanos(BigInt(Math.round(input[0] * 1e9)) + BigInt(Math.round(input[1]))); + } else if (isString(input)) { + const match4 = DURATION_REGEX.exec(input); + if (match4) { + const [_, valueStr, unit] = match4; + const value = Number(valueStr); + switch (unit) { + case "nano": + case "nanos": + return nanos(BigInt(valueStr)); + case "micro": + case "micros": + return micros(BigInt(valueStr)); + case "milli": + case "millis": + return millis(value); + case "second": + case "seconds": + return seconds(value); + case "minute": + case "minutes": + return minutes(value); + case "hour": + case "hours": + return hours(value); + case "day": + case "days": + return days(value); + case "week": + case "weeks": + return weeks(value); + } } } - function* shrinkIncr() { - let previous = tryTargetAsap ? undefined : target; - const gap = tryTargetAsap ? realGap : halveNegInteger(realGap); - for (let toremove = gap;toremove < 0; toremove = halveNegInteger(toremove)) { - const next = toremove === realGap ? target : current - toremove; - yield new Value(next, previous); - previous = next; + throw new Error("Invalid DurationInput"); +}; +var zeroValue = { + _tag: "Millis", + millis: 0 +}; +var infinityValue = { + _tag: "Infinity" +}; +var DurationProto = { + [TypeId5]: TypeId5, + [symbol]() { + return cached(this, structure(this.value)); + }, + [symbol2](that) { + return isDuration(that) && equals2(this, that); + }, + toString() { + return `Duration(${format2(this)})`; + }, + toJSON() { + switch (this.value._tag) { + case "Millis": + return { + _id: "Duration", + _tag: "Millis", + millis: this.value.millis + }; + case "Nanos": + return { + _id: "Duration", + _tag: "Nanos", + hrtime: toHrTime(this) + }; + case "Infinity": + return { + _id: "Duration", + _tag: "Infinity" + }; } + }, + [NodeInspectSymbol]() { + return this.toJSON(); + }, + pipe() { + return pipeArguments(this, arguments); } - return realGap > 0 ? stream(shrinkDecr()) : stream(shrinkIncr()); -} - -// node_modules/fast-check/lib/esm/arbitrary/_internals/IntegerArbitrary.js -var safeMathSign = Math.sign; -var safeNumberIsInteger = Number.isInteger; -var safeObjectIs = Object.is; - -class IntegerArbitrary extends Arbitrary { - constructor(min2, max2) { - super(); - this.min = min2; - this.max = max2; - } - generate(mrng, biasFactor) { - const range = this.computeGenerateRange(mrng, biasFactor); - return new Value(mrng.nextInt(range.min, range.max), undefined); - } - canShrinkWithoutContext(value) { - return typeof value === "number" && safeNumberIsInteger(value) && !safeObjectIs(value, -0) && this.min <= value && value <= this.max; - } - shrink(current, context) { - if (!IntegerArbitrary.isValidContext(current, context)) { - const target = this.defaultTarget(); - return shrinkInteger(current, target, true); - } - if (this.isLastChanceTry(current, context)) { - return Stream.of(new Value(context, undefined)); +}; +var make7 = (input) => { + const duration = Object.create(DurationProto); + if (isNumber(input)) { + if (isNaN(input) || input <= 0) { + duration.value = zeroValue; + } else if (!Number.isFinite(input)) { + duration.value = infinityValue; + } else if (!Number.isInteger(input)) { + duration.value = { + _tag: "Nanos", + nanos: BigInt(Math.round(input * 1e6)) + }; + } else { + duration.value = { + _tag: "Millis", + millis: input + }; } - return shrinkInteger(current, context, false); + } else if (input <= bigint0) { + duration.value = zeroValue; + } else { + duration.value = { + _tag: "Nanos", + nanos: input + }; } - defaultTarget() { - if (this.min <= 0 && this.max >= 0) { - return 0; + return duration; +}; +var isDuration = (u) => hasProperty(u, TypeId5); +var isFinite = (self) => self.value._tag !== "Infinity"; +var isZero = (self) => { + switch (self.value._tag) { + case "Millis": { + return self.value.millis === 0; } - return this.min < 0 ? this.max : this.min; - } - computeGenerateRange(mrng, biasFactor) { - if (biasFactor === undefined || mrng.nextInt(1, biasFactor) !== 1) { - return { min: this.min, max: this.max }; + case "Nanos": { + return self.value.nanos === bigint0; } - const ranges = biasNumericRange(this.min, this.max, integerLogLike); - if (ranges.length === 1) { - return ranges[0]; + case "Infinity": { + return false; } - const id = mrng.nextInt(-2 * (ranges.length - 1), ranges.length - 2); - return id < 0 ? ranges[0] : ranges[id + 1]; } - isLastChanceTry(current, context) { - if (current > 0) - return current === context + 1 && current > this.min; - if (current < 0) - return current === context - 1 && current < this.max; - return false; +}; +var zero = /* @__PURE__ */ make7(0); +var infinity = /* @__PURE__ */ make7(Infinity); +var nanos = (nanos2) => make7(nanos2); +var micros = (micros2) => make7(micros2 * bigint1e3); +var millis = (millis2) => make7(millis2); +var seconds = (seconds2) => make7(seconds2 * 1000); +var minutes = (minutes2) => make7(minutes2 * 60000); +var hours = (hours2) => make7(hours2 * 3600000); +var days = (days2) => make7(days2 * 86400000); +var weeks = (weeks2) => make7(weeks2 * 604800000); +var toMillis = (self) => match4(self, { + onMillis: (millis2) => millis2, + onNanos: (nanos2) => Number(nanos2) / 1e6 +}); +var toNanos = (self) => { + const _self = decode(self); + switch (_self.value._tag) { + case "Infinity": + return none2(); + case "Nanos": + return some2(_self.value.nanos); + case "Millis": + return some2(BigInt(Math.round(_self.value.millis * 1e6))); } - static isValidContext(current, context) { - if (context === undefined) { - return false; - } - if (typeof context !== "number") { - throw new Error(`Invalid context type passed to IntegerArbitrary (#1)`); - } - if (context !== 0 && safeMathSign(current) !== safeMathSign(context)) { - throw new Error(`Invalid context value passed to IntegerArbitrary (#2)`); - } - return true; +}; +var unsafeToNanos = (self) => { + const _self = decode(self); + switch (_self.value._tag) { + case "Infinity": + throw new Error("Cannot convert infinite duration to nanos"); + case "Nanos": + return _self.value.nanos; + case "Millis": + return BigInt(Math.round(_self.value.millis * 1e6)); } -} - -// node_modules/fast-check/lib/esm/arbitrary/integer.js -var safeNumberIsInteger2 = Number.isInteger; -function buildCompleteIntegerConstraints(constraints) { - const min2 = constraints.min !== undefined ? constraints.min : -2147483648; - const max2 = constraints.max !== undefined ? constraints.max : 2147483647; - return { min: min2, max: max2 }; -} -function integer(constraints = {}) { - const fullConstraints = buildCompleteIntegerConstraints(constraints); - if (fullConstraints.min > fullConstraints.max) { - throw new Error("fc.integer maximum value should be equal or greater than the minimum one"); +}; +var toHrTime = (self) => { + const _self = decode(self); + switch (_self.value._tag) { + case "Infinity": + return [Infinity, 0]; + case "Nanos": + return [Number(_self.value.nanos / bigint1e9), Number(_self.value.nanos % bigint1e9)]; + case "Millis": + return [Math.floor(_self.value.millis / 1000), Math.round(_self.value.millis % 1000 * 1e6)]; } - if (!safeNumberIsInteger2(fullConstraints.min)) { - throw new Error("fc.integer minimum value should be an integer"); +}; +var match4 = /* @__PURE__ */ dual(2, (self, options) => { + const _self = decode(self); + switch (_self.value._tag) { + case "Nanos": + return options.onNanos(_self.value.nanos); + case "Infinity": + return options.onMillis(Infinity); + case "Millis": + return options.onMillis(_self.value.millis); } - if (!safeNumberIsInteger2(fullConstraints.max)) { - throw new Error("fc.integer maximum value should be an integer"); +}); +var matchWith = /* @__PURE__ */ dual(3, (self, that, options) => { + const _self = decode(self); + const _that = decode(that); + if (_self.value._tag === "Infinity" || _that.value._tag === "Infinity") { + return options.onMillis(toMillis(_self), toMillis(_that)); + } else if (_self.value._tag === "Nanos" || _that.value._tag === "Nanos") { + const selfNanos = _self.value._tag === "Nanos" ? _self.value.nanos : BigInt(Math.round(_self.value.millis * 1e6)); + const thatNanos = _that.value._tag === "Nanos" ? _that.value.nanos : BigInt(Math.round(_that.value.millis * 1e6)); + return options.onNanos(selfNanos, thatNanos); } - return new IntegerArbitrary(fullConstraints.min, fullConstraints.max); -} - -// node_modules/fast-check/lib/esm/arbitrary/_internals/helpers/DepthContext.js -var depthContextCache = new Map; -function getDepthContextFor(contextMeta) { - if (contextMeta === undefined) { - return { depth: 0 }; + return options.onMillis(_self.value.millis, _that.value.millis); +}); +var Order = /* @__PURE__ */ make2((self, that) => matchWith(self, that, { + onMillis: (self2, that2) => self2 < that2 ? -1 : self2 > that2 ? 1 : 0, + onNanos: (self2, that2) => self2 < that2 ? -1 : self2 > that2 ? 1 : 0 +})); +var between2 = /* @__PURE__ */ between(/* @__PURE__ */ mapInput2(Order, decode)); +var Equivalence = (self, that) => matchWith(self, that, { + onMillis: (self2, that2) => self2 === that2, + onNanos: (self2, that2) => self2 === that2 +}); +var _clamp = /* @__PURE__ */ clamp(Order); +var clamp3 = /* @__PURE__ */ dual(2, (self, options) => _clamp(decode(self), { + minimum: decode(options.minimum), + maximum: decode(options.maximum) +})); +var lessThan2 = /* @__PURE__ */ dual(2, (self, that) => matchWith(self, that, { + onMillis: (self2, that2) => self2 < that2, + onNanos: (self2, that2) => self2 < that2 +})); +var lessThanOrEqualTo2 = /* @__PURE__ */ dual(2, (self, that) => matchWith(self, that, { + onMillis: (self2, that2) => self2 <= that2, + onNanos: (self2, that2) => self2 <= that2 +})); +var greaterThan2 = /* @__PURE__ */ dual(2, (self, that) => matchWith(self, that, { + onMillis: (self2, that2) => self2 > that2, + onNanos: (self2, that2) => self2 > that2 +})); +var greaterThanOrEqualTo2 = /* @__PURE__ */ dual(2, (self, that) => matchWith(self, that, { + onMillis: (self2, that2) => self2 >= that2, + onNanos: (self2, that2) => self2 >= that2 +})); +var equals2 = /* @__PURE__ */ dual(2, (self, that) => Equivalence(decode(self), decode(that))); +var parts = (self) => { + const duration = decode(self); + if (duration.value._tag === "Infinity") { + return { + days: Infinity, + hours: Infinity, + minutes: Infinity, + seconds: Infinity, + millis: Infinity, + nanos: Infinity + }; } - if (typeof contextMeta !== "string") { - return contextMeta; + const nanos2 = unsafeToNanos(duration); + const ms = nanos2 / bigint1e6; + const sec = ms / bigint1e3; + const min2 = sec / bigint60; + const hr = min2 / bigint60; + const days2 = hr / bigint24; + return { + days: Number(days2), + hours: Number(hr % bigint24), + minutes: Number(min2 % bigint60), + seconds: Number(sec % bigint60), + millis: Number(ms % bigint1e3), + nanos: Number(nanos2 % bigint1e6) + }; +}; +var format2 = (self) => { + const duration = decode(self); + if (duration.value._tag === "Infinity") { + return "Infinity"; } - const cachedContext = safeMapGet(depthContextCache, contextMeta); - if (cachedContext !== undefined) { - return cachedContext; + if (isZero(duration)) { + return "0"; } - const context = { depth: 0 }; - safeMapSet(depthContextCache, contextMeta, context); - return context; -} - -// node_modules/fast-check/lib/esm/arbitrary/_internals/implementations/NoopSlicedGenerator.js -class NoopSlicedGenerator { - constructor(arb, mrng, biasFactor) { - this.arb = arb; - this.mrng = mrng; - this.biasFactor = biasFactor; + const fragments = parts(duration); + const pieces = []; + if (fragments.days !== 0) { + pieces.push(`${fragments.days}d`); } - attemptExact() { - return; + if (fragments.hours !== 0) { + pieces.push(`${fragments.hours}h`); } - next() { - return this.arb.generate(this.mrng, this.biasFactor); + if (fragments.minutes !== 0) { + pieces.push(`${fragments.minutes}m`); } -} + if (fragments.seconds !== 0) { + pieces.push(`${fragments.seconds}s`); + } + if (fragments.millis !== 0) { + pieces.push(`${fragments.millis}ms`); + } + if (fragments.nanos !== 0) { + pieces.push(`${fragments.nanos}ns`); + } + return pieces.join(" "); +}; -// node_modules/fast-check/lib/esm/arbitrary/_internals/implementations/SlicedBasedGenerator.js -var safeMathMin = Math.min; -var safeMathMax = Math.max; +// node_modules/effect/dist/esm/internal/hashMap/config.js +var SIZE = 5; +var BUCKET_SIZE = /* @__PURE__ */ Math.pow(2, SIZE); +var MASK = BUCKET_SIZE - 1; +var MAX_INDEX_NODE = BUCKET_SIZE / 2; +var MIN_ARRAY_NODE = BUCKET_SIZE / 4; -class SlicedBasedGenerator { - constructor(arb, mrng, slices, biasFactor) { - this.arb = arb; - this.mrng = mrng; - this.slices = slices; - this.biasFactor = biasFactor; - this.activeSliceIndex = 0; - this.nextIndexInSlice = 0; - this.lastIndexInSlice = -1; +// node_modules/effect/dist/esm/internal/hashMap/bitwise.js +function popcount(x) { + x -= x >> 1 & 1431655765; + x = (x & 858993459) + (x >> 2 & 858993459); + x = x + (x >> 4) & 252645135; + x += x >> 8; + x += x >> 16; + return x & 127; +} +function hashFragment(shift, h) { + return h >>> shift & MASK; +} +function toBitmap(x) { + return 1 << x; +} +function fromBitmap(bitmap, bit) { + return popcount(bitmap & bit - 1); +} + +// node_modules/effect/dist/esm/internal/stack.js +var make8 = (value, previous) => ({ + value, + previous +}); + +// node_modules/effect/dist/esm/internal/hashMap/array.js +function arrayUpdate(mutate, at, v, arr) { + let out = arr; + if (!mutate) { + const len = arr.length; + out = new Array(len); + for (let i = 0;i < len; ++i) + out[i] = arr[i]; } - attemptExact(targetLength) { - if (targetLength !== 0 && this.mrng.nextInt(1, this.biasFactor) === 1) { - const eligibleIndices = []; - for (let index = 0;index !== this.slices.length; ++index) { - const slice = this.slices[index]; - if (slice.length === targetLength) { - safePush(eligibleIndices, index); - } - } - if (eligibleIndices.length === 0) { - return; - } - this.activeSliceIndex = eligibleIndices[this.mrng.nextInt(0, eligibleIndices.length - 1)]; - this.nextIndexInSlice = 0; - this.lastIndexInSlice = targetLength - 1; - } + out[at] = v; + return out; +} +function arraySpliceOut(mutate, at, arr) { + const newLen = arr.length - 1; + let i = 0; + let g = 0; + let out = arr; + if (mutate) { + i = g = at; + } else { + out = new Array(newLen); + while (i < at) + out[g++] = arr[i++]; } - next() { - if (this.nextIndexInSlice <= this.lastIndexInSlice) { - return new Value(this.slices[this.activeSliceIndex][this.nextIndexInSlice++], undefined); - } - if (this.mrng.nextInt(1, this.biasFactor) !== 1) { - return this.arb.generate(this.mrng, this.biasFactor); - } - this.activeSliceIndex = this.mrng.nextInt(0, this.slices.length - 1); - const slice = this.slices[this.activeSliceIndex]; - if (this.mrng.nextInt(1, this.biasFactor) !== 1) { - this.nextIndexInSlice = 1; - this.lastIndexInSlice = slice.length - 1; - return new Value(slice[0], undefined); - } - const rangeBoundaryA = this.mrng.nextInt(0, slice.length - 1); - const rangeBoundaryB = this.mrng.nextInt(0, slice.length - 1); - this.nextIndexInSlice = safeMathMin(rangeBoundaryA, rangeBoundaryB); - this.lastIndexInSlice = safeMathMax(rangeBoundaryA, rangeBoundaryB); - return new Value(slice[this.nextIndexInSlice++], undefined); + ++i; + while (i <= newLen) + out[g++] = arr[i++]; + if (mutate) { + out.length = newLen; } + return out; } - -// node_modules/fast-check/lib/esm/arbitrary/_internals/helpers/BuildSlicedGenerator.js -function buildSlicedGenerator(arb, mrng, slices, biasFactor) { - if (biasFactor === undefined || slices.length === 0 || mrng.nextInt(1, biasFactor) !== 1) { - return new NoopSlicedGenerator(arb, mrng, biasFactor); +function arraySpliceIn(mutate, at, v, arr) { + const len = arr.length; + if (mutate) { + let i2 = len; + while (i2 >= at) + arr[i2--] = arr[i2]; + arr[at] = v; + return arr; } - return new SlicedBasedGenerator(arb, mrng, slices, biasFactor); + let i = 0, g = 0; + const out = new Array(len + 1); + while (i < at) + out[g++] = arr[i++]; + out[at] = v; + while (i < len) + out[++g] = arr[i++]; + return out; } -// node_modules/fast-check/lib/esm/arbitrary/_internals/ArrayArbitrary.js -var safeMathFloor3 = Math.floor; -var safeMathLog2 = Math.log; -var safeMathMax2 = Math.max; -var safeArrayIsArray = Array.isArray; -function biasedMaxLength(minLength, maxLength) { - if (minLength === maxLength) { - return minLength; +// node_modules/effect/dist/esm/internal/hashMap/node.js +class EmptyNode { + _tag = "EmptyNode"; + modify(edit, _shift, f, hash2, key, size) { + const v = f(none2()); + if (isNone2(v)) + return new EmptyNode; + ++size.value; + return new LeafNode(edit, hash2, key, v); } - return minLength + safeMathFloor3(safeMathLog2(maxLength - minLength) / safeMathLog2(2)); +} +function isEmptyNode(a) { + return isTagged(a, "EmptyNode"); +} +function isLeafNode(node) { + return isEmptyNode(node) || node._tag === "LeafNode" || node._tag === "CollisionNode"; +} +function canEditNode(node, edit) { + return isEmptyNode(node) ? false : edit === node.edit; } -class ArrayArbitrary extends Arbitrary { - constructor(arb, minLength, maxGeneratedLength, maxLength, depthIdentifier, setBuilder, customSlices) { - super(); - this.arb = arb; - this.minLength = minLength; - this.maxGeneratedLength = maxGeneratedLength; - this.maxLength = maxLength; - this.setBuilder = setBuilder; - this.customSlices = customSlices; - this.lengthArb = integer({ min: minLength, max: maxGeneratedLength }); - this.depthContext = getDepthContextFor(depthIdentifier); - } - preFilter(tab) { - if (this.setBuilder === undefined) { - return tab; - } - const s = this.setBuilder(); - for (let index = 0;index !== tab.length; ++index) { - s.tryAdd(tab[index]); - } - return s.getData(); +class LeafNode { + edit; + hash; + key; + value; + _tag = "LeafNode"; + constructor(edit, hash2, key, value) { + this.edit = edit; + this.hash = hash2; + this.key = key; + this.value = value; } - static makeItCloneable(vs, shrinkables) { - vs[cloneMethod] = () => { - const cloned = []; - for (let idx = 0;idx !== shrinkables.length; ++idx) { - safePush(cloned, shrinkables[idx].value); + modify(edit, shift, f, hash2, key, size) { + if (equals(key, this.key)) { + const v2 = f(this.value); + if (v2 === this.value) + return this; + else if (isNone2(v2)) { + --size.value; + return new EmptyNode; } - this.makeItCloneable(cloned, shrinkables); - return cloned; - }; - return vs; - } - generateNItemsNoDuplicates(setBuilder, N, mrng, biasFactorItems) { - let numSkippedInRow = 0; - const s = setBuilder(); - const slicedGenerator = buildSlicedGenerator(this.arb, mrng, this.customSlices, biasFactorItems); - while (s.size() < N && numSkippedInRow < this.maxGeneratedLength) { - const current = slicedGenerator.next(); - if (s.tryAdd(current)) { - numSkippedInRow = 0; - } else { - numSkippedInRow += 1; + if (canEditNode(this, edit)) { + this.value = v2; + return this; } + return new LeafNode(edit, hash2, key, v2); } - return s.getData(); - } - safeGenerateNItemsNoDuplicates(setBuilder, N, mrng, biasFactorItems) { - const depthImpact = safeMathMax2(0, N - biasedMaxLength(this.minLength, this.maxGeneratedLength)); - this.depthContext.depth += depthImpact; - try { - return this.generateNItemsNoDuplicates(setBuilder, N, mrng, biasFactorItems); - } finally { - this.depthContext.depth -= depthImpact; - } + const v = f(none2()); + if (isNone2(v)) + return this; + ++size.value; + return mergeLeaves(edit, shift, this.hash, this, hash2, new LeafNode(edit, hash2, key, v)); } - generateNItems(N, mrng, biasFactorItems) { - const items = []; - const slicedGenerator = buildSlicedGenerator(this.arb, mrng, this.customSlices, biasFactorItems); - slicedGenerator.attemptExact(N); - for (let index = 0;index !== N; ++index) { - const current = slicedGenerator.next(); - safePush(items, current); - } - return items; +} + +class CollisionNode { + edit; + hash; + children; + _tag = "CollisionNode"; + constructor(edit, hash2, children) { + this.edit = edit; + this.hash = hash2; + this.children = children; } - safeGenerateNItems(N, mrng, biasFactorItems) { - const depthImpact = safeMathMax2(0, N - biasedMaxLength(this.minLength, this.maxGeneratedLength)); - this.depthContext.depth += depthImpact; - try { - return this.generateNItems(N, mrng, biasFactorItems); - } finally { - this.depthContext.depth -= depthImpact; + modify(edit, shift, f, hash2, key, size) { + if (hash2 === this.hash) { + const canEdit = canEditNode(this, edit); + const list = this.updateCollisionList(canEdit, edit, this.hash, this.children, f, key, size); + if (list === this.children) + return this; + return list.length > 1 ? new CollisionNode(edit, this.hash, list) : list[0]; } + const v = f(none2()); + if (isNone2(v)) + return this; + ++size.value; + return mergeLeaves(edit, shift, this.hash, this, hash2, new LeafNode(edit, hash2, key, v)); } - wrapper(itemsRaw, shrunkOnce, itemsRawLengthContext, startIndex) { - const items = shrunkOnce ? this.preFilter(itemsRaw) : itemsRaw; - let cloneable = false; - const vs = []; - const itemsContexts = []; - for (let idx = 0;idx !== items.length; ++idx) { - const s = items[idx]; - cloneable = cloneable || s.hasToBeCloned; - safePush(vs, s.value); - safePush(itemsContexts, s.context); - } - if (cloneable) { - ArrayArbitrary.makeItCloneable(vs, items); + updateCollisionList(mutate, edit, hash2, list, f, key, size) { + const len = list.length; + for (let i = 0;i < len; ++i) { + const child = list[i]; + if ("key" in child && equals(key, child.key)) { + const value = child.value; + const newValue2 = f(value); + if (newValue2 === value) + return list; + if (isNone2(newValue2)) { + --size.value; + return arraySpliceOut(mutate, i, list); + } + return arrayUpdate(mutate, i, new LeafNode(edit, hash2, key, newValue2), list); + } } - const context = { - shrunkOnce, - lengthContext: itemsRaw.length === items.length && itemsRawLengthContext !== undefined ? itemsRawLengthContext : undefined, - itemsContexts, - startIndex - }; - return new Value(vs, context); + const newValue = f(none2()); + if (isNone2(newValue)) + return list; + ++size.value; + return arrayUpdate(mutate, len, new LeafNode(edit, hash2, key, newValue), list); } - generate(mrng, biasFactor) { - const biasMeta = this.applyBias(mrng, biasFactor); - const targetSize = biasMeta.size; - const items = this.setBuilder !== undefined ? this.safeGenerateNItemsNoDuplicates(this.setBuilder, targetSize, mrng, biasMeta.biasFactorItems) : this.safeGenerateNItems(targetSize, mrng, biasMeta.biasFactorItems); - return this.wrapper(items, false, undefined, 0); +} + +class IndexedNode { + edit; + mask; + children; + _tag = "IndexedNode"; + constructor(edit, mask, children) { + this.edit = edit; + this.mask = mask; + this.children = children; } - applyBias(mrng, biasFactor) { - if (biasFactor === undefined) { - return { size: this.lengthArb.generate(mrng, undefined).value }; - } - if (this.minLength === this.maxGeneratedLength) { - return { size: this.lengthArb.generate(mrng, undefined).value, biasFactorItems: biasFactor }; + modify(edit, shift, f, hash2, key, size) { + const mask = this.mask; + const children = this.children; + const frag = hashFragment(shift, hash2); + const bit = toBitmap(frag); + const indx = fromBitmap(mask, bit); + const exists2 = mask & bit; + const canEdit = canEditNode(this, edit); + if (!exists2) { + const _newChild = new EmptyNode().modify(edit, shift + SIZE, f, hash2, key, size); + if (!_newChild) + return this; + return children.length >= MAX_INDEX_NODE ? expand(edit, frag, _newChild, mask, children) : new IndexedNode(edit, mask | bit, arraySpliceIn(canEdit, indx, _newChild, children)); } - if (mrng.nextInt(1, biasFactor) !== 1) { - return { size: this.lengthArb.generate(mrng, undefined).value }; + const current = children[indx]; + const child = current.modify(edit, shift + SIZE, f, hash2, key, size); + if (current === child) + return this; + let bitmap = mask; + let newChildren; + if (isEmptyNode(child)) { + bitmap &= ~bit; + if (!bitmap) + return new EmptyNode; + if (children.length <= 2 && isLeafNode(children[indx ^ 1])) { + return children[indx ^ 1]; + } + newChildren = arraySpliceOut(canEdit, indx, children); + } else { + newChildren = arrayUpdate(canEdit, indx, child, children); } - if (mrng.nextInt(1, biasFactor) !== 1 || this.minLength === this.maxGeneratedLength) { - return { size: this.lengthArb.generate(mrng, undefined).value, biasFactorItems: biasFactor }; + if (canEdit) { + this.mask = bitmap; + this.children = newChildren; + return this; } - const maxBiasedLength = biasedMaxLength(this.minLength, this.maxGeneratedLength); - const targetSizeValue = integer({ min: this.minLength, max: maxBiasedLength }).generate(mrng, undefined); - return { size: targetSizeValue.value, biasFactorItems: biasFactor }; + return new IndexedNode(edit, bitmap, newChildren); } - canShrinkWithoutContext(value) { - if (!safeArrayIsArray(value) || this.minLength > value.length || value.length > this.maxLength) { - return false; - } - for (let index = 0;index !== value.length; ++index) { - if (!(index in value)) { - return false; - } - if (!this.arb.canShrinkWithoutContext(value[index])) { - return false; +} + +class ArrayNode { + edit; + size; + children; + _tag = "ArrayNode"; + constructor(edit, size, children) { + this.edit = edit; + this.size = size; + this.children = children; + } + modify(edit, shift, f, hash2, key, size) { + let count = this.size; + const children = this.children; + const frag = hashFragment(shift, hash2); + const child = children[frag]; + const newChild = (child || new EmptyNode).modify(edit, shift + SIZE, f, hash2, key, size); + if (child === newChild) + return this; + const canEdit = canEditNode(this, edit); + let newChildren; + if (isEmptyNode(child) && !isEmptyNode(newChild)) { + ++count; + newChildren = arrayUpdate(canEdit, frag, newChild, children); + } else if (!isEmptyNode(child) && isEmptyNode(newChild)) { + --count; + if (count <= MIN_ARRAY_NODE) { + return pack(edit, count, frag, children); } + newChildren = arrayUpdate(canEdit, frag, new EmptyNode, children); + } else { + newChildren = arrayUpdate(canEdit, frag, newChild, children); } - const filtered = this.preFilter(safeMap(value, (item) => new Value(item, undefined))); - return filtered.length === value.length; - } - shrinkItemByItem(value, safeContext, endIndex) { - const shrinks = []; - for (let index = safeContext.startIndex;index < endIndex; ++index) { - safePush(shrinks, makeLazy(() => this.arb.shrink(value[index], safeContext.itemsContexts[index]).map((v) => { - const beforeCurrent = safeMap(safeSlice(value, 0, index), (v2, i) => new Value(cloneIfNeeded(v2), safeContext.itemsContexts[i])); - const afterCurrent = safeMap(safeSlice(value, index + 1), (v2, i) => new Value(cloneIfNeeded(v2), safeContext.itemsContexts[i + index + 1])); - return [ - [...beforeCurrent, v, ...afterCurrent], - undefined, - index - ]; - }))); + if (canEdit) { + this.size = count; + this.children = newChildren; + return this; } - return Stream.nil().join(...shrinks); + return new ArrayNode(edit, count, newChildren); } - shrinkImpl(value, context) { - if (value.length === 0) { - return Stream.nil(); +} +function pack(edit, count, removed, elements) { + const children = new Array(count - 1); + let g = 0; + let bitmap = 0; + for (let i = 0, len = elements.length;i < len; ++i) { + if (i !== removed) { + const elem = elements[i]; + if (elem && !isEmptyNode(elem)) { + children[g++] = elem; + bitmap |= 1 << i; + } } - const safeContext = context !== undefined ? context : { shrunkOnce: false, lengthContext: undefined, itemsContexts: [], startIndex: 0 }; - return this.lengthArb.shrink(value.length, safeContext.lengthContext).drop(safeContext.shrunkOnce && safeContext.lengthContext === undefined && value.length > this.minLength + 1 ? 1 : 0).map((lengthValue) => { - const sliceStart = value.length - lengthValue.value; - return [ - safeMap(safeSlice(value, sliceStart), (v, index) => new Value(cloneIfNeeded(v), safeContext.itemsContexts[index + sliceStart])), - lengthValue.context, - 0 - ]; - }).join(makeLazy(() => value.length > this.minLength ? this.shrinkItemByItem(value, safeContext, 1) : this.shrinkItemByItem(value, safeContext, value.length))).join(value.length > this.minLength ? makeLazy(() => { - const subContext = { - shrunkOnce: false, - lengthContext: undefined, - itemsContexts: safeSlice(safeContext.itemsContexts, 1), - startIndex: 0 - }; - return this.shrinkImpl(safeSlice(value, 1), subContext).filter((v) => this.minLength <= v[0].length + 1).map((v) => { - return [[new Value(cloneIfNeeded(value[0]), safeContext.itemsContexts[0]), ...v[0]], undefined, 0]; - }); - }) : Stream.nil()); - } - shrink(value, context) { - return this.shrinkImpl(value, context).map((contextualValue) => this.wrapper(contextualValue[0], true, contextualValue[1], contextualValue[2])); } + return new IndexedNode(edit, bitmap, children); } - -// node_modules/fast-check/lib/esm/arbitrary/_internals/helpers/MaxLengthFromMinLength.js -var safeMathFloor4 = Math.floor; -var safeMathMin2 = Math.min; -var MaxLengthUpperBound = 2147483647; -var orderedSize = ["xsmall", "small", "medium", "large", "xlarge"]; -var orderedRelativeSize = ["-4", "-3", "-2", "-1", "=", "+1", "+2", "+3", "+4"]; -var DefaultSize = "small"; -function maxLengthFromMinLength(minLength, size) { - switch (size) { - case "xsmall": - return safeMathFloor4(1.1 * minLength) + 1; - case "small": - return 2 * minLength + 10; - case "medium": - return 11 * minLength + 100; - case "large": - return 101 * minLength + 1000; - case "xlarge": - return 1001 * minLength + 1e4; - default: - throw new Error(`Unable to compute lengths based on received size: ${size}`); +function expand(edit, frag, child, bitmap, subNodes) { + const arr = []; + let bit = bitmap; + let count = 0; + for (let i = 0;bit; ++i) { + if (bit & 1) + arr[i] = subNodes[count++]; + bit >>>= 1; } + arr[frag] = child; + return new ArrayNode(edit, count + 1, arr); } -function relativeSizeToSize(size, defaultSize) { - const sizeInRelative = safeIndexOf(orderedRelativeSize, size); - if (sizeInRelative === -1) { - return size; - } - const defaultSizeInSize = safeIndexOf(orderedSize, defaultSize); - if (defaultSizeInSize === -1) { - throw new Error(`Unable to offset size based on the unknown defaulted one: ${defaultSize}`); +function mergeLeavesInner(edit, shift, h1, n1, h2, n2) { + if (h1 === h2) + return new CollisionNode(edit, h1, [n2, n1]); + const subH1 = hashFragment(shift, h1); + const subH2 = hashFragment(shift, h2); + if (subH1 === subH2) { + return (child) => new IndexedNode(edit, toBitmap(subH1) | toBitmap(subH2), [child]); + } else { + const children = subH1 < subH2 ? [n1, n2] : [n2, n1]; + return new IndexedNode(edit, toBitmap(subH1) | toBitmap(subH2), children); } - const resultingSizeInSize = defaultSizeInSize + sizeInRelative - 4; - return resultingSizeInSize < 0 ? orderedSize[0] : resultingSizeInSize >= orderedSize.length ? orderedSize[orderedSize.length - 1] : orderedSize[resultingSizeInSize]; } -function maxGeneratedLengthFromSizeForArbitrary(size, minLength, maxLength, specifiedMaxLength) { - const { baseSize: defaultSize = DefaultSize, defaultSizeToMaxWhenMaxSpecified } = readConfigureGlobal() || {}; - const definedSize = size !== undefined ? size : specifiedMaxLength && defaultSizeToMaxWhenMaxSpecified ? "max" : defaultSize; - if (definedSize === "max") { - return maxLength; +function mergeLeaves(edit, shift, h1, n1, h2, n2) { + let stack = undefined; + let currentShift = shift; + while (true) { + const res = mergeLeavesInner(edit, currentShift, h1, n1, h2, n2); + if (typeof res === "function") { + stack = make8(res, stack); + currentShift = currentShift + SIZE; + } else { + let final = res; + while (stack != null) { + final = stack.value(final); + stack = stack.previous; + } + return final; + } } - const finalSize = relativeSizeToSize(definedSize, defaultSize); - return safeMathMin2(maxLengthFromMinLength(minLength, finalSize), maxLength); -} - -// node_modules/fast-check/lib/esm/arbitrary/array.js -function array3(arb, constraints = {}) { - const size = constraints.size; - const minLength = constraints.minLength || 0; - const maxLengthOrUnset = constraints.maxLength; - const depthIdentifier = constraints.depthIdentifier; - const maxLength = maxLengthOrUnset !== undefined ? maxLengthOrUnset : MaxLengthUpperBound; - const specifiedMaxLength = maxLengthOrUnset !== undefined; - const maxGeneratedLength = maxGeneratedLengthFromSizeForArbitrary(size, minLength, maxLength, specifiedMaxLength); - const customSlices = constraints.experimentalCustomSlices || []; - return new ArrayArbitrary(arb, minLength, maxGeneratedLength, maxLength, depthIdentifier, undefined, customSlices); } -// node_modules/effect/dist/esm/internal/schema/util.js -var getKeysForIndexSignature = (input, parameter) => { - switch (parameter._tag) { - case "StringKeyword": - case "TemplateLiteral": - return Object.keys(input); - case "SymbolKeyword": - return Object.getOwnPropertySymbols(input); - case "Refinement": - return getKeysForIndexSignature(input, parameter.from); +// node_modules/effect/dist/esm/internal/hashMap.js +var HashMapSymbolKey = "effect/HashMap"; +var HashMapTypeId = /* @__PURE__ */ Symbol.for(HashMapSymbolKey); +var HashMapProto = { + [HashMapTypeId]: HashMapTypeId, + [Symbol.iterator]() { + return new HashMapIterator(this, (k, v) => [k, v]); + }, + [symbol]() { + let hash2 = hash(HashMapSymbolKey); + for (const item of this) { + hash2 ^= pipe(hash(item[0]), combine(hash(item[1]))); + } + return cached(this, hash2); + }, + [symbol2](that) { + if (isHashMap(that)) { + if (that._size !== this._size) { + return false; + } + for (const item of this) { + const elem = pipe(that, getHash(item[0], hash(item[0]))); + if (isNone2(elem)) { + return false; + } else { + if (!equals(item[1], elem.value)) { + return false; + } + } + } + return true; + } + return false; + }, + toString() { + return format(this.toJSON()); + }, + toJSON() { + return { + _id: "HashMap", + values: Array.from(this).map(toJSON) + }; + }, + [NodeInspectSymbol]() { + return this.toJSON(); + }, + pipe() { + return pipeArguments(this, arguments); } }; -var memoizeThunk = (f) => { - let done = false; - let a; - return () => { - if (done) { - return a; - } - a = f(); - done = true; - return a; - }; +var makeImpl = (editable, edit, root, size) => { + const map4 = Object.create(HashMapProto); + map4._editable = editable; + map4._edit = edit; + map4._root = root; + map4._size = size; + return map4; }; -var isNonEmpty = (x) => Array.isArray(x); -var isSingle = (x) => !Array.isArray(x); -var formatPathKey = (key) => `[${formatPropertyKey(key)}]`; -var formatPath = (path) => isNonEmpty(path) ? path.map(formatPathKey).join("") : formatPathKey(path); -// node_modules/effect/dist/esm/internal/schema/errors.js -var getErrorMessage = (reason, details, path, ast) => { - let out = reason; - if (path && isNonEmptyReadonlyArray(path)) { - out += ` -at path: ${formatPath(path)}`; +class HashMapIterator { + map; + f; + v; + constructor(map4, f) { + this.map = map4; + this.f = f; + this.v = visitLazy(this.map._root, this.f, undefined); } - if (details !== undefined) { - out += ` -details: ${details}`; + next() { + if (isNone2(this.v)) { + return { + done: true, + value: undefined + }; + } + const v0 = this.v.value; + this.v = applyCont(v0.cont); + return { + done: false, + value: v0.value + }; } - if (ast) { - out += ` -schema (${ast._tag}): ${ast}`; + [Symbol.iterator]() { + return new HashMapIterator(this.map, this.f); + } +} +var applyCont = (cont) => cont ? visitLazyChildren(cont[0], cont[1], cont[2], cont[3], cont[4]) : none2(); +var visitLazy = (node, f, cont = undefined) => { + switch (node._tag) { + case "LeafNode": { + if (isSome2(node.value)) { + return some2({ + value: f(node.key, node.value.value), + cont + }); + } + return applyCont(cont); + } + case "CollisionNode": + case "ArrayNode": + case "IndexedNode": { + const children = node.children; + return visitLazyChildren(children.length, children, 0, f, cont); + } + default: { + return applyCont(cont); + } } - return out; }; -var getInvalidArgumentErrorMessage = (details) => getErrorMessage("Invalid Argument", details); -var getUnsupportedSchemaErrorMessage = (details, path, ast) => getErrorMessage("Unsupported schema", details, path, ast); -var getEquivalenceUnsupportedErrorMessage = (ast, path) => getUnsupportedSchemaErrorMessage("Cannot build an Equivalence", path, ast); -var getSchemaExtendErrorMessage = (x, y, path) => getErrorMessage("Unsupported schema or overlapping types", `cannot extend ${x} with ${y}`, path); -var getSchemaUnsupportedLiteralSpanErrorMessage = (ast) => getErrorMessage("Unsupported template literal span", undefined, undefined, ast); -var getASTUnsupportedSchemaErrorMessage = (ast) => getUnsupportedSchemaErrorMessage(undefined, undefined, ast); -var getASTUnsupportedKeySchemaErrorMessage = (ast) => getErrorMessage("Unsupported key schema", undefined, undefined, ast); -var getASTUnsupportedLiteralErrorMessage = (literal) => getErrorMessage("Unsupported literal", `literal value: ${formatUnknown(literal)}`); -var getASTDuplicateIndexSignatureErrorMessage = (type) => getErrorMessage("Duplicate index signature", `${type} index signature`); -var getASTIndexSignatureParameterErrorMessage = /* @__PURE__ */ getErrorMessage("Unsupported index signature parameter", "An index signature parameter type must be `string`, `symbol`, a template literal type or a refinement of the previous types"); -var getASTRequiredElementFollowinAnOptionalElementErrorMessage = /* @__PURE__ */ getErrorMessage("Invalid element", "A required element cannot follow an optional element. ts(1257)"); -var getASTDuplicatePropertySignatureTransformationErrorMessage = (key) => getErrorMessage("Duplicate property signature transformation", `Duplicate key ${formatUnknown(key)}`); -var getASTUnsupportedRenameSchemaErrorMessage = (ast) => getUnsupportedSchemaErrorMessage(undefined, undefined, ast); -var getASTDuplicatePropertySignatureErrorMessage = (key) => getErrorMessage("Duplicate property signature", `Duplicate key ${formatUnknown(key)}`); - -// node_modules/effect/dist/esm/internal/schema/schemaId.js -var DateFromSelfSchemaId = /* @__PURE__ */ Symbol.for("effect/SchemaId/DateFromSelf"); -var GreaterThanSchemaId = /* @__PURE__ */ Symbol.for("effect/SchemaId/GreaterThan"); -var GreaterThanOrEqualToSchemaId = /* @__PURE__ */ Symbol.for("effect/SchemaId/GreaterThanOrEqualTo"); -var LessThanSchemaId = /* @__PURE__ */ Symbol.for("effect/SchemaId/LessThan"); -var LessThanOrEqualToSchemaId = /* @__PURE__ */ Symbol.for("effect/SchemaId/LessThanOrEqualTo"); -var IntSchemaId = /* @__PURE__ */ Symbol.for("effect/SchemaId/Int"); -var NonNaNSchemaId = /* @__PURE__ */ Symbol.for("effect/SchemaId/NonNaN"); -var FiniteSchemaId = /* @__PURE__ */ Symbol.for("effect/SchemaId/Finite"); -var JsonNumberSchemaId = /* @__PURE__ */ Symbol.for("effect/SchemaId/JsonNumber"); -var BetweenSchemaId = /* @__PURE__ */ Symbol.for("effect/SchemaId/Between"); -var GreaterThanBigintSchemaId = /* @__PURE__ */ Symbol.for("effect/SchemaId/GreaterThanBigint"); -var GreaterThanOrEqualToBigIntSchemaId = /* @__PURE__ */ Symbol.for("effect/SchemaId/GreaterThanOrEqualToBigint"); -var LessThanBigIntSchemaId = /* @__PURE__ */ Symbol.for("effect/SchemaId/LessThanBigint"); -var LessThanOrEqualToBigIntSchemaId = /* @__PURE__ */ Symbol.for("effect/SchemaId/LessThanOrEqualToBigint"); -var BetweenBigintSchemaId = /* @__PURE__ */ Symbol.for("effect/SchemaId/BetweenBigint"); -var MinLengthSchemaId = /* @__PURE__ */ Symbol.for("effect/SchemaId/MinLength"); -var MaxLengthSchemaId = /* @__PURE__ */ Symbol.for("effect/SchemaId/MaxLength"); -var LengthSchemaId = /* @__PURE__ */ Symbol.for("effect/SchemaId/Length"); -var MinItemsSchemaId = /* @__PURE__ */ Symbol.for("effect/SchemaId/MinItems"); -var MaxItemsSchemaId = /* @__PURE__ */ Symbol.for("effect/SchemaId/MaxItems"); -var ItemsCountSchemaId = /* @__PURE__ */ Symbol.for("effect/SchemaId/ItemsCount"); - -// node_modules/effect/dist/esm/Number.js -var Order = number3; -var clamp3 = /* @__PURE__ */ clamp(Order); -var remainder = /* @__PURE__ */ dual(2, (dividend, divisor) => { - const selfDecCount = (dividend.toString().split(".")[1] || "").length; - const divisorDecCount = (divisor.toString().split(".")[1] || "").length; - const decCount = selfDecCount > divisorDecCount ? selfDecCount : divisorDecCount; - const selfInt = parseInt(dividend.toFixed(decCount).replace(".", "")); - const divisorInt = parseInt(divisor.toFixed(decCount).replace(".", "")); - return selfInt % divisorInt / Math.pow(10, decCount); -}); -var parse = (s) => { - if (s === "NaN") { - return some(NaN); +var visitLazyChildren = (len, children, i, f, cont) => { + while (i < len) { + const child = children[i++]; + if (child && !isEmptyNode(child)) { + return visitLazy(child, f, [len, children, i, f, cont]); + } } - if (s === "Infinity") { - return some(Infinity); + return applyCont(cont); +}; +var _empty3 = /* @__PURE__ */ makeImpl(false, 0, /* @__PURE__ */ new EmptyNode, 0); +var empty5 = () => _empty3; +var fromIterable3 = (entries) => { + const map4 = beginMutation(empty5()); + for (const entry of entries) { + set(map4, entry[0], entry[1]); } - if (s === "-Infinity") { - return some(-Infinity); + return endMutation(map4); +}; +var isHashMap = (u) => hasProperty(u, HashMapTypeId); +var isEmpty2 = (self) => self && isEmptyNode(self._root); +var get5 = /* @__PURE__ */ dual(2, (self, key) => getHash(self, key, hash(key))); +var getHash = /* @__PURE__ */ dual(3, (self, key, hash2) => { + let node = self._root; + let shift = 0; + while (true) { + switch (node._tag) { + case "LeafNode": { + return equals(key, node.key) ? node.value : none2(); + } + case "CollisionNode": { + if (hash2 === node.hash) { + const children = node.children; + for (let i = 0, len = children.length;i < len; ++i) { + const child = children[i]; + if ("key" in child && equals(key, child.key)) { + return child.value; + } + } + } + return none2(); + } + case "IndexedNode": { + const frag = hashFragment(shift, hash2); + const bit = toBitmap(frag); + if (node.mask & bit) { + node = node.children[fromBitmap(node.mask, bit)]; + shift += SIZE; + break; + } + return none2(); + } + case "ArrayNode": { + node = node.children[hashFragment(shift, hash2)]; + if (node) { + shift += SIZE; + break; + } + return none2(); + } + default: + return none2(); + } } - if (s.trim() === "") { - return none; +}); +var has = /* @__PURE__ */ dual(2, (self, key) => isSome2(getHash(self, key, hash(key)))); +var set = /* @__PURE__ */ dual(3, (self, key, value) => modifyAt(self, key, () => some2(value))); +var setTree = /* @__PURE__ */ dual(3, (self, newRoot, newSize) => { + if (self._editable) { + self._root = newRoot; + self._size = newSize; + return self; } - const n = Number(s); - return Number.isNaN(n) ? none : some(n); + return newRoot === self._root ? self : makeImpl(self._editable, self._edit, newRoot, newSize); +}); +var keys = (self) => new HashMapIterator(self, (key) => key); +var size = (self) => self._size; +var beginMutation = (self) => makeImpl(true, self._edit + 1, self._root, self._size); +var endMutation = (self) => { + self._editable = false; + return self; }; - -// node_modules/effect/dist/esm/RegExp.js -var escape = (string2) => string2.replace(/[/\\^$*+?.()|[\]{}]/g, "\\$&"); - -// node_modules/effect/dist/esm/SchemaAST.js -var TypeConstructorAnnotationId = /* @__PURE__ */ Symbol.for("effect/annotation/TypeConstructor"); -var BrandAnnotationId = /* @__PURE__ */ Symbol.for("effect/annotation/Brand"); -var SchemaIdAnnotationId = /* @__PURE__ */ Symbol.for("effect/annotation/SchemaId"); -var MessageAnnotationId = /* @__PURE__ */ Symbol.for("effect/annotation/Message"); -var MissingMessageAnnotationId = /* @__PURE__ */ Symbol.for("effect/annotation/MissingMessage"); -var IdentifierAnnotationId = /* @__PURE__ */ Symbol.for("effect/annotation/Identifier"); -var TitleAnnotationId = /* @__PURE__ */ Symbol.for("effect/annotation/Title"); -var AutoTitleAnnotationId = /* @__PURE__ */ Symbol.for("effect/annotation/AutoTitle"); -var DescriptionAnnotationId = /* @__PURE__ */ Symbol.for("effect/annotation/Description"); -var ExamplesAnnotationId = /* @__PURE__ */ Symbol.for("effect/annotation/Examples"); -var DefaultAnnotationId = /* @__PURE__ */ Symbol.for("effect/annotation/Default"); -var JSONSchemaAnnotationId = /* @__PURE__ */ Symbol.for("effect/annotation/JSONSchema"); -var ArbitraryAnnotationId = /* @__PURE__ */ Symbol.for("effect/annotation/Arbitrary"); -var PrettyAnnotationId = /* @__PURE__ */ Symbol.for("effect/annotation/Pretty"); -var EquivalenceAnnotationId = /* @__PURE__ */ Symbol.for("effect/annotation/Equivalence"); -var DocumentationAnnotationId = /* @__PURE__ */ Symbol.for("effect/annotation/Documentation"); -var ConcurrencyAnnotationId = /* @__PURE__ */ Symbol.for("effect/annotation/Concurrency"); -var BatchingAnnotationId = /* @__PURE__ */ Symbol.for("effect/annotation/Batching"); -var ParseIssueTitleAnnotationId = /* @__PURE__ */ Symbol.for("effect/annotation/ParseIssueTitle"); -var ParseOptionsAnnotationId = /* @__PURE__ */ Symbol.for("effect/annotation/ParseOptions"); -var DecodingFallbackAnnotationId = /* @__PURE__ */ Symbol.for("effect/annotation/DecodingFallback"); -var SurrogateAnnotationId = /* @__PURE__ */ Symbol.for("effect/annotation/Surrogate"); -var StableFilterAnnotationId = /* @__PURE__ */ Symbol.for("effect/annotation/StableFilter"); -var getAnnotation = /* @__PURE__ */ dual(2, (annotated, key) => Object.prototype.hasOwnProperty.call(annotated.annotations, key) ? some2(annotated.annotations[key]) : none2()); -var getBrandAnnotation = /* @__PURE__ */ getAnnotation(BrandAnnotationId); -var getMessageAnnotation = /* @__PURE__ */ getAnnotation(MessageAnnotationId); -var getMissingMessageAnnotation = /* @__PURE__ */ getAnnotation(MissingMessageAnnotationId); -var getTitleAnnotation = /* @__PURE__ */ getAnnotation(TitleAnnotationId); -var getAutoTitleAnnotation = /* @__PURE__ */ getAnnotation(AutoTitleAnnotationId); -var getIdentifierAnnotation = /* @__PURE__ */ getAnnotation(IdentifierAnnotationId); -var getDescriptionAnnotation = /* @__PURE__ */ getAnnotation(DescriptionAnnotationId); -var getConcurrencyAnnotation = /* @__PURE__ */ getAnnotation(ConcurrencyAnnotationId); -var getBatchingAnnotation = /* @__PURE__ */ getAnnotation(BatchingAnnotationId); -var getParseIssueTitleAnnotation = /* @__PURE__ */ getAnnotation(ParseIssueTitleAnnotationId); -var getParseOptionsAnnotation = /* @__PURE__ */ getAnnotation(ParseOptionsAnnotationId); -var getDecodingFallbackAnnotation = /* @__PURE__ */ getAnnotation(DecodingFallbackAnnotationId); -var getSurrogateAnnotation = /* @__PURE__ */ getAnnotation(SurrogateAnnotationId); -var getStableFilterAnnotation = /* @__PURE__ */ getAnnotation(StableFilterAnnotationId); -var hasStableFilter = (annotated) => exists(getStableFilterAnnotation(annotated), (b) => b === true); -var JSONIdentifierAnnotationId = /* @__PURE__ */ Symbol.for("effect/annotation/JSONIdentifier"); -var getJSONIdentifierAnnotation = /* @__PURE__ */ getAnnotation(JSONIdentifierAnnotationId); -var getJSONIdentifier = (annotated) => orElse(getJSONIdentifierAnnotation(annotated), () => getIdentifierAnnotation(annotated)); -var ParseJsonSchemaId = /* @__PURE__ */ Symbol.for("effect/schema/ParseJson"); - -class Declaration { - typeParameters; - decodeUnknown; - encodeUnknown; - annotations; - _tag = "Declaration"; - constructor(typeParameters, decodeUnknown, encodeUnknown, annotations = {}) { - this.typeParameters = typeParameters; - this.decodeUnknown = decodeUnknown; - this.encodeUnknown = encodeUnknown; - this.annotations = annotations; - } - toString() { - return getOrElse(getExpected(this), () => ""); +var mutate = /* @__PURE__ */ dual(2, (self, f) => { + const transient = beginMutation(self); + f(transient); + return endMutation(transient); +}); +var modifyAt = /* @__PURE__ */ dual(3, (self, key, f) => modifyHash(self, key, hash(key), f)); +var modifyHash = /* @__PURE__ */ dual(4, (self, key, hash2, f) => { + const size2 = { + value: self._size + }; + const newRoot = self._root.modify(self._editable ? self._edit : NaN, 0, f, hash2, key, size2); + return pipe(self, setTree(newRoot, size2.value)); +}); +var remove2 = /* @__PURE__ */ dual(2, (self, key) => modifyAt(self, key, none2)); +var map4 = /* @__PURE__ */ dual(2, (self, f) => reduce2(self, empty5(), (map5, value, key) => set(map5, key, f(value, key)))); +var forEach = /* @__PURE__ */ dual(2, (self, f) => reduce2(self, undefined, (_, value, key) => f(value, key))); +var reduce2 = /* @__PURE__ */ dual(3, (self, zero2, f) => { + const root = self._root; + if (root._tag === "LeafNode") { + return isSome2(root.value) ? f(zero2, root.value.value, root.key) : zero2; } - toJSON() { - return { - _tag: this._tag, - typeParameters: this.typeParameters.map((ast) => ast.toJSON()), - annotations: toJSONAnnotations(this.annotations) - }; + if (root._tag === "EmptyNode") { + return zero2; } -} -var createASTGuard = (tag) => (ast) => ast._tag === tag; -class Literal { - literal; - annotations; - _tag = "Literal"; - constructor(literal, annotations = {}) { - this.literal = literal; - this.annotations = annotations; + const toVisit = [root.children]; + let children; + while (children = toVisit.pop()) { + for (let i = 0, len = children.length;i < len; ) { + const child = children[i++]; + if (child && !isEmptyNode(child)) { + if (child._tag === "LeafNode") { + if (isSome2(child.value)) { + zero2 = f(zero2, child.value.value, child.key); + } + } else { + toVisit.push(child.children); + } + } + } } + return zero2; +}); + +// node_modules/effect/dist/esm/internal/hashSet.js +var HashSetSymbolKey = "effect/HashSet"; +var HashSetTypeId = /* @__PURE__ */ Symbol.for(HashSetSymbolKey); +var HashSetProto = { + [HashSetTypeId]: HashSetTypeId, + [Symbol.iterator]() { + return keys(this._keyMap); + }, + [symbol]() { + return cached(this, combine(hash(this._keyMap))(hash(HashSetSymbolKey))); + }, + [symbol2](that) { + if (isHashSet(that)) { + return size(this._keyMap) === size(that._keyMap) && equals(this._keyMap, that._keyMap); + } + return false; + }, toString() { - return getOrElse(getExpected(this), () => formatUnknown(this.literal)); - } + return format(this.toJSON()); + }, toJSON() { return { - _tag: this._tag, - literal: isBigInt(this.literal) ? String(this.literal) : this.literal, - annotations: toJSONAnnotations(this.annotations) + _id: "HashSet", + values: Array.from(this).map(toJSON) }; + }, + [NodeInspectSymbol]() { + return this.toJSON(); + }, + pipe() { + return pipeArguments(this, arguments); } -} -var isLiteral = /* @__PURE__ */ createASTGuard("Literal"); -var $null = /* @__PURE__ */ new Literal(null); -class UniqueSymbol { - symbol; - annotations; - _tag = "UniqueSymbol"; - constructor(symbol3, annotations = {}) { - this.symbol = symbol3; - this.annotations = annotations; +}; +var makeImpl2 = (keyMap) => { + const set2 = Object.create(HashSetProto); + set2._keyMap = keyMap; + return set2; +}; +var isHashSet = (u) => hasProperty(u, HashSetTypeId); +var _empty4 = /* @__PURE__ */ makeImpl2(/* @__PURE__ */ empty5()); +var empty6 = () => _empty4; +var fromIterable4 = (elements) => { + const set2 = beginMutation2(empty6()); + for (const value of elements) { + add3(set2, value); } - toString() { - return getOrElse(getExpected(this), () => formatUnknown(this.symbol)); + return endMutation2(set2); +}; +var make9 = (...elements) => { + const set2 = beginMutation2(empty6()); + for (const value of elements) { + add3(set2, value); } - toJSON() { - return { - _tag: this._tag, - symbol: String(this.symbol), - annotations: toJSONAnnotations(this.annotations) - }; + return endMutation2(set2); +}; +var has2 = /* @__PURE__ */ dual(2, (self, value) => has(self._keyMap, value)); +var size2 = (self) => size(self._keyMap); +var beginMutation2 = (self) => makeImpl2(beginMutation(self._keyMap)); +var endMutation2 = (self) => { + self._keyMap._editable = false; + return self; +}; +var mutate2 = /* @__PURE__ */ dual(2, (self, f) => { + const transient = beginMutation2(self); + f(transient); + return endMutation2(transient); +}); +var add3 = /* @__PURE__ */ dual(2, (self, value) => self._keyMap._editable ? (set(value, true)(self._keyMap), self) : makeImpl2(set(value, true)(self._keyMap))); +var remove3 = /* @__PURE__ */ dual(2, (self, value) => self._keyMap._editable ? (remove2(value)(self._keyMap), self) : makeImpl2(remove2(value)(self._keyMap))); +var difference2 = /* @__PURE__ */ dual(2, (self, that) => mutate2(self, (set2) => { + for (const value of that) { + remove3(set2, value); } -} -var isUniqueSymbol = /* @__PURE__ */ createASTGuard("UniqueSymbol"); - -class UndefinedKeyword { - annotations; - _tag = "UndefinedKeyword"; - constructor(annotations = {}) { - this.annotations = annotations; +})); +var union2 = /* @__PURE__ */ dual(2, (self, that) => mutate2(empty6(), (set2) => { + forEach2(self, (value) => add3(set2, value)); + for (const value of that) { + add3(set2, value); } +})); +var forEach2 = /* @__PURE__ */ dual(2, (self, f) => forEach(self._keyMap, (_, k) => f(k))); +var reduce3 = /* @__PURE__ */ dual(3, (self, zero2, f) => reduce2(self._keyMap, zero2, (z, _, a) => f(z, a))); + +// node_modules/effect/dist/esm/HashSet.js +var isHashSet2 = isHashSet; +var empty7 = empty6; +var fromIterable5 = fromIterable4; +var make10 = make9; +var has3 = has2; +var size3 = size2; +var add4 = add3; +var remove4 = remove3; +var difference3 = difference2; +var union3 = union2; +var reduce4 = reduce3; + +// node_modules/effect/dist/esm/MutableRef.js +var TypeId6 = /* @__PURE__ */ Symbol.for("effect/MutableRef"); +var MutableRefProto = { + [TypeId6]: TypeId6, toString() { - return formatKeyword(this); - } + return format(this.toJSON()); + }, toJSON() { return { - _tag: this._tag, - annotations: toJSONAnnotations(this.annotations) + _id: "MutableRef", + current: toJSON(this.current) }; + }, + [NodeInspectSymbol]() { + return this.toJSON(); + }, + pipe() { + return pipeArguments(this, arguments); } -} -var undefinedKeyword = /* @__PURE__ */ new UndefinedKeyword({ - [TitleAnnotationId]: "undefined" -}); -class VoidKeyword { - annotations; - _tag = "VoidKeyword"; - constructor(annotations = {}) { - this.annotations = annotations; - } - toString() { - return formatKeyword(this); - } - toJSON() { - return { - _tag: this._tag, - annotations: toJSONAnnotations(this.annotations) - }; +}; +var make11 = (value) => { + const ref = Object.create(MutableRefProto); + ref.current = value; + return ref; +}; +var compareAndSet = /* @__PURE__ */ dual(3, (self, oldValue, newValue) => { + if (equals(oldValue, self.current)) { + self.current = newValue; + return true; } -} -var voidKeyword = /* @__PURE__ */ new VoidKeyword({ - [TitleAnnotationId]: "void" + return false; }); -class NeverKeyword { - annotations; - _tag = "NeverKeyword"; - constructor(annotations = {}) { - this.annotations = annotations; - } - toString() { - return formatKeyword(this); - } - toJSON() { - return { - _tag: this._tag, - annotations: toJSONAnnotations(this.annotations) - }; - } -} -var neverKeyword = /* @__PURE__ */ new NeverKeyword({ - [TitleAnnotationId]: "never" +var get6 = (self) => self.current; +var set2 = /* @__PURE__ */ dual(2, (self, value) => { + self.current = value; + return self; }); -var isNeverKeyword = /* @__PURE__ */ createASTGuard("NeverKeyword"); -class UnknownKeyword { - annotations; - _tag = "UnknownKeyword"; - constructor(annotations = {}) { - this.annotations = annotations; - } - toString() { - return formatKeyword(this); - } - toJSON() { - return { - _tag: this._tag, - annotations: toJSONAnnotations(this.annotations) - }; +// node_modules/effect/dist/esm/internal/fiberId.js +var FiberIdSymbolKey = "effect/FiberId"; +var FiberIdTypeId = /* @__PURE__ */ Symbol.for(FiberIdSymbolKey); +var OP_NONE = "None"; +var OP_RUNTIME = "Runtime"; +var OP_COMPOSITE = "Composite"; +var emptyHash = /* @__PURE__ */ string(`${FiberIdSymbolKey}-${OP_NONE}`); + +class None { + [FiberIdTypeId] = FiberIdTypeId; + _tag = OP_NONE; + id = -1; + startTimeMillis = -1; + [symbol]() { + return emptyHash; } -} -var unknownKeyword = /* @__PURE__ */ new UnknownKeyword({ - [TitleAnnotationId]: "unknown" -}); -class AnyKeyword { - annotations; - _tag = "AnyKeyword"; - constructor(annotations = {}) { - this.annotations = annotations; + [symbol2](that) { + return isFiberId(that) && that._tag === OP_NONE; } toString() { - return formatKeyword(this); + return format(this.toJSON()); } toJSON() { return { - _tag: this._tag, - annotations: toJSONAnnotations(this.annotations) + _id: "FiberId", + _tag: this._tag }; } -} -var anyKeyword = /* @__PURE__ */ new AnyKeyword({ - [TitleAnnotationId]: "any" -}); -class StringKeyword { - annotations; - _tag = "StringKeyword"; - constructor(annotations = {}) { - this.annotations = annotations; - } - toString() { - return formatKeyword(this); - } - toJSON() { - return { - _tag: this._tag, - annotations: toJSONAnnotations(this.annotations) - }; + [NodeInspectSymbol]() { + return this.toJSON(); } } -var stringKeyword = /* @__PURE__ */ new StringKeyword({ - [TitleAnnotationId]: "string", - [DescriptionAnnotationId]: "a string" -}); -var isStringKeyword = /* @__PURE__ */ createASTGuard("StringKeyword"); -class NumberKeyword { - annotations; - _tag = "NumberKeyword"; - constructor(annotations = {}) { - this.annotations = annotations; - } - toString() { - return formatKeyword(this); +class Runtime { + id; + startTimeMillis; + [FiberIdTypeId] = FiberIdTypeId; + _tag = OP_RUNTIME; + constructor(id, startTimeMillis) { + this.id = id; + this.startTimeMillis = startTimeMillis; } - toJSON() { - return { - _tag: this._tag, - annotations: toJSONAnnotations(this.annotations) - }; + [symbol]() { + return cached(this, string(`${FiberIdSymbolKey}-${this._tag}-${this.id}-${this.startTimeMillis}`)); } -} -var numberKeyword = /* @__PURE__ */ new NumberKeyword({ - [TitleAnnotationId]: "number", - [DescriptionAnnotationId]: "a number" -}); -var isNumberKeyword = /* @__PURE__ */ createASTGuard("NumberKeyword"); - -class BooleanKeyword { - annotations; - _tag = "BooleanKeyword"; - constructor(annotations = {}) { - this.annotations = annotations; + [symbol2](that) { + return isFiberId(that) && that._tag === OP_RUNTIME && this.id === that.id && this.startTimeMillis === that.startTimeMillis; } toString() { - return formatKeyword(this); + return format(this.toJSON()); } toJSON() { return { + _id: "FiberId", _tag: this._tag, - annotations: toJSONAnnotations(this.annotations) + id: this.id, + startTimeMillis: this.startTimeMillis }; } + [NodeInspectSymbol]() { + return this.toJSON(); + } } -var booleanKeyword = /* @__PURE__ */ new BooleanKeyword({ - [TitleAnnotationId]: "boolean", - [DescriptionAnnotationId]: "a boolean" -}); -var isBooleanKeyword = /* @__PURE__ */ createASTGuard("BooleanKeyword"); -class BigIntKeyword { - annotations; - _tag = "BigIntKeyword"; - constructor(annotations = {}) { - this.annotations = annotations; - } - toString() { - return formatKeyword(this); +class Composite { + left; + right; + [FiberIdTypeId] = FiberIdTypeId; + _tag = OP_COMPOSITE; + constructor(left3, right3) { + this.left = left3; + this.right = right3; } - toJSON() { - return { - _tag: this._tag, - annotations: toJSONAnnotations(this.annotations) - }; + _hash; + [symbol]() { + return pipe(string(`${FiberIdSymbolKey}-${this._tag}`), combine(hash(this.left)), combine(hash(this.right)), cached(this)); } -} -var bigIntKeyword = /* @__PURE__ */ new BigIntKeyword({ - [TitleAnnotationId]: "bigint", - [DescriptionAnnotationId]: "a bigint" -}); -class SymbolKeyword { - annotations; - _tag = "SymbolKeyword"; - constructor(annotations = {}) { - this.annotations = annotations; + [symbol2](that) { + return isFiberId(that) && that._tag === OP_COMPOSITE && equals(this.left, that.left) && equals(this.right, that.right); } toString() { - return formatKeyword(this); + return format(this.toJSON()); } toJSON() { return { + _id: "FiberId", _tag: this._tag, - annotations: toJSONAnnotations(this.annotations) + left: toJSON(this.left), + right: toJSON(this.right) }; } -} -var symbolKeyword = /* @__PURE__ */ new SymbolKeyword({ - [TitleAnnotationId]: "symbol", - [DescriptionAnnotationId]: "a symbol" -}); -var isSymbolKeyword = /* @__PURE__ */ createASTGuard("SymbolKeyword"); - -class ObjectKeyword { - annotations; - _tag = "ObjectKeyword"; - constructor(annotations = {}) { - this.annotations = annotations; + [NodeInspectSymbol]() { + return this.toJSON(); } - toString() { - return formatKeyword(this); +} +var none3 = /* @__PURE__ */ new None; +var runtime = (id, startTimeMillis) => { + return new Runtime(id, startTimeMillis); +}; +var composite = (left3, right3) => { + return new Composite(left3, right3); +}; +var isFiberId = (self) => hasProperty(self, FiberIdTypeId); +var combine2 = /* @__PURE__ */ dual(2, (self, that) => { + if (self._tag === OP_NONE) { + return that; } - toJSON() { - return { - _tag: this._tag, - annotations: toJSONAnnotations(this.annotations) - }; + if (that._tag === OP_NONE) { + return self; } -} -var objectKeyword = /* @__PURE__ */ new ObjectKeyword({ - [TitleAnnotationId]: "object", - [DescriptionAnnotationId]: "an object in the TypeScript meaning, i.e. the `object` type" + return new Composite(self, that); }); -class Enums { - enums; - annotations; - _tag = "Enums"; - constructor(enums, annotations = {}) { - this.enums = enums; - this.annotations = annotations; - } - toString() { - return getOrElse(getExpected(this), () => ` JSON.stringify(value)).join(" | ")}>`); - } - toJSON() { - return { - _tag: this._tag, - enums: this.enums, - annotations: toJSONAnnotations(this.annotations) - }; - } -} -var isEnums = /* @__PURE__ */ createASTGuard("Enums"); -var isTemplateLiteralSpanType = (ast) => { - switch (ast._tag) { - case "Literal": - case "NumberKeyword": - case "StringKeyword": - case "TemplateLiteral": - return true; - case "Union": - return ast.types.every(isTemplateLiteralSpanType); +var ids = (self) => { + switch (self._tag) { + case OP_NONE: { + return empty7(); + } + case OP_RUNTIME: { + return make10(self.id); + } + case OP_COMPOSITE: { + return pipe(ids(self.left), union3(ids(self.right))); + } } - return false; }; -var templateLiteralSpanUnionTypeToString = (type) => { - switch (type._tag) { - case "Literal": - return JSON.stringify(String(type.literal)); - case "StringKeyword": - return "string"; - case "NumberKeyword": - return "number"; - case "TemplateLiteral": - return String(type); - case "Union": - return type.types.map(templateLiteralSpanUnionTypeToString).join(" | "); - } +var _fiberCounter = /* @__PURE__ */ globalValue(/* @__PURE__ */ Symbol.for("effect/Fiber/Id/_fiberCounter"), () => make11(0)); +var threadName = (self) => { + const identifiers = Array.from(ids(self)).map((n) => `#${n}`).join(","); + return identifiers; }; -var templateLiteralSpanTypeToString = (type) => { - switch (type._tag) { - case "Literal": - return String(type.literal); - case "StringKeyword": - return "${string}"; - case "NumberKeyword": - return "${number}"; - case "TemplateLiteral": - return "${" + String(type) + "}"; - case "Union": - return "${" + type.types.map(templateLiteralSpanUnionTypeToString).join(" | ") + "}"; - } +var unsafeMake = () => { + const id = get6(_fiberCounter); + pipe(_fiberCounter, set2(id + 1)); + return new Runtime(id, Date.now()); }; -class TemplateLiteralSpan { - literal; - type; - constructor(type, literal) { - this.literal = literal; - if (isTemplateLiteralSpanType(type)) { - this.type = type; - } else { - throw new Error(getSchemaUnsupportedLiteralSpanErrorMessage(type)); - } - } - toString() { - return templateLiteralSpanTypeToString(this.type) + this.literal; - } - toJSON() { - return { - type: this.type.toJSON(), - literal: this.literal - }; - } -} +// node_modules/effect/dist/esm/FiberId.js +var none4 = none3; +var runtime2 = runtime; +var composite2 = composite; +var isFiberId2 = isFiberId; +var combine3 = combine2; +var threadName2 = threadName; +var unsafeMake2 = unsafeMake; -class TemplateLiteral { - head; - spans; - annotations; - _tag = "TemplateLiteral"; - constructor(head2, spans, annotations = {}) { - this.head = head2; - this.spans = spans; - this.annotations = annotations; - } +// node_modules/effect/dist/esm/HashMap.js +var isHashMap2 = isHashMap; +var empty8 = empty5; +var fromIterable6 = fromIterable3; +var isEmpty3 = isEmpty2; +var get7 = get5; +var set3 = set; +var keys2 = keys; +var mutate3 = mutate; +var modifyAt2 = modifyAt; +var map6 = map4; +var forEach3 = forEach; +var reduce5 = reduce2; + +// node_modules/effect/dist/esm/List.js +var TypeId7 = /* @__PURE__ */ Symbol.for("effect/List"); +var toArray2 = (self) => fromIterable(self); +var getEquivalence5 = (isEquivalent) => mapInput(getEquivalence3(isEquivalent), toArray2); +var _equivalence4 = /* @__PURE__ */ getEquivalence5(equals); +var ConsProto = { + [TypeId7]: TypeId7, + _tag: "Cons", toString() { - return getOrElse(getExpected(this), () => formatTemplateLiteral(this)); - } + return format(this.toJSON()); + }, toJSON() { return { - _tag: this._tag, - head: this.head, - spans: this.spans.map((span2) => span2.toJSON()), - annotations: toJSONAnnotations(this.annotations) + _id: "List", + _tag: "Cons", + values: toArray2(this).map(toJSON) }; - } -} -var formatTemplateLiteral = (ast) => "`" + ast.head + ast.spans.map(String).join("") + "`"; -var isTemplateLiteral = /* @__PURE__ */ createASTGuard("TemplateLiteral"); - -class Type { - type; - annotations; - constructor(type, annotations = {}) { - this.type = type; - this.annotations = annotations; - } - toJSON() { + }, + [NodeInspectSymbol]() { + return this.toJSON(); + }, + [symbol2](that) { + return isList(that) && this._tag === that._tag && _equivalence4(this, that); + }, + [symbol]() { + return cached(this, array2(toArray2(this))); + }, + [Symbol.iterator]() { + let done = false; + let self = this; return { - type: this.type.toJSON(), - annotations: toJSONAnnotations(this.annotations) + next() { + if (done) { + return this.return(); + } + if (self._tag === "Nil") { + done = true; + return this.return(); + } + const value = self.head; + self = self.tail; + return { + done, + value + }; + }, + return(value) { + if (!done) { + done = true; + } + return { + done: true, + value + }; + } }; + }, + pipe() { + return pipeArguments(this, arguments); } +}; +var makeCons = (head3, tail) => { + const cons = Object.create(ConsProto); + cons.head = head3; + cons.tail = tail; + return cons; +}; +var NilHash = /* @__PURE__ */ string("Nil"); +var NilProto = { + [TypeId7]: TypeId7, + _tag: "Nil", toString() { - return String(this.type); - } -} - -class OptionalType extends Type { - isOptional; - constructor(type, isOptional, annotations = {}) { - super(type, annotations); - this.isOptional = isOptional; - } + return format(this.toJSON()); + }, toJSON() { return { - type: this.type.toJSON(), - isOptional: this.isOptional, - annotations: toJSONAnnotations(this.annotations) + _id: "List", + _tag: "Nil" }; + }, + [NodeInspectSymbol]() { + return this.toJSON(); + }, + [symbol]() { + return NilHash; + }, + [symbol2](that) { + return isList(that) && this._tag === that._tag; + }, + [Symbol.iterator]() { + return { + next() { + return { + done: true, + value: undefined + }; + } + }; + }, + pipe() { + return pipeArguments(this, arguments); } - toString() { - return String(this.type) + (this.isOptional ? "?" : ""); - } -} -var getRestASTs = (rest) => rest.map((annotatedAST) => annotatedAST.type); - -class TupleType { - elements; - rest; - isReadonly; - annotations; - _tag = "TupleType"; - constructor(elements, rest, isReadonly, annotations = {}) { - this.elements = elements; - this.rest = rest; - this.isReadonly = isReadonly; - this.annotations = annotations; - let hasOptionalElement = false; - let hasIllegalRequiredElement = false; - for (const e of elements) { - if (e.isOptional) { - hasOptionalElement = true; - } else if (hasOptionalElement) { - hasIllegalRequiredElement = true; - break; - } - } - if (hasIllegalRequiredElement || hasOptionalElement && rest.length > 1) { - throw new Error(getASTRequiredElementFollowinAnOptionalElementErrorMessage); +}; +var _Nil = /* @__PURE__ */ Object.create(NilProto); +var isList = (u) => hasProperty(u, TypeId7); +var isNil = (self) => self._tag === "Nil"; +var isCons = (self) => self._tag === "Cons"; +var nil = () => _Nil; +var cons = (head3, tail) => makeCons(head3, tail); +var empty9 = nil; +var of3 = (value) => makeCons(value, _Nil); +var fromIterable7 = (prefix) => { + const iterator = prefix[Symbol.iterator](); + let next; + if ((next = iterator.next()) && !next.done) { + const result = makeCons(next.value, _Nil); + let curr = result; + while ((next = iterator.next()) && !next.done) { + const temp = makeCons(next.value, _Nil); + curr.tail = temp; + curr = temp; } + return result; + } else { + return _Nil; } - toString() { - return getOrElse(getExpected(this), () => formatTuple(this)); - } - toJSON() { - return { - _tag: this._tag, - elements: this.elements.map((e) => e.toJSON()), - rest: this.rest.map((ast) => ast.toJSON()), - isReadonly: this.isReadonly, - annotations: toJSONAnnotations(this.annotations) - }; - } -} -var formatTuple = (ast) => { - const formattedElements = ast.elements.map(String).join(", "); - return matchLeft(ast.rest, { - onEmpty: () => `readonly [${formattedElements}]`, - onNonEmpty: (head2, tail) => { - const formattedHead = String(head2); - const wrappedHead = formattedHead.includes(" | ") ? `(${formattedHead})` : formattedHead; - if (tail.length > 0) { - const formattedTail = tail.map(String).join(", "); - if (ast.elements.length > 0) { - return `readonly [${formattedElements}, ...${wrappedHead}[], ${formattedTail}]`; - } else { - return `readonly [...${wrappedHead}[], ${formattedTail}]`; - } - } else { - if (ast.elements.length > 0) { - return `readonly [${formattedElements}, ...${wrappedHead}[]]`; - } else { - return `ReadonlyArray<${formattedHead}>`; - } - } - } - }); }; -class PropertySignature extends OptionalType { - name; - isReadonly; - constructor(name, type, isOptional, isReadonly, annotations) { - super(type, isOptional, annotations); - this.name = name; - this.isReadonly = isReadonly; - } - toString() { - return (this.isReadonly ? "readonly " : "") + String(this.name) + (this.isOptional ? "?" : "") + ": " + this.type; +var appendAll3 = /* @__PURE__ */ dual(2, (self, that) => prependAll(that, self)); +var prepend3 = /* @__PURE__ */ dual(2, (self, element) => cons(element, self)); +var prependAll = /* @__PURE__ */ dual(2, (self, prefix) => { + if (isNil(self)) { + return prefix; + } else if (isNil(prefix)) { + return self; + } else { + const result = makeCons(prefix.head, self); + let curr = result; + let that = prefix.tail; + while (!isNil(that)) { + const temp = makeCons(that.head, self); + curr.tail = temp; + curr = temp; + that = that.tail; + } + return result; } - toJSON() { - return { - name: String(this.name), - type: this.type.toJSON(), - isOptional: this.isOptional, - isReadonly: this.isReadonly, - annotations: toJSONAnnotations(this.annotations) - }; +}); +var reduce6 = /* @__PURE__ */ dual(3, (self, zero2, f) => { + let acc = zero2; + let these = self; + while (!isNil(these)) { + acc = f(acc, these.head); + these = these.tail; } -} -var isParameter = (ast) => { - switch (ast._tag) { - case "StringKeyword": - case "SymbolKeyword": - case "TemplateLiteral": - return true; - case "Refinement": - return isParameter(ast.from); + return acc; +}); +var reverse3 = (self) => { + let result = empty9(); + let these = self; + while (!isNil(these)) { + result = prepend3(result, these.head); + these = these.tail; } - return false; + return result; }; -class IndexSignature { - type; - isReadonly; - parameter; - constructor(parameter, type, isReadonly) { - this.type = type; - this.isReadonly = isReadonly; - if (isParameter(parameter)) { - this.parameter = parameter; +// node_modules/effect/dist/esm/internal/data.js +var ArrayProto = /* @__PURE__ */ Object.assign(/* @__PURE__ */ Object.create(Array.prototype), { + [symbol]() { + return cached(this, array2(this)); + }, + [symbol2](that) { + if (Array.isArray(that) && this.length === that.length) { + return this.every((v, i) => equals(v, that[i])); } else { - throw new Error(getASTIndexSignatureParameterErrorMessage); + return false; } } - toString() { - return (this.isReadonly ? "readonly " : "") + `[x: ${this.parameter}]: ${this.type}`; - } - toJSON() { - return { - parameter: this.parameter.toJSON(), - type: this.type.toJSON(), - isReadonly: this.isReadonly - }; - } -} - -class TypeLiteral { - annotations; - _tag = "TypeLiteral"; - propertySignatures; - indexSignatures; - constructor(propertySignatures, indexSignatures, annotations = {}) { - this.annotations = annotations; - const keys = {}; - for (let i = 0;i < propertySignatures.length; i++) { - const name = propertySignatures[i].name; - if (Object.prototype.hasOwnProperty.call(keys, name)) { - throw new Error(getASTDuplicatePropertySignatureErrorMessage(name)); - } - keys[name] = null; - } - const parameters = { - string: false, - symbol: false - }; - for (let i = 0;i < indexSignatures.length; i++) { - const encodedParameter = getEncodedParameter(indexSignatures[i].parameter); - if (isStringKeyword(encodedParameter)) { - if (parameters.string) { - throw new Error(getASTDuplicateIndexSignatureErrorMessage("string")); - } - parameters.string = true; - } else if (isSymbolKeyword(encodedParameter)) { - if (parameters.symbol) { - throw new Error(getASTDuplicateIndexSignatureErrorMessage("symbol")); - } - parameters.symbol = true; - } +}); +var Structural = /* @__PURE__ */ function() { + function Structural2(args) { + if (args) { + Object.assign(this, args); } - this.propertySignatures = propertySignatures; - this.indexSignatures = indexSignatures; - } - toString() { - return getOrElse(getExpected(this), () => formatTypeLiteral(this)); - } - toJSON() { - return { - _tag: this._tag, - propertySignatures: this.propertySignatures.map((ps) => ps.toJSON()), - indexSignatures: this.indexSignatures.map((ps) => ps.toJSON()), - annotations: toJSONAnnotations(this.annotations) - }; } + Structural2.prototype = StructuralPrototype; + return Structural2; +}(); +var struct = (as) => Object.assign(Object.create(StructuralPrototype), as); + +// node_modules/effect/dist/esm/internal/differ/contextPatch.js +var ContextPatchTypeId = /* @__PURE__ */ Symbol.for("effect/DifferContextPatch"); +function variance(a) { + return a; } -var formatIndexSignatures = (iss) => iss.map(String).join("; "); -var formatTypeLiteral = (ast) => { - if (ast.propertySignatures.length > 0) { - const pss = ast.propertySignatures.map(String).join("; "); - if (ast.indexSignatures.length > 0) { - return `{ ${pss}; ${formatIndexSignatures(ast.indexSignatures)} }`; - } else { - return `{ ${pss} }`; - } - } else { - if (ast.indexSignatures.length > 0) { - return `{ ${formatIndexSignatures(ast.indexSignatures)} }`; - } else { - return "{}"; - } +var PatchProto = { + ...Structural.prototype, + [ContextPatchTypeId]: { + _Value: variance, + _Patch: variance } }; -var isTypeLiteral = /* @__PURE__ */ createASTGuard("TypeLiteral"); -var sortCandidates = /* @__PURE__ */ sort(/* @__PURE__ */ mapInput2(Order, (ast) => { - switch (ast._tag) { - case "AnyKeyword": - return 0; - case "UnknownKeyword": - return 1; - case "ObjectKeyword": - return 2; - case "StringKeyword": - case "NumberKeyword": - case "BooleanKeyword": - case "BigIntKeyword": - case "SymbolKeyword": - return 3; - } - return 4; -})); -var literalMap = { - string: "StringKeyword", - number: "NumberKeyword", - boolean: "BooleanKeyword", - bigint: "BigIntKeyword" +var EmptyProto = /* @__PURE__ */ Object.assign(/* @__PURE__ */ Object.create(PatchProto), { + _tag: "Empty" +}); +var _empty5 = /* @__PURE__ */ Object.create(EmptyProto); +var empty10 = () => _empty5; +var AndThenProto = /* @__PURE__ */ Object.assign(/* @__PURE__ */ Object.create(PatchProto), { + _tag: "AndThen" +}); +var makeAndThen = (first, second) => { + const o = Object.create(AndThenProto); + o.first = first; + o.second = second; + return o; }; -var flatten2 = (candidates) => flatMap2(candidates, (ast) => isUnion(ast) ? flatten2(ast.types) : [ast]); -var unify = (candidates) => { - const cs = sortCandidates(candidates); - const out = []; - const uniques = {}; - const literals = []; - for (const ast of cs) { - switch (ast._tag) { - case "NeverKeyword": - break; - case "AnyKeyword": - return [anyKeyword]; - case "UnknownKeyword": - return [unknownKeyword]; - case "ObjectKeyword": - case "UndefinedKeyword": - case "VoidKeyword": - case "StringKeyword": - case "NumberKeyword": - case "BooleanKeyword": - case "BigIntKeyword": - case "SymbolKeyword": { - if (!uniques[ast._tag]) { - uniques[ast._tag] = ast; - out.push(ast); - } +var AddServiceProto = /* @__PURE__ */ Object.assign(/* @__PURE__ */ Object.create(PatchProto), { + _tag: "AddService" +}); +var makeAddService = (key, service) => { + const o = Object.create(AddServiceProto); + o.key = key; + o.service = service; + return o; +}; +var RemoveServiceProto = /* @__PURE__ */ Object.assign(/* @__PURE__ */ Object.create(PatchProto), { + _tag: "RemoveService" +}); +var makeRemoveService = (key) => { + const o = Object.create(RemoveServiceProto); + o.key = key; + return o; +}; +var UpdateServiceProto = /* @__PURE__ */ Object.assign(/* @__PURE__ */ Object.create(PatchProto), { + _tag: "UpdateService" +}); +var makeUpdateService = (key, update) => { + const o = Object.create(UpdateServiceProto); + o.key = key; + o.update = update; + return o; +}; +var diff = (oldValue, newValue) => { + const missingServices = new Map(oldValue.unsafeMap); + let patch = empty10(); + for (const [tag, newService] of newValue.unsafeMap.entries()) { + if (missingServices.has(tag)) { + const old = missingServices.get(tag); + missingServices.delete(tag); + if (!equals(old, newService)) { + patch = combine4(makeUpdateService(tag, () => newService))(patch); + } + } else { + missingServices.delete(tag); + patch = combine4(makeAddService(tag, newService))(patch); + } + } + for (const [tag] of missingServices.entries()) { + patch = combine4(makeRemoveService(tag))(patch); + } + return patch; +}; +var combine4 = /* @__PURE__ */ dual(2, (self, that) => makeAndThen(self, that)); +var patch = /* @__PURE__ */ dual(2, (self, context) => { + if (self._tag === "Empty") { + return context; + } + let wasServiceUpdated = false; + let patches = of2(self); + const updatedContext = new Map(context.unsafeMap); + while (isNonEmpty(patches)) { + const head3 = headNonEmpty2(patches); + const tail = tailNonEmpty2(patches); + switch (head3._tag) { + case "Empty": { + patches = tail; break; } - case "Literal": { - const type = typeof ast.literal; - switch (type) { - case "string": - case "number": - case "bigint": - case "boolean": { - const _tag = literalMap[type]; - if (!uniques[_tag] && !literals.includes(ast.literal)) { - literals.push(ast.literal); - out.push(ast); - } - break; - } - case "object": { - if (!literals.includes(ast.literal)) { - literals.push(ast.literal); - out.push(ast); - } - break; - } - } + case "AddService": { + updatedContext.set(head3.key, head3.service); + patches = tail; break; } - case "UniqueSymbol": { - if (!uniques["SymbolKeyword"] && !literals.includes(ast.symbol)) { - literals.push(ast.symbol); - out.push(ast); - } + case "AndThen": { + patches = prepend2(prepend2(tail, head3.second), head3.first); break; } - case "TupleType": { - if (!uniques["ObjectKeyword"]) { - out.push(ast); - } + case "RemoveService": { + updatedContext.delete(head3.key); + patches = tail; break; } - case "TypeLiteral": { - if (ast.propertySignatures.length === 0 && ast.indexSignatures.length === 0) { - if (!uniques["{}"]) { - uniques["{}"] = ast; - out.push(ast); - } - } else if (!uniques["ObjectKeyword"]) { - out.push(ast); - } + case "UpdateService": { + updatedContext.set(head3.key, head3.update(updatedContext.get(head3.key))); + wasServiceUpdated = true; + patches = tail; break; } - default: - out.push(ast); } } - return out; -}; - -class Union { - types; - annotations; - static make = (types, annotations) => { - return isMembers(types) ? new Union(types, annotations) : types.length === 1 ? types[0] : neverKeyword; - }; - static unify = (candidates, annotations) => { - return Union.make(unify(flatten2(candidates)), annotations); - }; - _tag = "Union"; - constructor(types, annotations = {}) { - this.types = types; - this.annotations = annotations; + if (!wasServiceUpdated) { + return makeContext(updatedContext); } - toString() { - return getOrElse(getExpected(this), () => this.types.map(String).join(" | ")); + const map7 = new Map; + for (const [tag] of context.unsafeMap) { + if (updatedContext.has(tag)) { + map7.set(tag, updatedContext.get(tag)); + updatedContext.delete(tag); + } } - toJSON() { - return { - _tag: this._tag, - types: this.types.map((ast) => ast.toJSON()), - annotations: toJSONAnnotations(this.annotations) - }; + for (const [tag, s] of updatedContext) { + map7.set(tag, s); } -} -var mapMembers = (members, f) => members.map(f); -var isMembers = (as) => as.length > 1; -var isUnion = /* @__PURE__ */ createASTGuard("Union"); -var toJSONMemoMap = /* @__PURE__ */ globalValue(/* @__PURE__ */ Symbol.for("effect/Schema/AST/toJSONMemoMap"), () => new WeakMap); + return makeContext(map7); +}); -class Suspend { - f; - annotations; - _tag = "Suspend"; - constructor(f, annotations = {}) { - this.f = f; - this.annotations = annotations; - this.f = memoizeThunk(f); - } - toString() { - return getExpected(this).pipe(orElse(() => flatMap(liftThrowable(this.f)(), (ast) => getExpected(ast))), getOrElse(() => "")); - } - toJSON() { - const ast = this.f(); - let out = toJSONMemoMap.get(ast); - if (out) { - return out; - } - toJSONMemoMap.set(ast, { - _tag: this._tag - }); - out = { - _tag: this._tag, - ast: ast.toJSON(), - annotations: toJSONAnnotations(this.annotations) - }; - toJSONMemoMap.set(ast, out); - return out; - } +// node_modules/effect/dist/esm/internal/differ/hashSetPatch.js +var HashSetPatchTypeId = /* @__PURE__ */ Symbol.for("effect/DifferHashSetPatch"); +function variance2(a) { + return a; } -class Refinement { - from; - filter; - annotations; - _tag = "Refinement"; - constructor(from, filter2, annotations = {}) { - this.from = from; - this.filter = filter2; - this.annotations = annotations; - } - toString() { - return getIdentifierAnnotation(this).pipe(getOrElse(() => match2(getOrElseExpected(this), { - onNone: () => `{ ${this.from} | filter }`, - onSome: (expected) => isRefinement(this.from) ? String(this.from) + " & " + expected : expected - }))); - } - toJSON() { - return { - _tag: this._tag, - from: this.from.toJSON(), - annotations: toJSONAnnotations(this.annotations) - }; +var PatchProto2 = { + ...Structural.prototype, + [HashSetPatchTypeId]: { + _Value: variance2, + _Key: variance2, + _Patch: variance2 } -} -var isRefinement = /* @__PURE__ */ createASTGuard("Refinement"); -var defaultParseOption = {}; - -class Transformation { - from; - to; - transformation; - annotations; - _tag = "Transformation"; - constructor(from, to, transformation, annotations = {}) { - this.from = from; - this.to = to; - this.transformation = transformation; - this.annotations = annotations; - } - toString() { - return getOrElse(getExpected(this), () => `(${String(this.from)} <-> ${String(this.to)})`); - } - toJSON() { - return { - _tag: this._tag, - from: this.from.toJSON(), - to: this.to.toJSON(), - annotations: toJSONAnnotations(this.annotations) - }; - } -} -var isTransformation = /* @__PURE__ */ createASTGuard("Transformation"); - -class FinalTransformation { - decode; - encode; - _tag = "FinalTransformation"; - constructor(decode, encode) { - this.decode = decode; - this.encode = encode; - } -} -var createTransformationGuard = (tag) => (ast) => ast._tag === tag; -class ComposeTransformation { - _tag = "ComposeTransformation"; -} -var composeTransformation = /* @__PURE__ */ new ComposeTransformation; -class PropertySignatureTransformation { - from; - to; - decode; - encode; - constructor(from, to, decode, encode) { - this.from = from; - this.to = to; - this.decode = decode; - this.encode = encode; +}; +var EmptyProto2 = /* @__PURE__ */ Object.assign(/* @__PURE__ */ Object.create(PatchProto2), { + _tag: "Empty" +}); +var _empty6 = /* @__PURE__ */ Object.create(EmptyProto2); +var empty11 = () => _empty6; +var AndThenProto2 = /* @__PURE__ */ Object.assign(/* @__PURE__ */ Object.create(PatchProto2), { + _tag: "AndThen" +}); +var makeAndThen2 = (first, second) => { + const o = Object.create(AndThenProto2); + o.first = first; + o.second = second; + return o; +}; +var AddProto = /* @__PURE__ */ Object.assign(/* @__PURE__ */ Object.create(PatchProto2), { + _tag: "Add" +}); +var makeAdd = (value) => { + const o = Object.create(AddProto); + o.value = value; + return o; +}; +var RemoveProto = /* @__PURE__ */ Object.assign(/* @__PURE__ */ Object.create(PatchProto2), { + _tag: "Remove" +}); +var makeRemove = (value) => { + const o = Object.create(RemoveProto); + o.value = value; + return o; +}; +var diff2 = (oldValue, newValue) => { + const [removed, patch2] = reduce4([oldValue, empty11()], ([set4, patch3], value) => { + if (has3(value)(set4)) { + return [remove4(value)(set4), patch3]; + } + return [set4, combine5(makeAdd(value))(patch3)]; + })(newValue); + return reduce4(patch2, (patch3, value) => combine5(makeRemove(value))(patch3))(removed); +}; +var combine5 = /* @__PURE__ */ dual(2, (self, that) => makeAndThen2(self, that)); +var patch2 = /* @__PURE__ */ dual(2, (self, oldValue) => { + if (self._tag === "Empty") { + return oldValue; } -} -var isRenamingPropertySignatureTransformation = (t) => t.decode === identity && t.encode === identity; - -class TypeLiteralTransformation { - propertySignatureTransformations; - _tag = "TypeLiteralTransformation"; - constructor(propertySignatureTransformations) { - this.propertySignatureTransformations = propertySignatureTransformations; - const fromKeys = {}; - const toKeys = {}; - for (const pst of propertySignatureTransformations) { - const from = pst.from; - if (fromKeys[from]) { - throw new Error(getASTDuplicatePropertySignatureTransformationErrorMessage(from)); + let set4 = oldValue; + let patches = of2(self); + while (isNonEmpty(patches)) { + const head3 = headNonEmpty2(patches); + const tail = tailNonEmpty2(patches); + switch (head3._tag) { + case "Empty": { + patches = tail; + break; } - fromKeys[from] = true; - const to = pst.to; - if (toKeys[to]) { - throw new Error(getASTDuplicatePropertySignatureTransformationErrorMessage(to)); + case "AndThen": { + patches = prepend2(head3.first)(prepend2(head3.second)(tail)); + break; + } + case "Add": { + set4 = add4(head3.value)(set4); + patches = tail; + break; + } + case "Remove": { + set4 = remove4(head3.value)(set4); + patches = tail; } - toKeys[to] = true; } } + return set4; +}); + +// node_modules/effect/dist/esm/internal/differ/readonlyArrayPatch.js +var ReadonlyArrayPatchTypeId = /* @__PURE__ */ Symbol.for("effect/DifferReadonlyArrayPatch"); +function variance3(a) { + return a; } -var isTypeLiteralTransformation = /* @__PURE__ */ createTransformationGuard("TypeLiteralTransformation"); -var annotations = (ast, overrides) => { - const d = Object.getOwnPropertyDescriptors(ast); - const base = { - ...ast.annotations - }; - delete base[IdentifierAnnotationId]; - const value = { - ...base, - ...overrides - }; - const surrogate = getSurrogateAnnotation(ast); - if (isSome2(surrogate)) { - value[SurrogateAnnotationId] = annotations(surrogate.value, overrides); +var PatchProto3 = { + ...Structural.prototype, + [ReadonlyArrayPatchTypeId]: { + _Value: variance3, + _Patch: variance3 } - d.annotations.value = value; - return Object.create(Object.getPrototypeOf(ast), d); }; -var keyof = (ast) => Union.unify(_keyof(ast)); -var STRING_KEYWORD_PATTERN = "[\\s\\S]*?"; -var NUMBER_KEYWORD_PATTERN = "[+-]?\\d*\\.?\\d+(?:[Ee][+-]?\\d+)?"; -var getTemplateLiteralSpanTypePattern = (type, capture) => { - switch (type._tag) { - case "Literal": - return escape(String(type.literal)); - case "StringKeyword": - return STRING_KEYWORD_PATTERN; - case "NumberKeyword": - return NUMBER_KEYWORD_PATTERN; - case "TemplateLiteral": - return getTemplateLiteralPattern(type, capture, false); - case "Union": - return type.types.map((type2) => getTemplateLiteralSpanTypePattern(type2, capture)).join("|"); - } +var EmptyProto3 = /* @__PURE__ */ Object.assign(/* @__PURE__ */ Object.create(PatchProto3), { + _tag: "Empty" +}); +var _empty7 = /* @__PURE__ */ Object.create(EmptyProto3); +var empty12 = () => _empty7; +var AndThenProto3 = /* @__PURE__ */ Object.assign(/* @__PURE__ */ Object.create(PatchProto3), { + _tag: "AndThen" +}); +var makeAndThen3 = (first, second) => { + const o = Object.create(AndThenProto3); + o.first = first; + o.second = second; + return o; }; -var handleTemplateLiteralSpanTypeParens = (type, s, capture, top) => { - if (isUnion(type)) { - if (capture && !top) { - return `(?:${s})`; - } - } else if (!capture || !top) { - return s; - } - return `(${s})`; +var AppendProto = /* @__PURE__ */ Object.assign(/* @__PURE__ */ Object.create(PatchProto3), { + _tag: "Append" +}); +var makeAppend = (values3) => { + const o = Object.create(AppendProto); + o.values = values3; + return o; }; -var getTemplateLiteralPattern = (ast, capture, top) => { - let pattern = ``; - if (ast.head !== "") { - const head2 = escape(ast.head); - pattern += capture && top ? `(${head2})` : head2; - } - for (const span2 of ast.spans) { - const spanPattern = getTemplateLiteralSpanTypePattern(span2.type, capture); - pattern += handleTemplateLiteralSpanTypeParens(span2.type, spanPattern, capture, top); - if (span2.literal !== "") { - const literal = escape(span2.literal); - pattern += capture && top ? `(${literal})` : literal; +var SliceProto = /* @__PURE__ */ Object.assign(/* @__PURE__ */ Object.create(PatchProto3), { + _tag: "Slice" +}); +var makeSlice = (from, until) => { + const o = Object.create(SliceProto); + o.from = from; + o.until = until; + return o; +}; +var UpdateProto = /* @__PURE__ */ Object.assign(/* @__PURE__ */ Object.create(PatchProto3), { + _tag: "Update" +}); +var makeUpdate = (index, patch3) => { + const o = Object.create(UpdateProto); + o.index = index; + o.patch = patch3; + return o; +}; +var diff3 = (options) => { + let i = 0; + let patch3 = empty12(); + while (i < options.oldValue.length && i < options.newValue.length) { + const oldElement = options.oldValue[i]; + const newElement = options.newValue[i]; + const valuePatch = options.differ.diff(oldElement, newElement); + if (!equals(valuePatch, options.differ.empty)) { + patch3 = combine6(patch3, makeUpdate(i, valuePatch)); } + i = i + 1; } - return pattern; -}; -var getTemplateLiteralRegExp = (ast) => new RegExp(`^${getTemplateLiteralPattern(ast, false, true)}$`); -var getTemplateLiteralCapturingRegExp = (ast) => new RegExp(`^${getTemplateLiteralPattern(ast, true, true)}$`); -var getIndexSignatures = (ast) => { - const annotation = getSurrogateAnnotation(ast); - if (isSome2(annotation)) { - return getIndexSignatures(annotation.value); + if (i < options.oldValue.length) { + patch3 = combine6(patch3, makeSlice(0, i)); } - switch (ast._tag) { - case "TypeLiteral": - return ast.indexSignatures.slice(); - case "Suspend": - return getIndexSignatures(ast.f()); - case "Refinement": - return getIndexSignatures(ast.from); - case "Transformation": - return getIndexSignatures(ast.to); + if (i < options.newValue.length) { + patch3 = combine6(patch3, makeAppend(drop(i)(options.newValue))); } - return []; + return patch3; }; -var getNumberIndexedAccess = (ast) => { - switch (ast._tag) { - case "TupleType": { - let hasOptional = false; - let out = []; - for (const e of ast.elements) { - if (e.isOptional) { - hasOptional = true; - } - out.push(e.type); - } - if (hasOptional) { - out.push(undefinedKeyword); - } - out = out.concat(getRestASTs(ast.rest)); - return Union.make(out); - } - case "Refinement": - return getNumberIndexedAccess(ast.from); - case "Union": - return Union.make(ast.types.map(getNumberIndexedAccess)); - case "Suspend": - return getNumberIndexedAccess(ast.f()); - } - throw new Error(getASTUnsupportedSchemaErrorMessage(ast)); -}; -var getTypeLiteralPropertySignature = (ast, name) => { - const ops = findFirst2(ast.propertySignatures, (ps) => ps.name === name); - if (isSome2(ops)) { - return ops.value; - } - if (isString(name)) { - let out = undefined; - for (const is of ast.indexSignatures) { - const encodedParameter = getEncodedParameter(is.parameter); - switch (encodedParameter._tag) { - case "TemplateLiteral": { - const regex = getTemplateLiteralRegExp(encodedParameter); - if (regex.test(name)) { - return new PropertySignature(name, is.type, false, true); - } - break; - } - case "StringKeyword": { - if (out === undefined) { - out = new PropertySignature(name, is.type, false, true); - } - } - } - } - if (out) { - return out; - } - } else if (isSymbol(name)) { - for (const is of ast.indexSignatures) { - const encodedParameter = getEncodedParameter(is.parameter); - if (isSymbolKeyword(encodedParameter)) { - return new PropertySignature(name, is.type, false, true); - } - } - } -}; -var getPropertyKeyIndexedAccess = (ast, name) => { - const annotation = getSurrogateAnnotation(ast); - if (isSome2(annotation)) { - return getPropertyKeyIndexedAccess(annotation.value, name); - } - switch (ast._tag) { - case "TypeLiteral": { - const ps = getTypeLiteralPropertySignature(ast, name); - if (ps) { - return ps; - } - break; - } - case "Union": - return new PropertySignature(name, Union.make(ast.types.map((ast2) => getPropertyKeyIndexedAccess(ast2, name).type)), false, true); - case "Suspend": - return getPropertyKeyIndexedAccess(ast.f(), name); - case "Refinement": - return getPropertyKeyIndexedAccess(ast.from, name); - case "Transformation": - return getPropertyKeyIndexedAccess(ast.to, name); - } - throw new Error(getASTUnsupportedSchemaErrorMessage(ast)); -}; -var getPropertyKeys = (ast) => { - const annotation = getSurrogateAnnotation(ast); - if (isSome2(annotation)) { - return getPropertyKeys(annotation.value); - } - switch (ast._tag) { - case "TypeLiteral": - return ast.propertySignatures.map((ps) => ps.name); - case "Union": - return ast.types.slice(1).reduce((out, ast2) => intersection(out, getPropertyKeys(ast2)), getPropertyKeys(ast.types[0])); - case "Suspend": - return getPropertyKeys(ast.f()); - case "Refinement": - return getPropertyKeys(ast.from); - case "Transformation": - return getPropertyKeys(ast.to); +var combine6 = /* @__PURE__ */ dual(2, (self, that) => makeAndThen3(self, that)); +var patch3 = /* @__PURE__ */ dual(3, (self, oldValue, differ) => { + if (self._tag === "Empty") { + return oldValue; } - return []; -}; -var record = (key, value) => { - const propertySignatures = []; - const indexSignatures = []; - const go = (key2) => { - switch (key2._tag) { - case "NeverKeyword": - break; - case "StringKeyword": - case "SymbolKeyword": - case "TemplateLiteral": - case "Refinement": - indexSignatures.push(new IndexSignature(key2, value, true)); + let readonlyArray = oldValue.slice(); + let patches = of(self); + while (isNonEmptyArray2(patches)) { + const head3 = headNonEmpty(patches); + const tail = tailNonEmpty(patches); + switch (head3._tag) { + case "Empty": { + patches = tail; break; - case "Literal": - if (isString(key2.literal) || isNumber(key2.literal)) { - propertySignatures.push(new PropertySignature(key2.literal, value, false, true)); - } else { - throw new Error(getASTUnsupportedLiteralErrorMessage(key2.literal)); - } + } + case "AndThen": { + tail.unshift(head3.first, head3.second); + patches = tail; break; - case "Enums": { - for (const [_, name] of key2.enums) { - propertySignatures.push(new PropertySignature(name, value, false, true)); + } + case "Append": { + for (const value of head3.values) { + readonlyArray.push(value); } + patches = tail; break; } - case "UniqueSymbol": - propertySignatures.push(new PropertySignature(key2.symbol, value, false, true)); - break; - case "Union": - key2.types.forEach(go); + case "Slice": { + readonlyArray = readonlyArray.slice(head3.from, head3.until); + patches = tail; break; - default: - throw new Error(getASTUnsupportedKeySchemaErrorMessage(key2)); - } - }; - go(key); - return { - propertySignatures, - indexSignatures - }; -}; -var pick = (ast, keys) => { - const annotation = getSurrogateAnnotation(ast); - if (isSome2(annotation)) { - return pick(annotation.value, keys); - } - switch (ast._tag) { - case "TypeLiteral": { - const pss = []; - const names = {}; - for (const ps of ast.propertySignatures) { - names[ps.name] = null; - if (keys.includes(ps.name)) { - pss.push(ps); - } - } - for (const key of keys) { - if (!(key in names)) { - const ps = getTypeLiteralPropertySignature(ast, key); - if (ps) { - pss.push(ps); - } - } } - return new TypeLiteral(pss, []); - } - case "Union": - return new TypeLiteral(keys.map((name) => getPropertyKeyIndexedAccess(ast, name)), []); - case "Suspend": - return pick(ast.f(), keys); - case "Refinement": - return pick(ast.from, keys); - case "Transformation": { - switch (ast.transformation._tag) { - case "ComposeTransformation": - return new Transformation(pick(ast.from, keys), pick(ast.to, keys), composeTransformation); - case "TypeLiteralTransformation": { - const ts = []; - const fromKeys = []; - for (const k of keys) { - const t = ast.transformation.propertySignatureTransformations.find((t2) => t2.to === k); - if (t) { - ts.push(t); - fromKeys.push(t.from); - } else { - fromKeys.push(k); - } - } - return isNonEmptyReadonlyArray(ts) ? new Transformation(pick(ast.from, fromKeys), pick(ast.to, keys), new TypeLiteralTransformation(ts)) : pick(ast.from, fromKeys); - } + case "Update": { + readonlyArray[head3.index] = differ.patch(head3.patch, readonlyArray[head3.index]); + patches = tail; + break; } } } - throw new Error(getASTUnsupportedSchemaErrorMessage(ast)); -}; -var omit = (ast, keys) => { - let indexSignatures = getIndexSignatures(ast); - if (indexSignatures.length > 0) { - if (indexSignatures.some((is) => isStringKeyword(getEncodedParameter(is.parameter)))) { - indexSignatures = indexSignatures.filter((is) => !isTemplateLiteral(getEncodedParameter(is.parameter))); - } - return new TypeLiteral([], indexSignatures); + return readonlyArray; +}); + +// node_modules/effect/dist/esm/internal/differ.js +var DifferTypeId = /* @__PURE__ */ Symbol.for("effect/Differ"); +var DifferProto = { + [DifferTypeId]: { + _P: identity, + _V: identity + }, + pipe() { + return pipeArguments(this, arguments); } - return pick(ast, getPropertyKeys(ast).filter((name) => !keys.includes(name))); }; -var orUndefined = (ast) => Union.make([ast, undefinedKeyword]); -var partial = (ast, options) => { - const exact = options?.exact === true; - switch (ast._tag) { - case "TupleType": - return new TupleType(ast.elements.map((e) => new OptionalType(exact ? e.type : orUndefined(e.type), true)), match3(ast.rest, { - onEmpty: () => ast.rest, - onNonEmpty: (rest) => [new Type(Union.make([...getRestASTs(rest), undefinedKeyword]))] - }), ast.isReadonly); - case "TypeLiteral": - return new TypeLiteral(ast.propertySignatures.map((ps) => new PropertySignature(ps.name, exact ? ps.type : orUndefined(ps.type), true, ps.isReadonly, ps.annotations)), ast.indexSignatures.map((is) => new IndexSignature(is.parameter, orUndefined(is.type), is.isReadonly))); - case "Union": - return Union.make(ast.types.map((member) => partial(member, options))); - case "Suspend": - return new Suspend(() => partial(ast.f(), options)); - case "Declaration": - case "Refinement": - throw new Error(getASTUnsupportedSchemaErrorMessage(ast)); - case "Transformation": { - if (isTypeLiteralTransformation(ast.transformation) && ast.transformation.propertySignatureTransformations.every(isRenamingPropertySignatureTransformation)) { - return new Transformation(partial(ast.from, options), partial(ast.to, options), ast.transformation); - } - throw new Error(getASTUnsupportedSchemaErrorMessage(ast)); - } - } - return ast; +var make14 = (params) => { + const differ = Object.create(DifferProto); + differ.empty = params.empty; + differ.diff = params.diff; + differ.combine = params.combine; + differ.patch = params.patch; + return differ; }; -var required = (ast) => { - switch (ast._tag) { - case "TupleType": - return new TupleType(ast.elements.map((e) => new OptionalType(e.type, false)), ast.rest, ast.isReadonly); - case "TypeLiteral": - return new TypeLiteral(ast.propertySignatures.map((f) => new PropertySignature(f.name, f.type, false, f.isReadonly, f.annotations)), ast.indexSignatures); - case "Union": - return Union.make(ast.types.map((member) => required(member))); - case "Suspend": - return new Suspend(() => required(ast.f())); - case "Declaration": - case "Refinement": - throw new Error(getASTUnsupportedSchemaErrorMessage(ast)); - case "Transformation": { - if (isTypeLiteralTransformation(ast.transformation) && ast.transformation.propertySignatureTransformations.every(isRenamingPropertySignatureTransformation)) { - return new Transformation(required(ast.from), required(ast.to), ast.transformation); - } - throw new Error(getASTUnsupportedSchemaErrorMessage(ast)); - } - } - return ast; -}; -var mutable = (ast) => { - switch (ast._tag) { - case "TupleType": - return ast.isReadonly === false ? ast : new TupleType(ast.elements, ast.rest, false, ast.annotations); - case "TypeLiteral": { - const propertySignatures = changeMap(ast.propertySignatures, (ps) => ps.isReadonly === false ? ps : new PropertySignature(ps.name, ps.type, ps.isOptional, false, ps.annotations)); - const indexSignatures = changeMap(ast.indexSignatures, (is) => is.isReadonly === false ? is : new IndexSignature(is.parameter, is.type, false)); - return propertySignatures === ast.propertySignatures && indexSignatures === ast.indexSignatures ? ast : new TypeLiteral(propertySignatures, indexSignatures, ast.annotations); +var environment = () => make14({ + empty: empty10(), + combine: (first, second) => combine4(second)(first), + diff: (oldValue, newValue) => diff(oldValue, newValue), + patch: (patch4, oldValue) => patch(oldValue)(patch4) +}); +var hashSet = () => make14({ + empty: empty11(), + combine: (first, second) => combine5(second)(first), + diff: (oldValue, newValue) => diff2(oldValue, newValue), + patch: (patch4, oldValue) => patch2(oldValue)(patch4) +}); +var readonlyArray = (differ) => make14({ + empty: empty12(), + combine: (first, second) => combine6(first, second), + diff: (oldValue, newValue) => diff3({ + oldValue, + newValue, + differ + }), + patch: (patch4, oldValue) => patch3(patch4, oldValue, differ) +}); +var update = () => updateWith((_, a) => a); +var updateWith = (f) => make14({ + empty: identity, + combine: (first, second) => { + if (first === identity) { + return second; } - case "Union": { - const types = changeMap(ast.types, mutable); - return types === ast.types ? ast : Union.make(types, ast.annotations); + if (second === identity) { + return first; } - case "Suspend": - return new Suspend(() => mutable(ast.f()), ast.annotations); - case "Refinement": { - const from = mutable(ast.from); - return from === ast.from ? ast : new Refinement(from, ast.filter, ast.annotations); + return (a) => second(first(a)); + }, + diff: (oldValue, newValue) => { + if (equals(oldValue, newValue)) { + return identity; } - case "Transformation": { - const from = mutable(ast.from); - const to = mutable(ast.to); - return from === ast.from && to === ast.to ? ast : new Transformation(from, to, ast.transformation, ast.annotations); + return constant(newValue); + }, + patch: (patch4, oldValue) => f(oldValue, patch4(oldValue)) +}); + +// node_modules/effect/dist/esm/internal/runtimeFlagsPatch.js +var BIT_MASK = 255; +var BIT_SHIFT = 8; +var active = (patch4) => patch4 & BIT_MASK; +var enabled = (patch4) => patch4 >> BIT_SHIFT & BIT_MASK; +var make15 = (active2, enabled2) => (active2 & BIT_MASK) + ((enabled2 & active2 & BIT_MASK) << BIT_SHIFT); +var empty13 = /* @__PURE__ */ make15(0, 0); +var enable = (flag) => make15(flag, flag); +var disable = (flag) => make15(flag, 0); +var exclude = /* @__PURE__ */ dual(2, (self, flag) => make15(active(self) & ~flag, enabled(self))); +var andThen = /* @__PURE__ */ dual(2, (self, that) => self | that); +var invert = (n) => ~n >>> 0 & BIT_MASK; + +// node_modules/effect/dist/esm/internal/runtimeFlags.js +var None2 = 0; +var Interruption = 1 << 0; +var OpSupervision = 1 << 1; +var RuntimeMetrics = 1 << 2; +var WindDown = 1 << 4; +var CooperativeYielding = 1 << 5; +var cooperativeYielding = (self) => isEnabled(self, CooperativeYielding); +var disable2 = /* @__PURE__ */ dual(2, (self, flag) => self & ~flag); +var enable2 = /* @__PURE__ */ dual(2, (self, flag) => self | flag); +var interruptible = (self) => interruption(self) && !windDown(self); +var interruption = (self) => isEnabled(self, Interruption); +var isEnabled = /* @__PURE__ */ dual(2, (self, flag) => (self & flag) !== 0); +var make16 = (...flags) => flags.reduce((a, b) => a | b, 0); +var none5 = /* @__PURE__ */ make16(None2); +var runtimeMetrics = (self) => isEnabled(self, RuntimeMetrics); +var windDown = (self) => isEnabled(self, WindDown); +var diff4 = /* @__PURE__ */ dual(2, (self, that) => make15(self ^ that, that)); +var patch4 = /* @__PURE__ */ dual(2, (self, patch5) => self & (invert(active(patch5)) | enabled(patch5)) | active(patch5) & enabled(patch5)); +var differ = /* @__PURE__ */ make14({ + empty: empty13, + diff: (oldValue, newValue) => diff4(oldValue, newValue), + combine: (first, second) => andThen(second)(first), + patch: (_patch, oldValue) => patch4(oldValue, _patch) +}); + +// node_modules/effect/dist/esm/RuntimeFlagsPatch.js +var empty14 = empty13; +var enable3 = enable; +var disable3 = disable; +var exclude2 = exclude; + +// node_modules/effect/dist/esm/internal/blockedRequests.js +var empty15 = { + _tag: "Empty" +}; +var par = (self, that) => ({ + _tag: "Par", + left: self, + right: that +}); +var seq = (self, that) => ({ + _tag: "Seq", + left: self, + right: that +}); +var single = (dataSource, blockedRequest) => ({ + _tag: "Single", + dataSource, + blockedRequest +}); +var flatten2 = (self) => { + let current = of3(self); + let updated = empty9(); + while (true) { + const [parallel, sequential] = reduce6(current, [parallelCollectionEmpty(), empty9()], ([parallel2, sequential2], blockedRequest) => { + const [par2, seq2] = step(blockedRequest); + return [parallelCollectionCombine(parallel2, par2), appendAll3(sequential2, seq2)]; + }); + updated = merge4(updated, parallel); + if (isNil(sequential)) { + return reverse3(updated); } + current = sequential; } - return ast; + throw new Error("BUG: BlockedRequests.flatten - please report an issue at https://github.com/Effect-TS/effect/issues"); }; -var pickAnnotations = (annotationIds) => (annotated) => { - let out = undefined; - for (const id of annotationIds) { - if (Object.prototype.hasOwnProperty.call(annotated.annotations, id)) { - if (out === undefined) { - out = {}; +var step = (requests) => { + let current = requests; + let parallel = parallelCollectionEmpty(); + let stack = empty9(); + let sequential = empty9(); + while (true) { + switch (current._tag) { + case "Empty": { + if (isNil(stack)) { + return [parallel, sequential]; + } + current = stack.head; + stack = stack.tail; + break; + } + case "Par": { + stack = cons(current.right, stack); + current = current.left; + break; + } + case "Seq": { + const left3 = current.left; + const right3 = current.right; + switch (left3._tag) { + case "Empty": { + current = right3; + break; + } + case "Par": { + const l = left3.left; + const r = left3.right; + current = par(seq(l, right3), seq(r, right3)); + break; + } + case "Seq": { + const l = left3.left; + const r = left3.right; + current = seq(l, seq(r, right3)); + break; + } + case "Single": { + current = left3; + sequential = cons(right3, sequential); + break; + } + } + break; + } + case "Single": { + parallel = parallelCollectionAdd(parallel, current); + if (isNil(stack)) { + return [parallel, sequential]; + } + current = stack.head; + stack = stack.tail; + break; } - out[id] = annotated.annotations[id]; } } - return out; + throw new Error("BUG: BlockedRequests.step - please report an issue at https://github.com/Effect-TS/effect/issues"); }; -var omitAnnotations = (annotationIds) => (annotated) => { - const out = { - ...annotated.annotations - }; - for (const id of annotationIds) { - delete out[id]; +var merge4 = (sequential, parallel) => { + if (isNil(sequential)) { + return of3(parallelCollectionToSequentialCollection(parallel)); } - return out; -}; -var preserveTransformationAnnotations = /* @__PURE__ */ pickAnnotations([ExamplesAnnotationId, DefaultAnnotationId, JSONSchemaAnnotationId, ArbitraryAnnotationId, PrettyAnnotationId, EquivalenceAnnotationId]); -var typeAST = (ast) => { - switch (ast._tag) { - case "Declaration": { - const typeParameters = changeMap(ast.typeParameters, typeAST); - return typeParameters === ast.typeParameters ? ast : new Declaration(typeParameters, ast.decodeUnknown, ast.encodeUnknown, ast.annotations); - } - case "TupleType": { - const elements = changeMap(ast.elements, (e) => { - const type = typeAST(e.type); - return type === e.type ? e : new OptionalType(type, e.isOptional); - }); - const restASTs = getRestASTs(ast.rest); - const rest = changeMap(restASTs, typeAST); - return elements === ast.elements && rest === restASTs ? ast : new TupleType(elements, rest.map((type) => new Type(type)), ast.isReadonly, ast.annotations); - } - case "TypeLiteral": { - const propertySignatures = changeMap(ast.propertySignatures, (p) => { - const type = typeAST(p.type); - return type === p.type ? p : new PropertySignature(p.name, type, p.isOptional, p.isReadonly); - }); - const indexSignatures = changeMap(ast.indexSignatures, (is) => { - const type = typeAST(is.type); - return type === is.type ? is : new IndexSignature(is.parameter, type, is.isReadonly); - }); - return propertySignatures === ast.propertySignatures && indexSignatures === ast.indexSignatures ? ast : new TypeLiteral(propertySignatures, indexSignatures, ast.annotations); - } - case "Union": { - const types = changeMap(ast.types, typeAST); - return types === ast.types ? ast : Union.make(types, ast.annotations); - } - case "Suspend": - return new Suspend(() => typeAST(ast.f()), ast.annotations); - case "Refinement": { - const from = typeAST(ast.from); - return from === ast.from ? ast : new Refinement(from, ast.filter, ast.annotations); - } - case "Transformation": { - const preserve = preserveTransformationAnnotations(ast); - return typeAST(preserve !== undefined ? annotations(ast.to, preserve) : ast.to); - } + if (parallelCollectionIsEmpty(parallel)) { + return sequential; } - return ast; -}; -function changeMap(as, f) { - let changed = false; - const out = allocate(as.length); - for (let i = 0;i < as.length; i++) { - const a = as[i]; - const fa = f(a); - if (fa !== a) { - changed = true; - } - out[i] = fa; - } - return changed ? out : as; -} -var getTransformationFrom = (ast) => { - switch (ast._tag) { - case "Transformation": - return ast.from; - case "Refinement": - return getTransformationFrom(ast.from); - case "Suspend": - return getTransformationFrom(ast.f()); + const seqHeadKeys = sequentialCollectionKeys(sequential.head); + const parKeys = parallelCollectionKeys(parallel); + if (seqHeadKeys.length === 1 && parKeys.length === 1 && equals(seqHeadKeys[0], parKeys[0])) { + return cons(sequentialCollectionCombine(sequential.head, parallelCollectionToSequentialCollection(parallel)), sequential.tail); } + return cons(parallelCollectionToSequentialCollection(parallel), sequential); }; -var encodedAST_ = (ast, isBound) => { - switch (ast._tag) { - case "Declaration": { - const typeParameters = changeMap(ast.typeParameters, (ast2) => encodedAST_(ast2, isBound)); - return typeParameters === ast.typeParameters ? ast : new Declaration(typeParameters, ast.decodeUnknown, ast.encodeUnknown); - } - case "TupleType": { - const elements = changeMap(ast.elements, (e) => { - const type = encodedAST_(e.type, isBound); - return type === e.type ? e : new OptionalType(type, e.isOptional); - }); - const restASTs = getRestASTs(ast.rest); - const rest = changeMap(restASTs, (ast2) => encodedAST_(ast2, isBound)); - return elements === ast.elements && rest === restASTs ? ast : new TupleType(elements, rest.map((ast2) => new Type(ast2)), ast.isReadonly); - } - case "TypeLiteral": { - const propertySignatures = changeMap(ast.propertySignatures, (ps) => { - const type = encodedAST_(ps.type, isBound); - return type === ps.type ? ps : new PropertySignature(ps.name, type, ps.isOptional, ps.isReadonly); - }); - const indexSignatures = changeMap(ast.indexSignatures, (is) => { - const type = encodedAST_(is.type, isBound); - return type === is.type ? is : new IndexSignature(is.parameter, type, is.isReadonly); - }); - return propertySignatures === ast.propertySignatures && indexSignatures === ast.indexSignatures ? ast : new TypeLiteral(propertySignatures, indexSignatures); - } - case "Union": { - const types = changeMap(ast.types, (ast2) => encodedAST_(ast2, isBound)); - return types === ast.types ? ast : Union.make(types); - } - case "Suspend": { - let borrowedAnnotations = undefined; - const identifier = getJSONIdentifier(ast); - if (isSome2(identifier)) { - const suffix = isBound ? "Bound" : ""; - borrowedAnnotations = { - [JSONIdentifierAnnotationId]: `${identifier.value}Encoded${suffix}` - }; - } - return new Suspend(() => encodedAST_(ast.f(), isBound), borrowedAnnotations); - } - case "Refinement": { - const from = encodedAST_(ast.from, isBound); - if (isBound) { - if (from === ast.from) - return ast; - if (getTransformationFrom(ast.from) === undefined && hasStableFilter(ast)) { - return new Refinement(from, ast.filter, ast.annotations); - } - return from; - } else { - return from; - } - } - case "Transformation": - return encodedAST_(ast.from, isBound); +var EntryTypeId = /* @__PURE__ */ Symbol.for("effect/RequestBlock/Entry"); + +class EntryImpl { + request; + result; + listeners; + ownerId; + state; + [EntryTypeId] = blockedRequestVariance; + constructor(request, result, listeners, ownerId, state) { + this.request = request; + this.result = result; + this.listeners = listeners; + this.ownerId = ownerId; + this.state = state; } - return ast; +} +var blockedRequestVariance = { + _R: (_) => _ }; -var encodedAST = (ast) => encodedAST_(ast, false); -var encodedBoundAST = (ast) => encodedAST_(ast, true); -var toJSONAnnotations = (annotations2) => { - const out = {}; - for (const k of Object.getOwnPropertySymbols(annotations2)) { - out[String(k)] = annotations2[k]; - } - return out; +var makeEntry = (options) => new EntryImpl(options.request, options.result, options.listeners, options.ownerId, options.state); +var RequestBlockParallelTypeId = /* @__PURE__ */ Symbol.for("effect/RequestBlock/RequestBlockParallel"); +var parallelVariance = { + _R: (_) => _ }; -var getEncodedParameter = (ast) => { - switch (ast._tag) { - case "StringKeyword": - case "SymbolKeyword": - case "TemplateLiteral": - return ast; - case "Refinement": - return getEncodedParameter(ast.from); + +class ParallelImpl { + map; + [RequestBlockParallelTypeId] = parallelVariance; + constructor(map7) { + this.map = map7; } +} +var parallelCollectionEmpty = () => new ParallelImpl(empty8()); +var parallelCollectionAdd = (self, blockedRequest) => new ParallelImpl(modifyAt2(self.map, blockedRequest.dataSource, (_) => orElseSome(map2(_, append2(blockedRequest.blockedRequest)), () => of2(blockedRequest.blockedRequest)))); +var parallelCollectionCombine = (self, that) => new ParallelImpl(reduce5(self.map, that.map, (map7, value, key) => set3(map7, key, match2(get7(map7, key), { + onNone: () => value, + onSome: (other) => appendAll2(value, other) +})))); +var parallelCollectionIsEmpty = (self) => isEmpty3(self.map); +var parallelCollectionKeys = (self) => Array.from(keys2(self.map)); +var parallelCollectionToSequentialCollection = (self) => sequentialCollectionMake(map6(self.map, (x) => of2(x))); +var SequentialCollectionTypeId = /* @__PURE__ */ Symbol.for("effect/RequestBlock/RequestBlockSequential"); +var sequentialVariance = { + _R: (_) => _ }; -var equals2 = (self, that) => { - switch (self._tag) { - case "Literal": - return isLiteral(that) && that.literal === self.literal; - case "UniqueSymbol": - return isUniqueSymbol(that) && that.symbol === self.symbol; - case "UndefinedKeyword": - case "VoidKeyword": - case "NeverKeyword": - case "UnknownKeyword": - case "AnyKeyword": - case "StringKeyword": - case "NumberKeyword": - case "BooleanKeyword": - case "BigIntKeyword": - case "SymbolKeyword": - case "ObjectKeyword": - return that._tag === self._tag; - case "TemplateLiteral": - return isTemplateLiteral(that) && that.head === self.head && equalsTemplateLiteralSpan(that.spans, self.spans); - case "Enums": - return isEnums(that) && equalsEnums(that.enums, self.enums); - case "Union": - return isUnion(that) && equalsUnion(self.types, that.types); - case "Refinement": - case "TupleType": - case "TypeLiteral": - case "Suspend": - case "Transformation": - case "Declaration": - return self === that; + +class SequentialImpl { + map; + [SequentialCollectionTypeId] = sequentialVariance; + constructor(map7) { + this.map = map7; } +} +var sequentialCollectionMake = (map7) => new SequentialImpl(map7); +var sequentialCollectionCombine = (self, that) => new SequentialImpl(reduce5(that.map, self.map, (map7, value, key) => set3(map7, key, match2(get7(map7, key), { + onNone: () => empty2(), + onSome: (a) => appendAll2(a, value) +})))); +var sequentialCollectionKeys = (self) => Array.from(keys2(self.map)); +var sequentialCollectionToChunk = (self) => Array.from(self.map); + +// node_modules/effect/dist/esm/internal/opCodes/cause.js +var OP_DIE = "Die"; +var OP_EMPTY = "Empty"; +var OP_FAIL = "Fail"; +var OP_INTERRUPT = "Interrupt"; +var OP_PARALLEL = "Parallel"; +var OP_SEQUENTIAL = "Sequential"; + +// node_modules/effect/dist/esm/internal/cause.js +var CauseSymbolKey = "effect/Cause"; +var CauseTypeId = /* @__PURE__ */ Symbol.for(CauseSymbolKey); +var variance4 = { + _E: (_) => _ }; -var equalsTemplateLiteralSpan = /* @__PURE__ */ getEquivalence3((self, that) => { - return self.literal === that.literal && equals2(self.type, that.type); -}); -var equalsEnums = /* @__PURE__ */ getEquivalence3((self, that) => that[0] === self[0] && that[1] === self[1]); -var equalsUnion = /* @__PURE__ */ getEquivalence3(equals2); -var intersection2 = /* @__PURE__ */ intersectionWith(equals2); -var _keyof = (ast) => { - switch (ast._tag) { - case "Declaration": { - const annotation = getSurrogateAnnotation(ast); - if (isSome2(annotation)) { - return _keyof(annotation.value); - } - break; +var proto = { + [CauseTypeId]: variance4, + [symbol]() { + return pipe(hash(CauseSymbolKey), combine(hash(flattenCause(this))), cached(this)); + }, + [symbol2](that) { + return isCause(that) && causeEquals(this, that); + }, + pipe() { + return pipeArguments(this, arguments); + }, + toJSON() { + switch (this._tag) { + case "Empty": + return { + _id: "Cause", + _tag: this._tag + }; + case "Die": + return { + _id: "Cause", + _tag: this._tag, + defect: toJSON(this.defect) + }; + case "Interrupt": + return { + _id: "Cause", + _tag: this._tag, + fiberId: this.fiberId.toJSON() + }; + case "Fail": + return { + _id: "Cause", + _tag: this._tag, + failure: toJSON(this.error) + }; + case "Sequential": + case "Parallel": + return { + _id: "Cause", + _tag: this._tag, + left: toJSON(this.left), + right: toJSON(this.right) + }; } - case "TypeLiteral": - return ast.propertySignatures.map((p) => isSymbol(p.name) ? new UniqueSymbol(p.name) : new Literal(p.name)).concat(ast.indexSignatures.map((is) => getEncodedParameter(is.parameter))); - case "Suspend": - return _keyof(ast.f()); - case "Union": - return ast.types.slice(1).reduce((out, ast2) => intersection2(out, _keyof(ast2)), _keyof(ast.types[0])); - case "Transformation": - return _keyof(ast.to); - } - throw new Error(getASTUnsupportedSchemaErrorMessage(ast)); -}; -var compose = (ab, cd) => new Transformation(ab, cd, composeTransformation); -var rename = (ast, mapping) => { - switch (ast._tag) { - case "TypeLiteral": { - const propertySignatureTransformations = []; - for (const key of Reflect.ownKeys(mapping)) { - const name = mapping[key]; - if (name !== undefined) { - propertySignatureTransformations.push(new PropertySignatureTransformation(key, name, identity, identity)); - } - } - if (propertySignatureTransformations.length === 0) { - return ast; - } - return new Transformation(ast, new TypeLiteral(ast.propertySignatures.map((ps) => { - const name = mapping[ps.name]; - return new PropertySignature(name === undefined ? ps.name : name, typeAST(ps.type), ps.isOptional, ps.isReadonly, ps.annotations); - }), ast.indexSignatures), new TypeLiteralTransformation(propertySignatureTransformations)); - } - case "Union": - return Union.make(ast.types.map((ast2) => rename(ast2, mapping))); - case "Suspend": - return new Suspend(() => rename(ast.f(), mapping)); - case "Transformation": - return compose(ast, rename(typeAST(ast), mapping)); - } - throw new Error(getASTUnsupportedRenameSchemaErrorMessage(ast)); -}; -var formatKeyword = (ast) => getOrElse(getExpected(ast), () => ast._tag); -function getBrands(ast) { - return match2(getBrandAnnotation(ast), { - onNone: () => "", - onSome: (brands) => brands.map((brand) => ` & Brand<${formatUnknown(brand)}>`).join("") - }); -} -var getOrElseExpected = (ast) => getTitleAnnotation(ast).pipe(orElse(() => getDescriptionAnnotation(ast)), orElse(() => getAutoTitleAnnotation(ast)), map2((s) => s + getBrands(ast))); -var getExpected = (ast) => orElse(getIdentifierAnnotation(ast), () => getOrElseExpected(ast)); -var pruneUndefined = (ast, self, onTransformation) => { - switch (ast._tag) { - case "UndefinedKeyword": - return neverKeyword; - case "Union": { - const types = []; - let hasUndefined = false; - for (const type of ast.types) { - const pruned = self(type); - if (pruned) { - hasUndefined = true; - if (!isNeverKeyword(pruned)) { - types.push(pruned); - } - } else { - types.push(type); - } - } - if (hasUndefined) { - return Union.make(types); - } - break; - } - case "Suspend": - return self(ast.f()); - case "Transformation": - return onTransformation(ast); - } -}; -// node_modules/effect/dist/esm/BigDecimal.js -var FINITE_INT_REGEX = /^[+-]?\d+$/; -var TypeId3 = /* @__PURE__ */ Symbol.for("effect/BigDecimal"); -var BigDecimalProto = { - [TypeId3]: TypeId3, - [symbol]() { - const normalized = normalize(this); - return pipe(hash(normalized.value), combine(number2(normalized.scale)), cached(this)); - }, - [symbol2](that) { - return isBigDecimal(that) && equals3(this, that); }, toString() { - return `BigDecimal(${format2(this)})`; - }, - toJSON() { - return { - _id: "BigDecimal", - value: String(this.value), - scale: this.scale - }; + return pretty(this); }, [NodeInspectSymbol]() { return this.toJSON(); - }, - pipe() { - return pipeArguments(this, arguments); } }; -var isBigDecimal = (u) => hasProperty(u, TypeId3); -var make4 = (value, scale) => { - const o = Object.create(BigDecimalProto); - o.value = value; - o.scale = scale; +var empty16 = /* @__PURE__ */ (() => { + const o = /* @__PURE__ */ Object.create(proto); + o._tag = OP_EMPTY; + return o; +})(); +var fail = (error) => { + const o = Object.create(proto); + o._tag = OP_FAIL; + o.error = error; return o; }; -var unsafeMakeNormalized = (value, scale) => { - if (value !== bigint0 && value % bigint10 === bigint0) { - throw new RangeError("Value must be normalized"); - } - const o = make4(value, scale); - o.normalized = o; +var die = (defect) => { + const o = Object.create(proto); + o._tag = OP_DIE; + o.defect = defect; return o; }; -var bigint0 = /* @__PURE__ */ BigInt(0); -var bigint10 = /* @__PURE__ */ BigInt(10); -var zero = /* @__PURE__ */ unsafeMakeNormalized(bigint0, 0); -var normalize = (self) => { - if (self.normalized === undefined) { - if (self.value === bigint0) { - self.normalized = zero; - } else { - const digits = `${self.value}`; - let trail = 0; - for (let i = digits.length - 1;i >= 0; i--) { - if (digits[i] === "0") { - trail++; - } else { - break; - } +var interrupt = (fiberId) => { + const o = Object.create(proto); + o._tag = OP_INTERRUPT; + o.fiberId = fiberId; + return o; +}; +var parallel = (left3, right3) => { + const o = Object.create(proto); + o._tag = OP_PARALLEL; + o.left = left3; + o.right = right3; + return o; +}; +var sequential = (left3, right3) => { + const o = Object.create(proto); + o._tag = OP_SEQUENTIAL; + o.left = left3; + o.right = right3; + return o; +}; +var isCause = (u) => hasProperty(u, CauseTypeId); +var isEmptyType = (self) => self._tag === OP_EMPTY; +var isFailType = (self) => self._tag === OP_FAIL; +var isDieType = (self) => self._tag === OP_DIE; +var isEmpty5 = (self) => { + if (self._tag === OP_EMPTY) { + return true; + } + return reduce7(self, true, (acc, cause) => { + switch (cause._tag) { + case OP_EMPTY: { + return some2(acc); } - if (trail === 0) { - self.normalized = self; + case OP_DIE: + case OP_FAIL: + case OP_INTERRUPT: { + return some2(false); + } + default: { + return none2(); } - const value = BigInt(digits.substring(0, digits.length - trail)); - const scale = self.scale - trail; - self.normalized = unsafeMakeNormalized(value, scale); } - } - return self.normalized; + }); }; -var scale = /* @__PURE__ */ dual(2, (self, scale2) => { - if (scale2 > self.scale) { - return make4(self.value * bigint10 ** BigInt(scale2 - self.scale), scale2); - } - if (scale2 < self.scale) { - return make4(self.value / bigint10 ** BigInt(self.scale - scale2), scale2); +var isInterrupted = (self) => isSome2(interruptOption(self)); +var isInterruptedOnly = (self) => reduceWithContext(undefined, IsInterruptedOnlyCauseReducer)(self); +var failures = (self) => reverse2(reduce7(self, empty2(), (list, cause) => cause._tag === OP_FAIL ? some2(pipe(list, prepend2(cause.error))) : none2())); +var defects = (self) => reverse2(reduce7(self, empty2(), (list, cause) => cause._tag === OP_DIE ? some2(pipe(list, prepend2(cause.defect))) : none2())); +var interruptors = (self) => reduce7(self, empty7(), (set4, cause) => cause._tag === OP_INTERRUPT ? some2(pipe(set4, add4(cause.fiberId))) : none2()); +var failureOption = (self) => find(self, (cause) => cause._tag === OP_FAIL ? some2(cause.error) : none2()); +var failureOrCause = (self) => { + const option = failureOption(self); + switch (option._tag) { + case "None": { + return right2(self); + } + case "Some": { + return left2(option.value); + } } - return self; +}; +var interruptOption = (self) => find(self, (cause) => cause._tag === OP_INTERRUPT ? some2(cause.fiberId) : none2()); +var keepDefects = (self) => match5(self, { + onEmpty: none2(), + onFail: () => none2(), + onDie: (defect) => some2(die(defect)), + onInterrupt: () => none2(), + onSequential: mergeWith(sequential), + onParallel: mergeWith(parallel) }); -var Order2 = /* @__PURE__ */ make2((self, that) => { - const scmp = number3(sign(self), sign(that)); - if (scmp !== 0) { - return scmp; - } - if (self.scale > that.scale) { - return bigint(self.value, scale(that, self.scale).value); - } - if (self.scale < that.scale) { - return bigint(scale(self, that.scale).value, that.value); - } - return bigint(self.value, that.value); +var keepDefectsAndElectFailures = (self) => match5(self, { + onEmpty: none2(), + onFail: (failure) => some2(die(failure)), + onDie: (defect) => some2(die(defect)), + onInterrupt: () => none2(), + onSequential: mergeWith(sequential), + onParallel: mergeWith(parallel) }); -var lessThan2 = /* @__PURE__ */ lessThan(Order2); -var lessThanOrEqualTo2 = /* @__PURE__ */ lessThanOrEqualTo(Order2); -var greaterThan2 = /* @__PURE__ */ greaterThan(Order2); -var greaterThanOrEqualTo2 = /* @__PURE__ */ greaterThanOrEqualTo(Order2); -var between2 = /* @__PURE__ */ between(Order2); -var clamp4 = /* @__PURE__ */ clamp(Order2); -var sign = (n) => n.value === bigint0 ? 0 : n.value < bigint0 ? -1 : 1; -var abs = (n) => n.value < bigint0 ? make4(-n.value, n.scale) : n; -var Equivalence = /* @__PURE__ */ make((self, that) => { - if (self.scale > that.scale) { - return scale(that, self.scale).value === self.value; - } - if (self.scale < that.scale) { - return scale(self, that.scale).value === that.value; - } - return self.value === that.value; +var stripFailures = (self) => match5(self, { + onEmpty: empty16, + onFail: () => empty16, + onDie: die, + onInterrupt: interrupt, + onSequential: sequential, + onParallel: parallel }); -var equals3 = /* @__PURE__ */ dual(2, (self, that) => Equivalence(self, that)); -var unsafeFromNumber = (n) => getOrThrowWith2(safeFromNumber(n), () => new RangeError(`Number must be finite, got ${n}`)); -var safeFromNumber = (n) => { - if (!Number.isFinite(n)) { - return none2(); - } - const string2 = `${n}`; - if (string2.includes("e")) { - return fromString(string2); - } - const [lead, trail = ""] = string2.split("."); - return some2(make4(BigInt(`${lead}${trail}`), trail.length)); -}; -var fromString = (s) => { - if (s === "") { - return some2(zero); - } - let base; - let exp; - const seperator = s.search(/[eE]/); - if (seperator !== -1) { - const trail = s.slice(seperator + 1); - base = s.slice(0, seperator); - exp = Number(trail); - if (base === "" || !Number.isSafeInteger(exp) || !FINITE_INT_REGEX.test(trail)) { - return none2(); - } - } else { - base = s; - exp = 0; - } - let digits; - let offset; - const dot = base.search(/\./); - if (dot !== -1) { - const lead = base.slice(0, dot); - const trail = base.slice(dot + 1); - digits = `${lead}${trail}`; - offset = trail.length; - } else { - digits = base; - offset = 0; - } - if (!FINITE_INT_REGEX.test(digits)) { - return none2(); - } - const scale2 = offset - exp; - if (!Number.isSafeInteger(scale2)) { - return none2(); - } - return some2(make4(BigInt(digits), scale2)); -}; -var format2 = (n) => { - const normalized = normalize(n); - if (Math.abs(normalized.scale) >= 16) { - return toExponential(normalized); - } - const negative = normalized.value < bigint0; - const absolute = negative ? `${normalized.value}`.substring(1) : `${normalized.value}`; - let before; - let after; - if (normalized.scale >= absolute.length) { - before = "0"; - after = "0".repeat(normalized.scale - absolute.length) + absolute; - } else { - const location = absolute.length - normalized.scale; - if (location > absolute.length) { - const zeros = location - absolute.length; - before = `${absolute}${"0".repeat(zeros)}`; - after = ""; - } else { - after = absolute.slice(location); - before = absolute.slice(0, location); +var electFailures = (self) => match5(self, { + onEmpty: empty16, + onFail: die, + onDie: die, + onInterrupt: interrupt, + onSequential: sequential, + onParallel: parallel +}); +var flatMap6 = /* @__PURE__ */ dual(2, (self, f) => match5(self, { + onEmpty: empty16, + onFail: (error) => f(error), + onDie: (defect) => die(defect), + onInterrupt: (fiberId) => interrupt(fiberId), + onSequential: (left3, right3) => sequential(left3, right3), + onParallel: (left3, right3) => parallel(left3, right3) +})); +var flatten3 = (self) => flatMap6(self, identity); +var causeEquals = (left3, right3) => { + let leftStack = of2(left3); + let rightStack = of2(right3); + while (isNonEmpty(leftStack) && isNonEmpty(rightStack)) { + const [leftParallel, leftSequential] = pipe(headNonEmpty2(leftStack), reduce7([empty7(), empty2()], ([parallel2, sequential2], cause) => { + const [par2, seq2] = evaluateCause(cause); + return some2([pipe(parallel2, union3(par2)), pipe(sequential2, appendAll2(seq2))]); + })); + const [rightParallel, rightSequential] = pipe(headNonEmpty2(rightStack), reduce7([empty7(), empty2()], ([parallel2, sequential2], cause) => { + const [par2, seq2] = evaluateCause(cause); + return some2([pipe(parallel2, union3(par2)), pipe(sequential2, appendAll2(seq2))]); + })); + if (!equals(leftParallel, rightParallel)) { + return false; } + leftStack = leftSequential; + rightStack = rightSequential; } - const complete = after === "" ? before : `${before}.${after}`; - return negative ? `-${complete}` : complete; -}; -var toExponential = (n) => { - if (isZero(n)) { - return "0e+0"; - } - const normalized = normalize(n); - const digits = `${abs(normalized).value}`; - const head2 = digits.slice(0, 1); - const tail = digits.slice(1); - let output = `${isNegative(normalized) ? "-" : ""}${head2}`; - if (tail !== "") { - output += `.${tail}`; - } - const exp = tail.length - normalized.scale; - return `${output}e${exp >= 0 ? "+" : ""}${exp}`; -}; -var unsafeToNumber = (n) => Number(format2(n)); -var isZero = (n) => n.value === bigint0; -var isNegative = (n) => n.value < bigint0; -var isPositive = (n) => n.value > bigint0; -// node_modules/effect/dist/esm/BigInt.js -var Order3 = bigint; -var clamp5 = /* @__PURE__ */ clamp(Order3); -var toNumber = (b) => { - if (b > BigInt(Number.MAX_SAFE_INTEGER) || b < BigInt(Number.MIN_SAFE_INTEGER)) { - return none2(); - } - return some2(Number(b)); -}; -var fromString2 = (s) => { - try { - return s.trim() === "" ? none2() : some2(BigInt(s)); - } catch { - return none2(); - } -}; -var fromNumber = (n) => { - if (n > Number.MAX_SAFE_INTEGER || n < Number.MIN_SAFE_INTEGER) { - return none2(); - } - try { - return some2(BigInt(n)); - } catch { - return none2(); - } -}; -// node_modules/effect/dist/esm/Boolean.js -var not = (self) => !self; -// node_modules/effect/dist/esm/internal/context.js -var TagTypeId = /* @__PURE__ */ Symbol.for("effect/Context/Tag"); -var ReferenceTypeId = /* @__PURE__ */ Symbol.for("effect/Context/Reference"); -var STMSymbolKey = "effect/STM"; -var STMTypeId = /* @__PURE__ */ Symbol.for(STMSymbolKey); -var TagProto = { - ...EffectPrototype, - _op: "Tag", - [STMTypeId]: effectVariance, - [TagTypeId]: { - _Service: (_) => _, - _Identifier: (_) => _ - }, - toString() { - return format(this.toJSON()); - }, - toJSON() { - return { - _id: "Tag", - key: this.key, - stack: this.stack - }; - }, - [NodeInspectSymbol]() { - return this.toJSON(); - }, - of(self) { - return self; - }, - context(self) { - return make5(this, self); - } -}; -var ReferenceProto = { - ...TagProto, - [ReferenceTypeId]: ReferenceTypeId + return true; }; -var makeGenericTag = (key) => { - const limit = Error.stackTraceLimit; - Error.stackTraceLimit = 2; - const creationError = new Error; - Error.stackTraceLimit = limit; - const tag = Object.create(TagProto); - Object.defineProperty(tag, "stack", { - get() { - return creationError.stack; - } - }); - tag.key = key; - return tag; +var flattenCause = (cause) => { + return flattenCauseLoop(of2(cause), empty2()); }; -var Reference = () => (id, options) => { - const limit = Error.stackTraceLimit; - Error.stackTraceLimit = 2; - const creationError = new Error; - Error.stackTraceLimit = limit; - function ReferenceClass() {} - Object.setPrototypeOf(ReferenceClass, ReferenceProto); - ReferenceClass.key = id; - ReferenceClass.defaultValue = options.defaultValue; - Object.defineProperty(ReferenceClass, "stack", { - get() { - return creationError.stack; +var flattenCauseLoop = (causes, flattened) => { + while (true) { + const [parallel2, sequential2] = pipe(causes, reduce([empty7(), empty2()], ([parallel3, sequential3], cause) => { + const [par2, seq2] = evaluateCause(cause); + return [pipe(parallel3, union3(par2)), pipe(sequential3, appendAll2(seq2))]; + })); + const updated = size3(parallel2) > 0 ? pipe(flattened, prepend2(parallel2)) : flattened; + if (isEmpty(sequential2)) { + return reverse2(updated); } - }); - return ReferenceClass; + causes = sequential2; + flattened = updated; + } + throw new Error(getBugErrorMessage("Cause.flattenCauseLoop")); }; -var TypeId4 = /* @__PURE__ */ Symbol.for("effect/Context"); -var ContextProto = { - [TypeId4]: { - _Services: (_) => _ - }, - [symbol2](that) { - if (isContext(that)) { - if (this.unsafeMap.size === that.unsafeMap.size) { - for (const k of this.unsafeMap.keys()) { - if (!that.unsafeMap.has(k) || !equals(this.unsafeMap.get(k), that.unsafeMap.get(k))) { - return false; +var find = /* @__PURE__ */ dual(2, (self, pf) => { + const stack = [self]; + while (stack.length > 0) { + const item = stack.pop(); + const option = pf(item); + switch (option._tag) { + case "None": { + switch (item._tag) { + case OP_SEQUENTIAL: + case OP_PARALLEL: { + stack.push(item.right); + stack.push(item.left); + break; } } - return true; + break; } - } - return false; - }, - [symbol]() { - return cached(this, number2(this.unsafeMap.size)); - }, - pipe() { - return pipeArguments(this, arguments); - }, - toString() { - return format(this.toJSON()); - }, - toJSON() { - return { - _id: "Context", - services: Array.from(this.unsafeMap).map(toJSON) - }; - }, - [NodeInspectSymbol]() { - return this.toJSON(); - } -}; -var makeContext = (unsafeMap) => { - const context = Object.create(ContextProto); - context.unsafeMap = unsafeMap; - return context; -}; -var serviceNotFoundError = (tag) => { - const error = new Error(`Service not found${tag.key ? `: ${String(tag.key)}` : ""}`); - if (tag.stack) { - const lines = tag.stack.split(` -`); - if (lines.length > 2) { - const afterAt = lines[2].match(/at (.*)/); - if (afterAt) { - error.message = error.message + ` (defined at ${afterAt[1]})`; + case "Some": { + return option; } } } - if (error.stack) { - const lines = error.stack.split(` -`); - lines.splice(1, 3); - error.stack = lines.join(` -`); - } - return error; -}; -var isContext = (u) => hasProperty(u, TypeId4); -var isTag = (u) => hasProperty(u, TagTypeId); -var isReference = (u) => hasProperty(u, ReferenceTypeId); -var _empty = /* @__PURE__ */ makeContext(/* @__PURE__ */ new Map); -var empty2 = () => _empty; -var make5 = (tag, service) => makeContext(new Map([[tag.key, service]])); -var add = /* @__PURE__ */ dual(3, (self, tag, service) => { - const map4 = new Map(self.unsafeMap); - map4.set(tag.key, service); - return makeContext(map4); + return none2(); }); -var defaultValueCache = /* @__PURE__ */ globalValue("effect/Context/defaultValueCache", () => new Map); -var getDefaultValue = (tag) => { - if (defaultValueCache.has(tag.key)) { - return defaultValueCache.get(tag.key); +var evaluateCause = (self) => { + let cause = self; + const stack = []; + let _parallel = empty7(); + let _sequential = empty2(); + while (cause !== undefined) { + switch (cause._tag) { + case OP_EMPTY: { + if (stack.length === 0) { + return [_parallel, _sequential]; + } + cause = stack.pop(); + break; + } + case OP_FAIL: { + _parallel = add4(_parallel, make4(cause._tag, cause.error)); + if (stack.length === 0) { + return [_parallel, _sequential]; + } + cause = stack.pop(); + break; + } + case OP_DIE: { + _parallel = add4(_parallel, make4(cause._tag, cause.defect)); + if (stack.length === 0) { + return [_parallel, _sequential]; + } + cause = stack.pop(); + break; + } + case OP_INTERRUPT: { + _parallel = add4(_parallel, make4(cause._tag, cause.fiberId)); + if (stack.length === 0) { + return [_parallel, _sequential]; + } + cause = stack.pop(); + break; + } + case OP_SEQUENTIAL: { + switch (cause.left._tag) { + case OP_EMPTY: { + cause = cause.right; + break; + } + case OP_SEQUENTIAL: { + cause = sequential(cause.left.left, sequential(cause.left.right, cause.right)); + break; + } + case OP_PARALLEL: { + cause = parallel(sequential(cause.left.left, cause.right), sequential(cause.left.right, cause.right)); + break; + } + default: { + _sequential = prepend2(_sequential, cause.right); + cause = cause.left; + break; + } + } + break; + } + case OP_PARALLEL: { + stack.push(cause.right); + cause = cause.left; + break; + } + } } - const value = tag.defaultValue(); - defaultValueCache.set(tag.key, value); - return value; + throw new Error(getBugErrorMessage("Cause.evaluateCauseLoop")); }; -var unsafeGetReference = (self, tag) => { - return self.unsafeMap.has(tag.key) ? self.unsafeMap.get(tag.key) : getDefaultValue(tag); +var IsInterruptedOnlyCauseReducer = { + emptyCase: constTrue, + failCase: constFalse, + dieCase: constFalse, + interruptCase: constTrue, + sequentialCase: (_, left3, right3) => left3 && right3, + parallelCase: (_, left3, right3) => left3 && right3 }; -var unsafeGet2 = /* @__PURE__ */ dual(2, (self, tag) => { - if (!self.unsafeMap.has(tag.key)) { - if (ReferenceTypeId in tag) - return getDefaultValue(tag); - throw serviceNotFoundError(tag); - } - return self.unsafeMap.get(tag.key); -}); -var get2 = unsafeGet2; -var getOption = /* @__PURE__ */ dual(2, (self, tag) => { - if (!self.unsafeMap.has(tag.key)) { - return isReference(tag) ? some(getDefaultValue(tag)) : none; - } - return some(self.unsafeMap.get(tag.key)); -}); -var merge2 = /* @__PURE__ */ dual(2, (self, that) => { - const map4 = new Map(self.unsafeMap); - for (const [tag, s] of that.unsafeMap) { - map4.set(tag, s); - } - return makeContext(map4); +var OP_SEQUENTIAL_CASE = "SequentialCase"; +var OP_PARALLEL_CASE = "ParallelCase"; +var match5 = /* @__PURE__ */ dual(2, (self, { + onDie, + onEmpty, + onFail, + onInterrupt, + onParallel, + onSequential +}) => { + return reduceWithContext(self, undefined, { + emptyCase: () => onEmpty, + failCase: (_, error) => onFail(error), + dieCase: (_, defect) => onDie(defect), + interruptCase: (_, fiberId) => onInterrupt(fiberId), + sequentialCase: (_, left3, right3) => onSequential(left3, right3), + parallelCase: (_, left3, right3) => onParallel(left3, right3) + }); }); -var mergeAll = (...ctxs) => { - const map4 = new Map; - for (let i = 0;i < ctxs.length; i++) { - ctxs[i].unsafeMap.forEach((value, key) => { - map4.set(key, value); - }); - } - return makeContext(map4); -}; - -// node_modules/effect/dist/esm/Context.js -var GenericTag = makeGenericTag; -var isContext2 = isContext; -var isTag2 = isTag; -var empty3 = empty2; -var make6 = make5; -var add2 = add; -var get3 = get2; -var unsafeGet3 = unsafeGet2; -var getOption2 = getOption; -var merge3 = merge2; -var mergeAll2 = mergeAll; -var Reference2 = Reference; - -// node_modules/effect/dist/esm/Chunk.js -var TypeId5 = /* @__PURE__ */ Symbol.for("effect/Chunk"); -function copy2(src, srcPos, dest, destPos, len) { - for (let i = srcPos;i < Math.min(src.length, srcPos + len); i++) { - dest[destPos + i - srcPos] = src[i]; - } - return dest; -} -var emptyArray = []; -var getEquivalence4 = (isEquivalent) => make((self, that) => self.length === that.length && toReadonlyArray(self).every((value, i) => isEquivalent(value, unsafeGet4(that, i)))); -var _equivalence3 = /* @__PURE__ */ getEquivalence4(equals); -var ChunkProto = { - [TypeId5]: { - _A: (_) => _ - }, - toString() { - return format(this.toJSON()); - }, - toJSON() { - return { - _id: "Chunk", - values: toReadonlyArray(this).map(toJSON) - }; - }, - [NodeInspectSymbol]() { - return this.toJSON(); - }, - [symbol2](that) { - return isChunk(that) && _equivalence3(this, that); - }, - [symbol]() { - return cached(this, array2(toReadonlyArray(this))); - }, - [Symbol.iterator]() { - switch (this.backing._tag) { - case "IArray": { - return this.backing.array[Symbol.iterator](); +var reduce7 = /* @__PURE__ */ dual(3, (self, zero2, pf) => { + let accumulator = zero2; + let cause = self; + const causes = []; + while (cause !== undefined) { + const option = pf(accumulator, cause); + accumulator = isSome2(option) ? option.value : accumulator; + switch (cause._tag) { + case OP_SEQUENTIAL: { + causes.push(cause.right); + cause = cause.left; + break; } - case "IEmpty": { - return emptyArray[Symbol.iterator](); + case OP_PARALLEL: { + causes.push(cause.right); + cause = cause.left; + break; } default: { - return toReadonlyArray(this)[Symbol.iterator](); + cause = undefined; + break; } } - }, - pipe() { - return pipeArguments(this, arguments); - } -}; -var makeChunk = (backing) => { - const chunk = Object.create(ChunkProto); - chunk.backing = backing; - switch (backing._tag) { - case "IEmpty": { - chunk.length = 0; - chunk.depth = 0; - chunk.left = chunk; - chunk.right = chunk; - break; - } - case "IConcat": { - chunk.length = backing.left.length + backing.right.length; - chunk.depth = 1 + Math.max(backing.left.depth, backing.right.depth); - chunk.left = backing.left; - chunk.right = backing.right; - break; - } - case "IArray": { - chunk.length = backing.array.length; - chunk.depth = 0; - chunk.left = _empty2; - chunk.right = _empty2; - break; - } - case "ISingleton": { - chunk.length = 1; - chunk.depth = 0; - chunk.left = _empty2; - chunk.right = _empty2; - break; - } - case "ISlice": { - chunk.length = backing.length; - chunk.depth = backing.chunk.depth + 1; - chunk.left = _empty2; - chunk.right = _empty2; - break; + if (cause === undefined && causes.length > 0) { + cause = causes.pop(); } } - return chunk; -}; -var isChunk = (u) => hasProperty(u, TypeId5); -var _empty2 = /* @__PURE__ */ makeChunk({ - _tag: "IEmpty" -}); -var empty4 = () => _empty2; -var make7 = (...as) => unsafeFromNonEmptyArray(as); -var of2 = (a) => makeChunk({ - _tag: "ISingleton", - a + return accumulator; }); -var fromIterable2 = (self) => isChunk(self) ? self : unsafeFromArray(fromIterable(self)); -var copyToArray = (self, array4, initial) => { - switch (self.backing._tag) { - case "IArray": { - copy2(self.backing.array, 0, array4, initial, self.length); - break; - } - case "IConcat": { - copyToArray(self.left, array4, initial); - copyToArray(self.right, array4, initial + self.left.length); - break; - } - case "ISingleton": { - array4[initial] = self.backing.a; - break; - } - case "ISlice": { - let i = 0; - let j = initial; - while (i < self.length) { - array4[j] = unsafeGet4(self, i); - i += 1; - j += 1; - } - break; - } - } -}; -var toReadonlyArray_ = (self) => { - switch (self.backing._tag) { - case "IEmpty": { - return emptyArray; - } - case "IArray": { - return self.backing.array; - } - default: { - const arr = new Array(self.length); - copyToArray(self, arr, 0); - self.backing = { - _tag: "IArray", - array: arr - }; - self.left = _empty2; - self.right = _empty2; - self.depth = 0; - return arr; +var reduceWithContext = /* @__PURE__ */ dual(3, (self, context, reducer) => { + const input = [self]; + const output = []; + while (input.length > 0) { + const cause = input.pop(); + switch (cause._tag) { + case OP_EMPTY: { + output.push(right2(reducer.emptyCase(context))); + break; + } + case OP_FAIL: { + output.push(right2(reducer.failCase(context, cause.error))); + break; + } + case OP_DIE: { + output.push(right2(reducer.dieCase(context, cause.defect))); + break; + } + case OP_INTERRUPT: { + output.push(right2(reducer.interruptCase(context, cause.fiberId))); + break; + } + case OP_SEQUENTIAL: { + input.push(cause.right); + input.push(cause.left); + output.push(left2({ + _tag: OP_SEQUENTIAL_CASE + })); + break; + } + case OP_PARALLEL: { + input.push(cause.right); + input.push(cause.left); + output.push(left2({ + _tag: OP_PARALLEL_CASE + })); + break; + } } } -}; -var toReadonlyArray = toReadonlyArray_; -var reverseChunk = (self) => { - switch (self.backing._tag) { - case "IEmpty": - case "ISingleton": - return self; - case "IArray": { - return makeChunk({ - _tag: "IArray", - array: reverse(self.backing.array) - }); + const accumulator = []; + while (output.length > 0) { + const either2 = output.pop(); + switch (either2._tag) { + case "Left": { + switch (either2.left._tag) { + case OP_SEQUENTIAL_CASE: { + const left3 = accumulator.pop(); + const right3 = accumulator.pop(); + const value = reducer.sequentialCase(context, left3, right3); + accumulator.push(value); + break; + } + case OP_PARALLEL_CASE: { + const left3 = accumulator.pop(); + const right3 = accumulator.pop(); + const value = reducer.parallelCase(context, left3, right3); + accumulator.push(value); + break; + } + } + break; + } + case "Right": { + accumulator.push(either2.right); + break; + } } - case "IConcat": { - return makeChunk({ - _tag: "IConcat", - left: reverse2(self.backing.right), - right: reverse2(self.backing.left) - }); + } + if (accumulator.length === 0) { + throw new Error("BUG: Cause.reduceWithContext - please report an issue at https://github.com/Effect-TS/effect/issues"); + } + return accumulator.pop(); +}); +var pretty = (cause, options) => { + if (isInterruptedOnly(cause)) { + return "All fibers interrupted without errors."; + } + return prettyErrors(cause).map(function(e) { + if (options?.renderErrorCause !== true || e.cause === undefined) { + return e.stack; } - case "ISlice": - return unsafeFromArray(reverse(toReadonlyArray(self))); + return `${e.stack} { +${renderErrorCause(e.cause, " ")} +}`; + }).join(` +`); +}; +var renderErrorCause = (cause, prefix) => { + const lines = cause.stack.split(` +`); + let stack = `${prefix}[cause]: ${lines[0]}`; + for (let i = 1, len = lines.length;i < len; i++) { + stack += ` +${prefix}${lines[i]}`; + } + if (cause.cause) { + stack += ` { +${renderErrorCause(cause.cause, `${prefix} `)} +${prefix}}`; } + return stack; }; -var reverse2 = reverseChunk; -var get4 = /* @__PURE__ */ dual(2, (self, index) => index < 0 || index >= self.length ? none2() : some2(unsafeGet4(self, index))); -var unsafeFromArray = (self) => self.length === 0 ? empty4() : self.length === 1 ? of2(self[0]) : makeChunk({ - _tag: "IArray", - array: self -}); -var unsafeFromNonEmptyArray = (self) => unsafeFromArray(self); -var unsafeGet4 = /* @__PURE__ */ dual(2, (self, index) => { - switch (self.backing._tag) { - case "IEmpty": { - throw new Error(`Index out of bounds`); +var makePrettyError = (originalError) => { + const originalErrorIsObject = typeof originalError === "object" && originalError !== null; + const prevLimit = Error.stackTraceLimit; + Error.stackTraceLimit = 1; + const error = new Error(prettyErrorMessage(originalError), originalErrorIsObject && "cause" in originalError && typeof originalError.cause !== "undefined" ? { + cause: makePrettyError(originalError.cause) + } : undefined); + Error.stackTraceLimit = prevLimit; + if (error.message === "") { + error.message = "An error has occurred"; + } + Error.stackTraceLimit = prevLimit; + error.name = originalError instanceof Error ? originalError.name : "Error"; + if (originalErrorIsObject) { + if (spanSymbol in originalError) { + error.span = originalError[spanSymbol]; } - case "ISingleton": { - if (index !== 0) { - throw new Error(`Index out of bounds`); + Object.keys(originalError).forEach((key) => { + if (!(key in error)) { + error[key] = originalError[key]; } - return self.backing.a; + }); + } + error.stack = prettyErrorStack(`${error.name}: ${error.message}`, originalError instanceof Error && originalError.stack ? originalError.stack : "", error.span); + return error; +}; +var prettyErrorMessage = (u) => { + if (typeof u === "string") { + return u; + } + if (typeof u === "object" && u !== null && u instanceof Error) { + return u.message; + } + try { + if (hasProperty(u, "toString") && isFunction2(u["toString"]) && u["toString"] !== Object.prototype.toString && u["toString"] !== globalThis.Array.prototype.toString) { + return u["toString"](); } - case "IArray": { - if (index >= self.length || index < 0) { - throw new Error(`Index out of bounds`); - } - return self.backing.array[index]; + } catch {} + return stringifyCircular(u); +}; +var locationRegex = /\((.*)\)/g; +var spanToTrace = /* @__PURE__ */ globalValue("effect/Tracer/spanToTrace", () => new WeakMap); +var prettyErrorStack = (message, stack, span2) => { + const out = [message]; + const lines = stack.startsWith(message) ? stack.slice(message.length).split(` +`) : stack.split(` +`); + for (let i = 1;i < lines.length; i++) { + if (lines[i].includes(" at new BaseEffectError") || lines[i].includes(" at new YieldableError")) { + i++; + continue; } - case "IConcat": { - return index < self.left.length ? unsafeGet4(self.left, index) : unsafeGet4(self.right, index - self.left.length); + if (lines[i].includes("Generator.next")) { + break; } - case "ISlice": { - return unsafeGet4(self.backing.chunk, index + self.backing.offset); + if (lines[i].includes("effect_internal_function")) { + break; } + out.push(lines[i].replace(/at .*effect_instruction_i.*\((.*)\)/, "at $1").replace(/EffectPrimitive\.\w+/, "")); } -}); -var append2 = /* @__PURE__ */ dual(2, (self, a) => appendAll2(self, of2(a))); -var prepend2 = /* @__PURE__ */ dual(2, (self, elem) => appendAll2(of2(elem), self)); -var drop2 = /* @__PURE__ */ dual(2, (self, n) => { - if (n <= 0) { - return self; - } else if (n >= self.length) { - return _empty2; - } else { - switch (self.backing._tag) { - case "ISlice": { - return makeChunk({ - _tag: "ISlice", - chunk: self.backing.chunk, - offset: self.backing.offset + n, - length: self.backing.length - n - }); - } - case "IConcat": { - if (n > self.left.length) { - return drop2(self.right, n - self.left.length); + if (span2) { + let current = span2; + let i = 0; + while (current && current._tag === "Span" && i < 10) { + const stackFn = spanToTrace.get(current); + if (typeof stackFn === "function") { + const stack2 = stackFn(); + if (typeof stack2 === "string") { + const locationMatchAll = stack2.matchAll(locationRegex); + let match6 = false; + for (const [, location] of locationMatchAll) { + match6 = true; + out.push(` at ${current.name} (${location})`); + } + if (!match6) { + out.push(` at ${current.name} (${stack2.replace(/^at /, "")})`); + } + } else { + out.push(` at ${current.name}`); } - return makeChunk({ - _tag: "IConcat", - left: drop2(self.left, n), - right: self.right - }); - } - default: { - return makeChunk({ - _tag: "ISlice", - chunk: self, - offset: n, - length: self.length - n - }); + } else { + out.push(` at ${current.name}`); } + current = getOrUndefined(current.parent); + i++; } } + return out.join(` +`); +}; +var spanSymbol = /* @__PURE__ */ Symbol.for("effect/SpanAnnotation"); +var prettyErrors = (cause) => reduceWithContext(cause, undefined, { + emptyCase: () => [], + dieCase: (_, unknownError) => { + return [makePrettyError(unknownError)]; + }, + failCase: (_, error) => { + return [makePrettyError(error)]; + }, + interruptCase: () => [], + parallelCase: (_, l, r) => [...l, ...r], + sequentialCase: (_, l, r) => [...l, ...r] }); -var appendAll2 = /* @__PURE__ */ dual(2, (self, that) => { - if (self.backing._tag === "IEmpty") { - return that; - } - if (that.backing._tag === "IEmpty") { - return self; + +// node_modules/effect/dist/esm/internal/opCodes/deferred.js +var OP_STATE_PENDING = "Pending"; +var OP_STATE_DONE = "Done"; + +// node_modules/effect/dist/esm/internal/deferred.js +var DeferredSymbolKey = "effect/Deferred"; +var DeferredTypeId = /* @__PURE__ */ Symbol.for(DeferredSymbolKey); +var deferredVariance = { + _E: (_) => _, + _A: (_) => _ +}; +var pending = (joiners) => { + return { + _tag: OP_STATE_PENDING, + joiners + }; +}; +var done = (effect) => { + return { + _tag: OP_STATE_DONE, + effect + }; +}; + +// node_modules/effect/dist/esm/internal/singleShotGen.js +class SingleShotGen2 { + self; + called = false; + constructor(self) { + this.self = self; } - const diff = that.depth - self.depth; - if (Math.abs(diff) <= 1) { - return makeChunk({ - _tag: "IConcat", - left: self, - right: that + next(a) { + return this.called ? { + value: a, + done: true + } : (this.called = true, { + value: this.self, + done: false }); - } else if (diff < -1) { - if (self.left.depth >= self.right.depth) { - const nr = appendAll2(self.right, that); - return makeChunk({ - _tag: "IConcat", - left: self.left, - right: nr - }); - } else { - const nrr = appendAll2(self.right.right, that); - if (nrr.depth === self.depth - 3) { - const nr = makeChunk({ - _tag: "IConcat", - left: self.right.left, - right: nrr - }); - return makeChunk({ - _tag: "IConcat", - left: self.left, - right: nr - }); - } else { - const nl = makeChunk({ - _tag: "IConcat", - left: self.left, - right: self.right.left - }); - return makeChunk({ - _tag: "IConcat", - left: nl, - right: nrr - }); - } - } - } else { - if (that.right.depth >= that.left.depth) { - const nl = appendAll2(self, that.left); - return makeChunk({ - _tag: "IConcat", - left: nl, - right: that.right - }); - } else { - const nll = appendAll2(self, that.left.left); - if (nll.depth === that.depth - 3) { - const nl = makeChunk({ - _tag: "IConcat", - left: nll, - right: that.left.right - }); - return makeChunk({ - _tag: "IConcat", - left: nl, - right: that.right - }); - } else { - const nr = makeChunk({ - _tag: "IConcat", - left: that.left.right, - right: that.right - }); - return makeChunk({ - _tag: "IConcat", - left: nll, - right: nr - }); - } - } } -}); -var isEmpty = (self) => self.length === 0; -var isNonEmpty2 = (self) => self.length > 0; -var head2 = /* @__PURE__ */ get4(0); -var unsafeHead = (self) => unsafeGet4(self, 0); -var headNonEmpty2 = unsafeHead; -var tailNonEmpty2 = (self) => drop2(self, 1); - -// node_modules/effect/dist/esm/Duration.js -var TypeId6 = /* @__PURE__ */ Symbol.for("effect/Duration"); -var bigint02 = /* @__PURE__ */ BigInt(0); -var bigint24 = /* @__PURE__ */ BigInt(24); -var bigint60 = /* @__PURE__ */ BigInt(60); -var bigint1e3 = /* @__PURE__ */ BigInt(1000); -var bigint1e6 = /* @__PURE__ */ BigInt(1e6); -var bigint1e9 = /* @__PURE__ */ BigInt(1e9); -var DURATION_REGEX = /^(-?\d+(?:\.\d+)?)\s+(nanos?|micros?|millis?|seconds?|minutes?|hours?|days?|weeks?)$/; -var decode = (input) => { - if (isDuration(input)) { - return input; - } else if (isNumber(input)) { - return millis(input); - } else if (isBigInt(input)) { - return nanos(input); - } else if (Array.isArray(input) && input.length === 2 && input.every(isNumber)) { - if (input[0] === -Infinity || input[1] === -Infinity || Number.isNaN(input[0]) || Number.isNaN(input[1])) { - return zero2; - } - if (input[0] === Infinity || input[1] === Infinity) { - return infinity; - } - return nanos(BigInt(Math.round(input[0] * 1e9)) + BigInt(Math.round(input[1]))); - } else if (isString(input)) { - const match4 = DURATION_REGEX.exec(input); - if (match4) { - const [_, valueStr, unit] = match4; - const value = Number(valueStr); - switch (unit) { - case "nano": - case "nanos": - return nanos(BigInt(valueStr)); - case "micro": - case "micros": - return micros(BigInt(valueStr)); - case "milli": - case "millis": - return millis(value); - case "second": - case "seconds": - return seconds(value); - case "minute": - case "minutes": - return minutes(value); - case "hour": - case "hours": - return hours(value); - case "day": - case "days": - return days(value); - case "week": - case "weeks": - return weeks(value); - } - } + return(a) { + return { + value: a, + done: true + }; } - throw new Error("Invalid DurationInput"); -}; -var zeroValue = { - _tag: "Millis", - millis: 0 + throw(e) { + throw e; + } + [Symbol.iterator]() { + return new SingleShotGen2(this.self); + } +} + +// node_modules/effect/dist/esm/internal/core.js +var blocked = (blockedRequests, _continue) => { + const effect = new EffectPrimitive("Blocked"); + effect.effect_instruction_i0 = blockedRequests; + effect.effect_instruction_i1 = _continue; + return effect; }; -var infinityValue = { - _tag: "Infinity" +var runRequestBlock = (blockedRequests) => { + const effect = new EffectPrimitive("RunBlocked"); + effect.effect_instruction_i0 = blockedRequests; + return effect; }; -var DurationProto = { - [TypeId6]: TypeId6, - [symbol]() { - return cached(this, structure(this.value)); - }, - [symbol2](that) { - return isDuration(that) && equals4(this, that); - }, - toString() { - return `Duration(${format3(this)})`; - }, - toJSON() { - switch (this.value._tag) { - case "Millis": - return { - _id: "Duration", - _tag: "Millis", - millis: this.value.millis - }; - case "Nanos": - return { - _id: "Duration", - _tag: "Nanos", - hrtime: toHrTime(this) - }; - case "Infinity": - return { - _id: "Duration", - _tag: "Infinity" - }; - } - }, - [NodeInspectSymbol]() { - return this.toJSON(); - }, +var EffectTypeId2 = /* @__PURE__ */ Symbol.for("effect/Effect"); + +class RevertFlags { + patch; + op; + _op = OP_REVERT_FLAGS; + constructor(patch5, op) { + this.patch = patch5; + this.op = op; + } +} + +class EffectPrimitive { + _op; + effect_instruction_i0 = undefined; + effect_instruction_i1 = undefined; + effect_instruction_i2 = undefined; + trace = undefined; + [EffectTypeId2] = effectVariance; + constructor(_op) { + this._op = _op; + } + [symbol2](that) { + return this === that; + } + [symbol]() { + return cached(this, random(this)); + } pipe() { return pipeArguments(this, arguments); } -}; -var make8 = (input) => { - const duration = Object.create(DurationProto); - if (isNumber(input)) { - if (isNaN(input) || input <= 0) { - duration.value = zeroValue; - } else if (!Number.isFinite(input)) { - duration.value = infinityValue; - } else if (!Number.isInteger(input)) { - duration.value = { - _tag: "Nanos", - nanos: BigInt(Math.round(input * 1e6)) - }; - } else { - duration.value = { - _tag: "Millis", - millis: input - }; - } - } else if (input <= bigint02) { - duration.value = zeroValue; - } else { - duration.value = { - _tag: "Nanos", - nanos: input + toJSON() { + return { + _id: "Effect", + _op: this._op, + effect_instruction_i0: toJSON(this.effect_instruction_i0), + effect_instruction_i1: toJSON(this.effect_instruction_i1), + effect_instruction_i2: toJSON(this.effect_instruction_i2) }; } - return duration; -}; -var isDuration = (u) => hasProperty(u, TypeId6); -var isFinite = (self) => self.value._tag !== "Infinity"; -var isZero2 = (self) => { - switch (self.value._tag) { - case "Millis": { - return self.value.millis === 0; - } - case "Nanos": { - return self.value.nanos === bigint02; - } - case "Infinity": { - return false; - } + toString() { + return format(this.toJSON()); } -}; -var zero2 = /* @__PURE__ */ make8(0); -var infinity = /* @__PURE__ */ make8(Infinity); -var nanos = (nanos2) => make8(nanos2); -var micros = (micros2) => make8(micros2 * bigint1e3); -var millis = (millis2) => make8(millis2); -var seconds = (seconds2) => make8(seconds2 * 1000); -var minutes = (minutes2) => make8(minutes2 * 60000); -var hours = (hours2) => make8(hours2 * 3600000); -var days = (days2) => make8(days2 * 86400000); -var weeks = (weeks2) => make8(weeks2 * 604800000); -var toMillis = (self) => match4(self, { - onMillis: (millis2) => millis2, - onNanos: (nanos2) => Number(nanos2) / 1e6 -}); -var toNanos = (self) => { - const _self = decode(self); - switch (_self.value._tag) { - case "Infinity": - return none2(); - case "Nanos": - return some2(_self.value.nanos); - case "Millis": - return some2(BigInt(Math.round(_self.value.millis * 1e6))); + [NodeInspectSymbol]() { + return this.toJSON(); } -}; -var unsafeToNanos = (self) => { - const _self = decode(self); - switch (_self.value._tag) { - case "Infinity": - throw new Error("Cannot convert infinite duration to nanos"); - case "Nanos": - return _self.value.nanos; - case "Millis": - return BigInt(Math.round(_self.value.millis * 1e6)); + [Symbol.iterator]() { + return new SingleShotGen2(new YieldWrap(this)); } -}; -var toHrTime = (self) => { - const _self = decode(self); - switch (_self.value._tag) { - case "Infinity": - return [Infinity, 0]; - case "Nanos": - return [Number(_self.value.nanos / bigint1e9), Number(_self.value.nanos % bigint1e9)]; - case "Millis": - return [Math.floor(_self.value.millis / 1000), Math.round(_self.value.millis % 1000 * 1e6)]; +} + +class EffectPrimitiveFailure { + _op; + effect_instruction_i0 = undefined; + effect_instruction_i1 = undefined; + effect_instruction_i2 = undefined; + trace = undefined; + [EffectTypeId2] = effectVariance; + constructor(_op) { + this._op = _op; + this._tag = _op; } -}; -var match4 = /* @__PURE__ */ dual(2, (self, options) => { - const _self = decode(self); - switch (_self.value._tag) { - case "Nanos": - return options.onNanos(_self.value.nanos); - case "Infinity": - return options.onMillis(Infinity); - case "Millis": - return options.onMillis(_self.value.millis); + [symbol2](that) { + return exitIsExit(that) && that._op === "Failure" && equals(this.effect_instruction_i0, that.effect_instruction_i0); } -}); -var matchWith = /* @__PURE__ */ dual(3, (self, that, options) => { - const _self = decode(self); - const _that = decode(that); - if (_self.value._tag === "Infinity" || _that.value._tag === "Infinity") { - return options.onMillis(toMillis(_self), toMillis(_that)); - } else if (_self.value._tag === "Nanos" || _that.value._tag === "Nanos") { - const selfNanos = _self.value._tag === "Nanos" ? _self.value.nanos : BigInt(Math.round(_self.value.millis * 1e6)); - const thatNanos = _that.value._tag === "Nanos" ? _that.value.nanos : BigInt(Math.round(_that.value.millis * 1e6)); - return options.onNanos(selfNanos, thatNanos); + [symbol]() { + return pipe(string(this._tag), combine(hash(this.effect_instruction_i0)), cached(this)); } - return options.onMillis(_self.value.millis, _that.value.millis); -}); -var Order4 = /* @__PURE__ */ make2((self, that) => matchWith(self, that, { - onMillis: (self2, that2) => self2 < that2 ? -1 : self2 > that2 ? 1 : 0, - onNanos: (self2, that2) => self2 < that2 ? -1 : self2 > that2 ? 1 : 0 -})); -var between3 = /* @__PURE__ */ between(/* @__PURE__ */ mapInput2(Order4, decode)); -var Equivalence2 = (self, that) => matchWith(self, that, { - onMillis: (self2, that2) => self2 === that2, - onNanos: (self2, that2) => self2 === that2 -}); -var _clamp = /* @__PURE__ */ clamp(Order4); -var clamp6 = /* @__PURE__ */ dual(2, (self, options) => _clamp(decode(self), { - minimum: decode(options.minimum), - maximum: decode(options.maximum) -})); -var lessThan3 = /* @__PURE__ */ dual(2, (self, that) => matchWith(self, that, { - onMillis: (self2, that2) => self2 < that2, - onNanos: (self2, that2) => self2 < that2 -})); -var lessThanOrEqualTo3 = /* @__PURE__ */ dual(2, (self, that) => matchWith(self, that, { - onMillis: (self2, that2) => self2 <= that2, - onNanos: (self2, that2) => self2 <= that2 -})); -var greaterThan3 = /* @__PURE__ */ dual(2, (self, that) => matchWith(self, that, { - onMillis: (self2, that2) => self2 > that2, - onNanos: (self2, that2) => self2 > that2 -})); -var greaterThanOrEqualTo3 = /* @__PURE__ */ dual(2, (self, that) => matchWith(self, that, { - onMillis: (self2, that2) => self2 >= that2, - onNanos: (self2, that2) => self2 >= that2 -})); -var equals4 = /* @__PURE__ */ dual(2, (self, that) => Equivalence2(decode(self), decode(that))); -var parts = (self) => { - const duration = decode(self); - if (duration.value._tag === "Infinity") { + get cause() { + return this.effect_instruction_i0; + } + pipe() { + return pipeArguments(this, arguments); + } + toJSON() { return { - days: Infinity, - hours: Infinity, - minutes: Infinity, - seconds: Infinity, - millis: Infinity, - nanos: Infinity + _id: "Exit", + _tag: this._op, + cause: this.cause.toJSON() }; } - const nanos2 = unsafeToNanos(duration); - const ms = nanos2 / bigint1e6; - const sec = ms / bigint1e3; - const min2 = sec / bigint60; - const hr = min2 / bigint60; - const days2 = hr / bigint24; - return { - days: Number(days2), - hours: Number(hr % bigint24), - minutes: Number(min2 % bigint60), - seconds: Number(sec % bigint60), - millis: Number(ms % bigint1e3), - nanos: Number(nanos2 % bigint1e6) - }; -}; -var format3 = (self) => { - const duration = decode(self); - if (duration.value._tag === "Infinity") { - return "Infinity"; + toString() { + return format(this.toJSON()); } - if (isZero2(duration)) { - return "0"; + [NodeInspectSymbol]() { + return this.toJSON(); } - const fragments = parts(duration); - const pieces = []; - if (fragments.days !== 0) { - pieces.push(`${fragments.days}d`); + [Symbol.iterator]() { + return new SingleShotGen2(new YieldWrap(this)); } - if (fragments.hours !== 0) { - pieces.push(`${fragments.hours}h`); +} + +class EffectPrimitiveSuccess { + _op; + effect_instruction_i0 = undefined; + effect_instruction_i1 = undefined; + effect_instruction_i2 = undefined; + trace = undefined; + [EffectTypeId2] = effectVariance; + constructor(_op) { + this._op = _op; + this._tag = _op; } - if (fragments.minutes !== 0) { - pieces.push(`${fragments.minutes}m`); + [symbol2](that) { + return exitIsExit(that) && that._op === "Success" && equals(this.effect_instruction_i0, that.effect_instruction_i0); } - if (fragments.seconds !== 0) { - pieces.push(`${fragments.seconds}s`); + [symbol]() { + return pipe(string(this._tag), combine(hash(this.effect_instruction_i0)), cached(this)); } - if (fragments.millis !== 0) { - pieces.push(`${fragments.millis}ms`); + get value() { + return this.effect_instruction_i0; } - if (fragments.nanos !== 0) { - pieces.push(`${fragments.nanos}ns`); + pipe() { + return pipeArguments(this, arguments); } - return pieces.join(" "); -}; - -// node_modules/effect/dist/esm/internal/hashMap/config.js -var SIZE = 5; -var BUCKET_SIZE = /* @__PURE__ */ Math.pow(2, SIZE); -var MASK = BUCKET_SIZE - 1; -var MAX_INDEX_NODE = BUCKET_SIZE / 2; -var MIN_ARRAY_NODE = BUCKET_SIZE / 4; - -// node_modules/effect/dist/esm/internal/hashMap/bitwise.js -function popcount(x) { - x -= x >> 1 & 1431655765; - x = (x & 858993459) + (x >> 2 & 858993459); - x = x + (x >> 4) & 252645135; - x += x >> 8; - x += x >> 16; - return x & 127; -} -function hashFragment(shift, h) { - return h >>> shift & MASK; -} -function toBitmap(x) { - return 1 << x; -} -function fromBitmap(bitmap, bit) { - return popcount(bitmap & bit - 1); -} - -// node_modules/effect/dist/esm/internal/stack.js -var make9 = (value, previous) => ({ - value, - previous -}); - -// node_modules/effect/dist/esm/internal/hashMap/array.js -function arrayUpdate(mutate, at, v, arr) { - let out = arr; - if (!mutate) { - const len = arr.length; - out = new Array(len); - for (let i = 0;i < len; ++i) - out[i] = arr[i]; - } - out[at] = v; - return out; -} -function arraySpliceOut(mutate, at, arr) { - const newLen = arr.length - 1; - let i = 0; - let g = 0; - let out = arr; - if (mutate) { - i = g = at; - } else { - out = new Array(newLen); - while (i < at) - out[g++] = arr[i++]; + toJSON() { + return { + _id: "Exit", + _tag: this._op, + value: toJSON(this.value) + }; } - ++i; - while (i <= newLen) - out[g++] = arr[i++]; - if (mutate) { - out.length = newLen; + toString() { + return format(this.toJSON()); } - return out; -} -function arraySpliceIn(mutate, at, v, arr) { - const len = arr.length; - if (mutate) { - let i2 = len; - while (i2 >= at) - arr[i2--] = arr[i2]; - arr[at] = v; - return arr; + [NodeInspectSymbol]() { + return this.toJSON(); } - let i = 0, g = 0; - const out = new Array(len + 1); - while (i < at) - out[g++] = arr[i++]; - out[at] = v; - while (i < len) - out[++g] = arr[i++]; - return out; -} - -// node_modules/effect/dist/esm/internal/hashMap/node.js -class EmptyNode { - _tag = "EmptyNode"; - modify(edit, _shift, f, hash2, key, size) { - const v = f(none2()); - if (isNone2(v)) - return new EmptyNode; - ++size.value; - return new LeafNode(edit, hash2, key, v); + [Symbol.iterator]() { + return new SingleShotGen2(new YieldWrap(this)); } } -function isEmptyNode(a) { - return isTagged(a, "EmptyNode"); -} -function isLeafNode(node) { - return isEmptyNode(node) || node._tag === "LeafNode" || node._tag === "CollisionNode"; -} -function canEditNode(node, edit) { - return isEmptyNode(node) ? false : edit === node.edit; -} - -class LeafNode { - edit; - hash; - key; - value; - _tag = "LeafNode"; - constructor(edit, hash2, key, value) { - this.edit = edit; - this.hash = hash2; - this.key = key; - this.value = value; - } - modify(edit, shift, f, hash2, key, size) { - if (equals(key, this.key)) { - const v2 = f(this.value); - if (v2 === this.value) - return this; - else if (isNone2(v2)) { - --size.value; - return new EmptyNode; - } - if (canEditNode(this, edit)) { - this.value = v2; - return this; +var isEffect = (u) => hasProperty(u, EffectTypeId2); +var withFiberRuntime = (withRuntime) => { + const effect = new EffectPrimitive(OP_WITH_RUNTIME); + effect.effect_instruction_i0 = withRuntime; + return effect; +}; +var acquireUseRelease = /* @__PURE__ */ dual(3, (acquire, use, release) => uninterruptibleMask((restore) => flatMap7(acquire, (a) => flatMap7(exit(suspend(() => restore(use(a)))), (exit) => { + return suspend(() => release(a, exit)).pipe(matchCauseEffect({ + onFailure: (cause) => { + switch (exit._tag) { + case OP_FAILURE: + return failCause(sequential(exit.effect_instruction_i0, cause)); + case OP_SUCCESS: + return failCause(cause); } - return new LeafNode(edit, hash2, key, v2); + }, + onSuccess: () => exit + })); +})))); +var as = /* @__PURE__ */ dual(2, (self, value) => flatMap7(self, () => succeed(value))); +var asVoid = (self) => as(self, undefined); +var custom = function() { + const wrapper = new EffectPrimitive(OP_COMMIT); + switch (arguments.length) { + case 2: { + wrapper.effect_instruction_i0 = arguments[0]; + wrapper.commit = arguments[1]; + break; } - const v = f(none2()); - if (isNone2(v)) - return this; - ++size.value; - return mergeLeaves(edit, shift, this.hash, this, hash2, new LeafNode(edit, hash2, key, v)); - } -} - -class CollisionNode { - edit; - hash; - children; - _tag = "CollisionNode"; - constructor(edit, hash2, children) { - this.edit = edit; - this.hash = hash2; - this.children = children; - } - modify(edit, shift, f, hash2, key, size) { - if (hash2 === this.hash) { - const canEdit = canEditNode(this, edit); - const list = this.updateCollisionList(canEdit, edit, this.hash, this.children, f, key, size); - if (list === this.children) - return this; - return list.length > 1 ? new CollisionNode(edit, this.hash, list) : list[0]; + case 3: { + wrapper.effect_instruction_i0 = arguments[0]; + wrapper.effect_instruction_i1 = arguments[1]; + wrapper.commit = arguments[2]; + break; + } + case 4: { + wrapper.effect_instruction_i0 = arguments[0]; + wrapper.effect_instruction_i1 = arguments[1]; + wrapper.effect_instruction_i2 = arguments[2]; + wrapper.commit = arguments[3]; + break; + } + default: { + throw new Error(getBugErrorMessage("you're not supposed to end up here")); } - const v = f(none2()); - if (isNone2(v)) - return this; - ++size.value; - return mergeLeaves(edit, shift, this.hash, this, hash2, new LeafNode(edit, hash2, key, v)); } - updateCollisionList(mutate, edit, hash2, list, f, key, size) { - const len = list.length; - for (let i = 0;i < len; ++i) { - const child = list[i]; - if ("key" in child && equals(key, child.key)) { - const value = child.value; - const newValue2 = f(value); - if (newValue2 === value) - return list; - if (isNone2(newValue2)) { - --size.value; - return arraySpliceOut(mutate, i, list); - } - return arrayUpdate(mutate, i, new LeafNode(edit, hash2, key, newValue2), list); + return wrapper; +}; +var unsafeAsync = (register, blockingOn = none4) => { + const effect = new EffectPrimitive(OP_ASYNC); + let cancelerRef = undefined; + effect.effect_instruction_i0 = (resume) => { + cancelerRef = register(resume); + }; + effect.effect_instruction_i1 = blockingOn; + return onInterrupt(effect, (_) => isEffect(cancelerRef) ? cancelerRef : void_); +}; +var asyncInterrupt = (register, blockingOn = none4) => suspend(() => unsafeAsync(register, blockingOn)); +var async_ = (resume, blockingOn = none4) => { + return custom(resume, function() { + let backingResume = undefined; + let pendingEffect = undefined; + function proxyResume(effect2) { + if (backingResume) { + backingResume(effect2); + } else if (pendingEffect === undefined) { + pendingEffect = effect2; } } - const newValue = f(none2()); - if (isNone2(newValue)) - return list; - ++size.value; - return arrayUpdate(mutate, len, new LeafNode(edit, hash2, key, newValue), list); - } -} - -class IndexedNode { - edit; - mask; - children; - _tag = "IndexedNode"; - constructor(edit, mask, children) { - this.edit = edit; - this.mask = mask; - this.children = children; - } - modify(edit, shift, f, hash2, key, size) { - const mask = this.mask; - const children = this.children; - const frag = hashFragment(shift, hash2); - const bit = toBitmap(frag); - const indx = fromBitmap(mask, bit); - const exists2 = mask & bit; - const canEdit = canEditNode(this, edit); - if (!exists2) { - const _newChild = new EmptyNode().modify(edit, shift + SIZE, f, hash2, key, size); - if (!_newChild) - return this; - return children.length >= MAX_INDEX_NODE ? expand(edit, frag, _newChild, mask, children) : new IndexedNode(edit, mask | bit, arraySpliceIn(canEdit, indx, _newChild, children)); - } - const current = children[indx]; - const child = current.modify(edit, shift + SIZE, f, hash2, key, size); - if (current === child) - return this; - let bitmap = mask; - let newChildren; - if (isEmptyNode(child)) { - bitmap &= ~bit; - if (!bitmap) - return new EmptyNode; - if (children.length <= 2 && isLeafNode(children[indx ^ 1])) { - return children[indx ^ 1]; - } - newChildren = arraySpliceOut(canEdit, indx, children); - } else { - newChildren = arrayUpdate(canEdit, indx, child, children); - } - if (canEdit) { - this.mask = bitmap; - this.children = newChildren; - return this; - } - return new IndexedNode(edit, bitmap, newChildren); - } -} - -class ArrayNode { - edit; - size; - children; - _tag = "ArrayNode"; - constructor(edit, size, children) { - this.edit = edit; - this.size = size; - this.children = children; - } - modify(edit, shift, f, hash2, key, size) { - let count = this.size; - const children = this.children; - const frag = hashFragment(shift, hash2); - const child = children[frag]; - const newChild = (child || new EmptyNode).modify(edit, shift + SIZE, f, hash2, key, size); - if (child === newChild) - return this; - const canEdit = canEditNode(this, edit); - let newChildren; - if (isEmptyNode(child) && !isEmptyNode(newChild)) { - ++count; - newChildren = arrayUpdate(canEdit, frag, newChild, children); - } else if (!isEmptyNode(child) && isEmptyNode(newChild)) { - --count; - if (count <= MIN_ARRAY_NODE) { - return pack(edit, count, frag, children); + const effect = new EffectPrimitive(OP_ASYNC); + effect.effect_instruction_i0 = (resume2) => { + backingResume = resume2; + if (pendingEffect) { + resume2(pendingEffect); } - newChildren = arrayUpdate(canEdit, frag, new EmptyNode, children); + }; + effect.effect_instruction_i1 = blockingOn; + let cancelerRef = undefined; + let controllerRef = undefined; + if (this.effect_instruction_i0.length !== 1) { + controllerRef = new AbortController; + cancelerRef = internalCall(() => this.effect_instruction_i0(proxyResume, controllerRef.signal)); } else { - newChildren = arrayUpdate(canEdit, frag, newChild, children); - } - if (canEdit) { - this.size = count; - this.children = newChildren; - return this; + cancelerRef = internalCall(() => this.effect_instruction_i0(proxyResume)); } - return new ArrayNode(edit, count, newChildren); - } -} -function pack(edit, count, removed, elements) { - const children = new Array(count - 1); - let g = 0; - let bitmap = 0; - for (let i = 0, len = elements.length;i < len; ++i) { - if (i !== removed) { - const elem = elements[i]; - if (elem && !isEmptyNode(elem)) { - children[g++] = elem; - bitmap |= 1 << i; + return cancelerRef || controllerRef ? onInterrupt(effect, (_) => { + if (controllerRef) { + controllerRef.abort(); } - } - } - return new IndexedNode(edit, bitmap, children); -} -function expand(edit, frag, child, bitmap, subNodes) { - const arr = []; - let bit = bitmap; - let count = 0; - for (let i = 0;bit; ++i) { - if (bit & 1) - arr[i] = subNodes[count++]; - bit >>>= 1; - } - arr[frag] = child; - return new ArrayNode(edit, count + 1, arr); -} -function mergeLeavesInner(edit, shift, h1, n1, h2, n2) { - if (h1 === h2) - return new CollisionNode(edit, h1, [n2, n1]); - const subH1 = hashFragment(shift, h1); - const subH2 = hashFragment(shift, h2); - if (subH1 === subH2) { - return (child) => new IndexedNode(edit, toBitmap(subH1) | toBitmap(subH2), [child]); - } else { - const children = subH1 < subH2 ? [n1, n2] : [n2, n1]; - return new IndexedNode(edit, toBitmap(subH1) | toBitmap(subH2), children); + return cancelerRef ?? void_; + }) : effect; + }); +}; +var catchAllCause = /* @__PURE__ */ dual(2, (self, f) => { + const effect = new EffectPrimitive(OP_ON_FAILURE); + effect.effect_instruction_i0 = self; + effect.effect_instruction_i1 = f; + return effect; +}); +var catchAll = /* @__PURE__ */ dual(2, (self, f) => matchEffect(self, { + onFailure: f, + onSuccess: succeed +})); +var catchIf = /* @__PURE__ */ dual(3, (self, predicate, f) => catchAllCause(self, (cause) => { + const either2 = failureOrCause(cause); + switch (either2._tag) { + case "Left": + return predicate(either2.left) ? f(either2.left) : failCause(cause); + case "Right": + return failCause(either2.right); } -} -function mergeLeaves(edit, shift, h1, n1, h2, n2) { - let stack = undefined; - let currentShift = shift; - while (true) { - const res = mergeLeavesInner(edit, currentShift, h1, n1, h2, n2); - if (typeof res === "function") { - stack = make9(res, stack); - currentShift = currentShift + SIZE; - } else { - let final = res; - while (stack != null) { - final = stack.value(final); - stack = stack.previous; - } - return final; - } +})); +var catchSome = /* @__PURE__ */ dual(2, (self, pf) => catchAllCause(self, (cause) => { + const either2 = failureOrCause(cause); + switch (either2._tag) { + case "Left": + return pipe(pf(either2.left), getOrElse(() => failCause(cause))); + case "Right": + return failCause(either2.right); } -} - -// node_modules/effect/dist/esm/internal/hashMap.js -var HashMapSymbolKey = "effect/HashMap"; -var HashMapTypeId = /* @__PURE__ */ Symbol.for(HashMapSymbolKey); -var HashMapProto = { - [HashMapTypeId]: HashMapTypeId, - [Symbol.iterator]() { - return new HashMapIterator(this, (k, v) => [k, v]); - }, - [symbol]() { - let hash2 = hash(HashMapSymbolKey); - for (const item of this) { - hash2 ^= pipe(hash(item[0]), combine(hash(item[1]))); - } - return cached(this, hash2); - }, - [symbol2](that) { - if (isHashMap(that)) { - if (that._size !== this._size) { - return false; - } - for (const item of this) { - const elem = pipe(that, getHash(item[0], hash(item[0]))); - if (isNone2(elem)) { - return false; - } else { - if (!equals(item[1], elem.value)) { - return false; - } +})); +var checkInterruptible = (f) => withFiberRuntime((_, status) => f(interruption(status.runtimeFlags))); +var originalSymbol = /* @__PURE__ */ Symbol.for("effect/OriginalAnnotation"); +var capture = (obj, span2) => { + if (isSome2(span2)) { + return new Proxy(obj, { + has(target, p) { + return p === spanSymbol || p === originalSymbol || p in target; + }, + get(target, p) { + if (p === spanSymbol) { + return span2.value; + } + if (p === originalSymbol) { + return obj; } + return target[p]; } - return true; - } - return false; - }, - toString() { - return format(this.toJSON()); - }, - toJSON() { - return { - _id: "HashMap", - values: Array.from(this).map(toJSON) - }; - }, - [NodeInspectSymbol]() { - return this.toJSON(); - }, - pipe() { - return pipeArguments(this, arguments); + }); } + return obj; }; -var makeImpl = (editable, edit, root, size) => { - const map4 = Object.create(HashMapProto); - map4._editable = editable; - map4._edit = edit; - map4._root = root; - map4._size = size; - return map4; -}; - -class HashMapIterator { - map; - f; - v; - constructor(map4, f) { - this.map = map4; - this.f = f; - this.v = visitLazy(this.map._root, this.f, undefined); +var die2 = (defect) => isObject(defect) && !(spanSymbol in defect) ? withFiberRuntime((fiber) => failCause(die(capture(defect, currentSpanFromFiber(fiber))))) : failCause(die(defect)); +var dieMessage = (message) => failCauseSync(() => die(new RuntimeException(message))); +var dieSync = (evaluate) => flatMap7(sync(evaluate), die2); +var either2 = (self) => matchEffect(self, { + onFailure: (e) => succeed(left2(e)), + onSuccess: (a) => succeed(right2(a)) +}); +var exit = (self) => matchCause(self, { + onFailure: exitFailCause, + onSuccess: exitSucceed +}); +var fail2 = (error) => isObject(error) && !(spanSymbol in error) ? withFiberRuntime((fiber) => failCause(fail(capture(error, currentSpanFromFiber(fiber))))) : failCause(fail(error)); +var failSync = (evaluate) => flatMap7(sync(evaluate), fail2); +var failCause = (cause) => { + const effect = new EffectPrimitiveFailure(OP_FAILURE); + effect.effect_instruction_i0 = cause; + return effect; +}; +var failCauseSync = (evaluate) => flatMap7(sync(evaluate), failCause); +var fiberId = /* @__PURE__ */ withFiberRuntime((state) => succeed(state.id())); +var fiberIdWith = (f) => withFiberRuntime((state) => f(state.id())); +var flatMap7 = /* @__PURE__ */ dual(2, (self, f) => { + const effect = new EffectPrimitive(OP_ON_SUCCESS); + effect.effect_instruction_i0 = self; + effect.effect_instruction_i1 = f; + return effect; +}); +var andThen2 = /* @__PURE__ */ dual(2, (self, f) => flatMap7(self, (a) => { + const b = typeof f === "function" ? f(a) : f; + if (isEffect(b)) { + return b; + } else if (isPromiseLike(b)) { + return unsafeAsync((resume) => { + b.then((a2) => resume(succeed(a2)), (e) => resume(fail2(new UnknownException(e, "An unknown error occurred in Effect.andThen")))); + }); } - next() { - if (isNone2(this.v)) { - return { - done: true, - value: undefined - }; + return succeed(b); +})); +var step2 = (self) => { + const effect = new EffectPrimitive("OnStep"); + effect.effect_instruction_i0 = self; + return effect; +}; +var flatten4 = (self) => flatMap7(self, identity); +var flip = (self) => matchEffect(self, { + onFailure: succeed, + onSuccess: fail2 +}); +var matchCause = /* @__PURE__ */ dual(2, (self, options) => matchCauseEffect(self, { + onFailure: (cause) => succeed(options.onFailure(cause)), + onSuccess: (a) => succeed(options.onSuccess(a)) +})); +var matchCauseEffect = /* @__PURE__ */ dual(2, (self, options) => { + const effect = new EffectPrimitive(OP_ON_SUCCESS_AND_FAILURE); + effect.effect_instruction_i0 = self; + effect.effect_instruction_i1 = options.onFailure; + effect.effect_instruction_i2 = options.onSuccess; + return effect; +}); +var matchEffect = /* @__PURE__ */ dual(2, (self, options) => matchCauseEffect(self, { + onFailure: (cause) => { + const defects2 = defects(cause); + if (defects2.length > 0) { + return failCause(electFailures(cause)); } - const v0 = this.v.value; - this.v = applyCont(v0.cont); - return { - done: false, - value: v0.value - }; - } - [Symbol.iterator]() { - return new HashMapIterator(this.map, this.f); - } -} -var applyCont = (cont) => cont ? visitLazyChildren(cont[0], cont[1], cont[2], cont[3], cont[4]) : none2(); -var visitLazy = (node, f, cont = undefined) => { - switch (node._tag) { - case "LeafNode": { - if (isSome2(node.value)) { - return some2({ - value: f(node.key, node.value.value), - cont - }); - } - return applyCont(cont); + const failures2 = failures(cause); + if (failures2.length > 0) { + return options.onFailure(unsafeHead(failures2)); } - case "CollisionNode": - case "ArrayNode": - case "IndexedNode": { - const children = node.children; - return visitLazyChildren(children.length, children, 0, f, cont); + return failCause(cause); + }, + onSuccess: options.onSuccess +})); +var forEachSequential = /* @__PURE__ */ dual(2, (self, f) => suspend(() => { + const arr = fromIterable(self); + const ret = allocate(arr.length); + let i = 0; + return as(whileLoop({ + while: () => i < arr.length, + body: () => f(arr[i], i), + step: (b) => { + ret[i++] = b; } - default: { - return applyCont(cont); + }), ret); +})); +var forEachSequentialDiscard = /* @__PURE__ */ dual(2, (self, f) => suspend(() => { + const arr = fromIterable(self); + let i = 0; + return whileLoop({ + while: () => i < arr.length, + body: () => f(arr[i], i), + step: () => { + i++; } - } + }); +})); +var if_ = /* @__PURE__ */ dual((args) => typeof args[0] === "boolean" || isEffect(args[0]), (self, options) => isEffect(self) ? flatMap7(self, (b) => b ? options.onTrue() : options.onFalse()) : self ? options.onTrue() : options.onFalse()); +var interrupt2 = /* @__PURE__ */ flatMap7(fiberId, (fiberId2) => interruptWith(fiberId2)); +var interruptWith = (fiberId2) => failCause(interrupt(fiberId2)); +var interruptible2 = (self) => { + const effect = new EffectPrimitive(OP_UPDATE_RUNTIME_FLAGS); + effect.effect_instruction_i0 = enable3(Interruption); + effect.effect_instruction_i1 = () => self; + return effect; }; -var visitLazyChildren = (len, children, i, f, cont) => { - while (i < len) { - const child = children[i++]; - if (child && !isEmptyNode(child)) { - return visitLazy(child, f, [len, children, i, f, cont]); +var interruptibleMask = (f) => custom(f, function() { + const effect = new EffectPrimitive(OP_UPDATE_RUNTIME_FLAGS); + effect.effect_instruction_i0 = enable3(Interruption); + effect.effect_instruction_i1 = (oldFlags) => interruption(oldFlags) ? internalCall(() => this.effect_instruction_i0(interruptible2)) : internalCall(() => this.effect_instruction_i0(uninterruptible)); + return effect; +}); +var intoDeferred = /* @__PURE__ */ dual(2, (self, deferred) => uninterruptibleMask((restore) => flatMap7(exit(restore(self)), (exit2) => deferredDone(deferred, exit2)))); +var map9 = /* @__PURE__ */ dual(2, (self, f) => flatMap7(self, (a) => sync(() => f(a)))); +var mapBoth2 = /* @__PURE__ */ dual(2, (self, options) => matchEffect(self, { + onFailure: (e) => failSync(() => options.onFailure(e)), + onSuccess: (a) => sync(() => options.onSuccess(a)) +})); +var mapError = /* @__PURE__ */ dual(2, (self, f) => matchCauseEffect(self, { + onFailure: (cause) => { + const either3 = failureOrCause(cause); + switch (either3._tag) { + case "Left": { + return failSync(() => f(either3.left)); + } + case "Right": { + return failCause(either3.right); + } } + }, + onSuccess: succeed +})); +var onError = /* @__PURE__ */ dual(2, (self, cleanup) => onExit(self, (exit2) => exitIsSuccess(exit2) ? void_ : cleanup(exit2.effect_instruction_i0))); +var onExit = /* @__PURE__ */ dual(2, (self, cleanup) => uninterruptibleMask((restore) => matchCauseEffect(restore(self), { + onFailure: (cause1) => { + const result = exitFailCause(cause1); + return matchCauseEffect(cleanup(result), { + onFailure: (cause2) => exitFailCause(sequential(cause1, cause2)), + onSuccess: () => result + }); + }, + onSuccess: (success) => { + const result = exitSucceed(success); + return zipRight(cleanup(result), result); } - return applyCont(cont); +}))); +var onInterrupt = /* @__PURE__ */ dual(2, (self, cleanup) => onExit(self, exitMatch({ + onFailure: (cause) => isInterruptedOnly(cause) ? asVoid(cleanup(interruptors(cause))) : void_, + onSuccess: () => void_ +}))); +var orElse2 = /* @__PURE__ */ dual(2, (self, that) => attemptOrElse(self, that, succeed)); +var orDie = (self) => orDieWith(self, identity); +var orDieWith = /* @__PURE__ */ dual(2, (self, f) => matchEffect(self, { + onFailure: (e) => die2(f(e)), + onSuccess: succeed +})); +var partitionMap2 = partitionMap; +var runtimeFlags = /* @__PURE__ */ withFiberRuntime((_, status) => succeed(status.runtimeFlags)); +var succeed = (value) => { + const effect = new EffectPrimitiveSuccess(OP_SUCCESS); + effect.effect_instruction_i0 = value; + return effect; }; -var _empty3 = /* @__PURE__ */ makeImpl(false, 0, /* @__PURE__ */ new EmptyNode, 0); -var empty5 = () => _empty3; -var fromIterable3 = (entries) => { - const map4 = beginMutation(empty5()); - for (const entry of entries) { - set(map4, entry[0], entry[1]); +var suspend = (evaluate) => { + const effect = new EffectPrimitive(OP_COMMIT); + effect.commit = evaluate; + return effect; +}; +var sync = (thunk) => { + const effect = new EffectPrimitive(OP_SYNC); + effect.effect_instruction_i0 = thunk; + return effect; +}; +var tap = /* @__PURE__ */ dual((args) => args.length === 3 || args.length === 2 && !(isObject(args[1]) && ("onlyEffect" in args[1])), (self, f) => flatMap7(self, (a) => { + const b = typeof f === "function" ? f(a) : f; + if (isEffect(b)) { + return as(b, a); + } else if (isPromiseLike(b)) { + return unsafeAsync((resume) => { + b.then((_) => resume(succeed(a)), (e) => resume(fail2(new UnknownException(e, "An unknown error occurred in Effect.tap")))); + }); } - return endMutation(map4); + return succeed(a); +})); +var transplant = (f) => withFiberRuntime((state) => { + const scopeOverride = state.getFiberRef(currentForkScopeOverride); + const scope = pipe(scopeOverride, getOrElse(() => state.scope())); + return f(fiberRefLocally(currentForkScopeOverride, some2(scope))); +}); +var attemptOrElse = /* @__PURE__ */ dual(3, (self, that, onSuccess) => matchCauseEffect(self, { + onFailure: (cause) => { + const defects2 = defects(cause); + if (defects2.length > 0) { + return failCause(getOrThrow2(keepDefectsAndElectFailures(cause))); + } + return that(); + }, + onSuccess +})); +var uninterruptible = (self) => { + const effect = new EffectPrimitive(OP_UPDATE_RUNTIME_FLAGS); + effect.effect_instruction_i0 = disable3(Interruption); + effect.effect_instruction_i1 = () => self; + return effect; }; -var isHashMap = (u) => hasProperty(u, HashMapTypeId); -var isEmpty2 = (self) => self && isEmptyNode(self._root); -var get5 = /* @__PURE__ */ dual(2, (self, key) => getHash(self, key, hash(key))); -var getHash = /* @__PURE__ */ dual(3, (self, key, hash2) => { - let node = self._root; - let shift = 0; - while (true) { - switch (node._tag) { - case "LeafNode": { - return equals(key, node.key) ? node.value : none2(); - } - case "CollisionNode": { - if (hash2 === node.hash) { - const children = node.children; - for (let i = 0, len = children.length;i < len; ++i) { - const child = children[i]; - if ("key" in child && equals(key, child.key)) { - return child.value; - } - } - } - return none2(); - } - case "IndexedNode": { - const frag = hashFragment(shift, hash2); - const bit = toBitmap(frag); - if (node.mask & bit) { - node = node.children[fromBitmap(node.mask, bit)]; - shift += SIZE; - break; - } - return none2(); - } - case "ArrayNode": { - node = node.children[hashFragment(shift, hash2)]; - if (node) { - shift += SIZE; - break; - } - return none2(); - } - default: - return none2(); - } - } +var uninterruptibleMask = (f) => custom(f, function() { + const effect = new EffectPrimitive(OP_UPDATE_RUNTIME_FLAGS); + effect.effect_instruction_i0 = disable3(Interruption); + effect.effect_instruction_i1 = (oldFlags) => interruption(oldFlags) ? internalCall(() => this.effect_instruction_i0(interruptible2)) : internalCall(() => this.effect_instruction_i0(uninterruptible)); + return effect; }); -var has = /* @__PURE__ */ dual(2, (self, key) => isSome2(getHash(self, key, hash(key)))); -var set = /* @__PURE__ */ dual(3, (self, key, value) => modifyAt(self, key, () => some2(value))); -var setTree = /* @__PURE__ */ dual(3, (self, newRoot, newSize) => { - if (self._editable) { - self._root = newRoot; - self._size = newSize; - return self; +var void_ = /* @__PURE__ */ succeed(undefined); +var updateRuntimeFlags = (patch5) => { + const effect = new EffectPrimitive(OP_UPDATE_RUNTIME_FLAGS); + effect.effect_instruction_i0 = patch5; + effect.effect_instruction_i1 = undefined; + return effect; +}; +var whenEffect = /* @__PURE__ */ dual(2, (self, condition) => flatMap7(condition, (b) => { + if (b) { + return pipe(self, map9(some2)); } - return newRoot === self._root ? self : makeImpl(self._editable, self._edit, newRoot, newSize); + return succeed(none2()); +})); +var whileLoop = (options) => { + const effect = new EffectPrimitive(OP_WHILE); + effect.effect_instruction_i0 = options.while; + effect.effect_instruction_i1 = options.body; + effect.effect_instruction_i2 = options.step; + return effect; +}; +var fromIterator = (iterator) => suspend(() => { + const effect = new EffectPrimitive(OP_ITERATOR); + effect.effect_instruction_i0 = iterator(); + return effect; }); -var keys = (self) => new HashMapIterator(self, (key) => key); -var size = (self) => self._size; -var beginMutation = (self) => makeImpl(true, self._edit + 1, self._root, self._size); -var endMutation = (self) => { - self._editable = false; - return self; +var gen = function() { + const f = arguments.length === 1 ? arguments[0] : arguments[1].bind(arguments[0]); + return fromIterator(() => f(pipe)); }; -var mutate = /* @__PURE__ */ dual(2, (self, f) => { - const transient = beginMutation(self); - f(transient); - return endMutation(transient); +var fnUntraced = (body, ...pipeables) => Object.defineProperty(pipeables.length === 0 ? function(...args) { + return fromIterator(() => body.apply(this, args)); +} : function(...args) { + let effect = fromIterator(() => body.apply(this, args)); + for (const x of pipeables) { + effect = x(effect, ...args); + } + return effect; +}, "length", { + value: body.length, + configurable: true }); -var modifyAt = /* @__PURE__ */ dual(3, (self, key, f) => modifyHash(self, key, hash(key), f)); -var modifyHash = /* @__PURE__ */ dual(4, (self, key, hash2, f) => { - const size2 = { - value: self._size - }; - const newRoot = self._root.modify(self._editable ? self._edit : NaN, 0, f, hash2, key, size2); - return pipe(self, setTree(newRoot, size2.value)); +var withConcurrency = /* @__PURE__ */ dual(2, (self, concurrency) => fiberRefLocally(self, currentConcurrency, concurrency)); +var withRequestBatching = /* @__PURE__ */ dual(2, (self, requestBatching) => fiberRefLocally(self, currentRequestBatching, requestBatching)); +var withRuntimeFlags = /* @__PURE__ */ dual(2, (self, update2) => { + const effect = new EffectPrimitive(OP_UPDATE_RUNTIME_FLAGS); + effect.effect_instruction_i0 = update2; + effect.effect_instruction_i1 = () => self; + return effect; }); -var remove2 = /* @__PURE__ */ dual(2, (self, key) => modifyAt(self, key, none2)); -var map4 = /* @__PURE__ */ dual(2, (self, f) => reduce2(self, empty5(), (map5, value, key) => set(map5, key, f(value, key)))); -var forEach = /* @__PURE__ */ dual(2, (self, f) => reduce2(self, undefined, (_, value, key) => f(value, key))); -var reduce2 = /* @__PURE__ */ dual(3, (self, zero3, f) => { - const root = self._root; - if (root._tag === "LeafNode") { - return isSome2(root.value) ? f(zero3, root.value.value, root.key) : zero3; - } - if (root._tag === "EmptyNode") { - return zero3; - } - const toVisit = [root.children]; - let children; - while (children = toVisit.pop()) { - for (let i = 0, len = children.length;i < len; ) { - const child = children[i++]; - if (child && !isEmptyNode(child)) { - if (child._tag === "LeafNode") { - if (isSome2(child.value)) { - zero3 = f(zero3, child.value.value, child.key); - } - } else { - toVisit.push(child.children); - } - } - } - } - return zero3; +var withTracerEnabled = /* @__PURE__ */ dual(2, (effect, enabled2) => fiberRefLocally(effect, currentTracerEnabled, enabled2)); +var withTracerTiming = /* @__PURE__ */ dual(2, (effect, enabled2) => fiberRefLocally(effect, currentTracerTimingEnabled, enabled2)); +var yieldNow = (options) => { + const effect = new EffectPrimitive(OP_YIELD); + return typeof options?.priority !== "undefined" ? withSchedulingPriority(effect, options.priority) : effect; +}; +var zip2 = /* @__PURE__ */ dual(2, (self, that) => flatMap7(self, (a) => map9(that, (b) => [a, b]))); +var zipLeft = /* @__PURE__ */ dual(2, (self, that) => flatMap7(self, (a) => as(that, a))); +var zipRight = /* @__PURE__ */ dual(2, (self, that) => flatMap7(self, () => that)); +var zipWith2 = /* @__PURE__ */ dual(3, (self, that, f) => flatMap7(self, (a) => map9(that, (b) => f(a, b)))); +var never = /* @__PURE__ */ asyncInterrupt(() => { + const interval = setInterval(() => {}, 2 ** 31 - 1); + return sync(() => clearInterval(interval)); }); - -// node_modules/effect/dist/esm/internal/hashSet.js -var HashSetSymbolKey = "effect/HashSet"; -var HashSetTypeId = /* @__PURE__ */ Symbol.for(HashSetSymbolKey); -var HashSetProto = { - [HashSetTypeId]: HashSetTypeId, - [Symbol.iterator]() { - return keys(this._keyMap); - }, - [symbol]() { - return cached(this, combine(hash(this._keyMap))(hash(HashSetSymbolKey))); - }, - [symbol2](that) { - if (isHashSet(that)) { - return size(this._keyMap) === size(that._keyMap) && equals(this._keyMap, that._keyMap); - } - return false; - }, - toString() { - return format(this.toJSON()); - }, - toJSON() { - return { - _id: "HashSet", - values: Array.from(this).map(toJSON) - }; - }, - [NodeInspectSymbol]() { - return this.toJSON(); - }, +var interruptFiber = (self) => flatMap7(fiberId, (fiberId2) => pipe(self, interruptAsFiber(fiberId2))); +var interruptAsFiber = /* @__PURE__ */ dual(2, (self, fiberId2) => flatMap7(self.interruptAsFork(fiberId2), () => self.await)); +var logLevelAll = { + _tag: "All", + syslog: 0, + label: "ALL", + ordinal: Number.MIN_SAFE_INTEGER, pipe() { return pipeArguments(this, arguments); } }; -var makeImpl2 = (keyMap) => { - const set2 = Object.create(HashSetProto); - set2._keyMap = keyMap; - return set2; +var logLevelFatal = { + _tag: "Fatal", + syslog: 2, + label: "FATAL", + ordinal: 50000, + pipe() { + return pipeArguments(this, arguments); + } }; -var isHashSet = (u) => hasProperty(u, HashSetTypeId); -var _empty4 = /* @__PURE__ */ makeImpl2(/* @__PURE__ */ empty5()); -var empty6 = () => _empty4; -var fromIterable4 = (elements) => { - const set2 = beginMutation2(empty6()); - for (const value of elements) { - add3(set2, value); +var logLevelError = { + _tag: "Error", + syslog: 3, + label: "ERROR", + ordinal: 40000, + pipe() { + return pipeArguments(this, arguments); } - return endMutation2(set2); }; -var make10 = (...elements) => { - const set2 = beginMutation2(empty6()); - for (const value of elements) { - add3(set2, value); +var logLevelWarning = { + _tag: "Warning", + syslog: 4, + label: "WARN", + ordinal: 30000, + pipe() { + return pipeArguments(this, arguments); } - return endMutation2(set2); }; -var has2 = /* @__PURE__ */ dual(2, (self, value) => has(self._keyMap, value)); -var size2 = (self) => size(self._keyMap); -var beginMutation2 = (self) => makeImpl2(beginMutation(self._keyMap)); -var endMutation2 = (self) => { - self._keyMap._editable = false; - return self; +var logLevelInfo = { + _tag: "Info", + syslog: 6, + label: "INFO", + ordinal: 20000, + pipe() { + return pipeArguments(this, arguments); + } }; -var mutate2 = /* @__PURE__ */ dual(2, (self, f) => { - const transient = beginMutation2(self); - f(transient); - return endMutation2(transient); -}); -var add3 = /* @__PURE__ */ dual(2, (self, value) => self._keyMap._editable ? (set(value, true)(self._keyMap), self) : makeImpl2(set(value, true)(self._keyMap))); -var remove3 = /* @__PURE__ */ dual(2, (self, value) => self._keyMap._editable ? (remove2(value)(self._keyMap), self) : makeImpl2(remove2(value)(self._keyMap))); -var difference2 = /* @__PURE__ */ dual(2, (self, that) => mutate2(self, (set2) => { - for (const value of that) { - remove3(set2, value); +var logLevelDebug = { + _tag: "Debug", + syslog: 7, + label: "DEBUG", + ordinal: 1e4, + pipe() { + return pipeArguments(this, arguments); } -})); -var union2 = /* @__PURE__ */ dual(2, (self, that) => mutate2(empty6(), (set2) => { - forEach2(self, (value) => add3(set2, value)); - for (const value of that) { - add3(set2, value); - } -})); -var forEach2 = /* @__PURE__ */ dual(2, (self, f) => forEach(self._keyMap, (_, k) => f(k))); -var reduce3 = /* @__PURE__ */ dual(3, (self, zero3, f) => reduce2(self._keyMap, zero3, (z, _, a) => f(z, a))); - -// node_modules/effect/dist/esm/HashSet.js -var isHashSet2 = isHashSet; -var empty7 = empty6; -var fromIterable5 = fromIterable4; -var make11 = make10; -var has3 = has2; -var size3 = size2; -var add4 = add3; -var remove4 = remove3; -var difference3 = difference2; -var union3 = union2; -var reduce4 = reduce3; - -// node_modules/effect/dist/esm/MutableRef.js -var TypeId7 = /* @__PURE__ */ Symbol.for("effect/MutableRef"); -var MutableRefProto = { - [TypeId7]: TypeId7, - toString() { - return format(this.toJSON()); - }, - toJSON() { - return { - _id: "MutableRef", - current: toJSON(this.current) - }; - }, - [NodeInspectSymbol]() { - return this.toJSON(); - }, +}; +var logLevelTrace = { + _tag: "Trace", + syslog: 7, + label: "TRACE", + ordinal: 0, pipe() { return pipeArguments(this, arguments); } }; -var make12 = (value) => { - const ref = Object.create(MutableRefProto); - ref.current = value; - return ref; -}; -var compareAndSet = /* @__PURE__ */ dual(3, (self, oldValue, newValue) => { - if (equals(oldValue, self.current)) { - self.current = newValue; - return true; - } - return false; -}); -var get6 = (self) => self.current; -var set2 = /* @__PURE__ */ dual(2, (self, value) => { - self.current = value; - return self; -}); - -// node_modules/effect/dist/esm/internal/fiberId.js -var FiberIdSymbolKey = "effect/FiberId"; -var FiberIdTypeId = /* @__PURE__ */ Symbol.for(FiberIdSymbolKey); -var OP_NONE = "None"; -var OP_RUNTIME = "Runtime"; -var OP_COMPOSITE = "Composite"; -var emptyHash = /* @__PURE__ */ string(`${FiberIdSymbolKey}-${OP_NONE}`); - -class None { - [FiberIdTypeId] = FiberIdTypeId; - _tag = OP_NONE; - id = -1; - startTimeMillis = -1; - [symbol]() { - return emptyHash; - } - [symbol2](that) { - return isFiberId(that) && that._tag === OP_NONE; - } - toString() { - return format(this.toJSON()); - } - toJSON() { - return { - _id: "FiberId", - _tag: this._tag - }; - } - [NodeInspectSymbol]() { - return this.toJSON(); - } -} - -class Runtime { - id; - startTimeMillis; - [FiberIdTypeId] = FiberIdTypeId; - _tag = OP_RUNTIME; - constructor(id, startTimeMillis) { - this.id = id; - this.startTimeMillis = startTimeMillis; - } - [symbol]() { - return cached(this, string(`${FiberIdSymbolKey}-${this._tag}-${this.id}-${this.startTimeMillis}`)); - } - [symbol2](that) { - return isFiberId(that) && that._tag === OP_RUNTIME && this.id === that.id && this.startTimeMillis === that.startTimeMillis; - } - toString() { - return format(this.toJSON()); - } - toJSON() { - return { - _id: "FiberId", - _tag: this._tag, - id: this.id, - startTimeMillis: this.startTimeMillis - }; - } - [NodeInspectSymbol]() { - return this.toJSON(); - } -} - -class Composite { - left; - right; - [FiberIdTypeId] = FiberIdTypeId; - _tag = OP_COMPOSITE; - constructor(left3, right3) { - this.left = left3; - this.right = right3; - } - _hash; - [symbol]() { - return pipe(string(`${FiberIdSymbolKey}-${this._tag}`), combine(hash(this.left)), combine(hash(this.right)), cached(this)); - } - [symbol2](that) { - return isFiberId(that) && that._tag === OP_COMPOSITE && equals(this.left, that.left) && equals(this.right, that.right); - } - toString() { - return format(this.toJSON()); - } - toJSON() { - return { - _id: "FiberId", - _tag: this._tag, - left: toJSON(this.left), - right: toJSON(this.right) - }; - } - [NodeInspectSymbol]() { - return this.toJSON(); +var logLevelNone = { + _tag: "None", + syslog: 7, + label: "OFF", + ordinal: Number.MAX_SAFE_INTEGER, + pipe() { + return pipeArguments(this, arguments); } -} -var none3 = /* @__PURE__ */ new None; -var runtime = (id, startTimeMillis) => { - return new Runtime(id, startTimeMillis); }; -var composite = (left3, right3) => { - return new Composite(left3, right3); +var FiberRefSymbolKey = "effect/FiberRef"; +var FiberRefTypeId = /* @__PURE__ */ Symbol.for(FiberRefSymbolKey); +var fiberRefVariance = { + _A: (_) => _ }; -var isFiberId = (self) => hasProperty(self, FiberIdTypeId); -var combine2 = /* @__PURE__ */ dual(2, (self, that) => { - if (self._tag === OP_NONE) { - return that; - } - if (that._tag === OP_NONE) { - return self; - } - return new Composite(self, that); +var fiberRefGet = (self) => withFiberRuntime((fiber) => exitSucceed(fiber.getFiberRef(self))); +var fiberRefGetWith = /* @__PURE__ */ dual(2, (self, f) => flatMap7(fiberRefGet(self), f)); +var fiberRefSet = /* @__PURE__ */ dual(2, (self, value) => fiberRefModify(self, () => [undefined, value])); +var fiberRefModify = /* @__PURE__ */ dual(2, (self, f) => withFiberRuntime((state) => { + const [b, a] = f(state.getFiberRef(self)); + state.setFiberRef(self, a); + return succeed(b); +})); +var fiberRefLocally = /* @__PURE__ */ dual(3, (use, self, value) => acquireUseRelease(zipLeft(fiberRefGet(self), fiberRefSet(self, value)), () => use, (oldValue) => fiberRefSet(self, oldValue))); +var fiberRefLocallyWith = /* @__PURE__ */ dual(3, (use, self, f) => fiberRefGetWith(self, (a) => fiberRefLocally(use, self, f(a)))); +var fiberRefUnsafeMake = (initial, options) => fiberRefUnsafeMakePatch(initial, { + differ: update(), + fork: options?.fork ?? identity, + join: options?.join }); -var ids = (self) => { - switch (self._tag) { - case OP_NONE: { - return empty7(); - } - case OP_RUNTIME: { - return make11(self.id); - } - case OP_COMPOSITE: { - return pipe(ids(self.left), union3(ids(self.right))); - } - } +var fiberRefUnsafeMakeHashSet = (initial) => { + const differ2 = hashSet(); + return fiberRefUnsafeMakePatch(initial, { + differ: differ2, + fork: differ2.empty + }); }; -var _fiberCounter = /* @__PURE__ */ globalValue(/* @__PURE__ */ Symbol.for("effect/Fiber/Id/_fiberCounter"), () => make12(0)); -var threadName = (self) => { - const identifiers = Array.from(ids(self)).map((n) => `#${n}`).join(","); - return identifiers; +var fiberRefUnsafeMakeReadonlyArray = (initial) => { + const differ2 = readonlyArray(update()); + return fiberRefUnsafeMakePatch(initial, { + differ: differ2, + fork: differ2.empty + }); }; -var unsafeMake = () => { - const id = get6(_fiberCounter); - pipe(_fiberCounter, set2(id + 1)); - return new Runtime(id, Date.now()); +var fiberRefUnsafeMakeContext = (initial) => { + const differ2 = environment(); + return fiberRefUnsafeMakePatch(initial, { + differ: differ2, + fork: differ2.empty + }); }; - -// node_modules/effect/dist/esm/FiberId.js -var none4 = none3; -var runtime2 = runtime; -var composite2 = composite; -var isFiberId2 = isFiberId; -var combine3 = combine2; -var threadName2 = threadName; -var unsafeMake2 = unsafeMake; - -// node_modules/effect/dist/esm/HashMap.js -var isHashMap2 = isHashMap; -var empty8 = empty5; -var fromIterable6 = fromIterable3; -var isEmpty3 = isEmpty2; -var get7 = get5; -var set3 = set; -var keys2 = keys; -var mutate3 = mutate; -var modifyAt2 = modifyAt; -var map6 = map4; -var forEach3 = forEach; -var reduce5 = reduce2; - -// node_modules/effect/dist/esm/List.js -var TypeId8 = /* @__PURE__ */ Symbol.for("effect/List"); -var toArray2 = (self) => fromIterable(self); -var getEquivalence5 = (isEquivalent) => mapInput(getEquivalence3(isEquivalent), toArray2); -var _equivalence4 = /* @__PURE__ */ getEquivalence5(equals); -var ConsProto = { - [TypeId8]: TypeId8, - _tag: "Cons", - toString() { - return format(this.toJSON()); - }, - toJSON() { - return { - _id: "List", - _tag: "Cons", - values: toArray2(this).map(toJSON) - }; - }, - [NodeInspectSymbol]() { - return this.toJSON(); - }, - [symbol2](that) { - return isList(that) && this._tag === that._tag && _equivalence4(this, that); - }, - [symbol]() { - return cached(this, array2(toArray2(this))); - }, - [Symbol.iterator]() { - let done = false; - let self = this; - return { - next() { - if (done) { - return this.return(); - } - if (self._tag === "Nil") { - done = true; - return this.return(); - } - const value = self.head; - self = self.tail; - return { - done, - value - }; - }, - return(value) { - if (!done) { - done = true; - } - return { - done: true, - value - }; - } - }; - }, - pipe() { - return pipeArguments(this, arguments); - } -}; -var makeCons = (head3, tail) => { - const cons = Object.create(ConsProto); - cons.head = head3; - cons.tail = tail; - return cons; -}; -var NilHash = /* @__PURE__ */ string("Nil"); -var NilProto = { - [TypeId8]: TypeId8, - _tag: "Nil", - toString() { - return format(this.toJSON()); - }, - toJSON() { - return { - _id: "List", - _tag: "Nil" - }; - }, - [NodeInspectSymbol]() { - return this.toJSON(); - }, - [symbol]() { - return NilHash; - }, - [symbol2](that) { - return isList(that) && this._tag === that._tag; - }, - [Symbol.iterator]() { - return { - next() { - return { - done: true, - value: undefined - }; - } - }; - }, - pipe() { - return pipeArguments(this, arguments); - } -}; -var _Nil = /* @__PURE__ */ Object.create(NilProto); -var isList = (u) => hasProperty(u, TypeId8); -var isNil = (self) => self._tag === "Nil"; -var isCons = (self) => self._tag === "Cons"; -var nil = () => _Nil; -var cons = (head3, tail) => makeCons(head3, tail); -var empty9 = nil; -var of3 = (value) => makeCons(value, _Nil); -var fromIterable7 = (prefix) => { - const iterator = prefix[Symbol.iterator](); - let next; - if ((next = iterator.next()) && !next.done) { - const result = makeCons(next.value, _Nil); - let curr = result; - while ((next = iterator.next()) && !next.done) { - const temp = makeCons(next.value, _Nil); - curr.tail = temp; - curr = temp; - } - return result; - } else { - return _Nil; - } +var fiberRefUnsafeMakePatch = (initial, options) => { + const _fiberRef = { + ...CommitPrototype, + [FiberRefTypeId]: fiberRefVariance, + initial, + commit() { + return fiberRefGet(this); + }, + diff: (oldValue, newValue) => options.differ.diff(oldValue, newValue), + combine: (first, second) => options.differ.combine(first, second), + patch: (patch5) => (oldValue) => options.differ.patch(patch5, oldValue), + fork: options.fork, + join: options.join ?? ((_, n) => n) + }; + return _fiberRef; }; -var appendAll3 = /* @__PURE__ */ dual(2, (self, that) => prependAll(that, self)); -var prepend3 = /* @__PURE__ */ dual(2, (self, element) => cons(element, self)); -var prependAll = /* @__PURE__ */ dual(2, (self, prefix) => { - if (isNil(self)) { - return prefix; - } else if (isNil(prefix)) { - return self; - } else { - const result = makeCons(prefix.head, self); - let curr = result; - let that = prefix.tail; - while (!isNil(that)) { - const temp = makeCons(that.head, self); - curr.tail = temp; - curr = temp; - that = that.tail; - } - return result; - } -}); -var reduce6 = /* @__PURE__ */ dual(3, (self, zero3, f) => { - let acc = zero3; - let these = self; - while (!isNil(these)) { - acc = f(acc, these.head); - these = these.tail; - } - return acc; +var fiberRefUnsafeMakeRuntimeFlags = (initial) => fiberRefUnsafeMakePatch(initial, { + differ, + fork: differ.empty }); -var reverse3 = (self) => { - let result = empty9(); - let these = self; - while (!isNil(these)) { - result = prepend3(result, these.head); - these = these.tail; - } - return result; -}; - -// node_modules/effect/dist/esm/internal/data.js -var ArrayProto = /* @__PURE__ */ Object.assign(/* @__PURE__ */ Object.create(Array.prototype), { - [symbol]() { - return cached(this, array2(this)); - }, - [symbol2](that) { - if (Array.isArray(that) && this.length === that.length) { - return this.every((v, i) => equals(v, that[i])); - } else { - return false; +var currentContext = /* @__PURE__ */ globalValue(/* @__PURE__ */ Symbol.for("effect/FiberRef/currentContext"), () => fiberRefUnsafeMakeContext(empty4())); +var currentSchedulingPriority = /* @__PURE__ */ globalValue(/* @__PURE__ */ Symbol.for("effect/FiberRef/currentSchedulingPriority"), () => fiberRefUnsafeMake(0)); +var currentMaxOpsBeforeYield = /* @__PURE__ */ globalValue(/* @__PURE__ */ Symbol.for("effect/FiberRef/currentMaxOpsBeforeYield"), () => fiberRefUnsafeMake(2048)); +var currentLogAnnotations = /* @__PURE__ */ globalValue(/* @__PURE__ */ Symbol.for("effect/FiberRef/currentLogAnnotation"), () => fiberRefUnsafeMake(empty8())); +var currentLogLevel = /* @__PURE__ */ globalValue(/* @__PURE__ */ Symbol.for("effect/FiberRef/currentLogLevel"), () => fiberRefUnsafeMake(logLevelInfo)); +var currentLogSpan = /* @__PURE__ */ globalValue(/* @__PURE__ */ Symbol.for("effect/FiberRef/currentLogSpan"), () => fiberRefUnsafeMake(empty9())); +var withSchedulingPriority = /* @__PURE__ */ dual(2, (self, scheduler) => fiberRefLocally(self, currentSchedulingPriority, scheduler)); +var withMaxOpsBeforeYield = /* @__PURE__ */ dual(2, (self, scheduler) => fiberRefLocally(self, currentMaxOpsBeforeYield, scheduler)); +var currentConcurrency = /* @__PURE__ */ globalValue(/* @__PURE__ */ Symbol.for("effect/FiberRef/currentConcurrency"), () => fiberRefUnsafeMake("unbounded")); +var currentRequestBatching = /* @__PURE__ */ globalValue(/* @__PURE__ */ Symbol.for("effect/FiberRef/currentRequestBatching"), () => fiberRefUnsafeMake(true)); +var currentUnhandledErrorLogLevel = /* @__PURE__ */ globalValue(/* @__PURE__ */ Symbol.for("effect/FiberRef/currentUnhandledErrorLogLevel"), () => fiberRefUnsafeMake(some2(logLevelDebug))); +var currentVersionMismatchErrorLogLevel = /* @__PURE__ */ globalValue(/* @__PURE__ */ Symbol.for("effect/FiberRef/versionMismatchErrorLogLevel"), () => fiberRefUnsafeMake(some2(logLevelWarning))); +var withUnhandledErrorLogLevel = /* @__PURE__ */ dual(2, (self, level) => fiberRefLocally(self, currentUnhandledErrorLogLevel, level)); +var currentMetricLabels = /* @__PURE__ */ globalValue(/* @__PURE__ */ Symbol.for("effect/FiberRef/currentMetricLabels"), () => fiberRefUnsafeMakeReadonlyArray(empty())); +var metricLabels = /* @__PURE__ */ fiberRefGet(currentMetricLabels); +var currentForkScopeOverride = /* @__PURE__ */ globalValue(/* @__PURE__ */ Symbol.for("effect/FiberRef/currentForkScopeOverride"), () => fiberRefUnsafeMake(none2(), { + fork: () => none2(), + join: (parent, _) => parent +})); +var currentInterruptedCause = /* @__PURE__ */ globalValue(/* @__PURE__ */ Symbol.for("effect/FiberRef/currentInterruptedCause"), () => fiberRefUnsafeMake(empty16, { + fork: () => empty16, + join: (parent, _) => parent +})); +var currentTracerEnabled = /* @__PURE__ */ globalValue(/* @__PURE__ */ Symbol.for("effect/FiberRef/currentTracerEnabled"), () => fiberRefUnsafeMake(true)); +var currentTracerTimingEnabled = /* @__PURE__ */ globalValue(/* @__PURE__ */ Symbol.for("effect/FiberRef/currentTracerTiming"), () => fiberRefUnsafeMake(true)); +var currentTracerSpanAnnotations = /* @__PURE__ */ globalValue(/* @__PURE__ */ Symbol.for("effect/FiberRef/currentTracerSpanAnnotations"), () => fiberRefUnsafeMake(empty8())); +var currentTracerSpanLinks = /* @__PURE__ */ globalValue(/* @__PURE__ */ Symbol.for("effect/FiberRef/currentTracerSpanLinks"), () => fiberRefUnsafeMake(empty2())); +var ScopeTypeId = /* @__PURE__ */ Symbol.for("effect/Scope"); +var CloseableScopeTypeId = /* @__PURE__ */ Symbol.for("effect/CloseableScope"); +var scopeAddFinalizer = (self, finalizer) => self.addFinalizer(() => asVoid(finalizer)); +var scopeAddFinalizerExit = (self, finalizer) => self.addFinalizer(finalizer); +var scopeClose = (self, exit2) => self.close(exit2); +var scopeFork = (self, strategy) => self.fork(strategy); +var YieldableError = /* @__PURE__ */ function() { + class YieldableError2 extends globalThis.Error { + commit() { + return fail2(this); } - } -}); -var Structural = /* @__PURE__ */ function() { - function Structural2(args) { - if (args) { - Object.assign(this, args); + toJSON() { + const obj = { + ...this + }; + if (this.message) + obj.message = this.message; + if (this.cause) + obj.cause = this.cause; + return obj; + } + [NodeInspectSymbol]() { + if (this.toString !== globalThis.Error.prototype.toString) { + return this.stack ? `${this.toString()} +${this.stack.split(` +`).slice(1).join(` +`)}` : this.toString(); + } else if ("Bun" in globalThis) { + return pretty(fail(this), { + renderErrorCause: true + }); + } + return this; } } - Structural2.prototype = StructuralPrototype; - return Structural2; + Object.assign(YieldableError2.prototype, StructuralCommitPrototype); + return YieldableError2; }(); -var struct = (as) => Object.assign(Object.create(StructuralPrototype), as); +var makeException = (proto2, tag) => { -// node_modules/effect/dist/esm/internal/differ/contextPatch.js -var ContextPatchTypeId = /* @__PURE__ */ Symbol.for("effect/DifferContextPatch"); -function variance(a) { - return a; -} -var PatchProto = { - ...Structural.prototype, - [ContextPatchTypeId]: { - _Value: variance, - _Patch: variance + class Base2 extends YieldableError { + _tag = tag; } + Object.assign(Base2.prototype, proto2); + Base2.prototype.name = tag; + return Base2; }; -var EmptyProto = /* @__PURE__ */ Object.assign(/* @__PURE__ */ Object.create(PatchProto), { - _tag: "Empty" -}); -var _empty5 = /* @__PURE__ */ Object.create(EmptyProto); -var empty10 = () => _empty5; -var AndThenProto = /* @__PURE__ */ Object.assign(/* @__PURE__ */ Object.create(PatchProto), { - _tag: "AndThen" -}); -var makeAndThen = (first, second) => { - const o = Object.create(AndThenProto); - o.first = first; - o.second = second; - return o; -}; -var AddServiceProto = /* @__PURE__ */ Object.assign(/* @__PURE__ */ Object.create(PatchProto), { - _tag: "AddService" -}); -var makeAddService = (key, service) => { - const o = Object.create(AddServiceProto); - o.key = key; - o.service = service; - return o; -}; -var RemoveServiceProto = /* @__PURE__ */ Object.assign(/* @__PURE__ */ Object.create(PatchProto), { - _tag: "RemoveService" -}); -var makeRemoveService = (key) => { - const o = Object.create(RemoveServiceProto); - o.key = key; - return o; -}; -var UpdateServiceProto = /* @__PURE__ */ Object.assign(/* @__PURE__ */ Object.create(PatchProto), { - _tag: "UpdateService" -}); -var makeUpdateService = (key, update) => { - const o = Object.create(UpdateServiceProto); - o.key = key; - o.update = update; - return o; -}; -var diff = (oldValue, newValue) => { - const missingServices = new Map(oldValue.unsafeMap); - let patch = empty10(); - for (const [tag, newService] of newValue.unsafeMap.entries()) { - if (missingServices.has(tag)) { - const old = missingServices.get(tag); - missingServices.delete(tag); - if (!equals(old, newService)) { - patch = combine4(makeUpdateService(tag, () => newService))(patch); - } - } else { - missingServices.delete(tag); - patch = combine4(makeAddService(tag, newService))(patch); +var RuntimeExceptionTypeId = /* @__PURE__ */ Symbol.for("effect/Cause/errors/RuntimeException"); +var RuntimeException = /* @__PURE__ */ makeException({ + [RuntimeExceptionTypeId]: RuntimeExceptionTypeId +}, "RuntimeException"); +var InterruptedExceptionTypeId = /* @__PURE__ */ Symbol.for("effect/Cause/errors/InterruptedException"); +var InterruptedException = /* @__PURE__ */ makeException({ + [InterruptedExceptionTypeId]: InterruptedExceptionTypeId +}, "InterruptedException"); +var isInterruptedException = (u) => hasProperty(u, InterruptedExceptionTypeId); +var IllegalArgumentExceptionTypeId = /* @__PURE__ */ Symbol.for("effect/Cause/errors/IllegalArgument"); +var IllegalArgumentException = /* @__PURE__ */ makeException({ + [IllegalArgumentExceptionTypeId]: IllegalArgumentExceptionTypeId +}, "IllegalArgumentException"); +var NoSuchElementExceptionTypeId = /* @__PURE__ */ Symbol.for("effect/Cause/errors/NoSuchElement"); +var NoSuchElementException = /* @__PURE__ */ makeException({ + [NoSuchElementExceptionTypeId]: NoSuchElementExceptionTypeId +}, "NoSuchElementException"); +var isNoSuchElementException = (u) => hasProperty(u, NoSuchElementExceptionTypeId); +var InvalidPubSubCapacityExceptionTypeId = /* @__PURE__ */ Symbol.for("effect/Cause/errors/InvalidPubSubCapacityException"); +var InvalidPubSubCapacityException = /* @__PURE__ */ makeException({ + [InvalidPubSubCapacityExceptionTypeId]: InvalidPubSubCapacityExceptionTypeId +}, "InvalidPubSubCapacityException"); +var ExceededCapacityExceptionTypeId = /* @__PURE__ */ Symbol.for("effect/Cause/errors/ExceededCapacityException"); +var ExceededCapacityException = /* @__PURE__ */ makeException({ + [ExceededCapacityExceptionTypeId]: ExceededCapacityExceptionTypeId +}, "ExceededCapacityException"); +var TimeoutExceptionTypeId = /* @__PURE__ */ Symbol.for("effect/Cause/errors/Timeout"); +var TimeoutException = /* @__PURE__ */ makeException({ + [TimeoutExceptionTypeId]: TimeoutExceptionTypeId +}, "TimeoutException"); +var timeoutExceptionFromDuration = (duration) => new TimeoutException(`Operation timed out after '${format2(duration)}'`); +var UnknownExceptionTypeId = /* @__PURE__ */ Symbol.for("effect/Cause/errors/UnknownException"); +var UnknownException = /* @__PURE__ */ function() { + + class UnknownException2 extends YieldableError { + _tag = "UnknownException"; + error; + constructor(cause, message) { + super(message ?? "An unknown error occurred", { + cause + }); + this.error = cause; } } - for (const [tag] of missingServices.entries()) { - patch = combine4(makeRemoveService(tag))(patch); + Object.assign(UnknownException2.prototype, { + [UnknownExceptionTypeId]: UnknownExceptionTypeId, + name: "UnknownException" + }); + return UnknownException2; +}(); +var exitIsExit = (u) => isEffect(u) && ("_tag" in u) && (u._tag === "Success" || u._tag === "Failure"); +var exitIsFailure = (self) => self._tag === "Failure"; +var exitIsSuccess = (self) => self._tag === "Success"; +var exitAs = /* @__PURE__ */ dual(2, (self, value) => { + switch (self._tag) { + case OP_FAILURE: { + return exitFailCause(self.effect_instruction_i0); + } + case OP_SUCCESS: { + return exitSucceed(value); + } } - return patch; +}); +var exitAsVoid = (self) => exitAs(self, undefined); +var exitCollectAll = (exits, options) => exitCollectAllInternal(exits, options?.parallel ? parallel : sequential); +var exitDie = (defect) => exitFailCause(die(defect)); +var exitFail = (error) => exitFailCause(fail(error)); +var exitFailCause = (cause) => { + const effect = new EffectPrimitiveFailure(OP_FAILURE); + effect.effect_instruction_i0 = cause; + return effect; }; -var combine4 = /* @__PURE__ */ dual(2, (self, that) => makeAndThen(self, that)); -var patch = /* @__PURE__ */ dual(2, (self, context) => { - if (self._tag === "Empty") { - return context; - } - let wasServiceUpdated = false; - let patches = of2(self); - const updatedContext = new Map(context.unsafeMap); - while (isNonEmpty2(patches)) { - const head3 = headNonEmpty2(patches); - const tail = tailNonEmpty2(patches); - switch (head3._tag) { - case "Empty": { - patches = tail; - break; - } - case "AddService": { - updatedContext.set(head3.key, head3.service); - patches = tail; - break; - } - case "AndThen": { - patches = prepend2(prepend2(tail, head3.second), head3.first); - break; - } - case "RemoveService": { - updatedContext.delete(head3.key); - patches = tail; - break; - } - case "UpdateService": { - updatedContext.set(head3.key, head3.update(updatedContext.get(head3.key))); - wasServiceUpdated = true; - patches = tail; - break; - } +var exitFlatMap = /* @__PURE__ */ dual(2, (self, f) => { + switch (self._tag) { + case OP_FAILURE: { + return exitFailCause(self.effect_instruction_i0); } - } - if (!wasServiceUpdated) { - return makeContext(updatedContext); - } - const map7 = new Map; - for (const [tag] of context.unsafeMap) { - if (updatedContext.has(tag)) { - map7.set(tag, updatedContext.get(tag)); - updatedContext.delete(tag); + case OP_SUCCESS: { + return f(self.effect_instruction_i0); } } - for (const [tag, s] of updatedContext) { - map7.set(tag, s); - } - return makeContext(map7); }); - -// node_modules/effect/dist/esm/internal/differ/hashSetPatch.js -var HashSetPatchTypeId = /* @__PURE__ */ Symbol.for("effect/DifferHashSetPatch"); -function variance2(a) { - return a; -} -var PatchProto2 = { - ...Structural.prototype, - [HashSetPatchTypeId]: { - _Value: variance2, - _Key: variance2, - _Patch: variance2 +var exitFlatten = (self) => pipe(self, exitFlatMap(identity)); +var exitInterrupt = (fiberId2) => exitFailCause(interrupt(fiberId2)); +var exitMap = /* @__PURE__ */ dual(2, (self, f) => { + switch (self._tag) { + case OP_FAILURE: + return exitFailCause(self.effect_instruction_i0); + case OP_SUCCESS: + return exitSucceed(f(self.effect_instruction_i0)); } -}; -var EmptyProto2 = /* @__PURE__ */ Object.assign(/* @__PURE__ */ Object.create(PatchProto2), { - _tag: "Empty" }); -var _empty6 = /* @__PURE__ */ Object.create(EmptyProto2); -var empty11 = () => _empty6; -var AndThenProto2 = /* @__PURE__ */ Object.assign(/* @__PURE__ */ Object.create(PatchProto2), { - _tag: "AndThen" -}); -var makeAndThen2 = (first, second) => { - const o = Object.create(AndThenProto2); - o.first = first; - o.second = second; - return o; -}; -var AddProto = /* @__PURE__ */ Object.assign(/* @__PURE__ */ Object.create(PatchProto2), { - _tag: "Add" +var exitMatch = /* @__PURE__ */ dual(2, (self, { + onFailure, + onSuccess +}) => { + switch (self._tag) { + case OP_FAILURE: + return onFailure(self.effect_instruction_i0); + case OP_SUCCESS: + return onSuccess(self.effect_instruction_i0); + } }); -var makeAdd = (value) => { - const o = Object.create(AddProto); - o.value = value; - return o; -}; -var RemoveProto = /* @__PURE__ */ Object.assign(/* @__PURE__ */ Object.create(PatchProto2), { - _tag: "Remove" +var exitMatchEffect = /* @__PURE__ */ dual(2, (self, { + onFailure, + onSuccess +}) => { + switch (self._tag) { + case OP_FAILURE: + return onFailure(self.effect_instruction_i0); + case OP_SUCCESS: + return onSuccess(self.effect_instruction_i0); + } }); -var makeRemove = (value) => { - const o = Object.create(RemoveProto); - o.value = value; - return o; +var exitSucceed = (value) => { + const effect = new EffectPrimitiveSuccess(OP_SUCCESS); + effect.effect_instruction_i0 = value; + return effect; }; -var diff2 = (oldValue, newValue) => { - const [removed, patch2] = reduce4([oldValue, empty11()], ([set4, patch3], value) => { - if (has3(value)(set4)) { - return [remove4(value)(set4), patch3]; - } - return [set4, combine5(makeAdd(value))(patch3)]; - })(newValue); - return reduce4(patch2, (patch3, value) => combine5(makeRemove(value))(patch3))(removed); -}; -var combine5 = /* @__PURE__ */ dual(2, (self, that) => makeAndThen2(self, that)); -var patch2 = /* @__PURE__ */ dual(2, (self, oldValue) => { - if (self._tag === "Empty") { - return oldValue; - } - let set4 = oldValue; - let patches = of2(self); - while (isNonEmpty2(patches)) { - const head3 = headNonEmpty2(patches); - const tail = tailNonEmpty2(patches); - switch (head3._tag) { - case "Empty": { - patches = tail; - break; - } - case "AndThen": { - patches = prepend2(head3.first)(prepend2(head3.second)(tail)); - break; - } - case "Add": { - set4 = add4(head3.value)(set4); - patches = tail; - break; +var exitVoid = /* @__PURE__ */ exitSucceed(undefined); +var exitZipWith = /* @__PURE__ */ dual(3, (self, that, { + onFailure, + onSuccess +}) => { + switch (self._tag) { + case OP_FAILURE: { + switch (that._tag) { + case OP_SUCCESS: + return exitFailCause(self.effect_instruction_i0); + case OP_FAILURE: { + return exitFailCause(onFailure(self.effect_instruction_i0, that.effect_instruction_i0)); + } } - case "Remove": { - set4 = remove4(head3.value)(set4); - patches = tail; + } + case OP_SUCCESS: { + switch (that._tag) { + case OP_SUCCESS: + return exitSucceed(onSuccess(self.effect_instruction_i0, that.effect_instruction_i0)); + case OP_FAILURE: + return exitFailCause(that.effect_instruction_i0); } } } - return set4; }); - -// node_modules/effect/dist/esm/internal/differ/readonlyArrayPatch.js -var ReadonlyArrayPatchTypeId = /* @__PURE__ */ Symbol.for("effect/DifferReadonlyArrayPatch"); -function variance3(a) { - return a; -} -var PatchProto3 = { - ...Structural.prototype, - [ReadonlyArrayPatchTypeId]: { - _Value: variance3, - _Patch: variance3 +var exitCollectAllInternal = (exits, combineCauses) => { + const list = fromIterable2(exits); + if (!isNonEmpty(list)) { + return none2(); } + return pipe(tailNonEmpty2(list), reduce(pipe(headNonEmpty2(list), exitMap(of2)), (accumulator, current) => pipe(accumulator, exitZipWith(current, { + onSuccess: (list2, value) => pipe(list2, prepend2(value)), + onFailure: combineCauses + }))), exitMap(reverse2), exitMap((chunk) => toReadonlyArray(chunk)), some2); }; -var EmptyProto3 = /* @__PURE__ */ Object.assign(/* @__PURE__ */ Object.create(PatchProto3), { - _tag: "Empty" -}); -var _empty7 = /* @__PURE__ */ Object.create(EmptyProto3); -var empty12 = () => _empty7; -var AndThenProto3 = /* @__PURE__ */ Object.assign(/* @__PURE__ */ Object.create(PatchProto3), { - _tag: "AndThen" -}); -var makeAndThen3 = (first, second) => { - const o = Object.create(AndThenProto3); - o.first = first; - o.second = second; - return o; -}; -var AppendProto = /* @__PURE__ */ Object.assign(/* @__PURE__ */ Object.create(PatchProto3), { - _tag: "Append" -}); -var makeAppend = (values3) => { - const o = Object.create(AppendProto); - o.values = values3; - return o; -}; -var SliceProto = /* @__PURE__ */ Object.assign(/* @__PURE__ */ Object.create(PatchProto3), { - _tag: "Slice" -}); -var makeSlice = (from, until) => { - const o = Object.create(SliceProto); - o.from = from; - o.until = until; - return o; -}; -var UpdateProto = /* @__PURE__ */ Object.assign(/* @__PURE__ */ Object.create(PatchProto3), { - _tag: "Update" -}); -var makeUpdate = (index, patch3) => { - const o = Object.create(UpdateProto); - o.index = index; - o.patch = patch3; - return o; +var deferredUnsafeMake = (fiberId2) => { + const _deferred = { + ...CommitPrototype, + [DeferredTypeId]: deferredVariance, + state: make11(pending([])), + commit() { + return deferredAwait(this); + }, + blockingOn: fiberId2 + }; + return _deferred; }; -var diff3 = (options) => { - let i = 0; - let patch3 = empty12(); - while (i < options.oldValue.length && i < options.newValue.length) { - const oldElement = options.oldValue[i]; - const newElement = options.newValue[i]; - const valuePatch = options.differ.diff(oldElement, newElement); - if (!equals(valuePatch, options.differ.empty)) { - patch3 = combine6(patch3, makeUpdate(i, valuePatch)); +var deferredMake = () => flatMap7(fiberId, (id) => deferredMakeAs(id)); +var deferredMakeAs = (fiberId2) => sync(() => deferredUnsafeMake(fiberId2)); +var deferredAwait = (self) => asyncInterrupt((resume) => { + const state = get6(self.state); + switch (state._tag) { + case OP_STATE_DONE: { + return resume(state.effect); + } + case OP_STATE_PENDING: { + state.joiners.push(resume); + return deferredInterruptJoiner(self, resume); } - i = i + 1; } - if (i < options.oldValue.length) { - patch3 = combine6(patch3, makeSlice(0, i)); +}, self.blockingOn); +var deferredComplete = /* @__PURE__ */ dual(2, (self, effect) => intoDeferred(effect, self)); +var deferredCompleteWith = /* @__PURE__ */ dual(2, (self, effect) => sync(() => { + const state = get6(self.state); + switch (state._tag) { + case OP_STATE_DONE: { + return false; + } + case OP_STATE_PENDING: { + set2(self.state, done(effect)); + for (let i = 0, len = state.joiners.length;i < len; i++) { + state.joiners[i](effect); + } + return true; + } } - if (i < options.newValue.length) { - patch3 = combine6(patch3, makeAppend(drop(i)(options.newValue))); +})); +var deferredDone = /* @__PURE__ */ dual(2, (self, exit2) => deferredCompleteWith(self, exit2)); +var deferredFailCause = /* @__PURE__ */ dual(2, (self, cause) => deferredCompleteWith(self, failCause(cause))); +var deferredInterrupt = (self) => flatMap7(fiberId, (fiberId2) => deferredCompleteWith(self, interruptWith(fiberId2))); +var deferredSucceed = /* @__PURE__ */ dual(2, (self, value) => deferredCompleteWith(self, succeed(value))); +var deferredUnsafeDone = (self, effect) => { + const state = get6(self.state); + if (state._tag === OP_STATE_PENDING) { + set2(self.state, done(effect)); + for (let i = 0, len = state.joiners.length;i < len; i++) { + state.joiners[i](effect); + } } - return patch3; }; -var combine6 = /* @__PURE__ */ dual(2, (self, that) => makeAndThen3(self, that)); -var patch3 = /* @__PURE__ */ dual(3, (self, oldValue, differ) => { - if (self._tag === "Empty") { - return oldValue; - } - let readonlyArray = oldValue.slice(); - let patches = of(self); - while (isNonEmptyArray2(patches)) { - const head3 = headNonEmpty(patches); - const tail = tailNonEmpty(patches); - switch (head3._tag) { - case "Empty": { - patches = tail; - break; - } - case "AndThen": { - tail.unshift(head3.first, head3.second); - patches = tail; - break; - } - case "Append": { - for (const value of head3.values) { - readonlyArray.push(value); - } - patches = tail; - break; - } - case "Slice": { - readonlyArray = readonlyArray.slice(head3.from, head3.until); - patches = tail; - break; - } - case "Update": { - readonlyArray[head3.index] = differ.patch(head3.patch, readonlyArray[head3.index]); - patches = tail; - break; - } +var deferredInterruptJoiner = (self, joiner) => sync(() => { + const state = get6(self.state); + if (state._tag === OP_STATE_PENDING) { + const index = state.joiners.indexOf(joiner); + if (index >= 0) { + state.joiners.splice(index, 1); } } - return readonlyArray; }); - -// node_modules/effect/dist/esm/internal/differ.js -var DifferTypeId = /* @__PURE__ */ Symbol.for("effect/Differ"); -var DifferProto = { - [DifferTypeId]: { - _P: identity, - _V: identity - }, - pipe() { - return pipeArguments(this, arguments); - } -}; -var make15 = (params) => { - const differ = Object.create(DifferProto); - differ.empty = params.empty; - differ.diff = params.diff; - differ.combine = params.combine; - differ.patch = params.patch; - return differ; +var constContext = /* @__PURE__ */ withFiberRuntime((fiber) => exitSucceed(fiber.currentContext)); +var context = () => constContext; +var contextWithEffect = (f) => flatMap7(context(), f); +var provideContext = /* @__PURE__ */ dual(2, (self, context2) => fiberRefLocally(currentContext, context2)(self)); +var provideSomeContext = /* @__PURE__ */ dual(2, (self, context2) => fiberRefLocallyWith(currentContext, (parent) => merge3(parent, context2))(self)); +var mapInputContext = /* @__PURE__ */ dual(2, (self, f) => contextWithEffect((context2) => provideContext(self, f(context2)))); +var filterEffectOrElse = /* @__PURE__ */ dual(2, (self, options) => flatMap7(self, (a) => flatMap7(options.predicate(a), (pass) => pass ? succeed(a) : options.orElse(a)))); +var filterEffectOrFail = /* @__PURE__ */ dual(2, (self, options) => filterEffectOrElse(self, { + predicate: options.predicate, + orElse: (a) => fail2(options.orFailWith(a)) +})); +var currentSpanFromFiber = (fiber) => { + const span2 = fiber.currentSpan; + return span2 !== undefined && span2._tag === "Span" ? some2(span2) : none2(); }; -var environment = () => make15({ - empty: empty10(), - combine: (first, second) => combine4(second)(first), - diff: (oldValue, newValue) => diff(oldValue, newValue), - patch: (patch4, oldValue) => patch(oldValue)(patch4) -}); -var hashSet = () => make15({ - empty: empty11(), - combine: (first, second) => combine5(second)(first), - diff: (oldValue, newValue) => diff2(oldValue, newValue), - patch: (patch4, oldValue) => patch2(oldValue)(patch4) -}); -var readonlyArray = (differ) => make15({ - empty: empty12(), - combine: (first, second) => combine6(first, second), - diff: (oldValue, newValue) => diff3({ - oldValue, - newValue, - differ - }), - patch: (patch4, oldValue) => patch3(patch4, oldValue, differ) -}); -var update = () => updateWith((_, a) => a); -var updateWith = (f) => make15({ - empty: identity, - combine: (first, second) => { - if (first === identity) { - return second; - } - if (second === identity) { - return first; - } - return (a) => second(first(a)); - }, - diff: (oldValue, newValue) => { - if (equals(oldValue, newValue)) { - return identity; - } - return constant(newValue); +var NoopSpanProto = { + _tag: "Span", + spanId: "noop", + traceId: "noop", + sampled: false, + status: { + _tag: "Ended", + startTime: /* @__PURE__ */ BigInt(0), + endTime: /* @__PURE__ */ BigInt(0), + exit: exitVoid }, - patch: (patch4, oldValue) => f(oldValue, patch4(oldValue)) -}); - -// node_modules/effect/dist/esm/internal/runtimeFlagsPatch.js -var BIT_MASK = 255; -var BIT_SHIFT = 8; -var active = (patch4) => patch4 & BIT_MASK; -var enabled = (patch4) => patch4 >> BIT_SHIFT & BIT_MASK; -var make16 = (active2, enabled2) => (active2 & BIT_MASK) + ((enabled2 & active2 & BIT_MASK) << BIT_SHIFT); -var empty13 = /* @__PURE__ */ make16(0, 0); -var enable = (flag) => make16(flag, flag); -var disable = (flag) => make16(flag, 0); -var exclude = /* @__PURE__ */ dual(2, (self, flag) => make16(active(self) & ~flag, enabled(self))); -var andThen = /* @__PURE__ */ dual(2, (self, that) => self | that); -var invert = (n) => ~n >>> 0 & BIT_MASK; - -// node_modules/effect/dist/esm/internal/runtimeFlags.js -var None2 = 0; -var Interruption = 1 << 0; -var OpSupervision = 1 << 1; -var RuntimeMetrics = 1 << 2; -var WindDown = 1 << 4; -var CooperativeYielding = 1 << 5; -var cooperativeYielding = (self) => isEnabled(self, CooperativeYielding); -var disable2 = /* @__PURE__ */ dual(2, (self, flag) => self & ~flag); -var enable2 = /* @__PURE__ */ dual(2, (self, flag) => self | flag); -var interruptible = (self) => interruption(self) && !windDown(self); -var interruption = (self) => isEnabled(self, Interruption); -var isEnabled = /* @__PURE__ */ dual(2, (self, flag) => (self & flag) !== 0); -var make17 = (...flags) => flags.reduce((a, b) => a | b, 0); -var none5 = /* @__PURE__ */ make17(None2); -var runtimeMetrics = (self) => isEnabled(self, RuntimeMetrics); -var windDown = (self) => isEnabled(self, WindDown); -var diff4 = /* @__PURE__ */ dual(2, (self, that) => make16(self ^ that, that)); -var patch4 = /* @__PURE__ */ dual(2, (self, patch5) => self & (invert(active(patch5)) | enabled(patch5)) | active(patch5) & enabled(patch5)); -var differ = /* @__PURE__ */ make15({ - empty: empty13, - diff: (oldValue, newValue) => diff4(oldValue, newValue), - combine: (first, second) => andThen(second)(first), - patch: (_patch, oldValue) => patch4(oldValue, _patch) -}); + attributes: /* @__PURE__ */ new Map, + links: [], + kind: "internal", + attribute() {}, + event() {}, + end() {}, + addLinks() {} +}; +var noopSpan = (options) => Object.assign(Object.create(NoopSpanProto), options); -// node_modules/effect/dist/esm/RuntimeFlagsPatch.js -var empty14 = empty13; -var enable3 = enable; -var disable3 = disable; -var exclude2 = exclude; +// node_modules/effect/dist/esm/Data.js +var struct2 = struct; +var unsafeStruct = (as2) => Object.setPrototypeOf(as2, StructuralPrototype); +var tuple = (...as2) => unsafeArray(as2); +var array3 = (as2) => unsafeArray(as2.slice(0)); +var unsafeArray = (as2) => Object.setPrototypeOf(as2, ArrayProto); +var _case = () => (args) => args === undefined ? Object.create(StructuralPrototype) : struct2(args); +var tagged = (tag) => (args) => { + const value = args === undefined ? Object.create(StructuralPrototype) : struct2(args); + value._tag = tag; + return value; +}; +var Class = Structural; +var TaggedClass = (tag) => { -// node_modules/effect/dist/esm/internal/blockedRequests.js -var empty15 = { - _tag: "Empty" + class Base2 extends Class { + _tag = tag; + } + return Base2; }; -var par = (self, that) => ({ - _tag: "Par", - left: self, - right: that -}); -var seq = (self, that) => ({ - _tag: "Seq", - left: self, - right: that -}); -var single = (dataSource, blockedRequest) => ({ - _tag: "Single", - dataSource, - blockedRequest -}); -var flatten3 = (self) => { - let current = of3(self); - let updated = empty9(); - while (true) { - const [parallel, sequential] = reduce6(current, [parallelCollectionEmpty(), empty9()], ([parallel2, sequential2], blockedRequest) => { - const [par2, seq2] = step(blockedRequest); - return [parallelCollectionCombine(parallel2, par2), appendAll3(sequential2, seq2)]; - }); - updated = merge4(updated, parallel); - if (isNil(sequential)) { - return reverse3(updated); +var Structural2 = Structural; +var taggedEnum = () => new Proxy({}, { + get(_target, tag, _receiver) { + if (tag === "$is") { + return isTagged; + } else if (tag === "$match") { + return taggedMatch; } - current = sequential; + return tagged(tag); } - throw new Error("BUG: BlockedRequests.flatten - please report an issue at https://github.com/Effect-TS/effect/issues"); -}; -var step = (requests) => { - let current = requests; - let parallel = parallelCollectionEmpty(); - let stack = empty9(); - let sequential = empty9(); - while (true) { - switch (current._tag) { - case "Empty": { - if (isNil(stack)) { - return [parallel, sequential]; - } - current = stack.head; - stack = stack.tail; - break; - } - case "Par": { - stack = cons(current.right, stack); - current = current.left; - break; - } - case "Seq": { - const left3 = current.left; - const right3 = current.right; - switch (left3._tag) { - case "Empty": { - current = right3; - break; - } - case "Par": { - const l = left3.left; - const r = left3.right; - current = par(seq(l, right3), seq(r, right3)); - break; - } - case "Seq": { - const l = left3.left; - const r = left3.right; - current = seq(l, seq(r, right3)); - break; - } - case "Single": { - current = left3; - sequential = cons(right3, sequential); - break; - } +}); +function taggedMatch() { + if (arguments.length === 1) { + const cases2 = arguments[0]; + return function(value2) { + return cases2[value2._tag](value2); + }; + } + const value = arguments[0]; + const cases = arguments[1]; + return cases[value._tag](value); +} +var Error2 = /* @__PURE__ */ function() { + const plainArgsSymbol = /* @__PURE__ */ Symbol.for("effect/Data/Error/plainArgs"); + const O = { + BaseEffectError: class extends YieldableError { + constructor(args) { + super(args?.message, args?.cause ? { + cause: args.cause + } : undefined); + if (args) { + Object.assign(this, args); + Object.defineProperty(this, plainArgsSymbol, { + value: args, + enumerable: false + }); } - break; } - case "Single": { - parallel = parallelCollectionAdd(parallel, current); - if (isNil(stack)) { - return [parallel, sequential]; - } - current = stack.head; - stack = stack.tail; - break; + toJSON() { + return { + ...this[plainArgsSymbol], + ...this + }; } } - } - throw new Error("BUG: BlockedRequests.step - please report an issue at https://github.com/Effect-TS/effect/issues"); -}; -var merge4 = (sequential, parallel) => { - if (isNil(sequential)) { - return of3(parallelCollectionToSequentialCollection(parallel)); - } - if (parallelCollectionIsEmpty(parallel)) { - return sequential; - } - const seqHeadKeys = sequentialCollectionKeys(sequential.head); - const parKeys = parallelCollectionKeys(parallel); - if (seqHeadKeys.length === 1 && parKeys.length === 1 && equals(seqHeadKeys[0], parKeys[0])) { - return cons(sequentialCollectionCombine(sequential.head, parallelCollectionToSequentialCollection(parallel)), sequential.tail); - } - return cons(parallelCollectionToSequentialCollection(parallel), sequential); + }; + return O.BaseEffectError; +}(); +var TaggedError = (tag) => { + const O = { + BaseEffectError: class extends Error2 { + _tag = tag; + } + }; + O.BaseEffectError.prototype.name = tag; + return O.BaseEffectError; }; -var EntryTypeId = /* @__PURE__ */ Symbol.for("effect/RequestBlock/Entry"); - -class EntryImpl { - request; - result; - listeners; - ownerId; - state; - [EntryTypeId] = blockedRequestVariance; - constructor(request, result, listeners, ownerId, state) { - this.request = request; - this.result = result; - this.listeners = listeners; - this.ownerId = ownerId; - this.state = state; - } -} -var blockedRequestVariance = { - _R: (_) => _ -}; -var makeEntry = (options) => new EntryImpl(options.request, options.result, options.listeners, options.ownerId, options.state); -var RequestBlockParallelTypeId = /* @__PURE__ */ Symbol.for("effect/RequestBlock/RequestBlockParallel"); -var parallelVariance = { - _R: (_) => _ -}; - -class ParallelImpl { - map; - [RequestBlockParallelTypeId] = parallelVariance; - constructor(map7) { - this.map = map7; - } -} -var parallelCollectionEmpty = () => new ParallelImpl(empty8()); -var parallelCollectionAdd = (self, blockedRequest) => new ParallelImpl(modifyAt2(self.map, blockedRequest.dataSource, (_) => orElseSome(map2(_, append2(blockedRequest.blockedRequest)), () => of2(blockedRequest.blockedRequest)))); -var parallelCollectionCombine = (self, that) => new ParallelImpl(reduce5(self.map, that.map, (map7, value, key) => set3(map7, key, match2(get7(map7, key), { - onNone: () => value, - onSome: (other) => appendAll2(value, other) -})))); -var parallelCollectionIsEmpty = (self) => isEmpty3(self.map); -var parallelCollectionKeys = (self) => Array.from(keys2(self.map)); -var parallelCollectionToSequentialCollection = (self) => sequentialCollectionMake(map6(self.map, (x) => of2(x))); -var SequentialCollectionTypeId = /* @__PURE__ */ Symbol.for("effect/RequestBlock/RequestBlockSequential"); -var sequentialVariance = { - _R: (_) => _ -}; - -class SequentialImpl { - map; - [SequentialCollectionTypeId] = sequentialVariance; - constructor(map7) { - this.map = map7; - } -} -var sequentialCollectionMake = (map7) => new SequentialImpl(map7); -var sequentialCollectionCombine = (self, that) => new SequentialImpl(reduce5(that.map, self.map, (map7, value, key) => set3(map7, key, match2(get7(map7, key), { - onNone: () => empty4(), - onSome: (a) => appendAll2(a, value) -})))); -var sequentialCollectionKeys = (self) => Array.from(keys2(self.map)); -var sequentialCollectionToChunk = (self) => Array.from(self.map); - -// node_modules/effect/dist/esm/internal/opCodes/cause.js -var OP_DIE = "Die"; -var OP_EMPTY = "Empty"; -var OP_FAIL = "Fail"; -var OP_INTERRUPT = "Interrupt"; -var OP_PARALLEL = "Parallel"; -var OP_SEQUENTIAL = "Sequential"; - -// node_modules/effect/dist/esm/internal/cause.js -var CauseSymbolKey = "effect/Cause"; -var CauseTypeId = /* @__PURE__ */ Symbol.for(CauseSymbolKey); -var variance4 = { - _E: (_) => _ -}; -var proto = { - [CauseTypeId]: variance4, - [symbol]() { - return pipe(hash(CauseSymbolKey), combine(hash(flattenCause(this))), cached(this)); - }, - [symbol2](that) { - return isCause(that) && causeEquals(this, that); - }, - pipe() { - return pipeArguments(this, arguments); - }, - toJSON() { - switch (this._tag) { - case "Empty": - return { - _id: "Cause", - _tag: this._tag - }; - case "Die": - return { - _id: "Cause", - _tag: this._tag, - defect: toJSON(this.defect) - }; - case "Interrupt": - return { - _id: "Cause", - _tag: this._tag, - fiberId: this.fiberId.toJSON() - }; - case "Fail": - return { - _id: "Cause", - _tag: this._tag, - failure: toJSON(this.error) - }; - case "Sequential": - case "Parallel": - return { - _id: "Cause", - _tag: this._tag, - left: toJSON(this.left), - right: toJSON(this.right) - }; - } - }, - toString() { - return pretty(this); - }, - [NodeInspectSymbol]() { - return this.toJSON(); - } -}; -var empty16 = /* @__PURE__ */ (() => { - const o = /* @__PURE__ */ Object.create(proto); - o._tag = OP_EMPTY; - return o; -})(); -var fail = (error) => { - const o = Object.create(proto); - o._tag = OP_FAIL; - o.error = error; - return o; -}; -var die = (defect) => { - const o = Object.create(proto); - o._tag = OP_DIE; - o.defect = defect; - return o; -}; -var interrupt = (fiberId) => { - const o = Object.create(proto); - o._tag = OP_INTERRUPT; - o.fiberId = fiberId; - return o; -}; -var parallel = (left3, right3) => { - const o = Object.create(proto); - o._tag = OP_PARALLEL; - o.left = left3; - o.right = right3; - return o; -}; -var sequential = (left3, right3) => { - const o = Object.create(proto); - o._tag = OP_SEQUENTIAL; - o.left = left3; - o.right = right3; - return o; -}; -var isCause = (u) => hasProperty(u, CauseTypeId); -var isEmptyType = (self) => self._tag === OP_EMPTY; -var isFailType = (self) => self._tag === OP_FAIL; -var isDieType = (self) => self._tag === OP_DIE; -var isEmpty5 = (self) => { - if (self._tag === OP_EMPTY) { - return true; - } - return reduce7(self, true, (acc, cause) => { - switch (cause._tag) { - case OP_EMPTY: { - return some2(acc); - } - case OP_DIE: - case OP_FAIL: - case OP_INTERRUPT: { - return some2(false); - } - default: { - return none2(); - } - } - }); -}; -var isInterrupted = (self) => isSome2(interruptOption(self)); -var isInterruptedOnly = (self) => reduceWithContext(undefined, IsInterruptedOnlyCauseReducer)(self); -var failures = (self) => reverse2(reduce7(self, empty4(), (list, cause) => cause._tag === OP_FAIL ? some2(pipe(list, prepend2(cause.error))) : none2())); -var defects = (self) => reverse2(reduce7(self, empty4(), (list, cause) => cause._tag === OP_DIE ? some2(pipe(list, prepend2(cause.defect))) : none2())); -var interruptors = (self) => reduce7(self, empty7(), (set4, cause) => cause._tag === OP_INTERRUPT ? some2(pipe(set4, add4(cause.fiberId))) : none2()); -var failureOption = (self) => find(self, (cause) => cause._tag === OP_FAIL ? some2(cause.error) : none2()); -var failureOrCause = (self) => { - const option = failureOption(self); - switch (option._tag) { - case "None": { - return right2(self); - } - case "Some": { - return left2(option.value); - } - } -}; -var interruptOption = (self) => find(self, (cause) => cause._tag === OP_INTERRUPT ? some2(cause.fiberId) : none2()); -var keepDefects = (self) => match5(self, { - onEmpty: none2(), - onFail: () => none2(), - onDie: (defect) => some2(die(defect)), - onInterrupt: () => none2(), - onSequential: mergeWith(sequential), - onParallel: mergeWith(parallel) -}); -var keepDefectsAndElectFailures = (self) => match5(self, { - onEmpty: none2(), - onFail: (failure) => some2(die(failure)), - onDie: (defect) => some2(die(defect)), - onInterrupt: () => none2(), - onSequential: mergeWith(sequential), - onParallel: mergeWith(parallel) -}); -var stripFailures = (self) => match5(self, { - onEmpty: empty16, - onFail: () => empty16, - onDie: die, - onInterrupt: interrupt, - onSequential: sequential, - onParallel: parallel -}); -var electFailures = (self) => match5(self, { - onEmpty: empty16, - onFail: die, - onDie: die, - onInterrupt: interrupt, - onSequential: sequential, - onParallel: parallel -}); -var flatMap6 = /* @__PURE__ */ dual(2, (self, f) => match5(self, { - onEmpty: empty16, - onFail: (error) => f(error), - onDie: (defect) => die(defect), - onInterrupt: (fiberId) => interrupt(fiberId), - onSequential: (left3, right3) => sequential(left3, right3), - onParallel: (left3, right3) => parallel(left3, right3) -})); -var flatten4 = (self) => flatMap6(self, identity); -var causeEquals = (left3, right3) => { - let leftStack = of2(left3); - let rightStack = of2(right3); - while (isNonEmpty2(leftStack) && isNonEmpty2(rightStack)) { - const [leftParallel, leftSequential] = pipe(headNonEmpty2(leftStack), reduce7([empty7(), empty4()], ([parallel2, sequential2], cause) => { - const [par2, seq2] = evaluateCause(cause); - return some2([pipe(parallel2, union3(par2)), pipe(sequential2, appendAll2(seq2))]); - })); - const [rightParallel, rightSequential] = pipe(headNonEmpty2(rightStack), reduce7([empty7(), empty4()], ([parallel2, sequential2], cause) => { - const [par2, seq2] = evaluateCause(cause); - return some2([pipe(parallel2, union3(par2)), pipe(sequential2, appendAll2(seq2))]); - })); - if (!equals(leftParallel, rightParallel)) { - return false; - } - leftStack = leftSequential; - rightStack = rightSequential; - } - return true; -}; -var flattenCause = (cause) => { - return flattenCauseLoop(of2(cause), empty4()); -}; -var flattenCauseLoop = (causes, flattened) => { - while (true) { - const [parallel2, sequential2] = pipe(causes, reduce([empty7(), empty4()], ([parallel3, sequential3], cause) => { - const [par2, seq2] = evaluateCause(cause); - return [pipe(parallel3, union3(par2)), pipe(sequential3, appendAll2(seq2))]; - })); - const updated = size3(parallel2) > 0 ? pipe(flattened, prepend2(parallel2)) : flattened; - if (isEmpty(sequential2)) { - return reverse2(updated); - } - causes = sequential2; - flattened = updated; - } - throw new Error(getBugErrorMessage("Cause.flattenCauseLoop")); -}; -var find = /* @__PURE__ */ dual(2, (self, pf) => { - const stack = [self]; - while (stack.length > 0) { - const item = stack.pop(); - const option = pf(item); - switch (option._tag) { - case "None": { - switch (item._tag) { - case OP_SEQUENTIAL: - case OP_PARALLEL: { - stack.push(item.right); - stack.push(item.left); - break; - } - } - break; - } - case "Some": { - return option; - } - } - } - return none2(); -}); -var evaluateCause = (self) => { - let cause = self; - const stack = []; - let _parallel = empty7(); - let _sequential = empty4(); - while (cause !== undefined) { - switch (cause._tag) { - case OP_EMPTY: { - if (stack.length === 0) { - return [_parallel, _sequential]; - } - cause = stack.pop(); - break; - } - case OP_FAIL: { - _parallel = add4(_parallel, make7(cause._tag, cause.error)); - if (stack.length === 0) { - return [_parallel, _sequential]; - } - cause = stack.pop(); - break; - } - case OP_DIE: { - _parallel = add4(_parallel, make7(cause._tag, cause.defect)); - if (stack.length === 0) { - return [_parallel, _sequential]; - } - cause = stack.pop(); - break; - } - case OP_INTERRUPT: { - _parallel = add4(_parallel, make7(cause._tag, cause.fiberId)); - if (stack.length === 0) { - return [_parallel, _sequential]; - } - cause = stack.pop(); - break; - } - case OP_SEQUENTIAL: { - switch (cause.left._tag) { - case OP_EMPTY: { - cause = cause.right; - break; - } - case OP_SEQUENTIAL: { - cause = sequential(cause.left.left, sequential(cause.left.right, cause.right)); - break; - } - case OP_PARALLEL: { - cause = parallel(sequential(cause.left.left, cause.right), sequential(cause.left.right, cause.right)); - break; - } - default: { - _sequential = prepend2(_sequential, cause.right); - cause = cause.left; - break; - } - } - break; - } - case OP_PARALLEL: { - stack.push(cause.right); - cause = cause.left; - break; - } - } - } - throw new Error(getBugErrorMessage("Cause.evaluateCauseLoop")); -}; -var IsInterruptedOnlyCauseReducer = { - emptyCase: constTrue, - failCase: constFalse, - dieCase: constFalse, - interruptCase: constTrue, - sequentialCase: (_, left3, right3) => left3 && right3, - parallelCase: (_, left3, right3) => left3 && right3 -}; -var OP_SEQUENTIAL_CASE = "SequentialCase"; -var OP_PARALLEL_CASE = "ParallelCase"; -var match5 = /* @__PURE__ */ dual(2, (self, { - onDie, - onEmpty, - onFail, - onInterrupt, - onParallel, - onSequential -}) => { - return reduceWithContext(self, undefined, { - emptyCase: () => onEmpty, - failCase: (_, error) => onFail(error), - dieCase: (_, defect) => onDie(defect), - interruptCase: (_, fiberId) => onInterrupt(fiberId), - sequentialCase: (_, left3, right3) => onSequential(left3, right3), - parallelCase: (_, left3, right3) => onParallel(left3, right3) - }); -}); -var reduce7 = /* @__PURE__ */ dual(3, (self, zero3, pf) => { - let accumulator = zero3; - let cause = self; - const causes = []; - while (cause !== undefined) { - const option = pf(accumulator, cause); - accumulator = isSome2(option) ? option.value : accumulator; - switch (cause._tag) { - case OP_SEQUENTIAL: { - causes.push(cause.right); - cause = cause.left; - break; - } - case OP_PARALLEL: { - causes.push(cause.right); - cause = cause.left; - break; - } - default: { - cause = undefined; - break; - } - } - if (cause === undefined && causes.length > 0) { - cause = causes.pop(); - } - } - return accumulator; -}); -var reduceWithContext = /* @__PURE__ */ dual(3, (self, context, reducer) => { - const input = [self]; - const output = []; - while (input.length > 0) { - const cause = input.pop(); - switch (cause._tag) { - case OP_EMPTY: { - output.push(right2(reducer.emptyCase(context))); - break; - } - case OP_FAIL: { - output.push(right2(reducer.failCase(context, cause.error))); - break; - } - case OP_DIE: { - output.push(right2(reducer.dieCase(context, cause.defect))); - break; - } - case OP_INTERRUPT: { - output.push(right2(reducer.interruptCase(context, cause.fiberId))); - break; - } - case OP_SEQUENTIAL: { - input.push(cause.right); - input.push(cause.left); - output.push(left2({ - _tag: OP_SEQUENTIAL_CASE - })); - break; - } - case OP_PARALLEL: { - input.push(cause.right); - input.push(cause.left); - output.push(left2({ - _tag: OP_PARALLEL_CASE - })); - break; - } - } - } - const accumulator = []; - while (output.length > 0) { - const either2 = output.pop(); - switch (either2._tag) { - case "Left": { - switch (either2.left._tag) { - case OP_SEQUENTIAL_CASE: { - const left3 = accumulator.pop(); - const right3 = accumulator.pop(); - const value = reducer.sequentialCase(context, left3, right3); - accumulator.push(value); - break; - } - case OP_PARALLEL_CASE: { - const left3 = accumulator.pop(); - const right3 = accumulator.pop(); - const value = reducer.parallelCase(context, left3, right3); - accumulator.push(value); - break; - } - } - break; - } - case "Right": { - accumulator.push(either2.right); - break; - } - } - } - if (accumulator.length === 0) { - throw new Error("BUG: Cause.reduceWithContext - please report an issue at https://github.com/Effect-TS/effect/issues"); - } - return accumulator.pop(); -}); -var pretty = (cause, options) => { - if (isInterruptedOnly(cause)) { - return "All fibers interrupted without errors."; - } - return prettyErrors(cause).map(function(e) { - if (options?.renderErrorCause !== true || e.cause === undefined) { - return e.stack; - } - return `${e.stack} { -${renderErrorCause(e.cause, " ")} -}`; - }).join(` -`); -}; -var renderErrorCause = (cause, prefix) => { - const lines = cause.stack.split(` -`); - let stack = `${prefix}[cause]: ${lines[0]}`; - for (let i = 1, len = lines.length;i < len; i++) { - stack += ` -${prefix}${lines[i]}`; - } - if (cause.cause) { - stack += ` { -${renderErrorCause(cause.cause, `${prefix} `)} -${prefix}}`; - } - return stack; -}; -var makePrettyError = (originalError) => { - const originalErrorIsObject = typeof originalError === "object" && originalError !== null; - const prevLimit = Error.stackTraceLimit; - Error.stackTraceLimit = 1; - const error = new Error(prettyErrorMessage(originalError), originalErrorIsObject && "cause" in originalError && typeof originalError.cause !== "undefined" ? { - cause: makePrettyError(originalError.cause) - } : undefined); - Error.stackTraceLimit = prevLimit; - if (error.message === "") { - error.message = "An error has occurred"; - } - Error.stackTraceLimit = prevLimit; - error.name = originalError instanceof Error ? originalError.name : "Error"; - if (originalErrorIsObject) { - if (spanSymbol in originalError) { - error.span = originalError[spanSymbol]; - } - Object.keys(originalError).forEach((key) => { - if (!(key in error)) { - error[key] = originalError[key]; - } - }); - } - error.stack = prettyErrorStack(`${error.name}: ${error.message}`, originalError instanceof Error && originalError.stack ? originalError.stack : "", error.span); - return error; -}; -var prettyErrorMessage = (u) => { - if (typeof u === "string") { - return u; - } - if (typeof u === "object" && u !== null && u instanceof Error) { - return u.message; - } - try { - if (hasProperty(u, "toString") && isFunction2(u["toString"]) && u["toString"] !== Object.prototype.toString && u["toString"] !== globalThis.Array.prototype.toString) { - return u["toString"](); - } - } catch {} - return stringifyCircular(u); -}; -var locationRegex = /\((.*)\)/g; -var spanToTrace = /* @__PURE__ */ globalValue("effect/Tracer/spanToTrace", () => new WeakMap); -var prettyErrorStack = (message, stack, span2) => { - const out = [message]; - const lines = stack.startsWith(message) ? stack.slice(message.length).split(` -`) : stack.split(` -`); - for (let i = 1;i < lines.length; i++) { - if (lines[i].includes(" at new BaseEffectError") || lines[i].includes(" at new YieldableError")) { - i++; - continue; - } - if (lines[i].includes("Generator.next")) { - break; - } - if (lines[i].includes("effect_internal_function")) { - break; - } - out.push(lines[i].replace(/at .*effect_instruction_i.*\((.*)\)/, "at $1").replace(/EffectPrimitive\.\w+/, "")); - } - if (span2) { - let current = span2; - let i = 0; - while (current && current._tag === "Span" && i < 10) { - const stackFn = spanToTrace.get(current); - if (typeof stackFn === "function") { - const stack2 = stackFn(); - if (typeof stack2 === "string") { - const locationMatchAll = stack2.matchAll(locationRegex); - let match6 = false; - for (const [, location] of locationMatchAll) { - match6 = true; - out.push(` at ${current.name} (${location})`); - } - if (!match6) { - out.push(` at ${current.name} (${stack2.replace(/^at /, "")})`); - } - } else { - out.push(` at ${current.name}`); - } - } else { - out.push(` at ${current.name}`); - } - current = getOrUndefined(current.parent); - i++; - } - } - return out.join(` -`); -}; -var spanSymbol = /* @__PURE__ */ Symbol.for("effect/SpanAnnotation"); -var prettyErrors = (cause) => reduceWithContext(cause, undefined, { - emptyCase: () => [], - dieCase: (_, unknownError) => { - return [makePrettyError(unknownError)]; - }, - failCase: (_, error) => { - return [makePrettyError(error)]; - }, - interruptCase: () => [], - parallelCase: (_, l, r) => [...l, ...r], - sequentialCase: (_, l, r) => [...l, ...r] -}); - -// node_modules/effect/dist/esm/internal/opCodes/deferred.js -var OP_STATE_PENDING = "Pending"; -var OP_STATE_DONE = "Done"; - -// node_modules/effect/dist/esm/internal/deferred.js -var DeferredSymbolKey = "effect/Deferred"; -var DeferredTypeId = /* @__PURE__ */ Symbol.for(DeferredSymbolKey); -var deferredVariance = { - _E: (_) => _, - _A: (_) => _ -}; -var pending = (joiners) => { - return { - _tag: OP_STATE_PENDING, - joiners - }; -}; -var done = (effect) => { - return { - _tag: OP_STATE_DONE, - effect - }; -}; - -// node_modules/effect/dist/esm/internal/singleShotGen.js -class SingleShotGen2 { - self; - called = false; - constructor(self) { - this.self = self; - } - next(a) { - return this.called ? { - value: a, - done: true - } : (this.called = true, { - value: this.self, - done: false - }); - } - return(a) { - return { - value: a, - done: true - }; - } - throw(e) { - throw e; - } - [Symbol.iterator]() { - return new SingleShotGen2(this.self); - } -} - -// node_modules/effect/dist/esm/internal/core.js -var blocked = (blockedRequests, _continue) => { - const effect = new EffectPrimitive("Blocked"); - effect.effect_instruction_i0 = blockedRequests; - effect.effect_instruction_i1 = _continue; - return effect; -}; -var runRequestBlock = (blockedRequests) => { - const effect = new EffectPrimitive("RunBlocked"); - effect.effect_instruction_i0 = blockedRequests; - return effect; -}; -var EffectTypeId2 = /* @__PURE__ */ Symbol.for("effect/Effect"); - -class RevertFlags { - patch; - op; - _op = OP_REVERT_FLAGS; - constructor(patch5, op) { - this.patch = patch5; - this.op = op; - } -} - -class EffectPrimitive { - _op; - effect_instruction_i0 = undefined; - effect_instruction_i1 = undefined; - effect_instruction_i2 = undefined; - trace = undefined; - [EffectTypeId2] = effectVariance; - constructor(_op) { - this._op = _op; - } - [symbol2](that) { - return this === that; - } - [symbol]() { - return cached(this, random(this)); - } - pipe() { - return pipeArguments(this, arguments); - } - toJSON() { - return { - _id: "Effect", - _op: this._op, - effect_instruction_i0: toJSON(this.effect_instruction_i0), - effect_instruction_i1: toJSON(this.effect_instruction_i1), - effect_instruction_i2: toJSON(this.effect_instruction_i2) - }; - } - toString() { - return format(this.toJSON()); - } - [NodeInspectSymbol]() { - return this.toJSON(); - } - [Symbol.iterator]() { - return new SingleShotGen2(new YieldWrap(this)); - } -} - -class EffectPrimitiveFailure { - _op; - effect_instruction_i0 = undefined; - effect_instruction_i1 = undefined; - effect_instruction_i2 = undefined; - trace = undefined; - [EffectTypeId2] = effectVariance; - constructor(_op) { - this._op = _op; - this._tag = _op; - } - [symbol2](that) { - return exitIsExit(that) && that._op === "Failure" && equals(this.effect_instruction_i0, that.effect_instruction_i0); - } - [symbol]() { - return pipe(string(this._tag), combine(hash(this.effect_instruction_i0)), cached(this)); - } - get cause() { - return this.effect_instruction_i0; - } - pipe() { - return pipeArguments(this, arguments); - } - toJSON() { - return { - _id: "Exit", - _tag: this._op, - cause: this.cause.toJSON() - }; - } - toString() { - return format(this.toJSON()); - } - [NodeInspectSymbol]() { - return this.toJSON(); - } - [Symbol.iterator]() { - return new SingleShotGen2(new YieldWrap(this)); - } -} - -class EffectPrimitiveSuccess { - _op; - effect_instruction_i0 = undefined; - effect_instruction_i1 = undefined; - effect_instruction_i2 = undefined; - trace = undefined; - [EffectTypeId2] = effectVariance; - constructor(_op) { - this._op = _op; - this._tag = _op; - } - [symbol2](that) { - return exitIsExit(that) && that._op === "Success" && equals(this.effect_instruction_i0, that.effect_instruction_i0); - } - [symbol]() { - return pipe(string(this._tag), combine(hash(this.effect_instruction_i0)), cached(this)); - } - get value() { - return this.effect_instruction_i0; - } - pipe() { - return pipeArguments(this, arguments); - } - toJSON() { - return { - _id: "Exit", - _tag: this._op, - value: toJSON(this.value) - }; - } - toString() { - return format(this.toJSON()); - } - [NodeInspectSymbol]() { - return this.toJSON(); - } - [Symbol.iterator]() { - return new SingleShotGen2(new YieldWrap(this)); - } -} -var isEffect = (u) => hasProperty(u, EffectTypeId2); -var withFiberRuntime = (withRuntime) => { - const effect = new EffectPrimitive(OP_WITH_RUNTIME); - effect.effect_instruction_i0 = withRuntime; - return effect; -}; -var acquireUseRelease = /* @__PURE__ */ dual(3, (acquire, use, release) => uninterruptibleMask((restore) => flatMap7(acquire, (a) => flatMap7(exit(suspend(() => restore(use(a)))), (exit) => { - return suspend(() => release(a, exit)).pipe(matchCauseEffect({ - onFailure: (cause) => { - switch (exit._tag) { - case OP_FAILURE: - return failCause(sequential(exit.effect_instruction_i0, cause)); - case OP_SUCCESS: - return failCause(cause); - } - }, - onSuccess: () => exit - })); -})))); -var as = /* @__PURE__ */ dual(2, (self, value) => flatMap7(self, () => succeed(value))); -var asVoid = (self) => as(self, undefined); -var custom = function() { - const wrapper = new EffectPrimitive(OP_COMMIT); - switch (arguments.length) { - case 2: { - wrapper.effect_instruction_i0 = arguments[0]; - wrapper.commit = arguments[1]; - break; - } - case 3: { - wrapper.effect_instruction_i0 = arguments[0]; - wrapper.effect_instruction_i1 = arguments[1]; - wrapper.commit = arguments[2]; - break; - } - case 4: { - wrapper.effect_instruction_i0 = arguments[0]; - wrapper.effect_instruction_i1 = arguments[1]; - wrapper.effect_instruction_i2 = arguments[2]; - wrapper.commit = arguments[3]; - break; - } - default: { - throw new Error(getBugErrorMessage("you're not supposed to end up here")); - } - } - return wrapper; -}; -var unsafeAsync = (register, blockingOn = none4) => { - const effect = new EffectPrimitive(OP_ASYNC); - let cancelerRef = undefined; - effect.effect_instruction_i0 = (resume) => { - cancelerRef = register(resume); - }; - effect.effect_instruction_i1 = blockingOn; - return onInterrupt(effect, (_) => isEffect(cancelerRef) ? cancelerRef : void_); -}; -var asyncInterrupt = (register, blockingOn = none4) => suspend(() => unsafeAsync(register, blockingOn)); -var async_ = (resume, blockingOn = none4) => { - return custom(resume, function() { - let backingResume = undefined; - let pendingEffect = undefined; - function proxyResume(effect2) { - if (backingResume) { - backingResume(effect2); - } else if (pendingEffect === undefined) { - pendingEffect = effect2; - } - } - const effect = new EffectPrimitive(OP_ASYNC); - effect.effect_instruction_i0 = (resume2) => { - backingResume = resume2; - if (pendingEffect) { - resume2(pendingEffect); - } - }; - effect.effect_instruction_i1 = blockingOn; - let cancelerRef = undefined; - let controllerRef = undefined; - if (this.effect_instruction_i0.length !== 1) { - controllerRef = new AbortController; - cancelerRef = internalCall(() => this.effect_instruction_i0(proxyResume, controllerRef.signal)); - } else { - cancelerRef = internalCall(() => this.effect_instruction_i0(proxyResume)); - } - return cancelerRef || controllerRef ? onInterrupt(effect, (_) => { - if (controllerRef) { - controllerRef.abort(); - } - return cancelerRef ?? void_; - }) : effect; - }); -}; -var catchAllCause = /* @__PURE__ */ dual(2, (self, f) => { - const effect = new EffectPrimitive(OP_ON_FAILURE); - effect.effect_instruction_i0 = self; - effect.effect_instruction_i1 = f; - return effect; -}); -var catchAll = /* @__PURE__ */ dual(2, (self, f) => matchEffect(self, { - onFailure: f, - onSuccess: succeed -})); -var catchIf = /* @__PURE__ */ dual(3, (self, predicate, f) => catchAllCause(self, (cause) => { - const either2 = failureOrCause(cause); - switch (either2._tag) { - case "Left": - return predicate(either2.left) ? f(either2.left) : failCause(cause); - case "Right": - return failCause(either2.right); - } -})); -var catchSome = /* @__PURE__ */ dual(2, (self, pf) => catchAllCause(self, (cause) => { - const either2 = failureOrCause(cause); - switch (either2._tag) { - case "Left": - return pipe(pf(either2.left), getOrElse(() => failCause(cause))); - case "Right": - return failCause(either2.right); - } -})); -var checkInterruptible = (f) => withFiberRuntime((_, status) => f(interruption(status.runtimeFlags))); -var originalSymbol = /* @__PURE__ */ Symbol.for("effect/OriginalAnnotation"); -var capture = (obj, span2) => { - if (isSome2(span2)) { - return new Proxy(obj, { - has(target, p) { - return p === spanSymbol || p === originalSymbol || p in target; - }, - get(target, p) { - if (p === spanSymbol) { - return span2.value; - } - if (p === originalSymbol) { - return obj; - } - return target[p]; - } - }); - } - return obj; -}; -var die2 = (defect) => isObject(defect) && !(spanSymbol in defect) ? withFiberRuntime((fiber) => failCause(die(capture(defect, currentSpanFromFiber(fiber))))) : failCause(die(defect)); -var dieMessage = (message) => failCauseSync(() => die(new RuntimeException(message))); -var dieSync = (evaluate) => flatMap7(sync(evaluate), die2); -var either2 = (self) => matchEffect(self, { - onFailure: (e) => succeed(left2(e)), - onSuccess: (a) => succeed(right2(a)) -}); -var exit = (self) => matchCause(self, { - onFailure: exitFailCause, - onSuccess: exitSucceed -}); -var fail2 = (error) => isObject(error) && !(spanSymbol in error) ? withFiberRuntime((fiber) => failCause(fail(capture(error, currentSpanFromFiber(fiber))))) : failCause(fail(error)); -var failSync = (evaluate) => flatMap7(sync(evaluate), fail2); -var failCause = (cause) => { - const effect = new EffectPrimitiveFailure(OP_FAILURE); - effect.effect_instruction_i0 = cause; - return effect; -}; -var failCauseSync = (evaluate) => flatMap7(sync(evaluate), failCause); -var fiberId = /* @__PURE__ */ withFiberRuntime((state) => succeed(state.id())); -var fiberIdWith = (f) => withFiberRuntime((state) => f(state.id())); -var flatMap7 = /* @__PURE__ */ dual(2, (self, f) => { - const effect = new EffectPrimitive(OP_ON_SUCCESS); - effect.effect_instruction_i0 = self; - effect.effect_instruction_i1 = f; - return effect; -}); -var andThen2 = /* @__PURE__ */ dual(2, (self, f) => flatMap7(self, (a) => { - const b = typeof f === "function" ? f(a) : f; - if (isEffect(b)) { - return b; - } else if (isPromiseLike(b)) { - return unsafeAsync((resume) => { - b.then((a2) => resume(succeed(a2)), (e) => resume(fail2(new UnknownException(e, "An unknown error occurred in Effect.andThen")))); - }); - } - return succeed(b); -})); -var step2 = (self) => { - const effect = new EffectPrimitive("OnStep"); - effect.effect_instruction_i0 = self; - return effect; -}; -var flatten5 = (self) => flatMap7(self, identity); -var flip = (self) => matchEffect(self, { - onFailure: succeed, - onSuccess: fail2 -}); -var matchCause = /* @__PURE__ */ dual(2, (self, options) => matchCauseEffect(self, { - onFailure: (cause) => succeed(options.onFailure(cause)), - onSuccess: (a) => succeed(options.onSuccess(a)) -})); -var matchCauseEffect = /* @__PURE__ */ dual(2, (self, options) => { - const effect = new EffectPrimitive(OP_ON_SUCCESS_AND_FAILURE); - effect.effect_instruction_i0 = self; - effect.effect_instruction_i1 = options.onFailure; - effect.effect_instruction_i2 = options.onSuccess; - return effect; -}); -var matchEffect = /* @__PURE__ */ dual(2, (self, options) => matchCauseEffect(self, { - onFailure: (cause) => { - const defects2 = defects(cause); - if (defects2.length > 0) { - return failCause(electFailures(cause)); - } - const failures2 = failures(cause); - if (failures2.length > 0) { - return options.onFailure(unsafeHead(failures2)); - } - return failCause(cause); - }, - onSuccess: options.onSuccess -})); -var forEachSequential = /* @__PURE__ */ dual(2, (self, f) => suspend(() => { - const arr = fromIterable(self); - const ret = allocate(arr.length); - let i = 0; - return as(whileLoop({ - while: () => i < arr.length, - body: () => f(arr[i], i), - step: (b) => { - ret[i++] = b; - } - }), ret); -})); -var forEachSequentialDiscard = /* @__PURE__ */ dual(2, (self, f) => suspend(() => { - const arr = fromIterable(self); - let i = 0; - return whileLoop({ - while: () => i < arr.length, - body: () => f(arr[i], i), - step: () => { - i++; - } - }); -})); -var if_ = /* @__PURE__ */ dual((args) => typeof args[0] === "boolean" || isEffect(args[0]), (self, options) => isEffect(self) ? flatMap7(self, (b) => b ? options.onTrue() : options.onFalse()) : self ? options.onTrue() : options.onFalse()); -var interrupt2 = /* @__PURE__ */ flatMap7(fiberId, (fiberId2) => interruptWith(fiberId2)); -var interruptWith = (fiberId2) => failCause(interrupt(fiberId2)); -var interruptible2 = (self) => { - const effect = new EffectPrimitive(OP_UPDATE_RUNTIME_FLAGS); - effect.effect_instruction_i0 = enable3(Interruption); - effect.effect_instruction_i1 = () => self; - return effect; -}; -var interruptibleMask = (f) => custom(f, function() { - const effect = new EffectPrimitive(OP_UPDATE_RUNTIME_FLAGS); - effect.effect_instruction_i0 = enable3(Interruption); - effect.effect_instruction_i1 = (oldFlags) => interruption(oldFlags) ? internalCall(() => this.effect_instruction_i0(interruptible2)) : internalCall(() => this.effect_instruction_i0(uninterruptible)); - return effect; -}); -var intoDeferred = /* @__PURE__ */ dual(2, (self, deferred) => uninterruptibleMask((restore) => flatMap7(exit(restore(self)), (exit2) => deferredDone(deferred, exit2)))); -var map9 = /* @__PURE__ */ dual(2, (self, f) => flatMap7(self, (a) => sync(() => f(a)))); -var mapBoth2 = /* @__PURE__ */ dual(2, (self, options) => matchEffect(self, { - onFailure: (e) => failSync(() => options.onFailure(e)), - onSuccess: (a) => sync(() => options.onSuccess(a)) -})); -var mapError = /* @__PURE__ */ dual(2, (self, f) => matchCauseEffect(self, { - onFailure: (cause) => { - const either3 = failureOrCause(cause); - switch (either3._tag) { - case "Left": { - return failSync(() => f(either3.left)); - } - case "Right": { - return failCause(either3.right); - } - } - }, - onSuccess: succeed -})); -var onError = /* @__PURE__ */ dual(2, (self, cleanup) => onExit(self, (exit2) => exitIsSuccess(exit2) ? void_ : cleanup(exit2.effect_instruction_i0))); -var onExit = /* @__PURE__ */ dual(2, (self, cleanup) => uninterruptibleMask((restore) => matchCauseEffect(restore(self), { - onFailure: (cause1) => { - const result = exitFailCause(cause1); - return matchCauseEffect(cleanup(result), { - onFailure: (cause2) => exitFailCause(sequential(cause1, cause2)), - onSuccess: () => result - }); - }, - onSuccess: (success) => { - const result = exitSucceed(success); - return zipRight(cleanup(result), result); - } -}))); -var onInterrupt = /* @__PURE__ */ dual(2, (self, cleanup) => onExit(self, exitMatch({ - onFailure: (cause) => isInterruptedOnly(cause) ? asVoid(cleanup(interruptors(cause))) : void_, - onSuccess: () => void_ -}))); -var orElse2 = /* @__PURE__ */ dual(2, (self, that) => attemptOrElse(self, that, succeed)); -var orDie = (self) => orDieWith(self, identity); -var orDieWith = /* @__PURE__ */ dual(2, (self, f) => matchEffect(self, { - onFailure: (e) => die2(f(e)), - onSuccess: succeed -})); -var partitionMap2 = partitionMap; -var runtimeFlags = /* @__PURE__ */ withFiberRuntime((_, status) => succeed(status.runtimeFlags)); -var succeed = (value) => { - const effect = new EffectPrimitiveSuccess(OP_SUCCESS); - effect.effect_instruction_i0 = value; - return effect; -}; -var suspend = (evaluate) => { - const effect = new EffectPrimitive(OP_COMMIT); - effect.commit = evaluate; - return effect; -}; -var sync = (thunk) => { - const effect = new EffectPrimitive(OP_SYNC); - effect.effect_instruction_i0 = thunk; - return effect; -}; -var tap = /* @__PURE__ */ dual((args) => args.length === 3 || args.length === 2 && !(isObject(args[1]) && ("onlyEffect" in args[1])), (self, f) => flatMap7(self, (a) => { - const b = typeof f === "function" ? f(a) : f; - if (isEffect(b)) { - return as(b, a); - } else if (isPromiseLike(b)) { - return unsafeAsync((resume) => { - b.then((_) => resume(succeed(a)), (e) => resume(fail2(new UnknownException(e, "An unknown error occurred in Effect.tap")))); - }); - } - return succeed(a); -})); -var transplant = (f) => withFiberRuntime((state) => { - const scopeOverride = state.getFiberRef(currentForkScopeOverride); - const scope = pipe(scopeOverride, getOrElse(() => state.scope())); - return f(fiberRefLocally(currentForkScopeOverride, some2(scope))); -}); -var attemptOrElse = /* @__PURE__ */ dual(3, (self, that, onSuccess) => matchCauseEffect(self, { - onFailure: (cause) => { - const defects2 = defects(cause); - if (defects2.length > 0) { - return failCause(getOrThrow2(keepDefectsAndElectFailures(cause))); - } - return that(); - }, - onSuccess -})); -var uninterruptible = (self) => { - const effect = new EffectPrimitive(OP_UPDATE_RUNTIME_FLAGS); - effect.effect_instruction_i0 = disable3(Interruption); - effect.effect_instruction_i1 = () => self; - return effect; -}; -var uninterruptibleMask = (f) => custom(f, function() { - const effect = new EffectPrimitive(OP_UPDATE_RUNTIME_FLAGS); - effect.effect_instruction_i0 = disable3(Interruption); - effect.effect_instruction_i1 = (oldFlags) => interruption(oldFlags) ? internalCall(() => this.effect_instruction_i0(interruptible2)) : internalCall(() => this.effect_instruction_i0(uninterruptible)); - return effect; -}); -var void_ = /* @__PURE__ */ succeed(undefined); -var updateRuntimeFlags = (patch5) => { - const effect = new EffectPrimitive(OP_UPDATE_RUNTIME_FLAGS); - effect.effect_instruction_i0 = patch5; - effect.effect_instruction_i1 = undefined; - return effect; -}; -var whenEffect = /* @__PURE__ */ dual(2, (self, condition) => flatMap7(condition, (b) => { - if (b) { - return pipe(self, map9(some2)); - } - return succeed(none2()); -})); -var whileLoop = (options) => { - const effect = new EffectPrimitive(OP_WHILE); - effect.effect_instruction_i0 = options.while; - effect.effect_instruction_i1 = options.body; - effect.effect_instruction_i2 = options.step; - return effect; -}; -var fromIterator = (iterator) => suspend(() => { - const effect = new EffectPrimitive(OP_ITERATOR); - effect.effect_instruction_i0 = iterator(); - return effect; -}); -var gen = function() { - const f = arguments.length === 1 ? arguments[0] : arguments[1].bind(arguments[0]); - return fromIterator(() => f(pipe)); -}; -var fnUntraced = (body, ...pipeables) => Object.defineProperty(pipeables.length === 0 ? function(...args) { - return fromIterator(() => body.apply(this, args)); -} : function(...args) { - let effect = fromIterator(() => body.apply(this, args)); - for (const x of pipeables) { - effect = x(effect, ...args); - } - return effect; -}, "length", { - value: body.length, - configurable: true -}); -var withConcurrency = /* @__PURE__ */ dual(2, (self, concurrency) => fiberRefLocally(self, currentConcurrency, concurrency)); -var withRequestBatching = /* @__PURE__ */ dual(2, (self, requestBatching) => fiberRefLocally(self, currentRequestBatching, requestBatching)); -var withRuntimeFlags = /* @__PURE__ */ dual(2, (self, update2) => { - const effect = new EffectPrimitive(OP_UPDATE_RUNTIME_FLAGS); - effect.effect_instruction_i0 = update2; - effect.effect_instruction_i1 = () => self; - return effect; -}); -var withTracerEnabled = /* @__PURE__ */ dual(2, (effect, enabled2) => fiberRefLocally(effect, currentTracerEnabled, enabled2)); -var withTracerTiming = /* @__PURE__ */ dual(2, (effect, enabled2) => fiberRefLocally(effect, currentTracerTimingEnabled, enabled2)); -var yieldNow = (options) => { - const effect = new EffectPrimitive(OP_YIELD); - return typeof options?.priority !== "undefined" ? withSchedulingPriority(effect, options.priority) : effect; -}; -var zip2 = /* @__PURE__ */ dual(2, (self, that) => flatMap7(self, (a) => map9(that, (b) => [a, b]))); -var zipLeft = /* @__PURE__ */ dual(2, (self, that) => flatMap7(self, (a) => as(that, a))); -var zipRight = /* @__PURE__ */ dual(2, (self, that) => flatMap7(self, () => that)); -var zipWith2 = /* @__PURE__ */ dual(3, (self, that, f) => flatMap7(self, (a) => map9(that, (b) => f(a, b)))); -var never = /* @__PURE__ */ asyncInterrupt(() => { - const interval = setInterval(() => {}, 2 ** 31 - 1); - return sync(() => clearInterval(interval)); -}); -var interruptFiber = (self) => flatMap7(fiberId, (fiberId2) => pipe(self, interruptAsFiber(fiberId2))); -var interruptAsFiber = /* @__PURE__ */ dual(2, (self, fiberId2) => flatMap7(self.interruptAsFork(fiberId2), () => self.await)); -var logLevelAll = { - _tag: "All", - syslog: 0, - label: "ALL", - ordinal: Number.MIN_SAFE_INTEGER, - pipe() { - return pipeArguments(this, arguments); - } -}; -var logLevelFatal = { - _tag: "Fatal", - syslog: 2, - label: "FATAL", - ordinal: 50000, - pipe() { - return pipeArguments(this, arguments); - } -}; -var logLevelError = { - _tag: "Error", - syslog: 3, - label: "ERROR", - ordinal: 40000, - pipe() { - return pipeArguments(this, arguments); - } -}; -var logLevelWarning = { - _tag: "Warning", - syslog: 4, - label: "WARN", - ordinal: 30000, - pipe() { - return pipeArguments(this, arguments); - } -}; -var logLevelInfo = { - _tag: "Info", - syslog: 6, - label: "INFO", - ordinal: 20000, - pipe() { - return pipeArguments(this, arguments); - } -}; -var logLevelDebug = { - _tag: "Debug", - syslog: 7, - label: "DEBUG", - ordinal: 1e4, - pipe() { - return pipeArguments(this, arguments); - } -}; -var logLevelTrace = { - _tag: "Trace", - syslog: 7, - label: "TRACE", - ordinal: 0, - pipe() { - return pipeArguments(this, arguments); - } -}; -var logLevelNone = { - _tag: "None", - syslog: 7, - label: "OFF", - ordinal: Number.MAX_SAFE_INTEGER, - pipe() { - return pipeArguments(this, arguments); - } -}; -var FiberRefSymbolKey = "effect/FiberRef"; -var FiberRefTypeId = /* @__PURE__ */ Symbol.for(FiberRefSymbolKey); -var fiberRefVariance = { - _A: (_) => _ -}; -var fiberRefGet = (self) => withFiberRuntime((fiber) => exitSucceed(fiber.getFiberRef(self))); -var fiberRefGetWith = /* @__PURE__ */ dual(2, (self, f) => flatMap7(fiberRefGet(self), f)); -var fiberRefSet = /* @__PURE__ */ dual(2, (self, value) => fiberRefModify(self, () => [undefined, value])); -var fiberRefModify = /* @__PURE__ */ dual(2, (self, f) => withFiberRuntime((state) => { - const [b, a] = f(state.getFiberRef(self)); - state.setFiberRef(self, a); - return succeed(b); -})); -var fiberRefLocally = /* @__PURE__ */ dual(3, (use, self, value) => acquireUseRelease(zipLeft(fiberRefGet(self), fiberRefSet(self, value)), () => use, (oldValue) => fiberRefSet(self, oldValue))); -var fiberRefLocallyWith = /* @__PURE__ */ dual(3, (use, self, f) => fiberRefGetWith(self, (a) => fiberRefLocally(use, self, f(a)))); -var fiberRefUnsafeMake = (initial, options) => fiberRefUnsafeMakePatch(initial, { - differ: update(), - fork: options?.fork ?? identity, - join: options?.join -}); -var fiberRefUnsafeMakeHashSet = (initial) => { - const differ2 = hashSet(); - return fiberRefUnsafeMakePatch(initial, { - differ: differ2, - fork: differ2.empty - }); -}; -var fiberRefUnsafeMakeReadonlyArray = (initial) => { - const differ2 = readonlyArray(update()); - return fiberRefUnsafeMakePatch(initial, { - differ: differ2, - fork: differ2.empty - }); -}; -var fiberRefUnsafeMakeContext = (initial) => { - const differ2 = environment(); - return fiberRefUnsafeMakePatch(initial, { - differ: differ2, - fork: differ2.empty - }); -}; -var fiberRefUnsafeMakePatch = (initial, options) => { - const _fiberRef = { - ...CommitPrototype, - [FiberRefTypeId]: fiberRefVariance, - initial, - commit() { - return fiberRefGet(this); - }, - diff: (oldValue, newValue) => options.differ.diff(oldValue, newValue), - combine: (first, second) => options.differ.combine(first, second), - patch: (patch5) => (oldValue) => options.differ.patch(patch5, oldValue), - fork: options.fork, - join: options.join ?? ((_, n) => n) - }; - return _fiberRef; -}; -var fiberRefUnsafeMakeRuntimeFlags = (initial) => fiberRefUnsafeMakePatch(initial, { - differ, - fork: differ.empty -}); -var currentContext = /* @__PURE__ */ globalValue(/* @__PURE__ */ Symbol.for("effect/FiberRef/currentContext"), () => fiberRefUnsafeMakeContext(empty3())); -var currentSchedulingPriority = /* @__PURE__ */ globalValue(/* @__PURE__ */ Symbol.for("effect/FiberRef/currentSchedulingPriority"), () => fiberRefUnsafeMake(0)); -var currentMaxOpsBeforeYield = /* @__PURE__ */ globalValue(/* @__PURE__ */ Symbol.for("effect/FiberRef/currentMaxOpsBeforeYield"), () => fiberRefUnsafeMake(2048)); -var currentLogAnnotations = /* @__PURE__ */ globalValue(/* @__PURE__ */ Symbol.for("effect/FiberRef/currentLogAnnotation"), () => fiberRefUnsafeMake(empty8())); -var currentLogLevel = /* @__PURE__ */ globalValue(/* @__PURE__ */ Symbol.for("effect/FiberRef/currentLogLevel"), () => fiberRefUnsafeMake(logLevelInfo)); -var currentLogSpan = /* @__PURE__ */ globalValue(/* @__PURE__ */ Symbol.for("effect/FiberRef/currentLogSpan"), () => fiberRefUnsafeMake(empty9())); -var withSchedulingPriority = /* @__PURE__ */ dual(2, (self, scheduler) => fiberRefLocally(self, currentSchedulingPriority, scheduler)); -var withMaxOpsBeforeYield = /* @__PURE__ */ dual(2, (self, scheduler) => fiberRefLocally(self, currentMaxOpsBeforeYield, scheduler)); -var currentConcurrency = /* @__PURE__ */ globalValue(/* @__PURE__ */ Symbol.for("effect/FiberRef/currentConcurrency"), () => fiberRefUnsafeMake("unbounded")); -var currentRequestBatching = /* @__PURE__ */ globalValue(/* @__PURE__ */ Symbol.for("effect/FiberRef/currentRequestBatching"), () => fiberRefUnsafeMake(true)); -var currentUnhandledErrorLogLevel = /* @__PURE__ */ globalValue(/* @__PURE__ */ Symbol.for("effect/FiberRef/currentUnhandledErrorLogLevel"), () => fiberRefUnsafeMake(some2(logLevelDebug))); -var currentVersionMismatchErrorLogLevel = /* @__PURE__ */ globalValue(/* @__PURE__ */ Symbol.for("effect/FiberRef/versionMismatchErrorLogLevel"), () => fiberRefUnsafeMake(some2(logLevelWarning))); -var withUnhandledErrorLogLevel = /* @__PURE__ */ dual(2, (self, level) => fiberRefLocally(self, currentUnhandledErrorLogLevel, level)); -var currentMetricLabels = /* @__PURE__ */ globalValue(/* @__PURE__ */ Symbol.for("effect/FiberRef/currentMetricLabels"), () => fiberRefUnsafeMakeReadonlyArray(empty())); -var metricLabels = /* @__PURE__ */ fiberRefGet(currentMetricLabels); -var currentForkScopeOverride = /* @__PURE__ */ globalValue(/* @__PURE__ */ Symbol.for("effect/FiberRef/currentForkScopeOverride"), () => fiberRefUnsafeMake(none2(), { - fork: () => none2(), - join: (parent, _) => parent -})); -var currentInterruptedCause = /* @__PURE__ */ globalValue(/* @__PURE__ */ Symbol.for("effect/FiberRef/currentInterruptedCause"), () => fiberRefUnsafeMake(empty16, { - fork: () => empty16, - join: (parent, _) => parent -})); -var currentTracerEnabled = /* @__PURE__ */ globalValue(/* @__PURE__ */ Symbol.for("effect/FiberRef/currentTracerEnabled"), () => fiberRefUnsafeMake(true)); -var currentTracerTimingEnabled = /* @__PURE__ */ globalValue(/* @__PURE__ */ Symbol.for("effect/FiberRef/currentTracerTiming"), () => fiberRefUnsafeMake(true)); -var currentTracerSpanAnnotations = /* @__PURE__ */ globalValue(/* @__PURE__ */ Symbol.for("effect/FiberRef/currentTracerSpanAnnotations"), () => fiberRefUnsafeMake(empty8())); -var currentTracerSpanLinks = /* @__PURE__ */ globalValue(/* @__PURE__ */ Symbol.for("effect/FiberRef/currentTracerSpanLinks"), () => fiberRefUnsafeMake(empty4())); -var ScopeTypeId = /* @__PURE__ */ Symbol.for("effect/Scope"); -var CloseableScopeTypeId = /* @__PURE__ */ Symbol.for("effect/CloseableScope"); -var scopeAddFinalizer = (self, finalizer) => self.addFinalizer(() => asVoid(finalizer)); -var scopeAddFinalizerExit = (self, finalizer) => self.addFinalizer(finalizer); -var scopeClose = (self, exit2) => self.close(exit2); -var scopeFork = (self, strategy) => self.fork(strategy); -var YieldableError = /* @__PURE__ */ function() { - class YieldableError2 extends globalThis.Error { - commit() { - return fail2(this); - } - toJSON() { - const obj = { - ...this - }; - if (this.message) - obj.message = this.message; - if (this.cause) - obj.cause = this.cause; - return obj; - } - [NodeInspectSymbol]() { - if (this.toString !== globalThis.Error.prototype.toString) { - return this.stack ? `${this.toString()} -${this.stack.split(` -`).slice(1).join(` -`)}` : this.toString(); - } else if ("Bun" in globalThis) { - return pretty(fail(this), { - renderErrorCause: true - }); - } - return this; - } - } - Object.assign(YieldableError2.prototype, StructuralCommitPrototype); - return YieldableError2; -}(); -var makeException = (proto2, tag) => { - - class Base2 extends YieldableError { - _tag = tag; - } - Object.assign(Base2.prototype, proto2); - Base2.prototype.name = tag; - return Base2; -}; -var RuntimeExceptionTypeId = /* @__PURE__ */ Symbol.for("effect/Cause/errors/RuntimeException"); -var RuntimeException = /* @__PURE__ */ makeException({ - [RuntimeExceptionTypeId]: RuntimeExceptionTypeId -}, "RuntimeException"); -var InterruptedExceptionTypeId = /* @__PURE__ */ Symbol.for("effect/Cause/errors/InterruptedException"); -var InterruptedException = /* @__PURE__ */ makeException({ - [InterruptedExceptionTypeId]: InterruptedExceptionTypeId -}, "InterruptedException"); -var isInterruptedException = (u) => hasProperty(u, InterruptedExceptionTypeId); -var IllegalArgumentExceptionTypeId = /* @__PURE__ */ Symbol.for("effect/Cause/errors/IllegalArgument"); -var IllegalArgumentException = /* @__PURE__ */ makeException({ - [IllegalArgumentExceptionTypeId]: IllegalArgumentExceptionTypeId -}, "IllegalArgumentException"); -var NoSuchElementExceptionTypeId = /* @__PURE__ */ Symbol.for("effect/Cause/errors/NoSuchElement"); -var NoSuchElementException = /* @__PURE__ */ makeException({ - [NoSuchElementExceptionTypeId]: NoSuchElementExceptionTypeId -}, "NoSuchElementException"); -var isNoSuchElementException = (u) => hasProperty(u, NoSuchElementExceptionTypeId); -var InvalidPubSubCapacityExceptionTypeId = /* @__PURE__ */ Symbol.for("effect/Cause/errors/InvalidPubSubCapacityException"); -var InvalidPubSubCapacityException = /* @__PURE__ */ makeException({ - [InvalidPubSubCapacityExceptionTypeId]: InvalidPubSubCapacityExceptionTypeId -}, "InvalidPubSubCapacityException"); -var ExceededCapacityExceptionTypeId = /* @__PURE__ */ Symbol.for("effect/Cause/errors/ExceededCapacityException"); -var ExceededCapacityException = /* @__PURE__ */ makeException({ - [ExceededCapacityExceptionTypeId]: ExceededCapacityExceptionTypeId -}, "ExceededCapacityException"); -var TimeoutExceptionTypeId = /* @__PURE__ */ Symbol.for("effect/Cause/errors/Timeout"); -var TimeoutException = /* @__PURE__ */ makeException({ - [TimeoutExceptionTypeId]: TimeoutExceptionTypeId -}, "TimeoutException"); -var timeoutExceptionFromDuration = (duration) => new TimeoutException(`Operation timed out after '${format3(duration)}'`); -var UnknownExceptionTypeId = /* @__PURE__ */ Symbol.for("effect/Cause/errors/UnknownException"); -var UnknownException = /* @__PURE__ */ function() { - - class UnknownException2 extends YieldableError { - _tag = "UnknownException"; - error; - constructor(cause, message) { - super(message ?? "An unknown error occurred", { - cause - }); - this.error = cause; - } - } - Object.assign(UnknownException2.prototype, { - [UnknownExceptionTypeId]: UnknownExceptionTypeId, - name: "UnknownException" - }); - return UnknownException2; -}(); -var exitIsExit = (u) => isEffect(u) && ("_tag" in u) && (u._tag === "Success" || u._tag === "Failure"); -var exitIsFailure = (self) => self._tag === "Failure"; -var exitIsSuccess = (self) => self._tag === "Success"; -var exitAs = /* @__PURE__ */ dual(2, (self, value) => { - switch (self._tag) { - case OP_FAILURE: { - return exitFailCause(self.effect_instruction_i0); - } - case OP_SUCCESS: { - return exitSucceed(value); - } - } -}); -var exitAsVoid = (self) => exitAs(self, undefined); -var exitCollectAll = (exits, options) => exitCollectAllInternal(exits, options?.parallel ? parallel : sequential); -var exitDie = (defect) => exitFailCause(die(defect)); -var exitFail = (error) => exitFailCause(fail(error)); -var exitFailCause = (cause) => { - const effect = new EffectPrimitiveFailure(OP_FAILURE); - effect.effect_instruction_i0 = cause; - return effect; -}; -var exitFlatMap = /* @__PURE__ */ dual(2, (self, f) => { - switch (self._tag) { - case OP_FAILURE: { - return exitFailCause(self.effect_instruction_i0); - } - case OP_SUCCESS: { - return f(self.effect_instruction_i0); - } - } -}); -var exitFlatten = (self) => pipe(self, exitFlatMap(identity)); -var exitInterrupt = (fiberId2) => exitFailCause(interrupt(fiberId2)); -var exitMap = /* @__PURE__ */ dual(2, (self, f) => { - switch (self._tag) { - case OP_FAILURE: - return exitFailCause(self.effect_instruction_i0); - case OP_SUCCESS: - return exitSucceed(f(self.effect_instruction_i0)); - } -}); -var exitMatch = /* @__PURE__ */ dual(2, (self, { - onFailure, - onSuccess -}) => { - switch (self._tag) { - case OP_FAILURE: - return onFailure(self.effect_instruction_i0); - case OP_SUCCESS: - return onSuccess(self.effect_instruction_i0); - } -}); -var exitMatchEffect = /* @__PURE__ */ dual(2, (self, { - onFailure, - onSuccess -}) => { - switch (self._tag) { - case OP_FAILURE: - return onFailure(self.effect_instruction_i0); - case OP_SUCCESS: - return onSuccess(self.effect_instruction_i0); - } -}); -var exitSucceed = (value) => { - const effect = new EffectPrimitiveSuccess(OP_SUCCESS); - effect.effect_instruction_i0 = value; - return effect; -}; -var exitVoid = /* @__PURE__ */ exitSucceed(undefined); -var exitZipWith = /* @__PURE__ */ dual(3, (self, that, { - onFailure, - onSuccess -}) => { - switch (self._tag) { - case OP_FAILURE: { - switch (that._tag) { - case OP_SUCCESS: - return exitFailCause(self.effect_instruction_i0); - case OP_FAILURE: { - return exitFailCause(onFailure(self.effect_instruction_i0, that.effect_instruction_i0)); - } - } - } - case OP_SUCCESS: { - switch (that._tag) { - case OP_SUCCESS: - return exitSucceed(onSuccess(self.effect_instruction_i0, that.effect_instruction_i0)); - case OP_FAILURE: - return exitFailCause(that.effect_instruction_i0); - } - } - } -}); -var exitCollectAllInternal = (exits, combineCauses) => { - const list = fromIterable2(exits); - if (!isNonEmpty2(list)) { - return none2(); - } - return pipe(tailNonEmpty2(list), reduce(pipe(headNonEmpty2(list), exitMap(of2)), (accumulator, current) => pipe(accumulator, exitZipWith(current, { - onSuccess: (list2, value) => pipe(list2, prepend2(value)), - onFailure: combineCauses - }))), exitMap(reverse2), exitMap((chunk) => toReadonlyArray(chunk)), some2); -}; -var deferredUnsafeMake = (fiberId2) => { - const _deferred = { - ...CommitPrototype, - [DeferredTypeId]: deferredVariance, - state: make12(pending([])), - commit() { - return deferredAwait(this); - }, - blockingOn: fiberId2 - }; - return _deferred; -}; -var deferredMake = () => flatMap7(fiberId, (id) => deferredMakeAs(id)); -var deferredMakeAs = (fiberId2) => sync(() => deferredUnsafeMake(fiberId2)); -var deferredAwait = (self) => asyncInterrupt((resume) => { - const state = get6(self.state); - switch (state._tag) { - case OP_STATE_DONE: { - return resume(state.effect); - } - case OP_STATE_PENDING: { - state.joiners.push(resume); - return deferredInterruptJoiner(self, resume); - } - } -}, self.blockingOn); -var deferredComplete = /* @__PURE__ */ dual(2, (self, effect) => intoDeferred(effect, self)); -var deferredCompleteWith = /* @__PURE__ */ dual(2, (self, effect) => sync(() => { - const state = get6(self.state); - switch (state._tag) { - case OP_STATE_DONE: { - return false; - } - case OP_STATE_PENDING: { - set2(self.state, done(effect)); - for (let i = 0, len = state.joiners.length;i < len; i++) { - state.joiners[i](effect); - } - return true; - } - } -})); -var deferredDone = /* @__PURE__ */ dual(2, (self, exit2) => deferredCompleteWith(self, exit2)); -var deferredFailCause = /* @__PURE__ */ dual(2, (self, cause) => deferredCompleteWith(self, failCause(cause))); -var deferredInterrupt = (self) => flatMap7(fiberId, (fiberId2) => deferredCompleteWith(self, interruptWith(fiberId2))); -var deferredSucceed = /* @__PURE__ */ dual(2, (self, value) => deferredCompleteWith(self, succeed(value))); -var deferredUnsafeDone = (self, effect) => { - const state = get6(self.state); - if (state._tag === OP_STATE_PENDING) { - set2(self.state, done(effect)); - for (let i = 0, len = state.joiners.length;i < len; i++) { - state.joiners[i](effect); - } - } -}; -var deferredInterruptJoiner = (self, joiner) => sync(() => { - const state = get6(self.state); - if (state._tag === OP_STATE_PENDING) { - const index = state.joiners.indexOf(joiner); - if (index >= 0) { - state.joiners.splice(index, 1); - } - } -}); -var constContext = /* @__PURE__ */ withFiberRuntime((fiber) => exitSucceed(fiber.currentContext)); -var context = () => constContext; -var contextWithEffect = (f) => flatMap7(context(), f); -var provideContext = /* @__PURE__ */ dual(2, (self, context2) => fiberRefLocally(currentContext, context2)(self)); -var provideSomeContext = /* @__PURE__ */ dual(2, (self, context2) => fiberRefLocallyWith(currentContext, (parent) => merge3(parent, context2))(self)); -var mapInputContext = /* @__PURE__ */ dual(2, (self, f) => contextWithEffect((context2) => provideContext(self, f(context2)))); -var filterEffectOrElse = /* @__PURE__ */ dual(2, (self, options) => flatMap7(self, (a) => flatMap7(options.predicate(a), (pass) => pass ? succeed(a) : options.orElse(a)))); -var filterEffectOrFail = /* @__PURE__ */ dual(2, (self, options) => filterEffectOrElse(self, { - predicate: options.predicate, - orElse: (a) => fail2(options.orFailWith(a)) -})); -var currentSpanFromFiber = (fiber) => { - const span2 = fiber.currentSpan; - return span2 !== undefined && span2._tag === "Span" ? some2(span2) : none2(); -}; -var NoopSpanProto = { - _tag: "Span", - spanId: "noop", - traceId: "noop", - sampled: false, - status: { - _tag: "Ended", - startTime: /* @__PURE__ */ BigInt(0), - endTime: /* @__PURE__ */ BigInt(0), - exit: exitVoid - }, - attributes: /* @__PURE__ */ new Map, - links: [], - kind: "internal", - attribute() {}, - event() {}, - end() {}, - addLinks() {} -}; -var noopSpan = (options) => Object.assign(Object.create(NoopSpanProto), options); - -// node_modules/effect/dist/esm/Deferred.js -var _await = deferredAwait; -var done2 = deferredDone; -var interrupt3 = deferredInterrupt; -var unsafeMake3 = deferredUnsafeMake; - -// node_modules/effect/dist/esm/Exit.js -var isExit = exitIsExit; -var isSuccess = exitIsSuccess; -var failCause2 = exitFailCause; -var flatten6 = exitFlatten; -var match6 = exitMatch; -var succeed2 = exitSucceed; - -// node_modules/effect/dist/esm/MutableHashMap.js -var TypeId9 = /* @__PURE__ */ Symbol.for("effect/MutableHashMap"); -var MutableHashMapProto = { - [TypeId9]: TypeId9, - [Symbol.iterator]() { - return new MutableHashMapIterator(this); - }, - toString() { - return format(this.toJSON()); - }, - toJSON() { - return { - _id: "MutableHashMap", - values: Array.from(this).map(toJSON) - }; - }, - [NodeInspectSymbol]() { - return this.toJSON(); - }, - pipe() { - return pipeArguments(this, arguments); - } -}; - -class MutableHashMapIterator { - self; - referentialIterator; - bucketIterator; - constructor(self) { - this.self = self; - this.referentialIterator = self.referential[Symbol.iterator](); - } - next() { - if (this.bucketIterator !== undefined) { - return this.bucketIterator.next(); - } - const result = this.referentialIterator.next(); - if (result.done) { - this.bucketIterator = new BucketIterator(this.self.buckets.values()); - return this.next(); - } - return result; - } - [Symbol.iterator]() { - return new MutableHashMapIterator(this.self); - } -} - -class BucketIterator { - backing; - constructor(backing) { - this.backing = backing; - } - currentBucket; - next() { - if (this.currentBucket === undefined) { - const result2 = this.backing.next(); - if (result2.done) { - return result2; - } - this.currentBucket = result2.value[Symbol.iterator](); - } - const result = this.currentBucket.next(); - if (result.done) { - this.currentBucket = undefined; - return this.next(); - } - return result; - } -} -var empty17 = () => { - const self = Object.create(MutableHashMapProto); - self.referential = new Map; - self.buckets = new Map; - self.bucketsSize = 0; - return self; -}; -var get8 = /* @__PURE__ */ dual(2, (self, key) => { - if (isEqual(key) === false) { - return self.referential.has(key) ? some2(self.referential.get(key)) : none2(); - } - const hash2 = key[symbol](); - const bucket = self.buckets.get(hash2); - if (bucket === undefined) { - return none2(); - } - return getFromBucket(self, bucket, key); -}); -var getFromBucket = (self, bucket, key, remove5 = false) => { - for (let i = 0, len = bucket.length;i < len; i++) { - if (key[symbol2](bucket[i][0])) { - const value = bucket[i][1]; - if (remove5) { - bucket.splice(i, 1); - self.bucketsSize--; - } - return some2(value); - } - } - return none2(); -}; -var has4 = /* @__PURE__ */ dual(2, (self, key) => isSome2(get8(self, key))); -var set4 = /* @__PURE__ */ dual(3, (self, key, value) => { - if (isEqual(key) === false) { - self.referential.set(key, value); - return self; - } - const hash2 = key[symbol](); - const bucket = self.buckets.get(hash2); - if (bucket === undefined) { - self.buckets.set(hash2, [[key, value]]); - self.bucketsSize++; - return self; - } - removeFromBucket(self, bucket, key); - bucket.push([key, value]); - self.bucketsSize++; - return self; -}); -var removeFromBucket = (self, bucket, key) => { - for (let i = 0, len = bucket.length;i < len; i++) { - if (key[symbol2](bucket[i][0])) { - bucket.splice(i, 1); - self.bucketsSize--; - return; - } - } -}; -var remove5 = /* @__PURE__ */ dual(2, (self, key) => { - if (isEqual(key) === false) { - self.referential.delete(key); - return self; - } - const hash2 = key[symbol](); - const bucket = self.buckets.get(hash2); - if (bucket === undefined) { - return self; - } - removeFromBucket(self, bucket, key); - if (bucket.length === 0) { - self.buckets.delete(hash2); - } - return self; -}); -var size4 = (self) => { - return self.referential.size + self.bucketsSize; -}; - -// node_modules/effect/dist/esm/MutableList.js -var TypeId10 = /* @__PURE__ */ Symbol.for("effect/MutableList"); -var MutableListProto = { - [TypeId10]: TypeId10, - [Symbol.iterator]() { - let done3 = false; - let head3 = this.head; - return { - next() { - if (done3) { - return this.return(); - } - if (head3 == null) { - done3 = true; - return this.return(); - } - const value = head3.value; - head3 = head3.next; - return { - done: done3, - value - }; - }, - return(value) { - if (!done3) { - done3 = true; - } - return { - done: true, - value - }; - } - }; - }, - toString() { - return format(this.toJSON()); - }, - toJSON() { - return { - _id: "MutableList", - values: Array.from(this).map(toJSON) - }; - }, - [NodeInspectSymbol]() { - return this.toJSON(); - }, - pipe() { - return pipeArguments(this, arguments); - } -}; -var makeNode = (value) => ({ - value, - removed: false, - prev: undefined, - next: undefined -}); -var empty18 = () => { - const list = Object.create(MutableListProto); - list.head = undefined; - list.tail = undefined; - list._length = 0; - return list; -}; -var isEmpty6 = (self) => length(self) === 0; -var length = (self) => self._length; -var append3 = /* @__PURE__ */ dual(2, (self, value) => { - const node = makeNode(value); - if (self.head === undefined) { - self.head = node; - } - if (self.tail === undefined) { - self.tail = node; - } else { - self.tail.next = node; - node.prev = self.tail; - self.tail = node; - } - self._length += 1; - return self; -}); -var shift = (self) => { - const head3 = self.head; - if (head3 !== undefined) { - remove6(self, head3); - return head3.value; - } - return; -}; -var remove6 = (self, node) => { - if (node.removed) { - return; - } - node.removed = true; - if (node.prev !== undefined && node.next !== undefined) { - node.prev.next = node.next; - node.next.prev = node.prev; - } else if (node.prev !== undefined) { - self.tail = node.prev; - node.prev.next = undefined; - } else if (node.next !== undefined) { - self.head = node.next; - node.next.prev = undefined; - } else { - self.tail = undefined; - self.head = undefined; - } - if (self._length > 0) { - self._length -= 1; - } -}; - -// node_modules/effect/dist/esm/MutableQueue.js -var TypeId11 = /* @__PURE__ */ Symbol.for("effect/MutableQueue"); -var EmptyMutableQueue = /* @__PURE__ */ Symbol.for("effect/mutable/MutableQueue/Empty"); -var MutableQueueProto = { - [TypeId11]: TypeId11, - [Symbol.iterator]() { - return Array.from(this.queue)[Symbol.iterator](); - }, - toString() { - return format(this.toJSON()); - }, - toJSON() { - return { - _id: "MutableQueue", - values: Array.from(this).map(toJSON) - }; - }, - [NodeInspectSymbol]() { - return this.toJSON(); - }, - pipe() { - return pipeArguments(this, arguments); - } -}; -var make19 = (capacity) => { - const queue = Object.create(MutableQueueProto); - queue.queue = empty18(); - queue.capacity = capacity; - return queue; -}; -var unbounded = () => make19(undefined); -var offer = /* @__PURE__ */ dual(2, (self, value) => { - const queueLength = length(self.queue); - if (self.capacity !== undefined && queueLength === self.capacity) { - return false; - } - append3(value)(self.queue); - return true; -}); -var poll = /* @__PURE__ */ dual(2, (self, def) => { - if (isEmpty6(self.queue)) { - return def; - } - return shift(self.queue); -}); - -// node_modules/effect/dist/esm/internal/clock.js -var ClockSymbolKey = "effect/Clock"; -var ClockTypeId = /* @__PURE__ */ Symbol.for(ClockSymbolKey); -var clockTag = /* @__PURE__ */ GenericTag("effect/Clock"); -var MAX_TIMER_MILLIS = 2 ** 31 - 1; -var globalClockScheduler = { - unsafeSchedule(task, duration) { - const millis2 = toMillis(duration); - if (millis2 > MAX_TIMER_MILLIS) { - return constFalse; - } - let completed = false; - const handle = setTimeout(() => { - completed = true; - task(); - }, millis2); - return () => { - clearTimeout(handle); - return !completed; - }; - } -}; -var performanceNowNanos = /* @__PURE__ */ function() { - const bigint1e62 = /* @__PURE__ */ BigInt(1e6); - if (typeof performance === "undefined" || typeof performance.now !== "function") { - return () => BigInt(Date.now()) * bigint1e62; - } - let origin; - return () => { - if (origin === undefined) { - origin = BigInt(Date.now()) * bigint1e62 - BigInt(Math.round(performance.now() * 1e6)); - } - return origin + BigInt(Math.round(performance.now() * 1e6)); - }; -}(); -var processOrPerformanceNow = /* @__PURE__ */ function() { - const processHrtime = typeof process === "object" && "hrtime" in process && typeof process.hrtime.bigint === "function" ? process.hrtime : undefined; - if (!processHrtime) { - return performanceNowNanos; - } - const origin = /* @__PURE__ */ performanceNowNanos() - /* @__PURE__ */ processHrtime.bigint(); - return () => origin + processHrtime.bigint(); -}(); - -class ClockImpl { - [ClockTypeId] = ClockTypeId; - unsafeCurrentTimeMillis() { - return Date.now(); - } - unsafeCurrentTimeNanos() { - return processOrPerformanceNow(); - } - currentTimeMillis = /* @__PURE__ */ sync(() => this.unsafeCurrentTimeMillis()); - currentTimeNanos = /* @__PURE__ */ sync(() => this.unsafeCurrentTimeNanos()); - scheduler() { - return succeed(globalClockScheduler); - } - sleep(duration) { - return async_((resume) => { - const canceler = globalClockScheduler.unsafeSchedule(() => resume(void_), duration); - return asVoid(sync(canceler)); - }); - } -} -var make20 = () => new ClockImpl; - -// node_modules/effect/dist/esm/internal/opCodes/configError.js -var OP_AND = "And"; -var OP_OR = "Or"; -var OP_INVALID_DATA = "InvalidData"; -var OP_MISSING_DATA = "MissingData"; -var OP_SOURCE_UNAVAILABLE = "SourceUnavailable"; -var OP_UNSUPPORTED = "Unsupported"; - -// node_modules/effect/dist/esm/internal/configError.js -var ConfigErrorSymbolKey = "effect/ConfigError"; -var ConfigErrorTypeId = /* @__PURE__ */ Symbol.for(ConfigErrorSymbolKey); -var proto2 = { - _tag: "ConfigError", - [ConfigErrorTypeId]: ConfigErrorTypeId -}; -var And = (self, that) => { - const error = Object.create(proto2); - error._op = OP_AND; - error.left = self; - error.right = that; - Object.defineProperty(error, "toString", { - enumerable: false, - value() { - return `${this.left} and ${this.right}`; - } - }); - Object.defineProperty(error, "message", { - enumerable: false, - get() { - return this.toString(); - } - }); - return error; -}; -var Or = (self, that) => { - const error = Object.create(proto2); - error._op = OP_OR; - error.left = self; - error.right = that; - Object.defineProperty(error, "toString", { - enumerable: false, - value() { - return `${this.left} or ${this.right}`; - } - }); - Object.defineProperty(error, "message", { - enumerable: false, - get() { - return this.toString(); - } - }); - return error; -}; -var InvalidData = (path, message, options = { - pathDelim: "." -}) => { - const error = Object.create(proto2); - error._op = OP_INVALID_DATA; - error.path = path; - error.message = message; - Object.defineProperty(error, "toString", { - enumerable: false, - value() { - const path2 = pipe(this.path, join(options.pathDelim)); - return `(Invalid data at ${path2}: "${this.message}")`; - } - }); - return error; -}; -var MissingData = (path, message, options = { - pathDelim: "." -}) => { - const error = Object.create(proto2); - error._op = OP_MISSING_DATA; - error.path = path; - error.message = message; - Object.defineProperty(error, "toString", { - enumerable: false, - value() { - const path2 = pipe(this.path, join(options.pathDelim)); - return `(Missing data at ${path2}: "${this.message}")`; - } - }); - return error; -}; -var SourceUnavailable = (path, message, cause, options = { - pathDelim: "." -}) => { - const error = Object.create(proto2); - error._op = OP_SOURCE_UNAVAILABLE; - error.path = path; - error.message = message; - error.cause = cause; - Object.defineProperty(error, "toString", { - enumerable: false, - value() { - const path2 = pipe(this.path, join(options.pathDelim)); - return `(Source unavailable at ${path2}: "${this.message}")`; - } - }); - return error; -}; -var Unsupported = (path, message, options = { - pathDelim: "." -}) => { - const error = Object.create(proto2); - error._op = OP_UNSUPPORTED; - error.path = path; - error.message = message; - Object.defineProperty(error, "toString", { - enumerable: false, - value() { - const path2 = pipe(this.path, join(options.pathDelim)); - return `(Unsupported operation at ${path2}: "${this.message}")`; - } - }); - return error; -}; -var prefixed = /* @__PURE__ */ dual(2, (self, prefix) => { - switch (self._op) { - case OP_AND: { - return And(prefixed(self.left, prefix), prefixed(self.right, prefix)); - } - case OP_OR: { - return Or(prefixed(self.left, prefix), prefixed(self.right, prefix)); - } - case OP_INVALID_DATA: { - return InvalidData([...prefix, ...self.path], self.message); - } - case OP_MISSING_DATA: { - return MissingData([...prefix, ...self.path], self.message); - } - case OP_SOURCE_UNAVAILABLE: { - return SourceUnavailable([...prefix, ...self.path], self.message, self.cause); - } - case OP_UNSUPPORTED: { - return Unsupported([...prefix, ...self.path], self.message); - } - } -}); - -// node_modules/effect/dist/esm/internal/configProvider/pathPatch.js -var empty19 = { - _tag: "Empty" -}; -var patch5 = /* @__PURE__ */ dual(2, (path, patch6) => { - let input = of3(patch6); - let output = path; - while (isCons(input)) { - const patch7 = input.head; - switch (patch7._tag) { - case "Empty": { - input = input.tail; - break; - } - case "AndThen": { - input = cons(patch7.first, cons(patch7.second, input.tail)); - break; - } - case "MapName": { - output = map3(output, patch7.f); - input = input.tail; - break; - } - case "Nested": { - output = prepend(output, patch7.name); - input = input.tail; - break; - } - case "Unnested": { - const containsName = pipe(head(output), contains(patch7.name)); - if (containsName) { - output = tailNonEmpty(output); - input = input.tail; - } else { - return left2(MissingData(output, `Expected ${patch7.name} to be in path in ConfigProvider#unnested`)); - } - break; - } - } - } - return right2(output); -}); - -// node_modules/effect/dist/esm/internal/opCodes/config.js -var OP_CONSTANT = "Constant"; -var OP_FAIL2 = "Fail"; -var OP_FALLBACK = "Fallback"; -var OP_DESCRIBED = "Described"; -var OP_LAZY = "Lazy"; -var OP_MAP_OR_FAIL = "MapOrFail"; -var OP_NESTED = "Nested"; -var OP_PRIMITIVE = "Primitive"; -var OP_SEQUENCE = "Sequence"; -var OP_HASHMAP = "HashMap"; -var OP_ZIP_WITH = "ZipWith"; - -// node_modules/effect/dist/esm/internal/configProvider.js -var concat = (l, r) => [...l, ...r]; -var ConfigProviderSymbolKey = "effect/ConfigProvider"; -var ConfigProviderTypeId = /* @__PURE__ */ Symbol.for(ConfigProviderSymbolKey); -var configProviderTag = /* @__PURE__ */ GenericTag("effect/ConfigProvider"); -var FlatConfigProviderSymbolKey = "effect/ConfigProviderFlat"; -var FlatConfigProviderTypeId = /* @__PURE__ */ Symbol.for(FlatConfigProviderSymbolKey); -var make22 = (options) => ({ - [ConfigProviderTypeId]: ConfigProviderTypeId, - pipe() { - return pipeArguments(this, arguments); - }, - ...options -}); -var makeFlat = (options) => ({ - [FlatConfigProviderTypeId]: FlatConfigProviderTypeId, - patch: options.patch, - load: (path, config, split = true) => options.load(path, config, split), - enumerateChildren: options.enumerateChildren -}); -var fromFlat = (flat) => make22({ - load: (config) => flatMap7(fromFlatLoop(flat, empty(), config, false), (chunk) => match2(head(chunk), { - onNone: () => fail2(MissingData(empty(), `Expected a single value having structure: ${config}`)), - onSome: succeed - })), - flattened: flat -}); -var fromEnv = (options) => { - const { - pathDelim, - seqDelim - } = Object.assign({}, { - pathDelim: "_", - seqDelim: "," - }, options); - const makePathString = (path) => pipe(path, join(pathDelim)); - const unmakePathString = (pathString) => pathString.split(pathDelim); - const getEnv = () => typeof process !== "undefined" && ("env" in process) && typeof process.env === "object" ? process.env : {}; - const load = (path, primitive, split = true) => { - const pathString = makePathString(path); - const current = getEnv(); - const valueOpt = pathString in current ? some2(current[pathString]) : none2(); - return pipe(valueOpt, mapError(() => MissingData(path, `Expected ${pathString} to exist in the process context`)), flatMap7((value) => parsePrimitive(value, path, primitive, seqDelim, split))); - }; - const enumerateChildren = (path) => sync(() => { - const current = getEnv(); - const keys3 = Object.keys(current); - const keyPaths = keys3.map((value) => unmakePathString(value.toUpperCase())); - const filteredKeyPaths = keyPaths.filter((keyPath) => { - for (let i = 0;i < path.length; i++) { - const pathComponent = pipe(path, unsafeGet(i)); - const currentElement = keyPath[i]; - if (currentElement === undefined || pathComponent !== currentElement) { - return false; - } - } - return true; - }).flatMap((keyPath) => keyPath.slice(path.length, path.length + 1)); - return fromIterable5(filteredKeyPaths); - }); - return fromFlat(makeFlat({ - load, - enumerateChildren, - patch: empty19 - })); -}; -var extend = (leftDef, rightDef, left3, right3) => { - const leftPad = unfold(left3.length, (index) => index >= right3.length ? none2() : some2([leftDef(index), index + 1])); - const rightPad = unfold(right3.length, (index) => index >= left3.length ? none2() : some2([rightDef(index), index + 1])); - const leftExtension = concat(left3, leftPad); - const rightExtension = concat(right3, rightPad); - return [leftExtension, rightExtension]; -}; -var appendConfigPath = (path, config) => { - let op = config; - if (op._tag === "Nested") { - const out = path.slice(); - while (op._tag === "Nested") { - out.push(op.name); - op = op.config; - } - return out; - } - return path; -}; -var fromFlatLoop = (flat, prefix, config, split) => { - const op = config; - switch (op._tag) { - case OP_CONSTANT: { - return succeed(of(op.value)); - } - case OP_DESCRIBED: { - return suspend(() => fromFlatLoop(flat, prefix, op.config, split)); - } - case OP_FAIL2: { - return fail2(MissingData(prefix, op.message)); - } - case OP_FALLBACK: { - return pipe(suspend(() => fromFlatLoop(flat, prefix, op.first, split)), catchAll((error1) => { - if (op.condition(error1)) { - return pipe(fromFlatLoop(flat, prefix, op.second, split), catchAll((error2) => fail2(Or(error1, error2)))); - } - return fail2(error1); - })); - } - case OP_LAZY: { - return suspend(() => fromFlatLoop(flat, prefix, op.config(), split)); - } - case OP_MAP_OR_FAIL: { - return suspend(() => pipe(fromFlatLoop(flat, prefix, op.original, split), flatMap7(forEachSequential((a) => pipe(op.mapOrFail(a), mapError(prefixed(appendConfigPath(prefix, op.original)))))))); - } - case OP_NESTED: { - return suspend(() => fromFlatLoop(flat, concat(prefix, of(op.name)), op.config, split)); - } - case OP_PRIMITIVE: { - return pipe(patch5(prefix, flat.patch), flatMap7((prefix2) => pipe(flat.load(prefix2, op, split), flatMap7((values3) => { - if (values3.length === 0) { - const name = pipe(last(prefix2), getOrElse(() => "")); - return fail2(MissingData([], `Expected ${op.description} with name ${name}`)); - } - return succeed(values3); - })))); - } - case OP_SEQUENCE: { - return pipe(patch5(prefix, flat.patch), flatMap7((patchedPrefix) => pipe(flat.enumerateChildren(patchedPrefix), flatMap7(indicesFrom), flatMap7((indices) => { - if (indices.length === 0) { - return suspend(() => map9(fromFlatLoop(flat, prefix, op.config, true), of)); - } - return pipe(forEachSequential(indices, (index) => fromFlatLoop(flat, append(prefix, `[${index}]`), op.config, true)), map9((chunkChunk) => { - const flattened = flatten(chunkChunk); - if (flattened.length === 0) { - return of(empty()); - } - return of(flattened); - })); - })))); - } - case OP_HASHMAP: { - return suspend(() => pipe(patch5(prefix, flat.patch), flatMap7((prefix2) => pipe(flat.enumerateChildren(prefix2), flatMap7((keys3) => { - return pipe(keys3, forEachSequential((key) => fromFlatLoop(flat, concat(prefix2, of(key)), op.valueConfig, split)), map9((matrix) => { - if (matrix.length === 0) { - return of(empty8()); - } - return pipe(transpose(matrix), map3((values3) => fromIterable6(zip(fromIterable(keys3), values3)))); - })); - }))))); - } - case OP_ZIP_WITH: { - return suspend(() => pipe(fromFlatLoop(flat, prefix, op.left, split), either2, flatMap7((left3) => pipe(fromFlatLoop(flat, prefix, op.right, split), either2, flatMap7((right3) => { - if (isLeft2(left3) && isLeft2(right3)) { - return fail2(And(left3.left, right3.left)); - } - if (isLeft2(left3) && isRight2(right3)) { - return fail2(left3.left); - } - if (isRight2(left3) && isLeft2(right3)) { - return fail2(right3.left); - } - if (isRight2(left3) && isRight2(right3)) { - const path = pipe(prefix, join(".")); - const fail3 = fromFlatLoopFail(prefix, path); - const [lefts, rights] = extend(fail3, fail3, pipe(left3.right, map3(right2)), pipe(right3.right, map3(right2))); - return pipe(lefts, zip(rights), forEachSequential(([left4, right4]) => pipe(zip2(left4, right4), map9(([left5, right5]) => op.zip(left5, right5))))); - } - throw new Error("BUG: ConfigProvider.fromFlatLoop - please report an issue at https://github.com/Effect-TS/effect/issues"); - }))))); - } - } -}; -var fromFlatLoopFail = (prefix, path) => (index) => left2(MissingData(prefix, `The element at index ${index} in a sequence at path "${path}" was missing`)); -var splitPathString = (text, delim) => { - const split = text.split(new RegExp(`\\s*${escape(delim)}\\s*`)); - return split; -}; -var parsePrimitive = (text, path, primitive, delimiter, split) => { - if (!split) { - return pipe(primitive.parse(text), mapBoth2({ - onFailure: prefixed(path), - onSuccess: of - })); - } - return pipe(splitPathString(text, delimiter), forEachSequential((char) => primitive.parse(char.trim())), mapError(prefixed(path))); -}; -var transpose = (array4) => { - return Object.keys(array4[0]).map((column) => array4.map((row) => row[column])); -}; -var indicesFrom = (quotedIndices) => pipe(forEachSequential(quotedIndices, parseQuotedIndex), mapBoth2({ - onFailure: () => empty(), - onSuccess: sort(Order) -}), either2, map9(merge)); -var QUOTED_INDEX_REGEX = /^(\[(\d+)\])$/; -var parseQuotedIndex = (str) => { - const match7 = str.match(QUOTED_INDEX_REGEX); - if (match7 !== null) { - const matchedIndex = match7[2]; - return pipe(matchedIndex !== undefined && matchedIndex.length > 0 ? some2(matchedIndex) : none2(), flatMap(parseInteger)); - } - return none2(); -}; -var parseInteger = (str) => { - const parsedIndex = Number.parseInt(str); - return Number.isNaN(parsedIndex) ? none2() : some2(parsedIndex); -}; - -// node_modules/effect/dist/esm/internal/defaultServices/console.js -var TypeId12 = /* @__PURE__ */ Symbol.for("effect/Console"); -var consoleTag = /* @__PURE__ */ GenericTag("effect/Console"); -var defaultConsole = { - [TypeId12]: TypeId12, - assert(condition, ...args) { - return sync(() => { - console.assert(condition, ...args); - }); - }, - clear: /* @__PURE__ */ sync(() => { - console.clear(); - }), - count(label) { - return sync(() => { - console.count(label); - }); - }, - countReset(label) { - return sync(() => { - console.countReset(label); - }); - }, - debug(...args) { - return sync(() => { - console.debug(...args); - }); - }, - dir(item, options) { - return sync(() => { - console.dir(item, options); - }); - }, - dirxml(...args) { - return sync(() => { - console.dirxml(...args); - }); - }, - error(...args) { - return sync(() => { - console.error(...args); - }); - }, - group(options) { - return options?.collapsed ? sync(() => console.groupCollapsed(options?.label)) : sync(() => console.group(options?.label)); - }, - groupEnd: /* @__PURE__ */ sync(() => { - console.groupEnd(); - }), - info(...args) { - return sync(() => { - console.info(...args); - }); - }, - log(...args) { - return sync(() => { - console.log(...args); - }); - }, - table(tabularData, properties) { - return sync(() => { - console.table(tabularData, properties); - }); - }, - time(label) { - return sync(() => console.time(label)); - }, - timeEnd(label) { - return sync(() => console.timeEnd(label)); - }, - timeLog(label, ...args) { - return sync(() => { - console.timeLog(label, ...args); - }); - }, - trace(...args) { - return sync(() => { - console.trace(...args); - }); - }, - warn(...args) { - return sync(() => { - console.warn(...args); - }); - }, - unsafe: console -}; - -// node_modules/effect/dist/esm/internal/random.js -var RandomSymbolKey = "effect/Random"; -var RandomTypeId = /* @__PURE__ */ Symbol.for(RandomSymbolKey); -var randomTag = /* @__PURE__ */ GenericTag("effect/Random"); - -class RandomImpl { - seed; - [RandomTypeId] = RandomTypeId; - PRNG; - constructor(seed) { - this.seed = seed; - this.PRNG = new PCGRandom(seed); - } - get next() { - return sync(() => this.PRNG.number()); - } - get nextBoolean() { - return map9(this.next, (n) => n > 0.5); - } - get nextInt() { - return sync(() => this.PRNG.integer(Number.MAX_SAFE_INTEGER)); - } - nextRange(min2, max2) { - return map9(this.next, (n) => (max2 - min2) * n + min2); - } - nextIntBetween(min2, max2) { - return sync(() => this.PRNG.integer(max2 - min2) + min2); - } - shuffle(elements) { - return shuffleWith(elements, (n) => this.nextIntBetween(0, n)); - } -} -var shuffleWith = (elements, nextIntBounded) => { - return suspend(() => pipe(sync(() => Array.from(elements)), flatMap7((buffer) => { - const numbers = []; - for (let i = buffer.length;i >= 2; i = i - 1) { - numbers.push(i); - } - return pipe(numbers, forEachSequentialDiscard((n) => pipe(nextIntBounded(n), map9((k) => swap(buffer, n - 1, k)))), as(fromIterable2(buffer))); - }))); -}; -var swap = (buffer, index1, index2) => { - const tmp = buffer[index1]; - buffer[index1] = buffer[index2]; - buffer[index2] = tmp; - return buffer; -}; -var make23 = (seed) => new RandomImpl(hash(seed)); - -class FixedRandomImpl { - values; - [RandomTypeId] = RandomTypeId; - index = 0; - constructor(values3) { - this.values = values3; - if (values3.length === 0) { - throw new Error("Requires at least one value"); - } - } - getNextValue() { - const value = this.values[this.index]; - this.index = (this.index + 1) % this.values.length; - return value; - } - get next() { - return sync(() => { - const value = this.getNextValue(); - if (typeof value === "number") { - return Math.max(0, Math.min(1, value)); - } - return hash(value) / 2147483647; - }); - } - get nextBoolean() { - return sync(() => { - const value = this.getNextValue(); - if (typeof value === "boolean") { - return value; - } - return hash(value) % 2 === 0; - }); - } - get nextInt() { - return sync(() => { - const value = this.getNextValue(); - if (typeof value === "number" && Number.isFinite(value)) { - return Math.round(value); - } - return Math.abs(hash(value)); - }); - } - nextRange(min2, max2) { - return map9(this.next, (n) => (max2 - min2) * n + min2); - } - nextIntBetween(min2, max2) { - return sync(() => { - const value = this.getNextValue(); - if (typeof value === "number" && Number.isFinite(value)) { - return Math.max(min2, Math.min(max2 - 1, Math.round(value))); - } - const hash2 = Math.abs(hash(value)); - return min2 + hash2 % (max2 - min2); - }); - } - shuffle(elements) { - return shuffleWith(elements, (n) => this.nextIntBetween(0, n)); - } -} -var fixed = (values3) => new FixedRandomImpl(values3); - -// node_modules/effect/dist/esm/internal/tracer.js -var TracerTypeId = /* @__PURE__ */ Symbol.for("effect/Tracer"); -var make24 = (options) => ({ - [TracerTypeId]: TracerTypeId, - ...options -}); -var tracerTag = /* @__PURE__ */ GenericTag("effect/Tracer"); -var spanTag = /* @__PURE__ */ GenericTag("effect/ParentSpan"); -var randomHexString = /* @__PURE__ */ function() { - const characters = "abcdef0123456789"; - const charactersLength = characters.length; - return function(length2) { - let result = ""; - for (let i = 0;i < length2; i++) { - result += characters.charAt(Math.floor(Math.random() * charactersLength)); - } - return result; - }; -}(); - -class NativeSpan { - name; - parent; - context; - startTime; - kind; - _tag = "Span"; - spanId; - traceId = "native"; - sampled = true; - status; - attributes; - events = []; - links; - constructor(name, parent, context2, links, startTime, kind) { - this.name = name; - this.parent = parent; - this.context = context2; - this.startTime = startTime; - this.kind = kind; - this.status = { - _tag: "Started", - startTime - }; - this.attributes = new Map; - this.traceId = parent._tag === "Some" ? parent.value.traceId : randomHexString(32); - this.spanId = randomHexString(16); - this.links = Array.from(links); - } - end(endTime, exit2) { - this.status = { - _tag: "Ended", - endTime, - exit: exit2, - startTime: this.status.startTime - }; - } - attribute(key, value) { - this.attributes.set(key, value); - } - event(name, startTime, attributes) { - this.events.push([name, startTime, attributes ?? {}]); - } - addLinks(links) { - this.links.push(...links); - } -} -var nativeTracer = /* @__PURE__ */ make24({ - span: (name, parent, context2, links, startTime, kind) => new NativeSpan(name, parent, context2, links, startTime, kind), - context: (f) => f() -}); -var addSpanStackTrace = (options) => { - if (options?.captureStackTrace === false) { - return options; - } else if (options?.captureStackTrace !== undefined && typeof options.captureStackTrace !== "boolean") { - return options; - } - const limit = Error.stackTraceLimit; - Error.stackTraceLimit = 3; - const traceError = new Error; - Error.stackTraceLimit = limit; - let cache = false; - return { - ...options, - captureStackTrace: () => { - if (cache !== false) { - return cache; - } - if (traceError.stack !== undefined) { - const stack = traceError.stack.split(` -`); - if (stack[3] !== undefined) { - cache = stack[3].trim(); - return cache; - } - } - } - }; -}; -var DisablePropagation = /* @__PURE__ */ Reference2()("effect/Tracer/DisablePropagation", { - defaultValue: constFalse -}); - -// node_modules/effect/dist/esm/internal/defaultServices.js -var liveServices = /* @__PURE__ */ pipe(/* @__PURE__ */ empty3(), /* @__PURE__ */ add2(clockTag, /* @__PURE__ */ make20()), /* @__PURE__ */ add2(consoleTag, defaultConsole), /* @__PURE__ */ add2(randomTag, /* @__PURE__ */ make23(/* @__PURE__ */ Math.random())), /* @__PURE__ */ add2(configProviderTag, /* @__PURE__ */ fromEnv()), /* @__PURE__ */ add2(tracerTag, nativeTracer)); -var currentServices = /* @__PURE__ */ globalValue(/* @__PURE__ */ Symbol.for("effect/DefaultServices/currentServices"), () => fiberRefUnsafeMakeContext(liveServices)); -var sleep = (duration) => { - const decodedDuration = decode(duration); - return clockWith((clock) => clock.sleep(decodedDuration)); -}; -var defaultServicesWith = (f) => withFiberRuntime((fiber) => f(fiber.currentDefaultServices)); -var clockWith = (f) => defaultServicesWith((services) => f(services.unsafeMap.get(clockTag.key))); -var currentTimeMillis = /* @__PURE__ */ clockWith((clock) => clock.currentTimeMillis); -var currentTimeNanos = /* @__PURE__ */ clockWith((clock) => clock.currentTimeNanos); -var withClock = /* @__PURE__ */ dual(2, (effect, c) => fiberRefLocallyWith(currentServices, add2(clockTag, c))(effect)); -var withConfigProvider = /* @__PURE__ */ dual(2, (self, provider) => fiberRefLocallyWith(currentServices, add2(configProviderTag, provider))(self)); -var configProviderWith = (f) => defaultServicesWith((services) => f(services.unsafeMap.get(configProviderTag.key))); -var config = (config2) => configProviderWith((_) => _.load(config2)); -var randomWith = (f) => defaultServicesWith((services) => f(services.unsafeMap.get(randomTag.key))); -var withRandom = /* @__PURE__ */ dual(2, (effect, value) => fiberRefLocallyWith(currentServices, add2(randomTag, value))(effect)); -var tracerWith = (f) => defaultServicesWith((services) => f(services.unsafeMap.get(tracerTag.key))); -var withTracer = /* @__PURE__ */ dual(2, (effect, value) => fiberRefLocallyWith(currentServices, add2(tracerTag, value))(effect)); - -// node_modules/effect/dist/esm/Clock.js -var sleep2 = sleep; -var currentTimeMillis2 = currentTimeMillis; -var currentTimeNanos2 = currentTimeNanos; -var clockWith2 = clockWith; -var Clock = clockTag; - -// node_modules/effect/dist/esm/internal/fiberRefs.js -function unsafeMake4(fiberRefLocals) { - return new FiberRefsImpl(fiberRefLocals); -} -function empty20() { - return unsafeMake4(new Map); -} -var FiberRefsSym = /* @__PURE__ */ Symbol.for("effect/FiberRefs"); - -class FiberRefsImpl { - locals; - [FiberRefsSym] = FiberRefsSym; - constructor(locals) { - this.locals = locals; - } - pipe() { - return pipeArguments(this, arguments); - } -} -var findAncestor = (_ref, _parentStack, _childStack, _childModified = false) => { - const ref = _ref; - let parentStack = _parentStack; - let childStack = _childStack; - let childModified = _childModified; - let ret = undefined; - while (ret === undefined) { - if (isNonEmptyReadonlyArray(parentStack) && isNonEmptyReadonlyArray(childStack)) { - const parentFiberId = headNonEmpty(parentStack)[0]; - const parentAncestors = tailNonEmpty(parentStack); - const childFiberId = headNonEmpty(childStack)[0]; - const childRefValue = headNonEmpty(childStack)[1]; - const childAncestors = tailNonEmpty(childStack); - if (parentFiberId.startTimeMillis < childFiberId.startTimeMillis) { - childStack = childAncestors; - childModified = true; - } else if (parentFiberId.startTimeMillis > childFiberId.startTimeMillis) { - parentStack = parentAncestors; - } else { - if (parentFiberId.id < childFiberId.id) { - childStack = childAncestors; - childModified = true; - } else if (parentFiberId.id > childFiberId.id) { - parentStack = parentAncestors; - } else { - ret = [childRefValue, childModified]; - } - } - } else { - ret = [ref.initial, true]; - } - } - return ret; -}; -var joinAs = /* @__PURE__ */ dual(3, (self, fiberId2, that) => { - const parentFiberRefs = new Map(self.locals); - that.locals.forEach((childStack, fiberRef) => { - const childValue = childStack[0][1]; - if (!childStack[0][0][symbol2](fiberId2)) { - if (!parentFiberRefs.has(fiberRef)) { - if (equals(childValue, fiberRef.initial)) { - return; - } - parentFiberRefs.set(fiberRef, [[fiberId2, fiberRef.join(fiberRef.initial, childValue)]]); - return; - } - const parentStack = parentFiberRefs.get(fiberRef); - const [ancestor, wasModified] = findAncestor(fiberRef, parentStack, childStack); - if (wasModified) { - const patch6 = fiberRef.diff(ancestor, childValue); - const oldValue = parentStack[0][1]; - const newValue = fiberRef.join(oldValue, fiberRef.patch(patch6)(oldValue)); - if (!equals(oldValue, newValue)) { - let newStack; - const parentFiberId = parentStack[0][0]; - if (parentFiberId[symbol2](fiberId2)) { - newStack = [[parentFiberId, newValue], ...parentStack.slice(1)]; - } else { - newStack = [[fiberId2, newValue], ...parentStack]; - } - parentFiberRefs.set(fiberRef, newStack); - } - } - } - }); - return new FiberRefsImpl(parentFiberRefs); -}); -var forkAs = /* @__PURE__ */ dual(2, (self, childId) => { - const map10 = new Map; - unsafeForkAs(self, map10, childId); - return new FiberRefsImpl(map10); -}); -var unsafeForkAs = (self, map10, fiberId2) => { - self.locals.forEach((stack, fiberRef) => { - const oldValue = stack[0][1]; - const newValue = fiberRef.patch(fiberRef.fork)(oldValue); - if (equals(oldValue, newValue)) { - map10.set(fiberRef, stack); - } else { - map10.set(fiberRef, [[fiberId2, newValue], ...stack]); - } - }); -}; -var fiberRefs = (self) => fromIterable5(self.locals.keys()); -var setAll = (self) => forEachSequentialDiscard(fiberRefs(self), (fiberRef) => fiberRefSet(fiberRef, getOrDefault(self, fiberRef))); -var delete_ = /* @__PURE__ */ dual(2, (self, fiberRef) => { - const locals = new Map(self.locals); - locals.delete(fiberRef); - return new FiberRefsImpl(locals); -}); -var get9 = /* @__PURE__ */ dual(2, (self, fiberRef) => { - if (!self.locals.has(fiberRef)) { - return none2(); - } - return some2(headNonEmpty(self.locals.get(fiberRef))[1]); -}); -var getOrDefault = /* @__PURE__ */ dual(2, (self, fiberRef) => pipe(get9(self, fiberRef), getOrElse(() => fiberRef.initial))); -var updateAs = /* @__PURE__ */ dual(2, (self, { - fiberId: fiberId2, - fiberRef, - value -}) => { - if (self.locals.size === 0) { - return new FiberRefsImpl(new Map([[fiberRef, [[fiberId2, value]]]])); - } - const locals = new Map(self.locals); - unsafeUpdateAs(locals, fiberId2, fiberRef, value); - return new FiberRefsImpl(locals); -}); -var unsafeUpdateAs = (locals, fiberId2, fiberRef, value) => { - const oldStack = locals.get(fiberRef) ?? []; - let newStack; - if (isNonEmptyReadonlyArray(oldStack)) { - const [currentId, currentValue] = headNonEmpty(oldStack); - if (currentId[symbol2](fiberId2)) { - if (equals(currentValue, value)) { - return; - } else { - newStack = [[fiberId2, value], ...oldStack.slice(1)]; - } - } else { - newStack = [[fiberId2, value], ...oldStack]; - } - } else { - newStack = [[fiberId2, value]]; - } - locals.set(fiberRef, newStack); -}; -var updateManyAs = /* @__PURE__ */ dual(2, (self, { - entries: entries2, - forkAs: forkAs2 -}) => { - if (self.locals.size === 0) { - return new FiberRefsImpl(new Map(entries2)); - } - const locals = new Map(self.locals); - if (forkAs2 !== undefined) { - unsafeForkAs(self, locals, forkAs2); - } - entries2.forEach(([fiberRef, values3]) => { - if (values3.length === 1) { - unsafeUpdateAs(locals, values3[0][0], fiberRef, values3[0][1]); - } else { - values3.forEach(([fiberId2, value]) => { - unsafeUpdateAs(locals, fiberId2, fiberRef, value); - }); - } - }); - return new FiberRefsImpl(locals); -}); - -// node_modules/effect/dist/esm/FiberRefs.js -var get10 = get9; -var getOrDefault2 = getOrDefault; -var joinAs2 = joinAs; -var setAll2 = setAll; -var updateManyAs2 = updateManyAs; -var empty21 = empty20; - -// node_modules/effect/dist/esm/LogLevel.js -var All = logLevelAll; -var Fatal = logLevelFatal; -var Error2 = logLevelError; -var Warning = logLevelWarning; -var Info = logLevelInfo; -var Debug = logLevelDebug; -var Trace = logLevelTrace; -var None3 = logLevelNone; -var Order5 = /* @__PURE__ */ pipe(Order, /* @__PURE__ */ mapInput2((level) => level.ordinal)); -var greaterThan4 = /* @__PURE__ */ greaterThan(Order5); -var fromLiteral = (literal) => { - switch (literal) { - case "All": - return All; - case "Debug": - return Debug; - case "Error": - return Error2; - case "Fatal": - return Fatal; - case "Info": - return Info; - case "Trace": - return Trace; - case "None": - return None3; - case "Warning": - return Warning; - } -}; - -// node_modules/effect/dist/esm/internal/logSpan.js -var make25 = (label, startTime) => ({ - label, - startTime -}); -var formatLabel = (key) => key.replace(/[\s="]/g, "_"); -var render = (now) => (self) => { - const label = formatLabel(self.label); - return `${label}=${now - self.startTime}ms`; -}; - -// node_modules/effect/dist/esm/LogSpan.js -var make26 = make25; - -// node_modules/effect/dist/esm/Effectable.js -var EffectPrototype2 = EffectPrototype; -var CommitPrototype2 = CommitPrototype; -var Base2 = Base; -class Class extends Base2 { -} - -// node_modules/effect/dist/esm/Readable.js -var TypeId13 = /* @__PURE__ */ Symbol.for("effect/Readable"); -var Proto = { - [TypeId13]: TypeId13, - pipe() { - return pipeArguments(this, arguments); - } -}; - -// node_modules/effect/dist/esm/internal/ref.js -var RefTypeId = /* @__PURE__ */ Symbol.for("effect/Ref"); -var refVariance = { - _A: (_) => _ -}; - -class RefImpl extends Class { - ref; - commit() { - return this.get; - } - [RefTypeId] = refVariance; - [TypeId13] = TypeId13; - constructor(ref) { - super(); - this.ref = ref; - this.get = sync(() => get6(this.ref)); - } - get; - modify(f) { - return sync(() => { - const current = get6(this.ref); - const [b, a] = f(current); - if (current !== a) { - set2(a)(this.ref); - } - return b; - }); - } -} -var unsafeMake5 = (value) => new RefImpl(make12(value)); -var make27 = (value) => sync(() => unsafeMake5(value)); -var get11 = (self) => self.get; -var set5 = /* @__PURE__ */ dual(2, (self, value) => self.modify(() => [undefined, value])); -var getAndSet = /* @__PURE__ */ dual(2, (self, value) => self.modify((a) => [a, value])); -var modify3 = /* @__PURE__ */ dual(2, (self, f) => self.modify(f)); -var update2 = /* @__PURE__ */ dual(2, (self, f) => self.modify((a) => [undefined, f(a)])); - -// node_modules/effect/dist/esm/Ref.js -var make28 = make27; -var get12 = get11; -var getAndSet2 = getAndSet; -var update3 = update2; - -// node_modules/effect/dist/esm/Tracer.js -var tracerWith2 = tracerWith; - -// node_modules/effect/dist/esm/internal/fiberRefs/patch.js -var OP_EMPTY2 = "Empty"; -var OP_ADD = "Add"; -var OP_REMOVE = "Remove"; -var OP_UPDATE = "Update"; -var OP_AND_THEN = "AndThen"; -var empty22 = { - _tag: OP_EMPTY2 -}; -var diff5 = (oldValue, newValue) => { - const missingLocals = new Map(oldValue.locals); - let patch6 = empty22; - for (const [fiberRef, pairs] of newValue.locals.entries()) { - const newValue2 = headNonEmpty(pairs)[1]; - const old = missingLocals.get(fiberRef); - if (old !== undefined) { - const oldValue2 = headNonEmpty(old)[1]; - if (!equals(oldValue2, newValue2)) { - patch6 = combine7({ - _tag: OP_UPDATE, - fiberRef, - patch: fiberRef.diff(oldValue2, newValue2) - })(patch6); - } - } else { - patch6 = combine7({ - _tag: OP_ADD, - fiberRef, - value: newValue2 - })(patch6); - } - missingLocals.delete(fiberRef); - } - for (const [fiberRef] of missingLocals.entries()) { - patch6 = combine7({ - _tag: OP_REMOVE, - fiberRef - })(patch6); - } - return patch6; -}; -var combine7 = /* @__PURE__ */ dual(2, (self, that) => ({ - _tag: OP_AND_THEN, - first: self, - second: that -})); -var patch6 = /* @__PURE__ */ dual(3, (self, fiberId2, oldValue) => { - let fiberRefs2 = oldValue; - let patches = of(self); - while (isNonEmptyReadonlyArray(patches)) { - const head3 = headNonEmpty(patches); - const tail = tailNonEmpty(patches); - switch (head3._tag) { - case OP_EMPTY2: { - patches = tail; - break; - } - case OP_ADD: { - fiberRefs2 = updateAs(fiberRefs2, { - fiberId: fiberId2, - fiberRef: head3.fiberRef, - value: head3.value - }); - patches = tail; - break; - } - case OP_REMOVE: { - fiberRefs2 = delete_(fiberRefs2, head3.fiberRef); - patches = tail; - break; - } - case OP_UPDATE: { - const value = getOrDefault(fiberRefs2, head3.fiberRef); - fiberRefs2 = updateAs(fiberRefs2, { - fiberId: fiberId2, - fiberRef: head3.fiberRef, - value: head3.fiberRef.patch(head3.patch)(value) - }); - patches = tail; - break; - } - case OP_AND_THEN: { - patches = prepend(head3.first)(prepend(head3.second)(tail)); - break; - } - } - } - return fiberRefs2; -}); - -// node_modules/effect/dist/esm/internal/metric/label.js -var MetricLabelSymbolKey = "effect/MetricLabel"; -var MetricLabelTypeId = /* @__PURE__ */ Symbol.for(MetricLabelSymbolKey); - -class MetricLabelImpl { - key; - value; - [MetricLabelTypeId] = MetricLabelTypeId; - _hash; - constructor(key, value) { - this.key = key; - this.value = value; - this._hash = string(MetricLabelSymbolKey + this.key + this.value); - } - [symbol]() { - return this._hash; - } - [symbol2](that) { - return isMetricLabel(that) && this.key === that.key && this.value === that.value; - } - pipe() { - return pipeArguments(this, arguments); - } -} -var make29 = (key, value) => { - return new MetricLabelImpl(key, value); -}; -var isMetricLabel = (u) => hasProperty(u, MetricLabelTypeId); - -// node_modules/effect/dist/esm/internal/core-effect.js -var annotateLogs = /* @__PURE__ */ dual((args) => isEffect(args[0]), function() { - const args = arguments; - return fiberRefLocallyWith(args[0], currentLogAnnotations, typeof args[1] === "string" ? set3(args[1], args[2]) : (annotations2) => Object.entries(args[1]).reduce((acc, [key, value]) => set3(acc, key, value), annotations2)); -}); -var asSome = (self) => map9(self, some2); -var asSomeError = (self) => mapError(self, some2); -var try_2 = (arg) => { - let evaluate; - let onFailure = undefined; - if (typeof arg === "function") { - evaluate = arg; - } else { - evaluate = arg.try; - onFailure = arg.catch; - } - return suspend(() => { - try { - return succeed(internalCall(evaluate)); - } catch (error) { - return fail2(onFailure ? internalCall(() => onFailure(error)) : new UnknownException(error, "An unknown error occurred in Effect.try")); - } - }); -}; -var _catch = /* @__PURE__ */ dual(3, (self, tag, options) => catchAll(self, (e) => { - if (hasProperty(e, tag) && e[tag] === options.failure) { - return options.onFailure(e); - } - return fail2(e); -})); -var catchAllDefect = /* @__PURE__ */ dual(2, (self, f) => catchAllCause(self, (cause) => { - const option = find(cause, (_) => isDieType(_) ? some2(_) : none2()); - switch (option._tag) { - case "None": { - return failCause(cause); - } - case "Some": { - return f(option.value.defect); - } - } -})); -var catchSomeCause = /* @__PURE__ */ dual(2, (self, f) => matchCauseEffect(self, { - onFailure: (cause) => { - const option = f(cause); - switch (option._tag) { - case "None": { - return failCause(cause); - } - case "Some": { - return option.value; - } - } - }, - onSuccess: succeed -})); -var catchSomeDefect = /* @__PURE__ */ dual(2, (self, pf) => catchAllCause(self, (cause) => { - const option = find(cause, (_) => isDieType(_) ? some2(_) : none2()); - switch (option._tag) { - case "None": { - return failCause(cause); - } - case "Some": { - const optionEffect = pf(option.value.defect); - return optionEffect._tag === "Some" ? optionEffect.value : failCause(cause); - } - } -})); -var catchTag = /* @__PURE__ */ dual((args) => isEffect(args[0]), (self, ...args) => { - const f = args[args.length - 1]; - let predicate; - if (args.length === 2) { - predicate = isTagged(args[0]); - } else { - predicate = (e) => { - const tag = hasProperty(e, "_tag") ? e["_tag"] : undefined; - if (!tag) - return false; - for (let i = 0;i < args.length - 1; i++) { - if (args[i] === tag) - return true; - } - return false; - }; - } - return catchIf(self, predicate, f); -}); -var catchTags = /* @__PURE__ */ dual(2, (self, cases) => { - let keys3; - return catchIf(self, (e) => { - keys3 ??= Object.keys(cases); - return hasProperty(e, "_tag") && isString(e["_tag"]) && keys3.includes(e["_tag"]); - }, (e) => cases[e["_tag"]](e)); -}); -var cause = (self) => matchCause(self, { - onFailure: identity, - onSuccess: () => empty16 -}); -var clockWith3 = clockWith2; -var clock = /* @__PURE__ */ clockWith3(succeed); -var delay = /* @__PURE__ */ dual(2, (self, duration) => zipRight(sleep2(duration), self)); -var descriptorWith = (f) => withFiberRuntime((state, status) => f({ - id: state.id(), - status, - interruptors: interruptors(state.getFiberRef(currentInterruptedCause)) -})); -var allowInterrupt = /* @__PURE__ */ descriptorWith((descriptor) => size3(descriptor.interruptors) > 0 ? interrupt2 : void_); -var descriptor = /* @__PURE__ */ descriptorWith(succeed); -var diffFiberRefs = (self) => summarized(self, fiberRefs2, diff5); -var diffFiberRefsAndRuntimeFlags = (self) => summarized(self, zip2(fiberRefs2, runtimeFlags), ([refs, flags], [refsNew, flagsNew]) => [diff5(refs, refsNew), diff4(flags, flagsNew)]); -var Do = /* @__PURE__ */ succeed({}); -var bind2 = /* @__PURE__ */ bind(map9, flatMap7); -var bindTo2 = /* @__PURE__ */ bindTo(map9); -var let_2 = /* @__PURE__ */ let_(map9); -var dropUntil = /* @__PURE__ */ dual(2, (elements, predicate) => suspend(() => { - const iterator = elements[Symbol.iterator](); - const builder = []; - let next; - let dropping = succeed(false); - let i = 0; - while ((next = iterator.next()) && !next.done) { - const a = next.value; - const index = i++; - dropping = flatMap7(dropping, (bool) => { - if (bool) { - builder.push(a); - return succeed(true); - } - return predicate(a, index); - }); - } - return map9(dropping, () => builder); -})); -var dropWhile = /* @__PURE__ */ dual(2, (elements, predicate) => suspend(() => { - const iterator = elements[Symbol.iterator](); - const builder = []; - let next; - let dropping = succeed(true); - let i = 0; - while ((next = iterator.next()) && !next.done) { - const a = next.value; - const index = i++; - dropping = flatMap7(dropping, (d) => map9(d ? predicate(a, index) : succeed(false), (b) => { - if (!b) { - builder.push(a); - } - return b; - })); - } - return map9(dropping, () => builder); -})); -var contextWith = (f) => map9(context(), f); -var eventually = (self) => orElse2(self, () => flatMap7(yieldNow(), () => eventually(self))); -var filterMap4 = /* @__PURE__ */ dual(2, (elements, pf) => map9(forEachSequential(elements, identity), filterMap2(pf))); -var filterOrDie = /* @__PURE__ */ dual(3, (self, predicate, orDieWith2) => filterOrElse(self, predicate, (a) => dieSync(() => orDieWith2(a)))); -var filterOrDieMessage = /* @__PURE__ */ dual(3, (self, predicate, message) => filterOrElse(self, predicate, () => dieMessage(message))); -var filterOrElse = /* @__PURE__ */ dual(3, (self, predicate, orElse3) => flatMap7(self, (a) => predicate(a) ? succeed(a) : orElse3(a))); -var liftPredicate = /* @__PURE__ */ dual(3, (self, predicate, orFailWith) => suspend(() => predicate(self) ? succeed(self) : fail2(orFailWith(self)))); -var filterOrFail = /* @__PURE__ */ dual((args) => isEffect(args[0]), (self, predicate, orFailWith) => filterOrElse(self, predicate, (a) => orFailWith === undefined ? fail2(new NoSuchElementException) : failSync(() => orFailWith(a)))); -var findFirst4 = /* @__PURE__ */ dual(2, (elements, predicate) => suspend(() => { - const iterator = elements[Symbol.iterator](); - const next = iterator.next(); - if (!next.done) { - return findLoop(iterator, 0, predicate, next.value); - } - return succeed(none2()); -})); -var findLoop = (iterator, index, f, value) => flatMap7(f(value, index), (result) => { - if (result) { - return succeed(some2(value)); - } - const next = iterator.next(); - if (!next.done) { - return findLoop(iterator, index + 1, f, next.value); - } - return succeed(none2()); -}); -var firstSuccessOf = (effects) => suspend(() => { - const list = fromIterable2(effects); - if (!isNonEmpty2(list)) { - return dieSync(() => new IllegalArgumentException(`Received an empty collection of effects`)); - } - return pipe(tailNonEmpty2(list), reduce(headNonEmpty2(list), (left3, right3) => orElse2(left3, () => right3))); -}); -var flipWith = /* @__PURE__ */ dual(2, (self, f) => flip(f(flip(self)))); -var match7 = /* @__PURE__ */ dual(2, (self, options) => matchEffect(self, { - onFailure: (e) => succeed(options.onFailure(e)), - onSuccess: (a) => succeed(options.onSuccess(a)) -})); -var every4 = /* @__PURE__ */ dual(2, (elements, predicate) => suspend(() => forAllLoop(elements[Symbol.iterator](), 0, predicate))); -var forAllLoop = (iterator, index, f) => { - const next = iterator.next(); - return next.done ? succeed(true) : flatMap7(f(next.value, index), (b) => b ? forAllLoop(iterator, index + 1, f) : succeed(b)); -}; -var forever = (self) => { - const loop = flatMap7(flatMap7(self, () => yieldNow()), () => loop); - return loop; -}; -var fiberRefs2 = /* @__PURE__ */ withFiberRuntime((state) => succeed(state.getFiberRefs())); -var head3 = (self) => flatMap7(self, (as2) => { - const iterator = as2[Symbol.iterator](); - const next = iterator.next(); - if (next.done) { - return fail2(new NoSuchElementException); - } - return succeed(next.value); -}); -var ignore = (self) => match7(self, { - onFailure: constVoid, - onSuccess: constVoid -}); -var ignoreLogged = (self) => matchCauseEffect(self, { - onFailure: (cause2) => logDebug(cause2, "An error was silently ignored because it is not anticipated to be useful"), - onSuccess: () => void_ -}); -var inheritFiberRefs = (childFiberRefs) => updateFiberRefs((parentFiberId, parentFiberRefs) => joinAs2(parentFiberRefs, parentFiberId, childFiberRefs)); -var isFailure = (self) => match7(self, { - onFailure: constTrue, - onSuccess: constFalse -}); -var isSuccess2 = (self) => match7(self, { - onFailure: constFalse, - onSuccess: constTrue -}); -var iterate = (initial, options) => suspend(() => { - if (options.while(initial)) { - return flatMap7(options.body(initial), (z2) => iterate(z2, options)); - } - return succeed(initial); -}); -var logWithLevel = (level) => (...message) => { - const levelOption = fromNullable(level); - let cause2 = undefined; - for (let i = 0, len = message.length;i < len; i++) { - const msg = message[i]; - if (isCause(msg)) { - if (cause2 !== undefined) { - cause2 = sequential(cause2, msg); - } else { - cause2 = msg; - } - message = [...message.slice(0, i), ...message.slice(i + 1)]; - i--; - } - } - if (cause2 === undefined) { - cause2 = empty16; - } - return withFiberRuntime((fiberState) => { - fiberState.log(message, cause2, levelOption); - return void_; - }); -}; -var log = /* @__PURE__ */ logWithLevel(); -var logTrace = /* @__PURE__ */ logWithLevel(Trace); -var logDebug = /* @__PURE__ */ logWithLevel(Debug); -var logInfo = /* @__PURE__ */ logWithLevel(Info); -var logWarning = /* @__PURE__ */ logWithLevel(Warning); -var logError = /* @__PURE__ */ logWithLevel(Error2); -var logFatal = /* @__PURE__ */ logWithLevel(Fatal); -var withLogSpan = /* @__PURE__ */ dual(2, (effect, label) => flatMap7(currentTimeMillis2, (now) => fiberRefLocallyWith(effect, currentLogSpan, prepend3(make26(label, now))))); -var logAnnotations = /* @__PURE__ */ fiberRefGet(currentLogAnnotations); -var loop = (initial, options) => options.discard ? loopDiscard(initial, options.while, options.step, options.body) : map9(loopInternal(initial, options.while, options.step, options.body), fromIterable); -var loopInternal = (initial, cont, inc, body) => suspend(() => cont(initial) ? flatMap7(body(initial), (a) => map9(loopInternal(inc(initial), cont, inc, body), prepend3(a))) : sync(() => empty9())); -var loopDiscard = (initial, cont, inc, body) => suspend(() => cont(initial) ? flatMap7(body(initial), () => loopDiscard(inc(initial), cont, inc, body)) : void_); -var mapAccum2 = /* @__PURE__ */ dual(3, (elements, initial, f) => suspend(() => { - const iterator = elements[Symbol.iterator](); - const builder = []; - let result = succeed(initial); - let next; - let i = 0; - while (!(next = iterator.next()).done) { - const index = i++; - const value = next.value; - result = flatMap7(result, (state) => map9(f(state, value, index), ([z, b]) => { - builder.push(b); - return z; - })); - } - return map9(result, (z) => [z, builder]); -})); -var mapErrorCause = /* @__PURE__ */ dual(2, (self, f) => matchCauseEffect(self, { - onFailure: (c) => failCauseSync(() => f(c)), - onSuccess: succeed -})); -var memoize = (self) => pipe(deferredMake(), flatMap7((deferred) => pipe(diffFiberRefsAndRuntimeFlags(self), intoDeferred(deferred), once, map9((complete) => zipRight(complete, pipe(deferredAwait(deferred), flatMap7(([patch7, a]) => as(zip2(patchFiberRefs(patch7[0]), updateRuntimeFlags(patch7[1])), a)))))))); -var merge5 = (self) => matchEffect(self, { - onFailure: (e) => succeed(e), - onSuccess: succeed -}); -var negate = (self) => map9(self, (b) => !b); -var none6 = (self) => flatMap7(self, (option) => { - switch (option._tag) { - case "None": - return void_; - case "Some": - return fail2(new NoSuchElementException); - } -}); -var once = (self) => map9(make28(true), (ref) => asVoid(whenEffect(self, getAndSet2(ref, false)))); -var option = (self) => matchEffect(self, { - onFailure: () => succeed(none2()), - onSuccess: (a) => succeed(some2(a)) -}); -var orElseFail = /* @__PURE__ */ dual(2, (self, evaluate) => orElse2(self, () => failSync(evaluate))); -var orElseSucceed = /* @__PURE__ */ dual(2, (self, evaluate) => orElse2(self, () => sync(evaluate))); -var parallelErrors = (self) => matchCauseEffect(self, { - onFailure: (cause2) => { - const errors = fromIterable(failures(cause2)); - return errors.length === 0 ? failCause(cause2) : fail2(errors); - }, - onSuccess: succeed -}); -var patchFiberRefs = (patch7) => updateFiberRefs((fiberId2, fiberRefs3) => pipe(patch7, patch6(fiberId2, fiberRefs3))); -var promise = (evaluate) => evaluate.length >= 1 ? async_((resolve, signal) => { - try { - evaluate(signal).then((a) => resolve(succeed(a)), (e) => resolve(die2(e))); - } catch (e) { - resolve(die2(e)); - } -}) : async_((resolve) => { - try { - evaluate().then((a) => resolve(succeed(a)), (e) => resolve(die2(e))); - } catch (e) { - resolve(die2(e)); - } -}); -var provideService = /* @__PURE__ */ dual(3, (self, tag, service) => contextWithEffect((env) => provideContext(self, add2(env, tag, service)))); -var provideServiceEffect = /* @__PURE__ */ dual(3, (self, tag, effect) => contextWithEffect((env) => flatMap7(effect, (service) => provideContext(self, pipe(env, add2(tag, service)))))); -var random2 = /* @__PURE__ */ randomWith(succeed); -var reduce8 = /* @__PURE__ */ dual(3, (elements, zero3, f) => fromIterable(elements).reduce((acc, el, i) => flatMap7(acc, (a) => f(a, el, i)), succeed(zero3))); -var reduceRight2 = /* @__PURE__ */ dual(3, (elements, zero3, f) => fromIterable(elements).reduceRight((acc, el, i) => flatMap7(acc, (a) => f(el, a, i)), succeed(zero3))); -var reduceWhile = /* @__PURE__ */ dual(3, (elements, zero3, options) => flatMap7(sync(() => elements[Symbol.iterator]()), (iterator) => reduceWhileLoop(iterator, 0, zero3, options.while, options.body))); -var reduceWhileLoop = (iterator, index, state, predicate, f) => { - const next = iterator.next(); - if (!next.done && predicate(state)) { - return flatMap7(f(state, next.value, index), (nextState) => reduceWhileLoop(iterator, index + 1, nextState, predicate, f)); - } - return succeed(state); -}; -var repeatN = /* @__PURE__ */ dual(2, (self, n) => suspend(() => repeatNLoop(self, n))); -var repeatNLoop = (self, n) => flatMap7(self, (a) => n <= 0 ? succeed(a) : zipRight(yieldNow(), repeatNLoop(self, n - 1))); -var sandbox = (self) => matchCauseEffect(self, { - onFailure: fail2, - onSuccess: succeed -}); -var setFiberRefs = (fiberRefs3) => suspend(() => setAll2(fiberRefs3)); -var sleep3 = sleep2; -var succeedNone = /* @__PURE__ */ succeed(/* @__PURE__ */ none2()); -var succeedSome = (value) => succeed(some2(value)); -var summarized = /* @__PURE__ */ dual(3, (self, summary, f) => flatMap7(summary, (start) => flatMap7(self, (value) => map9(summary, (end) => [f(start, end), value])))); -var tagMetrics = /* @__PURE__ */ dual((args) => isEffect(args[0]), function() { - return labelMetrics(arguments[0], typeof arguments[1] === "string" ? [make29(arguments[1], arguments[2])] : Object.entries(arguments[1]).map(([k, v]) => make29(k, v))); -}); -var labelMetrics = /* @__PURE__ */ dual(2, (self, labels) => fiberRefLocallyWith(self, currentMetricLabels, (old) => union(old, labels))); -var takeUntil = /* @__PURE__ */ dual(2, (elements, predicate) => suspend(() => { - const iterator = elements[Symbol.iterator](); - const builder = []; - let next; - let effect = succeed(false); - let i = 0; - while ((next = iterator.next()) && !next.done) { - const a = next.value; - const index = i++; - effect = flatMap7(effect, (bool) => { - if (bool) { - return succeed(true); - } - builder.push(a); - return predicate(a, index); - }); - } - return map9(effect, () => builder); -})); -var takeWhile = /* @__PURE__ */ dual(2, (elements, predicate) => suspend(() => { - const iterator = elements[Symbol.iterator](); - const builder = []; - let next; - let taking = succeed(true); - let i = 0; - while ((next = iterator.next()) && !next.done) { - const a = next.value; - const index = i++; - taking = flatMap7(taking, (taking2) => pipe(taking2 ? predicate(a, index) : succeed(false), map9((bool) => { - if (bool) { - builder.push(a); - } - return bool; - }))); - } - return map9(taking, () => builder); -})); -var tapBoth = /* @__PURE__ */ dual(2, (self, { - onFailure, - onSuccess -}) => matchCauseEffect(self, { - onFailure: (cause2) => { - const either3 = failureOrCause(cause2); - switch (either3._tag) { - case "Left": { - return zipRight(onFailure(either3.left), failCause(cause2)); - } - case "Right": { - return failCause(cause2); - } - } - }, - onSuccess: (a) => as(onSuccess(a), a) -})); -var tapDefect = /* @__PURE__ */ dual(2, (self, f) => catchAllCause(self, (cause2) => match2(keepDefects(cause2), { - onNone: () => failCause(cause2), - onSome: (a) => zipRight(f(a), failCause(cause2)) -}))); -var tapError = /* @__PURE__ */ dual(2, (self, f) => matchCauseEffect(self, { - onFailure: (cause2) => { - const either3 = failureOrCause(cause2); - switch (either3._tag) { - case "Left": - return zipRight(f(either3.left), failCause(cause2)); - case "Right": - return failCause(cause2); - } - }, - onSuccess: succeed -})); -var tapErrorTag = /* @__PURE__ */ dual(3, (self, k, f) => tapError(self, (e) => { - if (isTagged(e, k)) { - return f(e); - } - return void_; -})); -var tapErrorCause = /* @__PURE__ */ dual(2, (self, f) => matchCauseEffect(self, { - onFailure: (cause2) => zipRight(f(cause2), failCause(cause2)), - onSuccess: succeed -})); -var timed = (self) => timedWith(self, currentTimeNanos2); -var timedWith = /* @__PURE__ */ dual(2, (self, nanos2) => summarized(self, nanos2, (start, end) => nanos(end - start))); -var tracerWith3 = tracerWith2; -var tracer = /* @__PURE__ */ tracerWith3(succeed); -var tryPromise = (arg) => { - let evaluate; - let catcher = undefined; - if (typeof arg === "function") { - evaluate = arg; - } else { - evaluate = arg.try; - catcher = arg.catch; - } - const fail3 = (e) => catcher ? failSync(() => catcher(e)) : fail2(new UnknownException(e, "An unknown error occurred in Effect.tryPromise")); - if (evaluate.length >= 1) { - return async_((resolve, signal) => { - try { - evaluate(signal).then((a) => resolve(succeed(a)), (e) => resolve(fail3(e))); - } catch (e) { - resolve(fail3(e)); - } - }); - } - return async_((resolve) => { - try { - evaluate().then((a) => resolve(succeed(a)), (e) => resolve(fail3(e))); - } catch (e) { - resolve(fail3(e)); - } - }); -}; -var tryMap = /* @__PURE__ */ dual(2, (self, options) => flatMap7(self, (a) => try_2({ - try: () => options.try(a), - catch: options.catch -}))); -var tryMapPromise = /* @__PURE__ */ dual(2, (self, options) => flatMap7(self, (a) => tryPromise({ - try: options.try.length >= 1 ? (signal) => options.try(a, signal) : () => options.try(a), - catch: options.catch -}))); -var unless = /* @__PURE__ */ dual(2, (self, condition) => suspend(() => condition() ? succeedNone : asSome(self))); -var unlessEffect = /* @__PURE__ */ dual(2, (self, condition) => flatMap7(condition, (b) => b ? succeedNone : asSome(self))); -var unsandbox = (self) => mapErrorCause(self, flatten4); -var updateFiberRefs = (f) => withFiberRuntime((state) => { - state.setFiberRefs(f(state.id(), state.getFiberRefs())); - return void_; -}); -var updateService = /* @__PURE__ */ dual(3, (self, tag, f) => mapInputContext(self, (context2) => add2(context2, tag, f(unsafeGet3(context2, tag))))); -var when = /* @__PURE__ */ dual(2, (self, condition) => suspend(() => condition() ? map9(self, some2) : succeed(none2()))); -var whenFiberRef = /* @__PURE__ */ dual(3, (self, fiberRef, predicate) => flatMap7(fiberRefGet(fiberRef), (s) => predicate(s) ? map9(self, (a) => [s, some2(a)]) : succeed([s, none2()]))); -var whenRef = /* @__PURE__ */ dual(3, (self, ref, predicate) => flatMap7(get12(ref), (s) => predicate(s) ? map9(self, (a) => [s, some2(a)]) : succeed([s, none2()]))); -var withMetric = /* @__PURE__ */ dual(2, (self, metric) => metric(self)); -var serviceFunctionEffect = (getService, f) => (...args) => flatMap7(getService, (a) => f(a)(...args)); -var serviceFunction = (getService, f) => (...args) => map9(getService, (a) => f(a)(...args)); -var serviceFunctions = (getService) => new Proxy({}, { - get(_target, prop, _receiver) { - return (...args) => flatMap7(getService, (s) => s[prop](...args)); - } -}); -var serviceConstants = (getService) => new Proxy({}, { - get(_target, prop, _receiver) { - return flatMap7(getService, (s) => isEffect(s[prop]) ? s[prop] : succeed(s[prop])); - } -}); -var serviceMembers = (getService) => ({ - functions: serviceFunctions(getService), - constants: serviceConstants(getService) -}); -var serviceOption = (tag) => map9(context(), getOption2(tag)); -var serviceOptional = (tag) => flatMap7(context(), getOption2(tag)); -var annotateCurrentSpan = function() { - const args = arguments; - return ignore(flatMap7(currentPropagatedSpan, (span2) => sync(() => { - if (typeof args[0] === "string") { - span2.attribute(args[0], args[1]); - } else { - for (const key in args[0]) { - span2.attribute(key, args[0][key]); - } - } - }))); -}; -var linkSpanCurrent = function() { - const args = arguments; - const links = Array.isArray(args[0]) ? args[0] : [{ - _tag: "SpanLink", - span: args[0], - attributes: args[1] ?? {} - }]; - return ignore(flatMap7(currentSpan, (span2) => sync(() => span2.addLinks(links)))); -}; -var annotateSpans = /* @__PURE__ */ dual((args) => isEffect(args[0]), function() { - const args = arguments; - return fiberRefLocallyWith(args[0], currentTracerSpanAnnotations, typeof args[1] === "string" ? set3(args[1], args[2]) : (annotations2) => Object.entries(args[1]).reduce((acc, [key, value]) => set3(acc, key, value), annotations2)); -}); -var currentParentSpan = /* @__PURE__ */ serviceOptional(spanTag); -var currentSpan = /* @__PURE__ */ flatMap7(/* @__PURE__ */ context(), (context2) => { - const span2 = context2.unsafeMap.get(spanTag.key); - return span2 !== undefined && span2._tag === "Span" ? succeed(span2) : fail2(new NoSuchElementException); -}); -var currentPropagatedSpan = /* @__PURE__ */ flatMap7(/* @__PURE__ */ context(), (context2) => { - const span2 = filterDisablePropagation(getOption2(context2, spanTag)); - return span2._tag === "Some" && span2.value._tag === "Span" ? succeed(span2.value) : fail2(new NoSuchElementException); -}); -var linkSpans = /* @__PURE__ */ dual((args) => isEffect(args[0]), (self, span2, attributes) => fiberRefLocallyWith(self, currentTracerSpanLinks, append2({ - _tag: "SpanLink", - span: span2, - attributes: attributes ?? {} -}))); -var bigint03 = /* @__PURE__ */ BigInt(0); -var filterDisablePropagation = /* @__PURE__ */ flatMap((span2) => get3(span2.context, DisablePropagation) ? span2._tag === "Span" ? filterDisablePropagation(span2.parent) : none2() : some2(span2)); -var unsafeMakeSpan = (fiber, name, options) => { - const disablePropagation = !fiber.getFiberRef(currentTracerEnabled) || options.context && get3(options.context, DisablePropagation); - const context2 = fiber.getFiberRef(currentContext); - const parent = options.parent ? some2(options.parent) : options.root ? none2() : filterDisablePropagation(getOption2(context2, spanTag)); - let span2; - if (disablePropagation) { - span2 = noopSpan({ - name, - parent, - context: add2(options.context ?? empty3(), DisablePropagation, true) - }); - } else { - const services = fiber.getFiberRef(currentServices); - const tracer2 = get3(services, tracerTag); - const clock2 = get3(services, Clock); - const timingEnabled = fiber.getFiberRef(currentTracerTimingEnabled); - const fiberRefs3 = fiber.getFiberRefs(); - const annotationsFromEnv = get10(fiberRefs3, currentTracerSpanAnnotations); - const linksFromEnv = get10(fiberRefs3, currentTracerSpanLinks); - const links = linksFromEnv._tag === "Some" ? options.links !== undefined ? [...toReadonlyArray(linksFromEnv.value), ...options.links ?? []] : toReadonlyArray(linksFromEnv.value) : options.links ?? empty(); - span2 = tracer2.span(name, parent, options.context ?? empty3(), links, timingEnabled ? clock2.unsafeCurrentTimeNanos() : bigint03, options.kind ?? "internal", options); - if (annotationsFromEnv._tag === "Some") { - forEach3(annotationsFromEnv.value, (value, key) => span2.attribute(key, value)); - } - if (options.attributes !== undefined) { - Object.entries(options.attributes).forEach(([k, v]) => span2.attribute(k, v)); - } - } - if (typeof options.captureStackTrace === "function") { - spanToTrace.set(span2, options.captureStackTrace); - } - return span2; -}; -var makeSpan = (name, options) => { - options = addSpanStackTrace(options); - return withFiberRuntime((fiber) => succeed(unsafeMakeSpan(fiber, name, options))); -}; -var spanAnnotations = /* @__PURE__ */ fiberRefGet(currentTracerSpanAnnotations); -var spanLinks = /* @__PURE__ */ fiberRefGet(currentTracerSpanLinks); -var endSpan = (span2, exit2, clock2, timingEnabled) => sync(() => { - if (span2.status._tag === "Ended") { - return; - } - if (exitIsFailure(exit2) && spanToTrace.has(span2)) { - span2.attribute("code.stacktrace", spanToTrace.get(span2)()); - } - span2.end(timingEnabled ? clock2.unsafeCurrentTimeNanos() : bigint03, exit2); -}); -var useSpan = (name, ...args) => { - const options = addSpanStackTrace(args.length === 1 ? undefined : args[0]); - const evaluate = args[args.length - 1]; - return withFiberRuntime((fiber) => { - const span2 = unsafeMakeSpan(fiber, name, options); - const timingEnabled = fiber.getFiberRef(currentTracerTimingEnabled); - const clock2 = get3(fiber.getFiberRef(currentServices), clockTag); - return onExit(evaluate(span2), (exit2) => endSpan(span2, exit2, clock2, timingEnabled)); - }); -}; -var withParentSpan = /* @__PURE__ */ dual(2, (self, span2) => provideService(self, spanTag, span2)); -var withSpan = function() { - const dataFirst = typeof arguments[0] !== "string"; - const name = dataFirst ? arguments[1] : arguments[0]; - const options = addSpanStackTrace(dataFirst ? arguments[2] : arguments[1]); - if (dataFirst) { - const self = arguments[0]; - return useSpan(name, options, (span2) => withParentSpan(self, span2)); - } - return (self) => useSpan(name, options, (span2) => withParentSpan(self, span2)); -}; -var functionWithSpan = (options) => function() { - let captureStackTrace = options.captureStackTrace ?? false; - if (options.captureStackTrace !== false) { - const limit = Error.stackTraceLimit; - Error.stackTraceLimit = 2; - const error = new Error; - Error.stackTraceLimit = limit; - let cache = false; - captureStackTrace = () => { - if (cache !== false) { - return cache; - } - if (error.stack) { - const stack = error.stack.trim().split(` -`); - cache = stack.slice(2).join(` -`).trim(); - return cache; - } - }; - } - return suspend(() => { - const opts = typeof options.options === "function" ? options.options.apply(null, arguments) : options.options; - return withSpan(suspend(() => internalCall(() => options.body.apply(this, arguments))), opts.name, { - ...opts, - captureStackTrace - }); - }); -}; -var fromNullable2 = (value) => value == null ? fail2(new NoSuchElementException) : succeed(value); -var optionFromOptional = (self) => catchAll(map9(self, some2), (error) => isNoSuchElementException(error) ? succeedNone : fail2(error)); - -// node_modules/effect/dist/esm/internal/executionStrategy.js -var OP_SEQUENTIAL2 = "Sequential"; -var OP_PARALLEL2 = "Parallel"; -var OP_PARALLEL_N = "ParallelN"; -var sequential2 = { - _tag: OP_SEQUENTIAL2 -}; -var parallel2 = { - _tag: OP_PARALLEL2 -}; -var parallelN = (parallelism) => ({ - _tag: OP_PARALLEL_N, - parallelism -}); -var isSequential = (self) => self._tag === OP_SEQUENTIAL2; -var isParallel = (self) => self._tag === OP_PARALLEL2; - -// node_modules/effect/dist/esm/ExecutionStrategy.js -var sequential3 = sequential2; -var parallel3 = parallel2; -var parallelN2 = parallelN; - -// node_modules/effect/dist/esm/FiberRefsPatch.js -var diff6 = diff5; -var patch7 = patch6; - -// node_modules/effect/dist/esm/internal/fiberStatus.js -var FiberStatusSymbolKey = "effect/FiberStatus"; -var FiberStatusTypeId = /* @__PURE__ */ Symbol.for(FiberStatusSymbolKey); -var OP_DONE = "Done"; -var OP_RUNNING = "Running"; -var OP_SUSPENDED = "Suspended"; -var DoneHash = /* @__PURE__ */ string(`${FiberStatusSymbolKey}-${OP_DONE}`); - -class Done { - [FiberStatusTypeId] = FiberStatusTypeId; - _tag = OP_DONE; - [symbol]() { - return DoneHash; - } - [symbol2](that) { - return isFiberStatus(that) && that._tag === OP_DONE; - } -} - -class Running { - runtimeFlags; - [FiberStatusTypeId] = FiberStatusTypeId; - _tag = OP_RUNNING; - constructor(runtimeFlags2) { - this.runtimeFlags = runtimeFlags2; - } - [symbol]() { - return pipe(hash(FiberStatusSymbolKey), combine(hash(this._tag)), combine(hash(this.runtimeFlags)), cached(this)); - } - [symbol2](that) { - return isFiberStatus(that) && that._tag === OP_RUNNING && this.runtimeFlags === that.runtimeFlags; - } -} - -class Suspended { - runtimeFlags; - blockingOn; - [FiberStatusTypeId] = FiberStatusTypeId; - _tag = OP_SUSPENDED; - constructor(runtimeFlags2, blockingOn) { - this.runtimeFlags = runtimeFlags2; - this.blockingOn = blockingOn; - } - [symbol]() { - return pipe(hash(FiberStatusSymbolKey), combine(hash(this._tag)), combine(hash(this.runtimeFlags)), combine(hash(this.blockingOn)), cached(this)); - } - [symbol2](that) { - return isFiberStatus(that) && that._tag === OP_SUSPENDED && this.runtimeFlags === that.runtimeFlags && equals(this.blockingOn, that.blockingOn); - } -} -var done3 = /* @__PURE__ */ new Done; -var running = (runtimeFlags2) => new Running(runtimeFlags2); -var suspended = (runtimeFlags2, blockingOn) => new Suspended(runtimeFlags2, blockingOn); -var isFiberStatus = (u) => hasProperty(u, FiberStatusTypeId); -var isDone = (self) => self._tag === OP_DONE; - -// node_modules/effect/dist/esm/FiberStatus.js -var done4 = done3; -var running2 = running; -var suspended2 = suspended; -var isDone2 = isDone; - -// node_modules/effect/dist/esm/Micro.js -var TypeId14 = /* @__PURE__ */ Symbol.for("effect/Micro"); -var MicroExitTypeId = /* @__PURE__ */ Symbol.for("effect/Micro/MicroExit"); -var MicroCauseTypeId = /* @__PURE__ */ Symbol.for("effect/Micro/MicroCause"); -var microCauseVariance = { - _E: identity -}; - -class MicroCauseImpl extends globalThis.Error { - _tag; - traces; - [MicroCauseTypeId]; - constructor(_tag, originalError, traces) { - const causeName = `MicroCause.${_tag}`; - let name; - let message; - let stack; - if (originalError instanceof globalThis.Error) { - name = `(${causeName}) ${originalError.name}`; - message = originalError.message; - const messageLines = message.split(` -`).length; - stack = originalError.stack ? `(${causeName}) ${originalError.stack.split(` -`).slice(0, messageLines + 3).join(` -`)}` : `${name}: ${message}`; - } else { - name = causeName; - message = toStringUnknown(originalError, 0); - stack = `${name}: ${message}`; - } - if (traces.length > 0) { - stack += ` - ${traces.join(` - `)}`; - } - super(message); - this._tag = _tag; - this.traces = traces; - this[MicroCauseTypeId] = microCauseVariance; - this.name = name; - this.stack = stack; - } - pipe() { - return pipeArguments(this, arguments); - } - toString() { - return this.stack; - } - [NodeInspectSymbol]() { - return this.stack; - } -} -class Die extends MicroCauseImpl { - defect; - constructor(defect, traces = []) { - super("Die", defect, traces); - this.defect = defect; - } -} -var causeDie = (defect, traces = []) => new Die(defect, traces); - -class Interrupt extends MicroCauseImpl { - constructor(traces = []) { - super("Interrupt", "interrupted", traces); - } -} -var causeInterrupt = (traces = []) => new Interrupt(traces); -var causeIsInterrupt = (self) => self._tag === "Interrupt"; -var MicroFiberTypeId = /* @__PURE__ */ Symbol.for("effect/Micro/MicroFiber"); -var fiberVariance = { - _A: identity, - _E: identity -}; - -class MicroFiberImpl { - context; - interruptible; - [MicroFiberTypeId]; - _stack = []; - _observers = []; - _exit; - _children; - currentOpCount = 0; - constructor(context2, interruptible3 = true) { - this.context = context2; - this.interruptible = interruptible3; - this[MicroFiberTypeId] = fiberVariance; - } - getRef(ref) { - return unsafeGetReference(this.context, ref); - } - addObserver(cb) { - if (this._exit) { - cb(this._exit); - return constVoid; - } - this._observers.push(cb); - return () => { - const index = this._observers.indexOf(cb); - if (index >= 0) { - this._observers.splice(index, 1); - } - }; - } - _interrupted = false; - unsafeInterrupt() { - if (this._exit) { - return; - } - this._interrupted = true; - if (this.interruptible) { - this.evaluate(exitInterrupt2); - } - } - unsafePoll() { - return this._exit; - } - evaluate(effect) { - if (this._exit) { - return; - } else if (this._yielded !== undefined) { - const yielded = this._yielded; - this._yielded = undefined; - yielded(); - } - const exit2 = this.runLoop(effect); - if (exit2 === Yield) { - return; - } - const interruptChildren = fiberMiddleware.interruptChildren && fiberMiddleware.interruptChildren(this); - if (interruptChildren !== undefined) { - return this.evaluate(flatMap8(interruptChildren, () => exit2)); - } - this._exit = exit2; - for (let i = 0;i < this._observers.length; i++) { - this._observers[i](exit2); - } - this._observers.length = 0; - } - runLoop(effect) { - let yielding = false; - let current = effect; - this.currentOpCount = 0; - try { - while (true) { - this.currentOpCount++; - if (!yielding && this.getRef(CurrentScheduler).shouldYield(this)) { - yielding = true; - const prev = current; - current = flatMap8(yieldNow2, () => prev); - } - current = current[evaluate](this); - if (current === Yield) { - const yielded = this._yielded; - if (MicroExitTypeId in yielded) { - this._yielded = undefined; - return yielded; - } - return Yield; - } - } - } catch (error) { - if (!hasProperty(current, evaluate)) { - return exitDie2(`MicroFiber.runLoop: Not a valid effect: ${String(current)}`); - } - return exitDie2(error); - } - } - getCont(symbol3) { - while (true) { - const op = this._stack.pop(); - if (!op) - return; - const cont = op[ensureCont] && op[ensureCont](this); - if (cont) - return { - [symbol3]: cont - }; - if (op[symbol3]) - return op; - } - } - _yielded = undefined; - yieldWith(value) { - this._yielded = value; - return Yield; - } - children() { - return this._children ??= new Set; - } -} -var fiberMiddleware = /* @__PURE__ */ globalValue("effect/Micro/fiberMiddleware", () => ({ - interruptChildren: undefined -})); -var identifier = /* @__PURE__ */ Symbol.for("effect/Micro/identifier"); -var args = /* @__PURE__ */ Symbol.for("effect/Micro/args"); -var evaluate = /* @__PURE__ */ Symbol.for("effect/Micro/evaluate"); -var successCont = /* @__PURE__ */ Symbol.for("effect/Micro/successCont"); -var failureCont = /* @__PURE__ */ Symbol.for("effect/Micro/failureCont"); -var ensureCont = /* @__PURE__ */ Symbol.for("effect/Micro/ensureCont"); -var Yield = /* @__PURE__ */ Symbol.for("effect/Micro/Yield"); -var microVariance = { - _A: identity, - _E: identity, - _R: identity -}; -var MicroProto = { - ...EffectPrototype2, - _op: "Micro", - [TypeId14]: microVariance, - pipe() { - return pipeArguments(this, arguments); - }, - [Symbol.iterator]() { - return new SingleShotGen(new YieldWrap(this)); - }, - toJSON() { - return { - _id: "Micro", - op: this[identifier], - ...args in this ? { - args: this[args] - } : undefined - }; - }, - toString() { - return format(this); - }, - [NodeInspectSymbol]() { - return format(this); - } -}; -function defaultEvaluate(_fiber) { - return exitDie2(`Micro.evaluate: Not implemented`); -} -var makePrimitiveProto = (options) => ({ - ...MicroProto, - [identifier]: options.op, - [evaluate]: options.eval ?? defaultEvaluate, - [successCont]: options.contA, - [failureCont]: options.contE, - [ensureCont]: options.ensure -}); -var makePrimitive = (options) => { - const Proto2 = makePrimitiveProto(options); - return function() { - const self = Object.create(Proto2); - self[args] = options.single === false ? arguments : arguments[0]; - return self; - }; -}; -var makeExit = (options) => { - const Proto2 = { - ...makePrimitiveProto(options), - [MicroExitTypeId]: MicroExitTypeId, - _tag: options.op, - get [options.prop]() { - return this[args]; - }, - toJSON() { - return { - _id: "MicroExit", - _tag: options.op, - [options.prop]: this[args] - }; - }, - [symbol2](that) { - return isMicroExit(that) && that._tag === options.op && equals(this[args], that[args]); - }, - [symbol]() { - return cached(this, combine(string(options.op))(hash(this[args]))); - } - }; - return function(value) { - const self = Object.create(Proto2); - self[args] = value; - self[successCont] = undefined; - self[failureCont] = undefined; - self[ensureCont] = undefined; - return self; - }; -}; -var succeed3 = /* @__PURE__ */ makeExit({ - op: "Success", - prop: "value", - eval(fiber) { - const cont = fiber.getCont(successCont); - return cont ? cont[successCont](this[args], fiber) : fiber.yieldWith(this); - } -}); -var failCause3 = /* @__PURE__ */ makeExit({ - op: "Failure", - prop: "cause", - eval(fiber) { - let cont = fiber.getCont(failureCont); - while (causeIsInterrupt(this[args]) && cont && fiber.interruptible) { - cont = fiber.getCont(failureCont); - } - return cont ? cont[failureCont](this[args], fiber) : fiber.yieldWith(this); - } -}); -var yieldNowWith = /* @__PURE__ */ makePrimitive({ - op: "Yield", - eval(fiber) { - let resumed = false; - fiber.getRef(CurrentScheduler).scheduleTask(() => { - if (resumed) - return; - fiber.evaluate(exitVoid2); - }, this[args] ?? 0); - return fiber.yieldWith(() => { - resumed = true; - }); - } -}); -var yieldNow2 = /* @__PURE__ */ yieldNowWith(0); -var void_2 = /* @__PURE__ */ succeed3(undefined); -var withMicroFiber = /* @__PURE__ */ makePrimitive({ - op: "WithMicroFiber", - eval(fiber) { - return this[args](fiber); - } -}); -var flatMap8 = /* @__PURE__ */ dual(2, (self, f) => { - const onSuccess = Object.create(OnSuccessProto); - onSuccess[args] = self; - onSuccess[successCont] = f; - return onSuccess; -}); -var OnSuccessProto = /* @__PURE__ */ makePrimitiveProto({ - op: "OnSuccess", - eval(fiber) { - fiber._stack.push(this); - return this[args]; - } -}); -var isMicroExit = (u) => hasProperty(u, MicroExitTypeId); -var exitSucceed2 = succeed3; -var exitFailCause2 = failCause3; -var exitInterrupt2 = /* @__PURE__ */ exitFailCause2(/* @__PURE__ */ causeInterrupt()); -var exitDie2 = (defect) => exitFailCause2(causeDie(defect)); -var exitVoid2 = /* @__PURE__ */ exitSucceed2(undefined); -var setImmediate = "setImmediate" in globalThis ? globalThis.setImmediate : (f) => setTimeout(f, 0); - -class MicroSchedulerDefault { - tasks = []; - running = false; - scheduleTask(task, _priority) { - this.tasks.push(task); - if (!this.running) { - this.running = true; - setImmediate(this.afterScheduled); - } - } - afterScheduled = () => { - this.running = false; - this.runTasks(); - }; - runTasks() { - const tasks = this.tasks; - this.tasks = []; - for (let i = 0, len = tasks.length;i < len; i++) { - tasks[i](); - } - } - shouldYield(fiber) { - return fiber.currentOpCount >= fiber.getRef(MaxOpsBeforeYield); - } - flush() { - while (this.tasks.length > 0) { - this.runTasks(); - } - } -} -var updateContext = /* @__PURE__ */ dual(2, (self, f) => withMicroFiber((fiber) => { - const prev = fiber.context; - fiber.context = f(prev); - return onExit2(self, () => { - fiber.context = prev; - return void_2; - }); -})); -var provideContext2 = /* @__PURE__ */ dual(2, (self, provided) => updateContext(self, merge3(provided))); -class MaxOpsBeforeYield extends (/* @__PURE__ */ Reference2()("effect/Micro/currentMaxOpsBeforeYield", { - defaultValue: () => 2048 -})) { -} -class CurrentScheduler extends (/* @__PURE__ */ Reference2()("effect/Micro/currentScheduler", { - defaultValue: () => new MicroSchedulerDefault -})) { -} -var matchCauseEffect2 = /* @__PURE__ */ dual(2, (self, options) => { - const primitive = Object.create(OnSuccessAndFailureProto); - primitive[args] = self; - primitive[successCont] = options.onSuccess; - primitive[failureCont] = options.onFailure; - return primitive; -}); -var OnSuccessAndFailureProto = /* @__PURE__ */ makePrimitiveProto({ - op: "OnSuccessAndFailure", - eval(fiber) { - fiber._stack.push(this); - return this[args]; - } -}); -var onExit2 = /* @__PURE__ */ dual(2, (self, f) => uninterruptibleMask2((restore) => matchCauseEffect2(restore(self), { - onFailure: (cause2) => flatMap8(f(exitFailCause2(cause2)), () => failCause3(cause2)), - onSuccess: (a) => flatMap8(f(exitSucceed2(a)), () => succeed3(a)) -}))); -var setInterruptible = /* @__PURE__ */ makePrimitive({ - op: "SetInterruptible", - ensure(fiber) { - fiber.interruptible = this[args]; - if (fiber._interrupted && fiber.interruptible) { - return () => exitInterrupt2; - } - } -}); -var interruptible3 = (self) => withMicroFiber((fiber) => { - if (fiber.interruptible) - return self; - fiber.interruptible = true; - fiber._stack.push(setInterruptible(false)); - if (fiber._interrupted) - return exitInterrupt2; - return self; -}); -var uninterruptibleMask2 = (f) => withMicroFiber((fiber) => { - if (!fiber.interruptible) - return f(identity); - fiber.interruptible = false; - fiber._stack.push(setInterruptible(true)); - return f(interruptible3); -}); -var runFork = (effect, options) => { - const fiber = new MicroFiberImpl(CurrentScheduler.context(options?.scheduler ?? new MicroSchedulerDefault)); - fiber.evaluate(effect); - if (options?.signal) { - if (options.signal.aborted) { - fiber.unsafeInterrupt(); - } else { - const abort = () => fiber.unsafeInterrupt(); - options.signal.addEventListener("abort", abort, { - once: true - }); - fiber.addObserver(() => options.signal.removeEventListener("abort", abort)); - } - } - return fiber; -}; - -// node_modules/effect/dist/esm/Scheduler.js -class SchedulerRunner { - scheduleDrain; - running = false; - tasks = /* @__PURE__ */ new PriorityBuckets; - constructor(scheduleDrain) { - this.scheduleDrain = scheduleDrain; - } - starveInternal = (depth) => { - const tasks = this.tasks.buckets; - this.tasks.buckets = []; - for (const [_, toRun] of tasks) { - for (let i = 0;i < toRun.length; i++) { - toRun[i](); - } - } - if (this.tasks.buckets.length === 0) { - this.running = false; - } else { - this.starve(depth); - } - }; - starve(depth = 0) { - this.scheduleDrain(depth, this.starveInternal); - } - scheduleTask(task, priority) { - this.tasks.scheduleTask(task, priority); - if (!this.running) { - this.running = true; - this.starve(); - } - } - static cached(scheduleDrain) { - const fallback = new SchedulerRunner(scheduleDrain); - const runners = new WeakMap; - return (fiber) => { - if (fiber === undefined) { - return fallback; - } - let runner = runners.get(fiber); - if (runner === undefined) { - runner = new SchedulerRunner(scheduleDrain); - runners.set(fiber, runner); - } - return runner; - }; - } -} - -class PriorityBuckets { - buckets = []; - scheduleTask(task, priority) { - const length2 = this.buckets.length; - let bucket = undefined; - let index = 0; - for (;index < length2; index++) { - if (this.buckets[index][0] <= priority) { - bucket = this.buckets[index]; - } else { - break; - } - } - if (bucket && bucket[0] === priority) { - bucket[1].push(task); - } else if (index === length2) { - this.buckets.push([priority, [task]]); - } else { - this.buckets.splice(index, 0, [priority, [task]]); - } - } -} - -class MixedScheduler { - maxNextTickBeforeTimer; - getRunner = /* @__PURE__ */ SchedulerRunner.cached((depth, drain) => { - if (depth >= this.maxNextTickBeforeTimer) { - setTimeout(() => drain(0), 0); - } else { - Promise.resolve(undefined).then(() => drain(depth + 1)); - } - }); - constructor(maxNextTickBeforeTimer) { - this.maxNextTickBeforeTimer = maxNextTickBeforeTimer; - } - shouldYield(fiber) { - return fiber.currentOpCount > fiber.getFiberRef(currentMaxOpsBeforeYield) ? fiber.getFiberRef(currentSchedulingPriority) : false; - } - scheduleTask(task, priority, fiber) { - this.getRunner(fiber).scheduleTask(task, priority); - } -} -var defaultScheduler = /* @__PURE__ */ globalValue(/* @__PURE__ */ Symbol.for("effect/Scheduler/defaultScheduler"), () => new MixedScheduler(2048)); - -class SyncScheduler { - tasks = /* @__PURE__ */ new PriorityBuckets; - deferred = false; - scheduleTask(task, priority, fiber) { - if (this.deferred) { - defaultScheduler.scheduleTask(task, priority, fiber); - } else { - this.tasks.scheduleTask(task, priority); - } - } - shouldYield(fiber) { - return fiber.currentOpCount > fiber.getFiberRef(currentMaxOpsBeforeYield) ? fiber.getFiberRef(currentSchedulingPriority) : false; - } - flush() { - while (this.tasks.buckets.length > 0) { - const tasks = this.tasks.buckets; - this.tasks.buckets = []; - for (const [_, toRun] of tasks) { - for (let i = 0;i < toRun.length; i++) { - toRun[i](); - } - } - } - this.deferred = true; - } -} -var currentScheduler = /* @__PURE__ */ globalValue(/* @__PURE__ */ Symbol.for("effect/FiberRef/currentScheduler"), () => fiberRefUnsafeMake(defaultScheduler)); -var withScheduler = /* @__PURE__ */ dual(2, (self, scheduler) => fiberRefLocally(self, currentScheduler, scheduler)); - -// node_modules/effect/dist/esm/internal/completedRequestMap.js -var currentRequestMap = /* @__PURE__ */ globalValue(/* @__PURE__ */ Symbol.for("effect/FiberRef/currentRequestMap"), () => fiberRefUnsafeMake(new Map)); - -// node_modules/effect/dist/esm/internal/concurrency.js -var match9 = (concurrency, sequential4, unbounded2, bounded) => { - switch (concurrency) { - case undefined: - return sequential4(); - case "unbounded": - return unbounded2(); - case "inherit": - return fiberRefGetWith(currentConcurrency, (concurrency2) => concurrency2 === "unbounded" ? unbounded2() : concurrency2 > 1 ? bounded(concurrency2) : sequential4()); - default: - return concurrency > 1 ? bounded(concurrency) : sequential4(); - } -}; -var matchSimple = (concurrency, sequential4, concurrent) => { - switch (concurrency) { - case undefined: - return sequential4(); - case "unbounded": - return concurrent(); - case "inherit": - return fiberRefGetWith(currentConcurrency, (concurrency2) => concurrency2 === "unbounded" || concurrency2 > 1 ? concurrent() : sequential4()); - default: - return concurrency > 1 ? concurrent() : sequential4(); - } -}; - -// node_modules/effect/dist/esm/internal/fiberMessage.js -var OP_INTERRUPT_SIGNAL = "InterruptSignal"; -var OP_STATEFUL = "Stateful"; -var OP_RESUME = "Resume"; -var OP_YIELD_NOW = "YieldNow"; -var interruptSignal = (cause2) => ({ - _tag: OP_INTERRUPT_SIGNAL, - cause: cause2 -}); -var stateful = (onFiber) => ({ - _tag: OP_STATEFUL, - onFiber -}); -var resume = (effect) => ({ - _tag: OP_RESUME, - effect -}); -var yieldNow3 = () => ({ - _tag: OP_YIELD_NOW -}); - -// node_modules/effect/dist/esm/internal/fiberScope.js -var FiberScopeSymbolKey = "effect/FiberScope"; -var FiberScopeTypeId = /* @__PURE__ */ Symbol.for(FiberScopeSymbolKey); - -class Global { - [FiberScopeTypeId] = FiberScopeTypeId; - fiberId = none4; - roots = /* @__PURE__ */ new Set; - add(_runtimeFlags, child) { - this.roots.add(child); - child.addObserver(() => { - this.roots.delete(child); - }); - } -} - -class Local { - fiberId; - parent; - [FiberScopeTypeId] = FiberScopeTypeId; - constructor(fiberId2, parent) { - this.fiberId = fiberId2; - this.parent = parent; - } - add(_runtimeFlags, child) { - this.parent.tell(stateful((parentFiber) => { - parentFiber.addChild(child); - child.addObserver(() => { - parentFiber.removeChild(child); - }); - })); - } -} -var unsafeMake6 = (fiber) => { - return new Local(fiber.id(), fiber); -}; -var globalScope = /* @__PURE__ */ globalValue(/* @__PURE__ */ Symbol.for("effect/FiberScope/Global"), () => new Global); - -// node_modules/effect/dist/esm/internal/fiber.js -var FiberSymbolKey = "effect/Fiber"; -var FiberTypeId = /* @__PURE__ */ Symbol.for(FiberSymbolKey); -var fiberVariance2 = { - _E: (_) => _, - _A: (_) => _ -}; -var fiberProto = { - [FiberTypeId]: fiberVariance2, - pipe() { - return pipeArguments(this, arguments); - } -}; -var RuntimeFiberSymbolKey = "effect/Fiber"; -var RuntimeFiberTypeId = /* @__PURE__ */ Symbol.for(RuntimeFiberSymbolKey); -var isRuntimeFiber = (self) => (RuntimeFiberTypeId in self); -var _await2 = (self) => self.await; -var inheritAll = (self) => self.inheritAll; -var interruptAllAs = /* @__PURE__ */ dual(2, /* @__PURE__ */ fnUntraced(function* (fibers, fiberId2) { - for (const fiber of fibers) { - if (isRuntimeFiber(fiber)) { - fiber.unsafeInterruptAsFork(fiberId2); - continue; - } - yield* fiber.interruptAsFork(fiberId2); - } - for (const fiber of fibers) { - if (isRuntimeFiber(fiber) && fiber.unsafePoll()) { - continue; - } - yield* fiber.await; - } -})); -var interruptAsFork = /* @__PURE__ */ dual(2, (self, fiberId2) => self.interruptAsFork(fiberId2)); -var join2 = (self) => zipLeft(flatten5(self.await), self.inheritAll); -var _never = { - ...CommitPrototype, - commit() { - return join2(this); - }, - ...fiberProto, - id: () => none4, - await: never, - children: /* @__PURE__ */ succeed([]), - inheritAll: never, - poll: /* @__PURE__ */ succeed(/* @__PURE__ */ none2()), - interruptAsFork: () => never -}; -var currentFiberURI = "effect/FiberCurrent"; - -// node_modules/effect/dist/esm/internal/logger.js -var LoggerSymbolKey = "effect/Logger"; -var LoggerTypeId = /* @__PURE__ */ Symbol.for(LoggerSymbolKey); -var loggerVariance = { - _Message: (_) => _, - _Output: (_) => _ -}; -var makeLogger = (log2) => ({ - [LoggerTypeId]: loggerVariance, - log: log2, - pipe() { - return pipeArguments(this, arguments); - } -}); -var none7 = { - [LoggerTypeId]: loggerVariance, - log: constVoid, - pipe() { - return pipeArguments(this, arguments); - } -}; -var textOnly = /^[^\s"=]*$/; -var format4 = (quoteValue, whitespace) => ({ - annotations: annotations2, - cause: cause2, - date, - fiberId: fiberId2, - logLevel, - message, - spans -}) => { - const formatValue = (value) => value.match(textOnly) ? value : quoteValue(value); - const format5 = (label, value) => `${formatLabel(label)}=${formatValue(value)}`; - const append4 = (label, value) => " " + format5(label, value); - let out = format5("timestamp", date.toISOString()); - out += append4("level", logLevel.label); - out += append4("fiber", threadName(fiberId2)); - const messages = ensure(message); - for (let i = 0;i < messages.length; i++) { - out += append4("message", toStringUnknown(messages[i], whitespace)); - } - if (!isEmptyType(cause2)) { - out += append4("cause", pretty(cause2, { - renderErrorCause: true - })); - } - for (const span2 of spans) { - out += " " + render(date.getTime())(span2); - } - for (const [label, value] of annotations2) { - out += append4(label, toStringUnknown(value, whitespace)); - } - return out; -}; -var escapeDoubleQuotes = (s) => `"${s.replace(/\\([\s\S])|(")/g, "\\$1$2")}"`; -var stringLogger = /* @__PURE__ */ makeLogger(/* @__PURE__ */ format4(escapeDoubleQuotes)); -var colors = { - bold: "1", - red: "31", - green: "32", - yellow: "33", - blue: "34", - cyan: "36", - white: "37", - gray: "90", - black: "30", - bgBrightRed: "101" -}; -var logLevelColors = { - None: [], - All: [], - Trace: [colors.gray], - Debug: [colors.blue], - Info: [colors.green], - Warning: [colors.yellow], - Error: [colors.red], - Fatal: [colors.bgBrightRed, colors.black] -}; -var hasProcessStdout = typeof process === "object" && process !== null && typeof process.stdout === "object" && process.stdout !== null; -var processStdoutIsTTY = hasProcessStdout && process.stdout.isTTY === true; -var hasProcessStdoutOrDeno = hasProcessStdout || "Deno" in globalThis; - -// node_modules/effect/dist/esm/internal/metric/boundaries.js -var MetricBoundariesSymbolKey = "effect/MetricBoundaries"; -var MetricBoundariesTypeId = /* @__PURE__ */ Symbol.for(MetricBoundariesSymbolKey); - -class MetricBoundariesImpl { - values; - [MetricBoundariesTypeId] = MetricBoundariesTypeId; - constructor(values3) { - this.values = values3; - this._hash = pipe(string(MetricBoundariesSymbolKey), combine(array2(this.values))); - } - _hash; - [symbol]() { - return this._hash; - } - [symbol2](u) { - return isMetricBoundaries(u) && equals(this.values, u.values); - } - pipe() { - return pipeArguments(this, arguments); - } -} -var isMetricBoundaries = (u) => hasProperty(u, MetricBoundariesTypeId); -var fromIterable8 = (iterable) => { - const values3 = pipe(iterable, appendAll(of2(Number.POSITIVE_INFINITY)), dedupe); - return new MetricBoundariesImpl(values3); -}; -var exponential = (options) => pipe(makeBy(options.count - 1, (i) => options.start * Math.pow(options.factor, i)), unsafeFromArray, fromIterable8); - -// node_modules/effect/dist/esm/internal/metric/keyType.js -var MetricKeyTypeSymbolKey = "effect/MetricKeyType"; -var MetricKeyTypeTypeId = /* @__PURE__ */ Symbol.for(MetricKeyTypeSymbolKey); -var CounterKeyTypeSymbolKey = "effect/MetricKeyType/Counter"; -var CounterKeyTypeTypeId = /* @__PURE__ */ Symbol.for(CounterKeyTypeSymbolKey); -var FrequencyKeyTypeSymbolKey = "effect/MetricKeyType/Frequency"; -var FrequencyKeyTypeTypeId = /* @__PURE__ */ Symbol.for(FrequencyKeyTypeSymbolKey); -var GaugeKeyTypeSymbolKey = "effect/MetricKeyType/Gauge"; -var GaugeKeyTypeTypeId = /* @__PURE__ */ Symbol.for(GaugeKeyTypeSymbolKey); -var HistogramKeyTypeSymbolKey = "effect/MetricKeyType/Histogram"; -var HistogramKeyTypeTypeId = /* @__PURE__ */ Symbol.for(HistogramKeyTypeSymbolKey); -var SummaryKeyTypeSymbolKey = "effect/MetricKeyType/Summary"; -var SummaryKeyTypeTypeId = /* @__PURE__ */ Symbol.for(SummaryKeyTypeSymbolKey); -var metricKeyTypeVariance = { - _In: (_) => _, - _Out: (_) => _ -}; - -class CounterKeyType { - incremental; - bigint; - [MetricKeyTypeTypeId] = metricKeyTypeVariance; - [CounterKeyTypeTypeId] = CounterKeyTypeTypeId; - constructor(incremental, bigint2) { - this.incremental = incremental; - this.bigint = bigint2; - this._hash = string(CounterKeyTypeSymbolKey); - } - _hash; - [symbol]() { - return this._hash; - } - [symbol2](that) { - return isCounterKey(that); - } - pipe() { - return pipeArguments(this, arguments); - } -} -class HistogramKeyType { - boundaries; - [MetricKeyTypeTypeId] = metricKeyTypeVariance; - [HistogramKeyTypeTypeId] = HistogramKeyTypeTypeId; - constructor(boundaries) { - this.boundaries = boundaries; - this._hash = pipe(string(HistogramKeyTypeSymbolKey), combine(hash(this.boundaries))); - } - _hash; - [symbol]() { - return this._hash; - } - [symbol2](that) { - return isHistogramKey(that) && equals(this.boundaries, that.boundaries); - } - pipe() { - return pipeArguments(this, arguments); - } -} -var counter = (options) => new CounterKeyType(options?.incremental ?? false, options?.bigint ?? false); -var histogram = (boundaries) => { - return new HistogramKeyType(boundaries); -}; -var isCounterKey = (u) => hasProperty(u, CounterKeyTypeTypeId); -var isFrequencyKey = (u) => hasProperty(u, FrequencyKeyTypeTypeId); -var isGaugeKey = (u) => hasProperty(u, GaugeKeyTypeTypeId); -var isHistogramKey = (u) => hasProperty(u, HistogramKeyTypeTypeId); -var isSummaryKey = (u) => hasProperty(u, SummaryKeyTypeTypeId); - -// node_modules/effect/dist/esm/internal/metric/key.js -var MetricKeySymbolKey = "effect/MetricKey"; -var MetricKeyTypeId = /* @__PURE__ */ Symbol.for(MetricKeySymbolKey); -var metricKeyVariance = { - _Type: (_) => _ -}; -var arrayEquivilence = /* @__PURE__ */ getEquivalence3(equals); - -class MetricKeyImpl { - name; - keyType; - description; - tags; - [MetricKeyTypeId] = metricKeyVariance; - constructor(name, keyType, description, tags = []) { - this.name = name; - this.keyType = keyType; - this.description = description; - this.tags = tags; - this._hash = pipe(string(this.name + this.description), combine(hash(this.keyType)), combine(array2(this.tags))); - } - _hash; - [symbol]() { - return this._hash; - } - [symbol2](u) { - return isMetricKey(u) && this.name === u.name && equals(this.keyType, u.keyType) && equals(this.description, u.description) && arrayEquivilence(this.tags, u.tags); - } - pipe() { - return pipeArguments(this, arguments); - } -} -var isMetricKey = (u) => hasProperty(u, MetricKeyTypeId); -var counter2 = (name, options) => new MetricKeyImpl(name, counter(options), fromNullable(options?.description)); -var histogram2 = (name, boundaries, description) => new MetricKeyImpl(name, histogram(boundaries), fromNullable(description)); -var taggedWithLabels = /* @__PURE__ */ dual(2, (self, extraTags) => extraTags.length === 0 ? self : new MetricKeyImpl(self.name, self.keyType, self.description, union(self.tags, extraTags))); - -// node_modules/effect/dist/esm/internal/metric/state.js -var MetricStateSymbolKey = "effect/MetricState"; -var MetricStateTypeId = /* @__PURE__ */ Symbol.for(MetricStateSymbolKey); -var CounterStateSymbolKey = "effect/MetricState/Counter"; -var CounterStateTypeId = /* @__PURE__ */ Symbol.for(CounterStateSymbolKey); -var FrequencyStateSymbolKey = "effect/MetricState/Frequency"; -var FrequencyStateTypeId = /* @__PURE__ */ Symbol.for(FrequencyStateSymbolKey); -var GaugeStateSymbolKey = "effect/MetricState/Gauge"; -var GaugeStateTypeId = /* @__PURE__ */ Symbol.for(GaugeStateSymbolKey); -var HistogramStateSymbolKey = "effect/MetricState/Histogram"; -var HistogramStateTypeId = /* @__PURE__ */ Symbol.for(HistogramStateSymbolKey); -var SummaryStateSymbolKey = "effect/MetricState/Summary"; -var SummaryStateTypeId = /* @__PURE__ */ Symbol.for(SummaryStateSymbolKey); -var metricStateVariance = { - _A: (_) => _ -}; - -class CounterState { - count; - [MetricStateTypeId] = metricStateVariance; - [CounterStateTypeId] = CounterStateTypeId; - constructor(count) { - this.count = count; - } - [symbol]() { - return pipe(hash(CounterStateSymbolKey), combine(hash(this.count)), cached(this)); - } - [symbol2](that) { - return isCounterState(that) && this.count === that.count; - } - pipe() { - return pipeArguments(this, arguments); - } -} -var arrayEquals = /* @__PURE__ */ getEquivalence3(equals); - -class FrequencyState { - occurrences; - [MetricStateTypeId] = metricStateVariance; - [FrequencyStateTypeId] = FrequencyStateTypeId; - constructor(occurrences) { - this.occurrences = occurrences; - } - _hash; - [symbol]() { - return pipe(string(FrequencyStateSymbolKey), combine(array2(fromIterable(this.occurrences.entries()))), cached(this)); - } - [symbol2](that) { - return isFrequencyState(that) && arrayEquals(fromIterable(this.occurrences.entries()), fromIterable(that.occurrences.entries())); - } - pipe() { - return pipeArguments(this, arguments); - } -} - -class GaugeState { - value; - [MetricStateTypeId] = metricStateVariance; - [GaugeStateTypeId] = GaugeStateTypeId; - constructor(value) { - this.value = value; - } - [symbol]() { - return pipe(hash(GaugeStateSymbolKey), combine(hash(this.value)), cached(this)); - } - [symbol2](u) { - return isGaugeState(u) && this.value === u.value; - } - pipe() { - return pipeArguments(this, arguments); - } -} - -class HistogramState { - buckets; - count; - min; - max; - sum; - [MetricStateTypeId] = metricStateVariance; - [HistogramStateTypeId] = HistogramStateTypeId; - constructor(buckets, count, min2, max2, sum) { - this.buckets = buckets; - this.count = count; - this.min = min2; - this.max = max2; - this.sum = sum; - } - [symbol]() { - return pipe(hash(HistogramStateSymbolKey), combine(hash(this.buckets)), combine(hash(this.count)), combine(hash(this.min)), combine(hash(this.max)), combine(hash(this.sum)), cached(this)); - } - [symbol2](that) { - return isHistogramState(that) && equals(this.buckets, that.buckets) && this.count === that.count && this.min === that.min && this.max === that.max && this.sum === that.sum; - } - pipe() { - return pipeArguments(this, arguments); - } -} - -class SummaryState { - error; - quantiles; - count; - min; - max; - sum; - [MetricStateTypeId] = metricStateVariance; - [SummaryStateTypeId] = SummaryStateTypeId; - constructor(error, quantiles, count, min2, max2, sum) { - this.error = error; - this.quantiles = quantiles; - this.count = count; - this.min = min2; - this.max = max2; - this.sum = sum; - } - [symbol]() { - return pipe(hash(SummaryStateSymbolKey), combine(hash(this.error)), combine(hash(this.quantiles)), combine(hash(this.count)), combine(hash(this.min)), combine(hash(this.max)), combine(hash(this.sum)), cached(this)); - } - [symbol2](that) { - return isSummaryState(that) && this.error === that.error && equals(this.quantiles, that.quantiles) && this.count === that.count && this.min === that.min && this.max === that.max && this.sum === that.sum; - } - pipe() { - return pipeArguments(this, arguments); - } -} -var counter3 = (count) => new CounterState(count); -var frequency2 = (occurrences) => { - return new FrequencyState(occurrences); -}; -var gauge2 = (count) => new GaugeState(count); -var histogram3 = (options) => new HistogramState(options.buckets, options.count, options.min, options.max, options.sum); -var summary2 = (options) => new SummaryState(options.error, options.quantiles, options.count, options.min, options.max, options.sum); -var isCounterState = (u) => hasProperty(u, CounterStateTypeId); -var isFrequencyState = (u) => hasProperty(u, FrequencyStateTypeId); -var isGaugeState = (u) => hasProperty(u, GaugeStateTypeId); -var isHistogramState = (u) => hasProperty(u, HistogramStateTypeId); -var isSummaryState = (u) => hasProperty(u, SummaryStateTypeId); - -// node_modules/effect/dist/esm/internal/metric/hook.js -var MetricHookSymbolKey = "effect/MetricHook"; -var MetricHookTypeId = /* @__PURE__ */ Symbol.for(MetricHookSymbolKey); -var metricHookVariance = { - _In: (_) => _, - _Out: (_) => _ -}; -var make30 = (options) => ({ - [MetricHookTypeId]: metricHookVariance, - pipe() { - return pipeArguments(this, arguments); - }, - ...options -}); -var bigint04 = /* @__PURE__ */ BigInt(0); -var counter4 = (key) => { - let sum = key.keyType.bigint ? bigint04 : 0; - const canUpdate = key.keyType.incremental ? key.keyType.bigint ? (value) => value >= bigint04 : (value) => value >= 0 : (_value) => true; - const update4 = (value) => { - if (canUpdate(value)) { - sum = sum + value; - } - }; - return make30({ - get: () => counter3(sum), - update: update4, - modify: update4 - }); -}; -var frequency3 = (key) => { - const values3 = new Map; - for (const word of key.keyType.preregisteredWords) { - values3.set(word, 0); - } - const update4 = (word) => { - const slotCount = values3.get(word) ?? 0; - values3.set(word, slotCount + 1); - }; - return make30({ - get: () => frequency2(values3), - update: update4, - modify: update4 - }); -}; -var gauge3 = (_key, startAt) => { - let value = startAt; - return make30({ - get: () => gauge2(value), - update: (v) => { - value = v; - }, - modify: (v) => { - value = value + v; - } - }); -}; -var histogram4 = (key) => { - const bounds = key.keyType.boundaries.values; - const size5 = bounds.length; - const values3 = new Uint32Array(size5 + 1); - const boundaries = new Float64Array(size5); - let count = 0; - let sum = 0; - let min2 = Number.MAX_VALUE; - let max2 = Number.MIN_VALUE; - pipe(bounds, sort(Order), map3((n, i) => { - boundaries[i] = n; - })); - const update4 = (value) => { - let from = 0; - let to = size5; - while (from !== to) { - const mid = Math.floor(from + (to - from) / 2); - const boundary = boundaries[mid]; - if (value <= boundary) { - to = mid; - } else { - from = mid; - } - if (to === from + 1) { - if (value <= boundaries[from]) { - to = from; - } else { - from = to; - } - } - } - values3[from] = values3[from] + 1; - count = count + 1; - sum = sum + value; - if (value < min2) { - min2 = value; - } - if (value > max2) { - max2 = value; - } - }; - const getBuckets = () => { - const builder = allocate(size5); - let cumulated = 0; - for (let i = 0;i < size5; i++) { - const boundary = boundaries[i]; - const value = values3[i]; - cumulated = cumulated + value; - builder[i] = [boundary, cumulated]; - } - return builder; - }; - return make30({ - get: () => histogram3({ - buckets: getBuckets(), - count, - min: min2, - max: max2, - sum - }), - update: update4, - modify: update4 - }); -}; -var summary3 = (key) => { - const { - error, - maxAge, - maxSize, - quantiles - } = key.keyType; - const sortedQuantiles = pipe(quantiles, sort(Order)); - const values3 = allocate(maxSize); - let head4 = 0; - let count = 0; - let sum = 0; - let min2 = 0; - let max2 = 0; - const snapshot = (now) => { - const builder = []; - let i = 0; - while (i !== maxSize - 1) { - const item = values3[i]; - if (item != null) { - const [t, v] = item; - const age = millis(now - t); - if (greaterThanOrEqualTo3(age, zero2) && lessThanOrEqualTo3(age, maxAge)) { - builder.push(v); - } - } - i = i + 1; - } - return calculateQuantiles(error, sortedQuantiles, sort(builder, Order)); - }; - const observe = (value, timestamp) => { - if (maxSize > 0) { - head4 = head4 + 1; - const target = head4 % maxSize; - values3[target] = [timestamp, value]; - } - min2 = count === 0 ? value : Math.min(min2, value); - max2 = count === 0 ? value : Math.max(max2, value); - count = count + 1; - sum = sum + value; - }; - return make30({ - get: () => summary2({ - error, - quantiles: snapshot(Date.now()), - count, - min: min2, - max: max2, - sum - }), - update: ([value, timestamp]) => observe(value, timestamp), - modify: ([value, timestamp]) => observe(value, timestamp) - }); -}; -var calculateQuantiles = (error, sortedQuantiles, sortedSamples) => { - const sampleCount = sortedSamples.length; - if (!isNonEmptyReadonlyArray(sortedQuantiles)) { - return empty(); - } - const head4 = sortedQuantiles[0]; - const tail = sortedQuantiles.slice(1); - const resolvedHead = resolveQuantile(error, sampleCount, none2(), 0, head4, sortedSamples); - const resolved = of(resolvedHead); - tail.forEach((quantile) => { - resolved.push(resolveQuantile(error, sampleCount, resolvedHead.value, resolvedHead.consumed, quantile, resolvedHead.rest)); - }); - return map3(resolved, (rq) => [rq.quantile, rq.value]); -}; -var resolveQuantile = (error, sampleCount, current, consumed, quantile, rest) => { - let error_1 = error; - let sampleCount_1 = sampleCount; - let current_1 = current; - let consumed_1 = consumed; - let quantile_1 = quantile; - let rest_1 = rest; - let error_2 = error; - let sampleCount_2 = sampleCount; - let current_2 = current; - let consumed_2 = consumed; - let quantile_2 = quantile; - let rest_2 = rest; - while (true) { - if (!isNonEmptyReadonlyArray(rest_1)) { - return { - quantile: quantile_1, - value: none2(), - consumed: consumed_1, - rest: [] - }; - } - if (quantile_1 === 1) { - return { - quantile: quantile_1, - value: some2(lastNonEmpty(rest_1)), - consumed: consumed_1 + rest_1.length, - rest: [] - }; - } - const headValue = headNonEmpty(rest_1); - const sameHead = span(rest_1, (n) => n === headValue); - const desired = quantile_1 * sampleCount_1; - const allowedError = error_1 / 2 * desired; - const candConsumed = consumed_1 + sameHead[0].length; - const candError = Math.abs(candConsumed - desired); - if (candConsumed < desired - allowedError) { - error_2 = error_1; - sampleCount_2 = sampleCount_1; - current_2 = head(rest_1); - consumed_2 = candConsumed; - quantile_2 = quantile_1; - rest_2 = sameHead[1]; - error_1 = error_2; - sampleCount_1 = sampleCount_2; - current_1 = current_2; - consumed_1 = consumed_2; - quantile_1 = quantile_2; - rest_1 = rest_2; - continue; - } - if (candConsumed > desired + allowedError) { - const valueToReturn = isNone2(current_1) ? some2(headValue) : current_1; - return { - quantile: quantile_1, - value: valueToReturn, - consumed: consumed_1, - rest: rest_1 - }; - } - switch (current_1._tag) { - case "None": { - error_2 = error_1; - sampleCount_2 = sampleCount_1; - current_2 = head(rest_1); - consumed_2 = candConsumed; - quantile_2 = quantile_1; - rest_2 = sameHead[1]; - error_1 = error_2; - sampleCount_1 = sampleCount_2; - current_1 = current_2; - consumed_1 = consumed_2; - quantile_1 = quantile_2; - rest_1 = rest_2; - continue; - } - case "Some": { - const prevError = Math.abs(desired - current_1.value); - if (candError < prevError) { - error_2 = error_1; - sampleCount_2 = sampleCount_1; - current_2 = head(rest_1); - consumed_2 = candConsumed; - quantile_2 = quantile_1; - rest_2 = sameHead[1]; - error_1 = error_2; - sampleCount_1 = sampleCount_2; - current_1 = current_2; - consumed_1 = consumed_2; - quantile_1 = quantile_2; - rest_1 = rest_2; - continue; - } - return { - quantile: quantile_1, - value: some2(current_1.value), - consumed: consumed_1, - rest: rest_1 - }; - } - } - } - throw new Error("BUG: MetricHook.resolveQuantiles - please report an issue at https://github.com/Effect-TS/effect/issues"); -}; - -// node_modules/effect/dist/esm/internal/metric/pair.js -var MetricPairSymbolKey = "effect/MetricPair"; -var MetricPairTypeId = /* @__PURE__ */ Symbol.for(MetricPairSymbolKey); -var metricPairVariance = { - _Type: (_) => _ -}; -var unsafeMake7 = (metricKey, metricState) => { - return { - [MetricPairTypeId]: metricPairVariance, - metricKey, - metricState, - pipe() { - return pipeArguments(this, arguments); - } - }; -}; - -// node_modules/effect/dist/esm/internal/metric/registry.js -var MetricRegistrySymbolKey = "effect/MetricRegistry"; -var MetricRegistryTypeId = /* @__PURE__ */ Symbol.for(MetricRegistrySymbolKey); - -class MetricRegistryImpl { - [MetricRegistryTypeId] = MetricRegistryTypeId; - map = /* @__PURE__ */ empty17(); - snapshot() { - const result = []; - for (const [key, hook] of this.map) { - result.push(unsafeMake7(key, hook.get())); - } - return result; - } - get(key) { - const hook = pipe(this.map, get8(key), getOrUndefined); - if (hook == null) { - if (isCounterKey(key.keyType)) { - return this.getCounter(key); - } - if (isGaugeKey(key.keyType)) { - return this.getGauge(key); - } - if (isFrequencyKey(key.keyType)) { - return this.getFrequency(key); - } - if (isHistogramKey(key.keyType)) { - return this.getHistogram(key); - } - if (isSummaryKey(key.keyType)) { - return this.getSummary(key); - } - throw new Error("BUG: MetricRegistry.get - unknown MetricKeyType - please report an issue at https://github.com/Effect-TS/effect/issues"); - } else { - return hook; - } - } - getCounter(key) { - let value = pipe(this.map, get8(key), getOrUndefined); - if (value == null) { - const counter5 = counter4(key); - if (!pipe(this.map, has4(key))) { - pipe(this.map, set4(key, counter5)); - } - value = counter5; - } - return value; - } - getFrequency(key) { - let value = pipe(this.map, get8(key), getOrUndefined); - if (value == null) { - const frequency4 = frequency3(key); - if (!pipe(this.map, has4(key))) { - pipe(this.map, set4(key, frequency4)); - } - value = frequency4; - } - return value; - } - getGauge(key) { - let value = pipe(this.map, get8(key), getOrUndefined); - if (value == null) { - const gauge4 = gauge3(key, key.keyType.bigint ? BigInt(0) : 0); - if (!pipe(this.map, has4(key))) { - pipe(this.map, set4(key, gauge4)); - } - value = gauge4; - } - return value; - } - getHistogram(key) { - let value = pipe(this.map, get8(key), getOrUndefined); - if (value == null) { - const histogram5 = histogram4(key); - if (!pipe(this.map, has4(key))) { - pipe(this.map, set4(key, histogram5)); - } - value = histogram5; - } - return value; - } - getSummary(key) { - let value = pipe(this.map, get8(key), getOrUndefined); - if (value == null) { - const summary4 = summary3(key); - if (!pipe(this.map, has4(key))) { - pipe(this.map, set4(key, summary4)); - } - value = summary4; - } - return value; - } -} -var make31 = () => { - return new MetricRegistryImpl; -}; - -// node_modules/effect/dist/esm/internal/metric.js -var MetricSymbolKey = "effect/Metric"; -var MetricTypeId = /* @__PURE__ */ Symbol.for(MetricSymbolKey); -var metricVariance = { - _Type: (_) => _, - _In: (_) => _, - _Out: (_) => _ -}; -var globalMetricRegistry = /* @__PURE__ */ globalValue(/* @__PURE__ */ Symbol.for("effect/Metric/globalMetricRegistry"), () => make31()); -var make32 = function(keyType, unsafeUpdate, unsafeValue, unsafeModify) { - const metric = Object.assign((effect) => tap(effect, (a) => update4(metric, a)), { - [MetricTypeId]: metricVariance, - keyType, - unsafeUpdate, - unsafeValue, - unsafeModify, - register() { - this.unsafeValue([]); - return this; - }, - pipe() { - return pipeArguments(this, arguments); - } - }); - return metric; -}; -var counter5 = (name, options) => fromMetricKey(counter2(name, options)); -var fromMetricKey = (key) => { - let untaggedHook; - const hookCache = new WeakMap; - const hook = (extraTags) => { - if (extraTags.length === 0) { - if (untaggedHook !== undefined) { - return untaggedHook; - } - untaggedHook = globalMetricRegistry.get(key); - return untaggedHook; - } - let hook2 = hookCache.get(extraTags); - if (hook2 !== undefined) { - return hook2; - } - hook2 = globalMetricRegistry.get(taggedWithLabels(key, extraTags)); - hookCache.set(extraTags, hook2); - return hook2; - }; - return make32(key.keyType, (input, extraTags) => hook(extraTags).update(input), (extraTags) => hook(extraTags).get(), (input, extraTags) => hook(extraTags).modify(input)); -}; -var histogram5 = (name, boundaries, description) => fromMetricKey(histogram2(name, boundaries, description)); -var tagged = /* @__PURE__ */ dual(3, (self, key, value) => taggedWithLabels2(self, [make29(key, value)])); -var taggedWithLabels2 = /* @__PURE__ */ dual(2, (self, extraTags) => { - return make32(self.keyType, (input, extraTags1) => self.unsafeUpdate(input, union(extraTags, extraTags1)), (extraTags1) => self.unsafeValue(union(extraTags, extraTags1)), (input, extraTags1) => self.unsafeModify(input, union(extraTags, extraTags1))); -}); -var update4 = /* @__PURE__ */ dual(2, (self, input) => fiberRefGetWith(currentMetricLabels, (tags) => sync(() => self.unsafeUpdate(input, tags)))); - -// node_modules/effect/dist/esm/internal/request.js -var RequestSymbolKey = "effect/Request"; -var RequestTypeId = /* @__PURE__ */ Symbol.for(RequestSymbolKey); -var requestVariance = { - _E: (_) => _, - _A: (_) => _ -}; -var RequestPrototype = { - ...StructuralPrototype, - [RequestTypeId]: requestVariance -}; -var isRequest = (u) => hasProperty(u, RequestTypeId); -var Class2 = /* @__PURE__ */ function() { - function Class3(args2) { - if (args2) { - Object.assign(this, args2); - } - } - Class3.prototype = RequestPrototype; - return Class3; -}(); -var complete = /* @__PURE__ */ dual(2, (self, result) => fiberRefGetWith(currentRequestMap, (map10) => sync(() => { - if (map10.has(self)) { - const entry = map10.get(self); - if (!entry.state.completed) { - entry.state.completed = true; - deferredUnsafeDone(entry.result, result); - } - } -}))); -class Listeners { - count = 0; - observers = /* @__PURE__ */ new Set; - interrupted = false; - addObserver(f) { - this.observers.add(f); - } - removeObserver(f) { - this.observers.delete(f); - } - increment() { - this.count++; - this.observers.forEach((f) => f(this.count)); - } - decrement() { - this.count--; - this.observers.forEach((f) => f(this.count)); - } -} - -// node_modules/effect/dist/esm/internal/redBlackTree/iterator.js -var Direction = { - Forward: 0, - Backward: 1 << 0 -}; - -class RedBlackTreeIterator { - self; - stack; - direction; - count = 0; - constructor(self, stack, direction) { - this.self = self; - this.stack = stack; - this.direction = direction; - } - clone() { - return new RedBlackTreeIterator(this.self, this.stack.slice(), this.direction); - } - reversed() { - return new RedBlackTreeIterator(this.self, this.stack.slice(), this.direction === Direction.Forward ? Direction.Backward : Direction.Forward); - } - next() { - const entry = this.entry; - this.count++; - if (this.direction === Direction.Forward) { - this.moveNext(); - } else { - this.movePrev(); - } - switch (entry._tag) { - case "None": { - return { - done: true, - value: this.count - }; - } - case "Some": { - return { - done: false, - value: entry.value - }; - } - } - } - get key() { - if (this.stack.length > 0) { - return some2(this.stack[this.stack.length - 1].key); - } - return none2(); - } - get value() { - if (this.stack.length > 0) { - return some2(this.stack[this.stack.length - 1].value); - } - return none2(); - } - get entry() { - return map2(last(this.stack), (node) => [node.key, node.value]); - } - get index() { - let idx = 0; - const stack = this.stack; - if (stack.length === 0) { - const r = this.self._root; - if (r != null) { - return r.count; - } - return 0; - } else if (stack[stack.length - 1].left != null) { - idx = stack[stack.length - 1].left.count; - } - for (let s = stack.length - 2;s >= 0; --s) { - if (stack[s + 1] === stack[s].right) { - ++idx; - if (stack[s].left != null) { - idx += stack[s].left.count; - } - } - } - return idx; - } - moveNext() { - const stack = this.stack; - if (stack.length === 0) { - return; - } - let n = stack[stack.length - 1]; - if (n.right != null) { - n = n.right; - while (n != null) { - stack.push(n); - n = n.left; - } - } else { - stack.pop(); - while (stack.length > 0 && stack[stack.length - 1].right === n) { - n = stack[stack.length - 1]; - stack.pop(); - } - } - } - get hasNext() { - const stack = this.stack; - if (stack.length === 0) { - return false; - } - if (stack[stack.length - 1].right != null) { - return true; - } - for (let s = stack.length - 1;s > 0; --s) { - if (stack[s - 1].left === stack[s]) { - return true; - } - } - return false; - } - movePrev() { - const stack = this.stack; - if (stack.length === 0) { - return; - } - let n = stack[stack.length - 1]; - if (n != null && n.left != null) { - n = n.left; - while (n != null) { - stack.push(n); - n = n.right; - } - } else { - stack.pop(); - while (stack.length > 0 && stack[stack.length - 1].left === n) { - n = stack[stack.length - 1]; - stack.pop(); - } - } - } - get hasPrev() { - const stack = this.stack; - if (stack.length === 0) { - return false; - } - if (stack[stack.length - 1].left != null) { - return true; - } - for (let s = stack.length - 1;s > 0; --s) { - if (stack[s - 1].right === stack[s]) { - return true; - } - } - return false; - } -} - -// node_modules/effect/dist/esm/internal/redBlackTree/node.js -var Color = { - Red: 0, - Black: 1 << 0 -}; -var repaint = ({ - count, - key, - left: left3, - right: right3, - value -}, color) => ({ - color, - key, - value, - left: left3, - right: right3, - count -}); -var recount = (node) => { - node.count = 1 + (node.left?.count ?? 0) + (node.right?.count ?? 0); -}; - -// node_modules/effect/dist/esm/internal/redBlackTree.js -var RedBlackTreeSymbolKey = "effect/RedBlackTree"; -var RedBlackTreeTypeId = /* @__PURE__ */ Symbol.for(RedBlackTreeSymbolKey); -var redBlackTreeVariance = { - _Key: (_) => _, - _Value: (_) => _ -}; -var RedBlackTreeProto = { - [RedBlackTreeTypeId]: redBlackTreeVariance, - [symbol]() { - let hash2 = hash(RedBlackTreeSymbolKey); - for (const item of this) { - hash2 ^= pipe(hash(item[0]), combine(hash(item[1]))); - } - return cached(this, hash2); - }, - [symbol2](that) { - if (isRedBlackTree(that)) { - if ((this._root?.count ?? 0) !== (that._root?.count ?? 0)) { - return false; - } - const entries2 = Array.from(that); - return Array.from(this).every((itemSelf, i) => { - const itemThat = entries2[i]; - return equals(itemSelf[0], itemThat[0]) && equals(itemSelf[1], itemThat[1]); - }); - } - return false; - }, - [Symbol.iterator]() { - const stack = []; - let n = this._root; - while (n != null) { - stack.push(n); - n = n.left; - } - return new RedBlackTreeIterator(this, stack, Direction.Forward); - }, - toString() { - return format(this.toJSON()); - }, - toJSON() { - return { - _id: "RedBlackTree", - values: Array.from(this).map(toJSON) - }; - }, - [NodeInspectSymbol]() { - return this.toJSON(); - }, - pipe() { - return pipeArguments(this, arguments); - } -}; -var makeImpl3 = (ord, root) => { - const tree = Object.create(RedBlackTreeProto); - tree._ord = ord; - tree._root = root; - return tree; -}; -var isRedBlackTree = (u) => hasProperty(u, RedBlackTreeTypeId); -var empty23 = (ord) => makeImpl3(ord, undefined); -var fromIterable9 = /* @__PURE__ */ dual(2, (entries2, ord) => { - let tree = empty23(ord); - for (const [key, value] of entries2) { - tree = insert(tree, key, value); - } - return tree; -}); -var findFirst5 = /* @__PURE__ */ dual(2, (self, key) => { - const cmp = self._ord; - let node = self._root; - while (node !== undefined) { - const d = cmp(key, node.key); - if (equals(key, node.key)) { - return some2(node.value); - } - if (d <= 0) { - node = node.left; - } else { - node = node.right; - } - } - return none2(); -}); -var has5 = /* @__PURE__ */ dual(2, (self, key) => isSome2(findFirst5(self, key))); -var insert = /* @__PURE__ */ dual(3, (self, key, value) => { - const cmp = self._ord; - let n = self._root; - const n_stack = []; - const d_stack = []; - while (n != null) { - const d = cmp(key, n.key); - n_stack.push(n); - d_stack.push(d); - if (d <= 0) { - n = n.left; - } else { - n = n.right; - } - } - n_stack.push({ - color: Color.Red, - key, - value, - left: undefined, - right: undefined, - count: 1 - }); - for (let s = n_stack.length - 2;s >= 0; --s) { - const n2 = n_stack[s]; - if (d_stack[s] <= 0) { - n_stack[s] = { - color: n2.color, - key: n2.key, - value: n2.value, - left: n_stack[s + 1], - right: n2.right, - count: n2.count + 1 - }; - } else { - n_stack[s] = { - color: n2.color, - key: n2.key, - value: n2.value, - left: n2.left, - right: n_stack[s + 1], - count: n2.count + 1 - }; - } - } - for (let s = n_stack.length - 1;s > 1; --s) { - const p = n_stack[s - 1]; - const n3 = n_stack[s]; - if (p.color === Color.Black || n3.color === Color.Black) { - break; - } - const pp = n_stack[s - 2]; - if (pp.left === p) { - if (p.left === n3) { - const y = pp.right; - if (y && y.color === Color.Red) { - p.color = Color.Black; - pp.right = repaint(y, Color.Black); - pp.color = Color.Red; - s -= 1; - } else { - pp.color = Color.Red; - pp.left = p.right; - p.color = Color.Black; - p.right = pp; - n_stack[s - 2] = p; - n_stack[s - 1] = n3; - recount(pp); - recount(p); - if (s >= 3) { - const ppp = n_stack[s - 3]; - if (ppp.left === pp) { - ppp.left = p; - } else { - ppp.right = p; - } - } - break; - } - } else { - const y = pp.right; - if (y && y.color === Color.Red) { - p.color = Color.Black; - pp.right = repaint(y, Color.Black); - pp.color = Color.Red; - s -= 1; - } else { - p.right = n3.left; - pp.color = Color.Red; - pp.left = n3.right; - n3.color = Color.Black; - n3.left = p; - n3.right = pp; - n_stack[s - 2] = n3; - n_stack[s - 1] = p; - recount(pp); - recount(p); - recount(n3); - if (s >= 3) { - const ppp = n_stack[s - 3]; - if (ppp.left === pp) { - ppp.left = n3; - } else { - ppp.right = n3; - } - } - break; - } - } - } else { - if (p.right === n3) { - const y = pp.left; - if (y && y.color === Color.Red) { - p.color = Color.Black; - pp.left = repaint(y, Color.Black); - pp.color = Color.Red; - s -= 1; - } else { - pp.color = Color.Red; - pp.right = p.left; - p.color = Color.Black; - p.left = pp; - n_stack[s - 2] = p; - n_stack[s - 1] = n3; - recount(pp); - recount(p); - if (s >= 3) { - const ppp = n_stack[s - 3]; - if (ppp.right === pp) { - ppp.right = p; - } else { - ppp.left = p; - } - } - break; - } - } else { - const y = pp.left; - if (y && y.color === Color.Red) { - p.color = Color.Black; - pp.left = repaint(y, Color.Black); - pp.color = Color.Red; - s -= 1; - } else { - p.left = n3.right; - pp.color = Color.Red; - pp.right = n3.left; - n3.color = Color.Black; - n3.right = p; - n3.left = pp; - n_stack[s - 2] = n3; - n_stack[s - 1] = p; - recount(pp); - recount(p); - recount(n3); - if (s >= 3) { - const ppp = n_stack[s - 3]; - if (ppp.right === pp) { - ppp.right = n3; - } else { - ppp.left = n3; - } - } - break; - } - } - } - } - n_stack[0].color = Color.Black; - return makeImpl3(self._ord, n_stack[0]); -}); -var keysForward = (self) => keys3(self, Direction.Forward); -var keys3 = (self, direction) => { - const begin = self[Symbol.iterator](); - let count = 0; - return { - [Symbol.iterator]: () => keys3(self, direction), - next: () => { - count++; - const entry = begin.key; - if (direction === Direction.Forward) { - begin.moveNext(); - } else { - begin.movePrev(); - } - switch (entry._tag) { - case "None": { - return { - done: true, - value: count - }; - } - case "Some": { - return { - done: false, - value: entry.value - }; - } - } - } - }; -}; - -// node_modules/effect/dist/esm/RedBlackTree.js -var fromIterable10 = fromIterable9; -var has6 = has5; -var keys4 = keysForward; - -// node_modules/effect/dist/esm/SortedSet.js -var TypeId15 = /* @__PURE__ */ Symbol.for("effect/SortedSet"); -var SortedSetProto = { - [TypeId15]: { - _A: (_) => _ - }, - [symbol]() { - return pipe(hash(this.keyTree), combine(hash(TypeId15)), cached(this)); - }, - [symbol2](that) { - return isSortedSet(that) && equals(this.keyTree, that.keyTree); - }, - [Symbol.iterator]() { - return keys4(this.keyTree); - }, - toString() { - return format(this.toJSON()); - }, - toJSON() { - return { - _id: "SortedSet", - values: Array.from(this).map(toJSON) - }; - }, - [NodeInspectSymbol]() { - return this.toJSON(); - }, - pipe() { - return pipeArguments(this, arguments); - } -}; -var fromTree = (keyTree) => { - const a = Object.create(SortedSetProto); - a.keyTree = keyTree; - return a; -}; -var isSortedSet = (u) => hasProperty(u, TypeId15); -var fromIterable11 = /* @__PURE__ */ dual(2, (iterable, ord) => fromTree(fromIterable10(Array.from(iterable).map((k) => [k, true]), ord))); -var every5 = /* @__PURE__ */ dual(2, (self, predicate) => { - for (const value of self) { - if (!predicate(value)) { - return false; - } - } - return true; -}); -var has7 = /* @__PURE__ */ dual(2, (self, value) => has6(self.keyTree, value)); -var isSubset2 = /* @__PURE__ */ dual(2, (self, that) => every5(self, (a) => has7(that, a))); -var values3 = (self) => keys4(self.keyTree); -var getEquivalence6 = () => (a, b) => isSubset2(a, b) && isSubset2(b, a); - -// node_modules/effect/dist/esm/internal/supervisor.js -var SupervisorSymbolKey = "effect/Supervisor"; -var SupervisorTypeId = /* @__PURE__ */ Symbol.for(SupervisorSymbolKey); -var supervisorVariance = { - _T: (_) => _ -}; - -class ProxySupervisor { - underlying; - value0; - [SupervisorTypeId] = supervisorVariance; - constructor(underlying, value0) { - this.underlying = underlying; - this.value0 = value0; - } - get value() { - return this.value0; - } - onStart(context2, effect, parent, fiber) { - this.underlying.onStart(context2, effect, parent, fiber); - } - onEnd(value, fiber) { - this.underlying.onEnd(value, fiber); - } - onEffect(fiber, effect) { - this.underlying.onEffect(fiber, effect); - } - onSuspend(fiber) { - this.underlying.onSuspend(fiber); - } - onResume(fiber) { - this.underlying.onResume(fiber); - } - map(f) { - return new ProxySupervisor(this, pipe(this.value, map9(f))); - } - zip(right3) { - return new Zip(this, right3); - } -} - -class Zip { - left; - right; - _tag = "Zip"; - [SupervisorTypeId] = supervisorVariance; - constructor(left3, right3) { - this.left = left3; - this.right = right3; - } - get value() { - return zip2(this.left.value, this.right.value); - } - onStart(context2, effect, parent, fiber) { - this.left.onStart(context2, effect, parent, fiber); - this.right.onStart(context2, effect, parent, fiber); - } - onEnd(value, fiber) { - this.left.onEnd(value, fiber); - this.right.onEnd(value, fiber); - } - onEffect(fiber, effect) { - this.left.onEffect(fiber, effect); - this.right.onEffect(fiber, effect); - } - onSuspend(fiber) { - this.left.onSuspend(fiber); - this.right.onSuspend(fiber); - } - onResume(fiber) { - this.left.onResume(fiber); - this.right.onResume(fiber); - } - map(f) { - return new ProxySupervisor(this, pipe(this.value, map9(f))); - } - zip(right3) { - return new Zip(this, right3); - } -} -var isZip = (self) => hasProperty(self, SupervisorTypeId) && isTagged(self, "Zip"); - -class Track { - [SupervisorTypeId] = supervisorVariance; - fibers = /* @__PURE__ */ new Set; - get value() { - return sync(() => Array.from(this.fibers)); - } - onStart(_context, _effect, _parent, fiber) { - this.fibers.add(fiber); - } - onEnd(_value, fiber) { - this.fibers.delete(fiber); - } - onEffect(_fiber, _effect) {} - onSuspend(_fiber) {} - onResume(_fiber) {} - map(f) { - return new ProxySupervisor(this, pipe(this.value, map9(f))); - } - zip(right3) { - return new Zip(this, right3); - } - onRun(execution, _fiber) { - return execution(); - } -} - -class Const { - effect; - [SupervisorTypeId] = supervisorVariance; - constructor(effect) { - this.effect = effect; - } - get value() { - return this.effect; - } - onStart(_context, _effect, _parent, _fiber) {} - onEnd(_value, _fiber) {} - onEffect(_fiber, _effect) {} - onSuspend(_fiber) {} - onResume(_fiber) {} - map(f) { - return new ProxySupervisor(this, pipe(this.value, map9(f))); - } - zip(right3) { - return new Zip(this, right3); - } - onRun(execution, _fiber) { - return execution(); - } -} -var unsafeTrack = () => { - return new Track; -}; -var track = /* @__PURE__ */ sync(unsafeTrack); -var fromEffect = (effect) => { - return new Const(effect); -}; -var none8 = /* @__PURE__ */ globalValue("effect/Supervisor/none", () => fromEffect(void_)); - -// node_modules/effect/dist/esm/Differ.js -var make34 = make15; - -// node_modules/effect/dist/esm/internal/supervisor/patch.js -var OP_EMPTY3 = "Empty"; -var OP_ADD_SUPERVISOR = "AddSupervisor"; -var OP_REMOVE_SUPERVISOR = "RemoveSupervisor"; -var OP_AND_THEN2 = "AndThen"; -var empty25 = { - _tag: OP_EMPTY3 -}; -var combine8 = (self, that) => { - return { - _tag: OP_AND_THEN2, - first: self, - second: that - }; -}; -var patch8 = (self, supervisor) => { - return patchLoop(supervisor, of2(self)); -}; -var patchLoop = (_supervisor, _patches) => { - let supervisor = _supervisor; - let patches = _patches; - while (isNonEmpty2(patches)) { - const head4 = headNonEmpty2(patches); - switch (head4._tag) { - case OP_EMPTY3: { - patches = tailNonEmpty2(patches); - break; - } - case OP_ADD_SUPERVISOR: { - supervisor = supervisor.zip(head4.supervisor); - patches = tailNonEmpty2(patches); - break; - } - case OP_REMOVE_SUPERVISOR: { - supervisor = removeSupervisor(supervisor, head4.supervisor); - patches = tailNonEmpty2(patches); - break; - } - case OP_AND_THEN2: { - patches = prepend2(head4.first)(prepend2(head4.second)(tailNonEmpty2(patches))); - break; - } - } - } - return supervisor; -}; -var removeSupervisor = (self, that) => { - if (equals(self, that)) { - return none8; - } else { - if (isZip(self)) { - return removeSupervisor(self.left, that).zip(removeSupervisor(self.right, that)); - } else { - return self; - } - } -}; -var toSet2 = (self) => { - if (equals(self, none8)) { - return empty7(); - } else { - if (isZip(self)) { - return pipe(toSet2(self.left), union3(toSet2(self.right))); - } else { - return make11(self); - } - } -}; -var diff7 = (oldValue, newValue) => { - if (equals(oldValue, newValue)) { - return empty25; - } - const oldSupervisors = toSet2(oldValue); - const newSupervisors = toSet2(newValue); - const added = pipe(newSupervisors, difference3(oldSupervisors), reduce4(empty25, (patch9, supervisor) => combine8(patch9, { - _tag: OP_ADD_SUPERVISOR, - supervisor - }))); - const removed = pipe(oldSupervisors, difference3(newSupervisors), reduce4(empty25, (patch9, supervisor) => combine8(patch9, { - _tag: OP_REMOVE_SUPERVISOR, - supervisor - }))); - return combine8(added, removed); -}; -var differ2 = /* @__PURE__ */ make34({ - empty: empty25, - patch: patch8, - combine: combine8, - diff: diff7 -}); - -// node_modules/effect/dist/esm/internal/fiberRuntime.js -var fiberStarted = /* @__PURE__ */ counter5("effect_fiber_started", { - incremental: true -}); -var fiberActive = /* @__PURE__ */ counter5("effect_fiber_active"); -var fiberSuccesses = /* @__PURE__ */ counter5("effect_fiber_successes", { - incremental: true -}); -var fiberFailures = /* @__PURE__ */ counter5("effect_fiber_failures", { - incremental: true -}); -var fiberLifetimes = /* @__PURE__ */ tagged(/* @__PURE__ */ histogram5("effect_fiber_lifetimes", /* @__PURE__ */ exponential({ - start: 0.5, - factor: 2, - count: 35 -})), "time_unit", "milliseconds"); -var EvaluationSignalContinue = "Continue"; -var EvaluationSignalDone = "Done"; -var EvaluationSignalYieldNow = "Yield"; -var runtimeFiberVariance = { - _E: (_) => _, - _A: (_) => _ -}; -var absurd = (_) => { - throw new Error(`BUG: FiberRuntime - ${toStringUnknown(_)} - please report an issue at https://github.com/Effect-TS/effect/issues`); -}; -var YieldedOp = /* @__PURE__ */ Symbol.for("effect/internal/fiberRuntime/YieldedOp"); -var yieldedOpChannel = /* @__PURE__ */ globalValue("effect/internal/fiberRuntime/yieldedOpChannel", () => ({ - currentOp: null -})); -var contOpSuccess = { - [OP_ON_SUCCESS]: (_, cont, value) => { - return internalCall(() => cont.effect_instruction_i1(value)); - }, - ["OnStep"]: (_, _cont, value) => { - return exitSucceed(exitSucceed(value)); - }, - [OP_ON_SUCCESS_AND_FAILURE]: (_, cont, value) => { - return internalCall(() => cont.effect_instruction_i2(value)); - }, - [OP_REVERT_FLAGS]: (self, cont, value) => { - self.patchRuntimeFlags(self.currentRuntimeFlags, cont.patch); - if (interruptible(self.currentRuntimeFlags) && self.isInterrupted()) { - return exitFailCause(self.getInterruptedCause()); - } else { - return exitSucceed(value); - } - }, - [OP_WHILE]: (self, cont, value) => { - internalCall(() => cont.effect_instruction_i2(value)); - if (internalCall(() => cont.effect_instruction_i0())) { - self.pushStack(cont); - return internalCall(() => cont.effect_instruction_i1()); - } else { - return void_; - } - }, - [OP_ITERATOR]: (self, cont, value) => { - while (true) { - const state = internalCall(() => cont.effect_instruction_i0.next(value)); - if (state.done) { - return exitSucceed(state.value); - } - const primitive = yieldWrapGet(state.value); - if (!exitIsExit(primitive)) { - self.pushStack(cont); - return primitive; - } else if (primitive._tag === "Failure") { - return primitive; - } - value = primitive.value; - } - } -}; -var drainQueueWhileRunningTable = { - [OP_INTERRUPT_SIGNAL]: (self, runtimeFlags2, cur, message) => { - self.processNewInterruptSignal(message.cause); - return interruptible(runtimeFlags2) ? exitFailCause(message.cause) : cur; - }, - [OP_RESUME]: (_self, _runtimeFlags, _cur, _message) => { - throw new Error("It is illegal to have multiple concurrent run loops in a single fiber"); - }, - [OP_STATEFUL]: (self, runtimeFlags2, cur, message) => { - message.onFiber(self, running2(runtimeFlags2)); - return cur; - }, - [OP_YIELD_NOW]: (_self, _runtimeFlags, cur, _message) => { - return flatMap7(yieldNow(), () => cur); - } -}; -var runBlockedRequests = (self) => forEachSequentialDiscard(flatten3(self), (requestsByRequestResolver) => forEachConcurrentDiscard(sequentialCollectionToChunk(requestsByRequestResolver), ([dataSource, sequential4]) => { - const map10 = new Map; - const arr = []; - for (const block of sequential4) { - arr.push(toReadonlyArray(block)); - for (const entry of block) { - map10.set(entry.request, entry); - } - } - const flat = arr.flat(); - return fiberRefLocally(invokeWithInterrupt(dataSource.runAll(arr), flat, () => flat.forEach((entry) => { - entry.listeners.interrupted = true; - })), currentRequestMap, map10); -}, false, false)); -var _version = /* @__PURE__ */ getCurrentVersion(); - -class FiberRuntime extends Class { - [FiberTypeId] = fiberVariance2; - [RuntimeFiberTypeId] = runtimeFiberVariance; - _fiberRefs; - _fiberId; - _queue = /* @__PURE__ */ new Array; - _children = null; - _observers = /* @__PURE__ */ new Array; - _running = false; - _stack = []; - _asyncInterruptor = null; - _asyncBlockingOn = null; - _exitValue = null; - _steps = []; - _isYielding = false; - currentRuntimeFlags; - currentOpCount = 0; - currentSupervisor; - currentScheduler; - currentTracer; - currentSpan; - currentContext; - currentDefaultServices; - constructor(fiberId2, fiberRefs0, runtimeFlags0) { - super(); - this.currentRuntimeFlags = runtimeFlags0; - this._fiberId = fiberId2; - this._fiberRefs = fiberRefs0; - if (runtimeMetrics(runtimeFlags0)) { - const tags = this.getFiberRef(currentMetricLabels); - fiberStarted.unsafeUpdate(1, tags); - fiberActive.unsafeUpdate(1, tags); - } - this.refreshRefCache(); - } - commit() { - return join2(this); - } - id() { - return this._fiberId; - } - resume(effect) { - this.tell(resume(effect)); - } - get status() { - return this.ask((_, status) => status); - } - get runtimeFlags() { - return this.ask((state, status) => { - if (isDone2(status)) { - return state.currentRuntimeFlags; - } - return status.runtimeFlags; - }); - } - scope() { - return unsafeMake6(this); - } - get children() { - return this.ask((fiber) => Array.from(fiber.getChildren())); - } - getChildren() { - if (this._children === null) { - this._children = new Set; - } - return this._children; - } - getInterruptedCause() { - return this.getFiberRef(currentInterruptedCause); - } - fiberRefs() { - return this.ask((fiber) => fiber.getFiberRefs()); - } - ask(f) { - return suspend(() => { - const deferred = deferredUnsafeMake(this._fiberId); - this.tell(stateful((fiber, status) => { - deferredUnsafeDone(deferred, sync(() => f(fiber, status))); - })); - return deferredAwait(deferred); - }); - } - tell(message) { - this._queue.push(message); - if (!this._running) { - this._running = true; - this.drainQueueLaterOnExecutor(); - } - } - get await() { - return async_((resume2) => { - const cb = (exit2) => resume2(succeed(exit2)); - if (this._exitValue !== null) { - cb(this._exitValue); - return; - } - this.tell(stateful((fiber, _) => { - if (fiber._exitValue !== null) { - cb(this._exitValue); - } else { - fiber.addObserver(cb); - } - })); - return sync(() => this.tell(stateful((fiber, _) => { - fiber.removeObserver(cb); - }))); - }, this.id()); - } - get inheritAll() { - return withFiberRuntime((parentFiber, parentStatus) => { - const parentFiberId = parentFiber.id(); - const parentFiberRefs = parentFiber.getFiberRefs(); - const parentRuntimeFlags = parentStatus.runtimeFlags; - const childFiberRefs = this.getFiberRefs(); - const updatedFiberRefs = joinAs(parentFiberRefs, parentFiberId, childFiberRefs); - parentFiber.setFiberRefs(updatedFiberRefs); - const updatedRuntimeFlags = parentFiber.getFiberRef(currentRuntimeFlags); - const patch9 = pipe(diff4(parentRuntimeFlags, updatedRuntimeFlags), exclude2(Interruption), exclude2(WindDown)); - return updateRuntimeFlags(patch9); - }); - } - get poll() { - return sync(() => fromNullable(this._exitValue)); - } - unsafePoll() { - return this._exitValue; - } - interruptAsFork(fiberId2) { - return sync(() => this.tell(interruptSignal(interrupt(fiberId2)))); - } - unsafeInterruptAsFork(fiberId2) { - this.tell(interruptSignal(interrupt(fiberId2))); - } - addObserver(observer) { - if (this._exitValue !== null) { - observer(this._exitValue); - } else { - this._observers.push(observer); - } - } - removeObserver(observer) { - this._observers = this._observers.filter((o) => o !== observer); - } - getFiberRefs() { - this.setFiberRef(currentRuntimeFlags, this.currentRuntimeFlags); - return this._fiberRefs; - } - unsafeDeleteFiberRef(fiberRef) { - this._fiberRefs = delete_(this._fiberRefs, fiberRef); - } - getFiberRef(fiberRef) { - if (this._fiberRefs.locals.has(fiberRef)) { - return this._fiberRefs.locals.get(fiberRef)[0][1]; - } - return fiberRef.initial; - } - setFiberRef(fiberRef, value) { - this._fiberRefs = updateAs(this._fiberRefs, { - fiberId: this._fiberId, - fiberRef, - value - }); - this.refreshRefCache(); - } - refreshRefCache() { - this.currentDefaultServices = this.getFiberRef(currentServices); - this.currentTracer = this.currentDefaultServices.unsafeMap.get(tracerTag.key); - this.currentSupervisor = this.getFiberRef(currentSupervisor); - this.currentScheduler = this.getFiberRef(currentScheduler); - this.currentContext = this.getFiberRef(currentContext); - this.currentSpan = this.currentContext.unsafeMap.get(spanTag.key); - } - setFiberRefs(fiberRefs3) { - this._fiberRefs = fiberRefs3; - this.refreshRefCache(); - } - addChild(child) { - this.getChildren().add(child); - } - removeChild(child) { - this.getChildren().delete(child); - } - transferChildren(scope) { - const children = this._children; - this._children = null; - if (children !== null && children.size > 0) { - for (const child of children) { - if (child._exitValue === null) { - scope.add(this.currentRuntimeFlags, child); - } - } - } - } - drainQueueOnCurrentThread() { - let recurse = true; - while (recurse) { - let evaluationSignal = EvaluationSignalContinue; - const prev = globalThis[currentFiberURI]; - globalThis[currentFiberURI] = this; - try { - while (evaluationSignal === EvaluationSignalContinue) { - evaluationSignal = this._queue.length === 0 ? EvaluationSignalDone : this.evaluateMessageWhileSuspended(this._queue.splice(0, 1)[0]); - } - } finally { - this._running = false; - globalThis[currentFiberURI] = prev; - } - if (this._queue.length > 0 && !this._running) { - this._running = true; - if (evaluationSignal === EvaluationSignalYieldNow) { - this.drainQueueLaterOnExecutor(); - recurse = false; - } else { - recurse = true; - } - } else { - recurse = false; - } - } - } - drainQueueLaterOnExecutor() { - this.currentScheduler.scheduleTask(this.run, this.getFiberRef(currentSchedulingPriority), this); - } - drainQueueWhileRunning(runtimeFlags2, cur0) { - let cur = cur0; - while (this._queue.length > 0) { - const message = this._queue.splice(0, 1)[0]; - cur = drainQueueWhileRunningTable[message._tag](this, runtimeFlags2, cur, message); - } - return cur; - } - isInterrupted() { - return !isEmpty5(this.getFiberRef(currentInterruptedCause)); - } - addInterruptedCause(cause2) { - const oldSC = this.getFiberRef(currentInterruptedCause); - this.setFiberRef(currentInterruptedCause, sequential(oldSC, cause2)); - } - processNewInterruptSignal(cause2) { - this.addInterruptedCause(cause2); - this.sendInterruptSignalToAllChildren(); - } - sendInterruptSignalToAllChildren() { - if (this._children === null || this._children.size === 0) { - return false; - } - let told = false; - for (const child of this._children) { - child.tell(interruptSignal(interrupt(this.id()))); - told = true; - } - return told; - } - interruptAllChildren() { - if (this.sendInterruptSignalToAllChildren()) { - const it = this._children.values(); - this._children = null; - let isDone3 = false; - const body = () => { - const next = it.next(); - if (!next.done) { - return asVoid(next.value.await); - } else { - return sync(() => { - isDone3 = true; - }); - } - }; - return whileLoop({ - while: () => !isDone3, - body, - step: () => {} - }); - } - return null; - } - reportExitValue(exit2) { - if (runtimeMetrics(this.currentRuntimeFlags)) { - const tags = this.getFiberRef(currentMetricLabels); - const startTimeMillis = this.id().startTimeMillis; - const endTimeMillis = Date.now(); - fiberLifetimes.unsafeUpdate(endTimeMillis - startTimeMillis, tags); - fiberActive.unsafeUpdate(-1, tags); - switch (exit2._tag) { - case OP_SUCCESS: { - fiberSuccesses.unsafeUpdate(1, tags); - break; - } - case OP_FAILURE: { - fiberFailures.unsafeUpdate(1, tags); - break; - } - } - } - if (exit2._tag === "Failure") { - const level = this.getFiberRef(currentUnhandledErrorLogLevel); - if (!isInterruptedOnly(exit2.cause) && level._tag === "Some") { - this.log("Fiber terminated with an unhandled error", exit2.cause, level); - } - } - } - setExitValue(exit2) { - this._exitValue = exit2; - this.reportExitValue(exit2); - for (let i = this._observers.length - 1;i >= 0; i--) { - this._observers[i](exit2); - } - this._observers = []; - } - getLoggers() { - return this.getFiberRef(currentLoggers); - } - log(message, cause2, overrideLogLevel) { - const logLevel = isSome2(overrideLogLevel) ? overrideLogLevel.value : this.getFiberRef(currentLogLevel); - const minimumLogLevel = this.getFiberRef(currentMinimumLogLevel); - if (greaterThan4(minimumLogLevel, logLevel)) { - return; - } - const spans = this.getFiberRef(currentLogSpan); - const annotations2 = this.getFiberRef(currentLogAnnotations); - const loggers = this.getLoggers(); - const contextMap = this.getFiberRefs(); - if (size3(loggers) > 0) { - const clockService = get3(this.getFiberRef(currentServices), clockTag); - const date = new Date(clockService.unsafeCurrentTimeMillis()); - withRedactableContext(contextMap, () => { - for (const logger of loggers) { - logger.log({ - fiberId: this.id(), - logLevel, - message, - cause: cause2, - context: contextMap, - spans, - annotations: annotations2, - date - }); - } - }); - } - } - evaluateMessageWhileSuspended(message) { - switch (message._tag) { - case OP_YIELD_NOW: { - return EvaluationSignalYieldNow; - } - case OP_INTERRUPT_SIGNAL: { - this.processNewInterruptSignal(message.cause); - if (this._asyncInterruptor !== null) { - this._asyncInterruptor(exitFailCause(message.cause)); - this._asyncInterruptor = null; - } - return EvaluationSignalContinue; - } - case OP_RESUME: { - this._asyncInterruptor = null; - this._asyncBlockingOn = null; - this.evaluateEffect(message.effect); - return EvaluationSignalContinue; - } - case OP_STATEFUL: { - message.onFiber(this, this._exitValue !== null ? done4 : suspended2(this.currentRuntimeFlags, this._asyncBlockingOn)); - return EvaluationSignalContinue; - } - default: { - return absurd(message); - } - } - } - evaluateEffect(effect0) { - this.currentSupervisor.onResume(this); - try { - let effect = interruptible(this.currentRuntimeFlags) && this.isInterrupted() ? exitFailCause(this.getInterruptedCause()) : effect0; - while (effect !== null) { - const eff = effect; - const exit2 = this.runLoop(eff); - if (exit2 === YieldedOp) { - const op = yieldedOpChannel.currentOp; - yieldedOpChannel.currentOp = null; - if (op._op === OP_YIELD) { - if (cooperativeYielding(this.currentRuntimeFlags)) { - this.tell(yieldNow3()); - this.tell(resume(exitVoid)); - effect = null; - } else { - effect = exitVoid; - } - } else if (op._op === OP_ASYNC) { - effect = null; - } - } else { - this.currentRuntimeFlags = pipe(this.currentRuntimeFlags, enable2(WindDown)); - const interruption2 = this.interruptAllChildren(); - if (interruption2 !== null) { - effect = flatMap7(interruption2, () => exit2); - } else { - if (this._queue.length === 0) { - this.setExitValue(exit2); - } else { - this.tell(resume(exit2)); - } - effect = null; - } - } - } - } finally { - this.currentSupervisor.onSuspend(this); - } - } - start(effect) { - if (!this._running) { - this._running = true; - const prev = globalThis[currentFiberURI]; - globalThis[currentFiberURI] = this; - try { - this.evaluateEffect(effect); - } finally { - this._running = false; - globalThis[currentFiberURI] = prev; - if (this._queue.length > 0) { - this.drainQueueLaterOnExecutor(); - } - } - } else { - this.tell(resume(effect)); - } - } - startFork(effect) { - this.tell(resume(effect)); - } - patchRuntimeFlags(oldRuntimeFlags, patch9) { - const newRuntimeFlags = patch4(oldRuntimeFlags, patch9); - globalThis[currentFiberURI] = this; - this.currentRuntimeFlags = newRuntimeFlags; - return newRuntimeFlags; - } - initiateAsync(runtimeFlags2, asyncRegister) { - let alreadyCalled = false; - const callback = (effect) => { - if (!alreadyCalled) { - alreadyCalled = true; - this.tell(resume(effect)); - } - }; - if (interruptible(runtimeFlags2)) { - this._asyncInterruptor = callback; - } - try { - asyncRegister(callback); - } catch (e) { - callback(failCause(die(e))); - } - } - pushStack(cont) { - this._stack.push(cont); - if (cont._op === "OnStep") { - this._steps.push({ - refs: this.getFiberRefs(), - flags: this.currentRuntimeFlags - }); - } - } - popStack() { - const item = this._stack.pop(); - if (item) { - if (item._op === "OnStep") { - this._steps.pop(); - } - return item; - } - return; - } - getNextSuccessCont() { - let frame = this.popStack(); - while (frame) { - if (frame._op !== OP_ON_FAILURE) { - return frame; - } - frame = this.popStack(); - } - } - getNextFailCont() { - let frame = this.popStack(); - while (frame) { - if (frame._op !== OP_ON_SUCCESS && frame._op !== OP_WHILE && frame._op !== OP_ITERATOR) { - return frame; - } - frame = this.popStack(); - } - } - [OP_TAG](op) { - return sync(() => unsafeGet3(this.currentContext, op)); - } - ["Left"](op) { - return fail2(op.left); - } - ["None"](_) { - return fail2(new NoSuchElementException); - } - ["Right"](op) { - return exitSucceed(op.right); - } - ["Some"](op) { - return exitSucceed(op.value); - } - ["Micro"](op) { - return unsafeAsync((microResume) => { - let resume2 = microResume; - const fiber = runFork(provideContext2(op, this.currentContext)); - fiber.addObserver((exit2) => { - if (exit2._tag === "Success") { - return resume2(exitSucceed(exit2.value)); - } - switch (exit2.cause._tag) { - case "Interrupt": { - return resume2(exitFailCause(interrupt(none4))); - } - case "Fail": { - return resume2(fail2(exit2.cause.error)); - } - case "Die": { - return resume2(die2(exit2.cause.defect)); - } - } - }); - return unsafeAsync((abortResume) => { - resume2 = (_) => { - abortResume(void_); - }; - fiber.unsafeInterrupt(); - }); - }); - } - [OP_SYNC](op) { - const value = internalCall(() => op.effect_instruction_i0()); - const cont = this.getNextSuccessCont(); - if (cont !== undefined) { - if (!(cont._op in contOpSuccess)) { - absurd(cont); - } - return contOpSuccess[cont._op](this, cont, value); - } else { - yieldedOpChannel.currentOp = exitSucceed(value); - return YieldedOp; - } - } - [OP_SUCCESS](op) { - const oldCur = op; - const cont = this.getNextSuccessCont(); - if (cont !== undefined) { - if (!(cont._op in contOpSuccess)) { - absurd(cont); - } - return contOpSuccess[cont._op](this, cont, oldCur.effect_instruction_i0); - } else { - yieldedOpChannel.currentOp = oldCur; - return YieldedOp; - } - } - [OP_FAILURE](op) { - const cause2 = op.effect_instruction_i0; - const cont = this.getNextFailCont(); - if (cont !== undefined) { - switch (cont._op) { - case OP_ON_FAILURE: - case OP_ON_SUCCESS_AND_FAILURE: { - if (!(interruptible(this.currentRuntimeFlags) && this.isInterrupted())) { - return internalCall(() => cont.effect_instruction_i1(cause2)); - } else { - return exitFailCause(stripFailures(cause2)); - } - } - case "OnStep": { - if (!(interruptible(this.currentRuntimeFlags) && this.isInterrupted())) { - return exitSucceed(exitFailCause(cause2)); - } else { - return exitFailCause(stripFailures(cause2)); - } - } - case OP_REVERT_FLAGS: { - this.patchRuntimeFlags(this.currentRuntimeFlags, cont.patch); - if (interruptible(this.currentRuntimeFlags) && this.isInterrupted()) { - return exitFailCause(sequential(cause2, this.getInterruptedCause())); - } else { - return exitFailCause(cause2); - } - } - default: { - absurd(cont); - } - } - } else { - yieldedOpChannel.currentOp = exitFailCause(cause2); - return YieldedOp; - } - } - [OP_WITH_RUNTIME](op) { - return internalCall(() => op.effect_instruction_i0(this, running2(this.currentRuntimeFlags))); - } - ["Blocked"](op) { - const refs = this.getFiberRefs(); - const flags = this.currentRuntimeFlags; - if (this._steps.length > 0) { - const frames = []; - const snap = this._steps[this._steps.length - 1]; - let frame = this.popStack(); - while (frame && frame._op !== "OnStep") { - frames.push(frame); - frame = this.popStack(); - } - this.setFiberRefs(snap.refs); - this.currentRuntimeFlags = snap.flags; - const patchRefs = diff6(snap.refs, refs); - const patchFlags = diff4(snap.flags, flags); - return exitSucceed(blocked(op.effect_instruction_i0, withFiberRuntime((newFiber) => { - while (frames.length > 0) { - newFiber.pushStack(frames.pop()); - } - newFiber.setFiberRefs(patch7(newFiber.id(), newFiber.getFiberRefs())(patchRefs)); - newFiber.currentRuntimeFlags = patch4(patchFlags)(newFiber.currentRuntimeFlags); - return op.effect_instruction_i1; - }))); - } - return uninterruptibleMask((restore) => flatMap7(forkDaemon(runRequestBlock(op.effect_instruction_i0)), () => restore(op.effect_instruction_i1))); - } - ["RunBlocked"](op) { - return runBlockedRequests(op.effect_instruction_i0); - } - [OP_UPDATE_RUNTIME_FLAGS](op) { - const updateFlags = op.effect_instruction_i0; - const oldRuntimeFlags = this.currentRuntimeFlags; - const newRuntimeFlags = patch4(oldRuntimeFlags, updateFlags); - if (interruptible(newRuntimeFlags) && this.isInterrupted()) { - return exitFailCause(this.getInterruptedCause()); - } else { - this.patchRuntimeFlags(this.currentRuntimeFlags, updateFlags); - if (op.effect_instruction_i1) { - const revertFlags = diff4(newRuntimeFlags, oldRuntimeFlags); - this.pushStack(new RevertFlags(revertFlags, op)); - return internalCall(() => op.effect_instruction_i1(oldRuntimeFlags)); - } else { - return exitVoid; - } - } - } - [OP_ON_SUCCESS](op) { - this.pushStack(op); - return op.effect_instruction_i0; - } - ["OnStep"](op) { - this.pushStack(op); - return op.effect_instruction_i0; - } - [OP_ON_FAILURE](op) { - this.pushStack(op); - return op.effect_instruction_i0; - } - [OP_ON_SUCCESS_AND_FAILURE](op) { - this.pushStack(op); - return op.effect_instruction_i0; - } - [OP_ASYNC](op) { - this._asyncBlockingOn = op.effect_instruction_i1; - this.initiateAsync(this.currentRuntimeFlags, op.effect_instruction_i0); - yieldedOpChannel.currentOp = op; - return YieldedOp; - } - [OP_YIELD](op) { - this._isYielding = false; - yieldedOpChannel.currentOp = op; - return YieldedOp; - } - [OP_WHILE](op) { - const check = op.effect_instruction_i0; - const body = op.effect_instruction_i1; - if (check()) { - this.pushStack(op); - return body(); - } else { - return exitVoid; - } - } - [OP_ITERATOR](op) { - return contOpSuccess[OP_ITERATOR](this, op, undefined); - } - [OP_COMMIT](op) { - return internalCall(() => op.commit()); - } - runLoop(effect0) { - let cur = effect0; - this.currentOpCount = 0; - while (true) { - if ((this.currentRuntimeFlags & OpSupervision) !== 0) { - this.currentSupervisor.onEffect(this, cur); - } - if (this._queue.length > 0) { - cur = this.drainQueueWhileRunning(this.currentRuntimeFlags, cur); - } - if (!this._isYielding) { - this.currentOpCount += 1; - const shouldYield = this.currentScheduler.shouldYield(this); - if (shouldYield !== false) { - this._isYielding = true; - this.currentOpCount = 0; - const oldCur = cur; - cur = flatMap7(yieldNow({ - priority: shouldYield - }), () => oldCur); - } - } - try { - cur = this.currentTracer.context(() => { - if (_version !== cur[EffectTypeId2]._V) { - const level = this.getFiberRef(currentVersionMismatchErrorLogLevel); - if (level._tag === "Some") { - const effectVersion = cur[EffectTypeId2]._V; - this.log(`Executing an Effect versioned ${effectVersion} with a Runtime of version ${getCurrentVersion()}, you may want to dedupe the effect dependencies, you can use the language service plugin to detect this at compile time: https://github.com/Effect-TS/language-service`, empty16, level); - } - } - return this[cur._op](cur); - }, this); - if (cur === YieldedOp) { - const op = yieldedOpChannel.currentOp; - if (op._op === OP_YIELD || op._op === OP_ASYNC) { - return YieldedOp; - } - yieldedOpChannel.currentOp = null; - return op._op === OP_SUCCESS || op._op === OP_FAILURE ? op : exitFailCause(die(op)); - } - } catch (e) { - if (cur !== YieldedOp && !hasProperty(cur, "_op") || !(cur._op in this)) { - cur = dieMessage(`Not a valid effect: ${toStringUnknown(cur)}`); - } else if (isInterruptedException(e)) { - cur = exitFailCause(sequential(die(e), interrupt(none4))); - } else { - cur = die2(e); - } - } - } - } - run = () => { - this.drainQueueOnCurrentThread(); - }; -} -var currentMinimumLogLevel = /* @__PURE__ */ globalValue("effect/FiberRef/currentMinimumLogLevel", () => fiberRefUnsafeMake(fromLiteral("Info"))); -var loggerWithConsoleLog = (self) => makeLogger((opts) => { - const services = getOrDefault2(opts.context, currentServices); - get3(services, consoleTag).unsafe.log(self.log(opts)); -}); -var defaultLogger = /* @__PURE__ */ globalValue(/* @__PURE__ */ Symbol.for("effect/Logger/defaultLogger"), () => loggerWithConsoleLog(stringLogger)); -var tracerLogger = /* @__PURE__ */ globalValue(/* @__PURE__ */ Symbol.for("effect/Logger/tracerLogger"), () => makeLogger(({ - annotations: annotations2, - cause: cause2, - context: context2, - fiberId: fiberId2, - logLevel, - message -}) => { - const span2 = filterDisablePropagation(getOption2(getOrDefault(context2, currentContext), spanTag)); - if (span2._tag === "None" || span2.value._tag === "ExternalSpan") { - return; - } - const clockService = unsafeGet3(getOrDefault(context2, currentServices), clockTag); - const attributes = {}; - for (const [key, value] of annotations2) { - attributes[key] = value; - } - attributes["effect.fiberId"] = threadName2(fiberId2); - attributes["effect.logLevel"] = logLevel.label; - if (cause2 !== null && cause2._tag !== "Empty") { - attributes["effect.cause"] = pretty(cause2, { - renderErrorCause: true - }); - } - span2.value.event(toStringUnknown(Array.isArray(message) && message.length === 1 ? message[0] : message), clockService.unsafeCurrentTimeNanos(), attributes); -})); -var currentLoggers = /* @__PURE__ */ globalValue(/* @__PURE__ */ Symbol.for("effect/FiberRef/currentLoggers"), () => fiberRefUnsafeMakeHashSet(make11(defaultLogger, tracerLogger))); -var annotateLogsScoped = function() { - if (typeof arguments[0] === "string") { - return fiberRefLocallyScopedWith(currentLogAnnotations, set3(arguments[0], arguments[1])); - } - const entries2 = Object.entries(arguments[0]); - return fiberRefLocallyScopedWith(currentLogAnnotations, mutate3((annotations2) => { - for (let i = 0;i < entries2.length; i++) { - const [key, value] = entries2[i]; - set3(annotations2, key, value); - } - return annotations2; - })); -}; -var whenLogLevel = /* @__PURE__ */ dual(2, (effect, level) => { - const requiredLogLevel = typeof level === "string" ? fromLiteral(level) : level; - return withFiberRuntime((fiberState) => { - const minimumLogLevel = fiberState.getFiberRef(currentMinimumLogLevel); - if (greaterThan4(minimumLogLevel, requiredLogLevel)) { - return succeed(none2()); - } - return map9(effect, some2); - }); -}); -var acquireRelease = /* @__PURE__ */ dual((args2) => isEffect(args2[0]), (acquire, release) => uninterruptible(tap(acquire, (a) => addFinalizer((exit2) => release(a, exit2))))); -var acquireReleaseInterruptible = /* @__PURE__ */ dual((args2) => isEffect(args2[0]), (acquire, release) => ensuring(acquire, addFinalizer((exit2) => release(exit2)))); -var addFinalizer = (finalizer) => withFiberRuntime((runtime3) => { - const acquireRefs = runtime3.getFiberRefs(); - const acquireFlags = disable2(runtime3.currentRuntimeFlags, Interruption); - return flatMap7(scope, (scope) => scopeAddFinalizerExit(scope, (exit2) => withFiberRuntime((runtimeFinalizer) => { - const preRefs = runtimeFinalizer.getFiberRefs(); - const preFlags = runtimeFinalizer.currentRuntimeFlags; - const patchRefs = diff6(preRefs, acquireRefs); - const patchFlags = diff4(preFlags, acquireFlags); - const inverseRefs = diff6(acquireRefs, preRefs); - runtimeFinalizer.setFiberRefs(patch7(patchRefs, runtimeFinalizer.id(), acquireRefs)); - return ensuring(withRuntimeFlags(finalizer(exit2), patchFlags), sync(() => { - runtimeFinalizer.setFiberRefs(patch7(inverseRefs, runtimeFinalizer.id(), runtimeFinalizer.getFiberRefs())); - })); - }))); -}); -var daemonChildren = (self) => { - const forkScope = fiberRefLocally(currentForkScopeOverride, some2(globalScope)); - return forkScope(self); -}; -var _existsParFound = /* @__PURE__ */ Symbol.for("effect/Effect/existsPar/found"); -var exists2 = /* @__PURE__ */ dual((args2) => isIterable(args2[0]) && !isEffect(args2[0]), (elements, predicate, options) => matchSimple(options?.concurrency, () => suspend(() => existsLoop(elements[Symbol.iterator](), 0, predicate)), () => matchEffect(forEach6(elements, (a, i) => if_(predicate(a, i), { - onTrue: () => fail2(_existsParFound), - onFalse: () => void_ -}), options), { - onFailure: (e) => e === _existsParFound ? succeed(true) : fail2(e), - onSuccess: () => succeed(false) -}))); -var existsLoop = (iterator, index, f) => { - const next = iterator.next(); - if (next.done) { - return succeed(false); - } - return flatMap7(f(next.value, index), (b) => b ? succeed(b) : existsLoop(iterator, index + 1, f)); -}; -var filter5 = /* @__PURE__ */ dual((args2) => isIterable(args2[0]) && !isEffect(args2[0]), (elements, predicate, options) => { - const predicate_ = options?.negate ? (a, i) => map9(predicate(a, i), not) : predicate; - return matchSimple(options?.concurrency, () => suspend(() => fromIterable(elements).reduceRight((effect, a, i) => zipWith2(effect, suspend(() => predicate_(a, i)), (list, b) => b ? [a, ...list] : list), sync(() => new Array))), () => map9(forEach6(elements, (a, i) => map9(predicate_(a, i), (b) => b ? some2(a) : none2()), options), getSomes)); -}); -var allResolveInput = (input) => { - if (Array.isArray(input) || isIterable(input)) { - return [input, none2()]; - } - const keys5 = Object.keys(input); - const size7 = keys5.length; - return [keys5.map((k) => input[k]), some2((values4) => { - const res = {}; - for (let i = 0;i < size7; i++) { - res[keys5[i]] = values4[i]; - } - return res; - })]; -}; -var allValidate = (effects, reconcile, options) => { - const eitherEffects = []; - for (const effect of effects) { - eitherEffects.push(either2(effect)); - } - return flatMap7(forEach6(eitherEffects, identity, { - concurrency: options?.concurrency, - batching: options?.batching, - concurrentFinalizers: options?.concurrentFinalizers - }), (eithers) => { - const none9 = none2(); - const size7 = eithers.length; - const errors = new Array(size7); - const successes = new Array(size7); - let errored = false; - for (let i = 0;i < size7; i++) { - const either3 = eithers[i]; - if (either3._tag === "Left") { - errors[i] = some2(either3.left); - errored = true; - } else { - successes[i] = either3.right; - errors[i] = none9; - } - } - if (errored) { - return reconcile._tag === "Some" ? fail2(reconcile.value(errors)) : fail2(errors); - } else if (options?.discard) { - return void_; - } - return reconcile._tag === "Some" ? succeed(reconcile.value(successes)) : succeed(successes); - }); -}; -var allEither = (effects, reconcile, options) => { - const eitherEffects = []; - for (const effect of effects) { - eitherEffects.push(either2(effect)); - } - if (options?.discard) { - return forEach6(eitherEffects, identity, { - concurrency: options?.concurrency, - batching: options?.batching, - discard: true, - concurrentFinalizers: options?.concurrentFinalizers - }); - } - return map9(forEach6(eitherEffects, identity, { - concurrency: options?.concurrency, - batching: options?.batching, - concurrentFinalizers: options?.concurrentFinalizers - }), (eithers) => reconcile._tag === "Some" ? reconcile.value(eithers) : eithers); -}; -var all2 = (arg, options) => { - const [effects, reconcile] = allResolveInput(arg); - if (options?.mode === "validate") { - return allValidate(effects, reconcile, options); - } else if (options?.mode === "either") { - return allEither(effects, reconcile, options); - } - return options?.discard !== true && reconcile._tag === "Some" ? map9(forEach6(effects, identity, options), reconcile.value) : forEach6(effects, identity, options); -}; -var allWith = (options) => (arg) => all2(arg, options); -var allSuccesses = (elements, options) => map9(all2(fromIterable(elements).map(exit), options), filterMap2((exit2) => exitIsSuccess(exit2) ? some2(exit2.effect_instruction_i0) : none2())); -var replicate = /* @__PURE__ */ dual(2, (self, n) => Array.from({ - length: n -}, () => self)); -var replicateEffect = /* @__PURE__ */ dual((args2) => isEffect(args2[0]), (self, n, options) => all2(replicate(self, n), options)); -var forEach6 = /* @__PURE__ */ dual((args2) => isIterable(args2[0]), (self, f, options) => withFiberRuntime((r) => { - const isRequestBatchingEnabled = options?.batching === true || options?.batching === "inherit" && r.getFiberRef(currentRequestBatching); - if (options?.discard) { - return match9(options.concurrency, () => finalizersMaskInternal(sequential3, options?.concurrentFinalizers)((restore) => isRequestBatchingEnabled ? forEachConcurrentDiscard(self, (a, i) => restore(f(a, i)), true, false, 1) : forEachSequentialDiscard(self, (a, i) => restore(f(a, i)))), () => finalizersMaskInternal(parallel3, options?.concurrentFinalizers)((restore) => forEachConcurrentDiscard(self, (a, i) => restore(f(a, i)), isRequestBatchingEnabled, false)), (n) => finalizersMaskInternal(parallelN2(n), options?.concurrentFinalizers)((restore) => forEachConcurrentDiscard(self, (a, i) => restore(f(a, i)), isRequestBatchingEnabled, false, n))); - } - return match9(options?.concurrency, () => finalizersMaskInternal(sequential3, options?.concurrentFinalizers)((restore) => isRequestBatchingEnabled ? forEachParN(self, 1, (a, i) => restore(f(a, i)), true) : forEachSequential(self, (a, i) => restore(f(a, i)))), () => finalizersMaskInternal(parallel3, options?.concurrentFinalizers)((restore) => forEachParUnbounded(self, (a, i) => restore(f(a, i)), isRequestBatchingEnabled)), (n) => finalizersMaskInternal(parallelN2(n), options?.concurrentFinalizers)((restore) => forEachParN(self, n, (a, i) => restore(f(a, i)), isRequestBatchingEnabled))); -})); -var forEachParUnbounded = (self, f, batching) => suspend(() => { - const as2 = fromIterable(self); - const array4 = new Array(as2.length); - const fn = (a, i) => flatMap7(f(a, i), (b) => sync(() => array4[i] = b)); - return zipRight(forEachConcurrentDiscard(as2, fn, batching, false), succeed(array4)); -}); -var forEachConcurrentDiscard = (self, f, batching, processAll, n) => uninterruptibleMask((restore) => transplant((graft) => withFiberRuntime((parent) => { - let todos = Array.from(self).reverse(); - let target = todos.length; - if (target === 0) { - return void_; - } - let counter6 = 0; - let interrupted = false; - const fibersCount = n ? Math.min(todos.length, n) : todos.length; - const fibers = new Set; - const results = new Array; - const interruptAll = () => fibers.forEach((fiber) => { - fiber.currentScheduler.scheduleTask(() => { - fiber.unsafeInterruptAsFork(parent.id()); - }, 0, fiber); - }); - const startOrder = new Array; - const joinOrder = new Array; - const residual = new Array; - const collectExits = () => { - const exits = results.filter(({ - exit: exit2 - }) => exit2._tag === "Failure").sort((a, b) => a.index < b.index ? -1 : a.index === b.index ? 0 : 1).map(({ - exit: exit2 - }) => exit2); - if (exits.length === 0) { - exits.push(exitVoid); - } - return exits; - }; - const runFiber = (eff, interruptImmediately = false) => { - const runnable = uninterruptible(graft(eff)); - const fiber = unsafeForkUnstarted(runnable, parent, parent.currentRuntimeFlags, globalScope); - parent.currentScheduler.scheduleTask(() => { - if (interruptImmediately) { - fiber.unsafeInterruptAsFork(parent.id()); - } - fiber.resume(runnable); - }, 0, fiber); - return fiber; - }; - const onInterruptSignal = () => { - if (!processAll) { - target -= todos.length; - todos = []; - } - interrupted = true; - interruptAll(); - }; - const stepOrExit = batching ? step2 : exit; - const processingFiber = runFiber(async_((resume2) => { - const pushResult = (res, index) => { - if (res._op === "Blocked") { - residual.push(res); - } else { - results.push({ - index, - exit: res - }); - if (res._op === "Failure" && !interrupted) { - onInterruptSignal(); - } - } - }; - const next = () => { - if (todos.length > 0) { - const a = todos.pop(); - let index = counter6++; - const returnNextElement = () => { - const a2 = todos.pop(); - index = counter6++; - return flatMap7(yieldNow(), () => flatMap7(stepOrExit(restore(f(a2, index))), onRes)); - }; - const onRes = (res) => { - if (todos.length > 0) { - pushResult(res, index); - if (todos.length > 0) { - return returnNextElement(); - } - } - return succeed(res); - }; - const todo = flatMap7(stepOrExit(restore(f(a, index))), onRes); - const fiber = runFiber(todo); - startOrder.push(fiber); - fibers.add(fiber); - if (interrupted) { - fiber.currentScheduler.scheduleTask(() => { - fiber.unsafeInterruptAsFork(parent.id()); - }, 0, fiber); - } - fiber.addObserver((wrapped) => { - let exit2; - if (wrapped._op === "Failure") { - exit2 = wrapped; - } else { - exit2 = wrapped.effect_instruction_i0; - } - joinOrder.push(fiber); - fibers.delete(fiber); - pushResult(exit2, index); - if (results.length === target) { - resume2(succeed(getOrElse(exitCollectAll(collectExits(), { - parallel: true - }), () => exitVoid))); - } else if (residual.length + results.length === target) { - const exits = collectExits(); - const requests = residual.map((blocked2) => blocked2.effect_instruction_i0).reduce(par); - resume2(succeed(blocked(requests, forEachConcurrentDiscard([getOrElse(exitCollectAll(exits, { - parallel: true - }), () => exitVoid), ...residual.map((blocked2) => blocked2.effect_instruction_i1)], (i) => i, batching, true, n)))); - } else { - next(); - } - }); - } - }; - for (let i = 0;i < fibersCount; i++) { - next(); - } - })); - return asVoid(onExit(flatten5(restore(join2(processingFiber))), exitMatch({ - onFailure: (cause2) => { - onInterruptSignal(); - const target2 = residual.length + 1; - const concurrency = Math.min(typeof n === "number" ? n : residual.length, residual.length); - const toPop = Array.from(residual); - return async_((cb) => { - const exits = []; - let count = 0; - let index = 0; - const check = (index2, hitNext) => (exit2) => { - exits[index2] = exit2; - count++; - if (count === target2) { - cb(exitSucceed(exitFailCause(cause2))); - } - if (toPop.length > 0 && hitNext) { - next(); - } - }; - const next = () => { - runFiber(toPop.pop(), true).addObserver(check(index, true)); - index++; - }; - processingFiber.addObserver(check(index, false)); - index++; - for (let i = 0;i < concurrency; i++) { - next(); - } - }); - }, - onSuccess: () => forEachSequential(joinOrder, (f2) => f2.inheritAll) - }))); -}))); -var forEachParN = (self, n, f, batching) => suspend(() => { - const as2 = fromIterable(self); - const array4 = new Array(as2.length); - const fn = (a, i) => map9(f(a, i), (b) => array4[i] = b); - return zipRight(forEachConcurrentDiscard(as2, fn, batching, false, n), succeed(array4)); -}); -var fork = (self) => withFiberRuntime((state, status) => succeed(unsafeFork(self, state, status.runtimeFlags))); -var forkDaemon = (self) => forkWithScopeOverride(self, globalScope); -var forkWithErrorHandler = /* @__PURE__ */ dual(2, (self, handler) => fork(onError(self, (cause2) => { - const either3 = failureOrCause(cause2); - switch (either3._tag) { - case "Left": - return handler(either3.left); - case "Right": - return failCause(either3.right); - } -}))); -var unsafeFork = (effect, parentFiber, parentRuntimeFlags, overrideScope = null) => { - const childFiber = unsafeMakeChildFiber(effect, parentFiber, parentRuntimeFlags, overrideScope); - childFiber.resume(effect); - return childFiber; -}; -var unsafeForkUnstarted = (effect, parentFiber, parentRuntimeFlags, overrideScope = null) => { - const childFiber = unsafeMakeChildFiber(effect, parentFiber, parentRuntimeFlags, overrideScope); - return childFiber; -}; -var unsafeMakeChildFiber = (effect, parentFiber, parentRuntimeFlags, overrideScope = null) => { - const childId = unsafeMake2(); - const parentFiberRefs = parentFiber.getFiberRefs(); - const childFiberRefs = forkAs(parentFiberRefs, childId); - const childFiber = new FiberRuntime(childId, childFiberRefs, parentRuntimeFlags); - const childContext = getOrDefault(childFiberRefs, currentContext); - const supervisor = childFiber.currentSupervisor; - supervisor.onStart(childContext, effect, some2(parentFiber), childFiber); - childFiber.addObserver((exit2) => supervisor.onEnd(exit2, childFiber)); - const parentScope = overrideScope !== null ? overrideScope : pipe(parentFiber.getFiberRef(currentForkScopeOverride), getOrElse(() => parentFiber.scope())); - parentScope.add(parentRuntimeFlags, childFiber); - return childFiber; -}; -var forkWithScopeOverride = (self, scopeOverride) => withFiberRuntime((parentFiber, parentStatus) => succeed(unsafeFork(self, parentFiber, parentStatus.runtimeFlags, scopeOverride))); -var mergeAll3 = /* @__PURE__ */ dual((args2) => isFunction2(args2[2]), (elements, zero3, f, options) => matchSimple(options?.concurrency, () => fromIterable(elements).reduce((acc, a, i) => zipWith2(acc, a, (acc2, a2) => f(acc2, a2, i)), succeed(zero3)), () => flatMap7(make28(zero3), (acc) => flatMap7(forEach6(elements, (effect, i) => flatMap7(effect, (a) => update3(acc, (b) => f(b, a, i))), options), () => get12(acc))))); -var partition3 = /* @__PURE__ */ dual((args2) => isIterable(args2[0]), (elements, f, options) => pipe(forEach6(elements, (a, i) => either2(f(a, i)), options), map9((chunk2) => partitionMap2(chunk2, identity)))); -var validateAll = /* @__PURE__ */ dual((args2) => isIterable(args2[0]), (elements, f, options) => flatMap7(partition3(elements, f, { - concurrency: options?.concurrency, - batching: options?.batching, - concurrentFinalizers: options?.concurrentFinalizers -}), ([es, bs]) => isNonEmptyArray2(es) ? fail2(es) : options?.discard ? void_ : succeed(bs))); -var raceAll = (all3) => withFiberRuntime((state, status) => async_((resume2) => { - const fibers = new Set; - let winner; - let failures2 = empty16; - const interruptAll = () => { - for (const fiber of fibers) { - fiber.unsafeInterruptAsFork(state.id()); - } - }; - let latch = false; - let empty26 = true; - for (const self of all3) { - empty26 = false; - const fiber = unsafeFork(interruptible2(self), state, status.runtimeFlags); - fibers.add(fiber); - fiber.addObserver((exit2) => { - fibers.delete(fiber); - if (!winner) { - if (exit2._tag === "Success") { - latch = true; - winner = fiber; - failures2 = empty16; - interruptAll(); - } else { - failures2 = parallel(exit2.cause, failures2); - } - } - if (latch && fibers.size === 0) { - resume2(winner ? zipRight(inheritAll(winner), winner.unsafePoll()) : failCause(failures2)); - } - }); - if (winner) - break; - } - if (empty26) { - return resume2(dieSync(() => new IllegalArgumentException(`Received an empty collection of effects`))); - } - latch = true; - return interruptAllAs(fibers, state.id()); -})); -var reduceEffect = /* @__PURE__ */ dual((args2) => isIterable(args2[0]) && !isEffect(args2[0]), (elements, zero3, f, options) => matchSimple(options?.concurrency, () => fromIterable(elements).reduce((acc, a, i) => zipWith2(acc, a, (acc2, a2) => f(acc2, a2, i)), zero3), () => suspend(() => pipe(mergeAll3([zero3, ...elements], none2(), (acc, elem, i) => { - switch (acc._tag) { - case "None": { - return some2(elem); - } - case "Some": { - return some2(f(acc.value, elem, i)); - } - } -}, options), map9((option2) => { - switch (option2._tag) { - case "None": { - throw new Error("BUG: Effect.reduceEffect - please report an issue at https://github.com/Effect-TS/effect/issues"); - } - case "Some": { - return option2.value; - } - } -}))))); -var parallelFinalizers = (self) => contextWithEffect((context2) => match2(getOption2(context2, scopeTag), { - onNone: () => self, - onSome: (scope) => { - switch (scope.strategy._tag) { - case "Parallel": - return self; - case "Sequential": - case "ParallelN": - return flatMap7(scopeFork(scope, parallel3), (inner) => scopeExtend(self, inner)); - } - } -})); -var parallelNFinalizers = (parallelism) => (self) => contextWithEffect((context2) => match2(getOption2(context2, scopeTag), { - onNone: () => self, - onSome: (scope) => { - if (scope.strategy._tag === "ParallelN" && scope.strategy.parallelism === parallelism) { - return self; - } - return flatMap7(scopeFork(scope, parallelN2(parallelism)), (inner) => scopeExtend(self, inner)); - } -})); -var finalizersMask = (strategy) => (self) => finalizersMaskInternal(strategy, true)(self); -var finalizersMaskInternal = (strategy, concurrentFinalizers) => (self) => contextWithEffect((context2) => match2(getOption2(context2, scopeTag), { - onNone: () => self(identity), - onSome: (scope) => { - if (concurrentFinalizers === true) { - const patch9 = strategy._tag === "Parallel" ? parallelFinalizers : strategy._tag === "Sequential" ? sequentialFinalizers : parallelNFinalizers(strategy.parallelism); - switch (scope.strategy._tag) { - case "Parallel": - return patch9(self(parallelFinalizers)); - case "Sequential": - return patch9(self(sequentialFinalizers)); - case "ParallelN": - return patch9(self(parallelNFinalizers(scope.strategy.parallelism))); - } - } else { - return self(identity); - } - } -})); -var scopeWith = (f) => flatMap7(scopeTag, f); -var scopedWith = (f) => flatMap7(scopeMake(), (scope) => onExit(f(scope), (exit2) => scope.close(exit2))); -var scopedEffect = (effect) => flatMap7(scopeMake(), (scope) => scopeUse(effect, scope)); -var sequentialFinalizers = (self) => contextWithEffect((context2) => match2(getOption2(context2, scopeTag), { - onNone: () => self, - onSome: (scope) => { - switch (scope.strategy._tag) { - case "Sequential": - return self; - case "Parallel": - case "ParallelN": - return flatMap7(scopeFork(scope, sequential3), (inner) => scopeExtend(self, inner)); - } - } -})); -var tagMetricsScoped = (key, value) => labelMetricsScoped([make29(key, value)]); -var labelMetricsScoped = (labels) => fiberRefLocallyScopedWith(currentMetricLabels, (old) => union(old, labels)); -var using = /* @__PURE__ */ dual(2, (self, use) => scopedWith((scope) => flatMap7(scopeExtend(self, scope), use))); -var validate = /* @__PURE__ */ dual((args2) => isEffect(args2[1]), (self, that, options) => validateWith(self, that, (a, b) => [a, b], options)); -var validateWith = /* @__PURE__ */ dual((args2) => isEffect(args2[1]), (self, that, f, options) => flatten5(zipWithOptions(exit(self), exit(that), (ea, eb) => exitZipWith(ea, eb, { - onSuccess: f, - onFailure: (ca, cb) => options?.concurrent ? parallel(ca, cb) : sequential(ca, cb) -}), options))); -var validateFirst = /* @__PURE__ */ dual((args2) => isIterable(args2[0]), (elements, f, options) => flip(forEach6(elements, (a, i) => flip(f(a, i)), options))); -var withClockScoped = (c) => fiberRefLocallyScopedWith(currentServices, add2(clockTag, c)); -var withRandomScoped = (value) => fiberRefLocallyScopedWith(currentServices, add2(randomTag, value)); -var withConfigProviderScoped = (provider) => fiberRefLocallyScopedWith(currentServices, add2(configProviderTag, provider)); -var withEarlyRelease = (self) => scopeWith((parent) => flatMap7(scopeFork(parent, sequential2), (child) => pipe(self, scopeExtend(child), map9((value) => [fiberIdWith((fiberId2) => scopeClose(child, exitInterrupt(fiberId2))), value])))); -var zipOptions = /* @__PURE__ */ dual((args2) => isEffect(args2[1]), (self, that, options) => zipWithOptions(self, that, (a, b) => [a, b], options)); -var zipLeftOptions = /* @__PURE__ */ dual((args2) => isEffect(args2[1]), (self, that, options) => { - if (options?.concurrent !== true && (options?.batching === undefined || options.batching === false)) { - return zipLeft(self, that); - } - return zipWithOptions(self, that, (a, _) => a, options); -}); -var zipRightOptions = /* @__PURE__ */ dual((args2) => isEffect(args2[1]), (self, that, options) => { - if (options?.concurrent !== true && (options?.batching === undefined || options.batching === false)) { - return zipRight(self, that); - } - return zipWithOptions(self, that, (_, b) => b, options); -}); -var zipWithOptions = /* @__PURE__ */ dual((args2) => isEffect(args2[1]), (self, that, f, options) => map9(all2([self, that], { - concurrency: options?.concurrent ? 2 : 1, - batching: options?.batching, - concurrentFinalizers: options?.concurrentFinalizers -}), ([a, a2]) => f(a, a2))); -var withRuntimeFlagsScoped = (update5) => { - if (update5 === empty14) { - return void_; - } - return pipe(runtimeFlags, flatMap7((runtimeFlags2) => { - const updatedRuntimeFlags = patch4(runtimeFlags2, update5); - const revertRuntimeFlags = diff4(updatedRuntimeFlags, runtimeFlags2); - return pipe(updateRuntimeFlags(update5), zipRight(addFinalizer(() => updateRuntimeFlags(revertRuntimeFlags))), asVoid); - }), uninterruptible); -}; -var scopeTag = /* @__PURE__ */ GenericTag("effect/Scope"); -var scope = scopeTag; -var scopeUnsafeAddFinalizer = (scope2, fin) => { - if (scope2.state._tag === "Open") { - scope2.state.finalizers.set({}, fin); - } -}; -var ScopeImplProto = { - [ScopeTypeId]: ScopeTypeId, - [CloseableScopeTypeId]: CloseableScopeTypeId, - pipe() { - return pipeArguments(this, arguments); - }, - fork(strategy) { - return sync(() => { - const newScope = scopeUnsafeMake(strategy); - if (this.state._tag === "Closed") { - newScope.state = this.state; - return newScope; - } - const key = {}; - const fin = (exit2) => newScope.close(exit2); - this.state.finalizers.set(key, fin); - scopeUnsafeAddFinalizer(newScope, (_) => sync(() => { - if (this.state._tag === "Open") { - this.state.finalizers.delete(key); - } - })); - return newScope; - }); - }, - close(exit2) { - return suspend(() => { - if (this.state._tag === "Closed") { - return void_; - } - const finalizers = Array.from(this.state.finalizers.values()).reverse(); - this.state = { - _tag: "Closed", - exit: exit2 - }; - if (finalizers.length === 0) { - return void_; - } - return isSequential(this.strategy) ? pipe(forEachSequential(finalizers, (fin) => exit(fin(exit2))), flatMap7((results) => pipe(exitCollectAll(results), map2(exitAsVoid), getOrElse(() => exitVoid)))) : isParallel(this.strategy) ? pipe(forEachParUnbounded(finalizers, (fin) => exit(fin(exit2)), false), flatMap7((results) => pipe(exitCollectAll(results, { - parallel: true - }), map2(exitAsVoid), getOrElse(() => exitVoid)))) : pipe(forEachParN(finalizers, this.strategy.parallelism, (fin) => exit(fin(exit2)), false), flatMap7((results) => pipe(exitCollectAll(results, { - parallel: true - }), map2(exitAsVoid), getOrElse(() => exitVoid)))); - }); - }, - addFinalizer(fin) { - return suspend(() => { - if (this.state._tag === "Closed") { - return fin(this.state.exit); - } - this.state.finalizers.set({}, fin); - return void_; - }); - } -}; -var scopeUnsafeMake = (strategy = sequential2) => { - const scope2 = Object.create(ScopeImplProto); - scope2.strategy = strategy; - scope2.state = { - _tag: "Open", - finalizers: new Map - }; - return scope2; -}; -var scopeMake = (strategy = sequential2) => sync(() => scopeUnsafeMake(strategy)); -var scopeExtend = /* @__PURE__ */ dual(2, (effect, scope2) => mapInputContext(effect, merge3(make6(scopeTag, scope2)))); -var scopeUse = /* @__PURE__ */ dual(2, (effect, scope2) => pipe(effect, scopeExtend(scope2), onExit((exit2) => scope2.close(exit2)))); -var fiberRefUnsafeMakeSupervisor = (initial) => fiberRefUnsafeMakePatch(initial, { - differ: differ2, - fork: empty25 -}); -var fiberRefLocallyScoped = /* @__PURE__ */ dual(2, (self, value) => asVoid(acquireRelease(flatMap7(fiberRefGet(self), (oldValue) => as(fiberRefSet(self, value), oldValue)), (oldValue) => fiberRefSet(self, oldValue)))); -var fiberRefLocallyScopedWith = /* @__PURE__ */ dual(2, (self, f) => fiberRefGetWith(self, (a) => fiberRefLocallyScoped(self, f(a)))); -var currentRuntimeFlags = /* @__PURE__ */ fiberRefUnsafeMakeRuntimeFlags(none5); -var currentSupervisor = /* @__PURE__ */ fiberRefUnsafeMakeSupervisor(none8); -var fiberAwaitAll = (fibers) => forEach6(fibers, _await2); -var fiberAll = (fibers) => { - const _fiberAll = { - ...CommitPrototype2, - commit() { - return join2(this); - }, - [FiberTypeId]: fiberVariance2, - id: () => fromIterable(fibers).reduce((id, fiber) => combine3(id, fiber.id()), none4), - await: exit(forEachParUnbounded(fibers, (fiber) => flatten5(fiber.await), false)), - children: map9(forEachParUnbounded(fibers, (fiber) => fiber.children, false), flatten), - inheritAll: forEachSequentialDiscard(fibers, (fiber) => fiber.inheritAll), - poll: map9(forEachSequential(fibers, (fiber) => fiber.poll), reduceRight(some2(exitSucceed(new Array)), (optionB, optionA) => { - switch (optionA._tag) { - case "None": { - return none2(); - } - case "Some": { - switch (optionB._tag) { - case "None": { - return none2(); - } - case "Some": { - return some2(exitZipWith(optionA.value, optionB.value, { - onSuccess: (a, chunk2) => [a, ...chunk2], - onFailure: parallel - })); - } - } - } - } - })), - interruptAsFork: (fiberId2) => forEachSequentialDiscard(fibers, (fiber) => fiber.interruptAsFork(fiberId2)) - }; - return _fiberAll; -}; -var raceWith = /* @__PURE__ */ dual(3, (self, other, options) => raceFibersWith(self, other, { - onSelfWin: (winner, loser) => flatMap7(winner.await, (exit2) => { - switch (exit2._tag) { - case OP_SUCCESS: { - return flatMap7(winner.inheritAll, () => options.onSelfDone(exit2, loser)); - } - case OP_FAILURE: { - return options.onSelfDone(exit2, loser); - } - } - }), - onOtherWin: (winner, loser) => flatMap7(winner.await, (exit2) => { - switch (exit2._tag) { - case OP_SUCCESS: { - return flatMap7(winner.inheritAll, () => options.onOtherDone(exit2, loser)); - } - case OP_FAILURE: { - return options.onOtherDone(exit2, loser); - } - } - }) -})); -var disconnect = (self) => uninterruptibleMask((restore) => fiberIdWith((fiberId2) => flatMap7(forkDaemon(restore(self)), (fiber) => pipe(restore(join2(fiber)), onInterrupt(() => pipe(fiber, interruptAsFork(fiberId2))))))); -var race = /* @__PURE__ */ dual(2, (self, that) => fiberIdWith((parentFiberId) => raceWith(self, that, { - onSelfDone: (exit2, right3) => exitMatchEffect(exit2, { - onFailure: (cause2) => pipe(join2(right3), mapErrorCause((cause22) => parallel(cause2, cause22))), - onSuccess: (value) => pipe(right3, interruptAsFiber(parentFiberId), as(value)) - }), - onOtherDone: (exit2, left3) => exitMatchEffect(exit2, { - onFailure: (cause2) => pipe(join2(left3), mapErrorCause((cause22) => parallel(cause22, cause2))), - onSuccess: (value) => pipe(left3, interruptAsFiber(parentFiberId), as(value)) - }) -}))); -var raceFibersWith = /* @__PURE__ */ dual(3, (self, other, options) => withFiberRuntime((parentFiber, parentStatus) => { - const parentRuntimeFlags = parentStatus.runtimeFlags; - const raceIndicator = make12(true); - const leftFiber = unsafeMakeChildFiber(self, parentFiber, parentRuntimeFlags, options.selfScope); - const rightFiber = unsafeMakeChildFiber(other, parentFiber, parentRuntimeFlags, options.otherScope); - return async_((cb) => { - leftFiber.addObserver(() => completeRace(leftFiber, rightFiber, options.onSelfWin, raceIndicator, cb)); - rightFiber.addObserver(() => completeRace(rightFiber, leftFiber, options.onOtherWin, raceIndicator, cb)); - leftFiber.startFork(self); - rightFiber.startFork(other); - }, combine3(leftFiber.id(), rightFiber.id())); -})); -var completeRace = (winner, loser, cont, ab, cb) => { - if (compareAndSet(true, false)(ab)) { - cb(cont(winner, loser)); - } -}; -var ensuring = /* @__PURE__ */ dual(2, (self, finalizer) => uninterruptibleMask((restore) => matchCauseEffect(restore(self), { - onFailure: (cause1) => matchCauseEffect(finalizer, { - onFailure: (cause2) => failCause(sequential(cause1, cause2)), - onSuccess: () => failCause(cause1) - }), - onSuccess: (a) => as(finalizer, a) -}))); -var invokeWithInterrupt = (self, entries2, onInterrupt2) => fiberIdWith((id) => ensuring(flatMap7(forkDaemon(interruptible2(self)), (processing) => async_((cb) => { - const counts = entries2.map((_) => _.listeners.count); - const checkDone = () => { - if (counts.every((count) => count === 0)) { - if (entries2.every((_) => { - if (_.result.state.current._tag === "Pending") { - return true; - } else if (_.result.state.current._tag === "Done" && exitIsExit(_.result.state.current.effect) && _.result.state.current.effect._tag === "Failure" && isInterrupted(_.result.state.current.effect.cause)) { - return true; - } else { - return false; - } - })) { - cleanup.forEach((f) => f()); - onInterrupt2?.(); - cb(interruptFiber(processing)); - } - } - }; - processing.addObserver((exit2) => { - cleanup.forEach((f) => f()); - cb(exit2); - }); - const cleanup = entries2.map((r, i) => { - const observer = (count) => { - counts[i] = count; - checkDone(); - }; - r.listeners.addObserver(observer); - return () => r.listeners.removeObserver(observer); - }); - checkDone(); - return sync(() => { - cleanup.forEach((f) => f()); - }); -})), suspend(() => { - const residual = entries2.flatMap((entry) => { - if (!entry.state.completed) { - return [entry]; - } - return []; - }); - return forEachSequentialDiscard(residual, (entry) => complete(entry.request, exitInterrupt(id))); -}))); -var makeSpanScoped = (name, options) => { - options = addSpanStackTrace(options); - return uninterruptible(withFiberRuntime((fiber) => { - const scope2 = unsafeGet3(fiber.getFiberRef(currentContext), scopeTag); - const span2 = unsafeMakeSpan(fiber, name, options); - const timingEnabled = fiber.getFiberRef(currentTracerTimingEnabled); - const clock_ = get3(fiber.getFiberRef(currentServices), clockTag); - return as(scopeAddFinalizerExit(scope2, (exit2) => endSpan(span2, exit2, clock_, timingEnabled)), span2); - })); -}; -var withTracerScoped = (value) => fiberRefLocallyScopedWith(currentServices, add2(tracerTag, value)); -var withSpanScoped = function() { - const dataFirst = typeof arguments[0] !== "string"; - const name = dataFirst ? arguments[1] : arguments[0]; - const options = addSpanStackTrace(dataFirst ? arguments[2] : arguments[1]); - if (dataFirst) { - const self = arguments[0]; - return flatMap7(makeSpanScoped(name, addSpanStackTrace(options)), (span2) => provideService(self, spanTag, span2)); - } - return (self) => flatMap7(makeSpanScoped(name, addSpanStackTrace(options)), (span2) => provideService(self, spanTag, span2)); -}; - -// node_modules/effect/dist/esm/internal/cache.js -var complete2 = (key, exit2, entryStats, timeToLiveMillis) => struct({ - _tag: "Complete", - key, - exit: exit2, - entryStats, - timeToLiveMillis -}); -var pending2 = (key, deferred) => struct({ - _tag: "Pending", - key, - deferred -}); -var refreshing = (deferred, complete3) => struct({ - _tag: "Refreshing", - deferred, - complete: complete3 -}); -var MapKeyTypeId = /* @__PURE__ */ Symbol.for("effect/Cache/MapKey"); - -class MapKeyImpl { - current; - [MapKeyTypeId] = MapKeyTypeId; - previous = undefined; - next = undefined; - constructor(current) { - this.current = current; - } - [symbol]() { - return pipe(hash(this.current), combine(hash(this.previous)), combine(hash(this.next)), cached(this)); - } - [symbol2](that) { - if (this === that) { - return true; - } - return isMapKey(that) && equals(this.current, that.current) && equals(this.previous, that.previous) && equals(this.next, that.next); - } -} -var makeMapKey = (current) => new MapKeyImpl(current); -var isMapKey = (u) => hasProperty(u, MapKeyTypeId); - -class KeySetImpl { - head = undefined; - tail = undefined; - add(key) { - if (key !== this.tail) { - if (this.tail === undefined) { - this.head = key; - this.tail = key; - } else { - const previous = key.previous; - const next = key.next; - if (next !== undefined) { - key.next = undefined; - if (previous !== undefined) { - previous.next = next; - next.previous = previous; - } else { - this.head = next; - this.head.previous = undefined; - } - } - this.tail.next = key; - key.previous = this.tail; - this.tail = key; - } - } - } - remove() { - const key = this.head; - if (key !== undefined) { - const next = key.next; - if (next !== undefined) { - key.next = undefined; - this.head = next; - this.head.previous = undefined; - } else { - this.head = undefined; - this.tail = undefined; - } - } - return key; - } -} -var makeKeySet = () => new KeySetImpl; -var makeCacheState = (map10, keys5, accesses, updating, hits, misses) => ({ - map: map10, - keys: keys5, - accesses, - updating, - hits, - misses -}); -var initialCacheState = () => makeCacheState(empty17(), makeKeySet(), unbounded(), make12(false), 0, 0); -var CacheSymbolKey = "effect/Cache"; -var CacheTypeId = /* @__PURE__ */ Symbol.for(CacheSymbolKey); -var cacheVariance = { - _Key: (_) => _, - _Error: (_) => _, - _Value: (_) => _ -}; -var ConsumerCacheSymbolKey = "effect/ConsumerCache"; -var ConsumerCacheTypeId = /* @__PURE__ */ Symbol.for(ConsumerCacheSymbolKey); -var consumerCacheVariance = { - _Key: (_) => _, - _Error: (_) => _, - _Value: (_) => _ -}; -var makeCacheStats = (options) => options; -var makeEntryStats = (loadedMillis) => ({ - loadedMillis -}); - -class CacheImpl { - capacity; - context; - fiberId; - lookup; - timeToLive; - [CacheTypeId] = cacheVariance; - [ConsumerCacheTypeId] = consumerCacheVariance; - cacheState; - constructor(capacity, context2, fiberId2, lookup, timeToLive) { - this.capacity = capacity; - this.context = context2; - this.fiberId = fiberId2; - this.lookup = lookup; - this.timeToLive = timeToLive; - this.cacheState = initialCacheState(); - } - get(key) { - return map9(this.getEither(key), merge); - } - get cacheStats() { - return sync(() => makeCacheStats({ - hits: this.cacheState.hits, - misses: this.cacheState.misses, - size: size4(this.cacheState.map) - })); - } - getOption(key) { - return suspend(() => match2(get8(this.cacheState.map, key), { - onNone: () => { - const mapKey = makeMapKey(key); - this.trackAccess(mapKey); - this.trackMiss(); - return succeed(none2()); - }, - onSome: (value) => this.resolveMapValue(value) - })); - } - getOptionComplete(key) { - return suspend(() => match2(get8(this.cacheState.map, key), { - onNone: () => { - const mapKey = makeMapKey(key); - this.trackAccess(mapKey); - this.trackMiss(); - return succeed(none2()); - }, - onSome: (value) => this.resolveMapValue(value, true) - })); - } - contains(key) { - return sync(() => has4(this.cacheState.map, key)); - } - entryStats(key) { - return sync(() => { - const option2 = get8(this.cacheState.map, key); - if (isSome2(option2)) { - switch (option2.value._tag) { - case "Complete": { - const loaded = option2.value.entryStats.loadedMillis; - return some2(makeEntryStats(loaded)); - } - case "Pending": { - return none2(); - } - case "Refreshing": { - const loaded = option2.value.complete.entryStats.loadedMillis; - return some2(makeEntryStats(loaded)); - } - } - } - return none2(); - }); - } - getEither(key) { - return suspend(() => { - const k = key; - let mapKey = undefined; - let deferred = undefined; - let value = getOrUndefined(get8(this.cacheState.map, k)); - if (value === undefined) { - deferred = unsafeMake3(this.fiberId); - mapKey = makeMapKey(k); - if (has4(this.cacheState.map, k)) { - value = getOrUndefined(get8(this.cacheState.map, k)); - } else { - set4(this.cacheState.map, k, pending2(mapKey, deferred)); - } - } - if (value === undefined) { - this.trackAccess(mapKey); - this.trackMiss(); - return map9(this.lookupValueOf(key, deferred), right2); - } else { - return flatMap7(this.resolveMapValue(value), match2({ - onNone: () => this.getEither(key), - onSome: (value2) => succeed(left2(value2)) - })); - } - }); - } - invalidate(key) { - return sync(() => { - remove5(this.cacheState.map, key); - }); - } - invalidateWhen(key, when2) { - return sync(() => { - const value = get8(this.cacheState.map, key); - if (isSome2(value) && value.value._tag === "Complete") { - if (value.value.exit._tag === "Success") { - if (when2(value.value.exit.value)) { - remove5(this.cacheState.map, key); - } - } - } - }); - } - get invalidateAll() { - return sync(() => { - this.cacheState.map = empty17(); - }); - } - refresh(key) { - return clockWith3((clock2) => suspend(() => { - const k = key; - const deferred = unsafeMake3(this.fiberId); - let value = getOrUndefined(get8(this.cacheState.map, k)); - if (value === undefined) { - if (has4(this.cacheState.map, k)) { - value = getOrUndefined(get8(this.cacheState.map, k)); - } else { - set4(this.cacheState.map, k, pending2(makeMapKey(k), deferred)); - } - } - if (value === undefined) { - return asVoid(this.lookupValueOf(key, deferred)); - } else { - switch (value._tag) { - case "Complete": { - if (this.hasExpired(clock2, value.timeToLiveMillis)) { - const found = getOrUndefined(get8(this.cacheState.map, k)); - if (equals(found, value)) { - remove5(this.cacheState.map, k); - } - return asVoid(this.get(key)); - } - return pipe(this.lookupValueOf(key, deferred), when(() => { - const current = getOrUndefined(get8(this.cacheState.map, k)); - if (equals(current, value)) { - const mapValue = refreshing(deferred, value); - set4(this.cacheState.map, k, mapValue); - return true; - } - return false; - }), asVoid); - } - case "Pending": { - return _await(value.deferred); - } - case "Refreshing": { - return _await(value.deferred); - } - } - } - })); - } - set(key, value) { - return clockWith3((clock2) => sync(() => { - const now = clock2.unsafeCurrentTimeMillis(); - const k = key; - const lookupResult = succeed2(value); - const mapValue = complete2(makeMapKey(k), lookupResult, makeEntryStats(now), now + toMillis(decode(this.timeToLive(lookupResult)))); - set4(this.cacheState.map, k, mapValue); - })); - } - get size() { - return sync(() => { - return size4(this.cacheState.map); - }); - } - get values() { - return sync(() => { - const values4 = []; - for (const entry of this.cacheState.map) { - if (entry[1]._tag === "Complete" && entry[1].exit._tag === "Success") { - values4.push(entry[1].exit.value); - } - } - return values4; - }); - } - get entries() { - return sync(() => { - const values4 = []; - for (const entry of this.cacheState.map) { - if (entry[1]._tag === "Complete" && entry[1].exit._tag === "Success") { - values4.push([entry[0], entry[1].exit.value]); - } - } - return values4; - }); - } - get keys() { - return sync(() => { - const keys5 = []; - for (const entry of this.cacheState.map) { - if (entry[1]._tag === "Complete" && entry[1].exit._tag === "Success") { - keys5.push(entry[0]); - } - } - return keys5; - }); - } - resolveMapValue(value, ignorePending = false) { - return clockWith3((clock2) => { - switch (value._tag) { - case "Complete": { - this.trackAccess(value.key); - if (this.hasExpired(clock2, value.timeToLiveMillis)) { - remove5(this.cacheState.map, value.key.current); - return succeed(none2()); - } - this.trackHit(); - return map9(value.exit, some2); - } - case "Pending": { - this.trackAccess(value.key); - this.trackHit(); - if (ignorePending) { - return succeed(none2()); - } - return map9(_await(value.deferred), some2); - } - case "Refreshing": { - this.trackAccess(value.complete.key); - this.trackHit(); - if (this.hasExpired(clock2, value.complete.timeToLiveMillis)) { - if (ignorePending) { - return succeed(none2()); - } - return map9(_await(value.deferred), some2); - } - return map9(value.complete.exit, some2); - } - } - }); - } - trackHit() { - this.cacheState.hits = this.cacheState.hits + 1; - } - trackMiss() { - this.cacheState.misses = this.cacheState.misses + 1; - } - trackAccess(key) { - offer(this.cacheState.accesses, key); - if (compareAndSet(this.cacheState.updating, false, true)) { - let loop2 = true; - while (loop2) { - const key2 = poll(this.cacheState.accesses, EmptyMutableQueue); - if (key2 === EmptyMutableQueue) { - loop2 = false; - } else { - this.cacheState.keys.add(key2); - } - } - let size7 = size4(this.cacheState.map); - loop2 = size7 > this.capacity; - while (loop2) { - const key2 = this.cacheState.keys.remove(); - if (key2 !== undefined) { - if (has4(this.cacheState.map, key2.current)) { - remove5(this.cacheState.map, key2.current); - size7 = size7 - 1; - loop2 = size7 > this.capacity; - } - } else { - loop2 = false; - } - } - set2(this.cacheState.updating, false); - } - } - hasExpired(clock2, timeToLiveMillis) { - return clock2.unsafeCurrentTimeMillis() > timeToLiveMillis; - } - lookupValueOf(input, deferred) { - return clockWith3((clock2) => suspend(() => { - const key = input; - return pipe(this.lookup(input), provideContext(this.context), exit, flatMap7((exit2) => { - const now = clock2.unsafeCurrentTimeMillis(); - const stats = makeEntryStats(now); - const value = complete2(makeMapKey(key), exit2, stats, now + toMillis(decode(this.timeToLive(exit2)))); - set4(this.cacheState.map, key, value); - return zipRight(done2(deferred, exit2), exit2); - }), onInterrupt(() => zipRight(interrupt3(deferred), sync(() => { - remove5(this.cacheState.map, key); - })))); - })); - } -} -var unsafeMakeWith = (capacity, lookup, timeToLive) => new CacheImpl(capacity, empty3(), none3, lookup, (exit2) => decode(timeToLive(exit2))); -// node_modules/effect/dist/esm/Cause.js -var empty26 = empty16; -var fail3 = fail; -var die3 = die; -var interrupt4 = interrupt; -var parallel4 = parallel; -var sequential4 = sequential; -var isCause2 = isCause; -var isFailType2 = isFailType; -var IllegalArgumentException2 = IllegalArgumentException; -var pretty2 = pretty; -// node_modules/effect/dist/esm/Effect.js -var exports_Effect = {}; -__export(exports_Effect, { - zipWith: () => zipWith3, - zipRight: () => zipRight2, - zipLeft: () => zipLeft2, - zip: () => zip4, - yieldNow: () => yieldNow4, - withUnhandledErrorLogLevel: () => withUnhandledErrorLogLevel2, - withTracerTiming: () => withTracerTiming2, - withTracerScoped: () => withTracerScoped2, - withTracerEnabled: () => withTracerEnabled2, - withTracer: () => withTracer2, - withSpanScoped: () => withSpanScoped2, - withSpan: () => withSpan2, - withSchedulingPriority: () => withSchedulingPriority2, - withScheduler: () => withScheduler2, - withRuntimeFlagsPatchScoped: () => withRuntimeFlagsPatchScoped, - withRuntimeFlagsPatch: () => withRuntimeFlagsPatch, - withRequestCaching: () => withRequestCaching2, - withRequestCache: () => withRequestCache2, - withRequestBatching: () => withRequestBatching2, - withRandomScoped: () => withRandomScoped2, - withRandomFixed: () => withRandomFixed, - withRandom: () => withRandom2, - withParentSpan: () => withParentSpan2, - withMetric: () => withMetric2, - withMaxOpsBeforeYield: () => withMaxOpsBeforeYield2, - withLogSpan: () => withLogSpan2, - withFiberRuntime: () => withFiberRuntime2, - withExecutionPlan: () => withExecutionPlan2, - withEarlyRelease: () => withEarlyRelease2, - withConsoleScoped: () => withConsoleScoped2, - withConsole: () => withConsole2, - withConfigProviderScoped: () => withConfigProviderScoped2, - withConfigProvider: () => withConfigProvider2, - withConcurrency: () => withConcurrency2, - withClockScoped: () => withClockScoped2, - withClock: () => withClock2, - whileLoop: () => whileLoop2, - whenRef: () => whenRef2, - whenLogLevel: () => whenLogLevel2, - whenFiberRef: () => whenFiberRef2, - whenEffect: () => whenEffect2, - when: () => when2, - void: () => _void, - validateWith: () => validateWith2, - validateFirst: () => validateFirst2, - validateAll: () => validateAll2, - validate: () => validate2, - using: () => using2, - useSpan: () => useSpan2, - updateService: () => updateService2, - updateFiberRefs: () => updateFiberRefs2, - unsandbox: () => unsandbox2, - unsafeMakeSemaphore: () => unsafeMakeSemaphore2, - unsafeMakeLatch: () => unsafeMakeLatch2, - unlessEffect: () => unlessEffect2, - unless: () => unless2, - uninterruptibleMask: () => uninterruptibleMask3, - uninterruptible: () => uninterruptible2, - tryPromise: () => tryPromise2, - tryMapPromise: () => tryMapPromise2, - tryMap: () => tryMap2, - try: () => try_3, - transposeOption: () => transposeOption, - transposeMapOption: () => transposeMapOption, - transplant: () => transplant2, - tracerWith: () => tracerWith4, - tracer: () => tracer2, - timeoutTo: () => timeoutTo2, - timeoutOption: () => timeoutOption2, - timeoutFailCause: () => timeoutFailCause2, - timeoutFail: () => timeoutFail2, - timeout: () => timeout2, - timedWith: () => timedWith2, - timed: () => timed2, - tapErrorTag: () => tapErrorTag2, - tapErrorCause: () => tapErrorCause2, - tapError: () => tapError2, - tapDefect: () => tapDefect2, - tapBoth: () => tapBoth2, - tap: () => tap2, - takeWhile: () => takeWhile2, - takeUntil: () => takeUntil2, - tagMetricsScoped: () => tagMetricsScoped2, - tagMetrics: () => tagMetrics2, - sync: () => sync3, - suspend: () => suspend3, - supervised: () => supervised2, - summarized: () => summarized2, - succeedSome: () => succeedSome2, - succeedNone: () => succeedNone2, - succeed: () => succeed6, - step: () => step3, - spanLinks: () => spanLinks2, - spanAnnotations: () => spanAnnotations2, - sleep: () => sleep4, - setFiberRefs: () => setFiberRefs2, - serviceOptional: () => serviceOptional2, - serviceOption: () => serviceOption2, - serviceMembers: () => serviceMembers2, - serviceFunctions: () => serviceFunctions2, - serviceFunctionEffect: () => serviceFunctionEffect2, - serviceFunction: () => serviceFunction2, - serviceConstants: () => serviceConstants2, - sequentialFinalizers: () => sequentialFinalizers2, - scopedWith: () => scopedWith2, - scoped: () => scoped2, - scopeWith: () => scopeWith2, - scope: () => scope2, - scheduleFrom: () => scheduleFrom, - scheduleForked: () => scheduleForked2, - schedule: () => schedule, - sandbox: () => sandbox2, - runtime: () => runtime4, - runSyncExit: () => runSyncExit, - runSync: () => runSync, - runRequestBlock: () => runRequestBlock2, - runPromiseExit: () => runPromiseExit, - runPromise: () => runPromise, - runFork: () => runFork2, - runCallback: () => runCallback, - retryOrElse: () => retryOrElse, - retry: () => retry, - request: () => request, - replicateEffect: () => replicateEffect2, - replicate: () => replicate2, - repeatOrElse: () => repeatOrElse, - repeatN: () => repeatN2, - repeat: () => repeat, - reduceWhile: () => reduceWhile2, - reduceRight: () => reduceRight3, - reduceEffect: () => reduceEffect2, - reduce: () => reduce10, - randomWith: () => randomWith2, - random: () => random3, - raceWith: () => raceWith2, - raceFirst: () => raceFirst2, - raceAll: () => raceAll2, - race: () => race2, - provideServiceEffect: () => provideServiceEffect2, - provideService: () => provideService2, - provide: () => provide2, - promise: () => promise2, - patchRuntimeFlags: () => patchRuntimeFlags, - patchFiberRefs: () => patchFiberRefs2, - partition: () => partition4, - parallelFinalizers: () => parallelFinalizers2, - parallelErrors: () => parallelErrors2, - orElseSucceed: () => orElseSucceed2, - orElseFail: () => orElseFail2, - orElse: () => orElse3, - orDieWith: () => orDieWith2, - orDie: () => orDie2, - optionFromOptional: () => optionFromOptional2, - option: () => option2, - once: () => once3, - onInterrupt: () => onInterrupt2, - onExit: () => onExit3, - onError: () => onError2, - none: () => none9, - never: () => never2, - negate: () => negate2, - metricLabels: () => metricLabels2, - mergeAll: () => mergeAll5, - merge: () => merge6, - matchEffect: () => matchEffect2, - matchCauseEffect: () => matchCauseEffect3, - matchCause: () => matchCause2, - match: () => match10, - mapInputContext: () => mapInputContext2, - mapErrorCause: () => mapErrorCause2, - mapError: () => mapError2, - mapBoth: () => mapBoth3, - mapAccum: () => mapAccum3, - map: () => map11, - makeSpanScoped: () => makeSpanScoped2, - makeSpan: () => makeSpan2, - makeSemaphore: () => makeSemaphore2, - makeLatch: () => makeLatch2, - loop: () => loop2, - logWithLevel: () => logWithLevel2, - logWarning: () => logWarning2, - logTrace: () => logTrace2, - logInfo: () => logInfo2, - logFatal: () => logFatal2, - logError: () => logError2, - logDebug: () => logDebug2, - logAnnotations: () => logAnnotations2, - log: () => log2, - locallyWith: () => locallyWith, - locallyScopedWith: () => locallyScopedWith, - locallyScoped: () => locallyScoped, - locally: () => locally, - linkSpans: () => linkSpans2, - linkSpanCurrent: () => linkSpanCurrent2, - liftPredicate: () => liftPredicate2, - let: () => let_3, - labelMetricsScoped: () => labelMetricsScoped2, - labelMetrics: () => labelMetrics2, - iterate: () => iterate2, - isSuccess: () => isSuccess3, - isFailure: () => isFailure3, - isEffect: () => isEffect2, - intoDeferred: () => intoDeferred2, - interruptibleMask: () => interruptibleMask2, - interruptible: () => interruptible4, - interruptWith: () => interruptWith2, - interrupt: () => interrupt5, - inheritFiberRefs: () => inheritFiberRefs2, - ignoreLogged: () => ignoreLogged2, - ignore: () => ignore2, - if: () => if_2, - head: () => head4, - getRuntimeFlags: () => getRuntimeFlags, - getFiberRefs: () => getFiberRefs, - gen: () => gen2, - functionWithSpan: () => functionWithSpan2, - fromNullable: () => fromNullable3, - fromFiberEffect: () => fromFiberEffect2, - fromFiber: () => fromFiber2, - forkWithErrorHandler: () => forkWithErrorHandler2, - forkScoped: () => forkScoped2, - forkIn: () => forkIn2, - forkDaemon: () => forkDaemon2, - forkAll: () => forkAll2, - fork: () => fork3, - forever: () => forever3, - forEach: () => forEach7, - fnUntraced: () => fnUntraced2, - fn: () => fn, - flipWith: () => flipWith2, - flip: () => flip2, - flatten: () => flatten7, - flatMap: () => flatMap9, - firstSuccessOf: () => firstSuccessOf2, - findFirst: () => findFirst6, - finalizersMask: () => finalizersMask2, - filterOrFail: () => filterOrFail2, - filterOrElse: () => filterOrElse2, - filterOrDieMessage: () => filterOrDieMessage2, - filterOrDie: () => filterOrDie2, - filterMap: () => filterMap5, - filterEffectOrFail: () => filterEffectOrFail2, - filterEffectOrElse: () => filterEffectOrElse2, - filter: () => filter7, - fiberIdWith: () => fiberIdWith2, - fiberId: () => fiberId2, - failSync: () => failSync2, - failCauseSync: () => failCauseSync2, - failCause: () => failCause5, - fail: () => fail5, - exit: () => exit2, - exists: () => exists3, - every: () => every6, - eventually: () => eventually2, - ensuringChildren: () => ensuringChildren2, - ensuringChild: () => ensuringChild2, - ensuring: () => ensuring2, - ensureSuccessType: () => ensureSuccessType, - ensureRequirementsType: () => ensureRequirementsType, - ensureErrorType: () => ensureErrorType, - either: () => either3, - dropWhile: () => dropWhile2, - dropUntil: () => dropUntil2, - disconnect: () => disconnect2, - diffFiberRefs: () => diffFiberRefs2, - dieSync: () => dieSync2, - dieMessage: () => dieMessage2, - die: () => die4, - descriptorWith: () => descriptorWith2, - descriptor: () => descriptor2, - delay: () => delay2, - daemonChildren: () => daemonChildren2, - custom: () => custom2, - currentSpan: () => currentSpan2, - currentPropagatedSpan: () => currentPropagatedSpan2, - currentParentSpan: () => currentParentSpan2, - contextWithEffect: () => contextWithEffect2, - contextWith: () => contextWith2, - context: () => context3, - consoleWith: () => consoleWith2, - console: () => console3, - configProviderWith: () => configProviderWith2, - clockWith: () => clockWith4, - clock: () => clock2, - checkInterruptible: () => checkInterruptible2, - cause: () => cause2, - catchTags: () => catchTags2, - catchTag: () => catchTag2, - catchSomeDefect: () => catchSomeDefect2, - catchSomeCause: () => catchSomeCause2, - catchSome: () => catchSome2, - catchIf: () => catchIf2, - catchAllDefect: () => catchAllDefect2, - catchAllCause: () => catchAllCause2, - catchAll: () => catchAll2, - catch: () => _catch2, - cachedWithTTL: () => cachedWithTTL, - cachedInvalidateWithTTL: () => cachedInvalidateWithTTL2, - cachedFunction: () => cachedFunction2, - cached: () => cached3, - cacheRequestResult: () => cacheRequestResult, - blocked: () => blocked2, - bindTo: () => bindTo3, - bindAll: () => bindAll2, - bind: () => bind3, - awaitAllChildren: () => awaitAllChildren2, - asyncEffect: () => asyncEffect2, - async: () => async, - asVoid: () => asVoid3, - asSomeError: () => asSomeError2, - asSome: () => asSome2, - as: () => as3, - ap: () => ap, - annotateSpans: () => annotateSpans2, - annotateLogsScoped: () => annotateLogsScoped2, - annotateLogs: () => annotateLogs2, - annotateCurrentSpan: () => annotateCurrentSpan2, - andThen: () => andThen4, - allowInterrupt: () => allowInterrupt2, - allWith: () => allWith2, - allSuccesses: () => allSuccesses2, - all: () => all3, - addFinalizer: () => addFinalizer2, - acquireUseRelease: () => acquireUseRelease2, - acquireReleaseInterruptible: () => acquireReleaseInterruptible2, - acquireRelease: () => acquireRelease2, - Tag: () => Tag2, - Service: () => Service, - EffectTypeId: () => EffectTypeId3, - Do: () => Do2 -}); - -// node_modules/effect/dist/esm/internal/schedule/interval.js -var IntervalSymbolKey = "effect/ScheduleInterval"; -var IntervalTypeId = /* @__PURE__ */ Symbol.for(IntervalSymbolKey); -var empty27 = { - [IntervalTypeId]: IntervalTypeId, - startMillis: 0, - endMillis: 0 -}; -var make35 = (startMillis, endMillis) => { - if (startMillis > endMillis) { - return empty27; - } - return { - [IntervalTypeId]: IntervalTypeId, - startMillis, - endMillis - }; -}; -var lessThan4 = /* @__PURE__ */ dual(2, (self, that) => min2(self, that) === self); -var min2 = /* @__PURE__ */ dual(2, (self, that) => { - if (self.endMillis <= that.startMillis) - return self; - if (that.endMillis <= self.startMillis) - return that; - if (self.startMillis < that.startMillis) - return self; - if (that.startMillis < self.startMillis) - return that; - if (self.endMillis <= that.endMillis) - return self; - return that; -}); -var isEmpty7 = (self) => { - return self.startMillis >= self.endMillis; -}; -var intersect = /* @__PURE__ */ dual(2, (self, that) => { - const start = Math.max(self.startMillis, that.startMillis); - const end = Math.min(self.endMillis, that.endMillis); - return make35(start, end); -}); -var after = (startMilliseconds) => { - return make35(startMilliseconds, Number.POSITIVE_INFINITY); -}; - -// node_modules/effect/dist/esm/ScheduleInterval.js -var empty28 = empty27; -var lessThan5 = lessThan4; -var isEmpty8 = isEmpty7; -var intersect2 = intersect; -var after2 = after; - -// node_modules/effect/dist/esm/internal/schedule/intervals.js -var IntervalsSymbolKey = "effect/ScheduleIntervals"; -var IntervalsTypeId = /* @__PURE__ */ Symbol.for(IntervalsSymbolKey); -var make37 = (intervals) => { - return { - [IntervalsTypeId]: IntervalsTypeId, - intervals - }; -}; -var intersect3 = /* @__PURE__ */ dual(2, (self, that) => intersectLoop(self.intervals, that.intervals, empty4())); -var intersectLoop = (_left, _right, _acc) => { - let left3 = _left; - let right3 = _right; - let acc = _acc; - while (isNonEmpty2(left3) && isNonEmpty2(right3)) { - const interval = pipe(headNonEmpty2(left3), intersect2(headNonEmpty2(right3))); - const intervals = isEmpty8(interval) ? acc : pipe(acc, prepend2(interval)); - if (pipe(headNonEmpty2(left3), lessThan5(headNonEmpty2(right3)))) { - left3 = tailNonEmpty2(left3); - } else { - right3 = tailNonEmpty2(right3); - } - acc = intervals; - } - return make37(reverse2(acc)); -}; -var start = (self) => { - return pipe(self.intervals, head2, getOrElse(() => empty28)).startMillis; -}; -var end = (self) => { - return pipe(self.intervals, head2, getOrElse(() => empty28)).endMillis; -}; -var lessThan6 = /* @__PURE__ */ dual(2, (self, that) => start(self) < start(that)); -var isNonEmpty4 = (self) => { - return isNonEmpty2(self.intervals); -}; - -// node_modules/effect/dist/esm/ScheduleIntervals.js -var make38 = make37; -var intersect4 = intersect3; -var start2 = start; -var end2 = end; -var lessThan7 = lessThan6; -var isNonEmpty5 = isNonEmpty4; - -// node_modules/effect/dist/esm/internal/schedule/decision.js -var OP_CONTINUE = "Continue"; -var OP_DONE2 = "Done"; -var _continue = (intervals) => { - return { - _tag: OP_CONTINUE, - intervals - }; -}; -var continueWith = (interval) => { - return { - _tag: OP_CONTINUE, - intervals: make38(of2(interval)) - }; -}; -var done5 = { - _tag: OP_DONE2 -}; -var isContinue = (self) => { - return self._tag === OP_CONTINUE; -}; -var isDone3 = (self) => { - return self._tag === OP_DONE2; -}; - -// node_modules/effect/dist/esm/ScheduleDecision.js -var _continue2 = _continue; -var continueWith2 = continueWith; -var done6 = done5; -var isContinue2 = isContinue; -var isDone4 = isDone3; - -// node_modules/effect/dist/esm/Scope.js -var close = scopeClose; -var fork2 = scopeFork; - -// node_modules/effect/dist/esm/internal/effect/circular.js -class Semaphore { - permits; - waiters = /* @__PURE__ */ new Set; - taken = 0; - constructor(permits) { - this.permits = permits; - } - get free() { - return this.permits - this.taken; - } - take = (n) => asyncInterrupt((resume2) => { - if (this.free < n) { - const observer = () => { - if (this.free < n) - return; - this.waiters.delete(observer); - resume2(suspend(() => { - if (this.free < n) - return this.take(n); - this.taken += n; - return succeed(n); - })); - }; - this.waiters.add(observer); - return sync(() => { - this.waiters.delete(observer); - }); - } - resume2(suspend(() => { - if (this.free < n) - return this.take(n); - this.taken += n; - return succeed(n); - })); - }); - updateTakenUnsafe(fiber, f) { - this.taken = f(this.taken); - if (this.waiters.size > 0) { - fiber.getFiberRef(currentScheduler).scheduleTask(() => { - const iter = this.waiters.values(); - let item = iter.next(); - while (item.done === false && this.free > 0) { - item.value(); - item = iter.next(); - } - }, fiber.getFiberRef(currentSchedulingPriority), fiber); - } - return succeed(this.free); - } - updateTaken(f) { - return withFiberRuntime((fiber) => this.updateTakenUnsafe(fiber, f)); - } - resize = (permits) => asVoid(withFiberRuntime((fiber) => { - this.permits = permits; - if (this.free < 0) { - return void_; - } - return this.updateTakenUnsafe(fiber, (taken) => taken); - })); - release = (n) => this.updateTaken((taken) => taken - n); - releaseAll = /* @__PURE__ */ this.updateTaken((_) => 0); - withPermits = (n) => (self) => uninterruptibleMask((restore) => flatMap7(restore(this.take(n)), (permits) => ensuring(restore(self), this.release(permits)))); - withPermitsIfAvailable = (n) => (self) => uninterruptibleMask((restore) => suspend(() => { - if (this.free < n) { - return succeedNone; - } - this.taken += n; - return ensuring(restore(asSome(self)), this.release(n)); - })); -} -var unsafeMakeSemaphore = (permits) => new Semaphore(permits); -var makeSemaphore = (permits) => sync(() => unsafeMakeSemaphore(permits)); - -class Latch extends Class { - isOpen; - waiters = []; - scheduled = false; - constructor(isOpen) { - super(); - this.isOpen = isOpen; - } - commit() { - return this.await; - } - unsafeSchedule(fiber) { - if (this.scheduled || this.waiters.length === 0) { - return void_; - } - this.scheduled = true; - fiber.currentScheduler.scheduleTask(this.flushWaiters, fiber.getFiberRef(currentSchedulingPriority), fiber); - return void_; - } - flushWaiters = () => { - this.scheduled = false; - const waiters = this.waiters; - this.waiters = []; - for (let i = 0;i < waiters.length; i++) { - waiters[i](exitVoid); - } - }; - open = /* @__PURE__ */ withFiberRuntime((fiber) => { - if (this.isOpen) { - return void_; - } - this.isOpen = true; - return this.unsafeSchedule(fiber); - }); - unsafeOpen() { - if (this.isOpen) - return; - this.isOpen = true; - this.flushWaiters(); - } - release = /* @__PURE__ */ withFiberRuntime((fiber) => { - if (this.isOpen) { - return void_; - } - return this.unsafeSchedule(fiber); - }); - await = /* @__PURE__ */ asyncInterrupt((resume2) => { - if (this.isOpen) { - return resume2(void_); - } - this.waiters.push(resume2); - return sync(() => { - const index = this.waiters.indexOf(resume2); - if (index !== -1) { - this.waiters.splice(index, 1); - } - }); - }); - unsafeClose() { - this.isOpen = false; - } - close = /* @__PURE__ */ sync(() => { - this.isOpen = false; - }); - whenOpen = (self) => { - return zipRight(this.await, self); - }; -} -var unsafeMakeLatch = (open) => new Latch(open ?? false); -var makeLatch = (open) => sync(() => unsafeMakeLatch(open)); -var awaitAllChildren = (self) => ensuringChildren(self, fiberAwaitAll); -var cached2 = /* @__PURE__ */ dual(2, (self, timeToLive) => map9(cachedInvalidateWithTTL(self, timeToLive), (tuple) => tuple[0])); -var cachedInvalidateWithTTL = /* @__PURE__ */ dual(2, (self, timeToLive) => { - const duration = decode(timeToLive); - return flatMap7(context(), (env) => map9(makeSynchronized(none2()), (cache) => [provideContext(getCachedValue(self, duration, cache), env), invalidateCache(cache)])); -}); -var computeCachedValue = (self, timeToLive, start3) => { - const timeToLiveMillis = toMillis(decode(timeToLive)); - return pipe(deferredMake(), tap((deferred) => intoDeferred(self, deferred)), map9((deferred) => some2([start3 + timeToLiveMillis, deferred]))); -}; -var getCachedValue = (self, timeToLive, cache) => uninterruptibleMask((restore) => pipe(clockWith3((clock2) => clock2.currentTimeMillis), flatMap7((time) => updateSomeAndGetEffectSynchronized(cache, (option2) => { - switch (option2._tag) { - case "None": { - return some2(computeCachedValue(self, timeToLive, time)); - } - case "Some": { - const [end3] = option2.value; - return end3 - time <= 0 ? some2(computeCachedValue(self, timeToLive, time)) : none2(); - } - } -})), flatMap7((option2) => isNone2(option2) ? dieMessage("BUG: Effect.cachedInvalidate - please report an issue at https://github.com/Effect-TS/effect/issues") : restore(deferredAwait(option2.value[1]))))); -var invalidateCache = (cache) => set5(cache, none2()); -var ensuringChild = /* @__PURE__ */ dual(2, (self, f) => ensuringChildren(self, (children) => f(fiberAll(children)))); -var ensuringChildren = /* @__PURE__ */ dual(2, (self, children) => flatMap7(track, (supervisor) => pipe(supervised(self, supervisor), ensuring(flatMap7(supervisor.value, children))))); -var forkAll = /* @__PURE__ */ dual((args2) => isIterable(args2[0]), (effects, options) => options?.discard ? forEachSequentialDiscard(effects, fork) : map9(forEachSequential(effects, fork), fiberAll)); -var forkIn = /* @__PURE__ */ dual(2, (self, scope2) => withFiberRuntime((parent, parentStatus) => { - const scopeImpl = scope2; - const fiber = unsafeFork(self, parent, parentStatus.runtimeFlags, globalScope); - if (scopeImpl.state._tag === "Open") { - const finalizer = () => fiberIdWith((fiberId2) => equals(fiberId2, fiber.id()) ? void_ : asVoid(interruptFiber(fiber))); - const key = {}; - scopeImpl.state.finalizers.set(key, finalizer); - fiber.addObserver(() => { - if (scopeImpl.state._tag === "Closed") - return; - scopeImpl.state.finalizers.delete(key); - }); - } else { - fiber.unsafeInterruptAsFork(parent.id()); - } - return succeed(fiber); -})); -var forkScoped = (self) => scopeWith((scope2) => forkIn(self, scope2)); -var fromFiber = (fiber) => join2(fiber); -var fromFiberEffect = (fiber) => suspend(() => flatMap7(fiber, join2)); -var memoKeySymbol = /* @__PURE__ */ Symbol.for("effect/Effect/memoizeFunction.key"); - -class Key { - a; - eq; - [memoKeySymbol] = memoKeySymbol; - constructor(a, eq) { - this.a = a; - this.eq = eq; - } - [symbol2](that) { - if (hasProperty(that, memoKeySymbol)) { - if (this.eq) { - return this.eq(this.a, that.a); - } else { - return equals(this.a, that.a); - } - } - return false; - } - [symbol]() { - return this.eq ? 0 : cached(this, hash(this.a)); - } -} -var cachedFunction = (f, eq) => { - return pipe(sync(() => empty17()), flatMap7(makeSynchronized), map9((ref) => (a) => pipe(ref.modifyEffect((map10) => { - const result = pipe(map10, get8(new Key(a, eq))); - if (isNone2(result)) { - return pipe(deferredMake(), tap((deferred) => pipe(diffFiberRefs(f(a)), intoDeferred(deferred), fork)), map9((deferred) => [deferred, pipe(map10, set4(new Key(a, eq), deferred))])); - } - return succeed([result.value, map10]); - }), flatMap7(deferredAwait), flatMap7(([patch9, b]) => pipe(patchFiberRefs(patch9), as(b)))))); -}; -var raceFirst = /* @__PURE__ */ dual(2, (self, that) => pipe(exit(self), race(exit(that)), (effect) => flatten5(effect))); -var supervised = /* @__PURE__ */ dual(2, (self, supervisor) => { - const supervise = fiberRefLocallyWith(currentSupervisor, (s) => s.zip(supervisor)); - return supervise(self); -}); -var timeout = /* @__PURE__ */ dual(2, (self, duration) => timeoutFail(self, { - onTimeout: () => timeoutExceptionFromDuration(duration), - duration -})); -var timeoutFail = /* @__PURE__ */ dual(2, (self, { - duration, - onTimeout -}) => flatten5(timeoutTo(self, { - onTimeout: () => failSync(onTimeout), - onSuccess: succeed, - duration -}))); -var timeoutFailCause = /* @__PURE__ */ dual(2, (self, { - duration, - onTimeout -}) => flatten5(timeoutTo(self, { - onTimeout: () => failCauseSync(onTimeout), - onSuccess: succeed, - duration -}))); -var timeoutOption = /* @__PURE__ */ dual(2, (self, duration) => timeoutTo(self, { - duration, - onSuccess: some2, - onTimeout: none2 -})); -var timeoutTo = /* @__PURE__ */ dual(2, (self, { - duration, - onSuccess, - onTimeout -}) => fiberIdWith((parentFiberId) => uninterruptibleMask((restore) => raceFibersWith(restore(self), interruptible2(sleep3(duration)), { - onSelfWin: (winner, loser) => flatMap7(winner.await, (exit2) => { - if (exit2._tag === "Success") { - return flatMap7(winner.inheritAll, () => as(interruptAsFiber(loser, parentFiberId), onSuccess(exit2.value))); - } else { - return flatMap7(interruptAsFiber(loser, parentFiberId), () => exitFailCause(exit2.cause)); - } - }), - onOtherWin: (winner, loser) => flatMap7(winner.await, (exit2) => { - if (exit2._tag === "Success") { - return flatMap7(winner.inheritAll, () => as(interruptAsFiber(loser, parentFiberId), onTimeout())); - } else { - return flatMap7(interruptAsFiber(loser, parentFiberId), () => exitFailCause(exit2.cause)); - } - }), - otherScope: globalScope -})))); -var SynchronizedSymbolKey = "effect/Ref/SynchronizedRef"; -var SynchronizedTypeId = /* @__PURE__ */ Symbol.for(SynchronizedSymbolKey); -var synchronizedVariance = { - _A: (_) => _ -}; - -class SynchronizedImpl extends Class { - ref; - withLock; - [SynchronizedTypeId] = synchronizedVariance; - [RefTypeId] = refVariance; - [TypeId13] = TypeId13; - constructor(ref, withLock) { - super(); - this.ref = ref; - this.withLock = withLock; - this.get = get11(this.ref); - } - get; - commit() { - return this.get; - } - modify(f) { - return this.modifyEffect((a) => succeed(f(a))); - } - modifyEffect(f) { - return this.withLock(pipe(flatMap7(get11(this.ref), f), flatMap7(([b, a]) => as(set5(this.ref, a), b)))); - } -} -var makeSynchronized = (value) => sync(() => unsafeMakeSynchronized(value)); -var unsafeMakeSynchronized = (value) => { - const ref = unsafeMake5(value); - const sem = unsafeMakeSemaphore(1); - return new SynchronizedImpl(ref, sem.withPermits(1)); -}; -var updateSomeAndGetEffectSynchronized = /* @__PURE__ */ dual(2, (self, pf) => self.modifyEffect((value) => { - const result = pf(value); - switch (result._tag) { - case "None": { - return succeed([value, value]); - } - case "Some": { - return map9(result.value, (a) => [a, a]); - } - } -})); -var bindAll = /* @__PURE__ */ dual((args2) => isEffect(args2[0]), (self, f, options) => flatMap7(self, (a) => all2(f(a), options).pipe(map9((record2) => Object.assign({}, a, record2))))); - -// node_modules/effect/dist/esm/internal/managedRuntime/circular.js -var TypeId16 = /* @__PURE__ */ Symbol.for("effect/ManagedRuntime"); - -// node_modules/effect/dist/esm/internal/opCodes/layer.js -var OP_FRESH = "Fresh"; -var OP_FROM_EFFECT = "FromEffect"; -var OP_SCOPED = "Scoped"; -var OP_SUSPEND = "Suspend"; -var OP_PROVIDE = "Provide"; -var OP_PROVIDE_MERGE = "ProvideMerge"; -var OP_MERGE_ALL = "MergeAll"; - -// node_modules/effect/dist/esm/Fiber.js -var interruptAs = interruptAsFiber; - -// node_modules/effect/dist/esm/internal/runtime.js -var makeDual = (f) => function() { - if (arguments.length === 1) { - const runtime3 = arguments[0]; - return (effect, ...args2) => f(runtime3, effect, ...args2); - } - return f.apply(this, arguments); -}; -var unsafeFork2 = /* @__PURE__ */ makeDual((runtime3, self, options) => { - const fiberId2 = unsafeMake2(); - const fiberRefUpdates = [[currentContext, [[fiberId2, runtime3.context]]]]; - if (options?.scheduler) { - fiberRefUpdates.push([currentScheduler, [[fiberId2, options.scheduler]]]); - } - let fiberRefs3 = updateManyAs2(runtime3.fiberRefs, { - entries: fiberRefUpdates, - forkAs: fiberId2 - }); - if (options?.updateRefs) { - fiberRefs3 = options.updateRefs(fiberRefs3, fiberId2); - } - const fiberRuntime = new FiberRuntime(fiberId2, fiberRefs3, runtime3.runtimeFlags); - let effect = self; - if (options?.scope) { - effect = flatMap7(fork2(options.scope, sequential2), (closeableScope) => zipRight(scopeAddFinalizer(closeableScope, fiberIdWith((id) => equals(id, fiberRuntime.id()) ? void_ : interruptAsFiber(fiberRuntime, id))), onExit(self, (exit2) => close(closeableScope, exit2)))); - } - const supervisor = fiberRuntime.currentSupervisor; - if (supervisor !== none8) { - supervisor.onStart(runtime3.context, effect, none2(), fiberRuntime); - fiberRuntime.addObserver((exit2) => supervisor.onEnd(exit2, fiberRuntime)); - } - globalScope.add(runtime3.runtimeFlags, fiberRuntime); - if (options?.immediate === false) { - fiberRuntime.resume(effect); - } else { - fiberRuntime.start(effect); - } - return fiberRuntime; -}); -var unsafeRunCallback = /* @__PURE__ */ makeDual((runtime3, effect, options = {}) => { - const fiberRuntime = unsafeFork2(runtime3, effect, options); - if (options.onExit) { - fiberRuntime.addObserver((exit2) => { - options.onExit(exit2); - }); - } - return (id, cancelOptions) => unsafeRunCallback(runtime3)(pipe(fiberRuntime, interruptAs(id ?? none4)), { - ...cancelOptions, - onExit: cancelOptions?.onExit ? (exit2) => cancelOptions.onExit(flatten6(exit2)) : undefined - }); -}); -var unsafeRunSync = /* @__PURE__ */ makeDual((runtime3, effect) => { - const result = unsafeRunSyncExit(runtime3)(effect); - if (result._tag === "Failure") { - throw fiberFailure(result.effect_instruction_i0); - } - return result.effect_instruction_i0; -}); - -class AsyncFiberExceptionImpl extends Error { - fiber; - _tag = "AsyncFiberException"; - constructor(fiber) { - super(`Fiber #${fiber.id().id} cannot be resolved synchronously. This is caused by using runSync on an effect that performs async work`); - this.fiber = fiber; - this.name = this._tag; - this.stack = this.message; - } -} -var asyncFiberException = (fiber) => { - const limit = Error.stackTraceLimit; - Error.stackTraceLimit = 0; - const error = new AsyncFiberExceptionImpl(fiber); - Error.stackTraceLimit = limit; - return error; -}; -var FiberFailureId = /* @__PURE__ */ Symbol.for("effect/Runtime/FiberFailure"); -var FiberFailureCauseId = /* @__PURE__ */ Symbol.for("effect/Runtime/FiberFailure/Cause"); - -class FiberFailureImpl extends Error { - [FiberFailureId]; - [FiberFailureCauseId]; - constructor(cause2) { - const head4 = prettyErrors(cause2)[0]; - super(head4?.message || "An error has occurred"); - this[FiberFailureId] = FiberFailureId; - this[FiberFailureCauseId] = cause2; - this.name = head4 ? `(FiberFailure) ${head4.name}` : "FiberFailure"; - if (head4?.stack) { - this.stack = head4.stack; - } - } - toJSON() { - return { - _id: "FiberFailure", - cause: this[FiberFailureCauseId].toJSON() - }; - } - toString() { - return "(FiberFailure) " + pretty(this[FiberFailureCauseId], { - renderErrorCause: true - }); - } - [NodeInspectSymbol]() { - return this.toString(); - } -} -var fiberFailure = (cause2) => { - const limit = Error.stackTraceLimit; - Error.stackTraceLimit = 0; - const error = new FiberFailureImpl(cause2); - Error.stackTraceLimit = limit; - return error; -}; -var fastPath = (effect) => { - const op = effect; - switch (op._op) { - case "Failure": - case "Success": { - return op; - } - case "Left": { - return exitFail(op.left); - } - case "Right": { - return exitSucceed(op.right); - } - case "Some": { - return exitSucceed(op.value); - } - case "None": { - return exitFail(new NoSuchElementException); - } - } -}; -var unsafeRunSyncExit = /* @__PURE__ */ makeDual((runtime3, effect) => { - const op = fastPath(effect); - if (op) { - return op; - } - const scheduler = new SyncScheduler; - const fiberRuntime = unsafeFork2(runtime3)(effect, { - scheduler - }); - scheduler.flush(); - const result = fiberRuntime.unsafePoll(); - if (result) { - return result; - } - return exitDie(capture(asyncFiberException(fiberRuntime), currentSpanFromFiber(fiberRuntime))); -}); -var unsafeRunPromise = /* @__PURE__ */ makeDual((runtime3, effect, options) => unsafeRunPromiseExit(runtime3, effect, options).then((result) => { - switch (result._tag) { - case OP_SUCCESS: { - return result.effect_instruction_i0; - } - case OP_FAILURE: { - throw fiberFailure(result.effect_instruction_i0); - } - } -})); -var unsafeRunPromiseExit = /* @__PURE__ */ makeDual((runtime3, effect, options) => new Promise((resolve) => { - const op = fastPath(effect); - if (op) { - resolve(op); - } - const fiber = unsafeFork2(runtime3)(effect); - fiber.addObserver((exit2) => { - resolve(exit2); - }); - if (options?.signal !== undefined) { - if (options.signal.aborted) { - fiber.unsafeInterruptAsFork(fiber.id()); - } else { - options.signal.addEventListener("abort", () => { - fiber.unsafeInterruptAsFork(fiber.id()); - }, { - once: true - }); - } - } -})); - -class RuntimeImpl { - context; - runtimeFlags; - fiberRefs; - constructor(context2, runtimeFlags2, fiberRefs3) { - this.context = context2; - this.runtimeFlags = runtimeFlags2; - this.fiberRefs = fiberRefs3; - } - pipe() { - return pipeArguments(this, arguments); - } -} -var make39 = (options) => new RuntimeImpl(options.context, options.runtimeFlags, options.fiberRefs); -var runtime3 = () => withFiberRuntime((state, status) => succeed(new RuntimeImpl(state.getFiberRef(currentContext), status.runtimeFlags, state.getFiberRefs()))); -var defaultRuntimeFlags = /* @__PURE__ */ make17(Interruption, CooperativeYielding, RuntimeMetrics); -var defaultRuntime = /* @__PURE__ */ make39({ - context: /* @__PURE__ */ empty3(), - runtimeFlags: defaultRuntimeFlags, - fiberRefs: /* @__PURE__ */ empty21() -}); -var unsafeRunEffect = /* @__PURE__ */ unsafeRunCallback(defaultRuntime); -var unsafeForkEffect = /* @__PURE__ */ unsafeFork2(defaultRuntime); -var unsafeRunPromiseEffect = /* @__PURE__ */ unsafeRunPromise(defaultRuntime); -var unsafeRunPromiseExitEffect = /* @__PURE__ */ unsafeRunPromiseExit(defaultRuntime); -var unsafeRunSyncEffect = /* @__PURE__ */ unsafeRunSync(defaultRuntime); -var unsafeRunSyncExitEffect = /* @__PURE__ */ unsafeRunSyncExit(defaultRuntime); -var asyncEffect = (register) => suspend(() => { - let cleanup = undefined; - return flatMap7(deferredMake(), (deferred) => flatMap7(runtime3(), (runtime4) => uninterruptibleMask((restore) => zipRight(fork(restore(matchCauseEffect(register((cb) => unsafeRunCallback(runtime4)(intoDeferred(cb, deferred))), { - onFailure: (cause2) => deferredFailCause(deferred, cause2), - onSuccess: (cleanup_) => { - cleanup = cleanup_; - return void_; - } - }))), restore(onInterrupt(deferredAwait(deferred), () => cleanup ?? void_)))))); -}); - -// node_modules/effect/dist/esm/internal/synchronizedRef.js -var modifyEffect = /* @__PURE__ */ dual(2, (self, f) => self.modifyEffect(f)); - -// node_modules/effect/dist/esm/internal/layer.js -var LayerSymbolKey = "effect/Layer"; -var LayerTypeId = /* @__PURE__ */ Symbol.for(LayerSymbolKey); -var layerVariance = { - _RIn: (_) => _, - _E: (_) => _, - _ROut: (_) => _ -}; -var proto3 = { - [LayerTypeId]: layerVariance, - pipe() { - return pipeArguments(this, arguments); - } -}; -var MemoMapTypeIdKey = "effect/Layer/MemoMap"; -var MemoMapTypeId = /* @__PURE__ */ Symbol.for(MemoMapTypeIdKey); -var CurrentMemoMap = /* @__PURE__ */ Reference2()("effect/Layer/CurrentMemoMap", { - defaultValue: () => unsafeMakeMemoMap() -}); -var isLayer = (u) => hasProperty(u, LayerTypeId); -var isFresh = (self) => { - return self._op_layer === OP_FRESH; -}; - -class MemoMapImpl { - ref; - [MemoMapTypeId]; - constructor(ref) { - this.ref = ref; - this[MemoMapTypeId] = MemoMapTypeId; - } - getOrElseMemoize(layer, scope2) { - return pipe(modifyEffect(this.ref, (map10) => { - const inMap = map10.get(layer); - if (inMap !== undefined) { - const [acquire, release] = inMap; - const cached3 = pipe(acquire, flatMap7(([patch9, b]) => pipe(patchFiberRefs(patch9), as(b))), onExit(exitMatch({ - onFailure: () => void_, - onSuccess: () => scopeAddFinalizerExit(scope2, release) - }))); - return succeed([cached3, map10]); - } - return pipe(make27(0), flatMap7((observers) => pipe(deferredMake(), flatMap7((deferred) => pipe(make27(() => void_), map9((finalizerRef) => { - const resource = uninterruptibleMask((restore) => pipe(scopeMake(), flatMap7((innerScope) => pipe(restore(flatMap7(makeBuilder(layer, innerScope, true), (f) => diffFiberRefs(f(this)))), exit, flatMap7((exit2) => { - switch (exit2._tag) { - case OP_FAILURE: { - return pipe(deferredFailCause(deferred, exit2.effect_instruction_i0), zipRight(scopeClose(innerScope, exit2)), zipRight(failCause(exit2.effect_instruction_i0))); - } - case OP_SUCCESS: { - return pipe(set5(finalizerRef, (exit3) => pipe(scopeClose(innerScope, exit3), whenEffect(modify3(observers, (n) => [n === 1, n - 1])), asVoid)), zipRight(update2(observers, (n) => n + 1)), zipRight(scopeAddFinalizerExit(scope2, (exit3) => pipe(sync(() => map10.delete(layer)), zipRight(get11(finalizerRef)), flatMap7((finalizer) => finalizer(exit3))))), zipRight(deferredSucceed(deferred, exit2.effect_instruction_i0)), as(exit2.effect_instruction_i0[1])); - } - } - }))))); - const memoized = [pipe(deferredAwait(deferred), onExit(exitMatchEffect({ - onFailure: () => void_, - onSuccess: () => update2(observers, (n) => n + 1) - }))), (exit2) => pipe(get11(finalizerRef), flatMap7((finalizer) => finalizer(exit2)))]; - return [resource, isFresh(layer) ? map10 : map10.set(layer, memoized)]; - })))))); - }), flatten5); - } -} -var makeMemoMap = /* @__PURE__ */ suspend(() => map9(makeSynchronized(new Map), (ref) => new MemoMapImpl(ref))); -var unsafeMakeMemoMap = () => new MemoMapImpl(unsafeMakeSynchronized(new Map)); -var buildWithScope = /* @__PURE__ */ dual(2, (self, scope2) => flatMap7(makeMemoMap, (memoMap) => buildWithMemoMap(self, memoMap, scope2))); -var buildWithMemoMap = /* @__PURE__ */ dual(3, (self, memoMap, scope2) => flatMap7(makeBuilder(self, scope2), (run) => provideService(run(memoMap), CurrentMemoMap, memoMap))); -var makeBuilder = (self, scope2, inMemoMap = false) => { - const op = self; - switch (op._op_layer) { - case "Locally": { - return sync(() => (memoMap) => op.f(memoMap.getOrElseMemoize(op.self, scope2))); - } - case "ExtendScope": { - return sync(() => (memoMap) => scopeWith((scope3) => memoMap.getOrElseMemoize(op.layer, scope3))); - } - case "Fold": { - return sync(() => (memoMap) => pipe(memoMap.getOrElseMemoize(op.layer, scope2), matchCauseEffect({ - onFailure: (cause2) => memoMap.getOrElseMemoize(op.failureK(cause2), scope2), - onSuccess: (value) => memoMap.getOrElseMemoize(op.successK(value), scope2) - }))); - } - case "Fresh": { - return sync(() => (_) => pipe(op.layer, buildWithScope(scope2))); - } - case "FromEffect": { - return inMemoMap ? sync(() => (_) => op.effect) : sync(() => (memoMap) => memoMap.getOrElseMemoize(self, scope2)); - } - case "Provide": { - return sync(() => (memoMap) => pipe(memoMap.getOrElseMemoize(op.first, scope2), flatMap7((env) => pipe(memoMap.getOrElseMemoize(op.second, scope2), provideContext(env))))); - } - case "Scoped": { - return inMemoMap ? sync(() => (_) => scopeExtend(op.effect, scope2)) : sync(() => (memoMap) => memoMap.getOrElseMemoize(self, scope2)); - } - case "Suspend": { - return sync(() => (memoMap) => memoMap.getOrElseMemoize(op.evaluate(), scope2)); - } - case "ProvideMerge": { - return sync(() => (memoMap) => pipe(memoMap.getOrElseMemoize(op.first, scope2), zipWith2(memoMap.getOrElseMemoize(op.second, scope2), op.zipK))); - } - case "ZipWith": { - return gen(function* () { - const parallelScope = yield* scopeFork(scope2, parallel2); - const firstScope = yield* scopeFork(parallelScope, sequential2); - const secondScope = yield* scopeFork(parallelScope, sequential2); - return (memoMap) => pipe(memoMap.getOrElseMemoize(op.first, firstScope), zipWithOptions(memoMap.getOrElseMemoize(op.second, secondScope), op.zipK, { - concurrent: true - })); - }); - } - case "MergeAll": { - const layers = op.layers; - return map9(scopeFork(scope2, parallel2), (parallelScope) => (memoMap) => { - const contexts = new Array(layers.length); - return map9(forEachConcurrentDiscard(layers, fnUntraced(function* (layer, i) { - const scope3 = yield* scopeFork(parallelScope, sequential2); - const context2 = yield* memoMap.getOrElseMemoize(layer, scope3); - contexts[i] = context2; - }), false, false), () => mergeAll2(...contexts)); - }); - } - } -}; -var context2 = () => fromEffectContext(context()); -var fromEffect2 = /* @__PURE__ */ dual(2, (a, b) => { - const tagFirst = isTag2(a); - const tag = tagFirst ? a : b; - const effect = tagFirst ? b : a; - return fromEffectContext(map9(effect, (service) => make6(tag, service))); -}); -function fromEffectContext(effect) { - const fromEffect3 = Object.create(proto3); - fromEffect3._op_layer = OP_FROM_EFFECT; - fromEffect3.effect = effect; - return fromEffect3; -} -var mergeAll4 = (...layers) => { - const mergeAll5 = Object.create(proto3); - mergeAll5._op_layer = OP_MERGE_ALL; - mergeAll5.layers = layers; - return mergeAll5; -}; -var scoped = /* @__PURE__ */ dual(2, (a, b) => { - const tagFirst = isTag2(a); - const tag = tagFirst ? a : b; - const effect = tagFirst ? b : a; - return scopedContext(map9(effect, (service) => make6(tag, service))); -}); -var scopedContext = (effect) => { - const scoped2 = Object.create(proto3); - scoped2._op_layer = OP_SCOPED; - scoped2.effect = effect; - return scoped2; -}; -var succeed4 = /* @__PURE__ */ dual(2, (a, b) => { - const tagFirst = isTag2(a); - const tag = tagFirst ? a : b; - const resource = tagFirst ? b : a; - return fromEffectContext(succeed(make6(tag, resource))); -}); -var suspend2 = (evaluate2) => { - const suspend3 = Object.create(proto3); - suspend3._op_layer = OP_SUSPEND; - suspend3.evaluate = evaluate2; - return suspend3; -}; -var sync2 = /* @__PURE__ */ dual(2, (a, b) => { - const tagFirst = isTag2(a); - const tag = tagFirst ? a : b; - const evaluate2 = tagFirst ? b : a; - return fromEffectContext(sync(() => make6(tag, evaluate2()))); -}); -var provide = /* @__PURE__ */ dual(2, (self, that) => suspend2(() => { - const provideTo = Object.create(proto3); - provideTo._op_layer = OP_PROVIDE; - provideTo.first = Object.create(proto3, { - _op_layer: { - value: OP_PROVIDE_MERGE, - enumerable: true - }, - first: { - value: context2(), - enumerable: true - }, - second: { - value: Array.isArray(that) ? mergeAll4(...that) : that - }, - zipK: { - value: (a, b) => pipe(a, merge3(b)) - } - }); - provideTo.second = self; - return provideTo; -})); -var provideSomeLayer = /* @__PURE__ */ dual(2, (self, layer) => scopedWith((scope2) => flatMap7(buildWithScope(layer, scope2), (context3) => provideSomeContext(self, context3)))); -var provideSomeRuntime = /* @__PURE__ */ dual(2, (self, rt) => { - const patchRefs = diff6(defaultRuntime.fiberRefs, rt.fiberRefs); - const patchFlags = diff4(defaultRuntime.runtimeFlags, rt.runtimeFlags); - return uninterruptibleMask((restore) => withFiberRuntime((fiber) => { - const oldContext = fiber.getFiberRef(currentContext); - const oldRefs = fiber.getFiberRefs(); - const newRefs = patch7(fiber.id(), oldRefs)(patchRefs); - const oldFlags = fiber.currentRuntimeFlags; - const newFlags = patch4(patchFlags)(oldFlags); - const rollbackRefs = diff6(newRefs, oldRefs); - const rollbackFlags = diff4(newFlags, oldFlags); - fiber.setFiberRefs(newRefs); - fiber.currentRuntimeFlags = newFlags; - return ensuring(provideSomeContext(restore(self), merge3(oldContext, rt.context)), withFiberRuntime((fiber2) => { - fiber2.setFiberRefs(patch7(fiber2.id(), fiber2.getFiberRefs())(rollbackRefs)); - fiber2.currentRuntimeFlags = patch4(rollbackFlags)(fiber2.currentRuntimeFlags); - return void_; - })); - })); -}); -var effect_provide = /* @__PURE__ */ dual(2, (self, source) => { - if (Array.isArray(source)) { - return provideSomeLayer(self, mergeAll4(...source)); - } else if (isLayer(source)) { - return provideSomeLayer(self, source); - } else if (isContext2(source)) { - return provideSomeContext(self, source); - } else if (TypeId16 in source) { - return flatMap7(source.runtimeEffect, (rt) => provideSomeRuntime(self, rt)); - } else { - return provideSomeRuntime(self, source); - } -}); - -// node_modules/effect/dist/esm/internal/console.js -var console2 = /* @__PURE__ */ map9(/* @__PURE__ */ fiberRefGet(currentServices), /* @__PURE__ */ get3(consoleTag)); -var consoleWith = (f) => fiberRefGetWith(currentServices, (services) => f(get3(services, consoleTag))); -var withConsole = /* @__PURE__ */ dual(2, (effect, value) => fiberRefLocallyWith(effect, currentServices, add2(consoleTag, value))); -var withConsoleScoped = (console3) => fiberRefLocallyScopedWith(currentServices, add2(consoleTag, console3)); - -// node_modules/effect/dist/esm/Data.js -var exports_Data = {}; -__export(exports_Data, { - unsafeStruct: () => unsafeStruct, - unsafeArray: () => unsafeArray, - tuple: () => tuple, - taggedEnum: () => taggedEnum, - tagged: () => tagged2, - struct: () => struct2, - case: () => _case, - array: () => array4, - TaggedError: () => TaggedError, - TaggedClass: () => TaggedClass, - Structural: () => Structural2, - Error: () => Error3, - Class: () => Class3 -}); -var struct2 = struct; -var unsafeStruct = (as3) => Object.setPrototypeOf(as3, StructuralPrototype); -var tuple = (...as3) => unsafeArray(as3); -var array4 = (as3) => unsafeArray(as3.slice(0)); -var unsafeArray = (as3) => Object.setPrototypeOf(as3, ArrayProto); -var _case = () => (args2) => args2 === undefined ? Object.create(StructuralPrototype) : struct2(args2); -var tagged2 = (tag) => (args2) => { - const value = args2 === undefined ? Object.create(StructuralPrototype) : struct2(args2); - value._tag = tag; - return value; -}; -var Class3 = Structural; -var TaggedClass = (tag) => { - - class Base3 extends Class3 { - _tag = tag; - } - return Base3; -}; -var Structural2 = Structural; -var taggedEnum = () => new Proxy({}, { - get(_target, tag, _receiver) { - if (tag === "$is") { - return isTagged; - } else if (tag === "$match") { - return taggedMatch; - } - return tagged2(tag); - } -}); -function taggedMatch() { - if (arguments.length === 1) { - const cases2 = arguments[0]; - return function(value2) { - return cases2[value2._tag](value2); - }; - } - const value = arguments[0]; - const cases = arguments[1]; - return cases[value._tag](value); -} -var Error3 = /* @__PURE__ */ function() { - const plainArgsSymbol = /* @__PURE__ */ Symbol.for("effect/Data/Error/plainArgs"); - const O = { - BaseEffectError: class extends YieldableError { - constructor(args2) { - super(args2?.message, args2?.cause ? { - cause: args2.cause - } : undefined); - if (args2) { - Object.assign(this, args2); - Object.defineProperty(this, plainArgsSymbol, { - value: args2, - enumerable: false - }); - } - } - toJSON() { - return { - ...this[plainArgsSymbol], - ...this - }; - } - } - }; - return O.BaseEffectError; -}(); -var TaggedError = (tag) => { - const O = { - BaseEffectError: class extends Error3 { - _tag = tag; - } - }; - O.BaseEffectError.prototype.name = tag; - return O.BaseEffectError; -}; - -// node_modules/effect/dist/esm/internal/dateTime.js -var TypeId17 = /* @__PURE__ */ Symbol.for("effect/DateTime"); -var TimeZoneTypeId = /* @__PURE__ */ Symbol.for("effect/DateTime/TimeZone"); -var Proto2 = { - [TypeId17]: TypeId17, - pipe() { - return pipeArguments(this, arguments); - }, - [NodeInspectSymbol]() { - return this.toString(); - }, - toJSON() { - return toDateUtc(this).toJSON(); - } -}; -var ProtoUtc = { - ...Proto2, - _tag: "Utc", - [symbol]() { - return cached(this, number2(this.epochMillis)); - }, - [symbol2](that) { - return isDateTime(that) && that._tag === "Utc" && this.epochMillis === that.epochMillis; - }, - toString() { - return `DateTime.Utc(${toDateUtc(this).toJSON()})`; - } -}; -var ProtoZoned = { - ...Proto2, - _tag: "Zoned", - [symbol]() { - return pipe(number2(this.epochMillis), combine(hash(this.zone)), cached(this)); - }, - [symbol2](that) { - return isDateTime(that) && that._tag === "Zoned" && this.epochMillis === that.epochMillis && equals(this.zone, that.zone); - }, - toString() { - return `DateTime.Zoned(${formatIsoZoned(this)})`; - } -}; -var ProtoTimeZone = { - [TimeZoneTypeId]: TimeZoneTypeId, - [NodeInspectSymbol]() { - return this.toString(); - } -}; -var ProtoTimeZoneNamed = { - ...ProtoTimeZone, - _tag: "Named", - [symbol]() { - return cached(this, string(`Named:${this.id}`)); - }, - [symbol2](that) { - return isTimeZone(that) && that._tag === "Named" && this.id === that.id; - }, - toString() { - return `TimeZone.Named(${this.id})`; - }, - toJSON() { - return { - _id: "TimeZone", - _tag: "Named", - id: this.id - }; - } -}; -var ProtoTimeZoneOffset = { - ...ProtoTimeZone, - _tag: "Offset", - [symbol]() { - return cached(this, string(`Offset:${this.offset}`)); - }, - [symbol2](that) { - return isTimeZone(that) && that._tag === "Offset" && this.offset === that.offset; - }, - toString() { - return `TimeZone.Offset(${offsetToString(this.offset)})`; - }, - toJSON() { - return { - _id: "TimeZone", - _tag: "Offset", - offset: this.offset - }; - } -}; -var makeZonedProto = (epochMillis, zone, partsUtc) => { - const self = Object.create(ProtoZoned); - self.epochMillis = epochMillis; - self.zone = zone; - Object.defineProperty(self, "partsUtc", { - value: partsUtc, - enumerable: false, - writable: true - }); - Object.defineProperty(self, "adjustedEpochMillis", { - value: undefined, - enumerable: false, - writable: true - }); - Object.defineProperty(self, "partsAdjusted", { - value: undefined, - enumerable: false, - writable: true - }); - return self; -}; -var isDateTime = (u) => hasProperty(u, TypeId17); -var isTimeZone = (u) => hasProperty(u, TimeZoneTypeId); -var isTimeZoneOffset = (u) => isTimeZone(u) && u._tag === "Offset"; -var isTimeZoneNamed = (u) => isTimeZone(u) && u._tag === "Named"; -var isUtc = (self) => self._tag === "Utc"; -var isZoned = (self) => self._tag === "Zoned"; -var Equivalence3 = /* @__PURE__ */ make((a, b) => a.epochMillis === b.epochMillis); -var makeUtc = (epochMillis) => { - const self = Object.create(ProtoUtc); - self.epochMillis = epochMillis; - Object.defineProperty(self, "partsUtc", { - value: undefined, - enumerable: false, - writable: true - }); - return self; -}; -var unsafeFromDate = (date) => { - const epochMillis = date.getTime(); - if (Number.isNaN(epochMillis)) { - throw new IllegalArgumentException2("Invalid date"); - } - return makeUtc(epochMillis); -}; -var unsafeMake8 = (input) => { - if (isDateTime(input)) { - return input; - } else if (input instanceof Date) { - return unsafeFromDate(input); - } else if (typeof input === "object") { - const date = new Date(0); - setPartsDate(date, input); - return unsafeFromDate(date); - } else if (typeof input === "string" && !hasZone(input)) { - return unsafeFromDate(new Date(input + "Z")); - } - return unsafeFromDate(new Date(input)); -}; -var hasZone = (input) => /Z|[+-]\d{2}$|[+-]\d{2}:?\d{2}$|\]$/.test(input); -var minEpochMillis = -8640000000000000 + 12 * 60 * 60 * 1000; -var maxEpochMillis = 8640000000000000 - 14 * 60 * 60 * 1000; -var unsafeMakeZoned = (input, options) => { - if (options?.timeZone === undefined && isDateTime(input) && isZoned(input)) { - return input; - } - const self = unsafeMake8(input); - if (self.epochMillis < minEpochMillis || self.epochMillis > maxEpochMillis) { - throw new RangeError(`Epoch millis out of range: ${self.epochMillis}`); - } - let zone; - if (options?.timeZone === undefined) { - const offset = new Date(self.epochMillis).getTimezoneOffset() * -60 * 1000; - zone = zoneMakeOffset(offset); - } else if (isTimeZone(options?.timeZone)) { - zone = options.timeZone; - } else if (typeof options?.timeZone === "number") { - zone = zoneMakeOffset(options.timeZone); - } else { - const parsedZone = zoneFromString(options.timeZone); - if (isNone2(parsedZone)) { - throw new IllegalArgumentException2(`Invalid time zone: ${options.timeZone}`); - } - zone = parsedZone.value; - } - if (options?.adjustForTimeZone !== true) { - return makeZonedProto(self.epochMillis, zone, self.partsUtc); - } - return makeZonedFromAdjusted(self.epochMillis, zone, options?.disambiguation ?? "compatible"); -}; -var makeZoned = /* @__PURE__ */ liftThrowable(unsafeMakeZoned); -var zonedStringRegex = /^(.{17,35})\[(.+)\]$/; -var makeZonedFromString = (input) => { - const match10 = zonedStringRegex.exec(input); - if (match10 === null) { - const offset = parseOffset(input); - return offset !== null ? makeZoned(input, { - timeZone: offset - }) : none2(); - } - const [, isoString, timeZone] = match10; - return makeZoned(isoString, { - timeZone - }); -}; -var validZoneCache = /* @__PURE__ */ globalValue("effect/DateTime/validZoneCache", () => new Map); -var formatOptions = { - day: "numeric", - month: "numeric", - year: "numeric", - hour: "numeric", - minute: "numeric", - second: "numeric", - timeZoneName: "longOffset", - fractionalSecondDigits: 3, - hourCycle: "h23" -}; -var zoneMakeIntl = (format5) => { - const zoneId = format5.resolvedOptions().timeZone; - if (validZoneCache.has(zoneId)) { - return validZoneCache.get(zoneId); - } - const zone = Object.create(ProtoTimeZoneNamed); - zone.id = zoneId; - zone.format = format5; - validZoneCache.set(zoneId, zone); - return zone; -}; -var zoneUnsafeMakeNamed = (zoneId) => { - if (validZoneCache.has(zoneId)) { - return validZoneCache.get(zoneId); - } - try { - return zoneMakeIntl(new Intl.DateTimeFormat("en-US", { - ...formatOptions, - timeZone: zoneId - })); - } catch { - throw new IllegalArgumentException2(`Invalid time zone: ${zoneId}`); - } -}; -var zoneMakeOffset = (offset) => { - const zone = Object.create(ProtoTimeZoneOffset); - zone.offset = offset; - return zone; -}; -var zoneMakeNamed = /* @__PURE__ */ liftThrowable(zoneUnsafeMakeNamed); -var offsetZoneRegex = /^(?:GMT|[+-])/; -var zoneFromString = (zone) => { - if (offsetZoneRegex.test(zone)) { - const offset = parseOffset(zone); - return offset === null ? none2() : some2(zoneMakeOffset(offset)); - } - return zoneMakeNamed(zone); -}; -var zoneToString = (self) => { - if (self._tag === "Offset") { - return offsetToString(self.offset); - } - return self.id; -}; -var toDateUtc = (self) => new Date(self.epochMillis); -var toDate = (self) => { - if (self._tag === "Utc") { - return new Date(self.epochMillis); - } else if (self.zone._tag === "Offset") { - return new Date(self.epochMillis + self.zone.offset); - } else if (self.adjustedEpochMillis !== undefined) { - return new Date(self.adjustedEpochMillis); - } - const parts2 = self.zone.format.formatToParts(self.epochMillis).filter((_) => _.type !== "literal"); - const date = new Date(0); - date.setUTCFullYear(Number(parts2[2].value), Number(parts2[0].value) - 1, Number(parts2[1].value)); - date.setUTCHours(Number(parts2[3].value), Number(parts2[4].value), Number(parts2[5].value), Number(parts2[6].value)); - self.adjustedEpochMillis = date.getTime(); - return date; -}; -var zonedOffset = (self) => { - const date = toDate(self); - return date.getTime() - toEpochMillis(self); -}; -var offsetToString = (offset) => { - const abs2 = Math.abs(offset); - let hours2 = Math.floor(abs2 / (60 * 60 * 1000)); - let minutes2 = Math.round(abs2 % (60 * 60 * 1000) / (60 * 1000)); - if (minutes2 === 60) { - hours2 += 1; - minutes2 = 0; - } - return `${offset < 0 ? "-" : "+"}${String(hours2).padStart(2, "0")}:${String(minutes2).padStart(2, "0")}`; -}; -var zonedOffsetIso = (self) => offsetToString(zonedOffset(self)); -var toEpochMillis = (self) => self.epochMillis; -var setPartsDate = (date, parts2) => { - if (parts2.year !== undefined) { - date.setUTCFullYear(parts2.year); - } - if (parts2.month !== undefined) { - date.setUTCMonth(parts2.month - 1); - } - if (parts2.day !== undefined) { - date.setUTCDate(parts2.day); - } - if (parts2.weekDay !== undefined) { - const diff8 = parts2.weekDay - date.getUTCDay(); - date.setUTCDate(date.getUTCDate() + diff8); - } - if (parts2.hours !== undefined) { - date.setUTCHours(parts2.hours); - } - if (parts2.minutes !== undefined) { - date.setUTCMinutes(parts2.minutes); - } - if (parts2.seconds !== undefined) { - date.setUTCSeconds(parts2.seconds); - } - if (parts2.millis !== undefined) { - date.setUTCMilliseconds(parts2.millis); - } -}; -var constDayMillis = 24 * 60 * 60 * 1000; -var makeZonedFromAdjusted = (adjustedMillis, zone, disambiguation) => { - if (zone._tag === "Offset") { - return makeZonedProto(adjustedMillis - zone.offset, zone); - } - const beforeOffset = calculateNamedOffset(adjustedMillis - constDayMillis, adjustedMillis, zone); - const afterOffset = calculateNamedOffset(adjustedMillis + constDayMillis, adjustedMillis, zone); - if (beforeOffset === afterOffset) { - return makeZonedProto(adjustedMillis - beforeOffset, zone); - } - const isForwards = beforeOffset < afterOffset; - const transitionMillis = beforeOffset - afterOffset; - if (isForwards) { - const currentAfterOffset = calculateNamedOffset(adjustedMillis - afterOffset, adjustedMillis, zone); - if (currentAfterOffset === afterOffset) { - return makeZonedProto(adjustedMillis - afterOffset, zone); - } - const before2 = makeZonedProto(adjustedMillis - beforeOffset, zone); - const beforeAdjustedMillis = toDate(before2).getTime(); - if (adjustedMillis !== beforeAdjustedMillis) { - switch (disambiguation) { - case "reject": { - const formatted = new Date(adjustedMillis).toISOString(); - throw new RangeError(`Gap time: ${formatted} does not exist in time zone ${zone.id}`); - } - case "earlier": - return makeZonedProto(adjustedMillis - afterOffset, zone); - case "compatible": - case "later": - return before2; - } - } - return before2; - } - const currentBeforeOffset = calculateNamedOffset(adjustedMillis - beforeOffset, adjustedMillis, zone); - if (currentBeforeOffset === beforeOffset) { - if (disambiguation === "earlier" || disambiguation === "compatible") { - return makeZonedProto(adjustedMillis - beforeOffset, zone); - } - const laterOffset = calculateNamedOffset(adjustedMillis - beforeOffset + transitionMillis, adjustedMillis + transitionMillis, zone); - if (laterOffset === beforeOffset) { - return makeZonedProto(adjustedMillis - beforeOffset, zone); - } - if (disambiguation === "reject") { - const formatted = new Date(adjustedMillis).toISOString(); - throw new RangeError(`Ambiguous time: ${formatted} occurs twice in time zone ${zone.id}`); - } - } - return makeZonedProto(adjustedMillis - afterOffset, zone); -}; -var offsetRegex = /([+-])(\d{2}):(\d{2})$/; -var parseOffset = (offset) => { - const match10 = offsetRegex.exec(offset); - if (match10 === null) { - return null; - } - const [, sign2, hours2, minutes2] = match10; - return (sign2 === "+" ? 1 : -1) * (Number(hours2) * 60 + Number(minutes2)) * 60 * 1000; -}; -var calculateNamedOffset = (utcMillis, adjustedMillis, zone) => { - const offset = zone.format.formatToParts(utcMillis).find((_) => _.type === "timeZoneName")?.value ?? ""; - if (offset === "GMT") { - return 0; - } - const result = parseOffset(offset); - if (result === null) { - return zonedOffset(makeZonedProto(adjustedMillis, zone)); - } - return result; -}; -var formatIso = (self) => toDateUtc(self).toISOString(); -var formatIsoOffset = (self) => { - const date = toDate(self); - return self._tag === "Utc" ? date.toISOString() : `${date.toISOString().slice(0, -1)}${zonedOffsetIso(self)}`; -}; -var formatIsoZoned = (self) => self.zone._tag === "Offset" ? formatIsoOffset(self) : `${formatIsoOffset(self)}[${self.zone.id}]`; - -// node_modules/effect/dist/esm/String.js -var toUpperCase = (self) => self.toUpperCase(); -var toLowerCase = (self) => self.toLowerCase(); -var capitalize = (self) => { - if (self.length === 0) - return self; - return toUpperCase(self[0]) + self.slice(1); -}; -var uncapitalize = (self) => { - if (self.length === 0) - return self; - return toLowerCase(self[0]) + self.slice(1); -}; -var isNonEmpty6 = (self) => self.length > 0; - -// node_modules/effect/dist/esm/Random.js -var fixed2 = fixed; - -// node_modules/effect/dist/esm/internal/schedule.js -var ScheduleSymbolKey = "effect/Schedule"; -var ScheduleTypeId = /* @__PURE__ */ Symbol.for(ScheduleSymbolKey); -var isSchedule = (u) => hasProperty(u, ScheduleTypeId); -var ScheduleDriverSymbolKey = "effect/ScheduleDriver"; -var ScheduleDriverTypeId = /* @__PURE__ */ Symbol.for(ScheduleDriverSymbolKey); -var defaultIterationMetadata = { - start: 0, - now: 0, - input: undefined, - output: undefined, - elapsed: zero2, - elapsedSincePrevious: zero2, - recurrence: 0 -}; -var CurrentIterationMetadata = /* @__PURE__ */ Reference2()("effect/Schedule/CurrentIterationMetadata", { - defaultValue: () => defaultIterationMetadata -}); -var scheduleVariance = { - _Out: (_) => _, - _In: (_) => _, - _R: (_) => _ -}; -var scheduleDriverVariance = { - _Out: (_) => _, - _In: (_) => _, - _R: (_) => _ -}; - -class ScheduleImpl { - initial; - step; - [ScheduleTypeId] = scheduleVariance; - constructor(initial, step3) { - this.initial = initial; - this.step = step3; - } - pipe() { - return pipeArguments(this, arguments); - } -} -var updateInfo = (iterationMetaRef, now, input, output) => update2(iterationMetaRef, (prev) => prev.recurrence === 0 ? { - now, - input, - output, - recurrence: prev.recurrence + 1, - elapsed: zero2, - elapsedSincePrevious: zero2, - start: now -} : { - now, - input, - output, - recurrence: prev.recurrence + 1, - elapsed: millis(now - prev.start), - elapsedSincePrevious: millis(now - prev.now), - start: prev.start -}); - -class ScheduleDriverImpl { - schedule; - ref; - [ScheduleDriverTypeId] = scheduleDriverVariance; - constructor(schedule, ref) { - this.schedule = schedule; - this.ref = ref; - } - get state() { - return map9(get11(this.ref), (tuple2) => tuple2[1]); - } - get last() { - return flatMap7(get11(this.ref), ([element, _]) => { - switch (element._tag) { - case "None": { - return failSync(() => new NoSuchElementException); - } - case "Some": { - return succeed(element.value); - } - } - }); - } - iterationMeta = /* @__PURE__ */ unsafeMake5(defaultIterationMetadata); - get reset() { - return set5(this.ref, [none2(), this.schedule.initial]).pipe(zipLeft(set5(this.iterationMeta, defaultIterationMetadata))); - } - next(input) { - return pipe(map9(get11(this.ref), (tuple2) => tuple2[1]), flatMap7((state) => pipe(currentTimeMillis2, flatMap7((now) => pipe(suspend(() => this.schedule.step(now, input, state)), flatMap7(([state2, out, decision]) => { - const setState = set5(this.ref, [some2(out), state2]); - if (isDone4(decision)) { - return setState.pipe(zipRight(fail2(none2()))); - } - const millis2 = start2(decision.intervals) - now; - if (millis2 <= 0) { - return setState.pipe(zipRight(updateInfo(this.iterationMeta, now, input, out)), as(out)); - } - const duration = millis(millis2); - return pipe(setState, zipRight(updateInfo(this.iterationMeta, now, input, out)), zipRight(sleep3(duration)), as(out)); - })))))); - } -} -var makeWithState = (initial, step3) => new ScheduleImpl(initial, step3); -var asVoid2 = (self) => map10(self, constVoid); -var check = /* @__PURE__ */ dual(2, (self, test) => checkEffect(self, (input, out) => sync(() => test(input, out)))); -var checkEffect = /* @__PURE__ */ dual(2, (self, test) => makeWithState(self.initial, (now, input, state) => flatMap7(self.step(now, input, state), ([state2, out, decision]) => { - if (isDone4(decision)) { - return succeed([state2, out, done6]); - } - return map9(test(input, out), (cont) => cont ? [state2, out, decision] : [state2, out, done6]); -}))); -var driver = (self) => pipe(make27([none2(), self.initial]), map9((ref) => new ScheduleDriverImpl(self, ref))); -var intersect5 = /* @__PURE__ */ dual(2, (self, that) => intersectWith(self, that, intersect4)); -var intersectWith = /* @__PURE__ */ dual(3, (self, that, f) => makeWithState([self.initial, that.initial], (now, input, state) => pipe(zipWith2(self.step(now, input, state[0]), that.step(now, input, state[1]), (a, b) => [a, b]), flatMap7(([[lState, out, lDecision], [rState, out2, rDecision]]) => { - if (isContinue2(lDecision) && isContinue2(rDecision)) { - return intersectWithLoop(self, that, input, lState, out, lDecision.intervals, rState, out2, rDecision.intervals, f); - } - return succeed([[lState, rState], [out, out2], done6]); -})))); -var intersectWithLoop = (self, that, input, lState, out, lInterval, rState, out2, rInterval, f) => { - const combined = f(lInterval, rInterval); - if (isNonEmpty5(combined)) { - return succeed([[lState, rState], [out, out2], _continue2(combined)]); - } - if (pipe(lInterval, lessThan7(rInterval))) { - return flatMap7(self.step(end2(lInterval), input, lState), ([lState2, out3, decision]) => { - if (isDone4(decision)) { - return succeed([[lState2, rState], [out3, out2], done6]); - } - return intersectWithLoop(self, that, input, lState2, out3, decision.intervals, rState, out2, rInterval, f); - }); - } - return flatMap7(that.step(end2(rInterval), input, rState), ([rState2, out22, decision]) => { - if (isDone4(decision)) { - return succeed([[lState, rState2], [out, out22], done6]); - } - return intersectWithLoop(self, that, input, lState, out, lInterval, rState2, out22, decision.intervals, f); - }); -}; -var map10 = /* @__PURE__ */ dual(2, (self, f) => mapEffect(self, (out) => sync(() => f(out)))); -var mapEffect = /* @__PURE__ */ dual(2, (self, f) => makeWithState(self.initial, (now, input, state) => flatMap7(self.step(now, input, state), ([state2, out, decision]) => map9(f(out), (out2) => [state2, out2, decision])))); -var passthrough = (self) => makeWithState(self.initial, (now, input, state) => pipe(self.step(now, input, state), map9(([state2, _, decision]) => [state2, input, decision]))); -var recurs = (n) => whileOutput(forever2, (out) => out < n); -var unfold2 = (initial, f) => makeWithState(initial, (now, _, state) => sync(() => [f(state), state, continueWith2(after2(now))])); -var untilInputEffect = /* @__PURE__ */ dual(2, (self, f) => checkEffect(self, (input, _) => negate(f(input)))); -var whileInputEffect = /* @__PURE__ */ dual(2, (self, f) => checkEffect(self, (input, _) => f(input))); -var whileOutput = /* @__PURE__ */ dual(2, (self, f) => check(self, (_, out) => f(out))); -var ScheduleDefectTypeId = /* @__PURE__ */ Symbol.for("effect/Schedule/ScheduleDefect"); - -class ScheduleDefect { - error; - [ScheduleDefectTypeId]; - constructor(error) { - this.error = error; - this[ScheduleDefectTypeId] = ScheduleDefectTypeId; - } -} -var isScheduleDefect = (u) => hasProperty(u, ScheduleDefectTypeId); -var scheduleDefectWrap = (self) => catchAll(self, (e) => die2(new ScheduleDefect(e))); -var scheduleDefectRefailCause = (cause2) => match2(find(cause2, (_) => isDieType(_) && isScheduleDefect(_.defect) ? some2(_.defect) : none2()), { - onNone: () => cause2, - onSome: (error) => fail(error.error) -}); -var scheduleDefectRefail = (effect) => catchAllCause(effect, (cause2) => failCause(scheduleDefectRefailCause(cause2))); -var repeat_Effect = /* @__PURE__ */ dual(2, (self, schedule) => repeatOrElse_Effect(self, schedule, (e, _) => fail2(e))); -var repeat_combined = /* @__PURE__ */ dual(2, (self, options) => { - if (isSchedule(options)) { - return repeat_Effect(self, options); - } - const base = options.schedule ?? passthrough(forever2); - const withWhile = options.while ? whileInputEffect(base, (a) => { - const applied = options.while(a); - if (typeof applied === "boolean") { - return succeed(applied); - } - return scheduleDefectWrap(applied); - }) : base; - const withUntil = options.until ? untilInputEffect(withWhile, (a) => { - const applied = options.until(a); - if (typeof applied === "boolean") { - return succeed(applied); - } - return scheduleDefectWrap(applied); - }) : withWhile; - const withTimes = options.times ? intersect5(withUntil, recurs(options.times)).pipe(map10((intersectionPair) => intersectionPair[0])) : withUntil; - return scheduleDefectRefail(repeat_Effect(self, withTimes)); -}); -var repeatOrElse_Effect = /* @__PURE__ */ dual(3, (self, schedule, orElse3) => flatMap7(driver(schedule), (driver2) => matchEffect(self, { - onFailure: (error) => orElse3(error, none2()), - onSuccess: (value) => repeatOrElseEffectLoop(provideServiceEffect(self, CurrentIterationMetadata, get11(driver2.iterationMeta)), driver2, (error, option2) => provideServiceEffect(orElse3(error, option2), CurrentIterationMetadata, get11(driver2.iterationMeta)), value) -}))); -var repeatOrElseEffectLoop = (self, driver2, orElse3, value) => matchEffect(driver2.next(value), { - onFailure: () => orDie(driver2.last), - onSuccess: (b) => matchEffect(self, { - onFailure: (error) => orElse3(error, some2(b)), - onSuccess: (value2) => repeatOrElseEffectLoop(self, driver2, orElse3, value2) - }) -}); -var retry_Effect = /* @__PURE__ */ dual(2, (self, policy) => retryOrElse_Effect(self, policy, (e, _) => fail2(e))); -var retry_combined = /* @__PURE__ */ dual(2, (self, options) => { - if (isSchedule(options)) { - return retry_Effect(self, options); - } - return scheduleDefectRefail(retry_Effect(self, fromRetryOptions(options))); -}); -var fromRetryOptions = (options) => { - const base = options.schedule ?? forever2; - const withWhile = options.while ? whileInputEffect(base, (e) => { - const applied = options.while(e); - if (typeof applied === "boolean") { - return succeed(applied); - } - return scheduleDefectWrap(applied); - }) : base; - const withUntil = options.until ? untilInputEffect(withWhile, (e) => { - const applied = options.until(e); - if (typeof applied === "boolean") { - return succeed(applied); - } - return scheduleDefectWrap(applied); - }) : withWhile; - return options.times !== undefined ? intersect5(withUntil, recurs(options.times)) : withUntil; -}; -var retryOrElse_Effect = /* @__PURE__ */ dual(3, (self, policy, orElse3) => flatMap7(driver(policy), (driver2) => retryOrElse_EffectLoop(provideServiceEffect(self, CurrentIterationMetadata, get11(driver2.iterationMeta)), driver2, (e, out) => provideServiceEffect(orElse3(e, out), CurrentIterationMetadata, get11(driver2.iterationMeta))))); -var retryOrElse_EffectLoop = (self, driver2, orElse3) => { - return catchAll(self, (e) => matchEffect(driver2.next(e), { - onFailure: () => pipe(driver2.last, orDie, flatMap7((out) => orElse3(e, out))), - onSuccess: () => retryOrElse_EffectLoop(self, driver2, orElse3) - })); -}; -var schedule_Effect = /* @__PURE__ */ dual(2, (self, schedule) => scheduleFrom_Effect(self, undefined, schedule)); -var scheduleFrom_Effect = /* @__PURE__ */ dual(3, (self, initial, schedule) => flatMap7(driver(schedule), (driver2) => scheduleFrom_EffectLoop(provideServiceEffect(self, CurrentIterationMetadata, get11(driver2.iterationMeta)), initial, driver2))); -var scheduleFrom_EffectLoop = (self, initial, driver2) => matchEffect(driver2.next(initial), { - onFailure: () => orDie(driver2.last), - onSuccess: () => flatMap7(self, (a) => scheduleFrom_EffectLoop(self, a, driver2)) -}); -var forever2 = /* @__PURE__ */ unfold2(0, (n) => n + 1); -var once2 = /* @__PURE__ */ asVoid2(/* @__PURE__ */ recurs(1)); -var scheduleForked = /* @__PURE__ */ dual(2, (self, schedule) => forkScoped(schedule_Effect(self, schedule))); - -// node_modules/effect/dist/esm/internal/executionPlan.js -var withExecutionPlan = /* @__PURE__ */ dual(2, (effect, plan) => suspend(() => { - let i = 0; - let result; - return flatMap7(whileLoop({ - while: () => i < plan.steps.length && (result === undefined || isLeft2(result)), - body: () => { - const step3 = plan.steps[i]; - let nextEffect = effect_provide(effect, step3.provide); - if (result) { - let attempted = false; - const wrapped = nextEffect; - nextEffect = suspend(() => { - if (attempted) - return wrapped; - attempted = true; - return result; - }); - nextEffect = scheduleDefectRefail(retry_Effect(nextEffect, scheduleFromStep(step3, false))); - } else { - const schedule = scheduleFromStep(step3, true); - nextEffect = schedule ? scheduleDefectRefail(retry_Effect(nextEffect, schedule)) : nextEffect; - } - return either2(nextEffect); - }, - step: (either3) => { - result = either3; - i++; - } - }), () => result); -})); -var scheduleFromStep = (step3, first2) => { - if (!first2) { - return fromRetryOptions({ - schedule: step3.schedule ? step3.schedule : step3.attempts ? undefined : once2, - times: step3.attempts, - while: step3.while - }); - } else if (step3.attempts === 1 || !(step3.schedule || step3.attempts)) { - return; - } - return fromRetryOptions({ - schedule: step3.schedule, - while: step3.while, - times: step3.attempts ? step3.attempts - 1 : undefined - }); -}; - -// node_modules/effect/dist/esm/internal/query.js -var currentCache = /* @__PURE__ */ globalValue(/* @__PURE__ */ Symbol.for("effect/FiberRef/currentCache"), () => fiberRefUnsafeMake(unsafeMakeWith(65536, () => map9(deferredMake(), (handle) => ({ - listeners: new Listeners, - handle -})), () => seconds(60)))); -var currentCacheEnabled = /* @__PURE__ */ globalValue(/* @__PURE__ */ Symbol.for("effect/FiberRef/currentCacheEnabled"), () => fiberRefUnsafeMake(false)); -var fromRequest = (request, dataSource) => flatMap7(isEffect(dataSource) ? dataSource : succeed(dataSource), (ds) => fiberIdWith((id) => { - const proxy = new Proxy(request, {}); - return fiberRefGetWith(currentCacheEnabled, (cacheEnabled) => { - if (cacheEnabled) { - const cached3 = fiberRefGetWith(currentCache, (cache) => flatMap7(cache.getEither(proxy), (orNew) => { - switch (orNew._tag) { - case "Left": { - if (orNew.left.listeners.interrupted) { - return flatMap7(cache.invalidateWhen(proxy, (entry) => entry.handle === orNew.left.handle), () => cached3); - } - orNew.left.listeners.increment(); - return uninterruptibleMask((restore) => flatMap7(exit(blocked(empty15, restore(deferredAwait(orNew.left.handle)))), (exit2) => { - orNew.left.listeners.decrement(); - return exit2; - })); - } - case "Right": { - orNew.right.listeners.increment(); - return uninterruptibleMask((restore) => flatMap7(exit(blocked(single(ds, makeEntry({ - request: proxy, - result: orNew.right.handle, - listeners: orNew.right.listeners, - ownerId: id, - state: { - completed: false - } - })), restore(deferredAwait(orNew.right.handle)))), () => { - orNew.right.listeners.decrement(); - return deferredAwait(orNew.right.handle); - })); - } - } - })); - return cached3; - } - const listeners = new Listeners; - listeners.increment(); - return flatMap7(deferredMake(), (ref) => ensuring(blocked(single(ds, makeEntry({ - request: proxy, - result: ref, - listeners, - ownerId: id, - state: { - completed: false - } - })), deferredAwait(ref)), sync(() => listeners.decrement()))); - }); -})); -var cacheRequest = (request, result) => { - return fiberRefGetWith(currentCacheEnabled, (cacheEnabled) => { - if (cacheEnabled) { - return fiberRefGetWith(currentCache, (cache) => flatMap7(cache.getEither(request), (orNew) => { - switch (orNew._tag) { - case "Left": { - return void_; - } - case "Right": { - return deferredComplete(orNew.right.handle, result); - } - } - })); - } - return void_; - }); -}; -var withRequestCaching = /* @__PURE__ */ dual(2, (self, strategy) => fiberRefLocally(self, currentCacheEnabled, strategy)); -var withRequestCache = /* @__PURE__ */ dual(2, (self, cache) => fiberRefLocally(self, currentCache, cache)); - -// node_modules/effect/dist/esm/Request.js -var isRequest2 = isRequest; -var Class4 = Class2; - -// node_modules/effect/dist/esm/Effect.js -var EffectTypeId3 = EffectTypeId2; -var isEffect2 = isEffect; -var cachedWithTTL = cached2; -var cachedInvalidateWithTTL2 = cachedInvalidateWithTTL; -var cached3 = memoize; -var cachedFunction2 = cachedFunction; -var once3 = once; -var all3 = all2; -var allWith2 = allWith; -var allSuccesses2 = allSuccesses; -var dropUntil2 = dropUntil; -var dropWhile2 = dropWhile; -var takeUntil2 = takeUntil; -var takeWhile2 = takeWhile; -var every6 = every4; -var exists3 = exists2; -var filter7 = filter5; -var filterMap5 = filterMap4; -var findFirst6 = findFirst4; -var forEach7 = forEach6; -var head4 = head3; -var mergeAll5 = mergeAll3; -var partition4 = partition3; -var reduce10 = reduce8; -var reduceWhile2 = reduceWhile; -var reduceRight3 = reduceRight2; -var reduceEffect2 = reduceEffect; -var replicate2 = replicate; -var replicateEffect2 = replicateEffect; -var validateAll2 = validateAll; -var validateFirst2 = validateFirst; -var async = async_; -var asyncEffect2 = asyncEffect; -var custom2 = custom; -var withFiberRuntime2 = withFiberRuntime; -var fail5 = fail2; -var failSync2 = failSync; -var failCause5 = failCause; -var failCauseSync2 = failCauseSync; -var die4 = die2; -var dieMessage2 = dieMessage; -var dieSync2 = dieSync; -var gen2 = gen; -var never2 = never; -var none9 = none6; -var promise2 = promise; -var succeed6 = succeed; -var succeedNone2 = succeedNone; -var succeedSome2 = succeedSome; -var suspend3 = suspend; -var sync3 = sync; -var _void = void_; -var yieldNow4 = yieldNow; -var _catch2 = _catch; -var catchAll2 = catchAll; -var catchAllCause2 = catchAllCause; -var catchAllDefect2 = catchAllDefect; -var catchIf2 = catchIf; -var catchSome2 = catchSome; -var catchSomeCause2 = catchSomeCause; -var catchSomeDefect2 = catchSomeDefect; -var catchTag2 = catchTag; -var catchTags2 = catchTags; -var cause2 = cause; -var eventually2 = eventually; -var ignore2 = ignore; -var ignoreLogged2 = ignoreLogged; -var parallelErrors2 = parallelErrors; -var sandbox2 = sandbox; -var retry = retry_combined; -var withExecutionPlan2 = withExecutionPlan; -var retryOrElse = retryOrElse_Effect; -var try_3 = try_2; -var tryMap2 = tryMap; -var tryMapPromise2 = tryMapPromise; -var tryPromise2 = tryPromise; -var unsandbox2 = unsandbox; -var allowInterrupt2 = allowInterrupt; -var checkInterruptible2 = checkInterruptible; -var disconnect2 = disconnect; -var interrupt5 = interrupt2; -var interruptWith2 = interruptWith; -var interruptible4 = interruptible2; -var interruptibleMask2 = interruptibleMask; -var onInterrupt2 = onInterrupt; -var uninterruptible2 = uninterruptible; -var uninterruptibleMask3 = uninterruptibleMask; -var liftPredicate2 = liftPredicate; -var as3 = as; -var asSome2 = asSome; -var asSomeError2 = asSomeError; -var asVoid3 = asVoid; -var flip2 = flip; -var flipWith2 = flipWith; -var map11 = map9; -var mapAccum3 = mapAccum2; -var mapBoth3 = mapBoth2; -var mapError2 = mapError; -var mapErrorCause2 = mapErrorCause; -var merge6 = merge5; -var negate2 = negate; -var acquireRelease2 = acquireRelease; -var acquireReleaseInterruptible2 = acquireReleaseInterruptible; -var acquireUseRelease2 = acquireUseRelease; -var addFinalizer2 = addFinalizer; -var ensuring2 = ensuring; -var onError2 = onError; -var onExit3 = onExit; -var parallelFinalizers2 = parallelFinalizers; -var sequentialFinalizers2 = sequentialFinalizers; -var finalizersMask2 = finalizersMask; -var scope2 = scope; -var scopeWith2 = scopeWith; -var scopedWith2 = scopedWith; -var scoped2 = scopedEffect; -var using2 = using; -var withEarlyRelease2 = withEarlyRelease; -var awaitAllChildren2 = awaitAllChildren; -var daemonChildren2 = daemonChildren; -var descriptor2 = descriptor; -var descriptorWith2 = descriptorWith; -var diffFiberRefs2 = diffFiberRefs; -var ensuringChild2 = ensuringChild; -var ensuringChildren2 = ensuringChildren; -var fiberId2 = fiberId; -var fiberIdWith2 = fiberIdWith; -var fork3 = fork; -var forkDaemon2 = forkDaemon; -var forkAll2 = forkAll; -var forkIn2 = forkIn; -var forkScoped2 = forkScoped; -var forkWithErrorHandler2 = forkWithErrorHandler; -var fromFiber2 = fromFiber; -var fromFiberEffect2 = fromFiberEffect; -var supervised2 = supervised; -var transplant2 = transplant; -var withConcurrency2 = withConcurrency; -var withScheduler2 = withScheduler; -var withSchedulingPriority2 = withSchedulingPriority; -var withMaxOpsBeforeYield2 = withMaxOpsBeforeYield; -var clock2 = clock; -var clockWith4 = clockWith3; -var withClockScoped2 = withClockScoped; -var withClock2 = withClock; -var console3 = console2; -var consoleWith2 = consoleWith; -var withConsoleScoped2 = withConsoleScoped; -var withConsole2 = withConsole; -var delay2 = delay; -var sleep4 = sleep3; -var timed2 = timed; -var timedWith2 = timedWith; -var timeout2 = timeout; -var timeoutOption2 = timeoutOption; -var timeoutFail2 = timeoutFail; -var timeoutFailCause2 = timeoutFailCause; -var timeoutTo2 = timeoutTo; -var configProviderWith2 = configProviderWith; -var withConfigProvider2 = withConfigProvider; -var withConfigProviderScoped2 = withConfigProviderScoped; -var context3 = context; -var contextWith2 = contextWith; -var contextWithEffect2 = contextWithEffect; -var mapInputContext2 = mapInputContext; -var provide2 = effect_provide; -var provideService2 = provideService; -var provideServiceEffect2 = provideServiceEffect; -var serviceFunction2 = serviceFunction; -var serviceFunctionEffect2 = serviceFunctionEffect; -var serviceFunctions2 = serviceFunctions; -var serviceConstants2 = serviceConstants; -var serviceMembers2 = serviceMembers; -var serviceOption2 = serviceOption; -var serviceOptional2 = serviceOptional; -var updateService2 = updateService; -var Do2 = Do; -var bind3 = bind2; -var bindAll2 = bindAll; -var bindTo3 = bindTo2; -var let_3 = let_2; -var option2 = option; -var either3 = either2; -var exit2 = exit; -var intoDeferred2 = intoDeferred; -var if_2 = if_; -var filterOrDie2 = filterOrDie; -var filterOrDieMessage2 = filterOrDieMessage; -var filterOrElse2 = filterOrElse; -var filterOrFail2 = filterOrFail; -var filterEffectOrElse2 = filterEffectOrElse; -var filterEffectOrFail2 = filterEffectOrFail; -var unless2 = unless; -var unlessEffect2 = unlessEffect; -var when2 = when; -var whenEffect2 = whenEffect; -var whenFiberRef2 = whenFiberRef; -var whenRef2 = whenRef; -var flatMap9 = flatMap7; -var andThen4 = andThen2; -var flatten7 = flatten5; -var race2 = race; -var raceAll2 = raceAll; -var raceFirst2 = raceFirst; -var raceWith2 = raceWith; -var summarized2 = summarized; -var tap2 = tap; -var tapBoth2 = tapBoth; -var tapDefect2 = tapDefect; -var tapError2 = tapError; -var tapErrorTag2 = tapErrorTag; -var tapErrorCause2 = tapErrorCause; -var forever3 = forever; -var iterate2 = iterate; -var loop2 = loop; -var repeat = repeat_combined; -var repeatN2 = repeatN; -var repeatOrElse = repeatOrElse_Effect; -var schedule = schedule_Effect; -var scheduleForked2 = scheduleForked; -var scheduleFrom = scheduleFrom_Effect; -var whileLoop2 = whileLoop; -var getFiberRefs = fiberRefs2; -var inheritFiberRefs2 = inheritFiberRefs; -var locally = fiberRefLocally; -var locallyWith = fiberRefLocallyWith; -var locallyScoped = fiberRefLocallyScoped; -var locallyScopedWith = fiberRefLocallyScopedWith; -var patchFiberRefs2 = patchFiberRefs; -var setFiberRefs2 = setFiberRefs; -var updateFiberRefs2 = updateFiberRefs; -var isFailure3 = isFailure; -var isSuccess3 = isSuccess2; -var match10 = match7; -var matchCause2 = matchCause; -var matchCauseEffect3 = matchCauseEffect; -var matchEffect2 = matchEffect; -var log2 = log; -var logWithLevel2 = (level, ...message) => logWithLevel(level)(...message); -var logTrace2 = logTrace; -var logDebug2 = logDebug; -var logInfo2 = logInfo; -var logWarning2 = logWarning; -var logError2 = logError; -var logFatal2 = logFatal; -var withLogSpan2 = withLogSpan; -var annotateLogs2 = annotateLogs; -var annotateLogsScoped2 = annotateLogsScoped; -var logAnnotations2 = logAnnotations; -var withUnhandledErrorLogLevel2 = withUnhandledErrorLogLevel; -var whenLogLevel2 = whenLogLevel; -var orDie2 = orDie; -var orDieWith2 = orDieWith; -var orElse3 = orElse2; -var orElseFail2 = orElseFail; -var orElseSucceed2 = orElseSucceed; -var firstSuccessOf2 = firstSuccessOf; -var random3 = random2; -var randomWith2 = randomWith; -var withRandom2 = withRandom; -var withRandomFixed = /* @__PURE__ */ dual(2, (effect, values4) => withRandom2(effect, fixed2(values4))); -var withRandomScoped2 = withRandomScoped; -var runtime4 = runtime3; -var getRuntimeFlags = runtimeFlags; -var patchRuntimeFlags = updateRuntimeFlags; -var withRuntimeFlagsPatch = withRuntimeFlags; -var withRuntimeFlagsPatchScoped = withRuntimeFlagsScoped; -var tagMetrics2 = tagMetrics; -var labelMetrics2 = labelMetrics; -var tagMetricsScoped2 = tagMetricsScoped; -var labelMetricsScoped2 = labelMetricsScoped; -var metricLabels2 = metricLabels; -var withMetric2 = withMetric; -var unsafeMakeSemaphore2 = unsafeMakeSemaphore; -var makeSemaphore2 = makeSemaphore; -var unsafeMakeLatch2 = unsafeMakeLatch; -var makeLatch2 = makeLatch; -var runFork2 = unsafeForkEffect; -var runCallback = unsafeRunEffect; -var runPromise = unsafeRunPromiseEffect; -var runPromiseExit = unsafeRunPromiseExitEffect; -var runSync = unsafeRunSyncEffect; -var runSyncExit = unsafeRunSyncExitEffect; -var validate2 = validate; -var validateWith2 = validateWith; -var zip4 = zipOptions; -var zipLeft2 = zipLeftOptions; -var zipRight2 = zipRightOptions; -var zipWith3 = zipWithOptions; -var ap = /* @__PURE__ */ dual(2, (self, that) => zipWith3(self, that, (f, a) => f(a))); -var blocked2 = blocked; -var runRequestBlock2 = runRequestBlock; -var step3 = step2; -var request = /* @__PURE__ */ dual((args2) => isRequest2(args2[0]), fromRequest); -var cacheRequestResult = cacheRequest; -var withRequestBatching2 = withRequestBatching; -var withRequestCaching2 = withRequestCaching; -var withRequestCache2 = withRequestCache; -var tracer2 = tracer; -var tracerWith4 = tracerWith; -var withTracer2 = withTracer; -var withTracerScoped2 = withTracerScoped; -var withTracerEnabled2 = withTracerEnabled; -var withTracerTiming2 = withTracerTiming; -var annotateSpans2 = annotateSpans; -var annotateCurrentSpan2 = annotateCurrentSpan; -var currentSpan2 = currentSpan; -var currentPropagatedSpan2 = currentPropagatedSpan; -var currentParentSpan2 = currentParentSpan; -var spanAnnotations2 = spanAnnotations; -var spanLinks2 = spanLinks; -var linkSpans2 = linkSpans; -var linkSpanCurrent2 = linkSpanCurrent; -var makeSpan2 = makeSpan; -var makeSpanScoped2 = makeSpanScoped; -var useSpan2 = useSpan; -var withSpan2 = withSpan; -var functionWithSpan2 = functionWithSpan; -var withSpanScoped2 = withSpanScoped; -var withParentSpan2 = withParentSpan; -var fromNullable3 = fromNullable2; -var optionFromOptional2 = optionFromOptional; -var transposeOption = (self) => { - return isNone(self) ? succeedNone2 : map11(self.value, some); +// node_modules/effect/dist/esm/Effect.js +var exports_Effect = {}; +__export(exports_Effect, { + zipWith: () => zipWith3, + zipRight: () => zipRight2, + zipLeft: () => zipLeft2, + zip: () => zip4, + yieldNow: () => yieldNow4, + withUnhandledErrorLogLevel: () => withUnhandledErrorLogLevel2, + withTracerTiming: () => withTracerTiming2, + withTracerScoped: () => withTracerScoped2, + withTracerEnabled: () => withTracerEnabled2, + withTracer: () => withTracer2, + withSpanScoped: () => withSpanScoped2, + withSpan: () => withSpan2, + withSchedulingPriority: () => withSchedulingPriority2, + withScheduler: () => withScheduler2, + withRuntimeFlagsPatchScoped: () => withRuntimeFlagsPatchScoped, + withRuntimeFlagsPatch: () => withRuntimeFlagsPatch, + withRequestCaching: () => withRequestCaching2, + withRequestCache: () => withRequestCache2, + withRequestBatching: () => withRequestBatching2, + withRandomScoped: () => withRandomScoped2, + withRandomFixed: () => withRandomFixed, + withRandom: () => withRandom2, + withParentSpan: () => withParentSpan2, + withMetric: () => withMetric2, + withMaxOpsBeforeYield: () => withMaxOpsBeforeYield2, + withLogSpan: () => withLogSpan2, + withFiberRuntime: () => withFiberRuntime2, + withExecutionPlan: () => withExecutionPlan2, + withEarlyRelease: () => withEarlyRelease2, + withConsoleScoped: () => withConsoleScoped2, + withConsole: () => withConsole2, + withConfigProviderScoped: () => withConfigProviderScoped2, + withConfigProvider: () => withConfigProvider2, + withConcurrency: () => withConcurrency2, + withClockScoped: () => withClockScoped2, + withClock: () => withClock2, + whileLoop: () => whileLoop2, + whenRef: () => whenRef2, + whenLogLevel: () => whenLogLevel2, + whenFiberRef: () => whenFiberRef2, + whenEffect: () => whenEffect2, + when: () => when2, + void: () => _void, + validateWith: () => validateWith2, + validateFirst: () => validateFirst2, + validateAll: () => validateAll2, + validate: () => validate2, + using: () => using2, + useSpan: () => useSpan2, + updateService: () => updateService2, + updateFiberRefs: () => updateFiberRefs2, + unsandbox: () => unsandbox2, + unsafeMakeSemaphore: () => unsafeMakeSemaphore2, + unsafeMakeLatch: () => unsafeMakeLatch2, + unlessEffect: () => unlessEffect2, + unless: () => unless2, + uninterruptibleMask: () => uninterruptibleMask3, + uninterruptible: () => uninterruptible2, + tryPromise: () => tryPromise2, + tryMapPromise: () => tryMapPromise2, + tryMap: () => tryMap2, + try: () => try_3, + transposeOption: () => transposeOption, + transposeMapOption: () => transposeMapOption, + transplant: () => transplant2, + tracerWith: () => tracerWith4, + tracer: () => tracer2, + timeoutTo: () => timeoutTo2, + timeoutOption: () => timeoutOption2, + timeoutFailCause: () => timeoutFailCause2, + timeoutFail: () => timeoutFail2, + timeout: () => timeout2, + timedWith: () => timedWith2, + timed: () => timed2, + tapErrorTag: () => tapErrorTag2, + tapErrorCause: () => tapErrorCause2, + tapError: () => tapError2, + tapDefect: () => tapDefect2, + tapBoth: () => tapBoth2, + tap: () => tap2, + takeWhile: () => takeWhile2, + takeUntil: () => takeUntil2, + tagMetricsScoped: () => tagMetricsScoped2, + tagMetrics: () => tagMetrics2, + sync: () => sync3, + suspend: () => suspend3, + supervised: () => supervised2, + summarized: () => summarized2, + succeedSome: () => succeedSome2, + succeedNone: () => succeedNone2, + succeed: () => succeed6, + step: () => step3, + spanLinks: () => spanLinks2, + spanAnnotations: () => spanAnnotations2, + sleep: () => sleep4, + setFiberRefs: () => setFiberRefs2, + serviceOptional: () => serviceOptional2, + serviceOption: () => serviceOption2, + serviceMembers: () => serviceMembers2, + serviceFunctions: () => serviceFunctions2, + serviceFunctionEffect: () => serviceFunctionEffect2, + serviceFunction: () => serviceFunction2, + serviceConstants: () => serviceConstants2, + sequentialFinalizers: () => sequentialFinalizers2, + scopedWith: () => scopedWith2, + scoped: () => scoped2, + scopeWith: () => scopeWith2, + scope: () => scope2, + scheduleFrom: () => scheduleFrom, + scheduleForked: () => scheduleForked2, + schedule: () => schedule, + sandbox: () => sandbox2, + runtime: () => runtime4, + runSyncExit: () => runSyncExit, + runSync: () => runSync, + runRequestBlock: () => runRequestBlock2, + runPromiseExit: () => runPromiseExit, + runPromise: () => runPromise, + runFork: () => runFork2, + runCallback: () => runCallback, + retryOrElse: () => retryOrElse, + retry: () => retry, + request: () => request, + replicateEffect: () => replicateEffect2, + replicate: () => replicate2, + repeatOrElse: () => repeatOrElse, + repeatN: () => repeatN2, + repeat: () => repeat, + reduceWhile: () => reduceWhile2, + reduceRight: () => reduceRight3, + reduceEffect: () => reduceEffect2, + reduce: () => reduce10, + randomWith: () => randomWith2, + random: () => random3, + raceWith: () => raceWith2, + raceFirst: () => raceFirst2, + raceAll: () => raceAll2, + race: () => race2, + provideServiceEffect: () => provideServiceEffect2, + provideService: () => provideService2, + provide: () => provide2, + promise: () => promise2, + patchRuntimeFlags: () => patchRuntimeFlags, + patchFiberRefs: () => patchFiberRefs2, + partition: () => partition4, + parallelFinalizers: () => parallelFinalizers2, + parallelErrors: () => parallelErrors2, + orElseSucceed: () => orElseSucceed2, + orElseFail: () => orElseFail2, + orElse: () => orElse3, + orDieWith: () => orDieWith2, + orDie: () => orDie2, + optionFromOptional: () => optionFromOptional2, + option: () => option2, + once: () => once3, + onInterrupt: () => onInterrupt2, + onExit: () => onExit3, + onError: () => onError2, + none: () => none9, + never: () => never2, + negate: () => negate2, + metricLabels: () => metricLabels2, + mergeAll: () => mergeAll5, + merge: () => merge6, + matchEffect: () => matchEffect2, + matchCauseEffect: () => matchCauseEffect3, + matchCause: () => matchCause2, + match: () => match10, + mapInputContext: () => mapInputContext2, + mapErrorCause: () => mapErrorCause2, + mapError: () => mapError2, + mapBoth: () => mapBoth3, + mapAccum: () => mapAccum3, + map: () => map11, + makeSpanScoped: () => makeSpanScoped2, + makeSpan: () => makeSpan2, + makeSemaphore: () => makeSemaphore2, + makeLatch: () => makeLatch2, + loop: () => loop2, + logWithLevel: () => logWithLevel2, + logWarning: () => logWarning2, + logTrace: () => logTrace2, + logInfo: () => logInfo2, + logFatal: () => logFatal2, + logError: () => logError2, + logDebug: () => logDebug2, + logAnnotations: () => logAnnotations2, + log: () => log2, + locallyWith: () => locallyWith, + locallyScopedWith: () => locallyScopedWith, + locallyScoped: () => locallyScoped, + locally: () => locally, + linkSpans: () => linkSpans2, + linkSpanCurrent: () => linkSpanCurrent2, + liftPredicate: () => liftPredicate2, + let: () => let_3, + labelMetricsScoped: () => labelMetricsScoped2, + labelMetrics: () => labelMetrics2, + iterate: () => iterate2, + isSuccess: () => isSuccess3, + isFailure: () => isFailure3, + isEffect: () => isEffect2, + intoDeferred: () => intoDeferred2, + interruptibleMask: () => interruptibleMask2, + interruptible: () => interruptible4, + interruptWith: () => interruptWith2, + interrupt: () => interrupt5, + inheritFiberRefs: () => inheritFiberRefs2, + ignoreLogged: () => ignoreLogged2, + ignore: () => ignore2, + if: () => if_2, + head: () => head4, + getRuntimeFlags: () => getRuntimeFlags, + getFiberRefs: () => getFiberRefs, + gen: () => gen2, + functionWithSpan: () => functionWithSpan2, + fromNullable: () => fromNullable3, + fromFiberEffect: () => fromFiberEffect2, + fromFiber: () => fromFiber2, + forkWithErrorHandler: () => forkWithErrorHandler2, + forkScoped: () => forkScoped2, + forkIn: () => forkIn2, + forkDaemon: () => forkDaemon2, + forkAll: () => forkAll2, + fork: () => fork3, + forever: () => forever3, + forEach: () => forEach7, + fnUntraced: () => fnUntraced2, + fn: () => fn, + flipWith: () => flipWith2, + flip: () => flip2, + flatten: () => flatten6, + flatMap: () => flatMap9, + firstSuccessOf: () => firstSuccessOf2, + findFirst: () => findFirst6, + finalizersMask: () => finalizersMask2, + filterOrFail: () => filterOrFail2, + filterOrElse: () => filterOrElse2, + filterOrDieMessage: () => filterOrDieMessage2, + filterOrDie: () => filterOrDie2, + filterMap: () => filterMap5, + filterEffectOrFail: () => filterEffectOrFail2, + filterEffectOrElse: () => filterEffectOrElse2, + filter: () => filter7, + fiberIdWith: () => fiberIdWith2, + fiberId: () => fiberId2, + failSync: () => failSync2, + failCauseSync: () => failCauseSync2, + failCause: () => failCause5, + fail: () => fail5, + exit: () => exit2, + exists: () => exists3, + every: () => every6, + eventually: () => eventually2, + ensuringChildren: () => ensuringChildren2, + ensuringChild: () => ensuringChild2, + ensuring: () => ensuring2, + ensureSuccessType: () => ensureSuccessType, + ensureRequirementsType: () => ensureRequirementsType, + ensureErrorType: () => ensureErrorType, + either: () => either3, + dropWhile: () => dropWhile2, + dropUntil: () => dropUntil2, + disconnect: () => disconnect2, + diffFiberRefs: () => diffFiberRefs2, + dieSync: () => dieSync2, + dieMessage: () => dieMessage2, + die: () => die4, + descriptorWith: () => descriptorWith2, + descriptor: () => descriptor2, + delay: () => delay2, + daemonChildren: () => daemonChildren2, + custom: () => custom2, + currentSpan: () => currentSpan2, + currentPropagatedSpan: () => currentPropagatedSpan2, + currentParentSpan: () => currentParentSpan2, + contextWithEffect: () => contextWithEffect2, + contextWith: () => contextWith2, + context: () => context3, + consoleWith: () => consoleWith2, + console: () => console3, + configProviderWith: () => configProviderWith2, + clockWith: () => clockWith4, + clock: () => clock2, + checkInterruptible: () => checkInterruptible2, + cause: () => cause2, + catchTags: () => catchTags2, + catchTag: () => catchTag2, + catchSomeDefect: () => catchSomeDefect2, + catchSomeCause: () => catchSomeCause2, + catchSome: () => catchSome2, + catchIf: () => catchIf2, + catchAllDefect: () => catchAllDefect2, + catchAllCause: () => catchAllCause2, + catchAll: () => catchAll2, + catch: () => _catch2, + cachedWithTTL: () => cachedWithTTL, + cachedInvalidateWithTTL: () => cachedInvalidateWithTTL2, + cachedFunction: () => cachedFunction2, + cached: () => cached3, + cacheRequestResult: () => cacheRequestResult, + blocked: () => blocked2, + bindTo: () => bindTo3, + bindAll: () => bindAll2, + bind: () => bind3, + awaitAllChildren: () => awaitAllChildren2, + asyncEffect: () => asyncEffect2, + async: () => async, + asVoid: () => asVoid3, + asSomeError: () => asSomeError2, + asSome: () => asSome2, + as: () => as3, + ap: () => ap, + annotateSpans: () => annotateSpans2, + annotateLogsScoped: () => annotateLogsScoped2, + annotateLogs: () => annotateLogs2, + annotateCurrentSpan: () => annotateCurrentSpan2, + andThen: () => andThen4, + allowInterrupt: () => allowInterrupt2, + allWith: () => allWith2, + allSuccesses: () => allSuccesses2, + all: () => all3, + addFinalizer: () => addFinalizer2, + acquireUseRelease: () => acquireUseRelease2, + acquireReleaseInterruptible: () => acquireReleaseInterruptible2, + acquireRelease: () => acquireRelease2, + Tag: () => Tag2, + Service: () => Service, + EffectTypeId: () => EffectTypeId3, + Do: () => Do2 +}); + +// node_modules/effect/dist/esm/internal/clock.js +var ClockSymbolKey = "effect/Clock"; +var ClockTypeId = /* @__PURE__ */ Symbol.for(ClockSymbolKey); +var clockTag = /* @__PURE__ */ GenericTag("effect/Clock"); +var MAX_TIMER_MILLIS = 2 ** 31 - 1; +var globalClockScheduler = { + unsafeSchedule(task, duration) { + const millis2 = toMillis(duration); + if (millis2 > MAX_TIMER_MILLIS) { + return constFalse; + } + let completed = false; + const handle = setTimeout(() => { + completed = true; + task(); + }, millis2); + return () => { + clearTimeout(handle); + return !completed; + }; + } +}; +var performanceNowNanos = /* @__PURE__ */ function() { + const bigint1e62 = /* @__PURE__ */ BigInt(1e6); + if (typeof performance === "undefined" || typeof performance.now !== "function") { + return () => BigInt(Date.now()) * bigint1e62; + } + let origin; + return () => { + if (origin === undefined) { + origin = BigInt(Date.now()) * bigint1e62 - BigInt(Math.round(performance.now() * 1e6)); + } + return origin + BigInt(Math.round(performance.now() * 1e6)); + }; +}(); +var processOrPerformanceNow = /* @__PURE__ */ function() { + const processHrtime = typeof process === "object" && "hrtime" in process && typeof process.hrtime.bigint === "function" ? process.hrtime : undefined; + if (!processHrtime) { + return performanceNowNanos; + } + const origin = /* @__PURE__ */ performanceNowNanos() - /* @__PURE__ */ processHrtime.bigint(); + return () => origin + processHrtime.bigint(); +}(); + +class ClockImpl { + [ClockTypeId] = ClockTypeId; + unsafeCurrentTimeMillis() { + return Date.now(); + } + unsafeCurrentTimeNanos() { + return processOrPerformanceNow(); + } + currentTimeMillis = /* @__PURE__ */ sync(() => this.unsafeCurrentTimeMillis()); + currentTimeNanos = /* @__PURE__ */ sync(() => this.unsafeCurrentTimeNanos()); + scheduler() { + return succeed(globalClockScheduler); + } + sleep(duration) { + return async_((resume) => { + const canceler = globalClockScheduler.unsafeSchedule(() => resume(void_), duration); + return asVoid(sync(canceler)); + }); + } +} +var make18 = () => new ClockImpl; + +// node_modules/effect/dist/esm/Number.js +var Order2 = number3; +var clamp4 = /* @__PURE__ */ clamp(Order2); +var remainder = /* @__PURE__ */ dual(2, (dividend, divisor) => { + const selfDecCount = (dividend.toString().split(".")[1] || "").length; + const divisorDecCount = (divisor.toString().split(".")[1] || "").length; + const decCount = selfDecCount > divisorDecCount ? selfDecCount : divisorDecCount; + const selfInt = parseInt(dividend.toFixed(decCount).replace(".", "")); + const divisorInt = parseInt(divisor.toFixed(decCount).replace(".", "")); + return selfInt % divisorInt / Math.pow(10, decCount); +}); +var parse = (s) => { + if (s === "NaN") { + return some(NaN); + } + if (s === "Infinity") { + return some(Infinity); + } + if (s === "-Infinity") { + return some(-Infinity); + } + if (s.trim() === "") { + return none; + } + const n = Number(s); + return Number.isNaN(n) ? none : some(n); +}; + +// node_modules/effect/dist/esm/RegExp.js +var escape = (string2) => string2.replace(/[/\\^$*+?.()|[\]{}]/g, "\\$&"); + +// node_modules/effect/dist/esm/internal/opCodes/configError.js +var OP_AND = "And"; +var OP_OR = "Or"; +var OP_INVALID_DATA = "InvalidData"; +var OP_MISSING_DATA = "MissingData"; +var OP_SOURCE_UNAVAILABLE = "SourceUnavailable"; +var OP_UNSUPPORTED = "Unsupported"; + +// node_modules/effect/dist/esm/internal/configError.js +var ConfigErrorSymbolKey = "effect/ConfigError"; +var ConfigErrorTypeId = /* @__PURE__ */ Symbol.for(ConfigErrorSymbolKey); +var proto2 = { + _tag: "ConfigError", + [ConfigErrorTypeId]: ConfigErrorTypeId +}; +var And = (self, that) => { + const error = Object.create(proto2); + error._op = OP_AND; + error.left = self; + error.right = that; + Object.defineProperty(error, "toString", { + enumerable: false, + value() { + return `${this.left} and ${this.right}`; + } + }); + Object.defineProperty(error, "message", { + enumerable: false, + get() { + return this.toString(); + } + }); + return error; +}; +var Or = (self, that) => { + const error = Object.create(proto2); + error._op = OP_OR; + error.left = self; + error.right = that; + Object.defineProperty(error, "toString", { + enumerable: false, + value() { + return `${this.left} or ${this.right}`; + } + }); + Object.defineProperty(error, "message", { + enumerable: false, + get() { + return this.toString(); + } + }); + return error; +}; +var InvalidData = (path, message, options = { + pathDelim: "." +}) => { + const error = Object.create(proto2); + error._op = OP_INVALID_DATA; + error.path = path; + error.message = message; + Object.defineProperty(error, "toString", { + enumerable: false, + value() { + const path2 = pipe(this.path, join(options.pathDelim)); + return `(Invalid data at ${path2}: "${this.message}")`; + } + }); + return error; +}; +var MissingData = (path, message, options = { + pathDelim: "." +}) => { + const error = Object.create(proto2); + error._op = OP_MISSING_DATA; + error.path = path; + error.message = message; + Object.defineProperty(error, "toString", { + enumerable: false, + value() { + const path2 = pipe(this.path, join(options.pathDelim)); + return `(Missing data at ${path2}: "${this.message}")`; + } + }); + return error; +}; +var SourceUnavailable = (path, message, cause, options = { + pathDelim: "." +}) => { + const error = Object.create(proto2); + error._op = OP_SOURCE_UNAVAILABLE; + error.path = path; + error.message = message; + error.cause = cause; + Object.defineProperty(error, "toString", { + enumerable: false, + value() { + const path2 = pipe(this.path, join(options.pathDelim)); + return `(Source unavailable at ${path2}: "${this.message}")`; + } + }); + return error; +}; +var Unsupported = (path, message, options = { + pathDelim: "." +}) => { + const error = Object.create(proto2); + error._op = OP_UNSUPPORTED; + error.path = path; + error.message = message; + Object.defineProperty(error, "toString", { + enumerable: false, + value() { + const path2 = pipe(this.path, join(options.pathDelim)); + return `(Unsupported operation at ${path2}: "${this.message}")`; + } + }); + return error; +}; +var prefixed = /* @__PURE__ */ dual(2, (self, prefix) => { + switch (self._op) { + case OP_AND: { + return And(prefixed(self.left, prefix), prefixed(self.right, prefix)); + } + case OP_OR: { + return Or(prefixed(self.left, prefix), prefixed(self.right, prefix)); + } + case OP_INVALID_DATA: { + return InvalidData([...prefix, ...self.path], self.message); + } + case OP_MISSING_DATA: { + return MissingData([...prefix, ...self.path], self.message); + } + case OP_SOURCE_UNAVAILABLE: { + return SourceUnavailable([...prefix, ...self.path], self.message, self.cause); + } + case OP_UNSUPPORTED: { + return Unsupported([...prefix, ...self.path], self.message); + } + } +}); + +// node_modules/effect/dist/esm/internal/configProvider/pathPatch.js +var empty17 = { + _tag: "Empty" +}; +var patch5 = /* @__PURE__ */ dual(2, (path, patch6) => { + let input = of3(patch6); + let output = path; + while (isCons(input)) { + const patch7 = input.head; + switch (patch7._tag) { + case "Empty": { + input = input.tail; + break; + } + case "AndThen": { + input = cons(patch7.first, cons(patch7.second, input.tail)); + break; + } + case "MapName": { + output = map3(output, patch7.f); + input = input.tail; + break; + } + case "Nested": { + output = prepend(output, patch7.name); + input = input.tail; + break; + } + case "Unnested": { + const containsName = pipe(head(output), contains(patch7.name)); + if (containsName) { + output = tailNonEmpty(output); + input = input.tail; + } else { + return left2(MissingData(output, `Expected ${patch7.name} to be in path in ConfigProvider#unnested`)); + } + break; + } + } + } + return right2(output); +}); + +// node_modules/effect/dist/esm/internal/opCodes/config.js +var OP_CONSTANT = "Constant"; +var OP_FAIL2 = "Fail"; +var OP_FALLBACK = "Fallback"; +var OP_DESCRIBED = "Described"; +var OP_LAZY = "Lazy"; +var OP_MAP_OR_FAIL = "MapOrFail"; +var OP_NESTED = "Nested"; +var OP_PRIMITIVE = "Primitive"; +var OP_SEQUENCE = "Sequence"; +var OP_HASHMAP = "HashMap"; +var OP_ZIP_WITH = "ZipWith"; + +// node_modules/effect/dist/esm/internal/configProvider.js +var concat = (l, r) => [...l, ...r]; +var ConfigProviderSymbolKey = "effect/ConfigProvider"; +var ConfigProviderTypeId = /* @__PURE__ */ Symbol.for(ConfigProviderSymbolKey); +var configProviderTag = /* @__PURE__ */ GenericTag("effect/ConfigProvider"); +var FlatConfigProviderSymbolKey = "effect/ConfigProviderFlat"; +var FlatConfigProviderTypeId = /* @__PURE__ */ Symbol.for(FlatConfigProviderSymbolKey); +var make20 = (options) => ({ + [ConfigProviderTypeId]: ConfigProviderTypeId, + pipe() { + return pipeArguments(this, arguments); + }, + ...options +}); +var makeFlat = (options) => ({ + [FlatConfigProviderTypeId]: FlatConfigProviderTypeId, + patch: options.patch, + load: (path, config, split = true) => options.load(path, config, split), + enumerateChildren: options.enumerateChildren +}); +var fromFlat = (flat) => make20({ + load: (config) => flatMap7(fromFlatLoop(flat, empty(), config, false), (chunk) => match2(head(chunk), { + onNone: () => fail2(MissingData(empty(), `Expected a single value having structure: ${config}`)), + onSome: succeed + })), + flattened: flat +}); +var fromEnv = (options) => { + const { + pathDelim, + seqDelim + } = Object.assign({}, { + pathDelim: "_", + seqDelim: "," + }, options); + const makePathString = (path) => pipe(path, join(pathDelim)); + const unmakePathString = (pathString) => pathString.split(pathDelim); + const getEnv = () => typeof process !== "undefined" && ("env" in process) && typeof process.env === "object" ? process.env : {}; + const load = (path, primitive, split = true) => { + const pathString = makePathString(path); + const current = getEnv(); + const valueOpt = pathString in current ? some2(current[pathString]) : none2(); + return pipe(valueOpt, mapError(() => MissingData(path, `Expected ${pathString} to exist in the process context`)), flatMap7((value) => parsePrimitive(value, path, primitive, seqDelim, split))); + }; + const enumerateChildren = (path) => sync(() => { + const current = getEnv(); + const keys3 = Object.keys(current); + const keyPaths = keys3.map((value) => unmakePathString(value.toUpperCase())); + const filteredKeyPaths = keyPaths.filter((keyPath) => { + for (let i = 0;i < path.length; i++) { + const pathComponent = pipe(path, unsafeGet(i)); + const currentElement = keyPath[i]; + if (currentElement === undefined || pathComponent !== currentElement) { + return false; + } + } + return true; + }).flatMap((keyPath) => keyPath.slice(path.length, path.length + 1)); + return fromIterable5(filteredKeyPaths); + }); + return fromFlat(makeFlat({ + load, + enumerateChildren, + patch: empty17 + })); +}; +var extend = (leftDef, rightDef, left3, right3) => { + const leftPad = unfold(left3.length, (index) => index >= right3.length ? none2() : some2([leftDef(index), index + 1])); + const rightPad = unfold(right3.length, (index) => index >= left3.length ? none2() : some2([rightDef(index), index + 1])); + const leftExtension = concat(left3, leftPad); + const rightExtension = concat(right3, rightPad); + return [leftExtension, rightExtension]; +}; +var appendConfigPath = (path, config) => { + let op = config; + if (op._tag === "Nested") { + const out = path.slice(); + while (op._tag === "Nested") { + out.push(op.name); + op = op.config; + } + return out; + } + return path; +}; +var fromFlatLoop = (flat, prefix, config, split) => { + const op = config; + switch (op._tag) { + case OP_CONSTANT: { + return succeed(of(op.value)); + } + case OP_DESCRIBED: { + return suspend(() => fromFlatLoop(flat, prefix, op.config, split)); + } + case OP_FAIL2: { + return fail2(MissingData(prefix, op.message)); + } + case OP_FALLBACK: { + return pipe(suspend(() => fromFlatLoop(flat, prefix, op.first, split)), catchAll((error1) => { + if (op.condition(error1)) { + return pipe(fromFlatLoop(flat, prefix, op.second, split), catchAll((error2) => fail2(Or(error1, error2)))); + } + return fail2(error1); + })); + } + case OP_LAZY: { + return suspend(() => fromFlatLoop(flat, prefix, op.config(), split)); + } + case OP_MAP_OR_FAIL: { + return suspend(() => pipe(fromFlatLoop(flat, prefix, op.original, split), flatMap7(forEachSequential((a) => pipe(op.mapOrFail(a), mapError(prefixed(appendConfigPath(prefix, op.original)))))))); + } + case OP_NESTED: { + return suspend(() => fromFlatLoop(flat, concat(prefix, of(op.name)), op.config, split)); + } + case OP_PRIMITIVE: { + return pipe(patch5(prefix, flat.patch), flatMap7((prefix2) => pipe(flat.load(prefix2, op, split), flatMap7((values3) => { + if (values3.length === 0) { + const name = pipe(last(prefix2), getOrElse(() => "")); + return fail2(MissingData([], `Expected ${op.description} with name ${name}`)); + } + return succeed(values3); + })))); + } + case OP_SEQUENCE: { + return pipe(patch5(prefix, flat.patch), flatMap7((patchedPrefix) => pipe(flat.enumerateChildren(patchedPrefix), flatMap7(indicesFrom), flatMap7((indices) => { + if (indices.length === 0) { + return suspend(() => map9(fromFlatLoop(flat, prefix, op.config, true), of)); + } + return pipe(forEachSequential(indices, (index) => fromFlatLoop(flat, append(prefix, `[${index}]`), op.config, true)), map9((chunkChunk) => { + const flattened = flatten(chunkChunk); + if (flattened.length === 0) { + return of(empty()); + } + return of(flattened); + })); + })))); + } + case OP_HASHMAP: { + return suspend(() => pipe(patch5(prefix, flat.patch), flatMap7((prefix2) => pipe(flat.enumerateChildren(prefix2), flatMap7((keys3) => { + return pipe(keys3, forEachSequential((key) => fromFlatLoop(flat, concat(prefix2, of(key)), op.valueConfig, split)), map9((matrix) => { + if (matrix.length === 0) { + return of(empty8()); + } + return pipe(transpose(matrix), map3((values3) => fromIterable6(zip(fromIterable(keys3), values3)))); + })); + }))))); + } + case OP_ZIP_WITH: { + return suspend(() => pipe(fromFlatLoop(flat, prefix, op.left, split), either2, flatMap7((left3) => pipe(fromFlatLoop(flat, prefix, op.right, split), either2, flatMap7((right3) => { + if (isLeft2(left3) && isLeft2(right3)) { + return fail2(And(left3.left, right3.left)); + } + if (isLeft2(left3) && isRight2(right3)) { + return fail2(left3.left); + } + if (isRight2(left3) && isLeft2(right3)) { + return fail2(right3.left); + } + if (isRight2(left3) && isRight2(right3)) { + const path = pipe(prefix, join(".")); + const fail3 = fromFlatLoopFail(prefix, path); + const [lefts, rights] = extend(fail3, fail3, pipe(left3.right, map3(right2)), pipe(right3.right, map3(right2))); + return pipe(lefts, zip(rights), forEachSequential(([left4, right4]) => pipe(zip2(left4, right4), map9(([left5, right5]) => op.zip(left5, right5))))); + } + throw new Error("BUG: ConfigProvider.fromFlatLoop - please report an issue at https://github.com/Effect-TS/effect/issues"); + }))))); + } + } +}; +var fromFlatLoopFail = (prefix, path) => (index) => left2(MissingData(prefix, `The element at index ${index} in a sequence at path "${path}" was missing`)); +var splitPathString = (text, delim) => { + const split = text.split(new RegExp(`\\s*${escape(delim)}\\s*`)); + return split; +}; +var parsePrimitive = (text, path, primitive, delimiter, split) => { + if (!split) { + return pipe(primitive.parse(text), mapBoth2({ + onFailure: prefixed(path), + onSuccess: of + })); + } + return pipe(splitPathString(text, delimiter), forEachSequential((char) => primitive.parse(char.trim())), mapError(prefixed(path))); +}; +var transpose = (array4) => { + return Object.keys(array4[0]).map((column) => array4.map((row) => row[column])); +}; +var indicesFrom = (quotedIndices) => pipe(forEachSequential(quotedIndices, parseQuotedIndex), mapBoth2({ + onFailure: () => empty(), + onSuccess: sort(Order2) +}), either2, map9(merge)); +var QUOTED_INDEX_REGEX = /^(\[(\d+)\])$/; +var parseQuotedIndex = (str) => { + const match6 = str.match(QUOTED_INDEX_REGEX); + if (match6 !== null) { + const matchedIndex = match6[2]; + return pipe(matchedIndex !== undefined && matchedIndex.length > 0 ? some2(matchedIndex) : none2(), flatMap(parseInteger)); + } + return none2(); +}; +var parseInteger = (str) => { + const parsedIndex = Number.parseInt(str); + return Number.isNaN(parsedIndex) ? none2() : some2(parsedIndex); +}; + +// node_modules/effect/dist/esm/internal/defaultServices/console.js +var TypeId8 = /* @__PURE__ */ Symbol.for("effect/Console"); +var consoleTag = /* @__PURE__ */ GenericTag("effect/Console"); +var defaultConsole = { + [TypeId8]: TypeId8, + assert(condition, ...args) { + return sync(() => { + console.assert(condition, ...args); + }); + }, + clear: /* @__PURE__ */ sync(() => { + console.clear(); + }), + count(label) { + return sync(() => { + console.count(label); + }); + }, + countReset(label) { + return sync(() => { + console.countReset(label); + }); + }, + debug(...args) { + return sync(() => { + console.debug(...args); + }); + }, + dir(item, options) { + return sync(() => { + console.dir(item, options); + }); + }, + dirxml(...args) { + return sync(() => { + console.dirxml(...args); + }); + }, + error(...args) { + return sync(() => { + console.error(...args); + }); + }, + group(options) { + return options?.collapsed ? sync(() => console.groupCollapsed(options?.label)) : sync(() => console.group(options?.label)); + }, + groupEnd: /* @__PURE__ */ sync(() => { + console.groupEnd(); + }), + info(...args) { + return sync(() => { + console.info(...args); + }); + }, + log(...args) { + return sync(() => { + console.log(...args); + }); + }, + table(tabularData, properties) { + return sync(() => { + console.table(tabularData, properties); + }); + }, + time(label) { + return sync(() => console.time(label)); + }, + timeEnd(label) { + return sync(() => console.timeEnd(label)); + }, + timeLog(label, ...args) { + return sync(() => { + console.timeLog(label, ...args); + }); + }, + trace(...args) { + return sync(() => { + console.trace(...args); + }); + }, + warn(...args) { + return sync(() => { + console.warn(...args); + }); + }, + unsafe: console +}; + +// node_modules/effect/dist/esm/internal/random.js +var RandomSymbolKey = "effect/Random"; +var RandomTypeId = /* @__PURE__ */ Symbol.for(RandomSymbolKey); +var randomTag = /* @__PURE__ */ GenericTag("effect/Random"); + +class RandomImpl { + seed; + [RandomTypeId] = RandomTypeId; + PRNG; + constructor(seed) { + this.seed = seed; + this.PRNG = new PCGRandom(seed); + } + get next() { + return sync(() => this.PRNG.number()); + } + get nextBoolean() { + return map9(this.next, (n) => n > 0.5); + } + get nextInt() { + return sync(() => this.PRNG.integer(Number.MAX_SAFE_INTEGER)); + } + nextRange(min2, max2) { + return map9(this.next, (n) => (max2 - min2) * n + min2); + } + nextIntBetween(min2, max2) { + return sync(() => this.PRNG.integer(max2 - min2) + min2); + } + shuffle(elements) { + return shuffleWith(elements, (n) => this.nextIntBetween(0, n)); + } +} +var shuffleWith = (elements, nextIntBounded) => { + return suspend(() => pipe(sync(() => Array.from(elements)), flatMap7((buffer) => { + const numbers = []; + for (let i = buffer.length;i >= 2; i = i - 1) { + numbers.push(i); + } + return pipe(numbers, forEachSequentialDiscard((n) => pipe(nextIntBounded(n), map9((k) => swap(buffer, n - 1, k)))), as(fromIterable2(buffer))); + }))); +}; +var swap = (buffer, index1, index2) => { + const tmp = buffer[index1]; + buffer[index1] = buffer[index2]; + buffer[index2] = tmp; + return buffer; +}; +var make21 = (seed) => new RandomImpl(hash(seed)); + +class FixedRandomImpl { + values; + [RandomTypeId] = RandomTypeId; + index = 0; + constructor(values3) { + this.values = values3; + if (values3.length === 0) { + throw new Error("Requires at least one value"); + } + } + getNextValue() { + const value = this.values[this.index]; + this.index = (this.index + 1) % this.values.length; + return value; + } + get next() { + return sync(() => { + const value = this.getNextValue(); + if (typeof value === "number") { + return Math.max(0, Math.min(1, value)); + } + return hash(value) / 2147483647; + }); + } + get nextBoolean() { + return sync(() => { + const value = this.getNextValue(); + if (typeof value === "boolean") { + return value; + } + return hash(value) % 2 === 0; + }); + } + get nextInt() { + return sync(() => { + const value = this.getNextValue(); + if (typeof value === "number" && Number.isFinite(value)) { + return Math.round(value); + } + return Math.abs(hash(value)); + }); + } + nextRange(min2, max2) { + return map9(this.next, (n) => (max2 - min2) * n + min2); + } + nextIntBetween(min2, max2) { + return sync(() => { + const value = this.getNextValue(); + if (typeof value === "number" && Number.isFinite(value)) { + return Math.max(min2, Math.min(max2 - 1, Math.round(value))); + } + const hash2 = Math.abs(hash(value)); + return min2 + hash2 % (max2 - min2); + }); + } + shuffle(elements) { + return shuffleWith(elements, (n) => this.nextIntBetween(0, n)); + } +} +var fixed = (values3) => new FixedRandomImpl(values3); + +// node_modules/effect/dist/esm/internal/tracer.js +var TracerTypeId = /* @__PURE__ */ Symbol.for("effect/Tracer"); +var make22 = (options) => ({ + [TracerTypeId]: TracerTypeId, + ...options +}); +var tracerTag = /* @__PURE__ */ GenericTag("effect/Tracer"); +var spanTag = /* @__PURE__ */ GenericTag("effect/ParentSpan"); +var randomHexString = /* @__PURE__ */ function() { + const characters = "abcdef0123456789"; + const charactersLength = characters.length; + return function(length) { + let result = ""; + for (let i = 0;i < length; i++) { + result += characters.charAt(Math.floor(Math.random() * charactersLength)); + } + return result; + }; +}(); + +class NativeSpan { + name; + parent; + context; + startTime; + kind; + _tag = "Span"; + spanId; + traceId = "native"; + sampled = true; + status; + attributes; + events = []; + links; + constructor(name, parent, context2, links, startTime, kind) { + this.name = name; + this.parent = parent; + this.context = context2; + this.startTime = startTime; + this.kind = kind; + this.status = { + _tag: "Started", + startTime + }; + this.attributes = new Map; + this.traceId = parent._tag === "Some" ? parent.value.traceId : randomHexString(32); + this.spanId = randomHexString(16); + this.links = Array.from(links); + } + end(endTime, exit2) { + this.status = { + _tag: "Ended", + endTime, + exit: exit2, + startTime: this.status.startTime + }; + } + attribute(key, value) { + this.attributes.set(key, value); + } + event(name, startTime, attributes) { + this.events.push([name, startTime, attributes ?? {}]); + } + addLinks(links) { + this.links.push(...links); + } +} +var nativeTracer = /* @__PURE__ */ make22({ + span: (name, parent, context2, links, startTime, kind) => new NativeSpan(name, parent, context2, links, startTime, kind), + context: (f) => f() +}); +var addSpanStackTrace = (options) => { + if (options?.captureStackTrace === false) { + return options; + } else if (options?.captureStackTrace !== undefined && typeof options.captureStackTrace !== "boolean") { + return options; + } + const limit = Error.stackTraceLimit; + Error.stackTraceLimit = 3; + const traceError = new Error; + Error.stackTraceLimit = limit; + let cache = false; + return { + ...options, + captureStackTrace: () => { + if (cache !== false) { + return cache; + } + if (traceError.stack !== undefined) { + const stack = traceError.stack.split(` +`); + if (stack[3] !== undefined) { + cache = stack[3].trim(); + return cache; + } + } + } + }; +}; +var DisablePropagation = /* @__PURE__ */ Reference2()("effect/Tracer/DisablePropagation", { + defaultValue: constFalse +}); + +// node_modules/effect/dist/esm/internal/defaultServices.js +var liveServices = /* @__PURE__ */ pipe(/* @__PURE__ */ empty4(), /* @__PURE__ */ add2(clockTag, /* @__PURE__ */ make18()), /* @__PURE__ */ add2(consoleTag, defaultConsole), /* @__PURE__ */ add2(randomTag, /* @__PURE__ */ make21(/* @__PURE__ */ Math.random())), /* @__PURE__ */ add2(configProviderTag, /* @__PURE__ */ fromEnv()), /* @__PURE__ */ add2(tracerTag, nativeTracer)); +var currentServices = /* @__PURE__ */ globalValue(/* @__PURE__ */ Symbol.for("effect/DefaultServices/currentServices"), () => fiberRefUnsafeMakeContext(liveServices)); +var sleep = (duration) => { + const decodedDuration = decode(duration); + return clockWith((clock) => clock.sleep(decodedDuration)); +}; +var defaultServicesWith = (f) => withFiberRuntime((fiber) => f(fiber.currentDefaultServices)); +var clockWith = (f) => defaultServicesWith((services) => f(services.unsafeMap.get(clockTag.key))); +var currentTimeMillis = /* @__PURE__ */ clockWith((clock) => clock.currentTimeMillis); +var currentTimeNanos = /* @__PURE__ */ clockWith((clock) => clock.currentTimeNanos); +var withClock = /* @__PURE__ */ dual(2, (effect, c) => fiberRefLocallyWith(currentServices, add2(clockTag, c))(effect)); +var withConfigProvider = /* @__PURE__ */ dual(2, (self, provider) => fiberRefLocallyWith(currentServices, add2(configProviderTag, provider))(self)); +var configProviderWith = (f) => defaultServicesWith((services) => f(services.unsafeMap.get(configProviderTag.key))); +var config = (config2) => configProviderWith((_) => _.load(config2)); +var randomWith = (f) => defaultServicesWith((services) => f(services.unsafeMap.get(randomTag.key))); +var withRandom = /* @__PURE__ */ dual(2, (effect, value) => fiberRefLocallyWith(currentServices, add2(randomTag, value))(effect)); +var tracerWith = (f) => defaultServicesWith((services) => f(services.unsafeMap.get(tracerTag.key))); +var withTracer = /* @__PURE__ */ dual(2, (effect, value) => fiberRefLocallyWith(currentServices, add2(tracerTag, value))(effect)); + +// node_modules/effect/dist/esm/Boolean.js +var not = (self) => !self; + +// node_modules/effect/dist/esm/Effectable.js +var EffectPrototype2 = EffectPrototype; +var CommitPrototype2 = CommitPrototype; +var Base2 = Base; +class Class2 extends Base2 { +} + +// node_modules/effect/dist/esm/internal/executionStrategy.js +var OP_SEQUENTIAL2 = "Sequential"; +var OP_PARALLEL2 = "Parallel"; +var OP_PARALLEL_N = "ParallelN"; +var sequential2 = { + _tag: OP_SEQUENTIAL2 +}; +var parallel2 = { + _tag: OP_PARALLEL2 +}; +var parallelN = (parallelism) => ({ + _tag: OP_PARALLEL_N, + parallelism +}); +var isSequential = (self) => self._tag === OP_SEQUENTIAL2; +var isParallel = (self) => self._tag === OP_PARALLEL2; + +// node_modules/effect/dist/esm/ExecutionStrategy.js +var sequential3 = sequential2; +var parallel3 = parallel2; +var parallelN2 = parallelN; + +// node_modules/effect/dist/esm/internal/fiberRefs.js +function unsafeMake3(fiberRefLocals) { + return new FiberRefsImpl(fiberRefLocals); +} +function empty18() { + return unsafeMake3(new Map); +} +var FiberRefsSym = /* @__PURE__ */ Symbol.for("effect/FiberRefs"); + +class FiberRefsImpl { + locals; + [FiberRefsSym] = FiberRefsSym; + constructor(locals) { + this.locals = locals; + } + pipe() { + return pipeArguments(this, arguments); + } +} +var findAncestor = (_ref, _parentStack, _childStack, _childModified = false) => { + const ref = _ref; + let parentStack = _parentStack; + let childStack = _childStack; + let childModified = _childModified; + let ret = undefined; + while (ret === undefined) { + if (isNonEmptyReadonlyArray(parentStack) && isNonEmptyReadonlyArray(childStack)) { + const parentFiberId = headNonEmpty(parentStack)[0]; + const parentAncestors = tailNonEmpty(parentStack); + const childFiberId = headNonEmpty(childStack)[0]; + const childRefValue = headNonEmpty(childStack)[1]; + const childAncestors = tailNonEmpty(childStack); + if (parentFiberId.startTimeMillis < childFiberId.startTimeMillis) { + childStack = childAncestors; + childModified = true; + } else if (parentFiberId.startTimeMillis > childFiberId.startTimeMillis) { + parentStack = parentAncestors; + } else { + if (parentFiberId.id < childFiberId.id) { + childStack = childAncestors; + childModified = true; + } else if (parentFiberId.id > childFiberId.id) { + parentStack = parentAncestors; + } else { + ret = [childRefValue, childModified]; + } + } + } else { + ret = [ref.initial, true]; + } + } + return ret; +}; +var joinAs = /* @__PURE__ */ dual(3, (self, fiberId2, that) => { + const parentFiberRefs = new Map(self.locals); + that.locals.forEach((childStack, fiberRef) => { + const childValue = childStack[0][1]; + if (!childStack[0][0][symbol2](fiberId2)) { + if (!parentFiberRefs.has(fiberRef)) { + if (equals(childValue, fiberRef.initial)) { + return; + } + parentFiberRefs.set(fiberRef, [[fiberId2, fiberRef.join(fiberRef.initial, childValue)]]); + return; + } + const parentStack = parentFiberRefs.get(fiberRef); + const [ancestor, wasModified] = findAncestor(fiberRef, parentStack, childStack); + if (wasModified) { + const patch6 = fiberRef.diff(ancestor, childValue); + const oldValue = parentStack[0][1]; + const newValue = fiberRef.join(oldValue, fiberRef.patch(patch6)(oldValue)); + if (!equals(oldValue, newValue)) { + let newStack; + const parentFiberId = parentStack[0][0]; + if (parentFiberId[symbol2](fiberId2)) { + newStack = [[parentFiberId, newValue], ...parentStack.slice(1)]; + } else { + newStack = [[fiberId2, newValue], ...parentStack]; + } + parentFiberRefs.set(fiberRef, newStack); + } + } + } + }); + return new FiberRefsImpl(parentFiberRefs); +}); +var forkAs = /* @__PURE__ */ dual(2, (self, childId) => { + const map10 = new Map; + unsafeForkAs(self, map10, childId); + return new FiberRefsImpl(map10); +}); +var unsafeForkAs = (self, map10, fiberId2) => { + self.locals.forEach((stack, fiberRef) => { + const oldValue = stack[0][1]; + const newValue = fiberRef.patch(fiberRef.fork)(oldValue); + if (equals(oldValue, newValue)) { + map10.set(fiberRef, stack); + } else { + map10.set(fiberRef, [[fiberId2, newValue], ...stack]); + } + }); +}; +var fiberRefs = (self) => fromIterable5(self.locals.keys()); +var setAll = (self) => forEachSequentialDiscard(fiberRefs(self), (fiberRef) => fiberRefSet(fiberRef, getOrDefault(self, fiberRef))); +var delete_ = /* @__PURE__ */ dual(2, (self, fiberRef) => { + const locals = new Map(self.locals); + locals.delete(fiberRef); + return new FiberRefsImpl(locals); +}); +var get8 = /* @__PURE__ */ dual(2, (self, fiberRef) => { + if (!self.locals.has(fiberRef)) { + return none2(); + } + return some2(headNonEmpty(self.locals.get(fiberRef))[1]); +}); +var getOrDefault = /* @__PURE__ */ dual(2, (self, fiberRef) => pipe(get8(self, fiberRef), getOrElse(() => fiberRef.initial))); +var updateAs = /* @__PURE__ */ dual(2, (self, { + fiberId: fiberId2, + fiberRef, + value +}) => { + if (self.locals.size === 0) { + return new FiberRefsImpl(new Map([[fiberRef, [[fiberId2, value]]]])); + } + const locals = new Map(self.locals); + unsafeUpdateAs(locals, fiberId2, fiberRef, value); + return new FiberRefsImpl(locals); +}); +var unsafeUpdateAs = (locals, fiberId2, fiberRef, value) => { + const oldStack = locals.get(fiberRef) ?? []; + let newStack; + if (isNonEmptyReadonlyArray(oldStack)) { + const [currentId, currentValue] = headNonEmpty(oldStack); + if (currentId[symbol2](fiberId2)) { + if (equals(currentValue, value)) { + return; + } else { + newStack = [[fiberId2, value], ...oldStack.slice(1)]; + } + } else { + newStack = [[fiberId2, value], ...oldStack]; + } + } else { + newStack = [[fiberId2, value]]; + } + locals.set(fiberRef, newStack); +}; +var updateManyAs = /* @__PURE__ */ dual(2, (self, { + entries: entries2, + forkAs: forkAs2 +}) => { + if (self.locals.size === 0) { + return new FiberRefsImpl(new Map(entries2)); + } + const locals = new Map(self.locals); + if (forkAs2 !== undefined) { + unsafeForkAs(self, locals, forkAs2); + } + entries2.forEach(([fiberRef, values3]) => { + if (values3.length === 1) { + unsafeUpdateAs(locals, values3[0][0], fiberRef, values3[0][1]); + } else { + values3.forEach(([fiberId2, value]) => { + unsafeUpdateAs(locals, fiberId2, fiberRef, value); + }); + } + }); + return new FiberRefsImpl(locals); +}); + +// node_modules/effect/dist/esm/FiberRefs.js +var get9 = get8; +var getOrDefault2 = getOrDefault; +var joinAs2 = joinAs; +var setAll2 = setAll; +var updateManyAs2 = updateManyAs; +var empty19 = empty18; + +// node_modules/effect/dist/esm/internal/fiberRefs/patch.js +var OP_EMPTY2 = "Empty"; +var OP_ADD = "Add"; +var OP_REMOVE = "Remove"; +var OP_UPDATE = "Update"; +var OP_AND_THEN = "AndThen"; +var empty20 = { + _tag: OP_EMPTY2 +}; +var diff5 = (oldValue, newValue) => { + const missingLocals = new Map(oldValue.locals); + let patch6 = empty20; + for (const [fiberRef, pairs] of newValue.locals.entries()) { + const newValue2 = headNonEmpty(pairs)[1]; + const old = missingLocals.get(fiberRef); + if (old !== undefined) { + const oldValue2 = headNonEmpty(old)[1]; + if (!equals(oldValue2, newValue2)) { + patch6 = combine7({ + _tag: OP_UPDATE, + fiberRef, + patch: fiberRef.diff(oldValue2, newValue2) + })(patch6); + } + } else { + patch6 = combine7({ + _tag: OP_ADD, + fiberRef, + value: newValue2 + })(patch6); + } + missingLocals.delete(fiberRef); + } + for (const [fiberRef] of missingLocals.entries()) { + patch6 = combine7({ + _tag: OP_REMOVE, + fiberRef + })(patch6); + } + return patch6; +}; +var combine7 = /* @__PURE__ */ dual(2, (self, that) => ({ + _tag: OP_AND_THEN, + first: self, + second: that +})); +var patch6 = /* @__PURE__ */ dual(3, (self, fiberId2, oldValue) => { + let fiberRefs2 = oldValue; + let patches = of(self); + while (isNonEmptyReadonlyArray(patches)) { + const head3 = headNonEmpty(patches); + const tail = tailNonEmpty(patches); + switch (head3._tag) { + case OP_EMPTY2: { + patches = tail; + break; + } + case OP_ADD: { + fiberRefs2 = updateAs(fiberRefs2, { + fiberId: fiberId2, + fiberRef: head3.fiberRef, + value: head3.value + }); + patches = tail; + break; + } + case OP_REMOVE: { + fiberRefs2 = delete_(fiberRefs2, head3.fiberRef); + patches = tail; + break; + } + case OP_UPDATE: { + const value = getOrDefault(fiberRefs2, head3.fiberRef); + fiberRefs2 = updateAs(fiberRefs2, { + fiberId: fiberId2, + fiberRef: head3.fiberRef, + value: head3.fiberRef.patch(head3.patch)(value) + }); + patches = tail; + break; + } + case OP_AND_THEN: { + patches = prepend(head3.first)(prepend(head3.second)(tail)); + break; + } + } + } + return fiberRefs2; +}); + +// node_modules/effect/dist/esm/FiberRefsPatch.js +var diff6 = diff5; +var patch7 = patch6; + +// node_modules/effect/dist/esm/internal/fiberStatus.js +var FiberStatusSymbolKey = "effect/FiberStatus"; +var FiberStatusTypeId = /* @__PURE__ */ Symbol.for(FiberStatusSymbolKey); +var OP_DONE = "Done"; +var OP_RUNNING = "Running"; +var OP_SUSPENDED = "Suspended"; +var DoneHash = /* @__PURE__ */ string(`${FiberStatusSymbolKey}-${OP_DONE}`); + +class Done { + [FiberStatusTypeId] = FiberStatusTypeId; + _tag = OP_DONE; + [symbol]() { + return DoneHash; + } + [symbol2](that) { + return isFiberStatus(that) && that._tag === OP_DONE; + } +} + +class Running { + runtimeFlags; + [FiberStatusTypeId] = FiberStatusTypeId; + _tag = OP_RUNNING; + constructor(runtimeFlags2) { + this.runtimeFlags = runtimeFlags2; + } + [symbol]() { + return pipe(hash(FiberStatusSymbolKey), combine(hash(this._tag)), combine(hash(this.runtimeFlags)), cached(this)); + } + [symbol2](that) { + return isFiberStatus(that) && that._tag === OP_RUNNING && this.runtimeFlags === that.runtimeFlags; + } +} + +class Suspended { + runtimeFlags; + blockingOn; + [FiberStatusTypeId] = FiberStatusTypeId; + _tag = OP_SUSPENDED; + constructor(runtimeFlags2, blockingOn) { + this.runtimeFlags = runtimeFlags2; + this.blockingOn = blockingOn; + } + [symbol]() { + return pipe(hash(FiberStatusSymbolKey), combine(hash(this._tag)), combine(hash(this.runtimeFlags)), combine(hash(this.blockingOn)), cached(this)); + } + [symbol2](that) { + return isFiberStatus(that) && that._tag === OP_SUSPENDED && this.runtimeFlags === that.runtimeFlags && equals(this.blockingOn, that.blockingOn); + } +} +var done2 = /* @__PURE__ */ new Done; +var running = (runtimeFlags2) => new Running(runtimeFlags2); +var suspended = (runtimeFlags2, blockingOn) => new Suspended(runtimeFlags2, blockingOn); +var isFiberStatus = (u) => hasProperty(u, FiberStatusTypeId); +var isDone = (self) => self._tag === OP_DONE; + +// node_modules/effect/dist/esm/FiberStatus.js +var done3 = done2; +var running2 = running; +var suspended2 = suspended; +var isDone2 = isDone; + +// node_modules/effect/dist/esm/LogLevel.js +var All = logLevelAll; +var Fatal = logLevelFatal; +var Error3 = logLevelError; +var Warning = logLevelWarning; +var Info = logLevelInfo; +var Debug = logLevelDebug; +var Trace = logLevelTrace; +var None3 = logLevelNone; +var Order3 = /* @__PURE__ */ pipe(Order2, /* @__PURE__ */ mapInput2((level) => level.ordinal)); +var greaterThan3 = /* @__PURE__ */ greaterThan(Order3); +var fromLiteral = (literal) => { + switch (literal) { + case "All": + return All; + case "Debug": + return Debug; + case "Error": + return Error3; + case "Fatal": + return Fatal; + case "Info": + return Info; + case "Trace": + return Trace; + case "None": + return None3; + case "Warning": + return Warning; + } +}; + +// node_modules/effect/dist/esm/Micro.js +var TypeId9 = /* @__PURE__ */ Symbol.for("effect/Micro"); +var MicroExitTypeId = /* @__PURE__ */ Symbol.for("effect/Micro/MicroExit"); +var MicroCauseTypeId = /* @__PURE__ */ Symbol.for("effect/Micro/MicroCause"); +var microCauseVariance = { + _E: identity +}; + +class MicroCauseImpl extends globalThis.Error { + _tag; + traces; + [MicroCauseTypeId]; + constructor(_tag, originalError, traces) { + const causeName = `MicroCause.${_tag}`; + let name; + let message; + let stack; + if (originalError instanceof globalThis.Error) { + name = `(${causeName}) ${originalError.name}`; + message = originalError.message; + const messageLines = message.split(` +`).length; + stack = originalError.stack ? `(${causeName}) ${originalError.stack.split(` +`).slice(0, messageLines + 3).join(` +`)}` : `${name}: ${message}`; + } else { + name = causeName; + message = toStringUnknown(originalError, 0); + stack = `${name}: ${message}`; + } + if (traces.length > 0) { + stack += ` + ${traces.join(` + `)}`; + } + super(message); + this._tag = _tag; + this.traces = traces; + this[MicroCauseTypeId] = microCauseVariance; + this.name = name; + this.stack = stack; + } + pipe() { + return pipeArguments(this, arguments); + } + toString() { + return this.stack; + } + [NodeInspectSymbol]() { + return this.stack; + } +} +class Die extends MicroCauseImpl { + defect; + constructor(defect, traces = []) { + super("Die", defect, traces); + this.defect = defect; + } +} +var causeDie = (defect, traces = []) => new Die(defect, traces); + +class Interrupt extends MicroCauseImpl { + constructor(traces = []) { + super("Interrupt", "interrupted", traces); + } +} +var causeInterrupt = (traces = []) => new Interrupt(traces); +var causeIsInterrupt = (self) => self._tag === "Interrupt"; +var MicroFiberTypeId = /* @__PURE__ */ Symbol.for("effect/Micro/MicroFiber"); +var fiberVariance = { + _A: identity, + _E: identity +}; + +class MicroFiberImpl { + context; + interruptible; + [MicroFiberTypeId]; + _stack = []; + _observers = []; + _exit; + _children; + currentOpCount = 0; + constructor(context2, interruptible3 = true) { + this.context = context2; + this.interruptible = interruptible3; + this[MicroFiberTypeId] = fiberVariance; + } + getRef(ref) { + return unsafeGetReference(this.context, ref); + } + addObserver(cb) { + if (this._exit) { + cb(this._exit); + return constVoid; + } + this._observers.push(cb); + return () => { + const index = this._observers.indexOf(cb); + if (index >= 0) { + this._observers.splice(index, 1); + } + }; + } + _interrupted = false; + unsafeInterrupt() { + if (this._exit) { + return; + } + this._interrupted = true; + if (this.interruptible) { + this.evaluate(exitInterrupt2); + } + } + unsafePoll() { + return this._exit; + } + evaluate(effect) { + if (this._exit) { + return; + } else if (this._yielded !== undefined) { + const yielded = this._yielded; + this._yielded = undefined; + yielded(); + } + const exit2 = this.runLoop(effect); + if (exit2 === Yield) { + return; + } + const interruptChildren = fiberMiddleware.interruptChildren && fiberMiddleware.interruptChildren(this); + if (interruptChildren !== undefined) { + return this.evaluate(flatMap8(interruptChildren, () => exit2)); + } + this._exit = exit2; + for (let i = 0;i < this._observers.length; i++) { + this._observers[i](exit2); + } + this._observers.length = 0; + } + runLoop(effect) { + let yielding = false; + let current = effect; + this.currentOpCount = 0; + try { + while (true) { + this.currentOpCount++; + if (!yielding && this.getRef(CurrentScheduler).shouldYield(this)) { + yielding = true; + const prev = current; + current = flatMap8(yieldNow2, () => prev); + } + current = current[evaluate](this); + if (current === Yield) { + const yielded = this._yielded; + if (MicroExitTypeId in yielded) { + this._yielded = undefined; + return yielded; + } + return Yield; + } + } + } catch (error) { + if (!hasProperty(current, evaluate)) { + return exitDie2(`MicroFiber.runLoop: Not a valid effect: ${String(current)}`); + } + return exitDie2(error); + } + } + getCont(symbol3) { + while (true) { + const op = this._stack.pop(); + if (!op) + return; + const cont = op[ensureCont] && op[ensureCont](this); + if (cont) + return { + [symbol3]: cont + }; + if (op[symbol3]) + return op; + } + } + _yielded = undefined; + yieldWith(value) { + this._yielded = value; + return Yield; + } + children() { + return this._children ??= new Set; + } +} +var fiberMiddleware = /* @__PURE__ */ globalValue("effect/Micro/fiberMiddleware", () => ({ + interruptChildren: undefined +})); +var identifier = /* @__PURE__ */ Symbol.for("effect/Micro/identifier"); +var args = /* @__PURE__ */ Symbol.for("effect/Micro/args"); +var evaluate = /* @__PURE__ */ Symbol.for("effect/Micro/evaluate"); +var successCont = /* @__PURE__ */ Symbol.for("effect/Micro/successCont"); +var failureCont = /* @__PURE__ */ Symbol.for("effect/Micro/failureCont"); +var ensureCont = /* @__PURE__ */ Symbol.for("effect/Micro/ensureCont"); +var Yield = /* @__PURE__ */ Symbol.for("effect/Micro/Yield"); +var microVariance = { + _A: identity, + _E: identity, + _R: identity +}; +var MicroProto = { + ...EffectPrototype2, + _op: "Micro", + [TypeId9]: microVariance, + pipe() { + return pipeArguments(this, arguments); + }, + [Symbol.iterator]() { + return new SingleShotGen(new YieldWrap(this)); + }, + toJSON() { + return { + _id: "Micro", + op: this[identifier], + ...args in this ? { + args: this[args] + } : undefined + }; + }, + toString() { + return format(this); + }, + [NodeInspectSymbol]() { + return format(this); + } +}; +function defaultEvaluate(_fiber) { + return exitDie2(`Micro.evaluate: Not implemented`); +} +var makePrimitiveProto = (options) => ({ + ...MicroProto, + [identifier]: options.op, + [evaluate]: options.eval ?? defaultEvaluate, + [successCont]: options.contA, + [failureCont]: options.contE, + [ensureCont]: options.ensure +}); +var makePrimitive = (options) => { + const Proto = makePrimitiveProto(options); + return function() { + const self = Object.create(Proto); + self[args] = options.single === false ? arguments : arguments[0]; + return self; + }; +}; +var makeExit = (options) => { + const Proto = { + ...makePrimitiveProto(options), + [MicroExitTypeId]: MicroExitTypeId, + _tag: options.op, + get [options.prop]() { + return this[args]; + }, + toJSON() { + return { + _id: "MicroExit", + _tag: options.op, + [options.prop]: this[args] + }; + }, + [symbol2](that) { + return isMicroExit(that) && that._tag === options.op && equals(this[args], that[args]); + }, + [symbol]() { + return cached(this, combine(string(options.op))(hash(this[args]))); + } + }; + return function(value) { + const self = Object.create(Proto); + self[args] = value; + self[successCont] = undefined; + self[failureCont] = undefined; + self[ensureCont] = undefined; + return self; + }; +}; +var succeed2 = /* @__PURE__ */ makeExit({ + op: "Success", + prop: "value", + eval(fiber) { + const cont = fiber.getCont(successCont); + return cont ? cont[successCont](this[args], fiber) : fiber.yieldWith(this); + } +}); +var failCause2 = /* @__PURE__ */ makeExit({ + op: "Failure", + prop: "cause", + eval(fiber) { + let cont = fiber.getCont(failureCont); + while (causeIsInterrupt(this[args]) && cont && fiber.interruptible) { + cont = fiber.getCont(failureCont); + } + return cont ? cont[failureCont](this[args], fiber) : fiber.yieldWith(this); + } +}); +var yieldNowWith = /* @__PURE__ */ makePrimitive({ + op: "Yield", + eval(fiber) { + let resumed = false; + fiber.getRef(CurrentScheduler).scheduleTask(() => { + if (resumed) + return; + fiber.evaluate(exitVoid2); + }, this[args] ?? 0); + return fiber.yieldWith(() => { + resumed = true; + }); + } +}); +var yieldNow2 = /* @__PURE__ */ yieldNowWith(0); +var void_2 = /* @__PURE__ */ succeed2(undefined); +var withMicroFiber = /* @__PURE__ */ makePrimitive({ + op: "WithMicroFiber", + eval(fiber) { + return this[args](fiber); + } +}); +var flatMap8 = /* @__PURE__ */ dual(2, (self, f) => { + const onSuccess = Object.create(OnSuccessProto); + onSuccess[args] = self; + onSuccess[successCont] = f; + return onSuccess; +}); +var OnSuccessProto = /* @__PURE__ */ makePrimitiveProto({ + op: "OnSuccess", + eval(fiber) { + fiber._stack.push(this); + return this[args]; + } +}); +var isMicroExit = (u) => hasProperty(u, MicroExitTypeId); +var exitSucceed2 = succeed2; +var exitFailCause2 = failCause2; +var exitInterrupt2 = /* @__PURE__ */ exitFailCause2(/* @__PURE__ */ causeInterrupt()); +var exitDie2 = (defect) => exitFailCause2(causeDie(defect)); +var exitVoid2 = /* @__PURE__ */ exitSucceed2(undefined); +var setImmediate = "setImmediate" in globalThis ? globalThis.setImmediate : (f) => setTimeout(f, 0); + +class MicroSchedulerDefault { + tasks = []; + running = false; + scheduleTask(task, _priority) { + this.tasks.push(task); + if (!this.running) { + this.running = true; + setImmediate(this.afterScheduled); + } + } + afterScheduled = () => { + this.running = false; + this.runTasks(); + }; + runTasks() { + const tasks = this.tasks; + this.tasks = []; + for (let i = 0, len = tasks.length;i < len; i++) { + tasks[i](); + } + } + shouldYield(fiber) { + return fiber.currentOpCount >= fiber.getRef(MaxOpsBeforeYield); + } + flush() { + while (this.tasks.length > 0) { + this.runTasks(); + } + } +} +var updateContext = /* @__PURE__ */ dual(2, (self, f) => withMicroFiber((fiber) => { + const prev = fiber.context; + fiber.context = f(prev); + return onExit2(self, () => { + fiber.context = prev; + return void_2; + }); +})); +var provideContext2 = /* @__PURE__ */ dual(2, (self, provided) => updateContext(self, merge3(provided))); +class MaxOpsBeforeYield extends (/* @__PURE__ */ Reference2()("effect/Micro/currentMaxOpsBeforeYield", { + defaultValue: () => 2048 +})) { +} +class CurrentScheduler extends (/* @__PURE__ */ Reference2()("effect/Micro/currentScheduler", { + defaultValue: () => new MicroSchedulerDefault +})) { +} +var matchCauseEffect2 = /* @__PURE__ */ dual(2, (self, options) => { + const primitive = Object.create(OnSuccessAndFailureProto); + primitive[args] = self; + primitive[successCont] = options.onSuccess; + primitive[failureCont] = options.onFailure; + return primitive; +}); +var OnSuccessAndFailureProto = /* @__PURE__ */ makePrimitiveProto({ + op: "OnSuccessAndFailure", + eval(fiber) { + fiber._stack.push(this); + return this[args]; + } +}); +var onExit2 = /* @__PURE__ */ dual(2, (self, f) => uninterruptibleMask2((restore) => matchCauseEffect2(restore(self), { + onFailure: (cause) => flatMap8(f(exitFailCause2(cause)), () => failCause2(cause)), + onSuccess: (a) => flatMap8(f(exitSucceed2(a)), () => succeed2(a)) +}))); +var setInterruptible = /* @__PURE__ */ makePrimitive({ + op: "SetInterruptible", + ensure(fiber) { + fiber.interruptible = this[args]; + if (fiber._interrupted && fiber.interruptible) { + return () => exitInterrupt2; + } + } +}); +var interruptible3 = (self) => withMicroFiber((fiber) => { + if (fiber.interruptible) + return self; + fiber.interruptible = true; + fiber._stack.push(setInterruptible(false)); + if (fiber._interrupted) + return exitInterrupt2; + return self; +}); +var uninterruptibleMask2 = (f) => withMicroFiber((fiber) => { + if (!fiber.interruptible) + return f(identity); + fiber.interruptible = false; + fiber._stack.push(setInterruptible(true)); + return f(interruptible3); +}); +var runFork = (effect, options) => { + const fiber = new MicroFiberImpl(CurrentScheduler.context(options?.scheduler ?? new MicroSchedulerDefault)); + fiber.evaluate(effect); + if (options?.signal) { + if (options.signal.aborted) { + fiber.unsafeInterrupt(); + } else { + const abort = () => fiber.unsafeInterrupt(); + options.signal.addEventListener("abort", abort, { + once: true + }); + fiber.addObserver(() => options.signal.removeEventListener("abort", abort)); + } + } + return fiber; +}; + +// node_modules/effect/dist/esm/Readable.js +var TypeId10 = /* @__PURE__ */ Symbol.for("effect/Readable"); +var Proto = { + [TypeId10]: TypeId10, + pipe() { + return pipeArguments(this, arguments); + } +}; + +// node_modules/effect/dist/esm/internal/ref.js +var RefTypeId = /* @__PURE__ */ Symbol.for("effect/Ref"); +var refVariance = { + _A: (_) => _ +}; + +class RefImpl extends Class2 { + ref; + commit() { + return this.get; + } + [RefTypeId] = refVariance; + [TypeId10] = TypeId10; + constructor(ref) { + super(); + this.ref = ref; + this.get = sync(() => get6(this.ref)); + } + get; + modify(f) { + return sync(() => { + const current = get6(this.ref); + const [b, a] = f(current); + if (current !== a) { + set2(a)(this.ref); + } + return b; + }); + } +} +var unsafeMake4 = (value) => new RefImpl(make11(value)); +var make23 = (value) => sync(() => unsafeMake4(value)); +var get10 = (self) => self.get; +var set4 = /* @__PURE__ */ dual(2, (self, value) => self.modify(() => [undefined, value])); +var getAndSet = /* @__PURE__ */ dual(2, (self, value) => self.modify((a) => [a, value])); +var modify3 = /* @__PURE__ */ dual(2, (self, f) => self.modify(f)); +var update2 = /* @__PURE__ */ dual(2, (self, f) => self.modify((a) => [undefined, f(a)])); + +// node_modules/effect/dist/esm/Ref.js +var make24 = make23; +var get11 = get10; +var getAndSet2 = getAndSet; +var update3 = update2; + +// node_modules/effect/dist/esm/Scheduler.js +class SchedulerRunner { + scheduleDrain; + running = false; + tasks = /* @__PURE__ */ new PriorityBuckets; + constructor(scheduleDrain) { + this.scheduleDrain = scheduleDrain; + } + starveInternal = (depth) => { + const tasks = this.tasks.buckets; + this.tasks.buckets = []; + for (const [_, toRun] of tasks) { + for (let i = 0;i < toRun.length; i++) { + toRun[i](); + } + } + if (this.tasks.buckets.length === 0) { + this.running = false; + } else { + this.starve(depth); + } + }; + starve(depth = 0) { + this.scheduleDrain(depth, this.starveInternal); + } + scheduleTask(task, priority) { + this.tasks.scheduleTask(task, priority); + if (!this.running) { + this.running = true; + this.starve(); + } + } + static cached(scheduleDrain) { + const fallback = new SchedulerRunner(scheduleDrain); + const runners = new WeakMap; + return (fiber) => { + if (fiber === undefined) { + return fallback; + } + let runner = runners.get(fiber); + if (runner === undefined) { + runner = new SchedulerRunner(scheduleDrain); + runners.set(fiber, runner); + } + return runner; + }; + } +} + +class PriorityBuckets { + buckets = []; + scheduleTask(task, priority) { + const length = this.buckets.length; + let bucket = undefined; + let index = 0; + for (;index < length; index++) { + if (this.buckets[index][0] <= priority) { + bucket = this.buckets[index]; + } else { + break; + } + } + if (bucket && bucket[0] === priority) { + bucket[1].push(task); + } else if (index === length) { + this.buckets.push([priority, [task]]); + } else { + this.buckets.splice(index, 0, [priority, [task]]); + } + } +} + +class MixedScheduler { + maxNextTickBeforeTimer; + getRunner = /* @__PURE__ */ SchedulerRunner.cached((depth, drain) => { + if (depth >= this.maxNextTickBeforeTimer) { + setTimeout(() => drain(0), 0); + } else { + Promise.resolve(undefined).then(() => drain(depth + 1)); + } + }); + constructor(maxNextTickBeforeTimer) { + this.maxNextTickBeforeTimer = maxNextTickBeforeTimer; + } + shouldYield(fiber) { + return fiber.currentOpCount > fiber.getFiberRef(currentMaxOpsBeforeYield) ? fiber.getFiberRef(currentSchedulingPriority) : false; + } + scheduleTask(task, priority, fiber) { + this.getRunner(fiber).scheduleTask(task, priority); + } +} +var defaultScheduler = /* @__PURE__ */ globalValue(/* @__PURE__ */ Symbol.for("effect/Scheduler/defaultScheduler"), () => new MixedScheduler(2048)); + +class SyncScheduler { + tasks = /* @__PURE__ */ new PriorityBuckets; + deferred = false; + scheduleTask(task, priority, fiber) { + if (this.deferred) { + defaultScheduler.scheduleTask(task, priority, fiber); + } else { + this.tasks.scheduleTask(task, priority); + } + } + shouldYield(fiber) { + return fiber.currentOpCount > fiber.getFiberRef(currentMaxOpsBeforeYield) ? fiber.getFiberRef(currentSchedulingPriority) : false; + } + flush() { + while (this.tasks.buckets.length > 0) { + const tasks = this.tasks.buckets; + this.tasks.buckets = []; + for (const [_, toRun] of tasks) { + for (let i = 0;i < toRun.length; i++) { + toRun[i](); + } + } + } + this.deferred = true; + } +} +var currentScheduler = /* @__PURE__ */ globalValue(/* @__PURE__ */ Symbol.for("effect/FiberRef/currentScheduler"), () => fiberRefUnsafeMake(defaultScheduler)); +var withScheduler = /* @__PURE__ */ dual(2, (self, scheduler) => fiberRefLocally(self, currentScheduler, scheduler)); + +// node_modules/effect/dist/esm/internal/completedRequestMap.js +var currentRequestMap = /* @__PURE__ */ globalValue(/* @__PURE__ */ Symbol.for("effect/FiberRef/currentRequestMap"), () => fiberRefUnsafeMake(new Map)); + +// node_modules/effect/dist/esm/internal/concurrency.js +var match7 = (concurrency, sequential4, unbounded, bounded) => { + switch (concurrency) { + case undefined: + return sequential4(); + case "unbounded": + return unbounded(); + case "inherit": + return fiberRefGetWith(currentConcurrency, (concurrency2) => concurrency2 === "unbounded" ? unbounded() : concurrency2 > 1 ? bounded(concurrency2) : sequential4()); + default: + return concurrency > 1 ? bounded(concurrency) : sequential4(); + } +}; +var matchSimple = (concurrency, sequential4, concurrent) => { + switch (concurrency) { + case undefined: + return sequential4(); + case "unbounded": + return concurrent(); + case "inherit": + return fiberRefGetWith(currentConcurrency, (concurrency2) => concurrency2 === "unbounded" || concurrency2 > 1 ? concurrent() : sequential4()); + default: + return concurrency > 1 ? concurrent() : sequential4(); + } +}; + +// node_modules/effect/dist/esm/Clock.js +var sleep2 = sleep; +var currentTimeMillis2 = currentTimeMillis; +var currentTimeNanos2 = currentTimeNanos; +var clockWith2 = clockWith; +var Clock = clockTag; + +// node_modules/effect/dist/esm/internal/logSpan.js +var make25 = (label, startTime) => ({ + label, + startTime +}); +var formatLabel = (key) => key.replace(/[\s="]/g, "_"); +var render = (now) => (self) => { + const label = formatLabel(self.label); + return `${label}=${now - self.startTime}ms`; +}; + +// node_modules/effect/dist/esm/LogSpan.js +var make26 = make25; + +// node_modules/effect/dist/esm/Tracer.js +var tracerWith2 = tracerWith; + +// node_modules/effect/dist/esm/internal/metric/label.js +var MetricLabelSymbolKey = "effect/MetricLabel"; +var MetricLabelTypeId = /* @__PURE__ */ Symbol.for(MetricLabelSymbolKey); + +class MetricLabelImpl { + key; + value; + [MetricLabelTypeId] = MetricLabelTypeId; + _hash; + constructor(key, value) { + this.key = key; + this.value = value; + this._hash = string(MetricLabelSymbolKey + this.key + this.value); + } + [symbol]() { + return this._hash; + } + [symbol2](that) { + return isMetricLabel(that) && this.key === that.key && this.value === that.value; + } + pipe() { + return pipeArguments(this, arguments); + } +} +var make27 = (key, value) => { + return new MetricLabelImpl(key, value); +}; +var isMetricLabel = (u) => hasProperty(u, MetricLabelTypeId); + +// node_modules/effect/dist/esm/internal/core-effect.js +var annotateLogs = /* @__PURE__ */ dual((args2) => isEffect(args2[0]), function() { + const args2 = arguments; + return fiberRefLocallyWith(args2[0], currentLogAnnotations, typeof args2[1] === "string" ? set3(args2[1], args2[2]) : (annotations) => Object.entries(args2[1]).reduce((acc, [key, value]) => set3(acc, key, value), annotations)); +}); +var asSome = (self) => map9(self, some2); +var asSomeError = (self) => mapError(self, some2); +var try_2 = (arg) => { + let evaluate2; + let onFailure = undefined; + if (typeof arg === "function") { + evaluate2 = arg; + } else { + evaluate2 = arg.try; + onFailure = arg.catch; + } + return suspend(() => { + try { + return succeed(internalCall(evaluate2)); + } catch (error) { + return fail2(onFailure ? internalCall(() => onFailure(error)) : new UnknownException(error, "An unknown error occurred in Effect.try")); + } + }); +}; +var _catch = /* @__PURE__ */ dual(3, (self, tag, options) => catchAll(self, (e) => { + if (hasProperty(e, tag) && e[tag] === options.failure) { + return options.onFailure(e); + } + return fail2(e); +})); +var catchAllDefect = /* @__PURE__ */ dual(2, (self, f) => catchAllCause(self, (cause) => { + const option = find(cause, (_) => isDieType(_) ? some2(_) : none2()); + switch (option._tag) { + case "None": { + return failCause(cause); + } + case "Some": { + return f(option.value.defect); + } + } +})); +var catchSomeCause = /* @__PURE__ */ dual(2, (self, f) => matchCauseEffect(self, { + onFailure: (cause) => { + const option = f(cause); + switch (option._tag) { + case "None": { + return failCause(cause); + } + case "Some": { + return option.value; + } + } + }, + onSuccess: succeed +})); +var catchSomeDefect = /* @__PURE__ */ dual(2, (self, pf) => catchAllCause(self, (cause) => { + const option = find(cause, (_) => isDieType(_) ? some2(_) : none2()); + switch (option._tag) { + case "None": { + return failCause(cause); + } + case "Some": { + const optionEffect = pf(option.value.defect); + return optionEffect._tag === "Some" ? optionEffect.value : failCause(cause); + } + } +})); +var catchTag = /* @__PURE__ */ dual((args2) => isEffect(args2[0]), (self, ...args2) => { + const f = args2[args2.length - 1]; + let predicate; + if (args2.length === 2) { + predicate = isTagged(args2[0]); + } else { + predicate = (e) => { + const tag = hasProperty(e, "_tag") ? e["_tag"] : undefined; + if (!tag) + return false; + for (let i = 0;i < args2.length - 1; i++) { + if (args2[i] === tag) + return true; + } + return false; + }; + } + return catchIf(self, predicate, f); +}); +var catchTags = /* @__PURE__ */ dual(2, (self, cases) => { + let keys3; + return catchIf(self, (e) => { + keys3 ??= Object.keys(cases); + return hasProperty(e, "_tag") && isString(e["_tag"]) && keys3.includes(e["_tag"]); + }, (e) => cases[e["_tag"]](e)); +}); +var cause = (self) => matchCause(self, { + onFailure: identity, + onSuccess: () => empty16 +}); +var clockWith3 = clockWith2; +var clock = /* @__PURE__ */ clockWith3(succeed); +var delay = /* @__PURE__ */ dual(2, (self, duration) => zipRight(sleep2(duration), self)); +var descriptorWith = (f) => withFiberRuntime((state, status) => f({ + id: state.id(), + status, + interruptors: interruptors(state.getFiberRef(currentInterruptedCause)) +})); +var allowInterrupt = /* @__PURE__ */ descriptorWith((descriptor) => size3(descriptor.interruptors) > 0 ? interrupt2 : void_); +var descriptor = /* @__PURE__ */ descriptorWith(succeed); +var diffFiberRefs = (self) => summarized(self, fiberRefs2, diff5); +var diffFiberRefsAndRuntimeFlags = (self) => summarized(self, zip2(fiberRefs2, runtimeFlags), ([refs, flags], [refsNew, flagsNew]) => [diff5(refs, refsNew), diff4(flags, flagsNew)]); +var Do = /* @__PURE__ */ succeed({}); +var bind2 = /* @__PURE__ */ bind(map9, flatMap7); +var bindTo2 = /* @__PURE__ */ bindTo(map9); +var let_2 = /* @__PURE__ */ let_(map9); +var dropUntil = /* @__PURE__ */ dual(2, (elements, predicate) => suspend(() => { + const iterator = elements[Symbol.iterator](); + const builder = []; + let next; + let dropping = succeed(false); + let i = 0; + while ((next = iterator.next()) && !next.done) { + const a = next.value; + const index = i++; + dropping = flatMap7(dropping, (bool) => { + if (bool) { + builder.push(a); + return succeed(true); + } + return predicate(a, index); + }); + } + return map9(dropping, () => builder); +})); +var dropWhile = /* @__PURE__ */ dual(2, (elements, predicate) => suspend(() => { + const iterator = elements[Symbol.iterator](); + const builder = []; + let next; + let dropping = succeed(true); + let i = 0; + while ((next = iterator.next()) && !next.done) { + const a = next.value; + const index = i++; + dropping = flatMap7(dropping, (d) => map9(d ? predicate(a, index) : succeed(false), (b) => { + if (!b) { + builder.push(a); + } + return b; + })); + } + return map9(dropping, () => builder); +})); +var contextWith = (f) => map9(context(), f); +var eventually = (self) => orElse2(self, () => flatMap7(yieldNow(), () => eventually(self))); +var filterMap4 = /* @__PURE__ */ dual(2, (elements, pf) => map9(forEachSequential(elements, identity), filterMap2(pf))); +var filterOrDie = /* @__PURE__ */ dual(3, (self, predicate, orDieWith2) => filterOrElse(self, predicate, (a) => dieSync(() => orDieWith2(a)))); +var filterOrDieMessage = /* @__PURE__ */ dual(3, (self, predicate, message) => filterOrElse(self, predicate, () => dieMessage(message))); +var filterOrElse = /* @__PURE__ */ dual(3, (self, predicate, orElse3) => flatMap7(self, (a) => predicate(a) ? succeed(a) : orElse3(a))); +var liftPredicate = /* @__PURE__ */ dual(3, (self, predicate, orFailWith) => suspend(() => predicate(self) ? succeed(self) : fail2(orFailWith(self)))); +var filterOrFail = /* @__PURE__ */ dual((args2) => isEffect(args2[0]), (self, predicate, orFailWith) => filterOrElse(self, predicate, (a) => orFailWith === undefined ? fail2(new NoSuchElementException) : failSync(() => orFailWith(a)))); +var findFirst4 = /* @__PURE__ */ dual(2, (elements, predicate) => suspend(() => { + const iterator = elements[Symbol.iterator](); + const next = iterator.next(); + if (!next.done) { + return findLoop(iterator, 0, predicate, next.value); + } + return succeed(none2()); +})); +var findLoop = (iterator, index, f, value) => flatMap7(f(value, index), (result) => { + if (result) { + return succeed(some2(value)); + } + const next = iterator.next(); + if (!next.done) { + return findLoop(iterator, index + 1, f, next.value); + } + return succeed(none2()); +}); +var firstSuccessOf = (effects) => suspend(() => { + const list = fromIterable2(effects); + if (!isNonEmpty(list)) { + return dieSync(() => new IllegalArgumentException(`Received an empty collection of effects`)); + } + return pipe(tailNonEmpty2(list), reduce(headNonEmpty2(list), (left3, right3) => orElse2(left3, () => right3))); +}); +var flipWith = /* @__PURE__ */ dual(2, (self, f) => flip(f(flip(self)))); +var match8 = /* @__PURE__ */ dual(2, (self, options) => matchEffect(self, { + onFailure: (e) => succeed(options.onFailure(e)), + onSuccess: (a) => succeed(options.onSuccess(a)) +})); +var every4 = /* @__PURE__ */ dual(2, (elements, predicate) => suspend(() => forAllLoop(elements[Symbol.iterator](), 0, predicate))); +var forAllLoop = (iterator, index, f) => { + const next = iterator.next(); + return next.done ? succeed(true) : flatMap7(f(next.value, index), (b) => b ? forAllLoop(iterator, index + 1, f) : succeed(b)); +}; +var forever = (self) => { + const loop = flatMap7(flatMap7(self, () => yieldNow()), () => loop); + return loop; +}; +var fiberRefs2 = /* @__PURE__ */ withFiberRuntime((state) => succeed(state.getFiberRefs())); +var head3 = (self) => flatMap7(self, (as2) => { + const iterator = as2[Symbol.iterator](); + const next = iterator.next(); + if (next.done) { + return fail2(new NoSuchElementException); + } + return succeed(next.value); +}); +var ignore = (self) => match8(self, { + onFailure: constVoid, + onSuccess: constVoid +}); +var ignoreLogged = (self) => matchCauseEffect(self, { + onFailure: (cause2) => logDebug(cause2, "An error was silently ignored because it is not anticipated to be useful"), + onSuccess: () => void_ +}); +var inheritFiberRefs = (childFiberRefs) => updateFiberRefs((parentFiberId, parentFiberRefs) => joinAs2(parentFiberRefs, parentFiberId, childFiberRefs)); +var isFailure = (self) => match8(self, { + onFailure: constTrue, + onSuccess: constFalse +}); +var isSuccess = (self) => match8(self, { + onFailure: constFalse, + onSuccess: constTrue +}); +var iterate = (initial, options) => suspend(() => { + if (options.while(initial)) { + return flatMap7(options.body(initial), (z2) => iterate(z2, options)); + } + return succeed(initial); +}); +var logWithLevel = (level) => (...message) => { + const levelOption = fromNullable(level); + let cause2 = undefined; + for (let i = 0, len = message.length;i < len; i++) { + const msg = message[i]; + if (isCause(msg)) { + if (cause2 !== undefined) { + cause2 = sequential(cause2, msg); + } else { + cause2 = msg; + } + message = [...message.slice(0, i), ...message.slice(i + 1)]; + i--; + } + } + if (cause2 === undefined) { + cause2 = empty16; + } + return withFiberRuntime((fiberState) => { + fiberState.log(message, cause2, levelOption); + return void_; + }); +}; +var log = /* @__PURE__ */ logWithLevel(); +var logTrace = /* @__PURE__ */ logWithLevel(Trace); +var logDebug = /* @__PURE__ */ logWithLevel(Debug); +var logInfo = /* @__PURE__ */ logWithLevel(Info); +var logWarning = /* @__PURE__ */ logWithLevel(Warning); +var logError = /* @__PURE__ */ logWithLevel(Error3); +var logFatal = /* @__PURE__ */ logWithLevel(Fatal); +var withLogSpan = /* @__PURE__ */ dual(2, (effect, label) => flatMap7(currentTimeMillis2, (now) => fiberRefLocallyWith(effect, currentLogSpan, prepend3(make26(label, now))))); +var logAnnotations = /* @__PURE__ */ fiberRefGet(currentLogAnnotations); +var loop = (initial, options) => options.discard ? loopDiscard(initial, options.while, options.step, options.body) : map9(loopInternal(initial, options.while, options.step, options.body), fromIterable); +var loopInternal = (initial, cont, inc, body) => suspend(() => cont(initial) ? flatMap7(body(initial), (a) => map9(loopInternal(inc(initial), cont, inc, body), prepend3(a))) : sync(() => empty9())); +var loopDiscard = (initial, cont, inc, body) => suspend(() => cont(initial) ? flatMap7(body(initial), () => loopDiscard(inc(initial), cont, inc, body)) : void_); +var mapAccum2 = /* @__PURE__ */ dual(3, (elements, initial, f) => suspend(() => { + const iterator = elements[Symbol.iterator](); + const builder = []; + let result = succeed(initial); + let next; + let i = 0; + while (!(next = iterator.next()).done) { + const index = i++; + const value = next.value; + result = flatMap7(result, (state) => map9(f(state, value, index), ([z, b]) => { + builder.push(b); + return z; + })); + } + return map9(result, (z) => [z, builder]); +})); +var mapErrorCause = /* @__PURE__ */ dual(2, (self, f) => matchCauseEffect(self, { + onFailure: (c) => failCauseSync(() => f(c)), + onSuccess: succeed +})); +var memoize = (self) => pipe(deferredMake(), flatMap7((deferred) => pipe(diffFiberRefsAndRuntimeFlags(self), intoDeferred(deferred), once, map9((complete) => zipRight(complete, pipe(deferredAwait(deferred), flatMap7(([patch8, a]) => as(zip2(patchFiberRefs(patch8[0]), updateRuntimeFlags(patch8[1])), a)))))))); +var merge5 = (self) => matchEffect(self, { + onFailure: (e) => succeed(e), + onSuccess: succeed +}); +var negate = (self) => map9(self, (b) => !b); +var none6 = (self) => flatMap7(self, (option) => { + switch (option._tag) { + case "None": + return void_; + case "Some": + return fail2(new NoSuchElementException); + } +}); +var once = (self) => map9(make24(true), (ref) => asVoid(whenEffect(self, getAndSet2(ref, false)))); +var option = (self) => matchEffect(self, { + onFailure: () => succeed(none2()), + onSuccess: (a) => succeed(some2(a)) +}); +var orElseFail = /* @__PURE__ */ dual(2, (self, evaluate2) => orElse2(self, () => failSync(evaluate2))); +var orElseSucceed = /* @__PURE__ */ dual(2, (self, evaluate2) => orElse2(self, () => sync(evaluate2))); +var parallelErrors = (self) => matchCauseEffect(self, { + onFailure: (cause2) => { + const errors = fromIterable(failures(cause2)); + return errors.length === 0 ? failCause(cause2) : fail2(errors); + }, + onSuccess: succeed +}); +var patchFiberRefs = (patch8) => updateFiberRefs((fiberId2, fiberRefs3) => pipe(patch8, patch6(fiberId2, fiberRefs3))); +var promise = (evaluate2) => evaluate2.length >= 1 ? async_((resolve, signal) => { + try { + evaluate2(signal).then((a) => resolve(succeed(a)), (e) => resolve(die2(e))); + } catch (e) { + resolve(die2(e)); + } +}) : async_((resolve) => { + try { + evaluate2().then((a) => resolve(succeed(a)), (e) => resolve(die2(e))); + } catch (e) { + resolve(die2(e)); + } +}); +var provideService = /* @__PURE__ */ dual(3, (self, tag, service) => contextWithEffect((env) => provideContext(self, add2(env, tag, service)))); +var provideServiceEffect = /* @__PURE__ */ dual(3, (self, tag, effect) => contextWithEffect((env) => flatMap7(effect, (service) => provideContext(self, pipe(env, add2(tag, service)))))); +var random2 = /* @__PURE__ */ randomWith(succeed); +var reduce8 = /* @__PURE__ */ dual(3, (elements, zero2, f) => fromIterable(elements).reduce((acc, el, i) => flatMap7(acc, (a) => f(a, el, i)), succeed(zero2))); +var reduceRight2 = /* @__PURE__ */ dual(3, (elements, zero2, f) => fromIterable(elements).reduceRight((acc, el, i) => flatMap7(acc, (a) => f(el, a, i)), succeed(zero2))); +var reduceWhile = /* @__PURE__ */ dual(3, (elements, zero2, options) => flatMap7(sync(() => elements[Symbol.iterator]()), (iterator) => reduceWhileLoop(iterator, 0, zero2, options.while, options.body))); +var reduceWhileLoop = (iterator, index, state, predicate, f) => { + const next = iterator.next(); + if (!next.done && predicate(state)) { + return flatMap7(f(state, next.value, index), (nextState) => reduceWhileLoop(iterator, index + 1, nextState, predicate, f)); + } + return succeed(state); +}; +var repeatN = /* @__PURE__ */ dual(2, (self, n) => suspend(() => repeatNLoop(self, n))); +var repeatNLoop = (self, n) => flatMap7(self, (a) => n <= 0 ? succeed(a) : zipRight(yieldNow(), repeatNLoop(self, n - 1))); +var sandbox = (self) => matchCauseEffect(self, { + onFailure: fail2, + onSuccess: succeed +}); +var setFiberRefs = (fiberRefs3) => suspend(() => setAll2(fiberRefs3)); +var sleep3 = sleep2; +var succeedNone = /* @__PURE__ */ succeed(/* @__PURE__ */ none2()); +var succeedSome = (value) => succeed(some2(value)); +var summarized = /* @__PURE__ */ dual(3, (self, summary, f) => flatMap7(summary, (start) => flatMap7(self, (value) => map9(summary, (end) => [f(start, end), value])))); +var tagMetrics = /* @__PURE__ */ dual((args2) => isEffect(args2[0]), function() { + return labelMetrics(arguments[0], typeof arguments[1] === "string" ? [make27(arguments[1], arguments[2])] : Object.entries(arguments[1]).map(([k, v]) => make27(k, v))); +}); +var labelMetrics = /* @__PURE__ */ dual(2, (self, labels) => fiberRefLocallyWith(self, currentMetricLabels, (old) => union(old, labels))); +var takeUntil = /* @__PURE__ */ dual(2, (elements, predicate) => suspend(() => { + const iterator = elements[Symbol.iterator](); + const builder = []; + let next; + let effect = succeed(false); + let i = 0; + while ((next = iterator.next()) && !next.done) { + const a = next.value; + const index = i++; + effect = flatMap7(effect, (bool) => { + if (bool) { + return succeed(true); + } + builder.push(a); + return predicate(a, index); + }); + } + return map9(effect, () => builder); +})); +var takeWhile = /* @__PURE__ */ dual(2, (elements, predicate) => suspend(() => { + const iterator = elements[Symbol.iterator](); + const builder = []; + let next; + let taking = succeed(true); + let i = 0; + while ((next = iterator.next()) && !next.done) { + const a = next.value; + const index = i++; + taking = flatMap7(taking, (taking2) => pipe(taking2 ? predicate(a, index) : succeed(false), map9((bool) => { + if (bool) { + builder.push(a); + } + return bool; + }))); + } + return map9(taking, () => builder); +})); +var tapBoth = /* @__PURE__ */ dual(2, (self, { + onFailure, + onSuccess +}) => matchCauseEffect(self, { + onFailure: (cause2) => { + const either3 = failureOrCause(cause2); + switch (either3._tag) { + case "Left": { + return zipRight(onFailure(either3.left), failCause(cause2)); + } + case "Right": { + return failCause(cause2); + } + } + }, + onSuccess: (a) => as(onSuccess(a), a) +})); +var tapDefect = /* @__PURE__ */ dual(2, (self, f) => catchAllCause(self, (cause2) => match2(keepDefects(cause2), { + onNone: () => failCause(cause2), + onSome: (a) => zipRight(f(a), failCause(cause2)) +}))); +var tapError = /* @__PURE__ */ dual(2, (self, f) => matchCauseEffect(self, { + onFailure: (cause2) => { + const either3 = failureOrCause(cause2); + switch (either3._tag) { + case "Left": + return zipRight(f(either3.left), failCause(cause2)); + case "Right": + return failCause(cause2); + } + }, + onSuccess: succeed +})); +var tapErrorTag = /* @__PURE__ */ dual(3, (self, k, f) => tapError(self, (e) => { + if (isTagged(e, k)) { + return f(e); + } + return void_; +})); +var tapErrorCause = /* @__PURE__ */ dual(2, (self, f) => matchCauseEffect(self, { + onFailure: (cause2) => zipRight(f(cause2), failCause(cause2)), + onSuccess: succeed +})); +var timed = (self) => timedWith(self, currentTimeNanos2); +var timedWith = /* @__PURE__ */ dual(2, (self, nanos2) => summarized(self, nanos2, (start, end) => nanos(end - start))); +var tracerWith3 = tracerWith2; +var tracer = /* @__PURE__ */ tracerWith3(succeed); +var tryPromise = (arg) => { + let evaluate2; + let catcher = undefined; + if (typeof arg === "function") { + evaluate2 = arg; + } else { + evaluate2 = arg.try; + catcher = arg.catch; + } + const fail3 = (e) => catcher ? failSync(() => catcher(e)) : fail2(new UnknownException(e, "An unknown error occurred in Effect.tryPromise")); + if (evaluate2.length >= 1) { + return async_((resolve, signal) => { + try { + evaluate2(signal).then((a) => resolve(succeed(a)), (e) => resolve(fail3(e))); + } catch (e) { + resolve(fail3(e)); + } + }); + } + return async_((resolve) => { + try { + evaluate2().then((a) => resolve(succeed(a)), (e) => resolve(fail3(e))); + } catch (e) { + resolve(fail3(e)); + } + }); +}; +var tryMap = /* @__PURE__ */ dual(2, (self, options) => flatMap7(self, (a) => try_2({ + try: () => options.try(a), + catch: options.catch +}))); +var tryMapPromise = /* @__PURE__ */ dual(2, (self, options) => flatMap7(self, (a) => tryPromise({ + try: options.try.length >= 1 ? (signal) => options.try(a, signal) : () => options.try(a), + catch: options.catch +}))); +var unless = /* @__PURE__ */ dual(2, (self, condition) => suspend(() => condition() ? succeedNone : asSome(self))); +var unlessEffect = /* @__PURE__ */ dual(2, (self, condition) => flatMap7(condition, (b) => b ? succeedNone : asSome(self))); +var unsandbox = (self) => mapErrorCause(self, flatten3); +var updateFiberRefs = (f) => withFiberRuntime((state) => { + state.setFiberRefs(f(state.id(), state.getFiberRefs())); + return void_; +}); +var updateService = /* @__PURE__ */ dual(3, (self, tag, f) => mapInputContext(self, (context2) => add2(context2, tag, f(unsafeGet4(context2, tag))))); +var when = /* @__PURE__ */ dual(2, (self, condition) => suspend(() => condition() ? map9(self, some2) : succeed(none2()))); +var whenFiberRef = /* @__PURE__ */ dual(3, (self, fiberRef, predicate) => flatMap7(fiberRefGet(fiberRef), (s) => predicate(s) ? map9(self, (a) => [s, some2(a)]) : succeed([s, none2()]))); +var whenRef = /* @__PURE__ */ dual(3, (self, ref, predicate) => flatMap7(get11(ref), (s) => predicate(s) ? map9(self, (a) => [s, some2(a)]) : succeed([s, none2()]))); +var withMetric = /* @__PURE__ */ dual(2, (self, metric) => metric(self)); +var serviceFunctionEffect = (getService, f) => (...args2) => flatMap7(getService, (a) => f(a)(...args2)); +var serviceFunction = (getService, f) => (...args2) => map9(getService, (a) => f(a)(...args2)); +var serviceFunctions = (getService) => new Proxy({}, { + get(_target, prop, _receiver) { + return (...args2) => flatMap7(getService, (s) => s[prop](...args2)); + } +}); +var serviceConstants = (getService) => new Proxy({}, { + get(_target, prop, _receiver) { + return flatMap7(getService, (s) => isEffect(s[prop]) ? s[prop] : succeed(s[prop])); + } +}); +var serviceMembers = (getService) => ({ + functions: serviceFunctions(getService), + constants: serviceConstants(getService) +}); +var serviceOption = (tag) => map9(context(), getOption2(tag)); +var serviceOptional = (tag) => flatMap7(context(), getOption2(tag)); +var annotateCurrentSpan = function() { + const args2 = arguments; + return ignore(flatMap7(currentPropagatedSpan, (span2) => sync(() => { + if (typeof args2[0] === "string") { + span2.attribute(args2[0], args2[1]); + } else { + for (const key in args2[0]) { + span2.attribute(key, args2[0][key]); + } + } + }))); +}; +var linkSpanCurrent = function() { + const args2 = arguments; + const links = Array.isArray(args2[0]) ? args2[0] : [{ + _tag: "SpanLink", + span: args2[0], + attributes: args2[1] ?? {} + }]; + return ignore(flatMap7(currentSpan, (span2) => sync(() => span2.addLinks(links)))); +}; +var annotateSpans = /* @__PURE__ */ dual((args2) => isEffect(args2[0]), function() { + const args2 = arguments; + return fiberRefLocallyWith(args2[0], currentTracerSpanAnnotations, typeof args2[1] === "string" ? set3(args2[1], args2[2]) : (annotations) => Object.entries(args2[1]).reduce((acc, [key, value]) => set3(acc, key, value), annotations)); +}); +var currentParentSpan = /* @__PURE__ */ serviceOptional(spanTag); +var currentSpan = /* @__PURE__ */ flatMap7(/* @__PURE__ */ context(), (context2) => { + const span2 = context2.unsafeMap.get(spanTag.key); + return span2 !== undefined && span2._tag === "Span" ? succeed(span2) : fail2(new NoSuchElementException); +}); +var currentPropagatedSpan = /* @__PURE__ */ flatMap7(/* @__PURE__ */ context(), (context2) => { + const span2 = filterDisablePropagation(getOption2(context2, spanTag)); + return span2._tag === "Some" && span2.value._tag === "Span" ? succeed(span2.value) : fail2(new NoSuchElementException); +}); +var linkSpans = /* @__PURE__ */ dual((args2) => isEffect(args2[0]), (self, span2, attributes) => fiberRefLocallyWith(self, currentTracerSpanLinks, append2({ + _tag: "SpanLink", + span: span2, + attributes: attributes ?? {} +}))); +var bigint02 = /* @__PURE__ */ BigInt(0); +var filterDisablePropagation = /* @__PURE__ */ flatMap((span2) => get4(span2.context, DisablePropagation) ? span2._tag === "Span" ? filterDisablePropagation(span2.parent) : none2() : some2(span2)); +var unsafeMakeSpan = (fiber, name, options) => { + const disablePropagation = !fiber.getFiberRef(currentTracerEnabled) || options.context && get4(options.context, DisablePropagation); + const context2 = fiber.getFiberRef(currentContext); + const parent = options.parent ? some2(options.parent) : options.root ? none2() : filterDisablePropagation(getOption2(context2, spanTag)); + let span2; + if (disablePropagation) { + span2 = noopSpan({ + name, + parent, + context: add2(options.context ?? empty4(), DisablePropagation, true) + }); + } else { + const services = fiber.getFiberRef(currentServices); + const tracer2 = get4(services, tracerTag); + const clock2 = get4(services, Clock); + const timingEnabled = fiber.getFiberRef(currentTracerTimingEnabled); + const fiberRefs3 = fiber.getFiberRefs(); + const annotationsFromEnv = get9(fiberRefs3, currentTracerSpanAnnotations); + const linksFromEnv = get9(fiberRefs3, currentTracerSpanLinks); + const links = linksFromEnv._tag === "Some" ? options.links !== undefined ? [...toReadonlyArray(linksFromEnv.value), ...options.links ?? []] : toReadonlyArray(linksFromEnv.value) : options.links ?? empty(); + span2 = tracer2.span(name, parent, options.context ?? empty4(), links, timingEnabled ? clock2.unsafeCurrentTimeNanos() : bigint02, options.kind ?? "internal", options); + if (annotationsFromEnv._tag === "Some") { + forEach3(annotationsFromEnv.value, (value, key) => span2.attribute(key, value)); + } + if (options.attributes !== undefined) { + Object.entries(options.attributes).forEach(([k, v]) => span2.attribute(k, v)); + } + } + if (typeof options.captureStackTrace === "function") { + spanToTrace.set(span2, options.captureStackTrace); + } + return span2; +}; +var makeSpan = (name, options) => { + options = addSpanStackTrace(options); + return withFiberRuntime((fiber) => succeed(unsafeMakeSpan(fiber, name, options))); +}; +var spanAnnotations = /* @__PURE__ */ fiberRefGet(currentTracerSpanAnnotations); +var spanLinks = /* @__PURE__ */ fiberRefGet(currentTracerSpanLinks); +var endSpan = (span2, exit2, clock2, timingEnabled) => sync(() => { + if (span2.status._tag === "Ended") { + return; + } + if (exitIsFailure(exit2) && spanToTrace.has(span2)) { + span2.attribute("code.stacktrace", spanToTrace.get(span2)()); + } + span2.end(timingEnabled ? clock2.unsafeCurrentTimeNanos() : bigint02, exit2); +}); +var useSpan = (name, ...args2) => { + const options = addSpanStackTrace(args2.length === 1 ? undefined : args2[0]); + const evaluate2 = args2[args2.length - 1]; + return withFiberRuntime((fiber) => { + const span2 = unsafeMakeSpan(fiber, name, options); + const timingEnabled = fiber.getFiberRef(currentTracerTimingEnabled); + const clock2 = get4(fiber.getFiberRef(currentServices), clockTag); + return onExit(evaluate2(span2), (exit2) => endSpan(span2, exit2, clock2, timingEnabled)); + }); +}; +var withParentSpan = /* @__PURE__ */ dual(2, (self, span2) => provideService(self, spanTag, span2)); +var withSpan = function() { + const dataFirst = typeof arguments[0] !== "string"; + const name = dataFirst ? arguments[1] : arguments[0]; + const options = addSpanStackTrace(dataFirst ? arguments[2] : arguments[1]); + if (dataFirst) { + const self = arguments[0]; + return useSpan(name, options, (span2) => withParentSpan(self, span2)); + } + return (self) => useSpan(name, options, (span2) => withParentSpan(self, span2)); +}; +var functionWithSpan = (options) => function() { + let captureStackTrace = options.captureStackTrace ?? false; + if (options.captureStackTrace !== false) { + const limit = Error.stackTraceLimit; + Error.stackTraceLimit = 2; + const error = new Error; + Error.stackTraceLimit = limit; + let cache = false; + captureStackTrace = () => { + if (cache !== false) { + return cache; + } + if (error.stack) { + const stack = error.stack.trim().split(` +`); + cache = stack.slice(2).join(` +`).trim(); + return cache; + } + }; + } + return suspend(() => { + const opts = typeof options.options === "function" ? options.options.apply(null, arguments) : options.options; + return withSpan(suspend(() => internalCall(() => options.body.apply(this, arguments))), opts.name, { + ...opts, + captureStackTrace + }); + }); +}; +var fromNullable2 = (value) => value == null ? fail2(new NoSuchElementException) : succeed(value); +var optionFromOptional = (self) => catchAll(map9(self, some2), (error) => isNoSuchElementException(error) ? succeedNone : fail2(error)); + +// node_modules/effect/dist/esm/Exit.js +var isExit = exitIsExit; +var isSuccess2 = exitIsSuccess; +var failCause3 = exitFailCause; +var flatten5 = exitFlatten; +var match9 = exitMatch; +var succeed3 = exitSucceed; + +// node_modules/effect/dist/esm/internal/fiberMessage.js +var OP_INTERRUPT_SIGNAL = "InterruptSignal"; +var OP_STATEFUL = "Stateful"; +var OP_RESUME = "Resume"; +var OP_YIELD_NOW = "YieldNow"; +var interruptSignal = (cause2) => ({ + _tag: OP_INTERRUPT_SIGNAL, + cause: cause2 +}); +var stateful = (onFiber) => ({ + _tag: OP_STATEFUL, + onFiber +}); +var resume = (effect) => ({ + _tag: OP_RESUME, + effect +}); +var yieldNow3 = () => ({ + _tag: OP_YIELD_NOW +}); + +// node_modules/effect/dist/esm/internal/fiberScope.js +var FiberScopeSymbolKey = "effect/FiberScope"; +var FiberScopeTypeId = /* @__PURE__ */ Symbol.for(FiberScopeSymbolKey); + +class Global { + [FiberScopeTypeId] = FiberScopeTypeId; + fiberId = none4; + roots = /* @__PURE__ */ new Set; + add(_runtimeFlags, child) { + this.roots.add(child); + child.addObserver(() => { + this.roots.delete(child); + }); + } +} + +class Local { + fiberId; + parent; + [FiberScopeTypeId] = FiberScopeTypeId; + constructor(fiberId2, parent) { + this.fiberId = fiberId2; + this.parent = parent; + } + add(_runtimeFlags, child) { + this.parent.tell(stateful((parentFiber) => { + parentFiber.addChild(child); + child.addObserver(() => { + parentFiber.removeChild(child); + }); + })); + } +} +var unsafeMake5 = (fiber) => { + return new Local(fiber.id(), fiber); +}; +var globalScope = /* @__PURE__ */ globalValue(/* @__PURE__ */ Symbol.for("effect/FiberScope/Global"), () => new Global); + +// node_modules/effect/dist/esm/internal/fiber.js +var FiberSymbolKey = "effect/Fiber"; +var FiberTypeId = /* @__PURE__ */ Symbol.for(FiberSymbolKey); +var fiberVariance2 = { + _E: (_) => _, + _A: (_) => _ +}; +var fiberProto = { + [FiberTypeId]: fiberVariance2, + pipe() { + return pipeArguments(this, arguments); + } +}; +var RuntimeFiberSymbolKey = "effect/Fiber"; +var RuntimeFiberTypeId = /* @__PURE__ */ Symbol.for(RuntimeFiberSymbolKey); +var isRuntimeFiber = (self) => (RuntimeFiberTypeId in self); +var _await = (self) => self.await; +var inheritAll = (self) => self.inheritAll; +var interruptAllAs = /* @__PURE__ */ dual(2, /* @__PURE__ */ fnUntraced(function* (fibers, fiberId2) { + for (const fiber of fibers) { + if (isRuntimeFiber(fiber)) { + fiber.unsafeInterruptAsFork(fiberId2); + continue; + } + yield* fiber.interruptAsFork(fiberId2); + } + for (const fiber of fibers) { + if (isRuntimeFiber(fiber) && fiber.unsafePoll()) { + continue; + } + yield* fiber.await; + } +})); +var interruptAsFork = /* @__PURE__ */ dual(2, (self, fiberId2) => self.interruptAsFork(fiberId2)); +var join2 = (self) => zipLeft(flatten4(self.await), self.inheritAll); +var _never = { + ...CommitPrototype, + commit() { + return join2(this); + }, + ...fiberProto, + id: () => none4, + await: never, + children: /* @__PURE__ */ succeed([]), + inheritAll: never, + poll: /* @__PURE__ */ succeed(/* @__PURE__ */ none2()), + interruptAsFork: () => never +}; +var currentFiberURI = "effect/FiberCurrent"; + +// node_modules/effect/dist/esm/internal/logger.js +var LoggerSymbolKey = "effect/Logger"; +var LoggerTypeId = /* @__PURE__ */ Symbol.for(LoggerSymbolKey); +var loggerVariance = { + _Message: (_) => _, + _Output: (_) => _ +}; +var makeLogger = (log2) => ({ + [LoggerTypeId]: loggerVariance, + log: log2, + pipe() { + return pipeArguments(this, arguments); + } +}); +var none7 = { + [LoggerTypeId]: loggerVariance, + log: constVoid, + pipe() { + return pipeArguments(this, arguments); + } +}; +var textOnly = /^[^\s"=]*$/; +var format3 = (quoteValue, whitespace) => ({ + annotations, + cause: cause2, + date, + fiberId: fiberId2, + logLevel, + message, + spans +}) => { + const formatValue = (value) => value.match(textOnly) ? value : quoteValue(value); + const format4 = (label, value) => `${formatLabel(label)}=${formatValue(value)}`; + const append3 = (label, value) => " " + format4(label, value); + let out = format4("timestamp", date.toISOString()); + out += append3("level", logLevel.label); + out += append3("fiber", threadName(fiberId2)); + const messages = ensure(message); + for (let i = 0;i < messages.length; i++) { + out += append3("message", toStringUnknown(messages[i], whitespace)); + } + if (!isEmptyType(cause2)) { + out += append3("cause", pretty(cause2, { + renderErrorCause: true + })); + } + for (const span2 of spans) { + out += " " + render(date.getTime())(span2); + } + for (const [label, value] of annotations) { + out += append3(label, toStringUnknown(value, whitespace)); + } + return out; +}; +var escapeDoubleQuotes = (s) => `"${s.replace(/\\([\s\S])|(")/g, "\\$1$2")}"`; +var stringLogger = /* @__PURE__ */ makeLogger(/* @__PURE__ */ format3(escapeDoubleQuotes)); +var colors = { + bold: "1", + red: "31", + green: "32", + yellow: "33", + blue: "34", + cyan: "36", + white: "37", + gray: "90", + black: "30", + bgBrightRed: "101" +}; +var logLevelColors = { + None: [], + All: [], + Trace: [colors.gray], + Debug: [colors.blue], + Info: [colors.green], + Warning: [colors.yellow], + Error: [colors.red], + Fatal: [colors.bgBrightRed, colors.black] +}; +var hasProcessStdout = typeof process === "object" && process !== null && typeof process.stdout === "object" && process.stdout !== null; +var processStdoutIsTTY = hasProcessStdout && process.stdout.isTTY === true; +var hasProcessStdoutOrDeno = hasProcessStdout || "Deno" in globalThis; + +// node_modules/effect/dist/esm/internal/metric/boundaries.js +var MetricBoundariesSymbolKey = "effect/MetricBoundaries"; +var MetricBoundariesTypeId = /* @__PURE__ */ Symbol.for(MetricBoundariesSymbolKey); + +class MetricBoundariesImpl { + values; + [MetricBoundariesTypeId] = MetricBoundariesTypeId; + constructor(values3) { + this.values = values3; + this._hash = pipe(string(MetricBoundariesSymbolKey), combine(array2(this.values))); + } + _hash; + [symbol]() { + return this._hash; + } + [symbol2](u) { + return isMetricBoundaries(u) && equals(this.values, u.values); + } + pipe() { + return pipeArguments(this, arguments); + } +} +var isMetricBoundaries = (u) => hasProperty(u, MetricBoundariesTypeId); +var fromIterable8 = (iterable) => { + const values3 = pipe(iterable, appendAll(of2(Number.POSITIVE_INFINITY)), dedupe); + return new MetricBoundariesImpl(values3); +}; +var exponential = (options) => pipe(makeBy(options.count - 1, (i) => options.start * Math.pow(options.factor, i)), unsafeFromArray, fromIterable8); + +// node_modules/effect/dist/esm/internal/metric/keyType.js +var MetricKeyTypeSymbolKey = "effect/MetricKeyType"; +var MetricKeyTypeTypeId = /* @__PURE__ */ Symbol.for(MetricKeyTypeSymbolKey); +var CounterKeyTypeSymbolKey = "effect/MetricKeyType/Counter"; +var CounterKeyTypeTypeId = /* @__PURE__ */ Symbol.for(CounterKeyTypeSymbolKey); +var FrequencyKeyTypeSymbolKey = "effect/MetricKeyType/Frequency"; +var FrequencyKeyTypeTypeId = /* @__PURE__ */ Symbol.for(FrequencyKeyTypeSymbolKey); +var GaugeKeyTypeSymbolKey = "effect/MetricKeyType/Gauge"; +var GaugeKeyTypeTypeId = /* @__PURE__ */ Symbol.for(GaugeKeyTypeSymbolKey); +var HistogramKeyTypeSymbolKey = "effect/MetricKeyType/Histogram"; +var HistogramKeyTypeTypeId = /* @__PURE__ */ Symbol.for(HistogramKeyTypeSymbolKey); +var SummaryKeyTypeSymbolKey = "effect/MetricKeyType/Summary"; +var SummaryKeyTypeTypeId = /* @__PURE__ */ Symbol.for(SummaryKeyTypeSymbolKey); +var metricKeyTypeVariance = { + _In: (_) => _, + _Out: (_) => _ +}; + +class CounterKeyType { + incremental; + bigint; + [MetricKeyTypeTypeId] = metricKeyTypeVariance; + [CounterKeyTypeTypeId] = CounterKeyTypeTypeId; + constructor(incremental, bigint2) { + this.incremental = incremental; + this.bigint = bigint2; + this._hash = string(CounterKeyTypeSymbolKey); + } + _hash; + [symbol]() { + return this._hash; + } + [symbol2](that) { + return isCounterKey(that); + } + pipe() { + return pipeArguments(this, arguments); + } +} +class HistogramKeyType { + boundaries; + [MetricKeyTypeTypeId] = metricKeyTypeVariance; + [HistogramKeyTypeTypeId] = HistogramKeyTypeTypeId; + constructor(boundaries) { + this.boundaries = boundaries; + this._hash = pipe(string(HistogramKeyTypeSymbolKey), combine(hash(this.boundaries))); + } + _hash; + [symbol]() { + return this._hash; + } + [symbol2](that) { + return isHistogramKey(that) && equals(this.boundaries, that.boundaries); + } + pipe() { + return pipeArguments(this, arguments); + } +} +var counter = (options) => new CounterKeyType(options?.incremental ?? false, options?.bigint ?? false); +var histogram = (boundaries) => { + return new HistogramKeyType(boundaries); +}; +var isCounterKey = (u) => hasProperty(u, CounterKeyTypeTypeId); +var isFrequencyKey = (u) => hasProperty(u, FrequencyKeyTypeTypeId); +var isGaugeKey = (u) => hasProperty(u, GaugeKeyTypeTypeId); +var isHistogramKey = (u) => hasProperty(u, HistogramKeyTypeTypeId); +var isSummaryKey = (u) => hasProperty(u, SummaryKeyTypeTypeId); + +// node_modules/effect/dist/esm/internal/metric/key.js +var MetricKeySymbolKey = "effect/MetricKey"; +var MetricKeyTypeId = /* @__PURE__ */ Symbol.for(MetricKeySymbolKey); +var metricKeyVariance = { + _Type: (_) => _ +}; +var arrayEquivilence = /* @__PURE__ */ getEquivalence3(equals); + +class MetricKeyImpl { + name; + keyType; + description; + tags; + [MetricKeyTypeId] = metricKeyVariance; + constructor(name, keyType, description, tags = []) { + this.name = name; + this.keyType = keyType; + this.description = description; + this.tags = tags; + this._hash = pipe(string(this.name + this.description), combine(hash(this.keyType)), combine(array2(this.tags))); + } + _hash; + [symbol]() { + return this._hash; + } + [symbol2](u) { + return isMetricKey(u) && this.name === u.name && equals(this.keyType, u.keyType) && equals(this.description, u.description) && arrayEquivilence(this.tags, u.tags); + } + pipe() { + return pipeArguments(this, arguments); + } +} +var isMetricKey = (u) => hasProperty(u, MetricKeyTypeId); +var counter2 = (name, options) => new MetricKeyImpl(name, counter(options), fromNullable(options?.description)); +var histogram2 = (name, boundaries, description) => new MetricKeyImpl(name, histogram(boundaries), fromNullable(description)); +var taggedWithLabels = /* @__PURE__ */ dual(2, (self, extraTags) => extraTags.length === 0 ? self : new MetricKeyImpl(self.name, self.keyType, self.description, union(self.tags, extraTags))); + +// node_modules/effect/dist/esm/MutableHashMap.js +var TypeId11 = /* @__PURE__ */ Symbol.for("effect/MutableHashMap"); +var MutableHashMapProto = { + [TypeId11]: TypeId11, + [Symbol.iterator]() { + return new MutableHashMapIterator(this); + }, + toString() { + return format(this.toJSON()); + }, + toJSON() { + return { + _id: "MutableHashMap", + values: Array.from(this).map(toJSON) + }; + }, + [NodeInspectSymbol]() { + return this.toJSON(); + }, + pipe() { + return pipeArguments(this, arguments); + } +}; + +class MutableHashMapIterator { + self; + referentialIterator; + bucketIterator; + constructor(self) { + this.self = self; + this.referentialIterator = self.referential[Symbol.iterator](); + } + next() { + if (this.bucketIterator !== undefined) { + return this.bucketIterator.next(); + } + const result = this.referentialIterator.next(); + if (result.done) { + this.bucketIterator = new BucketIterator(this.self.buckets.values()); + return this.next(); + } + return result; + } + [Symbol.iterator]() { + return new MutableHashMapIterator(this.self); + } +} + +class BucketIterator { + backing; + constructor(backing) { + this.backing = backing; + } + currentBucket; + next() { + if (this.currentBucket === undefined) { + const result2 = this.backing.next(); + if (result2.done) { + return result2; + } + this.currentBucket = result2.value[Symbol.iterator](); + } + const result = this.currentBucket.next(); + if (result.done) { + this.currentBucket = undefined; + return this.next(); + } + return result; + } +} +var empty21 = () => { + const self = Object.create(MutableHashMapProto); + self.referential = new Map; + self.buckets = new Map; + self.bucketsSize = 0; + return self; +}; +var get12 = /* @__PURE__ */ dual(2, (self, key) => { + if (isEqual(key) === false) { + return self.referential.has(key) ? some2(self.referential.get(key)) : none2(); + } + const hash2 = key[symbol](); + const bucket = self.buckets.get(hash2); + if (bucket === undefined) { + return none2(); + } + return getFromBucket(self, bucket, key); +}); +var getFromBucket = (self, bucket, key, remove5 = false) => { + for (let i = 0, len = bucket.length;i < len; i++) { + if (key[symbol2](bucket[i][0])) { + const value = bucket[i][1]; + if (remove5) { + bucket.splice(i, 1); + self.bucketsSize--; + } + return some2(value); + } + } + return none2(); +}; +var has4 = /* @__PURE__ */ dual(2, (self, key) => isSome2(get12(self, key))); +var set5 = /* @__PURE__ */ dual(3, (self, key, value) => { + if (isEqual(key) === false) { + self.referential.set(key, value); + return self; + } + const hash2 = key[symbol](); + const bucket = self.buckets.get(hash2); + if (bucket === undefined) { + self.buckets.set(hash2, [[key, value]]); + self.bucketsSize++; + return self; + } + removeFromBucket(self, bucket, key); + bucket.push([key, value]); + self.bucketsSize++; + return self; +}); +var removeFromBucket = (self, bucket, key) => { + for (let i = 0, len = bucket.length;i < len; i++) { + if (key[symbol2](bucket[i][0])) { + bucket.splice(i, 1); + self.bucketsSize--; + return; + } + } +}; +var remove5 = /* @__PURE__ */ dual(2, (self, key) => { + if (isEqual(key) === false) { + self.referential.delete(key); + return self; + } + const hash2 = key[symbol](); + const bucket = self.buckets.get(hash2); + if (bucket === undefined) { + return self; + } + removeFromBucket(self, bucket, key); + if (bucket.length === 0) { + self.buckets.delete(hash2); + } + return self; +}); +var size4 = (self) => { + return self.referential.size + self.bucketsSize; +}; + +// node_modules/effect/dist/esm/internal/metric/state.js +var MetricStateSymbolKey = "effect/MetricState"; +var MetricStateTypeId = /* @__PURE__ */ Symbol.for(MetricStateSymbolKey); +var CounterStateSymbolKey = "effect/MetricState/Counter"; +var CounterStateTypeId = /* @__PURE__ */ Symbol.for(CounterStateSymbolKey); +var FrequencyStateSymbolKey = "effect/MetricState/Frequency"; +var FrequencyStateTypeId = /* @__PURE__ */ Symbol.for(FrequencyStateSymbolKey); +var GaugeStateSymbolKey = "effect/MetricState/Gauge"; +var GaugeStateTypeId = /* @__PURE__ */ Symbol.for(GaugeStateSymbolKey); +var HistogramStateSymbolKey = "effect/MetricState/Histogram"; +var HistogramStateTypeId = /* @__PURE__ */ Symbol.for(HistogramStateSymbolKey); +var SummaryStateSymbolKey = "effect/MetricState/Summary"; +var SummaryStateTypeId = /* @__PURE__ */ Symbol.for(SummaryStateSymbolKey); +var metricStateVariance = { + _A: (_) => _ +}; + +class CounterState { + count; + [MetricStateTypeId] = metricStateVariance; + [CounterStateTypeId] = CounterStateTypeId; + constructor(count) { + this.count = count; + } + [symbol]() { + return pipe(hash(CounterStateSymbolKey), combine(hash(this.count)), cached(this)); + } + [symbol2](that) { + return isCounterState(that) && this.count === that.count; + } + pipe() { + return pipeArguments(this, arguments); + } +} +var arrayEquals = /* @__PURE__ */ getEquivalence3(equals); + +class FrequencyState { + occurrences; + [MetricStateTypeId] = metricStateVariance; + [FrequencyStateTypeId] = FrequencyStateTypeId; + constructor(occurrences) { + this.occurrences = occurrences; + } + _hash; + [symbol]() { + return pipe(string(FrequencyStateSymbolKey), combine(array2(fromIterable(this.occurrences.entries()))), cached(this)); + } + [symbol2](that) { + return isFrequencyState(that) && arrayEquals(fromIterable(this.occurrences.entries()), fromIterable(that.occurrences.entries())); + } + pipe() { + return pipeArguments(this, arguments); + } +} + +class GaugeState { + value; + [MetricStateTypeId] = metricStateVariance; + [GaugeStateTypeId] = GaugeStateTypeId; + constructor(value) { + this.value = value; + } + [symbol]() { + return pipe(hash(GaugeStateSymbolKey), combine(hash(this.value)), cached(this)); + } + [symbol2](u) { + return isGaugeState(u) && this.value === u.value; + } + pipe() { + return pipeArguments(this, arguments); + } +} + +class HistogramState { + buckets; + count; + min; + max; + sum; + [MetricStateTypeId] = metricStateVariance; + [HistogramStateTypeId] = HistogramStateTypeId; + constructor(buckets, count, min2, max2, sum) { + this.buckets = buckets; + this.count = count; + this.min = min2; + this.max = max2; + this.sum = sum; + } + [symbol]() { + return pipe(hash(HistogramStateSymbolKey), combine(hash(this.buckets)), combine(hash(this.count)), combine(hash(this.min)), combine(hash(this.max)), combine(hash(this.sum)), cached(this)); + } + [symbol2](that) { + return isHistogramState(that) && equals(this.buckets, that.buckets) && this.count === that.count && this.min === that.min && this.max === that.max && this.sum === that.sum; + } + pipe() { + return pipeArguments(this, arguments); + } +} + +class SummaryState { + error; + quantiles; + count; + min; + max; + sum; + [MetricStateTypeId] = metricStateVariance; + [SummaryStateTypeId] = SummaryStateTypeId; + constructor(error, quantiles, count, min2, max2, sum) { + this.error = error; + this.quantiles = quantiles; + this.count = count; + this.min = min2; + this.max = max2; + this.sum = sum; + } + [symbol]() { + return pipe(hash(SummaryStateSymbolKey), combine(hash(this.error)), combine(hash(this.quantiles)), combine(hash(this.count)), combine(hash(this.min)), combine(hash(this.max)), combine(hash(this.sum)), cached(this)); + } + [symbol2](that) { + return isSummaryState(that) && this.error === that.error && equals(this.quantiles, that.quantiles) && this.count === that.count && this.min === that.min && this.max === that.max && this.sum === that.sum; + } + pipe() { + return pipeArguments(this, arguments); + } +} +var counter3 = (count) => new CounterState(count); +var frequency2 = (occurrences) => { + return new FrequencyState(occurrences); +}; +var gauge2 = (count) => new GaugeState(count); +var histogram3 = (options) => new HistogramState(options.buckets, options.count, options.min, options.max, options.sum); +var summary2 = (options) => new SummaryState(options.error, options.quantiles, options.count, options.min, options.max, options.sum); +var isCounterState = (u) => hasProperty(u, CounterStateTypeId); +var isFrequencyState = (u) => hasProperty(u, FrequencyStateTypeId); +var isGaugeState = (u) => hasProperty(u, GaugeStateTypeId); +var isHistogramState = (u) => hasProperty(u, HistogramStateTypeId); +var isSummaryState = (u) => hasProperty(u, SummaryStateTypeId); + +// node_modules/effect/dist/esm/internal/metric/hook.js +var MetricHookSymbolKey = "effect/MetricHook"; +var MetricHookTypeId = /* @__PURE__ */ Symbol.for(MetricHookSymbolKey); +var metricHookVariance = { + _In: (_) => _, + _Out: (_) => _ +}; +var make28 = (options) => ({ + [MetricHookTypeId]: metricHookVariance, + pipe() { + return pipeArguments(this, arguments); + }, + ...options +}); +var bigint03 = /* @__PURE__ */ BigInt(0); +var counter4 = (key) => { + let sum = key.keyType.bigint ? bigint03 : 0; + const canUpdate = key.keyType.incremental ? key.keyType.bigint ? (value) => value >= bigint03 : (value) => value >= 0 : (_value) => true; + const update4 = (value) => { + if (canUpdate(value)) { + sum = sum + value; + } + }; + return make28({ + get: () => counter3(sum), + update: update4, + modify: update4 + }); +}; +var frequency3 = (key) => { + const values3 = new Map; + for (const word of key.keyType.preregisteredWords) { + values3.set(word, 0); + } + const update4 = (word) => { + const slotCount = values3.get(word) ?? 0; + values3.set(word, slotCount + 1); + }; + return make28({ + get: () => frequency2(values3), + update: update4, + modify: update4 + }); +}; +var gauge3 = (_key, startAt) => { + let value = startAt; + return make28({ + get: () => gauge2(value), + update: (v) => { + value = v; + }, + modify: (v) => { + value = value + v; + } + }); +}; +var histogram4 = (key) => { + const bounds = key.keyType.boundaries.values; + const size5 = bounds.length; + const values3 = new Uint32Array(size5 + 1); + const boundaries = new Float64Array(size5); + let count = 0; + let sum = 0; + let min2 = Number.MAX_VALUE; + let max2 = Number.MIN_VALUE; + pipe(bounds, sort(Order2), map3((n, i) => { + boundaries[i] = n; + })); + const update4 = (value) => { + let from = 0; + let to = size5; + while (from !== to) { + const mid = Math.floor(from + (to - from) / 2); + const boundary = boundaries[mid]; + if (value <= boundary) { + to = mid; + } else { + from = mid; + } + if (to === from + 1) { + if (value <= boundaries[from]) { + to = from; + } else { + from = to; + } + } + } + values3[from] = values3[from] + 1; + count = count + 1; + sum = sum + value; + if (value < min2) { + min2 = value; + } + if (value > max2) { + max2 = value; + } + }; + const getBuckets = () => { + const builder = allocate(size5); + let cumulated = 0; + for (let i = 0;i < size5; i++) { + const boundary = boundaries[i]; + const value = values3[i]; + cumulated = cumulated + value; + builder[i] = [boundary, cumulated]; + } + return builder; + }; + return make28({ + get: () => histogram3({ + buckets: getBuckets(), + count, + min: min2, + max: max2, + sum + }), + update: update4, + modify: update4 + }); +}; +var summary3 = (key) => { + const { + error, + maxAge, + maxSize, + quantiles + } = key.keyType; + const sortedQuantiles = pipe(quantiles, sort(Order2)); + const values3 = allocate(maxSize); + let head4 = 0; + let count = 0; + let sum = 0; + let min2 = 0; + let max2 = 0; + const snapshot = (now) => { + const builder = []; + let i = 0; + while (i !== maxSize - 1) { + const item = values3[i]; + if (item != null) { + const [t, v] = item; + const age = millis(now - t); + if (greaterThanOrEqualTo2(age, zero) && lessThanOrEqualTo2(age, maxAge)) { + builder.push(v); + } + } + i = i + 1; + } + return calculateQuantiles(error, sortedQuantiles, sort(builder, Order2)); + }; + const observe = (value, timestamp) => { + if (maxSize > 0) { + head4 = head4 + 1; + const target = head4 % maxSize; + values3[target] = [timestamp, value]; + } + min2 = count === 0 ? value : Math.min(min2, value); + max2 = count === 0 ? value : Math.max(max2, value); + count = count + 1; + sum = sum + value; + }; + return make28({ + get: () => summary2({ + error, + quantiles: snapshot(Date.now()), + count, + min: min2, + max: max2, + sum + }), + update: ([value, timestamp]) => observe(value, timestamp), + modify: ([value, timestamp]) => observe(value, timestamp) + }); +}; +var calculateQuantiles = (error, sortedQuantiles, sortedSamples) => { + const sampleCount = sortedSamples.length; + if (!isNonEmptyReadonlyArray(sortedQuantiles)) { + return empty(); + } + const head4 = sortedQuantiles[0]; + const tail = sortedQuantiles.slice(1); + const resolvedHead = resolveQuantile(error, sampleCount, none2(), 0, head4, sortedSamples); + const resolved = of(resolvedHead); + tail.forEach((quantile) => { + resolved.push(resolveQuantile(error, sampleCount, resolvedHead.value, resolvedHead.consumed, quantile, resolvedHead.rest)); + }); + return map3(resolved, (rq) => [rq.quantile, rq.value]); +}; +var resolveQuantile = (error, sampleCount, current, consumed, quantile, rest) => { + let error_1 = error; + let sampleCount_1 = sampleCount; + let current_1 = current; + let consumed_1 = consumed; + let quantile_1 = quantile; + let rest_1 = rest; + let error_2 = error; + let sampleCount_2 = sampleCount; + let current_2 = current; + let consumed_2 = consumed; + let quantile_2 = quantile; + let rest_2 = rest; + while (true) { + if (!isNonEmptyReadonlyArray(rest_1)) { + return { + quantile: quantile_1, + value: none2(), + consumed: consumed_1, + rest: [] + }; + } + if (quantile_1 === 1) { + return { + quantile: quantile_1, + value: some2(lastNonEmpty(rest_1)), + consumed: consumed_1 + rest_1.length, + rest: [] + }; + } + const headValue = headNonEmpty(rest_1); + const sameHead = span(rest_1, (n) => n === headValue); + const desired = quantile_1 * sampleCount_1; + const allowedError = error_1 / 2 * desired; + const candConsumed = consumed_1 + sameHead[0].length; + const candError = Math.abs(candConsumed - desired); + if (candConsumed < desired - allowedError) { + error_2 = error_1; + sampleCount_2 = sampleCount_1; + current_2 = head(rest_1); + consumed_2 = candConsumed; + quantile_2 = quantile_1; + rest_2 = sameHead[1]; + error_1 = error_2; + sampleCount_1 = sampleCount_2; + current_1 = current_2; + consumed_1 = consumed_2; + quantile_1 = quantile_2; + rest_1 = rest_2; + continue; + } + if (candConsumed > desired + allowedError) { + const valueToReturn = isNone2(current_1) ? some2(headValue) : current_1; + return { + quantile: quantile_1, + value: valueToReturn, + consumed: consumed_1, + rest: rest_1 + }; + } + switch (current_1._tag) { + case "None": { + error_2 = error_1; + sampleCount_2 = sampleCount_1; + current_2 = head(rest_1); + consumed_2 = candConsumed; + quantile_2 = quantile_1; + rest_2 = sameHead[1]; + error_1 = error_2; + sampleCount_1 = sampleCount_2; + current_1 = current_2; + consumed_1 = consumed_2; + quantile_1 = quantile_2; + rest_1 = rest_2; + continue; + } + case "Some": { + const prevError = Math.abs(desired - current_1.value); + if (candError < prevError) { + error_2 = error_1; + sampleCount_2 = sampleCount_1; + current_2 = head(rest_1); + consumed_2 = candConsumed; + quantile_2 = quantile_1; + rest_2 = sameHead[1]; + error_1 = error_2; + sampleCount_1 = sampleCount_2; + current_1 = current_2; + consumed_1 = consumed_2; + quantile_1 = quantile_2; + rest_1 = rest_2; + continue; + } + return { + quantile: quantile_1, + value: some2(current_1.value), + consumed: consumed_1, + rest: rest_1 + }; + } + } + } + throw new Error("BUG: MetricHook.resolveQuantiles - please report an issue at https://github.com/Effect-TS/effect/issues"); +}; + +// node_modules/effect/dist/esm/internal/metric/pair.js +var MetricPairSymbolKey = "effect/MetricPair"; +var MetricPairTypeId = /* @__PURE__ */ Symbol.for(MetricPairSymbolKey); +var metricPairVariance = { + _Type: (_) => _ +}; +var unsafeMake6 = (metricKey, metricState) => { + return { + [MetricPairTypeId]: metricPairVariance, + metricKey, + metricState, + pipe() { + return pipeArguments(this, arguments); + } + }; +}; + +// node_modules/effect/dist/esm/internal/metric/registry.js +var MetricRegistrySymbolKey = "effect/MetricRegistry"; +var MetricRegistryTypeId = /* @__PURE__ */ Symbol.for(MetricRegistrySymbolKey); + +class MetricRegistryImpl { + [MetricRegistryTypeId] = MetricRegistryTypeId; + map = /* @__PURE__ */ empty21(); + snapshot() { + const result = []; + for (const [key, hook] of this.map) { + result.push(unsafeMake6(key, hook.get())); + } + return result; + } + get(key) { + const hook = pipe(this.map, get12(key), getOrUndefined); + if (hook == null) { + if (isCounterKey(key.keyType)) { + return this.getCounter(key); + } + if (isGaugeKey(key.keyType)) { + return this.getGauge(key); + } + if (isFrequencyKey(key.keyType)) { + return this.getFrequency(key); + } + if (isHistogramKey(key.keyType)) { + return this.getHistogram(key); + } + if (isSummaryKey(key.keyType)) { + return this.getSummary(key); + } + throw new Error("BUG: MetricRegistry.get - unknown MetricKeyType - please report an issue at https://github.com/Effect-TS/effect/issues"); + } else { + return hook; + } + } + getCounter(key) { + let value = pipe(this.map, get12(key), getOrUndefined); + if (value == null) { + const counter5 = counter4(key); + if (!pipe(this.map, has4(key))) { + pipe(this.map, set5(key, counter5)); + } + value = counter5; + } + return value; + } + getFrequency(key) { + let value = pipe(this.map, get12(key), getOrUndefined); + if (value == null) { + const frequency4 = frequency3(key); + if (!pipe(this.map, has4(key))) { + pipe(this.map, set5(key, frequency4)); + } + value = frequency4; + } + return value; + } + getGauge(key) { + let value = pipe(this.map, get12(key), getOrUndefined); + if (value == null) { + const gauge4 = gauge3(key, key.keyType.bigint ? BigInt(0) : 0); + if (!pipe(this.map, has4(key))) { + pipe(this.map, set5(key, gauge4)); + } + value = gauge4; + } + return value; + } + getHistogram(key) { + let value = pipe(this.map, get12(key), getOrUndefined); + if (value == null) { + const histogram5 = histogram4(key); + if (!pipe(this.map, has4(key))) { + pipe(this.map, set5(key, histogram5)); + } + value = histogram5; + } + return value; + } + getSummary(key) { + let value = pipe(this.map, get12(key), getOrUndefined); + if (value == null) { + const summary4 = summary3(key); + if (!pipe(this.map, has4(key))) { + pipe(this.map, set5(key, summary4)); + } + value = summary4; + } + return value; + } +} +var make29 = () => { + return new MetricRegistryImpl; +}; + +// node_modules/effect/dist/esm/internal/metric.js +var MetricSymbolKey = "effect/Metric"; +var MetricTypeId = /* @__PURE__ */ Symbol.for(MetricSymbolKey); +var metricVariance = { + _Type: (_) => _, + _In: (_) => _, + _Out: (_) => _ +}; +var globalMetricRegistry = /* @__PURE__ */ globalValue(/* @__PURE__ */ Symbol.for("effect/Metric/globalMetricRegistry"), () => make29()); +var make30 = function(keyType, unsafeUpdate, unsafeValue, unsafeModify) { + const metric = Object.assign((effect) => tap(effect, (a) => update4(metric, a)), { + [MetricTypeId]: metricVariance, + keyType, + unsafeUpdate, + unsafeValue, + unsafeModify, + register() { + this.unsafeValue([]); + return this; + }, + pipe() { + return pipeArguments(this, arguments); + } + }); + return metric; +}; +var counter5 = (name, options) => fromMetricKey(counter2(name, options)); +var fromMetricKey = (key) => { + let untaggedHook; + const hookCache = new WeakMap; + const hook = (extraTags) => { + if (extraTags.length === 0) { + if (untaggedHook !== undefined) { + return untaggedHook; + } + untaggedHook = globalMetricRegistry.get(key); + return untaggedHook; + } + let hook2 = hookCache.get(extraTags); + if (hook2 !== undefined) { + return hook2; + } + hook2 = globalMetricRegistry.get(taggedWithLabels(key, extraTags)); + hookCache.set(extraTags, hook2); + return hook2; + }; + return make30(key.keyType, (input, extraTags) => hook(extraTags).update(input), (extraTags) => hook(extraTags).get(), (input, extraTags) => hook(extraTags).modify(input)); +}; +var histogram5 = (name, boundaries, description) => fromMetricKey(histogram2(name, boundaries, description)); +var tagged2 = /* @__PURE__ */ dual(3, (self, key, value) => taggedWithLabels2(self, [make27(key, value)])); +var taggedWithLabels2 = /* @__PURE__ */ dual(2, (self, extraTags) => { + return make30(self.keyType, (input, extraTags1) => self.unsafeUpdate(input, union(extraTags, extraTags1)), (extraTags1) => self.unsafeValue(union(extraTags, extraTags1)), (input, extraTags1) => self.unsafeModify(input, union(extraTags, extraTags1))); +}); +var update4 = /* @__PURE__ */ dual(2, (self, input) => fiberRefGetWith(currentMetricLabels, (tags) => sync(() => self.unsafeUpdate(input, tags)))); + +// node_modules/effect/dist/esm/internal/request.js +var RequestSymbolKey = "effect/Request"; +var RequestTypeId = /* @__PURE__ */ Symbol.for(RequestSymbolKey); +var requestVariance = { + _E: (_) => _, + _A: (_) => _ +}; +var RequestPrototype = { + ...StructuralPrototype, + [RequestTypeId]: requestVariance +}; +var isRequest = (u) => hasProperty(u, RequestTypeId); +var Class3 = /* @__PURE__ */ function() { + function Class4(args2) { + if (args2) { + Object.assign(this, args2); + } + } + Class4.prototype = RequestPrototype; + return Class4; +}(); +var complete = /* @__PURE__ */ dual(2, (self, result) => fiberRefGetWith(currentRequestMap, (map10) => sync(() => { + if (map10.has(self)) { + const entry = map10.get(self); + if (!entry.state.completed) { + entry.state.completed = true; + deferredUnsafeDone(entry.result, result); + } + } +}))); +class Listeners { + count = 0; + observers = /* @__PURE__ */ new Set; + interrupted = false; + addObserver(f) { + this.observers.add(f); + } + removeObserver(f) { + this.observers.delete(f); + } + increment() { + this.count++; + this.observers.forEach((f) => f(this.count)); + } + decrement() { + this.count--; + this.observers.forEach((f) => f(this.count)); + } +} + +// node_modules/effect/dist/esm/internal/redBlackTree/iterator.js +var Direction = { + Forward: 0, + Backward: 1 << 0 +}; + +class RedBlackTreeIterator { + self; + stack; + direction; + count = 0; + constructor(self, stack, direction) { + this.self = self; + this.stack = stack; + this.direction = direction; + } + clone() { + return new RedBlackTreeIterator(this.self, this.stack.slice(), this.direction); + } + reversed() { + return new RedBlackTreeIterator(this.self, this.stack.slice(), this.direction === Direction.Forward ? Direction.Backward : Direction.Forward); + } + next() { + const entry = this.entry; + this.count++; + if (this.direction === Direction.Forward) { + this.moveNext(); + } else { + this.movePrev(); + } + switch (entry._tag) { + case "None": { + return { + done: true, + value: this.count + }; + } + case "Some": { + return { + done: false, + value: entry.value + }; + } + } + } + get key() { + if (this.stack.length > 0) { + return some2(this.stack[this.stack.length - 1].key); + } + return none2(); + } + get value() { + if (this.stack.length > 0) { + return some2(this.stack[this.stack.length - 1].value); + } + return none2(); + } + get entry() { + return map2(last(this.stack), (node) => [node.key, node.value]); + } + get index() { + let idx = 0; + const stack = this.stack; + if (stack.length === 0) { + const r = this.self._root; + if (r != null) { + return r.count; + } + return 0; + } else if (stack[stack.length - 1].left != null) { + idx = stack[stack.length - 1].left.count; + } + for (let s = stack.length - 2;s >= 0; --s) { + if (stack[s + 1] === stack[s].right) { + ++idx; + if (stack[s].left != null) { + idx += stack[s].left.count; + } + } + } + return idx; + } + moveNext() { + const stack = this.stack; + if (stack.length === 0) { + return; + } + let n = stack[stack.length - 1]; + if (n.right != null) { + n = n.right; + while (n != null) { + stack.push(n); + n = n.left; + } + } else { + stack.pop(); + while (stack.length > 0 && stack[stack.length - 1].right === n) { + n = stack[stack.length - 1]; + stack.pop(); + } + } + } + get hasNext() { + const stack = this.stack; + if (stack.length === 0) { + return false; + } + if (stack[stack.length - 1].right != null) { + return true; + } + for (let s = stack.length - 1;s > 0; --s) { + if (stack[s - 1].left === stack[s]) { + return true; + } + } + return false; + } + movePrev() { + const stack = this.stack; + if (stack.length === 0) { + return; + } + let n = stack[stack.length - 1]; + if (n != null && n.left != null) { + n = n.left; + while (n != null) { + stack.push(n); + n = n.right; + } + } else { + stack.pop(); + while (stack.length > 0 && stack[stack.length - 1].left === n) { + n = stack[stack.length - 1]; + stack.pop(); + } + } + } + get hasPrev() { + const stack = this.stack; + if (stack.length === 0) { + return false; + } + if (stack[stack.length - 1].left != null) { + return true; + } + for (let s = stack.length - 1;s > 0; --s) { + if (stack[s - 1].right === stack[s]) { + return true; + } + } + return false; + } +} + +// node_modules/effect/dist/esm/internal/redBlackTree/node.js +var Color = { + Red: 0, + Black: 1 << 0 +}; +var repaint = ({ + count, + key, + left: left3, + right: right3, + value +}, color) => ({ + color, + key, + value, + left: left3, + right: right3, + count +}); +var recount = (node) => { + node.count = 1 + (node.left?.count ?? 0) + (node.right?.count ?? 0); +}; + +// node_modules/effect/dist/esm/internal/redBlackTree.js +var RedBlackTreeSymbolKey = "effect/RedBlackTree"; +var RedBlackTreeTypeId = /* @__PURE__ */ Symbol.for(RedBlackTreeSymbolKey); +var redBlackTreeVariance = { + _Key: (_) => _, + _Value: (_) => _ +}; +var RedBlackTreeProto = { + [RedBlackTreeTypeId]: redBlackTreeVariance, + [symbol]() { + let hash2 = hash(RedBlackTreeSymbolKey); + for (const item of this) { + hash2 ^= pipe(hash(item[0]), combine(hash(item[1]))); + } + return cached(this, hash2); + }, + [symbol2](that) { + if (isRedBlackTree(that)) { + if ((this._root?.count ?? 0) !== (that._root?.count ?? 0)) { + return false; + } + const entries2 = Array.from(that); + return Array.from(this).every((itemSelf, i) => { + const itemThat = entries2[i]; + return equals(itemSelf[0], itemThat[0]) && equals(itemSelf[1], itemThat[1]); + }); + } + return false; + }, + [Symbol.iterator]() { + const stack = []; + let n = this._root; + while (n != null) { + stack.push(n); + n = n.left; + } + return new RedBlackTreeIterator(this, stack, Direction.Forward); + }, + toString() { + return format(this.toJSON()); + }, + toJSON() { + return { + _id: "RedBlackTree", + values: Array.from(this).map(toJSON) + }; + }, + [NodeInspectSymbol]() { + return this.toJSON(); + }, + pipe() { + return pipeArguments(this, arguments); + } +}; +var makeImpl3 = (ord, root) => { + const tree = Object.create(RedBlackTreeProto); + tree._ord = ord; + tree._root = root; + return tree; +}; +var isRedBlackTree = (u) => hasProperty(u, RedBlackTreeTypeId); +var empty22 = (ord) => makeImpl3(ord, undefined); +var fromIterable9 = /* @__PURE__ */ dual(2, (entries2, ord) => { + let tree = empty22(ord); + for (const [key, value] of entries2) { + tree = insert(tree, key, value); + } + return tree; +}); +var findFirst5 = /* @__PURE__ */ dual(2, (self, key) => { + const cmp = self._ord; + let node = self._root; + while (node !== undefined) { + const d = cmp(key, node.key); + if (equals(key, node.key)) { + return some2(node.value); + } + if (d <= 0) { + node = node.left; + } else { + node = node.right; + } + } + return none2(); +}); +var has5 = /* @__PURE__ */ dual(2, (self, key) => isSome2(findFirst5(self, key))); +var insert = /* @__PURE__ */ dual(3, (self, key, value) => { + const cmp = self._ord; + let n = self._root; + const n_stack = []; + const d_stack = []; + while (n != null) { + const d = cmp(key, n.key); + n_stack.push(n); + d_stack.push(d); + if (d <= 0) { + n = n.left; + } else { + n = n.right; + } + } + n_stack.push({ + color: Color.Red, + key, + value, + left: undefined, + right: undefined, + count: 1 + }); + for (let s = n_stack.length - 2;s >= 0; --s) { + const n2 = n_stack[s]; + if (d_stack[s] <= 0) { + n_stack[s] = { + color: n2.color, + key: n2.key, + value: n2.value, + left: n_stack[s + 1], + right: n2.right, + count: n2.count + 1 + }; + } else { + n_stack[s] = { + color: n2.color, + key: n2.key, + value: n2.value, + left: n2.left, + right: n_stack[s + 1], + count: n2.count + 1 + }; + } + } + for (let s = n_stack.length - 1;s > 1; --s) { + const p = n_stack[s - 1]; + const n3 = n_stack[s]; + if (p.color === Color.Black || n3.color === Color.Black) { + break; + } + const pp = n_stack[s - 2]; + if (pp.left === p) { + if (p.left === n3) { + const y = pp.right; + if (y && y.color === Color.Red) { + p.color = Color.Black; + pp.right = repaint(y, Color.Black); + pp.color = Color.Red; + s -= 1; + } else { + pp.color = Color.Red; + pp.left = p.right; + p.color = Color.Black; + p.right = pp; + n_stack[s - 2] = p; + n_stack[s - 1] = n3; + recount(pp); + recount(p); + if (s >= 3) { + const ppp = n_stack[s - 3]; + if (ppp.left === pp) { + ppp.left = p; + } else { + ppp.right = p; + } + } + break; + } + } else { + const y = pp.right; + if (y && y.color === Color.Red) { + p.color = Color.Black; + pp.right = repaint(y, Color.Black); + pp.color = Color.Red; + s -= 1; + } else { + p.right = n3.left; + pp.color = Color.Red; + pp.left = n3.right; + n3.color = Color.Black; + n3.left = p; + n3.right = pp; + n_stack[s - 2] = n3; + n_stack[s - 1] = p; + recount(pp); + recount(p); + recount(n3); + if (s >= 3) { + const ppp = n_stack[s - 3]; + if (ppp.left === pp) { + ppp.left = n3; + } else { + ppp.right = n3; + } + } + break; + } + } + } else { + if (p.right === n3) { + const y = pp.left; + if (y && y.color === Color.Red) { + p.color = Color.Black; + pp.left = repaint(y, Color.Black); + pp.color = Color.Red; + s -= 1; + } else { + pp.color = Color.Red; + pp.right = p.left; + p.color = Color.Black; + p.left = pp; + n_stack[s - 2] = p; + n_stack[s - 1] = n3; + recount(pp); + recount(p); + if (s >= 3) { + const ppp = n_stack[s - 3]; + if (ppp.right === pp) { + ppp.right = p; + } else { + ppp.left = p; + } + } + break; + } + } else { + const y = pp.left; + if (y && y.color === Color.Red) { + p.color = Color.Black; + pp.left = repaint(y, Color.Black); + pp.color = Color.Red; + s -= 1; + } else { + p.left = n3.right; + pp.color = Color.Red; + pp.right = n3.left; + n3.color = Color.Black; + n3.right = p; + n3.left = pp; + n_stack[s - 2] = n3; + n_stack[s - 1] = p; + recount(pp); + recount(p); + recount(n3); + if (s >= 3) { + const ppp = n_stack[s - 3]; + if (ppp.right === pp) { + ppp.right = n3; + } else { + ppp.left = n3; + } + } + break; + } + } + } + } + n_stack[0].color = Color.Black; + return makeImpl3(self._ord, n_stack[0]); +}); +var keysForward = (self) => keys3(self, Direction.Forward); +var keys3 = (self, direction) => { + const begin = self[Symbol.iterator](); + let count = 0; + return { + [Symbol.iterator]: () => keys3(self, direction), + next: () => { + count++; + const entry = begin.key; + if (direction === Direction.Forward) { + begin.moveNext(); + } else { + begin.movePrev(); + } + switch (entry._tag) { + case "None": { + return { + done: true, + value: count + }; + } + case "Some": { + return { + done: false, + value: entry.value + }; + } + } + } + }; +}; + +// node_modules/effect/dist/esm/RedBlackTree.js +var fromIterable10 = fromIterable9; +var has6 = has5; +var keys4 = keysForward; + +// node_modules/effect/dist/esm/SortedSet.js +var TypeId12 = /* @__PURE__ */ Symbol.for("effect/SortedSet"); +var SortedSetProto = { + [TypeId12]: { + _A: (_) => _ + }, + [symbol]() { + return pipe(hash(this.keyTree), combine(hash(TypeId12)), cached(this)); + }, + [symbol2](that) { + return isSortedSet(that) && equals(this.keyTree, that.keyTree); + }, + [Symbol.iterator]() { + return keys4(this.keyTree); + }, + toString() { + return format(this.toJSON()); + }, + toJSON() { + return { + _id: "SortedSet", + values: Array.from(this).map(toJSON) + }; + }, + [NodeInspectSymbol]() { + return this.toJSON(); + }, + pipe() { + return pipeArguments(this, arguments); + } +}; +var fromTree = (keyTree) => { + const a = Object.create(SortedSetProto); + a.keyTree = keyTree; + return a; +}; +var isSortedSet = (u) => hasProperty(u, TypeId12); +var fromIterable11 = /* @__PURE__ */ dual(2, (iterable, ord) => fromTree(fromIterable10(Array.from(iterable).map((k) => [k, true]), ord))); +var every5 = /* @__PURE__ */ dual(2, (self, predicate) => { + for (const value of self) { + if (!predicate(value)) { + return false; + } + } + return true; +}); +var has7 = /* @__PURE__ */ dual(2, (self, value) => has6(self.keyTree, value)); +var isSubset2 = /* @__PURE__ */ dual(2, (self, that) => every5(self, (a) => has7(that, a))); +var values3 = (self) => keys4(self.keyTree); +var getEquivalence6 = () => (a, b) => isSubset2(a, b) && isSubset2(b, a); + +// node_modules/effect/dist/esm/internal/supervisor.js +var SupervisorSymbolKey = "effect/Supervisor"; +var SupervisorTypeId = /* @__PURE__ */ Symbol.for(SupervisorSymbolKey); +var supervisorVariance = { + _T: (_) => _ +}; + +class ProxySupervisor { + underlying; + value0; + [SupervisorTypeId] = supervisorVariance; + constructor(underlying, value0) { + this.underlying = underlying; + this.value0 = value0; + } + get value() { + return this.value0; + } + onStart(context2, effect, parent, fiber) { + this.underlying.onStart(context2, effect, parent, fiber); + } + onEnd(value, fiber) { + this.underlying.onEnd(value, fiber); + } + onEffect(fiber, effect) { + this.underlying.onEffect(fiber, effect); + } + onSuspend(fiber) { + this.underlying.onSuspend(fiber); + } + onResume(fiber) { + this.underlying.onResume(fiber); + } + map(f) { + return new ProxySupervisor(this, pipe(this.value, map9(f))); + } + zip(right3) { + return new Zip(this, right3); + } +} + +class Zip { + left; + right; + _tag = "Zip"; + [SupervisorTypeId] = supervisorVariance; + constructor(left3, right3) { + this.left = left3; + this.right = right3; + } + get value() { + return zip2(this.left.value, this.right.value); + } + onStart(context2, effect, parent, fiber) { + this.left.onStart(context2, effect, parent, fiber); + this.right.onStart(context2, effect, parent, fiber); + } + onEnd(value, fiber) { + this.left.onEnd(value, fiber); + this.right.onEnd(value, fiber); + } + onEffect(fiber, effect) { + this.left.onEffect(fiber, effect); + this.right.onEffect(fiber, effect); + } + onSuspend(fiber) { + this.left.onSuspend(fiber); + this.right.onSuspend(fiber); + } + onResume(fiber) { + this.left.onResume(fiber); + this.right.onResume(fiber); + } + map(f) { + return new ProxySupervisor(this, pipe(this.value, map9(f))); + } + zip(right3) { + return new Zip(this, right3); + } +} +var isZip = (self) => hasProperty(self, SupervisorTypeId) && isTagged(self, "Zip"); + +class Track { + [SupervisorTypeId] = supervisorVariance; + fibers = /* @__PURE__ */ new Set; + get value() { + return sync(() => Array.from(this.fibers)); + } + onStart(_context, _effect, _parent, fiber) { + this.fibers.add(fiber); + } + onEnd(_value, fiber) { + this.fibers.delete(fiber); + } + onEffect(_fiber, _effect) {} + onSuspend(_fiber) {} + onResume(_fiber) {} + map(f) { + return new ProxySupervisor(this, pipe(this.value, map9(f))); + } + zip(right3) { + return new Zip(this, right3); + } + onRun(execution, _fiber) { + return execution(); + } +} + +class Const { + effect; + [SupervisorTypeId] = supervisorVariance; + constructor(effect) { + this.effect = effect; + } + get value() { + return this.effect; + } + onStart(_context, _effect, _parent, _fiber) {} + onEnd(_value, _fiber) {} + onEffect(_fiber, _effect) {} + onSuspend(_fiber) {} + onResume(_fiber) {} + map(f) { + return new ProxySupervisor(this, pipe(this.value, map9(f))); + } + zip(right3) { + return new Zip(this, right3); + } + onRun(execution, _fiber) { + return execution(); + } +} +var unsafeTrack = () => { + return new Track; +}; +var track = /* @__PURE__ */ sync(unsafeTrack); +var fromEffect = (effect) => { + return new Const(effect); +}; +var none8 = /* @__PURE__ */ globalValue("effect/Supervisor/none", () => fromEffect(void_)); + +// node_modules/effect/dist/esm/Differ.js +var make32 = make14; + +// node_modules/effect/dist/esm/internal/supervisor/patch.js +var OP_EMPTY3 = "Empty"; +var OP_ADD_SUPERVISOR = "AddSupervisor"; +var OP_REMOVE_SUPERVISOR = "RemoveSupervisor"; +var OP_AND_THEN2 = "AndThen"; +var empty24 = { + _tag: OP_EMPTY3 +}; +var combine8 = (self, that) => { + return { + _tag: OP_AND_THEN2, + first: self, + second: that + }; +}; +var patch8 = (self, supervisor) => { + return patchLoop(supervisor, of2(self)); +}; +var patchLoop = (_supervisor, _patches) => { + let supervisor = _supervisor; + let patches = _patches; + while (isNonEmpty(patches)) { + const head4 = headNonEmpty2(patches); + switch (head4._tag) { + case OP_EMPTY3: { + patches = tailNonEmpty2(patches); + break; + } + case OP_ADD_SUPERVISOR: { + supervisor = supervisor.zip(head4.supervisor); + patches = tailNonEmpty2(patches); + break; + } + case OP_REMOVE_SUPERVISOR: { + supervisor = removeSupervisor(supervisor, head4.supervisor); + patches = tailNonEmpty2(patches); + break; + } + case OP_AND_THEN2: { + patches = prepend2(head4.first)(prepend2(head4.second)(tailNonEmpty2(patches))); + break; + } + } + } + return supervisor; +}; +var removeSupervisor = (self, that) => { + if (equals(self, that)) { + return none8; + } else { + if (isZip(self)) { + return removeSupervisor(self.left, that).zip(removeSupervisor(self.right, that)); + } else { + return self; + } + } +}; +var toSet2 = (self) => { + if (equals(self, none8)) { + return empty7(); + } else { + if (isZip(self)) { + return pipe(toSet2(self.left), union3(toSet2(self.right))); + } else { + return make10(self); + } + } +}; +var diff7 = (oldValue, newValue) => { + if (equals(oldValue, newValue)) { + return empty24; + } + const oldSupervisors = toSet2(oldValue); + const newSupervisors = toSet2(newValue); + const added = pipe(newSupervisors, difference3(oldSupervisors), reduce4(empty24, (patch9, supervisor) => combine8(patch9, { + _tag: OP_ADD_SUPERVISOR, + supervisor + }))); + const removed = pipe(oldSupervisors, difference3(newSupervisors), reduce4(empty24, (patch9, supervisor) => combine8(patch9, { + _tag: OP_REMOVE_SUPERVISOR, + supervisor + }))); + return combine8(added, removed); +}; +var differ2 = /* @__PURE__ */ make32({ + empty: empty24, + patch: patch8, + combine: combine8, + diff: diff7 +}); + +// node_modules/effect/dist/esm/internal/fiberRuntime.js +var fiberStarted = /* @__PURE__ */ counter5("effect_fiber_started", { + incremental: true +}); +var fiberActive = /* @__PURE__ */ counter5("effect_fiber_active"); +var fiberSuccesses = /* @__PURE__ */ counter5("effect_fiber_successes", { + incremental: true +}); +var fiberFailures = /* @__PURE__ */ counter5("effect_fiber_failures", { + incremental: true +}); +var fiberLifetimes = /* @__PURE__ */ tagged2(/* @__PURE__ */ histogram5("effect_fiber_lifetimes", /* @__PURE__ */ exponential({ + start: 0.5, + factor: 2, + count: 35 +})), "time_unit", "milliseconds"); +var EvaluationSignalContinue = "Continue"; +var EvaluationSignalDone = "Done"; +var EvaluationSignalYieldNow = "Yield"; +var runtimeFiberVariance = { + _E: (_) => _, + _A: (_) => _ +}; +var absurd = (_) => { + throw new Error(`BUG: FiberRuntime - ${toStringUnknown(_)} - please report an issue at https://github.com/Effect-TS/effect/issues`); +}; +var YieldedOp = /* @__PURE__ */ Symbol.for("effect/internal/fiberRuntime/YieldedOp"); +var yieldedOpChannel = /* @__PURE__ */ globalValue("effect/internal/fiberRuntime/yieldedOpChannel", () => ({ + currentOp: null +})); +var contOpSuccess = { + [OP_ON_SUCCESS]: (_, cont, value) => { + return internalCall(() => cont.effect_instruction_i1(value)); + }, + ["OnStep"]: (_, _cont, value) => { + return exitSucceed(exitSucceed(value)); + }, + [OP_ON_SUCCESS_AND_FAILURE]: (_, cont, value) => { + return internalCall(() => cont.effect_instruction_i2(value)); + }, + [OP_REVERT_FLAGS]: (self, cont, value) => { + self.patchRuntimeFlags(self.currentRuntimeFlags, cont.patch); + if (interruptible(self.currentRuntimeFlags) && self.isInterrupted()) { + return exitFailCause(self.getInterruptedCause()); + } else { + return exitSucceed(value); + } + }, + [OP_WHILE]: (self, cont, value) => { + internalCall(() => cont.effect_instruction_i2(value)); + if (internalCall(() => cont.effect_instruction_i0())) { + self.pushStack(cont); + return internalCall(() => cont.effect_instruction_i1()); + } else { + return void_; + } + }, + [OP_ITERATOR]: (self, cont, value) => { + while (true) { + const state = internalCall(() => cont.effect_instruction_i0.next(value)); + if (state.done) { + return exitSucceed(state.value); + } + const primitive = yieldWrapGet(state.value); + if (!exitIsExit(primitive)) { + self.pushStack(cont); + return primitive; + } else if (primitive._tag === "Failure") { + return primitive; + } + value = primitive.value; + } + } +}; +var drainQueueWhileRunningTable = { + [OP_INTERRUPT_SIGNAL]: (self, runtimeFlags2, cur, message) => { + self.processNewInterruptSignal(message.cause); + return interruptible(runtimeFlags2) ? exitFailCause(message.cause) : cur; + }, + [OP_RESUME]: (_self, _runtimeFlags, _cur, _message) => { + throw new Error("It is illegal to have multiple concurrent run loops in a single fiber"); + }, + [OP_STATEFUL]: (self, runtimeFlags2, cur, message) => { + message.onFiber(self, running2(runtimeFlags2)); + return cur; + }, + [OP_YIELD_NOW]: (_self, _runtimeFlags, cur, _message) => { + return flatMap7(yieldNow(), () => cur); + } +}; +var runBlockedRequests = (self) => forEachSequentialDiscard(flatten2(self), (requestsByRequestResolver) => forEachConcurrentDiscard(sequentialCollectionToChunk(requestsByRequestResolver), ([dataSource, sequential4]) => { + const map10 = new Map; + const arr = []; + for (const block of sequential4) { + arr.push(toReadonlyArray(block)); + for (const entry of block) { + map10.set(entry.request, entry); + } + } + const flat = arr.flat(); + return fiberRefLocally(invokeWithInterrupt(dataSource.runAll(arr), flat, () => flat.forEach((entry) => { + entry.listeners.interrupted = true; + })), currentRequestMap, map10); +}, false, false)); +var _version = /* @__PURE__ */ getCurrentVersion(); + +class FiberRuntime extends Class2 { + [FiberTypeId] = fiberVariance2; + [RuntimeFiberTypeId] = runtimeFiberVariance; + _fiberRefs; + _fiberId; + _queue = /* @__PURE__ */ new Array; + _children = null; + _observers = /* @__PURE__ */ new Array; + _running = false; + _stack = []; + _asyncInterruptor = null; + _asyncBlockingOn = null; + _exitValue = null; + _steps = []; + _isYielding = false; + currentRuntimeFlags; + currentOpCount = 0; + currentSupervisor; + currentScheduler; + currentTracer; + currentSpan; + currentContext; + currentDefaultServices; + constructor(fiberId2, fiberRefs0, runtimeFlags0) { + super(); + this.currentRuntimeFlags = runtimeFlags0; + this._fiberId = fiberId2; + this._fiberRefs = fiberRefs0; + if (runtimeMetrics(runtimeFlags0)) { + const tags = this.getFiberRef(currentMetricLabels); + fiberStarted.unsafeUpdate(1, tags); + fiberActive.unsafeUpdate(1, tags); + } + this.refreshRefCache(); + } + commit() { + return join2(this); + } + id() { + return this._fiberId; + } + resume(effect) { + this.tell(resume(effect)); + } + get status() { + return this.ask((_, status) => status); + } + get runtimeFlags() { + return this.ask((state, status) => { + if (isDone2(status)) { + return state.currentRuntimeFlags; + } + return status.runtimeFlags; + }); + } + scope() { + return unsafeMake5(this); + } + get children() { + return this.ask((fiber) => Array.from(fiber.getChildren())); + } + getChildren() { + if (this._children === null) { + this._children = new Set; + } + return this._children; + } + getInterruptedCause() { + return this.getFiberRef(currentInterruptedCause); + } + fiberRefs() { + return this.ask((fiber) => fiber.getFiberRefs()); + } + ask(f) { + return suspend(() => { + const deferred = deferredUnsafeMake(this._fiberId); + this.tell(stateful((fiber, status) => { + deferredUnsafeDone(deferred, sync(() => f(fiber, status))); + })); + return deferredAwait(deferred); + }); + } + tell(message) { + this._queue.push(message); + if (!this._running) { + this._running = true; + this.drainQueueLaterOnExecutor(); + } + } + get await() { + return async_((resume2) => { + const cb = (exit2) => resume2(succeed(exit2)); + if (this._exitValue !== null) { + cb(this._exitValue); + return; + } + this.tell(stateful((fiber, _) => { + if (fiber._exitValue !== null) { + cb(this._exitValue); + } else { + fiber.addObserver(cb); + } + })); + return sync(() => this.tell(stateful((fiber, _) => { + fiber.removeObserver(cb); + }))); + }, this.id()); + } + get inheritAll() { + return withFiberRuntime((parentFiber, parentStatus) => { + const parentFiberId = parentFiber.id(); + const parentFiberRefs = parentFiber.getFiberRefs(); + const parentRuntimeFlags = parentStatus.runtimeFlags; + const childFiberRefs = this.getFiberRefs(); + const updatedFiberRefs = joinAs(parentFiberRefs, parentFiberId, childFiberRefs); + parentFiber.setFiberRefs(updatedFiberRefs); + const updatedRuntimeFlags = parentFiber.getFiberRef(currentRuntimeFlags); + const patch9 = pipe(diff4(parentRuntimeFlags, updatedRuntimeFlags), exclude2(Interruption), exclude2(WindDown)); + return updateRuntimeFlags(patch9); + }); + } + get poll() { + return sync(() => fromNullable(this._exitValue)); + } + unsafePoll() { + return this._exitValue; + } + interruptAsFork(fiberId2) { + return sync(() => this.tell(interruptSignal(interrupt(fiberId2)))); + } + unsafeInterruptAsFork(fiberId2) { + this.tell(interruptSignal(interrupt(fiberId2))); + } + addObserver(observer) { + if (this._exitValue !== null) { + observer(this._exitValue); + } else { + this._observers.push(observer); + } + } + removeObserver(observer) { + this._observers = this._observers.filter((o) => o !== observer); + } + getFiberRefs() { + this.setFiberRef(currentRuntimeFlags, this.currentRuntimeFlags); + return this._fiberRefs; + } + unsafeDeleteFiberRef(fiberRef) { + this._fiberRefs = delete_(this._fiberRefs, fiberRef); + } + getFiberRef(fiberRef) { + if (this._fiberRefs.locals.has(fiberRef)) { + return this._fiberRefs.locals.get(fiberRef)[0][1]; + } + return fiberRef.initial; + } + setFiberRef(fiberRef, value) { + this._fiberRefs = updateAs(this._fiberRefs, { + fiberId: this._fiberId, + fiberRef, + value + }); + this.refreshRefCache(); + } + refreshRefCache() { + this.currentDefaultServices = this.getFiberRef(currentServices); + this.currentTracer = this.currentDefaultServices.unsafeMap.get(tracerTag.key); + this.currentSupervisor = this.getFiberRef(currentSupervisor); + this.currentScheduler = this.getFiberRef(currentScheduler); + this.currentContext = this.getFiberRef(currentContext); + this.currentSpan = this.currentContext.unsafeMap.get(spanTag.key); + } + setFiberRefs(fiberRefs3) { + this._fiberRefs = fiberRefs3; + this.refreshRefCache(); + } + addChild(child) { + this.getChildren().add(child); + } + removeChild(child) { + this.getChildren().delete(child); + } + transferChildren(scope) { + const children = this._children; + this._children = null; + if (children !== null && children.size > 0) { + for (const child of children) { + if (child._exitValue === null) { + scope.add(this.currentRuntimeFlags, child); + } + } + } + } + drainQueueOnCurrentThread() { + let recurse = true; + while (recurse) { + let evaluationSignal = EvaluationSignalContinue; + const prev = globalThis[currentFiberURI]; + globalThis[currentFiberURI] = this; + try { + while (evaluationSignal === EvaluationSignalContinue) { + evaluationSignal = this._queue.length === 0 ? EvaluationSignalDone : this.evaluateMessageWhileSuspended(this._queue.splice(0, 1)[0]); + } + } finally { + this._running = false; + globalThis[currentFiberURI] = prev; + } + if (this._queue.length > 0 && !this._running) { + this._running = true; + if (evaluationSignal === EvaluationSignalYieldNow) { + this.drainQueueLaterOnExecutor(); + recurse = false; + } else { + recurse = true; + } + } else { + recurse = false; + } + } + } + drainQueueLaterOnExecutor() { + this.currentScheduler.scheduleTask(this.run, this.getFiberRef(currentSchedulingPriority), this); + } + drainQueueWhileRunning(runtimeFlags2, cur0) { + let cur = cur0; + while (this._queue.length > 0) { + const message = this._queue.splice(0, 1)[0]; + cur = drainQueueWhileRunningTable[message._tag](this, runtimeFlags2, cur, message); + } + return cur; + } + isInterrupted() { + return !isEmpty5(this.getFiberRef(currentInterruptedCause)); + } + addInterruptedCause(cause2) { + const oldSC = this.getFiberRef(currentInterruptedCause); + this.setFiberRef(currentInterruptedCause, sequential(oldSC, cause2)); + } + processNewInterruptSignal(cause2) { + this.addInterruptedCause(cause2); + this.sendInterruptSignalToAllChildren(); + } + sendInterruptSignalToAllChildren() { + if (this._children === null || this._children.size === 0) { + return false; + } + let told = false; + for (const child of this._children) { + child.tell(interruptSignal(interrupt(this.id()))); + told = true; + } + return told; + } + interruptAllChildren() { + if (this.sendInterruptSignalToAllChildren()) { + const it = this._children.values(); + this._children = null; + let isDone3 = false; + const body = () => { + const next = it.next(); + if (!next.done) { + return asVoid(next.value.await); + } else { + return sync(() => { + isDone3 = true; + }); + } + }; + return whileLoop({ + while: () => !isDone3, + body, + step: () => {} + }); + } + return null; + } + reportExitValue(exit2) { + if (runtimeMetrics(this.currentRuntimeFlags)) { + const tags = this.getFiberRef(currentMetricLabels); + const startTimeMillis = this.id().startTimeMillis; + const endTimeMillis = Date.now(); + fiberLifetimes.unsafeUpdate(endTimeMillis - startTimeMillis, tags); + fiberActive.unsafeUpdate(-1, tags); + switch (exit2._tag) { + case OP_SUCCESS: { + fiberSuccesses.unsafeUpdate(1, tags); + break; + } + case OP_FAILURE: { + fiberFailures.unsafeUpdate(1, tags); + break; + } + } + } + if (exit2._tag === "Failure") { + const level = this.getFiberRef(currentUnhandledErrorLogLevel); + if (!isInterruptedOnly(exit2.cause) && level._tag === "Some") { + this.log("Fiber terminated with an unhandled error", exit2.cause, level); + } + } + } + setExitValue(exit2) { + this._exitValue = exit2; + this.reportExitValue(exit2); + for (let i = this._observers.length - 1;i >= 0; i--) { + this._observers[i](exit2); + } + this._observers = []; + } + getLoggers() { + return this.getFiberRef(currentLoggers); + } + log(message, cause2, overrideLogLevel) { + const logLevel = isSome2(overrideLogLevel) ? overrideLogLevel.value : this.getFiberRef(currentLogLevel); + const minimumLogLevel = this.getFiberRef(currentMinimumLogLevel); + if (greaterThan3(minimumLogLevel, logLevel)) { + return; + } + const spans = this.getFiberRef(currentLogSpan); + const annotations = this.getFiberRef(currentLogAnnotations); + const loggers = this.getLoggers(); + const contextMap = this.getFiberRefs(); + if (size3(loggers) > 0) { + const clockService = get4(this.getFiberRef(currentServices), clockTag); + const date = new Date(clockService.unsafeCurrentTimeMillis()); + withRedactableContext(contextMap, () => { + for (const logger of loggers) { + logger.log({ + fiberId: this.id(), + logLevel, + message, + cause: cause2, + context: contextMap, + spans, + annotations, + date + }); + } + }); + } + } + evaluateMessageWhileSuspended(message) { + switch (message._tag) { + case OP_YIELD_NOW: { + return EvaluationSignalYieldNow; + } + case OP_INTERRUPT_SIGNAL: { + this.processNewInterruptSignal(message.cause); + if (this._asyncInterruptor !== null) { + this._asyncInterruptor(exitFailCause(message.cause)); + this._asyncInterruptor = null; + } + return EvaluationSignalContinue; + } + case OP_RESUME: { + this._asyncInterruptor = null; + this._asyncBlockingOn = null; + this.evaluateEffect(message.effect); + return EvaluationSignalContinue; + } + case OP_STATEFUL: { + message.onFiber(this, this._exitValue !== null ? done3 : suspended2(this.currentRuntimeFlags, this._asyncBlockingOn)); + return EvaluationSignalContinue; + } + default: { + return absurd(message); + } + } + } + evaluateEffect(effect0) { + this.currentSupervisor.onResume(this); + try { + let effect = interruptible(this.currentRuntimeFlags) && this.isInterrupted() ? exitFailCause(this.getInterruptedCause()) : effect0; + while (effect !== null) { + const eff = effect; + const exit2 = this.runLoop(eff); + if (exit2 === YieldedOp) { + const op = yieldedOpChannel.currentOp; + yieldedOpChannel.currentOp = null; + if (op._op === OP_YIELD) { + if (cooperativeYielding(this.currentRuntimeFlags)) { + this.tell(yieldNow3()); + this.tell(resume(exitVoid)); + effect = null; + } else { + effect = exitVoid; + } + } else if (op._op === OP_ASYNC) { + effect = null; + } + } else { + this.currentRuntimeFlags = pipe(this.currentRuntimeFlags, enable2(WindDown)); + const interruption2 = this.interruptAllChildren(); + if (interruption2 !== null) { + effect = flatMap7(interruption2, () => exit2); + } else { + if (this._queue.length === 0) { + this.setExitValue(exit2); + } else { + this.tell(resume(exit2)); + } + effect = null; + } + } + } + } finally { + this.currentSupervisor.onSuspend(this); + } + } + start(effect) { + if (!this._running) { + this._running = true; + const prev = globalThis[currentFiberURI]; + globalThis[currentFiberURI] = this; + try { + this.evaluateEffect(effect); + } finally { + this._running = false; + globalThis[currentFiberURI] = prev; + if (this._queue.length > 0) { + this.drainQueueLaterOnExecutor(); + } + } + } else { + this.tell(resume(effect)); + } + } + startFork(effect) { + this.tell(resume(effect)); + } + patchRuntimeFlags(oldRuntimeFlags, patch9) { + const newRuntimeFlags = patch4(oldRuntimeFlags, patch9); + globalThis[currentFiberURI] = this; + this.currentRuntimeFlags = newRuntimeFlags; + return newRuntimeFlags; + } + initiateAsync(runtimeFlags2, asyncRegister) { + let alreadyCalled = false; + const callback = (effect) => { + if (!alreadyCalled) { + alreadyCalled = true; + this.tell(resume(effect)); + } + }; + if (interruptible(runtimeFlags2)) { + this._asyncInterruptor = callback; + } + try { + asyncRegister(callback); + } catch (e) { + callback(failCause(die(e))); + } + } + pushStack(cont) { + this._stack.push(cont); + if (cont._op === "OnStep") { + this._steps.push({ + refs: this.getFiberRefs(), + flags: this.currentRuntimeFlags + }); + } + } + popStack() { + const item = this._stack.pop(); + if (item) { + if (item._op === "OnStep") { + this._steps.pop(); + } + return item; + } + return; + } + getNextSuccessCont() { + let frame = this.popStack(); + while (frame) { + if (frame._op !== OP_ON_FAILURE) { + return frame; + } + frame = this.popStack(); + } + } + getNextFailCont() { + let frame = this.popStack(); + while (frame) { + if (frame._op !== OP_ON_SUCCESS && frame._op !== OP_WHILE && frame._op !== OP_ITERATOR) { + return frame; + } + frame = this.popStack(); + } + } + [OP_TAG](op) { + return sync(() => unsafeGet4(this.currentContext, op)); + } + ["Left"](op) { + return fail2(op.left); + } + ["None"](_) { + return fail2(new NoSuchElementException); + } + ["Right"](op) { + return exitSucceed(op.right); + } + ["Some"](op) { + return exitSucceed(op.value); + } + ["Micro"](op) { + return unsafeAsync((microResume) => { + let resume2 = microResume; + const fiber = runFork(provideContext2(op, this.currentContext)); + fiber.addObserver((exit2) => { + if (exit2._tag === "Success") { + return resume2(exitSucceed(exit2.value)); + } + switch (exit2.cause._tag) { + case "Interrupt": { + return resume2(exitFailCause(interrupt(none4))); + } + case "Fail": { + return resume2(fail2(exit2.cause.error)); + } + case "Die": { + return resume2(die2(exit2.cause.defect)); + } + } + }); + return unsafeAsync((abortResume) => { + resume2 = (_) => { + abortResume(void_); + }; + fiber.unsafeInterrupt(); + }); + }); + } + [OP_SYNC](op) { + const value = internalCall(() => op.effect_instruction_i0()); + const cont = this.getNextSuccessCont(); + if (cont !== undefined) { + if (!(cont._op in contOpSuccess)) { + absurd(cont); + } + return contOpSuccess[cont._op](this, cont, value); + } else { + yieldedOpChannel.currentOp = exitSucceed(value); + return YieldedOp; + } + } + [OP_SUCCESS](op) { + const oldCur = op; + const cont = this.getNextSuccessCont(); + if (cont !== undefined) { + if (!(cont._op in contOpSuccess)) { + absurd(cont); + } + return contOpSuccess[cont._op](this, cont, oldCur.effect_instruction_i0); + } else { + yieldedOpChannel.currentOp = oldCur; + return YieldedOp; + } + } + [OP_FAILURE](op) { + const cause2 = op.effect_instruction_i0; + const cont = this.getNextFailCont(); + if (cont !== undefined) { + switch (cont._op) { + case OP_ON_FAILURE: + case OP_ON_SUCCESS_AND_FAILURE: { + if (!(interruptible(this.currentRuntimeFlags) && this.isInterrupted())) { + return internalCall(() => cont.effect_instruction_i1(cause2)); + } else { + return exitFailCause(stripFailures(cause2)); + } + } + case "OnStep": { + if (!(interruptible(this.currentRuntimeFlags) && this.isInterrupted())) { + return exitSucceed(exitFailCause(cause2)); + } else { + return exitFailCause(stripFailures(cause2)); + } + } + case OP_REVERT_FLAGS: { + this.patchRuntimeFlags(this.currentRuntimeFlags, cont.patch); + if (interruptible(this.currentRuntimeFlags) && this.isInterrupted()) { + return exitFailCause(sequential(cause2, this.getInterruptedCause())); + } else { + return exitFailCause(cause2); + } + } + default: { + absurd(cont); + } + } + } else { + yieldedOpChannel.currentOp = exitFailCause(cause2); + return YieldedOp; + } + } + [OP_WITH_RUNTIME](op) { + return internalCall(() => op.effect_instruction_i0(this, running2(this.currentRuntimeFlags))); + } + ["Blocked"](op) { + const refs = this.getFiberRefs(); + const flags = this.currentRuntimeFlags; + if (this._steps.length > 0) { + const frames = []; + const snap = this._steps[this._steps.length - 1]; + let frame = this.popStack(); + while (frame && frame._op !== "OnStep") { + frames.push(frame); + frame = this.popStack(); + } + this.setFiberRefs(snap.refs); + this.currentRuntimeFlags = snap.flags; + const patchRefs = diff6(snap.refs, refs); + const patchFlags = diff4(snap.flags, flags); + return exitSucceed(blocked(op.effect_instruction_i0, withFiberRuntime((newFiber) => { + while (frames.length > 0) { + newFiber.pushStack(frames.pop()); + } + newFiber.setFiberRefs(patch7(newFiber.id(), newFiber.getFiberRefs())(patchRefs)); + newFiber.currentRuntimeFlags = patch4(patchFlags)(newFiber.currentRuntimeFlags); + return op.effect_instruction_i1; + }))); + } + return uninterruptibleMask((restore) => flatMap7(forkDaemon(runRequestBlock(op.effect_instruction_i0)), () => restore(op.effect_instruction_i1))); + } + ["RunBlocked"](op) { + return runBlockedRequests(op.effect_instruction_i0); + } + [OP_UPDATE_RUNTIME_FLAGS](op) { + const updateFlags = op.effect_instruction_i0; + const oldRuntimeFlags = this.currentRuntimeFlags; + const newRuntimeFlags = patch4(oldRuntimeFlags, updateFlags); + if (interruptible(newRuntimeFlags) && this.isInterrupted()) { + return exitFailCause(this.getInterruptedCause()); + } else { + this.patchRuntimeFlags(this.currentRuntimeFlags, updateFlags); + if (op.effect_instruction_i1) { + const revertFlags = diff4(newRuntimeFlags, oldRuntimeFlags); + this.pushStack(new RevertFlags(revertFlags, op)); + return internalCall(() => op.effect_instruction_i1(oldRuntimeFlags)); + } else { + return exitVoid; + } + } + } + [OP_ON_SUCCESS](op) { + this.pushStack(op); + return op.effect_instruction_i0; + } + ["OnStep"](op) { + this.pushStack(op); + return op.effect_instruction_i0; + } + [OP_ON_FAILURE](op) { + this.pushStack(op); + return op.effect_instruction_i0; + } + [OP_ON_SUCCESS_AND_FAILURE](op) { + this.pushStack(op); + return op.effect_instruction_i0; + } + [OP_ASYNC](op) { + this._asyncBlockingOn = op.effect_instruction_i1; + this.initiateAsync(this.currentRuntimeFlags, op.effect_instruction_i0); + yieldedOpChannel.currentOp = op; + return YieldedOp; + } + [OP_YIELD](op) { + this._isYielding = false; + yieldedOpChannel.currentOp = op; + return YieldedOp; + } + [OP_WHILE](op) { + const check = op.effect_instruction_i0; + const body = op.effect_instruction_i1; + if (check()) { + this.pushStack(op); + return body(); + } else { + return exitVoid; + } + } + [OP_ITERATOR](op) { + return contOpSuccess[OP_ITERATOR](this, op, undefined); + } + [OP_COMMIT](op) { + return internalCall(() => op.commit()); + } + runLoop(effect0) { + let cur = effect0; + this.currentOpCount = 0; + while (true) { + if ((this.currentRuntimeFlags & OpSupervision) !== 0) { + this.currentSupervisor.onEffect(this, cur); + } + if (this._queue.length > 0) { + cur = this.drainQueueWhileRunning(this.currentRuntimeFlags, cur); + } + if (!this._isYielding) { + this.currentOpCount += 1; + const shouldYield = this.currentScheduler.shouldYield(this); + if (shouldYield !== false) { + this._isYielding = true; + this.currentOpCount = 0; + const oldCur = cur; + cur = flatMap7(yieldNow({ + priority: shouldYield + }), () => oldCur); + } + } + try { + cur = this.currentTracer.context(() => { + if (_version !== cur[EffectTypeId2]._V) { + const level = this.getFiberRef(currentVersionMismatchErrorLogLevel); + if (level._tag === "Some") { + const effectVersion = cur[EffectTypeId2]._V; + this.log(`Executing an Effect versioned ${effectVersion} with a Runtime of version ${getCurrentVersion()}, you may want to dedupe the effect dependencies, you can use the language service plugin to detect this at compile time: https://github.com/Effect-TS/language-service`, empty16, level); + } + } + return this[cur._op](cur); + }, this); + if (cur === YieldedOp) { + const op = yieldedOpChannel.currentOp; + if (op._op === OP_YIELD || op._op === OP_ASYNC) { + return YieldedOp; + } + yieldedOpChannel.currentOp = null; + return op._op === OP_SUCCESS || op._op === OP_FAILURE ? op : exitFailCause(die(op)); + } + } catch (e) { + if (cur !== YieldedOp && !hasProperty(cur, "_op") || !(cur._op in this)) { + cur = dieMessage(`Not a valid effect: ${toStringUnknown(cur)}`); + } else if (isInterruptedException(e)) { + cur = exitFailCause(sequential(die(e), interrupt(none4))); + } else { + cur = die2(e); + } + } + } + } + run = () => { + this.drainQueueOnCurrentThread(); + }; +} +var currentMinimumLogLevel = /* @__PURE__ */ globalValue("effect/FiberRef/currentMinimumLogLevel", () => fiberRefUnsafeMake(fromLiteral("Info"))); +var loggerWithConsoleLog = (self) => makeLogger((opts) => { + const services = getOrDefault2(opts.context, currentServices); + get4(services, consoleTag).unsafe.log(self.log(opts)); +}); +var defaultLogger = /* @__PURE__ */ globalValue(/* @__PURE__ */ Symbol.for("effect/Logger/defaultLogger"), () => loggerWithConsoleLog(stringLogger)); +var tracerLogger = /* @__PURE__ */ globalValue(/* @__PURE__ */ Symbol.for("effect/Logger/tracerLogger"), () => makeLogger(({ + annotations, + cause: cause2, + context: context2, + fiberId: fiberId2, + logLevel, + message +}) => { + const span2 = filterDisablePropagation(getOption2(getOrDefault(context2, currentContext), spanTag)); + if (span2._tag === "None" || span2.value._tag === "ExternalSpan") { + return; + } + const clockService = unsafeGet4(getOrDefault(context2, currentServices), clockTag); + const attributes = {}; + for (const [key, value] of annotations) { + attributes[key] = value; + } + attributes["effect.fiberId"] = threadName2(fiberId2); + attributes["effect.logLevel"] = logLevel.label; + if (cause2 !== null && cause2._tag !== "Empty") { + attributes["effect.cause"] = pretty(cause2, { + renderErrorCause: true + }); + } + span2.value.event(toStringUnknown(Array.isArray(message) && message.length === 1 ? message[0] : message), clockService.unsafeCurrentTimeNanos(), attributes); +})); +var currentLoggers = /* @__PURE__ */ globalValue(/* @__PURE__ */ Symbol.for("effect/FiberRef/currentLoggers"), () => fiberRefUnsafeMakeHashSet(make10(defaultLogger, tracerLogger))); +var annotateLogsScoped = function() { + if (typeof arguments[0] === "string") { + return fiberRefLocallyScopedWith(currentLogAnnotations, set3(arguments[0], arguments[1])); + } + const entries2 = Object.entries(arguments[0]); + return fiberRefLocallyScopedWith(currentLogAnnotations, mutate3((annotations) => { + for (let i = 0;i < entries2.length; i++) { + const [key, value] = entries2[i]; + set3(annotations, key, value); + } + return annotations; + })); +}; +var whenLogLevel = /* @__PURE__ */ dual(2, (effect, level) => { + const requiredLogLevel = typeof level === "string" ? fromLiteral(level) : level; + return withFiberRuntime((fiberState) => { + const minimumLogLevel = fiberState.getFiberRef(currentMinimumLogLevel); + if (greaterThan3(minimumLogLevel, requiredLogLevel)) { + return succeed(none2()); + } + return map9(effect, some2); + }); +}); +var acquireRelease = /* @__PURE__ */ dual((args2) => isEffect(args2[0]), (acquire, release) => uninterruptible(tap(acquire, (a) => addFinalizer((exit2) => release(a, exit2))))); +var acquireReleaseInterruptible = /* @__PURE__ */ dual((args2) => isEffect(args2[0]), (acquire, release) => ensuring(acquire, addFinalizer((exit2) => release(exit2)))); +var addFinalizer = (finalizer) => withFiberRuntime((runtime3) => { + const acquireRefs = runtime3.getFiberRefs(); + const acquireFlags = disable2(runtime3.currentRuntimeFlags, Interruption); + return flatMap7(scope, (scope) => scopeAddFinalizerExit(scope, (exit2) => withFiberRuntime((runtimeFinalizer) => { + const preRefs = runtimeFinalizer.getFiberRefs(); + const preFlags = runtimeFinalizer.currentRuntimeFlags; + const patchRefs = diff6(preRefs, acquireRefs); + const patchFlags = diff4(preFlags, acquireFlags); + const inverseRefs = diff6(acquireRefs, preRefs); + runtimeFinalizer.setFiberRefs(patch7(patchRefs, runtimeFinalizer.id(), acquireRefs)); + return ensuring(withRuntimeFlags(finalizer(exit2), patchFlags), sync(() => { + runtimeFinalizer.setFiberRefs(patch7(inverseRefs, runtimeFinalizer.id(), runtimeFinalizer.getFiberRefs())); + })); + }))); +}); +var daemonChildren = (self) => { + const forkScope = fiberRefLocally(currentForkScopeOverride, some2(globalScope)); + return forkScope(self); +}; +var _existsParFound = /* @__PURE__ */ Symbol.for("effect/Effect/existsPar/found"); +var exists2 = /* @__PURE__ */ dual((args2) => isIterable(args2[0]) && !isEffect(args2[0]), (elements, predicate, options) => matchSimple(options?.concurrency, () => suspend(() => existsLoop(elements[Symbol.iterator](), 0, predicate)), () => matchEffect(forEach6(elements, (a, i) => if_(predicate(a, i), { + onTrue: () => fail2(_existsParFound), + onFalse: () => void_ +}), options), { + onFailure: (e) => e === _existsParFound ? succeed(true) : fail2(e), + onSuccess: () => succeed(false) +}))); +var existsLoop = (iterator, index, f) => { + const next = iterator.next(); + if (next.done) { + return succeed(false); + } + return flatMap7(f(next.value, index), (b) => b ? succeed(b) : existsLoop(iterator, index + 1, f)); +}; +var filter5 = /* @__PURE__ */ dual((args2) => isIterable(args2[0]) && !isEffect(args2[0]), (elements, predicate, options) => { + const predicate_ = options?.negate ? (a, i) => map9(predicate(a, i), not) : predicate; + return matchSimple(options?.concurrency, () => suspend(() => fromIterable(elements).reduceRight((effect, a, i) => zipWith2(effect, suspend(() => predicate_(a, i)), (list, b) => b ? [a, ...list] : list), sync(() => new Array))), () => map9(forEach6(elements, (a, i) => map9(predicate_(a, i), (b) => b ? some2(a) : none2()), options), getSomes)); +}); +var allResolveInput = (input) => { + if (Array.isArray(input) || isIterable(input)) { + return [input, none2()]; + } + const keys5 = Object.keys(input); + const size7 = keys5.length; + return [keys5.map((k) => input[k]), some2((values4) => { + const res = {}; + for (let i = 0;i < size7; i++) { + res[keys5[i]] = values4[i]; + } + return res; + })]; +}; +var allValidate = (effects, reconcile, options) => { + const eitherEffects = []; + for (const effect of effects) { + eitherEffects.push(either2(effect)); + } + return flatMap7(forEach6(eitherEffects, identity, { + concurrency: options?.concurrency, + batching: options?.batching, + concurrentFinalizers: options?.concurrentFinalizers + }), (eithers) => { + const none9 = none2(); + const size7 = eithers.length; + const errors = new Array(size7); + const successes = new Array(size7); + let errored = false; + for (let i = 0;i < size7; i++) { + const either3 = eithers[i]; + if (either3._tag === "Left") { + errors[i] = some2(either3.left); + errored = true; + } else { + successes[i] = either3.right; + errors[i] = none9; + } + } + if (errored) { + return reconcile._tag === "Some" ? fail2(reconcile.value(errors)) : fail2(errors); + } else if (options?.discard) { + return void_; + } + return reconcile._tag === "Some" ? succeed(reconcile.value(successes)) : succeed(successes); + }); +}; +var allEither = (effects, reconcile, options) => { + const eitherEffects = []; + for (const effect of effects) { + eitherEffects.push(either2(effect)); + } + if (options?.discard) { + return forEach6(eitherEffects, identity, { + concurrency: options?.concurrency, + batching: options?.batching, + discard: true, + concurrentFinalizers: options?.concurrentFinalizers + }); + } + return map9(forEach6(eitherEffects, identity, { + concurrency: options?.concurrency, + batching: options?.batching, + concurrentFinalizers: options?.concurrentFinalizers + }), (eithers) => reconcile._tag === "Some" ? reconcile.value(eithers) : eithers); +}; +var all2 = (arg, options) => { + const [effects, reconcile] = allResolveInput(arg); + if (options?.mode === "validate") { + return allValidate(effects, reconcile, options); + } else if (options?.mode === "either") { + return allEither(effects, reconcile, options); + } + return options?.discard !== true && reconcile._tag === "Some" ? map9(forEach6(effects, identity, options), reconcile.value) : forEach6(effects, identity, options); +}; +var allWith = (options) => (arg) => all2(arg, options); +var allSuccesses = (elements, options) => map9(all2(fromIterable(elements).map(exit), options), filterMap2((exit2) => exitIsSuccess(exit2) ? some2(exit2.effect_instruction_i0) : none2())); +var replicate = /* @__PURE__ */ dual(2, (self, n) => Array.from({ + length: n +}, () => self)); +var replicateEffect = /* @__PURE__ */ dual((args2) => isEffect(args2[0]), (self, n, options) => all2(replicate(self, n), options)); +var forEach6 = /* @__PURE__ */ dual((args2) => isIterable(args2[0]), (self, f, options) => withFiberRuntime((r) => { + const isRequestBatchingEnabled = options?.batching === true || options?.batching === "inherit" && r.getFiberRef(currentRequestBatching); + if (options?.discard) { + return match7(options.concurrency, () => finalizersMaskInternal(sequential3, options?.concurrentFinalizers)((restore) => isRequestBatchingEnabled ? forEachConcurrentDiscard(self, (a, i) => restore(f(a, i)), true, false, 1) : forEachSequentialDiscard(self, (a, i) => restore(f(a, i)))), () => finalizersMaskInternal(parallel3, options?.concurrentFinalizers)((restore) => forEachConcurrentDiscard(self, (a, i) => restore(f(a, i)), isRequestBatchingEnabled, false)), (n) => finalizersMaskInternal(parallelN2(n), options?.concurrentFinalizers)((restore) => forEachConcurrentDiscard(self, (a, i) => restore(f(a, i)), isRequestBatchingEnabled, false, n))); + } + return match7(options?.concurrency, () => finalizersMaskInternal(sequential3, options?.concurrentFinalizers)((restore) => isRequestBatchingEnabled ? forEachParN(self, 1, (a, i) => restore(f(a, i)), true) : forEachSequential(self, (a, i) => restore(f(a, i)))), () => finalizersMaskInternal(parallel3, options?.concurrentFinalizers)((restore) => forEachParUnbounded(self, (a, i) => restore(f(a, i)), isRequestBatchingEnabled)), (n) => finalizersMaskInternal(parallelN2(n), options?.concurrentFinalizers)((restore) => forEachParN(self, n, (a, i) => restore(f(a, i)), isRequestBatchingEnabled))); +})); +var forEachParUnbounded = (self, f, batching) => suspend(() => { + const as2 = fromIterable(self); + const array4 = new Array(as2.length); + const fn = (a, i) => flatMap7(f(a, i), (b) => sync(() => array4[i] = b)); + return zipRight(forEachConcurrentDiscard(as2, fn, batching, false), succeed(array4)); +}); +var forEachConcurrentDiscard = (self, f, batching, processAll, n) => uninterruptibleMask((restore) => transplant((graft) => withFiberRuntime((parent) => { + let todos = Array.from(self).reverse(); + let target = todos.length; + if (target === 0) { + return void_; + } + let counter6 = 0; + let interrupted = false; + const fibersCount = n ? Math.min(todos.length, n) : todos.length; + const fibers = new Set; + const results = new Array; + const interruptAll = () => fibers.forEach((fiber) => { + fiber.currentScheduler.scheduleTask(() => { + fiber.unsafeInterruptAsFork(parent.id()); + }, 0, fiber); + }); + const startOrder = new Array; + const joinOrder = new Array; + const residual = new Array; + const collectExits = () => { + const exits = results.filter(({ + exit: exit2 + }) => exit2._tag === "Failure").sort((a, b) => a.index < b.index ? -1 : a.index === b.index ? 0 : 1).map(({ + exit: exit2 + }) => exit2); + if (exits.length === 0) { + exits.push(exitVoid); + } + return exits; + }; + const runFiber = (eff, interruptImmediately = false) => { + const runnable = uninterruptible(graft(eff)); + const fiber = unsafeForkUnstarted(runnable, parent, parent.currentRuntimeFlags, globalScope); + parent.currentScheduler.scheduleTask(() => { + if (interruptImmediately) { + fiber.unsafeInterruptAsFork(parent.id()); + } + fiber.resume(runnable); + }, 0, fiber); + return fiber; + }; + const onInterruptSignal = () => { + if (!processAll) { + target -= todos.length; + todos = []; + } + interrupted = true; + interruptAll(); + }; + const stepOrExit = batching ? step2 : exit; + const processingFiber = runFiber(async_((resume2) => { + const pushResult = (res, index) => { + if (res._op === "Blocked") { + residual.push(res); + } else { + results.push({ + index, + exit: res + }); + if (res._op === "Failure" && !interrupted) { + onInterruptSignal(); + } + } + }; + const next = () => { + if (todos.length > 0) { + const a = todos.pop(); + let index = counter6++; + const returnNextElement = () => { + const a2 = todos.pop(); + index = counter6++; + return flatMap7(yieldNow(), () => flatMap7(stepOrExit(restore(f(a2, index))), onRes)); + }; + const onRes = (res) => { + if (todos.length > 0) { + pushResult(res, index); + if (todos.length > 0) { + return returnNextElement(); + } + } + return succeed(res); + }; + const todo = flatMap7(stepOrExit(restore(f(a, index))), onRes); + const fiber = runFiber(todo); + startOrder.push(fiber); + fibers.add(fiber); + if (interrupted) { + fiber.currentScheduler.scheduleTask(() => { + fiber.unsafeInterruptAsFork(parent.id()); + }, 0, fiber); + } + fiber.addObserver((wrapped) => { + let exit2; + if (wrapped._op === "Failure") { + exit2 = wrapped; + } else { + exit2 = wrapped.effect_instruction_i0; + } + joinOrder.push(fiber); + fibers.delete(fiber); + pushResult(exit2, index); + if (results.length === target) { + resume2(succeed(getOrElse(exitCollectAll(collectExits(), { + parallel: true + }), () => exitVoid))); + } else if (residual.length + results.length === target) { + const exits = collectExits(); + const requests = residual.map((blocked2) => blocked2.effect_instruction_i0).reduce(par); + resume2(succeed(blocked(requests, forEachConcurrentDiscard([getOrElse(exitCollectAll(exits, { + parallel: true + }), () => exitVoid), ...residual.map((blocked2) => blocked2.effect_instruction_i1)], (i) => i, batching, true, n)))); + } else { + next(); + } + }); + } + }; + for (let i = 0;i < fibersCount; i++) { + next(); + } + })); + return asVoid(onExit(flatten4(restore(join2(processingFiber))), exitMatch({ + onFailure: (cause2) => { + onInterruptSignal(); + const target2 = residual.length + 1; + const concurrency = Math.min(typeof n === "number" ? n : residual.length, residual.length); + const toPop = Array.from(residual); + return async_((cb) => { + const exits = []; + let count = 0; + let index = 0; + const check = (index2, hitNext) => (exit2) => { + exits[index2] = exit2; + count++; + if (count === target2) { + cb(exitSucceed(exitFailCause(cause2))); + } + if (toPop.length > 0 && hitNext) { + next(); + } + }; + const next = () => { + runFiber(toPop.pop(), true).addObserver(check(index, true)); + index++; + }; + processingFiber.addObserver(check(index, false)); + index++; + for (let i = 0;i < concurrency; i++) { + next(); + } + }); + }, + onSuccess: () => forEachSequential(joinOrder, (f2) => f2.inheritAll) + }))); +}))); +var forEachParN = (self, n, f, batching) => suspend(() => { + const as2 = fromIterable(self); + const array4 = new Array(as2.length); + const fn = (a, i) => map9(f(a, i), (b) => array4[i] = b); + return zipRight(forEachConcurrentDiscard(as2, fn, batching, false, n), succeed(array4)); +}); +var fork = (self) => withFiberRuntime((state, status) => succeed(unsafeFork(self, state, status.runtimeFlags))); +var forkDaemon = (self) => forkWithScopeOverride(self, globalScope); +var forkWithErrorHandler = /* @__PURE__ */ dual(2, (self, handler) => fork(onError(self, (cause2) => { + const either3 = failureOrCause(cause2); + switch (either3._tag) { + case "Left": + return handler(either3.left); + case "Right": + return failCause(either3.right); + } +}))); +var unsafeFork = (effect, parentFiber, parentRuntimeFlags, overrideScope = null) => { + const childFiber = unsafeMakeChildFiber(effect, parentFiber, parentRuntimeFlags, overrideScope); + childFiber.resume(effect); + return childFiber; +}; +var unsafeForkUnstarted = (effect, parentFiber, parentRuntimeFlags, overrideScope = null) => { + const childFiber = unsafeMakeChildFiber(effect, parentFiber, parentRuntimeFlags, overrideScope); + return childFiber; +}; +var unsafeMakeChildFiber = (effect, parentFiber, parentRuntimeFlags, overrideScope = null) => { + const childId = unsafeMake2(); + const parentFiberRefs = parentFiber.getFiberRefs(); + const childFiberRefs = forkAs(parentFiberRefs, childId); + const childFiber = new FiberRuntime(childId, childFiberRefs, parentRuntimeFlags); + const childContext = getOrDefault(childFiberRefs, currentContext); + const supervisor = childFiber.currentSupervisor; + supervisor.onStart(childContext, effect, some2(parentFiber), childFiber); + childFiber.addObserver((exit2) => supervisor.onEnd(exit2, childFiber)); + const parentScope = overrideScope !== null ? overrideScope : pipe(parentFiber.getFiberRef(currentForkScopeOverride), getOrElse(() => parentFiber.scope())); + parentScope.add(parentRuntimeFlags, childFiber); + return childFiber; +}; +var forkWithScopeOverride = (self, scopeOverride) => withFiberRuntime((parentFiber, parentStatus) => succeed(unsafeFork(self, parentFiber, parentStatus.runtimeFlags, scopeOverride))); +var mergeAll3 = /* @__PURE__ */ dual((args2) => isFunction2(args2[2]), (elements, zero2, f, options) => matchSimple(options?.concurrency, () => fromIterable(elements).reduce((acc, a, i) => zipWith2(acc, a, (acc2, a2) => f(acc2, a2, i)), succeed(zero2)), () => flatMap7(make24(zero2), (acc) => flatMap7(forEach6(elements, (effect, i) => flatMap7(effect, (a) => update3(acc, (b) => f(b, a, i))), options), () => get11(acc))))); +var partition3 = /* @__PURE__ */ dual((args2) => isIterable(args2[0]), (elements, f, options) => pipe(forEach6(elements, (a, i) => either2(f(a, i)), options), map9((chunk2) => partitionMap2(chunk2, identity)))); +var validateAll = /* @__PURE__ */ dual((args2) => isIterable(args2[0]), (elements, f, options) => flatMap7(partition3(elements, f, { + concurrency: options?.concurrency, + batching: options?.batching, + concurrentFinalizers: options?.concurrentFinalizers +}), ([es, bs]) => isNonEmptyArray2(es) ? fail2(es) : options?.discard ? void_ : succeed(bs))); +var raceAll = (all3) => withFiberRuntime((state, status) => async_((resume2) => { + const fibers = new Set; + let winner; + let failures2 = empty16; + const interruptAll = () => { + for (const fiber of fibers) { + fiber.unsafeInterruptAsFork(state.id()); + } + }; + let latch = false; + let empty25 = true; + for (const self of all3) { + empty25 = false; + const fiber = unsafeFork(interruptible2(self), state, status.runtimeFlags); + fibers.add(fiber); + fiber.addObserver((exit2) => { + fibers.delete(fiber); + if (!winner) { + if (exit2._tag === "Success") { + latch = true; + winner = fiber; + failures2 = empty16; + interruptAll(); + } else { + failures2 = parallel(exit2.cause, failures2); + } + } + if (latch && fibers.size === 0) { + resume2(winner ? zipRight(inheritAll(winner), winner.unsafePoll()) : failCause(failures2)); + } + }); + if (winner) + break; + } + if (empty25) { + return resume2(dieSync(() => new IllegalArgumentException(`Received an empty collection of effects`))); + } + latch = true; + return interruptAllAs(fibers, state.id()); +})); +var reduceEffect = /* @__PURE__ */ dual((args2) => isIterable(args2[0]) && !isEffect(args2[0]), (elements, zero2, f, options) => matchSimple(options?.concurrency, () => fromIterable(elements).reduce((acc, a, i) => zipWith2(acc, a, (acc2, a2) => f(acc2, a2, i)), zero2), () => suspend(() => pipe(mergeAll3([zero2, ...elements], none2(), (acc, elem, i) => { + switch (acc._tag) { + case "None": { + return some2(elem); + } + case "Some": { + return some2(f(acc.value, elem, i)); + } + } +}, options), map9((option2) => { + switch (option2._tag) { + case "None": { + throw new Error("BUG: Effect.reduceEffect - please report an issue at https://github.com/Effect-TS/effect/issues"); + } + case "Some": { + return option2.value; + } + } +}))))); +var parallelFinalizers = (self) => contextWithEffect((context2) => match2(getOption2(context2, scopeTag), { + onNone: () => self, + onSome: (scope) => { + switch (scope.strategy._tag) { + case "Parallel": + return self; + case "Sequential": + case "ParallelN": + return flatMap7(scopeFork(scope, parallel3), (inner) => scopeExtend(self, inner)); + } + } +})); +var parallelNFinalizers = (parallelism) => (self) => contextWithEffect((context2) => match2(getOption2(context2, scopeTag), { + onNone: () => self, + onSome: (scope) => { + if (scope.strategy._tag === "ParallelN" && scope.strategy.parallelism === parallelism) { + return self; + } + return flatMap7(scopeFork(scope, parallelN2(parallelism)), (inner) => scopeExtend(self, inner)); + } +})); +var finalizersMask = (strategy) => (self) => finalizersMaskInternal(strategy, true)(self); +var finalizersMaskInternal = (strategy, concurrentFinalizers) => (self) => contextWithEffect((context2) => match2(getOption2(context2, scopeTag), { + onNone: () => self(identity), + onSome: (scope) => { + if (concurrentFinalizers === true) { + const patch9 = strategy._tag === "Parallel" ? parallelFinalizers : strategy._tag === "Sequential" ? sequentialFinalizers : parallelNFinalizers(strategy.parallelism); + switch (scope.strategy._tag) { + case "Parallel": + return patch9(self(parallelFinalizers)); + case "Sequential": + return patch9(self(sequentialFinalizers)); + case "ParallelN": + return patch9(self(parallelNFinalizers(scope.strategy.parallelism))); + } + } else { + return self(identity); + } + } +})); +var scopeWith = (f) => flatMap7(scopeTag, f); +var scopedWith = (f) => flatMap7(scopeMake(), (scope) => onExit(f(scope), (exit2) => scope.close(exit2))); +var scopedEffect = (effect) => flatMap7(scopeMake(), (scope) => scopeUse(effect, scope)); +var sequentialFinalizers = (self) => contextWithEffect((context2) => match2(getOption2(context2, scopeTag), { + onNone: () => self, + onSome: (scope) => { + switch (scope.strategy._tag) { + case "Sequential": + return self; + case "Parallel": + case "ParallelN": + return flatMap7(scopeFork(scope, sequential3), (inner) => scopeExtend(self, inner)); + } + } +})); +var tagMetricsScoped = (key, value) => labelMetricsScoped([make27(key, value)]); +var labelMetricsScoped = (labels) => fiberRefLocallyScopedWith(currentMetricLabels, (old) => union(old, labels)); +var using = /* @__PURE__ */ dual(2, (self, use) => scopedWith((scope) => flatMap7(scopeExtend(self, scope), use))); +var validate = /* @__PURE__ */ dual((args2) => isEffect(args2[1]), (self, that, options) => validateWith(self, that, (a, b) => [a, b], options)); +var validateWith = /* @__PURE__ */ dual((args2) => isEffect(args2[1]), (self, that, f, options) => flatten4(zipWithOptions(exit(self), exit(that), (ea, eb) => exitZipWith(ea, eb, { + onSuccess: f, + onFailure: (ca, cb) => options?.concurrent ? parallel(ca, cb) : sequential(ca, cb) +}), options))); +var validateFirst = /* @__PURE__ */ dual((args2) => isIterable(args2[0]), (elements, f, options) => flip(forEach6(elements, (a, i) => flip(f(a, i)), options))); +var withClockScoped = (c) => fiberRefLocallyScopedWith(currentServices, add2(clockTag, c)); +var withRandomScoped = (value) => fiberRefLocallyScopedWith(currentServices, add2(randomTag, value)); +var withConfigProviderScoped = (provider) => fiberRefLocallyScopedWith(currentServices, add2(configProviderTag, provider)); +var withEarlyRelease = (self) => scopeWith((parent) => flatMap7(scopeFork(parent, sequential2), (child) => pipe(self, scopeExtend(child), map9((value) => [fiberIdWith((fiberId2) => scopeClose(child, exitInterrupt(fiberId2))), value])))); +var zipOptions = /* @__PURE__ */ dual((args2) => isEffect(args2[1]), (self, that, options) => zipWithOptions(self, that, (a, b) => [a, b], options)); +var zipLeftOptions = /* @__PURE__ */ dual((args2) => isEffect(args2[1]), (self, that, options) => { + if (options?.concurrent !== true && (options?.batching === undefined || options.batching === false)) { + return zipLeft(self, that); + } + return zipWithOptions(self, that, (a, _) => a, options); +}); +var zipRightOptions = /* @__PURE__ */ dual((args2) => isEffect(args2[1]), (self, that, options) => { + if (options?.concurrent !== true && (options?.batching === undefined || options.batching === false)) { + return zipRight(self, that); + } + return zipWithOptions(self, that, (_, b) => b, options); +}); +var zipWithOptions = /* @__PURE__ */ dual((args2) => isEffect(args2[1]), (self, that, f, options) => map9(all2([self, that], { + concurrency: options?.concurrent ? 2 : 1, + batching: options?.batching, + concurrentFinalizers: options?.concurrentFinalizers +}), ([a, a2]) => f(a, a2))); +var withRuntimeFlagsScoped = (update5) => { + if (update5 === empty14) { + return void_; + } + return pipe(runtimeFlags, flatMap7((runtimeFlags2) => { + const updatedRuntimeFlags = patch4(runtimeFlags2, update5); + const revertRuntimeFlags = diff4(updatedRuntimeFlags, runtimeFlags2); + return pipe(updateRuntimeFlags(update5), zipRight(addFinalizer(() => updateRuntimeFlags(revertRuntimeFlags))), asVoid); + }), uninterruptible); +}; +var scopeTag = /* @__PURE__ */ GenericTag("effect/Scope"); +var scope = scopeTag; +var scopeUnsafeAddFinalizer = (scope2, fin) => { + if (scope2.state._tag === "Open") { + scope2.state.finalizers.set({}, fin); + } +}; +var ScopeImplProto = { + [ScopeTypeId]: ScopeTypeId, + [CloseableScopeTypeId]: CloseableScopeTypeId, + pipe() { + return pipeArguments(this, arguments); + }, + fork(strategy) { + return sync(() => { + const newScope = scopeUnsafeMake(strategy); + if (this.state._tag === "Closed") { + newScope.state = this.state; + return newScope; + } + const key = {}; + const fin = (exit2) => newScope.close(exit2); + this.state.finalizers.set(key, fin); + scopeUnsafeAddFinalizer(newScope, (_) => sync(() => { + if (this.state._tag === "Open") { + this.state.finalizers.delete(key); + } + })); + return newScope; + }); + }, + close(exit2) { + return suspend(() => { + if (this.state._tag === "Closed") { + return void_; + } + const finalizers = Array.from(this.state.finalizers.values()).reverse(); + this.state = { + _tag: "Closed", + exit: exit2 + }; + if (finalizers.length === 0) { + return void_; + } + return isSequential(this.strategy) ? pipe(forEachSequential(finalizers, (fin) => exit(fin(exit2))), flatMap7((results) => pipe(exitCollectAll(results), map2(exitAsVoid), getOrElse(() => exitVoid)))) : isParallel(this.strategy) ? pipe(forEachParUnbounded(finalizers, (fin) => exit(fin(exit2)), false), flatMap7((results) => pipe(exitCollectAll(results, { + parallel: true + }), map2(exitAsVoid), getOrElse(() => exitVoid)))) : pipe(forEachParN(finalizers, this.strategy.parallelism, (fin) => exit(fin(exit2)), false), flatMap7((results) => pipe(exitCollectAll(results, { + parallel: true + }), map2(exitAsVoid), getOrElse(() => exitVoid)))); + }); + }, + addFinalizer(fin) { + return suspend(() => { + if (this.state._tag === "Closed") { + return fin(this.state.exit); + } + this.state.finalizers.set({}, fin); + return void_; + }); + } +}; +var scopeUnsafeMake = (strategy = sequential2) => { + const scope2 = Object.create(ScopeImplProto); + scope2.strategy = strategy; + scope2.state = { + _tag: "Open", + finalizers: new Map + }; + return scope2; +}; +var scopeMake = (strategy = sequential2) => sync(() => scopeUnsafeMake(strategy)); +var scopeExtend = /* @__PURE__ */ dual(2, (effect, scope2) => mapInputContext(effect, merge3(make6(scopeTag, scope2)))); +var scopeUse = /* @__PURE__ */ dual(2, (effect, scope2) => pipe(effect, scopeExtend(scope2), onExit((exit2) => scope2.close(exit2)))); +var fiberRefUnsafeMakeSupervisor = (initial) => fiberRefUnsafeMakePatch(initial, { + differ: differ2, + fork: empty24 +}); +var fiberRefLocallyScoped = /* @__PURE__ */ dual(2, (self, value) => asVoid(acquireRelease(flatMap7(fiberRefGet(self), (oldValue) => as(fiberRefSet(self, value), oldValue)), (oldValue) => fiberRefSet(self, oldValue)))); +var fiberRefLocallyScopedWith = /* @__PURE__ */ dual(2, (self, f) => fiberRefGetWith(self, (a) => fiberRefLocallyScoped(self, f(a)))); +var currentRuntimeFlags = /* @__PURE__ */ fiberRefUnsafeMakeRuntimeFlags(none5); +var currentSupervisor = /* @__PURE__ */ fiberRefUnsafeMakeSupervisor(none8); +var fiberAwaitAll = (fibers) => forEach6(fibers, _await); +var fiberAll = (fibers) => { + const _fiberAll = { + ...CommitPrototype2, + commit() { + return join2(this); + }, + [FiberTypeId]: fiberVariance2, + id: () => fromIterable(fibers).reduce((id, fiber) => combine3(id, fiber.id()), none4), + await: exit(forEachParUnbounded(fibers, (fiber) => flatten4(fiber.await), false)), + children: map9(forEachParUnbounded(fibers, (fiber) => fiber.children, false), flatten), + inheritAll: forEachSequentialDiscard(fibers, (fiber) => fiber.inheritAll), + poll: map9(forEachSequential(fibers, (fiber) => fiber.poll), reduceRight(some2(exitSucceed(new Array)), (optionB, optionA) => { + switch (optionA._tag) { + case "None": { + return none2(); + } + case "Some": { + switch (optionB._tag) { + case "None": { + return none2(); + } + case "Some": { + return some2(exitZipWith(optionA.value, optionB.value, { + onSuccess: (a, chunk2) => [a, ...chunk2], + onFailure: parallel + })); + } + } + } + } + })), + interruptAsFork: (fiberId2) => forEachSequentialDiscard(fibers, (fiber) => fiber.interruptAsFork(fiberId2)) + }; + return _fiberAll; +}; +var raceWith = /* @__PURE__ */ dual(3, (self, other, options) => raceFibersWith(self, other, { + onSelfWin: (winner, loser) => flatMap7(winner.await, (exit2) => { + switch (exit2._tag) { + case OP_SUCCESS: { + return flatMap7(winner.inheritAll, () => options.onSelfDone(exit2, loser)); + } + case OP_FAILURE: { + return options.onSelfDone(exit2, loser); + } + } + }), + onOtherWin: (winner, loser) => flatMap7(winner.await, (exit2) => { + switch (exit2._tag) { + case OP_SUCCESS: { + return flatMap7(winner.inheritAll, () => options.onOtherDone(exit2, loser)); + } + case OP_FAILURE: { + return options.onOtherDone(exit2, loser); + } + } + }) +})); +var disconnect = (self) => uninterruptibleMask((restore) => fiberIdWith((fiberId2) => flatMap7(forkDaemon(restore(self)), (fiber) => pipe(restore(join2(fiber)), onInterrupt(() => pipe(fiber, interruptAsFork(fiberId2))))))); +var race = /* @__PURE__ */ dual(2, (self, that) => fiberIdWith((parentFiberId) => raceWith(self, that, { + onSelfDone: (exit2, right3) => exitMatchEffect(exit2, { + onFailure: (cause2) => pipe(join2(right3), mapErrorCause((cause22) => parallel(cause2, cause22))), + onSuccess: (value) => pipe(right3, interruptAsFiber(parentFiberId), as(value)) + }), + onOtherDone: (exit2, left3) => exitMatchEffect(exit2, { + onFailure: (cause2) => pipe(join2(left3), mapErrorCause((cause22) => parallel(cause22, cause2))), + onSuccess: (value) => pipe(left3, interruptAsFiber(parentFiberId), as(value)) + }) +}))); +var raceFibersWith = /* @__PURE__ */ dual(3, (self, other, options) => withFiberRuntime((parentFiber, parentStatus) => { + const parentRuntimeFlags = parentStatus.runtimeFlags; + const raceIndicator = make11(true); + const leftFiber = unsafeMakeChildFiber(self, parentFiber, parentRuntimeFlags, options.selfScope); + const rightFiber = unsafeMakeChildFiber(other, parentFiber, parentRuntimeFlags, options.otherScope); + return async_((cb) => { + leftFiber.addObserver(() => completeRace(leftFiber, rightFiber, options.onSelfWin, raceIndicator, cb)); + rightFiber.addObserver(() => completeRace(rightFiber, leftFiber, options.onOtherWin, raceIndicator, cb)); + leftFiber.startFork(self); + rightFiber.startFork(other); + }, combine3(leftFiber.id(), rightFiber.id())); +})); +var completeRace = (winner, loser, cont, ab, cb) => { + if (compareAndSet(true, false)(ab)) { + cb(cont(winner, loser)); + } +}; +var ensuring = /* @__PURE__ */ dual(2, (self, finalizer) => uninterruptibleMask((restore) => matchCauseEffect(restore(self), { + onFailure: (cause1) => matchCauseEffect(finalizer, { + onFailure: (cause2) => failCause(sequential(cause1, cause2)), + onSuccess: () => failCause(cause1) + }), + onSuccess: (a) => as(finalizer, a) +}))); +var invokeWithInterrupt = (self, entries2, onInterrupt2) => fiberIdWith((id) => ensuring(flatMap7(forkDaemon(interruptible2(self)), (processing) => async_((cb) => { + const counts = entries2.map((_) => _.listeners.count); + const checkDone = () => { + if (counts.every((count) => count === 0)) { + if (entries2.every((_) => { + if (_.result.state.current._tag === "Pending") { + return true; + } else if (_.result.state.current._tag === "Done" && exitIsExit(_.result.state.current.effect) && _.result.state.current.effect._tag === "Failure" && isInterrupted(_.result.state.current.effect.cause)) { + return true; + } else { + return false; + } + })) { + cleanup.forEach((f) => f()); + onInterrupt2?.(); + cb(interruptFiber(processing)); + } + } + }; + processing.addObserver((exit2) => { + cleanup.forEach((f) => f()); + cb(exit2); + }); + const cleanup = entries2.map((r, i) => { + const observer = (count) => { + counts[i] = count; + checkDone(); + }; + r.listeners.addObserver(observer); + return () => r.listeners.removeObserver(observer); + }); + checkDone(); + return sync(() => { + cleanup.forEach((f) => f()); + }); +})), suspend(() => { + const residual = entries2.flatMap((entry) => { + if (!entry.state.completed) { + return [entry]; + } + return []; + }); + return forEachSequentialDiscard(residual, (entry) => complete(entry.request, exitInterrupt(id))); +}))); +var makeSpanScoped = (name, options) => { + options = addSpanStackTrace(options); + return uninterruptible(withFiberRuntime((fiber) => { + const scope2 = unsafeGet4(fiber.getFiberRef(currentContext), scopeTag); + const span2 = unsafeMakeSpan(fiber, name, options); + const timingEnabled = fiber.getFiberRef(currentTracerTimingEnabled); + const clock_ = get4(fiber.getFiberRef(currentServices), clockTag); + return as(scopeAddFinalizerExit(scope2, (exit2) => endSpan(span2, exit2, clock_, timingEnabled)), span2); + })); +}; +var withTracerScoped = (value) => fiberRefLocallyScopedWith(currentServices, add2(tracerTag, value)); +var withSpanScoped = function() { + const dataFirst = typeof arguments[0] !== "string"; + const name = dataFirst ? arguments[1] : arguments[0]; + const options = addSpanStackTrace(dataFirst ? arguments[2] : arguments[1]); + if (dataFirst) { + const self = arguments[0]; + return flatMap7(makeSpanScoped(name, addSpanStackTrace(options)), (span2) => provideService(self, spanTag, span2)); + } + return (self) => flatMap7(makeSpanScoped(name, addSpanStackTrace(options)), (span2) => provideService(self, spanTag, span2)); +}; + +// node_modules/effect/dist/esm/Cause.js +var empty25 = empty16; +var fail3 = fail; +var die3 = die; +var interrupt3 = interrupt; +var parallel4 = parallel; +var sequential4 = sequential; +var isCause2 = isCause; +var isFailType2 = isFailType; +var IllegalArgumentException2 = IllegalArgumentException; +var pretty2 = pretty; + +// node_modules/effect/dist/esm/internal/schedule/interval.js +var IntervalSymbolKey = "effect/ScheduleInterval"; +var IntervalTypeId = /* @__PURE__ */ Symbol.for(IntervalSymbolKey); +var empty26 = { + [IntervalTypeId]: IntervalTypeId, + startMillis: 0, + endMillis: 0 +}; +var make33 = (startMillis, endMillis) => { + if (startMillis > endMillis) { + return empty26; + } + return { + [IntervalTypeId]: IntervalTypeId, + startMillis, + endMillis + }; +}; +var lessThan3 = /* @__PURE__ */ dual(2, (self, that) => min2(self, that) === self); +var min2 = /* @__PURE__ */ dual(2, (self, that) => { + if (self.endMillis <= that.startMillis) + return self; + if (that.endMillis <= self.startMillis) + return that; + if (self.startMillis < that.startMillis) + return self; + if (that.startMillis < self.startMillis) + return that; + if (self.endMillis <= that.endMillis) + return self; + return that; +}); +var isEmpty6 = (self) => { + return self.startMillis >= self.endMillis; }; -var transposeMapOption = /* @__PURE__ */ dual(2, (self, f) => isNone(self) ? succeedNone2 : map11(f(self.value), some)); -var makeTagProxy = (TagClass) => { - const cache = new Map; - return new Proxy(TagClass, { - get(target, prop, receiver) { - if (prop in target) { - return Reflect.get(target, prop, receiver); - } - if (cache.has(prop)) { - return cache.get(prop); - } - const fn = (...args2) => andThen2(target, (s) => { - if (typeof s[prop] === "function") { - cache.set(prop, (...args3) => andThen2(target, (s2) => s2[prop](...args3))); - return s[prop](...args2); - } - cache.set(prop, andThen2(target, (s2) => s2[prop])); - return s[prop]; - }); - const cn = andThen2(target, (s) => s[prop]); - Object.assign(fn, cn); - const apply = fn.apply; - const bind4 = fn.bind; - const call = fn.call; - const proto4 = Object.setPrototypeOf({}, Object.getPrototypeOf(cn)); - proto4.apply = apply; - proto4.bind = bind4; - proto4.call = call; - Object.setPrototypeOf(fn, proto4); - cache.set(prop, fn); - return fn; - } - }); +var intersect = /* @__PURE__ */ dual(2, (self, that) => { + const start = Math.max(self.startMillis, that.startMillis); + const end = Math.min(self.endMillis, that.endMillis); + return make33(start, end); +}); +var after = (startMilliseconds) => { + return make33(startMilliseconds, Number.POSITIVE_INFINITY); }; -var Tag2 = (id) => () => { - const limit = Error.stackTraceLimit; - Error.stackTraceLimit = 2; - const creationError = new Error; - Error.stackTraceLimit = limit; - function TagClass() {} - Object.setPrototypeOf(TagClass, TagProto); - TagClass.key = id; - Object.defineProperty(TagClass, "use", { - get() { - return (body) => andThen2(this, body); - } - }); - Object.defineProperty(TagClass, "stack", { - get() { - return creationError.stack; - } - }); - return makeTagProxy(TagClass); + +// node_modules/effect/dist/esm/ScheduleInterval.js +var empty27 = empty26; +var lessThan4 = lessThan3; +var isEmpty7 = isEmpty6; +var intersect2 = intersect; +var after2 = after; + +// node_modules/effect/dist/esm/internal/schedule/intervals.js +var IntervalsSymbolKey = "effect/ScheduleIntervals"; +var IntervalsTypeId = /* @__PURE__ */ Symbol.for(IntervalsSymbolKey); +var make35 = (intervals) => { + return { + [IntervalsTypeId]: IntervalsTypeId, + intervals + }; }; -var Service = function() { - return function() { - const [id, maker] = arguments; - const proxy = "accessors" in maker ? maker["accessors"] : false; - const limit = Error.stackTraceLimit; - Error.stackTraceLimit = 2; - const creationError = new Error; - Error.stackTraceLimit = limit; - let patchState = "unchecked"; - const TagClass = function(service) { - if (patchState === "unchecked") { - const proto4 = Object.getPrototypeOf(service); - if (proto4 === Object.prototype || proto4 === null) { - patchState = "plain"; - } else { - const selfProto = Object.getPrototypeOf(this); - Object.setPrototypeOf(selfProto, proto4); - patchState = "patched"; - } - } - if (patchState === "plain") { - Object.assign(this, service); - } else if (patchState === "patched") { - Object.setPrototypeOf(service, Object.getPrototypeOf(this)); - return service; - } - }; - TagClass.prototype._tag = id; - Object.defineProperty(TagClass, "make", { - get() { - return (service) => new this(service); - } - }); - Object.defineProperty(TagClass, "use", { - get() { - return (body) => andThen2(this, body); - } - }); - TagClass.key = id; - Object.assign(TagClass, TagProto); - Object.defineProperty(TagClass, "stack", { - get() { - return creationError.stack; - } - }); - const hasDeps = "dependencies" in maker && maker.dependencies.length > 0; - const layerName = hasDeps ? "DefaultWithoutDependencies" : "Default"; - let layerCache; - let isFunction3 = false; - if ("effect" in maker) { - isFunction3 = typeof maker.effect === "function"; - Object.defineProperty(TagClass, layerName, { - get() { - if (isFunction3) { - return function() { - return fromEffect2(TagClass, map11(maker.effect.apply(null, arguments), (_) => new this(_))); - }.bind(this); - } - return layerCache ??= fromEffect2(TagClass, map11(maker.effect, (_) => new this(_))); - } - }); - } else if ("scoped" in maker) { - isFunction3 = typeof maker.scoped === "function"; - Object.defineProperty(TagClass, layerName, { - get() { - if (isFunction3) { - return function() { - return scoped(TagClass, map11(maker.scoped.apply(null, arguments), (_) => new this(_))); - }.bind(this); - } - return layerCache ??= scoped(TagClass, map11(maker.scoped, (_) => new this(_))); - } - }); - } else if ("sync" in maker) { - Object.defineProperty(TagClass, layerName, { - get() { - return layerCache ??= sync2(TagClass, () => new this(maker.sync())); - } - }); +var intersect3 = /* @__PURE__ */ dual(2, (self, that) => intersectLoop(self.intervals, that.intervals, empty2())); +var intersectLoop = (_left, _right, _acc) => { + let left3 = _left; + let right3 = _right; + let acc = _acc; + while (isNonEmpty(left3) && isNonEmpty(right3)) { + const interval = pipe(headNonEmpty2(left3), intersect2(headNonEmpty2(right3))); + const intervals = isEmpty7(interval) ? acc : pipe(acc, prepend2(interval)); + if (pipe(headNonEmpty2(left3), lessThan4(headNonEmpty2(right3)))) { + left3 = tailNonEmpty2(left3); } else { - Object.defineProperty(TagClass, layerName, { - get() { - return layerCache ??= succeed4(TagClass, new this(maker.succeed)); - } + right3 = tailNonEmpty2(right3); + } + acc = intervals; + } + return make35(reverse2(acc)); +}; +var start = (self) => { + return pipe(self.intervals, head2, getOrElse(() => empty27)).startMillis; +}; +var end = (self) => { + return pipe(self.intervals, head2, getOrElse(() => empty27)).endMillis; +}; +var lessThan5 = /* @__PURE__ */ dual(2, (self, that) => start(self) < start(that)); +var isNonEmpty3 = (self) => { + return isNonEmpty(self.intervals); +}; + +// node_modules/effect/dist/esm/ScheduleIntervals.js +var make36 = make35; +var intersect4 = intersect3; +var start2 = start; +var end2 = end; +var lessThan6 = lessThan5; +var isNonEmpty4 = isNonEmpty3; + +// node_modules/effect/dist/esm/internal/schedule/decision.js +var OP_CONTINUE = "Continue"; +var OP_DONE2 = "Done"; +var _continue = (intervals) => { + return { + _tag: OP_CONTINUE, + intervals + }; +}; +var continueWith = (interval) => { + return { + _tag: OP_CONTINUE, + intervals: make36(of2(interval)) + }; +}; +var done4 = { + _tag: OP_DONE2 +}; +var isContinue = (self) => { + return self._tag === OP_CONTINUE; +}; +var isDone3 = (self) => { + return self._tag === OP_DONE2; +}; + +// node_modules/effect/dist/esm/ScheduleDecision.js +var _continue2 = _continue; +var continueWith2 = continueWith; +var done5 = done4; +var isContinue2 = isContinue; +var isDone4 = isDone3; + +// node_modules/effect/dist/esm/Scope.js +var close = scopeClose; +var fork2 = scopeFork; + +// node_modules/effect/dist/esm/internal/effect/circular.js +class Semaphore { + permits; + waiters = /* @__PURE__ */ new Set; + taken = 0; + constructor(permits) { + this.permits = permits; + } + get free() { + return this.permits - this.taken; + } + take = (n) => asyncInterrupt((resume2) => { + if (this.free < n) { + const observer = () => { + if (this.free < n) + return; + this.waiters.delete(observer); + resume2(suspend(() => { + if (this.free < n) + return this.take(n); + this.taken += n; + return succeed(n); + })); + }; + this.waiters.add(observer); + return sync(() => { + this.waiters.delete(observer); }); } - if (hasDeps) { - let layerWithDepsCache; - Object.defineProperty(TagClass, "Default", { - get() { - if (isFunction3) { - return function() { - return provide(this.DefaultWithoutDependencies.apply(null, arguments), maker.dependencies); - }; - } - return layerWithDepsCache ??= provide(this.DefaultWithoutDependencies, maker.dependencies); + resume2(suspend(() => { + if (this.free < n) + return this.take(n); + this.taken += n; + return succeed(n); + })); + }); + updateTakenUnsafe(fiber, f) { + this.taken = f(this.taken); + if (this.waiters.size > 0) { + fiber.getFiberRef(currentScheduler).scheduleTask(() => { + const iter = this.waiters.values(); + let item = iter.next(); + while (item.done === false && this.free > 0) { + item.value(); + item = iter.next(); } - }); + }, fiber.getFiberRef(currentSchedulingPriority), fiber); + } + return succeed(this.free); + } + updateTaken(f) { + return withFiberRuntime((fiber) => this.updateTakenUnsafe(fiber, f)); + } + resize = (permits) => asVoid(withFiberRuntime((fiber) => { + this.permits = permits; + if (this.free < 0) { + return void_; + } + return this.updateTakenUnsafe(fiber, (taken) => taken); + })); + release = (n) => this.updateTaken((taken) => taken - n); + releaseAll = /* @__PURE__ */ this.updateTaken((_) => 0); + withPermits = (n) => (self) => uninterruptibleMask((restore) => flatMap7(restore(this.take(n)), (permits) => ensuring(restore(self), this.release(permits)))); + withPermitsIfAvailable = (n) => (self) => uninterruptibleMask((restore) => suspend(() => { + if (this.free < n) { + return succeedNone; + } + this.taken += n; + return ensuring(restore(asSome(self)), this.release(n)); + })); +} +var unsafeMakeSemaphore = (permits) => new Semaphore(permits); +var makeSemaphore = (permits) => sync(() => unsafeMakeSemaphore(permits)); + +class Latch extends Class2 { + isOpen; + waiters = []; + scheduled = false; + constructor(isOpen) { + super(); + this.isOpen = isOpen; + } + commit() { + return this.await; + } + unsafeSchedule(fiber) { + if (this.scheduled || this.waiters.length === 0) { + return void_; + } + this.scheduled = true; + fiber.currentScheduler.scheduleTask(this.flushWaiters, fiber.getFiberRef(currentSchedulingPriority), fiber); + return void_; + } + flushWaiters = () => { + this.scheduled = false; + const waiters = this.waiters; + this.waiters = []; + for (let i = 0;i < waiters.length; i++) { + waiters[i](exitVoid); } - return proxy === true ? makeTagProxy(TagClass) : TagClass; }; -}; -var fn = function(nameOrBody, ...pipeables) { - const limit = Error.stackTraceLimit; - Error.stackTraceLimit = 2; - const errorDef = new Error; - Error.stackTraceLimit = limit; - if (typeof nameOrBody !== "string") { - return defineLength(nameOrBody.length, function(...args2) { - const limit2 = Error.stackTraceLimit; - Error.stackTraceLimit = 2; - const errorCall = new Error; - Error.stackTraceLimit = limit2; - return fnApply({ - self: this, - body: nameOrBody, - args: args2, - pipeables, - spanName: "", - spanOptions: { - context: DisablePropagation.context(true) - }, - errorDef, - errorCall - }); - }); + open = /* @__PURE__ */ withFiberRuntime((fiber) => { + if (this.isOpen) { + return void_; + } + this.isOpen = true; + return this.unsafeSchedule(fiber); + }); + unsafeOpen() { + if (this.isOpen) + return; + this.isOpen = true; + this.flushWaiters(); } - const name = nameOrBody; - const options = pipeables[0]; - return (body, ...pipeables2) => defineLength(body.length, { - [name](...args2) { - const limit2 = Error.stackTraceLimit; - Error.stackTraceLimit = 2; - const errorCall = new Error; - Error.stackTraceLimit = limit2; - return fnApply({ - self: this, - body, - args: args2, - pipeables: pipeables2, - spanName: name, - spanOptions: options, - errorDef, - errorCall - }); + release = /* @__PURE__ */ withFiberRuntime((fiber) => { + if (this.isOpen) { + return void_; } - }[name]); -}; -function defineLength(length2, fn2) { - return Object.defineProperty(fn2, "length", { - value: length2, - configurable: true + return this.unsafeSchedule(fiber); + }); + await = /* @__PURE__ */ asyncInterrupt((resume2) => { + if (this.isOpen) { + return resume2(void_); + } + this.waiters.push(resume2); + return sync(() => { + const index = this.waiters.indexOf(resume2); + if (index !== -1) { + this.waiters.splice(index, 1); + } + }); }); + unsafeClose() { + this.isOpen = false; + } + close = /* @__PURE__ */ sync(() => { + this.isOpen = false; + }); + whenOpen = (self) => { + return zipRight(this.await, self); + }; } -function fnApply(options) { - let effect; - let fnError = undefined; - if (isGeneratorFunction(options.body)) { - effect = fromIterator(() => options.body.apply(options.self, options.args)); +var unsafeMakeLatch = (open) => new Latch(open ?? false); +var makeLatch = (open) => sync(() => unsafeMakeLatch(open)); +var awaitAllChildren = (self) => ensuringChildren(self, fiberAwaitAll); +var cached2 = /* @__PURE__ */ dual(2, (self, timeToLive) => map9(cachedInvalidateWithTTL(self, timeToLive), (tuple2) => tuple2[0])); +var cachedInvalidateWithTTL = /* @__PURE__ */ dual(2, (self, timeToLive) => { + const duration = decode(timeToLive); + return flatMap7(context(), (env) => map9(makeSynchronized(none2()), (cache) => [provideContext(getCachedValue(self, duration, cache), env), invalidateCache(cache)])); +}); +var computeCachedValue = (self, timeToLive, start3) => { + const timeToLiveMillis = toMillis(decode(timeToLive)); + return pipe(deferredMake(), tap((deferred) => intoDeferred(self, deferred)), map9((deferred) => some2([start3 + timeToLiveMillis, deferred]))); +}; +var getCachedValue = (self, timeToLive, cache) => uninterruptibleMask((restore) => pipe(clockWith3((clock2) => clock2.currentTimeMillis), flatMap7((time) => updateSomeAndGetEffectSynchronized(cache, (option2) => { + switch (option2._tag) { + case "None": { + return some2(computeCachedValue(self, timeToLive, time)); + } + case "Some": { + const [end3] = option2.value; + return end3 - time <= 0 ? some2(computeCachedValue(self, timeToLive, time)) : none2(); + } + } +})), flatMap7((option2) => isNone2(option2) ? dieMessage("BUG: Effect.cachedInvalidate - please report an issue at https://github.com/Effect-TS/effect/issues") : restore(deferredAwait(option2.value[1]))))); +var invalidateCache = (cache) => set4(cache, none2()); +var ensuringChild = /* @__PURE__ */ dual(2, (self, f) => ensuringChildren(self, (children) => f(fiberAll(children)))); +var ensuringChildren = /* @__PURE__ */ dual(2, (self, children) => flatMap7(track, (supervisor) => pipe(supervised(self, supervisor), ensuring(flatMap7(supervisor.value, children))))); +var forkAll = /* @__PURE__ */ dual((args2) => isIterable(args2[0]), (effects, options) => options?.discard ? forEachSequentialDiscard(effects, fork) : map9(forEachSequential(effects, fork), fiberAll)); +var forkIn = /* @__PURE__ */ dual(2, (self, scope2) => withFiberRuntime((parent, parentStatus) => { + const scopeImpl = scope2; + const fiber = unsafeFork(self, parent, parentStatus.runtimeFlags, globalScope); + if (scopeImpl.state._tag === "Open") { + const finalizer = () => fiberIdWith((fiberId2) => equals(fiberId2, fiber.id()) ? void_ : asVoid(interruptFiber(fiber))); + const key = {}; + scopeImpl.state.finalizers.set(key, finalizer); + fiber.addObserver(() => { + if (scopeImpl.state._tag === "Closed") + return; + scopeImpl.state.finalizers.delete(key); + }); } else { - try { - effect = options.body.apply(options.self, options.args); - } catch (error) { - fnError = error; - effect = die4(error); + fiber.unsafeInterruptAsFork(parent.id()); + } + return succeed(fiber); +})); +var forkScoped = (self) => scopeWith((scope2) => forkIn(self, scope2)); +var fromFiber = (fiber) => join2(fiber); +var fromFiberEffect = (fiber) => suspend(() => flatMap7(fiber, join2)); +var memoKeySymbol = /* @__PURE__ */ Symbol.for("effect/Effect/memoizeFunction.key"); + +class Key { + a; + eq; + [memoKeySymbol] = memoKeySymbol; + constructor(a, eq) { + this.a = a; + this.eq = eq; + } + [symbol2](that) { + if (hasProperty(that, memoKeySymbol)) { + if (this.eq) { + return this.eq(this.a, that.a); + } else { + return equals(this.a, that.a); + } + } + return false; + } + [symbol]() { + return this.eq ? 0 : cached(this, hash(this.a)); + } +} +var cachedFunction = (f, eq) => { + return pipe(sync(() => empty21()), flatMap7(makeSynchronized), map9((ref) => (a) => pipe(ref.modifyEffect((map10) => { + const result = pipe(map10, get12(new Key(a, eq))); + if (isNone2(result)) { + return pipe(deferredMake(), tap((deferred) => pipe(diffFiberRefs(f(a)), intoDeferred(deferred), fork)), map9((deferred) => [deferred, pipe(map10, set5(new Key(a, eq), deferred))])); + } + return succeed([result.value, map10]); + }), flatMap7(deferredAwait), flatMap7(([patch9, b]) => pipe(patchFiberRefs(patch9), as(b)))))); +}; +var raceFirst = /* @__PURE__ */ dual(2, (self, that) => pipe(exit(self), race(exit(that)), (effect) => flatten4(effect))); +var supervised = /* @__PURE__ */ dual(2, (self, supervisor) => { + const supervise = fiberRefLocallyWith(currentSupervisor, (s) => s.zip(supervisor)); + return supervise(self); +}); +var timeout = /* @__PURE__ */ dual(2, (self, duration) => timeoutFail(self, { + onTimeout: () => timeoutExceptionFromDuration(duration), + duration +})); +var timeoutFail = /* @__PURE__ */ dual(2, (self, { + duration, + onTimeout +}) => flatten4(timeoutTo(self, { + onTimeout: () => failSync(onTimeout), + onSuccess: succeed, + duration +}))); +var timeoutFailCause = /* @__PURE__ */ dual(2, (self, { + duration, + onTimeout +}) => flatten4(timeoutTo(self, { + onTimeout: () => failCauseSync(onTimeout), + onSuccess: succeed, + duration +}))); +var timeoutOption = /* @__PURE__ */ dual(2, (self, duration) => timeoutTo(self, { + duration, + onSuccess: some2, + onTimeout: none2 +})); +var timeoutTo = /* @__PURE__ */ dual(2, (self, { + duration, + onSuccess, + onTimeout +}) => fiberIdWith((parentFiberId) => uninterruptibleMask((restore) => raceFibersWith(restore(self), interruptible2(sleep3(duration)), { + onSelfWin: (winner, loser) => flatMap7(winner.await, (exit2) => { + if (exit2._tag === "Success") { + return flatMap7(winner.inheritAll, () => as(interruptAsFiber(loser, parentFiberId), onSuccess(exit2.value))); + } else { + return flatMap7(interruptAsFiber(loser, parentFiberId), () => exitFailCause(exit2.cause)); } - } - if (options.pipeables.length > 0) { - try { - for (const x of options.pipeables) { - effect = x(effect, ...options.args); - } - } catch (error) { - effect = fnError ? failCause5(sequential(die(fnError), die(error))) : die4(error); + }), + onOtherWin: (winner, loser) => flatMap7(winner.await, (exit2) => { + if (exit2._tag === "Success") { + return flatMap7(winner.inheritAll, () => as(interruptAsFiber(loser, parentFiberId), onTimeout())); + } else { + return flatMap7(interruptAsFiber(loser, parentFiberId), () => exitFailCause(exit2.cause)); } + }), + otherScope: globalScope +})))); +var SynchronizedSymbolKey = "effect/Ref/SynchronizedRef"; +var SynchronizedTypeId = /* @__PURE__ */ Symbol.for(SynchronizedSymbolKey); +var synchronizedVariance = { + _A: (_) => _ +}; + +class SynchronizedImpl extends Class2 { + ref; + withLock; + [SynchronizedTypeId] = synchronizedVariance; + [RefTypeId] = refVariance; + [TypeId10] = TypeId10; + constructor(ref, withLock) { + super(); + this.ref = ref; + this.withLock = withLock; + this.get = get10(this.ref); } - let cache = false; - const captureStackTrace = () => { - if (cache !== false) { - return cache; + get; + commit() { + return this.get; + } + modify(f) { + return this.modifyEffect((a) => succeed(f(a))); + } + modifyEffect(f) { + return this.withLock(pipe(flatMap7(get10(this.ref), f), flatMap7(([b, a]) => as(set4(this.ref, a), b)))); + } +} +var makeSynchronized = (value) => sync(() => unsafeMakeSynchronized(value)); +var unsafeMakeSynchronized = (value) => { + const ref = unsafeMake4(value); + const sem = unsafeMakeSemaphore(1); + return new SynchronizedImpl(ref, sem.withPermits(1)); +}; +var updateSomeAndGetEffectSynchronized = /* @__PURE__ */ dual(2, (self, pf) => self.modifyEffect((value) => { + const result = pf(value); + switch (result._tag) { + case "None": { + return succeed([value, value]); } - if (options.errorCall.stack) { - const stackDef = options.errorDef.stack.trim().split(` -`); - const stackCall = options.errorCall.stack.trim().split(` -`); - let endStackDef = stackDef.slice(2).join(` -`).trim(); - if (!endStackDef.includes(`(`)) { - endStackDef = endStackDef.replace(/at (.*)/, "at ($1)"); - } - let endStackCall = stackCall.slice(2).join(` -`).trim(); - if (!endStackCall.includes(`(`)) { - endStackCall = endStackCall.replace(/at (.*)/, "at ($1)"); - } - cache = `${endStackDef} -${endStackCall}`; - return cache; + case "Some": { + return map9(result.value, (a) => [a, a]); } - }; - const opts = options.spanOptions && "captureStackTrace" in options.spanOptions ? options.spanOptions : { - captureStackTrace, - ...options.spanOptions - }; - return withSpan2(effect, options.spanName, opts); -} -var fnUntraced2 = fnUntraced; -var ensureSuccessType = () => (effect) => effect; -var ensureErrorType = () => (effect) => effect; -var ensureRequirementsType = () => (effect) => effect; -// node_modules/effect/dist/esm/ConfigError.js -var InvalidData2 = InvalidData; + } +})); +var bindAll = /* @__PURE__ */ dual((args2) => isEffect(args2[0]), (self, f, options) => flatMap7(self, (a) => all2(f(a), options).pipe(map9((record) => Object.assign({}, a, record))))); -// node_modules/effect/dist/esm/internal/redacted.js -var RedactedSymbolKey = "effect/Redacted"; -var redactedRegistry = /* @__PURE__ */ globalValue("effect/Redacted/redactedRegistry", () => new WeakMap); -var RedactedTypeId = /* @__PURE__ */ Symbol.for(RedactedSymbolKey); -var proto4 = { - [RedactedTypeId]: { - _A: (_) => _ - }, - pipe() { - return pipeArguments(this, arguments); - }, - toString() { - return ""; - }, - toJSON() { - return ""; - }, - [NodeInspectSymbol]() { - return ""; - }, - [symbol]() { - return pipe(hash(RedactedSymbolKey), combine(hash(redactedRegistry.get(this))), cached(this)); - }, - [symbol2](that) { - return isRedacted(that) && equals(redactedRegistry.get(this), redactedRegistry.get(that)); +// node_modules/effect/dist/esm/internal/managedRuntime/circular.js +var TypeId13 = /* @__PURE__ */ Symbol.for("effect/ManagedRuntime"); + +// node_modules/effect/dist/esm/internal/opCodes/layer.js +var OP_FRESH = "Fresh"; +var OP_FROM_EFFECT = "FromEffect"; +var OP_SCOPED = "Scoped"; +var OP_SUSPEND = "Suspend"; +var OP_PROVIDE = "Provide"; +var OP_PROVIDE_MERGE = "ProvideMerge"; +var OP_MERGE_ALL = "MergeAll"; + +// node_modules/effect/dist/esm/Fiber.js +var interruptAs = interruptAsFiber; + +// node_modules/effect/dist/esm/internal/runtime.js +var makeDual = (f) => function() { + if (arguments.length === 1) { + const runtime3 = arguments[0]; + return (effect, ...args2) => f(runtime3, effect, ...args2); } + return f.apply(this, arguments); }; -var isRedacted = (u) => hasProperty(u, RedactedTypeId); -var make40 = (value) => { - const redacted = Object.create(proto4); - redactedRegistry.set(redacted, value); - return redacted; -}; -var value = (self) => { - if (redactedRegistry.has(self)) { - return redactedRegistry.get(self); - } else { - throw new Error("Unable to get redacted value"); +var unsafeFork2 = /* @__PURE__ */ makeDual((runtime3, self, options) => { + const fiberId2 = unsafeMake2(); + const fiberRefUpdates = [[currentContext, [[fiberId2, runtime3.context]]]]; + if (options?.scheduler) { + fiberRefUpdates.push([currentScheduler, [[fiberId2, options.scheduler]]]); } -}; - -// node_modules/effect/dist/esm/internal/config.js -var ConfigSymbolKey = "effect/Config"; -var ConfigTypeId = /* @__PURE__ */ Symbol.for(ConfigSymbolKey); -var configVariance = { - _A: (_) => _ -}; -var proto5 = { - ...CommitPrototype, - [ConfigTypeId]: configVariance, - commit() { - return config(this); + let fiberRefs3 = updateManyAs2(runtime3.fiberRefs, { + entries: fiberRefUpdates, + forkAs: fiberId2 + }); + if (options?.updateRefs) { + fiberRefs3 = options.updateRefs(fiberRefs3, fiberId2); } -}; -var mapOrFail = /* @__PURE__ */ dual(2, (self, f) => { - const mapOrFail2 = Object.create(proto5); - mapOrFail2._tag = OP_MAP_OR_FAIL; - mapOrFail2.original = self; - mapOrFail2.mapOrFail = f; - return mapOrFail2; -}); -var nested2 = /* @__PURE__ */ dual(2, (self, name) => { - const nested3 = Object.create(proto5); - nested3._tag = OP_NESTED; - nested3.name = name; - nested3.config = self; - return nested3; + const fiberRuntime = new FiberRuntime(fiberId2, fiberRefs3, runtime3.runtimeFlags); + let effect = self; + if (options?.scope) { + effect = flatMap7(fork2(options.scope, sequential2), (closeableScope) => zipRight(scopeAddFinalizer(closeableScope, fiberIdWith((id) => equals(id, fiberRuntime.id()) ? void_ : interruptAsFiber(fiberRuntime, id))), onExit(self, (exit2) => close(closeableScope, exit2)))); + } + const supervisor = fiberRuntime.currentSupervisor; + if (supervisor !== none8) { + supervisor.onStart(runtime3.context, effect, none2(), fiberRuntime); + fiberRuntime.addObserver((exit2) => supervisor.onEnd(exit2, fiberRuntime)); + } + globalScope.add(runtime3.runtimeFlags, fiberRuntime); + if (options?.immediate === false) { + fiberRuntime.resume(effect); + } else { + fiberRuntime.start(effect); + } + return fiberRuntime; }); -var primitive = (description, parse2) => { - const primitive2 = Object.create(proto5); - primitive2._tag = OP_PRIMITIVE; - primitive2.description = description; - primitive2.parse = parse2; - return primitive2; -}; -var string2 = (name) => { - const config2 = primitive("a text property", right2); - return name === undefined ? config2 : nested2(config2, name); -}; - -// node_modules/effect/dist/esm/Config.js -var mapOrFail2 = mapOrFail; -var string3 = string2; -// node_modules/effect/dist/esm/DateTime.js -var isDateTime2 = isDateTime; -var isTimeZoneOffset2 = isTimeZoneOffset; -var isTimeZoneNamed2 = isTimeZoneNamed; -var isUtc2 = isUtc; -var isZoned2 = isZoned; -var Equivalence4 = Equivalence3; -var unsafeFromDate2 = unsafeFromDate; -var unsafeMake9 = unsafeMake8; -var unsafeMakeZoned2 = unsafeMakeZoned; -var makeZonedFromString2 = makeZonedFromString; -var zoneUnsafeMakeNamed2 = zoneUnsafeMakeNamed; -var zoneMakeOffset2 = zoneMakeOffset; -var zoneFromString2 = zoneFromString; -var zoneToString2 = zoneToString; -var toDateUtc2 = toDateUtc; -var toEpochMillis2 = toEpochMillis; -var formatIso2 = formatIso; -var formatIsoZoned2 = formatIsoZoned; -// node_modules/effect/dist/esm/internal/encoding/common.js -var DecodeExceptionTypeId = /* @__PURE__ */ Symbol.for("effect/Encoding/errors/Decode"); -var DecodeException = (input, message) => { - const out = { - _tag: "DecodeException", - [DecodeExceptionTypeId]: DecodeExceptionTypeId, - input - }; - if (isString(message)) { - out.message = message; +var unsafeRunCallback = /* @__PURE__ */ makeDual((runtime3, effect, options = {}) => { + const fiberRuntime = unsafeFork2(runtime3, effect, options); + if (options.onExit) { + fiberRuntime.addObserver((exit2) => { + options.onExit(exit2); + }); } - return out; -}; -var EncodeExceptionTypeId = /* @__PURE__ */ Symbol.for("effect/Encoding/errors/Encode"); -var EncodeException = (input, message) => { - const out = { - _tag: "EncodeException", - [EncodeExceptionTypeId]: EncodeExceptionTypeId, - input - }; - if (isString(message)) { - out.message = message; + return (id, cancelOptions) => unsafeRunCallback(runtime3)(pipe(fiberRuntime, interruptAs(id ?? none4)), { + ...cancelOptions, + onExit: cancelOptions?.onExit ? (exit2) => cancelOptions.onExit(flatten5(exit2)) : undefined + }); +}); +var unsafeRunSync = /* @__PURE__ */ makeDual((runtime3, effect) => { + const result = unsafeRunSyncExit(runtime3)(effect); + if (result._tag === "Failure") { + throw fiberFailure(result.effect_instruction_i0); } - return out; + return result.effect_instruction_i0; +}); + +class AsyncFiberExceptionImpl extends Error { + fiber; + _tag = "AsyncFiberException"; + constructor(fiber) { + super(`Fiber #${fiber.id().id} cannot be resolved synchronously. This is caused by using runSync on an effect that performs async work`); + this.fiber = fiber; + this.name = this._tag; + this.stack = this.message; + } +} +var asyncFiberException = (fiber) => { + const limit = Error.stackTraceLimit; + Error.stackTraceLimit = 0; + const error = new AsyncFiberExceptionImpl(fiber); + Error.stackTraceLimit = limit; + return error; }; -var encoder = /* @__PURE__ */ new TextEncoder; -var decoder = /* @__PURE__ */ new TextDecoder; +var FiberFailureId = /* @__PURE__ */ Symbol.for("effect/Runtime/FiberFailure"); +var FiberFailureCauseId = /* @__PURE__ */ Symbol.for("effect/Runtime/FiberFailure/Cause"); -// node_modules/effect/dist/esm/internal/encoding/base64.js -var encode = (bytes) => { - const length2 = bytes.length; - let result = ""; - let i; - for (i = 2;i < length2; i += 3) { - result += base64abc[bytes[i - 2] >> 2]; - result += base64abc[(bytes[i - 2] & 3) << 4 | bytes[i - 1] >> 4]; - result += base64abc[(bytes[i - 1] & 15) << 2 | bytes[i] >> 6]; - result += base64abc[bytes[i] & 63]; +class FiberFailureImpl extends Error { + [FiberFailureId]; + [FiberFailureCauseId]; + constructor(cause2) { + const head4 = prettyErrors(cause2)[0]; + super(head4?.message || "An error has occurred"); + this[FiberFailureId] = FiberFailureId; + this[FiberFailureCauseId] = cause2; + this.name = head4 ? `(FiberFailure) ${head4.name}` : "FiberFailure"; + if (head4?.stack) { + this.stack = head4.stack; + } } - if (i === length2 + 1) { - result += base64abc[bytes[i - 2] >> 2]; - result += base64abc[(bytes[i - 2] & 3) << 4]; - result += "=="; + toJSON() { + return { + _id: "FiberFailure", + cause: this[FiberFailureCauseId].toJSON() + }; } - if (i === length2) { - result += base64abc[bytes[i - 2] >> 2]; - result += base64abc[(bytes[i - 2] & 3) << 4 | bytes[i - 1] >> 4]; - result += base64abc[(bytes[i - 1] & 15) << 2]; - result += "="; + toString() { + return "(FiberFailure) " + pretty(this[FiberFailureCauseId], { + renderErrorCause: true + }); } - return result; + [NodeInspectSymbol]() { + return this.toString(); + } +} +var fiberFailure = (cause2) => { + const limit = Error.stackTraceLimit; + Error.stackTraceLimit = 0; + const error = new FiberFailureImpl(cause2); + Error.stackTraceLimit = limit; + return error; }; -var decode2 = (str) => { - const stripped = stripCrlf(str); - const length2 = stripped.length; - if (length2 % 4 !== 0) { - return left2(DecodeException(stripped, `Length must be a multiple of 4, but is ${length2}`)); +var fastPath = (effect) => { + const op = effect; + switch (op._op) { + case "Failure": + case "Success": { + return op; + } + case "Left": { + return exitFail(op.left); + } + case "Right": { + return exitSucceed(op.right); + } + case "Some": { + return exitSucceed(op.value); + } + case "None": { + return exitFail(new NoSuchElementException); + } } - const index = stripped.indexOf("="); - if (index !== -1 && (index < length2 - 2 || index === length2 - 2 && stripped[length2 - 1] !== "=")) { - return left2(DecodeException(stripped, "Found a '=' character, but it is not at the end")); +}; +var unsafeRunSyncExit = /* @__PURE__ */ makeDual((runtime3, effect) => { + const op = fastPath(effect); + if (op) { + return op; } - try { - const missingOctets = stripped.endsWith("==") ? 2 : stripped.endsWith("=") ? 1 : 0; - const result = new Uint8Array(3 * (length2 / 4) - missingOctets); - for (let i = 0, j = 0;i < length2; i += 4, j += 3) { - const buffer = getBase64Code(stripped.charCodeAt(i)) << 18 | getBase64Code(stripped.charCodeAt(i + 1)) << 12 | getBase64Code(stripped.charCodeAt(i + 2)) << 6 | getBase64Code(stripped.charCodeAt(i + 3)); - result[j] = buffer >> 16; - result[j + 1] = buffer >> 8 & 255; - result[j + 2] = buffer & 255; + const scheduler = new SyncScheduler; + const fiberRuntime = unsafeFork2(runtime3)(effect, { + scheduler + }); + scheduler.flush(); + const result = fiberRuntime.unsafePoll(); + if (result) { + return result; + } + return exitDie(capture(asyncFiberException(fiberRuntime), currentSpanFromFiber(fiberRuntime))); +}); +var unsafeRunPromise = /* @__PURE__ */ makeDual((runtime3, effect, options) => unsafeRunPromiseExit(runtime3, effect, options).then((result) => { + switch (result._tag) { + case OP_SUCCESS: { + return result.effect_instruction_i0; + } + case OP_FAILURE: { + throw fiberFailure(result.effect_instruction_i0); } - return right2(result); - } catch (e) { - return left2(DecodeException(stripped, e instanceof Error ? e.message : "Invalid input")); } -}; -var stripCrlf = (str) => str.replace(/[\n\r]/g, ""); -function getBase64Code(charCode) { - if (charCode >= base64codes.length) { - throw new TypeError(`Invalid character ${String.fromCharCode(charCode)}`); +})); +var unsafeRunPromiseExit = /* @__PURE__ */ makeDual((runtime3, effect, options) => new Promise((resolve) => { + const op = fastPath(effect); + if (op) { + resolve(op); } - const code = base64codes[charCode]; - if (code === 255) { - throw new TypeError(`Invalid character ${String.fromCharCode(charCode)}`); + const fiber = unsafeFork2(runtime3)(effect); + fiber.addObserver((exit2) => { + resolve(exit2); + }); + if (options?.signal !== undefined) { + if (options.signal.aborted) { + fiber.unsafeInterruptAsFork(fiber.id()); + } else { + options.signal.addEventListener("abort", () => { + fiber.unsafeInterruptAsFork(fiber.id()); + }, { + once: true + }); + } } - return code; -} -var base64abc = ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "+", "/"]; -var base64codes = [255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 62, 255, 255, 255, 63, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 255, 255, 255, 0, 255, 255, 255, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 255, 255, 255, 255, 255, 255, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51]; +})); -// node_modules/effect/dist/esm/internal/encoding/base64Url.js -var encode2 = (data) => encode(data).replace(/=/g, "").replace(/\+/g, "-").replace(/\//g, "_"); -var decode3 = (str) => { - const stripped = stripCrlf(str); - const length2 = stripped.length; - if (length2 % 4 === 1) { - return left2(DecodeException(stripped, `Length should be a multiple of 4, but is ${length2}`)); +class RuntimeImpl { + context; + runtimeFlags; + fiberRefs; + constructor(context2, runtimeFlags2, fiberRefs3) { + this.context = context2; + this.runtimeFlags = runtimeFlags2; + this.fiberRefs = fiberRefs3; } - if (!/^[-_A-Z0-9]*?={0,2}$/i.test(stripped)) { - return left2(DecodeException(stripped, "Invalid input")); + pipe() { + return pipeArguments(this, arguments); } - let sanitized = length2 % 4 === 2 ? `${stripped}==` : length2 % 4 === 3 ? `${stripped}=` : stripped; - sanitized = sanitized.replace(/-/g, "+").replace(/_/g, "/"); - return decode2(sanitized); +} +var make37 = (options) => new RuntimeImpl(options.context, options.runtimeFlags, options.fiberRefs); +var runtime3 = () => withFiberRuntime((state, status) => succeed(new RuntimeImpl(state.getFiberRef(currentContext), status.runtimeFlags, state.getFiberRefs()))); +var defaultRuntimeFlags = /* @__PURE__ */ make16(Interruption, CooperativeYielding, RuntimeMetrics); +var defaultRuntime = /* @__PURE__ */ make37({ + context: /* @__PURE__ */ empty4(), + runtimeFlags: defaultRuntimeFlags, + fiberRefs: /* @__PURE__ */ empty19() +}); +var unsafeRunEffect = /* @__PURE__ */ unsafeRunCallback(defaultRuntime); +var unsafeForkEffect = /* @__PURE__ */ unsafeFork2(defaultRuntime); +var unsafeRunPromiseEffect = /* @__PURE__ */ unsafeRunPromise(defaultRuntime); +var unsafeRunPromiseExitEffect = /* @__PURE__ */ unsafeRunPromiseExit(defaultRuntime); +var unsafeRunSyncEffect = /* @__PURE__ */ unsafeRunSync(defaultRuntime); +var unsafeRunSyncExitEffect = /* @__PURE__ */ unsafeRunSyncExit(defaultRuntime); +var asyncEffect = (register) => suspend(() => { + let cleanup = undefined; + return flatMap7(deferredMake(), (deferred) => flatMap7(runtime3(), (runtime4) => uninterruptibleMask((restore) => zipRight(fork(restore(matchCauseEffect(register((cb) => unsafeRunCallback(runtime4)(intoDeferred(cb, deferred))), { + onFailure: (cause2) => deferredFailCause(deferred, cause2), + onSuccess: (cleanup_) => { + cleanup = cleanup_; + return void_; + } + }))), restore(onInterrupt(deferredAwait(deferred), () => cleanup ?? void_)))))); +}); + +// node_modules/effect/dist/esm/internal/synchronizedRef.js +var modifyEffect = /* @__PURE__ */ dual(2, (self, f) => self.modifyEffect(f)); + +// node_modules/effect/dist/esm/internal/layer.js +var LayerSymbolKey = "effect/Layer"; +var LayerTypeId = /* @__PURE__ */ Symbol.for(LayerSymbolKey); +var layerVariance = { + _RIn: (_) => _, + _E: (_) => _, + _ROut: (_) => _ +}; +var proto3 = { + [LayerTypeId]: layerVariance, + pipe() { + return pipeArguments(this, arguments); + } +}; +var MemoMapTypeIdKey = "effect/Layer/MemoMap"; +var MemoMapTypeId = /* @__PURE__ */ Symbol.for(MemoMapTypeIdKey); +var CurrentMemoMap = /* @__PURE__ */ Reference2()("effect/Layer/CurrentMemoMap", { + defaultValue: () => unsafeMakeMemoMap() +}); +var isLayer = (u) => hasProperty(u, LayerTypeId); +var isFresh = (self) => { + return self._op_layer === OP_FRESH; }; -// node_modules/effect/dist/esm/internal/encoding/hex.js -var encode3 = (bytes) => { - let result = ""; - for (let i = 0;i < bytes.length; ++i) { - result += bytesToHex[bytes[i]]; +class MemoMapImpl { + ref; + [MemoMapTypeId]; + constructor(ref) { + this.ref = ref; + this[MemoMapTypeId] = MemoMapTypeId; } - return result; -}; -var decode4 = (str) => { - const bytes = new TextEncoder().encode(str); - if (bytes.length % 2 !== 0) { - return left2(DecodeException(str, `Length must be a multiple of 2, but is ${bytes.length}`)); + getOrElseMemoize(layer, scope2) { + return pipe(modifyEffect(this.ref, (map10) => { + const inMap = map10.get(layer); + if (inMap !== undefined) { + const [acquire, release] = inMap; + const cached3 = pipe(acquire, flatMap7(([patch9, b]) => pipe(patchFiberRefs(patch9), as(b))), onExit(exitMatch({ + onFailure: () => void_, + onSuccess: () => scopeAddFinalizerExit(scope2, release) + }))); + return succeed([cached3, map10]); + } + return pipe(make23(0), flatMap7((observers) => pipe(deferredMake(), flatMap7((deferred) => pipe(make23(() => void_), map9((finalizerRef) => { + const resource = uninterruptibleMask((restore) => pipe(scopeMake(), flatMap7((innerScope) => pipe(restore(flatMap7(makeBuilder(layer, innerScope, true), (f) => diffFiberRefs(f(this)))), exit, flatMap7((exit2) => { + switch (exit2._tag) { + case OP_FAILURE: { + return pipe(deferredFailCause(deferred, exit2.effect_instruction_i0), zipRight(scopeClose(innerScope, exit2)), zipRight(failCause(exit2.effect_instruction_i0))); + } + case OP_SUCCESS: { + return pipe(set4(finalizerRef, (exit3) => pipe(scopeClose(innerScope, exit3), whenEffect(modify3(observers, (n) => [n === 1, n - 1])), asVoid)), zipRight(update2(observers, (n) => n + 1)), zipRight(scopeAddFinalizerExit(scope2, (exit3) => pipe(sync(() => map10.delete(layer)), zipRight(get10(finalizerRef)), flatMap7((finalizer) => finalizer(exit3))))), zipRight(deferredSucceed(deferred, exit2.effect_instruction_i0)), as(exit2.effect_instruction_i0[1])); + } + } + }))))); + const memoized = [pipe(deferredAwait(deferred), onExit(exitMatchEffect({ + onFailure: () => void_, + onSuccess: () => update2(observers, (n) => n + 1) + }))), (exit2) => pipe(get10(finalizerRef), flatMap7((finalizer) => finalizer(exit2)))]; + return [resource, isFresh(layer) ? map10 : map10.set(layer, memoized)]; + })))))); + }), flatten4); } - try { - const length2 = bytes.length / 2; - const result = new Uint8Array(length2); - for (let i = 0;i < length2; i++) { - const a = fromHexChar(bytes[i * 2]); - const b = fromHexChar(bytes[i * 2 + 1]); - result[i] = a << 4 | b; +} +var makeMemoMap = /* @__PURE__ */ suspend(() => map9(makeSynchronized(new Map), (ref) => new MemoMapImpl(ref))); +var unsafeMakeMemoMap = () => new MemoMapImpl(unsafeMakeSynchronized(new Map)); +var buildWithScope = /* @__PURE__ */ dual(2, (self, scope2) => flatMap7(makeMemoMap, (memoMap) => buildWithMemoMap(self, memoMap, scope2))); +var buildWithMemoMap = /* @__PURE__ */ dual(3, (self, memoMap, scope2) => flatMap7(makeBuilder(self, scope2), (run) => provideService(run(memoMap), CurrentMemoMap, memoMap))); +var makeBuilder = (self, scope2, inMemoMap = false) => { + const op = self; + switch (op._op_layer) { + case "Locally": { + return sync(() => (memoMap) => op.f(memoMap.getOrElseMemoize(op.self, scope2))); + } + case "ExtendScope": { + return sync(() => (memoMap) => scopeWith((scope3) => memoMap.getOrElseMemoize(op.layer, scope3))); + } + case "Fold": { + return sync(() => (memoMap) => pipe(memoMap.getOrElseMemoize(op.layer, scope2), matchCauseEffect({ + onFailure: (cause2) => memoMap.getOrElseMemoize(op.failureK(cause2), scope2), + onSuccess: (value) => memoMap.getOrElseMemoize(op.successK(value), scope2) + }))); + } + case "Fresh": { + return sync(() => (_) => pipe(op.layer, buildWithScope(scope2))); + } + case "FromEffect": { + return inMemoMap ? sync(() => (_) => op.effect) : sync(() => (memoMap) => memoMap.getOrElseMemoize(self, scope2)); + } + case "Provide": { + return sync(() => (memoMap) => pipe(memoMap.getOrElseMemoize(op.first, scope2), flatMap7((env) => pipe(memoMap.getOrElseMemoize(op.second, scope2), provideContext(env))))); + } + case "Scoped": { + return inMemoMap ? sync(() => (_) => scopeExtend(op.effect, scope2)) : sync(() => (memoMap) => memoMap.getOrElseMemoize(self, scope2)); + } + case "Suspend": { + return sync(() => (memoMap) => memoMap.getOrElseMemoize(op.evaluate(), scope2)); + } + case "ProvideMerge": { + return sync(() => (memoMap) => pipe(memoMap.getOrElseMemoize(op.first, scope2), zipWith2(memoMap.getOrElseMemoize(op.second, scope2), op.zipK))); + } + case "ZipWith": { + return gen(function* () { + const parallelScope = yield* scopeFork(scope2, parallel2); + const firstScope = yield* scopeFork(parallelScope, sequential2); + const secondScope = yield* scopeFork(parallelScope, sequential2); + return (memoMap) => pipe(memoMap.getOrElseMemoize(op.first, firstScope), zipWithOptions(memoMap.getOrElseMemoize(op.second, secondScope), op.zipK, { + concurrent: true + })); + }); + } + case "MergeAll": { + const layers = op.layers; + return map9(scopeFork(scope2, parallel2), (parallelScope) => (memoMap) => { + const contexts = new Array(layers.length); + return map9(forEachConcurrentDiscard(layers, fnUntraced(function* (layer, i) { + const scope3 = yield* scopeFork(parallelScope, sequential2); + const context2 = yield* memoMap.getOrElseMemoize(layer, scope3); + contexts[i] = context2; + }), false, false), () => mergeAll2(...contexts)); + }); } - return right2(result); - } catch (e) { - return left2(DecodeException(str, e instanceof Error ? e.message : "Invalid input")); } }; -var bytesToHex = ["00", "01", "02", "03", "04", "05", "06", "07", "08", "09", "0a", "0b", "0c", "0d", "0e", "0f", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "1a", "1b", "1c", "1d", "1e", "1f", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "2a", "2b", "2c", "2d", "2e", "2f", "30", "31", "32", "33", "34", "35", "36", "37", "38", "39", "3a", "3b", "3c", "3d", "3e", "3f", "40", "41", "42", "43", "44", "45", "46", "47", "48", "49", "4a", "4b", "4c", "4d", "4e", "4f", "50", "51", "52", "53", "54", "55", "56", "57", "58", "59", "5a", "5b", "5c", "5d", "5e", "5f", "60", "61", "62", "63", "64", "65", "66", "67", "68", "69", "6a", "6b", "6c", "6d", "6e", "6f", "70", "71", "72", "73", "74", "75", "76", "77", "78", "79", "7a", "7b", "7c", "7d", "7e", "7f", "80", "81", "82", "83", "84", "85", "86", "87", "88", "89", "8a", "8b", "8c", "8d", "8e", "8f", "90", "91", "92", "93", "94", "95", "96", "97", "98", "99", "9a", "9b", "9c", "9d", "9e", "9f", "a0", "a1", "a2", "a3", "a4", "a5", "a6", "a7", "a8", "a9", "aa", "ab", "ac", "ad", "ae", "af", "b0", "b1", "b2", "b3", "b4", "b5", "b6", "b7", "b8", "b9", "ba", "bb", "bc", "bd", "be", "bf", "c0", "c1", "c2", "c3", "c4", "c5", "c6", "c7", "c8", "c9", "ca", "cb", "cc", "cd", "ce", "cf", "d0", "d1", "d2", "d3", "d4", "d5", "d6", "d7", "d8", "d9", "da", "db", "dc", "dd", "de", "df", "e0", "e1", "e2", "e3", "e4", "e5", "e6", "e7", "e8", "e9", "ea", "eb", "ec", "ed", "ee", "ef", "f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7", "f8", "f9", "fa", "fb", "fc", "fd", "fe", "ff"]; -var fromHexChar = (byte) => { - if (48 <= byte && byte <= 57) { - return byte - 48; - } - if (97 <= byte && byte <= 102) { - return byte - 97 + 10; - } - if (65 <= byte && byte <= 70) { - return byte - 65 + 10; - } - throw new TypeError("Invalid input"); +var context2 = () => fromEffectContext(context()); +var fromEffect2 = /* @__PURE__ */ dual(2, (a, b) => { + const tagFirst = isTag2(a); + const tag = tagFirst ? a : b; + const effect = tagFirst ? b : a; + return fromEffectContext(map9(effect, (service) => make6(tag, service))); +}); +function fromEffectContext(effect) { + const fromEffect3 = Object.create(proto3); + fromEffect3._op_layer = OP_FROM_EFFECT; + fromEffect3.effect = effect; + return fromEffect3; +} +var mergeAll4 = (...layers) => { + const mergeAll5 = Object.create(proto3); + mergeAll5._op_layer = OP_MERGE_ALL; + mergeAll5.layers = layers; + return mergeAll5; }; - -// node_modules/effect/dist/esm/Encoding.js -var encodeBase64 = (input) => typeof input === "string" ? encode(encoder.encode(input)) : encode(input); -var decodeBase64 = (str) => decode2(str); -var decodeBase64String = (str) => map(decodeBase64(str), (_) => decoder.decode(_)); -var encodeBase64Url = (input) => typeof input === "string" ? encode2(encoder.encode(input)) : encode2(input); -var decodeBase64Url = (str) => decode3(str); -var decodeBase64UrlString = (str) => map(decodeBase64Url(str), (_) => decoder.decode(_)); -var encodeHex = (input) => typeof input === "string" ? encode3(encoder.encode(input)) : encode3(input); -var decodeHex = (str) => decode4(str); -var decodeHexString = (str) => map(decodeHex(str), (_) => decoder.decode(_)); -var encodeUriComponent = (str) => try_({ - try: () => encodeURIComponent(str), - catch: (e) => EncodeException2(str, e instanceof Error ? e.message : "Invalid input") +var scoped = /* @__PURE__ */ dual(2, (a, b) => { + const tagFirst = isTag2(a); + const tag = tagFirst ? a : b; + const effect = tagFirst ? b : a; + return scopedContext(map9(effect, (service) => make6(tag, service))); }); -var decodeUriComponent = (str) => try_({ - try: () => decodeURIComponent(str), - catch: (e) => DecodeException2(str, e instanceof Error ? e.message : "Invalid input") +var scopedContext = (effect) => { + const scoped2 = Object.create(proto3); + scoped2._op_layer = OP_SCOPED; + scoped2.effect = effect; + return scoped2; +}; +var succeed4 = /* @__PURE__ */ dual(2, (a, b) => { + const tagFirst = isTag2(a); + const tag = tagFirst ? a : b; + const resource = tagFirst ? b : a; + return fromEffectContext(succeed(make6(tag, resource))); }); -var DecodeException2 = DecodeException; -var EncodeException2 = EncodeException; -// node_modules/effect/dist/esm/ParseResult.js -class Pointer { - path; - actual; - issue; - _tag = "Pointer"; - constructor(path, actual, issue) { - this.path = path; - this.actual = actual; - this.issue = issue; - } -} - -class Unexpected { - actual; - message; - _tag = "Unexpected"; - constructor(actual, message) { - this.actual = actual; - this.message = message; - } -} - -class Missing { - ast; - message; - _tag = "Missing"; - actual = undefined; - constructor(ast, message) { - this.ast = ast; - this.message = message; - } -} - -class Composite2 { - ast; - actual; - issues; - output; - _tag = "Composite"; - constructor(ast, actual, issues, output) { - this.ast = ast; - this.actual = actual; - this.issues = issues; - this.output = output; +var suspend2 = (evaluate2) => { + const suspend3 = Object.create(proto3); + suspend3._op_layer = OP_SUSPEND; + suspend3.evaluate = evaluate2; + return suspend3; +}; +var sync2 = /* @__PURE__ */ dual(2, (a, b) => { + const tagFirst = isTag2(a); + const tag = tagFirst ? a : b; + const evaluate2 = tagFirst ? b : a; + return fromEffectContext(sync(() => make6(tag, evaluate2()))); +}); +var provide = /* @__PURE__ */ dual(2, (self, that) => suspend2(() => { + const provideTo = Object.create(proto3); + provideTo._op_layer = OP_PROVIDE; + provideTo.first = Object.create(proto3, { + _op_layer: { + value: OP_PROVIDE_MERGE, + enumerable: true + }, + first: { + value: context2(), + enumerable: true + }, + second: { + value: Array.isArray(that) ? mergeAll4(...that) : that + }, + zipK: { + value: (a, b) => pipe(a, merge3(b)) + } + }); + provideTo.second = self; + return provideTo; +})); +var provideSomeLayer = /* @__PURE__ */ dual(2, (self, layer) => scopedWith((scope2) => flatMap7(buildWithScope(layer, scope2), (context3) => provideSomeContext(self, context3)))); +var provideSomeRuntime = /* @__PURE__ */ dual(2, (self, rt) => { + const patchRefs = diff6(defaultRuntime.fiberRefs, rt.fiberRefs); + const patchFlags = diff4(defaultRuntime.runtimeFlags, rt.runtimeFlags); + return uninterruptibleMask((restore) => withFiberRuntime((fiber) => { + const oldContext = fiber.getFiberRef(currentContext); + const oldRefs = fiber.getFiberRefs(); + const newRefs = patch7(fiber.id(), oldRefs)(patchRefs); + const oldFlags = fiber.currentRuntimeFlags; + const newFlags = patch4(patchFlags)(oldFlags); + const rollbackRefs = diff6(newRefs, oldRefs); + const rollbackFlags = diff4(newFlags, oldFlags); + fiber.setFiberRefs(newRefs); + fiber.currentRuntimeFlags = newFlags; + return ensuring(provideSomeContext(restore(self), merge3(oldContext, rt.context)), withFiberRuntime((fiber2) => { + fiber2.setFiberRefs(patch7(fiber2.id(), fiber2.getFiberRefs())(rollbackRefs)); + fiber2.currentRuntimeFlags = patch4(rollbackFlags)(fiber2.currentRuntimeFlags); + return void_; + })); + })); +}); +var effect_provide = /* @__PURE__ */ dual(2, (self, source) => { + if (Array.isArray(source)) { + return provideSomeLayer(self, mergeAll4(...source)); + } else if (isLayer(source)) { + return provideSomeLayer(self, source); + } else if (isContext2(source)) { + return provideSomeContext(self, source); + } else if (TypeId13 in source) { + return flatMap7(source.runtimeEffect, (rt) => provideSomeRuntime(self, rt)); + } else { + return provideSomeRuntime(self, source); } -} +}); -class Refinement2 { - ast; - actual; - kind; - issue; - _tag = "Refinement"; - constructor(ast, actual, kind, issue) { - this.ast = ast; - this.actual = actual; - this.kind = kind; - this.issue = issue; - } -} +// node_modules/effect/dist/esm/internal/console.js +var console2 = /* @__PURE__ */ map9(/* @__PURE__ */ fiberRefGet(currentServices), /* @__PURE__ */ get4(consoleTag)); +var consoleWith = (f) => fiberRefGetWith(currentServices, (services) => f(get4(services, consoleTag))); +var withConsole = /* @__PURE__ */ dual(2, (effect, value) => fiberRefLocallyWith(effect, currentServices, add2(consoleTag, value))); +var withConsoleScoped = (console3) => fiberRefLocallyScopedWith(currentServices, add2(consoleTag, console3)); -class Transformation2 { - ast; - actual; - kind; - issue; - _tag = "Transformation"; - constructor(ast, actual, kind, issue) { - this.ast = ast; - this.actual = actual; - this.kind = kind; - this.issue = issue; +// node_modules/effect/dist/esm/internal/dateTime.js +var TypeId14 = /* @__PURE__ */ Symbol.for("effect/DateTime"); +var TimeZoneTypeId = /* @__PURE__ */ Symbol.for("effect/DateTime/TimeZone"); +var Proto2 = { + [TypeId14]: TypeId14, + pipe() { + return pipeArguments(this, arguments); + }, + [NodeInspectSymbol]() { + return this.toString(); + }, + toJSON() { + return toDateUtc(this).toJSON(); } -} - -class Type2 { - ast; - actual; - message; - _tag = "Type"; - constructor(ast, actual, message) { - this.ast = ast; - this.actual = actual; - this.message = message; +}; +var ProtoUtc = { + ...Proto2, + _tag: "Utc", + [symbol]() { + return cached(this, number2(this.epochMillis)); + }, + [symbol2](that) { + return isDateTime(that) && that._tag === "Utc" && this.epochMillis === that.epochMillis; + }, + toString() { + return `DateTime.Utc(${toDateUtc(this).toJSON()})`; } -} - -class Forbidden { - ast; - actual; - message; - _tag = "Forbidden"; - constructor(ast, actual, message) { - this.ast = ast; - this.actual = actual; - this.message = message; +}; +var ProtoZoned = { + ...Proto2, + _tag: "Zoned", + [symbol]() { + return pipe(number2(this.epochMillis), combine(hash(this.zone)), cached(this)); + }, + [symbol2](that) { + return isDateTime(that) && that._tag === "Zoned" && this.epochMillis === that.epochMillis && equals(this.zone, that.zone); + }, + toString() { + return `DateTime.Zoned(${formatIsoZoned(this)})`; } -} -var ParseErrorTypeId = /* @__PURE__ */ Symbol.for("effect/Schema/ParseErrorTypeId"); -class ParseError extends (/* @__PURE__ */ TaggedError("ParseError")) { - [ParseErrorTypeId] = ParseErrorTypeId; - get message() { +}; +var ProtoTimeZone = { + [TimeZoneTypeId]: TimeZoneTypeId, + [NodeInspectSymbol]() { return this.toString(); } +}; +var ProtoTimeZoneNamed = { + ...ProtoTimeZone, + _tag: "Named", + [symbol]() { + return cached(this, string(`Named:${this.id}`)); + }, + [symbol2](that) { + return isTimeZone(that) && that._tag === "Named" && this.id === that.id; + }, toString() { - return TreeFormatter.formatIssueSync(this.issue); + return `TimeZone.Named(${this.id})`; + }, + toJSON() { + return { + _id: "TimeZone", + _tag: "Named", + id: this.id + }; } +}; +var ProtoTimeZoneOffset = { + ...ProtoTimeZone, + _tag: "Offset", + [symbol]() { + return cached(this, string(`Offset:${this.offset}`)); + }, + [symbol2](that) { + return isTimeZone(that) && that._tag === "Offset" && this.offset === that.offset; + }, + toString() { + return `TimeZone.Offset(${offsetToString(this.offset)})`; + }, toJSON() { return { - _id: "ParseError", - message: this.toString() + _id: "TimeZone", + _tag: "Offset", + offset: this.offset }; } - [NodeInspectSymbol]() { - return this.toJSON(); +}; +var makeZonedProto = (epochMillis, zone, partsUtc) => { + const self = Object.create(ProtoZoned); + self.epochMillis = epochMillis; + self.zone = zone; + Object.defineProperty(self, "partsUtc", { + value: partsUtc, + enumerable: false, + writable: true + }); + Object.defineProperty(self, "adjustedEpochMillis", { + value: undefined, + enumerable: false, + writable: true + }); + Object.defineProperty(self, "partsAdjusted", { + value: undefined, + enumerable: false, + writable: true + }); + return self; +}; +var isDateTime = (u) => hasProperty(u, TypeId14); +var isTimeZone = (u) => hasProperty(u, TimeZoneTypeId); +var isTimeZoneOffset = (u) => isTimeZone(u) && u._tag === "Offset"; +var isTimeZoneNamed = (u) => isTimeZone(u) && u._tag === "Named"; +var isUtc = (self) => self._tag === "Utc"; +var isZoned = (self) => self._tag === "Zoned"; +var Equivalence2 = /* @__PURE__ */ make((a, b) => a.epochMillis === b.epochMillis); +var makeUtc = (epochMillis) => { + const self = Object.create(ProtoUtc); + self.epochMillis = epochMillis; + Object.defineProperty(self, "partsUtc", { + value: undefined, + enumerable: false, + writable: true + }); + return self; +}; +var unsafeFromDate = (date) => { + const epochMillis = date.getTime(); + if (Number.isNaN(epochMillis)) { + throw new IllegalArgumentException2("Invalid date"); + } + return makeUtc(epochMillis); +}; +var unsafeMake7 = (input) => { + if (isDateTime(input)) { + return input; + } else if (input instanceof Date) { + return unsafeFromDate(input); + } else if (typeof input === "object") { + const date = new Date(0); + setPartsDate(date, input); + return unsafeFromDate(date); + } else if (typeof input === "string" && !hasZone(input)) { + return unsafeFromDate(new Date(input + "Z")); + } + return unsafeFromDate(new Date(input)); +}; +var hasZone = (input) => /Z|[+-]\d{2}$|[+-]\d{2}:?\d{2}$|\]$/.test(input); +var minEpochMillis = -8640000000000000 + 12 * 60 * 60 * 1000; +var maxEpochMillis = 8640000000000000 - 14 * 60 * 60 * 1000; +var unsafeMakeZoned = (input, options) => { + if (options?.timeZone === undefined && isDateTime(input) && isZoned(input)) { + return input; + } + const self = unsafeMake7(input); + if (self.epochMillis < minEpochMillis || self.epochMillis > maxEpochMillis) { + throw new RangeError(`Epoch millis out of range: ${self.epochMillis}`); + } + let zone; + if (options?.timeZone === undefined) { + const offset = new Date(self.epochMillis).getTimezoneOffset() * -60 * 1000; + zone = zoneMakeOffset(offset); + } else if (isTimeZone(options?.timeZone)) { + zone = options.timeZone; + } else if (typeof options?.timeZone === "number") { + zone = zoneMakeOffset(options.timeZone); + } else { + const parsedZone = zoneFromString(options.timeZone); + if (isNone2(parsedZone)) { + throw new IllegalArgumentException2(`Invalid time zone: ${options.timeZone}`); + } + zone = parsedZone.value; + } + if (options?.adjustForTimeZone !== true) { + return makeZonedProto(self.epochMillis, zone, self.partsUtc); + } + return makeZonedFromAdjusted(self.epochMillis, zone, options?.disambiguation ?? "compatible"); +}; +var makeZoned = /* @__PURE__ */ liftThrowable(unsafeMakeZoned); +var zonedStringRegex = /^(.{17,35})\[(.+)\]$/; +var makeZonedFromString = (input) => { + const match10 = zonedStringRegex.exec(input); + if (match10 === null) { + const offset = parseOffset(input); + return offset !== null ? makeZoned(input, { + timeZone: offset + }) : none2(); + } + const [, isoString, timeZone] = match10; + return makeZoned(isoString, { + timeZone + }); +}; +var validZoneCache = /* @__PURE__ */ globalValue("effect/DateTime/validZoneCache", () => new Map); +var formatOptions = { + day: "numeric", + month: "numeric", + year: "numeric", + hour: "numeric", + minute: "numeric", + second: "numeric", + timeZoneName: "longOffset", + fractionalSecondDigits: 3, + hourCycle: "h23" +}; +var zoneMakeIntl = (format4) => { + const zoneId = format4.resolvedOptions().timeZone; + if (validZoneCache.has(zoneId)) { + return validZoneCache.get(zoneId); } -} -var parseError = (issue) => new ParseError({ - issue -}); -var succeed8 = right2; -var fail7 = left2; -var _try = try_; -var fromOption3 = fromOption2; -var isEither3 = isEither2; -var flatMap10 = /* @__PURE__ */ dual(2, (self, f) => { - return isEither3(self) ? match(self, { - onLeft: left2, - onRight: f - }) : flatMap9(self, f); -}); -var map13 = /* @__PURE__ */ dual(2, (self, f) => { - return isEither3(self) ? map(self, f) : map11(self, f); -}); -var mapError3 = /* @__PURE__ */ dual(2, (self, f) => { - return isEither3(self) ? mapLeft(self, f) : mapError2(self, f); -}); -var mapBoth4 = /* @__PURE__ */ dual(2, (self, options) => { - return isEither3(self) ? mapBoth(self, { - onLeft: options.onFailure, - onRight: options.onSuccess - }) : mapBoth3(self, options); -}); -var orElse5 = /* @__PURE__ */ dual(2, (self, f) => { - return isEither3(self) ? match(self, { - onLeft: f, - onRight: right2 - }) : catchAll2(self, f); -}); -var mergeInternalOptions = (options, overrideOptions) => { - if (overrideOptions === undefined || isNumber(overrideOptions)) { - return options; + const zone = Object.create(ProtoTimeZoneNamed); + zone.id = zoneId; + zone.format = format4; + validZoneCache.set(zoneId, zone); + return zone; +}; +var zoneUnsafeMakeNamed = (zoneId) => { + if (validZoneCache.has(zoneId)) { + return validZoneCache.get(zoneId); } - if (options === undefined) { - return overrideOptions; + try { + return zoneMakeIntl(new Intl.DateTimeFormat("en-US", { + ...formatOptions, + timeZone: zoneId + })); + } catch { + throw new IllegalArgumentException2(`Invalid time zone: ${zoneId}`); } - return { - ...options, - ...overrideOptions - }; }; -var getEither = (ast, isDecoding, options) => { - const parser = goMemo(ast, isDecoding); - return (u, overrideOptions) => parser(u, mergeInternalOptions(options, overrideOptions)); +var zoneMakeOffset = (offset) => { + const zone = Object.create(ProtoTimeZoneOffset); + zone.offset = offset; + return zone; }; -var getSync = (ast, isDecoding, options) => { - const parser = getEither(ast, isDecoding, options); - return (input, overrideOptions) => getOrThrowWith(parser(input, overrideOptions), parseError); +var zoneMakeNamed = /* @__PURE__ */ liftThrowable(zoneUnsafeMakeNamed); +var offsetZoneRegex = /^(?:GMT|[+-])/; +var zoneFromString = (zone) => { + if (offsetZoneRegex.test(zone)) { + const offset = parseOffset(zone); + return offset === null ? none2() : some2(zoneMakeOffset(offset)); + } + return zoneMakeNamed(zone); }; -var getOption3 = (ast, isDecoding, options) => { - const parser = getEither(ast, isDecoding, options); - return (input, overrideOptions) => getRight2(parser(input, overrideOptions)); +var zoneToString = (self) => { + if (self._tag === "Offset") { + return offsetToString(self.offset); + } + return self.id; }; -var getEffect = (ast, isDecoding, options) => { - const parser = goMemo(ast, isDecoding); - return (input, overrideOptions) => parser(input, { - ...mergeInternalOptions(options, overrideOptions), - isEffectAllowed: true - }); +var toDateUtc = (self) => new Date(self.epochMillis); +var toDate = (self) => { + if (self._tag === "Utc") { + return new Date(self.epochMillis); + } else if (self.zone._tag === "Offset") { + return new Date(self.epochMillis + self.zone.offset); + } else if (self.adjustedEpochMillis !== undefined) { + return new Date(self.adjustedEpochMillis); + } + const parts2 = self.zone.format.formatToParts(self.epochMillis).filter((_) => _.type !== "literal"); + const date = new Date(0); + date.setUTCFullYear(Number(parts2[2].value), Number(parts2[0].value) - 1, Number(parts2[1].value)); + date.setUTCHours(Number(parts2[3].value), Number(parts2[4].value), Number(parts2[5].value), Number(parts2[6].value)); + self.adjustedEpochMillis = date.getTime(); + return date; }; -var decodeUnknownSync = (schema, options) => getSync(schema.ast, true, options); -var decodeUnknownOption = (schema, options) => getOption3(schema.ast, true, options); -var decodeUnknownEither = (schema, options) => getEither(schema.ast, true, options); -var decodeUnknown = (schema, options) => getEffect(schema.ast, true, options); -var encodeUnknownSync = (schema, options) => getSync(schema.ast, false, options); -var encodeUnknownOption = (schema, options) => getOption3(schema.ast, false, options); -var encodeUnknownEither = (schema, options) => getEither(schema.ast, false, options); -var encodeUnknown = (schema, options) => getEffect(schema.ast, false, options); -var decodeSync = decodeUnknownSync; -var decodeOption = decodeUnknownOption; -var validateSync = (schema, options) => getSync(typeAST(schema.ast), true, options); -var validateOption = (schema, options) => getOption3(typeAST(schema.ast), true, options); -var validateEither = (schema, options) => getEither(typeAST(schema.ast), true, options); -var validate4 = (schema, options) => getEffect(typeAST(schema.ast), true, options); -var is = (schema, options) => { - const parser = goMemo(typeAST(schema.ast), true); - return (u, overrideOptions) => isRight2(parser(u, { - exact: true, - ...mergeInternalOptions(options, overrideOptions) - })); +var zonedOffset = (self) => { + const date = toDate(self); + return date.getTime() - toEpochMillis(self); }; -var asserts = (schema, options) => { - const parser = goMemo(typeAST(schema.ast), true); - return (u, overrideOptions) => { - const result = parser(u, { - exact: true, - ...mergeInternalOptions(options, overrideOptions) - }); - if (isLeft2(result)) { - throw parseError(result.left); - } - }; +var offsetToString = (offset) => { + const abs = Math.abs(offset); + let hours2 = Math.floor(abs / (60 * 60 * 1000)); + let minutes2 = Math.round(abs % (60 * 60 * 1000) / (60 * 1000)); + if (minutes2 === 60) { + hours2 += 1; + minutes2 = 0; + } + return `${offset < 0 ? "-" : "+"}${String(hours2).padStart(2, "0")}:${String(minutes2).padStart(2, "0")}`; }; -var encodeSync = encodeUnknownSync; -var encodeOption = encodeUnknownOption; -var decodeMemoMap = /* @__PURE__ */ globalValue(/* @__PURE__ */ Symbol.for("effect/ParseResult/decodeMemoMap"), () => new WeakMap); -var encodeMemoMap = /* @__PURE__ */ globalValue(/* @__PURE__ */ Symbol.for("effect/ParseResult/encodeMemoMap"), () => new WeakMap); -var goMemo = (ast, isDecoding) => { - const memoMap = isDecoding ? decodeMemoMap : encodeMemoMap; - const memo = memoMap.get(ast); - if (memo) { - return memo; +var zonedOffsetIso = (self) => offsetToString(zonedOffset(self)); +var toEpochMillis = (self) => self.epochMillis; +var setPartsDate = (date, parts2) => { + if (parts2.year !== undefined) { + date.setUTCFullYear(parts2.year); + } + if (parts2.month !== undefined) { + date.setUTCMonth(parts2.month - 1); + } + if (parts2.day !== undefined) { + date.setUTCDate(parts2.day); + } + if (parts2.weekDay !== undefined) { + const diff8 = parts2.weekDay - date.getUTCDay(); + date.setUTCDate(date.getUTCDate() + diff8); + } + if (parts2.hours !== undefined) { + date.setUTCHours(parts2.hours); + } + if (parts2.minutes !== undefined) { + date.setUTCMinutes(parts2.minutes); + } + if (parts2.seconds !== undefined) { + date.setUTCSeconds(parts2.seconds); + } + if (parts2.millis !== undefined) { + date.setUTCMilliseconds(parts2.millis); } - const raw = go(ast, isDecoding); - const parseOptionsAnnotation = getParseOptionsAnnotation(ast); - const parserWithOptions = isSome2(parseOptionsAnnotation) ? (i, options) => raw(i, mergeInternalOptions(options, parseOptionsAnnotation.value)) : raw; - const decodingFallbackAnnotation = getDecodingFallbackAnnotation(ast); - const parser = isDecoding && isSome2(decodingFallbackAnnotation) ? (i, options) => handleForbidden(orElse5(parserWithOptions(i, options), decodingFallbackAnnotation.value), ast, i, options) : parserWithOptions; - memoMap.set(ast, parser); - return parser; }; -var getConcurrency = (ast) => getOrUndefined(getConcurrencyAnnotation(ast)); -var getBatching = (ast) => getOrUndefined(getBatchingAnnotation(ast)); -var go = (ast, isDecoding) => { - switch (ast._tag) { - case "Refinement": { - if (isDecoding) { - const from = goMemo(ast.from, true); - return (i, options) => { - options = options ?? defaultParseOption; - const allErrors = options?.errors === "all"; - const result = flatMap10(orElse5(from(i, options), (ef) => { - const issue = new Refinement2(ast, i, "From", ef); - if (allErrors && hasStableFilter(ast) && isComposite2(ef)) { - return match2(ast.filter(i, options, ast), { - onNone: () => left2(issue), - onSome: (ep) => left2(new Composite2(ast, i, [issue, new Refinement2(ast, i, "Predicate", ep)])) - }); - } - return left2(issue); - }), (a) => match2(ast.filter(a, options, ast), { - onNone: () => right2(a), - onSome: (ep) => left2(new Refinement2(ast, i, "Predicate", ep)) - })); - return handleForbidden(result, ast, i, options); - }; - } else { - const from = goMemo(typeAST(ast), true); - const to = goMemo(dropRightRefinement(ast.from), false); - return (i, options) => handleForbidden(flatMap10(from(i, options), (a) => to(a, options)), ast, i, options); +var constDayMillis = 24 * 60 * 60 * 1000; +var makeZonedFromAdjusted = (adjustedMillis, zone, disambiguation) => { + if (zone._tag === "Offset") { + return makeZonedProto(adjustedMillis - zone.offset, zone); + } + const beforeOffset = calculateNamedOffset(adjustedMillis - constDayMillis, adjustedMillis, zone); + const afterOffset = calculateNamedOffset(adjustedMillis + constDayMillis, adjustedMillis, zone); + if (beforeOffset === afterOffset) { + return makeZonedProto(adjustedMillis - beforeOffset, zone); + } + const isForwards = beforeOffset < afterOffset; + const transitionMillis = beforeOffset - afterOffset; + if (isForwards) { + const currentAfterOffset = calculateNamedOffset(adjustedMillis - afterOffset, adjustedMillis, zone); + if (currentAfterOffset === afterOffset) { + return makeZonedProto(adjustedMillis - afterOffset, zone); + } + const before2 = makeZonedProto(adjustedMillis - beforeOffset, zone); + const beforeAdjustedMillis = toDate(before2).getTime(); + if (adjustedMillis !== beforeAdjustedMillis) { + switch (disambiguation) { + case "reject": { + const formatted = new Date(adjustedMillis).toISOString(); + throw new RangeError(`Gap time: ${formatted} does not exist in time zone ${zone.id}`); + } + case "earlier": + return makeZonedProto(adjustedMillis - afterOffset, zone); + case "compatible": + case "later": + return before2; } } - case "Transformation": { - const transform2 = getFinalTransformation(ast.transformation, isDecoding); - const from = isDecoding ? goMemo(ast.from, true) : goMemo(ast.to, false); - const to = isDecoding ? goMemo(ast.to, true) : goMemo(ast.from, false); - return (i, options) => handleForbidden(flatMap10(mapError3(from(i, options), (e) => new Transformation2(ast, i, isDecoding ? "Encoded" : "Type", e)), (a) => flatMap10(mapError3(transform2(a, options ?? defaultParseOption, ast, i), (e) => new Transformation2(ast, i, "Transformation", e)), (i2) => mapError3(to(i2, options), (e) => new Transformation2(ast, i, isDecoding ? "Type" : "Encoded", e)))), ast, i, options); + return before2; + } + const currentBeforeOffset = calculateNamedOffset(adjustedMillis - beforeOffset, adjustedMillis, zone); + if (currentBeforeOffset === beforeOffset) { + if (disambiguation === "earlier" || disambiguation === "compatible") { + return makeZonedProto(adjustedMillis - beforeOffset, zone); } - case "Declaration": { - const parse2 = isDecoding ? ast.decodeUnknown(...ast.typeParameters) : ast.encodeUnknown(...ast.typeParameters); - return (i, options) => handleForbidden(parse2(i, options ?? defaultParseOption, ast), ast, i, options); + const laterOffset = calculateNamedOffset(adjustedMillis - beforeOffset + transitionMillis, adjustedMillis + transitionMillis, zone); + if (laterOffset === beforeOffset) { + return makeZonedProto(adjustedMillis - beforeOffset, zone); } - case "Literal": - return fromRefinement(ast, (u) => u === ast.literal); - case "UniqueSymbol": - return fromRefinement(ast, (u) => u === ast.symbol); - case "UndefinedKeyword": - return fromRefinement(ast, isUndefined); - case "NeverKeyword": - return fromRefinement(ast, isNever); - case "UnknownKeyword": - case "AnyKeyword": - case "VoidKeyword": - return right2; - case "StringKeyword": - return fromRefinement(ast, isString); - case "NumberKeyword": - return fromRefinement(ast, isNumber); - case "BooleanKeyword": - return fromRefinement(ast, isBoolean); - case "BigIntKeyword": - return fromRefinement(ast, isBigInt); - case "SymbolKeyword": - return fromRefinement(ast, isSymbol); - case "ObjectKeyword": - return fromRefinement(ast, isObject); - case "Enums": - return fromRefinement(ast, (u) => ast.enums.some(([_, value2]) => value2 === u)); - case "TemplateLiteral": { - const regex = getTemplateLiteralRegExp(ast); - return fromRefinement(ast, (u) => isString(u) && regex.test(u)); + if (disambiguation === "reject") { + const formatted = new Date(adjustedMillis).toISOString(); + throw new RangeError(`Ambiguous time: ${formatted} occurs twice in time zone ${zone.id}`); } - case "TupleType": { - const elements = ast.elements.map((e) => goMemo(e.type, isDecoding)); - const rest = ast.rest.map((annotatedAST) => goMemo(annotatedAST.type, isDecoding)); - let requiredTypes = ast.elements.filter((e) => !e.isOptional); - if (ast.rest.length > 0) { - requiredTypes = requiredTypes.concat(ast.rest.slice(1)); - } - const requiredLen = requiredTypes.length; - const expectedIndexes = ast.elements.length > 0 ? ast.elements.map((_, i) => i).join(" | ") : "never"; - const concurrency = getConcurrency(ast); - const batching = getBatching(ast); - return (input, options) => { - if (!isArray(input)) { - return left2(new Type2(ast, input)); - } - const allErrors = options?.errors === "all"; - const es = []; - let stepKey = 0; - const output = []; - const len = input.length; - for (let i2 = len;i2 <= requiredLen - 1; i2++) { - const e = new Pointer(i2, input, new Missing(requiredTypes[i2 - len])); - if (allErrors) { - es.push([stepKey++, e]); - continue; - } else { - return left2(new Composite2(ast, input, e, output)); - } - } - if (ast.rest.length === 0) { - for (let i2 = ast.elements.length;i2 <= len - 1; i2++) { - const e = new Pointer(i2, input, new Unexpected(input[i2], `is unexpected, expected: ${expectedIndexes}`)); - if (allErrors) { - es.push([stepKey++, e]); - continue; - } else { - return left2(new Composite2(ast, input, e, output)); - } - } - } - let i = 0; - let queue = undefined; - for (;i < elements.length; i++) { - if (len < i + 1) { - if (ast.elements[i].isOptional) { - continue; - } - } else { - const parser = elements[i]; - const te = parser(input[i], options); - if (isEither3(te)) { - if (isLeft2(te)) { - const e = new Pointer(i, input, te.left); - if (allErrors) { - es.push([stepKey++, e]); - continue; - } else { - return left2(new Composite2(ast, input, e, sortByIndex(output))); - } - } - output.push([stepKey++, te.right]); - } else { - const nk = stepKey++; - const index = i; - if (!queue) { - queue = []; - } - queue.push(({ - es: es2, - output: output2 - }) => flatMap9(either3(te), (t) => { - if (isLeft2(t)) { - const e = new Pointer(index, input, t.left); - if (allErrors) { - es2.push([nk, e]); - return _void; - } else { - return left2(new Composite2(ast, input, e, sortByIndex(output2))); - } - } - output2.push([nk, t.right]); - return _void; - })); - } - } - } - if (isNonEmptyReadonlyArray(rest)) { - const [head5, ...tail] = rest; - for (;i < len - tail.length; i++) { - const te = head5(input[i], options); - if (isEither3(te)) { - if (isLeft2(te)) { - const e = new Pointer(i, input, te.left); - if (allErrors) { - es.push([stepKey++, e]); - continue; - } else { - return left2(new Composite2(ast, input, e, sortByIndex(output))); - } - } else { - output.push([stepKey++, te.right]); - } - } else { - const nk = stepKey++; - const index = i; - if (!queue) { - queue = []; - } - queue.push(({ - es: es2, - output: output2 - }) => flatMap9(either3(te), (t) => { - if (isLeft2(t)) { - const e = new Pointer(index, input, t.left); - if (allErrors) { - es2.push([nk, e]); - return _void; - } else { - return left2(new Composite2(ast, input, e, sortByIndex(output2))); - } - } else { - output2.push([nk, t.right]); - return _void; - } - })); - } - } - for (let j = 0;j < tail.length; j++) { - const index = i + j; - if (len < index + 1) { - continue; - } else { - const te = tail[j](input[index], options); - if (isEither3(te)) { - if (isLeft2(te)) { - const e = new Pointer(index, input, te.left); - if (allErrors) { - es.push([stepKey++, e]); - continue; - } else { - return left2(new Composite2(ast, input, e, sortByIndex(output))); - } - } - output.push([stepKey++, te.right]); - } else { - const nk = stepKey++; - if (!queue) { - queue = []; - } - queue.push(({ - es: es2, - output: output2 - }) => flatMap9(either3(te), (t) => { - if (isLeft2(t)) { - const e = new Pointer(index, input, t.left); - if (allErrors) { - es2.push([nk, e]); - return _void; - } else { - return left2(new Composite2(ast, input, e, sortByIndex(output2))); - } - } - output2.push([nk, t.right]); - return _void; - })); - } - } - } + } + return makeZonedProto(adjustedMillis - afterOffset, zone); +}; +var offsetRegex = /([+-])(\d{2}):(\d{2})$/; +var parseOffset = (offset) => { + const match10 = offsetRegex.exec(offset); + if (match10 === null) { + return null; + } + const [, sign, hours2, minutes2] = match10; + return (sign === "+" ? 1 : -1) * (Number(hours2) * 60 + Number(minutes2)) * 60 * 1000; +}; +var calculateNamedOffset = (utcMillis, adjustedMillis, zone) => { + const offset = zone.format.formatToParts(utcMillis).find((_) => _.type === "timeZoneName")?.value ?? ""; + if (offset === "GMT") { + return 0; + } + const result = parseOffset(offset); + if (result === null) { + return zonedOffset(makeZonedProto(adjustedMillis, zone)); + } + return result; +}; +var formatIso = (self) => toDateUtc(self).toISOString(); +var formatIsoOffset = (self) => { + const date = toDate(self); + return self._tag === "Utc" ? date.toISOString() : `${date.toISOString().slice(0, -1)}${zonedOffsetIso(self)}`; +}; +var formatIsoZoned = (self) => self.zone._tag === "Offset" ? formatIsoOffset(self) : `${formatIsoOffset(self)}[${self.zone.id}]`; + +// node_modules/effect/dist/esm/String.js +var toUpperCase = (self) => self.toUpperCase(); +var toLowerCase = (self) => self.toLowerCase(); +var capitalize = (self) => { + if (self.length === 0) + return self; + return toUpperCase(self[0]) + self.slice(1); +}; +var uncapitalize = (self) => { + if (self.length === 0) + return self; + return toLowerCase(self[0]) + self.slice(1); +}; +var isNonEmpty5 = (self) => self.length > 0; + +// node_modules/effect/dist/esm/Random.js +var fixed2 = fixed; + +// node_modules/effect/dist/esm/internal/schedule.js +var ScheduleSymbolKey = "effect/Schedule"; +var ScheduleTypeId = /* @__PURE__ */ Symbol.for(ScheduleSymbolKey); +var isSchedule = (u) => hasProperty(u, ScheduleTypeId); +var ScheduleDriverSymbolKey = "effect/ScheduleDriver"; +var ScheduleDriverTypeId = /* @__PURE__ */ Symbol.for(ScheduleDriverSymbolKey); +var defaultIterationMetadata = { + start: 0, + now: 0, + input: undefined, + output: undefined, + elapsed: zero, + elapsedSincePrevious: zero, + recurrence: 0 +}; +var CurrentIterationMetadata = /* @__PURE__ */ Reference2()("effect/Schedule/CurrentIterationMetadata", { + defaultValue: () => defaultIterationMetadata +}); +var scheduleVariance = { + _Out: (_) => _, + _In: (_) => _, + _R: (_) => _ +}; +var scheduleDriverVariance = { + _Out: (_) => _, + _In: (_) => _, + _R: (_) => _ +}; + +class ScheduleImpl { + initial; + step; + [ScheduleTypeId] = scheduleVariance; + constructor(initial, step3) { + this.initial = initial; + this.step = step3; + } + pipe() { + return pipeArguments(this, arguments); + } +} +var updateInfo = (iterationMetaRef, now, input, output) => update2(iterationMetaRef, (prev) => prev.recurrence === 0 ? { + now, + input, + output, + recurrence: prev.recurrence + 1, + elapsed: zero, + elapsedSincePrevious: zero, + start: now +} : { + now, + input, + output, + recurrence: prev.recurrence + 1, + elapsed: millis(now - prev.start), + elapsedSincePrevious: millis(now - prev.now), + start: prev.start +}); + +class ScheduleDriverImpl { + schedule; + ref; + [ScheduleDriverTypeId] = scheduleDriverVariance; + constructor(schedule, ref) { + this.schedule = schedule; + this.ref = ref; + } + get state() { + return map9(get10(this.ref), (tuple2) => tuple2[1]); + } + get last() { + return flatMap7(get10(this.ref), ([element, _]) => { + switch (element._tag) { + case "None": { + return failSync(() => new NoSuchElementException); } - const computeResult = ({ - es: es2, - output: output2 - }) => isNonEmptyArray2(es2) ? left2(new Composite2(ast, input, sortByIndex(es2), sortByIndex(output2))) : right2(sortByIndex(output2)); - if (queue && queue.length > 0) { - const cqueue = queue; - return suspend3(() => { - const state = { - es: copy(es), - output: copy(output) - }; - return flatMap9(forEach7(cqueue, (f) => f(state), { - concurrency, - batching, - discard: true - }), () => computeResult(state)); - }); + case "Some": { + return succeed(element.value); } - return computeResult({ - output, - es + } + }); + } + iterationMeta = /* @__PURE__ */ unsafeMake4(defaultIterationMetadata); + get reset() { + return set4(this.ref, [none2(), this.schedule.initial]).pipe(zipLeft(set4(this.iterationMeta, defaultIterationMetadata))); + } + next(input) { + return pipe(map9(get10(this.ref), (tuple2) => tuple2[1]), flatMap7((state) => pipe(currentTimeMillis2, flatMap7((now) => pipe(suspend(() => this.schedule.step(now, input, state)), flatMap7(([state2, out, decision]) => { + const setState = set4(this.ref, [some2(out), state2]); + if (isDone4(decision)) { + return setState.pipe(zipRight(fail2(none2()))); + } + const millis2 = start2(decision.intervals) - now; + if (millis2 <= 0) { + return setState.pipe(zipRight(updateInfo(this.iterationMeta, now, input, out)), as(out)); + } + const duration = millis(millis2); + return pipe(setState, zipRight(updateInfo(this.iterationMeta, now, input, out)), zipRight(sleep3(duration)), as(out)); + })))))); + } +} +var makeWithState = (initial, step3) => new ScheduleImpl(initial, step3); +var asVoid2 = (self) => map10(self, constVoid); +var check = /* @__PURE__ */ dual(2, (self, test) => checkEffect(self, (input, out) => sync(() => test(input, out)))); +var checkEffect = /* @__PURE__ */ dual(2, (self, test) => makeWithState(self.initial, (now, input, state) => flatMap7(self.step(now, input, state), ([state2, out, decision]) => { + if (isDone4(decision)) { + return succeed([state2, out, done5]); + } + return map9(test(input, out), (cont) => cont ? [state2, out, decision] : [state2, out, done5]); +}))); +var driver = (self) => pipe(make23([none2(), self.initial]), map9((ref) => new ScheduleDriverImpl(self, ref))); +var intersect5 = /* @__PURE__ */ dual(2, (self, that) => intersectWith(self, that, intersect4)); +var intersectWith = /* @__PURE__ */ dual(3, (self, that, f) => makeWithState([self.initial, that.initial], (now, input, state) => pipe(zipWith2(self.step(now, input, state[0]), that.step(now, input, state[1]), (a, b) => [a, b]), flatMap7(([[lState, out, lDecision], [rState, out2, rDecision]]) => { + if (isContinue2(lDecision) && isContinue2(rDecision)) { + return intersectWithLoop(self, that, input, lState, out, lDecision.intervals, rState, out2, rDecision.intervals, f); + } + return succeed([[lState, rState], [out, out2], done5]); +})))); +var intersectWithLoop = (self, that, input, lState, out, lInterval, rState, out2, rInterval, f) => { + const combined = f(lInterval, rInterval); + if (isNonEmpty4(combined)) { + return succeed([[lState, rState], [out, out2], _continue2(combined)]); + } + if (pipe(lInterval, lessThan6(rInterval))) { + return flatMap7(self.step(end2(lInterval), input, lState), ([lState2, out3, decision]) => { + if (isDone4(decision)) { + return succeed([[lState2, rState], [out3, out2], done5]); + } + return intersectWithLoop(self, that, input, lState2, out3, decision.intervals, rState, out2, rInterval, f); + }); + } + return flatMap7(that.step(end2(rInterval), input, rState), ([rState2, out22, decision]) => { + if (isDone4(decision)) { + return succeed([[lState, rState2], [out, out22], done5]); + } + return intersectWithLoop(self, that, input, lState, out, lInterval, rState2, out22, decision.intervals, f); + }); +}; +var map10 = /* @__PURE__ */ dual(2, (self, f) => mapEffect(self, (out) => sync(() => f(out)))); +var mapEffect = /* @__PURE__ */ dual(2, (self, f) => makeWithState(self.initial, (now, input, state) => flatMap7(self.step(now, input, state), ([state2, out, decision]) => map9(f(out), (out2) => [state2, out2, decision])))); +var passthrough = (self) => makeWithState(self.initial, (now, input, state) => pipe(self.step(now, input, state), map9(([state2, _, decision]) => [state2, input, decision]))); +var recurs = (n) => whileOutput(forever2, (out) => out < n); +var unfold2 = (initial, f) => makeWithState(initial, (now, _, state) => sync(() => [f(state), state, continueWith2(after2(now))])); +var untilInputEffect = /* @__PURE__ */ dual(2, (self, f) => checkEffect(self, (input, _) => negate(f(input)))); +var whileInputEffect = /* @__PURE__ */ dual(2, (self, f) => checkEffect(self, (input, _) => f(input))); +var whileOutput = /* @__PURE__ */ dual(2, (self, f) => check(self, (_, out) => f(out))); +var ScheduleDefectTypeId = /* @__PURE__ */ Symbol.for("effect/Schedule/ScheduleDefect"); + +class ScheduleDefect { + error; + [ScheduleDefectTypeId]; + constructor(error) { + this.error = error; + this[ScheduleDefectTypeId] = ScheduleDefectTypeId; + } +} +var isScheduleDefect = (u) => hasProperty(u, ScheduleDefectTypeId); +var scheduleDefectWrap = (self) => catchAll(self, (e) => die2(new ScheduleDefect(e))); +var scheduleDefectRefailCause = (cause2) => match2(find(cause2, (_) => isDieType(_) && isScheduleDefect(_.defect) ? some2(_.defect) : none2()), { + onNone: () => cause2, + onSome: (error) => fail(error.error) +}); +var scheduleDefectRefail = (effect) => catchAllCause(effect, (cause2) => failCause(scheduleDefectRefailCause(cause2))); +var repeat_Effect = /* @__PURE__ */ dual(2, (self, schedule) => repeatOrElse_Effect(self, schedule, (e, _) => fail2(e))); +var repeat_combined = /* @__PURE__ */ dual(2, (self, options) => { + if (isSchedule(options)) { + return repeat_Effect(self, options); + } + const base = options.schedule ?? passthrough(forever2); + const withWhile = options.while ? whileInputEffect(base, (a) => { + const applied = options.while(a); + if (typeof applied === "boolean") { + return succeed(applied); + } + return scheduleDefectWrap(applied); + }) : base; + const withUntil = options.until ? untilInputEffect(withWhile, (a) => { + const applied = options.until(a); + if (typeof applied === "boolean") { + return succeed(applied); + } + return scheduleDefectWrap(applied); + }) : withWhile; + const withTimes = options.times ? intersect5(withUntil, recurs(options.times)).pipe(map10((intersectionPair) => intersectionPair[0])) : withUntil; + return scheduleDefectRefail(repeat_Effect(self, withTimes)); +}); +var repeatOrElse_Effect = /* @__PURE__ */ dual(3, (self, schedule, orElse3) => flatMap7(driver(schedule), (driver2) => matchEffect(self, { + onFailure: (error) => orElse3(error, none2()), + onSuccess: (value) => repeatOrElseEffectLoop(provideServiceEffect(self, CurrentIterationMetadata, get10(driver2.iterationMeta)), driver2, (error, option2) => provideServiceEffect(orElse3(error, option2), CurrentIterationMetadata, get10(driver2.iterationMeta)), value) +}))); +var repeatOrElseEffectLoop = (self, driver2, orElse3, value) => matchEffect(driver2.next(value), { + onFailure: () => orDie(driver2.last), + onSuccess: (b) => matchEffect(self, { + onFailure: (error) => orElse3(error, some2(b)), + onSuccess: (value2) => repeatOrElseEffectLoop(self, driver2, orElse3, value2) + }) +}); +var retry_Effect = /* @__PURE__ */ dual(2, (self, policy) => retryOrElse_Effect(self, policy, (e, _) => fail2(e))); +var retry_combined = /* @__PURE__ */ dual(2, (self, options) => { + if (isSchedule(options)) { + return retry_Effect(self, options); + } + return scheduleDefectRefail(retry_Effect(self, fromRetryOptions(options))); +}); +var fromRetryOptions = (options) => { + const base = options.schedule ?? forever2; + const withWhile = options.while ? whileInputEffect(base, (e) => { + const applied = options.while(e); + if (typeof applied === "boolean") { + return succeed(applied); + } + return scheduleDefectWrap(applied); + }) : base; + const withUntil = options.until ? untilInputEffect(withWhile, (e) => { + const applied = options.until(e); + if (typeof applied === "boolean") { + return succeed(applied); + } + return scheduleDefectWrap(applied); + }) : withWhile; + return options.times !== undefined ? intersect5(withUntil, recurs(options.times)) : withUntil; +}; +var retryOrElse_Effect = /* @__PURE__ */ dual(3, (self, policy, orElse3) => flatMap7(driver(policy), (driver2) => retryOrElse_EffectLoop(provideServiceEffect(self, CurrentIterationMetadata, get10(driver2.iterationMeta)), driver2, (e, out) => provideServiceEffect(orElse3(e, out), CurrentIterationMetadata, get10(driver2.iterationMeta))))); +var retryOrElse_EffectLoop = (self, driver2, orElse3) => { + return catchAll(self, (e) => matchEffect(driver2.next(e), { + onFailure: () => pipe(driver2.last, orDie, flatMap7((out) => orElse3(e, out))), + onSuccess: () => retryOrElse_EffectLoop(self, driver2, orElse3) + })); +}; +var schedule_Effect = /* @__PURE__ */ dual(2, (self, schedule) => scheduleFrom_Effect(self, undefined, schedule)); +var scheduleFrom_Effect = /* @__PURE__ */ dual(3, (self, initial, schedule) => flatMap7(driver(schedule), (driver2) => scheduleFrom_EffectLoop(provideServiceEffect(self, CurrentIterationMetadata, get10(driver2.iterationMeta)), initial, driver2))); +var scheduleFrom_EffectLoop = (self, initial, driver2) => matchEffect(driver2.next(initial), { + onFailure: () => orDie(driver2.last), + onSuccess: () => flatMap7(self, (a) => scheduleFrom_EffectLoop(self, a, driver2)) +}); +var forever2 = /* @__PURE__ */ unfold2(0, (n) => n + 1); +var once2 = /* @__PURE__ */ asVoid2(/* @__PURE__ */ recurs(1)); +var scheduleForked = /* @__PURE__ */ dual(2, (self, schedule) => forkScoped(schedule_Effect(self, schedule))); + +// node_modules/effect/dist/esm/internal/executionPlan.js +var withExecutionPlan = /* @__PURE__ */ dual(2, (effect, plan) => suspend(() => { + let i = 0; + let result; + return flatMap7(whileLoop({ + while: () => i < plan.steps.length && (result === undefined || isLeft2(result)), + body: () => { + const step3 = plan.steps[i]; + let nextEffect = effect_provide(effect, step3.provide); + if (result) { + let attempted = false; + const wrapped = nextEffect; + nextEffect = suspend(() => { + if (attempted) + return wrapped; + attempted = true; + return result; }); - }; - } - case "TypeLiteral": { - if (ast.propertySignatures.length === 0 && ast.indexSignatures.length === 0) { - return fromRefinement(ast, isNotNullable); - } - const propertySignatures = []; - const expectedKeysMap = {}; - const expectedKeys = []; - for (const ps of ast.propertySignatures) { - propertySignatures.push([goMemo(ps.type, isDecoding), ps]); - expectedKeysMap[ps.name] = null; - expectedKeys.push(ps.name); + nextEffect = scheduleDefectRefail(retry_Effect(nextEffect, scheduleFromStep(step3, false))); + } else { + const schedule = scheduleFromStep(step3, true); + nextEffect = schedule ? scheduleDefectRefail(retry_Effect(nextEffect, schedule)) : nextEffect; } - const indexSignatures = ast.indexSignatures.map((is2) => [goMemo(is2.parameter, isDecoding), goMemo(is2.type, isDecoding), is2.parameter]); - const expectedAST = Union.make(ast.indexSignatures.map((is2) => is2.parameter).concat(expectedKeys.map((key) => isSymbol(key) ? new UniqueSymbol(key) : new Literal(key)))); - const expected = goMemo(expectedAST, isDecoding); - const concurrency = getConcurrency(ast); - const batching = getBatching(ast); - return (input, options) => { - if (!isRecord(input)) { - return left2(new Type2(ast, input)); + return either2(nextEffect); + }, + step: (either3) => { + result = either3; + i++; + } + }), () => result); +})); +var scheduleFromStep = (step3, first2) => { + if (!first2) { + return fromRetryOptions({ + schedule: step3.schedule ? step3.schedule : step3.attempts ? undefined : once2, + times: step3.attempts, + while: step3.while + }); + } else if (step3.attempts === 1 || !(step3.schedule || step3.attempts)) { + return; + } + return fromRetryOptions({ + schedule: step3.schedule, + while: step3.while, + times: step3.attempts ? step3.attempts - 1 : undefined + }); +}; + +// node_modules/effect/dist/esm/Deferred.js +var _await2 = deferredAwait; +var done6 = deferredDone; +var interrupt4 = deferredInterrupt; +var unsafeMake8 = deferredUnsafeMake; + +// node_modules/effect/dist/esm/MutableList.js +var TypeId15 = /* @__PURE__ */ Symbol.for("effect/MutableList"); +var MutableListProto = { + [TypeId15]: TypeId15, + [Symbol.iterator]() { + let done7 = false; + let head4 = this.head; + return { + next() { + if (done7) { + return this.return(); } - const allErrors = options?.errors === "all"; - const es = []; - let stepKey = 0; - const onExcessPropertyError = options?.onExcessProperty === "error"; - const onExcessPropertyPreserve = options?.onExcessProperty === "preserve"; - const output = {}; - let inputKeys; - if (onExcessPropertyError || onExcessPropertyPreserve) { - inputKeys = Reflect.ownKeys(input); - for (const key of inputKeys) { - const te = expected(key, options); - if (isEither3(te) && isLeft2(te)) { - if (onExcessPropertyError) { - const e = new Pointer(key, input, new Unexpected(input[key], `is unexpected, expected: ${String(expectedAST)}`)); - if (allErrors) { - es.push([stepKey++, e]); - continue; - } else { - return left2(new Composite2(ast, input, e, output)); - } - } else { - output[key] = input[key]; - } - } - } + if (head4 == null) { + done7 = true; + return this.return(); } - let queue = undefined; - const isExact = options?.exact === true; - for (let i = 0;i < propertySignatures.length; i++) { - const ps = propertySignatures[i][1]; - const name = ps.name; - const hasKey = Object.prototype.hasOwnProperty.call(input, name); - if (!hasKey) { - if (ps.isOptional) { - continue; - } else if (isExact) { - const e = new Pointer(name, input, new Missing(ps)); - if (allErrors) { - es.push([stepKey++, e]); - continue; - } else { - return left2(new Composite2(ast, input, e, output)); - } - } - } - const parser = propertySignatures[i][0]; - const te = parser(input[name], options); - if (isEither3(te)) { - if (isLeft2(te)) { - const e = new Pointer(name, input, hasKey ? te.left : new Missing(ps)); - if (allErrors) { - es.push([stepKey++, e]); - continue; - } else { - return left2(new Composite2(ast, input, e, output)); - } - } - output[name] = te.right; + const value = head4.value; + head4 = head4.next; + return { + done: done7, + value + }; + }, + return(value) { + if (!done7) { + done7 = true; + } + return { + done: true, + value + }; + } + }; + }, + toString() { + return format(this.toJSON()); + }, + toJSON() { + return { + _id: "MutableList", + values: Array.from(this).map(toJSON) + }; + }, + [NodeInspectSymbol]() { + return this.toJSON(); + }, + pipe() { + return pipeArguments(this, arguments); + } +}; +var makeNode = (value) => ({ + value, + removed: false, + prev: undefined, + next: undefined +}); +var empty29 = () => { + const list = Object.create(MutableListProto); + list.head = undefined; + list.tail = undefined; + list._length = 0; + return list; +}; +var isEmpty8 = (self) => length(self) === 0; +var length = (self) => self._length; +var append3 = /* @__PURE__ */ dual(2, (self, value) => { + const node = makeNode(value); + if (self.head === undefined) { + self.head = node; + } + if (self.tail === undefined) { + self.tail = node; + } else { + self.tail.next = node; + node.prev = self.tail; + self.tail = node; + } + self._length += 1; + return self; +}); +var shift = (self) => { + const head4 = self.head; + if (head4 !== undefined) { + remove6(self, head4); + return head4.value; + } + return; +}; +var remove6 = (self, node) => { + if (node.removed) { + return; + } + node.removed = true; + if (node.prev !== undefined && node.next !== undefined) { + node.prev.next = node.next; + node.next.prev = node.prev; + } else if (node.prev !== undefined) { + self.tail = node.prev; + node.prev.next = undefined; + } else if (node.next !== undefined) { + self.head = node.next; + node.next.prev = undefined; + } else { + self.tail = undefined; + self.head = undefined; + } + if (self._length > 0) { + self._length -= 1; + } +}; + +// node_modules/effect/dist/esm/MutableQueue.js +var TypeId16 = /* @__PURE__ */ Symbol.for("effect/MutableQueue"); +var EmptyMutableQueue = /* @__PURE__ */ Symbol.for("effect/mutable/MutableQueue/Empty"); +var MutableQueueProto = { + [TypeId16]: TypeId16, + [Symbol.iterator]() { + return Array.from(this.queue)[Symbol.iterator](); + }, + toString() { + return format(this.toJSON()); + }, + toJSON() { + return { + _id: "MutableQueue", + values: Array.from(this).map(toJSON) + }; + }, + [NodeInspectSymbol]() { + return this.toJSON(); + }, + pipe() { + return pipeArguments(this, arguments); + } +}; +var make38 = (capacity) => { + const queue = Object.create(MutableQueueProto); + queue.queue = empty29(); + queue.capacity = capacity; + return queue; +}; +var unbounded = () => make38(undefined); +var offer = /* @__PURE__ */ dual(2, (self, value) => { + const queueLength = length(self.queue); + if (self.capacity !== undefined && queueLength === self.capacity) { + return false; + } + append3(value)(self.queue); + return true; +}); +var poll = /* @__PURE__ */ dual(2, (self, def) => { + if (isEmpty8(self.queue)) { + return def; + } + return shift(self.queue); +}); + +// node_modules/effect/dist/esm/internal/cache.js +var complete2 = (key, exit2, entryStats, timeToLiveMillis) => struct({ + _tag: "Complete", + key, + exit: exit2, + entryStats, + timeToLiveMillis +}); +var pending2 = (key, deferred) => struct({ + _tag: "Pending", + key, + deferred +}); +var refreshing = (deferred, complete3) => struct({ + _tag: "Refreshing", + deferred, + complete: complete3 +}); +var MapKeyTypeId = /* @__PURE__ */ Symbol.for("effect/Cache/MapKey"); + +class MapKeyImpl { + current; + [MapKeyTypeId] = MapKeyTypeId; + previous = undefined; + next = undefined; + constructor(current) { + this.current = current; + } + [symbol]() { + return pipe(hash(this.current), combine(hash(this.previous)), combine(hash(this.next)), cached(this)); + } + [symbol2](that) { + if (this === that) { + return true; + } + return isMapKey(that) && equals(this.current, that.current) && equals(this.previous, that.previous) && equals(this.next, that.next); + } +} +var makeMapKey = (current) => new MapKeyImpl(current); +var isMapKey = (u) => hasProperty(u, MapKeyTypeId); + +class KeySetImpl { + head = undefined; + tail = undefined; + add(key) { + if (key !== this.tail) { + if (this.tail === undefined) { + this.head = key; + this.tail = key; + } else { + const previous = key.previous; + const next = key.next; + if (next !== undefined) { + key.next = undefined; + if (previous !== undefined) { + previous.next = next; + next.previous = previous; } else { - const nk = stepKey++; - const index = name; - if (!queue) { - queue = []; - } - queue.push(({ - es: es2, - output: output2 - }) => flatMap9(either3(te), (t) => { - if (isLeft2(t)) { - const e = new Pointer(index, input, hasKey ? t.left : new Missing(ps)); - if (allErrors) { - es2.push([nk, e]); - return _void; - } else { - return left2(new Composite2(ast, input, e, output2)); - } - } - output2[index] = t.right; - return _void; - })); - } - } - for (let i = 0;i < indexSignatures.length; i++) { - const indexSignature = indexSignatures[i]; - const parameter = indexSignature[0]; - const type = indexSignature[1]; - const keys5 = getKeysForIndexSignature(input, indexSignature[2]); - for (const key of keys5) { - const keu = parameter(key, options); - if (isEither3(keu) && isRight2(keu)) { - const vpr = type(input[key], options); - if (isEither3(vpr)) { - if (isLeft2(vpr)) { - const e = new Pointer(key, input, vpr.left); - if (allErrors) { - es.push([stepKey++, e]); - continue; - } else { - return left2(new Composite2(ast, input, e, output)); - } - } else { - if (!Object.prototype.hasOwnProperty.call(expectedKeysMap, key)) { - output[key] = vpr.right; - } - } - } else { - const nk = stepKey++; - const index = key; - if (!queue) { - queue = []; - } - queue.push(({ - es: es2, - output: output2 - }) => flatMap9(either3(vpr), (tv) => { - if (isLeft2(tv)) { - const e = new Pointer(index, input, tv.left); - if (allErrors) { - es2.push([nk, e]); - return _void; - } else { - return left2(new Composite2(ast, input, e, output2)); - } - } else { - if (!Object.prototype.hasOwnProperty.call(expectedKeysMap, key)) { - output2[key] = tv.right; - } - return _void; - } - })); - } - } + this.head = next; + this.head.previous = undefined; } } - const computeResult = ({ - es: es2, - output: output2 - }) => { - if (isNonEmptyArray2(es2)) { - return left2(new Composite2(ast, input, sortByIndex(es2), output2)); - } - if (options?.propertyOrder === "original") { - const keys5 = inputKeys || Reflect.ownKeys(input); - for (const name of expectedKeys) { - if (keys5.indexOf(name) === -1) { - keys5.push(name); - } - } - const out = {}; - for (const key of keys5) { - if (Object.prototype.hasOwnProperty.call(output2, key)) { - out[key] = output2[key]; - } - } - return right2(out); + this.tail.next = key; + key.previous = this.tail; + this.tail = key; + } + } + } + remove() { + const key = this.head; + if (key !== undefined) { + const next = key.next; + if (next !== undefined) { + key.next = undefined; + this.head = next; + this.head.previous = undefined; + } else { + this.head = undefined; + this.tail = undefined; + } + } + return key; + } +} +var makeKeySet = () => new KeySetImpl; +var makeCacheState = (map11, keys5, accesses, updating, hits, misses) => ({ + map: map11, + keys: keys5, + accesses, + updating, + hits, + misses +}); +var initialCacheState = () => makeCacheState(empty21(), makeKeySet(), unbounded(), make11(false), 0, 0); +var CacheSymbolKey = "effect/Cache"; +var CacheTypeId = /* @__PURE__ */ Symbol.for(CacheSymbolKey); +var cacheVariance = { + _Key: (_) => _, + _Error: (_) => _, + _Value: (_) => _ +}; +var ConsumerCacheSymbolKey = "effect/ConsumerCache"; +var ConsumerCacheTypeId = /* @__PURE__ */ Symbol.for(ConsumerCacheSymbolKey); +var consumerCacheVariance = { + _Key: (_) => _, + _Error: (_) => _, + _Value: (_) => _ +}; +var makeCacheStats = (options) => options; +var makeEntryStats = (loadedMillis) => ({ + loadedMillis +}); + +class CacheImpl { + capacity; + context; + fiberId; + lookup; + timeToLive; + [CacheTypeId] = cacheVariance; + [ConsumerCacheTypeId] = consumerCacheVariance; + cacheState; + constructor(capacity, context3, fiberId2, lookup, timeToLive) { + this.capacity = capacity; + this.context = context3; + this.fiberId = fiberId2; + this.lookup = lookup; + this.timeToLive = timeToLive; + this.cacheState = initialCacheState(); + } + get(key) { + return map9(this.getEither(key), merge); + } + get cacheStats() { + return sync(() => makeCacheStats({ + hits: this.cacheState.hits, + misses: this.cacheState.misses, + size: size4(this.cacheState.map) + })); + } + getOption(key) { + return suspend(() => match2(get12(this.cacheState.map, key), { + onNone: () => { + const mapKey = makeMapKey(key); + this.trackAccess(mapKey); + this.trackMiss(); + return succeed(none2()); + }, + onSome: (value) => this.resolveMapValue(value) + })); + } + getOptionComplete(key) { + return suspend(() => match2(get12(this.cacheState.map, key), { + onNone: () => { + const mapKey = makeMapKey(key); + this.trackAccess(mapKey); + this.trackMiss(); + return succeed(none2()); + }, + onSome: (value) => this.resolveMapValue(value, true) + })); + } + contains(key) { + return sync(() => has4(this.cacheState.map, key)); + } + entryStats(key) { + return sync(() => { + const option2 = get12(this.cacheState.map, key); + if (isSome2(option2)) { + switch (option2.value._tag) { + case "Complete": { + const loaded = option2.value.entryStats.loadedMillis; + return some2(makeEntryStats(loaded)); + } + case "Pending": { + return none2(); + } + case "Refreshing": { + const loaded = option2.value.complete.entryStats.loadedMillis; + return some2(makeEntryStats(loaded)); } - return right2(output2); - }; - if (queue && queue.length > 0) { - const cqueue = queue; - return suspend3(() => { - const state = { - es: copy(es), - output: Object.assign({}, output) - }; - return flatMap9(forEach7(cqueue, (f) => f(state), { - concurrency, - batching, - discard: true - }), () => computeResult(state)); - }); } - return computeResult({ - es, - output - }); - }; - } - case "Union": { - const searchTree = getSearchTree(ast.types, isDecoding); - const ownKeys = Reflect.ownKeys(searchTree.keys); - const ownKeysLen = ownKeys.length; - const astTypesLen = ast.types.length; - const map14 = new Map; - for (let i = 0;i < astTypesLen; i++) { - map14.set(ast.types[i], goMemo(ast.types[i], isDecoding)); } - const concurrency = getConcurrency(ast) ?? 1; - const batching = getBatching(ast); - return (input, options) => { - const es = []; - let stepKey = 0; - let candidates = []; - if (ownKeysLen > 0) { - if (isRecordOrArray(input)) { - for (let i = 0;i < ownKeysLen; i++) { - const name = ownKeys[i]; - const buckets = searchTree.keys[name].buckets; - if (Object.prototype.hasOwnProperty.call(input, name)) { - const literal2 = String(input[name]); - if (Object.prototype.hasOwnProperty.call(buckets, literal2)) { - candidates = candidates.concat(buckets[literal2]); - } else { - const { - candidates: candidates2, - literals - } = searchTree.keys[name]; - const literalsUnion = Union.make(literals); - const errorAst = candidates2.length === astTypesLen ? new TypeLiteral([new PropertySignature(name, literalsUnion, false, true)], []) : Union.make(candidates2); - es.push([stepKey++, new Composite2(errorAst, input, new Pointer(name, input, new Type2(literalsUnion, input[name])))]); - } - } else { - const { - candidates: candidates2, - literals - } = searchTree.keys[name]; - const fakePropertySignature = new PropertySignature(name, Union.make(literals), false, true); - const errorAst = candidates2.length === astTypesLen ? new TypeLiteral([fakePropertySignature], []) : Union.make(candidates2); - es.push([stepKey++, new Composite2(errorAst, input, new Pointer(name, input, new Missing(fakePropertySignature)))]); - } - } - } else { - const errorAst = searchTree.candidates.length === astTypesLen ? ast : Union.make(searchTree.candidates); - es.push([stepKey++, new Type2(errorAst, input)]); + return none2(); + }); + } + getEither(key) { + return suspend(() => { + const k = key; + let mapKey = undefined; + let deferred = undefined; + let value = getOrUndefined(get12(this.cacheState.map, k)); + if (value === undefined) { + deferred = unsafeMake8(this.fiberId); + mapKey = makeMapKey(k); + if (has4(this.cacheState.map, k)) { + value = getOrUndefined(get12(this.cacheState.map, k)); + } else { + set5(this.cacheState.map, k, pending2(mapKey, deferred)); + } + } + if (value === undefined) { + this.trackAccess(mapKey); + this.trackMiss(); + return map9(this.lookupValueOf(key, deferred), right2); + } else { + return flatMap7(this.resolveMapValue(value), match2({ + onNone: () => this.getEither(key), + onSome: (value2) => succeed(left2(value2)) + })); + } + }); + } + invalidate(key) { + return sync(() => { + remove5(this.cacheState.map, key); + }); + } + invalidateWhen(key, when2) { + return sync(() => { + const value = get12(this.cacheState.map, key); + if (isSome2(value) && value.value._tag === "Complete") { + if (value.value.exit._tag === "Success") { + if (when2(value.value.exit.value)) { + remove5(this.cacheState.map, key); } } - if (searchTree.otherwise.length > 0) { - candidates = candidates.concat(searchTree.otherwise); + } + }); + } + get invalidateAll() { + return sync(() => { + this.cacheState.map = empty21(); + }); + } + refresh(key) { + return clockWith3((clock2) => suspend(() => { + const k = key; + const deferred = unsafeMake8(this.fiberId); + let value = getOrUndefined(get12(this.cacheState.map, k)); + if (value === undefined) { + if (has4(this.cacheState.map, k)) { + value = getOrUndefined(get12(this.cacheState.map, k)); + } else { + set5(this.cacheState.map, k, pending2(makeMapKey(k), deferred)); } - let queue = undefined; - for (let i = 0;i < candidates.length; i++) { - const candidate = candidates[i]; - const pr = map14.get(candidate)(input, options); - if (isEither3(pr) && (!queue || queue.length === 0)) { - if (isRight2(pr)) { - return pr; - } else { - es.push([stepKey++, pr.left]); - } - } else { - const nk = stepKey++; - if (!queue) { - queue = []; + } + if (value === undefined) { + return asVoid(this.lookupValueOf(key, deferred)); + } else { + switch (value._tag) { + case "Complete": { + if (this.hasExpired(clock2, value.timeToLiveMillis)) { + const found = getOrUndefined(get12(this.cacheState.map, k)); + if (equals(found, value)) { + remove5(this.cacheState.map, k); + } + return asVoid(this.get(key)); } - queue.push((state) => suspend3(() => { - if ("finalResult" in state) { - return _void; - } else { - return flatMap9(either3(pr), (t) => { - if (isRight2(t)) { - state.finalResult = t; - } else { - state.es.push([nk, t.left]); - } - return _void; - }); + return pipe(this.lookupValueOf(key, deferred), when(() => { + const current = getOrUndefined(get12(this.cacheState.map, k)); + if (equals(current, value)) { + const mapValue = refreshing(deferred, value); + set5(this.cacheState.map, k, mapValue); + return true; } - })); + return false; + }), asVoid); + } + case "Pending": { + return _await2(value.deferred); + } + case "Refreshing": { + return _await2(value.deferred); } } - const computeResult = (es2) => isNonEmptyArray2(es2) ? es2.length === 1 && es2[0][1]._tag === "Type" ? left2(es2[0][1]) : left2(new Composite2(ast, input, sortByIndex(es2))) : left2(new Type2(ast, input)); - if (queue && queue.length > 0) { - const cqueue = queue; - return suspend3(() => { - const state = { - es: copy(es) - }; - return flatMap9(forEach7(cqueue, (f) => f(state), { - concurrency, - batching, - discard: true - }), () => { - if ("finalResult" in state) { - return state.finalResult; - } - return computeResult(state.es); - }); - }); + } + })); + } + set(key, value) { + return clockWith3((clock2) => sync(() => { + const now = clock2.unsafeCurrentTimeMillis(); + const k = key; + const lookupResult = succeed3(value); + const mapValue = complete2(makeMapKey(k), lookupResult, makeEntryStats(now), now + toMillis(decode(this.timeToLive(lookupResult)))); + set5(this.cacheState.map, k, mapValue); + })); + } + get size() { + return sync(() => { + return size4(this.cacheState.map); + }); + } + get values() { + return sync(() => { + const values4 = []; + for (const entry of this.cacheState.map) { + if (entry[1]._tag === "Complete" && entry[1].exit._tag === "Success") { + values4.push(entry[1].exit.value); } - return computeResult(es); - }; - } - case "Suspend": { - const get13 = memoizeThunk(() => goMemo(ast.f(), isDecoding)); - return (a, options) => get13()(a, options); - } + } + return values4; + }); } -}; -var fromRefinement = (ast, refinement) => (u) => refinement(u) ? right2(u) : left2(new Type2(ast, u)); -var getLiterals = (ast, isDecoding) => { - switch (ast._tag) { - case "Declaration": { - const annotation = getSurrogateAnnotation(ast); - if (isSome2(annotation)) { - return getLiterals(annotation.value, isDecoding); + get entries() { + return sync(() => { + const values4 = []; + for (const entry of this.cacheState.map) { + if (entry[1]._tag === "Complete" && entry[1].exit._tag === "Success") { + values4.push([entry[0], entry[1].exit.value]); + } } - break; - } - case "TypeLiteral": { - const out = []; - for (let i = 0;i < ast.propertySignatures.length; i++) { - const propertySignature = ast.propertySignatures[i]; - const type = isDecoding ? encodedAST(propertySignature.type) : typeAST(propertySignature.type); - if (isLiteral(type) && !propertySignature.isOptional) { - out.push([propertySignature.name, type]); + return values4; + }); + } + get keys() { + return sync(() => { + const keys5 = []; + for (const entry of this.cacheState.map) { + if (entry[1]._tag === "Complete" && entry[1].exit._tag === "Success") { + keys5.push(entry[0]); } } - return out; - } - case "TupleType": { - const out = []; - for (let i = 0;i < ast.elements.length; i++) { - const element = ast.elements[i]; - const type = isDecoding ? encodedAST(element.type) : typeAST(element.type); - if (isLiteral(type) && !element.isOptional) { - out.push([i, type]); + return keys5; + }); + } + resolveMapValue(value, ignorePending = false) { + return clockWith3((clock2) => { + switch (value._tag) { + case "Complete": { + this.trackAccess(value.key); + if (this.hasExpired(clock2, value.timeToLiveMillis)) { + remove5(this.cacheState.map, value.key.current); + return succeed(none2()); + } + this.trackHit(); + return map9(value.exit, some2); + } + case "Pending": { + this.trackAccess(value.key); + this.trackHit(); + if (ignorePending) { + return succeed(none2()); + } + return map9(_await2(value.deferred), some2); + } + case "Refreshing": { + this.trackAccess(value.complete.key); + this.trackHit(); + if (this.hasExpired(clock2, value.complete.timeToLiveMillis)) { + if (ignorePending) { + return succeed(none2()); + } + return map9(_await2(value.deferred), some2); + } + return map9(value.complete.exit, some2); } } - return out; - } - case "Refinement": - return getLiterals(ast.from, isDecoding); - case "Suspend": - return getLiterals(ast.f(), isDecoding); - case "Transformation": - return getLiterals(isDecoding ? ast.from : ast.to, isDecoding); + }); } - return []; -}; -var getSearchTree = (members, isDecoding) => { - const keys5 = {}; - const otherwise = []; - const candidates = []; - for (let i = 0;i < members.length; i++) { - const member = members[i]; - const tags = getLiterals(member, isDecoding); - if (tags.length > 0) { - candidates.push(member); - for (let j = 0;j < tags.length; j++) { - const [key, literal2] = tags[j]; - const hash2 = String(literal2.literal); - keys5[key] = keys5[key] || { - buckets: {}, - literals: [], - candidates: [] - }; - const buckets = keys5[key].buckets; - if (Object.prototype.hasOwnProperty.call(buckets, hash2)) { - if (j < tags.length - 1) { - continue; + trackHit() { + this.cacheState.hits = this.cacheState.hits + 1; + } + trackMiss() { + this.cacheState.misses = this.cacheState.misses + 1; + } + trackAccess(key) { + offer(this.cacheState.accesses, key); + if (compareAndSet(this.cacheState.updating, false, true)) { + let loop2 = true; + while (loop2) { + const key2 = poll(this.cacheState.accesses, EmptyMutableQueue); + if (key2 === EmptyMutableQueue) { + loop2 = false; + } else { + this.cacheState.keys.add(key2); + } + } + let size10 = size4(this.cacheState.map); + loop2 = size10 > this.capacity; + while (loop2) { + const key2 = this.cacheState.keys.remove(); + if (key2 !== undefined) { + if (has4(this.cacheState.map, key2.current)) { + remove5(this.cacheState.map, key2.current); + size10 = size10 - 1; + loop2 = size10 > this.capacity; } - buckets[hash2].push(member); - keys5[key].literals.push(literal2); - keys5[key].candidates.push(member); } else { - buckets[hash2] = [member]; - keys5[key].literals.push(literal2); - keys5[key].candidates.push(member); - break; + loop2 = false; } } - } else { - otherwise.push(member); + set2(this.cacheState.updating, false); } } - return { - keys: keys5, - otherwise, - candidates - }; -}; -var dropRightRefinement = (ast) => isRefinement(ast) ? dropRightRefinement(ast.from) : ast; -var handleForbidden = (effect, ast, actual, options) => { - if (options?.isEffectAllowed === true) { - return effect; + hasExpired(clock2, timeToLiveMillis) { + return clock2.unsafeCurrentTimeMillis() > timeToLiveMillis; } - if (isEither3(effect)) { - return effect; + lookupValueOf(input, deferred) { + return clockWith3((clock2) => suspend(() => { + const key = input; + return pipe(this.lookup(input), provideContext(this.context), exit, flatMap7((exit2) => { + const now = clock2.unsafeCurrentTimeMillis(); + const stats = makeEntryStats(now); + const value = complete2(makeMapKey(key), exit2, stats, now + toMillis(decode(this.timeToLive(exit2)))); + set5(this.cacheState.map, key, value); + return zipRight(done6(deferred, exit2), exit2); + }), onInterrupt(() => zipRight(interrupt4(deferred), sync(() => { + remove5(this.cacheState.map, key); + })))); + })); } - const scheduler = new SyncScheduler; - const fiber = runFork2(effect, { - scheduler - }); - scheduler.flush(); - const exit3 = fiber.unsafePoll(); - if (exit3) { - if (isSuccess(exit3)) { - return right2(exit3.value); +} +var unsafeMakeWith = (capacity, lookup, timeToLive) => new CacheImpl(capacity, empty4(), none3, lookup, (exit2) => decode(timeToLive(exit2))); + +// node_modules/effect/dist/esm/internal/query.js +var currentCache = /* @__PURE__ */ globalValue(/* @__PURE__ */ Symbol.for("effect/FiberRef/currentCache"), () => fiberRefUnsafeMake(unsafeMakeWith(65536, () => map9(deferredMake(), (handle) => ({ + listeners: new Listeners, + handle +})), () => seconds(60)))); +var currentCacheEnabled = /* @__PURE__ */ globalValue(/* @__PURE__ */ Symbol.for("effect/FiberRef/currentCacheEnabled"), () => fiberRefUnsafeMake(false)); +var fromRequest = (request, dataSource) => flatMap7(isEffect(dataSource) ? dataSource : succeed(dataSource), (ds) => fiberIdWith((id) => { + const proxy = new Proxy(request, {}); + return fiberRefGetWith(currentCacheEnabled, (cacheEnabled) => { + if (cacheEnabled) { + const cached3 = fiberRefGetWith(currentCache, (cache) => flatMap7(cache.getEither(proxy), (orNew) => { + switch (orNew._tag) { + case "Left": { + if (orNew.left.listeners.interrupted) { + return flatMap7(cache.invalidateWhen(proxy, (entry) => entry.handle === orNew.left.handle), () => cached3); + } + orNew.left.listeners.increment(); + return uninterruptibleMask((restore) => flatMap7(exit(blocked(empty15, restore(deferredAwait(orNew.left.handle)))), (exit2) => { + orNew.left.listeners.decrement(); + return exit2; + })); + } + case "Right": { + orNew.right.listeners.increment(); + return uninterruptibleMask((restore) => flatMap7(exit(blocked(single(ds, makeEntry({ + request: proxy, + result: orNew.right.handle, + listeners: orNew.right.listeners, + ownerId: id, + state: { + completed: false + } + })), restore(deferredAwait(orNew.right.handle)))), () => { + orNew.right.listeners.decrement(); + return deferredAwait(orNew.right.handle); + })); + } + } + })); + return cached3; } - const cause3 = exit3.cause; - if (isFailType2(cause3)) { - return left2(cause3.error); + const listeners = new Listeners; + listeners.increment(); + return flatMap7(deferredMake(), (ref) => ensuring(blocked(single(ds, makeEntry({ + request: proxy, + result: ref, + listeners, + ownerId: id, + state: { + completed: false + } + })), deferredAwait(ref)), sync(() => listeners.decrement()))); + }); +})); +var cacheRequest = (request, result) => { + return fiberRefGetWith(currentCacheEnabled, (cacheEnabled) => { + if (cacheEnabled) { + return fiberRefGetWith(currentCache, (cache) => flatMap7(cache.getEither(request), (orNew) => { + switch (orNew._tag) { + case "Left": { + return void_; + } + case "Right": { + return deferredComplete(orNew.right.handle, result); + } + } + })); } - return left2(new Forbidden(ast, actual, pretty2(cause3))); - } - return left2(new Forbidden(ast, actual, "cannot be be resolved synchronously, this is caused by using runSync on an effect that performs async work")); + return void_; + }); +}; +var withRequestCaching = /* @__PURE__ */ dual(2, (self, strategy) => fiberRefLocally(self, currentCacheEnabled, strategy)); +var withRequestCache = /* @__PURE__ */ dual(2, (self, cache) => fiberRefLocally(self, currentCache, cache)); + +// node_modules/effect/dist/esm/Request.js +var isRequest2 = isRequest; +var Class4 = Class3; + +// node_modules/effect/dist/esm/Effect.js +var EffectTypeId3 = EffectTypeId2; +var isEffect2 = isEffect; +var cachedWithTTL = cached2; +var cachedInvalidateWithTTL2 = cachedInvalidateWithTTL; +var cached3 = memoize; +var cachedFunction2 = cachedFunction; +var once3 = once; +var all3 = all2; +var allWith2 = allWith; +var allSuccesses2 = allSuccesses; +var dropUntil2 = dropUntil; +var dropWhile2 = dropWhile; +var takeUntil2 = takeUntil; +var takeWhile2 = takeWhile; +var every6 = every4; +var exists3 = exists2; +var filter7 = filter5; +var filterMap5 = filterMap4; +var findFirst6 = findFirst4; +var forEach7 = forEach6; +var head4 = head3; +var mergeAll5 = mergeAll3; +var partition4 = partition3; +var reduce10 = reduce8; +var reduceWhile2 = reduceWhile; +var reduceRight3 = reduceRight2; +var reduceEffect2 = reduceEffect; +var replicate2 = replicate; +var replicateEffect2 = replicateEffect; +var validateAll2 = validateAll; +var validateFirst2 = validateFirst; +var async = async_; +var asyncEffect2 = asyncEffect; +var custom2 = custom; +var withFiberRuntime2 = withFiberRuntime; +var fail5 = fail2; +var failSync2 = failSync; +var failCause5 = failCause; +var failCauseSync2 = failCauseSync; +var die4 = die2; +var dieMessage2 = dieMessage; +var dieSync2 = dieSync; +var gen2 = gen; +var never2 = never; +var none9 = none6; +var promise2 = promise; +var succeed6 = succeed; +var succeedNone2 = succeedNone; +var succeedSome2 = succeedSome; +var suspend3 = suspend; +var sync3 = sync; +var _void = void_; +var yieldNow4 = yieldNow; +var _catch2 = _catch; +var catchAll2 = catchAll; +var catchAllCause2 = catchAllCause; +var catchAllDefect2 = catchAllDefect; +var catchIf2 = catchIf; +var catchSome2 = catchSome; +var catchSomeCause2 = catchSomeCause; +var catchSomeDefect2 = catchSomeDefect; +var catchTag2 = catchTag; +var catchTags2 = catchTags; +var cause2 = cause; +var eventually2 = eventually; +var ignore2 = ignore; +var ignoreLogged2 = ignoreLogged; +var parallelErrors2 = parallelErrors; +var sandbox2 = sandbox; +var retry = retry_combined; +var withExecutionPlan2 = withExecutionPlan; +var retryOrElse = retryOrElse_Effect; +var try_3 = try_2; +var tryMap2 = tryMap; +var tryMapPromise2 = tryMapPromise; +var tryPromise2 = tryPromise; +var unsandbox2 = unsandbox; +var allowInterrupt2 = allowInterrupt; +var checkInterruptible2 = checkInterruptible; +var disconnect2 = disconnect; +var interrupt5 = interrupt2; +var interruptWith2 = interruptWith; +var interruptible4 = interruptible2; +var interruptibleMask2 = interruptibleMask; +var onInterrupt2 = onInterrupt; +var uninterruptible2 = uninterruptible; +var uninterruptibleMask3 = uninterruptibleMask; +var liftPredicate2 = liftPredicate; +var as3 = as; +var asSome2 = asSome; +var asSomeError2 = asSomeError; +var asVoid3 = asVoid; +var flip2 = flip; +var flipWith2 = flipWith; +var map11 = map9; +var mapAccum3 = mapAccum2; +var mapBoth3 = mapBoth2; +var mapError2 = mapError; +var mapErrorCause2 = mapErrorCause; +var merge6 = merge5; +var negate2 = negate; +var acquireRelease2 = acquireRelease; +var acquireReleaseInterruptible2 = acquireReleaseInterruptible; +var acquireUseRelease2 = acquireUseRelease; +var addFinalizer2 = addFinalizer; +var ensuring2 = ensuring; +var onError2 = onError; +var onExit3 = onExit; +var parallelFinalizers2 = parallelFinalizers; +var sequentialFinalizers2 = sequentialFinalizers; +var finalizersMask2 = finalizersMask; +var scope2 = scope; +var scopeWith2 = scopeWith; +var scopedWith2 = scopedWith; +var scoped2 = scopedEffect; +var using2 = using; +var withEarlyRelease2 = withEarlyRelease; +var awaitAllChildren2 = awaitAllChildren; +var daemonChildren2 = daemonChildren; +var descriptor2 = descriptor; +var descriptorWith2 = descriptorWith; +var diffFiberRefs2 = diffFiberRefs; +var ensuringChild2 = ensuringChild; +var ensuringChildren2 = ensuringChildren; +var fiberId2 = fiberId; +var fiberIdWith2 = fiberIdWith; +var fork3 = fork; +var forkDaemon2 = forkDaemon; +var forkAll2 = forkAll; +var forkIn2 = forkIn; +var forkScoped2 = forkScoped; +var forkWithErrorHandler2 = forkWithErrorHandler; +var fromFiber2 = fromFiber; +var fromFiberEffect2 = fromFiberEffect; +var supervised2 = supervised; +var transplant2 = transplant; +var withConcurrency2 = withConcurrency; +var withScheduler2 = withScheduler; +var withSchedulingPriority2 = withSchedulingPriority; +var withMaxOpsBeforeYield2 = withMaxOpsBeforeYield; +var clock2 = clock; +var clockWith4 = clockWith3; +var withClockScoped2 = withClockScoped; +var withClock2 = withClock; +var console3 = console2; +var consoleWith2 = consoleWith; +var withConsoleScoped2 = withConsoleScoped; +var withConsole2 = withConsole; +var delay2 = delay; +var sleep4 = sleep3; +var timed2 = timed; +var timedWith2 = timedWith; +var timeout2 = timeout; +var timeoutOption2 = timeoutOption; +var timeoutFail2 = timeoutFail; +var timeoutFailCause2 = timeoutFailCause; +var timeoutTo2 = timeoutTo; +var configProviderWith2 = configProviderWith; +var withConfigProvider2 = withConfigProvider; +var withConfigProviderScoped2 = withConfigProviderScoped; +var context3 = context; +var contextWith2 = contextWith; +var contextWithEffect2 = contextWithEffect; +var mapInputContext2 = mapInputContext; +var provide2 = effect_provide; +var provideService2 = provideService; +var provideServiceEffect2 = provideServiceEffect; +var serviceFunction2 = serviceFunction; +var serviceFunctionEffect2 = serviceFunctionEffect; +var serviceFunctions2 = serviceFunctions; +var serviceConstants2 = serviceConstants; +var serviceMembers2 = serviceMembers; +var serviceOption2 = serviceOption; +var serviceOptional2 = serviceOptional; +var updateService2 = updateService; +var Do2 = Do; +var bind3 = bind2; +var bindAll2 = bindAll; +var bindTo3 = bindTo2; +var let_3 = let_2; +var option2 = option; +var either3 = either2; +var exit2 = exit; +var intoDeferred2 = intoDeferred; +var if_2 = if_; +var filterOrDie2 = filterOrDie; +var filterOrDieMessage2 = filterOrDieMessage; +var filterOrElse2 = filterOrElse; +var filterOrFail2 = filterOrFail; +var filterEffectOrElse2 = filterEffectOrElse; +var filterEffectOrFail2 = filterEffectOrFail; +var unless2 = unless; +var unlessEffect2 = unlessEffect; +var when2 = when; +var whenEffect2 = whenEffect; +var whenFiberRef2 = whenFiberRef; +var whenRef2 = whenRef; +var flatMap9 = flatMap7; +var andThen4 = andThen2; +var flatten6 = flatten4; +var race2 = race; +var raceAll2 = raceAll; +var raceFirst2 = raceFirst; +var raceWith2 = raceWith; +var summarized2 = summarized; +var tap2 = tap; +var tapBoth2 = tapBoth; +var tapDefect2 = tapDefect; +var tapError2 = tapError; +var tapErrorTag2 = tapErrorTag; +var tapErrorCause2 = tapErrorCause; +var forever3 = forever; +var iterate2 = iterate; +var loop2 = loop; +var repeat = repeat_combined; +var repeatN2 = repeatN; +var repeatOrElse = repeatOrElse_Effect; +var schedule = schedule_Effect; +var scheduleForked2 = scheduleForked; +var scheduleFrom = scheduleFrom_Effect; +var whileLoop2 = whileLoop; +var getFiberRefs = fiberRefs2; +var inheritFiberRefs2 = inheritFiberRefs; +var locally = fiberRefLocally; +var locallyWith = fiberRefLocallyWith; +var locallyScoped = fiberRefLocallyScoped; +var locallyScopedWith = fiberRefLocallyScopedWith; +var patchFiberRefs2 = patchFiberRefs; +var setFiberRefs2 = setFiberRefs; +var updateFiberRefs2 = updateFiberRefs; +var isFailure3 = isFailure; +var isSuccess3 = isSuccess; +var match10 = match8; +var matchCause2 = matchCause; +var matchCauseEffect3 = matchCauseEffect; +var matchEffect2 = matchEffect; +var log2 = log; +var logWithLevel2 = (level, ...message) => logWithLevel(level)(...message); +var logTrace2 = logTrace; +var logDebug2 = logDebug; +var logInfo2 = logInfo; +var logWarning2 = logWarning; +var logError2 = logError; +var logFatal2 = logFatal; +var withLogSpan2 = withLogSpan; +var annotateLogs2 = annotateLogs; +var annotateLogsScoped2 = annotateLogsScoped; +var logAnnotations2 = logAnnotations; +var withUnhandledErrorLogLevel2 = withUnhandledErrorLogLevel; +var whenLogLevel2 = whenLogLevel; +var orDie2 = orDie; +var orDieWith2 = orDieWith; +var orElse3 = orElse2; +var orElseFail2 = orElseFail; +var orElseSucceed2 = orElseSucceed; +var firstSuccessOf2 = firstSuccessOf; +var random3 = random2; +var randomWith2 = randomWith; +var withRandom2 = withRandom; +var withRandomFixed = /* @__PURE__ */ dual(2, (effect, values4) => withRandom2(effect, fixed2(values4))); +var withRandomScoped2 = withRandomScoped; +var runtime4 = runtime3; +var getRuntimeFlags = runtimeFlags; +var patchRuntimeFlags = updateRuntimeFlags; +var withRuntimeFlagsPatch = withRuntimeFlags; +var withRuntimeFlagsPatchScoped = withRuntimeFlagsScoped; +var tagMetrics2 = tagMetrics; +var labelMetrics2 = labelMetrics; +var tagMetricsScoped2 = tagMetricsScoped; +var labelMetricsScoped2 = labelMetricsScoped; +var metricLabels2 = metricLabels; +var withMetric2 = withMetric; +var unsafeMakeSemaphore2 = unsafeMakeSemaphore; +var makeSemaphore2 = makeSemaphore; +var unsafeMakeLatch2 = unsafeMakeLatch; +var makeLatch2 = makeLatch; +var runFork2 = unsafeForkEffect; +var runCallback = unsafeRunEffect; +var runPromise = unsafeRunPromiseEffect; +var runPromiseExit = unsafeRunPromiseExitEffect; +var runSync = unsafeRunSyncEffect; +var runSyncExit = unsafeRunSyncExitEffect; +var validate2 = validate; +var validateWith2 = validateWith; +var zip4 = zipOptions; +var zipLeft2 = zipLeftOptions; +var zipRight2 = zipRightOptions; +var zipWith3 = zipWithOptions; +var ap = /* @__PURE__ */ dual(2, (self, that) => zipWith3(self, that, (f, a) => f(a))); +var blocked2 = blocked; +var runRequestBlock2 = runRequestBlock; +var step3 = step2; +var request = /* @__PURE__ */ dual((args2) => isRequest2(args2[0]), fromRequest); +var cacheRequestResult = cacheRequest; +var withRequestBatching2 = withRequestBatching; +var withRequestCaching2 = withRequestCaching; +var withRequestCache2 = withRequestCache; +var tracer2 = tracer; +var tracerWith4 = tracerWith; +var withTracer2 = withTracer; +var withTracerScoped2 = withTracerScoped; +var withTracerEnabled2 = withTracerEnabled; +var withTracerTiming2 = withTracerTiming; +var annotateSpans2 = annotateSpans; +var annotateCurrentSpan2 = annotateCurrentSpan; +var currentSpan2 = currentSpan; +var currentPropagatedSpan2 = currentPropagatedSpan; +var currentParentSpan2 = currentParentSpan; +var spanAnnotations2 = spanAnnotations; +var spanLinks2 = spanLinks; +var linkSpans2 = linkSpans; +var linkSpanCurrent2 = linkSpanCurrent; +var makeSpan2 = makeSpan; +var makeSpanScoped2 = makeSpanScoped; +var useSpan2 = useSpan; +var withSpan2 = withSpan; +var functionWithSpan2 = functionWithSpan; +var withSpanScoped2 = withSpanScoped; +var withParentSpan2 = withParentSpan; +var fromNullable3 = fromNullable2; +var optionFromOptional2 = optionFromOptional; +var transposeOption = (self) => { + return isNone(self) ? succeedNone2 : map11(self.value, some); }; -var compare = ([a], [b]) => a > b ? 1 : a < b ? -1 : 0; -function sortByIndex(es) { - return es.sort(compare).map((t) => t[1]); -} -var getFinalTransformation = (transformation, isDecoding) => { - switch (transformation._tag) { - case "FinalTransformation": - return isDecoding ? transformation.decode : transformation.encode; - case "ComposeTransformation": - return right2; - case "TypeLiteralTransformation": - return (input) => { - let out = right2(input); - for (const pst of transformation.propertySignatureTransformations) { - const [from, to] = isDecoding ? [pst.from, pst.to] : [pst.to, pst.from]; - const transformation2 = isDecoding ? pst.decode : pst.encode; - const f = (input2) => { - const o = transformation2(Object.prototype.hasOwnProperty.call(input2, from) ? some2(input2[from]) : none2()); - delete input2[from]; - if (isSome2(o)) { - input2[to] = o.value; - } - return input2; - }; - out = map13(out, f); +var transposeMapOption = /* @__PURE__ */ dual(2, (self, f) => isNone(self) ? succeedNone2 : map11(f(self.value), some)); +var makeTagProxy = (TagClass) => { + const cache = new Map; + return new Proxy(TagClass, { + get(target, prop, receiver) { + if (prop in target) { + return Reflect.get(target, prop, receiver); + } + if (cache.has(prop)) { + return cache.get(prop); + } + const fn = (...args2) => andThen2(target, (s) => { + if (typeof s[prop] === "function") { + cache.set(prop, (...args3) => andThen2(target, (s2) => s2[prop](...args3))); + return s[prop](...args2); } - return out; - }; - } -}; -var makeTree = (value2, forest = []) => ({ - value: value2, - forest -}); -var TreeFormatter = { - formatIssue: (issue) => map13(formatTree(issue), drawTree), - formatIssueSync: (issue) => { - const e = TreeFormatter.formatIssue(issue); - return isEither3(e) ? getOrThrow(e) : runSync(e); - }, - formatError: (error) => TreeFormatter.formatIssue(error.issue), - formatErrorSync: (error) => TreeFormatter.formatIssueSync(error.issue) -}; -var drawTree = (tree) => tree.value + draw(` -`, tree.forest); -var draw = (indentation, forest) => { - let r = ""; - const len = forest.length; - let tree; - for (let i = 0;i < len; i++) { - tree = forest[i]; - const isLast = i === len - 1; - r += indentation + (isLast ? "\u2514" : "\u251C") + "\u2500 " + tree.value; - r += draw(indentation + (len > 1 && !isLast ? "\u2502 " : " "), tree.forest); - } - return r; -}; -var formatTransformationKind = (kind) => { - switch (kind) { - case "Encoded": - return "Encoded side transformation failure"; - case "Transformation": - return "Transformation process failure"; - case "Type": - return "Type side transformation failure"; - } -}; -var formatRefinementKind = (kind) => { - switch (kind) { - case "From": - return "From side refinement failure"; - case "Predicate": - return "Predicate refinement failure"; - } -}; -var getAnnotated = (issue) => ("ast" in issue) ? some2(issue.ast) : none2(); -var Either_void = /* @__PURE__ */ right2(undefined); -var getCurrentMessage = (issue) => getAnnotated(issue).pipe(flatMap(getMessageAnnotation), match2({ - onNone: () => Either_void, - onSome: (messageAnnotation) => { - const union8 = messageAnnotation(issue); - if (isString(union8)) { - return right2({ - message: union8, - override: false + cache.set(prop, andThen2(target, (s2) => s2[prop])); + return s[prop]; }); + const cn = andThen2(target, (s) => s[prop]); + Object.assign(fn, cn); + const apply = fn.apply; + const bind4 = fn.bind; + const call = fn.call; + const proto4 = Object.setPrototypeOf({}, Object.getPrototypeOf(cn)); + proto4.apply = apply; + proto4.bind = bind4; + proto4.call = call; + Object.setPrototypeOf(fn, proto4); + cache.set(prop, fn); + return fn; } - if (isEffect2(union8)) { - return map11(union8, (message) => ({ - message, - override: false - })); + }); +}; +var Tag2 = (id) => () => { + const limit = Error.stackTraceLimit; + Error.stackTraceLimit = 2; + const creationError = new Error; + Error.stackTraceLimit = limit; + function TagClass() {} + Object.setPrototypeOf(TagClass, TagProto); + TagClass.key = id; + Object.defineProperty(TagClass, "use", { + get() { + return (body) => andThen2(this, body); } - if (isString(union8.message)) { - return right2({ - message: union8.message, - override: union8.override - }); + }); + Object.defineProperty(TagClass, "stack", { + get() { + return creationError.stack; } - return map11(union8.message, (message) => ({ - message, - override: union8.override - })); - } -})); -var createParseIssueGuard = (tag) => (issue) => issue._tag === tag; -var isComposite2 = /* @__PURE__ */ createParseIssueGuard("Composite"); -var isRefinement2 = /* @__PURE__ */ createParseIssueGuard("Refinement"); -var isTransformation2 = /* @__PURE__ */ createParseIssueGuard("Transformation"); -var getMessage = (issue) => flatMap10(getCurrentMessage(issue), (currentMessage) => { - if (currentMessage !== undefined) { - const useInnerMessage = !currentMessage.override && (isComposite2(issue) || isRefinement2(issue) && issue.kind === "From" || isTransformation2(issue) && issue.kind !== "Transformation"); - return useInnerMessage ? isTransformation2(issue) || isRefinement2(issue) ? getMessage(issue.issue) : Either_void : right2(currentMessage.message); - } - return Either_void; -}); -var getParseIssueTitleAnnotation2 = (issue) => getAnnotated(issue).pipe(flatMap(getParseIssueTitleAnnotation), flatMapNullable((annotation) => annotation(issue)), getOrUndefined); -function getRefinementExpected(ast) { - return getDescriptionAnnotation(ast).pipe(orElse(() => getTitleAnnotation(ast)), orElse(() => getAutoTitleAnnotation(ast)), orElse(() => getIdentifierAnnotation(ast)), getOrElse(() => `{ ${ast.from} | filter }`)); -} -function getDefaultTypeMessage(issue) { - if (issue.message !== undefined) { - return issue.message; - } - const expected = isRefinement(issue.ast) ? getRefinementExpected(issue.ast) : String(issue.ast); - return `Expected ${expected}, actual ${formatUnknown(issue.actual)}`; -} -var formatTypeMessage = (issue) => map13(getMessage(issue), (message) => message ?? getParseIssueTitleAnnotation2(issue) ?? getDefaultTypeMessage(issue)); -var getParseIssueTitle = (issue) => getParseIssueTitleAnnotation2(issue) ?? String(issue.ast); -var formatForbiddenMessage = (issue) => issue.message ?? "is forbidden"; -var formatUnexpectedMessage = (issue) => issue.message ?? "is unexpected"; -var formatMissingMessage = (issue) => { - const missingMessageAnnotation = getMissingMessageAnnotation(issue.ast); - if (isSome2(missingMessageAnnotation)) { - const annotation = missingMessageAnnotation.value(); - return isString(annotation) ? right2(annotation) : annotation; - } - return right2(issue.message ?? "is missing"); + }); + return makeTagProxy(TagClass); }; -var formatTree = (issue) => { - switch (issue._tag) { - case "Type": - return map13(formatTypeMessage(issue), makeTree); - case "Forbidden": - return right2(makeTree(getParseIssueTitle(issue), [makeTree(formatForbiddenMessage(issue))])); - case "Unexpected": - return right2(makeTree(formatUnexpectedMessage(issue))); - case "Missing": - return map13(formatMissingMessage(issue), makeTree); - case "Transformation": - return flatMap10(getMessage(issue), (message) => { - if (message !== undefined) { - return right2(makeTree(message)); +var Service = function() { + return function() { + const [id, maker] = arguments; + const proxy = "accessors" in maker ? maker["accessors"] : false; + const limit = Error.stackTraceLimit; + Error.stackTraceLimit = 2; + const creationError = new Error; + Error.stackTraceLimit = limit; + let patchState = "unchecked"; + const TagClass = function(service) { + if (patchState === "unchecked") { + const proto4 = Object.getPrototypeOf(service); + if (proto4 === Object.prototype || proto4 === null) { + patchState = "plain"; + } else { + const selfProto = Object.getPrototypeOf(this); + Object.setPrototypeOf(selfProto, proto4); + patchState = "patched"; + } + } + if (patchState === "plain") { + Object.assign(this, service); + } else if (patchState === "patched") { + Object.setPrototypeOf(service, Object.getPrototypeOf(this)); + return service; + } + }; + TagClass.prototype._tag = id; + Object.defineProperty(TagClass, "make", { + get() { + return (service) => new this(service); + } + }); + Object.defineProperty(TagClass, "use", { + get() { + return (body) => andThen2(this, body); + } + }); + TagClass.key = id; + Object.assign(TagClass, TagProto); + Object.defineProperty(TagClass, "stack", { + get() { + return creationError.stack; + } + }); + const hasDeps = "dependencies" in maker && maker.dependencies.length > 0; + const layerName = hasDeps ? "DefaultWithoutDependencies" : "Default"; + let layerCache; + let isFunction3 = false; + if ("effect" in maker) { + isFunction3 = typeof maker.effect === "function"; + Object.defineProperty(TagClass, layerName, { + get() { + if (isFunction3) { + return function() { + return fromEffect2(TagClass, map11(maker.effect.apply(null, arguments), (_) => new this(_))); + }.bind(this); + } + return layerCache ??= fromEffect2(TagClass, map11(maker.effect, (_) => new this(_))); } - return map13(formatTree(issue.issue), (tree) => makeTree(getParseIssueTitle(issue), [makeTree(formatTransformationKind(issue.kind), [tree])])); }); - case "Refinement": - return flatMap10(getMessage(issue), (message) => { - if (message !== undefined) { - return right2(makeTree(message)); + } else if ("scoped" in maker) { + isFunction3 = typeof maker.scoped === "function"; + Object.defineProperty(TagClass, layerName, { + get() { + if (isFunction3) { + return function() { + return scoped(TagClass, map11(maker.scoped.apply(null, arguments), (_) => new this(_))); + }.bind(this); + } + return layerCache ??= scoped(TagClass, map11(maker.scoped, (_) => new this(_))); } - return map13(formatTree(issue.issue), (tree) => makeTree(getParseIssueTitle(issue), [makeTree(formatRefinementKind(issue.kind), [tree])])); }); - case "Pointer": - return map13(formatTree(issue.issue), (tree) => makeTree(formatPath(issue.path), [tree])); - case "Composite": - return flatMap10(getMessage(issue), (message) => { - if (message !== undefined) { - return right2(makeTree(message)); + } else if ("sync" in maker) { + Object.defineProperty(TagClass, layerName, { + get() { + return layerCache ??= sync2(TagClass, () => new this(maker.sync())); } - const parseIssueTitle = getParseIssueTitle(issue); - return isNonEmpty(issue.issues) ? map13(forEach7(issue.issues, formatTree), (forest) => makeTree(parseIssueTitle, forest)) : map13(formatTree(issue.issues), (tree) => makeTree(parseIssueTitle, [tree])); }); - } -}; -var makeArrayFormatterIssue = (_tag, path, message) => ({ - _tag, - path, - message -}); -var ArrayFormatter = { - formatIssue: (issue) => getArrayFormatterIssues(issue, undefined, []), - formatIssueSync: (issue) => { - const e = ArrayFormatter.formatIssue(issue); - return isEither3(e) ? getOrThrow(e) : runSync(e); - }, - formatError: (error) => ArrayFormatter.formatIssue(error.issue), - formatErrorSync: (error) => ArrayFormatter.formatIssueSync(error.issue) -}; -var getArrayFormatterIssues = (issue, parentTag, path) => { - const _tag = issue._tag; - switch (_tag) { - case "Type": - return map13(formatTypeMessage(issue), (message) => [makeArrayFormatterIssue(parentTag ?? _tag, path, message)]); - case "Forbidden": - return right2([makeArrayFormatterIssue(_tag, path, formatForbiddenMessage(issue))]); - case "Unexpected": - return right2([makeArrayFormatterIssue(_tag, path, formatUnexpectedMessage(issue))]); - case "Missing": - return map13(formatMissingMessage(issue), (message) => [makeArrayFormatterIssue(_tag, path, message)]); - case "Pointer": - return getArrayFormatterIssues(issue.issue, undefined, path.concat(issue.path)); - case "Composite": - return flatMap10(getMessage(issue), (message) => { - if (message !== undefined) { - return right2([makeArrayFormatterIssue(_tag, path, message)]); + } else { + Object.defineProperty(TagClass, layerName, { + get() { + return layerCache ??= succeed4(TagClass, new this(maker.succeed)); } - return isNonEmpty(issue.issues) ? map13(forEach7(issue.issues, (issue2) => getArrayFormatterIssues(issue2, undefined, path)), flatten) : getArrayFormatterIssues(issue.issues, undefined, path); }); - case "Refinement": - return flatMap10(getMessage(issue), (message) => { - if (message !== undefined) { - return right2([makeArrayFormatterIssue(_tag, path, message)]); + } + if (hasDeps) { + let layerWithDepsCache; + Object.defineProperty(TagClass, "Default", { + get() { + if (isFunction3) { + return function() { + return provide(this.DefaultWithoutDependencies.apply(null, arguments), maker.dependencies); + }; + } + return layerWithDepsCache ??= provide(this.DefaultWithoutDependencies, maker.dependencies); } - return getArrayFormatterIssues(issue.issue, issue.kind === "Predicate" ? _tag : undefined, path); }); - case "Transformation": - return flatMap10(getMessage(issue), (message) => { - if (message !== undefined) { - return right2([makeArrayFormatterIssue(_tag, path, message)]); - } - return getArrayFormatterIssues(issue.issue, issue.kind === "Transformation" ? _tag : undefined, path); + } + return proxy === true ? makeTagProxy(TagClass) : TagClass; + }; +}; +var fn = function(nameOrBody, ...pipeables) { + const limit = Error.stackTraceLimit; + Error.stackTraceLimit = 2; + const errorDef = new Error; + Error.stackTraceLimit = limit; + if (typeof nameOrBody !== "string") { + return defineLength(nameOrBody.length, function(...args2) { + const limit2 = Error.stackTraceLimit; + Error.stackTraceLimit = 2; + const errorCall = new Error; + Error.stackTraceLimit = limit2; + return fnApply({ + self: this, + body: nameOrBody, + args: args2, + pipeables, + spanName: "", + spanOptions: { + context: DisablePropagation.context(true) + }, + errorDef, + errorCall }); + }); } + const name = nameOrBody; + const options = pipeables[0]; + return (body, ...pipeables2) => defineLength(body.length, { + [name](...args2) { + const limit2 = Error.stackTraceLimit; + Error.stackTraceLimit = 2; + const errorCall = new Error; + Error.stackTraceLimit = limit2; + return fnApply({ + self: this, + body, + args: args2, + pipeables: pipeables2, + spanName: name, + spanOptions: options, + errorDef, + errorCall + }); + } + }[name]); }; -// node_modules/effect/dist/esm/Redacted.js -var isRedacted2 = isRedacted; -var make42 = make40; -var value2 = value; -var getEquivalence7 = (isEquivalent) => make((x, y) => isEquivalent(value2(x), value2(y))); +function defineLength(length2, fn2) { + return Object.defineProperty(fn2, "length", { + value: length2, + configurable: true + }); +} +function fnApply(options) { + let effect; + let fnError = undefined; + if (isGeneratorFunction(options.body)) { + effect = fromIterator(() => options.body.apply(options.self, options.args)); + } else { + try { + effect = options.body.apply(options.self, options.args); + } catch (error) { + fnError = error; + effect = die4(error); + } + } + if (options.pipeables.length > 0) { + try { + for (const x of options.pipeables) { + effect = x(effect, ...options.args); + } + } catch (error) { + effect = fnError ? failCause5(sequential(die(fnError), die(error))) : die4(error); + } + } + let cache = false; + const captureStackTrace = () => { + if (cache !== false) { + return cache; + } + if (options.errorCall.stack) { + const stackDef = options.errorDef.stack.trim().split(` +`); + const stackCall = options.errorCall.stack.trim().split(` +`); + let endStackDef = stackDef.slice(2).join(` +`).trim(); + if (!endStackDef.includes(`(`)) { + endStackDef = endStackDef.replace(/at (.*)/, "at ($1)"); + } + let endStackCall = stackCall.slice(2).join(` +`).trim(); + if (!endStackCall.includes(`(`)) { + endStackCall = endStackCall.replace(/at (.*)/, "at ($1)"); + } + cache = `${endStackDef} +${endStackCall}`; + return cache; + } + }; + const opts = options.spanOptions && "captureStackTrace" in options.spanOptions ? options.spanOptions : { + captureStackTrace, + ...options.spanOptions + }; + return withSpan2(effect, options.spanName, opts); +} +var fnUntraced2 = fnUntraced; +var ensureSuccessType = () => (effect) => effect; +var ensureErrorType = () => (effect) => effect; +var ensureRequirementsType = () => (effect) => effect; // node_modules/effect/dist/esm/Schema.js var exports_Schema = {}; __export(exports_Schema, { @@ -19550,6 +15221,4350 @@ __export(exports_Schema, { Any: () => Any }); +// node_modules/effect/dist/esm/BigDecimal.js +var FINITE_INT_REGEX = /^[+-]?\d+$/; +var TypeId17 = /* @__PURE__ */ Symbol.for("effect/BigDecimal"); +var BigDecimalProto = { + [TypeId17]: TypeId17, + [symbol]() { + const normalized = normalize(this); + return pipe(hash(normalized.value), combine(number2(normalized.scale)), cached(this)); + }, + [symbol2](that) { + return isBigDecimal(that) && equals3(this, that); + }, + toString() { + return `BigDecimal(${format4(this)})`; + }, + toJSON() { + return { + _id: "BigDecimal", + value: String(this.value), + scale: this.scale + }; + }, + [NodeInspectSymbol]() { + return this.toJSON(); + }, + pipe() { + return pipeArguments(this, arguments); + } +}; +var isBigDecimal = (u) => hasProperty(u, TypeId17); +var make39 = (value, scale) => { + const o = Object.create(BigDecimalProto); + o.value = value; + o.scale = scale; + return o; +}; +var unsafeMakeNormalized = (value, scale) => { + if (value !== bigint04 && value % bigint10 === bigint04) { + throw new RangeError("Value must be normalized"); + } + const o = make39(value, scale); + o.normalized = o; + return o; +}; +var bigint04 = /* @__PURE__ */ BigInt(0); +var bigint10 = /* @__PURE__ */ BigInt(10); +var zero2 = /* @__PURE__ */ unsafeMakeNormalized(bigint04, 0); +var normalize = (self) => { + if (self.normalized === undefined) { + if (self.value === bigint04) { + self.normalized = zero2; + } else { + const digits = `${self.value}`; + let trail = 0; + for (let i = digits.length - 1;i >= 0; i--) { + if (digits[i] === "0") { + trail++; + } else { + break; + } + } + if (trail === 0) { + self.normalized = self; + } + const value = BigInt(digits.substring(0, digits.length - trail)); + const scale = self.scale - trail; + self.normalized = unsafeMakeNormalized(value, scale); + } + } + return self.normalized; +}; +var scale = /* @__PURE__ */ dual(2, (self, scale2) => { + if (scale2 > self.scale) { + return make39(self.value * bigint10 ** BigInt(scale2 - self.scale), scale2); + } + if (scale2 < self.scale) { + return make39(self.value / bigint10 ** BigInt(self.scale - scale2), scale2); + } + return self; +}); +var Order4 = /* @__PURE__ */ make2((self, that) => { + const scmp = number3(sign(self), sign(that)); + if (scmp !== 0) { + return scmp; + } + if (self.scale > that.scale) { + return bigint(self.value, scale(that, self.scale).value); + } + if (self.scale < that.scale) { + return bigint(scale(self, that.scale).value, that.value); + } + return bigint(self.value, that.value); +}); +var lessThan7 = /* @__PURE__ */ lessThan(Order4); +var lessThanOrEqualTo3 = /* @__PURE__ */ lessThanOrEqualTo(Order4); +var greaterThan4 = /* @__PURE__ */ greaterThan(Order4); +var greaterThanOrEqualTo3 = /* @__PURE__ */ greaterThanOrEqualTo(Order4); +var between3 = /* @__PURE__ */ between(Order4); +var clamp5 = /* @__PURE__ */ clamp(Order4); +var sign = (n) => n.value === bigint04 ? 0 : n.value < bigint04 ? -1 : 1; +var abs = (n) => n.value < bigint04 ? make39(-n.value, n.scale) : n; +var Equivalence3 = /* @__PURE__ */ make((self, that) => { + if (self.scale > that.scale) { + return scale(that, self.scale).value === self.value; + } + if (self.scale < that.scale) { + return scale(self, that.scale).value === that.value; + } + return self.value === that.value; +}); +var equals3 = /* @__PURE__ */ dual(2, (self, that) => Equivalence3(self, that)); +var unsafeFromNumber = (n) => getOrThrowWith2(safeFromNumber(n), () => new RangeError(`Number must be finite, got ${n}`)); +var safeFromNumber = (n) => { + if (!Number.isFinite(n)) { + return none2(); + } + const string2 = `${n}`; + if (string2.includes("e")) { + return fromString(string2); + } + const [lead, trail = ""] = string2.split("."); + return some2(make39(BigInt(`${lead}${trail}`), trail.length)); +}; +var fromString = (s) => { + if (s === "") { + return some2(zero2); + } + let base; + let exp; + const seperator = s.search(/[eE]/); + if (seperator !== -1) { + const trail = s.slice(seperator + 1); + base = s.slice(0, seperator); + exp = Number(trail); + if (base === "" || !Number.isSafeInteger(exp) || !FINITE_INT_REGEX.test(trail)) { + return none2(); + } + } else { + base = s; + exp = 0; + } + let digits; + let offset; + const dot = base.search(/\./); + if (dot !== -1) { + const lead = base.slice(0, dot); + const trail = base.slice(dot + 1); + digits = `${lead}${trail}`; + offset = trail.length; + } else { + digits = base; + offset = 0; + } + if (!FINITE_INT_REGEX.test(digits)) { + return none2(); + } + const scale2 = offset - exp; + if (!Number.isSafeInteger(scale2)) { + return none2(); + } + return some2(make39(BigInt(digits), scale2)); +}; +var format4 = (n) => { + const normalized = normalize(n); + if (Math.abs(normalized.scale) >= 16) { + return toExponential(normalized); + } + const negative = normalized.value < bigint04; + const absolute = negative ? `${normalized.value}`.substring(1) : `${normalized.value}`; + let before2; + let after3; + if (normalized.scale >= absolute.length) { + before2 = "0"; + after3 = "0".repeat(normalized.scale - absolute.length) + absolute; + } else { + const location = absolute.length - normalized.scale; + if (location > absolute.length) { + const zeros = location - absolute.length; + before2 = `${absolute}${"0".repeat(zeros)}`; + after3 = ""; + } else { + after3 = absolute.slice(location); + before2 = absolute.slice(0, location); + } + } + const complete3 = after3 === "" ? before2 : `${before2}.${after3}`; + return negative ? `-${complete3}` : complete3; +}; +var toExponential = (n) => { + if (isZero2(n)) { + return "0e+0"; + } + const normalized = normalize(n); + const digits = `${abs(normalized).value}`; + const head5 = digits.slice(0, 1); + const tail = digits.slice(1); + let output = `${isNegative(normalized) ? "-" : ""}${head5}`; + if (tail !== "") { + output += `.${tail}`; + } + const exp = tail.length - normalized.scale; + return `${output}e${exp >= 0 ? "+" : ""}${exp}`; +}; +var unsafeToNumber = (n) => Number(format4(n)); +var isZero2 = (n) => n.value === bigint04; +var isNegative = (n) => n.value < bigint04; +var isPositive = (n) => n.value > bigint04; + +// node_modules/effect/dist/esm/BigInt.js +var Order5 = bigint; +var clamp6 = /* @__PURE__ */ clamp(Order5); +var toNumber = (b) => { + if (b > BigInt(Number.MAX_SAFE_INTEGER) || b < BigInt(Number.MIN_SAFE_INTEGER)) { + return none2(); + } + return some2(Number(b)); +}; +var fromString2 = (s) => { + try { + return s.trim() === "" ? none2() : some2(BigInt(s)); + } catch { + return none2(); + } +}; +var fromNumber = (n) => { + if (n > Number.MAX_SAFE_INTEGER || n < Number.MIN_SAFE_INTEGER) { + return none2(); + } + try { + return some2(BigInt(n)); + } catch { + return none2(); + } +}; + +// node_modules/effect/dist/esm/ConfigError.js +var InvalidData2 = InvalidData; + +// node_modules/effect/dist/esm/internal/redacted.js +var RedactedSymbolKey = "effect/Redacted"; +var redactedRegistry = /* @__PURE__ */ globalValue("effect/Redacted/redactedRegistry", () => new WeakMap); +var RedactedTypeId = /* @__PURE__ */ Symbol.for(RedactedSymbolKey); +var proto4 = { + [RedactedTypeId]: { + _A: (_) => _ + }, + pipe() { + return pipeArguments(this, arguments); + }, + toString() { + return ""; + }, + toJSON() { + return ""; + }, + [NodeInspectSymbol]() { + return ""; + }, + [symbol]() { + return pipe(hash(RedactedSymbolKey), combine(hash(redactedRegistry.get(this))), cached(this)); + }, + [symbol2](that) { + return isRedacted(that) && equals(redactedRegistry.get(this), redactedRegistry.get(that)); + } +}; +var isRedacted = (u) => hasProperty(u, RedactedTypeId); +var make40 = (value) => { + const redacted = Object.create(proto4); + redactedRegistry.set(redacted, value); + return redacted; +}; +var value = (self) => { + if (redactedRegistry.has(self)) { + return redactedRegistry.get(self); + } else { + throw new Error("Unable to get redacted value"); + } +}; + +// node_modules/effect/dist/esm/internal/config.js +var ConfigSymbolKey = "effect/Config"; +var ConfigTypeId = /* @__PURE__ */ Symbol.for(ConfigSymbolKey); +var configVariance = { + _A: (_) => _ +}; +var proto5 = { + ...CommitPrototype, + [ConfigTypeId]: configVariance, + commit() { + return config(this); + } +}; +var mapOrFail = /* @__PURE__ */ dual(2, (self, f) => { + const mapOrFail2 = Object.create(proto5); + mapOrFail2._tag = OP_MAP_OR_FAIL; + mapOrFail2.original = self; + mapOrFail2.mapOrFail = f; + return mapOrFail2; +}); +var nested2 = /* @__PURE__ */ dual(2, (self, name) => { + const nested3 = Object.create(proto5); + nested3._tag = OP_NESTED; + nested3.name = name; + nested3.config = self; + return nested3; +}); +var primitive = (description, parse2) => { + const primitive2 = Object.create(proto5); + primitive2._tag = OP_PRIMITIVE; + primitive2.description = description; + primitive2.parse = parse2; + return primitive2; +}; +var string2 = (name) => { + const config2 = primitive("a text property", right2); + return name === undefined ? config2 : nested2(config2, name); +}; + +// node_modules/effect/dist/esm/Config.js +var mapOrFail2 = mapOrFail; +var string3 = string2; + +// node_modules/effect/dist/esm/DateTime.js +var isDateTime2 = isDateTime; +var isTimeZoneOffset2 = isTimeZoneOffset; +var isTimeZoneNamed2 = isTimeZoneNamed; +var isUtc2 = isUtc; +var isZoned2 = isZoned; +var Equivalence4 = Equivalence2; +var unsafeFromDate2 = unsafeFromDate; +var unsafeMake9 = unsafeMake7; +var unsafeMakeZoned2 = unsafeMakeZoned; +var makeZonedFromString2 = makeZonedFromString; +var zoneUnsafeMakeNamed2 = zoneUnsafeMakeNamed; +var zoneMakeOffset2 = zoneMakeOffset; +var zoneFromString2 = zoneFromString; +var zoneToString2 = zoneToString; +var toDateUtc2 = toDateUtc; +var toEpochMillis2 = toEpochMillis; +var formatIso2 = formatIso; +var formatIsoZoned2 = formatIsoZoned; + +// node_modules/effect/dist/esm/internal/encoding/common.js +var DecodeExceptionTypeId = /* @__PURE__ */ Symbol.for("effect/Encoding/errors/Decode"); +var DecodeException = (input, message) => { + const out = { + _tag: "DecodeException", + [DecodeExceptionTypeId]: DecodeExceptionTypeId, + input + }; + if (isString(message)) { + out.message = message; + } + return out; +}; +var EncodeExceptionTypeId = /* @__PURE__ */ Symbol.for("effect/Encoding/errors/Encode"); +var EncodeException = (input, message) => { + const out = { + _tag: "EncodeException", + [EncodeExceptionTypeId]: EncodeExceptionTypeId, + input + }; + if (isString(message)) { + out.message = message; + } + return out; +}; +var encoder = /* @__PURE__ */ new TextEncoder; +var decoder = /* @__PURE__ */ new TextDecoder; + +// node_modules/effect/dist/esm/internal/encoding/base64.js +var encode = (bytes) => { + const length2 = bytes.length; + let result = ""; + let i; + for (i = 2;i < length2; i += 3) { + result += base64abc[bytes[i - 2] >> 2]; + result += base64abc[(bytes[i - 2] & 3) << 4 | bytes[i - 1] >> 4]; + result += base64abc[(bytes[i - 1] & 15) << 2 | bytes[i] >> 6]; + result += base64abc[bytes[i] & 63]; + } + if (i === length2 + 1) { + result += base64abc[bytes[i - 2] >> 2]; + result += base64abc[(bytes[i - 2] & 3) << 4]; + result += "=="; + } + if (i === length2) { + result += base64abc[bytes[i - 2] >> 2]; + result += base64abc[(bytes[i - 2] & 3) << 4 | bytes[i - 1] >> 4]; + result += base64abc[(bytes[i - 1] & 15) << 2]; + result += "="; + } + return result; +}; +var decode2 = (str) => { + const stripped = stripCrlf(str); + const length2 = stripped.length; + if (length2 % 4 !== 0) { + return left2(DecodeException(stripped, `Length must be a multiple of 4, but is ${length2}`)); + } + const index = stripped.indexOf("="); + if (index !== -1 && (index < length2 - 2 || index === length2 - 2 && stripped[length2 - 1] !== "=")) { + return left2(DecodeException(stripped, "Found a '=' character, but it is not at the end")); + } + try { + const missingOctets = stripped.endsWith("==") ? 2 : stripped.endsWith("=") ? 1 : 0; + const result = new Uint8Array(3 * (length2 / 4) - missingOctets); + for (let i = 0, j = 0;i < length2; i += 4, j += 3) { + const buffer = getBase64Code(stripped.charCodeAt(i)) << 18 | getBase64Code(stripped.charCodeAt(i + 1)) << 12 | getBase64Code(stripped.charCodeAt(i + 2)) << 6 | getBase64Code(stripped.charCodeAt(i + 3)); + result[j] = buffer >> 16; + result[j + 1] = buffer >> 8 & 255; + result[j + 2] = buffer & 255; + } + return right2(result); + } catch (e) { + return left2(DecodeException(stripped, e instanceof Error ? e.message : "Invalid input")); + } +}; +var stripCrlf = (str) => str.replace(/[\n\r]/g, ""); +function getBase64Code(charCode) { + if (charCode >= base64codes.length) { + throw new TypeError(`Invalid character ${String.fromCharCode(charCode)}`); + } + const code = base64codes[charCode]; + if (code === 255) { + throw new TypeError(`Invalid character ${String.fromCharCode(charCode)}`); + } + return code; +} +var base64abc = ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "+", "/"]; +var base64codes = [255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 62, 255, 255, 255, 63, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 255, 255, 255, 0, 255, 255, 255, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 255, 255, 255, 255, 255, 255, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51]; + +// node_modules/effect/dist/esm/internal/encoding/base64Url.js +var encode2 = (data) => encode(data).replace(/=/g, "").replace(/\+/g, "-").replace(/\//g, "_"); +var decode3 = (str) => { + const stripped = stripCrlf(str); + const length2 = stripped.length; + if (length2 % 4 === 1) { + return left2(DecodeException(stripped, `Length should be a multiple of 4, but is ${length2}`)); + } + if (!/^[-_A-Z0-9]*?={0,2}$/i.test(stripped)) { + return left2(DecodeException(stripped, "Invalid input")); + } + let sanitized = length2 % 4 === 2 ? `${stripped}==` : length2 % 4 === 3 ? `${stripped}=` : stripped; + sanitized = sanitized.replace(/-/g, "+").replace(/_/g, "/"); + return decode2(sanitized); +}; + +// node_modules/effect/dist/esm/internal/encoding/hex.js +var encode3 = (bytes) => { + let result = ""; + for (let i = 0;i < bytes.length; ++i) { + result += bytesToHex[bytes[i]]; + } + return result; +}; +var decode4 = (str) => { + const bytes = new TextEncoder().encode(str); + if (bytes.length % 2 !== 0) { + return left2(DecodeException(str, `Length must be a multiple of 2, but is ${bytes.length}`)); + } + try { + const length2 = bytes.length / 2; + const result = new Uint8Array(length2); + for (let i = 0;i < length2; i++) { + const a = fromHexChar(bytes[i * 2]); + const b = fromHexChar(bytes[i * 2 + 1]); + result[i] = a << 4 | b; + } + return right2(result); + } catch (e) { + return left2(DecodeException(str, e instanceof Error ? e.message : "Invalid input")); + } +}; +var bytesToHex = ["00", "01", "02", "03", "04", "05", "06", "07", "08", "09", "0a", "0b", "0c", "0d", "0e", "0f", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "1a", "1b", "1c", "1d", "1e", "1f", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "2a", "2b", "2c", "2d", "2e", "2f", "30", "31", "32", "33", "34", "35", "36", "37", "38", "39", "3a", "3b", "3c", "3d", "3e", "3f", "40", "41", "42", "43", "44", "45", "46", "47", "48", "49", "4a", "4b", "4c", "4d", "4e", "4f", "50", "51", "52", "53", "54", "55", "56", "57", "58", "59", "5a", "5b", "5c", "5d", "5e", "5f", "60", "61", "62", "63", "64", "65", "66", "67", "68", "69", "6a", "6b", "6c", "6d", "6e", "6f", "70", "71", "72", "73", "74", "75", "76", "77", "78", "79", "7a", "7b", "7c", "7d", "7e", "7f", "80", "81", "82", "83", "84", "85", "86", "87", "88", "89", "8a", "8b", "8c", "8d", "8e", "8f", "90", "91", "92", "93", "94", "95", "96", "97", "98", "99", "9a", "9b", "9c", "9d", "9e", "9f", "a0", "a1", "a2", "a3", "a4", "a5", "a6", "a7", "a8", "a9", "aa", "ab", "ac", "ad", "ae", "af", "b0", "b1", "b2", "b3", "b4", "b5", "b6", "b7", "b8", "b9", "ba", "bb", "bc", "bd", "be", "bf", "c0", "c1", "c2", "c3", "c4", "c5", "c6", "c7", "c8", "c9", "ca", "cb", "cc", "cd", "ce", "cf", "d0", "d1", "d2", "d3", "d4", "d5", "d6", "d7", "d8", "d9", "da", "db", "dc", "dd", "de", "df", "e0", "e1", "e2", "e3", "e4", "e5", "e6", "e7", "e8", "e9", "ea", "eb", "ec", "ed", "ee", "ef", "f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7", "f8", "f9", "fa", "fb", "fc", "fd", "fe", "ff"]; +var fromHexChar = (byte) => { + if (48 <= byte && byte <= 57) { + return byte - 48; + } + if (97 <= byte && byte <= 102) { + return byte - 97 + 10; + } + if (65 <= byte && byte <= 70) { + return byte - 65 + 10; + } + throw new TypeError("Invalid input"); +}; + +// node_modules/effect/dist/esm/Encoding.js +var encodeBase64 = (input) => typeof input === "string" ? encode(encoder.encode(input)) : encode(input); +var decodeBase64 = (str) => decode2(str); +var decodeBase64String = (str) => map(decodeBase64(str), (_) => decoder.decode(_)); +var encodeBase64Url = (input) => typeof input === "string" ? encode2(encoder.encode(input)) : encode2(input); +var decodeBase64Url = (str) => decode3(str); +var decodeBase64UrlString = (str) => map(decodeBase64Url(str), (_) => decoder.decode(_)); +var encodeHex = (input) => typeof input === "string" ? encode3(encoder.encode(input)) : encode3(input); +var decodeHex = (str) => decode4(str); +var decodeHexString = (str) => map(decodeHex(str), (_) => decoder.decode(_)); +var encodeUriComponent = (str) => try_({ + try: () => encodeURIComponent(str), + catch: (e) => EncodeException2(str, e instanceof Error ? e.message : "Invalid input") +}); +var decodeUriComponent = (str) => try_({ + try: () => decodeURIComponent(str), + catch: (e) => DecodeException2(str, e instanceof Error ? e.message : "Invalid input") +}); +var DecodeException2 = DecodeException; +var EncodeException2 = EncodeException; + +// node_modules/fast-check/lib/esm/stream/StreamHelpers.js +class Nil { + [Symbol.iterator]() { + return this; + } + next(value2) { + return { value: value2, done: true }; + } +} +Nil.nil = new Nil; +function nilHelper() { + return Nil.nil; +} +function* mapHelper(g, f) { + for (const v of g) { + yield f(v); + } +} +function* flatMapHelper(g, f) { + for (const v of g) { + yield* f(v); + } +} +function* filterHelper(g, f) { + for (const v of g) { + if (f(v)) { + yield v; + } + } +} +function* takeNHelper(g, n) { + for (let i = 0;i < n; ++i) { + const cur = g.next(); + if (cur.done) { + break; + } + yield cur.value; + } +} +function* takeWhileHelper(g, f) { + let cur = g.next(); + while (!cur.done && f(cur.value)) { + yield cur.value; + cur = g.next(); + } +} +function* joinHelper(g, others) { + for (let cur = g.next();!cur.done; cur = g.next()) { + yield cur.value; + } + for (const s of others) { + for (let cur = s.next();!cur.done; cur = s.next()) { + yield cur.value; + } + } +} + +// node_modules/fast-check/lib/esm/stream/Stream.js +var safeSymbolIterator = Symbol.iterator; + +class Stream { + static nil() { + return new Stream(nilHelper()); + } + static of(...elements) { + return new Stream(elements[safeSymbolIterator]()); + } + constructor(g) { + this.g = g; + } + next() { + return this.g.next(); + } + [Symbol.iterator]() { + return this.g; + } + map(f) { + return new Stream(mapHelper(this.g, f)); + } + flatMap(f) { + return new Stream(flatMapHelper(this.g, f)); + } + dropWhile(f) { + let foundEligible = false; + function* helper(v) { + if (foundEligible || !f(v)) { + foundEligible = true; + yield v; + } + } + return this.flatMap(helper); + } + drop(n) { + if (n <= 0) { + return this; + } + let idx = 0; + function helper() { + return idx++ < n; + } + return this.dropWhile(helper); + } + takeWhile(f) { + return new Stream(takeWhileHelper(this.g, f)); + } + take(n) { + return new Stream(takeNHelper(this.g, n)); + } + filter(f) { + return new Stream(filterHelper(this.g, f)); + } + every(f) { + for (const v of this.g) { + if (!f(v)) { + return false; + } + } + return true; + } + has(f) { + for (const v of this.g) { + if (f(v)) { + return [true, v]; + } + } + return [false, null]; + } + join(...others) { + return new Stream(joinHelper(this.g, others)); + } + getNthOrLast(nth) { + let remaining = nth; + let last3 = null; + for (const v of this.g) { + if (remaining-- === 0) + return v; + last3 = v; + } + return last3; + } +} +function stream(g) { + return new Stream(g); +} + +// node_modules/fast-check/lib/esm/check/symbols.js +var cloneMethod = Symbol.for("fast-check/cloneMethod"); +function hasCloneMethod(instance) { + return instance !== null && (typeof instance === "object" || typeof instance === "function") && cloneMethod in instance && typeof instance[cloneMethod] === "function"; +} +function cloneIfNeeded(instance) { + return hasCloneMethod(instance) ? instance[cloneMethod]() : instance; +} + +// node_modules/fast-check/lib/esm/check/arbitrary/definition/Value.js +var safeObjectDefineProperty = Object.defineProperty; + +class Value { + constructor(value_, context4, customGetValue = undefined) { + this.value_ = value_; + this.context = context4; + this.hasToBeCloned = customGetValue !== undefined || hasCloneMethod(value_); + this.readOnce = false; + if (this.hasToBeCloned) { + safeObjectDefineProperty(this, "value", { get: customGetValue !== undefined ? customGetValue : this.getValue }); + } else { + this.value = value_; + } + } + getValue() { + if (this.hasToBeCloned) { + if (!this.readOnce) { + this.readOnce = true; + return this.value_; + } + return this.value_[cloneMethod](); + } + return this.value_; + } +} + +// node_modules/fast-check/lib/esm/check/arbitrary/definition/Arbitrary.js +var safeObjectAssign = Object.assign; + +class Arbitrary { + filter(refinement) { + return new FilterArbitrary(this, refinement); + } + map(mapper, unmapper) { + return new MapArbitrary(this, mapper, unmapper); + } + chain(chainer) { + return new ChainArbitrary(this, chainer); + } + noShrink() { + return new NoShrinkArbitrary(this); + } + noBias() { + return new NoBiasArbitrary(this); + } +} + +class ChainArbitrary extends Arbitrary { + constructor(arb, chainer) { + super(); + this.arb = arb; + this.chainer = chainer; + } + generate(mrng, biasFactor) { + const clonedMrng = mrng.clone(); + const src = this.arb.generate(mrng, biasFactor); + return this.valueChainer(src, mrng, clonedMrng, biasFactor); + } + canShrinkWithoutContext(value2) { + return false; + } + shrink(value2, context4) { + if (this.isSafeContext(context4)) { + return (!context4.stoppedForOriginal ? this.arb.shrink(context4.originalValue, context4.originalContext).map((v) => this.valueChainer(v, context4.clonedMrng.clone(), context4.clonedMrng, context4.originalBias)) : Stream.nil()).join(context4.chainedArbitrary.shrink(value2, context4.chainedContext).map((dst) => { + const newContext = safeObjectAssign(safeObjectAssign({}, context4), { + chainedContext: dst.context, + stoppedForOriginal: true + }); + return new Value(dst.value_, newContext); + })); + } + return Stream.nil(); + } + valueChainer(v, generateMrng, clonedMrng, biasFactor) { + const chainedArbitrary = this.chainer(v.value_); + const dst = chainedArbitrary.generate(generateMrng, biasFactor); + const context4 = { + originalBias: biasFactor, + originalValue: v.value_, + originalContext: v.context, + stoppedForOriginal: false, + chainedArbitrary, + chainedContext: dst.context, + clonedMrng + }; + return new Value(dst.value_, context4); + } + isSafeContext(context4) { + return context4 != null && typeof context4 === "object" && "originalBias" in context4 && "originalValue" in context4 && "originalContext" in context4 && "stoppedForOriginal" in context4 && "chainedArbitrary" in context4 && "chainedContext" in context4 && "clonedMrng" in context4; + } +} + +class MapArbitrary extends Arbitrary { + constructor(arb, mapper, unmapper) { + super(); + this.arb = arb; + this.mapper = mapper; + this.unmapper = unmapper; + this.bindValueMapper = (v) => this.valueMapper(v); + } + generate(mrng, biasFactor) { + const g = this.arb.generate(mrng, biasFactor); + return this.valueMapper(g); + } + canShrinkWithoutContext(value2) { + if (this.unmapper !== undefined) { + try { + const unmapped = this.unmapper(value2); + return this.arb.canShrinkWithoutContext(unmapped); + } catch (_err) { + return false; + } + } + return false; + } + shrink(value2, context4) { + if (this.isSafeContext(context4)) { + return this.arb.shrink(context4.originalValue, context4.originalContext).map(this.bindValueMapper); + } + if (this.unmapper !== undefined) { + const unmapped = this.unmapper(value2); + return this.arb.shrink(unmapped, undefined).map(this.bindValueMapper); + } + return Stream.nil(); + } + mapperWithCloneIfNeeded(v) { + const sourceValue = v.value; + const mappedValue = this.mapper(sourceValue); + if (v.hasToBeCloned && (typeof mappedValue === "object" && mappedValue !== null || typeof mappedValue === "function") && Object.isExtensible(mappedValue) && !hasCloneMethod(mappedValue)) { + Object.defineProperty(mappedValue, cloneMethod, { get: () => () => this.mapperWithCloneIfNeeded(v)[0] }); + } + return [mappedValue, sourceValue]; + } + valueMapper(v) { + const [mappedValue, sourceValue] = this.mapperWithCloneIfNeeded(v); + const context4 = { originalValue: sourceValue, originalContext: v.context }; + return new Value(mappedValue, context4); + } + isSafeContext(context4) { + return context4 != null && typeof context4 === "object" && "originalValue" in context4 && "originalContext" in context4; + } +} + +class FilterArbitrary extends Arbitrary { + constructor(arb, refinement) { + super(); + this.arb = arb; + this.refinement = refinement; + this.bindRefinementOnValue = (v) => this.refinementOnValue(v); + } + generate(mrng, biasFactor) { + while (true) { + const g = this.arb.generate(mrng, biasFactor); + if (this.refinementOnValue(g)) { + return g; + } + } + } + canShrinkWithoutContext(value2) { + return this.arb.canShrinkWithoutContext(value2) && this.refinement(value2); + } + shrink(value2, context4) { + return this.arb.shrink(value2, context4).filter(this.bindRefinementOnValue); + } + refinementOnValue(v) { + return this.refinement(v.value); + } +} + +class NoShrinkArbitrary extends Arbitrary { + constructor(arb) { + super(); + this.arb = arb; + } + generate(mrng, biasFactor) { + return this.arb.generate(mrng, biasFactor); + } + canShrinkWithoutContext(value2) { + return this.arb.canShrinkWithoutContext(value2); + } + shrink(_value, _context) { + return Stream.nil(); + } + noShrink() { + return this; + } +} + +class NoBiasArbitrary extends Arbitrary { + constructor(arb) { + super(); + this.arb = arb; + } + generate(mrng, _biasFactor) { + return this.arb.generate(mrng, undefined); + } + canShrinkWithoutContext(value2) { + return this.arb.canShrinkWithoutContext(value2); + } + shrink(value2, context4) { + return this.arb.shrink(value2, context4); + } + noBias() { + return this; + } +} + +// node_modules/fast-check/lib/esm/utils/apply.js +var untouchedApply = Function.prototype.apply; +var ApplySymbol = Symbol("apply"); +function safeExtractApply(f) { + try { + return f.apply; + } catch (err) { + return; + } +} +function safeApplyHacky(f, instance, args2) { + const ff = f; + ff[ApplySymbol] = untouchedApply; + const out = ff[ApplySymbol](instance, args2); + delete ff[ApplySymbol]; + return out; +} +function safeApply(f, instance, args2) { + if (safeExtractApply(f) === untouchedApply) { + return f.apply(instance, args2); + } + return safeApplyHacky(f, instance, args2); +} + +// node_modules/fast-check/lib/esm/utils/globals.js +var untouchedForEach = Array.prototype.forEach; +var untouchedIndexOf = Array.prototype.indexOf; +var untouchedJoin = Array.prototype.join; +var untouchedMap = Array.prototype.map; +var untouchedFilter = Array.prototype.filter; +var untouchedPush = Array.prototype.push; +var untouchedPop = Array.prototype.pop; +var untouchedSplice = Array.prototype.splice; +var untouchedSlice = Array.prototype.slice; +var untouchedSort = Array.prototype.sort; +var untouchedEvery = Array.prototype.every; +function extractIndexOf(instance) { + try { + return instance.indexOf; + } catch (err) { + return; + } +} +function extractMap(instance) { + try { + return instance.map; + } catch (err) { + return; + } +} +function extractPush(instance) { + try { + return instance.push; + } catch (err) { + return; + } +} +function extractSlice(instance) { + try { + return instance.slice; + } catch (err) { + return; + } +} +function safeIndexOf(instance, ...args2) { + if (extractIndexOf(instance) === untouchedIndexOf) { + return instance.indexOf(...args2); + } + return safeApply(untouchedIndexOf, instance, args2); +} +function safeMap(instance, fn2) { + if (extractMap(instance) === untouchedMap) { + return instance.map(fn2); + } + return safeApply(untouchedMap, instance, [fn2]); +} +function safePush(instance, ...args2) { + if (extractPush(instance) === untouchedPush) { + return instance.push(...args2); + } + return safeApply(untouchedPush, instance, args2); +} +function safeSlice(instance, ...args2) { + if (extractSlice(instance) === untouchedSlice) { + return instance.slice(...args2); + } + return safeApply(untouchedSlice, instance, args2); +} +var untouchedGetTime = Date.prototype.getTime; +var untouchedToISOString = Date.prototype.toISOString; +var untouchedAdd = Set.prototype.add; +var untouchedHas = Set.prototype.has; +var untouchedSet = WeakMap.prototype.set; +var untouchedGet = WeakMap.prototype.get; +var untouchedMapSet = Map.prototype.set; +var untouchedMapGet = Map.prototype.get; +function extractMapSet(instance) { + try { + return instance.set; + } catch (err) { + return; + } +} +function extractMapGet(instance) { + try { + return instance.get; + } catch (err) { + return; + } +} +function safeMapSet(instance, key, value2) { + if (extractMapSet(instance) === untouchedMapSet) { + return instance.set(key, value2); + } + return safeApply(untouchedMapSet, instance, [key, value2]); +} +function safeMapGet(instance, key) { + if (extractMapGet(instance) === untouchedMapGet) { + return instance.get(key); + } + return safeApply(untouchedMapGet, instance, [key]); +} +var untouchedSplit = String.prototype.split; +var untouchedStartsWith = String.prototype.startsWith; +var untouchedEndsWith = String.prototype.endsWith; +var untouchedSubstring = String.prototype.substring; +var untouchedToLowerCase = String.prototype.toLowerCase; +var untouchedToUpperCase = String.prototype.toUpperCase; +var untouchedPadStart = String.prototype.padStart; +var untouchedCharCodeAt = String.prototype.charCodeAt; +var untouchedNormalize = String.prototype.normalize; +var untouchedReplace = String.prototype.replace; +var untouchedNumberToString = Number.prototype.toString; + +// node_modules/fast-check/lib/esm/stream/LazyIterableIterator.js +class LazyIterableIterator { + constructor(producer) { + this.producer = producer; + } + [Symbol.iterator]() { + if (this.it === undefined) { + this.it = this.producer(); + } + return this.it; + } + next() { + if (this.it === undefined) { + this.it = this.producer(); + } + return this.it.next(); + } +} +function makeLazy(producer) { + return new LazyIterableIterator(producer); +} + +// node_modules/fast-check/lib/esm/check/runner/configuration/GlobalParameters.js +var globalParameters = {}; +function readConfigureGlobal() { + return globalParameters; +} + +// node_modules/fast-check/lib/esm/arbitrary/_internals/helpers/BiasNumericRange.js +var safeMathFloor = Math.floor; +var safeMathLog = Math.log; +function integerLogLike(v) { + return safeMathFloor(safeMathLog(v) / safeMathLog(2)); +} +function biasNumericRange(min4, max6, logLike) { + if (min4 === max6) { + return [{ min: min4, max: max6 }]; + } + if (min4 < 0 && max6 > 0) { + const logMin = logLike(-min4); + const logMax = logLike(max6); + return [ + { min: -logMin, max: logMax }, + { min: max6 - logMax, max: max6 }, + { min: min4, max: min4 + logMin } + ]; + } + const logGap = logLike(max6 - min4); + const arbCloseToMin = { min: min4, max: min4 + logGap }; + const arbCloseToMax = { min: max6 - logGap, max: max6 }; + return min4 < 0 ? [arbCloseToMax, arbCloseToMin] : [arbCloseToMin, arbCloseToMax]; +} + +// node_modules/fast-check/lib/esm/arbitrary/_internals/helpers/ShrinkInteger.js +var safeMathCeil = Math.ceil; +var safeMathFloor2 = Math.floor; +function halvePosInteger(n) { + return safeMathFloor2(n / 2); +} +function halveNegInteger(n) { + return safeMathCeil(n / 2); +} +function shrinkInteger(current, target, tryTargetAsap) { + const realGap = current - target; + function* shrinkDecr() { + let previous = tryTargetAsap ? undefined : target; + const gap = tryTargetAsap ? realGap : halvePosInteger(realGap); + for (let toremove = gap;toremove > 0; toremove = halvePosInteger(toremove)) { + const next = toremove === realGap ? target : current - toremove; + yield new Value(next, previous); + previous = next; + } + } + function* shrinkIncr() { + let previous = tryTargetAsap ? undefined : target; + const gap = tryTargetAsap ? realGap : halveNegInteger(realGap); + for (let toremove = gap;toremove < 0; toremove = halveNegInteger(toremove)) { + const next = toremove === realGap ? target : current - toremove; + yield new Value(next, previous); + previous = next; + } + } + return realGap > 0 ? stream(shrinkDecr()) : stream(shrinkIncr()); +} + +// node_modules/fast-check/lib/esm/arbitrary/_internals/IntegerArbitrary.js +var safeMathSign = Math.sign; +var safeNumberIsInteger = Number.isInteger; +var safeObjectIs = Object.is; + +class IntegerArbitrary extends Arbitrary { + constructor(min4, max6) { + super(); + this.min = min4; + this.max = max6; + } + generate(mrng, biasFactor) { + const range = this.computeGenerateRange(mrng, biasFactor); + return new Value(mrng.nextInt(range.min, range.max), undefined); + } + canShrinkWithoutContext(value2) { + return typeof value2 === "number" && safeNumberIsInteger(value2) && !safeObjectIs(value2, -0) && this.min <= value2 && value2 <= this.max; + } + shrink(current, context4) { + if (!IntegerArbitrary.isValidContext(current, context4)) { + const target = this.defaultTarget(); + return shrinkInteger(current, target, true); + } + if (this.isLastChanceTry(current, context4)) { + return Stream.of(new Value(context4, undefined)); + } + return shrinkInteger(current, context4, false); + } + defaultTarget() { + if (this.min <= 0 && this.max >= 0) { + return 0; + } + return this.min < 0 ? this.max : this.min; + } + computeGenerateRange(mrng, biasFactor) { + if (biasFactor === undefined || mrng.nextInt(1, biasFactor) !== 1) { + return { min: this.min, max: this.max }; + } + const ranges = biasNumericRange(this.min, this.max, integerLogLike); + if (ranges.length === 1) { + return ranges[0]; + } + const id = mrng.nextInt(-2 * (ranges.length - 1), ranges.length - 2); + return id < 0 ? ranges[0] : ranges[id + 1]; + } + isLastChanceTry(current, context4) { + if (current > 0) + return current === context4 + 1 && current > this.min; + if (current < 0) + return current === context4 - 1 && current < this.max; + return false; + } + static isValidContext(current, context4) { + if (context4 === undefined) { + return false; + } + if (typeof context4 !== "number") { + throw new Error(`Invalid context type passed to IntegerArbitrary (#1)`); + } + if (context4 !== 0 && safeMathSign(current) !== safeMathSign(context4)) { + throw new Error(`Invalid context value passed to IntegerArbitrary (#2)`); + } + return true; + } +} + +// node_modules/fast-check/lib/esm/arbitrary/integer.js +var safeNumberIsInteger2 = Number.isInteger; +function buildCompleteIntegerConstraints(constraints) { + const min4 = constraints.min !== undefined ? constraints.min : -2147483648; + const max6 = constraints.max !== undefined ? constraints.max : 2147483647; + return { min: min4, max: max6 }; +} +function integer2(constraints = {}) { + const fullConstraints = buildCompleteIntegerConstraints(constraints); + if (fullConstraints.min > fullConstraints.max) { + throw new Error("fc.integer maximum value should be equal or greater than the minimum one"); + } + if (!safeNumberIsInteger2(fullConstraints.min)) { + throw new Error("fc.integer minimum value should be an integer"); + } + if (!safeNumberIsInteger2(fullConstraints.max)) { + throw new Error("fc.integer maximum value should be an integer"); + } + return new IntegerArbitrary(fullConstraints.min, fullConstraints.max); +} + +// node_modules/fast-check/lib/esm/arbitrary/_internals/helpers/DepthContext.js +var depthContextCache = new Map; +function getDepthContextFor(contextMeta) { + if (contextMeta === undefined) { + return { depth: 0 }; + } + if (typeof contextMeta !== "string") { + return contextMeta; + } + const cachedContext = safeMapGet(depthContextCache, contextMeta); + if (cachedContext !== undefined) { + return cachedContext; + } + const context4 = { depth: 0 }; + safeMapSet(depthContextCache, contextMeta, context4); + return context4; +} + +// node_modules/fast-check/lib/esm/arbitrary/_internals/implementations/NoopSlicedGenerator.js +class NoopSlicedGenerator { + constructor(arb, mrng, biasFactor) { + this.arb = arb; + this.mrng = mrng; + this.biasFactor = biasFactor; + } + attemptExact() { + return; + } + next() { + return this.arb.generate(this.mrng, this.biasFactor); + } +} + +// node_modules/fast-check/lib/esm/arbitrary/_internals/implementations/SlicedBasedGenerator.js +var safeMathMin = Math.min; +var safeMathMax = Math.max; + +class SlicedBasedGenerator { + constructor(arb, mrng, slices, biasFactor) { + this.arb = arb; + this.mrng = mrng; + this.slices = slices; + this.biasFactor = biasFactor; + this.activeSliceIndex = 0; + this.nextIndexInSlice = 0; + this.lastIndexInSlice = -1; + } + attemptExact(targetLength) { + if (targetLength !== 0 && this.mrng.nextInt(1, this.biasFactor) === 1) { + const eligibleIndices = []; + for (let index = 0;index !== this.slices.length; ++index) { + const slice = this.slices[index]; + if (slice.length === targetLength) { + safePush(eligibleIndices, index); + } + } + if (eligibleIndices.length === 0) { + return; + } + this.activeSliceIndex = eligibleIndices[this.mrng.nextInt(0, eligibleIndices.length - 1)]; + this.nextIndexInSlice = 0; + this.lastIndexInSlice = targetLength - 1; + } + } + next() { + if (this.nextIndexInSlice <= this.lastIndexInSlice) { + return new Value(this.slices[this.activeSliceIndex][this.nextIndexInSlice++], undefined); + } + if (this.mrng.nextInt(1, this.biasFactor) !== 1) { + return this.arb.generate(this.mrng, this.biasFactor); + } + this.activeSliceIndex = this.mrng.nextInt(0, this.slices.length - 1); + const slice = this.slices[this.activeSliceIndex]; + if (this.mrng.nextInt(1, this.biasFactor) !== 1) { + this.nextIndexInSlice = 1; + this.lastIndexInSlice = slice.length - 1; + return new Value(slice[0], undefined); + } + const rangeBoundaryA = this.mrng.nextInt(0, slice.length - 1); + const rangeBoundaryB = this.mrng.nextInt(0, slice.length - 1); + this.nextIndexInSlice = safeMathMin(rangeBoundaryA, rangeBoundaryB); + this.lastIndexInSlice = safeMathMax(rangeBoundaryA, rangeBoundaryB); + return new Value(slice[this.nextIndexInSlice++], undefined); + } +} + +// node_modules/fast-check/lib/esm/arbitrary/_internals/helpers/BuildSlicedGenerator.js +function buildSlicedGenerator(arb, mrng, slices, biasFactor) { + if (biasFactor === undefined || slices.length === 0 || mrng.nextInt(1, biasFactor) !== 1) { + return new NoopSlicedGenerator(arb, mrng, biasFactor); + } + return new SlicedBasedGenerator(arb, mrng, slices, biasFactor); +} + +// node_modules/fast-check/lib/esm/arbitrary/_internals/ArrayArbitrary.js +var safeMathFloor3 = Math.floor; +var safeMathLog2 = Math.log; +var safeMathMax2 = Math.max; +var safeArrayIsArray = Array.isArray; +function biasedMaxLength(minLength, maxLength) { + if (minLength === maxLength) { + return minLength; + } + return minLength + safeMathFloor3(safeMathLog2(maxLength - minLength) / safeMathLog2(2)); +} + +class ArrayArbitrary extends Arbitrary { + constructor(arb, minLength, maxGeneratedLength, maxLength, depthIdentifier, setBuilder, customSlices) { + super(); + this.arb = arb; + this.minLength = minLength; + this.maxGeneratedLength = maxGeneratedLength; + this.maxLength = maxLength; + this.setBuilder = setBuilder; + this.customSlices = customSlices; + this.lengthArb = integer2({ min: minLength, max: maxGeneratedLength }); + this.depthContext = getDepthContextFor(depthIdentifier); + } + preFilter(tab) { + if (this.setBuilder === undefined) { + return tab; + } + const s = this.setBuilder(); + for (let index = 0;index !== tab.length; ++index) { + s.tryAdd(tab[index]); + } + return s.getData(); + } + static makeItCloneable(vs, shrinkables) { + vs[cloneMethod] = () => { + const cloned = []; + for (let idx = 0;idx !== shrinkables.length; ++idx) { + safePush(cloned, shrinkables[idx].value); + } + this.makeItCloneable(cloned, shrinkables); + return cloned; + }; + return vs; + } + generateNItemsNoDuplicates(setBuilder, N, mrng, biasFactorItems) { + let numSkippedInRow = 0; + const s = setBuilder(); + const slicedGenerator = buildSlicedGenerator(this.arb, mrng, this.customSlices, biasFactorItems); + while (s.size() < N && numSkippedInRow < this.maxGeneratedLength) { + const current = slicedGenerator.next(); + if (s.tryAdd(current)) { + numSkippedInRow = 0; + } else { + numSkippedInRow += 1; + } + } + return s.getData(); + } + safeGenerateNItemsNoDuplicates(setBuilder, N, mrng, biasFactorItems) { + const depthImpact = safeMathMax2(0, N - biasedMaxLength(this.minLength, this.maxGeneratedLength)); + this.depthContext.depth += depthImpact; + try { + return this.generateNItemsNoDuplicates(setBuilder, N, mrng, biasFactorItems); + } finally { + this.depthContext.depth -= depthImpact; + } + } + generateNItems(N, mrng, biasFactorItems) { + const items = []; + const slicedGenerator = buildSlicedGenerator(this.arb, mrng, this.customSlices, biasFactorItems); + slicedGenerator.attemptExact(N); + for (let index = 0;index !== N; ++index) { + const current = slicedGenerator.next(); + safePush(items, current); + } + return items; + } + safeGenerateNItems(N, mrng, biasFactorItems) { + const depthImpact = safeMathMax2(0, N - biasedMaxLength(this.minLength, this.maxGeneratedLength)); + this.depthContext.depth += depthImpact; + try { + return this.generateNItems(N, mrng, biasFactorItems); + } finally { + this.depthContext.depth -= depthImpact; + } + } + wrapper(itemsRaw, shrunkOnce, itemsRawLengthContext, startIndex) { + const items = shrunkOnce ? this.preFilter(itemsRaw) : itemsRaw; + let cloneable = false; + const vs = []; + const itemsContexts = []; + for (let idx = 0;idx !== items.length; ++idx) { + const s = items[idx]; + cloneable = cloneable || s.hasToBeCloned; + safePush(vs, s.value); + safePush(itemsContexts, s.context); + } + if (cloneable) { + ArrayArbitrary.makeItCloneable(vs, items); + } + const context4 = { + shrunkOnce, + lengthContext: itemsRaw.length === items.length && itemsRawLengthContext !== undefined ? itemsRawLengthContext : undefined, + itemsContexts, + startIndex + }; + return new Value(vs, context4); + } + generate(mrng, biasFactor) { + const biasMeta = this.applyBias(mrng, biasFactor); + const targetSize = biasMeta.size; + const items = this.setBuilder !== undefined ? this.safeGenerateNItemsNoDuplicates(this.setBuilder, targetSize, mrng, biasMeta.biasFactorItems) : this.safeGenerateNItems(targetSize, mrng, biasMeta.biasFactorItems); + return this.wrapper(items, false, undefined, 0); + } + applyBias(mrng, biasFactor) { + if (biasFactor === undefined) { + return { size: this.lengthArb.generate(mrng, undefined).value }; + } + if (this.minLength === this.maxGeneratedLength) { + return { size: this.lengthArb.generate(mrng, undefined).value, biasFactorItems: biasFactor }; + } + if (mrng.nextInt(1, biasFactor) !== 1) { + return { size: this.lengthArb.generate(mrng, undefined).value }; + } + if (mrng.nextInt(1, biasFactor) !== 1 || this.minLength === this.maxGeneratedLength) { + return { size: this.lengthArb.generate(mrng, undefined).value, biasFactorItems: biasFactor }; + } + const maxBiasedLength = biasedMaxLength(this.minLength, this.maxGeneratedLength); + const targetSizeValue = integer2({ min: this.minLength, max: maxBiasedLength }).generate(mrng, undefined); + return { size: targetSizeValue.value, biasFactorItems: biasFactor }; + } + canShrinkWithoutContext(value2) { + if (!safeArrayIsArray(value2) || this.minLength > value2.length || value2.length > this.maxLength) { + return false; + } + for (let index = 0;index !== value2.length; ++index) { + if (!(index in value2)) { + return false; + } + if (!this.arb.canShrinkWithoutContext(value2[index])) { + return false; + } + } + const filtered = this.preFilter(safeMap(value2, (item) => new Value(item, undefined))); + return filtered.length === value2.length; + } + shrinkItemByItem(value2, safeContext, endIndex) { + const shrinks = []; + for (let index = safeContext.startIndex;index < endIndex; ++index) { + safePush(shrinks, makeLazy(() => this.arb.shrink(value2[index], safeContext.itemsContexts[index]).map((v) => { + const beforeCurrent = safeMap(safeSlice(value2, 0, index), (v2, i) => new Value(cloneIfNeeded(v2), safeContext.itemsContexts[i])); + const afterCurrent = safeMap(safeSlice(value2, index + 1), (v2, i) => new Value(cloneIfNeeded(v2), safeContext.itemsContexts[i + index + 1])); + return [ + [...beforeCurrent, v, ...afterCurrent], + undefined, + index + ]; + }))); + } + return Stream.nil().join(...shrinks); + } + shrinkImpl(value2, context4) { + if (value2.length === 0) { + return Stream.nil(); + } + const safeContext = context4 !== undefined ? context4 : { shrunkOnce: false, lengthContext: undefined, itemsContexts: [], startIndex: 0 }; + return this.lengthArb.shrink(value2.length, safeContext.lengthContext).drop(safeContext.shrunkOnce && safeContext.lengthContext === undefined && value2.length > this.minLength + 1 ? 1 : 0).map((lengthValue) => { + const sliceStart = value2.length - lengthValue.value; + return [ + safeMap(safeSlice(value2, sliceStart), (v, index) => new Value(cloneIfNeeded(v), safeContext.itemsContexts[index + sliceStart])), + lengthValue.context, + 0 + ]; + }).join(makeLazy(() => value2.length > this.minLength ? this.shrinkItemByItem(value2, safeContext, 1) : this.shrinkItemByItem(value2, safeContext, value2.length))).join(value2.length > this.minLength ? makeLazy(() => { + const subContext = { + shrunkOnce: false, + lengthContext: undefined, + itemsContexts: safeSlice(safeContext.itemsContexts, 1), + startIndex: 0 + }; + return this.shrinkImpl(safeSlice(value2, 1), subContext).filter((v) => this.minLength <= v[0].length + 1).map((v) => { + return [[new Value(cloneIfNeeded(value2[0]), safeContext.itemsContexts[0]), ...v[0]], undefined, 0]; + }); + }) : Stream.nil()); + } + shrink(value2, context4) { + return this.shrinkImpl(value2, context4).map((contextualValue) => this.wrapper(contextualValue[0], true, contextualValue[1], contextualValue[2])); + } +} + +// node_modules/fast-check/lib/esm/arbitrary/_internals/helpers/MaxLengthFromMinLength.js +var safeMathFloor4 = Math.floor; +var safeMathMin2 = Math.min; +var MaxLengthUpperBound = 2147483647; +var orderedSize = ["xsmall", "small", "medium", "large", "xlarge"]; +var orderedRelativeSize = ["-4", "-3", "-2", "-1", "=", "+1", "+2", "+3", "+4"]; +var DefaultSize = "small"; +function maxLengthFromMinLength(minLength, size10) { + switch (size10) { + case "xsmall": + return safeMathFloor4(1.1 * minLength) + 1; + case "small": + return 2 * minLength + 10; + case "medium": + return 11 * minLength + 100; + case "large": + return 101 * minLength + 1000; + case "xlarge": + return 1001 * minLength + 1e4; + default: + throw new Error(`Unable to compute lengths based on received size: ${size10}`); + } +} +function relativeSizeToSize(size10, defaultSize) { + const sizeInRelative = safeIndexOf(orderedRelativeSize, size10); + if (sizeInRelative === -1) { + return size10; + } + const defaultSizeInSize = safeIndexOf(orderedSize, defaultSize); + if (defaultSizeInSize === -1) { + throw new Error(`Unable to offset size based on the unknown defaulted one: ${defaultSize}`); + } + const resultingSizeInSize = defaultSizeInSize + sizeInRelative - 4; + return resultingSizeInSize < 0 ? orderedSize[0] : resultingSizeInSize >= orderedSize.length ? orderedSize[orderedSize.length - 1] : orderedSize[resultingSizeInSize]; +} +function maxGeneratedLengthFromSizeForArbitrary(size10, minLength, maxLength, specifiedMaxLength) { + const { baseSize: defaultSize = DefaultSize, defaultSizeToMaxWhenMaxSpecified } = readConfigureGlobal() || {}; + const definedSize = size10 !== undefined ? size10 : specifiedMaxLength && defaultSizeToMaxWhenMaxSpecified ? "max" : defaultSize; + if (definedSize === "max") { + return maxLength; + } + const finalSize = relativeSizeToSize(definedSize, defaultSize); + return safeMathMin2(maxLengthFromMinLength(minLength, finalSize), maxLength); +} + +// node_modules/fast-check/lib/esm/arbitrary/array.js +function array5(arb, constraints = {}) { + const size10 = constraints.size; + const minLength = constraints.minLength || 0; + const maxLengthOrUnset = constraints.maxLength; + const depthIdentifier = constraints.depthIdentifier; + const maxLength = maxLengthOrUnset !== undefined ? maxLengthOrUnset : MaxLengthUpperBound; + const specifiedMaxLength = maxLengthOrUnset !== undefined; + const maxGeneratedLength = maxGeneratedLengthFromSizeForArbitrary(size10, minLength, maxLength, specifiedMaxLength); + const customSlices = constraints.experimentalCustomSlices || []; + return new ArrayArbitrary(arb, minLength, maxGeneratedLength, maxLength, depthIdentifier, undefined, customSlices); +} + +// node_modules/effect/dist/esm/internal/schema/util.js +var getKeysForIndexSignature = (input, parameter) => { + switch (parameter._tag) { + case "StringKeyword": + case "TemplateLiteral": + return Object.keys(input); + case "SymbolKeyword": + return Object.getOwnPropertySymbols(input); + case "Refinement": + return getKeysForIndexSignature(input, parameter.from); + } +}; +var memoizeThunk = (f) => { + let done7 = false; + let a; + return () => { + if (done7) { + return a; + } + a = f(); + done7 = true; + return a; + }; +}; +var isNonEmpty6 = (x) => Array.isArray(x); +var isSingle = (x) => !Array.isArray(x); +var formatPathKey = (key) => `[${formatPropertyKey(key)}]`; +var formatPath = (path) => isNonEmpty6(path) ? path.map(formatPathKey).join("") : formatPathKey(path); + +// node_modules/effect/dist/esm/internal/schema/errors.js +var getErrorMessage = (reason, details, path, ast) => { + let out = reason; + if (path && isNonEmptyReadonlyArray(path)) { + out += ` +at path: ${formatPath(path)}`; + } + if (details !== undefined) { + out += ` +details: ${details}`; + } + if (ast) { + out += ` +schema (${ast._tag}): ${ast}`; + } + return out; +}; +var getInvalidArgumentErrorMessage = (details) => getErrorMessage("Invalid Argument", details); +var getUnsupportedSchemaErrorMessage = (details, path, ast) => getErrorMessage("Unsupported schema", details, path, ast); +var getEquivalenceUnsupportedErrorMessage = (ast, path) => getUnsupportedSchemaErrorMessage("Cannot build an Equivalence", path, ast); +var getSchemaExtendErrorMessage = (x, y, path) => getErrorMessage("Unsupported schema or overlapping types", `cannot extend ${x} with ${y}`, path); +var getSchemaUnsupportedLiteralSpanErrorMessage = (ast) => getErrorMessage("Unsupported template literal span", undefined, undefined, ast); +var getASTUnsupportedSchemaErrorMessage = (ast) => getUnsupportedSchemaErrorMessage(undefined, undefined, ast); +var getASTUnsupportedKeySchemaErrorMessage = (ast) => getErrorMessage("Unsupported key schema", undefined, undefined, ast); +var getASTUnsupportedLiteralErrorMessage = (literal2) => getErrorMessage("Unsupported literal", `literal value: ${formatUnknown(literal2)}`); +var getASTDuplicateIndexSignatureErrorMessage = (type) => getErrorMessage("Duplicate index signature", `${type} index signature`); +var getASTIndexSignatureParameterErrorMessage = /* @__PURE__ */ getErrorMessage("Unsupported index signature parameter", "An index signature parameter type must be `string`, `symbol`, a template literal type or a refinement of the previous types"); +var getASTRequiredElementFollowinAnOptionalElementErrorMessage = /* @__PURE__ */ getErrorMessage("Invalid element", "A required element cannot follow an optional element. ts(1257)"); +var getASTDuplicatePropertySignatureTransformationErrorMessage = (key) => getErrorMessage("Duplicate property signature transformation", `Duplicate key ${formatUnknown(key)}`); +var getASTUnsupportedRenameSchemaErrorMessage = (ast) => getUnsupportedSchemaErrorMessage(undefined, undefined, ast); +var getASTDuplicatePropertySignatureErrorMessage = (key) => getErrorMessage("Duplicate property signature", `Duplicate key ${formatUnknown(key)}`); + +// node_modules/effect/dist/esm/internal/schema/schemaId.js +var DateFromSelfSchemaId = /* @__PURE__ */ Symbol.for("effect/SchemaId/DateFromSelf"); +var GreaterThanSchemaId = /* @__PURE__ */ Symbol.for("effect/SchemaId/GreaterThan"); +var GreaterThanOrEqualToSchemaId = /* @__PURE__ */ Symbol.for("effect/SchemaId/GreaterThanOrEqualTo"); +var LessThanSchemaId = /* @__PURE__ */ Symbol.for("effect/SchemaId/LessThan"); +var LessThanOrEqualToSchemaId = /* @__PURE__ */ Symbol.for("effect/SchemaId/LessThanOrEqualTo"); +var IntSchemaId = /* @__PURE__ */ Symbol.for("effect/SchemaId/Int"); +var NonNaNSchemaId = /* @__PURE__ */ Symbol.for("effect/SchemaId/NonNaN"); +var FiniteSchemaId = /* @__PURE__ */ Symbol.for("effect/SchemaId/Finite"); +var JsonNumberSchemaId = /* @__PURE__ */ Symbol.for("effect/SchemaId/JsonNumber"); +var BetweenSchemaId = /* @__PURE__ */ Symbol.for("effect/SchemaId/Between"); +var GreaterThanBigintSchemaId = /* @__PURE__ */ Symbol.for("effect/SchemaId/GreaterThanBigint"); +var GreaterThanOrEqualToBigIntSchemaId = /* @__PURE__ */ Symbol.for("effect/SchemaId/GreaterThanOrEqualToBigint"); +var LessThanBigIntSchemaId = /* @__PURE__ */ Symbol.for("effect/SchemaId/LessThanBigint"); +var LessThanOrEqualToBigIntSchemaId = /* @__PURE__ */ Symbol.for("effect/SchemaId/LessThanOrEqualToBigint"); +var BetweenBigintSchemaId = /* @__PURE__ */ Symbol.for("effect/SchemaId/BetweenBigint"); +var MinLengthSchemaId = /* @__PURE__ */ Symbol.for("effect/SchemaId/MinLength"); +var MaxLengthSchemaId = /* @__PURE__ */ Symbol.for("effect/SchemaId/MaxLength"); +var LengthSchemaId = /* @__PURE__ */ Symbol.for("effect/SchemaId/Length"); +var MinItemsSchemaId = /* @__PURE__ */ Symbol.for("effect/SchemaId/MinItems"); +var MaxItemsSchemaId = /* @__PURE__ */ Symbol.for("effect/SchemaId/MaxItems"); +var ItemsCountSchemaId = /* @__PURE__ */ Symbol.for("effect/SchemaId/ItemsCount"); + +// node_modules/effect/dist/esm/SchemaAST.js +var TypeConstructorAnnotationId = /* @__PURE__ */ Symbol.for("effect/annotation/TypeConstructor"); +var BrandAnnotationId = /* @__PURE__ */ Symbol.for("effect/annotation/Brand"); +var SchemaIdAnnotationId = /* @__PURE__ */ Symbol.for("effect/annotation/SchemaId"); +var MessageAnnotationId = /* @__PURE__ */ Symbol.for("effect/annotation/Message"); +var MissingMessageAnnotationId = /* @__PURE__ */ Symbol.for("effect/annotation/MissingMessage"); +var IdentifierAnnotationId = /* @__PURE__ */ Symbol.for("effect/annotation/Identifier"); +var TitleAnnotationId = /* @__PURE__ */ Symbol.for("effect/annotation/Title"); +var AutoTitleAnnotationId = /* @__PURE__ */ Symbol.for("effect/annotation/AutoTitle"); +var DescriptionAnnotationId = /* @__PURE__ */ Symbol.for("effect/annotation/Description"); +var ExamplesAnnotationId = /* @__PURE__ */ Symbol.for("effect/annotation/Examples"); +var DefaultAnnotationId = /* @__PURE__ */ Symbol.for("effect/annotation/Default"); +var JSONSchemaAnnotationId = /* @__PURE__ */ Symbol.for("effect/annotation/JSONSchema"); +var ArbitraryAnnotationId = /* @__PURE__ */ Symbol.for("effect/annotation/Arbitrary"); +var PrettyAnnotationId = /* @__PURE__ */ Symbol.for("effect/annotation/Pretty"); +var EquivalenceAnnotationId = /* @__PURE__ */ Symbol.for("effect/annotation/Equivalence"); +var DocumentationAnnotationId = /* @__PURE__ */ Symbol.for("effect/annotation/Documentation"); +var ConcurrencyAnnotationId = /* @__PURE__ */ Symbol.for("effect/annotation/Concurrency"); +var BatchingAnnotationId = /* @__PURE__ */ Symbol.for("effect/annotation/Batching"); +var ParseIssueTitleAnnotationId = /* @__PURE__ */ Symbol.for("effect/annotation/ParseIssueTitle"); +var ParseOptionsAnnotationId = /* @__PURE__ */ Symbol.for("effect/annotation/ParseOptions"); +var DecodingFallbackAnnotationId = /* @__PURE__ */ Symbol.for("effect/annotation/DecodingFallback"); +var SurrogateAnnotationId = /* @__PURE__ */ Symbol.for("effect/annotation/Surrogate"); +var StableFilterAnnotationId = /* @__PURE__ */ Symbol.for("effect/annotation/StableFilter"); +var getAnnotation = /* @__PURE__ */ dual(2, (annotated, key) => Object.prototype.hasOwnProperty.call(annotated.annotations, key) ? some2(annotated.annotations[key]) : none2()); +var getBrandAnnotation = /* @__PURE__ */ getAnnotation(BrandAnnotationId); +var getMessageAnnotation = /* @__PURE__ */ getAnnotation(MessageAnnotationId); +var getMissingMessageAnnotation = /* @__PURE__ */ getAnnotation(MissingMessageAnnotationId); +var getTitleAnnotation = /* @__PURE__ */ getAnnotation(TitleAnnotationId); +var getAutoTitleAnnotation = /* @__PURE__ */ getAnnotation(AutoTitleAnnotationId); +var getIdentifierAnnotation = /* @__PURE__ */ getAnnotation(IdentifierAnnotationId); +var getDescriptionAnnotation = /* @__PURE__ */ getAnnotation(DescriptionAnnotationId); +var getConcurrencyAnnotation = /* @__PURE__ */ getAnnotation(ConcurrencyAnnotationId); +var getBatchingAnnotation = /* @__PURE__ */ getAnnotation(BatchingAnnotationId); +var getParseIssueTitleAnnotation = /* @__PURE__ */ getAnnotation(ParseIssueTitleAnnotationId); +var getParseOptionsAnnotation = /* @__PURE__ */ getAnnotation(ParseOptionsAnnotationId); +var getDecodingFallbackAnnotation = /* @__PURE__ */ getAnnotation(DecodingFallbackAnnotationId); +var getSurrogateAnnotation = /* @__PURE__ */ getAnnotation(SurrogateAnnotationId); +var getStableFilterAnnotation = /* @__PURE__ */ getAnnotation(StableFilterAnnotationId); +var hasStableFilter = (annotated) => exists(getStableFilterAnnotation(annotated), (b) => b === true); +var JSONIdentifierAnnotationId = /* @__PURE__ */ Symbol.for("effect/annotation/JSONIdentifier"); +var getJSONIdentifierAnnotation = /* @__PURE__ */ getAnnotation(JSONIdentifierAnnotationId); +var getJSONIdentifier = (annotated) => orElse(getJSONIdentifierAnnotation(annotated), () => getIdentifierAnnotation(annotated)); +var ParseJsonSchemaId = /* @__PURE__ */ Symbol.for("effect/schema/ParseJson"); + +class Declaration { + typeParameters; + decodeUnknown; + encodeUnknown; + annotations; + _tag = "Declaration"; + constructor(typeParameters, decodeUnknown, encodeUnknown, annotations = {}) { + this.typeParameters = typeParameters; + this.decodeUnknown = decodeUnknown; + this.encodeUnknown = encodeUnknown; + this.annotations = annotations; + } + toString() { + return getOrElse(getExpected(this), () => ""); + } + toJSON() { + return { + _tag: this._tag, + typeParameters: this.typeParameters.map((ast) => ast.toJSON()), + annotations: toJSONAnnotations(this.annotations) + }; + } +} +var createASTGuard = (tag) => (ast) => ast._tag === tag; +class Literal { + literal; + annotations; + _tag = "Literal"; + constructor(literal2, annotations = {}) { + this.literal = literal2; + this.annotations = annotations; + } + toString() { + return getOrElse(getExpected(this), () => formatUnknown(this.literal)); + } + toJSON() { + return { + _tag: this._tag, + literal: isBigInt(this.literal) ? String(this.literal) : this.literal, + annotations: toJSONAnnotations(this.annotations) + }; + } +} +var isLiteral = /* @__PURE__ */ createASTGuard("Literal"); +var $null = /* @__PURE__ */ new Literal(null); +class UniqueSymbol { + symbol; + annotations; + _tag = "UniqueSymbol"; + constructor(symbol3, annotations = {}) { + this.symbol = symbol3; + this.annotations = annotations; + } + toString() { + return getOrElse(getExpected(this), () => formatUnknown(this.symbol)); + } + toJSON() { + return { + _tag: this._tag, + symbol: String(this.symbol), + annotations: toJSONAnnotations(this.annotations) + }; + } +} +var isUniqueSymbol = /* @__PURE__ */ createASTGuard("UniqueSymbol"); + +class UndefinedKeyword { + annotations; + _tag = "UndefinedKeyword"; + constructor(annotations = {}) { + this.annotations = annotations; + } + toString() { + return formatKeyword(this); + } + toJSON() { + return { + _tag: this._tag, + annotations: toJSONAnnotations(this.annotations) + }; + } +} +var undefinedKeyword = /* @__PURE__ */ new UndefinedKeyword({ + [TitleAnnotationId]: "undefined" +}); +class VoidKeyword { + annotations; + _tag = "VoidKeyword"; + constructor(annotations = {}) { + this.annotations = annotations; + } + toString() { + return formatKeyword(this); + } + toJSON() { + return { + _tag: this._tag, + annotations: toJSONAnnotations(this.annotations) + }; + } +} +var voidKeyword = /* @__PURE__ */ new VoidKeyword({ + [TitleAnnotationId]: "void" +}); +class NeverKeyword { + annotations; + _tag = "NeverKeyword"; + constructor(annotations = {}) { + this.annotations = annotations; + } + toString() { + return formatKeyword(this); + } + toJSON() { + return { + _tag: this._tag, + annotations: toJSONAnnotations(this.annotations) + }; + } +} +var neverKeyword = /* @__PURE__ */ new NeverKeyword({ + [TitleAnnotationId]: "never" +}); +var isNeverKeyword = /* @__PURE__ */ createASTGuard("NeverKeyword"); + +class UnknownKeyword { + annotations; + _tag = "UnknownKeyword"; + constructor(annotations = {}) { + this.annotations = annotations; + } + toString() { + return formatKeyword(this); + } + toJSON() { + return { + _tag: this._tag, + annotations: toJSONAnnotations(this.annotations) + }; + } +} +var unknownKeyword = /* @__PURE__ */ new UnknownKeyword({ + [TitleAnnotationId]: "unknown" +}); +class AnyKeyword { + annotations; + _tag = "AnyKeyword"; + constructor(annotations = {}) { + this.annotations = annotations; + } + toString() { + return formatKeyword(this); + } + toJSON() { + return { + _tag: this._tag, + annotations: toJSONAnnotations(this.annotations) + }; + } +} +var anyKeyword = /* @__PURE__ */ new AnyKeyword({ + [TitleAnnotationId]: "any" +}); +class StringKeyword { + annotations; + _tag = "StringKeyword"; + constructor(annotations = {}) { + this.annotations = annotations; + } + toString() { + return formatKeyword(this); + } + toJSON() { + return { + _tag: this._tag, + annotations: toJSONAnnotations(this.annotations) + }; + } +} +var stringKeyword = /* @__PURE__ */ new StringKeyword({ + [TitleAnnotationId]: "string", + [DescriptionAnnotationId]: "a string" +}); +var isStringKeyword = /* @__PURE__ */ createASTGuard("StringKeyword"); + +class NumberKeyword { + annotations; + _tag = "NumberKeyword"; + constructor(annotations = {}) { + this.annotations = annotations; + } + toString() { + return formatKeyword(this); + } + toJSON() { + return { + _tag: this._tag, + annotations: toJSONAnnotations(this.annotations) + }; + } +} +var numberKeyword = /* @__PURE__ */ new NumberKeyword({ + [TitleAnnotationId]: "number", + [DescriptionAnnotationId]: "a number" +}); +var isNumberKeyword = /* @__PURE__ */ createASTGuard("NumberKeyword"); + +class BooleanKeyword { + annotations; + _tag = "BooleanKeyword"; + constructor(annotations = {}) { + this.annotations = annotations; + } + toString() { + return formatKeyword(this); + } + toJSON() { + return { + _tag: this._tag, + annotations: toJSONAnnotations(this.annotations) + }; + } +} +var booleanKeyword = /* @__PURE__ */ new BooleanKeyword({ + [TitleAnnotationId]: "boolean", + [DescriptionAnnotationId]: "a boolean" +}); +var isBooleanKeyword = /* @__PURE__ */ createASTGuard("BooleanKeyword"); + +class BigIntKeyword { + annotations; + _tag = "BigIntKeyword"; + constructor(annotations = {}) { + this.annotations = annotations; + } + toString() { + return formatKeyword(this); + } + toJSON() { + return { + _tag: this._tag, + annotations: toJSONAnnotations(this.annotations) + }; + } +} +var bigIntKeyword = /* @__PURE__ */ new BigIntKeyword({ + [TitleAnnotationId]: "bigint", + [DescriptionAnnotationId]: "a bigint" +}); +class SymbolKeyword { + annotations; + _tag = "SymbolKeyword"; + constructor(annotations = {}) { + this.annotations = annotations; + } + toString() { + return formatKeyword(this); + } + toJSON() { + return { + _tag: this._tag, + annotations: toJSONAnnotations(this.annotations) + }; + } +} +var symbolKeyword = /* @__PURE__ */ new SymbolKeyword({ + [TitleAnnotationId]: "symbol", + [DescriptionAnnotationId]: "a symbol" +}); +var isSymbolKeyword = /* @__PURE__ */ createASTGuard("SymbolKeyword"); + +class ObjectKeyword { + annotations; + _tag = "ObjectKeyword"; + constructor(annotations = {}) { + this.annotations = annotations; + } + toString() { + return formatKeyword(this); + } + toJSON() { + return { + _tag: this._tag, + annotations: toJSONAnnotations(this.annotations) + }; + } +} +var objectKeyword = /* @__PURE__ */ new ObjectKeyword({ + [TitleAnnotationId]: "object", + [DescriptionAnnotationId]: "an object in the TypeScript meaning, i.e. the `object` type" +}); +class Enums { + enums; + annotations; + _tag = "Enums"; + constructor(enums, annotations = {}) { + this.enums = enums; + this.annotations = annotations; + } + toString() { + return getOrElse(getExpected(this), () => ` JSON.stringify(value2)).join(" | ")}>`); + } + toJSON() { + return { + _tag: this._tag, + enums: this.enums, + annotations: toJSONAnnotations(this.annotations) + }; + } +} +var isEnums = /* @__PURE__ */ createASTGuard("Enums"); +var isTemplateLiteralSpanType = (ast) => { + switch (ast._tag) { + case "Literal": + case "NumberKeyword": + case "StringKeyword": + case "TemplateLiteral": + return true; + case "Union": + return ast.types.every(isTemplateLiteralSpanType); + } + return false; +}; +var templateLiteralSpanUnionTypeToString = (type) => { + switch (type._tag) { + case "Literal": + return JSON.stringify(String(type.literal)); + case "StringKeyword": + return "string"; + case "NumberKeyword": + return "number"; + case "TemplateLiteral": + return String(type); + case "Union": + return type.types.map(templateLiteralSpanUnionTypeToString).join(" | "); + } +}; +var templateLiteralSpanTypeToString = (type) => { + switch (type._tag) { + case "Literal": + return String(type.literal); + case "StringKeyword": + return "${string}"; + case "NumberKeyword": + return "${number}"; + case "TemplateLiteral": + return "${" + String(type) + "}"; + case "Union": + return "${" + type.types.map(templateLiteralSpanUnionTypeToString).join(" | ") + "}"; + } +}; + +class TemplateLiteralSpan { + literal; + type; + constructor(type, literal2) { + this.literal = literal2; + if (isTemplateLiteralSpanType(type)) { + this.type = type; + } else { + throw new Error(getSchemaUnsupportedLiteralSpanErrorMessage(type)); + } + } + toString() { + return templateLiteralSpanTypeToString(this.type) + this.literal; + } + toJSON() { + return { + type: this.type.toJSON(), + literal: this.literal + }; + } +} + +class TemplateLiteral { + head; + spans; + annotations; + _tag = "TemplateLiteral"; + constructor(head5, spans, annotations = {}) { + this.head = head5; + this.spans = spans; + this.annotations = annotations; + } + toString() { + return getOrElse(getExpected(this), () => formatTemplateLiteral(this)); + } + toJSON() { + return { + _tag: this._tag, + head: this.head, + spans: this.spans.map((span2) => span2.toJSON()), + annotations: toJSONAnnotations(this.annotations) + }; + } +} +var formatTemplateLiteral = (ast) => "`" + ast.head + ast.spans.map(String).join("") + "`"; +var isTemplateLiteral = /* @__PURE__ */ createASTGuard("TemplateLiteral"); + +class Type { + type; + annotations; + constructor(type, annotations = {}) { + this.type = type; + this.annotations = annotations; + } + toJSON() { + return { + type: this.type.toJSON(), + annotations: toJSONAnnotations(this.annotations) + }; + } + toString() { + return String(this.type); + } +} + +class OptionalType extends Type { + isOptional; + constructor(type, isOptional, annotations = {}) { + super(type, annotations); + this.isOptional = isOptional; + } + toJSON() { + return { + type: this.type.toJSON(), + isOptional: this.isOptional, + annotations: toJSONAnnotations(this.annotations) + }; + } + toString() { + return String(this.type) + (this.isOptional ? "?" : ""); + } +} +var getRestASTs = (rest) => rest.map((annotatedAST) => annotatedAST.type); + +class TupleType { + elements; + rest; + isReadonly; + annotations; + _tag = "TupleType"; + constructor(elements, rest, isReadonly, annotations = {}) { + this.elements = elements; + this.rest = rest; + this.isReadonly = isReadonly; + this.annotations = annotations; + let hasOptionalElement = false; + let hasIllegalRequiredElement = false; + for (const e of elements) { + if (e.isOptional) { + hasOptionalElement = true; + } else if (hasOptionalElement) { + hasIllegalRequiredElement = true; + break; + } + } + if (hasIllegalRequiredElement || hasOptionalElement && rest.length > 1) { + throw new Error(getASTRequiredElementFollowinAnOptionalElementErrorMessage); + } + } + toString() { + return getOrElse(getExpected(this), () => formatTuple(this)); + } + toJSON() { + return { + _tag: this._tag, + elements: this.elements.map((e) => e.toJSON()), + rest: this.rest.map((ast) => ast.toJSON()), + isReadonly: this.isReadonly, + annotations: toJSONAnnotations(this.annotations) + }; + } +} +var formatTuple = (ast) => { + const formattedElements = ast.elements.map(String).join(", "); + return matchLeft(ast.rest, { + onEmpty: () => `readonly [${formattedElements}]`, + onNonEmpty: (head5, tail) => { + const formattedHead = String(head5); + const wrappedHead = formattedHead.includes(" | ") ? `(${formattedHead})` : formattedHead; + if (tail.length > 0) { + const formattedTail = tail.map(String).join(", "); + if (ast.elements.length > 0) { + return `readonly [${formattedElements}, ...${wrappedHead}[], ${formattedTail}]`; + } else { + return `readonly [...${wrappedHead}[], ${formattedTail}]`; + } + } else { + if (ast.elements.length > 0) { + return `readonly [${formattedElements}, ...${wrappedHead}[]]`; + } else { + return `ReadonlyArray<${formattedHead}>`; + } + } + } + }); +}; +class PropertySignature extends OptionalType { + name; + isReadonly; + constructor(name, type, isOptional, isReadonly, annotations) { + super(type, isOptional, annotations); + this.name = name; + this.isReadonly = isReadonly; + } + toString() { + return (this.isReadonly ? "readonly " : "") + String(this.name) + (this.isOptional ? "?" : "") + ": " + this.type; + } + toJSON() { + return { + name: String(this.name), + type: this.type.toJSON(), + isOptional: this.isOptional, + isReadonly: this.isReadonly, + annotations: toJSONAnnotations(this.annotations) + }; + } +} +var isParameter = (ast) => { + switch (ast._tag) { + case "StringKeyword": + case "SymbolKeyword": + case "TemplateLiteral": + return true; + case "Refinement": + return isParameter(ast.from); + } + return false; +}; + +class IndexSignature { + type; + isReadonly; + parameter; + constructor(parameter, type, isReadonly) { + this.type = type; + this.isReadonly = isReadonly; + if (isParameter(parameter)) { + this.parameter = parameter; + } else { + throw new Error(getASTIndexSignatureParameterErrorMessage); + } + } + toString() { + return (this.isReadonly ? "readonly " : "") + `[x: ${this.parameter}]: ${this.type}`; + } + toJSON() { + return { + parameter: this.parameter.toJSON(), + type: this.type.toJSON(), + isReadonly: this.isReadonly + }; + } +} + +class TypeLiteral { + annotations; + _tag = "TypeLiteral"; + propertySignatures; + indexSignatures; + constructor(propertySignatures, indexSignatures, annotations = {}) { + this.annotations = annotations; + const keys5 = {}; + for (let i = 0;i < propertySignatures.length; i++) { + const name = propertySignatures[i].name; + if (Object.prototype.hasOwnProperty.call(keys5, name)) { + throw new Error(getASTDuplicatePropertySignatureErrorMessage(name)); + } + keys5[name] = null; + } + const parameters = { + string: false, + symbol: false + }; + for (let i = 0;i < indexSignatures.length; i++) { + const encodedParameter = getEncodedParameter(indexSignatures[i].parameter); + if (isStringKeyword(encodedParameter)) { + if (parameters.string) { + throw new Error(getASTDuplicateIndexSignatureErrorMessage("string")); + } + parameters.string = true; + } else if (isSymbolKeyword(encodedParameter)) { + if (parameters.symbol) { + throw new Error(getASTDuplicateIndexSignatureErrorMessage("symbol")); + } + parameters.symbol = true; + } + } + this.propertySignatures = propertySignatures; + this.indexSignatures = indexSignatures; + } + toString() { + return getOrElse(getExpected(this), () => formatTypeLiteral(this)); + } + toJSON() { + return { + _tag: this._tag, + propertySignatures: this.propertySignatures.map((ps) => ps.toJSON()), + indexSignatures: this.indexSignatures.map((ps) => ps.toJSON()), + annotations: toJSONAnnotations(this.annotations) + }; + } +} +var formatIndexSignatures = (iss) => iss.map(String).join("; "); +var formatTypeLiteral = (ast) => { + if (ast.propertySignatures.length > 0) { + const pss = ast.propertySignatures.map(String).join("; "); + if (ast.indexSignatures.length > 0) { + return `{ ${pss}; ${formatIndexSignatures(ast.indexSignatures)} }`; + } else { + return `{ ${pss} }`; + } + } else { + if (ast.indexSignatures.length > 0) { + return `{ ${formatIndexSignatures(ast.indexSignatures)} }`; + } else { + return "{}"; + } + } +}; +var isTypeLiteral = /* @__PURE__ */ createASTGuard("TypeLiteral"); +var sortCandidates = /* @__PURE__ */ sort(/* @__PURE__ */ mapInput2(Order2, (ast) => { + switch (ast._tag) { + case "AnyKeyword": + return 0; + case "UnknownKeyword": + return 1; + case "ObjectKeyword": + return 2; + case "StringKeyword": + case "NumberKeyword": + case "BooleanKeyword": + case "BigIntKeyword": + case "SymbolKeyword": + return 3; + } + return 4; +})); +var literalMap = { + string: "StringKeyword", + number: "NumberKeyword", + boolean: "BooleanKeyword", + bigint: "BigIntKeyword" +}; +var flatten7 = (candidates) => flatMap2(candidates, (ast) => isUnion(ast) ? flatten7(ast.types) : [ast]); +var unify = (candidates) => { + const cs = sortCandidates(candidates); + const out = []; + const uniques = {}; + const literals = []; + for (const ast of cs) { + switch (ast._tag) { + case "NeverKeyword": + break; + case "AnyKeyword": + return [anyKeyword]; + case "UnknownKeyword": + return [unknownKeyword]; + case "ObjectKeyword": + case "UndefinedKeyword": + case "VoidKeyword": + case "StringKeyword": + case "NumberKeyword": + case "BooleanKeyword": + case "BigIntKeyword": + case "SymbolKeyword": { + if (!uniques[ast._tag]) { + uniques[ast._tag] = ast; + out.push(ast); + } + break; + } + case "Literal": { + const type = typeof ast.literal; + switch (type) { + case "string": + case "number": + case "bigint": + case "boolean": { + const _tag = literalMap[type]; + if (!uniques[_tag] && !literals.includes(ast.literal)) { + literals.push(ast.literal); + out.push(ast); + } + break; + } + case "object": { + if (!literals.includes(ast.literal)) { + literals.push(ast.literal); + out.push(ast); + } + break; + } + } + break; + } + case "UniqueSymbol": { + if (!uniques["SymbolKeyword"] && !literals.includes(ast.symbol)) { + literals.push(ast.symbol); + out.push(ast); + } + break; + } + case "TupleType": { + if (!uniques["ObjectKeyword"]) { + out.push(ast); + } + break; + } + case "TypeLiteral": { + if (ast.propertySignatures.length === 0 && ast.indexSignatures.length === 0) { + if (!uniques["{}"]) { + uniques["{}"] = ast; + out.push(ast); + } + } else if (!uniques["ObjectKeyword"]) { + out.push(ast); + } + break; + } + default: + out.push(ast); + } + } + return out; +}; + +class Union { + types; + annotations; + static make = (types, annotations) => { + return isMembers(types) ? new Union(types, annotations) : types.length === 1 ? types[0] : neverKeyword; + }; + static unify = (candidates, annotations) => { + return Union.make(unify(flatten7(candidates)), annotations); + }; + _tag = "Union"; + constructor(types, annotations = {}) { + this.types = types; + this.annotations = annotations; + } + toString() { + return getOrElse(getExpected(this), () => this.types.map(String).join(" | ")); + } + toJSON() { + return { + _tag: this._tag, + types: this.types.map((ast) => ast.toJSON()), + annotations: toJSONAnnotations(this.annotations) + }; + } +} +var mapMembers = (members, f) => members.map(f); +var isMembers = (as4) => as4.length > 1; +var isUnion = /* @__PURE__ */ createASTGuard("Union"); +var toJSONMemoMap = /* @__PURE__ */ globalValue(/* @__PURE__ */ Symbol.for("effect/Schema/AST/toJSONMemoMap"), () => new WeakMap); + +class Suspend { + f; + annotations; + _tag = "Suspend"; + constructor(f, annotations = {}) { + this.f = f; + this.annotations = annotations; + this.f = memoizeThunk(f); + } + toString() { + return getExpected(this).pipe(orElse(() => flatMap(liftThrowable(this.f)(), (ast) => getExpected(ast))), getOrElse(() => "")); + } + toJSON() { + const ast = this.f(); + let out = toJSONMemoMap.get(ast); + if (out) { + return out; + } + toJSONMemoMap.set(ast, { + _tag: this._tag + }); + out = { + _tag: this._tag, + ast: ast.toJSON(), + annotations: toJSONAnnotations(this.annotations) + }; + toJSONMemoMap.set(ast, out); + return out; + } +} +class Refinement { + from; + filter; + annotations; + _tag = "Refinement"; + constructor(from, filter8, annotations = {}) { + this.from = from; + this.filter = filter8; + this.annotations = annotations; + } + toString() { + return getIdentifierAnnotation(this).pipe(getOrElse(() => match2(getOrElseExpected(this), { + onNone: () => `{ ${this.from} | filter }`, + onSome: (expected) => isRefinement(this.from) ? String(this.from) + " & " + expected : expected + }))); + } + toJSON() { + return { + _tag: this._tag, + from: this.from.toJSON(), + annotations: toJSONAnnotations(this.annotations) + }; + } +} +var isRefinement = /* @__PURE__ */ createASTGuard("Refinement"); +var defaultParseOption = {}; + +class Transformation { + from; + to; + transformation; + annotations; + _tag = "Transformation"; + constructor(from, to, transformation, annotations = {}) { + this.from = from; + this.to = to; + this.transformation = transformation; + this.annotations = annotations; + } + toString() { + return getOrElse(getExpected(this), () => `(${String(this.from)} <-> ${String(this.to)})`); + } + toJSON() { + return { + _tag: this._tag, + from: this.from.toJSON(), + to: this.to.toJSON(), + annotations: toJSONAnnotations(this.annotations) + }; + } +} +var isTransformation = /* @__PURE__ */ createASTGuard("Transformation"); + +class FinalTransformation { + decode; + encode; + _tag = "FinalTransformation"; + constructor(decode5, encode4) { + this.decode = decode5; + this.encode = encode4; + } +} +var createTransformationGuard = (tag) => (ast) => ast._tag === tag; +class ComposeTransformation { + _tag = "ComposeTransformation"; +} +var composeTransformation = /* @__PURE__ */ new ComposeTransformation; +class PropertySignatureTransformation { + from; + to; + decode; + encode; + constructor(from, to, decode5, encode4) { + this.from = from; + this.to = to; + this.decode = decode5; + this.encode = encode4; + } +} +var isRenamingPropertySignatureTransformation = (t) => t.decode === identity && t.encode === identity; + +class TypeLiteralTransformation { + propertySignatureTransformations; + _tag = "TypeLiteralTransformation"; + constructor(propertySignatureTransformations) { + this.propertySignatureTransformations = propertySignatureTransformations; + const fromKeys = {}; + const toKeys = {}; + for (const pst of propertySignatureTransformations) { + const from = pst.from; + if (fromKeys[from]) { + throw new Error(getASTDuplicatePropertySignatureTransformationErrorMessage(from)); + } + fromKeys[from] = true; + const to = pst.to; + if (toKeys[to]) { + throw new Error(getASTDuplicatePropertySignatureTransformationErrorMessage(to)); + } + toKeys[to] = true; + } + } +} +var isTypeLiteralTransformation = /* @__PURE__ */ createTransformationGuard("TypeLiteralTransformation"); +var annotations = (ast, overrides) => { + const d = Object.getOwnPropertyDescriptors(ast); + const base = { + ...ast.annotations + }; + delete base[IdentifierAnnotationId]; + const value2 = { + ...base, + ...overrides + }; + const surrogate = getSurrogateAnnotation(ast); + if (isSome2(surrogate)) { + value2[SurrogateAnnotationId] = annotations(surrogate.value, overrides); + } + d.annotations.value = value2; + return Object.create(Object.getPrototypeOf(ast), d); +}; +var keyof = (ast) => Union.unify(_keyof(ast)); +var STRING_KEYWORD_PATTERN = "[\\s\\S]*?"; +var NUMBER_KEYWORD_PATTERN = "[+-]?\\d*\\.?\\d+(?:[Ee][+-]?\\d+)?"; +var getTemplateLiteralSpanTypePattern = (type, capture2) => { + switch (type._tag) { + case "Literal": + return escape(String(type.literal)); + case "StringKeyword": + return STRING_KEYWORD_PATTERN; + case "NumberKeyword": + return NUMBER_KEYWORD_PATTERN; + case "TemplateLiteral": + return getTemplateLiteralPattern(type, capture2, false); + case "Union": + return type.types.map((type2) => getTemplateLiteralSpanTypePattern(type2, capture2)).join("|"); + } +}; +var handleTemplateLiteralSpanTypeParens = (type, s, capture2, top) => { + if (isUnion(type)) { + if (capture2 && !top) { + return `(?:${s})`; + } + } else if (!capture2 || !top) { + return s; + } + return `(${s})`; +}; +var getTemplateLiteralPattern = (ast, capture2, top) => { + let pattern = ``; + if (ast.head !== "") { + const head5 = escape(ast.head); + pattern += capture2 && top ? `(${head5})` : head5; + } + for (const span2 of ast.spans) { + const spanPattern = getTemplateLiteralSpanTypePattern(span2.type, capture2); + pattern += handleTemplateLiteralSpanTypeParens(span2.type, spanPattern, capture2, top); + if (span2.literal !== "") { + const literal2 = escape(span2.literal); + pattern += capture2 && top ? `(${literal2})` : literal2; + } + } + return pattern; +}; +var getTemplateLiteralRegExp = (ast) => new RegExp(`^${getTemplateLiteralPattern(ast, false, true)}$`); +var getTemplateLiteralCapturingRegExp = (ast) => new RegExp(`^${getTemplateLiteralPattern(ast, true, true)}$`); +var getIndexSignatures = (ast) => { + const annotation = getSurrogateAnnotation(ast); + if (isSome2(annotation)) { + return getIndexSignatures(annotation.value); + } + switch (ast._tag) { + case "TypeLiteral": + return ast.indexSignatures.slice(); + case "Suspend": + return getIndexSignatures(ast.f()); + case "Refinement": + return getIndexSignatures(ast.from); + case "Transformation": + return getIndexSignatures(ast.to); + } + return []; +}; +var getNumberIndexedAccess = (ast) => { + switch (ast._tag) { + case "TupleType": { + let hasOptional = false; + let out = []; + for (const e of ast.elements) { + if (e.isOptional) { + hasOptional = true; + } + out.push(e.type); + } + if (hasOptional) { + out.push(undefinedKeyword); + } + out = out.concat(getRestASTs(ast.rest)); + return Union.make(out); + } + case "Refinement": + return getNumberIndexedAccess(ast.from); + case "Union": + return Union.make(ast.types.map(getNumberIndexedAccess)); + case "Suspend": + return getNumberIndexedAccess(ast.f()); + } + throw new Error(getASTUnsupportedSchemaErrorMessage(ast)); +}; +var getTypeLiteralPropertySignature = (ast, name) => { + const ops = findFirst2(ast.propertySignatures, (ps) => ps.name === name); + if (isSome2(ops)) { + return ops.value; + } + if (isString(name)) { + let out = undefined; + for (const is of ast.indexSignatures) { + const encodedParameter = getEncodedParameter(is.parameter); + switch (encodedParameter._tag) { + case "TemplateLiteral": { + const regex = getTemplateLiteralRegExp(encodedParameter); + if (regex.test(name)) { + return new PropertySignature(name, is.type, false, true); + } + break; + } + case "StringKeyword": { + if (out === undefined) { + out = new PropertySignature(name, is.type, false, true); + } + } + } + } + if (out) { + return out; + } + } else if (isSymbol(name)) { + for (const is of ast.indexSignatures) { + const encodedParameter = getEncodedParameter(is.parameter); + if (isSymbolKeyword(encodedParameter)) { + return new PropertySignature(name, is.type, false, true); + } + } + } +}; +var getPropertyKeyIndexedAccess = (ast, name) => { + const annotation = getSurrogateAnnotation(ast); + if (isSome2(annotation)) { + return getPropertyKeyIndexedAccess(annotation.value, name); + } + switch (ast._tag) { + case "TypeLiteral": { + const ps = getTypeLiteralPropertySignature(ast, name); + if (ps) { + return ps; + } + break; + } + case "Union": + return new PropertySignature(name, Union.make(ast.types.map((ast2) => getPropertyKeyIndexedAccess(ast2, name).type)), false, true); + case "Suspend": + return getPropertyKeyIndexedAccess(ast.f(), name); + case "Refinement": + return getPropertyKeyIndexedAccess(ast.from, name); + case "Transformation": + return getPropertyKeyIndexedAccess(ast.to, name); + } + throw new Error(getASTUnsupportedSchemaErrorMessage(ast)); +}; +var getPropertyKeys = (ast) => { + const annotation = getSurrogateAnnotation(ast); + if (isSome2(annotation)) { + return getPropertyKeys(annotation.value); + } + switch (ast._tag) { + case "TypeLiteral": + return ast.propertySignatures.map((ps) => ps.name); + case "Union": + return ast.types.slice(1).reduce((out, ast2) => intersection(out, getPropertyKeys(ast2)), getPropertyKeys(ast.types[0])); + case "Suspend": + return getPropertyKeys(ast.f()); + case "Refinement": + return getPropertyKeys(ast.from); + case "Transformation": + return getPropertyKeys(ast.to); + } + return []; +}; +var record = (key, value2) => { + const propertySignatures = []; + const indexSignatures = []; + const go = (key2) => { + switch (key2._tag) { + case "NeverKeyword": + break; + case "StringKeyword": + case "SymbolKeyword": + case "TemplateLiteral": + case "Refinement": + indexSignatures.push(new IndexSignature(key2, value2, true)); + break; + case "Literal": + if (isString(key2.literal) || isNumber(key2.literal)) { + propertySignatures.push(new PropertySignature(key2.literal, value2, false, true)); + } else { + throw new Error(getASTUnsupportedLiteralErrorMessage(key2.literal)); + } + break; + case "Enums": { + for (const [_, name] of key2.enums) { + propertySignatures.push(new PropertySignature(name, value2, false, true)); + } + break; + } + case "UniqueSymbol": + propertySignatures.push(new PropertySignature(key2.symbol, value2, false, true)); + break; + case "Union": + key2.types.forEach(go); + break; + default: + throw new Error(getASTUnsupportedKeySchemaErrorMessage(key2)); + } + }; + go(key); + return { + propertySignatures, + indexSignatures + }; +}; +var pick2 = (ast, keys5) => { + const annotation = getSurrogateAnnotation(ast); + if (isSome2(annotation)) { + return pick2(annotation.value, keys5); + } + switch (ast._tag) { + case "TypeLiteral": { + const pss = []; + const names = {}; + for (const ps of ast.propertySignatures) { + names[ps.name] = null; + if (keys5.includes(ps.name)) { + pss.push(ps); + } + } + for (const key of keys5) { + if (!(key in names)) { + const ps = getTypeLiteralPropertySignature(ast, key); + if (ps) { + pss.push(ps); + } + } + } + return new TypeLiteral(pss, []); + } + case "Union": + return new TypeLiteral(keys5.map((name) => getPropertyKeyIndexedAccess(ast, name)), []); + case "Suspend": + return pick2(ast.f(), keys5); + case "Refinement": + return pick2(ast.from, keys5); + case "Transformation": { + switch (ast.transformation._tag) { + case "ComposeTransformation": + return new Transformation(pick2(ast.from, keys5), pick2(ast.to, keys5), composeTransformation); + case "TypeLiteralTransformation": { + const ts = []; + const fromKeys = []; + for (const k of keys5) { + const t = ast.transformation.propertySignatureTransformations.find((t2) => t2.to === k); + if (t) { + ts.push(t); + fromKeys.push(t.from); + } else { + fromKeys.push(k); + } + } + return isNonEmptyReadonlyArray(ts) ? new Transformation(pick2(ast.from, fromKeys), pick2(ast.to, keys5), new TypeLiteralTransformation(ts)) : pick2(ast.from, fromKeys); + } + } + } + } + throw new Error(getASTUnsupportedSchemaErrorMessage(ast)); +}; +var omit2 = (ast, keys5) => { + let indexSignatures = getIndexSignatures(ast); + if (indexSignatures.length > 0) { + if (indexSignatures.some((is) => isStringKeyword(getEncodedParameter(is.parameter)))) { + indexSignatures = indexSignatures.filter((is) => !isTemplateLiteral(getEncodedParameter(is.parameter))); + } + return new TypeLiteral([], indexSignatures); + } + return pick2(ast, getPropertyKeys(ast).filter((name) => !keys5.includes(name))); +}; +var orUndefined = (ast) => Union.make([ast, undefinedKeyword]); +var partial = (ast, options) => { + const exact = options?.exact === true; + switch (ast._tag) { + case "TupleType": + return new TupleType(ast.elements.map((e) => new OptionalType(exact ? e.type : orUndefined(e.type), true)), match3(ast.rest, { + onEmpty: () => ast.rest, + onNonEmpty: (rest) => [new Type(Union.make([...getRestASTs(rest), undefinedKeyword]))] + }), ast.isReadonly); + case "TypeLiteral": + return new TypeLiteral(ast.propertySignatures.map((ps) => new PropertySignature(ps.name, exact ? ps.type : orUndefined(ps.type), true, ps.isReadonly, ps.annotations)), ast.indexSignatures.map((is) => new IndexSignature(is.parameter, orUndefined(is.type), is.isReadonly))); + case "Union": + return Union.make(ast.types.map((member) => partial(member, options))); + case "Suspend": + return new Suspend(() => partial(ast.f(), options)); + case "Declaration": + case "Refinement": + throw new Error(getASTUnsupportedSchemaErrorMessage(ast)); + case "Transformation": { + if (isTypeLiteralTransformation(ast.transformation) && ast.transformation.propertySignatureTransformations.every(isRenamingPropertySignatureTransformation)) { + return new Transformation(partial(ast.from, options), partial(ast.to, options), ast.transformation); + } + throw new Error(getASTUnsupportedSchemaErrorMessage(ast)); + } + } + return ast; +}; +var required = (ast) => { + switch (ast._tag) { + case "TupleType": + return new TupleType(ast.elements.map((e) => new OptionalType(e.type, false)), ast.rest, ast.isReadonly); + case "TypeLiteral": + return new TypeLiteral(ast.propertySignatures.map((f) => new PropertySignature(f.name, f.type, false, f.isReadonly, f.annotations)), ast.indexSignatures); + case "Union": + return Union.make(ast.types.map((member) => required(member))); + case "Suspend": + return new Suspend(() => required(ast.f())); + case "Declaration": + case "Refinement": + throw new Error(getASTUnsupportedSchemaErrorMessage(ast)); + case "Transformation": { + if (isTypeLiteralTransformation(ast.transformation) && ast.transformation.propertySignatureTransformations.every(isRenamingPropertySignatureTransformation)) { + return new Transformation(required(ast.from), required(ast.to), ast.transformation); + } + throw new Error(getASTUnsupportedSchemaErrorMessage(ast)); + } + } + return ast; +}; +var mutable = (ast) => { + switch (ast._tag) { + case "TupleType": + return ast.isReadonly === false ? ast : new TupleType(ast.elements, ast.rest, false, ast.annotations); + case "TypeLiteral": { + const propertySignatures = changeMap(ast.propertySignatures, (ps) => ps.isReadonly === false ? ps : new PropertySignature(ps.name, ps.type, ps.isOptional, false, ps.annotations)); + const indexSignatures = changeMap(ast.indexSignatures, (is) => is.isReadonly === false ? is : new IndexSignature(is.parameter, is.type, false)); + return propertySignatures === ast.propertySignatures && indexSignatures === ast.indexSignatures ? ast : new TypeLiteral(propertySignatures, indexSignatures, ast.annotations); + } + case "Union": { + const types = changeMap(ast.types, mutable); + return types === ast.types ? ast : Union.make(types, ast.annotations); + } + case "Suspend": + return new Suspend(() => mutable(ast.f()), ast.annotations); + case "Refinement": { + const from = mutable(ast.from); + return from === ast.from ? ast : new Refinement(from, ast.filter, ast.annotations); + } + case "Transformation": { + const from = mutable(ast.from); + const to = mutable(ast.to); + return from === ast.from && to === ast.to ? ast : new Transformation(from, to, ast.transformation, ast.annotations); + } + } + return ast; +}; +var pickAnnotations = (annotationIds) => (annotated) => { + let out = undefined; + for (const id of annotationIds) { + if (Object.prototype.hasOwnProperty.call(annotated.annotations, id)) { + if (out === undefined) { + out = {}; + } + out[id] = annotated.annotations[id]; + } + } + return out; +}; +var omitAnnotations = (annotationIds) => (annotated) => { + const out = { + ...annotated.annotations + }; + for (const id of annotationIds) { + delete out[id]; + } + return out; +}; +var preserveTransformationAnnotations = /* @__PURE__ */ pickAnnotations([ExamplesAnnotationId, DefaultAnnotationId, JSONSchemaAnnotationId, ArbitraryAnnotationId, PrettyAnnotationId, EquivalenceAnnotationId]); +var typeAST = (ast) => { + switch (ast._tag) { + case "Declaration": { + const typeParameters = changeMap(ast.typeParameters, typeAST); + return typeParameters === ast.typeParameters ? ast : new Declaration(typeParameters, ast.decodeUnknown, ast.encodeUnknown, ast.annotations); + } + case "TupleType": { + const elements = changeMap(ast.elements, (e) => { + const type = typeAST(e.type); + return type === e.type ? e : new OptionalType(type, e.isOptional); + }); + const restASTs = getRestASTs(ast.rest); + const rest = changeMap(restASTs, typeAST); + return elements === ast.elements && rest === restASTs ? ast : new TupleType(elements, rest.map((type) => new Type(type)), ast.isReadonly, ast.annotations); + } + case "TypeLiteral": { + const propertySignatures = changeMap(ast.propertySignatures, (p) => { + const type = typeAST(p.type); + return type === p.type ? p : new PropertySignature(p.name, type, p.isOptional, p.isReadonly); + }); + const indexSignatures = changeMap(ast.indexSignatures, (is) => { + const type = typeAST(is.type); + return type === is.type ? is : new IndexSignature(is.parameter, type, is.isReadonly); + }); + return propertySignatures === ast.propertySignatures && indexSignatures === ast.indexSignatures ? ast : new TypeLiteral(propertySignatures, indexSignatures, ast.annotations); + } + case "Union": { + const types = changeMap(ast.types, typeAST); + return types === ast.types ? ast : Union.make(types, ast.annotations); + } + case "Suspend": + return new Suspend(() => typeAST(ast.f()), ast.annotations); + case "Refinement": { + const from = typeAST(ast.from); + return from === ast.from ? ast : new Refinement(from, ast.filter, ast.annotations); + } + case "Transformation": { + const preserve = preserveTransformationAnnotations(ast); + return typeAST(preserve !== undefined ? annotations(ast.to, preserve) : ast.to); + } + } + return ast; +}; +function changeMap(as4, f) { + let changed = false; + const out = allocate(as4.length); + for (let i = 0;i < as4.length; i++) { + const a = as4[i]; + const fa = f(a); + if (fa !== a) { + changed = true; + } + out[i] = fa; + } + return changed ? out : as4; +} +var getTransformationFrom = (ast) => { + switch (ast._tag) { + case "Transformation": + return ast.from; + case "Refinement": + return getTransformationFrom(ast.from); + case "Suspend": + return getTransformationFrom(ast.f()); + } +}; +var encodedAST_ = (ast, isBound) => { + switch (ast._tag) { + case "Declaration": { + const typeParameters = changeMap(ast.typeParameters, (ast2) => encodedAST_(ast2, isBound)); + return typeParameters === ast.typeParameters ? ast : new Declaration(typeParameters, ast.decodeUnknown, ast.encodeUnknown); + } + case "TupleType": { + const elements = changeMap(ast.elements, (e) => { + const type = encodedAST_(e.type, isBound); + return type === e.type ? e : new OptionalType(type, e.isOptional); + }); + const restASTs = getRestASTs(ast.rest); + const rest = changeMap(restASTs, (ast2) => encodedAST_(ast2, isBound)); + return elements === ast.elements && rest === restASTs ? ast : new TupleType(elements, rest.map((ast2) => new Type(ast2)), ast.isReadonly); + } + case "TypeLiteral": { + const propertySignatures = changeMap(ast.propertySignatures, (ps) => { + const type = encodedAST_(ps.type, isBound); + return type === ps.type ? ps : new PropertySignature(ps.name, type, ps.isOptional, ps.isReadonly); + }); + const indexSignatures = changeMap(ast.indexSignatures, (is) => { + const type = encodedAST_(is.type, isBound); + return type === is.type ? is : new IndexSignature(is.parameter, type, is.isReadonly); + }); + return propertySignatures === ast.propertySignatures && indexSignatures === ast.indexSignatures ? ast : new TypeLiteral(propertySignatures, indexSignatures); + } + case "Union": { + const types = changeMap(ast.types, (ast2) => encodedAST_(ast2, isBound)); + return types === ast.types ? ast : Union.make(types); + } + case "Suspend": { + let borrowedAnnotations = undefined; + const identifier2 = getJSONIdentifier(ast); + if (isSome2(identifier2)) { + const suffix = isBound ? "Bound" : ""; + borrowedAnnotations = { + [JSONIdentifierAnnotationId]: `${identifier2.value}Encoded${suffix}` + }; + } + return new Suspend(() => encodedAST_(ast.f(), isBound), borrowedAnnotations); + } + case "Refinement": { + const from = encodedAST_(ast.from, isBound); + if (isBound) { + if (from === ast.from) + return ast; + if (getTransformationFrom(ast.from) === undefined && hasStableFilter(ast)) { + return new Refinement(from, ast.filter, ast.annotations); + } + return from; + } else { + return from; + } + } + case "Transformation": + return encodedAST_(ast.from, isBound); + } + return ast; +}; +var encodedAST = (ast) => encodedAST_(ast, false); +var encodedBoundAST = (ast) => encodedAST_(ast, true); +var toJSONAnnotations = (annotations2) => { + const out = {}; + for (const k of Object.getOwnPropertySymbols(annotations2)) { + out[String(k)] = annotations2[k]; + } + return out; +}; +var getEncodedParameter = (ast) => { + switch (ast._tag) { + case "StringKeyword": + case "SymbolKeyword": + case "TemplateLiteral": + return ast; + case "Refinement": + return getEncodedParameter(ast.from); + } +}; +var equals4 = (self, that) => { + switch (self._tag) { + case "Literal": + return isLiteral(that) && that.literal === self.literal; + case "UniqueSymbol": + return isUniqueSymbol(that) && that.symbol === self.symbol; + case "UndefinedKeyword": + case "VoidKeyword": + case "NeverKeyword": + case "UnknownKeyword": + case "AnyKeyword": + case "StringKeyword": + case "NumberKeyword": + case "BooleanKeyword": + case "BigIntKeyword": + case "SymbolKeyword": + case "ObjectKeyword": + return that._tag === self._tag; + case "TemplateLiteral": + return isTemplateLiteral(that) && that.head === self.head && equalsTemplateLiteralSpan(that.spans, self.spans); + case "Enums": + return isEnums(that) && equalsEnums(that.enums, self.enums); + case "Union": + return isUnion(that) && equalsUnion(self.types, that.types); + case "Refinement": + case "TupleType": + case "TypeLiteral": + case "Suspend": + case "Transformation": + case "Declaration": + return self === that; + } +}; +var equalsTemplateLiteralSpan = /* @__PURE__ */ getEquivalence3((self, that) => { + return self.literal === that.literal && equals4(self.type, that.type); +}); +var equalsEnums = /* @__PURE__ */ getEquivalence3((self, that) => that[0] === self[0] && that[1] === self[1]); +var equalsUnion = /* @__PURE__ */ getEquivalence3(equals4); +var intersection3 = /* @__PURE__ */ intersectionWith(equals4); +var _keyof = (ast) => { + switch (ast._tag) { + case "Declaration": { + const annotation = getSurrogateAnnotation(ast); + if (isSome2(annotation)) { + return _keyof(annotation.value); + } + break; + } + case "TypeLiteral": + return ast.propertySignatures.map((p) => isSymbol(p.name) ? new UniqueSymbol(p.name) : new Literal(p.name)).concat(ast.indexSignatures.map((is) => getEncodedParameter(is.parameter))); + case "Suspend": + return _keyof(ast.f()); + case "Union": + return ast.types.slice(1).reduce((out, ast2) => intersection3(out, _keyof(ast2)), _keyof(ast.types[0])); + case "Transformation": + return _keyof(ast.to); + } + throw new Error(getASTUnsupportedSchemaErrorMessage(ast)); +}; +var compose = (ab, cd) => new Transformation(ab, cd, composeTransformation); +var rename = (ast, mapping) => { + switch (ast._tag) { + case "TypeLiteral": { + const propertySignatureTransformations = []; + for (const key of Reflect.ownKeys(mapping)) { + const name = mapping[key]; + if (name !== undefined) { + propertySignatureTransformations.push(new PropertySignatureTransformation(key, name, identity, identity)); + } + } + if (propertySignatureTransformations.length === 0) { + return ast; + } + return new Transformation(ast, new TypeLiteral(ast.propertySignatures.map((ps) => { + const name = mapping[ps.name]; + return new PropertySignature(name === undefined ? ps.name : name, typeAST(ps.type), ps.isOptional, ps.isReadonly, ps.annotations); + }), ast.indexSignatures), new TypeLiteralTransformation(propertySignatureTransformations)); + } + case "Union": + return Union.make(ast.types.map((ast2) => rename(ast2, mapping))); + case "Suspend": + return new Suspend(() => rename(ast.f(), mapping)); + case "Transformation": + return compose(ast, rename(typeAST(ast), mapping)); + } + throw new Error(getASTUnsupportedRenameSchemaErrorMessage(ast)); +}; +var formatKeyword = (ast) => getOrElse(getExpected(ast), () => ast._tag); +function getBrands(ast) { + return match2(getBrandAnnotation(ast), { + onNone: () => "", + onSome: (brands) => brands.map((brand) => ` & Brand<${formatUnknown(brand)}>`).join("") + }); +} +var getOrElseExpected = (ast) => getTitleAnnotation(ast).pipe(orElse(() => getDescriptionAnnotation(ast)), orElse(() => getAutoTitleAnnotation(ast)), map2((s) => s + getBrands(ast))); +var getExpected = (ast) => orElse(getIdentifierAnnotation(ast), () => getOrElseExpected(ast)); +var pruneUndefined = (ast, self, onTransformation) => { + switch (ast._tag) { + case "UndefinedKeyword": + return neverKeyword; + case "Union": { + const types = []; + let hasUndefined = false; + for (const type of ast.types) { + const pruned = self(type); + if (pruned) { + hasUndefined = true; + if (!isNeverKeyword(pruned)) { + types.push(pruned); + } + } else { + types.push(type); + } + } + if (hasUndefined) { + return Union.make(types); + } + break; + } + case "Suspend": + return self(ast.f()); + case "Transformation": + return onTransformation(ast); + } +}; + +// node_modules/effect/dist/esm/ParseResult.js +class Pointer { + path; + actual; + issue; + _tag = "Pointer"; + constructor(path, actual, issue) { + this.path = path; + this.actual = actual; + this.issue = issue; + } +} + +class Unexpected { + actual; + message; + _tag = "Unexpected"; + constructor(actual, message) { + this.actual = actual; + this.message = message; + } +} + +class Missing { + ast; + message; + _tag = "Missing"; + actual = undefined; + constructor(ast, message) { + this.ast = ast; + this.message = message; + } +} + +class Composite2 { + ast; + actual; + issues; + output; + _tag = "Composite"; + constructor(ast, actual, issues, output) { + this.ast = ast; + this.actual = actual; + this.issues = issues; + this.output = output; + } +} + +class Refinement2 { + ast; + actual; + kind; + issue; + _tag = "Refinement"; + constructor(ast, actual, kind, issue) { + this.ast = ast; + this.actual = actual; + this.kind = kind; + this.issue = issue; + } +} + +class Transformation2 { + ast; + actual; + kind; + issue; + _tag = "Transformation"; + constructor(ast, actual, kind, issue) { + this.ast = ast; + this.actual = actual; + this.kind = kind; + this.issue = issue; + } +} + +class Type2 { + ast; + actual; + message; + _tag = "Type"; + constructor(ast, actual, message) { + this.ast = ast; + this.actual = actual; + this.message = message; + } +} + +class Forbidden { + ast; + actual; + message; + _tag = "Forbidden"; + constructor(ast, actual, message) { + this.ast = ast; + this.actual = actual; + this.message = message; + } +} +var ParseErrorTypeId = /* @__PURE__ */ Symbol.for("effect/Schema/ParseErrorTypeId"); +class ParseError extends (/* @__PURE__ */ TaggedError("ParseError")) { + [ParseErrorTypeId] = ParseErrorTypeId; + get message() { + return this.toString(); + } + toString() { + return TreeFormatter.formatIssueSync(this.issue); + } + toJSON() { + return { + _id: "ParseError", + message: this.toString() + }; + } + [NodeInspectSymbol]() { + return this.toJSON(); + } +} +var parseError = (issue) => new ParseError({ + issue +}); +var succeed8 = right2; +var fail7 = left2; +var _try = try_; +var fromOption3 = fromOption2; +var isEither3 = isEither2; +var flatMap10 = /* @__PURE__ */ dual(2, (self, f) => { + return isEither3(self) ? match(self, { + onLeft: left2, + onRight: f + }) : flatMap9(self, f); +}); +var map13 = /* @__PURE__ */ dual(2, (self, f) => { + return isEither3(self) ? map(self, f) : map11(self, f); +}); +var mapError3 = /* @__PURE__ */ dual(2, (self, f) => { + return isEither3(self) ? mapLeft(self, f) : mapError2(self, f); +}); +var mapBoth4 = /* @__PURE__ */ dual(2, (self, options) => { + return isEither3(self) ? mapBoth(self, { + onLeft: options.onFailure, + onRight: options.onSuccess + }) : mapBoth3(self, options); +}); +var orElse5 = /* @__PURE__ */ dual(2, (self, f) => { + return isEither3(self) ? match(self, { + onLeft: f, + onRight: right2 + }) : catchAll2(self, f); +}); +var mergeInternalOptions = (options, overrideOptions) => { + if (overrideOptions === undefined || isNumber(overrideOptions)) { + return options; + } + if (options === undefined) { + return overrideOptions; + } + return { + ...options, + ...overrideOptions + }; +}; +var getEither = (ast, isDecoding, options) => { + const parser = goMemo(ast, isDecoding); + return (u, overrideOptions) => parser(u, mergeInternalOptions(options, overrideOptions)); +}; +var getSync = (ast, isDecoding, options) => { + const parser = getEither(ast, isDecoding, options); + return (input, overrideOptions) => getOrThrowWith(parser(input, overrideOptions), parseError); +}; +var getOption3 = (ast, isDecoding, options) => { + const parser = getEither(ast, isDecoding, options); + return (input, overrideOptions) => getRight2(parser(input, overrideOptions)); +}; +var getEffect = (ast, isDecoding, options) => { + const parser = goMemo(ast, isDecoding); + return (input, overrideOptions) => parser(input, { + ...mergeInternalOptions(options, overrideOptions), + isEffectAllowed: true + }); +}; +var decodeUnknownSync = (schema, options) => getSync(schema.ast, true, options); +var decodeUnknownOption = (schema, options) => getOption3(schema.ast, true, options); +var decodeUnknownEither = (schema, options) => getEither(schema.ast, true, options); +var decodeUnknown = (schema, options) => getEffect(schema.ast, true, options); +var encodeUnknownSync = (schema, options) => getSync(schema.ast, false, options); +var encodeUnknownOption = (schema, options) => getOption3(schema.ast, false, options); +var encodeUnknownEither = (schema, options) => getEither(schema.ast, false, options); +var encodeUnknown = (schema, options) => getEffect(schema.ast, false, options); +var decodeSync = decodeUnknownSync; +var decodeOption = decodeUnknownOption; +var validateSync = (schema, options) => getSync(typeAST(schema.ast), true, options); +var validateOption = (schema, options) => getOption3(typeAST(schema.ast), true, options); +var validateEither = (schema, options) => getEither(typeAST(schema.ast), true, options); +var validate4 = (schema, options) => getEffect(typeAST(schema.ast), true, options); +var is = (schema, options) => { + const parser = goMemo(typeAST(schema.ast), true); + return (u, overrideOptions) => isRight2(parser(u, { + exact: true, + ...mergeInternalOptions(options, overrideOptions) + })); +}; +var asserts = (schema, options) => { + const parser = goMemo(typeAST(schema.ast), true); + return (u, overrideOptions) => { + const result = parser(u, { + exact: true, + ...mergeInternalOptions(options, overrideOptions) + }); + if (isLeft2(result)) { + throw parseError(result.left); + } + }; +}; +var encodeSync = encodeUnknownSync; +var encodeOption = encodeUnknownOption; +var decodeMemoMap = /* @__PURE__ */ globalValue(/* @__PURE__ */ Symbol.for("effect/ParseResult/decodeMemoMap"), () => new WeakMap); +var encodeMemoMap = /* @__PURE__ */ globalValue(/* @__PURE__ */ Symbol.for("effect/ParseResult/encodeMemoMap"), () => new WeakMap); +var goMemo = (ast, isDecoding) => { + const memoMap = isDecoding ? decodeMemoMap : encodeMemoMap; + const memo = memoMap.get(ast); + if (memo) { + return memo; + } + const raw = go(ast, isDecoding); + const parseOptionsAnnotation = getParseOptionsAnnotation(ast); + const parserWithOptions = isSome2(parseOptionsAnnotation) ? (i, options) => raw(i, mergeInternalOptions(options, parseOptionsAnnotation.value)) : raw; + const decodingFallbackAnnotation = getDecodingFallbackAnnotation(ast); + const parser = isDecoding && isSome2(decodingFallbackAnnotation) ? (i, options) => handleForbidden(orElse5(parserWithOptions(i, options), decodingFallbackAnnotation.value), ast, i, options) : parserWithOptions; + memoMap.set(ast, parser); + return parser; +}; +var getConcurrency = (ast) => getOrUndefined(getConcurrencyAnnotation(ast)); +var getBatching = (ast) => getOrUndefined(getBatchingAnnotation(ast)); +var go = (ast, isDecoding) => { + switch (ast._tag) { + case "Refinement": { + if (isDecoding) { + const from = goMemo(ast.from, true); + return (i, options) => { + options = options ?? defaultParseOption; + const allErrors = options?.errors === "all"; + const result = flatMap10(orElse5(from(i, options), (ef) => { + const issue = new Refinement2(ast, i, "From", ef); + if (allErrors && hasStableFilter(ast) && isComposite2(ef)) { + return match2(ast.filter(i, options, ast), { + onNone: () => left2(issue), + onSome: (ep) => left2(new Composite2(ast, i, [issue, new Refinement2(ast, i, "Predicate", ep)])) + }); + } + return left2(issue); + }), (a) => match2(ast.filter(a, options, ast), { + onNone: () => right2(a), + onSome: (ep) => left2(new Refinement2(ast, i, "Predicate", ep)) + })); + return handleForbidden(result, ast, i, options); + }; + } else { + const from = goMemo(typeAST(ast), true); + const to = goMemo(dropRightRefinement(ast.from), false); + return (i, options) => handleForbidden(flatMap10(from(i, options), (a) => to(a, options)), ast, i, options); + } + } + case "Transformation": { + const transform2 = getFinalTransformation(ast.transformation, isDecoding); + const from = isDecoding ? goMemo(ast.from, true) : goMemo(ast.to, false); + const to = isDecoding ? goMemo(ast.to, true) : goMemo(ast.from, false); + return (i, options) => handleForbidden(flatMap10(mapError3(from(i, options), (e) => new Transformation2(ast, i, isDecoding ? "Encoded" : "Type", e)), (a) => flatMap10(mapError3(transform2(a, options ?? defaultParseOption, ast, i), (e) => new Transformation2(ast, i, "Transformation", e)), (i2) => mapError3(to(i2, options), (e) => new Transformation2(ast, i, isDecoding ? "Type" : "Encoded", e)))), ast, i, options); + } + case "Declaration": { + const parse2 = isDecoding ? ast.decodeUnknown(...ast.typeParameters) : ast.encodeUnknown(...ast.typeParameters); + return (i, options) => handleForbidden(parse2(i, options ?? defaultParseOption, ast), ast, i, options); + } + case "Literal": + return fromRefinement(ast, (u) => u === ast.literal); + case "UniqueSymbol": + return fromRefinement(ast, (u) => u === ast.symbol); + case "UndefinedKeyword": + return fromRefinement(ast, isUndefined); + case "NeverKeyword": + return fromRefinement(ast, isNever); + case "UnknownKeyword": + case "AnyKeyword": + case "VoidKeyword": + return right2; + case "StringKeyword": + return fromRefinement(ast, isString); + case "NumberKeyword": + return fromRefinement(ast, isNumber); + case "BooleanKeyword": + return fromRefinement(ast, isBoolean); + case "BigIntKeyword": + return fromRefinement(ast, isBigInt); + case "SymbolKeyword": + return fromRefinement(ast, isSymbol); + case "ObjectKeyword": + return fromRefinement(ast, isObject); + case "Enums": + return fromRefinement(ast, (u) => ast.enums.some(([_, value2]) => value2 === u)); + case "TemplateLiteral": { + const regex = getTemplateLiteralRegExp(ast); + return fromRefinement(ast, (u) => isString(u) && regex.test(u)); + } + case "TupleType": { + const elements = ast.elements.map((e) => goMemo(e.type, isDecoding)); + const rest = ast.rest.map((annotatedAST) => goMemo(annotatedAST.type, isDecoding)); + let requiredTypes = ast.elements.filter((e) => !e.isOptional); + if (ast.rest.length > 0) { + requiredTypes = requiredTypes.concat(ast.rest.slice(1)); + } + const requiredLen = requiredTypes.length; + const expectedIndexes = ast.elements.length > 0 ? ast.elements.map((_, i) => i).join(" | ") : "never"; + const concurrency = getConcurrency(ast); + const batching = getBatching(ast); + return (input, options) => { + if (!isArray(input)) { + return left2(new Type2(ast, input)); + } + const allErrors = options?.errors === "all"; + const es = []; + let stepKey = 0; + const output = []; + const len = input.length; + for (let i2 = len;i2 <= requiredLen - 1; i2++) { + const e = new Pointer(i2, input, new Missing(requiredTypes[i2 - len])); + if (allErrors) { + es.push([stepKey++, e]); + continue; + } else { + return left2(new Composite2(ast, input, e, output)); + } + } + if (ast.rest.length === 0) { + for (let i2 = ast.elements.length;i2 <= len - 1; i2++) { + const e = new Pointer(i2, input, new Unexpected(input[i2], `is unexpected, expected: ${expectedIndexes}`)); + if (allErrors) { + es.push([stepKey++, e]); + continue; + } else { + return left2(new Composite2(ast, input, e, output)); + } + } + } + let i = 0; + let queue = undefined; + for (;i < elements.length; i++) { + if (len < i + 1) { + if (ast.elements[i].isOptional) { + continue; + } + } else { + const parser = elements[i]; + const te = parser(input[i], options); + if (isEither3(te)) { + if (isLeft2(te)) { + const e = new Pointer(i, input, te.left); + if (allErrors) { + es.push([stepKey++, e]); + continue; + } else { + return left2(new Composite2(ast, input, e, sortByIndex(output))); + } + } + output.push([stepKey++, te.right]); + } else { + const nk = stepKey++; + const index = i; + if (!queue) { + queue = []; + } + queue.push(({ + es: es2, + output: output2 + }) => flatMap9(either3(te), (t) => { + if (isLeft2(t)) { + const e = new Pointer(index, input, t.left); + if (allErrors) { + es2.push([nk, e]); + return _void; + } else { + return left2(new Composite2(ast, input, e, sortByIndex(output2))); + } + } + output2.push([nk, t.right]); + return _void; + })); + } + } + } + if (isNonEmptyReadonlyArray(rest)) { + const [head5, ...tail] = rest; + for (;i < len - tail.length; i++) { + const te = head5(input[i], options); + if (isEither3(te)) { + if (isLeft2(te)) { + const e = new Pointer(i, input, te.left); + if (allErrors) { + es.push([stepKey++, e]); + continue; + } else { + return left2(new Composite2(ast, input, e, sortByIndex(output))); + } + } else { + output.push([stepKey++, te.right]); + } + } else { + const nk = stepKey++; + const index = i; + if (!queue) { + queue = []; + } + queue.push(({ + es: es2, + output: output2 + }) => flatMap9(either3(te), (t) => { + if (isLeft2(t)) { + const e = new Pointer(index, input, t.left); + if (allErrors) { + es2.push([nk, e]); + return _void; + } else { + return left2(new Composite2(ast, input, e, sortByIndex(output2))); + } + } else { + output2.push([nk, t.right]); + return _void; + } + })); + } + } + for (let j = 0;j < tail.length; j++) { + const index = i + j; + if (len < index + 1) { + continue; + } else { + const te = tail[j](input[index], options); + if (isEither3(te)) { + if (isLeft2(te)) { + const e = new Pointer(index, input, te.left); + if (allErrors) { + es.push([stepKey++, e]); + continue; + } else { + return left2(new Composite2(ast, input, e, sortByIndex(output))); + } + } + output.push([stepKey++, te.right]); + } else { + const nk = stepKey++; + if (!queue) { + queue = []; + } + queue.push(({ + es: es2, + output: output2 + }) => flatMap9(either3(te), (t) => { + if (isLeft2(t)) { + const e = new Pointer(index, input, t.left); + if (allErrors) { + es2.push([nk, e]); + return _void; + } else { + return left2(new Composite2(ast, input, e, sortByIndex(output2))); + } + } + output2.push([nk, t.right]); + return _void; + })); + } + } + } + } + const computeResult = ({ + es: es2, + output: output2 + }) => isNonEmptyArray2(es2) ? left2(new Composite2(ast, input, sortByIndex(es2), sortByIndex(output2))) : right2(sortByIndex(output2)); + if (queue && queue.length > 0) { + const cqueue = queue; + return suspend3(() => { + const state = { + es: copy(es), + output: copy(output) + }; + return flatMap9(forEach7(cqueue, (f) => f(state), { + concurrency, + batching, + discard: true + }), () => computeResult(state)); + }); + } + return computeResult({ + output, + es + }); + }; + } + case "TypeLiteral": { + if (ast.propertySignatures.length === 0 && ast.indexSignatures.length === 0) { + return fromRefinement(ast, isNotNullable); + } + const propertySignatures = []; + const expectedKeysMap = {}; + const expectedKeys = []; + for (const ps of ast.propertySignatures) { + propertySignatures.push([goMemo(ps.type, isDecoding), ps]); + expectedKeysMap[ps.name] = null; + expectedKeys.push(ps.name); + } + const indexSignatures = ast.indexSignatures.map((is2) => [goMemo(is2.parameter, isDecoding), goMemo(is2.type, isDecoding), is2.parameter]); + const expectedAST = Union.make(ast.indexSignatures.map((is2) => is2.parameter).concat(expectedKeys.map((key) => isSymbol(key) ? new UniqueSymbol(key) : new Literal(key)))); + const expected = goMemo(expectedAST, isDecoding); + const concurrency = getConcurrency(ast); + const batching = getBatching(ast); + return (input, options) => { + if (!isRecord(input)) { + return left2(new Type2(ast, input)); + } + const allErrors = options?.errors === "all"; + const es = []; + let stepKey = 0; + const onExcessPropertyError = options?.onExcessProperty === "error"; + const onExcessPropertyPreserve = options?.onExcessProperty === "preserve"; + const output = {}; + let inputKeys; + if (onExcessPropertyError || onExcessPropertyPreserve) { + inputKeys = Reflect.ownKeys(input); + for (const key of inputKeys) { + const te = expected(key, options); + if (isEither3(te) && isLeft2(te)) { + if (onExcessPropertyError) { + const e = new Pointer(key, input, new Unexpected(input[key], `is unexpected, expected: ${String(expectedAST)}`)); + if (allErrors) { + es.push([stepKey++, e]); + continue; + } else { + return left2(new Composite2(ast, input, e, output)); + } + } else { + output[key] = input[key]; + } + } + } + } + let queue = undefined; + const isExact = options?.exact === true; + for (let i = 0;i < propertySignatures.length; i++) { + const ps = propertySignatures[i][1]; + const name = ps.name; + const hasKey = Object.prototype.hasOwnProperty.call(input, name); + if (!hasKey) { + if (ps.isOptional) { + continue; + } else if (isExact) { + const e = new Pointer(name, input, new Missing(ps)); + if (allErrors) { + es.push([stepKey++, e]); + continue; + } else { + return left2(new Composite2(ast, input, e, output)); + } + } + } + const parser = propertySignatures[i][0]; + const te = parser(input[name], options); + if (isEither3(te)) { + if (isLeft2(te)) { + const e = new Pointer(name, input, hasKey ? te.left : new Missing(ps)); + if (allErrors) { + es.push([stepKey++, e]); + continue; + } else { + return left2(new Composite2(ast, input, e, output)); + } + } + output[name] = te.right; + } else { + const nk = stepKey++; + const index = name; + if (!queue) { + queue = []; + } + queue.push(({ + es: es2, + output: output2 + }) => flatMap9(either3(te), (t) => { + if (isLeft2(t)) { + const e = new Pointer(index, input, hasKey ? t.left : new Missing(ps)); + if (allErrors) { + es2.push([nk, e]); + return _void; + } else { + return left2(new Composite2(ast, input, e, output2)); + } + } + output2[index] = t.right; + return _void; + })); + } + } + for (let i = 0;i < indexSignatures.length; i++) { + const indexSignature = indexSignatures[i]; + const parameter = indexSignature[0]; + const type = indexSignature[1]; + const keys5 = getKeysForIndexSignature(input, indexSignature[2]); + for (const key of keys5) { + const keu = parameter(key, options); + if (isEither3(keu) && isRight2(keu)) { + const vpr = type(input[key], options); + if (isEither3(vpr)) { + if (isLeft2(vpr)) { + const e = new Pointer(key, input, vpr.left); + if (allErrors) { + es.push([stepKey++, e]); + continue; + } else { + return left2(new Composite2(ast, input, e, output)); + } + } else { + if (!Object.prototype.hasOwnProperty.call(expectedKeysMap, key)) { + output[key] = vpr.right; + } + } + } else { + const nk = stepKey++; + const index = key; + if (!queue) { + queue = []; + } + queue.push(({ + es: es2, + output: output2 + }) => flatMap9(either3(vpr), (tv) => { + if (isLeft2(tv)) { + const e = new Pointer(index, input, tv.left); + if (allErrors) { + es2.push([nk, e]); + return _void; + } else { + return left2(new Composite2(ast, input, e, output2)); + } + } else { + if (!Object.prototype.hasOwnProperty.call(expectedKeysMap, key)) { + output2[key] = tv.right; + } + return _void; + } + })); + } + } + } + } + const computeResult = ({ + es: es2, + output: output2 + }) => { + if (isNonEmptyArray2(es2)) { + return left2(new Composite2(ast, input, sortByIndex(es2), output2)); + } + if (options?.propertyOrder === "original") { + const keys5 = inputKeys || Reflect.ownKeys(input); + for (const name of expectedKeys) { + if (keys5.indexOf(name) === -1) { + keys5.push(name); + } + } + const out = {}; + for (const key of keys5) { + if (Object.prototype.hasOwnProperty.call(output2, key)) { + out[key] = output2[key]; + } + } + return right2(out); + } + return right2(output2); + }; + if (queue && queue.length > 0) { + const cqueue = queue; + return suspend3(() => { + const state = { + es: copy(es), + output: Object.assign({}, output) + }; + return flatMap9(forEach7(cqueue, (f) => f(state), { + concurrency, + batching, + discard: true + }), () => computeResult(state)); + }); + } + return computeResult({ + es, + output + }); + }; + } + case "Union": { + const searchTree = getSearchTree(ast.types, isDecoding); + const ownKeys = Reflect.ownKeys(searchTree.keys); + const ownKeysLen = ownKeys.length; + const astTypesLen = ast.types.length; + const map14 = new Map; + for (let i = 0;i < astTypesLen; i++) { + map14.set(ast.types[i], goMemo(ast.types[i], isDecoding)); + } + const concurrency = getConcurrency(ast) ?? 1; + const batching = getBatching(ast); + return (input, options) => { + const es = []; + let stepKey = 0; + let candidates = []; + if (ownKeysLen > 0) { + if (isRecordOrArray(input)) { + for (let i = 0;i < ownKeysLen; i++) { + const name = ownKeys[i]; + const buckets = searchTree.keys[name].buckets; + if (Object.prototype.hasOwnProperty.call(input, name)) { + const literal2 = String(input[name]); + if (Object.prototype.hasOwnProperty.call(buckets, literal2)) { + candidates = candidates.concat(buckets[literal2]); + } else { + const { + candidates: candidates2, + literals + } = searchTree.keys[name]; + const literalsUnion = Union.make(literals); + const errorAst = candidates2.length === astTypesLen ? new TypeLiteral([new PropertySignature(name, literalsUnion, false, true)], []) : Union.make(candidates2); + es.push([stepKey++, new Composite2(errorAst, input, new Pointer(name, input, new Type2(literalsUnion, input[name])))]); + } + } else { + const { + candidates: candidates2, + literals + } = searchTree.keys[name]; + const fakePropertySignature = new PropertySignature(name, Union.make(literals), false, true); + const errorAst = candidates2.length === astTypesLen ? new TypeLiteral([fakePropertySignature], []) : Union.make(candidates2); + es.push([stepKey++, new Composite2(errorAst, input, new Pointer(name, input, new Missing(fakePropertySignature)))]); + } + } + } else { + const errorAst = searchTree.candidates.length === astTypesLen ? ast : Union.make(searchTree.candidates); + es.push([stepKey++, new Type2(errorAst, input)]); + } + } + if (searchTree.otherwise.length > 0) { + candidates = candidates.concat(searchTree.otherwise); + } + let queue = undefined; + for (let i = 0;i < candidates.length; i++) { + const candidate = candidates[i]; + const pr = map14.get(candidate)(input, options); + if (isEither3(pr) && (!queue || queue.length === 0)) { + if (isRight2(pr)) { + return pr; + } else { + es.push([stepKey++, pr.left]); + } + } else { + const nk = stepKey++; + if (!queue) { + queue = []; + } + queue.push((state) => suspend3(() => { + if ("finalResult" in state) { + return _void; + } else { + return flatMap9(either3(pr), (t) => { + if (isRight2(t)) { + state.finalResult = t; + } else { + state.es.push([nk, t.left]); + } + return _void; + }); + } + })); + } + } + const computeResult = (es2) => isNonEmptyArray2(es2) ? es2.length === 1 && es2[0][1]._tag === "Type" ? left2(es2[0][1]) : left2(new Composite2(ast, input, sortByIndex(es2))) : left2(new Type2(ast, input)); + if (queue && queue.length > 0) { + const cqueue = queue; + return suspend3(() => { + const state = { + es: copy(es) + }; + return flatMap9(forEach7(cqueue, (f) => f(state), { + concurrency, + batching, + discard: true + }), () => { + if ("finalResult" in state) { + return state.finalResult; + } + return computeResult(state.es); + }); + }); + } + return computeResult(es); + }; + } + case "Suspend": { + const get13 = memoizeThunk(() => goMemo(ast.f(), isDecoding)); + return (a, options) => get13()(a, options); + } + } +}; +var fromRefinement = (ast, refinement) => (u) => refinement(u) ? right2(u) : left2(new Type2(ast, u)); +var getLiterals = (ast, isDecoding) => { + switch (ast._tag) { + case "Declaration": { + const annotation = getSurrogateAnnotation(ast); + if (isSome2(annotation)) { + return getLiterals(annotation.value, isDecoding); + } + break; + } + case "TypeLiteral": { + const out = []; + for (let i = 0;i < ast.propertySignatures.length; i++) { + const propertySignature = ast.propertySignatures[i]; + const type = isDecoding ? encodedAST(propertySignature.type) : typeAST(propertySignature.type); + if (isLiteral(type) && !propertySignature.isOptional) { + out.push([propertySignature.name, type]); + } + } + return out; + } + case "TupleType": { + const out = []; + for (let i = 0;i < ast.elements.length; i++) { + const element = ast.elements[i]; + const type = isDecoding ? encodedAST(element.type) : typeAST(element.type); + if (isLiteral(type) && !element.isOptional) { + out.push([i, type]); + } + } + return out; + } + case "Refinement": + return getLiterals(ast.from, isDecoding); + case "Suspend": + return getLiterals(ast.f(), isDecoding); + case "Transformation": + return getLiterals(isDecoding ? ast.from : ast.to, isDecoding); + } + return []; +}; +var getSearchTree = (members, isDecoding) => { + const keys5 = {}; + const otherwise = []; + const candidates = []; + for (let i = 0;i < members.length; i++) { + const member = members[i]; + const tags = getLiterals(member, isDecoding); + if (tags.length > 0) { + candidates.push(member); + for (let j = 0;j < tags.length; j++) { + const [key, literal2] = tags[j]; + const hash2 = String(literal2.literal); + keys5[key] = keys5[key] || { + buckets: {}, + literals: [], + candidates: [] + }; + const buckets = keys5[key].buckets; + if (Object.prototype.hasOwnProperty.call(buckets, hash2)) { + if (j < tags.length - 1) { + continue; + } + buckets[hash2].push(member); + keys5[key].literals.push(literal2); + keys5[key].candidates.push(member); + } else { + buckets[hash2] = [member]; + keys5[key].literals.push(literal2); + keys5[key].candidates.push(member); + break; + } + } + } else { + otherwise.push(member); + } + } + return { + keys: keys5, + otherwise, + candidates + }; +}; +var dropRightRefinement = (ast) => isRefinement(ast) ? dropRightRefinement(ast.from) : ast; +var handleForbidden = (effect, ast, actual, options) => { + if (options?.isEffectAllowed === true) { + return effect; + } + if (isEither3(effect)) { + return effect; + } + const scheduler = new SyncScheduler; + const fiber = runFork2(effect, { + scheduler + }); + scheduler.flush(); + const exit3 = fiber.unsafePoll(); + if (exit3) { + if (isSuccess2(exit3)) { + return right2(exit3.value); + } + const cause3 = exit3.cause; + if (isFailType2(cause3)) { + return left2(cause3.error); + } + return left2(new Forbidden(ast, actual, pretty2(cause3))); + } + return left2(new Forbidden(ast, actual, "cannot be be resolved synchronously, this is caused by using runSync on an effect that performs async work")); +}; +var compare = ([a], [b]) => a > b ? 1 : a < b ? -1 : 0; +function sortByIndex(es) { + return es.sort(compare).map((t) => t[1]); +} +var getFinalTransformation = (transformation, isDecoding) => { + switch (transformation._tag) { + case "FinalTransformation": + return isDecoding ? transformation.decode : transformation.encode; + case "ComposeTransformation": + return right2; + case "TypeLiteralTransformation": + return (input) => { + let out = right2(input); + for (const pst of transformation.propertySignatureTransformations) { + const [from, to] = isDecoding ? [pst.from, pst.to] : [pst.to, pst.from]; + const transformation2 = isDecoding ? pst.decode : pst.encode; + const f = (input2) => { + const o = transformation2(Object.prototype.hasOwnProperty.call(input2, from) ? some2(input2[from]) : none2()); + delete input2[from]; + if (isSome2(o)) { + input2[to] = o.value; + } + return input2; + }; + out = map13(out, f); + } + return out; + }; + } +}; +var makeTree = (value2, forest = []) => ({ + value: value2, + forest +}); +var TreeFormatter = { + formatIssue: (issue) => map13(formatTree(issue), drawTree), + formatIssueSync: (issue) => { + const e = TreeFormatter.formatIssue(issue); + return isEither3(e) ? getOrThrow(e) : runSync(e); + }, + formatError: (error) => TreeFormatter.formatIssue(error.issue), + formatErrorSync: (error) => TreeFormatter.formatIssueSync(error.issue) +}; +var drawTree = (tree) => tree.value + draw(` +`, tree.forest); +var draw = (indentation, forest) => { + let r = ""; + const len = forest.length; + let tree; + for (let i = 0;i < len; i++) { + tree = forest[i]; + const isLast = i === len - 1; + r += indentation + (isLast ? "\u2514" : "\u251C") + "\u2500 " + tree.value; + r += draw(indentation + (len > 1 && !isLast ? "\u2502 " : " "), tree.forest); + } + return r; +}; +var formatTransformationKind = (kind) => { + switch (kind) { + case "Encoded": + return "Encoded side transformation failure"; + case "Transformation": + return "Transformation process failure"; + case "Type": + return "Type side transformation failure"; + } +}; +var formatRefinementKind = (kind) => { + switch (kind) { + case "From": + return "From side refinement failure"; + case "Predicate": + return "Predicate refinement failure"; + } +}; +var getAnnotated = (issue) => ("ast" in issue) ? some2(issue.ast) : none2(); +var Either_void = /* @__PURE__ */ right2(undefined); +var getCurrentMessage = (issue) => getAnnotated(issue).pipe(flatMap(getMessageAnnotation), match2({ + onNone: () => Either_void, + onSome: (messageAnnotation) => { + const union8 = messageAnnotation(issue); + if (isString(union8)) { + return right2({ + message: union8, + override: false + }); + } + if (isEffect2(union8)) { + return map11(union8, (message) => ({ + message, + override: false + })); + } + if (isString(union8.message)) { + return right2({ + message: union8.message, + override: union8.override + }); + } + return map11(union8.message, (message) => ({ + message, + override: union8.override + })); + } +})); +var createParseIssueGuard = (tag) => (issue) => issue._tag === tag; +var isComposite2 = /* @__PURE__ */ createParseIssueGuard("Composite"); +var isRefinement2 = /* @__PURE__ */ createParseIssueGuard("Refinement"); +var isTransformation2 = /* @__PURE__ */ createParseIssueGuard("Transformation"); +var getMessage = (issue) => flatMap10(getCurrentMessage(issue), (currentMessage) => { + if (currentMessage !== undefined) { + const useInnerMessage = !currentMessage.override && (isComposite2(issue) || isRefinement2(issue) && issue.kind === "From" || isTransformation2(issue) && issue.kind !== "Transformation"); + return useInnerMessage ? isTransformation2(issue) || isRefinement2(issue) ? getMessage(issue.issue) : Either_void : right2(currentMessage.message); + } + return Either_void; +}); +var getParseIssueTitleAnnotation2 = (issue) => getAnnotated(issue).pipe(flatMap(getParseIssueTitleAnnotation), flatMapNullable((annotation) => annotation(issue)), getOrUndefined); +function getRefinementExpected(ast) { + return getDescriptionAnnotation(ast).pipe(orElse(() => getTitleAnnotation(ast)), orElse(() => getAutoTitleAnnotation(ast)), orElse(() => getIdentifierAnnotation(ast)), getOrElse(() => `{ ${ast.from} | filter }`)); +} +function getDefaultTypeMessage(issue) { + if (issue.message !== undefined) { + return issue.message; + } + const expected = isRefinement(issue.ast) ? getRefinementExpected(issue.ast) : String(issue.ast); + return `Expected ${expected}, actual ${formatUnknown(issue.actual)}`; +} +var formatTypeMessage = (issue) => map13(getMessage(issue), (message) => message ?? getParseIssueTitleAnnotation2(issue) ?? getDefaultTypeMessage(issue)); +var getParseIssueTitle = (issue) => getParseIssueTitleAnnotation2(issue) ?? String(issue.ast); +var formatForbiddenMessage = (issue) => issue.message ?? "is forbidden"; +var formatUnexpectedMessage = (issue) => issue.message ?? "is unexpected"; +var formatMissingMessage = (issue) => { + const missingMessageAnnotation = getMissingMessageAnnotation(issue.ast); + if (isSome2(missingMessageAnnotation)) { + const annotation = missingMessageAnnotation.value(); + return isString(annotation) ? right2(annotation) : annotation; + } + return right2(issue.message ?? "is missing"); +}; +var formatTree = (issue) => { + switch (issue._tag) { + case "Type": + return map13(formatTypeMessage(issue), makeTree); + case "Forbidden": + return right2(makeTree(getParseIssueTitle(issue), [makeTree(formatForbiddenMessage(issue))])); + case "Unexpected": + return right2(makeTree(formatUnexpectedMessage(issue))); + case "Missing": + return map13(formatMissingMessage(issue), makeTree); + case "Transformation": + return flatMap10(getMessage(issue), (message) => { + if (message !== undefined) { + return right2(makeTree(message)); + } + return map13(formatTree(issue.issue), (tree) => makeTree(getParseIssueTitle(issue), [makeTree(formatTransformationKind(issue.kind), [tree])])); + }); + case "Refinement": + return flatMap10(getMessage(issue), (message) => { + if (message !== undefined) { + return right2(makeTree(message)); + } + return map13(formatTree(issue.issue), (tree) => makeTree(getParseIssueTitle(issue), [makeTree(formatRefinementKind(issue.kind), [tree])])); + }); + case "Pointer": + return map13(formatTree(issue.issue), (tree) => makeTree(formatPath(issue.path), [tree])); + case "Composite": + return flatMap10(getMessage(issue), (message) => { + if (message !== undefined) { + return right2(makeTree(message)); + } + const parseIssueTitle = getParseIssueTitle(issue); + return isNonEmpty6(issue.issues) ? map13(forEach7(issue.issues, formatTree), (forest) => makeTree(parseIssueTitle, forest)) : map13(formatTree(issue.issues), (tree) => makeTree(parseIssueTitle, [tree])); + }); + } +}; +var makeArrayFormatterIssue = (_tag, path, message) => ({ + _tag, + path, + message +}); +var ArrayFormatter = { + formatIssue: (issue) => getArrayFormatterIssues(issue, undefined, []), + formatIssueSync: (issue) => { + const e = ArrayFormatter.formatIssue(issue); + return isEither3(e) ? getOrThrow(e) : runSync(e); + }, + formatError: (error) => ArrayFormatter.formatIssue(error.issue), + formatErrorSync: (error) => ArrayFormatter.formatIssueSync(error.issue) +}; +var getArrayFormatterIssues = (issue, parentTag, path) => { + const _tag = issue._tag; + switch (_tag) { + case "Type": + return map13(formatTypeMessage(issue), (message) => [makeArrayFormatterIssue(parentTag ?? _tag, path, message)]); + case "Forbidden": + return right2([makeArrayFormatterIssue(_tag, path, formatForbiddenMessage(issue))]); + case "Unexpected": + return right2([makeArrayFormatterIssue(_tag, path, formatUnexpectedMessage(issue))]); + case "Missing": + return map13(formatMissingMessage(issue), (message) => [makeArrayFormatterIssue(_tag, path, message)]); + case "Pointer": + return getArrayFormatterIssues(issue.issue, undefined, path.concat(issue.path)); + case "Composite": + return flatMap10(getMessage(issue), (message) => { + if (message !== undefined) { + return right2([makeArrayFormatterIssue(_tag, path, message)]); + } + return isNonEmpty6(issue.issues) ? map13(forEach7(issue.issues, (issue2) => getArrayFormatterIssues(issue2, undefined, path)), flatten) : getArrayFormatterIssues(issue.issues, undefined, path); + }); + case "Refinement": + return flatMap10(getMessage(issue), (message) => { + if (message !== undefined) { + return right2([makeArrayFormatterIssue(_tag, path, message)]); + } + return getArrayFormatterIssues(issue.issue, issue.kind === "Predicate" ? _tag : undefined, path); + }); + case "Transformation": + return flatMap10(getMessage(issue), (message) => { + if (message !== undefined) { + return right2([makeArrayFormatterIssue(_tag, path, message)]); + } + return getArrayFormatterIssues(issue.issue, issue.kind === "Transformation" ? _tag : undefined, path); + }); + } +}; + +// node_modules/effect/dist/esm/Redacted.js +var isRedacted2 = isRedacted; +var make42 = make40; +var value2 = value; +var getEquivalence7 = (isEquivalent) => make((x, y) => isEquivalent(value2(x), value2(y))); + // node_modules/effect/dist/esm/Struct.js var pick3 = /* @__PURE__ */ dual((args2) => isObject(args2[0]), (s, ...keys5) => { const out = {}; @@ -19596,7 +19611,7 @@ var variance5 = { _I: (_) => _, _R: (_) => _ }; -var makeStandardResult = (exit3) => isSuccess(exit3) ? exit3.value : makeStandardFailureResult(pretty2(exit3.cause)); +var makeStandardResult = (exit3) => isSuccess2(exit3) ? exit3.value : makeStandardFailureResult(pretty2(exit3.cause)); var makeStandardFailureResult = (message) => ({ issues: [{ message @@ -20426,8 +20441,8 @@ function makeRecordClass(key, value3, ast) { }; } var Record = (options) => makeRecordClass(options.key, options.value); -var pick4 = (...keys5) => (self) => make43(pick(self.ast, keys5)); -var omit4 = (...keys5) => (self) => make43(omit(self.ast, keys5)); +var pick4 = (...keys5) => (self) => make43(pick2(self.ast, keys5)); +var omit4 = (...keys5) => (self) => make43(omit2(self.ast, keys5)); var pluck = /* @__PURE__ */ dual(2, (schema, key) => { const ps = getPropertyKeyIndexedAccess(typeAST(schema.ast), key); const value3 = make43(ps.isOptional ? orUndefined(ps.type) : ps.type); @@ -21125,7 +21140,7 @@ var nonNegative = (annotations3) => greaterThanOrEqualTo5(0, { var clamp8 = (minimum, maximum) => (self) => { return transform2(self, typeSchema(self).pipe(between5(minimum, maximum)), { strict: false, - decode: (i) => clamp3(i, { + decode: (i) => clamp4(i, { minimum, maximum }), @@ -21282,7 +21297,7 @@ var nonPositiveBigInt = (annotations3) => lessThanOrEqualToBigInt(0n, { }); var clampBigInt = (minimum, maximum) => (self) => transform2(self, self.pipe(typeSchema, betweenBigInt(minimum, maximum)), { strict: false, - decode: (i) => clamp5(i, { + decode: (i) => clamp6(i, { minimum, maximum }), @@ -21369,7 +21384,7 @@ class DurationFromSelf extends (/* @__PURE__ */ declare(isDuration, { arbitrary: () => (fc) => fc.oneof(fc.constant(infinity), fc.bigInt({ min: 0n }).map((_) => nanos(_)), fc.maxSafeNat().map((_) => millis(_))), - equivalence: () => Equivalence2 + equivalence: () => Equivalence })) { } @@ -21466,14 +21481,14 @@ class Duration extends (/* @__PURE__ */ transform2(Union2(DurationValue, HRTime) } var clampDuration = (minimum, maximum) => (self) => transform2(self, self.pipe(typeSchema, betweenDuration(minimum, maximum)), { strict: false, - decode: (i) => clamp6(i, { + decode: (i) => clamp3(i, { minimum, maximum }), encode: identity }); var LessThanDurationSchemaId = /* @__PURE__ */ Symbol.for("effect/SchemaId/LessThanDuration"); -var lessThanDuration = (max6, annotations3) => (self) => self.pipe(filter8((a) => lessThan3(a, max6), { +var lessThanDuration = (max6, annotations3) => (self) => self.pipe(filter8((a) => lessThan2(a, max6), { schemaId: LessThanDurationSchemaId, [LessThanDurationSchemaId]: { max: max6 @@ -21483,7 +21498,7 @@ var lessThanDuration = (max6, annotations3) => (self) => self.pipe(filter8((a) = ...annotations3 })); var LessThanOrEqualToDurationSchemaId = /* @__PURE__ */ Symbol.for("effect/schema/LessThanOrEqualToDuration"); -var lessThanOrEqualToDuration = (max6, annotations3) => (self) => self.pipe(filter8((a) => lessThanOrEqualTo3(a, max6), { +var lessThanOrEqualToDuration = (max6, annotations3) => (self) => self.pipe(filter8((a) => lessThanOrEqualTo2(a, max6), { schemaId: LessThanDurationSchemaId, [LessThanDurationSchemaId]: { max: max6 @@ -21493,7 +21508,7 @@ var lessThanOrEqualToDuration = (max6, annotations3) => (self) => self.pipe(filt ...annotations3 })); var GreaterThanDurationSchemaId = /* @__PURE__ */ Symbol.for("effect/SchemaId/GreaterThanDuration"); -var greaterThanDuration = (min4, annotations3) => (self) => self.pipe(filter8((a) => greaterThan3(a, min4), { +var greaterThanDuration = (min4, annotations3) => (self) => self.pipe(filter8((a) => greaterThan2(a, min4), { schemaId: GreaterThanDurationSchemaId, [GreaterThanDurationSchemaId]: { min: min4 @@ -21503,7 +21518,7 @@ var greaterThanDuration = (min4, annotations3) => (self) => self.pipe(filter8((a ...annotations3 })); var GreaterThanOrEqualToDurationSchemaId = /* @__PURE__ */ Symbol.for("effect/schema/GreaterThanOrEqualToDuration"); -var greaterThanOrEqualToDuration = (min4, annotations3) => (self) => self.pipe(filter8((a) => greaterThanOrEqualTo3(a, min4), { +var greaterThanOrEqualToDuration = (min4, annotations3) => (self) => self.pipe(filter8((a) => greaterThanOrEqualTo2(a, min4), { schemaId: GreaterThanOrEqualToDurationSchemaId, [GreaterThanOrEqualToDurationSchemaId]: { min: min4 @@ -21513,7 +21528,7 @@ var greaterThanOrEqualToDuration = (min4, annotations3) => (self) => self.pipe(f ...annotations3 })); var BetweenDurationSchemaId = /* @__PURE__ */ Symbol.for("effect/SchemaId/BetweenDuration"); -var betweenDuration = (minimum, maximum, annotations3) => (self) => self.pipe(filter8((a) => between3(a, { +var betweenDuration = (minimum, maximum, annotations3) => (self) => self.pipe(filter8((a) => between2(a, { minimum, maximum }), { @@ -22013,7 +22028,7 @@ function OptionFromUndefinedOr(value3) { class OptionFromNonEmptyTrimmedString extends (/* @__PURE__ */ transform2(String$, /* @__PURE__ */ OptionFromSelf(NonEmptyTrimmedString), { strict: true, - decode: (i) => filter(some2(i.trim()), isNonEmpty6), + decode: (i) => filter(some2(i.trim()), isNonEmpty5), encode: (a) => getOrElse(a, () => "") })) { } @@ -22254,11 +22269,11 @@ function set6(value3) { encode: (a) => Array.from(a) }); } -var bigDecimalPretty = () => (val) => `BigDecimal(${format2(normalize(val))})`; +var bigDecimalPretty = () => (val) => `BigDecimal(${format4(normalize(val))})`; var bigDecimalArbitrary = () => (fc) => fc.tuple(fc.bigInt(), fc.integer({ min: -18, max: 18 -})).map(([value3, scale2]) => make4(value3, scale2)); +})).map(([value3, scale2]) => make39(value3, scale2)); class BigDecimalFromSelf extends (/* @__PURE__ */ declare(isBigDecimal, { typeConstructor: { @@ -22267,7 +22282,7 @@ class BigDecimalFromSelf extends (/* @__PURE__ */ declare(isBigDecimal, { identifier: "BigDecimalFromSelf", pretty: bigDecimalPretty, arbitrary: bigDecimalArbitrary, - equivalence: () => Equivalence + equivalence: () => Equivalence3 })) { } @@ -22279,7 +22294,7 @@ class BigDecimal extends (/* @__PURE__ */ transformOrFail(String$.annotations({ onNone: () => fail7(new Type2(ast, i, `Unable to decode ${JSON.stringify(i)} into a BigDecimal`)), onSome: (val) => succeed8(normalize(val)) })), - encode: (a) => succeed8(format2(normalize(a))) + encode: (a) => succeed8(format4(normalize(a))) }).annotations({ identifier: "BigDecimal" })) { @@ -22297,8 +22312,8 @@ class BigDecimalFromNumber extends (/* @__PURE__ */ transform2(Number$.annotatio } var GreaterThanBigDecimalSchemaId = /* @__PURE__ */ Symbol.for("effect/SchemaId/GreaterThanBigDecimal"); var greaterThanBigDecimal = (min4, annotations3) => (self) => { - const formatted = format2(min4); - return self.pipe(filter8((a) => greaterThan2(a, min4), { + const formatted = format4(min4); + return self.pipe(filter8((a) => greaterThan4(a, min4), { schemaId: GreaterThanBigDecimalSchemaId, [GreaterThanBigDecimalSchemaId]: { min: min4 @@ -22310,8 +22325,8 @@ var greaterThanBigDecimal = (min4, annotations3) => (self) => { }; var GreaterThanOrEqualToBigDecimalSchemaId = /* @__PURE__ */ Symbol.for("effect/schema/GreaterThanOrEqualToBigDecimal"); var greaterThanOrEqualToBigDecimal = (min4, annotations3) => (self) => { - const formatted = format2(min4); - return self.pipe(filter8((a) => greaterThanOrEqualTo2(a, min4), { + const formatted = format4(min4); + return self.pipe(filter8((a) => greaterThanOrEqualTo3(a, min4), { schemaId: GreaterThanOrEqualToBigDecimalSchemaId, [GreaterThanOrEqualToBigDecimalSchemaId]: { min: min4 @@ -22323,8 +22338,8 @@ var greaterThanOrEqualToBigDecimal = (min4, annotations3) => (self) => { }; var LessThanBigDecimalSchemaId = /* @__PURE__ */ Symbol.for("effect/SchemaId/LessThanBigDecimal"); var lessThanBigDecimal = (max6, annotations3) => (self) => { - const formatted = format2(max6); - return self.pipe(filter8((a) => lessThan2(a, max6), { + const formatted = format4(max6); + return self.pipe(filter8((a) => lessThan7(a, max6), { schemaId: LessThanBigDecimalSchemaId, [LessThanBigDecimalSchemaId]: { max: max6 @@ -22336,8 +22351,8 @@ var lessThanBigDecimal = (max6, annotations3) => (self) => { }; var LessThanOrEqualToBigDecimalSchemaId = /* @__PURE__ */ Symbol.for("effect/schema/LessThanOrEqualToBigDecimal"); var lessThanOrEqualToBigDecimal = (max6, annotations3) => (self) => { - const formatted = format2(max6); - return self.pipe(filter8((a) => lessThanOrEqualTo2(a, max6), { + const formatted = format4(max6); + return self.pipe(filter8((a) => lessThanOrEqualTo3(a, max6), { schemaId: LessThanOrEqualToBigDecimalSchemaId, [LessThanOrEqualToBigDecimalSchemaId]: { max: max6 @@ -22389,9 +22404,9 @@ var NonPositiveBigDecimalFromSelf = /* @__PURE__ */ BigDecimalFromSelf.pipe(/* @ })); var BetweenBigDecimalSchemaId = /* @__PURE__ */ Symbol.for("effect/SchemaId/BetweenBigDecimal"); var betweenBigDecimal = (minimum, maximum, annotations3) => (self) => { - const formattedMinimum = format2(minimum); - const formattedMaximum = format2(maximum); - return self.pipe(filter8((a) => between2(a, { + const formattedMinimum = format4(minimum); + const formattedMaximum = format4(maximum); + return self.pipe(filter8((a) => between3(a, { minimum, maximum }), { @@ -22407,7 +22422,7 @@ var betweenBigDecimal = (minimum, maximum, annotations3) => (self) => { }; var clampBigDecimal = (minimum, maximum) => (self) => transform2(self, self.pipe(typeSchema, betweenBigDecimal(minimum, maximum)), { strict: false, - decode: (i) => clamp4(i, { + decode: (i) => clamp5(i, { minimum, maximum }), @@ -22418,7 +22433,7 @@ var chunkArbitrary = (item, ctx) => (fc) => { return (ctx.depthIdentifier !== undefined ? fc.oneof(ctx, fc.constant([]), items) : items).map(fromIterable2); }; var chunkPretty = (item) => (c) => `Chunk(${toReadonlyArray(c).map(item).join(", ")})`; -var chunkParse = (decodeUnknown3) => (u, options, ast) => isChunk(u) ? isEmpty(u) ? succeed8(empty4()) : toComposite(decodeUnknown3(toReadonlyArray(u), options), fromIterable2, ast, u) : fail7(new Type2(ast, u)); +var chunkParse = (decodeUnknown3) => (u, options, ast) => isChunk(u) ? isEmpty(u) ? succeed8(empty2()) : toComposite(decodeUnknown3(toReadonlyArray(u), options), fromIterable2, ast, u) : fail7(new Type2(ast, u)); var ChunkFromSelf = (value3) => { return declare([value3], { decode: (item) => chunkParse(decodeUnknown(Array$(item))), @@ -22436,15 +22451,15 @@ var ChunkFromSelf = (value3) => { function Chunk(value3) { return transform2(Array$(value3), ChunkFromSelf(typeSchema(asSchema(value3))), { strict: true, - decode: (i) => i.length === 0 ? empty4() : fromIterable2(i), + decode: (i) => i.length === 0 ? empty2() : fromIterable2(i), encode: (a) => toReadonlyArray(a) }); } -var nonEmptyChunkArbitrary = (item) => (fc) => array3(item(fc), { +var nonEmptyChunkArbitrary = (item) => (fc) => array5(item(fc), { minLength: 1 }).map((as4) => unsafeFromNonEmptyArray(as4)); var nonEmptyChunkPretty = (item) => (c) => `NonEmptyChunk(${toReadonlyArray(c).map(item).join(", ")})`; -var nonEmptyChunkParse = (decodeUnknown3) => (u, options, ast) => isChunk(u) && isNonEmpty2(u) ? toComposite(decodeUnknown3(toReadonlyArray(u), options), unsafeFromNonEmptyArray, ast, u) : fail7(new Type2(ast, u)); +var nonEmptyChunkParse = (decodeUnknown3) => (u, options, ast) => isChunk(u) && isNonEmpty(u) ? toComposite(decodeUnknown3(toReadonlyArray(u), options), unsafeFromNonEmptyArray, ast, u) : fail7(new Type2(ast, u)); var NonEmptyChunkFromSelf = (value3) => { return declare([value3], { decode: (item) => nonEmptyChunkParse(decodeUnknown(NonEmptyArray(item))), @@ -22466,7 +22481,7 @@ function NonEmptyChunk(value3) { encode: (a) => toReadonlyArray(a) }); } -var decodeData = (a) => Array.isArray(a) ? array4(a) : struct2(a); +var decodeData = (a) => Array.isArray(a) ? array3(a) : struct2(a); var dataArbitrary = (item) => (fc) => item(fc).map(decodeData); var dataPretty = (item) => (d) => `Data(${item(d)})`; var dataParse = (decodeUnknown3) => (u, options, ast) => isEqual(u) ? toComposite(decodeUnknown3(u, options), decodeData, ast, u) : fail7(new Type2(ast, u)); @@ -22497,7 +22512,7 @@ var Class5 = (identifier2) => (fieldsOr, annotations3) => makeClass({ identifier: identifier2, schema: getSchemaFromFieldsOr(fieldsOr), fields: getFieldsFromFieldsOr(fieldsOr), - Base: Class3, + Base: Class, annotations: annotations3 }); var getClassTag = (tag2) => withConstructorDefault(propertySignature(Literal2(tag2)), () => tag2); @@ -22513,7 +22528,7 @@ var TaggedClass3 = (identifier2) => (tag2, fieldsOr, annotations3) => { identifier: identifier2 ?? tag2, schema: extend2(schema, Struct(newFields)), fields: taggedFields, - Base: Class3, + Base: Class, annotations: annotations3 }) { static _tag = tag2; @@ -22521,7 +22536,7 @@ var TaggedClass3 = (identifier2) => (tag2, fieldsOr, annotations3) => { }; var TaggedError2 = (identifier2) => (tag2, fieldsOr, annotations3) => { - class Base3 extends Error3 { + class Base3 extends Error2 { } Base3.prototype.name = tag2; const fields = getFieldsFromFieldsOr(fieldsOr); @@ -22925,13 +22940,13 @@ var CauseFromSelf = ({ function causeDecode(cause3) { switch (cause3._tag) { case "Empty": - return empty26; + return empty25; case "Fail": return fail3(cause3.error); case "Die": return die3(cause3.defect); case "Interrupt": - return interrupt4(fiberIdDecode(cause3.fiberId)); + return interrupt3(fiberIdDecode(cause3.fiberId)); case "Sequential": return sequential4(causeDecode(cause3.left), causeDecode(cause3.right)); case "Parallel": @@ -23034,9 +23049,9 @@ var exitEncoded = (value3, error, defect) => { var exitDecode = (input) => { switch (input._tag) { case "Failure": - return failCause2(causeDecode(input.cause)); + return failCause3(causeDecode(input.cause)); case "Success": - return succeed2(input.value); + return succeed3(input.value); } }; var exitArbitrary = (value3, error, defect) => (fc) => fc.oneof(fc.record({ @@ -23047,9 +23062,9 @@ var exitArbitrary = (value3, error, defect) => (fc) => fc.oneof(fc.record({ value: value3(fc) })).map(exitDecode); var exitPretty = (value3, error) => (exit3) => exit3._tag === "Failure" ? `Exit.failCause(${causePretty(error)(exit3.cause)})` : `Exit.succeed(${value3(exit3.value)})`; -var exitParse = (decodeUnknownValue, decodeUnknownCause) => (u, options, ast) => isExit(u) ? match6(u, { - onFailure: (cause3) => toComposite(decodeUnknownCause(cause3, options), failCause2, ast, u), - onSuccess: (value3) => toComposite(decodeUnknownValue(value3, options), succeed2, ast, u) +var exitParse = (decodeUnknownValue, decodeUnknownCause) => (u, options, ast) => isExit(u) ? match9(u, { + onFailure: (cause3) => toComposite(decodeUnknownCause(cause3, options), failCause3, ast, u), + onSuccess: (value3) => toComposite(decodeUnknownValue(value3, options), succeed3, ast, u) }) : fail7(new Type2(ast, u)); var ExitFromSelf = ({ defect, @@ -24028,6 +24043,25 @@ async function stopLoopIfUnchanged(loopID, expectedUpdatedAt, reason, sessionLea return snapshot(loop3); }); } +async function rescheduleDynamicIfUnchanged(loopID, expectedUpdatedAt, delayMs, reason, sessionLease) { + const delay3 = positiveIntegerOrNull(Math.round(delayMs)); + if (delay3 == null) + throw new Error("delay must be a positive number of milliseconds"); + return mutate5((state) => { + const loop3 = state.loops[loopID]; + if (!loop3 || sessionLease && !matchesSessionLease(state, sessionLease)) + return null; + if (loop3.updatedAt !== expectedUpdatedAt || loop3.status !== "active" || loop3.mode !== "dynamic" || loop3.nextRunAt != null) { + return null; + } + loop3.scheduleRevision += 1; + loop3.nextRunAt = now2() + delay3; + loop3.nextRetryAt = null; + loop3.lastReason = reason.trim().slice(0, 400) || loop3.lastReason; + loop3.updatedAt = now2(); + return snapshot(loop3); + }); +} async function stopLoopsForSession(sessionID, reason) { return mutate5((state) => { const stopped = []; @@ -24256,6 +24290,7 @@ var DEFAULT_MAX_FAILURE_BACKOFF_SECONDS = 60 * 60; var DEFAULT_MAX_CONSECUTIVE_FAILURES = 5; var DEFAULT_MAX_LOOP_AGE_DAYS = 7; var DEFAULT_DYNAMIC_MAX_DELAY_SECONDS = 24 * 60 * 60; +var DEFAULT_DYNAMIC_RESTART_FALLBACK_SECONDS = 20 * 60; var RUN_CLAIM_LEASE_MS = 30000; var SESSION_LEASE_MS = 90000; var SESSION_LEASE_HEARTBEAT_MS = 30000; @@ -24277,6 +24312,15 @@ function restrictedAgentSet(options) { const names = Array.isArray(options?.restricted_agents) ? options.restricted_agents : DEFAULT_RESTRICTED_AGENTS; return new Set(names.map((name) => typeof name === "string" ? name.trim().toLowerCase() : "").filter(Boolean)); } +function dynamicRestartMode(options) { + return options?.dynamic_restart_mode?.trim().toLowerCase() === "stop" ? "stop" : "fallback"; +} +function dynamicRestartFallbackMs(options, minIntervalSeconds, dynamicMaxDelaySeconds) { + const fallbackSeconds = positiveNumberOr(options?.dynamic_restart_fallback_seconds, DEFAULT_DYNAMIC_RESTART_FALLBACK_SECONDS); + const minMs = (minIntervalSeconds ?? DEFAULT_MIN_INTERVAL_SECONDS) * 1000; + const maxMs = (dynamicMaxDelaySeconds ?? DEFAULT_DYNAMIC_MAX_DELAY_SECONDS) * 1000; + return Math.min(Math.max(Math.round(fallbackSeconds * 1000), minMs), Math.max(maxMs, minMs)); +} function registerDesktopCommand(config2, commandName, minIntervalSeconds) { config2.command ??= {}; if (config2.command[commandName]) @@ -24339,6 +24383,8 @@ var server = async ({ client, directory }, options) => { const maxLoopAgeMs = nonNegativeNumberOr(options?.max_loop_age_days, DEFAULT_MAX_LOOP_AGE_DAYS) * 24 * 60 * 60 * 1000; const dynamicMaxDelaySeconds = positiveNumberOr(options?.dynamic_max_delay_seconds, DEFAULT_DYNAMIC_MAX_DELAY_SECONDS); const restrictedAgents = restrictedAgentSet(options); + const restartMode = dynamicRestartMode(options); + const restartFallbackMs = dynamicRestartFallbackMs(options, minIntervalSeconds, dynamicMaxDelaySeconds); let disposed = false; const timers = new Map; const sendingLoops = new Set; @@ -24605,6 +24651,14 @@ var server = async ({ client, directory }, options) => { if (candidate.sessionID !== sessionID) continue; staleDynamicCandidates.delete(loopID); + if (restartMode === "fallback") { + const rescheduled = await rescheduleDynamicIfUnchanged(loopID, candidate.updatedAt, restartFallbackMs, "restarted with fallback delay; reschedule or stop after this iteration", lease).catch(() => null); + if (rescheduled) { + scheduleTimer(rescheduled); + await log3("info", "Dynamic loop resumed with fallback delay after restart", { loopID }); + continue; + } + } await stopLoopIfUnchanged(loopID, candidate.updatedAt, "not rescheduled before OpenCode restarted", lease); } } @@ -24869,6 +24923,8 @@ async function setupV2(context4) { const maxLoopAgeMs = nonNegativeNumberOr(options.max_loop_age_days, DEFAULT_MAX_LOOP_AGE_DAYS) * 24 * 60 * 60 * 1000; const dynamicMaxDelaySeconds = positiveNumberOr(options.dynamic_max_delay_seconds, DEFAULT_DYNAMIC_MAX_DELAY_SECONDS); const restrictedAgents = restrictedAgentSet(options); + const restartMode = dynamicRestartMode(options); + const restartFallbackMs = dynamicRestartFallbackMs(options, minIntervalSeconds, dynamicMaxDelaySeconds); let disposed = false; const timers = new Map; const sendingLoops = new Set; @@ -25170,6 +25226,17 @@ async function setupV2(context4) { if (candidate.sessionID !== sessionID) continue; staleDynamicCandidates.delete(loopID); + if (restartMode === "fallback") { + const rescheduled = await rescheduleDynamicIfUnchanged(loopID, candidate.updatedAt, restartFallbackMs, "restarted with fallback delay; reschedule or stop after this iteration", lease).catch(() => null); + if (rescheduled) { + scheduleTimer(rescheduled); + v2Log("info", "Dynamic loop resumed with fallback delay after restart", { + loopID, + sessionID + }); + continue; + } + } await stopLoopIfUnchanged(loopID, candidate.updatedAt, "not rescheduled before OpenCode restarted", lease); } } @@ -25300,6 +25367,16 @@ async function setupV2(context4) { return; sessionContext.system.push({ type: "text", text: reminder }); })); + registrations.push(await context4.session.hook("compaction", async (sessionCompaction) => { + await observeSession(sessionCompaction.sessionID); + const loops = await openLoops(sessionCompaction.sessionID); + const contextText = compactionContext(loops); + if (!contextText) + return; + if (sessionCompaction.system.some((part) => part.type === "text" && part.text.includes(LOOP_SYSTEM_MARKER))) + return; + sessionCompaction.system.push({ type: "text", text: contextText }); + })); await rehydrate().catch(() => v2Log("error", "Failed to rehydrate loops", { category: "state" })); const leaseHeartbeat = setInterval(() => { for (const sessionID of new Set([...observedSessions, ...keepAliveSessions])) { From 14ad844fa7edfa73952372aa8ed966238353fe58 Mon Sep 17 00:00:00 2001 From: BoYanZh Date: Thu, 15 Oct 2026 07:51:26 -0700 Subject: [PATCH 3/5] fix: root entry bridges for file-spec installs (subpath entries silently skipped) --- README.md | 5 +++++ package.json | 10 ++++------ server.js | 4 ++++ tui.js | 3 +++ 4 files changed, 16 insertions(+), 6 deletions(-) create mode 100644 server.js create mode 100644 tui.js diff --git a/README.md b/README.md index 6987bb7..21019e1 100644 --- a/README.md +++ b/README.md @@ -99,6 +99,11 @@ bun scripts/install.mjs --global bun scripts/install.mjs --project /path/to/project ``` +File-spec installs (local paths) require the entry files at the package root: +`./server.js` and `./tui.js` re-export `./dist/server.js` and `./src/tui.tsx`. +Subpath-only entries are silently skipped by some hosts, so keep the root +bridges even though the built bundle lives in `dist/`. + V2 supports the `/loop` command, all loop tools, persistent state, idle scheduling, dynamic loops, Plan-mode safety, session cleanup, TUI sidebar/palette integration, and the `compaction` hook for preserving loops across compaction. Stale dynamic loops resume with a configurable fallback delay after restart (`dynamic_restart_mode: "fallback"`, default 20m) instead of stopping. ## Usage diff --git a/package.json b/package.json index 9b3185e..6a1aa24 100644 --- a/package.json +++ b/package.json @@ -29,15 +29,13 @@ "author": "Prevalentware", "type": "module", "exports": { - "./server": { - "import": "./dist/server.js" - }, - "./tui": { - "import": "./src/tui.tsx" - } + "./server": "./server.js", + "./tui": "./tui.js" }, "files": [ "dist", + "server.js", + "tui.js", "src/tui.tsx", "LICENSE", "README.md" diff --git a/server.js b/server.js new file mode 100644 index 0000000..dfeb171 --- /dev/null +++ b/server.js @@ -0,0 +1,4 @@ +// Root server entrypoint bridge. File-spec installs resolve subpath entries +// unreliably (silently skipped on some hosts), so keep a root entry that +// re-exports the built bundle. +export { default } from "./dist/server.js"; diff --git a/tui.js b/tui.js new file mode 100644 index 0000000..58867aa --- /dev/null +++ b/tui.js @@ -0,0 +1,3 @@ +// Root TUI entrypoint bridge. See server.js for why the root entry exists. +export * from "./src/tui.tsx"; +export { default } from "./src/tui.tsx"; From c6f02e9c3630032d44a7a9762dd6a50c098cc725 Mon Sep 17 00:00:00 2001 From: Daniel Saldarriaga Date: Tue, 27 Oct 2026 22:02:32 +0100 Subject: [PATCH 4/5] fix: preserve installer config and fence dynamic restart recovery --- README.md | 4 +- dist/server.js | 32969 +++++++++++++++++++-------------------- package.json | 1 + scripts/install.mjs | 59 +- src/server.ts | 26 +- src/state.ts | 4 +- test/install.test.ts | 78 + test/server-v2.test.ts | 52 + test/server.test.ts | 20 + test/state.test.ts | 5 + 10 files changed, 16696 insertions(+), 16522 deletions(-) create mode 100644 test/install.test.ts diff --git a/README.md b/README.md index 21019e1..e62bfa5 100644 --- a/README.md +++ b/README.md @@ -99,6 +99,8 @@ bun scripts/install.mjs --global bun scripts/install.mjs --project /path/to/project ``` +Run these commands from a source checkout or the installed package directory. The installer preserves existing version pins and options, validates both files before writing, and refuses existing `.jsonc` configurations so they can be edited manually without losing comments. + File-spec installs (local paths) require the entry files at the package root: `./server.js` and `./tui.js` re-export `./dist/server.js` and `./src/tui.tsx`. Subpath-only entries are silently skipped by some hosts, so keep the root @@ -254,7 +256,7 @@ If `XDG_DATA_HOME` is not set, the default is: Set `OPENCODE_LOOP_STATE_PATH` to use a custom file. -The state file is written atomically with owner-only permissions when the host filesystem supports it. Persisted loops are rehydrated only after authoritative session context establishes a renewable session lease, preventing concurrent OpenCode instances from driving the same session. Dynamic loops that were waiting on the agent to schedule their next run cannot recover on their own after a restart and are stopped with an explanatory reason. +The state file is written atomically with owner-only permissions when the host filesystem supports it. Persisted loops are rehydrated only after authoritative session context establishes a renewable session lease, preventing concurrent OpenCode instances from driving the same session. Dynamic loops that were waiting on the agent to schedule their next run resume after the configured restart fallback delay once their session is observed. Set `dynamic_restart_mode: "stop"` to stop these loops with an explanatory reason instead. Session lease revisions identify ownership epochs; heartbeats keep the current epoch stable. Claims and automatic dynamic-loop cleanup are checked against that session epoch. Pausing, stopping, or explicitly rescheduling a loop invalidates any pending delivery claim. diff --git a/dist/server.js b/dist/server.js index a0fbb0e..c2612dd 100644 --- a/dist/server.js +++ b/dist/server.js @@ -1,16 +1,12 @@ // @bun var __defProp = Object.defineProperty; -var __returnValue = (v) => v; -function __exportSetter(name, newValue) { - this[name] = __returnValue.bind(null, newValue); -} var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true, configurable: true, - set: __exportSetter.bind(all, name) + set: (newValue) => all[name] = () => newValue }); }; @@ -23,23 +19,6 @@ import { randomUUID } from "crypto"; import { chmod, mkdir, link, readFile, rename as rename3, rm, writeFile } from "fs/promises"; import { homedir } from "os"; import { dirname, join as join3 } from "path"; -// node_modules/effect/dist/esm/Data.js -var exports_Data = {}; -__export(exports_Data, { - unsafeStruct: () => unsafeStruct, - unsafeArray: () => unsafeArray, - tuple: () => tuple, - taggedEnum: () => taggedEnum, - tagged: () => tagged, - struct: () => struct2, - case: () => _case, - array: () => array3, - TaggedError: () => TaggedError, - TaggedClass: () => TaggedClass, - Structural: () => Structural2, - Error: () => Error2, - Class: () => Class -}); // node_modules/effect/dist/esm/Function.js var isFunction = (input) => typeof input === "function"; @@ -1299,17126 +1278,16747 @@ var dedupeWith = /* @__PURE__ */ dual(2, (self, isEquivalent) => { var dedupe = (self) => dedupeWith(self, equivalence()); var join = /* @__PURE__ */ dual(2, (self, sep) => fromIterable(self).join(sep)); -// node_modules/effect/dist/esm/Chunk.js -var TypeId3 = /* @__PURE__ */ Symbol.for("effect/Chunk"); -function copy2(src, srcPos, dest, destPos, len) { - for (let i = srcPos;i < Math.min(src.length, srcPos + len); i++) { - dest[destPos + i - srcPos] = src[i]; +// node_modules/fast-check/lib/esm/stream/StreamHelpers.js +class Nil { + [Symbol.iterator]() { + return this; + } + next(value) { + return { value, done: true }; } - return dest; } -var emptyArray = []; -var getEquivalence4 = (isEquivalent) => make((self, that) => self.length === that.length && toReadonlyArray(self).every((value, i) => isEquivalent(value, unsafeGet2(that, i)))); -var _equivalence3 = /* @__PURE__ */ getEquivalence4(equals); -var ChunkProto = { - [TypeId3]: { - _A: (_) => _ - }, - toString() { - return format(this.toJSON()); - }, - toJSON() { - return { - _id: "Chunk", - values: toReadonlyArray(this).map(toJSON) - }; - }, - [NodeInspectSymbol]() { - return this.toJSON(); - }, - [symbol2](that) { - return isChunk(that) && _equivalence3(this, that); - }, - [symbol]() { - return cached(this, array2(toReadonlyArray(this))); - }, - [Symbol.iterator]() { - switch (this.backing._tag) { - case "IArray": { - return this.backing.array[Symbol.iterator](); - } - case "IEmpty": { - return emptyArray[Symbol.iterator](); - } - default: { - return toReadonlyArray(this)[Symbol.iterator](); - } - } - }, - pipe() { - return pipeArguments(this, arguments); +Nil.nil = new Nil; +function nilHelper() { + return Nil.nil; +} +function* mapHelper(g, f) { + for (const v of g) { + yield f(v); } -}; -var makeChunk = (backing) => { - const chunk = Object.create(ChunkProto); - chunk.backing = backing; - switch (backing._tag) { - case "IEmpty": { - chunk.length = 0; - chunk.depth = 0; - chunk.left = chunk; - chunk.right = chunk; - break; - } - case "IConcat": { - chunk.length = backing.left.length + backing.right.length; - chunk.depth = 1 + Math.max(backing.left.depth, backing.right.depth); - chunk.left = backing.left; - chunk.right = backing.right; - break; - } - case "IArray": { - chunk.length = backing.array.length; - chunk.depth = 0; - chunk.left = _empty; - chunk.right = _empty; - break; +} +function* flatMapHelper(g, f) { + for (const v of g) { + yield* f(v); + } +} +function* filterHelper(g, f) { + for (const v of g) { + if (f(v)) { + yield v; } - case "ISingleton": { - chunk.length = 1; - chunk.depth = 0; - chunk.left = _empty; - chunk.right = _empty; + } +} +function* takeNHelper(g, n) { + for (let i = 0;i < n; ++i) { + const cur = g.next(); + if (cur.done) { break; } - case "ISlice": { - chunk.length = backing.length; - chunk.depth = backing.chunk.depth + 1; - chunk.left = _empty; - chunk.right = _empty; - break; + yield cur.value; + } +} +function* takeWhileHelper(g, f) { + let cur = g.next(); + while (!cur.done && f(cur.value)) { + yield cur.value; + cur = g.next(); + } +} +function* joinHelper(g, others) { + for (let cur = g.next();!cur.done; cur = g.next()) { + yield cur.value; + } + for (const s of others) { + for (let cur = s.next();!cur.done; cur = s.next()) { + yield cur.value; } } - return chunk; -}; -var isChunk = (u) => hasProperty(u, TypeId3); -var _empty = /* @__PURE__ */ makeChunk({ - _tag: "IEmpty" -}); -var empty2 = () => _empty; -var make4 = (...as) => unsafeFromNonEmptyArray(as); -var of2 = (a) => makeChunk({ - _tag: "ISingleton", - a -}); -var fromIterable2 = (self) => isChunk(self) ? self : unsafeFromArray(fromIterable(self)); -var copyToArray = (self, array3, initial) => { - switch (self.backing._tag) { - case "IArray": { - copy2(self.backing.array, 0, array3, initial, self.length); - break; +} + +// node_modules/fast-check/lib/esm/stream/Stream.js +var safeSymbolIterator = Symbol.iterator; + +class Stream { + static nil() { + return new Stream(nilHelper()); + } + static of(...elements) { + return new Stream(elements[safeSymbolIterator]()); + } + constructor(g) { + this.g = g; + } + next() { + return this.g.next(); + } + [Symbol.iterator]() { + return this.g; + } + map(f) { + return new Stream(mapHelper(this.g, f)); + } + flatMap(f) { + return new Stream(flatMapHelper(this.g, f)); + } + dropWhile(f) { + let foundEligible = false; + function* helper(v) { + if (foundEligible || !f(v)) { + foundEligible = true; + yield v; + } } - case "IConcat": { - copyToArray(self.left, array3, initial); - copyToArray(self.right, array3, initial + self.left.length); - break; + return this.flatMap(helper); + } + drop(n) { + if (n <= 0) { + return this; } - case "ISingleton": { - array3[initial] = self.backing.a; - break; + let idx = 0; + function helper() { + return idx++ < n; } - case "ISlice": { - let i = 0; - let j = initial; - while (i < self.length) { - array3[j] = unsafeGet2(self, i); - i += 1; - j += 1; + return this.dropWhile(helper); + } + takeWhile(f) { + return new Stream(takeWhileHelper(this.g, f)); + } + take(n) { + return new Stream(takeNHelper(this.g, n)); + } + filter(f) { + return new Stream(filterHelper(this.g, f)); + } + every(f) { + for (const v of this.g) { + if (!f(v)) { + return false; } - break; } + return true; } -}; -var toReadonlyArray_ = (self) => { - switch (self.backing._tag) { - case "IEmpty": { - return emptyArray; - } - case "IArray": { - return self.backing.array; + has(f) { + for (const v of this.g) { + if (f(v)) { + return [true, v]; + } } - default: { - const arr = new Array(self.length); - copyToArray(self, arr, 0); - self.backing = { - _tag: "IArray", - array: arr - }; - self.left = _empty; - self.right = _empty; - self.depth = 0; - return arr; + return [false, null]; + } + join(...others) { + return new Stream(joinHelper(this.g, others)); + } + getNthOrLast(nth) { + let remaining = nth; + let last2 = null; + for (const v of this.g) { + if (remaining-- === 0) + return v; + last2 = v; } + return last2; } -}; -var toReadonlyArray = toReadonlyArray_; -var reverseChunk = (self) => { - switch (self.backing._tag) { - case "IEmpty": - case "ISingleton": - return self; - case "IArray": { - return makeChunk({ - _tag: "IArray", - array: reverse(self.backing.array) - }); - } - case "IConcat": { - return makeChunk({ - _tag: "IConcat", - left: reverse2(self.backing.right), - right: reverse2(self.backing.left) - }); +} +function stream(g) { + return new Stream(g); +} + +// node_modules/fast-check/lib/esm/check/symbols.js +var cloneMethod = Symbol.for("fast-check/cloneMethod"); +function hasCloneMethod(instance) { + return instance !== null && (typeof instance === "object" || typeof instance === "function") && cloneMethod in instance && typeof instance[cloneMethod] === "function"; +} +function cloneIfNeeded(instance) { + return hasCloneMethod(instance) ? instance[cloneMethod]() : instance; +} + +// node_modules/fast-check/lib/esm/check/arbitrary/definition/Value.js +var safeObjectDefineProperty = Object.defineProperty; + +class Value { + constructor(value_, context, customGetValue = undefined) { + this.value_ = value_; + this.context = context; + this.hasToBeCloned = customGetValue !== undefined || hasCloneMethod(value_); + this.readOnce = false; + if (this.hasToBeCloned) { + safeObjectDefineProperty(this, "value", { get: customGetValue !== undefined ? customGetValue : this.getValue }); + } else { + this.value = value_; } - case "ISlice": - return unsafeFromArray(reverse(toReadonlyArray(self))); } -}; -var reverse2 = reverseChunk; -var get2 = /* @__PURE__ */ dual(2, (self, index) => index < 0 || index >= self.length ? none2() : some2(unsafeGet2(self, index))); -var unsafeFromArray = (self) => self.length === 0 ? empty2() : self.length === 1 ? of2(self[0]) : makeChunk({ - _tag: "IArray", - array: self -}); -var unsafeFromNonEmptyArray = (self) => unsafeFromArray(self); -var unsafeGet2 = /* @__PURE__ */ dual(2, (self, index) => { - switch (self.backing._tag) { - case "IEmpty": { - throw new Error(`Index out of bounds`); - } - case "ISingleton": { - if (index !== 0) { - throw new Error(`Index out of bounds`); + getValue() { + if (this.hasToBeCloned) { + if (!this.readOnce) { + this.readOnce = true; + return this.value_; } - return self.backing.a; + return this.value_[cloneMethod](); } - case "IArray": { - if (index >= self.length || index < 0) { - throw new Error(`Index out of bounds`); + return this.value_; + } +} + +// node_modules/fast-check/lib/esm/check/arbitrary/definition/Arbitrary.js +var safeObjectAssign = Object.assign; + +class Arbitrary { + filter(refinement) { + return new FilterArbitrary(this, refinement); + } + map(mapper, unmapper) { + return new MapArbitrary(this, mapper, unmapper); + } + chain(chainer) { + return new ChainArbitrary(this, chainer); + } + noShrink() { + return new NoShrinkArbitrary(this); + } + noBias() { + return new NoBiasArbitrary(this); + } +} + +class ChainArbitrary extends Arbitrary { + constructor(arb, chainer) { + super(); + this.arb = arb; + this.chainer = chainer; + } + generate(mrng, biasFactor) { + const clonedMrng = mrng.clone(); + const src = this.arb.generate(mrng, biasFactor); + return this.valueChainer(src, mrng, clonedMrng, biasFactor); + } + canShrinkWithoutContext(value) { + return false; + } + shrink(value, context) { + if (this.isSafeContext(context)) { + return (!context.stoppedForOriginal ? this.arb.shrink(context.originalValue, context.originalContext).map((v) => this.valueChainer(v, context.clonedMrng.clone(), context.clonedMrng, context.originalBias)) : Stream.nil()).join(context.chainedArbitrary.shrink(value, context.chainedContext).map((dst) => { + const newContext = safeObjectAssign(safeObjectAssign({}, context), { + chainedContext: dst.context, + stoppedForOriginal: true + }); + return new Value(dst.value_, newContext); + })); + } + return Stream.nil(); + } + valueChainer(v, generateMrng, clonedMrng, biasFactor) { + const chainedArbitrary = this.chainer(v.value_); + const dst = chainedArbitrary.generate(generateMrng, biasFactor); + const context = { + originalBias: biasFactor, + originalValue: v.value_, + originalContext: v.context, + stoppedForOriginal: false, + chainedArbitrary, + chainedContext: dst.context, + clonedMrng + }; + return new Value(dst.value_, context); + } + isSafeContext(context) { + return context != null && typeof context === "object" && "originalBias" in context && "originalValue" in context && "originalContext" in context && "stoppedForOriginal" in context && "chainedArbitrary" in context && "chainedContext" in context && "clonedMrng" in context; + } +} + +class MapArbitrary extends Arbitrary { + constructor(arb, mapper, unmapper) { + super(); + this.arb = arb; + this.mapper = mapper; + this.unmapper = unmapper; + this.bindValueMapper = (v) => this.valueMapper(v); + } + generate(mrng, biasFactor) { + const g = this.arb.generate(mrng, biasFactor); + return this.valueMapper(g); + } + canShrinkWithoutContext(value) { + if (this.unmapper !== undefined) { + try { + const unmapped = this.unmapper(value); + return this.arb.canShrinkWithoutContext(unmapped); + } catch (_err) { + return false; } - return self.backing.array[index]; } - case "IConcat": { - return index < self.left.length ? unsafeGet2(self.left, index) : unsafeGet2(self.right, index - self.left.length); + return false; + } + shrink(value, context) { + if (this.isSafeContext(context)) { + return this.arb.shrink(context.originalValue, context.originalContext).map(this.bindValueMapper); } - case "ISlice": { - return unsafeGet2(self.backing.chunk, index + self.backing.offset); + if (this.unmapper !== undefined) { + const unmapped = this.unmapper(value); + return this.arb.shrink(unmapped, undefined).map(this.bindValueMapper); } + return Stream.nil(); } -}); -var append2 = /* @__PURE__ */ dual(2, (self, a) => appendAll2(self, of2(a))); -var prepend2 = /* @__PURE__ */ dual(2, (self, elem) => appendAll2(of2(elem), self)); -var drop2 = /* @__PURE__ */ dual(2, (self, n) => { - if (n <= 0) { - return self; - } else if (n >= self.length) { - return _empty; - } else { - switch (self.backing._tag) { - case "ISlice": { - return makeChunk({ - _tag: "ISlice", - chunk: self.backing.chunk, - offset: self.backing.offset + n, - length: self.backing.length - n - }); - } - case "IConcat": { - if (n > self.left.length) { - return drop2(self.right, n - self.left.length); - } - return makeChunk({ - _tag: "IConcat", - left: drop2(self.left, n), - right: self.right - }); - } - default: { - return makeChunk({ - _tag: "ISlice", - chunk: self, - offset: n, - length: self.length - n - }); - } + mapperWithCloneIfNeeded(v) { + const sourceValue = v.value; + const mappedValue = this.mapper(sourceValue); + if (v.hasToBeCloned && (typeof mappedValue === "object" && mappedValue !== null || typeof mappedValue === "function") && Object.isExtensible(mappedValue) && !hasCloneMethod(mappedValue)) { + Object.defineProperty(mappedValue, cloneMethod, { get: () => () => this.mapperWithCloneIfNeeded(v)[0] }); } + return [mappedValue, sourceValue]; } -}); -var appendAll2 = /* @__PURE__ */ dual(2, (self, that) => { - if (self.backing._tag === "IEmpty") { - return that; + valueMapper(v) { + const [mappedValue, sourceValue] = this.mapperWithCloneIfNeeded(v); + const context = { originalValue: sourceValue, originalContext: v.context }; + return new Value(mappedValue, context); } - if (that.backing._tag === "IEmpty") { - return self; + isSafeContext(context) { + return context != null && typeof context === "object" && "originalValue" in context && "originalContext" in context; } - const diff = that.depth - self.depth; - if (Math.abs(diff) <= 1) { - return makeChunk({ - _tag: "IConcat", - left: self, - right: that - }); - } else if (diff < -1) { - if (self.left.depth >= self.right.depth) { - const nr = appendAll2(self.right, that); - return makeChunk({ - _tag: "IConcat", - left: self.left, - right: nr - }); - } else { - const nrr = appendAll2(self.right.right, that); - if (nrr.depth === self.depth - 3) { - const nr = makeChunk({ - _tag: "IConcat", - left: self.right.left, - right: nrr - }); - return makeChunk({ - _tag: "IConcat", - left: self.left, - right: nr - }); - } else { - const nl = makeChunk({ - _tag: "IConcat", - left: self.left, - right: self.right.left - }); - return makeChunk({ - _tag: "IConcat", - left: nl, - right: nrr - }); - } - } - } else { - if (that.right.depth >= that.left.depth) { - const nl = appendAll2(self, that.left); - return makeChunk({ - _tag: "IConcat", - left: nl, - right: that.right - }); - } else { - const nll = appendAll2(self, that.left.left); - if (nll.depth === that.depth - 3) { - const nl = makeChunk({ - _tag: "IConcat", - left: nll, - right: that.left.right - }); - return makeChunk({ - _tag: "IConcat", - left: nl, - right: that.right - }); - } else { - const nr = makeChunk({ - _tag: "IConcat", - left: that.left.right, - right: that.right - }); - return makeChunk({ - _tag: "IConcat", - left: nll, - right: nr - }); +} + +class FilterArbitrary extends Arbitrary { + constructor(arb, refinement) { + super(); + this.arb = arb; + this.refinement = refinement; + this.bindRefinementOnValue = (v) => this.refinementOnValue(v); + } + generate(mrng, biasFactor) { + while (true) { + const g = this.arb.generate(mrng, biasFactor); + if (this.refinementOnValue(g)) { + return g; } } } -}); -var isEmpty = (self) => self.length === 0; -var isNonEmpty = (self) => self.length > 0; -var head2 = /* @__PURE__ */ get2(0); -var unsafeHead = (self) => unsafeGet2(self, 0); -var headNonEmpty2 = unsafeHead; -var tailNonEmpty2 = (self) => drop2(self, 1); + canShrinkWithoutContext(value) { + return this.arb.canShrinkWithoutContext(value) && this.refinement(value); + } + shrink(value, context) { + return this.arb.shrink(value, context).filter(this.bindRefinementOnValue); + } + refinementOnValue(v) { + return this.refinement(v.value); + } +} -// node_modules/effect/dist/esm/internal/context.js -var TagTypeId = /* @__PURE__ */ Symbol.for("effect/Context/Tag"); -var ReferenceTypeId = /* @__PURE__ */ Symbol.for("effect/Context/Reference"); -var STMSymbolKey = "effect/STM"; -var STMTypeId = /* @__PURE__ */ Symbol.for(STMSymbolKey); -var TagProto = { - ...EffectPrototype, - _op: "Tag", - [STMTypeId]: effectVariance, - [TagTypeId]: { - _Service: (_) => _, - _Identifier: (_) => _ - }, - toString() { - return format(this.toJSON()); - }, - toJSON() { - return { - _id: "Tag", - key: this.key, - stack: this.stack - }; - }, - [NodeInspectSymbol]() { - return this.toJSON(); - }, - of(self) { - return self; - }, - context(self) { - return make5(this, self); +class NoShrinkArbitrary extends Arbitrary { + constructor(arb) { + super(); + this.arb = arb; } -}; -var ReferenceProto = { - ...TagProto, - [ReferenceTypeId]: ReferenceTypeId -}; -var makeGenericTag = (key) => { - const limit = Error.stackTraceLimit; - Error.stackTraceLimit = 2; - const creationError = new Error; - Error.stackTraceLimit = limit; - const tag = Object.create(TagProto); - Object.defineProperty(tag, "stack", { - get() { - return creationError.stack; - } - }); - tag.key = key; - return tag; -}; -var Reference = () => (id, options) => { - const limit = Error.stackTraceLimit; - Error.stackTraceLimit = 2; - const creationError = new Error; - Error.stackTraceLimit = limit; - function ReferenceClass() {} - Object.setPrototypeOf(ReferenceClass, ReferenceProto); - ReferenceClass.key = id; - ReferenceClass.defaultValue = options.defaultValue; - Object.defineProperty(ReferenceClass, "stack", { - get() { - return creationError.stack; - } - }); - return ReferenceClass; -}; -var TypeId4 = /* @__PURE__ */ Symbol.for("effect/Context"); -var ContextProto = { - [TypeId4]: { - _Services: (_) => _ - }, - [symbol2](that) { - if (isContext(that)) { - if (this.unsafeMap.size === that.unsafeMap.size) { - for (const k of this.unsafeMap.keys()) { - if (!that.unsafeMap.has(k) || !equals(this.unsafeMap.get(k), that.unsafeMap.get(k))) { - return false; - } - } - return true; - } - } - return false; - }, - [symbol]() { - return cached(this, number2(this.unsafeMap.size)); - }, - pipe() { - return pipeArguments(this, arguments); - }, - toString() { - return format(this.toJSON()); - }, - toJSON() { - return { - _id: "Context", - services: Array.from(this.unsafeMap).map(toJSON) - }; - }, - [NodeInspectSymbol]() { - return this.toJSON(); + generate(mrng, biasFactor) { + return this.arb.generate(mrng, biasFactor); } -}; -var makeContext = (unsafeMap) => { - const context = Object.create(ContextProto); - context.unsafeMap = unsafeMap; - return context; -}; -var serviceNotFoundError = (tag) => { - const error = new Error(`Service not found${tag.key ? `: ${String(tag.key)}` : ""}`); - if (tag.stack) { - const lines = tag.stack.split(` -`); - if (lines.length > 2) { - const afterAt = lines[2].match(/at (.*)/); - if (afterAt) { - error.message = error.message + ` (defined at ${afterAt[1]})`; - } - } + canShrinkWithoutContext(value) { + return this.arb.canShrinkWithoutContext(value); } - if (error.stack) { - const lines = error.stack.split(` -`); - lines.splice(1, 3); - error.stack = lines.join(` -`); + shrink(_value, _context) { + return Stream.nil(); } - return error; -}; -var isContext = (u) => hasProperty(u, TypeId4); -var isTag = (u) => hasProperty(u, TagTypeId); -var isReference = (u) => hasProperty(u, ReferenceTypeId); -var _empty2 = /* @__PURE__ */ makeContext(/* @__PURE__ */ new Map); -var empty3 = () => _empty2; -var make5 = (tag, service) => makeContext(new Map([[tag.key, service]])); -var add = /* @__PURE__ */ dual(3, (self, tag, service) => { - const map4 = new Map(self.unsafeMap); - map4.set(tag.key, service); - return makeContext(map4); -}); -var defaultValueCache = /* @__PURE__ */ globalValue("effect/Context/defaultValueCache", () => new Map); -var getDefaultValue = (tag) => { - if (defaultValueCache.has(tag.key)) { - return defaultValueCache.get(tag.key); + noShrink() { + return this; } - const value = tag.defaultValue(); - defaultValueCache.set(tag.key, value); - return value; -}; -var unsafeGetReference = (self, tag) => { - return self.unsafeMap.has(tag.key) ? self.unsafeMap.get(tag.key) : getDefaultValue(tag); -}; -var unsafeGet3 = /* @__PURE__ */ dual(2, (self, tag) => { - if (!self.unsafeMap.has(tag.key)) { - if (ReferenceTypeId in tag) - return getDefaultValue(tag); - throw serviceNotFoundError(tag); +} + +class NoBiasArbitrary extends Arbitrary { + constructor(arb) { + super(); + this.arb = arb; } - return self.unsafeMap.get(tag.key); -}); -var get3 = unsafeGet3; -var getOption = /* @__PURE__ */ dual(2, (self, tag) => { - if (!self.unsafeMap.has(tag.key)) { - return isReference(tag) ? some(getDefaultValue(tag)) : none; + generate(mrng, _biasFactor) { + return this.arb.generate(mrng, undefined); } - return some(self.unsafeMap.get(tag.key)); -}); -var merge2 = /* @__PURE__ */ dual(2, (self, that) => { - const map4 = new Map(self.unsafeMap); - for (const [tag, s] of that.unsafeMap) { - map4.set(tag, s); + canShrinkWithoutContext(value) { + return this.arb.canShrinkWithoutContext(value); } - return makeContext(map4); -}); -var mergeAll = (...ctxs) => { - const map4 = new Map; - for (let i = 0;i < ctxs.length; i++) { - ctxs[i].unsafeMap.forEach((value, key) => { - map4.set(key, value); - }); + shrink(value, context) { + return this.arb.shrink(value, context); } - return makeContext(map4); -}; + noBias() { + return this; + } +} -// node_modules/effect/dist/esm/Context.js -var GenericTag = makeGenericTag; -var isContext2 = isContext; -var isTag2 = isTag; -var empty4 = empty3; -var make6 = make5; -var add2 = add; -var get4 = get3; -var unsafeGet4 = unsafeGet3; -var getOption2 = getOption; -var merge3 = merge2; -var mergeAll2 = mergeAll; -var Reference2 = Reference; +// node_modules/fast-check/lib/esm/utils/apply.js +var untouchedApply = Function.prototype.apply; +var ApplySymbol = Symbol("apply"); +function safeExtractApply(f) { + try { + return f.apply; + } catch (err) { + return; + } +} +function safeApplyHacky(f, instance, args) { + const ff = f; + ff[ApplySymbol] = untouchedApply; + const out = ff[ApplySymbol](instance, args); + delete ff[ApplySymbol]; + return out; +} +function safeApply(f, instance, args) { + if (safeExtractApply(f) === untouchedApply) { + return f.apply(instance, args); + } + return safeApplyHacky(f, instance, args); +} -// node_modules/effect/dist/esm/Duration.js -var TypeId5 = /* @__PURE__ */ Symbol.for("effect/Duration"); -var bigint0 = /* @__PURE__ */ BigInt(0); -var bigint24 = /* @__PURE__ */ BigInt(24); -var bigint60 = /* @__PURE__ */ BigInt(60); -var bigint1e3 = /* @__PURE__ */ BigInt(1000); -var bigint1e6 = /* @__PURE__ */ BigInt(1e6); -var bigint1e9 = /* @__PURE__ */ BigInt(1e9); -var DURATION_REGEX = /^(-?\d+(?:\.\d+)?)\s+(nanos?|micros?|millis?|seconds?|minutes?|hours?|days?|weeks?)$/; -var decode = (input) => { - if (isDuration(input)) { - return input; - } else if (isNumber(input)) { - return millis(input); - } else if (isBigInt(input)) { - return nanos(input); - } else if (Array.isArray(input) && input.length === 2 && input.every(isNumber)) { - if (input[0] === -Infinity || input[1] === -Infinity || Number.isNaN(input[0]) || Number.isNaN(input[1])) { - return zero; - } - if (input[0] === Infinity || input[1] === Infinity) { - return infinity; - } - return nanos(BigInt(Math.round(input[0] * 1e9)) + BigInt(Math.round(input[1]))); - } else if (isString(input)) { - const match4 = DURATION_REGEX.exec(input); - if (match4) { - const [_, valueStr, unit] = match4; - const value = Number(valueStr); - switch (unit) { - case "nano": - case "nanos": - return nanos(BigInt(valueStr)); - case "micro": - case "micros": - return micros(BigInt(valueStr)); - case "milli": - case "millis": - return millis(value); - case "second": - case "seconds": - return seconds(value); - case "minute": - case "minutes": - return minutes(value); - case "hour": - case "hours": - return hours(value); - case "day": - case "days": - return days(value); - case "week": - case "weeks": - return weeks(value); - } - } +// node_modules/fast-check/lib/esm/utils/globals.js +var untouchedForEach = Array.prototype.forEach; +var untouchedIndexOf = Array.prototype.indexOf; +var untouchedJoin = Array.prototype.join; +var untouchedMap = Array.prototype.map; +var untouchedFilter = Array.prototype.filter; +var untouchedPush = Array.prototype.push; +var untouchedPop = Array.prototype.pop; +var untouchedSplice = Array.prototype.splice; +var untouchedSlice = Array.prototype.slice; +var untouchedSort = Array.prototype.sort; +var untouchedEvery = Array.prototype.every; +function extractIndexOf(instance) { + try { + return instance.indexOf; + } catch (err) { + return; } - throw new Error("Invalid DurationInput"); -}; -var zeroValue = { - _tag: "Millis", - millis: 0 -}; -var infinityValue = { - _tag: "Infinity" -}; -var DurationProto = { - [TypeId5]: TypeId5, - [symbol]() { - return cached(this, structure(this.value)); - }, - [symbol2](that) { - return isDuration(that) && equals2(this, that); - }, - toString() { - return `Duration(${format2(this)})`; - }, - toJSON() { - switch (this.value._tag) { - case "Millis": - return { - _id: "Duration", - _tag: "Millis", - millis: this.value.millis - }; - case "Nanos": - return { - _id: "Duration", - _tag: "Nanos", - hrtime: toHrTime(this) - }; - case "Infinity": - return { - _id: "Duration", - _tag: "Infinity" - }; - } - }, - [NodeInspectSymbol]() { - return this.toJSON(); - }, - pipe() { - return pipeArguments(this, arguments); +} +function extractMap(instance) { + try { + return instance.map; + } catch (err) { + return; } -}; -var make7 = (input) => { - const duration = Object.create(DurationProto); - if (isNumber(input)) { - if (isNaN(input) || input <= 0) { - duration.value = zeroValue; - } else if (!Number.isFinite(input)) { - duration.value = infinityValue; - } else if (!Number.isInteger(input)) { - duration.value = { - _tag: "Nanos", - nanos: BigInt(Math.round(input * 1e6)) - }; - } else { - duration.value = { - _tag: "Millis", - millis: input - }; - } - } else if (input <= bigint0) { - duration.value = zeroValue; - } else { - duration.value = { - _tag: "Nanos", - nanos: input - }; +} +function extractPush(instance) { + try { + return instance.push; + } catch (err) { + return; } - return duration; -}; -var isDuration = (u) => hasProperty(u, TypeId5); -var isFinite = (self) => self.value._tag !== "Infinity"; -var isZero = (self) => { - switch (self.value._tag) { - case "Millis": { - return self.value.millis === 0; - } - case "Nanos": { - return self.value.nanos === bigint0; - } - case "Infinity": { - return false; - } +} +function extractSlice(instance) { + try { + return instance.slice; + } catch (err) { + return; } -}; -var zero = /* @__PURE__ */ make7(0); -var infinity = /* @__PURE__ */ make7(Infinity); -var nanos = (nanos2) => make7(nanos2); -var micros = (micros2) => make7(micros2 * bigint1e3); -var millis = (millis2) => make7(millis2); -var seconds = (seconds2) => make7(seconds2 * 1000); -var minutes = (minutes2) => make7(minutes2 * 60000); -var hours = (hours2) => make7(hours2 * 3600000); -var days = (days2) => make7(days2 * 86400000); -var weeks = (weeks2) => make7(weeks2 * 604800000); -var toMillis = (self) => match4(self, { - onMillis: (millis2) => millis2, - onNanos: (nanos2) => Number(nanos2) / 1e6 -}); -var toNanos = (self) => { - const _self = decode(self); - switch (_self.value._tag) { - case "Infinity": - return none2(); - case "Nanos": - return some2(_self.value.nanos); - case "Millis": - return some2(BigInt(Math.round(_self.value.millis * 1e6))); +} +function safeIndexOf(instance, ...args) { + if (extractIndexOf(instance) === untouchedIndexOf) { + return instance.indexOf(...args); } -}; -var unsafeToNanos = (self) => { - const _self = decode(self); - switch (_self.value._tag) { - case "Infinity": - throw new Error("Cannot convert infinite duration to nanos"); - case "Nanos": - return _self.value.nanos; - case "Millis": - return BigInt(Math.round(_self.value.millis * 1e6)); + return safeApply(untouchedIndexOf, instance, args); +} +function safeMap(instance, fn) { + if (extractMap(instance) === untouchedMap) { + return instance.map(fn); } -}; -var toHrTime = (self) => { - const _self = decode(self); - switch (_self.value._tag) { - case "Infinity": - return [Infinity, 0]; - case "Nanos": - return [Number(_self.value.nanos / bigint1e9), Number(_self.value.nanos % bigint1e9)]; - case "Millis": - return [Math.floor(_self.value.millis / 1000), Math.round(_self.value.millis % 1000 * 1e6)]; + return safeApply(untouchedMap, instance, [fn]); +} +function safePush(instance, ...args) { + if (extractPush(instance) === untouchedPush) { + return instance.push(...args); } -}; -var match4 = /* @__PURE__ */ dual(2, (self, options) => { - const _self = decode(self); - switch (_self.value._tag) { - case "Nanos": - return options.onNanos(_self.value.nanos); - case "Infinity": - return options.onMillis(Infinity); - case "Millis": - return options.onMillis(_self.value.millis); + return safeApply(untouchedPush, instance, args); +} +function safeSlice(instance, ...args) { + if (extractSlice(instance) === untouchedSlice) { + return instance.slice(...args); } -}); -var matchWith = /* @__PURE__ */ dual(3, (self, that, options) => { - const _self = decode(self); - const _that = decode(that); - if (_self.value._tag === "Infinity" || _that.value._tag === "Infinity") { - return options.onMillis(toMillis(_self), toMillis(_that)); - } else if (_self.value._tag === "Nanos" || _that.value._tag === "Nanos") { - const selfNanos = _self.value._tag === "Nanos" ? _self.value.nanos : BigInt(Math.round(_self.value.millis * 1e6)); - const thatNanos = _that.value._tag === "Nanos" ? _that.value.nanos : BigInt(Math.round(_that.value.millis * 1e6)); - return options.onNanos(selfNanos, thatNanos); + return safeApply(untouchedSlice, instance, args); +} +var untouchedGetTime = Date.prototype.getTime; +var untouchedToISOString = Date.prototype.toISOString; +var untouchedAdd = Set.prototype.add; +var untouchedHas = Set.prototype.has; +var untouchedSet = WeakMap.prototype.set; +var untouchedGet = WeakMap.prototype.get; +var untouchedMapSet = Map.prototype.set; +var untouchedMapGet = Map.prototype.get; +function extractMapSet(instance) { + try { + return instance.set; + } catch (err) { + return; } - return options.onMillis(_self.value.millis, _that.value.millis); -}); -var Order = /* @__PURE__ */ make2((self, that) => matchWith(self, that, { - onMillis: (self2, that2) => self2 < that2 ? -1 : self2 > that2 ? 1 : 0, - onNanos: (self2, that2) => self2 < that2 ? -1 : self2 > that2 ? 1 : 0 -})); -var between2 = /* @__PURE__ */ between(/* @__PURE__ */ mapInput2(Order, decode)); -var Equivalence = (self, that) => matchWith(self, that, { - onMillis: (self2, that2) => self2 === that2, - onNanos: (self2, that2) => self2 === that2 -}); -var _clamp = /* @__PURE__ */ clamp(Order); -var clamp3 = /* @__PURE__ */ dual(2, (self, options) => _clamp(decode(self), { - minimum: decode(options.minimum), - maximum: decode(options.maximum) -})); -var lessThan2 = /* @__PURE__ */ dual(2, (self, that) => matchWith(self, that, { - onMillis: (self2, that2) => self2 < that2, - onNanos: (self2, that2) => self2 < that2 -})); -var lessThanOrEqualTo2 = /* @__PURE__ */ dual(2, (self, that) => matchWith(self, that, { - onMillis: (self2, that2) => self2 <= that2, - onNanos: (self2, that2) => self2 <= that2 -})); -var greaterThan2 = /* @__PURE__ */ dual(2, (self, that) => matchWith(self, that, { - onMillis: (self2, that2) => self2 > that2, - onNanos: (self2, that2) => self2 > that2 -})); -var greaterThanOrEqualTo2 = /* @__PURE__ */ dual(2, (self, that) => matchWith(self, that, { - onMillis: (self2, that2) => self2 >= that2, - onNanos: (self2, that2) => self2 >= that2 -})); -var equals2 = /* @__PURE__ */ dual(2, (self, that) => Equivalence(decode(self), decode(that))); -var parts = (self) => { - const duration = decode(self); - if (duration.value._tag === "Infinity") { - return { - days: Infinity, - hours: Infinity, - minutes: Infinity, - seconds: Infinity, - millis: Infinity, - nanos: Infinity - }; - } - const nanos2 = unsafeToNanos(duration); - const ms = nanos2 / bigint1e6; - const sec = ms / bigint1e3; - const min2 = sec / bigint60; - const hr = min2 / bigint60; - const days2 = hr / bigint24; - return { - days: Number(days2), - hours: Number(hr % bigint24), - minutes: Number(min2 % bigint60), - seconds: Number(sec % bigint60), - millis: Number(ms % bigint1e3), - nanos: Number(nanos2 % bigint1e6) - }; -}; -var format2 = (self) => { - const duration = decode(self); - if (duration.value._tag === "Infinity") { - return "Infinity"; - } - if (isZero(duration)) { - return "0"; - } - const fragments = parts(duration); - const pieces = []; - if (fragments.days !== 0) { - pieces.push(`${fragments.days}d`); +} +function extractMapGet(instance) { + try { + return instance.get; + } catch (err) { + return; } - if (fragments.hours !== 0) { - pieces.push(`${fragments.hours}h`); +} +function safeMapSet(instance, key, value) { + if (extractMapSet(instance) === untouchedMapSet) { + return instance.set(key, value); } - if (fragments.minutes !== 0) { - pieces.push(`${fragments.minutes}m`); + return safeApply(untouchedMapSet, instance, [key, value]); +} +function safeMapGet(instance, key) { + if (extractMapGet(instance) === untouchedMapGet) { + return instance.get(key); } - if (fragments.seconds !== 0) { - pieces.push(`${fragments.seconds}s`); + return safeApply(untouchedMapGet, instance, [key]); +} +var untouchedSplit = String.prototype.split; +var untouchedStartsWith = String.prototype.startsWith; +var untouchedEndsWith = String.prototype.endsWith; +var untouchedSubstring = String.prototype.substring; +var untouchedToLowerCase = String.prototype.toLowerCase; +var untouchedToUpperCase = String.prototype.toUpperCase; +var untouchedPadStart = String.prototype.padStart; +var untouchedCharCodeAt = String.prototype.charCodeAt; +var untouchedNormalize = String.prototype.normalize; +var untouchedReplace = String.prototype.replace; +var untouchedNumberToString = Number.prototype.toString; + +// node_modules/fast-check/lib/esm/stream/LazyIterableIterator.js +class LazyIterableIterator { + constructor(producer) { + this.producer = producer; } - if (fragments.millis !== 0) { - pieces.push(`${fragments.millis}ms`); + [Symbol.iterator]() { + if (this.it === undefined) { + this.it = this.producer(); + } + return this.it; } - if (fragments.nanos !== 0) { - pieces.push(`${fragments.nanos}ns`); + next() { + if (this.it === undefined) { + this.it = this.producer(); + } + return this.it.next(); } - return pieces.join(" "); -}; - -// node_modules/effect/dist/esm/internal/hashMap/config.js -var SIZE = 5; -var BUCKET_SIZE = /* @__PURE__ */ Math.pow(2, SIZE); -var MASK = BUCKET_SIZE - 1; -var MAX_INDEX_NODE = BUCKET_SIZE / 2; -var MIN_ARRAY_NODE = BUCKET_SIZE / 4; - -// node_modules/effect/dist/esm/internal/hashMap/bitwise.js -function popcount(x) { - x -= x >> 1 & 1431655765; - x = (x & 858993459) + (x >> 2 & 858993459); - x = x + (x >> 4) & 252645135; - x += x >> 8; - x += x >> 16; - return x & 127; -} -function hashFragment(shift, h) { - return h >>> shift & MASK; -} -function toBitmap(x) { - return 1 << x; } -function fromBitmap(bitmap, bit) { - return popcount(bitmap & bit - 1); +function makeLazy(producer) { + return new LazyIterableIterator(producer); } -// node_modules/effect/dist/esm/internal/stack.js -var make8 = (value, previous) => ({ - value, - previous -}); +// node_modules/fast-check/lib/esm/check/runner/configuration/GlobalParameters.js +var globalParameters = {}; +function readConfigureGlobal() { + return globalParameters; +} -// node_modules/effect/dist/esm/internal/hashMap/array.js -function arrayUpdate(mutate, at, v, arr) { - let out = arr; - if (!mutate) { - const len = arr.length; - out = new Array(len); - for (let i = 0;i < len; ++i) - out[i] = arr[i]; - } - out[at] = v; - return out; +// node_modules/fast-check/lib/esm/arbitrary/_internals/helpers/BiasNumericRange.js +var safeMathFloor = Math.floor; +var safeMathLog = Math.log; +function integerLogLike(v) { + return safeMathFloor(safeMathLog(v) / safeMathLog(2)); } -function arraySpliceOut(mutate, at, arr) { - const newLen = arr.length - 1; - let i = 0; - let g = 0; - let out = arr; - if (mutate) { - i = g = at; - } else { - out = new Array(newLen); - while (i < at) - out[g++] = arr[i++]; - } - ++i; - while (i <= newLen) - out[g++] = arr[i++]; - if (mutate) { - out.length = newLen; +function biasNumericRange(min2, max2, logLike) { + if (min2 === max2) { + return [{ min: min2, max: max2 }]; } - return out; -} -function arraySpliceIn(mutate, at, v, arr) { - const len = arr.length; - if (mutate) { - let i2 = len; - while (i2 >= at) - arr[i2--] = arr[i2]; - arr[at] = v; - return arr; + if (min2 < 0 && max2 > 0) { + const logMin = logLike(-min2); + const logMax = logLike(max2); + return [ + { min: -logMin, max: logMax }, + { min: max2 - logMax, max: max2 }, + { min: min2, max: min2 + logMin } + ]; } - let i = 0, g = 0; - const out = new Array(len + 1); - while (i < at) - out[g++] = arr[i++]; - out[at] = v; - while (i < len) - out[++g] = arr[i++]; - return out; + const logGap = logLike(max2 - min2); + const arbCloseToMin = { min: min2, max: min2 + logGap }; + const arbCloseToMax = { min: max2 - logGap, max: max2 }; + return min2 < 0 ? [arbCloseToMax, arbCloseToMin] : [arbCloseToMin, arbCloseToMax]; } -// node_modules/effect/dist/esm/internal/hashMap/node.js -class EmptyNode { - _tag = "EmptyNode"; - modify(edit, _shift, f, hash2, key, size) { - const v = f(none2()); - if (isNone2(v)) - return new EmptyNode; - ++size.value; - return new LeafNode(edit, hash2, key, v); - } -} -function isEmptyNode(a) { - return isTagged(a, "EmptyNode"); +// node_modules/fast-check/lib/esm/arbitrary/_internals/helpers/ShrinkInteger.js +var safeMathCeil = Math.ceil; +var safeMathFloor2 = Math.floor; +function halvePosInteger(n) { + return safeMathFloor2(n / 2); } -function isLeafNode(node) { - return isEmptyNode(node) || node._tag === "LeafNode" || node._tag === "CollisionNode"; +function halveNegInteger(n) { + return safeMathCeil(n / 2); } -function canEditNode(node, edit) { - return isEmptyNode(node) ? false : edit === node.edit; +function shrinkInteger(current, target, tryTargetAsap) { + const realGap = current - target; + function* shrinkDecr() { + let previous = tryTargetAsap ? undefined : target; + const gap = tryTargetAsap ? realGap : halvePosInteger(realGap); + for (let toremove = gap;toremove > 0; toremove = halvePosInteger(toremove)) { + const next = toremove === realGap ? target : current - toremove; + yield new Value(next, previous); + previous = next; + } + } + function* shrinkIncr() { + let previous = tryTargetAsap ? undefined : target; + const gap = tryTargetAsap ? realGap : halveNegInteger(realGap); + for (let toremove = gap;toremove < 0; toremove = halveNegInteger(toremove)) { + const next = toremove === realGap ? target : current - toremove; + yield new Value(next, previous); + previous = next; + } + } + return realGap > 0 ? stream(shrinkDecr()) : stream(shrinkIncr()); } -class LeafNode { - edit; - hash; - key; - value; - _tag = "LeafNode"; - constructor(edit, hash2, key, value) { - this.edit = edit; - this.hash = hash2; - this.key = key; - this.value = value; +// node_modules/fast-check/lib/esm/arbitrary/_internals/IntegerArbitrary.js +var safeMathSign = Math.sign; +var safeNumberIsInteger = Number.isInteger; +var safeObjectIs = Object.is; + +class IntegerArbitrary extends Arbitrary { + constructor(min2, max2) { + super(); + this.min = min2; + this.max = max2; } - modify(edit, shift, f, hash2, key, size) { - if (equals(key, this.key)) { - const v2 = f(this.value); - if (v2 === this.value) - return this; - else if (isNone2(v2)) { - --size.value; - return new EmptyNode; - } - if (canEditNode(this, edit)) { - this.value = v2; - return this; - } - return new LeafNode(edit, hash2, key, v2); - } - const v = f(none2()); - if (isNone2(v)) - return this; - ++size.value; - return mergeLeaves(edit, shift, this.hash, this, hash2, new LeafNode(edit, hash2, key, v)); + generate(mrng, biasFactor) { + const range = this.computeGenerateRange(mrng, biasFactor); + return new Value(mrng.nextInt(range.min, range.max), undefined); } -} - -class CollisionNode { - edit; - hash; - children; - _tag = "CollisionNode"; - constructor(edit, hash2, children) { - this.edit = edit; - this.hash = hash2; - this.children = children; + canShrinkWithoutContext(value) { + return typeof value === "number" && safeNumberIsInteger(value) && !safeObjectIs(value, -0) && this.min <= value && value <= this.max; } - modify(edit, shift, f, hash2, key, size) { - if (hash2 === this.hash) { - const canEdit = canEditNode(this, edit); - const list = this.updateCollisionList(canEdit, edit, this.hash, this.children, f, key, size); - if (list === this.children) - return this; - return list.length > 1 ? new CollisionNode(edit, this.hash, list) : list[0]; + shrink(current, context) { + if (!IntegerArbitrary.isValidContext(current, context)) { + const target = this.defaultTarget(); + return shrinkInteger(current, target, true); } - const v = f(none2()); - if (isNone2(v)) - return this; - ++size.value; - return mergeLeaves(edit, shift, this.hash, this, hash2, new LeafNode(edit, hash2, key, v)); + if (this.isLastChanceTry(current, context)) { + return Stream.of(new Value(context, undefined)); + } + return shrinkInteger(current, context, false); } - updateCollisionList(mutate, edit, hash2, list, f, key, size) { - const len = list.length; - for (let i = 0;i < len; ++i) { - const child = list[i]; - if ("key" in child && equals(key, child.key)) { - const value = child.value; - const newValue2 = f(value); - if (newValue2 === value) - return list; - if (isNone2(newValue2)) { - --size.value; - return arraySpliceOut(mutate, i, list); - } - return arrayUpdate(mutate, i, new LeafNode(edit, hash2, key, newValue2), list); - } + defaultTarget() { + if (this.min <= 0 && this.max >= 0) { + return 0; } - const newValue = f(none2()); - if (isNone2(newValue)) - return list; - ++size.value; - return arrayUpdate(mutate, len, new LeafNode(edit, hash2, key, newValue), list); + return this.min < 0 ? this.max : this.min; } -} - -class IndexedNode { - edit; - mask; - children; - _tag = "IndexedNode"; - constructor(edit, mask, children) { - this.edit = edit; - this.mask = mask; - this.children = children; + computeGenerateRange(mrng, biasFactor) { + if (biasFactor === undefined || mrng.nextInt(1, biasFactor) !== 1) { + return { min: this.min, max: this.max }; + } + const ranges = biasNumericRange(this.min, this.max, integerLogLike); + if (ranges.length === 1) { + return ranges[0]; + } + const id = mrng.nextInt(-2 * (ranges.length - 1), ranges.length - 2); + return id < 0 ? ranges[0] : ranges[id + 1]; } - modify(edit, shift, f, hash2, key, size) { - const mask = this.mask; - const children = this.children; - const frag = hashFragment(shift, hash2); - const bit = toBitmap(frag); - const indx = fromBitmap(mask, bit); - const exists2 = mask & bit; - const canEdit = canEditNode(this, edit); - if (!exists2) { - const _newChild = new EmptyNode().modify(edit, shift + SIZE, f, hash2, key, size); - if (!_newChild) - return this; - return children.length >= MAX_INDEX_NODE ? expand(edit, frag, _newChild, mask, children) : new IndexedNode(edit, mask | bit, arraySpliceIn(canEdit, indx, _newChild, children)); + isLastChanceTry(current, context) { + if (current > 0) + return current === context + 1 && current > this.min; + if (current < 0) + return current === context - 1 && current < this.max; + return false; + } + static isValidContext(current, context) { + if (context === undefined) { + return false; } - const current = children[indx]; - const child = current.modify(edit, shift + SIZE, f, hash2, key, size); - if (current === child) - return this; - let bitmap = mask; - let newChildren; - if (isEmptyNode(child)) { - bitmap &= ~bit; - if (!bitmap) - return new EmptyNode; - if (children.length <= 2 && isLeafNode(children[indx ^ 1])) { - return children[indx ^ 1]; - } - newChildren = arraySpliceOut(canEdit, indx, children); - } else { - newChildren = arrayUpdate(canEdit, indx, child, children); + if (typeof context !== "number") { + throw new Error(`Invalid context type passed to IntegerArbitrary (#1)`); } - if (canEdit) { - this.mask = bitmap; - this.children = newChildren; - return this; + if (context !== 0 && safeMathSign(current) !== safeMathSign(context)) { + throw new Error(`Invalid context value passed to IntegerArbitrary (#2)`); } - return new IndexedNode(edit, bitmap, newChildren); + return true; } } -class ArrayNode { - edit; - size; - children; - _tag = "ArrayNode"; - constructor(edit, size, children) { - this.edit = edit; - this.size = size; - this.children = children; +// node_modules/fast-check/lib/esm/arbitrary/integer.js +var safeNumberIsInteger2 = Number.isInteger; +function buildCompleteIntegerConstraints(constraints) { + const min2 = constraints.min !== undefined ? constraints.min : -2147483648; + const max2 = constraints.max !== undefined ? constraints.max : 2147483647; + return { min: min2, max: max2 }; +} +function integer(constraints = {}) { + const fullConstraints = buildCompleteIntegerConstraints(constraints); + if (fullConstraints.min > fullConstraints.max) { + throw new Error("fc.integer maximum value should be equal or greater than the minimum one"); } - modify(edit, shift, f, hash2, key, size) { - let count = this.size; - const children = this.children; - const frag = hashFragment(shift, hash2); - const child = children[frag]; - const newChild = (child || new EmptyNode).modify(edit, shift + SIZE, f, hash2, key, size); - if (child === newChild) - return this; - const canEdit = canEditNode(this, edit); - let newChildren; - if (isEmptyNode(child) && !isEmptyNode(newChild)) { - ++count; - newChildren = arrayUpdate(canEdit, frag, newChild, children); - } else if (!isEmptyNode(child) && isEmptyNode(newChild)) { - --count; - if (count <= MIN_ARRAY_NODE) { - return pack(edit, count, frag, children); - } - newChildren = arrayUpdate(canEdit, frag, new EmptyNode, children); - } else { - newChildren = arrayUpdate(canEdit, frag, newChild, children); - } - if (canEdit) { - this.size = count; - this.children = newChildren; - return this; - } - return new ArrayNode(edit, count, newChildren); + if (!safeNumberIsInteger2(fullConstraints.min)) { + throw new Error("fc.integer minimum value should be an integer"); } -} -function pack(edit, count, removed, elements) { - const children = new Array(count - 1); - let g = 0; - let bitmap = 0; - for (let i = 0, len = elements.length;i < len; ++i) { - if (i !== removed) { - const elem = elements[i]; - if (elem && !isEmptyNode(elem)) { - children[g++] = elem; - bitmap |= 1 << i; - } - } + if (!safeNumberIsInteger2(fullConstraints.max)) { + throw new Error("fc.integer maximum value should be an integer"); } - return new IndexedNode(edit, bitmap, children); + return new IntegerArbitrary(fullConstraints.min, fullConstraints.max); } -function expand(edit, frag, child, bitmap, subNodes) { - const arr = []; - let bit = bitmap; - let count = 0; - for (let i = 0;bit; ++i) { - if (bit & 1) - arr[i] = subNodes[count++]; - bit >>>= 1; + +// node_modules/fast-check/lib/esm/arbitrary/_internals/helpers/DepthContext.js +var depthContextCache = new Map; +function getDepthContextFor(contextMeta) { + if (contextMeta === undefined) { + return { depth: 0 }; } - arr[frag] = child; - return new ArrayNode(edit, count + 1, arr); -} -function mergeLeavesInner(edit, shift, h1, n1, h2, n2) { - if (h1 === h2) - return new CollisionNode(edit, h1, [n2, n1]); - const subH1 = hashFragment(shift, h1); - const subH2 = hashFragment(shift, h2); - if (subH1 === subH2) { - return (child) => new IndexedNode(edit, toBitmap(subH1) | toBitmap(subH2), [child]); - } else { - const children = subH1 < subH2 ? [n1, n2] : [n2, n1]; - return new IndexedNode(edit, toBitmap(subH1) | toBitmap(subH2), children); + if (typeof contextMeta !== "string") { + return contextMeta; } -} -function mergeLeaves(edit, shift, h1, n1, h2, n2) { - let stack = undefined; - let currentShift = shift; - while (true) { - const res = mergeLeavesInner(edit, currentShift, h1, n1, h2, n2); - if (typeof res === "function") { - stack = make8(res, stack); - currentShift = currentShift + SIZE; - } else { - let final = res; - while (stack != null) { - final = stack.value(final); - stack = stack.previous; - } - return final; - } + const cachedContext = safeMapGet(depthContextCache, contextMeta); + if (cachedContext !== undefined) { + return cachedContext; } + const context = { depth: 0 }; + safeMapSet(depthContextCache, contextMeta, context); + return context; } -// node_modules/effect/dist/esm/internal/hashMap.js -var HashMapSymbolKey = "effect/HashMap"; -var HashMapTypeId = /* @__PURE__ */ Symbol.for(HashMapSymbolKey); -var HashMapProto = { - [HashMapTypeId]: HashMapTypeId, - [Symbol.iterator]() { - return new HashMapIterator(this, (k, v) => [k, v]); - }, - [symbol]() { - let hash2 = hash(HashMapSymbolKey); - for (const item of this) { - hash2 ^= pipe(hash(item[0]), combine(hash(item[1]))); - } - return cached(this, hash2); - }, - [symbol2](that) { - if (isHashMap(that)) { - if (that._size !== this._size) { - return false; - } - for (const item of this) { - const elem = pipe(that, getHash(item[0], hash(item[0]))); - if (isNone2(elem)) { - return false; - } else { - if (!equals(item[1], elem.value)) { - return false; - } +// node_modules/fast-check/lib/esm/arbitrary/_internals/implementations/NoopSlicedGenerator.js +class NoopSlicedGenerator { + constructor(arb, mrng, biasFactor) { + this.arb = arb; + this.mrng = mrng; + this.biasFactor = biasFactor; + } + attemptExact() { + return; + } + next() { + return this.arb.generate(this.mrng, this.biasFactor); + } +} + +// node_modules/fast-check/lib/esm/arbitrary/_internals/implementations/SlicedBasedGenerator.js +var safeMathMin = Math.min; +var safeMathMax = Math.max; + +class SlicedBasedGenerator { + constructor(arb, mrng, slices, biasFactor) { + this.arb = arb; + this.mrng = mrng; + this.slices = slices; + this.biasFactor = biasFactor; + this.activeSliceIndex = 0; + this.nextIndexInSlice = 0; + this.lastIndexInSlice = -1; + } + attemptExact(targetLength) { + if (targetLength !== 0 && this.mrng.nextInt(1, this.biasFactor) === 1) { + const eligibleIndices = []; + for (let index = 0;index !== this.slices.length; ++index) { + const slice = this.slices[index]; + if (slice.length === targetLength) { + safePush(eligibleIndices, index); } } - return true; + if (eligibleIndices.length === 0) { + return; + } + this.activeSliceIndex = eligibleIndices[this.mrng.nextInt(0, eligibleIndices.length - 1)]; + this.nextIndexInSlice = 0; + this.lastIndexInSlice = targetLength - 1; } - return false; - }, - toString() { - return format(this.toJSON()); - }, - toJSON() { - return { - _id: "HashMap", - values: Array.from(this).map(toJSON) - }; - }, - [NodeInspectSymbol]() { - return this.toJSON(); - }, - pipe() { - return pipeArguments(this, arguments); - } -}; -var makeImpl = (editable, edit, root, size) => { - const map4 = Object.create(HashMapProto); - map4._editable = editable; - map4._edit = edit; - map4._root = root; - map4._size = size; - return map4; -}; - -class HashMapIterator { - map; - f; - v; - constructor(map4, f) { - this.map = map4; - this.f = f; - this.v = visitLazy(this.map._root, this.f, undefined); } next() { - if (isNone2(this.v)) { - return { - done: true, - value: undefined - }; + if (this.nextIndexInSlice <= this.lastIndexInSlice) { + return new Value(this.slices[this.activeSliceIndex][this.nextIndexInSlice++], undefined); } - const v0 = this.v.value; - this.v = applyCont(v0.cont); - return { - done: false, - value: v0.value - }; + if (this.mrng.nextInt(1, this.biasFactor) !== 1) { + return this.arb.generate(this.mrng, this.biasFactor); + } + this.activeSliceIndex = this.mrng.nextInt(0, this.slices.length - 1); + const slice = this.slices[this.activeSliceIndex]; + if (this.mrng.nextInt(1, this.biasFactor) !== 1) { + this.nextIndexInSlice = 1; + this.lastIndexInSlice = slice.length - 1; + return new Value(slice[0], undefined); + } + const rangeBoundaryA = this.mrng.nextInt(0, slice.length - 1); + const rangeBoundaryB = this.mrng.nextInt(0, slice.length - 1); + this.nextIndexInSlice = safeMathMin(rangeBoundaryA, rangeBoundaryB); + this.lastIndexInSlice = safeMathMax(rangeBoundaryA, rangeBoundaryB); + return new Value(slice[this.nextIndexInSlice++], undefined); } - [Symbol.iterator]() { - return new HashMapIterator(this.map, this.f); +} + +// node_modules/fast-check/lib/esm/arbitrary/_internals/helpers/BuildSlicedGenerator.js +function buildSlicedGenerator(arb, mrng, slices, biasFactor) { + if (biasFactor === undefined || slices.length === 0 || mrng.nextInt(1, biasFactor) !== 1) { + return new NoopSlicedGenerator(arb, mrng, biasFactor); } + return new SlicedBasedGenerator(arb, mrng, slices, biasFactor); } -var applyCont = (cont) => cont ? visitLazyChildren(cont[0], cont[1], cont[2], cont[3], cont[4]) : none2(); -var visitLazy = (node, f, cont = undefined) => { - switch (node._tag) { - case "LeafNode": { - if (isSome2(node.value)) { - return some2({ - value: f(node.key, node.value.value), - cont - }); - } - return applyCont(cont); + +// node_modules/fast-check/lib/esm/arbitrary/_internals/ArrayArbitrary.js +var safeMathFloor3 = Math.floor; +var safeMathLog2 = Math.log; +var safeMathMax2 = Math.max; +var safeArrayIsArray = Array.isArray; +function biasedMaxLength(minLength, maxLength) { + if (minLength === maxLength) { + return minLength; + } + return minLength + safeMathFloor3(safeMathLog2(maxLength - minLength) / safeMathLog2(2)); +} + +class ArrayArbitrary extends Arbitrary { + constructor(arb, minLength, maxGeneratedLength, maxLength, depthIdentifier, setBuilder, customSlices) { + super(); + this.arb = arb; + this.minLength = minLength; + this.maxGeneratedLength = maxGeneratedLength; + this.maxLength = maxLength; + this.setBuilder = setBuilder; + this.customSlices = customSlices; + this.lengthArb = integer({ min: minLength, max: maxGeneratedLength }); + this.depthContext = getDepthContextFor(depthIdentifier); + } + preFilter(tab) { + if (this.setBuilder === undefined) { + return tab; } - case "CollisionNode": - case "ArrayNode": - case "IndexedNode": { - const children = node.children; - return visitLazyChildren(children.length, children, 0, f, cont); + const s = this.setBuilder(); + for (let index = 0;index !== tab.length; ++index) { + s.tryAdd(tab[index]); } - default: { - return applyCont(cont); + return s.getData(); + } + static makeItCloneable(vs, shrinkables) { + vs[cloneMethod] = () => { + const cloned = []; + for (let idx = 0;idx !== shrinkables.length; ++idx) { + safePush(cloned, shrinkables[idx].value); + } + this.makeItCloneable(cloned, shrinkables); + return cloned; + }; + return vs; + } + generateNItemsNoDuplicates(setBuilder, N, mrng, biasFactorItems) { + let numSkippedInRow = 0; + const s = setBuilder(); + const slicedGenerator = buildSlicedGenerator(this.arb, mrng, this.customSlices, biasFactorItems); + while (s.size() < N && numSkippedInRow < this.maxGeneratedLength) { + const current = slicedGenerator.next(); + if (s.tryAdd(current)) { + numSkippedInRow = 0; + } else { + numSkippedInRow += 1; + } } + return s.getData(); } -}; -var visitLazyChildren = (len, children, i, f, cont) => { - while (i < len) { - const child = children[i++]; - if (child && !isEmptyNode(child)) { - return visitLazy(child, f, [len, children, i, f, cont]); + safeGenerateNItemsNoDuplicates(setBuilder, N, mrng, biasFactorItems) { + const depthImpact = safeMathMax2(0, N - biasedMaxLength(this.minLength, this.maxGeneratedLength)); + this.depthContext.depth += depthImpact; + try { + return this.generateNItemsNoDuplicates(setBuilder, N, mrng, biasFactorItems); + } finally { + this.depthContext.depth -= depthImpact; } } - return applyCont(cont); -}; -var _empty3 = /* @__PURE__ */ makeImpl(false, 0, /* @__PURE__ */ new EmptyNode, 0); -var empty5 = () => _empty3; -var fromIterable3 = (entries) => { - const map4 = beginMutation(empty5()); - for (const entry of entries) { - set(map4, entry[0], entry[1]); + generateNItems(N, mrng, biasFactorItems) { + const items = []; + const slicedGenerator = buildSlicedGenerator(this.arb, mrng, this.customSlices, biasFactorItems); + slicedGenerator.attemptExact(N); + for (let index = 0;index !== N; ++index) { + const current = slicedGenerator.next(); + safePush(items, current); + } + return items; } - return endMutation(map4); -}; -var isHashMap = (u) => hasProperty(u, HashMapTypeId); -var isEmpty2 = (self) => self && isEmptyNode(self._root); -var get5 = /* @__PURE__ */ dual(2, (self, key) => getHash(self, key, hash(key))); -var getHash = /* @__PURE__ */ dual(3, (self, key, hash2) => { - let node = self._root; - let shift = 0; - while (true) { - switch (node._tag) { - case "LeafNode": { - return equals(key, node.key) ? node.value : none2(); - } - case "CollisionNode": { - if (hash2 === node.hash) { - const children = node.children; - for (let i = 0, len = children.length;i < len; ++i) { - const child = children[i]; - if ("key" in child && equals(key, child.key)) { - return child.value; - } - } - } - return none2(); - } - case "IndexedNode": { - const frag = hashFragment(shift, hash2); - const bit = toBitmap(frag); - if (node.mask & bit) { - node = node.children[fromBitmap(node.mask, bit)]; - shift += SIZE; - break; - } - return none2(); - } - case "ArrayNode": { - node = node.children[hashFragment(shift, hash2)]; - if (node) { - shift += SIZE; - break; - } - return none2(); - } - default: - return none2(); + safeGenerateNItems(N, mrng, biasFactorItems) { + const depthImpact = safeMathMax2(0, N - biasedMaxLength(this.minLength, this.maxGeneratedLength)); + this.depthContext.depth += depthImpact; + try { + return this.generateNItems(N, mrng, biasFactorItems); + } finally { + this.depthContext.depth -= depthImpact; } } -}); -var has = /* @__PURE__ */ dual(2, (self, key) => isSome2(getHash(self, key, hash(key)))); -var set = /* @__PURE__ */ dual(3, (self, key, value) => modifyAt(self, key, () => some2(value))); -var setTree = /* @__PURE__ */ dual(3, (self, newRoot, newSize) => { - if (self._editable) { - self._root = newRoot; - self._size = newSize; - return self; + wrapper(itemsRaw, shrunkOnce, itemsRawLengthContext, startIndex) { + const items = shrunkOnce ? this.preFilter(itemsRaw) : itemsRaw; + let cloneable = false; + const vs = []; + const itemsContexts = []; + for (let idx = 0;idx !== items.length; ++idx) { + const s = items[idx]; + cloneable = cloneable || s.hasToBeCloned; + safePush(vs, s.value); + safePush(itemsContexts, s.context); + } + if (cloneable) { + ArrayArbitrary.makeItCloneable(vs, items); + } + const context = { + shrunkOnce, + lengthContext: itemsRaw.length === items.length && itemsRawLengthContext !== undefined ? itemsRawLengthContext : undefined, + itemsContexts, + startIndex + }; + return new Value(vs, context); } - return newRoot === self._root ? self : makeImpl(self._editable, self._edit, newRoot, newSize); -}); -var keys = (self) => new HashMapIterator(self, (key) => key); -var size = (self) => self._size; -var beginMutation = (self) => makeImpl(true, self._edit + 1, self._root, self._size); -var endMutation = (self) => { - self._editable = false; - return self; -}; -var mutate = /* @__PURE__ */ dual(2, (self, f) => { - const transient = beginMutation(self); - f(transient); - return endMutation(transient); -}); -var modifyAt = /* @__PURE__ */ dual(3, (self, key, f) => modifyHash(self, key, hash(key), f)); -var modifyHash = /* @__PURE__ */ dual(4, (self, key, hash2, f) => { - const size2 = { - value: self._size - }; - const newRoot = self._root.modify(self._editable ? self._edit : NaN, 0, f, hash2, key, size2); - return pipe(self, setTree(newRoot, size2.value)); -}); -var remove2 = /* @__PURE__ */ dual(2, (self, key) => modifyAt(self, key, none2)); -var map4 = /* @__PURE__ */ dual(2, (self, f) => reduce2(self, empty5(), (map5, value, key) => set(map5, key, f(value, key)))); -var forEach = /* @__PURE__ */ dual(2, (self, f) => reduce2(self, undefined, (_, value, key) => f(value, key))); -var reduce2 = /* @__PURE__ */ dual(3, (self, zero2, f) => { - const root = self._root; - if (root._tag === "LeafNode") { - return isSome2(root.value) ? f(zero2, root.value.value, root.key) : zero2; + generate(mrng, biasFactor) { + const biasMeta = this.applyBias(mrng, biasFactor); + const targetSize = biasMeta.size; + const items = this.setBuilder !== undefined ? this.safeGenerateNItemsNoDuplicates(this.setBuilder, targetSize, mrng, biasMeta.biasFactorItems) : this.safeGenerateNItems(targetSize, mrng, biasMeta.biasFactorItems); + return this.wrapper(items, false, undefined, 0); } - if (root._tag === "EmptyNode") { - return zero2; + applyBias(mrng, biasFactor) { + if (biasFactor === undefined) { + return { size: this.lengthArb.generate(mrng, undefined).value }; + } + if (this.minLength === this.maxGeneratedLength) { + return { size: this.lengthArb.generate(mrng, undefined).value, biasFactorItems: biasFactor }; + } + if (mrng.nextInt(1, biasFactor) !== 1) { + return { size: this.lengthArb.generate(mrng, undefined).value }; + } + if (mrng.nextInt(1, biasFactor) !== 1 || this.minLength === this.maxGeneratedLength) { + return { size: this.lengthArb.generate(mrng, undefined).value, biasFactorItems: biasFactor }; + } + const maxBiasedLength = biasedMaxLength(this.minLength, this.maxGeneratedLength); + const targetSizeValue = integer({ min: this.minLength, max: maxBiasedLength }).generate(mrng, undefined); + return { size: targetSizeValue.value, biasFactorItems: biasFactor }; } - const toVisit = [root.children]; - let children; - while (children = toVisit.pop()) { - for (let i = 0, len = children.length;i < len; ) { - const child = children[i++]; - if (child && !isEmptyNode(child)) { - if (child._tag === "LeafNode") { - if (isSome2(child.value)) { - zero2 = f(zero2, child.value.value, child.key); - } - } else { - toVisit.push(child.children); - } + canShrinkWithoutContext(value) { + if (!safeArrayIsArray(value) || this.minLength > value.length || value.length > this.maxLength) { + return false; + } + for (let index = 0;index !== value.length; ++index) { + if (!(index in value)) { + return false; + } + if (!this.arb.canShrinkWithoutContext(value[index])) { + return false; } } + const filtered = this.preFilter(safeMap(value, (item) => new Value(item, undefined))); + return filtered.length === value.length; } - return zero2; -}); - -// node_modules/effect/dist/esm/internal/hashSet.js -var HashSetSymbolKey = "effect/HashSet"; -var HashSetTypeId = /* @__PURE__ */ Symbol.for(HashSetSymbolKey); -var HashSetProto = { - [HashSetTypeId]: HashSetTypeId, - [Symbol.iterator]() { - return keys(this._keyMap); - }, - [symbol]() { - return cached(this, combine(hash(this._keyMap))(hash(HashSetSymbolKey))); - }, - [symbol2](that) { - if (isHashSet(that)) { - return size(this._keyMap) === size(that._keyMap) && equals(this._keyMap, that._keyMap); + shrinkItemByItem(value, safeContext, endIndex) { + const shrinks = []; + for (let index = safeContext.startIndex;index < endIndex; ++index) { + safePush(shrinks, makeLazy(() => this.arb.shrink(value[index], safeContext.itemsContexts[index]).map((v) => { + const beforeCurrent = safeMap(safeSlice(value, 0, index), (v2, i) => new Value(cloneIfNeeded(v2), safeContext.itemsContexts[i])); + const afterCurrent = safeMap(safeSlice(value, index + 1), (v2, i) => new Value(cloneIfNeeded(v2), safeContext.itemsContexts[i + index + 1])); + return [ + [...beforeCurrent, v, ...afterCurrent], + undefined, + index + ]; + }))); } - return false; - }, - toString() { - return format(this.toJSON()); - }, - toJSON() { - return { - _id: "HashSet", - values: Array.from(this).map(toJSON) - }; - }, - [NodeInspectSymbol]() { - return this.toJSON(); - }, - pipe() { - return pipeArguments(this, arguments); + return Stream.nil().join(...shrinks); } -}; -var makeImpl2 = (keyMap) => { - const set2 = Object.create(HashSetProto); - set2._keyMap = keyMap; - return set2; -}; -var isHashSet = (u) => hasProperty(u, HashSetTypeId); -var _empty4 = /* @__PURE__ */ makeImpl2(/* @__PURE__ */ empty5()); -var empty6 = () => _empty4; -var fromIterable4 = (elements) => { - const set2 = beginMutation2(empty6()); - for (const value of elements) { - add3(set2, value); + shrinkImpl(value, context) { + if (value.length === 0) { + return Stream.nil(); + } + const safeContext = context !== undefined ? context : { shrunkOnce: false, lengthContext: undefined, itemsContexts: [], startIndex: 0 }; + return this.lengthArb.shrink(value.length, safeContext.lengthContext).drop(safeContext.shrunkOnce && safeContext.lengthContext === undefined && value.length > this.minLength + 1 ? 1 : 0).map((lengthValue) => { + const sliceStart = value.length - lengthValue.value; + return [ + safeMap(safeSlice(value, sliceStart), (v, index) => new Value(cloneIfNeeded(v), safeContext.itemsContexts[index + sliceStart])), + lengthValue.context, + 0 + ]; + }).join(makeLazy(() => value.length > this.minLength ? this.shrinkItemByItem(value, safeContext, 1) : this.shrinkItemByItem(value, safeContext, value.length))).join(value.length > this.minLength ? makeLazy(() => { + const subContext = { + shrunkOnce: false, + lengthContext: undefined, + itemsContexts: safeSlice(safeContext.itemsContexts, 1), + startIndex: 0 + }; + return this.shrinkImpl(safeSlice(value, 1), subContext).filter((v) => this.minLength <= v[0].length + 1).map((v) => { + return [[new Value(cloneIfNeeded(value[0]), safeContext.itemsContexts[0]), ...v[0]], undefined, 0]; + }); + }) : Stream.nil()); } - return endMutation2(set2); -}; -var make9 = (...elements) => { - const set2 = beginMutation2(empty6()); - for (const value of elements) { - add3(set2, value); + shrink(value, context) { + return this.shrinkImpl(value, context).map((contextualValue) => this.wrapper(contextualValue[0], true, contextualValue[1], contextualValue[2])); } - return endMutation2(set2); -}; -var has2 = /* @__PURE__ */ dual(2, (self, value) => has(self._keyMap, value)); -var size2 = (self) => size(self._keyMap); -var beginMutation2 = (self) => makeImpl2(beginMutation(self._keyMap)); -var endMutation2 = (self) => { - self._keyMap._editable = false; - return self; -}; -var mutate2 = /* @__PURE__ */ dual(2, (self, f) => { - const transient = beginMutation2(self); - f(transient); - return endMutation2(transient); -}); -var add3 = /* @__PURE__ */ dual(2, (self, value) => self._keyMap._editable ? (set(value, true)(self._keyMap), self) : makeImpl2(set(value, true)(self._keyMap))); -var remove3 = /* @__PURE__ */ dual(2, (self, value) => self._keyMap._editable ? (remove2(value)(self._keyMap), self) : makeImpl2(remove2(value)(self._keyMap))); -var difference2 = /* @__PURE__ */ dual(2, (self, that) => mutate2(self, (set2) => { - for (const value of that) { - remove3(set2, value); +} + +// node_modules/fast-check/lib/esm/arbitrary/_internals/helpers/MaxLengthFromMinLength.js +var safeMathFloor4 = Math.floor; +var safeMathMin2 = Math.min; +var MaxLengthUpperBound = 2147483647; +var orderedSize = ["xsmall", "small", "medium", "large", "xlarge"]; +var orderedRelativeSize = ["-4", "-3", "-2", "-1", "=", "+1", "+2", "+3", "+4"]; +var DefaultSize = "small"; +function maxLengthFromMinLength(minLength, size) { + switch (size) { + case "xsmall": + return safeMathFloor4(1.1 * minLength) + 1; + case "small": + return 2 * minLength + 10; + case "medium": + return 11 * minLength + 100; + case "large": + return 101 * minLength + 1000; + case "xlarge": + return 1001 * minLength + 1e4; + default: + throw new Error(`Unable to compute lengths based on received size: ${size}`); } -})); -var union2 = /* @__PURE__ */ dual(2, (self, that) => mutate2(empty6(), (set2) => { - forEach2(self, (value) => add3(set2, value)); - for (const value of that) { - add3(set2, value); +} +function relativeSizeToSize(size, defaultSize) { + const sizeInRelative = safeIndexOf(orderedRelativeSize, size); + if (sizeInRelative === -1) { + return size; } -})); -var forEach2 = /* @__PURE__ */ dual(2, (self, f) => forEach(self._keyMap, (_, k) => f(k))); -var reduce3 = /* @__PURE__ */ dual(3, (self, zero2, f) => reduce2(self._keyMap, zero2, (z, _, a) => f(z, a))); - -// node_modules/effect/dist/esm/HashSet.js -var isHashSet2 = isHashSet; -var empty7 = empty6; -var fromIterable5 = fromIterable4; -var make10 = make9; -var has3 = has2; -var size3 = size2; -var add4 = add3; -var remove4 = remove3; -var difference3 = difference2; -var union3 = union2; -var reduce4 = reduce3; + const defaultSizeInSize = safeIndexOf(orderedSize, defaultSize); + if (defaultSizeInSize === -1) { + throw new Error(`Unable to offset size based on the unknown defaulted one: ${defaultSize}`); + } + const resultingSizeInSize = defaultSizeInSize + sizeInRelative - 4; + return resultingSizeInSize < 0 ? orderedSize[0] : resultingSizeInSize >= orderedSize.length ? orderedSize[orderedSize.length - 1] : orderedSize[resultingSizeInSize]; +} +function maxGeneratedLengthFromSizeForArbitrary(size, minLength, maxLength, specifiedMaxLength) { + const { baseSize: defaultSize = DefaultSize, defaultSizeToMaxWhenMaxSpecified } = readConfigureGlobal() || {}; + const definedSize = size !== undefined ? size : specifiedMaxLength && defaultSizeToMaxWhenMaxSpecified ? "max" : defaultSize; + if (definedSize === "max") { + return maxLength; + } + const finalSize = relativeSizeToSize(definedSize, defaultSize); + return safeMathMin2(maxLengthFromMinLength(minLength, finalSize), maxLength); +} -// node_modules/effect/dist/esm/MutableRef.js -var TypeId6 = /* @__PURE__ */ Symbol.for("effect/MutableRef"); -var MutableRefProto = { - [TypeId6]: TypeId6, - toString() { - return format(this.toJSON()); - }, - toJSON() { - return { - _id: "MutableRef", - current: toJSON(this.current) - }; - }, - [NodeInspectSymbol]() { - return this.toJSON(); - }, - pipe() { - return pipeArguments(this, arguments); +// node_modules/fast-check/lib/esm/arbitrary/array.js +function array3(arb, constraints = {}) { + const size = constraints.size; + const minLength = constraints.minLength || 0; + const maxLengthOrUnset = constraints.maxLength; + const depthIdentifier = constraints.depthIdentifier; + const maxLength = maxLengthOrUnset !== undefined ? maxLengthOrUnset : MaxLengthUpperBound; + const specifiedMaxLength = maxLengthOrUnset !== undefined; + const maxGeneratedLength = maxGeneratedLengthFromSizeForArbitrary(size, minLength, maxLength, specifiedMaxLength); + const customSlices = constraints.experimentalCustomSlices || []; + return new ArrayArbitrary(arb, minLength, maxGeneratedLength, maxLength, depthIdentifier, undefined, customSlices); +} + +// node_modules/effect/dist/esm/internal/schema/util.js +var getKeysForIndexSignature = (input, parameter) => { + switch (parameter._tag) { + case "StringKeyword": + case "TemplateLiteral": + return Object.keys(input); + case "SymbolKeyword": + return Object.getOwnPropertySymbols(input); + case "Refinement": + return getKeysForIndexSignature(input, parameter.from); } }; -var make11 = (value) => { - const ref = Object.create(MutableRefProto); - ref.current = value; - return ref; +var memoizeThunk = (f) => { + let done = false; + let a; + return () => { + if (done) { + return a; + } + a = f(); + done = true; + return a; + }; }; -var compareAndSet = /* @__PURE__ */ dual(3, (self, oldValue, newValue) => { - if (equals(oldValue, self.current)) { - self.current = newValue; - return true; - } - return false; -}); -var get6 = (self) => self.current; -var set2 = /* @__PURE__ */ dual(2, (self, value) => { - self.current = value; - return self; -}); - -// node_modules/effect/dist/esm/internal/fiberId.js -var FiberIdSymbolKey = "effect/FiberId"; -var FiberIdTypeId = /* @__PURE__ */ Symbol.for(FiberIdSymbolKey); -var OP_NONE = "None"; -var OP_RUNTIME = "Runtime"; -var OP_COMPOSITE = "Composite"; -var emptyHash = /* @__PURE__ */ string(`${FiberIdSymbolKey}-${OP_NONE}`); +var isNonEmpty = (x) => Array.isArray(x); +var isSingle = (x) => !Array.isArray(x); +var formatPathKey = (key) => `[${formatPropertyKey(key)}]`; +var formatPath = (path) => isNonEmpty(path) ? path.map(formatPathKey).join("") : formatPathKey(path); -class None { - [FiberIdTypeId] = FiberIdTypeId; - _tag = OP_NONE; - id = -1; - startTimeMillis = -1; - [symbol]() { - return emptyHash; +// node_modules/effect/dist/esm/internal/schema/errors.js +var getErrorMessage = (reason, details, path, ast) => { + let out = reason; + if (path && isNonEmptyReadonlyArray(path)) { + out += ` +at path: ${formatPath(path)}`; } - [symbol2](that) { - return isFiberId(that) && that._tag === OP_NONE; + if (details !== undefined) { + out += ` +details: ${details}`; } - toString() { - return format(this.toJSON()); + if (ast) { + out += ` +schema (${ast._tag}): ${ast}`; } - toJSON() { - return { - _id: "FiberId", - _tag: this._tag - }; + return out; +}; +var getInvalidArgumentErrorMessage = (details) => getErrorMessage("Invalid Argument", details); +var getUnsupportedSchemaErrorMessage = (details, path, ast) => getErrorMessage("Unsupported schema", details, path, ast); +var getEquivalenceUnsupportedErrorMessage = (ast, path) => getUnsupportedSchemaErrorMessage("Cannot build an Equivalence", path, ast); +var getSchemaExtendErrorMessage = (x, y, path) => getErrorMessage("Unsupported schema or overlapping types", `cannot extend ${x} with ${y}`, path); +var getSchemaUnsupportedLiteralSpanErrorMessage = (ast) => getErrorMessage("Unsupported template literal span", undefined, undefined, ast); +var getASTUnsupportedSchemaErrorMessage = (ast) => getUnsupportedSchemaErrorMessage(undefined, undefined, ast); +var getASTUnsupportedKeySchemaErrorMessage = (ast) => getErrorMessage("Unsupported key schema", undefined, undefined, ast); +var getASTUnsupportedLiteralErrorMessage = (literal) => getErrorMessage("Unsupported literal", `literal value: ${formatUnknown(literal)}`); +var getASTDuplicateIndexSignatureErrorMessage = (type) => getErrorMessage("Duplicate index signature", `${type} index signature`); +var getASTIndexSignatureParameterErrorMessage = /* @__PURE__ */ getErrorMessage("Unsupported index signature parameter", "An index signature parameter type must be `string`, `symbol`, a template literal type or a refinement of the previous types"); +var getASTRequiredElementFollowinAnOptionalElementErrorMessage = /* @__PURE__ */ getErrorMessage("Invalid element", "A required element cannot follow an optional element. ts(1257)"); +var getASTDuplicatePropertySignatureTransformationErrorMessage = (key) => getErrorMessage("Duplicate property signature transformation", `Duplicate key ${formatUnknown(key)}`); +var getASTUnsupportedRenameSchemaErrorMessage = (ast) => getUnsupportedSchemaErrorMessage(undefined, undefined, ast); +var getASTDuplicatePropertySignatureErrorMessage = (key) => getErrorMessage("Duplicate property signature", `Duplicate key ${formatUnknown(key)}`); + +// node_modules/effect/dist/esm/internal/schema/schemaId.js +var DateFromSelfSchemaId = /* @__PURE__ */ Symbol.for("effect/SchemaId/DateFromSelf"); +var GreaterThanSchemaId = /* @__PURE__ */ Symbol.for("effect/SchemaId/GreaterThan"); +var GreaterThanOrEqualToSchemaId = /* @__PURE__ */ Symbol.for("effect/SchemaId/GreaterThanOrEqualTo"); +var LessThanSchemaId = /* @__PURE__ */ Symbol.for("effect/SchemaId/LessThan"); +var LessThanOrEqualToSchemaId = /* @__PURE__ */ Symbol.for("effect/SchemaId/LessThanOrEqualTo"); +var IntSchemaId = /* @__PURE__ */ Symbol.for("effect/SchemaId/Int"); +var NonNaNSchemaId = /* @__PURE__ */ Symbol.for("effect/SchemaId/NonNaN"); +var FiniteSchemaId = /* @__PURE__ */ Symbol.for("effect/SchemaId/Finite"); +var JsonNumberSchemaId = /* @__PURE__ */ Symbol.for("effect/SchemaId/JsonNumber"); +var BetweenSchemaId = /* @__PURE__ */ Symbol.for("effect/SchemaId/Between"); +var GreaterThanBigintSchemaId = /* @__PURE__ */ Symbol.for("effect/SchemaId/GreaterThanBigint"); +var GreaterThanOrEqualToBigIntSchemaId = /* @__PURE__ */ Symbol.for("effect/SchemaId/GreaterThanOrEqualToBigint"); +var LessThanBigIntSchemaId = /* @__PURE__ */ Symbol.for("effect/SchemaId/LessThanBigint"); +var LessThanOrEqualToBigIntSchemaId = /* @__PURE__ */ Symbol.for("effect/SchemaId/LessThanOrEqualToBigint"); +var BetweenBigintSchemaId = /* @__PURE__ */ Symbol.for("effect/SchemaId/BetweenBigint"); +var MinLengthSchemaId = /* @__PURE__ */ Symbol.for("effect/SchemaId/MinLength"); +var MaxLengthSchemaId = /* @__PURE__ */ Symbol.for("effect/SchemaId/MaxLength"); +var LengthSchemaId = /* @__PURE__ */ Symbol.for("effect/SchemaId/Length"); +var MinItemsSchemaId = /* @__PURE__ */ Symbol.for("effect/SchemaId/MinItems"); +var MaxItemsSchemaId = /* @__PURE__ */ Symbol.for("effect/SchemaId/MaxItems"); +var ItemsCountSchemaId = /* @__PURE__ */ Symbol.for("effect/SchemaId/ItemsCount"); + +// node_modules/effect/dist/esm/Number.js +var Order = number3; +var clamp3 = /* @__PURE__ */ clamp(Order); +var remainder = /* @__PURE__ */ dual(2, (dividend, divisor) => { + const selfDecCount = (dividend.toString().split(".")[1] || "").length; + const divisorDecCount = (divisor.toString().split(".")[1] || "").length; + const decCount = selfDecCount > divisorDecCount ? selfDecCount : divisorDecCount; + const selfInt = parseInt(dividend.toFixed(decCount).replace(".", "")); + const divisorInt = parseInt(divisor.toFixed(decCount).replace(".", "")); + return selfInt % divisorInt / Math.pow(10, decCount); +}); +var parse = (s) => { + if (s === "NaN") { + return some(NaN); } - [NodeInspectSymbol]() { - return this.toJSON(); + if (s === "Infinity") { + return some(Infinity); } -} - -class Runtime { - id; - startTimeMillis; - [FiberIdTypeId] = FiberIdTypeId; - _tag = OP_RUNTIME; - constructor(id, startTimeMillis) { - this.id = id; - this.startTimeMillis = startTimeMillis; + if (s === "-Infinity") { + return some(-Infinity); } - [symbol]() { - return cached(this, string(`${FiberIdSymbolKey}-${this._tag}-${this.id}-${this.startTimeMillis}`)); + if (s.trim() === "") { + return none; } - [symbol2](that) { - return isFiberId(that) && that._tag === OP_RUNTIME && this.id === that.id && this.startTimeMillis === that.startTimeMillis; + const n = Number(s); + return Number.isNaN(n) ? none : some(n); +}; + +// node_modules/effect/dist/esm/RegExp.js +var escape = (string2) => string2.replace(/[/\\^$*+?.()|[\]{}]/g, "\\$&"); + +// node_modules/effect/dist/esm/SchemaAST.js +var TypeConstructorAnnotationId = /* @__PURE__ */ Symbol.for("effect/annotation/TypeConstructor"); +var BrandAnnotationId = /* @__PURE__ */ Symbol.for("effect/annotation/Brand"); +var SchemaIdAnnotationId = /* @__PURE__ */ Symbol.for("effect/annotation/SchemaId"); +var MessageAnnotationId = /* @__PURE__ */ Symbol.for("effect/annotation/Message"); +var MissingMessageAnnotationId = /* @__PURE__ */ Symbol.for("effect/annotation/MissingMessage"); +var IdentifierAnnotationId = /* @__PURE__ */ Symbol.for("effect/annotation/Identifier"); +var TitleAnnotationId = /* @__PURE__ */ Symbol.for("effect/annotation/Title"); +var AutoTitleAnnotationId = /* @__PURE__ */ Symbol.for("effect/annotation/AutoTitle"); +var DescriptionAnnotationId = /* @__PURE__ */ Symbol.for("effect/annotation/Description"); +var ExamplesAnnotationId = /* @__PURE__ */ Symbol.for("effect/annotation/Examples"); +var DefaultAnnotationId = /* @__PURE__ */ Symbol.for("effect/annotation/Default"); +var JSONSchemaAnnotationId = /* @__PURE__ */ Symbol.for("effect/annotation/JSONSchema"); +var ArbitraryAnnotationId = /* @__PURE__ */ Symbol.for("effect/annotation/Arbitrary"); +var PrettyAnnotationId = /* @__PURE__ */ Symbol.for("effect/annotation/Pretty"); +var EquivalenceAnnotationId = /* @__PURE__ */ Symbol.for("effect/annotation/Equivalence"); +var DocumentationAnnotationId = /* @__PURE__ */ Symbol.for("effect/annotation/Documentation"); +var ConcurrencyAnnotationId = /* @__PURE__ */ Symbol.for("effect/annotation/Concurrency"); +var BatchingAnnotationId = /* @__PURE__ */ Symbol.for("effect/annotation/Batching"); +var ParseIssueTitleAnnotationId = /* @__PURE__ */ Symbol.for("effect/annotation/ParseIssueTitle"); +var ParseOptionsAnnotationId = /* @__PURE__ */ Symbol.for("effect/annotation/ParseOptions"); +var DecodingFallbackAnnotationId = /* @__PURE__ */ Symbol.for("effect/annotation/DecodingFallback"); +var SurrogateAnnotationId = /* @__PURE__ */ Symbol.for("effect/annotation/Surrogate"); +var StableFilterAnnotationId = /* @__PURE__ */ Symbol.for("effect/annotation/StableFilter"); +var getAnnotation = /* @__PURE__ */ dual(2, (annotated, key) => Object.prototype.hasOwnProperty.call(annotated.annotations, key) ? some2(annotated.annotations[key]) : none2()); +var getBrandAnnotation = /* @__PURE__ */ getAnnotation(BrandAnnotationId); +var getMessageAnnotation = /* @__PURE__ */ getAnnotation(MessageAnnotationId); +var getMissingMessageAnnotation = /* @__PURE__ */ getAnnotation(MissingMessageAnnotationId); +var getTitleAnnotation = /* @__PURE__ */ getAnnotation(TitleAnnotationId); +var getAutoTitleAnnotation = /* @__PURE__ */ getAnnotation(AutoTitleAnnotationId); +var getIdentifierAnnotation = /* @__PURE__ */ getAnnotation(IdentifierAnnotationId); +var getDescriptionAnnotation = /* @__PURE__ */ getAnnotation(DescriptionAnnotationId); +var getConcurrencyAnnotation = /* @__PURE__ */ getAnnotation(ConcurrencyAnnotationId); +var getBatchingAnnotation = /* @__PURE__ */ getAnnotation(BatchingAnnotationId); +var getParseIssueTitleAnnotation = /* @__PURE__ */ getAnnotation(ParseIssueTitleAnnotationId); +var getParseOptionsAnnotation = /* @__PURE__ */ getAnnotation(ParseOptionsAnnotationId); +var getDecodingFallbackAnnotation = /* @__PURE__ */ getAnnotation(DecodingFallbackAnnotationId); +var getSurrogateAnnotation = /* @__PURE__ */ getAnnotation(SurrogateAnnotationId); +var getStableFilterAnnotation = /* @__PURE__ */ getAnnotation(StableFilterAnnotationId); +var hasStableFilter = (annotated) => exists(getStableFilterAnnotation(annotated), (b) => b === true); +var JSONIdentifierAnnotationId = /* @__PURE__ */ Symbol.for("effect/annotation/JSONIdentifier"); +var getJSONIdentifierAnnotation = /* @__PURE__ */ getAnnotation(JSONIdentifierAnnotationId); +var getJSONIdentifier = (annotated) => orElse(getJSONIdentifierAnnotation(annotated), () => getIdentifierAnnotation(annotated)); +var ParseJsonSchemaId = /* @__PURE__ */ Symbol.for("effect/schema/ParseJson"); + +class Declaration { + typeParameters; + decodeUnknown; + encodeUnknown; + annotations; + _tag = "Declaration"; + constructor(typeParameters, decodeUnknown, encodeUnknown, annotations = {}) { + this.typeParameters = typeParameters; + this.decodeUnknown = decodeUnknown; + this.encodeUnknown = encodeUnknown; + this.annotations = annotations; } toString() { - return format(this.toJSON()); + return getOrElse(getExpected(this), () => ""); } toJSON() { return { - _id: "FiberId", _tag: this._tag, - id: this.id, - startTimeMillis: this.startTimeMillis + typeParameters: this.typeParameters.map((ast) => ast.toJSON()), + annotations: toJSONAnnotations(this.annotations) }; } - [NodeInspectSymbol]() { - return this.toJSON(); - } } - -class Composite { - left; - right; - [FiberIdTypeId] = FiberIdTypeId; - _tag = OP_COMPOSITE; - constructor(left3, right3) { - this.left = left3; - this.right = right3; +var createASTGuard = (tag) => (ast) => ast._tag === tag; +class Literal { + literal; + annotations; + _tag = "Literal"; + constructor(literal, annotations = {}) { + this.literal = literal; + this.annotations = annotations; } - _hash; - [symbol]() { - return pipe(string(`${FiberIdSymbolKey}-${this._tag}`), combine(hash(this.left)), combine(hash(this.right)), cached(this)); + toString() { + return getOrElse(getExpected(this), () => formatUnknown(this.literal)); } - [symbol2](that) { - return isFiberId(that) && that._tag === OP_COMPOSITE && equals(this.left, that.left) && equals(this.right, that.right); + toJSON() { + return { + _tag: this._tag, + literal: isBigInt(this.literal) ? String(this.literal) : this.literal, + annotations: toJSONAnnotations(this.annotations) + }; + } +} +var isLiteral = /* @__PURE__ */ createASTGuard("Literal"); +var $null = /* @__PURE__ */ new Literal(null); +class UniqueSymbol { + symbol; + annotations; + _tag = "UniqueSymbol"; + constructor(symbol3, annotations = {}) { + this.symbol = symbol3; + this.annotations = annotations; } toString() { - return format(this.toJSON()); + return getOrElse(getExpected(this), () => formatUnknown(this.symbol)); } toJSON() { return { - _id: "FiberId", _tag: this._tag, - left: toJSON(this.left), - right: toJSON(this.right) + symbol: String(this.symbol), + annotations: toJSONAnnotations(this.annotations) }; } - [NodeInspectSymbol]() { - return this.toJSON(); +} +var isUniqueSymbol = /* @__PURE__ */ createASTGuard("UniqueSymbol"); + +class UndefinedKeyword { + annotations; + _tag = "UndefinedKeyword"; + constructor(annotations = {}) { + this.annotations = annotations; + } + toString() { + return formatKeyword(this); + } + toJSON() { + return { + _tag: this._tag, + annotations: toJSONAnnotations(this.annotations) + }; } } -var none3 = /* @__PURE__ */ new None; -var runtime = (id, startTimeMillis) => { - return new Runtime(id, startTimeMillis); -}; -var composite = (left3, right3) => { - return new Composite(left3, right3); -}; -var isFiberId = (self) => hasProperty(self, FiberIdTypeId); -var combine2 = /* @__PURE__ */ dual(2, (self, that) => { - if (self._tag === OP_NONE) { - return that; +var undefinedKeyword = /* @__PURE__ */ new UndefinedKeyword({ + [TitleAnnotationId]: "undefined" +}); +class VoidKeyword { + annotations; + _tag = "VoidKeyword"; + constructor(annotations = {}) { + this.annotations = annotations; } - if (that._tag === OP_NONE) { - return self; + toString() { + return formatKeyword(this); } - return new Composite(self, that); + toJSON() { + return { + _tag: this._tag, + annotations: toJSONAnnotations(this.annotations) + }; + } +} +var voidKeyword = /* @__PURE__ */ new VoidKeyword({ + [TitleAnnotationId]: "void" }); -var ids = (self) => { - switch (self._tag) { - case OP_NONE: { - return empty7(); - } - case OP_RUNTIME: { - return make10(self.id); - } - case OP_COMPOSITE: { - return pipe(ids(self.left), union3(ids(self.right))); - } +class NeverKeyword { + annotations; + _tag = "NeverKeyword"; + constructor(annotations = {}) { + this.annotations = annotations; } -}; -var _fiberCounter = /* @__PURE__ */ globalValue(/* @__PURE__ */ Symbol.for("effect/Fiber/Id/_fiberCounter"), () => make11(0)); -var threadName = (self) => { - const identifiers = Array.from(ids(self)).map((n) => `#${n}`).join(","); - return identifiers; -}; -var unsafeMake = () => { - const id = get6(_fiberCounter); - pipe(_fiberCounter, set2(id + 1)); - return new Runtime(id, Date.now()); -}; - -// node_modules/effect/dist/esm/FiberId.js -var none4 = none3; -var runtime2 = runtime; -var composite2 = composite; -var isFiberId2 = isFiberId; -var combine3 = combine2; -var threadName2 = threadName; -var unsafeMake2 = unsafeMake; - -// node_modules/effect/dist/esm/HashMap.js -var isHashMap2 = isHashMap; -var empty8 = empty5; -var fromIterable6 = fromIterable3; -var isEmpty3 = isEmpty2; -var get7 = get5; -var set3 = set; -var keys2 = keys; -var mutate3 = mutate; -var modifyAt2 = modifyAt; -var map6 = map4; -var forEach3 = forEach; -var reduce5 = reduce2; - -// node_modules/effect/dist/esm/List.js -var TypeId7 = /* @__PURE__ */ Symbol.for("effect/List"); -var toArray2 = (self) => fromIterable(self); -var getEquivalence5 = (isEquivalent) => mapInput(getEquivalence3(isEquivalent), toArray2); -var _equivalence4 = /* @__PURE__ */ getEquivalence5(equals); -var ConsProto = { - [TypeId7]: TypeId7, - _tag: "Cons", toString() { - return format(this.toJSON()); - }, + return formatKeyword(this); + } toJSON() { return { - _id: "List", - _tag: "Cons", - values: toArray2(this).map(toJSON) + _tag: this._tag, + annotations: toJSONAnnotations(this.annotations) }; - }, - [NodeInspectSymbol]() { - return this.toJSON(); - }, - [symbol2](that) { - return isList(that) && this._tag === that._tag && _equivalence4(this, that); - }, - [symbol]() { - return cached(this, array2(toArray2(this))); - }, - [Symbol.iterator]() { - let done = false; - let self = this; + } +} +var neverKeyword = /* @__PURE__ */ new NeverKeyword({ + [TitleAnnotationId]: "never" +}); +var isNeverKeyword = /* @__PURE__ */ createASTGuard("NeverKeyword"); + +class UnknownKeyword { + annotations; + _tag = "UnknownKeyword"; + constructor(annotations = {}) { + this.annotations = annotations; + } + toString() { + return formatKeyword(this); + } + toJSON() { return { - next() { - if (done) { - return this.return(); - } - if (self._tag === "Nil") { - done = true; - return this.return(); - } - const value = self.head; - self = self.tail; - return { - done, - value - }; - }, - return(value) { - if (!done) { - done = true; - } - return { - done: true, - value - }; - } + _tag: this._tag, + annotations: toJSONAnnotations(this.annotations) }; - }, - pipe() { - return pipeArguments(this, arguments); } -}; -var makeCons = (head3, tail) => { - const cons = Object.create(ConsProto); - cons.head = head3; - cons.tail = tail; - return cons; -}; -var NilHash = /* @__PURE__ */ string("Nil"); -var NilProto = { - [TypeId7]: TypeId7, - _tag: "Nil", +} +var unknownKeyword = /* @__PURE__ */ new UnknownKeyword({ + [TitleAnnotationId]: "unknown" +}); +class AnyKeyword { + annotations; + _tag = "AnyKeyword"; + constructor(annotations = {}) { + this.annotations = annotations; + } toString() { - return format(this.toJSON()); - }, + return formatKeyword(this); + } toJSON() { return { - _id: "List", - _tag: "Nil" + _tag: this._tag, + annotations: toJSONAnnotations(this.annotations) }; - }, - [NodeInspectSymbol]() { - return this.toJSON(); - }, - [symbol]() { - return NilHash; - }, - [symbol2](that) { - return isList(that) && this._tag === that._tag; - }, - [Symbol.iterator]() { + } +} +var anyKeyword = /* @__PURE__ */ new AnyKeyword({ + [TitleAnnotationId]: "any" +}); +class StringKeyword { + annotations; + _tag = "StringKeyword"; + constructor(annotations = {}) { + this.annotations = annotations; + } + toString() { + return formatKeyword(this); + } + toJSON() { return { - next() { - return { - done: true, - value: undefined - }; - } + _tag: this._tag, + annotations: toJSONAnnotations(this.annotations) }; - }, - pipe() { - return pipeArguments(this, arguments); } -}; -var _Nil = /* @__PURE__ */ Object.create(NilProto); -var isList = (u) => hasProperty(u, TypeId7); -var isNil = (self) => self._tag === "Nil"; -var isCons = (self) => self._tag === "Cons"; -var nil = () => _Nil; -var cons = (head3, tail) => makeCons(head3, tail); -var empty9 = nil; -var of3 = (value) => makeCons(value, _Nil); -var fromIterable7 = (prefix) => { - const iterator = prefix[Symbol.iterator](); - let next; - if ((next = iterator.next()) && !next.done) { - const result = makeCons(next.value, _Nil); - let curr = result; - while ((next = iterator.next()) && !next.done) { - const temp = makeCons(next.value, _Nil); - curr.tail = temp; - curr = temp; - } - return result; - } else { - return _Nil; +} +var stringKeyword = /* @__PURE__ */ new StringKeyword({ + [TitleAnnotationId]: "string", + [DescriptionAnnotationId]: "a string" +}); +var isStringKeyword = /* @__PURE__ */ createASTGuard("StringKeyword"); + +class NumberKeyword { + annotations; + _tag = "NumberKeyword"; + constructor(annotations = {}) { + this.annotations = annotations; } -}; -var appendAll3 = /* @__PURE__ */ dual(2, (self, that) => prependAll(that, self)); -var prepend3 = /* @__PURE__ */ dual(2, (self, element) => cons(element, self)); -var prependAll = /* @__PURE__ */ dual(2, (self, prefix) => { - if (isNil(self)) { - return prefix; - } else if (isNil(prefix)) { - return self; - } else { - const result = makeCons(prefix.head, self); - let curr = result; - let that = prefix.tail; - while (!isNil(that)) { - const temp = makeCons(that.head, self); - curr.tail = temp; - curr = temp; - that = that.tail; - } - return result; + toString() { + return formatKeyword(this); } -}); -var reduce6 = /* @__PURE__ */ dual(3, (self, zero2, f) => { - let acc = zero2; - let these = self; - while (!isNil(these)) { - acc = f(acc, these.head); - these = these.tail; + toJSON() { + return { + _tag: this._tag, + annotations: toJSONAnnotations(this.annotations) + }; } - return acc; +} +var numberKeyword = /* @__PURE__ */ new NumberKeyword({ + [TitleAnnotationId]: "number", + [DescriptionAnnotationId]: "a number" }); -var reverse3 = (self) => { - let result = empty9(); - let these = self; - while (!isNil(these)) { - result = prepend3(result, these.head); - these = these.tail; +var isNumberKeyword = /* @__PURE__ */ createASTGuard("NumberKeyword"); + +class BooleanKeyword { + annotations; + _tag = "BooleanKeyword"; + constructor(annotations = {}) { + this.annotations = annotations; } - return result; -}; + toString() { + return formatKeyword(this); + } + toJSON() { + return { + _tag: this._tag, + annotations: toJSONAnnotations(this.annotations) + }; + } +} +var booleanKeyword = /* @__PURE__ */ new BooleanKeyword({ + [TitleAnnotationId]: "boolean", + [DescriptionAnnotationId]: "a boolean" +}); +var isBooleanKeyword = /* @__PURE__ */ createASTGuard("BooleanKeyword"); -// node_modules/effect/dist/esm/internal/data.js -var ArrayProto = /* @__PURE__ */ Object.assign(/* @__PURE__ */ Object.create(Array.prototype), { - [symbol]() { - return cached(this, array2(this)); - }, - [symbol2](that) { - if (Array.isArray(that) && this.length === that.length) { - return this.every((v, i) => equals(v, that[i])); - } else { - return false; - } +class BigIntKeyword { + annotations; + _tag = "BigIntKeyword"; + constructor(annotations = {}) { + this.annotations = annotations; + } + toString() { + return formatKeyword(this); + } + toJSON() { + return { + _tag: this._tag, + annotations: toJSONAnnotations(this.annotations) + }; } +} +var bigIntKeyword = /* @__PURE__ */ new BigIntKeyword({ + [TitleAnnotationId]: "bigint", + [DescriptionAnnotationId]: "a bigint" }); -var Structural = /* @__PURE__ */ function() { - function Structural2(args) { - if (args) { - Object.assign(this, args); - } +class SymbolKeyword { + annotations; + _tag = "SymbolKeyword"; + constructor(annotations = {}) { + this.annotations = annotations; } - Structural2.prototype = StructuralPrototype; - return Structural2; -}(); -var struct = (as) => Object.assign(Object.create(StructuralPrototype), as); + toString() { + return formatKeyword(this); + } + toJSON() { + return { + _tag: this._tag, + annotations: toJSONAnnotations(this.annotations) + }; + } +} +var symbolKeyword = /* @__PURE__ */ new SymbolKeyword({ + [TitleAnnotationId]: "symbol", + [DescriptionAnnotationId]: "a symbol" +}); +var isSymbolKeyword = /* @__PURE__ */ createASTGuard("SymbolKeyword"); -// node_modules/effect/dist/esm/internal/differ/contextPatch.js -var ContextPatchTypeId = /* @__PURE__ */ Symbol.for("effect/DifferContextPatch"); -function variance(a) { - return a; +class ObjectKeyword { + annotations; + _tag = "ObjectKeyword"; + constructor(annotations = {}) { + this.annotations = annotations; + } + toString() { + return formatKeyword(this); + } + toJSON() { + return { + _tag: this._tag, + annotations: toJSONAnnotations(this.annotations) + }; + } } -var PatchProto = { - ...Structural.prototype, - [ContextPatchTypeId]: { - _Value: variance, - _Patch: variance +var objectKeyword = /* @__PURE__ */ new ObjectKeyword({ + [TitleAnnotationId]: "object", + [DescriptionAnnotationId]: "an object in the TypeScript meaning, i.e. the `object` type" +}); +class Enums { + enums; + annotations; + _tag = "Enums"; + constructor(enums, annotations = {}) { + this.enums = enums; + this.annotations = annotations; + } + toString() { + return getOrElse(getExpected(this), () => ` JSON.stringify(value)).join(" | ")}>`); + } + toJSON() { + return { + _tag: this._tag, + enums: this.enums, + annotations: toJSONAnnotations(this.annotations) + }; + } +} +var isEnums = /* @__PURE__ */ createASTGuard("Enums"); +var isTemplateLiteralSpanType = (ast) => { + switch (ast._tag) { + case "Literal": + case "NumberKeyword": + case "StringKeyword": + case "TemplateLiteral": + return true; + case "Union": + return ast.types.every(isTemplateLiteralSpanType); } + return false; }; -var EmptyProto = /* @__PURE__ */ Object.assign(/* @__PURE__ */ Object.create(PatchProto), { - _tag: "Empty" -}); -var _empty5 = /* @__PURE__ */ Object.create(EmptyProto); -var empty10 = () => _empty5; -var AndThenProto = /* @__PURE__ */ Object.assign(/* @__PURE__ */ Object.create(PatchProto), { - _tag: "AndThen" -}); -var makeAndThen = (first, second) => { - const o = Object.create(AndThenProto); - o.first = first; - o.second = second; - return o; -}; -var AddServiceProto = /* @__PURE__ */ Object.assign(/* @__PURE__ */ Object.create(PatchProto), { - _tag: "AddService" -}); -var makeAddService = (key, service) => { - const o = Object.create(AddServiceProto); - o.key = key; - o.service = service; - return o; -}; -var RemoveServiceProto = /* @__PURE__ */ Object.assign(/* @__PURE__ */ Object.create(PatchProto), { - _tag: "RemoveService" -}); -var makeRemoveService = (key) => { - const o = Object.create(RemoveServiceProto); - o.key = key; - return o; +var templateLiteralSpanUnionTypeToString = (type) => { + switch (type._tag) { + case "Literal": + return JSON.stringify(String(type.literal)); + case "StringKeyword": + return "string"; + case "NumberKeyword": + return "number"; + case "TemplateLiteral": + return String(type); + case "Union": + return type.types.map(templateLiteralSpanUnionTypeToString).join(" | "); + } }; -var UpdateServiceProto = /* @__PURE__ */ Object.assign(/* @__PURE__ */ Object.create(PatchProto), { - _tag: "UpdateService" -}); -var makeUpdateService = (key, update) => { - const o = Object.create(UpdateServiceProto); - o.key = key; - o.update = update; - return o; +var templateLiteralSpanTypeToString = (type) => { + switch (type._tag) { + case "Literal": + return String(type.literal); + case "StringKeyword": + return "${string}"; + case "NumberKeyword": + return "${number}"; + case "TemplateLiteral": + return "${" + String(type) + "}"; + case "Union": + return "${" + type.types.map(templateLiteralSpanUnionTypeToString).join(" | ") + "}"; + } }; -var diff = (oldValue, newValue) => { - const missingServices = new Map(oldValue.unsafeMap); - let patch = empty10(); - for (const [tag, newService] of newValue.unsafeMap.entries()) { - if (missingServices.has(tag)) { - const old = missingServices.get(tag); - missingServices.delete(tag); - if (!equals(old, newService)) { - patch = combine4(makeUpdateService(tag, () => newService))(patch); - } + +class TemplateLiteralSpan { + literal; + type; + constructor(type, literal) { + this.literal = literal; + if (isTemplateLiteralSpanType(type)) { + this.type = type; } else { - missingServices.delete(tag); - patch = combine4(makeAddService(tag, newService))(patch); + throw new Error(getSchemaUnsupportedLiteralSpanErrorMessage(type)); } } - for (const [tag] of missingServices.entries()) { - patch = combine4(makeRemoveService(tag))(patch); - } - return patch; -}; -var combine4 = /* @__PURE__ */ dual(2, (self, that) => makeAndThen(self, that)); -var patch = /* @__PURE__ */ dual(2, (self, context) => { - if (self._tag === "Empty") { - return context; + toString() { + return templateLiteralSpanTypeToString(this.type) + this.literal; } - let wasServiceUpdated = false; - let patches = of2(self); - const updatedContext = new Map(context.unsafeMap); - while (isNonEmpty(patches)) { - const head3 = headNonEmpty2(patches); - const tail = tailNonEmpty2(patches); - switch (head3._tag) { - case "Empty": { - patches = tail; - break; - } - case "AddService": { - updatedContext.set(head3.key, head3.service); - patches = tail; - break; - } - case "AndThen": { - patches = prepend2(prepend2(tail, head3.second), head3.first); - break; - } - case "RemoveService": { - updatedContext.delete(head3.key); - patches = tail; - break; - } - case "UpdateService": { - updatedContext.set(head3.key, head3.update(updatedContext.get(head3.key))); - wasServiceUpdated = true; - patches = tail; - break; - } - } + toJSON() { + return { + type: this.type.toJSON(), + literal: this.literal + }; } - if (!wasServiceUpdated) { - return makeContext(updatedContext); +} + +class TemplateLiteral { + head; + spans; + annotations; + _tag = "TemplateLiteral"; + constructor(head2, spans, annotations = {}) { + this.head = head2; + this.spans = spans; + this.annotations = annotations; } - const map7 = new Map; - for (const [tag] of context.unsafeMap) { - if (updatedContext.has(tag)) { - map7.set(tag, updatedContext.get(tag)); - updatedContext.delete(tag); - } + toString() { + return getOrElse(getExpected(this), () => formatTemplateLiteral(this)); } - for (const [tag, s] of updatedContext) { - map7.set(tag, s); + toJSON() { + return { + _tag: this._tag, + head: this.head, + spans: this.spans.map((span2) => span2.toJSON()), + annotations: toJSONAnnotations(this.annotations) + }; } - return makeContext(map7); -}); - -// node_modules/effect/dist/esm/internal/differ/hashSetPatch.js -var HashSetPatchTypeId = /* @__PURE__ */ Symbol.for("effect/DifferHashSetPatch"); -function variance2(a) { - return a; } -var PatchProto2 = { - ...Structural.prototype, - [HashSetPatchTypeId]: { - _Value: variance2, - _Key: variance2, - _Patch: variance2 +var formatTemplateLiteral = (ast) => "`" + ast.head + ast.spans.map(String).join("") + "`"; +var isTemplateLiteral = /* @__PURE__ */ createASTGuard("TemplateLiteral"); + +class Type { + type; + annotations; + constructor(type, annotations = {}) { + this.type = type; + this.annotations = annotations; } -}; -var EmptyProto2 = /* @__PURE__ */ Object.assign(/* @__PURE__ */ Object.create(PatchProto2), { - _tag: "Empty" -}); -var _empty6 = /* @__PURE__ */ Object.create(EmptyProto2); -var empty11 = () => _empty6; -var AndThenProto2 = /* @__PURE__ */ Object.assign(/* @__PURE__ */ Object.create(PatchProto2), { - _tag: "AndThen" -}); -var makeAndThen2 = (first, second) => { - const o = Object.create(AndThenProto2); - o.first = first; - o.second = second; - return o; -}; -var AddProto = /* @__PURE__ */ Object.assign(/* @__PURE__ */ Object.create(PatchProto2), { - _tag: "Add" -}); -var makeAdd = (value) => { - const o = Object.create(AddProto); - o.value = value; - return o; -}; -var RemoveProto = /* @__PURE__ */ Object.assign(/* @__PURE__ */ Object.create(PatchProto2), { - _tag: "Remove" -}); -var makeRemove = (value) => { - const o = Object.create(RemoveProto); - o.value = value; - return o; -}; -var diff2 = (oldValue, newValue) => { - const [removed, patch2] = reduce4([oldValue, empty11()], ([set4, patch3], value) => { - if (has3(value)(set4)) { - return [remove4(value)(set4), patch3]; - } - return [set4, combine5(makeAdd(value))(patch3)]; - })(newValue); - return reduce4(patch2, (patch3, value) => combine5(makeRemove(value))(patch3))(removed); -}; -var combine5 = /* @__PURE__ */ dual(2, (self, that) => makeAndThen2(self, that)); -var patch2 = /* @__PURE__ */ dual(2, (self, oldValue) => { - if (self._tag === "Empty") { - return oldValue; + toJSON() { + return { + type: this.type.toJSON(), + annotations: toJSONAnnotations(this.annotations) + }; } - let set4 = oldValue; - let patches = of2(self); - while (isNonEmpty(patches)) { - const head3 = headNonEmpty2(patches); - const tail = tailNonEmpty2(patches); - switch (head3._tag) { - case "Empty": { - patches = tail; - break; - } - case "AndThen": { - patches = prepend2(head3.first)(prepend2(head3.second)(tail)); - break; - } - case "Add": { - set4 = add4(head3.value)(set4); - patches = tail; - break; - } - case "Remove": { - set4 = remove4(head3.value)(set4); - patches = tail; - } - } + toString() { + return String(this.type); } - return set4; -}); - -// node_modules/effect/dist/esm/internal/differ/readonlyArrayPatch.js -var ReadonlyArrayPatchTypeId = /* @__PURE__ */ Symbol.for("effect/DifferReadonlyArrayPatch"); -function variance3(a) { - return a; } -var PatchProto3 = { - ...Structural.prototype, - [ReadonlyArrayPatchTypeId]: { - _Value: variance3, - _Patch: variance3 - } -}; -var EmptyProto3 = /* @__PURE__ */ Object.assign(/* @__PURE__ */ Object.create(PatchProto3), { - _tag: "Empty" -}); -var _empty7 = /* @__PURE__ */ Object.create(EmptyProto3); -var empty12 = () => _empty7; -var AndThenProto3 = /* @__PURE__ */ Object.assign(/* @__PURE__ */ Object.create(PatchProto3), { - _tag: "AndThen" -}); -var makeAndThen3 = (first, second) => { - const o = Object.create(AndThenProto3); - o.first = first; - o.second = second; - return o; -}; -var AppendProto = /* @__PURE__ */ Object.assign(/* @__PURE__ */ Object.create(PatchProto3), { - _tag: "Append" -}); -var makeAppend = (values3) => { - const o = Object.create(AppendProto); - o.values = values3; - return o; -}; -var SliceProto = /* @__PURE__ */ Object.assign(/* @__PURE__ */ Object.create(PatchProto3), { - _tag: "Slice" -}); -var makeSlice = (from, until) => { - const o = Object.create(SliceProto); - o.from = from; - o.until = until; - return o; -}; -var UpdateProto = /* @__PURE__ */ Object.assign(/* @__PURE__ */ Object.create(PatchProto3), { - _tag: "Update" -}); -var makeUpdate = (index, patch3) => { - const o = Object.create(UpdateProto); - o.index = index; - o.patch = patch3; - return o; -}; -var diff3 = (options) => { - let i = 0; - let patch3 = empty12(); - while (i < options.oldValue.length && i < options.newValue.length) { - const oldElement = options.oldValue[i]; - const newElement = options.newValue[i]; - const valuePatch = options.differ.diff(oldElement, newElement); - if (!equals(valuePatch, options.differ.empty)) { - patch3 = combine6(patch3, makeUpdate(i, valuePatch)); - } - i = i + 1; - } - if (i < options.oldValue.length) { - patch3 = combine6(patch3, makeSlice(0, i)); + +class OptionalType extends Type { + isOptional; + constructor(type, isOptional, annotations = {}) { + super(type, annotations); + this.isOptional = isOptional; } - if (i < options.newValue.length) { - patch3 = combine6(patch3, makeAppend(drop(i)(options.newValue))); + toJSON() { + return { + type: this.type.toJSON(), + isOptional: this.isOptional, + annotations: toJSONAnnotations(this.annotations) + }; } - return patch3; -}; -var combine6 = /* @__PURE__ */ dual(2, (self, that) => makeAndThen3(self, that)); -var patch3 = /* @__PURE__ */ dual(3, (self, oldValue, differ) => { - if (self._tag === "Empty") { - return oldValue; + toString() { + return String(this.type) + (this.isOptional ? "?" : ""); } - let readonlyArray = oldValue.slice(); - let patches = of(self); - while (isNonEmptyArray2(patches)) { - const head3 = headNonEmpty(patches); - const tail = tailNonEmpty(patches); - switch (head3._tag) { - case "Empty": { - patches = tail; - break; - } - case "AndThen": { - tail.unshift(head3.first, head3.second); - patches = tail; +} +var getRestASTs = (rest) => rest.map((annotatedAST) => annotatedAST.type); + +class TupleType { + elements; + rest; + isReadonly; + annotations; + _tag = "TupleType"; + constructor(elements, rest, isReadonly, annotations = {}) { + this.elements = elements; + this.rest = rest; + this.isReadonly = isReadonly; + this.annotations = annotations; + let hasOptionalElement = false; + let hasIllegalRequiredElement = false; + for (const e of elements) { + if (e.isOptional) { + hasOptionalElement = true; + } else if (hasOptionalElement) { + hasIllegalRequiredElement = true; break; } - case "Append": { - for (const value of head3.values) { - readonlyArray.push(value); + } + if (hasIllegalRequiredElement || hasOptionalElement && rest.length > 1) { + throw new Error(getASTRequiredElementFollowinAnOptionalElementErrorMessage); + } + } + toString() { + return getOrElse(getExpected(this), () => formatTuple(this)); + } + toJSON() { + return { + _tag: this._tag, + elements: this.elements.map((e) => e.toJSON()), + rest: this.rest.map((ast) => ast.toJSON()), + isReadonly: this.isReadonly, + annotations: toJSONAnnotations(this.annotations) + }; + } +} +var formatTuple = (ast) => { + const formattedElements = ast.elements.map(String).join(", "); + return matchLeft(ast.rest, { + onEmpty: () => `readonly [${formattedElements}]`, + onNonEmpty: (head2, tail) => { + const formattedHead = String(head2); + const wrappedHead = formattedHead.includes(" | ") ? `(${formattedHead})` : formattedHead; + if (tail.length > 0) { + const formattedTail = tail.map(String).join(", "); + if (ast.elements.length > 0) { + return `readonly [${formattedElements}, ...${wrappedHead}[], ${formattedTail}]`; + } else { + return `readonly [...${wrappedHead}[], ${formattedTail}]`; + } + } else { + if (ast.elements.length > 0) { + return `readonly [${formattedElements}, ...${wrappedHead}[]]`; + } else { + return `ReadonlyArray<${formattedHead}>`; } - patches = tail; - break; - } - case "Slice": { - readonlyArray = readonlyArray.slice(head3.from, head3.until); - patches = tail; - break; - } - case "Update": { - readonlyArray[head3.index] = differ.patch(head3.patch, readonlyArray[head3.index]); - patches = tail; - break; } } + }); +}; +class PropertySignature extends OptionalType { + name; + isReadonly; + constructor(name, type, isOptional, isReadonly, annotations) { + super(type, isOptional, annotations); + this.name = name; + this.isReadonly = isReadonly; } - return readonlyArray; -}); - -// node_modules/effect/dist/esm/internal/differ.js -var DifferTypeId = /* @__PURE__ */ Symbol.for("effect/Differ"); -var DifferProto = { - [DifferTypeId]: { - _P: identity, - _V: identity - }, - pipe() { - return pipeArguments(this, arguments); + toString() { + return (this.isReadonly ? "readonly " : "") + String(this.name) + (this.isOptional ? "?" : "") + ": " + this.type; } + toJSON() { + return { + name: String(this.name), + type: this.type.toJSON(), + isOptional: this.isOptional, + isReadonly: this.isReadonly, + annotations: toJSONAnnotations(this.annotations) + }; + } +} +var isParameter = (ast) => { + switch (ast._tag) { + case "StringKeyword": + case "SymbolKeyword": + case "TemplateLiteral": + return true; + case "Refinement": + return isParameter(ast.from); + } + return false; }; -var make14 = (params) => { - const differ = Object.create(DifferProto); - differ.empty = params.empty; - differ.diff = params.diff; - differ.combine = params.combine; - differ.patch = params.patch; - return differ; -}; -var environment = () => make14({ - empty: empty10(), - combine: (first, second) => combine4(second)(first), - diff: (oldValue, newValue) => diff(oldValue, newValue), - patch: (patch4, oldValue) => patch(oldValue)(patch4) -}); -var hashSet = () => make14({ - empty: empty11(), - combine: (first, second) => combine5(second)(first), - diff: (oldValue, newValue) => diff2(oldValue, newValue), - patch: (patch4, oldValue) => patch2(oldValue)(patch4) -}); -var readonlyArray = (differ) => make14({ - empty: empty12(), - combine: (first, second) => combine6(first, second), - diff: (oldValue, newValue) => diff3({ - oldValue, - newValue, - differ - }), - patch: (patch4, oldValue) => patch3(patch4, oldValue, differ) -}); -var update = () => updateWith((_, a) => a); -var updateWith = (f) => make14({ - empty: identity, - combine: (first, second) => { - if (first === identity) { - return second; - } - if (second === identity) { - return first; - } - return (a) => second(first(a)); - }, - diff: (oldValue, newValue) => { - if (equals(oldValue, newValue)) { - return identity; - } - return constant(newValue); - }, - patch: (patch4, oldValue) => f(oldValue, patch4(oldValue)) -}); -// node_modules/effect/dist/esm/internal/runtimeFlagsPatch.js -var BIT_MASK = 255; -var BIT_SHIFT = 8; -var active = (patch4) => patch4 & BIT_MASK; -var enabled = (patch4) => patch4 >> BIT_SHIFT & BIT_MASK; -var make15 = (active2, enabled2) => (active2 & BIT_MASK) + ((enabled2 & active2 & BIT_MASK) << BIT_SHIFT); -var empty13 = /* @__PURE__ */ make15(0, 0); -var enable = (flag) => make15(flag, flag); -var disable = (flag) => make15(flag, 0); -var exclude = /* @__PURE__ */ dual(2, (self, flag) => make15(active(self) & ~flag, enabled(self))); -var andThen = /* @__PURE__ */ dual(2, (self, that) => self | that); -var invert = (n) => ~n >>> 0 & BIT_MASK; - -// node_modules/effect/dist/esm/internal/runtimeFlags.js -var None2 = 0; -var Interruption = 1 << 0; -var OpSupervision = 1 << 1; -var RuntimeMetrics = 1 << 2; -var WindDown = 1 << 4; -var CooperativeYielding = 1 << 5; -var cooperativeYielding = (self) => isEnabled(self, CooperativeYielding); -var disable2 = /* @__PURE__ */ dual(2, (self, flag) => self & ~flag); -var enable2 = /* @__PURE__ */ dual(2, (self, flag) => self | flag); -var interruptible = (self) => interruption(self) && !windDown(self); -var interruption = (self) => isEnabled(self, Interruption); -var isEnabled = /* @__PURE__ */ dual(2, (self, flag) => (self & flag) !== 0); -var make16 = (...flags) => flags.reduce((a, b) => a | b, 0); -var none5 = /* @__PURE__ */ make16(None2); -var runtimeMetrics = (self) => isEnabled(self, RuntimeMetrics); -var windDown = (self) => isEnabled(self, WindDown); -var diff4 = /* @__PURE__ */ dual(2, (self, that) => make15(self ^ that, that)); -var patch4 = /* @__PURE__ */ dual(2, (self, patch5) => self & (invert(active(patch5)) | enabled(patch5)) | active(patch5) & enabled(patch5)); -var differ = /* @__PURE__ */ make14({ - empty: empty13, - diff: (oldValue, newValue) => diff4(oldValue, newValue), - combine: (first, second) => andThen(second)(first), - patch: (_patch, oldValue) => patch4(oldValue, _patch) -}); - -// node_modules/effect/dist/esm/RuntimeFlagsPatch.js -var empty14 = empty13; -var enable3 = enable; -var disable3 = disable; -var exclude2 = exclude; - -// node_modules/effect/dist/esm/internal/blockedRequests.js -var empty15 = { - _tag: "Empty" -}; -var par = (self, that) => ({ - _tag: "Par", - left: self, - right: that -}); -var seq = (self, that) => ({ - _tag: "Seq", - left: self, - right: that -}); -var single = (dataSource, blockedRequest) => ({ - _tag: "Single", - dataSource, - blockedRequest -}); -var flatten2 = (self) => { - let current = of3(self); - let updated = empty9(); - while (true) { - const [parallel, sequential] = reduce6(current, [parallelCollectionEmpty(), empty9()], ([parallel2, sequential2], blockedRequest) => { - const [par2, seq2] = step(blockedRequest); - return [parallelCollectionCombine(parallel2, par2), appendAll3(sequential2, seq2)]; - }); - updated = merge4(updated, parallel); - if (isNil(sequential)) { - return reverse3(updated); +class IndexSignature { + type; + isReadonly; + parameter; + constructor(parameter, type, isReadonly) { + this.type = type; + this.isReadonly = isReadonly; + if (isParameter(parameter)) { + this.parameter = parameter; + } else { + throw new Error(getASTIndexSignatureParameterErrorMessage); } - current = sequential; } - throw new Error("BUG: BlockedRequests.flatten - please report an issue at https://github.com/Effect-TS/effect/issues"); -}; -var step = (requests) => { - let current = requests; - let parallel = parallelCollectionEmpty(); - let stack = empty9(); - let sequential = empty9(); - while (true) { - switch (current._tag) { - case "Empty": { - if (isNil(stack)) { - return [parallel, sequential]; - } - current = stack.head; - stack = stack.tail; - break; - } - case "Par": { - stack = cons(current.right, stack); - current = current.left; - break; + toString() { + return (this.isReadonly ? "readonly " : "") + `[x: ${this.parameter}]: ${this.type}`; + } + toJSON() { + return { + parameter: this.parameter.toJSON(), + type: this.type.toJSON(), + isReadonly: this.isReadonly + }; + } +} + +class TypeLiteral { + annotations; + _tag = "TypeLiteral"; + propertySignatures; + indexSignatures; + constructor(propertySignatures, indexSignatures, annotations = {}) { + this.annotations = annotations; + const keys = {}; + for (let i = 0;i < propertySignatures.length; i++) { + const name = propertySignatures[i].name; + if (Object.prototype.hasOwnProperty.call(keys, name)) { + throw new Error(getASTDuplicatePropertySignatureErrorMessage(name)); } - case "Seq": { - const left3 = current.left; - const right3 = current.right; - switch (left3._tag) { - case "Empty": { - current = right3; - break; - } - case "Par": { - const l = left3.left; - const r = left3.right; - current = par(seq(l, right3), seq(r, right3)); - break; - } - case "Seq": { - const l = left3.left; - const r = left3.right; - current = seq(l, seq(r, right3)); - break; - } - case "Single": { - current = left3; - sequential = cons(right3, sequential); - break; - } + keys[name] = null; + } + const parameters = { + string: false, + symbol: false + }; + for (let i = 0;i < indexSignatures.length; i++) { + const encodedParameter = getEncodedParameter(indexSignatures[i].parameter); + if (isStringKeyword(encodedParameter)) { + if (parameters.string) { + throw new Error(getASTDuplicateIndexSignatureErrorMessage("string")); } - break; - } - case "Single": { - parallel = parallelCollectionAdd(parallel, current); - if (isNil(stack)) { - return [parallel, sequential]; + parameters.string = true; + } else if (isSymbolKeyword(encodedParameter)) { + if (parameters.symbol) { + throw new Error(getASTDuplicateIndexSignatureErrorMessage("symbol")); } - current = stack.head; - stack = stack.tail; - break; + parameters.symbol = true; } } + this.propertySignatures = propertySignatures; + this.indexSignatures = indexSignatures; } - throw new Error("BUG: BlockedRequests.step - please report an issue at https://github.com/Effect-TS/effect/issues"); -}; -var merge4 = (sequential, parallel) => { - if (isNil(sequential)) { - return of3(parallelCollectionToSequentialCollection(parallel)); + toString() { + return getOrElse(getExpected(this), () => formatTypeLiteral(this)); } - if (parallelCollectionIsEmpty(parallel)) { - return sequential; + toJSON() { + return { + _tag: this._tag, + propertySignatures: this.propertySignatures.map((ps) => ps.toJSON()), + indexSignatures: this.indexSignatures.map((ps) => ps.toJSON()), + annotations: toJSONAnnotations(this.annotations) + }; } - const seqHeadKeys = sequentialCollectionKeys(sequential.head); - const parKeys = parallelCollectionKeys(parallel); - if (seqHeadKeys.length === 1 && parKeys.length === 1 && equals(seqHeadKeys[0], parKeys[0])) { - return cons(sequentialCollectionCombine(sequential.head, parallelCollectionToSequentialCollection(parallel)), sequential.tail); +} +var formatIndexSignatures = (iss) => iss.map(String).join("; "); +var formatTypeLiteral = (ast) => { + if (ast.propertySignatures.length > 0) { + const pss = ast.propertySignatures.map(String).join("; "); + if (ast.indexSignatures.length > 0) { + return `{ ${pss}; ${formatIndexSignatures(ast.indexSignatures)} }`; + } else { + return `{ ${pss} }`; + } + } else { + if (ast.indexSignatures.length > 0) { + return `{ ${formatIndexSignatures(ast.indexSignatures)} }`; + } else { + return "{}"; + } } - return cons(parallelCollectionToSequentialCollection(parallel), sequential); }; -var EntryTypeId = /* @__PURE__ */ Symbol.for("effect/RequestBlock/Entry"); - -class EntryImpl { - request; - result; - listeners; - ownerId; - state; - [EntryTypeId] = blockedRequestVariance; - constructor(request, result, listeners, ownerId, state) { - this.request = request; - this.result = result; - this.listeners = listeners; - this.ownerId = ownerId; - this.state = state; +var isTypeLiteral = /* @__PURE__ */ createASTGuard("TypeLiteral"); +var sortCandidates = /* @__PURE__ */ sort(/* @__PURE__ */ mapInput2(Order, (ast) => { + switch (ast._tag) { + case "AnyKeyword": + return 0; + case "UnknownKeyword": + return 1; + case "ObjectKeyword": + return 2; + case "StringKeyword": + case "NumberKeyword": + case "BooleanKeyword": + case "BigIntKeyword": + case "SymbolKeyword": + return 3; } -} -var blockedRequestVariance = { - _R: (_) => _ -}; -var makeEntry = (options) => new EntryImpl(options.request, options.result, options.listeners, options.ownerId, options.state); -var RequestBlockParallelTypeId = /* @__PURE__ */ Symbol.for("effect/RequestBlock/RequestBlockParallel"); -var parallelVariance = { - _R: (_) => _ + return 4; +})); +var literalMap = { + string: "StringKeyword", + number: "NumberKeyword", + boolean: "BooleanKeyword", + bigint: "BigIntKeyword" }; - -class ParallelImpl { - map; - [RequestBlockParallelTypeId] = parallelVariance; - constructor(map7) { - this.map = map7; +var flatten2 = (candidates) => flatMap2(candidates, (ast) => isUnion(ast) ? flatten2(ast.types) : [ast]); +var unify = (candidates) => { + const cs = sortCandidates(candidates); + const out = []; + const uniques = {}; + const literals = []; + for (const ast of cs) { + switch (ast._tag) { + case "NeverKeyword": + break; + case "AnyKeyword": + return [anyKeyword]; + case "UnknownKeyword": + return [unknownKeyword]; + case "ObjectKeyword": + case "UndefinedKeyword": + case "VoidKeyword": + case "StringKeyword": + case "NumberKeyword": + case "BooleanKeyword": + case "BigIntKeyword": + case "SymbolKeyword": { + if (!uniques[ast._tag]) { + uniques[ast._tag] = ast; + out.push(ast); + } + break; + } + case "Literal": { + const type = typeof ast.literal; + switch (type) { + case "string": + case "number": + case "bigint": + case "boolean": { + const _tag = literalMap[type]; + if (!uniques[_tag] && !literals.includes(ast.literal)) { + literals.push(ast.literal); + out.push(ast); + } + break; + } + case "object": { + if (!literals.includes(ast.literal)) { + literals.push(ast.literal); + out.push(ast); + } + break; + } + } + break; + } + case "UniqueSymbol": { + if (!uniques["SymbolKeyword"] && !literals.includes(ast.symbol)) { + literals.push(ast.symbol); + out.push(ast); + } + break; + } + case "TupleType": { + if (!uniques["ObjectKeyword"]) { + out.push(ast); + } + break; + } + case "TypeLiteral": { + if (ast.propertySignatures.length === 0 && ast.indexSignatures.length === 0) { + if (!uniques["{}"]) { + uniques["{}"] = ast; + out.push(ast); + } + } else if (!uniques["ObjectKeyword"]) { + out.push(ast); + } + break; + } + default: + out.push(ast); + } } -} -var parallelCollectionEmpty = () => new ParallelImpl(empty8()); -var parallelCollectionAdd = (self, blockedRequest) => new ParallelImpl(modifyAt2(self.map, blockedRequest.dataSource, (_) => orElseSome(map2(_, append2(blockedRequest.blockedRequest)), () => of2(blockedRequest.blockedRequest)))); -var parallelCollectionCombine = (self, that) => new ParallelImpl(reduce5(self.map, that.map, (map7, value, key) => set3(map7, key, match2(get7(map7, key), { - onNone: () => value, - onSome: (other) => appendAll2(value, other) -})))); -var parallelCollectionIsEmpty = (self) => isEmpty3(self.map); -var parallelCollectionKeys = (self) => Array.from(keys2(self.map)); -var parallelCollectionToSequentialCollection = (self) => sequentialCollectionMake(map6(self.map, (x) => of2(x))); -var SequentialCollectionTypeId = /* @__PURE__ */ Symbol.for("effect/RequestBlock/RequestBlockSequential"); -var sequentialVariance = { - _R: (_) => _ + return out; }; -class SequentialImpl { - map; - [SequentialCollectionTypeId] = sequentialVariance; - constructor(map7) { - this.map = map7; +class Union { + types; + annotations; + static make = (types, annotations) => { + return isMembers(types) ? new Union(types, annotations) : types.length === 1 ? types[0] : neverKeyword; + }; + static unify = (candidates, annotations) => { + return Union.make(unify(flatten2(candidates)), annotations); + }; + _tag = "Union"; + constructor(types, annotations = {}) { + this.types = types; + this.annotations = annotations; + } + toString() { + return getOrElse(getExpected(this), () => this.types.map(String).join(" | ")); + } + toJSON() { + return { + _tag: this._tag, + types: this.types.map((ast) => ast.toJSON()), + annotations: toJSONAnnotations(this.annotations) + }; } } -var sequentialCollectionMake = (map7) => new SequentialImpl(map7); -var sequentialCollectionCombine = (self, that) => new SequentialImpl(reduce5(that.map, self.map, (map7, value, key) => set3(map7, key, match2(get7(map7, key), { - onNone: () => empty2(), - onSome: (a) => appendAll2(a, value) -})))); -var sequentialCollectionKeys = (self) => Array.from(keys2(self.map)); -var sequentialCollectionToChunk = (self) => Array.from(self.map); - -// node_modules/effect/dist/esm/internal/opCodes/cause.js -var OP_DIE = "Die"; -var OP_EMPTY = "Empty"; -var OP_FAIL = "Fail"; -var OP_INTERRUPT = "Interrupt"; -var OP_PARALLEL = "Parallel"; -var OP_SEQUENTIAL = "Sequential"; +var mapMembers = (members, f) => members.map(f); +var isMembers = (as) => as.length > 1; +var isUnion = /* @__PURE__ */ createASTGuard("Union"); +var toJSONMemoMap = /* @__PURE__ */ globalValue(/* @__PURE__ */ Symbol.for("effect/Schema/AST/toJSONMemoMap"), () => new WeakMap); -// node_modules/effect/dist/esm/internal/cause.js -var CauseSymbolKey = "effect/Cause"; -var CauseTypeId = /* @__PURE__ */ Symbol.for(CauseSymbolKey); -var variance4 = { - _E: (_) => _ -}; -var proto = { - [CauseTypeId]: variance4, - [symbol]() { - return pipe(hash(CauseSymbolKey), combine(hash(flattenCause(this))), cached(this)); - }, - [symbol2](that) { - return isCause(that) && causeEquals(this, that); - }, - pipe() { - return pipeArguments(this, arguments); - }, +class Suspend { + f; + annotations; + _tag = "Suspend"; + constructor(f, annotations = {}) { + this.f = f; + this.annotations = annotations; + this.f = memoizeThunk(f); + } + toString() { + return getExpected(this).pipe(orElse(() => flatMap(liftThrowable(this.f)(), (ast) => getExpected(ast))), getOrElse(() => "")); + } toJSON() { - switch (this._tag) { - case "Empty": - return { - _id: "Cause", - _tag: this._tag - }; - case "Die": - return { - _id: "Cause", - _tag: this._tag, - defect: toJSON(this.defect) - }; - case "Interrupt": - return { - _id: "Cause", - _tag: this._tag, - fiberId: this.fiberId.toJSON() - }; - case "Fail": - return { - _id: "Cause", - _tag: this._tag, - failure: toJSON(this.error) - }; - case "Sequential": - case "Parallel": - return { - _id: "Cause", - _tag: this._tag, - left: toJSON(this.left), - right: toJSON(this.right) - }; + const ast = this.f(); + let out = toJSONMemoMap.get(ast); + if (out) { + return out; } - }, + toJSONMemoMap.set(ast, { + _tag: this._tag + }); + out = { + _tag: this._tag, + ast: ast.toJSON(), + annotations: toJSONAnnotations(this.annotations) + }; + toJSONMemoMap.set(ast, out); + return out; + } +} +class Refinement { + from; + filter; + annotations; + _tag = "Refinement"; + constructor(from, filter2, annotations = {}) { + this.from = from; + this.filter = filter2; + this.annotations = annotations; + } toString() { - return pretty(this); - }, - [NodeInspectSymbol]() { - return this.toJSON(); + return getIdentifierAnnotation(this).pipe(getOrElse(() => match2(getOrElseExpected(this), { + onNone: () => `{ ${this.from} | filter }`, + onSome: (expected) => isRefinement(this.from) ? String(this.from) + " & " + expected : expected + }))); } -}; -var empty16 = /* @__PURE__ */ (() => { - const o = /* @__PURE__ */ Object.create(proto); - o._tag = OP_EMPTY; - return o; -})(); -var fail = (error) => { - const o = Object.create(proto); - o._tag = OP_FAIL; - o.error = error; - return o; -}; -var die = (defect) => { - const o = Object.create(proto); - o._tag = OP_DIE; - o.defect = defect; - return o; -}; -var interrupt = (fiberId) => { - const o = Object.create(proto); - o._tag = OP_INTERRUPT; - o.fiberId = fiberId; - return o; -}; -var parallel = (left3, right3) => { - const o = Object.create(proto); - o._tag = OP_PARALLEL; - o.left = left3; - o.right = right3; - return o; -}; -var sequential = (left3, right3) => { - const o = Object.create(proto); - o._tag = OP_SEQUENTIAL; - o.left = left3; - o.right = right3; - return o; -}; -var isCause = (u) => hasProperty(u, CauseTypeId); -var isEmptyType = (self) => self._tag === OP_EMPTY; -var isFailType = (self) => self._tag === OP_FAIL; -var isDieType = (self) => self._tag === OP_DIE; -var isEmpty5 = (self) => { - if (self._tag === OP_EMPTY) { - return true; + toJSON() { + return { + _tag: this._tag, + from: this.from.toJSON(), + annotations: toJSONAnnotations(this.annotations) + }; } - return reduce7(self, true, (acc, cause) => { - switch (cause._tag) { - case OP_EMPTY: { - return some2(acc); - } - case OP_DIE: - case OP_FAIL: - case OP_INTERRUPT: { - return some2(false); +} +var isRefinement = /* @__PURE__ */ createASTGuard("Refinement"); +var defaultParseOption = {}; + +class Transformation { + from; + to; + transformation; + annotations; + _tag = "Transformation"; + constructor(from, to, transformation, annotations = {}) { + this.from = from; + this.to = to; + this.transformation = transformation; + this.annotations = annotations; + } + toString() { + return getOrElse(getExpected(this), () => `(${String(this.from)} <-> ${String(this.to)})`); + } + toJSON() { + return { + _tag: this._tag, + from: this.from.toJSON(), + to: this.to.toJSON(), + annotations: toJSONAnnotations(this.annotations) + }; + } +} +var isTransformation = /* @__PURE__ */ createASTGuard("Transformation"); + +class FinalTransformation { + decode; + encode; + _tag = "FinalTransformation"; + constructor(decode, encode) { + this.decode = decode; + this.encode = encode; + } +} +var createTransformationGuard = (tag) => (ast) => ast._tag === tag; +class ComposeTransformation { + _tag = "ComposeTransformation"; +} +var composeTransformation = /* @__PURE__ */ new ComposeTransformation; +class PropertySignatureTransformation { + from; + to; + decode; + encode; + constructor(from, to, decode, encode) { + this.from = from; + this.to = to; + this.decode = decode; + this.encode = encode; + } +} +var isRenamingPropertySignatureTransformation = (t) => t.decode === identity && t.encode === identity; + +class TypeLiteralTransformation { + propertySignatureTransformations; + _tag = "TypeLiteralTransformation"; + constructor(propertySignatureTransformations) { + this.propertySignatureTransformations = propertySignatureTransformations; + const fromKeys = {}; + const toKeys = {}; + for (const pst of propertySignatureTransformations) { + const from = pst.from; + if (fromKeys[from]) { + throw new Error(getASTDuplicatePropertySignatureTransformationErrorMessage(from)); } - default: { - return none2(); + fromKeys[from] = true; + const to = pst.to; + if (toKeys[to]) { + throw new Error(getASTDuplicatePropertySignatureTransformationErrorMessage(to)); } + toKeys[to] = true; } - }); + } +} +var isTypeLiteralTransformation = /* @__PURE__ */ createTransformationGuard("TypeLiteralTransformation"); +var annotations = (ast, overrides) => { + const d = Object.getOwnPropertyDescriptors(ast); + const base = { + ...ast.annotations + }; + delete base[IdentifierAnnotationId]; + const value = { + ...base, + ...overrides + }; + const surrogate = getSurrogateAnnotation(ast); + if (isSome2(surrogate)) { + value[SurrogateAnnotationId] = annotations(surrogate.value, overrides); + } + d.annotations.value = value; + return Object.create(Object.getPrototypeOf(ast), d); }; -var isInterrupted = (self) => isSome2(interruptOption(self)); -var isInterruptedOnly = (self) => reduceWithContext(undefined, IsInterruptedOnlyCauseReducer)(self); -var failures = (self) => reverse2(reduce7(self, empty2(), (list, cause) => cause._tag === OP_FAIL ? some2(pipe(list, prepend2(cause.error))) : none2())); -var defects = (self) => reverse2(reduce7(self, empty2(), (list, cause) => cause._tag === OP_DIE ? some2(pipe(list, prepend2(cause.defect))) : none2())); -var interruptors = (self) => reduce7(self, empty7(), (set4, cause) => cause._tag === OP_INTERRUPT ? some2(pipe(set4, add4(cause.fiberId))) : none2()); -var failureOption = (self) => find(self, (cause) => cause._tag === OP_FAIL ? some2(cause.error) : none2()); -var failureOrCause = (self) => { - const option = failureOption(self); - switch (option._tag) { - case "None": { - return right2(self); - } - case "Some": { - return left2(option.value); - } +var keyof = (ast) => Union.unify(_keyof(ast)); +var STRING_KEYWORD_PATTERN = "[\\s\\S]*?"; +var NUMBER_KEYWORD_PATTERN = "[+-]?\\d*\\.?\\d+(?:[Ee][+-]?\\d+)?"; +var getTemplateLiteralSpanTypePattern = (type, capture) => { + switch (type._tag) { + case "Literal": + return escape(String(type.literal)); + case "StringKeyword": + return STRING_KEYWORD_PATTERN; + case "NumberKeyword": + return NUMBER_KEYWORD_PATTERN; + case "TemplateLiteral": + return getTemplateLiteralPattern(type, capture, false); + case "Union": + return type.types.map((type2) => getTemplateLiteralSpanTypePattern(type2, capture)).join("|"); } }; -var interruptOption = (self) => find(self, (cause) => cause._tag === OP_INTERRUPT ? some2(cause.fiberId) : none2()); -var keepDefects = (self) => match5(self, { - onEmpty: none2(), - onFail: () => none2(), - onDie: (defect) => some2(die(defect)), - onInterrupt: () => none2(), - onSequential: mergeWith(sequential), - onParallel: mergeWith(parallel) -}); -var keepDefectsAndElectFailures = (self) => match5(self, { - onEmpty: none2(), - onFail: (failure) => some2(die(failure)), - onDie: (defect) => some2(die(defect)), - onInterrupt: () => none2(), - onSequential: mergeWith(sequential), - onParallel: mergeWith(parallel) -}); -var stripFailures = (self) => match5(self, { - onEmpty: empty16, - onFail: () => empty16, - onDie: die, - onInterrupt: interrupt, - onSequential: sequential, - onParallel: parallel -}); -var electFailures = (self) => match5(self, { - onEmpty: empty16, - onFail: die, - onDie: die, - onInterrupt: interrupt, - onSequential: sequential, - onParallel: parallel -}); -var flatMap6 = /* @__PURE__ */ dual(2, (self, f) => match5(self, { - onEmpty: empty16, - onFail: (error) => f(error), - onDie: (defect) => die(defect), - onInterrupt: (fiberId) => interrupt(fiberId), - onSequential: (left3, right3) => sequential(left3, right3), - onParallel: (left3, right3) => parallel(left3, right3) -})); -var flatten3 = (self) => flatMap6(self, identity); -var causeEquals = (left3, right3) => { - let leftStack = of2(left3); - let rightStack = of2(right3); - while (isNonEmpty(leftStack) && isNonEmpty(rightStack)) { - const [leftParallel, leftSequential] = pipe(headNonEmpty2(leftStack), reduce7([empty7(), empty2()], ([parallel2, sequential2], cause) => { - const [par2, seq2] = evaluateCause(cause); - return some2([pipe(parallel2, union3(par2)), pipe(sequential2, appendAll2(seq2))]); - })); - const [rightParallel, rightSequential] = pipe(headNonEmpty2(rightStack), reduce7([empty7(), empty2()], ([parallel2, sequential2], cause) => { - const [par2, seq2] = evaluateCause(cause); - return some2([pipe(parallel2, union3(par2)), pipe(sequential2, appendAll2(seq2))]); - })); - if (!equals(leftParallel, rightParallel)) { - return false; +var handleTemplateLiteralSpanTypeParens = (type, s, capture, top) => { + if (isUnion(type)) { + if (capture && !top) { + return `(?:${s})`; } - leftStack = leftSequential; - rightStack = rightSequential; + } else if (!capture || !top) { + return s; } - return true; -}; -var flattenCause = (cause) => { - return flattenCauseLoop(of2(cause), empty2()); + return `(${s})`; }; -var flattenCauseLoop = (causes, flattened) => { - while (true) { - const [parallel2, sequential2] = pipe(causes, reduce([empty7(), empty2()], ([parallel3, sequential3], cause) => { - const [par2, seq2] = evaluateCause(cause); - return [pipe(parallel3, union3(par2)), pipe(sequential3, appendAll2(seq2))]; - })); - const updated = size3(parallel2) > 0 ? pipe(flattened, prepend2(parallel2)) : flattened; - if (isEmpty(sequential2)) { - return reverse2(updated); +var getTemplateLiteralPattern = (ast, capture, top) => { + let pattern = ``; + if (ast.head !== "") { + const head2 = escape(ast.head); + pattern += capture && top ? `(${head2})` : head2; + } + for (const span2 of ast.spans) { + const spanPattern = getTemplateLiteralSpanTypePattern(span2.type, capture); + pattern += handleTemplateLiteralSpanTypeParens(span2.type, spanPattern, capture, top); + if (span2.literal !== "") { + const literal = escape(span2.literal); + pattern += capture && top ? `(${literal})` : literal; } - causes = sequential2; - flattened = updated; } - throw new Error(getBugErrorMessage("Cause.flattenCauseLoop")); + return pattern; }; -var find = /* @__PURE__ */ dual(2, (self, pf) => { - const stack = [self]; - while (stack.length > 0) { - const item = stack.pop(); - const option = pf(item); - switch (option._tag) { - case "None": { - switch (item._tag) { - case OP_SEQUENTIAL: - case OP_PARALLEL: { - stack.push(item.right); - stack.push(item.left); - break; - } - } - break; - } - case "Some": { - return option; - } - } +var getTemplateLiteralRegExp = (ast) => new RegExp(`^${getTemplateLiteralPattern(ast, false, true)}$`); +var getTemplateLiteralCapturingRegExp = (ast) => new RegExp(`^${getTemplateLiteralPattern(ast, true, true)}$`); +var getIndexSignatures = (ast) => { + const annotation = getSurrogateAnnotation(ast); + if (isSome2(annotation)) { + return getIndexSignatures(annotation.value); } - return none2(); -}); -var evaluateCause = (self) => { - let cause = self; - const stack = []; - let _parallel = empty7(); - let _sequential = empty2(); - while (cause !== undefined) { - switch (cause._tag) { - case OP_EMPTY: { - if (stack.length === 0) { - return [_parallel, _sequential]; - } - cause = stack.pop(); - break; - } - case OP_FAIL: { - _parallel = add4(_parallel, make4(cause._tag, cause.error)); - if (stack.length === 0) { - return [_parallel, _sequential]; - } - cause = stack.pop(); - break; - } - case OP_DIE: { - _parallel = add4(_parallel, make4(cause._tag, cause.defect)); - if (stack.length === 0) { - return [_parallel, _sequential]; + switch (ast._tag) { + case "TypeLiteral": + return ast.indexSignatures.slice(); + case "Suspend": + return getIndexSignatures(ast.f()); + case "Refinement": + return getIndexSignatures(ast.from); + case "Transformation": + return getIndexSignatures(ast.to); + } + return []; +}; +var getNumberIndexedAccess = (ast) => { + switch (ast._tag) { + case "TupleType": { + let hasOptional = false; + let out = []; + for (const e of ast.elements) { + if (e.isOptional) { + hasOptional = true; } - cause = stack.pop(); - break; + out.push(e.type); } - case OP_INTERRUPT: { - _parallel = add4(_parallel, make4(cause._tag, cause.fiberId)); - if (stack.length === 0) { - return [_parallel, _sequential]; - } - cause = stack.pop(); - break; + if (hasOptional) { + out.push(undefinedKeyword); } - case OP_SEQUENTIAL: { - switch (cause.left._tag) { - case OP_EMPTY: { - cause = cause.right; - break; - } - case OP_SEQUENTIAL: { - cause = sequential(cause.left.left, sequential(cause.left.right, cause.right)); - break; - } - case OP_PARALLEL: { - cause = parallel(sequential(cause.left.left, cause.right), sequential(cause.left.right, cause.right)); - break; + out = out.concat(getRestASTs(ast.rest)); + return Union.make(out); + } + case "Refinement": + return getNumberIndexedAccess(ast.from); + case "Union": + return Union.make(ast.types.map(getNumberIndexedAccess)); + case "Suspend": + return getNumberIndexedAccess(ast.f()); + } + throw new Error(getASTUnsupportedSchemaErrorMessage(ast)); +}; +var getTypeLiteralPropertySignature = (ast, name) => { + const ops = findFirst2(ast.propertySignatures, (ps) => ps.name === name); + if (isSome2(ops)) { + return ops.value; + } + if (isString(name)) { + let out = undefined; + for (const is of ast.indexSignatures) { + const encodedParameter = getEncodedParameter(is.parameter); + switch (encodedParameter._tag) { + case "TemplateLiteral": { + const regex = getTemplateLiteralRegExp(encodedParameter); + if (regex.test(name)) { + return new PropertySignature(name, is.type, false, true); } - default: { - _sequential = prepend2(_sequential, cause.right); - cause = cause.left; - break; + break; + } + case "StringKeyword": { + if (out === undefined) { + out = new PropertySignature(name, is.type, false, true); } } - break; } - case OP_PARALLEL: { - stack.push(cause.right); - cause = cause.left; - break; + } + if (out) { + return out; + } + } else if (isSymbol(name)) { + for (const is of ast.indexSignatures) { + const encodedParameter = getEncodedParameter(is.parameter); + if (isSymbolKeyword(encodedParameter)) { + return new PropertySignature(name, is.type, false, true); } } } - throw new Error(getBugErrorMessage("Cause.evaluateCauseLoop")); -}; -var IsInterruptedOnlyCauseReducer = { - emptyCase: constTrue, - failCase: constFalse, - dieCase: constFalse, - interruptCase: constTrue, - sequentialCase: (_, left3, right3) => left3 && right3, - parallelCase: (_, left3, right3) => left3 && right3 }; -var OP_SEQUENTIAL_CASE = "SequentialCase"; -var OP_PARALLEL_CASE = "ParallelCase"; -var match5 = /* @__PURE__ */ dual(2, (self, { - onDie, - onEmpty, - onFail, - onInterrupt, - onParallel, - onSequential -}) => { - return reduceWithContext(self, undefined, { - emptyCase: () => onEmpty, - failCase: (_, error) => onFail(error), - dieCase: (_, defect) => onDie(defect), - interruptCase: (_, fiberId) => onInterrupt(fiberId), - sequentialCase: (_, left3, right3) => onSequential(left3, right3), - parallelCase: (_, left3, right3) => onParallel(left3, right3) - }); -}); -var reduce7 = /* @__PURE__ */ dual(3, (self, zero2, pf) => { - let accumulator = zero2; - let cause = self; - const causes = []; - while (cause !== undefined) { - const option = pf(accumulator, cause); - accumulator = isSome2(option) ? option.value : accumulator; - switch (cause._tag) { - case OP_SEQUENTIAL: { - causes.push(cause.right); - cause = cause.left; - break; - } - case OP_PARALLEL: { - causes.push(cause.right); - cause = cause.left; - break; - } - default: { - cause = undefined; - break; +var getPropertyKeyIndexedAccess = (ast, name) => { + const annotation = getSurrogateAnnotation(ast); + if (isSome2(annotation)) { + return getPropertyKeyIndexedAccess(annotation.value, name); + } + switch (ast._tag) { + case "TypeLiteral": { + const ps = getTypeLiteralPropertySignature(ast, name); + if (ps) { + return ps; } + break; } - if (cause === undefined && causes.length > 0) { - cause = causes.pop(); - } + case "Union": + return new PropertySignature(name, Union.make(ast.types.map((ast2) => getPropertyKeyIndexedAccess(ast2, name).type)), false, true); + case "Suspend": + return getPropertyKeyIndexedAccess(ast.f(), name); + case "Refinement": + return getPropertyKeyIndexedAccess(ast.from, name); + case "Transformation": + return getPropertyKeyIndexedAccess(ast.to, name); } - return accumulator; -}); -var reduceWithContext = /* @__PURE__ */ dual(3, (self, context, reducer) => { - const input = [self]; - const output = []; - while (input.length > 0) { - const cause = input.pop(); - switch (cause._tag) { - case OP_EMPTY: { - output.push(right2(reducer.emptyCase(context))); + throw new Error(getASTUnsupportedSchemaErrorMessage(ast)); +}; +var getPropertyKeys = (ast) => { + const annotation = getSurrogateAnnotation(ast); + if (isSome2(annotation)) { + return getPropertyKeys(annotation.value); + } + switch (ast._tag) { + case "TypeLiteral": + return ast.propertySignatures.map((ps) => ps.name); + case "Union": + return ast.types.slice(1).reduce((out, ast2) => intersection(out, getPropertyKeys(ast2)), getPropertyKeys(ast.types[0])); + case "Suspend": + return getPropertyKeys(ast.f()); + case "Refinement": + return getPropertyKeys(ast.from); + case "Transformation": + return getPropertyKeys(ast.to); + } + return []; +}; +var record = (key, value) => { + const propertySignatures = []; + const indexSignatures = []; + const go = (key2) => { + switch (key2._tag) { + case "NeverKeyword": break; - } - case OP_FAIL: { - output.push(right2(reducer.failCase(context, cause.error))); + case "StringKeyword": + case "SymbolKeyword": + case "TemplateLiteral": + case "Refinement": + indexSignatures.push(new IndexSignature(key2, value, true)); break; - } - case OP_DIE: { - output.push(right2(reducer.dieCase(context, cause.defect))); + case "Literal": + if (isString(key2.literal) || isNumber(key2.literal)) { + propertySignatures.push(new PropertySignature(key2.literal, value, false, true)); + } else { + throw new Error(getASTUnsupportedLiteralErrorMessage(key2.literal)); + } break; - } - case OP_INTERRUPT: { - output.push(right2(reducer.interruptCase(context, cause.fiberId))); + case "Enums": { + for (const [_, name] of key2.enums) { + propertySignatures.push(new PropertySignature(name, value, false, true)); + } break; } - case OP_SEQUENTIAL: { - input.push(cause.right); - input.push(cause.left); - output.push(left2({ - _tag: OP_SEQUENTIAL_CASE - })); + case "UniqueSymbol": + propertySignatures.push(new PropertySignature(key2.symbol, value, false, true)); break; - } - case OP_PARALLEL: { - input.push(cause.right); - input.push(cause.left); - output.push(left2({ - _tag: OP_PARALLEL_CASE - })); + case "Union": + key2.types.forEach(go); break; - } + default: + throw new Error(getASTUnsupportedKeySchemaErrorMessage(key2)); } + }; + go(key); + return { + propertySignatures, + indexSignatures + }; +}; +var pick = (ast, keys) => { + const annotation = getSurrogateAnnotation(ast); + if (isSome2(annotation)) { + return pick(annotation.value, keys); } - const accumulator = []; - while (output.length > 0) { - const either2 = output.pop(); - switch (either2._tag) { - case "Left": { - switch (either2.left._tag) { - case OP_SEQUENTIAL_CASE: { - const left3 = accumulator.pop(); - const right3 = accumulator.pop(); - const value = reducer.sequentialCase(context, left3, right3); - accumulator.push(value); - break; - } - case OP_PARALLEL_CASE: { - const left3 = accumulator.pop(); - const right3 = accumulator.pop(); - const value = reducer.parallelCase(context, left3, right3); - accumulator.push(value); - break; + switch (ast._tag) { + case "TypeLiteral": { + const pss = []; + const names = {}; + for (const ps of ast.propertySignatures) { + names[ps.name] = null; + if (keys.includes(ps.name)) { + pss.push(ps); + } + } + for (const key of keys) { + if (!(key in names)) { + const ps = getTypeLiteralPropertySignature(ast, key); + if (ps) { + pss.push(ps); } } - break; } - case "Right": { - accumulator.push(either2.right); - break; + return new TypeLiteral(pss, []); + } + case "Union": + return new TypeLiteral(keys.map((name) => getPropertyKeyIndexedAccess(ast, name)), []); + case "Suspend": + return pick(ast.f(), keys); + case "Refinement": + return pick(ast.from, keys); + case "Transformation": { + switch (ast.transformation._tag) { + case "ComposeTransformation": + return new Transformation(pick(ast.from, keys), pick(ast.to, keys), composeTransformation); + case "TypeLiteralTransformation": { + const ts = []; + const fromKeys = []; + for (const k of keys) { + const t = ast.transformation.propertySignatureTransformations.find((t2) => t2.to === k); + if (t) { + ts.push(t); + fromKeys.push(t.from); + } else { + fromKeys.push(k); + } + } + return isNonEmptyReadonlyArray(ts) ? new Transformation(pick(ast.from, fromKeys), pick(ast.to, keys), new TypeLiteralTransformation(ts)) : pick(ast.from, fromKeys); + } } } } - if (accumulator.length === 0) { - throw new Error("BUG: Cause.reduceWithContext - please report an issue at https://github.com/Effect-TS/effect/issues"); - } - return accumulator.pop(); -}); -var pretty = (cause, options) => { - if (isInterruptedOnly(cause)) { - return "All fibers interrupted without errors."; - } - return prettyErrors(cause).map(function(e) { - if (options?.renderErrorCause !== true || e.cause === undefined) { - return e.stack; - } - return `${e.stack} { -${renderErrorCause(e.cause, " ")} -}`; - }).join(` -`); + throw new Error(getASTUnsupportedSchemaErrorMessage(ast)); }; -var renderErrorCause = (cause, prefix) => { - const lines = cause.stack.split(` -`); - let stack = `${prefix}[cause]: ${lines[0]}`; - for (let i = 1, len = lines.length;i < len; i++) { - stack += ` -${prefix}${lines[i]}`; - } - if (cause.cause) { - stack += ` { -${renderErrorCause(cause.cause, `${prefix} `)} -${prefix}}`; +var omit = (ast, keys) => { + let indexSignatures = getIndexSignatures(ast); + if (indexSignatures.length > 0) { + if (indexSignatures.some((is) => isStringKeyword(getEncodedParameter(is.parameter)))) { + indexSignatures = indexSignatures.filter((is) => !isTemplateLiteral(getEncodedParameter(is.parameter))); + } + return new TypeLiteral([], indexSignatures); } - return stack; + return pick(ast, getPropertyKeys(ast).filter((name) => !keys.includes(name))); }; -var makePrettyError = (originalError) => { - const originalErrorIsObject = typeof originalError === "object" && originalError !== null; - const prevLimit = Error.stackTraceLimit; - Error.stackTraceLimit = 1; - const error = new Error(prettyErrorMessage(originalError), originalErrorIsObject && "cause" in originalError && typeof originalError.cause !== "undefined" ? { - cause: makePrettyError(originalError.cause) - } : undefined); - Error.stackTraceLimit = prevLimit; - if (error.message === "") { - error.message = "An error has occurred"; - } - Error.stackTraceLimit = prevLimit; - error.name = originalError instanceof Error ? originalError.name : "Error"; - if (originalErrorIsObject) { - if (spanSymbol in originalError) { - error.span = originalError[spanSymbol]; - } - Object.keys(originalError).forEach((key) => { - if (!(key in error)) { - error[key] = originalError[key]; +var orUndefined = (ast) => Union.make([ast, undefinedKeyword]); +var partial = (ast, options) => { + const exact = options?.exact === true; + switch (ast._tag) { + case "TupleType": + return new TupleType(ast.elements.map((e) => new OptionalType(exact ? e.type : orUndefined(e.type), true)), match3(ast.rest, { + onEmpty: () => ast.rest, + onNonEmpty: (rest) => [new Type(Union.make([...getRestASTs(rest), undefinedKeyword]))] + }), ast.isReadonly); + case "TypeLiteral": + return new TypeLiteral(ast.propertySignatures.map((ps) => new PropertySignature(ps.name, exact ? ps.type : orUndefined(ps.type), true, ps.isReadonly, ps.annotations)), ast.indexSignatures.map((is) => new IndexSignature(is.parameter, orUndefined(is.type), is.isReadonly))); + case "Union": + return Union.make(ast.types.map((member) => partial(member, options))); + case "Suspend": + return new Suspend(() => partial(ast.f(), options)); + case "Declaration": + case "Refinement": + throw new Error(getASTUnsupportedSchemaErrorMessage(ast)); + case "Transformation": { + if (isTypeLiteralTransformation(ast.transformation) && ast.transformation.propertySignatureTransformations.every(isRenamingPropertySignatureTransformation)) { + return new Transformation(partial(ast.from, options), partial(ast.to, options), ast.transformation); } - }); + throw new Error(getASTUnsupportedSchemaErrorMessage(ast)); + } } - error.stack = prettyErrorStack(`${error.name}: ${error.message}`, originalError instanceof Error && originalError.stack ? originalError.stack : "", error.span); - return error; + return ast; }; -var prettyErrorMessage = (u) => { - if (typeof u === "string") { - return u; - } - if (typeof u === "object" && u !== null && u instanceof Error) { - return u.message; - } - try { - if (hasProperty(u, "toString") && isFunction2(u["toString"]) && u["toString"] !== Object.prototype.toString && u["toString"] !== globalThis.Array.prototype.toString) { - return u["toString"](); +var required = (ast) => { + switch (ast._tag) { + case "TupleType": + return new TupleType(ast.elements.map((e) => new OptionalType(e.type, false)), ast.rest, ast.isReadonly); + case "TypeLiteral": + return new TypeLiteral(ast.propertySignatures.map((f) => new PropertySignature(f.name, f.type, false, f.isReadonly, f.annotations)), ast.indexSignatures); + case "Union": + return Union.make(ast.types.map((member) => required(member))); + case "Suspend": + return new Suspend(() => required(ast.f())); + case "Declaration": + case "Refinement": + throw new Error(getASTUnsupportedSchemaErrorMessage(ast)); + case "Transformation": { + if (isTypeLiteralTransformation(ast.transformation) && ast.transformation.propertySignatureTransformations.every(isRenamingPropertySignatureTransformation)) { + return new Transformation(required(ast.from), required(ast.to), ast.transformation); + } + throw new Error(getASTUnsupportedSchemaErrorMessage(ast)); } - } catch {} - return stringifyCircular(u); + } + return ast; }; -var locationRegex = /\((.*)\)/g; -var spanToTrace = /* @__PURE__ */ globalValue("effect/Tracer/spanToTrace", () => new WeakMap); -var prettyErrorStack = (message, stack, span2) => { - const out = [message]; - const lines = stack.startsWith(message) ? stack.slice(message.length).split(` -`) : stack.split(` -`); - for (let i = 1;i < lines.length; i++) { - if (lines[i].includes(" at new BaseEffectError") || lines[i].includes(" at new YieldableError")) { - i++; - continue; +var mutable = (ast) => { + switch (ast._tag) { + case "TupleType": + return ast.isReadonly === false ? ast : new TupleType(ast.elements, ast.rest, false, ast.annotations); + case "TypeLiteral": { + const propertySignatures = changeMap(ast.propertySignatures, (ps) => ps.isReadonly === false ? ps : new PropertySignature(ps.name, ps.type, ps.isOptional, false, ps.annotations)); + const indexSignatures = changeMap(ast.indexSignatures, (is) => is.isReadonly === false ? is : new IndexSignature(is.parameter, is.type, false)); + return propertySignatures === ast.propertySignatures && indexSignatures === ast.indexSignatures ? ast : new TypeLiteral(propertySignatures, indexSignatures, ast.annotations); } - if (lines[i].includes("Generator.next")) { - break; + case "Union": { + const types = changeMap(ast.types, mutable); + return types === ast.types ? ast : Union.make(types, ast.annotations); } - if (lines[i].includes("effect_internal_function")) { - break; + case "Suspend": + return new Suspend(() => mutable(ast.f()), ast.annotations); + case "Refinement": { + const from = mutable(ast.from); + return from === ast.from ? ast : new Refinement(from, ast.filter, ast.annotations); + } + case "Transformation": { + const from = mutable(ast.from); + const to = mutable(ast.to); + return from === ast.from && to === ast.to ? ast : new Transformation(from, to, ast.transformation, ast.annotations); } - out.push(lines[i].replace(/at .*effect_instruction_i.*\((.*)\)/, "at $1").replace(/EffectPrimitive\.\w+/, "")); } - if (span2) { - let current = span2; - let i = 0; - while (current && current._tag === "Span" && i < 10) { - const stackFn = spanToTrace.get(current); - if (typeof stackFn === "function") { - const stack2 = stackFn(); - if (typeof stack2 === "string") { - const locationMatchAll = stack2.matchAll(locationRegex); - let match6 = false; - for (const [, location] of locationMatchAll) { - match6 = true; - out.push(` at ${current.name} (${location})`); - } - if (!match6) { - out.push(` at ${current.name} (${stack2.replace(/^at /, "")})`); - } - } else { - out.push(` at ${current.name}`); - } - } else { - out.push(` at ${current.name}`); + return ast; +}; +var pickAnnotations = (annotationIds) => (annotated) => { + let out = undefined; + for (const id of annotationIds) { + if (Object.prototype.hasOwnProperty.call(annotated.annotations, id)) { + if (out === undefined) { + out = {}; } - current = getOrUndefined(current.parent); - i++; + out[id] = annotated.annotations[id]; } } - return out.join(` -`); -}; -var spanSymbol = /* @__PURE__ */ Symbol.for("effect/SpanAnnotation"); -var prettyErrors = (cause) => reduceWithContext(cause, undefined, { - emptyCase: () => [], - dieCase: (_, unknownError) => { - return [makePrettyError(unknownError)]; - }, - failCase: (_, error) => { - return [makePrettyError(error)]; - }, - interruptCase: () => [], - parallelCase: (_, l, r) => [...l, ...r], - sequentialCase: (_, l, r) => [...l, ...r] -}); - -// node_modules/effect/dist/esm/internal/opCodes/deferred.js -var OP_STATE_PENDING = "Pending"; -var OP_STATE_DONE = "Done"; - -// node_modules/effect/dist/esm/internal/deferred.js -var DeferredSymbolKey = "effect/Deferred"; -var DeferredTypeId = /* @__PURE__ */ Symbol.for(DeferredSymbolKey); -var deferredVariance = { - _E: (_) => _, - _A: (_) => _ -}; -var pending = (joiners) => { - return { - _tag: OP_STATE_PENDING, - joiners - }; + return out; }; -var done = (effect) => { - return { - _tag: OP_STATE_DONE, - effect +var omitAnnotations = (annotationIds) => (annotated) => { + const out = { + ...annotated.annotations }; -}; - -// node_modules/effect/dist/esm/internal/singleShotGen.js -class SingleShotGen2 { - self; - called = false; - constructor(self) { - this.self = self; - } - next(a) { - return this.called ? { - value: a, - done: true - } : (this.called = true, { - value: this.self, - done: false - }); - } - return(a) { - return { - value: a, - done: true - }; - } - throw(e) { - throw e; - } - [Symbol.iterator]() { - return new SingleShotGen2(this.self); + for (const id of annotationIds) { + delete out[id]; } -} - -// node_modules/effect/dist/esm/internal/core.js -var blocked = (blockedRequests, _continue) => { - const effect = new EffectPrimitive("Blocked"); - effect.effect_instruction_i0 = blockedRequests; - effect.effect_instruction_i1 = _continue; - return effect; + return out; }; -var runRequestBlock = (blockedRequests) => { - const effect = new EffectPrimitive("RunBlocked"); - effect.effect_instruction_i0 = blockedRequests; - return effect; +var preserveTransformationAnnotations = /* @__PURE__ */ pickAnnotations([ExamplesAnnotationId, DefaultAnnotationId, JSONSchemaAnnotationId, ArbitraryAnnotationId, PrettyAnnotationId, EquivalenceAnnotationId]); +var typeAST = (ast) => { + switch (ast._tag) { + case "Declaration": { + const typeParameters = changeMap(ast.typeParameters, typeAST); + return typeParameters === ast.typeParameters ? ast : new Declaration(typeParameters, ast.decodeUnknown, ast.encodeUnknown, ast.annotations); + } + case "TupleType": { + const elements = changeMap(ast.elements, (e) => { + const type = typeAST(e.type); + return type === e.type ? e : new OptionalType(type, e.isOptional); + }); + const restASTs = getRestASTs(ast.rest); + const rest = changeMap(restASTs, typeAST); + return elements === ast.elements && rest === restASTs ? ast : new TupleType(elements, rest.map((type) => new Type(type)), ast.isReadonly, ast.annotations); + } + case "TypeLiteral": { + const propertySignatures = changeMap(ast.propertySignatures, (p) => { + const type = typeAST(p.type); + return type === p.type ? p : new PropertySignature(p.name, type, p.isOptional, p.isReadonly); + }); + const indexSignatures = changeMap(ast.indexSignatures, (is) => { + const type = typeAST(is.type); + return type === is.type ? is : new IndexSignature(is.parameter, type, is.isReadonly); + }); + return propertySignatures === ast.propertySignatures && indexSignatures === ast.indexSignatures ? ast : new TypeLiteral(propertySignatures, indexSignatures, ast.annotations); + } + case "Union": { + const types = changeMap(ast.types, typeAST); + return types === ast.types ? ast : Union.make(types, ast.annotations); + } + case "Suspend": + return new Suspend(() => typeAST(ast.f()), ast.annotations); + case "Refinement": { + const from = typeAST(ast.from); + return from === ast.from ? ast : new Refinement(from, ast.filter, ast.annotations); + } + case "Transformation": { + const preserve = preserveTransformationAnnotations(ast); + return typeAST(preserve !== undefined ? annotations(ast.to, preserve) : ast.to); + } + } + return ast; }; -var EffectTypeId2 = /* @__PURE__ */ Symbol.for("effect/Effect"); - -class RevertFlags { - patch; - op; - _op = OP_REVERT_FLAGS; - constructor(patch5, op) { - this.patch = patch5; - this.op = op; +function changeMap(as, f) { + let changed = false; + const out = allocate(as.length); + for (let i = 0;i < as.length; i++) { + const a = as[i]; + const fa = f(a); + if (fa !== a) { + changed = true; + } + out[i] = fa; } + return changed ? out : as; } - -class EffectPrimitive { - _op; - effect_instruction_i0 = undefined; - effect_instruction_i1 = undefined; - effect_instruction_i2 = undefined; - trace = undefined; - [EffectTypeId2] = effectVariance; - constructor(_op) { - this._op = _op; - } - [symbol2](that) { - return this === that; - } - [symbol]() { - return cached(this, random(this)); - } - pipe() { - return pipeArguments(this, arguments); - } - toJSON() { - return { - _id: "Effect", - _op: this._op, - effect_instruction_i0: toJSON(this.effect_instruction_i0), - effect_instruction_i1: toJSON(this.effect_instruction_i1), - effect_instruction_i2: toJSON(this.effect_instruction_i2) - }; +var getTransformationFrom = (ast) => { + switch (ast._tag) { + case "Transformation": + return ast.from; + case "Refinement": + return getTransformationFrom(ast.from); + case "Suspend": + return getTransformationFrom(ast.f()); } - toString() { - return format(this.toJSON()); +}; +var encodedAST_ = (ast, isBound) => { + switch (ast._tag) { + case "Declaration": { + const typeParameters = changeMap(ast.typeParameters, (ast2) => encodedAST_(ast2, isBound)); + return typeParameters === ast.typeParameters ? ast : new Declaration(typeParameters, ast.decodeUnknown, ast.encodeUnknown); + } + case "TupleType": { + const elements = changeMap(ast.elements, (e) => { + const type = encodedAST_(e.type, isBound); + return type === e.type ? e : new OptionalType(type, e.isOptional); + }); + const restASTs = getRestASTs(ast.rest); + const rest = changeMap(restASTs, (ast2) => encodedAST_(ast2, isBound)); + return elements === ast.elements && rest === restASTs ? ast : new TupleType(elements, rest.map((ast2) => new Type(ast2)), ast.isReadonly); + } + case "TypeLiteral": { + const propertySignatures = changeMap(ast.propertySignatures, (ps) => { + const type = encodedAST_(ps.type, isBound); + return type === ps.type ? ps : new PropertySignature(ps.name, type, ps.isOptional, ps.isReadonly); + }); + const indexSignatures = changeMap(ast.indexSignatures, (is) => { + const type = encodedAST_(is.type, isBound); + return type === is.type ? is : new IndexSignature(is.parameter, type, is.isReadonly); + }); + return propertySignatures === ast.propertySignatures && indexSignatures === ast.indexSignatures ? ast : new TypeLiteral(propertySignatures, indexSignatures); + } + case "Union": { + const types = changeMap(ast.types, (ast2) => encodedAST_(ast2, isBound)); + return types === ast.types ? ast : Union.make(types); + } + case "Suspend": { + let borrowedAnnotations = undefined; + const identifier = getJSONIdentifier(ast); + if (isSome2(identifier)) { + const suffix = isBound ? "Bound" : ""; + borrowedAnnotations = { + [JSONIdentifierAnnotationId]: `${identifier.value}Encoded${suffix}` + }; + } + return new Suspend(() => encodedAST_(ast.f(), isBound), borrowedAnnotations); + } + case "Refinement": { + const from = encodedAST_(ast.from, isBound); + if (isBound) { + if (from === ast.from) + return ast; + if (getTransformationFrom(ast.from) === undefined && hasStableFilter(ast)) { + return new Refinement(from, ast.filter, ast.annotations); + } + return from; + } else { + return from; + } + } + case "Transformation": + return encodedAST_(ast.from, isBound); } - [NodeInspectSymbol]() { - return this.toJSON(); + return ast; +}; +var encodedAST = (ast) => encodedAST_(ast, false); +var encodedBoundAST = (ast) => encodedAST_(ast, true); +var toJSONAnnotations = (annotations2) => { + const out = {}; + for (const k of Object.getOwnPropertySymbols(annotations2)) { + out[String(k)] = annotations2[k]; } - [Symbol.iterator]() { - return new SingleShotGen2(new YieldWrap(this)); + return out; +}; +var getEncodedParameter = (ast) => { + switch (ast._tag) { + case "StringKeyword": + case "SymbolKeyword": + case "TemplateLiteral": + return ast; + case "Refinement": + return getEncodedParameter(ast.from); } -} - -class EffectPrimitiveFailure { - _op; - effect_instruction_i0 = undefined; - effect_instruction_i1 = undefined; - effect_instruction_i2 = undefined; - trace = undefined; - [EffectTypeId2] = effectVariance; - constructor(_op) { - this._op = _op; - this._tag = _op; - } - [symbol2](that) { - return exitIsExit(that) && that._op === "Failure" && equals(this.effect_instruction_i0, that.effect_instruction_i0); +}; +var equals2 = (self, that) => { + switch (self._tag) { + case "Literal": + return isLiteral(that) && that.literal === self.literal; + case "UniqueSymbol": + return isUniqueSymbol(that) && that.symbol === self.symbol; + case "UndefinedKeyword": + case "VoidKeyword": + case "NeverKeyword": + case "UnknownKeyword": + case "AnyKeyword": + case "StringKeyword": + case "NumberKeyword": + case "BooleanKeyword": + case "BigIntKeyword": + case "SymbolKeyword": + case "ObjectKeyword": + return that._tag === self._tag; + case "TemplateLiteral": + return isTemplateLiteral(that) && that.head === self.head && equalsTemplateLiteralSpan(that.spans, self.spans); + case "Enums": + return isEnums(that) && equalsEnums(that.enums, self.enums); + case "Union": + return isUnion(that) && equalsUnion(self.types, that.types); + case "Refinement": + case "TupleType": + case "TypeLiteral": + case "Suspend": + case "Transformation": + case "Declaration": + return self === that; } - [symbol]() { - return pipe(string(this._tag), combine(hash(this.effect_instruction_i0)), cached(this)); +}; +var equalsTemplateLiteralSpan = /* @__PURE__ */ getEquivalence3((self, that) => { + return self.literal === that.literal && equals2(self.type, that.type); +}); +var equalsEnums = /* @__PURE__ */ getEquivalence3((self, that) => that[0] === self[0] && that[1] === self[1]); +var equalsUnion = /* @__PURE__ */ getEquivalence3(equals2); +var intersection2 = /* @__PURE__ */ intersectionWith(equals2); +var _keyof = (ast) => { + switch (ast._tag) { + case "Declaration": { + const annotation = getSurrogateAnnotation(ast); + if (isSome2(annotation)) { + return _keyof(annotation.value); + } + break; + } + case "TypeLiteral": + return ast.propertySignatures.map((p) => isSymbol(p.name) ? new UniqueSymbol(p.name) : new Literal(p.name)).concat(ast.indexSignatures.map((is) => getEncodedParameter(is.parameter))); + case "Suspend": + return _keyof(ast.f()); + case "Union": + return ast.types.slice(1).reduce((out, ast2) => intersection2(out, _keyof(ast2)), _keyof(ast.types[0])); + case "Transformation": + return _keyof(ast.to); } - get cause() { - return this.effect_instruction_i0; + throw new Error(getASTUnsupportedSchemaErrorMessage(ast)); +}; +var compose = (ab, cd) => new Transformation(ab, cd, composeTransformation); +var rename = (ast, mapping) => { + switch (ast._tag) { + case "TypeLiteral": { + const propertySignatureTransformations = []; + for (const key of Reflect.ownKeys(mapping)) { + const name = mapping[key]; + if (name !== undefined) { + propertySignatureTransformations.push(new PropertySignatureTransformation(key, name, identity, identity)); + } + } + if (propertySignatureTransformations.length === 0) { + return ast; + } + return new Transformation(ast, new TypeLiteral(ast.propertySignatures.map((ps) => { + const name = mapping[ps.name]; + return new PropertySignature(name === undefined ? ps.name : name, typeAST(ps.type), ps.isOptional, ps.isReadonly, ps.annotations); + }), ast.indexSignatures), new TypeLiteralTransformation(propertySignatureTransformations)); + } + case "Union": + return Union.make(ast.types.map((ast2) => rename(ast2, mapping))); + case "Suspend": + return new Suspend(() => rename(ast.f(), mapping)); + case "Transformation": + return compose(ast, rename(typeAST(ast), mapping)); } - pipe() { - return pipeArguments(this, arguments); + throw new Error(getASTUnsupportedRenameSchemaErrorMessage(ast)); +}; +var formatKeyword = (ast) => getOrElse(getExpected(ast), () => ast._tag); +function getBrands(ast) { + return match2(getBrandAnnotation(ast), { + onNone: () => "", + onSome: (brands) => brands.map((brand) => ` & Brand<${formatUnknown(brand)}>`).join("") + }); +} +var getOrElseExpected = (ast) => getTitleAnnotation(ast).pipe(orElse(() => getDescriptionAnnotation(ast)), orElse(() => getAutoTitleAnnotation(ast)), map2((s) => s + getBrands(ast))); +var getExpected = (ast) => orElse(getIdentifierAnnotation(ast), () => getOrElseExpected(ast)); +var pruneUndefined = (ast, self, onTransformation) => { + switch (ast._tag) { + case "UndefinedKeyword": + return neverKeyword; + case "Union": { + const types = []; + let hasUndefined = false; + for (const type of ast.types) { + const pruned = self(type); + if (pruned) { + hasUndefined = true; + if (!isNeverKeyword(pruned)) { + types.push(pruned); + } + } else { + types.push(type); + } + } + if (hasUndefined) { + return Union.make(types); + } + break; + } + case "Suspend": + return self(ast.f()); + case "Transformation": + return onTransformation(ast); } +}; +// node_modules/effect/dist/esm/BigDecimal.js +var FINITE_INT_REGEX = /^[+-]?\d+$/; +var TypeId3 = /* @__PURE__ */ Symbol.for("effect/BigDecimal"); +var BigDecimalProto = { + [TypeId3]: TypeId3, + [symbol]() { + const normalized = normalize(this); + return pipe(hash(normalized.value), combine(number2(normalized.scale)), cached(this)); + }, + [symbol2](that) { + return isBigDecimal(that) && equals3(this, that); + }, + toString() { + return `BigDecimal(${format2(this)})`; + }, toJSON() { return { - _id: "Exit", - _tag: this._op, - cause: this.cause.toJSON() + _id: "BigDecimal", + value: String(this.value), + scale: this.scale }; - } - toString() { - return format(this.toJSON()); - } + }, [NodeInspectSymbol]() { return this.toJSON(); + }, + pipe() { + return pipeArguments(this, arguments); } - [Symbol.iterator]() { - return new SingleShotGen2(new YieldWrap(this)); - } -} - -class EffectPrimitiveSuccess { - _op; - effect_instruction_i0 = undefined; - effect_instruction_i1 = undefined; - effect_instruction_i2 = undefined; - trace = undefined; - [EffectTypeId2] = effectVariance; - constructor(_op) { - this._op = _op; - this._tag = _op; +}; +var isBigDecimal = (u) => hasProperty(u, TypeId3); +var make4 = (value, scale) => { + const o = Object.create(BigDecimalProto); + o.value = value; + o.scale = scale; + return o; +}; +var unsafeMakeNormalized = (value, scale) => { + if (value !== bigint0 && value % bigint10 === bigint0) { + throw new RangeError("Value must be normalized"); } - [symbol2](that) { - return exitIsExit(that) && that._op === "Success" && equals(this.effect_instruction_i0, that.effect_instruction_i0); + const o = make4(value, scale); + o.normalized = o; + return o; +}; +var bigint0 = /* @__PURE__ */ BigInt(0); +var bigint10 = /* @__PURE__ */ BigInt(10); +var zero = /* @__PURE__ */ unsafeMakeNormalized(bigint0, 0); +var normalize = (self) => { + if (self.normalized === undefined) { + if (self.value === bigint0) { + self.normalized = zero; + } else { + const digits = `${self.value}`; + let trail = 0; + for (let i = digits.length - 1;i >= 0; i--) { + if (digits[i] === "0") { + trail++; + } else { + break; + } + } + if (trail === 0) { + self.normalized = self; + } + const value = BigInt(digits.substring(0, digits.length - trail)); + const scale = self.scale - trail; + self.normalized = unsafeMakeNormalized(value, scale); + } } - [symbol]() { - return pipe(string(this._tag), combine(hash(this.effect_instruction_i0)), cached(this)); + return self.normalized; +}; +var scale = /* @__PURE__ */ dual(2, (self, scale2) => { + if (scale2 > self.scale) { + return make4(self.value * bigint10 ** BigInt(scale2 - self.scale), scale2); } - get value() { - return this.effect_instruction_i0; + if (scale2 < self.scale) { + return make4(self.value / bigint10 ** BigInt(self.scale - scale2), scale2); } - pipe() { - return pipeArguments(this, arguments); + return self; +}); +var Order2 = /* @__PURE__ */ make2((self, that) => { + const scmp = number3(sign(self), sign(that)); + if (scmp !== 0) { + return scmp; } - toJSON() { - return { - _id: "Exit", - _tag: this._op, - value: toJSON(this.value) - }; + if (self.scale > that.scale) { + return bigint(self.value, scale(that, self.scale).value); } - toString() { - return format(this.toJSON()); + if (self.scale < that.scale) { + return bigint(scale(self, that.scale).value, that.value); } - [NodeInspectSymbol]() { - return this.toJSON(); + return bigint(self.value, that.value); +}); +var lessThan2 = /* @__PURE__ */ lessThan(Order2); +var lessThanOrEqualTo2 = /* @__PURE__ */ lessThanOrEqualTo(Order2); +var greaterThan2 = /* @__PURE__ */ greaterThan(Order2); +var greaterThanOrEqualTo2 = /* @__PURE__ */ greaterThanOrEqualTo(Order2); +var between2 = /* @__PURE__ */ between(Order2); +var clamp4 = /* @__PURE__ */ clamp(Order2); +var sign = (n) => n.value === bigint0 ? 0 : n.value < bigint0 ? -1 : 1; +var abs = (n) => n.value < bigint0 ? make4(-n.value, n.scale) : n; +var Equivalence = /* @__PURE__ */ make((self, that) => { + if (self.scale > that.scale) { + return scale(that, self.scale).value === self.value; } - [Symbol.iterator]() { - return new SingleShotGen2(new YieldWrap(this)); + if (self.scale < that.scale) { + return scale(self, that.scale).value === that.value; } -} -var isEffect = (u) => hasProperty(u, EffectTypeId2); -var withFiberRuntime = (withRuntime) => { - const effect = new EffectPrimitive(OP_WITH_RUNTIME); - effect.effect_instruction_i0 = withRuntime; - return effect; + return self.value === that.value; +}); +var equals3 = /* @__PURE__ */ dual(2, (self, that) => Equivalence(self, that)); +var unsafeFromNumber = (n) => getOrThrowWith2(safeFromNumber(n), () => new RangeError(`Number must be finite, got ${n}`)); +var safeFromNumber = (n) => { + if (!Number.isFinite(n)) { + return none2(); + } + const string2 = `${n}`; + if (string2.includes("e")) { + return fromString(string2); + } + const [lead, trail = ""] = string2.split("."); + return some2(make4(BigInt(`${lead}${trail}`), trail.length)); }; -var acquireUseRelease = /* @__PURE__ */ dual(3, (acquire, use, release) => uninterruptibleMask((restore) => flatMap7(acquire, (a) => flatMap7(exit(suspend(() => restore(use(a)))), (exit) => { - return suspend(() => release(a, exit)).pipe(matchCauseEffect({ - onFailure: (cause) => { - switch (exit._tag) { - case OP_FAILURE: - return failCause(sequential(exit.effect_instruction_i0, cause)); - case OP_SUCCESS: - return failCause(cause); - } - }, - onSuccess: () => exit - })); -})))); -var as = /* @__PURE__ */ dual(2, (self, value) => flatMap7(self, () => succeed(value))); -var asVoid = (self) => as(self, undefined); -var custom = function() { - const wrapper = new EffectPrimitive(OP_COMMIT); - switch (arguments.length) { - case 2: { - wrapper.effect_instruction_i0 = arguments[0]; - wrapper.commit = arguments[1]; - break; - } - case 3: { - wrapper.effect_instruction_i0 = arguments[0]; - wrapper.effect_instruction_i1 = arguments[1]; - wrapper.commit = arguments[2]; - break; - } - case 4: { - wrapper.effect_instruction_i0 = arguments[0]; - wrapper.effect_instruction_i1 = arguments[1]; - wrapper.effect_instruction_i2 = arguments[2]; - wrapper.commit = arguments[3]; - break; - } - default: { - throw new Error(getBugErrorMessage("you're not supposed to end up here")); +var fromString = (s) => { + if (s === "") { + return some2(zero); + } + let base; + let exp; + const seperator = s.search(/[eE]/); + if (seperator !== -1) { + const trail = s.slice(seperator + 1); + base = s.slice(0, seperator); + exp = Number(trail); + if (base === "" || !Number.isSafeInteger(exp) || !FINITE_INT_REGEX.test(trail)) { + return none2(); } + } else { + base = s; + exp = 0; } - return wrapper; -}; -var unsafeAsync = (register, blockingOn = none4) => { - const effect = new EffectPrimitive(OP_ASYNC); - let cancelerRef = undefined; - effect.effect_instruction_i0 = (resume) => { - cancelerRef = register(resume); - }; - effect.effect_instruction_i1 = blockingOn; - return onInterrupt(effect, (_) => isEffect(cancelerRef) ? cancelerRef : void_); + let digits; + let offset; + const dot = base.search(/\./); + if (dot !== -1) { + const lead = base.slice(0, dot); + const trail = base.slice(dot + 1); + digits = `${lead}${trail}`; + offset = trail.length; + } else { + digits = base; + offset = 0; + } + if (!FINITE_INT_REGEX.test(digits)) { + return none2(); + } + const scale2 = offset - exp; + if (!Number.isSafeInteger(scale2)) { + return none2(); + } + return some2(make4(BigInt(digits), scale2)); }; -var asyncInterrupt = (register, blockingOn = none4) => suspend(() => unsafeAsync(register, blockingOn)); -var async_ = (resume, blockingOn = none4) => { - return custom(resume, function() { - let backingResume = undefined; - let pendingEffect = undefined; - function proxyResume(effect2) { - if (backingResume) { - backingResume(effect2); - } else if (pendingEffect === undefined) { - pendingEffect = effect2; - } - } - const effect = new EffectPrimitive(OP_ASYNC); - effect.effect_instruction_i0 = (resume2) => { - backingResume = resume2; - if (pendingEffect) { - resume2(pendingEffect); - } - }; - effect.effect_instruction_i1 = blockingOn; - let cancelerRef = undefined; - let controllerRef = undefined; - if (this.effect_instruction_i0.length !== 1) { - controllerRef = new AbortController; - cancelerRef = internalCall(() => this.effect_instruction_i0(proxyResume, controllerRef.signal)); +var format2 = (n) => { + const normalized = normalize(n); + if (Math.abs(normalized.scale) >= 16) { + return toExponential(normalized); + } + const negative = normalized.value < bigint0; + const absolute = negative ? `${normalized.value}`.substring(1) : `${normalized.value}`; + let before; + let after; + if (normalized.scale >= absolute.length) { + before = "0"; + after = "0".repeat(normalized.scale - absolute.length) + absolute; + } else { + const location = absolute.length - normalized.scale; + if (location > absolute.length) { + const zeros = location - absolute.length; + before = `${absolute}${"0".repeat(zeros)}`; + after = ""; } else { - cancelerRef = internalCall(() => this.effect_instruction_i0(proxyResume)); + after = absolute.slice(location); + before = absolute.slice(0, location); } - return cancelerRef || controllerRef ? onInterrupt(effect, (_) => { - if (controllerRef) { - controllerRef.abort(); - } - return cancelerRef ?? void_; - }) : effect; - }); + } + const complete = after === "" ? before : `${before}.${after}`; + return negative ? `-${complete}` : complete; }; -var catchAllCause = /* @__PURE__ */ dual(2, (self, f) => { - const effect = new EffectPrimitive(OP_ON_FAILURE); - effect.effect_instruction_i0 = self; - effect.effect_instruction_i1 = f; - return effect; -}); -var catchAll = /* @__PURE__ */ dual(2, (self, f) => matchEffect(self, { - onFailure: f, - onSuccess: succeed -})); -var catchIf = /* @__PURE__ */ dual(3, (self, predicate, f) => catchAllCause(self, (cause) => { - const either2 = failureOrCause(cause); - switch (either2._tag) { - case "Left": - return predicate(either2.left) ? f(either2.left) : failCause(cause); - case "Right": - return failCause(either2.right); +var toExponential = (n) => { + if (isZero(n)) { + return "0e+0"; } -})); -var catchSome = /* @__PURE__ */ dual(2, (self, pf) => catchAllCause(self, (cause) => { - const either2 = failureOrCause(cause); - switch (either2._tag) { - case "Left": - return pipe(pf(either2.left), getOrElse(() => failCause(cause))); - case "Right": - return failCause(either2.right); + const normalized = normalize(n); + const digits = `${abs(normalized).value}`; + const head2 = digits.slice(0, 1); + const tail = digits.slice(1); + let output = `${isNegative(normalized) ? "-" : ""}${head2}`; + if (tail !== "") { + output += `.${tail}`; } -})); -var checkInterruptible = (f) => withFiberRuntime((_, status) => f(interruption(status.runtimeFlags))); -var originalSymbol = /* @__PURE__ */ Symbol.for("effect/OriginalAnnotation"); -var capture = (obj, span2) => { - if (isSome2(span2)) { - return new Proxy(obj, { - has(target, p) { - return p === spanSymbol || p === originalSymbol || p in target; - }, - get(target, p) { - if (p === spanSymbol) { - return span2.value; - } - if (p === originalSymbol) { - return obj; - } - return target[p]; - } - }); + const exp = tail.length - normalized.scale; + return `${output}e${exp >= 0 ? "+" : ""}${exp}`; +}; +var unsafeToNumber = (n) => Number(format2(n)); +var isZero = (n) => n.value === bigint0; +var isNegative = (n) => n.value < bigint0; +var isPositive = (n) => n.value > bigint0; +// node_modules/effect/dist/esm/BigInt.js +var Order3 = bigint; +var clamp5 = /* @__PURE__ */ clamp(Order3); +var toNumber = (b) => { + if (b > BigInt(Number.MAX_SAFE_INTEGER) || b < BigInt(Number.MIN_SAFE_INTEGER)) { + return none2(); } - return obj; + return some2(Number(b)); }; -var die2 = (defect) => isObject(defect) && !(spanSymbol in defect) ? withFiberRuntime((fiber) => failCause(die(capture(defect, currentSpanFromFiber(fiber))))) : failCause(die(defect)); -var dieMessage = (message) => failCauseSync(() => die(new RuntimeException(message))); -var dieSync = (evaluate) => flatMap7(sync(evaluate), die2); -var either2 = (self) => matchEffect(self, { - onFailure: (e) => succeed(left2(e)), - onSuccess: (a) => succeed(right2(a)) -}); -var exit = (self) => matchCause(self, { - onFailure: exitFailCause, - onSuccess: exitSucceed -}); -var fail2 = (error) => isObject(error) && !(spanSymbol in error) ? withFiberRuntime((fiber) => failCause(fail(capture(error, currentSpanFromFiber(fiber))))) : failCause(fail(error)); -var failSync = (evaluate) => flatMap7(sync(evaluate), fail2); -var failCause = (cause) => { - const effect = new EffectPrimitiveFailure(OP_FAILURE); - effect.effect_instruction_i0 = cause; - return effect; +var fromString2 = (s) => { + try { + return s.trim() === "" ? none2() : some2(BigInt(s)); + } catch { + return none2(); + } }; -var failCauseSync = (evaluate) => flatMap7(sync(evaluate), failCause); -var fiberId = /* @__PURE__ */ withFiberRuntime((state) => succeed(state.id())); -var fiberIdWith = (f) => withFiberRuntime((state) => f(state.id())); -var flatMap7 = /* @__PURE__ */ dual(2, (self, f) => { - const effect = new EffectPrimitive(OP_ON_SUCCESS); - effect.effect_instruction_i0 = self; - effect.effect_instruction_i1 = f; - return effect; -}); -var andThen2 = /* @__PURE__ */ dual(2, (self, f) => flatMap7(self, (a) => { - const b = typeof f === "function" ? f(a) : f; - if (isEffect(b)) { - return b; - } else if (isPromiseLike(b)) { - return unsafeAsync((resume) => { - b.then((a2) => resume(succeed(a2)), (e) => resume(fail2(new UnknownException(e, "An unknown error occurred in Effect.andThen")))); - }); +var fromNumber = (n) => { + if (n > Number.MAX_SAFE_INTEGER || n < Number.MIN_SAFE_INTEGER) { + return none2(); + } + try { + return some2(BigInt(n)); + } catch { + return none2(); } - return succeed(b); -})); -var step2 = (self) => { - const effect = new EffectPrimitive("OnStep"); - effect.effect_instruction_i0 = self; - return effect; }; -var flatten4 = (self) => flatMap7(self, identity); -var flip = (self) => matchEffect(self, { - onFailure: succeed, - onSuccess: fail2 -}); -var matchCause = /* @__PURE__ */ dual(2, (self, options) => matchCauseEffect(self, { - onFailure: (cause) => succeed(options.onFailure(cause)), - onSuccess: (a) => succeed(options.onSuccess(a)) -})); -var matchCauseEffect = /* @__PURE__ */ dual(2, (self, options) => { - const effect = new EffectPrimitive(OP_ON_SUCCESS_AND_FAILURE); - effect.effect_instruction_i0 = self; - effect.effect_instruction_i1 = options.onFailure; - effect.effect_instruction_i2 = options.onSuccess; - return effect; -}); -var matchEffect = /* @__PURE__ */ dual(2, (self, options) => matchCauseEffect(self, { - onFailure: (cause) => { - const defects2 = defects(cause); - if (defects2.length > 0) { - return failCause(electFailures(cause)); - } - const failures2 = failures(cause); - if (failures2.length > 0) { - return options.onFailure(unsafeHead(failures2)); - } - return failCause(cause); +// node_modules/effect/dist/esm/Boolean.js +var not = (self) => !self; +// node_modules/effect/dist/esm/internal/context.js +var TagTypeId = /* @__PURE__ */ Symbol.for("effect/Context/Tag"); +var ReferenceTypeId = /* @__PURE__ */ Symbol.for("effect/Context/Reference"); +var STMSymbolKey = "effect/STM"; +var STMTypeId = /* @__PURE__ */ Symbol.for(STMSymbolKey); +var TagProto = { + ...EffectPrototype, + _op: "Tag", + [STMTypeId]: effectVariance, + [TagTypeId]: { + _Service: (_) => _, + _Identifier: (_) => _ }, - onSuccess: options.onSuccess -})); -var forEachSequential = /* @__PURE__ */ dual(2, (self, f) => suspend(() => { - const arr = fromIterable(self); - const ret = allocate(arr.length); - let i = 0; - return as(whileLoop({ - while: () => i < arr.length, - body: () => f(arr[i], i), - step: (b) => { - ret[i++] = b; + toString() { + return format(this.toJSON()); + }, + toJSON() { + return { + _id: "Tag", + key: this.key, + stack: this.stack + }; + }, + [NodeInspectSymbol]() { + return this.toJSON(); + }, + of(self) { + return self; + }, + context(self) { + return make5(this, self); + } +}; +var ReferenceProto = { + ...TagProto, + [ReferenceTypeId]: ReferenceTypeId +}; +var makeGenericTag = (key) => { + const limit = Error.stackTraceLimit; + Error.stackTraceLimit = 2; + const creationError = new Error; + Error.stackTraceLimit = limit; + const tag = Object.create(TagProto); + Object.defineProperty(tag, "stack", { + get() { + return creationError.stack; } - }), ret); -})); -var forEachSequentialDiscard = /* @__PURE__ */ dual(2, (self, f) => suspend(() => { - const arr = fromIterable(self); - let i = 0; - return whileLoop({ - while: () => i < arr.length, - body: () => f(arr[i], i), - step: () => { - i++; + }); + tag.key = key; + return tag; +}; +var Reference = () => (id, options) => { + const limit = Error.stackTraceLimit; + Error.stackTraceLimit = 2; + const creationError = new Error; + Error.stackTraceLimit = limit; + function ReferenceClass() {} + Object.setPrototypeOf(ReferenceClass, ReferenceProto); + ReferenceClass.key = id; + ReferenceClass.defaultValue = options.defaultValue; + Object.defineProperty(ReferenceClass, "stack", { + get() { + return creationError.stack; } }); -})); -var if_ = /* @__PURE__ */ dual((args) => typeof args[0] === "boolean" || isEffect(args[0]), (self, options) => isEffect(self) ? flatMap7(self, (b) => b ? options.onTrue() : options.onFalse()) : self ? options.onTrue() : options.onFalse()); -var interrupt2 = /* @__PURE__ */ flatMap7(fiberId, (fiberId2) => interruptWith(fiberId2)); -var interruptWith = (fiberId2) => failCause(interrupt(fiberId2)); -var interruptible2 = (self) => { - const effect = new EffectPrimitive(OP_UPDATE_RUNTIME_FLAGS); - effect.effect_instruction_i0 = enable3(Interruption); - effect.effect_instruction_i1 = () => self; - return effect; + return ReferenceClass; }; -var interruptibleMask = (f) => custom(f, function() { - const effect = new EffectPrimitive(OP_UPDATE_RUNTIME_FLAGS); - effect.effect_instruction_i0 = enable3(Interruption); - effect.effect_instruction_i1 = (oldFlags) => interruption(oldFlags) ? internalCall(() => this.effect_instruction_i0(interruptible2)) : internalCall(() => this.effect_instruction_i0(uninterruptible)); - return effect; -}); -var intoDeferred = /* @__PURE__ */ dual(2, (self, deferred) => uninterruptibleMask((restore) => flatMap7(exit(restore(self)), (exit2) => deferredDone(deferred, exit2)))); -var map9 = /* @__PURE__ */ dual(2, (self, f) => flatMap7(self, (a) => sync(() => f(a)))); -var mapBoth2 = /* @__PURE__ */ dual(2, (self, options) => matchEffect(self, { - onFailure: (e) => failSync(() => options.onFailure(e)), - onSuccess: (a) => sync(() => options.onSuccess(a)) -})); -var mapError = /* @__PURE__ */ dual(2, (self, f) => matchCauseEffect(self, { - onFailure: (cause) => { - const either3 = failureOrCause(cause); - switch (either3._tag) { - case "Left": { - return failSync(() => f(either3.left)); - } - case "Right": { - return failCause(either3.right); +var TypeId4 = /* @__PURE__ */ Symbol.for("effect/Context"); +var ContextProto = { + [TypeId4]: { + _Services: (_) => _ + }, + [symbol2](that) { + if (isContext(that)) { + if (this.unsafeMap.size === that.unsafeMap.size) { + for (const k of this.unsafeMap.keys()) { + if (!that.unsafeMap.has(k) || !equals(this.unsafeMap.get(k), that.unsafeMap.get(k))) { + return false; + } + } + return true; } } + return false; }, - onSuccess: succeed -})); -var onError = /* @__PURE__ */ dual(2, (self, cleanup) => onExit(self, (exit2) => exitIsSuccess(exit2) ? void_ : cleanup(exit2.effect_instruction_i0))); -var onExit = /* @__PURE__ */ dual(2, (self, cleanup) => uninterruptibleMask((restore) => matchCauseEffect(restore(self), { - onFailure: (cause1) => { - const result = exitFailCause(cause1); - return matchCauseEffect(cleanup(result), { - onFailure: (cause2) => exitFailCause(sequential(cause1, cause2)), - onSuccess: () => result - }); + [symbol]() { + return cached(this, number2(this.unsafeMap.size)); }, - onSuccess: (success) => { - const result = exitSucceed(success); - return zipRight(cleanup(result), result); + pipe() { + return pipeArguments(this, arguments); + }, + toString() { + return format(this.toJSON()); + }, + toJSON() { + return { + _id: "Context", + services: Array.from(this.unsafeMap).map(toJSON) + }; + }, + [NodeInspectSymbol]() { + return this.toJSON(); } -}))); -var onInterrupt = /* @__PURE__ */ dual(2, (self, cleanup) => onExit(self, exitMatch({ - onFailure: (cause) => isInterruptedOnly(cause) ? asVoid(cleanup(interruptors(cause))) : void_, - onSuccess: () => void_ -}))); -var orElse2 = /* @__PURE__ */ dual(2, (self, that) => attemptOrElse(self, that, succeed)); -var orDie = (self) => orDieWith(self, identity); -var orDieWith = /* @__PURE__ */ dual(2, (self, f) => matchEffect(self, { - onFailure: (e) => die2(f(e)), - onSuccess: succeed -})); -var partitionMap2 = partitionMap; -var runtimeFlags = /* @__PURE__ */ withFiberRuntime((_, status) => succeed(status.runtimeFlags)); -var succeed = (value) => { - const effect = new EffectPrimitiveSuccess(OP_SUCCESS); - effect.effect_instruction_i0 = value; - return effect; }; -var suspend = (evaluate) => { - const effect = new EffectPrimitive(OP_COMMIT); - effect.commit = evaluate; - return effect; -}; -var sync = (thunk) => { - const effect = new EffectPrimitive(OP_SYNC); - effect.effect_instruction_i0 = thunk; - return effect; +var makeContext = (unsafeMap) => { + const context = Object.create(ContextProto); + context.unsafeMap = unsafeMap; + return context; }; -var tap = /* @__PURE__ */ dual((args) => args.length === 3 || args.length === 2 && !(isObject(args[1]) && ("onlyEffect" in args[1])), (self, f) => flatMap7(self, (a) => { - const b = typeof f === "function" ? f(a) : f; - if (isEffect(b)) { - return as(b, a); - } else if (isPromiseLike(b)) { - return unsafeAsync((resume) => { - b.then((_) => resume(succeed(a)), (e) => resume(fail2(new UnknownException(e, "An unknown error occurred in Effect.tap")))); - }); +var serviceNotFoundError = (tag) => { + const error = new Error(`Service not found${tag.key ? `: ${String(tag.key)}` : ""}`); + if (tag.stack) { + const lines = tag.stack.split(` +`); + if (lines.length > 2) { + const afterAt = lines[2].match(/at (.*)/); + if (afterAt) { + error.message = error.message + ` (defined at ${afterAt[1]})`; + } + } } - return succeed(a); -})); -var transplant = (f) => withFiberRuntime((state) => { - const scopeOverride = state.getFiberRef(currentForkScopeOverride); - const scope = pipe(scopeOverride, getOrElse(() => state.scope())); - return f(fiberRefLocally(currentForkScopeOverride, some2(scope))); + if (error.stack) { + const lines = error.stack.split(` +`); + lines.splice(1, 3); + error.stack = lines.join(` +`); + } + return error; +}; +var isContext = (u) => hasProperty(u, TypeId4); +var isTag = (u) => hasProperty(u, TagTypeId); +var isReference = (u) => hasProperty(u, ReferenceTypeId); +var _empty = /* @__PURE__ */ makeContext(/* @__PURE__ */ new Map); +var empty2 = () => _empty; +var make5 = (tag, service) => makeContext(new Map([[tag.key, service]])); +var add = /* @__PURE__ */ dual(3, (self, tag, service) => { + const map4 = new Map(self.unsafeMap); + map4.set(tag.key, service); + return makeContext(map4); }); -var attemptOrElse = /* @__PURE__ */ dual(3, (self, that, onSuccess) => matchCauseEffect(self, { - onFailure: (cause) => { - const defects2 = defects(cause); - if (defects2.length > 0) { - return failCause(getOrThrow2(keepDefectsAndElectFailures(cause))); - } - return that(); - }, - onSuccess -})); -var uninterruptible = (self) => { - const effect = new EffectPrimitive(OP_UPDATE_RUNTIME_FLAGS); - effect.effect_instruction_i0 = disable3(Interruption); - effect.effect_instruction_i1 = () => self; - return effect; -}; -var uninterruptibleMask = (f) => custom(f, function() { - const effect = new EffectPrimitive(OP_UPDATE_RUNTIME_FLAGS); - effect.effect_instruction_i0 = disable3(Interruption); - effect.effect_instruction_i1 = (oldFlags) => interruption(oldFlags) ? internalCall(() => this.effect_instruction_i0(interruptible2)) : internalCall(() => this.effect_instruction_i0(uninterruptible)); - return effect; -}); -var void_ = /* @__PURE__ */ succeed(undefined); -var updateRuntimeFlags = (patch5) => { - const effect = new EffectPrimitive(OP_UPDATE_RUNTIME_FLAGS); - effect.effect_instruction_i0 = patch5; - effect.effect_instruction_i1 = undefined; - return effect; -}; -var whenEffect = /* @__PURE__ */ dual(2, (self, condition) => flatMap7(condition, (b) => { - if (b) { - return pipe(self, map9(some2)); +var defaultValueCache = /* @__PURE__ */ globalValue("effect/Context/defaultValueCache", () => new Map); +var getDefaultValue = (tag) => { + if (defaultValueCache.has(tag.key)) { + return defaultValueCache.get(tag.key); } - return succeed(none2()); -})); -var whileLoop = (options) => { - const effect = new EffectPrimitive(OP_WHILE); - effect.effect_instruction_i0 = options.while; - effect.effect_instruction_i1 = options.body; - effect.effect_instruction_i2 = options.step; - return effect; + const value = tag.defaultValue(); + defaultValueCache.set(tag.key, value); + return value; }; -var fromIterator = (iterator) => suspend(() => { - const effect = new EffectPrimitive(OP_ITERATOR); - effect.effect_instruction_i0 = iterator(); - return effect; -}); -var gen = function() { - const f = arguments.length === 1 ? arguments[0] : arguments[1].bind(arguments[0]); - return fromIterator(() => f(pipe)); +var unsafeGetReference = (self, tag) => { + return self.unsafeMap.has(tag.key) ? self.unsafeMap.get(tag.key) : getDefaultValue(tag); }; -var fnUntraced = (body, ...pipeables) => Object.defineProperty(pipeables.length === 0 ? function(...args) { - return fromIterator(() => body.apply(this, args)); -} : function(...args) { - let effect = fromIterator(() => body.apply(this, args)); - for (const x of pipeables) { - effect = x(effect, ...args); +var unsafeGet2 = /* @__PURE__ */ dual(2, (self, tag) => { + if (!self.unsafeMap.has(tag.key)) { + if (ReferenceTypeId in tag) + return getDefaultValue(tag); + throw serviceNotFoundError(tag); } - return effect; -}, "length", { - value: body.length, - configurable: true + return self.unsafeMap.get(tag.key); }); -var withConcurrency = /* @__PURE__ */ dual(2, (self, concurrency) => fiberRefLocally(self, currentConcurrency, concurrency)); -var withRequestBatching = /* @__PURE__ */ dual(2, (self, requestBatching) => fiberRefLocally(self, currentRequestBatching, requestBatching)); -var withRuntimeFlags = /* @__PURE__ */ dual(2, (self, update2) => { - const effect = new EffectPrimitive(OP_UPDATE_RUNTIME_FLAGS); - effect.effect_instruction_i0 = update2; - effect.effect_instruction_i1 = () => self; - return effect; +var get2 = unsafeGet2; +var getOption = /* @__PURE__ */ dual(2, (self, tag) => { + if (!self.unsafeMap.has(tag.key)) { + return isReference(tag) ? some(getDefaultValue(tag)) : none; + } + return some(self.unsafeMap.get(tag.key)); }); -var withTracerEnabled = /* @__PURE__ */ dual(2, (effect, enabled2) => fiberRefLocally(effect, currentTracerEnabled, enabled2)); -var withTracerTiming = /* @__PURE__ */ dual(2, (effect, enabled2) => fiberRefLocally(effect, currentTracerTimingEnabled, enabled2)); -var yieldNow = (options) => { - const effect = new EffectPrimitive(OP_YIELD); - return typeof options?.priority !== "undefined" ? withSchedulingPriority(effect, options.priority) : effect; -}; -var zip2 = /* @__PURE__ */ dual(2, (self, that) => flatMap7(self, (a) => map9(that, (b) => [a, b]))); -var zipLeft = /* @__PURE__ */ dual(2, (self, that) => flatMap7(self, (a) => as(that, a))); -var zipRight = /* @__PURE__ */ dual(2, (self, that) => flatMap7(self, () => that)); -var zipWith2 = /* @__PURE__ */ dual(3, (self, that, f) => flatMap7(self, (a) => map9(that, (b) => f(a, b)))); -var never = /* @__PURE__ */ asyncInterrupt(() => { - const interval = setInterval(() => {}, 2 ** 31 - 1); - return sync(() => clearInterval(interval)); +var merge2 = /* @__PURE__ */ dual(2, (self, that) => { + const map4 = new Map(self.unsafeMap); + for (const [tag, s] of that.unsafeMap) { + map4.set(tag, s); + } + return makeContext(map4); }); -var interruptFiber = (self) => flatMap7(fiberId, (fiberId2) => pipe(self, interruptAsFiber(fiberId2))); -var interruptAsFiber = /* @__PURE__ */ dual(2, (self, fiberId2) => flatMap7(self.interruptAsFork(fiberId2), () => self.await)); -var logLevelAll = { - _tag: "All", - syslog: 0, - label: "ALL", - ordinal: Number.MIN_SAFE_INTEGER, - pipe() { - return pipeArguments(this, arguments); +var mergeAll = (...ctxs) => { + const map4 = new Map; + for (let i = 0;i < ctxs.length; i++) { + ctxs[i].unsafeMap.forEach((value, key) => { + map4.set(key, value); + }); } + return makeContext(map4); }; -var logLevelFatal = { - _tag: "Fatal", - syslog: 2, - label: "FATAL", - ordinal: 50000, + +// node_modules/effect/dist/esm/Context.js +var GenericTag = makeGenericTag; +var isContext2 = isContext; +var isTag2 = isTag; +var empty3 = empty2; +var make6 = make5; +var add2 = add; +var get3 = get2; +var unsafeGet3 = unsafeGet2; +var getOption2 = getOption; +var merge3 = merge2; +var mergeAll2 = mergeAll; +var Reference2 = Reference; + +// node_modules/effect/dist/esm/Chunk.js +var TypeId5 = /* @__PURE__ */ Symbol.for("effect/Chunk"); +function copy2(src, srcPos, dest, destPos, len) { + for (let i = srcPos;i < Math.min(src.length, srcPos + len); i++) { + dest[destPos + i - srcPos] = src[i]; + } + return dest; +} +var emptyArray = []; +var getEquivalence4 = (isEquivalent) => make((self, that) => self.length === that.length && toReadonlyArray(self).every((value, i) => isEquivalent(value, unsafeGet4(that, i)))); +var _equivalence3 = /* @__PURE__ */ getEquivalence4(equals); +var ChunkProto = { + [TypeId5]: { + _A: (_) => _ + }, + toString() { + return format(this.toJSON()); + }, + toJSON() { + return { + _id: "Chunk", + values: toReadonlyArray(this).map(toJSON) + }; + }, + [NodeInspectSymbol]() { + return this.toJSON(); + }, + [symbol2](that) { + return isChunk(that) && _equivalence3(this, that); + }, + [symbol]() { + return cached(this, array2(toReadonlyArray(this))); + }, + [Symbol.iterator]() { + switch (this.backing._tag) { + case "IArray": { + return this.backing.array[Symbol.iterator](); + } + case "IEmpty": { + return emptyArray[Symbol.iterator](); + } + default: { + return toReadonlyArray(this)[Symbol.iterator](); + } + } + }, pipe() { return pipeArguments(this, arguments); } }; -var logLevelError = { - _tag: "Error", - syslog: 3, - label: "ERROR", - ordinal: 40000, - pipe() { - return pipeArguments(this, arguments); +var makeChunk = (backing) => { + const chunk = Object.create(ChunkProto); + chunk.backing = backing; + switch (backing._tag) { + case "IEmpty": { + chunk.length = 0; + chunk.depth = 0; + chunk.left = chunk; + chunk.right = chunk; + break; + } + case "IConcat": { + chunk.length = backing.left.length + backing.right.length; + chunk.depth = 1 + Math.max(backing.left.depth, backing.right.depth); + chunk.left = backing.left; + chunk.right = backing.right; + break; + } + case "IArray": { + chunk.length = backing.array.length; + chunk.depth = 0; + chunk.left = _empty2; + chunk.right = _empty2; + break; + } + case "ISingleton": { + chunk.length = 1; + chunk.depth = 0; + chunk.left = _empty2; + chunk.right = _empty2; + break; + } + case "ISlice": { + chunk.length = backing.length; + chunk.depth = backing.chunk.depth + 1; + chunk.left = _empty2; + chunk.right = _empty2; + break; + } } + return chunk; }; -var logLevelWarning = { - _tag: "Warning", - syslog: 4, - label: "WARN", - ordinal: 30000, - pipe() { - return pipeArguments(this, arguments); +var isChunk = (u) => hasProperty(u, TypeId5); +var _empty2 = /* @__PURE__ */ makeChunk({ + _tag: "IEmpty" +}); +var empty4 = () => _empty2; +var make7 = (...as) => unsafeFromNonEmptyArray(as); +var of2 = (a) => makeChunk({ + _tag: "ISingleton", + a +}); +var fromIterable2 = (self) => isChunk(self) ? self : unsafeFromArray(fromIterable(self)); +var copyToArray = (self, array4, initial) => { + switch (self.backing._tag) { + case "IArray": { + copy2(self.backing.array, 0, array4, initial, self.length); + break; + } + case "IConcat": { + copyToArray(self.left, array4, initial); + copyToArray(self.right, array4, initial + self.left.length); + break; + } + case "ISingleton": { + array4[initial] = self.backing.a; + break; + } + case "ISlice": { + let i = 0; + let j = initial; + while (i < self.length) { + array4[j] = unsafeGet4(self, i); + i += 1; + j += 1; + } + break; + } } }; -var logLevelInfo = { - _tag: "Info", - syslog: 6, - label: "INFO", - ordinal: 20000, - pipe() { - return pipeArguments(this, arguments); - } -}; -var logLevelDebug = { - _tag: "Debug", - syslog: 7, - label: "DEBUG", - ordinal: 1e4, - pipe() { - return pipeArguments(this, arguments); - } -}; -var logLevelTrace = { - _tag: "Trace", - syslog: 7, - label: "TRACE", - ordinal: 0, - pipe() { - return pipeArguments(this, arguments); +var toReadonlyArray_ = (self) => { + switch (self.backing._tag) { + case "IEmpty": { + return emptyArray; + } + case "IArray": { + return self.backing.array; + } + default: { + const arr = new Array(self.length); + copyToArray(self, arr, 0); + self.backing = { + _tag: "IArray", + array: arr + }; + self.left = _empty2; + self.right = _empty2; + self.depth = 0; + return arr; + } } }; -var logLevelNone = { - _tag: "None", - syslog: 7, - label: "OFF", - ordinal: Number.MAX_SAFE_INTEGER, - pipe() { - return pipeArguments(this, arguments); +var toReadonlyArray = toReadonlyArray_; +var reverseChunk = (self) => { + switch (self.backing._tag) { + case "IEmpty": + case "ISingleton": + return self; + case "IArray": { + return makeChunk({ + _tag: "IArray", + array: reverse(self.backing.array) + }); + } + case "IConcat": { + return makeChunk({ + _tag: "IConcat", + left: reverse2(self.backing.right), + right: reverse2(self.backing.left) + }); + } + case "ISlice": + return unsafeFromArray(reverse(toReadonlyArray(self))); } }; -var FiberRefSymbolKey = "effect/FiberRef"; -var FiberRefTypeId = /* @__PURE__ */ Symbol.for(FiberRefSymbolKey); -var fiberRefVariance = { - _A: (_) => _ -}; -var fiberRefGet = (self) => withFiberRuntime((fiber) => exitSucceed(fiber.getFiberRef(self))); -var fiberRefGetWith = /* @__PURE__ */ dual(2, (self, f) => flatMap7(fiberRefGet(self), f)); -var fiberRefSet = /* @__PURE__ */ dual(2, (self, value) => fiberRefModify(self, () => [undefined, value])); -var fiberRefModify = /* @__PURE__ */ dual(2, (self, f) => withFiberRuntime((state) => { - const [b, a] = f(state.getFiberRef(self)); - state.setFiberRef(self, a); - return succeed(b); -})); -var fiberRefLocally = /* @__PURE__ */ dual(3, (use, self, value) => acquireUseRelease(zipLeft(fiberRefGet(self), fiberRefSet(self, value)), () => use, (oldValue) => fiberRefSet(self, oldValue))); -var fiberRefLocallyWith = /* @__PURE__ */ dual(3, (use, self, f) => fiberRefGetWith(self, (a) => fiberRefLocally(use, self, f(a)))); -var fiberRefUnsafeMake = (initial, options) => fiberRefUnsafeMakePatch(initial, { - differ: update(), - fork: options?.fork ?? identity, - join: options?.join -}); -var fiberRefUnsafeMakeHashSet = (initial) => { - const differ2 = hashSet(); - return fiberRefUnsafeMakePatch(initial, { - differ: differ2, - fork: differ2.empty - }); -}; -var fiberRefUnsafeMakeReadonlyArray = (initial) => { - const differ2 = readonlyArray(update()); - return fiberRefUnsafeMakePatch(initial, { - differ: differ2, - fork: differ2.empty - }); -}; -var fiberRefUnsafeMakeContext = (initial) => { - const differ2 = environment(); - return fiberRefUnsafeMakePatch(initial, { - differ: differ2, - fork: differ2.empty - }); -}; -var fiberRefUnsafeMakePatch = (initial, options) => { - const _fiberRef = { - ...CommitPrototype, - [FiberRefTypeId]: fiberRefVariance, - initial, - commit() { - return fiberRefGet(this); - }, - diff: (oldValue, newValue) => options.differ.diff(oldValue, newValue), - combine: (first, second) => options.differ.combine(first, second), - patch: (patch5) => (oldValue) => options.differ.patch(patch5, oldValue), - fork: options.fork, - join: options.join ?? ((_, n) => n) - }; - return _fiberRef; -}; -var fiberRefUnsafeMakeRuntimeFlags = (initial) => fiberRefUnsafeMakePatch(initial, { - differ, - fork: differ.empty +var reverse2 = reverseChunk; +var get4 = /* @__PURE__ */ dual(2, (self, index) => index < 0 || index >= self.length ? none2() : some2(unsafeGet4(self, index))); +var unsafeFromArray = (self) => self.length === 0 ? empty4() : self.length === 1 ? of2(self[0]) : makeChunk({ + _tag: "IArray", + array: self }); -var currentContext = /* @__PURE__ */ globalValue(/* @__PURE__ */ Symbol.for("effect/FiberRef/currentContext"), () => fiberRefUnsafeMakeContext(empty4())); -var currentSchedulingPriority = /* @__PURE__ */ globalValue(/* @__PURE__ */ Symbol.for("effect/FiberRef/currentSchedulingPriority"), () => fiberRefUnsafeMake(0)); -var currentMaxOpsBeforeYield = /* @__PURE__ */ globalValue(/* @__PURE__ */ Symbol.for("effect/FiberRef/currentMaxOpsBeforeYield"), () => fiberRefUnsafeMake(2048)); -var currentLogAnnotations = /* @__PURE__ */ globalValue(/* @__PURE__ */ Symbol.for("effect/FiberRef/currentLogAnnotation"), () => fiberRefUnsafeMake(empty8())); -var currentLogLevel = /* @__PURE__ */ globalValue(/* @__PURE__ */ Symbol.for("effect/FiberRef/currentLogLevel"), () => fiberRefUnsafeMake(logLevelInfo)); -var currentLogSpan = /* @__PURE__ */ globalValue(/* @__PURE__ */ Symbol.for("effect/FiberRef/currentLogSpan"), () => fiberRefUnsafeMake(empty9())); -var withSchedulingPriority = /* @__PURE__ */ dual(2, (self, scheduler) => fiberRefLocally(self, currentSchedulingPriority, scheduler)); -var withMaxOpsBeforeYield = /* @__PURE__ */ dual(2, (self, scheduler) => fiberRefLocally(self, currentMaxOpsBeforeYield, scheduler)); -var currentConcurrency = /* @__PURE__ */ globalValue(/* @__PURE__ */ Symbol.for("effect/FiberRef/currentConcurrency"), () => fiberRefUnsafeMake("unbounded")); -var currentRequestBatching = /* @__PURE__ */ globalValue(/* @__PURE__ */ Symbol.for("effect/FiberRef/currentRequestBatching"), () => fiberRefUnsafeMake(true)); -var currentUnhandledErrorLogLevel = /* @__PURE__ */ globalValue(/* @__PURE__ */ Symbol.for("effect/FiberRef/currentUnhandledErrorLogLevel"), () => fiberRefUnsafeMake(some2(logLevelDebug))); -var currentVersionMismatchErrorLogLevel = /* @__PURE__ */ globalValue(/* @__PURE__ */ Symbol.for("effect/FiberRef/versionMismatchErrorLogLevel"), () => fiberRefUnsafeMake(some2(logLevelWarning))); -var withUnhandledErrorLogLevel = /* @__PURE__ */ dual(2, (self, level) => fiberRefLocally(self, currentUnhandledErrorLogLevel, level)); -var currentMetricLabels = /* @__PURE__ */ globalValue(/* @__PURE__ */ Symbol.for("effect/FiberRef/currentMetricLabels"), () => fiberRefUnsafeMakeReadonlyArray(empty())); -var metricLabels = /* @__PURE__ */ fiberRefGet(currentMetricLabels); -var currentForkScopeOverride = /* @__PURE__ */ globalValue(/* @__PURE__ */ Symbol.for("effect/FiberRef/currentForkScopeOverride"), () => fiberRefUnsafeMake(none2(), { - fork: () => none2(), - join: (parent, _) => parent -})); -var currentInterruptedCause = /* @__PURE__ */ globalValue(/* @__PURE__ */ Symbol.for("effect/FiberRef/currentInterruptedCause"), () => fiberRefUnsafeMake(empty16, { - fork: () => empty16, - join: (parent, _) => parent -})); -var currentTracerEnabled = /* @__PURE__ */ globalValue(/* @__PURE__ */ Symbol.for("effect/FiberRef/currentTracerEnabled"), () => fiberRefUnsafeMake(true)); -var currentTracerTimingEnabled = /* @__PURE__ */ globalValue(/* @__PURE__ */ Symbol.for("effect/FiberRef/currentTracerTiming"), () => fiberRefUnsafeMake(true)); -var currentTracerSpanAnnotations = /* @__PURE__ */ globalValue(/* @__PURE__ */ Symbol.for("effect/FiberRef/currentTracerSpanAnnotations"), () => fiberRefUnsafeMake(empty8())); -var currentTracerSpanLinks = /* @__PURE__ */ globalValue(/* @__PURE__ */ Symbol.for("effect/FiberRef/currentTracerSpanLinks"), () => fiberRefUnsafeMake(empty2())); -var ScopeTypeId = /* @__PURE__ */ Symbol.for("effect/Scope"); -var CloseableScopeTypeId = /* @__PURE__ */ Symbol.for("effect/CloseableScope"); -var scopeAddFinalizer = (self, finalizer) => self.addFinalizer(() => asVoid(finalizer)); -var scopeAddFinalizerExit = (self, finalizer) => self.addFinalizer(finalizer); -var scopeClose = (self, exit2) => self.close(exit2); -var scopeFork = (self, strategy) => self.fork(strategy); -var YieldableError = /* @__PURE__ */ function() { - class YieldableError2 extends globalThis.Error { - commit() { - return fail2(this); +var unsafeFromNonEmptyArray = (self) => unsafeFromArray(self); +var unsafeGet4 = /* @__PURE__ */ dual(2, (self, index) => { + switch (self.backing._tag) { + case "IEmpty": { + throw new Error(`Index out of bounds`); } - toJSON() { - const obj = { - ...this - }; - if (this.message) - obj.message = this.message; - if (this.cause) - obj.cause = this.cause; - return obj; + case "ISingleton": { + if (index !== 0) { + throw new Error(`Index out of bounds`); + } + return self.backing.a; } - [NodeInspectSymbol]() { - if (this.toString !== globalThis.Error.prototype.toString) { - return this.stack ? `${this.toString()} -${this.stack.split(` -`).slice(1).join(` -`)}` : this.toString(); - } else if ("Bun" in globalThis) { - return pretty(fail(this), { - renderErrorCause: true + case "IArray": { + if (index >= self.length || index < 0) { + throw new Error(`Index out of bounds`); + } + return self.backing.array[index]; + } + case "IConcat": { + return index < self.left.length ? unsafeGet4(self.left, index) : unsafeGet4(self.right, index - self.left.length); + } + case "ISlice": { + return unsafeGet4(self.backing.chunk, index + self.backing.offset); + } + } +}); +var append2 = /* @__PURE__ */ dual(2, (self, a) => appendAll2(self, of2(a))); +var prepend2 = /* @__PURE__ */ dual(2, (self, elem) => appendAll2(of2(elem), self)); +var drop2 = /* @__PURE__ */ dual(2, (self, n) => { + if (n <= 0) { + return self; + } else if (n >= self.length) { + return _empty2; + } else { + switch (self.backing._tag) { + case "ISlice": { + return makeChunk({ + _tag: "ISlice", + chunk: self.backing.chunk, + offset: self.backing.offset + n, + length: self.backing.length - n + }); + } + case "IConcat": { + if (n > self.left.length) { + return drop2(self.right, n - self.left.length); + } + return makeChunk({ + _tag: "IConcat", + left: drop2(self.left, n), + right: self.right + }); + } + default: { + return makeChunk({ + _tag: "ISlice", + chunk: self, + offset: n, + length: self.length - n }); } - return this; } } - Object.assign(YieldableError2.prototype, StructuralCommitPrototype); - return YieldableError2; -}(); -var makeException = (proto2, tag) => { - - class Base2 extends YieldableError { - _tag = tag; +}); +var appendAll2 = /* @__PURE__ */ dual(2, (self, that) => { + if (self.backing._tag === "IEmpty") { + return that; } - Object.assign(Base2.prototype, proto2); - Base2.prototype.name = tag; - return Base2; -}; -var RuntimeExceptionTypeId = /* @__PURE__ */ Symbol.for("effect/Cause/errors/RuntimeException"); -var RuntimeException = /* @__PURE__ */ makeException({ - [RuntimeExceptionTypeId]: RuntimeExceptionTypeId -}, "RuntimeException"); -var InterruptedExceptionTypeId = /* @__PURE__ */ Symbol.for("effect/Cause/errors/InterruptedException"); -var InterruptedException = /* @__PURE__ */ makeException({ - [InterruptedExceptionTypeId]: InterruptedExceptionTypeId -}, "InterruptedException"); -var isInterruptedException = (u) => hasProperty(u, InterruptedExceptionTypeId); -var IllegalArgumentExceptionTypeId = /* @__PURE__ */ Symbol.for("effect/Cause/errors/IllegalArgument"); -var IllegalArgumentException = /* @__PURE__ */ makeException({ - [IllegalArgumentExceptionTypeId]: IllegalArgumentExceptionTypeId -}, "IllegalArgumentException"); -var NoSuchElementExceptionTypeId = /* @__PURE__ */ Symbol.for("effect/Cause/errors/NoSuchElement"); -var NoSuchElementException = /* @__PURE__ */ makeException({ - [NoSuchElementExceptionTypeId]: NoSuchElementExceptionTypeId -}, "NoSuchElementException"); -var isNoSuchElementException = (u) => hasProperty(u, NoSuchElementExceptionTypeId); -var InvalidPubSubCapacityExceptionTypeId = /* @__PURE__ */ Symbol.for("effect/Cause/errors/InvalidPubSubCapacityException"); -var InvalidPubSubCapacityException = /* @__PURE__ */ makeException({ - [InvalidPubSubCapacityExceptionTypeId]: InvalidPubSubCapacityExceptionTypeId -}, "InvalidPubSubCapacityException"); -var ExceededCapacityExceptionTypeId = /* @__PURE__ */ Symbol.for("effect/Cause/errors/ExceededCapacityException"); -var ExceededCapacityException = /* @__PURE__ */ makeException({ - [ExceededCapacityExceptionTypeId]: ExceededCapacityExceptionTypeId -}, "ExceededCapacityException"); -var TimeoutExceptionTypeId = /* @__PURE__ */ Symbol.for("effect/Cause/errors/Timeout"); -var TimeoutException = /* @__PURE__ */ makeException({ - [TimeoutExceptionTypeId]: TimeoutExceptionTypeId -}, "TimeoutException"); -var timeoutExceptionFromDuration = (duration) => new TimeoutException(`Operation timed out after '${format2(duration)}'`); -var UnknownExceptionTypeId = /* @__PURE__ */ Symbol.for("effect/Cause/errors/UnknownException"); -var UnknownException = /* @__PURE__ */ function() { - - class UnknownException2 extends YieldableError { - _tag = "UnknownException"; - error; - constructor(cause, message) { - super(message ?? "An unknown error occurred", { - cause - }); - this.error = cause; - } + if (that.backing._tag === "IEmpty") { + return self; } - Object.assign(UnknownException2.prototype, { - [UnknownExceptionTypeId]: UnknownExceptionTypeId, - name: "UnknownException" - }); - return UnknownException2; -}(); -var exitIsExit = (u) => isEffect(u) && ("_tag" in u) && (u._tag === "Success" || u._tag === "Failure"); -var exitIsFailure = (self) => self._tag === "Failure"; -var exitIsSuccess = (self) => self._tag === "Success"; -var exitAs = /* @__PURE__ */ dual(2, (self, value) => { - switch (self._tag) { - case OP_FAILURE: { - return exitFailCause(self.effect_instruction_i0); + const diff = that.depth - self.depth; + if (Math.abs(diff) <= 1) { + return makeChunk({ + _tag: "IConcat", + left: self, + right: that + }); + } else if (diff < -1) { + if (self.left.depth >= self.right.depth) { + const nr = appendAll2(self.right, that); + return makeChunk({ + _tag: "IConcat", + left: self.left, + right: nr + }); + } else { + const nrr = appendAll2(self.right.right, that); + if (nrr.depth === self.depth - 3) { + const nr = makeChunk({ + _tag: "IConcat", + left: self.right.left, + right: nrr + }); + return makeChunk({ + _tag: "IConcat", + left: self.left, + right: nr + }); + } else { + const nl = makeChunk({ + _tag: "IConcat", + left: self.left, + right: self.right.left + }); + return makeChunk({ + _tag: "IConcat", + left: nl, + right: nrr + }); + } } - case OP_SUCCESS: { - return exitSucceed(value); + } else { + if (that.right.depth >= that.left.depth) { + const nl = appendAll2(self, that.left); + return makeChunk({ + _tag: "IConcat", + left: nl, + right: that.right + }); + } else { + const nll = appendAll2(self, that.left.left); + if (nll.depth === that.depth - 3) { + const nl = makeChunk({ + _tag: "IConcat", + left: nll, + right: that.left.right + }); + return makeChunk({ + _tag: "IConcat", + left: nl, + right: that.right + }); + } else { + const nr = makeChunk({ + _tag: "IConcat", + left: that.left.right, + right: that.right + }); + return makeChunk({ + _tag: "IConcat", + left: nll, + right: nr + }); + } } } }); -var exitAsVoid = (self) => exitAs(self, undefined); -var exitCollectAll = (exits, options) => exitCollectAllInternal(exits, options?.parallel ? parallel : sequential); -var exitDie = (defect) => exitFailCause(die(defect)); -var exitFail = (error) => exitFailCause(fail(error)); -var exitFailCause = (cause) => { - const effect = new EffectPrimitiveFailure(OP_FAILURE); - effect.effect_instruction_i0 = cause; - return effect; -}; -var exitFlatMap = /* @__PURE__ */ dual(2, (self, f) => { - switch (self._tag) { - case OP_FAILURE: { - return exitFailCause(self.effect_instruction_i0); +var isEmpty = (self) => self.length === 0; +var isNonEmpty2 = (self) => self.length > 0; +var head2 = /* @__PURE__ */ get4(0); +var unsafeHead = (self) => unsafeGet4(self, 0); +var headNonEmpty2 = unsafeHead; +var tailNonEmpty2 = (self) => drop2(self, 1); + +// node_modules/effect/dist/esm/Duration.js +var TypeId6 = /* @__PURE__ */ Symbol.for("effect/Duration"); +var bigint02 = /* @__PURE__ */ BigInt(0); +var bigint24 = /* @__PURE__ */ BigInt(24); +var bigint60 = /* @__PURE__ */ BigInt(60); +var bigint1e3 = /* @__PURE__ */ BigInt(1000); +var bigint1e6 = /* @__PURE__ */ BigInt(1e6); +var bigint1e9 = /* @__PURE__ */ BigInt(1e9); +var DURATION_REGEX = /^(-?\d+(?:\.\d+)?)\s+(nanos?|micros?|millis?|seconds?|minutes?|hours?|days?|weeks?)$/; +var decode = (input) => { + if (isDuration(input)) { + return input; + } else if (isNumber(input)) { + return millis(input); + } else if (isBigInt(input)) { + return nanos(input); + } else if (Array.isArray(input) && input.length === 2 && input.every(isNumber)) { + if (input[0] === -Infinity || input[1] === -Infinity || Number.isNaN(input[0]) || Number.isNaN(input[1])) { + return zero2; } - case OP_SUCCESS: { - return f(self.effect_instruction_i0); + if (input[0] === Infinity || input[1] === Infinity) { + return infinity; } - } -}); -var exitFlatten = (self) => pipe(self, exitFlatMap(identity)); -var exitInterrupt = (fiberId2) => exitFailCause(interrupt(fiberId2)); -var exitMap = /* @__PURE__ */ dual(2, (self, f) => { - switch (self._tag) { - case OP_FAILURE: - return exitFailCause(self.effect_instruction_i0); - case OP_SUCCESS: - return exitSucceed(f(self.effect_instruction_i0)); - } -}); -var exitMatch = /* @__PURE__ */ dual(2, (self, { - onFailure, - onSuccess -}) => { - switch (self._tag) { - case OP_FAILURE: - return onFailure(self.effect_instruction_i0); - case OP_SUCCESS: - return onSuccess(self.effect_instruction_i0); - } -}); -var exitMatchEffect = /* @__PURE__ */ dual(2, (self, { - onFailure, - onSuccess -}) => { - switch (self._tag) { - case OP_FAILURE: - return onFailure(self.effect_instruction_i0); - case OP_SUCCESS: - return onSuccess(self.effect_instruction_i0); - } -}); -var exitSucceed = (value) => { - const effect = new EffectPrimitiveSuccess(OP_SUCCESS); - effect.effect_instruction_i0 = value; - return effect; -}; -var exitVoid = /* @__PURE__ */ exitSucceed(undefined); -var exitZipWith = /* @__PURE__ */ dual(3, (self, that, { - onFailure, - onSuccess -}) => { - switch (self._tag) { - case OP_FAILURE: { - switch (that._tag) { - case OP_SUCCESS: - return exitFailCause(self.effect_instruction_i0); - case OP_FAILURE: { - return exitFailCause(onFailure(self.effect_instruction_i0, that.effect_instruction_i0)); - } + return nanos(BigInt(Math.round(input[0] * 1e9)) + BigInt(Math.round(input[1]))); + } else if (isString(input)) { + const match4 = DURATION_REGEX.exec(input); + if (match4) { + const [_, valueStr, unit] = match4; + const value = Number(valueStr); + switch (unit) { + case "nano": + case "nanos": + return nanos(BigInt(valueStr)); + case "micro": + case "micros": + return micros(BigInt(valueStr)); + case "milli": + case "millis": + return millis(value); + case "second": + case "seconds": + return seconds(value); + case "minute": + case "minutes": + return minutes(value); + case "hour": + case "hours": + return hours(value); + case "day": + case "days": + return days(value); + case "week": + case "weeks": + return weeks(value); } } - case OP_SUCCESS: { - switch (that._tag) { - case OP_SUCCESS: - return exitSucceed(onSuccess(self.effect_instruction_i0, that.effect_instruction_i0)); - case OP_FAILURE: - return exitFailCause(that.effect_instruction_i0); - } - } - } -}); -var exitCollectAllInternal = (exits, combineCauses) => { - const list = fromIterable2(exits); - if (!isNonEmpty(list)) { - return none2(); } - return pipe(tailNonEmpty2(list), reduce(pipe(headNonEmpty2(list), exitMap(of2)), (accumulator, current) => pipe(accumulator, exitZipWith(current, { - onSuccess: (list2, value) => pipe(list2, prepend2(value)), - onFailure: combineCauses - }))), exitMap(reverse2), exitMap((chunk) => toReadonlyArray(chunk)), some2); + throw new Error("Invalid DurationInput"); }; -var deferredUnsafeMake = (fiberId2) => { - const _deferred = { - ...CommitPrototype, - [DeferredTypeId]: deferredVariance, - state: make11(pending([])), - commit() { - return deferredAwait(this); - }, - blockingOn: fiberId2 - }; - return _deferred; +var zeroValue = { + _tag: "Millis", + millis: 0 }; -var deferredMake = () => flatMap7(fiberId, (id) => deferredMakeAs(id)); -var deferredMakeAs = (fiberId2) => sync(() => deferredUnsafeMake(fiberId2)); -var deferredAwait = (self) => asyncInterrupt((resume) => { - const state = get6(self.state); - switch (state._tag) { - case OP_STATE_DONE: { - return resume(state.effect); +var infinityValue = { + _tag: "Infinity" +}; +var DurationProto = { + [TypeId6]: TypeId6, + [symbol]() { + return cached(this, structure(this.value)); + }, + [symbol2](that) { + return isDuration(that) && equals4(this, that); + }, + toString() { + return `Duration(${format3(this)})`; + }, + toJSON() { + switch (this.value._tag) { + case "Millis": + return { + _id: "Duration", + _tag: "Millis", + millis: this.value.millis + }; + case "Nanos": + return { + _id: "Duration", + _tag: "Nanos", + hrtime: toHrTime(this) + }; + case "Infinity": + return { + _id: "Duration", + _tag: "Infinity" + }; } - case OP_STATE_PENDING: { - state.joiners.push(resume); - return deferredInterruptJoiner(self, resume); + }, + [NodeInspectSymbol]() { + return this.toJSON(); + }, + pipe() { + return pipeArguments(this, arguments); + } +}; +var make8 = (input) => { + const duration = Object.create(DurationProto); + if (isNumber(input)) { + if (isNaN(input) || input <= 0) { + duration.value = zeroValue; + } else if (!Number.isFinite(input)) { + duration.value = infinityValue; + } else if (!Number.isInteger(input)) { + duration.value = { + _tag: "Nanos", + nanos: BigInt(Math.round(input * 1e6)) + }; + } else { + duration.value = { + _tag: "Millis", + millis: input + }; } + } else if (input <= bigint02) { + duration.value = zeroValue; + } else { + duration.value = { + _tag: "Nanos", + nanos: input + }; } -}, self.blockingOn); -var deferredComplete = /* @__PURE__ */ dual(2, (self, effect) => intoDeferred(effect, self)); -var deferredCompleteWith = /* @__PURE__ */ dual(2, (self, effect) => sync(() => { - const state = get6(self.state); - switch (state._tag) { - case OP_STATE_DONE: { - return false; + return duration; +}; +var isDuration = (u) => hasProperty(u, TypeId6); +var isFinite = (self) => self.value._tag !== "Infinity"; +var isZero2 = (self) => { + switch (self.value._tag) { + case "Millis": { + return self.value.millis === 0; } - case OP_STATE_PENDING: { - set2(self.state, done(effect)); - for (let i = 0, len = state.joiners.length;i < len; i++) { - state.joiners[i](effect); - } - return true; + case "Nanos": { + return self.value.nanos === bigint02; } - } -})); -var deferredDone = /* @__PURE__ */ dual(2, (self, exit2) => deferredCompleteWith(self, exit2)); -var deferredFailCause = /* @__PURE__ */ dual(2, (self, cause) => deferredCompleteWith(self, failCause(cause))); -var deferredInterrupt = (self) => flatMap7(fiberId, (fiberId2) => deferredCompleteWith(self, interruptWith(fiberId2))); -var deferredSucceed = /* @__PURE__ */ dual(2, (self, value) => deferredCompleteWith(self, succeed(value))); -var deferredUnsafeDone = (self, effect) => { - const state = get6(self.state); - if (state._tag === OP_STATE_PENDING) { - set2(self.state, done(effect)); - for (let i = 0, len = state.joiners.length;i < len; i++) { - state.joiners[i](effect); + case "Infinity": { + return false; } } }; -var deferredInterruptJoiner = (self, joiner) => sync(() => { - const state = get6(self.state); - if (state._tag === OP_STATE_PENDING) { - const index = state.joiners.indexOf(joiner); - if (index >= 0) { - state.joiners.splice(index, 1); - } - } +var zero2 = /* @__PURE__ */ make8(0); +var infinity = /* @__PURE__ */ make8(Infinity); +var nanos = (nanos2) => make8(nanos2); +var micros = (micros2) => make8(micros2 * bigint1e3); +var millis = (millis2) => make8(millis2); +var seconds = (seconds2) => make8(seconds2 * 1000); +var minutes = (minutes2) => make8(minutes2 * 60000); +var hours = (hours2) => make8(hours2 * 3600000); +var days = (days2) => make8(days2 * 86400000); +var weeks = (weeks2) => make8(weeks2 * 604800000); +var toMillis = (self) => match4(self, { + onMillis: (millis2) => millis2, + onNanos: (nanos2) => Number(nanos2) / 1e6 }); -var constContext = /* @__PURE__ */ withFiberRuntime((fiber) => exitSucceed(fiber.currentContext)); -var context = () => constContext; -var contextWithEffect = (f) => flatMap7(context(), f); -var provideContext = /* @__PURE__ */ dual(2, (self, context2) => fiberRefLocally(currentContext, context2)(self)); -var provideSomeContext = /* @__PURE__ */ dual(2, (self, context2) => fiberRefLocallyWith(currentContext, (parent) => merge3(parent, context2))(self)); -var mapInputContext = /* @__PURE__ */ dual(2, (self, f) => contextWithEffect((context2) => provideContext(self, f(context2)))); -var filterEffectOrElse = /* @__PURE__ */ dual(2, (self, options) => flatMap7(self, (a) => flatMap7(options.predicate(a), (pass) => pass ? succeed(a) : options.orElse(a)))); -var filterEffectOrFail = /* @__PURE__ */ dual(2, (self, options) => filterEffectOrElse(self, { - predicate: options.predicate, - orElse: (a) => fail2(options.orFailWith(a)) -})); -var currentSpanFromFiber = (fiber) => { - const span2 = fiber.currentSpan; - return span2 !== undefined && span2._tag === "Span" ? some2(span2) : none2(); -}; -var NoopSpanProto = { - _tag: "Span", - spanId: "noop", - traceId: "noop", - sampled: false, - status: { - _tag: "Ended", - startTime: /* @__PURE__ */ BigInt(0), - endTime: /* @__PURE__ */ BigInt(0), - exit: exitVoid - }, - attributes: /* @__PURE__ */ new Map, - links: [], - kind: "internal", - attribute() {}, - event() {}, - end() {}, - addLinks() {} +var toNanos = (self) => { + const _self = decode(self); + switch (_self.value._tag) { + case "Infinity": + return none2(); + case "Nanos": + return some2(_self.value.nanos); + case "Millis": + return some2(BigInt(Math.round(_self.value.millis * 1e6))); + } }; -var noopSpan = (options) => Object.assign(Object.create(NoopSpanProto), options); - -// node_modules/effect/dist/esm/Data.js -var struct2 = struct; -var unsafeStruct = (as2) => Object.setPrototypeOf(as2, StructuralPrototype); -var tuple = (...as2) => unsafeArray(as2); -var array3 = (as2) => unsafeArray(as2.slice(0)); -var unsafeArray = (as2) => Object.setPrototypeOf(as2, ArrayProto); -var _case = () => (args) => args === undefined ? Object.create(StructuralPrototype) : struct2(args); -var tagged = (tag) => (args) => { - const value = args === undefined ? Object.create(StructuralPrototype) : struct2(args); - value._tag = tag; - return value; +var unsafeToNanos = (self) => { + const _self = decode(self); + switch (_self.value._tag) { + case "Infinity": + throw new Error("Cannot convert infinite duration to nanos"); + case "Nanos": + return _self.value.nanos; + case "Millis": + return BigInt(Math.round(_self.value.millis * 1e6)); + } }; -var Class = Structural; -var TaggedClass = (tag) => { - - class Base2 extends Class { - _tag = tag; +var toHrTime = (self) => { + const _self = decode(self); + switch (_self.value._tag) { + case "Infinity": + return [Infinity, 0]; + case "Nanos": + return [Number(_self.value.nanos / bigint1e9), Number(_self.value.nanos % bigint1e9)]; + case "Millis": + return [Math.floor(_self.value.millis / 1000), Math.round(_self.value.millis % 1000 * 1e6)]; } - return Base2; }; -var Structural2 = Structural; -var taggedEnum = () => new Proxy({}, { - get(_target, tag, _receiver) { - if (tag === "$is") { - return isTagged; - } else if (tag === "$match") { - return taggedMatch; - } - return tagged(tag); +var match4 = /* @__PURE__ */ dual(2, (self, options) => { + const _self = decode(self); + switch (_self.value._tag) { + case "Nanos": + return options.onNanos(_self.value.nanos); + case "Infinity": + return options.onMillis(Infinity); + case "Millis": + return options.onMillis(_self.value.millis); } }); -function taggedMatch() { - if (arguments.length === 1) { - const cases2 = arguments[0]; - return function(value2) { - return cases2[value2._tag](value2); - }; +var matchWith = /* @__PURE__ */ dual(3, (self, that, options) => { + const _self = decode(self); + const _that = decode(that); + if (_self.value._tag === "Infinity" || _that.value._tag === "Infinity") { + return options.onMillis(toMillis(_self), toMillis(_that)); + } else if (_self.value._tag === "Nanos" || _that.value._tag === "Nanos") { + const selfNanos = _self.value._tag === "Nanos" ? _self.value.nanos : BigInt(Math.round(_self.value.millis * 1e6)); + const thatNanos = _that.value._tag === "Nanos" ? _that.value.nanos : BigInt(Math.round(_that.value.millis * 1e6)); + return options.onNanos(selfNanos, thatNanos); } - const value = arguments[0]; - const cases = arguments[1]; - return cases[value._tag](value); -} -var Error2 = /* @__PURE__ */ function() { - const plainArgsSymbol = /* @__PURE__ */ Symbol.for("effect/Data/Error/plainArgs"); - const O = { - BaseEffectError: class extends YieldableError { - constructor(args) { - super(args?.message, args?.cause ? { - cause: args.cause - } : undefined); - if (args) { - Object.assign(this, args); - Object.defineProperty(this, plainArgsSymbol, { - value: args, - enumerable: false - }); - } + return options.onMillis(_self.value.millis, _that.value.millis); +}); +var Order4 = /* @__PURE__ */ make2((self, that) => matchWith(self, that, { + onMillis: (self2, that2) => self2 < that2 ? -1 : self2 > that2 ? 1 : 0, + onNanos: (self2, that2) => self2 < that2 ? -1 : self2 > that2 ? 1 : 0 +})); +var between3 = /* @__PURE__ */ between(/* @__PURE__ */ mapInput2(Order4, decode)); +var Equivalence2 = (self, that) => matchWith(self, that, { + onMillis: (self2, that2) => self2 === that2, + onNanos: (self2, that2) => self2 === that2 +}); +var _clamp = /* @__PURE__ */ clamp(Order4); +var clamp6 = /* @__PURE__ */ dual(2, (self, options) => _clamp(decode(self), { + minimum: decode(options.minimum), + maximum: decode(options.maximum) +})); +var lessThan3 = /* @__PURE__ */ dual(2, (self, that) => matchWith(self, that, { + onMillis: (self2, that2) => self2 < that2, + onNanos: (self2, that2) => self2 < that2 +})); +var lessThanOrEqualTo3 = /* @__PURE__ */ dual(2, (self, that) => matchWith(self, that, { + onMillis: (self2, that2) => self2 <= that2, + onNanos: (self2, that2) => self2 <= that2 +})); +var greaterThan3 = /* @__PURE__ */ dual(2, (self, that) => matchWith(self, that, { + onMillis: (self2, that2) => self2 > that2, + onNanos: (self2, that2) => self2 > that2 +})); +var greaterThanOrEqualTo3 = /* @__PURE__ */ dual(2, (self, that) => matchWith(self, that, { + onMillis: (self2, that2) => self2 >= that2, + onNanos: (self2, that2) => self2 >= that2 +})); +var equals4 = /* @__PURE__ */ dual(2, (self, that) => Equivalence2(decode(self), decode(that))); +var parts = (self) => { + const duration = decode(self); + if (duration.value._tag === "Infinity") { + return { + days: Infinity, + hours: Infinity, + minutes: Infinity, + seconds: Infinity, + millis: Infinity, + nanos: Infinity + }; + } + const nanos2 = unsafeToNanos(duration); + const ms = nanos2 / bigint1e6; + const sec = ms / bigint1e3; + const min2 = sec / bigint60; + const hr = min2 / bigint60; + const days2 = hr / bigint24; + return { + days: Number(days2), + hours: Number(hr % bigint24), + minutes: Number(min2 % bigint60), + seconds: Number(sec % bigint60), + millis: Number(ms % bigint1e3), + nanos: Number(nanos2 % bigint1e6) + }; +}; +var format3 = (self) => { + const duration = decode(self); + if (duration.value._tag === "Infinity") { + return "Infinity"; + } + if (isZero2(duration)) { + return "0"; + } + const fragments = parts(duration); + const pieces = []; + if (fragments.days !== 0) { + pieces.push(`${fragments.days}d`); + } + if (fragments.hours !== 0) { + pieces.push(`${fragments.hours}h`); + } + if (fragments.minutes !== 0) { + pieces.push(`${fragments.minutes}m`); + } + if (fragments.seconds !== 0) { + pieces.push(`${fragments.seconds}s`); + } + if (fragments.millis !== 0) { + pieces.push(`${fragments.millis}ms`); + } + if (fragments.nanos !== 0) { + pieces.push(`${fragments.nanos}ns`); + } + return pieces.join(" "); +}; + +// node_modules/effect/dist/esm/internal/hashMap/config.js +var SIZE = 5; +var BUCKET_SIZE = /* @__PURE__ */ Math.pow(2, SIZE); +var MASK = BUCKET_SIZE - 1; +var MAX_INDEX_NODE = BUCKET_SIZE / 2; +var MIN_ARRAY_NODE = BUCKET_SIZE / 4; + +// node_modules/effect/dist/esm/internal/hashMap/bitwise.js +function popcount(x) { + x -= x >> 1 & 1431655765; + x = (x & 858993459) + (x >> 2 & 858993459); + x = x + (x >> 4) & 252645135; + x += x >> 8; + x += x >> 16; + return x & 127; +} +function hashFragment(shift, h) { + return h >>> shift & MASK; +} +function toBitmap(x) { + return 1 << x; +} +function fromBitmap(bitmap, bit) { + return popcount(bitmap & bit - 1); +} + +// node_modules/effect/dist/esm/internal/stack.js +var make9 = (value, previous) => ({ + value, + previous +}); + +// node_modules/effect/dist/esm/internal/hashMap/array.js +function arrayUpdate(mutate, at, v, arr) { + let out = arr; + if (!mutate) { + const len = arr.length; + out = new Array(len); + for (let i = 0;i < len; ++i) + out[i] = arr[i]; + } + out[at] = v; + return out; +} +function arraySpliceOut(mutate, at, arr) { + const newLen = arr.length - 1; + let i = 0; + let g = 0; + let out = arr; + if (mutate) { + i = g = at; + } else { + out = new Array(newLen); + while (i < at) + out[g++] = arr[i++]; + } + ++i; + while (i <= newLen) + out[g++] = arr[i++]; + if (mutate) { + out.length = newLen; + } + return out; +} +function arraySpliceIn(mutate, at, v, arr) { + const len = arr.length; + if (mutate) { + let i2 = len; + while (i2 >= at) + arr[i2--] = arr[i2]; + arr[at] = v; + return arr; + } + let i = 0, g = 0; + const out = new Array(len + 1); + while (i < at) + out[g++] = arr[i++]; + out[at] = v; + while (i < len) + out[++g] = arr[i++]; + return out; +} + +// node_modules/effect/dist/esm/internal/hashMap/node.js +class EmptyNode { + _tag = "EmptyNode"; + modify(edit, _shift, f, hash2, key, size) { + const v = f(none2()); + if (isNone2(v)) + return new EmptyNode; + ++size.value; + return new LeafNode(edit, hash2, key, v); + } +} +function isEmptyNode(a) { + return isTagged(a, "EmptyNode"); +} +function isLeafNode(node) { + return isEmptyNode(node) || node._tag === "LeafNode" || node._tag === "CollisionNode"; +} +function canEditNode(node, edit) { + return isEmptyNode(node) ? false : edit === node.edit; +} + +class LeafNode { + edit; + hash; + key; + value; + _tag = "LeafNode"; + constructor(edit, hash2, key, value) { + this.edit = edit; + this.hash = hash2; + this.key = key; + this.value = value; + } + modify(edit, shift, f, hash2, key, size) { + if (equals(key, this.key)) { + const v2 = f(this.value); + if (v2 === this.value) + return this; + else if (isNone2(v2)) { + --size.value; + return new EmptyNode; } - toJSON() { - return { - ...this[plainArgsSymbol], - ...this - }; + if (canEditNode(this, edit)) { + this.value = v2; + return this; } + return new LeafNode(edit, hash2, key, v2); } - }; - return O.BaseEffectError; -}(); -var TaggedError = (tag) => { - const O = { - BaseEffectError: class extends Error2 { - _tag = tag; + const v = f(none2()); + if (isNone2(v)) + return this; + ++size.value; + return mergeLeaves(edit, shift, this.hash, this, hash2, new LeafNode(edit, hash2, key, v)); + } +} + +class CollisionNode { + edit; + hash; + children; + _tag = "CollisionNode"; + constructor(edit, hash2, children) { + this.edit = edit; + this.hash = hash2; + this.children = children; + } + modify(edit, shift, f, hash2, key, size) { + if (hash2 === this.hash) { + const canEdit = canEditNode(this, edit); + const list = this.updateCollisionList(canEdit, edit, this.hash, this.children, f, key, size); + if (list === this.children) + return this; + return list.length > 1 ? new CollisionNode(edit, this.hash, list) : list[0]; } - }; - O.BaseEffectError.prototype.name = tag; - return O.BaseEffectError; -}; -// node_modules/effect/dist/esm/Effect.js -var exports_Effect = {}; -__export(exports_Effect, { - zipWith: () => zipWith3, - zipRight: () => zipRight2, - zipLeft: () => zipLeft2, - zip: () => zip4, - yieldNow: () => yieldNow4, - withUnhandledErrorLogLevel: () => withUnhandledErrorLogLevel2, - withTracerTiming: () => withTracerTiming2, - withTracerScoped: () => withTracerScoped2, - withTracerEnabled: () => withTracerEnabled2, - withTracer: () => withTracer2, - withSpanScoped: () => withSpanScoped2, - withSpan: () => withSpan2, - withSchedulingPriority: () => withSchedulingPriority2, - withScheduler: () => withScheduler2, - withRuntimeFlagsPatchScoped: () => withRuntimeFlagsPatchScoped, - withRuntimeFlagsPatch: () => withRuntimeFlagsPatch, - withRequestCaching: () => withRequestCaching2, - withRequestCache: () => withRequestCache2, - withRequestBatching: () => withRequestBatching2, - withRandomScoped: () => withRandomScoped2, - withRandomFixed: () => withRandomFixed, - withRandom: () => withRandom2, - withParentSpan: () => withParentSpan2, - withMetric: () => withMetric2, - withMaxOpsBeforeYield: () => withMaxOpsBeforeYield2, - withLogSpan: () => withLogSpan2, - withFiberRuntime: () => withFiberRuntime2, - withExecutionPlan: () => withExecutionPlan2, - withEarlyRelease: () => withEarlyRelease2, - withConsoleScoped: () => withConsoleScoped2, - withConsole: () => withConsole2, - withConfigProviderScoped: () => withConfigProviderScoped2, - withConfigProvider: () => withConfigProvider2, - withConcurrency: () => withConcurrency2, - withClockScoped: () => withClockScoped2, - withClock: () => withClock2, - whileLoop: () => whileLoop2, - whenRef: () => whenRef2, - whenLogLevel: () => whenLogLevel2, - whenFiberRef: () => whenFiberRef2, - whenEffect: () => whenEffect2, - when: () => when2, - void: () => _void, - validateWith: () => validateWith2, - validateFirst: () => validateFirst2, - validateAll: () => validateAll2, - validate: () => validate2, - using: () => using2, - useSpan: () => useSpan2, - updateService: () => updateService2, - updateFiberRefs: () => updateFiberRefs2, - unsandbox: () => unsandbox2, - unsafeMakeSemaphore: () => unsafeMakeSemaphore2, - unsafeMakeLatch: () => unsafeMakeLatch2, - unlessEffect: () => unlessEffect2, - unless: () => unless2, - uninterruptibleMask: () => uninterruptibleMask3, - uninterruptible: () => uninterruptible2, - tryPromise: () => tryPromise2, - tryMapPromise: () => tryMapPromise2, - tryMap: () => tryMap2, - try: () => try_3, - transposeOption: () => transposeOption, - transposeMapOption: () => transposeMapOption, - transplant: () => transplant2, - tracerWith: () => tracerWith4, - tracer: () => tracer2, - timeoutTo: () => timeoutTo2, - timeoutOption: () => timeoutOption2, - timeoutFailCause: () => timeoutFailCause2, - timeoutFail: () => timeoutFail2, - timeout: () => timeout2, - timedWith: () => timedWith2, - timed: () => timed2, - tapErrorTag: () => tapErrorTag2, - tapErrorCause: () => tapErrorCause2, - tapError: () => tapError2, - tapDefect: () => tapDefect2, - tapBoth: () => tapBoth2, - tap: () => tap2, - takeWhile: () => takeWhile2, - takeUntil: () => takeUntil2, - tagMetricsScoped: () => tagMetricsScoped2, - tagMetrics: () => tagMetrics2, - sync: () => sync3, - suspend: () => suspend3, - supervised: () => supervised2, - summarized: () => summarized2, - succeedSome: () => succeedSome2, - succeedNone: () => succeedNone2, - succeed: () => succeed6, - step: () => step3, - spanLinks: () => spanLinks2, - spanAnnotations: () => spanAnnotations2, - sleep: () => sleep4, - setFiberRefs: () => setFiberRefs2, - serviceOptional: () => serviceOptional2, - serviceOption: () => serviceOption2, - serviceMembers: () => serviceMembers2, - serviceFunctions: () => serviceFunctions2, - serviceFunctionEffect: () => serviceFunctionEffect2, - serviceFunction: () => serviceFunction2, - serviceConstants: () => serviceConstants2, - sequentialFinalizers: () => sequentialFinalizers2, - scopedWith: () => scopedWith2, - scoped: () => scoped2, - scopeWith: () => scopeWith2, - scope: () => scope2, - scheduleFrom: () => scheduleFrom, - scheduleForked: () => scheduleForked2, - schedule: () => schedule, - sandbox: () => sandbox2, - runtime: () => runtime4, - runSyncExit: () => runSyncExit, - runSync: () => runSync, - runRequestBlock: () => runRequestBlock2, - runPromiseExit: () => runPromiseExit, - runPromise: () => runPromise, - runFork: () => runFork2, - runCallback: () => runCallback, - retryOrElse: () => retryOrElse, - retry: () => retry, - request: () => request, - replicateEffect: () => replicateEffect2, - replicate: () => replicate2, - repeatOrElse: () => repeatOrElse, - repeatN: () => repeatN2, - repeat: () => repeat, - reduceWhile: () => reduceWhile2, - reduceRight: () => reduceRight3, - reduceEffect: () => reduceEffect2, - reduce: () => reduce10, - randomWith: () => randomWith2, - random: () => random3, - raceWith: () => raceWith2, - raceFirst: () => raceFirst2, - raceAll: () => raceAll2, - race: () => race2, - provideServiceEffect: () => provideServiceEffect2, - provideService: () => provideService2, - provide: () => provide2, - promise: () => promise2, - patchRuntimeFlags: () => patchRuntimeFlags, - patchFiberRefs: () => patchFiberRefs2, - partition: () => partition4, - parallelFinalizers: () => parallelFinalizers2, - parallelErrors: () => parallelErrors2, - orElseSucceed: () => orElseSucceed2, - orElseFail: () => orElseFail2, - orElse: () => orElse3, - orDieWith: () => orDieWith2, - orDie: () => orDie2, - optionFromOptional: () => optionFromOptional2, - option: () => option2, - once: () => once3, - onInterrupt: () => onInterrupt2, - onExit: () => onExit3, - onError: () => onError2, - none: () => none9, - never: () => never2, - negate: () => negate2, - metricLabels: () => metricLabels2, - mergeAll: () => mergeAll5, - merge: () => merge6, - matchEffect: () => matchEffect2, - matchCauseEffect: () => matchCauseEffect3, - matchCause: () => matchCause2, - match: () => match10, - mapInputContext: () => mapInputContext2, - mapErrorCause: () => mapErrorCause2, - mapError: () => mapError2, - mapBoth: () => mapBoth3, - mapAccum: () => mapAccum3, - map: () => map11, - makeSpanScoped: () => makeSpanScoped2, - makeSpan: () => makeSpan2, - makeSemaphore: () => makeSemaphore2, - makeLatch: () => makeLatch2, - loop: () => loop2, - logWithLevel: () => logWithLevel2, - logWarning: () => logWarning2, - logTrace: () => logTrace2, - logInfo: () => logInfo2, - logFatal: () => logFatal2, - logError: () => logError2, - logDebug: () => logDebug2, - logAnnotations: () => logAnnotations2, - log: () => log2, - locallyWith: () => locallyWith, - locallyScopedWith: () => locallyScopedWith, - locallyScoped: () => locallyScoped, - locally: () => locally, - linkSpans: () => linkSpans2, - linkSpanCurrent: () => linkSpanCurrent2, - liftPredicate: () => liftPredicate2, - let: () => let_3, - labelMetricsScoped: () => labelMetricsScoped2, - labelMetrics: () => labelMetrics2, - iterate: () => iterate2, - isSuccess: () => isSuccess3, - isFailure: () => isFailure3, - isEffect: () => isEffect2, - intoDeferred: () => intoDeferred2, - interruptibleMask: () => interruptibleMask2, - interruptible: () => interruptible4, - interruptWith: () => interruptWith2, - interrupt: () => interrupt5, - inheritFiberRefs: () => inheritFiberRefs2, - ignoreLogged: () => ignoreLogged2, - ignore: () => ignore2, - if: () => if_2, - head: () => head4, - getRuntimeFlags: () => getRuntimeFlags, - getFiberRefs: () => getFiberRefs, - gen: () => gen2, - functionWithSpan: () => functionWithSpan2, - fromNullable: () => fromNullable3, - fromFiberEffect: () => fromFiberEffect2, - fromFiber: () => fromFiber2, - forkWithErrorHandler: () => forkWithErrorHandler2, - forkScoped: () => forkScoped2, - forkIn: () => forkIn2, - forkDaemon: () => forkDaemon2, - forkAll: () => forkAll2, - fork: () => fork3, - forever: () => forever3, - forEach: () => forEach7, - fnUntraced: () => fnUntraced2, - fn: () => fn, - flipWith: () => flipWith2, - flip: () => flip2, - flatten: () => flatten6, - flatMap: () => flatMap9, - firstSuccessOf: () => firstSuccessOf2, - findFirst: () => findFirst6, - finalizersMask: () => finalizersMask2, - filterOrFail: () => filterOrFail2, - filterOrElse: () => filterOrElse2, - filterOrDieMessage: () => filterOrDieMessage2, - filterOrDie: () => filterOrDie2, - filterMap: () => filterMap5, - filterEffectOrFail: () => filterEffectOrFail2, - filterEffectOrElse: () => filterEffectOrElse2, - filter: () => filter7, - fiberIdWith: () => fiberIdWith2, - fiberId: () => fiberId2, - failSync: () => failSync2, - failCauseSync: () => failCauseSync2, - failCause: () => failCause5, - fail: () => fail5, - exit: () => exit2, - exists: () => exists3, - every: () => every6, - eventually: () => eventually2, - ensuringChildren: () => ensuringChildren2, - ensuringChild: () => ensuringChild2, - ensuring: () => ensuring2, - ensureSuccessType: () => ensureSuccessType, - ensureRequirementsType: () => ensureRequirementsType, - ensureErrorType: () => ensureErrorType, - either: () => either3, - dropWhile: () => dropWhile2, - dropUntil: () => dropUntil2, - disconnect: () => disconnect2, - diffFiberRefs: () => diffFiberRefs2, - dieSync: () => dieSync2, - dieMessage: () => dieMessage2, - die: () => die4, - descriptorWith: () => descriptorWith2, - descriptor: () => descriptor2, - delay: () => delay2, - daemonChildren: () => daemonChildren2, - custom: () => custom2, - currentSpan: () => currentSpan2, - currentPropagatedSpan: () => currentPropagatedSpan2, - currentParentSpan: () => currentParentSpan2, - contextWithEffect: () => contextWithEffect2, - contextWith: () => contextWith2, - context: () => context3, - consoleWith: () => consoleWith2, - console: () => console3, - configProviderWith: () => configProviderWith2, - clockWith: () => clockWith4, - clock: () => clock2, - checkInterruptible: () => checkInterruptible2, - cause: () => cause2, - catchTags: () => catchTags2, - catchTag: () => catchTag2, - catchSomeDefect: () => catchSomeDefect2, - catchSomeCause: () => catchSomeCause2, - catchSome: () => catchSome2, - catchIf: () => catchIf2, - catchAllDefect: () => catchAllDefect2, - catchAllCause: () => catchAllCause2, - catchAll: () => catchAll2, - catch: () => _catch2, - cachedWithTTL: () => cachedWithTTL, - cachedInvalidateWithTTL: () => cachedInvalidateWithTTL2, - cachedFunction: () => cachedFunction2, - cached: () => cached3, - cacheRequestResult: () => cacheRequestResult, - blocked: () => blocked2, - bindTo: () => bindTo3, - bindAll: () => bindAll2, - bind: () => bind3, - awaitAllChildren: () => awaitAllChildren2, - asyncEffect: () => asyncEffect2, - async: () => async, - asVoid: () => asVoid3, - asSomeError: () => asSomeError2, - asSome: () => asSome2, - as: () => as3, - ap: () => ap, - annotateSpans: () => annotateSpans2, - annotateLogsScoped: () => annotateLogsScoped2, - annotateLogs: () => annotateLogs2, - annotateCurrentSpan: () => annotateCurrentSpan2, - andThen: () => andThen4, - allowInterrupt: () => allowInterrupt2, - allWith: () => allWith2, - allSuccesses: () => allSuccesses2, - all: () => all3, - addFinalizer: () => addFinalizer2, - acquireUseRelease: () => acquireUseRelease2, - acquireReleaseInterruptible: () => acquireReleaseInterruptible2, - acquireRelease: () => acquireRelease2, - Tag: () => Tag2, - Service: () => Service, - EffectTypeId: () => EffectTypeId3, - Do: () => Do2 -}); - -// node_modules/effect/dist/esm/internal/clock.js -var ClockSymbolKey = "effect/Clock"; -var ClockTypeId = /* @__PURE__ */ Symbol.for(ClockSymbolKey); -var clockTag = /* @__PURE__ */ GenericTag("effect/Clock"); -var MAX_TIMER_MILLIS = 2 ** 31 - 1; -var globalClockScheduler = { - unsafeSchedule(task, duration) { - const millis2 = toMillis(duration); - if (millis2 > MAX_TIMER_MILLIS) { - return constFalse; - } - let completed = false; - const handle = setTimeout(() => { - completed = true; - task(); - }, millis2); - return () => { - clearTimeout(handle); - return !completed; - }; - } -}; -var performanceNowNanos = /* @__PURE__ */ function() { - const bigint1e62 = /* @__PURE__ */ BigInt(1e6); - if (typeof performance === "undefined" || typeof performance.now !== "function") { - return () => BigInt(Date.now()) * bigint1e62; - } - let origin; - return () => { - if (origin === undefined) { - origin = BigInt(Date.now()) * bigint1e62 - BigInt(Math.round(performance.now() * 1e6)); - } - return origin + BigInt(Math.round(performance.now() * 1e6)); - }; -}(); -var processOrPerformanceNow = /* @__PURE__ */ function() { - const processHrtime = typeof process === "object" && "hrtime" in process && typeof process.hrtime.bigint === "function" ? process.hrtime : undefined; - if (!processHrtime) { - return performanceNowNanos; - } - const origin = /* @__PURE__ */ performanceNowNanos() - /* @__PURE__ */ processHrtime.bigint(); - return () => origin + processHrtime.bigint(); -}(); - -class ClockImpl { - [ClockTypeId] = ClockTypeId; - unsafeCurrentTimeMillis() { - return Date.now(); - } - unsafeCurrentTimeNanos() { - return processOrPerformanceNow(); - } - currentTimeMillis = /* @__PURE__ */ sync(() => this.unsafeCurrentTimeMillis()); - currentTimeNanos = /* @__PURE__ */ sync(() => this.unsafeCurrentTimeNanos()); - scheduler() { - return succeed(globalClockScheduler); - } - sleep(duration) { - return async_((resume) => { - const canceler = globalClockScheduler.unsafeSchedule(() => resume(void_), duration); - return asVoid(sync(canceler)); - }); - } -} -var make18 = () => new ClockImpl; - -// node_modules/effect/dist/esm/Number.js -var Order2 = number3; -var clamp4 = /* @__PURE__ */ clamp(Order2); -var remainder = /* @__PURE__ */ dual(2, (dividend, divisor) => { - const selfDecCount = (dividend.toString().split(".")[1] || "").length; - const divisorDecCount = (divisor.toString().split(".")[1] || "").length; - const decCount = selfDecCount > divisorDecCount ? selfDecCount : divisorDecCount; - const selfInt = parseInt(dividend.toFixed(decCount).replace(".", "")); - const divisorInt = parseInt(divisor.toFixed(decCount).replace(".", "")); - return selfInt % divisorInt / Math.pow(10, decCount); -}); -var parse = (s) => { - if (s === "NaN") { - return some(NaN); - } - if (s === "Infinity") { - return some(Infinity); - } - if (s === "-Infinity") { - return some(-Infinity); - } - if (s.trim() === "") { - return none; - } - const n = Number(s); - return Number.isNaN(n) ? none : some(n); -}; - -// node_modules/effect/dist/esm/RegExp.js -var escape = (string2) => string2.replace(/[/\\^$*+?.()|[\]{}]/g, "\\$&"); - -// node_modules/effect/dist/esm/internal/opCodes/configError.js -var OP_AND = "And"; -var OP_OR = "Or"; -var OP_INVALID_DATA = "InvalidData"; -var OP_MISSING_DATA = "MissingData"; -var OP_SOURCE_UNAVAILABLE = "SourceUnavailable"; -var OP_UNSUPPORTED = "Unsupported"; - -// node_modules/effect/dist/esm/internal/configError.js -var ConfigErrorSymbolKey = "effect/ConfigError"; -var ConfigErrorTypeId = /* @__PURE__ */ Symbol.for(ConfigErrorSymbolKey); -var proto2 = { - _tag: "ConfigError", - [ConfigErrorTypeId]: ConfigErrorTypeId -}; -var And = (self, that) => { - const error = Object.create(proto2); - error._op = OP_AND; - error.left = self; - error.right = that; - Object.defineProperty(error, "toString", { - enumerable: false, - value() { - return `${this.left} and ${this.right}`; - } - }); - Object.defineProperty(error, "message", { - enumerable: false, - get() { - return this.toString(); - } - }); - return error; -}; -var Or = (self, that) => { - const error = Object.create(proto2); - error._op = OP_OR; - error.left = self; - error.right = that; - Object.defineProperty(error, "toString", { - enumerable: false, - value() { - return `${this.left} or ${this.right}`; - } - }); - Object.defineProperty(error, "message", { - enumerable: false, - get() { - return this.toString(); - } - }); - return error; -}; -var InvalidData = (path, message, options = { - pathDelim: "." -}) => { - const error = Object.create(proto2); - error._op = OP_INVALID_DATA; - error.path = path; - error.message = message; - Object.defineProperty(error, "toString", { - enumerable: false, - value() { - const path2 = pipe(this.path, join(options.pathDelim)); - return `(Invalid data at ${path2}: "${this.message}")`; - } - }); - return error; -}; -var MissingData = (path, message, options = { - pathDelim: "." -}) => { - const error = Object.create(proto2); - error._op = OP_MISSING_DATA; - error.path = path; - error.message = message; - Object.defineProperty(error, "toString", { - enumerable: false, - value() { - const path2 = pipe(this.path, join(options.pathDelim)); - return `(Missing data at ${path2}: "${this.message}")`; - } - }); - return error; -}; -var SourceUnavailable = (path, message, cause, options = { - pathDelim: "." -}) => { - const error = Object.create(proto2); - error._op = OP_SOURCE_UNAVAILABLE; - error.path = path; - error.message = message; - error.cause = cause; - Object.defineProperty(error, "toString", { - enumerable: false, - value() { - const path2 = pipe(this.path, join(options.pathDelim)); - return `(Source unavailable at ${path2}: "${this.message}")`; - } - }); - return error; -}; -var Unsupported = (path, message, options = { - pathDelim: "." -}) => { - const error = Object.create(proto2); - error._op = OP_UNSUPPORTED; - error.path = path; - error.message = message; - Object.defineProperty(error, "toString", { - enumerable: false, - value() { - const path2 = pipe(this.path, join(options.pathDelim)); - return `(Unsupported operation at ${path2}: "${this.message}")`; - } - }); - return error; -}; -var prefixed = /* @__PURE__ */ dual(2, (self, prefix) => { - switch (self._op) { - case OP_AND: { - return And(prefixed(self.left, prefix), prefixed(self.right, prefix)); - } - case OP_OR: { - return Or(prefixed(self.left, prefix), prefixed(self.right, prefix)); - } - case OP_INVALID_DATA: { - return InvalidData([...prefix, ...self.path], self.message); - } - case OP_MISSING_DATA: { - return MissingData([...prefix, ...self.path], self.message); - } - case OP_SOURCE_UNAVAILABLE: { - return SourceUnavailable([...prefix, ...self.path], self.message, self.cause); - } - case OP_UNSUPPORTED: { - return Unsupported([...prefix, ...self.path], self.message); - } - } -}); - -// node_modules/effect/dist/esm/internal/configProvider/pathPatch.js -var empty17 = { - _tag: "Empty" -}; -var patch5 = /* @__PURE__ */ dual(2, (path, patch6) => { - let input = of3(patch6); - let output = path; - while (isCons(input)) { - const patch7 = input.head; - switch (patch7._tag) { - case "Empty": { - input = input.tail; - break; - } - case "AndThen": { - input = cons(patch7.first, cons(patch7.second, input.tail)); - break; - } - case "MapName": { - output = map3(output, patch7.f); - input = input.tail; - break; - } - case "Nested": { - output = prepend(output, patch7.name); - input = input.tail; - break; - } - case "Unnested": { - const containsName = pipe(head(output), contains(patch7.name)); - if (containsName) { - output = tailNonEmpty(output); - input = input.tail; - } else { - return left2(MissingData(output, `Expected ${patch7.name} to be in path in ConfigProvider#unnested`)); - } - break; - } - } - } - return right2(output); -}); - -// node_modules/effect/dist/esm/internal/opCodes/config.js -var OP_CONSTANT = "Constant"; -var OP_FAIL2 = "Fail"; -var OP_FALLBACK = "Fallback"; -var OP_DESCRIBED = "Described"; -var OP_LAZY = "Lazy"; -var OP_MAP_OR_FAIL = "MapOrFail"; -var OP_NESTED = "Nested"; -var OP_PRIMITIVE = "Primitive"; -var OP_SEQUENCE = "Sequence"; -var OP_HASHMAP = "HashMap"; -var OP_ZIP_WITH = "ZipWith"; - -// node_modules/effect/dist/esm/internal/configProvider.js -var concat = (l, r) => [...l, ...r]; -var ConfigProviderSymbolKey = "effect/ConfigProvider"; -var ConfigProviderTypeId = /* @__PURE__ */ Symbol.for(ConfigProviderSymbolKey); -var configProviderTag = /* @__PURE__ */ GenericTag("effect/ConfigProvider"); -var FlatConfigProviderSymbolKey = "effect/ConfigProviderFlat"; -var FlatConfigProviderTypeId = /* @__PURE__ */ Symbol.for(FlatConfigProviderSymbolKey); -var make20 = (options) => ({ - [ConfigProviderTypeId]: ConfigProviderTypeId, - pipe() { - return pipeArguments(this, arguments); - }, - ...options -}); -var makeFlat = (options) => ({ - [FlatConfigProviderTypeId]: FlatConfigProviderTypeId, - patch: options.patch, - load: (path, config, split = true) => options.load(path, config, split), - enumerateChildren: options.enumerateChildren -}); -var fromFlat = (flat) => make20({ - load: (config) => flatMap7(fromFlatLoop(flat, empty(), config, false), (chunk) => match2(head(chunk), { - onNone: () => fail2(MissingData(empty(), `Expected a single value having structure: ${config}`)), - onSome: succeed - })), - flattened: flat -}); -var fromEnv = (options) => { - const { - pathDelim, - seqDelim - } = Object.assign({}, { - pathDelim: "_", - seqDelim: "," - }, options); - const makePathString = (path) => pipe(path, join(pathDelim)); - const unmakePathString = (pathString) => pathString.split(pathDelim); - const getEnv = () => typeof process !== "undefined" && ("env" in process) && typeof process.env === "object" ? process.env : {}; - const load = (path, primitive, split = true) => { - const pathString = makePathString(path); - const current = getEnv(); - const valueOpt = pathString in current ? some2(current[pathString]) : none2(); - return pipe(valueOpt, mapError(() => MissingData(path, `Expected ${pathString} to exist in the process context`)), flatMap7((value) => parsePrimitive(value, path, primitive, seqDelim, split))); - }; - const enumerateChildren = (path) => sync(() => { - const current = getEnv(); - const keys3 = Object.keys(current); - const keyPaths = keys3.map((value) => unmakePathString(value.toUpperCase())); - const filteredKeyPaths = keyPaths.filter((keyPath) => { - for (let i = 0;i < path.length; i++) { - const pathComponent = pipe(path, unsafeGet(i)); - const currentElement = keyPath[i]; - if (currentElement === undefined || pathComponent !== currentElement) { - return false; - } - } - return true; - }).flatMap((keyPath) => keyPath.slice(path.length, path.length + 1)); - return fromIterable5(filteredKeyPaths); - }); - return fromFlat(makeFlat({ - load, - enumerateChildren, - patch: empty17 - })); -}; -var extend = (leftDef, rightDef, left3, right3) => { - const leftPad = unfold(left3.length, (index) => index >= right3.length ? none2() : some2([leftDef(index), index + 1])); - const rightPad = unfold(right3.length, (index) => index >= left3.length ? none2() : some2([rightDef(index), index + 1])); - const leftExtension = concat(left3, leftPad); - const rightExtension = concat(right3, rightPad); - return [leftExtension, rightExtension]; -}; -var appendConfigPath = (path, config) => { - let op = config; - if (op._tag === "Nested") { - const out = path.slice(); - while (op._tag === "Nested") { - out.push(op.name); - op = op.config; - } - return out; - } - return path; -}; -var fromFlatLoop = (flat, prefix, config, split) => { - const op = config; - switch (op._tag) { - case OP_CONSTANT: { - return succeed(of(op.value)); - } - case OP_DESCRIBED: { - return suspend(() => fromFlatLoop(flat, prefix, op.config, split)); - } - case OP_FAIL2: { - return fail2(MissingData(prefix, op.message)); - } - case OP_FALLBACK: { - return pipe(suspend(() => fromFlatLoop(flat, prefix, op.first, split)), catchAll((error1) => { - if (op.condition(error1)) { - return pipe(fromFlatLoop(flat, prefix, op.second, split), catchAll((error2) => fail2(Or(error1, error2)))); - } - return fail2(error1); - })); - } - case OP_LAZY: { - return suspend(() => fromFlatLoop(flat, prefix, op.config(), split)); - } - case OP_MAP_OR_FAIL: { - return suspend(() => pipe(fromFlatLoop(flat, prefix, op.original, split), flatMap7(forEachSequential((a) => pipe(op.mapOrFail(a), mapError(prefixed(appendConfigPath(prefix, op.original)))))))); - } - case OP_NESTED: { - return suspend(() => fromFlatLoop(flat, concat(prefix, of(op.name)), op.config, split)); - } - case OP_PRIMITIVE: { - return pipe(patch5(prefix, flat.patch), flatMap7((prefix2) => pipe(flat.load(prefix2, op, split), flatMap7((values3) => { - if (values3.length === 0) { - const name = pipe(last(prefix2), getOrElse(() => "")); - return fail2(MissingData([], `Expected ${op.description} with name ${name}`)); - } - return succeed(values3); - })))); - } - case OP_SEQUENCE: { - return pipe(patch5(prefix, flat.patch), flatMap7((patchedPrefix) => pipe(flat.enumerateChildren(patchedPrefix), flatMap7(indicesFrom), flatMap7((indices) => { - if (indices.length === 0) { - return suspend(() => map9(fromFlatLoop(flat, prefix, op.config, true), of)); - } - return pipe(forEachSequential(indices, (index) => fromFlatLoop(flat, append(prefix, `[${index}]`), op.config, true)), map9((chunkChunk) => { - const flattened = flatten(chunkChunk); - if (flattened.length === 0) { - return of(empty()); - } - return of(flattened); - })); - })))); - } - case OP_HASHMAP: { - return suspend(() => pipe(patch5(prefix, flat.patch), flatMap7((prefix2) => pipe(flat.enumerateChildren(prefix2), flatMap7((keys3) => { - return pipe(keys3, forEachSequential((key) => fromFlatLoop(flat, concat(prefix2, of(key)), op.valueConfig, split)), map9((matrix) => { - if (matrix.length === 0) { - return of(empty8()); - } - return pipe(transpose(matrix), map3((values3) => fromIterable6(zip(fromIterable(keys3), values3)))); - })); - }))))); - } - case OP_ZIP_WITH: { - return suspend(() => pipe(fromFlatLoop(flat, prefix, op.left, split), either2, flatMap7((left3) => pipe(fromFlatLoop(flat, prefix, op.right, split), either2, flatMap7((right3) => { - if (isLeft2(left3) && isLeft2(right3)) { - return fail2(And(left3.left, right3.left)); - } - if (isLeft2(left3) && isRight2(right3)) { - return fail2(left3.left); - } - if (isRight2(left3) && isLeft2(right3)) { - return fail2(right3.left); - } - if (isRight2(left3) && isRight2(right3)) { - const path = pipe(prefix, join(".")); - const fail3 = fromFlatLoopFail(prefix, path); - const [lefts, rights] = extend(fail3, fail3, pipe(left3.right, map3(right2)), pipe(right3.right, map3(right2))); - return pipe(lefts, zip(rights), forEachSequential(([left4, right4]) => pipe(zip2(left4, right4), map9(([left5, right5]) => op.zip(left5, right5))))); - } - throw new Error("BUG: ConfigProvider.fromFlatLoop - please report an issue at https://github.com/Effect-TS/effect/issues"); - }))))); - } - } -}; -var fromFlatLoopFail = (prefix, path) => (index) => left2(MissingData(prefix, `The element at index ${index} in a sequence at path "${path}" was missing`)); -var splitPathString = (text, delim) => { - const split = text.split(new RegExp(`\\s*${escape(delim)}\\s*`)); - return split; -}; -var parsePrimitive = (text, path, primitive, delimiter, split) => { - if (!split) { - return pipe(primitive.parse(text), mapBoth2({ - onFailure: prefixed(path), - onSuccess: of - })); - } - return pipe(splitPathString(text, delimiter), forEachSequential((char) => primitive.parse(char.trim())), mapError(prefixed(path))); -}; -var transpose = (array4) => { - return Object.keys(array4[0]).map((column) => array4.map((row) => row[column])); -}; -var indicesFrom = (quotedIndices) => pipe(forEachSequential(quotedIndices, parseQuotedIndex), mapBoth2({ - onFailure: () => empty(), - onSuccess: sort(Order2) -}), either2, map9(merge)); -var QUOTED_INDEX_REGEX = /^(\[(\d+)\])$/; -var parseQuotedIndex = (str) => { - const match6 = str.match(QUOTED_INDEX_REGEX); - if (match6 !== null) { - const matchedIndex = match6[2]; - return pipe(matchedIndex !== undefined && matchedIndex.length > 0 ? some2(matchedIndex) : none2(), flatMap(parseInteger)); - } - return none2(); -}; -var parseInteger = (str) => { - const parsedIndex = Number.parseInt(str); - return Number.isNaN(parsedIndex) ? none2() : some2(parsedIndex); -}; - -// node_modules/effect/dist/esm/internal/defaultServices/console.js -var TypeId8 = /* @__PURE__ */ Symbol.for("effect/Console"); -var consoleTag = /* @__PURE__ */ GenericTag("effect/Console"); -var defaultConsole = { - [TypeId8]: TypeId8, - assert(condition, ...args) { - return sync(() => { - console.assert(condition, ...args); - }); - }, - clear: /* @__PURE__ */ sync(() => { - console.clear(); - }), - count(label) { - return sync(() => { - console.count(label); - }); - }, - countReset(label) { - return sync(() => { - console.countReset(label); - }); - }, - debug(...args) { - return sync(() => { - console.debug(...args); - }); - }, - dir(item, options) { - return sync(() => { - console.dir(item, options); - }); - }, - dirxml(...args) { - return sync(() => { - console.dirxml(...args); - }); - }, - error(...args) { - return sync(() => { - console.error(...args); - }); - }, - group(options) { - return options?.collapsed ? sync(() => console.groupCollapsed(options?.label)) : sync(() => console.group(options?.label)); - }, - groupEnd: /* @__PURE__ */ sync(() => { - console.groupEnd(); - }), - info(...args) { - return sync(() => { - console.info(...args); - }); - }, - log(...args) { - return sync(() => { - console.log(...args); - }); - }, - table(tabularData, properties) { - return sync(() => { - console.table(tabularData, properties); - }); - }, - time(label) { - return sync(() => console.time(label)); - }, - timeEnd(label) { - return sync(() => console.timeEnd(label)); - }, - timeLog(label, ...args) { - return sync(() => { - console.timeLog(label, ...args); - }); - }, - trace(...args) { - return sync(() => { - console.trace(...args); - }); - }, - warn(...args) { - return sync(() => { - console.warn(...args); - }); - }, - unsafe: console -}; - -// node_modules/effect/dist/esm/internal/random.js -var RandomSymbolKey = "effect/Random"; -var RandomTypeId = /* @__PURE__ */ Symbol.for(RandomSymbolKey); -var randomTag = /* @__PURE__ */ GenericTag("effect/Random"); - -class RandomImpl { - seed; - [RandomTypeId] = RandomTypeId; - PRNG; - constructor(seed) { - this.seed = seed; - this.PRNG = new PCGRandom(seed); - } - get next() { - return sync(() => this.PRNG.number()); - } - get nextBoolean() { - return map9(this.next, (n) => n > 0.5); - } - get nextInt() { - return sync(() => this.PRNG.integer(Number.MAX_SAFE_INTEGER)); - } - nextRange(min2, max2) { - return map9(this.next, (n) => (max2 - min2) * n + min2); - } - nextIntBetween(min2, max2) { - return sync(() => this.PRNG.integer(max2 - min2) + min2); - } - shuffle(elements) { - return shuffleWith(elements, (n) => this.nextIntBetween(0, n)); - } -} -var shuffleWith = (elements, nextIntBounded) => { - return suspend(() => pipe(sync(() => Array.from(elements)), flatMap7((buffer) => { - const numbers = []; - for (let i = buffer.length;i >= 2; i = i - 1) { - numbers.push(i); - } - return pipe(numbers, forEachSequentialDiscard((n) => pipe(nextIntBounded(n), map9((k) => swap(buffer, n - 1, k)))), as(fromIterable2(buffer))); - }))); -}; -var swap = (buffer, index1, index2) => { - const tmp = buffer[index1]; - buffer[index1] = buffer[index2]; - buffer[index2] = tmp; - return buffer; -}; -var make21 = (seed) => new RandomImpl(hash(seed)); - -class FixedRandomImpl { - values; - [RandomTypeId] = RandomTypeId; - index = 0; - constructor(values3) { - this.values = values3; - if (values3.length === 0) { - throw new Error("Requires at least one value"); - } - } - getNextValue() { - const value = this.values[this.index]; - this.index = (this.index + 1) % this.values.length; - return value; - } - get next() { - return sync(() => { - const value = this.getNextValue(); - if (typeof value === "number") { - return Math.max(0, Math.min(1, value)); - } - return hash(value) / 2147483647; - }); - } - get nextBoolean() { - return sync(() => { - const value = this.getNextValue(); - if (typeof value === "boolean") { - return value; - } - return hash(value) % 2 === 0; - }); - } - get nextInt() { - return sync(() => { - const value = this.getNextValue(); - if (typeof value === "number" && Number.isFinite(value)) { - return Math.round(value); - } - return Math.abs(hash(value)); - }); - } - nextRange(min2, max2) { - return map9(this.next, (n) => (max2 - min2) * n + min2); - } - nextIntBetween(min2, max2) { - return sync(() => { - const value = this.getNextValue(); - if (typeof value === "number" && Number.isFinite(value)) { - return Math.max(min2, Math.min(max2 - 1, Math.round(value))); - } - const hash2 = Math.abs(hash(value)); - return min2 + hash2 % (max2 - min2); - }); - } - shuffle(elements) { - return shuffleWith(elements, (n) => this.nextIntBetween(0, n)); - } -} -var fixed = (values3) => new FixedRandomImpl(values3); - -// node_modules/effect/dist/esm/internal/tracer.js -var TracerTypeId = /* @__PURE__ */ Symbol.for("effect/Tracer"); -var make22 = (options) => ({ - [TracerTypeId]: TracerTypeId, - ...options -}); -var tracerTag = /* @__PURE__ */ GenericTag("effect/Tracer"); -var spanTag = /* @__PURE__ */ GenericTag("effect/ParentSpan"); -var randomHexString = /* @__PURE__ */ function() { - const characters = "abcdef0123456789"; - const charactersLength = characters.length; - return function(length) { - let result = ""; - for (let i = 0;i < length; i++) { - result += characters.charAt(Math.floor(Math.random() * charactersLength)); - } - return result; - }; -}(); - -class NativeSpan { - name; - parent; - context; - startTime; - kind; - _tag = "Span"; - spanId; - traceId = "native"; - sampled = true; - status; - attributes; - events = []; - links; - constructor(name, parent, context2, links, startTime, kind) { - this.name = name; - this.parent = parent; - this.context = context2; - this.startTime = startTime; - this.kind = kind; - this.status = { - _tag: "Started", - startTime - }; - this.attributes = new Map; - this.traceId = parent._tag === "Some" ? parent.value.traceId : randomHexString(32); - this.spanId = randomHexString(16); - this.links = Array.from(links); - } - end(endTime, exit2) { - this.status = { - _tag: "Ended", - endTime, - exit: exit2, - startTime: this.status.startTime - }; - } - attribute(key, value) { - this.attributes.set(key, value); - } - event(name, startTime, attributes) { - this.events.push([name, startTime, attributes ?? {}]); - } - addLinks(links) { - this.links.push(...links); - } -} -var nativeTracer = /* @__PURE__ */ make22({ - span: (name, parent, context2, links, startTime, kind) => new NativeSpan(name, parent, context2, links, startTime, kind), - context: (f) => f() -}); -var addSpanStackTrace = (options) => { - if (options?.captureStackTrace === false) { - return options; - } else if (options?.captureStackTrace !== undefined && typeof options.captureStackTrace !== "boolean") { - return options; - } - const limit = Error.stackTraceLimit; - Error.stackTraceLimit = 3; - const traceError = new Error; - Error.stackTraceLimit = limit; - let cache = false; - return { - ...options, - captureStackTrace: () => { - if (cache !== false) { - return cache; - } - if (traceError.stack !== undefined) { - const stack = traceError.stack.split(` -`); - if (stack[3] !== undefined) { - cache = stack[3].trim(); - return cache; - } - } - } - }; -}; -var DisablePropagation = /* @__PURE__ */ Reference2()("effect/Tracer/DisablePropagation", { - defaultValue: constFalse -}); - -// node_modules/effect/dist/esm/internal/defaultServices.js -var liveServices = /* @__PURE__ */ pipe(/* @__PURE__ */ empty4(), /* @__PURE__ */ add2(clockTag, /* @__PURE__ */ make18()), /* @__PURE__ */ add2(consoleTag, defaultConsole), /* @__PURE__ */ add2(randomTag, /* @__PURE__ */ make21(/* @__PURE__ */ Math.random())), /* @__PURE__ */ add2(configProviderTag, /* @__PURE__ */ fromEnv()), /* @__PURE__ */ add2(tracerTag, nativeTracer)); -var currentServices = /* @__PURE__ */ globalValue(/* @__PURE__ */ Symbol.for("effect/DefaultServices/currentServices"), () => fiberRefUnsafeMakeContext(liveServices)); -var sleep = (duration) => { - const decodedDuration = decode(duration); - return clockWith((clock) => clock.sleep(decodedDuration)); -}; -var defaultServicesWith = (f) => withFiberRuntime((fiber) => f(fiber.currentDefaultServices)); -var clockWith = (f) => defaultServicesWith((services) => f(services.unsafeMap.get(clockTag.key))); -var currentTimeMillis = /* @__PURE__ */ clockWith((clock) => clock.currentTimeMillis); -var currentTimeNanos = /* @__PURE__ */ clockWith((clock) => clock.currentTimeNanos); -var withClock = /* @__PURE__ */ dual(2, (effect, c) => fiberRefLocallyWith(currentServices, add2(clockTag, c))(effect)); -var withConfigProvider = /* @__PURE__ */ dual(2, (self, provider) => fiberRefLocallyWith(currentServices, add2(configProviderTag, provider))(self)); -var configProviderWith = (f) => defaultServicesWith((services) => f(services.unsafeMap.get(configProviderTag.key))); -var config = (config2) => configProviderWith((_) => _.load(config2)); -var randomWith = (f) => defaultServicesWith((services) => f(services.unsafeMap.get(randomTag.key))); -var withRandom = /* @__PURE__ */ dual(2, (effect, value) => fiberRefLocallyWith(currentServices, add2(randomTag, value))(effect)); -var tracerWith = (f) => defaultServicesWith((services) => f(services.unsafeMap.get(tracerTag.key))); -var withTracer = /* @__PURE__ */ dual(2, (effect, value) => fiberRefLocallyWith(currentServices, add2(tracerTag, value))(effect)); - -// node_modules/effect/dist/esm/Boolean.js -var not = (self) => !self; - -// node_modules/effect/dist/esm/Effectable.js -var EffectPrototype2 = EffectPrototype; -var CommitPrototype2 = CommitPrototype; -var Base2 = Base; -class Class2 extends Base2 { -} - -// node_modules/effect/dist/esm/internal/executionStrategy.js -var OP_SEQUENTIAL2 = "Sequential"; -var OP_PARALLEL2 = "Parallel"; -var OP_PARALLEL_N = "ParallelN"; -var sequential2 = { - _tag: OP_SEQUENTIAL2 -}; -var parallel2 = { - _tag: OP_PARALLEL2 -}; -var parallelN = (parallelism) => ({ - _tag: OP_PARALLEL_N, - parallelism -}); -var isSequential = (self) => self._tag === OP_SEQUENTIAL2; -var isParallel = (self) => self._tag === OP_PARALLEL2; - -// node_modules/effect/dist/esm/ExecutionStrategy.js -var sequential3 = sequential2; -var parallel3 = parallel2; -var parallelN2 = parallelN; - -// node_modules/effect/dist/esm/internal/fiberRefs.js -function unsafeMake3(fiberRefLocals) { - return new FiberRefsImpl(fiberRefLocals); -} -function empty18() { - return unsafeMake3(new Map); -} -var FiberRefsSym = /* @__PURE__ */ Symbol.for("effect/FiberRefs"); - -class FiberRefsImpl { - locals; - [FiberRefsSym] = FiberRefsSym; - constructor(locals) { - this.locals = locals; - } - pipe() { - return pipeArguments(this, arguments); - } -} -var findAncestor = (_ref, _parentStack, _childStack, _childModified = false) => { - const ref = _ref; - let parentStack = _parentStack; - let childStack = _childStack; - let childModified = _childModified; - let ret = undefined; - while (ret === undefined) { - if (isNonEmptyReadonlyArray(parentStack) && isNonEmptyReadonlyArray(childStack)) { - const parentFiberId = headNonEmpty(parentStack)[0]; - const parentAncestors = tailNonEmpty(parentStack); - const childFiberId = headNonEmpty(childStack)[0]; - const childRefValue = headNonEmpty(childStack)[1]; - const childAncestors = tailNonEmpty(childStack); - if (parentFiberId.startTimeMillis < childFiberId.startTimeMillis) { - childStack = childAncestors; - childModified = true; - } else if (parentFiberId.startTimeMillis > childFiberId.startTimeMillis) { - parentStack = parentAncestors; - } else { - if (parentFiberId.id < childFiberId.id) { - childStack = childAncestors; - childModified = true; - } else if (parentFiberId.id > childFiberId.id) { - parentStack = parentAncestors; - } else { - ret = [childRefValue, childModified]; - } - } - } else { - ret = [ref.initial, true]; - } - } - return ret; -}; -var joinAs = /* @__PURE__ */ dual(3, (self, fiberId2, that) => { - const parentFiberRefs = new Map(self.locals); - that.locals.forEach((childStack, fiberRef) => { - const childValue = childStack[0][1]; - if (!childStack[0][0][symbol2](fiberId2)) { - if (!parentFiberRefs.has(fiberRef)) { - if (equals(childValue, fiberRef.initial)) { - return; - } - parentFiberRefs.set(fiberRef, [[fiberId2, fiberRef.join(fiberRef.initial, childValue)]]); - return; - } - const parentStack = parentFiberRefs.get(fiberRef); - const [ancestor, wasModified] = findAncestor(fiberRef, parentStack, childStack); - if (wasModified) { - const patch6 = fiberRef.diff(ancestor, childValue); - const oldValue = parentStack[0][1]; - const newValue = fiberRef.join(oldValue, fiberRef.patch(patch6)(oldValue)); - if (!equals(oldValue, newValue)) { - let newStack; - const parentFiberId = parentStack[0][0]; - if (parentFiberId[symbol2](fiberId2)) { - newStack = [[parentFiberId, newValue], ...parentStack.slice(1)]; - } else { - newStack = [[fiberId2, newValue], ...parentStack]; - } - parentFiberRefs.set(fiberRef, newStack); - } - } - } - }); - return new FiberRefsImpl(parentFiberRefs); -}); -var forkAs = /* @__PURE__ */ dual(2, (self, childId) => { - const map10 = new Map; - unsafeForkAs(self, map10, childId); - return new FiberRefsImpl(map10); -}); -var unsafeForkAs = (self, map10, fiberId2) => { - self.locals.forEach((stack, fiberRef) => { - const oldValue = stack[0][1]; - const newValue = fiberRef.patch(fiberRef.fork)(oldValue); - if (equals(oldValue, newValue)) { - map10.set(fiberRef, stack); - } else { - map10.set(fiberRef, [[fiberId2, newValue], ...stack]); - } - }); -}; -var fiberRefs = (self) => fromIterable5(self.locals.keys()); -var setAll = (self) => forEachSequentialDiscard(fiberRefs(self), (fiberRef) => fiberRefSet(fiberRef, getOrDefault(self, fiberRef))); -var delete_ = /* @__PURE__ */ dual(2, (self, fiberRef) => { - const locals = new Map(self.locals); - locals.delete(fiberRef); - return new FiberRefsImpl(locals); -}); -var get8 = /* @__PURE__ */ dual(2, (self, fiberRef) => { - if (!self.locals.has(fiberRef)) { - return none2(); - } - return some2(headNonEmpty(self.locals.get(fiberRef))[1]); -}); -var getOrDefault = /* @__PURE__ */ dual(2, (self, fiberRef) => pipe(get8(self, fiberRef), getOrElse(() => fiberRef.initial))); -var updateAs = /* @__PURE__ */ dual(2, (self, { - fiberId: fiberId2, - fiberRef, - value -}) => { - if (self.locals.size === 0) { - return new FiberRefsImpl(new Map([[fiberRef, [[fiberId2, value]]]])); - } - const locals = new Map(self.locals); - unsafeUpdateAs(locals, fiberId2, fiberRef, value); - return new FiberRefsImpl(locals); -}); -var unsafeUpdateAs = (locals, fiberId2, fiberRef, value) => { - const oldStack = locals.get(fiberRef) ?? []; - let newStack; - if (isNonEmptyReadonlyArray(oldStack)) { - const [currentId, currentValue] = headNonEmpty(oldStack); - if (currentId[symbol2](fiberId2)) { - if (equals(currentValue, value)) { - return; - } else { - newStack = [[fiberId2, value], ...oldStack.slice(1)]; - } - } else { - newStack = [[fiberId2, value], ...oldStack]; - } - } else { - newStack = [[fiberId2, value]]; - } - locals.set(fiberRef, newStack); -}; -var updateManyAs = /* @__PURE__ */ dual(2, (self, { - entries: entries2, - forkAs: forkAs2 -}) => { - if (self.locals.size === 0) { - return new FiberRefsImpl(new Map(entries2)); - } - const locals = new Map(self.locals); - if (forkAs2 !== undefined) { - unsafeForkAs(self, locals, forkAs2); - } - entries2.forEach(([fiberRef, values3]) => { - if (values3.length === 1) { - unsafeUpdateAs(locals, values3[0][0], fiberRef, values3[0][1]); - } else { - values3.forEach(([fiberId2, value]) => { - unsafeUpdateAs(locals, fiberId2, fiberRef, value); - }); - } - }); - return new FiberRefsImpl(locals); -}); - -// node_modules/effect/dist/esm/FiberRefs.js -var get9 = get8; -var getOrDefault2 = getOrDefault; -var joinAs2 = joinAs; -var setAll2 = setAll; -var updateManyAs2 = updateManyAs; -var empty19 = empty18; - -// node_modules/effect/dist/esm/internal/fiberRefs/patch.js -var OP_EMPTY2 = "Empty"; -var OP_ADD = "Add"; -var OP_REMOVE = "Remove"; -var OP_UPDATE = "Update"; -var OP_AND_THEN = "AndThen"; -var empty20 = { - _tag: OP_EMPTY2 -}; -var diff5 = (oldValue, newValue) => { - const missingLocals = new Map(oldValue.locals); - let patch6 = empty20; - for (const [fiberRef, pairs] of newValue.locals.entries()) { - const newValue2 = headNonEmpty(pairs)[1]; - const old = missingLocals.get(fiberRef); - if (old !== undefined) { - const oldValue2 = headNonEmpty(old)[1]; - if (!equals(oldValue2, newValue2)) { - patch6 = combine7({ - _tag: OP_UPDATE, - fiberRef, - patch: fiberRef.diff(oldValue2, newValue2) - })(patch6); - } - } else { - patch6 = combine7({ - _tag: OP_ADD, - fiberRef, - value: newValue2 - })(patch6); - } - missingLocals.delete(fiberRef); - } - for (const [fiberRef] of missingLocals.entries()) { - patch6 = combine7({ - _tag: OP_REMOVE, - fiberRef - })(patch6); - } - return patch6; -}; -var combine7 = /* @__PURE__ */ dual(2, (self, that) => ({ - _tag: OP_AND_THEN, - first: self, - second: that -})); -var patch6 = /* @__PURE__ */ dual(3, (self, fiberId2, oldValue) => { - let fiberRefs2 = oldValue; - let patches = of(self); - while (isNonEmptyReadonlyArray(patches)) { - const head3 = headNonEmpty(patches); - const tail = tailNonEmpty(patches); - switch (head3._tag) { - case OP_EMPTY2: { - patches = tail; - break; - } - case OP_ADD: { - fiberRefs2 = updateAs(fiberRefs2, { - fiberId: fiberId2, - fiberRef: head3.fiberRef, - value: head3.value - }); - patches = tail; - break; - } - case OP_REMOVE: { - fiberRefs2 = delete_(fiberRefs2, head3.fiberRef); - patches = tail; - break; - } - case OP_UPDATE: { - const value = getOrDefault(fiberRefs2, head3.fiberRef); - fiberRefs2 = updateAs(fiberRefs2, { - fiberId: fiberId2, - fiberRef: head3.fiberRef, - value: head3.fiberRef.patch(head3.patch)(value) - }); - patches = tail; - break; - } - case OP_AND_THEN: { - patches = prepend(head3.first)(prepend(head3.second)(tail)); - break; - } - } - } - return fiberRefs2; -}); - -// node_modules/effect/dist/esm/FiberRefsPatch.js -var diff6 = diff5; -var patch7 = patch6; - -// node_modules/effect/dist/esm/internal/fiberStatus.js -var FiberStatusSymbolKey = "effect/FiberStatus"; -var FiberStatusTypeId = /* @__PURE__ */ Symbol.for(FiberStatusSymbolKey); -var OP_DONE = "Done"; -var OP_RUNNING = "Running"; -var OP_SUSPENDED = "Suspended"; -var DoneHash = /* @__PURE__ */ string(`${FiberStatusSymbolKey}-${OP_DONE}`); - -class Done { - [FiberStatusTypeId] = FiberStatusTypeId; - _tag = OP_DONE; - [symbol]() { - return DoneHash; - } - [symbol2](that) { - return isFiberStatus(that) && that._tag === OP_DONE; - } -} - -class Running { - runtimeFlags; - [FiberStatusTypeId] = FiberStatusTypeId; - _tag = OP_RUNNING; - constructor(runtimeFlags2) { - this.runtimeFlags = runtimeFlags2; - } - [symbol]() { - return pipe(hash(FiberStatusSymbolKey), combine(hash(this._tag)), combine(hash(this.runtimeFlags)), cached(this)); - } - [symbol2](that) { - return isFiberStatus(that) && that._tag === OP_RUNNING && this.runtimeFlags === that.runtimeFlags; - } -} - -class Suspended { - runtimeFlags; - blockingOn; - [FiberStatusTypeId] = FiberStatusTypeId; - _tag = OP_SUSPENDED; - constructor(runtimeFlags2, blockingOn) { - this.runtimeFlags = runtimeFlags2; - this.blockingOn = blockingOn; - } - [symbol]() { - return pipe(hash(FiberStatusSymbolKey), combine(hash(this._tag)), combine(hash(this.runtimeFlags)), combine(hash(this.blockingOn)), cached(this)); - } - [symbol2](that) { - return isFiberStatus(that) && that._tag === OP_SUSPENDED && this.runtimeFlags === that.runtimeFlags && equals(this.blockingOn, that.blockingOn); - } -} -var done2 = /* @__PURE__ */ new Done; -var running = (runtimeFlags2) => new Running(runtimeFlags2); -var suspended = (runtimeFlags2, blockingOn) => new Suspended(runtimeFlags2, blockingOn); -var isFiberStatus = (u) => hasProperty(u, FiberStatusTypeId); -var isDone = (self) => self._tag === OP_DONE; - -// node_modules/effect/dist/esm/FiberStatus.js -var done3 = done2; -var running2 = running; -var suspended2 = suspended; -var isDone2 = isDone; - -// node_modules/effect/dist/esm/LogLevel.js -var All = logLevelAll; -var Fatal = logLevelFatal; -var Error3 = logLevelError; -var Warning = logLevelWarning; -var Info = logLevelInfo; -var Debug = logLevelDebug; -var Trace = logLevelTrace; -var None3 = logLevelNone; -var Order3 = /* @__PURE__ */ pipe(Order2, /* @__PURE__ */ mapInput2((level) => level.ordinal)); -var greaterThan3 = /* @__PURE__ */ greaterThan(Order3); -var fromLiteral = (literal) => { - switch (literal) { - case "All": - return All; - case "Debug": - return Debug; - case "Error": - return Error3; - case "Fatal": - return Fatal; - case "Info": - return Info; - case "Trace": - return Trace; - case "None": - return None3; - case "Warning": - return Warning; - } -}; - -// node_modules/effect/dist/esm/Micro.js -var TypeId9 = /* @__PURE__ */ Symbol.for("effect/Micro"); -var MicroExitTypeId = /* @__PURE__ */ Symbol.for("effect/Micro/MicroExit"); -var MicroCauseTypeId = /* @__PURE__ */ Symbol.for("effect/Micro/MicroCause"); -var microCauseVariance = { - _E: identity -}; - -class MicroCauseImpl extends globalThis.Error { - _tag; - traces; - [MicroCauseTypeId]; - constructor(_tag, originalError, traces) { - const causeName = `MicroCause.${_tag}`; - let name; - let message; - let stack; - if (originalError instanceof globalThis.Error) { - name = `(${causeName}) ${originalError.name}`; - message = originalError.message; - const messageLines = message.split(` -`).length; - stack = originalError.stack ? `(${causeName}) ${originalError.stack.split(` -`).slice(0, messageLines + 3).join(` -`)}` : `${name}: ${message}`; - } else { - name = causeName; - message = toStringUnknown(originalError, 0); - stack = `${name}: ${message}`; - } - if (traces.length > 0) { - stack += ` - ${traces.join(` - `)}`; - } - super(message); - this._tag = _tag; - this.traces = traces; - this[MicroCauseTypeId] = microCauseVariance; - this.name = name; - this.stack = stack; - } - pipe() { - return pipeArguments(this, arguments); - } - toString() { - return this.stack; - } - [NodeInspectSymbol]() { - return this.stack; - } -} -class Die extends MicroCauseImpl { - defect; - constructor(defect, traces = []) { - super("Die", defect, traces); - this.defect = defect; - } -} -var causeDie = (defect, traces = []) => new Die(defect, traces); - -class Interrupt extends MicroCauseImpl { - constructor(traces = []) { - super("Interrupt", "interrupted", traces); - } -} -var causeInterrupt = (traces = []) => new Interrupt(traces); -var causeIsInterrupt = (self) => self._tag === "Interrupt"; -var MicroFiberTypeId = /* @__PURE__ */ Symbol.for("effect/Micro/MicroFiber"); -var fiberVariance = { - _A: identity, - _E: identity -}; - -class MicroFiberImpl { - context; - interruptible; - [MicroFiberTypeId]; - _stack = []; - _observers = []; - _exit; - _children; - currentOpCount = 0; - constructor(context2, interruptible3 = true) { - this.context = context2; - this.interruptible = interruptible3; - this[MicroFiberTypeId] = fiberVariance; - } - getRef(ref) { - return unsafeGetReference(this.context, ref); - } - addObserver(cb) { - if (this._exit) { - cb(this._exit); - return constVoid; - } - this._observers.push(cb); - return () => { - const index = this._observers.indexOf(cb); - if (index >= 0) { - this._observers.splice(index, 1); - } - }; - } - _interrupted = false; - unsafeInterrupt() { - if (this._exit) { - return; - } - this._interrupted = true; - if (this.interruptible) { - this.evaluate(exitInterrupt2); - } - } - unsafePoll() { - return this._exit; - } - evaluate(effect) { - if (this._exit) { - return; - } else if (this._yielded !== undefined) { - const yielded = this._yielded; - this._yielded = undefined; - yielded(); - } - const exit2 = this.runLoop(effect); - if (exit2 === Yield) { - return; - } - const interruptChildren = fiberMiddleware.interruptChildren && fiberMiddleware.interruptChildren(this); - if (interruptChildren !== undefined) { - return this.evaluate(flatMap8(interruptChildren, () => exit2)); - } - this._exit = exit2; - for (let i = 0;i < this._observers.length; i++) { - this._observers[i](exit2); - } - this._observers.length = 0; - } - runLoop(effect) { - let yielding = false; - let current = effect; - this.currentOpCount = 0; - try { - while (true) { - this.currentOpCount++; - if (!yielding && this.getRef(CurrentScheduler).shouldYield(this)) { - yielding = true; - const prev = current; - current = flatMap8(yieldNow2, () => prev); - } - current = current[evaluate](this); - if (current === Yield) { - const yielded = this._yielded; - if (MicroExitTypeId in yielded) { - this._yielded = undefined; - return yielded; - } - return Yield; - } - } - } catch (error) { - if (!hasProperty(current, evaluate)) { - return exitDie2(`MicroFiber.runLoop: Not a valid effect: ${String(current)}`); - } - return exitDie2(error); - } - } - getCont(symbol3) { - while (true) { - const op = this._stack.pop(); - if (!op) - return; - const cont = op[ensureCont] && op[ensureCont](this); - if (cont) - return { - [symbol3]: cont - }; - if (op[symbol3]) - return op; - } - } - _yielded = undefined; - yieldWith(value) { - this._yielded = value; - return Yield; - } - children() { - return this._children ??= new Set; - } -} -var fiberMiddleware = /* @__PURE__ */ globalValue("effect/Micro/fiberMiddleware", () => ({ - interruptChildren: undefined -})); -var identifier = /* @__PURE__ */ Symbol.for("effect/Micro/identifier"); -var args = /* @__PURE__ */ Symbol.for("effect/Micro/args"); -var evaluate = /* @__PURE__ */ Symbol.for("effect/Micro/evaluate"); -var successCont = /* @__PURE__ */ Symbol.for("effect/Micro/successCont"); -var failureCont = /* @__PURE__ */ Symbol.for("effect/Micro/failureCont"); -var ensureCont = /* @__PURE__ */ Symbol.for("effect/Micro/ensureCont"); -var Yield = /* @__PURE__ */ Symbol.for("effect/Micro/Yield"); -var microVariance = { - _A: identity, - _E: identity, - _R: identity -}; -var MicroProto = { - ...EffectPrototype2, - _op: "Micro", - [TypeId9]: microVariance, - pipe() { - return pipeArguments(this, arguments); - }, - [Symbol.iterator]() { - return new SingleShotGen(new YieldWrap(this)); - }, - toJSON() { - return { - _id: "Micro", - op: this[identifier], - ...args in this ? { - args: this[args] - } : undefined - }; - }, - toString() { - return format(this); - }, - [NodeInspectSymbol]() { - return format(this); - } -}; -function defaultEvaluate(_fiber) { - return exitDie2(`Micro.evaluate: Not implemented`); -} -var makePrimitiveProto = (options) => ({ - ...MicroProto, - [identifier]: options.op, - [evaluate]: options.eval ?? defaultEvaluate, - [successCont]: options.contA, - [failureCont]: options.contE, - [ensureCont]: options.ensure -}); -var makePrimitive = (options) => { - const Proto = makePrimitiveProto(options); - return function() { - const self = Object.create(Proto); - self[args] = options.single === false ? arguments : arguments[0]; - return self; - }; -}; -var makeExit = (options) => { - const Proto = { - ...makePrimitiveProto(options), - [MicroExitTypeId]: MicroExitTypeId, - _tag: options.op, - get [options.prop]() { - return this[args]; - }, - toJSON() { - return { - _id: "MicroExit", - _tag: options.op, - [options.prop]: this[args] - }; - }, - [symbol2](that) { - return isMicroExit(that) && that._tag === options.op && equals(this[args], that[args]); - }, - [symbol]() { - return cached(this, combine(string(options.op))(hash(this[args]))); - } - }; - return function(value) { - const self = Object.create(Proto); - self[args] = value; - self[successCont] = undefined; - self[failureCont] = undefined; - self[ensureCont] = undefined; - return self; - }; -}; -var succeed2 = /* @__PURE__ */ makeExit({ - op: "Success", - prop: "value", - eval(fiber) { - const cont = fiber.getCont(successCont); - return cont ? cont[successCont](this[args], fiber) : fiber.yieldWith(this); - } -}); -var failCause2 = /* @__PURE__ */ makeExit({ - op: "Failure", - prop: "cause", - eval(fiber) { - let cont = fiber.getCont(failureCont); - while (causeIsInterrupt(this[args]) && cont && fiber.interruptible) { - cont = fiber.getCont(failureCont); - } - return cont ? cont[failureCont](this[args], fiber) : fiber.yieldWith(this); - } -}); -var yieldNowWith = /* @__PURE__ */ makePrimitive({ - op: "Yield", - eval(fiber) { - let resumed = false; - fiber.getRef(CurrentScheduler).scheduleTask(() => { - if (resumed) - return; - fiber.evaluate(exitVoid2); - }, this[args] ?? 0); - return fiber.yieldWith(() => { - resumed = true; - }); - } -}); -var yieldNow2 = /* @__PURE__ */ yieldNowWith(0); -var void_2 = /* @__PURE__ */ succeed2(undefined); -var withMicroFiber = /* @__PURE__ */ makePrimitive({ - op: "WithMicroFiber", - eval(fiber) { - return this[args](fiber); - } -}); -var flatMap8 = /* @__PURE__ */ dual(2, (self, f) => { - const onSuccess = Object.create(OnSuccessProto); - onSuccess[args] = self; - onSuccess[successCont] = f; - return onSuccess; -}); -var OnSuccessProto = /* @__PURE__ */ makePrimitiveProto({ - op: "OnSuccess", - eval(fiber) { - fiber._stack.push(this); - return this[args]; - } -}); -var isMicroExit = (u) => hasProperty(u, MicroExitTypeId); -var exitSucceed2 = succeed2; -var exitFailCause2 = failCause2; -var exitInterrupt2 = /* @__PURE__ */ exitFailCause2(/* @__PURE__ */ causeInterrupt()); -var exitDie2 = (defect) => exitFailCause2(causeDie(defect)); -var exitVoid2 = /* @__PURE__ */ exitSucceed2(undefined); -var setImmediate = "setImmediate" in globalThis ? globalThis.setImmediate : (f) => setTimeout(f, 0); - -class MicroSchedulerDefault { - tasks = []; - running = false; - scheduleTask(task, _priority) { - this.tasks.push(task); - if (!this.running) { - this.running = true; - setImmediate(this.afterScheduled); - } - } - afterScheduled = () => { - this.running = false; - this.runTasks(); - }; - runTasks() { - const tasks = this.tasks; - this.tasks = []; - for (let i = 0, len = tasks.length;i < len; i++) { - tasks[i](); - } - } - shouldYield(fiber) { - return fiber.currentOpCount >= fiber.getRef(MaxOpsBeforeYield); - } - flush() { - while (this.tasks.length > 0) { - this.runTasks(); - } - } -} -var updateContext = /* @__PURE__ */ dual(2, (self, f) => withMicroFiber((fiber) => { - const prev = fiber.context; - fiber.context = f(prev); - return onExit2(self, () => { - fiber.context = prev; - return void_2; - }); -})); -var provideContext2 = /* @__PURE__ */ dual(2, (self, provided) => updateContext(self, merge3(provided))); -class MaxOpsBeforeYield extends (/* @__PURE__ */ Reference2()("effect/Micro/currentMaxOpsBeforeYield", { - defaultValue: () => 2048 -})) { -} -class CurrentScheduler extends (/* @__PURE__ */ Reference2()("effect/Micro/currentScheduler", { - defaultValue: () => new MicroSchedulerDefault -})) { -} -var matchCauseEffect2 = /* @__PURE__ */ dual(2, (self, options) => { - const primitive = Object.create(OnSuccessAndFailureProto); - primitive[args] = self; - primitive[successCont] = options.onSuccess; - primitive[failureCont] = options.onFailure; - return primitive; -}); -var OnSuccessAndFailureProto = /* @__PURE__ */ makePrimitiveProto({ - op: "OnSuccessAndFailure", - eval(fiber) { - fiber._stack.push(this); - return this[args]; - } -}); -var onExit2 = /* @__PURE__ */ dual(2, (self, f) => uninterruptibleMask2((restore) => matchCauseEffect2(restore(self), { - onFailure: (cause) => flatMap8(f(exitFailCause2(cause)), () => failCause2(cause)), - onSuccess: (a) => flatMap8(f(exitSucceed2(a)), () => succeed2(a)) -}))); -var setInterruptible = /* @__PURE__ */ makePrimitive({ - op: "SetInterruptible", - ensure(fiber) { - fiber.interruptible = this[args]; - if (fiber._interrupted && fiber.interruptible) { - return () => exitInterrupt2; - } - } -}); -var interruptible3 = (self) => withMicroFiber((fiber) => { - if (fiber.interruptible) - return self; - fiber.interruptible = true; - fiber._stack.push(setInterruptible(false)); - if (fiber._interrupted) - return exitInterrupt2; - return self; -}); -var uninterruptibleMask2 = (f) => withMicroFiber((fiber) => { - if (!fiber.interruptible) - return f(identity); - fiber.interruptible = false; - fiber._stack.push(setInterruptible(true)); - return f(interruptible3); -}); -var runFork = (effect, options) => { - const fiber = new MicroFiberImpl(CurrentScheduler.context(options?.scheduler ?? new MicroSchedulerDefault)); - fiber.evaluate(effect); - if (options?.signal) { - if (options.signal.aborted) { - fiber.unsafeInterrupt(); - } else { - const abort = () => fiber.unsafeInterrupt(); - options.signal.addEventListener("abort", abort, { - once: true - }); - fiber.addObserver(() => options.signal.removeEventListener("abort", abort)); - } - } - return fiber; -}; - -// node_modules/effect/dist/esm/Readable.js -var TypeId10 = /* @__PURE__ */ Symbol.for("effect/Readable"); -var Proto = { - [TypeId10]: TypeId10, - pipe() { - return pipeArguments(this, arguments); - } -}; - -// node_modules/effect/dist/esm/internal/ref.js -var RefTypeId = /* @__PURE__ */ Symbol.for("effect/Ref"); -var refVariance = { - _A: (_) => _ -}; - -class RefImpl extends Class2 { - ref; - commit() { - return this.get; - } - [RefTypeId] = refVariance; - [TypeId10] = TypeId10; - constructor(ref) { - super(); - this.ref = ref; - this.get = sync(() => get6(this.ref)); - } - get; - modify(f) { - return sync(() => { - const current = get6(this.ref); - const [b, a] = f(current); - if (current !== a) { - set2(a)(this.ref); - } - return b; - }); - } -} -var unsafeMake4 = (value) => new RefImpl(make11(value)); -var make23 = (value) => sync(() => unsafeMake4(value)); -var get10 = (self) => self.get; -var set4 = /* @__PURE__ */ dual(2, (self, value) => self.modify(() => [undefined, value])); -var getAndSet = /* @__PURE__ */ dual(2, (self, value) => self.modify((a) => [a, value])); -var modify3 = /* @__PURE__ */ dual(2, (self, f) => self.modify(f)); -var update2 = /* @__PURE__ */ dual(2, (self, f) => self.modify((a) => [undefined, f(a)])); - -// node_modules/effect/dist/esm/Ref.js -var make24 = make23; -var get11 = get10; -var getAndSet2 = getAndSet; -var update3 = update2; - -// node_modules/effect/dist/esm/Scheduler.js -class SchedulerRunner { - scheduleDrain; - running = false; - tasks = /* @__PURE__ */ new PriorityBuckets; - constructor(scheduleDrain) { - this.scheduleDrain = scheduleDrain; - } - starveInternal = (depth) => { - const tasks = this.tasks.buckets; - this.tasks.buckets = []; - for (const [_, toRun] of tasks) { - for (let i = 0;i < toRun.length; i++) { - toRun[i](); - } - } - if (this.tasks.buckets.length === 0) { - this.running = false; - } else { - this.starve(depth); - } - }; - starve(depth = 0) { - this.scheduleDrain(depth, this.starveInternal); - } - scheduleTask(task, priority) { - this.tasks.scheduleTask(task, priority); - if (!this.running) { - this.running = true; - this.starve(); - } - } - static cached(scheduleDrain) { - const fallback = new SchedulerRunner(scheduleDrain); - const runners = new WeakMap; - return (fiber) => { - if (fiber === undefined) { - return fallback; - } - let runner = runners.get(fiber); - if (runner === undefined) { - runner = new SchedulerRunner(scheduleDrain); - runners.set(fiber, runner); - } - return runner; - }; - } -} - -class PriorityBuckets { - buckets = []; - scheduleTask(task, priority) { - const length = this.buckets.length; - let bucket = undefined; - let index = 0; - for (;index < length; index++) { - if (this.buckets[index][0] <= priority) { - bucket = this.buckets[index]; - } else { - break; - } - } - if (bucket && bucket[0] === priority) { - bucket[1].push(task); - } else if (index === length) { - this.buckets.push([priority, [task]]); - } else { - this.buckets.splice(index, 0, [priority, [task]]); - } - } -} - -class MixedScheduler { - maxNextTickBeforeTimer; - getRunner = /* @__PURE__ */ SchedulerRunner.cached((depth, drain) => { - if (depth >= this.maxNextTickBeforeTimer) { - setTimeout(() => drain(0), 0); - } else { - Promise.resolve(undefined).then(() => drain(depth + 1)); - } - }); - constructor(maxNextTickBeforeTimer) { - this.maxNextTickBeforeTimer = maxNextTickBeforeTimer; - } - shouldYield(fiber) { - return fiber.currentOpCount > fiber.getFiberRef(currentMaxOpsBeforeYield) ? fiber.getFiberRef(currentSchedulingPriority) : false; - } - scheduleTask(task, priority, fiber) { - this.getRunner(fiber).scheduleTask(task, priority); - } -} -var defaultScheduler = /* @__PURE__ */ globalValue(/* @__PURE__ */ Symbol.for("effect/Scheduler/defaultScheduler"), () => new MixedScheduler(2048)); - -class SyncScheduler { - tasks = /* @__PURE__ */ new PriorityBuckets; - deferred = false; - scheduleTask(task, priority, fiber) { - if (this.deferred) { - defaultScheduler.scheduleTask(task, priority, fiber); - } else { - this.tasks.scheduleTask(task, priority); - } - } - shouldYield(fiber) { - return fiber.currentOpCount > fiber.getFiberRef(currentMaxOpsBeforeYield) ? fiber.getFiberRef(currentSchedulingPriority) : false; - } - flush() { - while (this.tasks.buckets.length > 0) { - const tasks = this.tasks.buckets; - this.tasks.buckets = []; - for (const [_, toRun] of tasks) { - for (let i = 0;i < toRun.length; i++) { - toRun[i](); - } - } - } - this.deferred = true; - } -} -var currentScheduler = /* @__PURE__ */ globalValue(/* @__PURE__ */ Symbol.for("effect/FiberRef/currentScheduler"), () => fiberRefUnsafeMake(defaultScheduler)); -var withScheduler = /* @__PURE__ */ dual(2, (self, scheduler) => fiberRefLocally(self, currentScheduler, scheduler)); - -// node_modules/effect/dist/esm/internal/completedRequestMap.js -var currentRequestMap = /* @__PURE__ */ globalValue(/* @__PURE__ */ Symbol.for("effect/FiberRef/currentRequestMap"), () => fiberRefUnsafeMake(new Map)); - -// node_modules/effect/dist/esm/internal/concurrency.js -var match7 = (concurrency, sequential4, unbounded, bounded) => { - switch (concurrency) { - case undefined: - return sequential4(); - case "unbounded": - return unbounded(); - case "inherit": - return fiberRefGetWith(currentConcurrency, (concurrency2) => concurrency2 === "unbounded" ? unbounded() : concurrency2 > 1 ? bounded(concurrency2) : sequential4()); - default: - return concurrency > 1 ? bounded(concurrency) : sequential4(); - } -}; -var matchSimple = (concurrency, sequential4, concurrent) => { - switch (concurrency) { - case undefined: - return sequential4(); - case "unbounded": - return concurrent(); - case "inherit": - return fiberRefGetWith(currentConcurrency, (concurrency2) => concurrency2 === "unbounded" || concurrency2 > 1 ? concurrent() : sequential4()); - default: - return concurrency > 1 ? concurrent() : sequential4(); - } -}; - -// node_modules/effect/dist/esm/Clock.js -var sleep2 = sleep; -var currentTimeMillis2 = currentTimeMillis; -var currentTimeNanos2 = currentTimeNanos; -var clockWith2 = clockWith; -var Clock = clockTag; - -// node_modules/effect/dist/esm/internal/logSpan.js -var make25 = (label, startTime) => ({ - label, - startTime -}); -var formatLabel = (key) => key.replace(/[\s="]/g, "_"); -var render = (now) => (self) => { - const label = formatLabel(self.label); - return `${label}=${now - self.startTime}ms`; -}; - -// node_modules/effect/dist/esm/LogSpan.js -var make26 = make25; - -// node_modules/effect/dist/esm/Tracer.js -var tracerWith2 = tracerWith; - -// node_modules/effect/dist/esm/internal/metric/label.js -var MetricLabelSymbolKey = "effect/MetricLabel"; -var MetricLabelTypeId = /* @__PURE__ */ Symbol.for(MetricLabelSymbolKey); - -class MetricLabelImpl { - key; - value; - [MetricLabelTypeId] = MetricLabelTypeId; - _hash; - constructor(key, value) { - this.key = key; - this.value = value; - this._hash = string(MetricLabelSymbolKey + this.key + this.value); - } - [symbol]() { - return this._hash; - } - [symbol2](that) { - return isMetricLabel(that) && this.key === that.key && this.value === that.value; - } - pipe() { - return pipeArguments(this, arguments); - } -} -var make27 = (key, value) => { - return new MetricLabelImpl(key, value); -}; -var isMetricLabel = (u) => hasProperty(u, MetricLabelTypeId); - -// node_modules/effect/dist/esm/internal/core-effect.js -var annotateLogs = /* @__PURE__ */ dual((args2) => isEffect(args2[0]), function() { - const args2 = arguments; - return fiberRefLocallyWith(args2[0], currentLogAnnotations, typeof args2[1] === "string" ? set3(args2[1], args2[2]) : (annotations) => Object.entries(args2[1]).reduce((acc, [key, value]) => set3(acc, key, value), annotations)); -}); -var asSome = (self) => map9(self, some2); -var asSomeError = (self) => mapError(self, some2); -var try_2 = (arg) => { - let evaluate2; - let onFailure = undefined; - if (typeof arg === "function") { - evaluate2 = arg; - } else { - evaluate2 = arg.try; - onFailure = arg.catch; - } - return suspend(() => { - try { - return succeed(internalCall(evaluate2)); - } catch (error) { - return fail2(onFailure ? internalCall(() => onFailure(error)) : new UnknownException(error, "An unknown error occurred in Effect.try")); - } - }); -}; -var _catch = /* @__PURE__ */ dual(3, (self, tag, options) => catchAll(self, (e) => { - if (hasProperty(e, tag) && e[tag] === options.failure) { - return options.onFailure(e); - } - return fail2(e); -})); -var catchAllDefect = /* @__PURE__ */ dual(2, (self, f) => catchAllCause(self, (cause) => { - const option = find(cause, (_) => isDieType(_) ? some2(_) : none2()); - switch (option._tag) { - case "None": { - return failCause(cause); - } - case "Some": { - return f(option.value.defect); - } - } -})); -var catchSomeCause = /* @__PURE__ */ dual(2, (self, f) => matchCauseEffect(self, { - onFailure: (cause) => { - const option = f(cause); - switch (option._tag) { - case "None": { - return failCause(cause); - } - case "Some": { - return option.value; - } - } - }, - onSuccess: succeed -})); -var catchSomeDefect = /* @__PURE__ */ dual(2, (self, pf) => catchAllCause(self, (cause) => { - const option = find(cause, (_) => isDieType(_) ? some2(_) : none2()); - switch (option._tag) { - case "None": { - return failCause(cause); - } - case "Some": { - const optionEffect = pf(option.value.defect); - return optionEffect._tag === "Some" ? optionEffect.value : failCause(cause); - } - } -})); -var catchTag = /* @__PURE__ */ dual((args2) => isEffect(args2[0]), (self, ...args2) => { - const f = args2[args2.length - 1]; - let predicate; - if (args2.length === 2) { - predicate = isTagged(args2[0]); - } else { - predicate = (e) => { - const tag = hasProperty(e, "_tag") ? e["_tag"] : undefined; - if (!tag) - return false; - for (let i = 0;i < args2.length - 1; i++) { - if (args2[i] === tag) - return true; - } - return false; - }; - } - return catchIf(self, predicate, f); -}); -var catchTags = /* @__PURE__ */ dual(2, (self, cases) => { - let keys3; - return catchIf(self, (e) => { - keys3 ??= Object.keys(cases); - return hasProperty(e, "_tag") && isString(e["_tag"]) && keys3.includes(e["_tag"]); - }, (e) => cases[e["_tag"]](e)); -}); -var cause = (self) => matchCause(self, { - onFailure: identity, - onSuccess: () => empty16 -}); -var clockWith3 = clockWith2; -var clock = /* @__PURE__ */ clockWith3(succeed); -var delay = /* @__PURE__ */ dual(2, (self, duration) => zipRight(sleep2(duration), self)); -var descriptorWith = (f) => withFiberRuntime((state, status) => f({ - id: state.id(), - status, - interruptors: interruptors(state.getFiberRef(currentInterruptedCause)) -})); -var allowInterrupt = /* @__PURE__ */ descriptorWith((descriptor) => size3(descriptor.interruptors) > 0 ? interrupt2 : void_); -var descriptor = /* @__PURE__ */ descriptorWith(succeed); -var diffFiberRefs = (self) => summarized(self, fiberRefs2, diff5); -var diffFiberRefsAndRuntimeFlags = (self) => summarized(self, zip2(fiberRefs2, runtimeFlags), ([refs, flags], [refsNew, flagsNew]) => [diff5(refs, refsNew), diff4(flags, flagsNew)]); -var Do = /* @__PURE__ */ succeed({}); -var bind2 = /* @__PURE__ */ bind(map9, flatMap7); -var bindTo2 = /* @__PURE__ */ bindTo(map9); -var let_2 = /* @__PURE__ */ let_(map9); -var dropUntil = /* @__PURE__ */ dual(2, (elements, predicate) => suspend(() => { - const iterator = elements[Symbol.iterator](); - const builder = []; - let next; - let dropping = succeed(false); - let i = 0; - while ((next = iterator.next()) && !next.done) { - const a = next.value; - const index = i++; - dropping = flatMap7(dropping, (bool) => { - if (bool) { - builder.push(a); - return succeed(true); - } - return predicate(a, index); - }); - } - return map9(dropping, () => builder); -})); -var dropWhile = /* @__PURE__ */ dual(2, (elements, predicate) => suspend(() => { - const iterator = elements[Symbol.iterator](); - const builder = []; - let next; - let dropping = succeed(true); - let i = 0; - while ((next = iterator.next()) && !next.done) { - const a = next.value; - const index = i++; - dropping = flatMap7(dropping, (d) => map9(d ? predicate(a, index) : succeed(false), (b) => { - if (!b) { - builder.push(a); - } - return b; - })); - } - return map9(dropping, () => builder); -})); -var contextWith = (f) => map9(context(), f); -var eventually = (self) => orElse2(self, () => flatMap7(yieldNow(), () => eventually(self))); -var filterMap4 = /* @__PURE__ */ dual(2, (elements, pf) => map9(forEachSequential(elements, identity), filterMap2(pf))); -var filterOrDie = /* @__PURE__ */ dual(3, (self, predicate, orDieWith2) => filterOrElse(self, predicate, (a) => dieSync(() => orDieWith2(a)))); -var filterOrDieMessage = /* @__PURE__ */ dual(3, (self, predicate, message) => filterOrElse(self, predicate, () => dieMessage(message))); -var filterOrElse = /* @__PURE__ */ dual(3, (self, predicate, orElse3) => flatMap7(self, (a) => predicate(a) ? succeed(a) : orElse3(a))); -var liftPredicate = /* @__PURE__ */ dual(3, (self, predicate, orFailWith) => suspend(() => predicate(self) ? succeed(self) : fail2(orFailWith(self)))); -var filterOrFail = /* @__PURE__ */ dual((args2) => isEffect(args2[0]), (self, predicate, orFailWith) => filterOrElse(self, predicate, (a) => orFailWith === undefined ? fail2(new NoSuchElementException) : failSync(() => orFailWith(a)))); -var findFirst4 = /* @__PURE__ */ dual(2, (elements, predicate) => suspend(() => { - const iterator = elements[Symbol.iterator](); - const next = iterator.next(); - if (!next.done) { - return findLoop(iterator, 0, predicate, next.value); - } - return succeed(none2()); -})); -var findLoop = (iterator, index, f, value) => flatMap7(f(value, index), (result) => { - if (result) { - return succeed(some2(value)); - } - const next = iterator.next(); - if (!next.done) { - return findLoop(iterator, index + 1, f, next.value); - } - return succeed(none2()); -}); -var firstSuccessOf = (effects) => suspend(() => { - const list = fromIterable2(effects); - if (!isNonEmpty(list)) { - return dieSync(() => new IllegalArgumentException(`Received an empty collection of effects`)); - } - return pipe(tailNonEmpty2(list), reduce(headNonEmpty2(list), (left3, right3) => orElse2(left3, () => right3))); -}); -var flipWith = /* @__PURE__ */ dual(2, (self, f) => flip(f(flip(self)))); -var match8 = /* @__PURE__ */ dual(2, (self, options) => matchEffect(self, { - onFailure: (e) => succeed(options.onFailure(e)), - onSuccess: (a) => succeed(options.onSuccess(a)) -})); -var every4 = /* @__PURE__ */ dual(2, (elements, predicate) => suspend(() => forAllLoop(elements[Symbol.iterator](), 0, predicate))); -var forAllLoop = (iterator, index, f) => { - const next = iterator.next(); - return next.done ? succeed(true) : flatMap7(f(next.value, index), (b) => b ? forAllLoop(iterator, index + 1, f) : succeed(b)); -}; -var forever = (self) => { - const loop = flatMap7(flatMap7(self, () => yieldNow()), () => loop); - return loop; -}; -var fiberRefs2 = /* @__PURE__ */ withFiberRuntime((state) => succeed(state.getFiberRefs())); -var head3 = (self) => flatMap7(self, (as2) => { - const iterator = as2[Symbol.iterator](); - const next = iterator.next(); - if (next.done) { - return fail2(new NoSuchElementException); - } - return succeed(next.value); -}); -var ignore = (self) => match8(self, { - onFailure: constVoid, - onSuccess: constVoid -}); -var ignoreLogged = (self) => matchCauseEffect(self, { - onFailure: (cause2) => logDebug(cause2, "An error was silently ignored because it is not anticipated to be useful"), - onSuccess: () => void_ -}); -var inheritFiberRefs = (childFiberRefs) => updateFiberRefs((parentFiberId, parentFiberRefs) => joinAs2(parentFiberRefs, parentFiberId, childFiberRefs)); -var isFailure = (self) => match8(self, { - onFailure: constTrue, - onSuccess: constFalse -}); -var isSuccess = (self) => match8(self, { - onFailure: constFalse, - onSuccess: constTrue -}); -var iterate = (initial, options) => suspend(() => { - if (options.while(initial)) { - return flatMap7(options.body(initial), (z2) => iterate(z2, options)); - } - return succeed(initial); -}); -var logWithLevel = (level) => (...message) => { - const levelOption = fromNullable(level); - let cause2 = undefined; - for (let i = 0, len = message.length;i < len; i++) { - const msg = message[i]; - if (isCause(msg)) { - if (cause2 !== undefined) { - cause2 = sequential(cause2, msg); - } else { - cause2 = msg; - } - message = [...message.slice(0, i), ...message.slice(i + 1)]; - i--; - } - } - if (cause2 === undefined) { - cause2 = empty16; - } - return withFiberRuntime((fiberState) => { - fiberState.log(message, cause2, levelOption); - return void_; - }); -}; -var log = /* @__PURE__ */ logWithLevel(); -var logTrace = /* @__PURE__ */ logWithLevel(Trace); -var logDebug = /* @__PURE__ */ logWithLevel(Debug); -var logInfo = /* @__PURE__ */ logWithLevel(Info); -var logWarning = /* @__PURE__ */ logWithLevel(Warning); -var logError = /* @__PURE__ */ logWithLevel(Error3); -var logFatal = /* @__PURE__ */ logWithLevel(Fatal); -var withLogSpan = /* @__PURE__ */ dual(2, (effect, label) => flatMap7(currentTimeMillis2, (now) => fiberRefLocallyWith(effect, currentLogSpan, prepend3(make26(label, now))))); -var logAnnotations = /* @__PURE__ */ fiberRefGet(currentLogAnnotations); -var loop = (initial, options) => options.discard ? loopDiscard(initial, options.while, options.step, options.body) : map9(loopInternal(initial, options.while, options.step, options.body), fromIterable); -var loopInternal = (initial, cont, inc, body) => suspend(() => cont(initial) ? flatMap7(body(initial), (a) => map9(loopInternal(inc(initial), cont, inc, body), prepend3(a))) : sync(() => empty9())); -var loopDiscard = (initial, cont, inc, body) => suspend(() => cont(initial) ? flatMap7(body(initial), () => loopDiscard(inc(initial), cont, inc, body)) : void_); -var mapAccum2 = /* @__PURE__ */ dual(3, (elements, initial, f) => suspend(() => { - const iterator = elements[Symbol.iterator](); - const builder = []; - let result = succeed(initial); - let next; - let i = 0; - while (!(next = iterator.next()).done) { - const index = i++; - const value = next.value; - result = flatMap7(result, (state) => map9(f(state, value, index), ([z, b]) => { - builder.push(b); - return z; - })); - } - return map9(result, (z) => [z, builder]); -})); -var mapErrorCause = /* @__PURE__ */ dual(2, (self, f) => matchCauseEffect(self, { - onFailure: (c) => failCauseSync(() => f(c)), - onSuccess: succeed -})); -var memoize = (self) => pipe(deferredMake(), flatMap7((deferred) => pipe(diffFiberRefsAndRuntimeFlags(self), intoDeferred(deferred), once, map9((complete) => zipRight(complete, pipe(deferredAwait(deferred), flatMap7(([patch8, a]) => as(zip2(patchFiberRefs(patch8[0]), updateRuntimeFlags(patch8[1])), a)))))))); -var merge5 = (self) => matchEffect(self, { - onFailure: (e) => succeed(e), - onSuccess: succeed -}); -var negate = (self) => map9(self, (b) => !b); -var none6 = (self) => flatMap7(self, (option) => { - switch (option._tag) { - case "None": - return void_; - case "Some": - return fail2(new NoSuchElementException); - } -}); -var once = (self) => map9(make24(true), (ref) => asVoid(whenEffect(self, getAndSet2(ref, false)))); -var option = (self) => matchEffect(self, { - onFailure: () => succeed(none2()), - onSuccess: (a) => succeed(some2(a)) -}); -var orElseFail = /* @__PURE__ */ dual(2, (self, evaluate2) => orElse2(self, () => failSync(evaluate2))); -var orElseSucceed = /* @__PURE__ */ dual(2, (self, evaluate2) => orElse2(self, () => sync(evaluate2))); -var parallelErrors = (self) => matchCauseEffect(self, { - onFailure: (cause2) => { - const errors = fromIterable(failures(cause2)); - return errors.length === 0 ? failCause(cause2) : fail2(errors); - }, - onSuccess: succeed -}); -var patchFiberRefs = (patch8) => updateFiberRefs((fiberId2, fiberRefs3) => pipe(patch8, patch6(fiberId2, fiberRefs3))); -var promise = (evaluate2) => evaluate2.length >= 1 ? async_((resolve, signal) => { - try { - evaluate2(signal).then((a) => resolve(succeed(a)), (e) => resolve(die2(e))); - } catch (e) { - resolve(die2(e)); - } -}) : async_((resolve) => { - try { - evaluate2().then((a) => resolve(succeed(a)), (e) => resolve(die2(e))); - } catch (e) { - resolve(die2(e)); - } -}); -var provideService = /* @__PURE__ */ dual(3, (self, tag, service) => contextWithEffect((env) => provideContext(self, add2(env, tag, service)))); -var provideServiceEffect = /* @__PURE__ */ dual(3, (self, tag, effect) => contextWithEffect((env) => flatMap7(effect, (service) => provideContext(self, pipe(env, add2(tag, service)))))); -var random2 = /* @__PURE__ */ randomWith(succeed); -var reduce8 = /* @__PURE__ */ dual(3, (elements, zero2, f) => fromIterable(elements).reduce((acc, el, i) => flatMap7(acc, (a) => f(a, el, i)), succeed(zero2))); -var reduceRight2 = /* @__PURE__ */ dual(3, (elements, zero2, f) => fromIterable(elements).reduceRight((acc, el, i) => flatMap7(acc, (a) => f(el, a, i)), succeed(zero2))); -var reduceWhile = /* @__PURE__ */ dual(3, (elements, zero2, options) => flatMap7(sync(() => elements[Symbol.iterator]()), (iterator) => reduceWhileLoop(iterator, 0, zero2, options.while, options.body))); -var reduceWhileLoop = (iterator, index, state, predicate, f) => { - const next = iterator.next(); - if (!next.done && predicate(state)) { - return flatMap7(f(state, next.value, index), (nextState) => reduceWhileLoop(iterator, index + 1, nextState, predicate, f)); - } - return succeed(state); -}; -var repeatN = /* @__PURE__ */ dual(2, (self, n) => suspend(() => repeatNLoop(self, n))); -var repeatNLoop = (self, n) => flatMap7(self, (a) => n <= 0 ? succeed(a) : zipRight(yieldNow(), repeatNLoop(self, n - 1))); -var sandbox = (self) => matchCauseEffect(self, { - onFailure: fail2, - onSuccess: succeed -}); -var setFiberRefs = (fiberRefs3) => suspend(() => setAll2(fiberRefs3)); -var sleep3 = sleep2; -var succeedNone = /* @__PURE__ */ succeed(/* @__PURE__ */ none2()); -var succeedSome = (value) => succeed(some2(value)); -var summarized = /* @__PURE__ */ dual(3, (self, summary, f) => flatMap7(summary, (start) => flatMap7(self, (value) => map9(summary, (end) => [f(start, end), value])))); -var tagMetrics = /* @__PURE__ */ dual((args2) => isEffect(args2[0]), function() { - return labelMetrics(arguments[0], typeof arguments[1] === "string" ? [make27(arguments[1], arguments[2])] : Object.entries(arguments[1]).map(([k, v]) => make27(k, v))); -}); -var labelMetrics = /* @__PURE__ */ dual(2, (self, labels) => fiberRefLocallyWith(self, currentMetricLabels, (old) => union(old, labels))); -var takeUntil = /* @__PURE__ */ dual(2, (elements, predicate) => suspend(() => { - const iterator = elements[Symbol.iterator](); - const builder = []; - let next; - let effect = succeed(false); - let i = 0; - while ((next = iterator.next()) && !next.done) { - const a = next.value; - const index = i++; - effect = flatMap7(effect, (bool) => { - if (bool) { - return succeed(true); - } - builder.push(a); - return predicate(a, index); - }); - } - return map9(effect, () => builder); -})); -var takeWhile = /* @__PURE__ */ dual(2, (elements, predicate) => suspend(() => { - const iterator = elements[Symbol.iterator](); - const builder = []; - let next; - let taking = succeed(true); - let i = 0; - while ((next = iterator.next()) && !next.done) { - const a = next.value; - const index = i++; - taking = flatMap7(taking, (taking2) => pipe(taking2 ? predicate(a, index) : succeed(false), map9((bool) => { - if (bool) { - builder.push(a); - } - return bool; - }))); - } - return map9(taking, () => builder); -})); -var tapBoth = /* @__PURE__ */ dual(2, (self, { - onFailure, - onSuccess -}) => matchCauseEffect(self, { - onFailure: (cause2) => { - const either3 = failureOrCause(cause2); - switch (either3._tag) { - case "Left": { - return zipRight(onFailure(either3.left), failCause(cause2)); - } - case "Right": { - return failCause(cause2); - } - } - }, - onSuccess: (a) => as(onSuccess(a), a) -})); -var tapDefect = /* @__PURE__ */ dual(2, (self, f) => catchAllCause(self, (cause2) => match2(keepDefects(cause2), { - onNone: () => failCause(cause2), - onSome: (a) => zipRight(f(a), failCause(cause2)) -}))); -var tapError = /* @__PURE__ */ dual(2, (self, f) => matchCauseEffect(self, { - onFailure: (cause2) => { - const either3 = failureOrCause(cause2); - switch (either3._tag) { - case "Left": - return zipRight(f(either3.left), failCause(cause2)); - case "Right": - return failCause(cause2); - } - }, - onSuccess: succeed -})); -var tapErrorTag = /* @__PURE__ */ dual(3, (self, k, f) => tapError(self, (e) => { - if (isTagged(e, k)) { - return f(e); - } - return void_; -})); -var tapErrorCause = /* @__PURE__ */ dual(2, (self, f) => matchCauseEffect(self, { - onFailure: (cause2) => zipRight(f(cause2), failCause(cause2)), - onSuccess: succeed -})); -var timed = (self) => timedWith(self, currentTimeNanos2); -var timedWith = /* @__PURE__ */ dual(2, (self, nanos2) => summarized(self, nanos2, (start, end) => nanos(end - start))); -var tracerWith3 = tracerWith2; -var tracer = /* @__PURE__ */ tracerWith3(succeed); -var tryPromise = (arg) => { - let evaluate2; - let catcher = undefined; - if (typeof arg === "function") { - evaluate2 = arg; - } else { - evaluate2 = arg.try; - catcher = arg.catch; - } - const fail3 = (e) => catcher ? failSync(() => catcher(e)) : fail2(new UnknownException(e, "An unknown error occurred in Effect.tryPromise")); - if (evaluate2.length >= 1) { - return async_((resolve, signal) => { - try { - evaluate2(signal).then((a) => resolve(succeed(a)), (e) => resolve(fail3(e))); - } catch (e) { - resolve(fail3(e)); - } - }); - } - return async_((resolve) => { - try { - evaluate2().then((a) => resolve(succeed(a)), (e) => resolve(fail3(e))); - } catch (e) { - resolve(fail3(e)); - } - }); -}; -var tryMap = /* @__PURE__ */ dual(2, (self, options) => flatMap7(self, (a) => try_2({ - try: () => options.try(a), - catch: options.catch -}))); -var tryMapPromise = /* @__PURE__ */ dual(2, (self, options) => flatMap7(self, (a) => tryPromise({ - try: options.try.length >= 1 ? (signal) => options.try(a, signal) : () => options.try(a), - catch: options.catch -}))); -var unless = /* @__PURE__ */ dual(2, (self, condition) => suspend(() => condition() ? succeedNone : asSome(self))); -var unlessEffect = /* @__PURE__ */ dual(2, (self, condition) => flatMap7(condition, (b) => b ? succeedNone : asSome(self))); -var unsandbox = (self) => mapErrorCause(self, flatten3); -var updateFiberRefs = (f) => withFiberRuntime((state) => { - state.setFiberRefs(f(state.id(), state.getFiberRefs())); - return void_; -}); -var updateService = /* @__PURE__ */ dual(3, (self, tag, f) => mapInputContext(self, (context2) => add2(context2, tag, f(unsafeGet4(context2, tag))))); -var when = /* @__PURE__ */ dual(2, (self, condition) => suspend(() => condition() ? map9(self, some2) : succeed(none2()))); -var whenFiberRef = /* @__PURE__ */ dual(3, (self, fiberRef, predicate) => flatMap7(fiberRefGet(fiberRef), (s) => predicate(s) ? map9(self, (a) => [s, some2(a)]) : succeed([s, none2()]))); -var whenRef = /* @__PURE__ */ dual(3, (self, ref, predicate) => flatMap7(get11(ref), (s) => predicate(s) ? map9(self, (a) => [s, some2(a)]) : succeed([s, none2()]))); -var withMetric = /* @__PURE__ */ dual(2, (self, metric) => metric(self)); -var serviceFunctionEffect = (getService, f) => (...args2) => flatMap7(getService, (a) => f(a)(...args2)); -var serviceFunction = (getService, f) => (...args2) => map9(getService, (a) => f(a)(...args2)); -var serviceFunctions = (getService) => new Proxy({}, { - get(_target, prop, _receiver) { - return (...args2) => flatMap7(getService, (s) => s[prop](...args2)); - } -}); -var serviceConstants = (getService) => new Proxy({}, { - get(_target, prop, _receiver) { - return flatMap7(getService, (s) => isEffect(s[prop]) ? s[prop] : succeed(s[prop])); - } -}); -var serviceMembers = (getService) => ({ - functions: serviceFunctions(getService), - constants: serviceConstants(getService) -}); -var serviceOption = (tag) => map9(context(), getOption2(tag)); -var serviceOptional = (tag) => flatMap7(context(), getOption2(tag)); -var annotateCurrentSpan = function() { - const args2 = arguments; - return ignore(flatMap7(currentPropagatedSpan, (span2) => sync(() => { - if (typeof args2[0] === "string") { - span2.attribute(args2[0], args2[1]); - } else { - for (const key in args2[0]) { - span2.attribute(key, args2[0][key]); - } - } - }))); -}; -var linkSpanCurrent = function() { - const args2 = arguments; - const links = Array.isArray(args2[0]) ? args2[0] : [{ - _tag: "SpanLink", - span: args2[0], - attributes: args2[1] ?? {} - }]; - return ignore(flatMap7(currentSpan, (span2) => sync(() => span2.addLinks(links)))); -}; -var annotateSpans = /* @__PURE__ */ dual((args2) => isEffect(args2[0]), function() { - const args2 = arguments; - return fiberRefLocallyWith(args2[0], currentTracerSpanAnnotations, typeof args2[1] === "string" ? set3(args2[1], args2[2]) : (annotations) => Object.entries(args2[1]).reduce((acc, [key, value]) => set3(acc, key, value), annotations)); -}); -var currentParentSpan = /* @__PURE__ */ serviceOptional(spanTag); -var currentSpan = /* @__PURE__ */ flatMap7(/* @__PURE__ */ context(), (context2) => { - const span2 = context2.unsafeMap.get(spanTag.key); - return span2 !== undefined && span2._tag === "Span" ? succeed(span2) : fail2(new NoSuchElementException); -}); -var currentPropagatedSpan = /* @__PURE__ */ flatMap7(/* @__PURE__ */ context(), (context2) => { - const span2 = filterDisablePropagation(getOption2(context2, spanTag)); - return span2._tag === "Some" && span2.value._tag === "Span" ? succeed(span2.value) : fail2(new NoSuchElementException); -}); -var linkSpans = /* @__PURE__ */ dual((args2) => isEffect(args2[0]), (self, span2, attributes) => fiberRefLocallyWith(self, currentTracerSpanLinks, append2({ - _tag: "SpanLink", - span: span2, - attributes: attributes ?? {} -}))); -var bigint02 = /* @__PURE__ */ BigInt(0); -var filterDisablePropagation = /* @__PURE__ */ flatMap((span2) => get4(span2.context, DisablePropagation) ? span2._tag === "Span" ? filterDisablePropagation(span2.parent) : none2() : some2(span2)); -var unsafeMakeSpan = (fiber, name, options) => { - const disablePropagation = !fiber.getFiberRef(currentTracerEnabled) || options.context && get4(options.context, DisablePropagation); - const context2 = fiber.getFiberRef(currentContext); - const parent = options.parent ? some2(options.parent) : options.root ? none2() : filterDisablePropagation(getOption2(context2, spanTag)); - let span2; - if (disablePropagation) { - span2 = noopSpan({ - name, - parent, - context: add2(options.context ?? empty4(), DisablePropagation, true) - }); - } else { - const services = fiber.getFiberRef(currentServices); - const tracer2 = get4(services, tracerTag); - const clock2 = get4(services, Clock); - const timingEnabled = fiber.getFiberRef(currentTracerTimingEnabled); - const fiberRefs3 = fiber.getFiberRefs(); - const annotationsFromEnv = get9(fiberRefs3, currentTracerSpanAnnotations); - const linksFromEnv = get9(fiberRefs3, currentTracerSpanLinks); - const links = linksFromEnv._tag === "Some" ? options.links !== undefined ? [...toReadonlyArray(linksFromEnv.value), ...options.links ?? []] : toReadonlyArray(linksFromEnv.value) : options.links ?? empty(); - span2 = tracer2.span(name, parent, options.context ?? empty4(), links, timingEnabled ? clock2.unsafeCurrentTimeNanos() : bigint02, options.kind ?? "internal", options); - if (annotationsFromEnv._tag === "Some") { - forEach3(annotationsFromEnv.value, (value, key) => span2.attribute(key, value)); - } - if (options.attributes !== undefined) { - Object.entries(options.attributes).forEach(([k, v]) => span2.attribute(k, v)); - } - } - if (typeof options.captureStackTrace === "function") { - spanToTrace.set(span2, options.captureStackTrace); - } - return span2; -}; -var makeSpan = (name, options) => { - options = addSpanStackTrace(options); - return withFiberRuntime((fiber) => succeed(unsafeMakeSpan(fiber, name, options))); -}; -var spanAnnotations = /* @__PURE__ */ fiberRefGet(currentTracerSpanAnnotations); -var spanLinks = /* @__PURE__ */ fiberRefGet(currentTracerSpanLinks); -var endSpan = (span2, exit2, clock2, timingEnabled) => sync(() => { - if (span2.status._tag === "Ended") { - return; - } - if (exitIsFailure(exit2) && spanToTrace.has(span2)) { - span2.attribute("code.stacktrace", spanToTrace.get(span2)()); - } - span2.end(timingEnabled ? clock2.unsafeCurrentTimeNanos() : bigint02, exit2); -}); -var useSpan = (name, ...args2) => { - const options = addSpanStackTrace(args2.length === 1 ? undefined : args2[0]); - const evaluate2 = args2[args2.length - 1]; - return withFiberRuntime((fiber) => { - const span2 = unsafeMakeSpan(fiber, name, options); - const timingEnabled = fiber.getFiberRef(currentTracerTimingEnabled); - const clock2 = get4(fiber.getFiberRef(currentServices), clockTag); - return onExit(evaluate2(span2), (exit2) => endSpan(span2, exit2, clock2, timingEnabled)); - }); -}; -var withParentSpan = /* @__PURE__ */ dual(2, (self, span2) => provideService(self, spanTag, span2)); -var withSpan = function() { - const dataFirst = typeof arguments[0] !== "string"; - const name = dataFirst ? arguments[1] : arguments[0]; - const options = addSpanStackTrace(dataFirst ? arguments[2] : arguments[1]); - if (dataFirst) { - const self = arguments[0]; - return useSpan(name, options, (span2) => withParentSpan(self, span2)); - } - return (self) => useSpan(name, options, (span2) => withParentSpan(self, span2)); -}; -var functionWithSpan = (options) => function() { - let captureStackTrace = options.captureStackTrace ?? false; - if (options.captureStackTrace !== false) { - const limit = Error.stackTraceLimit; - Error.stackTraceLimit = 2; - const error = new Error; - Error.stackTraceLimit = limit; - let cache = false; - captureStackTrace = () => { - if (cache !== false) { - return cache; - } - if (error.stack) { - const stack = error.stack.trim().split(` -`); - cache = stack.slice(2).join(` -`).trim(); - return cache; - } - }; - } - return suspend(() => { - const opts = typeof options.options === "function" ? options.options.apply(null, arguments) : options.options; - return withSpan(suspend(() => internalCall(() => options.body.apply(this, arguments))), opts.name, { - ...opts, - captureStackTrace - }); - }); -}; -var fromNullable2 = (value) => value == null ? fail2(new NoSuchElementException) : succeed(value); -var optionFromOptional = (self) => catchAll(map9(self, some2), (error) => isNoSuchElementException(error) ? succeedNone : fail2(error)); - -// node_modules/effect/dist/esm/Exit.js -var isExit = exitIsExit; -var isSuccess2 = exitIsSuccess; -var failCause3 = exitFailCause; -var flatten5 = exitFlatten; -var match9 = exitMatch; -var succeed3 = exitSucceed; - -// node_modules/effect/dist/esm/internal/fiberMessage.js -var OP_INTERRUPT_SIGNAL = "InterruptSignal"; -var OP_STATEFUL = "Stateful"; -var OP_RESUME = "Resume"; -var OP_YIELD_NOW = "YieldNow"; -var interruptSignal = (cause2) => ({ - _tag: OP_INTERRUPT_SIGNAL, - cause: cause2 -}); -var stateful = (onFiber) => ({ - _tag: OP_STATEFUL, - onFiber -}); -var resume = (effect) => ({ - _tag: OP_RESUME, - effect -}); -var yieldNow3 = () => ({ - _tag: OP_YIELD_NOW -}); - -// node_modules/effect/dist/esm/internal/fiberScope.js -var FiberScopeSymbolKey = "effect/FiberScope"; -var FiberScopeTypeId = /* @__PURE__ */ Symbol.for(FiberScopeSymbolKey); - -class Global { - [FiberScopeTypeId] = FiberScopeTypeId; - fiberId = none4; - roots = /* @__PURE__ */ new Set; - add(_runtimeFlags, child) { - this.roots.add(child); - child.addObserver(() => { - this.roots.delete(child); - }); - } -} - -class Local { - fiberId; - parent; - [FiberScopeTypeId] = FiberScopeTypeId; - constructor(fiberId2, parent) { - this.fiberId = fiberId2; - this.parent = parent; - } - add(_runtimeFlags, child) { - this.parent.tell(stateful((parentFiber) => { - parentFiber.addChild(child); - child.addObserver(() => { - parentFiber.removeChild(child); - }); - })); - } -} -var unsafeMake5 = (fiber) => { - return new Local(fiber.id(), fiber); -}; -var globalScope = /* @__PURE__ */ globalValue(/* @__PURE__ */ Symbol.for("effect/FiberScope/Global"), () => new Global); - -// node_modules/effect/dist/esm/internal/fiber.js -var FiberSymbolKey = "effect/Fiber"; -var FiberTypeId = /* @__PURE__ */ Symbol.for(FiberSymbolKey); -var fiberVariance2 = { - _E: (_) => _, - _A: (_) => _ -}; -var fiberProto = { - [FiberTypeId]: fiberVariance2, - pipe() { - return pipeArguments(this, arguments); - } -}; -var RuntimeFiberSymbolKey = "effect/Fiber"; -var RuntimeFiberTypeId = /* @__PURE__ */ Symbol.for(RuntimeFiberSymbolKey); -var isRuntimeFiber = (self) => (RuntimeFiberTypeId in self); -var _await = (self) => self.await; -var inheritAll = (self) => self.inheritAll; -var interruptAllAs = /* @__PURE__ */ dual(2, /* @__PURE__ */ fnUntraced(function* (fibers, fiberId2) { - for (const fiber of fibers) { - if (isRuntimeFiber(fiber)) { - fiber.unsafeInterruptAsFork(fiberId2); - continue; - } - yield* fiber.interruptAsFork(fiberId2); - } - for (const fiber of fibers) { - if (isRuntimeFiber(fiber) && fiber.unsafePoll()) { - continue; - } - yield* fiber.await; - } -})); -var interruptAsFork = /* @__PURE__ */ dual(2, (self, fiberId2) => self.interruptAsFork(fiberId2)); -var join2 = (self) => zipLeft(flatten4(self.await), self.inheritAll); -var _never = { - ...CommitPrototype, - commit() { - return join2(this); - }, - ...fiberProto, - id: () => none4, - await: never, - children: /* @__PURE__ */ succeed([]), - inheritAll: never, - poll: /* @__PURE__ */ succeed(/* @__PURE__ */ none2()), - interruptAsFork: () => never -}; -var currentFiberURI = "effect/FiberCurrent"; - -// node_modules/effect/dist/esm/internal/logger.js -var LoggerSymbolKey = "effect/Logger"; -var LoggerTypeId = /* @__PURE__ */ Symbol.for(LoggerSymbolKey); -var loggerVariance = { - _Message: (_) => _, - _Output: (_) => _ -}; -var makeLogger = (log2) => ({ - [LoggerTypeId]: loggerVariance, - log: log2, - pipe() { - return pipeArguments(this, arguments); - } -}); -var none7 = { - [LoggerTypeId]: loggerVariance, - log: constVoid, - pipe() { - return pipeArguments(this, arguments); - } -}; -var textOnly = /^[^\s"=]*$/; -var format3 = (quoteValue, whitespace) => ({ - annotations, - cause: cause2, - date, - fiberId: fiberId2, - logLevel, - message, - spans -}) => { - const formatValue = (value) => value.match(textOnly) ? value : quoteValue(value); - const format4 = (label, value) => `${formatLabel(label)}=${formatValue(value)}`; - const append3 = (label, value) => " " + format4(label, value); - let out = format4("timestamp", date.toISOString()); - out += append3("level", logLevel.label); - out += append3("fiber", threadName(fiberId2)); - const messages = ensure(message); - for (let i = 0;i < messages.length; i++) { - out += append3("message", toStringUnknown(messages[i], whitespace)); - } - if (!isEmptyType(cause2)) { - out += append3("cause", pretty(cause2, { - renderErrorCause: true - })); - } - for (const span2 of spans) { - out += " " + render(date.getTime())(span2); - } - for (const [label, value] of annotations) { - out += append3(label, toStringUnknown(value, whitespace)); - } - return out; -}; -var escapeDoubleQuotes = (s) => `"${s.replace(/\\([\s\S])|(")/g, "\\$1$2")}"`; -var stringLogger = /* @__PURE__ */ makeLogger(/* @__PURE__ */ format3(escapeDoubleQuotes)); -var colors = { - bold: "1", - red: "31", - green: "32", - yellow: "33", - blue: "34", - cyan: "36", - white: "37", - gray: "90", - black: "30", - bgBrightRed: "101" -}; -var logLevelColors = { - None: [], - All: [], - Trace: [colors.gray], - Debug: [colors.blue], - Info: [colors.green], - Warning: [colors.yellow], - Error: [colors.red], - Fatal: [colors.bgBrightRed, colors.black] -}; -var hasProcessStdout = typeof process === "object" && process !== null && typeof process.stdout === "object" && process.stdout !== null; -var processStdoutIsTTY = hasProcessStdout && process.stdout.isTTY === true; -var hasProcessStdoutOrDeno = hasProcessStdout || "Deno" in globalThis; - -// node_modules/effect/dist/esm/internal/metric/boundaries.js -var MetricBoundariesSymbolKey = "effect/MetricBoundaries"; -var MetricBoundariesTypeId = /* @__PURE__ */ Symbol.for(MetricBoundariesSymbolKey); - -class MetricBoundariesImpl { - values; - [MetricBoundariesTypeId] = MetricBoundariesTypeId; - constructor(values3) { - this.values = values3; - this._hash = pipe(string(MetricBoundariesSymbolKey), combine(array2(this.values))); - } - _hash; - [symbol]() { - return this._hash; - } - [symbol2](u) { - return isMetricBoundaries(u) && equals(this.values, u.values); - } - pipe() { - return pipeArguments(this, arguments); - } -} -var isMetricBoundaries = (u) => hasProperty(u, MetricBoundariesTypeId); -var fromIterable8 = (iterable) => { - const values3 = pipe(iterable, appendAll(of2(Number.POSITIVE_INFINITY)), dedupe); - return new MetricBoundariesImpl(values3); -}; -var exponential = (options) => pipe(makeBy(options.count - 1, (i) => options.start * Math.pow(options.factor, i)), unsafeFromArray, fromIterable8); - -// node_modules/effect/dist/esm/internal/metric/keyType.js -var MetricKeyTypeSymbolKey = "effect/MetricKeyType"; -var MetricKeyTypeTypeId = /* @__PURE__ */ Symbol.for(MetricKeyTypeSymbolKey); -var CounterKeyTypeSymbolKey = "effect/MetricKeyType/Counter"; -var CounterKeyTypeTypeId = /* @__PURE__ */ Symbol.for(CounterKeyTypeSymbolKey); -var FrequencyKeyTypeSymbolKey = "effect/MetricKeyType/Frequency"; -var FrequencyKeyTypeTypeId = /* @__PURE__ */ Symbol.for(FrequencyKeyTypeSymbolKey); -var GaugeKeyTypeSymbolKey = "effect/MetricKeyType/Gauge"; -var GaugeKeyTypeTypeId = /* @__PURE__ */ Symbol.for(GaugeKeyTypeSymbolKey); -var HistogramKeyTypeSymbolKey = "effect/MetricKeyType/Histogram"; -var HistogramKeyTypeTypeId = /* @__PURE__ */ Symbol.for(HistogramKeyTypeSymbolKey); -var SummaryKeyTypeSymbolKey = "effect/MetricKeyType/Summary"; -var SummaryKeyTypeTypeId = /* @__PURE__ */ Symbol.for(SummaryKeyTypeSymbolKey); -var metricKeyTypeVariance = { - _In: (_) => _, - _Out: (_) => _ -}; - -class CounterKeyType { - incremental; - bigint; - [MetricKeyTypeTypeId] = metricKeyTypeVariance; - [CounterKeyTypeTypeId] = CounterKeyTypeTypeId; - constructor(incremental, bigint2) { - this.incremental = incremental; - this.bigint = bigint2; - this._hash = string(CounterKeyTypeSymbolKey); - } - _hash; - [symbol]() { - return this._hash; - } - [symbol2](that) { - return isCounterKey(that); - } - pipe() { - return pipeArguments(this, arguments); - } -} -class HistogramKeyType { - boundaries; - [MetricKeyTypeTypeId] = metricKeyTypeVariance; - [HistogramKeyTypeTypeId] = HistogramKeyTypeTypeId; - constructor(boundaries) { - this.boundaries = boundaries; - this._hash = pipe(string(HistogramKeyTypeSymbolKey), combine(hash(this.boundaries))); - } - _hash; - [symbol]() { - return this._hash; - } - [symbol2](that) { - return isHistogramKey(that) && equals(this.boundaries, that.boundaries); - } - pipe() { - return pipeArguments(this, arguments); - } -} -var counter = (options) => new CounterKeyType(options?.incremental ?? false, options?.bigint ?? false); -var histogram = (boundaries) => { - return new HistogramKeyType(boundaries); -}; -var isCounterKey = (u) => hasProperty(u, CounterKeyTypeTypeId); -var isFrequencyKey = (u) => hasProperty(u, FrequencyKeyTypeTypeId); -var isGaugeKey = (u) => hasProperty(u, GaugeKeyTypeTypeId); -var isHistogramKey = (u) => hasProperty(u, HistogramKeyTypeTypeId); -var isSummaryKey = (u) => hasProperty(u, SummaryKeyTypeTypeId); - -// node_modules/effect/dist/esm/internal/metric/key.js -var MetricKeySymbolKey = "effect/MetricKey"; -var MetricKeyTypeId = /* @__PURE__ */ Symbol.for(MetricKeySymbolKey); -var metricKeyVariance = { - _Type: (_) => _ -}; -var arrayEquivilence = /* @__PURE__ */ getEquivalence3(equals); - -class MetricKeyImpl { - name; - keyType; - description; - tags; - [MetricKeyTypeId] = metricKeyVariance; - constructor(name, keyType, description, tags = []) { - this.name = name; - this.keyType = keyType; - this.description = description; - this.tags = tags; - this._hash = pipe(string(this.name + this.description), combine(hash(this.keyType)), combine(array2(this.tags))); - } - _hash; - [symbol]() { - return this._hash; - } - [symbol2](u) { - return isMetricKey(u) && this.name === u.name && equals(this.keyType, u.keyType) && equals(this.description, u.description) && arrayEquivilence(this.tags, u.tags); - } - pipe() { - return pipeArguments(this, arguments); - } -} -var isMetricKey = (u) => hasProperty(u, MetricKeyTypeId); -var counter2 = (name, options) => new MetricKeyImpl(name, counter(options), fromNullable(options?.description)); -var histogram2 = (name, boundaries, description) => new MetricKeyImpl(name, histogram(boundaries), fromNullable(description)); -var taggedWithLabels = /* @__PURE__ */ dual(2, (self, extraTags) => extraTags.length === 0 ? self : new MetricKeyImpl(self.name, self.keyType, self.description, union(self.tags, extraTags))); - -// node_modules/effect/dist/esm/MutableHashMap.js -var TypeId11 = /* @__PURE__ */ Symbol.for("effect/MutableHashMap"); -var MutableHashMapProto = { - [TypeId11]: TypeId11, - [Symbol.iterator]() { - return new MutableHashMapIterator(this); - }, - toString() { - return format(this.toJSON()); - }, - toJSON() { - return { - _id: "MutableHashMap", - values: Array.from(this).map(toJSON) - }; - }, - [NodeInspectSymbol]() { - return this.toJSON(); - }, - pipe() { - return pipeArguments(this, arguments); - } -}; - -class MutableHashMapIterator { - self; - referentialIterator; - bucketIterator; - constructor(self) { - this.self = self; - this.referentialIterator = self.referential[Symbol.iterator](); - } - next() { - if (this.bucketIterator !== undefined) { - return this.bucketIterator.next(); - } - const result = this.referentialIterator.next(); - if (result.done) { - this.bucketIterator = new BucketIterator(this.self.buckets.values()); - return this.next(); - } - return result; - } - [Symbol.iterator]() { - return new MutableHashMapIterator(this.self); - } -} - -class BucketIterator { - backing; - constructor(backing) { - this.backing = backing; - } - currentBucket; - next() { - if (this.currentBucket === undefined) { - const result2 = this.backing.next(); - if (result2.done) { - return result2; - } - this.currentBucket = result2.value[Symbol.iterator](); - } - const result = this.currentBucket.next(); - if (result.done) { - this.currentBucket = undefined; - return this.next(); - } - return result; - } -} -var empty21 = () => { - const self = Object.create(MutableHashMapProto); - self.referential = new Map; - self.buckets = new Map; - self.bucketsSize = 0; - return self; -}; -var get12 = /* @__PURE__ */ dual(2, (self, key) => { - if (isEqual(key) === false) { - return self.referential.has(key) ? some2(self.referential.get(key)) : none2(); - } - const hash2 = key[symbol](); - const bucket = self.buckets.get(hash2); - if (bucket === undefined) { - return none2(); - } - return getFromBucket(self, bucket, key); -}); -var getFromBucket = (self, bucket, key, remove5 = false) => { - for (let i = 0, len = bucket.length;i < len; i++) { - if (key[symbol2](bucket[i][0])) { - const value = bucket[i][1]; - if (remove5) { - bucket.splice(i, 1); - self.bucketsSize--; - } - return some2(value); - } - } - return none2(); -}; -var has4 = /* @__PURE__ */ dual(2, (self, key) => isSome2(get12(self, key))); -var set5 = /* @__PURE__ */ dual(3, (self, key, value) => { - if (isEqual(key) === false) { - self.referential.set(key, value); - return self; - } - const hash2 = key[symbol](); - const bucket = self.buckets.get(hash2); - if (bucket === undefined) { - self.buckets.set(hash2, [[key, value]]); - self.bucketsSize++; - return self; - } - removeFromBucket(self, bucket, key); - bucket.push([key, value]); - self.bucketsSize++; - return self; -}); -var removeFromBucket = (self, bucket, key) => { - for (let i = 0, len = bucket.length;i < len; i++) { - if (key[symbol2](bucket[i][0])) { - bucket.splice(i, 1); - self.bucketsSize--; - return; - } - } -}; -var remove5 = /* @__PURE__ */ dual(2, (self, key) => { - if (isEqual(key) === false) { - self.referential.delete(key); - return self; - } - const hash2 = key[symbol](); - const bucket = self.buckets.get(hash2); - if (bucket === undefined) { - return self; - } - removeFromBucket(self, bucket, key); - if (bucket.length === 0) { - self.buckets.delete(hash2); - } - return self; -}); -var size4 = (self) => { - return self.referential.size + self.bucketsSize; -}; - -// node_modules/effect/dist/esm/internal/metric/state.js -var MetricStateSymbolKey = "effect/MetricState"; -var MetricStateTypeId = /* @__PURE__ */ Symbol.for(MetricStateSymbolKey); -var CounterStateSymbolKey = "effect/MetricState/Counter"; -var CounterStateTypeId = /* @__PURE__ */ Symbol.for(CounterStateSymbolKey); -var FrequencyStateSymbolKey = "effect/MetricState/Frequency"; -var FrequencyStateTypeId = /* @__PURE__ */ Symbol.for(FrequencyStateSymbolKey); -var GaugeStateSymbolKey = "effect/MetricState/Gauge"; -var GaugeStateTypeId = /* @__PURE__ */ Symbol.for(GaugeStateSymbolKey); -var HistogramStateSymbolKey = "effect/MetricState/Histogram"; -var HistogramStateTypeId = /* @__PURE__ */ Symbol.for(HistogramStateSymbolKey); -var SummaryStateSymbolKey = "effect/MetricState/Summary"; -var SummaryStateTypeId = /* @__PURE__ */ Symbol.for(SummaryStateSymbolKey); -var metricStateVariance = { - _A: (_) => _ -}; - -class CounterState { - count; - [MetricStateTypeId] = metricStateVariance; - [CounterStateTypeId] = CounterStateTypeId; - constructor(count) { - this.count = count; - } - [symbol]() { - return pipe(hash(CounterStateSymbolKey), combine(hash(this.count)), cached(this)); - } - [symbol2](that) { - return isCounterState(that) && this.count === that.count; - } - pipe() { - return pipeArguments(this, arguments); - } -} -var arrayEquals = /* @__PURE__ */ getEquivalence3(equals); - -class FrequencyState { - occurrences; - [MetricStateTypeId] = metricStateVariance; - [FrequencyStateTypeId] = FrequencyStateTypeId; - constructor(occurrences) { - this.occurrences = occurrences; - } - _hash; - [symbol]() { - return pipe(string(FrequencyStateSymbolKey), combine(array2(fromIterable(this.occurrences.entries()))), cached(this)); - } - [symbol2](that) { - return isFrequencyState(that) && arrayEquals(fromIterable(this.occurrences.entries()), fromIterable(that.occurrences.entries())); - } - pipe() { - return pipeArguments(this, arguments); - } -} - -class GaugeState { - value; - [MetricStateTypeId] = metricStateVariance; - [GaugeStateTypeId] = GaugeStateTypeId; - constructor(value) { - this.value = value; - } - [symbol]() { - return pipe(hash(GaugeStateSymbolKey), combine(hash(this.value)), cached(this)); - } - [symbol2](u) { - return isGaugeState(u) && this.value === u.value; - } - pipe() { - return pipeArguments(this, arguments); - } -} - -class HistogramState { - buckets; - count; - min; - max; - sum; - [MetricStateTypeId] = metricStateVariance; - [HistogramStateTypeId] = HistogramStateTypeId; - constructor(buckets, count, min2, max2, sum) { - this.buckets = buckets; - this.count = count; - this.min = min2; - this.max = max2; - this.sum = sum; - } - [symbol]() { - return pipe(hash(HistogramStateSymbolKey), combine(hash(this.buckets)), combine(hash(this.count)), combine(hash(this.min)), combine(hash(this.max)), combine(hash(this.sum)), cached(this)); - } - [symbol2](that) { - return isHistogramState(that) && equals(this.buckets, that.buckets) && this.count === that.count && this.min === that.min && this.max === that.max && this.sum === that.sum; - } - pipe() { - return pipeArguments(this, arguments); - } -} - -class SummaryState { - error; - quantiles; - count; - min; - max; - sum; - [MetricStateTypeId] = metricStateVariance; - [SummaryStateTypeId] = SummaryStateTypeId; - constructor(error, quantiles, count, min2, max2, sum) { - this.error = error; - this.quantiles = quantiles; - this.count = count; - this.min = min2; - this.max = max2; - this.sum = sum; - } - [symbol]() { - return pipe(hash(SummaryStateSymbolKey), combine(hash(this.error)), combine(hash(this.quantiles)), combine(hash(this.count)), combine(hash(this.min)), combine(hash(this.max)), combine(hash(this.sum)), cached(this)); - } - [symbol2](that) { - return isSummaryState(that) && this.error === that.error && equals(this.quantiles, that.quantiles) && this.count === that.count && this.min === that.min && this.max === that.max && this.sum === that.sum; - } - pipe() { - return pipeArguments(this, arguments); - } -} -var counter3 = (count) => new CounterState(count); -var frequency2 = (occurrences) => { - return new FrequencyState(occurrences); -}; -var gauge2 = (count) => new GaugeState(count); -var histogram3 = (options) => new HistogramState(options.buckets, options.count, options.min, options.max, options.sum); -var summary2 = (options) => new SummaryState(options.error, options.quantiles, options.count, options.min, options.max, options.sum); -var isCounterState = (u) => hasProperty(u, CounterStateTypeId); -var isFrequencyState = (u) => hasProperty(u, FrequencyStateTypeId); -var isGaugeState = (u) => hasProperty(u, GaugeStateTypeId); -var isHistogramState = (u) => hasProperty(u, HistogramStateTypeId); -var isSummaryState = (u) => hasProperty(u, SummaryStateTypeId); - -// node_modules/effect/dist/esm/internal/metric/hook.js -var MetricHookSymbolKey = "effect/MetricHook"; -var MetricHookTypeId = /* @__PURE__ */ Symbol.for(MetricHookSymbolKey); -var metricHookVariance = { - _In: (_) => _, - _Out: (_) => _ -}; -var make28 = (options) => ({ - [MetricHookTypeId]: metricHookVariance, - pipe() { - return pipeArguments(this, arguments); - }, - ...options -}); -var bigint03 = /* @__PURE__ */ BigInt(0); -var counter4 = (key) => { - let sum = key.keyType.bigint ? bigint03 : 0; - const canUpdate = key.keyType.incremental ? key.keyType.bigint ? (value) => value >= bigint03 : (value) => value >= 0 : (_value) => true; - const update4 = (value) => { - if (canUpdate(value)) { - sum = sum + value; - } - }; - return make28({ - get: () => counter3(sum), - update: update4, - modify: update4 - }); -}; -var frequency3 = (key) => { - const values3 = new Map; - for (const word of key.keyType.preregisteredWords) { - values3.set(word, 0); - } - const update4 = (word) => { - const slotCount = values3.get(word) ?? 0; - values3.set(word, slotCount + 1); - }; - return make28({ - get: () => frequency2(values3), - update: update4, - modify: update4 - }); -}; -var gauge3 = (_key, startAt) => { - let value = startAt; - return make28({ - get: () => gauge2(value), - update: (v) => { - value = v; - }, - modify: (v) => { - value = value + v; - } - }); -}; -var histogram4 = (key) => { - const bounds = key.keyType.boundaries.values; - const size5 = bounds.length; - const values3 = new Uint32Array(size5 + 1); - const boundaries = new Float64Array(size5); - let count = 0; - let sum = 0; - let min2 = Number.MAX_VALUE; - let max2 = Number.MIN_VALUE; - pipe(bounds, sort(Order2), map3((n, i) => { - boundaries[i] = n; - })); - const update4 = (value) => { - let from = 0; - let to = size5; - while (from !== to) { - const mid = Math.floor(from + (to - from) / 2); - const boundary = boundaries[mid]; - if (value <= boundary) { - to = mid; - } else { - from = mid; - } - if (to === from + 1) { - if (value <= boundaries[from]) { - to = from; - } else { - from = to; - } - } - } - values3[from] = values3[from] + 1; - count = count + 1; - sum = sum + value; - if (value < min2) { - min2 = value; - } - if (value > max2) { - max2 = value; - } - }; - const getBuckets = () => { - const builder = allocate(size5); - let cumulated = 0; - for (let i = 0;i < size5; i++) { - const boundary = boundaries[i]; - const value = values3[i]; - cumulated = cumulated + value; - builder[i] = [boundary, cumulated]; - } - return builder; - }; - return make28({ - get: () => histogram3({ - buckets: getBuckets(), - count, - min: min2, - max: max2, - sum - }), - update: update4, - modify: update4 - }); -}; -var summary3 = (key) => { - const { - error, - maxAge, - maxSize, - quantiles - } = key.keyType; - const sortedQuantiles = pipe(quantiles, sort(Order2)); - const values3 = allocate(maxSize); - let head4 = 0; - let count = 0; - let sum = 0; - let min2 = 0; - let max2 = 0; - const snapshot = (now) => { - const builder = []; - let i = 0; - while (i !== maxSize - 1) { - const item = values3[i]; - if (item != null) { - const [t, v] = item; - const age = millis(now - t); - if (greaterThanOrEqualTo2(age, zero) && lessThanOrEqualTo2(age, maxAge)) { - builder.push(v); - } - } - i = i + 1; - } - return calculateQuantiles(error, sortedQuantiles, sort(builder, Order2)); - }; - const observe = (value, timestamp) => { - if (maxSize > 0) { - head4 = head4 + 1; - const target = head4 % maxSize; - values3[target] = [timestamp, value]; - } - min2 = count === 0 ? value : Math.min(min2, value); - max2 = count === 0 ? value : Math.max(max2, value); - count = count + 1; - sum = sum + value; - }; - return make28({ - get: () => summary2({ - error, - quantiles: snapshot(Date.now()), - count, - min: min2, - max: max2, - sum - }), - update: ([value, timestamp]) => observe(value, timestamp), - modify: ([value, timestamp]) => observe(value, timestamp) - }); -}; -var calculateQuantiles = (error, sortedQuantiles, sortedSamples) => { - const sampleCount = sortedSamples.length; - if (!isNonEmptyReadonlyArray(sortedQuantiles)) { - return empty(); - } - const head4 = sortedQuantiles[0]; - const tail = sortedQuantiles.slice(1); - const resolvedHead = resolveQuantile(error, sampleCount, none2(), 0, head4, sortedSamples); - const resolved = of(resolvedHead); - tail.forEach((quantile) => { - resolved.push(resolveQuantile(error, sampleCount, resolvedHead.value, resolvedHead.consumed, quantile, resolvedHead.rest)); - }); - return map3(resolved, (rq) => [rq.quantile, rq.value]); -}; -var resolveQuantile = (error, sampleCount, current, consumed, quantile, rest) => { - let error_1 = error; - let sampleCount_1 = sampleCount; - let current_1 = current; - let consumed_1 = consumed; - let quantile_1 = quantile; - let rest_1 = rest; - let error_2 = error; - let sampleCount_2 = sampleCount; - let current_2 = current; - let consumed_2 = consumed; - let quantile_2 = quantile; - let rest_2 = rest; - while (true) { - if (!isNonEmptyReadonlyArray(rest_1)) { - return { - quantile: quantile_1, - value: none2(), - consumed: consumed_1, - rest: [] - }; - } - if (quantile_1 === 1) { - return { - quantile: quantile_1, - value: some2(lastNonEmpty(rest_1)), - consumed: consumed_1 + rest_1.length, - rest: [] - }; - } - const headValue = headNonEmpty(rest_1); - const sameHead = span(rest_1, (n) => n === headValue); - const desired = quantile_1 * sampleCount_1; - const allowedError = error_1 / 2 * desired; - const candConsumed = consumed_1 + sameHead[0].length; - const candError = Math.abs(candConsumed - desired); - if (candConsumed < desired - allowedError) { - error_2 = error_1; - sampleCount_2 = sampleCount_1; - current_2 = head(rest_1); - consumed_2 = candConsumed; - quantile_2 = quantile_1; - rest_2 = sameHead[1]; - error_1 = error_2; - sampleCount_1 = sampleCount_2; - current_1 = current_2; - consumed_1 = consumed_2; - quantile_1 = quantile_2; - rest_1 = rest_2; - continue; - } - if (candConsumed > desired + allowedError) { - const valueToReturn = isNone2(current_1) ? some2(headValue) : current_1; - return { - quantile: quantile_1, - value: valueToReturn, - consumed: consumed_1, - rest: rest_1 - }; - } - switch (current_1._tag) { - case "None": { - error_2 = error_1; - sampleCount_2 = sampleCount_1; - current_2 = head(rest_1); - consumed_2 = candConsumed; - quantile_2 = quantile_1; - rest_2 = sameHead[1]; - error_1 = error_2; - sampleCount_1 = sampleCount_2; - current_1 = current_2; - consumed_1 = consumed_2; - quantile_1 = quantile_2; - rest_1 = rest_2; - continue; - } - case "Some": { - const prevError = Math.abs(desired - current_1.value); - if (candError < prevError) { - error_2 = error_1; - sampleCount_2 = sampleCount_1; - current_2 = head(rest_1); - consumed_2 = candConsumed; - quantile_2 = quantile_1; - rest_2 = sameHead[1]; - error_1 = error_2; - sampleCount_1 = sampleCount_2; - current_1 = current_2; - consumed_1 = consumed_2; - quantile_1 = quantile_2; - rest_1 = rest_2; - continue; - } - return { - quantile: quantile_1, - value: some2(current_1.value), - consumed: consumed_1, - rest: rest_1 - }; - } - } - } - throw new Error("BUG: MetricHook.resolveQuantiles - please report an issue at https://github.com/Effect-TS/effect/issues"); -}; - -// node_modules/effect/dist/esm/internal/metric/pair.js -var MetricPairSymbolKey = "effect/MetricPair"; -var MetricPairTypeId = /* @__PURE__ */ Symbol.for(MetricPairSymbolKey); -var metricPairVariance = { - _Type: (_) => _ -}; -var unsafeMake6 = (metricKey, metricState) => { - return { - [MetricPairTypeId]: metricPairVariance, - metricKey, - metricState, - pipe() { - return pipeArguments(this, arguments); - } - }; -}; - -// node_modules/effect/dist/esm/internal/metric/registry.js -var MetricRegistrySymbolKey = "effect/MetricRegistry"; -var MetricRegistryTypeId = /* @__PURE__ */ Symbol.for(MetricRegistrySymbolKey); - -class MetricRegistryImpl { - [MetricRegistryTypeId] = MetricRegistryTypeId; - map = /* @__PURE__ */ empty21(); - snapshot() { - const result = []; - for (const [key, hook] of this.map) { - result.push(unsafeMake6(key, hook.get())); - } - return result; - } - get(key) { - const hook = pipe(this.map, get12(key), getOrUndefined); - if (hook == null) { - if (isCounterKey(key.keyType)) { - return this.getCounter(key); - } - if (isGaugeKey(key.keyType)) { - return this.getGauge(key); - } - if (isFrequencyKey(key.keyType)) { - return this.getFrequency(key); - } - if (isHistogramKey(key.keyType)) { - return this.getHistogram(key); - } - if (isSummaryKey(key.keyType)) { - return this.getSummary(key); - } - throw new Error("BUG: MetricRegistry.get - unknown MetricKeyType - please report an issue at https://github.com/Effect-TS/effect/issues"); - } else { - return hook; - } - } - getCounter(key) { - let value = pipe(this.map, get12(key), getOrUndefined); - if (value == null) { - const counter5 = counter4(key); - if (!pipe(this.map, has4(key))) { - pipe(this.map, set5(key, counter5)); - } - value = counter5; - } - return value; - } - getFrequency(key) { - let value = pipe(this.map, get12(key), getOrUndefined); - if (value == null) { - const frequency4 = frequency3(key); - if (!pipe(this.map, has4(key))) { - pipe(this.map, set5(key, frequency4)); - } - value = frequency4; - } - return value; - } - getGauge(key) { - let value = pipe(this.map, get12(key), getOrUndefined); - if (value == null) { - const gauge4 = gauge3(key, key.keyType.bigint ? BigInt(0) : 0); - if (!pipe(this.map, has4(key))) { - pipe(this.map, set5(key, gauge4)); - } - value = gauge4; - } - return value; - } - getHistogram(key) { - let value = pipe(this.map, get12(key), getOrUndefined); - if (value == null) { - const histogram5 = histogram4(key); - if (!pipe(this.map, has4(key))) { - pipe(this.map, set5(key, histogram5)); - } - value = histogram5; - } - return value; - } - getSummary(key) { - let value = pipe(this.map, get12(key), getOrUndefined); - if (value == null) { - const summary4 = summary3(key); - if (!pipe(this.map, has4(key))) { - pipe(this.map, set5(key, summary4)); - } - value = summary4; - } - return value; - } -} -var make29 = () => { - return new MetricRegistryImpl; -}; - -// node_modules/effect/dist/esm/internal/metric.js -var MetricSymbolKey = "effect/Metric"; -var MetricTypeId = /* @__PURE__ */ Symbol.for(MetricSymbolKey); -var metricVariance = { - _Type: (_) => _, - _In: (_) => _, - _Out: (_) => _ -}; -var globalMetricRegistry = /* @__PURE__ */ globalValue(/* @__PURE__ */ Symbol.for("effect/Metric/globalMetricRegistry"), () => make29()); -var make30 = function(keyType, unsafeUpdate, unsafeValue, unsafeModify) { - const metric = Object.assign((effect) => tap(effect, (a) => update4(metric, a)), { - [MetricTypeId]: metricVariance, - keyType, - unsafeUpdate, - unsafeValue, - unsafeModify, - register() { - this.unsafeValue([]); - return this; - }, - pipe() { - return pipeArguments(this, arguments); - } - }); - return metric; -}; -var counter5 = (name, options) => fromMetricKey(counter2(name, options)); -var fromMetricKey = (key) => { - let untaggedHook; - const hookCache = new WeakMap; - const hook = (extraTags) => { - if (extraTags.length === 0) { - if (untaggedHook !== undefined) { - return untaggedHook; - } - untaggedHook = globalMetricRegistry.get(key); - return untaggedHook; - } - let hook2 = hookCache.get(extraTags); - if (hook2 !== undefined) { - return hook2; - } - hook2 = globalMetricRegistry.get(taggedWithLabels(key, extraTags)); - hookCache.set(extraTags, hook2); - return hook2; - }; - return make30(key.keyType, (input, extraTags) => hook(extraTags).update(input), (extraTags) => hook(extraTags).get(), (input, extraTags) => hook(extraTags).modify(input)); -}; -var histogram5 = (name, boundaries, description) => fromMetricKey(histogram2(name, boundaries, description)); -var tagged2 = /* @__PURE__ */ dual(3, (self, key, value) => taggedWithLabels2(self, [make27(key, value)])); -var taggedWithLabels2 = /* @__PURE__ */ dual(2, (self, extraTags) => { - return make30(self.keyType, (input, extraTags1) => self.unsafeUpdate(input, union(extraTags, extraTags1)), (extraTags1) => self.unsafeValue(union(extraTags, extraTags1)), (input, extraTags1) => self.unsafeModify(input, union(extraTags, extraTags1))); -}); -var update4 = /* @__PURE__ */ dual(2, (self, input) => fiberRefGetWith(currentMetricLabels, (tags) => sync(() => self.unsafeUpdate(input, tags)))); - -// node_modules/effect/dist/esm/internal/request.js -var RequestSymbolKey = "effect/Request"; -var RequestTypeId = /* @__PURE__ */ Symbol.for(RequestSymbolKey); -var requestVariance = { - _E: (_) => _, - _A: (_) => _ -}; -var RequestPrototype = { - ...StructuralPrototype, - [RequestTypeId]: requestVariance -}; -var isRequest = (u) => hasProperty(u, RequestTypeId); -var Class3 = /* @__PURE__ */ function() { - function Class4(args2) { - if (args2) { - Object.assign(this, args2); - } - } - Class4.prototype = RequestPrototype; - return Class4; -}(); -var complete = /* @__PURE__ */ dual(2, (self, result) => fiberRefGetWith(currentRequestMap, (map10) => sync(() => { - if (map10.has(self)) { - const entry = map10.get(self); - if (!entry.state.completed) { - entry.state.completed = true; - deferredUnsafeDone(entry.result, result); - } - } -}))); -class Listeners { - count = 0; - observers = /* @__PURE__ */ new Set; - interrupted = false; - addObserver(f) { - this.observers.add(f); - } - removeObserver(f) { - this.observers.delete(f); - } - increment() { - this.count++; - this.observers.forEach((f) => f(this.count)); - } - decrement() { - this.count--; - this.observers.forEach((f) => f(this.count)); - } -} - -// node_modules/effect/dist/esm/internal/redBlackTree/iterator.js -var Direction = { - Forward: 0, - Backward: 1 << 0 -}; - -class RedBlackTreeIterator { - self; - stack; - direction; - count = 0; - constructor(self, stack, direction) { - this.self = self; - this.stack = stack; - this.direction = direction; - } - clone() { - return new RedBlackTreeIterator(this.self, this.stack.slice(), this.direction); - } - reversed() { - return new RedBlackTreeIterator(this.self, this.stack.slice(), this.direction === Direction.Forward ? Direction.Backward : Direction.Forward); - } - next() { - const entry = this.entry; - this.count++; - if (this.direction === Direction.Forward) { - this.moveNext(); - } else { - this.movePrev(); - } - switch (entry._tag) { - case "None": { - return { - done: true, - value: this.count - }; - } - case "Some": { - return { - done: false, - value: entry.value - }; - } - } - } - get key() { - if (this.stack.length > 0) { - return some2(this.stack[this.stack.length - 1].key); - } - return none2(); - } - get value() { - if (this.stack.length > 0) { - return some2(this.stack[this.stack.length - 1].value); - } - return none2(); - } - get entry() { - return map2(last(this.stack), (node) => [node.key, node.value]); - } - get index() { - let idx = 0; - const stack = this.stack; - if (stack.length === 0) { - const r = this.self._root; - if (r != null) { - return r.count; - } - return 0; - } else if (stack[stack.length - 1].left != null) { - idx = stack[stack.length - 1].left.count; - } - for (let s = stack.length - 2;s >= 0; --s) { - if (stack[s + 1] === stack[s].right) { - ++idx; - if (stack[s].left != null) { - idx += stack[s].left.count; - } - } - } - return idx; - } - moveNext() { - const stack = this.stack; - if (stack.length === 0) { - return; - } - let n = stack[stack.length - 1]; - if (n.right != null) { - n = n.right; - while (n != null) { - stack.push(n); - n = n.left; - } - } else { - stack.pop(); - while (stack.length > 0 && stack[stack.length - 1].right === n) { - n = stack[stack.length - 1]; - stack.pop(); - } - } - } - get hasNext() { - const stack = this.stack; - if (stack.length === 0) { - return false; - } - if (stack[stack.length - 1].right != null) { - return true; - } - for (let s = stack.length - 1;s > 0; --s) { - if (stack[s - 1].left === stack[s]) { - return true; - } - } - return false; - } - movePrev() { - const stack = this.stack; - if (stack.length === 0) { - return; - } - let n = stack[stack.length - 1]; - if (n != null && n.left != null) { - n = n.left; - while (n != null) { - stack.push(n); - n = n.right; - } - } else { - stack.pop(); - while (stack.length > 0 && stack[stack.length - 1].left === n) { - n = stack[stack.length - 1]; - stack.pop(); - } - } - } - get hasPrev() { - const stack = this.stack; - if (stack.length === 0) { - return false; - } - if (stack[stack.length - 1].left != null) { - return true; - } - for (let s = stack.length - 1;s > 0; --s) { - if (stack[s - 1].right === stack[s]) { - return true; - } - } - return false; - } -} - -// node_modules/effect/dist/esm/internal/redBlackTree/node.js -var Color = { - Red: 0, - Black: 1 << 0 -}; -var repaint = ({ - count, - key, - left: left3, - right: right3, - value -}, color) => ({ - color, - key, - value, - left: left3, - right: right3, - count -}); -var recount = (node) => { - node.count = 1 + (node.left?.count ?? 0) + (node.right?.count ?? 0); -}; - -// node_modules/effect/dist/esm/internal/redBlackTree.js -var RedBlackTreeSymbolKey = "effect/RedBlackTree"; -var RedBlackTreeTypeId = /* @__PURE__ */ Symbol.for(RedBlackTreeSymbolKey); -var redBlackTreeVariance = { - _Key: (_) => _, - _Value: (_) => _ -}; -var RedBlackTreeProto = { - [RedBlackTreeTypeId]: redBlackTreeVariance, - [symbol]() { - let hash2 = hash(RedBlackTreeSymbolKey); - for (const item of this) { - hash2 ^= pipe(hash(item[0]), combine(hash(item[1]))); - } - return cached(this, hash2); - }, - [symbol2](that) { - if (isRedBlackTree(that)) { - if ((this._root?.count ?? 0) !== (that._root?.count ?? 0)) { - return false; - } - const entries2 = Array.from(that); - return Array.from(this).every((itemSelf, i) => { - const itemThat = entries2[i]; - return equals(itemSelf[0], itemThat[0]) && equals(itemSelf[1], itemThat[1]); - }); - } - return false; - }, - [Symbol.iterator]() { - const stack = []; - let n = this._root; - while (n != null) { - stack.push(n); - n = n.left; - } - return new RedBlackTreeIterator(this, stack, Direction.Forward); - }, - toString() { - return format(this.toJSON()); - }, - toJSON() { - return { - _id: "RedBlackTree", - values: Array.from(this).map(toJSON) - }; - }, - [NodeInspectSymbol]() { - return this.toJSON(); - }, - pipe() { - return pipeArguments(this, arguments); - } -}; -var makeImpl3 = (ord, root) => { - const tree = Object.create(RedBlackTreeProto); - tree._ord = ord; - tree._root = root; - return tree; -}; -var isRedBlackTree = (u) => hasProperty(u, RedBlackTreeTypeId); -var empty22 = (ord) => makeImpl3(ord, undefined); -var fromIterable9 = /* @__PURE__ */ dual(2, (entries2, ord) => { - let tree = empty22(ord); - for (const [key, value] of entries2) { - tree = insert(tree, key, value); - } - return tree; -}); -var findFirst5 = /* @__PURE__ */ dual(2, (self, key) => { - const cmp = self._ord; - let node = self._root; - while (node !== undefined) { - const d = cmp(key, node.key); - if (equals(key, node.key)) { - return some2(node.value); - } - if (d <= 0) { - node = node.left; - } else { - node = node.right; - } - } - return none2(); -}); -var has5 = /* @__PURE__ */ dual(2, (self, key) => isSome2(findFirst5(self, key))); -var insert = /* @__PURE__ */ dual(3, (self, key, value) => { - const cmp = self._ord; - let n = self._root; - const n_stack = []; - const d_stack = []; - while (n != null) { - const d = cmp(key, n.key); - n_stack.push(n); - d_stack.push(d); - if (d <= 0) { - n = n.left; - } else { - n = n.right; - } - } - n_stack.push({ - color: Color.Red, - key, - value, - left: undefined, - right: undefined, - count: 1 - }); - for (let s = n_stack.length - 2;s >= 0; --s) { - const n2 = n_stack[s]; - if (d_stack[s] <= 0) { - n_stack[s] = { - color: n2.color, - key: n2.key, - value: n2.value, - left: n_stack[s + 1], - right: n2.right, - count: n2.count + 1 - }; - } else { - n_stack[s] = { - color: n2.color, - key: n2.key, - value: n2.value, - left: n2.left, - right: n_stack[s + 1], - count: n2.count + 1 - }; - } - } - for (let s = n_stack.length - 1;s > 1; --s) { - const p = n_stack[s - 1]; - const n3 = n_stack[s]; - if (p.color === Color.Black || n3.color === Color.Black) { - break; - } - const pp = n_stack[s - 2]; - if (pp.left === p) { - if (p.left === n3) { - const y = pp.right; - if (y && y.color === Color.Red) { - p.color = Color.Black; - pp.right = repaint(y, Color.Black); - pp.color = Color.Red; - s -= 1; - } else { - pp.color = Color.Red; - pp.left = p.right; - p.color = Color.Black; - p.right = pp; - n_stack[s - 2] = p; - n_stack[s - 1] = n3; - recount(pp); - recount(p); - if (s >= 3) { - const ppp = n_stack[s - 3]; - if (ppp.left === pp) { - ppp.left = p; - } else { - ppp.right = p; - } - } - break; - } - } else { - const y = pp.right; - if (y && y.color === Color.Red) { - p.color = Color.Black; - pp.right = repaint(y, Color.Black); - pp.color = Color.Red; - s -= 1; - } else { - p.right = n3.left; - pp.color = Color.Red; - pp.left = n3.right; - n3.color = Color.Black; - n3.left = p; - n3.right = pp; - n_stack[s - 2] = n3; - n_stack[s - 1] = p; - recount(pp); - recount(p); - recount(n3); - if (s >= 3) { - const ppp = n_stack[s - 3]; - if (ppp.left === pp) { - ppp.left = n3; - } else { - ppp.right = n3; - } - } - break; - } - } - } else { - if (p.right === n3) { - const y = pp.left; - if (y && y.color === Color.Red) { - p.color = Color.Black; - pp.left = repaint(y, Color.Black); - pp.color = Color.Red; - s -= 1; - } else { - pp.color = Color.Red; - pp.right = p.left; - p.color = Color.Black; - p.left = pp; - n_stack[s - 2] = p; - n_stack[s - 1] = n3; - recount(pp); - recount(p); - if (s >= 3) { - const ppp = n_stack[s - 3]; - if (ppp.right === pp) { - ppp.right = p; - } else { - ppp.left = p; - } - } - break; - } - } else { - const y = pp.left; - if (y && y.color === Color.Red) { - p.color = Color.Black; - pp.left = repaint(y, Color.Black); - pp.color = Color.Red; - s -= 1; - } else { - p.left = n3.right; - pp.color = Color.Red; - pp.right = n3.left; - n3.color = Color.Black; - n3.right = p; - n3.left = pp; - n_stack[s - 2] = n3; - n_stack[s - 1] = p; - recount(pp); - recount(p); - recount(n3); - if (s >= 3) { - const ppp = n_stack[s - 3]; - if (ppp.right === pp) { - ppp.right = n3; - } else { - ppp.left = n3; - } - } - break; - } - } - } - } - n_stack[0].color = Color.Black; - return makeImpl3(self._ord, n_stack[0]); -}); -var keysForward = (self) => keys3(self, Direction.Forward); -var keys3 = (self, direction) => { - const begin = self[Symbol.iterator](); - let count = 0; - return { - [Symbol.iterator]: () => keys3(self, direction), - next: () => { - count++; - const entry = begin.key; - if (direction === Direction.Forward) { - begin.moveNext(); - } else { - begin.movePrev(); - } - switch (entry._tag) { - case "None": { - return { - done: true, - value: count - }; - } - case "Some": { - return { - done: false, - value: entry.value - }; - } - } - } - }; -}; - -// node_modules/effect/dist/esm/RedBlackTree.js -var fromIterable10 = fromIterable9; -var has6 = has5; -var keys4 = keysForward; - -// node_modules/effect/dist/esm/SortedSet.js -var TypeId12 = /* @__PURE__ */ Symbol.for("effect/SortedSet"); -var SortedSetProto = { - [TypeId12]: { - _A: (_) => _ - }, - [symbol]() { - return pipe(hash(this.keyTree), combine(hash(TypeId12)), cached(this)); - }, - [symbol2](that) { - return isSortedSet(that) && equals(this.keyTree, that.keyTree); - }, - [Symbol.iterator]() { - return keys4(this.keyTree); - }, - toString() { - return format(this.toJSON()); - }, - toJSON() { - return { - _id: "SortedSet", - values: Array.from(this).map(toJSON) - }; - }, - [NodeInspectSymbol]() { - return this.toJSON(); - }, - pipe() { - return pipeArguments(this, arguments); - } -}; -var fromTree = (keyTree) => { - const a = Object.create(SortedSetProto); - a.keyTree = keyTree; - return a; -}; -var isSortedSet = (u) => hasProperty(u, TypeId12); -var fromIterable11 = /* @__PURE__ */ dual(2, (iterable, ord) => fromTree(fromIterable10(Array.from(iterable).map((k) => [k, true]), ord))); -var every5 = /* @__PURE__ */ dual(2, (self, predicate) => { - for (const value of self) { - if (!predicate(value)) { - return false; - } - } - return true; -}); -var has7 = /* @__PURE__ */ dual(2, (self, value) => has6(self.keyTree, value)); -var isSubset2 = /* @__PURE__ */ dual(2, (self, that) => every5(self, (a) => has7(that, a))); -var values3 = (self) => keys4(self.keyTree); -var getEquivalence6 = () => (a, b) => isSubset2(a, b) && isSubset2(b, a); - -// node_modules/effect/dist/esm/internal/supervisor.js -var SupervisorSymbolKey = "effect/Supervisor"; -var SupervisorTypeId = /* @__PURE__ */ Symbol.for(SupervisorSymbolKey); -var supervisorVariance = { - _T: (_) => _ -}; - -class ProxySupervisor { - underlying; - value0; - [SupervisorTypeId] = supervisorVariance; - constructor(underlying, value0) { - this.underlying = underlying; - this.value0 = value0; - } - get value() { - return this.value0; - } - onStart(context2, effect, parent, fiber) { - this.underlying.onStart(context2, effect, parent, fiber); - } - onEnd(value, fiber) { - this.underlying.onEnd(value, fiber); - } - onEffect(fiber, effect) { - this.underlying.onEffect(fiber, effect); - } - onSuspend(fiber) { - this.underlying.onSuspend(fiber); - } - onResume(fiber) { - this.underlying.onResume(fiber); - } - map(f) { - return new ProxySupervisor(this, pipe(this.value, map9(f))); - } - zip(right3) { - return new Zip(this, right3); - } -} - -class Zip { - left; - right; - _tag = "Zip"; - [SupervisorTypeId] = supervisorVariance; - constructor(left3, right3) { - this.left = left3; - this.right = right3; - } - get value() { - return zip2(this.left.value, this.right.value); - } - onStart(context2, effect, parent, fiber) { - this.left.onStart(context2, effect, parent, fiber); - this.right.onStart(context2, effect, parent, fiber); - } - onEnd(value, fiber) { - this.left.onEnd(value, fiber); - this.right.onEnd(value, fiber); - } - onEffect(fiber, effect) { - this.left.onEffect(fiber, effect); - this.right.onEffect(fiber, effect); - } - onSuspend(fiber) { - this.left.onSuspend(fiber); - this.right.onSuspend(fiber); - } - onResume(fiber) { - this.left.onResume(fiber); - this.right.onResume(fiber); - } - map(f) { - return new ProxySupervisor(this, pipe(this.value, map9(f))); - } - zip(right3) { - return new Zip(this, right3); - } -} -var isZip = (self) => hasProperty(self, SupervisorTypeId) && isTagged(self, "Zip"); - -class Track { - [SupervisorTypeId] = supervisorVariance; - fibers = /* @__PURE__ */ new Set; - get value() { - return sync(() => Array.from(this.fibers)); - } - onStart(_context, _effect, _parent, fiber) { - this.fibers.add(fiber); - } - onEnd(_value, fiber) { - this.fibers.delete(fiber); - } - onEffect(_fiber, _effect) {} - onSuspend(_fiber) {} - onResume(_fiber) {} - map(f) { - return new ProxySupervisor(this, pipe(this.value, map9(f))); - } - zip(right3) { - return new Zip(this, right3); - } - onRun(execution, _fiber) { - return execution(); - } -} - -class Const { - effect; - [SupervisorTypeId] = supervisorVariance; - constructor(effect) { - this.effect = effect; - } - get value() { - return this.effect; - } - onStart(_context, _effect, _parent, _fiber) {} - onEnd(_value, _fiber) {} - onEffect(_fiber, _effect) {} - onSuspend(_fiber) {} - onResume(_fiber) {} - map(f) { - return new ProxySupervisor(this, pipe(this.value, map9(f))); - } - zip(right3) { - return new Zip(this, right3); - } - onRun(execution, _fiber) { - return execution(); - } -} -var unsafeTrack = () => { - return new Track; -}; -var track = /* @__PURE__ */ sync(unsafeTrack); -var fromEffect = (effect) => { - return new Const(effect); -}; -var none8 = /* @__PURE__ */ globalValue("effect/Supervisor/none", () => fromEffect(void_)); - -// node_modules/effect/dist/esm/Differ.js -var make32 = make14; - -// node_modules/effect/dist/esm/internal/supervisor/patch.js -var OP_EMPTY3 = "Empty"; -var OP_ADD_SUPERVISOR = "AddSupervisor"; -var OP_REMOVE_SUPERVISOR = "RemoveSupervisor"; -var OP_AND_THEN2 = "AndThen"; -var empty24 = { - _tag: OP_EMPTY3 -}; -var combine8 = (self, that) => { - return { - _tag: OP_AND_THEN2, - first: self, - second: that - }; -}; -var patch8 = (self, supervisor) => { - return patchLoop(supervisor, of2(self)); -}; -var patchLoop = (_supervisor, _patches) => { - let supervisor = _supervisor; - let patches = _patches; - while (isNonEmpty(patches)) { - const head4 = headNonEmpty2(patches); - switch (head4._tag) { - case OP_EMPTY3: { - patches = tailNonEmpty2(patches); - break; - } - case OP_ADD_SUPERVISOR: { - supervisor = supervisor.zip(head4.supervisor); - patches = tailNonEmpty2(patches); - break; - } - case OP_REMOVE_SUPERVISOR: { - supervisor = removeSupervisor(supervisor, head4.supervisor); - patches = tailNonEmpty2(patches); - break; - } - case OP_AND_THEN2: { - patches = prepend2(head4.first)(prepend2(head4.second)(tailNonEmpty2(patches))); - break; - } - } - } - return supervisor; -}; -var removeSupervisor = (self, that) => { - if (equals(self, that)) { - return none8; - } else { - if (isZip(self)) { - return removeSupervisor(self.left, that).zip(removeSupervisor(self.right, that)); - } else { - return self; - } - } -}; -var toSet2 = (self) => { - if (equals(self, none8)) { - return empty7(); - } else { - if (isZip(self)) { - return pipe(toSet2(self.left), union3(toSet2(self.right))); - } else { - return make10(self); - } - } -}; -var diff7 = (oldValue, newValue) => { - if (equals(oldValue, newValue)) { - return empty24; - } - const oldSupervisors = toSet2(oldValue); - const newSupervisors = toSet2(newValue); - const added = pipe(newSupervisors, difference3(oldSupervisors), reduce4(empty24, (patch9, supervisor) => combine8(patch9, { - _tag: OP_ADD_SUPERVISOR, - supervisor - }))); - const removed = pipe(oldSupervisors, difference3(newSupervisors), reduce4(empty24, (patch9, supervisor) => combine8(patch9, { - _tag: OP_REMOVE_SUPERVISOR, - supervisor - }))); - return combine8(added, removed); -}; -var differ2 = /* @__PURE__ */ make32({ - empty: empty24, - patch: patch8, - combine: combine8, - diff: diff7 -}); - -// node_modules/effect/dist/esm/internal/fiberRuntime.js -var fiberStarted = /* @__PURE__ */ counter5("effect_fiber_started", { - incremental: true -}); -var fiberActive = /* @__PURE__ */ counter5("effect_fiber_active"); -var fiberSuccesses = /* @__PURE__ */ counter5("effect_fiber_successes", { - incremental: true -}); -var fiberFailures = /* @__PURE__ */ counter5("effect_fiber_failures", { - incremental: true -}); -var fiberLifetimes = /* @__PURE__ */ tagged2(/* @__PURE__ */ histogram5("effect_fiber_lifetimes", /* @__PURE__ */ exponential({ - start: 0.5, - factor: 2, - count: 35 -})), "time_unit", "milliseconds"); -var EvaluationSignalContinue = "Continue"; -var EvaluationSignalDone = "Done"; -var EvaluationSignalYieldNow = "Yield"; -var runtimeFiberVariance = { - _E: (_) => _, - _A: (_) => _ -}; -var absurd = (_) => { - throw new Error(`BUG: FiberRuntime - ${toStringUnknown(_)} - please report an issue at https://github.com/Effect-TS/effect/issues`); -}; -var YieldedOp = /* @__PURE__ */ Symbol.for("effect/internal/fiberRuntime/YieldedOp"); -var yieldedOpChannel = /* @__PURE__ */ globalValue("effect/internal/fiberRuntime/yieldedOpChannel", () => ({ - currentOp: null -})); -var contOpSuccess = { - [OP_ON_SUCCESS]: (_, cont, value) => { - return internalCall(() => cont.effect_instruction_i1(value)); - }, - ["OnStep"]: (_, _cont, value) => { - return exitSucceed(exitSucceed(value)); - }, - [OP_ON_SUCCESS_AND_FAILURE]: (_, cont, value) => { - return internalCall(() => cont.effect_instruction_i2(value)); - }, - [OP_REVERT_FLAGS]: (self, cont, value) => { - self.patchRuntimeFlags(self.currentRuntimeFlags, cont.patch); - if (interruptible(self.currentRuntimeFlags) && self.isInterrupted()) { - return exitFailCause(self.getInterruptedCause()); - } else { - return exitSucceed(value); - } - }, - [OP_WHILE]: (self, cont, value) => { - internalCall(() => cont.effect_instruction_i2(value)); - if (internalCall(() => cont.effect_instruction_i0())) { - self.pushStack(cont); - return internalCall(() => cont.effect_instruction_i1()); - } else { - return void_; - } - }, - [OP_ITERATOR]: (self, cont, value) => { - while (true) { - const state = internalCall(() => cont.effect_instruction_i0.next(value)); - if (state.done) { - return exitSucceed(state.value); - } - const primitive = yieldWrapGet(state.value); - if (!exitIsExit(primitive)) { - self.pushStack(cont); - return primitive; - } else if (primitive._tag === "Failure") { - return primitive; - } - value = primitive.value; - } - } -}; -var drainQueueWhileRunningTable = { - [OP_INTERRUPT_SIGNAL]: (self, runtimeFlags2, cur, message) => { - self.processNewInterruptSignal(message.cause); - return interruptible(runtimeFlags2) ? exitFailCause(message.cause) : cur; - }, - [OP_RESUME]: (_self, _runtimeFlags, _cur, _message) => { - throw new Error("It is illegal to have multiple concurrent run loops in a single fiber"); - }, - [OP_STATEFUL]: (self, runtimeFlags2, cur, message) => { - message.onFiber(self, running2(runtimeFlags2)); - return cur; - }, - [OP_YIELD_NOW]: (_self, _runtimeFlags, cur, _message) => { - return flatMap7(yieldNow(), () => cur); - } -}; -var runBlockedRequests = (self) => forEachSequentialDiscard(flatten2(self), (requestsByRequestResolver) => forEachConcurrentDiscard(sequentialCollectionToChunk(requestsByRequestResolver), ([dataSource, sequential4]) => { - const map10 = new Map; - const arr = []; - for (const block of sequential4) { - arr.push(toReadonlyArray(block)); - for (const entry of block) { - map10.set(entry.request, entry); - } - } - const flat = arr.flat(); - return fiberRefLocally(invokeWithInterrupt(dataSource.runAll(arr), flat, () => flat.forEach((entry) => { - entry.listeners.interrupted = true; - })), currentRequestMap, map10); -}, false, false)); -var _version = /* @__PURE__ */ getCurrentVersion(); - -class FiberRuntime extends Class2 { - [FiberTypeId] = fiberVariance2; - [RuntimeFiberTypeId] = runtimeFiberVariance; - _fiberRefs; - _fiberId; - _queue = /* @__PURE__ */ new Array; - _children = null; - _observers = /* @__PURE__ */ new Array; - _running = false; - _stack = []; - _asyncInterruptor = null; - _asyncBlockingOn = null; - _exitValue = null; - _steps = []; - _isYielding = false; - currentRuntimeFlags; - currentOpCount = 0; - currentSupervisor; - currentScheduler; - currentTracer; - currentSpan; - currentContext; - currentDefaultServices; - constructor(fiberId2, fiberRefs0, runtimeFlags0) { - super(); - this.currentRuntimeFlags = runtimeFlags0; - this._fiberId = fiberId2; - this._fiberRefs = fiberRefs0; - if (runtimeMetrics(runtimeFlags0)) { - const tags = this.getFiberRef(currentMetricLabels); - fiberStarted.unsafeUpdate(1, tags); - fiberActive.unsafeUpdate(1, tags); - } - this.refreshRefCache(); - } - commit() { - return join2(this); - } - id() { - return this._fiberId; - } - resume(effect) { - this.tell(resume(effect)); - } - get status() { - return this.ask((_, status) => status); - } - get runtimeFlags() { - return this.ask((state, status) => { - if (isDone2(status)) { - return state.currentRuntimeFlags; - } - return status.runtimeFlags; - }); - } - scope() { - return unsafeMake5(this); - } - get children() { - return this.ask((fiber) => Array.from(fiber.getChildren())); - } - getChildren() { - if (this._children === null) { - this._children = new Set; - } - return this._children; - } - getInterruptedCause() { - return this.getFiberRef(currentInterruptedCause); - } - fiberRefs() { - return this.ask((fiber) => fiber.getFiberRefs()); - } - ask(f) { - return suspend(() => { - const deferred = deferredUnsafeMake(this._fiberId); - this.tell(stateful((fiber, status) => { - deferredUnsafeDone(deferred, sync(() => f(fiber, status))); - })); - return deferredAwait(deferred); - }); - } - tell(message) { - this._queue.push(message); - if (!this._running) { - this._running = true; - this.drainQueueLaterOnExecutor(); - } - } - get await() { - return async_((resume2) => { - const cb = (exit2) => resume2(succeed(exit2)); - if (this._exitValue !== null) { - cb(this._exitValue); - return; - } - this.tell(stateful((fiber, _) => { - if (fiber._exitValue !== null) { - cb(this._exitValue); - } else { - fiber.addObserver(cb); - } - })); - return sync(() => this.tell(stateful((fiber, _) => { - fiber.removeObserver(cb); - }))); - }, this.id()); - } - get inheritAll() { - return withFiberRuntime((parentFiber, parentStatus) => { - const parentFiberId = parentFiber.id(); - const parentFiberRefs = parentFiber.getFiberRefs(); - const parentRuntimeFlags = parentStatus.runtimeFlags; - const childFiberRefs = this.getFiberRefs(); - const updatedFiberRefs = joinAs(parentFiberRefs, parentFiberId, childFiberRefs); - parentFiber.setFiberRefs(updatedFiberRefs); - const updatedRuntimeFlags = parentFiber.getFiberRef(currentRuntimeFlags); - const patch9 = pipe(diff4(parentRuntimeFlags, updatedRuntimeFlags), exclude2(Interruption), exclude2(WindDown)); - return updateRuntimeFlags(patch9); - }); - } - get poll() { - return sync(() => fromNullable(this._exitValue)); - } - unsafePoll() { - return this._exitValue; - } - interruptAsFork(fiberId2) { - return sync(() => this.tell(interruptSignal(interrupt(fiberId2)))); - } - unsafeInterruptAsFork(fiberId2) { - this.tell(interruptSignal(interrupt(fiberId2))); - } - addObserver(observer) { - if (this._exitValue !== null) { - observer(this._exitValue); - } else { - this._observers.push(observer); - } - } - removeObserver(observer) { - this._observers = this._observers.filter((o) => o !== observer); - } - getFiberRefs() { - this.setFiberRef(currentRuntimeFlags, this.currentRuntimeFlags); - return this._fiberRefs; - } - unsafeDeleteFiberRef(fiberRef) { - this._fiberRefs = delete_(this._fiberRefs, fiberRef); - } - getFiberRef(fiberRef) { - if (this._fiberRefs.locals.has(fiberRef)) { - return this._fiberRefs.locals.get(fiberRef)[0][1]; - } - return fiberRef.initial; - } - setFiberRef(fiberRef, value) { - this._fiberRefs = updateAs(this._fiberRefs, { - fiberId: this._fiberId, - fiberRef, - value - }); - this.refreshRefCache(); - } - refreshRefCache() { - this.currentDefaultServices = this.getFiberRef(currentServices); - this.currentTracer = this.currentDefaultServices.unsafeMap.get(tracerTag.key); - this.currentSupervisor = this.getFiberRef(currentSupervisor); - this.currentScheduler = this.getFiberRef(currentScheduler); - this.currentContext = this.getFiberRef(currentContext); - this.currentSpan = this.currentContext.unsafeMap.get(spanTag.key); - } - setFiberRefs(fiberRefs3) { - this._fiberRefs = fiberRefs3; - this.refreshRefCache(); - } - addChild(child) { - this.getChildren().add(child); - } - removeChild(child) { - this.getChildren().delete(child); - } - transferChildren(scope) { - const children = this._children; - this._children = null; - if (children !== null && children.size > 0) { - for (const child of children) { - if (child._exitValue === null) { - scope.add(this.currentRuntimeFlags, child); - } - } - } - } - drainQueueOnCurrentThread() { - let recurse = true; - while (recurse) { - let evaluationSignal = EvaluationSignalContinue; - const prev = globalThis[currentFiberURI]; - globalThis[currentFiberURI] = this; - try { - while (evaluationSignal === EvaluationSignalContinue) { - evaluationSignal = this._queue.length === 0 ? EvaluationSignalDone : this.evaluateMessageWhileSuspended(this._queue.splice(0, 1)[0]); - } - } finally { - this._running = false; - globalThis[currentFiberURI] = prev; - } - if (this._queue.length > 0 && !this._running) { - this._running = true; - if (evaluationSignal === EvaluationSignalYieldNow) { - this.drainQueueLaterOnExecutor(); - recurse = false; - } else { - recurse = true; - } - } else { - recurse = false; - } - } - } - drainQueueLaterOnExecutor() { - this.currentScheduler.scheduleTask(this.run, this.getFiberRef(currentSchedulingPriority), this); - } - drainQueueWhileRunning(runtimeFlags2, cur0) { - let cur = cur0; - while (this._queue.length > 0) { - const message = this._queue.splice(0, 1)[0]; - cur = drainQueueWhileRunningTable[message._tag](this, runtimeFlags2, cur, message); - } - return cur; - } - isInterrupted() { - return !isEmpty5(this.getFiberRef(currentInterruptedCause)); - } - addInterruptedCause(cause2) { - const oldSC = this.getFiberRef(currentInterruptedCause); - this.setFiberRef(currentInterruptedCause, sequential(oldSC, cause2)); - } - processNewInterruptSignal(cause2) { - this.addInterruptedCause(cause2); - this.sendInterruptSignalToAllChildren(); - } - sendInterruptSignalToAllChildren() { - if (this._children === null || this._children.size === 0) { - return false; - } - let told = false; - for (const child of this._children) { - child.tell(interruptSignal(interrupt(this.id()))); - told = true; - } - return told; - } - interruptAllChildren() { - if (this.sendInterruptSignalToAllChildren()) { - const it = this._children.values(); - this._children = null; - let isDone3 = false; - const body = () => { - const next = it.next(); - if (!next.done) { - return asVoid(next.value.await); - } else { - return sync(() => { - isDone3 = true; - }); - } - }; - return whileLoop({ - while: () => !isDone3, - body, - step: () => {} - }); - } - return null; - } - reportExitValue(exit2) { - if (runtimeMetrics(this.currentRuntimeFlags)) { - const tags = this.getFiberRef(currentMetricLabels); - const startTimeMillis = this.id().startTimeMillis; - const endTimeMillis = Date.now(); - fiberLifetimes.unsafeUpdate(endTimeMillis - startTimeMillis, tags); - fiberActive.unsafeUpdate(-1, tags); - switch (exit2._tag) { - case OP_SUCCESS: { - fiberSuccesses.unsafeUpdate(1, tags); - break; - } - case OP_FAILURE: { - fiberFailures.unsafeUpdate(1, tags); - break; - } - } - } - if (exit2._tag === "Failure") { - const level = this.getFiberRef(currentUnhandledErrorLogLevel); - if (!isInterruptedOnly(exit2.cause) && level._tag === "Some") { - this.log("Fiber terminated with an unhandled error", exit2.cause, level); - } - } - } - setExitValue(exit2) { - this._exitValue = exit2; - this.reportExitValue(exit2); - for (let i = this._observers.length - 1;i >= 0; i--) { - this._observers[i](exit2); - } - this._observers = []; - } - getLoggers() { - return this.getFiberRef(currentLoggers); - } - log(message, cause2, overrideLogLevel) { - const logLevel = isSome2(overrideLogLevel) ? overrideLogLevel.value : this.getFiberRef(currentLogLevel); - const minimumLogLevel = this.getFiberRef(currentMinimumLogLevel); - if (greaterThan3(minimumLogLevel, logLevel)) { - return; - } - const spans = this.getFiberRef(currentLogSpan); - const annotations = this.getFiberRef(currentLogAnnotations); - const loggers = this.getLoggers(); - const contextMap = this.getFiberRefs(); - if (size3(loggers) > 0) { - const clockService = get4(this.getFiberRef(currentServices), clockTag); - const date = new Date(clockService.unsafeCurrentTimeMillis()); - withRedactableContext(contextMap, () => { - for (const logger of loggers) { - logger.log({ - fiberId: this.id(), - logLevel, - message, - cause: cause2, - context: contextMap, - spans, - annotations, - date - }); - } - }); - } - } - evaluateMessageWhileSuspended(message) { - switch (message._tag) { - case OP_YIELD_NOW: { - return EvaluationSignalYieldNow; - } - case OP_INTERRUPT_SIGNAL: { - this.processNewInterruptSignal(message.cause); - if (this._asyncInterruptor !== null) { - this._asyncInterruptor(exitFailCause(message.cause)); - this._asyncInterruptor = null; - } - return EvaluationSignalContinue; - } - case OP_RESUME: { - this._asyncInterruptor = null; - this._asyncBlockingOn = null; - this.evaluateEffect(message.effect); - return EvaluationSignalContinue; - } - case OP_STATEFUL: { - message.onFiber(this, this._exitValue !== null ? done3 : suspended2(this.currentRuntimeFlags, this._asyncBlockingOn)); - return EvaluationSignalContinue; - } - default: { - return absurd(message); - } - } - } - evaluateEffect(effect0) { - this.currentSupervisor.onResume(this); - try { - let effect = interruptible(this.currentRuntimeFlags) && this.isInterrupted() ? exitFailCause(this.getInterruptedCause()) : effect0; - while (effect !== null) { - const eff = effect; - const exit2 = this.runLoop(eff); - if (exit2 === YieldedOp) { - const op = yieldedOpChannel.currentOp; - yieldedOpChannel.currentOp = null; - if (op._op === OP_YIELD) { - if (cooperativeYielding(this.currentRuntimeFlags)) { - this.tell(yieldNow3()); - this.tell(resume(exitVoid)); - effect = null; - } else { - effect = exitVoid; - } - } else if (op._op === OP_ASYNC) { - effect = null; - } - } else { - this.currentRuntimeFlags = pipe(this.currentRuntimeFlags, enable2(WindDown)); - const interruption2 = this.interruptAllChildren(); - if (interruption2 !== null) { - effect = flatMap7(interruption2, () => exit2); - } else { - if (this._queue.length === 0) { - this.setExitValue(exit2); - } else { - this.tell(resume(exit2)); - } - effect = null; - } - } - } - } finally { - this.currentSupervisor.onSuspend(this); - } - } - start(effect) { - if (!this._running) { - this._running = true; - const prev = globalThis[currentFiberURI]; - globalThis[currentFiberURI] = this; - try { - this.evaluateEffect(effect); - } finally { - this._running = false; - globalThis[currentFiberURI] = prev; - if (this._queue.length > 0) { - this.drainQueueLaterOnExecutor(); - } - } - } else { - this.tell(resume(effect)); - } - } - startFork(effect) { - this.tell(resume(effect)); - } - patchRuntimeFlags(oldRuntimeFlags, patch9) { - const newRuntimeFlags = patch4(oldRuntimeFlags, patch9); - globalThis[currentFiberURI] = this; - this.currentRuntimeFlags = newRuntimeFlags; - return newRuntimeFlags; - } - initiateAsync(runtimeFlags2, asyncRegister) { - let alreadyCalled = false; - const callback = (effect) => { - if (!alreadyCalled) { - alreadyCalled = true; - this.tell(resume(effect)); - } - }; - if (interruptible(runtimeFlags2)) { - this._asyncInterruptor = callback; - } - try { - asyncRegister(callback); - } catch (e) { - callback(failCause(die(e))); - } - } - pushStack(cont) { - this._stack.push(cont); - if (cont._op === "OnStep") { - this._steps.push({ - refs: this.getFiberRefs(), - flags: this.currentRuntimeFlags - }); - } - } - popStack() { - const item = this._stack.pop(); - if (item) { - if (item._op === "OnStep") { - this._steps.pop(); - } - return item; - } - return; - } - getNextSuccessCont() { - let frame = this.popStack(); - while (frame) { - if (frame._op !== OP_ON_FAILURE) { - return frame; - } - frame = this.popStack(); - } - } - getNextFailCont() { - let frame = this.popStack(); - while (frame) { - if (frame._op !== OP_ON_SUCCESS && frame._op !== OP_WHILE && frame._op !== OP_ITERATOR) { - return frame; - } - frame = this.popStack(); - } - } - [OP_TAG](op) { - return sync(() => unsafeGet4(this.currentContext, op)); - } - ["Left"](op) { - return fail2(op.left); - } - ["None"](_) { - return fail2(new NoSuchElementException); - } - ["Right"](op) { - return exitSucceed(op.right); - } - ["Some"](op) { - return exitSucceed(op.value); - } - ["Micro"](op) { - return unsafeAsync((microResume) => { - let resume2 = microResume; - const fiber = runFork(provideContext2(op, this.currentContext)); - fiber.addObserver((exit2) => { - if (exit2._tag === "Success") { - return resume2(exitSucceed(exit2.value)); - } - switch (exit2.cause._tag) { - case "Interrupt": { - return resume2(exitFailCause(interrupt(none4))); - } - case "Fail": { - return resume2(fail2(exit2.cause.error)); - } - case "Die": { - return resume2(die2(exit2.cause.defect)); - } - } - }); - return unsafeAsync((abortResume) => { - resume2 = (_) => { - abortResume(void_); - }; - fiber.unsafeInterrupt(); - }); - }); - } - [OP_SYNC](op) { - const value = internalCall(() => op.effect_instruction_i0()); - const cont = this.getNextSuccessCont(); - if (cont !== undefined) { - if (!(cont._op in contOpSuccess)) { - absurd(cont); - } - return contOpSuccess[cont._op](this, cont, value); - } else { - yieldedOpChannel.currentOp = exitSucceed(value); - return YieldedOp; - } - } - [OP_SUCCESS](op) { - const oldCur = op; - const cont = this.getNextSuccessCont(); - if (cont !== undefined) { - if (!(cont._op in contOpSuccess)) { - absurd(cont); - } - return contOpSuccess[cont._op](this, cont, oldCur.effect_instruction_i0); - } else { - yieldedOpChannel.currentOp = oldCur; - return YieldedOp; - } - } - [OP_FAILURE](op) { - const cause2 = op.effect_instruction_i0; - const cont = this.getNextFailCont(); - if (cont !== undefined) { - switch (cont._op) { - case OP_ON_FAILURE: - case OP_ON_SUCCESS_AND_FAILURE: { - if (!(interruptible(this.currentRuntimeFlags) && this.isInterrupted())) { - return internalCall(() => cont.effect_instruction_i1(cause2)); - } else { - return exitFailCause(stripFailures(cause2)); - } - } - case "OnStep": { - if (!(interruptible(this.currentRuntimeFlags) && this.isInterrupted())) { - return exitSucceed(exitFailCause(cause2)); - } else { - return exitFailCause(stripFailures(cause2)); - } - } - case OP_REVERT_FLAGS: { - this.patchRuntimeFlags(this.currentRuntimeFlags, cont.patch); - if (interruptible(this.currentRuntimeFlags) && this.isInterrupted()) { - return exitFailCause(sequential(cause2, this.getInterruptedCause())); - } else { - return exitFailCause(cause2); - } - } - default: { - absurd(cont); - } - } - } else { - yieldedOpChannel.currentOp = exitFailCause(cause2); - return YieldedOp; - } - } - [OP_WITH_RUNTIME](op) { - return internalCall(() => op.effect_instruction_i0(this, running2(this.currentRuntimeFlags))); - } - ["Blocked"](op) { - const refs = this.getFiberRefs(); - const flags = this.currentRuntimeFlags; - if (this._steps.length > 0) { - const frames = []; - const snap = this._steps[this._steps.length - 1]; - let frame = this.popStack(); - while (frame && frame._op !== "OnStep") { - frames.push(frame); - frame = this.popStack(); - } - this.setFiberRefs(snap.refs); - this.currentRuntimeFlags = snap.flags; - const patchRefs = diff6(snap.refs, refs); - const patchFlags = diff4(snap.flags, flags); - return exitSucceed(blocked(op.effect_instruction_i0, withFiberRuntime((newFiber) => { - while (frames.length > 0) { - newFiber.pushStack(frames.pop()); - } - newFiber.setFiberRefs(patch7(newFiber.id(), newFiber.getFiberRefs())(patchRefs)); - newFiber.currentRuntimeFlags = patch4(patchFlags)(newFiber.currentRuntimeFlags); - return op.effect_instruction_i1; - }))); - } - return uninterruptibleMask((restore) => flatMap7(forkDaemon(runRequestBlock(op.effect_instruction_i0)), () => restore(op.effect_instruction_i1))); - } - ["RunBlocked"](op) { - return runBlockedRequests(op.effect_instruction_i0); - } - [OP_UPDATE_RUNTIME_FLAGS](op) { - const updateFlags = op.effect_instruction_i0; - const oldRuntimeFlags = this.currentRuntimeFlags; - const newRuntimeFlags = patch4(oldRuntimeFlags, updateFlags); - if (interruptible(newRuntimeFlags) && this.isInterrupted()) { - return exitFailCause(this.getInterruptedCause()); - } else { - this.patchRuntimeFlags(this.currentRuntimeFlags, updateFlags); - if (op.effect_instruction_i1) { - const revertFlags = diff4(newRuntimeFlags, oldRuntimeFlags); - this.pushStack(new RevertFlags(revertFlags, op)); - return internalCall(() => op.effect_instruction_i1(oldRuntimeFlags)); - } else { - return exitVoid; - } - } - } - [OP_ON_SUCCESS](op) { - this.pushStack(op); - return op.effect_instruction_i0; - } - ["OnStep"](op) { - this.pushStack(op); - return op.effect_instruction_i0; - } - [OP_ON_FAILURE](op) { - this.pushStack(op); - return op.effect_instruction_i0; - } - [OP_ON_SUCCESS_AND_FAILURE](op) { - this.pushStack(op); - return op.effect_instruction_i0; - } - [OP_ASYNC](op) { - this._asyncBlockingOn = op.effect_instruction_i1; - this.initiateAsync(this.currentRuntimeFlags, op.effect_instruction_i0); - yieldedOpChannel.currentOp = op; - return YieldedOp; - } - [OP_YIELD](op) { - this._isYielding = false; - yieldedOpChannel.currentOp = op; - return YieldedOp; - } - [OP_WHILE](op) { - const check = op.effect_instruction_i0; - const body = op.effect_instruction_i1; - if (check()) { - this.pushStack(op); - return body(); - } else { - return exitVoid; - } - } - [OP_ITERATOR](op) { - return contOpSuccess[OP_ITERATOR](this, op, undefined); - } - [OP_COMMIT](op) { - return internalCall(() => op.commit()); - } - runLoop(effect0) { - let cur = effect0; - this.currentOpCount = 0; - while (true) { - if ((this.currentRuntimeFlags & OpSupervision) !== 0) { - this.currentSupervisor.onEffect(this, cur); - } - if (this._queue.length > 0) { - cur = this.drainQueueWhileRunning(this.currentRuntimeFlags, cur); - } - if (!this._isYielding) { - this.currentOpCount += 1; - const shouldYield = this.currentScheduler.shouldYield(this); - if (shouldYield !== false) { - this._isYielding = true; - this.currentOpCount = 0; - const oldCur = cur; - cur = flatMap7(yieldNow({ - priority: shouldYield - }), () => oldCur); - } - } - try { - cur = this.currentTracer.context(() => { - if (_version !== cur[EffectTypeId2]._V) { - const level = this.getFiberRef(currentVersionMismatchErrorLogLevel); - if (level._tag === "Some") { - const effectVersion = cur[EffectTypeId2]._V; - this.log(`Executing an Effect versioned ${effectVersion} with a Runtime of version ${getCurrentVersion()}, you may want to dedupe the effect dependencies, you can use the language service plugin to detect this at compile time: https://github.com/Effect-TS/language-service`, empty16, level); - } - } - return this[cur._op](cur); - }, this); - if (cur === YieldedOp) { - const op = yieldedOpChannel.currentOp; - if (op._op === OP_YIELD || op._op === OP_ASYNC) { - return YieldedOp; - } - yieldedOpChannel.currentOp = null; - return op._op === OP_SUCCESS || op._op === OP_FAILURE ? op : exitFailCause(die(op)); - } - } catch (e) { - if (cur !== YieldedOp && !hasProperty(cur, "_op") || !(cur._op in this)) { - cur = dieMessage(`Not a valid effect: ${toStringUnknown(cur)}`); - } else if (isInterruptedException(e)) { - cur = exitFailCause(sequential(die(e), interrupt(none4))); - } else { - cur = die2(e); - } - } - } - } - run = () => { - this.drainQueueOnCurrentThread(); - }; -} -var currentMinimumLogLevel = /* @__PURE__ */ globalValue("effect/FiberRef/currentMinimumLogLevel", () => fiberRefUnsafeMake(fromLiteral("Info"))); -var loggerWithConsoleLog = (self) => makeLogger((opts) => { - const services = getOrDefault2(opts.context, currentServices); - get4(services, consoleTag).unsafe.log(self.log(opts)); -}); -var defaultLogger = /* @__PURE__ */ globalValue(/* @__PURE__ */ Symbol.for("effect/Logger/defaultLogger"), () => loggerWithConsoleLog(stringLogger)); -var tracerLogger = /* @__PURE__ */ globalValue(/* @__PURE__ */ Symbol.for("effect/Logger/tracerLogger"), () => makeLogger(({ - annotations, - cause: cause2, - context: context2, - fiberId: fiberId2, - logLevel, - message -}) => { - const span2 = filterDisablePropagation(getOption2(getOrDefault(context2, currentContext), spanTag)); - if (span2._tag === "None" || span2.value._tag === "ExternalSpan") { - return; - } - const clockService = unsafeGet4(getOrDefault(context2, currentServices), clockTag); - const attributes = {}; - for (const [key, value] of annotations) { - attributes[key] = value; - } - attributes["effect.fiberId"] = threadName2(fiberId2); - attributes["effect.logLevel"] = logLevel.label; - if (cause2 !== null && cause2._tag !== "Empty") { - attributes["effect.cause"] = pretty(cause2, { - renderErrorCause: true - }); - } - span2.value.event(toStringUnknown(Array.isArray(message) && message.length === 1 ? message[0] : message), clockService.unsafeCurrentTimeNanos(), attributes); -})); -var currentLoggers = /* @__PURE__ */ globalValue(/* @__PURE__ */ Symbol.for("effect/FiberRef/currentLoggers"), () => fiberRefUnsafeMakeHashSet(make10(defaultLogger, tracerLogger))); -var annotateLogsScoped = function() { - if (typeof arguments[0] === "string") { - return fiberRefLocallyScopedWith(currentLogAnnotations, set3(arguments[0], arguments[1])); - } - const entries2 = Object.entries(arguments[0]); - return fiberRefLocallyScopedWith(currentLogAnnotations, mutate3((annotations) => { - for (let i = 0;i < entries2.length; i++) { - const [key, value] = entries2[i]; - set3(annotations, key, value); - } - return annotations; - })); -}; -var whenLogLevel = /* @__PURE__ */ dual(2, (effect, level) => { - const requiredLogLevel = typeof level === "string" ? fromLiteral(level) : level; - return withFiberRuntime((fiberState) => { - const minimumLogLevel = fiberState.getFiberRef(currentMinimumLogLevel); - if (greaterThan3(minimumLogLevel, requiredLogLevel)) { - return succeed(none2()); - } - return map9(effect, some2); - }); -}); -var acquireRelease = /* @__PURE__ */ dual((args2) => isEffect(args2[0]), (acquire, release) => uninterruptible(tap(acquire, (a) => addFinalizer((exit2) => release(a, exit2))))); -var acquireReleaseInterruptible = /* @__PURE__ */ dual((args2) => isEffect(args2[0]), (acquire, release) => ensuring(acquire, addFinalizer((exit2) => release(exit2)))); -var addFinalizer = (finalizer) => withFiberRuntime((runtime3) => { - const acquireRefs = runtime3.getFiberRefs(); - const acquireFlags = disable2(runtime3.currentRuntimeFlags, Interruption); - return flatMap7(scope, (scope) => scopeAddFinalizerExit(scope, (exit2) => withFiberRuntime((runtimeFinalizer) => { - const preRefs = runtimeFinalizer.getFiberRefs(); - const preFlags = runtimeFinalizer.currentRuntimeFlags; - const patchRefs = diff6(preRefs, acquireRefs); - const patchFlags = diff4(preFlags, acquireFlags); - const inverseRefs = diff6(acquireRefs, preRefs); - runtimeFinalizer.setFiberRefs(patch7(patchRefs, runtimeFinalizer.id(), acquireRefs)); - return ensuring(withRuntimeFlags(finalizer(exit2), patchFlags), sync(() => { - runtimeFinalizer.setFiberRefs(patch7(inverseRefs, runtimeFinalizer.id(), runtimeFinalizer.getFiberRefs())); - })); - }))); -}); -var daemonChildren = (self) => { - const forkScope = fiberRefLocally(currentForkScopeOverride, some2(globalScope)); - return forkScope(self); -}; -var _existsParFound = /* @__PURE__ */ Symbol.for("effect/Effect/existsPar/found"); -var exists2 = /* @__PURE__ */ dual((args2) => isIterable(args2[0]) && !isEffect(args2[0]), (elements, predicate, options) => matchSimple(options?.concurrency, () => suspend(() => existsLoop(elements[Symbol.iterator](), 0, predicate)), () => matchEffect(forEach6(elements, (a, i) => if_(predicate(a, i), { - onTrue: () => fail2(_existsParFound), - onFalse: () => void_ -}), options), { - onFailure: (e) => e === _existsParFound ? succeed(true) : fail2(e), - onSuccess: () => succeed(false) -}))); -var existsLoop = (iterator, index, f) => { - const next = iterator.next(); - if (next.done) { - return succeed(false); - } - return flatMap7(f(next.value, index), (b) => b ? succeed(b) : existsLoop(iterator, index + 1, f)); -}; -var filter5 = /* @__PURE__ */ dual((args2) => isIterable(args2[0]) && !isEffect(args2[0]), (elements, predicate, options) => { - const predicate_ = options?.negate ? (a, i) => map9(predicate(a, i), not) : predicate; - return matchSimple(options?.concurrency, () => suspend(() => fromIterable(elements).reduceRight((effect, a, i) => zipWith2(effect, suspend(() => predicate_(a, i)), (list, b) => b ? [a, ...list] : list), sync(() => new Array))), () => map9(forEach6(elements, (a, i) => map9(predicate_(a, i), (b) => b ? some2(a) : none2()), options), getSomes)); -}); -var allResolveInput = (input) => { - if (Array.isArray(input) || isIterable(input)) { - return [input, none2()]; - } - const keys5 = Object.keys(input); - const size7 = keys5.length; - return [keys5.map((k) => input[k]), some2((values4) => { - const res = {}; - for (let i = 0;i < size7; i++) { - res[keys5[i]] = values4[i]; - } - return res; - })]; -}; -var allValidate = (effects, reconcile, options) => { - const eitherEffects = []; - for (const effect of effects) { - eitherEffects.push(either2(effect)); - } - return flatMap7(forEach6(eitherEffects, identity, { - concurrency: options?.concurrency, - batching: options?.batching, - concurrentFinalizers: options?.concurrentFinalizers - }), (eithers) => { - const none9 = none2(); - const size7 = eithers.length; - const errors = new Array(size7); - const successes = new Array(size7); - let errored = false; - for (let i = 0;i < size7; i++) { - const either3 = eithers[i]; - if (either3._tag === "Left") { - errors[i] = some2(either3.left); - errored = true; - } else { - successes[i] = either3.right; - errors[i] = none9; - } - } - if (errored) { - return reconcile._tag === "Some" ? fail2(reconcile.value(errors)) : fail2(errors); - } else if (options?.discard) { - return void_; - } - return reconcile._tag === "Some" ? succeed(reconcile.value(successes)) : succeed(successes); - }); -}; -var allEither = (effects, reconcile, options) => { - const eitherEffects = []; - for (const effect of effects) { - eitherEffects.push(either2(effect)); - } - if (options?.discard) { - return forEach6(eitherEffects, identity, { - concurrency: options?.concurrency, - batching: options?.batching, - discard: true, - concurrentFinalizers: options?.concurrentFinalizers - }); - } - return map9(forEach6(eitherEffects, identity, { - concurrency: options?.concurrency, - batching: options?.batching, - concurrentFinalizers: options?.concurrentFinalizers - }), (eithers) => reconcile._tag === "Some" ? reconcile.value(eithers) : eithers); -}; -var all2 = (arg, options) => { - const [effects, reconcile] = allResolveInput(arg); - if (options?.mode === "validate") { - return allValidate(effects, reconcile, options); - } else if (options?.mode === "either") { - return allEither(effects, reconcile, options); - } - return options?.discard !== true && reconcile._tag === "Some" ? map9(forEach6(effects, identity, options), reconcile.value) : forEach6(effects, identity, options); -}; -var allWith = (options) => (arg) => all2(arg, options); -var allSuccesses = (elements, options) => map9(all2(fromIterable(elements).map(exit), options), filterMap2((exit2) => exitIsSuccess(exit2) ? some2(exit2.effect_instruction_i0) : none2())); -var replicate = /* @__PURE__ */ dual(2, (self, n) => Array.from({ - length: n -}, () => self)); -var replicateEffect = /* @__PURE__ */ dual((args2) => isEffect(args2[0]), (self, n, options) => all2(replicate(self, n), options)); -var forEach6 = /* @__PURE__ */ dual((args2) => isIterable(args2[0]), (self, f, options) => withFiberRuntime((r) => { - const isRequestBatchingEnabled = options?.batching === true || options?.batching === "inherit" && r.getFiberRef(currentRequestBatching); - if (options?.discard) { - return match7(options.concurrency, () => finalizersMaskInternal(sequential3, options?.concurrentFinalizers)((restore) => isRequestBatchingEnabled ? forEachConcurrentDiscard(self, (a, i) => restore(f(a, i)), true, false, 1) : forEachSequentialDiscard(self, (a, i) => restore(f(a, i)))), () => finalizersMaskInternal(parallel3, options?.concurrentFinalizers)((restore) => forEachConcurrentDiscard(self, (a, i) => restore(f(a, i)), isRequestBatchingEnabled, false)), (n) => finalizersMaskInternal(parallelN2(n), options?.concurrentFinalizers)((restore) => forEachConcurrentDiscard(self, (a, i) => restore(f(a, i)), isRequestBatchingEnabled, false, n))); - } - return match7(options?.concurrency, () => finalizersMaskInternal(sequential3, options?.concurrentFinalizers)((restore) => isRequestBatchingEnabled ? forEachParN(self, 1, (a, i) => restore(f(a, i)), true) : forEachSequential(self, (a, i) => restore(f(a, i)))), () => finalizersMaskInternal(parallel3, options?.concurrentFinalizers)((restore) => forEachParUnbounded(self, (a, i) => restore(f(a, i)), isRequestBatchingEnabled)), (n) => finalizersMaskInternal(parallelN2(n), options?.concurrentFinalizers)((restore) => forEachParN(self, n, (a, i) => restore(f(a, i)), isRequestBatchingEnabled))); -})); -var forEachParUnbounded = (self, f, batching) => suspend(() => { - const as2 = fromIterable(self); - const array4 = new Array(as2.length); - const fn = (a, i) => flatMap7(f(a, i), (b) => sync(() => array4[i] = b)); - return zipRight(forEachConcurrentDiscard(as2, fn, batching, false), succeed(array4)); -}); -var forEachConcurrentDiscard = (self, f, batching, processAll, n) => uninterruptibleMask((restore) => transplant((graft) => withFiberRuntime((parent) => { - let todos = Array.from(self).reverse(); - let target = todos.length; - if (target === 0) { - return void_; - } - let counter6 = 0; - let interrupted = false; - const fibersCount = n ? Math.min(todos.length, n) : todos.length; - const fibers = new Set; - const results = new Array; - const interruptAll = () => fibers.forEach((fiber) => { - fiber.currentScheduler.scheduleTask(() => { - fiber.unsafeInterruptAsFork(parent.id()); - }, 0, fiber); - }); - const startOrder = new Array; - const joinOrder = new Array; - const residual = new Array; - const collectExits = () => { - const exits = results.filter(({ - exit: exit2 - }) => exit2._tag === "Failure").sort((a, b) => a.index < b.index ? -1 : a.index === b.index ? 0 : 1).map(({ - exit: exit2 - }) => exit2); - if (exits.length === 0) { - exits.push(exitVoid); - } - return exits; - }; - const runFiber = (eff, interruptImmediately = false) => { - const runnable = uninterruptible(graft(eff)); - const fiber = unsafeForkUnstarted(runnable, parent, parent.currentRuntimeFlags, globalScope); - parent.currentScheduler.scheduleTask(() => { - if (interruptImmediately) { - fiber.unsafeInterruptAsFork(parent.id()); - } - fiber.resume(runnable); - }, 0, fiber); - return fiber; - }; - const onInterruptSignal = () => { - if (!processAll) { - target -= todos.length; - todos = []; - } - interrupted = true; - interruptAll(); - }; - const stepOrExit = batching ? step2 : exit; - const processingFiber = runFiber(async_((resume2) => { - const pushResult = (res, index) => { - if (res._op === "Blocked") { - residual.push(res); - } else { - results.push({ - index, - exit: res - }); - if (res._op === "Failure" && !interrupted) { - onInterruptSignal(); - } - } - }; - const next = () => { - if (todos.length > 0) { - const a = todos.pop(); - let index = counter6++; - const returnNextElement = () => { - const a2 = todos.pop(); - index = counter6++; - return flatMap7(yieldNow(), () => flatMap7(stepOrExit(restore(f(a2, index))), onRes)); - }; - const onRes = (res) => { - if (todos.length > 0) { - pushResult(res, index); - if (todos.length > 0) { - return returnNextElement(); - } - } - return succeed(res); - }; - const todo = flatMap7(stepOrExit(restore(f(a, index))), onRes); - const fiber = runFiber(todo); - startOrder.push(fiber); - fibers.add(fiber); - if (interrupted) { - fiber.currentScheduler.scheduleTask(() => { - fiber.unsafeInterruptAsFork(parent.id()); - }, 0, fiber); - } - fiber.addObserver((wrapped) => { - let exit2; - if (wrapped._op === "Failure") { - exit2 = wrapped; - } else { - exit2 = wrapped.effect_instruction_i0; - } - joinOrder.push(fiber); - fibers.delete(fiber); - pushResult(exit2, index); - if (results.length === target) { - resume2(succeed(getOrElse(exitCollectAll(collectExits(), { - parallel: true - }), () => exitVoid))); - } else if (residual.length + results.length === target) { - const exits = collectExits(); - const requests = residual.map((blocked2) => blocked2.effect_instruction_i0).reduce(par); - resume2(succeed(blocked(requests, forEachConcurrentDiscard([getOrElse(exitCollectAll(exits, { - parallel: true - }), () => exitVoid), ...residual.map((blocked2) => blocked2.effect_instruction_i1)], (i) => i, batching, true, n)))); - } else { - next(); - } - }); - } - }; - for (let i = 0;i < fibersCount; i++) { - next(); - } - })); - return asVoid(onExit(flatten4(restore(join2(processingFiber))), exitMatch({ - onFailure: (cause2) => { - onInterruptSignal(); - const target2 = residual.length + 1; - const concurrency = Math.min(typeof n === "number" ? n : residual.length, residual.length); - const toPop = Array.from(residual); - return async_((cb) => { - const exits = []; - let count = 0; - let index = 0; - const check = (index2, hitNext) => (exit2) => { - exits[index2] = exit2; - count++; - if (count === target2) { - cb(exitSucceed(exitFailCause(cause2))); - } - if (toPop.length > 0 && hitNext) { - next(); - } - }; - const next = () => { - runFiber(toPop.pop(), true).addObserver(check(index, true)); - index++; - }; - processingFiber.addObserver(check(index, false)); - index++; - for (let i = 0;i < concurrency; i++) { - next(); - } - }); - }, - onSuccess: () => forEachSequential(joinOrder, (f2) => f2.inheritAll) - }))); -}))); -var forEachParN = (self, n, f, batching) => suspend(() => { - const as2 = fromIterable(self); - const array4 = new Array(as2.length); - const fn = (a, i) => map9(f(a, i), (b) => array4[i] = b); - return zipRight(forEachConcurrentDiscard(as2, fn, batching, false, n), succeed(array4)); -}); -var fork = (self) => withFiberRuntime((state, status) => succeed(unsafeFork(self, state, status.runtimeFlags))); -var forkDaemon = (self) => forkWithScopeOverride(self, globalScope); -var forkWithErrorHandler = /* @__PURE__ */ dual(2, (self, handler) => fork(onError(self, (cause2) => { - const either3 = failureOrCause(cause2); - switch (either3._tag) { - case "Left": - return handler(either3.left); - case "Right": - return failCause(either3.right); - } -}))); -var unsafeFork = (effect, parentFiber, parentRuntimeFlags, overrideScope = null) => { - const childFiber = unsafeMakeChildFiber(effect, parentFiber, parentRuntimeFlags, overrideScope); - childFiber.resume(effect); - return childFiber; -}; -var unsafeForkUnstarted = (effect, parentFiber, parentRuntimeFlags, overrideScope = null) => { - const childFiber = unsafeMakeChildFiber(effect, parentFiber, parentRuntimeFlags, overrideScope); - return childFiber; -}; -var unsafeMakeChildFiber = (effect, parentFiber, parentRuntimeFlags, overrideScope = null) => { - const childId = unsafeMake2(); - const parentFiberRefs = parentFiber.getFiberRefs(); - const childFiberRefs = forkAs(parentFiberRefs, childId); - const childFiber = new FiberRuntime(childId, childFiberRefs, parentRuntimeFlags); - const childContext = getOrDefault(childFiberRefs, currentContext); - const supervisor = childFiber.currentSupervisor; - supervisor.onStart(childContext, effect, some2(parentFiber), childFiber); - childFiber.addObserver((exit2) => supervisor.onEnd(exit2, childFiber)); - const parentScope = overrideScope !== null ? overrideScope : pipe(parentFiber.getFiberRef(currentForkScopeOverride), getOrElse(() => parentFiber.scope())); - parentScope.add(parentRuntimeFlags, childFiber); - return childFiber; -}; -var forkWithScopeOverride = (self, scopeOverride) => withFiberRuntime((parentFiber, parentStatus) => succeed(unsafeFork(self, parentFiber, parentStatus.runtimeFlags, scopeOverride))); -var mergeAll3 = /* @__PURE__ */ dual((args2) => isFunction2(args2[2]), (elements, zero2, f, options) => matchSimple(options?.concurrency, () => fromIterable(elements).reduce((acc, a, i) => zipWith2(acc, a, (acc2, a2) => f(acc2, a2, i)), succeed(zero2)), () => flatMap7(make24(zero2), (acc) => flatMap7(forEach6(elements, (effect, i) => flatMap7(effect, (a) => update3(acc, (b) => f(b, a, i))), options), () => get11(acc))))); -var partition3 = /* @__PURE__ */ dual((args2) => isIterable(args2[0]), (elements, f, options) => pipe(forEach6(elements, (a, i) => either2(f(a, i)), options), map9((chunk2) => partitionMap2(chunk2, identity)))); -var validateAll = /* @__PURE__ */ dual((args2) => isIterable(args2[0]), (elements, f, options) => flatMap7(partition3(elements, f, { - concurrency: options?.concurrency, - batching: options?.batching, - concurrentFinalizers: options?.concurrentFinalizers -}), ([es, bs]) => isNonEmptyArray2(es) ? fail2(es) : options?.discard ? void_ : succeed(bs))); -var raceAll = (all3) => withFiberRuntime((state, status) => async_((resume2) => { - const fibers = new Set; - let winner; - let failures2 = empty16; - const interruptAll = () => { - for (const fiber of fibers) { - fiber.unsafeInterruptAsFork(state.id()); - } - }; - let latch = false; - let empty25 = true; - for (const self of all3) { - empty25 = false; - const fiber = unsafeFork(interruptible2(self), state, status.runtimeFlags); - fibers.add(fiber); - fiber.addObserver((exit2) => { - fibers.delete(fiber); - if (!winner) { - if (exit2._tag === "Success") { - latch = true; - winner = fiber; - failures2 = empty16; - interruptAll(); - } else { - failures2 = parallel(exit2.cause, failures2); - } - } - if (latch && fibers.size === 0) { - resume2(winner ? zipRight(inheritAll(winner), winner.unsafePoll()) : failCause(failures2)); - } - }); - if (winner) - break; - } - if (empty25) { - return resume2(dieSync(() => new IllegalArgumentException(`Received an empty collection of effects`))); - } - latch = true; - return interruptAllAs(fibers, state.id()); -})); -var reduceEffect = /* @__PURE__ */ dual((args2) => isIterable(args2[0]) && !isEffect(args2[0]), (elements, zero2, f, options) => matchSimple(options?.concurrency, () => fromIterable(elements).reduce((acc, a, i) => zipWith2(acc, a, (acc2, a2) => f(acc2, a2, i)), zero2), () => suspend(() => pipe(mergeAll3([zero2, ...elements], none2(), (acc, elem, i) => { - switch (acc._tag) { - case "None": { - return some2(elem); - } - case "Some": { - return some2(f(acc.value, elem, i)); - } - } -}, options), map9((option2) => { - switch (option2._tag) { - case "None": { - throw new Error("BUG: Effect.reduceEffect - please report an issue at https://github.com/Effect-TS/effect/issues"); - } - case "Some": { - return option2.value; - } - } -}))))); -var parallelFinalizers = (self) => contextWithEffect((context2) => match2(getOption2(context2, scopeTag), { - onNone: () => self, - onSome: (scope) => { - switch (scope.strategy._tag) { - case "Parallel": - return self; - case "Sequential": - case "ParallelN": - return flatMap7(scopeFork(scope, parallel3), (inner) => scopeExtend(self, inner)); - } - } -})); -var parallelNFinalizers = (parallelism) => (self) => contextWithEffect((context2) => match2(getOption2(context2, scopeTag), { - onNone: () => self, - onSome: (scope) => { - if (scope.strategy._tag === "ParallelN" && scope.strategy.parallelism === parallelism) { - return self; - } - return flatMap7(scopeFork(scope, parallelN2(parallelism)), (inner) => scopeExtend(self, inner)); - } -})); -var finalizersMask = (strategy) => (self) => finalizersMaskInternal(strategy, true)(self); -var finalizersMaskInternal = (strategy, concurrentFinalizers) => (self) => contextWithEffect((context2) => match2(getOption2(context2, scopeTag), { - onNone: () => self(identity), - onSome: (scope) => { - if (concurrentFinalizers === true) { - const patch9 = strategy._tag === "Parallel" ? parallelFinalizers : strategy._tag === "Sequential" ? sequentialFinalizers : parallelNFinalizers(strategy.parallelism); - switch (scope.strategy._tag) { - case "Parallel": - return patch9(self(parallelFinalizers)); - case "Sequential": - return patch9(self(sequentialFinalizers)); - case "ParallelN": - return patch9(self(parallelNFinalizers(scope.strategy.parallelism))); - } - } else { - return self(identity); - } - } -})); -var scopeWith = (f) => flatMap7(scopeTag, f); -var scopedWith = (f) => flatMap7(scopeMake(), (scope) => onExit(f(scope), (exit2) => scope.close(exit2))); -var scopedEffect = (effect) => flatMap7(scopeMake(), (scope) => scopeUse(effect, scope)); -var sequentialFinalizers = (self) => contextWithEffect((context2) => match2(getOption2(context2, scopeTag), { - onNone: () => self, - onSome: (scope) => { - switch (scope.strategy._tag) { - case "Sequential": - return self; - case "Parallel": - case "ParallelN": - return flatMap7(scopeFork(scope, sequential3), (inner) => scopeExtend(self, inner)); - } - } -})); -var tagMetricsScoped = (key, value) => labelMetricsScoped([make27(key, value)]); -var labelMetricsScoped = (labels) => fiberRefLocallyScopedWith(currentMetricLabels, (old) => union(old, labels)); -var using = /* @__PURE__ */ dual(2, (self, use) => scopedWith((scope) => flatMap7(scopeExtend(self, scope), use))); -var validate = /* @__PURE__ */ dual((args2) => isEffect(args2[1]), (self, that, options) => validateWith(self, that, (a, b) => [a, b], options)); -var validateWith = /* @__PURE__ */ dual((args2) => isEffect(args2[1]), (self, that, f, options) => flatten4(zipWithOptions(exit(self), exit(that), (ea, eb) => exitZipWith(ea, eb, { - onSuccess: f, - onFailure: (ca, cb) => options?.concurrent ? parallel(ca, cb) : sequential(ca, cb) -}), options))); -var validateFirst = /* @__PURE__ */ dual((args2) => isIterable(args2[0]), (elements, f, options) => flip(forEach6(elements, (a, i) => flip(f(a, i)), options))); -var withClockScoped = (c) => fiberRefLocallyScopedWith(currentServices, add2(clockTag, c)); -var withRandomScoped = (value) => fiberRefLocallyScopedWith(currentServices, add2(randomTag, value)); -var withConfigProviderScoped = (provider) => fiberRefLocallyScopedWith(currentServices, add2(configProviderTag, provider)); -var withEarlyRelease = (self) => scopeWith((parent) => flatMap7(scopeFork(parent, sequential2), (child) => pipe(self, scopeExtend(child), map9((value) => [fiberIdWith((fiberId2) => scopeClose(child, exitInterrupt(fiberId2))), value])))); -var zipOptions = /* @__PURE__ */ dual((args2) => isEffect(args2[1]), (self, that, options) => zipWithOptions(self, that, (a, b) => [a, b], options)); -var zipLeftOptions = /* @__PURE__ */ dual((args2) => isEffect(args2[1]), (self, that, options) => { - if (options?.concurrent !== true && (options?.batching === undefined || options.batching === false)) { - return zipLeft(self, that); - } - return zipWithOptions(self, that, (a, _) => a, options); -}); -var zipRightOptions = /* @__PURE__ */ dual((args2) => isEffect(args2[1]), (self, that, options) => { - if (options?.concurrent !== true && (options?.batching === undefined || options.batching === false)) { - return zipRight(self, that); - } - return zipWithOptions(self, that, (_, b) => b, options); -}); -var zipWithOptions = /* @__PURE__ */ dual((args2) => isEffect(args2[1]), (self, that, f, options) => map9(all2([self, that], { - concurrency: options?.concurrent ? 2 : 1, - batching: options?.batching, - concurrentFinalizers: options?.concurrentFinalizers -}), ([a, a2]) => f(a, a2))); -var withRuntimeFlagsScoped = (update5) => { - if (update5 === empty14) { - return void_; - } - return pipe(runtimeFlags, flatMap7((runtimeFlags2) => { - const updatedRuntimeFlags = patch4(runtimeFlags2, update5); - const revertRuntimeFlags = diff4(updatedRuntimeFlags, runtimeFlags2); - return pipe(updateRuntimeFlags(update5), zipRight(addFinalizer(() => updateRuntimeFlags(revertRuntimeFlags))), asVoid); - }), uninterruptible); -}; -var scopeTag = /* @__PURE__ */ GenericTag("effect/Scope"); -var scope = scopeTag; -var scopeUnsafeAddFinalizer = (scope2, fin) => { - if (scope2.state._tag === "Open") { - scope2.state.finalizers.set({}, fin); - } -}; -var ScopeImplProto = { - [ScopeTypeId]: ScopeTypeId, - [CloseableScopeTypeId]: CloseableScopeTypeId, - pipe() { - return pipeArguments(this, arguments); - }, - fork(strategy) { - return sync(() => { - const newScope = scopeUnsafeMake(strategy); - if (this.state._tag === "Closed") { - newScope.state = this.state; - return newScope; - } - const key = {}; - const fin = (exit2) => newScope.close(exit2); - this.state.finalizers.set(key, fin); - scopeUnsafeAddFinalizer(newScope, (_) => sync(() => { - if (this.state._tag === "Open") { - this.state.finalizers.delete(key); - } - })); - return newScope; - }); - }, - close(exit2) { - return suspend(() => { - if (this.state._tag === "Closed") { - return void_; - } - const finalizers = Array.from(this.state.finalizers.values()).reverse(); - this.state = { - _tag: "Closed", - exit: exit2 - }; - if (finalizers.length === 0) { - return void_; - } - return isSequential(this.strategy) ? pipe(forEachSequential(finalizers, (fin) => exit(fin(exit2))), flatMap7((results) => pipe(exitCollectAll(results), map2(exitAsVoid), getOrElse(() => exitVoid)))) : isParallel(this.strategy) ? pipe(forEachParUnbounded(finalizers, (fin) => exit(fin(exit2)), false), flatMap7((results) => pipe(exitCollectAll(results, { - parallel: true - }), map2(exitAsVoid), getOrElse(() => exitVoid)))) : pipe(forEachParN(finalizers, this.strategy.parallelism, (fin) => exit(fin(exit2)), false), flatMap7((results) => pipe(exitCollectAll(results, { - parallel: true - }), map2(exitAsVoid), getOrElse(() => exitVoid)))); - }); - }, - addFinalizer(fin) { - return suspend(() => { - if (this.state._tag === "Closed") { - return fin(this.state.exit); - } - this.state.finalizers.set({}, fin); - return void_; - }); - } -}; -var scopeUnsafeMake = (strategy = sequential2) => { - const scope2 = Object.create(ScopeImplProto); - scope2.strategy = strategy; - scope2.state = { - _tag: "Open", - finalizers: new Map - }; - return scope2; -}; -var scopeMake = (strategy = sequential2) => sync(() => scopeUnsafeMake(strategy)); -var scopeExtend = /* @__PURE__ */ dual(2, (effect, scope2) => mapInputContext(effect, merge3(make6(scopeTag, scope2)))); -var scopeUse = /* @__PURE__ */ dual(2, (effect, scope2) => pipe(effect, scopeExtend(scope2), onExit((exit2) => scope2.close(exit2)))); -var fiberRefUnsafeMakeSupervisor = (initial) => fiberRefUnsafeMakePatch(initial, { - differ: differ2, - fork: empty24 -}); -var fiberRefLocallyScoped = /* @__PURE__ */ dual(2, (self, value) => asVoid(acquireRelease(flatMap7(fiberRefGet(self), (oldValue) => as(fiberRefSet(self, value), oldValue)), (oldValue) => fiberRefSet(self, oldValue)))); -var fiberRefLocallyScopedWith = /* @__PURE__ */ dual(2, (self, f) => fiberRefGetWith(self, (a) => fiberRefLocallyScoped(self, f(a)))); -var currentRuntimeFlags = /* @__PURE__ */ fiberRefUnsafeMakeRuntimeFlags(none5); -var currentSupervisor = /* @__PURE__ */ fiberRefUnsafeMakeSupervisor(none8); -var fiberAwaitAll = (fibers) => forEach6(fibers, _await); -var fiberAll = (fibers) => { - const _fiberAll = { - ...CommitPrototype2, - commit() { - return join2(this); - }, - [FiberTypeId]: fiberVariance2, - id: () => fromIterable(fibers).reduce((id, fiber) => combine3(id, fiber.id()), none4), - await: exit(forEachParUnbounded(fibers, (fiber) => flatten4(fiber.await), false)), - children: map9(forEachParUnbounded(fibers, (fiber) => fiber.children, false), flatten), - inheritAll: forEachSequentialDiscard(fibers, (fiber) => fiber.inheritAll), - poll: map9(forEachSequential(fibers, (fiber) => fiber.poll), reduceRight(some2(exitSucceed(new Array)), (optionB, optionA) => { - switch (optionA._tag) { - case "None": { - return none2(); - } - case "Some": { - switch (optionB._tag) { - case "None": { - return none2(); - } - case "Some": { - return some2(exitZipWith(optionA.value, optionB.value, { - onSuccess: (a, chunk2) => [a, ...chunk2], - onFailure: parallel - })); - } - } - } - } - })), - interruptAsFork: (fiberId2) => forEachSequentialDiscard(fibers, (fiber) => fiber.interruptAsFork(fiberId2)) - }; - return _fiberAll; -}; -var raceWith = /* @__PURE__ */ dual(3, (self, other, options) => raceFibersWith(self, other, { - onSelfWin: (winner, loser) => flatMap7(winner.await, (exit2) => { - switch (exit2._tag) { - case OP_SUCCESS: { - return flatMap7(winner.inheritAll, () => options.onSelfDone(exit2, loser)); - } - case OP_FAILURE: { - return options.onSelfDone(exit2, loser); - } - } - }), - onOtherWin: (winner, loser) => flatMap7(winner.await, (exit2) => { - switch (exit2._tag) { - case OP_SUCCESS: { - return flatMap7(winner.inheritAll, () => options.onOtherDone(exit2, loser)); - } - case OP_FAILURE: { - return options.onOtherDone(exit2, loser); - } - } - }) -})); -var disconnect = (self) => uninterruptibleMask((restore) => fiberIdWith((fiberId2) => flatMap7(forkDaemon(restore(self)), (fiber) => pipe(restore(join2(fiber)), onInterrupt(() => pipe(fiber, interruptAsFork(fiberId2))))))); -var race = /* @__PURE__ */ dual(2, (self, that) => fiberIdWith((parentFiberId) => raceWith(self, that, { - onSelfDone: (exit2, right3) => exitMatchEffect(exit2, { - onFailure: (cause2) => pipe(join2(right3), mapErrorCause((cause22) => parallel(cause2, cause22))), - onSuccess: (value) => pipe(right3, interruptAsFiber(parentFiberId), as(value)) - }), - onOtherDone: (exit2, left3) => exitMatchEffect(exit2, { - onFailure: (cause2) => pipe(join2(left3), mapErrorCause((cause22) => parallel(cause22, cause2))), - onSuccess: (value) => pipe(left3, interruptAsFiber(parentFiberId), as(value)) - }) -}))); -var raceFibersWith = /* @__PURE__ */ dual(3, (self, other, options) => withFiberRuntime((parentFiber, parentStatus) => { - const parentRuntimeFlags = parentStatus.runtimeFlags; - const raceIndicator = make11(true); - const leftFiber = unsafeMakeChildFiber(self, parentFiber, parentRuntimeFlags, options.selfScope); - const rightFiber = unsafeMakeChildFiber(other, parentFiber, parentRuntimeFlags, options.otherScope); - return async_((cb) => { - leftFiber.addObserver(() => completeRace(leftFiber, rightFiber, options.onSelfWin, raceIndicator, cb)); - rightFiber.addObserver(() => completeRace(rightFiber, leftFiber, options.onOtherWin, raceIndicator, cb)); - leftFiber.startFork(self); - rightFiber.startFork(other); - }, combine3(leftFiber.id(), rightFiber.id())); -})); -var completeRace = (winner, loser, cont, ab, cb) => { - if (compareAndSet(true, false)(ab)) { - cb(cont(winner, loser)); - } -}; -var ensuring = /* @__PURE__ */ dual(2, (self, finalizer) => uninterruptibleMask((restore) => matchCauseEffect(restore(self), { - onFailure: (cause1) => matchCauseEffect(finalizer, { - onFailure: (cause2) => failCause(sequential(cause1, cause2)), - onSuccess: () => failCause(cause1) - }), - onSuccess: (a) => as(finalizer, a) -}))); -var invokeWithInterrupt = (self, entries2, onInterrupt2) => fiberIdWith((id) => ensuring(flatMap7(forkDaemon(interruptible2(self)), (processing) => async_((cb) => { - const counts = entries2.map((_) => _.listeners.count); - const checkDone = () => { - if (counts.every((count) => count === 0)) { - if (entries2.every((_) => { - if (_.result.state.current._tag === "Pending") { - return true; - } else if (_.result.state.current._tag === "Done" && exitIsExit(_.result.state.current.effect) && _.result.state.current.effect._tag === "Failure" && isInterrupted(_.result.state.current.effect.cause)) { - return true; - } else { - return false; - } - })) { - cleanup.forEach((f) => f()); - onInterrupt2?.(); - cb(interruptFiber(processing)); - } - } - }; - processing.addObserver((exit2) => { - cleanup.forEach((f) => f()); - cb(exit2); - }); - const cleanup = entries2.map((r, i) => { - const observer = (count) => { - counts[i] = count; - checkDone(); - }; - r.listeners.addObserver(observer); - return () => r.listeners.removeObserver(observer); - }); - checkDone(); - return sync(() => { - cleanup.forEach((f) => f()); - }); -})), suspend(() => { - const residual = entries2.flatMap((entry) => { - if (!entry.state.completed) { - return [entry]; - } - return []; - }); - return forEachSequentialDiscard(residual, (entry) => complete(entry.request, exitInterrupt(id))); -}))); -var makeSpanScoped = (name, options) => { - options = addSpanStackTrace(options); - return uninterruptible(withFiberRuntime((fiber) => { - const scope2 = unsafeGet4(fiber.getFiberRef(currentContext), scopeTag); - const span2 = unsafeMakeSpan(fiber, name, options); - const timingEnabled = fiber.getFiberRef(currentTracerTimingEnabled); - const clock_ = get4(fiber.getFiberRef(currentServices), clockTag); - return as(scopeAddFinalizerExit(scope2, (exit2) => endSpan(span2, exit2, clock_, timingEnabled)), span2); - })); -}; -var withTracerScoped = (value) => fiberRefLocallyScopedWith(currentServices, add2(tracerTag, value)); -var withSpanScoped = function() { - const dataFirst = typeof arguments[0] !== "string"; - const name = dataFirst ? arguments[1] : arguments[0]; - const options = addSpanStackTrace(dataFirst ? arguments[2] : arguments[1]); - if (dataFirst) { - const self = arguments[0]; - return flatMap7(makeSpanScoped(name, addSpanStackTrace(options)), (span2) => provideService(self, spanTag, span2)); - } - return (self) => flatMap7(makeSpanScoped(name, addSpanStackTrace(options)), (span2) => provideService(self, spanTag, span2)); -}; - -// node_modules/effect/dist/esm/Cause.js -var empty25 = empty16; -var fail3 = fail; -var die3 = die; -var interrupt3 = interrupt; -var parallel4 = parallel; -var sequential4 = sequential; -var isCause2 = isCause; -var isFailType2 = isFailType; -var IllegalArgumentException2 = IllegalArgumentException; -var pretty2 = pretty; - -// node_modules/effect/dist/esm/internal/schedule/interval.js -var IntervalSymbolKey = "effect/ScheduleInterval"; -var IntervalTypeId = /* @__PURE__ */ Symbol.for(IntervalSymbolKey); -var empty26 = { - [IntervalTypeId]: IntervalTypeId, - startMillis: 0, - endMillis: 0 -}; -var make33 = (startMillis, endMillis) => { - if (startMillis > endMillis) { - return empty26; - } - return { - [IntervalTypeId]: IntervalTypeId, - startMillis, - endMillis - }; -}; -var lessThan3 = /* @__PURE__ */ dual(2, (self, that) => min2(self, that) === self); -var min2 = /* @__PURE__ */ dual(2, (self, that) => { - if (self.endMillis <= that.startMillis) - return self; - if (that.endMillis <= self.startMillis) - return that; - if (self.startMillis < that.startMillis) - return self; - if (that.startMillis < self.startMillis) - return that; - if (self.endMillis <= that.endMillis) - return self; - return that; -}); -var isEmpty6 = (self) => { - return self.startMillis >= self.endMillis; -}; -var intersect = /* @__PURE__ */ dual(2, (self, that) => { - const start = Math.max(self.startMillis, that.startMillis); - const end = Math.min(self.endMillis, that.endMillis); - return make33(start, end); -}); -var after = (startMilliseconds) => { - return make33(startMilliseconds, Number.POSITIVE_INFINITY); -}; - -// node_modules/effect/dist/esm/ScheduleInterval.js -var empty27 = empty26; -var lessThan4 = lessThan3; -var isEmpty7 = isEmpty6; -var intersect2 = intersect; -var after2 = after; - -// node_modules/effect/dist/esm/internal/schedule/intervals.js -var IntervalsSymbolKey = "effect/ScheduleIntervals"; -var IntervalsTypeId = /* @__PURE__ */ Symbol.for(IntervalsSymbolKey); -var make35 = (intervals) => { - return { - [IntervalsTypeId]: IntervalsTypeId, - intervals - }; -}; -var intersect3 = /* @__PURE__ */ dual(2, (self, that) => intersectLoop(self.intervals, that.intervals, empty2())); -var intersectLoop = (_left, _right, _acc) => { - let left3 = _left; - let right3 = _right; - let acc = _acc; - while (isNonEmpty(left3) && isNonEmpty(right3)) { - const interval = pipe(headNonEmpty2(left3), intersect2(headNonEmpty2(right3))); - const intervals = isEmpty7(interval) ? acc : pipe(acc, prepend2(interval)); - if (pipe(headNonEmpty2(left3), lessThan4(headNonEmpty2(right3)))) { - left3 = tailNonEmpty2(left3); - } else { - right3 = tailNonEmpty2(right3); - } - acc = intervals; - } - return make35(reverse2(acc)); -}; -var start = (self) => { - return pipe(self.intervals, head2, getOrElse(() => empty27)).startMillis; -}; -var end = (self) => { - return pipe(self.intervals, head2, getOrElse(() => empty27)).endMillis; -}; -var lessThan5 = /* @__PURE__ */ dual(2, (self, that) => start(self) < start(that)); -var isNonEmpty3 = (self) => { - return isNonEmpty(self.intervals); -}; - -// node_modules/effect/dist/esm/ScheduleIntervals.js -var make36 = make35; -var intersect4 = intersect3; -var start2 = start; -var end2 = end; -var lessThan6 = lessThan5; -var isNonEmpty4 = isNonEmpty3; - -// node_modules/effect/dist/esm/internal/schedule/decision.js -var OP_CONTINUE = "Continue"; -var OP_DONE2 = "Done"; -var _continue = (intervals) => { - return { - _tag: OP_CONTINUE, - intervals - }; -}; -var continueWith = (interval) => { - return { - _tag: OP_CONTINUE, - intervals: make36(of2(interval)) - }; -}; -var done4 = { - _tag: OP_DONE2 -}; -var isContinue = (self) => { - return self._tag === OP_CONTINUE; -}; -var isDone3 = (self) => { - return self._tag === OP_DONE2; -}; - -// node_modules/effect/dist/esm/ScheduleDecision.js -var _continue2 = _continue; -var continueWith2 = continueWith; -var done5 = done4; -var isContinue2 = isContinue; -var isDone4 = isDone3; - -// node_modules/effect/dist/esm/Scope.js -var close = scopeClose; -var fork2 = scopeFork; - -// node_modules/effect/dist/esm/internal/effect/circular.js -class Semaphore { - permits; - waiters = /* @__PURE__ */ new Set; - taken = 0; - constructor(permits) { - this.permits = permits; - } - get free() { - return this.permits - this.taken; - } - take = (n) => asyncInterrupt((resume2) => { - if (this.free < n) { - const observer = () => { - if (this.free < n) - return; - this.waiters.delete(observer); - resume2(suspend(() => { - if (this.free < n) - return this.take(n); - this.taken += n; - return succeed(n); - })); - }; - this.waiters.add(observer); - return sync(() => { - this.waiters.delete(observer); - }); - } - resume2(suspend(() => { - if (this.free < n) - return this.take(n); - this.taken += n; - return succeed(n); - })); - }); - updateTakenUnsafe(fiber, f) { - this.taken = f(this.taken); - if (this.waiters.size > 0) { - fiber.getFiberRef(currentScheduler).scheduleTask(() => { - const iter = this.waiters.values(); - let item = iter.next(); - while (item.done === false && this.free > 0) { - item.value(); - item = iter.next(); - } - }, fiber.getFiberRef(currentSchedulingPriority), fiber); - } - return succeed(this.free); - } - updateTaken(f) { - return withFiberRuntime((fiber) => this.updateTakenUnsafe(fiber, f)); - } - resize = (permits) => asVoid(withFiberRuntime((fiber) => { - this.permits = permits; - if (this.free < 0) { - return void_; - } - return this.updateTakenUnsafe(fiber, (taken) => taken); - })); - release = (n) => this.updateTaken((taken) => taken - n); - releaseAll = /* @__PURE__ */ this.updateTaken((_) => 0); - withPermits = (n) => (self) => uninterruptibleMask((restore) => flatMap7(restore(this.take(n)), (permits) => ensuring(restore(self), this.release(permits)))); - withPermitsIfAvailable = (n) => (self) => uninterruptibleMask((restore) => suspend(() => { - if (this.free < n) { - return succeedNone; - } - this.taken += n; - return ensuring(restore(asSome(self)), this.release(n)); - })); -} -var unsafeMakeSemaphore = (permits) => new Semaphore(permits); -var makeSemaphore = (permits) => sync(() => unsafeMakeSemaphore(permits)); - -class Latch extends Class2 { - isOpen; - waiters = []; - scheduled = false; - constructor(isOpen) { - super(); - this.isOpen = isOpen; - } - commit() { - return this.await; - } - unsafeSchedule(fiber) { - if (this.scheduled || this.waiters.length === 0) { - return void_; - } - this.scheduled = true; - fiber.currentScheduler.scheduleTask(this.flushWaiters, fiber.getFiberRef(currentSchedulingPriority), fiber); - return void_; - } - flushWaiters = () => { - this.scheduled = false; - const waiters = this.waiters; - this.waiters = []; - for (let i = 0;i < waiters.length; i++) { - waiters[i](exitVoid); - } - }; - open = /* @__PURE__ */ withFiberRuntime((fiber) => { - if (this.isOpen) { - return void_; - } - this.isOpen = true; - return this.unsafeSchedule(fiber); - }); - unsafeOpen() { - if (this.isOpen) - return; - this.isOpen = true; - this.flushWaiters(); - } - release = /* @__PURE__ */ withFiberRuntime((fiber) => { - if (this.isOpen) { - return void_; - } - return this.unsafeSchedule(fiber); - }); - await = /* @__PURE__ */ asyncInterrupt((resume2) => { - if (this.isOpen) { - return resume2(void_); - } - this.waiters.push(resume2); - return sync(() => { - const index = this.waiters.indexOf(resume2); - if (index !== -1) { - this.waiters.splice(index, 1); - } - }); - }); - unsafeClose() { - this.isOpen = false; - } - close = /* @__PURE__ */ sync(() => { - this.isOpen = false; - }); - whenOpen = (self) => { - return zipRight(this.await, self); - }; -} -var unsafeMakeLatch = (open) => new Latch(open ?? false); -var makeLatch = (open) => sync(() => unsafeMakeLatch(open)); -var awaitAllChildren = (self) => ensuringChildren(self, fiberAwaitAll); -var cached2 = /* @__PURE__ */ dual(2, (self, timeToLive) => map9(cachedInvalidateWithTTL(self, timeToLive), (tuple2) => tuple2[0])); -var cachedInvalidateWithTTL = /* @__PURE__ */ dual(2, (self, timeToLive) => { - const duration = decode(timeToLive); - return flatMap7(context(), (env) => map9(makeSynchronized(none2()), (cache) => [provideContext(getCachedValue(self, duration, cache), env), invalidateCache(cache)])); -}); -var computeCachedValue = (self, timeToLive, start3) => { - const timeToLiveMillis = toMillis(decode(timeToLive)); - return pipe(deferredMake(), tap((deferred) => intoDeferred(self, deferred)), map9((deferred) => some2([start3 + timeToLiveMillis, deferred]))); -}; -var getCachedValue = (self, timeToLive, cache) => uninterruptibleMask((restore) => pipe(clockWith3((clock2) => clock2.currentTimeMillis), flatMap7((time) => updateSomeAndGetEffectSynchronized(cache, (option2) => { - switch (option2._tag) { - case "None": { - return some2(computeCachedValue(self, timeToLive, time)); - } - case "Some": { - const [end3] = option2.value; - return end3 - time <= 0 ? some2(computeCachedValue(self, timeToLive, time)) : none2(); - } - } -})), flatMap7((option2) => isNone2(option2) ? dieMessage("BUG: Effect.cachedInvalidate - please report an issue at https://github.com/Effect-TS/effect/issues") : restore(deferredAwait(option2.value[1]))))); -var invalidateCache = (cache) => set4(cache, none2()); -var ensuringChild = /* @__PURE__ */ dual(2, (self, f) => ensuringChildren(self, (children) => f(fiberAll(children)))); -var ensuringChildren = /* @__PURE__ */ dual(2, (self, children) => flatMap7(track, (supervisor) => pipe(supervised(self, supervisor), ensuring(flatMap7(supervisor.value, children))))); -var forkAll = /* @__PURE__ */ dual((args2) => isIterable(args2[0]), (effects, options) => options?.discard ? forEachSequentialDiscard(effects, fork) : map9(forEachSequential(effects, fork), fiberAll)); -var forkIn = /* @__PURE__ */ dual(2, (self, scope2) => withFiberRuntime((parent, parentStatus) => { - const scopeImpl = scope2; - const fiber = unsafeFork(self, parent, parentStatus.runtimeFlags, globalScope); - if (scopeImpl.state._tag === "Open") { - const finalizer = () => fiberIdWith((fiberId2) => equals(fiberId2, fiber.id()) ? void_ : asVoid(interruptFiber(fiber))); - const key = {}; - scopeImpl.state.finalizers.set(key, finalizer); - fiber.addObserver(() => { - if (scopeImpl.state._tag === "Closed") - return; - scopeImpl.state.finalizers.delete(key); - }); - } else { - fiber.unsafeInterruptAsFork(parent.id()); - } - return succeed(fiber); -})); -var forkScoped = (self) => scopeWith((scope2) => forkIn(self, scope2)); -var fromFiber = (fiber) => join2(fiber); -var fromFiberEffect = (fiber) => suspend(() => flatMap7(fiber, join2)); -var memoKeySymbol = /* @__PURE__ */ Symbol.for("effect/Effect/memoizeFunction.key"); - -class Key { - a; - eq; - [memoKeySymbol] = memoKeySymbol; - constructor(a, eq) { - this.a = a; - this.eq = eq; - } - [symbol2](that) { - if (hasProperty(that, memoKeySymbol)) { - if (this.eq) { - return this.eq(this.a, that.a); - } else { - return equals(this.a, that.a); - } - } - return false; - } - [symbol]() { - return this.eq ? 0 : cached(this, hash(this.a)); - } -} -var cachedFunction = (f, eq) => { - return pipe(sync(() => empty21()), flatMap7(makeSynchronized), map9((ref) => (a) => pipe(ref.modifyEffect((map10) => { - const result = pipe(map10, get12(new Key(a, eq))); - if (isNone2(result)) { - return pipe(deferredMake(), tap((deferred) => pipe(diffFiberRefs(f(a)), intoDeferred(deferred), fork)), map9((deferred) => [deferred, pipe(map10, set5(new Key(a, eq), deferred))])); - } - return succeed([result.value, map10]); - }), flatMap7(deferredAwait), flatMap7(([patch9, b]) => pipe(patchFiberRefs(patch9), as(b)))))); -}; -var raceFirst = /* @__PURE__ */ dual(2, (self, that) => pipe(exit(self), race(exit(that)), (effect) => flatten4(effect))); -var supervised = /* @__PURE__ */ dual(2, (self, supervisor) => { - const supervise = fiberRefLocallyWith(currentSupervisor, (s) => s.zip(supervisor)); - return supervise(self); -}); -var timeout = /* @__PURE__ */ dual(2, (self, duration) => timeoutFail(self, { - onTimeout: () => timeoutExceptionFromDuration(duration), - duration -})); -var timeoutFail = /* @__PURE__ */ dual(2, (self, { - duration, - onTimeout -}) => flatten4(timeoutTo(self, { - onTimeout: () => failSync(onTimeout), - onSuccess: succeed, - duration -}))); -var timeoutFailCause = /* @__PURE__ */ dual(2, (self, { - duration, - onTimeout -}) => flatten4(timeoutTo(self, { - onTimeout: () => failCauseSync(onTimeout), - onSuccess: succeed, - duration -}))); -var timeoutOption = /* @__PURE__ */ dual(2, (self, duration) => timeoutTo(self, { - duration, - onSuccess: some2, - onTimeout: none2 -})); -var timeoutTo = /* @__PURE__ */ dual(2, (self, { - duration, - onSuccess, - onTimeout -}) => fiberIdWith((parentFiberId) => uninterruptibleMask((restore) => raceFibersWith(restore(self), interruptible2(sleep3(duration)), { - onSelfWin: (winner, loser) => flatMap7(winner.await, (exit2) => { - if (exit2._tag === "Success") { - return flatMap7(winner.inheritAll, () => as(interruptAsFiber(loser, parentFiberId), onSuccess(exit2.value))); - } else { - return flatMap7(interruptAsFiber(loser, parentFiberId), () => exitFailCause(exit2.cause)); - } - }), - onOtherWin: (winner, loser) => flatMap7(winner.await, (exit2) => { - if (exit2._tag === "Success") { - return flatMap7(winner.inheritAll, () => as(interruptAsFiber(loser, parentFiberId), onTimeout())); - } else { - return flatMap7(interruptAsFiber(loser, parentFiberId), () => exitFailCause(exit2.cause)); - } - }), - otherScope: globalScope -})))); -var SynchronizedSymbolKey = "effect/Ref/SynchronizedRef"; -var SynchronizedTypeId = /* @__PURE__ */ Symbol.for(SynchronizedSymbolKey); -var synchronizedVariance = { - _A: (_) => _ -}; - -class SynchronizedImpl extends Class2 { - ref; - withLock; - [SynchronizedTypeId] = synchronizedVariance; - [RefTypeId] = refVariance; - [TypeId10] = TypeId10; - constructor(ref, withLock) { - super(); - this.ref = ref; - this.withLock = withLock; - this.get = get10(this.ref); - } - get; - commit() { - return this.get; - } - modify(f) { - return this.modifyEffect((a) => succeed(f(a))); - } - modifyEffect(f) { - return this.withLock(pipe(flatMap7(get10(this.ref), f), flatMap7(([b, a]) => as(set4(this.ref, a), b)))); - } -} -var makeSynchronized = (value) => sync(() => unsafeMakeSynchronized(value)); -var unsafeMakeSynchronized = (value) => { - const ref = unsafeMake4(value); - const sem = unsafeMakeSemaphore(1); - return new SynchronizedImpl(ref, sem.withPermits(1)); -}; -var updateSomeAndGetEffectSynchronized = /* @__PURE__ */ dual(2, (self, pf) => self.modifyEffect((value) => { - const result = pf(value); - switch (result._tag) { - case "None": { - return succeed([value, value]); - } - case "Some": { - return map9(result.value, (a) => [a, a]); - } - } -})); -var bindAll = /* @__PURE__ */ dual((args2) => isEffect(args2[0]), (self, f, options) => flatMap7(self, (a) => all2(f(a), options).pipe(map9((record) => Object.assign({}, a, record))))); - -// node_modules/effect/dist/esm/internal/managedRuntime/circular.js -var TypeId13 = /* @__PURE__ */ Symbol.for("effect/ManagedRuntime"); - -// node_modules/effect/dist/esm/internal/opCodes/layer.js -var OP_FRESH = "Fresh"; -var OP_FROM_EFFECT = "FromEffect"; -var OP_SCOPED = "Scoped"; -var OP_SUSPEND = "Suspend"; -var OP_PROVIDE = "Provide"; -var OP_PROVIDE_MERGE = "ProvideMerge"; -var OP_MERGE_ALL = "MergeAll"; - -// node_modules/effect/dist/esm/Fiber.js -var interruptAs = interruptAsFiber; - -// node_modules/effect/dist/esm/internal/runtime.js -var makeDual = (f) => function() { - if (arguments.length === 1) { - const runtime3 = arguments[0]; - return (effect, ...args2) => f(runtime3, effect, ...args2); - } - return f.apply(this, arguments); -}; -var unsafeFork2 = /* @__PURE__ */ makeDual((runtime3, self, options) => { - const fiberId2 = unsafeMake2(); - const fiberRefUpdates = [[currentContext, [[fiberId2, runtime3.context]]]]; - if (options?.scheduler) { - fiberRefUpdates.push([currentScheduler, [[fiberId2, options.scheduler]]]); - } - let fiberRefs3 = updateManyAs2(runtime3.fiberRefs, { - entries: fiberRefUpdates, - forkAs: fiberId2 - }); - if (options?.updateRefs) { - fiberRefs3 = options.updateRefs(fiberRefs3, fiberId2); - } - const fiberRuntime = new FiberRuntime(fiberId2, fiberRefs3, runtime3.runtimeFlags); - let effect = self; - if (options?.scope) { - effect = flatMap7(fork2(options.scope, sequential2), (closeableScope) => zipRight(scopeAddFinalizer(closeableScope, fiberIdWith((id) => equals(id, fiberRuntime.id()) ? void_ : interruptAsFiber(fiberRuntime, id))), onExit(self, (exit2) => close(closeableScope, exit2)))); - } - const supervisor = fiberRuntime.currentSupervisor; - if (supervisor !== none8) { - supervisor.onStart(runtime3.context, effect, none2(), fiberRuntime); - fiberRuntime.addObserver((exit2) => supervisor.onEnd(exit2, fiberRuntime)); - } - globalScope.add(runtime3.runtimeFlags, fiberRuntime); - if (options?.immediate === false) { - fiberRuntime.resume(effect); - } else { - fiberRuntime.start(effect); - } - return fiberRuntime; -}); -var unsafeRunCallback = /* @__PURE__ */ makeDual((runtime3, effect, options = {}) => { - const fiberRuntime = unsafeFork2(runtime3, effect, options); - if (options.onExit) { - fiberRuntime.addObserver((exit2) => { - options.onExit(exit2); - }); - } - return (id, cancelOptions) => unsafeRunCallback(runtime3)(pipe(fiberRuntime, interruptAs(id ?? none4)), { - ...cancelOptions, - onExit: cancelOptions?.onExit ? (exit2) => cancelOptions.onExit(flatten5(exit2)) : undefined - }); -}); -var unsafeRunSync = /* @__PURE__ */ makeDual((runtime3, effect) => { - const result = unsafeRunSyncExit(runtime3)(effect); - if (result._tag === "Failure") { - throw fiberFailure(result.effect_instruction_i0); - } - return result.effect_instruction_i0; -}); - -class AsyncFiberExceptionImpl extends Error { - fiber; - _tag = "AsyncFiberException"; - constructor(fiber) { - super(`Fiber #${fiber.id().id} cannot be resolved synchronously. This is caused by using runSync on an effect that performs async work`); - this.fiber = fiber; - this.name = this._tag; - this.stack = this.message; - } -} -var asyncFiberException = (fiber) => { - const limit = Error.stackTraceLimit; - Error.stackTraceLimit = 0; - const error = new AsyncFiberExceptionImpl(fiber); - Error.stackTraceLimit = limit; - return error; -}; -var FiberFailureId = /* @__PURE__ */ Symbol.for("effect/Runtime/FiberFailure"); -var FiberFailureCauseId = /* @__PURE__ */ Symbol.for("effect/Runtime/FiberFailure/Cause"); - -class FiberFailureImpl extends Error { - [FiberFailureId]; - [FiberFailureCauseId]; - constructor(cause2) { - const head4 = prettyErrors(cause2)[0]; - super(head4?.message || "An error has occurred"); - this[FiberFailureId] = FiberFailureId; - this[FiberFailureCauseId] = cause2; - this.name = head4 ? `(FiberFailure) ${head4.name}` : "FiberFailure"; - if (head4?.stack) { - this.stack = head4.stack; - } - } - toJSON() { - return { - _id: "FiberFailure", - cause: this[FiberFailureCauseId].toJSON() - }; - } - toString() { - return "(FiberFailure) " + pretty(this[FiberFailureCauseId], { - renderErrorCause: true - }); - } - [NodeInspectSymbol]() { - return this.toString(); - } -} -var fiberFailure = (cause2) => { - const limit = Error.stackTraceLimit; - Error.stackTraceLimit = 0; - const error = new FiberFailureImpl(cause2); - Error.stackTraceLimit = limit; - return error; -}; -var fastPath = (effect) => { - const op = effect; - switch (op._op) { - case "Failure": - case "Success": { - return op; - } - case "Left": { - return exitFail(op.left); - } - case "Right": { - return exitSucceed(op.right); - } - case "Some": { - return exitSucceed(op.value); - } - case "None": { - return exitFail(new NoSuchElementException); - } - } -}; -var unsafeRunSyncExit = /* @__PURE__ */ makeDual((runtime3, effect) => { - const op = fastPath(effect); - if (op) { - return op; - } - const scheduler = new SyncScheduler; - const fiberRuntime = unsafeFork2(runtime3)(effect, { - scheduler - }); - scheduler.flush(); - const result = fiberRuntime.unsafePoll(); - if (result) { - return result; - } - return exitDie(capture(asyncFiberException(fiberRuntime), currentSpanFromFiber(fiberRuntime))); -}); -var unsafeRunPromise = /* @__PURE__ */ makeDual((runtime3, effect, options) => unsafeRunPromiseExit(runtime3, effect, options).then((result) => { - switch (result._tag) { - case OP_SUCCESS: { - return result.effect_instruction_i0; - } - case OP_FAILURE: { - throw fiberFailure(result.effect_instruction_i0); - } - } -})); -var unsafeRunPromiseExit = /* @__PURE__ */ makeDual((runtime3, effect, options) => new Promise((resolve) => { - const op = fastPath(effect); - if (op) { - resolve(op); - } - const fiber = unsafeFork2(runtime3)(effect); - fiber.addObserver((exit2) => { - resolve(exit2); - }); - if (options?.signal !== undefined) { - if (options.signal.aborted) { - fiber.unsafeInterruptAsFork(fiber.id()); - } else { - options.signal.addEventListener("abort", () => { - fiber.unsafeInterruptAsFork(fiber.id()); - }, { - once: true - }); - } - } -})); - -class RuntimeImpl { - context; - runtimeFlags; - fiberRefs; - constructor(context2, runtimeFlags2, fiberRefs3) { - this.context = context2; - this.runtimeFlags = runtimeFlags2; - this.fiberRefs = fiberRefs3; - } - pipe() { - return pipeArguments(this, arguments); - } -} -var make37 = (options) => new RuntimeImpl(options.context, options.runtimeFlags, options.fiberRefs); -var runtime3 = () => withFiberRuntime((state, status) => succeed(new RuntimeImpl(state.getFiberRef(currentContext), status.runtimeFlags, state.getFiberRefs()))); -var defaultRuntimeFlags = /* @__PURE__ */ make16(Interruption, CooperativeYielding, RuntimeMetrics); -var defaultRuntime = /* @__PURE__ */ make37({ - context: /* @__PURE__ */ empty4(), - runtimeFlags: defaultRuntimeFlags, - fiberRefs: /* @__PURE__ */ empty19() -}); -var unsafeRunEffect = /* @__PURE__ */ unsafeRunCallback(defaultRuntime); -var unsafeForkEffect = /* @__PURE__ */ unsafeFork2(defaultRuntime); -var unsafeRunPromiseEffect = /* @__PURE__ */ unsafeRunPromise(defaultRuntime); -var unsafeRunPromiseExitEffect = /* @__PURE__ */ unsafeRunPromiseExit(defaultRuntime); -var unsafeRunSyncEffect = /* @__PURE__ */ unsafeRunSync(defaultRuntime); -var unsafeRunSyncExitEffect = /* @__PURE__ */ unsafeRunSyncExit(defaultRuntime); -var asyncEffect = (register) => suspend(() => { - let cleanup = undefined; - return flatMap7(deferredMake(), (deferred) => flatMap7(runtime3(), (runtime4) => uninterruptibleMask((restore) => zipRight(fork(restore(matchCauseEffect(register((cb) => unsafeRunCallback(runtime4)(intoDeferred(cb, deferred))), { - onFailure: (cause2) => deferredFailCause(deferred, cause2), - onSuccess: (cleanup_) => { - cleanup = cleanup_; - return void_; - } - }))), restore(onInterrupt(deferredAwait(deferred), () => cleanup ?? void_)))))); -}); - -// node_modules/effect/dist/esm/internal/synchronizedRef.js -var modifyEffect = /* @__PURE__ */ dual(2, (self, f) => self.modifyEffect(f)); - -// node_modules/effect/dist/esm/internal/layer.js -var LayerSymbolKey = "effect/Layer"; -var LayerTypeId = /* @__PURE__ */ Symbol.for(LayerSymbolKey); -var layerVariance = { - _RIn: (_) => _, - _E: (_) => _, - _ROut: (_) => _ -}; -var proto3 = { - [LayerTypeId]: layerVariance, - pipe() { - return pipeArguments(this, arguments); - } -}; -var MemoMapTypeIdKey = "effect/Layer/MemoMap"; -var MemoMapTypeId = /* @__PURE__ */ Symbol.for(MemoMapTypeIdKey); -var CurrentMemoMap = /* @__PURE__ */ Reference2()("effect/Layer/CurrentMemoMap", { - defaultValue: () => unsafeMakeMemoMap() -}); -var isLayer = (u) => hasProperty(u, LayerTypeId); -var isFresh = (self) => { - return self._op_layer === OP_FRESH; -}; - -class MemoMapImpl { - ref; - [MemoMapTypeId]; - constructor(ref) { - this.ref = ref; - this[MemoMapTypeId] = MemoMapTypeId; - } - getOrElseMemoize(layer, scope2) { - return pipe(modifyEffect(this.ref, (map10) => { - const inMap = map10.get(layer); - if (inMap !== undefined) { - const [acquire, release] = inMap; - const cached3 = pipe(acquire, flatMap7(([patch9, b]) => pipe(patchFiberRefs(patch9), as(b))), onExit(exitMatch({ - onFailure: () => void_, - onSuccess: () => scopeAddFinalizerExit(scope2, release) - }))); - return succeed([cached3, map10]); - } - return pipe(make23(0), flatMap7((observers) => pipe(deferredMake(), flatMap7((deferred) => pipe(make23(() => void_), map9((finalizerRef) => { - const resource = uninterruptibleMask((restore) => pipe(scopeMake(), flatMap7((innerScope) => pipe(restore(flatMap7(makeBuilder(layer, innerScope, true), (f) => diffFiberRefs(f(this)))), exit, flatMap7((exit2) => { - switch (exit2._tag) { - case OP_FAILURE: { - return pipe(deferredFailCause(deferred, exit2.effect_instruction_i0), zipRight(scopeClose(innerScope, exit2)), zipRight(failCause(exit2.effect_instruction_i0))); - } - case OP_SUCCESS: { - return pipe(set4(finalizerRef, (exit3) => pipe(scopeClose(innerScope, exit3), whenEffect(modify3(observers, (n) => [n === 1, n - 1])), asVoid)), zipRight(update2(observers, (n) => n + 1)), zipRight(scopeAddFinalizerExit(scope2, (exit3) => pipe(sync(() => map10.delete(layer)), zipRight(get10(finalizerRef)), flatMap7((finalizer) => finalizer(exit3))))), zipRight(deferredSucceed(deferred, exit2.effect_instruction_i0)), as(exit2.effect_instruction_i0[1])); - } - } - }))))); - const memoized = [pipe(deferredAwait(deferred), onExit(exitMatchEffect({ - onFailure: () => void_, - onSuccess: () => update2(observers, (n) => n + 1) - }))), (exit2) => pipe(get10(finalizerRef), flatMap7((finalizer) => finalizer(exit2)))]; - return [resource, isFresh(layer) ? map10 : map10.set(layer, memoized)]; - })))))); - }), flatten4); - } -} -var makeMemoMap = /* @__PURE__ */ suspend(() => map9(makeSynchronized(new Map), (ref) => new MemoMapImpl(ref))); -var unsafeMakeMemoMap = () => new MemoMapImpl(unsafeMakeSynchronized(new Map)); -var buildWithScope = /* @__PURE__ */ dual(2, (self, scope2) => flatMap7(makeMemoMap, (memoMap) => buildWithMemoMap(self, memoMap, scope2))); -var buildWithMemoMap = /* @__PURE__ */ dual(3, (self, memoMap, scope2) => flatMap7(makeBuilder(self, scope2), (run) => provideService(run(memoMap), CurrentMemoMap, memoMap))); -var makeBuilder = (self, scope2, inMemoMap = false) => { - const op = self; - switch (op._op_layer) { - case "Locally": { - return sync(() => (memoMap) => op.f(memoMap.getOrElseMemoize(op.self, scope2))); - } - case "ExtendScope": { - return sync(() => (memoMap) => scopeWith((scope3) => memoMap.getOrElseMemoize(op.layer, scope3))); - } - case "Fold": { - return sync(() => (memoMap) => pipe(memoMap.getOrElseMemoize(op.layer, scope2), matchCauseEffect({ - onFailure: (cause2) => memoMap.getOrElseMemoize(op.failureK(cause2), scope2), - onSuccess: (value) => memoMap.getOrElseMemoize(op.successK(value), scope2) - }))); - } - case "Fresh": { - return sync(() => (_) => pipe(op.layer, buildWithScope(scope2))); - } - case "FromEffect": { - return inMemoMap ? sync(() => (_) => op.effect) : sync(() => (memoMap) => memoMap.getOrElseMemoize(self, scope2)); - } - case "Provide": { - return sync(() => (memoMap) => pipe(memoMap.getOrElseMemoize(op.first, scope2), flatMap7((env) => pipe(memoMap.getOrElseMemoize(op.second, scope2), provideContext(env))))); - } - case "Scoped": { - return inMemoMap ? sync(() => (_) => scopeExtend(op.effect, scope2)) : sync(() => (memoMap) => memoMap.getOrElseMemoize(self, scope2)); - } - case "Suspend": { - return sync(() => (memoMap) => memoMap.getOrElseMemoize(op.evaluate(), scope2)); - } - case "ProvideMerge": { - return sync(() => (memoMap) => pipe(memoMap.getOrElseMemoize(op.first, scope2), zipWith2(memoMap.getOrElseMemoize(op.second, scope2), op.zipK))); - } - case "ZipWith": { - return gen(function* () { - const parallelScope = yield* scopeFork(scope2, parallel2); - const firstScope = yield* scopeFork(parallelScope, sequential2); - const secondScope = yield* scopeFork(parallelScope, sequential2); - return (memoMap) => pipe(memoMap.getOrElseMemoize(op.first, firstScope), zipWithOptions(memoMap.getOrElseMemoize(op.second, secondScope), op.zipK, { - concurrent: true - })); - }); - } - case "MergeAll": { - const layers = op.layers; - return map9(scopeFork(scope2, parallel2), (parallelScope) => (memoMap) => { - const contexts = new Array(layers.length); - return map9(forEachConcurrentDiscard(layers, fnUntraced(function* (layer, i) { - const scope3 = yield* scopeFork(parallelScope, sequential2); - const context2 = yield* memoMap.getOrElseMemoize(layer, scope3); - contexts[i] = context2; - }), false, false), () => mergeAll2(...contexts)); - }); - } - } -}; -var context2 = () => fromEffectContext(context()); -var fromEffect2 = /* @__PURE__ */ dual(2, (a, b) => { - const tagFirst = isTag2(a); - const tag = tagFirst ? a : b; - const effect = tagFirst ? b : a; - return fromEffectContext(map9(effect, (service) => make6(tag, service))); -}); -function fromEffectContext(effect) { - const fromEffect3 = Object.create(proto3); - fromEffect3._op_layer = OP_FROM_EFFECT; - fromEffect3.effect = effect; - return fromEffect3; -} -var mergeAll4 = (...layers) => { - const mergeAll5 = Object.create(proto3); - mergeAll5._op_layer = OP_MERGE_ALL; - mergeAll5.layers = layers; - return mergeAll5; -}; -var scoped = /* @__PURE__ */ dual(2, (a, b) => { - const tagFirst = isTag2(a); - const tag = tagFirst ? a : b; - const effect = tagFirst ? b : a; - return scopedContext(map9(effect, (service) => make6(tag, service))); -}); -var scopedContext = (effect) => { - const scoped2 = Object.create(proto3); - scoped2._op_layer = OP_SCOPED; - scoped2.effect = effect; - return scoped2; -}; -var succeed4 = /* @__PURE__ */ dual(2, (a, b) => { - const tagFirst = isTag2(a); - const tag = tagFirst ? a : b; - const resource = tagFirst ? b : a; - return fromEffectContext(succeed(make6(tag, resource))); -}); -var suspend2 = (evaluate2) => { - const suspend3 = Object.create(proto3); - suspend3._op_layer = OP_SUSPEND; - suspend3.evaluate = evaluate2; - return suspend3; -}; -var sync2 = /* @__PURE__ */ dual(2, (a, b) => { - const tagFirst = isTag2(a); - const tag = tagFirst ? a : b; - const evaluate2 = tagFirst ? b : a; - return fromEffectContext(sync(() => make6(tag, evaluate2()))); -}); -var provide = /* @__PURE__ */ dual(2, (self, that) => suspend2(() => { - const provideTo = Object.create(proto3); - provideTo._op_layer = OP_PROVIDE; - provideTo.first = Object.create(proto3, { - _op_layer: { - value: OP_PROVIDE_MERGE, - enumerable: true - }, - first: { - value: context2(), - enumerable: true - }, - second: { - value: Array.isArray(that) ? mergeAll4(...that) : that - }, - zipK: { - value: (a, b) => pipe(a, merge3(b)) - } - }); - provideTo.second = self; - return provideTo; -})); -var provideSomeLayer = /* @__PURE__ */ dual(2, (self, layer) => scopedWith((scope2) => flatMap7(buildWithScope(layer, scope2), (context3) => provideSomeContext(self, context3)))); -var provideSomeRuntime = /* @__PURE__ */ dual(2, (self, rt) => { - const patchRefs = diff6(defaultRuntime.fiberRefs, rt.fiberRefs); - const patchFlags = diff4(defaultRuntime.runtimeFlags, rt.runtimeFlags); - return uninterruptibleMask((restore) => withFiberRuntime((fiber) => { - const oldContext = fiber.getFiberRef(currentContext); - const oldRefs = fiber.getFiberRefs(); - const newRefs = patch7(fiber.id(), oldRefs)(patchRefs); - const oldFlags = fiber.currentRuntimeFlags; - const newFlags = patch4(patchFlags)(oldFlags); - const rollbackRefs = diff6(newRefs, oldRefs); - const rollbackFlags = diff4(newFlags, oldFlags); - fiber.setFiberRefs(newRefs); - fiber.currentRuntimeFlags = newFlags; - return ensuring(provideSomeContext(restore(self), merge3(oldContext, rt.context)), withFiberRuntime((fiber2) => { - fiber2.setFiberRefs(patch7(fiber2.id(), fiber2.getFiberRefs())(rollbackRefs)); - fiber2.currentRuntimeFlags = patch4(rollbackFlags)(fiber2.currentRuntimeFlags); - return void_; - })); - })); -}); -var effect_provide = /* @__PURE__ */ dual(2, (self, source) => { - if (Array.isArray(source)) { - return provideSomeLayer(self, mergeAll4(...source)); - } else if (isLayer(source)) { - return provideSomeLayer(self, source); - } else if (isContext2(source)) { - return provideSomeContext(self, source); - } else if (TypeId13 in source) { - return flatMap7(source.runtimeEffect, (rt) => provideSomeRuntime(self, rt)); - } else { - return provideSomeRuntime(self, source); - } -}); - -// node_modules/effect/dist/esm/internal/console.js -var console2 = /* @__PURE__ */ map9(/* @__PURE__ */ fiberRefGet(currentServices), /* @__PURE__ */ get4(consoleTag)); -var consoleWith = (f) => fiberRefGetWith(currentServices, (services) => f(get4(services, consoleTag))); -var withConsole = /* @__PURE__ */ dual(2, (effect, value) => fiberRefLocallyWith(effect, currentServices, add2(consoleTag, value))); -var withConsoleScoped = (console3) => fiberRefLocallyScopedWith(currentServices, add2(consoleTag, console3)); - -// node_modules/effect/dist/esm/internal/dateTime.js -var TypeId14 = /* @__PURE__ */ Symbol.for("effect/DateTime"); -var TimeZoneTypeId = /* @__PURE__ */ Symbol.for("effect/DateTime/TimeZone"); -var Proto2 = { - [TypeId14]: TypeId14, - pipe() { - return pipeArguments(this, arguments); - }, - [NodeInspectSymbol]() { - return this.toString(); - }, - toJSON() { - return toDateUtc(this).toJSON(); - } -}; -var ProtoUtc = { - ...Proto2, - _tag: "Utc", - [symbol]() { - return cached(this, number2(this.epochMillis)); - }, - [symbol2](that) { - return isDateTime(that) && that._tag === "Utc" && this.epochMillis === that.epochMillis; - }, - toString() { - return `DateTime.Utc(${toDateUtc(this).toJSON()})`; - } -}; -var ProtoZoned = { - ...Proto2, - _tag: "Zoned", - [symbol]() { - return pipe(number2(this.epochMillis), combine(hash(this.zone)), cached(this)); - }, - [symbol2](that) { - return isDateTime(that) && that._tag === "Zoned" && this.epochMillis === that.epochMillis && equals(this.zone, that.zone); - }, - toString() { - return `DateTime.Zoned(${formatIsoZoned(this)})`; - } -}; -var ProtoTimeZone = { - [TimeZoneTypeId]: TimeZoneTypeId, - [NodeInspectSymbol]() { - return this.toString(); - } -}; -var ProtoTimeZoneNamed = { - ...ProtoTimeZone, - _tag: "Named", - [symbol]() { - return cached(this, string(`Named:${this.id}`)); - }, - [symbol2](that) { - return isTimeZone(that) && that._tag === "Named" && this.id === that.id; - }, - toString() { - return `TimeZone.Named(${this.id})`; - }, - toJSON() { - return { - _id: "TimeZone", - _tag: "Named", - id: this.id - }; - } -}; -var ProtoTimeZoneOffset = { - ...ProtoTimeZone, - _tag: "Offset", - [symbol]() { - return cached(this, string(`Offset:${this.offset}`)); - }, - [symbol2](that) { - return isTimeZone(that) && that._tag === "Offset" && this.offset === that.offset; - }, - toString() { - return `TimeZone.Offset(${offsetToString(this.offset)})`; - }, - toJSON() { - return { - _id: "TimeZone", - _tag: "Offset", - offset: this.offset - }; - } -}; -var makeZonedProto = (epochMillis, zone, partsUtc) => { - const self = Object.create(ProtoZoned); - self.epochMillis = epochMillis; - self.zone = zone; - Object.defineProperty(self, "partsUtc", { - value: partsUtc, - enumerable: false, - writable: true - }); - Object.defineProperty(self, "adjustedEpochMillis", { - value: undefined, - enumerable: false, - writable: true - }); - Object.defineProperty(self, "partsAdjusted", { - value: undefined, - enumerable: false, - writable: true - }); - return self; -}; -var isDateTime = (u) => hasProperty(u, TypeId14); -var isTimeZone = (u) => hasProperty(u, TimeZoneTypeId); -var isTimeZoneOffset = (u) => isTimeZone(u) && u._tag === "Offset"; -var isTimeZoneNamed = (u) => isTimeZone(u) && u._tag === "Named"; -var isUtc = (self) => self._tag === "Utc"; -var isZoned = (self) => self._tag === "Zoned"; -var Equivalence2 = /* @__PURE__ */ make((a, b) => a.epochMillis === b.epochMillis); -var makeUtc = (epochMillis) => { - const self = Object.create(ProtoUtc); - self.epochMillis = epochMillis; - Object.defineProperty(self, "partsUtc", { - value: undefined, - enumerable: false, - writable: true - }); - return self; -}; -var unsafeFromDate = (date) => { - const epochMillis = date.getTime(); - if (Number.isNaN(epochMillis)) { - throw new IllegalArgumentException2("Invalid date"); - } - return makeUtc(epochMillis); -}; -var unsafeMake7 = (input) => { - if (isDateTime(input)) { - return input; - } else if (input instanceof Date) { - return unsafeFromDate(input); - } else if (typeof input === "object") { - const date = new Date(0); - setPartsDate(date, input); - return unsafeFromDate(date); - } else if (typeof input === "string" && !hasZone(input)) { - return unsafeFromDate(new Date(input + "Z")); - } - return unsafeFromDate(new Date(input)); -}; -var hasZone = (input) => /Z|[+-]\d{2}$|[+-]\d{2}:?\d{2}$|\]$/.test(input); -var minEpochMillis = -8640000000000000 + 12 * 60 * 60 * 1000; -var maxEpochMillis = 8640000000000000 - 14 * 60 * 60 * 1000; -var unsafeMakeZoned = (input, options) => { - if (options?.timeZone === undefined && isDateTime(input) && isZoned(input)) { - return input; - } - const self = unsafeMake7(input); - if (self.epochMillis < minEpochMillis || self.epochMillis > maxEpochMillis) { - throw new RangeError(`Epoch millis out of range: ${self.epochMillis}`); - } - let zone; - if (options?.timeZone === undefined) { - const offset = new Date(self.epochMillis).getTimezoneOffset() * -60 * 1000; - zone = zoneMakeOffset(offset); - } else if (isTimeZone(options?.timeZone)) { - zone = options.timeZone; - } else if (typeof options?.timeZone === "number") { - zone = zoneMakeOffset(options.timeZone); - } else { - const parsedZone = zoneFromString(options.timeZone); - if (isNone2(parsedZone)) { - throw new IllegalArgumentException2(`Invalid time zone: ${options.timeZone}`); - } - zone = parsedZone.value; - } - if (options?.adjustForTimeZone !== true) { - return makeZonedProto(self.epochMillis, zone, self.partsUtc); - } - return makeZonedFromAdjusted(self.epochMillis, zone, options?.disambiguation ?? "compatible"); -}; -var makeZoned = /* @__PURE__ */ liftThrowable(unsafeMakeZoned); -var zonedStringRegex = /^(.{17,35})\[(.+)\]$/; -var makeZonedFromString = (input) => { - const match10 = zonedStringRegex.exec(input); - if (match10 === null) { - const offset = parseOffset(input); - return offset !== null ? makeZoned(input, { - timeZone: offset - }) : none2(); - } - const [, isoString, timeZone] = match10; - return makeZoned(isoString, { - timeZone - }); -}; -var validZoneCache = /* @__PURE__ */ globalValue("effect/DateTime/validZoneCache", () => new Map); -var formatOptions = { - day: "numeric", - month: "numeric", - year: "numeric", - hour: "numeric", - minute: "numeric", - second: "numeric", - timeZoneName: "longOffset", - fractionalSecondDigits: 3, - hourCycle: "h23" -}; -var zoneMakeIntl = (format4) => { - const zoneId = format4.resolvedOptions().timeZone; - if (validZoneCache.has(zoneId)) { - return validZoneCache.get(zoneId); - } - const zone = Object.create(ProtoTimeZoneNamed); - zone.id = zoneId; - zone.format = format4; - validZoneCache.set(zoneId, zone); - return zone; -}; -var zoneUnsafeMakeNamed = (zoneId) => { - if (validZoneCache.has(zoneId)) { - return validZoneCache.get(zoneId); - } - try { - return zoneMakeIntl(new Intl.DateTimeFormat("en-US", { - ...formatOptions, - timeZone: zoneId - })); - } catch { - throw new IllegalArgumentException2(`Invalid time zone: ${zoneId}`); - } -}; -var zoneMakeOffset = (offset) => { - const zone = Object.create(ProtoTimeZoneOffset); - zone.offset = offset; - return zone; -}; -var zoneMakeNamed = /* @__PURE__ */ liftThrowable(zoneUnsafeMakeNamed); -var offsetZoneRegex = /^(?:GMT|[+-])/; -var zoneFromString = (zone) => { - if (offsetZoneRegex.test(zone)) { - const offset = parseOffset(zone); - return offset === null ? none2() : some2(zoneMakeOffset(offset)); - } - return zoneMakeNamed(zone); -}; -var zoneToString = (self) => { - if (self._tag === "Offset") { - return offsetToString(self.offset); - } - return self.id; -}; -var toDateUtc = (self) => new Date(self.epochMillis); -var toDate = (self) => { - if (self._tag === "Utc") { - return new Date(self.epochMillis); - } else if (self.zone._tag === "Offset") { - return new Date(self.epochMillis + self.zone.offset); - } else if (self.adjustedEpochMillis !== undefined) { - return new Date(self.adjustedEpochMillis); - } - const parts2 = self.zone.format.formatToParts(self.epochMillis).filter((_) => _.type !== "literal"); - const date = new Date(0); - date.setUTCFullYear(Number(parts2[2].value), Number(parts2[0].value) - 1, Number(parts2[1].value)); - date.setUTCHours(Number(parts2[3].value), Number(parts2[4].value), Number(parts2[5].value), Number(parts2[6].value)); - self.adjustedEpochMillis = date.getTime(); - return date; -}; -var zonedOffset = (self) => { - const date = toDate(self); - return date.getTime() - toEpochMillis(self); -}; -var offsetToString = (offset) => { - const abs = Math.abs(offset); - let hours2 = Math.floor(abs / (60 * 60 * 1000)); - let minutes2 = Math.round(abs % (60 * 60 * 1000) / (60 * 1000)); - if (minutes2 === 60) { - hours2 += 1; - minutes2 = 0; - } - return `${offset < 0 ? "-" : "+"}${String(hours2).padStart(2, "0")}:${String(minutes2).padStart(2, "0")}`; -}; -var zonedOffsetIso = (self) => offsetToString(zonedOffset(self)); -var toEpochMillis = (self) => self.epochMillis; -var setPartsDate = (date, parts2) => { - if (parts2.year !== undefined) { - date.setUTCFullYear(parts2.year); - } - if (parts2.month !== undefined) { - date.setUTCMonth(parts2.month - 1); - } - if (parts2.day !== undefined) { - date.setUTCDate(parts2.day); - } - if (parts2.weekDay !== undefined) { - const diff8 = parts2.weekDay - date.getUTCDay(); - date.setUTCDate(date.getUTCDate() + diff8); - } - if (parts2.hours !== undefined) { - date.setUTCHours(parts2.hours); - } - if (parts2.minutes !== undefined) { - date.setUTCMinutes(parts2.minutes); - } - if (parts2.seconds !== undefined) { - date.setUTCSeconds(parts2.seconds); - } - if (parts2.millis !== undefined) { - date.setUTCMilliseconds(parts2.millis); - } -}; -var constDayMillis = 24 * 60 * 60 * 1000; -var makeZonedFromAdjusted = (adjustedMillis, zone, disambiguation) => { - if (zone._tag === "Offset") { - return makeZonedProto(adjustedMillis - zone.offset, zone); - } - const beforeOffset = calculateNamedOffset(adjustedMillis - constDayMillis, adjustedMillis, zone); - const afterOffset = calculateNamedOffset(adjustedMillis + constDayMillis, adjustedMillis, zone); - if (beforeOffset === afterOffset) { - return makeZonedProto(adjustedMillis - beforeOffset, zone); - } - const isForwards = beforeOffset < afterOffset; - const transitionMillis = beforeOffset - afterOffset; - if (isForwards) { - const currentAfterOffset = calculateNamedOffset(adjustedMillis - afterOffset, adjustedMillis, zone); - if (currentAfterOffset === afterOffset) { - return makeZonedProto(adjustedMillis - afterOffset, zone); - } - const before2 = makeZonedProto(adjustedMillis - beforeOffset, zone); - const beforeAdjustedMillis = toDate(before2).getTime(); - if (adjustedMillis !== beforeAdjustedMillis) { - switch (disambiguation) { - case "reject": { - const formatted = new Date(adjustedMillis).toISOString(); - throw new RangeError(`Gap time: ${formatted} does not exist in time zone ${zone.id}`); - } - case "earlier": - return makeZonedProto(adjustedMillis - afterOffset, zone); - case "compatible": - case "later": - return before2; - } - } - return before2; - } - const currentBeforeOffset = calculateNamedOffset(adjustedMillis - beforeOffset, adjustedMillis, zone); - if (currentBeforeOffset === beforeOffset) { - if (disambiguation === "earlier" || disambiguation === "compatible") { - return makeZonedProto(adjustedMillis - beforeOffset, zone); - } - const laterOffset = calculateNamedOffset(adjustedMillis - beforeOffset + transitionMillis, adjustedMillis + transitionMillis, zone); - if (laterOffset === beforeOffset) { - return makeZonedProto(adjustedMillis - beforeOffset, zone); - } - if (disambiguation === "reject") { - const formatted = new Date(adjustedMillis).toISOString(); - throw new RangeError(`Ambiguous time: ${formatted} occurs twice in time zone ${zone.id}`); - } - } - return makeZonedProto(adjustedMillis - afterOffset, zone); -}; -var offsetRegex = /([+-])(\d{2}):(\d{2})$/; -var parseOffset = (offset) => { - const match10 = offsetRegex.exec(offset); - if (match10 === null) { - return null; - } - const [, sign, hours2, minutes2] = match10; - return (sign === "+" ? 1 : -1) * (Number(hours2) * 60 + Number(minutes2)) * 60 * 1000; -}; -var calculateNamedOffset = (utcMillis, adjustedMillis, zone) => { - const offset = zone.format.formatToParts(utcMillis).find((_) => _.type === "timeZoneName")?.value ?? ""; - if (offset === "GMT") { - return 0; - } - const result = parseOffset(offset); - if (result === null) { - return zonedOffset(makeZonedProto(adjustedMillis, zone)); - } - return result; -}; -var formatIso = (self) => toDateUtc(self).toISOString(); -var formatIsoOffset = (self) => { - const date = toDate(self); - return self._tag === "Utc" ? date.toISOString() : `${date.toISOString().slice(0, -1)}${zonedOffsetIso(self)}`; -}; -var formatIsoZoned = (self) => self.zone._tag === "Offset" ? formatIsoOffset(self) : `${formatIsoOffset(self)}[${self.zone.id}]`; - -// node_modules/effect/dist/esm/String.js -var toUpperCase = (self) => self.toUpperCase(); -var toLowerCase = (self) => self.toLowerCase(); -var capitalize = (self) => { - if (self.length === 0) - return self; - return toUpperCase(self[0]) + self.slice(1); -}; -var uncapitalize = (self) => { - if (self.length === 0) - return self; - return toLowerCase(self[0]) + self.slice(1); -}; -var isNonEmpty5 = (self) => self.length > 0; - -// node_modules/effect/dist/esm/Random.js -var fixed2 = fixed; - -// node_modules/effect/dist/esm/internal/schedule.js -var ScheduleSymbolKey = "effect/Schedule"; -var ScheduleTypeId = /* @__PURE__ */ Symbol.for(ScheduleSymbolKey); -var isSchedule = (u) => hasProperty(u, ScheduleTypeId); -var ScheduleDriverSymbolKey = "effect/ScheduleDriver"; -var ScheduleDriverTypeId = /* @__PURE__ */ Symbol.for(ScheduleDriverSymbolKey); -var defaultIterationMetadata = { - start: 0, - now: 0, - input: undefined, - output: undefined, - elapsed: zero, - elapsedSincePrevious: zero, - recurrence: 0 -}; -var CurrentIterationMetadata = /* @__PURE__ */ Reference2()("effect/Schedule/CurrentIterationMetadata", { - defaultValue: () => defaultIterationMetadata -}); -var scheduleVariance = { - _Out: (_) => _, - _In: (_) => _, - _R: (_) => _ -}; -var scheduleDriverVariance = { - _Out: (_) => _, - _In: (_) => _, - _R: (_) => _ -}; - -class ScheduleImpl { - initial; - step; - [ScheduleTypeId] = scheduleVariance; - constructor(initial, step3) { - this.initial = initial; - this.step = step3; - } - pipe() { - return pipeArguments(this, arguments); - } -} -var updateInfo = (iterationMetaRef, now, input, output) => update2(iterationMetaRef, (prev) => prev.recurrence === 0 ? { - now, - input, - output, - recurrence: prev.recurrence + 1, - elapsed: zero, - elapsedSincePrevious: zero, - start: now -} : { - now, - input, - output, - recurrence: prev.recurrence + 1, - elapsed: millis(now - prev.start), - elapsedSincePrevious: millis(now - prev.now), - start: prev.start -}); - -class ScheduleDriverImpl { - schedule; - ref; - [ScheduleDriverTypeId] = scheduleDriverVariance; - constructor(schedule, ref) { - this.schedule = schedule; - this.ref = ref; - } - get state() { - return map9(get10(this.ref), (tuple2) => tuple2[1]); - } - get last() { - return flatMap7(get10(this.ref), ([element, _]) => { - switch (element._tag) { - case "None": { - return failSync(() => new NoSuchElementException); - } - case "Some": { - return succeed(element.value); - } - } - }); - } - iterationMeta = /* @__PURE__ */ unsafeMake4(defaultIterationMetadata); - get reset() { - return set4(this.ref, [none2(), this.schedule.initial]).pipe(zipLeft(set4(this.iterationMeta, defaultIterationMetadata))); - } - next(input) { - return pipe(map9(get10(this.ref), (tuple2) => tuple2[1]), flatMap7((state) => pipe(currentTimeMillis2, flatMap7((now) => pipe(suspend(() => this.schedule.step(now, input, state)), flatMap7(([state2, out, decision]) => { - const setState = set4(this.ref, [some2(out), state2]); - if (isDone4(decision)) { - return setState.pipe(zipRight(fail2(none2()))); - } - const millis2 = start2(decision.intervals) - now; - if (millis2 <= 0) { - return setState.pipe(zipRight(updateInfo(this.iterationMeta, now, input, out)), as(out)); - } - const duration = millis(millis2); - return pipe(setState, zipRight(updateInfo(this.iterationMeta, now, input, out)), zipRight(sleep3(duration)), as(out)); - })))))); - } -} -var makeWithState = (initial, step3) => new ScheduleImpl(initial, step3); -var asVoid2 = (self) => map10(self, constVoid); -var check = /* @__PURE__ */ dual(2, (self, test) => checkEffect(self, (input, out) => sync(() => test(input, out)))); -var checkEffect = /* @__PURE__ */ dual(2, (self, test) => makeWithState(self.initial, (now, input, state) => flatMap7(self.step(now, input, state), ([state2, out, decision]) => { - if (isDone4(decision)) { - return succeed([state2, out, done5]); - } - return map9(test(input, out), (cont) => cont ? [state2, out, decision] : [state2, out, done5]); -}))); -var driver = (self) => pipe(make23([none2(), self.initial]), map9((ref) => new ScheduleDriverImpl(self, ref))); -var intersect5 = /* @__PURE__ */ dual(2, (self, that) => intersectWith(self, that, intersect4)); -var intersectWith = /* @__PURE__ */ dual(3, (self, that, f) => makeWithState([self.initial, that.initial], (now, input, state) => pipe(zipWith2(self.step(now, input, state[0]), that.step(now, input, state[1]), (a, b) => [a, b]), flatMap7(([[lState, out, lDecision], [rState, out2, rDecision]]) => { - if (isContinue2(lDecision) && isContinue2(rDecision)) { - return intersectWithLoop(self, that, input, lState, out, lDecision.intervals, rState, out2, rDecision.intervals, f); - } - return succeed([[lState, rState], [out, out2], done5]); -})))); -var intersectWithLoop = (self, that, input, lState, out, lInterval, rState, out2, rInterval, f) => { - const combined = f(lInterval, rInterval); - if (isNonEmpty4(combined)) { - return succeed([[lState, rState], [out, out2], _continue2(combined)]); - } - if (pipe(lInterval, lessThan6(rInterval))) { - return flatMap7(self.step(end2(lInterval), input, lState), ([lState2, out3, decision]) => { - if (isDone4(decision)) { - return succeed([[lState2, rState], [out3, out2], done5]); - } - return intersectWithLoop(self, that, input, lState2, out3, decision.intervals, rState, out2, rInterval, f); - }); - } - return flatMap7(that.step(end2(rInterval), input, rState), ([rState2, out22, decision]) => { - if (isDone4(decision)) { - return succeed([[lState, rState2], [out, out22], done5]); - } - return intersectWithLoop(self, that, input, lState, out, lInterval, rState2, out22, decision.intervals, f); - }); -}; -var map10 = /* @__PURE__ */ dual(2, (self, f) => mapEffect(self, (out) => sync(() => f(out)))); -var mapEffect = /* @__PURE__ */ dual(2, (self, f) => makeWithState(self.initial, (now, input, state) => flatMap7(self.step(now, input, state), ([state2, out, decision]) => map9(f(out), (out2) => [state2, out2, decision])))); -var passthrough = (self) => makeWithState(self.initial, (now, input, state) => pipe(self.step(now, input, state), map9(([state2, _, decision]) => [state2, input, decision]))); -var recurs = (n) => whileOutput(forever2, (out) => out < n); -var unfold2 = (initial, f) => makeWithState(initial, (now, _, state) => sync(() => [f(state), state, continueWith2(after2(now))])); -var untilInputEffect = /* @__PURE__ */ dual(2, (self, f) => checkEffect(self, (input, _) => negate(f(input)))); -var whileInputEffect = /* @__PURE__ */ dual(2, (self, f) => checkEffect(self, (input, _) => f(input))); -var whileOutput = /* @__PURE__ */ dual(2, (self, f) => check(self, (_, out) => f(out))); -var ScheduleDefectTypeId = /* @__PURE__ */ Symbol.for("effect/Schedule/ScheduleDefect"); - -class ScheduleDefect { - error; - [ScheduleDefectTypeId]; - constructor(error) { - this.error = error; - this[ScheduleDefectTypeId] = ScheduleDefectTypeId; - } -} -var isScheduleDefect = (u) => hasProperty(u, ScheduleDefectTypeId); -var scheduleDefectWrap = (self) => catchAll(self, (e) => die2(new ScheduleDefect(e))); -var scheduleDefectRefailCause = (cause2) => match2(find(cause2, (_) => isDieType(_) && isScheduleDefect(_.defect) ? some2(_.defect) : none2()), { - onNone: () => cause2, - onSome: (error) => fail(error.error) -}); -var scheduleDefectRefail = (effect) => catchAllCause(effect, (cause2) => failCause(scheduleDefectRefailCause(cause2))); -var repeat_Effect = /* @__PURE__ */ dual(2, (self, schedule) => repeatOrElse_Effect(self, schedule, (e, _) => fail2(e))); -var repeat_combined = /* @__PURE__ */ dual(2, (self, options) => { - if (isSchedule(options)) { - return repeat_Effect(self, options); - } - const base = options.schedule ?? passthrough(forever2); - const withWhile = options.while ? whileInputEffect(base, (a) => { - const applied = options.while(a); - if (typeof applied === "boolean") { - return succeed(applied); - } - return scheduleDefectWrap(applied); - }) : base; - const withUntil = options.until ? untilInputEffect(withWhile, (a) => { - const applied = options.until(a); - if (typeof applied === "boolean") { - return succeed(applied); - } - return scheduleDefectWrap(applied); - }) : withWhile; - const withTimes = options.times ? intersect5(withUntil, recurs(options.times)).pipe(map10((intersectionPair) => intersectionPair[0])) : withUntil; - return scheduleDefectRefail(repeat_Effect(self, withTimes)); -}); -var repeatOrElse_Effect = /* @__PURE__ */ dual(3, (self, schedule, orElse3) => flatMap7(driver(schedule), (driver2) => matchEffect(self, { - onFailure: (error) => orElse3(error, none2()), - onSuccess: (value) => repeatOrElseEffectLoop(provideServiceEffect(self, CurrentIterationMetadata, get10(driver2.iterationMeta)), driver2, (error, option2) => provideServiceEffect(orElse3(error, option2), CurrentIterationMetadata, get10(driver2.iterationMeta)), value) -}))); -var repeatOrElseEffectLoop = (self, driver2, orElse3, value) => matchEffect(driver2.next(value), { - onFailure: () => orDie(driver2.last), - onSuccess: (b) => matchEffect(self, { - onFailure: (error) => orElse3(error, some2(b)), - onSuccess: (value2) => repeatOrElseEffectLoop(self, driver2, orElse3, value2) - }) -}); -var retry_Effect = /* @__PURE__ */ dual(2, (self, policy) => retryOrElse_Effect(self, policy, (e, _) => fail2(e))); -var retry_combined = /* @__PURE__ */ dual(2, (self, options) => { - if (isSchedule(options)) { - return retry_Effect(self, options); - } - return scheduleDefectRefail(retry_Effect(self, fromRetryOptions(options))); -}); -var fromRetryOptions = (options) => { - const base = options.schedule ?? forever2; - const withWhile = options.while ? whileInputEffect(base, (e) => { - const applied = options.while(e); - if (typeof applied === "boolean") { - return succeed(applied); - } - return scheduleDefectWrap(applied); - }) : base; - const withUntil = options.until ? untilInputEffect(withWhile, (e) => { - const applied = options.until(e); - if (typeof applied === "boolean") { - return succeed(applied); - } - return scheduleDefectWrap(applied); - }) : withWhile; - return options.times !== undefined ? intersect5(withUntil, recurs(options.times)) : withUntil; -}; -var retryOrElse_Effect = /* @__PURE__ */ dual(3, (self, policy, orElse3) => flatMap7(driver(policy), (driver2) => retryOrElse_EffectLoop(provideServiceEffect(self, CurrentIterationMetadata, get10(driver2.iterationMeta)), driver2, (e, out) => provideServiceEffect(orElse3(e, out), CurrentIterationMetadata, get10(driver2.iterationMeta))))); -var retryOrElse_EffectLoop = (self, driver2, orElse3) => { - return catchAll(self, (e) => matchEffect(driver2.next(e), { - onFailure: () => pipe(driver2.last, orDie, flatMap7((out) => orElse3(e, out))), - onSuccess: () => retryOrElse_EffectLoop(self, driver2, orElse3) - })); -}; -var schedule_Effect = /* @__PURE__ */ dual(2, (self, schedule) => scheduleFrom_Effect(self, undefined, schedule)); -var scheduleFrom_Effect = /* @__PURE__ */ dual(3, (self, initial, schedule) => flatMap7(driver(schedule), (driver2) => scheduleFrom_EffectLoop(provideServiceEffect(self, CurrentIterationMetadata, get10(driver2.iterationMeta)), initial, driver2))); -var scheduleFrom_EffectLoop = (self, initial, driver2) => matchEffect(driver2.next(initial), { - onFailure: () => orDie(driver2.last), - onSuccess: () => flatMap7(self, (a) => scheduleFrom_EffectLoop(self, a, driver2)) -}); -var forever2 = /* @__PURE__ */ unfold2(0, (n) => n + 1); -var once2 = /* @__PURE__ */ asVoid2(/* @__PURE__ */ recurs(1)); -var scheduleForked = /* @__PURE__ */ dual(2, (self, schedule) => forkScoped(schedule_Effect(self, schedule))); - -// node_modules/effect/dist/esm/internal/executionPlan.js -var withExecutionPlan = /* @__PURE__ */ dual(2, (effect, plan) => suspend(() => { - let i = 0; - let result; - return flatMap7(whileLoop({ - while: () => i < plan.steps.length && (result === undefined || isLeft2(result)), - body: () => { - const step3 = plan.steps[i]; - let nextEffect = effect_provide(effect, step3.provide); - if (result) { - let attempted = false; - const wrapped = nextEffect; - nextEffect = suspend(() => { - if (attempted) - return wrapped; - attempted = true; - return result; - }); - nextEffect = scheduleDefectRefail(retry_Effect(nextEffect, scheduleFromStep(step3, false))); - } else { - const schedule = scheduleFromStep(step3, true); - nextEffect = schedule ? scheduleDefectRefail(retry_Effect(nextEffect, schedule)) : nextEffect; - } - return either2(nextEffect); - }, - step: (either3) => { - result = either3; - i++; - } - }), () => result); -})); -var scheduleFromStep = (step3, first2) => { - if (!first2) { - return fromRetryOptions({ - schedule: step3.schedule ? step3.schedule : step3.attempts ? undefined : once2, - times: step3.attempts, - while: step3.while - }); - } else if (step3.attempts === 1 || !(step3.schedule || step3.attempts)) { - return; - } - return fromRetryOptions({ - schedule: step3.schedule, - while: step3.while, - times: step3.attempts ? step3.attempts - 1 : undefined - }); -}; - -// node_modules/effect/dist/esm/Deferred.js -var _await2 = deferredAwait; -var done6 = deferredDone; -var interrupt4 = deferredInterrupt; -var unsafeMake8 = deferredUnsafeMake; - -// node_modules/effect/dist/esm/MutableList.js -var TypeId15 = /* @__PURE__ */ Symbol.for("effect/MutableList"); -var MutableListProto = { - [TypeId15]: TypeId15, - [Symbol.iterator]() { - let done7 = false; - let head4 = this.head; - return { - next() { - if (done7) { - return this.return(); - } - if (head4 == null) { - done7 = true; - return this.return(); - } - const value = head4.value; - head4 = head4.next; - return { - done: done7, - value - }; - }, - return(value) { - if (!done7) { - done7 = true; - } - return { - done: true, - value - }; - } - }; - }, - toString() { - return format(this.toJSON()); - }, - toJSON() { - return { - _id: "MutableList", - values: Array.from(this).map(toJSON) - }; - }, - [NodeInspectSymbol]() { - return this.toJSON(); - }, - pipe() { - return pipeArguments(this, arguments); - } -}; -var makeNode = (value) => ({ - value, - removed: false, - prev: undefined, - next: undefined -}); -var empty29 = () => { - const list = Object.create(MutableListProto); - list.head = undefined; - list.tail = undefined; - list._length = 0; - return list; -}; -var isEmpty8 = (self) => length(self) === 0; -var length = (self) => self._length; -var append3 = /* @__PURE__ */ dual(2, (self, value) => { - const node = makeNode(value); - if (self.head === undefined) { - self.head = node; - } - if (self.tail === undefined) { - self.tail = node; - } else { - self.tail.next = node; - node.prev = self.tail; - self.tail = node; - } - self._length += 1; - return self; -}); -var shift = (self) => { - const head4 = self.head; - if (head4 !== undefined) { - remove6(self, head4); - return head4.value; - } - return; -}; -var remove6 = (self, node) => { - if (node.removed) { - return; - } - node.removed = true; - if (node.prev !== undefined && node.next !== undefined) { - node.prev.next = node.next; - node.next.prev = node.prev; - } else if (node.prev !== undefined) { - self.tail = node.prev; - node.prev.next = undefined; - } else if (node.next !== undefined) { - self.head = node.next; - node.next.prev = undefined; - } else { - self.tail = undefined; - self.head = undefined; - } - if (self._length > 0) { - self._length -= 1; - } -}; - -// node_modules/effect/dist/esm/MutableQueue.js -var TypeId16 = /* @__PURE__ */ Symbol.for("effect/MutableQueue"); -var EmptyMutableQueue = /* @__PURE__ */ Symbol.for("effect/mutable/MutableQueue/Empty"); -var MutableQueueProto = { - [TypeId16]: TypeId16, - [Symbol.iterator]() { - return Array.from(this.queue)[Symbol.iterator](); - }, - toString() { - return format(this.toJSON()); - }, - toJSON() { - return { - _id: "MutableQueue", - values: Array.from(this).map(toJSON) - }; - }, - [NodeInspectSymbol]() { - return this.toJSON(); - }, - pipe() { - return pipeArguments(this, arguments); - } -}; -var make38 = (capacity) => { - const queue = Object.create(MutableQueueProto); - queue.queue = empty29(); - queue.capacity = capacity; - return queue; -}; -var unbounded = () => make38(undefined); -var offer = /* @__PURE__ */ dual(2, (self, value) => { - const queueLength = length(self.queue); - if (self.capacity !== undefined && queueLength === self.capacity) { - return false; - } - append3(value)(self.queue); - return true; -}); -var poll = /* @__PURE__ */ dual(2, (self, def) => { - if (isEmpty8(self.queue)) { - return def; - } - return shift(self.queue); -}); - -// node_modules/effect/dist/esm/internal/cache.js -var complete2 = (key, exit2, entryStats, timeToLiveMillis) => struct({ - _tag: "Complete", - key, - exit: exit2, - entryStats, - timeToLiveMillis -}); -var pending2 = (key, deferred) => struct({ - _tag: "Pending", - key, - deferred -}); -var refreshing = (deferred, complete3) => struct({ - _tag: "Refreshing", - deferred, - complete: complete3 -}); -var MapKeyTypeId = /* @__PURE__ */ Symbol.for("effect/Cache/MapKey"); - -class MapKeyImpl { - current; - [MapKeyTypeId] = MapKeyTypeId; - previous = undefined; - next = undefined; - constructor(current) { - this.current = current; - } - [symbol]() { - return pipe(hash(this.current), combine(hash(this.previous)), combine(hash(this.next)), cached(this)); - } - [symbol2](that) { - if (this === that) { - return true; - } - return isMapKey(that) && equals(this.current, that.current) && equals(this.previous, that.previous) && equals(this.next, that.next); - } -} -var makeMapKey = (current) => new MapKeyImpl(current); -var isMapKey = (u) => hasProperty(u, MapKeyTypeId); - -class KeySetImpl { - head = undefined; - tail = undefined; - add(key) { - if (key !== this.tail) { - if (this.tail === undefined) { - this.head = key; - this.tail = key; - } else { - const previous = key.previous; - const next = key.next; - if (next !== undefined) { - key.next = undefined; - if (previous !== undefined) { - previous.next = next; - next.previous = previous; - } else { - this.head = next; - this.head.previous = undefined; - } - } - this.tail.next = key; - key.previous = this.tail; - this.tail = key; - } - } - } - remove() { - const key = this.head; - if (key !== undefined) { - const next = key.next; - if (next !== undefined) { - key.next = undefined; - this.head = next; - this.head.previous = undefined; - } else { - this.head = undefined; - this.tail = undefined; - } - } - return key; - } -} -var makeKeySet = () => new KeySetImpl; -var makeCacheState = (map11, keys5, accesses, updating, hits, misses) => ({ - map: map11, - keys: keys5, - accesses, - updating, - hits, - misses -}); -var initialCacheState = () => makeCacheState(empty21(), makeKeySet(), unbounded(), make11(false), 0, 0); -var CacheSymbolKey = "effect/Cache"; -var CacheTypeId = /* @__PURE__ */ Symbol.for(CacheSymbolKey); -var cacheVariance = { - _Key: (_) => _, - _Error: (_) => _, - _Value: (_) => _ -}; -var ConsumerCacheSymbolKey = "effect/ConsumerCache"; -var ConsumerCacheTypeId = /* @__PURE__ */ Symbol.for(ConsumerCacheSymbolKey); -var consumerCacheVariance = { - _Key: (_) => _, - _Error: (_) => _, - _Value: (_) => _ -}; -var makeCacheStats = (options) => options; -var makeEntryStats = (loadedMillis) => ({ - loadedMillis -}); - -class CacheImpl { - capacity; - context; - fiberId; - lookup; - timeToLive; - [CacheTypeId] = cacheVariance; - [ConsumerCacheTypeId] = consumerCacheVariance; - cacheState; - constructor(capacity, context3, fiberId2, lookup, timeToLive) { - this.capacity = capacity; - this.context = context3; - this.fiberId = fiberId2; - this.lookup = lookup; - this.timeToLive = timeToLive; - this.cacheState = initialCacheState(); - } - get(key) { - return map9(this.getEither(key), merge); - } - get cacheStats() { - return sync(() => makeCacheStats({ - hits: this.cacheState.hits, - misses: this.cacheState.misses, - size: size4(this.cacheState.map) - })); - } - getOption(key) { - return suspend(() => match2(get12(this.cacheState.map, key), { - onNone: () => { - const mapKey = makeMapKey(key); - this.trackAccess(mapKey); - this.trackMiss(); - return succeed(none2()); - }, - onSome: (value) => this.resolveMapValue(value) - })); - } - getOptionComplete(key) { - return suspend(() => match2(get12(this.cacheState.map, key), { - onNone: () => { - const mapKey = makeMapKey(key); - this.trackAccess(mapKey); - this.trackMiss(); - return succeed(none2()); - }, - onSome: (value) => this.resolveMapValue(value, true) - })); - } - contains(key) { - return sync(() => has4(this.cacheState.map, key)); - } - entryStats(key) { - return sync(() => { - const option2 = get12(this.cacheState.map, key); - if (isSome2(option2)) { - switch (option2.value._tag) { - case "Complete": { - const loaded = option2.value.entryStats.loadedMillis; - return some2(makeEntryStats(loaded)); - } - case "Pending": { - return none2(); - } - case "Refreshing": { - const loaded = option2.value.complete.entryStats.loadedMillis; - return some2(makeEntryStats(loaded)); - } - } - } - return none2(); - }); - } - getEither(key) { - return suspend(() => { - const k = key; - let mapKey = undefined; - let deferred = undefined; - let value = getOrUndefined(get12(this.cacheState.map, k)); - if (value === undefined) { - deferred = unsafeMake8(this.fiberId); - mapKey = makeMapKey(k); - if (has4(this.cacheState.map, k)) { - value = getOrUndefined(get12(this.cacheState.map, k)); - } else { - set5(this.cacheState.map, k, pending2(mapKey, deferred)); - } - } - if (value === undefined) { - this.trackAccess(mapKey); - this.trackMiss(); - return map9(this.lookupValueOf(key, deferred), right2); - } else { - return flatMap7(this.resolveMapValue(value), match2({ - onNone: () => this.getEither(key), - onSome: (value2) => succeed(left2(value2)) - })); - } - }); - } - invalidate(key) { - return sync(() => { - remove5(this.cacheState.map, key); - }); - } - invalidateWhen(key, when2) { - return sync(() => { - const value = get12(this.cacheState.map, key); - if (isSome2(value) && value.value._tag === "Complete") { - if (value.value.exit._tag === "Success") { - if (when2(value.value.exit.value)) { - remove5(this.cacheState.map, key); - } - } - } - }); - } - get invalidateAll() { - return sync(() => { - this.cacheState.map = empty21(); - }); - } - refresh(key) { - return clockWith3((clock2) => suspend(() => { - const k = key; - const deferred = unsafeMake8(this.fiberId); - let value = getOrUndefined(get12(this.cacheState.map, k)); - if (value === undefined) { - if (has4(this.cacheState.map, k)) { - value = getOrUndefined(get12(this.cacheState.map, k)); - } else { - set5(this.cacheState.map, k, pending2(makeMapKey(k), deferred)); - } - } - if (value === undefined) { - return asVoid(this.lookupValueOf(key, deferred)); - } else { - switch (value._tag) { - case "Complete": { - if (this.hasExpired(clock2, value.timeToLiveMillis)) { - const found = getOrUndefined(get12(this.cacheState.map, k)); - if (equals(found, value)) { - remove5(this.cacheState.map, k); - } - return asVoid(this.get(key)); - } - return pipe(this.lookupValueOf(key, deferred), when(() => { - const current = getOrUndefined(get12(this.cacheState.map, k)); - if (equals(current, value)) { - const mapValue = refreshing(deferred, value); - set5(this.cacheState.map, k, mapValue); - return true; - } - return false; - }), asVoid); - } - case "Pending": { - return _await2(value.deferred); - } - case "Refreshing": { - return _await2(value.deferred); - } - } - } - })); - } - set(key, value) { - return clockWith3((clock2) => sync(() => { - const now = clock2.unsafeCurrentTimeMillis(); - const k = key; - const lookupResult = succeed3(value); - const mapValue = complete2(makeMapKey(k), lookupResult, makeEntryStats(now), now + toMillis(decode(this.timeToLive(lookupResult)))); - set5(this.cacheState.map, k, mapValue); - })); - } - get size() { - return sync(() => { - return size4(this.cacheState.map); - }); - } - get values() { - return sync(() => { - const values4 = []; - for (const entry of this.cacheState.map) { - if (entry[1]._tag === "Complete" && entry[1].exit._tag === "Success") { - values4.push(entry[1].exit.value); - } - } - return values4; - }); - } - get entries() { - return sync(() => { - const values4 = []; - for (const entry of this.cacheState.map) { - if (entry[1]._tag === "Complete" && entry[1].exit._tag === "Success") { - values4.push([entry[0], entry[1].exit.value]); - } - } - return values4; - }); - } - get keys() { - return sync(() => { - const keys5 = []; - for (const entry of this.cacheState.map) { - if (entry[1]._tag === "Complete" && entry[1].exit._tag === "Success") { - keys5.push(entry[0]); - } - } - return keys5; - }); - } - resolveMapValue(value, ignorePending = false) { - return clockWith3((clock2) => { - switch (value._tag) { - case "Complete": { - this.trackAccess(value.key); - if (this.hasExpired(clock2, value.timeToLiveMillis)) { - remove5(this.cacheState.map, value.key.current); - return succeed(none2()); - } - this.trackHit(); - return map9(value.exit, some2); - } - case "Pending": { - this.trackAccess(value.key); - this.trackHit(); - if (ignorePending) { - return succeed(none2()); - } - return map9(_await2(value.deferred), some2); - } - case "Refreshing": { - this.trackAccess(value.complete.key); - this.trackHit(); - if (this.hasExpired(clock2, value.complete.timeToLiveMillis)) { - if (ignorePending) { - return succeed(none2()); - } - return map9(_await2(value.deferred), some2); - } - return map9(value.complete.exit, some2); - } - } - }); - } - trackHit() { - this.cacheState.hits = this.cacheState.hits + 1; - } - trackMiss() { - this.cacheState.misses = this.cacheState.misses + 1; - } - trackAccess(key) { - offer(this.cacheState.accesses, key); - if (compareAndSet(this.cacheState.updating, false, true)) { - let loop2 = true; - while (loop2) { - const key2 = poll(this.cacheState.accesses, EmptyMutableQueue); - if (key2 === EmptyMutableQueue) { - loop2 = false; - } else { - this.cacheState.keys.add(key2); - } - } - let size10 = size4(this.cacheState.map); - loop2 = size10 > this.capacity; - while (loop2) { - const key2 = this.cacheState.keys.remove(); - if (key2 !== undefined) { - if (has4(this.cacheState.map, key2.current)) { - remove5(this.cacheState.map, key2.current); - size10 = size10 - 1; - loop2 = size10 > this.capacity; - } - } else { - loop2 = false; - } - } - set2(this.cacheState.updating, false); - } - } - hasExpired(clock2, timeToLiveMillis) { - return clock2.unsafeCurrentTimeMillis() > timeToLiveMillis; - } - lookupValueOf(input, deferred) { - return clockWith3((clock2) => suspend(() => { - const key = input; - return pipe(this.lookup(input), provideContext(this.context), exit, flatMap7((exit2) => { - const now = clock2.unsafeCurrentTimeMillis(); - const stats = makeEntryStats(now); - const value = complete2(makeMapKey(key), exit2, stats, now + toMillis(decode(this.timeToLive(exit2)))); - set5(this.cacheState.map, key, value); - return zipRight(done6(deferred, exit2), exit2); - }), onInterrupt(() => zipRight(interrupt4(deferred), sync(() => { - remove5(this.cacheState.map, key); - })))); - })); - } -} -var unsafeMakeWith = (capacity, lookup, timeToLive) => new CacheImpl(capacity, empty4(), none3, lookup, (exit2) => decode(timeToLive(exit2))); - -// node_modules/effect/dist/esm/internal/query.js -var currentCache = /* @__PURE__ */ globalValue(/* @__PURE__ */ Symbol.for("effect/FiberRef/currentCache"), () => fiberRefUnsafeMake(unsafeMakeWith(65536, () => map9(deferredMake(), (handle) => ({ - listeners: new Listeners, - handle -})), () => seconds(60)))); -var currentCacheEnabled = /* @__PURE__ */ globalValue(/* @__PURE__ */ Symbol.for("effect/FiberRef/currentCacheEnabled"), () => fiberRefUnsafeMake(false)); -var fromRequest = (request, dataSource) => flatMap7(isEffect(dataSource) ? dataSource : succeed(dataSource), (ds) => fiberIdWith((id) => { - const proxy = new Proxy(request, {}); - return fiberRefGetWith(currentCacheEnabled, (cacheEnabled) => { - if (cacheEnabled) { - const cached3 = fiberRefGetWith(currentCache, (cache) => flatMap7(cache.getEither(proxy), (orNew) => { - switch (orNew._tag) { - case "Left": { - if (orNew.left.listeners.interrupted) { - return flatMap7(cache.invalidateWhen(proxy, (entry) => entry.handle === orNew.left.handle), () => cached3); - } - orNew.left.listeners.increment(); - return uninterruptibleMask((restore) => flatMap7(exit(blocked(empty15, restore(deferredAwait(orNew.left.handle)))), (exit2) => { - orNew.left.listeners.decrement(); - return exit2; - })); - } - case "Right": { - orNew.right.listeners.increment(); - return uninterruptibleMask((restore) => flatMap7(exit(blocked(single(ds, makeEntry({ - request: proxy, - result: orNew.right.handle, - listeners: orNew.right.listeners, - ownerId: id, - state: { - completed: false - } - })), restore(deferredAwait(orNew.right.handle)))), () => { - orNew.right.listeners.decrement(); - return deferredAwait(orNew.right.handle); - })); - } - } - })); - return cached3; - } - const listeners = new Listeners; - listeners.increment(); - return flatMap7(deferredMake(), (ref) => ensuring(blocked(single(ds, makeEntry({ - request: proxy, - result: ref, - listeners, - ownerId: id, - state: { - completed: false - } - })), deferredAwait(ref)), sync(() => listeners.decrement()))); - }); -})); -var cacheRequest = (request, result) => { - return fiberRefGetWith(currentCacheEnabled, (cacheEnabled) => { - if (cacheEnabled) { - return fiberRefGetWith(currentCache, (cache) => flatMap7(cache.getEither(request), (orNew) => { - switch (orNew._tag) { - case "Left": { - return void_; - } - case "Right": { - return deferredComplete(orNew.right.handle, result); - } - } - })); - } - return void_; - }); -}; -var withRequestCaching = /* @__PURE__ */ dual(2, (self, strategy) => fiberRefLocally(self, currentCacheEnabled, strategy)); -var withRequestCache = /* @__PURE__ */ dual(2, (self, cache) => fiberRefLocally(self, currentCache, cache)); - -// node_modules/effect/dist/esm/Request.js -var isRequest2 = isRequest; -var Class4 = Class3; - -// node_modules/effect/dist/esm/Effect.js -var EffectTypeId3 = EffectTypeId2; -var isEffect2 = isEffect; -var cachedWithTTL = cached2; -var cachedInvalidateWithTTL2 = cachedInvalidateWithTTL; -var cached3 = memoize; -var cachedFunction2 = cachedFunction; -var once3 = once; -var all3 = all2; -var allWith2 = allWith; -var allSuccesses2 = allSuccesses; -var dropUntil2 = dropUntil; -var dropWhile2 = dropWhile; -var takeUntil2 = takeUntil; -var takeWhile2 = takeWhile; -var every6 = every4; -var exists3 = exists2; -var filter7 = filter5; -var filterMap5 = filterMap4; -var findFirst6 = findFirst4; -var forEach7 = forEach6; -var head4 = head3; -var mergeAll5 = mergeAll3; -var partition4 = partition3; -var reduce10 = reduce8; -var reduceWhile2 = reduceWhile; -var reduceRight3 = reduceRight2; -var reduceEffect2 = reduceEffect; -var replicate2 = replicate; -var replicateEffect2 = replicateEffect; -var validateAll2 = validateAll; -var validateFirst2 = validateFirst; -var async = async_; -var asyncEffect2 = asyncEffect; -var custom2 = custom; -var withFiberRuntime2 = withFiberRuntime; -var fail5 = fail2; -var failSync2 = failSync; -var failCause5 = failCause; -var failCauseSync2 = failCauseSync; -var die4 = die2; -var dieMessage2 = dieMessage; -var dieSync2 = dieSync; -var gen2 = gen; -var never2 = never; -var none9 = none6; -var promise2 = promise; -var succeed6 = succeed; -var succeedNone2 = succeedNone; -var succeedSome2 = succeedSome; -var suspend3 = suspend; -var sync3 = sync; -var _void = void_; -var yieldNow4 = yieldNow; -var _catch2 = _catch; -var catchAll2 = catchAll; -var catchAllCause2 = catchAllCause; -var catchAllDefect2 = catchAllDefect; -var catchIf2 = catchIf; -var catchSome2 = catchSome; -var catchSomeCause2 = catchSomeCause; -var catchSomeDefect2 = catchSomeDefect; -var catchTag2 = catchTag; -var catchTags2 = catchTags; -var cause2 = cause; -var eventually2 = eventually; -var ignore2 = ignore; -var ignoreLogged2 = ignoreLogged; -var parallelErrors2 = parallelErrors; -var sandbox2 = sandbox; -var retry = retry_combined; -var withExecutionPlan2 = withExecutionPlan; -var retryOrElse = retryOrElse_Effect; -var try_3 = try_2; -var tryMap2 = tryMap; -var tryMapPromise2 = tryMapPromise; -var tryPromise2 = tryPromise; -var unsandbox2 = unsandbox; -var allowInterrupt2 = allowInterrupt; -var checkInterruptible2 = checkInterruptible; -var disconnect2 = disconnect; -var interrupt5 = interrupt2; -var interruptWith2 = interruptWith; -var interruptible4 = interruptible2; -var interruptibleMask2 = interruptibleMask; -var onInterrupt2 = onInterrupt; -var uninterruptible2 = uninterruptible; -var uninterruptibleMask3 = uninterruptibleMask; -var liftPredicate2 = liftPredicate; -var as3 = as; -var asSome2 = asSome; -var asSomeError2 = asSomeError; -var asVoid3 = asVoid; -var flip2 = flip; -var flipWith2 = flipWith; -var map11 = map9; -var mapAccum3 = mapAccum2; -var mapBoth3 = mapBoth2; -var mapError2 = mapError; -var mapErrorCause2 = mapErrorCause; -var merge6 = merge5; -var negate2 = negate; -var acquireRelease2 = acquireRelease; -var acquireReleaseInterruptible2 = acquireReleaseInterruptible; -var acquireUseRelease2 = acquireUseRelease; -var addFinalizer2 = addFinalizer; -var ensuring2 = ensuring; -var onError2 = onError; -var onExit3 = onExit; -var parallelFinalizers2 = parallelFinalizers; -var sequentialFinalizers2 = sequentialFinalizers; -var finalizersMask2 = finalizersMask; -var scope2 = scope; -var scopeWith2 = scopeWith; -var scopedWith2 = scopedWith; -var scoped2 = scopedEffect; -var using2 = using; -var withEarlyRelease2 = withEarlyRelease; -var awaitAllChildren2 = awaitAllChildren; -var daemonChildren2 = daemonChildren; -var descriptor2 = descriptor; -var descriptorWith2 = descriptorWith; -var diffFiberRefs2 = diffFiberRefs; -var ensuringChild2 = ensuringChild; -var ensuringChildren2 = ensuringChildren; -var fiberId2 = fiberId; -var fiberIdWith2 = fiberIdWith; -var fork3 = fork; -var forkDaemon2 = forkDaemon; -var forkAll2 = forkAll; -var forkIn2 = forkIn; -var forkScoped2 = forkScoped; -var forkWithErrorHandler2 = forkWithErrorHandler; -var fromFiber2 = fromFiber; -var fromFiberEffect2 = fromFiberEffect; -var supervised2 = supervised; -var transplant2 = transplant; -var withConcurrency2 = withConcurrency; -var withScheduler2 = withScheduler; -var withSchedulingPriority2 = withSchedulingPriority; -var withMaxOpsBeforeYield2 = withMaxOpsBeforeYield; -var clock2 = clock; -var clockWith4 = clockWith3; -var withClockScoped2 = withClockScoped; -var withClock2 = withClock; -var console3 = console2; -var consoleWith2 = consoleWith; -var withConsoleScoped2 = withConsoleScoped; -var withConsole2 = withConsole; -var delay2 = delay; -var sleep4 = sleep3; -var timed2 = timed; -var timedWith2 = timedWith; -var timeout2 = timeout; -var timeoutOption2 = timeoutOption; -var timeoutFail2 = timeoutFail; -var timeoutFailCause2 = timeoutFailCause; -var timeoutTo2 = timeoutTo; -var configProviderWith2 = configProviderWith; -var withConfigProvider2 = withConfigProvider; -var withConfigProviderScoped2 = withConfigProviderScoped; -var context3 = context; -var contextWith2 = contextWith; -var contextWithEffect2 = contextWithEffect; -var mapInputContext2 = mapInputContext; -var provide2 = effect_provide; -var provideService2 = provideService; -var provideServiceEffect2 = provideServiceEffect; -var serviceFunction2 = serviceFunction; -var serviceFunctionEffect2 = serviceFunctionEffect; -var serviceFunctions2 = serviceFunctions; -var serviceConstants2 = serviceConstants; -var serviceMembers2 = serviceMembers; -var serviceOption2 = serviceOption; -var serviceOptional2 = serviceOptional; -var updateService2 = updateService; -var Do2 = Do; -var bind3 = bind2; -var bindAll2 = bindAll; -var bindTo3 = bindTo2; -var let_3 = let_2; -var option2 = option; -var either3 = either2; -var exit2 = exit; -var intoDeferred2 = intoDeferred; -var if_2 = if_; -var filterOrDie2 = filterOrDie; -var filterOrDieMessage2 = filterOrDieMessage; -var filterOrElse2 = filterOrElse; -var filterOrFail2 = filterOrFail; -var filterEffectOrElse2 = filterEffectOrElse; -var filterEffectOrFail2 = filterEffectOrFail; -var unless2 = unless; -var unlessEffect2 = unlessEffect; -var when2 = when; -var whenEffect2 = whenEffect; -var whenFiberRef2 = whenFiberRef; -var whenRef2 = whenRef; -var flatMap9 = flatMap7; -var andThen4 = andThen2; -var flatten6 = flatten4; -var race2 = race; -var raceAll2 = raceAll; -var raceFirst2 = raceFirst; -var raceWith2 = raceWith; -var summarized2 = summarized; -var tap2 = tap; -var tapBoth2 = tapBoth; -var tapDefect2 = tapDefect; -var tapError2 = tapError; -var tapErrorTag2 = tapErrorTag; -var tapErrorCause2 = tapErrorCause; -var forever3 = forever; -var iterate2 = iterate; -var loop2 = loop; -var repeat = repeat_combined; -var repeatN2 = repeatN; -var repeatOrElse = repeatOrElse_Effect; -var schedule = schedule_Effect; -var scheduleForked2 = scheduleForked; -var scheduleFrom = scheduleFrom_Effect; -var whileLoop2 = whileLoop; -var getFiberRefs = fiberRefs2; -var inheritFiberRefs2 = inheritFiberRefs; -var locally = fiberRefLocally; -var locallyWith = fiberRefLocallyWith; -var locallyScoped = fiberRefLocallyScoped; -var locallyScopedWith = fiberRefLocallyScopedWith; -var patchFiberRefs2 = patchFiberRefs; -var setFiberRefs2 = setFiberRefs; -var updateFiberRefs2 = updateFiberRefs; -var isFailure3 = isFailure; -var isSuccess3 = isSuccess; -var match10 = match8; -var matchCause2 = matchCause; -var matchCauseEffect3 = matchCauseEffect; -var matchEffect2 = matchEffect; -var log2 = log; -var logWithLevel2 = (level, ...message) => logWithLevel(level)(...message); -var logTrace2 = logTrace; -var logDebug2 = logDebug; -var logInfo2 = logInfo; -var logWarning2 = logWarning; -var logError2 = logError; -var logFatal2 = logFatal; -var withLogSpan2 = withLogSpan; -var annotateLogs2 = annotateLogs; -var annotateLogsScoped2 = annotateLogsScoped; -var logAnnotations2 = logAnnotations; -var withUnhandledErrorLogLevel2 = withUnhandledErrorLogLevel; -var whenLogLevel2 = whenLogLevel; -var orDie2 = orDie; -var orDieWith2 = orDieWith; -var orElse3 = orElse2; -var orElseFail2 = orElseFail; -var orElseSucceed2 = orElseSucceed; -var firstSuccessOf2 = firstSuccessOf; -var random3 = random2; -var randomWith2 = randomWith; -var withRandom2 = withRandom; -var withRandomFixed = /* @__PURE__ */ dual(2, (effect, values4) => withRandom2(effect, fixed2(values4))); -var withRandomScoped2 = withRandomScoped; -var runtime4 = runtime3; -var getRuntimeFlags = runtimeFlags; -var patchRuntimeFlags = updateRuntimeFlags; -var withRuntimeFlagsPatch = withRuntimeFlags; -var withRuntimeFlagsPatchScoped = withRuntimeFlagsScoped; -var tagMetrics2 = tagMetrics; -var labelMetrics2 = labelMetrics; -var tagMetricsScoped2 = tagMetricsScoped; -var labelMetricsScoped2 = labelMetricsScoped; -var metricLabels2 = metricLabels; -var withMetric2 = withMetric; -var unsafeMakeSemaphore2 = unsafeMakeSemaphore; -var makeSemaphore2 = makeSemaphore; -var unsafeMakeLatch2 = unsafeMakeLatch; -var makeLatch2 = makeLatch; -var runFork2 = unsafeForkEffect; -var runCallback = unsafeRunEffect; -var runPromise = unsafeRunPromiseEffect; -var runPromiseExit = unsafeRunPromiseExitEffect; -var runSync = unsafeRunSyncEffect; -var runSyncExit = unsafeRunSyncExitEffect; -var validate2 = validate; -var validateWith2 = validateWith; -var zip4 = zipOptions; -var zipLeft2 = zipLeftOptions; -var zipRight2 = zipRightOptions; -var zipWith3 = zipWithOptions; -var ap = /* @__PURE__ */ dual(2, (self, that) => zipWith3(self, that, (f, a) => f(a))); -var blocked2 = blocked; -var runRequestBlock2 = runRequestBlock; -var step3 = step2; -var request = /* @__PURE__ */ dual((args2) => isRequest2(args2[0]), fromRequest); -var cacheRequestResult = cacheRequest; -var withRequestBatching2 = withRequestBatching; -var withRequestCaching2 = withRequestCaching; -var withRequestCache2 = withRequestCache; -var tracer2 = tracer; -var tracerWith4 = tracerWith; -var withTracer2 = withTracer; -var withTracerScoped2 = withTracerScoped; -var withTracerEnabled2 = withTracerEnabled; -var withTracerTiming2 = withTracerTiming; -var annotateSpans2 = annotateSpans; -var annotateCurrentSpan2 = annotateCurrentSpan; -var currentSpan2 = currentSpan; -var currentPropagatedSpan2 = currentPropagatedSpan; -var currentParentSpan2 = currentParentSpan; -var spanAnnotations2 = spanAnnotations; -var spanLinks2 = spanLinks; -var linkSpans2 = linkSpans; -var linkSpanCurrent2 = linkSpanCurrent; -var makeSpan2 = makeSpan; -var makeSpanScoped2 = makeSpanScoped; -var useSpan2 = useSpan; -var withSpan2 = withSpan; -var functionWithSpan2 = functionWithSpan; -var withSpanScoped2 = withSpanScoped; -var withParentSpan2 = withParentSpan; -var fromNullable3 = fromNullable2; -var optionFromOptional2 = optionFromOptional; -var transposeOption = (self) => { - return isNone(self) ? succeedNone2 : map11(self.value, some); -}; -var transposeMapOption = /* @__PURE__ */ dual(2, (self, f) => isNone(self) ? succeedNone2 : map11(f(self.value), some)); -var makeTagProxy = (TagClass) => { - const cache = new Map; - return new Proxy(TagClass, { - get(target, prop, receiver) { - if (prop in target) { - return Reflect.get(target, prop, receiver); - } - if (cache.has(prop)) { - return cache.get(prop); - } - const fn = (...args2) => andThen2(target, (s) => { - if (typeof s[prop] === "function") { - cache.set(prop, (...args3) => andThen2(target, (s2) => s2[prop](...args3))); - return s[prop](...args2); - } - cache.set(prop, andThen2(target, (s2) => s2[prop])); - return s[prop]; - }); - const cn = andThen2(target, (s) => s[prop]); - Object.assign(fn, cn); - const apply = fn.apply; - const bind4 = fn.bind; - const call = fn.call; - const proto4 = Object.setPrototypeOf({}, Object.getPrototypeOf(cn)); - proto4.apply = apply; - proto4.bind = bind4; - proto4.call = call; - Object.setPrototypeOf(fn, proto4); - cache.set(prop, fn); - return fn; - } - }); -}; -var Tag2 = (id) => () => { - const limit = Error.stackTraceLimit; - Error.stackTraceLimit = 2; - const creationError = new Error; - Error.stackTraceLimit = limit; - function TagClass() {} - Object.setPrototypeOf(TagClass, TagProto); - TagClass.key = id; - Object.defineProperty(TagClass, "use", { - get() { - return (body) => andThen2(this, body); - } - }); - Object.defineProperty(TagClass, "stack", { - get() { - return creationError.stack; - } - }); - return makeTagProxy(TagClass); -}; -var Service = function() { - return function() { - const [id, maker] = arguments; - const proxy = "accessors" in maker ? maker["accessors"] : false; - const limit = Error.stackTraceLimit; - Error.stackTraceLimit = 2; - const creationError = new Error; - Error.stackTraceLimit = limit; - let patchState = "unchecked"; - const TagClass = function(service) { - if (patchState === "unchecked") { - const proto4 = Object.getPrototypeOf(service); - if (proto4 === Object.prototype || proto4 === null) { - patchState = "plain"; - } else { - const selfProto = Object.getPrototypeOf(this); - Object.setPrototypeOf(selfProto, proto4); - patchState = "patched"; - } - } - if (patchState === "plain") { - Object.assign(this, service); - } else if (patchState === "patched") { - Object.setPrototypeOf(service, Object.getPrototypeOf(this)); - return service; - } - }; - TagClass.prototype._tag = id; - Object.defineProperty(TagClass, "make", { - get() { - return (service) => new this(service); - } - }); - Object.defineProperty(TagClass, "use", { - get() { - return (body) => andThen2(this, body); - } - }); - TagClass.key = id; - Object.assign(TagClass, TagProto); - Object.defineProperty(TagClass, "stack", { - get() { - return creationError.stack; - } - }); - const hasDeps = "dependencies" in maker && maker.dependencies.length > 0; - const layerName = hasDeps ? "DefaultWithoutDependencies" : "Default"; - let layerCache; - let isFunction3 = false; - if ("effect" in maker) { - isFunction3 = typeof maker.effect === "function"; - Object.defineProperty(TagClass, layerName, { - get() { - if (isFunction3) { - return function() { - return fromEffect2(TagClass, map11(maker.effect.apply(null, arguments), (_) => new this(_))); - }.bind(this); - } - return layerCache ??= fromEffect2(TagClass, map11(maker.effect, (_) => new this(_))); - } - }); - } else if ("scoped" in maker) { - isFunction3 = typeof maker.scoped === "function"; - Object.defineProperty(TagClass, layerName, { - get() { - if (isFunction3) { - return function() { - return scoped(TagClass, map11(maker.scoped.apply(null, arguments), (_) => new this(_))); - }.bind(this); - } - return layerCache ??= scoped(TagClass, map11(maker.scoped, (_) => new this(_))); - } - }); - } else if ("sync" in maker) { - Object.defineProperty(TagClass, layerName, { - get() { - return layerCache ??= sync2(TagClass, () => new this(maker.sync())); - } - }); - } else { - Object.defineProperty(TagClass, layerName, { - get() { - return layerCache ??= succeed4(TagClass, new this(maker.succeed)); - } - }); - } - if (hasDeps) { - let layerWithDepsCache; - Object.defineProperty(TagClass, "Default", { - get() { - if (isFunction3) { - return function() { - return provide(this.DefaultWithoutDependencies.apply(null, arguments), maker.dependencies); - }; - } - return layerWithDepsCache ??= provide(this.DefaultWithoutDependencies, maker.dependencies); - } - }); - } - return proxy === true ? makeTagProxy(TagClass) : TagClass; - }; -}; -var fn = function(nameOrBody, ...pipeables) { - const limit = Error.stackTraceLimit; - Error.stackTraceLimit = 2; - const errorDef = new Error; - Error.stackTraceLimit = limit; - if (typeof nameOrBody !== "string") { - return defineLength(nameOrBody.length, function(...args2) { - const limit2 = Error.stackTraceLimit; - Error.stackTraceLimit = 2; - const errorCall = new Error; - Error.stackTraceLimit = limit2; - return fnApply({ - self: this, - body: nameOrBody, - args: args2, - pipeables, - spanName: "", - spanOptions: { - context: DisablePropagation.context(true) - }, - errorDef, - errorCall - }); - }); - } - const name = nameOrBody; - const options = pipeables[0]; - return (body, ...pipeables2) => defineLength(body.length, { - [name](...args2) { - const limit2 = Error.stackTraceLimit; - Error.stackTraceLimit = 2; - const errorCall = new Error; - Error.stackTraceLimit = limit2; - return fnApply({ - self: this, - body, - args: args2, - pipeables: pipeables2, - spanName: name, - spanOptions: options, - errorDef, - errorCall - }); - } - }[name]); -}; -function defineLength(length2, fn2) { - return Object.defineProperty(fn2, "length", { - value: length2, - configurable: true - }); -} -function fnApply(options) { - let effect; - let fnError = undefined; - if (isGeneratorFunction(options.body)) { - effect = fromIterator(() => options.body.apply(options.self, options.args)); - } else { - try { - effect = options.body.apply(options.self, options.args); - } catch (error) { - fnError = error; - effect = die4(error); - } - } - if (options.pipeables.length > 0) { - try { - for (const x of options.pipeables) { - effect = x(effect, ...options.args); - } - } catch (error) { - effect = fnError ? failCause5(sequential(die(fnError), die(error))) : die4(error); - } - } - let cache = false; - const captureStackTrace = () => { - if (cache !== false) { - return cache; - } - if (options.errorCall.stack) { - const stackDef = options.errorDef.stack.trim().split(` -`); - const stackCall = options.errorCall.stack.trim().split(` -`); - let endStackDef = stackDef.slice(2).join(` -`).trim(); - if (!endStackDef.includes(`(`)) { - endStackDef = endStackDef.replace(/at (.*)/, "at ($1)"); - } - let endStackCall = stackCall.slice(2).join(` -`).trim(); - if (!endStackCall.includes(`(`)) { - endStackCall = endStackCall.replace(/at (.*)/, "at ($1)"); - } - cache = `${endStackDef} -${endStackCall}`; - return cache; - } - }; - const opts = options.spanOptions && "captureStackTrace" in options.spanOptions ? options.spanOptions : { - captureStackTrace, - ...options.spanOptions - }; - return withSpan2(effect, options.spanName, opts); -} -var fnUntraced2 = fnUntraced; -var ensureSuccessType = () => (effect) => effect; -var ensureErrorType = () => (effect) => effect; -var ensureRequirementsType = () => (effect) => effect; -// node_modules/effect/dist/esm/Schema.js -var exports_Schema = {}; -__export(exports_Schema, { - withDefaults: () => withDefaults, - withDecodingDefault: () => withDecodingDefault, - withConstructorDefault: () => withConstructorDefault, - validateSync: () => validateSync, - validatePromise: () => validatePromise, - validateOption: () => validateOption, - validateEither: () => validateEither2, - validate: () => validate5, - validDate: () => validDate, - uppercased: () => uppercased, - uncapitalized: () => uncapitalized, - typeSchema: () => typeSchema, - trimmed: () => trimmed, - transformOrFail: () => transformOrFail, - transformLiterals: () => transformLiterals, - transformLiteral: () => transformLiteral, - transform: () => transform2, - tag: () => tag, - symbolWithResult: () => symbolWithResult, - symbolSerializable: () => symbolSerializable, - suspend: () => suspend5, - successSchema: () => successSchema, - startsWith: () => startsWith, - standardSchemaV1: () => standardSchemaV1, - split: () => split, - serializeSuccess: () => serializeSuccess, - serializeFailure: () => serializeFailure, - serializeExit: () => serializeExit, - serialize: () => serialize, - serializableSchema: () => serializableSchema, - requiredToOptional: () => requiredToOptional, - required: () => required2, - rename: () => rename2, - propertySignature: () => propertySignature, - positiveBigInt: () => positiveBigInt, - positiveBigDecimal: () => positiveBigDecimal, - positive: () => positive, - pluck: () => pluck, - pickLiteral: () => pickLiteral, - pick: () => pick4, - pattern: () => pattern, - partialWith: () => partialWith, - partial: () => partial2, - parseNumber: () => parseNumber, - parseJson: () => parseJson, - optionalWith: () => optionalWith, - optionalToRequired: () => optionalToRequired, - optionalToOptional: () => optionalToOptional, - optionalElement: () => optionalElement, - optional: () => optional, - omit: () => omit4, - nonPositiveBigInt: () => nonPositiveBigInt, - nonPositiveBigDecimal: () => nonPositiveBigDecimal, - nonPositive: () => nonPositive, - nonNegativeBigInt: () => nonNegativeBigInt, - nonNegativeBigDecimal: () => nonNegativeBigDecimal, - nonNegative: () => nonNegative, - nonNaN: () => nonNaN, - nonEmptyString: () => nonEmptyString2, - negativeBigInt: () => negativeBigInt, - negativeBigDecimal: () => negativeBigDecimal, - negative: () => negative, - mutable: () => mutable2, - multipleOf: () => multipleOf, - minLength: () => minLength, - minItems: () => minItems, - maxLength: () => maxLength, - maxItems: () => maxItems, - makePropertySignature: () => makePropertySignature, - make: () => make43, - lowercased: () => lowercased, - lessThanOrEqualToDuration: () => lessThanOrEqualToDuration, - lessThanOrEqualToDate: () => lessThanOrEqualToDate, - lessThanOrEqualToBigInt: () => lessThanOrEqualToBigInt, - lessThanOrEqualToBigDecimal: () => lessThanOrEqualToBigDecimal, - lessThanOrEqualTo: () => lessThanOrEqualTo5, - lessThanDuration: () => lessThanDuration, - lessThanDate: () => lessThanDate, - lessThanBigInt: () => lessThanBigInt, - lessThanBigDecimal: () => lessThanBigDecimal, - lessThan: () => lessThan9, - length: () => length2, - keyof: () => keyof2, - itemsCount: () => itemsCount, - isSchema: () => isSchema, - isPropertySignature: () => isPropertySignature, - is: () => is, - int: () => int, - instanceOf: () => instanceOf, - includes: () => includes, - headOrElse: () => headOrElse, - headNonEmpty: () => headNonEmpty3, - head: () => head5, - greaterThanOrEqualToDuration: () => greaterThanOrEqualToDuration, - greaterThanOrEqualToDate: () => greaterThanOrEqualToDate, - greaterThanOrEqualToBigInt: () => greaterThanOrEqualToBigInt, - greaterThanOrEqualToBigDecimal: () => greaterThanOrEqualToBigDecimal, - greaterThanOrEqualTo: () => greaterThanOrEqualTo5, - greaterThanDuration: () => greaterThanDuration, - greaterThanDate: () => greaterThanDate, - greaterThanBigInt: () => greaterThanBigInt, - greaterThanBigDecimal: () => greaterThanBigDecimal, - greaterThan: () => greaterThan6, - getNumberIndexedAccess: () => getNumberIndexedAccess2, - getClassTag: () => getClassTag, - fromKey: () => fromKey, - fromBrand: () => fromBrand, - format: () => format6, - finite: () => finite, - filterEffect: () => filterEffect, - filter: () => filter8, - failureSchema: () => failureSchema, - extend: () => extend2, - exitSchema: () => exitSchema, - equivalence: () => equivalence2, - endsWith: () => endsWith, - encodedSchema: () => encodedSchema, - encodedBoundSchema: () => encodedBoundSchema, - encodeUnknownSync: () => encodeUnknownSync, - encodeUnknownPromise: () => encodeUnknownPromise, - encodeUnknownOption: () => encodeUnknownOption, - encodeUnknownEither: () => encodeUnknownEither2, - encodeUnknown: () => encodeUnknown2, - encodeSync: () => encodeSync, - encodePromise: () => encodePromise, - encodeOption: () => encodeOption, - encodeEither: () => encodeEither, - encode: () => encode4, - element: () => element, - deserializeSuccess: () => deserializeSuccess, - deserializeFailure: () => deserializeFailure, - deserializeExit: () => deserializeExit, - deserialize: () => deserialize, - decodeUnknownSync: () => decodeUnknownSync, - decodeUnknownPromise: () => decodeUnknownPromise, - decodeUnknownOption: () => decodeUnknownOption, - decodeUnknownEither: () => decodeUnknownEither2, - decodeUnknown: () => decodeUnknown2, - decodeSync: () => decodeSync, - decodePromise: () => decodePromise, - decodeOption: () => decodeOption, - decodeEither: () => decodeEither, - decode: () => decode5, - declare: () => declare, - compose: () => compose2, - clampDuration: () => clampDuration, - clampBigInt: () => clampBigInt, - clampBigDecimal: () => clampBigDecimal, - clamp: () => clamp8, - capitalized: () => capitalized, - brand: () => brand, - betweenDuration: () => betweenDuration, - betweenDate: () => betweenDate, - betweenBigInt: () => betweenBigInt, - betweenBigDecimal: () => betweenBigDecimal, - between: () => between5, - attachPropertySignature: () => attachPropertySignature, - asserts: () => asserts, - asWithResult: () => asWithResult, - asSerializableWithResult: () => asSerializableWithResult, - asSerializable: () => asSerializable, - asSchema: () => asSchema, - annotations: () => annotations2, - Void: () => Void, - ValidDateSchemaId: () => ValidDateSchemaId, - ValidDateFromSelf: () => ValidDateFromSelf, - UppercasedSchemaId: () => UppercasedSchemaId, - Uppercased: () => Uppercased, - Uppercase: () => Uppercase, - Unknown: () => Unknown, - UniqueSymbolFromSelf: () => UniqueSymbolFromSelf, - Union: () => Union2, - UndefinedOr: () => UndefinedOr, - Undefined: () => Undefined, - UncapitalizedSchemaId: () => UncapitalizedSchemaId, - Uncapitalized: () => Uncapitalized, - Uncapitalize: () => Uncapitalize, - Uint8ArrayFromSelf: () => Uint8ArrayFromSelf, - Uint8ArrayFromHex: () => Uint8ArrayFromHex, - Uint8ArrayFromBase64Url: () => Uint8ArrayFromBase64Url, - Uint8ArrayFromBase64: () => Uint8ArrayFromBase64, - Uint8Array: () => Uint8Array$, - Uint8: () => Uint8, - UUIDSchemaId: () => UUIDSchemaId, - UUID: () => UUID, - URLFromSelf: () => URLFromSelf, - URL: () => URL$, - ULIDSchemaId: () => ULIDSchemaId, - ULID: () => ULID, - TypeId: () => TypeId18, - Tuple: () => Tuple, - TrimmedSchemaId: () => TrimmedSchemaId, - Trimmed: () => Trimmed, - Trim: () => Trim, - ToPropertySignature: () => ToPropertySignature, - TimeZoneOffsetFromSelf: () => TimeZoneOffsetFromSelf, - TimeZoneOffset: () => TimeZoneOffset, - TimeZoneNamedFromSelf: () => TimeZoneNamedFromSelf, - TimeZoneNamed: () => TimeZoneNamed, - TimeZoneFromSelf: () => TimeZoneFromSelf, - TimeZone: () => TimeZone, - TemplateLiteralParser: () => TemplateLiteralParser, - TemplateLiteral: () => TemplateLiteral2, - TaggedStruct: () => TaggedStruct, - TaggedRequest: () => TaggedRequest, - TaggedError: () => TaggedError2, - TaggedClass: () => TaggedClass3, - SymbolFromSelf: () => SymbolFromSelf, - Symbol: () => Symbol$, - Struct: () => Struct, - StringFromUriComponent: () => StringFromUriComponent, - StringFromHex: () => StringFromHex, - StringFromBase64Url: () => StringFromBase64Url, - StringFromBase64: () => StringFromBase64, - String: () => String$, - StartsWithSchemaId: () => StartsWithSchemaId, - SortedSetFromSelf: () => SortedSetFromSelf, - SortedSet: () => SortedSet, - SetFromSelf: () => SetFromSelf, - Set: () => set6, - RefineSchemaId: () => RefineSchemaId, - RedactedFromSelf: () => RedactedFromSelf, - Redacted: () => Redacted, - Record: () => Record, - ReadonlySetFromSelf: () => ReadonlySetFromSelf, - ReadonlySet: () => ReadonlySet, - ReadonlyMapFromSelf: () => ReadonlyMapFromSelf, - ReadonlyMapFromRecord: () => ReadonlyMapFromRecord, - ReadonlyMap: () => ReadonlyMap, - PropertySignatureTypeId: () => PropertySignatureTypeId, - PropertySignatureTransformation: () => PropertySignatureTransformation2, - PropertySignatureDeclaration: () => PropertySignatureDeclaration, - PropertyKey: () => PropertyKey$, - PositiveBigIntFromSelf: () => PositiveBigIntFromSelf, - PositiveBigInt: () => PositiveBigInt, - PositiveBigDecimalSchemaId: () => PositiveBigDecimalSchemaId, - PositiveBigDecimalFromSelf: () => PositiveBigDecimalFromSelf, - Positive: () => Positive, - PatternSchemaId: () => PatternSchemaId, - OptionFromUndefinedOr: () => OptionFromUndefinedOr, - OptionFromSelf: () => OptionFromSelf, - OptionFromNullishOr: () => OptionFromNullishOr, - OptionFromNullOr: () => OptionFromNullOr, - OptionFromNonEmptyTrimmedString: () => OptionFromNonEmptyTrimmedString, - Option: () => Option, - Object: () => Object$, - NumberFromString: () => NumberFromString, - Number: () => Number$, - NullishOr: () => NullishOr, - NullOr: () => NullOr, - Null: () => Null, - Not: () => Not, - NonPositiveBigIntFromSelf: () => NonPositiveBigIntFromSelf, - NonPositiveBigInt: () => NonPositiveBigInt, - NonPositiveBigDecimalSchemaId: () => NonPositiveBigDecimalSchemaId, - NonPositiveBigDecimalFromSelf: () => NonPositiveBigDecimalFromSelf, - NonPositive: () => NonPositive, - NonNegativeInt: () => NonNegativeInt, - NonNegativeBigIntFromSelf: () => NonNegativeBigIntFromSelf, - NonNegativeBigInt: () => NonNegativeBigInt, - NonNegativeBigDecimalSchemaId: () => NonNegativeBigDecimalSchemaId, - NonNegativeBigDecimalFromSelf: () => NonNegativeBigDecimalFromSelf, - NonNegative: () => NonNegative, - NonNaNSchemaId: () => NonNaNSchemaId2, - NonNaN: () => NonNaN, - NonEmptyTrimmedString: () => NonEmptyTrimmedString, - NonEmptyString: () => NonEmptyString, - NonEmptyChunkFromSelf: () => NonEmptyChunkFromSelf, - NonEmptyChunk: () => NonEmptyChunk, - NonEmptyArrayEnsure: () => NonEmptyArrayEnsure, - NonEmptyArray: () => NonEmptyArray, - Never: () => Never, - NegativeBigIntFromSelf: () => NegativeBigIntFromSelf, - NegativeBigInt: () => NegativeBigInt, - NegativeBigDecimalSchemaId: () => NegativeBigDecimalSchemaId, - NegativeBigDecimalFromSelf: () => NegativeBigDecimalFromSelf, - Negative: () => Negative, - MultipleOfSchemaId: () => MultipleOfSchemaId, - MinLengthSchemaId: () => MinLengthSchemaId2, - MinItemsSchemaId: () => MinItemsSchemaId2, - MaxLengthSchemaId: () => MaxLengthSchemaId2, - MaxItemsSchemaId: () => MaxItemsSchemaId2, - MapFromSelf: () => MapFromSelf, - MapFromRecord: () => MapFromRecord, - Map: () => map14, - LowercasedSchemaId: () => LowercasedSchemaId, - Lowercased: () => Lowercased, - Lowercase: () => Lowercase, - Literal: () => Literal2, - ListFromSelf: () => ListFromSelf, - List: () => List, - LessThanSchemaId: () => LessThanSchemaId2, - LessThanOrEqualToSchemaId: () => LessThanOrEqualToSchemaId2, - LessThanOrEqualToDurationSchemaId: () => LessThanOrEqualToDurationSchemaId, - LessThanOrEqualToDateSchemaId: () => LessThanOrEqualToDateSchemaId, - LessThanOrEqualToBigIntSchemaId: () => LessThanOrEqualToBigIntSchemaId2, - LessThanOrEqualToBigDecimalSchemaId: () => LessThanOrEqualToBigDecimalSchemaId, - LessThanDurationSchemaId: () => LessThanDurationSchemaId, - LessThanDateSchemaId: () => LessThanDateSchemaId, - LessThanBigIntSchemaId: () => LessThanBigIntSchemaId2, - LessThanBigDecimalSchemaId: () => LessThanBigDecimalSchemaId, - LengthSchemaId: () => LengthSchemaId2, - JsonNumberSchemaId: () => JsonNumberSchemaId2, - JsonNumber: () => JsonNumber, - ItemsCountSchemaId: () => ItemsCountSchemaId2, - IntSchemaId: () => IntSchemaId2, - Int: () => Int, - InstanceOfSchemaId: () => InstanceOfSchemaId, - IncludesSchemaId: () => IncludesSchemaId, - HashSetFromSelf: () => HashSetFromSelf, - HashSet: () => HashSet, - HashMapFromSelf: () => HashMapFromSelf, - HashMap: () => HashMap, - GreaterThanSchemaId: () => GreaterThanSchemaId2, - GreaterThanOrEqualToSchemaId: () => GreaterThanOrEqualToSchemaId2, - GreaterThanOrEqualToDurationSchemaId: () => GreaterThanOrEqualToDurationSchemaId, - GreaterThanOrEqualToDateSchemaId: () => GreaterThanOrEqualToDateSchemaId, - GreaterThanOrEqualToBigIntSchemaId: () => GreaterThanOrEqualToBigIntSchemaId2, - GreaterThanOrEqualToBigDecimalSchemaId: () => GreaterThanOrEqualToBigDecimalSchemaId, - GreaterThanDurationSchemaId: () => GreaterThanDurationSchemaId, - GreaterThanDateSchemaId: () => GreaterThanDateSchemaId, - GreaterThanBigIntSchemaId: () => GreaterThanBigIntSchemaId, - GreaterThanBigDecimalSchemaId: () => GreaterThanBigDecimalSchemaId, - FromPropertySignature: () => FromPropertySignature, - FiniteSchemaId: () => FiniteSchemaId2, - Finite: () => Finite, - FiberIdFromSelf: () => FiberIdFromSelf, - FiberId: () => FiberId, - ExitFromSelf: () => ExitFromSelf, - Exit: () => Exit, - Enums: () => Enums2, - EndsWithSchemaId: () => EndsWithSchemaId, - EitherFromUnion: () => EitherFromUnion, - EitherFromSelf: () => EitherFromSelf, - Either: () => Either, - DurationFromSelf: () => DurationFromSelf, - DurationFromNanos: () => DurationFromNanos, - DurationFromMillis: () => DurationFromMillis, - Duration: () => Duration, - Defect: () => Defect, - DateTimeZonedFromSelf: () => DateTimeZonedFromSelf, - DateTimeZoned: () => DateTimeZoned, - DateTimeUtcFromSelf: () => DateTimeUtcFromSelf, - DateTimeUtcFromNumber: () => DateTimeUtcFromNumber, - DateTimeUtcFromDate: () => DateTimeUtcFromDate, - DateTimeUtc: () => DateTimeUtc, - DateFromString: () => DateFromString, - DateFromSelfSchemaId: () => DateFromSelfSchemaId2, - DateFromSelf: () => DateFromSelf, - DateFromNumber: () => DateFromNumber, - Date: () => Date$, - DataFromSelf: () => DataFromSelf, - Data: () => Data, - Config: () => Config, - Class: () => Class5, - ChunkFromSelf: () => ChunkFromSelf, - Chunk: () => Chunk, - Char: () => Char, - CauseFromSelf: () => CauseFromSelf, - Cause: () => Cause, - CapitalizedSchemaId: () => CapitalizedSchemaId, - Capitalized: () => Capitalized, - Capitalize: () => Capitalize, - BrandSchemaId: () => BrandSchemaId, - BooleanFromUnknown: () => BooleanFromUnknown, - BooleanFromString: () => BooleanFromString, - Boolean: () => Boolean$, - BigIntFromSelf: () => BigIntFromSelf, - BigIntFromNumber: () => BigIntFromNumber, - BigInt: () => BigInt$, - BigDecimalFromSelf: () => BigDecimalFromSelf, - BigDecimalFromNumber: () => BigDecimalFromNumber, - BigDecimal: () => BigDecimal, - BetweenSchemaId: () => BetweenSchemaId2, - BetweenDurationSchemaId: () => BetweenDurationSchemaId, - BetweenDateSchemaId: () => BetweenDateSchemaId, - BetweenBigIntSchemaId: () => BetweenBigIntSchemaId, - BetweenBigDecimalSchemaId: () => BetweenBigDecimalSchemaId, - ArrayFormatterIssue: () => ArrayFormatterIssue, - ArrayEnsure: () => ArrayEnsure, - Array: () => Array$, - Any: () => Any + const v = f(none2()); + if (isNone2(v)) + return this; + ++size.value; + return mergeLeaves(edit, shift, this.hash, this, hash2, new LeafNode(edit, hash2, key, v)); + } + updateCollisionList(mutate, edit, hash2, list, f, key, size) { + const len = list.length; + for (let i = 0;i < len; ++i) { + const child = list[i]; + if ("key" in child && equals(key, child.key)) { + const value = child.value; + const newValue2 = f(value); + if (newValue2 === value) + return list; + if (isNone2(newValue2)) { + --size.value; + return arraySpliceOut(mutate, i, list); + } + return arrayUpdate(mutate, i, new LeafNode(edit, hash2, key, newValue2), list); + } + } + const newValue = f(none2()); + if (isNone2(newValue)) + return list; + ++size.value; + return arrayUpdate(mutate, len, new LeafNode(edit, hash2, key, newValue), list); + } +} + +class IndexedNode { + edit; + mask; + children; + _tag = "IndexedNode"; + constructor(edit, mask, children) { + this.edit = edit; + this.mask = mask; + this.children = children; + } + modify(edit, shift, f, hash2, key, size) { + const mask = this.mask; + const children = this.children; + const frag = hashFragment(shift, hash2); + const bit = toBitmap(frag); + const indx = fromBitmap(mask, bit); + const exists2 = mask & bit; + const canEdit = canEditNode(this, edit); + if (!exists2) { + const _newChild = new EmptyNode().modify(edit, shift + SIZE, f, hash2, key, size); + if (!_newChild) + return this; + return children.length >= MAX_INDEX_NODE ? expand(edit, frag, _newChild, mask, children) : new IndexedNode(edit, mask | bit, arraySpliceIn(canEdit, indx, _newChild, children)); + } + const current = children[indx]; + const child = current.modify(edit, shift + SIZE, f, hash2, key, size); + if (current === child) + return this; + let bitmap = mask; + let newChildren; + if (isEmptyNode(child)) { + bitmap &= ~bit; + if (!bitmap) + return new EmptyNode; + if (children.length <= 2 && isLeafNode(children[indx ^ 1])) { + return children[indx ^ 1]; + } + newChildren = arraySpliceOut(canEdit, indx, children); + } else { + newChildren = arrayUpdate(canEdit, indx, child, children); + } + if (canEdit) { + this.mask = bitmap; + this.children = newChildren; + return this; + } + return new IndexedNode(edit, bitmap, newChildren); + } +} + +class ArrayNode { + edit; + size; + children; + _tag = "ArrayNode"; + constructor(edit, size, children) { + this.edit = edit; + this.size = size; + this.children = children; + } + modify(edit, shift, f, hash2, key, size) { + let count = this.size; + const children = this.children; + const frag = hashFragment(shift, hash2); + const child = children[frag]; + const newChild = (child || new EmptyNode).modify(edit, shift + SIZE, f, hash2, key, size); + if (child === newChild) + return this; + const canEdit = canEditNode(this, edit); + let newChildren; + if (isEmptyNode(child) && !isEmptyNode(newChild)) { + ++count; + newChildren = arrayUpdate(canEdit, frag, newChild, children); + } else if (!isEmptyNode(child) && isEmptyNode(newChild)) { + --count; + if (count <= MIN_ARRAY_NODE) { + return pack(edit, count, frag, children); + } + newChildren = arrayUpdate(canEdit, frag, new EmptyNode, children); + } else { + newChildren = arrayUpdate(canEdit, frag, newChild, children); + } + if (canEdit) { + this.size = count; + this.children = newChildren; + return this; + } + return new ArrayNode(edit, count, newChildren); + } +} +function pack(edit, count, removed, elements) { + const children = new Array(count - 1); + let g = 0; + let bitmap = 0; + for (let i = 0, len = elements.length;i < len; ++i) { + if (i !== removed) { + const elem = elements[i]; + if (elem && !isEmptyNode(elem)) { + children[g++] = elem; + bitmap |= 1 << i; + } + } + } + return new IndexedNode(edit, bitmap, children); +} +function expand(edit, frag, child, bitmap, subNodes) { + const arr = []; + let bit = bitmap; + let count = 0; + for (let i = 0;bit; ++i) { + if (bit & 1) + arr[i] = subNodes[count++]; + bit >>>= 1; + } + arr[frag] = child; + return new ArrayNode(edit, count + 1, arr); +} +function mergeLeavesInner(edit, shift, h1, n1, h2, n2) { + if (h1 === h2) + return new CollisionNode(edit, h1, [n2, n1]); + const subH1 = hashFragment(shift, h1); + const subH2 = hashFragment(shift, h2); + if (subH1 === subH2) { + return (child) => new IndexedNode(edit, toBitmap(subH1) | toBitmap(subH2), [child]); + } else { + const children = subH1 < subH2 ? [n1, n2] : [n2, n1]; + return new IndexedNode(edit, toBitmap(subH1) | toBitmap(subH2), children); + } +} +function mergeLeaves(edit, shift, h1, n1, h2, n2) { + let stack = undefined; + let currentShift = shift; + while (true) { + const res = mergeLeavesInner(edit, currentShift, h1, n1, h2, n2); + if (typeof res === "function") { + stack = make9(res, stack); + currentShift = currentShift + SIZE; + } else { + let final = res; + while (stack != null) { + final = stack.value(final); + stack = stack.previous; + } + return final; + } + } +} + +// node_modules/effect/dist/esm/internal/hashMap.js +var HashMapSymbolKey = "effect/HashMap"; +var HashMapTypeId = /* @__PURE__ */ Symbol.for(HashMapSymbolKey); +var HashMapProto = { + [HashMapTypeId]: HashMapTypeId, + [Symbol.iterator]() { + return new HashMapIterator(this, (k, v) => [k, v]); + }, + [symbol]() { + let hash2 = hash(HashMapSymbolKey); + for (const item of this) { + hash2 ^= pipe(hash(item[0]), combine(hash(item[1]))); + } + return cached(this, hash2); + }, + [symbol2](that) { + if (isHashMap(that)) { + if (that._size !== this._size) { + return false; + } + for (const item of this) { + const elem = pipe(that, getHash(item[0], hash(item[0]))); + if (isNone2(elem)) { + return false; + } else { + if (!equals(item[1], elem.value)) { + return false; + } + } + } + return true; + } + return false; + }, + toString() { + return format(this.toJSON()); + }, + toJSON() { + return { + _id: "HashMap", + values: Array.from(this).map(toJSON) + }; + }, + [NodeInspectSymbol]() { + return this.toJSON(); + }, + pipe() { + return pipeArguments(this, arguments); + } +}; +var makeImpl = (editable, edit, root, size) => { + const map4 = Object.create(HashMapProto); + map4._editable = editable; + map4._edit = edit; + map4._root = root; + map4._size = size; + return map4; +}; + +class HashMapIterator { + map; + f; + v; + constructor(map4, f) { + this.map = map4; + this.f = f; + this.v = visitLazy(this.map._root, this.f, undefined); + } + next() { + if (isNone2(this.v)) { + return { + done: true, + value: undefined + }; + } + const v0 = this.v.value; + this.v = applyCont(v0.cont); + return { + done: false, + value: v0.value + }; + } + [Symbol.iterator]() { + return new HashMapIterator(this.map, this.f); + } +} +var applyCont = (cont) => cont ? visitLazyChildren(cont[0], cont[1], cont[2], cont[3], cont[4]) : none2(); +var visitLazy = (node, f, cont = undefined) => { + switch (node._tag) { + case "LeafNode": { + if (isSome2(node.value)) { + return some2({ + value: f(node.key, node.value.value), + cont + }); + } + return applyCont(cont); + } + case "CollisionNode": + case "ArrayNode": + case "IndexedNode": { + const children = node.children; + return visitLazyChildren(children.length, children, 0, f, cont); + } + default: { + return applyCont(cont); + } + } +}; +var visitLazyChildren = (len, children, i, f, cont) => { + while (i < len) { + const child = children[i++]; + if (child && !isEmptyNode(child)) { + return visitLazy(child, f, [len, children, i, f, cont]); + } + } + return applyCont(cont); +}; +var _empty3 = /* @__PURE__ */ makeImpl(false, 0, /* @__PURE__ */ new EmptyNode, 0); +var empty5 = () => _empty3; +var fromIterable3 = (entries) => { + const map4 = beginMutation(empty5()); + for (const entry of entries) { + set(map4, entry[0], entry[1]); + } + return endMutation(map4); +}; +var isHashMap = (u) => hasProperty(u, HashMapTypeId); +var isEmpty2 = (self) => self && isEmptyNode(self._root); +var get5 = /* @__PURE__ */ dual(2, (self, key) => getHash(self, key, hash(key))); +var getHash = /* @__PURE__ */ dual(3, (self, key, hash2) => { + let node = self._root; + let shift = 0; + while (true) { + switch (node._tag) { + case "LeafNode": { + return equals(key, node.key) ? node.value : none2(); + } + case "CollisionNode": { + if (hash2 === node.hash) { + const children = node.children; + for (let i = 0, len = children.length;i < len; ++i) { + const child = children[i]; + if ("key" in child && equals(key, child.key)) { + return child.value; + } + } + } + return none2(); + } + case "IndexedNode": { + const frag = hashFragment(shift, hash2); + const bit = toBitmap(frag); + if (node.mask & bit) { + node = node.children[fromBitmap(node.mask, bit)]; + shift += SIZE; + break; + } + return none2(); + } + case "ArrayNode": { + node = node.children[hashFragment(shift, hash2)]; + if (node) { + shift += SIZE; + break; + } + return none2(); + } + default: + return none2(); + } + } +}); +var has = /* @__PURE__ */ dual(2, (self, key) => isSome2(getHash(self, key, hash(key)))); +var set = /* @__PURE__ */ dual(3, (self, key, value) => modifyAt(self, key, () => some2(value))); +var setTree = /* @__PURE__ */ dual(3, (self, newRoot, newSize) => { + if (self._editable) { + self._root = newRoot; + self._size = newSize; + return self; + } + return newRoot === self._root ? self : makeImpl(self._editable, self._edit, newRoot, newSize); +}); +var keys = (self) => new HashMapIterator(self, (key) => key); +var size = (self) => self._size; +var beginMutation = (self) => makeImpl(true, self._edit + 1, self._root, self._size); +var endMutation = (self) => { + self._editable = false; + return self; +}; +var mutate = /* @__PURE__ */ dual(2, (self, f) => { + const transient = beginMutation(self); + f(transient); + return endMutation(transient); +}); +var modifyAt = /* @__PURE__ */ dual(3, (self, key, f) => modifyHash(self, key, hash(key), f)); +var modifyHash = /* @__PURE__ */ dual(4, (self, key, hash2, f) => { + const size2 = { + value: self._size + }; + const newRoot = self._root.modify(self._editable ? self._edit : NaN, 0, f, hash2, key, size2); + return pipe(self, setTree(newRoot, size2.value)); +}); +var remove2 = /* @__PURE__ */ dual(2, (self, key) => modifyAt(self, key, none2)); +var map4 = /* @__PURE__ */ dual(2, (self, f) => reduce2(self, empty5(), (map5, value, key) => set(map5, key, f(value, key)))); +var forEach = /* @__PURE__ */ dual(2, (self, f) => reduce2(self, undefined, (_, value, key) => f(value, key))); +var reduce2 = /* @__PURE__ */ dual(3, (self, zero3, f) => { + const root = self._root; + if (root._tag === "LeafNode") { + return isSome2(root.value) ? f(zero3, root.value.value, root.key) : zero3; + } + if (root._tag === "EmptyNode") { + return zero3; + } + const toVisit = [root.children]; + let children; + while (children = toVisit.pop()) { + for (let i = 0, len = children.length;i < len; ) { + const child = children[i++]; + if (child && !isEmptyNode(child)) { + if (child._tag === "LeafNode") { + if (isSome2(child.value)) { + zero3 = f(zero3, child.value.value, child.key); + } + } else { + toVisit.push(child.children); + } + } + } + } + return zero3; +}); + +// node_modules/effect/dist/esm/internal/hashSet.js +var HashSetSymbolKey = "effect/HashSet"; +var HashSetTypeId = /* @__PURE__ */ Symbol.for(HashSetSymbolKey); +var HashSetProto = { + [HashSetTypeId]: HashSetTypeId, + [Symbol.iterator]() { + return keys(this._keyMap); + }, + [symbol]() { + return cached(this, combine(hash(this._keyMap))(hash(HashSetSymbolKey))); + }, + [symbol2](that) { + if (isHashSet(that)) { + return size(this._keyMap) === size(that._keyMap) && equals(this._keyMap, that._keyMap); + } + return false; + }, + toString() { + return format(this.toJSON()); + }, + toJSON() { + return { + _id: "HashSet", + values: Array.from(this).map(toJSON) + }; + }, + [NodeInspectSymbol]() { + return this.toJSON(); + }, + pipe() { + return pipeArguments(this, arguments); + } +}; +var makeImpl2 = (keyMap) => { + const set2 = Object.create(HashSetProto); + set2._keyMap = keyMap; + return set2; +}; +var isHashSet = (u) => hasProperty(u, HashSetTypeId); +var _empty4 = /* @__PURE__ */ makeImpl2(/* @__PURE__ */ empty5()); +var empty6 = () => _empty4; +var fromIterable4 = (elements) => { + const set2 = beginMutation2(empty6()); + for (const value of elements) { + add3(set2, value); + } + return endMutation2(set2); +}; +var make10 = (...elements) => { + const set2 = beginMutation2(empty6()); + for (const value of elements) { + add3(set2, value); + } + return endMutation2(set2); +}; +var has2 = /* @__PURE__ */ dual(2, (self, value) => has(self._keyMap, value)); +var size2 = (self) => size(self._keyMap); +var beginMutation2 = (self) => makeImpl2(beginMutation(self._keyMap)); +var endMutation2 = (self) => { + self._keyMap._editable = false; + return self; +}; +var mutate2 = /* @__PURE__ */ dual(2, (self, f) => { + const transient = beginMutation2(self); + f(transient); + return endMutation2(transient); +}); +var add3 = /* @__PURE__ */ dual(2, (self, value) => self._keyMap._editable ? (set(value, true)(self._keyMap), self) : makeImpl2(set(value, true)(self._keyMap))); +var remove3 = /* @__PURE__ */ dual(2, (self, value) => self._keyMap._editable ? (remove2(value)(self._keyMap), self) : makeImpl2(remove2(value)(self._keyMap))); +var difference2 = /* @__PURE__ */ dual(2, (self, that) => mutate2(self, (set2) => { + for (const value of that) { + remove3(set2, value); + } +})); +var union2 = /* @__PURE__ */ dual(2, (self, that) => mutate2(empty6(), (set2) => { + forEach2(self, (value) => add3(set2, value)); + for (const value of that) { + add3(set2, value); + } +})); +var forEach2 = /* @__PURE__ */ dual(2, (self, f) => forEach(self._keyMap, (_, k) => f(k))); +var reduce3 = /* @__PURE__ */ dual(3, (self, zero3, f) => reduce2(self._keyMap, zero3, (z, _, a) => f(z, a))); + +// node_modules/effect/dist/esm/HashSet.js +var isHashSet2 = isHashSet; +var empty7 = empty6; +var fromIterable5 = fromIterable4; +var make11 = make10; +var has3 = has2; +var size3 = size2; +var add4 = add3; +var remove4 = remove3; +var difference3 = difference2; +var union3 = union2; +var reduce4 = reduce3; + +// node_modules/effect/dist/esm/MutableRef.js +var TypeId7 = /* @__PURE__ */ Symbol.for("effect/MutableRef"); +var MutableRefProto = { + [TypeId7]: TypeId7, + toString() { + return format(this.toJSON()); + }, + toJSON() { + return { + _id: "MutableRef", + current: toJSON(this.current) + }; + }, + [NodeInspectSymbol]() { + return this.toJSON(); + }, + pipe() { + return pipeArguments(this, arguments); + } +}; +var make12 = (value) => { + const ref = Object.create(MutableRefProto); + ref.current = value; + return ref; +}; +var compareAndSet = /* @__PURE__ */ dual(3, (self, oldValue, newValue) => { + if (equals(oldValue, self.current)) { + self.current = newValue; + return true; + } + return false; +}); +var get6 = (self) => self.current; +var set2 = /* @__PURE__ */ dual(2, (self, value) => { + self.current = value; + return self; +}); + +// node_modules/effect/dist/esm/internal/fiberId.js +var FiberIdSymbolKey = "effect/FiberId"; +var FiberIdTypeId = /* @__PURE__ */ Symbol.for(FiberIdSymbolKey); +var OP_NONE = "None"; +var OP_RUNTIME = "Runtime"; +var OP_COMPOSITE = "Composite"; +var emptyHash = /* @__PURE__ */ string(`${FiberIdSymbolKey}-${OP_NONE}`); + +class None { + [FiberIdTypeId] = FiberIdTypeId; + _tag = OP_NONE; + id = -1; + startTimeMillis = -1; + [symbol]() { + return emptyHash; + } + [symbol2](that) { + return isFiberId(that) && that._tag === OP_NONE; + } + toString() { + return format(this.toJSON()); + } + toJSON() { + return { + _id: "FiberId", + _tag: this._tag + }; + } + [NodeInspectSymbol]() { + return this.toJSON(); + } +} + +class Runtime { + id; + startTimeMillis; + [FiberIdTypeId] = FiberIdTypeId; + _tag = OP_RUNTIME; + constructor(id, startTimeMillis) { + this.id = id; + this.startTimeMillis = startTimeMillis; + } + [symbol]() { + return cached(this, string(`${FiberIdSymbolKey}-${this._tag}-${this.id}-${this.startTimeMillis}`)); + } + [symbol2](that) { + return isFiberId(that) && that._tag === OP_RUNTIME && this.id === that.id && this.startTimeMillis === that.startTimeMillis; + } + toString() { + return format(this.toJSON()); + } + toJSON() { + return { + _id: "FiberId", + _tag: this._tag, + id: this.id, + startTimeMillis: this.startTimeMillis + }; + } + [NodeInspectSymbol]() { + return this.toJSON(); + } +} + +class Composite { + left; + right; + [FiberIdTypeId] = FiberIdTypeId; + _tag = OP_COMPOSITE; + constructor(left3, right3) { + this.left = left3; + this.right = right3; + } + _hash; + [symbol]() { + return pipe(string(`${FiberIdSymbolKey}-${this._tag}`), combine(hash(this.left)), combine(hash(this.right)), cached(this)); + } + [symbol2](that) { + return isFiberId(that) && that._tag === OP_COMPOSITE && equals(this.left, that.left) && equals(this.right, that.right); + } + toString() { + return format(this.toJSON()); + } + toJSON() { + return { + _id: "FiberId", + _tag: this._tag, + left: toJSON(this.left), + right: toJSON(this.right) + }; + } + [NodeInspectSymbol]() { + return this.toJSON(); + } +} +var none3 = /* @__PURE__ */ new None; +var runtime = (id, startTimeMillis) => { + return new Runtime(id, startTimeMillis); +}; +var composite = (left3, right3) => { + return new Composite(left3, right3); +}; +var isFiberId = (self) => hasProperty(self, FiberIdTypeId); +var combine2 = /* @__PURE__ */ dual(2, (self, that) => { + if (self._tag === OP_NONE) { + return that; + } + if (that._tag === OP_NONE) { + return self; + } + return new Composite(self, that); +}); +var ids = (self) => { + switch (self._tag) { + case OP_NONE: { + return empty7(); + } + case OP_RUNTIME: { + return make11(self.id); + } + case OP_COMPOSITE: { + return pipe(ids(self.left), union3(ids(self.right))); + } + } +}; +var _fiberCounter = /* @__PURE__ */ globalValue(/* @__PURE__ */ Symbol.for("effect/Fiber/Id/_fiberCounter"), () => make12(0)); +var threadName = (self) => { + const identifiers = Array.from(ids(self)).map((n) => `#${n}`).join(","); + return identifiers; +}; +var unsafeMake = () => { + const id = get6(_fiberCounter); + pipe(_fiberCounter, set2(id + 1)); + return new Runtime(id, Date.now()); +}; + +// node_modules/effect/dist/esm/FiberId.js +var none4 = none3; +var runtime2 = runtime; +var composite2 = composite; +var isFiberId2 = isFiberId; +var combine3 = combine2; +var threadName2 = threadName; +var unsafeMake2 = unsafeMake; + +// node_modules/effect/dist/esm/HashMap.js +var isHashMap2 = isHashMap; +var empty8 = empty5; +var fromIterable6 = fromIterable3; +var isEmpty3 = isEmpty2; +var get7 = get5; +var set3 = set; +var keys2 = keys; +var mutate3 = mutate; +var modifyAt2 = modifyAt; +var map6 = map4; +var forEach3 = forEach; +var reduce5 = reduce2; + +// node_modules/effect/dist/esm/List.js +var TypeId8 = /* @__PURE__ */ Symbol.for("effect/List"); +var toArray2 = (self) => fromIterable(self); +var getEquivalence5 = (isEquivalent) => mapInput(getEquivalence3(isEquivalent), toArray2); +var _equivalence4 = /* @__PURE__ */ getEquivalence5(equals); +var ConsProto = { + [TypeId8]: TypeId8, + _tag: "Cons", + toString() { + return format(this.toJSON()); + }, + toJSON() { + return { + _id: "List", + _tag: "Cons", + values: toArray2(this).map(toJSON) + }; + }, + [NodeInspectSymbol]() { + return this.toJSON(); + }, + [symbol2](that) { + return isList(that) && this._tag === that._tag && _equivalence4(this, that); + }, + [symbol]() { + return cached(this, array2(toArray2(this))); + }, + [Symbol.iterator]() { + let done = false; + let self = this; + return { + next() { + if (done) { + return this.return(); + } + if (self._tag === "Nil") { + done = true; + return this.return(); + } + const value = self.head; + self = self.tail; + return { + done, + value + }; + }, + return(value) { + if (!done) { + done = true; + } + return { + done: true, + value + }; + } + }; + }, + pipe() { + return pipeArguments(this, arguments); + } +}; +var makeCons = (head3, tail) => { + const cons = Object.create(ConsProto); + cons.head = head3; + cons.tail = tail; + return cons; +}; +var NilHash = /* @__PURE__ */ string("Nil"); +var NilProto = { + [TypeId8]: TypeId8, + _tag: "Nil", + toString() { + return format(this.toJSON()); + }, + toJSON() { + return { + _id: "List", + _tag: "Nil" + }; + }, + [NodeInspectSymbol]() { + return this.toJSON(); + }, + [symbol]() { + return NilHash; + }, + [symbol2](that) { + return isList(that) && this._tag === that._tag; + }, + [Symbol.iterator]() { + return { + next() { + return { + done: true, + value: undefined + }; + } + }; + }, + pipe() { + return pipeArguments(this, arguments); + } +}; +var _Nil = /* @__PURE__ */ Object.create(NilProto); +var isList = (u) => hasProperty(u, TypeId8); +var isNil = (self) => self._tag === "Nil"; +var isCons = (self) => self._tag === "Cons"; +var nil = () => _Nil; +var cons = (head3, tail) => makeCons(head3, tail); +var empty9 = nil; +var of3 = (value) => makeCons(value, _Nil); +var fromIterable7 = (prefix) => { + const iterator = prefix[Symbol.iterator](); + let next; + if ((next = iterator.next()) && !next.done) { + const result = makeCons(next.value, _Nil); + let curr = result; + while ((next = iterator.next()) && !next.done) { + const temp = makeCons(next.value, _Nil); + curr.tail = temp; + curr = temp; + } + return result; + } else { + return _Nil; + } +}; +var appendAll3 = /* @__PURE__ */ dual(2, (self, that) => prependAll(that, self)); +var prepend3 = /* @__PURE__ */ dual(2, (self, element) => cons(element, self)); +var prependAll = /* @__PURE__ */ dual(2, (self, prefix) => { + if (isNil(self)) { + return prefix; + } else if (isNil(prefix)) { + return self; + } else { + const result = makeCons(prefix.head, self); + let curr = result; + let that = prefix.tail; + while (!isNil(that)) { + const temp = makeCons(that.head, self); + curr.tail = temp; + curr = temp; + that = that.tail; + } + return result; + } +}); +var reduce6 = /* @__PURE__ */ dual(3, (self, zero3, f) => { + let acc = zero3; + let these = self; + while (!isNil(these)) { + acc = f(acc, these.head); + these = these.tail; + } + return acc; +}); +var reverse3 = (self) => { + let result = empty9(); + let these = self; + while (!isNil(these)) { + result = prepend3(result, these.head); + these = these.tail; + } + return result; +}; + +// node_modules/effect/dist/esm/internal/data.js +var ArrayProto = /* @__PURE__ */ Object.assign(/* @__PURE__ */ Object.create(Array.prototype), { + [symbol]() { + return cached(this, array2(this)); + }, + [symbol2](that) { + if (Array.isArray(that) && this.length === that.length) { + return this.every((v, i) => equals(v, that[i])); + } else { + return false; + } + } +}); +var Structural = /* @__PURE__ */ function() { + function Structural2(args) { + if (args) { + Object.assign(this, args); + } + } + Structural2.prototype = StructuralPrototype; + return Structural2; +}(); +var struct = (as) => Object.assign(Object.create(StructuralPrototype), as); + +// node_modules/effect/dist/esm/internal/differ/contextPatch.js +var ContextPatchTypeId = /* @__PURE__ */ Symbol.for("effect/DifferContextPatch"); +function variance(a) { + return a; +} +var PatchProto = { + ...Structural.prototype, + [ContextPatchTypeId]: { + _Value: variance, + _Patch: variance + } +}; +var EmptyProto = /* @__PURE__ */ Object.assign(/* @__PURE__ */ Object.create(PatchProto), { + _tag: "Empty" +}); +var _empty5 = /* @__PURE__ */ Object.create(EmptyProto); +var empty10 = () => _empty5; +var AndThenProto = /* @__PURE__ */ Object.assign(/* @__PURE__ */ Object.create(PatchProto), { + _tag: "AndThen" +}); +var makeAndThen = (first, second) => { + const o = Object.create(AndThenProto); + o.first = first; + o.second = second; + return o; +}; +var AddServiceProto = /* @__PURE__ */ Object.assign(/* @__PURE__ */ Object.create(PatchProto), { + _tag: "AddService" +}); +var makeAddService = (key, service) => { + const o = Object.create(AddServiceProto); + o.key = key; + o.service = service; + return o; +}; +var RemoveServiceProto = /* @__PURE__ */ Object.assign(/* @__PURE__ */ Object.create(PatchProto), { + _tag: "RemoveService" +}); +var makeRemoveService = (key) => { + const o = Object.create(RemoveServiceProto); + o.key = key; + return o; +}; +var UpdateServiceProto = /* @__PURE__ */ Object.assign(/* @__PURE__ */ Object.create(PatchProto), { + _tag: "UpdateService" +}); +var makeUpdateService = (key, update) => { + const o = Object.create(UpdateServiceProto); + o.key = key; + o.update = update; + return o; +}; +var diff = (oldValue, newValue) => { + const missingServices = new Map(oldValue.unsafeMap); + let patch = empty10(); + for (const [tag, newService] of newValue.unsafeMap.entries()) { + if (missingServices.has(tag)) { + const old = missingServices.get(tag); + missingServices.delete(tag); + if (!equals(old, newService)) { + patch = combine4(makeUpdateService(tag, () => newService))(patch); + } + } else { + missingServices.delete(tag); + patch = combine4(makeAddService(tag, newService))(patch); + } + } + for (const [tag] of missingServices.entries()) { + patch = combine4(makeRemoveService(tag))(patch); + } + return patch; +}; +var combine4 = /* @__PURE__ */ dual(2, (self, that) => makeAndThen(self, that)); +var patch = /* @__PURE__ */ dual(2, (self, context) => { + if (self._tag === "Empty") { + return context; + } + let wasServiceUpdated = false; + let patches = of2(self); + const updatedContext = new Map(context.unsafeMap); + while (isNonEmpty2(patches)) { + const head3 = headNonEmpty2(patches); + const tail = tailNonEmpty2(patches); + switch (head3._tag) { + case "Empty": { + patches = tail; + break; + } + case "AddService": { + updatedContext.set(head3.key, head3.service); + patches = tail; + break; + } + case "AndThen": { + patches = prepend2(prepend2(tail, head3.second), head3.first); + break; + } + case "RemoveService": { + updatedContext.delete(head3.key); + patches = tail; + break; + } + case "UpdateService": { + updatedContext.set(head3.key, head3.update(updatedContext.get(head3.key))); + wasServiceUpdated = true; + patches = tail; + break; + } + } + } + if (!wasServiceUpdated) { + return makeContext(updatedContext); + } + const map7 = new Map; + for (const [tag] of context.unsafeMap) { + if (updatedContext.has(tag)) { + map7.set(tag, updatedContext.get(tag)); + updatedContext.delete(tag); + } + } + for (const [tag, s] of updatedContext) { + map7.set(tag, s); + } + return makeContext(map7); +}); + +// node_modules/effect/dist/esm/internal/differ/hashSetPatch.js +var HashSetPatchTypeId = /* @__PURE__ */ Symbol.for("effect/DifferHashSetPatch"); +function variance2(a) { + return a; +} +var PatchProto2 = { + ...Structural.prototype, + [HashSetPatchTypeId]: { + _Value: variance2, + _Key: variance2, + _Patch: variance2 + } +}; +var EmptyProto2 = /* @__PURE__ */ Object.assign(/* @__PURE__ */ Object.create(PatchProto2), { + _tag: "Empty" +}); +var _empty6 = /* @__PURE__ */ Object.create(EmptyProto2); +var empty11 = () => _empty6; +var AndThenProto2 = /* @__PURE__ */ Object.assign(/* @__PURE__ */ Object.create(PatchProto2), { + _tag: "AndThen" +}); +var makeAndThen2 = (first, second) => { + const o = Object.create(AndThenProto2); + o.first = first; + o.second = second; + return o; +}; +var AddProto = /* @__PURE__ */ Object.assign(/* @__PURE__ */ Object.create(PatchProto2), { + _tag: "Add" +}); +var makeAdd = (value) => { + const o = Object.create(AddProto); + o.value = value; + return o; +}; +var RemoveProto = /* @__PURE__ */ Object.assign(/* @__PURE__ */ Object.create(PatchProto2), { + _tag: "Remove" +}); +var makeRemove = (value) => { + const o = Object.create(RemoveProto); + o.value = value; + return o; +}; +var diff2 = (oldValue, newValue) => { + const [removed, patch2] = reduce4([oldValue, empty11()], ([set4, patch3], value) => { + if (has3(value)(set4)) { + return [remove4(value)(set4), patch3]; + } + return [set4, combine5(makeAdd(value))(patch3)]; + })(newValue); + return reduce4(patch2, (patch3, value) => combine5(makeRemove(value))(patch3))(removed); +}; +var combine5 = /* @__PURE__ */ dual(2, (self, that) => makeAndThen2(self, that)); +var patch2 = /* @__PURE__ */ dual(2, (self, oldValue) => { + if (self._tag === "Empty") { + return oldValue; + } + let set4 = oldValue; + let patches = of2(self); + while (isNonEmpty2(patches)) { + const head3 = headNonEmpty2(patches); + const tail = tailNonEmpty2(patches); + switch (head3._tag) { + case "Empty": { + patches = tail; + break; + } + case "AndThen": { + patches = prepend2(head3.first)(prepend2(head3.second)(tail)); + break; + } + case "Add": { + set4 = add4(head3.value)(set4); + patches = tail; + break; + } + case "Remove": { + set4 = remove4(head3.value)(set4); + patches = tail; + } + } + } + return set4; +}); + +// node_modules/effect/dist/esm/internal/differ/readonlyArrayPatch.js +var ReadonlyArrayPatchTypeId = /* @__PURE__ */ Symbol.for("effect/DifferReadonlyArrayPatch"); +function variance3(a) { + return a; +} +var PatchProto3 = { + ...Structural.prototype, + [ReadonlyArrayPatchTypeId]: { + _Value: variance3, + _Patch: variance3 + } +}; +var EmptyProto3 = /* @__PURE__ */ Object.assign(/* @__PURE__ */ Object.create(PatchProto3), { + _tag: "Empty" +}); +var _empty7 = /* @__PURE__ */ Object.create(EmptyProto3); +var empty12 = () => _empty7; +var AndThenProto3 = /* @__PURE__ */ Object.assign(/* @__PURE__ */ Object.create(PatchProto3), { + _tag: "AndThen" +}); +var makeAndThen3 = (first, second) => { + const o = Object.create(AndThenProto3); + o.first = first; + o.second = second; + return o; +}; +var AppendProto = /* @__PURE__ */ Object.assign(/* @__PURE__ */ Object.create(PatchProto3), { + _tag: "Append" +}); +var makeAppend = (values3) => { + const o = Object.create(AppendProto); + o.values = values3; + return o; +}; +var SliceProto = /* @__PURE__ */ Object.assign(/* @__PURE__ */ Object.create(PatchProto3), { + _tag: "Slice" +}); +var makeSlice = (from, until) => { + const o = Object.create(SliceProto); + o.from = from; + o.until = until; + return o; +}; +var UpdateProto = /* @__PURE__ */ Object.assign(/* @__PURE__ */ Object.create(PatchProto3), { + _tag: "Update" +}); +var makeUpdate = (index, patch3) => { + const o = Object.create(UpdateProto); + o.index = index; + o.patch = patch3; + return o; +}; +var diff3 = (options) => { + let i = 0; + let patch3 = empty12(); + while (i < options.oldValue.length && i < options.newValue.length) { + const oldElement = options.oldValue[i]; + const newElement = options.newValue[i]; + const valuePatch = options.differ.diff(oldElement, newElement); + if (!equals(valuePatch, options.differ.empty)) { + patch3 = combine6(patch3, makeUpdate(i, valuePatch)); + } + i = i + 1; + } + if (i < options.oldValue.length) { + patch3 = combine6(patch3, makeSlice(0, i)); + } + if (i < options.newValue.length) { + patch3 = combine6(patch3, makeAppend(drop(i)(options.newValue))); + } + return patch3; +}; +var combine6 = /* @__PURE__ */ dual(2, (self, that) => makeAndThen3(self, that)); +var patch3 = /* @__PURE__ */ dual(3, (self, oldValue, differ) => { + if (self._tag === "Empty") { + return oldValue; + } + let readonlyArray = oldValue.slice(); + let patches = of(self); + while (isNonEmptyArray2(patches)) { + const head3 = headNonEmpty(patches); + const tail = tailNonEmpty(patches); + switch (head3._tag) { + case "Empty": { + patches = tail; + break; + } + case "AndThen": { + tail.unshift(head3.first, head3.second); + patches = tail; + break; + } + case "Append": { + for (const value of head3.values) { + readonlyArray.push(value); + } + patches = tail; + break; + } + case "Slice": { + readonlyArray = readonlyArray.slice(head3.from, head3.until); + patches = tail; + break; + } + case "Update": { + readonlyArray[head3.index] = differ.patch(head3.patch, readonlyArray[head3.index]); + patches = tail; + break; + } + } + } + return readonlyArray; +}); + +// node_modules/effect/dist/esm/internal/differ.js +var DifferTypeId = /* @__PURE__ */ Symbol.for("effect/Differ"); +var DifferProto = { + [DifferTypeId]: { + _P: identity, + _V: identity + }, + pipe() { + return pipeArguments(this, arguments); + } +}; +var make15 = (params) => { + const differ = Object.create(DifferProto); + differ.empty = params.empty; + differ.diff = params.diff; + differ.combine = params.combine; + differ.patch = params.patch; + return differ; +}; +var environment = () => make15({ + empty: empty10(), + combine: (first, second) => combine4(second)(first), + diff: (oldValue, newValue) => diff(oldValue, newValue), + patch: (patch4, oldValue) => patch(oldValue)(patch4) +}); +var hashSet = () => make15({ + empty: empty11(), + combine: (first, second) => combine5(second)(first), + diff: (oldValue, newValue) => diff2(oldValue, newValue), + patch: (patch4, oldValue) => patch2(oldValue)(patch4) +}); +var readonlyArray = (differ) => make15({ + empty: empty12(), + combine: (first, second) => combine6(first, second), + diff: (oldValue, newValue) => diff3({ + oldValue, + newValue, + differ + }), + patch: (patch4, oldValue) => patch3(patch4, oldValue, differ) +}); +var update = () => updateWith((_, a) => a); +var updateWith = (f) => make15({ + empty: identity, + combine: (first, second) => { + if (first === identity) { + return second; + } + if (second === identity) { + return first; + } + return (a) => second(first(a)); + }, + diff: (oldValue, newValue) => { + if (equals(oldValue, newValue)) { + return identity; + } + return constant(newValue); + }, + patch: (patch4, oldValue) => f(oldValue, patch4(oldValue)) +}); + +// node_modules/effect/dist/esm/internal/runtimeFlagsPatch.js +var BIT_MASK = 255; +var BIT_SHIFT = 8; +var active = (patch4) => patch4 & BIT_MASK; +var enabled = (patch4) => patch4 >> BIT_SHIFT & BIT_MASK; +var make16 = (active2, enabled2) => (active2 & BIT_MASK) + ((enabled2 & active2 & BIT_MASK) << BIT_SHIFT); +var empty13 = /* @__PURE__ */ make16(0, 0); +var enable = (flag) => make16(flag, flag); +var disable = (flag) => make16(flag, 0); +var exclude = /* @__PURE__ */ dual(2, (self, flag) => make16(active(self) & ~flag, enabled(self))); +var andThen = /* @__PURE__ */ dual(2, (self, that) => self | that); +var invert = (n) => ~n >>> 0 & BIT_MASK; + +// node_modules/effect/dist/esm/internal/runtimeFlags.js +var None2 = 0; +var Interruption = 1 << 0; +var OpSupervision = 1 << 1; +var RuntimeMetrics = 1 << 2; +var WindDown = 1 << 4; +var CooperativeYielding = 1 << 5; +var cooperativeYielding = (self) => isEnabled(self, CooperativeYielding); +var disable2 = /* @__PURE__ */ dual(2, (self, flag) => self & ~flag); +var enable2 = /* @__PURE__ */ dual(2, (self, flag) => self | flag); +var interruptible = (self) => interruption(self) && !windDown(self); +var interruption = (self) => isEnabled(self, Interruption); +var isEnabled = /* @__PURE__ */ dual(2, (self, flag) => (self & flag) !== 0); +var make17 = (...flags) => flags.reduce((a, b) => a | b, 0); +var none5 = /* @__PURE__ */ make17(None2); +var runtimeMetrics = (self) => isEnabled(self, RuntimeMetrics); +var windDown = (self) => isEnabled(self, WindDown); +var diff4 = /* @__PURE__ */ dual(2, (self, that) => make16(self ^ that, that)); +var patch4 = /* @__PURE__ */ dual(2, (self, patch5) => self & (invert(active(patch5)) | enabled(patch5)) | active(patch5) & enabled(patch5)); +var differ = /* @__PURE__ */ make15({ + empty: empty13, + diff: (oldValue, newValue) => diff4(oldValue, newValue), + combine: (first, second) => andThen(second)(first), + patch: (_patch, oldValue) => patch4(oldValue, _patch) +}); + +// node_modules/effect/dist/esm/RuntimeFlagsPatch.js +var empty14 = empty13; +var enable3 = enable; +var disable3 = disable; +var exclude2 = exclude; + +// node_modules/effect/dist/esm/internal/blockedRequests.js +var empty15 = { + _tag: "Empty" +}; +var par = (self, that) => ({ + _tag: "Par", + left: self, + right: that +}); +var seq = (self, that) => ({ + _tag: "Seq", + left: self, + right: that +}); +var single = (dataSource, blockedRequest) => ({ + _tag: "Single", + dataSource, + blockedRequest +}); +var flatten3 = (self) => { + let current = of3(self); + let updated = empty9(); + while (true) { + const [parallel, sequential] = reduce6(current, [parallelCollectionEmpty(), empty9()], ([parallel2, sequential2], blockedRequest) => { + const [par2, seq2] = step(blockedRequest); + return [parallelCollectionCombine(parallel2, par2), appendAll3(sequential2, seq2)]; + }); + updated = merge4(updated, parallel); + if (isNil(sequential)) { + return reverse3(updated); + } + current = sequential; + } + throw new Error("BUG: BlockedRequests.flatten - please report an issue at https://github.com/Effect-TS/effect/issues"); +}; +var step = (requests) => { + let current = requests; + let parallel = parallelCollectionEmpty(); + let stack = empty9(); + let sequential = empty9(); + while (true) { + switch (current._tag) { + case "Empty": { + if (isNil(stack)) { + return [parallel, sequential]; + } + current = stack.head; + stack = stack.tail; + break; + } + case "Par": { + stack = cons(current.right, stack); + current = current.left; + break; + } + case "Seq": { + const left3 = current.left; + const right3 = current.right; + switch (left3._tag) { + case "Empty": { + current = right3; + break; + } + case "Par": { + const l = left3.left; + const r = left3.right; + current = par(seq(l, right3), seq(r, right3)); + break; + } + case "Seq": { + const l = left3.left; + const r = left3.right; + current = seq(l, seq(r, right3)); + break; + } + case "Single": { + current = left3; + sequential = cons(right3, sequential); + break; + } + } + break; + } + case "Single": { + parallel = parallelCollectionAdd(parallel, current); + if (isNil(stack)) { + return [parallel, sequential]; + } + current = stack.head; + stack = stack.tail; + break; + } + } + } + throw new Error("BUG: BlockedRequests.step - please report an issue at https://github.com/Effect-TS/effect/issues"); +}; +var merge4 = (sequential, parallel) => { + if (isNil(sequential)) { + return of3(parallelCollectionToSequentialCollection(parallel)); + } + if (parallelCollectionIsEmpty(parallel)) { + return sequential; + } + const seqHeadKeys = sequentialCollectionKeys(sequential.head); + const parKeys = parallelCollectionKeys(parallel); + if (seqHeadKeys.length === 1 && parKeys.length === 1 && equals(seqHeadKeys[0], parKeys[0])) { + return cons(sequentialCollectionCombine(sequential.head, parallelCollectionToSequentialCollection(parallel)), sequential.tail); + } + return cons(parallelCollectionToSequentialCollection(parallel), sequential); +}; +var EntryTypeId = /* @__PURE__ */ Symbol.for("effect/RequestBlock/Entry"); + +class EntryImpl { + request; + result; + listeners; + ownerId; + state; + [EntryTypeId] = blockedRequestVariance; + constructor(request, result, listeners, ownerId, state) { + this.request = request; + this.result = result; + this.listeners = listeners; + this.ownerId = ownerId; + this.state = state; + } +} +var blockedRequestVariance = { + _R: (_) => _ +}; +var makeEntry = (options) => new EntryImpl(options.request, options.result, options.listeners, options.ownerId, options.state); +var RequestBlockParallelTypeId = /* @__PURE__ */ Symbol.for("effect/RequestBlock/RequestBlockParallel"); +var parallelVariance = { + _R: (_) => _ +}; + +class ParallelImpl { + map; + [RequestBlockParallelTypeId] = parallelVariance; + constructor(map7) { + this.map = map7; + } +} +var parallelCollectionEmpty = () => new ParallelImpl(empty8()); +var parallelCollectionAdd = (self, blockedRequest) => new ParallelImpl(modifyAt2(self.map, blockedRequest.dataSource, (_) => orElseSome(map2(_, append2(blockedRequest.blockedRequest)), () => of2(blockedRequest.blockedRequest)))); +var parallelCollectionCombine = (self, that) => new ParallelImpl(reduce5(self.map, that.map, (map7, value, key) => set3(map7, key, match2(get7(map7, key), { + onNone: () => value, + onSome: (other) => appendAll2(value, other) +})))); +var parallelCollectionIsEmpty = (self) => isEmpty3(self.map); +var parallelCollectionKeys = (self) => Array.from(keys2(self.map)); +var parallelCollectionToSequentialCollection = (self) => sequentialCollectionMake(map6(self.map, (x) => of2(x))); +var SequentialCollectionTypeId = /* @__PURE__ */ Symbol.for("effect/RequestBlock/RequestBlockSequential"); +var sequentialVariance = { + _R: (_) => _ +}; + +class SequentialImpl { + map; + [SequentialCollectionTypeId] = sequentialVariance; + constructor(map7) { + this.map = map7; + } +} +var sequentialCollectionMake = (map7) => new SequentialImpl(map7); +var sequentialCollectionCombine = (self, that) => new SequentialImpl(reduce5(that.map, self.map, (map7, value, key) => set3(map7, key, match2(get7(map7, key), { + onNone: () => empty4(), + onSome: (a) => appendAll2(a, value) +})))); +var sequentialCollectionKeys = (self) => Array.from(keys2(self.map)); +var sequentialCollectionToChunk = (self) => Array.from(self.map); + +// node_modules/effect/dist/esm/internal/opCodes/cause.js +var OP_DIE = "Die"; +var OP_EMPTY = "Empty"; +var OP_FAIL = "Fail"; +var OP_INTERRUPT = "Interrupt"; +var OP_PARALLEL = "Parallel"; +var OP_SEQUENTIAL = "Sequential"; + +// node_modules/effect/dist/esm/internal/cause.js +var CauseSymbolKey = "effect/Cause"; +var CauseTypeId = /* @__PURE__ */ Symbol.for(CauseSymbolKey); +var variance4 = { + _E: (_) => _ +}; +var proto = { + [CauseTypeId]: variance4, + [symbol]() { + return pipe(hash(CauseSymbolKey), combine(hash(flattenCause(this))), cached(this)); + }, + [symbol2](that) { + return isCause(that) && causeEquals(this, that); + }, + pipe() { + return pipeArguments(this, arguments); + }, + toJSON() { + switch (this._tag) { + case "Empty": + return { + _id: "Cause", + _tag: this._tag + }; + case "Die": + return { + _id: "Cause", + _tag: this._tag, + defect: toJSON(this.defect) + }; + case "Interrupt": + return { + _id: "Cause", + _tag: this._tag, + fiberId: this.fiberId.toJSON() + }; + case "Fail": + return { + _id: "Cause", + _tag: this._tag, + failure: toJSON(this.error) + }; + case "Sequential": + case "Parallel": + return { + _id: "Cause", + _tag: this._tag, + left: toJSON(this.left), + right: toJSON(this.right) + }; + } + }, + toString() { + return pretty(this); + }, + [NodeInspectSymbol]() { + return this.toJSON(); + } +}; +var empty16 = /* @__PURE__ */ (() => { + const o = /* @__PURE__ */ Object.create(proto); + o._tag = OP_EMPTY; + return o; +})(); +var fail = (error) => { + const o = Object.create(proto); + o._tag = OP_FAIL; + o.error = error; + return o; +}; +var die = (defect) => { + const o = Object.create(proto); + o._tag = OP_DIE; + o.defect = defect; + return o; +}; +var interrupt = (fiberId) => { + const o = Object.create(proto); + o._tag = OP_INTERRUPT; + o.fiberId = fiberId; + return o; +}; +var parallel = (left3, right3) => { + const o = Object.create(proto); + o._tag = OP_PARALLEL; + o.left = left3; + o.right = right3; + return o; +}; +var sequential = (left3, right3) => { + const o = Object.create(proto); + o._tag = OP_SEQUENTIAL; + o.left = left3; + o.right = right3; + return o; +}; +var isCause = (u) => hasProperty(u, CauseTypeId); +var isEmptyType = (self) => self._tag === OP_EMPTY; +var isFailType = (self) => self._tag === OP_FAIL; +var isDieType = (self) => self._tag === OP_DIE; +var isEmpty5 = (self) => { + if (self._tag === OP_EMPTY) { + return true; + } + return reduce7(self, true, (acc, cause) => { + switch (cause._tag) { + case OP_EMPTY: { + return some2(acc); + } + case OP_DIE: + case OP_FAIL: + case OP_INTERRUPT: { + return some2(false); + } + default: { + return none2(); + } + } + }); +}; +var isInterrupted = (self) => isSome2(interruptOption(self)); +var isInterruptedOnly = (self) => reduceWithContext(undefined, IsInterruptedOnlyCauseReducer)(self); +var failures = (self) => reverse2(reduce7(self, empty4(), (list, cause) => cause._tag === OP_FAIL ? some2(pipe(list, prepend2(cause.error))) : none2())); +var defects = (self) => reverse2(reduce7(self, empty4(), (list, cause) => cause._tag === OP_DIE ? some2(pipe(list, prepend2(cause.defect))) : none2())); +var interruptors = (self) => reduce7(self, empty7(), (set4, cause) => cause._tag === OP_INTERRUPT ? some2(pipe(set4, add4(cause.fiberId))) : none2()); +var failureOption = (self) => find(self, (cause) => cause._tag === OP_FAIL ? some2(cause.error) : none2()); +var failureOrCause = (self) => { + const option = failureOption(self); + switch (option._tag) { + case "None": { + return right2(self); + } + case "Some": { + return left2(option.value); + } + } +}; +var interruptOption = (self) => find(self, (cause) => cause._tag === OP_INTERRUPT ? some2(cause.fiberId) : none2()); +var keepDefects = (self) => match5(self, { + onEmpty: none2(), + onFail: () => none2(), + onDie: (defect) => some2(die(defect)), + onInterrupt: () => none2(), + onSequential: mergeWith(sequential), + onParallel: mergeWith(parallel) +}); +var keepDefectsAndElectFailures = (self) => match5(self, { + onEmpty: none2(), + onFail: (failure) => some2(die(failure)), + onDie: (defect) => some2(die(defect)), + onInterrupt: () => none2(), + onSequential: mergeWith(sequential), + onParallel: mergeWith(parallel) +}); +var stripFailures = (self) => match5(self, { + onEmpty: empty16, + onFail: () => empty16, + onDie: die, + onInterrupt: interrupt, + onSequential: sequential, + onParallel: parallel +}); +var electFailures = (self) => match5(self, { + onEmpty: empty16, + onFail: die, + onDie: die, + onInterrupt: interrupt, + onSequential: sequential, + onParallel: parallel +}); +var flatMap6 = /* @__PURE__ */ dual(2, (self, f) => match5(self, { + onEmpty: empty16, + onFail: (error) => f(error), + onDie: (defect) => die(defect), + onInterrupt: (fiberId) => interrupt(fiberId), + onSequential: (left3, right3) => sequential(left3, right3), + onParallel: (left3, right3) => parallel(left3, right3) +})); +var flatten4 = (self) => flatMap6(self, identity); +var causeEquals = (left3, right3) => { + let leftStack = of2(left3); + let rightStack = of2(right3); + while (isNonEmpty2(leftStack) && isNonEmpty2(rightStack)) { + const [leftParallel, leftSequential] = pipe(headNonEmpty2(leftStack), reduce7([empty7(), empty4()], ([parallel2, sequential2], cause) => { + const [par2, seq2] = evaluateCause(cause); + return some2([pipe(parallel2, union3(par2)), pipe(sequential2, appendAll2(seq2))]); + })); + const [rightParallel, rightSequential] = pipe(headNonEmpty2(rightStack), reduce7([empty7(), empty4()], ([parallel2, sequential2], cause) => { + const [par2, seq2] = evaluateCause(cause); + return some2([pipe(parallel2, union3(par2)), pipe(sequential2, appendAll2(seq2))]); + })); + if (!equals(leftParallel, rightParallel)) { + return false; + } + leftStack = leftSequential; + rightStack = rightSequential; + } + return true; +}; +var flattenCause = (cause) => { + return flattenCauseLoop(of2(cause), empty4()); +}; +var flattenCauseLoop = (causes, flattened) => { + while (true) { + const [parallel2, sequential2] = pipe(causes, reduce([empty7(), empty4()], ([parallel3, sequential3], cause) => { + const [par2, seq2] = evaluateCause(cause); + return [pipe(parallel3, union3(par2)), pipe(sequential3, appendAll2(seq2))]; + })); + const updated = size3(parallel2) > 0 ? pipe(flattened, prepend2(parallel2)) : flattened; + if (isEmpty(sequential2)) { + return reverse2(updated); + } + causes = sequential2; + flattened = updated; + } + throw new Error(getBugErrorMessage("Cause.flattenCauseLoop")); +}; +var find = /* @__PURE__ */ dual(2, (self, pf) => { + const stack = [self]; + while (stack.length > 0) { + const item = stack.pop(); + const option = pf(item); + switch (option._tag) { + case "None": { + switch (item._tag) { + case OP_SEQUENTIAL: + case OP_PARALLEL: { + stack.push(item.right); + stack.push(item.left); + break; + } + } + break; + } + case "Some": { + return option; + } + } + } + return none2(); +}); +var evaluateCause = (self) => { + let cause = self; + const stack = []; + let _parallel = empty7(); + let _sequential = empty4(); + while (cause !== undefined) { + switch (cause._tag) { + case OP_EMPTY: { + if (stack.length === 0) { + return [_parallel, _sequential]; + } + cause = stack.pop(); + break; + } + case OP_FAIL: { + _parallel = add4(_parallel, make7(cause._tag, cause.error)); + if (stack.length === 0) { + return [_parallel, _sequential]; + } + cause = stack.pop(); + break; + } + case OP_DIE: { + _parallel = add4(_parallel, make7(cause._tag, cause.defect)); + if (stack.length === 0) { + return [_parallel, _sequential]; + } + cause = stack.pop(); + break; + } + case OP_INTERRUPT: { + _parallel = add4(_parallel, make7(cause._tag, cause.fiberId)); + if (stack.length === 0) { + return [_parallel, _sequential]; + } + cause = stack.pop(); + break; + } + case OP_SEQUENTIAL: { + switch (cause.left._tag) { + case OP_EMPTY: { + cause = cause.right; + break; + } + case OP_SEQUENTIAL: { + cause = sequential(cause.left.left, sequential(cause.left.right, cause.right)); + break; + } + case OP_PARALLEL: { + cause = parallel(sequential(cause.left.left, cause.right), sequential(cause.left.right, cause.right)); + break; + } + default: { + _sequential = prepend2(_sequential, cause.right); + cause = cause.left; + break; + } + } + break; + } + case OP_PARALLEL: { + stack.push(cause.right); + cause = cause.left; + break; + } + } + } + throw new Error(getBugErrorMessage("Cause.evaluateCauseLoop")); +}; +var IsInterruptedOnlyCauseReducer = { + emptyCase: constTrue, + failCase: constFalse, + dieCase: constFalse, + interruptCase: constTrue, + sequentialCase: (_, left3, right3) => left3 && right3, + parallelCase: (_, left3, right3) => left3 && right3 +}; +var OP_SEQUENTIAL_CASE = "SequentialCase"; +var OP_PARALLEL_CASE = "ParallelCase"; +var match5 = /* @__PURE__ */ dual(2, (self, { + onDie, + onEmpty, + onFail, + onInterrupt, + onParallel, + onSequential +}) => { + return reduceWithContext(self, undefined, { + emptyCase: () => onEmpty, + failCase: (_, error) => onFail(error), + dieCase: (_, defect) => onDie(defect), + interruptCase: (_, fiberId) => onInterrupt(fiberId), + sequentialCase: (_, left3, right3) => onSequential(left3, right3), + parallelCase: (_, left3, right3) => onParallel(left3, right3) + }); +}); +var reduce7 = /* @__PURE__ */ dual(3, (self, zero3, pf) => { + let accumulator = zero3; + let cause = self; + const causes = []; + while (cause !== undefined) { + const option = pf(accumulator, cause); + accumulator = isSome2(option) ? option.value : accumulator; + switch (cause._tag) { + case OP_SEQUENTIAL: { + causes.push(cause.right); + cause = cause.left; + break; + } + case OP_PARALLEL: { + causes.push(cause.right); + cause = cause.left; + break; + } + default: { + cause = undefined; + break; + } + } + if (cause === undefined && causes.length > 0) { + cause = causes.pop(); + } + } + return accumulator; +}); +var reduceWithContext = /* @__PURE__ */ dual(3, (self, context, reducer) => { + const input = [self]; + const output = []; + while (input.length > 0) { + const cause = input.pop(); + switch (cause._tag) { + case OP_EMPTY: { + output.push(right2(reducer.emptyCase(context))); + break; + } + case OP_FAIL: { + output.push(right2(reducer.failCase(context, cause.error))); + break; + } + case OP_DIE: { + output.push(right2(reducer.dieCase(context, cause.defect))); + break; + } + case OP_INTERRUPT: { + output.push(right2(reducer.interruptCase(context, cause.fiberId))); + break; + } + case OP_SEQUENTIAL: { + input.push(cause.right); + input.push(cause.left); + output.push(left2({ + _tag: OP_SEQUENTIAL_CASE + })); + break; + } + case OP_PARALLEL: { + input.push(cause.right); + input.push(cause.left); + output.push(left2({ + _tag: OP_PARALLEL_CASE + })); + break; + } + } + } + const accumulator = []; + while (output.length > 0) { + const either2 = output.pop(); + switch (either2._tag) { + case "Left": { + switch (either2.left._tag) { + case OP_SEQUENTIAL_CASE: { + const left3 = accumulator.pop(); + const right3 = accumulator.pop(); + const value = reducer.sequentialCase(context, left3, right3); + accumulator.push(value); + break; + } + case OP_PARALLEL_CASE: { + const left3 = accumulator.pop(); + const right3 = accumulator.pop(); + const value = reducer.parallelCase(context, left3, right3); + accumulator.push(value); + break; + } + } + break; + } + case "Right": { + accumulator.push(either2.right); + break; + } + } + } + if (accumulator.length === 0) { + throw new Error("BUG: Cause.reduceWithContext - please report an issue at https://github.com/Effect-TS/effect/issues"); + } + return accumulator.pop(); +}); +var pretty = (cause, options) => { + if (isInterruptedOnly(cause)) { + return "All fibers interrupted without errors."; + } + return prettyErrors(cause).map(function(e) { + if (options?.renderErrorCause !== true || e.cause === undefined) { + return e.stack; + } + return `${e.stack} { +${renderErrorCause(e.cause, " ")} +}`; + }).join(` +`); +}; +var renderErrorCause = (cause, prefix) => { + const lines = cause.stack.split(` +`); + let stack = `${prefix}[cause]: ${lines[0]}`; + for (let i = 1, len = lines.length;i < len; i++) { + stack += ` +${prefix}${lines[i]}`; + } + if (cause.cause) { + stack += ` { +${renderErrorCause(cause.cause, `${prefix} `)} +${prefix}}`; + } + return stack; +}; +var makePrettyError = (originalError) => { + const originalErrorIsObject = typeof originalError === "object" && originalError !== null; + const prevLimit = Error.stackTraceLimit; + Error.stackTraceLimit = 1; + const error = new Error(prettyErrorMessage(originalError), originalErrorIsObject && "cause" in originalError && typeof originalError.cause !== "undefined" ? { + cause: makePrettyError(originalError.cause) + } : undefined); + Error.stackTraceLimit = prevLimit; + if (error.message === "") { + error.message = "An error has occurred"; + } + Error.stackTraceLimit = prevLimit; + error.name = originalError instanceof Error ? originalError.name : "Error"; + if (originalErrorIsObject) { + if (spanSymbol in originalError) { + error.span = originalError[spanSymbol]; + } + Object.keys(originalError).forEach((key) => { + if (!(key in error)) { + error[key] = originalError[key]; + } + }); + } + error.stack = prettyErrorStack(`${error.name}: ${error.message}`, originalError instanceof Error && originalError.stack ? originalError.stack : "", error.span); + return error; +}; +var prettyErrorMessage = (u) => { + if (typeof u === "string") { + return u; + } + if (typeof u === "object" && u !== null && u instanceof Error) { + return u.message; + } + try { + if (hasProperty(u, "toString") && isFunction2(u["toString"]) && u["toString"] !== Object.prototype.toString && u["toString"] !== globalThis.Array.prototype.toString) { + return u["toString"](); + } + } catch {} + return stringifyCircular(u); +}; +var locationRegex = /\((.*)\)/g; +var spanToTrace = /* @__PURE__ */ globalValue("effect/Tracer/spanToTrace", () => new WeakMap); +var prettyErrorStack = (message, stack, span2) => { + const out = [message]; + const lines = stack.startsWith(message) ? stack.slice(message.length).split(` +`) : stack.split(` +`); + for (let i = 1;i < lines.length; i++) { + if (lines[i].includes(" at new BaseEffectError") || lines[i].includes(" at new YieldableError")) { + i++; + continue; + } + if (lines[i].includes("Generator.next")) { + break; + } + if (lines[i].includes("effect_internal_function")) { + break; + } + out.push(lines[i].replace(/at .*effect_instruction_i.*\((.*)\)/, "at $1").replace(/EffectPrimitive\.\w+/, "")); + } + if (span2) { + let current = span2; + let i = 0; + while (current && current._tag === "Span" && i < 10) { + const stackFn = spanToTrace.get(current); + if (typeof stackFn === "function") { + const stack2 = stackFn(); + if (typeof stack2 === "string") { + const locationMatchAll = stack2.matchAll(locationRegex); + let match6 = false; + for (const [, location] of locationMatchAll) { + match6 = true; + out.push(` at ${current.name} (${location})`); + } + if (!match6) { + out.push(` at ${current.name} (${stack2.replace(/^at /, "")})`); + } + } else { + out.push(` at ${current.name}`); + } + } else { + out.push(` at ${current.name}`); + } + current = getOrUndefined(current.parent); + i++; + } + } + return out.join(` +`); +}; +var spanSymbol = /* @__PURE__ */ Symbol.for("effect/SpanAnnotation"); +var prettyErrors = (cause) => reduceWithContext(cause, undefined, { + emptyCase: () => [], + dieCase: (_, unknownError) => { + return [makePrettyError(unknownError)]; + }, + failCase: (_, error) => { + return [makePrettyError(error)]; + }, + interruptCase: () => [], + parallelCase: (_, l, r) => [...l, ...r], + sequentialCase: (_, l, r) => [...l, ...r] +}); + +// node_modules/effect/dist/esm/internal/opCodes/deferred.js +var OP_STATE_PENDING = "Pending"; +var OP_STATE_DONE = "Done"; + +// node_modules/effect/dist/esm/internal/deferred.js +var DeferredSymbolKey = "effect/Deferred"; +var DeferredTypeId = /* @__PURE__ */ Symbol.for(DeferredSymbolKey); +var deferredVariance = { + _E: (_) => _, + _A: (_) => _ +}; +var pending = (joiners) => { + return { + _tag: OP_STATE_PENDING, + joiners + }; +}; +var done = (effect) => { + return { + _tag: OP_STATE_DONE, + effect + }; +}; + +// node_modules/effect/dist/esm/internal/singleShotGen.js +class SingleShotGen2 { + self; + called = false; + constructor(self) { + this.self = self; + } + next(a) { + return this.called ? { + value: a, + done: true + } : (this.called = true, { + value: this.self, + done: false + }); + } + return(a) { + return { + value: a, + done: true + }; + } + throw(e) { + throw e; + } + [Symbol.iterator]() { + return new SingleShotGen2(this.self); + } +} + +// node_modules/effect/dist/esm/internal/core.js +var blocked = (blockedRequests, _continue) => { + const effect = new EffectPrimitive("Blocked"); + effect.effect_instruction_i0 = blockedRequests; + effect.effect_instruction_i1 = _continue; + return effect; +}; +var runRequestBlock = (blockedRequests) => { + const effect = new EffectPrimitive("RunBlocked"); + effect.effect_instruction_i0 = blockedRequests; + return effect; +}; +var EffectTypeId2 = /* @__PURE__ */ Symbol.for("effect/Effect"); + +class RevertFlags { + patch; + op; + _op = OP_REVERT_FLAGS; + constructor(patch5, op) { + this.patch = patch5; + this.op = op; + } +} + +class EffectPrimitive { + _op; + effect_instruction_i0 = undefined; + effect_instruction_i1 = undefined; + effect_instruction_i2 = undefined; + trace = undefined; + [EffectTypeId2] = effectVariance; + constructor(_op) { + this._op = _op; + } + [symbol2](that) { + return this === that; + } + [symbol]() { + return cached(this, random(this)); + } + pipe() { + return pipeArguments(this, arguments); + } + toJSON() { + return { + _id: "Effect", + _op: this._op, + effect_instruction_i0: toJSON(this.effect_instruction_i0), + effect_instruction_i1: toJSON(this.effect_instruction_i1), + effect_instruction_i2: toJSON(this.effect_instruction_i2) + }; + } + toString() { + return format(this.toJSON()); + } + [NodeInspectSymbol]() { + return this.toJSON(); + } + [Symbol.iterator]() { + return new SingleShotGen2(new YieldWrap(this)); + } +} + +class EffectPrimitiveFailure { + _op; + effect_instruction_i0 = undefined; + effect_instruction_i1 = undefined; + effect_instruction_i2 = undefined; + trace = undefined; + [EffectTypeId2] = effectVariance; + constructor(_op) { + this._op = _op; + this._tag = _op; + } + [symbol2](that) { + return exitIsExit(that) && that._op === "Failure" && equals(this.effect_instruction_i0, that.effect_instruction_i0); + } + [symbol]() { + return pipe(string(this._tag), combine(hash(this.effect_instruction_i0)), cached(this)); + } + get cause() { + return this.effect_instruction_i0; + } + pipe() { + return pipeArguments(this, arguments); + } + toJSON() { + return { + _id: "Exit", + _tag: this._op, + cause: this.cause.toJSON() + }; + } + toString() { + return format(this.toJSON()); + } + [NodeInspectSymbol]() { + return this.toJSON(); + } + [Symbol.iterator]() { + return new SingleShotGen2(new YieldWrap(this)); + } +} + +class EffectPrimitiveSuccess { + _op; + effect_instruction_i0 = undefined; + effect_instruction_i1 = undefined; + effect_instruction_i2 = undefined; + trace = undefined; + [EffectTypeId2] = effectVariance; + constructor(_op) { + this._op = _op; + this._tag = _op; + } + [symbol2](that) { + return exitIsExit(that) && that._op === "Success" && equals(this.effect_instruction_i0, that.effect_instruction_i0); + } + [symbol]() { + return pipe(string(this._tag), combine(hash(this.effect_instruction_i0)), cached(this)); + } + get value() { + return this.effect_instruction_i0; + } + pipe() { + return pipeArguments(this, arguments); + } + toJSON() { + return { + _id: "Exit", + _tag: this._op, + value: toJSON(this.value) + }; + } + toString() { + return format(this.toJSON()); + } + [NodeInspectSymbol]() { + return this.toJSON(); + } + [Symbol.iterator]() { + return new SingleShotGen2(new YieldWrap(this)); + } +} +var isEffect = (u) => hasProperty(u, EffectTypeId2); +var withFiberRuntime = (withRuntime) => { + const effect = new EffectPrimitive(OP_WITH_RUNTIME); + effect.effect_instruction_i0 = withRuntime; + return effect; +}; +var acquireUseRelease = /* @__PURE__ */ dual(3, (acquire, use, release) => uninterruptibleMask((restore) => flatMap7(acquire, (a) => flatMap7(exit(suspend(() => restore(use(a)))), (exit) => { + return suspend(() => release(a, exit)).pipe(matchCauseEffect({ + onFailure: (cause) => { + switch (exit._tag) { + case OP_FAILURE: + return failCause(sequential(exit.effect_instruction_i0, cause)); + case OP_SUCCESS: + return failCause(cause); + } + }, + onSuccess: () => exit + })); +})))); +var as = /* @__PURE__ */ dual(2, (self, value) => flatMap7(self, () => succeed(value))); +var asVoid = (self) => as(self, undefined); +var custom = function() { + const wrapper = new EffectPrimitive(OP_COMMIT); + switch (arguments.length) { + case 2: { + wrapper.effect_instruction_i0 = arguments[0]; + wrapper.commit = arguments[1]; + break; + } + case 3: { + wrapper.effect_instruction_i0 = arguments[0]; + wrapper.effect_instruction_i1 = arguments[1]; + wrapper.commit = arguments[2]; + break; + } + case 4: { + wrapper.effect_instruction_i0 = arguments[0]; + wrapper.effect_instruction_i1 = arguments[1]; + wrapper.effect_instruction_i2 = arguments[2]; + wrapper.commit = arguments[3]; + break; + } + default: { + throw new Error(getBugErrorMessage("you're not supposed to end up here")); + } + } + return wrapper; +}; +var unsafeAsync = (register, blockingOn = none4) => { + const effect = new EffectPrimitive(OP_ASYNC); + let cancelerRef = undefined; + effect.effect_instruction_i0 = (resume) => { + cancelerRef = register(resume); + }; + effect.effect_instruction_i1 = blockingOn; + return onInterrupt(effect, (_) => isEffect(cancelerRef) ? cancelerRef : void_); +}; +var asyncInterrupt = (register, blockingOn = none4) => suspend(() => unsafeAsync(register, blockingOn)); +var async_ = (resume, blockingOn = none4) => { + return custom(resume, function() { + let backingResume = undefined; + let pendingEffect = undefined; + function proxyResume(effect2) { + if (backingResume) { + backingResume(effect2); + } else if (pendingEffect === undefined) { + pendingEffect = effect2; + } + } + const effect = new EffectPrimitive(OP_ASYNC); + effect.effect_instruction_i0 = (resume2) => { + backingResume = resume2; + if (pendingEffect) { + resume2(pendingEffect); + } + }; + effect.effect_instruction_i1 = blockingOn; + let cancelerRef = undefined; + let controllerRef = undefined; + if (this.effect_instruction_i0.length !== 1) { + controllerRef = new AbortController; + cancelerRef = internalCall(() => this.effect_instruction_i0(proxyResume, controllerRef.signal)); + } else { + cancelerRef = internalCall(() => this.effect_instruction_i0(proxyResume)); + } + return cancelerRef || controllerRef ? onInterrupt(effect, (_) => { + if (controllerRef) { + controllerRef.abort(); + } + return cancelerRef ?? void_; + }) : effect; + }); +}; +var catchAllCause = /* @__PURE__ */ dual(2, (self, f) => { + const effect = new EffectPrimitive(OP_ON_FAILURE); + effect.effect_instruction_i0 = self; + effect.effect_instruction_i1 = f; + return effect; +}); +var catchAll = /* @__PURE__ */ dual(2, (self, f) => matchEffect(self, { + onFailure: f, + onSuccess: succeed +})); +var catchIf = /* @__PURE__ */ dual(3, (self, predicate, f) => catchAllCause(self, (cause) => { + const either2 = failureOrCause(cause); + switch (either2._tag) { + case "Left": + return predicate(either2.left) ? f(either2.left) : failCause(cause); + case "Right": + return failCause(either2.right); + } +})); +var catchSome = /* @__PURE__ */ dual(2, (self, pf) => catchAllCause(self, (cause) => { + const either2 = failureOrCause(cause); + switch (either2._tag) { + case "Left": + return pipe(pf(either2.left), getOrElse(() => failCause(cause))); + case "Right": + return failCause(either2.right); + } +})); +var checkInterruptible = (f) => withFiberRuntime((_, status) => f(interruption(status.runtimeFlags))); +var originalSymbol = /* @__PURE__ */ Symbol.for("effect/OriginalAnnotation"); +var capture = (obj, span2) => { + if (isSome2(span2)) { + return new Proxy(obj, { + has(target, p) { + return p === spanSymbol || p === originalSymbol || p in target; + }, + get(target, p) { + if (p === spanSymbol) { + return span2.value; + } + if (p === originalSymbol) { + return obj; + } + return target[p]; + } + }); + } + return obj; +}; +var die2 = (defect) => isObject(defect) && !(spanSymbol in defect) ? withFiberRuntime((fiber) => failCause(die(capture(defect, currentSpanFromFiber(fiber))))) : failCause(die(defect)); +var dieMessage = (message) => failCauseSync(() => die(new RuntimeException(message))); +var dieSync = (evaluate) => flatMap7(sync(evaluate), die2); +var either2 = (self) => matchEffect(self, { + onFailure: (e) => succeed(left2(e)), + onSuccess: (a) => succeed(right2(a)) +}); +var exit = (self) => matchCause(self, { + onFailure: exitFailCause, + onSuccess: exitSucceed +}); +var fail2 = (error) => isObject(error) && !(spanSymbol in error) ? withFiberRuntime((fiber) => failCause(fail(capture(error, currentSpanFromFiber(fiber))))) : failCause(fail(error)); +var failSync = (evaluate) => flatMap7(sync(evaluate), fail2); +var failCause = (cause) => { + const effect = new EffectPrimitiveFailure(OP_FAILURE); + effect.effect_instruction_i0 = cause; + return effect; +}; +var failCauseSync = (evaluate) => flatMap7(sync(evaluate), failCause); +var fiberId = /* @__PURE__ */ withFiberRuntime((state) => succeed(state.id())); +var fiberIdWith = (f) => withFiberRuntime((state) => f(state.id())); +var flatMap7 = /* @__PURE__ */ dual(2, (self, f) => { + const effect = new EffectPrimitive(OP_ON_SUCCESS); + effect.effect_instruction_i0 = self; + effect.effect_instruction_i1 = f; + return effect; +}); +var andThen2 = /* @__PURE__ */ dual(2, (self, f) => flatMap7(self, (a) => { + const b = typeof f === "function" ? f(a) : f; + if (isEffect(b)) { + return b; + } else if (isPromiseLike(b)) { + return unsafeAsync((resume) => { + b.then((a2) => resume(succeed(a2)), (e) => resume(fail2(new UnknownException(e, "An unknown error occurred in Effect.andThen")))); + }); + } + return succeed(b); +})); +var step2 = (self) => { + const effect = new EffectPrimitive("OnStep"); + effect.effect_instruction_i0 = self; + return effect; +}; +var flatten5 = (self) => flatMap7(self, identity); +var flip = (self) => matchEffect(self, { + onFailure: succeed, + onSuccess: fail2 +}); +var matchCause = /* @__PURE__ */ dual(2, (self, options) => matchCauseEffect(self, { + onFailure: (cause) => succeed(options.onFailure(cause)), + onSuccess: (a) => succeed(options.onSuccess(a)) +})); +var matchCauseEffect = /* @__PURE__ */ dual(2, (self, options) => { + const effect = new EffectPrimitive(OP_ON_SUCCESS_AND_FAILURE); + effect.effect_instruction_i0 = self; + effect.effect_instruction_i1 = options.onFailure; + effect.effect_instruction_i2 = options.onSuccess; + return effect; +}); +var matchEffect = /* @__PURE__ */ dual(2, (self, options) => matchCauseEffect(self, { + onFailure: (cause) => { + const defects2 = defects(cause); + if (defects2.length > 0) { + return failCause(electFailures(cause)); + } + const failures2 = failures(cause); + if (failures2.length > 0) { + return options.onFailure(unsafeHead(failures2)); + } + return failCause(cause); + }, + onSuccess: options.onSuccess +})); +var forEachSequential = /* @__PURE__ */ dual(2, (self, f) => suspend(() => { + const arr = fromIterable(self); + const ret = allocate(arr.length); + let i = 0; + return as(whileLoop({ + while: () => i < arr.length, + body: () => f(arr[i], i), + step: (b) => { + ret[i++] = b; + } + }), ret); +})); +var forEachSequentialDiscard = /* @__PURE__ */ dual(2, (self, f) => suspend(() => { + const arr = fromIterable(self); + let i = 0; + return whileLoop({ + while: () => i < arr.length, + body: () => f(arr[i], i), + step: () => { + i++; + } + }); +})); +var if_ = /* @__PURE__ */ dual((args) => typeof args[0] === "boolean" || isEffect(args[0]), (self, options) => isEffect(self) ? flatMap7(self, (b) => b ? options.onTrue() : options.onFalse()) : self ? options.onTrue() : options.onFalse()); +var interrupt2 = /* @__PURE__ */ flatMap7(fiberId, (fiberId2) => interruptWith(fiberId2)); +var interruptWith = (fiberId2) => failCause(interrupt(fiberId2)); +var interruptible2 = (self) => { + const effect = new EffectPrimitive(OP_UPDATE_RUNTIME_FLAGS); + effect.effect_instruction_i0 = enable3(Interruption); + effect.effect_instruction_i1 = () => self; + return effect; +}; +var interruptibleMask = (f) => custom(f, function() { + const effect = new EffectPrimitive(OP_UPDATE_RUNTIME_FLAGS); + effect.effect_instruction_i0 = enable3(Interruption); + effect.effect_instruction_i1 = (oldFlags) => interruption(oldFlags) ? internalCall(() => this.effect_instruction_i0(interruptible2)) : internalCall(() => this.effect_instruction_i0(uninterruptible)); + return effect; +}); +var intoDeferred = /* @__PURE__ */ dual(2, (self, deferred) => uninterruptibleMask((restore) => flatMap7(exit(restore(self)), (exit2) => deferredDone(deferred, exit2)))); +var map9 = /* @__PURE__ */ dual(2, (self, f) => flatMap7(self, (a) => sync(() => f(a)))); +var mapBoth2 = /* @__PURE__ */ dual(2, (self, options) => matchEffect(self, { + onFailure: (e) => failSync(() => options.onFailure(e)), + onSuccess: (a) => sync(() => options.onSuccess(a)) +})); +var mapError = /* @__PURE__ */ dual(2, (self, f) => matchCauseEffect(self, { + onFailure: (cause) => { + const either3 = failureOrCause(cause); + switch (either3._tag) { + case "Left": { + return failSync(() => f(either3.left)); + } + case "Right": { + return failCause(either3.right); + } + } + }, + onSuccess: succeed +})); +var onError = /* @__PURE__ */ dual(2, (self, cleanup) => onExit(self, (exit2) => exitIsSuccess(exit2) ? void_ : cleanup(exit2.effect_instruction_i0))); +var onExit = /* @__PURE__ */ dual(2, (self, cleanup) => uninterruptibleMask((restore) => matchCauseEffect(restore(self), { + onFailure: (cause1) => { + const result = exitFailCause(cause1); + return matchCauseEffect(cleanup(result), { + onFailure: (cause2) => exitFailCause(sequential(cause1, cause2)), + onSuccess: () => result + }); + }, + onSuccess: (success) => { + const result = exitSucceed(success); + return zipRight(cleanup(result), result); + } +}))); +var onInterrupt = /* @__PURE__ */ dual(2, (self, cleanup) => onExit(self, exitMatch({ + onFailure: (cause) => isInterruptedOnly(cause) ? asVoid(cleanup(interruptors(cause))) : void_, + onSuccess: () => void_ +}))); +var orElse2 = /* @__PURE__ */ dual(2, (self, that) => attemptOrElse(self, that, succeed)); +var orDie = (self) => orDieWith(self, identity); +var orDieWith = /* @__PURE__ */ dual(2, (self, f) => matchEffect(self, { + onFailure: (e) => die2(f(e)), + onSuccess: succeed +})); +var partitionMap2 = partitionMap; +var runtimeFlags = /* @__PURE__ */ withFiberRuntime((_, status) => succeed(status.runtimeFlags)); +var succeed = (value) => { + const effect = new EffectPrimitiveSuccess(OP_SUCCESS); + effect.effect_instruction_i0 = value; + return effect; +}; +var suspend = (evaluate) => { + const effect = new EffectPrimitive(OP_COMMIT); + effect.commit = evaluate; + return effect; +}; +var sync = (thunk) => { + const effect = new EffectPrimitive(OP_SYNC); + effect.effect_instruction_i0 = thunk; + return effect; +}; +var tap = /* @__PURE__ */ dual((args) => args.length === 3 || args.length === 2 && !(isObject(args[1]) && ("onlyEffect" in args[1])), (self, f) => flatMap7(self, (a) => { + const b = typeof f === "function" ? f(a) : f; + if (isEffect(b)) { + return as(b, a); + } else if (isPromiseLike(b)) { + return unsafeAsync((resume) => { + b.then((_) => resume(succeed(a)), (e) => resume(fail2(new UnknownException(e, "An unknown error occurred in Effect.tap")))); + }); + } + return succeed(a); +})); +var transplant = (f) => withFiberRuntime((state) => { + const scopeOverride = state.getFiberRef(currentForkScopeOverride); + const scope = pipe(scopeOverride, getOrElse(() => state.scope())); + return f(fiberRefLocally(currentForkScopeOverride, some2(scope))); +}); +var attemptOrElse = /* @__PURE__ */ dual(3, (self, that, onSuccess) => matchCauseEffect(self, { + onFailure: (cause) => { + const defects2 = defects(cause); + if (defects2.length > 0) { + return failCause(getOrThrow2(keepDefectsAndElectFailures(cause))); + } + return that(); + }, + onSuccess +})); +var uninterruptible = (self) => { + const effect = new EffectPrimitive(OP_UPDATE_RUNTIME_FLAGS); + effect.effect_instruction_i0 = disable3(Interruption); + effect.effect_instruction_i1 = () => self; + return effect; +}; +var uninterruptibleMask = (f) => custom(f, function() { + const effect = new EffectPrimitive(OP_UPDATE_RUNTIME_FLAGS); + effect.effect_instruction_i0 = disable3(Interruption); + effect.effect_instruction_i1 = (oldFlags) => interruption(oldFlags) ? internalCall(() => this.effect_instruction_i0(interruptible2)) : internalCall(() => this.effect_instruction_i0(uninterruptible)); + return effect; +}); +var void_ = /* @__PURE__ */ succeed(undefined); +var updateRuntimeFlags = (patch5) => { + const effect = new EffectPrimitive(OP_UPDATE_RUNTIME_FLAGS); + effect.effect_instruction_i0 = patch5; + effect.effect_instruction_i1 = undefined; + return effect; +}; +var whenEffect = /* @__PURE__ */ dual(2, (self, condition) => flatMap7(condition, (b) => { + if (b) { + return pipe(self, map9(some2)); + } + return succeed(none2()); +})); +var whileLoop = (options) => { + const effect = new EffectPrimitive(OP_WHILE); + effect.effect_instruction_i0 = options.while; + effect.effect_instruction_i1 = options.body; + effect.effect_instruction_i2 = options.step; + return effect; +}; +var fromIterator = (iterator) => suspend(() => { + const effect = new EffectPrimitive(OP_ITERATOR); + effect.effect_instruction_i0 = iterator(); + return effect; +}); +var gen = function() { + const f = arguments.length === 1 ? arguments[0] : arguments[1].bind(arguments[0]); + return fromIterator(() => f(pipe)); +}; +var fnUntraced = (body, ...pipeables) => Object.defineProperty(pipeables.length === 0 ? function(...args) { + return fromIterator(() => body.apply(this, args)); +} : function(...args) { + let effect = fromIterator(() => body.apply(this, args)); + for (const x of pipeables) { + effect = x(effect, ...args); + } + return effect; +}, "length", { + value: body.length, + configurable: true +}); +var withConcurrency = /* @__PURE__ */ dual(2, (self, concurrency) => fiberRefLocally(self, currentConcurrency, concurrency)); +var withRequestBatching = /* @__PURE__ */ dual(2, (self, requestBatching) => fiberRefLocally(self, currentRequestBatching, requestBatching)); +var withRuntimeFlags = /* @__PURE__ */ dual(2, (self, update2) => { + const effect = new EffectPrimitive(OP_UPDATE_RUNTIME_FLAGS); + effect.effect_instruction_i0 = update2; + effect.effect_instruction_i1 = () => self; + return effect; +}); +var withTracerEnabled = /* @__PURE__ */ dual(2, (effect, enabled2) => fiberRefLocally(effect, currentTracerEnabled, enabled2)); +var withTracerTiming = /* @__PURE__ */ dual(2, (effect, enabled2) => fiberRefLocally(effect, currentTracerTimingEnabled, enabled2)); +var yieldNow = (options) => { + const effect = new EffectPrimitive(OP_YIELD); + return typeof options?.priority !== "undefined" ? withSchedulingPriority(effect, options.priority) : effect; +}; +var zip2 = /* @__PURE__ */ dual(2, (self, that) => flatMap7(self, (a) => map9(that, (b) => [a, b]))); +var zipLeft = /* @__PURE__ */ dual(2, (self, that) => flatMap7(self, (a) => as(that, a))); +var zipRight = /* @__PURE__ */ dual(2, (self, that) => flatMap7(self, () => that)); +var zipWith2 = /* @__PURE__ */ dual(3, (self, that, f) => flatMap7(self, (a) => map9(that, (b) => f(a, b)))); +var never = /* @__PURE__ */ asyncInterrupt(() => { + const interval = setInterval(() => {}, 2 ** 31 - 1); + return sync(() => clearInterval(interval)); +}); +var interruptFiber = (self) => flatMap7(fiberId, (fiberId2) => pipe(self, interruptAsFiber(fiberId2))); +var interruptAsFiber = /* @__PURE__ */ dual(2, (self, fiberId2) => flatMap7(self.interruptAsFork(fiberId2), () => self.await)); +var logLevelAll = { + _tag: "All", + syslog: 0, + label: "ALL", + ordinal: Number.MIN_SAFE_INTEGER, + pipe() { + return pipeArguments(this, arguments); + } +}; +var logLevelFatal = { + _tag: "Fatal", + syslog: 2, + label: "FATAL", + ordinal: 50000, + pipe() { + return pipeArguments(this, arguments); + } +}; +var logLevelError = { + _tag: "Error", + syslog: 3, + label: "ERROR", + ordinal: 40000, + pipe() { + return pipeArguments(this, arguments); + } +}; +var logLevelWarning = { + _tag: "Warning", + syslog: 4, + label: "WARN", + ordinal: 30000, + pipe() { + return pipeArguments(this, arguments); + } +}; +var logLevelInfo = { + _tag: "Info", + syslog: 6, + label: "INFO", + ordinal: 20000, + pipe() { + return pipeArguments(this, arguments); + } +}; +var logLevelDebug = { + _tag: "Debug", + syslog: 7, + label: "DEBUG", + ordinal: 1e4, + pipe() { + return pipeArguments(this, arguments); + } +}; +var logLevelTrace = { + _tag: "Trace", + syslog: 7, + label: "TRACE", + ordinal: 0, + pipe() { + return pipeArguments(this, arguments); + } +}; +var logLevelNone = { + _tag: "None", + syslog: 7, + label: "OFF", + ordinal: Number.MAX_SAFE_INTEGER, + pipe() { + return pipeArguments(this, arguments); + } +}; +var FiberRefSymbolKey = "effect/FiberRef"; +var FiberRefTypeId = /* @__PURE__ */ Symbol.for(FiberRefSymbolKey); +var fiberRefVariance = { + _A: (_) => _ +}; +var fiberRefGet = (self) => withFiberRuntime((fiber) => exitSucceed(fiber.getFiberRef(self))); +var fiberRefGetWith = /* @__PURE__ */ dual(2, (self, f) => flatMap7(fiberRefGet(self), f)); +var fiberRefSet = /* @__PURE__ */ dual(2, (self, value) => fiberRefModify(self, () => [undefined, value])); +var fiberRefModify = /* @__PURE__ */ dual(2, (self, f) => withFiberRuntime((state) => { + const [b, a] = f(state.getFiberRef(self)); + state.setFiberRef(self, a); + return succeed(b); +})); +var fiberRefLocally = /* @__PURE__ */ dual(3, (use, self, value) => acquireUseRelease(zipLeft(fiberRefGet(self), fiberRefSet(self, value)), () => use, (oldValue) => fiberRefSet(self, oldValue))); +var fiberRefLocallyWith = /* @__PURE__ */ dual(3, (use, self, f) => fiberRefGetWith(self, (a) => fiberRefLocally(use, self, f(a)))); +var fiberRefUnsafeMake = (initial, options) => fiberRefUnsafeMakePatch(initial, { + differ: update(), + fork: options?.fork ?? identity, + join: options?.join +}); +var fiberRefUnsafeMakeHashSet = (initial) => { + const differ2 = hashSet(); + return fiberRefUnsafeMakePatch(initial, { + differ: differ2, + fork: differ2.empty + }); +}; +var fiberRefUnsafeMakeReadonlyArray = (initial) => { + const differ2 = readonlyArray(update()); + return fiberRefUnsafeMakePatch(initial, { + differ: differ2, + fork: differ2.empty + }); +}; +var fiberRefUnsafeMakeContext = (initial) => { + const differ2 = environment(); + return fiberRefUnsafeMakePatch(initial, { + differ: differ2, + fork: differ2.empty + }); +}; +var fiberRefUnsafeMakePatch = (initial, options) => { + const _fiberRef = { + ...CommitPrototype, + [FiberRefTypeId]: fiberRefVariance, + initial, + commit() { + return fiberRefGet(this); + }, + diff: (oldValue, newValue) => options.differ.diff(oldValue, newValue), + combine: (first, second) => options.differ.combine(first, second), + patch: (patch5) => (oldValue) => options.differ.patch(patch5, oldValue), + fork: options.fork, + join: options.join ?? ((_, n) => n) + }; + return _fiberRef; +}; +var fiberRefUnsafeMakeRuntimeFlags = (initial) => fiberRefUnsafeMakePatch(initial, { + differ, + fork: differ.empty +}); +var currentContext = /* @__PURE__ */ globalValue(/* @__PURE__ */ Symbol.for("effect/FiberRef/currentContext"), () => fiberRefUnsafeMakeContext(empty3())); +var currentSchedulingPriority = /* @__PURE__ */ globalValue(/* @__PURE__ */ Symbol.for("effect/FiberRef/currentSchedulingPriority"), () => fiberRefUnsafeMake(0)); +var currentMaxOpsBeforeYield = /* @__PURE__ */ globalValue(/* @__PURE__ */ Symbol.for("effect/FiberRef/currentMaxOpsBeforeYield"), () => fiberRefUnsafeMake(2048)); +var currentLogAnnotations = /* @__PURE__ */ globalValue(/* @__PURE__ */ Symbol.for("effect/FiberRef/currentLogAnnotation"), () => fiberRefUnsafeMake(empty8())); +var currentLogLevel = /* @__PURE__ */ globalValue(/* @__PURE__ */ Symbol.for("effect/FiberRef/currentLogLevel"), () => fiberRefUnsafeMake(logLevelInfo)); +var currentLogSpan = /* @__PURE__ */ globalValue(/* @__PURE__ */ Symbol.for("effect/FiberRef/currentLogSpan"), () => fiberRefUnsafeMake(empty9())); +var withSchedulingPriority = /* @__PURE__ */ dual(2, (self, scheduler) => fiberRefLocally(self, currentSchedulingPriority, scheduler)); +var withMaxOpsBeforeYield = /* @__PURE__ */ dual(2, (self, scheduler) => fiberRefLocally(self, currentMaxOpsBeforeYield, scheduler)); +var currentConcurrency = /* @__PURE__ */ globalValue(/* @__PURE__ */ Symbol.for("effect/FiberRef/currentConcurrency"), () => fiberRefUnsafeMake("unbounded")); +var currentRequestBatching = /* @__PURE__ */ globalValue(/* @__PURE__ */ Symbol.for("effect/FiberRef/currentRequestBatching"), () => fiberRefUnsafeMake(true)); +var currentUnhandledErrorLogLevel = /* @__PURE__ */ globalValue(/* @__PURE__ */ Symbol.for("effect/FiberRef/currentUnhandledErrorLogLevel"), () => fiberRefUnsafeMake(some2(logLevelDebug))); +var currentVersionMismatchErrorLogLevel = /* @__PURE__ */ globalValue(/* @__PURE__ */ Symbol.for("effect/FiberRef/versionMismatchErrorLogLevel"), () => fiberRefUnsafeMake(some2(logLevelWarning))); +var withUnhandledErrorLogLevel = /* @__PURE__ */ dual(2, (self, level) => fiberRefLocally(self, currentUnhandledErrorLogLevel, level)); +var currentMetricLabels = /* @__PURE__ */ globalValue(/* @__PURE__ */ Symbol.for("effect/FiberRef/currentMetricLabels"), () => fiberRefUnsafeMakeReadonlyArray(empty())); +var metricLabels = /* @__PURE__ */ fiberRefGet(currentMetricLabels); +var currentForkScopeOverride = /* @__PURE__ */ globalValue(/* @__PURE__ */ Symbol.for("effect/FiberRef/currentForkScopeOverride"), () => fiberRefUnsafeMake(none2(), { + fork: () => none2(), + join: (parent, _) => parent +})); +var currentInterruptedCause = /* @__PURE__ */ globalValue(/* @__PURE__ */ Symbol.for("effect/FiberRef/currentInterruptedCause"), () => fiberRefUnsafeMake(empty16, { + fork: () => empty16, + join: (parent, _) => parent +})); +var currentTracerEnabled = /* @__PURE__ */ globalValue(/* @__PURE__ */ Symbol.for("effect/FiberRef/currentTracerEnabled"), () => fiberRefUnsafeMake(true)); +var currentTracerTimingEnabled = /* @__PURE__ */ globalValue(/* @__PURE__ */ Symbol.for("effect/FiberRef/currentTracerTiming"), () => fiberRefUnsafeMake(true)); +var currentTracerSpanAnnotations = /* @__PURE__ */ globalValue(/* @__PURE__ */ Symbol.for("effect/FiberRef/currentTracerSpanAnnotations"), () => fiberRefUnsafeMake(empty8())); +var currentTracerSpanLinks = /* @__PURE__ */ globalValue(/* @__PURE__ */ Symbol.for("effect/FiberRef/currentTracerSpanLinks"), () => fiberRefUnsafeMake(empty4())); +var ScopeTypeId = /* @__PURE__ */ Symbol.for("effect/Scope"); +var CloseableScopeTypeId = /* @__PURE__ */ Symbol.for("effect/CloseableScope"); +var scopeAddFinalizer = (self, finalizer) => self.addFinalizer(() => asVoid(finalizer)); +var scopeAddFinalizerExit = (self, finalizer) => self.addFinalizer(finalizer); +var scopeClose = (self, exit2) => self.close(exit2); +var scopeFork = (self, strategy) => self.fork(strategy); +var YieldableError = /* @__PURE__ */ function() { + class YieldableError2 extends globalThis.Error { + commit() { + return fail2(this); + } + toJSON() { + const obj = { + ...this + }; + if (this.message) + obj.message = this.message; + if (this.cause) + obj.cause = this.cause; + return obj; + } + [NodeInspectSymbol]() { + if (this.toString !== globalThis.Error.prototype.toString) { + return this.stack ? `${this.toString()} +${this.stack.split(` +`).slice(1).join(` +`)}` : this.toString(); + } else if ("Bun" in globalThis) { + return pretty(fail(this), { + renderErrorCause: true + }); + } + return this; + } + } + Object.assign(YieldableError2.prototype, StructuralCommitPrototype); + return YieldableError2; +}(); +var makeException = (proto2, tag) => { + + class Base2 extends YieldableError { + _tag = tag; + } + Object.assign(Base2.prototype, proto2); + Base2.prototype.name = tag; + return Base2; +}; +var RuntimeExceptionTypeId = /* @__PURE__ */ Symbol.for("effect/Cause/errors/RuntimeException"); +var RuntimeException = /* @__PURE__ */ makeException({ + [RuntimeExceptionTypeId]: RuntimeExceptionTypeId +}, "RuntimeException"); +var InterruptedExceptionTypeId = /* @__PURE__ */ Symbol.for("effect/Cause/errors/InterruptedException"); +var InterruptedException = /* @__PURE__ */ makeException({ + [InterruptedExceptionTypeId]: InterruptedExceptionTypeId +}, "InterruptedException"); +var isInterruptedException = (u) => hasProperty(u, InterruptedExceptionTypeId); +var IllegalArgumentExceptionTypeId = /* @__PURE__ */ Symbol.for("effect/Cause/errors/IllegalArgument"); +var IllegalArgumentException = /* @__PURE__ */ makeException({ + [IllegalArgumentExceptionTypeId]: IllegalArgumentExceptionTypeId +}, "IllegalArgumentException"); +var NoSuchElementExceptionTypeId = /* @__PURE__ */ Symbol.for("effect/Cause/errors/NoSuchElement"); +var NoSuchElementException = /* @__PURE__ */ makeException({ + [NoSuchElementExceptionTypeId]: NoSuchElementExceptionTypeId +}, "NoSuchElementException"); +var isNoSuchElementException = (u) => hasProperty(u, NoSuchElementExceptionTypeId); +var InvalidPubSubCapacityExceptionTypeId = /* @__PURE__ */ Symbol.for("effect/Cause/errors/InvalidPubSubCapacityException"); +var InvalidPubSubCapacityException = /* @__PURE__ */ makeException({ + [InvalidPubSubCapacityExceptionTypeId]: InvalidPubSubCapacityExceptionTypeId +}, "InvalidPubSubCapacityException"); +var ExceededCapacityExceptionTypeId = /* @__PURE__ */ Symbol.for("effect/Cause/errors/ExceededCapacityException"); +var ExceededCapacityException = /* @__PURE__ */ makeException({ + [ExceededCapacityExceptionTypeId]: ExceededCapacityExceptionTypeId +}, "ExceededCapacityException"); +var TimeoutExceptionTypeId = /* @__PURE__ */ Symbol.for("effect/Cause/errors/Timeout"); +var TimeoutException = /* @__PURE__ */ makeException({ + [TimeoutExceptionTypeId]: TimeoutExceptionTypeId +}, "TimeoutException"); +var timeoutExceptionFromDuration = (duration) => new TimeoutException(`Operation timed out after '${format3(duration)}'`); +var UnknownExceptionTypeId = /* @__PURE__ */ Symbol.for("effect/Cause/errors/UnknownException"); +var UnknownException = /* @__PURE__ */ function() { + + class UnknownException2 extends YieldableError { + _tag = "UnknownException"; + error; + constructor(cause, message) { + super(message ?? "An unknown error occurred", { + cause + }); + this.error = cause; + } + } + Object.assign(UnknownException2.prototype, { + [UnknownExceptionTypeId]: UnknownExceptionTypeId, + name: "UnknownException" + }); + return UnknownException2; +}(); +var exitIsExit = (u) => isEffect(u) && ("_tag" in u) && (u._tag === "Success" || u._tag === "Failure"); +var exitIsFailure = (self) => self._tag === "Failure"; +var exitIsSuccess = (self) => self._tag === "Success"; +var exitAs = /* @__PURE__ */ dual(2, (self, value) => { + switch (self._tag) { + case OP_FAILURE: { + return exitFailCause(self.effect_instruction_i0); + } + case OP_SUCCESS: { + return exitSucceed(value); + } + } +}); +var exitAsVoid = (self) => exitAs(self, undefined); +var exitCollectAll = (exits, options) => exitCollectAllInternal(exits, options?.parallel ? parallel : sequential); +var exitDie = (defect) => exitFailCause(die(defect)); +var exitFail = (error) => exitFailCause(fail(error)); +var exitFailCause = (cause) => { + const effect = new EffectPrimitiveFailure(OP_FAILURE); + effect.effect_instruction_i0 = cause; + return effect; +}; +var exitFlatMap = /* @__PURE__ */ dual(2, (self, f) => { + switch (self._tag) { + case OP_FAILURE: { + return exitFailCause(self.effect_instruction_i0); + } + case OP_SUCCESS: { + return f(self.effect_instruction_i0); + } + } +}); +var exitFlatten = (self) => pipe(self, exitFlatMap(identity)); +var exitInterrupt = (fiberId2) => exitFailCause(interrupt(fiberId2)); +var exitMap = /* @__PURE__ */ dual(2, (self, f) => { + switch (self._tag) { + case OP_FAILURE: + return exitFailCause(self.effect_instruction_i0); + case OP_SUCCESS: + return exitSucceed(f(self.effect_instruction_i0)); + } +}); +var exitMatch = /* @__PURE__ */ dual(2, (self, { + onFailure, + onSuccess +}) => { + switch (self._tag) { + case OP_FAILURE: + return onFailure(self.effect_instruction_i0); + case OP_SUCCESS: + return onSuccess(self.effect_instruction_i0); + } +}); +var exitMatchEffect = /* @__PURE__ */ dual(2, (self, { + onFailure, + onSuccess +}) => { + switch (self._tag) { + case OP_FAILURE: + return onFailure(self.effect_instruction_i0); + case OP_SUCCESS: + return onSuccess(self.effect_instruction_i0); + } +}); +var exitSucceed = (value) => { + const effect = new EffectPrimitiveSuccess(OP_SUCCESS); + effect.effect_instruction_i0 = value; + return effect; +}; +var exitVoid = /* @__PURE__ */ exitSucceed(undefined); +var exitZipWith = /* @__PURE__ */ dual(3, (self, that, { + onFailure, + onSuccess +}) => { + switch (self._tag) { + case OP_FAILURE: { + switch (that._tag) { + case OP_SUCCESS: + return exitFailCause(self.effect_instruction_i0); + case OP_FAILURE: { + return exitFailCause(onFailure(self.effect_instruction_i0, that.effect_instruction_i0)); + } + } + } + case OP_SUCCESS: { + switch (that._tag) { + case OP_SUCCESS: + return exitSucceed(onSuccess(self.effect_instruction_i0, that.effect_instruction_i0)); + case OP_FAILURE: + return exitFailCause(that.effect_instruction_i0); + } + } + } +}); +var exitCollectAllInternal = (exits, combineCauses) => { + const list = fromIterable2(exits); + if (!isNonEmpty2(list)) { + return none2(); + } + return pipe(tailNonEmpty2(list), reduce(pipe(headNonEmpty2(list), exitMap(of2)), (accumulator, current) => pipe(accumulator, exitZipWith(current, { + onSuccess: (list2, value) => pipe(list2, prepend2(value)), + onFailure: combineCauses + }))), exitMap(reverse2), exitMap((chunk) => toReadonlyArray(chunk)), some2); +}; +var deferredUnsafeMake = (fiberId2) => { + const _deferred = { + ...CommitPrototype, + [DeferredTypeId]: deferredVariance, + state: make12(pending([])), + commit() { + return deferredAwait(this); + }, + blockingOn: fiberId2 + }; + return _deferred; +}; +var deferredMake = () => flatMap7(fiberId, (id) => deferredMakeAs(id)); +var deferredMakeAs = (fiberId2) => sync(() => deferredUnsafeMake(fiberId2)); +var deferredAwait = (self) => asyncInterrupt((resume) => { + const state = get6(self.state); + switch (state._tag) { + case OP_STATE_DONE: { + return resume(state.effect); + } + case OP_STATE_PENDING: { + state.joiners.push(resume); + return deferredInterruptJoiner(self, resume); + } + } +}, self.blockingOn); +var deferredComplete = /* @__PURE__ */ dual(2, (self, effect) => intoDeferred(effect, self)); +var deferredCompleteWith = /* @__PURE__ */ dual(2, (self, effect) => sync(() => { + const state = get6(self.state); + switch (state._tag) { + case OP_STATE_DONE: { + return false; + } + case OP_STATE_PENDING: { + set2(self.state, done(effect)); + for (let i = 0, len = state.joiners.length;i < len; i++) { + state.joiners[i](effect); + } + return true; + } + } +})); +var deferredDone = /* @__PURE__ */ dual(2, (self, exit2) => deferredCompleteWith(self, exit2)); +var deferredFailCause = /* @__PURE__ */ dual(2, (self, cause) => deferredCompleteWith(self, failCause(cause))); +var deferredInterrupt = (self) => flatMap7(fiberId, (fiberId2) => deferredCompleteWith(self, interruptWith(fiberId2))); +var deferredSucceed = /* @__PURE__ */ dual(2, (self, value) => deferredCompleteWith(self, succeed(value))); +var deferredUnsafeDone = (self, effect) => { + const state = get6(self.state); + if (state._tag === OP_STATE_PENDING) { + set2(self.state, done(effect)); + for (let i = 0, len = state.joiners.length;i < len; i++) { + state.joiners[i](effect); + } + } +}; +var deferredInterruptJoiner = (self, joiner) => sync(() => { + const state = get6(self.state); + if (state._tag === OP_STATE_PENDING) { + const index = state.joiners.indexOf(joiner); + if (index >= 0) { + state.joiners.splice(index, 1); + } + } +}); +var constContext = /* @__PURE__ */ withFiberRuntime((fiber) => exitSucceed(fiber.currentContext)); +var context = () => constContext; +var contextWithEffect = (f) => flatMap7(context(), f); +var provideContext = /* @__PURE__ */ dual(2, (self, context2) => fiberRefLocally(currentContext, context2)(self)); +var provideSomeContext = /* @__PURE__ */ dual(2, (self, context2) => fiberRefLocallyWith(currentContext, (parent) => merge3(parent, context2))(self)); +var mapInputContext = /* @__PURE__ */ dual(2, (self, f) => contextWithEffect((context2) => provideContext(self, f(context2)))); +var filterEffectOrElse = /* @__PURE__ */ dual(2, (self, options) => flatMap7(self, (a) => flatMap7(options.predicate(a), (pass) => pass ? succeed(a) : options.orElse(a)))); +var filterEffectOrFail = /* @__PURE__ */ dual(2, (self, options) => filterEffectOrElse(self, { + predicate: options.predicate, + orElse: (a) => fail2(options.orFailWith(a)) +})); +var currentSpanFromFiber = (fiber) => { + const span2 = fiber.currentSpan; + return span2 !== undefined && span2._tag === "Span" ? some2(span2) : none2(); +}; +var NoopSpanProto = { + _tag: "Span", + spanId: "noop", + traceId: "noop", + sampled: false, + status: { + _tag: "Ended", + startTime: /* @__PURE__ */ BigInt(0), + endTime: /* @__PURE__ */ BigInt(0), + exit: exitVoid + }, + attributes: /* @__PURE__ */ new Map, + links: [], + kind: "internal", + attribute() {}, + event() {}, + end() {}, + addLinks() {} +}; +var noopSpan = (options) => Object.assign(Object.create(NoopSpanProto), options); + +// node_modules/effect/dist/esm/Deferred.js +var _await = deferredAwait; +var done2 = deferredDone; +var interrupt3 = deferredInterrupt; +var unsafeMake3 = deferredUnsafeMake; + +// node_modules/effect/dist/esm/Exit.js +var isExit = exitIsExit; +var isSuccess = exitIsSuccess; +var failCause2 = exitFailCause; +var flatten6 = exitFlatten; +var match6 = exitMatch; +var succeed2 = exitSucceed; + +// node_modules/effect/dist/esm/MutableHashMap.js +var TypeId9 = /* @__PURE__ */ Symbol.for("effect/MutableHashMap"); +var MutableHashMapProto = { + [TypeId9]: TypeId9, + [Symbol.iterator]() { + return new MutableHashMapIterator(this); + }, + toString() { + return format(this.toJSON()); + }, + toJSON() { + return { + _id: "MutableHashMap", + values: Array.from(this).map(toJSON) + }; + }, + [NodeInspectSymbol]() { + return this.toJSON(); + }, + pipe() { + return pipeArguments(this, arguments); + } +}; + +class MutableHashMapIterator { + self; + referentialIterator; + bucketIterator; + constructor(self) { + this.self = self; + this.referentialIterator = self.referential[Symbol.iterator](); + } + next() { + if (this.bucketIterator !== undefined) { + return this.bucketIterator.next(); + } + const result = this.referentialIterator.next(); + if (result.done) { + this.bucketIterator = new BucketIterator(this.self.buckets.values()); + return this.next(); + } + return result; + } + [Symbol.iterator]() { + return new MutableHashMapIterator(this.self); + } +} + +class BucketIterator { + backing; + constructor(backing) { + this.backing = backing; + } + currentBucket; + next() { + if (this.currentBucket === undefined) { + const result2 = this.backing.next(); + if (result2.done) { + return result2; + } + this.currentBucket = result2.value[Symbol.iterator](); + } + const result = this.currentBucket.next(); + if (result.done) { + this.currentBucket = undefined; + return this.next(); + } + return result; + } +} +var empty17 = () => { + const self = Object.create(MutableHashMapProto); + self.referential = new Map; + self.buckets = new Map; + self.bucketsSize = 0; + return self; +}; +var get8 = /* @__PURE__ */ dual(2, (self, key) => { + if (isEqual(key) === false) { + return self.referential.has(key) ? some2(self.referential.get(key)) : none2(); + } + const hash2 = key[symbol](); + const bucket = self.buckets.get(hash2); + if (bucket === undefined) { + return none2(); + } + return getFromBucket(self, bucket, key); +}); +var getFromBucket = (self, bucket, key, remove5 = false) => { + for (let i = 0, len = bucket.length;i < len; i++) { + if (key[symbol2](bucket[i][0])) { + const value = bucket[i][1]; + if (remove5) { + bucket.splice(i, 1); + self.bucketsSize--; + } + return some2(value); + } + } + return none2(); +}; +var has4 = /* @__PURE__ */ dual(2, (self, key) => isSome2(get8(self, key))); +var set4 = /* @__PURE__ */ dual(3, (self, key, value) => { + if (isEqual(key) === false) { + self.referential.set(key, value); + return self; + } + const hash2 = key[symbol](); + const bucket = self.buckets.get(hash2); + if (bucket === undefined) { + self.buckets.set(hash2, [[key, value]]); + self.bucketsSize++; + return self; + } + removeFromBucket(self, bucket, key); + bucket.push([key, value]); + self.bucketsSize++; + return self; +}); +var removeFromBucket = (self, bucket, key) => { + for (let i = 0, len = bucket.length;i < len; i++) { + if (key[symbol2](bucket[i][0])) { + bucket.splice(i, 1); + self.bucketsSize--; + return; + } + } +}; +var remove5 = /* @__PURE__ */ dual(2, (self, key) => { + if (isEqual(key) === false) { + self.referential.delete(key); + return self; + } + const hash2 = key[symbol](); + const bucket = self.buckets.get(hash2); + if (bucket === undefined) { + return self; + } + removeFromBucket(self, bucket, key); + if (bucket.length === 0) { + self.buckets.delete(hash2); + } + return self; +}); +var size4 = (self) => { + return self.referential.size + self.bucketsSize; +}; + +// node_modules/effect/dist/esm/MutableList.js +var TypeId10 = /* @__PURE__ */ Symbol.for("effect/MutableList"); +var MutableListProto = { + [TypeId10]: TypeId10, + [Symbol.iterator]() { + let done3 = false; + let head3 = this.head; + return { + next() { + if (done3) { + return this.return(); + } + if (head3 == null) { + done3 = true; + return this.return(); + } + const value = head3.value; + head3 = head3.next; + return { + done: done3, + value + }; + }, + return(value) { + if (!done3) { + done3 = true; + } + return { + done: true, + value + }; + } + }; + }, + toString() { + return format(this.toJSON()); + }, + toJSON() { + return { + _id: "MutableList", + values: Array.from(this).map(toJSON) + }; + }, + [NodeInspectSymbol]() { + return this.toJSON(); + }, + pipe() { + return pipeArguments(this, arguments); + } +}; +var makeNode = (value) => ({ + value, + removed: false, + prev: undefined, + next: undefined +}); +var empty18 = () => { + const list = Object.create(MutableListProto); + list.head = undefined; + list.tail = undefined; + list._length = 0; + return list; +}; +var isEmpty6 = (self) => length(self) === 0; +var length = (self) => self._length; +var append3 = /* @__PURE__ */ dual(2, (self, value) => { + const node = makeNode(value); + if (self.head === undefined) { + self.head = node; + } + if (self.tail === undefined) { + self.tail = node; + } else { + self.tail.next = node; + node.prev = self.tail; + self.tail = node; + } + self._length += 1; + return self; +}); +var shift = (self) => { + const head3 = self.head; + if (head3 !== undefined) { + remove6(self, head3); + return head3.value; + } + return; +}; +var remove6 = (self, node) => { + if (node.removed) { + return; + } + node.removed = true; + if (node.prev !== undefined && node.next !== undefined) { + node.prev.next = node.next; + node.next.prev = node.prev; + } else if (node.prev !== undefined) { + self.tail = node.prev; + node.prev.next = undefined; + } else if (node.next !== undefined) { + self.head = node.next; + node.next.prev = undefined; + } else { + self.tail = undefined; + self.head = undefined; + } + if (self._length > 0) { + self._length -= 1; + } +}; + +// node_modules/effect/dist/esm/MutableQueue.js +var TypeId11 = /* @__PURE__ */ Symbol.for("effect/MutableQueue"); +var EmptyMutableQueue = /* @__PURE__ */ Symbol.for("effect/mutable/MutableQueue/Empty"); +var MutableQueueProto = { + [TypeId11]: TypeId11, + [Symbol.iterator]() { + return Array.from(this.queue)[Symbol.iterator](); + }, + toString() { + return format(this.toJSON()); + }, + toJSON() { + return { + _id: "MutableQueue", + values: Array.from(this).map(toJSON) + }; + }, + [NodeInspectSymbol]() { + return this.toJSON(); + }, + pipe() { + return pipeArguments(this, arguments); + } +}; +var make19 = (capacity) => { + const queue = Object.create(MutableQueueProto); + queue.queue = empty18(); + queue.capacity = capacity; + return queue; +}; +var unbounded = () => make19(undefined); +var offer = /* @__PURE__ */ dual(2, (self, value) => { + const queueLength = length(self.queue); + if (self.capacity !== undefined && queueLength === self.capacity) { + return false; + } + append3(value)(self.queue); + return true; +}); +var poll = /* @__PURE__ */ dual(2, (self, def) => { + if (isEmpty6(self.queue)) { + return def; + } + return shift(self.queue); +}); + +// node_modules/effect/dist/esm/internal/clock.js +var ClockSymbolKey = "effect/Clock"; +var ClockTypeId = /* @__PURE__ */ Symbol.for(ClockSymbolKey); +var clockTag = /* @__PURE__ */ GenericTag("effect/Clock"); +var MAX_TIMER_MILLIS = 2 ** 31 - 1; +var globalClockScheduler = { + unsafeSchedule(task, duration) { + const millis2 = toMillis(duration); + if (millis2 > MAX_TIMER_MILLIS) { + return constFalse; + } + let completed = false; + const handle = setTimeout(() => { + completed = true; + task(); + }, millis2); + return () => { + clearTimeout(handle); + return !completed; + }; + } +}; +var performanceNowNanos = /* @__PURE__ */ function() { + const bigint1e62 = /* @__PURE__ */ BigInt(1e6); + if (typeof performance === "undefined" || typeof performance.now !== "function") { + return () => BigInt(Date.now()) * bigint1e62; + } + let origin; + return () => { + if (origin === undefined) { + origin = BigInt(Date.now()) * bigint1e62 - BigInt(Math.round(performance.now() * 1e6)); + } + return origin + BigInt(Math.round(performance.now() * 1e6)); + }; +}(); +var processOrPerformanceNow = /* @__PURE__ */ function() { + const processHrtime = typeof process === "object" && "hrtime" in process && typeof process.hrtime.bigint === "function" ? process.hrtime : undefined; + if (!processHrtime) { + return performanceNowNanos; + } + const origin = /* @__PURE__ */ performanceNowNanos() - /* @__PURE__ */ processHrtime.bigint(); + return () => origin + processHrtime.bigint(); +}(); + +class ClockImpl { + [ClockTypeId] = ClockTypeId; + unsafeCurrentTimeMillis() { + return Date.now(); + } + unsafeCurrentTimeNanos() { + return processOrPerformanceNow(); + } + currentTimeMillis = /* @__PURE__ */ sync(() => this.unsafeCurrentTimeMillis()); + currentTimeNanos = /* @__PURE__ */ sync(() => this.unsafeCurrentTimeNanos()); + scheduler() { + return succeed(globalClockScheduler); + } + sleep(duration) { + return async_((resume) => { + const canceler = globalClockScheduler.unsafeSchedule(() => resume(void_), duration); + return asVoid(sync(canceler)); + }); + } +} +var make20 = () => new ClockImpl; + +// node_modules/effect/dist/esm/internal/opCodes/configError.js +var OP_AND = "And"; +var OP_OR = "Or"; +var OP_INVALID_DATA = "InvalidData"; +var OP_MISSING_DATA = "MissingData"; +var OP_SOURCE_UNAVAILABLE = "SourceUnavailable"; +var OP_UNSUPPORTED = "Unsupported"; + +// node_modules/effect/dist/esm/internal/configError.js +var ConfigErrorSymbolKey = "effect/ConfigError"; +var ConfigErrorTypeId = /* @__PURE__ */ Symbol.for(ConfigErrorSymbolKey); +var proto2 = { + _tag: "ConfigError", + [ConfigErrorTypeId]: ConfigErrorTypeId +}; +var And = (self, that) => { + const error = Object.create(proto2); + error._op = OP_AND; + error.left = self; + error.right = that; + Object.defineProperty(error, "toString", { + enumerable: false, + value() { + return `${this.left} and ${this.right}`; + } + }); + Object.defineProperty(error, "message", { + enumerable: false, + get() { + return this.toString(); + } + }); + return error; +}; +var Or = (self, that) => { + const error = Object.create(proto2); + error._op = OP_OR; + error.left = self; + error.right = that; + Object.defineProperty(error, "toString", { + enumerable: false, + value() { + return `${this.left} or ${this.right}`; + } + }); + Object.defineProperty(error, "message", { + enumerable: false, + get() { + return this.toString(); + } + }); + return error; +}; +var InvalidData = (path, message, options = { + pathDelim: "." +}) => { + const error = Object.create(proto2); + error._op = OP_INVALID_DATA; + error.path = path; + error.message = message; + Object.defineProperty(error, "toString", { + enumerable: false, + value() { + const path2 = pipe(this.path, join(options.pathDelim)); + return `(Invalid data at ${path2}: "${this.message}")`; + } + }); + return error; +}; +var MissingData = (path, message, options = { + pathDelim: "." +}) => { + const error = Object.create(proto2); + error._op = OP_MISSING_DATA; + error.path = path; + error.message = message; + Object.defineProperty(error, "toString", { + enumerable: false, + value() { + const path2 = pipe(this.path, join(options.pathDelim)); + return `(Missing data at ${path2}: "${this.message}")`; + } + }); + return error; +}; +var SourceUnavailable = (path, message, cause, options = { + pathDelim: "." +}) => { + const error = Object.create(proto2); + error._op = OP_SOURCE_UNAVAILABLE; + error.path = path; + error.message = message; + error.cause = cause; + Object.defineProperty(error, "toString", { + enumerable: false, + value() { + const path2 = pipe(this.path, join(options.pathDelim)); + return `(Source unavailable at ${path2}: "${this.message}")`; + } + }); + return error; +}; +var Unsupported = (path, message, options = { + pathDelim: "." +}) => { + const error = Object.create(proto2); + error._op = OP_UNSUPPORTED; + error.path = path; + error.message = message; + Object.defineProperty(error, "toString", { + enumerable: false, + value() { + const path2 = pipe(this.path, join(options.pathDelim)); + return `(Unsupported operation at ${path2}: "${this.message}")`; + } + }); + return error; +}; +var prefixed = /* @__PURE__ */ dual(2, (self, prefix) => { + switch (self._op) { + case OP_AND: { + return And(prefixed(self.left, prefix), prefixed(self.right, prefix)); + } + case OP_OR: { + return Or(prefixed(self.left, prefix), prefixed(self.right, prefix)); + } + case OP_INVALID_DATA: { + return InvalidData([...prefix, ...self.path], self.message); + } + case OP_MISSING_DATA: { + return MissingData([...prefix, ...self.path], self.message); + } + case OP_SOURCE_UNAVAILABLE: { + return SourceUnavailable([...prefix, ...self.path], self.message, self.cause); + } + case OP_UNSUPPORTED: { + return Unsupported([...prefix, ...self.path], self.message); + } + } +}); + +// node_modules/effect/dist/esm/internal/configProvider/pathPatch.js +var empty19 = { + _tag: "Empty" +}; +var patch5 = /* @__PURE__ */ dual(2, (path, patch6) => { + let input = of3(patch6); + let output = path; + while (isCons(input)) { + const patch7 = input.head; + switch (patch7._tag) { + case "Empty": { + input = input.tail; + break; + } + case "AndThen": { + input = cons(patch7.first, cons(patch7.second, input.tail)); + break; + } + case "MapName": { + output = map3(output, patch7.f); + input = input.tail; + break; + } + case "Nested": { + output = prepend(output, patch7.name); + input = input.tail; + break; + } + case "Unnested": { + const containsName = pipe(head(output), contains(patch7.name)); + if (containsName) { + output = tailNonEmpty(output); + input = input.tail; + } else { + return left2(MissingData(output, `Expected ${patch7.name} to be in path in ConfigProvider#unnested`)); + } + break; + } + } + } + return right2(output); +}); + +// node_modules/effect/dist/esm/internal/opCodes/config.js +var OP_CONSTANT = "Constant"; +var OP_FAIL2 = "Fail"; +var OP_FALLBACK = "Fallback"; +var OP_DESCRIBED = "Described"; +var OP_LAZY = "Lazy"; +var OP_MAP_OR_FAIL = "MapOrFail"; +var OP_NESTED = "Nested"; +var OP_PRIMITIVE = "Primitive"; +var OP_SEQUENCE = "Sequence"; +var OP_HASHMAP = "HashMap"; +var OP_ZIP_WITH = "ZipWith"; + +// node_modules/effect/dist/esm/internal/configProvider.js +var concat = (l, r) => [...l, ...r]; +var ConfigProviderSymbolKey = "effect/ConfigProvider"; +var ConfigProviderTypeId = /* @__PURE__ */ Symbol.for(ConfigProviderSymbolKey); +var configProviderTag = /* @__PURE__ */ GenericTag("effect/ConfigProvider"); +var FlatConfigProviderSymbolKey = "effect/ConfigProviderFlat"; +var FlatConfigProviderTypeId = /* @__PURE__ */ Symbol.for(FlatConfigProviderSymbolKey); +var make22 = (options) => ({ + [ConfigProviderTypeId]: ConfigProviderTypeId, + pipe() { + return pipeArguments(this, arguments); + }, + ...options +}); +var makeFlat = (options) => ({ + [FlatConfigProviderTypeId]: FlatConfigProviderTypeId, + patch: options.patch, + load: (path, config, split = true) => options.load(path, config, split), + enumerateChildren: options.enumerateChildren +}); +var fromFlat = (flat) => make22({ + load: (config) => flatMap7(fromFlatLoop(flat, empty(), config, false), (chunk) => match2(head(chunk), { + onNone: () => fail2(MissingData(empty(), `Expected a single value having structure: ${config}`)), + onSome: succeed + })), + flattened: flat +}); +var fromEnv = (options) => { + const { + pathDelim, + seqDelim + } = Object.assign({}, { + pathDelim: "_", + seqDelim: "," + }, options); + const makePathString = (path) => pipe(path, join(pathDelim)); + const unmakePathString = (pathString) => pathString.split(pathDelim); + const getEnv = () => typeof process !== "undefined" && ("env" in process) && typeof process.env === "object" ? process.env : {}; + const load = (path, primitive, split = true) => { + const pathString = makePathString(path); + const current = getEnv(); + const valueOpt = pathString in current ? some2(current[pathString]) : none2(); + return pipe(valueOpt, mapError(() => MissingData(path, `Expected ${pathString} to exist in the process context`)), flatMap7((value) => parsePrimitive(value, path, primitive, seqDelim, split))); + }; + const enumerateChildren = (path) => sync(() => { + const current = getEnv(); + const keys3 = Object.keys(current); + const keyPaths = keys3.map((value) => unmakePathString(value.toUpperCase())); + const filteredKeyPaths = keyPaths.filter((keyPath) => { + for (let i = 0;i < path.length; i++) { + const pathComponent = pipe(path, unsafeGet(i)); + const currentElement = keyPath[i]; + if (currentElement === undefined || pathComponent !== currentElement) { + return false; + } + } + return true; + }).flatMap((keyPath) => keyPath.slice(path.length, path.length + 1)); + return fromIterable5(filteredKeyPaths); + }); + return fromFlat(makeFlat({ + load, + enumerateChildren, + patch: empty19 + })); +}; +var extend = (leftDef, rightDef, left3, right3) => { + const leftPad = unfold(left3.length, (index) => index >= right3.length ? none2() : some2([leftDef(index), index + 1])); + const rightPad = unfold(right3.length, (index) => index >= left3.length ? none2() : some2([rightDef(index), index + 1])); + const leftExtension = concat(left3, leftPad); + const rightExtension = concat(right3, rightPad); + return [leftExtension, rightExtension]; +}; +var appendConfigPath = (path, config) => { + let op = config; + if (op._tag === "Nested") { + const out = path.slice(); + while (op._tag === "Nested") { + out.push(op.name); + op = op.config; + } + return out; + } + return path; +}; +var fromFlatLoop = (flat, prefix, config, split) => { + const op = config; + switch (op._tag) { + case OP_CONSTANT: { + return succeed(of(op.value)); + } + case OP_DESCRIBED: { + return suspend(() => fromFlatLoop(flat, prefix, op.config, split)); + } + case OP_FAIL2: { + return fail2(MissingData(prefix, op.message)); + } + case OP_FALLBACK: { + return pipe(suspend(() => fromFlatLoop(flat, prefix, op.first, split)), catchAll((error1) => { + if (op.condition(error1)) { + return pipe(fromFlatLoop(flat, prefix, op.second, split), catchAll((error2) => fail2(Or(error1, error2)))); + } + return fail2(error1); + })); + } + case OP_LAZY: { + return suspend(() => fromFlatLoop(flat, prefix, op.config(), split)); + } + case OP_MAP_OR_FAIL: { + return suspend(() => pipe(fromFlatLoop(flat, prefix, op.original, split), flatMap7(forEachSequential((a) => pipe(op.mapOrFail(a), mapError(prefixed(appendConfigPath(prefix, op.original)))))))); + } + case OP_NESTED: { + return suspend(() => fromFlatLoop(flat, concat(prefix, of(op.name)), op.config, split)); + } + case OP_PRIMITIVE: { + return pipe(patch5(prefix, flat.patch), flatMap7((prefix2) => pipe(flat.load(prefix2, op, split), flatMap7((values3) => { + if (values3.length === 0) { + const name = pipe(last(prefix2), getOrElse(() => "")); + return fail2(MissingData([], `Expected ${op.description} with name ${name}`)); + } + return succeed(values3); + })))); + } + case OP_SEQUENCE: { + return pipe(patch5(prefix, flat.patch), flatMap7((patchedPrefix) => pipe(flat.enumerateChildren(patchedPrefix), flatMap7(indicesFrom), flatMap7((indices) => { + if (indices.length === 0) { + return suspend(() => map9(fromFlatLoop(flat, prefix, op.config, true), of)); + } + return pipe(forEachSequential(indices, (index) => fromFlatLoop(flat, append(prefix, `[${index}]`), op.config, true)), map9((chunkChunk) => { + const flattened = flatten(chunkChunk); + if (flattened.length === 0) { + return of(empty()); + } + return of(flattened); + })); + })))); + } + case OP_HASHMAP: { + return suspend(() => pipe(patch5(prefix, flat.patch), flatMap7((prefix2) => pipe(flat.enumerateChildren(prefix2), flatMap7((keys3) => { + return pipe(keys3, forEachSequential((key) => fromFlatLoop(flat, concat(prefix2, of(key)), op.valueConfig, split)), map9((matrix) => { + if (matrix.length === 0) { + return of(empty8()); + } + return pipe(transpose(matrix), map3((values3) => fromIterable6(zip(fromIterable(keys3), values3)))); + })); + }))))); + } + case OP_ZIP_WITH: { + return suspend(() => pipe(fromFlatLoop(flat, prefix, op.left, split), either2, flatMap7((left3) => pipe(fromFlatLoop(flat, prefix, op.right, split), either2, flatMap7((right3) => { + if (isLeft2(left3) && isLeft2(right3)) { + return fail2(And(left3.left, right3.left)); + } + if (isLeft2(left3) && isRight2(right3)) { + return fail2(left3.left); + } + if (isRight2(left3) && isLeft2(right3)) { + return fail2(right3.left); + } + if (isRight2(left3) && isRight2(right3)) { + const path = pipe(prefix, join(".")); + const fail3 = fromFlatLoopFail(prefix, path); + const [lefts, rights] = extend(fail3, fail3, pipe(left3.right, map3(right2)), pipe(right3.right, map3(right2))); + return pipe(lefts, zip(rights), forEachSequential(([left4, right4]) => pipe(zip2(left4, right4), map9(([left5, right5]) => op.zip(left5, right5))))); + } + throw new Error("BUG: ConfigProvider.fromFlatLoop - please report an issue at https://github.com/Effect-TS/effect/issues"); + }))))); + } + } +}; +var fromFlatLoopFail = (prefix, path) => (index) => left2(MissingData(prefix, `The element at index ${index} in a sequence at path "${path}" was missing`)); +var splitPathString = (text, delim) => { + const split = text.split(new RegExp(`\\s*${escape(delim)}\\s*`)); + return split; +}; +var parsePrimitive = (text, path, primitive, delimiter, split) => { + if (!split) { + return pipe(primitive.parse(text), mapBoth2({ + onFailure: prefixed(path), + onSuccess: of + })); + } + return pipe(splitPathString(text, delimiter), forEachSequential((char) => primitive.parse(char.trim())), mapError(prefixed(path))); +}; +var transpose = (array4) => { + return Object.keys(array4[0]).map((column) => array4.map((row) => row[column])); +}; +var indicesFrom = (quotedIndices) => pipe(forEachSequential(quotedIndices, parseQuotedIndex), mapBoth2({ + onFailure: () => empty(), + onSuccess: sort(Order) +}), either2, map9(merge)); +var QUOTED_INDEX_REGEX = /^(\[(\d+)\])$/; +var parseQuotedIndex = (str) => { + const match7 = str.match(QUOTED_INDEX_REGEX); + if (match7 !== null) { + const matchedIndex = match7[2]; + return pipe(matchedIndex !== undefined && matchedIndex.length > 0 ? some2(matchedIndex) : none2(), flatMap(parseInteger)); + } + return none2(); +}; +var parseInteger = (str) => { + const parsedIndex = Number.parseInt(str); + return Number.isNaN(parsedIndex) ? none2() : some2(parsedIndex); +}; + +// node_modules/effect/dist/esm/internal/defaultServices/console.js +var TypeId12 = /* @__PURE__ */ Symbol.for("effect/Console"); +var consoleTag = /* @__PURE__ */ GenericTag("effect/Console"); +var defaultConsole = { + [TypeId12]: TypeId12, + assert(condition, ...args) { + return sync(() => { + console.assert(condition, ...args); + }); + }, + clear: /* @__PURE__ */ sync(() => { + console.clear(); + }), + count(label) { + return sync(() => { + console.count(label); + }); + }, + countReset(label) { + return sync(() => { + console.countReset(label); + }); + }, + debug(...args) { + return sync(() => { + console.debug(...args); + }); + }, + dir(item, options) { + return sync(() => { + console.dir(item, options); + }); + }, + dirxml(...args) { + return sync(() => { + console.dirxml(...args); + }); + }, + error(...args) { + return sync(() => { + console.error(...args); + }); + }, + group(options) { + return options?.collapsed ? sync(() => console.groupCollapsed(options?.label)) : sync(() => console.group(options?.label)); + }, + groupEnd: /* @__PURE__ */ sync(() => { + console.groupEnd(); + }), + info(...args) { + return sync(() => { + console.info(...args); + }); + }, + log(...args) { + return sync(() => { + console.log(...args); + }); + }, + table(tabularData, properties) { + return sync(() => { + console.table(tabularData, properties); + }); + }, + time(label) { + return sync(() => console.time(label)); + }, + timeEnd(label) { + return sync(() => console.timeEnd(label)); + }, + timeLog(label, ...args) { + return sync(() => { + console.timeLog(label, ...args); + }); + }, + trace(...args) { + return sync(() => { + console.trace(...args); + }); + }, + warn(...args) { + return sync(() => { + console.warn(...args); + }); + }, + unsafe: console +}; + +// node_modules/effect/dist/esm/internal/random.js +var RandomSymbolKey = "effect/Random"; +var RandomTypeId = /* @__PURE__ */ Symbol.for(RandomSymbolKey); +var randomTag = /* @__PURE__ */ GenericTag("effect/Random"); + +class RandomImpl { + seed; + [RandomTypeId] = RandomTypeId; + PRNG; + constructor(seed) { + this.seed = seed; + this.PRNG = new PCGRandom(seed); + } + get next() { + return sync(() => this.PRNG.number()); + } + get nextBoolean() { + return map9(this.next, (n) => n > 0.5); + } + get nextInt() { + return sync(() => this.PRNG.integer(Number.MAX_SAFE_INTEGER)); + } + nextRange(min2, max2) { + return map9(this.next, (n) => (max2 - min2) * n + min2); + } + nextIntBetween(min2, max2) { + return sync(() => this.PRNG.integer(max2 - min2) + min2); + } + shuffle(elements) { + return shuffleWith(elements, (n) => this.nextIntBetween(0, n)); + } +} +var shuffleWith = (elements, nextIntBounded) => { + return suspend(() => pipe(sync(() => Array.from(elements)), flatMap7((buffer) => { + const numbers = []; + for (let i = buffer.length;i >= 2; i = i - 1) { + numbers.push(i); + } + return pipe(numbers, forEachSequentialDiscard((n) => pipe(nextIntBounded(n), map9((k) => swap(buffer, n - 1, k)))), as(fromIterable2(buffer))); + }))); +}; +var swap = (buffer, index1, index2) => { + const tmp = buffer[index1]; + buffer[index1] = buffer[index2]; + buffer[index2] = tmp; + return buffer; +}; +var make23 = (seed) => new RandomImpl(hash(seed)); + +class FixedRandomImpl { + values; + [RandomTypeId] = RandomTypeId; + index = 0; + constructor(values3) { + this.values = values3; + if (values3.length === 0) { + throw new Error("Requires at least one value"); + } + } + getNextValue() { + const value = this.values[this.index]; + this.index = (this.index + 1) % this.values.length; + return value; + } + get next() { + return sync(() => { + const value = this.getNextValue(); + if (typeof value === "number") { + return Math.max(0, Math.min(1, value)); + } + return hash(value) / 2147483647; + }); + } + get nextBoolean() { + return sync(() => { + const value = this.getNextValue(); + if (typeof value === "boolean") { + return value; + } + return hash(value) % 2 === 0; + }); + } + get nextInt() { + return sync(() => { + const value = this.getNextValue(); + if (typeof value === "number" && Number.isFinite(value)) { + return Math.round(value); + } + return Math.abs(hash(value)); + }); + } + nextRange(min2, max2) { + return map9(this.next, (n) => (max2 - min2) * n + min2); + } + nextIntBetween(min2, max2) { + return sync(() => { + const value = this.getNextValue(); + if (typeof value === "number" && Number.isFinite(value)) { + return Math.max(min2, Math.min(max2 - 1, Math.round(value))); + } + const hash2 = Math.abs(hash(value)); + return min2 + hash2 % (max2 - min2); + }); + } + shuffle(elements) { + return shuffleWith(elements, (n) => this.nextIntBetween(0, n)); + } +} +var fixed = (values3) => new FixedRandomImpl(values3); + +// node_modules/effect/dist/esm/internal/tracer.js +var TracerTypeId = /* @__PURE__ */ Symbol.for("effect/Tracer"); +var make24 = (options) => ({ + [TracerTypeId]: TracerTypeId, + ...options +}); +var tracerTag = /* @__PURE__ */ GenericTag("effect/Tracer"); +var spanTag = /* @__PURE__ */ GenericTag("effect/ParentSpan"); +var randomHexString = /* @__PURE__ */ function() { + const characters = "abcdef0123456789"; + const charactersLength = characters.length; + return function(length2) { + let result = ""; + for (let i = 0;i < length2; i++) { + result += characters.charAt(Math.floor(Math.random() * charactersLength)); + } + return result; + }; +}(); + +class NativeSpan { + name; + parent; + context; + startTime; + kind; + _tag = "Span"; + spanId; + traceId = "native"; + sampled = true; + status; + attributes; + events = []; + links; + constructor(name, parent, context2, links, startTime, kind) { + this.name = name; + this.parent = parent; + this.context = context2; + this.startTime = startTime; + this.kind = kind; + this.status = { + _tag: "Started", + startTime + }; + this.attributes = new Map; + this.traceId = parent._tag === "Some" ? parent.value.traceId : randomHexString(32); + this.spanId = randomHexString(16); + this.links = Array.from(links); + } + end(endTime, exit2) { + this.status = { + _tag: "Ended", + endTime, + exit: exit2, + startTime: this.status.startTime + }; + } + attribute(key, value) { + this.attributes.set(key, value); + } + event(name, startTime, attributes) { + this.events.push([name, startTime, attributes ?? {}]); + } + addLinks(links) { + this.links.push(...links); + } +} +var nativeTracer = /* @__PURE__ */ make24({ + span: (name, parent, context2, links, startTime, kind) => new NativeSpan(name, parent, context2, links, startTime, kind), + context: (f) => f() +}); +var addSpanStackTrace = (options) => { + if (options?.captureStackTrace === false) { + return options; + } else if (options?.captureStackTrace !== undefined && typeof options.captureStackTrace !== "boolean") { + return options; + } + const limit = Error.stackTraceLimit; + Error.stackTraceLimit = 3; + const traceError = new Error; + Error.stackTraceLimit = limit; + let cache = false; + return { + ...options, + captureStackTrace: () => { + if (cache !== false) { + return cache; + } + if (traceError.stack !== undefined) { + const stack = traceError.stack.split(` +`); + if (stack[3] !== undefined) { + cache = stack[3].trim(); + return cache; + } + } + } + }; +}; +var DisablePropagation = /* @__PURE__ */ Reference2()("effect/Tracer/DisablePropagation", { + defaultValue: constFalse +}); + +// node_modules/effect/dist/esm/internal/defaultServices.js +var liveServices = /* @__PURE__ */ pipe(/* @__PURE__ */ empty3(), /* @__PURE__ */ add2(clockTag, /* @__PURE__ */ make20()), /* @__PURE__ */ add2(consoleTag, defaultConsole), /* @__PURE__ */ add2(randomTag, /* @__PURE__ */ make23(/* @__PURE__ */ Math.random())), /* @__PURE__ */ add2(configProviderTag, /* @__PURE__ */ fromEnv()), /* @__PURE__ */ add2(tracerTag, nativeTracer)); +var currentServices = /* @__PURE__ */ globalValue(/* @__PURE__ */ Symbol.for("effect/DefaultServices/currentServices"), () => fiberRefUnsafeMakeContext(liveServices)); +var sleep = (duration) => { + const decodedDuration = decode(duration); + return clockWith((clock) => clock.sleep(decodedDuration)); +}; +var defaultServicesWith = (f) => withFiberRuntime((fiber) => f(fiber.currentDefaultServices)); +var clockWith = (f) => defaultServicesWith((services) => f(services.unsafeMap.get(clockTag.key))); +var currentTimeMillis = /* @__PURE__ */ clockWith((clock) => clock.currentTimeMillis); +var currentTimeNanos = /* @__PURE__ */ clockWith((clock) => clock.currentTimeNanos); +var withClock = /* @__PURE__ */ dual(2, (effect, c) => fiberRefLocallyWith(currentServices, add2(clockTag, c))(effect)); +var withConfigProvider = /* @__PURE__ */ dual(2, (self, provider) => fiberRefLocallyWith(currentServices, add2(configProviderTag, provider))(self)); +var configProviderWith = (f) => defaultServicesWith((services) => f(services.unsafeMap.get(configProviderTag.key))); +var config = (config2) => configProviderWith((_) => _.load(config2)); +var randomWith = (f) => defaultServicesWith((services) => f(services.unsafeMap.get(randomTag.key))); +var withRandom = /* @__PURE__ */ dual(2, (effect, value) => fiberRefLocallyWith(currentServices, add2(randomTag, value))(effect)); +var tracerWith = (f) => defaultServicesWith((services) => f(services.unsafeMap.get(tracerTag.key))); +var withTracer = /* @__PURE__ */ dual(2, (effect, value) => fiberRefLocallyWith(currentServices, add2(tracerTag, value))(effect)); + +// node_modules/effect/dist/esm/Clock.js +var sleep2 = sleep; +var currentTimeMillis2 = currentTimeMillis; +var currentTimeNanos2 = currentTimeNanos; +var clockWith2 = clockWith; +var Clock = clockTag; + +// node_modules/effect/dist/esm/internal/fiberRefs.js +function unsafeMake4(fiberRefLocals) { + return new FiberRefsImpl(fiberRefLocals); +} +function empty20() { + return unsafeMake4(new Map); +} +var FiberRefsSym = /* @__PURE__ */ Symbol.for("effect/FiberRefs"); + +class FiberRefsImpl { + locals; + [FiberRefsSym] = FiberRefsSym; + constructor(locals) { + this.locals = locals; + } + pipe() { + return pipeArguments(this, arguments); + } +} +var findAncestor = (_ref, _parentStack, _childStack, _childModified = false) => { + const ref = _ref; + let parentStack = _parentStack; + let childStack = _childStack; + let childModified = _childModified; + let ret = undefined; + while (ret === undefined) { + if (isNonEmptyReadonlyArray(parentStack) && isNonEmptyReadonlyArray(childStack)) { + const parentFiberId = headNonEmpty(parentStack)[0]; + const parentAncestors = tailNonEmpty(parentStack); + const childFiberId = headNonEmpty(childStack)[0]; + const childRefValue = headNonEmpty(childStack)[1]; + const childAncestors = tailNonEmpty(childStack); + if (parentFiberId.startTimeMillis < childFiberId.startTimeMillis) { + childStack = childAncestors; + childModified = true; + } else if (parentFiberId.startTimeMillis > childFiberId.startTimeMillis) { + parentStack = parentAncestors; + } else { + if (parentFiberId.id < childFiberId.id) { + childStack = childAncestors; + childModified = true; + } else if (parentFiberId.id > childFiberId.id) { + parentStack = parentAncestors; + } else { + ret = [childRefValue, childModified]; + } + } + } else { + ret = [ref.initial, true]; + } + } + return ret; +}; +var joinAs = /* @__PURE__ */ dual(3, (self, fiberId2, that) => { + const parentFiberRefs = new Map(self.locals); + that.locals.forEach((childStack, fiberRef) => { + const childValue = childStack[0][1]; + if (!childStack[0][0][symbol2](fiberId2)) { + if (!parentFiberRefs.has(fiberRef)) { + if (equals(childValue, fiberRef.initial)) { + return; + } + parentFiberRefs.set(fiberRef, [[fiberId2, fiberRef.join(fiberRef.initial, childValue)]]); + return; + } + const parentStack = parentFiberRefs.get(fiberRef); + const [ancestor, wasModified] = findAncestor(fiberRef, parentStack, childStack); + if (wasModified) { + const patch6 = fiberRef.diff(ancestor, childValue); + const oldValue = parentStack[0][1]; + const newValue = fiberRef.join(oldValue, fiberRef.patch(patch6)(oldValue)); + if (!equals(oldValue, newValue)) { + let newStack; + const parentFiberId = parentStack[0][0]; + if (parentFiberId[symbol2](fiberId2)) { + newStack = [[parentFiberId, newValue], ...parentStack.slice(1)]; + } else { + newStack = [[fiberId2, newValue], ...parentStack]; + } + parentFiberRefs.set(fiberRef, newStack); + } + } + } + }); + return new FiberRefsImpl(parentFiberRefs); +}); +var forkAs = /* @__PURE__ */ dual(2, (self, childId) => { + const map10 = new Map; + unsafeForkAs(self, map10, childId); + return new FiberRefsImpl(map10); +}); +var unsafeForkAs = (self, map10, fiberId2) => { + self.locals.forEach((stack, fiberRef) => { + const oldValue = stack[0][1]; + const newValue = fiberRef.patch(fiberRef.fork)(oldValue); + if (equals(oldValue, newValue)) { + map10.set(fiberRef, stack); + } else { + map10.set(fiberRef, [[fiberId2, newValue], ...stack]); + } + }); +}; +var fiberRefs = (self) => fromIterable5(self.locals.keys()); +var setAll = (self) => forEachSequentialDiscard(fiberRefs(self), (fiberRef) => fiberRefSet(fiberRef, getOrDefault(self, fiberRef))); +var delete_ = /* @__PURE__ */ dual(2, (self, fiberRef) => { + const locals = new Map(self.locals); + locals.delete(fiberRef); + return new FiberRefsImpl(locals); +}); +var get9 = /* @__PURE__ */ dual(2, (self, fiberRef) => { + if (!self.locals.has(fiberRef)) { + return none2(); + } + return some2(headNonEmpty(self.locals.get(fiberRef))[1]); +}); +var getOrDefault = /* @__PURE__ */ dual(2, (self, fiberRef) => pipe(get9(self, fiberRef), getOrElse(() => fiberRef.initial))); +var updateAs = /* @__PURE__ */ dual(2, (self, { + fiberId: fiberId2, + fiberRef, + value +}) => { + if (self.locals.size === 0) { + return new FiberRefsImpl(new Map([[fiberRef, [[fiberId2, value]]]])); + } + const locals = new Map(self.locals); + unsafeUpdateAs(locals, fiberId2, fiberRef, value); + return new FiberRefsImpl(locals); +}); +var unsafeUpdateAs = (locals, fiberId2, fiberRef, value) => { + const oldStack = locals.get(fiberRef) ?? []; + let newStack; + if (isNonEmptyReadonlyArray(oldStack)) { + const [currentId, currentValue] = headNonEmpty(oldStack); + if (currentId[symbol2](fiberId2)) { + if (equals(currentValue, value)) { + return; + } else { + newStack = [[fiberId2, value], ...oldStack.slice(1)]; + } + } else { + newStack = [[fiberId2, value], ...oldStack]; + } + } else { + newStack = [[fiberId2, value]]; + } + locals.set(fiberRef, newStack); +}; +var updateManyAs = /* @__PURE__ */ dual(2, (self, { + entries: entries2, + forkAs: forkAs2 +}) => { + if (self.locals.size === 0) { + return new FiberRefsImpl(new Map(entries2)); + } + const locals = new Map(self.locals); + if (forkAs2 !== undefined) { + unsafeForkAs(self, locals, forkAs2); + } + entries2.forEach(([fiberRef, values3]) => { + if (values3.length === 1) { + unsafeUpdateAs(locals, values3[0][0], fiberRef, values3[0][1]); + } else { + values3.forEach(([fiberId2, value]) => { + unsafeUpdateAs(locals, fiberId2, fiberRef, value); + }); + } + }); + return new FiberRefsImpl(locals); +}); + +// node_modules/effect/dist/esm/FiberRefs.js +var get10 = get9; +var getOrDefault2 = getOrDefault; +var joinAs2 = joinAs; +var setAll2 = setAll; +var updateManyAs2 = updateManyAs; +var empty21 = empty20; + +// node_modules/effect/dist/esm/LogLevel.js +var All = logLevelAll; +var Fatal = logLevelFatal; +var Error2 = logLevelError; +var Warning = logLevelWarning; +var Info = logLevelInfo; +var Debug = logLevelDebug; +var Trace = logLevelTrace; +var None3 = logLevelNone; +var Order5 = /* @__PURE__ */ pipe(Order, /* @__PURE__ */ mapInput2((level) => level.ordinal)); +var greaterThan4 = /* @__PURE__ */ greaterThan(Order5); +var fromLiteral = (literal) => { + switch (literal) { + case "All": + return All; + case "Debug": + return Debug; + case "Error": + return Error2; + case "Fatal": + return Fatal; + case "Info": + return Info; + case "Trace": + return Trace; + case "None": + return None3; + case "Warning": + return Warning; + } +}; + +// node_modules/effect/dist/esm/internal/logSpan.js +var make25 = (label, startTime) => ({ + label, + startTime +}); +var formatLabel = (key) => key.replace(/[\s="]/g, "_"); +var render = (now) => (self) => { + const label = formatLabel(self.label); + return `${label}=${now - self.startTime}ms`; +}; + +// node_modules/effect/dist/esm/LogSpan.js +var make26 = make25; + +// node_modules/effect/dist/esm/Effectable.js +var EffectPrototype2 = EffectPrototype; +var CommitPrototype2 = CommitPrototype; +var Base2 = Base; +class Class extends Base2 { +} + +// node_modules/effect/dist/esm/Readable.js +var TypeId13 = /* @__PURE__ */ Symbol.for("effect/Readable"); +var Proto = { + [TypeId13]: TypeId13, + pipe() { + return pipeArguments(this, arguments); + } +}; + +// node_modules/effect/dist/esm/internal/ref.js +var RefTypeId = /* @__PURE__ */ Symbol.for("effect/Ref"); +var refVariance = { + _A: (_) => _ +}; + +class RefImpl extends Class { + ref; + commit() { + return this.get; + } + [RefTypeId] = refVariance; + [TypeId13] = TypeId13; + constructor(ref) { + super(); + this.ref = ref; + this.get = sync(() => get6(this.ref)); + } + get; + modify(f) { + return sync(() => { + const current = get6(this.ref); + const [b, a] = f(current); + if (current !== a) { + set2(a)(this.ref); + } + return b; + }); + } +} +var unsafeMake5 = (value) => new RefImpl(make12(value)); +var make27 = (value) => sync(() => unsafeMake5(value)); +var get11 = (self) => self.get; +var set5 = /* @__PURE__ */ dual(2, (self, value) => self.modify(() => [undefined, value])); +var getAndSet = /* @__PURE__ */ dual(2, (self, value) => self.modify((a) => [a, value])); +var modify3 = /* @__PURE__ */ dual(2, (self, f) => self.modify(f)); +var update2 = /* @__PURE__ */ dual(2, (self, f) => self.modify((a) => [undefined, f(a)])); + +// node_modules/effect/dist/esm/Ref.js +var make28 = make27; +var get12 = get11; +var getAndSet2 = getAndSet; +var update3 = update2; + +// node_modules/effect/dist/esm/Tracer.js +var tracerWith2 = tracerWith; + +// node_modules/effect/dist/esm/internal/fiberRefs/patch.js +var OP_EMPTY2 = "Empty"; +var OP_ADD = "Add"; +var OP_REMOVE = "Remove"; +var OP_UPDATE = "Update"; +var OP_AND_THEN = "AndThen"; +var empty22 = { + _tag: OP_EMPTY2 +}; +var diff5 = (oldValue, newValue) => { + const missingLocals = new Map(oldValue.locals); + let patch6 = empty22; + for (const [fiberRef, pairs] of newValue.locals.entries()) { + const newValue2 = headNonEmpty(pairs)[1]; + const old = missingLocals.get(fiberRef); + if (old !== undefined) { + const oldValue2 = headNonEmpty(old)[1]; + if (!equals(oldValue2, newValue2)) { + patch6 = combine7({ + _tag: OP_UPDATE, + fiberRef, + patch: fiberRef.diff(oldValue2, newValue2) + })(patch6); + } + } else { + patch6 = combine7({ + _tag: OP_ADD, + fiberRef, + value: newValue2 + })(patch6); + } + missingLocals.delete(fiberRef); + } + for (const [fiberRef] of missingLocals.entries()) { + patch6 = combine7({ + _tag: OP_REMOVE, + fiberRef + })(patch6); + } + return patch6; +}; +var combine7 = /* @__PURE__ */ dual(2, (self, that) => ({ + _tag: OP_AND_THEN, + first: self, + second: that +})); +var patch6 = /* @__PURE__ */ dual(3, (self, fiberId2, oldValue) => { + let fiberRefs2 = oldValue; + let patches = of(self); + while (isNonEmptyReadonlyArray(patches)) { + const head3 = headNonEmpty(patches); + const tail = tailNonEmpty(patches); + switch (head3._tag) { + case OP_EMPTY2: { + patches = tail; + break; + } + case OP_ADD: { + fiberRefs2 = updateAs(fiberRefs2, { + fiberId: fiberId2, + fiberRef: head3.fiberRef, + value: head3.value + }); + patches = tail; + break; + } + case OP_REMOVE: { + fiberRefs2 = delete_(fiberRefs2, head3.fiberRef); + patches = tail; + break; + } + case OP_UPDATE: { + const value = getOrDefault(fiberRefs2, head3.fiberRef); + fiberRefs2 = updateAs(fiberRefs2, { + fiberId: fiberId2, + fiberRef: head3.fiberRef, + value: head3.fiberRef.patch(head3.patch)(value) + }); + patches = tail; + break; + } + case OP_AND_THEN: { + patches = prepend(head3.first)(prepend(head3.second)(tail)); + break; + } + } + } + return fiberRefs2; +}); + +// node_modules/effect/dist/esm/internal/metric/label.js +var MetricLabelSymbolKey = "effect/MetricLabel"; +var MetricLabelTypeId = /* @__PURE__ */ Symbol.for(MetricLabelSymbolKey); + +class MetricLabelImpl { + key; + value; + [MetricLabelTypeId] = MetricLabelTypeId; + _hash; + constructor(key, value) { + this.key = key; + this.value = value; + this._hash = string(MetricLabelSymbolKey + this.key + this.value); + } + [symbol]() { + return this._hash; + } + [symbol2](that) { + return isMetricLabel(that) && this.key === that.key && this.value === that.value; + } + pipe() { + return pipeArguments(this, arguments); + } +} +var make29 = (key, value) => { + return new MetricLabelImpl(key, value); +}; +var isMetricLabel = (u) => hasProperty(u, MetricLabelTypeId); + +// node_modules/effect/dist/esm/internal/core-effect.js +var annotateLogs = /* @__PURE__ */ dual((args) => isEffect(args[0]), function() { + const args = arguments; + return fiberRefLocallyWith(args[0], currentLogAnnotations, typeof args[1] === "string" ? set3(args[1], args[2]) : (annotations2) => Object.entries(args[1]).reduce((acc, [key, value]) => set3(acc, key, value), annotations2)); +}); +var asSome = (self) => map9(self, some2); +var asSomeError = (self) => mapError(self, some2); +var try_2 = (arg) => { + let evaluate; + let onFailure = undefined; + if (typeof arg === "function") { + evaluate = arg; + } else { + evaluate = arg.try; + onFailure = arg.catch; + } + return suspend(() => { + try { + return succeed(internalCall(evaluate)); + } catch (error) { + return fail2(onFailure ? internalCall(() => onFailure(error)) : new UnknownException(error, "An unknown error occurred in Effect.try")); + } + }); +}; +var _catch = /* @__PURE__ */ dual(3, (self, tag, options) => catchAll(self, (e) => { + if (hasProperty(e, tag) && e[tag] === options.failure) { + return options.onFailure(e); + } + return fail2(e); +})); +var catchAllDefect = /* @__PURE__ */ dual(2, (self, f) => catchAllCause(self, (cause) => { + const option = find(cause, (_) => isDieType(_) ? some2(_) : none2()); + switch (option._tag) { + case "None": { + return failCause(cause); + } + case "Some": { + return f(option.value.defect); + } + } +})); +var catchSomeCause = /* @__PURE__ */ dual(2, (self, f) => matchCauseEffect(self, { + onFailure: (cause) => { + const option = f(cause); + switch (option._tag) { + case "None": { + return failCause(cause); + } + case "Some": { + return option.value; + } + } + }, + onSuccess: succeed +})); +var catchSomeDefect = /* @__PURE__ */ dual(2, (self, pf) => catchAllCause(self, (cause) => { + const option = find(cause, (_) => isDieType(_) ? some2(_) : none2()); + switch (option._tag) { + case "None": { + return failCause(cause); + } + case "Some": { + const optionEffect = pf(option.value.defect); + return optionEffect._tag === "Some" ? optionEffect.value : failCause(cause); + } + } +})); +var catchTag = /* @__PURE__ */ dual((args) => isEffect(args[0]), (self, ...args) => { + const f = args[args.length - 1]; + let predicate; + if (args.length === 2) { + predicate = isTagged(args[0]); + } else { + predicate = (e) => { + const tag = hasProperty(e, "_tag") ? e["_tag"] : undefined; + if (!tag) + return false; + for (let i = 0;i < args.length - 1; i++) { + if (args[i] === tag) + return true; + } + return false; + }; + } + return catchIf(self, predicate, f); +}); +var catchTags = /* @__PURE__ */ dual(2, (self, cases) => { + let keys3; + return catchIf(self, (e) => { + keys3 ??= Object.keys(cases); + return hasProperty(e, "_tag") && isString(e["_tag"]) && keys3.includes(e["_tag"]); + }, (e) => cases[e["_tag"]](e)); +}); +var cause = (self) => matchCause(self, { + onFailure: identity, + onSuccess: () => empty16 +}); +var clockWith3 = clockWith2; +var clock = /* @__PURE__ */ clockWith3(succeed); +var delay = /* @__PURE__ */ dual(2, (self, duration) => zipRight(sleep2(duration), self)); +var descriptorWith = (f) => withFiberRuntime((state, status) => f({ + id: state.id(), + status, + interruptors: interruptors(state.getFiberRef(currentInterruptedCause)) +})); +var allowInterrupt = /* @__PURE__ */ descriptorWith((descriptor) => size3(descriptor.interruptors) > 0 ? interrupt2 : void_); +var descriptor = /* @__PURE__ */ descriptorWith(succeed); +var diffFiberRefs = (self) => summarized(self, fiberRefs2, diff5); +var diffFiberRefsAndRuntimeFlags = (self) => summarized(self, zip2(fiberRefs2, runtimeFlags), ([refs, flags], [refsNew, flagsNew]) => [diff5(refs, refsNew), diff4(flags, flagsNew)]); +var Do = /* @__PURE__ */ succeed({}); +var bind2 = /* @__PURE__ */ bind(map9, flatMap7); +var bindTo2 = /* @__PURE__ */ bindTo(map9); +var let_2 = /* @__PURE__ */ let_(map9); +var dropUntil = /* @__PURE__ */ dual(2, (elements, predicate) => suspend(() => { + const iterator = elements[Symbol.iterator](); + const builder = []; + let next; + let dropping = succeed(false); + let i = 0; + while ((next = iterator.next()) && !next.done) { + const a = next.value; + const index = i++; + dropping = flatMap7(dropping, (bool) => { + if (bool) { + builder.push(a); + return succeed(true); + } + return predicate(a, index); + }); + } + return map9(dropping, () => builder); +})); +var dropWhile = /* @__PURE__ */ dual(2, (elements, predicate) => suspend(() => { + const iterator = elements[Symbol.iterator](); + const builder = []; + let next; + let dropping = succeed(true); + let i = 0; + while ((next = iterator.next()) && !next.done) { + const a = next.value; + const index = i++; + dropping = flatMap7(dropping, (d) => map9(d ? predicate(a, index) : succeed(false), (b) => { + if (!b) { + builder.push(a); + } + return b; + })); + } + return map9(dropping, () => builder); +})); +var contextWith = (f) => map9(context(), f); +var eventually = (self) => orElse2(self, () => flatMap7(yieldNow(), () => eventually(self))); +var filterMap4 = /* @__PURE__ */ dual(2, (elements, pf) => map9(forEachSequential(elements, identity), filterMap2(pf))); +var filterOrDie = /* @__PURE__ */ dual(3, (self, predicate, orDieWith2) => filterOrElse(self, predicate, (a) => dieSync(() => orDieWith2(a)))); +var filterOrDieMessage = /* @__PURE__ */ dual(3, (self, predicate, message) => filterOrElse(self, predicate, () => dieMessage(message))); +var filterOrElse = /* @__PURE__ */ dual(3, (self, predicate, orElse3) => flatMap7(self, (a) => predicate(a) ? succeed(a) : orElse3(a))); +var liftPredicate = /* @__PURE__ */ dual(3, (self, predicate, orFailWith) => suspend(() => predicate(self) ? succeed(self) : fail2(orFailWith(self)))); +var filterOrFail = /* @__PURE__ */ dual((args) => isEffect(args[0]), (self, predicate, orFailWith) => filterOrElse(self, predicate, (a) => orFailWith === undefined ? fail2(new NoSuchElementException) : failSync(() => orFailWith(a)))); +var findFirst4 = /* @__PURE__ */ dual(2, (elements, predicate) => suspend(() => { + const iterator = elements[Symbol.iterator](); + const next = iterator.next(); + if (!next.done) { + return findLoop(iterator, 0, predicate, next.value); + } + return succeed(none2()); +})); +var findLoop = (iterator, index, f, value) => flatMap7(f(value, index), (result) => { + if (result) { + return succeed(some2(value)); + } + const next = iterator.next(); + if (!next.done) { + return findLoop(iterator, index + 1, f, next.value); + } + return succeed(none2()); +}); +var firstSuccessOf = (effects) => suspend(() => { + const list = fromIterable2(effects); + if (!isNonEmpty2(list)) { + return dieSync(() => new IllegalArgumentException(`Received an empty collection of effects`)); + } + return pipe(tailNonEmpty2(list), reduce(headNonEmpty2(list), (left3, right3) => orElse2(left3, () => right3))); +}); +var flipWith = /* @__PURE__ */ dual(2, (self, f) => flip(f(flip(self)))); +var match7 = /* @__PURE__ */ dual(2, (self, options) => matchEffect(self, { + onFailure: (e) => succeed(options.onFailure(e)), + onSuccess: (a) => succeed(options.onSuccess(a)) +})); +var every4 = /* @__PURE__ */ dual(2, (elements, predicate) => suspend(() => forAllLoop(elements[Symbol.iterator](), 0, predicate))); +var forAllLoop = (iterator, index, f) => { + const next = iterator.next(); + return next.done ? succeed(true) : flatMap7(f(next.value, index), (b) => b ? forAllLoop(iterator, index + 1, f) : succeed(b)); +}; +var forever = (self) => { + const loop = flatMap7(flatMap7(self, () => yieldNow()), () => loop); + return loop; +}; +var fiberRefs2 = /* @__PURE__ */ withFiberRuntime((state) => succeed(state.getFiberRefs())); +var head3 = (self) => flatMap7(self, (as2) => { + const iterator = as2[Symbol.iterator](); + const next = iterator.next(); + if (next.done) { + return fail2(new NoSuchElementException); + } + return succeed(next.value); +}); +var ignore = (self) => match7(self, { + onFailure: constVoid, + onSuccess: constVoid +}); +var ignoreLogged = (self) => matchCauseEffect(self, { + onFailure: (cause2) => logDebug(cause2, "An error was silently ignored because it is not anticipated to be useful"), + onSuccess: () => void_ +}); +var inheritFiberRefs = (childFiberRefs) => updateFiberRefs((parentFiberId, parentFiberRefs) => joinAs2(parentFiberRefs, parentFiberId, childFiberRefs)); +var isFailure = (self) => match7(self, { + onFailure: constTrue, + onSuccess: constFalse +}); +var isSuccess2 = (self) => match7(self, { + onFailure: constFalse, + onSuccess: constTrue +}); +var iterate = (initial, options) => suspend(() => { + if (options.while(initial)) { + return flatMap7(options.body(initial), (z2) => iterate(z2, options)); + } + return succeed(initial); +}); +var logWithLevel = (level) => (...message) => { + const levelOption = fromNullable(level); + let cause2 = undefined; + for (let i = 0, len = message.length;i < len; i++) { + const msg = message[i]; + if (isCause(msg)) { + if (cause2 !== undefined) { + cause2 = sequential(cause2, msg); + } else { + cause2 = msg; + } + message = [...message.slice(0, i), ...message.slice(i + 1)]; + i--; + } + } + if (cause2 === undefined) { + cause2 = empty16; + } + return withFiberRuntime((fiberState) => { + fiberState.log(message, cause2, levelOption); + return void_; + }); +}; +var log = /* @__PURE__ */ logWithLevel(); +var logTrace = /* @__PURE__ */ logWithLevel(Trace); +var logDebug = /* @__PURE__ */ logWithLevel(Debug); +var logInfo = /* @__PURE__ */ logWithLevel(Info); +var logWarning = /* @__PURE__ */ logWithLevel(Warning); +var logError = /* @__PURE__ */ logWithLevel(Error2); +var logFatal = /* @__PURE__ */ logWithLevel(Fatal); +var withLogSpan = /* @__PURE__ */ dual(2, (effect, label) => flatMap7(currentTimeMillis2, (now) => fiberRefLocallyWith(effect, currentLogSpan, prepend3(make26(label, now))))); +var logAnnotations = /* @__PURE__ */ fiberRefGet(currentLogAnnotations); +var loop = (initial, options) => options.discard ? loopDiscard(initial, options.while, options.step, options.body) : map9(loopInternal(initial, options.while, options.step, options.body), fromIterable); +var loopInternal = (initial, cont, inc, body) => suspend(() => cont(initial) ? flatMap7(body(initial), (a) => map9(loopInternal(inc(initial), cont, inc, body), prepend3(a))) : sync(() => empty9())); +var loopDiscard = (initial, cont, inc, body) => suspend(() => cont(initial) ? flatMap7(body(initial), () => loopDiscard(inc(initial), cont, inc, body)) : void_); +var mapAccum2 = /* @__PURE__ */ dual(3, (elements, initial, f) => suspend(() => { + const iterator = elements[Symbol.iterator](); + const builder = []; + let result = succeed(initial); + let next; + let i = 0; + while (!(next = iterator.next()).done) { + const index = i++; + const value = next.value; + result = flatMap7(result, (state) => map9(f(state, value, index), ([z, b]) => { + builder.push(b); + return z; + })); + } + return map9(result, (z) => [z, builder]); +})); +var mapErrorCause = /* @__PURE__ */ dual(2, (self, f) => matchCauseEffect(self, { + onFailure: (c) => failCauseSync(() => f(c)), + onSuccess: succeed +})); +var memoize = (self) => pipe(deferredMake(), flatMap7((deferred) => pipe(diffFiberRefsAndRuntimeFlags(self), intoDeferred(deferred), once, map9((complete) => zipRight(complete, pipe(deferredAwait(deferred), flatMap7(([patch7, a]) => as(zip2(patchFiberRefs(patch7[0]), updateRuntimeFlags(patch7[1])), a)))))))); +var merge5 = (self) => matchEffect(self, { + onFailure: (e) => succeed(e), + onSuccess: succeed +}); +var negate = (self) => map9(self, (b) => !b); +var none6 = (self) => flatMap7(self, (option) => { + switch (option._tag) { + case "None": + return void_; + case "Some": + return fail2(new NoSuchElementException); + } +}); +var once = (self) => map9(make28(true), (ref) => asVoid(whenEffect(self, getAndSet2(ref, false)))); +var option = (self) => matchEffect(self, { + onFailure: () => succeed(none2()), + onSuccess: (a) => succeed(some2(a)) +}); +var orElseFail = /* @__PURE__ */ dual(2, (self, evaluate) => orElse2(self, () => failSync(evaluate))); +var orElseSucceed = /* @__PURE__ */ dual(2, (self, evaluate) => orElse2(self, () => sync(evaluate))); +var parallelErrors = (self) => matchCauseEffect(self, { + onFailure: (cause2) => { + const errors = fromIterable(failures(cause2)); + return errors.length === 0 ? failCause(cause2) : fail2(errors); + }, + onSuccess: succeed +}); +var patchFiberRefs = (patch7) => updateFiberRefs((fiberId2, fiberRefs3) => pipe(patch7, patch6(fiberId2, fiberRefs3))); +var promise = (evaluate) => evaluate.length >= 1 ? async_((resolve, signal) => { + try { + evaluate(signal).then((a) => resolve(succeed(a)), (e) => resolve(die2(e))); + } catch (e) { + resolve(die2(e)); + } +}) : async_((resolve) => { + try { + evaluate().then((a) => resolve(succeed(a)), (e) => resolve(die2(e))); + } catch (e) { + resolve(die2(e)); + } +}); +var provideService = /* @__PURE__ */ dual(3, (self, tag, service) => contextWithEffect((env) => provideContext(self, add2(env, tag, service)))); +var provideServiceEffect = /* @__PURE__ */ dual(3, (self, tag, effect) => contextWithEffect((env) => flatMap7(effect, (service) => provideContext(self, pipe(env, add2(tag, service)))))); +var random2 = /* @__PURE__ */ randomWith(succeed); +var reduce8 = /* @__PURE__ */ dual(3, (elements, zero3, f) => fromIterable(elements).reduce((acc, el, i) => flatMap7(acc, (a) => f(a, el, i)), succeed(zero3))); +var reduceRight2 = /* @__PURE__ */ dual(3, (elements, zero3, f) => fromIterable(elements).reduceRight((acc, el, i) => flatMap7(acc, (a) => f(el, a, i)), succeed(zero3))); +var reduceWhile = /* @__PURE__ */ dual(3, (elements, zero3, options) => flatMap7(sync(() => elements[Symbol.iterator]()), (iterator) => reduceWhileLoop(iterator, 0, zero3, options.while, options.body))); +var reduceWhileLoop = (iterator, index, state, predicate, f) => { + const next = iterator.next(); + if (!next.done && predicate(state)) { + return flatMap7(f(state, next.value, index), (nextState) => reduceWhileLoop(iterator, index + 1, nextState, predicate, f)); + } + return succeed(state); +}; +var repeatN = /* @__PURE__ */ dual(2, (self, n) => suspend(() => repeatNLoop(self, n))); +var repeatNLoop = (self, n) => flatMap7(self, (a) => n <= 0 ? succeed(a) : zipRight(yieldNow(), repeatNLoop(self, n - 1))); +var sandbox = (self) => matchCauseEffect(self, { + onFailure: fail2, + onSuccess: succeed +}); +var setFiberRefs = (fiberRefs3) => suspend(() => setAll2(fiberRefs3)); +var sleep3 = sleep2; +var succeedNone = /* @__PURE__ */ succeed(/* @__PURE__ */ none2()); +var succeedSome = (value) => succeed(some2(value)); +var summarized = /* @__PURE__ */ dual(3, (self, summary, f) => flatMap7(summary, (start) => flatMap7(self, (value) => map9(summary, (end) => [f(start, end), value])))); +var tagMetrics = /* @__PURE__ */ dual((args) => isEffect(args[0]), function() { + return labelMetrics(arguments[0], typeof arguments[1] === "string" ? [make29(arguments[1], arguments[2])] : Object.entries(arguments[1]).map(([k, v]) => make29(k, v))); +}); +var labelMetrics = /* @__PURE__ */ dual(2, (self, labels) => fiberRefLocallyWith(self, currentMetricLabels, (old) => union(old, labels))); +var takeUntil = /* @__PURE__ */ dual(2, (elements, predicate) => suspend(() => { + const iterator = elements[Symbol.iterator](); + const builder = []; + let next; + let effect = succeed(false); + let i = 0; + while ((next = iterator.next()) && !next.done) { + const a = next.value; + const index = i++; + effect = flatMap7(effect, (bool) => { + if (bool) { + return succeed(true); + } + builder.push(a); + return predicate(a, index); + }); + } + return map9(effect, () => builder); +})); +var takeWhile = /* @__PURE__ */ dual(2, (elements, predicate) => suspend(() => { + const iterator = elements[Symbol.iterator](); + const builder = []; + let next; + let taking = succeed(true); + let i = 0; + while ((next = iterator.next()) && !next.done) { + const a = next.value; + const index = i++; + taking = flatMap7(taking, (taking2) => pipe(taking2 ? predicate(a, index) : succeed(false), map9((bool) => { + if (bool) { + builder.push(a); + } + return bool; + }))); + } + return map9(taking, () => builder); +})); +var tapBoth = /* @__PURE__ */ dual(2, (self, { + onFailure, + onSuccess +}) => matchCauseEffect(self, { + onFailure: (cause2) => { + const either3 = failureOrCause(cause2); + switch (either3._tag) { + case "Left": { + return zipRight(onFailure(either3.left), failCause(cause2)); + } + case "Right": { + return failCause(cause2); + } + } + }, + onSuccess: (a) => as(onSuccess(a), a) +})); +var tapDefect = /* @__PURE__ */ dual(2, (self, f) => catchAllCause(self, (cause2) => match2(keepDefects(cause2), { + onNone: () => failCause(cause2), + onSome: (a) => zipRight(f(a), failCause(cause2)) +}))); +var tapError = /* @__PURE__ */ dual(2, (self, f) => matchCauseEffect(self, { + onFailure: (cause2) => { + const either3 = failureOrCause(cause2); + switch (either3._tag) { + case "Left": + return zipRight(f(either3.left), failCause(cause2)); + case "Right": + return failCause(cause2); + } + }, + onSuccess: succeed +})); +var tapErrorTag = /* @__PURE__ */ dual(3, (self, k, f) => tapError(self, (e) => { + if (isTagged(e, k)) { + return f(e); + } + return void_; +})); +var tapErrorCause = /* @__PURE__ */ dual(2, (self, f) => matchCauseEffect(self, { + onFailure: (cause2) => zipRight(f(cause2), failCause(cause2)), + onSuccess: succeed +})); +var timed = (self) => timedWith(self, currentTimeNanos2); +var timedWith = /* @__PURE__ */ dual(2, (self, nanos2) => summarized(self, nanos2, (start, end) => nanos(end - start))); +var tracerWith3 = tracerWith2; +var tracer = /* @__PURE__ */ tracerWith3(succeed); +var tryPromise = (arg) => { + let evaluate; + let catcher = undefined; + if (typeof arg === "function") { + evaluate = arg; + } else { + evaluate = arg.try; + catcher = arg.catch; + } + const fail3 = (e) => catcher ? failSync(() => catcher(e)) : fail2(new UnknownException(e, "An unknown error occurred in Effect.tryPromise")); + if (evaluate.length >= 1) { + return async_((resolve, signal) => { + try { + evaluate(signal).then((a) => resolve(succeed(a)), (e) => resolve(fail3(e))); + } catch (e) { + resolve(fail3(e)); + } + }); + } + return async_((resolve) => { + try { + evaluate().then((a) => resolve(succeed(a)), (e) => resolve(fail3(e))); + } catch (e) { + resolve(fail3(e)); + } + }); +}; +var tryMap = /* @__PURE__ */ dual(2, (self, options) => flatMap7(self, (a) => try_2({ + try: () => options.try(a), + catch: options.catch +}))); +var tryMapPromise = /* @__PURE__ */ dual(2, (self, options) => flatMap7(self, (a) => tryPromise({ + try: options.try.length >= 1 ? (signal) => options.try(a, signal) : () => options.try(a), + catch: options.catch +}))); +var unless = /* @__PURE__ */ dual(2, (self, condition) => suspend(() => condition() ? succeedNone : asSome(self))); +var unlessEffect = /* @__PURE__ */ dual(2, (self, condition) => flatMap7(condition, (b) => b ? succeedNone : asSome(self))); +var unsandbox = (self) => mapErrorCause(self, flatten4); +var updateFiberRefs = (f) => withFiberRuntime((state) => { + state.setFiberRefs(f(state.id(), state.getFiberRefs())); + return void_; +}); +var updateService = /* @__PURE__ */ dual(3, (self, tag, f) => mapInputContext(self, (context2) => add2(context2, tag, f(unsafeGet3(context2, tag))))); +var when = /* @__PURE__ */ dual(2, (self, condition) => suspend(() => condition() ? map9(self, some2) : succeed(none2()))); +var whenFiberRef = /* @__PURE__ */ dual(3, (self, fiberRef, predicate) => flatMap7(fiberRefGet(fiberRef), (s) => predicate(s) ? map9(self, (a) => [s, some2(a)]) : succeed([s, none2()]))); +var whenRef = /* @__PURE__ */ dual(3, (self, ref, predicate) => flatMap7(get12(ref), (s) => predicate(s) ? map9(self, (a) => [s, some2(a)]) : succeed([s, none2()]))); +var withMetric = /* @__PURE__ */ dual(2, (self, metric) => metric(self)); +var serviceFunctionEffect = (getService, f) => (...args) => flatMap7(getService, (a) => f(a)(...args)); +var serviceFunction = (getService, f) => (...args) => map9(getService, (a) => f(a)(...args)); +var serviceFunctions = (getService) => new Proxy({}, { + get(_target, prop, _receiver) { + return (...args) => flatMap7(getService, (s) => s[prop](...args)); + } +}); +var serviceConstants = (getService) => new Proxy({}, { + get(_target, prop, _receiver) { + return flatMap7(getService, (s) => isEffect(s[prop]) ? s[prop] : succeed(s[prop])); + } +}); +var serviceMembers = (getService) => ({ + functions: serviceFunctions(getService), + constants: serviceConstants(getService) +}); +var serviceOption = (tag) => map9(context(), getOption2(tag)); +var serviceOptional = (tag) => flatMap7(context(), getOption2(tag)); +var annotateCurrentSpan = function() { + const args = arguments; + return ignore(flatMap7(currentPropagatedSpan, (span2) => sync(() => { + if (typeof args[0] === "string") { + span2.attribute(args[0], args[1]); + } else { + for (const key in args[0]) { + span2.attribute(key, args[0][key]); + } + } + }))); +}; +var linkSpanCurrent = function() { + const args = arguments; + const links = Array.isArray(args[0]) ? args[0] : [{ + _tag: "SpanLink", + span: args[0], + attributes: args[1] ?? {} + }]; + return ignore(flatMap7(currentSpan, (span2) => sync(() => span2.addLinks(links)))); +}; +var annotateSpans = /* @__PURE__ */ dual((args) => isEffect(args[0]), function() { + const args = arguments; + return fiberRefLocallyWith(args[0], currentTracerSpanAnnotations, typeof args[1] === "string" ? set3(args[1], args[2]) : (annotations2) => Object.entries(args[1]).reduce((acc, [key, value]) => set3(acc, key, value), annotations2)); +}); +var currentParentSpan = /* @__PURE__ */ serviceOptional(spanTag); +var currentSpan = /* @__PURE__ */ flatMap7(/* @__PURE__ */ context(), (context2) => { + const span2 = context2.unsafeMap.get(spanTag.key); + return span2 !== undefined && span2._tag === "Span" ? succeed(span2) : fail2(new NoSuchElementException); +}); +var currentPropagatedSpan = /* @__PURE__ */ flatMap7(/* @__PURE__ */ context(), (context2) => { + const span2 = filterDisablePropagation(getOption2(context2, spanTag)); + return span2._tag === "Some" && span2.value._tag === "Span" ? succeed(span2.value) : fail2(new NoSuchElementException); +}); +var linkSpans = /* @__PURE__ */ dual((args) => isEffect(args[0]), (self, span2, attributes) => fiberRefLocallyWith(self, currentTracerSpanLinks, append2({ + _tag: "SpanLink", + span: span2, + attributes: attributes ?? {} +}))); +var bigint03 = /* @__PURE__ */ BigInt(0); +var filterDisablePropagation = /* @__PURE__ */ flatMap((span2) => get3(span2.context, DisablePropagation) ? span2._tag === "Span" ? filterDisablePropagation(span2.parent) : none2() : some2(span2)); +var unsafeMakeSpan = (fiber, name, options) => { + const disablePropagation = !fiber.getFiberRef(currentTracerEnabled) || options.context && get3(options.context, DisablePropagation); + const context2 = fiber.getFiberRef(currentContext); + const parent = options.parent ? some2(options.parent) : options.root ? none2() : filterDisablePropagation(getOption2(context2, spanTag)); + let span2; + if (disablePropagation) { + span2 = noopSpan({ + name, + parent, + context: add2(options.context ?? empty3(), DisablePropagation, true) + }); + } else { + const services = fiber.getFiberRef(currentServices); + const tracer2 = get3(services, tracerTag); + const clock2 = get3(services, Clock); + const timingEnabled = fiber.getFiberRef(currentTracerTimingEnabled); + const fiberRefs3 = fiber.getFiberRefs(); + const annotationsFromEnv = get10(fiberRefs3, currentTracerSpanAnnotations); + const linksFromEnv = get10(fiberRefs3, currentTracerSpanLinks); + const links = linksFromEnv._tag === "Some" ? options.links !== undefined ? [...toReadonlyArray(linksFromEnv.value), ...options.links ?? []] : toReadonlyArray(linksFromEnv.value) : options.links ?? empty(); + span2 = tracer2.span(name, parent, options.context ?? empty3(), links, timingEnabled ? clock2.unsafeCurrentTimeNanos() : bigint03, options.kind ?? "internal", options); + if (annotationsFromEnv._tag === "Some") { + forEach3(annotationsFromEnv.value, (value, key) => span2.attribute(key, value)); + } + if (options.attributes !== undefined) { + Object.entries(options.attributes).forEach(([k, v]) => span2.attribute(k, v)); + } + } + if (typeof options.captureStackTrace === "function") { + spanToTrace.set(span2, options.captureStackTrace); + } + return span2; +}; +var makeSpan = (name, options) => { + options = addSpanStackTrace(options); + return withFiberRuntime((fiber) => succeed(unsafeMakeSpan(fiber, name, options))); +}; +var spanAnnotations = /* @__PURE__ */ fiberRefGet(currentTracerSpanAnnotations); +var spanLinks = /* @__PURE__ */ fiberRefGet(currentTracerSpanLinks); +var endSpan = (span2, exit2, clock2, timingEnabled) => sync(() => { + if (span2.status._tag === "Ended") { + return; + } + if (exitIsFailure(exit2) && spanToTrace.has(span2)) { + span2.attribute("code.stacktrace", spanToTrace.get(span2)()); + } + span2.end(timingEnabled ? clock2.unsafeCurrentTimeNanos() : bigint03, exit2); +}); +var useSpan = (name, ...args) => { + const options = addSpanStackTrace(args.length === 1 ? undefined : args[0]); + const evaluate = args[args.length - 1]; + return withFiberRuntime((fiber) => { + const span2 = unsafeMakeSpan(fiber, name, options); + const timingEnabled = fiber.getFiberRef(currentTracerTimingEnabled); + const clock2 = get3(fiber.getFiberRef(currentServices), clockTag); + return onExit(evaluate(span2), (exit2) => endSpan(span2, exit2, clock2, timingEnabled)); + }); +}; +var withParentSpan = /* @__PURE__ */ dual(2, (self, span2) => provideService(self, spanTag, span2)); +var withSpan = function() { + const dataFirst = typeof arguments[0] !== "string"; + const name = dataFirst ? arguments[1] : arguments[0]; + const options = addSpanStackTrace(dataFirst ? arguments[2] : arguments[1]); + if (dataFirst) { + const self = arguments[0]; + return useSpan(name, options, (span2) => withParentSpan(self, span2)); + } + return (self) => useSpan(name, options, (span2) => withParentSpan(self, span2)); +}; +var functionWithSpan = (options) => function() { + let captureStackTrace = options.captureStackTrace ?? false; + if (options.captureStackTrace !== false) { + const limit = Error.stackTraceLimit; + Error.stackTraceLimit = 2; + const error = new Error; + Error.stackTraceLimit = limit; + let cache = false; + captureStackTrace = () => { + if (cache !== false) { + return cache; + } + if (error.stack) { + const stack = error.stack.trim().split(` +`); + cache = stack.slice(2).join(` +`).trim(); + return cache; + } + }; + } + return suspend(() => { + const opts = typeof options.options === "function" ? options.options.apply(null, arguments) : options.options; + return withSpan(suspend(() => internalCall(() => options.body.apply(this, arguments))), opts.name, { + ...opts, + captureStackTrace + }); + }); +}; +var fromNullable2 = (value) => value == null ? fail2(new NoSuchElementException) : succeed(value); +var optionFromOptional = (self) => catchAll(map9(self, some2), (error) => isNoSuchElementException(error) ? succeedNone : fail2(error)); + +// node_modules/effect/dist/esm/internal/executionStrategy.js +var OP_SEQUENTIAL2 = "Sequential"; +var OP_PARALLEL2 = "Parallel"; +var OP_PARALLEL_N = "ParallelN"; +var sequential2 = { + _tag: OP_SEQUENTIAL2 +}; +var parallel2 = { + _tag: OP_PARALLEL2 +}; +var parallelN = (parallelism) => ({ + _tag: OP_PARALLEL_N, + parallelism +}); +var isSequential = (self) => self._tag === OP_SEQUENTIAL2; +var isParallel = (self) => self._tag === OP_PARALLEL2; + +// node_modules/effect/dist/esm/ExecutionStrategy.js +var sequential3 = sequential2; +var parallel3 = parallel2; +var parallelN2 = parallelN; + +// node_modules/effect/dist/esm/FiberRefsPatch.js +var diff6 = diff5; +var patch7 = patch6; + +// node_modules/effect/dist/esm/internal/fiberStatus.js +var FiberStatusSymbolKey = "effect/FiberStatus"; +var FiberStatusTypeId = /* @__PURE__ */ Symbol.for(FiberStatusSymbolKey); +var OP_DONE = "Done"; +var OP_RUNNING = "Running"; +var OP_SUSPENDED = "Suspended"; +var DoneHash = /* @__PURE__ */ string(`${FiberStatusSymbolKey}-${OP_DONE}`); + +class Done { + [FiberStatusTypeId] = FiberStatusTypeId; + _tag = OP_DONE; + [symbol]() { + return DoneHash; + } + [symbol2](that) { + return isFiberStatus(that) && that._tag === OP_DONE; + } +} + +class Running { + runtimeFlags; + [FiberStatusTypeId] = FiberStatusTypeId; + _tag = OP_RUNNING; + constructor(runtimeFlags2) { + this.runtimeFlags = runtimeFlags2; + } + [symbol]() { + return pipe(hash(FiberStatusSymbolKey), combine(hash(this._tag)), combine(hash(this.runtimeFlags)), cached(this)); + } + [symbol2](that) { + return isFiberStatus(that) && that._tag === OP_RUNNING && this.runtimeFlags === that.runtimeFlags; + } +} + +class Suspended { + runtimeFlags; + blockingOn; + [FiberStatusTypeId] = FiberStatusTypeId; + _tag = OP_SUSPENDED; + constructor(runtimeFlags2, blockingOn) { + this.runtimeFlags = runtimeFlags2; + this.blockingOn = blockingOn; + } + [symbol]() { + return pipe(hash(FiberStatusSymbolKey), combine(hash(this._tag)), combine(hash(this.runtimeFlags)), combine(hash(this.blockingOn)), cached(this)); + } + [symbol2](that) { + return isFiberStatus(that) && that._tag === OP_SUSPENDED && this.runtimeFlags === that.runtimeFlags && equals(this.blockingOn, that.blockingOn); + } +} +var done3 = /* @__PURE__ */ new Done; +var running = (runtimeFlags2) => new Running(runtimeFlags2); +var suspended = (runtimeFlags2, blockingOn) => new Suspended(runtimeFlags2, blockingOn); +var isFiberStatus = (u) => hasProperty(u, FiberStatusTypeId); +var isDone = (self) => self._tag === OP_DONE; + +// node_modules/effect/dist/esm/FiberStatus.js +var done4 = done3; +var running2 = running; +var suspended2 = suspended; +var isDone2 = isDone; + +// node_modules/effect/dist/esm/Micro.js +var TypeId14 = /* @__PURE__ */ Symbol.for("effect/Micro"); +var MicroExitTypeId = /* @__PURE__ */ Symbol.for("effect/Micro/MicroExit"); +var MicroCauseTypeId = /* @__PURE__ */ Symbol.for("effect/Micro/MicroCause"); +var microCauseVariance = { + _E: identity +}; + +class MicroCauseImpl extends globalThis.Error { + _tag; + traces; + [MicroCauseTypeId]; + constructor(_tag, originalError, traces) { + const causeName = `MicroCause.${_tag}`; + let name; + let message; + let stack; + if (originalError instanceof globalThis.Error) { + name = `(${causeName}) ${originalError.name}`; + message = originalError.message; + const messageLines = message.split(` +`).length; + stack = originalError.stack ? `(${causeName}) ${originalError.stack.split(` +`).slice(0, messageLines + 3).join(` +`)}` : `${name}: ${message}`; + } else { + name = causeName; + message = toStringUnknown(originalError, 0); + stack = `${name}: ${message}`; + } + if (traces.length > 0) { + stack += ` + ${traces.join(` + `)}`; + } + super(message); + this._tag = _tag; + this.traces = traces; + this[MicroCauseTypeId] = microCauseVariance; + this.name = name; + this.stack = stack; + } + pipe() { + return pipeArguments(this, arguments); + } + toString() { + return this.stack; + } + [NodeInspectSymbol]() { + return this.stack; + } +} +class Die extends MicroCauseImpl { + defect; + constructor(defect, traces = []) { + super("Die", defect, traces); + this.defect = defect; + } +} +var causeDie = (defect, traces = []) => new Die(defect, traces); + +class Interrupt extends MicroCauseImpl { + constructor(traces = []) { + super("Interrupt", "interrupted", traces); + } +} +var causeInterrupt = (traces = []) => new Interrupt(traces); +var causeIsInterrupt = (self) => self._tag === "Interrupt"; +var MicroFiberTypeId = /* @__PURE__ */ Symbol.for("effect/Micro/MicroFiber"); +var fiberVariance = { + _A: identity, + _E: identity +}; + +class MicroFiberImpl { + context; + interruptible; + [MicroFiberTypeId]; + _stack = []; + _observers = []; + _exit; + _children; + currentOpCount = 0; + constructor(context2, interruptible3 = true) { + this.context = context2; + this.interruptible = interruptible3; + this[MicroFiberTypeId] = fiberVariance; + } + getRef(ref) { + return unsafeGetReference(this.context, ref); + } + addObserver(cb) { + if (this._exit) { + cb(this._exit); + return constVoid; + } + this._observers.push(cb); + return () => { + const index = this._observers.indexOf(cb); + if (index >= 0) { + this._observers.splice(index, 1); + } + }; + } + _interrupted = false; + unsafeInterrupt() { + if (this._exit) { + return; + } + this._interrupted = true; + if (this.interruptible) { + this.evaluate(exitInterrupt2); + } + } + unsafePoll() { + return this._exit; + } + evaluate(effect) { + if (this._exit) { + return; + } else if (this._yielded !== undefined) { + const yielded = this._yielded; + this._yielded = undefined; + yielded(); + } + const exit2 = this.runLoop(effect); + if (exit2 === Yield) { + return; + } + const interruptChildren = fiberMiddleware.interruptChildren && fiberMiddleware.interruptChildren(this); + if (interruptChildren !== undefined) { + return this.evaluate(flatMap8(interruptChildren, () => exit2)); + } + this._exit = exit2; + for (let i = 0;i < this._observers.length; i++) { + this._observers[i](exit2); + } + this._observers.length = 0; + } + runLoop(effect) { + let yielding = false; + let current = effect; + this.currentOpCount = 0; + try { + while (true) { + this.currentOpCount++; + if (!yielding && this.getRef(CurrentScheduler).shouldYield(this)) { + yielding = true; + const prev = current; + current = flatMap8(yieldNow2, () => prev); + } + current = current[evaluate](this); + if (current === Yield) { + const yielded = this._yielded; + if (MicroExitTypeId in yielded) { + this._yielded = undefined; + return yielded; + } + return Yield; + } + } + } catch (error) { + if (!hasProperty(current, evaluate)) { + return exitDie2(`MicroFiber.runLoop: Not a valid effect: ${String(current)}`); + } + return exitDie2(error); + } + } + getCont(symbol3) { + while (true) { + const op = this._stack.pop(); + if (!op) + return; + const cont = op[ensureCont] && op[ensureCont](this); + if (cont) + return { + [symbol3]: cont + }; + if (op[symbol3]) + return op; + } + } + _yielded = undefined; + yieldWith(value) { + this._yielded = value; + return Yield; + } + children() { + return this._children ??= new Set; + } +} +var fiberMiddleware = /* @__PURE__ */ globalValue("effect/Micro/fiberMiddleware", () => ({ + interruptChildren: undefined +})); +var identifier = /* @__PURE__ */ Symbol.for("effect/Micro/identifier"); +var args = /* @__PURE__ */ Symbol.for("effect/Micro/args"); +var evaluate = /* @__PURE__ */ Symbol.for("effect/Micro/evaluate"); +var successCont = /* @__PURE__ */ Symbol.for("effect/Micro/successCont"); +var failureCont = /* @__PURE__ */ Symbol.for("effect/Micro/failureCont"); +var ensureCont = /* @__PURE__ */ Symbol.for("effect/Micro/ensureCont"); +var Yield = /* @__PURE__ */ Symbol.for("effect/Micro/Yield"); +var microVariance = { + _A: identity, + _E: identity, + _R: identity +}; +var MicroProto = { + ...EffectPrototype2, + _op: "Micro", + [TypeId14]: microVariance, + pipe() { + return pipeArguments(this, arguments); + }, + [Symbol.iterator]() { + return new SingleShotGen(new YieldWrap(this)); + }, + toJSON() { + return { + _id: "Micro", + op: this[identifier], + ...args in this ? { + args: this[args] + } : undefined + }; + }, + toString() { + return format(this); + }, + [NodeInspectSymbol]() { + return format(this); + } +}; +function defaultEvaluate(_fiber) { + return exitDie2(`Micro.evaluate: Not implemented`); +} +var makePrimitiveProto = (options) => ({ + ...MicroProto, + [identifier]: options.op, + [evaluate]: options.eval ?? defaultEvaluate, + [successCont]: options.contA, + [failureCont]: options.contE, + [ensureCont]: options.ensure +}); +var makePrimitive = (options) => { + const Proto2 = makePrimitiveProto(options); + return function() { + const self = Object.create(Proto2); + self[args] = options.single === false ? arguments : arguments[0]; + return self; + }; +}; +var makeExit = (options) => { + const Proto2 = { + ...makePrimitiveProto(options), + [MicroExitTypeId]: MicroExitTypeId, + _tag: options.op, + get [options.prop]() { + return this[args]; + }, + toJSON() { + return { + _id: "MicroExit", + _tag: options.op, + [options.prop]: this[args] + }; + }, + [symbol2](that) { + return isMicroExit(that) && that._tag === options.op && equals(this[args], that[args]); + }, + [symbol]() { + return cached(this, combine(string(options.op))(hash(this[args]))); + } + }; + return function(value) { + const self = Object.create(Proto2); + self[args] = value; + self[successCont] = undefined; + self[failureCont] = undefined; + self[ensureCont] = undefined; + return self; + }; +}; +var succeed3 = /* @__PURE__ */ makeExit({ + op: "Success", + prop: "value", + eval(fiber) { + const cont = fiber.getCont(successCont); + return cont ? cont[successCont](this[args], fiber) : fiber.yieldWith(this); + } +}); +var failCause3 = /* @__PURE__ */ makeExit({ + op: "Failure", + prop: "cause", + eval(fiber) { + let cont = fiber.getCont(failureCont); + while (causeIsInterrupt(this[args]) && cont && fiber.interruptible) { + cont = fiber.getCont(failureCont); + } + return cont ? cont[failureCont](this[args], fiber) : fiber.yieldWith(this); + } +}); +var yieldNowWith = /* @__PURE__ */ makePrimitive({ + op: "Yield", + eval(fiber) { + let resumed = false; + fiber.getRef(CurrentScheduler).scheduleTask(() => { + if (resumed) + return; + fiber.evaluate(exitVoid2); + }, this[args] ?? 0); + return fiber.yieldWith(() => { + resumed = true; + }); + } +}); +var yieldNow2 = /* @__PURE__ */ yieldNowWith(0); +var void_2 = /* @__PURE__ */ succeed3(undefined); +var withMicroFiber = /* @__PURE__ */ makePrimitive({ + op: "WithMicroFiber", + eval(fiber) { + return this[args](fiber); + } +}); +var flatMap8 = /* @__PURE__ */ dual(2, (self, f) => { + const onSuccess = Object.create(OnSuccessProto); + onSuccess[args] = self; + onSuccess[successCont] = f; + return onSuccess; +}); +var OnSuccessProto = /* @__PURE__ */ makePrimitiveProto({ + op: "OnSuccess", + eval(fiber) { + fiber._stack.push(this); + return this[args]; + } +}); +var isMicroExit = (u) => hasProperty(u, MicroExitTypeId); +var exitSucceed2 = succeed3; +var exitFailCause2 = failCause3; +var exitInterrupt2 = /* @__PURE__ */ exitFailCause2(/* @__PURE__ */ causeInterrupt()); +var exitDie2 = (defect) => exitFailCause2(causeDie(defect)); +var exitVoid2 = /* @__PURE__ */ exitSucceed2(undefined); +var setImmediate = "setImmediate" in globalThis ? globalThis.setImmediate : (f) => setTimeout(f, 0); + +class MicroSchedulerDefault { + tasks = []; + running = false; + scheduleTask(task, _priority) { + this.tasks.push(task); + if (!this.running) { + this.running = true; + setImmediate(this.afterScheduled); + } + } + afterScheduled = () => { + this.running = false; + this.runTasks(); + }; + runTasks() { + const tasks = this.tasks; + this.tasks = []; + for (let i = 0, len = tasks.length;i < len; i++) { + tasks[i](); + } + } + shouldYield(fiber) { + return fiber.currentOpCount >= fiber.getRef(MaxOpsBeforeYield); + } + flush() { + while (this.tasks.length > 0) { + this.runTasks(); + } + } +} +var updateContext = /* @__PURE__ */ dual(2, (self, f) => withMicroFiber((fiber) => { + const prev = fiber.context; + fiber.context = f(prev); + return onExit2(self, () => { + fiber.context = prev; + return void_2; + }); +})); +var provideContext2 = /* @__PURE__ */ dual(2, (self, provided) => updateContext(self, merge3(provided))); +class MaxOpsBeforeYield extends (/* @__PURE__ */ Reference2()("effect/Micro/currentMaxOpsBeforeYield", { + defaultValue: () => 2048 +})) { +} +class CurrentScheduler extends (/* @__PURE__ */ Reference2()("effect/Micro/currentScheduler", { + defaultValue: () => new MicroSchedulerDefault +})) { +} +var matchCauseEffect2 = /* @__PURE__ */ dual(2, (self, options) => { + const primitive = Object.create(OnSuccessAndFailureProto); + primitive[args] = self; + primitive[successCont] = options.onSuccess; + primitive[failureCont] = options.onFailure; + return primitive; +}); +var OnSuccessAndFailureProto = /* @__PURE__ */ makePrimitiveProto({ + op: "OnSuccessAndFailure", + eval(fiber) { + fiber._stack.push(this); + return this[args]; + } +}); +var onExit2 = /* @__PURE__ */ dual(2, (self, f) => uninterruptibleMask2((restore) => matchCauseEffect2(restore(self), { + onFailure: (cause2) => flatMap8(f(exitFailCause2(cause2)), () => failCause3(cause2)), + onSuccess: (a) => flatMap8(f(exitSucceed2(a)), () => succeed3(a)) +}))); +var setInterruptible = /* @__PURE__ */ makePrimitive({ + op: "SetInterruptible", + ensure(fiber) { + fiber.interruptible = this[args]; + if (fiber._interrupted && fiber.interruptible) { + return () => exitInterrupt2; + } + } +}); +var interruptible3 = (self) => withMicroFiber((fiber) => { + if (fiber.interruptible) + return self; + fiber.interruptible = true; + fiber._stack.push(setInterruptible(false)); + if (fiber._interrupted) + return exitInterrupt2; + return self; +}); +var uninterruptibleMask2 = (f) => withMicroFiber((fiber) => { + if (!fiber.interruptible) + return f(identity); + fiber.interruptible = false; + fiber._stack.push(setInterruptible(true)); + return f(interruptible3); +}); +var runFork = (effect, options) => { + const fiber = new MicroFiberImpl(CurrentScheduler.context(options?.scheduler ?? new MicroSchedulerDefault)); + fiber.evaluate(effect); + if (options?.signal) { + if (options.signal.aborted) { + fiber.unsafeInterrupt(); + } else { + const abort = () => fiber.unsafeInterrupt(); + options.signal.addEventListener("abort", abort, { + once: true + }); + fiber.addObserver(() => options.signal.removeEventListener("abort", abort)); + } + } + return fiber; +}; + +// node_modules/effect/dist/esm/Scheduler.js +class SchedulerRunner { + scheduleDrain; + running = false; + tasks = /* @__PURE__ */ new PriorityBuckets; + constructor(scheduleDrain) { + this.scheduleDrain = scheduleDrain; + } + starveInternal = (depth) => { + const tasks = this.tasks.buckets; + this.tasks.buckets = []; + for (const [_, toRun] of tasks) { + for (let i = 0;i < toRun.length; i++) { + toRun[i](); + } + } + if (this.tasks.buckets.length === 0) { + this.running = false; + } else { + this.starve(depth); + } + }; + starve(depth = 0) { + this.scheduleDrain(depth, this.starveInternal); + } + scheduleTask(task, priority) { + this.tasks.scheduleTask(task, priority); + if (!this.running) { + this.running = true; + this.starve(); + } + } + static cached(scheduleDrain) { + const fallback = new SchedulerRunner(scheduleDrain); + const runners = new WeakMap; + return (fiber) => { + if (fiber === undefined) { + return fallback; + } + let runner = runners.get(fiber); + if (runner === undefined) { + runner = new SchedulerRunner(scheduleDrain); + runners.set(fiber, runner); + } + return runner; + }; + } +} + +class PriorityBuckets { + buckets = []; + scheduleTask(task, priority) { + const length2 = this.buckets.length; + let bucket = undefined; + let index = 0; + for (;index < length2; index++) { + if (this.buckets[index][0] <= priority) { + bucket = this.buckets[index]; + } else { + break; + } + } + if (bucket && bucket[0] === priority) { + bucket[1].push(task); + } else if (index === length2) { + this.buckets.push([priority, [task]]); + } else { + this.buckets.splice(index, 0, [priority, [task]]); + } + } +} + +class MixedScheduler { + maxNextTickBeforeTimer; + getRunner = /* @__PURE__ */ SchedulerRunner.cached((depth, drain) => { + if (depth >= this.maxNextTickBeforeTimer) { + setTimeout(() => drain(0), 0); + } else { + Promise.resolve(undefined).then(() => drain(depth + 1)); + } + }); + constructor(maxNextTickBeforeTimer) { + this.maxNextTickBeforeTimer = maxNextTickBeforeTimer; + } + shouldYield(fiber) { + return fiber.currentOpCount > fiber.getFiberRef(currentMaxOpsBeforeYield) ? fiber.getFiberRef(currentSchedulingPriority) : false; + } + scheduleTask(task, priority, fiber) { + this.getRunner(fiber).scheduleTask(task, priority); + } +} +var defaultScheduler = /* @__PURE__ */ globalValue(/* @__PURE__ */ Symbol.for("effect/Scheduler/defaultScheduler"), () => new MixedScheduler(2048)); + +class SyncScheduler { + tasks = /* @__PURE__ */ new PriorityBuckets; + deferred = false; + scheduleTask(task, priority, fiber) { + if (this.deferred) { + defaultScheduler.scheduleTask(task, priority, fiber); + } else { + this.tasks.scheduleTask(task, priority); + } + } + shouldYield(fiber) { + return fiber.currentOpCount > fiber.getFiberRef(currentMaxOpsBeforeYield) ? fiber.getFiberRef(currentSchedulingPriority) : false; + } + flush() { + while (this.tasks.buckets.length > 0) { + const tasks = this.tasks.buckets; + this.tasks.buckets = []; + for (const [_, toRun] of tasks) { + for (let i = 0;i < toRun.length; i++) { + toRun[i](); + } + } + } + this.deferred = true; + } +} +var currentScheduler = /* @__PURE__ */ globalValue(/* @__PURE__ */ Symbol.for("effect/FiberRef/currentScheduler"), () => fiberRefUnsafeMake(defaultScheduler)); +var withScheduler = /* @__PURE__ */ dual(2, (self, scheduler) => fiberRefLocally(self, currentScheduler, scheduler)); + +// node_modules/effect/dist/esm/internal/completedRequestMap.js +var currentRequestMap = /* @__PURE__ */ globalValue(/* @__PURE__ */ Symbol.for("effect/FiberRef/currentRequestMap"), () => fiberRefUnsafeMake(new Map)); + +// node_modules/effect/dist/esm/internal/concurrency.js +var match9 = (concurrency, sequential4, unbounded2, bounded) => { + switch (concurrency) { + case undefined: + return sequential4(); + case "unbounded": + return unbounded2(); + case "inherit": + return fiberRefGetWith(currentConcurrency, (concurrency2) => concurrency2 === "unbounded" ? unbounded2() : concurrency2 > 1 ? bounded(concurrency2) : sequential4()); + default: + return concurrency > 1 ? bounded(concurrency) : sequential4(); + } +}; +var matchSimple = (concurrency, sequential4, concurrent) => { + switch (concurrency) { + case undefined: + return sequential4(); + case "unbounded": + return concurrent(); + case "inherit": + return fiberRefGetWith(currentConcurrency, (concurrency2) => concurrency2 === "unbounded" || concurrency2 > 1 ? concurrent() : sequential4()); + default: + return concurrency > 1 ? concurrent() : sequential4(); + } +}; + +// node_modules/effect/dist/esm/internal/fiberMessage.js +var OP_INTERRUPT_SIGNAL = "InterruptSignal"; +var OP_STATEFUL = "Stateful"; +var OP_RESUME = "Resume"; +var OP_YIELD_NOW = "YieldNow"; +var interruptSignal = (cause2) => ({ + _tag: OP_INTERRUPT_SIGNAL, + cause: cause2 +}); +var stateful = (onFiber) => ({ + _tag: OP_STATEFUL, + onFiber +}); +var resume = (effect) => ({ + _tag: OP_RESUME, + effect +}); +var yieldNow3 = () => ({ + _tag: OP_YIELD_NOW +}); + +// node_modules/effect/dist/esm/internal/fiberScope.js +var FiberScopeSymbolKey = "effect/FiberScope"; +var FiberScopeTypeId = /* @__PURE__ */ Symbol.for(FiberScopeSymbolKey); + +class Global { + [FiberScopeTypeId] = FiberScopeTypeId; + fiberId = none4; + roots = /* @__PURE__ */ new Set; + add(_runtimeFlags, child) { + this.roots.add(child); + child.addObserver(() => { + this.roots.delete(child); + }); + } +} + +class Local { + fiberId; + parent; + [FiberScopeTypeId] = FiberScopeTypeId; + constructor(fiberId2, parent) { + this.fiberId = fiberId2; + this.parent = parent; + } + add(_runtimeFlags, child) { + this.parent.tell(stateful((parentFiber) => { + parentFiber.addChild(child); + child.addObserver(() => { + parentFiber.removeChild(child); + }); + })); + } +} +var unsafeMake6 = (fiber) => { + return new Local(fiber.id(), fiber); +}; +var globalScope = /* @__PURE__ */ globalValue(/* @__PURE__ */ Symbol.for("effect/FiberScope/Global"), () => new Global); + +// node_modules/effect/dist/esm/internal/fiber.js +var FiberSymbolKey = "effect/Fiber"; +var FiberTypeId = /* @__PURE__ */ Symbol.for(FiberSymbolKey); +var fiberVariance2 = { + _E: (_) => _, + _A: (_) => _ +}; +var fiberProto = { + [FiberTypeId]: fiberVariance2, + pipe() { + return pipeArguments(this, arguments); + } +}; +var RuntimeFiberSymbolKey = "effect/Fiber"; +var RuntimeFiberTypeId = /* @__PURE__ */ Symbol.for(RuntimeFiberSymbolKey); +var isRuntimeFiber = (self) => (RuntimeFiberTypeId in self); +var _await2 = (self) => self.await; +var inheritAll = (self) => self.inheritAll; +var interruptAllAs = /* @__PURE__ */ dual(2, /* @__PURE__ */ fnUntraced(function* (fibers, fiberId2) { + for (const fiber of fibers) { + if (isRuntimeFiber(fiber)) { + fiber.unsafeInterruptAsFork(fiberId2); + continue; + } + yield* fiber.interruptAsFork(fiberId2); + } + for (const fiber of fibers) { + if (isRuntimeFiber(fiber) && fiber.unsafePoll()) { + continue; + } + yield* fiber.await; + } +})); +var interruptAsFork = /* @__PURE__ */ dual(2, (self, fiberId2) => self.interruptAsFork(fiberId2)); +var join2 = (self) => zipLeft(flatten5(self.await), self.inheritAll); +var _never = { + ...CommitPrototype, + commit() { + return join2(this); + }, + ...fiberProto, + id: () => none4, + await: never, + children: /* @__PURE__ */ succeed([]), + inheritAll: never, + poll: /* @__PURE__ */ succeed(/* @__PURE__ */ none2()), + interruptAsFork: () => never +}; +var currentFiberURI = "effect/FiberCurrent"; + +// node_modules/effect/dist/esm/internal/logger.js +var LoggerSymbolKey = "effect/Logger"; +var LoggerTypeId = /* @__PURE__ */ Symbol.for(LoggerSymbolKey); +var loggerVariance = { + _Message: (_) => _, + _Output: (_) => _ +}; +var makeLogger = (log2) => ({ + [LoggerTypeId]: loggerVariance, + log: log2, + pipe() { + return pipeArguments(this, arguments); + } +}); +var none7 = { + [LoggerTypeId]: loggerVariance, + log: constVoid, + pipe() { + return pipeArguments(this, arguments); + } +}; +var textOnly = /^[^\s"=]*$/; +var format4 = (quoteValue, whitespace) => ({ + annotations: annotations2, + cause: cause2, + date, + fiberId: fiberId2, + logLevel, + message, + spans +}) => { + const formatValue = (value) => value.match(textOnly) ? value : quoteValue(value); + const format5 = (label, value) => `${formatLabel(label)}=${formatValue(value)}`; + const append4 = (label, value) => " " + format5(label, value); + let out = format5("timestamp", date.toISOString()); + out += append4("level", logLevel.label); + out += append4("fiber", threadName(fiberId2)); + const messages = ensure(message); + for (let i = 0;i < messages.length; i++) { + out += append4("message", toStringUnknown(messages[i], whitespace)); + } + if (!isEmptyType(cause2)) { + out += append4("cause", pretty(cause2, { + renderErrorCause: true + })); + } + for (const span2 of spans) { + out += " " + render(date.getTime())(span2); + } + for (const [label, value] of annotations2) { + out += append4(label, toStringUnknown(value, whitespace)); + } + return out; +}; +var escapeDoubleQuotes = (s) => `"${s.replace(/\\([\s\S])|(")/g, "\\$1$2")}"`; +var stringLogger = /* @__PURE__ */ makeLogger(/* @__PURE__ */ format4(escapeDoubleQuotes)); +var colors = { + bold: "1", + red: "31", + green: "32", + yellow: "33", + blue: "34", + cyan: "36", + white: "37", + gray: "90", + black: "30", + bgBrightRed: "101" +}; +var logLevelColors = { + None: [], + All: [], + Trace: [colors.gray], + Debug: [colors.blue], + Info: [colors.green], + Warning: [colors.yellow], + Error: [colors.red], + Fatal: [colors.bgBrightRed, colors.black] +}; +var hasProcessStdout = typeof process === "object" && process !== null && typeof process.stdout === "object" && process.stdout !== null; +var processStdoutIsTTY = hasProcessStdout && process.stdout.isTTY === true; +var hasProcessStdoutOrDeno = hasProcessStdout || "Deno" in globalThis; + +// node_modules/effect/dist/esm/internal/metric/boundaries.js +var MetricBoundariesSymbolKey = "effect/MetricBoundaries"; +var MetricBoundariesTypeId = /* @__PURE__ */ Symbol.for(MetricBoundariesSymbolKey); + +class MetricBoundariesImpl { + values; + [MetricBoundariesTypeId] = MetricBoundariesTypeId; + constructor(values3) { + this.values = values3; + this._hash = pipe(string(MetricBoundariesSymbolKey), combine(array2(this.values))); + } + _hash; + [symbol]() { + return this._hash; + } + [symbol2](u) { + return isMetricBoundaries(u) && equals(this.values, u.values); + } + pipe() { + return pipeArguments(this, arguments); + } +} +var isMetricBoundaries = (u) => hasProperty(u, MetricBoundariesTypeId); +var fromIterable8 = (iterable) => { + const values3 = pipe(iterable, appendAll(of2(Number.POSITIVE_INFINITY)), dedupe); + return new MetricBoundariesImpl(values3); +}; +var exponential = (options) => pipe(makeBy(options.count - 1, (i) => options.start * Math.pow(options.factor, i)), unsafeFromArray, fromIterable8); + +// node_modules/effect/dist/esm/internal/metric/keyType.js +var MetricKeyTypeSymbolKey = "effect/MetricKeyType"; +var MetricKeyTypeTypeId = /* @__PURE__ */ Symbol.for(MetricKeyTypeSymbolKey); +var CounterKeyTypeSymbolKey = "effect/MetricKeyType/Counter"; +var CounterKeyTypeTypeId = /* @__PURE__ */ Symbol.for(CounterKeyTypeSymbolKey); +var FrequencyKeyTypeSymbolKey = "effect/MetricKeyType/Frequency"; +var FrequencyKeyTypeTypeId = /* @__PURE__ */ Symbol.for(FrequencyKeyTypeSymbolKey); +var GaugeKeyTypeSymbolKey = "effect/MetricKeyType/Gauge"; +var GaugeKeyTypeTypeId = /* @__PURE__ */ Symbol.for(GaugeKeyTypeSymbolKey); +var HistogramKeyTypeSymbolKey = "effect/MetricKeyType/Histogram"; +var HistogramKeyTypeTypeId = /* @__PURE__ */ Symbol.for(HistogramKeyTypeSymbolKey); +var SummaryKeyTypeSymbolKey = "effect/MetricKeyType/Summary"; +var SummaryKeyTypeTypeId = /* @__PURE__ */ Symbol.for(SummaryKeyTypeSymbolKey); +var metricKeyTypeVariance = { + _In: (_) => _, + _Out: (_) => _ +}; + +class CounterKeyType { + incremental; + bigint; + [MetricKeyTypeTypeId] = metricKeyTypeVariance; + [CounterKeyTypeTypeId] = CounterKeyTypeTypeId; + constructor(incremental, bigint2) { + this.incremental = incremental; + this.bigint = bigint2; + this._hash = string(CounterKeyTypeSymbolKey); + } + _hash; + [symbol]() { + return this._hash; + } + [symbol2](that) { + return isCounterKey(that); + } + pipe() { + return pipeArguments(this, arguments); + } +} +class HistogramKeyType { + boundaries; + [MetricKeyTypeTypeId] = metricKeyTypeVariance; + [HistogramKeyTypeTypeId] = HistogramKeyTypeTypeId; + constructor(boundaries) { + this.boundaries = boundaries; + this._hash = pipe(string(HistogramKeyTypeSymbolKey), combine(hash(this.boundaries))); + } + _hash; + [symbol]() { + return this._hash; + } + [symbol2](that) { + return isHistogramKey(that) && equals(this.boundaries, that.boundaries); + } + pipe() { + return pipeArguments(this, arguments); + } +} +var counter = (options) => new CounterKeyType(options?.incremental ?? false, options?.bigint ?? false); +var histogram = (boundaries) => { + return new HistogramKeyType(boundaries); +}; +var isCounterKey = (u) => hasProperty(u, CounterKeyTypeTypeId); +var isFrequencyKey = (u) => hasProperty(u, FrequencyKeyTypeTypeId); +var isGaugeKey = (u) => hasProperty(u, GaugeKeyTypeTypeId); +var isHistogramKey = (u) => hasProperty(u, HistogramKeyTypeTypeId); +var isSummaryKey = (u) => hasProperty(u, SummaryKeyTypeTypeId); + +// node_modules/effect/dist/esm/internal/metric/key.js +var MetricKeySymbolKey = "effect/MetricKey"; +var MetricKeyTypeId = /* @__PURE__ */ Symbol.for(MetricKeySymbolKey); +var metricKeyVariance = { + _Type: (_) => _ +}; +var arrayEquivilence = /* @__PURE__ */ getEquivalence3(equals); + +class MetricKeyImpl { + name; + keyType; + description; + tags; + [MetricKeyTypeId] = metricKeyVariance; + constructor(name, keyType, description, tags = []) { + this.name = name; + this.keyType = keyType; + this.description = description; + this.tags = tags; + this._hash = pipe(string(this.name + this.description), combine(hash(this.keyType)), combine(array2(this.tags))); + } + _hash; + [symbol]() { + return this._hash; + } + [symbol2](u) { + return isMetricKey(u) && this.name === u.name && equals(this.keyType, u.keyType) && equals(this.description, u.description) && arrayEquivilence(this.tags, u.tags); + } + pipe() { + return pipeArguments(this, arguments); + } +} +var isMetricKey = (u) => hasProperty(u, MetricKeyTypeId); +var counter2 = (name, options) => new MetricKeyImpl(name, counter(options), fromNullable(options?.description)); +var histogram2 = (name, boundaries, description) => new MetricKeyImpl(name, histogram(boundaries), fromNullable(description)); +var taggedWithLabels = /* @__PURE__ */ dual(2, (self, extraTags) => extraTags.length === 0 ? self : new MetricKeyImpl(self.name, self.keyType, self.description, union(self.tags, extraTags))); + +// node_modules/effect/dist/esm/internal/metric/state.js +var MetricStateSymbolKey = "effect/MetricState"; +var MetricStateTypeId = /* @__PURE__ */ Symbol.for(MetricStateSymbolKey); +var CounterStateSymbolKey = "effect/MetricState/Counter"; +var CounterStateTypeId = /* @__PURE__ */ Symbol.for(CounterStateSymbolKey); +var FrequencyStateSymbolKey = "effect/MetricState/Frequency"; +var FrequencyStateTypeId = /* @__PURE__ */ Symbol.for(FrequencyStateSymbolKey); +var GaugeStateSymbolKey = "effect/MetricState/Gauge"; +var GaugeStateTypeId = /* @__PURE__ */ Symbol.for(GaugeStateSymbolKey); +var HistogramStateSymbolKey = "effect/MetricState/Histogram"; +var HistogramStateTypeId = /* @__PURE__ */ Symbol.for(HistogramStateSymbolKey); +var SummaryStateSymbolKey = "effect/MetricState/Summary"; +var SummaryStateTypeId = /* @__PURE__ */ Symbol.for(SummaryStateSymbolKey); +var metricStateVariance = { + _A: (_) => _ +}; + +class CounterState { + count; + [MetricStateTypeId] = metricStateVariance; + [CounterStateTypeId] = CounterStateTypeId; + constructor(count) { + this.count = count; + } + [symbol]() { + return pipe(hash(CounterStateSymbolKey), combine(hash(this.count)), cached(this)); + } + [symbol2](that) { + return isCounterState(that) && this.count === that.count; + } + pipe() { + return pipeArguments(this, arguments); + } +} +var arrayEquals = /* @__PURE__ */ getEquivalence3(equals); + +class FrequencyState { + occurrences; + [MetricStateTypeId] = metricStateVariance; + [FrequencyStateTypeId] = FrequencyStateTypeId; + constructor(occurrences) { + this.occurrences = occurrences; + } + _hash; + [symbol]() { + return pipe(string(FrequencyStateSymbolKey), combine(array2(fromIterable(this.occurrences.entries()))), cached(this)); + } + [symbol2](that) { + return isFrequencyState(that) && arrayEquals(fromIterable(this.occurrences.entries()), fromIterable(that.occurrences.entries())); + } + pipe() { + return pipeArguments(this, arguments); + } +} + +class GaugeState { + value; + [MetricStateTypeId] = metricStateVariance; + [GaugeStateTypeId] = GaugeStateTypeId; + constructor(value) { + this.value = value; + } + [symbol]() { + return pipe(hash(GaugeStateSymbolKey), combine(hash(this.value)), cached(this)); + } + [symbol2](u) { + return isGaugeState(u) && this.value === u.value; + } + pipe() { + return pipeArguments(this, arguments); + } +} + +class HistogramState { + buckets; + count; + min; + max; + sum; + [MetricStateTypeId] = metricStateVariance; + [HistogramStateTypeId] = HistogramStateTypeId; + constructor(buckets, count, min2, max2, sum) { + this.buckets = buckets; + this.count = count; + this.min = min2; + this.max = max2; + this.sum = sum; + } + [symbol]() { + return pipe(hash(HistogramStateSymbolKey), combine(hash(this.buckets)), combine(hash(this.count)), combine(hash(this.min)), combine(hash(this.max)), combine(hash(this.sum)), cached(this)); + } + [symbol2](that) { + return isHistogramState(that) && equals(this.buckets, that.buckets) && this.count === that.count && this.min === that.min && this.max === that.max && this.sum === that.sum; + } + pipe() { + return pipeArguments(this, arguments); + } +} + +class SummaryState { + error; + quantiles; + count; + min; + max; + sum; + [MetricStateTypeId] = metricStateVariance; + [SummaryStateTypeId] = SummaryStateTypeId; + constructor(error, quantiles, count, min2, max2, sum) { + this.error = error; + this.quantiles = quantiles; + this.count = count; + this.min = min2; + this.max = max2; + this.sum = sum; + } + [symbol]() { + return pipe(hash(SummaryStateSymbolKey), combine(hash(this.error)), combine(hash(this.quantiles)), combine(hash(this.count)), combine(hash(this.min)), combine(hash(this.max)), combine(hash(this.sum)), cached(this)); + } + [symbol2](that) { + return isSummaryState(that) && this.error === that.error && equals(this.quantiles, that.quantiles) && this.count === that.count && this.min === that.min && this.max === that.max && this.sum === that.sum; + } + pipe() { + return pipeArguments(this, arguments); + } +} +var counter3 = (count) => new CounterState(count); +var frequency2 = (occurrences) => { + return new FrequencyState(occurrences); +}; +var gauge2 = (count) => new GaugeState(count); +var histogram3 = (options) => new HistogramState(options.buckets, options.count, options.min, options.max, options.sum); +var summary2 = (options) => new SummaryState(options.error, options.quantiles, options.count, options.min, options.max, options.sum); +var isCounterState = (u) => hasProperty(u, CounterStateTypeId); +var isFrequencyState = (u) => hasProperty(u, FrequencyStateTypeId); +var isGaugeState = (u) => hasProperty(u, GaugeStateTypeId); +var isHistogramState = (u) => hasProperty(u, HistogramStateTypeId); +var isSummaryState = (u) => hasProperty(u, SummaryStateTypeId); + +// node_modules/effect/dist/esm/internal/metric/hook.js +var MetricHookSymbolKey = "effect/MetricHook"; +var MetricHookTypeId = /* @__PURE__ */ Symbol.for(MetricHookSymbolKey); +var metricHookVariance = { + _In: (_) => _, + _Out: (_) => _ +}; +var make30 = (options) => ({ + [MetricHookTypeId]: metricHookVariance, + pipe() { + return pipeArguments(this, arguments); + }, + ...options +}); +var bigint04 = /* @__PURE__ */ BigInt(0); +var counter4 = (key) => { + let sum = key.keyType.bigint ? bigint04 : 0; + const canUpdate = key.keyType.incremental ? key.keyType.bigint ? (value) => value >= bigint04 : (value) => value >= 0 : (_value) => true; + const update4 = (value) => { + if (canUpdate(value)) { + sum = sum + value; + } + }; + return make30({ + get: () => counter3(sum), + update: update4, + modify: update4 + }); +}; +var frequency3 = (key) => { + const values3 = new Map; + for (const word of key.keyType.preregisteredWords) { + values3.set(word, 0); + } + const update4 = (word) => { + const slotCount = values3.get(word) ?? 0; + values3.set(word, slotCount + 1); + }; + return make30({ + get: () => frequency2(values3), + update: update4, + modify: update4 + }); +}; +var gauge3 = (_key, startAt) => { + let value = startAt; + return make30({ + get: () => gauge2(value), + update: (v) => { + value = v; + }, + modify: (v) => { + value = value + v; + } + }); +}; +var histogram4 = (key) => { + const bounds = key.keyType.boundaries.values; + const size5 = bounds.length; + const values3 = new Uint32Array(size5 + 1); + const boundaries = new Float64Array(size5); + let count = 0; + let sum = 0; + let min2 = Number.MAX_VALUE; + let max2 = Number.MIN_VALUE; + pipe(bounds, sort(Order), map3((n, i) => { + boundaries[i] = n; + })); + const update4 = (value) => { + let from = 0; + let to = size5; + while (from !== to) { + const mid = Math.floor(from + (to - from) / 2); + const boundary = boundaries[mid]; + if (value <= boundary) { + to = mid; + } else { + from = mid; + } + if (to === from + 1) { + if (value <= boundaries[from]) { + to = from; + } else { + from = to; + } + } + } + values3[from] = values3[from] + 1; + count = count + 1; + sum = sum + value; + if (value < min2) { + min2 = value; + } + if (value > max2) { + max2 = value; + } + }; + const getBuckets = () => { + const builder = allocate(size5); + let cumulated = 0; + for (let i = 0;i < size5; i++) { + const boundary = boundaries[i]; + const value = values3[i]; + cumulated = cumulated + value; + builder[i] = [boundary, cumulated]; + } + return builder; + }; + return make30({ + get: () => histogram3({ + buckets: getBuckets(), + count, + min: min2, + max: max2, + sum + }), + update: update4, + modify: update4 + }); +}; +var summary3 = (key) => { + const { + error, + maxAge, + maxSize, + quantiles + } = key.keyType; + const sortedQuantiles = pipe(quantiles, sort(Order)); + const values3 = allocate(maxSize); + let head4 = 0; + let count = 0; + let sum = 0; + let min2 = 0; + let max2 = 0; + const snapshot = (now) => { + const builder = []; + let i = 0; + while (i !== maxSize - 1) { + const item = values3[i]; + if (item != null) { + const [t, v] = item; + const age = millis(now - t); + if (greaterThanOrEqualTo3(age, zero2) && lessThanOrEqualTo3(age, maxAge)) { + builder.push(v); + } + } + i = i + 1; + } + return calculateQuantiles(error, sortedQuantiles, sort(builder, Order)); + }; + const observe = (value, timestamp) => { + if (maxSize > 0) { + head4 = head4 + 1; + const target = head4 % maxSize; + values3[target] = [timestamp, value]; + } + min2 = count === 0 ? value : Math.min(min2, value); + max2 = count === 0 ? value : Math.max(max2, value); + count = count + 1; + sum = sum + value; + }; + return make30({ + get: () => summary2({ + error, + quantiles: snapshot(Date.now()), + count, + min: min2, + max: max2, + sum + }), + update: ([value, timestamp]) => observe(value, timestamp), + modify: ([value, timestamp]) => observe(value, timestamp) + }); +}; +var calculateQuantiles = (error, sortedQuantiles, sortedSamples) => { + const sampleCount = sortedSamples.length; + if (!isNonEmptyReadonlyArray(sortedQuantiles)) { + return empty(); + } + const head4 = sortedQuantiles[0]; + const tail = sortedQuantiles.slice(1); + const resolvedHead = resolveQuantile(error, sampleCount, none2(), 0, head4, sortedSamples); + const resolved = of(resolvedHead); + tail.forEach((quantile) => { + resolved.push(resolveQuantile(error, sampleCount, resolvedHead.value, resolvedHead.consumed, quantile, resolvedHead.rest)); + }); + return map3(resolved, (rq) => [rq.quantile, rq.value]); +}; +var resolveQuantile = (error, sampleCount, current, consumed, quantile, rest) => { + let error_1 = error; + let sampleCount_1 = sampleCount; + let current_1 = current; + let consumed_1 = consumed; + let quantile_1 = quantile; + let rest_1 = rest; + let error_2 = error; + let sampleCount_2 = sampleCount; + let current_2 = current; + let consumed_2 = consumed; + let quantile_2 = quantile; + let rest_2 = rest; + while (true) { + if (!isNonEmptyReadonlyArray(rest_1)) { + return { + quantile: quantile_1, + value: none2(), + consumed: consumed_1, + rest: [] + }; + } + if (quantile_1 === 1) { + return { + quantile: quantile_1, + value: some2(lastNonEmpty(rest_1)), + consumed: consumed_1 + rest_1.length, + rest: [] + }; + } + const headValue = headNonEmpty(rest_1); + const sameHead = span(rest_1, (n) => n === headValue); + const desired = quantile_1 * sampleCount_1; + const allowedError = error_1 / 2 * desired; + const candConsumed = consumed_1 + sameHead[0].length; + const candError = Math.abs(candConsumed - desired); + if (candConsumed < desired - allowedError) { + error_2 = error_1; + sampleCount_2 = sampleCount_1; + current_2 = head(rest_1); + consumed_2 = candConsumed; + quantile_2 = quantile_1; + rest_2 = sameHead[1]; + error_1 = error_2; + sampleCount_1 = sampleCount_2; + current_1 = current_2; + consumed_1 = consumed_2; + quantile_1 = quantile_2; + rest_1 = rest_2; + continue; + } + if (candConsumed > desired + allowedError) { + const valueToReturn = isNone2(current_1) ? some2(headValue) : current_1; + return { + quantile: quantile_1, + value: valueToReturn, + consumed: consumed_1, + rest: rest_1 + }; + } + switch (current_1._tag) { + case "None": { + error_2 = error_1; + sampleCount_2 = sampleCount_1; + current_2 = head(rest_1); + consumed_2 = candConsumed; + quantile_2 = quantile_1; + rest_2 = sameHead[1]; + error_1 = error_2; + sampleCount_1 = sampleCount_2; + current_1 = current_2; + consumed_1 = consumed_2; + quantile_1 = quantile_2; + rest_1 = rest_2; + continue; + } + case "Some": { + const prevError = Math.abs(desired - current_1.value); + if (candError < prevError) { + error_2 = error_1; + sampleCount_2 = sampleCount_1; + current_2 = head(rest_1); + consumed_2 = candConsumed; + quantile_2 = quantile_1; + rest_2 = sameHead[1]; + error_1 = error_2; + sampleCount_1 = sampleCount_2; + current_1 = current_2; + consumed_1 = consumed_2; + quantile_1 = quantile_2; + rest_1 = rest_2; + continue; + } + return { + quantile: quantile_1, + value: some2(current_1.value), + consumed: consumed_1, + rest: rest_1 + }; + } + } + } + throw new Error("BUG: MetricHook.resolveQuantiles - please report an issue at https://github.com/Effect-TS/effect/issues"); +}; + +// node_modules/effect/dist/esm/internal/metric/pair.js +var MetricPairSymbolKey = "effect/MetricPair"; +var MetricPairTypeId = /* @__PURE__ */ Symbol.for(MetricPairSymbolKey); +var metricPairVariance = { + _Type: (_) => _ +}; +var unsafeMake7 = (metricKey, metricState) => { + return { + [MetricPairTypeId]: metricPairVariance, + metricKey, + metricState, + pipe() { + return pipeArguments(this, arguments); + } + }; +}; + +// node_modules/effect/dist/esm/internal/metric/registry.js +var MetricRegistrySymbolKey = "effect/MetricRegistry"; +var MetricRegistryTypeId = /* @__PURE__ */ Symbol.for(MetricRegistrySymbolKey); + +class MetricRegistryImpl { + [MetricRegistryTypeId] = MetricRegistryTypeId; + map = /* @__PURE__ */ empty17(); + snapshot() { + const result = []; + for (const [key, hook] of this.map) { + result.push(unsafeMake7(key, hook.get())); + } + return result; + } + get(key) { + const hook = pipe(this.map, get8(key), getOrUndefined); + if (hook == null) { + if (isCounterKey(key.keyType)) { + return this.getCounter(key); + } + if (isGaugeKey(key.keyType)) { + return this.getGauge(key); + } + if (isFrequencyKey(key.keyType)) { + return this.getFrequency(key); + } + if (isHistogramKey(key.keyType)) { + return this.getHistogram(key); + } + if (isSummaryKey(key.keyType)) { + return this.getSummary(key); + } + throw new Error("BUG: MetricRegistry.get - unknown MetricKeyType - please report an issue at https://github.com/Effect-TS/effect/issues"); + } else { + return hook; + } + } + getCounter(key) { + let value = pipe(this.map, get8(key), getOrUndefined); + if (value == null) { + const counter5 = counter4(key); + if (!pipe(this.map, has4(key))) { + pipe(this.map, set4(key, counter5)); + } + value = counter5; + } + return value; + } + getFrequency(key) { + let value = pipe(this.map, get8(key), getOrUndefined); + if (value == null) { + const frequency4 = frequency3(key); + if (!pipe(this.map, has4(key))) { + pipe(this.map, set4(key, frequency4)); + } + value = frequency4; + } + return value; + } + getGauge(key) { + let value = pipe(this.map, get8(key), getOrUndefined); + if (value == null) { + const gauge4 = gauge3(key, key.keyType.bigint ? BigInt(0) : 0); + if (!pipe(this.map, has4(key))) { + pipe(this.map, set4(key, gauge4)); + } + value = gauge4; + } + return value; + } + getHistogram(key) { + let value = pipe(this.map, get8(key), getOrUndefined); + if (value == null) { + const histogram5 = histogram4(key); + if (!pipe(this.map, has4(key))) { + pipe(this.map, set4(key, histogram5)); + } + value = histogram5; + } + return value; + } + getSummary(key) { + let value = pipe(this.map, get8(key), getOrUndefined); + if (value == null) { + const summary4 = summary3(key); + if (!pipe(this.map, has4(key))) { + pipe(this.map, set4(key, summary4)); + } + value = summary4; + } + return value; + } +} +var make31 = () => { + return new MetricRegistryImpl; +}; + +// node_modules/effect/dist/esm/internal/metric.js +var MetricSymbolKey = "effect/Metric"; +var MetricTypeId = /* @__PURE__ */ Symbol.for(MetricSymbolKey); +var metricVariance = { + _Type: (_) => _, + _In: (_) => _, + _Out: (_) => _ +}; +var globalMetricRegistry = /* @__PURE__ */ globalValue(/* @__PURE__ */ Symbol.for("effect/Metric/globalMetricRegistry"), () => make31()); +var make32 = function(keyType, unsafeUpdate, unsafeValue, unsafeModify) { + const metric = Object.assign((effect) => tap(effect, (a) => update4(metric, a)), { + [MetricTypeId]: metricVariance, + keyType, + unsafeUpdate, + unsafeValue, + unsafeModify, + register() { + this.unsafeValue([]); + return this; + }, + pipe() { + return pipeArguments(this, arguments); + } + }); + return metric; +}; +var counter5 = (name, options) => fromMetricKey(counter2(name, options)); +var fromMetricKey = (key) => { + let untaggedHook; + const hookCache = new WeakMap; + const hook = (extraTags) => { + if (extraTags.length === 0) { + if (untaggedHook !== undefined) { + return untaggedHook; + } + untaggedHook = globalMetricRegistry.get(key); + return untaggedHook; + } + let hook2 = hookCache.get(extraTags); + if (hook2 !== undefined) { + return hook2; + } + hook2 = globalMetricRegistry.get(taggedWithLabels(key, extraTags)); + hookCache.set(extraTags, hook2); + return hook2; + }; + return make32(key.keyType, (input, extraTags) => hook(extraTags).update(input), (extraTags) => hook(extraTags).get(), (input, extraTags) => hook(extraTags).modify(input)); +}; +var histogram5 = (name, boundaries, description) => fromMetricKey(histogram2(name, boundaries, description)); +var tagged = /* @__PURE__ */ dual(3, (self, key, value) => taggedWithLabels2(self, [make29(key, value)])); +var taggedWithLabels2 = /* @__PURE__ */ dual(2, (self, extraTags) => { + return make32(self.keyType, (input, extraTags1) => self.unsafeUpdate(input, union(extraTags, extraTags1)), (extraTags1) => self.unsafeValue(union(extraTags, extraTags1)), (input, extraTags1) => self.unsafeModify(input, union(extraTags, extraTags1))); +}); +var update4 = /* @__PURE__ */ dual(2, (self, input) => fiberRefGetWith(currentMetricLabels, (tags) => sync(() => self.unsafeUpdate(input, tags)))); + +// node_modules/effect/dist/esm/internal/request.js +var RequestSymbolKey = "effect/Request"; +var RequestTypeId = /* @__PURE__ */ Symbol.for(RequestSymbolKey); +var requestVariance = { + _E: (_) => _, + _A: (_) => _ +}; +var RequestPrototype = { + ...StructuralPrototype, + [RequestTypeId]: requestVariance +}; +var isRequest = (u) => hasProperty(u, RequestTypeId); +var Class2 = /* @__PURE__ */ function() { + function Class3(args2) { + if (args2) { + Object.assign(this, args2); + } + } + Class3.prototype = RequestPrototype; + return Class3; +}(); +var complete = /* @__PURE__ */ dual(2, (self, result) => fiberRefGetWith(currentRequestMap, (map10) => sync(() => { + if (map10.has(self)) { + const entry = map10.get(self); + if (!entry.state.completed) { + entry.state.completed = true; + deferredUnsafeDone(entry.result, result); + } + } +}))); +class Listeners { + count = 0; + observers = /* @__PURE__ */ new Set; + interrupted = false; + addObserver(f) { + this.observers.add(f); + } + removeObserver(f) { + this.observers.delete(f); + } + increment() { + this.count++; + this.observers.forEach((f) => f(this.count)); + } + decrement() { + this.count--; + this.observers.forEach((f) => f(this.count)); + } +} + +// node_modules/effect/dist/esm/internal/redBlackTree/iterator.js +var Direction = { + Forward: 0, + Backward: 1 << 0 +}; + +class RedBlackTreeIterator { + self; + stack; + direction; + count = 0; + constructor(self, stack, direction) { + this.self = self; + this.stack = stack; + this.direction = direction; + } + clone() { + return new RedBlackTreeIterator(this.self, this.stack.slice(), this.direction); + } + reversed() { + return new RedBlackTreeIterator(this.self, this.stack.slice(), this.direction === Direction.Forward ? Direction.Backward : Direction.Forward); + } + next() { + const entry = this.entry; + this.count++; + if (this.direction === Direction.Forward) { + this.moveNext(); + } else { + this.movePrev(); + } + switch (entry._tag) { + case "None": { + return { + done: true, + value: this.count + }; + } + case "Some": { + return { + done: false, + value: entry.value + }; + } + } + } + get key() { + if (this.stack.length > 0) { + return some2(this.stack[this.stack.length - 1].key); + } + return none2(); + } + get value() { + if (this.stack.length > 0) { + return some2(this.stack[this.stack.length - 1].value); + } + return none2(); + } + get entry() { + return map2(last(this.stack), (node) => [node.key, node.value]); + } + get index() { + let idx = 0; + const stack = this.stack; + if (stack.length === 0) { + const r = this.self._root; + if (r != null) { + return r.count; + } + return 0; + } else if (stack[stack.length - 1].left != null) { + idx = stack[stack.length - 1].left.count; + } + for (let s = stack.length - 2;s >= 0; --s) { + if (stack[s + 1] === stack[s].right) { + ++idx; + if (stack[s].left != null) { + idx += stack[s].left.count; + } + } + } + return idx; + } + moveNext() { + const stack = this.stack; + if (stack.length === 0) { + return; + } + let n = stack[stack.length - 1]; + if (n.right != null) { + n = n.right; + while (n != null) { + stack.push(n); + n = n.left; + } + } else { + stack.pop(); + while (stack.length > 0 && stack[stack.length - 1].right === n) { + n = stack[stack.length - 1]; + stack.pop(); + } + } + } + get hasNext() { + const stack = this.stack; + if (stack.length === 0) { + return false; + } + if (stack[stack.length - 1].right != null) { + return true; + } + for (let s = stack.length - 1;s > 0; --s) { + if (stack[s - 1].left === stack[s]) { + return true; + } + } + return false; + } + movePrev() { + const stack = this.stack; + if (stack.length === 0) { + return; + } + let n = stack[stack.length - 1]; + if (n != null && n.left != null) { + n = n.left; + while (n != null) { + stack.push(n); + n = n.right; + } + } else { + stack.pop(); + while (stack.length > 0 && stack[stack.length - 1].left === n) { + n = stack[stack.length - 1]; + stack.pop(); + } + } + } + get hasPrev() { + const stack = this.stack; + if (stack.length === 0) { + return false; + } + if (stack[stack.length - 1].left != null) { + return true; + } + for (let s = stack.length - 1;s > 0; --s) { + if (stack[s - 1].right === stack[s]) { + return true; + } + } + return false; + } +} + +// node_modules/effect/dist/esm/internal/redBlackTree/node.js +var Color = { + Red: 0, + Black: 1 << 0 +}; +var repaint = ({ + count, + key, + left: left3, + right: right3, + value +}, color) => ({ + color, + key, + value, + left: left3, + right: right3, + count +}); +var recount = (node) => { + node.count = 1 + (node.left?.count ?? 0) + (node.right?.count ?? 0); +}; + +// node_modules/effect/dist/esm/internal/redBlackTree.js +var RedBlackTreeSymbolKey = "effect/RedBlackTree"; +var RedBlackTreeTypeId = /* @__PURE__ */ Symbol.for(RedBlackTreeSymbolKey); +var redBlackTreeVariance = { + _Key: (_) => _, + _Value: (_) => _ +}; +var RedBlackTreeProto = { + [RedBlackTreeTypeId]: redBlackTreeVariance, + [symbol]() { + let hash2 = hash(RedBlackTreeSymbolKey); + for (const item of this) { + hash2 ^= pipe(hash(item[0]), combine(hash(item[1]))); + } + return cached(this, hash2); + }, + [symbol2](that) { + if (isRedBlackTree(that)) { + if ((this._root?.count ?? 0) !== (that._root?.count ?? 0)) { + return false; + } + const entries2 = Array.from(that); + return Array.from(this).every((itemSelf, i) => { + const itemThat = entries2[i]; + return equals(itemSelf[0], itemThat[0]) && equals(itemSelf[1], itemThat[1]); + }); + } + return false; + }, + [Symbol.iterator]() { + const stack = []; + let n = this._root; + while (n != null) { + stack.push(n); + n = n.left; + } + return new RedBlackTreeIterator(this, stack, Direction.Forward); + }, + toString() { + return format(this.toJSON()); + }, + toJSON() { + return { + _id: "RedBlackTree", + values: Array.from(this).map(toJSON) + }; + }, + [NodeInspectSymbol]() { + return this.toJSON(); + }, + pipe() { + return pipeArguments(this, arguments); + } +}; +var makeImpl3 = (ord, root) => { + const tree = Object.create(RedBlackTreeProto); + tree._ord = ord; + tree._root = root; + return tree; +}; +var isRedBlackTree = (u) => hasProperty(u, RedBlackTreeTypeId); +var empty23 = (ord) => makeImpl3(ord, undefined); +var fromIterable9 = /* @__PURE__ */ dual(2, (entries2, ord) => { + let tree = empty23(ord); + for (const [key, value] of entries2) { + tree = insert(tree, key, value); + } + return tree; +}); +var findFirst5 = /* @__PURE__ */ dual(2, (self, key) => { + const cmp = self._ord; + let node = self._root; + while (node !== undefined) { + const d = cmp(key, node.key); + if (equals(key, node.key)) { + return some2(node.value); + } + if (d <= 0) { + node = node.left; + } else { + node = node.right; + } + } + return none2(); +}); +var has5 = /* @__PURE__ */ dual(2, (self, key) => isSome2(findFirst5(self, key))); +var insert = /* @__PURE__ */ dual(3, (self, key, value) => { + const cmp = self._ord; + let n = self._root; + const n_stack = []; + const d_stack = []; + while (n != null) { + const d = cmp(key, n.key); + n_stack.push(n); + d_stack.push(d); + if (d <= 0) { + n = n.left; + } else { + n = n.right; + } + } + n_stack.push({ + color: Color.Red, + key, + value, + left: undefined, + right: undefined, + count: 1 + }); + for (let s = n_stack.length - 2;s >= 0; --s) { + const n2 = n_stack[s]; + if (d_stack[s] <= 0) { + n_stack[s] = { + color: n2.color, + key: n2.key, + value: n2.value, + left: n_stack[s + 1], + right: n2.right, + count: n2.count + 1 + }; + } else { + n_stack[s] = { + color: n2.color, + key: n2.key, + value: n2.value, + left: n2.left, + right: n_stack[s + 1], + count: n2.count + 1 + }; + } + } + for (let s = n_stack.length - 1;s > 1; --s) { + const p = n_stack[s - 1]; + const n3 = n_stack[s]; + if (p.color === Color.Black || n3.color === Color.Black) { + break; + } + const pp = n_stack[s - 2]; + if (pp.left === p) { + if (p.left === n3) { + const y = pp.right; + if (y && y.color === Color.Red) { + p.color = Color.Black; + pp.right = repaint(y, Color.Black); + pp.color = Color.Red; + s -= 1; + } else { + pp.color = Color.Red; + pp.left = p.right; + p.color = Color.Black; + p.right = pp; + n_stack[s - 2] = p; + n_stack[s - 1] = n3; + recount(pp); + recount(p); + if (s >= 3) { + const ppp = n_stack[s - 3]; + if (ppp.left === pp) { + ppp.left = p; + } else { + ppp.right = p; + } + } + break; + } + } else { + const y = pp.right; + if (y && y.color === Color.Red) { + p.color = Color.Black; + pp.right = repaint(y, Color.Black); + pp.color = Color.Red; + s -= 1; + } else { + p.right = n3.left; + pp.color = Color.Red; + pp.left = n3.right; + n3.color = Color.Black; + n3.left = p; + n3.right = pp; + n_stack[s - 2] = n3; + n_stack[s - 1] = p; + recount(pp); + recount(p); + recount(n3); + if (s >= 3) { + const ppp = n_stack[s - 3]; + if (ppp.left === pp) { + ppp.left = n3; + } else { + ppp.right = n3; + } + } + break; + } + } + } else { + if (p.right === n3) { + const y = pp.left; + if (y && y.color === Color.Red) { + p.color = Color.Black; + pp.left = repaint(y, Color.Black); + pp.color = Color.Red; + s -= 1; + } else { + pp.color = Color.Red; + pp.right = p.left; + p.color = Color.Black; + p.left = pp; + n_stack[s - 2] = p; + n_stack[s - 1] = n3; + recount(pp); + recount(p); + if (s >= 3) { + const ppp = n_stack[s - 3]; + if (ppp.right === pp) { + ppp.right = p; + } else { + ppp.left = p; + } + } + break; + } + } else { + const y = pp.left; + if (y && y.color === Color.Red) { + p.color = Color.Black; + pp.left = repaint(y, Color.Black); + pp.color = Color.Red; + s -= 1; + } else { + p.left = n3.right; + pp.color = Color.Red; + pp.right = n3.left; + n3.color = Color.Black; + n3.right = p; + n3.left = pp; + n_stack[s - 2] = n3; + n_stack[s - 1] = p; + recount(pp); + recount(p); + recount(n3); + if (s >= 3) { + const ppp = n_stack[s - 3]; + if (ppp.right === pp) { + ppp.right = n3; + } else { + ppp.left = n3; + } + } + break; + } + } + } + } + n_stack[0].color = Color.Black; + return makeImpl3(self._ord, n_stack[0]); +}); +var keysForward = (self) => keys3(self, Direction.Forward); +var keys3 = (self, direction) => { + const begin = self[Symbol.iterator](); + let count = 0; + return { + [Symbol.iterator]: () => keys3(self, direction), + next: () => { + count++; + const entry = begin.key; + if (direction === Direction.Forward) { + begin.moveNext(); + } else { + begin.movePrev(); + } + switch (entry._tag) { + case "None": { + return { + done: true, + value: count + }; + } + case "Some": { + return { + done: false, + value: entry.value + }; + } + } + } + }; +}; + +// node_modules/effect/dist/esm/RedBlackTree.js +var fromIterable10 = fromIterable9; +var has6 = has5; +var keys4 = keysForward; + +// node_modules/effect/dist/esm/SortedSet.js +var TypeId15 = /* @__PURE__ */ Symbol.for("effect/SortedSet"); +var SortedSetProto = { + [TypeId15]: { + _A: (_) => _ + }, + [symbol]() { + return pipe(hash(this.keyTree), combine(hash(TypeId15)), cached(this)); + }, + [symbol2](that) { + return isSortedSet(that) && equals(this.keyTree, that.keyTree); + }, + [Symbol.iterator]() { + return keys4(this.keyTree); + }, + toString() { + return format(this.toJSON()); + }, + toJSON() { + return { + _id: "SortedSet", + values: Array.from(this).map(toJSON) + }; + }, + [NodeInspectSymbol]() { + return this.toJSON(); + }, + pipe() { + return pipeArguments(this, arguments); + } +}; +var fromTree = (keyTree) => { + const a = Object.create(SortedSetProto); + a.keyTree = keyTree; + return a; +}; +var isSortedSet = (u) => hasProperty(u, TypeId15); +var fromIterable11 = /* @__PURE__ */ dual(2, (iterable, ord) => fromTree(fromIterable10(Array.from(iterable).map((k) => [k, true]), ord))); +var every5 = /* @__PURE__ */ dual(2, (self, predicate) => { + for (const value of self) { + if (!predicate(value)) { + return false; + } + } + return true; +}); +var has7 = /* @__PURE__ */ dual(2, (self, value) => has6(self.keyTree, value)); +var isSubset2 = /* @__PURE__ */ dual(2, (self, that) => every5(self, (a) => has7(that, a))); +var values3 = (self) => keys4(self.keyTree); +var getEquivalence6 = () => (a, b) => isSubset2(a, b) && isSubset2(b, a); + +// node_modules/effect/dist/esm/internal/supervisor.js +var SupervisorSymbolKey = "effect/Supervisor"; +var SupervisorTypeId = /* @__PURE__ */ Symbol.for(SupervisorSymbolKey); +var supervisorVariance = { + _T: (_) => _ +}; + +class ProxySupervisor { + underlying; + value0; + [SupervisorTypeId] = supervisorVariance; + constructor(underlying, value0) { + this.underlying = underlying; + this.value0 = value0; + } + get value() { + return this.value0; + } + onStart(context2, effect, parent, fiber) { + this.underlying.onStart(context2, effect, parent, fiber); + } + onEnd(value, fiber) { + this.underlying.onEnd(value, fiber); + } + onEffect(fiber, effect) { + this.underlying.onEffect(fiber, effect); + } + onSuspend(fiber) { + this.underlying.onSuspend(fiber); + } + onResume(fiber) { + this.underlying.onResume(fiber); + } + map(f) { + return new ProxySupervisor(this, pipe(this.value, map9(f))); + } + zip(right3) { + return new Zip(this, right3); + } +} + +class Zip { + left; + right; + _tag = "Zip"; + [SupervisorTypeId] = supervisorVariance; + constructor(left3, right3) { + this.left = left3; + this.right = right3; + } + get value() { + return zip2(this.left.value, this.right.value); + } + onStart(context2, effect, parent, fiber) { + this.left.onStart(context2, effect, parent, fiber); + this.right.onStart(context2, effect, parent, fiber); + } + onEnd(value, fiber) { + this.left.onEnd(value, fiber); + this.right.onEnd(value, fiber); + } + onEffect(fiber, effect) { + this.left.onEffect(fiber, effect); + this.right.onEffect(fiber, effect); + } + onSuspend(fiber) { + this.left.onSuspend(fiber); + this.right.onSuspend(fiber); + } + onResume(fiber) { + this.left.onResume(fiber); + this.right.onResume(fiber); + } + map(f) { + return new ProxySupervisor(this, pipe(this.value, map9(f))); + } + zip(right3) { + return new Zip(this, right3); + } +} +var isZip = (self) => hasProperty(self, SupervisorTypeId) && isTagged(self, "Zip"); + +class Track { + [SupervisorTypeId] = supervisorVariance; + fibers = /* @__PURE__ */ new Set; + get value() { + return sync(() => Array.from(this.fibers)); + } + onStart(_context, _effect, _parent, fiber) { + this.fibers.add(fiber); + } + onEnd(_value, fiber) { + this.fibers.delete(fiber); + } + onEffect(_fiber, _effect) {} + onSuspend(_fiber) {} + onResume(_fiber) {} + map(f) { + return new ProxySupervisor(this, pipe(this.value, map9(f))); + } + zip(right3) { + return new Zip(this, right3); + } + onRun(execution, _fiber) { + return execution(); + } +} + +class Const { + effect; + [SupervisorTypeId] = supervisorVariance; + constructor(effect) { + this.effect = effect; + } + get value() { + return this.effect; + } + onStart(_context, _effect, _parent, _fiber) {} + onEnd(_value, _fiber) {} + onEffect(_fiber, _effect) {} + onSuspend(_fiber) {} + onResume(_fiber) {} + map(f) { + return new ProxySupervisor(this, pipe(this.value, map9(f))); + } + zip(right3) { + return new Zip(this, right3); + } + onRun(execution, _fiber) { + return execution(); + } +} +var unsafeTrack = () => { + return new Track; +}; +var track = /* @__PURE__ */ sync(unsafeTrack); +var fromEffect = (effect) => { + return new Const(effect); +}; +var none8 = /* @__PURE__ */ globalValue("effect/Supervisor/none", () => fromEffect(void_)); + +// node_modules/effect/dist/esm/Differ.js +var make34 = make15; + +// node_modules/effect/dist/esm/internal/supervisor/patch.js +var OP_EMPTY3 = "Empty"; +var OP_ADD_SUPERVISOR = "AddSupervisor"; +var OP_REMOVE_SUPERVISOR = "RemoveSupervisor"; +var OP_AND_THEN2 = "AndThen"; +var empty25 = { + _tag: OP_EMPTY3 +}; +var combine8 = (self, that) => { + return { + _tag: OP_AND_THEN2, + first: self, + second: that + }; +}; +var patch8 = (self, supervisor) => { + return patchLoop(supervisor, of2(self)); +}; +var patchLoop = (_supervisor, _patches) => { + let supervisor = _supervisor; + let patches = _patches; + while (isNonEmpty2(patches)) { + const head4 = headNonEmpty2(patches); + switch (head4._tag) { + case OP_EMPTY3: { + patches = tailNonEmpty2(patches); + break; + } + case OP_ADD_SUPERVISOR: { + supervisor = supervisor.zip(head4.supervisor); + patches = tailNonEmpty2(patches); + break; + } + case OP_REMOVE_SUPERVISOR: { + supervisor = removeSupervisor(supervisor, head4.supervisor); + patches = tailNonEmpty2(patches); + break; + } + case OP_AND_THEN2: { + patches = prepend2(head4.first)(prepend2(head4.second)(tailNonEmpty2(patches))); + break; + } + } + } + return supervisor; +}; +var removeSupervisor = (self, that) => { + if (equals(self, that)) { + return none8; + } else { + if (isZip(self)) { + return removeSupervisor(self.left, that).zip(removeSupervisor(self.right, that)); + } else { + return self; + } + } +}; +var toSet2 = (self) => { + if (equals(self, none8)) { + return empty7(); + } else { + if (isZip(self)) { + return pipe(toSet2(self.left), union3(toSet2(self.right))); + } else { + return make11(self); + } + } +}; +var diff7 = (oldValue, newValue) => { + if (equals(oldValue, newValue)) { + return empty25; + } + const oldSupervisors = toSet2(oldValue); + const newSupervisors = toSet2(newValue); + const added = pipe(newSupervisors, difference3(oldSupervisors), reduce4(empty25, (patch9, supervisor) => combine8(patch9, { + _tag: OP_ADD_SUPERVISOR, + supervisor + }))); + const removed = pipe(oldSupervisors, difference3(newSupervisors), reduce4(empty25, (patch9, supervisor) => combine8(patch9, { + _tag: OP_REMOVE_SUPERVISOR, + supervisor + }))); + return combine8(added, removed); +}; +var differ2 = /* @__PURE__ */ make34({ + empty: empty25, + patch: patch8, + combine: combine8, + diff: diff7 }); -// node_modules/effect/dist/esm/BigDecimal.js -var FINITE_INT_REGEX = /^[+-]?\d+$/; -var TypeId17 = /* @__PURE__ */ Symbol.for("effect/BigDecimal"); -var BigDecimalProto = { - [TypeId17]: TypeId17, - [symbol]() { - const normalized = normalize(this); - return pipe(hash(normalized.value), combine(number2(normalized.scale)), cached(this)); +// node_modules/effect/dist/esm/internal/fiberRuntime.js +var fiberStarted = /* @__PURE__ */ counter5("effect_fiber_started", { + incremental: true +}); +var fiberActive = /* @__PURE__ */ counter5("effect_fiber_active"); +var fiberSuccesses = /* @__PURE__ */ counter5("effect_fiber_successes", { + incremental: true +}); +var fiberFailures = /* @__PURE__ */ counter5("effect_fiber_failures", { + incremental: true +}); +var fiberLifetimes = /* @__PURE__ */ tagged(/* @__PURE__ */ histogram5("effect_fiber_lifetimes", /* @__PURE__ */ exponential({ + start: 0.5, + factor: 2, + count: 35 +})), "time_unit", "milliseconds"); +var EvaluationSignalContinue = "Continue"; +var EvaluationSignalDone = "Done"; +var EvaluationSignalYieldNow = "Yield"; +var runtimeFiberVariance = { + _E: (_) => _, + _A: (_) => _ +}; +var absurd = (_) => { + throw new Error(`BUG: FiberRuntime - ${toStringUnknown(_)} - please report an issue at https://github.com/Effect-TS/effect/issues`); +}; +var YieldedOp = /* @__PURE__ */ Symbol.for("effect/internal/fiberRuntime/YieldedOp"); +var yieldedOpChannel = /* @__PURE__ */ globalValue("effect/internal/fiberRuntime/yieldedOpChannel", () => ({ + currentOp: null +})); +var contOpSuccess = { + [OP_ON_SUCCESS]: (_, cont, value) => { + return internalCall(() => cont.effect_instruction_i1(value)); }, - [symbol2](that) { - return isBigDecimal(that) && equals3(this, that); + ["OnStep"]: (_, _cont, value) => { + return exitSucceed(exitSucceed(value)); }, - toString() { - return `BigDecimal(${format4(this)})`; + [OP_ON_SUCCESS_AND_FAILURE]: (_, cont, value) => { + return internalCall(() => cont.effect_instruction_i2(value)); }, - toJSON() { - return { - _id: "BigDecimal", - value: String(this.value), - scale: this.scale - }; + [OP_REVERT_FLAGS]: (self, cont, value) => { + self.patchRuntimeFlags(self.currentRuntimeFlags, cont.patch); + if (interruptible(self.currentRuntimeFlags) && self.isInterrupted()) { + return exitFailCause(self.getInterruptedCause()); + } else { + return exitSucceed(value); + } }, - [NodeInspectSymbol]() { - return this.toJSON(); + [OP_WHILE]: (self, cont, value) => { + internalCall(() => cont.effect_instruction_i2(value)); + if (internalCall(() => cont.effect_instruction_i0())) { + self.pushStack(cont); + return internalCall(() => cont.effect_instruction_i1()); + } else { + return void_; + } }, - pipe() { - return pipeArguments(this, arguments); + [OP_ITERATOR]: (self, cont, value) => { + while (true) { + const state = internalCall(() => cont.effect_instruction_i0.next(value)); + if (state.done) { + return exitSucceed(state.value); + } + const primitive = yieldWrapGet(state.value); + if (!exitIsExit(primitive)) { + self.pushStack(cont); + return primitive; + } else if (primitive._tag === "Failure") { + return primitive; + } + value = primitive.value; + } + } +}; +var drainQueueWhileRunningTable = { + [OP_INTERRUPT_SIGNAL]: (self, runtimeFlags2, cur, message) => { + self.processNewInterruptSignal(message.cause); + return interruptible(runtimeFlags2) ? exitFailCause(message.cause) : cur; + }, + [OP_RESUME]: (_self, _runtimeFlags, _cur, _message) => { + throw new Error("It is illegal to have multiple concurrent run loops in a single fiber"); + }, + [OP_STATEFUL]: (self, runtimeFlags2, cur, message) => { + message.onFiber(self, running2(runtimeFlags2)); + return cur; + }, + [OP_YIELD_NOW]: (_self, _runtimeFlags, cur, _message) => { + return flatMap7(yieldNow(), () => cur); + } +}; +var runBlockedRequests = (self) => forEachSequentialDiscard(flatten3(self), (requestsByRequestResolver) => forEachConcurrentDiscard(sequentialCollectionToChunk(requestsByRequestResolver), ([dataSource, sequential4]) => { + const map10 = new Map; + const arr = []; + for (const block of sequential4) { + arr.push(toReadonlyArray(block)); + for (const entry of block) { + map10.set(entry.request, entry); + } + } + const flat = arr.flat(); + return fiberRefLocally(invokeWithInterrupt(dataSource.runAll(arr), flat, () => flat.forEach((entry) => { + entry.listeners.interrupted = true; + })), currentRequestMap, map10); +}, false, false)); +var _version = /* @__PURE__ */ getCurrentVersion(); + +class FiberRuntime extends Class { + [FiberTypeId] = fiberVariance2; + [RuntimeFiberTypeId] = runtimeFiberVariance; + _fiberRefs; + _fiberId; + _queue = /* @__PURE__ */ new Array; + _children = null; + _observers = /* @__PURE__ */ new Array; + _running = false; + _stack = []; + _asyncInterruptor = null; + _asyncBlockingOn = null; + _exitValue = null; + _steps = []; + _isYielding = false; + currentRuntimeFlags; + currentOpCount = 0; + currentSupervisor; + currentScheduler; + currentTracer; + currentSpan; + currentContext; + currentDefaultServices; + constructor(fiberId2, fiberRefs0, runtimeFlags0) { + super(); + this.currentRuntimeFlags = runtimeFlags0; + this._fiberId = fiberId2; + this._fiberRefs = fiberRefs0; + if (runtimeMetrics(runtimeFlags0)) { + const tags = this.getFiberRef(currentMetricLabels); + fiberStarted.unsafeUpdate(1, tags); + fiberActive.unsafeUpdate(1, tags); + } + this.refreshRefCache(); + } + commit() { + return join2(this); + } + id() { + return this._fiberId; + } + resume(effect) { + this.tell(resume(effect)); + } + get status() { + return this.ask((_, status) => status); + } + get runtimeFlags() { + return this.ask((state, status) => { + if (isDone2(status)) { + return state.currentRuntimeFlags; + } + return status.runtimeFlags; + }); + } + scope() { + return unsafeMake6(this); + } + get children() { + return this.ask((fiber) => Array.from(fiber.getChildren())); + } + getChildren() { + if (this._children === null) { + this._children = new Set; + } + return this._children; + } + getInterruptedCause() { + return this.getFiberRef(currentInterruptedCause); + } + fiberRefs() { + return this.ask((fiber) => fiber.getFiberRefs()); + } + ask(f) { + return suspend(() => { + const deferred = deferredUnsafeMake(this._fiberId); + this.tell(stateful((fiber, status) => { + deferredUnsafeDone(deferred, sync(() => f(fiber, status))); + })); + return deferredAwait(deferred); + }); } -}; -var isBigDecimal = (u) => hasProperty(u, TypeId17); -var make39 = (value, scale) => { - const o = Object.create(BigDecimalProto); - o.value = value; - o.scale = scale; - return o; -}; -var unsafeMakeNormalized = (value, scale) => { - if (value !== bigint04 && value % bigint10 === bigint04) { - throw new RangeError("Value must be normalized"); + tell(message) { + this._queue.push(message); + if (!this._running) { + this._running = true; + this.drainQueueLaterOnExecutor(); + } } - const o = make39(value, scale); - o.normalized = o; - return o; -}; -var bigint04 = /* @__PURE__ */ BigInt(0); -var bigint10 = /* @__PURE__ */ BigInt(10); -var zero2 = /* @__PURE__ */ unsafeMakeNormalized(bigint04, 0); -var normalize = (self) => { - if (self.normalized === undefined) { - if (self.value === bigint04) { - self.normalized = zero2; - } else { - const digits = `${self.value}`; - let trail = 0; - for (let i = digits.length - 1;i >= 0; i--) { - if (digits[i] === "0") { - trail++; + get await() { + return async_((resume2) => { + const cb = (exit2) => resume2(succeed(exit2)); + if (this._exitValue !== null) { + cb(this._exitValue); + return; + } + this.tell(stateful((fiber, _) => { + if (fiber._exitValue !== null) { + cb(this._exitValue); } else { - break; + fiber.addObserver(cb); } - } - if (trail === 0) { - self.normalized = self; - } - const value = BigInt(digits.substring(0, digits.length - trail)); - const scale = self.scale - trail; - self.normalized = unsafeMakeNormalized(value, scale); + })); + return sync(() => this.tell(stateful((fiber, _) => { + fiber.removeObserver(cb); + }))); + }, this.id()); + } + get inheritAll() { + return withFiberRuntime((parentFiber, parentStatus) => { + const parentFiberId = parentFiber.id(); + const parentFiberRefs = parentFiber.getFiberRefs(); + const parentRuntimeFlags = parentStatus.runtimeFlags; + const childFiberRefs = this.getFiberRefs(); + const updatedFiberRefs = joinAs(parentFiberRefs, parentFiberId, childFiberRefs); + parentFiber.setFiberRefs(updatedFiberRefs); + const updatedRuntimeFlags = parentFiber.getFiberRef(currentRuntimeFlags); + const patch9 = pipe(diff4(parentRuntimeFlags, updatedRuntimeFlags), exclude2(Interruption), exclude2(WindDown)); + return updateRuntimeFlags(patch9); + }); + } + get poll() { + return sync(() => fromNullable(this._exitValue)); + } + unsafePoll() { + return this._exitValue; + } + interruptAsFork(fiberId2) { + return sync(() => this.tell(interruptSignal(interrupt(fiberId2)))); + } + unsafeInterruptAsFork(fiberId2) { + this.tell(interruptSignal(interrupt(fiberId2))); + } + addObserver(observer) { + if (this._exitValue !== null) { + observer(this._exitValue); + } else { + this._observers.push(observer); } } - return self.normalized; -}; -var scale = /* @__PURE__ */ dual(2, (self, scale2) => { - if (scale2 > self.scale) { - return make39(self.value * bigint10 ** BigInt(scale2 - self.scale), scale2); + removeObserver(observer) { + this._observers = this._observers.filter((o) => o !== observer); } - if (scale2 < self.scale) { - return make39(self.value / bigint10 ** BigInt(self.scale - scale2), scale2); + getFiberRefs() { + this.setFiberRef(currentRuntimeFlags, this.currentRuntimeFlags); + return this._fiberRefs; } - return self; -}); -var Order4 = /* @__PURE__ */ make2((self, that) => { - const scmp = number3(sign(self), sign(that)); - if (scmp !== 0) { - return scmp; + unsafeDeleteFiberRef(fiberRef) { + this._fiberRefs = delete_(this._fiberRefs, fiberRef); } - if (self.scale > that.scale) { - return bigint(self.value, scale(that, self.scale).value); + getFiberRef(fiberRef) { + if (this._fiberRefs.locals.has(fiberRef)) { + return this._fiberRefs.locals.get(fiberRef)[0][1]; + } + return fiberRef.initial; } - if (self.scale < that.scale) { - return bigint(scale(self, that.scale).value, that.value); + setFiberRef(fiberRef, value) { + this._fiberRefs = updateAs(this._fiberRefs, { + fiberId: this._fiberId, + fiberRef, + value + }); + this.refreshRefCache(); } - return bigint(self.value, that.value); -}); -var lessThan7 = /* @__PURE__ */ lessThan(Order4); -var lessThanOrEqualTo3 = /* @__PURE__ */ lessThanOrEqualTo(Order4); -var greaterThan4 = /* @__PURE__ */ greaterThan(Order4); -var greaterThanOrEqualTo3 = /* @__PURE__ */ greaterThanOrEqualTo(Order4); -var between3 = /* @__PURE__ */ between(Order4); -var clamp5 = /* @__PURE__ */ clamp(Order4); -var sign = (n) => n.value === bigint04 ? 0 : n.value < bigint04 ? -1 : 1; -var abs = (n) => n.value < bigint04 ? make39(-n.value, n.scale) : n; -var Equivalence3 = /* @__PURE__ */ make((self, that) => { - if (self.scale > that.scale) { - return scale(that, self.scale).value === self.value; + refreshRefCache() { + this.currentDefaultServices = this.getFiberRef(currentServices); + this.currentTracer = this.currentDefaultServices.unsafeMap.get(tracerTag.key); + this.currentSupervisor = this.getFiberRef(currentSupervisor); + this.currentScheduler = this.getFiberRef(currentScheduler); + this.currentContext = this.getFiberRef(currentContext); + this.currentSpan = this.currentContext.unsafeMap.get(spanTag.key); } - if (self.scale < that.scale) { - return scale(self, that.scale).value === that.value; + setFiberRefs(fiberRefs3) { + this._fiberRefs = fiberRefs3; + this.refreshRefCache(); } - return self.value === that.value; -}); -var equals3 = /* @__PURE__ */ dual(2, (self, that) => Equivalence3(self, that)); -var unsafeFromNumber = (n) => getOrThrowWith2(safeFromNumber(n), () => new RangeError(`Number must be finite, got ${n}`)); -var safeFromNumber = (n) => { - if (!Number.isFinite(n)) { - return none2(); + addChild(child) { + this.getChildren().add(child); } - const string2 = `${n}`; - if (string2.includes("e")) { - return fromString(string2); + removeChild(child) { + this.getChildren().delete(child); } - const [lead, trail = ""] = string2.split("."); - return some2(make39(BigInt(`${lead}${trail}`), trail.length)); -}; -var fromString = (s) => { - if (s === "") { - return some2(zero2); + transferChildren(scope) { + const children = this._children; + this._children = null; + if (children !== null && children.size > 0) { + for (const child of children) { + if (child._exitValue === null) { + scope.add(this.currentRuntimeFlags, child); + } + } + } + } + drainQueueOnCurrentThread() { + let recurse = true; + while (recurse) { + let evaluationSignal = EvaluationSignalContinue; + const prev = globalThis[currentFiberURI]; + globalThis[currentFiberURI] = this; + try { + while (evaluationSignal === EvaluationSignalContinue) { + evaluationSignal = this._queue.length === 0 ? EvaluationSignalDone : this.evaluateMessageWhileSuspended(this._queue.splice(0, 1)[0]); + } + } finally { + this._running = false; + globalThis[currentFiberURI] = prev; + } + if (this._queue.length > 0 && !this._running) { + this._running = true; + if (evaluationSignal === EvaluationSignalYieldNow) { + this.drainQueueLaterOnExecutor(); + recurse = false; + } else { + recurse = true; + } + } else { + recurse = false; + } + } + } + drainQueueLaterOnExecutor() { + this.currentScheduler.scheduleTask(this.run, this.getFiberRef(currentSchedulingPriority), this); + } + drainQueueWhileRunning(runtimeFlags2, cur0) { + let cur = cur0; + while (this._queue.length > 0) { + const message = this._queue.splice(0, 1)[0]; + cur = drainQueueWhileRunningTable[message._tag](this, runtimeFlags2, cur, message); + } + return cur; + } + isInterrupted() { + return !isEmpty5(this.getFiberRef(currentInterruptedCause)); + } + addInterruptedCause(cause2) { + const oldSC = this.getFiberRef(currentInterruptedCause); + this.setFiberRef(currentInterruptedCause, sequential(oldSC, cause2)); + } + processNewInterruptSignal(cause2) { + this.addInterruptedCause(cause2); + this.sendInterruptSignalToAllChildren(); + } + sendInterruptSignalToAllChildren() { + if (this._children === null || this._children.size === 0) { + return false; + } + let told = false; + for (const child of this._children) { + child.tell(interruptSignal(interrupt(this.id()))); + told = true; + } + return told; + } + interruptAllChildren() { + if (this.sendInterruptSignalToAllChildren()) { + const it = this._children.values(); + this._children = null; + let isDone3 = false; + const body = () => { + const next = it.next(); + if (!next.done) { + return asVoid(next.value.await); + } else { + return sync(() => { + isDone3 = true; + }); + } + }; + return whileLoop({ + while: () => !isDone3, + body, + step: () => {} + }); + } + return null; + } + reportExitValue(exit2) { + if (runtimeMetrics(this.currentRuntimeFlags)) { + const tags = this.getFiberRef(currentMetricLabels); + const startTimeMillis = this.id().startTimeMillis; + const endTimeMillis = Date.now(); + fiberLifetimes.unsafeUpdate(endTimeMillis - startTimeMillis, tags); + fiberActive.unsafeUpdate(-1, tags); + switch (exit2._tag) { + case OP_SUCCESS: { + fiberSuccesses.unsafeUpdate(1, tags); + break; + } + case OP_FAILURE: { + fiberFailures.unsafeUpdate(1, tags); + break; + } + } + } + if (exit2._tag === "Failure") { + const level = this.getFiberRef(currentUnhandledErrorLogLevel); + if (!isInterruptedOnly(exit2.cause) && level._tag === "Some") { + this.log("Fiber terminated with an unhandled error", exit2.cause, level); + } + } } - let base; - let exp; - const seperator = s.search(/[eE]/); - if (seperator !== -1) { - const trail = s.slice(seperator + 1); - base = s.slice(0, seperator); - exp = Number(trail); - if (base === "" || !Number.isSafeInteger(exp) || !FINITE_INT_REGEX.test(trail)) { - return none2(); + setExitValue(exit2) { + this._exitValue = exit2; + this.reportExitValue(exit2); + for (let i = this._observers.length - 1;i >= 0; i--) { + this._observers[i](exit2); } - } else { - base = s; - exp = 0; + this._observers = []; } - let digits; - let offset; - const dot = base.search(/\./); - if (dot !== -1) { - const lead = base.slice(0, dot); - const trail = base.slice(dot + 1); - digits = `${lead}${trail}`; - offset = trail.length; - } else { - digits = base; - offset = 0; + getLoggers() { + return this.getFiberRef(currentLoggers); } - if (!FINITE_INT_REGEX.test(digits)) { - return none2(); + log(message, cause2, overrideLogLevel) { + const logLevel = isSome2(overrideLogLevel) ? overrideLogLevel.value : this.getFiberRef(currentLogLevel); + const minimumLogLevel = this.getFiberRef(currentMinimumLogLevel); + if (greaterThan4(minimumLogLevel, logLevel)) { + return; + } + const spans = this.getFiberRef(currentLogSpan); + const annotations2 = this.getFiberRef(currentLogAnnotations); + const loggers = this.getLoggers(); + const contextMap = this.getFiberRefs(); + if (size3(loggers) > 0) { + const clockService = get3(this.getFiberRef(currentServices), clockTag); + const date = new Date(clockService.unsafeCurrentTimeMillis()); + withRedactableContext(contextMap, () => { + for (const logger of loggers) { + logger.log({ + fiberId: this.id(), + logLevel, + message, + cause: cause2, + context: contextMap, + spans, + annotations: annotations2, + date + }); + } + }); + } } - const scale2 = offset - exp; - if (!Number.isSafeInteger(scale2)) { - return none2(); + evaluateMessageWhileSuspended(message) { + switch (message._tag) { + case OP_YIELD_NOW: { + return EvaluationSignalYieldNow; + } + case OP_INTERRUPT_SIGNAL: { + this.processNewInterruptSignal(message.cause); + if (this._asyncInterruptor !== null) { + this._asyncInterruptor(exitFailCause(message.cause)); + this._asyncInterruptor = null; + } + return EvaluationSignalContinue; + } + case OP_RESUME: { + this._asyncInterruptor = null; + this._asyncBlockingOn = null; + this.evaluateEffect(message.effect); + return EvaluationSignalContinue; + } + case OP_STATEFUL: { + message.onFiber(this, this._exitValue !== null ? done4 : suspended2(this.currentRuntimeFlags, this._asyncBlockingOn)); + return EvaluationSignalContinue; + } + default: { + return absurd(message); + } + } } - return some2(make39(BigInt(digits), scale2)); -}; -var format4 = (n) => { - const normalized = normalize(n); - if (Math.abs(normalized.scale) >= 16) { - return toExponential(normalized); + evaluateEffect(effect0) { + this.currentSupervisor.onResume(this); + try { + let effect = interruptible(this.currentRuntimeFlags) && this.isInterrupted() ? exitFailCause(this.getInterruptedCause()) : effect0; + while (effect !== null) { + const eff = effect; + const exit2 = this.runLoop(eff); + if (exit2 === YieldedOp) { + const op = yieldedOpChannel.currentOp; + yieldedOpChannel.currentOp = null; + if (op._op === OP_YIELD) { + if (cooperativeYielding(this.currentRuntimeFlags)) { + this.tell(yieldNow3()); + this.tell(resume(exitVoid)); + effect = null; + } else { + effect = exitVoid; + } + } else if (op._op === OP_ASYNC) { + effect = null; + } + } else { + this.currentRuntimeFlags = pipe(this.currentRuntimeFlags, enable2(WindDown)); + const interruption2 = this.interruptAllChildren(); + if (interruption2 !== null) { + effect = flatMap7(interruption2, () => exit2); + } else { + if (this._queue.length === 0) { + this.setExitValue(exit2); + } else { + this.tell(resume(exit2)); + } + effect = null; + } + } + } + } finally { + this.currentSupervisor.onSuspend(this); + } } - const negative = normalized.value < bigint04; - const absolute = negative ? `${normalized.value}`.substring(1) : `${normalized.value}`; - let before2; - let after3; - if (normalized.scale >= absolute.length) { - before2 = "0"; - after3 = "0".repeat(normalized.scale - absolute.length) + absolute; - } else { - const location = absolute.length - normalized.scale; - if (location > absolute.length) { - const zeros = location - absolute.length; - before2 = `${absolute}${"0".repeat(zeros)}`; - after3 = ""; + start(effect) { + if (!this._running) { + this._running = true; + const prev = globalThis[currentFiberURI]; + globalThis[currentFiberURI] = this; + try { + this.evaluateEffect(effect); + } finally { + this._running = false; + globalThis[currentFiberURI] = prev; + if (this._queue.length > 0) { + this.drainQueueLaterOnExecutor(); + } + } } else { - after3 = absolute.slice(location); - before2 = absolute.slice(0, location); + this.tell(resume(effect)); } } - const complete3 = after3 === "" ? before2 : `${before2}.${after3}`; - return negative ? `-${complete3}` : complete3; -}; -var toExponential = (n) => { - if (isZero2(n)) { - return "0e+0"; - } - const normalized = normalize(n); - const digits = `${abs(normalized).value}`; - const head5 = digits.slice(0, 1); - const tail = digits.slice(1); - let output = `${isNegative(normalized) ? "-" : ""}${head5}`; - if (tail !== "") { - output += `.${tail}`; - } - const exp = tail.length - normalized.scale; - return `${output}e${exp >= 0 ? "+" : ""}${exp}`; -}; -var unsafeToNumber = (n) => Number(format4(n)); -var isZero2 = (n) => n.value === bigint04; -var isNegative = (n) => n.value < bigint04; -var isPositive = (n) => n.value > bigint04; - -// node_modules/effect/dist/esm/BigInt.js -var Order5 = bigint; -var clamp6 = /* @__PURE__ */ clamp(Order5); -var toNumber = (b) => { - if (b > BigInt(Number.MAX_SAFE_INTEGER) || b < BigInt(Number.MIN_SAFE_INTEGER)) { - return none2(); + startFork(effect) { + this.tell(resume(effect)); } - return some2(Number(b)); -}; -var fromString2 = (s) => { - try { - return s.trim() === "" ? none2() : some2(BigInt(s)); - } catch { - return none2(); + patchRuntimeFlags(oldRuntimeFlags, patch9) { + const newRuntimeFlags = patch4(oldRuntimeFlags, patch9); + globalThis[currentFiberURI] = this; + this.currentRuntimeFlags = newRuntimeFlags; + return newRuntimeFlags; } -}; -var fromNumber = (n) => { - if (n > Number.MAX_SAFE_INTEGER || n < Number.MIN_SAFE_INTEGER) { - return none2(); + initiateAsync(runtimeFlags2, asyncRegister) { + let alreadyCalled = false; + const callback = (effect) => { + if (!alreadyCalled) { + alreadyCalled = true; + this.tell(resume(effect)); + } + }; + if (interruptible(runtimeFlags2)) { + this._asyncInterruptor = callback; + } + try { + asyncRegister(callback); + } catch (e) { + callback(failCause(die(e))); + } } - try { - return some2(BigInt(n)); - } catch { - return none2(); + pushStack(cont) { + this._stack.push(cont); + if (cont._op === "OnStep") { + this._steps.push({ + refs: this.getFiberRefs(), + flags: this.currentRuntimeFlags + }); + } } -}; - -// node_modules/effect/dist/esm/ConfigError.js -var InvalidData2 = InvalidData; - -// node_modules/effect/dist/esm/internal/redacted.js -var RedactedSymbolKey = "effect/Redacted"; -var redactedRegistry = /* @__PURE__ */ globalValue("effect/Redacted/redactedRegistry", () => new WeakMap); -var RedactedTypeId = /* @__PURE__ */ Symbol.for(RedactedSymbolKey); -var proto4 = { - [RedactedTypeId]: { - _A: (_) => _ - }, - pipe() { - return pipeArguments(this, arguments); - }, - toString() { - return ""; - }, - toJSON() { - return ""; - }, - [NodeInspectSymbol]() { - return ""; - }, - [symbol]() { - return pipe(hash(RedactedSymbolKey), combine(hash(redactedRegistry.get(this))), cached(this)); - }, - [symbol2](that) { - return isRedacted(that) && equals(redactedRegistry.get(this), redactedRegistry.get(that)); + popStack() { + const item = this._stack.pop(); + if (item) { + if (item._op === "OnStep") { + this._steps.pop(); + } + return item; + } + return; } -}; -var isRedacted = (u) => hasProperty(u, RedactedTypeId); -var make40 = (value) => { - const redacted = Object.create(proto4); - redactedRegistry.set(redacted, value); - return redacted; -}; -var value = (self) => { - if (redactedRegistry.has(self)) { - return redactedRegistry.get(self); - } else { - throw new Error("Unable to get redacted value"); + getNextSuccessCont() { + let frame = this.popStack(); + while (frame) { + if (frame._op !== OP_ON_FAILURE) { + return frame; + } + frame = this.popStack(); + } } -}; - -// node_modules/effect/dist/esm/internal/config.js -var ConfigSymbolKey = "effect/Config"; -var ConfigTypeId = /* @__PURE__ */ Symbol.for(ConfigSymbolKey); -var configVariance = { - _A: (_) => _ -}; -var proto5 = { - ...CommitPrototype, - [ConfigTypeId]: configVariance, - commit() { - return config(this); + getNextFailCont() { + let frame = this.popStack(); + while (frame) { + if (frame._op !== OP_ON_SUCCESS && frame._op !== OP_WHILE && frame._op !== OP_ITERATOR) { + return frame; + } + frame = this.popStack(); + } } -}; -var mapOrFail = /* @__PURE__ */ dual(2, (self, f) => { - const mapOrFail2 = Object.create(proto5); - mapOrFail2._tag = OP_MAP_OR_FAIL; - mapOrFail2.original = self; - mapOrFail2.mapOrFail = f; - return mapOrFail2; -}); -var nested2 = /* @__PURE__ */ dual(2, (self, name) => { - const nested3 = Object.create(proto5); - nested3._tag = OP_NESTED; - nested3.name = name; - nested3.config = self; - return nested3; -}); -var primitive = (description, parse2) => { - const primitive2 = Object.create(proto5); - primitive2._tag = OP_PRIMITIVE; - primitive2.description = description; - primitive2.parse = parse2; - return primitive2; -}; -var string2 = (name) => { - const config2 = primitive("a text property", right2); - return name === undefined ? config2 : nested2(config2, name); -}; - -// node_modules/effect/dist/esm/Config.js -var mapOrFail2 = mapOrFail; -var string3 = string2; - -// node_modules/effect/dist/esm/DateTime.js -var isDateTime2 = isDateTime; -var isTimeZoneOffset2 = isTimeZoneOffset; -var isTimeZoneNamed2 = isTimeZoneNamed; -var isUtc2 = isUtc; -var isZoned2 = isZoned; -var Equivalence4 = Equivalence2; -var unsafeFromDate2 = unsafeFromDate; -var unsafeMake9 = unsafeMake7; -var unsafeMakeZoned2 = unsafeMakeZoned; -var makeZonedFromString2 = makeZonedFromString; -var zoneUnsafeMakeNamed2 = zoneUnsafeMakeNamed; -var zoneMakeOffset2 = zoneMakeOffset; -var zoneFromString2 = zoneFromString; -var zoneToString2 = zoneToString; -var toDateUtc2 = toDateUtc; -var toEpochMillis2 = toEpochMillis; -var formatIso2 = formatIso; -var formatIsoZoned2 = formatIsoZoned; - -// node_modules/effect/dist/esm/internal/encoding/common.js -var DecodeExceptionTypeId = /* @__PURE__ */ Symbol.for("effect/Encoding/errors/Decode"); -var DecodeException = (input, message) => { - const out = { - _tag: "DecodeException", - [DecodeExceptionTypeId]: DecodeExceptionTypeId, - input - }; - if (isString(message)) { - out.message = message; + [OP_TAG](op) { + return sync(() => unsafeGet3(this.currentContext, op)); } - return out; -}; -var EncodeExceptionTypeId = /* @__PURE__ */ Symbol.for("effect/Encoding/errors/Encode"); -var EncodeException = (input, message) => { - const out = { - _tag: "EncodeException", - [EncodeExceptionTypeId]: EncodeExceptionTypeId, - input - }; - if (isString(message)) { - out.message = message; + ["Left"](op) { + return fail2(op.left); } - return out; -}; -var encoder = /* @__PURE__ */ new TextEncoder; -var decoder = /* @__PURE__ */ new TextDecoder; - -// node_modules/effect/dist/esm/internal/encoding/base64.js -var encode = (bytes) => { - const length2 = bytes.length; - let result = ""; - let i; - for (i = 2;i < length2; i += 3) { - result += base64abc[bytes[i - 2] >> 2]; - result += base64abc[(bytes[i - 2] & 3) << 4 | bytes[i - 1] >> 4]; - result += base64abc[(bytes[i - 1] & 15) << 2 | bytes[i] >> 6]; - result += base64abc[bytes[i] & 63]; + ["None"](_) { + return fail2(new NoSuchElementException); } - if (i === length2 + 1) { - result += base64abc[bytes[i - 2] >> 2]; - result += base64abc[(bytes[i - 2] & 3) << 4]; - result += "=="; + ["Right"](op) { + return exitSucceed(op.right); } - if (i === length2) { - result += base64abc[bytes[i - 2] >> 2]; - result += base64abc[(bytes[i - 2] & 3) << 4 | bytes[i - 1] >> 4]; - result += base64abc[(bytes[i - 1] & 15) << 2]; - result += "="; + ["Some"](op) { + return exitSucceed(op.value); } - return result; -}; -var decode2 = (str) => { - const stripped = stripCrlf(str); - const length2 = stripped.length; - if (length2 % 4 !== 0) { - return left2(DecodeException(stripped, `Length must be a multiple of 4, but is ${length2}`)); + ["Micro"](op) { + return unsafeAsync((microResume) => { + let resume2 = microResume; + const fiber = runFork(provideContext2(op, this.currentContext)); + fiber.addObserver((exit2) => { + if (exit2._tag === "Success") { + return resume2(exitSucceed(exit2.value)); + } + switch (exit2.cause._tag) { + case "Interrupt": { + return resume2(exitFailCause(interrupt(none4))); + } + case "Fail": { + return resume2(fail2(exit2.cause.error)); + } + case "Die": { + return resume2(die2(exit2.cause.defect)); + } + } + }); + return unsafeAsync((abortResume) => { + resume2 = (_) => { + abortResume(void_); + }; + fiber.unsafeInterrupt(); + }); + }); } - const index = stripped.indexOf("="); - if (index !== -1 && (index < length2 - 2 || index === length2 - 2 && stripped[length2 - 1] !== "=")) { - return left2(DecodeException(stripped, "Found a '=' character, but it is not at the end")); + [OP_SYNC](op) { + const value = internalCall(() => op.effect_instruction_i0()); + const cont = this.getNextSuccessCont(); + if (cont !== undefined) { + if (!(cont._op in contOpSuccess)) { + absurd(cont); + } + return contOpSuccess[cont._op](this, cont, value); + } else { + yieldedOpChannel.currentOp = exitSucceed(value); + return YieldedOp; + } } - try { - const missingOctets = stripped.endsWith("==") ? 2 : stripped.endsWith("=") ? 1 : 0; - const result = new Uint8Array(3 * (length2 / 4) - missingOctets); - for (let i = 0, j = 0;i < length2; i += 4, j += 3) { - const buffer = getBase64Code(stripped.charCodeAt(i)) << 18 | getBase64Code(stripped.charCodeAt(i + 1)) << 12 | getBase64Code(stripped.charCodeAt(i + 2)) << 6 | getBase64Code(stripped.charCodeAt(i + 3)); - result[j] = buffer >> 16; - result[j + 1] = buffer >> 8 & 255; - result[j + 2] = buffer & 255; + [OP_SUCCESS](op) { + const oldCur = op; + const cont = this.getNextSuccessCont(); + if (cont !== undefined) { + if (!(cont._op in contOpSuccess)) { + absurd(cont); + } + return contOpSuccess[cont._op](this, cont, oldCur.effect_instruction_i0); + } else { + yieldedOpChannel.currentOp = oldCur; + return YieldedOp; + } + } + [OP_FAILURE](op) { + const cause2 = op.effect_instruction_i0; + const cont = this.getNextFailCont(); + if (cont !== undefined) { + switch (cont._op) { + case OP_ON_FAILURE: + case OP_ON_SUCCESS_AND_FAILURE: { + if (!(interruptible(this.currentRuntimeFlags) && this.isInterrupted())) { + return internalCall(() => cont.effect_instruction_i1(cause2)); + } else { + return exitFailCause(stripFailures(cause2)); + } + } + case "OnStep": { + if (!(interruptible(this.currentRuntimeFlags) && this.isInterrupted())) { + return exitSucceed(exitFailCause(cause2)); + } else { + return exitFailCause(stripFailures(cause2)); + } + } + case OP_REVERT_FLAGS: { + this.patchRuntimeFlags(this.currentRuntimeFlags, cont.patch); + if (interruptible(this.currentRuntimeFlags) && this.isInterrupted()) { + return exitFailCause(sequential(cause2, this.getInterruptedCause())); + } else { + return exitFailCause(cause2); + } + } + default: { + absurd(cont); + } + } + } else { + yieldedOpChannel.currentOp = exitFailCause(cause2); + return YieldedOp; } - return right2(result); - } catch (e) { - return left2(DecodeException(stripped, e instanceof Error ? e.message : "Invalid input")); - } -}; -var stripCrlf = (str) => str.replace(/[\n\r]/g, ""); -function getBase64Code(charCode) { - if (charCode >= base64codes.length) { - throw new TypeError(`Invalid character ${String.fromCharCode(charCode)}`); - } - const code = base64codes[charCode]; - if (code === 255) { - throw new TypeError(`Invalid character ${String.fromCharCode(charCode)}`); - } - return code; -} -var base64abc = ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "+", "/"]; -var base64codes = [255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 62, 255, 255, 255, 63, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 255, 255, 255, 0, 255, 255, 255, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 255, 255, 255, 255, 255, 255, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51]; - -// node_modules/effect/dist/esm/internal/encoding/base64Url.js -var encode2 = (data) => encode(data).replace(/=/g, "").replace(/\+/g, "-").replace(/\//g, "_"); -var decode3 = (str) => { - const stripped = stripCrlf(str); - const length2 = stripped.length; - if (length2 % 4 === 1) { - return left2(DecodeException(stripped, `Length should be a multiple of 4, but is ${length2}`)); - } - if (!/^[-_A-Z0-9]*?={0,2}$/i.test(stripped)) { - return left2(DecodeException(stripped, "Invalid input")); - } - let sanitized = length2 % 4 === 2 ? `${stripped}==` : length2 % 4 === 3 ? `${stripped}=` : stripped; - sanitized = sanitized.replace(/-/g, "+").replace(/_/g, "/"); - return decode2(sanitized); -}; - -// node_modules/effect/dist/esm/internal/encoding/hex.js -var encode3 = (bytes) => { - let result = ""; - for (let i = 0;i < bytes.length; ++i) { - result += bytesToHex[bytes[i]]; } - return result; -}; -var decode4 = (str) => { - const bytes = new TextEncoder().encode(str); - if (bytes.length % 2 !== 0) { - return left2(DecodeException(str, `Length must be a multiple of 2, but is ${bytes.length}`)); + [OP_WITH_RUNTIME](op) { + return internalCall(() => op.effect_instruction_i0(this, running2(this.currentRuntimeFlags))); } - try { - const length2 = bytes.length / 2; - const result = new Uint8Array(length2); - for (let i = 0;i < length2; i++) { - const a = fromHexChar(bytes[i * 2]); - const b = fromHexChar(bytes[i * 2 + 1]); - result[i] = a << 4 | b; + ["Blocked"](op) { + const refs = this.getFiberRefs(); + const flags = this.currentRuntimeFlags; + if (this._steps.length > 0) { + const frames = []; + const snap = this._steps[this._steps.length - 1]; + let frame = this.popStack(); + while (frame && frame._op !== "OnStep") { + frames.push(frame); + frame = this.popStack(); + } + this.setFiberRefs(snap.refs); + this.currentRuntimeFlags = snap.flags; + const patchRefs = diff6(snap.refs, refs); + const patchFlags = diff4(snap.flags, flags); + return exitSucceed(blocked(op.effect_instruction_i0, withFiberRuntime((newFiber) => { + while (frames.length > 0) { + newFiber.pushStack(frames.pop()); + } + newFiber.setFiberRefs(patch7(newFiber.id(), newFiber.getFiberRefs())(patchRefs)); + newFiber.currentRuntimeFlags = patch4(patchFlags)(newFiber.currentRuntimeFlags); + return op.effect_instruction_i1; + }))); } - return right2(result); - } catch (e) { - return left2(DecodeException(str, e instanceof Error ? e.message : "Invalid input")); + return uninterruptibleMask((restore) => flatMap7(forkDaemon(runRequestBlock(op.effect_instruction_i0)), () => restore(op.effect_instruction_i1))); } -}; -var bytesToHex = ["00", "01", "02", "03", "04", "05", "06", "07", "08", "09", "0a", "0b", "0c", "0d", "0e", "0f", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "1a", "1b", "1c", "1d", "1e", "1f", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "2a", "2b", "2c", "2d", "2e", "2f", "30", "31", "32", "33", "34", "35", "36", "37", "38", "39", "3a", "3b", "3c", "3d", "3e", "3f", "40", "41", "42", "43", "44", "45", "46", "47", "48", "49", "4a", "4b", "4c", "4d", "4e", "4f", "50", "51", "52", "53", "54", "55", "56", "57", "58", "59", "5a", "5b", "5c", "5d", "5e", "5f", "60", "61", "62", "63", "64", "65", "66", "67", "68", "69", "6a", "6b", "6c", "6d", "6e", "6f", "70", "71", "72", "73", "74", "75", "76", "77", "78", "79", "7a", "7b", "7c", "7d", "7e", "7f", "80", "81", "82", "83", "84", "85", "86", "87", "88", "89", "8a", "8b", "8c", "8d", "8e", "8f", "90", "91", "92", "93", "94", "95", "96", "97", "98", "99", "9a", "9b", "9c", "9d", "9e", "9f", "a0", "a1", "a2", "a3", "a4", "a5", "a6", "a7", "a8", "a9", "aa", "ab", "ac", "ad", "ae", "af", "b0", "b1", "b2", "b3", "b4", "b5", "b6", "b7", "b8", "b9", "ba", "bb", "bc", "bd", "be", "bf", "c0", "c1", "c2", "c3", "c4", "c5", "c6", "c7", "c8", "c9", "ca", "cb", "cc", "cd", "ce", "cf", "d0", "d1", "d2", "d3", "d4", "d5", "d6", "d7", "d8", "d9", "da", "db", "dc", "dd", "de", "df", "e0", "e1", "e2", "e3", "e4", "e5", "e6", "e7", "e8", "e9", "ea", "eb", "ec", "ed", "ee", "ef", "f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7", "f8", "f9", "fa", "fb", "fc", "fd", "fe", "ff"]; -var fromHexChar = (byte) => { - if (48 <= byte && byte <= 57) { - return byte - 48; + ["RunBlocked"](op) { + return runBlockedRequests(op.effect_instruction_i0); } - if (97 <= byte && byte <= 102) { - return byte - 97 + 10; + [OP_UPDATE_RUNTIME_FLAGS](op) { + const updateFlags = op.effect_instruction_i0; + const oldRuntimeFlags = this.currentRuntimeFlags; + const newRuntimeFlags = patch4(oldRuntimeFlags, updateFlags); + if (interruptible(newRuntimeFlags) && this.isInterrupted()) { + return exitFailCause(this.getInterruptedCause()); + } else { + this.patchRuntimeFlags(this.currentRuntimeFlags, updateFlags); + if (op.effect_instruction_i1) { + const revertFlags = diff4(newRuntimeFlags, oldRuntimeFlags); + this.pushStack(new RevertFlags(revertFlags, op)); + return internalCall(() => op.effect_instruction_i1(oldRuntimeFlags)); + } else { + return exitVoid; + } + } } - if (65 <= byte && byte <= 70) { - return byte - 65 + 10; + [OP_ON_SUCCESS](op) { + this.pushStack(op); + return op.effect_instruction_i0; } - throw new TypeError("Invalid input"); -}; - -// node_modules/effect/dist/esm/Encoding.js -var encodeBase64 = (input) => typeof input === "string" ? encode(encoder.encode(input)) : encode(input); -var decodeBase64 = (str) => decode2(str); -var decodeBase64String = (str) => map(decodeBase64(str), (_) => decoder.decode(_)); -var encodeBase64Url = (input) => typeof input === "string" ? encode2(encoder.encode(input)) : encode2(input); -var decodeBase64Url = (str) => decode3(str); -var decodeBase64UrlString = (str) => map(decodeBase64Url(str), (_) => decoder.decode(_)); -var encodeHex = (input) => typeof input === "string" ? encode3(encoder.encode(input)) : encode3(input); -var decodeHex = (str) => decode4(str); -var decodeHexString = (str) => map(decodeHex(str), (_) => decoder.decode(_)); -var encodeUriComponent = (str) => try_({ - try: () => encodeURIComponent(str), - catch: (e) => EncodeException2(str, e instanceof Error ? e.message : "Invalid input") -}); -var decodeUriComponent = (str) => try_({ - try: () => decodeURIComponent(str), - catch: (e) => DecodeException2(str, e instanceof Error ? e.message : "Invalid input") -}); -var DecodeException2 = DecodeException; -var EncodeException2 = EncodeException; - -// node_modules/fast-check/lib/esm/stream/StreamHelpers.js -class Nil { - [Symbol.iterator]() { - return this; + ["OnStep"](op) { + this.pushStack(op); + return op.effect_instruction_i0; } - next(value2) { - return { value: value2, done: true }; + [OP_ON_FAILURE](op) { + this.pushStack(op); + return op.effect_instruction_i0; } -} -Nil.nil = new Nil; -function nilHelper() { - return Nil.nil; -} -function* mapHelper(g, f) { - for (const v of g) { - yield f(v); + [OP_ON_SUCCESS_AND_FAILURE](op) { + this.pushStack(op); + return op.effect_instruction_i0; } -} -function* flatMapHelper(g, f) { - for (const v of g) { - yield* f(v); + [OP_ASYNC](op) { + this._asyncBlockingOn = op.effect_instruction_i1; + this.initiateAsync(this.currentRuntimeFlags, op.effect_instruction_i0); + yieldedOpChannel.currentOp = op; + return YieldedOp; } -} -function* filterHelper(g, f) { - for (const v of g) { - if (f(v)) { - yield v; - } + [OP_YIELD](op) { + this._isYielding = false; + yieldedOpChannel.currentOp = op; + return YieldedOp; } -} -function* takeNHelper(g, n) { - for (let i = 0;i < n; ++i) { - const cur = g.next(); - if (cur.done) { - break; + [OP_WHILE](op) { + const check = op.effect_instruction_i0; + const body = op.effect_instruction_i1; + if (check()) { + this.pushStack(op); + return body(); + } else { + return exitVoid; } - yield cur.value; } -} -function* takeWhileHelper(g, f) { - let cur = g.next(); - while (!cur.done && f(cur.value)) { - yield cur.value; - cur = g.next(); + [OP_ITERATOR](op) { + return contOpSuccess[OP_ITERATOR](this, op, undefined); } -} -function* joinHelper(g, others) { - for (let cur = g.next();!cur.done; cur = g.next()) { - yield cur.value; + [OP_COMMIT](op) { + return internalCall(() => op.commit()); } - for (const s of others) { - for (let cur = s.next();!cur.done; cur = s.next()) { - yield cur.value; + runLoop(effect0) { + let cur = effect0; + this.currentOpCount = 0; + while (true) { + if ((this.currentRuntimeFlags & OpSupervision) !== 0) { + this.currentSupervisor.onEffect(this, cur); + } + if (this._queue.length > 0) { + cur = this.drainQueueWhileRunning(this.currentRuntimeFlags, cur); + } + if (!this._isYielding) { + this.currentOpCount += 1; + const shouldYield = this.currentScheduler.shouldYield(this); + if (shouldYield !== false) { + this._isYielding = true; + this.currentOpCount = 0; + const oldCur = cur; + cur = flatMap7(yieldNow({ + priority: shouldYield + }), () => oldCur); + } + } + try { + cur = this.currentTracer.context(() => { + if (_version !== cur[EffectTypeId2]._V) { + const level = this.getFiberRef(currentVersionMismatchErrorLogLevel); + if (level._tag === "Some") { + const effectVersion = cur[EffectTypeId2]._V; + this.log(`Executing an Effect versioned ${effectVersion} with a Runtime of version ${getCurrentVersion()}, you may want to dedupe the effect dependencies, you can use the language service plugin to detect this at compile time: https://github.com/Effect-TS/language-service`, empty16, level); + } + } + return this[cur._op](cur); + }, this); + if (cur === YieldedOp) { + const op = yieldedOpChannel.currentOp; + if (op._op === OP_YIELD || op._op === OP_ASYNC) { + return YieldedOp; + } + yieldedOpChannel.currentOp = null; + return op._op === OP_SUCCESS || op._op === OP_FAILURE ? op : exitFailCause(die(op)); + } + } catch (e) { + if (cur !== YieldedOp && !hasProperty(cur, "_op") || !(cur._op in this)) { + cur = dieMessage(`Not a valid effect: ${toStringUnknown(cur)}`); + } else if (isInterruptedException(e)) { + cur = exitFailCause(sequential(die(e), interrupt(none4))); + } else { + cur = die2(e); + } + } } } + run = () => { + this.drainQueueOnCurrentThread(); + }; } - -// node_modules/fast-check/lib/esm/stream/Stream.js -var safeSymbolIterator = Symbol.iterator; - -class Stream { - static nil() { - return new Stream(nilHelper()); - } - static of(...elements) { - return new Stream(elements[safeSymbolIterator]()); - } - constructor(g) { - this.g = g; - } - next() { - return this.g.next(); - } - [Symbol.iterator]() { - return this.g; +var currentMinimumLogLevel = /* @__PURE__ */ globalValue("effect/FiberRef/currentMinimumLogLevel", () => fiberRefUnsafeMake(fromLiteral("Info"))); +var loggerWithConsoleLog = (self) => makeLogger((opts) => { + const services = getOrDefault2(opts.context, currentServices); + get3(services, consoleTag).unsafe.log(self.log(opts)); +}); +var defaultLogger = /* @__PURE__ */ globalValue(/* @__PURE__ */ Symbol.for("effect/Logger/defaultLogger"), () => loggerWithConsoleLog(stringLogger)); +var tracerLogger = /* @__PURE__ */ globalValue(/* @__PURE__ */ Symbol.for("effect/Logger/tracerLogger"), () => makeLogger(({ + annotations: annotations2, + cause: cause2, + context: context2, + fiberId: fiberId2, + logLevel, + message +}) => { + const span2 = filterDisablePropagation(getOption2(getOrDefault(context2, currentContext), spanTag)); + if (span2._tag === "None" || span2.value._tag === "ExternalSpan") { + return; } - map(f) { - return new Stream(mapHelper(this.g, f)); + const clockService = unsafeGet3(getOrDefault(context2, currentServices), clockTag); + const attributes = {}; + for (const [key, value] of annotations2) { + attributes[key] = value; } - flatMap(f) { - return new Stream(flatMapHelper(this.g, f)); + attributes["effect.fiberId"] = threadName2(fiberId2); + attributes["effect.logLevel"] = logLevel.label; + if (cause2 !== null && cause2._tag !== "Empty") { + attributes["effect.cause"] = pretty(cause2, { + renderErrorCause: true + }); } - dropWhile(f) { - let foundEligible = false; - function* helper(v) { - if (foundEligible || !f(v)) { - foundEligible = true; - yield v; - } - } - return this.flatMap(helper); + span2.value.event(toStringUnknown(Array.isArray(message) && message.length === 1 ? message[0] : message), clockService.unsafeCurrentTimeNanos(), attributes); +})); +var currentLoggers = /* @__PURE__ */ globalValue(/* @__PURE__ */ Symbol.for("effect/FiberRef/currentLoggers"), () => fiberRefUnsafeMakeHashSet(make11(defaultLogger, tracerLogger))); +var annotateLogsScoped = function() { + if (typeof arguments[0] === "string") { + return fiberRefLocallyScopedWith(currentLogAnnotations, set3(arguments[0], arguments[1])); } - drop(n) { - if (n <= 0) { - return this; + const entries2 = Object.entries(arguments[0]); + return fiberRefLocallyScopedWith(currentLogAnnotations, mutate3((annotations2) => { + for (let i = 0;i < entries2.length; i++) { + const [key, value] = entries2[i]; + set3(annotations2, key, value); } - let idx = 0; - function helper() { - return idx++ < n; + return annotations2; + })); +}; +var whenLogLevel = /* @__PURE__ */ dual(2, (effect, level) => { + const requiredLogLevel = typeof level === "string" ? fromLiteral(level) : level; + return withFiberRuntime((fiberState) => { + const minimumLogLevel = fiberState.getFiberRef(currentMinimumLogLevel); + if (greaterThan4(minimumLogLevel, requiredLogLevel)) { + return succeed(none2()); } - return this.dropWhile(helper); - } - takeWhile(f) { - return new Stream(takeWhileHelper(this.g, f)); - } - take(n) { - return new Stream(takeNHelper(this.g, n)); + return map9(effect, some2); + }); +}); +var acquireRelease = /* @__PURE__ */ dual((args2) => isEffect(args2[0]), (acquire, release) => uninterruptible(tap(acquire, (a) => addFinalizer((exit2) => release(a, exit2))))); +var acquireReleaseInterruptible = /* @__PURE__ */ dual((args2) => isEffect(args2[0]), (acquire, release) => ensuring(acquire, addFinalizer((exit2) => release(exit2)))); +var addFinalizer = (finalizer) => withFiberRuntime((runtime3) => { + const acquireRefs = runtime3.getFiberRefs(); + const acquireFlags = disable2(runtime3.currentRuntimeFlags, Interruption); + return flatMap7(scope, (scope) => scopeAddFinalizerExit(scope, (exit2) => withFiberRuntime((runtimeFinalizer) => { + const preRefs = runtimeFinalizer.getFiberRefs(); + const preFlags = runtimeFinalizer.currentRuntimeFlags; + const patchRefs = diff6(preRefs, acquireRefs); + const patchFlags = diff4(preFlags, acquireFlags); + const inverseRefs = diff6(acquireRefs, preRefs); + runtimeFinalizer.setFiberRefs(patch7(patchRefs, runtimeFinalizer.id(), acquireRefs)); + return ensuring(withRuntimeFlags(finalizer(exit2), patchFlags), sync(() => { + runtimeFinalizer.setFiberRefs(patch7(inverseRefs, runtimeFinalizer.id(), runtimeFinalizer.getFiberRefs())); + })); + }))); +}); +var daemonChildren = (self) => { + const forkScope = fiberRefLocally(currentForkScopeOverride, some2(globalScope)); + return forkScope(self); +}; +var _existsParFound = /* @__PURE__ */ Symbol.for("effect/Effect/existsPar/found"); +var exists2 = /* @__PURE__ */ dual((args2) => isIterable(args2[0]) && !isEffect(args2[0]), (elements, predicate, options) => matchSimple(options?.concurrency, () => suspend(() => existsLoop(elements[Symbol.iterator](), 0, predicate)), () => matchEffect(forEach6(elements, (a, i) => if_(predicate(a, i), { + onTrue: () => fail2(_existsParFound), + onFalse: () => void_ +}), options), { + onFailure: (e) => e === _existsParFound ? succeed(true) : fail2(e), + onSuccess: () => succeed(false) +}))); +var existsLoop = (iterator, index, f) => { + const next = iterator.next(); + if (next.done) { + return succeed(false); } - filter(f) { - return new Stream(filterHelper(this.g, f)); + return flatMap7(f(next.value, index), (b) => b ? succeed(b) : existsLoop(iterator, index + 1, f)); +}; +var filter5 = /* @__PURE__ */ dual((args2) => isIterable(args2[0]) && !isEffect(args2[0]), (elements, predicate, options) => { + const predicate_ = options?.negate ? (a, i) => map9(predicate(a, i), not) : predicate; + return matchSimple(options?.concurrency, () => suspend(() => fromIterable(elements).reduceRight((effect, a, i) => zipWith2(effect, suspend(() => predicate_(a, i)), (list, b) => b ? [a, ...list] : list), sync(() => new Array))), () => map9(forEach6(elements, (a, i) => map9(predicate_(a, i), (b) => b ? some2(a) : none2()), options), getSomes)); +}); +var allResolveInput = (input) => { + if (Array.isArray(input) || isIterable(input)) { + return [input, none2()]; } - every(f) { - for (const v of this.g) { - if (!f(v)) { - return false; - } + const keys5 = Object.keys(input); + const size7 = keys5.length; + return [keys5.map((k) => input[k]), some2((values4) => { + const res = {}; + for (let i = 0;i < size7; i++) { + res[keys5[i]] = values4[i]; } - return true; + return res; + })]; +}; +var allValidate = (effects, reconcile, options) => { + const eitherEffects = []; + for (const effect of effects) { + eitherEffects.push(either2(effect)); } - has(f) { - for (const v of this.g) { - if (f(v)) { - return [true, v]; + return flatMap7(forEach6(eitherEffects, identity, { + concurrency: options?.concurrency, + batching: options?.batching, + concurrentFinalizers: options?.concurrentFinalizers + }), (eithers) => { + const none9 = none2(); + const size7 = eithers.length; + const errors = new Array(size7); + const successes = new Array(size7); + let errored = false; + for (let i = 0;i < size7; i++) { + const either3 = eithers[i]; + if (either3._tag === "Left") { + errors[i] = some2(either3.left); + errored = true; + } else { + successes[i] = either3.right; + errors[i] = none9; } } - return [false, null]; - } - join(...others) { - return new Stream(joinHelper(this.g, others)); - } - getNthOrLast(nth) { - let remaining = nth; - let last3 = null; - for (const v of this.g) { - if (remaining-- === 0) - return v; - last3 = v; - } - return last3; - } -} -function stream(g) { - return new Stream(g); -} - -// node_modules/fast-check/lib/esm/check/symbols.js -var cloneMethod = Symbol.for("fast-check/cloneMethod"); -function hasCloneMethod(instance) { - return instance !== null && (typeof instance === "object" || typeof instance === "function") && cloneMethod in instance && typeof instance[cloneMethod] === "function"; -} -function cloneIfNeeded(instance) { - return hasCloneMethod(instance) ? instance[cloneMethod]() : instance; -} - -// node_modules/fast-check/lib/esm/check/arbitrary/definition/Value.js -var safeObjectDefineProperty = Object.defineProperty; - -class Value { - constructor(value_, context4, customGetValue = undefined) { - this.value_ = value_; - this.context = context4; - this.hasToBeCloned = customGetValue !== undefined || hasCloneMethod(value_); - this.readOnce = false; - if (this.hasToBeCloned) { - safeObjectDefineProperty(this, "value", { get: customGetValue !== undefined ? customGetValue : this.getValue }); - } else { - this.value = value_; - } - } - getValue() { - if (this.hasToBeCloned) { - if (!this.readOnce) { - this.readOnce = true; - return this.value_; - } - return this.value_[cloneMethod](); + if (errored) { + return reconcile._tag === "Some" ? fail2(reconcile.value(errors)) : fail2(errors); + } else if (options?.discard) { + return void_; } - return this.value_; - } -} - -// node_modules/fast-check/lib/esm/check/arbitrary/definition/Arbitrary.js -var safeObjectAssign = Object.assign; - -class Arbitrary { - filter(refinement) { - return new FilterArbitrary(this, refinement); - } - map(mapper, unmapper) { - return new MapArbitrary(this, mapper, unmapper); - } - chain(chainer) { - return new ChainArbitrary(this, chainer); - } - noShrink() { - return new NoShrinkArbitrary(this); + return reconcile._tag === "Some" ? succeed(reconcile.value(successes)) : succeed(successes); + }); +}; +var allEither = (effects, reconcile, options) => { + const eitherEffects = []; + for (const effect of effects) { + eitherEffects.push(either2(effect)); } - noBias() { - return new NoBiasArbitrary(this); + if (options?.discard) { + return forEach6(eitherEffects, identity, { + concurrency: options?.concurrency, + batching: options?.batching, + discard: true, + concurrentFinalizers: options?.concurrentFinalizers + }); } -} - -class ChainArbitrary extends Arbitrary { - constructor(arb, chainer) { - super(); - this.arb = arb; - this.chainer = chainer; + return map9(forEach6(eitherEffects, identity, { + concurrency: options?.concurrency, + batching: options?.batching, + concurrentFinalizers: options?.concurrentFinalizers + }), (eithers) => reconcile._tag === "Some" ? reconcile.value(eithers) : eithers); +}; +var all2 = (arg, options) => { + const [effects, reconcile] = allResolveInput(arg); + if (options?.mode === "validate") { + return allValidate(effects, reconcile, options); + } else if (options?.mode === "either") { + return allEither(effects, reconcile, options); } - generate(mrng, biasFactor) { - const clonedMrng = mrng.clone(); - const src = this.arb.generate(mrng, biasFactor); - return this.valueChainer(src, mrng, clonedMrng, biasFactor); + return options?.discard !== true && reconcile._tag === "Some" ? map9(forEach6(effects, identity, options), reconcile.value) : forEach6(effects, identity, options); +}; +var allWith = (options) => (arg) => all2(arg, options); +var allSuccesses = (elements, options) => map9(all2(fromIterable(elements).map(exit), options), filterMap2((exit2) => exitIsSuccess(exit2) ? some2(exit2.effect_instruction_i0) : none2())); +var replicate = /* @__PURE__ */ dual(2, (self, n) => Array.from({ + length: n +}, () => self)); +var replicateEffect = /* @__PURE__ */ dual((args2) => isEffect(args2[0]), (self, n, options) => all2(replicate(self, n), options)); +var forEach6 = /* @__PURE__ */ dual((args2) => isIterable(args2[0]), (self, f, options) => withFiberRuntime((r) => { + const isRequestBatchingEnabled = options?.batching === true || options?.batching === "inherit" && r.getFiberRef(currentRequestBatching); + if (options?.discard) { + return match9(options.concurrency, () => finalizersMaskInternal(sequential3, options?.concurrentFinalizers)((restore) => isRequestBatchingEnabled ? forEachConcurrentDiscard(self, (a, i) => restore(f(a, i)), true, false, 1) : forEachSequentialDiscard(self, (a, i) => restore(f(a, i)))), () => finalizersMaskInternal(parallel3, options?.concurrentFinalizers)((restore) => forEachConcurrentDiscard(self, (a, i) => restore(f(a, i)), isRequestBatchingEnabled, false)), (n) => finalizersMaskInternal(parallelN2(n), options?.concurrentFinalizers)((restore) => forEachConcurrentDiscard(self, (a, i) => restore(f(a, i)), isRequestBatchingEnabled, false, n))); } - canShrinkWithoutContext(value2) { - return false; + return match9(options?.concurrency, () => finalizersMaskInternal(sequential3, options?.concurrentFinalizers)((restore) => isRequestBatchingEnabled ? forEachParN(self, 1, (a, i) => restore(f(a, i)), true) : forEachSequential(self, (a, i) => restore(f(a, i)))), () => finalizersMaskInternal(parallel3, options?.concurrentFinalizers)((restore) => forEachParUnbounded(self, (a, i) => restore(f(a, i)), isRequestBatchingEnabled)), (n) => finalizersMaskInternal(parallelN2(n), options?.concurrentFinalizers)((restore) => forEachParN(self, n, (a, i) => restore(f(a, i)), isRequestBatchingEnabled))); +})); +var forEachParUnbounded = (self, f, batching) => suspend(() => { + const as2 = fromIterable(self); + const array4 = new Array(as2.length); + const fn = (a, i) => flatMap7(f(a, i), (b) => sync(() => array4[i] = b)); + return zipRight(forEachConcurrentDiscard(as2, fn, batching, false), succeed(array4)); +}); +var forEachConcurrentDiscard = (self, f, batching, processAll, n) => uninterruptibleMask((restore) => transplant((graft) => withFiberRuntime((parent) => { + let todos = Array.from(self).reverse(); + let target = todos.length; + if (target === 0) { + return void_; } - shrink(value2, context4) { - if (this.isSafeContext(context4)) { - return (!context4.stoppedForOriginal ? this.arb.shrink(context4.originalValue, context4.originalContext).map((v) => this.valueChainer(v, context4.clonedMrng.clone(), context4.clonedMrng, context4.originalBias)) : Stream.nil()).join(context4.chainedArbitrary.shrink(value2, context4.chainedContext).map((dst) => { - const newContext = safeObjectAssign(safeObjectAssign({}, context4), { - chainedContext: dst.context, - stoppedForOriginal: true + let counter6 = 0; + let interrupted = false; + const fibersCount = n ? Math.min(todos.length, n) : todos.length; + const fibers = new Set; + const results = new Array; + const interruptAll = () => fibers.forEach((fiber) => { + fiber.currentScheduler.scheduleTask(() => { + fiber.unsafeInterruptAsFork(parent.id()); + }, 0, fiber); + }); + const startOrder = new Array; + const joinOrder = new Array; + const residual = new Array; + const collectExits = () => { + const exits = results.filter(({ + exit: exit2 + }) => exit2._tag === "Failure").sort((a, b) => a.index < b.index ? -1 : a.index === b.index ? 0 : 1).map(({ + exit: exit2 + }) => exit2); + if (exits.length === 0) { + exits.push(exitVoid); + } + return exits; + }; + const runFiber = (eff, interruptImmediately = false) => { + const runnable = uninterruptible(graft(eff)); + const fiber = unsafeForkUnstarted(runnable, parent, parent.currentRuntimeFlags, globalScope); + parent.currentScheduler.scheduleTask(() => { + if (interruptImmediately) { + fiber.unsafeInterruptAsFork(parent.id()); + } + fiber.resume(runnable); + }, 0, fiber); + return fiber; + }; + const onInterruptSignal = () => { + if (!processAll) { + target -= todos.length; + todos = []; + } + interrupted = true; + interruptAll(); + }; + const stepOrExit = batching ? step2 : exit; + const processingFiber = runFiber(async_((resume2) => { + const pushResult = (res, index) => { + if (res._op === "Blocked") { + residual.push(res); + } else { + results.push({ + index, + exit: res }); - return new Value(dst.value_, newContext); - })); + if (res._op === "Failure" && !interrupted) { + onInterruptSignal(); + } + } + }; + const next = () => { + if (todos.length > 0) { + const a = todos.pop(); + let index = counter6++; + const returnNextElement = () => { + const a2 = todos.pop(); + index = counter6++; + return flatMap7(yieldNow(), () => flatMap7(stepOrExit(restore(f(a2, index))), onRes)); + }; + const onRes = (res) => { + if (todos.length > 0) { + pushResult(res, index); + if (todos.length > 0) { + return returnNextElement(); + } + } + return succeed(res); + }; + const todo = flatMap7(stepOrExit(restore(f(a, index))), onRes); + const fiber = runFiber(todo); + startOrder.push(fiber); + fibers.add(fiber); + if (interrupted) { + fiber.currentScheduler.scheduleTask(() => { + fiber.unsafeInterruptAsFork(parent.id()); + }, 0, fiber); + } + fiber.addObserver((wrapped) => { + let exit2; + if (wrapped._op === "Failure") { + exit2 = wrapped; + } else { + exit2 = wrapped.effect_instruction_i0; + } + joinOrder.push(fiber); + fibers.delete(fiber); + pushResult(exit2, index); + if (results.length === target) { + resume2(succeed(getOrElse(exitCollectAll(collectExits(), { + parallel: true + }), () => exitVoid))); + } else if (residual.length + results.length === target) { + const exits = collectExits(); + const requests = residual.map((blocked2) => blocked2.effect_instruction_i0).reduce(par); + resume2(succeed(blocked(requests, forEachConcurrentDiscard([getOrElse(exitCollectAll(exits, { + parallel: true + }), () => exitVoid), ...residual.map((blocked2) => blocked2.effect_instruction_i1)], (i) => i, batching, true, n)))); + } else { + next(); + } + }); + } + }; + for (let i = 0;i < fibersCount; i++) { + next(); + } + })); + return asVoid(onExit(flatten5(restore(join2(processingFiber))), exitMatch({ + onFailure: (cause2) => { + onInterruptSignal(); + const target2 = residual.length + 1; + const concurrency = Math.min(typeof n === "number" ? n : residual.length, residual.length); + const toPop = Array.from(residual); + return async_((cb) => { + const exits = []; + let count = 0; + let index = 0; + const check = (index2, hitNext) => (exit2) => { + exits[index2] = exit2; + count++; + if (count === target2) { + cb(exitSucceed(exitFailCause(cause2))); + } + if (toPop.length > 0 && hitNext) { + next(); + } + }; + const next = () => { + runFiber(toPop.pop(), true).addObserver(check(index, true)); + index++; + }; + processingFiber.addObserver(check(index, false)); + index++; + for (let i = 0;i < concurrency; i++) { + next(); + } + }); + }, + onSuccess: () => forEachSequential(joinOrder, (f2) => f2.inheritAll) + }))); +}))); +var forEachParN = (self, n, f, batching) => suspend(() => { + const as2 = fromIterable(self); + const array4 = new Array(as2.length); + const fn = (a, i) => map9(f(a, i), (b) => array4[i] = b); + return zipRight(forEachConcurrentDiscard(as2, fn, batching, false, n), succeed(array4)); +}); +var fork = (self) => withFiberRuntime((state, status) => succeed(unsafeFork(self, state, status.runtimeFlags))); +var forkDaemon = (self) => forkWithScopeOverride(self, globalScope); +var forkWithErrorHandler = /* @__PURE__ */ dual(2, (self, handler) => fork(onError(self, (cause2) => { + const either3 = failureOrCause(cause2); + switch (either3._tag) { + case "Left": + return handler(either3.left); + case "Right": + return failCause(either3.right); + } +}))); +var unsafeFork = (effect, parentFiber, parentRuntimeFlags, overrideScope = null) => { + const childFiber = unsafeMakeChildFiber(effect, parentFiber, parentRuntimeFlags, overrideScope); + childFiber.resume(effect); + return childFiber; +}; +var unsafeForkUnstarted = (effect, parentFiber, parentRuntimeFlags, overrideScope = null) => { + const childFiber = unsafeMakeChildFiber(effect, parentFiber, parentRuntimeFlags, overrideScope); + return childFiber; +}; +var unsafeMakeChildFiber = (effect, parentFiber, parentRuntimeFlags, overrideScope = null) => { + const childId = unsafeMake2(); + const parentFiberRefs = parentFiber.getFiberRefs(); + const childFiberRefs = forkAs(parentFiberRefs, childId); + const childFiber = new FiberRuntime(childId, childFiberRefs, parentRuntimeFlags); + const childContext = getOrDefault(childFiberRefs, currentContext); + const supervisor = childFiber.currentSupervisor; + supervisor.onStart(childContext, effect, some2(parentFiber), childFiber); + childFiber.addObserver((exit2) => supervisor.onEnd(exit2, childFiber)); + const parentScope = overrideScope !== null ? overrideScope : pipe(parentFiber.getFiberRef(currentForkScopeOverride), getOrElse(() => parentFiber.scope())); + parentScope.add(parentRuntimeFlags, childFiber); + return childFiber; +}; +var forkWithScopeOverride = (self, scopeOverride) => withFiberRuntime((parentFiber, parentStatus) => succeed(unsafeFork(self, parentFiber, parentStatus.runtimeFlags, scopeOverride))); +var mergeAll3 = /* @__PURE__ */ dual((args2) => isFunction2(args2[2]), (elements, zero3, f, options) => matchSimple(options?.concurrency, () => fromIterable(elements).reduce((acc, a, i) => zipWith2(acc, a, (acc2, a2) => f(acc2, a2, i)), succeed(zero3)), () => flatMap7(make28(zero3), (acc) => flatMap7(forEach6(elements, (effect, i) => flatMap7(effect, (a) => update3(acc, (b) => f(b, a, i))), options), () => get12(acc))))); +var partition3 = /* @__PURE__ */ dual((args2) => isIterable(args2[0]), (elements, f, options) => pipe(forEach6(elements, (a, i) => either2(f(a, i)), options), map9((chunk2) => partitionMap2(chunk2, identity)))); +var validateAll = /* @__PURE__ */ dual((args2) => isIterable(args2[0]), (elements, f, options) => flatMap7(partition3(elements, f, { + concurrency: options?.concurrency, + batching: options?.batching, + concurrentFinalizers: options?.concurrentFinalizers +}), ([es, bs]) => isNonEmptyArray2(es) ? fail2(es) : options?.discard ? void_ : succeed(bs))); +var raceAll = (all3) => withFiberRuntime((state, status) => async_((resume2) => { + const fibers = new Set; + let winner; + let failures2 = empty16; + const interruptAll = () => { + for (const fiber of fibers) { + fiber.unsafeInterruptAsFork(state.id()); } - return Stream.nil(); - } - valueChainer(v, generateMrng, clonedMrng, biasFactor) { - const chainedArbitrary = this.chainer(v.value_); - const dst = chainedArbitrary.generate(generateMrng, biasFactor); - const context4 = { - originalBias: biasFactor, - originalValue: v.value_, - originalContext: v.context, - stoppedForOriginal: false, - chainedArbitrary, - chainedContext: dst.context, - clonedMrng - }; - return new Value(dst.value_, context4); - } - isSafeContext(context4) { - return context4 != null && typeof context4 === "object" && "originalBias" in context4 && "originalValue" in context4 && "originalContext" in context4 && "stoppedForOriginal" in context4 && "chainedArbitrary" in context4 && "chainedContext" in context4 && "clonedMrng" in context4; - } -} - -class MapArbitrary extends Arbitrary { - constructor(arb, mapper, unmapper) { - super(); - this.arb = arb; - this.mapper = mapper; - this.unmapper = unmapper; - this.bindValueMapper = (v) => this.valueMapper(v); + }; + let latch = false; + let empty26 = true; + for (const self of all3) { + empty26 = false; + const fiber = unsafeFork(interruptible2(self), state, status.runtimeFlags); + fibers.add(fiber); + fiber.addObserver((exit2) => { + fibers.delete(fiber); + if (!winner) { + if (exit2._tag === "Success") { + latch = true; + winner = fiber; + failures2 = empty16; + interruptAll(); + } else { + failures2 = parallel(exit2.cause, failures2); + } + } + if (latch && fibers.size === 0) { + resume2(winner ? zipRight(inheritAll(winner), winner.unsafePoll()) : failCause(failures2)); + } + }); + if (winner) + break; } - generate(mrng, biasFactor) { - const g = this.arb.generate(mrng, biasFactor); - return this.valueMapper(g); + if (empty26) { + return resume2(dieSync(() => new IllegalArgumentException(`Received an empty collection of effects`))); } - canShrinkWithoutContext(value2) { - if (this.unmapper !== undefined) { - try { - const unmapped = this.unmapper(value2); - return this.arb.canShrinkWithoutContext(unmapped); - } catch (_err) { - return false; - } + latch = true; + return interruptAllAs(fibers, state.id()); +})); +var reduceEffect = /* @__PURE__ */ dual((args2) => isIterable(args2[0]) && !isEffect(args2[0]), (elements, zero3, f, options) => matchSimple(options?.concurrency, () => fromIterable(elements).reduce((acc, a, i) => zipWith2(acc, a, (acc2, a2) => f(acc2, a2, i)), zero3), () => suspend(() => pipe(mergeAll3([zero3, ...elements], none2(), (acc, elem, i) => { + switch (acc._tag) { + case "None": { + return some2(elem); + } + case "Some": { + return some2(f(acc.value, elem, i)); } - return false; } - shrink(value2, context4) { - if (this.isSafeContext(context4)) { - return this.arb.shrink(context4.originalValue, context4.originalContext).map(this.bindValueMapper); +}, options), map9((option2) => { + switch (option2._tag) { + case "None": { + throw new Error("BUG: Effect.reduceEffect - please report an issue at https://github.com/Effect-TS/effect/issues"); } - if (this.unmapper !== undefined) { - const unmapped = this.unmapper(value2); - return this.arb.shrink(unmapped, undefined).map(this.bindValueMapper); + case "Some": { + return option2.value; } - return Stream.nil(); } - mapperWithCloneIfNeeded(v) { - const sourceValue = v.value; - const mappedValue = this.mapper(sourceValue); - if (v.hasToBeCloned && (typeof mappedValue === "object" && mappedValue !== null || typeof mappedValue === "function") && Object.isExtensible(mappedValue) && !hasCloneMethod(mappedValue)) { - Object.defineProperty(mappedValue, cloneMethod, { get: () => () => this.mapperWithCloneIfNeeded(v)[0] }); +}))))); +var parallelFinalizers = (self) => contextWithEffect((context2) => match2(getOption2(context2, scopeTag), { + onNone: () => self, + onSome: (scope) => { + switch (scope.strategy._tag) { + case "Parallel": + return self; + case "Sequential": + case "ParallelN": + return flatMap7(scopeFork(scope, parallel3), (inner) => scopeExtend(self, inner)); } - return [mappedValue, sourceValue]; - } - valueMapper(v) { - const [mappedValue, sourceValue] = this.mapperWithCloneIfNeeded(v); - const context4 = { originalValue: sourceValue, originalContext: v.context }; - return new Value(mappedValue, context4); } - isSafeContext(context4) { - return context4 != null && typeof context4 === "object" && "originalValue" in context4 && "originalContext" in context4; - } -} - -class FilterArbitrary extends Arbitrary { - constructor(arb, refinement) { - super(); - this.arb = arb; - this.refinement = refinement; - this.bindRefinementOnValue = (v) => this.refinementOnValue(v); +})); +var parallelNFinalizers = (parallelism) => (self) => contextWithEffect((context2) => match2(getOption2(context2, scopeTag), { + onNone: () => self, + onSome: (scope) => { + if (scope.strategy._tag === "ParallelN" && scope.strategy.parallelism === parallelism) { + return self; + } + return flatMap7(scopeFork(scope, parallelN2(parallelism)), (inner) => scopeExtend(self, inner)); } - generate(mrng, biasFactor) { - while (true) { - const g = this.arb.generate(mrng, biasFactor); - if (this.refinementOnValue(g)) { - return g; +})); +var finalizersMask = (strategy) => (self) => finalizersMaskInternal(strategy, true)(self); +var finalizersMaskInternal = (strategy, concurrentFinalizers) => (self) => contextWithEffect((context2) => match2(getOption2(context2, scopeTag), { + onNone: () => self(identity), + onSome: (scope) => { + if (concurrentFinalizers === true) { + const patch9 = strategy._tag === "Parallel" ? parallelFinalizers : strategy._tag === "Sequential" ? sequentialFinalizers : parallelNFinalizers(strategy.parallelism); + switch (scope.strategy._tag) { + case "Parallel": + return patch9(self(parallelFinalizers)); + case "Sequential": + return patch9(self(sequentialFinalizers)); + case "ParallelN": + return patch9(self(parallelNFinalizers(scope.strategy.parallelism))); } + } else { + return self(identity); } } - canShrinkWithoutContext(value2) { - return this.arb.canShrinkWithoutContext(value2) && this.refinement(value2); - } - shrink(value2, context4) { - return this.arb.shrink(value2, context4).filter(this.bindRefinementOnValue); - } - refinementOnValue(v) { - return this.refinement(v.value); - } -} - -class NoShrinkArbitrary extends Arbitrary { - constructor(arb) { - super(); - this.arb = arb; - } - generate(mrng, biasFactor) { - return this.arb.generate(mrng, biasFactor); - } - canShrinkWithoutContext(value2) { - return this.arb.canShrinkWithoutContext(value2); - } - shrink(_value, _context) { - return Stream.nil(); - } - noShrink() { - return this; - } -} - -class NoBiasArbitrary extends Arbitrary { - constructor(arb) { - super(); - this.arb = arb; - } - generate(mrng, _biasFactor) { - return this.arb.generate(mrng, undefined); - } - canShrinkWithoutContext(value2) { - return this.arb.canShrinkWithoutContext(value2); - } - shrink(value2, context4) { - return this.arb.shrink(value2, context4); - } - noBias() { - return this; - } -} - -// node_modules/fast-check/lib/esm/utils/apply.js -var untouchedApply = Function.prototype.apply; -var ApplySymbol = Symbol("apply"); -function safeExtractApply(f) { - try { - return f.apply; - } catch (err) { - return; - } -} -function safeApplyHacky(f, instance, args2) { - const ff = f; - ff[ApplySymbol] = untouchedApply; - const out = ff[ApplySymbol](instance, args2); - delete ff[ApplySymbol]; - return out; -} -function safeApply(f, instance, args2) { - if (safeExtractApply(f) === untouchedApply) { - return f.apply(instance, args2); - } - return safeApplyHacky(f, instance, args2); -} - -// node_modules/fast-check/lib/esm/utils/globals.js -var untouchedForEach = Array.prototype.forEach; -var untouchedIndexOf = Array.prototype.indexOf; -var untouchedJoin = Array.prototype.join; -var untouchedMap = Array.prototype.map; -var untouchedFilter = Array.prototype.filter; -var untouchedPush = Array.prototype.push; -var untouchedPop = Array.prototype.pop; -var untouchedSplice = Array.prototype.splice; -var untouchedSlice = Array.prototype.slice; -var untouchedSort = Array.prototype.sort; -var untouchedEvery = Array.prototype.every; -function extractIndexOf(instance) { - try { - return instance.indexOf; - } catch (err) { - return; - } -} -function extractMap(instance) { - try { - return instance.map; - } catch (err) { - return; - } -} -function extractPush(instance) { - try { - return instance.push; - } catch (err) { - return; - } -} -function extractSlice(instance) { - try { - return instance.slice; - } catch (err) { - return; - } -} -function safeIndexOf(instance, ...args2) { - if (extractIndexOf(instance) === untouchedIndexOf) { - return instance.indexOf(...args2); - } - return safeApply(untouchedIndexOf, instance, args2); -} -function safeMap(instance, fn2) { - if (extractMap(instance) === untouchedMap) { - return instance.map(fn2); - } - return safeApply(untouchedMap, instance, [fn2]); -} -function safePush(instance, ...args2) { - if (extractPush(instance) === untouchedPush) { - return instance.push(...args2); - } - return safeApply(untouchedPush, instance, args2); -} -function safeSlice(instance, ...args2) { - if (extractSlice(instance) === untouchedSlice) { - return instance.slice(...args2); +})); +var scopeWith = (f) => flatMap7(scopeTag, f); +var scopedWith = (f) => flatMap7(scopeMake(), (scope) => onExit(f(scope), (exit2) => scope.close(exit2))); +var scopedEffect = (effect) => flatMap7(scopeMake(), (scope) => scopeUse(effect, scope)); +var sequentialFinalizers = (self) => contextWithEffect((context2) => match2(getOption2(context2, scopeTag), { + onNone: () => self, + onSome: (scope) => { + switch (scope.strategy._tag) { + case "Sequential": + return self; + case "Parallel": + case "ParallelN": + return flatMap7(scopeFork(scope, sequential3), (inner) => scopeExtend(self, inner)); + } } - return safeApply(untouchedSlice, instance, args2); -} -var untouchedGetTime = Date.prototype.getTime; -var untouchedToISOString = Date.prototype.toISOString; -var untouchedAdd = Set.prototype.add; -var untouchedHas = Set.prototype.has; -var untouchedSet = WeakMap.prototype.set; -var untouchedGet = WeakMap.prototype.get; -var untouchedMapSet = Map.prototype.set; -var untouchedMapGet = Map.prototype.get; -function extractMapSet(instance) { - try { - return instance.set; - } catch (err) { - return; +})); +var tagMetricsScoped = (key, value) => labelMetricsScoped([make29(key, value)]); +var labelMetricsScoped = (labels) => fiberRefLocallyScopedWith(currentMetricLabels, (old) => union(old, labels)); +var using = /* @__PURE__ */ dual(2, (self, use) => scopedWith((scope) => flatMap7(scopeExtend(self, scope), use))); +var validate = /* @__PURE__ */ dual((args2) => isEffect(args2[1]), (self, that, options) => validateWith(self, that, (a, b) => [a, b], options)); +var validateWith = /* @__PURE__ */ dual((args2) => isEffect(args2[1]), (self, that, f, options) => flatten5(zipWithOptions(exit(self), exit(that), (ea, eb) => exitZipWith(ea, eb, { + onSuccess: f, + onFailure: (ca, cb) => options?.concurrent ? parallel(ca, cb) : sequential(ca, cb) +}), options))); +var validateFirst = /* @__PURE__ */ dual((args2) => isIterable(args2[0]), (elements, f, options) => flip(forEach6(elements, (a, i) => flip(f(a, i)), options))); +var withClockScoped = (c) => fiberRefLocallyScopedWith(currentServices, add2(clockTag, c)); +var withRandomScoped = (value) => fiberRefLocallyScopedWith(currentServices, add2(randomTag, value)); +var withConfigProviderScoped = (provider) => fiberRefLocallyScopedWith(currentServices, add2(configProviderTag, provider)); +var withEarlyRelease = (self) => scopeWith((parent) => flatMap7(scopeFork(parent, sequential2), (child) => pipe(self, scopeExtend(child), map9((value) => [fiberIdWith((fiberId2) => scopeClose(child, exitInterrupt(fiberId2))), value])))); +var zipOptions = /* @__PURE__ */ dual((args2) => isEffect(args2[1]), (self, that, options) => zipWithOptions(self, that, (a, b) => [a, b], options)); +var zipLeftOptions = /* @__PURE__ */ dual((args2) => isEffect(args2[1]), (self, that, options) => { + if (options?.concurrent !== true && (options?.batching === undefined || options.batching === false)) { + return zipLeft(self, that); } -} -function extractMapGet(instance) { - try { - return instance.get; - } catch (err) { - return; + return zipWithOptions(self, that, (a, _) => a, options); +}); +var zipRightOptions = /* @__PURE__ */ dual((args2) => isEffect(args2[1]), (self, that, options) => { + if (options?.concurrent !== true && (options?.batching === undefined || options.batching === false)) { + return zipRight(self, that); } -} -function safeMapSet(instance, key, value2) { - if (extractMapSet(instance) === untouchedMapSet) { - return instance.set(key, value2); + return zipWithOptions(self, that, (_, b) => b, options); +}); +var zipWithOptions = /* @__PURE__ */ dual((args2) => isEffect(args2[1]), (self, that, f, options) => map9(all2([self, that], { + concurrency: options?.concurrent ? 2 : 1, + batching: options?.batching, + concurrentFinalizers: options?.concurrentFinalizers +}), ([a, a2]) => f(a, a2))); +var withRuntimeFlagsScoped = (update5) => { + if (update5 === empty14) { + return void_; } - return safeApply(untouchedMapSet, instance, [key, value2]); -} -function safeMapGet(instance, key) { - if (extractMapGet(instance) === untouchedMapGet) { - return instance.get(key); + return pipe(runtimeFlags, flatMap7((runtimeFlags2) => { + const updatedRuntimeFlags = patch4(runtimeFlags2, update5); + const revertRuntimeFlags = diff4(updatedRuntimeFlags, runtimeFlags2); + return pipe(updateRuntimeFlags(update5), zipRight(addFinalizer(() => updateRuntimeFlags(revertRuntimeFlags))), asVoid); + }), uninterruptible); +}; +var scopeTag = /* @__PURE__ */ GenericTag("effect/Scope"); +var scope = scopeTag; +var scopeUnsafeAddFinalizer = (scope2, fin) => { + if (scope2.state._tag === "Open") { + scope2.state.finalizers.set({}, fin); } - return safeApply(untouchedMapGet, instance, [key]); -} -var untouchedSplit = String.prototype.split; -var untouchedStartsWith = String.prototype.startsWith; -var untouchedEndsWith = String.prototype.endsWith; -var untouchedSubstring = String.prototype.substring; -var untouchedToLowerCase = String.prototype.toLowerCase; -var untouchedToUpperCase = String.prototype.toUpperCase; -var untouchedPadStart = String.prototype.padStart; -var untouchedCharCodeAt = String.prototype.charCodeAt; -var untouchedNormalize = String.prototype.normalize; -var untouchedReplace = String.prototype.replace; -var untouchedNumberToString = Number.prototype.toString; - -// node_modules/fast-check/lib/esm/stream/LazyIterableIterator.js -class LazyIterableIterator { - constructor(producer) { - this.producer = producer; +}; +var ScopeImplProto = { + [ScopeTypeId]: ScopeTypeId, + [CloseableScopeTypeId]: CloseableScopeTypeId, + pipe() { + return pipeArguments(this, arguments); + }, + fork(strategy) { + return sync(() => { + const newScope = scopeUnsafeMake(strategy); + if (this.state._tag === "Closed") { + newScope.state = this.state; + return newScope; + } + const key = {}; + const fin = (exit2) => newScope.close(exit2); + this.state.finalizers.set(key, fin); + scopeUnsafeAddFinalizer(newScope, (_) => sync(() => { + if (this.state._tag === "Open") { + this.state.finalizers.delete(key); + } + })); + return newScope; + }); + }, + close(exit2) { + return suspend(() => { + if (this.state._tag === "Closed") { + return void_; + } + const finalizers = Array.from(this.state.finalizers.values()).reverse(); + this.state = { + _tag: "Closed", + exit: exit2 + }; + if (finalizers.length === 0) { + return void_; + } + return isSequential(this.strategy) ? pipe(forEachSequential(finalizers, (fin) => exit(fin(exit2))), flatMap7((results) => pipe(exitCollectAll(results), map2(exitAsVoid), getOrElse(() => exitVoid)))) : isParallel(this.strategy) ? pipe(forEachParUnbounded(finalizers, (fin) => exit(fin(exit2)), false), flatMap7((results) => pipe(exitCollectAll(results, { + parallel: true + }), map2(exitAsVoid), getOrElse(() => exitVoid)))) : pipe(forEachParN(finalizers, this.strategy.parallelism, (fin) => exit(fin(exit2)), false), flatMap7((results) => pipe(exitCollectAll(results, { + parallel: true + }), map2(exitAsVoid), getOrElse(() => exitVoid)))); + }); + }, + addFinalizer(fin) { + return suspend(() => { + if (this.state._tag === "Closed") { + return fin(this.state.exit); + } + this.state.finalizers.set({}, fin); + return void_; + }); } - [Symbol.iterator]() { - if (this.it === undefined) { - this.it = this.producer(); +}; +var scopeUnsafeMake = (strategy = sequential2) => { + const scope2 = Object.create(ScopeImplProto); + scope2.strategy = strategy; + scope2.state = { + _tag: "Open", + finalizers: new Map + }; + return scope2; +}; +var scopeMake = (strategy = sequential2) => sync(() => scopeUnsafeMake(strategy)); +var scopeExtend = /* @__PURE__ */ dual(2, (effect, scope2) => mapInputContext(effect, merge3(make6(scopeTag, scope2)))); +var scopeUse = /* @__PURE__ */ dual(2, (effect, scope2) => pipe(effect, scopeExtend(scope2), onExit((exit2) => scope2.close(exit2)))); +var fiberRefUnsafeMakeSupervisor = (initial) => fiberRefUnsafeMakePatch(initial, { + differ: differ2, + fork: empty25 +}); +var fiberRefLocallyScoped = /* @__PURE__ */ dual(2, (self, value) => asVoid(acquireRelease(flatMap7(fiberRefGet(self), (oldValue) => as(fiberRefSet(self, value), oldValue)), (oldValue) => fiberRefSet(self, oldValue)))); +var fiberRefLocallyScopedWith = /* @__PURE__ */ dual(2, (self, f) => fiberRefGetWith(self, (a) => fiberRefLocallyScoped(self, f(a)))); +var currentRuntimeFlags = /* @__PURE__ */ fiberRefUnsafeMakeRuntimeFlags(none5); +var currentSupervisor = /* @__PURE__ */ fiberRefUnsafeMakeSupervisor(none8); +var fiberAwaitAll = (fibers) => forEach6(fibers, _await2); +var fiberAll = (fibers) => { + const _fiberAll = { + ...CommitPrototype2, + commit() { + return join2(this); + }, + [FiberTypeId]: fiberVariance2, + id: () => fromIterable(fibers).reduce((id, fiber) => combine3(id, fiber.id()), none4), + await: exit(forEachParUnbounded(fibers, (fiber) => flatten5(fiber.await), false)), + children: map9(forEachParUnbounded(fibers, (fiber) => fiber.children, false), flatten), + inheritAll: forEachSequentialDiscard(fibers, (fiber) => fiber.inheritAll), + poll: map9(forEachSequential(fibers, (fiber) => fiber.poll), reduceRight(some2(exitSucceed(new Array)), (optionB, optionA) => { + switch (optionA._tag) { + case "None": { + return none2(); + } + case "Some": { + switch (optionB._tag) { + case "None": { + return none2(); + } + case "Some": { + return some2(exitZipWith(optionA.value, optionB.value, { + onSuccess: (a, chunk2) => [a, ...chunk2], + onFailure: parallel + })); + } + } + } + } + })), + interruptAsFork: (fiberId2) => forEachSequentialDiscard(fibers, (fiber) => fiber.interruptAsFork(fiberId2)) + }; + return _fiberAll; +}; +var raceWith = /* @__PURE__ */ dual(3, (self, other, options) => raceFibersWith(self, other, { + onSelfWin: (winner, loser) => flatMap7(winner.await, (exit2) => { + switch (exit2._tag) { + case OP_SUCCESS: { + return flatMap7(winner.inheritAll, () => options.onSelfDone(exit2, loser)); + } + case OP_FAILURE: { + return options.onSelfDone(exit2, loser); + } + } + }), + onOtherWin: (winner, loser) => flatMap7(winner.await, (exit2) => { + switch (exit2._tag) { + case OP_SUCCESS: { + return flatMap7(winner.inheritAll, () => options.onOtherDone(exit2, loser)); + } + case OP_FAILURE: { + return options.onOtherDone(exit2, loser); + } + } + }) +})); +var disconnect = (self) => uninterruptibleMask((restore) => fiberIdWith((fiberId2) => flatMap7(forkDaemon(restore(self)), (fiber) => pipe(restore(join2(fiber)), onInterrupt(() => pipe(fiber, interruptAsFork(fiberId2))))))); +var race = /* @__PURE__ */ dual(2, (self, that) => fiberIdWith((parentFiberId) => raceWith(self, that, { + onSelfDone: (exit2, right3) => exitMatchEffect(exit2, { + onFailure: (cause2) => pipe(join2(right3), mapErrorCause((cause22) => parallel(cause2, cause22))), + onSuccess: (value) => pipe(right3, interruptAsFiber(parentFiberId), as(value)) + }), + onOtherDone: (exit2, left3) => exitMatchEffect(exit2, { + onFailure: (cause2) => pipe(join2(left3), mapErrorCause((cause22) => parallel(cause22, cause2))), + onSuccess: (value) => pipe(left3, interruptAsFiber(parentFiberId), as(value)) + }) +}))); +var raceFibersWith = /* @__PURE__ */ dual(3, (self, other, options) => withFiberRuntime((parentFiber, parentStatus) => { + const parentRuntimeFlags = parentStatus.runtimeFlags; + const raceIndicator = make12(true); + const leftFiber = unsafeMakeChildFiber(self, parentFiber, parentRuntimeFlags, options.selfScope); + const rightFiber = unsafeMakeChildFiber(other, parentFiber, parentRuntimeFlags, options.otherScope); + return async_((cb) => { + leftFiber.addObserver(() => completeRace(leftFiber, rightFiber, options.onSelfWin, raceIndicator, cb)); + rightFiber.addObserver(() => completeRace(rightFiber, leftFiber, options.onOtherWin, raceIndicator, cb)); + leftFiber.startFork(self); + rightFiber.startFork(other); + }, combine3(leftFiber.id(), rightFiber.id())); +})); +var completeRace = (winner, loser, cont, ab, cb) => { + if (compareAndSet(true, false)(ab)) { + cb(cont(winner, loser)); + } +}; +var ensuring = /* @__PURE__ */ dual(2, (self, finalizer) => uninterruptibleMask((restore) => matchCauseEffect(restore(self), { + onFailure: (cause1) => matchCauseEffect(finalizer, { + onFailure: (cause2) => failCause(sequential(cause1, cause2)), + onSuccess: () => failCause(cause1) + }), + onSuccess: (a) => as(finalizer, a) +}))); +var invokeWithInterrupt = (self, entries2, onInterrupt2) => fiberIdWith((id) => ensuring(flatMap7(forkDaemon(interruptible2(self)), (processing) => async_((cb) => { + const counts = entries2.map((_) => _.listeners.count); + const checkDone = () => { + if (counts.every((count) => count === 0)) { + if (entries2.every((_) => { + if (_.result.state.current._tag === "Pending") { + return true; + } else if (_.result.state.current._tag === "Done" && exitIsExit(_.result.state.current.effect) && _.result.state.current.effect._tag === "Failure" && isInterrupted(_.result.state.current.effect.cause)) { + return true; + } else { + return false; + } + })) { + cleanup.forEach((f) => f()); + onInterrupt2?.(); + cb(interruptFiber(processing)); + } } - return this.it; - } - next() { - if (this.it === undefined) { - this.it = this.producer(); + }; + processing.addObserver((exit2) => { + cleanup.forEach((f) => f()); + cb(exit2); + }); + const cleanup = entries2.map((r, i) => { + const observer = (count) => { + counts[i] = count; + checkDone(); + }; + r.listeners.addObserver(observer); + return () => r.listeners.removeObserver(observer); + }); + checkDone(); + return sync(() => { + cleanup.forEach((f) => f()); + }); +})), suspend(() => { + const residual = entries2.flatMap((entry) => { + if (!entry.state.completed) { + return [entry]; } - return this.it.next(); + return []; + }); + return forEachSequentialDiscard(residual, (entry) => complete(entry.request, exitInterrupt(id))); +}))); +var makeSpanScoped = (name, options) => { + options = addSpanStackTrace(options); + return uninterruptible(withFiberRuntime((fiber) => { + const scope2 = unsafeGet3(fiber.getFiberRef(currentContext), scopeTag); + const span2 = unsafeMakeSpan(fiber, name, options); + const timingEnabled = fiber.getFiberRef(currentTracerTimingEnabled); + const clock_ = get3(fiber.getFiberRef(currentServices), clockTag); + return as(scopeAddFinalizerExit(scope2, (exit2) => endSpan(span2, exit2, clock_, timingEnabled)), span2); + })); +}; +var withTracerScoped = (value) => fiberRefLocallyScopedWith(currentServices, add2(tracerTag, value)); +var withSpanScoped = function() { + const dataFirst = typeof arguments[0] !== "string"; + const name = dataFirst ? arguments[1] : arguments[0]; + const options = addSpanStackTrace(dataFirst ? arguments[2] : arguments[1]); + if (dataFirst) { + const self = arguments[0]; + return flatMap7(makeSpanScoped(name, addSpanStackTrace(options)), (span2) => provideService(self, spanTag, span2)); } -} -function makeLazy(producer) { - return new LazyIterableIterator(producer); -} + return (self) => flatMap7(makeSpanScoped(name, addSpanStackTrace(options)), (span2) => provideService(self, spanTag, span2)); +}; -// node_modules/fast-check/lib/esm/check/runner/configuration/GlobalParameters.js -var globalParameters = {}; -function readConfigureGlobal() { - return globalParameters; -} +// node_modules/effect/dist/esm/internal/cache.js +var complete2 = (key, exit2, entryStats, timeToLiveMillis) => struct({ + _tag: "Complete", + key, + exit: exit2, + entryStats, + timeToLiveMillis +}); +var pending2 = (key, deferred) => struct({ + _tag: "Pending", + key, + deferred +}); +var refreshing = (deferred, complete3) => struct({ + _tag: "Refreshing", + deferred, + complete: complete3 +}); +var MapKeyTypeId = /* @__PURE__ */ Symbol.for("effect/Cache/MapKey"); -// node_modules/fast-check/lib/esm/arbitrary/_internals/helpers/BiasNumericRange.js -var safeMathFloor = Math.floor; -var safeMathLog = Math.log; -function integerLogLike(v) { - return safeMathFloor(safeMathLog(v) / safeMathLog(2)); -} -function biasNumericRange(min4, max6, logLike) { - if (min4 === max6) { - return [{ min: min4, max: max6 }]; - } - if (min4 < 0 && max6 > 0) { - const logMin = logLike(-min4); - const logMax = logLike(max6); - return [ - { min: -logMin, max: logMax }, - { min: max6 - logMax, max: max6 }, - { min: min4, max: min4 + logMin } - ]; +class MapKeyImpl { + current; + [MapKeyTypeId] = MapKeyTypeId; + previous = undefined; + next = undefined; + constructor(current) { + this.current = current; } - const logGap = logLike(max6 - min4); - const arbCloseToMin = { min: min4, max: min4 + logGap }; - const arbCloseToMax = { min: max6 - logGap, max: max6 }; - return min4 < 0 ? [arbCloseToMax, arbCloseToMin] : [arbCloseToMin, arbCloseToMax]; -} - -// node_modules/fast-check/lib/esm/arbitrary/_internals/helpers/ShrinkInteger.js -var safeMathCeil = Math.ceil; -var safeMathFloor2 = Math.floor; -function halvePosInteger(n) { - return safeMathFloor2(n / 2); -} -function halveNegInteger(n) { - return safeMathCeil(n / 2); -} -function shrinkInteger(current, target, tryTargetAsap) { - const realGap = current - target; - function* shrinkDecr() { - let previous = tryTargetAsap ? undefined : target; - const gap = tryTargetAsap ? realGap : halvePosInteger(realGap); - for (let toremove = gap;toremove > 0; toremove = halvePosInteger(toremove)) { - const next = toremove === realGap ? target : current - toremove; - yield new Value(next, previous); - previous = next; - } + [symbol]() { + return pipe(hash(this.current), combine(hash(this.previous)), combine(hash(this.next)), cached(this)); } - function* shrinkIncr() { - let previous = tryTargetAsap ? undefined : target; - const gap = tryTargetAsap ? realGap : halveNegInteger(realGap); - for (let toremove = gap;toremove < 0; toremove = halveNegInteger(toremove)) { - const next = toremove === realGap ? target : current - toremove; - yield new Value(next, previous); - previous = next; + [symbol2](that) { + if (this === that) { + return true; } + return isMapKey(that) && equals(this.current, that.current) && equals(this.previous, that.previous) && equals(this.next, that.next); } - return realGap > 0 ? stream(shrinkDecr()) : stream(shrinkIncr()); } +var makeMapKey = (current) => new MapKeyImpl(current); +var isMapKey = (u) => hasProperty(u, MapKeyTypeId); -// node_modules/fast-check/lib/esm/arbitrary/_internals/IntegerArbitrary.js -var safeMathSign = Math.sign; -var safeNumberIsInteger = Number.isInteger; -var safeObjectIs = Object.is; - -class IntegerArbitrary extends Arbitrary { - constructor(min4, max6) { - super(); - this.min = min4; - this.max = max6; - } - generate(mrng, biasFactor) { - const range = this.computeGenerateRange(mrng, biasFactor); - return new Value(mrng.nextInt(range.min, range.max), undefined); - } - canShrinkWithoutContext(value2) { - return typeof value2 === "number" && safeNumberIsInteger(value2) && !safeObjectIs(value2, -0) && this.min <= value2 && value2 <= this.max; - } - shrink(current, context4) { - if (!IntegerArbitrary.isValidContext(current, context4)) { - const target = this.defaultTarget(); - return shrinkInteger(current, target, true); - } - if (this.isLastChanceTry(current, context4)) { - return Stream.of(new Value(context4, undefined)); - } - return shrinkInteger(current, context4, false); - } - defaultTarget() { - if (this.min <= 0 && this.max >= 0) { - return 0; +class KeySetImpl { + head = undefined; + tail = undefined; + add(key) { + if (key !== this.tail) { + if (this.tail === undefined) { + this.head = key; + this.tail = key; + } else { + const previous = key.previous; + const next = key.next; + if (next !== undefined) { + key.next = undefined; + if (previous !== undefined) { + previous.next = next; + next.previous = previous; + } else { + this.head = next; + this.head.previous = undefined; + } + } + this.tail.next = key; + key.previous = this.tail; + this.tail = key; + } } - return this.min < 0 ? this.max : this.min; } - computeGenerateRange(mrng, biasFactor) { - if (biasFactor === undefined || mrng.nextInt(1, biasFactor) !== 1) { - return { min: this.min, max: this.max }; - } - const ranges = biasNumericRange(this.min, this.max, integerLogLike); - if (ranges.length === 1) { - return ranges[0]; + remove() { + const key = this.head; + if (key !== undefined) { + const next = key.next; + if (next !== undefined) { + key.next = undefined; + this.head = next; + this.head.previous = undefined; + } else { + this.head = undefined; + this.tail = undefined; + } } - const id = mrng.nextInt(-2 * (ranges.length - 1), ranges.length - 2); - return id < 0 ? ranges[0] : ranges[id + 1]; - } - isLastChanceTry(current, context4) { - if (current > 0) - return current === context4 + 1 && current > this.min; - if (current < 0) - return current === context4 - 1 && current < this.max; - return false; + return key; } - static isValidContext(current, context4) { - if (context4 === undefined) { - return false; - } - if (typeof context4 !== "number") { - throw new Error(`Invalid context type passed to IntegerArbitrary (#1)`); - } - if (context4 !== 0 && safeMathSign(current) !== safeMathSign(context4)) { - throw new Error(`Invalid context value passed to IntegerArbitrary (#2)`); - } - return true; +} +var makeKeySet = () => new KeySetImpl; +var makeCacheState = (map10, keys5, accesses, updating, hits, misses) => ({ + map: map10, + keys: keys5, + accesses, + updating, + hits, + misses +}); +var initialCacheState = () => makeCacheState(empty17(), makeKeySet(), unbounded(), make12(false), 0, 0); +var CacheSymbolKey = "effect/Cache"; +var CacheTypeId = /* @__PURE__ */ Symbol.for(CacheSymbolKey); +var cacheVariance = { + _Key: (_) => _, + _Error: (_) => _, + _Value: (_) => _ +}; +var ConsumerCacheSymbolKey = "effect/ConsumerCache"; +var ConsumerCacheTypeId = /* @__PURE__ */ Symbol.for(ConsumerCacheSymbolKey); +var consumerCacheVariance = { + _Key: (_) => _, + _Error: (_) => _, + _Value: (_) => _ +}; +var makeCacheStats = (options) => options; +var makeEntryStats = (loadedMillis) => ({ + loadedMillis +}); + +class CacheImpl { + capacity; + context; + fiberId; + lookup; + timeToLive; + [CacheTypeId] = cacheVariance; + [ConsumerCacheTypeId] = consumerCacheVariance; + cacheState; + constructor(capacity, context2, fiberId2, lookup, timeToLive) { + this.capacity = capacity; + this.context = context2; + this.fiberId = fiberId2; + this.lookup = lookup; + this.timeToLive = timeToLive; + this.cacheState = initialCacheState(); } -} - -// node_modules/fast-check/lib/esm/arbitrary/integer.js -var safeNumberIsInteger2 = Number.isInteger; -function buildCompleteIntegerConstraints(constraints) { - const min4 = constraints.min !== undefined ? constraints.min : -2147483648; - const max6 = constraints.max !== undefined ? constraints.max : 2147483647; - return { min: min4, max: max6 }; -} -function integer2(constraints = {}) { - const fullConstraints = buildCompleteIntegerConstraints(constraints); - if (fullConstraints.min > fullConstraints.max) { - throw new Error("fc.integer maximum value should be equal or greater than the minimum one"); + get(key) { + return map9(this.getEither(key), merge); } - if (!safeNumberIsInteger2(fullConstraints.min)) { - throw new Error("fc.integer minimum value should be an integer"); + get cacheStats() { + return sync(() => makeCacheStats({ + hits: this.cacheState.hits, + misses: this.cacheState.misses, + size: size4(this.cacheState.map) + })); } - if (!safeNumberIsInteger2(fullConstraints.max)) { - throw new Error("fc.integer maximum value should be an integer"); + getOption(key) { + return suspend(() => match2(get8(this.cacheState.map, key), { + onNone: () => { + const mapKey = makeMapKey(key); + this.trackAccess(mapKey); + this.trackMiss(); + return succeed(none2()); + }, + onSome: (value) => this.resolveMapValue(value) + })); } - return new IntegerArbitrary(fullConstraints.min, fullConstraints.max); -} - -// node_modules/fast-check/lib/esm/arbitrary/_internals/helpers/DepthContext.js -var depthContextCache = new Map; -function getDepthContextFor(contextMeta) { - if (contextMeta === undefined) { - return { depth: 0 }; + getOptionComplete(key) { + return suspend(() => match2(get8(this.cacheState.map, key), { + onNone: () => { + const mapKey = makeMapKey(key); + this.trackAccess(mapKey); + this.trackMiss(); + return succeed(none2()); + }, + onSome: (value) => this.resolveMapValue(value, true) + })); } - if (typeof contextMeta !== "string") { - return contextMeta; + contains(key) { + return sync(() => has4(this.cacheState.map, key)); } - const cachedContext = safeMapGet(depthContextCache, contextMeta); - if (cachedContext !== undefined) { - return cachedContext; + entryStats(key) { + return sync(() => { + const option2 = get8(this.cacheState.map, key); + if (isSome2(option2)) { + switch (option2.value._tag) { + case "Complete": { + const loaded = option2.value.entryStats.loadedMillis; + return some2(makeEntryStats(loaded)); + } + case "Pending": { + return none2(); + } + case "Refreshing": { + const loaded = option2.value.complete.entryStats.loadedMillis; + return some2(makeEntryStats(loaded)); + } + } + } + return none2(); + }); } - const context4 = { depth: 0 }; - safeMapSet(depthContextCache, contextMeta, context4); - return context4; -} - -// node_modules/fast-check/lib/esm/arbitrary/_internals/implementations/NoopSlicedGenerator.js -class NoopSlicedGenerator { - constructor(arb, mrng, biasFactor) { - this.arb = arb; - this.mrng = mrng; - this.biasFactor = biasFactor; + getEither(key) { + return suspend(() => { + const k = key; + let mapKey = undefined; + let deferred = undefined; + let value = getOrUndefined(get8(this.cacheState.map, k)); + if (value === undefined) { + deferred = unsafeMake3(this.fiberId); + mapKey = makeMapKey(k); + if (has4(this.cacheState.map, k)) { + value = getOrUndefined(get8(this.cacheState.map, k)); + } else { + set4(this.cacheState.map, k, pending2(mapKey, deferred)); + } + } + if (value === undefined) { + this.trackAccess(mapKey); + this.trackMiss(); + return map9(this.lookupValueOf(key, deferred), right2); + } else { + return flatMap7(this.resolveMapValue(value), match2({ + onNone: () => this.getEither(key), + onSome: (value2) => succeed(left2(value2)) + })); + } + }); } - attemptExact() { - return; + invalidate(key) { + return sync(() => { + remove5(this.cacheState.map, key); + }); } - next() { - return this.arb.generate(this.mrng, this.biasFactor); + invalidateWhen(key, when2) { + return sync(() => { + const value = get8(this.cacheState.map, key); + if (isSome2(value) && value.value._tag === "Complete") { + if (value.value.exit._tag === "Success") { + if (when2(value.value.exit.value)) { + remove5(this.cacheState.map, key); + } + } + } + }); } -} - -// node_modules/fast-check/lib/esm/arbitrary/_internals/implementations/SlicedBasedGenerator.js -var safeMathMin = Math.min; -var safeMathMax = Math.max; - -class SlicedBasedGenerator { - constructor(arb, mrng, slices, biasFactor) { - this.arb = arb; - this.mrng = mrng; - this.slices = slices; - this.biasFactor = biasFactor; - this.activeSliceIndex = 0; - this.nextIndexInSlice = 0; - this.lastIndexInSlice = -1; + get invalidateAll() { + return sync(() => { + this.cacheState.map = empty17(); + }); } - attemptExact(targetLength) { - if (targetLength !== 0 && this.mrng.nextInt(1, this.biasFactor) === 1) { - const eligibleIndices = []; - for (let index = 0;index !== this.slices.length; ++index) { - const slice = this.slices[index]; - if (slice.length === targetLength) { - safePush(eligibleIndices, index); + refresh(key) { + return clockWith3((clock2) => suspend(() => { + const k = key; + const deferred = unsafeMake3(this.fiberId); + let value = getOrUndefined(get8(this.cacheState.map, k)); + if (value === undefined) { + if (has4(this.cacheState.map, k)) { + value = getOrUndefined(get8(this.cacheState.map, k)); + } else { + set4(this.cacheState.map, k, pending2(makeMapKey(k), deferred)); } } - if (eligibleIndices.length === 0) { - return; + if (value === undefined) { + return asVoid(this.lookupValueOf(key, deferred)); + } else { + switch (value._tag) { + case "Complete": { + if (this.hasExpired(clock2, value.timeToLiveMillis)) { + const found = getOrUndefined(get8(this.cacheState.map, k)); + if (equals(found, value)) { + remove5(this.cacheState.map, k); + } + return asVoid(this.get(key)); + } + return pipe(this.lookupValueOf(key, deferred), when(() => { + const current = getOrUndefined(get8(this.cacheState.map, k)); + if (equals(current, value)) { + const mapValue = refreshing(deferred, value); + set4(this.cacheState.map, k, mapValue); + return true; + } + return false; + }), asVoid); + } + case "Pending": { + return _await(value.deferred); + } + case "Refreshing": { + return _await(value.deferred); + } + } } - this.activeSliceIndex = eligibleIndices[this.mrng.nextInt(0, eligibleIndices.length - 1)]; - this.nextIndexInSlice = 0; - this.lastIndexInSlice = targetLength - 1; - } - } - next() { - if (this.nextIndexInSlice <= this.lastIndexInSlice) { - return new Value(this.slices[this.activeSliceIndex][this.nextIndexInSlice++], undefined); - } - if (this.mrng.nextInt(1, this.biasFactor) !== 1) { - return this.arb.generate(this.mrng, this.biasFactor); - } - this.activeSliceIndex = this.mrng.nextInt(0, this.slices.length - 1); - const slice = this.slices[this.activeSliceIndex]; - if (this.mrng.nextInt(1, this.biasFactor) !== 1) { - this.nextIndexInSlice = 1; - this.lastIndexInSlice = slice.length - 1; - return new Value(slice[0], undefined); - } - const rangeBoundaryA = this.mrng.nextInt(0, slice.length - 1); - const rangeBoundaryB = this.mrng.nextInt(0, slice.length - 1); - this.nextIndexInSlice = safeMathMin(rangeBoundaryA, rangeBoundaryB); - this.lastIndexInSlice = safeMathMax(rangeBoundaryA, rangeBoundaryB); - return new Value(slice[this.nextIndexInSlice++], undefined); + })); } -} - -// node_modules/fast-check/lib/esm/arbitrary/_internals/helpers/BuildSlicedGenerator.js -function buildSlicedGenerator(arb, mrng, slices, biasFactor) { - if (biasFactor === undefined || slices.length === 0 || mrng.nextInt(1, biasFactor) !== 1) { - return new NoopSlicedGenerator(arb, mrng, biasFactor); + set(key, value) { + return clockWith3((clock2) => sync(() => { + const now = clock2.unsafeCurrentTimeMillis(); + const k = key; + const lookupResult = succeed2(value); + const mapValue = complete2(makeMapKey(k), lookupResult, makeEntryStats(now), now + toMillis(decode(this.timeToLive(lookupResult)))); + set4(this.cacheState.map, k, mapValue); + })); } - return new SlicedBasedGenerator(arb, mrng, slices, biasFactor); -} - -// node_modules/fast-check/lib/esm/arbitrary/_internals/ArrayArbitrary.js -var safeMathFloor3 = Math.floor; -var safeMathLog2 = Math.log; -var safeMathMax2 = Math.max; -var safeArrayIsArray = Array.isArray; -function biasedMaxLength(minLength, maxLength) { - if (minLength === maxLength) { - return minLength; + get size() { + return sync(() => { + return size4(this.cacheState.map); + }); } - return minLength + safeMathFloor3(safeMathLog2(maxLength - minLength) / safeMathLog2(2)); -} - -class ArrayArbitrary extends Arbitrary { - constructor(arb, minLength, maxGeneratedLength, maxLength, depthIdentifier, setBuilder, customSlices) { - super(); - this.arb = arb; - this.minLength = minLength; - this.maxGeneratedLength = maxGeneratedLength; - this.maxLength = maxLength; - this.setBuilder = setBuilder; - this.customSlices = customSlices; - this.lengthArb = integer2({ min: minLength, max: maxGeneratedLength }); - this.depthContext = getDepthContextFor(depthIdentifier); + get values() { + return sync(() => { + const values4 = []; + for (const entry of this.cacheState.map) { + if (entry[1]._tag === "Complete" && entry[1].exit._tag === "Success") { + values4.push(entry[1].exit.value); + } + } + return values4; + }); } - preFilter(tab) { - if (this.setBuilder === undefined) { - return tab; - } - const s = this.setBuilder(); - for (let index = 0;index !== tab.length; ++index) { - s.tryAdd(tab[index]); - } - return s.getData(); + get entries() { + return sync(() => { + const values4 = []; + for (const entry of this.cacheState.map) { + if (entry[1]._tag === "Complete" && entry[1].exit._tag === "Success") { + values4.push([entry[0], entry[1].exit.value]); + } + } + return values4; + }); } - static makeItCloneable(vs, shrinkables) { - vs[cloneMethod] = () => { - const cloned = []; - for (let idx = 0;idx !== shrinkables.length; ++idx) { - safePush(cloned, shrinkables[idx].value); + get keys() { + return sync(() => { + const keys5 = []; + for (const entry of this.cacheState.map) { + if (entry[1]._tag === "Complete" && entry[1].exit._tag === "Success") { + keys5.push(entry[0]); + } } - this.makeItCloneable(cloned, shrinkables); - return cloned; - }; - return vs; + return keys5; + }); } - generateNItemsNoDuplicates(setBuilder, N, mrng, biasFactorItems) { - let numSkippedInRow = 0; - const s = setBuilder(); - const slicedGenerator = buildSlicedGenerator(this.arb, mrng, this.customSlices, biasFactorItems); - while (s.size() < N && numSkippedInRow < this.maxGeneratedLength) { - const current = slicedGenerator.next(); - if (s.tryAdd(current)) { - numSkippedInRow = 0; - } else { - numSkippedInRow += 1; + resolveMapValue(value, ignorePending = false) { + return clockWith3((clock2) => { + switch (value._tag) { + case "Complete": { + this.trackAccess(value.key); + if (this.hasExpired(clock2, value.timeToLiveMillis)) { + remove5(this.cacheState.map, value.key.current); + return succeed(none2()); + } + this.trackHit(); + return map9(value.exit, some2); + } + case "Pending": { + this.trackAccess(value.key); + this.trackHit(); + if (ignorePending) { + return succeed(none2()); + } + return map9(_await(value.deferred), some2); + } + case "Refreshing": { + this.trackAccess(value.complete.key); + this.trackHit(); + if (this.hasExpired(clock2, value.complete.timeToLiveMillis)) { + if (ignorePending) { + return succeed(none2()); + } + return map9(_await(value.deferred), some2); + } + return map9(value.complete.exit, some2); + } } - } - return s.getData(); + }); } - safeGenerateNItemsNoDuplicates(setBuilder, N, mrng, biasFactorItems) { - const depthImpact = safeMathMax2(0, N - biasedMaxLength(this.minLength, this.maxGeneratedLength)); - this.depthContext.depth += depthImpact; - try { - return this.generateNItemsNoDuplicates(setBuilder, N, mrng, biasFactorItems); - } finally { - this.depthContext.depth -= depthImpact; - } + trackHit() { + this.cacheState.hits = this.cacheState.hits + 1; } - generateNItems(N, mrng, biasFactorItems) { - const items = []; - const slicedGenerator = buildSlicedGenerator(this.arb, mrng, this.customSlices, biasFactorItems); - slicedGenerator.attemptExact(N); - for (let index = 0;index !== N; ++index) { - const current = slicedGenerator.next(); - safePush(items, current); - } - return items; + trackMiss() { + this.cacheState.misses = this.cacheState.misses + 1; } - safeGenerateNItems(N, mrng, biasFactorItems) { - const depthImpact = safeMathMax2(0, N - biasedMaxLength(this.minLength, this.maxGeneratedLength)); - this.depthContext.depth += depthImpact; - try { - return this.generateNItems(N, mrng, biasFactorItems); - } finally { - this.depthContext.depth -= depthImpact; + trackAccess(key) { + offer(this.cacheState.accesses, key); + if (compareAndSet(this.cacheState.updating, false, true)) { + let loop2 = true; + while (loop2) { + const key2 = poll(this.cacheState.accesses, EmptyMutableQueue); + if (key2 === EmptyMutableQueue) { + loop2 = false; + } else { + this.cacheState.keys.add(key2); + } + } + let size7 = size4(this.cacheState.map); + loop2 = size7 > this.capacity; + while (loop2) { + const key2 = this.cacheState.keys.remove(); + if (key2 !== undefined) { + if (has4(this.cacheState.map, key2.current)) { + remove5(this.cacheState.map, key2.current); + size7 = size7 - 1; + loop2 = size7 > this.capacity; + } + } else { + loop2 = false; + } + } + set2(this.cacheState.updating, false); } } - wrapper(itemsRaw, shrunkOnce, itemsRawLengthContext, startIndex) { - const items = shrunkOnce ? this.preFilter(itemsRaw) : itemsRaw; - let cloneable = false; - const vs = []; - const itemsContexts = []; - for (let idx = 0;idx !== items.length; ++idx) { - const s = items[idx]; - cloneable = cloneable || s.hasToBeCloned; - safePush(vs, s.value); - safePush(itemsContexts, s.context); - } - if (cloneable) { - ArrayArbitrary.makeItCloneable(vs, items); - } - const context4 = { - shrunkOnce, - lengthContext: itemsRaw.length === items.length && itemsRawLengthContext !== undefined ? itemsRawLengthContext : undefined, - itemsContexts, - startIndex - }; - return new Value(vs, context4); + hasExpired(clock2, timeToLiveMillis) { + return clock2.unsafeCurrentTimeMillis() > timeToLiveMillis; } - generate(mrng, biasFactor) { - const biasMeta = this.applyBias(mrng, biasFactor); - const targetSize = biasMeta.size; - const items = this.setBuilder !== undefined ? this.safeGenerateNItemsNoDuplicates(this.setBuilder, targetSize, mrng, biasMeta.biasFactorItems) : this.safeGenerateNItems(targetSize, mrng, biasMeta.biasFactorItems); - return this.wrapper(items, false, undefined, 0); + lookupValueOf(input, deferred) { + return clockWith3((clock2) => suspend(() => { + const key = input; + return pipe(this.lookup(input), provideContext(this.context), exit, flatMap7((exit2) => { + const now = clock2.unsafeCurrentTimeMillis(); + const stats = makeEntryStats(now); + const value = complete2(makeMapKey(key), exit2, stats, now + toMillis(decode(this.timeToLive(exit2)))); + set4(this.cacheState.map, key, value); + return zipRight(done2(deferred, exit2), exit2); + }), onInterrupt(() => zipRight(interrupt3(deferred), sync(() => { + remove5(this.cacheState.map, key); + })))); + })); + } +} +var unsafeMakeWith = (capacity, lookup, timeToLive) => new CacheImpl(capacity, empty3(), none3, lookup, (exit2) => decode(timeToLive(exit2))); +// node_modules/effect/dist/esm/Cause.js +var empty26 = empty16; +var fail3 = fail; +var die3 = die; +var interrupt4 = interrupt; +var parallel4 = parallel; +var sequential4 = sequential; +var isCause2 = isCause; +var isFailType2 = isFailType; +var IllegalArgumentException2 = IllegalArgumentException; +var pretty2 = pretty; +// node_modules/effect/dist/esm/Effect.js +var exports_Effect = {}; +__export(exports_Effect, { + zipWith: () => zipWith3, + zipRight: () => zipRight2, + zipLeft: () => zipLeft2, + zip: () => zip4, + yieldNow: () => yieldNow4, + withUnhandledErrorLogLevel: () => withUnhandledErrorLogLevel2, + withTracerTiming: () => withTracerTiming2, + withTracerScoped: () => withTracerScoped2, + withTracerEnabled: () => withTracerEnabled2, + withTracer: () => withTracer2, + withSpanScoped: () => withSpanScoped2, + withSpan: () => withSpan2, + withSchedulingPriority: () => withSchedulingPriority2, + withScheduler: () => withScheduler2, + withRuntimeFlagsPatchScoped: () => withRuntimeFlagsPatchScoped, + withRuntimeFlagsPatch: () => withRuntimeFlagsPatch, + withRequestCaching: () => withRequestCaching2, + withRequestCache: () => withRequestCache2, + withRequestBatching: () => withRequestBatching2, + withRandomScoped: () => withRandomScoped2, + withRandomFixed: () => withRandomFixed, + withRandom: () => withRandom2, + withParentSpan: () => withParentSpan2, + withMetric: () => withMetric2, + withMaxOpsBeforeYield: () => withMaxOpsBeforeYield2, + withLogSpan: () => withLogSpan2, + withFiberRuntime: () => withFiberRuntime2, + withExecutionPlan: () => withExecutionPlan2, + withEarlyRelease: () => withEarlyRelease2, + withConsoleScoped: () => withConsoleScoped2, + withConsole: () => withConsole2, + withConfigProviderScoped: () => withConfigProviderScoped2, + withConfigProvider: () => withConfigProvider2, + withConcurrency: () => withConcurrency2, + withClockScoped: () => withClockScoped2, + withClock: () => withClock2, + whileLoop: () => whileLoop2, + whenRef: () => whenRef2, + whenLogLevel: () => whenLogLevel2, + whenFiberRef: () => whenFiberRef2, + whenEffect: () => whenEffect2, + when: () => when2, + void: () => _void, + validateWith: () => validateWith2, + validateFirst: () => validateFirst2, + validateAll: () => validateAll2, + validate: () => validate2, + using: () => using2, + useSpan: () => useSpan2, + updateService: () => updateService2, + updateFiberRefs: () => updateFiberRefs2, + unsandbox: () => unsandbox2, + unsafeMakeSemaphore: () => unsafeMakeSemaphore2, + unsafeMakeLatch: () => unsafeMakeLatch2, + unlessEffect: () => unlessEffect2, + unless: () => unless2, + uninterruptibleMask: () => uninterruptibleMask3, + uninterruptible: () => uninterruptible2, + tryPromise: () => tryPromise2, + tryMapPromise: () => tryMapPromise2, + tryMap: () => tryMap2, + try: () => try_3, + transposeOption: () => transposeOption, + transposeMapOption: () => transposeMapOption, + transplant: () => transplant2, + tracerWith: () => tracerWith4, + tracer: () => tracer2, + timeoutTo: () => timeoutTo2, + timeoutOption: () => timeoutOption2, + timeoutFailCause: () => timeoutFailCause2, + timeoutFail: () => timeoutFail2, + timeout: () => timeout2, + timedWith: () => timedWith2, + timed: () => timed2, + tapErrorTag: () => tapErrorTag2, + tapErrorCause: () => tapErrorCause2, + tapError: () => tapError2, + tapDefect: () => tapDefect2, + tapBoth: () => tapBoth2, + tap: () => tap2, + takeWhile: () => takeWhile2, + takeUntil: () => takeUntil2, + tagMetricsScoped: () => tagMetricsScoped2, + tagMetrics: () => tagMetrics2, + sync: () => sync3, + suspend: () => suspend3, + supervised: () => supervised2, + summarized: () => summarized2, + succeedSome: () => succeedSome2, + succeedNone: () => succeedNone2, + succeed: () => succeed6, + step: () => step3, + spanLinks: () => spanLinks2, + spanAnnotations: () => spanAnnotations2, + sleep: () => sleep4, + setFiberRefs: () => setFiberRefs2, + serviceOptional: () => serviceOptional2, + serviceOption: () => serviceOption2, + serviceMembers: () => serviceMembers2, + serviceFunctions: () => serviceFunctions2, + serviceFunctionEffect: () => serviceFunctionEffect2, + serviceFunction: () => serviceFunction2, + serviceConstants: () => serviceConstants2, + sequentialFinalizers: () => sequentialFinalizers2, + scopedWith: () => scopedWith2, + scoped: () => scoped2, + scopeWith: () => scopeWith2, + scope: () => scope2, + scheduleFrom: () => scheduleFrom, + scheduleForked: () => scheduleForked2, + schedule: () => schedule, + sandbox: () => sandbox2, + runtime: () => runtime4, + runSyncExit: () => runSyncExit, + runSync: () => runSync, + runRequestBlock: () => runRequestBlock2, + runPromiseExit: () => runPromiseExit, + runPromise: () => runPromise, + runFork: () => runFork2, + runCallback: () => runCallback, + retryOrElse: () => retryOrElse, + retry: () => retry, + request: () => request, + replicateEffect: () => replicateEffect2, + replicate: () => replicate2, + repeatOrElse: () => repeatOrElse, + repeatN: () => repeatN2, + repeat: () => repeat, + reduceWhile: () => reduceWhile2, + reduceRight: () => reduceRight3, + reduceEffect: () => reduceEffect2, + reduce: () => reduce10, + randomWith: () => randomWith2, + random: () => random3, + raceWith: () => raceWith2, + raceFirst: () => raceFirst2, + raceAll: () => raceAll2, + race: () => race2, + provideServiceEffect: () => provideServiceEffect2, + provideService: () => provideService2, + provide: () => provide2, + promise: () => promise2, + patchRuntimeFlags: () => patchRuntimeFlags, + patchFiberRefs: () => patchFiberRefs2, + partition: () => partition4, + parallelFinalizers: () => parallelFinalizers2, + parallelErrors: () => parallelErrors2, + orElseSucceed: () => orElseSucceed2, + orElseFail: () => orElseFail2, + orElse: () => orElse3, + orDieWith: () => orDieWith2, + orDie: () => orDie2, + optionFromOptional: () => optionFromOptional2, + option: () => option2, + once: () => once3, + onInterrupt: () => onInterrupt2, + onExit: () => onExit3, + onError: () => onError2, + none: () => none9, + never: () => never2, + negate: () => negate2, + metricLabels: () => metricLabels2, + mergeAll: () => mergeAll5, + merge: () => merge6, + matchEffect: () => matchEffect2, + matchCauseEffect: () => matchCauseEffect3, + matchCause: () => matchCause2, + match: () => match10, + mapInputContext: () => mapInputContext2, + mapErrorCause: () => mapErrorCause2, + mapError: () => mapError2, + mapBoth: () => mapBoth3, + mapAccum: () => mapAccum3, + map: () => map11, + makeSpanScoped: () => makeSpanScoped2, + makeSpan: () => makeSpan2, + makeSemaphore: () => makeSemaphore2, + makeLatch: () => makeLatch2, + loop: () => loop2, + logWithLevel: () => logWithLevel2, + logWarning: () => logWarning2, + logTrace: () => logTrace2, + logInfo: () => logInfo2, + logFatal: () => logFatal2, + logError: () => logError2, + logDebug: () => logDebug2, + logAnnotations: () => logAnnotations2, + log: () => log2, + locallyWith: () => locallyWith, + locallyScopedWith: () => locallyScopedWith, + locallyScoped: () => locallyScoped, + locally: () => locally, + linkSpans: () => linkSpans2, + linkSpanCurrent: () => linkSpanCurrent2, + liftPredicate: () => liftPredicate2, + let: () => let_3, + labelMetricsScoped: () => labelMetricsScoped2, + labelMetrics: () => labelMetrics2, + iterate: () => iterate2, + isSuccess: () => isSuccess3, + isFailure: () => isFailure3, + isEffect: () => isEffect2, + intoDeferred: () => intoDeferred2, + interruptibleMask: () => interruptibleMask2, + interruptible: () => interruptible4, + interruptWith: () => interruptWith2, + interrupt: () => interrupt5, + inheritFiberRefs: () => inheritFiberRefs2, + ignoreLogged: () => ignoreLogged2, + ignore: () => ignore2, + if: () => if_2, + head: () => head4, + getRuntimeFlags: () => getRuntimeFlags, + getFiberRefs: () => getFiberRefs, + gen: () => gen2, + functionWithSpan: () => functionWithSpan2, + fromNullable: () => fromNullable3, + fromFiberEffect: () => fromFiberEffect2, + fromFiber: () => fromFiber2, + forkWithErrorHandler: () => forkWithErrorHandler2, + forkScoped: () => forkScoped2, + forkIn: () => forkIn2, + forkDaemon: () => forkDaemon2, + forkAll: () => forkAll2, + fork: () => fork3, + forever: () => forever3, + forEach: () => forEach7, + fnUntraced: () => fnUntraced2, + fn: () => fn, + flipWith: () => flipWith2, + flip: () => flip2, + flatten: () => flatten7, + flatMap: () => flatMap9, + firstSuccessOf: () => firstSuccessOf2, + findFirst: () => findFirst6, + finalizersMask: () => finalizersMask2, + filterOrFail: () => filterOrFail2, + filterOrElse: () => filterOrElse2, + filterOrDieMessage: () => filterOrDieMessage2, + filterOrDie: () => filterOrDie2, + filterMap: () => filterMap5, + filterEffectOrFail: () => filterEffectOrFail2, + filterEffectOrElse: () => filterEffectOrElse2, + filter: () => filter7, + fiberIdWith: () => fiberIdWith2, + fiberId: () => fiberId2, + failSync: () => failSync2, + failCauseSync: () => failCauseSync2, + failCause: () => failCause5, + fail: () => fail5, + exit: () => exit2, + exists: () => exists3, + every: () => every6, + eventually: () => eventually2, + ensuringChildren: () => ensuringChildren2, + ensuringChild: () => ensuringChild2, + ensuring: () => ensuring2, + ensureSuccessType: () => ensureSuccessType, + ensureRequirementsType: () => ensureRequirementsType, + ensureErrorType: () => ensureErrorType, + either: () => either3, + dropWhile: () => dropWhile2, + dropUntil: () => dropUntil2, + disconnect: () => disconnect2, + diffFiberRefs: () => diffFiberRefs2, + dieSync: () => dieSync2, + dieMessage: () => dieMessage2, + die: () => die4, + descriptorWith: () => descriptorWith2, + descriptor: () => descriptor2, + delay: () => delay2, + daemonChildren: () => daemonChildren2, + custom: () => custom2, + currentSpan: () => currentSpan2, + currentPropagatedSpan: () => currentPropagatedSpan2, + currentParentSpan: () => currentParentSpan2, + contextWithEffect: () => contextWithEffect2, + contextWith: () => contextWith2, + context: () => context3, + consoleWith: () => consoleWith2, + console: () => console3, + configProviderWith: () => configProviderWith2, + clockWith: () => clockWith4, + clock: () => clock2, + checkInterruptible: () => checkInterruptible2, + cause: () => cause2, + catchTags: () => catchTags2, + catchTag: () => catchTag2, + catchSomeDefect: () => catchSomeDefect2, + catchSomeCause: () => catchSomeCause2, + catchSome: () => catchSome2, + catchIf: () => catchIf2, + catchAllDefect: () => catchAllDefect2, + catchAllCause: () => catchAllCause2, + catchAll: () => catchAll2, + catch: () => _catch2, + cachedWithTTL: () => cachedWithTTL, + cachedInvalidateWithTTL: () => cachedInvalidateWithTTL2, + cachedFunction: () => cachedFunction2, + cached: () => cached3, + cacheRequestResult: () => cacheRequestResult, + blocked: () => blocked2, + bindTo: () => bindTo3, + bindAll: () => bindAll2, + bind: () => bind3, + awaitAllChildren: () => awaitAllChildren2, + asyncEffect: () => asyncEffect2, + async: () => async, + asVoid: () => asVoid3, + asSomeError: () => asSomeError2, + asSome: () => asSome2, + as: () => as3, + ap: () => ap, + annotateSpans: () => annotateSpans2, + annotateLogsScoped: () => annotateLogsScoped2, + annotateLogs: () => annotateLogs2, + annotateCurrentSpan: () => annotateCurrentSpan2, + andThen: () => andThen4, + allowInterrupt: () => allowInterrupt2, + allWith: () => allWith2, + allSuccesses: () => allSuccesses2, + all: () => all3, + addFinalizer: () => addFinalizer2, + acquireUseRelease: () => acquireUseRelease2, + acquireReleaseInterruptible: () => acquireReleaseInterruptible2, + acquireRelease: () => acquireRelease2, + Tag: () => Tag2, + Service: () => Service, + EffectTypeId: () => EffectTypeId3, + Do: () => Do2 +}); + +// node_modules/effect/dist/esm/internal/schedule/interval.js +var IntervalSymbolKey = "effect/ScheduleInterval"; +var IntervalTypeId = /* @__PURE__ */ Symbol.for(IntervalSymbolKey); +var empty27 = { + [IntervalTypeId]: IntervalTypeId, + startMillis: 0, + endMillis: 0 +}; +var make35 = (startMillis, endMillis) => { + if (startMillis > endMillis) { + return empty27; } - applyBias(mrng, biasFactor) { - if (biasFactor === undefined) { - return { size: this.lengthArb.generate(mrng, undefined).value }; - } - if (this.minLength === this.maxGeneratedLength) { - return { size: this.lengthArb.generate(mrng, undefined).value, biasFactorItems: biasFactor }; - } - if (mrng.nextInt(1, biasFactor) !== 1) { - return { size: this.lengthArb.generate(mrng, undefined).value }; - } - if (mrng.nextInt(1, biasFactor) !== 1 || this.minLength === this.maxGeneratedLength) { - return { size: this.lengthArb.generate(mrng, undefined).value, biasFactorItems: biasFactor }; + return { + [IntervalTypeId]: IntervalTypeId, + startMillis, + endMillis + }; +}; +var lessThan4 = /* @__PURE__ */ dual(2, (self, that) => min2(self, that) === self); +var min2 = /* @__PURE__ */ dual(2, (self, that) => { + if (self.endMillis <= that.startMillis) + return self; + if (that.endMillis <= self.startMillis) + return that; + if (self.startMillis < that.startMillis) + return self; + if (that.startMillis < self.startMillis) + return that; + if (self.endMillis <= that.endMillis) + return self; + return that; +}); +var isEmpty7 = (self) => { + return self.startMillis >= self.endMillis; +}; +var intersect = /* @__PURE__ */ dual(2, (self, that) => { + const start = Math.max(self.startMillis, that.startMillis); + const end = Math.min(self.endMillis, that.endMillis); + return make35(start, end); +}); +var after = (startMilliseconds) => { + return make35(startMilliseconds, Number.POSITIVE_INFINITY); +}; + +// node_modules/effect/dist/esm/ScheduleInterval.js +var empty28 = empty27; +var lessThan5 = lessThan4; +var isEmpty8 = isEmpty7; +var intersect2 = intersect; +var after2 = after; + +// node_modules/effect/dist/esm/internal/schedule/intervals.js +var IntervalsSymbolKey = "effect/ScheduleIntervals"; +var IntervalsTypeId = /* @__PURE__ */ Symbol.for(IntervalsSymbolKey); +var make37 = (intervals) => { + return { + [IntervalsTypeId]: IntervalsTypeId, + intervals + }; +}; +var intersect3 = /* @__PURE__ */ dual(2, (self, that) => intersectLoop(self.intervals, that.intervals, empty4())); +var intersectLoop = (_left, _right, _acc) => { + let left3 = _left; + let right3 = _right; + let acc = _acc; + while (isNonEmpty2(left3) && isNonEmpty2(right3)) { + const interval = pipe(headNonEmpty2(left3), intersect2(headNonEmpty2(right3))); + const intervals = isEmpty8(interval) ? acc : pipe(acc, prepend2(interval)); + if (pipe(headNonEmpty2(left3), lessThan5(headNonEmpty2(right3)))) { + left3 = tailNonEmpty2(left3); + } else { + right3 = tailNonEmpty2(right3); } - const maxBiasedLength = biasedMaxLength(this.minLength, this.maxGeneratedLength); - const targetSizeValue = integer2({ min: this.minLength, max: maxBiasedLength }).generate(mrng, undefined); - return { size: targetSizeValue.value, biasFactorItems: biasFactor }; + acc = intervals; } - canShrinkWithoutContext(value2) { - if (!safeArrayIsArray(value2) || this.minLength > value2.length || value2.length > this.maxLength) { - return false; - } - for (let index = 0;index !== value2.length; ++index) { - if (!(index in value2)) { - return false; - } - if (!this.arb.canShrinkWithoutContext(value2[index])) { - return false; - } - } - const filtered = this.preFilter(safeMap(value2, (item) => new Value(item, undefined))); - return filtered.length === value2.length; + return make37(reverse2(acc)); +}; +var start = (self) => { + return pipe(self.intervals, head2, getOrElse(() => empty28)).startMillis; +}; +var end = (self) => { + return pipe(self.intervals, head2, getOrElse(() => empty28)).endMillis; +}; +var lessThan6 = /* @__PURE__ */ dual(2, (self, that) => start(self) < start(that)); +var isNonEmpty4 = (self) => { + return isNonEmpty2(self.intervals); +}; + +// node_modules/effect/dist/esm/ScheduleIntervals.js +var make38 = make37; +var intersect4 = intersect3; +var start2 = start; +var end2 = end; +var lessThan7 = lessThan6; +var isNonEmpty5 = isNonEmpty4; + +// node_modules/effect/dist/esm/internal/schedule/decision.js +var OP_CONTINUE = "Continue"; +var OP_DONE2 = "Done"; +var _continue = (intervals) => { + return { + _tag: OP_CONTINUE, + intervals + }; +}; +var continueWith = (interval) => { + return { + _tag: OP_CONTINUE, + intervals: make38(of2(interval)) + }; +}; +var done5 = { + _tag: OP_DONE2 +}; +var isContinue = (self) => { + return self._tag === OP_CONTINUE; +}; +var isDone3 = (self) => { + return self._tag === OP_DONE2; +}; + +// node_modules/effect/dist/esm/ScheduleDecision.js +var _continue2 = _continue; +var continueWith2 = continueWith; +var done6 = done5; +var isContinue2 = isContinue; +var isDone4 = isDone3; + +// node_modules/effect/dist/esm/Scope.js +var close = scopeClose; +var fork2 = scopeFork; + +// node_modules/effect/dist/esm/internal/effect/circular.js +class Semaphore { + permits; + waiters = /* @__PURE__ */ new Set; + taken = 0; + constructor(permits) { + this.permits = permits; } - shrinkItemByItem(value2, safeContext, endIndex) { - const shrinks = []; - for (let index = safeContext.startIndex;index < endIndex; ++index) { - safePush(shrinks, makeLazy(() => this.arb.shrink(value2[index], safeContext.itemsContexts[index]).map((v) => { - const beforeCurrent = safeMap(safeSlice(value2, 0, index), (v2, i) => new Value(cloneIfNeeded(v2), safeContext.itemsContexts[i])); - const afterCurrent = safeMap(safeSlice(value2, index + 1), (v2, i) => new Value(cloneIfNeeded(v2), safeContext.itemsContexts[i + index + 1])); - return [ - [...beforeCurrent, v, ...afterCurrent], - undefined, - index - ]; - }))); - } - return Stream.nil().join(...shrinks); + get free() { + return this.permits - this.taken; } - shrinkImpl(value2, context4) { - if (value2.length === 0) { - return Stream.nil(); - } - const safeContext = context4 !== undefined ? context4 : { shrunkOnce: false, lengthContext: undefined, itemsContexts: [], startIndex: 0 }; - return this.lengthArb.shrink(value2.length, safeContext.lengthContext).drop(safeContext.shrunkOnce && safeContext.lengthContext === undefined && value2.length > this.minLength + 1 ? 1 : 0).map((lengthValue) => { - const sliceStart = value2.length - lengthValue.value; - return [ - safeMap(safeSlice(value2, sliceStart), (v, index) => new Value(cloneIfNeeded(v), safeContext.itemsContexts[index + sliceStart])), - lengthValue.context, - 0 - ]; - }).join(makeLazy(() => value2.length > this.minLength ? this.shrinkItemByItem(value2, safeContext, 1) : this.shrinkItemByItem(value2, safeContext, value2.length))).join(value2.length > this.minLength ? makeLazy(() => { - const subContext = { - shrunkOnce: false, - lengthContext: undefined, - itemsContexts: safeSlice(safeContext.itemsContexts, 1), - startIndex: 0 + take = (n) => asyncInterrupt((resume2) => { + if (this.free < n) { + const observer = () => { + if (this.free < n) + return; + this.waiters.delete(observer); + resume2(suspend(() => { + if (this.free < n) + return this.take(n); + this.taken += n; + return succeed(n); + })); }; - return this.shrinkImpl(safeSlice(value2, 1), subContext).filter((v) => this.minLength <= v[0].length + 1).map((v) => { - return [[new Value(cloneIfNeeded(value2[0]), safeContext.itemsContexts[0]), ...v[0]], undefined, 0]; + this.waiters.add(observer); + return sync(() => { + this.waiters.delete(observer); }); - }) : Stream.nil()); - } - shrink(value2, context4) { - return this.shrinkImpl(value2, context4).map((contextualValue) => this.wrapper(contextualValue[0], true, contextualValue[1], contextualValue[2])); - } -} - -// node_modules/fast-check/lib/esm/arbitrary/_internals/helpers/MaxLengthFromMinLength.js -var safeMathFloor4 = Math.floor; -var safeMathMin2 = Math.min; -var MaxLengthUpperBound = 2147483647; -var orderedSize = ["xsmall", "small", "medium", "large", "xlarge"]; -var orderedRelativeSize = ["-4", "-3", "-2", "-1", "=", "+1", "+2", "+3", "+4"]; -var DefaultSize = "small"; -function maxLengthFromMinLength(minLength, size10) { - switch (size10) { - case "xsmall": - return safeMathFloor4(1.1 * minLength) + 1; - case "small": - return 2 * minLength + 10; - case "medium": - return 11 * minLength + 100; - case "large": - return 101 * minLength + 1000; - case "xlarge": - return 1001 * minLength + 1e4; - default: - throw new Error(`Unable to compute lengths based on received size: ${size10}`); - } -} -function relativeSizeToSize(size10, defaultSize) { - const sizeInRelative = safeIndexOf(orderedRelativeSize, size10); - if (sizeInRelative === -1) { - return size10; - } - const defaultSizeInSize = safeIndexOf(orderedSize, defaultSize); - if (defaultSizeInSize === -1) { - throw new Error(`Unable to offset size based on the unknown defaulted one: ${defaultSize}`); - } - const resultingSizeInSize = defaultSizeInSize + sizeInRelative - 4; - return resultingSizeInSize < 0 ? orderedSize[0] : resultingSizeInSize >= orderedSize.length ? orderedSize[orderedSize.length - 1] : orderedSize[resultingSizeInSize]; -} -function maxGeneratedLengthFromSizeForArbitrary(size10, minLength, maxLength, specifiedMaxLength) { - const { baseSize: defaultSize = DefaultSize, defaultSizeToMaxWhenMaxSpecified } = readConfigureGlobal() || {}; - const definedSize = size10 !== undefined ? size10 : specifiedMaxLength && defaultSizeToMaxWhenMaxSpecified ? "max" : defaultSize; - if (definedSize === "max") { - return maxLength; - } - const finalSize = relativeSizeToSize(definedSize, defaultSize); - return safeMathMin2(maxLengthFromMinLength(minLength, finalSize), maxLength); -} - -// node_modules/fast-check/lib/esm/arbitrary/array.js -function array5(arb, constraints = {}) { - const size10 = constraints.size; - const minLength = constraints.minLength || 0; - const maxLengthOrUnset = constraints.maxLength; - const depthIdentifier = constraints.depthIdentifier; - const maxLength = maxLengthOrUnset !== undefined ? maxLengthOrUnset : MaxLengthUpperBound; - const specifiedMaxLength = maxLengthOrUnset !== undefined; - const maxGeneratedLength = maxGeneratedLengthFromSizeForArbitrary(size10, minLength, maxLength, specifiedMaxLength); - const customSlices = constraints.experimentalCustomSlices || []; - return new ArrayArbitrary(arb, minLength, maxGeneratedLength, maxLength, depthIdentifier, undefined, customSlices); -} - -// node_modules/effect/dist/esm/internal/schema/util.js -var getKeysForIndexSignature = (input, parameter) => { - switch (parameter._tag) { - case "StringKeyword": - case "TemplateLiteral": - return Object.keys(input); - case "SymbolKeyword": - return Object.getOwnPropertySymbols(input); - case "Refinement": - return getKeysForIndexSignature(input, parameter.from); + } + resume2(suspend(() => { + if (this.free < n) + return this.take(n); + this.taken += n; + return succeed(n); + })); + }); + updateTakenUnsafe(fiber, f) { + this.taken = f(this.taken); + if (this.waiters.size > 0) { + fiber.getFiberRef(currentScheduler).scheduleTask(() => { + const iter = this.waiters.values(); + let item = iter.next(); + while (item.done === false && this.free > 0) { + item.value(); + item = iter.next(); + } + }, fiber.getFiberRef(currentSchedulingPriority), fiber); + } + return succeed(this.free); } -}; -var memoizeThunk = (f) => { - let done7 = false; - let a; - return () => { - if (done7) { - return a; + updateTaken(f) { + return withFiberRuntime((fiber) => this.updateTakenUnsafe(fiber, f)); + } + resize = (permits) => asVoid(withFiberRuntime((fiber) => { + this.permits = permits; + if (this.free < 0) { + return void_; } - a = f(); - done7 = true; - return a; - }; -}; -var isNonEmpty6 = (x) => Array.isArray(x); -var isSingle = (x) => !Array.isArray(x); -var formatPathKey = (key) => `[${formatPropertyKey(key)}]`; -var formatPath = (path) => isNonEmpty6(path) ? path.map(formatPathKey).join("") : formatPathKey(path); + return this.updateTakenUnsafe(fiber, (taken) => taken); + })); + release = (n) => this.updateTaken((taken) => taken - n); + releaseAll = /* @__PURE__ */ this.updateTaken((_) => 0); + withPermits = (n) => (self) => uninterruptibleMask((restore) => flatMap7(restore(this.take(n)), (permits) => ensuring(restore(self), this.release(permits)))); + withPermitsIfAvailable = (n) => (self) => uninterruptibleMask((restore) => suspend(() => { + if (this.free < n) { + return succeedNone; + } + this.taken += n; + return ensuring(restore(asSome(self)), this.release(n)); + })); +} +var unsafeMakeSemaphore = (permits) => new Semaphore(permits); +var makeSemaphore = (permits) => sync(() => unsafeMakeSemaphore(permits)); -// node_modules/effect/dist/esm/internal/schema/errors.js -var getErrorMessage = (reason, details, path, ast) => { - let out = reason; - if (path && isNonEmptyReadonlyArray(path)) { - out += ` -at path: ${formatPath(path)}`; - } - if (details !== undefined) { - out += ` -details: ${details}`; +class Latch extends Class { + isOpen; + waiters = []; + scheduled = false; + constructor(isOpen) { + super(); + this.isOpen = isOpen; } - if (ast) { - out += ` -schema (${ast._tag}): ${ast}`; + commit() { + return this.await; } - return out; -}; -var getInvalidArgumentErrorMessage = (details) => getErrorMessage("Invalid Argument", details); -var getUnsupportedSchemaErrorMessage = (details, path, ast) => getErrorMessage("Unsupported schema", details, path, ast); -var getEquivalenceUnsupportedErrorMessage = (ast, path) => getUnsupportedSchemaErrorMessage("Cannot build an Equivalence", path, ast); -var getSchemaExtendErrorMessage = (x, y, path) => getErrorMessage("Unsupported schema or overlapping types", `cannot extend ${x} with ${y}`, path); -var getSchemaUnsupportedLiteralSpanErrorMessage = (ast) => getErrorMessage("Unsupported template literal span", undefined, undefined, ast); -var getASTUnsupportedSchemaErrorMessage = (ast) => getUnsupportedSchemaErrorMessage(undefined, undefined, ast); -var getASTUnsupportedKeySchemaErrorMessage = (ast) => getErrorMessage("Unsupported key schema", undefined, undefined, ast); -var getASTUnsupportedLiteralErrorMessage = (literal2) => getErrorMessage("Unsupported literal", `literal value: ${formatUnknown(literal2)}`); -var getASTDuplicateIndexSignatureErrorMessage = (type) => getErrorMessage("Duplicate index signature", `${type} index signature`); -var getASTIndexSignatureParameterErrorMessage = /* @__PURE__ */ getErrorMessage("Unsupported index signature parameter", "An index signature parameter type must be `string`, `symbol`, a template literal type or a refinement of the previous types"); -var getASTRequiredElementFollowinAnOptionalElementErrorMessage = /* @__PURE__ */ getErrorMessage("Invalid element", "A required element cannot follow an optional element. ts(1257)"); -var getASTDuplicatePropertySignatureTransformationErrorMessage = (key) => getErrorMessage("Duplicate property signature transformation", `Duplicate key ${formatUnknown(key)}`); -var getASTUnsupportedRenameSchemaErrorMessage = (ast) => getUnsupportedSchemaErrorMessage(undefined, undefined, ast); -var getASTDuplicatePropertySignatureErrorMessage = (key) => getErrorMessage("Duplicate property signature", `Duplicate key ${formatUnknown(key)}`); - -// node_modules/effect/dist/esm/internal/schema/schemaId.js -var DateFromSelfSchemaId = /* @__PURE__ */ Symbol.for("effect/SchemaId/DateFromSelf"); -var GreaterThanSchemaId = /* @__PURE__ */ Symbol.for("effect/SchemaId/GreaterThan"); -var GreaterThanOrEqualToSchemaId = /* @__PURE__ */ Symbol.for("effect/SchemaId/GreaterThanOrEqualTo"); -var LessThanSchemaId = /* @__PURE__ */ Symbol.for("effect/SchemaId/LessThan"); -var LessThanOrEqualToSchemaId = /* @__PURE__ */ Symbol.for("effect/SchemaId/LessThanOrEqualTo"); -var IntSchemaId = /* @__PURE__ */ Symbol.for("effect/SchemaId/Int"); -var NonNaNSchemaId = /* @__PURE__ */ Symbol.for("effect/SchemaId/NonNaN"); -var FiniteSchemaId = /* @__PURE__ */ Symbol.for("effect/SchemaId/Finite"); -var JsonNumberSchemaId = /* @__PURE__ */ Symbol.for("effect/SchemaId/JsonNumber"); -var BetweenSchemaId = /* @__PURE__ */ Symbol.for("effect/SchemaId/Between"); -var GreaterThanBigintSchemaId = /* @__PURE__ */ Symbol.for("effect/SchemaId/GreaterThanBigint"); -var GreaterThanOrEqualToBigIntSchemaId = /* @__PURE__ */ Symbol.for("effect/SchemaId/GreaterThanOrEqualToBigint"); -var LessThanBigIntSchemaId = /* @__PURE__ */ Symbol.for("effect/SchemaId/LessThanBigint"); -var LessThanOrEqualToBigIntSchemaId = /* @__PURE__ */ Symbol.for("effect/SchemaId/LessThanOrEqualToBigint"); -var BetweenBigintSchemaId = /* @__PURE__ */ Symbol.for("effect/SchemaId/BetweenBigint"); -var MinLengthSchemaId = /* @__PURE__ */ Symbol.for("effect/SchemaId/MinLength"); -var MaxLengthSchemaId = /* @__PURE__ */ Symbol.for("effect/SchemaId/MaxLength"); -var LengthSchemaId = /* @__PURE__ */ Symbol.for("effect/SchemaId/Length"); -var MinItemsSchemaId = /* @__PURE__ */ Symbol.for("effect/SchemaId/MinItems"); -var MaxItemsSchemaId = /* @__PURE__ */ Symbol.for("effect/SchemaId/MaxItems"); -var ItemsCountSchemaId = /* @__PURE__ */ Symbol.for("effect/SchemaId/ItemsCount"); - -// node_modules/effect/dist/esm/SchemaAST.js -var TypeConstructorAnnotationId = /* @__PURE__ */ Symbol.for("effect/annotation/TypeConstructor"); -var BrandAnnotationId = /* @__PURE__ */ Symbol.for("effect/annotation/Brand"); -var SchemaIdAnnotationId = /* @__PURE__ */ Symbol.for("effect/annotation/SchemaId"); -var MessageAnnotationId = /* @__PURE__ */ Symbol.for("effect/annotation/Message"); -var MissingMessageAnnotationId = /* @__PURE__ */ Symbol.for("effect/annotation/MissingMessage"); -var IdentifierAnnotationId = /* @__PURE__ */ Symbol.for("effect/annotation/Identifier"); -var TitleAnnotationId = /* @__PURE__ */ Symbol.for("effect/annotation/Title"); -var AutoTitleAnnotationId = /* @__PURE__ */ Symbol.for("effect/annotation/AutoTitle"); -var DescriptionAnnotationId = /* @__PURE__ */ Symbol.for("effect/annotation/Description"); -var ExamplesAnnotationId = /* @__PURE__ */ Symbol.for("effect/annotation/Examples"); -var DefaultAnnotationId = /* @__PURE__ */ Symbol.for("effect/annotation/Default"); -var JSONSchemaAnnotationId = /* @__PURE__ */ Symbol.for("effect/annotation/JSONSchema"); -var ArbitraryAnnotationId = /* @__PURE__ */ Symbol.for("effect/annotation/Arbitrary"); -var PrettyAnnotationId = /* @__PURE__ */ Symbol.for("effect/annotation/Pretty"); -var EquivalenceAnnotationId = /* @__PURE__ */ Symbol.for("effect/annotation/Equivalence"); -var DocumentationAnnotationId = /* @__PURE__ */ Symbol.for("effect/annotation/Documentation"); -var ConcurrencyAnnotationId = /* @__PURE__ */ Symbol.for("effect/annotation/Concurrency"); -var BatchingAnnotationId = /* @__PURE__ */ Symbol.for("effect/annotation/Batching"); -var ParseIssueTitleAnnotationId = /* @__PURE__ */ Symbol.for("effect/annotation/ParseIssueTitle"); -var ParseOptionsAnnotationId = /* @__PURE__ */ Symbol.for("effect/annotation/ParseOptions"); -var DecodingFallbackAnnotationId = /* @__PURE__ */ Symbol.for("effect/annotation/DecodingFallback"); -var SurrogateAnnotationId = /* @__PURE__ */ Symbol.for("effect/annotation/Surrogate"); -var StableFilterAnnotationId = /* @__PURE__ */ Symbol.for("effect/annotation/StableFilter"); -var getAnnotation = /* @__PURE__ */ dual(2, (annotated, key) => Object.prototype.hasOwnProperty.call(annotated.annotations, key) ? some2(annotated.annotations[key]) : none2()); -var getBrandAnnotation = /* @__PURE__ */ getAnnotation(BrandAnnotationId); -var getMessageAnnotation = /* @__PURE__ */ getAnnotation(MessageAnnotationId); -var getMissingMessageAnnotation = /* @__PURE__ */ getAnnotation(MissingMessageAnnotationId); -var getTitleAnnotation = /* @__PURE__ */ getAnnotation(TitleAnnotationId); -var getAutoTitleAnnotation = /* @__PURE__ */ getAnnotation(AutoTitleAnnotationId); -var getIdentifierAnnotation = /* @__PURE__ */ getAnnotation(IdentifierAnnotationId); -var getDescriptionAnnotation = /* @__PURE__ */ getAnnotation(DescriptionAnnotationId); -var getConcurrencyAnnotation = /* @__PURE__ */ getAnnotation(ConcurrencyAnnotationId); -var getBatchingAnnotation = /* @__PURE__ */ getAnnotation(BatchingAnnotationId); -var getParseIssueTitleAnnotation = /* @__PURE__ */ getAnnotation(ParseIssueTitleAnnotationId); -var getParseOptionsAnnotation = /* @__PURE__ */ getAnnotation(ParseOptionsAnnotationId); -var getDecodingFallbackAnnotation = /* @__PURE__ */ getAnnotation(DecodingFallbackAnnotationId); -var getSurrogateAnnotation = /* @__PURE__ */ getAnnotation(SurrogateAnnotationId); -var getStableFilterAnnotation = /* @__PURE__ */ getAnnotation(StableFilterAnnotationId); -var hasStableFilter = (annotated) => exists(getStableFilterAnnotation(annotated), (b) => b === true); -var JSONIdentifierAnnotationId = /* @__PURE__ */ Symbol.for("effect/annotation/JSONIdentifier"); -var getJSONIdentifierAnnotation = /* @__PURE__ */ getAnnotation(JSONIdentifierAnnotationId); -var getJSONIdentifier = (annotated) => orElse(getJSONIdentifierAnnotation(annotated), () => getIdentifierAnnotation(annotated)); -var ParseJsonSchemaId = /* @__PURE__ */ Symbol.for("effect/schema/ParseJson"); - -class Declaration { - typeParameters; - decodeUnknown; - encodeUnknown; - annotations; - _tag = "Declaration"; - constructor(typeParameters, decodeUnknown, encodeUnknown, annotations = {}) { - this.typeParameters = typeParameters; - this.decodeUnknown = decodeUnknown; - this.encodeUnknown = encodeUnknown; - this.annotations = annotations; + unsafeSchedule(fiber) { + if (this.scheduled || this.waiters.length === 0) { + return void_; + } + this.scheduled = true; + fiber.currentScheduler.scheduleTask(this.flushWaiters, fiber.getFiberRef(currentSchedulingPriority), fiber); + return void_; } - toString() { - return getOrElse(getExpected(this), () => ""); + flushWaiters = () => { + this.scheduled = false; + const waiters = this.waiters; + this.waiters = []; + for (let i = 0;i < waiters.length; i++) { + waiters[i](exitVoid); + } + }; + open = /* @__PURE__ */ withFiberRuntime((fiber) => { + if (this.isOpen) { + return void_; + } + this.isOpen = true; + return this.unsafeSchedule(fiber); + }); + unsafeOpen() { + if (this.isOpen) + return; + this.isOpen = true; + this.flushWaiters(); } - toJSON() { - return { - _tag: this._tag, - typeParameters: this.typeParameters.map((ast) => ast.toJSON()), - annotations: toJSONAnnotations(this.annotations) - }; + release = /* @__PURE__ */ withFiberRuntime((fiber) => { + if (this.isOpen) { + return void_; + } + return this.unsafeSchedule(fiber); + }); + await = /* @__PURE__ */ asyncInterrupt((resume2) => { + if (this.isOpen) { + return resume2(void_); + } + this.waiters.push(resume2); + return sync(() => { + const index = this.waiters.indexOf(resume2); + if (index !== -1) { + this.waiters.splice(index, 1); + } + }); + }); + unsafeClose() { + this.isOpen = false; } + close = /* @__PURE__ */ sync(() => { + this.isOpen = false; + }); + whenOpen = (self) => { + return zipRight(this.await, self); + }; } -var createASTGuard = (tag) => (ast) => ast._tag === tag; -class Literal { - literal; - annotations; - _tag = "Literal"; - constructor(literal2, annotations = {}) { - this.literal = literal2; - this.annotations = annotations; +var unsafeMakeLatch = (open) => new Latch(open ?? false); +var makeLatch = (open) => sync(() => unsafeMakeLatch(open)); +var awaitAllChildren = (self) => ensuringChildren(self, fiberAwaitAll); +var cached2 = /* @__PURE__ */ dual(2, (self, timeToLive) => map9(cachedInvalidateWithTTL(self, timeToLive), (tuple) => tuple[0])); +var cachedInvalidateWithTTL = /* @__PURE__ */ dual(2, (self, timeToLive) => { + const duration = decode(timeToLive); + return flatMap7(context(), (env) => map9(makeSynchronized(none2()), (cache) => [provideContext(getCachedValue(self, duration, cache), env), invalidateCache(cache)])); +}); +var computeCachedValue = (self, timeToLive, start3) => { + const timeToLiveMillis = toMillis(decode(timeToLive)); + return pipe(deferredMake(), tap((deferred) => intoDeferred(self, deferred)), map9((deferred) => some2([start3 + timeToLiveMillis, deferred]))); +}; +var getCachedValue = (self, timeToLive, cache) => uninterruptibleMask((restore) => pipe(clockWith3((clock2) => clock2.currentTimeMillis), flatMap7((time) => updateSomeAndGetEffectSynchronized(cache, (option2) => { + switch (option2._tag) { + case "None": { + return some2(computeCachedValue(self, timeToLive, time)); + } + case "Some": { + const [end3] = option2.value; + return end3 - time <= 0 ? some2(computeCachedValue(self, timeToLive, time)) : none2(); + } + } +})), flatMap7((option2) => isNone2(option2) ? dieMessage("BUG: Effect.cachedInvalidate - please report an issue at https://github.com/Effect-TS/effect/issues") : restore(deferredAwait(option2.value[1]))))); +var invalidateCache = (cache) => set5(cache, none2()); +var ensuringChild = /* @__PURE__ */ dual(2, (self, f) => ensuringChildren(self, (children) => f(fiberAll(children)))); +var ensuringChildren = /* @__PURE__ */ dual(2, (self, children) => flatMap7(track, (supervisor) => pipe(supervised(self, supervisor), ensuring(flatMap7(supervisor.value, children))))); +var forkAll = /* @__PURE__ */ dual((args2) => isIterable(args2[0]), (effects, options) => options?.discard ? forEachSequentialDiscard(effects, fork) : map9(forEachSequential(effects, fork), fiberAll)); +var forkIn = /* @__PURE__ */ dual(2, (self, scope2) => withFiberRuntime((parent, parentStatus) => { + const scopeImpl = scope2; + const fiber = unsafeFork(self, parent, parentStatus.runtimeFlags, globalScope); + if (scopeImpl.state._tag === "Open") { + const finalizer = () => fiberIdWith((fiberId2) => equals(fiberId2, fiber.id()) ? void_ : asVoid(interruptFiber(fiber))); + const key = {}; + scopeImpl.state.finalizers.set(key, finalizer); + fiber.addObserver(() => { + if (scopeImpl.state._tag === "Closed") + return; + scopeImpl.state.finalizers.delete(key); + }); + } else { + fiber.unsafeInterruptAsFork(parent.id()); } - toString() { - return getOrElse(getExpected(this), () => formatUnknown(this.literal)); + return succeed(fiber); +})); +var forkScoped = (self) => scopeWith((scope2) => forkIn(self, scope2)); +var fromFiber = (fiber) => join2(fiber); +var fromFiberEffect = (fiber) => suspend(() => flatMap7(fiber, join2)); +var memoKeySymbol = /* @__PURE__ */ Symbol.for("effect/Effect/memoizeFunction.key"); + +class Key { + a; + eq; + [memoKeySymbol] = memoKeySymbol; + constructor(a, eq) { + this.a = a; + this.eq = eq; } - toJSON() { - return { - _tag: this._tag, - literal: isBigInt(this.literal) ? String(this.literal) : this.literal, - annotations: toJSONAnnotations(this.annotations) - }; + [symbol2](that) { + if (hasProperty(that, memoKeySymbol)) { + if (this.eq) { + return this.eq(this.a, that.a); + } else { + return equals(this.a, that.a); + } + } + return false; + } + [symbol]() { + return this.eq ? 0 : cached(this, hash(this.a)); } } -var isLiteral = /* @__PURE__ */ createASTGuard("Literal"); -var $null = /* @__PURE__ */ new Literal(null); -class UniqueSymbol { - symbol; - annotations; - _tag = "UniqueSymbol"; - constructor(symbol3, annotations = {}) { - this.symbol = symbol3; - this.annotations = annotations; +var cachedFunction = (f, eq) => { + return pipe(sync(() => empty17()), flatMap7(makeSynchronized), map9((ref) => (a) => pipe(ref.modifyEffect((map10) => { + const result = pipe(map10, get8(new Key(a, eq))); + if (isNone2(result)) { + return pipe(deferredMake(), tap((deferred) => pipe(diffFiberRefs(f(a)), intoDeferred(deferred), fork)), map9((deferred) => [deferred, pipe(map10, set4(new Key(a, eq), deferred))])); + } + return succeed([result.value, map10]); + }), flatMap7(deferredAwait), flatMap7(([patch9, b]) => pipe(patchFiberRefs(patch9), as(b)))))); +}; +var raceFirst = /* @__PURE__ */ dual(2, (self, that) => pipe(exit(self), race(exit(that)), (effect) => flatten5(effect))); +var supervised = /* @__PURE__ */ dual(2, (self, supervisor) => { + const supervise = fiberRefLocallyWith(currentSupervisor, (s) => s.zip(supervisor)); + return supervise(self); +}); +var timeout = /* @__PURE__ */ dual(2, (self, duration) => timeoutFail(self, { + onTimeout: () => timeoutExceptionFromDuration(duration), + duration +})); +var timeoutFail = /* @__PURE__ */ dual(2, (self, { + duration, + onTimeout +}) => flatten5(timeoutTo(self, { + onTimeout: () => failSync(onTimeout), + onSuccess: succeed, + duration +}))); +var timeoutFailCause = /* @__PURE__ */ dual(2, (self, { + duration, + onTimeout +}) => flatten5(timeoutTo(self, { + onTimeout: () => failCauseSync(onTimeout), + onSuccess: succeed, + duration +}))); +var timeoutOption = /* @__PURE__ */ dual(2, (self, duration) => timeoutTo(self, { + duration, + onSuccess: some2, + onTimeout: none2 +})); +var timeoutTo = /* @__PURE__ */ dual(2, (self, { + duration, + onSuccess, + onTimeout +}) => fiberIdWith((parentFiberId) => uninterruptibleMask((restore) => raceFibersWith(restore(self), interruptible2(sleep3(duration)), { + onSelfWin: (winner, loser) => flatMap7(winner.await, (exit2) => { + if (exit2._tag === "Success") { + return flatMap7(winner.inheritAll, () => as(interruptAsFiber(loser, parentFiberId), onSuccess(exit2.value))); + } else { + return flatMap7(interruptAsFiber(loser, parentFiberId), () => exitFailCause(exit2.cause)); + } + }), + onOtherWin: (winner, loser) => flatMap7(winner.await, (exit2) => { + if (exit2._tag === "Success") { + return flatMap7(winner.inheritAll, () => as(interruptAsFiber(loser, parentFiberId), onTimeout())); + } else { + return flatMap7(interruptAsFiber(loser, parentFiberId), () => exitFailCause(exit2.cause)); + } + }), + otherScope: globalScope +})))); +var SynchronizedSymbolKey = "effect/Ref/SynchronizedRef"; +var SynchronizedTypeId = /* @__PURE__ */ Symbol.for(SynchronizedSymbolKey); +var synchronizedVariance = { + _A: (_) => _ +}; + +class SynchronizedImpl extends Class { + ref; + withLock; + [SynchronizedTypeId] = synchronizedVariance; + [RefTypeId] = refVariance; + [TypeId13] = TypeId13; + constructor(ref, withLock) { + super(); + this.ref = ref; + this.withLock = withLock; + this.get = get11(this.ref); } - toString() { - return getOrElse(getExpected(this), () => formatUnknown(this.symbol)); + get; + commit() { + return this.get; } - toJSON() { - return { - _tag: this._tag, - symbol: String(this.symbol), - annotations: toJSONAnnotations(this.annotations) - }; + modify(f) { + return this.modifyEffect((a) => succeed(f(a))); + } + modifyEffect(f) { + return this.withLock(pipe(flatMap7(get11(this.ref), f), flatMap7(([b, a]) => as(set5(this.ref, a), b)))); } } -var isUniqueSymbol = /* @__PURE__ */ createASTGuard("UniqueSymbol"); +var makeSynchronized = (value) => sync(() => unsafeMakeSynchronized(value)); +var unsafeMakeSynchronized = (value) => { + const ref = unsafeMake5(value); + const sem = unsafeMakeSemaphore(1); + return new SynchronizedImpl(ref, sem.withPermits(1)); +}; +var updateSomeAndGetEffectSynchronized = /* @__PURE__ */ dual(2, (self, pf) => self.modifyEffect((value) => { + const result = pf(value); + switch (result._tag) { + case "None": { + return succeed([value, value]); + } + case "Some": { + return map9(result.value, (a) => [a, a]); + } + } +})); +var bindAll = /* @__PURE__ */ dual((args2) => isEffect(args2[0]), (self, f, options) => flatMap7(self, (a) => all2(f(a), options).pipe(map9((record2) => Object.assign({}, a, record2))))); -class UndefinedKeyword { - annotations; - _tag = "UndefinedKeyword"; - constructor(annotations = {}) { - this.annotations = annotations; +// node_modules/effect/dist/esm/internal/managedRuntime/circular.js +var TypeId16 = /* @__PURE__ */ Symbol.for("effect/ManagedRuntime"); + +// node_modules/effect/dist/esm/internal/opCodes/layer.js +var OP_FRESH = "Fresh"; +var OP_FROM_EFFECT = "FromEffect"; +var OP_SCOPED = "Scoped"; +var OP_SUSPEND = "Suspend"; +var OP_PROVIDE = "Provide"; +var OP_PROVIDE_MERGE = "ProvideMerge"; +var OP_MERGE_ALL = "MergeAll"; + +// node_modules/effect/dist/esm/Fiber.js +var interruptAs = interruptAsFiber; + +// node_modules/effect/dist/esm/internal/runtime.js +var makeDual = (f) => function() { + if (arguments.length === 1) { + const runtime3 = arguments[0]; + return (effect, ...args2) => f(runtime3, effect, ...args2); } - toString() { - return formatKeyword(this); + return f.apply(this, arguments); +}; +var unsafeFork2 = /* @__PURE__ */ makeDual((runtime3, self, options) => { + const fiberId2 = unsafeMake2(); + const fiberRefUpdates = [[currentContext, [[fiberId2, runtime3.context]]]]; + if (options?.scheduler) { + fiberRefUpdates.push([currentScheduler, [[fiberId2, options.scheduler]]]); } - toJSON() { - return { - _tag: this._tag, - annotations: toJSONAnnotations(this.annotations) - }; + let fiberRefs3 = updateManyAs2(runtime3.fiberRefs, { + entries: fiberRefUpdates, + forkAs: fiberId2 + }); + if (options?.updateRefs) { + fiberRefs3 = options.updateRefs(fiberRefs3, fiberId2); } -} -var undefinedKeyword = /* @__PURE__ */ new UndefinedKeyword({ - [TitleAnnotationId]: "undefined" -}); -class VoidKeyword { - annotations; - _tag = "VoidKeyword"; - constructor(annotations = {}) { - this.annotations = annotations; + const fiberRuntime = new FiberRuntime(fiberId2, fiberRefs3, runtime3.runtimeFlags); + let effect = self; + if (options?.scope) { + effect = flatMap7(fork2(options.scope, sequential2), (closeableScope) => zipRight(scopeAddFinalizer(closeableScope, fiberIdWith((id) => equals(id, fiberRuntime.id()) ? void_ : interruptAsFiber(fiberRuntime, id))), onExit(self, (exit2) => close(closeableScope, exit2)))); } - toString() { - return formatKeyword(this); + const supervisor = fiberRuntime.currentSupervisor; + if (supervisor !== none8) { + supervisor.onStart(runtime3.context, effect, none2(), fiberRuntime); + fiberRuntime.addObserver((exit2) => supervisor.onEnd(exit2, fiberRuntime)); } - toJSON() { - return { - _tag: this._tag, - annotations: toJSONAnnotations(this.annotations) - }; + globalScope.add(runtime3.runtimeFlags, fiberRuntime); + if (options?.immediate === false) { + fiberRuntime.resume(effect); + } else { + fiberRuntime.start(effect); } -} -var voidKeyword = /* @__PURE__ */ new VoidKeyword({ - [TitleAnnotationId]: "void" + return fiberRuntime; }); -class NeverKeyword { - annotations; - _tag = "NeverKeyword"; - constructor(annotations = {}) { - this.annotations = annotations; +var unsafeRunCallback = /* @__PURE__ */ makeDual((runtime3, effect, options = {}) => { + const fiberRuntime = unsafeFork2(runtime3, effect, options); + if (options.onExit) { + fiberRuntime.addObserver((exit2) => { + options.onExit(exit2); + }); } - toString() { - return formatKeyword(this); + return (id, cancelOptions) => unsafeRunCallback(runtime3)(pipe(fiberRuntime, interruptAs(id ?? none4)), { + ...cancelOptions, + onExit: cancelOptions?.onExit ? (exit2) => cancelOptions.onExit(flatten6(exit2)) : undefined + }); +}); +var unsafeRunSync = /* @__PURE__ */ makeDual((runtime3, effect) => { + const result = unsafeRunSyncExit(runtime3)(effect); + if (result._tag === "Failure") { + throw fiberFailure(result.effect_instruction_i0); } - toJSON() { - return { - _tag: this._tag, - annotations: toJSONAnnotations(this.annotations) - }; + return result.effect_instruction_i0; +}); + +class AsyncFiberExceptionImpl extends Error { + fiber; + _tag = "AsyncFiberException"; + constructor(fiber) { + super(`Fiber #${fiber.id().id} cannot be resolved synchronously. This is caused by using runSync on an effect that performs async work`); + this.fiber = fiber; + this.name = this._tag; + this.stack = this.message; } } -var neverKeyword = /* @__PURE__ */ new NeverKeyword({ - [TitleAnnotationId]: "never" -}); -var isNeverKeyword = /* @__PURE__ */ createASTGuard("NeverKeyword"); +var asyncFiberException = (fiber) => { + const limit = Error.stackTraceLimit; + Error.stackTraceLimit = 0; + const error = new AsyncFiberExceptionImpl(fiber); + Error.stackTraceLimit = limit; + return error; +}; +var FiberFailureId = /* @__PURE__ */ Symbol.for("effect/Runtime/FiberFailure"); +var FiberFailureCauseId = /* @__PURE__ */ Symbol.for("effect/Runtime/FiberFailure/Cause"); -class UnknownKeyword { - annotations; - _tag = "UnknownKeyword"; - constructor(annotations = {}) { - this.annotations = annotations; - } - toString() { - return formatKeyword(this); +class FiberFailureImpl extends Error { + [FiberFailureId]; + [FiberFailureCauseId]; + constructor(cause2) { + const head4 = prettyErrors(cause2)[0]; + super(head4?.message || "An error has occurred"); + this[FiberFailureId] = FiberFailureId; + this[FiberFailureCauseId] = cause2; + this.name = head4 ? `(FiberFailure) ${head4.name}` : "FiberFailure"; + if (head4?.stack) { + this.stack = head4.stack; + } } toJSON() { return { - _tag: this._tag, - annotations: toJSONAnnotations(this.annotations) + _id: "FiberFailure", + cause: this[FiberFailureCauseId].toJSON() }; } -} -var unknownKeyword = /* @__PURE__ */ new UnknownKeyword({ - [TitleAnnotationId]: "unknown" -}); -class AnyKeyword { - annotations; - _tag = "AnyKeyword"; - constructor(annotations = {}) { - this.annotations = annotations; - } toString() { - return formatKeyword(this); + return "(FiberFailure) " + pretty(this[FiberFailureCauseId], { + renderErrorCause: true + }); } - toJSON() { - return { - _tag: this._tag, - annotations: toJSONAnnotations(this.annotations) - }; + [NodeInspectSymbol]() { + return this.toString(); } } -var anyKeyword = /* @__PURE__ */ new AnyKeyword({ - [TitleAnnotationId]: "any" -}); -class StringKeyword { - annotations; - _tag = "StringKeyword"; - constructor(annotations = {}) { - this.annotations = annotations; +var fiberFailure = (cause2) => { + const limit = Error.stackTraceLimit; + Error.stackTraceLimit = 0; + const error = new FiberFailureImpl(cause2); + Error.stackTraceLimit = limit; + return error; +}; +var fastPath = (effect) => { + const op = effect; + switch (op._op) { + case "Failure": + case "Success": { + return op; + } + case "Left": { + return exitFail(op.left); + } + case "Right": { + return exitSucceed(op.right); + } + case "Some": { + return exitSucceed(op.value); + } + case "None": { + return exitFail(new NoSuchElementException); + } } - toString() { - return formatKeyword(this); +}; +var unsafeRunSyncExit = /* @__PURE__ */ makeDual((runtime3, effect) => { + const op = fastPath(effect); + if (op) { + return op; } - toJSON() { - return { - _tag: this._tag, - annotations: toJSONAnnotations(this.annotations) - }; + const scheduler = new SyncScheduler; + const fiberRuntime = unsafeFork2(runtime3)(effect, { + scheduler + }); + scheduler.flush(); + const result = fiberRuntime.unsafePoll(); + if (result) { + return result; } -} -var stringKeyword = /* @__PURE__ */ new StringKeyword({ - [TitleAnnotationId]: "string", - [DescriptionAnnotationId]: "a string" + return exitDie(capture(asyncFiberException(fiberRuntime), currentSpanFromFiber(fiberRuntime))); }); -var isStringKeyword = /* @__PURE__ */ createASTGuard("StringKeyword"); - -class NumberKeyword { - annotations; - _tag = "NumberKeyword"; - constructor(annotations = {}) { - this.annotations = annotations; +var unsafeRunPromise = /* @__PURE__ */ makeDual((runtime3, effect, options) => unsafeRunPromiseExit(runtime3, effect, options).then((result) => { + switch (result._tag) { + case OP_SUCCESS: { + return result.effect_instruction_i0; + } + case OP_FAILURE: { + throw fiberFailure(result.effect_instruction_i0); + } } - toString() { - return formatKeyword(this); +})); +var unsafeRunPromiseExit = /* @__PURE__ */ makeDual((runtime3, effect, options) => new Promise((resolve) => { + const op = fastPath(effect); + if (op) { + resolve(op); } - toJSON() { - return { - _tag: this._tag, - annotations: toJSONAnnotations(this.annotations) - }; + const fiber = unsafeFork2(runtime3)(effect); + fiber.addObserver((exit2) => { + resolve(exit2); + }); + if (options?.signal !== undefined) { + if (options.signal.aborted) { + fiber.unsafeInterruptAsFork(fiber.id()); + } else { + options.signal.addEventListener("abort", () => { + fiber.unsafeInterruptAsFork(fiber.id()); + }, { + once: true + }); + } } -} -var numberKeyword = /* @__PURE__ */ new NumberKeyword({ - [TitleAnnotationId]: "number", - [DescriptionAnnotationId]: "a number" -}); -var isNumberKeyword = /* @__PURE__ */ createASTGuard("NumberKeyword"); +})); -class BooleanKeyword { - annotations; - _tag = "BooleanKeyword"; - constructor(annotations = {}) { - this.annotations = annotations; - } - toString() { - return formatKeyword(this); +class RuntimeImpl { + context; + runtimeFlags; + fiberRefs; + constructor(context2, runtimeFlags2, fiberRefs3) { + this.context = context2; + this.runtimeFlags = runtimeFlags2; + this.fiberRefs = fiberRefs3; } - toJSON() { - return { - _tag: this._tag, - annotations: toJSONAnnotations(this.annotations) - }; + pipe() { + return pipeArguments(this, arguments); } } -var booleanKeyword = /* @__PURE__ */ new BooleanKeyword({ - [TitleAnnotationId]: "boolean", - [DescriptionAnnotationId]: "a boolean" +var make39 = (options) => new RuntimeImpl(options.context, options.runtimeFlags, options.fiberRefs); +var runtime3 = () => withFiberRuntime((state, status) => succeed(new RuntimeImpl(state.getFiberRef(currentContext), status.runtimeFlags, state.getFiberRefs()))); +var defaultRuntimeFlags = /* @__PURE__ */ make17(Interruption, CooperativeYielding, RuntimeMetrics); +var defaultRuntime = /* @__PURE__ */ make39({ + context: /* @__PURE__ */ empty3(), + runtimeFlags: defaultRuntimeFlags, + fiberRefs: /* @__PURE__ */ empty21() }); -var isBooleanKeyword = /* @__PURE__ */ createASTGuard("BooleanKeyword"); - -class BigIntKeyword { - annotations; - _tag = "BigIntKeyword"; - constructor(annotations = {}) { - this.annotations = annotations; - } - toString() { - return formatKeyword(this); - } - toJSON() { - return { - _tag: this._tag, - annotations: toJSONAnnotations(this.annotations) - }; - } -} -var bigIntKeyword = /* @__PURE__ */ new BigIntKeyword({ - [TitleAnnotationId]: "bigint", - [DescriptionAnnotationId]: "a bigint" +var unsafeRunEffect = /* @__PURE__ */ unsafeRunCallback(defaultRuntime); +var unsafeForkEffect = /* @__PURE__ */ unsafeFork2(defaultRuntime); +var unsafeRunPromiseEffect = /* @__PURE__ */ unsafeRunPromise(defaultRuntime); +var unsafeRunPromiseExitEffect = /* @__PURE__ */ unsafeRunPromiseExit(defaultRuntime); +var unsafeRunSyncEffect = /* @__PURE__ */ unsafeRunSync(defaultRuntime); +var unsafeRunSyncExitEffect = /* @__PURE__ */ unsafeRunSyncExit(defaultRuntime); +var asyncEffect = (register) => suspend(() => { + let cleanup = undefined; + return flatMap7(deferredMake(), (deferred) => flatMap7(runtime3(), (runtime4) => uninterruptibleMask((restore) => zipRight(fork(restore(matchCauseEffect(register((cb) => unsafeRunCallback(runtime4)(intoDeferred(cb, deferred))), { + onFailure: (cause2) => deferredFailCause(deferred, cause2), + onSuccess: (cleanup_) => { + cleanup = cleanup_; + return void_; + } + }))), restore(onInterrupt(deferredAwait(deferred), () => cleanup ?? void_)))))); }); -class SymbolKeyword { - annotations; - _tag = "SymbolKeyword"; - constructor(annotations = {}) { - this.annotations = annotations; - } - toString() { - return formatKeyword(this); - } - toJSON() { - return { - _tag: this._tag, - annotations: toJSONAnnotations(this.annotations) - }; + +// node_modules/effect/dist/esm/internal/synchronizedRef.js +var modifyEffect = /* @__PURE__ */ dual(2, (self, f) => self.modifyEffect(f)); + +// node_modules/effect/dist/esm/internal/layer.js +var LayerSymbolKey = "effect/Layer"; +var LayerTypeId = /* @__PURE__ */ Symbol.for(LayerSymbolKey); +var layerVariance = { + _RIn: (_) => _, + _E: (_) => _, + _ROut: (_) => _ +}; +var proto3 = { + [LayerTypeId]: layerVariance, + pipe() { + return pipeArguments(this, arguments); } -} -var symbolKeyword = /* @__PURE__ */ new SymbolKeyword({ - [TitleAnnotationId]: "symbol", - [DescriptionAnnotationId]: "a symbol" +}; +var MemoMapTypeIdKey = "effect/Layer/MemoMap"; +var MemoMapTypeId = /* @__PURE__ */ Symbol.for(MemoMapTypeIdKey); +var CurrentMemoMap = /* @__PURE__ */ Reference2()("effect/Layer/CurrentMemoMap", { + defaultValue: () => unsafeMakeMemoMap() }); -var isSymbolKeyword = /* @__PURE__ */ createASTGuard("SymbolKeyword"); +var isLayer = (u) => hasProperty(u, LayerTypeId); +var isFresh = (self) => { + return self._op_layer === OP_FRESH; +}; -class ObjectKeyword { - annotations; - _tag = "ObjectKeyword"; - constructor(annotations = {}) { - this.annotations = annotations; - } - toString() { - return formatKeyword(this); +class MemoMapImpl { + ref; + [MemoMapTypeId]; + constructor(ref) { + this.ref = ref; + this[MemoMapTypeId] = MemoMapTypeId; } - toJSON() { - return { - _tag: this._tag, - annotations: toJSONAnnotations(this.annotations) - }; + getOrElseMemoize(layer, scope2) { + return pipe(modifyEffect(this.ref, (map10) => { + const inMap = map10.get(layer); + if (inMap !== undefined) { + const [acquire, release] = inMap; + const cached3 = pipe(acquire, flatMap7(([patch9, b]) => pipe(patchFiberRefs(patch9), as(b))), onExit(exitMatch({ + onFailure: () => void_, + onSuccess: () => scopeAddFinalizerExit(scope2, release) + }))); + return succeed([cached3, map10]); + } + return pipe(make27(0), flatMap7((observers) => pipe(deferredMake(), flatMap7((deferred) => pipe(make27(() => void_), map9((finalizerRef) => { + const resource = uninterruptibleMask((restore) => pipe(scopeMake(), flatMap7((innerScope) => pipe(restore(flatMap7(makeBuilder(layer, innerScope, true), (f) => diffFiberRefs(f(this)))), exit, flatMap7((exit2) => { + switch (exit2._tag) { + case OP_FAILURE: { + return pipe(deferredFailCause(deferred, exit2.effect_instruction_i0), zipRight(scopeClose(innerScope, exit2)), zipRight(failCause(exit2.effect_instruction_i0))); + } + case OP_SUCCESS: { + return pipe(set5(finalizerRef, (exit3) => pipe(scopeClose(innerScope, exit3), whenEffect(modify3(observers, (n) => [n === 1, n - 1])), asVoid)), zipRight(update2(observers, (n) => n + 1)), zipRight(scopeAddFinalizerExit(scope2, (exit3) => pipe(sync(() => map10.delete(layer)), zipRight(get11(finalizerRef)), flatMap7((finalizer) => finalizer(exit3))))), zipRight(deferredSucceed(deferred, exit2.effect_instruction_i0)), as(exit2.effect_instruction_i0[1])); + } + } + }))))); + const memoized = [pipe(deferredAwait(deferred), onExit(exitMatchEffect({ + onFailure: () => void_, + onSuccess: () => update2(observers, (n) => n + 1) + }))), (exit2) => pipe(get11(finalizerRef), flatMap7((finalizer) => finalizer(exit2)))]; + return [resource, isFresh(layer) ? map10 : map10.set(layer, memoized)]; + })))))); + }), flatten5); } } -var objectKeyword = /* @__PURE__ */ new ObjectKeyword({ - [TitleAnnotationId]: "object", - [DescriptionAnnotationId]: "an object in the TypeScript meaning, i.e. the `object` type" -}); -class Enums { - enums; - annotations; - _tag = "Enums"; - constructor(enums, annotations = {}) { - this.enums = enums; - this.annotations = annotations; - } - toString() { - return getOrElse(getExpected(this), () => ` JSON.stringify(value2)).join(" | ")}>`); - } - toJSON() { - return { - _tag: this._tag, - enums: this.enums, - annotations: toJSONAnnotations(this.annotations) - }; +var makeMemoMap = /* @__PURE__ */ suspend(() => map9(makeSynchronized(new Map), (ref) => new MemoMapImpl(ref))); +var unsafeMakeMemoMap = () => new MemoMapImpl(unsafeMakeSynchronized(new Map)); +var buildWithScope = /* @__PURE__ */ dual(2, (self, scope2) => flatMap7(makeMemoMap, (memoMap) => buildWithMemoMap(self, memoMap, scope2))); +var buildWithMemoMap = /* @__PURE__ */ dual(3, (self, memoMap, scope2) => flatMap7(makeBuilder(self, scope2), (run) => provideService(run(memoMap), CurrentMemoMap, memoMap))); +var makeBuilder = (self, scope2, inMemoMap = false) => { + const op = self; + switch (op._op_layer) { + case "Locally": { + return sync(() => (memoMap) => op.f(memoMap.getOrElseMemoize(op.self, scope2))); + } + case "ExtendScope": { + return sync(() => (memoMap) => scopeWith((scope3) => memoMap.getOrElseMemoize(op.layer, scope3))); + } + case "Fold": { + return sync(() => (memoMap) => pipe(memoMap.getOrElseMemoize(op.layer, scope2), matchCauseEffect({ + onFailure: (cause2) => memoMap.getOrElseMemoize(op.failureK(cause2), scope2), + onSuccess: (value) => memoMap.getOrElseMemoize(op.successK(value), scope2) + }))); + } + case "Fresh": { + return sync(() => (_) => pipe(op.layer, buildWithScope(scope2))); + } + case "FromEffect": { + return inMemoMap ? sync(() => (_) => op.effect) : sync(() => (memoMap) => memoMap.getOrElseMemoize(self, scope2)); + } + case "Provide": { + return sync(() => (memoMap) => pipe(memoMap.getOrElseMemoize(op.first, scope2), flatMap7((env) => pipe(memoMap.getOrElseMemoize(op.second, scope2), provideContext(env))))); + } + case "Scoped": { + return inMemoMap ? sync(() => (_) => scopeExtend(op.effect, scope2)) : sync(() => (memoMap) => memoMap.getOrElseMemoize(self, scope2)); + } + case "Suspend": { + return sync(() => (memoMap) => memoMap.getOrElseMemoize(op.evaluate(), scope2)); + } + case "ProvideMerge": { + return sync(() => (memoMap) => pipe(memoMap.getOrElseMemoize(op.first, scope2), zipWith2(memoMap.getOrElseMemoize(op.second, scope2), op.zipK))); + } + case "ZipWith": { + return gen(function* () { + const parallelScope = yield* scopeFork(scope2, parallel2); + const firstScope = yield* scopeFork(parallelScope, sequential2); + const secondScope = yield* scopeFork(parallelScope, sequential2); + return (memoMap) => pipe(memoMap.getOrElseMemoize(op.first, firstScope), zipWithOptions(memoMap.getOrElseMemoize(op.second, secondScope), op.zipK, { + concurrent: true + })); + }); + } + case "MergeAll": { + const layers = op.layers; + return map9(scopeFork(scope2, parallel2), (parallelScope) => (memoMap) => { + const contexts = new Array(layers.length); + return map9(forEachConcurrentDiscard(layers, fnUntraced(function* (layer, i) { + const scope3 = yield* scopeFork(parallelScope, sequential2); + const context2 = yield* memoMap.getOrElseMemoize(layer, scope3); + contexts[i] = context2; + }), false, false), () => mergeAll2(...contexts)); + }); + } } +}; +var context2 = () => fromEffectContext(context()); +var fromEffect2 = /* @__PURE__ */ dual(2, (a, b) => { + const tagFirst = isTag2(a); + const tag = tagFirst ? a : b; + const effect = tagFirst ? b : a; + return fromEffectContext(map9(effect, (service) => make6(tag, service))); +}); +function fromEffectContext(effect) { + const fromEffect3 = Object.create(proto3); + fromEffect3._op_layer = OP_FROM_EFFECT; + fromEffect3.effect = effect; + return fromEffect3; } -var isEnums = /* @__PURE__ */ createASTGuard("Enums"); -var isTemplateLiteralSpanType = (ast) => { - switch (ast._tag) { - case "Literal": - case "NumberKeyword": - case "StringKeyword": - case "TemplateLiteral": - return true; - case "Union": - return ast.types.every(isTemplateLiteralSpanType); - } - return false; +var mergeAll4 = (...layers) => { + const mergeAll5 = Object.create(proto3); + mergeAll5._op_layer = OP_MERGE_ALL; + mergeAll5.layers = layers; + return mergeAll5; }; -var templateLiteralSpanUnionTypeToString = (type) => { - switch (type._tag) { - case "Literal": - return JSON.stringify(String(type.literal)); - case "StringKeyword": - return "string"; - case "NumberKeyword": - return "number"; - case "TemplateLiteral": - return String(type); - case "Union": - return type.types.map(templateLiteralSpanUnionTypeToString).join(" | "); - } +var scoped = /* @__PURE__ */ dual(2, (a, b) => { + const tagFirst = isTag2(a); + const tag = tagFirst ? a : b; + const effect = tagFirst ? b : a; + return scopedContext(map9(effect, (service) => make6(tag, service))); +}); +var scopedContext = (effect) => { + const scoped2 = Object.create(proto3); + scoped2._op_layer = OP_SCOPED; + scoped2.effect = effect; + return scoped2; }; -var templateLiteralSpanTypeToString = (type) => { - switch (type._tag) { - case "Literal": - return String(type.literal); - case "StringKeyword": - return "${string}"; - case "NumberKeyword": - return "${number}"; - case "TemplateLiteral": - return "${" + String(type) + "}"; - case "Union": - return "${" + type.types.map(templateLiteralSpanUnionTypeToString).join(" | ") + "}"; - } +var succeed4 = /* @__PURE__ */ dual(2, (a, b) => { + const tagFirst = isTag2(a); + const tag = tagFirst ? a : b; + const resource = tagFirst ? b : a; + return fromEffectContext(succeed(make6(tag, resource))); +}); +var suspend2 = (evaluate2) => { + const suspend3 = Object.create(proto3); + suspend3._op_layer = OP_SUSPEND; + suspend3.evaluate = evaluate2; + return suspend3; }; - -class TemplateLiteralSpan { - literal; - type; - constructor(type, literal2) { - this.literal = literal2; - if (isTemplateLiteralSpanType(type)) { - this.type = type; - } else { - throw new Error(getSchemaUnsupportedLiteralSpanErrorMessage(type)); - } - } - toString() { - return templateLiteralSpanTypeToString(this.type) + this.literal; - } - toJSON() { - return { - type: this.type.toJSON(), - literal: this.literal - }; +var sync2 = /* @__PURE__ */ dual(2, (a, b) => { + const tagFirst = isTag2(a); + const tag = tagFirst ? a : b; + const evaluate2 = tagFirst ? b : a; + return fromEffectContext(sync(() => make6(tag, evaluate2()))); +}); +var provide = /* @__PURE__ */ dual(2, (self, that) => suspend2(() => { + const provideTo = Object.create(proto3); + provideTo._op_layer = OP_PROVIDE; + provideTo.first = Object.create(proto3, { + _op_layer: { + value: OP_PROVIDE_MERGE, + enumerable: true + }, + first: { + value: context2(), + enumerable: true + }, + second: { + value: Array.isArray(that) ? mergeAll4(...that) : that + }, + zipK: { + value: (a, b) => pipe(a, merge3(b)) + } + }); + provideTo.second = self; + return provideTo; +})); +var provideSomeLayer = /* @__PURE__ */ dual(2, (self, layer) => scopedWith((scope2) => flatMap7(buildWithScope(layer, scope2), (context3) => provideSomeContext(self, context3)))); +var provideSomeRuntime = /* @__PURE__ */ dual(2, (self, rt) => { + const patchRefs = diff6(defaultRuntime.fiberRefs, rt.fiberRefs); + const patchFlags = diff4(defaultRuntime.runtimeFlags, rt.runtimeFlags); + return uninterruptibleMask((restore) => withFiberRuntime((fiber) => { + const oldContext = fiber.getFiberRef(currentContext); + const oldRefs = fiber.getFiberRefs(); + const newRefs = patch7(fiber.id(), oldRefs)(patchRefs); + const oldFlags = fiber.currentRuntimeFlags; + const newFlags = patch4(patchFlags)(oldFlags); + const rollbackRefs = diff6(newRefs, oldRefs); + const rollbackFlags = diff4(newFlags, oldFlags); + fiber.setFiberRefs(newRefs); + fiber.currentRuntimeFlags = newFlags; + return ensuring(provideSomeContext(restore(self), merge3(oldContext, rt.context)), withFiberRuntime((fiber2) => { + fiber2.setFiberRefs(patch7(fiber2.id(), fiber2.getFiberRefs())(rollbackRefs)); + fiber2.currentRuntimeFlags = patch4(rollbackFlags)(fiber2.currentRuntimeFlags); + return void_; + })); + })); +}); +var effect_provide = /* @__PURE__ */ dual(2, (self, source) => { + if (Array.isArray(source)) { + return provideSomeLayer(self, mergeAll4(...source)); + } else if (isLayer(source)) { + return provideSomeLayer(self, source); + } else if (isContext2(source)) { + return provideSomeContext(self, source); + } else if (TypeId16 in source) { + return flatMap7(source.runtimeEffect, (rt) => provideSomeRuntime(self, rt)); + } else { + return provideSomeRuntime(self, source); } -} +}); -class TemplateLiteral { - head; - spans; - annotations; - _tag = "TemplateLiteral"; - constructor(head5, spans, annotations = {}) { - this.head = head5; - this.spans = spans; - this.annotations = annotations; - } - toString() { - return getOrElse(getExpected(this), () => formatTemplateLiteral(this)); - } - toJSON() { - return { - _tag: this._tag, - head: this.head, - spans: this.spans.map((span2) => span2.toJSON()), - annotations: toJSONAnnotations(this.annotations) - }; - } -} -var formatTemplateLiteral = (ast) => "`" + ast.head + ast.spans.map(String).join("") + "`"; -var isTemplateLiteral = /* @__PURE__ */ createASTGuard("TemplateLiteral"); +// node_modules/effect/dist/esm/internal/console.js +var console2 = /* @__PURE__ */ map9(/* @__PURE__ */ fiberRefGet(currentServices), /* @__PURE__ */ get3(consoleTag)); +var consoleWith = (f) => fiberRefGetWith(currentServices, (services) => f(get3(services, consoleTag))); +var withConsole = /* @__PURE__ */ dual(2, (effect, value) => fiberRefLocallyWith(effect, currentServices, add2(consoleTag, value))); +var withConsoleScoped = (console3) => fiberRefLocallyScopedWith(currentServices, add2(consoleTag, console3)); -class Type { - type; - annotations; - constructor(type, annotations = {}) { - this.type = type; - this.annotations = annotations; - } - toJSON() { - return { - type: this.type.toJSON(), - annotations: toJSONAnnotations(this.annotations) - }; - } - toString() { - return String(this.type); - } -} +// node_modules/effect/dist/esm/Data.js +var exports_Data = {}; +__export(exports_Data, { + unsafeStruct: () => unsafeStruct, + unsafeArray: () => unsafeArray, + tuple: () => tuple, + taggedEnum: () => taggedEnum, + tagged: () => tagged2, + struct: () => struct2, + case: () => _case, + array: () => array4, + TaggedError: () => TaggedError, + TaggedClass: () => TaggedClass, + Structural: () => Structural2, + Error: () => Error3, + Class: () => Class3 +}); +var struct2 = struct; +var unsafeStruct = (as3) => Object.setPrototypeOf(as3, StructuralPrototype); +var tuple = (...as3) => unsafeArray(as3); +var array4 = (as3) => unsafeArray(as3.slice(0)); +var unsafeArray = (as3) => Object.setPrototypeOf(as3, ArrayProto); +var _case = () => (args2) => args2 === undefined ? Object.create(StructuralPrototype) : struct2(args2); +var tagged2 = (tag) => (args2) => { + const value = args2 === undefined ? Object.create(StructuralPrototype) : struct2(args2); + value._tag = tag; + return value; +}; +var Class3 = Structural; +var TaggedClass = (tag) => { -class OptionalType extends Type { - isOptional; - constructor(type, isOptional, annotations = {}) { - super(type, annotations); - this.isOptional = isOptional; - } - toJSON() { - return { - type: this.type.toJSON(), - isOptional: this.isOptional, - annotations: toJSONAnnotations(this.annotations) - }; - } - toString() { - return String(this.type) + (this.isOptional ? "?" : ""); + class Base3 extends Class3 { + _tag = tag; } -} -var getRestASTs = (rest) => rest.map((annotatedAST) => annotatedAST.type); - -class TupleType { - elements; - rest; - isReadonly; - annotations; - _tag = "TupleType"; - constructor(elements, rest, isReadonly, annotations = {}) { - this.elements = elements; - this.rest = rest; - this.isReadonly = isReadonly; - this.annotations = annotations; - let hasOptionalElement = false; - let hasIllegalRequiredElement = false; - for (const e of elements) { - if (e.isOptional) { - hasOptionalElement = true; - } else if (hasOptionalElement) { - hasIllegalRequiredElement = true; - break; - } - } - if (hasIllegalRequiredElement || hasOptionalElement && rest.length > 1) { - throw new Error(getASTRequiredElementFollowinAnOptionalElementErrorMessage); + return Base3; +}; +var Structural2 = Structural; +var taggedEnum = () => new Proxy({}, { + get(_target, tag, _receiver) { + if (tag === "$is") { + return isTagged; + } else if (tag === "$match") { + return taggedMatch; } + return tagged2(tag); } - toString() { - return getOrElse(getExpected(this), () => formatTuple(this)); - } - toJSON() { - return { - _tag: this._tag, - elements: this.elements.map((e) => e.toJSON()), - rest: this.rest.map((ast) => ast.toJSON()), - isReadonly: this.isReadonly, - annotations: toJSONAnnotations(this.annotations) +}); +function taggedMatch() { + if (arguments.length === 1) { + const cases2 = arguments[0]; + return function(value2) { + return cases2[value2._tag](value2); }; } + const value = arguments[0]; + const cases = arguments[1]; + return cases[value._tag](value); } -var formatTuple = (ast) => { - const formattedElements = ast.elements.map(String).join(", "); - return matchLeft(ast.rest, { - onEmpty: () => `readonly [${formattedElements}]`, - onNonEmpty: (head5, tail) => { - const formattedHead = String(head5); - const wrappedHead = formattedHead.includes(" | ") ? `(${formattedHead})` : formattedHead; - if (tail.length > 0) { - const formattedTail = tail.map(String).join(", "); - if (ast.elements.length > 0) { - return `readonly [${formattedElements}, ...${wrappedHead}[], ${formattedTail}]`; - } else { - return `readonly [...${wrappedHead}[], ${formattedTail}]`; - } - } else { - if (ast.elements.length > 0) { - return `readonly [${formattedElements}, ...${wrappedHead}[]]`; - } else { - return `ReadonlyArray<${formattedHead}>`; +var Error3 = /* @__PURE__ */ function() { + const plainArgsSymbol = /* @__PURE__ */ Symbol.for("effect/Data/Error/plainArgs"); + const O = { + BaseEffectError: class extends YieldableError { + constructor(args2) { + super(args2?.message, args2?.cause ? { + cause: args2.cause + } : undefined); + if (args2) { + Object.assign(this, args2); + Object.defineProperty(this, plainArgsSymbol, { + value: args2, + enumerable: false + }); } } + toJSON() { + return { + ...this[plainArgsSymbol], + ...this + }; + } } - }); + }; + return O.BaseEffectError; +}(); +var TaggedError = (tag) => { + const O = { + BaseEffectError: class extends Error3 { + _tag = tag; + } + }; + O.BaseEffectError.prototype.name = tag; + return O.BaseEffectError; }; -class PropertySignature extends OptionalType { - name; - isReadonly; - constructor(name, type, isOptional, isReadonly, annotations) { - super(type, isOptional, annotations); - this.name = name; - this.isReadonly = isReadonly; - } - toString() { - return (this.isReadonly ? "readonly " : "") + String(this.name) + (this.isOptional ? "?" : "") + ": " + this.type; - } + +// node_modules/effect/dist/esm/internal/dateTime.js +var TypeId17 = /* @__PURE__ */ Symbol.for("effect/DateTime"); +var TimeZoneTypeId = /* @__PURE__ */ Symbol.for("effect/DateTime/TimeZone"); +var Proto2 = { + [TypeId17]: TypeId17, + pipe() { + return pipeArguments(this, arguments); + }, + [NodeInspectSymbol]() { + return this.toString(); + }, toJSON() { - return { - name: String(this.name), - type: this.type.toJSON(), - isOptional: this.isOptional, - isReadonly: this.isReadonly, - annotations: toJSONAnnotations(this.annotations) - }; + return toDateUtc(this).toJSON(); } -} -var isParameter = (ast) => { - switch (ast._tag) { - case "StringKeyword": - case "SymbolKeyword": - case "TemplateLiteral": - return true; - case "Refinement": - return isParameter(ast.from); +}; +var ProtoUtc = { + ...Proto2, + _tag: "Utc", + [symbol]() { + return cached(this, number2(this.epochMillis)); + }, + [symbol2](that) { + return isDateTime(that) && that._tag === "Utc" && this.epochMillis === that.epochMillis; + }, + toString() { + return `DateTime.Utc(${toDateUtc(this).toJSON()})`; } - return false; }; - -class IndexSignature { - type; - isReadonly; - parameter; - constructor(parameter, type, isReadonly) { - this.type = type; - this.isReadonly = isReadonly; - if (isParameter(parameter)) { - this.parameter = parameter; - } else { - throw new Error(getASTIndexSignatureParameterErrorMessage); - } - } +var ProtoZoned = { + ...Proto2, + _tag: "Zoned", + [symbol]() { + return pipe(number2(this.epochMillis), combine(hash(this.zone)), cached(this)); + }, + [symbol2](that) { + return isDateTime(that) && that._tag === "Zoned" && this.epochMillis === that.epochMillis && equals(this.zone, that.zone); + }, toString() { - return (this.isReadonly ? "readonly " : "") + `[x: ${this.parameter}]: ${this.type}`; + return `DateTime.Zoned(${formatIsoZoned(this)})`; } +}; +var ProtoTimeZone = { + [TimeZoneTypeId]: TimeZoneTypeId, + [NodeInspectSymbol]() { + return this.toString(); + } +}; +var ProtoTimeZoneNamed = { + ...ProtoTimeZone, + _tag: "Named", + [symbol]() { + return cached(this, string(`Named:${this.id}`)); + }, + [symbol2](that) { + return isTimeZone(that) && that._tag === "Named" && this.id === that.id; + }, + toString() { + return `TimeZone.Named(${this.id})`; + }, toJSON() { return { - parameter: this.parameter.toJSON(), - type: this.type.toJSON(), - isReadonly: this.isReadonly - }; - } -} - -class TypeLiteral { - annotations; - _tag = "TypeLiteral"; - propertySignatures; - indexSignatures; - constructor(propertySignatures, indexSignatures, annotations = {}) { - this.annotations = annotations; - const keys5 = {}; - for (let i = 0;i < propertySignatures.length; i++) { - const name = propertySignatures[i].name; - if (Object.prototype.hasOwnProperty.call(keys5, name)) { - throw new Error(getASTDuplicatePropertySignatureErrorMessage(name)); - } - keys5[name] = null; - } - const parameters = { - string: false, - symbol: false + _id: "TimeZone", + _tag: "Named", + id: this.id }; - for (let i = 0;i < indexSignatures.length; i++) { - const encodedParameter = getEncodedParameter(indexSignatures[i].parameter); - if (isStringKeyword(encodedParameter)) { - if (parameters.string) { - throw new Error(getASTDuplicateIndexSignatureErrorMessage("string")); - } - parameters.string = true; - } else if (isSymbolKeyword(encodedParameter)) { - if (parameters.symbol) { - throw new Error(getASTDuplicateIndexSignatureErrorMessage("symbol")); - } - parameters.symbol = true; - } - } - this.propertySignatures = propertySignatures; - this.indexSignatures = indexSignatures; } +}; +var ProtoTimeZoneOffset = { + ...ProtoTimeZone, + _tag: "Offset", + [symbol]() { + return cached(this, string(`Offset:${this.offset}`)); + }, + [symbol2](that) { + return isTimeZone(that) && that._tag === "Offset" && this.offset === that.offset; + }, toString() { - return getOrElse(getExpected(this), () => formatTypeLiteral(this)); - } + return `TimeZone.Offset(${offsetToString(this.offset)})`; + }, toJSON() { return { - _tag: this._tag, - propertySignatures: this.propertySignatures.map((ps) => ps.toJSON()), - indexSignatures: this.indexSignatures.map((ps) => ps.toJSON()), - annotations: toJSONAnnotations(this.annotations) + _id: "TimeZone", + _tag: "Offset", + offset: this.offset }; } -} -var formatIndexSignatures = (iss) => iss.map(String).join("; "); -var formatTypeLiteral = (ast) => { - if (ast.propertySignatures.length > 0) { - const pss = ast.propertySignatures.map(String).join("; "); - if (ast.indexSignatures.length > 0) { - return `{ ${pss}; ${formatIndexSignatures(ast.indexSignatures)} }`; - } else { - return `{ ${pss} }`; - } - } else { - if (ast.indexSignatures.length > 0) { - return `{ ${formatIndexSignatures(ast.indexSignatures)} }`; - } else { - return "{}"; - } - } }; -var isTypeLiteral = /* @__PURE__ */ createASTGuard("TypeLiteral"); -var sortCandidates = /* @__PURE__ */ sort(/* @__PURE__ */ mapInput2(Order2, (ast) => { - switch (ast._tag) { - case "AnyKeyword": - return 0; - case "UnknownKeyword": - return 1; - case "ObjectKeyword": - return 2; - case "StringKeyword": - case "NumberKeyword": - case "BooleanKeyword": - case "BigIntKeyword": - case "SymbolKeyword": - return 3; - } - return 4; -})); -var literalMap = { - string: "StringKeyword", - number: "NumberKeyword", - boolean: "BooleanKeyword", - bigint: "BigIntKeyword" +var makeZonedProto = (epochMillis, zone, partsUtc) => { + const self = Object.create(ProtoZoned); + self.epochMillis = epochMillis; + self.zone = zone; + Object.defineProperty(self, "partsUtc", { + value: partsUtc, + enumerable: false, + writable: true + }); + Object.defineProperty(self, "adjustedEpochMillis", { + value: undefined, + enumerable: false, + writable: true + }); + Object.defineProperty(self, "partsAdjusted", { + value: undefined, + enumerable: false, + writable: true + }); + return self; }; -var flatten7 = (candidates) => flatMap2(candidates, (ast) => isUnion(ast) ? flatten7(ast.types) : [ast]); -var unify = (candidates) => { - const cs = sortCandidates(candidates); - const out = []; - const uniques = {}; - const literals = []; - for (const ast of cs) { - switch (ast._tag) { - case "NeverKeyword": - break; - case "AnyKeyword": - return [anyKeyword]; - case "UnknownKeyword": - return [unknownKeyword]; - case "ObjectKeyword": - case "UndefinedKeyword": - case "VoidKeyword": - case "StringKeyword": - case "NumberKeyword": - case "BooleanKeyword": - case "BigIntKeyword": - case "SymbolKeyword": { - if (!uniques[ast._tag]) { - uniques[ast._tag] = ast; - out.push(ast); - } - break; - } - case "Literal": { - const type = typeof ast.literal; - switch (type) { - case "string": - case "number": - case "bigint": - case "boolean": { - const _tag = literalMap[type]; - if (!uniques[_tag] && !literals.includes(ast.literal)) { - literals.push(ast.literal); - out.push(ast); - } - break; - } - case "object": { - if (!literals.includes(ast.literal)) { - literals.push(ast.literal); - out.push(ast); - } - break; - } - } - break; - } - case "UniqueSymbol": { - if (!uniques["SymbolKeyword"] && !literals.includes(ast.symbol)) { - literals.push(ast.symbol); - out.push(ast); - } - break; - } - case "TupleType": { - if (!uniques["ObjectKeyword"]) { - out.push(ast); - } - break; - } - case "TypeLiteral": { - if (ast.propertySignatures.length === 0 && ast.indexSignatures.length === 0) { - if (!uniques["{}"]) { - uniques["{}"] = ast; - out.push(ast); - } - } else if (!uniques["ObjectKeyword"]) { - out.push(ast); - } - break; - } - default: - out.push(ast); +var isDateTime = (u) => hasProperty(u, TypeId17); +var isTimeZone = (u) => hasProperty(u, TimeZoneTypeId); +var isTimeZoneOffset = (u) => isTimeZone(u) && u._tag === "Offset"; +var isTimeZoneNamed = (u) => isTimeZone(u) && u._tag === "Named"; +var isUtc = (self) => self._tag === "Utc"; +var isZoned = (self) => self._tag === "Zoned"; +var Equivalence3 = /* @__PURE__ */ make((a, b) => a.epochMillis === b.epochMillis); +var makeUtc = (epochMillis) => { + const self = Object.create(ProtoUtc); + self.epochMillis = epochMillis; + Object.defineProperty(self, "partsUtc", { + value: undefined, + enumerable: false, + writable: true + }); + return self; +}; +var unsafeFromDate = (date) => { + const epochMillis = date.getTime(); + if (Number.isNaN(epochMillis)) { + throw new IllegalArgumentException2("Invalid date"); + } + return makeUtc(epochMillis); +}; +var unsafeMake8 = (input) => { + if (isDateTime(input)) { + return input; + } else if (input instanceof Date) { + return unsafeFromDate(input); + } else if (typeof input === "object") { + const date = new Date(0); + setPartsDate(date, input); + return unsafeFromDate(date); + } else if (typeof input === "string" && !hasZone(input)) { + return unsafeFromDate(new Date(input + "Z")); + } + return unsafeFromDate(new Date(input)); +}; +var hasZone = (input) => /Z|[+-]\d{2}$|[+-]\d{2}:?\d{2}$|\]$/.test(input); +var minEpochMillis = -8640000000000000 + 12 * 60 * 60 * 1000; +var maxEpochMillis = 8640000000000000 - 14 * 60 * 60 * 1000; +var unsafeMakeZoned = (input, options) => { + if (options?.timeZone === undefined && isDateTime(input) && isZoned(input)) { + return input; + } + const self = unsafeMake8(input); + if (self.epochMillis < minEpochMillis || self.epochMillis > maxEpochMillis) { + throw new RangeError(`Epoch millis out of range: ${self.epochMillis}`); + } + let zone; + if (options?.timeZone === undefined) { + const offset = new Date(self.epochMillis).getTimezoneOffset() * -60 * 1000; + zone = zoneMakeOffset(offset); + } else if (isTimeZone(options?.timeZone)) { + zone = options.timeZone; + } else if (typeof options?.timeZone === "number") { + zone = zoneMakeOffset(options.timeZone); + } else { + const parsedZone = zoneFromString(options.timeZone); + if (isNone2(parsedZone)) { + throw new IllegalArgumentException2(`Invalid time zone: ${options.timeZone}`); } + zone = parsedZone.value; } - return out; + if (options?.adjustForTimeZone !== true) { + return makeZonedProto(self.epochMillis, zone, self.partsUtc); + } + return makeZonedFromAdjusted(self.epochMillis, zone, options?.disambiguation ?? "compatible"); }; - -class Union { - types; - annotations; - static make = (types, annotations) => { - return isMembers(types) ? new Union(types, annotations) : types.length === 1 ? types[0] : neverKeyword; - }; - static unify = (candidates, annotations) => { - return Union.make(unify(flatten7(candidates)), annotations); - }; - _tag = "Union"; - constructor(types, annotations = {}) { - this.types = types; - this.annotations = annotations; +var makeZoned = /* @__PURE__ */ liftThrowable(unsafeMakeZoned); +var zonedStringRegex = /^(.{17,35})\[(.+)\]$/; +var makeZonedFromString = (input) => { + const match10 = zonedStringRegex.exec(input); + if (match10 === null) { + const offset = parseOffset(input); + return offset !== null ? makeZoned(input, { + timeZone: offset + }) : none2(); } - toString() { - return getOrElse(getExpected(this), () => this.types.map(String).join(" | ")); + const [, isoString, timeZone] = match10; + return makeZoned(isoString, { + timeZone + }); +}; +var validZoneCache = /* @__PURE__ */ globalValue("effect/DateTime/validZoneCache", () => new Map); +var formatOptions = { + day: "numeric", + month: "numeric", + year: "numeric", + hour: "numeric", + minute: "numeric", + second: "numeric", + timeZoneName: "longOffset", + fractionalSecondDigits: 3, + hourCycle: "h23" +}; +var zoneMakeIntl = (format5) => { + const zoneId = format5.resolvedOptions().timeZone; + if (validZoneCache.has(zoneId)) { + return validZoneCache.get(zoneId); } - toJSON() { - return { - _tag: this._tag, - types: this.types.map((ast) => ast.toJSON()), - annotations: toJSONAnnotations(this.annotations) - }; + const zone = Object.create(ProtoTimeZoneNamed); + zone.id = zoneId; + zone.format = format5; + validZoneCache.set(zoneId, zone); + return zone; +}; +var zoneUnsafeMakeNamed = (zoneId) => { + if (validZoneCache.has(zoneId)) { + return validZoneCache.get(zoneId); } -} -var mapMembers = (members, f) => members.map(f); -var isMembers = (as4) => as4.length > 1; -var isUnion = /* @__PURE__ */ createASTGuard("Union"); -var toJSONMemoMap = /* @__PURE__ */ globalValue(/* @__PURE__ */ Symbol.for("effect/Schema/AST/toJSONMemoMap"), () => new WeakMap); - -class Suspend { - f; - annotations; - _tag = "Suspend"; - constructor(f, annotations = {}) { - this.f = f; - this.annotations = annotations; - this.f = memoizeThunk(f); + try { + return zoneMakeIntl(new Intl.DateTimeFormat("en-US", { + ...formatOptions, + timeZone: zoneId + })); + } catch { + throw new IllegalArgumentException2(`Invalid time zone: ${zoneId}`); } - toString() { - return getExpected(this).pipe(orElse(() => flatMap(liftThrowable(this.f)(), (ast) => getExpected(ast))), getOrElse(() => "")); +}; +var zoneMakeOffset = (offset) => { + const zone = Object.create(ProtoTimeZoneOffset); + zone.offset = offset; + return zone; +}; +var zoneMakeNamed = /* @__PURE__ */ liftThrowable(zoneUnsafeMakeNamed); +var offsetZoneRegex = /^(?:GMT|[+-])/; +var zoneFromString = (zone) => { + if (offsetZoneRegex.test(zone)) { + const offset = parseOffset(zone); + return offset === null ? none2() : some2(zoneMakeOffset(offset)); } - toJSON() { - const ast = this.f(); - let out = toJSONMemoMap.get(ast); - if (out) { - return out; - } - toJSONMemoMap.set(ast, { - _tag: this._tag - }); - out = { - _tag: this._tag, - ast: ast.toJSON(), - annotations: toJSONAnnotations(this.annotations) - }; - toJSONMemoMap.set(ast, out); - return out; + return zoneMakeNamed(zone); +}; +var zoneToString = (self) => { + if (self._tag === "Offset") { + return offsetToString(self.offset); } -} -class Refinement { - from; - filter; - annotations; - _tag = "Refinement"; - constructor(from, filter8, annotations = {}) { - this.from = from; - this.filter = filter8; - this.annotations = annotations; + return self.id; +}; +var toDateUtc = (self) => new Date(self.epochMillis); +var toDate = (self) => { + if (self._tag === "Utc") { + return new Date(self.epochMillis); + } else if (self.zone._tag === "Offset") { + return new Date(self.epochMillis + self.zone.offset); + } else if (self.adjustedEpochMillis !== undefined) { + return new Date(self.adjustedEpochMillis); } - toString() { - return getIdentifierAnnotation(this).pipe(getOrElse(() => match2(getOrElseExpected(this), { - onNone: () => `{ ${this.from} | filter }`, - onSome: (expected) => isRefinement(this.from) ? String(this.from) + " & " + expected : expected - }))); + const parts2 = self.zone.format.formatToParts(self.epochMillis).filter((_) => _.type !== "literal"); + const date = new Date(0); + date.setUTCFullYear(Number(parts2[2].value), Number(parts2[0].value) - 1, Number(parts2[1].value)); + date.setUTCHours(Number(parts2[3].value), Number(parts2[4].value), Number(parts2[5].value), Number(parts2[6].value)); + self.adjustedEpochMillis = date.getTime(); + return date; +}; +var zonedOffset = (self) => { + const date = toDate(self); + return date.getTime() - toEpochMillis(self); +}; +var offsetToString = (offset) => { + const abs2 = Math.abs(offset); + let hours2 = Math.floor(abs2 / (60 * 60 * 1000)); + let minutes2 = Math.round(abs2 % (60 * 60 * 1000) / (60 * 1000)); + if (minutes2 === 60) { + hours2 += 1; + minutes2 = 0; } - toJSON() { - return { - _tag: this._tag, - from: this.from.toJSON(), - annotations: toJSONAnnotations(this.annotations) - }; + return `${offset < 0 ? "-" : "+"}${String(hours2).padStart(2, "0")}:${String(minutes2).padStart(2, "0")}`; +}; +var zonedOffsetIso = (self) => offsetToString(zonedOffset(self)); +var toEpochMillis = (self) => self.epochMillis; +var setPartsDate = (date, parts2) => { + if (parts2.year !== undefined) { + date.setUTCFullYear(parts2.year); } -} -var isRefinement = /* @__PURE__ */ createASTGuard("Refinement"); -var defaultParseOption = {}; - -class Transformation { - from; - to; - transformation; - annotations; - _tag = "Transformation"; - constructor(from, to, transformation, annotations = {}) { - this.from = from; - this.to = to; - this.transformation = transformation; - this.annotations = annotations; + if (parts2.month !== undefined) { + date.setUTCMonth(parts2.month - 1); } - toString() { - return getOrElse(getExpected(this), () => `(${String(this.from)} <-> ${String(this.to)})`); + if (parts2.day !== undefined) { + date.setUTCDate(parts2.day); } - toJSON() { - return { - _tag: this._tag, - from: this.from.toJSON(), - to: this.to.toJSON(), - annotations: toJSONAnnotations(this.annotations) - }; + if (parts2.weekDay !== undefined) { + const diff8 = parts2.weekDay - date.getUTCDay(); + date.setUTCDate(date.getUTCDate() + diff8); + } + if (parts2.hours !== undefined) { + date.setUTCHours(parts2.hours); + } + if (parts2.minutes !== undefined) { + date.setUTCMinutes(parts2.minutes); } -} -var isTransformation = /* @__PURE__ */ createASTGuard("Transformation"); - -class FinalTransformation { - decode; - encode; - _tag = "FinalTransformation"; - constructor(decode5, encode4) { - this.decode = decode5; - this.encode = encode4; + if (parts2.seconds !== undefined) { + date.setUTCSeconds(parts2.seconds); } -} -var createTransformationGuard = (tag) => (ast) => ast._tag === tag; -class ComposeTransformation { - _tag = "ComposeTransformation"; -} -var composeTransformation = /* @__PURE__ */ new ComposeTransformation; -class PropertySignatureTransformation { - from; - to; - decode; - encode; - constructor(from, to, decode5, encode4) { - this.from = from; - this.to = to; - this.decode = decode5; - this.encode = encode4; + if (parts2.millis !== undefined) { + date.setUTCMilliseconds(parts2.millis); } -} -var isRenamingPropertySignatureTransformation = (t) => t.decode === identity && t.encode === identity; - -class TypeLiteralTransformation { - propertySignatureTransformations; - _tag = "TypeLiteralTransformation"; - constructor(propertySignatureTransformations) { - this.propertySignatureTransformations = propertySignatureTransformations; - const fromKeys = {}; - const toKeys = {}; - for (const pst of propertySignatureTransformations) { - const from = pst.from; - if (fromKeys[from]) { - throw new Error(getASTDuplicatePropertySignatureTransformationErrorMessage(from)); - } - fromKeys[from] = true; - const to = pst.to; - if (toKeys[to]) { - throw new Error(getASTDuplicatePropertySignatureTransformationErrorMessage(to)); +}; +var constDayMillis = 24 * 60 * 60 * 1000; +var makeZonedFromAdjusted = (adjustedMillis, zone, disambiguation) => { + if (zone._tag === "Offset") { + return makeZonedProto(adjustedMillis - zone.offset, zone); + } + const beforeOffset = calculateNamedOffset(adjustedMillis - constDayMillis, adjustedMillis, zone); + const afterOffset = calculateNamedOffset(adjustedMillis + constDayMillis, adjustedMillis, zone); + if (beforeOffset === afterOffset) { + return makeZonedProto(adjustedMillis - beforeOffset, zone); + } + const isForwards = beforeOffset < afterOffset; + const transitionMillis = beforeOffset - afterOffset; + if (isForwards) { + const currentAfterOffset = calculateNamedOffset(adjustedMillis - afterOffset, adjustedMillis, zone); + if (currentAfterOffset === afterOffset) { + return makeZonedProto(adjustedMillis - afterOffset, zone); + } + const before2 = makeZonedProto(adjustedMillis - beforeOffset, zone); + const beforeAdjustedMillis = toDate(before2).getTime(); + if (adjustedMillis !== beforeAdjustedMillis) { + switch (disambiguation) { + case "reject": { + const formatted = new Date(adjustedMillis).toISOString(); + throw new RangeError(`Gap time: ${formatted} does not exist in time zone ${zone.id}`); + } + case "earlier": + return makeZonedProto(adjustedMillis - afterOffset, zone); + case "compatible": + case "later": + return before2; } - toKeys[to] = true; } + return before2; } -} -var isTypeLiteralTransformation = /* @__PURE__ */ createTransformationGuard("TypeLiteralTransformation"); -var annotations = (ast, overrides) => { - const d = Object.getOwnPropertyDescriptors(ast); - const base = { - ...ast.annotations - }; - delete base[IdentifierAnnotationId]; - const value2 = { - ...base, - ...overrides - }; - const surrogate = getSurrogateAnnotation(ast); - if (isSome2(surrogate)) { - value2[SurrogateAnnotationId] = annotations(surrogate.value, overrides); - } - d.annotations.value = value2; - return Object.create(Object.getPrototypeOf(ast), d); -}; -var keyof = (ast) => Union.unify(_keyof(ast)); -var STRING_KEYWORD_PATTERN = "[\\s\\S]*?"; -var NUMBER_KEYWORD_PATTERN = "[+-]?\\d*\\.?\\d+(?:[Ee][+-]?\\d+)?"; -var getTemplateLiteralSpanTypePattern = (type, capture2) => { - switch (type._tag) { - case "Literal": - return escape(String(type.literal)); - case "StringKeyword": - return STRING_KEYWORD_PATTERN; - case "NumberKeyword": - return NUMBER_KEYWORD_PATTERN; - case "TemplateLiteral": - return getTemplateLiteralPattern(type, capture2, false); - case "Union": - return type.types.map((type2) => getTemplateLiteralSpanTypePattern(type2, capture2)).join("|"); + const currentBeforeOffset = calculateNamedOffset(adjustedMillis - beforeOffset, adjustedMillis, zone); + if (currentBeforeOffset === beforeOffset) { + if (disambiguation === "earlier" || disambiguation === "compatible") { + return makeZonedProto(adjustedMillis - beforeOffset, zone); + } + const laterOffset = calculateNamedOffset(adjustedMillis - beforeOffset + transitionMillis, adjustedMillis + transitionMillis, zone); + if (laterOffset === beforeOffset) { + return makeZonedProto(adjustedMillis - beforeOffset, zone); + } + if (disambiguation === "reject") { + const formatted = new Date(adjustedMillis).toISOString(); + throw new RangeError(`Ambiguous time: ${formatted} occurs twice in time zone ${zone.id}`); + } } + return makeZonedProto(adjustedMillis - afterOffset, zone); }; -var handleTemplateLiteralSpanTypeParens = (type, s, capture2, top) => { - if (isUnion(type)) { - if (capture2 && !top) { - return `(?:${s})`; - } - } else if (!capture2 || !top) { - return s; +var offsetRegex = /([+-])(\d{2}):(\d{2})$/; +var parseOffset = (offset) => { + const match10 = offsetRegex.exec(offset); + if (match10 === null) { + return null; } - return `(${s})`; + const [, sign2, hours2, minutes2] = match10; + return (sign2 === "+" ? 1 : -1) * (Number(hours2) * 60 + Number(minutes2)) * 60 * 1000; }; -var getTemplateLiteralPattern = (ast, capture2, top) => { - let pattern = ``; - if (ast.head !== "") { - const head5 = escape(ast.head); - pattern += capture2 && top ? `(${head5})` : head5; +var calculateNamedOffset = (utcMillis, adjustedMillis, zone) => { + const offset = zone.format.formatToParts(utcMillis).find((_) => _.type === "timeZoneName")?.value ?? ""; + if (offset === "GMT") { + return 0; } - for (const span2 of ast.spans) { - const spanPattern = getTemplateLiteralSpanTypePattern(span2.type, capture2); - pattern += handleTemplateLiteralSpanTypeParens(span2.type, spanPattern, capture2, top); - if (span2.literal !== "") { - const literal2 = escape(span2.literal); - pattern += capture2 && top ? `(${literal2})` : literal2; - } + const result = parseOffset(offset); + if (result === null) { + return zonedOffset(makeZonedProto(adjustedMillis, zone)); } - return pattern; + return result; }; -var getTemplateLiteralRegExp = (ast) => new RegExp(`^${getTemplateLiteralPattern(ast, false, true)}$`); -var getTemplateLiteralCapturingRegExp = (ast) => new RegExp(`^${getTemplateLiteralPattern(ast, true, true)}$`); -var getIndexSignatures = (ast) => { - const annotation = getSurrogateAnnotation(ast); - if (isSome2(annotation)) { - return getIndexSignatures(annotation.value); +var formatIso = (self) => toDateUtc(self).toISOString(); +var formatIsoOffset = (self) => { + const date = toDate(self); + return self._tag === "Utc" ? date.toISOString() : `${date.toISOString().slice(0, -1)}${zonedOffsetIso(self)}`; +}; +var formatIsoZoned = (self) => self.zone._tag === "Offset" ? formatIsoOffset(self) : `${formatIsoOffset(self)}[${self.zone.id}]`; + +// node_modules/effect/dist/esm/String.js +var toUpperCase = (self) => self.toUpperCase(); +var toLowerCase = (self) => self.toLowerCase(); +var capitalize = (self) => { + if (self.length === 0) + return self; + return toUpperCase(self[0]) + self.slice(1); +}; +var uncapitalize = (self) => { + if (self.length === 0) + return self; + return toLowerCase(self[0]) + self.slice(1); +}; +var isNonEmpty6 = (self) => self.length > 0; + +// node_modules/effect/dist/esm/Random.js +var fixed2 = fixed; + +// node_modules/effect/dist/esm/internal/schedule.js +var ScheduleSymbolKey = "effect/Schedule"; +var ScheduleTypeId = /* @__PURE__ */ Symbol.for(ScheduleSymbolKey); +var isSchedule = (u) => hasProperty(u, ScheduleTypeId); +var ScheduleDriverSymbolKey = "effect/ScheduleDriver"; +var ScheduleDriverTypeId = /* @__PURE__ */ Symbol.for(ScheduleDriverSymbolKey); +var defaultIterationMetadata = { + start: 0, + now: 0, + input: undefined, + output: undefined, + elapsed: zero2, + elapsedSincePrevious: zero2, + recurrence: 0 +}; +var CurrentIterationMetadata = /* @__PURE__ */ Reference2()("effect/Schedule/CurrentIterationMetadata", { + defaultValue: () => defaultIterationMetadata +}); +var scheduleVariance = { + _Out: (_) => _, + _In: (_) => _, + _R: (_) => _ +}; +var scheduleDriverVariance = { + _Out: (_) => _, + _In: (_) => _, + _R: (_) => _ +}; + +class ScheduleImpl { + initial; + step; + [ScheduleTypeId] = scheduleVariance; + constructor(initial, step3) { + this.initial = initial; + this.step = step3; } - switch (ast._tag) { - case "TypeLiteral": - return ast.indexSignatures.slice(); - case "Suspend": - return getIndexSignatures(ast.f()); - case "Refinement": - return getIndexSignatures(ast.from); - case "Transformation": - return getIndexSignatures(ast.to); + pipe() { + return pipeArguments(this, arguments); } - return []; -}; -var getNumberIndexedAccess = (ast) => { - switch (ast._tag) { - case "TupleType": { - let hasOptional = false; - let out = []; - for (const e of ast.elements) { - if (e.isOptional) { - hasOptional = true; - } - out.push(e.type); - } - if (hasOptional) { - out.push(undefinedKeyword); - } - out = out.concat(getRestASTs(ast.rest)); - return Union.make(out); - } - case "Refinement": - return getNumberIndexedAccess(ast.from); - case "Union": - return Union.make(ast.types.map(getNumberIndexedAccess)); - case "Suspend": - return getNumberIndexedAccess(ast.f()); +} +var updateInfo = (iterationMetaRef, now, input, output) => update2(iterationMetaRef, (prev) => prev.recurrence === 0 ? { + now, + input, + output, + recurrence: prev.recurrence + 1, + elapsed: zero2, + elapsedSincePrevious: zero2, + start: now +} : { + now, + input, + output, + recurrence: prev.recurrence + 1, + elapsed: millis(now - prev.start), + elapsedSincePrevious: millis(now - prev.now), + start: prev.start +}); + +class ScheduleDriverImpl { + schedule; + ref; + [ScheduleDriverTypeId] = scheduleDriverVariance; + constructor(schedule, ref) { + this.schedule = schedule; + this.ref = ref; } - throw new Error(getASTUnsupportedSchemaErrorMessage(ast)); -}; -var getTypeLiteralPropertySignature = (ast, name) => { - const ops = findFirst2(ast.propertySignatures, (ps) => ps.name === name); - if (isSome2(ops)) { - return ops.value; + get state() { + return map9(get11(this.ref), (tuple2) => tuple2[1]); } - if (isString(name)) { - let out = undefined; - for (const is of ast.indexSignatures) { - const encodedParameter = getEncodedParameter(is.parameter); - switch (encodedParameter._tag) { - case "TemplateLiteral": { - const regex = getTemplateLiteralRegExp(encodedParameter); - if (regex.test(name)) { - return new PropertySignature(name, is.type, false, true); - } - break; + get last() { + return flatMap7(get11(this.ref), ([element, _]) => { + switch (element._tag) { + case "None": { + return failSync(() => new NoSuchElementException); } - case "StringKeyword": { - if (out === undefined) { - out = new PropertySignature(name, is.type, false, true); - } + case "Some": { + return succeed(element.value); } } - } - if (out) { - return out; - } - } else if (isSymbol(name)) { - for (const is of ast.indexSignatures) { - const encodedParameter = getEncodedParameter(is.parameter); - if (isSymbolKeyword(encodedParameter)) { - return new PropertySignature(name, is.type, false, true); + }); + } + iterationMeta = /* @__PURE__ */ unsafeMake5(defaultIterationMetadata); + get reset() { + return set5(this.ref, [none2(), this.schedule.initial]).pipe(zipLeft(set5(this.iterationMeta, defaultIterationMetadata))); + } + next(input) { + return pipe(map9(get11(this.ref), (tuple2) => tuple2[1]), flatMap7((state) => pipe(currentTimeMillis2, flatMap7((now) => pipe(suspend(() => this.schedule.step(now, input, state)), flatMap7(([state2, out, decision]) => { + const setState = set5(this.ref, [some2(out), state2]); + if (isDone4(decision)) { + return setState.pipe(zipRight(fail2(none2()))); } - } + const millis2 = start2(decision.intervals) - now; + if (millis2 <= 0) { + return setState.pipe(zipRight(updateInfo(this.iterationMeta, now, input, out)), as(out)); + } + const duration = millis(millis2); + return pipe(setState, zipRight(updateInfo(this.iterationMeta, now, input, out)), zipRight(sleep3(duration)), as(out)); + })))))); } -}; -var getPropertyKeyIndexedAccess = (ast, name) => { - const annotation = getSurrogateAnnotation(ast); - if (isSome2(annotation)) { - return getPropertyKeyIndexedAccess(annotation.value, name); +} +var makeWithState = (initial, step3) => new ScheduleImpl(initial, step3); +var asVoid2 = (self) => map10(self, constVoid); +var check = /* @__PURE__ */ dual(2, (self, test) => checkEffect(self, (input, out) => sync(() => test(input, out)))); +var checkEffect = /* @__PURE__ */ dual(2, (self, test) => makeWithState(self.initial, (now, input, state) => flatMap7(self.step(now, input, state), ([state2, out, decision]) => { + if (isDone4(decision)) { + return succeed([state2, out, done6]); } - switch (ast._tag) { - case "TypeLiteral": { - const ps = getTypeLiteralPropertySignature(ast, name); - if (ps) { - return ps; + return map9(test(input, out), (cont) => cont ? [state2, out, decision] : [state2, out, done6]); +}))); +var driver = (self) => pipe(make27([none2(), self.initial]), map9((ref) => new ScheduleDriverImpl(self, ref))); +var intersect5 = /* @__PURE__ */ dual(2, (self, that) => intersectWith(self, that, intersect4)); +var intersectWith = /* @__PURE__ */ dual(3, (self, that, f) => makeWithState([self.initial, that.initial], (now, input, state) => pipe(zipWith2(self.step(now, input, state[0]), that.step(now, input, state[1]), (a, b) => [a, b]), flatMap7(([[lState, out, lDecision], [rState, out2, rDecision]]) => { + if (isContinue2(lDecision) && isContinue2(rDecision)) { + return intersectWithLoop(self, that, input, lState, out, lDecision.intervals, rState, out2, rDecision.intervals, f); + } + return succeed([[lState, rState], [out, out2], done6]); +})))); +var intersectWithLoop = (self, that, input, lState, out, lInterval, rState, out2, rInterval, f) => { + const combined = f(lInterval, rInterval); + if (isNonEmpty5(combined)) { + return succeed([[lState, rState], [out, out2], _continue2(combined)]); + } + if (pipe(lInterval, lessThan7(rInterval))) { + return flatMap7(self.step(end2(lInterval), input, lState), ([lState2, out3, decision]) => { + if (isDone4(decision)) { + return succeed([[lState2, rState], [out3, out2], done6]); } - break; - } - case "Union": - return new PropertySignature(name, Union.make(ast.types.map((ast2) => getPropertyKeyIndexedAccess(ast2, name).type)), false, true); - case "Suspend": - return getPropertyKeyIndexedAccess(ast.f(), name); - case "Refinement": - return getPropertyKeyIndexedAccess(ast.from, name); - case "Transformation": - return getPropertyKeyIndexedAccess(ast.to, name); + return intersectWithLoop(self, that, input, lState2, out3, decision.intervals, rState, out2, rInterval, f); + }); } - throw new Error(getASTUnsupportedSchemaErrorMessage(ast)); + return flatMap7(that.step(end2(rInterval), input, rState), ([rState2, out22, decision]) => { + if (isDone4(decision)) { + return succeed([[lState, rState2], [out, out22], done6]); + } + return intersectWithLoop(self, that, input, lState, out, lInterval, rState2, out22, decision.intervals, f); + }); }; -var getPropertyKeys = (ast) => { - const annotation = getSurrogateAnnotation(ast); - if (isSome2(annotation)) { - return getPropertyKeys(annotation.value); +var map10 = /* @__PURE__ */ dual(2, (self, f) => mapEffect(self, (out) => sync(() => f(out)))); +var mapEffect = /* @__PURE__ */ dual(2, (self, f) => makeWithState(self.initial, (now, input, state) => flatMap7(self.step(now, input, state), ([state2, out, decision]) => map9(f(out), (out2) => [state2, out2, decision])))); +var passthrough = (self) => makeWithState(self.initial, (now, input, state) => pipe(self.step(now, input, state), map9(([state2, _, decision]) => [state2, input, decision]))); +var recurs = (n) => whileOutput(forever2, (out) => out < n); +var unfold2 = (initial, f) => makeWithState(initial, (now, _, state) => sync(() => [f(state), state, continueWith2(after2(now))])); +var untilInputEffect = /* @__PURE__ */ dual(2, (self, f) => checkEffect(self, (input, _) => negate(f(input)))); +var whileInputEffect = /* @__PURE__ */ dual(2, (self, f) => checkEffect(self, (input, _) => f(input))); +var whileOutput = /* @__PURE__ */ dual(2, (self, f) => check(self, (_, out) => f(out))); +var ScheduleDefectTypeId = /* @__PURE__ */ Symbol.for("effect/Schedule/ScheduleDefect"); + +class ScheduleDefect { + error; + [ScheduleDefectTypeId]; + constructor(error) { + this.error = error; + this[ScheduleDefectTypeId] = ScheduleDefectTypeId; } - switch (ast._tag) { - case "TypeLiteral": - return ast.propertySignatures.map((ps) => ps.name); - case "Union": - return ast.types.slice(1).reduce((out, ast2) => intersection(out, getPropertyKeys(ast2)), getPropertyKeys(ast.types[0])); - case "Suspend": - return getPropertyKeys(ast.f()); - case "Refinement": - return getPropertyKeys(ast.from); - case "Transformation": - return getPropertyKeys(ast.to); +} +var isScheduleDefect = (u) => hasProperty(u, ScheduleDefectTypeId); +var scheduleDefectWrap = (self) => catchAll(self, (e) => die2(new ScheduleDefect(e))); +var scheduleDefectRefailCause = (cause2) => match2(find(cause2, (_) => isDieType(_) && isScheduleDefect(_.defect) ? some2(_.defect) : none2()), { + onNone: () => cause2, + onSome: (error) => fail(error.error) +}); +var scheduleDefectRefail = (effect) => catchAllCause(effect, (cause2) => failCause(scheduleDefectRefailCause(cause2))); +var repeat_Effect = /* @__PURE__ */ dual(2, (self, schedule) => repeatOrElse_Effect(self, schedule, (e, _) => fail2(e))); +var repeat_combined = /* @__PURE__ */ dual(2, (self, options) => { + if (isSchedule(options)) { + return repeat_Effect(self, options); } - return []; + const base = options.schedule ?? passthrough(forever2); + const withWhile = options.while ? whileInputEffect(base, (a) => { + const applied = options.while(a); + if (typeof applied === "boolean") { + return succeed(applied); + } + return scheduleDefectWrap(applied); + }) : base; + const withUntil = options.until ? untilInputEffect(withWhile, (a) => { + const applied = options.until(a); + if (typeof applied === "boolean") { + return succeed(applied); + } + return scheduleDefectWrap(applied); + }) : withWhile; + const withTimes = options.times ? intersect5(withUntil, recurs(options.times)).pipe(map10((intersectionPair) => intersectionPair[0])) : withUntil; + return scheduleDefectRefail(repeat_Effect(self, withTimes)); +}); +var repeatOrElse_Effect = /* @__PURE__ */ dual(3, (self, schedule, orElse3) => flatMap7(driver(schedule), (driver2) => matchEffect(self, { + onFailure: (error) => orElse3(error, none2()), + onSuccess: (value) => repeatOrElseEffectLoop(provideServiceEffect(self, CurrentIterationMetadata, get11(driver2.iterationMeta)), driver2, (error, option2) => provideServiceEffect(orElse3(error, option2), CurrentIterationMetadata, get11(driver2.iterationMeta)), value) +}))); +var repeatOrElseEffectLoop = (self, driver2, orElse3, value) => matchEffect(driver2.next(value), { + onFailure: () => orDie(driver2.last), + onSuccess: (b) => matchEffect(self, { + onFailure: (error) => orElse3(error, some2(b)), + onSuccess: (value2) => repeatOrElseEffectLoop(self, driver2, orElse3, value2) + }) +}); +var retry_Effect = /* @__PURE__ */ dual(2, (self, policy) => retryOrElse_Effect(self, policy, (e, _) => fail2(e))); +var retry_combined = /* @__PURE__ */ dual(2, (self, options) => { + if (isSchedule(options)) { + return retry_Effect(self, options); + } + return scheduleDefectRefail(retry_Effect(self, fromRetryOptions(options))); +}); +var fromRetryOptions = (options) => { + const base = options.schedule ?? forever2; + const withWhile = options.while ? whileInputEffect(base, (e) => { + const applied = options.while(e); + if (typeof applied === "boolean") { + return succeed(applied); + } + return scheduleDefectWrap(applied); + }) : base; + const withUntil = options.until ? untilInputEffect(withWhile, (e) => { + const applied = options.until(e); + if (typeof applied === "boolean") { + return succeed(applied); + } + return scheduleDefectWrap(applied); + }) : withWhile; + return options.times !== undefined ? intersect5(withUntil, recurs(options.times)) : withUntil; }; -var record = (key, value2) => { - const propertySignatures = []; - const indexSignatures = []; - const go = (key2) => { - switch (key2._tag) { - case "NeverKeyword": - break; - case "StringKeyword": - case "SymbolKeyword": - case "TemplateLiteral": - case "Refinement": - indexSignatures.push(new IndexSignature(key2, value2, true)); - break; - case "Literal": - if (isString(key2.literal) || isNumber(key2.literal)) { - propertySignatures.push(new PropertySignature(key2.literal, value2, false, true)); - } else { - throw new Error(getASTUnsupportedLiteralErrorMessage(key2.literal)); - } - break; - case "Enums": { - for (const [_, name] of key2.enums) { - propertySignatures.push(new PropertySignature(name, value2, false, true)); - } - break; +var retryOrElse_Effect = /* @__PURE__ */ dual(3, (self, policy, orElse3) => flatMap7(driver(policy), (driver2) => retryOrElse_EffectLoop(provideServiceEffect(self, CurrentIterationMetadata, get11(driver2.iterationMeta)), driver2, (e, out) => provideServiceEffect(orElse3(e, out), CurrentIterationMetadata, get11(driver2.iterationMeta))))); +var retryOrElse_EffectLoop = (self, driver2, orElse3) => { + return catchAll(self, (e) => matchEffect(driver2.next(e), { + onFailure: () => pipe(driver2.last, orDie, flatMap7((out) => orElse3(e, out))), + onSuccess: () => retryOrElse_EffectLoop(self, driver2, orElse3) + })); +}; +var schedule_Effect = /* @__PURE__ */ dual(2, (self, schedule) => scheduleFrom_Effect(self, undefined, schedule)); +var scheduleFrom_Effect = /* @__PURE__ */ dual(3, (self, initial, schedule) => flatMap7(driver(schedule), (driver2) => scheduleFrom_EffectLoop(provideServiceEffect(self, CurrentIterationMetadata, get11(driver2.iterationMeta)), initial, driver2))); +var scheduleFrom_EffectLoop = (self, initial, driver2) => matchEffect(driver2.next(initial), { + onFailure: () => orDie(driver2.last), + onSuccess: () => flatMap7(self, (a) => scheduleFrom_EffectLoop(self, a, driver2)) +}); +var forever2 = /* @__PURE__ */ unfold2(0, (n) => n + 1); +var once2 = /* @__PURE__ */ asVoid2(/* @__PURE__ */ recurs(1)); +var scheduleForked = /* @__PURE__ */ dual(2, (self, schedule) => forkScoped(schedule_Effect(self, schedule))); + +// node_modules/effect/dist/esm/internal/executionPlan.js +var withExecutionPlan = /* @__PURE__ */ dual(2, (effect, plan) => suspend(() => { + let i = 0; + let result; + return flatMap7(whileLoop({ + while: () => i < plan.steps.length && (result === undefined || isLeft2(result)), + body: () => { + const step3 = plan.steps[i]; + let nextEffect = effect_provide(effect, step3.provide); + if (result) { + let attempted = false; + const wrapped = nextEffect; + nextEffect = suspend(() => { + if (attempted) + return wrapped; + attempted = true; + return result; + }); + nextEffect = scheduleDefectRefail(retry_Effect(nextEffect, scheduleFromStep(step3, false))); + } else { + const schedule = scheduleFromStep(step3, true); + nextEffect = schedule ? scheduleDefectRefail(retry_Effect(nextEffect, schedule)) : nextEffect; } - case "UniqueSymbol": - propertySignatures.push(new PropertySignature(key2.symbol, value2, false, true)); - break; - case "Union": - key2.types.forEach(go); - break; - default: - throw new Error(getASTUnsupportedKeySchemaErrorMessage(key2)); + return either2(nextEffect); + }, + step: (either3) => { + result = either3; + i++; } - }; - go(key); - return { - propertySignatures, - indexSignatures - }; -}; -var pick2 = (ast, keys5) => { - const annotation = getSurrogateAnnotation(ast); - if (isSome2(annotation)) { - return pick2(annotation.value, keys5); + }), () => result); +})); +var scheduleFromStep = (step3, first2) => { + if (!first2) { + return fromRetryOptions({ + schedule: step3.schedule ? step3.schedule : step3.attempts ? undefined : once2, + times: step3.attempts, + while: step3.while + }); + } else if (step3.attempts === 1 || !(step3.schedule || step3.attempts)) { + return; } - switch (ast._tag) { - case "TypeLiteral": { - const pss = []; - const names = {}; - for (const ps of ast.propertySignatures) { - names[ps.name] = null; - if (keys5.includes(ps.name)) { - pss.push(ps); - } - } - for (const key of keys5) { - if (!(key in names)) { - const ps = getTypeLiteralPropertySignature(ast, key); - if (ps) { - pss.push(ps); - } - } - } - return new TypeLiteral(pss, []); - } - case "Union": - return new TypeLiteral(keys5.map((name) => getPropertyKeyIndexedAccess(ast, name)), []); - case "Suspend": - return pick2(ast.f(), keys5); - case "Refinement": - return pick2(ast.from, keys5); - case "Transformation": { - switch (ast.transformation._tag) { - case "ComposeTransformation": - return new Transformation(pick2(ast.from, keys5), pick2(ast.to, keys5), composeTransformation); - case "TypeLiteralTransformation": { - const ts = []; - const fromKeys = []; - for (const k of keys5) { - const t = ast.transformation.propertySignatureTransformations.find((t2) => t2.to === k); - if (t) { - ts.push(t); - fromKeys.push(t.from); - } else { - fromKeys.push(k); + return fromRetryOptions({ + schedule: step3.schedule, + while: step3.while, + times: step3.attempts ? step3.attempts - 1 : undefined + }); +}; + +// node_modules/effect/dist/esm/internal/query.js +var currentCache = /* @__PURE__ */ globalValue(/* @__PURE__ */ Symbol.for("effect/FiberRef/currentCache"), () => fiberRefUnsafeMake(unsafeMakeWith(65536, () => map9(deferredMake(), (handle) => ({ + listeners: new Listeners, + handle +})), () => seconds(60)))); +var currentCacheEnabled = /* @__PURE__ */ globalValue(/* @__PURE__ */ Symbol.for("effect/FiberRef/currentCacheEnabled"), () => fiberRefUnsafeMake(false)); +var fromRequest = (request, dataSource) => flatMap7(isEffect(dataSource) ? dataSource : succeed(dataSource), (ds) => fiberIdWith((id) => { + const proxy = new Proxy(request, {}); + return fiberRefGetWith(currentCacheEnabled, (cacheEnabled) => { + if (cacheEnabled) { + const cached3 = fiberRefGetWith(currentCache, (cache) => flatMap7(cache.getEither(proxy), (orNew) => { + switch (orNew._tag) { + case "Left": { + if (orNew.left.listeners.interrupted) { + return flatMap7(cache.invalidateWhen(proxy, (entry) => entry.handle === orNew.left.handle), () => cached3); } + orNew.left.listeners.increment(); + return uninterruptibleMask((restore) => flatMap7(exit(blocked(empty15, restore(deferredAwait(orNew.left.handle)))), (exit2) => { + orNew.left.listeners.decrement(); + return exit2; + })); + } + case "Right": { + orNew.right.listeners.increment(); + return uninterruptibleMask((restore) => flatMap7(exit(blocked(single(ds, makeEntry({ + request: proxy, + result: orNew.right.handle, + listeners: orNew.right.listeners, + ownerId: id, + state: { + completed: false + } + })), restore(deferredAwait(orNew.right.handle)))), () => { + orNew.right.listeners.decrement(); + return deferredAwait(orNew.right.handle); + })); } - return isNonEmptyReadonlyArray(ts) ? new Transformation(pick2(ast.from, fromKeys), pick2(ast.to, keys5), new TypeLiteralTransformation(ts)) : pick2(ast.from, fromKeys); } - } - } - } - throw new Error(getASTUnsupportedSchemaErrorMessage(ast)); -}; -var omit2 = (ast, keys5) => { - let indexSignatures = getIndexSignatures(ast); - if (indexSignatures.length > 0) { - if (indexSignatures.some((is) => isStringKeyword(getEncodedParameter(is.parameter)))) { - indexSignatures = indexSignatures.filter((is) => !isTemplateLiteral(getEncodedParameter(is.parameter))); + })); + return cached3; } - return new TypeLiteral([], indexSignatures); - } - return pick2(ast, getPropertyKeys(ast).filter((name) => !keys5.includes(name))); -}; -var orUndefined = (ast) => Union.make([ast, undefinedKeyword]); -var partial = (ast, options) => { - const exact = options?.exact === true; - switch (ast._tag) { - case "TupleType": - return new TupleType(ast.elements.map((e) => new OptionalType(exact ? e.type : orUndefined(e.type), true)), match3(ast.rest, { - onEmpty: () => ast.rest, - onNonEmpty: (rest) => [new Type(Union.make([...getRestASTs(rest), undefinedKeyword]))] - }), ast.isReadonly); - case "TypeLiteral": - return new TypeLiteral(ast.propertySignatures.map((ps) => new PropertySignature(ps.name, exact ? ps.type : orUndefined(ps.type), true, ps.isReadonly, ps.annotations)), ast.indexSignatures.map((is) => new IndexSignature(is.parameter, orUndefined(is.type), is.isReadonly))); - case "Union": - return Union.make(ast.types.map((member) => partial(member, options))); - case "Suspend": - return new Suspend(() => partial(ast.f(), options)); - case "Declaration": - case "Refinement": - throw new Error(getASTUnsupportedSchemaErrorMessage(ast)); - case "Transformation": { - if (isTypeLiteralTransformation(ast.transformation) && ast.transformation.propertySignatureTransformations.every(isRenamingPropertySignatureTransformation)) { - return new Transformation(partial(ast.from, options), partial(ast.to, options), ast.transformation); + const listeners = new Listeners; + listeners.increment(); + return flatMap7(deferredMake(), (ref) => ensuring(blocked(single(ds, makeEntry({ + request: proxy, + result: ref, + listeners, + ownerId: id, + state: { + completed: false } - throw new Error(getASTUnsupportedSchemaErrorMessage(ast)); + })), deferredAwait(ref)), sync(() => listeners.decrement()))); + }); +})); +var cacheRequest = (request, result) => { + return fiberRefGetWith(currentCacheEnabled, (cacheEnabled) => { + if (cacheEnabled) { + return fiberRefGetWith(currentCache, (cache) => flatMap7(cache.getEither(request), (orNew) => { + switch (orNew._tag) { + case "Left": { + return void_; + } + case "Right": { + return deferredComplete(orNew.right.handle, result); + } + } + })); } - } - return ast; + return void_; + }); }; -var required = (ast) => { - switch (ast._tag) { - case "TupleType": - return new TupleType(ast.elements.map((e) => new OptionalType(e.type, false)), ast.rest, ast.isReadonly); - case "TypeLiteral": - return new TypeLiteral(ast.propertySignatures.map((f) => new PropertySignature(f.name, f.type, false, f.isReadonly, f.annotations)), ast.indexSignatures); - case "Union": - return Union.make(ast.types.map((member) => required(member))); - case "Suspend": - return new Suspend(() => required(ast.f())); - case "Declaration": - case "Refinement": - throw new Error(getASTUnsupportedSchemaErrorMessage(ast)); - case "Transformation": { - if (isTypeLiteralTransformation(ast.transformation) && ast.transformation.propertySignatureTransformations.every(isRenamingPropertySignatureTransformation)) { - return new Transformation(required(ast.from), required(ast.to), ast.transformation); +var withRequestCaching = /* @__PURE__ */ dual(2, (self, strategy) => fiberRefLocally(self, currentCacheEnabled, strategy)); +var withRequestCache = /* @__PURE__ */ dual(2, (self, cache) => fiberRefLocally(self, currentCache, cache)); + +// node_modules/effect/dist/esm/Request.js +var isRequest2 = isRequest; +var Class4 = Class2; + +// node_modules/effect/dist/esm/Effect.js +var EffectTypeId3 = EffectTypeId2; +var isEffect2 = isEffect; +var cachedWithTTL = cached2; +var cachedInvalidateWithTTL2 = cachedInvalidateWithTTL; +var cached3 = memoize; +var cachedFunction2 = cachedFunction; +var once3 = once; +var all3 = all2; +var allWith2 = allWith; +var allSuccesses2 = allSuccesses; +var dropUntil2 = dropUntil; +var dropWhile2 = dropWhile; +var takeUntil2 = takeUntil; +var takeWhile2 = takeWhile; +var every6 = every4; +var exists3 = exists2; +var filter7 = filter5; +var filterMap5 = filterMap4; +var findFirst6 = findFirst4; +var forEach7 = forEach6; +var head4 = head3; +var mergeAll5 = mergeAll3; +var partition4 = partition3; +var reduce10 = reduce8; +var reduceWhile2 = reduceWhile; +var reduceRight3 = reduceRight2; +var reduceEffect2 = reduceEffect; +var replicate2 = replicate; +var replicateEffect2 = replicateEffect; +var validateAll2 = validateAll; +var validateFirst2 = validateFirst; +var async = async_; +var asyncEffect2 = asyncEffect; +var custom2 = custom; +var withFiberRuntime2 = withFiberRuntime; +var fail5 = fail2; +var failSync2 = failSync; +var failCause5 = failCause; +var failCauseSync2 = failCauseSync; +var die4 = die2; +var dieMessage2 = dieMessage; +var dieSync2 = dieSync; +var gen2 = gen; +var never2 = never; +var none9 = none6; +var promise2 = promise; +var succeed6 = succeed; +var succeedNone2 = succeedNone; +var succeedSome2 = succeedSome; +var suspend3 = suspend; +var sync3 = sync; +var _void = void_; +var yieldNow4 = yieldNow; +var _catch2 = _catch; +var catchAll2 = catchAll; +var catchAllCause2 = catchAllCause; +var catchAllDefect2 = catchAllDefect; +var catchIf2 = catchIf; +var catchSome2 = catchSome; +var catchSomeCause2 = catchSomeCause; +var catchSomeDefect2 = catchSomeDefect; +var catchTag2 = catchTag; +var catchTags2 = catchTags; +var cause2 = cause; +var eventually2 = eventually; +var ignore2 = ignore; +var ignoreLogged2 = ignoreLogged; +var parallelErrors2 = parallelErrors; +var sandbox2 = sandbox; +var retry = retry_combined; +var withExecutionPlan2 = withExecutionPlan; +var retryOrElse = retryOrElse_Effect; +var try_3 = try_2; +var tryMap2 = tryMap; +var tryMapPromise2 = tryMapPromise; +var tryPromise2 = tryPromise; +var unsandbox2 = unsandbox; +var allowInterrupt2 = allowInterrupt; +var checkInterruptible2 = checkInterruptible; +var disconnect2 = disconnect; +var interrupt5 = interrupt2; +var interruptWith2 = interruptWith; +var interruptible4 = interruptible2; +var interruptibleMask2 = interruptibleMask; +var onInterrupt2 = onInterrupt; +var uninterruptible2 = uninterruptible; +var uninterruptibleMask3 = uninterruptibleMask; +var liftPredicate2 = liftPredicate; +var as3 = as; +var asSome2 = asSome; +var asSomeError2 = asSomeError; +var asVoid3 = asVoid; +var flip2 = flip; +var flipWith2 = flipWith; +var map11 = map9; +var mapAccum3 = mapAccum2; +var mapBoth3 = mapBoth2; +var mapError2 = mapError; +var mapErrorCause2 = mapErrorCause; +var merge6 = merge5; +var negate2 = negate; +var acquireRelease2 = acquireRelease; +var acquireReleaseInterruptible2 = acquireReleaseInterruptible; +var acquireUseRelease2 = acquireUseRelease; +var addFinalizer2 = addFinalizer; +var ensuring2 = ensuring; +var onError2 = onError; +var onExit3 = onExit; +var parallelFinalizers2 = parallelFinalizers; +var sequentialFinalizers2 = sequentialFinalizers; +var finalizersMask2 = finalizersMask; +var scope2 = scope; +var scopeWith2 = scopeWith; +var scopedWith2 = scopedWith; +var scoped2 = scopedEffect; +var using2 = using; +var withEarlyRelease2 = withEarlyRelease; +var awaitAllChildren2 = awaitAllChildren; +var daemonChildren2 = daemonChildren; +var descriptor2 = descriptor; +var descriptorWith2 = descriptorWith; +var diffFiberRefs2 = diffFiberRefs; +var ensuringChild2 = ensuringChild; +var ensuringChildren2 = ensuringChildren; +var fiberId2 = fiberId; +var fiberIdWith2 = fiberIdWith; +var fork3 = fork; +var forkDaemon2 = forkDaemon; +var forkAll2 = forkAll; +var forkIn2 = forkIn; +var forkScoped2 = forkScoped; +var forkWithErrorHandler2 = forkWithErrorHandler; +var fromFiber2 = fromFiber; +var fromFiberEffect2 = fromFiberEffect; +var supervised2 = supervised; +var transplant2 = transplant; +var withConcurrency2 = withConcurrency; +var withScheduler2 = withScheduler; +var withSchedulingPriority2 = withSchedulingPriority; +var withMaxOpsBeforeYield2 = withMaxOpsBeforeYield; +var clock2 = clock; +var clockWith4 = clockWith3; +var withClockScoped2 = withClockScoped; +var withClock2 = withClock; +var console3 = console2; +var consoleWith2 = consoleWith; +var withConsoleScoped2 = withConsoleScoped; +var withConsole2 = withConsole; +var delay2 = delay; +var sleep4 = sleep3; +var timed2 = timed; +var timedWith2 = timedWith; +var timeout2 = timeout; +var timeoutOption2 = timeoutOption; +var timeoutFail2 = timeoutFail; +var timeoutFailCause2 = timeoutFailCause; +var timeoutTo2 = timeoutTo; +var configProviderWith2 = configProviderWith; +var withConfigProvider2 = withConfigProvider; +var withConfigProviderScoped2 = withConfigProviderScoped; +var context3 = context; +var contextWith2 = contextWith; +var contextWithEffect2 = contextWithEffect; +var mapInputContext2 = mapInputContext; +var provide2 = effect_provide; +var provideService2 = provideService; +var provideServiceEffect2 = provideServiceEffect; +var serviceFunction2 = serviceFunction; +var serviceFunctionEffect2 = serviceFunctionEffect; +var serviceFunctions2 = serviceFunctions; +var serviceConstants2 = serviceConstants; +var serviceMembers2 = serviceMembers; +var serviceOption2 = serviceOption; +var serviceOptional2 = serviceOptional; +var updateService2 = updateService; +var Do2 = Do; +var bind3 = bind2; +var bindAll2 = bindAll; +var bindTo3 = bindTo2; +var let_3 = let_2; +var option2 = option; +var either3 = either2; +var exit2 = exit; +var intoDeferred2 = intoDeferred; +var if_2 = if_; +var filterOrDie2 = filterOrDie; +var filterOrDieMessage2 = filterOrDieMessage; +var filterOrElse2 = filterOrElse; +var filterOrFail2 = filterOrFail; +var filterEffectOrElse2 = filterEffectOrElse; +var filterEffectOrFail2 = filterEffectOrFail; +var unless2 = unless; +var unlessEffect2 = unlessEffect; +var when2 = when; +var whenEffect2 = whenEffect; +var whenFiberRef2 = whenFiberRef; +var whenRef2 = whenRef; +var flatMap9 = flatMap7; +var andThen4 = andThen2; +var flatten7 = flatten5; +var race2 = race; +var raceAll2 = raceAll; +var raceFirst2 = raceFirst; +var raceWith2 = raceWith; +var summarized2 = summarized; +var tap2 = tap; +var tapBoth2 = tapBoth; +var tapDefect2 = tapDefect; +var tapError2 = tapError; +var tapErrorTag2 = tapErrorTag; +var tapErrorCause2 = tapErrorCause; +var forever3 = forever; +var iterate2 = iterate; +var loop2 = loop; +var repeat = repeat_combined; +var repeatN2 = repeatN; +var repeatOrElse = repeatOrElse_Effect; +var schedule = schedule_Effect; +var scheduleForked2 = scheduleForked; +var scheduleFrom = scheduleFrom_Effect; +var whileLoop2 = whileLoop; +var getFiberRefs = fiberRefs2; +var inheritFiberRefs2 = inheritFiberRefs; +var locally = fiberRefLocally; +var locallyWith = fiberRefLocallyWith; +var locallyScoped = fiberRefLocallyScoped; +var locallyScopedWith = fiberRefLocallyScopedWith; +var patchFiberRefs2 = patchFiberRefs; +var setFiberRefs2 = setFiberRefs; +var updateFiberRefs2 = updateFiberRefs; +var isFailure3 = isFailure; +var isSuccess3 = isSuccess2; +var match10 = match7; +var matchCause2 = matchCause; +var matchCauseEffect3 = matchCauseEffect; +var matchEffect2 = matchEffect; +var log2 = log; +var logWithLevel2 = (level, ...message) => logWithLevel(level)(...message); +var logTrace2 = logTrace; +var logDebug2 = logDebug; +var logInfo2 = logInfo; +var logWarning2 = logWarning; +var logError2 = logError; +var logFatal2 = logFatal; +var withLogSpan2 = withLogSpan; +var annotateLogs2 = annotateLogs; +var annotateLogsScoped2 = annotateLogsScoped; +var logAnnotations2 = logAnnotations; +var withUnhandledErrorLogLevel2 = withUnhandledErrorLogLevel; +var whenLogLevel2 = whenLogLevel; +var orDie2 = orDie; +var orDieWith2 = orDieWith; +var orElse3 = orElse2; +var orElseFail2 = orElseFail; +var orElseSucceed2 = orElseSucceed; +var firstSuccessOf2 = firstSuccessOf; +var random3 = random2; +var randomWith2 = randomWith; +var withRandom2 = withRandom; +var withRandomFixed = /* @__PURE__ */ dual(2, (effect, values4) => withRandom2(effect, fixed2(values4))); +var withRandomScoped2 = withRandomScoped; +var runtime4 = runtime3; +var getRuntimeFlags = runtimeFlags; +var patchRuntimeFlags = updateRuntimeFlags; +var withRuntimeFlagsPatch = withRuntimeFlags; +var withRuntimeFlagsPatchScoped = withRuntimeFlagsScoped; +var tagMetrics2 = tagMetrics; +var labelMetrics2 = labelMetrics; +var tagMetricsScoped2 = tagMetricsScoped; +var labelMetricsScoped2 = labelMetricsScoped; +var metricLabels2 = metricLabels; +var withMetric2 = withMetric; +var unsafeMakeSemaphore2 = unsafeMakeSemaphore; +var makeSemaphore2 = makeSemaphore; +var unsafeMakeLatch2 = unsafeMakeLatch; +var makeLatch2 = makeLatch; +var runFork2 = unsafeForkEffect; +var runCallback = unsafeRunEffect; +var runPromise = unsafeRunPromiseEffect; +var runPromiseExit = unsafeRunPromiseExitEffect; +var runSync = unsafeRunSyncEffect; +var runSyncExit = unsafeRunSyncExitEffect; +var validate2 = validate; +var validateWith2 = validateWith; +var zip4 = zipOptions; +var zipLeft2 = zipLeftOptions; +var zipRight2 = zipRightOptions; +var zipWith3 = zipWithOptions; +var ap = /* @__PURE__ */ dual(2, (self, that) => zipWith3(self, that, (f, a) => f(a))); +var blocked2 = blocked; +var runRequestBlock2 = runRequestBlock; +var step3 = step2; +var request = /* @__PURE__ */ dual((args2) => isRequest2(args2[0]), fromRequest); +var cacheRequestResult = cacheRequest; +var withRequestBatching2 = withRequestBatching; +var withRequestCaching2 = withRequestCaching; +var withRequestCache2 = withRequestCache; +var tracer2 = tracer; +var tracerWith4 = tracerWith; +var withTracer2 = withTracer; +var withTracerScoped2 = withTracerScoped; +var withTracerEnabled2 = withTracerEnabled; +var withTracerTiming2 = withTracerTiming; +var annotateSpans2 = annotateSpans; +var annotateCurrentSpan2 = annotateCurrentSpan; +var currentSpan2 = currentSpan; +var currentPropagatedSpan2 = currentPropagatedSpan; +var currentParentSpan2 = currentParentSpan; +var spanAnnotations2 = spanAnnotations; +var spanLinks2 = spanLinks; +var linkSpans2 = linkSpans; +var linkSpanCurrent2 = linkSpanCurrent; +var makeSpan2 = makeSpan; +var makeSpanScoped2 = makeSpanScoped; +var useSpan2 = useSpan; +var withSpan2 = withSpan; +var functionWithSpan2 = functionWithSpan; +var withSpanScoped2 = withSpanScoped; +var withParentSpan2 = withParentSpan; +var fromNullable3 = fromNullable2; +var optionFromOptional2 = optionFromOptional; +var transposeOption = (self) => { + return isNone(self) ? succeedNone2 : map11(self.value, some); +}; +var transposeMapOption = /* @__PURE__ */ dual(2, (self, f) => isNone(self) ? succeedNone2 : map11(f(self.value), some)); +var makeTagProxy = (TagClass) => { + const cache = new Map; + return new Proxy(TagClass, { + get(target, prop, receiver) { + if (prop in target) { + return Reflect.get(target, prop, receiver); } - throw new Error(getASTUnsupportedSchemaErrorMessage(ast)); + if (cache.has(prop)) { + return cache.get(prop); + } + const fn = (...args2) => andThen2(target, (s) => { + if (typeof s[prop] === "function") { + cache.set(prop, (...args3) => andThen2(target, (s2) => s2[prop](...args3))); + return s[prop](...args2); + } + cache.set(prop, andThen2(target, (s2) => s2[prop])); + return s[prop]; + }); + const cn = andThen2(target, (s) => s[prop]); + Object.assign(fn, cn); + const apply = fn.apply; + const bind4 = fn.bind; + const call = fn.call; + const proto4 = Object.setPrototypeOf({}, Object.getPrototypeOf(cn)); + proto4.apply = apply; + proto4.bind = bind4; + proto4.call = call; + Object.setPrototypeOf(fn, proto4); + cache.set(prop, fn); + return fn; } - } - return ast; + }); }; -var mutable = (ast) => { - switch (ast._tag) { - case "TupleType": - return ast.isReadonly === false ? ast : new TupleType(ast.elements, ast.rest, false, ast.annotations); - case "TypeLiteral": { - const propertySignatures = changeMap(ast.propertySignatures, (ps) => ps.isReadonly === false ? ps : new PropertySignature(ps.name, ps.type, ps.isOptional, false, ps.annotations)); - const indexSignatures = changeMap(ast.indexSignatures, (is) => is.isReadonly === false ? is : new IndexSignature(is.parameter, is.type, false)); - return propertySignatures === ast.propertySignatures && indexSignatures === ast.indexSignatures ? ast : new TypeLiteral(propertySignatures, indexSignatures, ast.annotations); - } - case "Union": { - const types = changeMap(ast.types, mutable); - return types === ast.types ? ast : Union.make(types, ast.annotations); - } - case "Suspend": - return new Suspend(() => mutable(ast.f()), ast.annotations); - case "Refinement": { - const from = mutable(ast.from); - return from === ast.from ? ast : new Refinement(from, ast.filter, ast.annotations); +var Tag2 = (id) => () => { + const limit = Error.stackTraceLimit; + Error.stackTraceLimit = 2; + const creationError = new Error; + Error.stackTraceLimit = limit; + function TagClass() {} + Object.setPrototypeOf(TagClass, TagProto); + TagClass.key = id; + Object.defineProperty(TagClass, "use", { + get() { + return (body) => andThen2(this, body); } - case "Transformation": { - const from = mutable(ast.from); - const to = mutable(ast.to); - return from === ast.from && to === ast.to ? ast : new Transformation(from, to, ast.transformation, ast.annotations); + }); + Object.defineProperty(TagClass, "stack", { + get() { + return creationError.stack; } - } - return ast; + }); + return makeTagProxy(TagClass); }; -var pickAnnotations = (annotationIds) => (annotated) => { - let out = undefined; - for (const id of annotationIds) { - if (Object.prototype.hasOwnProperty.call(annotated.annotations, id)) { - if (out === undefined) { - out = {}; +var Service = function() { + return function() { + const [id, maker] = arguments; + const proxy = "accessors" in maker ? maker["accessors"] : false; + const limit = Error.stackTraceLimit; + Error.stackTraceLimit = 2; + const creationError = new Error; + Error.stackTraceLimit = limit; + let patchState = "unchecked"; + const TagClass = function(service) { + if (patchState === "unchecked") { + const proto4 = Object.getPrototypeOf(service); + if (proto4 === Object.prototype || proto4 === null) { + patchState = "plain"; + } else { + const selfProto = Object.getPrototypeOf(this); + Object.setPrototypeOf(selfProto, proto4); + patchState = "patched"; + } } - out[id] = annotated.annotations[id]; - } - } - return out; -}; -var omitAnnotations = (annotationIds) => (annotated) => { - const out = { - ...annotated.annotations - }; - for (const id of annotationIds) { - delete out[id]; - } - return out; -}; -var preserveTransformationAnnotations = /* @__PURE__ */ pickAnnotations([ExamplesAnnotationId, DefaultAnnotationId, JSONSchemaAnnotationId, ArbitraryAnnotationId, PrettyAnnotationId, EquivalenceAnnotationId]); -var typeAST = (ast) => { - switch (ast._tag) { - case "Declaration": { - const typeParameters = changeMap(ast.typeParameters, typeAST); - return typeParameters === ast.typeParameters ? ast : new Declaration(typeParameters, ast.decodeUnknown, ast.encodeUnknown, ast.annotations); - } - case "TupleType": { - const elements = changeMap(ast.elements, (e) => { - const type = typeAST(e.type); - return type === e.type ? e : new OptionalType(type, e.isOptional); + if (patchState === "plain") { + Object.assign(this, service); + } else if (patchState === "patched") { + Object.setPrototypeOf(service, Object.getPrototypeOf(this)); + return service; + } + }; + TagClass.prototype._tag = id; + Object.defineProperty(TagClass, "make", { + get() { + return (service) => new this(service); + } + }); + Object.defineProperty(TagClass, "use", { + get() { + return (body) => andThen2(this, body); + } + }); + TagClass.key = id; + Object.assign(TagClass, TagProto); + Object.defineProperty(TagClass, "stack", { + get() { + return creationError.stack; + } + }); + const hasDeps = "dependencies" in maker && maker.dependencies.length > 0; + const layerName = hasDeps ? "DefaultWithoutDependencies" : "Default"; + let layerCache; + let isFunction3 = false; + if ("effect" in maker) { + isFunction3 = typeof maker.effect === "function"; + Object.defineProperty(TagClass, layerName, { + get() { + if (isFunction3) { + return function() { + return fromEffect2(TagClass, map11(maker.effect.apply(null, arguments), (_) => new this(_))); + }.bind(this); + } + return layerCache ??= fromEffect2(TagClass, map11(maker.effect, (_) => new this(_))); + } }); - const restASTs = getRestASTs(ast.rest); - const rest = changeMap(restASTs, typeAST); - return elements === ast.elements && rest === restASTs ? ast : new TupleType(elements, rest.map((type) => new Type(type)), ast.isReadonly, ast.annotations); - } - case "TypeLiteral": { - const propertySignatures = changeMap(ast.propertySignatures, (p) => { - const type = typeAST(p.type); - return type === p.type ? p : new PropertySignature(p.name, type, p.isOptional, p.isReadonly); + } else if ("scoped" in maker) { + isFunction3 = typeof maker.scoped === "function"; + Object.defineProperty(TagClass, layerName, { + get() { + if (isFunction3) { + return function() { + return scoped(TagClass, map11(maker.scoped.apply(null, arguments), (_) => new this(_))); + }.bind(this); + } + return layerCache ??= scoped(TagClass, map11(maker.scoped, (_) => new this(_))); + } }); - const indexSignatures = changeMap(ast.indexSignatures, (is) => { - const type = typeAST(is.type); - return type === is.type ? is : new IndexSignature(is.parameter, type, is.isReadonly); + } else if ("sync" in maker) { + Object.defineProperty(TagClass, layerName, { + get() { + return layerCache ??= sync2(TagClass, () => new this(maker.sync())); + } + }); + } else { + Object.defineProperty(TagClass, layerName, { + get() { + return layerCache ??= succeed4(TagClass, new this(maker.succeed)); + } }); - return propertySignatures === ast.propertySignatures && indexSignatures === ast.indexSignatures ? ast : new TypeLiteral(propertySignatures, indexSignatures, ast.annotations); - } - case "Union": { - const types = changeMap(ast.types, typeAST); - return types === ast.types ? ast : Union.make(types, ast.annotations); - } - case "Suspend": - return new Suspend(() => typeAST(ast.f()), ast.annotations); - case "Refinement": { - const from = typeAST(ast.from); - return from === ast.from ? ast : new Refinement(from, ast.filter, ast.annotations); - } - case "Transformation": { - const preserve = preserveTransformationAnnotations(ast); - return typeAST(preserve !== undefined ? annotations(ast.to, preserve) : ast.to); - } - } - return ast; -}; -function changeMap(as4, f) { - let changed = false; - const out = allocate(as4.length); - for (let i = 0;i < as4.length; i++) { - const a = as4[i]; - const fa = f(a); - if (fa !== a) { - changed = true; - } - out[i] = fa; - } - return changed ? out : as4; -} -var getTransformationFrom = (ast) => { - switch (ast._tag) { - case "Transformation": - return ast.from; - case "Refinement": - return getTransformationFrom(ast.from); - case "Suspend": - return getTransformationFrom(ast.f()); - } -}; -var encodedAST_ = (ast, isBound) => { - switch (ast._tag) { - case "Declaration": { - const typeParameters = changeMap(ast.typeParameters, (ast2) => encodedAST_(ast2, isBound)); - return typeParameters === ast.typeParameters ? ast : new Declaration(typeParameters, ast.decodeUnknown, ast.encodeUnknown); } - case "TupleType": { - const elements = changeMap(ast.elements, (e) => { - const type = encodedAST_(e.type, isBound); - return type === e.type ? e : new OptionalType(type, e.isOptional); + if (hasDeps) { + let layerWithDepsCache; + Object.defineProperty(TagClass, "Default", { + get() { + if (isFunction3) { + return function() { + return provide(this.DefaultWithoutDependencies.apply(null, arguments), maker.dependencies); + }; + } + return layerWithDepsCache ??= provide(this.DefaultWithoutDependencies, maker.dependencies); + } }); - const restASTs = getRestASTs(ast.rest); - const rest = changeMap(restASTs, (ast2) => encodedAST_(ast2, isBound)); - return elements === ast.elements && rest === restASTs ? ast : new TupleType(elements, rest.map((ast2) => new Type(ast2)), ast.isReadonly); } - case "TypeLiteral": { - const propertySignatures = changeMap(ast.propertySignatures, (ps) => { - const type = encodedAST_(ps.type, isBound); - return type === ps.type ? ps : new PropertySignature(ps.name, type, ps.isOptional, ps.isReadonly); + return proxy === true ? makeTagProxy(TagClass) : TagClass; + }; +}; +var fn = function(nameOrBody, ...pipeables) { + const limit = Error.stackTraceLimit; + Error.stackTraceLimit = 2; + const errorDef = new Error; + Error.stackTraceLimit = limit; + if (typeof nameOrBody !== "string") { + return defineLength(nameOrBody.length, function(...args2) { + const limit2 = Error.stackTraceLimit; + Error.stackTraceLimit = 2; + const errorCall = new Error; + Error.stackTraceLimit = limit2; + return fnApply({ + self: this, + body: nameOrBody, + args: args2, + pipeables, + spanName: "", + spanOptions: { + context: DisablePropagation.context(true) + }, + errorDef, + errorCall }); - const indexSignatures = changeMap(ast.indexSignatures, (is) => { - const type = encodedAST_(is.type, isBound); - return type === is.type ? is : new IndexSignature(is.parameter, type, is.isReadonly); + }); + } + const name = nameOrBody; + const options = pipeables[0]; + return (body, ...pipeables2) => defineLength(body.length, { + [name](...args2) { + const limit2 = Error.stackTraceLimit; + Error.stackTraceLimit = 2; + const errorCall = new Error; + Error.stackTraceLimit = limit2; + return fnApply({ + self: this, + body, + args: args2, + pipeables: pipeables2, + spanName: name, + spanOptions: options, + errorDef, + errorCall }); - return propertySignatures === ast.propertySignatures && indexSignatures === ast.indexSignatures ? ast : new TypeLiteral(propertySignatures, indexSignatures); } - case "Union": { - const types = changeMap(ast.types, (ast2) => encodedAST_(ast2, isBound)); - return types === ast.types ? ast : Union.make(types); + }[name]); +}; +function defineLength(length2, fn2) { + return Object.defineProperty(fn2, "length", { + value: length2, + configurable: true + }); +} +function fnApply(options) { + let effect; + let fnError = undefined; + if (isGeneratorFunction(options.body)) { + effect = fromIterator(() => options.body.apply(options.self, options.args)); + } else { + try { + effect = options.body.apply(options.self, options.args); + } catch (error) { + fnError = error; + effect = die4(error); } - case "Suspend": { - let borrowedAnnotations = undefined; - const identifier2 = getJSONIdentifier(ast); - if (isSome2(identifier2)) { - const suffix = isBound ? "Bound" : ""; - borrowedAnnotations = { - [JSONIdentifierAnnotationId]: `${identifier2.value}Encoded${suffix}` - }; + } + if (options.pipeables.length > 0) { + try { + for (const x of options.pipeables) { + effect = x(effect, ...options.args); } - return new Suspend(() => encodedAST_(ast.f(), isBound), borrowedAnnotations); + } catch (error) { + effect = fnError ? failCause5(sequential(die(fnError), die(error))) : die4(error); } - case "Refinement": { - const from = encodedAST_(ast.from, isBound); - if (isBound) { - if (from === ast.from) - return ast; - if (getTransformationFrom(ast.from) === undefined && hasStableFilter(ast)) { - return new Refinement(from, ast.filter, ast.annotations); - } - return from; - } else { - return from; + } + let cache = false; + const captureStackTrace = () => { + if (cache !== false) { + return cache; + } + if (options.errorCall.stack) { + const stackDef = options.errorDef.stack.trim().split(` +`); + const stackCall = options.errorCall.stack.trim().split(` +`); + let endStackDef = stackDef.slice(2).join(` +`).trim(); + if (!endStackDef.includes(`(`)) { + endStackDef = endStackDef.replace(/at (.*)/, "at ($1)"); + } + let endStackCall = stackCall.slice(2).join(` +`).trim(); + if (!endStackCall.includes(`(`)) { + endStackCall = endStackCall.replace(/at (.*)/, "at ($1)"); } + cache = `${endStackDef} +${endStackCall}`; + return cache; } - case "Transformation": - return encodedAST_(ast.from, isBound); + }; + const opts = options.spanOptions && "captureStackTrace" in options.spanOptions ? options.spanOptions : { + captureStackTrace, + ...options.spanOptions + }; + return withSpan2(effect, options.spanName, opts); +} +var fnUntraced2 = fnUntraced; +var ensureSuccessType = () => (effect) => effect; +var ensureErrorType = () => (effect) => effect; +var ensureRequirementsType = () => (effect) => effect; +// node_modules/effect/dist/esm/ConfigError.js +var InvalidData2 = InvalidData; + +// node_modules/effect/dist/esm/internal/redacted.js +var RedactedSymbolKey = "effect/Redacted"; +var redactedRegistry = /* @__PURE__ */ globalValue("effect/Redacted/redactedRegistry", () => new WeakMap); +var RedactedTypeId = /* @__PURE__ */ Symbol.for(RedactedSymbolKey); +var proto4 = { + [RedactedTypeId]: { + _A: (_) => _ + }, + pipe() { + return pipeArguments(this, arguments); + }, + toString() { + return ""; + }, + toJSON() { + return ""; + }, + [NodeInspectSymbol]() { + return ""; + }, + [symbol]() { + return pipe(hash(RedactedSymbolKey), combine(hash(redactedRegistry.get(this))), cached(this)); + }, + [symbol2](that) { + return isRedacted(that) && equals(redactedRegistry.get(this), redactedRegistry.get(that)); + } +}; +var isRedacted = (u) => hasProperty(u, RedactedTypeId); +var make40 = (value) => { + const redacted = Object.create(proto4); + redactedRegistry.set(redacted, value); + return redacted; +}; +var value = (self) => { + if (redactedRegistry.has(self)) { + return redactedRegistry.get(self); + } else { + throw new Error("Unable to get redacted value"); + } +}; + +// node_modules/effect/dist/esm/internal/config.js +var ConfigSymbolKey = "effect/Config"; +var ConfigTypeId = /* @__PURE__ */ Symbol.for(ConfigSymbolKey); +var configVariance = { + _A: (_) => _ +}; +var proto5 = { + ...CommitPrototype, + [ConfigTypeId]: configVariance, + commit() { + return config(this); + } +}; +var mapOrFail = /* @__PURE__ */ dual(2, (self, f) => { + const mapOrFail2 = Object.create(proto5); + mapOrFail2._tag = OP_MAP_OR_FAIL; + mapOrFail2.original = self; + mapOrFail2.mapOrFail = f; + return mapOrFail2; +}); +var nested2 = /* @__PURE__ */ dual(2, (self, name) => { + const nested3 = Object.create(proto5); + nested3._tag = OP_NESTED; + nested3.name = name; + nested3.config = self; + return nested3; +}); +var primitive = (description, parse2) => { + const primitive2 = Object.create(proto5); + primitive2._tag = OP_PRIMITIVE; + primitive2.description = description; + primitive2.parse = parse2; + return primitive2; +}; +var string2 = (name) => { + const config2 = primitive("a text property", right2); + return name === undefined ? config2 : nested2(config2, name); +}; + +// node_modules/effect/dist/esm/Config.js +var mapOrFail2 = mapOrFail; +var string3 = string2; +// node_modules/effect/dist/esm/DateTime.js +var isDateTime2 = isDateTime; +var isTimeZoneOffset2 = isTimeZoneOffset; +var isTimeZoneNamed2 = isTimeZoneNamed; +var isUtc2 = isUtc; +var isZoned2 = isZoned; +var Equivalence4 = Equivalence3; +var unsafeFromDate2 = unsafeFromDate; +var unsafeMake9 = unsafeMake8; +var unsafeMakeZoned2 = unsafeMakeZoned; +var makeZonedFromString2 = makeZonedFromString; +var zoneUnsafeMakeNamed2 = zoneUnsafeMakeNamed; +var zoneMakeOffset2 = zoneMakeOffset; +var zoneFromString2 = zoneFromString; +var zoneToString2 = zoneToString; +var toDateUtc2 = toDateUtc; +var toEpochMillis2 = toEpochMillis; +var formatIso2 = formatIso; +var formatIsoZoned2 = formatIsoZoned; +// node_modules/effect/dist/esm/internal/encoding/common.js +var DecodeExceptionTypeId = /* @__PURE__ */ Symbol.for("effect/Encoding/errors/Decode"); +var DecodeException = (input, message) => { + const out = { + _tag: "DecodeException", + [DecodeExceptionTypeId]: DecodeExceptionTypeId, + input + }; + if (isString(message)) { + out.message = message; } - return ast; + return out; }; -var encodedAST = (ast) => encodedAST_(ast, false); -var encodedBoundAST = (ast) => encodedAST_(ast, true); -var toJSONAnnotations = (annotations2) => { - const out = {}; - for (const k of Object.getOwnPropertySymbols(annotations2)) { - out[String(k)] = annotations2[k]; +var EncodeExceptionTypeId = /* @__PURE__ */ Symbol.for("effect/Encoding/errors/Encode"); +var EncodeException = (input, message) => { + const out = { + _tag: "EncodeException", + [EncodeExceptionTypeId]: EncodeExceptionTypeId, + input + }; + if (isString(message)) { + out.message = message; } return out; }; -var getEncodedParameter = (ast) => { - switch (ast._tag) { - case "StringKeyword": - case "SymbolKeyword": - case "TemplateLiteral": - return ast; - case "Refinement": - return getEncodedParameter(ast.from); +var encoder = /* @__PURE__ */ new TextEncoder; +var decoder = /* @__PURE__ */ new TextDecoder; + +// node_modules/effect/dist/esm/internal/encoding/base64.js +var encode = (bytes) => { + const length2 = bytes.length; + let result = ""; + let i; + for (i = 2;i < length2; i += 3) { + result += base64abc[bytes[i - 2] >> 2]; + result += base64abc[(bytes[i - 2] & 3) << 4 | bytes[i - 1] >> 4]; + result += base64abc[(bytes[i - 1] & 15) << 2 | bytes[i] >> 6]; + result += base64abc[bytes[i] & 63]; } -}; -var equals4 = (self, that) => { - switch (self._tag) { - case "Literal": - return isLiteral(that) && that.literal === self.literal; - case "UniqueSymbol": - return isUniqueSymbol(that) && that.symbol === self.symbol; - case "UndefinedKeyword": - case "VoidKeyword": - case "NeverKeyword": - case "UnknownKeyword": - case "AnyKeyword": - case "StringKeyword": - case "NumberKeyword": - case "BooleanKeyword": - case "BigIntKeyword": - case "SymbolKeyword": - case "ObjectKeyword": - return that._tag === self._tag; - case "TemplateLiteral": - return isTemplateLiteral(that) && that.head === self.head && equalsTemplateLiteralSpan(that.spans, self.spans); - case "Enums": - return isEnums(that) && equalsEnums(that.enums, self.enums); - case "Union": - return isUnion(that) && equalsUnion(self.types, that.types); - case "Refinement": - case "TupleType": - case "TypeLiteral": - case "Suspend": - case "Transformation": - case "Declaration": - return self === that; + if (i === length2 + 1) { + result += base64abc[bytes[i - 2] >> 2]; + result += base64abc[(bytes[i - 2] & 3) << 4]; + result += "=="; } -}; -var equalsTemplateLiteralSpan = /* @__PURE__ */ getEquivalence3((self, that) => { - return self.literal === that.literal && equals4(self.type, that.type); -}); -var equalsEnums = /* @__PURE__ */ getEquivalence3((self, that) => that[0] === self[0] && that[1] === self[1]); -var equalsUnion = /* @__PURE__ */ getEquivalence3(equals4); -var intersection3 = /* @__PURE__ */ intersectionWith(equals4); -var _keyof = (ast) => { - switch (ast._tag) { - case "Declaration": { - const annotation = getSurrogateAnnotation(ast); - if (isSome2(annotation)) { - return _keyof(annotation.value); - } - break; - } - case "TypeLiteral": - return ast.propertySignatures.map((p) => isSymbol(p.name) ? new UniqueSymbol(p.name) : new Literal(p.name)).concat(ast.indexSignatures.map((is) => getEncodedParameter(is.parameter))); - case "Suspend": - return _keyof(ast.f()); - case "Union": - return ast.types.slice(1).reduce((out, ast2) => intersection3(out, _keyof(ast2)), _keyof(ast.types[0])); - case "Transformation": - return _keyof(ast.to); + if (i === length2) { + result += base64abc[bytes[i - 2] >> 2]; + result += base64abc[(bytes[i - 2] & 3) << 4 | bytes[i - 1] >> 4]; + result += base64abc[(bytes[i - 1] & 15) << 2]; + result += "="; } - throw new Error(getASTUnsupportedSchemaErrorMessage(ast)); + return result; }; -var compose = (ab, cd) => new Transformation(ab, cd, composeTransformation); -var rename = (ast, mapping) => { - switch (ast._tag) { - case "TypeLiteral": { - const propertySignatureTransformations = []; - for (const key of Reflect.ownKeys(mapping)) { - const name = mapping[key]; - if (name !== undefined) { - propertySignatureTransformations.push(new PropertySignatureTransformation(key, name, identity, identity)); - } - } - if (propertySignatureTransformations.length === 0) { - return ast; - } - return new Transformation(ast, new TypeLiteral(ast.propertySignatures.map((ps) => { - const name = mapping[ps.name]; - return new PropertySignature(name === undefined ? ps.name : name, typeAST(ps.type), ps.isOptional, ps.isReadonly, ps.annotations); - }), ast.indexSignatures), new TypeLiteralTransformation(propertySignatureTransformations)); +var decode2 = (str) => { + const stripped = stripCrlf(str); + const length2 = stripped.length; + if (length2 % 4 !== 0) { + return left2(DecodeException(stripped, `Length must be a multiple of 4, but is ${length2}`)); + } + const index = stripped.indexOf("="); + if (index !== -1 && (index < length2 - 2 || index === length2 - 2 && stripped[length2 - 1] !== "=")) { + return left2(DecodeException(stripped, "Found a '=' character, but it is not at the end")); + } + try { + const missingOctets = stripped.endsWith("==") ? 2 : stripped.endsWith("=") ? 1 : 0; + const result = new Uint8Array(3 * (length2 / 4) - missingOctets); + for (let i = 0, j = 0;i < length2; i += 4, j += 3) { + const buffer = getBase64Code(stripped.charCodeAt(i)) << 18 | getBase64Code(stripped.charCodeAt(i + 1)) << 12 | getBase64Code(stripped.charCodeAt(i + 2)) << 6 | getBase64Code(stripped.charCodeAt(i + 3)); + result[j] = buffer >> 16; + result[j + 1] = buffer >> 8 & 255; + result[j + 2] = buffer & 255; } - case "Union": - return Union.make(ast.types.map((ast2) => rename(ast2, mapping))); - case "Suspend": - return new Suspend(() => rename(ast.f(), mapping)); - case "Transformation": - return compose(ast, rename(typeAST(ast), mapping)); + return right2(result); + } catch (e) { + return left2(DecodeException(stripped, e instanceof Error ? e.message : "Invalid input")); } - throw new Error(getASTUnsupportedRenameSchemaErrorMessage(ast)); }; -var formatKeyword = (ast) => getOrElse(getExpected(ast), () => ast._tag); -function getBrands(ast) { - return match2(getBrandAnnotation(ast), { - onNone: () => "", - onSome: (brands) => brands.map((brand) => ` & Brand<${formatUnknown(brand)}>`).join("") - }); +var stripCrlf = (str) => str.replace(/[\n\r]/g, ""); +function getBase64Code(charCode) { + if (charCode >= base64codes.length) { + throw new TypeError(`Invalid character ${String.fromCharCode(charCode)}`); + } + const code = base64codes[charCode]; + if (code === 255) { + throw new TypeError(`Invalid character ${String.fromCharCode(charCode)}`); + } + return code; } -var getOrElseExpected = (ast) => getTitleAnnotation(ast).pipe(orElse(() => getDescriptionAnnotation(ast)), orElse(() => getAutoTitleAnnotation(ast)), map2((s) => s + getBrands(ast))); -var getExpected = (ast) => orElse(getIdentifierAnnotation(ast), () => getOrElseExpected(ast)); -var pruneUndefined = (ast, self, onTransformation) => { - switch (ast._tag) { - case "UndefinedKeyword": - return neverKeyword; - case "Union": { - const types = []; - let hasUndefined = false; - for (const type of ast.types) { - const pruned = self(type); - if (pruned) { - hasUndefined = true; - if (!isNeverKeyword(pruned)) { - types.push(pruned); - } - } else { - types.push(type); - } - } - if (hasUndefined) { - return Union.make(types); - } - break; +var base64abc = ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "+", "/"]; +var base64codes = [255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 62, 255, 255, 255, 63, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 255, 255, 255, 0, 255, 255, 255, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 255, 255, 255, 255, 255, 255, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51]; + +// node_modules/effect/dist/esm/internal/encoding/base64Url.js +var encode2 = (data) => encode(data).replace(/=/g, "").replace(/\+/g, "-").replace(/\//g, "_"); +var decode3 = (str) => { + const stripped = stripCrlf(str); + const length2 = stripped.length; + if (length2 % 4 === 1) { + return left2(DecodeException(stripped, `Length should be a multiple of 4, but is ${length2}`)); + } + if (!/^[-_A-Z0-9]*?={0,2}$/i.test(stripped)) { + return left2(DecodeException(stripped, "Invalid input")); + } + let sanitized = length2 % 4 === 2 ? `${stripped}==` : length2 % 4 === 3 ? `${stripped}=` : stripped; + sanitized = sanitized.replace(/-/g, "+").replace(/_/g, "/"); + return decode2(sanitized); +}; + +// node_modules/effect/dist/esm/internal/encoding/hex.js +var encode3 = (bytes) => { + let result = ""; + for (let i = 0;i < bytes.length; ++i) { + result += bytesToHex[bytes[i]]; + } + return result; +}; +var decode4 = (str) => { + const bytes = new TextEncoder().encode(str); + if (bytes.length % 2 !== 0) { + return left2(DecodeException(str, `Length must be a multiple of 2, but is ${bytes.length}`)); + } + try { + const length2 = bytes.length / 2; + const result = new Uint8Array(length2); + for (let i = 0;i < length2; i++) { + const a = fromHexChar(bytes[i * 2]); + const b = fromHexChar(bytes[i * 2 + 1]); + result[i] = a << 4 | b; } - case "Suspend": - return self(ast.f()); - case "Transformation": - return onTransformation(ast); + return right2(result); + } catch (e) { + return left2(DecodeException(str, e instanceof Error ? e.message : "Invalid input")); + } +}; +var bytesToHex = ["00", "01", "02", "03", "04", "05", "06", "07", "08", "09", "0a", "0b", "0c", "0d", "0e", "0f", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "1a", "1b", "1c", "1d", "1e", "1f", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "2a", "2b", "2c", "2d", "2e", "2f", "30", "31", "32", "33", "34", "35", "36", "37", "38", "39", "3a", "3b", "3c", "3d", "3e", "3f", "40", "41", "42", "43", "44", "45", "46", "47", "48", "49", "4a", "4b", "4c", "4d", "4e", "4f", "50", "51", "52", "53", "54", "55", "56", "57", "58", "59", "5a", "5b", "5c", "5d", "5e", "5f", "60", "61", "62", "63", "64", "65", "66", "67", "68", "69", "6a", "6b", "6c", "6d", "6e", "6f", "70", "71", "72", "73", "74", "75", "76", "77", "78", "79", "7a", "7b", "7c", "7d", "7e", "7f", "80", "81", "82", "83", "84", "85", "86", "87", "88", "89", "8a", "8b", "8c", "8d", "8e", "8f", "90", "91", "92", "93", "94", "95", "96", "97", "98", "99", "9a", "9b", "9c", "9d", "9e", "9f", "a0", "a1", "a2", "a3", "a4", "a5", "a6", "a7", "a8", "a9", "aa", "ab", "ac", "ad", "ae", "af", "b0", "b1", "b2", "b3", "b4", "b5", "b6", "b7", "b8", "b9", "ba", "bb", "bc", "bd", "be", "bf", "c0", "c1", "c2", "c3", "c4", "c5", "c6", "c7", "c8", "c9", "ca", "cb", "cc", "cd", "ce", "cf", "d0", "d1", "d2", "d3", "d4", "d5", "d6", "d7", "d8", "d9", "da", "db", "dc", "dd", "de", "df", "e0", "e1", "e2", "e3", "e4", "e5", "e6", "e7", "e8", "e9", "ea", "eb", "ec", "ed", "ee", "ef", "f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7", "f8", "f9", "fa", "fb", "fc", "fd", "fe", "ff"]; +var fromHexChar = (byte) => { + if (48 <= byte && byte <= 57) { + return byte - 48; + } + if (97 <= byte && byte <= 102) { + return byte - 97 + 10; + } + if (65 <= byte && byte <= 70) { + return byte - 65 + 10; } + throw new TypeError("Invalid input"); }; +// node_modules/effect/dist/esm/Encoding.js +var encodeBase64 = (input) => typeof input === "string" ? encode(encoder.encode(input)) : encode(input); +var decodeBase64 = (str) => decode2(str); +var decodeBase64String = (str) => map(decodeBase64(str), (_) => decoder.decode(_)); +var encodeBase64Url = (input) => typeof input === "string" ? encode2(encoder.encode(input)) : encode2(input); +var decodeBase64Url = (str) => decode3(str); +var decodeBase64UrlString = (str) => map(decodeBase64Url(str), (_) => decoder.decode(_)); +var encodeHex = (input) => typeof input === "string" ? encode3(encoder.encode(input)) : encode3(input); +var decodeHex = (str) => decode4(str); +var decodeHexString = (str) => map(decodeHex(str), (_) => decoder.decode(_)); +var encodeUriComponent = (str) => try_({ + try: () => encodeURIComponent(str), + catch: (e) => EncodeException2(str, e instanceof Error ? e.message : "Invalid input") +}); +var decodeUriComponent = (str) => try_({ + try: () => decodeURIComponent(str), + catch: (e) => DecodeException2(str, e instanceof Error ? e.message : "Invalid input") +}); +var DecodeException2 = DecodeException; +var EncodeException2 = EncodeException; // node_modules/effect/dist/esm/ParseResult.js class Pointer { path; @@ -19322,7 +18922,7 @@ var handleForbidden = (effect, ast, actual, options) => { scheduler.flush(); const exit3 = fiber.unsafePoll(); if (exit3) { - if (isSuccess2(exit3)) { + if (isSuccess(exit3)) { return right2(exit3.value); } const cause3 = exit3.cause; @@ -19504,7 +19104,7 @@ var formatTree = (issue) => { return right2(makeTree(message)); } const parseIssueTitle = getParseIssueTitle(issue); - return isNonEmpty6(issue.issues) ? map13(forEach7(issue.issues, formatTree), (forest) => makeTree(parseIssueTitle, forest)) : map13(formatTree(issue.issues), (tree) => makeTree(parseIssueTitle, [tree])); + return isNonEmpty(issue.issues) ? map13(forEach7(issue.issues, formatTree), (forest) => makeTree(parseIssueTitle, forest)) : map13(formatTree(issue.issues), (tree) => makeTree(parseIssueTitle, [tree])); }); } }; @@ -19513,57 +19113,442 @@ var makeArrayFormatterIssue = (_tag, path, message) => ({ path, message }); -var ArrayFormatter = { - formatIssue: (issue) => getArrayFormatterIssues(issue, undefined, []), - formatIssueSync: (issue) => { - const e = ArrayFormatter.formatIssue(issue); - return isEither3(e) ? getOrThrow(e) : runSync(e); - }, - formatError: (error) => ArrayFormatter.formatIssue(error.issue), - formatErrorSync: (error) => ArrayFormatter.formatIssueSync(error.issue) -}; -var getArrayFormatterIssues = (issue, parentTag, path) => { - const _tag = issue._tag; - switch (_tag) { - case "Type": - return map13(formatTypeMessage(issue), (message) => [makeArrayFormatterIssue(parentTag ?? _tag, path, message)]); - case "Forbidden": - return right2([makeArrayFormatterIssue(_tag, path, formatForbiddenMessage(issue))]); - case "Unexpected": - return right2([makeArrayFormatterIssue(_tag, path, formatUnexpectedMessage(issue))]); - case "Missing": - return map13(formatMissingMessage(issue), (message) => [makeArrayFormatterIssue(_tag, path, message)]); - case "Pointer": - return getArrayFormatterIssues(issue.issue, undefined, path.concat(issue.path)); - case "Composite": - return flatMap10(getMessage(issue), (message) => { - if (message !== undefined) { - return right2([makeArrayFormatterIssue(_tag, path, message)]); - } - return isNonEmpty6(issue.issues) ? map13(forEach7(issue.issues, (issue2) => getArrayFormatterIssues(issue2, undefined, path)), flatten) : getArrayFormatterIssues(issue.issues, undefined, path); - }); - case "Refinement": - return flatMap10(getMessage(issue), (message) => { - if (message !== undefined) { - return right2([makeArrayFormatterIssue(_tag, path, message)]); - } - return getArrayFormatterIssues(issue.issue, issue.kind === "Predicate" ? _tag : undefined, path); - }); - case "Transformation": - return flatMap10(getMessage(issue), (message) => { - if (message !== undefined) { - return right2([makeArrayFormatterIssue(_tag, path, message)]); - } - return getArrayFormatterIssues(issue.issue, issue.kind === "Transformation" ? _tag : undefined, path); - }); - } -}; - -// node_modules/effect/dist/esm/Redacted.js -var isRedacted2 = isRedacted; -var make42 = make40; -var value2 = value; -var getEquivalence7 = (isEquivalent) => make((x, y) => isEquivalent(value2(x), value2(y))); +var ArrayFormatter = { + formatIssue: (issue) => getArrayFormatterIssues(issue, undefined, []), + formatIssueSync: (issue) => { + const e = ArrayFormatter.formatIssue(issue); + return isEither3(e) ? getOrThrow(e) : runSync(e); + }, + formatError: (error) => ArrayFormatter.formatIssue(error.issue), + formatErrorSync: (error) => ArrayFormatter.formatIssueSync(error.issue) +}; +var getArrayFormatterIssues = (issue, parentTag, path) => { + const _tag = issue._tag; + switch (_tag) { + case "Type": + return map13(formatTypeMessage(issue), (message) => [makeArrayFormatterIssue(parentTag ?? _tag, path, message)]); + case "Forbidden": + return right2([makeArrayFormatterIssue(_tag, path, formatForbiddenMessage(issue))]); + case "Unexpected": + return right2([makeArrayFormatterIssue(_tag, path, formatUnexpectedMessage(issue))]); + case "Missing": + return map13(formatMissingMessage(issue), (message) => [makeArrayFormatterIssue(_tag, path, message)]); + case "Pointer": + return getArrayFormatterIssues(issue.issue, undefined, path.concat(issue.path)); + case "Composite": + return flatMap10(getMessage(issue), (message) => { + if (message !== undefined) { + return right2([makeArrayFormatterIssue(_tag, path, message)]); + } + return isNonEmpty(issue.issues) ? map13(forEach7(issue.issues, (issue2) => getArrayFormatterIssues(issue2, undefined, path)), flatten) : getArrayFormatterIssues(issue.issues, undefined, path); + }); + case "Refinement": + return flatMap10(getMessage(issue), (message) => { + if (message !== undefined) { + return right2([makeArrayFormatterIssue(_tag, path, message)]); + } + return getArrayFormatterIssues(issue.issue, issue.kind === "Predicate" ? _tag : undefined, path); + }); + case "Transformation": + return flatMap10(getMessage(issue), (message) => { + if (message !== undefined) { + return right2([makeArrayFormatterIssue(_tag, path, message)]); + } + return getArrayFormatterIssues(issue.issue, issue.kind === "Transformation" ? _tag : undefined, path); + }); + } +}; +// node_modules/effect/dist/esm/Redacted.js +var isRedacted2 = isRedacted; +var make42 = make40; +var value2 = value; +var getEquivalence7 = (isEquivalent) => make((x, y) => isEquivalent(value2(x), value2(y))); +// node_modules/effect/dist/esm/Schema.js +var exports_Schema = {}; +__export(exports_Schema, { + withDefaults: () => withDefaults, + withDecodingDefault: () => withDecodingDefault, + withConstructorDefault: () => withConstructorDefault, + validateSync: () => validateSync, + validatePromise: () => validatePromise, + validateOption: () => validateOption, + validateEither: () => validateEither2, + validate: () => validate5, + validDate: () => validDate, + uppercased: () => uppercased, + uncapitalized: () => uncapitalized, + typeSchema: () => typeSchema, + trimmed: () => trimmed, + transformOrFail: () => transformOrFail, + transformLiterals: () => transformLiterals, + transformLiteral: () => transformLiteral, + transform: () => transform2, + tag: () => tag, + symbolWithResult: () => symbolWithResult, + symbolSerializable: () => symbolSerializable, + suspend: () => suspend5, + successSchema: () => successSchema, + startsWith: () => startsWith, + standardSchemaV1: () => standardSchemaV1, + split: () => split, + serializeSuccess: () => serializeSuccess, + serializeFailure: () => serializeFailure, + serializeExit: () => serializeExit, + serialize: () => serialize, + serializableSchema: () => serializableSchema, + requiredToOptional: () => requiredToOptional, + required: () => required2, + rename: () => rename2, + propertySignature: () => propertySignature, + positiveBigInt: () => positiveBigInt, + positiveBigDecimal: () => positiveBigDecimal, + positive: () => positive, + pluck: () => pluck, + pickLiteral: () => pickLiteral, + pick: () => pick4, + pattern: () => pattern, + partialWith: () => partialWith, + partial: () => partial2, + parseNumber: () => parseNumber, + parseJson: () => parseJson, + optionalWith: () => optionalWith, + optionalToRequired: () => optionalToRequired, + optionalToOptional: () => optionalToOptional, + optionalElement: () => optionalElement, + optional: () => optional, + omit: () => omit4, + nonPositiveBigInt: () => nonPositiveBigInt, + nonPositiveBigDecimal: () => nonPositiveBigDecimal, + nonPositive: () => nonPositive, + nonNegativeBigInt: () => nonNegativeBigInt, + nonNegativeBigDecimal: () => nonNegativeBigDecimal, + nonNegative: () => nonNegative, + nonNaN: () => nonNaN, + nonEmptyString: () => nonEmptyString2, + negativeBigInt: () => negativeBigInt, + negativeBigDecimal: () => negativeBigDecimal, + negative: () => negative, + mutable: () => mutable2, + multipleOf: () => multipleOf, + minLength: () => minLength, + minItems: () => minItems, + maxLength: () => maxLength, + maxItems: () => maxItems, + makePropertySignature: () => makePropertySignature, + make: () => make43, + lowercased: () => lowercased, + lessThanOrEqualToDuration: () => lessThanOrEqualToDuration, + lessThanOrEqualToDate: () => lessThanOrEqualToDate, + lessThanOrEqualToBigInt: () => lessThanOrEqualToBigInt, + lessThanOrEqualToBigDecimal: () => lessThanOrEqualToBigDecimal, + lessThanOrEqualTo: () => lessThanOrEqualTo5, + lessThanDuration: () => lessThanDuration, + lessThanDate: () => lessThanDate, + lessThanBigInt: () => lessThanBigInt, + lessThanBigDecimal: () => lessThanBigDecimal, + lessThan: () => lessThan9, + length: () => length2, + keyof: () => keyof2, + itemsCount: () => itemsCount, + isSchema: () => isSchema, + isPropertySignature: () => isPropertySignature, + is: () => is, + int: () => int, + instanceOf: () => instanceOf, + includes: () => includes, + headOrElse: () => headOrElse, + headNonEmpty: () => headNonEmpty3, + head: () => head5, + greaterThanOrEqualToDuration: () => greaterThanOrEqualToDuration, + greaterThanOrEqualToDate: () => greaterThanOrEqualToDate, + greaterThanOrEqualToBigInt: () => greaterThanOrEqualToBigInt, + greaterThanOrEqualToBigDecimal: () => greaterThanOrEqualToBigDecimal, + greaterThanOrEqualTo: () => greaterThanOrEqualTo5, + greaterThanDuration: () => greaterThanDuration, + greaterThanDate: () => greaterThanDate, + greaterThanBigInt: () => greaterThanBigInt, + greaterThanBigDecimal: () => greaterThanBigDecimal, + greaterThan: () => greaterThan6, + getNumberIndexedAccess: () => getNumberIndexedAccess2, + getClassTag: () => getClassTag, + fromKey: () => fromKey, + fromBrand: () => fromBrand, + format: () => format6, + finite: () => finite, + filterEffect: () => filterEffect, + filter: () => filter8, + failureSchema: () => failureSchema, + extend: () => extend2, + exitSchema: () => exitSchema, + equivalence: () => equivalence2, + endsWith: () => endsWith, + encodedSchema: () => encodedSchema, + encodedBoundSchema: () => encodedBoundSchema, + encodeUnknownSync: () => encodeUnknownSync, + encodeUnknownPromise: () => encodeUnknownPromise, + encodeUnknownOption: () => encodeUnknownOption, + encodeUnknownEither: () => encodeUnknownEither2, + encodeUnknown: () => encodeUnknown2, + encodeSync: () => encodeSync, + encodePromise: () => encodePromise, + encodeOption: () => encodeOption, + encodeEither: () => encodeEither, + encode: () => encode4, + element: () => element, + deserializeSuccess: () => deserializeSuccess, + deserializeFailure: () => deserializeFailure, + deserializeExit: () => deserializeExit, + deserialize: () => deserialize, + decodeUnknownSync: () => decodeUnknownSync, + decodeUnknownPromise: () => decodeUnknownPromise, + decodeUnknownOption: () => decodeUnknownOption, + decodeUnknownEither: () => decodeUnknownEither2, + decodeUnknown: () => decodeUnknown2, + decodeSync: () => decodeSync, + decodePromise: () => decodePromise, + decodeOption: () => decodeOption, + decodeEither: () => decodeEither, + decode: () => decode5, + declare: () => declare, + compose: () => compose2, + clampDuration: () => clampDuration, + clampBigInt: () => clampBigInt, + clampBigDecimal: () => clampBigDecimal, + clamp: () => clamp8, + capitalized: () => capitalized, + brand: () => brand, + betweenDuration: () => betweenDuration, + betweenDate: () => betweenDate, + betweenBigInt: () => betweenBigInt, + betweenBigDecimal: () => betweenBigDecimal, + between: () => between5, + attachPropertySignature: () => attachPropertySignature, + asserts: () => asserts, + asWithResult: () => asWithResult, + asSerializableWithResult: () => asSerializableWithResult, + asSerializable: () => asSerializable, + asSchema: () => asSchema, + annotations: () => annotations2, + Void: () => Void, + ValidDateSchemaId: () => ValidDateSchemaId, + ValidDateFromSelf: () => ValidDateFromSelf, + UppercasedSchemaId: () => UppercasedSchemaId, + Uppercased: () => Uppercased, + Uppercase: () => Uppercase, + Unknown: () => Unknown, + UniqueSymbolFromSelf: () => UniqueSymbolFromSelf, + Union: () => Union2, + UndefinedOr: () => UndefinedOr, + Undefined: () => Undefined, + UncapitalizedSchemaId: () => UncapitalizedSchemaId, + Uncapitalized: () => Uncapitalized, + Uncapitalize: () => Uncapitalize, + Uint8ArrayFromSelf: () => Uint8ArrayFromSelf, + Uint8ArrayFromHex: () => Uint8ArrayFromHex, + Uint8ArrayFromBase64Url: () => Uint8ArrayFromBase64Url, + Uint8ArrayFromBase64: () => Uint8ArrayFromBase64, + Uint8Array: () => Uint8Array$, + Uint8: () => Uint8, + UUIDSchemaId: () => UUIDSchemaId, + UUID: () => UUID, + URLFromSelf: () => URLFromSelf, + URL: () => URL$, + ULIDSchemaId: () => ULIDSchemaId, + ULID: () => ULID, + TypeId: () => TypeId18, + Tuple: () => Tuple, + TrimmedSchemaId: () => TrimmedSchemaId, + Trimmed: () => Trimmed, + Trim: () => Trim, + ToPropertySignature: () => ToPropertySignature, + TimeZoneOffsetFromSelf: () => TimeZoneOffsetFromSelf, + TimeZoneOffset: () => TimeZoneOffset, + TimeZoneNamedFromSelf: () => TimeZoneNamedFromSelf, + TimeZoneNamed: () => TimeZoneNamed, + TimeZoneFromSelf: () => TimeZoneFromSelf, + TimeZone: () => TimeZone, + TemplateLiteralParser: () => TemplateLiteralParser, + TemplateLiteral: () => TemplateLiteral2, + TaggedStruct: () => TaggedStruct, + TaggedRequest: () => TaggedRequest, + TaggedError: () => TaggedError2, + TaggedClass: () => TaggedClass3, + SymbolFromSelf: () => SymbolFromSelf, + Symbol: () => Symbol$, + Struct: () => Struct, + StringFromUriComponent: () => StringFromUriComponent, + StringFromHex: () => StringFromHex, + StringFromBase64Url: () => StringFromBase64Url, + StringFromBase64: () => StringFromBase64, + String: () => String$, + StartsWithSchemaId: () => StartsWithSchemaId, + SortedSetFromSelf: () => SortedSetFromSelf, + SortedSet: () => SortedSet, + SetFromSelf: () => SetFromSelf, + Set: () => set6, + RefineSchemaId: () => RefineSchemaId, + RedactedFromSelf: () => RedactedFromSelf, + Redacted: () => Redacted, + Record: () => Record, + ReadonlySetFromSelf: () => ReadonlySetFromSelf, + ReadonlySet: () => ReadonlySet, + ReadonlyMapFromSelf: () => ReadonlyMapFromSelf, + ReadonlyMapFromRecord: () => ReadonlyMapFromRecord, + ReadonlyMap: () => ReadonlyMap, + PropertySignatureTypeId: () => PropertySignatureTypeId, + PropertySignatureTransformation: () => PropertySignatureTransformation2, + PropertySignatureDeclaration: () => PropertySignatureDeclaration, + PropertyKey: () => PropertyKey$, + PositiveBigIntFromSelf: () => PositiveBigIntFromSelf, + PositiveBigInt: () => PositiveBigInt, + PositiveBigDecimalSchemaId: () => PositiveBigDecimalSchemaId, + PositiveBigDecimalFromSelf: () => PositiveBigDecimalFromSelf, + Positive: () => Positive, + PatternSchemaId: () => PatternSchemaId, + OptionFromUndefinedOr: () => OptionFromUndefinedOr, + OptionFromSelf: () => OptionFromSelf, + OptionFromNullishOr: () => OptionFromNullishOr, + OptionFromNullOr: () => OptionFromNullOr, + OptionFromNonEmptyTrimmedString: () => OptionFromNonEmptyTrimmedString, + Option: () => Option, + Object: () => Object$, + NumberFromString: () => NumberFromString, + Number: () => Number$, + NullishOr: () => NullishOr, + NullOr: () => NullOr, + Null: () => Null, + Not: () => Not, + NonPositiveBigIntFromSelf: () => NonPositiveBigIntFromSelf, + NonPositiveBigInt: () => NonPositiveBigInt, + NonPositiveBigDecimalSchemaId: () => NonPositiveBigDecimalSchemaId, + NonPositiveBigDecimalFromSelf: () => NonPositiveBigDecimalFromSelf, + NonPositive: () => NonPositive, + NonNegativeInt: () => NonNegativeInt, + NonNegativeBigIntFromSelf: () => NonNegativeBigIntFromSelf, + NonNegativeBigInt: () => NonNegativeBigInt, + NonNegativeBigDecimalSchemaId: () => NonNegativeBigDecimalSchemaId, + NonNegativeBigDecimalFromSelf: () => NonNegativeBigDecimalFromSelf, + NonNegative: () => NonNegative, + NonNaNSchemaId: () => NonNaNSchemaId2, + NonNaN: () => NonNaN, + NonEmptyTrimmedString: () => NonEmptyTrimmedString, + NonEmptyString: () => NonEmptyString, + NonEmptyChunkFromSelf: () => NonEmptyChunkFromSelf, + NonEmptyChunk: () => NonEmptyChunk, + NonEmptyArrayEnsure: () => NonEmptyArrayEnsure, + NonEmptyArray: () => NonEmptyArray, + Never: () => Never, + NegativeBigIntFromSelf: () => NegativeBigIntFromSelf, + NegativeBigInt: () => NegativeBigInt, + NegativeBigDecimalSchemaId: () => NegativeBigDecimalSchemaId, + NegativeBigDecimalFromSelf: () => NegativeBigDecimalFromSelf, + Negative: () => Negative, + MultipleOfSchemaId: () => MultipleOfSchemaId, + MinLengthSchemaId: () => MinLengthSchemaId2, + MinItemsSchemaId: () => MinItemsSchemaId2, + MaxLengthSchemaId: () => MaxLengthSchemaId2, + MaxItemsSchemaId: () => MaxItemsSchemaId2, + MapFromSelf: () => MapFromSelf, + MapFromRecord: () => MapFromRecord, + Map: () => map14, + LowercasedSchemaId: () => LowercasedSchemaId, + Lowercased: () => Lowercased, + Lowercase: () => Lowercase, + Literal: () => Literal2, + ListFromSelf: () => ListFromSelf, + List: () => List, + LessThanSchemaId: () => LessThanSchemaId2, + LessThanOrEqualToSchemaId: () => LessThanOrEqualToSchemaId2, + LessThanOrEqualToDurationSchemaId: () => LessThanOrEqualToDurationSchemaId, + LessThanOrEqualToDateSchemaId: () => LessThanOrEqualToDateSchemaId, + LessThanOrEqualToBigIntSchemaId: () => LessThanOrEqualToBigIntSchemaId2, + LessThanOrEqualToBigDecimalSchemaId: () => LessThanOrEqualToBigDecimalSchemaId, + LessThanDurationSchemaId: () => LessThanDurationSchemaId, + LessThanDateSchemaId: () => LessThanDateSchemaId, + LessThanBigIntSchemaId: () => LessThanBigIntSchemaId2, + LessThanBigDecimalSchemaId: () => LessThanBigDecimalSchemaId, + LengthSchemaId: () => LengthSchemaId2, + JsonNumberSchemaId: () => JsonNumberSchemaId2, + JsonNumber: () => JsonNumber, + ItemsCountSchemaId: () => ItemsCountSchemaId2, + IntSchemaId: () => IntSchemaId2, + Int: () => Int, + InstanceOfSchemaId: () => InstanceOfSchemaId, + IncludesSchemaId: () => IncludesSchemaId, + HashSetFromSelf: () => HashSetFromSelf, + HashSet: () => HashSet, + HashMapFromSelf: () => HashMapFromSelf, + HashMap: () => HashMap, + GreaterThanSchemaId: () => GreaterThanSchemaId2, + GreaterThanOrEqualToSchemaId: () => GreaterThanOrEqualToSchemaId2, + GreaterThanOrEqualToDurationSchemaId: () => GreaterThanOrEqualToDurationSchemaId, + GreaterThanOrEqualToDateSchemaId: () => GreaterThanOrEqualToDateSchemaId, + GreaterThanOrEqualToBigIntSchemaId: () => GreaterThanOrEqualToBigIntSchemaId2, + GreaterThanOrEqualToBigDecimalSchemaId: () => GreaterThanOrEqualToBigDecimalSchemaId, + GreaterThanDurationSchemaId: () => GreaterThanDurationSchemaId, + GreaterThanDateSchemaId: () => GreaterThanDateSchemaId, + GreaterThanBigIntSchemaId: () => GreaterThanBigIntSchemaId, + GreaterThanBigDecimalSchemaId: () => GreaterThanBigDecimalSchemaId, + FromPropertySignature: () => FromPropertySignature, + FiniteSchemaId: () => FiniteSchemaId2, + Finite: () => Finite, + FiberIdFromSelf: () => FiberIdFromSelf, + FiberId: () => FiberId, + ExitFromSelf: () => ExitFromSelf, + Exit: () => Exit, + Enums: () => Enums2, + EndsWithSchemaId: () => EndsWithSchemaId, + EitherFromUnion: () => EitherFromUnion, + EitherFromSelf: () => EitherFromSelf, + Either: () => Either, + DurationFromSelf: () => DurationFromSelf, + DurationFromNanos: () => DurationFromNanos, + DurationFromMillis: () => DurationFromMillis, + Duration: () => Duration, + Defect: () => Defect, + DateTimeZonedFromSelf: () => DateTimeZonedFromSelf, + DateTimeZoned: () => DateTimeZoned, + DateTimeUtcFromSelf: () => DateTimeUtcFromSelf, + DateTimeUtcFromNumber: () => DateTimeUtcFromNumber, + DateTimeUtcFromDate: () => DateTimeUtcFromDate, + DateTimeUtc: () => DateTimeUtc, + DateFromString: () => DateFromString, + DateFromSelfSchemaId: () => DateFromSelfSchemaId2, + DateFromSelf: () => DateFromSelf, + DateFromNumber: () => DateFromNumber, + Date: () => Date$, + DataFromSelf: () => DataFromSelf, + Data: () => Data, + Config: () => Config, + Class: () => Class5, + ChunkFromSelf: () => ChunkFromSelf, + Chunk: () => Chunk, + Char: () => Char, + CauseFromSelf: () => CauseFromSelf, + Cause: () => Cause, + CapitalizedSchemaId: () => CapitalizedSchemaId, + Capitalized: () => Capitalized, + Capitalize: () => Capitalize, + BrandSchemaId: () => BrandSchemaId, + BooleanFromUnknown: () => BooleanFromUnknown, + BooleanFromString: () => BooleanFromString, + Boolean: () => Boolean$, + BigIntFromSelf: () => BigIntFromSelf, + BigIntFromNumber: () => BigIntFromNumber, + BigInt: () => BigInt$, + BigDecimalFromSelf: () => BigDecimalFromSelf, + BigDecimalFromNumber: () => BigDecimalFromNumber, + BigDecimal: () => BigDecimal, + BetweenSchemaId: () => BetweenSchemaId2, + BetweenDurationSchemaId: () => BetweenDurationSchemaId, + BetweenDateSchemaId: () => BetweenDateSchemaId, + BetweenBigIntSchemaId: () => BetweenBigIntSchemaId, + BetweenBigDecimalSchemaId: () => BetweenBigDecimalSchemaId, + ArrayFormatterIssue: () => ArrayFormatterIssue, + ArrayEnsure: () => ArrayEnsure, + Array: () => Array$, + Any: () => Any +}); // node_modules/effect/dist/esm/Struct.js var pick3 = /* @__PURE__ */ dual((args2) => isObject(args2[0]), (s, ...keys5) => { @@ -19611,7 +19596,7 @@ var variance5 = { _I: (_) => _, _R: (_) => _ }; -var makeStandardResult = (exit3) => isSuccess2(exit3) ? exit3.value : makeStandardFailureResult(pretty2(exit3.cause)); +var makeStandardResult = (exit3) => isSuccess(exit3) ? exit3.value : makeStandardFailureResult(pretty2(exit3.cause)); var makeStandardFailureResult = (message) => ({ issues: [{ message @@ -20441,8 +20426,8 @@ function makeRecordClass(key, value3, ast) { }; } var Record = (options) => makeRecordClass(options.key, options.value); -var pick4 = (...keys5) => (self) => make43(pick2(self.ast, keys5)); -var omit4 = (...keys5) => (self) => make43(omit2(self.ast, keys5)); +var pick4 = (...keys5) => (self) => make43(pick(self.ast, keys5)); +var omit4 = (...keys5) => (self) => make43(omit(self.ast, keys5)); var pluck = /* @__PURE__ */ dual(2, (schema, key) => { const ps = getPropertyKeyIndexedAccess(typeAST(schema.ast), key); const value3 = make43(ps.isOptional ? orUndefined(ps.type) : ps.type); @@ -21140,7 +21125,7 @@ var nonNegative = (annotations3) => greaterThanOrEqualTo5(0, { var clamp8 = (minimum, maximum) => (self) => { return transform2(self, typeSchema(self).pipe(between5(minimum, maximum)), { strict: false, - decode: (i) => clamp4(i, { + decode: (i) => clamp3(i, { minimum, maximum }), @@ -21297,7 +21282,7 @@ var nonPositiveBigInt = (annotations3) => lessThanOrEqualToBigInt(0n, { }); var clampBigInt = (minimum, maximum) => (self) => transform2(self, self.pipe(typeSchema, betweenBigInt(minimum, maximum)), { strict: false, - decode: (i) => clamp6(i, { + decode: (i) => clamp5(i, { minimum, maximum }), @@ -21384,7 +21369,7 @@ class DurationFromSelf extends (/* @__PURE__ */ declare(isDuration, { arbitrary: () => (fc) => fc.oneof(fc.constant(infinity), fc.bigInt({ min: 0n }).map((_) => nanos(_)), fc.maxSafeNat().map((_) => millis(_))), - equivalence: () => Equivalence + equivalence: () => Equivalence2 })) { } @@ -21481,14 +21466,14 @@ class Duration extends (/* @__PURE__ */ transform2(Union2(DurationValue, HRTime) } var clampDuration = (minimum, maximum) => (self) => transform2(self, self.pipe(typeSchema, betweenDuration(minimum, maximum)), { strict: false, - decode: (i) => clamp3(i, { + decode: (i) => clamp6(i, { minimum, maximum }), encode: identity }); var LessThanDurationSchemaId = /* @__PURE__ */ Symbol.for("effect/SchemaId/LessThanDuration"); -var lessThanDuration = (max6, annotations3) => (self) => self.pipe(filter8((a) => lessThan2(a, max6), { +var lessThanDuration = (max6, annotations3) => (self) => self.pipe(filter8((a) => lessThan3(a, max6), { schemaId: LessThanDurationSchemaId, [LessThanDurationSchemaId]: { max: max6 @@ -21498,7 +21483,7 @@ var lessThanDuration = (max6, annotations3) => (self) => self.pipe(filter8((a) = ...annotations3 })); var LessThanOrEqualToDurationSchemaId = /* @__PURE__ */ Symbol.for("effect/schema/LessThanOrEqualToDuration"); -var lessThanOrEqualToDuration = (max6, annotations3) => (self) => self.pipe(filter8((a) => lessThanOrEqualTo2(a, max6), { +var lessThanOrEqualToDuration = (max6, annotations3) => (self) => self.pipe(filter8((a) => lessThanOrEqualTo3(a, max6), { schemaId: LessThanDurationSchemaId, [LessThanDurationSchemaId]: { max: max6 @@ -21508,7 +21493,7 @@ var lessThanOrEqualToDuration = (max6, annotations3) => (self) => self.pipe(filt ...annotations3 })); var GreaterThanDurationSchemaId = /* @__PURE__ */ Symbol.for("effect/SchemaId/GreaterThanDuration"); -var greaterThanDuration = (min4, annotations3) => (self) => self.pipe(filter8((a) => greaterThan2(a, min4), { +var greaterThanDuration = (min4, annotations3) => (self) => self.pipe(filter8((a) => greaterThan3(a, min4), { schemaId: GreaterThanDurationSchemaId, [GreaterThanDurationSchemaId]: { min: min4 @@ -21518,7 +21503,7 @@ var greaterThanDuration = (min4, annotations3) => (self) => self.pipe(filter8((a ...annotations3 })); var GreaterThanOrEqualToDurationSchemaId = /* @__PURE__ */ Symbol.for("effect/schema/GreaterThanOrEqualToDuration"); -var greaterThanOrEqualToDuration = (min4, annotations3) => (self) => self.pipe(filter8((a) => greaterThanOrEqualTo2(a, min4), { +var greaterThanOrEqualToDuration = (min4, annotations3) => (self) => self.pipe(filter8((a) => greaterThanOrEqualTo3(a, min4), { schemaId: GreaterThanOrEqualToDurationSchemaId, [GreaterThanOrEqualToDurationSchemaId]: { min: min4 @@ -21528,7 +21513,7 @@ var greaterThanOrEqualToDuration = (min4, annotations3) => (self) => self.pipe(f ...annotations3 })); var BetweenDurationSchemaId = /* @__PURE__ */ Symbol.for("effect/SchemaId/BetweenDuration"); -var betweenDuration = (minimum, maximum, annotations3) => (self) => self.pipe(filter8((a) => between2(a, { +var betweenDuration = (minimum, maximum, annotations3) => (self) => self.pipe(filter8((a) => between3(a, { minimum, maximum }), { @@ -22028,7 +22013,7 @@ function OptionFromUndefinedOr(value3) { class OptionFromNonEmptyTrimmedString extends (/* @__PURE__ */ transform2(String$, /* @__PURE__ */ OptionFromSelf(NonEmptyTrimmedString), { strict: true, - decode: (i) => filter(some2(i.trim()), isNonEmpty5), + decode: (i) => filter(some2(i.trim()), isNonEmpty6), encode: (a) => getOrElse(a, () => "") })) { } @@ -22269,11 +22254,11 @@ function set6(value3) { encode: (a) => Array.from(a) }); } -var bigDecimalPretty = () => (val) => `BigDecimal(${format4(normalize(val))})`; +var bigDecimalPretty = () => (val) => `BigDecimal(${format2(normalize(val))})`; var bigDecimalArbitrary = () => (fc) => fc.tuple(fc.bigInt(), fc.integer({ min: -18, max: 18 -})).map(([value3, scale2]) => make39(value3, scale2)); +})).map(([value3, scale2]) => make4(value3, scale2)); class BigDecimalFromSelf extends (/* @__PURE__ */ declare(isBigDecimal, { typeConstructor: { @@ -22282,7 +22267,7 @@ class BigDecimalFromSelf extends (/* @__PURE__ */ declare(isBigDecimal, { identifier: "BigDecimalFromSelf", pretty: bigDecimalPretty, arbitrary: bigDecimalArbitrary, - equivalence: () => Equivalence3 + equivalence: () => Equivalence })) { } @@ -22294,7 +22279,7 @@ class BigDecimal extends (/* @__PURE__ */ transformOrFail(String$.annotations({ onNone: () => fail7(new Type2(ast, i, `Unable to decode ${JSON.stringify(i)} into a BigDecimal`)), onSome: (val) => succeed8(normalize(val)) })), - encode: (a) => succeed8(format4(normalize(a))) + encode: (a) => succeed8(format2(normalize(a))) }).annotations({ identifier: "BigDecimal" })) { @@ -22312,8 +22297,8 @@ class BigDecimalFromNumber extends (/* @__PURE__ */ transform2(Number$.annotatio } var GreaterThanBigDecimalSchemaId = /* @__PURE__ */ Symbol.for("effect/SchemaId/GreaterThanBigDecimal"); var greaterThanBigDecimal = (min4, annotations3) => (self) => { - const formatted = format4(min4); - return self.pipe(filter8((a) => greaterThan4(a, min4), { + const formatted = format2(min4); + return self.pipe(filter8((a) => greaterThan2(a, min4), { schemaId: GreaterThanBigDecimalSchemaId, [GreaterThanBigDecimalSchemaId]: { min: min4 @@ -22325,8 +22310,8 @@ var greaterThanBigDecimal = (min4, annotations3) => (self) => { }; var GreaterThanOrEqualToBigDecimalSchemaId = /* @__PURE__ */ Symbol.for("effect/schema/GreaterThanOrEqualToBigDecimal"); var greaterThanOrEqualToBigDecimal = (min4, annotations3) => (self) => { - const formatted = format4(min4); - return self.pipe(filter8((a) => greaterThanOrEqualTo3(a, min4), { + const formatted = format2(min4); + return self.pipe(filter8((a) => greaterThanOrEqualTo2(a, min4), { schemaId: GreaterThanOrEqualToBigDecimalSchemaId, [GreaterThanOrEqualToBigDecimalSchemaId]: { min: min4 @@ -22338,8 +22323,8 @@ var greaterThanOrEqualToBigDecimal = (min4, annotations3) => (self) => { }; var LessThanBigDecimalSchemaId = /* @__PURE__ */ Symbol.for("effect/SchemaId/LessThanBigDecimal"); var lessThanBigDecimal = (max6, annotations3) => (self) => { - const formatted = format4(max6); - return self.pipe(filter8((a) => lessThan7(a, max6), { + const formatted = format2(max6); + return self.pipe(filter8((a) => lessThan2(a, max6), { schemaId: LessThanBigDecimalSchemaId, [LessThanBigDecimalSchemaId]: { max: max6 @@ -22351,8 +22336,8 @@ var lessThanBigDecimal = (max6, annotations3) => (self) => { }; var LessThanOrEqualToBigDecimalSchemaId = /* @__PURE__ */ Symbol.for("effect/schema/LessThanOrEqualToBigDecimal"); var lessThanOrEqualToBigDecimal = (max6, annotations3) => (self) => { - const formatted = format4(max6); - return self.pipe(filter8((a) => lessThanOrEqualTo3(a, max6), { + const formatted = format2(max6); + return self.pipe(filter8((a) => lessThanOrEqualTo2(a, max6), { schemaId: LessThanOrEqualToBigDecimalSchemaId, [LessThanOrEqualToBigDecimalSchemaId]: { max: max6 @@ -22404,9 +22389,9 @@ var NonPositiveBigDecimalFromSelf = /* @__PURE__ */ BigDecimalFromSelf.pipe(/* @ })); var BetweenBigDecimalSchemaId = /* @__PURE__ */ Symbol.for("effect/SchemaId/BetweenBigDecimal"); var betweenBigDecimal = (minimum, maximum, annotations3) => (self) => { - const formattedMinimum = format4(minimum); - const formattedMaximum = format4(maximum); - return self.pipe(filter8((a) => between3(a, { + const formattedMinimum = format2(minimum); + const formattedMaximum = format2(maximum); + return self.pipe(filter8((a) => between2(a, { minimum, maximum }), { @@ -22422,7 +22407,7 @@ var betweenBigDecimal = (minimum, maximum, annotations3) => (self) => { }; var clampBigDecimal = (minimum, maximum) => (self) => transform2(self, self.pipe(typeSchema, betweenBigDecimal(minimum, maximum)), { strict: false, - decode: (i) => clamp5(i, { + decode: (i) => clamp4(i, { minimum, maximum }), @@ -22433,7 +22418,7 @@ var chunkArbitrary = (item, ctx) => (fc) => { return (ctx.depthIdentifier !== undefined ? fc.oneof(ctx, fc.constant([]), items) : items).map(fromIterable2); }; var chunkPretty = (item) => (c) => `Chunk(${toReadonlyArray(c).map(item).join(", ")})`; -var chunkParse = (decodeUnknown3) => (u, options, ast) => isChunk(u) ? isEmpty(u) ? succeed8(empty2()) : toComposite(decodeUnknown3(toReadonlyArray(u), options), fromIterable2, ast, u) : fail7(new Type2(ast, u)); +var chunkParse = (decodeUnknown3) => (u, options, ast) => isChunk(u) ? isEmpty(u) ? succeed8(empty4()) : toComposite(decodeUnknown3(toReadonlyArray(u), options), fromIterable2, ast, u) : fail7(new Type2(ast, u)); var ChunkFromSelf = (value3) => { return declare([value3], { decode: (item) => chunkParse(decodeUnknown(Array$(item))), @@ -22451,15 +22436,15 @@ var ChunkFromSelf = (value3) => { function Chunk(value3) { return transform2(Array$(value3), ChunkFromSelf(typeSchema(asSchema(value3))), { strict: true, - decode: (i) => i.length === 0 ? empty2() : fromIterable2(i), + decode: (i) => i.length === 0 ? empty4() : fromIterable2(i), encode: (a) => toReadonlyArray(a) }); } -var nonEmptyChunkArbitrary = (item) => (fc) => array5(item(fc), { +var nonEmptyChunkArbitrary = (item) => (fc) => array3(item(fc), { minLength: 1 }).map((as4) => unsafeFromNonEmptyArray(as4)); var nonEmptyChunkPretty = (item) => (c) => `NonEmptyChunk(${toReadonlyArray(c).map(item).join(", ")})`; -var nonEmptyChunkParse = (decodeUnknown3) => (u, options, ast) => isChunk(u) && isNonEmpty(u) ? toComposite(decodeUnknown3(toReadonlyArray(u), options), unsafeFromNonEmptyArray, ast, u) : fail7(new Type2(ast, u)); +var nonEmptyChunkParse = (decodeUnknown3) => (u, options, ast) => isChunk(u) && isNonEmpty2(u) ? toComposite(decodeUnknown3(toReadonlyArray(u), options), unsafeFromNonEmptyArray, ast, u) : fail7(new Type2(ast, u)); var NonEmptyChunkFromSelf = (value3) => { return declare([value3], { decode: (item) => nonEmptyChunkParse(decodeUnknown(NonEmptyArray(item))), @@ -22481,7 +22466,7 @@ function NonEmptyChunk(value3) { encode: (a) => toReadonlyArray(a) }); } -var decodeData = (a) => Array.isArray(a) ? array3(a) : struct2(a); +var decodeData = (a) => Array.isArray(a) ? array4(a) : struct2(a); var dataArbitrary = (item) => (fc) => item(fc).map(decodeData); var dataPretty = (item) => (d) => `Data(${item(d)})`; var dataParse = (decodeUnknown3) => (u, options, ast) => isEqual(u) ? toComposite(decodeUnknown3(u, options), decodeData, ast, u) : fail7(new Type2(ast, u)); @@ -22512,7 +22497,7 @@ var Class5 = (identifier2) => (fieldsOr, annotations3) => makeClass({ identifier: identifier2, schema: getSchemaFromFieldsOr(fieldsOr), fields: getFieldsFromFieldsOr(fieldsOr), - Base: Class, + Base: Class3, annotations: annotations3 }); var getClassTag = (tag2) => withConstructorDefault(propertySignature(Literal2(tag2)), () => tag2); @@ -22528,7 +22513,7 @@ var TaggedClass3 = (identifier2) => (tag2, fieldsOr, annotations3) => { identifier: identifier2 ?? tag2, schema: extend2(schema, Struct(newFields)), fields: taggedFields, - Base: Class, + Base: Class3, annotations: annotations3 }) { static _tag = tag2; @@ -22536,7 +22521,7 @@ var TaggedClass3 = (identifier2) => (tag2, fieldsOr, annotations3) => { }; var TaggedError2 = (identifier2) => (tag2, fieldsOr, annotations3) => { - class Base3 extends Error2 { + class Base3 extends Error3 { } Base3.prototype.name = tag2; const fields = getFieldsFromFieldsOr(fieldsOr); @@ -22940,13 +22925,13 @@ var CauseFromSelf = ({ function causeDecode(cause3) { switch (cause3._tag) { case "Empty": - return empty25; + return empty26; case "Fail": return fail3(cause3.error); case "Die": return die3(cause3.defect); case "Interrupt": - return interrupt3(fiberIdDecode(cause3.fiberId)); + return interrupt4(fiberIdDecode(cause3.fiberId)); case "Sequential": return sequential4(causeDecode(cause3.left), causeDecode(cause3.right)); case "Parallel": @@ -23049,9 +23034,9 @@ var exitEncoded = (value3, error, defect) => { var exitDecode = (input) => { switch (input._tag) { case "Failure": - return failCause3(causeDecode(input.cause)); + return failCause2(causeDecode(input.cause)); case "Success": - return succeed3(input.value); + return succeed2(input.value); } }; var exitArbitrary = (value3, error, defect) => (fc) => fc.oneof(fc.record({ @@ -23062,9 +23047,9 @@ var exitArbitrary = (value3, error, defect) => (fc) => fc.oneof(fc.record({ value: value3(fc) })).map(exitDecode); var exitPretty = (value3, error) => (exit3) => exit3._tag === "Failure" ? `Exit.failCause(${causePretty(error)(exit3.cause)})` : `Exit.succeed(${value3(exit3.value)})`; -var exitParse = (decodeUnknownValue, decodeUnknownCause) => (u, options, ast) => isExit(u) ? match9(u, { - onFailure: (cause3) => toComposite(decodeUnknownCause(cause3, options), failCause3, ast, u), - onSuccess: (value3) => toComposite(decodeUnknownValue(value3, options), succeed3, ast, u) +var exitParse = (decodeUnknownValue, decodeUnknownCause) => (u, options, ast) => isExit(u) ? match6(u, { + onFailure: (cause3) => toComposite(decodeUnknownCause(cause3, options), failCause2, ast, u), + onSuccess: (value3) => toComposite(decodeUnknownValue(value3, options), succeed2, ast, u) }) : fail7(new Type2(ast, u)); var ExitFromSelf = ({ defect, @@ -24032,7 +24017,7 @@ async function stopLoop(loopID, reason) { async function stopLoopIfUnchanged(loopID, expectedUpdatedAt, reason, sessionLease) { return mutate5((state) => { const loop3 = state.loops[loopID]; - if (!loop3 || sessionLease && !matchesSessionLease(state, sessionLease)) + if (!loop3 || sessionLease && (sessionLease.sessionID !== loop3.sessionID || !matchesSessionLease(state, sessionLease))) return null; if (loop3.updatedAt !== expectedUpdatedAt || loop3.status !== "active" || loop3.mode !== "dynamic" || loop3.nextRunAt != null) { return null; @@ -24049,7 +24034,7 @@ async function rescheduleDynamicIfUnchanged(loopID, expectedUpdatedAt, delayMs, throw new Error("delay must be a positive number of milliseconds"); return mutate5((state) => { const loop3 = state.loops[loopID]; - if (!loop3 || sessionLease && !matchesSessionLease(state, sessionLease)) + if (!loop3 || sessionLease && (sessionLease.sessionID !== loop3.sessionID || !matchesSessionLease(state, sessionLease))) return null; if (loop3.updatedAt !== expectedUpdatedAt || loop3.status !== "active" || loop3.mode !== "dynamic" || loop3.nextRunAt != null) { return null; @@ -24313,7 +24298,7 @@ function restrictedAgentSet(options) { return new Set(names.map((name) => typeof name === "string" ? name.trim().toLowerCase() : "").filter(Boolean)); } function dynamicRestartMode(options) { - return options?.dynamic_restart_mode?.trim().toLowerCase() === "stop" ? "stop" : "fallback"; + return typeof options?.dynamic_restart_mode === "string" && options.dynamic_restart_mode.trim().toLowerCase() === "stop" ? "stop" : "fallback"; } function dynamicRestartFallbackMs(options, minIntervalSeconds, dynamicMaxDelaySeconds) { const fallbackSeconds = positiveNumberOr(options?.dynamic_restart_fallback_seconds, DEFAULT_DYNAMIC_RESTART_FALLBACK_SECONDS); @@ -24650,16 +24635,16 @@ var server = async ({ client, directory }, options) => { for (const [loopID, candidate] of staleDynamicCandidates) { if (candidate.sessionID !== sessionID) continue; - staleDynamicCandidates.delete(loopID); if (restartMode === "fallback") { - const rescheduled = await rescheduleDynamicIfUnchanged(loopID, candidate.updatedAt, restartFallbackMs, "restarted with fallback delay; reschedule or stop after this iteration", lease).catch(() => null); + const rescheduled = await rescheduleDynamicIfUnchanged(loopID, candidate.updatedAt, restartFallbackMs, "restarted with fallback delay; reschedule or stop after this iteration", lease); if (rescheduled) { scheduleTimer(rescheduled); await log3("info", "Dynamic loop resumed with fallback delay after restart", { loopID }); - continue; } + } else { + await stopLoopIfUnchanged(loopID, candidate.updatedAt, "not rescheduled before OpenCode restarted", lease); } - await stopLoopIfUnchanged(loopID, candidate.updatedAt, "not rescheduled before OpenCode restarted", lease); + staleDynamicCandidates.delete(loopID); } } async function requireSessionLoop(loopID, sessionID) { @@ -25225,19 +25210,19 @@ async function setupV2(context4) { for (const [loopID, candidate] of staleDynamicCandidates) { if (candidate.sessionID !== sessionID) continue; - staleDynamicCandidates.delete(loopID); if (restartMode === "fallback") { - const rescheduled = await rescheduleDynamicIfUnchanged(loopID, candidate.updatedAt, restartFallbackMs, "restarted with fallback delay; reschedule or stop after this iteration", lease).catch(() => null); + const rescheduled = await rescheduleDynamicIfUnchanged(loopID, candidate.updatedAt, restartFallbackMs, "restarted with fallback delay; reschedule or stop after this iteration", lease); if (rescheduled) { scheduleTimer(rescheduled); v2Log("info", "Dynamic loop resumed with fallback delay after restart", { loopID, sessionID }); - continue; } + } else { + await stopLoopIfUnchanged(loopID, candidate.updatedAt, "not rescheduled before OpenCode restarted", lease); } - await stopLoopIfUnchanged(loopID, candidate.updatedAt, "not rescheduled before OpenCode restarted", lease); + staleDynamicCandidates.delete(loopID); } } async function requireSessionLoop(loopID, sessionID) { diff --git a/package.json b/package.json index 6a1aa24..438347f 100644 --- a/package.json +++ b/package.json @@ -36,6 +36,7 @@ "dist", "server.js", "tui.js", + "scripts/install.mjs", "src/tui.tsx", "LICENSE", "README.md" diff --git a/scripts/install.mjs b/scripts/install.mjs index 7560b6e..9b31db8 100644 --- a/scripts/install.mjs +++ b/scripts/install.mjs @@ -1,4 +1,5 @@ -import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs" +import { existsSync, mkdirSync, readFileSync, renameSync, rmSync, writeFileSync } from "node:fs" +import { randomUUID } from "node:crypto" import { homedir } from "node:os" import { dirname, join, resolve } from "node:path" @@ -14,7 +15,9 @@ function configDir() { function readJson(path) { if (!existsSync(path)) return {} try { - return JSON.parse(readFileSync(path, "utf8")) + const value = JSON.parse(readFileSync(path, "utf8")) + if (!value || typeof value !== "object" || Array.isArray(value)) throw new Error("expected an object") + return value } catch { throw new Error(`invalid JSON: ${path}`) } @@ -27,26 +30,47 @@ function ensurePluginList(value) { } function pluginKey(entry) { - if (typeof entry === "string") return entry - if (entry && typeof entry === "object" && typeof entry.package === "string") return entry.package - return null + const spec = typeof entry === "string" ? entry : entry?.package + if (typeof spec !== "string") return null + return spec.replace(/^(?:(@[^/]+\/[^@/]+)|([^@./][^@/]*))@.+$/, "$1$2") } function addPlugin(list, pkg) { - if (list.some((entry) => pluginKey(entry) === pkg)) return { list, added: false } + if (list.some((entry) => pluginKey(entry) === pluginKey(pkg))) return { list, added: false } return { list: [...list, pkg], added: true } } function writeJson(path, value) { mkdirSync(dirname(path), { recursive: true }) - writeFileSync(path, `${JSON.stringify(value, null, 2)}\n`) + const temporary = `${path}.${randomUUID()}.tmp` + try { + writeFileSync(temporary, `${JSON.stringify(value, null, 2)}\n`, { mode: 0o600 }) + renameSync(temporary, path) + } finally { + rmSync(temporary, { force: true }) + } } function main() { const args = process.argv.slice(2) - const projectDir = args.includes("--project") ? resolve(args[args.indexOf("--project") + 1] ?? ".") : null - const pkg = args.includes("--package") ? args[args.indexOf("--package") + 1] : PACKAGE_NAME - if (!pkg) throw new Error("missing package name") + let projectDir = null + let global = false + let pkg = PACKAGE_NAME + const seen = new Set() + for (let index = 0; index < args.length; index++) { + const flag = args[index] + if (!["--global", "--project", "--package"].includes(flag) || seen.has(flag)) throw new Error(`invalid argument: ${flag}`) + seen.add(flag) + if (flag === "--global") { + global = true + continue + } + const value = args[++index] + if (!value || value.startsWith("--")) throw new Error(`missing value for ${flag}`) + if (flag === "--project") projectDir = resolve(value) + else pkg = value + } + if (global && projectDir) throw new Error("choose --global or --project") const targets = [] if (projectDir) { @@ -56,14 +80,21 @@ function main() { } targets.push({ kind: "tui", path: join(configDir(), "cli.json") }) - for (const target of targets) { + const updates = targets.map((target) => { + if (existsSync(target.path.replace(/\.json$/, ".jsonc"))) { + throw new Error(`edit the existing JSONC configuration manually: ${target.path.replace(/\.json$/, ".jsonc")}`) + } const current = readJson(target.path) const { list, added } = addPlugin(ensurePluginList(current.plugins), pkg) + return { ...target, current, list, added } + }) + + for (const { kind, path, current, list, added } of updates) { if (added) { - writeJson(target.path, { ...current, plugins: list }) - console.log(`added ${pkg} to ${target.kind}: ${target.path}`) + writeJson(path, { ...current, plugins: list }) + console.log(`added ${pkg} to ${kind}: ${path}`) } else { - console.log(`already present in ${target.kind}: ${target.path}`) + console.log(`already present in ${kind}: ${path}`) } } } diff --git a/src/server.ts b/src/server.ts index d90f968..8953bf7 100644 --- a/src/server.ts +++ b/src/server.ts @@ -94,7 +94,7 @@ function restrictedAgentSet(options?: Options) { } function dynamicRestartMode(options?: Options) { - return options?.dynamic_restart_mode?.trim().toLowerCase() === "stop" ? "stop" : "fallback" + return typeof options?.dynamic_restart_mode === "string" && options.dynamic_restart_mode.trim().toLowerCase() === "stop" ? "stop" : "fallback" } function dynamicRestartFallbackMs(options?: Options, minIntervalSeconds?: number, dynamicMaxDelaySeconds?: number) { @@ -454,20 +454,20 @@ const server: Plugin = async ({ client, directory }, options?: Options) => { if (!lease) return for (const [loopID, candidate] of staleDynamicCandidates) { if (candidate.sessionID !== sessionID) continue - staleDynamicCandidates.delete(loopID) if (restartMode === "fallback") { const rescheduled = await rescheduleDynamicIfUnchanged( loopID, candidate.updatedAt, restartFallbackMs, "restarted with fallback delay; reschedule or stop after this iteration", lease, - ).catch(() => null) + ) if (rescheduled) { scheduleTimer(rescheduled) await log("info", "Dynamic loop resumed with fallback delay after restart", { loopID }) - continue } + } else { + await stopLoopIfUnchanged( + loopID, candidate.updatedAt, "not rescheduled before OpenCode restarted", lease, + ) } - await stopLoopIfUnchanged( - loopID, candidate.updatedAt, "not rescheduled before OpenCode restarted", lease, - ) + staleDynamicCandidates.delete(loopID) } } @@ -1072,23 +1072,23 @@ async function setupV2(context: PluginV2.Plugin.Context): Promise null) + ) if (rescheduled) { scheduleTimer(rescheduled) v2Log("info", "Dynamic loop resumed with fallback delay after restart", { loopID, sessionID, }) - continue } + } else { + await stopLoopIfUnchanged( + loopID, candidate.updatedAt, "not rescheduled before OpenCode restarted", lease, + ) } - await stopLoopIfUnchanged( - loopID, candidate.updatedAt, "not rescheduled before OpenCode restarted", lease, - ) + staleDynamicCandidates.delete(loopID) } } diff --git a/src/state.ts b/src/state.ts index 2e94fcc..d8da6c4 100644 --- a/src/state.ts +++ b/src/state.ts @@ -649,7 +649,7 @@ export async function stopLoopIfUnchanged( ) { return mutate((state) => { const loop = state.loops[loopID] - if (!loop || (sessionLease && !matchesSessionLease(state, sessionLease))) return null + if (!loop || (sessionLease && (sessionLease.sessionID !== loop.sessionID || !matchesSessionLease(state, sessionLease)))) return null if ( loop.updatedAt !== expectedUpdatedAt || loop.status !== "active" || @@ -676,7 +676,7 @@ export async function rescheduleDynamicIfUnchanged( if (delay == null) throw new Error("delay must be a positive number of milliseconds") return mutate((state) => { const loop = state.loops[loopID] - if (!loop || (sessionLease && !matchesSessionLease(state, sessionLease))) return null + if (!loop || (sessionLease && (sessionLease.sessionID !== loop.sessionID || !matchesSessionLease(state, sessionLease)))) return null if ( loop.updatedAt !== expectedUpdatedAt || loop.status !== "active" || diff --git a/test/install.test.ts b/test/install.test.ts new file mode 100644 index 0000000..a9d64f7 --- /dev/null +++ b/test/install.test.ts @@ -0,0 +1,78 @@ +import { afterEach, beforeEach, expect, test } from "bun:test" +import { mkdir, mkdtemp, readFile, rm, writeFile } from "node:fs/promises" +import { tmpdir } from "node:os" +import { join } from "node:path" + +let directory = "" +let config = "" +const packageName = "@prevalentware/opencode-loop-plugin" + +beforeEach(async () => { + directory = await mkdtemp(join(tmpdir(), "loop-install-")) + config = join(directory, "config", "opencode") + await mkdir(config, { recursive: true }) +}) + +afterEach(async () => { + await rm(directory, { recursive: true, force: true }) +}) + +async function install(...args: string[]) { + const child = Bun.spawn([process.execPath, join(import.meta.dir, "../scripts/install.mjs"), ...args], { + cwd: directory, + env: { ...process.env, XDG_CONFIG_HOME: join(directory, "config") }, + stdout: "pipe", + stderr: "pipe", + }) + const [stdout, stderr, code] = await Promise.all([ + new Response(child.stdout).text(), new Response(child.stderr).text(), child.exited, + ]) + return { code, stdout, stderr } +} + +test("installer writes both V2 configs and preserves pinned entries and options on repeat", async () => { + const existing = { plugins: [{ package: `${packageName}@0.1.13`, options: { dynamic_restart_mode: "stop" } }], model: "test/model" } + const original = JSON.stringify(existing) + await writeFile(join(config, "opencode.json"), original) + expect((await install("--global")).code).toBe(0) + expect(await readFile(join(config, "opencode.json"), "utf8")).toBe(original) + expect(JSON.parse(await readFile(join(config, "cli.json"), "utf8"))).toEqual({ plugins: [packageName] }) + expect((await install("--global")).code).toBe(0) + expect(JSON.parse(await readFile(join(config, "cli.json"), "utf8"))).toEqual({ plugins: [packageName] }) +}) + +test("project installer changes the project server config and global TUI config", async () => { + const project = join(directory, "project") + expect((await install("--project", project)).code).toBe(0) + expect(JSON.parse(await readFile(join(project, "opencode.json"), "utf8"))).toEqual({ plugins: [packageName] }) + expect(JSON.parse(await readFile(join(config, "cli.json"), "utf8"))).toEqual({ plugins: [packageName] }) + expect(await Bun.file(join(config, "opencode.json")).exists()).toBe(false) +}) + +test.each(["null", "[]", '"invalid"', '{"plugins":{}}', "{broken"])("installer validates both documents before writing: %s", async (invalid) => { + const original = '{"model":"test/model"}' + await writeFile(join(config, "opencode.json"), original) + await writeFile(join(config, "cli.json"), invalid) + expect((await install("--global")).code).not.toBe(0) + expect(await readFile(join(config, "opencode.json"), "utf8")).toBe(original) + expect(await readFile(join(config, "cli.json"), "utf8")).toBe(invalid) +}) + +test.each([ + { args: ["--project"] }, + { args: ["--project", "--package", packageName] }, + { args: ["--global", "--project", "."] }, + { args: ["--unknown"] }, +])("installer rejects invalid arguments: %j", async ({ args }) => { + expect((await install(...args)).code).not.toBe(0) + expect(await Bun.file(join(config, "opencode.json")).exists()).toBe(false) + expect(await Bun.file(join(config, "cli.json")).exists()).toBe(false) +}) + +test("installer refuses JSONC before creating a competing JSON configuration", async () => { + const original = '{\n// keep this comment\n"plugins": []\n}' + await writeFile(join(config, "cli.jsonc"), original) + expect((await install("--global")).code).not.toBe(0) + expect(await readFile(join(config, "cli.jsonc"), "utf8")).toBe(original) + expect(await Bun.file(join(config, "opencode.json")).exists()).toBe(false) +}) diff --git a/test/server-v2.test.ts b/test/server-v2.test.ts index f481f35..13d2e68 100644 --- a/test/server-v2.test.ts +++ b/test/server-v2.test.ts @@ -342,6 +342,58 @@ test("V2 context hook injects a session-specific loop reminder", async () => { await cleanup() }) +test("V2 compaction preserves open loops per session without duplicating context", async () => { + const mock = makeMockContext() + const cleanup = await plugin.setup(mock as never) + try { + await loopTool(mock, "create_loop").execute({ instruction: "preserve this task", interval: "1m" }, toolContext()) + const compaction = mock.hooks.compaction + if (!compaction) throw new Error("compaction hook not registered") + const input = { sessionID: "ses_v2", system: [{ type: "text", text: "base" }] } + await compaction(input) + await compaction(input) + expect(input.system).toHaveLength(2) + expect(input.system[1]?.text).toContain("preserve this task") + expect(input.system[1]?.text).toContain("across compaction") + const other = { sessionID: "ses_other", system: [] } + await compaction(other) + expect(other.system).toHaveLength(0) + } finally { + mock.stream.end() + await cleanup() + } +}) + +test.each([ + { mode: "fallback", fallback: 0.1, maximum: 60, delay: 1000 }, + { mode: "fallback", fallback: 1200, maximum: 2, delay: 2000 }, + { mode: "fallback", fallback: undefined, maximum: 86400, delay: 1200000 }, + { mode: "stop", fallback: 1, maximum: 60, delay: null }, +])("V2 recovers stale dynamic loops using restart options %j", async ({ mode, fallback, maximum, delay }) => { + const loop = await createLoop("ses_v2", { prompt: "watch CI", mode: "dynamic" }) + const mock = makeMockContext({ dynamic_restart_mode: mode, dynamic_restart_fallback_seconds: fallback, dynamic_max_delay_seconds: maximum }) + const cleanup = await plugin.setup(mock as never) + try { + expect((await getLoop(loop.id))?.nextRunAt).toBeNull() + const started = Date.now() + await mock.hooks.context?.({ sessionID: "ses_v2", system: [] }) + const recovered = await getLoop(loop.id) + if (delay === null) { + expect(recovered?.status).toBe("stopped") + expect(recovered?.stopReason).toContain("restarted") + } else { + expect(recovered?.status).toBe("active") + expect(recovered?.nextRunAt).toBeGreaterThanOrEqual(started + delay) + expect(recovered?.nextRunAt).toBeLessThanOrEqual(Date.now() + delay) + await mock.hooks.context?.({ sessionID: "ses_v2", system: [] }) + expect((await getLoop(loop.id))?.nextRunAt).toBe(recovered?.nextRunAt) + } + } finally { + mock.stream.end() + await cleanup() + } +}) + test("V2 busy/idle events defer and then inject loop iterations", async () => { const mock = makeMockContext() const cleanup = await plugin.setup(mock as never) diff --git a/test/server.test.ts b/test/server.test.ts index 63bc7cb..b12fcf1 100644 --- a/test/server.test.ts +++ b/test/server.test.ts @@ -291,6 +291,26 @@ test("system transform merges a loop reminder for sessions with open loops", asy await hooks.dispose?.() }) +test.each(["fallback", "stop"])("V1 recovers stale dynamic loops in %s mode", async (mode) => { + const loop = await createLoop("ses_1", { prompt: "watch CI", mode: "dynamic" }) + const hooks = await makeServer([], { dynamic_restart_mode: mode, dynamic_restart_fallback_seconds: 120 }) + try { + expect((await getLoop(loop.id))?.nextRunAt).toBeNull() + const started = Date.now() + await idle(hooks, "ses_1") + const recovered = await getLoop(loop.id) + if (mode === "stop") expect(recovered?.status).toBe("stopped") + else { + expect(recovered?.status).toBe("active") + expect(recovered?.nextRunAt).toBeGreaterThanOrEqual(started + 120000) + await idle(hooks, "ses_1") + expect((await getLoop(loop.id))?.nextRunAt).toBe(recovered?.nextRunAt) + } + } finally { + await hooks.dispose?.() + } +}) + test("rehydrated loops resume after an authoritative idle event", async () => { const sent: SentPrompt[] = [] const first = await makeServer(sent) diff --git a/test/state.test.ts b/test/state.test.ts index 1ccd509..03b1696 100644 --- a/test/state.test.ts +++ b/test/state.test.ts @@ -412,7 +412,12 @@ test("orphan dynamic cleanup is fenced by session ownership", async () => { await releaseSessionLease("ses_1", "a", lease.revision) await acquireSessionLease("ses_1", "b", 60_000) expect(await stopLoopIfUnchanged(loop.id, loop.updatedAt, "stale", lease)).toBeNull() + expect(await rescheduleDynamicIfUnchanged(loop.id, loop.updatedAt, 60_000, "restart", lease)).toBeNull() + const foreign = (await acquireSessionLease("ses_other", "a", 60_000))! + expect(await stopLoopIfUnchanged(loop.id, loop.updatedAt, "stale", foreign)).toBeNull() + expect(await rescheduleDynamicIfUnchanged(loop.id, loop.updatedAt, 60_000, "restart", foreign)).toBeNull() expect((await getLoop(loop.id))?.status).toBe("active") + expect((await getLoop(loop.id))?.nextRunAt).toBeNull() }) test("maximum failure backoff caps even the first retry", async () => { From 1105c9a2e06924bb019003a87a104d2b1b83e249 Mon Sep 17 00:00:00 2001 From: Daniel Saldarriaga Date: Tue, 27 Oct 2026 22:08:01 +0100 Subject: [PATCH 5/5] fix: align installer paths and preserve linked configurations --- dist/server.js | 2 +- scripts/install.mjs | 41 +++++++++++++++++++++++------------------ src/server.ts | 2 +- test/install.test.ts | 34 +++++++++++++++++++++++++++++++++- test/server-v2.test.ts | 2 +- test/state.test.ts | 5 ++++- 6 files changed, 63 insertions(+), 23 deletions(-) diff --git a/dist/server.js b/dist/server.js index c2612dd..aacdfed 100644 --- a/dist/server.js +++ b/dist/server.js @@ -25358,7 +25358,7 @@ async function setupV2(context4) { const contextText = compactionContext(loops); if (!contextText) return; - if (sessionCompaction.system.some((part) => part.type === "text" && part.text.includes(LOOP_SYSTEM_MARKER))) + if (sessionCompaction.system.some((part) => part.type === "text" && part.text.includes("OpenCode loop mode is tracking recurring loops for this session across compaction."))) return; sessionCompaction.system.push({ type: "text", text: contextText }); })); diff --git a/scripts/install.mjs b/scripts/install.mjs index 9b31db8..b88aea4 100644 --- a/scripts/install.mjs +++ b/scripts/install.mjs @@ -1,4 +1,4 @@ -import { existsSync, mkdirSync, readFileSync, renameSync, rmSync, writeFileSync } from "node:fs" +import { existsSync, mkdirSync, readFileSync, realpathSync, renameSync, rmSync, statSync, writeFileSync } from "node:fs" import { randomUUID } from "node:crypto" import { homedir } from "node:os" import { dirname, join, resolve } from "node:path" @@ -6,10 +6,7 @@ import { dirname, join, resolve } from "node:path" const PACKAGE_NAME = "@prevalentware/opencode-loop-plugin" function configDir() { - if (process.env.XDG_CONFIG_HOME) return resolve(process.env.XDG_CONFIG_HOME, "opencode") - if (process.platform === "win32" && process.env.APPDATA) return join(process.env.APPDATA, "..", "Local", "opencode") - const base = process.platform === "win32" ? join(homedir(), "AppData", "Local") : join(homedir(), ".config") - return join(base, "opencode") + return resolve(process.env.XDG_CONFIG_HOME || join(homedir(), ".config"), "opencode") } function readJson(path) { @@ -19,7 +16,7 @@ function readJson(path) { if (!value || typeof value !== "object" || Array.isArray(value)) throw new Error("expected an object") return value } catch { - throw new Error(`invalid JSON: ${path}`) + throw new Error(`expected a JSON object: ${path}; comments and trailing commas are not supported, edit manually`) } } @@ -41,11 +38,13 @@ function addPlugin(list, pkg) { } function writeJson(path, value) { - mkdirSync(dirname(path), { recursive: true }) - const temporary = `${path}.${randomUUID()}.tmp` + const target = existsSync(path) ? realpathSync(path) : path + const mode = existsSync(target) ? statSync(target).mode & 0o777 : 0o600 + mkdirSync(dirname(target), { recursive: true }) + const temporary = `${target}.${randomUUID()}.tmp` try { - writeFileSync(temporary, `${JSON.stringify(value, null, 2)}\n`, { mode: 0o600 }) - renameSync(temporary, path) + writeFileSync(temporary, `${JSON.stringify(value, null, 2)}\n`, { mode }) + renameSync(temporary, target) } finally { rmSync(temporary, { force: true }) } @@ -72,18 +71,24 @@ function main() { } if (global && projectDir) throw new Error("choose --global or --project") - const targets = [] - if (projectDir) { - targets.push({ kind: "server(project)", path: join(projectDir, "opencode.json") }) - } else { - targets.push({ kind: "server(global)", path: join(configDir(), "opencode.json") }) + const serverPaths = projectDir + ? [join(projectDir, "opencode.json"), join(projectDir, ".opencode", "opencode.json")] + : [join(configDir(), "opencode.json")] + for (const path of [...serverPaths, join(configDir(), "cli.json")]) { + const jsonc = path.replace(/\.json$/, ".jsonc") + if (existsSync(jsonc)) throw new Error(`edit the existing JSONC configuration manually: ${jsonc}`) } + const serverConfigs = serverPaths.map((path) => { + const current = readJson(path) + return { path, plugins: ensurePluginList(current.plugins) } + }) + const serverPath = serverConfigs.find(({ plugins }) => plugins.some((entry) => pluginKey(entry) === pluginKey(pkg)))?.path + ?? serverPaths.find(existsSync) ?? serverPaths[0] + const targets = [] + targets.push({ kind: projectDir ? "server(project)" : "server(global)", path: serverPath }) targets.push({ kind: "tui", path: join(configDir(), "cli.json") }) const updates = targets.map((target) => { - if (existsSync(target.path.replace(/\.json$/, ".jsonc"))) { - throw new Error(`edit the existing JSONC configuration manually: ${target.path.replace(/\.json$/, ".jsonc")}`) - } const current = readJson(target.path) const { list, added } = addPlugin(ensurePluginList(current.plugins), pkg) return { ...target, current, list, added } diff --git a/src/server.ts b/src/server.ts index 8953bf7..187a33e 100644 --- a/src/server.ts +++ b/src/server.ts @@ -1231,7 +1231,7 @@ async function setupV2(context: PluginV2.Plugin.Context): Promise part.type === "text" && part.text.includes(LOOP_SYSTEM_MARKER))) return + if (sessionCompaction.system.some((part) => part.type === "text" && part.text.includes("OpenCode loop mode is tracking recurring loops for this session across compaction."))) return sessionCompaction.system.push({ type: "text", text: contextText }) }), ) diff --git a/test/install.test.ts b/test/install.test.ts index a9d64f7..b12e6b0 100644 --- a/test/install.test.ts +++ b/test/install.test.ts @@ -1,5 +1,5 @@ import { afterEach, beforeEach, expect, test } from "bun:test" -import { mkdir, mkdtemp, readFile, rm, writeFile } from "node:fs/promises" +import { lstat, mkdir, mkdtemp, readFile, rm, stat, symlink, writeFile } from "node:fs/promises" import { tmpdir } from "node:os" import { join } from "node:path" @@ -76,3 +76,35 @@ test("installer refuses JSONC before creating a competing JSON configuration", a expect(await readFile(join(config, "cli.jsonc"), "utf8")).toBe(original) expect(await Bun.file(join(config, "opencode.json")).exists()).toBe(false) }) + +test("project installer respects nested pinned config even when a root config exists", async () => { + const project = join(directory, "project") + await mkdir(join(project, ".opencode"), { recursive: true }) + const nested = JSON.stringify({ plugins: [`${packageName}@0.1.13`] }) + await writeFile(join(project, ".opencode", "opencode.json"), nested) + await writeFile(join(project, "opencode.json"), "{}") + expect((await install("--project", project)).code).toBe(0) + expect(await readFile(join(project, "opencode.json"), "utf8")).toBe("{}") + expect(await readFile(join(project, ".opencode", "opencode.json"), "utf8")).toBe(nested) +}) + +test("project installer refuses nested JSONC before writing either config", async () => { + const project = join(directory, "project") + await mkdir(join(project, ".opencode"), { recursive: true }) + await writeFile(join(project, ".opencode", "opencode.jsonc"), "{}") + expect((await install("--project", project)).code).not.toBe(0) + expect(await Bun.file(join(project, "opencode.json")).exists()).toBe(false) + expect(await Bun.file(join(config, "cli.json")).exists()).toBe(false) +}) + +test("installer preserves config symlinks and existing permissions", async () => { + const target = join(directory, "dotfiles.json") + await writeFile(target, "{}", { mode: 0o640 }) + const mode = (await stat(target)).mode & 0o777 + const link = join(config, "opencode.json") + await symlink(target, link) + expect((await install("--global")).code).toBe(0) + expect((await lstat(link)).isSymbolicLink()).toBe(true) + expect((await stat(target)).mode & 0o777).toBe(mode) + expect(JSON.parse(await readFile(target, "utf8"))).toEqual({ plugins: [packageName] }) +}) diff --git a/test/server-v2.test.ts b/test/server-v2.test.ts index 13d2e68..2aff693 100644 --- a/test/server-v2.test.ts +++ b/test/server-v2.test.ts @@ -349,7 +349,7 @@ test("V2 compaction preserves open loops per session without duplicating context await loopTool(mock, "create_loop").execute({ instruction: "preserve this task", interval: "1m" }, toolContext()) const compaction = mock.hooks.compaction if (!compaction) throw new Error("compaction hook not registered") - const input = { sessionID: "ses_v2", system: [{ type: "text", text: "base" }] } + const input = { sessionID: "ses_v2", system: [{ type: "text", text: "OpenCode loop mode reminder: existing per-turn context" }] } await compaction(input) await compaction(input) expect(input.system).toHaveLength(2) diff --git a/test/state.test.ts b/test/state.test.ts index 03b1696..d44b451 100644 --- a/test/state.test.ts +++ b/test/state.test.ts @@ -182,7 +182,10 @@ test("stale dynamic loops resume with fallback delay instead of stopping", async const changed = (await getLoop(created.id))! expect(await rescheduleDynamicIfUnchanged(created.id, created.updatedAt, 120_000, "stale")).toBeNull() - expect(changed.nextRunAt).not.toBeNull() + const after = await getLoop(created.id) + expect(after?.nextRunAt).toBe(changed.nextRunAt) + expect(after?.updatedAt).toBe(changed.updatedAt) + expect(after?.scheduleRevision).toBe(changed.scheduleRevision) }) test("serializes state mutations across processes", async () => {