@postgresx/noredis 0.1.0 → 0.5.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.
@@ -17,14 +17,25 @@ interface PgKvCacheOptions {
17
17
  notify?: false | PgKvCacheNotifyOptions;
18
18
  instanceId?: string;
19
19
  now?: () => number;
20
+ serializer?: PgKvSerializer;
20
21
  }
21
22
  interface PgKvSetOptions {
22
23
  ttlMs?: number | null;
23
24
  notify?: boolean;
25
+ mode?: "always" | "nx" | "xx";
26
+ nx?: boolean;
27
+ xx?: boolean;
28
+ }
29
+ interface PgKvCompareAndSwapOptions extends PgKvSetOptions {
30
+ expectedMissing?: boolean;
24
31
  }
25
32
  interface PgKvSchemaOptions {
26
33
  unlogged?: boolean;
27
34
  }
35
+ interface PgKvSerializer {
36
+ serialize(value: unknown): unknown;
37
+ deserialize(value: unknown): unknown;
38
+ }
28
39
  interface PgKvNotification {
29
40
  namespace: string;
30
41
  key?: string;
@@ -50,12 +61,13 @@ declare class PgKvCache {
50
61
  private readonly l1Max;
51
62
  private readonly l1TtlMs;
52
63
  private readonly notifyEnabled;
64
+ private readonly serializer;
53
65
  private readonly l1;
54
66
  constructor(options: PgKvCacheOptions);
55
67
  ensureSchema(options?: PgKvSchemaOptions): Promise<void>;
56
68
  get<T = unknown>(key: string): Promise<T | null>;
57
69
  mget<T = unknown>(keys: readonly string[]): Promise<Map<string, T>>;
58
- set<T = unknown>(key: string, value: T, options?: PgKvSetOptions): Promise<void>;
70
+ set<T = unknown>(key: string, value: T, options?: PgKvSetOptions): Promise<boolean>;
59
71
  mset<T = unknown>(entries: Iterable<readonly [string, T]>, options?: PgKvSetOptions): Promise<void>;
60
72
  delete(key: string, options?: {
61
73
  notify?: boolean;
@@ -67,10 +79,34 @@ declare class PgKvCache {
67
79
  notify?: boolean;
68
80
  }): Promise<number>;
69
81
  cleanupExpired(limit?: number): Promise<number>;
82
+ compareAndSwap<T = unknown>(key: string, expected: T | null, next: T, options?: PgKvCompareAndSwapOptions): Promise<boolean>;
83
+ expire(key: string, ttlMs: number, options?: {
84
+ notify?: boolean;
85
+ }): Promise<boolean>;
86
+ persist(key: string, options?: {
87
+ notify?: boolean;
88
+ }): Promise<boolean>;
89
+ touch(key: string): Promise<boolean>;
90
+ ttl(key: string): Promise<number | null>;
70
91
  invalidate(key: string): void;
71
92
  handleNotification(payload: string | PgKvNotification): boolean;
93
+ keys(pattern?: string, limit?: number): Promise<string[]>;
94
+ scan(cursor?: string | null, count?: number, pattern?: string): Promise<{
95
+ cursor: string | null;
96
+ keys: string[];
97
+ }>;
98
+ rename(key: string, newKey: string): Promise<boolean>;
99
+ type(key: string): Promise<"string" | "none">;
100
+ unlink(...keys: string[]): Promise<number>;
101
+ setex<T = unknown>(key: string, seconds: number, value: T): Promise<"OK">;
102
+ psetex<T = unknown>(key: string, milliseconds: number, value: T): Promise<"OK">;
103
+ setnx<T = unknown>(key: string, value: T): Promise<number>;
104
+ getset<T = unknown>(key: string, value: T): Promise<T | null>;
105
+ getdel<T = unknown>(key: string): Promise<T | null>;
72
106
  stats(): PgKvCacheStats;
73
107
  private publish;
108
+ private deserialize;
109
+ private resolveSetMode;
74
110
  private parseNotification;
75
111
  private getL1;
76
112
  private setL1;
@@ -81,4 +117,4 @@ declare class PgKvCache {
81
117
  }
82
118
  declare function createPgKvCache(options: PgKvCacheOptions): PgKvCache;
83
119
 
84
- export { type BunSqlLike, PgKvCache, type PgKvCacheL1Options, type PgKvCacheNotifyOptions, type PgKvCacheOptions, type PgKvCacheStats, type PgKvNotification, type PgKvSchemaOptions, type PgKvSetOptions, createPgKvCache };
120
+ export { type BunSqlLike, PgKvCache, type PgKvCacheL1Options, type PgKvCacheNotifyOptions, type PgKvCacheOptions, type PgKvCacheStats, type PgKvCompareAndSwapOptions, type PgKvNotification, type PgKvSchemaOptions, type PgKvSerializer, type PgKvSetOptions, createPgKvCache };
package/dist/kv-cache.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  PgKvCache,
3
3
  createPgKvCache
4
- } from "./chunk-GBFG2TOL.js";
4
+ } from "./chunk-VLFUE33D.js";
5
5
  export {
6
6
  PgKvCache,
7
7
  createPgKvCache
package/dist/kv.d.ts ADDED
@@ -0,0 +1 @@
1
+ export { BunSqlLike, PgKvCache, PgKvCacheL1Options, PgKvCacheNotifyOptions, PgKvCacheOptions, PgKvCacheStats, PgKvNotification, PgKvSchemaOptions, PgKvSerializer, PgKvSetOptions, createPgKvCache } from './kv-cache.js';
package/dist/kv.js ADDED
@@ -0,0 +1,8 @@
1
+ import {
2
+ PgKvCache,
3
+ createPgKvCache
4
+ } from "./chunk-VLFUE33D.js";
5
+ export {
6
+ PgKvCache,
7
+ createPgKvCache
8
+ };
@@ -0,0 +1,53 @@
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 };
@@ -0,0 +1,9 @@
1
+ import {
2
+ PgList,
3
+ createPgList
4
+ } from "./chunk-HW3WONAC.js";
5
+ import "./chunk-RWRM5RVO.js";
6
+ export {
7
+ PgList,
8
+ createPgList
9
+ };
@@ -57,4 +57,4 @@ declare const createPgListener: typeof createBunPgListener;
57
57
  declare function publishPgNotify(sql: PgSqlLike, channel: string, payload: PgNotifyPayload): Promise<void>;
58
58
  declare function createPgPublisher(sql: PgSqlLike): PgPublisher;
59
59
 
60
- export { type NotifyHandler as N, type PgListenerEvents as P, type PgListenerHandle as a, type PgListenerHealth as b, type PgListenerOptions as c, type PgNotifyPayload as d, type PgPublisher as e, createBunPgListener as f, createPgListener as g, createPgPublisher as h, publishPgNotify as p };
60
+ export { type NotifyHandler, type PgListenerEvents, type PgListenerHandle, type PgListenerHealth, type PgListenerOptions, type PgNotifyPayload, type PgPublisher, createBunPgListener, createPgListener, createPgPublisher, publishPgNotify };
@@ -0,0 +1,12 @@
1
+ import {
2
+ createBunPgListener,
3
+ createPgListener,
4
+ createPgPublisher,
5
+ publishPgNotify
6
+ } from "./chunk-QI73S2FT.js";
7
+ export {
8
+ createBunPgListener,
9
+ createPgListener,
10
+ createPgPublisher,
11
+ publishPgNotify
12
+ };
@@ -0,0 +1,42 @@
1
+ import { P as PgSqlLike } from './sql-DKf2TDlu.js';
2
+
3
+ interface PgSetOptions {
4
+ sql: PgSqlLike;
5
+ namespace?: string;
6
+ tableName?: string;
7
+ }
8
+ interface PgSetSchemaOptions {
9
+ unlogged?: boolean;
10
+ }
11
+ interface PgSetScanResult {
12
+ cursor: string | null;
13
+ members: string[];
14
+ }
15
+ declare class PgSet {
16
+ readonly namespace: string;
17
+ readonly tableName: string;
18
+ readonly quotedTableName: string;
19
+ private readonly sql;
20
+ constructor(options: PgSetOptions);
21
+ ensureSchema(options?: PgSetSchemaOptions): Promise<void>;
22
+ sadd(key: string, ...members: string[]): Promise<number>;
23
+ srem(key: string, ...members: string[]): Promise<number>;
24
+ sismember(key: string, member: string): Promise<boolean>;
25
+ smembers(key: string): Promise<string[]>;
26
+ sinter(...keys: string[]): Promise<string[]>;
27
+ sunion(...keys: string[]): Promise<string[]>;
28
+ sdiff(key: string, ...otherKeys: string[]): Promise<string[]>;
29
+ scard(key: string): Promise<number>;
30
+ sclear(key: string): Promise<number>;
31
+ sscan(key: string, cursor?: string | null, count?: number): Promise<PgSetScanResult>;
32
+ expire(key: string, ttlMs: number): Promise<number>;
33
+ persist(key: string): Promise<number>;
34
+ ttl(key: string): Promise<number | null>;
35
+ spop(key: string, count?: number): Promise<string[]>;
36
+ srandmember(key: string, count?: number): Promise<string[]>;
37
+ smove(source: string, destination: string, member: string): Promise<boolean>;
38
+ cleanupExpired(limit?: number): Promise<number>;
39
+ }
40
+ declare function createPgSet(options: PgSetOptions): PgSet;
41
+
42
+ export { PgSet, type PgSetOptions, type PgSetScanResult, type PgSetSchemaOptions, createPgSet };
@@ -0,0 +1,9 @@
1
+ import {
2
+ PgSet,
3
+ createPgSet
4
+ } from "./chunk-3DNTNHVD.js";
5
+ import "./chunk-RWRM5RVO.js";
6
+ export {
7
+ PgSet,
8
+ createPgSet
9
+ };
@@ -0,0 +1,58 @@
1
+ import { P as PgSqlLike } from './sql-DKf2TDlu.js';
2
+
3
+ interface PgSortedSetOptions {
4
+ sql: PgSqlLike;
5
+ namespace?: string;
6
+ tableName?: string;
7
+ }
8
+ interface PgSortedSetSchemaOptions {
9
+ unlogged?: boolean;
10
+ }
11
+ interface PgSortedSetMember {
12
+ member: string;
13
+ score: number;
14
+ }
15
+ interface PgSortedSetScanResult {
16
+ cursor: string | null;
17
+ entries: PgSortedSetMember[];
18
+ }
19
+ declare class PgSortedSet {
20
+ readonly namespace: string;
21
+ readonly tableName: string;
22
+ readonly quotedTableName: string;
23
+ private readonly sql;
24
+ constructor(options: PgSortedSetOptions);
25
+ ensureSchema(options?: PgSortedSetSchemaOptions): Promise<void>;
26
+ zadd(key: string, score: number, member: string): Promise<boolean>;
27
+ zscore(key: string, member: string): Promise<number | null>;
28
+ zrange(key: string, start?: number, stop?: number, options?: {
29
+ withScores?: boolean;
30
+ desc?: boolean;
31
+ }): Promise<string[] | PgSortedSetMember[]>;
32
+ zrangeByScore(key: string, min?: number, max?: number, options?: {
33
+ withScores?: boolean;
34
+ limit?: number;
35
+ offset?: number;
36
+ desc?: boolean;
37
+ }): Promise<string[] | PgSortedSetMember[]>;
38
+ zrank(key: string, member: string, options?: {
39
+ desc?: boolean;
40
+ }): Promise<number | null>;
41
+ zcount(key: string, min?: number, max?: number): Promise<number>;
42
+ zrem(key: string, ...members: string[]): Promise<number>;
43
+ zpopmin(key: string, count?: number): Promise<PgSortedSetMember[]>;
44
+ zscan(key: string, cursor?: string | null, count?: number): Promise<PgSortedSetScanResult>;
45
+ expire(key: string, ttlMs: number): Promise<number>;
46
+ persist(key: string): Promise<number>;
47
+ ttl(key: string): Promise<number | null>;
48
+ zcard(key: string): Promise<number>;
49
+ zrevrange(key: string, start?: number, stop?: number, options?: {
50
+ withScores?: boolean;
51
+ }): Promise<string[] | PgSortedSetMember[]>;
52
+ zincrby(key: string, amount: number, member: string): Promise<number>;
53
+ zpopmax(key: string, count?: number): Promise<PgSortedSetMember[]>;
54
+ cleanupExpired(limit?: number): Promise<number>;
55
+ }
56
+ declare function createPgSortedSet(options: PgSortedSetOptions): PgSortedSet;
57
+
58
+ export { PgSortedSet, type PgSortedSetMember, type PgSortedSetOptions, type PgSortedSetScanResult, type PgSortedSetSchemaOptions, createPgSortedSet };
@@ -0,0 +1,9 @@
1
+ import {
2
+ PgSortedSet,
3
+ createPgSortedSet
4
+ } from "./chunk-YSWHEFPX.js";
5
+ import "./chunk-RWRM5RVO.js";
6
+ export {
7
+ PgSortedSet,
8
+ createPgSortedSet
9
+ };
package/package.json CHANGED
@@ -1,9 +1,14 @@
1
1
  {
2
2
  "name": "@postgresx/noredis",
3
- "version": "0.1.0",
3
+ "version": "0.5.2",
4
4
  "description": "PostgreSQL-backed Redis feature replacement toolkit: KV/TTL cache, pub/sub, advisory locks, rate limiting, and pg-boss queues",
5
5
  "type": "module",
6
6
  "license": "MIT",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "https://github.com/zuohuadong/postgresx",
10
+ "directory": "packages/pgredis"
11
+ },
7
12
  "sideEffects": false,
8
13
  "files": [
9
14
  "dist/**/*",
@@ -27,22 +32,67 @@
27
32
  "import": "./dist/adapters/node.js",
28
33
  "default": "./dist/adapters/node.js"
29
34
  },
35
+ "./adapters/web": {
36
+ "types": "./dist/adapters/web.d.ts",
37
+ "import": "./dist/adapters/web.js",
38
+ "default": "./dist/adapters/web.js"
39
+ },
40
+ "./adapters/ioredis": {
41
+ "types": "./dist/adapters/ioredis.d.ts",
42
+ "import": "./dist/adapters/ioredis.js",
43
+ "default": "./dist/adapters/ioredis.js"
44
+ },
45
+ "./adapters/redis": {
46
+ "types": "./dist/adapters/redis.d.ts",
47
+ "import": "./dist/adapters/redis.js",
48
+ "default": "./dist/adapters/redis.js"
49
+ },
30
50
  "./kv-cache": {
31
51
  "types": "./dist/kv-cache.d.ts",
32
52
  "import": "./dist/kv-cache.js",
33
53
  "default": "./dist/kv-cache.js"
54
+ },
55
+ "./kv": {
56
+ "types": "./dist/kv.d.ts",
57
+ "import": "./dist/kv.js",
58
+ "default": "./dist/kv.js"
59
+ },
60
+ "./hash": {
61
+ "types": "./dist/hash-index.d.ts",
62
+ "import": "./dist/hash-index.js",
63
+ "default": "./dist/hash-index.js"
64
+ },
65
+ "./set": {
66
+ "types": "./dist/set-index.d.ts",
67
+ "import": "./dist/set-index.js",
68
+ "default": "./dist/set-index.js"
69
+ },
70
+ "./sorted-set": {
71
+ "types": "./dist/sorted-set-index.d.ts",
72
+ "import": "./dist/sorted-set-index.js",
73
+ "default": "./dist/sorted-set-index.js"
74
+ },
75
+ "./list": {
76
+ "types": "./dist/list-index.d.ts",
77
+ "import": "./dist/list-index.js",
78
+ "default": "./dist/list-index.js"
79
+ },
80
+ "./pubsub": {
81
+ "types": "./dist/pubsub-index.d.ts",
82
+ "import": "./dist/pubsub-index.js",
83
+ "default": "./dist/pubsub-index.js"
34
84
  }
35
85
  },
36
86
  "scripts": {
37
- "build": "tsup src/index.ts src/adapters/bun.ts src/adapters/node.ts src/kv-cache.ts --format esm --dts --clean --out-dir dist --external pg --external pg-boss --external @postgresx/bun-listen",
38
- "test": "bun test src/*.test.ts",
87
+ "build": "tsup src/index.ts src/adapters/bun.ts src/adapters/node.ts src/adapters/web.ts src/adapters/ioredis.ts src/adapters/redis.ts src/kv-cache.ts src/kv.ts src/hash-index.ts src/set-index.ts src/sorted-set-index.ts src/list-index.ts src/pubsub-index.ts --format esm --dts --clean --out-dir dist --external pg --external pg-boss --external @postgresx/bun-listen",
88
+ "test": "bun test src",
39
89
  "check": "tsc --noEmit -p tsconfig.json"
40
90
  },
41
91
  "devDependencies": {
42
92
  "@types/bun": "^1.3.14",
43
93
  "@types/node": "^25.0.0",
44
94
  "@types/pg": "^8.16.0",
45
- "@postgresx/bun-listen": "^0.1.0",
95
+ "@postgresx/bun-listen": "^0.3.0",
46
96
  "tsup": "^8.5.0",
47
97
  "typescript": "^6.0.3"
48
98
  }