@optimystic/db-core 1.19.0 → 1.20.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/dist/src/cluster/structs.d.ts +41 -8
- package/dist/src/cluster/structs.d.ts.map +1 -1
- package/dist/src/cluster/structs.js +18 -7
- package/dist/src/cluster/structs.js.map +1 -1
- package/dist/src/collection/action.d.ts +29 -0
- package/dist/src/collection/action.d.ts.map +1 -1
- package/dist/src/collection/action.js +6 -0
- package/dist/src/collection/action.js.map +1 -1
- package/dist/src/collection/collection.d.ts +533 -120
- package/dist/src/collection/collection.d.ts.map +1 -1
- package/dist/src/collection/collection.js +974 -500
- package/dist/src/collection/collection.js.map +1 -1
- package/dist/src/collection/head-commit.d.ts +110 -0
- package/dist/src/collection/head-commit.d.ts.map +1 -0
- package/dist/src/collection/head-commit.js +65 -0
- package/dist/src/collection/head-commit.js.map +1 -0
- package/dist/src/collection/index.d.ts +2 -0
- package/dist/src/collection/index.d.ts.map +1 -1
- package/dist/src/collection/index.js +2 -0
- package/dist/src/collection/index.js.map +1 -1
- package/dist/src/collection/segments.d.ts +77 -0
- package/dist/src/collection/segments.d.ts.map +1 -0
- package/dist/src/collection/segments.js +110 -0
- package/dist/src/collection/segments.js.map +1 -0
- package/dist/src/collection/struct.d.ts +156 -1
- package/dist/src/collection/struct.d.ts.map +1 -1
- package/dist/src/collection/struct.js +70 -0
- package/dist/src/collection/struct.js.map +1 -1
- package/dist/src/collection/write-attempts.d.ts +245 -0
- package/dist/src/collection/write-attempts.d.ts.map +1 -0
- package/dist/src/collection/write-attempts.js +439 -0
- package/dist/src/collection/write-attempts.js.map +1 -0
- package/dist/src/collections/tree/struct.d.ts +100 -17
- package/dist/src/collections/tree/struct.d.ts.map +1 -1
- package/dist/src/collections/tree/struct.js +38 -7
- package/dist/src/collections/tree/struct.js.map +1 -1
- package/dist/src/collections/tree/tree.d.ts +17 -5
- package/dist/src/collections/tree/tree.d.ts.map +1 -1
- package/dist/src/collections/tree/tree.js +112 -26
- package/dist/src/collections/tree/tree.js.map +1 -1
- package/dist/src/index.d.ts +2 -0
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +2 -0
- package/dist/src/index.js.map +1 -1
- package/dist/src/network/i-repo.d.ts +3 -0
- package/dist/src/network/i-repo.d.ts.map +1 -1
- package/dist/src/network/index.d.ts +3 -0
- package/dist/src/network/index.d.ts.map +1 -1
- package/dist/src/network/index.js +3 -0
- package/dist/src/network/index.js.map +1 -1
- package/dist/src/network/promise-shortfall-error.d.ts +40 -0
- package/dist/src/network/promise-shortfall-error.d.ts.map +1 -0
- package/dist/src/network/promise-shortfall-error.js +67 -0
- package/dist/src/network/promise-shortfall-error.js.map +1 -0
- package/dist/src/network/refuse-solo.d.ts +8 -0
- package/dist/src/network/refuse-solo.d.ts.map +1 -0
- package/dist/src/network/refuse-solo.js +8 -0
- package/dist/src/network/refuse-solo.js.map +1 -0
- package/dist/src/network/stale-failure.d.ts +20 -3
- package/dist/src/network/stale-failure.d.ts.map +1 -1
- package/dist/src/network/stale-failure.js +24 -3
- package/dist/src/network/stale-failure.js.map +1 -1
- package/dist/src/network/struct.d.ts +148 -2
- package/dist/src/network/struct.d.ts.map +1 -1
- package/dist/src/network/struct.js.map +1 -1
- package/dist/src/network/validity-rejected-error.d.ts +28 -0
- package/dist/src/network/validity-rejected-error.d.ts.map +1 -0
- package/dist/src/network/validity-rejected-error.js +51 -0
- package/dist/src/network/validity-rejected-error.js.map +1 -0
- package/dist/src/offline/entry.d.ts +72 -0
- package/dist/src/offline/entry.d.ts.map +1 -0
- package/dist/src/offline/entry.js +73 -0
- package/dist/src/offline/entry.js.map +1 -0
- package/dist/src/offline/index.d.ts +5 -0
- package/dist/src/offline/index.d.ts.map +1 -0
- package/dist/src/offline/index.js +5 -0
- package/dist/src/offline/index.js.map +1 -0
- package/dist/src/offline/journal.d.ts +61 -0
- package/dist/src/offline/journal.d.ts.map +1 -0
- package/dist/src/offline/journal.js +2 -0
- package/dist/src/offline/journal.js.map +1 -0
- package/dist/src/offline/queue.d.ts +484 -0
- package/dist/src/offline/queue.d.ts.map +1 -0
- package/dist/src/offline/queue.js +1236 -0
- package/dist/src/offline/queue.js.map +1 -0
- package/dist/src/offline/reachability.d.ts +25 -0
- package/dist/src/offline/reachability.d.ts.map +1 -0
- package/dist/src/offline/reachability.js +13 -0
- package/dist/src/offline/reachability.js.map +1 -0
- package/dist/src/offline/status.d.ts +148 -0
- package/dist/src/offline/status.d.ts.map +1 -0
- package/dist/src/offline/status.js +63 -0
- package/dist/src/offline/status.js.map +1 -0
- package/dist/src/offline/wake.d.ts +30 -0
- package/dist/src/offline/wake.d.ts.map +1 -0
- package/dist/src/offline/wake.js +68 -0
- package/dist/src/offline/wake.js.map +1 -0
- package/dist/src/testing/test-transactor.d.ts +29 -0
- package/dist/src/testing/test-transactor.d.ts.map +1 -1
- package/dist/src/testing/test-transactor.js +50 -0
- package/dist/src/testing/test-transactor.js.map +1 -1
- package/dist/src/transaction/commit-failure-class.d.ts +103 -0
- package/dist/src/transaction/commit-failure-class.d.ts.map +1 -0
- package/dist/src/transaction/commit-failure-class.js +96 -0
- package/dist/src/transaction/commit-failure-class.js.map +1 -0
- package/dist/src/transaction/coordinator.d.ts +165 -41
- package/dist/src/transaction/coordinator.d.ts.map +1 -1
- package/dist/src/transaction/coordinator.js +605 -300
- package/dist/src/transaction/coordinator.js.map +1 -1
- package/dist/src/transaction/entry-commit.d.ts +139 -0
- package/dist/src/transaction/entry-commit.d.ts.map +1 -0
- package/dist/src/transaction/entry-commit.js +199 -0
- package/dist/src/transaction/entry-commit.js.map +1 -0
- package/dist/src/transaction/index.d.ts +4 -1
- package/dist/src/transaction/index.d.ts.map +1 -1
- package/dist/src/transaction/index.js +1 -0
- package/dist/src/transaction/index.js.map +1 -1
- package/dist/src/transaction/transaction.d.ts +20 -0
- package/dist/src/transaction/transaction.d.ts.map +1 -1
- package/dist/src/transaction/validator.d.ts +7 -0
- package/dist/src/transaction/validator.d.ts.map +1 -1
- package/dist/src/transaction/validator.js +21 -12
- package/dist/src/transaction/validator.js.map +1 -1
- package/dist/src/transactor/network-transactor.d.ts +1 -0
- package/dist/src/transactor/network-transactor.d.ts.map +1 -1
- package/dist/src/transactor/network-transactor.js +61 -28
- package/dist/src/transactor/network-transactor.js.map +1 -1
- package/dist/src/transactor/transactor-source.d.ts +22 -11
- package/dist/src/transactor/transactor-source.d.ts.map +1 -1
- package/dist/src/transactor/transactor-source.js +9 -13
- package/dist/src/transactor/transactor-source.js.map +1 -1
- package/dist/src/utility/visit-every.d.ts +14 -0
- package/dist/src/utility/visit-every.d.ts.map +1 -0
- package/dist/src/utility/visit-every.js +27 -0
- package/dist/src/utility/visit-every.js.map +1 -0
- package/package.json +1 -1
- package/src/cluster/structs.ts +42 -7
- package/src/collection/action.ts +34 -0
- package/src/collection/collection.ts +1048 -543
- package/src/collection/head-commit.ts +148 -0
- package/src/collection/index.ts +2 -0
- package/src/collection/segments.ts +149 -0
- package/src/collection/struct.ts +183 -1
- package/src/collection/write-attempts.ts +506 -0
- package/src/collections/tree/struct.ts +97 -17
- package/src/collections/tree/tree.ts +125 -29
- package/src/index.ts +2 -0
- package/src/network/i-repo.ts +3 -0
- package/src/network/index.ts +3 -0
- package/src/network/promise-shortfall-error.ts +69 -0
- package/src/network/refuse-solo.ts +7 -0
- package/src/network/stale-failure.ts +27 -4
- package/src/network/struct.ts +154 -2
- package/src/network/validity-rejected-error.ts +55 -0
- package/src/offline/entry.ts +127 -0
- package/src/offline/index.ts +4 -0
- package/src/offline/journal.ts +60 -0
- package/src/offline/queue.ts +1342 -0
- package/src/offline/reachability.ts +32 -0
- package/src/offline/status.ts +183 -0
- package/src/offline/wake.ts +67 -0
- package/src/testing/test-transactor.ts +53 -0
- package/src/transaction/commit-failure-class.ts +133 -0
- package/src/transaction/coordinator.ts +696 -349
- package/src/transaction/entry-commit.ts +285 -0
- package/src/transaction/index.ts +4 -0
- package/src/transaction/transaction.ts +21 -0
- package/src/transaction/validator.ts +22 -12
- package/src/transactor/network-transactor.ts +62 -28
- package/src/transactor/transactor-source.ts +29 -13
- package/src/utility/visit-every.ts +25 -0
|
@@ -6,11 +6,32 @@ import { withBlockRevs } from "../network/durability.js";
|
|
|
6
6
|
import type { ReadDependency } from "../transaction/transaction.js";
|
|
7
7
|
import { ReadDependencyCollector } from "../transaction/read-dependency-collector.js";
|
|
8
8
|
import { blockDigestsField, baseRevsField } from "../transform/digest.js";
|
|
9
|
+
import { refuseSoloField } from "../network/refuse-solo.js";
|
|
9
10
|
import type { BlockFloorCheck } from "./block-floors.js";
|
|
10
11
|
import { createLogger } from "../logger.js";
|
|
11
12
|
|
|
12
13
|
const log = createLogger('transactor-source');
|
|
13
14
|
|
|
15
|
+
/** {@link TransactorSource.transact}'s optional parts of one attempt. Each is omitted from the
|
|
16
|
+
* request it rides on when unset, so a caller that sets nothing sends exactly the requests it always
|
|
17
|
+
* did — every one of them is hashed verbatim into the cohort signature preimages. */
|
|
18
|
+
export type TransactOptions = {
|
|
19
|
+
/** Aged, advisory retry priority (default 0). Rides on the pend so a repeatedly-losing
|
|
20
|
+
* single-collection sync out-ranks fresh rivals in a concurrent race (`resolveRace`);
|
|
21
|
+
* fairness-only, never affects validity. Omitted from the pend when 0. */
|
|
22
|
+
readonly priority?: number;
|
|
23
|
+
/** Per-block content declarations for the commit (see {@link BlockContentDigests}), computed by
|
|
24
|
+
* the caller from the same tracker that produced the transforms. */
|
|
25
|
+
readonly blockDigests?: BlockContentDigests;
|
|
26
|
+
/** Per-block base revisions for the pend (see `PendRequest.baseRevs`): the committed revision each
|
|
27
|
+
* update-only block's operations were computed against, from the same tracker
|
|
28
|
+
* (`Tracker.stagedBaseRevs`). */
|
|
29
|
+
readonly baseRevs?: BlockBaseRevs;
|
|
30
|
+
/** Refuse to be committed by a lone coordinator that knows it is not alone
|
|
31
|
+
* (`SyncOptions.refuseSoloCommit`): set on both the pend and the commit as `refuseSolo`. */
|
|
32
|
+
readonly refuseSolo?: boolean;
|
|
33
|
+
};
|
|
34
|
+
|
|
14
35
|
/** The block `entry` answers for `id`, for a read at `context` (`undefined` for an unpinned "give me
|
|
15
36
|
* latest" read) — `undefined` when the block is absent — or a throw when the entry is not an answer
|
|
16
37
|
* that read may use. Every read that consumes a raw {@link GetBlockResult} goes through here, so a
|
|
@@ -218,16 +239,8 @@ export class TransactorSource<TBlock extends IBlock> implements BlockSource<TBlo
|
|
|
218
239
|
* that creates it.
|
|
219
240
|
* @param tailId - The Id of the collection's log tail block. This block's transform is committed FIRST
|
|
220
241
|
* (prior to the rest of the block operations), to resolve the "winner" of a race to commit to the collection.
|
|
221
|
-
* @param
|
|
222
|
-
*
|
|
223
|
-
* affects validity. Omitted from the pend when 0 so the common first-attempt pend serializes exactly as before.
|
|
224
|
-
* @param blockDigests - Optional per-block content declarations for this commit (see {@link BlockContentDigests}),
|
|
225
|
-
* computed by the caller from the same tracker that produced `transform`. Omitted from the commit request when
|
|
226
|
-
* undefined, so a caller that declares nothing produces exactly the request shape as before — the field rides
|
|
227
|
-
* inside every cohort signature's hash preimage, so keeping the shape clean keeps those preimages clean.
|
|
228
|
-
* @param baseRevs - Optional per-block base revisions for the pend (see {@link PendRequest.baseRevs}): the
|
|
229
|
-
* committed revision each update-only block's operations were computed against, from the same tracker
|
|
230
|
-
* (`Tracker.stagedBaseRevs`). Omitted from the pend request when empty, for the same preimage reason.
|
|
242
|
+
* @param options - The attempt's optional parts ({@link TransactOptions}); each is left off the request it
|
|
243
|
+
* rides on when unset.
|
|
231
244
|
* @returns The transactor's own verdict, unflattened: a {@link CommitSuccess} carrying the
|
|
232
245
|
* {@link WriteDurability} of the committed revision — naming every block it committed at `rev`
|
|
233
246
|
* (`blockRevs`) — or a {@link StaleFailure} if the pend or the commit was refused. Success is
|
|
@@ -236,13 +249,15 @@ export class TransactorSource<TBlock extends IBlock> implements BlockSource<TBlo
|
|
|
236
249
|
* `result.success`. Test "is this completely saved" through `isFullyDurable`, never
|
|
237
250
|
* by comparing `quorum` (see {@link WriteDurability}).
|
|
238
251
|
*/
|
|
239
|
-
async transact(transform: Transforms, actionId: ActionId, rev: number, headerId: BlockId, tailId: BlockId,
|
|
252
|
+
async transact(transform: Transforms, actionId: ActionId, rev: number, headerId: BlockId, tailId: BlockId, options: TransactOptions = {}): Promise<CommitResult> {
|
|
253
|
+
const { priority = 0, blockDigests, baseRevs, refuseSolo } = options;
|
|
240
254
|
const pendResult = await this.transactor.pend({
|
|
241
255
|
transforms: transform, actionId, rev, policy: 'r',
|
|
242
256
|
...(priority > 0 ? { priority } : {}),
|
|
243
257
|
...baseRevsField(baseRevs),
|
|
244
258
|
// One collection, pended whole and then committed: the shape `PendRequest.soleReservation` names.
|
|
245
|
-
soleReservation: true
|
|
259
|
+
soleReservation: true,
|
|
260
|
+
...refuseSoloField(refuseSolo)
|
|
246
261
|
});
|
|
247
262
|
if (!pendResult.success) {
|
|
248
263
|
return pendResult;
|
|
@@ -255,7 +270,8 @@ export class TransactorSource<TBlock extends IBlock> implements BlockSource<TBlo
|
|
|
255
270
|
blockIds: pendResult.blockIds,
|
|
256
271
|
actionId,
|
|
257
272
|
rev,
|
|
258
|
-
...blockDigestsField(blockDigests)
|
|
273
|
+
...blockDigestsField(blockDigests),
|
|
274
|
+
...refuseSoloField(refuseSolo)
|
|
259
275
|
});
|
|
260
276
|
if (!commitResult.success) {
|
|
261
277
|
// A confirmed conflict has to be RETURNED as the StaleFailure, because `Collection.sync`
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Visit every item in turn, letting no throw stop the rest, and throw the FIRST error once every
|
|
3
|
+
* item has been visited. Sequential on purpose: each visit must finish before the next starts.
|
|
4
|
+
*
|
|
5
|
+
* For a round of independent per-collection steps — a rollback's restores, a commit's unwinding of
|
|
6
|
+
* its failed participants — where stopping at the first throw would leave every later collection
|
|
7
|
+
* untouched, and silently: the caller sees one error and has no way to tell which collections it
|
|
8
|
+
* reached. Each step being independent (its own instance, its own state) is what makes the first
|
|
9
|
+
* error the right one to report; a step whose failure should change how the next is handled does
|
|
10
|
+
* not belong in this loop. `TransactionCoordinator.refreshBetweenAttempts` is the same idiom with
|
|
11
|
+
* a per-error classification this helper does not carry.
|
|
12
|
+
*/
|
|
13
|
+
export async function visitEveryThenThrow<T>(items: Iterable<T>, visit: (item: T) => Promise<void>): Promise<void> {
|
|
14
|
+
let first: { error: unknown } | undefined;
|
|
15
|
+
for (const item of items) {
|
|
16
|
+
try {
|
|
17
|
+
await visit(item);
|
|
18
|
+
} catch (error) {
|
|
19
|
+
first ??= { error };
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
if (first !== undefined) {
|
|
23
|
+
throw first.error;
|
|
24
|
+
}
|
|
25
|
+
}
|