@peerbit/document 15.0.32 → 15.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +49 -0
- package/dist/src/batch-error.d.ts +23 -0
- package/dist/src/batch-error.d.ts.map +1 -0
- package/dist/src/batch-error.js +26 -0
- package/dist/src/batch-error.js.map +1 -0
- package/dist/src/index.d.ts +1 -0
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +1 -0
- package/dist/src/index.js.map +1 -1
- package/dist/src/program.d.ts +5 -1
- package/dist/src/program.d.ts.map +1 -1
- package/dist/src/program.js +99 -39
- package/dist/src/program.js.map +1 -1
- package/package.json +14 -14
- package/src/batch-error.ts +45 -0
- package/src/index.ts +1 -0
- package/src/program.ts +150 -44
package/README.md
CHANGED
|
@@ -33,6 +33,55 @@ single `del` operation. For a delete, the receipt covers the exact `CUT`
|
|
|
33
33
|
tombstone entry. It does not wait for remote document-index or change-event
|
|
34
34
|
side effects, prove permanent tombstone retention, or compact prior history.
|
|
35
35
|
|
|
36
|
+
## Required local batching and failure accounting
|
|
37
|
+
|
|
38
|
+
Callers that cannot accept a sequential `put` fallback can opt in explicitly:
|
|
39
|
+
|
|
40
|
+
```typescript
|
|
41
|
+
import { DocumentBatchCommitError } from "@peerbit/document";
|
|
42
|
+
|
|
43
|
+
try {
|
|
44
|
+
const result = await store.docs.putMany(documents, {
|
|
45
|
+
batching: "required",
|
|
46
|
+
unique: true,
|
|
47
|
+
target: "none",
|
|
48
|
+
});
|
|
49
|
+
// result.entries has the same order as the captured input documents.
|
|
50
|
+
} catch (error) {
|
|
51
|
+
if (!(error instanceof DocumentBatchCommitError)) throw error;
|
|
52
|
+
console.log(error.localCommit, error.committedItems, error.cause);
|
|
53
|
+
}
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
Required mode captures the input array, document encodings, keys, and supported
|
|
57
|
+
append options at invocation. It rejects unsupported document modes/options and
|
|
58
|
+
duplicate keys before append, and never falls back to sequential document puts.
|
|
59
|
+
The default behavior is unchanged. This requires the existing independent batch
|
|
60
|
+
append path, not an all-or-none storage transaction or a particular number of
|
|
61
|
+
fsync calls. Backend durability configuration still applies.
|
|
62
|
+
|
|
63
|
+
`DocumentBatchCommitError.committedItems` is an immutable array of `{ index, hash }`
|
|
64
|
+
pairs: indexes refer to the captured input array, not a later mutated array.
|
|
65
|
+
The local outcome is separate from projection and remote delivery:
|
|
66
|
+
|
|
67
|
+
- `not-started`: no local append was handed off; `retrySafe` is true for replaying
|
|
68
|
+
the local append only, not for application/policy callback side effects.
|
|
69
|
+
- `committed`: the complete ordered local append is confirmed. Do not replay it;
|
|
70
|
+
projection, change-event, or remote-receipt work may still have failed. Inspect
|
|
71
|
+
`cause` to determine the failed phase.
|
|
72
|
+
- `indeterminate`: native preparation/append may have changed state without a
|
|
73
|
+
complete success acknowledgment, or native durable persistence failed.
|
|
74
|
+
`recoveryRequired` is true and automatic replay is unsafe. An empty evidence
|
|
75
|
+
array does **not** mean nothing committed. Exact indexes are exposed only when
|
|
76
|
+
the complete ordered batch is known.
|
|
77
|
+
|
|
78
|
+
`recoveryRequired` describes an unresolved local append outcome: false does not
|
|
79
|
+
mean a failed document projection needs no repair. Required batching can also be
|
|
80
|
+
combined with persisted delivery (omit `target: "none"` in that case). A remote
|
|
81
|
+
receipt failure retains local commit evidence and the `PersistedDeliveryError`
|
|
82
|
+
as `cause`; only successful persisted delivery proves the requested remote
|
|
83
|
+
durability. No transaction atomicity or permanent custody is implied.
|
|
84
|
+
|
|
36
85
|
|
|
37
86
|
|
|
38
87
|
Example
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export type DocumentBatchCommittedItem = Readonly<{
|
|
2
|
+
/** Position in the input array captured when putMany was invoked. */
|
|
3
|
+
index: number;
|
|
4
|
+
hash: string;
|
|
5
|
+
}>;
|
|
6
|
+
export type DocumentBatchLocalCommit = "not-started" | "committed" | "indeterminate";
|
|
7
|
+
/**
|
|
8
|
+
* Failure of a putMany invocation with batching: "required". Local append
|
|
9
|
+
* evidence does not prove remote receipt, document projection completion, or
|
|
10
|
+
* an atomic storage transaction. An indeterminate outcome requires recovery
|
|
11
|
+
* and must never be treated as an empty committed set that is safe to retry.
|
|
12
|
+
*/
|
|
13
|
+
export declare class DocumentBatchCommitError extends Error {
|
|
14
|
+
readonly cause: unknown;
|
|
15
|
+
readonly localCommit: DocumentBatchLocalCommit;
|
|
16
|
+
readonly committedItems: readonly DocumentBatchCommittedItem[];
|
|
17
|
+
/** Safety of replaying this local append only; not application side effects. */
|
|
18
|
+
readonly retrySafe: boolean;
|
|
19
|
+
/** Unresolved local append outcome; false does not rule out projection repair. */
|
|
20
|
+
readonly recoveryRequired: boolean;
|
|
21
|
+
constructor(cause: unknown, localCommit: DocumentBatchLocalCommit, committedItems: readonly DocumentBatchCommittedItem[]);
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=batch-error.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"batch-error.d.ts","sourceRoot":"","sources":["../../src/batch-error.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,0BAA0B,GAAG,QAAQ,CAAC;IACjD,qEAAqE;IACrE,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;CACb,CAAC,CAAC;AAEH,MAAM,MAAM,wBAAwB,GACjC,aAAa,GACb,WAAW,GACX,eAAe,CAAC;AAEnB;;;;;GAKG;AACH,qBAAa,wBAAyB,SAAQ,KAAK;IAClD,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC;IACxB,QAAQ,CAAC,WAAW,EAAE,wBAAwB,CAAC;IAC/C,QAAQ,CAAC,cAAc,EAAE,SAAS,0BAA0B,EAAE,CAAC;IAC/D,gFAAgF;IAChF,QAAQ,CAAC,SAAS,EAAE,OAAO,CAAC;IAC5B,kFAAkF;IAClF,QAAQ,CAAC,gBAAgB,EAAE,OAAO,CAAC;gBAGlC,KAAK,EAAE,OAAO,EACd,WAAW,EAAE,wBAAwB,EACrC,cAAc,EAAE,SAAS,0BAA0B,EAAE;CAetD"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Failure of a putMany invocation with batching: "required". Local append
|
|
3
|
+
* evidence does not prove remote receipt, document projection completion, or
|
|
4
|
+
* an atomic storage transaction. An indeterminate outcome requires recovery
|
|
5
|
+
* and must never be treated as an empty committed set that is safe to retry.
|
|
6
|
+
*/
|
|
7
|
+
export class DocumentBatchCommitError extends Error {
|
|
8
|
+
cause;
|
|
9
|
+
localCommit;
|
|
10
|
+
committedItems;
|
|
11
|
+
/** Safety of replaying this local append only; not application side effects. */
|
|
12
|
+
retrySafe;
|
|
13
|
+
/** Unresolved local append outcome; false does not rule out projection repair. */
|
|
14
|
+
recoveryRequired;
|
|
15
|
+
constructor(cause, localCommit, committedItems) {
|
|
16
|
+
super(`Required document batch failed (${localCommit}): ${cause instanceof Error ? cause.message : String(cause)}`);
|
|
17
|
+
this.name = "DocumentBatchCommitError";
|
|
18
|
+
this.cause = cause;
|
|
19
|
+
this.localCommit = localCommit;
|
|
20
|
+
this.committedItems = Object.freeze(committedItems.map(({ index, hash }) => Object.freeze({ index, hash })));
|
|
21
|
+
this.retrySafe = localCommit === "not-started";
|
|
22
|
+
this.recoveryRequired = localCommit === "indeterminate";
|
|
23
|
+
Object.freeze(this);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=batch-error.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"batch-error.js","sourceRoot":"","sources":["../../src/batch-error.ts"],"names":[],"mappings":"AAWA;;;;;GAKG;AACH,MAAM,OAAO,wBAAyB,SAAQ,KAAK;IACzC,KAAK,CAAU;IACf,WAAW,CAA2B;IACtC,cAAc,CAAwC;IAC/D,gFAAgF;IACvE,SAAS,CAAU;IAC5B,kFAAkF;IACzE,gBAAgB,CAAU;IAEnC,YACC,KAAc,EACd,WAAqC,EACrC,cAAqD;QAErD,KAAK,CACJ,mCAAmC,WAAW,MAAM,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAC5G,CAAC;QACF,IAAI,CAAC,IAAI,GAAG,0BAA0B,CAAC;QACvC,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC;QAC/B,IAAI,CAAC,cAAc,GAAG,MAAM,CAAC,MAAM,CAClC,cAAc,CAAC,GAAG,CAAC,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC,CACvE,CAAC;QACF,IAAI,CAAC,SAAS,GAAG,WAAW,KAAK,aAAa,CAAC;QAC/C,IAAI,CAAC,gBAAgB,GAAG,WAAW,KAAK,eAAe,CAAC;QACxD,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;IACrB,CAAC;CACD"}
|
package/dist/src/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export * from "@peerbit/indexer-interface";
|
|
2
2
|
export * from "@peerbit/document-interface";
|
|
3
3
|
export * from "./program.js";
|
|
4
|
+
export * from "./batch-error.js";
|
|
4
5
|
export type { CanRead, CanSearch, DocumentIndex, WithContext, WithIndexedContext, WithIndexed, OpenOptions, GetOptions, QueryOptions, RemoteQueryOptions, ResultsIterator, SearchOptions, TransformOptions, TransformerAsConstructor, TransformerAsFunction, ValueTypeFromRequest, UpdateCallbacks, UpdateMergeStrategy, UpdateOptions, UpdateReason, WaitBehavior, WaitPolicy, ReachScope, PrefetchOptions, LateResultsEvent, JoiningOnMissedResults, JoiningTargets, JoiningTimeoutPolicy, } from "./search.js";
|
|
5
6
|
export { coerceWithContext, coerceWithIndexed } from "./search.js";
|
|
6
7
|
export * from "./operation.js";
|
package/dist/src/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,4BAA4B,CAAC;AAC3C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,cAAc,CAAC;AAC7B,YAAY,EACX,OAAO,EACP,SAAS,EACT,aAAa,EACb,WAAW,EACX,kBAAkB,EAClB,WAAW,EACX,WAAW,EACX,UAAU,EACV,YAAY,EACZ,kBAAkB,EAClB,eAAe,EACf,aAAa,EACb,gBAAgB,EAChB,wBAAwB,EACxB,qBAAqB,EACrB,oBAAoB,EACpB,eAAe,EACf,mBAAmB,EACnB,aAAa,EACb,YAAY,EACZ,YAAY,EACZ,UAAU,EACV,UAAU,EACV,eAAe,EACf,gBAAgB,EAChB,sBAAsB,EACtB,cAAc,EACd,oBAAoB,GACpB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AACnE,cAAc,gBAAgB,CAAC;AAC/B,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC3C,OAAO,EAAE,0BAA0B,EAAE,MAAM,YAAY,CAAC;AACxD,OAAO,EAAE,cAAc,IAAI,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AACrE,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EACN,KAAK,oBAAoB,EACzB,oBAAoB,EACpB,gCAAgC,GAChC,MAAM,aAAa,CAAC;AACrB,cAAc,aAAa,CAAC;AAC5B,YAAY,EACX,aAAa,EACb,yBAAyB,EACzB,kBAAkB,EAClB,kBAAkB,EAClB,2BAA2B,GAC3B,MAAM,WAAW,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,4BAA4B,CAAC;AAC3C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,cAAc,CAAC;AAC7B,cAAc,kBAAkB,CAAC;AACjC,YAAY,EACX,OAAO,EACP,SAAS,EACT,aAAa,EACb,WAAW,EACX,kBAAkB,EAClB,WAAW,EACX,WAAW,EACX,UAAU,EACV,YAAY,EACZ,kBAAkB,EAClB,eAAe,EACf,aAAa,EACb,gBAAgB,EAChB,wBAAwB,EACxB,qBAAqB,EACrB,oBAAoB,EACpB,eAAe,EACf,mBAAmB,EACnB,aAAa,EACb,YAAY,EACZ,YAAY,EACZ,UAAU,EACV,UAAU,EACV,eAAe,EACf,gBAAgB,EAChB,sBAAsB,EACtB,cAAc,EACd,oBAAoB,GACpB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AACnE,cAAc,gBAAgB,CAAC;AAC/B,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC3C,OAAO,EAAE,0BAA0B,EAAE,MAAM,YAAY,CAAC;AACxD,OAAO,EAAE,cAAc,IAAI,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AACrE,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EACN,KAAK,oBAAoB,EACzB,oBAAoB,EACpB,gCAAgC,GAChC,MAAM,aAAa,CAAC;AACrB,cAAc,aAAa,CAAC;AAC5B,YAAY,EACX,aAAa,EACb,yBAAyB,EACzB,kBAAkB,EAClB,kBAAkB,EAClB,2BAA2B,GAC3B,MAAM,WAAW,CAAC"}
|
package/dist/src/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export * from "@peerbit/indexer-interface";
|
|
2
2
|
export * from "@peerbit/document-interface";
|
|
3
3
|
export * from "./program.js";
|
|
4
|
+
export * from "./batch-error.js";
|
|
4
5
|
export { coerceWithContext, coerceWithIndexed } from "./search.js";
|
|
5
6
|
export * from "./operation.js";
|
|
6
7
|
export { policy } from "./policy.js";
|
package/dist/src/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,4BAA4B,CAAC;AAC3C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,cAAc,CAAC;AA+
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,4BAA4B,CAAC;AAC3C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,cAAc,CAAC;AAC7B,cAAc,kBAAkB,CAAC;AA+BjC,OAAO,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AACnE,cAAc,gBAAgB,CAAC;AAC/B,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC3C,OAAO,EAAE,0BAA0B,EAAE,MAAM,YAAY,CAAC;AACxD,OAAO,EAAE,cAAc,IAAI,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AACrE,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAEN,oBAAoB,EACpB,gCAAgC,GAChC,MAAM,aAAa,CAAC;AACrB,cAAc,aAAa,CAAC"}
|
package/dist/src/program.d.ts
CHANGED
|
@@ -69,6 +69,10 @@ type DocumentPutOptions = SharedAppendOptions<Operation> & {
|
|
|
69
69
|
replicate?: boolean;
|
|
70
70
|
checkRemote?: boolean;
|
|
71
71
|
};
|
|
72
|
+
export type DocumentPutManyOptions = DocumentPutOptions & {
|
|
73
|
+
/** Require a supported independent batch; never fall back to sequential puts. */
|
|
74
|
+
batching?: "required";
|
|
75
|
+
};
|
|
72
76
|
type DocumentPutResult = {
|
|
73
77
|
readonly entry: Entry<Operation>;
|
|
74
78
|
removed: ShallowOrFullEntry<Operation>[];
|
|
@@ -264,7 +268,7 @@ export declare class Documents<T, I extends Record<string, any> = T extends Reco
|
|
|
264
268
|
private deliverPersistedDocumentEntries;
|
|
265
269
|
private deliverPersistedDocumentAppendCommits;
|
|
266
270
|
private putCompatDocumentBackend;
|
|
267
|
-
putMany(docs: T[], options?:
|
|
271
|
+
putMany(docs: T[], options?: DocumentPutManyOptions): Promise<DocumentPutManyResult>;
|
|
268
272
|
private putManyCompatDocumentBackend;
|
|
269
273
|
private putManySequential;
|
|
270
274
|
private hasDuplicatePreparedPutKeys;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"program.d.ts","sourceRoot":"","sources":["../../src/program.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,KAAK,YAAY,EAMjB,MAAM,gBAAgB,CAAC;AAOxB,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAChE,OAAO,KAAK,YAAY,MAAM,4BAA4B,CAAC;AAC3D,OAAO,EACN,KAAK,MAAM,EACX,KAAK,EAKL,KAAK,kBAAkB,EAEvB,KAAK,WAAW,EAEhB,MAAM,cAAc,CAAC;AAEtB,OAAO,EAAE,OAAO,EAAE,KAAK,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAC/D,OAAO,EACN,KAAK,eAAe,
|
|
1
|
+
{"version":3,"file":"program.d.ts","sourceRoot":"","sources":["../../src/program.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,KAAK,YAAY,EAMjB,MAAM,gBAAgB,CAAC;AAOxB,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAChE,OAAO,KAAK,YAAY,MAAM,4BAA4B,CAAC;AAC3D,OAAO,EACN,KAAK,MAAM,EACX,KAAK,EAKL,KAAK,kBAAkB,EAEvB,KAAK,WAAW,EAEhB,MAAM,cAAc,CAAC;AAEtB,OAAO,EAAE,OAAO,EAAE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EAAE,YAAY,CAAC,OAAO,GAAG,YAAY,CAAC,KAAK,EAC7C,OAAO,CAAC,EAAE,mBAAmB,CAAC,SAAS,CAAC;YA2B3B,wBAAwB;YA2CxB,wBAAwB;YA0BxB,oCAAoC;IAwH5C,aAAa,CAClB,MAAM,EAAE,MAAM,CAAC,SAAS,CAAC,EACzB,SAAS,CAAC,EAAE,kBAAkB,CAAC,CAAC,EAAE,CAAC,CAAC,GAClC,OAAO,CAAC,IAAI,CAAC;YAeF,oBAAoB;IA0QlC;;;;;OAKG;IACG,KAAK,CAAC,OAAO,CAAC,EAAE;QACrB,KAAK,CAAC,EAAE,YAAY,CAAC,KAAK,GAAG,YAAY,CAAC,SAAS,CAAC;QACpD,WAAW,CAAC,EAAE,KAAK,GAAG,SAAS,CAAC;KAChC,GAAG,OAAO,CAAC,MAAM,CAAC;IACb,KAAK,CAAC,OAAO,EAAE;QACpB,KAAK,CAAC,EAAE,YAAY,CAAC,KAAK,GAAG,YAAY,CAAC,SAAS,CAAC;QACpD,WAAW,EAAE,IAAI,GAAG;YAAE,KAAK,CAAC,EAAE,UAAU,CAAA;SAAE,CAAC;KAC3C,GAAG,OAAO,CAAC,aAAa,CAAC;CAqG1B"}
|
package/dist/src/program.js
CHANGED
|
@@ -39,7 +39,8 @@ import * as indexerTypes from "@peerbit/indexer-interface";
|
|
|
39
39
|
import { Entry, EntryType, LamportClock, ShallowEntry, ShallowMeta, Timestamp, entryV0PlainPayloadDataFromStorage, } from "@peerbit/log";
|
|
40
40
|
import { logger as loggerFn } from "@peerbit/logger";
|
|
41
41
|
import { Program } from "@peerbit/program";
|
|
42
|
-
import { PersistedDeliveryError, SharedLog, } from "@peerbit/shared-log";
|
|
42
|
+
import { NativeDurableCommitError, PersistedDeliveryError, SharedLog, } from "@peerbit/shared-log";
|
|
43
|
+
import { DocumentBatchCommitError } from "./batch-error.js";
|
|
43
44
|
import { detachCanPerformCallbackProperties, detachEntryForCallback, detachEntryPayloadForCallback, } from "./callback-detachment.js";
|
|
44
45
|
import { MAX_BATCH_SIZE } from "./constants.js";
|
|
45
46
|
import { extractDocumentFieldSimple, initializeDocumentRust, planDocumentContext, planDocumentContextBatch, tryPlanDocumentContext, tryPlanDocumentContextBatch, } from "./native-rust.js";
|
|
@@ -201,8 +202,8 @@ class CompatDocumentBackend {
|
|
|
201
202
|
put(doc, options) {
|
|
202
203
|
return this.putImpl(doc, options);
|
|
203
204
|
}
|
|
204
|
-
putMany(docs, options) {
|
|
205
|
-
return this.putManyImpl(docs, options);
|
|
205
|
+
putMany(docs, options, batch) {
|
|
206
|
+
return this.putManyImpl(docs, options, batch);
|
|
206
207
|
}
|
|
207
208
|
del(id, options) {
|
|
208
209
|
return this.deleteImpl(id, options);
|
|
@@ -274,7 +275,7 @@ class NativeDocumentBackend {
|
|
|
274
275
|
}
|
|
275
276
|
return assertPolicyAndCommit();
|
|
276
277
|
}
|
|
277
|
-
async putMany(docs, options) {
|
|
278
|
+
async putMany(docs, options, batch) {
|
|
278
279
|
if (docs.length === 0) {
|
|
279
280
|
return { entries: [], removed: [] };
|
|
280
281
|
}
|
|
@@ -282,8 +283,10 @@ class NativeDocumentBackend {
|
|
|
282
283
|
for (const doc of docs) {
|
|
283
284
|
this.context.assertPlainPutSupported(doc, putOptions);
|
|
284
285
|
}
|
|
285
|
-
const prepared = docs.map((doc) => this.context.preparePlainPut(doc));
|
|
286
|
+
const prepared = batch?.prepared ?? docs.map((doc) => this.context.preparePlainPut(doc));
|
|
286
287
|
if (this.context.hasDuplicatePreparedPutKeys(prepared)) {
|
|
288
|
+
if (batch)
|
|
289
|
+
throw new Error("Required putMany batching requires distinct document keys");
|
|
287
290
|
if (hasPersistedDelivery(options)) {
|
|
288
291
|
throw this.context.nativeModeError("requires distinct document keys for persisted putMany");
|
|
289
292
|
}
|
|
@@ -362,6 +365,7 @@ class NativeDocumentBackend {
|
|
|
362
365
|
resolveTrimmedEntries: this.context.shouldResolveTrimmedEntries(),
|
|
363
366
|
options: putOptions,
|
|
364
367
|
useNativeExistingDocumentContext,
|
|
368
|
+
batch,
|
|
365
369
|
}), (documentAppendCommit) => {
|
|
366
370
|
if (!documentAppendCommit) {
|
|
367
371
|
throw this.context.nativeModeError("requires native batched payload append support");
|
|
@@ -1980,8 +1984,11 @@ let Documents = (() => {
|
|
|
1980
1984
|
operation,
|
|
1981
1985
|
};
|
|
1982
1986
|
}
|
|
1983
|
-
preparePlainPut(doc) {
|
|
1984
|
-
const
|
|
1987
|
+
preparePlainPut(doc, capture = false) {
|
|
1988
|
+
const resolvedKey = this.idResolver(doc);
|
|
1989
|
+
const keyValue = capture && ArrayBuffer.isView(resolvedKey)
|
|
1990
|
+
? new Uint8Array(new Uint8Array(resolvedKey.buffer, resolvedKey.byteOffset, resolvedKey.byteLength))
|
|
1991
|
+
: resolvedKey;
|
|
1985
1992
|
indexerTypes.checkId(keyValue);
|
|
1986
1993
|
const documentBytes = serialize(doc);
|
|
1987
1994
|
if (documentBytes.length > MAX_BATCH_SIZE) {
|
|
@@ -1989,7 +1996,9 @@ let Documents = (() => {
|
|
|
1989
1996
|
}
|
|
1990
1997
|
const operationPayloadBytes = encodePutOperationPayload(documentBytes);
|
|
1991
1998
|
return {
|
|
1992
|
-
document:
|
|
1999
|
+
document: capture
|
|
2000
|
+
? this._index.valueEncoding.decoder(documentBytes)
|
|
2001
|
+
: doc,
|
|
1993
2002
|
encodedDocument: operationPayloadBytes.subarray(PUT_OPERATION_PREFIX_LENGTH),
|
|
1994
2003
|
operationPayloadBytes,
|
|
1995
2004
|
keyValue,
|
|
@@ -2091,49 +2100,88 @@ let Documents = (() => {
|
|
|
2091
2100
|
return appended;
|
|
2092
2101
|
}
|
|
2093
2102
|
async putMany(docs, options) {
|
|
2094
|
-
|
|
2095
|
-
|
|
2096
|
-
|
|
2097
|
-
|
|
2103
|
+
const batching = options?.batching;
|
|
2104
|
+
if (batching !== undefined && batching !== "required") {
|
|
2105
|
+
throw new Error('Unsupported putMany batching mode; expected "required"');
|
|
2106
|
+
}
|
|
2107
|
+
const batch = batching === "required"
|
|
2108
|
+
? { prepared: [], committedHashes: new Set(), appendStarted: false }
|
|
2109
|
+
: undefined;
|
|
2110
|
+
try {
|
|
2111
|
+
if (batch)
|
|
2112
|
+
docs = docs.slice();
|
|
2113
|
+
options = asTrustedDocumentSharedLog(this.log).snapshotDocumentAppendOptions(options, this.isNativeMode() && docs.length > 0
|
|
2114
|
+
? (capturedOptions) => {
|
|
2115
|
+
if (capturedOptions.encryption) {
|
|
2116
|
+
this.assertNativeModePlainPutSupported(docs[0], capturedOptions);
|
|
2117
|
+
}
|
|
2098
2118
|
}
|
|
2119
|
+
: undefined);
|
|
2120
|
+
if (batch) {
|
|
2121
|
+
if (Program.isPrototypeOf(this._clazz)) {
|
|
2122
|
+
throw new Error("Required putMany batching does not support program-valued documents");
|
|
2123
|
+
}
|
|
2124
|
+
// Capture every encoded value and key before the first asynchronous
|
|
2125
|
+
// operation, then reuse these bytes in the ordinary native batch path.
|
|
2126
|
+
batch.prepared = docs.map((doc) => this.preparePlainPut(doc, true));
|
|
2127
|
+
docs = batch.prepared.map(({ document }) => document);
|
|
2128
|
+
}
|
|
2129
|
+
const persistedRequested = hasPersistedDelivery(options);
|
|
2130
|
+
const result = await this._documentBackend.putMany(docs, options, batch);
|
|
2131
|
+
if (!persistedRequested) {
|
|
2132
|
+
return result;
|
|
2133
|
+
}
|
|
2134
|
+
const appendDelivery = persistedDocumentAppendDelivery.get(result);
|
|
2135
|
+
if (appendDelivery) {
|
|
2136
|
+
persistedDocumentAppendDelivery.delete(result);
|
|
2137
|
+
await this.deliverPersistedDocumentAppendCommits(appendDelivery, options);
|
|
2138
|
+
let entries;
|
|
2139
|
+
return {
|
|
2140
|
+
get entries() {
|
|
2141
|
+
return (entries ??= result.entries);
|
|
2142
|
+
},
|
|
2143
|
+
removed: result.removed,
|
|
2144
|
+
};
|
|
2099
2145
|
}
|
|
2100
|
-
|
|
2101
|
-
|
|
2102
|
-
|
|
2103
|
-
|
|
2104
|
-
|
|
2105
|
-
|
|
2106
|
-
const appendDelivery = persistedDocumentAppendDelivery.get(result);
|
|
2107
|
-
if (appendDelivery) {
|
|
2108
|
-
persistedDocumentAppendDelivery.delete(result);
|
|
2109
|
-
await this.deliverPersistedDocumentAppendCommits(appendDelivery, options);
|
|
2110
|
-
let entries;
|
|
2111
|
-
return {
|
|
2112
|
-
get entries() {
|
|
2113
|
-
return (entries ??= result.entries);
|
|
2114
|
-
},
|
|
2115
|
-
removed: result.removed,
|
|
2116
|
-
};
|
|
2117
|
-
}
|
|
2118
|
-
const entries = result.entries;
|
|
2119
|
-
if (entries.length === 0) {
|
|
2120
|
-
return result;
|
|
2146
|
+
const entries = result.entries;
|
|
2147
|
+
if (entries.length === 0) {
|
|
2148
|
+
return result;
|
|
2149
|
+
}
|
|
2150
|
+
await this.deliverPersistedDocumentEntries(entries, options);
|
|
2151
|
+
return { entries, removed: result.removed };
|
|
2121
2152
|
}
|
|
2122
|
-
|
|
2123
|
-
|
|
2124
|
-
|
|
2125
|
-
|
|
2153
|
+
catch (error) {
|
|
2154
|
+
if (!batch)
|
|
2155
|
+
throw error;
|
|
2156
|
+
const hashes = [...batch.committedHashes];
|
|
2157
|
+
// The trusted independent-batch seam emits all hashes in input order.
|
|
2158
|
+
// Never invent indexes from incomplete or contradictory batch evidence.
|
|
2159
|
+
const complete = hashes.length === batch.prepared.length && hashes.length > 0;
|
|
2160
|
+
const cause = error instanceof PersistedDeliveryError ? error.cause : error;
|
|
2161
|
+
const localCommit = complete && !(cause instanceof NativeDurableCommitError)
|
|
2162
|
+
? "committed"
|
|
2163
|
+
: batch.appendStarted || hashes.length > 0
|
|
2164
|
+
? "indeterminate"
|
|
2165
|
+
: "not-started";
|
|
2166
|
+
throw new DocumentBatchCommitError(error, localCommit, complete ? hashes.map((hash, index) => ({ index, hash })) : []);
|
|
2167
|
+
}
|
|
2168
|
+
}
|
|
2169
|
+
async putManyCompatDocumentBackend(docs, options, batch) {
|
|
2126
2170
|
if (docs.length === 0) {
|
|
2127
2171
|
return { entries: [], removed: [] };
|
|
2128
2172
|
}
|
|
2129
2173
|
if (!this.canUsePlainPutManyFastPath(docs, options)) {
|
|
2174
|
+
if (batch)
|
|
2175
|
+
throw new Error("Required putMany batching requires the independent batched document path");
|
|
2130
2176
|
if (hasPersistedDelivery(options)) {
|
|
2131
2177
|
throw new Error("persisted putMany requires the independent batched document path");
|
|
2132
2178
|
}
|
|
2133
2179
|
return this.putManySequential(docs, options);
|
|
2134
2180
|
}
|
|
2135
|
-
const prepared = docs.map((doc) => this.preparePlainPut(doc));
|
|
2181
|
+
const prepared = batch?.prepared ?? docs.map((doc) => this.preparePlainPut(doc));
|
|
2136
2182
|
if (this.hasDuplicatePreparedPutKeys(prepared)) {
|
|
2183
|
+
if (batch)
|
|
2184
|
+
throw new Error("Required putMany batching requires distinct document keys");
|
|
2137
2185
|
if (hasPersistedDelivery(options)) {
|
|
2138
2186
|
throw new Error("persisted putMany requires distinct document keys");
|
|
2139
2187
|
}
|
|
@@ -2150,8 +2198,11 @@ let Documents = (() => {
|
|
|
2150
2198
|
})),
|
|
2151
2199
|
resolveTrimmedEntries: !this._index.canGetIdentityIndexedByHead(),
|
|
2152
2200
|
options,
|
|
2201
|
+
batch,
|
|
2153
2202
|
});
|
|
2154
2203
|
if (!documentAppendCommit) {
|
|
2204
|
+
if (batch)
|
|
2205
|
+
throw new Error("Required putMany batching requires native batched payload append support");
|
|
2155
2206
|
if (hasPersistedDelivery(options)) {
|
|
2156
2207
|
throw new Error("persisted putMany requires native batched payload append support");
|
|
2157
2208
|
}
|
|
@@ -2446,6 +2497,9 @@ let Documents = (() => {
|
|
|
2446
2497
|
return await runAfterDocumentCommit(input.options, appended.appendCommit.hash, () => this.createDocumentAppendCommitFacts(input, appended, nativeBackboneDocumentIndex));
|
|
2447
2498
|
}
|
|
2448
2499
|
async commitNativeDocumentAppendMany(input) {
|
|
2500
|
+
if (input.batch) {
|
|
2501
|
+
return this.commitNativeDocumentAppendManyWithEvidence(input, input.batch);
|
|
2502
|
+
}
|
|
2449
2503
|
if (!hasPersistedDelivery(input.options)) {
|
|
2450
2504
|
return this.commitNativeDocumentAppendManyWithEvidence(input, undefined);
|
|
2451
2505
|
}
|
|
@@ -2471,7 +2525,11 @@ let Documents = (() => {
|
|
|
2471
2525
|
}
|
|
2472
2526
|
return [next];
|
|
2473
2527
|
});
|
|
2474
|
-
const
|
|
2528
|
+
const payloads = input.puts.map((put) => put.operationPayloadBytes);
|
|
2529
|
+
const appendOptions = withoutPersistedDelivery(input.options);
|
|
2530
|
+
if (input.batch)
|
|
2531
|
+
input.batch.appendStarted = true;
|
|
2532
|
+
const appended = await trustedLog.appendLocallyPreparedPayloadsManyIndependent(payloads, appendOptions, {
|
|
2475
2533
|
resolveTrimmedEntries: input.resolveTrimmedEntries,
|
|
2476
2534
|
nexts,
|
|
2477
2535
|
nativeBackboneDocumentIndexes: nativeBackboneDocumentIndexInputs,
|
|
@@ -2479,6 +2537,8 @@ let Documents = (() => {
|
|
|
2479
2537
|
...(localCommitEvidence ? { localCommitEvidence } : undefined),
|
|
2480
2538
|
});
|
|
2481
2539
|
if (!appended) {
|
|
2540
|
+
// An unsupported lower append can already have prepared native state.
|
|
2541
|
+
// Absence of success evidence cannot prove that replay is safe.
|
|
2482
2542
|
if (this.isNativeMode()) {
|
|
2483
2543
|
throw this.nativeModeError("requires native batched payload append support");
|
|
2484
2544
|
}
|