semantic-atlas 0.3.0 → 1.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/.agents/skills/semantic-atlas/SKILL.md +134 -166
- package/.agents/skills/semantic-atlas/agents/openai.yaml +4 -0
- package/.agents/skills/semantic-atlas/references/observations.md +131 -0
- package/.agents/skills/semantic-atlas/scripts/query-context.mjs +110 -0
- package/.agents/skills/semantic-atlas-maintenance/SKILL.md +93 -0
- package/.agents/skills/semantic-atlas-maintenance/agents/openai.yaml +4 -0
- package/.agents/skills/semantic-atlas-maintenance/references/reconciliation.md +56 -0
- package/README.md +134 -239
- package/dist/application/map-application.d.ts +24 -0
- package/dist/application/map-application.d.ts.map +1 -0
- package/dist/application/map-application.js +134 -0
- package/dist/application/map-application.js.map +1 -0
- package/dist/cli/bin.js +6 -35
- package/dist/cli/bin.js.map +1 -0
- package/dist/cli/observation-commands.d.ts +16 -0
- package/dist/cli/observation-commands.d.ts.map +1 -0
- package/dist/cli/observation-commands.js +118 -0
- package/dist/cli/observation-commands.js.map +1 -0
- package/dist/cli/projection-writer.d.ts +2 -0
- package/dist/cli/projection-writer.d.ts.map +1 -0
- package/dist/cli/projection-writer.js +9 -0
- package/dist/cli/projection-writer.js.map +1 -0
- package/dist/cli/reconciliation-command.d.ts +7 -0
- package/dist/cli/reconciliation-command.d.ts.map +1 -0
- package/dist/cli/reconciliation-command.js +33 -0
- package/dist/cli/reconciliation-command.js.map +1 -0
- package/dist/cli/run-cli.d.ts +21 -0
- package/dist/cli/run-cli.d.ts.map +1 -0
- package/dist/cli/run-cli.js +299 -0
- package/dist/cli/run-cli.js.map +1 -0
- package/dist/contracts/cli.d.ts +166 -1211
- package/dist/contracts/cli.d.ts.map +1 -1
- package/dist/contracts/cli.js +2 -232
- package/dist/contracts/cli.js.map +1 -0
- package/dist/contracts/insights.d.ts +39 -1
- package/dist/contracts/insights.d.ts.map +1 -1
- package/dist/contracts/insights.js +2 -1
- package/dist/contracts/insights.js.map +1 -0
- package/dist/contracts/map.d.ts +154 -0
- package/dist/contracts/map.d.ts.map +1 -0
- package/dist/contracts/map.js +60 -0
- package/dist/contracts/map.js.map +1 -0
- package/dist/contracts/observation.d.ts +649 -0
- package/dist/contracts/observation.d.ts.map +1 -0
- package/dist/contracts/observation.js +140 -0
- package/dist/contracts/observation.js.map +1 -0
- package/dist/contracts/projection.d.ts +7 -0
- package/dist/contracts/projection.d.ts.map +1 -0
- package/dist/contracts/projection.js +2 -0
- package/dist/contracts/projection.js.map +1 -0
- package/dist/contracts/reconciliation.d.ts +40 -0
- package/dist/contracts/reconciliation.d.ts.map +1 -0
- package/dist/contracts/reconciliation.js +2 -0
- package/dist/contracts/reconciliation.js.map +1 -0
- package/dist/index.d.ts +7 -17
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -9
- package/dist/index.js.map +1 -0
- package/dist/insights/insight-service.d.ts +14 -0
- package/dist/insights/insight-service.d.ts.map +1 -0
- package/dist/insights/insight-service.js +129 -0
- package/dist/insights/insight-service.js.map +1 -0
- package/dist/map/business-graph.d.ts +32 -0
- package/dist/map/business-graph.d.ts.map +1 -0
- package/dist/map/business-graph.js +122 -0
- package/dist/map/business-graph.js.map +1 -0
- package/dist/map/map-document-loader.d.ts +13 -0
- package/dist/map/map-document-loader.d.ts.map +1 -0
- package/dist/map/map-document-loader.js +86 -0
- package/dist/map/map-document-loader.js.map +1 -0
- package/dist/map/map-validator.d.ts +12 -0
- package/dist/map/map-validator.d.ts.map +1 -0
- package/dist/map/map-validator.js +322 -0
- package/dist/map/map-validator.js.map +1 -0
- package/dist/observations/observation-application.d.ts +23 -0
- package/dist/observations/observation-application.d.ts.map +1 -0
- package/dist/observations/observation-application.js +62 -0
- package/dist/observations/observation-application.js.map +1 -0
- package/dist/observations/observation-claim-manager.d.ts +13 -0
- package/dist/observations/observation-claim-manager.d.ts.map +1 -0
- package/dist/observations/observation-claim-manager.js +247 -0
- package/dist/observations/observation-claim-manager.js.map +1 -0
- package/dist/observations/observation-store.d.ts +43 -0
- package/dist/observations/observation-store.d.ts.map +1 -0
- package/dist/observations/observation-store.js +208 -0
- package/dist/observations/observation-store.js.map +1 -0
- package/dist/observations/repository-identity.d.ts +12 -0
- package/dist/observations/repository-identity.d.ts.map +1 -0
- package/dist/observations/repository-identity.js +108 -0
- package/dist/observations/repository-identity.js.map +1 -0
- package/dist/query/context-query-service.d.ts +15 -0
- package/dist/query/context-query-service.d.ts.map +1 -0
- package/dist/query/context-query-service.js +36 -0
- package/dist/query/context-query-service.js.map +1 -0
- package/dist/reconciliation/reconciliation-service.d.ts +10 -0
- package/dist/reconciliation/reconciliation-service.d.ts.map +1 -0
- package/dist/reconciliation/reconciliation-service.js +116 -0
- package/dist/reconciliation/reconciliation-service.js.map +1 -0
- package/dist/rendering/map-projector.d.ts +8 -0
- package/dist/rendering/map-projector.d.ts.map +1 -0
- package/dist/rendering/map-projector.js +386 -0
- package/dist/rendering/map-projector.js.map +1 -0
- package/dist/setup/managed-skill-installer.d.ts +60 -0
- package/dist/setup/managed-skill-installer.d.ts.map +1 -0
- package/dist/setup/managed-skill-installer.js +307 -0
- package/dist/setup/managed-skill-installer.js.map +1 -0
- package/dist/setup/package-identity.d.ts +6 -0
- package/dist/setup/package-identity.d.ts.map +1 -0
- package/dist/setup/package-identity.js +16 -0
- package/dist/setup/package-identity.js.map +1 -0
- package/dist/setup/package-upgrader.d.ts +10 -22
- package/dist/setup/package-upgrader.d.ts.map +1 -1
- package/dist/setup/package-upgrader.js +60 -76
- package/dist/setup/package-upgrader.js.map +1 -0
- package/docs/architecture.md +428 -0
- package/docs/evaluation.md +220 -174
- package/docs/index.md +27 -40
- package/docs/map-format.md +224 -0
- package/docs/observations.md +175 -0
- package/docs/product-contract.md +295 -137
- package/examples/commerce.yaml +204 -0
- package/package.json +31 -30
- package/.agents/skills/semantic-atlas/references/graph-patch.md +0 -190
- package/.agents/skills/semantic-atlas/references/product-feedback.md +0 -34
- package/.agents/skills/semantic-atlas/references/result-routing.md +0 -104
- package/.agents/skills/semantic-atlas/references/snapshot-bootstrap.md +0 -42
- package/.agents/skills/semantic-atlas-insights/SKILL.md +0 -55
- package/README.zh-CN.md +0 -273
- package/dist/business-flow/business-flow-derivation-service.d.ts +0 -11
- package/dist/business-flow/business-flow-derivation-service.d.ts.map +0 -1
- package/dist/business-flow/business-flow-derivation-service.js +0 -151
- package/dist/business-flow/business-flow-draft.d.ts +0 -16
- package/dist/business-flow/business-flow-draft.d.ts.map +0 -1
- package/dist/business-flow/business-flow-draft.js +0 -150
- package/dist/business-flow/framework-business-strategy.d.ts +0 -7
- package/dist/business-flow/framework-business-strategy.d.ts.map +0 -1
- package/dist/business-flow/framework-business-strategy.js +0 -1
- package/dist/business-flow/strategies/bullmq-business-strategy.d.ts +0 -10
- package/dist/business-flow/strategies/bullmq-business-strategy.d.ts.map +0 -1
- package/dist/business-flow/strategies/bullmq-business-strategy.js +0 -79
- package/dist/business-flow/strategies/called-operation-derivation.d.ts +0 -13
- package/dist/business-flow/strategies/called-operation-derivation.d.ts.map +0 -1
- package/dist/business-flow/strategies/called-operation-derivation.js +0 -32
- package/dist/business-flow/strategies/graphql-business-strategy.d.ts +0 -8
- package/dist/business-flow/strategies/graphql-business-strategy.d.ts.map +0 -1
- package/dist/business-flow/strategies/graphql-business-strategy.js +0 -65
- package/dist/business-flow/strategies/nestjs-business-strategy.d.ts +0 -8
- package/dist/business-flow/strategies/nestjs-business-strategy.d.ts.map +0 -1
- package/dist/business-flow/strategies/nestjs-business-strategy.js +0 -72
- package/dist/business-flow/strategies/strategy-helpers.d.ts +0 -32
- package/dist/business-flow/strategies/strategy-helpers.d.ts.map +0 -1
- package/dist/business-flow/strategies/strategy-helpers.js +0 -49
- package/dist/business-flow/strategies/typeorm-business-strategy.d.ts +0 -10
- package/dist/business-flow/strategies/typeorm-business-strategy.d.ts.map +0 -1
- package/dist/business-flow/strategies/typeorm-business-strategy.js +0 -136
- package/dist/business-flow/strategies/verified-invariant-strategy.d.ts +0 -5
- package/dist/business-flow/strategies/verified-invariant-strategy.d.ts.map +0 -1
- package/dist/business-flow/strategies/verified-invariant-strategy.js +0 -38
- package/dist/business-flow/strategies/verified-test-strategy.d.ts +0 -5
- package/dist/business-flow/strategies/verified-test-strategy.d.ts.map +0 -1
- package/dist/business-flow/strategies/verified-test-strategy.js +0 -26
- package/dist/business-flow/structural-flow-catalog.d.ts +0 -21
- package/dist/business-flow/structural-flow-catalog.d.ts.map +0 -1
- package/dist/business-flow/structural-flow-catalog.js +0 -125
- package/dist/business-flow/types.d.ts +0 -51
- package/dist/business-flow/types.d.ts.map +0 -1
- package/dist/business-flow/types.js +0 -1
- package/dist/cli/argument-parser.d.ts +0 -3
- package/dist/cli/argument-parser.d.ts.map +0 -1
- package/dist/cli/argument-parser.js +0 -200
- package/dist/cli/cli-application.d.ts +0 -39
- package/dist/cli/cli-application.d.ts.map +0 -1
- package/dist/cli/cli-application.js +0 -571
- package/dist/cli/cli-error.d.ts +0 -12
- package/dist/cli/cli-error.d.ts.map +0 -1
- package/dist/cli/cli-error.js +0 -44
- package/dist/cli/cli-presenter.d.ts +0 -14
- package/dist/cli/cli-presenter.d.ts.map +0 -1
- package/dist/cli/cli-presenter.js +0 -36
- package/dist/cli/insights-cli.d.ts +0 -6
- package/dist/cli/insights-cli.d.ts.map +0 -1
- package/dist/cli/insights-cli.js +0 -236
- package/dist/cli/main.d.ts +0 -3
- package/dist/cli/main.d.ts.map +0 -1
- package/dist/cli/main.js +0 -137
- package/dist/cli/standalone-cli.d.ts +0 -3
- package/dist/cli/standalone-cli.d.ts.map +0 -1
- package/dist/cli/standalone-cli.js +0 -96
- package/dist/cli/types.d.ts +0 -49
- package/dist/cli/types.d.ts.map +0 -1
- package/dist/cli/types.js +0 -1
- package/dist/contracts/graph.d.ts +0 -266
- package/dist/contracts/graph.d.ts.map +0 -1
- package/dist/contracts/graph.js +0 -182
- package/dist/contracts/identifiers.d.ts +0 -4
- package/dist/contracts/identifiers.d.ts.map +0 -1
- package/dist/contracts/identifiers.js +0 -7
- package/dist/contracts/public-contracts.d.ts +0 -5
- package/dist/contracts/public-contracts.d.ts.map +0 -1
- package/dist/contracts/public-contracts.js +0 -4
- package/dist/evaluation/comparison.d.ts +0 -30
- package/dist/evaluation/comparison.d.ts.map +0 -1
- package/dist/evaluation/comparison.js +0 -108
- package/dist/evaluation/contracts.d.ts +0 -301
- package/dist/evaluation/contracts.d.ts.map +0 -1
- package/dist/evaluation/contracts.js +0 -413
- package/dist/graph/graph-store.d.ts +0 -55
- package/dist/graph/graph-store.d.ts.map +0 -1
- package/dist/graph/graph-store.js +0 -912
- package/dist/graph/types.d.ts +0 -189
- package/dist/graph/types.d.ts.map +0 -1
- package/dist/graph/types.js +0 -1
- package/dist/insights/contracts.d.ts +0 -266
- package/dist/insights/contracts.d.ts.map +0 -1
- package/dist/insights/contracts.js +0 -124
- package/dist/insights/insights-store.d.ts +0 -73
- package/dist/insights/insights-store.d.ts.map +0 -1
- package/dist/insights/insights-store.js +0 -246
- package/dist/knowledge/business-knowledge-service.d.ts +0 -24
- package/dist/knowledge/business-knowledge-service.d.ts.map +0 -1
- package/dist/knowledge/business-knowledge-service.js +0 -200
- package/dist/knowledge/graph-patch-conflict-error.d.ts +0 -8
- package/dist/knowledge/graph-patch-conflict-error.d.ts.map +0 -1
- package/dist/knowledge/graph-patch-conflict-error.js +0 -12
- package/dist/knowledge/structural-target-binding.d.ts +0 -14
- package/dist/knowledge/structural-target-binding.d.ts.map +0 -1
- package/dist/knowledge/structural-target-binding.js +0 -11
- package/dist/package-metadata.d.ts +0 -2
- package/dist/package-metadata.d.ts.map +0 -1
- package/dist/package-metadata.js +0 -9
- package/dist/repository/git-command.d.ts +0 -3
- package/dist/repository/git-command.d.ts.map +0 -1
- package/dist/repository/git-command.js +0 -25
- package/dist/repository/repository-inspector.d.ts +0 -7
- package/dist/repository/repository-inspector.d.ts.map +0 -1
- package/dist/repository/repository-inspector.js +0 -84
- package/dist/repository/repository-language-support.d.ts +0 -14
- package/dist/repository/repository-language-support.d.ts.map +0 -1
- package/dist/repository/repository-language-support.js +0 -64
- package/dist/repository/types.d.ts +0 -9
- package/dist/repository/types.d.ts.map +0 -1
- package/dist/repository/types.js +0 -1
- package/dist/runtime/sqlite-compatibility-process.d.ts +0 -8
- package/dist/runtime/sqlite-compatibility-process.d.ts.map +0 -1
- package/dist/runtime/sqlite-compatibility-process.js +0 -20
- package/dist/setup/skill-installer.d.ts +0 -20
- package/dist/setup/skill-installer.d.ts.map +0 -1
- package/dist/setup/skill-installer.js +0 -187
- package/dist/snapshots/repository-snapshot.d.ts +0 -4
- package/dist/snapshots/repository-snapshot.d.ts.map +0 -1
- package/dist/snapshots/repository-snapshot.js +0 -119
- package/dist/snapshots/types.d.ts +0 -30
- package/dist/snapshots/types.d.ts.map +0 -1
- package/dist/snapshots/types.js +0 -1
- package/dist/storage/atlas-database.d.ts +0 -19
- package/dist/storage/atlas-database.d.ts.map +0 -1
- package/dist/storage/atlas-database.js +0 -433
- package/dist/storage/snapshot-store.d.ts +0 -19
- package/dist/storage/snapshot-store.d.ts.map +0 -1
- package/dist/storage/snapshot-store.js +0 -74
- package/dist/structural-backend/codegraph-backend.d.ts +0 -57
- package/dist/structural-backend/codegraph-backend.d.ts.map +0 -1
- package/dist/structural-backend/codegraph-backend.js +0 -1230
- package/dist/structural-backend/codegraph-worker-client.d.ts +0 -5
- package/dist/structural-backend/codegraph-worker-client.d.ts.map +0 -1
- package/dist/structural-backend/codegraph-worker-client.js +0 -118
- package/dist/structural-backend/codegraph-worker-protocol.d.ts +0 -35
- package/dist/structural-backend/codegraph-worker-protocol.d.ts.map +0 -1
- package/dist/structural-backend/codegraph-worker-protocol.js +0 -1
- package/dist/structural-backend/codegraph-worker.d.ts +0 -2
- package/dist/structural-backend/codegraph-worker.d.ts.map +0 -1
- package/dist/structural-backend/codegraph-worker.js +0 -131
- package/dist/structural-backend/process-instance.d.ts +0 -18
- package/dist/structural-backend/process-instance.d.ts.map +0 -1
- package/dist/structural-backend/process-instance.js +0 -207
- package/dist/structural-backend/structural-fact-changes.d.ts +0 -7
- package/dist/structural-backend/structural-fact-changes.d.ts.map +0 -1
- package/dist/structural-backend/structural-fact-changes.js +0 -78
- package/dist/structural-backend/structural-projection-bootstrapper.d.ts +0 -10
- package/dist/structural-backend/structural-projection-bootstrapper.d.ts.map +0 -1
- package/dist/structural-backend/structural-projection-bootstrapper.js +0 -295
- package/dist/structural-backend/structural-publication.d.ts +0 -13
- package/dist/structural-backend/structural-publication.d.ts.map +0 -1
- package/dist/structural-backend/structural-publication.js +0 -255
- package/dist/structural-backend/structural-write-lock.d.ts +0 -8
- package/dist/structural-backend/structural-write-lock.d.ts.map +0 -1
- package/dist/structural-backend/structural-write-lock.js +0 -415
- package/dist/structural-backend/types.d.ts +0 -144
- package/dist/structural-backend/types.d.ts.map +0 -1
- package/dist/structural-backend/types.js +0 -11
- package/dist/world/business-map-projector.d.ts +0 -14
- package/dist/world/business-map-projector.d.ts.map +0 -1
- package/dist/world/business-map-projector.js +0 -178
- package/dist/world/types.d.ts +0 -77
- package/dist/world/types.d.ts.map +0 -1
- package/dist/world/types.js +0 -1
- package/dist/world/world-graph-query.d.ts +0 -26
- package/dist/world/world-graph-query.d.ts.map +0 -1
- package/dist/world/world-graph-query.js +0 -250
- package/dist/world/world-model-service.d.ts +0 -21
- package/dist/world/world-model-service.d.ts.map +0 -1
- package/dist/world/world-model-service.js +0 -219
- package/dist/world/world-snapshot-store.d.ts +0 -40
- package/dist/world/world-snapshot-store.d.ts.map +0 -1
- package/dist/world/world-snapshot-store.js +0 -581
- package/docs/README.md +0 -30
- package/docs/architecture/codegraph-backend.md +0 -190
- package/docs/architecture/continuous-business-learning.md +0 -240
- package/docs/contracts/cli-v1.md +0 -164
- package/docs/contracts/graph-model.md +0 -106
- package/docs/contracts/graph-patch-v1.md +0 -105
- package/docs/contracts/insights-v1.md +0 -84
- package/docs/log.md +0 -80
- package/docs/mindmaps/semantic-atlas-overview.drawio +0 -255
- package/docs/mindmaps/semantic-atlas-overview.png +0 -0
- package/docs/mindmaps/semantic-atlas-overview.zh-CN.drawio +0 -255
- package/docs/mindmaps/semantic-atlas-overview.zh-CN.png +0 -0
- package/schemas/cli-envelope-v1.schema.json +0 -1244
- package/schemas/evaluation-plan-v1.schema.json +0 -211
- package/schemas/evaluation-run-v1.schema.json +0 -659
- package/schemas/graph-patch-v1.schema.json +0 -392
- package/schemas/insights-envelope-v1.schema.json +0 -428
|
@@ -1,295 +0,0 @@
|
|
|
1
|
-
var __addDisposableResource = (this && this.__addDisposableResource) || function (env, value, async) {
|
|
2
|
-
if (value !== null && value !== void 0) {
|
|
3
|
-
if (typeof value !== "object" && typeof value !== "function") throw new TypeError("Object expected.");
|
|
4
|
-
var dispose, inner;
|
|
5
|
-
if (async) {
|
|
6
|
-
if (!Symbol.asyncDispose) throw new TypeError("Symbol.asyncDispose is not defined.");
|
|
7
|
-
dispose = value[Symbol.asyncDispose];
|
|
8
|
-
}
|
|
9
|
-
if (dispose === void 0) {
|
|
10
|
-
if (!Symbol.dispose) throw new TypeError("Symbol.dispose is not defined.");
|
|
11
|
-
dispose = value[Symbol.dispose];
|
|
12
|
-
if (async) inner = dispose;
|
|
13
|
-
}
|
|
14
|
-
if (typeof dispose !== "function") throw new TypeError("Object not disposable.");
|
|
15
|
-
if (inner) dispose = function() { try { inner.call(this); } catch (e) { return Promise.reject(e); } };
|
|
16
|
-
env.stack.push({ value: value, dispose: dispose, async: async });
|
|
17
|
-
}
|
|
18
|
-
else if (async) {
|
|
19
|
-
env.stack.push({ async: true });
|
|
20
|
-
}
|
|
21
|
-
return value;
|
|
22
|
-
};
|
|
23
|
-
var __disposeResources = (this && this.__disposeResources) || (function (SuppressedError) {
|
|
24
|
-
return function (env) {
|
|
25
|
-
function fail(e) {
|
|
26
|
-
env.error = env.hasError ? new SuppressedError(e, env.error, "An error was suppressed during disposal.") : e;
|
|
27
|
-
env.hasError = true;
|
|
28
|
-
}
|
|
29
|
-
var r, s = 0;
|
|
30
|
-
function next() {
|
|
31
|
-
while (r = env.stack.pop()) {
|
|
32
|
-
try {
|
|
33
|
-
if (!r.async && s === 1) return s = 0, env.stack.push(r), Promise.resolve().then(next);
|
|
34
|
-
if (r.dispose) {
|
|
35
|
-
var result = r.dispose.call(r.value);
|
|
36
|
-
if (r.async) return s |= 2, Promise.resolve(result).then(next, function(e) { fail(e); return next(); });
|
|
37
|
-
}
|
|
38
|
-
else s |= 1;
|
|
39
|
-
}
|
|
40
|
-
catch (e) {
|
|
41
|
-
fail(e);
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
if (s === 1) return env.hasError ? Promise.reject(env.error) : Promise.resolve();
|
|
45
|
-
if (env.hasError) throw env.error;
|
|
46
|
-
}
|
|
47
|
-
return next();
|
|
48
|
-
};
|
|
49
|
-
})(typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
50
|
-
var e = new Error(message);
|
|
51
|
-
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
52
|
-
});
|
|
53
|
-
import { randomUUID } from "node:crypto";
|
|
54
|
-
import { lstat, rename, rm } from "node:fs/promises";
|
|
55
|
-
import { createRequire } from "node:module";
|
|
56
|
-
import { join, resolve } from "node:path";
|
|
57
|
-
import { DatabaseSync } from "node:sqlite";
|
|
58
|
-
import { isSupportedSource, inspectGitRepository } from "../repository/repository-inspector.js";
|
|
59
|
-
import { AtlasDatabase } from "../storage/atlas-database.js";
|
|
60
|
-
import { CodeGraphStructuralBackend } from "./codegraph-backend.js";
|
|
61
|
-
import { backupSqliteDatabase } from "./structural-publication.js";
|
|
62
|
-
import { StructuralWriteLock } from "./structural-write-lock.js";
|
|
63
|
-
import { STRUCTURAL_BACKEND_VERSION } from "./types.js";
|
|
64
|
-
const ATLAS_DIRECTORY = ".atlas";
|
|
65
|
-
const CODEGRAPH_DATABASE = "codegraph.db";
|
|
66
|
-
const ATLAS_WRITE_LOCK = "semantic-atlas.lock";
|
|
67
|
-
const CODEGRAPH_DIRECTORY_ENVIRONMENT = "CODEGRAPH_DIR";
|
|
68
|
-
const require = createRequire(import.meta.url);
|
|
69
|
-
export class StructuralProjectionBootstrapper {
|
|
70
|
-
#repository;
|
|
71
|
-
#databasePath;
|
|
72
|
-
constructor(repository) {
|
|
73
|
-
this.#repository = repository;
|
|
74
|
-
this.#databasePath = join(repository.worktreeRoot, ATLAS_DIRECTORY, CODEGRAPH_DATABASE);
|
|
75
|
-
}
|
|
76
|
-
async bootstrap(currentSnapshot) {
|
|
77
|
-
if (await pathExists(this.#databasePath)) {
|
|
78
|
-
return false;
|
|
79
|
-
}
|
|
80
|
-
const candidates = await this.findCandidates(currentSnapshot.snapshotId);
|
|
81
|
-
for (const candidate of candidates) {
|
|
82
|
-
if (await this.restoreCandidate(candidate)) {
|
|
83
|
-
return true;
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
return false;
|
|
87
|
-
}
|
|
88
|
-
async findCandidates(currentSnapshotId) {
|
|
89
|
-
const env_1 = { stack: [], error: void 0, hasError: false };
|
|
90
|
-
try {
|
|
91
|
-
const atlas = __addDisposableResource(env_1, new AtlasDatabase(this.#repository), false);
|
|
92
|
-
const candidates = [];
|
|
93
|
-
for (const worktreeRoot of this.#repository.worktreeRoots) {
|
|
94
|
-
if (resolve(worktreeRoot) === resolve(this.#repository.worktreeRoot)) {
|
|
95
|
-
continue;
|
|
96
|
-
}
|
|
97
|
-
try {
|
|
98
|
-
const repository = await inspectGitRepository(worktreeRoot);
|
|
99
|
-
if (repository.repositoryId !== this.#repository.repositoryId) {
|
|
100
|
-
continue;
|
|
101
|
-
}
|
|
102
|
-
const row = atlas.connection.prepare(`
|
|
103
|
-
SELECT
|
|
104
|
-
state.current_snapshot_id,
|
|
105
|
-
state.backend_version,
|
|
106
|
-
state.extraction_version,
|
|
107
|
-
state.published_at,
|
|
108
|
-
snapshot.payload
|
|
109
|
-
FROM atlas_worktree_states AS state
|
|
110
|
-
JOIN atlas_repository_snapshots AS snapshot
|
|
111
|
-
ON snapshot.repository_id = state.repository_id
|
|
112
|
-
AND snapshot.snapshot_id = state.current_snapshot_id
|
|
113
|
-
WHERE state.repository_id = ?
|
|
114
|
-
AND state.git_directory = ?
|
|
115
|
-
AND state.status = 'current'
|
|
116
|
-
`).get(this.#repository.repositoryId, repository.gitDirectory);
|
|
117
|
-
if (row === undefined
|
|
118
|
-
|| row.backend_version !== STRUCTURAL_BACKEND_VERSION
|
|
119
|
-
|| row.extraction_version === null
|
|
120
|
-
|| row.published_at === null) {
|
|
121
|
-
continue;
|
|
122
|
-
}
|
|
123
|
-
candidates.push({
|
|
124
|
-
repository,
|
|
125
|
-
snapshot: JSON.parse(row.payload),
|
|
126
|
-
backendVersion: row.backend_version,
|
|
127
|
-
extractionVersion: row.extraction_version,
|
|
128
|
-
publishedAt: row.published_at,
|
|
129
|
-
});
|
|
130
|
-
}
|
|
131
|
-
catch {
|
|
132
|
-
continue;
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
return candidates.sort((left, right) => (Number(right.snapshot.snapshotId === currentSnapshotId)
|
|
136
|
-
- Number(left.snapshot.snapshotId === currentSnapshotId)
|
|
137
|
-
|| right.publishedAt.localeCompare(left.publishedAt)
|
|
138
|
-
|| normalizePath(left.repository.worktreeRoot)
|
|
139
|
-
.localeCompare(normalizePath(right.repository.worktreeRoot))));
|
|
140
|
-
}
|
|
141
|
-
catch (e_1) {
|
|
142
|
-
env_1.error = e_1;
|
|
143
|
-
env_1.hasError = true;
|
|
144
|
-
}
|
|
145
|
-
finally {
|
|
146
|
-
__disposeResources(env_1);
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
async restoreCandidate(candidate) {
|
|
150
|
-
const sourceDatabase = join(candidate.repository.worktreeRoot, ATLAS_DIRECTORY, CODEGRAPH_DATABASE);
|
|
151
|
-
const sourceLockPath = join(candidate.repository.worktreeRoot, ATLAS_DIRECTORY, ATLAS_WRITE_LOCK);
|
|
152
|
-
let sourceLock;
|
|
153
|
-
try {
|
|
154
|
-
sourceLock = StructuralWriteLock.acquire(sourceLockPath);
|
|
155
|
-
}
|
|
156
|
-
catch {
|
|
157
|
-
return false;
|
|
158
|
-
}
|
|
159
|
-
if (sourceLock === undefined) {
|
|
160
|
-
return false;
|
|
161
|
-
}
|
|
162
|
-
const stagingPath = join(this.#repository.worktreeRoot, ATLAS_DIRECTORY, `.codegraph-bootstrap-${randomUUID()}.db`);
|
|
163
|
-
try {
|
|
164
|
-
await requireOrdinaryDatabase(sourceDatabase);
|
|
165
|
-
if (!projectionMatchesSnapshot(sourceDatabase, candidate.snapshot, candidate.backendVersion, candidate.extractionVersion) || !await usesCurrentExtraction(candidate.repository)) {
|
|
166
|
-
return false;
|
|
167
|
-
}
|
|
168
|
-
await new CodeGraphStructuralBackend(this.#repository).prepareStorageForBootstrap();
|
|
169
|
-
if (await pathExists(this.#databasePath)) {
|
|
170
|
-
return false;
|
|
171
|
-
}
|
|
172
|
-
await backupSqliteDatabase(sourceDatabase, stagingPath);
|
|
173
|
-
if (!projectionMatchesSnapshot(stagingPath, candidate.snapshot, candidate.backendVersion, candidate.extractionVersion)) {
|
|
174
|
-
return false;
|
|
175
|
-
}
|
|
176
|
-
await rename(stagingPath, this.#databasePath);
|
|
177
|
-
return true;
|
|
178
|
-
}
|
|
179
|
-
catch {
|
|
180
|
-
return false;
|
|
181
|
-
}
|
|
182
|
-
finally {
|
|
183
|
-
sourceLock.release();
|
|
184
|
-
await rm(stagingPath, { force: true }).catch(() => undefined);
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
async function usesCurrentExtraction(repository) {
|
|
189
|
-
const sdk = require("@colbymchenry/codegraph");
|
|
190
|
-
let graph;
|
|
191
|
-
const originalDirectory = process.env[CODEGRAPH_DIRECTORY_ENVIRONMENT];
|
|
192
|
-
process.env[CODEGRAPH_DIRECTORY_ENVIRONMENT] = ATLAS_DIRECTORY;
|
|
193
|
-
try {
|
|
194
|
-
graph = await sdk.CodeGraph.open(repository.worktreeRoot, {
|
|
195
|
-
sync: false,
|
|
196
|
-
readOnly: true,
|
|
197
|
-
});
|
|
198
|
-
return !graph.isIndexStale();
|
|
199
|
-
}
|
|
200
|
-
catch {
|
|
201
|
-
return false;
|
|
202
|
-
}
|
|
203
|
-
finally {
|
|
204
|
-
graph?.close();
|
|
205
|
-
if (originalDirectory === undefined) {
|
|
206
|
-
delete process.env[CODEGRAPH_DIRECTORY_ENVIRONMENT];
|
|
207
|
-
}
|
|
208
|
-
else {
|
|
209
|
-
process.env[CODEGRAPH_DIRECTORY_ENVIRONMENT] = originalDirectory;
|
|
210
|
-
}
|
|
211
|
-
}
|
|
212
|
-
}
|
|
213
|
-
function projectionMatchesSnapshot(databasePath, snapshot, backendVersion, extractionVersion) {
|
|
214
|
-
const database = new DatabaseSync(databasePath, { readOnly: true });
|
|
215
|
-
try {
|
|
216
|
-
const integrity = database.prepare("PRAGMA integrity_check").get();
|
|
217
|
-
if (integrity?.integrity_check !== "ok") {
|
|
218
|
-
return false;
|
|
219
|
-
}
|
|
220
|
-
const atlasObjects = database.prepare(`
|
|
221
|
-
SELECT COUNT(*) AS count
|
|
222
|
-
FROM sqlite_schema
|
|
223
|
-
WHERE name LIKE 'atlas\\_%' ESCAPE '\\'
|
|
224
|
-
`).get();
|
|
225
|
-
if (atlasObjects.count !== 0) {
|
|
226
|
-
return false;
|
|
227
|
-
}
|
|
228
|
-
const metadata = new Map(database.prepare(`
|
|
229
|
-
SELECT key, value
|
|
230
|
-
FROM project_metadata
|
|
231
|
-
WHERE key IN (
|
|
232
|
-
'index_state',
|
|
233
|
-
'indexed_with_version',
|
|
234
|
-
'indexed_with_extraction_version',
|
|
235
|
-
'index_files_discovered',
|
|
236
|
-
'index_files_accounted'
|
|
237
|
-
)
|
|
238
|
-
`).all()
|
|
239
|
-
.map(({ key, value }) => [key, value]));
|
|
240
|
-
if (metadata.get("index_state") !== "complete"
|
|
241
|
-
|| metadata.get("indexed_with_version") !== backendVersion
|
|
242
|
-
|| Number(metadata.get("indexed_with_extraction_version")) !== extractionVersion
|
|
243
|
-
|| metadata.get("index_files_discovered") !== metadata.get("index_files_accounted")) {
|
|
244
|
-
return false;
|
|
245
|
-
}
|
|
246
|
-
const indexedSources = database.prepare(`
|
|
247
|
-
SELECT path, content_hash, errors
|
|
248
|
-
FROM files
|
|
249
|
-
ORDER BY path
|
|
250
|
-
`).all();
|
|
251
|
-
if (indexedSources.some(({ errors }) => errors !== null && errors !== "[]")) {
|
|
252
|
-
return false;
|
|
253
|
-
}
|
|
254
|
-
const indexedHashes = new Map(indexedSources.map((source) => [
|
|
255
|
-
normalizeRepositoryPath(source.path),
|
|
256
|
-
source.content_hash,
|
|
257
|
-
]));
|
|
258
|
-
const snapshotHashes = new Map(snapshot.files.flatMap((file) => (isSupportedSource(file.path) && file.worktree !== null
|
|
259
|
-
? [[normalizeRepositoryPath(file.path), file.worktree.contentHash]]
|
|
260
|
-
: [])));
|
|
261
|
-
return [...snapshotHashes].every(([path, hash]) => indexedHashes.get(path) === hash)
|
|
262
|
-
&& [...indexedHashes.keys()].every((path) => (!isSupportedSource(path) || snapshotHashes.has(path)));
|
|
263
|
-
}
|
|
264
|
-
catch {
|
|
265
|
-
return false;
|
|
266
|
-
}
|
|
267
|
-
finally {
|
|
268
|
-
database.close();
|
|
269
|
-
}
|
|
270
|
-
}
|
|
271
|
-
async function requireOrdinaryDatabase(databasePath) {
|
|
272
|
-
const metadata = await lstat(databasePath);
|
|
273
|
-
if (!metadata.isFile() || metadata.isSymbolicLink()) {
|
|
274
|
-
throw new Error("A bootstrap source must be a regular CodeGraph database");
|
|
275
|
-
}
|
|
276
|
-
}
|
|
277
|
-
async function pathExists(path) {
|
|
278
|
-
try {
|
|
279
|
-
await lstat(path);
|
|
280
|
-
return true;
|
|
281
|
-
}
|
|
282
|
-
catch (error) {
|
|
283
|
-
if (error instanceof Error && "code" in error && error.code === "ENOENT") {
|
|
284
|
-
return false;
|
|
285
|
-
}
|
|
286
|
-
throw error;
|
|
287
|
-
}
|
|
288
|
-
}
|
|
289
|
-
function normalizeRepositoryPath(path) {
|
|
290
|
-
return path.replaceAll("\\", "/").replace(/^\.\//u, "");
|
|
291
|
-
}
|
|
292
|
-
function normalizePath(path) {
|
|
293
|
-
const normalized = resolve(path).replaceAll("\\", "/");
|
|
294
|
-
return process.platform === "win32" ? normalized.toLowerCase() : normalized;
|
|
295
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
export declare class StructuralPublication {
|
|
2
|
-
#private;
|
|
3
|
-
private constructor();
|
|
4
|
-
get backupPath(): string;
|
|
5
|
-
static begin(databasePath: string, hasPublishedDatabase: boolean): Promise<StructuralPublication>;
|
|
6
|
-
static recoverAbandoned(databasePath: string): Promise<boolean>;
|
|
7
|
-
commit(): Promise<void>;
|
|
8
|
-
rollback(): Promise<void>;
|
|
9
|
-
private cleanupDirectoryPath;
|
|
10
|
-
private requireActive;
|
|
11
|
-
}
|
|
12
|
-
export declare function backupSqliteDatabase(databasePath: string, backupPath: string): Promise<void>;
|
|
13
|
-
//# sourceMappingURL=structural-publication.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"structural-publication.d.ts","sourceRoot":"","sources":["../../src/structural-backend/structural-publication.ts"],"names":[],"mappings":"AA4BA,qBAAa,qBAAqB;;IAOhC,OAAO;IAOP,IAAI,UAAU,IAAI,MAAM,CAEvB;WAEY,KAAK,CAChB,YAAY,EAAE,MAAM,EACpB,oBAAoB,EAAE,OAAO,GAC5B,OAAO,CAAC,qBAAqB,CAAC;WAoBpB,gBAAgB,CAAC,YAAY,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAqB/D,MAAM,IAAI,OAAO,CAAC,IAAI,CAAC;IASvB,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC;IAsB/B,OAAO,CAAC,oBAAoB;IAI5B,OAAO,CAAC,aAAa;CAKtB;AAYD,wBAAsB,oBAAoB,CACxC,YAAY,EAAE,MAAM,EACpB,UAAU,EAAE,MAAM,GACjB,OAAO,CAAC,IAAI,CAAC,CAGf"}
|
|
@@ -1,255 +0,0 @@
|
|
|
1
|
-
import { randomUUID } from "node:crypto";
|
|
2
|
-
import { constants as fileSystemConstants } from "node:fs";
|
|
3
|
-
import { lstat, mkdtemp, open, readdir, realpath, rename, rm, } from "node:fs/promises";
|
|
4
|
-
import { createRequire } from "node:module";
|
|
5
|
-
import { basename, dirname, join, resolve } from "node:path";
|
|
6
|
-
const ACTIVE_PUBLICATION_DIRECTORY = ".structural-publication";
|
|
7
|
-
const STAGING_DIRECTORY_PREFIX = ".structural-publication-staging-";
|
|
8
|
-
const CLEANUP_DIRECTORY_PREFIX = ".structural-publication-cleanup-";
|
|
9
|
-
const PUBLICATION_MANIFEST = "publication.json";
|
|
10
|
-
const PUBLISHED_DATABASE = "published.db";
|
|
11
|
-
const DATABASE_SIDECARS = ["-wal", "-shm", "-journal"];
|
|
12
|
-
const require = createRequire(import.meta.url);
|
|
13
|
-
export class StructuralPublication {
|
|
14
|
-
#databasePath;
|
|
15
|
-
#atlasDirectory;
|
|
16
|
-
#activeDirectory;
|
|
17
|
-
#hasPublishedDatabase;
|
|
18
|
-
#active = true;
|
|
19
|
-
constructor(databasePath, hasPublishedDatabase) {
|
|
20
|
-
this.#databasePath = databasePath;
|
|
21
|
-
this.#atlasDirectory = dirname(databasePath);
|
|
22
|
-
this.#activeDirectory = join(this.#atlasDirectory, ACTIVE_PUBLICATION_DIRECTORY);
|
|
23
|
-
this.#hasPublishedDatabase = hasPublishedDatabase;
|
|
24
|
-
}
|
|
25
|
-
get backupPath() {
|
|
26
|
-
return join(this.#activeDirectory, PUBLISHED_DATABASE);
|
|
27
|
-
}
|
|
28
|
-
static async begin(databasePath, hasPublishedDatabase) {
|
|
29
|
-
const atlasDirectory = await verifyAtlasDatabaseLocation(databasePath);
|
|
30
|
-
const activeDirectory = join(atlasDirectory, ACTIVE_PUBLICATION_DIRECTORY);
|
|
31
|
-
await requireMissingPath(activeDirectory, "An unfinished structural publication already exists");
|
|
32
|
-
const stagingDirectory = await mkdtemp(join(atlasDirectory, STAGING_DIRECTORY_PREFIX));
|
|
33
|
-
try {
|
|
34
|
-
if (hasPublishedDatabase) {
|
|
35
|
-
const backupPath = join(stagingDirectory, PUBLISHED_DATABASE);
|
|
36
|
-
await backupSqliteDatabase(databasePath, backupPath);
|
|
37
|
-
}
|
|
38
|
-
await writeManifest(stagingDirectory, { version: 1, hasPublishedDatabase });
|
|
39
|
-
await rename(stagingDirectory, activeDirectory);
|
|
40
|
-
return new StructuralPublication(databasePath, hasPublishedDatabase);
|
|
41
|
-
}
|
|
42
|
-
catch (error) {
|
|
43
|
-
await rm(stagingDirectory, { recursive: true, force: true });
|
|
44
|
-
throw error;
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
static async recoverAbandoned(databasePath) {
|
|
48
|
-
const atlasDirectory = await verifyAtlasDatabaseLocation(databasePath);
|
|
49
|
-
const activeDirectory = join(atlasDirectory, ACTIVE_PUBLICATION_DIRECTORY);
|
|
50
|
-
await cleanupOrphanedPublicationDirectories(atlasDirectory);
|
|
51
|
-
let manifest;
|
|
52
|
-
try {
|
|
53
|
-
await verifyOwnedDirectory(activeDirectory, "The structural publication state");
|
|
54
|
-
manifest = await readManifest(activeDirectory);
|
|
55
|
-
}
|
|
56
|
-
catch (error) {
|
|
57
|
-
if (isFileSystemError(error, "ENOENT")) {
|
|
58
|
-
return false;
|
|
59
|
-
}
|
|
60
|
-
throw error;
|
|
61
|
-
}
|
|
62
|
-
const publication = new StructuralPublication(databasePath, manifest.hasPublishedDatabase);
|
|
63
|
-
await publication.rollback();
|
|
64
|
-
return true;
|
|
65
|
-
}
|
|
66
|
-
async commit() {
|
|
67
|
-
this.requireActive();
|
|
68
|
-
await verifyOwnedDirectory(this.#activeDirectory, "The structural publication state");
|
|
69
|
-
const cleanupDirectory = this.cleanupDirectoryPath();
|
|
70
|
-
await rename(this.#activeDirectory, cleanupDirectory);
|
|
71
|
-
this.#active = false;
|
|
72
|
-
await rm(cleanupDirectory, { recursive: true, force: true }).catch(() => undefined);
|
|
73
|
-
}
|
|
74
|
-
async rollback() {
|
|
75
|
-
this.requireActive();
|
|
76
|
-
await verifyOwnedDirectory(this.#activeDirectory, "The structural publication state");
|
|
77
|
-
const manifest = await readManifest(this.#activeDirectory);
|
|
78
|
-
if (manifest.hasPublishedDatabase !== this.#hasPublishedDatabase) {
|
|
79
|
-
throw new Error("The structural publication manifest changed during recovery");
|
|
80
|
-
}
|
|
81
|
-
if (this.#hasPublishedDatabase) {
|
|
82
|
-
await verifyOwnedRegularFile(this.backupPath, "The published structural database backup");
|
|
83
|
-
await restoreDatabase(this.backupPath, this.#databasePath);
|
|
84
|
-
await verifySqliteDatabase(this.#databasePath);
|
|
85
|
-
}
|
|
86
|
-
else {
|
|
87
|
-
await removeUnpublishedDatabase(this.#databasePath);
|
|
88
|
-
}
|
|
89
|
-
const cleanupDirectory = this.cleanupDirectoryPath();
|
|
90
|
-
await rename(this.#activeDirectory, cleanupDirectory);
|
|
91
|
-
this.#active = false;
|
|
92
|
-
await rm(cleanupDirectory, { recursive: true, force: true }).catch(() => undefined);
|
|
93
|
-
}
|
|
94
|
-
cleanupDirectoryPath() {
|
|
95
|
-
return join(this.#atlasDirectory, `${CLEANUP_DIRECTORY_PREFIX}${randomUUID()}`);
|
|
96
|
-
}
|
|
97
|
-
requireActive() {
|
|
98
|
-
if (!this.#active) {
|
|
99
|
-
throw new Error("The structural publication lifecycle has already finished");
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
async function captureDatabase(databasePath, backupPath) {
|
|
104
|
-
const sqlite = loadNodeSqliteBackup();
|
|
105
|
-
const database = new sqlite.DatabaseSync(databasePath, { readOnly: true });
|
|
106
|
-
try {
|
|
107
|
-
await sqlite.backup(database, backupPath);
|
|
108
|
-
}
|
|
109
|
-
finally {
|
|
110
|
-
database.close();
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
export async function backupSqliteDatabase(databasePath, backupPath) {
|
|
114
|
-
await captureDatabase(databasePath, backupPath);
|
|
115
|
-
await verifySqliteDatabase(backupPath);
|
|
116
|
-
}
|
|
117
|
-
async function restoreDatabase(backupPath, databasePath) {
|
|
118
|
-
const sqlite = loadNodeSqliteBackup();
|
|
119
|
-
const publishedDatabase = new sqlite.DatabaseSync(backupPath, { readOnly: true });
|
|
120
|
-
try {
|
|
121
|
-
await removeUnpublishedDatabase(databasePath);
|
|
122
|
-
await sqlite.backup(publishedDatabase, databasePath);
|
|
123
|
-
}
|
|
124
|
-
finally {
|
|
125
|
-
publishedDatabase.close();
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
function loadNodeSqliteBackup() {
|
|
129
|
-
const sqlite = require("node:sqlite");
|
|
130
|
-
if (typeof sqlite.backup !== "function") {
|
|
131
|
-
throw new Error("The structural backend runtime does not support online SQLite backups");
|
|
132
|
-
}
|
|
133
|
-
return sqlite;
|
|
134
|
-
}
|
|
135
|
-
async function verifySqliteDatabase(databasePath) {
|
|
136
|
-
await verifyOwnedRegularFile(databasePath, "The structural database");
|
|
137
|
-
const { DatabaseSync } = loadNodeSqliteBackup();
|
|
138
|
-
const database = new DatabaseSync(databasePath, { readOnly: true });
|
|
139
|
-
try {
|
|
140
|
-
const result = database.prepare("PRAGMA integrity_check").get();
|
|
141
|
-
if (result?.integrity_check !== "ok") {
|
|
142
|
-
throw new Error("The restored structural database failed its integrity check");
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
finally {
|
|
146
|
-
database.close();
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
async function writeManifest(directoryPath, manifest) {
|
|
150
|
-
const manifestPath = join(directoryPath, PUBLICATION_MANIFEST);
|
|
151
|
-
const noFollow = fileSystemConstants.O_NOFOLLOW ?? 0;
|
|
152
|
-
const file = await open(manifestPath, fileSystemConstants.O_WRONLY |
|
|
153
|
-
fileSystemConstants.O_CREAT |
|
|
154
|
-
fileSystemConstants.O_EXCL |
|
|
155
|
-
noFollow, 0o600);
|
|
156
|
-
try {
|
|
157
|
-
await file.writeFile(`${JSON.stringify(manifest)}\n`, "utf8");
|
|
158
|
-
await file.sync();
|
|
159
|
-
}
|
|
160
|
-
finally {
|
|
161
|
-
await file.close();
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
async function readManifest(directoryPath) {
|
|
165
|
-
const manifestPath = join(directoryPath, PUBLICATION_MANIFEST);
|
|
166
|
-
await verifyOwnedRegularFile(manifestPath, "The structural publication manifest");
|
|
167
|
-
const noFollow = fileSystemConstants.O_NOFOLLOW ?? 0;
|
|
168
|
-
const file = await open(manifestPath, fileSystemConstants.O_RDONLY | noFollow);
|
|
169
|
-
try {
|
|
170
|
-
const parsed = JSON.parse(await file.readFile("utf8"));
|
|
171
|
-
if (typeof parsed !== "object" ||
|
|
172
|
-
parsed === null ||
|
|
173
|
-
!("version" in parsed) ||
|
|
174
|
-
parsed.version !== 1 ||
|
|
175
|
-
!("hasPublishedDatabase" in parsed) ||
|
|
176
|
-
typeof parsed.hasPublishedDatabase !== "boolean") {
|
|
177
|
-
throw new Error("The structural publication manifest is invalid");
|
|
178
|
-
}
|
|
179
|
-
return { version: 1, hasPublishedDatabase: parsed.hasPublishedDatabase };
|
|
180
|
-
}
|
|
181
|
-
finally {
|
|
182
|
-
await file.close();
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
async function removeUnpublishedDatabase(databasePath) {
|
|
186
|
-
for (const path of [databasePath, ...DATABASE_SIDECARS.map((suffix) => `${databasePath}${suffix}`)]) {
|
|
187
|
-
try {
|
|
188
|
-
const metadata = await lstat(path);
|
|
189
|
-
if (!metadata.isFile() || metadata.isSymbolicLink()) {
|
|
190
|
-
throw new Error("The unpublished structural database state is not a regular file");
|
|
191
|
-
}
|
|
192
|
-
await rm(path);
|
|
193
|
-
}
|
|
194
|
-
catch (error) {
|
|
195
|
-
if (!isFileSystemError(error, "ENOENT")) {
|
|
196
|
-
throw error;
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
async function cleanupOrphanedPublicationDirectories(atlasDirectory) {
|
|
202
|
-
const entries = await readdir(atlasDirectory, { withFileTypes: true });
|
|
203
|
-
for (const entry of entries) {
|
|
204
|
-
if (entry.name.startsWith(STAGING_DIRECTORY_PREFIX) ||
|
|
205
|
-
entry.name.startsWith(CLEANUP_DIRECTORY_PREFIX)) {
|
|
206
|
-
const path = join(atlasDirectory, entry.name);
|
|
207
|
-
await verifyOwnedDirectory(path, "The orphaned structural publication state");
|
|
208
|
-
await rm(path, { recursive: true, force: true });
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
}
|
|
212
|
-
async function verifyAtlasDatabaseLocation(databasePath) {
|
|
213
|
-
if (basename(databasePath) !== "codegraph.db") {
|
|
214
|
-
throw new Error("The structural publication database must use the Atlas database path");
|
|
215
|
-
}
|
|
216
|
-
const atlasDirectory = dirname(resolve(databasePath));
|
|
217
|
-
await verifyOwnedDirectory(atlasDirectory, "The Atlas store");
|
|
218
|
-
if (resolve(await realpath(atlasDirectory)) !== atlasDirectory) {
|
|
219
|
-
throw new Error("The Atlas store resolves outside the target worktree");
|
|
220
|
-
}
|
|
221
|
-
return atlasDirectory;
|
|
222
|
-
}
|
|
223
|
-
async function verifyOwnedDirectory(path, label) {
|
|
224
|
-
const metadata = await lstat(path);
|
|
225
|
-
if (!metadata.isDirectory() || metadata.isSymbolicLink()) {
|
|
226
|
-
throw new Error(`${label} must be a real directory`);
|
|
227
|
-
}
|
|
228
|
-
if (resolve(await realpath(path)) !== resolve(path)) {
|
|
229
|
-
throw new Error(`${label} resolves outside the Atlas store`);
|
|
230
|
-
}
|
|
231
|
-
}
|
|
232
|
-
async function verifyOwnedRegularFile(path, label) {
|
|
233
|
-
const metadata = await lstat(path);
|
|
234
|
-
if (!metadata.isFile() || metadata.isSymbolicLink()) {
|
|
235
|
-
throw new Error(`${label} must be a regular file`);
|
|
236
|
-
}
|
|
237
|
-
if (resolve(await realpath(path)) !== resolve(path)) {
|
|
238
|
-
throw new Error(`${label} resolves outside the Atlas store`);
|
|
239
|
-
}
|
|
240
|
-
}
|
|
241
|
-
async function requireMissingPath(path, message) {
|
|
242
|
-
try {
|
|
243
|
-
await lstat(path);
|
|
244
|
-
}
|
|
245
|
-
catch (error) {
|
|
246
|
-
if (isFileSystemError(error, "ENOENT")) {
|
|
247
|
-
return;
|
|
248
|
-
}
|
|
249
|
-
throw error;
|
|
250
|
-
}
|
|
251
|
-
throw new Error(message);
|
|
252
|
-
}
|
|
253
|
-
function isFileSystemError(error, code) {
|
|
254
|
-
return error instanceof Error && "code" in error && error.code === code;
|
|
255
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"structural-write-lock.d.ts","sourceRoot":"","sources":["../../src/structural-backend/structural-write-lock.ts"],"names":[],"mappings":"AAuCA,qBAAa,mBAAmB;;IAO9B,OAAO;IAcP,MAAM,CAAC,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,mBAAmB,GAAG,SAAS;IAoB7D,OAAO,IAAI,IAAI;IAoBf,OAAO,CAAC,MAAM,CAAC,MAAM;CA2EtB"}
|