@fedify/postgres 2.4.0-dev.1936 → 2.4.0-dev.1959
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 +31 -27
- package/dist/kv.d.cts +4 -0
- package/dist/kv.d.ts +4 -0
- package/dist/kv.js +31 -27
- 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
|
@@ -32,7 +32,8 @@ var PostgresKvStore = class {
|
|
|
32
32
|
#sql;
|
|
33
33
|
#tableName;
|
|
34
34
|
#unlogged;
|
|
35
|
-
#
|
|
35
|
+
#skipDdl;
|
|
36
|
+
#initialized = false;
|
|
36
37
|
#initializing;
|
|
37
38
|
#driverSerializesJson = false;
|
|
38
39
|
/**
|
|
@@ -44,7 +45,7 @@ var PostgresKvStore = class {
|
|
|
44
45
|
this.#sql = sql;
|
|
45
46
|
this.#tableName = options.tableName ?? "fedify_kv_v2";
|
|
46
47
|
this.#unlogged = options.unlogged ?? false;
|
|
47
|
-
this.#
|
|
48
|
+
this.#skipDdl = options.initialized ?? false;
|
|
48
49
|
}
|
|
49
50
|
async #expire() {
|
|
50
51
|
await this.#sql`
|
|
@@ -173,31 +174,7 @@ var PostgresKvStore = class {
|
|
|
173
174
|
if (this.#initialized) return;
|
|
174
175
|
this.#initializing ??= (async () => {
|
|
175
176
|
logger.debug("Initializing the key–value store table {tableName}...", { tableName: this.#tableName });
|
|
176
|
-
if (this.#
|
|
177
|
-
CREATE UNLOGGED TABLE IF NOT EXISTS ${this.#sql(this.#tableName)} (
|
|
178
|
-
key text[] PRIMARY KEY,
|
|
179
|
-
value jsonb NOT NULL,
|
|
180
|
-
created timestamp with time zone DEFAULT CURRENT_TIMESTAMP,
|
|
181
|
-
ttl interval
|
|
182
|
-
);
|
|
183
|
-
`;
|
|
184
|
-
else {
|
|
185
|
-
await this.#sql`
|
|
186
|
-
CREATE TABLE IF NOT EXISTS ${this.#sql(this.#tableName)} (
|
|
187
|
-
key text[] PRIMARY KEY,
|
|
188
|
-
value jsonb NOT NULL,
|
|
189
|
-
created timestamp with time zone DEFAULT CURRENT_TIMESTAMP,
|
|
190
|
-
ttl interval
|
|
191
|
-
);
|
|
192
|
-
`;
|
|
193
|
-
if ((await this.#sql`
|
|
194
|
-
SELECT relpersistence
|
|
195
|
-
FROM pg_class
|
|
196
|
-
WHERE oid = to_regclass(${quoteIdentifier(this.#tableName)});
|
|
197
|
-
`)[0]?.relpersistence === "u") await this.#sql`
|
|
198
|
-
ALTER TABLE ${this.#sql(this.#tableName)} SET LOGGED;
|
|
199
|
-
`;
|
|
200
|
-
}
|
|
177
|
+
if (!this.#skipDdl) await this.#initializeTable();
|
|
201
178
|
this.#driverSerializesJson = await require_utils.driverSerializesJson(this.#sql);
|
|
202
179
|
this.#initialized = true;
|
|
203
180
|
logger.debug("Initialized the key–value store table {tableName}.", { tableName: this.#tableName });
|
|
@@ -209,6 +186,33 @@ var PostgresKvStore = class {
|
|
|
209
186
|
throw error;
|
|
210
187
|
}
|
|
211
188
|
}
|
|
189
|
+
async #initializeTable() {
|
|
190
|
+
if (this.#unlogged) await this.#sql`
|
|
191
|
+
CREATE UNLOGGED TABLE IF NOT EXISTS ${this.#sql(this.#tableName)} (
|
|
192
|
+
key text[] PRIMARY KEY,
|
|
193
|
+
value jsonb NOT NULL,
|
|
194
|
+
created timestamp with time zone DEFAULT CURRENT_TIMESTAMP,
|
|
195
|
+
ttl interval
|
|
196
|
+
);
|
|
197
|
+
`;
|
|
198
|
+
else {
|
|
199
|
+
await this.#sql`
|
|
200
|
+
CREATE TABLE IF NOT EXISTS ${this.#sql(this.#tableName)} (
|
|
201
|
+
key text[] PRIMARY KEY,
|
|
202
|
+
value jsonb NOT NULL,
|
|
203
|
+
created timestamp with time zone DEFAULT CURRENT_TIMESTAMP,
|
|
204
|
+
ttl interval
|
|
205
|
+
);
|
|
206
|
+
`;
|
|
207
|
+
if ((await this.#sql`
|
|
208
|
+
SELECT relpersistence
|
|
209
|
+
FROM pg_class
|
|
210
|
+
WHERE oid = to_regclass(${quoteIdentifier(this.#tableName)});
|
|
211
|
+
`)[0]?.relpersistence === "u") await this.#sql`
|
|
212
|
+
ALTER TABLE ${this.#sql(this.#tableName)} SET LOGGED;
|
|
213
|
+
`;
|
|
214
|
+
}
|
|
215
|
+
}
|
|
212
216
|
/**
|
|
213
217
|
* Drops the table used by the key–value store. Does nothing if the table
|
|
214
218
|
* does not exist.
|
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
|
@@ -29,7 +29,8 @@ var PostgresKvStore = class {
|
|
|
29
29
|
#sql;
|
|
30
30
|
#tableName;
|
|
31
31
|
#unlogged;
|
|
32
|
-
#
|
|
32
|
+
#skipDdl;
|
|
33
|
+
#initialized = false;
|
|
33
34
|
#initializing;
|
|
34
35
|
#driverSerializesJson = false;
|
|
35
36
|
/**
|
|
@@ -41,7 +42,7 @@ var PostgresKvStore = class {
|
|
|
41
42
|
this.#sql = sql;
|
|
42
43
|
this.#tableName = options.tableName ?? "fedify_kv_v2";
|
|
43
44
|
this.#unlogged = options.unlogged ?? false;
|
|
44
|
-
this.#
|
|
45
|
+
this.#skipDdl = options.initialized ?? false;
|
|
45
46
|
}
|
|
46
47
|
async #expire() {
|
|
47
48
|
await this.#sql`
|
|
@@ -170,31 +171,7 @@ var PostgresKvStore = class {
|
|
|
170
171
|
if (this.#initialized) return;
|
|
171
172
|
this.#initializing ??= (async () => {
|
|
172
173
|
logger.debug("Initializing the key–value store table {tableName}...", { tableName: this.#tableName });
|
|
173
|
-
if (this.#
|
|
174
|
-
CREATE UNLOGGED TABLE IF NOT EXISTS ${this.#sql(this.#tableName)} (
|
|
175
|
-
key text[] PRIMARY KEY,
|
|
176
|
-
value jsonb NOT NULL,
|
|
177
|
-
created timestamp with time zone DEFAULT CURRENT_TIMESTAMP,
|
|
178
|
-
ttl interval
|
|
179
|
-
);
|
|
180
|
-
`;
|
|
181
|
-
else {
|
|
182
|
-
await this.#sql`
|
|
183
|
-
CREATE TABLE IF NOT EXISTS ${this.#sql(this.#tableName)} (
|
|
184
|
-
key text[] PRIMARY KEY,
|
|
185
|
-
value jsonb NOT NULL,
|
|
186
|
-
created timestamp with time zone DEFAULT CURRENT_TIMESTAMP,
|
|
187
|
-
ttl interval
|
|
188
|
-
);
|
|
189
|
-
`;
|
|
190
|
-
if ((await this.#sql`
|
|
191
|
-
SELECT relpersistence
|
|
192
|
-
FROM pg_class
|
|
193
|
-
WHERE oid = to_regclass(${quoteIdentifier(this.#tableName)});
|
|
194
|
-
`)[0]?.relpersistence === "u") await this.#sql`
|
|
195
|
-
ALTER TABLE ${this.#sql(this.#tableName)} SET LOGGED;
|
|
196
|
-
`;
|
|
197
|
-
}
|
|
174
|
+
if (!this.#skipDdl) await this.#initializeTable();
|
|
198
175
|
this.#driverSerializesJson = await driverSerializesJson(this.#sql);
|
|
199
176
|
this.#initialized = true;
|
|
200
177
|
logger.debug("Initialized the key–value store table {tableName}.", { tableName: this.#tableName });
|
|
@@ -206,6 +183,33 @@ var PostgresKvStore = class {
|
|
|
206
183
|
throw error;
|
|
207
184
|
}
|
|
208
185
|
}
|
|
186
|
+
async #initializeTable() {
|
|
187
|
+
if (this.#unlogged) await this.#sql`
|
|
188
|
+
CREATE UNLOGGED TABLE IF NOT EXISTS ${this.#sql(this.#tableName)} (
|
|
189
|
+
key text[] PRIMARY KEY,
|
|
190
|
+
value jsonb NOT NULL,
|
|
191
|
+
created timestamp with time zone DEFAULT CURRENT_TIMESTAMP,
|
|
192
|
+
ttl interval
|
|
193
|
+
);
|
|
194
|
+
`;
|
|
195
|
+
else {
|
|
196
|
+
await this.#sql`
|
|
197
|
+
CREATE TABLE IF NOT EXISTS ${this.#sql(this.#tableName)} (
|
|
198
|
+
key text[] PRIMARY KEY,
|
|
199
|
+
value jsonb NOT NULL,
|
|
200
|
+
created timestamp with time zone DEFAULT CURRENT_TIMESTAMP,
|
|
201
|
+
ttl interval
|
|
202
|
+
);
|
|
203
|
+
`;
|
|
204
|
+
if ((await this.#sql`
|
|
205
|
+
SELECT relpersistence
|
|
206
|
+
FROM pg_class
|
|
207
|
+
WHERE oid = to_regclass(${quoteIdentifier(this.#tableName)});
|
|
208
|
+
`)[0]?.relpersistence === "u") await this.#sql`
|
|
209
|
+
ALTER TABLE ${this.#sql(this.#tableName)} SET LOGGED;
|
|
210
|
+
`;
|
|
211
|
+
}
|
|
212
|
+
}
|
|
209
213
|
/**
|
|
210
214
|
* Drops the table used by the key–value store. Does nothing if the table
|
|
211
215
|
* does not exist.
|
package/dist/mq.cjs
CHANGED
|
@@ -63,7 +63,8 @@ var PostgresMessageQueue = class {
|
|
|
63
63
|
#channelName;
|
|
64
64
|
#pollIntervalMs;
|
|
65
65
|
#handlerTimeoutMs;
|
|
66
|
-
#
|
|
66
|
+
#skipDdl;
|
|
67
|
+
#initialized = false;
|
|
67
68
|
#initPromise;
|
|
68
69
|
#driverSerializesJson = false;
|
|
69
70
|
constructor(sql, options = {}) {
|
|
@@ -72,7 +73,7 @@ var PostgresMessageQueue = class {
|
|
|
72
73
|
this.#channelName = options?.channelName ?? "fedify_channel";
|
|
73
74
|
this.#pollIntervalMs = Temporal.Duration.from(options?.pollInterval ?? { seconds: 5 }).total("millisecond");
|
|
74
75
|
this.#handlerTimeoutMs = Temporal.Duration.from(options?.handlerTimeout ?? { seconds: 60 }).total("millisecond");
|
|
75
|
-
this.#
|
|
76
|
+
this.#skipDdl = options?.initialized ?? false;
|
|
76
77
|
}
|
|
77
78
|
async enqueue(message, options) {
|
|
78
79
|
await this.initialize();
|
|
@@ -311,6 +312,12 @@ var PostgresMessageQueue = class {
|
|
|
311
312
|
}
|
|
312
313
|
async #doInitialize() {
|
|
313
314
|
logger.debug("Initializing the message queue table {tableName}...", { tableName: this.#tableName });
|
|
315
|
+
if (!this.#skipDdl) await this.#initializeTable();
|
|
316
|
+
this.#driverSerializesJson = await require_utils.driverSerializesJson(this.#sql);
|
|
317
|
+
this.#initialized = true;
|
|
318
|
+
logger.debug("Initialized the message queue table {tableName}.", { tableName: this.#tableName });
|
|
319
|
+
}
|
|
320
|
+
async #initializeTable() {
|
|
314
321
|
for (let attempt = 1; attempt <= INITIALIZE_MAX_ATTEMPTS; attempt++) try {
|
|
315
322
|
await this.#sql`
|
|
316
323
|
CREATE TABLE IF NOT EXISTS ${this.#sql(this.#tableName)} (
|
|
@@ -345,9 +352,6 @@ var PostgresMessageQueue = class {
|
|
|
345
352
|
});
|
|
346
353
|
await sleep(backoffMs);
|
|
347
354
|
}
|
|
348
|
-
this.#driverSerializesJson = await require_utils.driverSerializesJson(this.#sql);
|
|
349
|
-
this.#initialized = true;
|
|
350
|
-
logger.debug("Initialized the message queue table {tableName}.", { tableName: this.#tableName });
|
|
351
355
|
}
|
|
352
356
|
/**
|
|
353
357
|
* 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
|
@@ -58,7 +58,8 @@ var PostgresMessageQueue = class {
|
|
|
58
58
|
#channelName;
|
|
59
59
|
#pollIntervalMs;
|
|
60
60
|
#handlerTimeoutMs;
|
|
61
|
-
#
|
|
61
|
+
#skipDdl;
|
|
62
|
+
#initialized = false;
|
|
62
63
|
#initPromise;
|
|
63
64
|
#driverSerializesJson = false;
|
|
64
65
|
constructor(sql, options = {}) {
|
|
@@ -67,7 +68,7 @@ var PostgresMessageQueue = class {
|
|
|
67
68
|
this.#channelName = options?.channelName ?? "fedify_channel";
|
|
68
69
|
this.#pollIntervalMs = Temporal.Duration.from(options?.pollInterval ?? { seconds: 5 }).total("millisecond");
|
|
69
70
|
this.#handlerTimeoutMs = Temporal.Duration.from(options?.handlerTimeout ?? { seconds: 60 }).total("millisecond");
|
|
70
|
-
this.#
|
|
71
|
+
this.#skipDdl = options?.initialized ?? false;
|
|
71
72
|
}
|
|
72
73
|
async enqueue(message, options) {
|
|
73
74
|
await this.initialize();
|
|
@@ -306,6 +307,12 @@ var PostgresMessageQueue = class {
|
|
|
306
307
|
}
|
|
307
308
|
async #doInitialize() {
|
|
308
309
|
logger.debug("Initializing the message queue table {tableName}...", { tableName: this.#tableName });
|
|
310
|
+
if (!this.#skipDdl) await this.#initializeTable();
|
|
311
|
+
this.#driverSerializesJson = await driverSerializesJson(this.#sql);
|
|
312
|
+
this.#initialized = true;
|
|
313
|
+
logger.debug("Initialized the message queue table {tableName}.", { tableName: this.#tableName });
|
|
314
|
+
}
|
|
315
|
+
async #initializeTable() {
|
|
309
316
|
for (let attempt = 1; attempt <= INITIALIZE_MAX_ATTEMPTS; attempt++) try {
|
|
310
317
|
await this.#sql`
|
|
311
318
|
CREATE TABLE IF NOT EXISTS ${this.#sql(this.#tableName)} (
|
|
@@ -340,9 +347,6 @@ var PostgresMessageQueue = class {
|
|
|
340
347
|
});
|
|
341
348
|
await sleep(backoffMs);
|
|
342
349
|
}
|
|
343
|
-
this.#driverSerializesJson = await driverSerializesJson(this.#sql);
|
|
344
|
-
this.#initialized = true;
|
|
345
|
-
logger.debug("Initialized the message queue table {tableName}.", { tableName: this.#tableName });
|
|
346
350
|
}
|
|
347
351
|
/**
|
|
348
352
|
* 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.4.0-dev.
|
|
3
|
+
"version": "2.4.0-dev.1959+0da7be03",
|
|
4
4
|
"description": "PostgreSQL drivers for Fedify",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"fedify",
|
|
@@ -71,7 +71,7 @@
|
|
|
71
71
|
},
|
|
72
72
|
"peerDependencies": {
|
|
73
73
|
"postgres": "^3.4.7",
|
|
74
|
-
"@fedify/fedify": "^2.4.0-dev.
|
|
74
|
+
"@fedify/fedify": "^2.4.0-dev.1959+0da7be03"
|
|
75
75
|
},
|
|
76
76
|
"devDependencies": {
|
|
77
77
|
"@js-temporal/polyfill": "^0.5.1",
|
|
@@ -79,7 +79,7 @@
|
|
|
79
79
|
"tsdown": "^0.22.0",
|
|
80
80
|
"typescript": "^6.0.0",
|
|
81
81
|
"@fedify/fixture": "^2.0.0",
|
|
82
|
-
"@fedify/testing": "^2.4.0-dev.
|
|
82
|
+
"@fedify/testing": "^2.4.0-dev.1959+0da7be03"
|
|
83
83
|
},
|
|
84
84
|
"scripts": {
|
|
85
85
|
"build:self": "tsdown",
|