@fedify/postgres 2.3.6 → 2.3.8

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 CHANGED
@@ -26,7 +26,8 @@ const logger = (0, require("@logtape/logtape").getLogger)([
26
26
  var PostgresKvStore = class {
27
27
  #sql;
28
28
  #tableName;
29
- #initialized;
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.#initialized = options.initialized ?? false;
40
+ this.#skipDdl = options.initialized ?? false;
40
41
  }
41
42
  async #expire() {
42
43
  await this.#sql`
@@ -116,6 +117,12 @@ var PostgresKvStore = class {
116
117
  async initialize() {
117
118
  if (this.#initialized) return;
118
119
  logger.debug("Initializing the key–value store table {tableName}...", { tableName: this.#tableName });
120
+ if (!this.#skipDdl) await this.#initializeTable();
121
+ this.#driverSerializesJson = await require_utils.driverSerializesJson(this.#sql);
122
+ this.#initialized = true;
123
+ logger.debug("Initialized the key–value store table {tableName}.", { tableName: this.#tableName });
124
+ }
125
+ async #initializeTable() {
119
126
  await this.#sql`
120
127
  CREATE UNLOGGED TABLE IF NOT EXISTS ${this.#sql(this.#tableName)} (
121
128
  key text[] PRIMARY KEY,
@@ -124,9 +131,6 @@ var PostgresKvStore = class {
124
131
  ttl interval
125
132
  );
126
133
  `;
127
- this.#driverSerializesJson = await require_utils.driverSerializesJson(this.#sql);
128
- this.#initialized = true;
129
- logger.debug("Initialized the key–value store table {tableName}.", { tableName: this.#tableName });
130
134
  }
131
135
  /**
132
136
  * 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
- #initialized;
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.#initialized = options.initialized ?? false;
39
+ this.#skipDdl = options.initialized ?? false;
39
40
  }
40
41
  async #expire() {
41
42
  await this.#sql`
@@ -115,6 +116,12 @@ var PostgresKvStore = class {
115
116
  async initialize() {
116
117
  if (this.#initialized) return;
117
118
  logger.debug("Initializing the key–value store table {tableName}...", { tableName: this.#tableName });
119
+ if (!this.#skipDdl) await this.#initializeTable();
120
+ this.#driverSerializesJson = await driverSerializesJson(this.#sql);
121
+ this.#initialized = true;
122
+ logger.debug("Initialized the key–value store table {tableName}.", { tableName: this.#tableName });
123
+ }
124
+ async #initializeTable() {
118
125
  await this.#sql`
119
126
  CREATE UNLOGGED TABLE IF NOT EXISTS ${this.#sql(this.#tableName)} (
120
127
  key text[] PRIMARY KEY,
@@ -123,9 +130,6 @@ var PostgresKvStore = class {
123
130
  ttl interval
124
131
  );
125
132
  `;
126
- this.#driverSerializesJson = await driverSerializesJson(this.#sql);
127
- this.#initialized = true;
128
- logger.debug("Initialized the key–value store table {tableName}.", { tableName: this.#tableName });
129
133
  }
130
134
  /**
131
135
  * Drops the table used by the key–value store. Does nothing if the table
package/dist/mq.cjs CHANGED
@@ -60,7 +60,8 @@ var PostgresMessageQueue = class {
60
60
  #channelName;
61
61
  #pollIntervalMs;
62
62
  #handlerTimeoutMs;
63
- #initialized;
63
+ #skipDdl;
64
+ #initialized = false;
64
65
  #initPromise;
65
66
  #driverSerializesJson = false;
66
67
  constructor(sql, options = {}) {
@@ -69,7 +70,7 @@ var PostgresMessageQueue = class {
69
70
  this.#channelName = options?.channelName ?? "fedify_channel";
70
71
  this.#pollIntervalMs = Temporal.Duration.from(options?.pollInterval ?? { seconds: 5 }).total("millisecond");
71
72
  this.#handlerTimeoutMs = Temporal.Duration.from(options?.handlerTimeout ?? { seconds: 60 }).total("millisecond");
72
- this.#initialized = options?.initialized ?? false;
73
+ this.#skipDdl = options?.initialized ?? false;
73
74
  }
74
75
  async enqueue(message, options) {
75
76
  await this.initialize();
@@ -308,6 +309,12 @@ var PostgresMessageQueue = class {
308
309
  }
309
310
  async #doInitialize() {
310
311
  logger.debug("Initializing the message queue table {tableName}...", { tableName: this.#tableName });
312
+ if (!this.#skipDdl) await this.#initializeTable();
313
+ this.#driverSerializesJson = await require_utils.driverSerializesJson(this.#sql);
314
+ this.#initialized = true;
315
+ logger.debug("Initialized the message queue table {tableName}.", { tableName: this.#tableName });
316
+ }
317
+ async #initializeTable() {
311
318
  for (let attempt = 1; attempt <= INITIALIZE_MAX_ATTEMPTS; attempt++) try {
312
319
  await this.#sql`
313
320
  CREATE TABLE IF NOT EXISTS ${this.#sql(this.#tableName)} (
@@ -342,9 +349,6 @@ var PostgresMessageQueue = class {
342
349
  });
343
350
  await sleep(backoffMs);
344
351
  }
345
- this.#driverSerializesJson = await require_utils.driverSerializesJson(this.#sql);
346
- this.#initialized = true;
347
- logger.debug("Initialized the message queue table {tableName}.", { tableName: this.#tableName });
348
352
  }
349
353
  /**
350
354
  * 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
@@ -57,7 +57,8 @@ var PostgresMessageQueue = class {
57
57
  #channelName;
58
58
  #pollIntervalMs;
59
59
  #handlerTimeoutMs;
60
- #initialized;
60
+ #skipDdl;
61
+ #initialized = false;
61
62
  #initPromise;
62
63
  #driverSerializesJson = false;
63
64
  constructor(sql, options = {}) {
@@ -66,7 +67,7 @@ var PostgresMessageQueue = class {
66
67
  this.#channelName = options?.channelName ?? "fedify_channel";
67
68
  this.#pollIntervalMs = Temporal.Duration.from(options?.pollInterval ?? { seconds: 5 }).total("millisecond");
68
69
  this.#handlerTimeoutMs = Temporal.Duration.from(options?.handlerTimeout ?? { seconds: 60 }).total("millisecond");
69
- this.#initialized = options?.initialized ?? false;
70
+ this.#skipDdl = options?.initialized ?? false;
70
71
  }
71
72
  async enqueue(message, options) {
72
73
  await this.initialize();
@@ -305,6 +306,12 @@ var PostgresMessageQueue = class {
305
306
  }
306
307
  async #doInitialize() {
307
308
  logger.debug("Initializing the message queue table {tableName}...", { tableName: this.#tableName });
309
+ if (!this.#skipDdl) await this.#initializeTable();
310
+ this.#driverSerializesJson = await driverSerializesJson(this.#sql);
311
+ this.#initialized = true;
312
+ logger.debug("Initialized the message queue table {tableName}.", { tableName: this.#tableName });
313
+ }
314
+ async #initializeTable() {
308
315
  for (let attempt = 1; attempt <= INITIALIZE_MAX_ATTEMPTS; attempt++) try {
309
316
  await this.#sql`
310
317
  CREATE TABLE IF NOT EXISTS ${this.#sql(this.#tableName)} (
@@ -339,9 +346,6 @@ var PostgresMessageQueue = class {
339
346
  });
340
347
  await sleep(backoffMs);
341
348
  }
342
- this.#driverSerializesJson = await driverSerializesJson(this.#sql);
343
- this.#initialized = true;
344
- logger.debug("Initialized the message queue table {tableName}.", { tableName: this.#tableName });
345
349
  }
346
350
  /**
347
351
  * 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.3.6",
3
+ "version": "2.3.8",
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.3.6"
77
+ "@fedify/fedify": "^2.3.8"
78
78
  },
79
79
  "devDependencies": {
80
80
  "@std/async": "npm:@jsr/std__async@^1.0.13",
81
81
  "tsdown": "^0.22.0",
82
82
  "typescript": "^6.0.0",
83
83
  "@fedify/fixture": "^2.0.0",
84
- "@fedify/testing": "^2.3.6"
84
+ "@fedify/testing": "^2.3.8"
85
85
  },
86
86
  "scripts": {
87
87
  "build:self": "tsdown",