@fedify/postgres 2.0.0-dev.1961 → 2.0.0-dev.85
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/kv.cjs +29 -0
- package/dist/kv.d.cts +6 -1
- package/dist/kv.d.ts +6 -1
- package/dist/kv.js +29 -0
- package/package.json +3 -3
package/dist/kv.cjs
CHANGED
|
@@ -81,6 +81,35 @@ var PostgresKvStore = class {
|
|
|
81
81
|
await this.#expire();
|
|
82
82
|
}
|
|
83
83
|
/**
|
|
84
|
+
* {@inheritDoc KvStore.list}
|
|
85
|
+
* @since 1.10.0
|
|
86
|
+
*/
|
|
87
|
+
async *list(prefix) {
|
|
88
|
+
await this.initialize();
|
|
89
|
+
let results;
|
|
90
|
+
if (prefix == null || prefix.length === 0) results = await this.#sql`
|
|
91
|
+
SELECT key, value
|
|
92
|
+
FROM ${this.#sql(this.#tableName)}
|
|
93
|
+
WHERE ttl IS NULL OR created + ttl > CURRENT_TIMESTAMP
|
|
94
|
+
ORDER BY key
|
|
95
|
+
`;
|
|
96
|
+
else {
|
|
97
|
+
const prefixLength = prefix.length;
|
|
98
|
+
results = await this.#sql`
|
|
99
|
+
SELECT key, value
|
|
100
|
+
FROM ${this.#sql(this.#tableName)}
|
|
101
|
+
WHERE array_length(key, 1) >= ${prefixLength}
|
|
102
|
+
AND key[1:${prefixLength}] = ${prefix}::text[]
|
|
103
|
+
AND (ttl IS NULL OR created + ttl > CURRENT_TIMESTAMP)
|
|
104
|
+
ORDER BY key
|
|
105
|
+
`;
|
|
106
|
+
}
|
|
107
|
+
for (const row of results) yield {
|
|
108
|
+
key: row.key,
|
|
109
|
+
value: row.value
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
84
113
|
* Creates the table used by the key–value store if it does not already exist.
|
|
85
114
|
* Does nothing if the table already exists.
|
|
86
115
|
*/
|
package/dist/kv.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { KvKey, KvStore, KvStoreSetOptions } from "@fedify/fedify";
|
|
1
|
+
import { KvKey, KvStore, KvStoreListEntry, KvStoreSetOptions } from "@fedify/fedify";
|
|
2
2
|
import { Sql } from "postgres";
|
|
3
3
|
|
|
4
4
|
//#region src/kv.d.ts
|
|
@@ -44,6 +44,11 @@ declare class PostgresKvStore implements KvStore {
|
|
|
44
44
|
get<T = unknown>(key: KvKey): Promise<T | undefined>;
|
|
45
45
|
set(key: KvKey, value: unknown, options?: KvStoreSetOptions | undefined): Promise<void>;
|
|
46
46
|
delete(key: KvKey): Promise<void>;
|
|
47
|
+
/**
|
|
48
|
+
* {@inheritDoc KvStore.list}
|
|
49
|
+
* @since 1.10.0
|
|
50
|
+
*/
|
|
51
|
+
list(prefix?: KvKey): AsyncIterable<KvStoreListEntry>;
|
|
47
52
|
/**
|
|
48
53
|
* Creates the table used by the key–value store if it does not already exist.
|
|
49
54
|
* Does nothing if the table already exists.
|
package/dist/kv.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Temporal } from "@js-temporal/polyfill";
|
|
2
2
|
import { Sql } from "postgres";
|
|
3
|
-
import { KvKey, KvStore, KvStoreSetOptions } from "@fedify/fedify";
|
|
3
|
+
import { KvKey, KvStore, KvStoreListEntry, KvStoreSetOptions } from "@fedify/fedify";
|
|
4
4
|
|
|
5
5
|
//#region src/kv.d.ts
|
|
6
6
|
/**
|
|
@@ -45,6 +45,11 @@ declare class PostgresKvStore implements KvStore {
|
|
|
45
45
|
get<T = unknown>(key: KvKey): Promise<T | undefined>;
|
|
46
46
|
set(key: KvKey, value: unknown, options?: KvStoreSetOptions | undefined): Promise<void>;
|
|
47
47
|
delete(key: KvKey): Promise<void>;
|
|
48
|
+
/**
|
|
49
|
+
* {@inheritDoc KvStore.list}
|
|
50
|
+
* @since 1.10.0
|
|
51
|
+
*/
|
|
52
|
+
list(prefix?: KvKey): AsyncIterable<KvStoreListEntry>;
|
|
48
53
|
/**
|
|
49
54
|
* Creates the table used by the key–value store if it does not already exist.
|
|
50
55
|
* Does nothing if the table already exists.
|
package/dist/kv.js
CHANGED
|
@@ -80,6 +80,35 @@ var PostgresKvStore = class {
|
|
|
80
80
|
await this.#expire();
|
|
81
81
|
}
|
|
82
82
|
/**
|
|
83
|
+
* {@inheritDoc KvStore.list}
|
|
84
|
+
* @since 1.10.0
|
|
85
|
+
*/
|
|
86
|
+
async *list(prefix) {
|
|
87
|
+
await this.initialize();
|
|
88
|
+
let results;
|
|
89
|
+
if (prefix == null || prefix.length === 0) results = await this.#sql`
|
|
90
|
+
SELECT key, value
|
|
91
|
+
FROM ${this.#sql(this.#tableName)}
|
|
92
|
+
WHERE ttl IS NULL OR created + ttl > CURRENT_TIMESTAMP
|
|
93
|
+
ORDER BY key
|
|
94
|
+
`;
|
|
95
|
+
else {
|
|
96
|
+
const prefixLength = prefix.length;
|
|
97
|
+
results = await this.#sql`
|
|
98
|
+
SELECT key, value
|
|
99
|
+
FROM ${this.#sql(this.#tableName)}
|
|
100
|
+
WHERE array_length(key, 1) >= ${prefixLength}
|
|
101
|
+
AND key[1:${prefixLength}] = ${prefix}::text[]
|
|
102
|
+
AND (ttl IS NULL OR created + ttl > CURRENT_TIMESTAMP)
|
|
103
|
+
ORDER BY key
|
|
104
|
+
`;
|
|
105
|
+
}
|
|
106
|
+
for (const row of results) yield {
|
|
107
|
+
key: row.key,
|
|
108
|
+
value: row.value
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
83
112
|
* Creates the table used by the key–value store if it does not already exist.
|
|
84
113
|
* Does nothing if the table already exists.
|
|
85
114
|
*/
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fedify/postgres",
|
|
3
|
-
"version": "2.0.0-dev.
|
|
3
|
+
"version": "2.0.0-dev.85+a55c8362",
|
|
4
4
|
"description": "PostgreSQL drivers for Fedify",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"fedify",
|
|
@@ -70,11 +70,11 @@
|
|
|
70
70
|
],
|
|
71
71
|
"dependencies": {
|
|
72
72
|
"@js-temporal/polyfill": "^0.5.1",
|
|
73
|
-
"@logtape/logtape": "^1.
|
|
73
|
+
"@logtape/logtape": "^1.3.5"
|
|
74
74
|
},
|
|
75
75
|
"peerDependencies": {
|
|
76
76
|
"postgres": "^3.4.7",
|
|
77
|
-
"@fedify/fedify": "^2.0.0-dev.
|
|
77
|
+
"@fedify/fedify": "^2.0.0-dev.85+a55c8362"
|
|
78
78
|
},
|
|
79
79
|
"devDependencies": {
|
|
80
80
|
"@std/async": "npm:@jsr/std__async@^1.0.13",
|