@spine-event-engine/storage-postgres 2.0.0-snapshot.26 → 2.0.0-snapshot.29
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/REFERENCE.md +10 -2
- package/dist/postgres/record-indexes.d.ts +114 -0
- package/dist/postgres/record-indexes.d.ts.map +1 -0
- package/dist/postgres/record-indexes.js +97 -0
- package/dist/postgres/record-indexes.js.map +1 -0
- package/dist/postgres/record-storage.d.ts +22 -13
- package/dist/postgres/record-storage.d.ts.map +1 -1
- package/dist/postgres/record-storage.js +39 -14
- package/dist/postgres/record-storage.js.map +1 -1
- package/dist/postgres/storage-factory.d.ts +46 -2
- package/dist/postgres/storage-factory.d.ts.map +1 -1
- package/dist/postgres/storage-factory.js +83 -17
- package/dist/postgres/storage-factory.js.map +1 -1
- package/dist/postgres/table-initializer.d.ts.map +1 -1
- package/dist/postgres/table-initializer.js +5 -0
- package/dist/postgres/table-initializer.js.map +1 -1
- package/dist/postgres/table-spec.d.ts +2 -1
- package/dist/postgres/table-spec.d.ts.map +1 -1
- package/dist/postgres/table-spec.js +11 -0
- package/dist/postgres/table-spec.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +4 -4
package/REFERENCE.md
CHANGED
|
@@ -35,8 +35,16 @@ and required audit indexes without DDL or custom creation SQL. A successful
|
|
|
35
35
|
compatible preparation is reused by later handles and operations in this
|
|
36
36
|
factory. Explicit preparation uses and releases a temporary pool when no runtime
|
|
37
37
|
pool exists; otherwise it reuses the retained runtime pool. Failed requirements
|
|
38
|
-
can be retried without discarding
|
|
39
|
-
|
|
38
|
+
can be retried without discarding earlier compatible families.
|
|
39
|
+
|
|
40
|
+
Each `RecordSpec.indexes` requirement likewise checks a complete non-unique,
|
|
41
|
+
ascending B-tree index with default operator class and column collation, no
|
|
42
|
+
partial predicate, expression, or included column. Create mode adds missing
|
|
43
|
+
indexes under the family preparation lock; incompatible existing indexes reject
|
|
44
|
+
without alteration. Fixed byte columns use `BYTEA` and exact-width stored and
|
|
45
|
+
query validation. Non-null fixed-byte equality uses native `=` for indexable
|
|
46
|
+
queries. A record handle with `prepareOnAccess: false` performs no index
|
|
47
|
+
metadata probe or DDL on ordinary data operations.
|
|
40
48
|
|
|
41
49
|
The default shared registry converts message-valued IDs and columns using
|
|
42
50
|
generated descriptors registered on module import. A registry supplied with
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import type { PoolClient } from "pg";
|
|
2
|
+
import type { StoragePreparationMode } from "@spine-event-engine/storage/provider";
|
|
3
|
+
import type { PostgresIndexSpec } from "./storage-factory.js";
|
|
4
|
+
/**
|
|
5
|
+
* Carries one ordered PostgreSQL catalog component and its index-wide flags.
|
|
6
|
+
*/
|
|
7
|
+
interface IndexRow {
|
|
8
|
+
/**
|
|
9
|
+
* Materialized column name, absent for an expression component.
|
|
10
|
+
*/
|
|
11
|
+
readonly column_name: string | null;
|
|
12
|
+
/**
|
|
13
|
+
* One-based position in the native index.
|
|
14
|
+
*/
|
|
15
|
+
readonly ordinal: number | string;
|
|
16
|
+
/**
|
|
17
|
+
* Whether the index enforces uniqueness.
|
|
18
|
+
*/
|
|
19
|
+
readonly unique: boolean;
|
|
20
|
+
/**
|
|
21
|
+
* Whether the index is valid for queries.
|
|
22
|
+
*/
|
|
23
|
+
readonly valid: boolean;
|
|
24
|
+
/**
|
|
25
|
+
* Whether writes maintain the index.
|
|
26
|
+
*/
|
|
27
|
+
readonly ready: boolean;
|
|
28
|
+
/**
|
|
29
|
+
* Whether the index remains live.
|
|
30
|
+
*/
|
|
31
|
+
readonly live: boolean;
|
|
32
|
+
/**
|
|
33
|
+
* Whether a predicate excludes some table rows.
|
|
34
|
+
*/
|
|
35
|
+
readonly partial: boolean;
|
|
36
|
+
/**
|
|
37
|
+
* Whether a component is an expression.
|
|
38
|
+
*/
|
|
39
|
+
readonly expression: boolean;
|
|
40
|
+
/**
|
|
41
|
+
* Number of searchable key components.
|
|
42
|
+
*/
|
|
43
|
+
readonly key_count: number;
|
|
44
|
+
/**
|
|
45
|
+
* Total components, including non-key values.
|
|
46
|
+
*/
|
|
47
|
+
readonly total_count: number;
|
|
48
|
+
/**
|
|
49
|
+
* Native access method name.
|
|
50
|
+
*/
|
|
51
|
+
readonly method: string;
|
|
52
|
+
/**
|
|
53
|
+
* Native relation kind.
|
|
54
|
+
*/
|
|
55
|
+
readonly kind: string;
|
|
56
|
+
/**
|
|
57
|
+
* Native sort-direction flags.
|
|
58
|
+
*/
|
|
59
|
+
readonly direction: number;
|
|
60
|
+
/**
|
|
61
|
+
* Whether the component uses its default operator class.
|
|
62
|
+
*/
|
|
63
|
+
readonly default_operator: boolean;
|
|
64
|
+
/**
|
|
65
|
+
* Whether the index uses the source column collation.
|
|
66
|
+
*/
|
|
67
|
+
readonly column_collation: boolean;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Defines native catalog operations for complete lookup-index preparation.
|
|
71
|
+
*/
|
|
72
|
+
interface IndexOperations {
|
|
73
|
+
/**
|
|
74
|
+
* Creates or checks a complete native lookup index.
|
|
75
|
+
*
|
|
76
|
+
* @param client PostgreSQL transaction or read-only client.
|
|
77
|
+
* @param index Declared physical lookup index.
|
|
78
|
+
* @param mode Physical preparation mode.
|
|
79
|
+
* @param schema Physical PostgreSQL schema.
|
|
80
|
+
* @param table Physical record-family table.
|
|
81
|
+
* @returns Completion of index preparation.
|
|
82
|
+
*/
|
|
83
|
+
ensure(client: PoolClient, schema: string, table: string, index: PostgresIndexSpec, mode: StoragePreparationMode): Promise<void>;
|
|
84
|
+
/**
|
|
85
|
+
* Reads the ordered native index catalog rows.
|
|
86
|
+
*
|
|
87
|
+
* @param client PostgreSQL transaction or read-only client.
|
|
88
|
+
* @param name Physical index name or identifier.
|
|
89
|
+
* @param schema Physical PostgreSQL schema.
|
|
90
|
+
* @param table Physical record-family table.
|
|
91
|
+
* @returns Ordered native index catalog rows.
|
|
92
|
+
*/
|
|
93
|
+
read(client: PoolClient, schema: string, table: string, name: string): Promise<readonly IndexRow[]>;
|
|
94
|
+
/**
|
|
95
|
+
* Rejects an incompatible native index definition.
|
|
96
|
+
*
|
|
97
|
+
* @param index Declared physical lookup index.
|
|
98
|
+
* @param rows Ordered native index catalog rows.
|
|
99
|
+
*/
|
|
100
|
+
assert(index: PostgresIndexSpec, rows: readonly IndexRow[]): void;
|
|
101
|
+
/**
|
|
102
|
+
* Returns one safely quoted physical SQL identifier.
|
|
103
|
+
*
|
|
104
|
+
* @param value Physical SQL identifier.
|
|
105
|
+
* @returns Quoted SQL identifier.
|
|
106
|
+
*/
|
|
107
|
+
quote(value: string): string;
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Creates or checks complete PostgreSQL B-tree lookup indexes.
|
|
111
|
+
*/
|
|
112
|
+
export declare const PostgresRecordIndexes: Readonly<IndexOperations>;
|
|
113
|
+
export {};
|
|
114
|
+
//# sourceMappingURL=record-indexes.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"record-indexes.d.ts","sourceRoot":"","sources":["../../src/postgres/record-indexes.ts"],"names":[],"mappings":"AAcA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,IAAI,CAAC;AACrC,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,sCAAsC,CAAC;AAEnF,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAE9D;;GAEG;AACH,UAAU,QAAQ;IAGhB;;OAEG;IACH,QAAQ,CAAC,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;IAEpC;;OAEG;IACH,QAAQ,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAAC;IAElC;;OAEG;IACH,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC;IAEzB;;OAEG;IACH,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC;IAExB;;OAEG;IACH,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC;IAExB;;OAEG;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,0 +1,97 @@
|
|
|
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 { PostgresStorageSchemaError } from "./errors.js";
|
|
15
|
+
/**
|
|
16
|
+
* Creates or checks complete PostgreSQL B-tree lookup indexes.
|
|
17
|
+
*/
|
|
18
|
+
export const PostgresRecordIndexes = Object.freeze({
|
|
19
|
+
/**
|
|
20
|
+
* Establishes one declared index without repairing an incompatible definition.
|
|
21
|
+
* @param client Transaction client or read-only checker.
|
|
22
|
+
* @param schema Physical schema.
|
|
23
|
+
* @param table Physical table.
|
|
24
|
+
* @param index Complete ordered requirement.
|
|
25
|
+
* @param mode Creation or check mode.
|
|
26
|
+
*/
|
|
27
|
+
async ensure(client, schema, table, index, mode) {
|
|
28
|
+
let rows = await this.read(client, schema, table, index.name);
|
|
29
|
+
if (rows.length === 0) {
|
|
30
|
+
if (mode === "check")
|
|
31
|
+
throw new PostgresStorageSchemaError("PostgreSQL record index is missing.");
|
|
32
|
+
const qualified = `${this.quote(schema)}.${this.quote(table)}`;
|
|
33
|
+
const columns = index.columns.map((column) => this.quote(column)).join(", ");
|
|
34
|
+
await client.query(`CREATE INDEX ${this.quote(index.name)} ON ${qualified} USING btree (${columns})`);
|
|
35
|
+
rows = await this.read(client, schema, table, index.name);
|
|
36
|
+
}
|
|
37
|
+
this.assert(index, rows);
|
|
38
|
+
},
|
|
39
|
+
/**
|
|
40
|
+
* Reads ordered native index components and structural flags from the catalog.
|
|
41
|
+
* @param client PostgreSQL client.
|
|
42
|
+
* @param schema Physical schema.
|
|
43
|
+
* @param table Physical table.
|
|
44
|
+
* @param name Required physical index name.
|
|
45
|
+
* @returns Ordered catalog rows.
|
|
46
|
+
*/
|
|
47
|
+
async read(client, schema, table, name) {
|
|
48
|
+
const result = await client.query("SELECT a.attname AS column_name, key.ordinality AS ordinal, x.indisunique AS unique, " +
|
|
49
|
+
"x.indisvalid AS valid, x.indisready AS ready, x.indislive AS live, " +
|
|
50
|
+
"x.indpred IS NOT NULL AS partial, x.indexprs IS NOT NULL AS expression, " +
|
|
51
|
+
"x.indnkeyatts AS key_count, x.indnatts AS total_count, am.amname AS method, " +
|
|
52
|
+
"i.relkind AS kind, x.indoption[(key.ordinality - 1)::int] AS direction, " +
|
|
53
|
+
"op.opcdefault AS default_operator, " +
|
|
54
|
+
"x.indcollation[(key.ordinality - 1)::int] = a.attcollation AS column_collation " +
|
|
55
|
+
"FROM pg_class t JOIN pg_namespace n ON n.oid=t.relnamespace " +
|
|
56
|
+
"JOIN pg_index x ON x.indrelid=t.oid JOIN pg_class i ON i.oid=x.indexrelid " +
|
|
57
|
+
"JOIN pg_am am ON am.oid=i.relam " +
|
|
58
|
+
"JOIN LATERAL unnest(x.indkey) WITH ORDINALITY AS key(attnum, ordinality) ON true " +
|
|
59
|
+
"LEFT JOIN pg_attribute a ON a.attrelid=t.oid AND a.attnum=key.attnum " +
|
|
60
|
+
"LEFT JOIN pg_opclass op ON op.oid=x.indclass[(key.ordinality - 1)::int] " +
|
|
61
|
+
"WHERE n.nspname=$1 AND t.relname=$2 AND i.relname=$3 ORDER BY key.ordinality", [schema, table, name]);
|
|
62
|
+
return result.rows;
|
|
63
|
+
},
|
|
64
|
+
/**
|
|
65
|
+
* Rejects substituted, unusable, or incomplete index definitions.
|
|
66
|
+
* @param index Required index.
|
|
67
|
+
* @param rows Native ordered components.
|
|
68
|
+
*/
|
|
69
|
+
assert(index, rows) {
|
|
70
|
+
if (rows.length !== index.columns.length ||
|
|
71
|
+
rows.some((row, position) => row.column_name !== index.columns[position] ||
|
|
72
|
+
Number(row.ordinal) !== position + 1 ||
|
|
73
|
+
row.unique ||
|
|
74
|
+
!row.valid ||
|
|
75
|
+
!row.ready ||
|
|
76
|
+
!row.live ||
|
|
77
|
+
row.partial ||
|
|
78
|
+
row.expression ||
|
|
79
|
+
row.key_count !== index.columns.length ||
|
|
80
|
+
row.total_count !== index.columns.length ||
|
|
81
|
+
row.method !== "btree" ||
|
|
82
|
+
row.kind !== "i" ||
|
|
83
|
+
row.direction !== 0 ||
|
|
84
|
+
!row.default_operator ||
|
|
85
|
+
!row.column_collation))
|
|
86
|
+
throw new PostgresStorageSchemaError("PostgreSQL record index is incompatible.");
|
|
87
|
+
},
|
|
88
|
+
/**
|
|
89
|
+
* Quotes a physical identifier without truncation.
|
|
90
|
+
* @param value Physical identifier.
|
|
91
|
+
* @returns SQL-quoted identifier.
|
|
92
|
+
*/
|
|
93
|
+
quote(value) {
|
|
94
|
+
return `"${value.replaceAll('"', '""')}"`;
|
|
95
|
+
},
|
|
96
|
+
});
|
|
97
|
+
//# sourceMappingURL=record-indexes.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"record-indexes.js","sourceRoot":"","sources":["../../src/postgres/record-indexes.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAIH,OAAO,EAAE,0BAA0B,EAAE,MAAM,aAAa,CAAC;AA4IzD;;GAEG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAA8B,MAAM,CAAC,MAAM,CAAC;IAC5E;;;;;;;OAOG;IACH,KAAK,CAAC,MAAM,CACV,MAAkB,EAClB,MAAc,EACd,KAAa,EACb,KAAwB,EACxB,IAA4B;QAE5B,IAAI,IAAI,GAAG,MAAM,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,KAA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AC;IACrB,CAAC;IAED;;;;OAIG;IACH,MAAM,CAAC,KAAwB,EAAE,IAAyB;QACxD,IACE,IAAI,CAAC,MAAM,KAAK,KAAK,CAAC,OAAO,CAAC,MAAM;YACpC,IAAI,CAAC,IAAI,CACP,CAAC,GAAG,EAAE,QAAQ,EAAE,EAAE,CAChB,GAAG,CAAC,WAAW,KAAK,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC;gBAC3C,MAAM,CAAC,GAAG,CAAC,OAAO,CAAC,KAAK,QAAQ,GAAG,CAAC;gBACpC,GAAG,CAAC,MAAM;gBACV,CAAC,GAAG,CAAC,KAAK;gBACV,CAAC,GAAG,CAAC,KAAK;gBACV,CAAC,GAAG,CAAC,IAAI;gBACT,GAAG,CAAC,OAAO;gBACX,GAAG,CAAC,UAAU;gBACd,GAAG,CAAC,SAAS,KAAK,KAAK,CAAC,OAAO,CAAC,MAAM;gBACtC,GAAG,CAAC,WAAW,KAAK,KAAK,CAAC,OAAO,CAAC,MAAM;gBACxC,GAAG,CAAC,MAAM,KAAK,OAAO;gBACtB,GAAG,CAAC,IAAI,KAAK,GAAG;gBAChB,GAAG,CAAC,SAAS,KAAK,CAAC;gBACnB,CAAC,GAAG,CAAC,gBAAgB;gBACrB,CAAC,GAAG,CAAC,gBAAgB,CACxB;YAED,MAAM,IAAI,0BAA0B,CAAC,0CAA0C,CAAC,CAAC;IACrF,CAAC;IAED;;;;OAIG;IACH,KAAK,CAAC,KAAa;QACjB,OAAO,IAAI,KAAK,CAAC,UAAU,CAAC,GAAG,EAAE,IAAI,CAAC,GAAG,CAAC;IAC5C,CAAC;CACF,CAAC,CAAC"}
|
|
@@ -70,8 +70,8 @@ export interface PostgresRecordLifecycle {
|
|
|
70
70
|
*/
|
|
71
71
|
export interface PostgresRecordExecutor<I, R extends Message> {
|
|
72
72
|
/**
|
|
73
|
-
*
|
|
74
|
-
* @returns
|
|
73
|
+
* Binds the destination and prepares the table when this handle enables preparation on access.
|
|
74
|
+
* @returns Completion after binding and any preparation required by this handle.
|
|
75
75
|
*/
|
|
76
76
|
prepare(): Promise<void>;
|
|
77
77
|
/**
|
|
@@ -157,6 +157,7 @@ export declare class PostgresRecordStorage<I, R extends Message> extends RecordS
|
|
|
157
157
|
private readonly lifecycle;
|
|
158
158
|
private readonly onClose;
|
|
159
159
|
private readonly create?;
|
|
160
|
+
private readonly prepareOnAccess;
|
|
160
161
|
/**
|
|
161
162
|
* Reports that compare-and-set uses a conditional SQL mutation.
|
|
162
163
|
*/
|
|
@@ -172,10 +173,11 @@ export declare class PostgresRecordStorage<I, R extends Message> extends RecordS
|
|
|
172
173
|
* @param onClose Removes this handle from the factory's live set.
|
|
173
174
|
* @param create Optionally supplies custom create-table SQL.
|
|
174
175
|
* @param stringifiers Converts message IDs and columns reversibly.
|
|
176
|
+
* @param prepareOnAccess Whether data access prepares the physical table.
|
|
175
177
|
*/
|
|
176
|
-
constructor(context: StorageContext, spec: RecordSpec<I, R>, tableNameValue: string, onSchema: (schema: string) => PostgresTableSpec<I, R>, lifecycle: PostgresRecordLifecycle, onClose: () => void, create?: ((table: PostgresTableSpec<I, R>) => string) | undefined, stringifiers?: StringifierRegistry);
|
|
178
|
+
constructor(context: StorageContext, spec: RecordSpec<I, R>, tableNameValue: string, onSchema: (schema: string) => PostgresTableSpec<I, R>, lifecycle: PostgresRecordLifecycle, onClose: () => void, create?: ((table: PostgresTableSpec<I, R>) => string) | undefined, stringifiers?: StringifierRegistry, prepareOnAccess?: boolean);
|
|
177
179
|
/**
|
|
178
|
-
* Returns the bound layout after
|
|
180
|
+
* Returns the bound layout after destination resolution.
|
|
179
181
|
*
|
|
180
182
|
* @returns The resolved physical layout.
|
|
181
183
|
*/
|
|
@@ -187,21 +189,21 @@ export declare class PostgresRecordStorage<I, R extends Message> extends RecordS
|
|
|
187
189
|
*/
|
|
188
190
|
get tableName(): string;
|
|
189
191
|
/**
|
|
190
|
-
*
|
|
192
|
+
* Binds this table before a record operation and applies this handle's preparation policy.
|
|
191
193
|
*
|
|
192
|
-
* @returns
|
|
194
|
+
* @returns Completion after binding and any preparation required by this handle.
|
|
193
195
|
*/
|
|
194
196
|
prepare(): Promise<void>;
|
|
195
197
|
/**
|
|
196
|
-
*
|
|
198
|
+
* Binds an already admitted operation and applies this handle's preparation policy.
|
|
197
199
|
*
|
|
198
|
-
* @returns Completion after table preparation.
|
|
200
|
+
* @returns Completion after binding and any required table preparation.
|
|
199
201
|
*/
|
|
200
202
|
private prepareInternal;
|
|
201
203
|
/**
|
|
202
|
-
* Binds the destination and prepares its physical table.
|
|
204
|
+
* Binds the destination and prepares its physical table when enabled for this handle.
|
|
203
205
|
*
|
|
204
|
-
* @returns Completion after
|
|
206
|
+
* @returns Completion after binding and any required table preparation.
|
|
205
207
|
*/
|
|
206
208
|
private prepareBound;
|
|
207
209
|
/**
|
|
@@ -385,7 +387,7 @@ export declare class PostgresRecordStorage<I, R extends Message> extends RecordS
|
|
|
385
387
|
*/
|
|
386
388
|
private casUpdateSql;
|
|
387
389
|
/**
|
|
388
|
-
* Executes work with one
|
|
390
|
+
* Executes work with one automatically released client after applying this handle's policy.
|
|
389
391
|
*
|
|
390
392
|
* @typeParam T The value returned by the client work.
|
|
391
393
|
* @param work Performs the client work.
|
|
@@ -393,7 +395,7 @@ export declare class PostgresRecordStorage<I, R extends Message> extends RecordS
|
|
|
393
395
|
*/
|
|
394
396
|
private using;
|
|
395
397
|
/**
|
|
396
|
-
* Executes one
|
|
398
|
+
* Executes one record operation on a released client after applying this handle's policy.
|
|
397
399
|
*
|
|
398
400
|
* @typeParam T The operation result.
|
|
399
401
|
* @param work Performs the client operation.
|
|
@@ -409,7 +411,7 @@ export declare class PostgresRecordStorage<I, R extends Message> extends RecordS
|
|
|
409
411
|
*/
|
|
410
412
|
private transaction;
|
|
411
413
|
/**
|
|
412
|
-
* Executes one
|
|
414
|
+
* Executes one Agent transaction on a released client after applying this handle's policy.
|
|
413
415
|
*
|
|
414
416
|
* @typeParam T The transaction result.
|
|
415
417
|
* @param work Performs work on the transaction client.
|
|
@@ -582,6 +584,13 @@ export declare class PostgresRecordStorage<I, R extends Message> extends RecordS
|
|
|
582
584
|
* @returns The parameterized SQL predicate.
|
|
583
585
|
*/
|
|
584
586
|
private predicate;
|
|
587
|
+
/**
|
|
588
|
+
* Returns indexable equality only for present fixed-byte column values.
|
|
589
|
+
* @param name Declared comparison column.
|
|
590
|
+
* @param value Compared logical value.
|
|
591
|
+
* @returns Equality SQL preserving null semantics otherwise.
|
|
592
|
+
*/
|
|
593
|
+
private equalityOperator;
|
|
585
594
|
/**
|
|
586
595
|
* Validates and quotes one queryable column name.
|
|
587
596
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"record-storage.d.ts","sourceRoot":"","sources":["../../src/postgres/record-storage.ts"],"names":[],"mappings":"AAcA,OAAO,EAAoC,KAAK,OAAO,EAAE,MAAM,oBAAoB,CAAC;AACpF,OAAO,EAA8B,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAC3F,OAAO,EAGL,WAAW,EACX,aAAa,EAEb,KAAK,mBAAmB,EAExB,KAAK,WAAW,EAChB,KAAK,UAAU,EACf,KAAK,cAAc,EACnB,KAAK,wBAAwB,EAC9B,MAAM,6BAA6B,CAAC;AACrC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,IAAI,CAAC;AAUrC,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AACxD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAI9D;;;;;;GAMG;AACH,MAAM,MAAM,iBAAiB,GAAG,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,KAAK,OAAO,CAAC,CAAC,CAAC,CAAC;AAE1E;;GAEG;AACH,MAAM,WAAW,uBAAuB;IACtC;;;;OAIG;IACH,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IAEzB;;;;;;OAMG;IACH,OAAO,CA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;;;;;;OAMG;IACH,OAAO,CAAC,mBAAmB;IA4B3B;;;;;OAKG;IACH,OAAO,CAAC,wBAAwB;IAkBhC;;;;;OAKG;IACH,OAAO,CAAC,sBAAsB;IAkB9B;;;;;;OAMG;IACH,OAAO,CAAC,oBAAoB;IAc5B;;;;;OAKG;IACH,OAAO,CAAC,kBAAkB;IAO1B;;;;;;OAMG;IACH,OAAO,CAAC,aAAa;IAuBrB;;;;;OAKG;IACH,OAAO,CAAC,WAAW;IAWnB;;;;;;OAMG;IACH,OAAO,CAAC,YAAY;IAiCpB;;;;;;;;OAQG;IACH,OAAO,CAAC,SAAS;IAajB;;;;;;OAMG;IACH,OAAO,CAAC,SAAS;IAiBjB;;;;;OAKG;IACH,OAAO,CAAC,gBAAgB;IAUxB;;;;;OAKG;IACH,OAAO,CAAC,MAAM;IAOd;;;;;;OAMG;IACH,OAAO,CAAC,KAAK;IAQb;;;;;OAKG;IACH,OAAO,CAAC,EAAE;IAQV;;;;;;OAMG;IACH,OAAO,CAAC,IAAI;IAQZ;;;;OAIG;IACH,OAAO,CAAC,SAAS;IAIjB;;;;OAIG;IACH,OAAO,CAAC,SAAS;IAIjB;;;;OAIG;IACH,OAAO,CAAC,YAAY;IAIpB;;;;OAIG;IACH,OAAO,CAAC,SAAS;IAMjB;;;;OAIG;IACH,OAAO,CAAC,SAAS;IAOjB;;;;;;OAMG;IACH,OAAO,CAAC,SAAS;CAGlB;AAED;;;;;GAKG;AACH,KAAK,YAAY,CAAC,CAAC,EAAE,CAAC,SAAS,OAAO,IAAI,UAAU,CAAC,UAAU,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC"}
|
|
@@ -31,6 +31,7 @@ export class PostgresRecordStorage extends RecordStorage {
|
|
|
31
31
|
lifecycle;
|
|
32
32
|
onClose;
|
|
33
33
|
create;
|
|
34
|
+
prepareOnAccess;
|
|
34
35
|
/**
|
|
35
36
|
* Reports that compare-and-set uses a conditional SQL mutation.
|
|
36
37
|
*/
|
|
@@ -50,19 +51,21 @@ export class PostgresRecordStorage extends RecordStorage {
|
|
|
50
51
|
* @param onClose Removes this handle from the factory's live set.
|
|
51
52
|
* @param create Optionally supplies custom create-table SQL.
|
|
52
53
|
* @param stringifiers Converts message IDs and columns reversibly.
|
|
54
|
+
* @param prepareOnAccess Whether data access prepares the physical table.
|
|
53
55
|
*/
|
|
54
|
-
constructor(context, spec, tableNameValue, onSchema, lifecycle, onClose, create, stringifiers = defaultStringifierRegistry) {
|
|
56
|
+
constructor(context, spec, tableNameValue, onSchema, lifecycle, onClose, create, stringifiers = defaultStringifierRegistry, prepareOnAccess = true) {
|
|
55
57
|
super(context, spec);
|
|
56
58
|
this.tableNameValue = tableNameValue;
|
|
57
59
|
this.onSchema = onSchema;
|
|
58
60
|
this.lifecycle = lifecycle;
|
|
59
61
|
this.onClose = onClose;
|
|
60
62
|
this.create = create;
|
|
63
|
+
this.prepareOnAccess = prepareOnAccess;
|
|
61
64
|
this.#idColumn = new PostgresIdColumn(spec.idType, stringifiers);
|
|
62
65
|
this.#columns = new PostgresColumnMapping(stringifiers);
|
|
63
66
|
}
|
|
64
67
|
/**
|
|
65
|
-
* Returns the bound layout after
|
|
68
|
+
* Returns the bound layout after destination resolution.
|
|
66
69
|
*
|
|
67
70
|
* @returns The resolved physical layout.
|
|
68
71
|
*/
|
|
@@ -80,25 +83,25 @@ export class PostgresRecordStorage extends RecordStorage {
|
|
|
80
83
|
return this.tableNameValue;
|
|
81
84
|
}
|
|
82
85
|
/**
|
|
83
|
-
*
|
|
86
|
+
* Binds this table before a record operation and applies this handle's preparation policy.
|
|
84
87
|
*
|
|
85
|
-
* @returns
|
|
88
|
+
* @returns Completion after binding and any preparation required by this handle.
|
|
86
89
|
*/
|
|
87
90
|
prepare() {
|
|
88
91
|
return this.admit(() => this.prepareInternal());
|
|
89
92
|
}
|
|
90
93
|
/**
|
|
91
|
-
*
|
|
94
|
+
* Binds an already admitted operation and applies this handle's preparation policy.
|
|
92
95
|
*
|
|
93
|
-
* @returns Completion after table preparation.
|
|
96
|
+
* @returns Completion after binding and any required table preparation.
|
|
94
97
|
*/
|
|
95
98
|
prepareInternal() {
|
|
96
99
|
return this.lifecycle.track(Promise.resolve().then(() => this.prepareBound()));
|
|
97
100
|
}
|
|
98
101
|
/**
|
|
99
|
-
* Binds the destination and prepares its physical table.
|
|
102
|
+
* Binds the destination and prepares its physical table when enabled for this handle.
|
|
100
103
|
*
|
|
101
|
-
* @returns Completion after
|
|
104
|
+
* @returns Completion after binding and any required table preparation.
|
|
102
105
|
*/
|
|
103
106
|
async prepareBound() {
|
|
104
107
|
this.#binding ??= this.bind().catch((error) => {
|
|
@@ -106,6 +109,8 @@ export class PostgresRecordStorage extends RecordStorage {
|
|
|
106
109
|
throw error;
|
|
107
110
|
});
|
|
108
111
|
await this.#binding;
|
|
112
|
+
if (!this.prepareOnAccess)
|
|
113
|
+
return;
|
|
109
114
|
const create = this.create;
|
|
110
115
|
await this.lifecycle.prepare(this.table, create === undefined ? undefined : () => create(this.table));
|
|
111
116
|
}
|
|
@@ -438,7 +443,7 @@ export class PostgresRecordStorage extends RecordStorage {
|
|
|
438
443
|
return `UPDATE ${this.qualified()} SET ${assignments.join(", ")} WHERE "ID" = $1 AND "bytes" = $2`;
|
|
439
444
|
}
|
|
440
445
|
/**
|
|
441
|
-
* Executes work with one
|
|
446
|
+
* Executes work with one automatically released client after applying this handle's policy.
|
|
442
447
|
*
|
|
443
448
|
* @typeParam T The value returned by the client work.
|
|
444
449
|
* @param work Performs the client work.
|
|
@@ -448,7 +453,7 @@ export class PostgresRecordStorage extends RecordStorage {
|
|
|
448
453
|
return this.lifecycle.track(this.usePrepared(work));
|
|
449
454
|
}
|
|
450
455
|
/**
|
|
451
|
-
* Executes one
|
|
456
|
+
* Executes one record operation on a released client after applying this handle's policy.
|
|
452
457
|
*
|
|
453
458
|
* @typeParam T The operation result.
|
|
454
459
|
* @param work Performs the client operation.
|
|
@@ -480,7 +485,7 @@ export class PostgresRecordStorage extends RecordStorage {
|
|
|
480
485
|
return this.lifecycle.track(this.transactionPrepared(work));
|
|
481
486
|
}
|
|
482
487
|
/**
|
|
483
|
-
* Executes one
|
|
488
|
+
* Executes one Agent transaction on a released client after applying this handle's policy.
|
|
484
489
|
*
|
|
485
490
|
* @typeParam T The transaction result.
|
|
486
491
|
* @param work Performs work on the transaction client.
|
|
@@ -824,7 +829,8 @@ export class PostgresRecordStorage extends RecordStorage {
|
|
|
824
829
|
for (const filter of query.filters ?? []) {
|
|
825
830
|
const column = this.column(filter.column === "id" ? "ID" : filter.column);
|
|
826
831
|
const accepted = RecordQuery.acceptedValues(filter);
|
|
827
|
-
const alternatives = accepted.map((value) => `${column}
|
|
832
|
+
const alternatives = accepted.map((value) => `${column} ${this.equalityOperator(filter.column, value)} ` +
|
|
833
|
+
bind.add(this.value(filter.column, value)));
|
|
828
834
|
clauses.push(accepted.length === 0
|
|
829
835
|
? "1=0"
|
|
830
836
|
: accepted.length === 1
|
|
@@ -906,12 +912,31 @@ export class PostgresRecordStorage extends RecordStorage {
|
|
|
906
912
|
predicate(predicate, bind) {
|
|
907
913
|
if (predicate.kind === "ids")
|
|
908
914
|
return `"ID" IN (${predicate.ids.map((id) => bind.add(this.id(id))).join(", ")})`;
|
|
909
|
-
if (predicate.kind === "comparison")
|
|
910
|
-
|
|
915
|
+
if (predicate.kind === "comparison") {
|
|
916
|
+
const comparisonOperator = predicate.operator === "equal"
|
|
917
|
+
? this.equalityOperator(predicate.column, predicate.value)
|
|
918
|
+
: operator(predicate.operator);
|
|
919
|
+
return (`${this.column(predicate.column)} ${comparisonOperator} ` +
|
|
911
920
|
bind.add(this.value(predicate.column, predicate.value)));
|
|
921
|
+
}
|
|
912
922
|
const joiner = predicate.kind === "all" ? " AND " : " OR ";
|
|
913
923
|
return `(${predicate.predicates.map((child) => this.predicate(child, bind)).join(joiner)})`;
|
|
914
924
|
}
|
|
925
|
+
/**
|
|
926
|
+
* Returns indexable equality only for present fixed-byte column values.
|
|
927
|
+
* @param name Declared comparison column.
|
|
928
|
+
* @param value Compared logical value.
|
|
929
|
+
* @returns Equality SQL preserving null semantics otherwise.
|
|
930
|
+
*/
|
|
931
|
+
equalityOperator(name, value) {
|
|
932
|
+
const type = this.recordSpec.columns.find((column) => column.name === name)?.type;
|
|
933
|
+
return type?.kind === "scalar" &&
|
|
934
|
+
type.scalar === ScalarType.BYTES &&
|
|
935
|
+
type.byteLength !== undefined &&
|
|
936
|
+
value instanceof Uint8Array
|
|
937
|
+
? "="
|
|
938
|
+
: "IS NOT DISTINCT FROM";
|
|
939
|
+
}
|
|
915
940
|
/**
|
|
916
941
|
* Validates and quotes one queryable column name.
|
|
917
942
|
*
|