@keyv/postgres 2.1.6 → 2.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +18 -12
- package/dist/index.d.cts +2 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +16 -10
- package/package.json +11 -26
package/dist/index.cjs
CHANGED
|
@@ -35,7 +35,7 @@ __export(index_exports, {
|
|
|
35
35
|
default: () => index_default
|
|
36
36
|
});
|
|
37
37
|
module.exports = __toCommonJS(index_exports);
|
|
38
|
-
var
|
|
38
|
+
var import_node_events = __toESM(require("events"), 1);
|
|
39
39
|
var import_keyv = __toESM(require("keyv"), 1);
|
|
40
40
|
|
|
41
41
|
// src/pool.ts
|
|
@@ -51,12 +51,12 @@ var pool = (uri, options = {}) => {
|
|
|
51
51
|
return postgresPool;
|
|
52
52
|
};
|
|
53
53
|
var endPool = async () => {
|
|
54
|
-
await postgresPool
|
|
54
|
+
await postgresPool?.end();
|
|
55
55
|
globalUri = void 0;
|
|
56
56
|
};
|
|
57
57
|
|
|
58
58
|
// src/index.ts
|
|
59
|
-
var KeyvPostgres = class extends
|
|
59
|
+
var KeyvPostgres = class extends import_node_events.default {
|
|
60
60
|
ttlSupport;
|
|
61
61
|
opts;
|
|
62
62
|
query;
|
|
@@ -77,13 +77,6 @@ var KeyvPostgres = class extends import_events.default {
|
|
|
77
77
|
...options
|
|
78
78
|
};
|
|
79
79
|
}
|
|
80
|
-
const connect = async () => {
|
|
81
|
-
const conn = pool(options.uri, options);
|
|
82
|
-
return async (sql, values) => {
|
|
83
|
-
const data = await conn.query(sql, values);
|
|
84
|
-
return data.rows;
|
|
85
|
-
};
|
|
86
|
-
};
|
|
87
80
|
this.opts = {
|
|
88
81
|
table: "keyv",
|
|
89
82
|
schema: "public",
|
|
@@ -94,7 +87,7 @@ var KeyvPostgres = class extends import_events.default {
|
|
|
94
87
|
if (this.opts.schema !== "public") {
|
|
95
88
|
createTable = `CREATE SCHEMA IF NOT EXISTS ${this.opts.schema}; ${createTable}`;
|
|
96
89
|
}
|
|
97
|
-
const connected = connect().then(async (query) => {
|
|
90
|
+
const connected = this.connect().then(async (query) => {
|
|
98
91
|
try {
|
|
99
92
|
await query(createTable);
|
|
100
93
|
} catch (error) {
|
|
@@ -123,6 +116,7 @@ var KeyvPostgres = class extends import_events.default {
|
|
|
123
116
|
}
|
|
124
117
|
return results;
|
|
125
118
|
}
|
|
119
|
+
// biome-ignore lint/suspicious/noExplicitAny: type format
|
|
126
120
|
async set(key, value) {
|
|
127
121
|
const upsert = `INSERT INTO ${this.opts.schema}.${this.opts.table} (key, value)
|
|
128
122
|
VALUES($1, $2)
|
|
@@ -158,7 +152,12 @@ var KeyvPostgres = class extends import_events.default {
|
|
|
158
152
|
const limit = Number.parseInt(String(this.opts.iterationLimit), 10) || 10;
|
|
159
153
|
async function* iterate(offset, options, query) {
|
|
160
154
|
const select = `SELECT * FROM ${options.schema}.${options.table} WHERE key LIKE $1 LIMIT $2 OFFSET $3`;
|
|
161
|
-
const entries = await query(select, [
|
|
155
|
+
const entries = await query(select, [
|
|
156
|
+
// biome-ignore lint/style/useTemplate: need to fix
|
|
157
|
+
`${namespace ? namespace + ":" : ""}%`,
|
|
158
|
+
limit,
|
|
159
|
+
offset
|
|
160
|
+
]);
|
|
162
161
|
if (entries.length === 0) {
|
|
163
162
|
return;
|
|
164
163
|
}
|
|
@@ -175,6 +174,13 @@ var KeyvPostgres = class extends import_events.default {
|
|
|
175
174
|
const rows = await this.query(exists, [key]);
|
|
176
175
|
return rows[0].exists;
|
|
177
176
|
}
|
|
177
|
+
async connect() {
|
|
178
|
+
const conn = pool(this.opts.uri, this.opts);
|
|
179
|
+
return async (sql, values) => {
|
|
180
|
+
const data = await conn.query(sql, values);
|
|
181
|
+
return data.rows;
|
|
182
|
+
};
|
|
183
|
+
}
|
|
178
184
|
async disconnect() {
|
|
179
185
|
await endPool();
|
|
180
186
|
}
|
package/dist/index.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import EventEmitter from 'events';
|
|
1
|
+
import EventEmitter from 'node:events';
|
|
2
2
|
import Keyv, { KeyvStoreAdapter } from 'keyv';
|
|
3
3
|
import { PoolConfig } from 'pg';
|
|
4
4
|
|
|
@@ -28,6 +28,7 @@ declare class KeyvPostgres extends EventEmitter implements KeyvStoreAdapter {
|
|
|
28
28
|
clear(): Promise<void>;
|
|
29
29
|
iterator(namespace?: string): AsyncGenerator<any, void, any>;
|
|
30
30
|
has(key: string): Promise<any>;
|
|
31
|
+
connect(): Promise<(sql: string, values?: any) => Promise<any[]>>;
|
|
31
32
|
disconnect(): Promise<void>;
|
|
32
33
|
}
|
|
33
34
|
declare const createKeyv: (options?: KeyvPostgresOptions) => Keyv<any>;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import EventEmitter from 'events';
|
|
1
|
+
import EventEmitter from 'node:events';
|
|
2
2
|
import Keyv, { KeyvStoreAdapter } from 'keyv';
|
|
3
3
|
import { PoolConfig } from 'pg';
|
|
4
4
|
|
|
@@ -28,6 +28,7 @@ declare class KeyvPostgres extends EventEmitter implements KeyvStoreAdapter {
|
|
|
28
28
|
clear(): Promise<void>;
|
|
29
29
|
iterator(namespace?: string): AsyncGenerator<any, void, any>;
|
|
30
30
|
has(key: string): Promise<any>;
|
|
31
|
+
connect(): Promise<(sql: string, values?: any) => Promise<any[]>>;
|
|
31
32
|
disconnect(): Promise<void>;
|
|
32
33
|
}
|
|
33
34
|
declare const createKeyv: (options?: KeyvPostgresOptions) => Keyv<any>;
|
package/dist/index.js
CHANGED
|
@@ -15,7 +15,7 @@ var pool = (uri, options = {}) => {
|
|
|
15
15
|
return postgresPool;
|
|
16
16
|
};
|
|
17
17
|
var endPool = async () => {
|
|
18
|
-
await postgresPool
|
|
18
|
+
await postgresPool?.end();
|
|
19
19
|
globalUri = void 0;
|
|
20
20
|
};
|
|
21
21
|
|
|
@@ -41,13 +41,6 @@ var KeyvPostgres = class extends EventEmitter {
|
|
|
41
41
|
...options
|
|
42
42
|
};
|
|
43
43
|
}
|
|
44
|
-
const connect = async () => {
|
|
45
|
-
const conn = pool(options.uri, options);
|
|
46
|
-
return async (sql, values) => {
|
|
47
|
-
const data = await conn.query(sql, values);
|
|
48
|
-
return data.rows;
|
|
49
|
-
};
|
|
50
|
-
};
|
|
51
44
|
this.opts = {
|
|
52
45
|
table: "keyv",
|
|
53
46
|
schema: "public",
|
|
@@ -58,7 +51,7 @@ var KeyvPostgres = class extends EventEmitter {
|
|
|
58
51
|
if (this.opts.schema !== "public") {
|
|
59
52
|
createTable = `CREATE SCHEMA IF NOT EXISTS ${this.opts.schema}; ${createTable}`;
|
|
60
53
|
}
|
|
61
|
-
const connected = connect().then(async (query) => {
|
|
54
|
+
const connected = this.connect().then(async (query) => {
|
|
62
55
|
try {
|
|
63
56
|
await query(createTable);
|
|
64
57
|
} catch (error) {
|
|
@@ -87,6 +80,7 @@ var KeyvPostgres = class extends EventEmitter {
|
|
|
87
80
|
}
|
|
88
81
|
return results;
|
|
89
82
|
}
|
|
83
|
+
// biome-ignore lint/suspicious/noExplicitAny: type format
|
|
90
84
|
async set(key, value) {
|
|
91
85
|
const upsert = `INSERT INTO ${this.opts.schema}.${this.opts.table} (key, value)
|
|
92
86
|
VALUES($1, $2)
|
|
@@ -122,7 +116,12 @@ var KeyvPostgres = class extends EventEmitter {
|
|
|
122
116
|
const limit = Number.parseInt(String(this.opts.iterationLimit), 10) || 10;
|
|
123
117
|
async function* iterate(offset, options, query) {
|
|
124
118
|
const select = `SELECT * FROM ${options.schema}.${options.table} WHERE key LIKE $1 LIMIT $2 OFFSET $3`;
|
|
125
|
-
const entries = await query(select, [
|
|
119
|
+
const entries = await query(select, [
|
|
120
|
+
// biome-ignore lint/style/useTemplate: need to fix
|
|
121
|
+
`${namespace ? namespace + ":" : ""}%`,
|
|
122
|
+
limit,
|
|
123
|
+
offset
|
|
124
|
+
]);
|
|
126
125
|
if (entries.length === 0) {
|
|
127
126
|
return;
|
|
128
127
|
}
|
|
@@ -139,6 +138,13 @@ var KeyvPostgres = class extends EventEmitter {
|
|
|
139
138
|
const rows = await this.query(exists, [key]);
|
|
140
139
|
return rows[0].exists;
|
|
141
140
|
}
|
|
141
|
+
async connect() {
|
|
142
|
+
const conn = pool(this.opts.uri, this.opts);
|
|
143
|
+
return async (sql, values) => {
|
|
144
|
+
const data = await conn.query(sql, values);
|
|
145
|
+
return data.rows;
|
|
146
|
+
};
|
|
147
|
+
}
|
|
142
148
|
async disconnect() {
|
|
143
149
|
await endPool();
|
|
144
150
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@keyv/postgres",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.2.0",
|
|
4
4
|
"description": "PostgreSQL storage adapter for Keyv",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.cjs",
|
|
@@ -12,23 +12,6 @@
|
|
|
12
12
|
"import": "./dist/index.js"
|
|
13
13
|
}
|
|
14
14
|
},
|
|
15
|
-
"xo": {
|
|
16
|
-
"rules": {
|
|
17
|
-
"import/no-named-as-default": "off",
|
|
18
|
-
"import/extensions": "off",
|
|
19
|
-
"n/file-extension-in-import": "off",
|
|
20
|
-
"unicorn/prefer-event-target": "off",
|
|
21
|
-
"promise/prefer-await-to-then": "off",
|
|
22
|
-
"unicorn/prefer-module": "off",
|
|
23
|
-
"@typescript-eslint/use-unknown-in-catch-callback-variable": "off",
|
|
24
|
-
"unicorn/prefer-node-protocol": "off",
|
|
25
|
-
"@typescript-eslint/no-unsafe-return": "off",
|
|
26
|
-
"@typescript-eslint/no-confusing-void-expression": "off",
|
|
27
|
-
"import/no-extraneous-dependencies": "off",
|
|
28
|
-
"@typescript-eslint/no-unnecessary-type-assertion": "off",
|
|
29
|
-
"@typescript-eslint/no-unnecessary-type-arguments": "off"
|
|
30
|
-
}
|
|
31
|
-
},
|
|
32
15
|
"repository": {
|
|
33
16
|
"type": "git",
|
|
34
17
|
"url": "git+https://github.com/jaredwray/keyv.git"
|
|
@@ -53,19 +36,19 @@
|
|
|
53
36
|
},
|
|
54
37
|
"homepage": "https://github.com/jaredwray/keyv",
|
|
55
38
|
"dependencies": {
|
|
56
|
-
"pg": "^8.16.
|
|
39
|
+
"pg": "^8.16.3"
|
|
57
40
|
},
|
|
58
41
|
"peerDependencies": {
|
|
59
|
-
"keyv": "^5.
|
|
42
|
+
"keyv": "^5.5.4"
|
|
60
43
|
},
|
|
61
44
|
"devDependencies": {
|
|
62
|
-
"@
|
|
45
|
+
"@biomejs/biome": "^2.2.6",
|
|
46
|
+
"@types/pg": "^8.15.5",
|
|
63
47
|
"@vitest/coverage-v8": "^3.2.4",
|
|
64
48
|
"rimraf": "^6.0.1",
|
|
65
|
-
"tsd": "^0.
|
|
49
|
+
"tsd": "^0.33.0",
|
|
66
50
|
"vitest": "^3.2.4",
|
|
67
|
-
"
|
|
68
|
-
"@keyv/test-suite": "^2.0.8"
|
|
51
|
+
"@keyv/test-suite": "^2.1.1"
|
|
69
52
|
},
|
|
70
53
|
"tsd": {
|
|
71
54
|
"directory": "test"
|
|
@@ -79,8 +62,10 @@
|
|
|
79
62
|
],
|
|
80
63
|
"scripts": {
|
|
81
64
|
"build": "rimraf ./dist && tsup src/index.ts --format cjs,esm --dts --clean",
|
|
82
|
-
"
|
|
83
|
-
"
|
|
65
|
+
"lint": "biome check --write --error-on-warnings",
|
|
66
|
+
"lint:ci": "biome check --error-on-warnings",
|
|
67
|
+
"test": "pnpm lint && vitest run --coverage",
|
|
68
|
+
"test:ci": "pnpm lint:ci && vitest --run --sequence.setupFiles=list --coverage",
|
|
84
69
|
"clean": "rimraf ./node_modules ./coverage ./dist"
|
|
85
70
|
}
|
|
86
71
|
}
|