@agent-teams/repository-mutation 0.0.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 +5 -0
- package/LICENSE +201 -0
- package/README.md +10 -0
- package/dist/canonical-json.d.ts +12 -0
- package/dist/canonical-json.d.ts.map +1 -0
- package/dist/canonical-json.js +137 -0
- package/dist/canonical-json.js.map +1 -0
- package/dist/errors.d.ts +6 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +9 -0
- package/dist/errors.js.map +1 -0
- package/dist/index.d.ts +25 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +13 -0
- package/dist/index.js.map +1 -0
- package/dist/installed-artifact-identity.d.ts +15 -0
- package/dist/installed-artifact-identity.d.ts.map +1 -0
- package/dist/installed-artifact-identity.js +127 -0
- package/dist/installed-artifact-identity.js.map +1 -0
- package/dist/node.d.ts +29 -0
- package/dist/node.d.ts.map +1 -0
- package/dist/node.js +19 -0
- package/dist/node.js.map +1 -0
- package/dist/package-version.d.ts +3 -0
- package/dist/package-version.d.ts.map +1 -0
- package/dist/package-version.js +11 -0
- package/dist/package-version.js.map +1 -0
- package/dist/qualification/index.d.ts +24 -0
- package/dist/qualification/index.d.ts.map +1 -0
- package/dist/qualification/index.js +11 -0
- package/dist/qualification/index.js.map +1 -0
- package/dist/repository-mutation/adapters/node/node-absent-file-publication-private.d.ts +19 -0
- package/dist/repository-mutation/adapters/node/node-absent-file-publication-private.d.ts.map +1 -0
- package/dist/repository-mutation/adapters/node/node-absent-file-publication-private.js +74 -0
- package/dist/repository-mutation/adapters/node/node-absent-file-publication-private.js.map +1 -0
- package/dist/repository-mutation/adapters/node/node-absent-file-publication.d.ts +35 -0
- package/dist/repository-mutation/adapters/node/node-absent-file-publication.d.ts.map +1 -0
- package/dist/repository-mutation/adapters/node/node-absent-file-publication.js +181 -0
- package/dist/repository-mutation/adapters/node/node-absent-file-publication.js.map +1 -0
- package/dist/repository-mutation/adapters/node/node-bounded-regular-file.d.ts +23 -0
- package/dist/repository-mutation/adapters/node/node-bounded-regular-file.d.ts.map +1 -0
- package/dist/repository-mutation/adapters/node/node-bounded-regular-file.js +134 -0
- package/dist/repository-mutation/adapters/node/node-bounded-regular-file.js.map +1 -0
- package/dist/repository-mutation/adapters/node/node-cleanup-owned-temporary.d.ts +26 -0
- package/dist/repository-mutation/adapters/node/node-cleanup-owned-temporary.d.ts.map +1 -0
- package/dist/repository-mutation/adapters/node/node-cleanup-owned-temporary.js +172 -0
- package/dist/repository-mutation/adapters/node/node-cleanup-owned-temporary.js.map +1 -0
- package/dist/repository-mutation/adapters/node/node-create-and-bind-directory.d.ts +14 -0
- package/dist/repository-mutation/adapters/node/node-create-and-bind-directory.d.ts.map +1 -0
- package/dist/repository-mutation/adapters/node/node-create-and-bind-directory.js +23 -0
- package/dist/repository-mutation/adapters/node/node-create-and-bind-directory.js.map +1 -0
- package/dist/repository-mutation/adapters/node/node-directory-durability.d.ts +17 -0
- package/dist/repository-mutation/adapters/node/node-directory-durability.d.ts.map +1 -0
- package/dist/repository-mutation/adapters/node/node-directory-durability.js +47 -0
- package/dist/repository-mutation/adapters/node/node-directory-durability.js.map +1 -0
- package/dist/repository-mutation/adapters/node/node-directory-materialization.d.ts +37 -0
- package/dist/repository-mutation/adapters/node/node-directory-materialization.d.ts.map +1 -0
- package/dist/repository-mutation/adapters/node/node-directory-materialization.js +244 -0
- package/dist/repository-mutation/adapters/node/node-directory-materialization.js.map +1 -0
- package/dist/repository-mutation/adapters/node/node-existing-repository-ancestors.d.ts +13 -0
- package/dist/repository-mutation/adapters/node/node-existing-repository-ancestors.d.ts.map +1 -0
- package/dist/repository-mutation/adapters/node/node-existing-repository-ancestors.js +67 -0
- package/dist/repository-mutation/adapters/node/node-existing-repository-ancestors.js.map +1 -0
- package/dist/repository-mutation/adapters/node/node-known-file-apply-effects.d.ts +84 -0
- package/dist/repository-mutation/adapters/node/node-known-file-apply-effects.d.ts.map +1 -0
- package/dist/repository-mutation/adapters/node/node-known-file-apply-effects.js +232 -0
- package/dist/repository-mutation/adapters/node/node-known-file-apply-effects.js.map +1 -0
- package/dist/repository-mutation/adapters/node/node-known-file-apply-faults.d.ts +9 -0
- package/dist/repository-mutation/adapters/node/node-known-file-apply-faults.d.ts.map +1 -0
- package/dist/repository-mutation/adapters/node/node-known-file-apply-faults.js +2 -0
- package/dist/repository-mutation/adapters/node/node-known-file-apply-faults.js.map +1 -0
- package/dist/repository-mutation/adapters/node/node-known-file-apply-observation.d.ts +6 -0
- package/dist/repository-mutation/adapters/node/node-known-file-apply-observation.d.ts.map +1 -0
- package/dist/repository-mutation/adapters/node/node-known-file-apply-observation.js +30 -0
- package/dist/repository-mutation/adapters/node/node-known-file-apply-observation.js.map +1 -0
- package/dist/repository-mutation/adapters/node/node-known-file-apply-operation.d.ts +11 -0
- package/dist/repository-mutation/adapters/node/node-known-file-apply-operation.d.ts.map +1 -0
- package/dist/repository-mutation/adapters/node/node-known-file-apply-operation.js +159 -0
- package/dist/repository-mutation/adapters/node/node-known-file-apply-operation.js.map +1 -0
- package/dist/repository-mutation/adapters/node/node-known-file-apply-state.d.ts +9 -0
- package/dist/repository-mutation/adapters/node/node-known-file-apply-state.d.ts.map +1 -0
- package/dist/repository-mutation/adapters/node/node-known-file-apply-state.js +22 -0
- package/dist/repository-mutation/adapters/node/node-known-file-apply-state.js.map +1 -0
- package/dist/repository-mutation/adapters/node/node-known-file-recovery-cleanup.d.ts +9 -0
- package/dist/repository-mutation/adapters/node/node-known-file-recovery-cleanup.d.ts.map +1 -0
- package/dist/repository-mutation/adapters/node/node-known-file-recovery-cleanup.js +203 -0
- package/dist/repository-mutation/adapters/node/node-known-file-recovery-cleanup.js.map +1 -0
- package/dist/repository-mutation/adapters/node/node-known-file-recovery-executor.d.ts +17 -0
- package/dist/repository-mutation/adapters/node/node-known-file-recovery-executor.d.ts.map +1 -0
- package/dist/repository-mutation/adapters/node/node-known-file-recovery-executor.js +22 -0
- package/dist/repository-mutation/adapters/node/node-known-file-recovery-executor.js.map +1 -0
- package/dist/repository-mutation/adapters/node/node-known-file-recovery-filesystem.d.ts +28 -0
- package/dist/repository-mutation/adapters/node/node-known-file-recovery-filesystem.d.ts.map +1 -0
- package/dist/repository-mutation/adapters/node/node-known-file-recovery-filesystem.js +213 -0
- package/dist/repository-mutation/adapters/node/node-known-file-recovery-filesystem.js.map +1 -0
- package/dist/repository-mutation/adapters/node/node-known-file-recovery-observation.d.ts +15 -0
- package/dist/repository-mutation/adapters/node/node-known-file-recovery-observation.d.ts.map +1 -0
- package/dist/repository-mutation/adapters/node/node-known-file-recovery-observation.js +51 -0
- package/dist/repository-mutation/adapters/node/node-known-file-recovery-observation.js.map +1 -0
- package/dist/repository-mutation/adapters/node/node-known-file-recovery-preimage-captured-cleanup.d.ts +29 -0
- package/dist/repository-mutation/adapters/node/node-known-file-recovery-preimage-captured-cleanup.d.ts.map +1 -0
- package/dist/repository-mutation/adapters/node/node-known-file-recovery-preimage-captured-cleanup.js +72 -0
- package/dist/repository-mutation/adapters/node/node-known-file-recovery-preimage-captured-cleanup.js.map +1 -0
- package/dist/repository-mutation/adapters/node/node-known-file-recovery-preimage-captured.d.ts +31 -0
- package/dist/repository-mutation/adapters/node/node-known-file-recovery-preimage-captured.d.ts.map +1 -0
- package/dist/repository-mutation/adapters/node/node-known-file-recovery-preimage-captured.js +254 -0
- package/dist/repository-mutation/adapters/node/node-known-file-recovery-preimage-captured.js.map +1 -0
- package/dist/repository-mutation/adapters/node/node-known-file-recovery-preimage.d.ts +13 -0
- package/dist/repository-mutation/adapters/node/node-known-file-recovery-preimage.d.ts.map +1 -0
- package/dist/repository-mutation/adapters/node/node-known-file-recovery-preimage.js +210 -0
- package/dist/repository-mutation/adapters/node/node-known-file-recovery-preimage.js.map +1 -0
- package/dist/repository-mutation/adapters/node/node-known-file-recovery-retirement.d.ts +15 -0
- package/dist/repository-mutation/adapters/node/node-known-file-recovery-retirement.d.ts.map +1 -0
- package/dist/repository-mutation/adapters/node/node-known-file-recovery-retirement.js +181 -0
- package/dist/repository-mutation/adapters/node/node-known-file-recovery-retirement.js.map +1 -0
- package/dist/repository-mutation/adapters/node/node-known-file-recovery-state.d.ts +12 -0
- package/dist/repository-mutation/adapters/node/node-known-file-recovery-state.d.ts.map +1 -0
- package/dist/repository-mutation/adapters/node/node-known-file-recovery-state.js +18 -0
- package/dist/repository-mutation/adapters/node/node-known-file-recovery-state.js.map +1 -0
- package/dist/repository-mutation/adapters/node/node-known-file-transaction-filesystem.d.ts +25 -0
- package/dist/repository-mutation/adapters/node/node-known-file-transaction-filesystem.d.ts.map +1 -0
- package/dist/repository-mutation/adapters/node/node-known-file-transaction-filesystem.js +150 -0
- package/dist/repository-mutation/adapters/node/node-known-file-transaction-filesystem.js.map +1 -0
- package/dist/repository-mutation/adapters/node/node-known-file-transaction-inspection.d.ts +12 -0
- package/dist/repository-mutation/adapters/node/node-known-file-transaction-inspection.d.ts.map +1 -0
- package/dist/repository-mutation/adapters/node/node-known-file-transaction-inspection.js +56 -0
- package/dist/repository-mutation/adapters/node/node-known-file-transaction-inspection.js.map +1 -0
- package/dist/repository-mutation/adapters/node/node-known-file-transaction-journal-store.d.ts +22 -0
- package/dist/repository-mutation/adapters/node/node-known-file-transaction-journal-store.d.ts.map +1 -0
- package/dist/repository-mutation/adapters/node/node-known-file-transaction-journal-store.js +246 -0
- package/dist/repository-mutation/adapters/node/node-known-file-transaction-journal-store.js.map +1 -0
- package/dist/repository-mutation/adapters/node/node-known-file-transaction-lease-release.d.ts +21 -0
- package/dist/repository-mutation/adapters/node/node-known-file-transaction-lease-release.d.ts.map +1 -0
- package/dist/repository-mutation/adapters/node/node-known-file-transaction-lease-release.js +34 -0
- package/dist/repository-mutation/adapters/node/node-known-file-transaction-lease-release.js.map +1 -0
- package/dist/repository-mutation/adapters/node/node-known-file-transaction-receipt.d.ts +4 -0
- package/dist/repository-mutation/adapters/node/node-known-file-transaction-receipt.d.ts.map +1 -0
- package/dist/repository-mutation/adapters/node/node-known-file-transaction-receipt.js +43 -0
- package/dist/repository-mutation/adapters/node/node-known-file-transaction-receipt.js.map +1 -0
- package/dist/repository-mutation/adapters/node/node-known-file-transaction-recovery.d.ts +14 -0
- package/dist/repository-mutation/adapters/node/node-known-file-transaction-recovery.d.ts.map +1 -0
- package/dist/repository-mutation/adapters/node/node-known-file-transaction-recovery.js +109 -0
- package/dist/repository-mutation/adapters/node/node-known-file-transaction-recovery.js.map +1 -0
- package/dist/repository-mutation/adapters/node/node-known-file-transaction.d.ts +21 -0
- package/dist/repository-mutation/adapters/node/node-known-file-transaction.d.ts.map +1 -0
- package/dist/repository-mutation/adapters/node/node-known-file-transaction.js +215 -0
- package/dist/repository-mutation/adapters/node/node-known-file-transaction.js.map +1 -0
- package/dist/repository-mutation/adapters/node/node-prepare-exact-sibling-temporary.d.ts +18 -0
- package/dist/repository-mutation/adapters/node/node-prepare-exact-sibling-temporary.d.ts.map +1 -0
- package/dist/repository-mutation/adapters/node/node-prepare-exact-sibling-temporary.js +30 -0
- package/dist/repository-mutation/adapters/node/node-prepare-exact-sibling-temporary.js.map +1 -0
- package/dist/repository-mutation/adapters/node/node-publish-prepared-absent-file.d.ts +31 -0
- package/dist/repository-mutation/adapters/node/node-publish-prepared-absent-file.d.ts.map +1 -0
- package/dist/repository-mutation/adapters/node/node-publish-prepared-absent-file.js +50 -0
- package/dist/repository-mutation/adapters/node/node-publish-prepared-absent-file.js.map +1 -0
- package/dist/repository-mutation/adapters/node/node-repository-path.d.ts +2 -0
- package/dist/repository-mutation/adapters/node/node-repository-path.d.ts.map +1 -0
- package/dist/repository-mutation/adapters/node/node-repository-path.js +7 -0
- package/dist/repository-mutation/adapters/node/node-repository-path.js.map +1 -0
- package/dist/repository-mutation/adapters/node/node-terminal-evidence-directory.d.ts +21 -0
- package/dist/repository-mutation/adapters/node/node-terminal-evidence-directory.d.ts.map +1 -0
- package/dist/repository-mutation/adapters/node/node-terminal-evidence-directory.js +59 -0
- package/dist/repository-mutation/adapters/node/node-terminal-evidence-directory.js.map +1 -0
- package/dist/repository-mutation/application/model/directory-materialization.d.ts +35 -0
- package/dist/repository-mutation/application/model/directory-materialization.d.ts.map +1 -0
- package/dist/repository-mutation/application/model/directory-materialization.js +11 -0
- package/dist/repository-mutation/application/model/directory-materialization.js.map +1 -0
- package/dist/repository-mutation/application/model/exact-postimage.d.ts +17 -0
- package/dist/repository-mutation/application/model/exact-postimage.d.ts.map +1 -0
- package/dist/repository-mutation/application/model/exact-postimage.js +11 -0
- package/dist/repository-mutation/application/model/exact-postimage.js.map +1 -0
- package/dist/repository-mutation/application/model/known-file-transaction-journal.d.ts +69 -0
- package/dist/repository-mutation/application/model/known-file-transaction-journal.d.ts.map +1 -0
- package/dist/repository-mutation/application/model/known-file-transaction-journal.js +15 -0
- package/dist/repository-mutation/application/model/known-file-transaction-journal.js.map +1 -0
- package/dist/repository-mutation/application/model/known-file-transaction.d.ts +64 -0
- package/dist/repository-mutation/application/model/known-file-transaction.d.ts.map +1 -0
- package/dist/repository-mutation/application/model/known-file-transaction.js +2 -0
- package/dist/repository-mutation/application/model/known-file-transaction.js.map +1 -0
- package/dist/repository-mutation/application/model/path-identity.d.ts +7 -0
- package/dist/repository-mutation/application/model/path-identity.d.ts.map +1 -0
- package/dist/repository-mutation/application/model/path-identity.js +2 -0
- package/dist/repository-mutation/application/model/path-identity.js.map +1 -0
- package/dist/repository-mutation/application/model/repository-path.d.ts +8 -0
- package/dist/repository-mutation/application/model/repository-path.d.ts.map +1 -0
- package/dist/repository-mutation/application/model/repository-path.js +74 -0
- package/dist/repository-mutation/application/model/repository-path.js.map +1 -0
- package/dist/repository-mutation/application/policies/classify-known-file-recovery-transition.d.ts +33 -0
- package/dist/repository-mutation/application/policies/classify-known-file-recovery-transition.d.ts.map +1 -0
- package/dist/repository-mutation/application/policies/classify-known-file-recovery-transition.js +21 -0
- package/dist/repository-mutation/application/policies/classify-known-file-recovery-transition.js.map +1 -0
- package/dist/repository-mutation/application/policies/known-file-transaction-envelope.d.ts +9 -0
- package/dist/repository-mutation/application/policies/known-file-transaction-envelope.d.ts.map +1 -0
- package/dist/repository-mutation/application/policies/known-file-transaction-envelope.js +214 -0
- package/dist/repository-mutation/application/policies/known-file-transaction-envelope.js.map +1 -0
- package/dist/repository-mutation/application/policies/known-file-transaction-plan.d.ts +7 -0
- package/dist/repository-mutation/application/policies/known-file-transaction-plan.d.ts.map +1 -0
- package/dist/repository-mutation/application/policies/known-file-transaction-plan.js +253 -0
- package/dist/repository-mutation/application/policies/known-file-transaction-plan.js.map +1 -0
- package/dist/repository-mutation/application/ports/owned-temporary-cleanup-transition.d.ts +7 -0
- package/dist/repository-mutation/application/ports/owned-temporary-cleanup-transition.d.ts.map +1 -0
- package/dist/repository-mutation/application/ports/owned-temporary-cleanup-transition.js +2 -0
- package/dist/repository-mutation/application/ports/owned-temporary-cleanup-transition.js.map +1 -0
- package/dist/repository-mutation-envelope.d.ts +32 -0
- package/dist/repository-mutation-envelope.d.ts.map +1 -0
- package/dist/repository-mutation-envelope.js +292 -0
- package/dist/repository-mutation-envelope.js.map +1 -0
- package/dist/state-contract.d.ts +6 -0
- package/dist/state-contract.d.ts.map +1 -0
- package/dist/state-contract.js +6 -0
- package/dist/state-contract.js.map +1 -0
- package/dist/strict-json.d.ts +7 -0
- package/dist/strict-json.d.ts.map +1 -0
- package/dist/strict-json.js +131 -0
- package/dist/strict-json.js.map +1 -0
- package/dist/transaction-coordination/adapters/node/node-journal-slot-evidence.d.ts +29 -0
- package/dist/transaction-coordination/adapters/node/node-journal-slot-evidence.d.ts.map +1 -0
- package/dist/transaction-coordination/adapters/node/node-journal-slot-evidence.js +139 -0
- package/dist/transaction-coordination/adapters/node/node-journal-slot-evidence.js.map +1 -0
- package/dist/transaction-coordination/adapters/node/node-journal-slot-profile.d.ts +151 -0
- package/dist/transaction-coordination/adapters/node/node-journal-slot-profile.d.ts.map +1 -0
- package/dist/transaction-coordination/adapters/node/node-journal-slot-profile.js +29 -0
- package/dist/transaction-coordination/adapters/node/node-journal-slot-profile.js.map +1 -0
- package/dist/transaction-coordination/adapters/node/node-journal-slot-store.d.ts +25 -0
- package/dist/transaction-coordination/adapters/node/node-journal-slot-store.d.ts.map +1 -0
- package/dist/transaction-coordination/adapters/node/node-journal-slot-store.js +303 -0
- package/dist/transaction-coordination/adapters/node/node-journal-slot-store.js.map +1 -0
- package/dist/transaction-coordination/adapters/node/node-operation-lock.d.ts +16 -0
- package/dist/transaction-coordination/adapters/node/node-operation-lock.d.ts.map +1 -0
- package/dist/transaction-coordination/adapters/node/node-operation-lock.js +359 -0
- package/dist/transaction-coordination/adapters/node/node-operation-lock.js.map +1 -0
- package/dist/transaction-coordination/adapters/node/node-state-directory.d.ts +11 -0
- package/dist/transaction-coordination/adapters/node/node-state-directory.d.ts.map +1 -0
- package/dist/transaction-coordination/adapters/node/node-state-directory.js +91 -0
- package/dist/transaction-coordination/adapters/node/node-state-directory.js.map +1 -0
- package/dist/transaction-coordination/mutation-lease.d.ts +38 -0
- package/dist/transaction-coordination/mutation-lease.d.ts.map +1 -0
- package/dist/transaction-coordination/mutation-lease.js +351 -0
- package/dist/transaction-coordination/mutation-lease.js.map +1 -0
- package/package.json +52 -0
- package/schemas/known-file-transaction-plan/v1.schema.json +65 -0
- package/schemas/known-file-transaction-receipt/v1.schema.json +36 -0
- package/schemas/repository-mutation-transaction-envelope/v1.schema.json +46 -0
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
import { lstat, rmdir } from "node:fs/promises";
|
|
2
|
+
import { basename, dirname, join } from "node:path";
|
|
3
|
+
import { deserializeKnownFileIdentity } from "../../application/model/known-file-transaction-journal.js";
|
|
4
|
+
import { readBoundedRegularFile } from "./node-bounded-regular-file.js";
|
|
5
|
+
import { syncDirectoryStrictly } from "./node-directory-durability.js";
|
|
6
|
+
import { knownFileErrorCode, knownFileTemporaryName, KnownFileTransactionError, matchesKnownFileImage, sameKnownFileIdentity } from "./node-known-file-transaction-filesystem.js";
|
|
7
|
+
import { knownFileCapturePaths } from "./node-known-file-recovery-filesystem.js";
|
|
8
|
+
import { restorePreimage } from "./node-known-file-recovery-preimage.js";
|
|
9
|
+
import { retireJournalBoundPath } from "./node-known-file-recovery-retirement.js";
|
|
10
|
+
async function cleanupOperationTemporaries(options) {
|
|
11
|
+
const operation = options.stored.envelope.payload.plan.operations[options.operationIndex];
|
|
12
|
+
const journalOperation = options.stored.envelope.payload.operations[options.operationIndex];
|
|
13
|
+
const parent = dirname(join(options.root, ...operation.path.split("/")));
|
|
14
|
+
const candidates = [
|
|
15
|
+
{
|
|
16
|
+
identity: "temporaryIdentity" in journalOperation
|
|
17
|
+
? deserializeKnownFileIdentity(journalOperation.temporaryIdentity)
|
|
18
|
+
: undefined,
|
|
19
|
+
image: operation.postimage,
|
|
20
|
+
kind: "temporary",
|
|
21
|
+
authorizedWithoutIdentity: journalOperation.state === "temporary-authorized",
|
|
22
|
+
path: join(parent, knownFileTemporaryName(operation.path, options.stored.envelope.payload.plan.planDigest, options.operationIndex))
|
|
23
|
+
},
|
|
24
|
+
...(operation.precondition.state === "known-file" &&
|
|
25
|
+
journalOperation.matchedPreimage !== undefined
|
|
26
|
+
? [{
|
|
27
|
+
identity: journalOperation.rollbackTemporaryIdentity === undefined
|
|
28
|
+
? undefined
|
|
29
|
+
: deserializeKnownFileIdentity(journalOperation.rollbackTemporaryIdentity),
|
|
30
|
+
image: operation.precondition.acceptedPreimages[journalOperation.matchedPreimage],
|
|
31
|
+
kind: "rollback-temporary",
|
|
32
|
+
path: join(parent, `.${basename(operation.path)}.agent-teams.rollback.${options.operationIndex}.tmp`)
|
|
33
|
+
}]
|
|
34
|
+
: [])
|
|
35
|
+
];
|
|
36
|
+
for (const candidate of candidates) {
|
|
37
|
+
let observed;
|
|
38
|
+
try {
|
|
39
|
+
observed = await readBoundedRegularFile(candidate.path, candidate.image.size);
|
|
40
|
+
}
|
|
41
|
+
catch (error) {
|
|
42
|
+
if (knownFileErrorCode(error) === "ENOENT") {
|
|
43
|
+
continue;
|
|
44
|
+
}
|
|
45
|
+
throw error;
|
|
46
|
+
}
|
|
47
|
+
if (observed.outcome !== "read" || !matchesKnownFileImage({
|
|
48
|
+
state: "file", bytes: observed.bytes, identity: observed.identity,
|
|
49
|
+
mode: observed.mode & 0o777
|
|
50
|
+
}, candidate.image)) {
|
|
51
|
+
throw new KnownFileTransactionError("KNOWN_FILE_RECOVERY_CONFLICT", `Transaction temporary is foreign or modified: ${operation.path}.`);
|
|
52
|
+
}
|
|
53
|
+
if (candidate.identity === undefined && candidate.authorizedWithoutIdentity === true) {
|
|
54
|
+
throw new KnownFileTransactionError("KNOWN_FILE_RECOVERY_CONFLICT", `Authorized temporary exists without durable ownership identity: ${operation.path}.`);
|
|
55
|
+
}
|
|
56
|
+
if (candidate.identity === undefined ||
|
|
57
|
+
!sameKnownFileIdentity(observed.identity, candidate.identity)) {
|
|
58
|
+
throw new KnownFileTransactionError("KNOWN_FILE_RECOVERY_CONFLICT", `Transaction temporary identity is absent or changed: ${operation.path}.`);
|
|
59
|
+
}
|
|
60
|
+
await retireJournalBoundPath({
|
|
61
|
+
expectedIdentity: candidate.identity,
|
|
62
|
+
kind: candidate.kind,
|
|
63
|
+
operationIndex: options.operationIndex,
|
|
64
|
+
root: options.root,
|
|
65
|
+
store: options.store,
|
|
66
|
+
stored: options.stored
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
async function cleanupAuthorizedCapture(options) {
|
|
71
|
+
const operation = options.journal.plan.operations[options.operationIndex];
|
|
72
|
+
const parent = dirname(join(options.root, ...operation.path.split("/")));
|
|
73
|
+
const paths = knownFileCapturePaths({
|
|
74
|
+
operationIndex: options.operationIndex,
|
|
75
|
+
operationPath: operation.path,
|
|
76
|
+
parent,
|
|
77
|
+
planDigest: options.journal.plan.planDigest
|
|
78
|
+
});
|
|
79
|
+
const metadata = await lstat(paths.directory).catch((error) => {
|
|
80
|
+
if (knownFileErrorCode(error) === "ENOENT") {
|
|
81
|
+
return null;
|
|
82
|
+
}
|
|
83
|
+
throw error;
|
|
84
|
+
});
|
|
85
|
+
if (metadata === null) {
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
if (!metadata.isDirectory() || metadata.isSymbolicLink()) {
|
|
89
|
+
throw new KnownFileTransactionError("KNOWN_FILE_RECOVERY_CONFLICT", `Authorized capture path is foreign: ${operation.path}.`);
|
|
90
|
+
}
|
|
91
|
+
throw new KnownFileTransactionError("KNOWN_FILE_RECOVERY_CONFLICT", `Authorized capture exists without durable ownership identity: ${operation.path}.`);
|
|
92
|
+
}
|
|
93
|
+
async function removeAuthorizedDirectories(root, directories) {
|
|
94
|
+
for (const repositoryPath of directories.toReversed()) {
|
|
95
|
+
const path = join(root, ...repositoryPath.split("/"));
|
|
96
|
+
const metadata = await lstat(path).catch((error) => {
|
|
97
|
+
if (knownFileErrorCode(error) === "ENOENT") {
|
|
98
|
+
return null;
|
|
99
|
+
}
|
|
100
|
+
throw error;
|
|
101
|
+
});
|
|
102
|
+
if (metadata === null) {
|
|
103
|
+
continue;
|
|
104
|
+
}
|
|
105
|
+
if (!metadata.isDirectory() || metadata.isSymbolicLink()) {
|
|
106
|
+
throw new KnownFileTransactionError("KNOWN_FILE_RECOVERY_CONFLICT", `Authorized directory path is foreign: ${repositoryPath}.`);
|
|
107
|
+
}
|
|
108
|
+
throw new KnownFileTransactionError("KNOWN_FILE_RECOVERY_CONFLICT", `Authorized directory exists without durable ownership identity: ${repositoryPath}.`);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
async function removeCreatedDirectories(root, directories) {
|
|
112
|
+
for (const directory of directories.toReversed()) {
|
|
113
|
+
const path = join(root, ...directory.path.split("/"));
|
|
114
|
+
let metadata;
|
|
115
|
+
try {
|
|
116
|
+
metadata = await lstat(path, { bigint: true });
|
|
117
|
+
}
|
|
118
|
+
catch (error) {
|
|
119
|
+
if (knownFileErrorCode(error) === "ENOENT") {
|
|
120
|
+
continue;
|
|
121
|
+
}
|
|
122
|
+
throw error;
|
|
123
|
+
}
|
|
124
|
+
const expected = deserializeKnownFileIdentity(directory.identity);
|
|
125
|
+
if (!metadata.isDirectory() || metadata.isSymbolicLink() ||
|
|
126
|
+
metadata.dev !== expected.dev || metadata.ino !== expected.ino ||
|
|
127
|
+
metadata.birthtimeNs !== expected.birthtimeNs) {
|
|
128
|
+
throw new KnownFileTransactionError("KNOWN_FILE_RECOVERY_CONFLICT", `Transaction-created directory changed before cleanup: ${directory.path}.`);
|
|
129
|
+
}
|
|
130
|
+
try {
|
|
131
|
+
await rmdir(path);
|
|
132
|
+
await syncDirectoryStrictly(dirname(path));
|
|
133
|
+
}
|
|
134
|
+
catch (error) {
|
|
135
|
+
if (knownFileErrorCode(error) !== "ENOTEMPTY") {
|
|
136
|
+
throw error;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
export async function rollbackKnownFileRecovery(options) {
|
|
142
|
+
for (let index = options.stored.envelope.payload.operations.length - 1; index >= 0; index -= 1) {
|
|
143
|
+
let journalOperation = options.stored.envelope.payload.operations[index];
|
|
144
|
+
if (journalOperation.retirement !== undefined) {
|
|
145
|
+
await retireJournalBoundPath({
|
|
146
|
+
expectedIdentity: deserializeKnownFileIdentity(journalOperation.retirement.pathIdentity),
|
|
147
|
+
...(options.faultInjector === undefined ? {} : { faultInjector: options.faultInjector }),
|
|
148
|
+
kind: journalOperation.retirement.kind,
|
|
149
|
+
operationIndex: index,
|
|
150
|
+
root: options.root,
|
|
151
|
+
store: options.store,
|
|
152
|
+
stored: options.stored
|
|
153
|
+
});
|
|
154
|
+
journalOperation = options.stored.envelope.payload.operations[index];
|
|
155
|
+
}
|
|
156
|
+
if (journalOperation.state === "capture-authorized") {
|
|
157
|
+
await cleanupAuthorizedCapture({
|
|
158
|
+
journal: options.stored.envelope.payload,
|
|
159
|
+
operationIndex: index,
|
|
160
|
+
root: options.root
|
|
161
|
+
});
|
|
162
|
+
continue;
|
|
163
|
+
}
|
|
164
|
+
if (![
|
|
165
|
+
"capture-ready", "preimage-captured", "destination-retired",
|
|
166
|
+
"publishing", "published", "rollback-restored"
|
|
167
|
+
].includes(journalOperation.state)) {
|
|
168
|
+
continue;
|
|
169
|
+
}
|
|
170
|
+
await restorePreimage({
|
|
171
|
+
...(options.faultInjector === undefined ? {} : { faultInjector: options.faultInjector }),
|
|
172
|
+
operation: options.stored.envelope.payload.plan.operations[index],
|
|
173
|
+
operationIndex: index,
|
|
174
|
+
root: options.root,
|
|
175
|
+
store: options.store,
|
|
176
|
+
stored: options.stored
|
|
177
|
+
});
|
|
178
|
+
await cleanupOperationTemporaries({
|
|
179
|
+
operationIndex: index,
|
|
180
|
+
root: options.root,
|
|
181
|
+
store: options.store,
|
|
182
|
+
stored: options.stored
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
for (let index = options.stored.envelope.payload.operations.length - 1; index >= 0; index -= 1) {
|
|
186
|
+
const journal = options.stored.envelope.payload;
|
|
187
|
+
if (![
|
|
188
|
+
"capture-ready", "preimage-captured", "destination-retired",
|
|
189
|
+
"publishing", "published", "rollback-restored"
|
|
190
|
+
].includes(journal.operations[index].state)) {
|
|
191
|
+
await cleanupOperationTemporaries({
|
|
192
|
+
operationIndex: index,
|
|
193
|
+
root: options.root,
|
|
194
|
+
store: options.store,
|
|
195
|
+
stored: options.stored
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
const journal = options.stored.envelope.payload;
|
|
200
|
+
await removeCreatedDirectories(options.root, journal.createdDirectories);
|
|
201
|
+
await removeAuthorizedDirectories(options.root, journal.authorizedDirectories);
|
|
202
|
+
}
|
|
203
|
+
//# sourceMappingURL=node-known-file-recovery-cleanup.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"node-known-file-recovery-cleanup.js","sourceRoot":"","sources":["../../../../src/repository-mutation/adapters/node/node-known-file-recovery-cleanup.ts"],"names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AC;IACD,KAAK,IAAI,KAAK,GAAG,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,OAAO,CAAC,UAAU,CAAC,MAAM,GAAG,CAAC,EAAE,KAAK,IAAI,CAAC,EAAE,KAAK,IAAI,CAAC,EAAE,CAAC;QAC/F,MAAM,OAAO,GAAG,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,OAAO,CAAC;QAChD,IAAI,CAAC;YACH,eAAe,EAAE,mBAAmB,EAAE,qBAAqB;YAC3D,YAAY,EAAE,WAAW,EAAE,mBAAmB;SAC/C,CAAC,QAAQ,CAAC,OAAO,CAAC,UAAU,CAAC,KAAK,CAAE,CAAC,KAAK,CAAC,EAAE,CAAC;YAC7C,MAAM,2BAA2B,CAAC;gBAChC,cAAc,EAAE,KAAK;gBACrB,IAAI,EAAE,OAAO,CAAC,IAAI;gBAClB,KAAK,EAAE,OAAO,CAAC,KAAK;gBACpB,MAAM,EAAE,OAAO,CAAC,MAAM;aACvB,CAAC,CAAC;QACL,CAAC;IACH,CAAC;IACD,MAAM,OAAO,GAAG,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,OAAO,CAAC;IAChD,MAAM,wBAAwB,CAAC,OAAO,CAAC,IAAI,EAAE,OAAO,CAAC,kBAAkB,CAAC,CAAC;IACzE,MAAM,2BAA2B,CAAC,OAAO,CAAC,IAAI,EAAE,OAAO,CAAC,qBAAqB,CAAC,CAAC;AACjF,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { KnownFileTransactionReceiptV1 } from "../../application/model/known-file-transaction.js";
|
|
2
|
+
import { type KnownFileRecoveryFaultInjector, type StoredRecoveryJournal } from "./node-known-file-recovery-state.js";
|
|
3
|
+
import type { NodeKnownFileTransactionJournalStore } from "./node-known-file-transaction-journal-store.js";
|
|
4
|
+
export type { KnownFileRecoveryFaultInjector } from "./node-known-file-recovery-state.js";
|
|
5
|
+
export declare function executeCommittedKnownFileRecovery(options: {
|
|
6
|
+
readonly faultInjector?: KnownFileRecoveryFaultInjector;
|
|
7
|
+
readonly root: string;
|
|
8
|
+
readonly store: NodeKnownFileTransactionJournalStore;
|
|
9
|
+
readonly stored: StoredRecoveryJournal;
|
|
10
|
+
}): Promise<KnownFileTransactionReceiptV1>;
|
|
11
|
+
export declare function executeApplyingKnownFileRollback(options: {
|
|
12
|
+
readonly faultInjector?: KnownFileRecoveryFaultInjector;
|
|
13
|
+
readonly root: string;
|
|
14
|
+
readonly store: NodeKnownFileTransactionJournalStore;
|
|
15
|
+
readonly stored: StoredRecoveryJournal;
|
|
16
|
+
}): Promise<KnownFileTransactionReceiptV1>;
|
|
17
|
+
//# sourceMappingURL=node-known-file-recovery-executor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"node-known-file-recovery-executor.d.ts","sourceRoot":"","sources":["../../../../src/repository-mutation/adapters/node/node-known-file-recovery-executor.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,6BAA6B,EAAE,MAAM,mDAAmD,CAAC;AAGvG,OAAO,EACL,KAAK,8BAA8B,EACnC,KAAK,qBAAqB,EAC3B,MAAM,qCAAqC,CAAC;AAC7C,OAAO,KAAK,EAAE,oCAAoC,EAAE,MAAM,gDAAgD,CAAC;AAQ3G,YAAY,EAAE,8BAA8B,EAAE,MAAM,qCAAqC,CAAC;AAE1F,wBAAsB,iCAAiC,CAAC,OAAO,EAAE;IAC/D,QAAQ,CAAC,aAAa,CAAC,EAAE,8BAA8B,CAAC;IACxD,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,KAAK,EAAE,oCAAoC,CAAC;IACrD,QAAQ,CAAC,MAAM,EAAE,qBAAqB,CAAC;CACxC,GAAG,OAAO,CAAC,6BAA6B,CAAC,CAczC;AAED,wBAAsB,gCAAgC,CAAC,OAAO,EAAE;IAC9D,QAAQ,CAAC,aAAa,CAAC,EAAE,8BAA8B,CAAC;IACxD,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,KAAK,EAAE,oCAAoC,CAAC;IACrD,QAAQ,CAAC,MAAM,EAAE,qBAAqB,CAAC;CACxC,GAAG,OAAO,CAAC,6BAA6B,CAAC,CAMzC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { cleanupCommittedKnownFileCaptures } from "./node-known-file-recovery-filesystem.js";
|
|
2
|
+
import { rollbackKnownFileRecovery } from "./node-known-file-recovery-cleanup.js";
|
|
3
|
+
import {} from "./node-known-file-recovery-state.js";
|
|
4
|
+
import { compileKnownFileTransactionReceipt, verifyCommittedKnownFilePostimages } from "./node-known-file-transaction.js";
|
|
5
|
+
import { compileRolledBackReceipt } from "./node-known-file-transaction-receipt.js";
|
|
6
|
+
import { verifyRolledBackKnownFileState } from "./node-known-file-recovery-observation.js";
|
|
7
|
+
export async function executeCommittedKnownFileRecovery(options) {
|
|
8
|
+
await verifyCommittedKnownFilePostimages(options.root, options.stored.envelope.payload);
|
|
9
|
+
await cleanupCommittedKnownFileCaptures(options.root, options.stored.envelope.payload, options.faultInjector);
|
|
10
|
+
await verifyCommittedKnownFilePostimages(options.root, options.stored.envelope.payload);
|
|
11
|
+
const result = compileKnownFileTransactionReceipt(options.stored.envelope.payload, "applied");
|
|
12
|
+
await options.store.remove(options.stored.authority);
|
|
13
|
+
return result;
|
|
14
|
+
}
|
|
15
|
+
export async function executeApplyingKnownFileRollback(options) {
|
|
16
|
+
await rollbackKnownFileRecovery(options);
|
|
17
|
+
await verifyRolledBackKnownFileState(options.root, options.stored.envelope.payload);
|
|
18
|
+
const result = compileRolledBackReceipt(options.stored.envelope.payload);
|
|
19
|
+
await options.store.remove(options.stored.authority);
|
|
20
|
+
return result;
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=node-known-file-recovery-executor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"node-known-file-recovery-executor.js","sourceRoot":"","sources":["../../../../src/repository-mutation/adapters/node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AM,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;IACzE,MAAM,OAAO,CAAC,KAAK,CAAC,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;IACrD,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { KnownFileImageV1 } from "../../application/model/known-file-transaction.js";
|
|
2
|
+
import type { KnownFileTransactionJournalV1 } from "../../application/model/known-file-transaction-journal.js";
|
|
3
|
+
import { deserializeKnownFileIdentity } from "../../application/model/known-file-transaction-journal.js";
|
|
4
|
+
import { captureFileHandleIdentity } from "./node-bounded-regular-file.js";
|
|
5
|
+
import { type ObservedKnownFile } from "./node-known-file-transaction-filesystem.js";
|
|
6
|
+
export declare function knownFileCapturePaths(options: {
|
|
7
|
+
readonly operationPath: string;
|
|
8
|
+
readonly operationIndex: number;
|
|
9
|
+
readonly parent: string;
|
|
10
|
+
readonly planDigest: string;
|
|
11
|
+
}): {
|
|
12
|
+
readonly captured: string;
|
|
13
|
+
readonly directory: string;
|
|
14
|
+
readonly retired: string;
|
|
15
|
+
};
|
|
16
|
+
export declare function cleanupCommittedKnownFileCaptures(root: string, journal: KnownFileTransactionJournalV1, faultInjector?: (point: {
|
|
17
|
+
readonly operationIndex: number;
|
|
18
|
+
readonly path: string;
|
|
19
|
+
readonly phase: "after-committed-capture-unlinked";
|
|
20
|
+
}) => Promise<void> | void): Promise<void>;
|
|
21
|
+
export declare function observeRecoveryFile(path: string, maximumBytes: number): Promise<ObservedKnownFile>;
|
|
22
|
+
export declare function prepareRollbackTemporary(options: {
|
|
23
|
+
readonly expectedIdentity?: ReturnType<typeof deserializeKnownFileIdentity>;
|
|
24
|
+
readonly operationPath: string;
|
|
25
|
+
readonly path: string;
|
|
26
|
+
readonly preimage: KnownFileImageV1;
|
|
27
|
+
}): Promise<Awaited<ReturnType<typeof captureFileHandleIdentity>>>;
|
|
28
|
+
//# sourceMappingURL=node-known-file-recovery-filesystem.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"node-known-file-recovery-filesystem.d.ts","sourceRoot":"","sources":["../../../../src/repository-mutation/adapters/node/node-known-file-recovery-filesystem.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,mDAAmD,CAAC;AAC1F,OAAO,KAAK,EAAE,6BAA6B,EAAE,MAAM,2DAA2D,CAAC;AAC/G,OAAO,EAAE,4BAA4B,EAAE,MAAM,2DAA2D,CAAC;AACzG,OAAO,EACL,yBAAyB,EAG1B,MAAM,gCAAgC,CAAC;AAExC,OAAO,EAOL,KAAK,iBAAiB,EACvB,MAAM,6CAA6C,CAAC;AAErD,wBAAgB,qBAAqB,CAAC,OAAO,EAAE;IAC7C,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;IAC/B,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAC;IAChC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;CAC7B,GAAG;IAAE,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAA;CAAE,CAWtF;AA2CD,wBAAsB,iCAAiC,CACrD,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,6BAA6B,EACtC,aAAa,CAAC,EAAE,CAAC,KAAK,EAAE;IACtB,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAC;IAChC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,KAAK,EAAE,kCAAkC,CAAC;CACpD,KAAK,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,GACzB,OAAO,CAAC,IAAI,CAAC,CA6Ff;AAED,wBAAsB,mBAAmB,CACvC,IAAI,EAAE,MAAM,EACZ,YAAY,EAAE,MAAM,GACnB,OAAO,CAAC,iBAAiB,CAAC,CAoB5B;AAED,wBAAsB,wBAAwB,CAAC,OAAO,EAAE;IACtD,QAAQ,CAAC,gBAAgB,CAAC,EAAE,UAAU,CAAC,OAAO,4BAA4B,CAAC,CAAC;IAC5E,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;IAC/B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,QAAQ,EAAE,gBAAgB,CAAC;CACrC,GAAG,OAAO,CAAC,OAAO,CAAC,UAAU,CAAC,OAAO,yBAAyB,CAAC,CAAC,CAAC,CAuFjE"}
|
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
import { constants, lstat, open, opendir, rmdir, unlink } from "node:fs/promises";
|
|
2
|
+
import { basename, dirname, join } from "node:path";
|
|
3
|
+
import { deserializeKnownFileIdentity } from "../../application/model/known-file-transaction-journal.js";
|
|
4
|
+
import { captureFileHandleIdentity, readBoundedRegularFile, readBoundedRegularFileHandle } from "./node-bounded-regular-file.js";
|
|
5
|
+
import { syncDirectoryStrictly } from "./node-directory-durability.js";
|
|
6
|
+
import { knownFileErrorCode, knownFileCaptureDirectoryName, knownFileImageBytes, KnownFileTransactionError, matchesKnownFileImage, sameKnownFileIdentity } from "./node-known-file-transaction-filesystem.js";
|
|
7
|
+
export function knownFileCapturePaths(options) {
|
|
8
|
+
const directory = join(options.parent, knownFileCaptureDirectoryName(options.operationPath, options.planDigest, options.operationIndex));
|
|
9
|
+
return {
|
|
10
|
+
captured: join(directory, "preimage"),
|
|
11
|
+
directory,
|
|
12
|
+
retired: join(directory, "retired")
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
async function boundedCaptureEntries(path) {
|
|
16
|
+
const directory = await opendir(path);
|
|
17
|
+
const entries = [];
|
|
18
|
+
try {
|
|
19
|
+
for (;;) {
|
|
20
|
+
const entry = await directory.read();
|
|
21
|
+
if (entry === null) {
|
|
22
|
+
return entries.toSorted();
|
|
23
|
+
}
|
|
24
|
+
entries.push(entry.name);
|
|
25
|
+
if (entries.length > 2) {
|
|
26
|
+
throw new KnownFileTransactionError("KNOWN_FILE_RECOVERY_CONFLICT", "Transaction capture directory contains excess foreign evidence.");
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
finally {
|
|
31
|
+
await directory.close();
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
async function assertCaptureDirectoryIdentity(path, expected, displayPath) {
|
|
35
|
+
const metadata = await lstat(path, { bigint: true }).catch((error) => {
|
|
36
|
+
if (knownFileErrorCode(error) === "ENOENT") {
|
|
37
|
+
return null;
|
|
38
|
+
}
|
|
39
|
+
throw error;
|
|
40
|
+
});
|
|
41
|
+
if (metadata === null) {
|
|
42
|
+
return false;
|
|
43
|
+
}
|
|
44
|
+
if (!metadata.isDirectory() || metadata.isSymbolicLink() ||
|
|
45
|
+
metadata.birthtimeNs !== expected.birthtimeNs || metadata.dev !== expected.dev ||
|
|
46
|
+
metadata.ino !== expected.ino) {
|
|
47
|
+
throw new KnownFileTransactionError("KNOWN_FILE_RECOVERY_CONFLICT", `Transaction capture directory changed: ${displayPath}.`);
|
|
48
|
+
}
|
|
49
|
+
return true;
|
|
50
|
+
}
|
|
51
|
+
export async function cleanupCommittedKnownFileCaptures(root, journal, faultInjector) {
|
|
52
|
+
for (const [index, journalOperation] of journal.operations.entries()) {
|
|
53
|
+
if (!("temporaryIdentity" in journalOperation) ||
|
|
54
|
+
journalOperation.captureDirectoryIdentity === undefined) {
|
|
55
|
+
continue;
|
|
56
|
+
}
|
|
57
|
+
const operation = journal.plan.operations[index];
|
|
58
|
+
const parent = dirname(join(root, ...operation.path.split("/")));
|
|
59
|
+
const paths = knownFileCapturePaths({
|
|
60
|
+
operationIndex: index,
|
|
61
|
+
operationPath: operation.path,
|
|
62
|
+
parent,
|
|
63
|
+
planDigest: journal.plan.planDigest
|
|
64
|
+
});
|
|
65
|
+
if (operation.precondition.state !== "known-file" ||
|
|
66
|
+
journalOperation.matchedPreimage === undefined) {
|
|
67
|
+
throw new KnownFileTransactionError("KNOWN_FILE_RECOVERY_CONFLICT", `Committed replacement lacks exact preimage authority: ${operation.path}.`);
|
|
68
|
+
}
|
|
69
|
+
const preimage = operation.precondition.acceptedPreimages[journalOperation.matchedPreimage];
|
|
70
|
+
if (journalOperation.rollbackTemporaryIdentity !== undefined) {
|
|
71
|
+
const rollbackPath = join(parent, `.${basename(operation.path)}.agent-teams.rollback.${index}.tmp`);
|
|
72
|
+
const rollback = await observeRecoveryFile(rollbackPath, preimage.size);
|
|
73
|
+
if (rollback.state === "file") {
|
|
74
|
+
const expectedRollback = deserializeKnownFileIdentity(journalOperation.rollbackTemporaryIdentity);
|
|
75
|
+
if (rollback.identity === undefined ||
|
|
76
|
+
!sameKnownFileIdentity(rollback.identity, expectedRollback) ||
|
|
77
|
+
!matchesKnownFileImage(rollback, preimage)) {
|
|
78
|
+
throw new KnownFileTransactionError("KNOWN_FILE_RECOVERY_CONFLICT", `Committed rollback copy changed: ${operation.path}.`);
|
|
79
|
+
}
|
|
80
|
+
await unlink(rollbackPath);
|
|
81
|
+
await syncDirectoryStrictly(parent);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
const expectedDirectory = deserializeKnownFileIdentity(journalOperation.captureDirectoryIdentity);
|
|
85
|
+
const directoryExists = await assertCaptureDirectoryIdentity(paths.directory, expectedDirectory, operation.path);
|
|
86
|
+
if (!directoryExists) {
|
|
87
|
+
continue;
|
|
88
|
+
}
|
|
89
|
+
const entries = await boundedCaptureEntries(paths.directory);
|
|
90
|
+
if (entries.length === 0) {
|
|
91
|
+
await rmdir(paths.directory);
|
|
92
|
+
await syncDirectoryStrictly(parent);
|
|
93
|
+
continue;
|
|
94
|
+
}
|
|
95
|
+
if (journalOperation.capturedPreimageIdentity === undefined) {
|
|
96
|
+
throw new KnownFileTransactionError("KNOWN_FILE_RECOVERY_CONFLICT", `Committed replacement lacks captured preimage authority: ${operation.path}.`);
|
|
97
|
+
}
|
|
98
|
+
const captured = await readBoundedRegularFile(paths.captured, operation.precondition.acceptedPreimages[journalOperation.matchedPreimage].size);
|
|
99
|
+
const expectedCaptured = deserializeKnownFileIdentity(journalOperation.capturedPreimageIdentity);
|
|
100
|
+
if (captured.outcome !== "read" ||
|
|
101
|
+
!sameKnownFileIdentity(captured.identity, expectedCaptured) ||
|
|
102
|
+
!matchesKnownFileImage({
|
|
103
|
+
state: "file", bytes: captured.bytes, identity: captured.identity,
|
|
104
|
+
mode: captured.mode & 0o777
|
|
105
|
+
}, preimage)) {
|
|
106
|
+
throw new KnownFileTransactionError("KNOWN_FILE_RECOVERY_CONFLICT", `Committed captured preimage changed: ${operation.path}.`);
|
|
107
|
+
}
|
|
108
|
+
if (entries.join(",") !== "preimage") {
|
|
109
|
+
throw new KnownFileTransactionError("KNOWN_FILE_RECOVERY_CONFLICT", `Committed capture directory contains foreign evidence: ${operation.path}.`);
|
|
110
|
+
}
|
|
111
|
+
await unlink(paths.captured);
|
|
112
|
+
await syncDirectoryStrictly(paths.directory);
|
|
113
|
+
await faultInjector?.({
|
|
114
|
+
operationIndex: index,
|
|
115
|
+
path: operation.path,
|
|
116
|
+
phase: "after-committed-capture-unlinked"
|
|
117
|
+
});
|
|
118
|
+
await rmdir(paths.directory);
|
|
119
|
+
await syncDirectoryStrictly(parent);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
export async function observeRecoveryFile(path, maximumBytes) {
|
|
123
|
+
let observed;
|
|
124
|
+
try {
|
|
125
|
+
observed = await readBoundedRegularFile(path, maximumBytes);
|
|
126
|
+
}
|
|
127
|
+
catch (error) {
|
|
128
|
+
if (knownFileErrorCode(error) === "ENOENT") {
|
|
129
|
+
return { state: "absent" };
|
|
130
|
+
}
|
|
131
|
+
throw error;
|
|
132
|
+
}
|
|
133
|
+
if (observed.outcome !== "read") {
|
|
134
|
+
throw new KnownFileTransactionError("KNOWN_FILE_RECOVERY_CONFLICT", "Recovery path is not one stable bounded regular file.");
|
|
135
|
+
}
|
|
136
|
+
return {
|
|
137
|
+
state: "file",
|
|
138
|
+
bytes: observed.bytes,
|
|
139
|
+
identity: observed.identity,
|
|
140
|
+
mode: observed.mode & 0o777
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
export async function prepareRollbackTemporary(options) {
|
|
144
|
+
let handle;
|
|
145
|
+
let rollbackIdentity;
|
|
146
|
+
let created = false;
|
|
147
|
+
try {
|
|
148
|
+
handle = await open(options.path, "wx", 0o600);
|
|
149
|
+
created = true;
|
|
150
|
+
rollbackIdentity = await captureFileHandleIdentity(handle);
|
|
151
|
+
}
|
|
152
|
+
catch (error) {
|
|
153
|
+
if (knownFileErrorCode(error) !== "EEXIST") {
|
|
154
|
+
throw error;
|
|
155
|
+
}
|
|
156
|
+
if (options.expectedIdentity === undefined) {
|
|
157
|
+
throw new KnownFileTransactionError("KNOWN_FILE_RECOVERY_CONFLICT", `Rollback temporary exists without durable identity authority: ${options.operationPath}.`);
|
|
158
|
+
}
|
|
159
|
+
const noFollow = process.platform === "win32" ? 0 : constants.O_NOFOLLOW;
|
|
160
|
+
handle = await open(options.path, constants.O_RDWR | noFollow);
|
|
161
|
+
try {
|
|
162
|
+
const stale = await readBoundedRegularFileHandle(handle, options.path, options.preimage.size);
|
|
163
|
+
if (stale.outcome !== "read" || !matchesKnownFileImage({
|
|
164
|
+
state: "file", bytes: stale.bytes, identity: stale.identity,
|
|
165
|
+
mode: stale.mode & 0o777
|
|
166
|
+
}, options.preimage)) {
|
|
167
|
+
throw new KnownFileTransactionError("KNOWN_FILE_RECOVERY_CONFLICT", `Rollback temporary is foreign or modified: ${options.operationPath}.`);
|
|
168
|
+
}
|
|
169
|
+
rollbackIdentity = await captureFileHandleIdentity(handle);
|
|
170
|
+
if (!sameKnownFileIdentity(rollbackIdentity, stale.identity) ||
|
|
171
|
+
!sameKnownFileIdentity(rollbackIdentity, options.expectedIdentity)) {
|
|
172
|
+
throw new KnownFileTransactionError("KNOWN_FILE_RECOVERY_CONFLICT", `Rollback temporary changed while it was opened: ${options.operationPath}.`);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
catch (inspectionError) {
|
|
176
|
+
await handle.close();
|
|
177
|
+
throw inspectionError;
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
if (created) {
|
|
181
|
+
try {
|
|
182
|
+
const bytes = knownFileImageBytes(options.preimage);
|
|
183
|
+
await handle.truncate(0);
|
|
184
|
+
let offset = 0;
|
|
185
|
+
while (offset < bytes.byteLength) {
|
|
186
|
+
const { bytesWritten } = await handle.write(bytes, offset, bytes.byteLength - offset, offset);
|
|
187
|
+
if (bytesWritten === 0) {
|
|
188
|
+
throw new KnownFileTransactionError("KNOWN_FILE_RECOVERY_FAILED", `Rollback temporary write made no progress: ${options.operationPath}.`);
|
|
189
|
+
}
|
|
190
|
+
offset += bytesWritten;
|
|
191
|
+
}
|
|
192
|
+
await handle.chmod(options.preimage.mode);
|
|
193
|
+
await handle.sync();
|
|
194
|
+
}
|
|
195
|
+
finally {
|
|
196
|
+
await handle.close();
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
else {
|
|
200
|
+
await handle.close();
|
|
201
|
+
}
|
|
202
|
+
const prepared = await readBoundedRegularFile(options.path, options.preimage.size);
|
|
203
|
+
if (prepared.outcome !== "read" ||
|
|
204
|
+
!sameKnownFileIdentity(prepared.identity, rollbackIdentity) ||
|
|
205
|
+
!matchesKnownFileImage({
|
|
206
|
+
state: "file", bytes: prepared.bytes, identity: prepared.identity,
|
|
207
|
+
mode: prepared.mode & 0o777
|
|
208
|
+
}, options.preimage)) {
|
|
209
|
+
throw new KnownFileTransactionError("KNOWN_FILE_RECOVERY_CONFLICT", `Rollback temporary changed before publication: ${options.operationPath}.`);
|
|
210
|
+
}
|
|
211
|
+
return rollbackIdentity;
|
|
212
|
+
}
|
|
213
|
+
//# sourceMappingURL=node-known-file-recovery-filesystem.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"node-known-file-recovery-filesystem.js","sourceRoot":"","sources":["../../../../src/repository-mutation/adapters/node/node-known-file-recovery-filesystem.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,SAAS,EACT,KAAK,EACL,IAAI,EACJ,OAAO,EACP,KAAK,EACL,MAAM,EAEP,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAIpD,OAAO,EAAE,4BAA4B,EAAE,MAAM,2DAA2D,CAAC;AACzG,OAAO,EACL,yBAAyB,EACzB,sBAAsB,EACtB,4BAA4B,EAC7B,MAAM,gCAAgC,CAAC;AACxC,OAAO,EAAE,qBAAqB,EAAE,MAAM,gCAAgC,CAAC;AACvE,OAAO,EACL,kBAAkB,EAClB,6BAA6B,EAC7B,mBAAmB,EACnB,yBAAyB,EACzB,qBAAqB,EACrB,qBAAqB,EAEtB,MAAM,6CAA6C,CAAC;AAErD,MAAM,UAAU,qBAAqB,CAAC,OAKrC;IACC,MAAM,SAAS,GAAG,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,6BAA6B,CAClE,OAAO,CAAC,aAAa,EACrB,OAAO,CAAC,UAAU,EAClB,OAAO,CAAC,cAAc,CACvB,CAAC,CAAC;IACH,OAAO;QACL,QAAQ,EAAE,IAAI,CAAC,SAAS,EAAE,UAAU,CAAC;QACrC,SAAS;QACT,OAAO,EAAE,IAAI,CAAC,SAAS,EAAE,SAAS,CAAC;KACpC,CAAC;AACJ,CAAC;AAED,KAAK,UAAU,qBAAqB,CAAC,IAAY;IAC/C,MAAM,SAAS,GAAG,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;IACtC,MAAM,OAAO,GAAa,EAAE,CAAC;IAC7B,IAAI,CAAC;QACH,SAAS,CAAC;YACR,MAAM,KAAK,GAAG,MAAM,SAAS,CAAC,IAAI,EAAE,CAAC;YACrC,IAAI,KAAK,KAAK,IAAI,EAAE,CAAC;gBA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KAAK;SAC5B,EAAE,OAAO,CAAC,QAAQ,CAAC,EAAE,CAAC;QACvB,MAAM,IAAI,yBAAyB,CACjC,8BAA8B,EAC9B,kDAAkD,OAAO,CAAC,aAAa,GAAG,CAC3E,CAAC;IACJ,CAAC;IACD,OAAO,gBAAgB,CAAC;AAC1B,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { KnownFileTransactionEnvelopeV1, KnownFileTransactionJournalV1 } from "../../application/model/known-file-transaction-journal.js";
|
|
2
|
+
import type { InstalledKnownFileRecoveryBuild } from "../../application/policies/classify-known-file-recovery-transition.js";
|
|
3
|
+
import { NodeKnownFileTransactionJournalStore, type KnownFileJournalAuthority } from "./node-known-file-transaction-journal-store.js";
|
|
4
|
+
export interface StoredKnownFileRecoveryJournal {
|
|
5
|
+
authority: KnownFileJournalAuthority;
|
|
6
|
+
envelope: KnownFileTransactionEnvelopeV1;
|
|
7
|
+
}
|
|
8
|
+
export interface KnownFileRecoveryEvidence {
|
|
9
|
+
readonly installedBuild: InstalledKnownFileRecoveryBuild;
|
|
10
|
+
readonly store: NodeKnownFileTransactionJournalStore;
|
|
11
|
+
readonly stored: StoredKnownFileRecoveryJournal;
|
|
12
|
+
}
|
|
13
|
+
export declare function observeKnownFileRecoveryEvidence(root: string): Promise<KnownFileRecoveryEvidence>;
|
|
14
|
+
export declare function verifyRolledBackKnownFileState(root: string, journal: KnownFileTransactionJournalV1): Promise<void>;
|
|
15
|
+
//# sourceMappingURL=node-known-file-recovery-observation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"node-known-file-recovery-observation.d.ts","sourceRoot":"","sources":["../../../../src/repository-mutation/adapters/node/node-known-file-recovery-observation.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EACV,8BAA8B,EAC9B,6BAA6B,EAC9B,MAAM,2DAA2D,CAAC;AACnE,OAAO,KAAK,EAAE,+BAA+B,EAAE,MAAM,uEAAuE,CAAC;AAO7H,OAAO,EACL,oCAAoC,EACpC,KAAK,yBAAyB,EAC/B,MAAM,gDAAgD,CAAC;AAExD,MAAM,WAAW,8BAA8B;IAC7C,SAAS,EAAE,yBAAyB,CAAC;IACrC,QAAQ,EAAE,8BAA8B,CAAC;CAC1C;AAED,MAAM,WAAW,yBAAyB;IACxC,QAAQ,CAAC,cAAc,EAAE,+BAA+B,CAAC;IACzD,QAAQ,CAAC,KAAK,EAAE,oCAAoC,CAAC;IACrD,QAAQ,CAAC,MAAM,EAAE,8BAA8B,CAAC;CACjD;AAED,wBAAsB,gCAAgC,CACpD,IAAI,EAAE,MAAM,GACX,OAAO,CAAC,yBAAyB,CAAC,CAyBpC;AAED,wBAAsB,8BAA8B,CAClD,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,6BAA6B,GACrC,OAAO,CAAC,IAAI,CAAC,CAmCf"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { join } from "node:path";
|
|
2
|
+
import { installedRepositoryMutationBuildIdentity } from "../../../installed-artifact-identity.js";
|
|
3
|
+
import { installedRepositoryMutationVersion, REPOSITORY_MUTATION_PACKAGE_NAME } from "../../../package-version.js";
|
|
4
|
+
import { LOCAL_STATE_DIRECTORY } from "../../../state-contract.js";
|
|
5
|
+
import { KnownFileTransactionError, matchesKnownFileImage, maximumKnownFileEvidenceBytes, observeKnownFile } from "./node-known-file-transaction-filesystem.js";
|
|
6
|
+
import { NodeKnownFileTransactionJournalStore } from "./node-known-file-transaction-journal-store.js";
|
|
7
|
+
export async function observeKnownFileRecoveryEvidence(root) {
|
|
8
|
+
const [version, buildIdentity] = await Promise.all([
|
|
9
|
+
installedRepositoryMutationVersion(),
|
|
10
|
+
installedRepositoryMutationBuildIdentity()
|
|
11
|
+
]);
|
|
12
|
+
const artifact = { name: REPOSITORY_MUTATION_PACKAGE_NAME, buildIdentity, version };
|
|
13
|
+
const store = new NodeKnownFileTransactionJournalStore(join(root, LOCAL_STATE_DIRECTORY), artifact, artifact);
|
|
14
|
+
await store.canonicalizeTemporary();
|
|
15
|
+
const observed = await store.read();
|
|
16
|
+
if (observed === undefined) {
|
|
17
|
+
throw new KnownFileTransactionError("KNOWN_FILE_JOURNAL_MISSING", "Known-file recovery journal disappeared.");
|
|
18
|
+
}
|
|
19
|
+
return {
|
|
20
|
+
installedBuild: {
|
|
21
|
+
ownerArtifact: artifact,
|
|
22
|
+
kernelArtifact: artifact
|
|
23
|
+
},
|
|
24
|
+
store,
|
|
25
|
+
stored: observed
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
export async function verifyRolledBackKnownFileState(root, journal) {
|
|
29
|
+
for (const [index, operation] of journal.plan.operations.entries()) {
|
|
30
|
+
const journalOperation = journal.operations[index];
|
|
31
|
+
const observed = await observeKnownFile(root, operation.path, maximumKnownFileEvidenceBytes(operation));
|
|
32
|
+
if (journalOperation.state === "already-satisfied") {
|
|
33
|
+
if (!matchesKnownFileImage(observed, operation.postimage)) {
|
|
34
|
+
throw new KnownFileTransactionError("KNOWN_FILE_RECOVERY_CONFLICT", `Unchanged guard drifted during rollback: ${operation.path}.`);
|
|
35
|
+
}
|
|
36
|
+
continue;
|
|
37
|
+
}
|
|
38
|
+
if (operation.precondition.state === "absent") {
|
|
39
|
+
if (observed.state !== "absent") {
|
|
40
|
+
throw new KnownFileTransactionError("KNOWN_FILE_RECOVERY_CONFLICT", `Absent preimage was not restored: ${operation.path}.`);
|
|
41
|
+
}
|
|
42
|
+
continue;
|
|
43
|
+
}
|
|
44
|
+
const matched = journalOperation.matchedPreimage;
|
|
45
|
+
if (matched === undefined ||
|
|
46
|
+
!matchesKnownFileImage(observed, operation.precondition.acceptedPreimages[matched])) {
|
|
47
|
+
throw new KnownFileTransactionError("KNOWN_FILE_RECOVERY_CONFLICT", `Exact preimage was not restored: ${operation.path}.`);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
//# sourceMappingURL=node-known-file-recovery-observation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"node-known-file-recovery-observation.js","sourceRoot":"","sources":["../../../../src/repository-mutation/adapters/node/node-known-file-recovery-observation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAEjC,OAAO,EAAE,wCAAwC,EAAE,MAAM,yCAAyC,CAAC;AACnG,OAAO,EAAE,kCAAkC,EAAE,gCAAgC,EAAE,MAAM,6BAA6B,CAAC;AACnH,OAAO,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AAMnE,OAAO,EACL,yBAAyB,EACzB,qBAAqB,EACrB,6BAA6B,EAC7B,gBAAgB,EACjB,MAAM,6CAA6C,CAAC;AACrD,OAAO,EACL,oCAAoC,EAErC,MAAM,gDAAgD,CAAC;AAaxD,MAAM,CAAC,KAAK,UAAU,gCAAgC,CACpD,IAAY;IAEZ,MAAM,CAAC,OAAO,EAAE,aAAa,CAAC,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC;QACjD,kCAAkC,EAAE;QACpC,wCAAwC,EAAE;KAC3C,CAAC,CAAC;IACH,MAAM,QAAQ,GAAG,EAAE,IAAI,EAAE,gCAAgC,EAAE,aAAa,EAAE,OAAO,EAAE,CAAC;IACpF,MAAM,KAAK,GAAG,IAAI,oCAAoC,CACpD,IAAI,CAAC,IAAI,EAAE,qBAAqB,CAAC,EAAE,QAAQ,EAAE,QAAQ,CACtD,CAAC;IACF,MAAM,KAAK,CAAC,qBAAqB,EAAE,CAAC;IACpC,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,IAAI,EAAE,CAAC;IACpC,IAAI,QAAQ,KAAK,SAAS,EAAE,CAAC;QAC3B,MAAM,IAAI,yBAAyB,CACjC,4BAA4B,EAC5B,0CAA0C,CAC3C,CAAC;IACJ,CAAC;IACD,OAAO;QACL,cAAc,EAAE;YACd,aAAa,EAAE,QAAQ;YACvB,cAAc,EAAE,QAAQ;SACzB;QACD,KAAK;QACL,MAAM,EAAE,QA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