@supalive/core 1.2.0 → 1.3.0
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/README.md +2 -2
- package/dist/db-ClCicssQ.js.map +1 -1
- package/dist/index-4Nis7Wnk.d.ts +1973 -0
- package/dist/index-4Nis7Wnk.d.ts.map +1 -0
- package/dist/index-Ca58CrWX.d.ts +2103 -0
- package/dist/index-Ca58CrWX.d.ts.map +1 -0
- package/dist/index-DDK9ZIYb.d.ts +2103 -0
- package/dist/index-DDK9ZIYb.d.ts.map +1 -0
- package/dist/{index-E1_1iRI1.d.ts → index-DJYvJYR4.d.ts} +6 -5
- package/dist/index-DJYvJYR4.d.ts.map +1 -0
- package/dist/index-Oz3eyddt.d.ts +1974 -0
- package/dist/index-Oz3eyddt.d.ts.map +1 -0
- package/dist/{mysql-BmkLy5oY.d.ts → mysql-53W9lRh9.d.ts} +2 -2
- package/dist/{mysql-BmkLy5oY.d.ts.map → mysql-53W9lRh9.d.ts.map} +1 -1
- package/dist/{mysql-Ca1B_0k_.js → mysql-C0mysDQ_.js} +1 -2
- package/dist/mysql-C0mysDQ_.js.map +1 -0
- package/dist/mysql-D0pFocWL.d.ts +109 -0
- package/dist/mysql-D0pFocWL.d.ts.map +1 -0
- package/dist/mysql-DF-dZHi7.d.ts +109 -0
- package/dist/mysql-DF-dZHi7.d.ts.map +1 -0
- package/dist/mysql-QWBVXBjM.d.ts +109 -0
- package/dist/mysql-QWBVXBjM.d.ts.map +1 -0
- package/dist/mysql-fECZYP_m.d.ts +109 -0
- package/dist/mysql-fECZYP_m.d.ts.map +1 -0
- package/dist/object-storage-4t7JvpuK.d.ts +67 -0
- package/dist/object-storage-4t7JvpuK.d.ts.map +1 -0
- package/dist/{postgres-v2ctNE6o.d.ts → postgres-7d6R9P7w.d.ts} +2 -2
- package/dist/{postgres-v2ctNE6o.d.ts.map → postgres-7d6R9P7w.d.ts.map} +1 -1
- package/dist/postgres-C1qWlB--.d.ts +113 -0
- package/dist/postgres-C1qWlB--.d.ts.map +1 -0
- package/dist/postgres-CKtJ62S4.d.ts +113 -0
- package/dist/postgres-CKtJ62S4.d.ts.map +1 -0
- package/dist/postgres-DdqpjjYF.d.ts +113 -0
- package/dist/postgres-DdqpjjYF.d.ts.map +1 -0
- package/dist/postgres-DhCgxVOr.d.ts +113 -0
- package/dist/postgres-DhCgxVOr.d.ts.map +1 -0
- package/dist/{postgres-CHDY1HPf.js → postgres-SvdXfb0w.js} +2 -6
- package/dist/postgres-SvdXfb0w.js.map +1 -0
- package/dist/procedure-Ze1GE-N9.js.map +1 -1
- package/dist/src/client/index.d.ts +1 -1
- package/dist/src/client/index.js +7 -1
- package/dist/src/client/index.js.map +1 -1
- package/dist/src/exports/mysql.d.ts +1 -1
- package/dist/src/exports/mysql.js +1 -1
- package/dist/src/exports/postgres.d.ts +1 -1
- package/dist/src/exports/postgres.js +1 -1
- package/dist/src/exports/procedure.d.ts +1 -1
- package/dist/src/exports/schema-sql.d.ts +16 -15
- package/dist/src/exports/schema-sql.d.ts.map +1 -1
- package/dist/src/exports/schema-sql.js +15 -3
- package/dist/src/exports/schema-sql.js.map +1 -1
- package/dist/src/exports/server.d.ts +22 -19
- package/dist/src/exports/server.d.ts.map +1 -1
- package/dist/src/exports/server.js +15 -8
- package/dist/src/exports/server.js.map +1 -1
- package/dist/src/exports/storage.d.ts +56 -0
- package/dist/src/exports/storage.d.ts.map +1 -0
- package/dist/src/exports/storage.js +62 -0
- package/dist/src/exports/storage.js.map +1 -0
- package/dist/src/exports/subscription-manager-worker-entry.js +1 -1
- package/dist/src/exports/types.d.ts +2 -2
- package/dist/{subscription-worker-CAf6MUta.js → subscription-worker-B2XtjFWY.js} +16 -15
- package/dist/subscription-worker-B2XtjFWY.js.map +1 -0
- package/dist/types_server-AN8OiTEx.d.ts +302 -0
- package/dist/types_server-AN8OiTEx.d.ts.map +1 -0
- package/dist/types_server-C9owgeSs.d.ts +302 -0
- package/dist/types_server-C9owgeSs.d.ts.map +1 -0
- package/dist/types_server-D5JDD_Dp.d.ts +430 -0
- package/dist/types_server-D5JDD_Dp.d.ts.map +1 -0
- package/dist/types_server-Dxx_Xx86.d.ts +430 -0
- package/dist/types_server-Dxx_Xx86.d.ts.map +1 -0
- package/dist/{types_server-CzAufcee.d.ts → types_server-wW3ZgE7l.d.ts} +2 -2
- package/dist/{types_server-CzAufcee.d.ts.map → types_server-wW3ZgE7l.d.ts.map} +1 -1
- package/package.json +15 -1
- package/dist/index-E1_1iRI1.d.ts.map +0 -1
- package/dist/mysql-Ca1B_0k_.js.map +0 -1
- package/dist/postgres-CHDY1HPf.js.map +0 -1
- package/dist/subscription-worker-CAf6MUta.js.map +0 -1
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { Bn as DbType, Gn as SqlBuilder, Gr as ReadEntry, Hn as PooledClient, Jr as WriteEntry, Kn as TxDatabase, Ln as CoreInitLockCtx, Rn as Database, Un as PreparedQueries, Vn as LazyCommitTsParam, mr as CommitLogEntry, qn as CacheLayer, zn as DbQueryResult } from "./index-Ca58CrWX.js";
|
|
2
|
+
import { Pool, PoolOptions } from "mysql2/promise";
|
|
3
|
+
import { Logger } from "pino";
|
|
4
|
+
|
|
5
|
+
//#region src/db/mysql.d.ts
|
|
6
|
+
/**
|
|
7
|
+
* mysql2's PoolOptions does not have a per-statement timeout field; we
|
|
8
|
+
* carry our own. Set 0 to disable.
|
|
9
|
+
*/
|
|
10
|
+
type MySqlPoolOptions = PoolOptions & {
|
|
11
|
+
queryTimeoutMs?: number;
|
|
12
|
+
};
|
|
13
|
+
declare class MySqlDatabase implements Database {
|
|
14
|
+
constructor(logger: Logger, config: MySqlPoolOptions, pool?: Pool | undefined);
|
|
15
|
+
private logger;
|
|
16
|
+
config: PoolOptions;
|
|
17
|
+
protected queryTimeoutMs: number;
|
|
18
|
+
private pool;
|
|
19
|
+
readonly dbType: DbType;
|
|
20
|
+
readonly sqlBuilder: SqlBuilder;
|
|
21
|
+
columnTypes: Map<string, Map<string, string>>;
|
|
22
|
+
protected sqlCache: Map<string, string>;
|
|
23
|
+
/**
|
|
24
|
+
* Fetches actual column types from MySQL for `table` and returns a
|
|
25
|
+
* map of DB column name → MySQL type string (as produced by `COLUMN_TYPE`,
|
|
26
|
+
* e.g. `bigint`, `integer`, `varchar(32)`, `text`, `json`).
|
|
27
|
+
* No caching here — see {@link getColumnTypes} for the cached path.
|
|
28
|
+
*/
|
|
29
|
+
loadColumnTypesFromMySql(table: string): Promise<Map<string, string>>;
|
|
30
|
+
/**
|
|
31
|
+
* Synchronous column-type lookup. The apply path calls this on every
|
|
32
|
+
* batched write, so it can't await — populate the cache via
|
|
33
|
+
* {@link bootstrapColumnTypes} at server start. Throws if `table` is
|
|
34
|
+
* missing (programmer error / bootstrap skipped).
|
|
35
|
+
*/
|
|
36
|
+
getColumnTypes(table: string): Map<string, string> | null;
|
|
37
|
+
/**
|
|
38
|
+
* Eagerly load column types into the in-memory cache. With a Redis
|
|
39
|
+
* client supplied, attempts the cache key first and falls through to
|
|
40
|
+
* MySQL on miss (writing the result back to Redis). This is the
|
|
41
|
+
* "one server queries MySQL, the rest read from Redis" pattern for cold
|
|
42
|
+
* starts in a multi-instance deploy. Without Redis, always queries MySQL.
|
|
43
|
+
*
|
|
44
|
+
* Pass `tables` to limit the load to a specific list; otherwise every
|
|
45
|
+
* user table in the connected database is loaded.
|
|
46
|
+
*
|
|
47
|
+
* The Redis cache key should encode whatever invalidates types in your
|
|
48
|
+
* environment (typically a schema version / deploy version). The
|
|
49
|
+
* subscriber in supalive-server.ts is expected to publish a reload
|
|
50
|
+
* signal after migrations and invoke {@link invalidateColumnTypes}.
|
|
51
|
+
*/
|
|
52
|
+
bootstrapColumnTypes(opts: {
|
|
53
|
+
redis?: CacheLayer;
|
|
54
|
+
cacheKey: string;
|
|
55
|
+
tables?: string[];
|
|
56
|
+
}): Promise<void>;
|
|
57
|
+
/**
|
|
58
|
+
* Invalidate cached types (and dependent SQL) for `table`, or the entire
|
|
59
|
+
* cache if `table` is omitted. The Redis-pubsub reload signal in
|
|
60
|
+
* supalive-server.ts is expected to call this on schema changes.
|
|
61
|
+
*/
|
|
62
|
+
invalidateColumnTypes(table?: string): void;
|
|
63
|
+
/** Replace this instance's caches with shared references from a parent.
|
|
64
|
+
* Used by getTransactionClient so types loaded once at startup are
|
|
65
|
+
* visible inside transactions. */
|
|
66
|
+
adoptCaches(columnTypes: Map<string, Map<string, string>>, sqlCache: Map<string, string>): void;
|
|
67
|
+
/** Enumerate the user-defined tables in the connected database for mysql — used
|
|
68
|
+
* by bootstrapColumnTypes() when no explicit list is provided. */
|
|
69
|
+
private listUserTables;
|
|
70
|
+
getCoreVersion(): Promise<bigint>;
|
|
71
|
+
coreMigrationStatements(toVersion: bigint): string[];
|
|
72
|
+
withCoreInitLock(fn: (ctx: CoreInitLockCtx) => Promise<void>): Promise<void>;
|
|
73
|
+
query<T = any>(sql: string, params?: unknown[]): Promise<DbQueryResult<T>>;
|
|
74
|
+
getClient(): Promise<PooledClient>;
|
|
75
|
+
getTransactionClient(): Promise<TxDatabase>;
|
|
76
|
+
getLatestSnapshotTimestamp(): Promise<bigint>;
|
|
77
|
+
updateLatestSnapshotTimestamp(commitTs: bigint): Promise<void>;
|
|
78
|
+
getMinSnapshotTimestamp(): Promise<bigint>;
|
|
79
|
+
updateMinSnapshotTimestamp(ts: bigint): Promise<void>;
|
|
80
|
+
getNextTimestamp(): Promise<bigint>;
|
|
81
|
+
attachPrevDataToWriteSet(writeSet: WriteEntry[], readSet: ReadEntry[]): Promise<void>;
|
|
82
|
+
prepareCommitWrites(readSet: ReadEntry[], writeSet: WriteEntry[], commitTs: LazyCommitTsParam): Promise<PreparedQueries>;
|
|
83
|
+
private mysqlPrepareBatchWrites;
|
|
84
|
+
private mysqlPrepareInsertBatch;
|
|
85
|
+
private mysqlPrepareUpdateSingle;
|
|
86
|
+
private mysqlPrepareDeleteBatch;
|
|
87
|
+
private mysqlPrepareCommitLogs;
|
|
88
|
+
/**
|
|
89
|
+
* Point-only OCC check. For each genuine point read, compare the row's
|
|
90
|
+
* current commit_ts against the value captured at read time. A `null`
|
|
91
|
+
* expectedCommitTs means "row didn't exist when we read"; any row found
|
|
92
|
+
* now is a conflict. Reads whose row is being written in this same txn
|
|
93
|
+
* are skipped — the CAS UPDATE/DELETE already validated those.
|
|
94
|
+
*/
|
|
95
|
+
private mysqlPrepareValidatePointReadsByCommitTs;
|
|
96
|
+
commitWrites(beginTs: bigint, queries: PreparedQueries, commitTs: bigint): Promise<{
|
|
97
|
+
success: boolean;
|
|
98
|
+
}>;
|
|
99
|
+
private mysqlApplyWrites;
|
|
100
|
+
private validatePointReadsByCommitTs;
|
|
101
|
+
pruneCommitLogsBefore(ts: bigint): Promise<bigint>;
|
|
102
|
+
getMinCommitLogTs(): Promise<bigint | null>;
|
|
103
|
+
getCommitLogsBetweenTs(beginTs: bigint, endTs: bigint, tableIds: Uint8Array[]): Promise<CommitLogEntry[]>;
|
|
104
|
+
getCommitLogsSinceTs(sinceTs: bigint, excludeTs: bigint, tableIds: Uint8Array[]): Promise<CommitLogEntry[]>;
|
|
105
|
+
close(): Promise<void>;
|
|
106
|
+
}
|
|
107
|
+
//#endregion
|
|
108
|
+
export { MySqlDatabase as t };
|
|
109
|
+
//# sourceMappingURL=mysql-fECZYP_m.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mysql-fECZYP_m.d.ts","names":[],"sources":["../src/db/mysql.ts"],"mappings":";;;;;;;;;KAwCY,gBAAA,GAAmB,WAAW;EAAK,cAAc;AAAA;AAAA,cAEhD,aAAA,YAAyB,QAAA;cAElC,MAAA,EAAQ,MAAA,EACR,MAAA,EAAQ,gBAAA,EACR,IAAA,GAAM,IAAA;EAAA,QAaA,MAAA;EACD,MAAA,EAAQ,WAAA;EAAA,UACL,cAAA;EAAA,QACF,IAAA;EAAA,SACC,MAAA,EAAQ,MAAA;EAAA,SACR,UAAA,EAAY,UAAA;EAMd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AgDF,YAAA,CACJ,OAAA,UACA,OAAA,EAAS,eAAA,EACT,QAAA,WACC,OAAA;IAAU,OAAA;EAAA;EAAA,QAqCC,gBAAA;EAAA,QAyDA,4BAAA;EAwCR,qBAAA,CAAsB,EAAA,WAAa,OAAA;EAQnC,iBAAA,IAAqB,OAAA;EAQrB,sBAAA,CAAuB,OAAA,UAAiB,KAAA,UAAe,QAAA,EAAU,UAAA,KAAe,OAAA,CAAQ,cAAA;EAmBxF,oBAAA,CAAqB,OAAA,UAAiB,SAAA,UAAmB,QAAA,EAAU,UAAA,KAAe,OAAA,CAAQ,cAAA;EAmB1F,KAAA,IAAS,OAAA;AAAA"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
//#region src/storage/object-storage.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Pluggable object storage for user-uploaded files (card artwork, receipts,
|
|
4
|
+
* customer photos, …). The server owns one instance and hands out short-lived,
|
|
5
|
+
* presigned URLs so clients upload their bytes DIRECTLY to the storage provider
|
|
6
|
+
* — the app server never proxies the file body.
|
|
7
|
+
*
|
|
8
|
+
* The durable reference persisted in the database is the object {@link key}
|
|
9
|
+
* (a stable path), never a presigned URL: URLs expire, keys do not. A viewable
|
|
10
|
+
* link is (re)derived from the key on read via {@link ObjectStorage.createDownloadUrl}
|
|
11
|
+
* or {@link ObjectStorage.publicUrl}.
|
|
12
|
+
*/
|
|
13
|
+
/** A presigned target a client PUTs raw bytes to, uploading straight to storage. */
|
|
14
|
+
interface PresignedUpload {
|
|
15
|
+
/** The object key the bytes will live at. */
|
|
16
|
+
key: string;
|
|
17
|
+
/** Short-lived URL the client uploads to. */
|
|
18
|
+
uploadUrl: string;
|
|
19
|
+
/** HTTP method to use for the upload (S3 presigned PUT). */
|
|
20
|
+
method: "PUT";
|
|
21
|
+
/**
|
|
22
|
+
* Headers the client MUST send with the upload for the signature to match
|
|
23
|
+
* (e.g. `Content-Type`). Send these verbatim and add nothing else that was
|
|
24
|
+
* signed.
|
|
25
|
+
*/
|
|
26
|
+
headers: Record<string, string>;
|
|
27
|
+
/** When {@link uploadUrl} stops being valid. */
|
|
28
|
+
expiresAt: Date;
|
|
29
|
+
}
|
|
30
|
+
/** Options for {@link ObjectStorage.createUploadUrl}. */
|
|
31
|
+
interface CreateUploadUrlOptions {
|
|
32
|
+
/** Full object key (path) to write to, e.g. `designs/store_x/abc.png`. */
|
|
33
|
+
key: string;
|
|
34
|
+
/** MIME type of the upload; signed into the URL when provided. */
|
|
35
|
+
contentType?: string;
|
|
36
|
+
/** Seconds the upload URL stays valid. Provider default applies when omitted. */
|
|
37
|
+
expiresIn?: number;
|
|
38
|
+
}
|
|
39
|
+
/** Options for {@link ObjectStorage.createDownloadUrl}. */
|
|
40
|
+
interface CreateDownloadUrlOptions {
|
|
41
|
+
/** Object key to read. */
|
|
42
|
+
key: string;
|
|
43
|
+
/** Seconds the download URL stays valid. Provider default applies when omitted. */
|
|
44
|
+
expiresIn?: number;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Storage backend abstraction. Implementations presign upload/download URLs for
|
|
48
|
+
* an S3-compatible provider (AWS S3, Cloudflare R2, MinIO, …).
|
|
49
|
+
*/
|
|
50
|
+
interface ObjectStorage {
|
|
51
|
+
/** Presign a direct-to-storage upload target for `key`. */
|
|
52
|
+
createUploadUrl(opts: CreateUploadUrlOptions): Promise<PresignedUpload>;
|
|
53
|
+
/**
|
|
54
|
+
* Presign a short-lived, read-only URL for a private object. Use this for the
|
|
55
|
+
* "secure link" a client shows after upload and on subsequent reads.
|
|
56
|
+
*/
|
|
57
|
+
createDownloadUrl(opts: CreateDownloadUrlOptions): Promise<string>;
|
|
58
|
+
/**
|
|
59
|
+
* A stable, public URL for `key` when the bucket is served publicly (e.g. an
|
|
60
|
+
* R2 public bucket or custom domain). Returns `null` when no public base is
|
|
61
|
+
* configured — callers should then fall back to {@link createDownloadUrl}.
|
|
62
|
+
*/
|
|
63
|
+
publicUrl(key: string): string | null;
|
|
64
|
+
}
|
|
65
|
+
//#endregion
|
|
66
|
+
export { PresignedUpload as i, CreateUploadUrlOptions as n, ObjectStorage as r, CreateDownloadUrlOptions as t };
|
|
67
|
+
//# sourceMappingURL=object-storage-4t7JvpuK.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"object-storage-4t7JvpuK.d.ts","names":[],"sources":["../src/storage/object-storage.ts"],"mappings":";;AAaA;;;;;;;;;;;UAAiB,eAAA;EAcA;EAZf,GAAA;EAgBqC;EAdrC,SAAA;EAcqC;EAZrC,MAAA;EAgBA;;;AAES;AAIX;EAhBE,OAAA,EAAS,MAAA;;EAET,SAAA,EAAW,IAAI;AAAA;AAyBjB;AAAA,UArBiB,sBAAA;;EAEf,GAAA;EAqBuD;EAnBvD,WAAA;EAyBwB;EAvBxB,SAAA;AAAA;;UAIe,wBAAA;EAaO;EAXtB,GAAA;EAW+C;EAT/C,SAAS;AAAA;;;;;UAOM,aAAA;EAeM;EAbrB,eAAA,CAAgB,IAAA,EAAM,sBAAA,GAAyB,OAAA,CAAQ,eAAA;;;;;EAMvD,iBAAA,CAAkB,IAAA,EAAM,wBAAA,GAA2B,OAAA;;;;;;EAOnD,SAAA,CAAU,GAAA;AAAA"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { An as DbType, Dn as CoreInitLockCtx, Fn as SqlBuilder, Fr as ReadEntry, In as TxDatabase, Ln as CacheLayer, Mn as PooledClient, Nn as PreparedQueries, On as Database, Rr as WriteEntry, ir as CommitLogEntry, jn as LazyCommitTsParam, kn as DbQueryResult } from "./index-
|
|
1
|
+
import { An as DbType, Dn as CoreInitLockCtx, Fn as SqlBuilder, Fr as ReadEntry, In as TxDatabase, Ln as CacheLayer, Mn as PooledClient, Nn as PreparedQueries, On as Database, Rr as WriteEntry, ir as CommitLogEntry, jn as LazyCommitTsParam, kn as DbQueryResult } from "./index-DJYvJYR4.js";
|
|
2
2
|
import { Pool, PoolConfig } from "pg";
|
|
3
3
|
import { Logger } from "pino";
|
|
4
4
|
|
|
@@ -110,4 +110,4 @@ declare class PgDatabase implements Database {
|
|
|
110
110
|
}
|
|
111
111
|
//#endregion
|
|
112
112
|
export { PgDatabase as t };
|
|
113
|
-
//# sourceMappingURL=postgres-
|
|
113
|
+
//# sourceMappingURL=postgres-7d6R9P7w.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"postgres-
|
|
1
|
+
{"version":3,"file":"postgres-7d6R9P7w.d.ts","names":[],"sources":["../src/db/postgres.ts"],"mappings":";;;;;cAiBa,UAAA,YAAsB,QAAA;cAE/B,MAAA,EAAQ,MAAA,EACR,MAAA,EAAQ,UAAA,EACR,IAAA,GAAM,IAAA;EAAA,QAWA,MAAA;EACD,MAAA,EAAQ,UAAA;EAAA,QACP,IAAA;EAAA,SACC,UAAA,EAAY,UAAA;EAAA,SACZ,MAAA,EAAQ,MAAA;EAMV,WAAA,EAAa,GAAA,SAAY,GAAA;EAAA,UAGtB,QAAA,EAAU,GAAA;EAHY;;;;;;EAW1B,qBAAA,CAAsB,KAAA,WAAgB,OAAA,CAAQ,GAAA;EAoDhD;;;;;;EA5BJ,cAAA,CAAe,KAAA,WAAgB,GAAA;EAyJ4B;;;;;;;;;;;;;;;EAjIrD,oBAAA,CAAqB,IAAA;IACzB,KAAA,GAAQ,UAAA;IACR,QAAA;IACA,MAAA;EAAA,IACE,OAAA;EAyRD;;;;;EAAA,QA/OK,qBAAA;EA23BsF;;EAAA,QA72BhF,cAAA;EAUR,cAAA,IAAkB,OAAA;EAWxB,uBAAA,CAAwB,SAAA;EAUlB,gBAAA,CAAiB,EAAA,GAAK,GAAA,EAAK,eAAA,KAAoB,OAAA,SAAgB,OAAA;EAsC/D,KAAA,UAAe,GAAA,UAAa,MAAA,eAAyB,OAAA,CAAQ,aAAA,CAAc,CAAA;EAe3E,SAAA,IAAa,OAAA,CAAQ,YAAA;EAIrB,oBAAA,IAAwB,OAAA,CAAQ,UAAA;EAxOL;;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ln as CoreInitLockCtx, Rn as Database, Un as PreparedQueries, Vn as LazyCommitTsParam, mr as CommitLogEntry, qn as CacheLayer, zn as DbQueryResult } from "./index-Ca58CrWX.js";
|
|
2
|
+
import { Pool, PoolConfig } from "pg";
|
|
3
|
+
import { Logger } from "pino";
|
|
4
|
+
|
|
5
|
+
//#region src/db/postgres.d.ts
|
|
6
|
+
declare class PgDatabase implements Database {
|
|
7
|
+
constructor(logger: Logger, config: PoolConfig, pool?: Pool | undefined);
|
|
8
|
+
private logger;
|
|
9
|
+
config: PoolConfig;
|
|
10
|
+
private pool;
|
|
11
|
+
readonly sqlBuilder: SqlBuilder;
|
|
12
|
+
readonly dbType: DbType;
|
|
13
|
+
columnTypes: Map<string, Map<string, string>>;
|
|
14
|
+
protected sqlCache: Map<string, string>;
|
|
15
|
+
/**
|
|
16
|
+
* Fetches actual column types from Postgres for `table` and returns a
|
|
17
|
+
* map of DB column name → PG type string (as produced by `format_type`,
|
|
18
|
+
* e.g. `bigint`, `integer`, `character varying(32)`, `text[]`, `jsonb`).
|
|
19
|
+
* No caching here — see {@link getColumnTypes} for the cached path.
|
|
20
|
+
*/
|
|
21
|
+
loadColumnTypesFromPg(table: string): Promise<Map<string, string>>;
|
|
22
|
+
/**
|
|
23
|
+
* Synchronous column-type lookup. The apply path calls this on every
|
|
24
|
+
* batched write, so it can't await — populate the cache via
|
|
25
|
+
* {@link bootstrapColumnTypes} at server start. Throws if `table` is
|
|
26
|
+
* missing (programmer error / bootstrap skipped).
|
|
27
|
+
*/
|
|
28
|
+
getColumnTypes(table: string): Map<string, string> | null;
|
|
29
|
+
/**
|
|
30
|
+
* Eagerly load column types into the in-memory cache. With a Redis
|
|
31
|
+
* client supplied, attempts the cache key first and falls through to
|
|
32
|
+
* Postgres on miss (writing the result back to Redis). This is the
|
|
33
|
+
* "one server queries PG, the rest read from Redis" pattern for cold
|
|
34
|
+
* starts in a multi-instance deploy. Without Redis, always queries PG.
|
|
35
|
+
*
|
|
36
|
+
* Pass `tables` to limit the load to a specific list; otherwise every
|
|
37
|
+
* user table in the connected database is loaded.
|
|
38
|
+
*
|
|
39
|
+
* The Redis cache key should encode whatever invalidates types in your
|
|
40
|
+
* environment (typically a schema version / deploy version). The
|
|
41
|
+
* subscriber in supalive-server.ts is expected to publish a reload
|
|
42
|
+
* signal after migrations and invoke {@link invalidateColumnTypes}.
|
|
43
|
+
*/
|
|
44
|
+
bootstrapColumnTypes(opts: {
|
|
45
|
+
redis?: CacheLayer;
|
|
46
|
+
cacheKey: string;
|
|
47
|
+
tables?: string[];
|
|
48
|
+
}): Promise<void>;
|
|
49
|
+
/**
|
|
50
|
+
* Invalidate cached types (and dependent SQL) for `table`, or the entire
|
|
51
|
+
* cache if `table` is omitted. The Redis-pubsub reload signal in
|
|
52
|
+
* supalive-server.ts is expected to call this on schema changes.
|
|
53
|
+
*/
|
|
54
|
+
private invalidateColumnTypes;
|
|
55
|
+
/** Enumerate the user-defined tables in the connected database — used
|
|
56
|
+
* by bootstrapColumnTypes() when no explicit list is provided. */
|
|
57
|
+
private listUserTables;
|
|
58
|
+
getCoreVersion(): Promise<bigint>;
|
|
59
|
+
coreMigrationStatements(toVersion: bigint): string[];
|
|
60
|
+
withCoreInitLock(fn: (ctx: CoreInitLockCtx) => Promise<void>): Promise<void>;
|
|
61
|
+
query<T = any>(sql: string, params?: unknown[]): Promise<DbQueryResult<T>>;
|
|
62
|
+
getClient(): Promise<PooledClient>;
|
|
63
|
+
getTransactionClient(): Promise<TxDatabase>;
|
|
64
|
+
/** Internal: replace this instance's caches with shared references from
|
|
65
|
+
* a parent. Used by PgDatabase.getTransactionClient. */
|
|
66
|
+
adoptCaches(columnTypes: Map<string, Map<string, string>>, sqlCache: Map<string, string>): void;
|
|
67
|
+
getLatestSnapshotTimestamp(): Promise<bigint>;
|
|
68
|
+
updateLatestSnapshotTimestamp(commitTs: bigint): Promise<void>;
|
|
69
|
+
getMinSnapshotTimestamp(): Promise<bigint>;
|
|
70
|
+
updateMinSnapshotTimestamp(ts: bigint): Promise<void>;
|
|
71
|
+
getNextTimestamp(): Promise<bigint>;
|
|
72
|
+
attachPrevDataToWriteSet(writeSet: WriteEntry[], readSet: ReadEntry[]): Promise<void>;
|
|
73
|
+
prepareCommitWrites(readSet: ReadEntry[], writeSet: WriteEntry[], commitTs: LazyCommitTsParam): Promise<PreparedQueries>;
|
|
74
|
+
private pgPrepareBatchWrites;
|
|
75
|
+
private pgPrepareInsertSingle;
|
|
76
|
+
private pgPrepareInsertBatch;
|
|
77
|
+
private pgPrepareUpdateSingle;
|
|
78
|
+
private pgPrepareUpdateBatch;
|
|
79
|
+
private pgPrepareDeleteSingle;
|
|
80
|
+
private pgPrepareDeleteBatch;
|
|
81
|
+
private buildOrGetInsertSql;
|
|
82
|
+
private buildOrGetUpdateSql;
|
|
83
|
+
private buildOrGetDeleteSql;
|
|
84
|
+
private pgPrepareCommitLogs;
|
|
85
|
+
/**
|
|
86
|
+
* Point-only OCC check. For each genuine point read, compare the row's
|
|
87
|
+
* current commit_ts against the value captured at read time. A `null`
|
|
88
|
+
* expectedCommitTs means "row didn't exist when we read"; any row found
|
|
89
|
+
* now is a conflict. Reads whose row is being written in this same txn
|
|
90
|
+
* are skipped — the CAS UPDATE/DELETE already validated those.
|
|
91
|
+
*/
|
|
92
|
+
private pgPrepareValidatePointReadsByCommitTs;
|
|
93
|
+
commitWrites(beginTs: bigint, queries: PreparedQueries, commitTs: bigint): Promise<{
|
|
94
|
+
success: boolean;
|
|
95
|
+
}>;
|
|
96
|
+
private pgApplyWrites;
|
|
97
|
+
/**
|
|
98
|
+
* Point-only OCC check. For each genuine point read, compare the row's
|
|
99
|
+
* current commit_ts against the value captured at read time. A `null`
|
|
100
|
+
* expectedCommitTs means "row didn't exist when we read"; any row found
|
|
101
|
+
* now is a conflict. Reads whose row is being written in this same txn
|
|
102
|
+
* are skipped — the CAS UPDATE/DELETE already validated those.
|
|
103
|
+
*/
|
|
104
|
+
private validatePointReadsByCommitTs;
|
|
105
|
+
pruneCommitLogsBefore(ts: bigint): Promise<bigint>;
|
|
106
|
+
getMinCommitLogTs(): Promise<bigint | null>;
|
|
107
|
+
getCommitLogsBetweenTs(beginTs: bigint, endTs: bigint, tableIds: Uint8Array[]): Promise<CommitLogEntry[]>;
|
|
108
|
+
getCommitLogsSinceTs(sinceTs: bigint, excludeTs: bigint, tableIds: Uint8Array[]): Promise<CommitLogEntry[]>;
|
|
109
|
+
close(): Promise<void>;
|
|
110
|
+
}
|
|
111
|
+
//#endregion
|
|
112
|
+
export { PgDatabase as t };
|
|
113
|
+
//# sourceMappingURL=postgres-C1qWlB--.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"postgres-C1qWlB--.d.ts","names":[],"sources":["../src/db/postgres.ts"],"mappings":";;;;;cAiBa,UAAA,YAAsB,QAAA;cAE/B,MAAA,EAAQ,MAAA,EACR,MAAA,EAAQ,UAAA,EACR,IAAA,GAAM,IAAA;EAAA,QAWA,MAAA;EACD,MAAA,EAAQ,UAAA;EAAA,QACP,IAAA;EAAA,SACC,UAAA,EAAY,UAAA;EAAA,SACZ,MAAA,EAAQ,MAAA;EAMV,WAAA,EAAa,GAAA,SAAY,GAAA;EAAA,UAGtB,QAAA,EAAU,GAAA;EAHY;;;;;;EAW1B,qBAAA,CAAsB,KAAA,WAAgB,OAAA,CAAQ,GAAA;EAoDhD;;;;;;EA5BJ,cAAA,CAAe,KAAA,WAAgB,GAAA;EAyJ4B;;;;;;;;;;;;;;;EAjIrD,oBAAA,CAAqB,IAAA;IACzB,KAAA,GAAQ,UAAA;IACR,QAAA;IACA,MAAA;EAAA,IACE,OAAA;EAyRD;;;;;EAAA,QA/OK,qBAAA;EA23BsF;;EAAA,QA72BhF,cAAA;EAUR,cAAA,IAAkB,OAAA;EAWxB,uBAAA,CAAwB,SAAA;EAUlB,gBAAA,CAAiB,EAAA,GAAK,GAAA,EAAK,eAAA,KAAoB,OAAA,SAAgB,OAAA;EAsC/D,KAAA,U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1F,KAAA,IAAS,OAAA;AAAA"}
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import { Bn as DbType, Gn as SqlBuilder, Gr as ReadEntry, Hn as PooledClient, Jr as WriteEntry, Kn as TxDatabase, Ln as CoreInitLockCtx, Rn as Database, Un as PreparedQueries, Vn as LazyCommitTsParam, mr as CommitLogEntry, qn as CacheLayer, zn as DbQueryResult } from "./index-DDK9ZIYb.js";
|
|
2
|
+
import { Pool, PoolConfig } from "pg";
|
|
3
|
+
import { Logger } from "pino";
|
|
4
|
+
|
|
5
|
+
//#region src/db/postgres.d.ts
|
|
6
|
+
declare class PgDatabase implements Database {
|
|
7
|
+
constructor(logger: Logger, config: PoolConfig, pool?: Pool | undefined);
|
|
8
|
+
private logger;
|
|
9
|
+
config: PoolConfig;
|
|
10
|
+
private pool;
|
|
11
|
+
readonly sqlBuilder: SqlBuilder;
|
|
12
|
+
readonly dbType: DbType;
|
|
13
|
+
columnTypes: Map<string, Map<string, string>>;
|
|
14
|
+
protected sqlCache: Map<string, string>;
|
|
15
|
+
/**
|
|
16
|
+
* Fetches actual column types from Postgres for `table` and returns a
|
|
17
|
+
* map of DB column name → PG type string (as produced by `format_type`,
|
|
18
|
+
* e.g. `bigint`, `integer`, `character varying(32)`, `text[]`, `jsonb`).
|
|
19
|
+
* No caching here — see {@link getColumnTypes} for the cached path.
|
|
20
|
+
*/
|
|
21
|
+
loadColumnTypesFromPg(table: string): Promise<Map<string, string>>;
|
|
22
|
+
/**
|
|
23
|
+
* Synchronous column-type lookup. The apply path calls this on every
|
|
24
|
+
* batched write, so it can't await — populate the cache via
|
|
25
|
+
* {@link bootstrapColumnTypes} at server start. Throws if `table` is
|
|
26
|
+
* missing (programmer error / bootstrap skipped).
|
|
27
|
+
*/
|
|
28
|
+
getColumnTypes(table: string): Map<string, string> | null;
|
|
29
|
+
/**
|
|
30
|
+
* Eagerly load column types into the in-memory cache. With a Redis
|
|
31
|
+
* client supplied, attempts the cache key first and falls through to
|
|
32
|
+
* Postgres on miss (writing the result back to Redis). This is the
|
|
33
|
+
* "one server queries PG, the rest read from Redis" pattern for cold
|
|
34
|
+
* starts in a multi-instance deploy. Without Redis, always queries PG.
|
|
35
|
+
*
|
|
36
|
+
* Pass `tables` to limit the load to a specific list; otherwise every
|
|
37
|
+
* user table in the connected database is loaded.
|
|
38
|
+
*
|
|
39
|
+
* The Redis cache key should encode whatever invalidates types in your
|
|
40
|
+
* environment (typically a schema version / deploy version). The
|
|
41
|
+
* subscriber in supalive-server.ts is expected to publish a reload
|
|
42
|
+
* signal after migrations and invoke {@link invalidateColumnTypes}.
|
|
43
|
+
*/
|
|
44
|
+
bootstrapColumnTypes(opts: {
|
|
45
|
+
redis?: CacheLayer;
|
|
46
|
+
cacheKey: string;
|
|
47
|
+
tables?: string[];
|
|
48
|
+
}): Promise<void>;
|
|
49
|
+
/**
|
|
50
|
+
* Invalidate cached types (and dependent SQL) for `table`, or the entire
|
|
51
|
+
* cache if `table` is omitted. The Redis-pubsub reload signal in
|
|
52
|
+
* supalive-server.ts is expected to call this on schema changes.
|
|
53
|
+
*/
|
|
54
|
+
private invalidateColumnTypes;
|
|
55
|
+
/** Enumerate the user-defined tables in the connected database — used
|
|
56
|
+
* by bootstrapColumnTypes() when no explicit list is provided. */
|
|
57
|
+
private listUserTables;
|
|
58
|
+
getCoreVersion(): Promise<bigint>;
|
|
59
|
+
coreMigrationStatements(toVersion: bigint): string[];
|
|
60
|
+
withCoreInitLock(fn: (ctx: CoreInitLockCtx) => Promise<void>): Promise<void>;
|
|
61
|
+
query<T = any>(sql: string, params?: unknown[]): Promise<DbQueryResult<T>>;
|
|
62
|
+
getClient(): Promise<PooledClient>;
|
|
63
|
+
getTransactionClient(): Promise<TxDatabase>;
|
|
64
|
+
/** Internal: replace this instance's caches with shared references from
|
|
65
|
+
* a parent. Used by PgDatabase.getTransactionClient. */
|
|
66
|
+
adoptCaches(columnTypes: Map<string, Map<string, string>>, sqlCache: Map<string, string>): void;
|
|
67
|
+
getLatestSnapshotTimestamp(): Promise<bigint>;
|
|
68
|
+
updateLatestSnapshotTimestamp(commitTs: bigint): Promise<void>;
|
|
69
|
+
getMinSnapshotTimestamp(): Promise<bigint>;
|
|
70
|
+
updateMinSnapshotTimestamp(ts: bigint): Promise<void>;
|
|
71
|
+
getNextTimestamp(): Promise<bigint>;
|
|
72
|
+
attachPrevDataToWriteSet(writeSet: WriteEntry[], readSet: ReadEntry[]): Promise<void>;
|
|
73
|
+
prepareCommitWrites(readSet: ReadEntry[], writeSet: WriteEntry[], commitTs: LazyCommitTsParam): Promise<PreparedQueries>;
|
|
74
|
+
private pgPrepareBatchWrites;
|
|
75
|
+
private pgPrepareInsertSingle;
|
|
76
|
+
private pgPrepareInsertBatch;
|
|
77
|
+
private pgPrepareUpdateSingle;
|
|
78
|
+
private pgPrepareUpdateBatch;
|
|
79
|
+
private pgPrepareDeleteSingle;
|
|
80
|
+
private pgPrepareDeleteBatch;
|
|
81
|
+
private buildOrGetInsertSql;
|
|
82
|
+
private buildOrGetUpdateSql;
|
|
83
|
+
private buildOrGetDeleteSql;
|
|
84
|
+
private pgPrepareCommitLogs;
|
|
85
|
+
/**
|
|
86
|
+
* Point-only OCC check. For each genuine point read, compare the row's
|
|
87
|
+
* current commit_ts against the value captured at read time. A `null`
|
|
88
|
+
* expectedCommitTs means "row didn't exist when we read"; any row found
|
|
89
|
+
* now is a conflict. Reads whose row is being written in this same txn
|
|
90
|
+
* are skipped — the CAS UPDATE/DELETE already validated those.
|
|
91
|
+
*/
|
|
92
|
+
private pgPrepareValidatePointReadsByCommitTs;
|
|
93
|
+
commitWrites(beginTs: bigint, queries: PreparedQueries, commitTs: bigint): Promise<{
|
|
94
|
+
success: boolean;
|
|
95
|
+
}>;
|
|
96
|
+
private pgApplyWrites;
|
|
97
|
+
/**
|
|
98
|
+
* Point-only OCC check. For each genuine point read, compare the row's
|
|
99
|
+
* current commit_ts against the value captured at read time. A `null`
|
|
100
|
+
* expectedCommitTs means "row didn't exist when we read"; any row found
|
|
101
|
+
* now is a conflict. Reads whose row is being written in this same txn
|
|
102
|
+
* are skipped — the CAS UPDATE/DELETE already validated those.
|
|
103
|
+
*/
|
|
104
|
+
private validatePointReadsByCommitTs;
|
|
105
|
+
pruneCommitLogsBefore(ts: bigint): Promise<bigint>;
|
|
106
|
+
getMinCommitLogTs(): Promise<bigint | null>;
|
|
107
|
+
getCommitLogsBetweenTs(beginTs: bigint, endTs: bigint, tableIds: Uint8Array[]): Promise<CommitLogEntry[]>;
|
|
108
|
+
getCommitLogsSinceTs(sinceTs: bigint, excludeTs: bigint, tableIds: Uint8Array[]): Promise<CommitLogEntry[]>;
|
|
109
|
+
close(): Promise<void>;
|
|
110
|
+
}
|
|
111
|
+
//#endregion
|
|
112
|
+
export { PgDatabase as t };
|
|
113
|
+
//# sourceMappingURL=postgres-CKtJ62S4.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"postgres-CKtJ62S4.d.ts","names":[],"sources":["../src/db/postgres.ts"],"mappings":";;;;;cAiBa,UAAA,YAAsB,QAAA;cAE/B,MAAA,EAAQ,MAAA,EACR,MAAA,EAAQ,UAAA,EACR,IAAA,GAAM,IAAA;EAAA,QAWA,MAAA;EACD,MAAA,EAAQ,UAAA;EAAA,QACP,IAAA;EAAA,SACC,UAAA,EAAY,UAAA;EAAA,SACZ,MAAA,EAAQ,MAAA;EAMV,WAAA,EAAa,GAAA,SAAY,GAAA;EAAA,UAGtB,QAAA,EAAU,GAAA;EAHY;;;;;;EAW1B,qBAAA,CAAsB,KAAA,WAAgB,OAAA,CAAQ,GAAA;EAoDhD;;;;;;EA5BJ,cAAA,CAAe,KAAA,WAAgB,GAAA;EAyJ4B;;;;;;;;;;;;;;;EAjIrD,oBAAA,CAAqB,IAAA;IACzB,KAAA,GAAQ,UAAA;IACR,QAAA;IACA,MAAA;EAAA,IACE,OAAA;EAyRD;;;;;EAAA,QA/OK,qBAAA;EA23BsF;;EAAA,QA72BhF,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KAAA,UAAe,QAAA,EAAU,UAAA,KAAe,OAAA,CAAQ,cAAA;EAmBxF,oBAAA,CAAqB,OAAA,UAAiB,SAAA,UAAmB,QAAA,EAAU,UAAA,KAAe,OAAA,CAAQ,cAAA;EAmB1F,KAAA,IAAS,OAAA;AAAA"}
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import { An as DbType, Dn as CoreInitLockCtx, Fn as SqlBuilder, Fr as ReadEntry, In as TxDatabase, Ln as CacheLayer, Mn as PooledClient, Nn as PreparedQueries, On as Database, Rr as WriteEntry, ir as CommitLogEntry, jn as LazyCommitTsParam, kn as DbQueryResult } from "./index-4Nis7Wnk.js";
|
|
2
|
+
import { Pool, PoolConfig } from "pg";
|
|
3
|
+
import { Logger } from "pino";
|
|
4
|
+
|
|
5
|
+
//#region src/db/postgres.d.ts
|
|
6
|
+
declare class PgDatabase implements Database {
|
|
7
|
+
constructor(logger: Logger, config: PoolConfig, pool?: Pool | undefined);
|
|
8
|
+
private logger;
|
|
9
|
+
config: PoolConfig;
|
|
10
|
+
private pool;
|
|
11
|
+
readonly sqlBuilder: SqlBuilder;
|
|
12
|
+
readonly dbType: DbType;
|
|
13
|
+
columnTypes: Map<string, Map<string, string>>;
|
|
14
|
+
protected sqlCache: Map<string, string>;
|
|
15
|
+
/**
|
|
16
|
+
* Fetches actual column types from Postgres for `table` and returns a
|
|
17
|
+
* map of DB column name → PG type string (as produced by `format_type`,
|
|
18
|
+
* e.g. `bigint`, `integer`, `character varying(32)`, `text[]`, `jsonb`).
|
|
19
|
+
* No caching here — see {@link getColumnTypes} for the cached path.
|
|
20
|
+
*/
|
|
21
|
+
loadColumnTypesFromPg(table: string): Promise<Map<string, string>>;
|
|
22
|
+
/**
|
|
23
|
+
* Synchronous column-type lookup. The apply path calls this on every
|
|
24
|
+
* batched write, so it can't await — populate the cache via
|
|
25
|
+
* {@link bootstrapColumnTypes} at server start. Throws if `table` is
|
|
26
|
+
* missing (programmer error / bootstrap skipped).
|
|
27
|
+
*/
|
|
28
|
+
getColumnTypes(table: string): Map<string, string> | null;
|
|
29
|
+
/**
|
|
30
|
+
* Eagerly load column types into the in-memory cache. With a Redis
|
|
31
|
+
* client supplied, attempts the cache key first and falls through to
|
|
32
|
+
* Postgres on miss (writing the result back to Redis). This is the
|
|
33
|
+
* "one server queries PG, the rest read from Redis" pattern for cold
|
|
34
|
+
* starts in a multi-instance deploy. Without Redis, always queries PG.
|
|
35
|
+
*
|
|
36
|
+
* Pass `tables` to limit the load to a specific list; otherwise every
|
|
37
|
+
* user table in the connected database is loaded.
|
|
38
|
+
*
|
|
39
|
+
* The Redis cache key should encode whatever invalidates types in your
|
|
40
|
+
* environment (typically a schema version / deploy version). The
|
|
41
|
+
* subscriber in supalive-server.ts is expected to publish a reload
|
|
42
|
+
* signal after migrations and invoke {@link invalidateColumnTypes}.
|
|
43
|
+
*/
|
|
44
|
+
bootstrapColumnTypes(opts: {
|
|
45
|
+
redis?: CacheLayer;
|
|
46
|
+
cacheKey: string;
|
|
47
|
+
tables?: string[];
|
|
48
|
+
}): Promise<void>;
|
|
49
|
+
/**
|
|
50
|
+
* Invalidate cached types (and dependent SQL) for `table`, or the entire
|
|
51
|
+
* cache if `table` is omitted. The Redis-pubsub reload signal in
|
|
52
|
+
* supalive-server.ts is expected to call this on schema changes.
|
|
53
|
+
*/
|
|
54
|
+
private invalidateColumnTypes;
|
|
55
|
+
/** Enumerate the user-defined tables in the connected database — used
|
|
56
|
+
* by bootstrapColumnTypes() when no explicit list is provided. */
|
|
57
|
+
private listUserTables;
|
|
58
|
+
getCoreVersion(): Promise<bigint>;
|
|
59
|
+
coreMigrationStatements(toVersion: bigint): string[];
|
|
60
|
+
withCoreInitLock(fn: (ctx: CoreInitLockCtx) => Promise<void>): Promise<void>;
|
|
61
|
+
query<T = any>(sql: string, params?: unknown[]): Promise<DbQueryResult<T>>;
|
|
62
|
+
getClient(): Promise<PooledClient>;
|
|
63
|
+
getTransactionClient(): Promise<TxDatabase>;
|
|
64
|
+
/** Internal: replace this instance's caches with shared references from
|
|
65
|
+
* a parent. Used by PgDatabase.getTransactionClient. */
|
|
66
|
+
adoptCaches(columnTypes: Map<string, Map<string, string>>, sqlCache: Map<string, string>): void;
|
|
67
|
+
getLatestSnapshotTimestamp(): Promise<bigint>;
|
|
68
|
+
updateLatestSnapshotTimestamp(commitTs: bigint): Promise<void>;
|
|
69
|
+
getMinSnapshotTimestamp(): Promise<bigint>;
|
|
70
|
+
updateMinSnapshotTimestamp(ts: bigint): Promise<void>;
|
|
71
|
+
getNextTimestamp(): Promise<bigint>;
|
|
72
|
+
attachPrevDataToWriteSet(writeSet: WriteEntry[], readSet: ReadEntry[]): Promise<void>;
|
|
73
|
+
prepareCommitWrites(readSet: ReadEntry[], writeSet: WriteEntry[], commitTs: LazyCommitTsParam): Promise<PreparedQueries>;
|
|
74
|
+
private pgPrepareBatchWrites;
|
|
75
|
+
private pgPrepareInsertSingle;
|
|
76
|
+
private pgPrepareInsertBatch;
|
|
77
|
+
private pgPrepareUpdateSingle;
|
|
78
|
+
private pgPrepareUpdateBatch;
|
|
79
|
+
private pgPrepareDeleteSingle;
|
|
80
|
+
private pgPrepareDeleteBatch;
|
|
81
|
+
private buildOrGetInsertSql;
|
|
82
|
+
private buildOrGetUpdateSql;
|
|
83
|
+
private buildOrGetDeleteSql;
|
|
84
|
+
private pgPrepareCommitLogs;
|
|
85
|
+
/**
|
|
86
|
+
* Point-only OCC check. For each genuine point read, compare the row's
|
|
87
|
+
* current commit_ts against the value captured at read time. A `null`
|
|
88
|
+
* expectedCommitTs means "row didn't exist when we read"; any row found
|
|
89
|
+
* now is a conflict. Reads whose row is being written in this same txn
|
|
90
|
+
* are skipped — the CAS UPDATE/DELETE already validated those.
|
|
91
|
+
*/
|
|
92
|
+
private pgPrepareValidatePointReadsByCommitTs;
|
|
93
|
+
commitWrites(beginTs: bigint, queries: PreparedQueries, commitTs: bigint): Promise<{
|
|
94
|
+
success: boolean;
|
|
95
|
+
}>;
|
|
96
|
+
private pgApplyWrites;
|
|
97
|
+
/**
|
|
98
|
+
* Point-only OCC check. For each genuine point read, compare the row's
|
|
99
|
+
* current commit_ts against the value captured at read time. A `null`
|
|
100
|
+
* expectedCommitTs means "row didn't exist when we read"; any row found
|
|
101
|
+
* now is a conflict. Reads whose row is being written in this same txn
|
|
102
|
+
* are skipped — the CAS UPDATE/DELETE already validated those.
|
|
103
|
+
*/
|
|
104
|
+
private validatePointReadsByCommitTs;
|
|
105
|
+
pruneCommitLogsBefore(ts: bigint): Promise<bigint>;
|
|
106
|
+
getMinCommitLogTs(): Promise<bigint | null>;
|
|
107
|
+
getCommitLogsBetweenTs(beginTs: bigint, endTs: bigint, tableIds: Uint8Array[]): Promise<CommitLogEntry[]>;
|
|
108
|
+
getCommitLogsSinceTs(sinceTs: bigint, excludeTs: bigint, tableIds: Uint8Array[]): Promise<CommitLogEntry[]>;
|
|
109
|
+
close(): Promise<void>;
|
|
110
|
+
}
|
|
111
|
+
//#endregion
|
|
112
|
+
export { PgDatabase as t };
|
|
113
|
+
//# sourceMappingURL=postgres-DdqpjjYF.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"postgres-DdqpjjYF.d.ts","names":[],"sources":["../src/db/postgres.ts"],"mappings":";;;;;cAiBa,UAAA,YAAsB,QAAA;cAE/B,MAAA,EAAQ,MAAA,EACR,MAAA,EAAQ,UAAA,EACR,IAAA,GAAM,IAAA;EAAA,QAWA,MAAA;EACD,MAAA,EAAQ,UAAA;EAAA,QACP,IAAA;EAAA,SACC,UAAA,EAAY,UAAA;EAAA,SACZ,MAAA,EAAQ,MAAA;EAMV,WAAA,EAAa,GAAA,SAAY,GAAA;EAAA,UAGtB,QAAA,EAAU,GAAA;EAHY;;;;;;EAW1B,qBAAA,CAAsB,KAAA,WAAgB,OAAA,CAAQ,GAAA;EAoDhD;;;;;;EA5BJ,cAAA,CAAe,KAAA,WAAgB,GAAA;EAyJ4B;;;;;;;;;;;;;;;EA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