@spine-event-engine/storage-postgres 2.0.0-snapshot.13

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.
Files changed (61) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +102 -0
  3. package/REFERENCE.md +85 -0
  4. package/dist/index.d.ts +5 -0
  5. package/dist/index.d.ts.map +1 -0
  6. package/dist/index.js +16 -0
  7. package/dist/index.js.map +1 -0
  8. package/dist/postgres/column-mapping.d.ts +33 -0
  9. package/dist/postgres/column-mapping.d.ts.map +1 -0
  10. package/dist/postgres/column-mapping.js +93 -0
  11. package/dist/postgres/column-mapping.js.map +1 -0
  12. package/dist/postgres/data-type.d.ts +25 -0
  13. package/dist/postgres/data-type.d.ts.map +1 -0
  14. package/dist/postgres/data-type.js +29 -0
  15. package/dist/postgres/data-type.js.map +1 -0
  16. package/dist/postgres/delivery-cleanup.d.ts +76 -0
  17. package/dist/postgres/delivery-cleanup.d.ts.map +1 -0
  18. package/dist/postgres/delivery-cleanup.js +224 -0
  19. package/dist/postgres/delivery-cleanup.js.map +1 -0
  20. package/dist/postgres/entity-commit.d.ts +114 -0
  21. package/dist/postgres/entity-commit.d.ts.map +1 -0
  22. package/dist/postgres/entity-commit.js +385 -0
  23. package/dist/postgres/entity-commit.js.map +1 -0
  24. package/dist/postgres/entity-history.d.ts +85 -0
  25. package/dist/postgres/entity-history.d.ts.map +1 -0
  26. package/dist/postgres/entity-history.js +840 -0
  27. package/dist/postgres/entity-history.js.map +1 -0
  28. package/dist/postgres/errors.d.ts +51 -0
  29. package/dist/postgres/errors.d.ts.map +1 -0
  30. package/dist/postgres/errors.js +113 -0
  31. package/dist/postgres/errors.js.map +1 -0
  32. package/dist/postgres/id-column.d.ts +61 -0
  33. package/dist/postgres/id-column.d.ts.map +1 -0
  34. package/dist/postgres/id-column.js +165 -0
  35. package/dist/postgres/id-column.js.map +1 -0
  36. package/dist/postgres/parameter.d.ts +5 -0
  37. package/dist/postgres/parameter.d.ts.map +1 -0
  38. package/dist/postgres/parameter.js +15 -0
  39. package/dist/postgres/parameter.js.map +1 -0
  40. package/dist/postgres/record-storage.d.ts +514 -0
  41. package/dist/postgres/record-storage.d.ts.map +1 -0
  42. package/dist/postgres/record-storage.js +849 -0
  43. package/dist/postgres/record-storage.js.map +1 -0
  44. package/dist/postgres/storage-factory.d.ts +321 -0
  45. package/dist/postgres/storage-factory.d.ts.map +1 -0
  46. package/dist/postgres/storage-factory.js +584 -0
  47. package/dist/postgres/storage-factory.js.map +1 -0
  48. package/dist/postgres/table-initializer.d.ts +66 -0
  49. package/dist/postgres/table-initializer.d.ts.map +1 -0
  50. package/dist/postgres/table-initializer.js +301 -0
  51. package/dist/postgres/table-initializer.js.map +1 -0
  52. package/dist/postgres/table-resolver.d.ts +41 -0
  53. package/dist/postgres/table-resolver.d.ts.map +1 -0
  54. package/dist/postgres/table-resolver.js +225 -0
  55. package/dist/postgres/table-resolver.js.map +1 -0
  56. package/dist/postgres/table-spec.d.ts +40 -0
  57. package/dist/postgres/table-spec.d.ts.map +1 -0
  58. package/dist/postgres/table-spec.js +126 -0
  59. package/dist/postgres/table-spec.js.map +1 -0
  60. package/dist/tsconfig.tsbuildinfo +1 -0
  61. package/package.json +40 -0
@@ -0,0 +1,301 @@
1
+ /*
2
+ * Copyright 2026, CodeMatters. All rights reserved.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
5
+ * in compliance with the License. You may obtain a copy of the License at
6
+ *
7
+ * https://www.apache.org/licenses/LICENSE-2.0
8
+ *
9
+ * Unless required by applicable law or agreed to in writing, software distributed under the License
10
+ * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11
+ * or implied. See the License for the specific language governing permissions and limitations under
12
+ * the License.
13
+ */
14
+ import { createHash } from "node:crypto";
15
+ import { PostgresDataTypes } from "./data-type.js";
16
+ import { PostgresRollbackErrors, PostgresStorageErrors, PostgresStorageSchemaError, PostgresTransactionErrors, } from "./errors.js";
17
+ /**
18
+ * Prepares one PostgreSQL record-family table.
19
+ */
20
+ export class PostgresTableInitializer {
21
+ lifecycle;
22
+ schema;
23
+ table;
24
+ customCreate;
25
+ #ready;
26
+ /**
27
+ * Creates a private initializer for one resolved PostgreSQL table.
28
+ *
29
+ * @param lifecycle Acquires clients and supplies the stable database lock identity.
30
+ * @param schema Names the resolved PostgreSQL schema.
31
+ * @param table Describes the canonical record-family layout.
32
+ * @param customCreate Optionally supplies caller-defined create-table SQL.
33
+ */
34
+ constructor(lifecycle, schema, table, customCreate) {
35
+ this.lifecycle = lifecycle;
36
+ this.schema = schema;
37
+ this.table = table;
38
+ this.customCreate = customCreate;
39
+ }
40
+ /**
41
+ * Prepares the table once.
42
+ *
43
+ * @returns Completion of initialization.
44
+ */
45
+ prepare() {
46
+ this.#ready ??= this.attempt().catch((error) => this.retry(error));
47
+ return this.#ready;
48
+ }
49
+ /**
50
+ * Retries initialization only after an admitted transaction conflict.
51
+ *
52
+ * @param error Initial table-preparation failure.
53
+ * @returns Completion of the retry attempt.
54
+ */
55
+ retry(error) {
56
+ if (!PostgresTransactionErrors.retryable(error))
57
+ throw PostgresStorageErrors.operation(error);
58
+ return this.attempt();
59
+ }
60
+ /**
61
+ * Creates and verifies the table inside one transaction.
62
+ *
63
+ * @returns Completion after commit.
64
+ */
65
+ async attempt() {
66
+ const client = await this.lifecycle.acquire();
67
+ let discard;
68
+ try {
69
+ await client.query("BEGIN");
70
+ await this.lock(client);
71
+ await client.query(this.customCreate?.() ?? this.create());
72
+ await this.verify(client);
73
+ await client.query("COMMIT");
74
+ }
75
+ catch (error) {
76
+ try {
77
+ await client.query("ROLLBACK");
78
+ }
79
+ catch {
80
+ discard = PostgresRollbackErrors.discard(error);
81
+ }
82
+ throw error;
83
+ }
84
+ finally {
85
+ client.release(discard);
86
+ }
87
+ }
88
+ /**
89
+ * Acquires the transaction lock for this physical table.
90
+ *
91
+ * @param client PostgreSQL transaction client.
92
+ * @returns PostgreSQL lock-query result.
93
+ */
94
+ lock(client) {
95
+ return client.query("SELECT pg_advisory_xact_lock($1)", [
96
+ PostgresLocks.key(this.lifecycle.lockIdentity ?? "", this.schema, this.table.tableName),
97
+ ]);
98
+ }
99
+ /**
100
+ * Builds the default idempotent table-creation statement.
101
+ *
102
+ * @returns Schema-qualified PostgreSQL DDL.
103
+ */
104
+ create() {
105
+ const columns = this.table.columns.map(PostgresSql.column).join(", ");
106
+ const primary = this.table.primaryKey.map(PostgresSql.identifier).join(", ");
107
+ const qualified = PostgresSql.qualified(this.schema, this.table.tableName);
108
+ return `CREATE TABLE IF NOT EXISTS ${qualified} (${columns}, PRIMARY KEY (${primary}))`;
109
+ }
110
+ /**
111
+ * Verifies columns, primary key, and unsupported unique constraints.
112
+ *
113
+ * @param client PostgreSQL transaction client.
114
+ * @returns Completion after catalog verification.
115
+ */
116
+ async verify(client) {
117
+ const columns = await PostgresCatalog.columns(client, this.schema, this.table.tableName);
118
+ PostgresCatalog.assertColumns(this.table.columns, columns);
119
+ const primary = await PostgresCatalog.primaryKey(client, this.schema, this.table.tableName);
120
+ PostgresCatalog.assertPrimary(this.table.primaryKey, primary);
121
+ PostgresCatalog.assertUnique(await PostgresCatalog.unique(client, this.schema, this.table.tableName));
122
+ }
123
+ }
124
+ const PostgresSql = Object.freeze({
125
+ /**
126
+ * Returns one safely quoted PostgreSQL identifier.
127
+ *
128
+ * @param value Identifier spelling.
129
+ * @returns Safely quoted identifier.
130
+ */
131
+ identifier(value) {
132
+ return `"${value.replaceAll('"', '""')}"`;
133
+ },
134
+ /**
135
+ * Builds one quoted schema-qualified table identifier.
136
+ *
137
+ * @param schema PostgreSQL schema name.
138
+ * @param table PostgreSQL table name.
139
+ * @returns Qualified table reference.
140
+ */
141
+ qualified(schema, table) {
142
+ return `${PostgresSql.identifier(schema)}.${PostgresSql.identifier(table)}`;
143
+ },
144
+ /**
145
+ * Renders one physical column declaration.
146
+ *
147
+ * @param column PostgreSQL column specification.
148
+ * @returns Column DDL fragment.
149
+ */
150
+ column(column) {
151
+ const nullable = column.nullable ? "" : " NOT NULL";
152
+ const fallback = column.defaultSql === undefined ? "" : ` DEFAULT ${column.defaultSql}`;
153
+ return `${PostgresSql.identifier(column.name)} ${column.postgresType}${nullable}${fallback}`;
154
+ },
155
+ });
156
+ const PostgresCatalog = Object.freeze({
157
+ /**
158
+ * Reads the ordered column catalog for one table.
159
+ *
160
+ * @param client PostgreSQL transaction client.
161
+ * @param schema PostgreSQL schema name.
162
+ * @param table PostgreSQL table name.
163
+ * @returns Catalog column rows.
164
+ */
165
+ async columns(client, schema, table) {
166
+ const result = await client.query("SELECT column_name, data_type, character_maximum_length, is_nullable, column_default " +
167
+ "FROM information_schema.columns WHERE table_schema=$1 AND table_name=$2 ORDER BY ordinal_position", [schema, table]);
168
+ return result.rows;
169
+ },
170
+ /**
171
+ * Reads the ordered primary-key catalog for one table.
172
+ *
173
+ * @param client PostgreSQL transaction client.
174
+ * @param schema PostgreSQL schema name.
175
+ * @param table PostgreSQL table name.
176
+ * @returns Primary-key column rows.
177
+ */
178
+ async primaryKey(client, schema, table) {
179
+ const result = await client.query("SELECT kcu.column_name, kcu.ordinal_position FROM information_schema.table_constraints tc " +
180
+ "JOIN information_schema.key_column_usage kcu USING (constraint_catalog, constraint_schema, constraint_name) " +
181
+ "WHERE tc.table_schema=$1 AND tc.table_name=$2 AND tc.constraint_type = 'PRIMARY KEY' " +
182
+ "ORDER BY kcu.ordinal_position", [schema, table]);
183
+ return result.rows;
184
+ },
185
+ /**
186
+ * Reads user-defined unique constraints for one table.
187
+ *
188
+ * @param client PostgreSQL transaction client.
189
+ * @param schema PostgreSQL schema name.
190
+ * @param table PostgreSQL table name.
191
+ * @returns Unique-constraint rows.
192
+ */
193
+ async unique(client, schema, table) {
194
+ const result = await client.query("SELECT tc.constraint_name, kcu.column_name, kcu.ordinal_position FROM information_schema.table_constraints tc " +
195
+ "JOIN information_schema.key_column_usage kcu USING (constraint_catalog, constraint_schema, constraint_name) " +
196
+ "WHERE tc.table_schema=$1 AND tc.table_name=$2 AND tc.constraint_type = 'UNIQUE' " +
197
+ "ORDER BY tc.constraint_name, kcu.ordinal_position", [schema, table]);
198
+ return result.rows;
199
+ },
200
+ /**
201
+ * Verifies the complete physical column set.
202
+ *
203
+ * @param expected Required column specifications.
204
+ * @param actual Catalog column rows.
205
+ */
206
+ assertColumns(expected, actual) {
207
+ if (actual.length !== expected.length)
208
+ PostgresCatalog.incompatible();
209
+ for (const expectedColumn of expected) {
210
+ const actualColumn = actual.find(({ column_name }) => column_name === expectedColumn.name);
211
+ if (actualColumn === undefined || !PostgresCatalog.sameColumn(expectedColumn, actualColumn))
212
+ PostgresCatalog.incompatible();
213
+ }
214
+ },
215
+ /**
216
+ * Verifies the ordered primary-key columns.
217
+ *
218
+ * @param expected Required primary-key column names.
219
+ * @param actual Catalog primary-key rows.
220
+ */
221
+ assertPrimary(expected, actual) {
222
+ if (actual.length !== expected.length ||
223
+ actual.some(({ column_name }, index) => column_name !== expected[index]))
224
+ PostgresCatalog.incompatible();
225
+ },
226
+ /**
227
+ * Rejects unexpected user-defined unique constraints.
228
+ *
229
+ * @param actual Catalog unique-constraint rows.
230
+ */
231
+ assertUnique(actual) {
232
+ if (actual.length > 0)
233
+ PostgresCatalog.incompatible();
234
+ },
235
+ /**
236
+ * Compares one expected column with its catalog row.
237
+ *
238
+ * @param expected Required column specification.
239
+ * @param actual Catalog column row.
240
+ * @returns Whether type, nullability, and default match.
241
+ */
242
+ sameColumn(expected, actual) {
243
+ return (PostgresCatalog.type(expected.postgresType, actual) &&
244
+ (actual.is_nullable === "YES") === expected.nullable &&
245
+ PostgresCatalog.default(expected.defaultSql) ===
246
+ PostgresCatalog.default(actual.column_default));
247
+ },
248
+ /**
249
+ * Compares one canonical DDL type with a catalog type.
250
+ *
251
+ * @param expected Canonical PostgreSQL DDL type name.
252
+ * @param actual Catalog column row.
253
+ * @returns Whether both describe the same PostgreSQL type.
254
+ */
255
+ type(expected, actual) {
256
+ if (expected === PostgresDataTypes.varchar512)
257
+ return actual.data_type === "character varying" && actual.character_maximum_length === 512;
258
+ if (expected === PostgresDataTypes.integer)
259
+ return actual.data_type === "integer";
260
+ return expected.toLowerCase() === actual.data_type.toLowerCase();
261
+ },
262
+ /**
263
+ * Normalizes a catalog or expected default expression.
264
+ *
265
+ * @param value Default expression.
266
+ * @returns Normalized expression or `null` when absent.
267
+ */
268
+ default(value) {
269
+ return value === undefined || value === null ? null : value.trim().toLowerCase();
270
+ },
271
+ /**
272
+ * Throws the stable incompatible-schema error.
273
+ *
274
+ * @returns This operation never returns.
275
+ */
276
+ incompatible() {
277
+ throw new PostgresStorageSchemaError("PostgreSQL table schema is incompatible.");
278
+ },
279
+ });
280
+ const PostgresLocks = Object.freeze({
281
+ /**
282
+ * Calculates the advisory lock key for one physical table.
283
+ *
284
+ * @param database Stable database connection identity.
285
+ * @param schema PostgreSQL schema name.
286
+ * @param table PostgreSQL table name.
287
+ * @returns Signed 64-bit advisory-lock key.
288
+ */
289
+ key(database, schema, table) {
290
+ return createHash("sha256")
291
+ .update("spine-postgres-table\u0000")
292
+ .update(database)
293
+ .update("\u0000")
294
+ .update(schema)
295
+ .update("\u0000")
296
+ .update(table)
297
+ .digest()
298
+ .readBigInt64BE();
299
+ },
300
+ });
301
+ //# sourceMappingURL=table-initializer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"table-initializer.js","sourceRoot":"","sources":["../../src/postgres/table-initializer.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAGzC,OAAO,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAGnD,OAAO,EACL,sBAAsB,EACtB,qBAAqB,EACrB,0BAA0B,EAC1B,yBAAyB,GAC1B,MAAM,aAAa,CAAC;AAErB;;GAEG;AACH,MAAM,OAAO,wBAAwB;IAYhB;IACA;IACA;IACA;IAdnB,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G;IACH,OAAO,CAAC,KAAgC;QACtC,OAAO,KAAK,KAAK,SAAS,IAAI,KAAK,KAAK,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC;IACnF,CAAC;IAED;;;;OAIG;IACH,YAAY;QACV,MAAM,IAAI,0BAA0B,CAAC,0CAA0C,CAAC,CAAC;IACnF,CAAC;CACF,CAAC,CAAC;AAEH,MAAM,aAAa,GAAG,MAAM,CAAC,MAAM,CAAC;IAClC;;;;;;;OAOG;IACH,GAAG,CAAC,QAAgB,EAAE,MAAc,EAAE,KAAa;QACjD,OAAO,UAAU,CAAC,QAAQ,CAAC;aACxB,MAAM,CAAC,4BAA4B,CAAC;aACpC,MAAM,CAAC,QAAQ,CAAC;aAChB,MAAM,CAAC,QAAQ,CAAC;aAChB,MAAM,CAAC,MAAM,CAAC;aACd,MAAM,CAAC,QAAQ,CAAC;aAChB,MAAM,CAAC,KAAK,CAAC;aACb,MAAM,EAAE;aACR,cAAc,EAAE,CAAC;IACtB,CAAC;CACF,CAAC,CAAC"}
@@ -0,0 +1,41 @@
1
+ /**
2
+ * Resolves PostgreSQL physical names for record families.
3
+ */
4
+ export declare class PostgresTableResolver {
5
+ #private;
6
+ /**
7
+ * Sets an ungrouped record-family table name.
8
+ *
9
+ * @param recordType Names the record type.
10
+ * @param name Specifies the requested physical table name.
11
+ */
12
+ setRecordName(recordType: string, name: string): void;
13
+ /**
14
+ * Sets a grouped record-family table name.
15
+ *
16
+ * @param sourceType Names the source type.
17
+ * @param recordType Names the grouped record type.
18
+ * @param name Names the physical table.
19
+ */
20
+ setGroupName(sourceType: string, recordType: string, name: string): void;
21
+ /**
22
+ * Resolves one record-family physical name.
23
+ *
24
+ * @param sourceType Names the record source type.
25
+ * @param group Names the optional storage group.
26
+ * @param name Supplies an explicit physical name.
27
+ * @param recordType Names the grouped record type.
28
+ * @returns The validated PostgreSQL table identity.
29
+ */
30
+ resolve(sourceType: string, group: string | undefined, name?: string, recordType?: string): {
31
+ readonly tableName: string;
32
+ };
33
+ /**
34
+ * Registers one logical-to-physical table-name request.
35
+ *
36
+ * @param identity Stable logical record-family identity.
37
+ * @param name Requested physical table name.
38
+ */
39
+ private set;
40
+ }
41
+ //# sourceMappingURL=table-resolver.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"table-resolver.d.ts","sourceRoot":"","sources":["../../src/postgres/table-resolver.ts"],"names":[],"mappings":"AAcA;;GAEG;AACH,qBAAa,qBAAqB;;IAKhC;;;;;OAKG;IACH,aAAa,CAAC,UAAU,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,IAAI;IAIrD;;;;;;OAMG;IACH,YAAY,CAAC,UAAU,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,IAAI;IAIxE;;;;;;;;OAQG;IACH,OAAO,CACL,UAAU,EAAE,MAAM,EAClB,KAAK,EAAE,MAAM,GAAG,SAAS,EACzB,IAAI,CAAC,EAAE,MAAM,EACb,UAAU,CAAC,EAAE,MAAM,GAClB;QAAE,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAA;KAAE;IAmBjC;;;;;OAKG;IACH,OAAO,CAAC,GAAG;CASZ"}
@@ -0,0 +1,225 @@
1
+ /*
2
+ * Copyright 2026, CodeMatters. All rights reserved.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
5
+ * in compliance with the License. You may obtain a copy of the License at
6
+ *
7
+ * https://www.apache.org/licenses/LICENSE-2.0
8
+ *
9
+ * Unless required by applicable law or agreed to in writing, software distributed under the License
10
+ * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11
+ * or implied. See the License for the specific language governing permissions and limitations under
12
+ * the License.
13
+ */
14
+ /**
15
+ * Resolves PostgreSQL physical names for record families.
16
+ */
17
+ export class PostgresTableResolver {
18
+ #names = new Map();
19
+ #resolved = new Map();
20
+ /**
21
+ * Sets an ungrouped record-family table name.
22
+ *
23
+ * @param recordType Names the record type.
24
+ * @param name Specifies the requested physical table name.
25
+ */
26
+ setRecordName(recordType, name) {
27
+ this.set(`record:${recordType}`, name);
28
+ }
29
+ /**
30
+ * Sets a grouped record-family table name.
31
+ *
32
+ * @param sourceType Names the source type.
33
+ * @param recordType Names the grouped record type.
34
+ * @param name Names the physical table.
35
+ */
36
+ setGroupName(sourceType, recordType, name) {
37
+ this.set(`group:${sourceType}\u0000${recordType}`, name);
38
+ }
39
+ /**
40
+ * Resolves one record-family physical name.
41
+ *
42
+ * @param sourceType Names the record source type.
43
+ * @param group Names the optional storage group.
44
+ * @param name Supplies an explicit physical name.
45
+ * @param recordType Names the grouped record type.
46
+ * @returns The validated PostgreSQL table identity.
47
+ */
48
+ resolve(sourceType, group, name, recordType) {
49
+ const identity = group === undefined
50
+ ? sourceType
51
+ : `${sourceType}\u0000${recordType ?? sourceType}\u0000${group}`;
52
+ const readable = name ??
53
+ (group === undefined
54
+ ? this.#names.get(`record:${sourceType}`)
55
+ : this.#names.get(`group:${sourceType}\u0000${recordType ?? sourceType}`)) ??
56
+ PostgresNames.default(sourceType, group, recordType);
57
+ const tableName = PostgresNames.physical(readable);
58
+ const previous = this.#resolved.get(tableName);
59
+ if (previous !== undefined && previous !== identity)
60
+ throw new Error(`PostgreSQL table name collides: ${tableName}`);
61
+ this.#resolved.set(tableName, identity);
62
+ return Object.freeze({ tableName });
63
+ }
64
+ /**
65
+ * Registers one logical-to-physical table-name request.
66
+ *
67
+ * @param identity Stable logical record-family identity.
68
+ * @param name Requested physical table name.
69
+ */
70
+ set(identity, name) {
71
+ const physical = PostgresNames.physical(name);
72
+ for (const [registered, value] of this.#names) {
73
+ if (registered !== identity && PostgresNames.physical(value) === physical) {
74
+ throw new Error(`PostgreSQL table name collides: ${physical}`);
75
+ }
76
+ }
77
+ this.#names.set(identity, name);
78
+ }
79
+ }
80
+ const PostgresNames = Object.freeze({
81
+ /**
82
+ * Calculates the default readable name for one record family.
83
+ *
84
+ * @param sourceType Record source type name.
85
+ * @param group Optional storage group name.
86
+ * @param recordType Optional grouped record type name.
87
+ * @returns Default readable table name.
88
+ */
89
+ default(sourceType, group, recordType) {
90
+ if (group === undefined)
91
+ return sourceType.replaceAll(".", "_");
92
+ const type = recordType ?? sourceType;
93
+ return `${group.replaceAll(".", "_")}_${type.slice(type.lastIndexOf(".") + 1)}`;
94
+ },
95
+ /**
96
+ * Applies PostgreSQL identifier validation and case folding.
97
+ *
98
+ * @param name Requested readable table name.
99
+ * @returns Validated physical table name.
100
+ */
101
+ physical(name) {
102
+ if (/\s/u.test(name) ||
103
+ name.includes("\u0000") ||
104
+ name.length === 0 ||
105
+ Buffer.byteLength(name) > 63) {
106
+ throw new Error(`PostgreSQL table name is invalid: ${name}`);
107
+ }
108
+ return PostgresNames.plain(name) && !PostgresNames.reserved.has(name.toLowerCase())
109
+ ? name.replace(/[A-Z]/g, (letter) => letter.toLowerCase())
110
+ : name;
111
+ },
112
+ /**
113
+ * Checks whether a name uses the unquoted PostgreSQL identifier grammar.
114
+ *
115
+ * @param name Requested table name.
116
+ * @returns Whether PostgreSQL may use the name without quoting for spelling.
117
+ */
118
+ plain(name) {
119
+ return /^[A-Za-z_][A-Za-z0-9_]*$/u.test(name);
120
+ },
121
+ // QueryDSL 5.1.0 querydsl-sql `keywords/postgresql`, loaded by `Keywords.POSTGRESQL`.
122
+ reserved: new Set([
123
+ "ALL",
124
+ "ANALYSE",
125
+ "ANALYZE",
126
+ "AND",
127
+ "ANY",
128
+ "ARRAY",
129
+ "AS",
130
+ "ASC",
131
+ "ASYMMETRIC",
132
+ "AUTHORIZATION",
133
+ "BINARY",
134
+ "BOTH",
135
+ "CASE",
136
+ "CAST",
137
+ "CHECK",
138
+ "COLLATE",
139
+ "COLLATION",
140
+ "COLUMN",
141
+ "CONCURRENTLY",
142
+ "CONSTRAINT",
143
+ "CREATE",
144
+ "CROSS",
145
+ "CURRENT_CATALOG",
146
+ "CURRENT_DATE",
147
+ "CURRENT_ROLE",
148
+ "CURRENT_SCHEMA",
149
+ "CURRENT_TIME",
150
+ "CURRENT_TIMESTAMP",
151
+ "CURRENT_USER",
152
+ "DEFAULT",
153
+ "DEFERRABLE",
154
+ "DESC",
155
+ "DISTINCT",
156
+ "DO",
157
+ "ELSE",
158
+ "END",
159
+ "EXCEPT",
160
+ "FALSE",
161
+ "FETCH",
162
+ "FOR",
163
+ "FOREIGN",
164
+ "FREEZE",
165
+ "FROM",
166
+ "FULL",
167
+ "GRANT",
168
+ "GROUP",
169
+ "HAVING",
170
+ "ILIKE",
171
+ "IN",
172
+ "INITIALLY",
173
+ "INNER",
174
+ "INTERSECT",
175
+ "INTO",
176
+ "IS",
177
+ "ISNULL",
178
+ "JOIN",
179
+ "LATERAL",
180
+ "LEADING",
181
+ "LEFT",
182
+ "LIKE",
183
+ "LIMIT",
184
+ "LOCALTIME",
185
+ "LOCALTIMESTAMP",
186
+ "NATURAL",
187
+ "NOT",
188
+ "NOTNULL",
189
+ "NULL",
190
+ "OFFSET",
191
+ "ON",
192
+ "ONLY",
193
+ "OR",
194
+ "ORDER",
195
+ "OUTER",
196
+ "OVER",
197
+ "OVERLAPS",
198
+ "PLACING",
199
+ "PRIMARY",
200
+ "REFERENCES",
201
+ "RETURNING",
202
+ "RIGHT",
203
+ "SELECT",
204
+ "SESSION_USER",
205
+ "SIMILAR",
206
+ "SOME",
207
+ "SYMMETRIC",
208
+ "TABLE",
209
+ "THEN",
210
+ "TO",
211
+ "TRAILING",
212
+ "TRUE",
213
+ "UNION",
214
+ "UNIQUE",
215
+ "USER",
216
+ "USING",
217
+ "VARIADIC",
218
+ "VERBOSE",
219
+ "WHEN",
220
+ "WHERE",
221
+ "WINDOW",
222
+ "WITH",
223
+ ].map((keyword) => keyword.toLowerCase())),
224
+ });
225
+ //# sourceMappingURL=table-resolver.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"table-resolver.js","sour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AI;QACJ,WAAW;QACX,OAAO;QACP,WAAW;QACX,MAAM;QACN,IAAI;QACJ,QAAQ;QACR,MAAM;QACN,SAAS;QACT,SAAS;QACT,MAAM;QACN,MAAM;QACN,OAAO;QACP,WAAW;QACX,gBAAgB;QAChB,SAAS;QACT,KAAK;QACL,SAAS;QACT,MAAM;QACN,QAAQ;QACR,IAAI;QACJ,MAAM;QACN,IAAI;QACJ,OAAO;QACP,OAAO;QACP,MAAM;QACN,UAAU;QACV,SAAS;QACT,SAAS;QACT,YAAY;QACZ,WAAW;QACX,OAAO;QACP,QAAQ;QACR,cAAc;QACd,SAAS;QACT,MAAM;QACN,WAAW;QACX,OAAO;QACP,MAAM;QACN,IAAI;QACJ,UAAU;QACV,MAAM;QACN,OAAO;QACP,QAAQ;QACR,MAAM;QACN,OAAO;QACP,UAAU;QACV,SAAS;QACT,MAAM;QACN,OAAO;QACP,QAAQ;QACR,MAAM;KACP,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,WAAW,EAAE,CAAC,CAC1C;CACF,CAAC,CAAC"}
@@ -0,0 +1,40 @@
1
+ import { type Message } from "@bufbuild/protobuf";
2
+ import type { GenMessage } from "@bufbuild/protobuf/codegenv2";
3
+ import type { RecordColumn, RecordColumnType } from "@spine-event-engine/storage";
4
+ import { type PostgresDdlType } from "./data-type.js";
5
+ import type { PostgresTableSpec } from "./storage-factory.js";
6
+ /**
7
+ * Resolves PostgreSQL-native declared-column and record-family table layouts.
8
+ */
9
+ export declare const PostgresTableSpecs: PostgresTableSpecifications;
10
+ /**
11
+ * Describes PostgreSQL table-layout operations.
12
+ */
13
+ interface PostgresTableSpecifications {
14
+ /**
15
+ * Maps one declared record-column type to PostgreSQL DDL.
16
+ *
17
+ * @param type Declared Protobuf column type.
18
+ * @returns Canonical PostgreSQL DDL type name.
19
+ */
20
+ postgresColumnType(type: RecordColumnType): PostgresDdlType;
21
+ /**
22
+ * Builds the complete physical layout for one record family.
23
+ *
24
+ * @typeParam I Record identifier type.
25
+ * @typeParam R Stored Protobuf record type.
26
+ * @param input Resolved schema, table, types, group, and declared columns.
27
+ * @returns Complete PostgreSQL table specification.
28
+ */
29
+ resolvedPostgresTableSpec<I, R extends Message>(input: {
30
+ readonly schema: string;
31
+ readonly tableName: string;
32
+ readonly sourceType: GenMessage<Message>;
33
+ readonly recordType: GenMessage<R>;
34
+ readonly idType: I extends Message ? GenMessage<I> : string;
35
+ readonly groupName?: string;
36
+ readonly declaredColumns: readonly RecordColumn<R>[];
37
+ }): PostgresTableSpec<I, R>;
38
+ }
39
+ export {};
40
+ //# sourceMappingURL=table-spec.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"table-spec.d.ts","sourceRoot":"","sources":["../../src/postgres/table-spec.ts"],"names":[],"mappings":"AAcA,OAAO,EAAc,KAAK,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAC9D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,8BAA8B,CAAC;AAC/D,OAAO,KAAK,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;AAGlF,OAAO,EAAqB,KAAK,eAAe,EAAE,MAAM,gBAAgB,CAAC;AACzE,OAAO,KAAK,EAAsB,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAGlF;;GAEG;AACH,eAAO,MAAM,kBAAkB,EAAE,2BA8D/B,CAAC;AAEH;;GAEG;AACH,UAAU,2BAA2B;IACnC;;;;;OAKG;IACH,kBAAkB,CAAC,IAAI,EAAE,gBAAgB,GAAG,eAAe,CAAC;IAE5D;;;;;;;OAOG;IACH,yBAAyB,CAAC,CAAC,EAAE,CAAC,SAAS,OAAO,EAAE,KAAK,EAAE;QACrD,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;QACxB,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;QAC3B,QAAQ,CAAC,UAAU,EAAE,UAAU,CAAC,OAAO,CAAC,CAAC;QACzC,QAAQ,CAAC,UAAU,EAAE,UAAU,CAAC,CAAC,CAAC,CAAC;QACnC,QAAQ,CAAC,MAAM,EAAE,CAAC,SAAS,OAAO,GAAG,UAAU,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC;QAC5D,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;QAC5B,QAAQ,CAAC,eAAe,EAAE,SAAS,YAAY,CAAC,CAAC,CAAC,EAAE,CAAC;KACtD,GAAG,iBAAiB,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;CAC7B"}