@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
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { KvError as e } from "./errors.js";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import { createNativeRedisConnection as t, disconnectNativeRedis as n, nativeRedisOptions as r, nativeRedisTopology as i } from "./nativeRedisTopology.js";
|
|
3
|
+
import { missingDriver as a } from "./driverModule.js";
|
|
4
4
|
import { Effect as o } from "effect";
|
|
5
5
|
// src/connectionSubscriber.ts
|
|
6
6
|
var s = async (e, o) => {
|
|
7
7
|
o.throwIfAborted();
|
|
8
|
-
let s = await
|
|
8
|
+
let s = await t(e, "subscriber"), c, l = () => Promise.all([n(s), c === void 0 ? Promise.resolve() : n({
|
|
9
9
|
kind: "standalone",
|
|
10
10
|
client: c
|
|
11
11
|
})]).then(() => void 0), u = () => {
|
|
@@ -17,19 +17,19 @@ var s = async (e, o) => {
|
|
|
17
17
|
client: s.client,
|
|
18
18
|
dispose: l
|
|
19
19
|
};
|
|
20
|
-
let
|
|
21
|
-
if (
|
|
22
|
-
let u =
|
|
20
|
+
let t = s.client.nodes("master").find((e) => e.status === "ready");
|
|
21
|
+
if (t === void 0) throw Error("No ready Cluster primary");
|
|
22
|
+
let u = t.options.host, d = t.options.port;
|
|
23
23
|
if (u === void 0 || d === void 0) throw Error("Cluster primary endpoint missing");
|
|
24
|
-
let f =
|
|
24
|
+
let f = i(e);
|
|
25
25
|
if (f.kind !== "cluster") throw Error("Expected Cluster topology");
|
|
26
|
-
let { default: p } = await import("ioredis").catch(
|
|
26
|
+
let { default: p } = await import("ioredis").catch(a("ioredis", "A Redis subscriber connection"));
|
|
27
27
|
return o.throwIfAborted(), c = new p({
|
|
28
28
|
...f.options,
|
|
29
|
-
...
|
|
29
|
+
...r("subscriber"),
|
|
30
30
|
host: u,
|
|
31
31
|
port: d
|
|
32
|
-
}), c.on("error", () => {}), await c.connect(), o.throwIfAborted(), await
|
|
32
|
+
}), c.on("error", () => {}), await c.connect(), o.throwIfAborted(), await n(s), o.throwIfAborted(), {
|
|
33
33
|
client: c,
|
|
34
34
|
dispose: l
|
|
35
35
|
};
|
package/dist/hot-contract.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { consumeHotRateLimit as e } from "./hotRateLimit.js";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import { applyHotOperations as t, compareHotMembers as n } from "./hotState.js";
|
|
3
|
+
import { hotStoreFromRunner as r, validateHotOp as i } from "./hotOperations.js";
|
|
4
4
|
import { readHotStoreWithFallback as a } from "./hotReadAvailability.js";
|
|
5
5
|
import { Context as o, Schema as s } from "effect";
|
|
6
6
|
// src/HotStore.ts
|
|
@@ -14,4 +14,4 @@ var c = class extends s.TaggedError()("HotError", {
|
|
|
14
14
|
"unavailable"
|
|
15
15
|
])
|
|
16
16
|
}) {}, l = class extends o.Service()("@voltro/HotStore") {};
|
|
17
|
-
export { c as HotError, l as HotStore,
|
|
17
|
+
export { c as HotError, l as HotStore, t as applyHotOperations, n as compareHotMembers, e as consumeHotRateLimit, r as hotStoreFromRunner, a as readHotStoreWithFallback, i as validateHotOp };
|
package/dist/hot-testing.d.ts
CHANGED
|
@@ -6,6 +6,23 @@ import { Schema } from 'effect';
|
|
|
6
6
|
import { Stream } from 'effect';
|
|
7
7
|
import { YieldableError } from 'effect/Cause';
|
|
8
8
|
|
|
9
|
+
/** Tag and replacement path. A replacement backend proves itself with
|
|
10
|
+
* `conformance`, the same suite the memory and Redis backends run. */
|
|
11
|
+
export declare const hotBackendPortFixture: {
|
|
12
|
+
kind: "port";
|
|
13
|
+
tag: typeof HotStore;
|
|
14
|
+
fakeLayer: Layer.Layer<HotStore, HotError, never>;
|
|
15
|
+
conformance: (name: string, fixture: () => HotConformanceFixture, tests: HotConformanceTestApi) => void;
|
|
16
|
+
probe: {
|
|
17
|
+
run: () => Effect.Effect<number, HotError, never>;
|
|
18
|
+
expected: number;
|
|
19
|
+
};
|
|
20
|
+
overrideProbe: {
|
|
21
|
+
run: () => Effect.Effect<number, HotError, never>;
|
|
22
|
+
expected: number;
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
|
|
9
26
|
declare interface HotBucketConfig {
|
|
10
27
|
readonly capacity: number;
|
|
11
28
|
readonly refillPerSec: number;
|
|
@@ -193,6 +210,9 @@ declare const HotStore_base: Context.ServiceClass<HotStore, "@voltro/HotStore",
|
|
|
193
210
|
/** Run exactly the same behavioral contract against a backend or a replacement port. */
|
|
194
211
|
export declare const hotStoreConformance: (name: string, fixture: () => HotConformanceFixture, tests: HotConformanceTestApi) => void;
|
|
195
212
|
|
|
213
|
+
/** The in-memory backend: one fresh store per provided scope. */
|
|
214
|
+
export declare const hotStoreFakeLayer: Layer.Layer<HotStore, HotError>;
|
|
215
|
+
|
|
196
216
|
declare interface HotStoreShape {
|
|
197
217
|
readonly zadd: (key: string, members: ReadonlyArray<HotMember>, options?: HotZaddOptions) => Effect.Effect<void, HotError>;
|
|
198
218
|
readonly zrem: (key: string, members: ReadonlyArray<string>) => Effect.Effect<number, HotError>;
|
package/dist/hot-testing.js
CHANGED
|
@@ -1 +1,3 @@
|
|
|
1
|
-
|
|
1
|
+
import { hotStoreConformance as e } from "./hotStoreConformance.js";
|
|
2
|
+
import { hotBackendPortFixture as t, hotStoreFakeLayer as n } from "./hotStoreFixtures.js";
|
|
3
|
+
export { t as hotBackendPortFixture, e as hotStoreConformance, n as hotStoreFakeLayer };
|
package/dist/hot.d.ts
CHANGED
|
@@ -280,7 +280,7 @@ declare interface ConnectionPoolSnapshot {
|
|
|
280
280
|
readonly source: 'config' | 'environment' | 'override';
|
|
281
281
|
readonly label?: string;
|
|
282
282
|
readonly region?: string;
|
|
283
|
-
readonly persistence?: RedisConnectionConfig['persistence']
|
|
283
|
+
readonly persistence?: NonNullable<RedisConnectionConfig['persistence']>;
|
|
284
284
|
}
|
|
285
285
|
|
|
286
286
|
/** Borrowed Pub/Sub port. A consumer owns registrations, never broker sockets. */
|
|
@@ -608,6 +608,22 @@ export declare interface HotStoreShape {
|
|
|
608
608
|
};
|
|
609
609
|
}
|
|
610
610
|
|
|
611
|
+
/** Inventory of the hot store's replaceable part as actual exports: the backend
|
|
612
|
+
* behind the `HotStore` Tag. `hotSystemManifest.test.ts` runs the fixture and
|
|
613
|
+
* the shared conformance suite against a replacement. Routing is an option of
|
|
614
|
+
* `layerRoutedHotRedis`, not a slot. */
|
|
615
|
+
export declare const hotStoreSystemContractManifest: Readonly<{
|
|
616
|
+
slots: Readonly<{}>;
|
|
617
|
+
ports: Readonly<{
|
|
618
|
+
backend: Readonly<{
|
|
619
|
+
tagExport: "HotStore";
|
|
620
|
+
fakeLayerExport: "hotStoreFakeLayer";
|
|
621
|
+
fixtureExport: "hotBackendPortFixture";
|
|
622
|
+
}>;
|
|
623
|
+
}>;
|
|
624
|
+
events: readonly string[];
|
|
625
|
+
}>;
|
|
626
|
+
|
|
611
627
|
export declare interface HotTtl {
|
|
612
628
|
readonly ttlMs?: number;
|
|
613
629
|
}
|
package/dist/hot.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
|
|
1
|
+
import { HotError as e, HotStore as t } from "./hot-contract.js";
|
|
2
|
+
import { consumeHotRateLimit as n } from "./hotRateLimit.js";
|
|
3
|
+
import { HOT_MEMORY_DEFAULTS as r, layerHotMemory as i, makeMemoryHotStore as a } from "./hotMemory.js";
|
|
4
|
+
import { HOT_REDIS_DEFAULTS as o, layerHotRedis as s, makeRedisHotStore as c } from "./hotRedis.js";
|
|
5
|
+
import { layerRoutedHotRedis as l } from "./hotRouting.js";
|
|
6
|
+
import { readHotStoreWithFallback as u } from "./hotReadAvailability.js";
|
|
7
|
+
import { hotStoreSystemContractManifest as d } from "./hotSystemManifest.js";
|
|
8
|
+
export { r as HOT_MEMORY_DEFAULTS, o as HOT_REDIS_DEFAULTS, e as HotError, t as HotStore, n as consumeHotRateLimit, d as hotStoreSystemContractManifest, i as layerHotMemory, s as layerHotRedis, l as layerRoutedHotRedis, a as makeMemoryHotStore, c as makeRedisHotStore, u as readHotStoreWithFallback };
|
package/dist/hotMemory.js
CHANGED
|
@@ -1,27 +1,27 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import { HotError as e, HotStore as t } from "./hot-contract.js";
|
|
2
|
+
import { hotStoreFromRunner as n, validateHotOp as r } from "./hotOperations.js";
|
|
3
|
+
import { applyHotOperations as i, compareHotMembers as a } from "./hotState.js";
|
|
4
4
|
import { Clock as o, Effect as s, Layer as c, Stream as l } from "effect";
|
|
5
5
|
// src/hotMemory.ts
|
|
6
|
-
var u = { sweepBatchSize: 32 }, d = (
|
|
6
|
+
var u = { sweepBatchSize: 32 }, d = (t = {}) => s.try({
|
|
7
7
|
try: () => {
|
|
8
|
-
let c = /* @__PURE__ */ new Map(), d =
|
|
8
|
+
let c = /* @__PURE__ */ new Map(), d = t.sweepBatchSize ?? u.sweepBatchSize;
|
|
9
9
|
if (!Number.isSafeInteger(d) || d < 1) throw Error("HotStore sweepBatchSize must be a positive integer");
|
|
10
|
-
let f = c.entries(), p =
|
|
11
|
-
return
|
|
10
|
+
let f = c.entries(), p = t.now === void 0 ? o.currentTimeMillis : s.sync(t.now);
|
|
11
|
+
return n((t) => p.pipe(s.flatMap((n) => s.try({
|
|
12
12
|
try: () => {
|
|
13
|
-
|
|
13
|
+
t.forEach(r);
|
|
14
14
|
for (let e = 0; e < d; e++) {
|
|
15
15
|
let e = f.next();
|
|
16
16
|
if (e.done) {
|
|
17
17
|
f = c.entries();
|
|
18
18
|
break;
|
|
19
19
|
}
|
|
20
|
-
e.value[1].expiresAt <=
|
|
20
|
+
e.value[1].expiresAt <= n && c.delete(e.value[0]);
|
|
21
21
|
}
|
|
22
|
-
return
|
|
22
|
+
return i(c, t, n);
|
|
23
23
|
},
|
|
24
|
-
catch: (
|
|
24
|
+
catch: (t) => t instanceof e ? t : new e({
|
|
25
25
|
operation: "multi",
|
|
26
26
|
key: "",
|
|
27
27
|
reason: "invalid"
|
|
@@ -29,17 +29,17 @@ var u = { sweepBatchSize: 32 }, d = (a = {}) => s.try({
|
|
|
29
29
|
}))), (e) => l.unwrap(p.pipe(s.map((t) => {
|
|
30
30
|
let n = [];
|
|
31
31
|
for (let [r, i] of c) i.expiresAt <= t ? c.delete(r) : r.startsWith(e) && n.push(r);
|
|
32
|
-
return l.fromIterable(n.sort(
|
|
32
|
+
return l.fromIterable(n.sort(a));
|
|
33
33
|
}))), {
|
|
34
34
|
atomicMulti: !0,
|
|
35
35
|
crossNode: !1,
|
|
36
36
|
persistent: !1
|
|
37
37
|
});
|
|
38
38
|
},
|
|
39
|
-
catch: () => new
|
|
39
|
+
catch: () => new e({
|
|
40
40
|
operation: "connect",
|
|
41
41
|
key: "",
|
|
42
42
|
reason: "invalid"
|
|
43
43
|
})
|
|
44
|
-
}), f = (e = {}) => c.effect(
|
|
44
|
+
}), f = (e = {}) => c.effect(t, d(e));
|
|
45
45
|
export { u as HOT_MEMORY_DEFAULTS, f as layerHotMemory, d as makeMemoryHotStore };
|
package/dist/hotRedis.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { RedisConnections as e } from "./connection.js";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import { HotError as t, HotStore as n } from "./hot-contract.js";
|
|
3
|
+
import { hotStoreFromRunner as r, isHotReadOperation as i, validateHotOp as a, validateHotReadOptions as o } from "./hotOperations.js";
|
|
4
4
|
import { HOT_SCRIPT as s } from "./hotRedisScript.js";
|
|
5
5
|
import { Effect as c, Layer as l, Option as u, Stream as d } from "effect";
|
|
6
6
|
// src/hotRedis.ts
|
|
@@ -8,46 +8,46 @@ var f = {
|
|
|
8
8
|
connectionName: "hot",
|
|
9
9
|
namespace: "voltro:hot",
|
|
10
10
|
scanCount: 200
|
|
11
|
-
}, p = (e) => e.replace(/[\\*?\[\]]/g, "\\$&"), m = (e,
|
|
12
|
-
if (
|
|
11
|
+
}, p = (e) => e.replace(/[\\*?\[\]]/g, "\\$&"), m = (e, n = f.namespace, l = f.scanCount) => {
|
|
12
|
+
if (n.length === 0 || /[{}]/.test(n)) throw Error("HotStore namespace must be nonempty and contain no braces");
|
|
13
13
|
if (!Number.isSafeInteger(l) || l < 1) throw Error("HotStore scanCount must be a positive integer");
|
|
14
|
-
let m = `{${
|
|
15
|
-
return
|
|
14
|
+
let m = `{${n}}:`, h = (e) => m + e;
|
|
15
|
+
return r((n, r) => c.gen(function* () {
|
|
16
16
|
if (yield* c.try({
|
|
17
17
|
try: () => {
|
|
18
|
-
if (
|
|
18
|
+
if (n.forEach(a), o(r, n[0]?.op ?? "multi", n[0]?.key ?? ""), r?.consistency === "eventual" && (n.length !== 1 || !i(n[0]))) throw new t({
|
|
19
19
|
operation: "multi",
|
|
20
20
|
key: "",
|
|
21
21
|
reason: "invalid"
|
|
22
22
|
});
|
|
23
23
|
},
|
|
24
|
-
catch: (e) => e instanceof
|
|
24
|
+
catch: (e) => e instanceof t ? e : new t({
|
|
25
25
|
operation: "multi",
|
|
26
26
|
key: "",
|
|
27
27
|
reason: "invalid"
|
|
28
28
|
})
|
|
29
|
-
}),
|
|
29
|
+
}), n.length === 0) return [];
|
|
30
30
|
let l = yield* c.tryPromise({
|
|
31
31
|
try: () => {
|
|
32
|
-
let
|
|
33
|
-
return
|
|
32
|
+
let t = r?.consistency === "eventual" ? e.readOnly : e;
|
|
33
|
+
return t === void 0 ? Promise.reject(/* @__PURE__ */ Error("Read-only Lua is unavailable")) : t.eval(s, n.length, ...n.map((e) => h(e.key)), JSON.stringify(n));
|
|
34
34
|
},
|
|
35
|
-
catch: () => new
|
|
35
|
+
catch: () => new t({
|
|
36
36
|
operation: "multi",
|
|
37
37
|
key: "",
|
|
38
38
|
reason: "unavailable"
|
|
39
39
|
})
|
|
40
40
|
}), u = yield* c.try({
|
|
41
41
|
try: () => JSON.parse(String(l)),
|
|
42
|
-
catch: () => new
|
|
42
|
+
catch: () => new t({
|
|
43
43
|
operation: "multi",
|
|
44
44
|
key: "",
|
|
45
45
|
reason: "unavailable"
|
|
46
46
|
})
|
|
47
47
|
});
|
|
48
|
-
return u.failure === void 0 ? u.results?.length ===
|
|
49
|
-
try: () => u.results.map(({ value: e },
|
|
50
|
-
let
|
|
48
|
+
return u.failure === void 0 ? u.results?.length === n.length ? yield* c.try({
|
|
49
|
+
try: () => u.results.map(({ value: e }, r) => {
|
|
50
|
+
let i = n[r];
|
|
51
51
|
if ([
|
|
52
52
|
"zrem",
|
|
53
53
|
"zrank",
|
|
@@ -58,12 +58,12 @@ var f = {
|
|
|
58
58
|
"hdel",
|
|
59
59
|
"sadd",
|
|
60
60
|
"srem"
|
|
61
|
-
].includes(
|
|
62
|
-
if (
|
|
61
|
+
].includes(i.op)) return e === null ? null : Number(e);
|
|
62
|
+
if (i.op === "zrange") return Array.isArray(e) ? e.map((e) => ({
|
|
63
63
|
member: e.member,
|
|
64
64
|
score: Number(e.score)
|
|
65
65
|
})) : [];
|
|
66
|
-
if (
|
|
66
|
+
if (i.op === "tokenBucket") {
|
|
67
67
|
let t = e;
|
|
68
68
|
return {
|
|
69
69
|
allowed: t.allowed,
|
|
@@ -71,48 +71,48 @@ var f = {
|
|
|
71
71
|
retryAfterMs: Number(t.retryAfterMs)
|
|
72
72
|
};
|
|
73
73
|
}
|
|
74
|
-
if (
|
|
75
|
-
let
|
|
76
|
-
allowed:
|
|
77
|
-
remaining: Number(
|
|
78
|
-
resetAtMs: Number(
|
|
79
|
-
retryAfterMs: Number(
|
|
74
|
+
if (i.op === "rateLimit") {
|
|
75
|
+
let n = e, r = {
|
|
76
|
+
allowed: n.allowed,
|
|
77
|
+
remaining: Number(n.remaining),
|
|
78
|
+
resetAtMs: Number(n.resetAtMs),
|
|
79
|
+
retryAfterMs: Number(n.retryAfterMs)
|
|
80
80
|
};
|
|
81
|
-
if (typeof
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
].every(Number.isFinite)) throw new
|
|
81
|
+
if (typeof r.allowed != "boolean" || ![
|
|
82
|
+
r.remaining,
|
|
83
|
+
r.resetAtMs,
|
|
84
|
+
r.retryAfterMs
|
|
85
|
+
].every(Number.isFinite)) throw new t({
|
|
86
86
|
operation: "rateLimit",
|
|
87
|
-
key:
|
|
87
|
+
key: i.key,
|
|
88
88
|
reason: "unavailable"
|
|
89
89
|
});
|
|
90
|
-
return
|
|
90
|
+
return r;
|
|
91
91
|
}
|
|
92
|
-
return
|
|
92
|
+
return i.op === "smembers" && !Array.isArray(e) ? [] : e;
|
|
93
93
|
}),
|
|
94
|
-
catch: (e) => e instanceof
|
|
94
|
+
catch: (e) => e instanceof t ? e : new t({
|
|
95
95
|
operation: "multi",
|
|
96
96
|
key: "",
|
|
97
97
|
reason: "unavailable"
|
|
98
98
|
})
|
|
99
|
-
}) : yield* c.fail(new
|
|
99
|
+
}) : yield* c.fail(new t({
|
|
100
100
|
operation: "multi",
|
|
101
101
|
key: "",
|
|
102
102
|
reason: "unavailable"
|
|
103
|
-
})) : yield* c.fail(new
|
|
104
|
-
}), (
|
|
105
|
-
let
|
|
106
|
-
return d.paginate("0", (
|
|
107
|
-
try: () => e.scan(
|
|
108
|
-
catch: () => new
|
|
103
|
+
})) : yield* c.fail(new t(u.failure));
|
|
104
|
+
}), (n) => d.unwrap(c.sync(() => {
|
|
105
|
+
let r = /* @__PURE__ */ new Set();
|
|
106
|
+
return d.paginate("0", (i) => c.tryPromise({
|
|
107
|
+
try: () => e.scan(i, `${p(m + n)}*`, l),
|
|
108
|
+
catch: () => new t({
|
|
109
109
|
operation: "scanPrefix",
|
|
110
|
-
key:
|
|
110
|
+
key: n,
|
|
111
111
|
reason: "unavailable"
|
|
112
112
|
})
|
|
113
|
-
}).pipe(c.map(({ cursor: e, keys:
|
|
113
|
+
}).pipe(c.map(({ cursor: e, keys: t }) => {
|
|
114
114
|
let i = [];
|
|
115
|
-
for (let e of
|
|
115
|
+
for (let e of t) e.startsWith(m + n) && !r.has(e) && (r.add(e), i.push(e.slice(m.length)));
|
|
116
116
|
return [i, e === "0" ? u.none() : u.some(e)];
|
|
117
117
|
})));
|
|
118
118
|
})), {
|
|
@@ -120,15 +120,15 @@ var f = {
|
|
|
120
120
|
crossNode: e.crossNode ?? !0,
|
|
121
121
|
persistent: !1
|
|
122
122
|
});
|
|
123
|
-
}, h = (
|
|
124
|
-
let n = yield* (yield* e).client(
|
|
123
|
+
}, h = (r = {}) => l.effect(n, c.gen(function* () {
|
|
124
|
+
let n = yield* (yield* e).client(r.connectionName ?? f.connectionName).pipe(c.mapError(() => new t({
|
|
125
125
|
operation: "connect",
|
|
126
126
|
key: "",
|
|
127
127
|
reason: "unavailable"
|
|
128
128
|
})));
|
|
129
129
|
return yield* c.try({
|
|
130
|
-
try: () => m(n,
|
|
131
|
-
catch: () => new
|
|
130
|
+
try: () => m(n, r.namespace, r.scanCount),
|
|
131
|
+
catch: () => new t({
|
|
132
132
|
operation: "connect",
|
|
133
133
|
key: "",
|
|
134
134
|
reason: "invalid"
|
package/dist/hotRouting.js
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
import { ConnectionRegistry as e } from "./connectionPool.js";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import { HotError as t, HotStore as n } from "./hot-contract.js";
|
|
3
|
+
import { hotStoreFromRunner as r, validateHotOp as i, validateHotReadOptions as a } from "./hotOperations.js";
|
|
4
4
|
import { makeRedisHotStore as o } from "./hotRedis.js";
|
|
5
5
|
import { Effect as s, Layer as c, Stream as l } from "effect";
|
|
6
6
|
// src/hotRouting.ts
|
|
7
|
-
var u = (u) => c.effect(
|
|
8
|
-
let
|
|
7
|
+
var u = (u) => c.effect(n, s.gen(function* () {
|
|
8
|
+
let n = yield* e, c = u.routes?.[u.consumer], d = c?.select, f = u.context === void 0 ? void 0 : Object.freeze({ tenantId: u.context.tenantId }), p = u.consumers?.[u.consumer] ?? u.connection, m = [...new Set(c?.connections ?? [p ?? ""])], h = u.namespace, g = u.scanCount, _ = (e, n = "") => new t({
|
|
9
9
|
operation: e,
|
|
10
|
-
key:
|
|
10
|
+
key: n,
|
|
11
11
|
reason: "invalid"
|
|
12
12
|
});
|
|
13
13
|
if (!u.consumer || m.length === 0 || c !== void 0 && (c.keyAffinity !== !0 || typeof c.select != "function")) return yield* s.fail(_("route"));
|
|
14
14
|
let v = !0;
|
|
15
15
|
for (let e of m) {
|
|
16
16
|
if (e !== "" && !/^redis:[A-Za-z][A-Za-z0-9_-]*$/.test(e)) return yield* s.fail(_("route"));
|
|
17
|
-
(yield*
|
|
17
|
+
(yield* n.validate(e).pipe(s.mapError(() => _("route")))).tenantScoped && f === void 0 || (yield* n.config(e, f).pipe(s.mapError(() => _("route")))).driver !== "memory" || (v = !1);
|
|
18
18
|
}
|
|
19
19
|
if (h !== void 0 && (!h || /[{}]/.test(h)) || g !== void 0 && (!Number.isSafeInteger(g) || g < 1)) return yield* s.fail(_("route"));
|
|
20
20
|
let y = (e) => s.try({
|
|
@@ -27,40 +27,40 @@ var u = (u) => c.effect(a, s.gen(function* () {
|
|
|
27
27
|
return t;
|
|
28
28
|
},
|
|
29
29
|
catch: () => _("route", e)
|
|
30
|
-
}), b = (e) =>
|
|
30
|
+
}), b = (e) => n.client(e, f).pipe(s.mapError(() => new t({
|
|
31
31
|
operation: "connect",
|
|
32
32
|
key: "",
|
|
33
33
|
reason: "unavailable"
|
|
34
34
|
})), s.map((e) => o(e, h, g)));
|
|
35
|
-
return
|
|
35
|
+
return r((e, n) => s.gen(function* () {
|
|
36
36
|
if (yield* s.try({
|
|
37
37
|
try: () => {
|
|
38
|
-
e.forEach(
|
|
38
|
+
e.forEach(i), a(n, e[0]?.op ?? "multi", e[0]?.key ?? "");
|
|
39
39
|
},
|
|
40
|
-
catch: (e) => e instanceof
|
|
40
|
+
catch: (e) => e instanceof t ? e : _("multi")
|
|
41
41
|
}), e.length === 0) return [];
|
|
42
|
-
let
|
|
43
|
-
for (let t of e)
|
|
44
|
-
let o = new Set(
|
|
42
|
+
let r = /* @__PURE__ */ new Map();
|
|
43
|
+
for (let t of e) r.has(t.key) || r.set(t.key, yield* y(t.key));
|
|
44
|
+
let o = new Set(r.values());
|
|
45
45
|
if (o.size !== 1) return yield* s.fail(_("multi"));
|
|
46
46
|
let c = yield* b(o.values().next().value);
|
|
47
|
-
if (
|
|
47
|
+
if (n?.consistency === "eventual") {
|
|
48
48
|
if (e.length !== 1) return yield* s.fail(_("multi"));
|
|
49
|
-
let
|
|
49
|
+
let t = e[0];
|
|
50
50
|
return [yield* s.gen(function* () {
|
|
51
|
-
switch (
|
|
52
|
-
case "zrank": return yield* c.zrank(
|
|
53
|
-
case "zscore": return yield* c.zscore(
|
|
54
|
-
case "zrange": return yield* c.zrange(
|
|
55
|
-
...
|
|
56
|
-
...
|
|
51
|
+
switch (t.op) {
|
|
52
|
+
case "zrank": return yield* c.zrank(t.key, t.member, t.order, n).pipe(s.map((e) => e._tag === "Some" ? e.value : null));
|
|
53
|
+
case "zscore": return yield* c.zscore(t.key, t.member, n).pipe(s.map((e) => e._tag === "Some" ? e.value : null));
|
|
54
|
+
case "zrange": return yield* c.zrange(t.key, t.range, t.order, {
|
|
55
|
+
...t.options,
|
|
56
|
+
...n
|
|
57
57
|
});
|
|
58
|
-
case "zcard": return yield* c.zcard(
|
|
59
|
-
case "hget": return yield* c.hget(
|
|
60
|
-
case "hgetAll": return yield* c.hgetAll(
|
|
61
|
-
case "smembers": return yield* c.smembers(
|
|
62
|
-
case "sismember": return yield* c.sismember(
|
|
63
|
-
default: return yield* s.fail(_(
|
|
58
|
+
case "zcard": return yield* c.zcard(t.key, n);
|
|
59
|
+
case "hget": return yield* c.hget(t.key, t.field, n).pipe(s.map((e) => e._tag === "Some" ? e.value : null));
|
|
60
|
+
case "hgetAll": return yield* c.hgetAll(t.key, n);
|
|
61
|
+
case "smembers": return yield* c.smembers(t.key, n);
|
|
62
|
+
case "sismember": return yield* c.sismember(t.key, t.member, n);
|
|
63
|
+
default: return yield* s.fail(_(t.op, t.key));
|
|
64
64
|
}
|
|
65
65
|
})];
|
|
66
66
|
}
|
package/dist/hotState.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { HotError as e } from "./hot-contract.js";
|
|
2
2
|
import { validateHotOp as t } from "./hotOperations.js";
|
|
3
|
-
import {
|
|
3
|
+
import { consumeHotRateLimit as n } from "./hotRateLimit.js";
|
|
4
4
|
// src/hotState.ts
|
|
5
5
|
var r = (e, t) => {
|
|
6
6
|
let n = Array.from(e, (e) => e.codePointAt(0) ?? 0), r = Array.from(t, (e) => e.codePointAt(0) ?? 0);
|
|
@@ -56,11 +56,11 @@ var r = (e, t) => {
|
|
|
56
56
|
t !== void 0 && t.expiresAt > l && !u.has(e.key) && u.set(e.key, d.has(e.key) ? o(t) : t);
|
|
57
57
|
}
|
|
58
58
|
let f = c.map((t) => {
|
|
59
|
-
let o = u.get(t.key), s = (
|
|
60
|
-
throw new
|
|
59
|
+
let o = u.get(t.key), s = (n) => {
|
|
60
|
+
throw new e({
|
|
61
61
|
operation: t.op,
|
|
62
62
|
key: t.key,
|
|
63
|
-
reason:
|
|
63
|
+
reason: n
|
|
64
64
|
});
|
|
65
65
|
}, c = (e) => (o !== void 0 && o.kind !== e && s("wrongType"), o), d = (e) => (o = {
|
|
66
66
|
...e,
|
|
@@ -123,7 +123,7 @@ var r = (e, t) => {
|
|
|
123
123
|
};
|
|
124
124
|
}
|
|
125
125
|
case "rateLimit": {
|
|
126
|
-
let
|
|
126
|
+
let e = c("rateLimit")?.state, r = n(e, t.config, t.nowMs ?? l);
|
|
127
127
|
return d({
|
|
128
128
|
kind: "rateLimit",
|
|
129
129
|
state: r.state
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { HotStore as e } from "./hot-contract.js";
|
|
2
|
+
import { layerHotMemory as t, makeMemoryHotStore as n } from "./hotMemory.js";
|
|
3
|
+
import { hotStoreConformance as r } from "./hotStoreConformance.js";
|
|
4
|
+
import { Effect as i, Layer as a } from "effect";
|
|
5
|
+
// src/hotStoreFixtures.ts
|
|
6
|
+
var o = t(), s = (t) => e.pipe(i.flatMap((e) => e.incrBy("fixture:counter", 2)), i.provide(t)), c = {
|
|
7
|
+
kind: "port",
|
|
8
|
+
tag: e,
|
|
9
|
+
fakeLayer: o,
|
|
10
|
+
conformance: r,
|
|
11
|
+
probe: {
|
|
12
|
+
run: () => s(o),
|
|
13
|
+
expected: 2
|
|
14
|
+
},
|
|
15
|
+
overrideProbe: {
|
|
16
|
+
run: () => s(a.effect(e, i.map(n(), (e) => ({
|
|
17
|
+
...e,
|
|
18
|
+
incrBy: (t, n, r) => e.incrBy(t, n * 10, r)
|
|
19
|
+
})))),
|
|
20
|
+
expected: 20
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
export { c as hotBackendPortFixture, o as hotStoreFakeLayer };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// src/hotSystemManifest.ts
|
|
2
|
+
var e = Object.freeze({
|
|
3
|
+
slots: Object.freeze({}),
|
|
4
|
+
ports: Object.freeze({ backend: Object.freeze({
|
|
5
|
+
tagExport: "HotStore",
|
|
6
|
+
fakeLayerExport: "hotStoreFakeLayer",
|
|
7
|
+
fixtureExport: "hotBackendPortFixture"
|
|
8
|
+
}) }),
|
|
9
|
+
events: Object.freeze([])
|
|
10
|
+
});
|
|
11
|
+
export { e as hotStoreSystemContractManifest };
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { Kv as e } from "./Kv.js";
|
|
2
|
+
import { KvStore as t } from "./KvStore.js";
|
|
3
3
|
import { KvError as n } from "./errors.js";
|
|
4
4
|
import { layerMemory as r } from "./backendMemory.js";
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
export {
|
|
5
|
+
import { layerRedis as i, makeRedisKvStore as a } from "./backendRedis.js";
|
|
6
|
+
import { RedisConnections as o, commandRetry as s, connect as c, connectionConfig as l, layerConnections as u } from "./connection.js";
|
|
7
|
+
export { e as Kv, n as KvError, t as KvStore, o as RedisConnections, s as commandRetry, c as connect, l as connectionConfig, u as layerConnections, r as layerMemory, i as layerRedis, a as makeRedisKvStore };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@voltro/kv",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.91.0",
|
|
4
4
|
"description": "Named RESP connection registry + durable key-value primitive. One config surface for many Redis-family connections (Redis/Valkey/KeyDB/Dragonfly/Upstash) shared across cache, rate-limit, RYW and broadcast; plus a durable, tenant-scoped KV store distinct from the best-effort cache.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"voltro",
|
|
@@ -68,12 +68,12 @@
|
|
|
68
68
|
"node": ">=24.0.0"
|
|
69
69
|
},
|
|
70
70
|
"dependencies": {
|
|
71
|
-
"@voltro/shared": "0.
|
|
71
|
+
"@voltro/shared": "0.91.0"
|
|
72
72
|
},
|
|
73
73
|
"peerDependencies": {
|
|
74
|
-
"effect": "4.1.
|
|
74
|
+
"effect": "4.1.4",
|
|
75
75
|
"@nats-io/transport-node": "^3.4.0",
|
|
76
|
-
"@upstash/redis": "^1.
|
|
76
|
+
"@upstash/redis": "^1.41.0",
|
|
77
77
|
"ioredis": "^6.0.0"
|
|
78
78
|
},
|
|
79
79
|
"peerDependenciesMeta": {
|