@fedify/postgres 2.1.21 → 2.1.23
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 +9 -5
- package/dist/kv.d.cts +4 -0
- package/dist/kv.d.ts +4 -0
- package/dist/kv.js +9 -5
- package/dist/mq.cjs +9 -5
- package/dist/mq.d.cts +4 -0
- package/dist/mq.d.ts +4 -0
- package/dist/mq.js +9 -5
- package/package.json +3 -3
package/dist/kv.cjs
CHANGED
|
@@ -26,7 +26,8 @@ const logger = (0, require("@logtape/logtape").getLogger)([
|
|
|
26
26
|
var PostgresKvStore = class {
|
|
27
27
|
#sql;
|
|
28
28
|
#tableName;
|
|
29
|
-
#
|
|
29
|
+
#skipDdl;
|
|
30
|
+
#initialized = false;
|
|
30
31
|
#driverSerializesJson = false;
|
|
31
32
|
/**
|
|
32
33
|
* Creates a new PostgreSQL key–value store.
|
|
@@ -36,7 +37,7 @@ var PostgresKvStore = class {
|
|
|
36
37
|
constructor(sql, options = {}) {
|
|
37
38
|
this.#sql = sql;
|
|
38
39
|
this.#tableName = options.tableName ?? "fedify_kv_v2";
|
|
39
|
-
this.#
|
|
40
|
+
this.#skipDdl = options.initialized ?? false;
|
|
40
41
|
}
|
|
41
42
|
async #expire() {
|
|
42
43
|
await this.#sql`
|
|
@@ -113,6 +114,12 @@ var PostgresKvStore = class {
|
|
|
113
114
|
async initialize() {
|
|
114
115
|
if (this.#initialized) return;
|
|
115
116
|
logger.debug("Initializing the key–value store table {tableName}...", { tableName: this.#tableName });
|
|
117
|
+
if (!this.#skipDdl) await this.#initializeTable();
|
|
118
|
+
this.#driverSerializesJson = await require_utils.driverSerializesJson(this.#sql);
|
|
119
|
+
this.#initialized = true;
|
|
120
|
+
logger.debug("Initialized the key–value store table {tableName}.", { tableName: this.#tableName });
|
|
121
|
+
}
|
|
122
|
+
async #initializeTable() {
|
|
116
123
|
await this.#sql`
|
|
117
124
|
CREATE UNLOGGED TABLE IF NOT EXISTS ${this.#sql(this.#tableName)} (
|
|
118
125
|
key text[] PRIMARY KEY,
|
|
@@ -121,9 +128,6 @@ var PostgresKvStore = class {
|
|
|
121
128
|
ttl interval
|
|
122
129
|
);
|
|
123
130
|
`;
|
|
124
|
-
this.#driverSerializesJson = await require_utils.driverSerializesJson(this.#sql);
|
|
125
|
-
this.#initialized = true;
|
|
126
|
-
logger.debug("Initialized the key–value store table {tableName}.", { tableName: this.#tableName });
|
|
127
131
|
}
|
|
128
132
|
/**
|
|
129
133
|
* Drops the table used by the key–value store. Does nothing if the table
|
package/dist/kv.d.cts
CHANGED
|
@@ -15,6 +15,10 @@ interface PostgresKvStoreOptions {
|
|
|
15
15
|
readonly tableName?: string;
|
|
16
16
|
/**
|
|
17
17
|
* Whether the table has been initialized. `false` by default.
|
|
18
|
+
*
|
|
19
|
+
* This skips only the table's schema DDL. Driver-specific runtime setup,
|
|
20
|
+
* such as detecting whether the driver serializes JSON parameters on its
|
|
21
|
+
* own, still runs before the first key is read or written.
|
|
18
22
|
* @default `false`
|
|
19
23
|
*/
|
|
20
24
|
readonly initialized?: boolean;
|
package/dist/kv.d.ts
CHANGED
|
@@ -15,6 +15,10 @@ interface PostgresKvStoreOptions {
|
|
|
15
15
|
readonly tableName?: string;
|
|
16
16
|
/**
|
|
17
17
|
* Whether the table has been initialized. `false` by default.
|
|
18
|
+
*
|
|
19
|
+
* This skips only the table's schema DDL. Driver-specific runtime setup,
|
|
20
|
+
* such as detecting whether the driver serializes JSON parameters on its
|
|
21
|
+
* own, still runs before the first key is read or written.
|
|
18
22
|
* @default `false`
|
|
19
23
|
*/
|
|
20
24
|
readonly initialized?: boolean;
|
package/dist/kv.js
CHANGED
|
@@ -25,7 +25,8 @@ const logger = getLogger([
|
|
|
25
25
|
var PostgresKvStore = class {
|
|
26
26
|
#sql;
|
|
27
27
|
#tableName;
|
|
28
|
-
#
|
|
28
|
+
#skipDdl;
|
|
29
|
+
#initialized = false;
|
|
29
30
|
#driverSerializesJson = false;
|
|
30
31
|
/**
|
|
31
32
|
* Creates a new PostgreSQL key–value store.
|
|
@@ -35,7 +36,7 @@ var PostgresKvStore = class {
|
|
|
35
36
|
constructor(sql, options = {}) {
|
|
36
37
|
this.#sql = sql;
|
|
37
38
|
this.#tableName = options.tableName ?? "fedify_kv_v2";
|
|
38
|
-
this.#
|
|
39
|
+
this.#skipDdl = options.initialized ?? false;
|
|
39
40
|
}
|
|
40
41
|
async #expire() {
|
|
41
42
|
await this.#sql`
|
|
@@ -112,6 +113,12 @@ var PostgresKvStore = class {
|
|
|
112
113
|
async initialize() {
|
|
113
114
|
if (this.#initialized) return;
|
|
114
115
|
logger.debug("Initializing the key–value store table {tableName}...", { tableName: this.#tableName });
|
|
116
|
+
if (!this.#skipDdl) await this.#initializeTable();
|
|
117
|
+
this.#driverSerializesJson = await driverSerializesJson(this.#sql);
|
|
118
|
+
this.#initialized = true;
|
|
119
|
+
logger.debug("Initialized the key–value store table {tableName}.", { tableName: this.#tableName });
|
|
120
|
+
}
|
|
121
|
+
async #initializeTable() {
|
|
115
122
|
await this.#sql`
|
|
116
123
|
CREATE UNLOGGED TABLE IF NOT EXISTS ${this.#sql(this.#tableName)} (
|
|
117
124
|
key text[] PRIMARY KEY,
|
|
@@ -120,9 +127,6 @@ var PostgresKvStore = class {
|
|
|
120
127
|
ttl interval
|
|
121
128
|
);
|
|
122
129
|
`;
|
|
123
|
-
this.#driverSerializesJson = await driverSerializesJson(this.#sql);
|
|
124
|
-
this.#initialized = true;
|
|
125
|
-
logger.debug("Initialized the key–value store table {tableName}.", { tableName: this.#tableName });
|
|
126
130
|
}
|
|
127
131
|
/**
|
|
128
132
|
* Drops the table used by the key–value store. Does nothing if the table
|
package/dist/mq.cjs
CHANGED
|
@@ -56,7 +56,8 @@ var PostgresMessageQueue = class {
|
|
|
56
56
|
#channelName;
|
|
57
57
|
#pollIntervalMs;
|
|
58
58
|
#handlerTimeoutMs;
|
|
59
|
-
#
|
|
59
|
+
#skipDdl;
|
|
60
|
+
#initialized = false;
|
|
60
61
|
#initPromise;
|
|
61
62
|
#driverSerializesJson = false;
|
|
62
63
|
constructor(sql, options = {}) {
|
|
@@ -65,7 +66,7 @@ var PostgresMessageQueue = class {
|
|
|
65
66
|
this.#channelName = options?.channelName ?? "fedify_channel";
|
|
66
67
|
this.#pollIntervalMs = Temporal.Duration.from(options?.pollInterval ?? { seconds: 5 }).total("millisecond");
|
|
67
68
|
this.#handlerTimeoutMs = Temporal.Duration.from(options?.handlerTimeout ?? { seconds: 60 }).total("millisecond");
|
|
68
|
-
this.#
|
|
69
|
+
this.#skipDdl = options?.initialized ?? false;
|
|
69
70
|
}
|
|
70
71
|
async enqueue(message, options) {
|
|
71
72
|
await this.initialize();
|
|
@@ -278,6 +279,12 @@ var PostgresMessageQueue = class {
|
|
|
278
279
|
}
|
|
279
280
|
async #doInitialize() {
|
|
280
281
|
logger.debug("Initializing the message queue table {tableName}...", { tableName: this.#tableName });
|
|
282
|
+
if (!this.#skipDdl) await this.#initializeTable();
|
|
283
|
+
this.#driverSerializesJson = await require_utils.driverSerializesJson(this.#sql);
|
|
284
|
+
this.#initialized = true;
|
|
285
|
+
logger.debug("Initialized the message queue table {tableName}.", { tableName: this.#tableName });
|
|
286
|
+
}
|
|
287
|
+
async #initializeTable() {
|
|
281
288
|
for (let attempt = 1; attempt <= INITIALIZE_MAX_ATTEMPTS; attempt++) try {
|
|
282
289
|
await this.#sql`
|
|
283
290
|
CREATE TABLE IF NOT EXISTS ${this.#sql(this.#tableName)} (
|
|
@@ -312,9 +319,6 @@ var PostgresMessageQueue = class {
|
|
|
312
319
|
});
|
|
313
320
|
await sleep(backoffMs);
|
|
314
321
|
}
|
|
315
|
-
this.#driverSerializesJson = await require_utils.driverSerializesJson(this.#sql);
|
|
316
|
-
this.#initialized = true;
|
|
317
|
-
logger.debug("Initialized the message queue table {tableName}.", { tableName: this.#tableName });
|
|
318
322
|
}
|
|
319
323
|
/**
|
|
320
324
|
* Drops the message queue table if it exists.
|
package/dist/mq.d.cts
CHANGED
|
@@ -21,6 +21,10 @@ interface PostgresMessageQueueOptions {
|
|
|
21
21
|
readonly channelName?: string;
|
|
22
22
|
/**
|
|
23
23
|
* Whether the table has been initialized. `false` by default.
|
|
24
|
+
*
|
|
25
|
+
* This skips only the table's schema DDL. Driver-specific runtime setup,
|
|
26
|
+
* such as detecting whether the driver serializes JSON parameters on its
|
|
27
|
+
* own, still runs before the first message is enqueued.
|
|
24
28
|
* @default `false`
|
|
25
29
|
*/
|
|
26
30
|
readonly initialized?: boolean;
|
package/dist/mq.d.ts
CHANGED
|
@@ -21,6 +21,10 @@ interface PostgresMessageQueueOptions {
|
|
|
21
21
|
readonly channelName?: string;
|
|
22
22
|
/**
|
|
23
23
|
* Whether the table has been initialized. `false` by default.
|
|
24
|
+
*
|
|
25
|
+
* This skips only the table's schema DDL. Driver-specific runtime setup,
|
|
26
|
+
* such as detecting whether the driver serializes JSON parameters on its
|
|
27
|
+
* own, still runs before the first message is enqueued.
|
|
24
28
|
* @default `false`
|
|
25
29
|
*/
|
|
26
30
|
readonly initialized?: boolean;
|
package/dist/mq.js
CHANGED
|
@@ -53,7 +53,8 @@ var PostgresMessageQueue = class {
|
|
|
53
53
|
#channelName;
|
|
54
54
|
#pollIntervalMs;
|
|
55
55
|
#handlerTimeoutMs;
|
|
56
|
-
#
|
|
56
|
+
#skipDdl;
|
|
57
|
+
#initialized = false;
|
|
57
58
|
#initPromise;
|
|
58
59
|
#driverSerializesJson = false;
|
|
59
60
|
constructor(sql, options = {}) {
|
|
@@ -62,7 +63,7 @@ var PostgresMessageQueue = class {
|
|
|
62
63
|
this.#channelName = options?.channelName ?? "fedify_channel";
|
|
63
64
|
this.#pollIntervalMs = Temporal.Duration.from(options?.pollInterval ?? { seconds: 5 }).total("millisecond");
|
|
64
65
|
this.#handlerTimeoutMs = Temporal.Duration.from(options?.handlerTimeout ?? { seconds: 60 }).total("millisecond");
|
|
65
|
-
this.#
|
|
66
|
+
this.#skipDdl = options?.initialized ?? false;
|
|
66
67
|
}
|
|
67
68
|
async enqueue(message, options) {
|
|
68
69
|
await this.initialize();
|
|
@@ -275,6 +276,12 @@ var PostgresMessageQueue = class {
|
|
|
275
276
|
}
|
|
276
277
|
async #doInitialize() {
|
|
277
278
|
logger.debug("Initializing the message queue table {tableName}...", { tableName: this.#tableName });
|
|
279
|
+
if (!this.#skipDdl) await this.#initializeTable();
|
|
280
|
+
this.#driverSerializesJson = await driverSerializesJson(this.#sql);
|
|
281
|
+
this.#initialized = true;
|
|
282
|
+
logger.debug("Initialized the message queue table {tableName}.", { tableName: this.#tableName });
|
|
283
|
+
}
|
|
284
|
+
async #initializeTable() {
|
|
278
285
|
for (let attempt = 1; attempt <= INITIALIZE_MAX_ATTEMPTS; attempt++) try {
|
|
279
286
|
await this.#sql`
|
|
280
287
|
CREATE TABLE IF NOT EXISTS ${this.#sql(this.#tableName)} (
|
|
@@ -309,9 +316,6 @@ var PostgresMessageQueue = class {
|
|
|
309
316
|
});
|
|
310
317
|
await sleep(backoffMs);
|
|
311
318
|
}
|
|
312
|
-
this.#driverSerializesJson = await driverSerializesJson(this.#sql);
|
|
313
|
-
this.#initialized = true;
|
|
314
|
-
logger.debug("Initialized the message queue table {tableName}.", { tableName: this.#tableName });
|
|
315
319
|
}
|
|
316
320
|
/**
|
|
317
321
|
* Drops the message queue table if it exists.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fedify/postgres",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.23",
|
|
4
4
|
"description": "PostgreSQL drivers for Fedify",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"fedify",
|
|
@@ -74,14 +74,14 @@
|
|
|
74
74
|
},
|
|
75
75
|
"peerDependencies": {
|
|
76
76
|
"postgres": "^3.4.7",
|
|
77
|
-
"@fedify/fedify": "^2.1.
|
|
77
|
+
"@fedify/fedify": "^2.1.23"
|
|
78
78
|
},
|
|
79
79
|
"devDependencies": {
|
|
80
80
|
"@std/async": "npm:@jsr/std__async@^1.0.13",
|
|
81
81
|
"tsdown": "^0.21.6",
|
|
82
82
|
"typescript": "^6.0.0",
|
|
83
83
|
"@fedify/fixture": "^2.0.0",
|
|
84
|
-
"@fedify/testing": "^2.1.
|
|
84
|
+
"@fedify/testing": "^2.1.23"
|
|
85
85
|
},
|
|
86
86
|
"scripts": {
|
|
87
87
|
"build:self": "tsdown",
|