@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.
@@ -266,7 +266,23 @@ export declare const byTenant: (target: ConnectionRef<"redis">) => ConnectionRou
266
266
 
267
267
  declare type ByteStream = Stream.Stream<Uint8Array, StorageError>;
268
268
 
269
- /** One cache program. Every accessed key is declared; memberships are versioned. */
269
+ /**
270
+ * The bounded unit of every multi-step maintenance command. Clear and tag
271
+ * invalidation take effect in one O(1) transition and reclaim storage in
272
+ * pages of at most this many entries, so no command declares a whole
273
+ * namespace or replies with a whole tag.
274
+ */
275
+ export declare const CACHE_ATOMIC_PAGE = 64;
276
+
277
+ /** The largest SCAN hint one maintenance page asks for. */
278
+ export declare const CACHE_ATOMIC_SCAN = 200;
279
+
280
+ /**
281
+ * One cache program. Every accessed key is declared; memberships are versioned.
282
+ * Entries carry the namespace generation they were written in (absent = 0); an
283
+ * entry of another generation, or one missing a live membership, is unreadable
284
+ * and reclaimable.
285
+ */
270
286
  export declare const CACHE_ATOMIC_SCRIPT: string;
271
287
 
272
288
  /**
@@ -280,8 +296,6 @@ export declare const CACHE_FENCE_RETENTION_MS = 900000;
280
296
  export declare const cacheAtomicArray: (input: unknown) => ReadonlyArray<unknown>;
281
297
 
282
298
  export declare type CacheAtomicCommand = {
283
- readonly op: 'revision';
284
- } | {
285
299
  readonly op: 'fence';
286
300
  } | {
287
301
  readonly op: 'inspect';
@@ -293,18 +307,15 @@ export declare type CacheAtomicCommand = {
293
307
  readonly op: 'read';
294
308
  readonly key: string;
295
309
  readonly snapshot: CacheAtomicSnapshot | null;
296
- } | {
297
- readonly op: 'tag';
298
- readonly tag: string;
299
310
  } | {
300
311
  readonly op: 'scan';
301
312
  readonly cursor: string;
313
+ readonly count: number;
302
314
  } | {
303
315
  readonly op: 'write';
304
316
  readonly key: string;
305
317
  readonly snapshot: CacheAtomicSnapshot | null;
306
318
  readonly version: string;
307
- readonly revision: string;
308
319
  readonly tags: ReadonlyArray<string>;
309
320
  readonly value: string;
310
321
  readonly ttlMs: number | null;
@@ -313,17 +324,38 @@ export declare type CacheAtomicCommand = {
313
324
  readonly op: 'remove';
314
325
  readonly key: string;
315
326
  readonly snapshot: CacheAtomicSnapshot | null;
316
- readonly revision: string;
317
- } | {
318
- readonly op: 'invalidate';
327
+ }
328
+ /** Moves the tag index aside under `retired` and advances the fence: every
329
+ * entry of the tag stops being readable in this one transition. */
330
+ | {
331
+ readonly op: 'retire';
332
+ readonly tag: string;
333
+ readonly retired: string;
334
+ }
335
+ /** The first `count` memberships of a retired tag index. */
336
+ | {
337
+ readonly op: 'retired';
338
+ readonly tag: string;
339
+ readonly retired: string;
340
+ readonly count: number;
341
+ }
342
+ /** Deletes the observed entries of a retired tag index and drops those memberships. */
343
+ | {
344
+ readonly op: 'purge';
319
345
  readonly tag: string;
346
+ readonly retired: string;
320
347
  readonly members: ReadonlyArray<string>;
321
348
  readonly snapshots: ReadonlyArray<CacheAtomicValueSnapshot>;
322
- readonly revision: string;
323
- } | {
349
+ }
350
+ /** Advances the namespace generation: every earlier entry stops being readable. */
351
+ | {
324
352
  readonly op: 'clear';
325
- readonly keys: ReadonlyArray<string>;
326
- readonly revision: string | null;
353
+ }
354
+ /** Deletes observed entries that can no longer be read and retired tag indexes. */
355
+ | {
356
+ readonly op: 'sweep';
357
+ readonly snapshots: ReadonlyArray<CacheAtomicValueSnapshot>;
358
+ readonly retired: ReadonlyArray<string>;
327
359
  };
328
360
 
329
361
  /** JSON before UTF-8 preserves distinct JS strings containing lone surrogates. */
@@ -355,12 +387,24 @@ export declare interface CacheAtomicReply {
355
387
  readonly value: unknown;
356
388
  }
357
389
 
390
+ /** A retired tag index reference: the retirement identity, then the tag. */
391
+ export declare const cacheAtomicRetired: (retirement: string, tag: string) => string;
392
+
358
393
  /** Every cache namespace owns one Redis Cluster hash slot. */
359
394
  export declare const cacheAtomicRoot: (prefix: string) => string;
360
395
 
396
+ /**
397
+ * One SCAN page, classified. Only entries (`:v:`) and retired tag indexes
398
+ * (`:d:`) are reclaimable. Live tag indexes shrink as their entries go; the
399
+ * fence (`:s`, `:e:`) and the generation (`:g`) outlive every clear on purpose:
400
+ * dropping the fence would let a compute that observed the sequence before an
401
+ * invalidation store after it, and dropping the generation would make every
402
+ * cleared entry readable again.
403
+ */
361
404
  export declare const cacheAtomicScanPage: (root: string, input: unknown) => {
362
405
  readonly cursor: string;
363
- readonly keys: ReadonlyArray<string>;
406
+ readonly values: ReadonlyArray<string>;
407
+ readonly retired: ReadonlyArray<string>;
364
408
  };
365
409
 
366
410
  export declare interface CacheAtomicSnapshot {
@@ -442,7 +486,7 @@ export declare interface ConnectionPoolSnapshot {
442
486
  readonly source: 'config' | 'environment' | 'override';
443
487
  readonly label?: string;
444
488
  readonly region?: string;
445
- readonly persistence?: RedisConnectionConfig['persistence'];
489
+ readonly persistence?: NonNullable<RedisConnectionConfig['persistence']>;
446
490
  }
447
491
 
448
492
  /** Borrowed Pub/Sub port. A consumer owns registrations, never broker sockets. */
@@ -1,22 +1,22 @@
1
1
  import { KvError as e } from "./errors.js";
2
2
  import { withRespKeyPrefix as t } from "./connectionPrefix.js";
3
- import { dynamicSql as n } from "./connectionSqlConfig.js";
4
- import { dynamicAnalytics as r } from "./connectionAnalyticsConfig.js";
5
- import { byTenant as i, connectionDefinitionsProblem as a, connectionMetadataProblem as o, declaredConnectionEnv as s, dynamic as c, dynamicNats as l, env as u, memory as d, redisConnectionName as f, redisTimeoutsProblem as p, roundRobin as m, shardBy as h } from "./connectionDefinitions.js";
6
- import { missingDriver as g } from "./driverModule.js";
7
- import { createNativeRedisConnection as _, disconnectNativeRedis as v, nativeRedisTopology as y, scanNativeRedis as b } from "./nativeRedisTopology.js";
8
- import { connectRedisSubscriber as x } from "./connectionSubscriber.js";
9
- import { dynamicStorage as S } from "./connectionStorageConfig.js";
10
- import { withConnectionRegistryConfigProvider as C } from "./connectionConfigProvider.js";
11
- import { ConnectionRegistry as ee, layerConfiguredConnections as w, makeConnectionRegistry as T } from "./connectionPool.js";
12
- import { httpRedisReaders as E } from "./redisReadPolicy.js";
13
- import { nativeRedisReadConfigs as D, openNativeRedisReaders as te } from "./nativeRedisReads.js";
14
- import { readRedisNodeDiagnostics as ne } from "./redisDiagnostics.js";
15
- import { CACHE_FENCE_RETENTION_MS as re, CacheAtomicProtocolError as ie, cacheAtomicArray as ae, cacheAtomicComponent as oe, cacheAtomicKeys as se, cacheAtomicMember as ce, cacheAtomicMembership as O, cacheAtomicRoot as k, cacheAtomicScanPage as A, cacheAtomicSnapshot as j, cacheAtomicTtl as M, cacheAtomicValueSnapshots as N, decodeCacheAtomicCommand as P, decodeCacheAtomicPolicy as F, decodeCacheAtomicReply as I, isCacheAtomicRead as L } from "./cacheAtomicProtocol.js";
16
- import { CACHE_ATOMIC_SCRIPT as R } from "./cacheAtomicScript.js";
17
- import { Config as z, ConfigProvider as B, Context as V, Effect as H, Layer as U, Option as W, Schedule as G } from "effect";
3
+ import { byTenant as n, connectionDefinitionsProblem as r, connectionMetadataProblem as i, declaredConnectionEnv as a, dynamic as o, dynamicNats as s, env as c, memory as l, redisConnectionName as ee, redisTimeoutsProblem as u, roundRobin as d, shardBy as f } from "./connectionDefinitions.js";
4
+ import { ConnectionRegistry as p, layerConfiguredConnections as m, makeConnectionRegistry as h } from "./connectionPool.js";
5
+ import { createNativeRedisConnection as g, disconnectNativeRedis as _, nativeRedisTopology as v, scanNativeRedis as y } from "./nativeRedisTopology.js";
6
+ import { nativeRedisReadConfigs as b, openNativeRedisReaders as x } from "./nativeRedisReads.js";
7
+ import { httpRedisReaders as S } from "./redisReadPolicy.js";
8
+ import { readRedisNodeDiagnostics as C } from "./redisDiagnostics.js";
9
+ import { missingDriver as w } from "./driverModule.js";
10
+ import { connectRedisSubscriber as T } from "./connectionSubscriber.js";
11
+ import { withConnectionRegistryConfigProvider as te } from "./connectionConfigProvider.js";
12
+ import { dynamicStorage as ne } from "./connectionStorageConfig.js";
13
+ import { dynamicAnalytics as re } from "./connectionAnalyticsConfig.js";
14
+ import { dynamicSql as ie } from "./connectionSqlConfig.js";
15
+ import { CACHE_ATOMIC_SCRIPT as ae } from "./cacheAtomicScript.js";
16
+ import { CACHE_ATOMIC_PAGE as oe, CACHE_ATOMIC_SCAN as se, CACHE_FENCE_RETENTION_MS as ce, CacheAtomicProtocolError as le, cacheAtomicArray as E, cacheAtomicComponent as D, cacheAtomicKeys as O, cacheAtomicMember as k, cacheAtomicMembership as A, cacheAtomicRetired as j, cacheAtomicRoot as M, cacheAtomicScanPage as N, cacheAtomicSnapshot as P, cacheAtomicTtl as F, cacheAtomicValueSnapshots as I, decodeCacheAtomicCommand as L, decodeCacheAtomicPolicy as R, decodeCacheAtomicReply as z, isCacheAtomicRead as B } from "./cacheAtomicProtocol.js";
17
+ import { Config as V, ConfigProvider as H, Context as U, Effect as W, Layer as ue, Option as G, Schedule as K } from "effect";
18
18
  // src/connection.ts
19
- var K = (e) => new z.ConfigError(new B.SourceError({ message: e })), le = (e, t) => {
19
+ var q = (e) => new V.ConfigError(new H.SourceError({ message: e })), de = (e, t) => {
20
20
  let n = e.client;
21
21
  return {
22
22
  readOnly: {
@@ -45,7 +45,7 @@ var K = (e) => new z.ConfigError(new B.SourceError({ message: e })), le = (e, t)
45
45
  diagnostics: async () => {
46
46
  await e.ready();
47
47
  let t = e.kind === "cluster" ? n.nodes("master") : [n];
48
- return { nodes: await Promise.all(t.map((e) => ne({
48
+ return { nodes: await Promise.all(t.map((e) => C({
49
49
  info: (t) => e.info(t),
50
50
  config: (t, n) => e.config(t, n)
51
51
  }))) };
@@ -71,7 +71,7 @@ var K = (e) => new z.ConfigError(new B.SourceError({ message: e })), le = (e, t)
71
71
  exists: async (t) => (await e.ready(), n.exists(t)),
72
72
  eval: async (t, r, ...i) => (await e.ready(), n.eval(t, r, ...i)),
73
73
  zrange: async (t) => (await e.ready(), n.zrange(t, 0, "-1")),
74
- scan: async (t, n, r) => (await e.ready(), b(e, t, n, r)),
74
+ scan: async (t, n, r) => (await e.ready(), y(e, t, n, r)),
75
75
  close: async () => {
76
76
  let r, i = () => {
77
77
  try {
@@ -85,11 +85,11 @@ var K = (e) => new z.ConfigError(new B.SourceError({ message: e })), le = (e, t)
85
85
  }, 1e3);
86
86
  })]);
87
87
  } finally {
88
- r !== void 0 && clearTimeout(r), await Promise.all([t.close(), v(e)]).then(() => void 0);
88
+ r !== void 0 && clearTimeout(r), await Promise.all([t.close(), _(e)]).then(() => void 0);
89
89
  }
90
90
  }
91
91
  };
92
- }, q = (e) => ({
92
+ }, J = (e) => ({
93
93
  readOnly: {
94
94
  get: (t) => e.get(t),
95
95
  exists: (t) => e.exists(t),
@@ -115,16 +115,16 @@ var K = (e) => new z.ConfigError(new B.SourceError({ message: e })), le = (e, t)
115
115
  };
116
116
  },
117
117
  close: () => Promise.resolve()
118
- }), J = (e) => e.toUpperCase().replace(/[^A-Z0-9]+/g, "_"), Y = (e) => {
118
+ }), Y = (e) => e.toUpperCase().replace(/[^A-Z0-9]+/g, "_"), X = (e) => {
119
119
  if (![
120
120
  "resp",
121
121
  "http",
122
122
  "memory"
123
123
  ].includes(e.driver)) return "Redis driver must be resp, http or memory";
124
124
  if (typeof e.url != "string" || !e.url.trim()) return "Redis URL must be a nonempty string";
125
- let t = o(e);
125
+ let t = i(e);
126
126
  if (t) return t;
127
- let n = p(e, e.driver);
127
+ let n = u(e, e.driver);
128
128
  if (n) return n;
129
129
  if (e.token !== void 0 && (typeof e.token != "string" || !e.token)) return "Redis token must be a nonempty string";
130
130
  if (e.cluster !== void 0 && typeof e.cluster != "boolean") return "Redis cluster must be a boolean";
@@ -153,90 +153,90 @@ var K = (e) => new z.ConfigError(new B.SourceError({ message: e })), le = (e, t)
153
153
  "none"
154
154
  ].includes(e.persistence)) return "Connection persistence must be required, optional or none";
155
155
  if (e.maxmemoryPolicyHint !== void 0 && typeof e.maxmemoryPolicyHint != "string") return "Redis maxmemoryPolicyHint must be a string";
156
- }, X = (e) => {
157
- let t = Y(e);
158
- return t ? H.fail(K(t)) : e.driver === "resp" ? H.try({
156
+ }, Z = (e) => {
157
+ let t = X(e);
158
+ return t ? W.fail(q(t)) : e.driver === "resp" ? W.try({
159
159
  try: () => {
160
- let t = y(e);
161
- if (D(e), e.readFrom === "replica" && t.kind === "standalone" && !e.replicas?.length) throw Error("Standalone replica reads require replica endpoints");
160
+ let t = v(e);
161
+ if (b(e), e.readFrom === "replica" && t.kind === "standalone" && !e.replicas?.length) throw Error("Standalone replica reads require replica endpoints");
162
162
  return t.kind === "cluster" && e.cluster === void 0 ? {
163
163
  ...e,
164
164
  cluster: !0
165
165
  } : e;
166
166
  },
167
- catch: () => K("Invalid native Redis topology declaration")
168
- }) : H.succeed(e);
169
- }, Z = ["resp", "http"], ue = (e, t = {}) => H.gen(function* () {
170
- let n = J(e), r = t.url ?? (yield* z.String(`${n}_REDIS_URL`).pipe(z.orElse(() => z.String("REDIS_URL")))), i = t.driver === void 0 ? yield* z.Literals(Z, `${n}_REDIS_DRIVER`).pipe(z.option) : W.none(), a = t.driver ?? (W.isSome(i) ? i.value : yield* z.Literals(Z, "REDIS_DRIVER").pipe(z.withDefault("resp"))), o = t.token === void 0 ? yield* z.String(`${n}_REDIS_TOKEN`).pipe(z.orElse(() => z.String("REDIS_TOKEN")), z.orElse(() => z.String("UPSTASH_REDIS_REST_TOKEN")), z.option) : W.some(t.token), s = t.keyPrefix === void 0 ? yield* z.String(`${n}_REDIS_KEY_PREFIX`).pipe(z.option) : W.some(t.keyPrefix);
167
+ catch: () => q("Invalid native Redis topology declaration")
168
+ }) : W.succeed(e);
169
+ }, Q = ["resp", "http"], fe = (e, t = {}) => W.gen(function* () {
170
+ let n = Y(e), r = t.url ?? (yield* V.String(`${n}_REDIS_URL`).pipe(V.orElse(() => V.String("REDIS_URL")))), i = t.driver === void 0 ? yield* V.Literals(Q, `${n}_REDIS_DRIVER`).pipe(V.option) : G.none(), a = t.driver ?? (G.isSome(i) ? i.value : yield* V.Literals(Q, "REDIS_DRIVER").pipe(V.withDefault("resp"))), o = t.token === void 0 ? yield* V.String(`${n}_REDIS_TOKEN`).pipe(V.orElse(() => V.String("REDIS_TOKEN")), V.orElse(() => V.String("UPSTASH_REDIS_REST_TOKEN")), V.option) : G.some(t.token), s = t.keyPrefix === void 0 ? yield* V.String(`${n}_REDIS_KEY_PREFIX`).pipe(V.option) : G.some(t.keyPrefix);
171
171
  return {
172
172
  url: r,
173
173
  driver: a,
174
- ...W.isSome(o) ? { token: o.value } : {},
175
- ...W.isSome(s) ? { keyPrefix: s.value } : {},
174
+ ...G.isSome(o) ? { token: o.value } : {},
175
+ ...G.isSome(s) ? { keyPrefix: s.value } : {},
176
176
  ...t.source === void 0 ? {} : { source: t.source },
177
177
  ...t.connectTimeoutMs === void 0 ? {} : { connectTimeoutMs: t.connectTimeoutMs },
178
178
  ...t.commandTimeoutMs === void 0 ? {} : { commandTimeoutMs: t.commandTimeoutMs }
179
179
  };
180
- }).pipe(H.flatMap(X));
181
- function Q(e, t, n) {
182
- let r = n === void 0 ? void 0 : Object.freeze({ tenantId: n.tenantId });
183
- return H.gen(function* () {
184
- let n = a(t ?? {});
185
- if (n) return yield* H.fail(K(n));
186
- let i = e.includes(":"), o = i ? e.slice(e.indexOf(":") + 1) : e;
187
- if (i && !e.startsWith("redis:")) return yield* H.fail(K("A Redis consumer requires a redis:name connection reference"));
188
- if (i && o && !/^[A-Za-z][A-Za-z0-9_-]*$/.test(o)) return yield* H.fail(K("Malformed Redis connection reference"));
189
- let s = t?.redis ?? {}, c = Object.keys(s), l = f(o, t ?? {}), u = Object.hasOwn(s, l) ? s[l] : void 0;
190
- if (!u && c.length > 0) return yield* H.fail(K(`Unknown Redis connection ${l || "(default)"}. Known names: ${c.sort().join(", ") || "(none)"}`));
191
- let d = `CONNECTIONS_REDIS_${J(l)}`, p = yield* z.String(`${d}_URL`).pipe(z.option), m = yield* z.Literals(["resp", "http"], `${d}_DRIVER`).pipe(z.option), h = yield* z.String(`${d}_TOKEN`).pipe(z.option), g = yield* z.String(`${d}_KEY_PREFIX`).pipe(z.option), _ = {
192
- ...W.isSome(p) ? { url: p.value } : {},
193
- ...W.isSome(m) ? { driver: m.value } : {},
194
- ...W.isSome(h) ? { token: h.value } : {},
195
- ...W.isSome(g) ? { keyPrefix: g.value } : {},
180
+ }).pipe(W.flatMap(Z));
181
+ function pe(e, t, n) {
182
+ let i = n === void 0 ? void 0 : Object.freeze({ tenantId: n.tenantId });
183
+ return W.gen(function* () {
184
+ let n = r(t ?? {});
185
+ if (n) return yield* W.fail(q(n));
186
+ let a = e.includes(":"), o = a ? e.slice(e.indexOf(":") + 1) : e;
187
+ if (a && !e.startsWith("redis:")) return yield* W.fail(q("A Redis consumer requires a redis:name connection reference"));
188
+ if (a && o && !/^[A-Za-z][A-Za-z0-9_-]*$/.test(o)) return yield* W.fail(q("Malformed Redis connection reference"));
189
+ let s = t?.redis ?? {}, c = Object.keys(s), l = ee(o, t ?? {}), u = Object.hasOwn(s, l) ? s[l] : void 0;
190
+ if (!u && c.length > 0) return yield* W.fail(q(`Unknown Redis connection ${l || "(default)"}. Known names: ${c.sort().join(", ") || "(none)"}`));
191
+ let d = `CONNECTIONS_REDIS_${Y(l)}`, f = yield* V.String(`${d}_URL`).pipe(V.option), p = yield* V.Literals(["resp", "http"], `${d}_DRIVER`).pipe(V.option), m = yield* V.String(`${d}_TOKEN`).pipe(V.option), h = yield* V.String(`${d}_KEY_PREFIX`).pipe(V.option), g = {
192
+ ...G.isSome(f) ? { url: f.value } : {},
193
+ ...G.isSome(p) ? { driver: p.value } : {},
194
+ ...G.isSome(m) ? { token: m.value } : {},
195
+ ...G.isSome(h) ? { keyPrefix: h.value } : {},
196
196
  ...[
197
+ f,
197
198
  p,
198
199
  m,
199
- h,
200
- g
201
- ].some(W.isSome) ? { source: "override" } : {}
200
+ h
201
+ ].some(G.isSome) ? { source: "override" } : {}
202
202
  };
203
203
  if (u && "_tag" in u && u._tag === "MemoryRedisConnection") return [
204
+ f,
204
205
  p,
205
206
  m,
206
- h,
207
- g
208
- ].some(W.isSome) ? yield* H.fail(K("A local memory connection cannot be redirected by transport environment overrides")) : {
207
+ h
208
+ ].some(G.isSome) ? yield* W.fail(q("A local memory connection cannot be redirected by transport environment overrides")) : {
209
209
  url: `memory:${l}`,
210
210
  driver: "memory",
211
211
  source: "config",
212
212
  ...u.now === void 0 ? {} : { memoryClock: u.now }
213
213
  };
214
214
  if (u && "_tag" in u) {
215
- if (!r?.tenantId) return yield* H.fail(K("A dynamic Redis connection requires tenantId"));
215
+ if (!i?.tenantId) return yield* W.fail(q("A dynamic Redis connection requires tenantId"));
216
216
  let e = {
217
- ...yield* u.resolve(r),
218
- ..._
219
- }, t = Y(e);
220
- return t ? yield* H.fail(K(t)) : e.driver === "memory" ? yield* H.fail(K("Local memory connections require a memory() declaration, not a tenant credential resolver")) : e.keyPrefix !== void 0 && typeof e.keyPrefix != "string" ? yield* H.fail(K("Connection keyPrefix must be a string")) : e.allowSharedNamespace !== void 0 && typeof e.allowSharedNamespace != "boolean" ? yield* H.fail(K("Connection allowSharedNamespace must be a boolean")) : e.driver === "http" && !e.token ? yield* H.fail(K("An HTTP Redis connection requires a declared token")) : e.tls === "required" && !/^rediss(?:\+cluster|\+sentinel)?:\/\//i.test(e.url) && !(e.driver === "http" && /^https:\/\//i.test(e.url)) ? yield* H.fail(K("A Redis connection with tls: required needs a secure Redis scheme or HTTPS")) : yield* X(e);
217
+ ...yield* u.resolve(i),
218
+ ...g
219
+ }, t = X(e);
220
+ return t ? yield* W.fail(q(t)) : e.driver === "memory" ? yield* W.fail(q("Local memory connections require a memory() declaration, not a tenant credential resolver")) : e.keyPrefix !== void 0 && typeof e.keyPrefix != "string" ? yield* W.fail(q("Connection keyPrefix must be a string")) : e.allowSharedNamespace !== void 0 && typeof e.allowSharedNamespace != "boolean" ? yield* W.fail(q("Connection allowSharedNamespace must be a boolean")) : e.driver === "http" && !e.token ? yield* W.fail(q("An HTTP Redis connection requires a declared token")) : e.tls === "required" && !/^rediss(?:\+cluster|\+sentinel)?:\/\//i.test(e.url) && !(e.driver === "http" && /^https:\/\//i.test(e.url)) ? yield* W.fail(q("A Redis connection with tls: required needs a secure Redis scheme or HTTPS")) : yield* Z(e);
221
221
  }
222
- if (!u) return yield* ue(l || e, _);
223
- let v = W.isSome(p) ? p.value : yield* z.String(u.url.name), y = W.isSome(m) ? m.value : u.driver ?? "resp", b = W.isSome(h) ? W.some(h.value) : u.token ? W.some(yield* z.String(u.token.name)) : W.none();
224
- if (y === "http" && W.isNone(b)) return yield* H.fail(K("An HTTP Redis connection requires a declared token"));
225
- let x = W.isSome(g) ? g.value : u.keyPrefix, S = u.cluster ?? /^rediss?\+cluster:\/\//i.test(v);
226
- if (u.tls === "required" && !/^rediss(?:\+cluster|\+sentinel)?:\/\//i.test(v) && !(y === "http" && /^https:\/\//i.test(v))) return yield* H.fail(K("A Redis connection with tls: required needs a secure Redis scheme or HTTPS"));
227
- let C = yield* H.forEach(u.replicas ?? [], (e) => z.String(e.name));
228
- return yield* X({
229
- url: v,
230
- driver: y,
231
- cluster: S,
222
+ if (!u) return yield* fe(l || e, g);
223
+ let _ = G.isSome(f) ? f.value : yield* V.String(u.url.name), v = G.isSome(p) ? p.value : u.driver ?? "resp", y = G.isSome(m) ? G.some(m.value) : u.token ? G.some(yield* V.String(u.token.name)) : G.none();
224
+ if (v === "http" && G.isNone(y)) return yield* W.fail(q("An HTTP Redis connection requires a declared token"));
225
+ let b = G.isSome(h) ? h.value : u.keyPrefix, x = u.cluster ?? /^rediss?\+cluster:\/\//i.test(_);
226
+ if (u.tls === "required" && !/^rediss(?:\+cluster|\+sentinel)?:\/\//i.test(_) && !(v === "http" && /^https:\/\//i.test(_))) return yield* W.fail(q("A Redis connection with tls: required needs a secure Redis scheme or HTTPS"));
227
+ let S = yield* W.forEach(u.replicas ?? [], (e) => V.String(e.name));
228
+ return yield* Z({
229
+ url: _,
230
+ driver: v,
231
+ cluster: x,
232
232
  source: [
233
+ f,
233
234
  p,
234
235
  m,
235
- h,
236
- g
237
- ].some(W.isSome) ? "override" : "config",
238
- ...W.isSome(b) ? { token: b.value } : {},
239
- ...x === void 0 ? {} : { keyPrefix: x },
236
+ h
237
+ ].some(G.isSome) ? "override" : "config",
238
+ ...G.isSome(y) ? { token: y.value } : {},
239
+ ...b === void 0 ? {} : { keyPrefix: b },
240
240
  ...u.allowSharedNamespace === void 0 ? {} : { allowSharedNamespace: u.allowSharedNamespace },
241
241
  ...u.tls === void 0 ? {} : { tls: u.tls },
242
242
  ...u.persistence === void 0 ? {} : { persistence: u.persistence },
@@ -246,17 +246,17 @@ function Q(e, t, n) {
246
246
  ...u.readFrom === void 0 ? {} : { readFrom: u.readFrom },
247
247
  ...u.connectTimeoutMs === void 0 ? {} : { connectTimeoutMs: u.connectTimeoutMs },
248
248
  ...u.commandTimeoutMs === void 0 ? {} : { commandTimeoutMs: u.commandTimeoutMs },
249
- ...C.length > 0 ? { replicas: C } : {},
249
+ ...S.length > 0 ? { replicas: S } : {},
250
250
  ...u.maxmemoryPolicyHint === void 0 ? {} : { maxmemoryPolicyHint: u.maxmemoryPolicyHint }
251
251
  });
252
252
  });
253
253
  }
254
- var de = (n) => H.tryPromise({
254
+ var me = (n) => W.tryPromise({
255
255
  try: async (e) => {
256
256
  e.throwIfAborted();
257
- let t = Y(n);
257
+ let t = X(n);
258
258
  if (t) throw Error(t);
259
- if (n.driver === "resp" && D(n), n.driver === "memory") {
259
+ if (n.driver === "resp" && b(n), n.driver === "memory") {
260
260
  let { makeMemoryConnectionState: e } = await import("./connectionMemory.js"), t = e(n.memoryClock), r = t.command();
261
261
  return {
262
262
  ...r,
@@ -266,7 +266,7 @@ var de = (n) => H.tryPromise({
266
266
  };
267
267
  }
268
268
  if (n.driver === "http") {
269
- let t = await import("@upstash/redis").catch(g("@upstash/redis", "An Upstash HTTP connection"));
269
+ let t = await import("@upstash/redis").catch(w("@upstash/redis", "An Upstash HTTP connection"));
270
270
  e.throwIfAborted();
271
271
  let r = typeof t.default == "function" ? t.default : t.default?.Redis, i = t.Redis ?? r;
272
272
  if (!i) throw Error("@upstash/redis: Redis constructor not found in module");
@@ -285,7 +285,7 @@ var de = (n) => H.tryPromise({
285
285
  signal: r.signal
286
286
  });
287
287
  if (await a.ping() !== "PONG") throw Error("HTTP reader readiness failed");
288
- let o = q(a);
288
+ let o = J(a);
289
289
  if (Number(await o.readOnly.eval("return 1", 0)) !== 1) throw Error("HTTP read-only Lua readiness failed");
290
290
  return e.throwIfAborted(), {
291
291
  ...o,
@@ -314,14 +314,14 @@ var de = (n) => H.tryPromise({
314
314
  if (await t.ping() !== "PONG") throw Error("HTTP primary readiness failed");
315
315
  e.throwIfAborted();
316
316
  let r = {
317
- ...q(t),
317
+ ...J(t),
318
318
  close: async () => {
319
319
  o.abort();
320
320
  }
321
321
  }, s = [];
322
322
  try {
323
323
  if (n.readFrom !== void 0 && n.readFrom !== "primary") for (let e of n.replicas ?? []) s.push(await a(e));
324
- let t = E(r, s, n.readFrom);
324
+ let t = S(r, s, n.readFrom);
325
325
  return (n.readFrom === "replica" || n.readFrom === "nearest") && await t.readOnly.eval("return 1", 0), e.throwIfAborted(), t;
326
326
  } catch (e) {
327
327
  throw await Promise.all([r, ...s].map((e) => e.close())), e;
@@ -332,7 +332,7 @@ var de = (n) => H.tryPromise({
332
332
  e.removeEventListener("abort", s);
333
333
  }
334
334
  }
335
- let r = await _(n), i = r.client;
335
+ let r = await g(n), i = r.client;
336
336
  i.on("error", () => {});
337
337
  let a = () => {
338
338
  i.disconnect();
@@ -341,19 +341,19 @@ var de = (n) => H.tryPromise({
341
341
  try {
342
342
  e.throwIfAborted(), await i.connect(), await r.ready(), e.throwIfAborted();
343
343
  } catch (e) {
344
- throw await v(r), e;
344
+ throw await _(r), e;
345
345
  } finally {
346
346
  e.removeEventListener("abort", a);
347
347
  }
348
348
  try {
349
- let t = await te(n, r, e);
349
+ let t = await x(n, r, e);
350
350
  try {
351
- return e.throwIfAborted(), le(r, t);
351
+ return e.throwIfAborted(), de(r, t);
352
352
  } catch (e) {
353
353
  throw await t.close(), e;
354
354
  }
355
355
  } catch (e) {
356
- throw await v(r), e;
356
+ throw await _(r), e;
357
357
  }
358
358
  },
359
359
  catch: () => new e({
@@ -361,5 +361,5 @@ var de = (n) => H.tryPromise({
361
361
  key: "",
362
362
  cause: n.keyPrefix !== void 0 && typeof n.keyPrefix != "string" ? "Connection keyPrefix must be a string" : "Redis connection could not be opened"
363
363
  })
364
- }).pipe(H.map((e) => t(e, n.keyPrefix))), fe = G.max([G.exponential("10 millis"), G.recurs(2)]), $ = class extends V.Service()("@voltro/RedisConnections") {}, pe = U.effect($, H.suspend(() => T()).pipe(H.orDie, H.map((e) => e.redis)));
365
- export { R as CACHE_ATOMIC_SCRIPT, re as CACHE_FENCE_RETENTION_MS, ie as CacheAtomicProtocolError, ee as ConnectionRegistry, $ as RedisConnections, i as byTenant, ae as cacheAtomicArray, oe as cacheAtomicComponent, se as cacheAtomicKeys, ce as cacheAtomicMember, O as cacheAtomicMembership, k as cacheAtomicRoot, A as cacheAtomicScanPage, j as cacheAtomicSnapshot, M as cacheAtomicTtl, N as cacheAtomicValueSnapshots, fe as commandRetry, de as connect, x as connectRedisSubscriber, Q as connectionConfig, a as connectionDefinitionsProblem, s as declaredConnectionEnv, P as decodeCacheAtomicCommand, F as decodeCacheAtomicPolicy, I as decodeCacheAtomicReply, c as dynamic, r as dynamicAnalytics, l as dynamicNats, n as dynamicSql, S as dynamicStorage, u as env, L as isCacheAtomicRead, w as layerConfiguredConnections, pe as layerConnections, T as makeConnectionRegistry, d as memory, m as roundRobin, h as shardBy, C as withConnectionRegistryConfigProvider };
364
+ }).pipe(W.map((e) => t(e, n.keyPrefix))), he = K.max([K.exponential("10 millis"), K.recurs(2)]), $ = class extends U.Service()("@voltro/RedisConnections") {}, ge = ue.effect($, W.suspend(() => h()).pipe(W.orDie, W.map((e) => e.redis)));
365
+ export { oe as CACHE_ATOMIC_PAGE, se as CACHE_ATOMIC_SCAN, ae as CACHE_ATOMIC_SCRIPT, ce as CACHE_FENCE_RETENTION_MS, le as CacheAtomicProtocolError, p as ConnectionRegistry, $ as RedisConnections, n as byTenant, E as cacheAtomicArray, D as cacheAtomicComponent, O as cacheAtomicKeys, k as cacheAtomicMember, A as cacheAtomicMembership, j as cacheAtomicRetired, M as cacheAtomicRoot, N as cacheAtomicScanPage, P as cacheAtomicSnapshot, F as cacheAtomicTtl, I as cacheAtomicValueSnapshots, he as commandRetry, me as connect, T as connectRedisSubscriber, pe as connectionConfig, r as connectionDefinitionsProblem, a as declaredConnectionEnv, L as decodeCacheAtomicCommand, R as decodeCacheAtomicPolicy, z as decodeCacheAtomicReply, o as dynamic, re as dynamicAnalytics, s as dynamicNats, ie as dynamicSql, ne as dynamicStorage, c as env, B as isCacheAtomicRead, m as layerConfiguredConnections, ge as layerConnections, h as makeConnectionRegistry, l as memory, d as roundRobin, f as shardBy, te as withConnectionRegistryConfigProvider };