@voltro/kv 0.89.2 → 0.91.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,242 +1,242 @@
1
- import { KvError as e } from "./errors.js";
2
- import { withRespKeyPrefix as t } from "./connectionPrefix.js";
3
- import { sqlConfigProblem as n, sqlConnectionConfig as r, sqlConnectionName as i } from "./connectionSqlConfig.js";
4
- import { analyticsConfigProblem as a, analyticsConnectionConfig as o, analyticsConnectionName as s } from "./connectionAnalyticsConfig.js";
5
- import { connectionDefinitionsProblem as c, natsConnectionName as l, redisConnectionName as u } from "./connectionDefinitions.js";
6
- import { makeConnectionOwner as d } from "./connectionOwner.js";
1
+ import { sqlConfigProblem as e, sqlConnectionConfig as t, sqlConnectionName as n } from "./connectionSqlConfig.js";
2
+ import { RedisConnections as r, connect as i, connectionConfig as a } from "./connection.js";
3
+ import { connectionDefinitionsProblem as o, natsConnectionName as s, redisConnectionName as c } from "./connectionDefinitions.js";
4
+ import { KvError as l } from "./errors.js";
5
+ import { makeConnectionOwner as u } from "./connectionOwner.js";
6
+ import { withRespKeyPrefix as d } from "./connectionPrefix.js";
7
7
  import { applyConnectionNamespace as f, connectionNamespace as p } from "./connectionNamespace.js";
8
- import { connectRedisSubscriber as m } from "./connectionSubscriber.js";
9
- import { assertNatsSubject as ee, withNatsSubjectPrefix as te } from "./connectionNatsSubjects.js";
10
- import { connectNats as ne } from "./connectionNats.js";
11
- import { natsConnectionConfig as re } from "./connectionNatsConfig.js";
12
- import { StorageError as h } from "./storage.js";
13
- import { storageConfigProblem as ie, storageConnectionConfig as ae, storageConnectionName as oe } from "./connectionStorageConfig.js";
14
- import { makeStorageFacade as se } from "./connectionStorageFacade.js";
15
- import { CONNECTION_PUBLISH_SCRIPT as ce } from "./connectionScripts.js";
16
- import { AnalyticsCapabilityNotSupported as g, AnalyticsError as _ } from "./analytics.js";
17
- import { makeConnectionMetrics as le } from "./connectionMetrics.js";
18
- import { withConnectionRegistryConfigProvider as v } from "./connectionConfigProvider.js";
8
+ import { connectRedisSubscriber as ee } from "./connectionSubscriber.js";
9
+ import { connectNats as te } from "./connectionNats.js";
10
+ import { assertNatsSubject as m, withNatsSubjectPrefix as h } from "./connectionNatsSubjects.js";
11
+ import { natsConnectionConfig as ne } from "./connectionNatsConfig.js";
12
+ import { StorageError as g } from "./storage.js";
13
+ import { storageConfigProblem as re, storageConnectionConfig as ie, storageConnectionName as ae } from "./connectionStorageConfig.js";
14
+ import { makeStorageFacade as oe } from "./connectionStorageFacade.js";
15
+ import { CONNECTION_PUBLISH_SCRIPT as se } from "./connectionScripts.js";
16
+ import { AnalyticsCapabilityNotSupported as _, AnalyticsError as v } from "./analytics.js";
17
+ import { analyticsConfigProblem as ce, analyticsConnectionConfig as le, analyticsConnectionName as ue } from "./connectionAnalyticsConfig.js";
18
+ import { makeConnectionMetrics as de } from "./connectionMetrics.js";
19
+ import { withConnectionRegistryConfigProvider as fe } from "./connectionConfigProvider.js";
19
20
  import { connectionConfigError as y } from "./connectionConfigError.js";
20
- import { RedisConnections as ue, connect as de, connectionConfig as fe } from "./connection.js";
21
- import { Cause as b, Clock as x, Config as S, ConfigProvider as C, Context as w, Deferred as pe, Effect as T, Layer as E, Pull as me, Scope as he, Stream as D, SynchronizedRef as O } from "effect";
22
- import { CircuitBreaker as ge, CircuitOpen as _e } from "@voltro/shared";
21
+ import { Cause as pe, Clock as b, Config as x, ConfigProvider as S, Context as C, Deferred as me, Effect as w, Layer as T, Pull as he, Scope as ge, Stream as E, SynchronizedRef as D } from "effect";
22
+ import { CircuitBreaker as _e, CircuitOpen as ve } from "@voltro/shared";
23
23
  // src/connectionPool.ts
24
- var k = class extends w.Service()("@voltro/ConnectionRegistry") {}, A = (v = {}) => T.gen(function* () {
25
- let ue = 0, w = v.connections === void 0 ? {} : v.connections;
26
- if (v.requirements !== void 0 && !Array.isArray(v.requirements)) return yield* T.fail(new S.ConfigError(new C.SourceError({ message: "Connection requirements must be an array" })));
27
- let E = (v.requirements ?? []).map((e) => Object.freeze({ ...e }));
28
- for (let e of E) if (e.onUnavailable !== void 0 && e.onUnavailable !== "degrade" && e.onUnavailable !== "fail" || typeof e.consumer != "string" || !e.consumer.trim() || typeof e.role != "string" || !/^[A-Za-z][A-Za-z0-9_-]*$/.test(e.role) || e.reference !== "" && (typeof e.reference != "string" || !/^(redis|nats|storage|analytics|sql):[A-Za-z][A-Za-z0-9_-]*$/.test(e.reference)) || [
24
+ var O = class extends C.Service()("@voltro/ConnectionRegistry") {}, k = (r = {}) => w.gen(function* () {
25
+ let fe = 0, C = r.connections === void 0 ? {} : r.connections;
26
+ if (r.requirements !== void 0 && !Array.isArray(r.requirements)) return yield* w.fail(new x.ConfigError(new S.SourceError({ message: "Connection requirements must be an array" })));
27
+ let T = (r.requirements ?? []).map((e) => Object.freeze({ ...e }));
28
+ for (let e of T) if (e.onUnavailable !== void 0 && e.onUnavailable !== "degrade" && e.onUnavailable !== "fail" || typeof e.consumer != "string" || !e.consumer.trim() || typeof e.role != "string" || !/^[A-Za-z][A-Za-z0-9_-]*$/.test(e.role) || e.reference !== "" && (typeof e.reference != "string" || !/^(redis|nats|storage|analytics|sql):[A-Za-z][A-Za-z0-9_-]*$/.test(e.reference)) || [
29
29
  "crossNode",
30
30
  "pubsub",
31
31
  "atomicMulti"
32
32
  ].some((t) => {
33
33
  let n = e[t];
34
34
  return n !== void 0 && typeof n != "boolean";
35
- })) return yield* T.fail(new S.ConfigError(new C.SourceError({ message: "Connection requirements need consumer, role, a typed reference, boolean capabilities and a degrade/fail unavailable policy" })));
36
- v.namespaceIdentity !== void 0 && (yield* T.try({
37
- try: () => p(v.namespaceIdentity),
38
- catch: () => new S.ConfigError(new C.SourceError({ message: "Connection namespace requires a nonempty app name and environment" }))
35
+ })) return yield* w.fail(new x.ConfigError(new S.SourceError({ message: "Connection requirements need consumer, role, a typed reference, boolean capabilities and a degrade/fail unavailable policy" })));
36
+ r.namespaceIdentity !== void 0 && (yield* w.try({
37
+ try: () => p(r.namespaceIdentity),
38
+ catch: () => new x.ConfigError(new S.SourceError({ message: "Connection namespace requires a nonempty app name and environment" }))
39
39
  }));
40
- let k = le(v.namespaceIdentity === void 0 ? "unscoped" : p(v.namespaceIdentity)), A = c(w);
41
- if (A) return yield* T.fail(new S.ConfigError(new C.SourceError({ message: A })));
42
- let j = w.maxDynamicPools ?? 128, ve = w.rotationGraceMs ?? 3e4, ye = v.failureThreshold ?? 5, be = v.resetTimeoutMs ?? 3e4;
40
+ let O = de(r.namespaceIdentity === void 0 ? "unscoped" : p(r.namespaceIdentity)), k = o(C);
41
+ if (k) return yield* w.fail(new x.ConfigError(new S.SourceError({ message: k })));
42
+ let A = C.maxDynamicPools ?? 128, ye = C.rotationGraceMs ?? 3e4, be = r.failureThreshold ?? 5, xe = r.resetTimeoutMs ?? 3e4;
43
43
  for (let [e, t, n] of [
44
44
  [
45
45
  "maxDynamicPools",
46
- j,
46
+ A,
47
47
  !1
48
48
  ],
49
49
  [
50
50
  "rotationGraceMs",
51
- ve,
51
+ ye,
52
52
  !0
53
53
  ],
54
54
  [
55
55
  "failureThreshold",
56
- ye,
56
+ be,
57
57
  !1
58
58
  ],
59
59
  [
60
60
  "resetTimeoutMs",
61
- be,
61
+ xe,
62
62
  !1
63
63
  ]
64
- ]) if (!Number.isSafeInteger(t) || t < +!n) return yield* T.fail(new S.ConfigError(new C.SourceError({ message: `${e} must be a ${n ? "nonnegative" : "positive"} safe integer` })));
65
- let M = yield* T.context(), xe = T.runPromiseWith(M), N = yield* O.make(/* @__PURE__ */ new Map()), P = /* @__PURE__ */ new Map(), F = /* @__PURE__ */ new Map(), I = /* @__PURE__ */ new Map(), L = /* @__PURE__ */ new Map(), R = /* @__PURE__ */ new Map(), z = /* @__PURE__ */ new Map(), B = (e) => {
66
- if (e.startsWith("sql:")) return `sql:${i(e, w)}`;
67
- if (e.startsWith("analytics:")) return `analytics:${s(e, w)}`;
68
- if (e.startsWith("storage:")) return `storage:${oe(e, w)}`;
69
- if (e.startsWith("nats:")) return `nats:${l(e, w)}`;
70
- let t = u(e, w);
71
- return w.redis?.[t] === void 0 ? e.startsWith("redis:") ? t : e : `redis:${t}`;
72
- }, V = (e, t) => JSON.stringify([B(e), H(e) ? t?.tenantId ?? null : null]), Se = (e) => e.startsWith("sql:") ? w.sql?.[i(e, w)] : e.startsWith("analytics:") ? w.analytics?.[s(e, w)] : e.startsWith("storage:") ? w.storage?.[oe(e, w)] : e.startsWith("nats:") ? w.nats?.[l(e, w)] : w.redis?.[u(e, w)], H = (e) => {
73
- let t = Se(e);
64
+ ]) if (!Number.isSafeInteger(t) || t < +!n) return yield* w.fail(new x.ConfigError(new S.SourceError({ message: `${e} must be a ${n ? "nonnegative" : "positive"} safe integer` })));
65
+ let j = yield* w.context(), Se = w.runPromiseWith(j), M = yield* D.make(/* @__PURE__ */ new Map()), N = /* @__PURE__ */ new Map(), P = /* @__PURE__ */ new Map(), F = /* @__PURE__ */ new Map(), I = /* @__PURE__ */ new Map(), L = /* @__PURE__ */ new Map(), R = /* @__PURE__ */ new Map(), z = (e) => {
66
+ if (e.startsWith("sql:")) return `sql:${n(e, C)}`;
67
+ if (e.startsWith("analytics:")) return `analytics:${ue(e, C)}`;
68
+ if (e.startsWith("storage:")) return `storage:${ae(e, C)}`;
69
+ if (e.startsWith("nats:")) return `nats:${s(e, C)}`;
70
+ let t = c(e, C);
71
+ return C.redis?.[t] === void 0 ? e.startsWith("redis:") ? t : e : `redis:${t}`;
72
+ }, B = (e, t) => JSON.stringify([z(e), V(e) ? t?.tenantId ?? null : null]), Ce = (e) => e.startsWith("sql:") ? C.sql?.[n(e, C)] : e.startsWith("analytics:") ? C.analytics?.[ue(e, C)] : e.startsWith("storage:") ? C.storage?.[ae(e, C)] : e.startsWith("nats:") ? C.nats?.[s(e, C)] : C.redis?.[c(e, C)], V = (e) => {
73
+ let t = Ce(e);
74
74
  return t !== void 0 && "_tag" in t && (t._tag === "DynamicRedisConnection" || t._tag === "DynamicNatsConnection" || t._tag === "DynamicStorageConnection" || t._tag === "DynamicAnalyticsConnection" || t._tag === "DynamicSqlConnection");
75
- }, Ce = (e) => T.suspend(() => {
76
- if (e !== "" && !/^(redis|nats|storage|analytics|sql):[A-Za-z][A-Za-z0-9_-]*$/.test(e)) return T.fail(new S.ConfigError(new C.SourceError({ message: "A connection reference must use redis:name, nats:name, storage:name, analytics:name or sql:name" })));
77
- let t = H(e), n = {
78
- reference: B(e),
75
+ }, we = (e) => w.suspend(() => {
76
+ if (e !== "" && !/^(redis|nats|storage|analytics|sql):[A-Za-z][A-Za-z0-9_-]*$/.test(e)) return w.fail(new x.ConfigError(new S.SourceError({ message: "A connection reference must use redis:name, nats:name, storage:name, analytics:name or sql:name" })));
77
+ let t = V(e), n = {
78
+ reference: z(e),
79
79
  tenantScoped: t
80
80
  };
81
- return t ? T.succeed(n) : Oe(e).pipe(T.as(n));
82
- }), U = (e, t) => fe(e, w, t).pipe(T.flatMap((e) => v.namespaceIdentity === void 0 ? T.succeed(e) : T.try({
83
- try: () => f(e, v.namespaceIdentity),
84
- catch: (e) => new S.ConfigError(new C.SourceError({ message: e instanceof Error ? e.message : "Connection namespace admission failed" }))
85
- })), T.flatMap((t) => {
86
- let n = B(e);
87
- for (let e of E) if (B(e.reference) === n) {
88
- if (t.driver === "memory" && e.crossNode) return T.fail(new S.ConfigError(new C.SourceError({ message: `Plugin ${e.consumer} role ${e.role} requires a network Redis connection; memory is local` })));
81
+ return t ? w.succeed(n) : Oe(e).pipe(w.as(n));
82
+ }), H = (e, t) => a(e, C, t).pipe(w.flatMap((e) => r.namespaceIdentity === void 0 ? w.succeed(e) : w.try({
83
+ try: () => f(e, r.namespaceIdentity),
84
+ catch: (e) => new x.ConfigError(new S.SourceError({ message: e instanceof Error ? e.message : "Connection namespace admission failed" }))
85
+ })), w.flatMap((t) => {
86
+ let n = z(e);
87
+ for (let e of T) if (z(e.reference) === n) {
88
+ if (t.driver === "memory" && e.crossNode) return w.fail(new x.ConfigError(new S.SourceError({ message: `Plugin ${e.consumer} role ${e.role} requires a network Redis connection; memory is local` })));
89
89
  if (t.driver === "http" && (e.pubsub || e.atomicMulti)) {
90
90
  let t = e.pubsub ? "Pub/Sub" : "atomic MULTI";
91
- return T.fail(new S.ConfigError(new C.SourceError({ message: `Plugin ${e.consumer} role ${e.role} requires ${t}; its selected Redis connection requires the RESP driver` })));
91
+ return w.fail(new x.ConfigError(new S.SourceError({ message: `Plugin ${e.consumer} role ${e.role} requires ${t}; its selected Redis connection requires the RESP driver` })));
92
92
  }
93
93
  }
94
- return T.succeed(t);
95
- }), T.mapError((e) => y(e, "redis"))), we = (e, t) => re(e, w, t).pipe(T.flatMap((e) => v.namespaceIdentity === void 0 ? T.succeed(e) : T.try({
96
- try: () => f(e, v.namespaceIdentity),
97
- catch: () => new S.ConfigError(new C.SourceError({ message: "Connection namespace admission failed" }))
98
- })), T.mapError((e) => y(e, "nats"))), Te = (e, t) => ae(e, w, t).pipe(T.flatMap((t) => {
99
- if (v.namespaceIdentity?.environment === "production" && (t = {
94
+ return w.succeed(t);
95
+ }), w.mapError((e) => y(e, "redis"))), U = (e, t) => ne(e, C, t).pipe(w.flatMap((e) => r.namespaceIdentity === void 0 ? w.succeed(e) : w.try({
96
+ try: () => f(e, r.namespaceIdentity),
97
+ catch: () => new x.ConfigError(new S.SourceError({ message: "Connection namespace admission failed" }))
98
+ })), w.mapError((e) => y(e, "nats"))), Te = (e, t) => ie(e, C, t).pipe(w.flatMap((t) => {
99
+ if (r.namespaceIdentity?.environment === "production" && (t = {
100
100
  ...t,
101
101
  tls: "required"
102
- }), v.namespaceIdentity !== void 0 && t.keyPrefix === void 0 && (t = {
102
+ }), r.namespaceIdentity !== void 0 && t.keyPrefix === void 0 && (t = {
103
103
  ...t,
104
- keyPrefix: `${p(v.namespaceIdentity)}/`
105
- }), v.namespaceIdentity?.environment === "production" && t.keyPrefix !== `${p(v.namespaceIdentity)}/` && !t.allowSharedNamespace) return T.fail(new S.ConfigError(new C.SourceError({ message: "A custom production storage namespace requires allowSharedNamespace" })));
106
- for (let n of E) if (B(n.reference) === B(e)) {
107
- if (n.pubsub || n.atomicMulti) return T.fail(new S.ConfigError(new C.SourceError({ message: "Storage cannot provide Pub/Sub or atomic MULTI" })));
104
+ keyPrefix: `${p(r.namespaceIdentity)}/`
105
+ }), r.namespaceIdentity?.environment === "production" && t.keyPrefix !== `${p(r.namespaceIdentity)}/` && !t.allowSharedNamespace) return w.fail(new x.ConfigError(new S.SourceError({ message: "A custom production storage namespace requires allowSharedNamespace" })));
106
+ for (let n of T) if (z(n.reference) === z(e)) {
107
+ if (n.pubsub || n.atomicMulti) return w.fail(new x.ConfigError(new S.SourceError({ message: "Storage cannot provide Pub/Sub or atomic MULTI" })));
108
108
  if (n.crossNode && [
109
109
  "memory",
110
110
  "filesystem",
111
111
  "database"
112
- ].includes(t.provider)) return T.fail(new S.ConfigError(new C.SourceError({ message: "Cross-node storage requires a declared object-storage service" })));
112
+ ].includes(t.provider)) return w.fail(new x.ConfigError(new S.SourceError({ message: "Cross-node storage requires a declared object-storage service" })));
113
113
  }
114
- let n = ie(t);
115
- return n ? T.fail(new S.ConfigError(new C.SourceError({ message: n }))) : T.succeed(t);
116
- }), T.mapError((e) => y(e, "storage"))), Ee = (e, t) => o(e, w, t).pipe(T.flatMap((t) => {
117
- v.namespaceIdentity?.environment === "production" && (t = {
114
+ let n = re(t);
115
+ return n ? w.fail(new x.ConfigError(new S.SourceError({ message: n }))) : w.succeed(t);
116
+ }), w.mapError((e) => y(e, "storage"))), Ee = (e, t) => le(e, C, t).pipe(w.flatMap((t) => {
117
+ r.namespaceIdentity?.environment === "production" && (t = {
118
118
  ...t,
119
119
  tls: "required"
120
120
  });
121
- let n = a(t);
122
- if (n) return T.fail(new S.ConfigError(new C.SourceError({ message: n })));
123
- for (let n of E) if (B(n.reference) === B(e)) {
124
- if (n.pubsub || n.atomicMulti) return T.fail(new S.ConfigError(new C.SourceError({ message: "Analytics cannot provide Redis Pub/Sub or atomic MULTI" })));
125
- if (n.crossNode && t.provider === "duckdb") return T.fail(new S.ConfigError(new C.SourceError({ message: "Cross-node analytics requires a network provider; DuckDB is local" })));
121
+ let n = ce(t);
122
+ if (n) return w.fail(new x.ConfigError(new S.SourceError({ message: n })));
123
+ for (let n of T) if (z(n.reference) === z(e)) {
124
+ if (n.pubsub || n.atomicMulti) return w.fail(new x.ConfigError(new S.SourceError({ message: "Analytics cannot provide Redis Pub/Sub or atomic MULTI" })));
125
+ if (n.crossNode && t.provider === "duckdb") return w.fail(new x.ConfigError(new S.SourceError({ message: "Cross-node analytics requires a network provider; DuckDB is local" })));
126
126
  }
127
- return T.succeed(t);
128
- }), T.mapError((e) => y(e, "analytics"))), De = (e, t) => r(e, w, t).pipe(T.flatMap((t) => {
129
- v.namespaceIdentity?.environment === "production" && !["sqlite", "turso"].includes(t.dialect) && (t = {
127
+ return w.succeed(t);
128
+ }), w.mapError((e) => y(e, "analytics"))), De = (n, i) => t(n, C, i).pipe(w.flatMap((t) => {
129
+ r.namespaceIdentity?.environment === "production" && !["sqlite", "turso"].includes(t.dialect) && (t = {
130
130
  ...t,
131
131
  tls: "required"
132
132
  });
133
- let r = n(t);
134
- if (r) return T.fail(new S.ConfigError(new C.SourceError({ message: r })));
135
- for (let n of E) if (B(n.reference) === B(e)) {
136
- if (n.pubsub || n.atomicMulti) return T.fail(new S.ConfigError(new C.SourceError({ message: "SQL cannot provide Redis Pub/Sub or atomic MULTI" })));
137
- if (n.crossNode && ["sqlite", "turso"].includes(t.dialect)) return T.fail(new S.ConfigError(new C.SourceError({ message: "Cross-node SQL requires a network SQL dialect" })));
133
+ let i = e(t);
134
+ if (i) return w.fail(new x.ConfigError(new S.SourceError({ message: i })));
135
+ for (let e of T) if (z(e.reference) === z(n)) {
136
+ if (e.pubsub || e.atomicMulti) return w.fail(new x.ConfigError(new S.SourceError({ message: "SQL cannot provide Redis Pub/Sub or atomic MULTI" })));
137
+ if (e.crossNode && ["sqlite", "turso"].includes(t.dialect)) return w.fail(new x.ConfigError(new S.SourceError({ message: "Cross-node SQL requires a network SQL dialect" })));
138
138
  }
139
- return T.succeed(t);
140
- }), T.mapError((e) => y(e, "sql")));
139
+ return w.succeed(t);
140
+ }), w.mapError((e) => y(e, "sql")));
141
141
  function Oe(e, t) {
142
- return e.startsWith("sql:") ? De(e, t) : e.startsWith("analytics:") ? Ee(e, t) : e.startsWith("storage:") ? Te(e, t) : e.startsWith("nats:") ? we(e, t) : U(e, t);
142
+ return e.startsWith("sql:") ? De(e, t) : e.startsWith("analytics:") ? Ee(e, t) : e.startsWith("storage:") ? Te(e, t) : e.startsWith("nats:") ? U(e, t) : H(e, t);
143
143
  }
144
- for (let e of E) if ((e.reference.startsWith("nats:") || e.reference.startsWith("storage:") || e.reference.startsWith("analytics:") || e.reference.startsWith("sql:")) && e.atomicMulti) return yield* T.fail(new S.ConfigError(new C.SourceError({ message: `Plugin ${e.consumer} role ${e.role} requires atomic MULTI; NATS cannot provide Redis commands` })));
145
- let W = yield* d({
146
- rotationGraceMs: ve,
144
+ for (let e of T) if ((e.reference.startsWith("nats:") || e.reference.startsWith("storage:") || e.reference.startsWith("analytics:") || e.reference.startsWith("sql:")) && e.atomicMulti) return yield* w.fail(new x.ConfigError(new S.SourceError({ message: `Plugin ${e.consumer} role ${e.role} requires atomic MULTI; NATS cannot provide Redis commands` })));
145
+ let W = yield* u({
146
+ rotationGraceMs: ye,
147
147
  onStopping: () => {
148
- P.clear();
148
+ N.clear();
149
149
  },
150
150
  onStopped: () => {
151
- for (let e of F.values()) e.channels.clear(), e.listeners.clear();
152
- F.clear();
153
- for (let e of z.values()) e.dispose();
154
- z.clear();
155
- for (let e of I.values()) e.clear();
156
- I.clear(), R.clear(), L.clear();
151
+ for (let e of P.values()) e.channels.clear(), e.listeners.clear();
152
+ P.clear();
153
+ for (let e of R.values()) e.dispose();
154
+ R.clear();
155
+ for (let e of F.values()) e.clear();
156
+ F.clear(), L.clear(), I.clear();
157
157
  },
158
- dispose: (e) => T.gen(function* () {
159
- e.detachCommandReconnect?.(), e.binding?.current === e && delete e.binding.current, e.kind === "sql" || e.kind === "storage" || e.kind === "analytics" ? yield* e.transport.close : e.kind === "nats" ? yield* T.promise(() => e.transport.close().catch(() => void 0)) : (yield* T.promise(() => e.subscriber?.close().catch(() => void 0) ?? Promise.resolve()), yield* T.promise(() => e.client.close().catch(() => void 0)));
160
- }).pipe(T.ensuring(T.sync(() => k.close(e))))
158
+ dispose: (e) => w.gen(function* () {
159
+ e.detachCommandReconnect?.(), e.binding?.current === e && delete e.binding.current, e.kind === "sql" || e.kind === "storage" || e.kind === "analytics" ? yield* e.transport.close : e.kind === "nats" ? yield* w.promise(() => e.transport.close().catch(() => void 0)) : (yield* w.promise(() => e.subscriber?.close().catch(() => void 0) ?? Promise.resolve()), yield* w.promise(() => e.client.close().catch(() => void 0)));
160
+ }).pipe(w.ensuring(w.sync(() => O.close(e))))
161
161
  }), { close: G, trackOpen: ke } = W, K = (e) => {
162
- W.register(e), k.register(e, e.reference);
163
- }, Ae = (e) => T.sync(() => k.retire(e)).pipe(T.andThen(W.retire(e))), q = (e) => T.sync(() => k.release(e)).pipe(T.andThen(W.release(e))), J = (e) => {
164
- e.errors++, k.error(e.reference);
165
- }, Y = (e) => (t) => b.hasInterruptsOnly(t) ? T.void : T.sync(() => {
162
+ W.register(e), O.register(e, e.reference);
163
+ }, Ae = (e) => w.sync(() => O.retire(e)).pipe(w.andThen(W.retire(e))), q = (e) => w.sync(() => O.release(e)).pipe(w.andThen(W.release(e))), J = (e) => {
164
+ e.errors++, O.error(e.reference);
165
+ }, Y = (e) => (t) => pe.hasInterruptsOnly(t) ? w.void : w.sync(() => {
166
166
  J(e);
167
- }), X = (e, t) => x.currentTimeNanos.pipe(T.flatMap((n) => e.breaker.state.pipe(T.tap((r) => T.sync(() => {
168
- e.latencyMs = Number(n - t) / 1e6, k.completed(e.reference, e.latencyMs), r === "open" && k.available(e, !1);
167
+ }), X = (e, t) => b.currentTimeNanos.pipe(w.flatMap((n) => e.breaker.state.pipe(w.tap((r) => w.sync(() => {
168
+ e.latencyMs = Number(n - t) / 1e6, O.completed(e.reference, e.latencyMs), r === "open" && O.available(e, !1);
169
169
  }))))), je = (e, t) => {
170
170
  for (let n of e.listeners) try {
171
171
  n(t);
172
172
  } catch {}
173
- }, Me = (t, n) => T.gen(function* () {
174
- if (t.kind === "sql" || t.kind === "storage" || t.kind === "analytics") return yield* T.fail(new e({
173
+ }, Me = (e, t) => w.gen(function* () {
174
+ if (e.kind === "sql" || e.kind === "storage" || e.kind === "analytics") return yield* w.fail(new l({
175
175
  operation: "subscribe",
176
176
  key: "",
177
177
  cause: "Selected connection has no Pub/Sub transport"
178
178
  }));
179
- if (t.subscriber !== void 0) return;
180
- if (t.kind === "redis" && t.config.driver === "http") return yield* T.fail(new e({
179
+ if (e.subscriber !== void 0) return;
180
+ if (e.kind === "redis" && e.config.driver === "http") return yield* w.fail(new l({
181
181
  operation: "subscribe",
182
182
  key: "",
183
183
  cause: "Redis Pub/Sub requires the RESP driver"
184
184
  }));
185
- let r = yield* (t.kind === "nats" ? T.succeed(te(t.transport, t.config.keyPrefix)) : t.memory === void 0 ? (v.connectSubscriber ?? m)(t.config) : T.sync(() => t.memory.subscriber())).pipe(T.mapError(() => new e({
185
+ let n = yield* (e.kind === "nats" ? w.succeed(h(e.transport, e.config.keyPrefix)) : e.memory === void 0 ? (r.connectSubscriber ?? ee)(e.config) : w.sync(() => e.memory.subscriber())).pipe(w.mapError(() => new l({
186
186
  operation: "subscribe",
187
187
  key: "",
188
188
  cause: "Redis subscriber could not be opened"
189
189
  })));
190
- t.subscriber = r, t.binding = n, r.onMessage((e, n) => {
191
- let r = t.binding;
192
- if (!(W.stopped || r?.current !== t || t.closed)) for (let t of r.channels.get(e) ?? []) try {
193
- t(n);
190
+ e.subscriber = n, e.binding = t, n.onMessage((t, n) => {
191
+ let r = e.binding;
192
+ if (!(W.stopped || r?.current !== e || e.closed)) for (let e of r.channels.get(t) ?? []) try {
193
+ e(n);
194
194
  } catch {}
195
- }), r.onTransportEvent((e) => {
196
- let n = t.binding;
197
- !W.stopped && n?.current === t && !t.closed && je(n, e);
198
- }), yield* T.forEach([...n.channels.keys()], (t) => T.tryPromise({
199
- try: () => r.subscribe(t),
200
- catch: () => new e({
195
+ }), n.onTransportEvent((t) => {
196
+ let n = e.binding;
197
+ !W.stopped && n?.current === e && !e.closed && je(n, t);
198
+ }), yield* w.forEach([...t.channels.keys()], (e) => w.tryPromise({
199
+ try: () => n.subscribe(e),
200
+ catch: () => new l({
201
201
  operation: "subscribe",
202
202
  key: "",
203
203
  cause: "Redis subscription could not be registered"
204
204
  })
205
205
  }), { discard: !0 });
206
206
  }), Ne = (e, t) => ke(Me(e, t)), Pe = (e) => {
207
- k.activate(e), e.kind === "storage" && L.set(V(e.reference, e.context), e.config);
207
+ O.activate(e), e.kind === "storage" && I.set(B(e.reference, e.context), e.config);
208
208
  let t = e.binding;
209
209
  if (t === void 0) return;
210
210
  let n = t.current;
211
211
  t.current = e, n !== void 0 && n !== e && t.channels.size > 0 && (je(t, { kind: "disconnected" }), je(t, { kind: "reconnected" }));
212
- }, Fe = (n, r, i, a) => T.uninterruptibleMask((o) => T.gen(function* () {
213
- let s = yield* o((n.startsWith("sql:") ? De(n, r).pipe(T.map((e) => ({
212
+ }, Fe = (e, t, n, a) => w.uninterruptibleMask((o) => w.gen(function* () {
213
+ let s = yield* o((e.startsWith("sql:") ? De(e, t).pipe(w.map((e) => ({
214
214
  kind: "sql",
215
215
  config: e
216
- }))) : n.startsWith("analytics:") ? Ee(n, r).pipe(T.map((e) => ({
216
+ }))) : e.startsWith("analytics:") ? Ee(e, t).pipe(w.map((e) => ({
217
217
  kind: "analytics",
218
218
  config: e
219
- }))) : n.startsWith("storage:") ? Te(n, r).pipe(T.map((e) => ({
219
+ }))) : e.startsWith("storage:") ? Te(e, t).pipe(w.map((e) => ({
220
220
  kind: "storage",
221
221
  config: e
222
- }))) : n.startsWith("nats:") ? we(n, r).pipe(T.map((e) => ({
222
+ }))) : e.startsWith("nats:") ? U(e, t).pipe(w.map((e) => ({
223
223
  kind: "nats",
224
224
  config: e
225
- }))) : U(n, r).pipe(T.map((e) => ({
225
+ }))) : H(e, t).pipe(w.map((e) => ({
226
226
  kind: "redis",
227
227
  config: e
228
- })))).pipe(T.interruptible)), c = yield* x.currentTimeMillis, l = Se(n), u = H(n), d = yield* ge.make({
229
- name: n,
230
- failureThreshold: ye,
231
- resetTimeout: be,
232
- ...s.kind === "sql" ? { isFailure: (t) => t instanceof e || t instanceof _ || typeof t == "object" && !!t && "_tag" in t && t._tag === "HotError" && "reason" in t && t.reason === "unavailable" } : {}
233
- }), f = yield* pe.make(), p = {
234
- reference: B(n),
235
- context: r,
236
- breaker: d,
237
- dynamic: u,
238
- closedSignal: f,
239
- expiresAt: l !== void 0 && "_tag" in l && "ttlMs" in l ? c + l.ttlMs : Infinity,
228
+ })))).pipe(w.interruptible)), c = yield* b.currentTimeMillis, u = Ce(e), f = V(e), p = yield* _e.make({
229
+ name: e,
230
+ failureThreshold: be,
231
+ resetTimeout: xe,
232
+ ...s.kind === "sql" ? { isFailure: (e) => e instanceof l || e instanceof v || typeof e == "object" && !!e && "_tag" in e && e._tag === "HotError" && "reason" in e && e.reason === "unavailable" } : {}
233
+ }), ee = yield* me.make(), m = {
234
+ reference: z(e),
235
+ context: t,
236
+ breaker: p,
237
+ dynamic: f,
238
+ closedSignal: ee,
239
+ expiresAt: u !== void 0 && "_tag" in u && "ttlMs" in u ? c + u.ttlMs : Infinity,
240
240
  active: 0,
241
241
  lastUsed: c,
242
242
  commands: 0,
@@ -244,170 +244,170 @@ var k = class extends w.Service()("@voltro/ConnectionRegistry") {}, A = (v = {})
244
244
  latencyMs: null,
245
245
  retired: !1,
246
246
  closed: !1
247
- }, m;
247
+ }, h;
248
248
  if (s.kind === "sql") {
249
- if (v.connectSql === void 0) return yield* T.fail(new S.ConfigError(new C.SourceError({ message: "SQL requires an app-owned SQL connector" })));
250
- if (a !== void 0 && (a.kind !== "sql" || a.config.dialect !== s.config.dialect)) return yield* T.fail(new S.ConfigError(new C.SourceError({ message: "SQL rotation must preserve the dialect contract" })));
251
- let t = yield* v.connectSql(s.config).pipe(T.mapError(() => new e({
249
+ if (r.connectSql === void 0) return yield* w.fail(new x.ConfigError(new S.SourceError({ message: "SQL requires an app-owned SQL connector" })));
250
+ if (a !== void 0 && (a.kind !== "sql" || a.config.dialect !== s.config.dialect)) return yield* w.fail(new x.ConfigError(new S.SourceError({ message: "SQL rotation must preserve the dialect contract" })));
251
+ let e = yield* r.connectSql(s.config).pipe(w.mapError(() => new l({
252
252
  operation: "connect",
253
253
  key: "",
254
254
  cause: "SQL transport could not be constructed"
255
255
  })));
256
- m = {
257
- ...p,
256
+ h = {
257
+ ...m,
258
258
  kind: "sql",
259
259
  drainUntilReleased: !0,
260
- transport: t,
260
+ transport: e,
261
261
  config: s.config
262
- }, K(m), yield* o(t.probe.pipe(T.interruptible, T.timeout("5 seconds"), T.mapError(() => new e({
262
+ }, K(h), yield* o(e.probe.pipe(w.interruptible, w.timeout("5 seconds"), w.mapError(() => new l({
263
263
  operation: "connect",
264
264
  key: "",
265
265
  cause: "SQL readiness failed"
266
- })))).pipe(T.onError(() => G(m)));
266
+ })))).pipe(w.onError(() => G(h)));
267
267
  } else if (s.kind === "analytics") {
268
- if (v.connectAnalytics === void 0) return yield* T.fail(new S.ConfigError(new C.SourceError({ message: "Analytics requires an app-owned analytics connector" })));
269
- let t = yield* v.connectAnalytics(s.config).pipe(T.mapError(() => new e({
268
+ if (r.connectAnalytics === void 0) return yield* w.fail(new x.ConfigError(new S.SourceError({ message: "Analytics requires an app-owned analytics connector" })));
269
+ let e = yield* r.connectAnalytics(s.config).pipe(w.mapError(() => new l({
270
270
  operation: "connect",
271
271
  key: "",
272
272
  cause: "Analytics transport could not be constructed"
273
273
  })));
274
- if (m = {
275
- ...p,
274
+ if (h = {
275
+ ...m,
276
276
  kind: "analytics",
277
- transport: t,
277
+ transport: e,
278
278
  config: s.config
279
- }, K(m), a !== void 0) {
280
- if (a.kind !== "analytics" || a.config.provider !== s.config.provider) return yield* G(m), yield* T.fail(new S.ConfigError(new C.SourceError({ message: "Analytics rotation must preserve the provider contract" })));
281
- let e = a.transport.sink, n = t.sink;
282
- if (JSON.stringify(e.info.capabilities) !== JSON.stringify(n.info.capabilities) || JSON.stringify(e.mirror?.tables ?? []) !== JSON.stringify(n.mirror?.tables ?? []) || e.mirror?.primaryKey !== n.mirror?.primaryKey) return yield* G(m), yield* T.fail(new S.ConfigError(new C.SourceError({ message: "Analytics rotation must preserve capabilities and mirror schema" })));
279
+ }, K(h), a !== void 0) {
280
+ if (a.kind !== "analytics" || a.config.provider !== s.config.provider) return yield* G(h), yield* w.fail(new x.ConfigError(new S.SourceError({ message: "Analytics rotation must preserve the provider contract" })));
281
+ let t = a.transport.sink, n = e.sink;
282
+ if (JSON.stringify(t.info.capabilities) !== JSON.stringify(n.info.capabilities) || JSON.stringify(t.mirror?.tables ?? []) !== JSON.stringify(n.mirror?.tables ?? []) || t.mirror?.primaryKey !== n.mirror?.primaryKey) return yield* G(h), yield* w.fail(new x.ConfigError(new S.SourceError({ message: "Analytics rotation must preserve capabilities and mirror schema" })));
283
283
  }
284
- yield* o(t.probe.pipe(T.interruptible, T.timeout("5 seconds"), T.mapError(() => new e({
284
+ yield* o(e.probe.pipe(w.interruptible, w.timeout("5 seconds"), w.mapError(() => new l({
285
285
  operation: "connect",
286
286
  key: "",
287
287
  cause: a === void 0 ? "Analytics readiness failed" : "Replacement analytics readiness failed"
288
- })))).pipe(T.onError(() => G(m)));
288
+ })))).pipe(w.onError(() => G(h)));
289
289
  } else if (s.kind === "storage") {
290
- if (v.connectStorage === void 0) return yield* T.fail(new S.ConfigError(new C.SourceError({ message: "Storage requires an app-owned storage connector" })));
291
- let t;
290
+ if (r.connectStorage === void 0) return yield* w.fail(new x.ConfigError(new S.SourceError({ message: "Storage requires an app-owned storage connector" })));
291
+ let n;
292
292
  if (s.config.provider === "memory") {
293
- let e = V(n, r);
294
- t = I.get(e), t === void 0 && (t = /* @__PURE__ */ new Map(), I.set(e, t));
293
+ let r = B(e, t);
294
+ n = F.get(r), n === void 0 && (n = /* @__PURE__ */ new Map(), F.set(r, n));
295
295
  }
296
- let i = yield* v.connectStorage(s.config, t === void 0 ? {} : { memory: t }).pipe(T.mapError(() => new e({
296
+ let i = yield* r.connectStorage(s.config, n === void 0 ? {} : { memory: n }).pipe(w.mapError(() => new l({
297
297
  operation: "connect",
298
298
  key: "",
299
299
  cause: "Storage transport could not be constructed"
300
300
  })));
301
- m = {
302
- ...p,
301
+ h = {
302
+ ...m,
303
303
  kind: "storage",
304
304
  transport: i,
305
305
  config: s.config
306
- }, K(m);
307
- let o = R.get(V(n, r));
308
- o !== void 0 && i.provider.bindDataStore?.(o), a !== void 0 && (yield* i.probe.pipe(T.timeout("5 seconds"), T.mapError(() => new e({
306
+ }, K(h);
307
+ let o = L.get(B(e, t));
308
+ o !== void 0 && i.provider.bindDataStore?.(o), a !== void 0 && (yield* i.probe.pipe(w.timeout("5 seconds"), w.mapError(() => new l({
309
309
  operation: "connect",
310
310
  key: "",
311
311
  cause: "Replacement storage readiness failed"
312
- })), T.onError(() => G(m))));
312
+ })), w.onError(() => G(h))));
313
313
  } else if (s.kind === "nats") {
314
- let t = s.config, n = yield* (v.connectNats === void 0 ? ne(t).pipe(T.timeout("5 seconds"), T.interruptible) : v.connectNats(t)).pipe(T.mapError(() => new e({
314
+ let e = s.config, t = yield* (r.connectNats === void 0 ? te(e).pipe(w.timeout("5 seconds"), w.interruptible) : r.connectNats(e)).pipe(w.mapError(() => new l({
315
315
  operation: "connect",
316
316
  key: "",
317
317
  cause: "NATS driver could not be opened"
318
318
  })));
319
- m = {
320
- ...p,
319
+ h = {
320
+ ...m,
321
321
  kind: "nats",
322
- transport: n,
323
- config: t
324
- }, K(m);
325
- let r = m;
326
- m.detachCommandReconnect = n.onTransportEvent((e) => {
327
- e.kind !== "reconnected" || W.stopped || r.closed || r.retired || T.runSyncWith(M)(r.breaker.reset);
322
+ transport: t,
323
+ config: e
324
+ }, K(h);
325
+ let n = h;
326
+ h.detachCommandReconnect = t.onTransportEvent((e) => {
327
+ e.kind !== "reconnected" || W.stopped || n.closed || n.retired || w.runSyncWith(j)(n.breaker.reset);
328
328
  });
329
329
  } else {
330
- let i = s.config, { keyPrefix: a, ...o } = i, c;
331
- if (i.driver === "memory") {
332
- let e = V(n, r);
333
- if (c = z.get(e), c === void 0) {
334
- let { makeMemoryConnectionState: t } = yield* T.promise(() => import("./connectionMemory.js"));
335
- c = t(i.memoryClock), z.set(e, c);
330
+ let n = s.config, { keyPrefix: a, ...o } = n, c;
331
+ if (n.driver === "memory") {
332
+ let r = B(e, t);
333
+ if (c = R.get(r), c === void 0) {
334
+ let { makeMemoryConnectionState: e } = yield* w.promise(() => import("./connectionMemory.js"));
335
+ c = e(n.memoryClock), R.set(r, c);
336
336
  }
337
337
  }
338
- let l = yield* (c === void 0 ? v.connect === void 0 ? de(o).pipe(T.interruptible) : v.connect(o) : T.sync(() => c.command())).pipe(T.map((e) => t(e, a)), T.mapError(() => new e({
338
+ let u = yield* (c === void 0 ? r.connect === void 0 ? i(o).pipe(w.interruptible) : r.connect(o) : w.sync(() => c.command())).pipe(w.map((e) => d(e, a)), w.mapError(() => new l({
339
339
  operation: "connect",
340
340
  key: "",
341
341
  cause: "Connection driver could not be opened"
342
342
  })));
343
- m = {
344
- ...p,
343
+ h = {
344
+ ...m,
345
345
  kind: "redis",
346
- client: l,
347
- config: i,
346
+ client: u,
347
+ config: n,
348
348
  ...c === void 0 ? {} : { memory: c }
349
- }, K(m);
350
- let u = m, d = l.onReconnect?.(() => {
351
- W.stopped || u.closed || u.retired || T.runSyncWith(M)(u.breaker.reset);
349
+ }, K(h);
350
+ let f = h, p = u.onReconnect?.(() => {
351
+ W.stopped || f.closed || f.retired || w.runSyncWith(j)(f.breaker.reset);
352
352
  });
353
- d !== void 0 && (m.detachCommandReconnect = d);
353
+ p !== void 0 && (h.detachCommandReconnect = p);
354
354
  }
355
- return k.available(m, m.kind !== "storage" || a !== void 0), i?.(m), a?.binding !== void 0 && (m.binding = a.binding, a.binding.channels.size > 0 && (yield* Ne(m, a.binding).pipe(T.onError(() => G(m))))), i === void 0 && Pe(m), m;
356
- })), Ie = (e, t, n, r) => ke(Fe(e, t, n, r)).pipe(T.tapCause((t) => b.hasInterruptsOnly(t) ? T.void : T.sync(() => {
357
- let t = B(e);
358
- /^(redis|nats|storage|analytics|sql):[A-Za-z][A-Za-z0-9_-]*$/.test(t) && k.error(t);
359
- }))), Z = (t, n) => O.modifyEffect(N, (r) => T.gen(function* () {
360
- if (W.stopped) return yield* T.fail(new e({
355
+ return O.available(h, h.kind !== "storage" || a !== void 0), n?.(h), a?.binding !== void 0 && (h.binding = a.binding, a.binding.channels.size > 0 && (yield* Ne(h, a.binding).pipe(w.onError(() => G(h))))), n === void 0 && Pe(h), h;
356
+ })), Ie = (e, t, n, r) => ke(Fe(e, t, n, r)).pipe(w.tapCause((t) => pe.hasInterruptsOnly(t) ? w.void : w.sync(() => {
357
+ let t = z(e);
358
+ /^(redis|nats|storage|analytics|sql):[A-Za-z][A-Za-z0-9_-]*$/.test(t) && O.error(t);
359
+ }))), Z = (e, t) => D.modifyEffect(M, (n) => w.gen(function* () {
360
+ if (W.stopped) return yield* w.fail(new l({
361
361
  operation: "connect",
362
362
  key: "",
363
363
  cause: "Connection registry is closed"
364
364
  }));
365
- let i = V(t, n), a = yield* x.currentTimeMillis, o = r.get(i);
366
- if (o && o.expiresAt > a) return o.active++, k.acquire(o), o.lastUsed = a, [o, r];
367
- let s = new Map(r);
368
- if (!o && H(t)) {
369
- let r = [...s.entries()].filter(([, e]) => e.dynamic);
370
- if (r.length >= j) {
371
- let a = r.filter(([, e]) => e.active === 0 && (e.binding?.channels.size ?? 0) === 0).sort((e, t) => e[1].lastUsed - t[1].lastUsed)[0];
372
- if (!a) return yield* T.fail(new e({
365
+ let r = B(e, t), i = yield* b.currentTimeMillis, a = n.get(r);
366
+ if (a && a.expiresAt > i) return a.active++, O.acquire(a), a.lastUsed = i, [a, n];
367
+ let o = new Map(n);
368
+ if (!a && V(e)) {
369
+ let n = [...o.entries()].filter(([, e]) => e.dynamic);
370
+ if (n.length >= A) {
371
+ let i = n.filter(([, e]) => e.active === 0 && (e.binding?.channels.size ?? 0) === 0).sort((e, t) => e[1].lastUsed - t[1].lastUsed)[0];
372
+ if (!i) return yield* w.fail(new l({
373
373
  operation: "connect",
374
374
  key: "",
375
375
  cause: "All dynamic connection pools are busy; maxDynamicPools reached"
376
376
  }));
377
- let c = yield* Ie(t, n, void 0, o);
378
- return s.delete(a[0]), yield* Ae(a[1]), c.active++, k.acquire(c), s.set(i, c), [c, s];
377
+ let s = yield* Ie(e, t, void 0, a);
378
+ return o.delete(i[0]), yield* Ae(i[1]), s.active++, O.acquire(s), o.set(r, s), [s, o];
379
379
  }
380
380
  }
381
- let c = yield* Ie(t, n, void 0, o);
382
- return o && (yield* Ae(o)), c.active++, k.acquire(c), s.set(i, c), [c, s];
383
- })), Q = (t, n, r, i) => T.acquireUseRelease(Z(t, n), (t) => T.gen(function* () {
384
- let n = yield* x.currentTimeNanos;
385
- return t.commands++, k.command(t.reference), yield* t.breaker(i(t)).pipe(T.tap(() => T.sync(() => k.available(t, !0))), T.tapCause(Y(t)), T.mapError((t) => t instanceof _e ? new e({
386
- operation: r,
381
+ let s = yield* Ie(e, t, void 0, a);
382
+ return a && (yield* Ae(a)), s.active++, O.acquire(s), o.set(r, s), [s, o];
383
+ })), Q = (e, t, n, r) => w.acquireUseRelease(Z(e, t), (e) => w.gen(function* () {
384
+ let t = yield* b.currentTimeNanos;
385
+ return e.commands++, O.command(e.reference), yield* e.breaker(r(e)).pipe(w.tap(() => w.sync(() => O.available(e, !0))), w.tapCause(Y(e)), w.mapError((e) => e instanceof ve ? new l({
386
+ operation: n,
387
387
  key: "",
388
- cause: `Connection circuit is open; retry after ${t.retryAfterMs} ms`
389
- }) : t), T.ensuring(X(t, n)));
390
- }), q), Le = (t, n, r, i) => xe(Q(t, n, r, (t) => T.tryPromise({
391
- try: () => i(t),
392
- catch: () => new e({
393
- operation: r,
388
+ cause: `Connection circuit is open; retry after ${e.retryAfterMs} ms`
389
+ }) : e), w.ensuring(X(e, t)));
390
+ }), q), Le = (e, t, n, r) => Se(Q(e, t, n, (e) => w.tryPromise({
391
+ try: () => r(e),
392
+ catch: () => new l({
393
+ operation: n,
394
394
  key: "",
395
395
  cause: "Connection command failed"
396
396
  })
397
- }))), Re = (t, n) => Q(t, n, "probe", (t) => t.kind === "sql" ? t.transport.probe : t.kind === "analytics" ? t.transport.probe.pipe(T.mapError(() => new e({
397
+ }))), Re = (e, t) => Q(e, t, "probe", (e) => e.kind === "sql" ? e.transport.probe : e.kind === "analytics" ? e.transport.probe.pipe(w.mapError(() => new l({
398
398
  operation: "probe",
399
399
  key: "",
400
400
  cause: "Analytics readiness probe failed"
401
- }))) : t.kind === "storage" ? t.transport.probe.pipe(T.mapError(() => new e({
401
+ }))) : e.kind === "storage" ? e.transport.probe.pipe(w.mapError(() => new l({
402
402
  operation: "probe",
403
403
  key: "",
404
404
  cause: "Storage readiness probe failed"
405
- }))) : T.tryPromise({
405
+ }))) : w.tryPromise({
406
406
  try: async () => {
407
- if (t.kind === "nats") return t.transport.flush();
408
- if (t.client.ping === void 0 || await t.client.ping() !== "PONG") throw Error("Redis readiness requires PONG");
407
+ if (e.kind === "nats") return e.transport.flush();
408
+ if (e.client.ping === void 0 || await e.client.ping() !== "PONG") throw Error("Redis readiness requires PONG");
409
409
  },
410
- catch: () => new e({
410
+ catch: () => new l({
411
411
  operation: "probe",
412
412
  key: "",
413
413
  cause: "Connection readiness probe failed"
@@ -415,12 +415,12 @@ var k = class extends w.Service()("@voltro/ConnectionRegistry") {}, A = (v = {})
415
415
  })), $ = (e, t, n, r) => Le(e, t, n, (e) => {
416
416
  if (e.kind !== "redis") throw Error("Redis commands require a Redis connection");
417
417
  return r(e.client);
418
- }), ze = (e, t) => T.gen(function* () {
419
- if (e.includes(":") && !e.startsWith("redis:")) return yield* T.fail(new S.ConfigError(new C.SourceError({ message: "Redis commands require a redis:name reference" })));
420
- let n = t === void 0 ? void 0 : Object.freeze({ tenantId: t.tenantId }), r = yield* T.acquireUseRelease(Z(e, n), (e) => e.kind === "redis" ? T.succeed({
418
+ }), ze = (e, t) => w.gen(function* () {
419
+ if (e.includes(":") && !e.startsWith("redis:")) return yield* w.fail(new x.ConfigError(new S.SourceError({ message: "Redis commands require a redis:name reference" })));
420
+ let n = t === void 0 ? void 0 : Object.freeze({ tenantId: t.tenantId }), r = yield* w.acquireUseRelease(Z(e, n), (e) => e.kind === "redis" ? w.succeed({
421
421
  ping: e.client.ping !== void 0,
422
422
  crossNode: e.client.crossNode
423
- }) : T.fail(new S.ConfigError(new C.SourceError({ message: "Redis commands require a redis:name reference" }))), q), i = V(e, n), a = P.get(i);
423
+ }) : w.fail(new x.ConfigError(new S.SourceError({ message: "Redis commands require a redis:name reference" }))), q), i = B(e, n), a = N.get(i);
424
424
  if (a) return a;
425
425
  let o = (t, r) => $(e, n, t, (e) => {
426
426
  if (e.readOnly === void 0) throw Error("Connection has no read-only transport");
@@ -448,64 +448,64 @@ var k = class extends w.Service()("@voltro/ConnectionRegistry") {}, A = (v = {})
448
448
  scan: (t, r, i) => $(e, n, "scan", (e) => e.scan(t, r, i)),
449
449
  close: () => Promise.resolve()
450
450
  };
451
- return H(e) || P.set(i, s), s;
451
+ return V(e) || N.set(i, s), s;
452
452
  });
453
453
  return {
454
454
  client: ze,
455
455
  config: Oe,
456
- validate: Ce,
457
- storage: (e, t) => T.gen(function* () {
458
- if (!e.startsWith("storage:")) return yield* T.fail(new S.ConfigError(new C.SourceError({ message: "Storage requires a storage:name reference" })));
459
- let n = t === void 0 ? void 0 : Object.freeze({ tenantId: t.tenantId }), r = yield* T.acquireUseRelease(Z(e, n), (e) => e.kind === "storage" ? T.succeed(e.config) : T.fail(new S.ConfigError(new C.SourceError({ message: "Storage requires a storage:name reference" }))), q), i = V(e, n), a = (e) => new h({
456
+ validate: we,
457
+ storage: (e, t) => w.gen(function* () {
458
+ if (!e.startsWith("storage:")) return yield* w.fail(new x.ConfigError(new S.SourceError({ message: "Storage requires a storage:name reference" })));
459
+ let n = t === void 0 ? void 0 : Object.freeze({ tenantId: t.tenantId }), r = yield* w.acquireUseRelease(Z(e, n), (e) => e.kind === "storage" ? w.succeed(e.config) : w.fail(new x.ConfigError(new S.SourceError({ message: "Storage requires a storage:name reference" }))), q), i = B(e, n), a = (e) => new g({
460
460
  provider: r.provider,
461
461
  message: "Storage connection operation failed",
462
- transient: e instanceof h ? e.transient : !0,
463
- ...e instanceof h && e.outcome !== void 0 ? { outcome: e.outcome } : {},
464
- ...e instanceof h && e.status !== void 0 ? { status: e.status } : {}
462
+ transient: e instanceof g ? e.transient : !0,
463
+ ...e instanceof g && e.outcome !== void 0 ? { outcome: e.outcome } : {},
464
+ ...e instanceof g && e.status !== void 0 ? { status: e.status } : {}
465
465
  });
466
- return se({
467
- config: () => L.get(i) ?? r,
468
- command: (t, r) => T.acquireUseRelease(Z(e, n).pipe(T.mapError(a)), (e) => T.gen(function* () {
469
- if (e.kind !== "storage") return yield* T.fail(a(void 0));
470
- let t = yield* x.currentTimeNanos;
471
- return e.commands++, k.command(e.reference), yield* e.breaker(r(e.transport.provider)).pipe(T.tap(() => T.sync(() => k.available(e, !0))), T.tapCause(Y(e)), T.mapError(a), T.ensuring(X(e, t)));
466
+ return oe({
467
+ config: () => I.get(i) ?? r,
468
+ command: (t, r) => w.acquireUseRelease(Z(e, n).pipe(w.mapError(a)), (e) => w.gen(function* () {
469
+ if (e.kind !== "storage") return yield* w.fail(a(void 0));
470
+ let t = yield* b.currentTimeNanos;
471
+ return e.commands++, O.command(e.reference), yield* e.breaker(r(e.transport.provider)).pipe(w.tap(() => w.sync(() => O.available(e, !0))), w.tapCause(Y(e)), w.mapError(a), w.ensuring(X(e, t)));
472
472
  }), q),
473
- stream: (t, r) => D.unwrap(T.acquireRelease(Z(e, n).pipe(T.mapError(a)), q).pipe(T.flatMap((e) => T.gen(function* () {
474
- if (e.kind !== "storage") return yield* T.fail(a(void 0));
475
- let n = yield* x.currentTimeNanos;
476
- e.commands++, k.command(e.reference), yield* T.addFinalizer(() => X(e, n));
477
- let i = e.transport.provider, o = i.getStream === void 0 ? i.get(t).pipe(T.flatMap((t) => t.bytes.byteLength !== r.size || t.contentType !== (r.contentType ?? "application/octet-stream") ? T.fail(new h({
473
+ stream: (t, r) => E.unwrap(w.acquireRelease(Z(e, n).pipe(w.mapError(a)), q).pipe(w.flatMap((e) => w.gen(function* () {
474
+ if (e.kind !== "storage") return yield* w.fail(a(void 0));
475
+ let n = yield* b.currentTimeNanos;
476
+ e.commands++, O.command(e.reference), yield* w.addFinalizer(() => X(e, n));
477
+ let i = e.transport.provider, o = i.getStream === void 0 ? i.get(t).pipe(w.flatMap((t) => t.bytes.byteLength !== r.size || t.contentType !== (r.contentType ?? "application/octet-stream") ? w.fail(new g({
478
478
  provider: e.config.provider,
479
479
  message: "Storage metadata changed before stream consumption",
480
480
  transient: !0
481
- })) : T.succeed(D.succeed(t.bytes)))) : T.acquireRelease(i.getStream(t), (e) => e.close ?? T.void).pipe(T.flatMap((t) => t.size !== void 0 && t.size !== r.size || t.contentType !== (r.contentType ?? "application/octet-stream") ? T.fail(new h({
481
+ })) : w.succeed(E.succeed(t.bytes)))) : w.acquireRelease(i.getStream(t), (e) => e.close ?? w.void).pipe(w.flatMap((t) => t.size !== void 0 && t.size !== r.size || t.contentType !== (r.contentType ?? "application/octet-stream") ? w.fail(new g({
482
482
  provider: e.config.provider,
483
483
  message: "Storage metadata changed before stream consumption",
484
484
  transient: !0
485
- })) : T.succeed(t.stream)));
486
- return yield* e.breaker(o).pipe(T.tap(() => T.sync(() => k.available(e, !0))), T.tapCause(Y(e)), T.mapError(a), T.map((t) => t.pipe(D.mapError(a), D.tapCause((t) => Y(e)(t)))));
485
+ })) : w.succeed(t.stream)));
486
+ return yield* e.breaker(o).pipe(w.tap(() => w.sync(() => O.available(e, !0))), w.tapCause(Y(e)), w.mapError(a), w.map((t) => t.pipe(E.mapError(a), E.tapCause((t) => Y(e)(t)))));
487
487
  })))),
488
488
  bind: (e) => {
489
489
  if (W.stopped) throw Error("Connection registry is closed");
490
- R.set(i, e);
491
- for (let t of T.runSyncWith(M)(O.get(N)).values()) t.kind === "storage" && V(t.reference, t.context) === i && t.transport.provider.bindDataStore?.(e);
490
+ L.set(i, e);
491
+ for (let t of w.runSyncWith(j)(D.get(M)).values()) t.kind === "storage" && B(t.reference, t.context) === i && t.transport.provider.bindDataStore?.(e);
492
492
  }
493
493
  });
494
494
  }),
495
- analytics: (e, t) => T.gen(function* () {
496
- if (!e.startsWith("analytics:")) return yield* T.fail(new S.ConfigError(new C.SourceError({ message: "Analytics requires an analytics:name reference" })));
497
- let n = t === void 0 ? void 0 : Object.freeze({ tenantId: t.tenantId }), r = yield* T.acquireUseRelease(Z(e, n), (e) => e.kind === "analytics" ? T.succeed(e.transport.sink) : T.fail(new S.ConfigError(new C.SourceError({ message: "Analytics requires an analytics:name reference" }))), q), i = Object.freeze({
495
+ analytics: (e, t) => w.gen(function* () {
496
+ if (!e.startsWith("analytics:")) return yield* w.fail(new x.ConfigError(new S.SourceError({ message: "Analytics requires an analytics:name reference" })));
497
+ let n = t === void 0 ? void 0 : Object.freeze({ tenantId: t.tenantId }), r = yield* w.acquireUseRelease(Z(e, n), (e) => e.kind === "analytics" ? w.succeed(e.transport.sink) : w.fail(new x.ConfigError(new S.SourceError({ message: "Analytics requires an analytics:name reference" }))), q), i = Object.freeze({
498
498
  provider: r.info.provider,
499
499
  capabilities: Object.freeze({ ...r.info.capabilities })
500
- }), a = (t, r) => Q(e, n, t, (e) => e.kind === "analytics" ? T.suspend(() => r(e.transport.sink)).pipe(T.mapError((e) => e instanceof g ? e : new _({
500
+ }), a = (t, r) => Q(e, n, t, (e) => e.kind === "analytics" ? w.suspend(() => r(e.transport.sink)).pipe(w.mapError((e) => e instanceof _ ? e : new v({
501
501
  provider: i.provider,
502
502
  operation: t,
503
503
  cause: "Analytics connection operation failed"
504
- }))) : T.fail(new _({
504
+ }))) : w.fail(new v({
505
505
  provider: i.provider,
506
506
  operation: t,
507
507
  cause: "Selected connection is not analytics"
508
- }))).pipe(T.mapError((e) => e instanceof g ? e : new _({
508
+ }))).pipe(w.mapError((e) => e instanceof _ ? e : new v({
509
509
  provider: i.provider,
510
510
  operation: t,
511
511
  cause: "Analytics connection operation failed"
@@ -519,196 +519,196 @@ var k = class extends w.Service()("@voltro/ConnectionRegistry") {}, A = (v = {})
519
519
  ...r.mirror === void 0 ? {} : { mirror: {
520
520
  tables: Object.freeze([...r.mirror.tables]),
521
521
  ...r.mirror.primaryKey === void 0 ? {} : { primaryKey: r.mirror.primaryKey },
522
- upsert: (e) => a("mirror.upsert", (t) => t.mirror === void 0 ? T.fail(new g({
522
+ upsert: (e) => a("mirror.upsert", (t) => t.mirror === void 0 ? w.fail(new _({
523
523
  provider: i.provider,
524
524
  capability: "mirror"
525
525
  })) : t.mirror.upsert(e)),
526
- remove: (e) => a("mirror.remove", (t) => t.mirror === void 0 ? T.fail(new g({
526
+ remove: (e) => a("mirror.remove", (t) => t.mirror === void 0 ? w.fail(new _({
527
527
  provider: i.provider,
528
528
  capability: "mirror"
529
529
  })) : t.mirror.remove(e)),
530
- maxVersion: (e) => a("mirror.maxVersion", (t) => t.mirror === void 0 ? T.fail(new g({
530
+ maxVersion: (e) => a("mirror.maxVersion", (t) => t.mirror === void 0 ? w.fail(new _({
531
531
  provider: i.provider,
532
532
  capability: "mirror"
533
533
  })) : t.mirror.maxVersion(e))
534
534
  } }
535
535
  };
536
536
  }),
537
- sql: (t, n) => T.gen(function* () {
538
- if (!/^sql:[A-Za-z][A-Za-z0-9_-]*$/.test(t)) return yield* T.fail(new S.ConfigError(new C.SourceError({ message: "SQL requires a sql:name reference" })));
539
- let r = n === void 0 ? void 0 : Object.freeze({ tenantId: n.tenantId }), i = yield* T.acquireUseRelease(Z(t, r), (e) => e.kind === "sql" ? T.succeed(e.config.dialect) : T.fail(new S.ConfigError(new C.SourceError({ message: "SQL requires a sql:name reference" }))), q), a = () => new e({
537
+ sql: (e, t) => w.gen(function* () {
538
+ if (!/^sql:[A-Za-z][A-Za-z0-9_-]*$/.test(e)) return yield* w.fail(new x.ConfigError(new S.SourceError({ message: "SQL requires a sql:name reference" })));
539
+ let n = t === void 0 ? void 0 : Object.freeze({ tenantId: t.tenantId }), r = yield* w.acquireUseRelease(Z(e, n), (e) => e.kind === "sql" ? w.succeed(e.config.dialect) : w.fail(new x.ConfigError(new S.SourceError({ message: "SQL requires a sql:name reference" }))), q), i = () => new l({
540
540
  operation: "sql",
541
541
  key: "",
542
542
  cause: "SQL connection operation failed"
543
- }), o = (e) => typeof e == "object" && e && "_tag" in e && e._tag === "SqlError" ? a() : e;
543
+ }), a = (e) => typeof e == "object" && e && "_tag" in e && e._tag === "SqlError" ? i() : e;
544
544
  return {
545
- dialect: i,
546
- use: (e) => Q(t, r, "sql", (t) => t.kind === "sql" ? T.suspend(() => e(t.transport.client)).pipe(T.mapError(o)) : T.fail(a())),
547
- stream: (n) => D.unwrap(T.gen(function* () {
548
- let i = yield* T.acquireRelease(Z(t, r), q);
549
- if (i.kind !== "sql") return D.fail(a());
550
- let s = yield* x.currentTimeNanos;
551
- i.commands++, k.command(i.reference), yield* T.addFinalizer(() => X(i, s));
552
- let c = yield* T.scope, l = yield* T.cached(D.toPull(D.suspend(() => n(i.transport.client))).pipe(T.provideService(he.Scope, c))), u = T.flatMap(l, (e) => e);
553
- return D.fromPull(T.succeed(i.breaker(u.pipe(T.mapError(o), me.catchDone(() => T.succeed(null)))).pipe(T.tap(() => T.sync(() => k.available(i, !0))), T.tapCause(Y(i)), T.mapError((t) => t instanceof _e ? new e({
545
+ dialect: r,
546
+ use: (t) => Q(e, n, "sql", (e) => e.kind === "sql" ? w.suspend(() => t(e.transport.client)).pipe(w.mapError(a)) : w.fail(i())),
547
+ stream: (t) => E.unwrap(w.gen(function* () {
548
+ let r = yield* w.acquireRelease(Z(e, n), q);
549
+ if (r.kind !== "sql") return E.fail(i());
550
+ let o = yield* b.currentTimeNanos;
551
+ r.commands++, O.command(r.reference), yield* w.addFinalizer(() => X(r, o));
552
+ let s = yield* w.scope, c = yield* w.cached(E.toPull(E.suspend(() => t(r.transport.client))).pipe(w.provideService(ge.Scope, s))), u = w.flatMap(c, (e) => e);
553
+ return E.fromPull(w.succeed(r.breaker(u.pipe(w.mapError(a), he.catchDone(() => w.succeed(null)))).pipe(w.tap(() => w.sync(() => O.available(r, !0))), w.tapCause(Y(r)), w.mapError((e) => e instanceof ve ? new l({
554
554
  operation: "sql",
555
555
  key: "",
556
- cause: `Connection circuit is open; retry after ${t.retryAfterMs} ms`
557
- }) : t), T.flatMap((e) => e === null ? b.done() : T.succeed(e)))));
556
+ cause: `Connection circuit is open; retry after ${e.retryAfterMs} ms`
557
+ }) : e), w.flatMap((e) => e === null ? pe.done() : w.succeed(e)))));
558
558
  }))
559
559
  };
560
560
  }),
561
- pubsub: (t, n) => T.gen(function* () {
562
- if (t.includes(":") && !/^(redis|nats):/.test(t)) return yield* T.fail(new S.ConfigError(new C.SourceError({ message: "Pub/Sub requires a Redis or NATS reference" })));
563
- if (W.stopped) return yield* T.fail(new e({
561
+ pubsub: (e, t) => w.gen(function* () {
562
+ if (e.includes(":") && !/^(redis|nats):/.test(e)) return yield* w.fail(new x.ConfigError(new S.SourceError({ message: "Pub/Sub requires a Redis or NATS reference" })));
563
+ if (W.stopped) return yield* w.fail(new l({
564
564
  operation: "subscribe",
565
565
  key: "",
566
566
  cause: "Connection registry is closed"
567
567
  }));
568
- let r = n === void 0 ? void 0 : Object.freeze({ tenantId: n.tenantId }), i = yield* t.startsWith("nats:") ? we(t, r) : U(t, r);
569
- if (W.stopped) return yield* T.fail(new e({
568
+ let n = t === void 0 ? void 0 : Object.freeze({ tenantId: t.tenantId }), r = yield* e.startsWith("nats:") ? U(e, n) : H(e, n);
569
+ if (W.stopped) return yield* w.fail(new l({
570
570
  operation: "subscribe",
571
571
  key: "",
572
572
  cause: "Connection registry is closed"
573
573
  }));
574
- if ("driver" in i && i.driver === "http") return yield* T.fail(new e({
574
+ if ("driver" in r && r.driver === "http") return yield* w.fail(new l({
575
575
  operation: "subscribe",
576
576
  key: "",
577
577
  cause: "Redis Pub/Sub requires the RESP driver"
578
578
  }));
579
- let a = V(t, r), o = F.get(a);
580
- o === void 0 && (o = {
579
+ let i = B(e, n), a = P.get(i);
580
+ a === void 0 && (a = {
581
581
  channels: /* @__PURE__ */ new Map(),
582
582
  listeners: /* @__PURE__ */ new Set(),
583
583
  consumers: 0
584
- }, F.set(a, o));
585
- let s = o;
586
- s.consumers++;
587
- let c = !1, l = /* @__PURE__ */ new Set(), u = /* @__PURE__ */ new Set(), d = (e) => O.updateEffect(N, (t) => T.gen(function* () {
584
+ }, P.set(i, a));
585
+ let o = a;
586
+ o.consumers++;
587
+ let s = !1, c = /* @__PURE__ */ new Set(), u = /* @__PURE__ */ new Set(), d = (e) => D.updateEffect(M, (t) => w.gen(function* () {
588
588
  if (e.released) return t;
589
- e.released = !0, l.delete(e);
590
- let n = s.channels.get(e.channel);
589
+ e.released = !0, c.delete(e);
590
+ let n = o.channels.get(e.channel);
591
591
  if (n?.delete(e.handler), n?.size === 0) {
592
- s.channels.delete(e.channel);
593
- let t = s.current;
594
- t?.subscriber !== void 0 && !t.closed && (yield* T.promise(() => t.subscriber.unsubscribe(e.channel).catch(() => {
592
+ o.channels.delete(e.channel);
593
+ let t = o.current;
594
+ t?.subscriber !== void 0 && !t.closed && (yield* w.promise(() => t.subscriber.unsubscribe(e.channel).catch(() => {
595
595
  J(t);
596
596
  })));
597
597
  }
598
598
  return t;
599
- })).pipe(T.uninterruptible), f = yield* T.cached(T.gen(function* () {
600
- c = !0, yield* O.update(N, (e) => e);
601
- for (let e of u) s.listeners.delete(e);
602
- u.clear(), yield* T.forEach([...l], d, { discard: !0 }), s.consumers--, s.consumers === 0 && F.get(a) === s && F.delete(a);
603
- }).pipe(T.uninterruptible)), p = (n) => t.startsWith("nats:") ? T.try({
604
- try: () => ee(`${i.keyPrefix ?? ""}${n}`),
605
- catch: () => new e({
599
+ })).pipe(w.uninterruptible), f = yield* w.cached(w.gen(function* () {
600
+ s = !0, yield* D.update(M, (e) => e);
601
+ for (let e of u) o.listeners.delete(e);
602
+ u.clear(), yield* w.forEach([...c], d, { discard: !0 }), o.consumers--, o.consumers === 0 && P.get(i) === o && P.delete(i);
603
+ }).pipe(w.uninterruptible)), p = (t) => e.startsWith("nats:") ? w.try({
604
+ try: () => m(`${r.keyPrefix ?? ""}${t}`),
605
+ catch: () => new l({
606
606
  operation: "subscribe",
607
607
  key: "",
608
608
  cause: "NATS channels must be exact nonempty subjects"
609
609
  })
610
- }) : T.void;
610
+ }) : w.void;
611
611
  return {
612
- publish: (n, i) => T.suspend(() => c || W.stopped ? T.fail(new e({
612
+ publish: (t, r) => w.suspend(() => s || W.stopped ? w.fail(new l({
613
613
  operation: "publish",
614
614
  key: "",
615
615
  cause: "Pub/Sub consumer is closed"
616
- })) : p(n).pipe(T.andThen(T.tryPromise({
617
- try: () => Le(t, r, "publish", (e) => e.kind === "nats" ? e.transport.publish(`${e.config.keyPrefix ?? ""}${n}`, i) : e.kind === "redis" ? e.client.eval(ce, 0, n, i) : Promise.reject(/* @__PURE__ */ Error("Storage has no Pub/Sub"))),
618
- catch: () => new e({
616
+ })) : p(t).pipe(w.andThen(w.tryPromise({
617
+ try: () => Le(e, n, "publish", (e) => e.kind === "nats" ? e.transport.publish(`${e.config.keyPrefix ?? ""}${t}`, r) : e.kind === "redis" ? e.client.eval(se, 0, t, r) : Promise.reject(/* @__PURE__ */ Error("Storage has no Pub/Sub"))),
618
+ catch: () => new l({
619
619
  operation: "publish",
620
620
  key: "",
621
621
  cause: "Pub/Sub publication failed"
622
622
  })
623
- }))).pipe(T.asVoid)),
624
- subscribe: (n, i) => p(n).pipe(T.andThen(T.uninterruptibleMask(() => T.acquireUseRelease(Z(t, r), () => O.modifyEffect(N, (t) => T.gen(function* () {
625
- if (c || W.stopped) return yield* T.fail(new e({
623
+ }))).pipe(w.asVoid)),
624
+ subscribe: (t, r) => p(t).pipe(w.andThen(w.uninterruptibleMask(() => w.acquireUseRelease(Z(e, n), () => D.modifyEffect(M, (e) => w.gen(function* () {
625
+ if (s || W.stopped) return yield* w.fail(new l({
626
626
  operation: "subscribe",
627
627
  key: "",
628
628
  cause: "Pub/Sub consumer is closed"
629
629
  }));
630
- let r = t.get(a);
631
- if (r === void 0) return yield* T.fail(new e({
630
+ let n = e.get(i);
631
+ if (n === void 0) return yield* w.fail(new l({
632
632
  operation: "subscribe",
633
633
  key: "",
634
634
  cause: "Connection generation is unavailable"
635
635
  }));
636
- let o = {
637
- channel: n,
636
+ let a = {
637
+ channel: t,
638
638
  handler: (e) => {
639
- c || i(e);
639
+ s || r(e);
640
640
  },
641
641
  released: !1
642
- }, u = s.channels.get(n) ?? /* @__PURE__ */ new Set(), f = u.size === 0;
643
- u.add(o.handler), s.channels.set(n, u), r.binding = s, Pe(r);
644
- let p = r.subscriber !== void 0;
645
- return yield* T.gen(function* () {
646
- if (yield* Ne(r, s), p && f && (yield* T.tryPromise({
647
- try: () => r.subscriber.subscribe(n),
648
- catch: () => new e({
642
+ }, u = o.channels.get(t) ?? /* @__PURE__ */ new Set(), f = u.size === 0;
643
+ u.add(a.handler), o.channels.set(t, u), n.binding = o, Pe(n);
644
+ let p = n.subscriber !== void 0;
645
+ return yield* w.gen(function* () {
646
+ if (yield* Ne(n, o), p && f && (yield* w.tryPromise({
647
+ try: () => n.subscriber.subscribe(t),
648
+ catch: () => new l({
649
649
  operation: "subscribe",
650
650
  key: "",
651
651
  cause: "Redis subscription could not be registered"
652
652
  })
653
- })), c || W.stopped) return yield* T.fail(new e({
653
+ })), s || W.stopped) return yield* w.fail(new l({
654
654
  operation: "subscribe",
655
655
  key: "",
656
656
  cause: "Pub/Sub consumer is closed"
657
657
  }));
658
- }).pipe(T.onError(() => T.gen(function* () {
659
- if (J(r), u.delete(o.handler), u.size === 0) {
660
- s.channels.delete(n);
661
- let e = r.subscriber;
662
- e !== void 0 && !r.closed && (yield* T.promise(() => e.unsubscribe(n).catch(() => {
663
- J(r);
658
+ }).pipe(w.onError(() => w.gen(function* () {
659
+ if (J(n), u.delete(a.handler), u.size === 0) {
660
+ o.channels.delete(t);
661
+ let e = n.subscriber;
662
+ e !== void 0 && !n.closed && (yield* w.promise(() => e.unsubscribe(t).catch(() => {
663
+ J(n);
664
664
  })));
665
665
  }
666
- }))), l.add(o), [yield* T.cached(d(o)), t];
667
- })), q)).pipe(ke, T.mapError(() => new e({
666
+ }))), c.add(a), [yield* w.cached(d(a)), e];
667
+ })), q)).pipe(ke, w.mapError(() => new l({
668
668
  operation: "subscribe",
669
669
  key: "",
670
670
  cause: "Pub/Sub subscription could not be registered"
671
671
  }))))),
672
672
  onTransportEvent: (e) => {
673
- if (c || W.stopped) throw Error("Pub/Sub consumer is closed");
673
+ if (s || W.stopped) throw Error("Pub/Sub consumer is closed");
674
674
  let t = (t) => {
675
- c || e(t);
675
+ s || e(t);
676
676
  };
677
- return s.listeners.add(t), u.add(t), () => {
678
- s.listeners.delete(t), u.delete(t);
677
+ return o.listeners.add(t), u.add(t), () => {
678
+ o.listeners.delete(t), u.delete(t);
679
679
  };
680
680
  },
681
681
  close: f
682
682
  };
683
683
  }),
684
684
  probe: Re,
685
- reload: T.uninterruptibleMask((t) => T.gen(function* () {
686
- if (W.stopped) return yield* T.fail(new e({
685
+ reload: w.uninterruptibleMask((e) => w.gen(function* () {
686
+ if (W.stopped) return yield* w.fail(new l({
687
687
  operation: "reload",
688
688
  key: "",
689
689
  cause: "Connection registry is closed"
690
690
  }));
691
- let n = yield* x.currentTimeMillis, r = yield* x.currentTimeNanos, i = yield* t(O.updateEffect(N, (e) => T.uninterruptibleMask((t) => T.gen(function* () {
692
- let n = /* @__PURE__ */ new Map(), r = yield* t(T.forEach([...e], ([e, t]) => Ie(t.reference, t.context, (t) => {
691
+ let t = yield* b.currentTimeMillis, n = yield* b.currentTimeNanos, i = yield* e(D.updateEffect(M, (e) => w.uninterruptibleMask((t) => w.gen(function* () {
692
+ let n = /* @__PURE__ */ new Map(), r = yield* t(w.forEach([...e], ([e, t]) => Ie(t.reference, t.context, (t) => {
693
693
  n.set(e, t);
694
- }, t))).pipe(T.exit);
695
- if (r._tag === "Failure") return yield* T.forEach([...n.values()], G, { discard: !0 }), yield* T.failCause(r.cause);
694
+ }, t))).pipe(w.exit);
695
+ if (r._tag === "Failure") return yield* w.forEach([...n.values()], G, { discard: !0 }), yield* w.failCause(r.cause);
696
696
  for (let e of n.values()) Pe(e);
697
- return yield* T.forEach([...e.values()], Ae, { discard: !0 }), n;
698
- })))).pipe(T.exit), a = yield* x.currentTimeNanos, o = Object.freeze({
699
- sequence: ++ue,
700
- startedAt: n,
701
- durationMs: Number(a - r) / 1e6,
697
+ return yield* w.forEach([...e.values()], Ae, { discard: !0 }), n;
698
+ })))).pipe(w.exit), a = yield* b.currentTimeNanos, o = Object.freeze({
699
+ sequence: ++fe,
700
+ startedAt: t,
701
+ durationMs: Number(a - n) / 1e6,
702
702
  outcome: i._tag === "Success" ? "succeeded" : "failed"
703
703
  });
704
- if (yield* T.sync(() => {
705
- k.rotated(o.outcome, o.durationMs);
704
+ if (yield* w.sync(() => {
705
+ O.rotated(o.outcome, o.durationMs);
706
706
  try {
707
- v.onRotation?.(o);
707
+ r.onRotation?.(o);
708
708
  } catch {}
709
- }), i._tag === "Failure") return yield* T.failCause(i.cause);
709
+ }), i._tag === "Failure") return yield* w.failCause(i.cause);
710
710
  })),
711
- inspect: O.get(N).pipe(T.flatMap((e) => T.forEach([...e.values()], (e) => T.gen(function* () {
711
+ inspect: D.get(M).pipe(w.flatMap((e) => w.forEach([...e.values()], (e) => w.gen(function* () {
712
712
  let t = e.config;
713
713
  return {
714
714
  reference: e.reference,
@@ -720,7 +720,7 @@ var k = class extends w.Service()("@voltro/ConnectionRegistry") {}, A = (v = {})
720
720
  errors: e.errors,
721
721
  latencyMs: e.latencyMs,
722
722
  state: yield* e.breaker.state,
723
- source: t.source ?? (w.redis && Object.keys(w.redis).length > 0 ? "config" : "environment"),
723
+ source: t.source ?? (C.redis && Object.keys(C.redis).length > 0 ? "config" : "environment"),
724
724
  ...t.label === void 0 ? {} : { label: t.label },
725
725
  ...t.region === void 0 ? {} : { region: t.region },
726
726
  ..."persistence" in t && t.persistence !== void 0 ? { persistence: t.persistence } : {}
@@ -728,11 +728,11 @@ var k = class extends w.Service()("@voltro/ConnectionRegistry") {}, A = (v = {})
728
728
  })))),
729
729
  redis: {
730
730
  client: (e) => ze(e),
731
- config: (e) => U(e)
731
+ config: (e) => H(e)
732
732
  }
733
733
  };
734
- }), j = (e = {}) => E.effectContext(T.gen(function* () {
735
- let t = yield* C.ConfigProvider, n = v(yield* A(e), t);
736
- return w.make(k, n).pipe(w.add(ue, n.redis));
734
+ }), A = (e = {}) => T.effectContext(w.gen(function* () {
735
+ let t = yield* S.ConfigProvider, n = fe(yield* k(e), t);
736
+ return C.make(O, n).pipe(C.add(r, n.redis));
737
737
  }));
738
- export { k as ConnectionRegistry, j as layerConfiguredConnections, A as makeConnectionRegistry };
738
+ export { O as ConnectionRegistry, A as layerConfiguredConnections, k as makeConnectionRegistry };