@fedify/postgres 2.0.27-dev.1941 → 2.0.27-dev.1944

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`
@@ -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
- #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`
@@ -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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fedify/postgres",
3
- "version": "2.0.27-dev.1941+9c8ec49c",
3
+ "version": "2.0.27-dev.1944+784647a5",
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.0.27-dev.1941+9c8ec49c"
77
+ "@fedify/fedify": "^2.0.27-dev.1944+784647a5"
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
- "@fedify/testing": "^2.0.27-dev.1941+9c8ec49c",
84
- "@fedify/fixture": "^2.0.0"
83
+ "@fedify/fixture": "^2.0.0",
84
+ "@fedify/testing": "^2.0.27-dev.1944+784647a5"
85
85
  },
86
86
  "scripts": {
87
87
  "build:self": "tsdown",