@postgresx/noredis 0.10.0 → 0.12.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.
Files changed (44) hide show
  1. package/README.md +5 -0
  2. package/dist/adapters/bun.d.ts +5 -8
  3. package/dist/adapters/ioredis.d.ts +12 -15
  4. package/dist/adapters/ioredis.js +8 -1
  5. package/dist/adapters/node.d.ts +11 -13
  6. package/dist/adapters/redis.d.ts +12 -15
  7. package/dist/adapters/redis.js +8 -1
  8. package/dist/adapters/web.d.ts +11 -16
  9. package/dist/advisory-lock.d.ts +24 -0
  10. package/dist/{chunk-WRMEEA6T.js → chunk-6PU53SX7.js} +16 -2
  11. package/dist/{chunk-HW3WONAC.js → chunk-JRMUZTI4.js} +128 -15
  12. package/dist/{chunk-YSWHEFPX.js → chunk-LN56Y4FI.js} +68 -0
  13. package/dist/{chunk-7T5O55TM.js → chunk-QIWUTOLC.js} +50 -15
  14. package/dist/client.d.ts +70 -0
  15. package/dist/counter.d.ts +27 -0
  16. package/dist/errors.d.ts +5 -0
  17. package/dist/hash-index.d.ts +1 -43
  18. package/dist/hash.d.ts +40 -0
  19. package/dist/index.d.ts +17 -16
  20. package/dist/index.js +4 -4
  21. package/dist/kv-cache.d.ts +36 -20
  22. package/dist/kv-cache.js +1 -1
  23. package/dist/kv.d.ts +1 -3
  24. package/dist/kv.js +1 -1
  25. package/dist/list-index.d.ts +1 -53
  26. package/dist/list-index.js +1 -1
  27. package/dist/list.d.ts +74 -0
  28. package/dist/metrics.d.ts +48 -0
  29. package/dist/pipeline.d.ts +14 -0
  30. package/dist/pubsub-index.d.ts +1 -60
  31. package/dist/pubsub.d.ts +57 -0
  32. package/dist/queue.d.ts +50 -0
  33. package/dist/rate-limit.d.ts +108 -0
  34. package/dist/redis-aliases.d.ts +129 -0
  35. package/dist/set-index.d.ts +1 -42
  36. package/dist/set.d.ts +39 -0
  37. package/dist/sorted-set-index.d.ts +1 -58
  38. package/dist/sorted-set-index.js +1 -1
  39. package/dist/sorted-set.d.ts +73 -0
  40. package/dist/sql.d.ts +8 -0
  41. package/dist/stream.d.ts +59 -0
  42. package/package.json +4 -4
  43. package/dist/client-ChVkyyno.d.ts +0 -513
  44. package/dist/sql-DKf2TDlu.d.ts +0 -10
@@ -4,6 +4,15 @@ var DEFAULT_NAMESPACE = "default";
4
4
  var DEFAULT_L1_MAX = 1e4;
5
5
  var DEFAULT_L1_TTL_MS = 6e4;
6
6
  var DEFAULT_NOTIFY_CHANNEL = "pg_kv_cache_invalidate";
7
+ var textEncoder = new TextEncoder();
8
+ function estimateValueBytes(value) {
9
+ try {
10
+ const json = JSON.stringify(value);
11
+ return json === void 0 ? 0 : textEncoder.encode(json).length;
12
+ } catch {
13
+ return 0;
14
+ }
15
+ }
7
16
  function randomId() {
8
17
  const cryptoApi = globalThis.crypto;
9
18
  if (cryptoApi?.randomUUID) return cryptoApi.randomUUID();
@@ -78,6 +87,8 @@ var PgKvCache = class {
78
87
  l1Max;
79
88
  l1TtlMs;
80
89
  l1NegativeTtlMs;
90
+ l1MaxBytes;
91
+ l1MaxEntryBytes;
81
92
  notifyEnabled;
82
93
  serializer;
83
94
  singleflight;
@@ -88,6 +99,7 @@ var PgKvCache = class {
88
99
  l1Misses = 0;
89
100
  l1NegativeHits = 0;
90
101
  l1Paused = false;
102
+ l1Bytes = 0;
91
103
  coalescedReads = 0;
92
104
  invalidationListener = null;
93
105
  invalidationUnsubscribers = [];
@@ -102,6 +114,8 @@ var PgKvCache = class {
102
114
  this.l1Max = options.l1 && options.l1.max !== void 0 ? options.l1.max : DEFAULT_L1_MAX;
103
115
  this.l1TtlMs = options.l1 && options.l1.ttlMs !== void 0 ? options.l1.ttlMs : DEFAULT_L1_TTL_MS;
104
116
  this.l1NegativeTtlMs = options.l1 && options.l1.negativeTtlMs !== void 0 && options.l1.negativeTtlMs > 0 ? options.l1.negativeTtlMs : 0;
117
+ this.l1MaxBytes = options.l1 && options.l1.maxBytes !== void 0 && options.l1.maxBytes > 0 ? options.l1.maxBytes : 0;
118
+ this.l1MaxEntryBytes = options.l1 && options.l1.maxEntryBytes !== void 0 && options.l1.maxEntryBytes > 0 ? options.l1.maxEntryBytes : 0;
105
119
  this.notifyEnabled = options.notify !== false && options.notify?.enabled !== false;
106
120
  this.notifyChannel = options.notify && options.notify.channel ? options.notify.channel : DEFAULT_NOTIFY_CHANNEL;
107
121
  this.serializer = options.serializer ?? {
@@ -446,7 +460,7 @@ var PgKvCache = class {
446
460
  }
447
461
  invalidateAll() {
448
462
  this.l1Generation += 1;
449
- this.l1.clear();
463
+ this.clearL1();
450
464
  }
451
465
  startInvalidationListener(factory, options = {}) {
452
466
  this.stopInvalidationListener();
@@ -488,13 +502,17 @@ var PgKvCache = class {
488
502
  pauseL1() {
489
503
  this.l1Paused = true;
490
504
  this.l1Generation += 1;
491
- this.l1.clear();
505
+ this.clearL1();
492
506
  }
493
507
  resumeL1() {
494
508
  this.l1Generation += 1;
495
- this.l1.clear();
509
+ this.clearL1();
496
510
  this.l1Paused = false;
497
511
  }
512
+ clearL1() {
513
+ this.l1.clear();
514
+ this.l1Bytes = 0;
515
+ }
498
516
  handleNotification(payload) {
499
517
  const event = typeof payload === "string" ? this.parseNotification(payload) : payload;
500
518
  if (!event || event.namespace !== this.namespace || event.senderId === this.instanceId) return false;
@@ -506,7 +524,7 @@ var PgKvCache = class {
506
524
  if (!event.prefix) return false;
507
525
  this.l1Generation += 1;
508
526
  for (const key of this.l1.keys()) {
509
- if (key.startsWith(event.prefix)) this.l1.delete(key);
527
+ if (key.startsWith(event.prefix)) this.removeEntry(key);
510
528
  }
511
529
  return true;
512
530
  }
@@ -659,7 +677,9 @@ var PgKvCache = class {
659
677
  l1NegativeHits: this.l1NegativeHits,
660
678
  l1Paused: this.l1Paused,
661
679
  inflightReads: this.inflight.size,
662
- coalescedReads: this.coalescedReads
680
+ coalescedReads: this.coalescedReads,
681
+ l1Bytes: this.l1Bytes,
682
+ l1MaxBytes: this.l1MaxBytes
663
683
  };
664
684
  }
665
685
  async publish(event) {
@@ -717,7 +737,7 @@ var PgKvCache = class {
717
737
  return { hit: false };
718
738
  }
719
739
  if (entry.expiresAt !== null && entry.expiresAt <= this.now()) {
720
- this.l1.delete(key);
740
+ this.removeEntry(key);
721
741
  this.l1Misses += 1;
722
742
  return { hit: false };
723
743
  }
@@ -730,12 +750,21 @@ var PgKvCache = class {
730
750
  this.l1.set(key, entry);
731
751
  return { hit: true, value: entry.value };
732
752
  }
753
+ removeEntry(key) {
754
+ const entry = this.l1.get(key);
755
+ if (!entry) return;
756
+ this.l1.delete(key);
757
+ this.l1Bytes -= entry.bytes ?? 0;
758
+ }
759
+ tracksBytes() {
760
+ return this.l1MaxBytes > 0 || this.l1MaxEntryBytes > 0;
761
+ }
733
762
  setNegativeL1(key, generation = this.l1Generation) {
734
763
  if (!this.l1Enabled || this.l1Paused || this.l1Max <= 0 || this.l1NegativeTtlMs <= 0) return;
735
764
  if (generation !== this.l1Generation) return;
736
765
  const expiresAt = this.now() + this.l1NegativeTtlMs;
737
- this.l1.delete(key);
738
- this.l1.set(key, { value: null, expiresAt, negative: true });
766
+ this.removeEntry(key);
767
+ this.l1.set(key, { value: null, expiresAt, negative: true, bytes: 0 });
739
768
  this.enforceL1Max();
740
769
  }
741
770
  setL1(key, value, l2ExpiresAt, generation = this.l1Generation) {
@@ -743,11 +772,17 @@ var PgKvCache = class {
743
772
  if (generation !== this.l1Generation) return;
744
773
  const l1ExpiresAt = this.computeL1ExpiresAt(l2ExpiresAt);
745
774
  if (l1ExpiresAt !== null && l1ExpiresAt <= this.now()) {
746
- this.l1.delete(key);
775
+ this.removeEntry(key);
747
776
  return;
748
777
  }
749
- this.l1.delete(key);
750
- this.l1.set(key, { value, expiresAt: l1ExpiresAt });
778
+ const bytes = this.tracksBytes() ? estimateValueBytes(value) : 0;
779
+ if (this.l1MaxEntryBytes > 0 && bytes > this.l1MaxEntryBytes) {
780
+ this.removeEntry(key);
781
+ return;
782
+ }
783
+ this.removeEntry(key);
784
+ this.l1.set(key, { value, expiresAt: l1ExpiresAt, bytes });
785
+ this.l1Bytes += bytes;
751
786
  this.enforceL1Max();
752
787
  }
753
788
  computeL1ExpiresAt(l2ExpiresAt) {
@@ -759,20 +794,20 @@ var PgKvCache = class {
759
794
  deleteL1(key) {
760
795
  if (!this.l1Enabled) return;
761
796
  this.l1Generation += 1;
762
- this.l1.delete(key);
797
+ this.removeEntry(key);
763
798
  }
764
799
  cleanupL1() {
765
800
  if (!this.l1Enabled) return;
766
801
  const now = this.now();
767
802
  for (const [key, entry] of this.l1.entries()) {
768
- if (entry.expiresAt !== null && entry.expiresAt <= now) this.l1.delete(key);
803
+ if (entry.expiresAt !== null && entry.expiresAt <= now) this.removeEntry(key);
769
804
  }
770
805
  }
771
806
  enforceL1Max() {
772
- while (this.l1.size > this.l1Max) {
807
+ while (this.l1.size > this.l1Max || this.l1MaxBytes > 0 && this.l1Bytes > this.l1MaxBytes) {
773
808
  const oldest = this.l1.keys().next();
774
809
  if (oldest.done) return;
775
- this.l1.delete(oldest.value);
810
+ this.removeEntry(oldest.value);
776
811
  }
777
812
  }
778
813
  };
@@ -0,0 +1,70 @@
1
+ import { type PgKvCache, type PgKvCacheOptions } from "./kv-cache.js";
2
+ import { type PgAdvisoryLocker } from "./advisory-lock.js";
3
+ import { type PgCounter } from "./counter.js";
4
+ import { type PgHash } from "./hash.js";
5
+ import { type PgList } from "./list.js";
6
+ import { type PgredisCleanupMetrics, type PgredisMetrics } from "./metrics.js";
7
+ import { PgredisPipeline, type PgredisBatchOperation } from "./pipeline.js";
8
+ import { type PgPublisher } from "./pubsub.js";
9
+ import { type PgBossJobQueue, type PgBossQueueOptions, type QueueResult } from "./queue.js";
10
+ import { type PgFixedWindowRateLimiter } from "./rate-limit.js";
11
+ import { type PgredisMigrationAliases } from "./redis-aliases.js";
12
+ import { type PgSet } from "./set.js";
13
+ import { type PgSortedSet } from "./sorted-set.js";
14
+ import type { PgSqlLike } from "./sql.js";
15
+ import { type PgOutboxStream } from "./stream.js";
16
+ export interface PgredisOptions {
17
+ sql: PgSqlLike;
18
+ namespace?: string;
19
+ tablePrefix?: string;
20
+ cache?: Omit<PgKvCacheOptions, "sql" | "namespace" | "tableName"> & {
21
+ tableName?: string;
22
+ };
23
+ rateLimit?: {
24
+ limit: number;
25
+ windowMs: number;
26
+ tableName?: string;
27
+ };
28
+ queue?: PgBossQueueOptions | string;
29
+ outbox?: {
30
+ tableName?: string;
31
+ };
32
+ }
33
+ export interface PgredisSchemaOptions {
34
+ /** Controls cache-style primitives; the durable outbox always remains logged. */
35
+ unlogged?: boolean;
36
+ }
37
+ export interface PgredisClient {
38
+ cache: PgKvCache;
39
+ counter: PgCounter;
40
+ hash: PgHash;
41
+ set: PgSet;
42
+ list: PgList;
43
+ sortedSet: PgSortedSet;
44
+ locks: PgAdvisoryLocker;
45
+ pubsub: PgPublisher;
46
+ rateLimit?: PgFixedWindowRateLimiter;
47
+ queue?: PgBossJobQueue;
48
+ outbox: PgOutboxStream;
49
+ stream: PgOutboxStream;
50
+ redis: PgredisMigrationAliases;
51
+ batch<T>(operation: PgredisBatchOperation<T>): Promise<T>;
52
+ pipeline(): PgredisPipeline;
53
+ health(): Promise<{
54
+ ok: true;
55
+ }>;
56
+ stats(): Promise<{
57
+ cache: ReturnType<PgKvCache["stats"]>;
58
+ queue?: QueueResult[];
59
+ cleanup: PgredisCleanupMetrics;
60
+ }>;
61
+ metrics(): Promise<PgredisMetrics>;
62
+ cleanupExpired(limit?: number): Promise<Record<string, number>>;
63
+ startCleanupWorker(options?: {
64
+ intervalMs?: number;
65
+ limit?: number;
66
+ onError?: (error: unknown) => void;
67
+ }): () => void;
68
+ ensureSchema(options?: PgredisSchemaOptions): Promise<void>;
69
+ }
70
+ export declare function createPgredis(options: PgredisOptions): PgredisClient;
@@ -0,0 +1,27 @@
1
+ import { type PgSqlLike } from "./sql.js";
2
+ export interface PgCounterOptions {
3
+ sql: PgSqlLike;
4
+ namespace?: string;
5
+ tableName?: string;
6
+ }
7
+ export interface PgCounterSetOptions {
8
+ ttlMs?: number | null;
9
+ }
10
+ export interface PgCounterSchemaOptions {
11
+ unlogged?: boolean;
12
+ }
13
+ export declare class PgCounter {
14
+ readonly namespace: string;
15
+ readonly tableName: string;
16
+ readonly quotedTableName: string;
17
+ private readonly sql;
18
+ constructor(options: PgCounterOptions);
19
+ ensureSchema(options?: PgCounterSchemaOptions): Promise<void>;
20
+ get(key: string): Promise<number | null>;
21
+ set(key: string, value: number, options?: PgCounterSetOptions): Promise<number>;
22
+ incr(key: string, amount?: number, options?: PgCounterSetOptions): Promise<number>;
23
+ decr(key: string, amount?: number, options?: PgCounterSetOptions): Promise<number>;
24
+ delete(key: string): Promise<boolean>;
25
+ cleanupExpired(limit?: number): Promise<number>;
26
+ }
27
+ export declare function createPgCounter(options: PgCounterOptions): PgCounter;
@@ -0,0 +1,5 @@
1
+ /** 不支持命令时抛出的标准错误 */
2
+ export declare class UnsupportedCommandError extends Error {
3
+ readonly command: string;
4
+ constructor(command: string);
5
+ }
@@ -1,43 +1 @@
1
- import { P as PgSqlLike } from './sql-DKf2TDlu.js';
2
-
3
- interface PgHashOptions {
4
- sql: PgSqlLike;
5
- namespace?: string;
6
- tableName?: string;
7
- }
8
- interface PgHashSchemaOptions {
9
- unlogged?: boolean;
10
- }
11
- interface PgHashScanResult<T = unknown> {
12
- cursor: string | null;
13
- entries: Array<readonly [string, T]>;
14
- }
15
- declare class PgHash {
16
- readonly namespace: string;
17
- readonly tableName: string;
18
- readonly quotedTableName: string;
19
- private readonly sql;
20
- constructor(options: PgHashOptions);
21
- ensureSchema(options?: PgHashSchemaOptions): Promise<void>;
22
- hget<T = unknown>(key: string, field: string): Promise<T | null>;
23
- hset<T = unknown>(key: string, field: string, value: T): Promise<void>;
24
- hmset<T = unknown>(key: string, entries: Iterable<readonly [string, T]>): Promise<void>;
25
- hgetall<T = unknown>(key: string): Promise<Record<string, T>>;
26
- hdel(key: string, field: string): Promise<boolean>;
27
- hclear(key: string): Promise<number>;
28
- hexists(key: string, field: string): Promise<boolean>;
29
- hlen(key: string): Promise<number>;
30
- hincrby(key: string, field: string, amount?: number): Promise<number>;
31
- hscan<T = unknown>(key: string, cursor?: string | null, count?: number): Promise<PgHashScanResult<T>>;
32
- expire(key: string, ttlMs: number): Promise<number>;
33
- persist(key: string): Promise<number>;
34
- ttl(key: string): Promise<number | null>;
35
- hmget<T = unknown>(key: string, ...fields: string[]): Promise<Array<T | null>>;
36
- hkeys(key: string): Promise<string[]>;
37
- hvals<T = unknown>(key: string): Promise<T[]>;
38
- hstrlen(key: string, field: string): Promise<number>;
39
- cleanupExpired(limit?: number): Promise<number>;
40
- }
41
- declare function createPgHash(options: PgHashOptions): PgHash;
42
-
43
- export { PgHash, type PgHashOptions, type PgHashScanResult, type PgHashSchemaOptions, createPgHash };
1
+ export { createPgHash, PgHash, type PgHashOptions, type PgHashSchemaOptions, type PgHashScanResult } from "./hash.js";
package/dist/hash.d.ts ADDED
@@ -0,0 +1,40 @@
1
+ import { type PgSqlLike } from "./sql.js";
2
+ export interface PgHashOptions {
3
+ sql: PgSqlLike;
4
+ namespace?: string;
5
+ tableName?: string;
6
+ }
7
+ export interface PgHashSchemaOptions {
8
+ unlogged?: boolean;
9
+ }
10
+ export interface PgHashScanResult<T = unknown> {
11
+ cursor: string | null;
12
+ entries: Array<readonly [string, T]>;
13
+ }
14
+ export declare class PgHash {
15
+ readonly namespace: string;
16
+ readonly tableName: string;
17
+ readonly quotedTableName: string;
18
+ private readonly sql;
19
+ constructor(options: PgHashOptions);
20
+ ensureSchema(options?: PgHashSchemaOptions): Promise<void>;
21
+ hget<T = unknown>(key: string, field: string): Promise<T | null>;
22
+ hset<T = unknown>(key: string, field: string, value: T): Promise<void>;
23
+ hmset<T = unknown>(key: string, entries: Iterable<readonly [string, T]>): Promise<void>;
24
+ hgetall<T = unknown>(key: string): Promise<Record<string, T>>;
25
+ hdel(key: string, field: string): Promise<boolean>;
26
+ hclear(key: string): Promise<number>;
27
+ hexists(key: string, field: string): Promise<boolean>;
28
+ hlen(key: string): Promise<number>;
29
+ hincrby(key: string, field: string, amount?: number): Promise<number>;
30
+ hscan<T = unknown>(key: string, cursor?: string | null, count?: number): Promise<PgHashScanResult<T>>;
31
+ expire(key: string, ttlMs: number): Promise<number>;
32
+ persist(key: string): Promise<number>;
33
+ ttl(key: string): Promise<number | null>;
34
+ hmget<T = unknown>(key: string, ...fields: string[]): Promise<Array<T | null>>;
35
+ hkeys(key: string): Promise<string[]>;
36
+ hvals<T = unknown>(key: string): Promise<T[]>;
37
+ hstrlen(key: string, field: string): Promise<number>;
38
+ cleanupExpired(limit?: number): Promise<number>;
39
+ }
40
+ export declare function createPgHash(options: PgHashOptions): PgHash;
package/dist/index.d.ts CHANGED
@@ -1,16 +1,17 @@
1
- export { BunSqlLike, PgKvCache, PgKvCacheInvalidationOptions, PgKvCacheL1Options, PgKvCacheListenerFactory, PgKvCacheListenerFactoryOptions, PgKvCacheNotifyOptions, PgKvCacheOptions, PgKvCacheStats, PgKvNotification, PgKvSchemaOptions, PgKvSetOptions, createPgKvCache } from './kv-cache.js';
2
- export { d as Job, P as PgAdvisoryLockBusyError, a as PgAdvisoryLockKey, b as PgAdvisoryLockOptions, c as PgAdvisoryLocker, f as PgBoss, d as PgBossJob, e as PgBossJobQueue, f as PgBossLike, g as PgBossOptions, h as PgBossQueueDefinition, i as PgBossQueueMap, j as PgBossQueueOptions, k as PgBossQueueResult, l as PgBossSendOptions, m as PgBossWorkHandler, n as PgBossWorkOptions, o as PgCounter, p as PgCounterOptions, q as PgCounterSchemaOptions, r as PgCounterSetOptions, s as PgFixedWindowRateLimiter, t as PgOutboxAppendOptions, u as PgOutboxClaimOptions, v as PgOutboxMessage, w as PgOutboxPendingSummary, x as PgOutboxReadOptions, y as PgOutboxStream, z as PgOutboxStreamOptions, A as PgOutboxStreamSchemaOptions, B as PgOutboxTrimOptions, C as PgRateLimitBlockOptions, D as PgRateLimitHitOptions, E as PgRateLimitResult, F as PgRateLimitSchemaOptions, G as PgRateLimitStateOptions, H as PgRateLimiterOptions, I as PgSlidingWindowRateLimiter, J as PgSlidingWindowRateLimiterOptions, K as PgTokenBucketRateLimiter, L as PgTokenBucketRateLimiterOptions, M as PgTokenBucketResult, N as PgredisBatchOperation, O as PgredisCleanupMetrics, Q as PgredisClient, R as PgredisListenerMetrics, S as PgredisMetrics, T as PgredisMetricsOptions, U as PgredisMigrationAliases, V as PgredisOptions, W as PgredisPipeline, X as PgredisQueueMetrics, Y as PgredisSchemaOptions, Z as PgredisTableMetrics, _ as PipelineCommand, $ as PipelineFacade, h as Queue, k as QueueResult, a0 as RedisSetAliasOptions, l as SendOptions, m as WorkHandler, n as WorkOptions, a1 as advisoryLockKeyToSqlArgs, a2 as collectPgredisMetrics, a3 as createPgAdvisoryLocker, a4 as createPgBossJobQueue, a5 as createPgCounter, a6 as createPgFixedWindowRateLimiter, a7 as createPgOutboxStream, a8 as createPgSlidingWindowRateLimiter, a9 as createPgTokenBucketRateLimiter, aa as createPgredis, ab as createPgredisMigrationAliases, ac as withPgAdvisoryLock } from './client-ChVkyyno.js';
3
- export { PgHash, PgHashOptions, PgHashScanResult, PgHashSchemaOptions, createPgHash } from './hash-index.js';
4
- export { PgList, PgListBlockingPopOptions, PgListBlockingPopResult, PgListOptions, PgListScanResult, PgListSchemaOptions, createPgList } from './list-index.js';
5
- export { NotifyHandler, PgListenerEvents, PgListenerHandle, PgListenerHealth, PgListenerOptions, PgNotifyPayload, PgPublisher, createBunPgListener, createPgListener, createPgPublisher, publishPgNotify } from './pubsub-index.js';
6
- export { PgSet, PgSetOptions, PgSetScanResult, PgSetSchemaOptions, createPgSet } from './set-index.js';
7
- export { P as PgSqlLike, i as indexName, n as normalizePositiveInteger, q as quoteIdentifier, a as quoteQualifiedName } from './sql-DKf2TDlu.js';
8
- export { PgSortedSet, PgSortedSetMember, PgSortedSetOptions, PgSortedSetScanResult, PgSortedSetSchemaOptions, createPgSortedSet } from './sorted-set-index.js';
9
-
10
- /** 不支持命令时抛出的标准错误 */
11
- declare class UnsupportedCommandError extends Error {
12
- readonly command: string;
13
- constructor(command: string);
14
- }
15
-
16
- export { UnsupportedCommandError };
1
+ export { createPgKvCache, PgKvCache, type BunSqlLike, type PgKvCacheInvalidationOptions, type PgKvCacheL1Options, type PgKvCacheListenerFactory, type PgKvCacheListenerFactoryOptions, type PgKvCacheNotifyOptions, type PgKvCacheOptions, type PgKvCacheStats, type PgKvNotification, type PgKvSchemaOptions, type PgKvSetOptions } from "./kv-cache.js";
2
+ export * from "./advisory-lock.js";
3
+ export * from "./client.js";
4
+ export * from "./counter.js";
5
+ export * from "./hash.js";
6
+ export * from "./list.js";
7
+ export * from "./metrics.js";
8
+ export * from "./pipeline.js";
9
+ export * from "./pubsub.js";
10
+ export * from "./queue.js";
11
+ export * from "./rate-limit.js";
12
+ export * from "./redis-aliases.js";
13
+ export * from "./set.js";
14
+ export * from "./sql.js";
15
+ export * from "./sorted-set.js";
16
+ export * from "./stream.js";
17
+ export * from "./errors.js";
package/dist/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  UnsupportedCommandError,
3
3
  createPgredisMigrationAliases
4
- } from "./chunk-WRMEEA6T.js";
4
+ } from "./chunk-6PU53SX7.js";
5
5
  import {
6
6
  PgHash,
7
7
  createPgHash
@@ -9,11 +9,11 @@ import {
9
9
  import {
10
10
  PgKvCache,
11
11
  createPgKvCache
12
- } from "./chunk-7T5O55TM.js";
12
+ } from "./chunk-QIWUTOLC.js";
13
13
  import {
14
14
  PgList,
15
15
  createPgList
16
- } from "./chunk-HW3WONAC.js";
16
+ } from "./chunk-JRMUZTI4.js";
17
17
  import {
18
18
  createBunPgListener,
19
19
  createPgListener,
@@ -27,7 +27,7 @@ import {
27
27
  import {
28
28
  PgSortedSet,
29
29
  createPgSortedSet
30
- } from "./chunk-YSWHEFPX.js";
30
+ } from "./chunk-LN56Y4FI.js";
31
31
  import {
32
32
  indexName,
33
33
  normalizePositiveInteger,
@@ -1,11 +1,9 @@
1
- import { NotifyHandler, PgListenerHandle } from './pubsub-index.js';
2
- import './sql-DKf2TDlu.js';
3
-
4
- interface BunSqlLike {
1
+ import type { NotifyHandler, PgListenerHandle } from "./pubsub.js";
2
+ export interface BunSqlLike {
5
3
  unsafe<T = Record<string, unknown>>(query: string, params?: readonly unknown[]): Promise<T[]>;
6
4
  begin?<T>(callback: (tx: BunSqlLike) => Promise<T>): Promise<T>;
7
5
  }
8
- interface PgKvCacheL1Options {
6
+ export interface PgKvCacheL1Options {
9
7
  max?: number;
10
8
  ttlMs?: number;
11
9
  /**
@@ -15,8 +13,18 @@ interface PgKvCacheL1Options {
15
13
  * set/delete notification clears the entry immediately.
16
14
  */
17
15
  negativeTtlMs?: number;
16
+ /**
17
+ * Evict least-recently-used entries once the approximate cache size exceeds
18
+ * this many bytes. Defaults to 0 (no byte cap; only `max` entries apply).
19
+ */
20
+ maxBytes?: number;
21
+ /**
22
+ * Refuse to cache any single value larger than this many bytes. Defaults to
23
+ * 0 (no per-value limit).
24
+ */
25
+ maxEntryBytes?: number;
18
26
  }
19
- interface PgKvCacheNotifyOptions {
27
+ export interface PgKvCacheNotifyOptions {
20
28
  channel?: string;
21
29
  enabled?: boolean;
22
30
  listener?: PgKvCacheListenerFactory;
@@ -24,17 +32,17 @@ interface PgKvCacheNotifyOptions {
24
32
  /** Pause L1 reads and fills while the invalidation listener is unhealthy. Defaults to true. */
25
33
  pauseOnDisconnect?: boolean;
26
34
  }
27
- interface PgKvCacheListenerFactoryOptions {
35
+ export interface PgKvCacheListenerFactoryOptions {
28
36
  channels: string[];
29
37
  onNotify: NotifyHandler;
30
38
  }
31
- type PgKvCacheListenerFactory = (options: PgKvCacheListenerFactoryOptions) => PgListenerHandle;
32
- interface PgKvCacheInvalidationOptions {
39
+ export type PgKvCacheListenerFactory = (options: PgKvCacheListenerFactoryOptions) => PgListenerHandle;
40
+ export interface PgKvCacheInvalidationOptions {
33
41
  clearL1OnReconnect?: boolean;
34
42
  /** Pause L1 reads and fills while the invalidation listener is unhealthy. Defaults to true. */
35
43
  pauseOnDisconnect?: boolean;
36
44
  }
37
- interface PgKvCacheOptions {
45
+ export interface PgKvCacheOptions {
38
46
  sql: BunSqlLike;
39
47
  namespace?: string;
40
48
  tableName?: string;
@@ -49,31 +57,31 @@ interface PgKvCacheOptions {
49
57
  */
50
58
  singleflight?: boolean;
51
59
  }
52
- interface PgKvSetOptions {
60
+ export interface PgKvSetOptions {
53
61
  ttlMs?: number | null;
54
62
  notify?: boolean;
55
63
  mode?: "always" | "nx" | "xx";
56
64
  nx?: boolean;
57
65
  xx?: boolean;
58
66
  }
59
- interface PgKvCompareAndSwapOptions extends PgKvSetOptions {
67
+ export interface PgKvCompareAndSwapOptions extends PgKvSetOptions {
60
68
  expectedMissing?: boolean;
61
69
  }
62
- interface PgKvSchemaOptions {
70
+ export interface PgKvSchemaOptions {
63
71
  unlogged?: boolean;
64
72
  }
65
- interface PgKvSerializer {
73
+ export interface PgKvSerializer {
66
74
  serialize(value: unknown): unknown;
67
75
  deserialize(value: unknown): unknown;
68
76
  }
69
- interface PgKvNotification {
77
+ export interface PgKvNotification {
70
78
  namespace: string;
71
79
  key?: string;
72
80
  prefix?: string;
73
81
  op: "set" | "delete" | "clearPrefix" | "clearNamespace";
74
82
  senderId?: string;
75
83
  }
76
- interface PgKvCacheStats {
84
+ export interface PgKvCacheStats {
77
85
  namespace: string;
78
86
  tableName: string;
79
87
  l1Size: number;
@@ -90,8 +98,12 @@ interface PgKvCacheStats {
90
98
  inflightReads: number;
91
99
  /** Monotonic count of reads that joined an in-flight query for the same key. */
92
100
  coalescedReads: number;
101
+ /** Approximate bytes currently held by L1 (0 when byte accounting is off). */
102
+ l1Bytes: number;
103
+ /** Configured byte cap, or 0 when unlimited. */
104
+ l1MaxBytes: number;
93
105
  }
94
- declare class PgKvCache {
106
+ export declare class PgKvCache {
95
107
  readonly namespace: string;
96
108
  readonly tableName: string;
97
109
  readonly quotedTableName: string;
@@ -103,6 +115,8 @@ declare class PgKvCache {
103
115
  private readonly l1Max;
104
116
  private readonly l1TtlMs;
105
117
  private readonly l1NegativeTtlMs;
118
+ private readonly l1MaxBytes;
119
+ private readonly l1MaxEntryBytes;
106
120
  private readonly notifyEnabled;
107
121
  private readonly serializer;
108
122
  private readonly singleflight;
@@ -113,6 +127,7 @@ declare class PgKvCache {
113
127
  private l1Misses;
114
128
  private l1NegativeHits;
115
129
  private l1Paused;
130
+ private l1Bytes;
116
131
  private coalescedReads;
117
132
  private invalidationListener;
118
133
  private invalidationUnsubscribers;
@@ -149,6 +164,7 @@ declare class PgKvCache {
149
164
  stopInvalidationListener(): void;
150
165
  private pauseL1;
151
166
  private resumeL1;
167
+ private clearL1;
152
168
  handleNotification(payload: string | PgKvNotification): boolean;
153
169
  keys(pattern?: string, limit?: number): Promise<string[]>;
154
170
  scan(cursor?: string | null, count?: number, pattern?: string): Promise<{
@@ -171,6 +187,8 @@ declare class PgKvCache {
171
187
  private resolveNotifyOptions;
172
188
  private parseNotification;
173
189
  private getL1;
190
+ private removeEntry;
191
+ private tracksBytes;
174
192
  private setNegativeL1;
175
193
  private setL1;
176
194
  private computeL1ExpiresAt;
@@ -178,6 +196,4 @@ declare class PgKvCache {
178
196
  private cleanupL1;
179
197
  private enforceL1Max;
180
198
  }
181
- declare function createPgKvCache(options: PgKvCacheOptions): PgKvCache;
182
-
183
- export { type BunSqlLike, PgKvCache, type PgKvCacheInvalidationOptions, type PgKvCacheL1Options, type PgKvCacheListenerFactory, type PgKvCacheListenerFactoryOptions, type PgKvCacheNotifyOptions, type PgKvCacheOptions, type PgKvCacheStats, type PgKvCompareAndSwapOptions, type PgKvNotification, type PgKvSchemaOptions, type PgKvSerializer, type PgKvSetOptions, createPgKvCache };
199
+ export declare function createPgKvCache(options: PgKvCacheOptions): PgKvCache;
package/dist/kv-cache.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  PgKvCache,
3
3
  createPgKvCache
4
- } from "./chunk-7T5O55TM.js";
4
+ } from "./chunk-QIWUTOLC.js";
5
5
  export {
6
6
  PgKvCache,
7
7
  createPgKvCache
package/dist/kv.d.ts CHANGED
@@ -1,3 +1 @@
1
- export { BunSqlLike, PgKvCache, PgKvCacheInvalidationOptions, PgKvCacheL1Options, PgKvCacheListenerFactory, PgKvCacheListenerFactoryOptions, PgKvCacheNotifyOptions, PgKvCacheOptions, PgKvCacheStats, PgKvNotification, PgKvSchemaOptions, PgKvSerializer, PgKvSetOptions, createPgKvCache } from './kv-cache.js';
2
- import './pubsub-index.js';
3
- import './sql-DKf2TDlu.js';
1
+ export { createPgKvCache, PgKvCache, type PgKvCacheOptions, type PgKvSetOptions, type PgKvSchemaOptions, type PgKvCacheStats, type BunSqlLike, type PgKvCacheInvalidationOptions, type PgKvCacheL1Options, type PgKvCacheListenerFactory, type PgKvCacheListenerFactoryOptions, type PgKvCacheNotifyOptions, type PgKvSerializer, type PgKvNotification } from "./kv-cache.js";
package/dist/kv.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  PgKvCache,
3
3
  createPgKvCache
4
- } from "./chunk-7T5O55TM.js";
4
+ } from "./chunk-QIWUTOLC.js";
5
5
  export {
6
6
  PgKvCache,
7
7
  createPgKvCache
@@ -1,53 +1 @@
1
- import { P as PgSqlLike } from './sql-DKf2TDlu.js';
2
-
3
- interface PgListOptions {
4
- sql: PgSqlLike;
5
- namespace?: string;
6
- tableName?: string;
7
- }
8
- interface PgListSchemaOptions {
9
- unlogged?: boolean;
10
- }
11
- interface PgListScanResult<T = unknown> {
12
- cursor: number | null;
13
- values: T[];
14
- }
15
- interface PgListBlockingPopOptions {
16
- timeoutMs?: number;
17
- pollIntervalMs?: number;
18
- }
19
- interface PgListBlockingPopResult<T = unknown> {
20
- key: string;
21
- value: T;
22
- }
23
- declare class PgList {
24
- readonly namespace: string;
25
- readonly tableName: string;
26
- readonly quotedTableName: string;
27
- private readonly sql;
28
- private readonly now;
29
- constructor(options: PgListOptions & {
30
- now?: () => number;
31
- });
32
- ensureSchema(options?: PgListSchemaOptions): Promise<void>;
33
- lpush<T = unknown>(key: string, ...values: T[]): Promise<number>;
34
- rpush<T = unknown>(key: string, ...values: T[]): Promise<number>;
35
- lpop<T = unknown>(key: string, count?: number): Promise<T[]>;
36
- rpop<T = unknown>(key: string, count?: number): Promise<T[]>;
37
- blpop<T = unknown>(keys: string | readonly string[], options?: PgListBlockingPopOptions): Promise<PgListBlockingPopResult<T> | null>;
38
- brpop<T = unknown>(keys: string | readonly string[], options?: PgListBlockingPopOptions): Promise<PgListBlockingPopResult<T> | null>;
39
- lrange<T = unknown>(key: string, start?: number, stop?: number): Promise<T[]>;
40
- llen(key: string): Promise<number>;
41
- lclear(key: string): Promise<number>;
42
- private push;
43
- private pop;
44
- private blockingPop;
45
- lscan<T = unknown>(key: string, cursor?: number | null, count?: number): Promise<PgListScanResult<T>>;
46
- expire(key: string, ttlMs: number): Promise<number>;
47
- persist(key: string): Promise<number>;
48
- ttl(key: string): Promise<number | null>;
49
- cleanupExpired(limit?: number): Promise<number>;
50
- }
51
- declare function createPgList(options: PgListOptions): PgList;
52
-
53
- export { PgList, type PgListBlockingPopOptions, type PgListBlockingPopResult, type PgListOptions, type PgListScanResult, type PgListSchemaOptions, createPgList };
1
+ export { createPgList, PgList, type PgListOptions, type PgListSchemaOptions, type PgListScanResult, type PgListBlockingPopOptions, type PgListBlockingPopResult } from "./list.js";
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  PgList,
3
3
  createPgList
4
- } from "./chunk-HW3WONAC.js";
4
+ } from "./chunk-JRMUZTI4.js";
5
5
  import "./chunk-RWRM5RVO.js";
6
6
  export {
7
7
  PgList,