@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.
- package/LICENSE +201 -0
- package/README.md +102 -0
- package/REFERENCE.md +85 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +16 -0
- package/dist/index.js.map +1 -0
- package/dist/postgres/column-mapping.d.ts +33 -0
- package/dist/postgres/column-mapping.d.ts.map +1 -0
- package/dist/postgres/column-mapping.js +93 -0
- package/dist/postgres/column-mapping.js.map +1 -0
- package/dist/postgres/data-type.d.ts +25 -0
- package/dist/postgres/data-type.d.ts.map +1 -0
- package/dist/postgres/data-type.js +29 -0
- package/dist/postgres/data-type.js.map +1 -0
- package/dist/postgres/delivery-cleanup.d.ts +76 -0
- package/dist/postgres/delivery-cleanup.d.ts.map +1 -0
- package/dist/postgres/delivery-cleanup.js +224 -0
- package/dist/postgres/delivery-cleanup.js.map +1 -0
- package/dist/postgres/entity-commit.d.ts +114 -0
- package/dist/postgres/entity-commit.d.ts.map +1 -0
- package/dist/postgres/entity-commit.js +385 -0
- package/dist/postgres/entity-commit.js.map +1 -0
- package/dist/postgres/entity-history.d.ts +85 -0
- package/dist/postgres/entity-history.d.ts.map +1 -0
- package/dist/postgres/entity-history.js +840 -0
- package/dist/postgres/entity-history.js.map +1 -0
- package/dist/postgres/errors.d.ts +51 -0
- package/dist/postgres/errors.d.ts.map +1 -0
- package/dist/postgres/errors.js +113 -0
- package/dist/postgres/errors.js.map +1 -0
- package/dist/postgres/id-column.d.ts +61 -0
- package/dist/postgres/id-column.d.ts.map +1 -0
- package/dist/postgres/id-column.js +165 -0
- package/dist/postgres/id-column.js.map +1 -0
- package/dist/postgres/parameter.d.ts +5 -0
- package/dist/postgres/parameter.d.ts.map +1 -0
- package/dist/postgres/parameter.js +15 -0
- package/dist/postgres/parameter.js.map +1 -0
- package/dist/postgres/record-storage.d.ts +514 -0
- package/dist/postgres/record-storage.d.ts.map +1 -0
- package/dist/postgres/record-storage.js +849 -0
- package/dist/postgres/record-storage.js.map +1 -0
- package/dist/postgres/storage-factory.d.ts +321 -0
- package/dist/postgres/storage-factory.d.ts.map +1 -0
- package/dist/postgres/storage-factory.js +584 -0
- package/dist/postgres/storage-factory.js.map +1 -0
- package/dist/postgres/table-initializer.d.ts +66 -0
- package/dist/postgres/table-initializer.d.ts.map +1 -0
- package/dist/postgres/table-initializer.js +301 -0
- package/dist/postgres/table-initializer.js.map +1 -0
- package/dist/postgres/table-resolver.d.ts +41 -0
- package/dist/postgres/table-resolver.d.ts.map +1 -0
- package/dist/postgres/table-resolver.js +225 -0
- package/dist/postgres/table-resolver.js.map +1 -0
- package/dist/postgres/table-spec.d.ts +40 -0
- package/dist/postgres/table-spec.d.ts.map +1 -0
- package/dist/postgres/table-spec.js +126 -0
- package/dist/postgres/table-spec.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/package.json +40 -0
|
@@ -0,0 +1,514 @@
|
|
|
1
|
+
import { type Message } from "@bufbuild/protobuf";
|
|
2
|
+
import { StringifierRegistry } from "@spine-event-engine/core";
|
|
3
|
+
import { RecordStorage, type NormalizedQueryPlan, type RecordEntry, type RecordQuery, type RecordSpec, type StorageContext, type StorageQueryCapabilities } from "@spine-event-engine/storage";
|
|
4
|
+
import type { PoolClient } from "pg";
|
|
5
|
+
import type { PostgresParameter } from "./parameter.js";
|
|
6
|
+
import type { PostgresTableSpec } from "./storage-factory.js";
|
|
7
|
+
/**
|
|
8
|
+
* Manages PostgreSQL clients for one record-family handle.
|
|
9
|
+
*/
|
|
10
|
+
export interface PostgresRecordLifecycle {
|
|
11
|
+
/**
|
|
12
|
+
* Names the selected database for advisory coordination.
|
|
13
|
+
*/
|
|
14
|
+
readonly databaseName: string;
|
|
15
|
+
/**
|
|
16
|
+
* Names the resolved schema.
|
|
17
|
+
*/
|
|
18
|
+
readonly schema: string;
|
|
19
|
+
/**
|
|
20
|
+
* Acquires an available PostgreSQL client.
|
|
21
|
+
*
|
|
22
|
+
* @returns A client that the caller releases.
|
|
23
|
+
*/
|
|
24
|
+
acquire(): Promise<PoolClient>;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Performs package-local bounded operations for one PostgreSQL record family.
|
|
28
|
+
*
|
|
29
|
+
* This capability deliberately stays outside the package root: Entity history
|
|
30
|
+
* uses it to keep its SQL and transaction scope on the PostgreSQL provider.
|
|
31
|
+
*
|
|
32
|
+
* @typeParam I The storage identifier type.
|
|
33
|
+
* @typeParam R The stored Protobuf record type.
|
|
34
|
+
*/
|
|
35
|
+
export interface PostgresRecordExecutor<I, R extends Message> {
|
|
36
|
+
/**
|
|
37
|
+
* Prepares the backing table before acquiring an operation client.
|
|
38
|
+
* @returns A promise that resolves when the table is compatible.
|
|
39
|
+
*/
|
|
40
|
+
prepare(): Promise<void>;
|
|
41
|
+
/**
|
|
42
|
+
* Returns one PostgreSQL transaction with rollback and client release.
|
|
43
|
+
*
|
|
44
|
+
* @typeParam T The value returned by the transaction work.
|
|
45
|
+
* @param work Performs work with the transaction client.
|
|
46
|
+
* @returns The work result.
|
|
47
|
+
*/
|
|
48
|
+
transaction<T>(work: (client: PoolClient) => Promise<T>): Promise<T>;
|
|
49
|
+
/**
|
|
50
|
+
* Returns bounded work on one acquired PostgreSQL client.
|
|
51
|
+
*
|
|
52
|
+
* @typeParam T The value returned by the client work.
|
|
53
|
+
* @param work Performs work with the acquired client.
|
|
54
|
+
* @returns The work result.
|
|
55
|
+
*/
|
|
56
|
+
using<T>(work: (client: PoolClient) => Promise<T>): Promise<T>;
|
|
57
|
+
/**
|
|
58
|
+
* Reads one record on a caller-managed client.
|
|
59
|
+
* @param client Provides the transaction client.
|
|
60
|
+
* @param id Identifies the stored record.
|
|
61
|
+
* @param lock Requests a row lock when present.
|
|
62
|
+
* @returns The decoded record, when present.
|
|
63
|
+
*/
|
|
64
|
+
read(client: PoolClient, id: I, lock?: "for-update"): Promise<R | undefined>;
|
|
65
|
+
/**
|
|
66
|
+
* Checks that an immutable record is absent or byte-identical.
|
|
67
|
+
* @param client Provides the transaction client.
|
|
68
|
+
* @param record Provides the immutable record to inspect.
|
|
69
|
+
* @returns A promise that rejects for a conflicting payload.
|
|
70
|
+
*/
|
|
71
|
+
assertImmutable(client: PoolClient, record: R): Promise<void>;
|
|
72
|
+
/**
|
|
73
|
+
* Stores an immutable record on a caller-managed transaction client.
|
|
74
|
+
* @param client Provides the transaction client.
|
|
75
|
+
* @param record Provides the record to store.
|
|
76
|
+
* @returns A promise that resolves after storage or identity confirmation.
|
|
77
|
+
*/
|
|
78
|
+
appendImmutable(client: PoolClient, record: R): Promise<void>;
|
|
79
|
+
/**
|
|
80
|
+
* Writes one mutable record on a caller-managed transaction client.
|
|
81
|
+
* @param client Provides the transaction client.
|
|
82
|
+
* @param record Provides the record to write.
|
|
83
|
+
* @returns A promise that resolves after the upsert.
|
|
84
|
+
*/
|
|
85
|
+
write(client: PoolClient, record: R): Promise<void>;
|
|
86
|
+
/**
|
|
87
|
+
* Deletes one record on a caller-managed transaction client.
|
|
88
|
+
* @param client Provides the transaction client.
|
|
89
|
+
* @param id Identifies the stored record.
|
|
90
|
+
* @returns Whether PostgreSQL deleted the record.
|
|
91
|
+
*/
|
|
92
|
+
delete(client: PoolClient, id: I): Promise<boolean>;
|
|
93
|
+
/**
|
|
94
|
+
* Decodes records returned by one bounded PostgreSQL statement.
|
|
95
|
+
* @param client Provides the transaction client.
|
|
96
|
+
* @param sql Supplies bounded provider SQL.
|
|
97
|
+
* @param values Supplies bound SQL values.
|
|
98
|
+
* @returns Decoded records.
|
|
99
|
+
*/
|
|
100
|
+
query(client: PoolClient, sql: string, values: readonly PostgresParameter[]): Promise<readonly R[]>;
|
|
101
|
+
/**
|
|
102
|
+
* Converts one declared column value to its PostgreSQL representation.
|
|
103
|
+
* @param name Names the declared column.
|
|
104
|
+
* @param value Supplies the logical column value.
|
|
105
|
+
* @returns The PostgreSQL parameter value.
|
|
106
|
+
*/
|
|
107
|
+
column(name: string, value: unknown): PostgresParameter;
|
|
108
|
+
/**
|
|
109
|
+
* Returns the fully qualified backing table identifier.
|
|
110
|
+
* @returns The validated table identifier.
|
|
111
|
+
*/
|
|
112
|
+
table(): string;
|
|
113
|
+
/**
|
|
114
|
+
* Returns a hash for one provider-private advisory-lock identity.
|
|
115
|
+
* @param domain Separates lock kinds.
|
|
116
|
+
* @param identity Identifies the locked resource.
|
|
117
|
+
* @returns A signed PostgreSQL advisory key.
|
|
118
|
+
*/
|
|
119
|
+
lock(domain: string, ...identity: readonly string[]): bigint;
|
|
120
|
+
/**
|
|
121
|
+
* Returns the same record-mutation lock used by compare-and-set.
|
|
122
|
+
* @param id Identifies the guarded record.
|
|
123
|
+
* @returns A signed PostgreSQL advisory key.
|
|
124
|
+
*/
|
|
125
|
+
lockRecord(id: I): bigint;
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Stores one record family in one qualified PostgreSQL table.
|
|
129
|
+
*
|
|
130
|
+
* @typeParam I The storage identifier type.
|
|
131
|
+
* @typeParam R The stored Protobuf record type.
|
|
132
|
+
*/
|
|
133
|
+
export declare class PostgresRecordStorage<I, R extends Message> extends RecordStorage<I, R> {
|
|
134
|
+
#private;
|
|
135
|
+
private readonly table;
|
|
136
|
+
private readonly lifecycle;
|
|
137
|
+
private readonly onClose;
|
|
138
|
+
/**
|
|
139
|
+
* Reports that compare-and-set uses PostgreSQL transaction coordination.
|
|
140
|
+
*/
|
|
141
|
+
readonly atomicCompareAndSet = true;
|
|
142
|
+
/**
|
|
143
|
+
* Creates a PostgreSQL record-family handle.
|
|
144
|
+
*
|
|
145
|
+
* @param context Identifies the storage boundary for this handle.
|
|
146
|
+
* @param spec Defines the record type, ID type, and declared columns.
|
|
147
|
+
* @param table Supplies the resolved physical table layout.
|
|
148
|
+
* @param lifecycle Acquires clients for the selected database and schema.
|
|
149
|
+
* @param onClose Removes this handle from the factory's live set.
|
|
150
|
+
* @param create Optionally supplies custom create-table SQL.
|
|
151
|
+
* @param stringifiers Converts message IDs and columns reversibly.
|
|
152
|
+
*/
|
|
153
|
+
constructor(context: StorageContext, spec: RecordSpec<I, R>, table: PostgresTableSpec<I, R>, lifecycle: PostgresRecordLifecycle, onClose: () => void, create?: () => string, stringifiers?: StringifierRegistry);
|
|
154
|
+
/**
|
|
155
|
+
* Returns the resolved physical table name.
|
|
156
|
+
*
|
|
157
|
+
* @returns The physical table name without its schema.
|
|
158
|
+
*/
|
|
159
|
+
get tableName(): string;
|
|
160
|
+
/**
|
|
161
|
+
* Prepares this table before an external coordinator transaction.
|
|
162
|
+
*
|
|
163
|
+
* @returns A promise that resolves after compatible initialization.
|
|
164
|
+
*/
|
|
165
|
+
prepare(): Promise<void>;
|
|
166
|
+
/**
|
|
167
|
+
* Opens package-local bounded history operations for this record family.
|
|
168
|
+
*
|
|
169
|
+
* @internal
|
|
170
|
+
* @returns PostgreSQL-only history execution capabilities.
|
|
171
|
+
*/
|
|
172
|
+
historyExecutor(): PostgresRecordExecutor<I, R>;
|
|
173
|
+
/**
|
|
174
|
+
* Closes this handle and unregisters it from the factory.
|
|
175
|
+
*/
|
|
176
|
+
close(): void;
|
|
177
|
+
/**
|
|
178
|
+
* Writes an immutable record or confirms an identical existing payload.
|
|
179
|
+
*
|
|
180
|
+
* @param record Provides the immutable record to store.
|
|
181
|
+
* @returns A promise that resolves when the payload is stored or confirmed.
|
|
182
|
+
*/
|
|
183
|
+
writeImmutable(record: R): Promise<void>;
|
|
184
|
+
/**
|
|
185
|
+
* Checks whether an immutable record is absent or byte-identical.
|
|
186
|
+
*
|
|
187
|
+
* @param record Provides the immutable record to inspect.
|
|
188
|
+
* @returns A promise that rejects when the stored payload differs.
|
|
189
|
+
*/
|
|
190
|
+
assertImmutable(record: R): Promise<void>;
|
|
191
|
+
/**
|
|
192
|
+
* Deletes one record by storage ID.
|
|
193
|
+
*
|
|
194
|
+
* @param id Identifies the record to delete.
|
|
195
|
+
* @returns Whether a stored record was deleted.
|
|
196
|
+
*/
|
|
197
|
+
protected deleteRecord(id: I): Promise<boolean>;
|
|
198
|
+
/**
|
|
199
|
+
* Reads one record by storage ID.
|
|
200
|
+
*
|
|
201
|
+
* @param id Identifies the record to read.
|
|
202
|
+
* @returns The decoded record, when present.
|
|
203
|
+
*/
|
|
204
|
+
protected readRecord(id: I): Promise<R | undefined>;
|
|
205
|
+
/**
|
|
206
|
+
* Returns query records from one parameterized PostgreSQL statement.
|
|
207
|
+
*
|
|
208
|
+
* @param query Defines IDs, filters, order, continuation, and bounds.
|
|
209
|
+
* @returns The decoded records admitted by the query.
|
|
210
|
+
*/
|
|
211
|
+
protected queryRecordEntries(query: RecordQuery<I>): Promise<readonly RecordEntry<I, R>[]>;
|
|
212
|
+
/**
|
|
213
|
+
* Returns complete normalized-plan pushdown capabilities.
|
|
214
|
+
*
|
|
215
|
+
* @returns The normalized query features implemented by this storage.
|
|
216
|
+
*/
|
|
217
|
+
protected queryCapabilities(): StorageQueryCapabilities;
|
|
218
|
+
/**
|
|
219
|
+
* Executes a normalized plan as one parameterized statement.
|
|
220
|
+
*
|
|
221
|
+
* @param plan Defines the validated normalized predicate and bounds.
|
|
222
|
+
* @returns The decoded records admitted by the plan.
|
|
223
|
+
*/
|
|
224
|
+
protected queryPlanRecordEntries(plan: NormalizedQueryPlan<I>): Promise<readonly RecordEntry<I, R>[]>;
|
|
225
|
+
/**
|
|
226
|
+
* Compares and atomically applies one mutation with bounded retry.
|
|
227
|
+
*
|
|
228
|
+
* @param id Identifies the record guarded by the transaction advisory lock.
|
|
229
|
+
* @param expected Specifies the current materialized record required to write.
|
|
230
|
+
* @param next Specifies the replacement record, or absence for deletion.
|
|
231
|
+
* @returns Whether the current stored payload matched the expected payload.
|
|
232
|
+
*/
|
|
233
|
+
protected compareAndSetRecord(id: I, expected: Materialized<I, R> | undefined, next: Materialized<I, R> | undefined): Promise<boolean>;
|
|
234
|
+
/**
|
|
235
|
+
* Writes all supplied materialized records in source order and one transaction.
|
|
236
|
+
*
|
|
237
|
+
* @param records Provides the materialized records to write.
|
|
238
|
+
* @returns A promise that resolves after the transaction commits.
|
|
239
|
+
*/
|
|
240
|
+
protected writeAllRecords(records: readonly Materialized<I, R>[]): Promise<void>;
|
|
241
|
+
/**
|
|
242
|
+
* Writes one materialized record.
|
|
243
|
+
*
|
|
244
|
+
* @param record Provides the materialized record to write.
|
|
245
|
+
* @returns A promise that resolves after PostgreSQL applies the upsert.
|
|
246
|
+
*/
|
|
247
|
+
protected writeRecord(record: Materialized<I, R>): Promise<void>;
|
|
248
|
+
/**
|
|
249
|
+
* Applies one compare-and-set attempt inside a transaction.
|
|
250
|
+
*
|
|
251
|
+
* @param id Identifies the guarded record.
|
|
252
|
+
* @param expected Supplies the required current materialization.
|
|
253
|
+
* @param next Supplies the replacement or requests deletion when absent.
|
|
254
|
+
* @returns Whether the current record matched the expected record.
|
|
255
|
+
*/
|
|
256
|
+
private casOnce;
|
|
257
|
+
/**
|
|
258
|
+
* Executes work in one transaction and always releases its client.
|
|
259
|
+
*
|
|
260
|
+
* @typeParam T The value returned by the transaction work.
|
|
261
|
+
* @param work Performs the transaction work.
|
|
262
|
+
* @returns The value returned by the work after a successful commit.
|
|
263
|
+
*/
|
|
264
|
+
private transaction;
|
|
265
|
+
/**
|
|
266
|
+
* Executes work with one prepared and automatically released client.
|
|
267
|
+
*
|
|
268
|
+
* @typeParam T The value returned by the client work.
|
|
269
|
+
* @param work Performs the client work.
|
|
270
|
+
* @returns The value returned by the work.
|
|
271
|
+
*/
|
|
272
|
+
private using;
|
|
273
|
+
/**
|
|
274
|
+
* Reads and decodes one record on the supplied client.
|
|
275
|
+
*
|
|
276
|
+
* @param client Provides the active client.
|
|
277
|
+
* @param id Identifies the record.
|
|
278
|
+
* @param lock Whether to lock the selected row for update.
|
|
279
|
+
* @returns The decoded record, when present.
|
|
280
|
+
*/
|
|
281
|
+
private readOn;
|
|
282
|
+
/**
|
|
283
|
+
* Executes a compiled query and decodes its record entries.
|
|
284
|
+
*
|
|
285
|
+
* @param client Provides the active client.
|
|
286
|
+
* @param query Supplies the compiled SQL and bind values.
|
|
287
|
+
* @returns The decoded record entries.
|
|
288
|
+
*/
|
|
289
|
+
private entries;
|
|
290
|
+
/**
|
|
291
|
+
* Acquires the transaction lock for one record slot.
|
|
292
|
+
*
|
|
293
|
+
* @param client Provides the active transaction client.
|
|
294
|
+
* @param id Identifies the record slot.
|
|
295
|
+
* @returns A promise that resolves after lock acquisition.
|
|
296
|
+
*/
|
|
297
|
+
private lockSlot;
|
|
298
|
+
/**
|
|
299
|
+
* Acquires record-slot locks in stable order to avoid deadlocks.
|
|
300
|
+
*
|
|
301
|
+
* @param client Provides the active transaction client.
|
|
302
|
+
* @param ids Identify the record slots.
|
|
303
|
+
* @returns A promise that resolves after every lock is acquired.
|
|
304
|
+
*/
|
|
305
|
+
private lockSlots;
|
|
306
|
+
/**
|
|
307
|
+
* Writes one record on a caller-managed client.
|
|
308
|
+
*
|
|
309
|
+
* @param client Provides the active transaction client.
|
|
310
|
+
* @param record Supplies the record to write.
|
|
311
|
+
* @param id Identifies the record.
|
|
312
|
+
* @param locked Whether the caller already holds the record lock.
|
|
313
|
+
* @returns A promise that resolves after the upsert.
|
|
314
|
+
*/
|
|
315
|
+
private writeOn;
|
|
316
|
+
/**
|
|
317
|
+
* Deletes one record on a caller-managed client.
|
|
318
|
+
*
|
|
319
|
+
* @param client Provides the active transaction client.
|
|
320
|
+
* @param id Identifies the record.
|
|
321
|
+
* @param locked Whether the caller already holds the record lock.
|
|
322
|
+
* @returns Whether PostgreSQL deleted a row.
|
|
323
|
+
*/
|
|
324
|
+
private deleteOn;
|
|
325
|
+
/**
|
|
326
|
+
* Stores an immutable record or confirms an identical existing record.
|
|
327
|
+
*
|
|
328
|
+
* @param client Provides the active transaction client.
|
|
329
|
+
* @param record Supplies the immutable record.
|
|
330
|
+
* @param locked Whether the caller already holds the record lock.
|
|
331
|
+
* @returns A promise that resolves after insertion or identity confirmation.
|
|
332
|
+
*/
|
|
333
|
+
private appendImmutableOn;
|
|
334
|
+
/**
|
|
335
|
+
* Checks that an immutable record is absent or byte-identical.
|
|
336
|
+
*
|
|
337
|
+
* @param client Provides the active client.
|
|
338
|
+
* @param record Supplies the immutable record.
|
|
339
|
+
* @returns A promise that rejects for a conflicting stored payload.
|
|
340
|
+
*/
|
|
341
|
+
private assertImmutableOn;
|
|
342
|
+
/**
|
|
343
|
+
* Executes provider SQL and decodes its record rows.
|
|
344
|
+
*
|
|
345
|
+
* @param client Provides the active client.
|
|
346
|
+
* @param sql Supplies parameterized SQL.
|
|
347
|
+
* @param values Supply the bind values.
|
|
348
|
+
* @returns The decoded records.
|
|
349
|
+
*/
|
|
350
|
+
private historyEntries;
|
|
351
|
+
/**
|
|
352
|
+
* Converts one declared history column value to its database representation.
|
|
353
|
+
*
|
|
354
|
+
* @param name Names the declared column.
|
|
355
|
+
* @param value Supplies its logical value.
|
|
356
|
+
* @returns The PostgreSQL parameter value.
|
|
357
|
+
*/
|
|
358
|
+
private historyColumn;
|
|
359
|
+
/**
|
|
360
|
+
* Calculates a stable advisory-lock key within the selected database and schema.
|
|
361
|
+
*
|
|
362
|
+
* @param domain Separates lock purposes.
|
|
363
|
+
* @param identity Identifies the protected resource.
|
|
364
|
+
* @returns A signed PostgreSQL advisory-lock key.
|
|
365
|
+
*/
|
|
366
|
+
private historyKey;
|
|
367
|
+
/**
|
|
368
|
+
* Encodes one record as ordered table-column values.
|
|
369
|
+
*
|
|
370
|
+
* @param record Supplies the record to encode.
|
|
371
|
+
* @param id Identifies the record.
|
|
372
|
+
* @returns Values ordered for the generated insert statement.
|
|
373
|
+
*/
|
|
374
|
+
private values;
|
|
375
|
+
/**
|
|
376
|
+
* Builds parameterized PostgreSQL SQL for a record query.
|
|
377
|
+
*
|
|
378
|
+
* @param query Defines filters, ordering, continuation, and bounds.
|
|
379
|
+
* @returns The compiled statement.
|
|
380
|
+
*/
|
|
381
|
+
private recordQuery;
|
|
382
|
+
/**
|
|
383
|
+
* Builds one bounded statement for a normalized query plan.
|
|
384
|
+
*
|
|
385
|
+
* @param plan Supplies the normalized plan.
|
|
386
|
+
* @returns The compiled statement.
|
|
387
|
+
*/
|
|
388
|
+
private planQuery;
|
|
389
|
+
/**
|
|
390
|
+
* Builds predicates for IDs and declared-column equality filters.
|
|
391
|
+
*
|
|
392
|
+
* @param query Supplies the record query.
|
|
393
|
+
* @param bind Collects parameter values.
|
|
394
|
+
* @returns SQL predicate fragments.
|
|
395
|
+
*/
|
|
396
|
+
private recordClauses;
|
|
397
|
+
/**
|
|
398
|
+
* Builds deterministic ordering for one record query.
|
|
399
|
+
*
|
|
400
|
+
* @param query Supplies the requested sort order.
|
|
401
|
+
* @returns The PostgreSQL order expression.
|
|
402
|
+
*/
|
|
403
|
+
private recordOrder;
|
|
404
|
+
/**
|
|
405
|
+
* Builds the continuation predicate for one record query.
|
|
406
|
+
*
|
|
407
|
+
* @param query Supplies the sort order and continuation values.
|
|
408
|
+
* @param bind Collects parameter values.
|
|
409
|
+
* @returns The continuation predicate.
|
|
410
|
+
*/
|
|
411
|
+
private continuation;
|
|
412
|
+
/**
|
|
413
|
+
* Builds one direction-aware continuation comparison.
|
|
414
|
+
*
|
|
415
|
+
* @param column Supplies the quoted column name.
|
|
416
|
+
* @param direction Supplies the requested sort direction.
|
|
417
|
+
* @param value Supplies the continuation value.
|
|
418
|
+
* @param bind Collects parameter values.
|
|
419
|
+
* @returns The comparison expression.
|
|
420
|
+
*/
|
|
421
|
+
private afterTerm;
|
|
422
|
+
/**
|
|
423
|
+
* Builds SQL for one normalized query predicate recursively.
|
|
424
|
+
*
|
|
425
|
+
* @param predicate Supplies the normalized predicate.
|
|
426
|
+
* @param bind Collects parameter values.
|
|
427
|
+
* @returns The parameterized SQL predicate.
|
|
428
|
+
*/
|
|
429
|
+
private predicate;
|
|
430
|
+
/**
|
|
431
|
+
* Validates and quotes one queryable column name.
|
|
432
|
+
*
|
|
433
|
+
* @param name Names the requested column.
|
|
434
|
+
* @returns The quoted PostgreSQL identifier.
|
|
435
|
+
*/
|
|
436
|
+
private column;
|
|
437
|
+
/**
|
|
438
|
+
* Converts one query value to its database representation.
|
|
439
|
+
*
|
|
440
|
+
* @param name Names the ID or declared column.
|
|
441
|
+
* @param value Supplies the logical value.
|
|
442
|
+
* @returns The PostgreSQL parameter value.
|
|
443
|
+
*/
|
|
444
|
+
private value;
|
|
445
|
+
/**
|
|
446
|
+
* Converts one record ID to its database representation.
|
|
447
|
+
*
|
|
448
|
+
* @param id Supplies the logical ID.
|
|
449
|
+
* @returns The PostgreSQL parameter value.
|
|
450
|
+
*/
|
|
451
|
+
private id;
|
|
452
|
+
/**
|
|
453
|
+
* Compares two optional records by their Protobuf bytes.
|
|
454
|
+
*
|
|
455
|
+
* @param left Supplies the first record.
|
|
456
|
+
* @param right Supplies the second record.
|
|
457
|
+
* @returns Whether both records are absent or byte-identical.
|
|
458
|
+
*/
|
|
459
|
+
private same;
|
|
460
|
+
/**
|
|
461
|
+
* Returns the quoted schema-qualified table name.
|
|
462
|
+
*
|
|
463
|
+
* @returns The qualified PostgreSQL identifier.
|
|
464
|
+
*/
|
|
465
|
+
private qualified;
|
|
466
|
+
/**
|
|
467
|
+
* Builds the delete statement for this record family.
|
|
468
|
+
*
|
|
469
|
+
* @returns Parameterized delete SQL.
|
|
470
|
+
*/
|
|
471
|
+
private deleteSql;
|
|
472
|
+
/**
|
|
473
|
+
* Builds the conflict-tolerant immutable insert statement.
|
|
474
|
+
*
|
|
475
|
+
* @returns Parameterized immutable-insert SQL.
|
|
476
|
+
*/
|
|
477
|
+
private immutableSql;
|
|
478
|
+
/**
|
|
479
|
+
* Builds the upsert statement for this record family.
|
|
480
|
+
*
|
|
481
|
+
* @returns Parameterized upsert SQL.
|
|
482
|
+
*/
|
|
483
|
+
private upsertSql;
|
|
484
|
+
/**
|
|
485
|
+
* Builds the base insert statement for this record family.
|
|
486
|
+
*
|
|
487
|
+
* @returns Parameterized insert SQL.
|
|
488
|
+
*/
|
|
489
|
+
private insertSql;
|
|
490
|
+
/**
|
|
491
|
+
* Builds PostgreSQL's unbounded-limit form for an offset-only query.
|
|
492
|
+
*
|
|
493
|
+
* @param bind Collects parameter values.
|
|
494
|
+
* @param offset Supplies the requested row offset.
|
|
495
|
+
* @returns The limit and offset clause.
|
|
496
|
+
*/
|
|
497
|
+
private offsetSql;
|
|
498
|
+
/**
|
|
499
|
+
* Calculates the advisory key for one record mutation.
|
|
500
|
+
*
|
|
501
|
+
* @param id Identifies the record.
|
|
502
|
+
* @returns The signed advisory-lock key.
|
|
503
|
+
*/
|
|
504
|
+
private casKey;
|
|
505
|
+
}
|
|
506
|
+
/**
|
|
507
|
+
* Represents one record after its declared columns are materialized.
|
|
508
|
+
*
|
|
509
|
+
* @typeParam I The record identifier type.
|
|
510
|
+
* @typeParam R The Protobuf record type.
|
|
511
|
+
*/
|
|
512
|
+
type Materialized<I, R extends Message> = ReturnType<RecordSpec<I, R>["materialize"]>;
|
|
513
|
+
export {};
|
|
514
|
+
//# sourceMappingURL=record-storage.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"record-storage.d.ts","sourceRoot":"","sources":["../../src/postgres/record-storage.ts"],"names":[],"mappings":"AAcA,OAAO,EAAwB,KAAK,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAExE,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAC/D,OAAO,EAGL,aAAa,EAEb,KAAK,mBAAmB,EAExB,KAAK,WAAW,EAChB,KAAK,WAAW,EAChB,KAAK,UAAU,EACf,KAAK,cAAc,EACnB,KAAK,wBAAwB,EAC9B,MAAM,6BAA6B,CAAC;AACrC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,IAAI,CAAC;AAWrC,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AACxD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,sBAAs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