@postgresx/noredis 0.6.0 → 0.6.1
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 +59 -2
- package/dist/adapters/ioredis.d.ts +1 -1
- package/dist/adapters/redis.d.ts +1 -1
- package/dist/adapters/web.d.ts +2 -0
- package/dist/{chunk-VLFUE33D.js → chunk-BD36RDOX.js} +111 -11
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/kv-cache.d.ts +23 -1
- package/dist/kv-cache.js +1 -1
- package/dist/kv.d.ts +3 -1
- package/dist/kv.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -249,6 +249,36 @@ If package-name aliasing is useful during migration, use the thin re-export
|
|
|
249
249
|
packages `@postgresx/noredis-ioredis` and `@postgresx/noredis-redis`. They are
|
|
250
250
|
still facades over `PgredisClient`; they do not provide drop-in constructors.
|
|
251
251
|
|
|
252
|
+
### L1 invalidation and atomic swaps
|
|
253
|
+
|
|
254
|
+
Configure a listener factory to keep the local L1 cache coherent across
|
|
255
|
+
processes. The listener must use a dedicated connection that supports
|
|
256
|
+
`LISTEN`; do not reuse a transaction-pooled request connection.
|
|
257
|
+
|
|
258
|
+
```ts
|
|
259
|
+
import { createPgredis } from "@postgresx/noredis";
|
|
260
|
+
import { createPgNodeListener } from "@postgresx/noredis/adapters/node";
|
|
261
|
+
|
|
262
|
+
const pg = createPgredis({
|
|
263
|
+
sql,
|
|
264
|
+
cache: {
|
|
265
|
+
notify: {
|
|
266
|
+
listener: ({ channels, onNotify }) =>
|
|
267
|
+
createPgNodeListener(directDatabaseUrl, { channels, onNotify })
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
});
|
|
271
|
+
|
|
272
|
+
pg.cache.stopInvalidationListener();
|
|
273
|
+
```
|
|
274
|
+
|
|
275
|
+
Remote notifications invalidate matching L1 entries. A listener reconnect
|
|
276
|
+
clears the complete L1 cache by default so notifications missed during the
|
|
277
|
+
disconnect cannot leave stale entries behind. `getset()` runs in a retried
|
|
278
|
+
serializable transaction and therefore requires an adapter with `begin()`;
|
|
279
|
+
the built-in Bun and Node adapters provide it. `getdel()` uses one atomic
|
|
280
|
+
`DELETE ... RETURNING` statement.
|
|
281
|
+
|
|
252
282
|
## Pub/Sub
|
|
253
283
|
|
|
254
284
|
Publishing uses only the configured SQL adapter. Bun LISTEN/NOTIFY consumption
|
|
@@ -411,7 +441,7 @@ Remaining gates before a production or 1.0 launch:
|
|
|
411
441
|
|
|
412
442
|
| Area | Status | Why it matters | Recommended action |
|
|
413
443
|
| --- | --- | --- | --- |
|
|
414
|
-
| Real database coverage | Added in CI | PostgreSQL DDL, indexes, transactions, JSONB behavior, and LISTEN/NOTIFY reconnect behavior need real database coverage. | CI runs `bun run test:integration` against PostgreSQL
|
|
444
|
+
| Real database coverage | Added in CI | PostgreSQL DDL, indexes, transactions, JSONB behavior, and LISTEN/NOTIFY reconnect behavior need real database coverage. | CI runs `bun run test:integration` against PostgreSQL 17 and 18. Run locally with `TEST_DATABASE_URL` when debugging. |
|
|
415
445
|
| Benchmark baseline | Generated | `benchmark.md` is generated by GitHub Actions and includes both service-level PostgreSQL columns and L1 hot-read columns. | Benchmark-relevant changes refresh it automatically; local benchmark runs are optional. |
|
|
416
446
|
| Install smoke test | Added in CI | Build output exists, but the published package shape should be verified from a packed tarball, including subpath exports. | CI runs `bun run smoke:pack` to import packed tarballs from clean Node and Bun entrypoints. |
|
|
417
447
|
| Monorepo release chain | Guarded in CI | Source package manifests must keep internal packages as `workspace:*`; publish rewrites them to concrete versions in a temp tree. | CI runs `check:workspace-deps` before install, and `publish:packages` remains the only npm publish path. |
|
|
@@ -720,6 +750,33 @@ await redisJsLike.hSet("profile:1", "name", "Ada");
|
|
|
720
750
|
`@postgresx/noredis-ioredis` 和 `@postgresx/noredis-redis`。它们仍然是
|
|
721
751
|
`PgredisClient` 之上的外观,不提供即插即用构造器。
|
|
722
752
|
|
|
753
|
+
### L1 失效与原子交换
|
|
754
|
+
|
|
755
|
+
通过 listener factory 让多个进程的本地 L1 缓存保持一致。监听器必须使用
|
|
756
|
+
支持 `LISTEN` 的独立连接,不要复用 transaction pooler 的请求连接。
|
|
757
|
+
|
|
758
|
+
```ts
|
|
759
|
+
import { createPgredis } from "@postgresx/noredis";
|
|
760
|
+
import { createPgNodeListener } from "@postgresx/noredis/adapters/node";
|
|
761
|
+
|
|
762
|
+
const pg = createPgredis({
|
|
763
|
+
sql,
|
|
764
|
+
cache: {
|
|
765
|
+
notify: {
|
|
766
|
+
listener: ({ channels, onNotify }) =>
|
|
767
|
+
createPgNodeListener(directDatabaseUrl, { channels, onNotify })
|
|
768
|
+
}
|
|
769
|
+
}
|
|
770
|
+
});
|
|
771
|
+
|
|
772
|
+
pg.cache.stopInvalidationListener();
|
|
773
|
+
```
|
|
774
|
+
|
|
775
|
+
远端通知会使匹配的 L1 条目失效。监听连接重连时默认清空完整 L1,避免断线期间
|
|
776
|
+
漏掉的通知留下陈旧缓存。`getset()` 在可重试的串行化事务中执行,因此 SQL
|
|
777
|
+
适配器必须提供 `begin()`;内置 Bun 和 Node 适配器均支持。`getdel()` 使用单条
|
|
778
|
+
原子 `DELETE ... RETURNING` 语句。
|
|
779
|
+
|
|
723
780
|
## Pub/Sub
|
|
724
781
|
|
|
725
782
|
发布仅使用配置的 SQL 适配器。Bun LISTEN/NOTIFY 消费使用独立的 `@postgresx/bun-listen` 包,并动态加载。
|
|
@@ -868,7 +925,7 @@ npm install @postgresx/noredis pg-boss
|
|
|
868
925
|
|
|
869
926
|
| 领域 | 状态 | 重要性 | 建议操作 |
|
|
870
927
|
| --- | --- | --- | --- |
|
|
871
|
-
| 真实数据库覆盖 | CI 中已添加 | PostgreSQL DDL、索引、事务、JSONB 行为和 LISTEN/NOTIFY 重连行为需要真实数据库覆盖。 | CI 针对 PostgreSQL
|
|
928
|
+
| 真实数据库覆盖 | CI 中已添加 | PostgreSQL DDL、索引、事务、JSONB 行为和 LISTEN/NOTIFY 重连行为需要真实数据库覆盖。 | CI 针对 PostgreSQL 17 和 18 运行 `bun run test:integration`。调试时使用 `TEST_DATABASE_URL` 本地运行。 |
|
|
872
929
|
| 基准测试基线 | 已生成 | `benchmark.md` 已由 GitHub Actions 生成,并区分主服务级对比和 L1 热读说明。 | benchmark 相关文件变化会自动刷新;本地基准测试运行是可选的。 |
|
|
873
930
|
| 安装冒烟测试 | CI 中已添加 | 构建输出存在,但已发布包的形状应从打包的 tarball 验证,包括子路径导出。 | CI 运行 `bun run smoke:pack` 从干净的 Node 和 Bun 入口点导入打包的 tarball。 |
|
|
874
931
|
| 发布凭证 | 在工作流中保护 | Release Please 和 npm publish 依赖仓库密钥和 npm provenance 设置。 | 当 `RELEASE_PAT` 或 `NPM_TOKEN` 缺失时,工作流会提前失败;首次发布前仍需验证包访问权限。 |
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { Q as PgredisClient, _ as PipelineFacade, U as PgredisMigrationAliases } from '../client-DP3ssToT.js';
|
|
2
2
|
import '../kv-cache.js';
|
|
3
|
+
import '../pubsub-index.js';
|
|
3
4
|
import '../sql-DKf2TDlu.js';
|
|
4
5
|
import '../hash-index.js';
|
|
5
6
|
import '../list-index.js';
|
|
6
|
-
import '../pubsub-index.js';
|
|
7
7
|
import '../set-index.js';
|
|
8
8
|
import '../sorted-set-index.js';
|
|
9
9
|
|
package/dist/adapters/redis.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { Q as PgredisClient, _ as PipelineFacade, U as PgredisMigrationAliases } from '../client-DP3ssToT.js';
|
|
2
2
|
import '../kv-cache.js';
|
|
3
|
+
import '../pubsub-index.js';
|
|
3
4
|
import '../sql-DKf2TDlu.js';
|
|
4
5
|
import '../hash-index.js';
|
|
5
6
|
import '../list-index.js';
|
|
6
|
-
import '../pubsub-index.js';
|
|
7
7
|
import '../set-index.js';
|
|
8
8
|
import '../sorted-set-index.js';
|
|
9
9
|
|
package/dist/adapters/web.d.ts
CHANGED
|
@@ -49,6 +49,11 @@ function normalizeTtlMs(ttlMs) {
|
|
|
49
49
|
if (!Number.isFinite(ttlMs)) throw new Error(`Invalid ttlMs: ${ttlMs}`);
|
|
50
50
|
return Math.max(0, Math.floor(ttlMs));
|
|
51
51
|
}
|
|
52
|
+
function isSerializationFailure(error) {
|
|
53
|
+
if (!error || typeof error !== "object") return false;
|
|
54
|
+
if ("code" in error && error.code === "40001") return true;
|
|
55
|
+
return "cause" in error && isSerializationFailure(error.cause);
|
|
56
|
+
}
|
|
52
57
|
function escapeLike(value) {
|
|
53
58
|
return value.replace(/[\\%_]/g, (match) => `\\${match}`);
|
|
54
59
|
}
|
|
@@ -75,6 +80,9 @@ var PgKvCache = class {
|
|
|
75
80
|
notifyEnabled;
|
|
76
81
|
serializer;
|
|
77
82
|
l1 = /* @__PURE__ */ new Map();
|
|
83
|
+
l1Generation = 0;
|
|
84
|
+
invalidationListener = null;
|
|
85
|
+
invalidationReconnectUnsubscribe = null;
|
|
78
86
|
constructor(options) {
|
|
79
87
|
this.sql = options.sql;
|
|
80
88
|
this.namespace = options.namespace || DEFAULT_NAMESPACE;
|
|
@@ -91,6 +99,12 @@ var PgKvCache = class {
|
|
|
91
99
|
serialize: (value) => value,
|
|
92
100
|
deserialize: (value) => value
|
|
93
101
|
};
|
|
102
|
+
const listenerFactory = this.resolveNotifyOptions(options.notify)?.listener;
|
|
103
|
+
if (listenerFactory) {
|
|
104
|
+
this.startInvalidationListener(listenerFactory, {
|
|
105
|
+
clearL1OnReconnect: this.resolveNotifyOptions(options.notify)?.clearL1OnReconnect
|
|
106
|
+
});
|
|
107
|
+
}
|
|
94
108
|
}
|
|
95
109
|
async ensureSchema(options = {}) {
|
|
96
110
|
const persistence = options.unlogged === false ? "" : "UNLOGGED ";
|
|
@@ -117,6 +131,7 @@ var PgKvCache = class {
|
|
|
117
131
|
async get(key) {
|
|
118
132
|
const cached = this.getL1(key);
|
|
119
133
|
if (cached.hit) return cached.value;
|
|
134
|
+
const l1Generation = this.l1Generation;
|
|
120
135
|
const rows = await this.sql.unsafe(
|
|
121
136
|
`SELECT value, expires_at
|
|
122
137
|
FROM ${this.quotedTableName}
|
|
@@ -132,7 +147,7 @@ var PgKvCache = class {
|
|
|
132
147
|
return null;
|
|
133
148
|
}
|
|
134
149
|
const value = this.deserialize(row.value);
|
|
135
|
-
this.setL1(key, value, rowExpiresAt(row));
|
|
150
|
+
this.setL1(key, value, rowExpiresAt(row), l1Generation);
|
|
136
151
|
return value;
|
|
137
152
|
}
|
|
138
153
|
async mget(keys) {
|
|
@@ -147,6 +162,7 @@ var PgKvCache = class {
|
|
|
147
162
|
}
|
|
148
163
|
}
|
|
149
164
|
if (missing.length === 0) return result;
|
|
165
|
+
const l1Generation = this.l1Generation;
|
|
150
166
|
const placeholders = missing.map((_, index) => `$${index + 2}`).join(", ");
|
|
151
167
|
const rows = await this.sql.unsafe(
|
|
152
168
|
`SELECT key, value, expires_at
|
|
@@ -160,7 +176,7 @@ var PgKvCache = class {
|
|
|
160
176
|
if (!row.key) continue;
|
|
161
177
|
const value = this.deserialize(row.value);
|
|
162
178
|
result.set(row.key, value);
|
|
163
|
-
this.setL1(row.key, value, rowExpiresAt(row));
|
|
179
|
+
this.setL1(row.key, value, rowExpiresAt(row), l1Generation);
|
|
164
180
|
}
|
|
165
181
|
for (const key of missing) {
|
|
166
182
|
if (!result.has(key)) this.deleteL1(key);
|
|
@@ -261,7 +277,7 @@ var PgKvCache = class {
|
|
|
261
277
|
RETURNING key`,
|
|
262
278
|
[this.namespace]
|
|
263
279
|
);
|
|
264
|
-
this.
|
|
280
|
+
this.invalidateAll();
|
|
265
281
|
if (options.notify !== false) await this.publish({ op: "clearNamespace" });
|
|
266
282
|
return rows.length;
|
|
267
283
|
}
|
|
@@ -396,6 +412,31 @@ var PgKvCache = class {
|
|
|
396
412
|
invalidate(key) {
|
|
397
413
|
this.deleteL1(key);
|
|
398
414
|
}
|
|
415
|
+
invalidateAll() {
|
|
416
|
+
this.l1Generation += 1;
|
|
417
|
+
this.l1.clear();
|
|
418
|
+
}
|
|
419
|
+
startInvalidationListener(factory, options = {}) {
|
|
420
|
+
this.stopInvalidationListener();
|
|
421
|
+
const listener = factory({
|
|
422
|
+
channels: [this.notifyChannel],
|
|
423
|
+
onNotify: (channel, payload) => {
|
|
424
|
+
if (channel === this.notifyChannel) this.handleNotification(payload);
|
|
425
|
+
}
|
|
426
|
+
});
|
|
427
|
+
const reconnectUnsubscribe = options.clearL1OnReconnect === false ? null : listener.on("reconnect", () => this.invalidateAll());
|
|
428
|
+
this.invalidationListener = listener;
|
|
429
|
+
this.invalidationReconnectUnsubscribe = reconnectUnsubscribe;
|
|
430
|
+
return listener;
|
|
431
|
+
}
|
|
432
|
+
stopInvalidationListener() {
|
|
433
|
+
const listener = this.invalidationListener;
|
|
434
|
+
const reconnectUnsubscribe = this.invalidationReconnectUnsubscribe;
|
|
435
|
+
this.invalidationListener = null;
|
|
436
|
+
this.invalidationReconnectUnsubscribe = null;
|
|
437
|
+
reconnectUnsubscribe?.();
|
|
438
|
+
listener?.close();
|
|
439
|
+
}
|
|
399
440
|
handleNotification(payload) {
|
|
400
441
|
const event = typeof payload === "string" ? this.parseNotification(payload) : payload;
|
|
401
442
|
if (!event || event.namespace !== this.namespace || event.senderId === this.instanceId) return false;
|
|
@@ -405,13 +446,14 @@ var PgKvCache = class {
|
|
|
405
446
|
}
|
|
406
447
|
if (event.op === "clearPrefix") {
|
|
407
448
|
if (!event.prefix) return false;
|
|
449
|
+
this.l1Generation += 1;
|
|
408
450
|
for (const key of this.l1.keys()) {
|
|
409
451
|
if (key.startsWith(event.prefix)) this.l1.delete(key);
|
|
410
452
|
}
|
|
411
453
|
return true;
|
|
412
454
|
}
|
|
413
455
|
if (event.op === "clearNamespace") {
|
|
414
|
-
this.
|
|
456
|
+
this.invalidateAll();
|
|
415
457
|
return true;
|
|
416
458
|
}
|
|
417
459
|
return false;
|
|
@@ -502,14 +544,50 @@ var PgKvCache = class {
|
|
|
502
544
|
return written ? 1 : 0;
|
|
503
545
|
}
|
|
504
546
|
async getset(key, value) {
|
|
505
|
-
const
|
|
506
|
-
|
|
507
|
-
|
|
547
|
+
const serialized = jsonValue(this.serializer.serialize(value));
|
|
548
|
+
const l1Generation = this.l1Generation;
|
|
549
|
+
const oldValue = await this.runSerializable(async (tx) => {
|
|
550
|
+
const rows = await tx.unsafe(
|
|
551
|
+
`SELECT value, expires_at
|
|
552
|
+
FROM ${this.quotedTableName}
|
|
553
|
+
WHERE namespace = $1
|
|
554
|
+
AND key = $2
|
|
555
|
+
AND (expires_at IS NULL OR expires_at > NOW())
|
|
556
|
+
FOR UPDATE`,
|
|
557
|
+
[this.namespace, key]
|
|
558
|
+
);
|
|
559
|
+
await tx.unsafe(
|
|
560
|
+
`INSERT INTO ${this.quotedTableName} (namespace, key, value, expires_at, updated_at)
|
|
561
|
+
VALUES ($1, $2, $3::jsonb, NULL, NOW())
|
|
562
|
+
ON CONFLICT (namespace, key) DO UPDATE
|
|
563
|
+
SET value = EXCLUDED.value,
|
|
564
|
+
expires_at = NULL,
|
|
565
|
+
updated_at = NOW()`,
|
|
566
|
+
[this.namespace, key, serialized]
|
|
567
|
+
);
|
|
568
|
+
return rows[0] ? this.deserialize(rows[0].value) : null;
|
|
569
|
+
});
|
|
570
|
+
this.setL1(key, value, null, l1Generation);
|
|
571
|
+
await this.publish({ op: "set", key });
|
|
572
|
+
return oldValue;
|
|
508
573
|
}
|
|
509
574
|
async getdel(key) {
|
|
510
|
-
const
|
|
511
|
-
|
|
512
|
-
|
|
575
|
+
const rows = await this.sql.unsafe(
|
|
576
|
+
`WITH deleted AS (
|
|
577
|
+
DELETE FROM ${this.quotedTableName}
|
|
578
|
+
WHERE namespace = $1 AND key = $2
|
|
579
|
+
RETURNING value, expires_at
|
|
580
|
+
)
|
|
581
|
+
SELECT value,
|
|
582
|
+
(expires_at IS NULL OR expires_at > NOW()) AS is_live
|
|
583
|
+
FROM deleted`,
|
|
584
|
+
[this.namespace, key]
|
|
585
|
+
);
|
|
586
|
+
const row = rows[0];
|
|
587
|
+
this.deleteL1(key);
|
|
588
|
+
if (!row) return null;
|
|
589
|
+
await this.publish({ op: "delete", key });
|
|
590
|
+
return row.is_live ? this.deserialize(row.value) : null;
|
|
513
591
|
}
|
|
514
592
|
stats() {
|
|
515
593
|
this.cleanupL1();
|
|
@@ -529,6 +607,23 @@ var PgKvCache = class {
|
|
|
529
607
|
};
|
|
530
608
|
await this.sql.unsafe("SELECT pg_notify($1, $2)", [this.notifyChannel, JSON.stringify(payload)]);
|
|
531
609
|
}
|
|
610
|
+
async runSerializable(operation) {
|
|
611
|
+
const begin = this.sql.begin?.bind(this.sql);
|
|
612
|
+
if (!begin) {
|
|
613
|
+
throw new Error("PgKvCache.getset requires a transaction-capable sql adapter");
|
|
614
|
+
}
|
|
615
|
+
for (let attempt = 0; attempt < 3; attempt += 1) {
|
|
616
|
+
try {
|
|
617
|
+
return await begin(async (tx) => {
|
|
618
|
+
await tx.unsafe("SET TRANSACTION ISOLATION LEVEL SERIALIZABLE");
|
|
619
|
+
return operation(tx);
|
|
620
|
+
});
|
|
621
|
+
} catch (error) {
|
|
622
|
+
if (!isSerializationFailure(error) || attempt === 2) throw error;
|
|
623
|
+
}
|
|
624
|
+
}
|
|
625
|
+
throw new Error("PgKvCache serializable transaction retry exhausted");
|
|
626
|
+
}
|
|
532
627
|
deserialize(value) {
|
|
533
628
|
return this.serializer.deserialize(parseValue(value));
|
|
534
629
|
}
|
|
@@ -538,6 +633,9 @@ var PgKvCache = class {
|
|
|
538
633
|
if (options.xx) return "xx";
|
|
539
634
|
return options.mode ?? "always";
|
|
540
635
|
}
|
|
636
|
+
resolveNotifyOptions(options) {
|
|
637
|
+
return options === false ? void 0 : options;
|
|
638
|
+
}
|
|
541
639
|
parseNotification(payload) {
|
|
542
640
|
try {
|
|
543
641
|
const value = JSON.parse(payload);
|
|
@@ -559,8 +657,9 @@ var PgKvCache = class {
|
|
|
559
657
|
this.l1.set(key, entry);
|
|
560
658
|
return { hit: true, value: entry.value };
|
|
561
659
|
}
|
|
562
|
-
setL1(key, value, l2ExpiresAt) {
|
|
660
|
+
setL1(key, value, l2ExpiresAt, generation = this.l1Generation) {
|
|
563
661
|
if (!this.l1Enabled || this.l1Max <= 0) return;
|
|
662
|
+
if (generation !== this.l1Generation) return;
|
|
564
663
|
const l1ExpiresAt = this.computeL1ExpiresAt(l2ExpiresAt);
|
|
565
664
|
if (l1ExpiresAt !== null && l1ExpiresAt <= this.now()) {
|
|
566
665
|
this.l1.delete(key);
|
|
@@ -578,6 +677,7 @@ var PgKvCache = class {
|
|
|
578
677
|
}
|
|
579
678
|
deleteL1(key) {
|
|
580
679
|
if (!this.l1Enabled) return;
|
|
680
|
+
this.l1Generation += 1;
|
|
581
681
|
this.l1.delete(key);
|
|
582
682
|
}
|
|
583
683
|
cleanupL1() {
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { BunSqlLike, PgKvCache, PgKvCacheL1Options, PgKvCacheNotifyOptions, PgKvCacheOptions, PgKvCacheStats, PgKvNotification, PgKvSchemaOptions, PgKvSetOptions, createPgKvCache } from './kv-cache.js';
|
|
1
|
+
export { BunSqlLike, PgKvCache, PgKvCacheInvalidationOptions, PgKvCacheL1Options, PgKvCacheListenerFactory, PgKvCacheListenerFactoryOptions, PgKvCacheNotifyOptions, PgKvCacheOptions, PgKvCacheStats, PgKvNotification, PgKvSchemaOptions, PgKvSetOptions, createPgKvCache } from './kv-cache.js';
|
|
2
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 PgredisTableMetrics, Z as PipelineCommand, _ as PipelineFacade, h as Queue, k as QueueResult, $ as RedisSetAliasOptions, l as SendOptions, m as WorkHandler, n as WorkOptions, a0 as advisoryLockKeyToSqlArgs, a1 as collectPgredisMetrics, a2 as createPgAdvisoryLocker, a3 as createPgBossJobQueue, a4 as createPgCounter, a5 as createPgFixedWindowRateLimiter, a6 as createPgOutboxStream, a7 as createPgSlidingWindowRateLimiter, a8 as createPgTokenBucketRateLimiter, a9 as createPgredis, aa as createPgredisMigrationAliases, ab as withPgAdvisoryLock } from './client-DP3ssToT.js';
|
|
3
3
|
export { PgHash, PgHashOptions, PgHashScanResult, PgHashSchemaOptions, createPgHash } from './hash-index.js';
|
|
4
4
|
export { PgList, PgListBlockingPopOptions, PgListBlockingPopResult, PgListOptions, PgListScanResult, PgListSchemaOptions, createPgList } from './list-index.js';
|
package/dist/index.js
CHANGED
package/dist/kv-cache.d.ts
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
|
+
import { NotifyHandler, PgListenerHandle } from './pubsub-index.js';
|
|
2
|
+
import './sql-DKf2TDlu.js';
|
|
3
|
+
|
|
1
4
|
interface BunSqlLike {
|
|
2
5
|
unsafe<T = Record<string, unknown>>(query: string, params?: readonly unknown[]): Promise<T[]>;
|
|
6
|
+
begin?<T>(callback: (tx: BunSqlLike) => Promise<T>): Promise<T>;
|
|
3
7
|
}
|
|
4
8
|
interface PgKvCacheL1Options {
|
|
5
9
|
max?: number;
|
|
@@ -8,6 +12,16 @@ interface PgKvCacheL1Options {
|
|
|
8
12
|
interface PgKvCacheNotifyOptions {
|
|
9
13
|
channel?: string;
|
|
10
14
|
enabled?: boolean;
|
|
15
|
+
listener?: PgKvCacheListenerFactory;
|
|
16
|
+
clearL1OnReconnect?: boolean;
|
|
17
|
+
}
|
|
18
|
+
interface PgKvCacheListenerFactoryOptions {
|
|
19
|
+
channels: string[];
|
|
20
|
+
onNotify: NotifyHandler;
|
|
21
|
+
}
|
|
22
|
+
type PgKvCacheListenerFactory = (options: PgKvCacheListenerFactoryOptions) => PgListenerHandle;
|
|
23
|
+
interface PgKvCacheInvalidationOptions {
|
|
24
|
+
clearL1OnReconnect?: boolean;
|
|
11
25
|
}
|
|
12
26
|
interface PgKvCacheOptions {
|
|
13
27
|
sql: BunSqlLike;
|
|
@@ -63,6 +77,9 @@ declare class PgKvCache {
|
|
|
63
77
|
private readonly notifyEnabled;
|
|
64
78
|
private readonly serializer;
|
|
65
79
|
private readonly l1;
|
|
80
|
+
private l1Generation;
|
|
81
|
+
private invalidationListener;
|
|
82
|
+
private invalidationReconnectUnsubscribe;
|
|
66
83
|
constructor(options: PgKvCacheOptions);
|
|
67
84
|
ensureSchema(options?: PgKvSchemaOptions): Promise<void>;
|
|
68
85
|
get<T = unknown>(key: string): Promise<T | null>;
|
|
@@ -89,6 +106,9 @@ declare class PgKvCache {
|
|
|
89
106
|
touch(key: string): Promise<boolean>;
|
|
90
107
|
ttl(key: string): Promise<number | null>;
|
|
91
108
|
invalidate(key: string): void;
|
|
109
|
+
invalidateAll(): void;
|
|
110
|
+
startInvalidationListener(factory: PgKvCacheListenerFactory, options?: PgKvCacheInvalidationOptions): PgListenerHandle;
|
|
111
|
+
stopInvalidationListener(): void;
|
|
92
112
|
handleNotification(payload: string | PgKvNotification): boolean;
|
|
93
113
|
keys(pattern?: string, limit?: number): Promise<string[]>;
|
|
94
114
|
scan(cursor?: string | null, count?: number, pattern?: string): Promise<{
|
|
@@ -105,8 +125,10 @@ declare class PgKvCache {
|
|
|
105
125
|
getdel<T = unknown>(key: string): Promise<T | null>;
|
|
106
126
|
stats(): PgKvCacheStats;
|
|
107
127
|
private publish;
|
|
128
|
+
private runSerializable;
|
|
108
129
|
private deserialize;
|
|
109
130
|
private resolveSetMode;
|
|
131
|
+
private resolveNotifyOptions;
|
|
110
132
|
private parseNotification;
|
|
111
133
|
private getL1;
|
|
112
134
|
private setL1;
|
|
@@ -117,4 +139,4 @@ declare class PgKvCache {
|
|
|
117
139
|
}
|
|
118
140
|
declare function createPgKvCache(options: PgKvCacheOptions): PgKvCache;
|
|
119
141
|
|
|
120
|
-
export { type BunSqlLike, PgKvCache, type PgKvCacheL1Options, type PgKvCacheNotifyOptions, type PgKvCacheOptions, type PgKvCacheStats, type PgKvCompareAndSwapOptions, type PgKvNotification, type PgKvSchemaOptions, type PgKvSerializer, type PgKvSetOptions, createPgKvCache };
|
|
142
|
+
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 };
|
package/dist/kv-cache.js
CHANGED
package/dist/kv.d.ts
CHANGED
|
@@ -1 +1,3 @@
|
|
|
1
|
-
export { BunSqlLike, PgKvCache, PgKvCacheL1Options, PgKvCacheNotifyOptions, PgKvCacheOptions, PgKvCacheStats, PgKvNotification, PgKvSchemaOptions, PgKvSerializer, PgKvSetOptions, createPgKvCache } from './kv-cache.js';
|
|
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';
|
package/dist/kv.js
CHANGED
package/package.json
CHANGED