@supalive/core 1.8.1 → 1.10.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.
Files changed (106) hide show
  1. package/README.md +1 -2
  2. package/dist/index-BQRlJY_1.d.ts +2192 -0
  3. package/dist/index-BQRlJY_1.d.ts.map +1 -0
  4. package/dist/index-CDG1kbFO.d.ts +2211 -0
  5. package/dist/index-CDG1kbFO.d.ts.map +1 -0
  6. package/dist/index-CkYZi3ai.d.ts +2186 -0
  7. package/dist/index-CkYZi3ai.d.ts.map +1 -0
  8. package/dist/index-D8O39FoZ.d.ts +2192 -0
  9. package/dist/index-D8O39FoZ.d.ts.map +1 -0
  10. package/dist/index-DKlWIC3k.d.ts +2200 -0
  11. package/dist/index-DKlWIC3k.d.ts.map +1 -0
  12. package/dist/index-Dy9UlONo.d.ts +2192 -0
  13. package/dist/index-Dy9UlONo.d.ts.map +1 -0
  14. package/dist/index-WMhtVzJA.d.ts +2192 -0
  15. package/dist/index-WMhtVzJA.d.ts.map +1 -0
  16. package/dist/index-tDcHLwJu.d.ts +2186 -0
  17. package/dist/index-tDcHLwJu.d.ts.map +1 -0
  18. package/dist/mysql-BBNCFz8q.d.ts +109 -0
  19. package/dist/mysql-BBNCFz8q.d.ts.map +1 -0
  20. package/dist/mysql-BVz7201u.d.ts +109 -0
  21. package/dist/mysql-BVz7201u.d.ts.map +1 -0
  22. package/dist/mysql-CBSuONm5.d.ts +109 -0
  23. package/dist/mysql-CBSuONm5.d.ts.map +1 -0
  24. package/dist/mysql-CBlZ6FVc.d.ts +109 -0
  25. package/dist/mysql-CBlZ6FVc.d.ts.map +1 -0
  26. package/dist/mysql-CDenA4XE.d.ts +109 -0
  27. package/dist/mysql-CDenA4XE.d.ts.map +1 -0
  28. package/dist/mysql-CfYZLs5V.d.ts +109 -0
  29. package/dist/mysql-CfYZLs5V.d.ts.map +1 -0
  30. package/dist/mysql-DAfFK5v1.d.ts +109 -0
  31. package/dist/mysql-DAfFK5v1.d.ts.map +1 -0
  32. package/dist/mysql-DjjyCiO4.d.ts +109 -0
  33. package/dist/mysql-DjjyCiO4.d.ts.map +1 -0
  34. package/dist/postgres-BKGLPrKt.d.ts +113 -0
  35. package/dist/postgres-BKGLPrKt.d.ts.map +1 -0
  36. package/dist/postgres-CKBWXyY8.d.ts +113 -0
  37. package/dist/postgres-CKBWXyY8.d.ts.map +1 -0
  38. package/dist/postgres-CUHirAJN.d.ts +113 -0
  39. package/dist/postgres-CUHirAJN.d.ts.map +1 -0
  40. package/dist/postgres-Cj9zuZ8p.d.ts +113 -0
  41. package/dist/postgres-Cj9zuZ8p.d.ts.map +1 -0
  42. package/dist/postgres-DGK6Y1aL.d.ts +113 -0
  43. package/dist/postgres-DGK6Y1aL.d.ts.map +1 -0
  44. package/dist/postgres-DQxKs5Nu.d.ts +113 -0
  45. package/dist/postgres-DQxKs5Nu.d.ts.map +1 -0
  46. package/dist/postgres-hlrVkOXa.d.ts +113 -0
  47. package/dist/postgres-hlrVkOXa.d.ts.map +1 -0
  48. package/dist/postgres-ziXP2hco.d.ts +113 -0
  49. package/dist/postgres-ziXP2hco.d.ts.map +1 -0
  50. package/dist/procedure-B4qKrlBL.js +158 -0
  51. package/dist/procedure-B4qKrlBL.js.map +1 -0
  52. package/dist/procedure-BDcrK98I.js +173 -0
  53. package/dist/procedure-BDcrK98I.js.map +1 -0
  54. package/dist/procedure-BxGOWNWg.js.map +1 -0
  55. package/dist/procedure-CRkrxHvn.js +187 -0
  56. package/dist/procedure-CRkrxHvn.js.map +1 -0
  57. package/dist/procedure-Ck4v3__H.js +212 -0
  58. package/dist/procedure-Ck4v3__H.js.map +1 -0
  59. package/dist/procedure-DPgXC2Cm.js +221 -0
  60. package/dist/procedure-DPgXC2Cm.js.map +1 -0
  61. package/dist/procedure-xUVIUm5W.js +213 -0
  62. package/dist/procedure-xUVIUm5W.js.map +1 -0
  63. package/dist/src/client/index.d.ts +1 -1
  64. package/dist/src/client/index.js +1 -1
  65. package/dist/src/exports/mysql.d.ts +1 -1
  66. package/dist/src/exports/postgres.d.ts +1 -1
  67. package/dist/src/exports/procedure.d.ts +17 -2
  68. package/dist/src/exports/procedure.d.ts.map +1 -0
  69. package/dist/src/exports/procedure.js +8 -2
  70. package/dist/src/exports/procedure.js.map +1 -0
  71. package/dist/src/exports/schema-sql.d.ts +1 -1
  72. package/dist/src/exports/server.d.ts +24 -124
  73. package/dist/src/exports/server.d.ts.map +1 -1
  74. package/dist/src/exports/server.js +128 -30
  75. package/dist/src/exports/server.js.map +1 -1
  76. package/dist/src/exports/sub-manager-worker-entry.d.ts +1 -0
  77. package/dist/src/exports/sub-manager-worker-entry.js +71 -0
  78. package/dist/src/exports/sub-manager-worker-entry.js.map +1 -0
  79. package/dist/src/exports/subscription-manager-worker-entry.js +3 -49
  80. package/dist/src/exports/subscription-manager-worker-entry.js.map +1 -1
  81. package/dist/src/exports/types.d.ts +2 -2
  82. package/dist/sub-worker-dispatch-G8V8asfR.js +810 -0
  83. package/dist/sub-worker-dispatch-G8V8asfR.js.map +1 -0
  84. package/dist/subscription-worker-dispatch-CSQV-PO3.js +810 -0
  85. package/dist/subscription-worker-dispatch-CSQV-PO3.js.map +1 -0
  86. package/dist/types_server-AQ8Jl2_R.d.ts +521 -0
  87. package/dist/types_server-AQ8Jl2_R.d.ts.map +1 -0
  88. package/dist/types_server-BB2WvXEA.d.ts +521 -0
  89. package/dist/types_server-BB2WvXEA.d.ts.map +1 -0
  90. package/dist/types_server-BI7uQd6x.d.ts +328 -0
  91. package/dist/types_server-BI7uQd6x.d.ts.map +1 -0
  92. package/dist/types_server-BcT4A8OM.d.ts +328 -0
  93. package/dist/types_server-BcT4A8OM.d.ts.map +1 -0
  94. package/dist/types_server-CO3IYNS9.d.ts +328 -0
  95. package/dist/types_server-CO3IYNS9.d.ts.map +1 -0
  96. package/dist/types_server-Clf74qZP.d.ts +328 -0
  97. package/dist/types_server-Clf74qZP.d.ts.map +1 -0
  98. package/dist/types_server-DEAwXI4p.d.ts +328 -0
  99. package/dist/types_server-DEAwXI4p.d.ts.map +1 -0
  100. package/dist/types_server-DU9JMSXd.d.ts +521 -0
  101. package/dist/types_server-DU9JMSXd.d.ts.map +1 -0
  102. package/dist/zod_ext-B5cyjWqZ.d.ts +11 -0
  103. package/dist/zod_ext-B5cyjWqZ.d.ts.map +1 -0
  104. package/dist/zod_ext-CZlJ4wtJ.d.ts +11 -0
  105. package/dist/zod_ext-CZlJ4wtJ.d.ts.map +1 -0
  106. package/package.json +6 -5
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mysql-CDenA4XE.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,WAAA,EAAa,GAAA,SAAY,GAAA;EAAA,UAGtB,QAAA,EAAU,GAAA;EAwII;;;;;;EAhIlB,wBAAA,CAAyB,KAAA,WAAgB,OAAA,CAAQ,GAAA;EA0M5B;;;;;;EAlL3B,cAAA,CAAe,KAAA,WAAgB,GAAA;EA+Me;;;;;;;;;;;;;;;EAvLxC,oBAAA,CAAqB,IAAA;IACzB,KAAA,GAAQ,UAAA;IACR,QAAA;IACA,MAAA;EAAA,IACE,OAAA;EAgsBW;;;;;EAtpBf,qBAAA,CAAsB,KAAA;EAnIZ;;;EAkJV,WAAA,CACE,WAAA,EAAa,GAAA,SAAY,GAAA,mBACzB,QAAA,EAAU,GAAA;EAlJJ;;EAAA,QA0JM,cAAA;EASR,cAAA,IAAkB,OAAA;EAYxB,uBAAA,CAAwB,SAAA;EAWlB,gB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acheLayer, Un as Database, Wn as DbQueryResult, Xn as SqlBuilder, Xr as ReadEntry, Zn as TxDatabase, qn as PooledClient, yr as CommitLogEntry } from "./index-CDG1kbFO.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-CfYZLs5V.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mysql-CfYZLs5V.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,WAAA,EAAa,GAAA,SAAY,GAAA;EAAA,UAGtB,QAAA,EAAU,GAAA;EAwII;;;;;;EAhIlB,wBAAA,CAAyB,KAAA,WAAgB,OAAA,CAAQ,GAA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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,109 @@
1
+ import { $r as WriteEntry, Gn as DbType, Hn as CoreInitLockCtx, Jn as PreparedQueries, Kn as LazyCommitTsParam, Qn as CacheLayer, Un as Database, Wn as DbQueryResult, Xn as SqlBuilder, Xr as ReadEntry, Zn as TxDatabase, qn as PooledClient, yr as CommitLogEntry } from "./index-WMhtVzJA.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-DAfFK5v1.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mysql-DAfFK5v1.d.ts","names":[],"sources":["../src/db/mysql.ts"],"mappings":";;;;;;;;;KAwCY,gBAAA,GAAmB,WAAW;E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,KAAc,OAAA;EA6DxE,mBAAA,CACJ,OAAA,EAAS,SAAA,IACT,QAAA,EAAU,UAAA,IACV,QAAA,EAAU,iBAAA,GACT,OAAA,CAAQ,eAAA;EAAA,QAmBG,uBAAA;EAAA,QAyBA,uBAAA;EAAA,QA2CA,wBAAA;EAAA,QAiCA,uBAAA;EAAA,QA4BA,sBAAA;EAlcC;;;;;;;EAAA,QA4eP,wCAAA;EAgDF,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,109 @@
1
+ import { Bn as CoreInitLockCtx, Gn as PooledClient, Hn as DbQueryResult, Jn as SqlBuilder, Jr as ReadEntry, Kn as PreparedQueries, Un as DbType, Vn as Database, Wn as LazyCommitTsParam, Xn as CacheLayer, Yn as TxDatabase, Zr as WriteEntry, _r as CommitLogEntry } from "./index-tDcHLwJu.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-DjjyCiO4.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mysql-DjjyCiO4.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,WAAA,EAAa,GAAA,SAAY,GAAA;EAAA,UAGtB,QAAA,EAAU,GAAA;EAwII;;;;;;EAhIlB,wBAAA,CAAyB,KAAA,WAAgB,OAAA,CAAQ,GAAA;EA0M5B;;;;;;EAlL3B,cAAA,CAAe,KAAA,WAAgB,GAAA;EA+Me;;;;;;;;;;;;;;;EAvLxC,oBAAA,CAAqB,IAAA;IACzB,KAAA,GAAQ,UAAA;IACR,QAAA;IACA,MAAA;EAAA,IACE,OAAA;EAgsBW;;;;;EAtpBf,qBAAA,CAAsB,KAAA;EAnIZ;;;EAkJV,WAAA,CACE,WAAA,EAAa,GAAA,SAAY,GAAA,mBACzB,QAAA,EAAU,GAAA;EAlJJ;;EAAA,QA0JM,cAAA;EASR,cAAA,IAAkB,OAAA;EAYxB,uBAAA,CAAwB,SAAA;EAWlB,gBAAA,CAAiB,EAAA,GAAK,GAAA,EAAK,eAAA,KAAoB,OAAA,SAAg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as TxDatabase, qn as PooledClient, yr as CommitLogEntry } from "./index-BQRlJY_1.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-BKGLPrKt.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"postgres-BKGLPrKt.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,KAA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AA,WACC,OAAA;IAAU,OAAA;EAAA;EAAA,QAqCC,aAAA;EApwBa;;;;;;;EAAA,QA+2Bb,4BAAA;EA0CR,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,113 @@
1
+ import { $r as WriteEntry, Gn as DbType, Hn as CoreInitLockCtx, Jn as PreparedQueries, Kn as LazyCommitTsParam, Qn as CacheLayer, Un as Database, Wn as DbQueryResult, Xn as SqlBuilder, Xr as ReadEntry, Zn as TxDatabase, qn as PooledClient, yr as CommitLogEntry } from "./index-D8O39FoZ.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 {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