@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.
- package/CHANGELOG.md +1943 -0
- package/README.md +0 -110
- package/dist/backendRedis.js +21 -21
- package/dist/cacheAtomicProtocol.js +185 -161
- package/dist/cacheAtomicScript.js +140 -95
- package/dist/cacheAtomicState.js +112 -96
- package/dist/connection.d.ts +60 -16
- package/dist/connection.js +91 -91
- package/dist/connectionMemory.js +54 -54
- package/dist/connectionNats.js +32 -32
- package/dist/connectionPool.js +364 -364
- package/dist/connectionSubscriber.js +10 -10
- package/dist/hot-contract.js +3 -3
- package/dist/hot-testing.d.ts +20 -0
- package/dist/hot-testing.js +3 -1
- package/dist/hot.d.ts +17 -1
- package/dist/hot.js +8 -7
- package/dist/hotMemory.js +14 -14
- package/dist/hotRedis.js +48 -48
- package/dist/hotRouting.js +27 -27
- package/dist/hotState.js +6 -6
- package/dist/hotStoreFixtures.js +23 -0
- package/dist/hotSystemManifest.js +11 -0
- package/dist/index.js +5 -5
- package/package.json +4 -4
package/dist/connection.d.ts
CHANGED
|
@@ -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
|
-
/**
|
|
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
|
-
|
|
317
|
-
|
|
318
|
-
|
|
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
|
-
|
|
323
|
-
|
|
349
|
+
}
|
|
350
|
+
/** Advances the namespace generation: every earlier entry stops being readable. */
|
|
351
|
+
| {
|
|
324
352
|
readonly op: 'clear';
|
|
325
|
-
|
|
326
|
-
|
|
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
|
|
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. */
|
package/dist/connection.js
CHANGED
|
@@ -1,22 +1,22 @@
|
|
|
1
1
|
import { KvError as e } from "./errors.js";
|
|
2
2
|
import { withRespKeyPrefix as t } from "./connectionPrefix.js";
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
15
|
-
import {
|
|
16
|
-
import {
|
|
17
|
-
import { Config as
|
|
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
|
|
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) =>
|
|
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(),
|
|
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(),
|
|
88
|
+
r !== void 0 && clearTimeout(r), await Promise.all([t.close(), _(e)]).then(() => void 0);
|
|
89
89
|
}
|
|
90
90
|
}
|
|
91
91
|
};
|
|
92
|
-
},
|
|
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
|
-
}),
|
|
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 =
|
|
125
|
+
let t = i(e);
|
|
126
126
|
if (t) return t;
|
|
127
|
-
let n =
|
|
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
|
-
},
|
|
157
|
-
let t =
|
|
158
|
-
return t ?
|
|
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 =
|
|
161
|
-
if (
|
|
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: () =>
|
|
168
|
-
}) :
|
|
169
|
-
},
|
|
170
|
-
let n =
|
|
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
|
-
...
|
|
175
|
-
...
|
|
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(
|
|
181
|
-
function
|
|
182
|
-
let
|
|
183
|
-
return
|
|
184
|
-
let n =
|
|
185
|
-
if (n) return yield*
|
|
186
|
-
let
|
|
187
|
-
if (
|
|
188
|
-
if (
|
|
189
|
-
let s = t?.redis ?? {}, c = Object.keys(s), l =
|
|
190
|
-
if (!u && c.length > 0) return yield*
|
|
191
|
-
let d = `CONNECTIONS_REDIS_${
|
|
192
|
-
...
|
|
193
|
-
...
|
|
194
|
-
...
|
|
195
|
-
...
|
|
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
|
-
|
|
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
|
-
|
|
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 (!
|
|
215
|
+
if (!i?.tenantId) return yield* W.fail(q("A dynamic Redis connection requires tenantId"));
|
|
216
216
|
let e = {
|
|
217
|
-
...yield* u.resolve(
|
|
218
|
-
...
|
|
219
|
-
}, t =
|
|
220
|
-
return t ? yield*
|
|
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*
|
|
223
|
-
let
|
|
224
|
-
if (
|
|
225
|
-
let
|
|
226
|
-
if (u.tls === "required" && !/^rediss(?:\+cluster|\+sentinel)?:\/\//i.test(
|
|
227
|
-
let
|
|
228
|
-
return yield*
|
|
229
|
-
url:
|
|
230
|
-
driver:
|
|
231
|
-
cluster:
|
|
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
|
-
|
|
237
|
-
|
|
238
|
-
...
|
|
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
|
-
...
|
|
249
|
+
...S.length > 0 ? { replicas: S } : {},
|
|
250
250
|
...u.maxmemoryPolicyHint === void 0 ? {} : { maxmemoryPolicyHint: u.maxmemoryPolicyHint }
|
|
251
251
|
});
|
|
252
252
|
});
|
|
253
253
|
}
|
|
254
|
-
var
|
|
254
|
+
var me = (n) => W.tryPromise({
|
|
255
255
|
try: async (e) => {
|
|
256
256
|
e.throwIfAborted();
|
|
257
|
-
let t =
|
|
257
|
+
let t = X(n);
|
|
258
258
|
if (t) throw Error(t);
|
|
259
|
-
if (n.driver === "resp" &&
|
|
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(
|
|
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 =
|
|
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
|
-
...
|
|
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 =
|
|
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
|
|
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
|
|
344
|
+
throw await _(r), e;
|
|
345
345
|
} finally {
|
|
346
346
|
e.removeEventListener("abort", a);
|
|
347
347
|
}
|
|
348
348
|
try {
|
|
349
|
-
let t = await
|
|
349
|
+
let t = await x(n, r, e);
|
|
350
350
|
try {
|
|
351
|
-
return e.throwIfAborted(),
|
|
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
|
|
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(
|
|
365
|
-
export {
|
|
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 };
|