@hoshinotatsuya/pg-replica-sync 0.2.2 → 0.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/CHANGELOG.md +8 -0
- package/README.md +1 -1
- package/dist/compare-lsn.d.mts +3 -3
- package/dist/compare-lsn.d.ts +3 -3
- package/dist/compare-lsn.js +3 -3
- package/dist/constants/exclusion-reason.constant.d.mts +12 -12
- package/dist/constants/exclusion-reason.constant.d.ts +12 -12
- package/dist/constants/exclusion-reason.constant.d.ts.map +1 -1
- package/dist/constants/exclusion-reason.constant.js +12 -12
- package/dist/constants/exclusion-reason.constant.js.map +1 -1
- package/dist/constants/node-role.constant.d.mts +1 -1
- package/dist/constants/node-role.constant.d.ts +1 -1
- package/dist/constants/node-role.constant.d.ts.map +1 -1
- package/dist/constants/node-role.constant.js +1 -1
- package/dist/constants/node-role.constant.js.map +1 -1
- package/dist/constants/probe-sql.constant.d.mts +25 -25
- package/dist/constants/probe-sql.constant.d.ts +25 -25
- package/dist/constants/probe-sql.constant.js +25 -25
- package/dist/constants/replica-sync-defaults.constant.d.mts +26 -26
- package/dist/constants/replica-sync-defaults.constant.d.ts +26 -26
- package/dist/constants/replica-sync-defaults.constant.d.ts.map +1 -1
- package/dist/constants/replica-sync-defaults.constant.js +26 -26
- package/dist/constants/replica-sync-defaults.constant.js.map +1 -1
- package/dist/constants/route-reason.constant.d.mts +13 -13
- package/dist/constants/route-reason.constant.d.ts +13 -13
- package/dist/constants/route-reason.constant.d.ts.map +1 -1
- package/dist/constants/route-reason.constant.js +13 -13
- package/dist/constants/route-reason.constant.js.map +1 -1
- package/dist/constants/token-format.constant.d.mts +11 -11
- package/dist/constants/token-format.constant.d.ts +11 -11
- package/dist/constants/token-format.constant.d.ts.map +1 -1
- package/dist/constants/token-format.constant.js +11 -11
- package/dist/constants/token-format.constant.js.map +1 -1
- package/dist/constants/wal-format.constant.d.mts +6 -6
- package/dist/constants/wal-format.constant.d.ts +6 -6
- package/dist/constants/wal-format.constant.d.ts.map +1 -1
- package/dist/constants/wal-format.constant.js +6 -6
- package/dist/constants/wal-format.constant.js.map +1 -1
- package/dist/decode-canonical-base64url.d.mts +1 -1
- package/dist/decode-canonical-base64url.d.ts +1 -1
- package/dist/decode-canonical-base64url.d.ts.map +1 -1
- package/dist/decode-canonical-base64url.js +1 -1
- package/dist/decode-canonical-base64url.js.map +1 -1
- package/dist/deep-freeze.d.mts +7 -7
- package/dist/deep-freeze.d.ts +7 -7
- package/dist/deep-freeze.js +9 -9
- package/dist/deep-freeze.js.map +1 -1
- package/dist/destroy-client.d.mts +3 -3
- package/dist/destroy-client.d.ts +3 -3
- package/dist/destroy-client.js +3 -3
- package/dist/evaluate-replica.d.mts +3 -3
- package/dist/evaluate-replica.d.ts +3 -3
- package/dist/evaluate-replica.js +3 -3
- package/dist/format-lsn.d.mts +1 -1
- package/dist/format-lsn.d.ts +1 -1
- package/dist/format-lsn.d.ts.map +1 -1
- package/dist/format-lsn.js +2 -2
- package/dist/format-lsn.js.map +1 -1
- package/dist/invalid-lsn.error.d.mts +1 -1
- package/dist/invalid-lsn.error.d.ts +1 -1
- package/dist/invalid-lsn.error.d.ts.map +1 -1
- package/dist/invalid-lsn.error.js +2 -2
- package/dist/invalid-lsn.error.js.map +1 -1
- package/dist/invalid-replica-sync-options.error.d.mts +1 -1
- package/dist/invalid-replica-sync-options.error.d.ts +1 -1
- package/dist/invalid-replica-sync-options.error.d.ts.map +1 -1
- package/dist/invalid-replica-sync-options.error.js +1 -1
- package/dist/invalid-replica-sync-options.error.js.map +1 -1
- package/dist/lag-bytes.d.mts +3 -3
- package/dist/lag-bytes.d.ts +3 -3
- package/dist/lag-bytes.js +3 -3
- package/dist/lsn-or-null.d.mts +1 -1
- package/dist/lsn-or-null.d.ts +1 -1
- package/dist/lsn-or-null.d.ts.map +1 -1
- package/dist/lsn-or-null.js +1 -1
- package/dist/lsn-or-null.js.map +1 -1
- package/dist/notify.d.mts +7 -7
- package/dist/notify.d.ts +7 -7
- package/dist/notify.js +8 -8
- package/dist/notify.js.map +1 -1
- package/dist/parse-lsn.d.mts +3 -3
- package/dist/parse-lsn.d.ts +3 -3
- package/dist/parse-lsn.js +3 -3
- package/dist/probe-connection-closed.error.d.mts +1 -1
- package/dist/probe-connection-closed.error.d.ts +1 -1
- package/dist/probe-connection-closed.error.d.ts.map +1 -1
- package/dist/probe-connection-closed.error.js +2 -2
- package/dist/probe-connection-closed.error.js.map +1 -1
- package/dist/probe-connection.d.mts +20 -20
- package/dist/probe-connection.d.ts +20 -20
- package/dist/probe-connection.d.ts.map +1 -1
- package/dist/probe-connection.js +25 -25
- package/dist/probe-connection.js.map +1 -1
- package/dist/probe-timeout.error.d.mts +1 -1
- package/dist/probe-timeout.error.d.ts +1 -1
- package/dist/probe-timeout.error.d.ts.map +1 -1
- package/dist/probe-timeout.error.js +2 -2
- package/dist/probe-timeout.error.js.map +1 -1
- package/dist/read-node-state.d.mts +3 -3
- package/dist/read-node-state.d.ts +3 -3
- package/dist/read-node-state.js +4 -4
- package/dist/read-node-state.js.map +1 -1
- package/dist/replica-router.d.mts +133 -133
- package/dist/replica-router.d.ts +133 -133
- package/dist/replica-router.d.ts.map +1 -1
- package/dist/replica-router.js +162 -162
- package/dist/replica-router.js.map +1 -1
- package/dist/require-integer.d.mts +1 -1
- package/dist/require-integer.d.ts +1 -1
- package/dist/require-integer.d.ts.map +1 -1
- package/dist/require-integer.js +3 -3
- package/dist/require-integer.js.map +1 -1
- package/dist/secret-weakness.d.mts +13 -13
- package/dist/secret-weakness.d.ts +13 -13
- package/dist/secret-weakness.js +16 -16
- package/dist/secret-weakness.js.map +1 -1
- package/dist/smallest-period.d.mts +4 -4
- package/dist/smallest-period.d.ts +4 -4
- package/dist/smallest-period.js +4 -4
- package/dist/sql-state-of.d.mts +6 -6
- package/dist/sql-state-of.d.ts +6 -6
- package/dist/sql-state-of.js +6 -6
- package/dist/state-cache.d.mts +14 -14
- package/dist/state-cache.d.ts +14 -14
- package/dist/state-cache.d.ts.map +1 -1
- package/dist/state-cache.js +15 -15
- package/dist/state-cache.js.map +1 -1
- package/dist/timeline-of.d.mts +2 -2
- package/dist/timeline-of.d.ts +2 -2
- package/dist/timeline-of.js +2 -2
- package/dist/to-error.d.mts +1 -1
- package/dist/to-error.d.ts +1 -1
- package/dist/to-error.d.ts.map +1 -1
- package/dist/to-error.js +1 -1
- package/dist/to-error.js.map +1 -1
- package/dist/token-codec.d.mts +10 -10
- package/dist/token-codec.d.ts +10 -10
- package/dist/token-codec.js +31 -31
- package/dist/token-codec.js.map +1 -1
- package/dist/token-lsn.d.mts +13 -13
- package/dist/token-lsn.d.ts +13 -13
- package/dist/token-lsn.js +13 -13
- package/dist/transaction-not-committed.error.d.mts +2 -2
- package/dist/transaction-not-committed.error.d.ts +2 -2
- package/dist/transaction-not-committed.error.d.ts.map +1 -1
- package/dist/transaction-not-committed.error.js +3 -3
- package/dist/transaction-not-committed.error.js.map +1 -1
- package/dist/transaction-not-open.error.d.mts +5 -5
- package/dist/transaction-not-open.error.d.ts +5 -5
- package/dist/transaction-not-open.error.js +6 -6
- package/dist/transaction-not-open.error.js.map +1 -1
- package/dist/types/cache-entry.type.d.mts +4 -4
- package/dist/types/cache-entry.type.d.ts +4 -4
- package/dist/types/clock.type.d.mts +3 -3
- package/dist/types/clock.type.d.ts +3 -3
- package/dist/types/confirm-event.type.d.mts +3 -3
- package/dist/types/confirm-event.type.d.ts +3 -3
- package/dist/types/decoded-token.type.d.mts +2 -2
- package/dist/types/decoded-token.type.d.ts +2 -2
- package/dist/types/evaluated.type.d.mts +1 -1
- package/dist/types/evaluated.type.d.ts +1 -1
- package/dist/types/evaluated.type.d.ts.map +1 -1
- package/dist/types/exclusion.type.d.mts +1 -1
- package/dist/types/exclusion.type.d.ts +1 -1
- package/dist/types/exclusion.type.d.ts.map +1 -1
- package/dist/types/node-state.type.d.mts +13 -13
- package/dist/types/node-state.type.d.ts +13 -13
- package/dist/types/node-state.type.d.ts.map +1 -1
- package/dist/types/not-a-pool.type.d.mts +5 -5
- package/dist/types/not-a-pool.type.d.ts +5 -5
- package/dist/types/probe-event.type.d.mts +1 -1
- package/dist/types/probe-event.type.d.ts +1 -1
- package/dist/types/probe-event.type.d.ts.map +1 -1
- package/dist/types/probe-outcome.type.d.mts +1 -1
- package/dist/types/probe-outcome.type.d.ts +1 -1
- package/dist/types/probe-outcome.type.d.ts.map +1 -1
- package/dist/types/probe-sample.type.d.mts +1 -1
- package/dist/types/probe-sample.type.d.ts +1 -1
- package/dist/types/probe-sample.type.d.ts.map +1 -1
- package/dist/types/replica-node.type.d.mts +7 -7
- package/dist/types/replica-node.type.d.ts +7 -7
- package/dist/types/replica-requirement.type.d.mts +2 -2
- package/dist/types/replica-requirement.type.d.ts +2 -2
- package/dist/types/replica-router-options.type.d.mts +25 -25
- package/dist/types/replica-router-options.type.d.ts +25 -25
- package/dist/types/replica-router-options.type.d.ts.map +1 -1
- package/dist/types/route-decision.type.d.mts +5 -5
- package/dist/types/route-decision.type.d.ts +5 -5
- package/dist/types/route-decision.type.d.ts.map +1 -1
- package/dist/types/router-observer.type.d.mts +5 -5
- package/dist/types/router-observer.type.d.ts +5 -5
- package/dist/types/router-observer.type.d.ts.map +1 -1
- package/dist/types/router-stats.type.d.mts +8 -8
- package/dist/types/router-stats.type.d.ts +8 -8
- package/dist/types/router-stats.type.d.ts.map +1 -1
- package/dist/types/sql-command-executor.type.d.mts +4 -4
- package/dist/types/sql-command-executor.type.d.ts +4 -4
- package/dist/types/sql-query-executor.type.d.mts +3 -3
- package/dist/types/sql-query-executor.type.d.ts +3 -3
- package/dist/types/wal-layout.type.d.mts +1 -1
- package/dist/types/wal-layout.type.d.ts +1 -1
- package/dist/types/wal-layout.type.d.ts.map +1 -1
- package/dist/types/wal-position.type.d.mts +5 -5
- package/dist/types/wal-position.type.d.ts +5 -5
- package/dist/types/wal-position.type.d.ts.map +1 -1
- package/dist/value-text.d.mts +5 -5
- package/dist/value-text.d.ts +5 -5
- package/dist/value-text.js +6 -6
- package/dist/value-text.js.map +1 -1
- package/dist/wal-layout-of.d.mts +1 -1
- package/dist/wal-layout-of.d.ts +1 -1
- package/dist/wal-layout-of.d.ts.map +1 -1
- package/dist/wal-layout-of.js +1 -1
- package/dist/wal-layout-of.js.map +1 -1
- package/package.json +11 -9
package/dist/state-cache.js
CHANGED
|
@@ -2,19 +2,19 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.StateCache = void 0;
|
|
4
4
|
/**
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
* `delete
|
|
11
|
-
*
|
|
5
|
+
* A cache of node states with a lifetime ceiling. The ceiling is checked not only on
|
|
6
|
+
* read: expired entries are EVICTED on every access, and the keys are only
|
|
7
|
+
* the nodes from the configuration, so the cache grows neither with time nor with input.
|
|
8
|
+
* A probe refusal lives its own time (`failureTtlMs`): an unavailable node is not polled
|
|
9
|
+
* on every read, and a frozen node does not delay every query by the probe ceiling.
|
|
10
|
+
* `delete`: the probe connection of the node is lost (a server restart): the state taken through
|
|
11
|
+
* it proves nothing anymore and does not live until the ceiling.
|
|
12
12
|
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
13
|
+
* The cache clock comes from outside (the `clock` option) and can step back (NTP, the clock of
|
|
14
|
+
* the stand) or return a non-number. The ceiling of an entry is counted by the previous clock, and after
|
|
15
|
+
* a step back by an hour it would live an extra hour — a pause or a promotion of the node would
|
|
16
|
+
* go unnoticed. So a step back and a non-number evict ALL entries, and an entry is not stored on
|
|
17
|
+
* a non-number: there is no cache until the clock returns a finite value.
|
|
18
18
|
*/
|
|
19
19
|
class StateCache {
|
|
20
20
|
nodes;
|
|
@@ -35,7 +35,7 @@ class StateCache {
|
|
|
35
35
|
}
|
|
36
36
|
set(node, outcome, probe) {
|
|
37
37
|
if (!this.nodes.has(node)) {
|
|
38
|
-
throw new Error(
|
|
38
|
+
throw new Error(`the node ${JSON.stringify(node)} is not from the router configuration`);
|
|
39
39
|
}
|
|
40
40
|
const now = this.evictExpired();
|
|
41
41
|
if (now === null) {
|
|
@@ -52,12 +52,12 @@ class StateCache {
|
|
|
52
52
|
delete(node) {
|
|
53
53
|
this.entries.delete(node);
|
|
54
54
|
}
|
|
55
|
-
/**
|
|
55
|
+
/** The number of live entries — for specs: eviction is visible without access to the internals. */
|
|
56
56
|
get size() {
|
|
57
57
|
this.evictExpired();
|
|
58
58
|
return this.entries.size;
|
|
59
59
|
}
|
|
60
|
-
/**
|
|
60
|
+
/** Evict the expired; return "now" by the cache clock or `null` if the clock did not give a number. */
|
|
61
61
|
evictExpired() {
|
|
62
62
|
const now = this.clock();
|
|
63
63
|
if (!Number.isFinite(now)) {
|
package/dist/state-cache.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"state-cache.js","sourceRoot":"","sources":["../src/state-cache.ts"],"names":[],"mappings":";;;AAIA;;;;;;;;;;;;;;GAcG;AACH,MAAa,UAAU;IAKF;IACA;IACA;IACA;IAPF,OAAO,GAAG,IAAI,GAAG,EAAsB,CAAC;IACjD,IAAI,GAAG,MAAM,CAAC,iBAAiB,CAAC;IAExC,YACmB,KAA0B,EAC1B,YAAoB,EACpB,YAAoB,EACpB,KAAY;QAHZ,UAAK,GAAL,KAAK,CAAqB;QAC1B,iBAAY,GAAZ,YAAY,CAAQ;QACpB,iBAAY,GAAZ,YAAY,CAAQ;QACpB,UAAK,GAAL,KAAK,CAAO;IAC5B,CAAC;IAEJ,GAAG,CAAC,IAAY;QACd,IAAI,CAAC,YAAY,EAAE,CAAC;QACpB,OAAO,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IAChC,CAAC;IAED,GAAG,CACD,IAAY,EACZ,OAAqB,EACrB,KAA2D;QAE3D,IAAI,CAAC,IAAI,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;YACpB,GAAG,EAAE,KAAK,CAAC,GAAG;YACd,SAAS,EAAE,KAAK,CAAC,SAAS;SAC3B,CAAC,CAAC;IACL,CAAC;IAED,MAAM,CAAC,IAAY;QACjB,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;IAC5B,CAAC;IAED,mGAAmG;IACnG,IAAI,IAAI;QACN,IAAI,CAAC,YAAY,EAAE,CAAC;QACpB,OAAO,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC;IAC3B,CAAC;IAED,uGAAuG;IAC/F,YAAY;QAClB,MAAM,GAAG,GAAG,IAAI,CAAC,KAAK,EAAE,CAAC;QACzB,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC;YAC1B,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC;YACrB,OAAO,IAAI,CAAC;QACd,CAAC;QACD,IAAI,GAAG,GAAG,IAAI,CAAC,IAAI,EAAE,CAAC;YACpB,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC;QACvB,CAAC;QACD,IAAI,CAAC,IAAI,GAAG,GAAG,CAAC;QAChB,KAAK,MAAM,CAAC,IAAI,EAAE,KAAK,CAAC,IAAI,IAAI,CAAC,OAAO,EAAE,CAAC;YACzC,IAAI,KAAK,CAAC,SAAS,IAAI,GAAG,EAAE,CAAC;gBAC3B,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;YAC5B,CAAC;QACH,CAAC;QACD,OAAO,GAAG,CAAC;IACb,CAAC;CACF;AAjED,gCAiEC"}
|
package/dist/timeline-of.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
2
|
+
* The timeline of a node: of replicas — the `received_tli` of the WAL receiver, of the primary — from
|
|
3
|
+
* the WAL file name of the insert position. `null` means not determined.
|
|
4
4
|
*/
|
|
5
5
|
export declare function timelineOf(inRecovery: boolean, receivedTli: unknown, walFile: unknown): number | null;
|
package/dist/timeline-of.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
2
|
+
* The timeline of a node: of replicas — the `received_tli` of the WAL receiver, of the primary — from
|
|
3
|
+
* the WAL file name of the insert position. `null` means not determined.
|
|
4
4
|
*/
|
|
5
5
|
export declare function timelineOf(inRecovery: boolean, receivedTli: unknown, walFile: unknown): number | null;
|
|
6
6
|
//# sourceMappingURL=timeline-of.d.ts.map
|
package/dist/timeline-of.js
CHANGED
|
@@ -3,8 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.timelineOf = timelineOf;
|
|
4
4
|
const wal_format_constant_1 = require("./constants/wal-format.constant");
|
|
5
5
|
/**
|
|
6
|
-
*
|
|
7
|
-
*
|
|
6
|
+
* The timeline of a node: of replicas — the `received_tli` of the WAL receiver, of the primary — from
|
|
7
|
+
* the WAL file name of the insert position. `null` means not determined.
|
|
8
8
|
*/
|
|
9
9
|
function timelineOf(inRecovery, receivedTli, walFile) {
|
|
10
10
|
if (inRecovery) {
|
package/dist/to-error.d.mts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
/**
|
|
1
|
+
/** A thrown value → an Error (anything can be thrown). */
|
|
2
2
|
export declare function toError(value: unknown): Error;
|
package/dist/to-error.d.ts
CHANGED
package/dist/to-error.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"to-error.d.ts","sourceRoot":"","sources":["../src/to-error.ts"],"names":[],"mappings":"AACA,
|
|
1
|
+
{"version":3,"file":"to-error.d.ts","sourceRoot":"","sources":["../src/to-error.ts"],"names":[],"mappings":"AACA,0DAA0D;AAC1D,wBAAgB,OAAO,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,CAE7C"}
|
package/dist/to-error.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.toError = toError;
|
|
4
4
|
const value_text_1 = require("./value-text");
|
|
5
|
-
/**
|
|
5
|
+
/** A thrown value → an Error (anything can be thrown). */
|
|
6
6
|
function toError(value) {
|
|
7
7
|
return value instanceof Error ? value : new Error((0, value_text_1.valueText)(value), { cause: value });
|
|
8
8
|
}
|
package/dist/to-error.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"to-error.js","sourceRoot":"","sources":["../src/to-error.ts"],"names":[],"mappings":";;AAEA,0BAEC;AAJD,6CAAyC;AACzC,
|
|
1
|
+
{"version":3,"file":"to-error.js","sourceRoot":"","sources":["../src/to-error.ts"],"names":[],"mappings":";;AAEA,0BAEC;AAJD,6CAAyC;AACzC,0DAA0D;AAC1D,SAAgB,OAAO,CAAC,KAAc;IACpC,OAAO,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,IAAA,sBAAS,EAAC,KAAK,CAAC,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,CAAC;AACxF,CAAC"}
|
package/dist/token-codec.d.mts
CHANGED
|
@@ -1,22 +1,22 @@
|
|
|
1
1
|
import type { DecodedToken } from './types/decoded-token.type.mjs';
|
|
2
2
|
import type { WalPosition } from './types/wal-position.type.mjs';
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
4
|
+
* A WAL position token for handing to a client (a header, a cookie, a context):
|
|
5
|
+
* it is signed with HMAC-SHA256, so a forged or corrupted position
|
|
6
|
+
* is not accepted. Everything that did not parse is `invalid`, and the router
|
|
7
|
+
* reads from the primary: an illegible token does not fail the request and does not send it to a
|
|
8
|
+
* replica. The token is not encrypted — a WAL position is not a secret, but it is not client data either.
|
|
9
9
|
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
10
|
+
* The token carries the issue moment (Unix epoch ms, the clock of the issuing process): by it
|
|
11
|
+
* the router limits how long a token that no replica can satisfy
|
|
12
|
+
* (without a position, from another timeline) holds the client on the primary.
|
|
13
13
|
*/
|
|
14
14
|
export declare class TokenCodec {
|
|
15
15
|
private readonly keys;
|
|
16
16
|
constructor(secrets: readonly (string | Uint8Array)[]);
|
|
17
17
|
/**
|
|
18
|
-
*
|
|
19
|
-
*
|
|
18
|
+
* Position → token; `null` gives a "position unknown" token: such a client reads from
|
|
19
|
+
* the primary. `issuedAt` is the issue moment, whole Unix epoch ms.
|
|
20
20
|
*/
|
|
21
21
|
encode(position: WalPosition | null, issuedAt: number): string;
|
|
22
22
|
decode(token: string): DecodedToken;
|
package/dist/token-codec.d.ts
CHANGED
|
@@ -1,22 +1,22 @@
|
|
|
1
1
|
import type { DecodedToken } from './types/decoded-token.type';
|
|
2
2
|
import type { WalPosition } from './types/wal-position.type';
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
4
|
+
* A WAL position token for handing to a client (a header, a cookie, a context):
|
|
5
|
+
* it is signed with HMAC-SHA256, so a forged or corrupted position
|
|
6
|
+
* is not accepted. Everything that did not parse is `invalid`, and the router
|
|
7
|
+
* reads from the primary: an illegible token does not fail the request and does not send it to a
|
|
8
|
+
* replica. The token is not encrypted — a WAL position is not a secret, but it is not client data either.
|
|
9
9
|
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
10
|
+
* The token carries the issue moment (Unix epoch ms, the clock of the issuing process): by it
|
|
11
|
+
* the router limits how long a token that no replica can satisfy
|
|
12
|
+
* (without a position, from another timeline) holds the client on the primary.
|
|
13
13
|
*/
|
|
14
14
|
export declare class TokenCodec {
|
|
15
15
|
private readonly keys;
|
|
16
16
|
constructor(secrets: readonly (string | Uint8Array)[]);
|
|
17
17
|
/**
|
|
18
|
-
*
|
|
19
|
-
*
|
|
18
|
+
* Position → token; `null` gives a "position unknown" token: such a client reads from
|
|
19
|
+
* the primary. `issuedAt` is the issue moment, whole Unix epoch ms.
|
|
20
20
|
*/
|
|
21
21
|
encode(position: WalPosition | null, issuedAt: number): string;
|
|
22
22
|
decode(token: string): DecodedToken;
|
package/dist/token-codec.js
CHANGED
|
@@ -10,88 +10,88 @@ const invalid_replica_sync_options_error_1 = require("./invalid-replica-sync-opt
|
|
|
10
10
|
const parse_lsn_1 = require("./parse-lsn");
|
|
11
11
|
const secret_weakness_1 = require("./secret-weakness");
|
|
12
12
|
/**
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
13
|
+
* A WAL position token for handing to a client (a header, a cookie, a context):
|
|
14
|
+
* it is signed with HMAC-SHA256, so a forged or corrupted position
|
|
15
|
+
* is not accepted. Everything that did not parse is `invalid`, and the router
|
|
16
|
+
* reads from the primary: an illegible token does not fail the request and does not send it to a
|
|
17
|
+
* replica. The token is not encrypted — a WAL position is not a secret, but it is not client data either.
|
|
18
18
|
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
19
|
+
* The token carries the issue moment (Unix epoch ms, the clock of the issuing process): by it
|
|
20
|
+
* the router limits how long a token that no replica can satisfy
|
|
21
|
+
* (without a position, from another timeline) holds the client on the primary.
|
|
22
22
|
*/
|
|
23
23
|
class TokenCodec {
|
|
24
24
|
keys;
|
|
25
25
|
constructor(secrets) {
|
|
26
26
|
if (!Array.isArray(secrets) || secrets.length === 0) {
|
|
27
|
-
throw new invalid_replica_sync_options_error_1.InvalidReplicaSyncOptionsError('secrets:
|
|
27
|
+
throw new invalid_replica_sync_options_error_1.InvalidReplicaSyncOptionsError('secrets: at least one token signing key is required');
|
|
28
28
|
}
|
|
29
29
|
this.keys = secrets.map((secret, index) => {
|
|
30
30
|
if (typeof secret !== 'string' && !(secret instanceof Uint8Array)) {
|
|
31
|
-
throw new invalid_replica_sync_options_error_1.InvalidReplicaSyncOptionsError(`secrets[${index}]:
|
|
31
|
+
throw new invalid_replica_sync_options_error_1.InvalidReplicaSyncOptionsError(`secrets[${index}]: a string or a Uint8Array is expected, got ${secret === null ? 'null' : typeof secret}`);
|
|
32
32
|
}
|
|
33
33
|
const key = Buffer.from(secret);
|
|
34
34
|
if (key.length < token_format_constant_1.TOKEN_FORMAT.MIN_SECRET_BYTES) {
|
|
35
|
-
throw new invalid_replica_sync_options_error_1.InvalidReplicaSyncOptionsError(`secrets[${index}]:
|
|
35
|
+
throw new invalid_replica_sync_options_error_1.InvalidReplicaSyncOptionsError(`secrets[${index}]: the key is shorter than ${token_format_constant_1.TOKEN_FORMAT.MIN_SECRET_BYTES} bytes (${key.length})`);
|
|
36
36
|
}
|
|
37
|
-
//
|
|
38
|
-
//
|
|
37
|
+
// A key that is a repetition of a piece, a near-repeat or a handful of distinct bytes is not a key:
|
|
38
|
+
// it is found by brute force. A dictionary key cannot be detected from here (secretWeakness).
|
|
39
39
|
const weakness = (0, secret_weakness_1.secretWeakness)(key);
|
|
40
40
|
if (weakness !== null) {
|
|
41
|
-
throw new invalid_replica_sync_options_error_1.InvalidReplicaSyncOptionsError(`secrets[${index}]: ${weakness} —
|
|
41
|
+
throw new invalid_replica_sync_options_error_1.InvalidReplicaSyncOptionsError(`secrets[${index}]: ${weakness} — not a key`);
|
|
42
42
|
}
|
|
43
43
|
return key;
|
|
44
44
|
});
|
|
45
45
|
}
|
|
46
46
|
/**
|
|
47
|
-
*
|
|
48
|
-
*
|
|
47
|
+
* Position → token; `null` gives a "position unknown" token: such a client reads from
|
|
48
|
+
* the primary. `issuedAt` is the issue moment, whole Unix epoch ms.
|
|
49
49
|
*/
|
|
50
50
|
encode(position, issuedAt) {
|
|
51
51
|
if (!Number.isSafeInteger(issuedAt) || issuedAt < 0) {
|
|
52
|
-
throw new RangeError(
|
|
52
|
+
throw new RangeError(`the issue moment is not a non-negative integer of ms: ${issuedAt}`);
|
|
53
53
|
}
|
|
54
54
|
let payload = `${token_format_constant_1.TOKEN_FORMAT.UNRESOLVED_TAG}:${issuedAt}`;
|
|
55
55
|
if (position !== null) {
|
|
56
56
|
if (!wal_format_constant_1.WAL_FORMAT.SYSTEM_ID.test(position.systemId)) {
|
|
57
|
-
throw new RangeError(`systemId
|
|
57
|
+
throw new RangeError(`systemId is not a number: ${JSON.stringify(position.systemId)}`);
|
|
58
58
|
}
|
|
59
59
|
if (!Number.isInteger(position.timeline) ||
|
|
60
60
|
position.timeline < 1 ||
|
|
61
61
|
position.timeline > wal_format_constant_1.WAL_FORMAT.MAX_TIMELINE) {
|
|
62
|
-
throw new RangeError(
|
|
62
|
+
throw new RangeError(`the timeline is outside 1..2³²−1: ${position.timeline}`);
|
|
63
63
|
}
|
|
64
64
|
payload = `${token_format_constant_1.TOKEN_FORMAT.POSITION_TAG}:${position.systemId}:${position.timeline}:${(0, format_lsn_1.formatLsn)(position.lsn)}:${issuedAt}`;
|
|
65
65
|
}
|
|
66
66
|
const body = Buffer.from(payload, 'utf8').toString('base64url');
|
|
67
67
|
const [signing] = this.keys;
|
|
68
68
|
if (signing === undefined) {
|
|
69
|
-
throw new invalid_replica_sync_options_error_1.InvalidReplicaSyncOptionsError('secrets:
|
|
69
|
+
throw new invalid_replica_sync_options_error_1.InvalidReplicaSyncOptionsError('secrets: no signing key');
|
|
70
70
|
}
|
|
71
71
|
return `${token_format_constant_1.TOKEN_FORMAT.VERSION}.${body}.${this.sign(signing, body).toString('base64url')}`;
|
|
72
72
|
}
|
|
73
73
|
decode(token) {
|
|
74
74
|
if (token.length > token_format_constant_1.TOKEN_FORMAT.MAX_LENGTH) {
|
|
75
|
-
return TokenCodec.invalid(
|
|
75
|
+
return TokenCodec.invalid(`longer than ${token_format_constant_1.TOKEN_FORMAT.MAX_LENGTH} characters`);
|
|
76
76
|
}
|
|
77
77
|
const parts = token.split('.');
|
|
78
78
|
const [version, body, signature] = parts;
|
|
79
79
|
if (parts.length !== 3 || version === undefined || body === undefined || signature === undefined) {
|
|
80
|
-
return TokenCodec.invalid('
|
|
80
|
+
return TokenCodec.invalid('not three parts separated by dots');
|
|
81
81
|
}
|
|
82
82
|
if (version !== token_format_constant_1.TOKEN_FORMAT.VERSION) {
|
|
83
|
-
return TokenCodec.invalid(
|
|
83
|
+
return TokenCodec.invalid(`version ${JSON.stringify(version.slice(0, 8))}`);
|
|
84
84
|
}
|
|
85
85
|
const mac = (0, decode_canonical_base64url_1.decodeCanonicalBase64Url)(signature);
|
|
86
86
|
if (mac === null || mac.length !== token_format_constant_1.TOKEN_FORMAT.MAC_BYTES) {
|
|
87
|
-
return TokenCodec.invalid('
|
|
87
|
+
return TokenCodec.invalid('the signature is not in the form');
|
|
88
88
|
}
|
|
89
89
|
if (!this.keys.some((key) => (0, node_crypto_1.timingSafeEqual)(this.sign(key, body), mac))) {
|
|
90
|
-
return TokenCodec.invalid('
|
|
90
|
+
return TokenCodec.invalid('the signature does not match');
|
|
91
91
|
}
|
|
92
92
|
const payloadBytes = (0, decode_canonical_base64url_1.decodeCanonicalBase64Url)(body);
|
|
93
93
|
if (payloadBytes === null) {
|
|
94
|
-
return TokenCodec.invalid('
|
|
94
|
+
return TokenCodec.invalid('the payload is not in the form');
|
|
95
95
|
}
|
|
96
96
|
return this.parsePayload(payloadBytes.toString('utf8'));
|
|
97
97
|
}
|
|
@@ -114,22 +114,22 @@ class TokenCodec {
|
|
|
114
114
|
const issuedAt = TokenCodec.issuedAtOf(fields[1]);
|
|
115
115
|
return fields.length === 2 && issuedAt !== null
|
|
116
116
|
? { kind: 'unresolved', issuedAt }
|
|
117
|
-
: TokenCodec.invalid('
|
|
117
|
+
: TokenCodec.invalid('the payload does not parse');
|
|
118
118
|
}
|
|
119
119
|
const [tag, systemId, timelineText, lsnText, issuedAtText] = fields;
|
|
120
120
|
if (fields.length !== 5 ||
|
|
121
121
|
tag !== token_format_constant_1.TOKEN_FORMAT.POSITION_TAG ||
|
|
122
122
|
systemId === undefined ||
|
|
123
123
|
!wal_format_constant_1.WAL_FORMAT.SYSTEM_ID.test(systemId)) {
|
|
124
|
-
return TokenCodec.invalid('
|
|
124
|
+
return TokenCodec.invalid('the payload does not parse');
|
|
125
125
|
}
|
|
126
126
|
const timeline = Number(timelineText);
|
|
127
127
|
if (!wal_format_constant_1.WAL_FORMAT.TIMELINE_TEXT.test(timelineText ?? '') || timeline > wal_format_constant_1.WAL_FORMAT.MAX_TIMELINE) {
|
|
128
|
-
return TokenCodec.invalid('
|
|
128
|
+
return TokenCodec.invalid('the timeline does not parse');
|
|
129
129
|
}
|
|
130
130
|
const issuedAt = TokenCodec.issuedAtOf(issuedAtText);
|
|
131
131
|
if (issuedAt === null) {
|
|
132
|
-
return TokenCodec.invalid('
|
|
132
|
+
return TokenCodec.invalid('the issue moment does not parse');
|
|
133
133
|
}
|
|
134
134
|
try {
|
|
135
135
|
return {
|
|
@@ -139,7 +139,7 @@ class TokenCodec {
|
|
|
139
139
|
};
|
|
140
140
|
}
|
|
141
141
|
catch {
|
|
142
|
-
return TokenCodec.invalid('
|
|
142
|
+
return TokenCodec.invalid('the position does not parse');
|
|
143
143
|
}
|
|
144
144
|
}
|
|
145
145
|
}
|
package/dist/token-codec.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"token-codec.js","sourceRoot":"","sources":["../src/token-codec.ts"],"names":[],"mappings":";;;AAAA,6CAA0D;AAE1D,6EAAiE;AACjE,yEAA6D;AAC7D,6EAAwE;AACxE,6CAAyC;AACzC,6FAAsF;AACtF,2CAAuC;AACvC,uDAAmD;AAInD;;;;;;;;;;GAUG;AACH,MAAa,UAAU;IACJ,IAAI,CAAoB;IAEzC,YAAY,OAAyC;QACnD,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YACpD,MAAM,IAAI,mEAA8B,CAAC,
|
|
1
|
+
{"version":3,"file":"token-codec.js","sourceRoot":"","sources":["../src/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Q,EAAE,GAAG,EAAE,IAAA,oBAAQ,EAAC,OAAO,IAAI,EAAE,CAAC,EAAE;gBAC9D,QAAQ;aACT,CAAC;QACJ,CAAC;QAAC,MAAM,CAAC;YACP,OAAO,UAAU,CAAC,OAAO,CAAC,6BAA6B,CAAC,CAAC;QAC3D,CAAC;IACH,CAAC;CACF;AAxID,gCAwIC"}
|
package/dist/token-lsn.d.mts
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
import type { WalLayout } from './types/wal-layout.type.mjs';
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
3
|
+
* The position for a token by the primary insert position.
|
|
4
4
|
*
|
|
5
|
-
* `pg_current_wal_insert_lsn()`,
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
5
|
+
* `pg_current_wal_insert_lsn()`, when the last record ended exactly on a
|
|
6
|
+
* WAL page boundary (or right after a segment switch), stands BEHIND
|
|
7
|
+
* the header of the new page, where there is no record yet, while the replica replay is
|
|
8
|
+
* at the boundary itself (the end of the last record). A replica passed such a position
|
|
9
|
+
* only with the next WAL record — on an idle primary this is a wait without an
|
|
10
|
+
* upper bound. The header bytes are not record bytes: no record
|
|
11
|
+
* ends inside it, so the page boundary is the same position "after
|
|
12
|
+
* everything written", and the token takes it.
|
|
13
13
|
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
* (24
|
|
17
|
-
*
|
|
14
|
+
* The header sizes come from the server layout (`pg_control_init()`):
|
|
15
|
+
* short = MAXALIGN(20), long (the first page of a segment) = MAXALIGN(36)
|
|
16
|
+
* (24 and 40 with alignment 8). If the layout was not determined or the alignment
|
|
17
|
+
* is neither 4 nor 8, the insert position as is: an error on the side of the primary.
|
|
18
18
|
*/
|
|
19
19
|
export declare function tokenLsn(insertLsn: bigint, layout: WalLayout | null): bigint;
|
package/dist/token-lsn.d.ts
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
import type { WalLayout } from './types/wal-layout.type';
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
3
|
+
* The position for a token by the primary insert position.
|
|
4
4
|
*
|
|
5
|
-
* `pg_current_wal_insert_lsn()`,
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
5
|
+
* `pg_current_wal_insert_lsn()`, when the last record ended exactly on a
|
|
6
|
+
* WAL page boundary (or right after a segment switch), stands BEHIND
|
|
7
|
+
* the header of the new page, where there is no record yet, while the replica replay is
|
|
8
|
+
* at the boundary itself (the end of the last record). A replica passed such a position
|
|
9
|
+
* only with the next WAL record — on an idle primary this is a wait without an
|
|
10
|
+
* upper bound. The header bytes are not record bytes: no record
|
|
11
|
+
* ends inside it, so the page boundary is the same position "after
|
|
12
|
+
* everything written", and the token takes it.
|
|
13
13
|
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
* (24
|
|
17
|
-
*
|
|
14
|
+
* The header sizes come from the server layout (`pg_control_init()`):
|
|
15
|
+
* short = MAXALIGN(20), long (the first page of a segment) = MAXALIGN(36)
|
|
16
|
+
* (24 and 40 with alignment 8). If the layout was not determined or the alignment
|
|
17
|
+
* is neither 4 nor 8, the insert position as is: an error on the side of the primary.
|
|
18
18
|
*/
|
|
19
19
|
export declare function tokenLsn(insertLsn: bigint, layout: WalLayout | null): bigint;
|
|
20
20
|
//# sourceMappingURL=token-lsn.d.ts.map
|
package/dist/token-lsn.js
CHANGED
|
@@ -2,21 +2,21 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.tokenLsn = tokenLsn;
|
|
4
4
|
/**
|
|
5
|
-
*
|
|
5
|
+
* The position for a token by the primary insert position.
|
|
6
6
|
*
|
|
7
|
-
* `pg_current_wal_insert_lsn()`,
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
7
|
+
* `pg_current_wal_insert_lsn()`, when the last record ended exactly on a
|
|
8
|
+
* WAL page boundary (or right after a segment switch), stands BEHIND
|
|
9
|
+
* the header of the new page, where there is no record yet, while the replica replay is
|
|
10
|
+
* at the boundary itself (the end of the last record). A replica passed such a position
|
|
11
|
+
* only with the next WAL record — on an idle primary this is a wait without an
|
|
12
|
+
* upper bound. The header bytes are not record bytes: no record
|
|
13
|
+
* ends inside it, so the page boundary is the same position "after
|
|
14
|
+
* everything written", and the token takes it.
|
|
15
15
|
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
* (24
|
|
19
|
-
*
|
|
16
|
+
* The header sizes come from the server layout (`pg_control_init()`):
|
|
17
|
+
* short = MAXALIGN(20), long (the first page of a segment) = MAXALIGN(36)
|
|
18
|
+
* (24 and 40 with alignment 8). If the layout was not determined or the alignment
|
|
19
|
+
* is neither 4 nor 8, the insert position as is: an error on the side of the primary.
|
|
20
20
|
*/
|
|
21
21
|
function tokenLsn(insertLsn, layout) {
|
|
22
22
|
if (layout === null || (layout.maxAlign !== 4 && layout.maxAlign !== 8)) {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* `COMMIT`
|
|
3
|
-
* `ROLLBACK`
|
|
2
|
+
* `COMMIT` did not commit: the transaction was in an error state, and Postgres answered
|
|
3
|
+
* `ROLLBACK` without an exception. There is no write — and there must be no token after it.
|
|
4
4
|
*/
|
|
5
5
|
export declare class TransactionNotCommittedError extends Error {
|
|
6
6
|
readonly command: string;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* `COMMIT`
|
|
3
|
-
* `ROLLBACK`
|
|
2
|
+
* `COMMIT` did not commit: the transaction was in an error state, and Postgres answered
|
|
3
|
+
* `ROLLBACK` without an exception. There is no write — and there must be no token after it.
|
|
4
4
|
*/
|
|
5
5
|
export declare class TransactionNotCommittedError extends Error {
|
|
6
6
|
readonly command: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transaction-not-committed.error.d.ts","sourceRoot":"","sources":["../src/transaction-not-committed.error.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,qBAAa,4BAA6B,SAAQ,KAAK;IAGzC,QAAQ,CAAC,OAAO,EAAE,MAAM;IAFpC,SAAkB,IAAI,kCAAkC;gBAEnC,OAAO,EAAE,MAAM;
|
|
1
|
+
{"version":3,"file":"transaction-not-committed.error.d.ts","sourceRoot":"","sources":["../src/transaction-not-committed.error.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,qBAAa,4BAA6B,SAAQ,KAAK;IAGzC,QAAQ,CAAC,OAAO,EAAE,MAAM;IAFpC,SAAkB,IAAI,kCAAkC;gBAEnC,OAAO,EAAE,MAAM;CAKrC"}
|
|
@@ -2,14 +2,14 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.TransactionNotCommittedError = void 0;
|
|
4
4
|
/**
|
|
5
|
-
* `COMMIT`
|
|
6
|
-
* `ROLLBACK`
|
|
5
|
+
* `COMMIT` did not commit: the transaction was in an error state, and Postgres answered
|
|
6
|
+
* `ROLLBACK` without an exception. There is no write — and there must be no token after it.
|
|
7
7
|
*/
|
|
8
8
|
class TransactionNotCommittedError extends Error {
|
|
9
9
|
command;
|
|
10
10
|
name = 'TransactionNotCommittedError';
|
|
11
11
|
constructor(command) {
|
|
12
|
-
super(`COMMIT
|
|
12
|
+
super(`COMMIT finished as ${JSON.stringify(command)}: the transaction is rolled back, the write did not go through`);
|
|
13
13
|
this.command = command;
|
|
14
14
|
}
|
|
15
15
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transaction-not-committed.error.js","sourceRoot":"","sources":["../src/transaction-not-committed.error.ts"],"names":[],"mappings":";;;AAAA;;;GAGG;AACH,MAAa,4BAA6B,SAAQ,KAAK;IAGhC;IAFH,IAAI,GAAG,8BAA8B,CAAC;IAExD,YAAqB,OAAe;QAClC,KAAK,
|
|
1
|
+
{"version":3,"file":"transaction-not-committed.error.js","sourceRoot":"","sources":["../src/transaction-not-committed.error.ts"],"names":[],"mappings":";;;AAAA;;;GAGG;AACH,MAAa,4BAA6B,SAAQ,KAAK;IAGhC;IAFH,IAAI,GAAG,8BAA8B,CAAC;IAExD,YAAqB,OAAe;QAClC,KAAK,CACH,sBAAsB,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,gEAAgE,CAC9G,CAAC;QAHiB,YAAO,GAAP,OAAO,CAAQ;IAIpC,CAAC;CACF;AARD,oEAQC"}
|