tricache 1.0.0 → 1.0.2
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/README.md +36 -28
- package/dist/{cache-service-pJ-nFcVj.d.ts → cache-service-B108FzER.d.ts} +63 -3
- package/dist/cache-service-CWI4jkS7.d.cts +963 -0
- package/dist/{cache-service-26GCO3UU.js → cache-service-GYPZFB7O.js} +2 -2
- package/dist/{chunk-IITRFWHY.js → chunk-EUKB7RKP.js} +21 -4
- package/dist/{chunk-2AJKEQMZ.js → chunk-H4GFLQ26.js} +7 -4
- package/dist/{chunk-7RV5ZVBB.js → chunk-JNSLMK4Q.js} +111 -29
- package/dist/chunk-OYDU3SMI.js +89 -0
- package/dist/{chunk-VXFTFZ5N.js → chunk-VNRDL5RA.js} +117 -138
- package/dist/{chunk-7SZSQS55.js → chunk-WYF7NOAT.js} +1831 -759
- package/dist/cli.cjs +1757 -777
- package/dist/cli.d.cts +12 -0
- package/dist/cli.js +27 -6
- package/dist/dashboard/index.cjs +111 -29
- package/dist/dashboard/index.d.cts +185 -0
- package/dist/dashboard/index.d.ts +5 -3
- package/dist/dashboard/index.js +1 -1
- package/dist/drizzle/index.cjs +1757 -773
- package/dist/drizzle/index.d.cts +46 -0
- package/dist/drizzle/index.d.ts +2 -2
- package/dist/drizzle/index.js +1 -1
- package/dist/edge/index.cjs +280 -153
- package/dist/edge/index.d.cts +127 -0
- package/dist/edge/index.d.ts +3 -3
- package/dist/edge/index.js +254 -147
- package/dist/hono/index.cjs +1805 -793
- package/dist/hono/index.d.cts +93 -0
- package/dist/hono/index.d.ts +7 -5
- package/dist/hono/index.js +16 -9
- package/dist/{hono-DuNvciyq.d.ts → hono-3rDMYVtY.d.ts} +23 -3
- package/dist/hono-C886ok3X.d.cts +391 -0
- package/dist/http/index.cjs +1946 -842
- package/dist/http/index.d.cts +103 -0
- package/dist/http/index.d.ts +13 -5
- package/dist/http/index.js +137 -57
- package/dist/index.cjs +2073 -937
- package/dist/index.d.cts +1006 -0
- package/dist/index.d.ts +40 -8
- package/dist/index.js +8 -8
- package/dist/murmur3-CMGw9PbV.d.cts +98 -0
- package/dist/nestjs/index.cjs +1849 -806
- package/dist/nestjs/index.d.cts +285 -0
- package/dist/nestjs/index.d.ts +103 -30
- package/dist/nestjs/index.js +115 -32
- package/dist/next/index.cjs +1913 -887
- package/dist/next/index.d.cts +232 -0
- package/dist/next/index.d.ts +33 -11
- package/dist/next/index.js +174 -107
- package/dist/prisma/index.cjs +11 -1
- package/dist/prisma/index.d.cts +62 -0
- package/dist/prisma/index.d.ts +2 -2
- package/dist/prisma/index.js +11 -1
- package/dist/serialize-worker.d.cts +2 -0
- package/dist/{types-5HXqBfAf.d.ts → types-BA4pz1A0.d.cts} +26 -9
- package/dist/types-BA4pz1A0.d.ts +1519 -0
- package/dist/{utils-CEsU_Z0s.d.ts → utils-Bvzn-rKS.d.cts} +3 -1
- package/dist/utils-Bvzn-rKS.d.ts +29 -0
- package/package.json +96 -36
- package/src/adapters/auto-pipeliner.ts +107 -24
- package/src/adapters/node-redis.ts +123 -25
- package/src/cache-service.ts +1238 -659
- package/src/cli.ts +24 -6
- package/src/cross-region.ts +21 -3
- package/src/dashboard/handler.ts +26 -6
- package/src/dashboard/html.ts +35 -10
- package/src/dashboard/index.ts +35 -13
- package/src/dashboard/types.ts +3 -1
- package/src/disk-tier.ts +171 -65
- package/src/edge/cache.ts +202 -129
- package/src/edge/hono.ts +23 -6
- package/src/edge/types.ts +2 -0
- package/src/hono/index.ts +19 -9
- package/src/http/express.ts +110 -26
- package/src/http/fastify.ts +38 -28
- package/src/http/utils.ts +54 -20
- package/src/ipc-telemetry.ts +35 -9
- package/src/nestjs/decorators.ts +1 -1
- package/src/nestjs/index.ts +2 -0
- package/src/nestjs/keyv-adapter.ts +68 -0
- package/src/nestjs/tricache.module.ts +13 -11
- package/src/nestjs/tricache.store.ts +51 -20
- package/src/nestjs/types.ts +29 -15
- package/src/next/cache-handler.ts +132 -57
- package/src/next/index.ts +1 -0
- package/src/next/isr-handler.ts +1 -4
- package/src/next/types.ts +21 -0
- package/src/prisma/index.ts +12 -1
- package/src/smart-memory-cache.ts +65 -27
- package/src/types.ts +27 -2
- package/src/utils/cgroup.ts +12 -0
- package/src/utils/deadline.ts +14 -0
- package/src/utils/diagnostics.ts +27 -0
- package/src/utils/redis-slot.ts +13 -0
- package/src/wasm/bloom-filter-wasm.ts +9 -4
- package/src/worker-pool.ts +17 -8
- package/src/wtiny-lfu.ts +20 -6
- package/dist/chunk-BQRURGGD.js +0 -60
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export { C as CacheService, I as IIpcCacheProvider, a as IpcMetricsPayload, b as IpcTelemetryClient, c as IpcTelemetryServer, L as LatencyWatchdogOptions, d as LatencyWatchdogTelemetry, P as ProcessTerminationBus, T as TierLatencyWatchdog, e as deepMergeOptions, f as findActiveSockets, g as formatBytes, h as formatDuration, i as formatNumber, r as renderProgressBar, j as renderTopDashboard, k as resolveIpcSocketPath } from './cache-service-
|
|
2
|
-
import { j as IRemoteSnapshotAdapter, k as CategoryLimit, S as SmartCacheEntry, l as EvictionReason, i as ILogger, m as CacheHit, f as CachePriority, h as WTinyLfuStats$1, n as CacheEncryption, o as CompressionAlgorithm, p as DiskCacheEntry, D as DiskBackpressureStats, q as IRedisDriver, r as IRedisPipeline } from './types-
|
|
3
|
-
export { c as CacheHealthStatus, b as CacheMetrics, C as CacheOptions, g as CachePingResult, d as CachePresetType, e as CrossRegionInvalidationEvent, s as CrossRegionRelayOptions, t as CustomCompressor, E as EncryptionMode, u as EnvelopeEncryption, v as EnvelopeEncryptionOptions, H as HttpMeshRelayOptions, w as HttpSnapshotAdapterOptions, x as ICacheBatchObservableCallback, y as ICacheCounter, z as ICacheMeter, A as ICacheObservableGauge, B as ICacheSpan, F as ICacheSpanLink, I as ICacheTracer, G as ICrossRegionRelay, a as InvalidateTagOptions, L as LockOptions, R as RemoteSnapshotOptions, J as WebhookRequestLike, K as WebhookResponseLike, W as WrapOptions, M as consoleLogger, N as createCrossRegionWebhookHandler, O as createCustomCrossRegionRelay, P as createCustomSnapshotAdapter, Q as createHttpMeshRelay, T as createHttpSnapshotAdapter, U as createMemoryCrossRegionRelay, V as createMemorySnapshotAdapter, X as initZstd } from './types-
|
|
1
|
+
export { C as CacheService, I as IIpcCacheProvider, a as IpcMetricsPayload, b as IpcTelemetryClient, c as IpcTelemetryServer, L as LatencyWatchdogOptions, d as LatencyWatchdogTelemetry, P as ProcessTerminationBus, T as TierLatencyWatchdog, e as deepMergeOptions, f as findActiveSockets, g as formatBytes, h as formatDuration, i as formatNumber, r as renderProgressBar, j as renderTopDashboard, k as resolveIpcSocketPath } from './cache-service-B108FzER.js';
|
|
2
|
+
import { j as IRemoteSnapshotAdapter, k as CategoryLimit, S as SmartCacheEntry, l as EvictionReason, i as ILogger, m as CacheHit, f as CachePriority, h as WTinyLfuStats$1, n as CacheEncryption, o as CompressionAlgorithm, p as DiskCacheEntry, D as DiskBackpressureStats, q as IRedisDriver, r as IRedisPipeline } from './types-BA4pz1A0.js';
|
|
3
|
+
export { c as CacheHealthStatus, b as CacheMetrics, C as CacheOptions, g as CachePingResult, d as CachePresetType, e as CrossRegionInvalidationEvent, s as CrossRegionRelayOptions, t as CustomCompressor, E as EncryptionMode, u as EnvelopeEncryption, v as EnvelopeEncryptionOptions, H as HttpMeshRelayOptions, w as HttpSnapshotAdapterOptions, x as ICacheBatchObservableCallback, y as ICacheCounter, z as ICacheMeter, A as ICacheObservableGauge, B as ICacheSpan, F as ICacheSpanLink, I as ICacheTracer, G as ICrossRegionRelay, a as InvalidateTagOptions, L as LockOptions, R as RemoteSnapshotOptions, J as WebhookRequestLike, K as WebhookResponseLike, W as WrapOptions, M as consoleLogger, N as createCrossRegionWebhookHandler, O as createCustomCrossRegionRelay, P as createCustomSnapshotAdapter, Q as createHttpMeshRelay, T as createHttpSnapshotAdapter, U as createMemoryCrossRegionRelay, V as createMemorySnapshotAdapter, X as initZstd } from './types-BA4pz1A0.js';
|
|
4
4
|
export { B as BloomFilterStats, M as Murmur3BloomFilter, W as WasmBloomFilter, m as murmur3_32 } from './murmur3-CMGw9PbV.js';
|
|
5
5
|
import { EventEmitter } from 'node:events';
|
|
6
6
|
export { DashboardActionEvent, DashboardOptions, DashboardPeerInstance, StandaloneDashboardOptions, createNextDashboardHandlers, handleDashboardRequest, startDashboardServer, tricacheDashboard } from './dashboard/index.js';
|
|
@@ -203,7 +203,8 @@ declare class SmartMemoryCache {
|
|
|
203
203
|
private maybeRebuildBloom;
|
|
204
204
|
private smartEvict;
|
|
205
205
|
get(key: string): CacheHit | null;
|
|
206
|
-
set(key: string, data: unknown, ttlMs: number, priority?: CachePriority, staleAt?: number, delta?: number, tagVersions?: Record<string, number
|
|
206
|
+
set(key: string, data: unknown, ttlMs: number, priority?: CachePriority, staleAt?: number, delta?: number, tagVersions?: Record<string, number>, setAt?: number, tags?: string[], dependsOn?: string[]): boolean;
|
|
207
|
+
private storePacked;
|
|
207
208
|
delete(key: string): boolean;
|
|
208
209
|
private keysMatchingPattern;
|
|
209
210
|
deletePattern(pattern: string): number;
|
|
@@ -528,6 +529,7 @@ interface WTinyLfuAdmissionDecision {
|
|
|
528
529
|
*/
|
|
529
530
|
declare class WTinyLfuPolicy {
|
|
530
531
|
private readonly sketch;
|
|
532
|
+
private readonly canEvict?;
|
|
531
533
|
private readonly maxTotal;
|
|
532
534
|
private readonly maxWindow;
|
|
533
535
|
private readonly maxProtected;
|
|
@@ -544,7 +546,7 @@ declare class WTinyLfuPolicy {
|
|
|
544
546
|
constructor(capacity: number, sketch: {
|
|
545
547
|
estimate(key: string): number;
|
|
546
548
|
increment(key: string): void;
|
|
547
|
-
}, windowPercent?: number, protectedPercent?: number);
|
|
549
|
+
}, windowPercent?: number, protectedPercent?: number, canEvict?: ((key: string) => boolean) | undefined);
|
|
548
550
|
get windowSize(): number;
|
|
549
551
|
get probationSize(): number;
|
|
550
552
|
get protectedSize(): number;
|
|
@@ -593,6 +595,8 @@ declare class BoundedDiskQueue {
|
|
|
593
595
|
private circuitState;
|
|
594
596
|
private lastStateChangeMonotonic;
|
|
595
597
|
constructor(maxConcurrent?: number, maxPending?: number, writeTimeoutMs?: number, failureThreshold?: number, cooldownMs?: number);
|
|
598
|
+
get isSaturated(): boolean;
|
|
599
|
+
private releaseSlot;
|
|
596
600
|
schedule<T>(task: () => Promise<T>): Promise<T | null>;
|
|
597
601
|
getStats(): DiskBackpressureStats;
|
|
598
602
|
reset(): void;
|
|
@@ -638,6 +642,13 @@ declare class DiskTier {
|
|
|
638
642
|
private diskUsageBytes;
|
|
639
643
|
private usageCounted;
|
|
640
644
|
private fileCount;
|
|
645
|
+
private reservedBytes;
|
|
646
|
+
private reservedFiles;
|
|
647
|
+
private saveSequence;
|
|
648
|
+
private epoch;
|
|
649
|
+
private readonly pendingSaves;
|
|
650
|
+
private closed;
|
|
651
|
+
private readonly invalidatedKeys;
|
|
641
652
|
/** Next bucket index (0–255) for the staggered janitor wheel. */
|
|
642
653
|
private _nextJanitorBucket;
|
|
643
654
|
private _isPruning;
|
|
@@ -688,6 +699,8 @@ declare class DiskTier {
|
|
|
688
699
|
* 12 hex digits ≈ 6 bytes ≈ year 10889 max. Padded so length is always 77 chars.
|
|
689
700
|
*/
|
|
690
701
|
private hashToWritePath;
|
|
702
|
+
private findFilePaths;
|
|
703
|
+
private fileWrittenAt;
|
|
691
704
|
/**
|
|
692
705
|
* Find the on-disk file for a key hash, handling all filename generations:
|
|
693
706
|
* V3 (current): "{hash}_{expiresHex12}" — 77 chars
|
|
@@ -695,6 +708,7 @@ declare class DiskTier {
|
|
|
695
708
|
* Returns null when the bucket dir does not exist or the key is absent.
|
|
696
709
|
*/
|
|
697
710
|
private findFilePath;
|
|
711
|
+
private removeFile;
|
|
698
712
|
/**
|
|
699
713
|
* Recursively list all cache file paths across the 2-level sharded subdirs.
|
|
700
714
|
* Top-level entries that are not directories are skipped (e.g. stale flat
|
|
@@ -734,8 +748,10 @@ declare class DiskTier {
|
|
|
734
748
|
save(key: string, entry: DiskCacheEntry): Promise<void>;
|
|
735
749
|
/** Load a key from disk, or return null on miss/expiry/corruption. */
|
|
736
750
|
load(key: string): DiskCacheEntry | null;
|
|
737
|
-
/**
|
|
738
|
-
|
|
751
|
+
/** Synchronously fence queued/running saves while leaving filesystem cleanup deferred. */
|
|
752
|
+
invalidate(key: string): void;
|
|
753
|
+
/** Delete all versions; deferred cleanup must not cancel a newer save. */
|
|
754
|
+
delete(key: string, invalidatedOnly?: boolean): void;
|
|
739
755
|
/** Purge all expired entries. Returns number deleted. */
|
|
740
756
|
purgeExpired(): number;
|
|
741
757
|
/**
|
|
@@ -803,8 +819,10 @@ declare class DiskTier {
|
|
|
803
819
|
* Universal driver adapter wrapping `@redis/client` (node-redis) to satisfy TriCache's
|
|
804
820
|
* `IRedisDriver` contract without adding runtime dependencies.
|
|
805
821
|
*/
|
|
806
|
-
declare class NodeRedisAdapter implements IRedisDriver {
|
|
822
|
+
declare class NodeRedisAdapter extends EventEmitter implements IRedisDriver {
|
|
807
823
|
readonly client: any;
|
|
824
|
+
private connecting;
|
|
825
|
+
pttl?: (key: string) => Promise<number>;
|
|
808
826
|
constructor(client: any);
|
|
809
827
|
get isOpen(): boolean;
|
|
810
828
|
connect(): Promise<unknown>;
|
|
@@ -824,8 +842,14 @@ declare class NodeRedisAdapter implements IRedisDriver {
|
|
|
824
842
|
sadd(key: string, ...members: string[]): Promise<number>;
|
|
825
843
|
mget(keys: string[]): Promise<(string | null)[]>;
|
|
826
844
|
hset(key: string, value: Record<string, string>): Promise<unknown>;
|
|
845
|
+
hgetall(key: string): Promise<Record<string, string>>;
|
|
827
846
|
publish(channel: string, message: string): Promise<number>;
|
|
828
847
|
subscribe(...channels: string[]): Promise<unknown>;
|
|
848
|
+
unsubscribe(...channels: string[]): Promise<unknown>;
|
|
849
|
+
xread(...args: (string | number)[]): Promise<Array<[string, Array<[string, string[]]>]> | null>;
|
|
850
|
+
xadd(...args: (string | number)[]): Promise<unknown>;
|
|
851
|
+
xrange(...args: (string | number)[]): Promise<Array<[string, string[]]>>;
|
|
852
|
+
xrevrange(...args: (string | number)[]): Promise<Array<[string, string[]]>>;
|
|
829
853
|
scanStream(options?: {
|
|
830
854
|
match?: string;
|
|
831
855
|
count?: number;
|
|
@@ -833,6 +857,7 @@ declare class NodeRedisAdapter implements IRedisDriver {
|
|
|
833
857
|
duplicate(): IRedisDriver;
|
|
834
858
|
on(event: string, listener: (...args: any[]) => void): this;
|
|
835
859
|
once(event: string, listener: (...args: any[]) => void): this;
|
|
860
|
+
removeListener(event: string, listener: (...args: any[]) => void): this;
|
|
836
861
|
}
|
|
837
862
|
/**
|
|
838
863
|
* Creates a pluggable `IRedisDriver` adapter wrapping an existing `@redis/client` instance.
|
|
@@ -856,6 +881,10 @@ interface AutoPipelinerOptions {
|
|
|
856
881
|
/** Whether auto-pipelining is enabled. Default: true */
|
|
857
882
|
enabled?: boolean;
|
|
858
883
|
}
|
|
884
|
+
interface TimedRedisValue {
|
|
885
|
+
raw: string | Record<string, string> | null;
|
|
886
|
+
ttlMs?: number;
|
|
887
|
+
}
|
|
859
888
|
/**
|
|
860
889
|
* AutoPipeliner — Microtask-coalesced Redis request batching.
|
|
861
890
|
*
|
|
@@ -880,11 +909,14 @@ declare class AutoPipeliner {
|
|
|
880
909
|
pendingQueueSize: number;
|
|
881
910
|
};
|
|
882
911
|
get(key: string): Promise<string | null>;
|
|
912
|
+
read(key: string, hash?: boolean): Promise<TimedRedisValue>;
|
|
883
913
|
setex(key: string, seconds: number, value: string): Promise<void>;
|
|
914
|
+
setpx(key: string, milliseconds: number, value: string): Promise<void>;
|
|
884
915
|
del(...keys: string[]): Promise<number>;
|
|
885
916
|
private supportsPipelines;
|
|
886
917
|
private enqueue;
|
|
887
918
|
flush(): Promise<void>;
|
|
919
|
+
private dispatch;
|
|
888
920
|
}
|
|
889
921
|
|
|
890
922
|
/** Default safety ceiling for autonomous L1 memory allocations: 512 MB */
|
package/dist/index.js
CHANGED
|
@@ -1,12 +1,8 @@
|
|
|
1
1
|
import {
|
|
2
2
|
NodeRedisAdapter,
|
|
3
3
|
SigV4SnapshotAdapter,
|
|
4
|
-
createCrossRegionWebhookHandler,
|
|
5
|
-
createCustomCrossRegionRelay,
|
|
6
4
|
createCustomSnapshotAdapter,
|
|
7
|
-
createHttpMeshRelay,
|
|
8
5
|
createHttpSnapshotAdapter,
|
|
9
|
-
createMemoryCrossRegionRelay,
|
|
10
6
|
createMemorySnapshotAdapter,
|
|
11
7
|
createNodeRedisAdapter,
|
|
12
8
|
createR2SnapshotAdapter,
|
|
@@ -14,7 +10,7 @@ import {
|
|
|
14
10
|
createSigV4SnapshotAdapter,
|
|
15
11
|
formatTraceParent,
|
|
16
12
|
parseTraceParent
|
|
17
|
-
} from "./chunk-
|
|
13
|
+
} from "./chunk-VNRDL5RA.js";
|
|
18
14
|
import {
|
|
19
15
|
AutoPipeliner,
|
|
20
16
|
CacheCodec,
|
|
@@ -30,6 +26,10 @@ import {
|
|
|
30
26
|
TinyLfuSketch,
|
|
31
27
|
WTinyLfuCache,
|
|
32
28
|
WTinyLfuPolicy,
|
|
29
|
+
createCrossRegionWebhookHandler,
|
|
30
|
+
createCustomCrossRegionRelay,
|
|
31
|
+
createHttpMeshRelay,
|
|
32
|
+
createMemoryCrossRegionRelay,
|
|
33
33
|
deepMergeOptions,
|
|
34
34
|
defaultCodec,
|
|
35
35
|
findActiveSockets,
|
|
@@ -43,7 +43,7 @@ import {
|
|
|
43
43
|
resolveAutonomousL1MaxBytes,
|
|
44
44
|
resolveDefaultDiskDir,
|
|
45
45
|
resolveIpcSocketPath
|
|
46
|
-
} from "./chunk-
|
|
46
|
+
} from "./chunk-WYF7NOAT.js";
|
|
47
47
|
import {
|
|
48
48
|
CacheEncryption,
|
|
49
49
|
CachePriority,
|
|
@@ -56,7 +56,7 @@ import {
|
|
|
56
56
|
handleDashboardRequest,
|
|
57
57
|
startDashboardServer,
|
|
58
58
|
tricacheDashboard
|
|
59
|
-
} from "./chunk-
|
|
59
|
+
} from "./chunk-JNSLMK4Q.js";
|
|
60
60
|
import {
|
|
61
61
|
Murmur3BloomFilter,
|
|
62
62
|
murmur3_32
|
|
@@ -67,7 +67,7 @@ import {
|
|
|
67
67
|
isChildTag,
|
|
68
68
|
isWildcardTag,
|
|
69
69
|
matchesTagPattern
|
|
70
|
-
} from "./chunk-
|
|
70
|
+
} from "./chunk-H4GFLQ26.js";
|
|
71
71
|
export {
|
|
72
72
|
AutoPipeliner,
|
|
73
73
|
CacheCodec,
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
declare class WasmBloomFilter {
|
|
2
|
+
private readonly exports;
|
|
3
|
+
private readonly mem;
|
|
4
|
+
private readonly stagingTarget;
|
|
5
|
+
private readonly encoder;
|
|
6
|
+
private readonly numBits;
|
|
7
|
+
/** Pre-computed — k and numBits are fixed constants; no need to recalculate on every probe. */
|
|
8
|
+
private readonly _maxCapacity;
|
|
9
|
+
/** Tracks total add() calls so we know when phantom bits have saturated the filter. */
|
|
10
|
+
private _insertionCount;
|
|
11
|
+
constructor();
|
|
12
|
+
private writeKey;
|
|
13
|
+
add(key: string): void;
|
|
14
|
+
mightContain(key: string): boolean;
|
|
15
|
+
reset(): void;
|
|
16
|
+
rebuild(keys: Iterable<string>): void;
|
|
17
|
+
get stats(): {
|
|
18
|
+
bitsSet: number;
|
|
19
|
+
fillFactor: number;
|
|
20
|
+
};
|
|
21
|
+
/** Number of add() calls since last reset/rebuild. */
|
|
22
|
+
get insertions(): number;
|
|
23
|
+
/**
|
|
24
|
+
* Maximum safe insertions before false-positive rate exceeds ~1 %.
|
|
25
|
+
* Exact formula for k=7 hash rounds, m=100 000 bits, p=1%:
|
|
26
|
+
* n_max = -m * ln(1 - p^(1/k)) / k ≈ 10 434
|
|
27
|
+
*/
|
|
28
|
+
get maxCapacity(): number;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Standard 32-bit MurmurHash3 (x86_32) implementation.
|
|
33
|
+
* Pure TypeScript, zero external dependencies, zero Node.js Buffer dependencies.
|
|
34
|
+
*
|
|
35
|
+
* Fully compatible with V8 Edge Isolates (Cloudflare Workers, Fastly Compute,
|
|
36
|
+
* Vercel Edge, Deno, Bun, and modern browsers).
|
|
37
|
+
*/
|
|
38
|
+
/**
|
|
39
|
+
* Computes the 32-bit MurmurHash3 of a string with an optional seed.
|
|
40
|
+
* Uses 32-bit unsigned arithmetic (>>> 0).
|
|
41
|
+
*/
|
|
42
|
+
declare function murmur3_32(key: string, seed?: number): number;
|
|
43
|
+
interface BloomFilterStats {
|
|
44
|
+
bitsSet: number;
|
|
45
|
+
fillFactor: number;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Pure TypeScript Bloom filter backed by a Uint8Array bitset.
|
|
49
|
+
* Uses Murmur3 double-hashing (Kirsch-Mitzenmacher technique):
|
|
50
|
+
* h_i(x) = (h1(x) + i * h2(x)) % m
|
|
51
|
+
*
|
|
52
|
+
* Zero Buffer dependency — runs identically in Node.js, Edge Isolates, and Browsers.
|
|
53
|
+
*/
|
|
54
|
+
declare class Murmur3BloomFilter {
|
|
55
|
+
private readonly bits;
|
|
56
|
+
readonly numBits: number;
|
|
57
|
+
readonly k: number;
|
|
58
|
+
private readonly _maxCapacity;
|
|
59
|
+
private _insertionCount;
|
|
60
|
+
/**
|
|
61
|
+
* @param numBits Total bits in the filter (default: 100,000 bits = 12.5 KB)
|
|
62
|
+
* @param k Number of hash probes per key (default: 7, targeting ~1% FPR at 2,000 items)
|
|
63
|
+
*/
|
|
64
|
+
constructor(numBits?: number, k?: number);
|
|
65
|
+
private setBit;
|
|
66
|
+
private getBit;
|
|
67
|
+
/**
|
|
68
|
+
* Adds a key to the Bloom filter.
|
|
69
|
+
*/
|
|
70
|
+
add(key: string): void;
|
|
71
|
+
/**
|
|
72
|
+
* Tests whether a key might be in the set.
|
|
73
|
+
* Returns `false` for guaranteed misses, `true` for possible hits.
|
|
74
|
+
*/
|
|
75
|
+
mightContain(key: string): boolean;
|
|
76
|
+
/**
|
|
77
|
+
* Clears all set bits in the filter.
|
|
78
|
+
*/
|
|
79
|
+
reset(): void;
|
|
80
|
+
/**
|
|
81
|
+
* Rebuilds the filter from a collection of keys.
|
|
82
|
+
*/
|
|
83
|
+
rebuild(keys: Iterable<string>): void;
|
|
84
|
+
/**
|
|
85
|
+
* Total add() calls since creation or last reset.
|
|
86
|
+
*/
|
|
87
|
+
get insertions(): number;
|
|
88
|
+
/**
|
|
89
|
+
* Maximum safe insertions before false positive rate exceeds target ~1%.
|
|
90
|
+
*/
|
|
91
|
+
get maxCapacity(): number;
|
|
92
|
+
/**
|
|
93
|
+
* Returns current bit saturation metrics.
|
|
94
|
+
*/
|
|
95
|
+
get stats(): BloomFilterStats;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
export { type BloomFilterStats as B, Murmur3BloomFilter as M, WasmBloomFilter as W, murmur3_32 as m };
|