semantic-atlas 0.3.0 → 0.4.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.
Files changed (49) hide show
  1. package/README.md +27 -1
  2. package/README.zh-CN.md +24 -1
  3. package/dist/cli/bin.js +12 -5
  4. package/dist/cli/standalone-cli.d.ts.map +1 -1
  5. package/dist/cli/standalone-cli.js +8 -0
  6. package/dist/cli/web-cli.d.ts +9 -0
  7. package/dist/cli/web-cli.d.ts.map +1 -0
  8. package/dist/cli/web-cli.js +134 -0
  9. package/dist/graph/graph-store.d.ts +2 -2
  10. package/dist/graph/graph-store.d.ts.map +1 -1
  11. package/dist/graph/graph-store.js +2 -2
  12. package/dist/repository/repository-inspector.d.ts +1 -0
  13. package/dist/repository/repository-inspector.d.ts.map +1 -1
  14. package/dist/repository/repository-inspector.js +13 -0
  15. package/dist/storage/atlas-database.d.ts +7 -1
  16. package/dist/storage/atlas-database.d.ts.map +1 -1
  17. package/dist/storage/atlas-database.js +60 -10
  18. package/dist/web/application/atlas-read-service.d.ts +27 -0
  19. package/dist/web/application/atlas-read-service.d.ts.map +1 -0
  20. package/dist/web/application/atlas-read-service.js +216 -0
  21. package/dist/web/application/primary-repository-catalog.d.ts +15 -0
  22. package/dist/web/application/primary-repository-catalog.d.ts.map +1 -0
  23. package/dist/web/application/primary-repository-catalog.js +202 -0
  24. package/dist/web/application/types.d.ts +41 -0
  25. package/dist/web/application/types.d.ts.map +1 -0
  26. package/dist/web/application/types.js +1 -0
  27. package/dist/web/server/api-router.d.ts +4 -0
  28. package/dist/web/server/api-router.d.ts.map +1 -0
  29. package/dist/web/server/api-router.js +151 -0
  30. package/dist/web/server/local-web-server.d.ts +12 -0
  31. package/dist/web/server/local-web-server.d.ts.map +1 -0
  32. package/dist/web/server/local-web-server.js +100 -0
  33. package/dist/web-client/assets/index-DneaErDj.css +1 -0
  34. package/dist/web-client/assets/index-cze_4vtt.js +2 -0
  35. package/dist/web-client/assets/index-cze_4vtt.js.map +1 -0
  36. package/dist/web-client/index.html +61 -0
  37. package/dist/world/world-graph-query.d.ts +5 -1
  38. package/dist/world/world-graph-query.d.ts.map +1 -1
  39. package/dist/world/world-graph-query.js +4 -2
  40. package/dist/world/world-snapshot-store.d.ts +2 -1
  41. package/dist/world/world-snapshot-store.d.ts.map +1 -1
  42. package/dist/world/world-snapshot-store.js +2 -2
  43. package/docs/architecture/web-viewer.md +225 -0
  44. package/docs/contracts/cli-v1.md +16 -1
  45. package/docs/contracts/http-api-v1.md +155 -0
  46. package/docs/index.md +5 -0
  47. package/docs/log.md +79 -0
  48. package/docs/product-contract.md +31 -3
  49. package/package.json +5 -4
@@ -0,0 +1,216 @@
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 { GraphStore } from "../../graph/graph-store.js";
54
+ import { inspectRepositoryLanguages, } from "../../repository/repository-language-support.js";
55
+ import { CodeGraphStructuralBackend } from "../../structural-backend/codegraph-backend.js";
56
+ import { StructuralBackendError } from "../../structural-backend/types.js";
57
+ import { WorldGraphQuery } from "../../world/world-graph-query.js";
58
+ import { PrimaryRepositoryCatalog, } from "./primary-repository-catalog.js";
59
+ export class AtlasReadError extends Error {
60
+ statusCode;
61
+ code;
62
+ constructor(statusCode, code, message) {
63
+ super(message);
64
+ this.statusCode = statusCode;
65
+ this.code = code;
66
+ this.name = "AtlasReadError";
67
+ }
68
+ }
69
+ export class AtlasReadService {
70
+ #catalog;
71
+ #repositoryQueues = new Map();
72
+ constructor(catalog = new PrimaryRepositoryCatalog()) {
73
+ this.#catalog = catalog;
74
+ }
75
+ listProjects() {
76
+ return this.#catalog.listProjects();
77
+ }
78
+ getStatus(repositoryId) {
79
+ return this.withRepositoryRead(repositoryId, async (project) => {
80
+ const [languages, structural] = await Promise.all([
81
+ inspectRepositoryLanguages(project.repository),
82
+ new CodeGraphStructuralBackend(project.repository).inspect(),
83
+ ]);
84
+ const warnings = [];
85
+ if (project.summary.freshness === "stale") {
86
+ warnings.push({
87
+ code: "STALE_INDEX",
88
+ message: "The repository differs from the published Atlas snapshot.",
89
+ });
90
+ }
91
+ if (structural.completeness === "incomplete") {
92
+ warnings.push({ code: "INCOMPLETE_INDEX", message: "The structural index is incomplete." });
93
+ }
94
+ for (const language of languages) {
95
+ if (language.support === "unsupported") {
96
+ warnings.push({ code: "UNSUPPORTED_LANGUAGE", message: language.reason });
97
+ }
98
+ }
99
+ return {
100
+ project: project.summary,
101
+ currentRevision: {
102
+ headCommit: project.currentSnapshot.headCommit,
103
+ changes: {
104
+ staged: project.currentSnapshot.changes.staged.length,
105
+ unstaged: project.currentSnapshot.changes.unstaged.length,
106
+ untracked: project.currentSnapshot.changes.untracked.length,
107
+ },
108
+ },
109
+ languages,
110
+ backend: {
111
+ backendVersion: structural.backendVersion,
112
+ completeness: structural.completeness,
113
+ extractionVersion: structural.extractionVersion,
114
+ indexedAt: structural.indexedAt,
115
+ },
116
+ warnings,
117
+ };
118
+ });
119
+ }
120
+ getMap(repositoryId, focusKey) {
121
+ return this.withPublishedWorld(repositoryId, async (query) => {
122
+ const map = await query.view(focusKey);
123
+ if (map === undefined) {
124
+ throw new AtlasReadError(404, "BUSINESS_NODE_NOT_FOUND", "The requested business node is not available.");
125
+ }
126
+ return map;
127
+ });
128
+ }
129
+ searchBusiness(repositoryId, queryText, limit) {
130
+ return this.withPublishedWorld(repositoryId, async (query) => ({
131
+ query: queryText,
132
+ limit,
133
+ results: await query.searchBusiness(queryText, { limit }),
134
+ }));
135
+ }
136
+ getBusinessNode(repositoryId, businessKey) {
137
+ return this.withPublishedWorld(repositoryId, async (query) => {
138
+ const node = await query.showBusiness(businessKey);
139
+ if (node === undefined) {
140
+ throw new AtlasReadError(404, "BUSINESS_NODE_NOT_FOUND", "The requested business node is not available.");
141
+ }
142
+ return node;
143
+ });
144
+ }
145
+ withPublishedWorld(repositoryId, operation) {
146
+ return this.withRepositoryRead(repositoryId, async (project) => {
147
+ const env_1 = { stack: [], error: void 0, hasError: false };
148
+ try {
149
+ if (project.summary.status !== "current" || project.summary.snapshotId === null) {
150
+ throw unavailableWorld();
151
+ }
152
+ const structural = new CodeGraphStructuralBackend(project.repository);
153
+ const state = await structural.inspect();
154
+ if (state.completeness !== "complete") {
155
+ throw unavailableWorld();
156
+ }
157
+ const graph = __addDisposableResource(env_1, new GraphStore(project.repository, { access: "read-only" }), false);
158
+ const query = __addDisposableResource(env_1, new WorldGraphQuery(project.repository, graph, structural, {
159
+ atlasAccess: "read-only",
160
+ }), false);
161
+ try {
162
+ return await operation(query);
163
+ }
164
+ catch (error) {
165
+ if (error instanceof AtlasReadError) {
166
+ throw error;
167
+ }
168
+ if (error instanceof Error && error.message.includes("publication changed")) {
169
+ throw new AtlasReadError(409, "PUBLICATION_CHANGED", "The Atlas publication changed during the request. Try again.");
170
+ }
171
+ if (isUnavailableWorldError(error)) {
172
+ throw unavailableWorld();
173
+ }
174
+ throw error;
175
+ }
176
+ }
177
+ catch (e_1) {
178
+ env_1.error = e_1;
179
+ env_1.hasError = true;
180
+ }
181
+ finally {
182
+ __disposeResources(env_1);
183
+ }
184
+ });
185
+ }
186
+ async withRepositoryRead(repositoryId, operation) {
187
+ const previous = this.#repositoryQueues.get(repositoryId) ?? Promise.resolve();
188
+ let resolveQueue;
189
+ const queue = new Promise((resolve) => { resolveQueue = resolve; });
190
+ const queueTail = previous.catch(() => undefined).then(() => queue);
191
+ this.#repositoryQueues.set(repositoryId, queueTail);
192
+ await previous.catch(() => undefined);
193
+ try {
194
+ const project = await this.#catalog.findProject(repositoryId);
195
+ if (project === undefined) {
196
+ throw new AtlasReadError(404, "PROJECT_NOT_FOUND", "The requested project is not available.");
197
+ }
198
+ return await operation(project);
199
+ }
200
+ finally {
201
+ resolveQueue();
202
+ if (this.#repositoryQueues.get(repositoryId) === queueTail) {
203
+ this.#repositoryQueues.delete(repositoryId);
204
+ }
205
+ }
206
+ }
207
+ }
208
+ function isUnavailableWorldError(error) {
209
+ return error instanceof StructuralBackendError
210
+ || (error instanceof Error && (error.message.startsWith("World snapshot is ")
211
+ || error.message.includes("current world publication")
212
+ || error.message.includes("current world snapshot")));
213
+ }
214
+ function unavailableWorld() {
215
+ return new AtlasReadError(409, "ATLAS_STATE_UNAVAILABLE", "The current Atlas publication is unavailable for this project.");
216
+ }
@@ -0,0 +1,15 @@
1
+ import type { GitRepository } from "../../repository/types.js";
2
+ import type { RepositorySnapshot } from "../../snapshots/types.js";
3
+ import type { WebProjectSummary } from "./types.js";
4
+ export interface PrimaryRepositoryProject {
5
+ readonly repository: GitRepository;
6
+ readonly currentSnapshot: RepositorySnapshot;
7
+ readonly summary: WebProjectSummary;
8
+ }
9
+ export declare class PrimaryRepositoryCatalog {
10
+ listProjects(): Promise<readonly WebProjectSummary[]>;
11
+ findProject(repositoryId: string): Promise<PrimaryRepositoryProject | undefined>;
12
+ private discoverProjects;
13
+ private inspectStoredRepository;
14
+ }
15
+ //# sourceMappingURL=primary-repository-catalog.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"primary-repository-catalog.d.ts","sourceRoot":"","sources":["../../../src/web/application/primary-repository-catalog.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAE/D,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AAKnE,OAAO,KAAK,EAGV,iBAAiB,EAClB,MAAM,YAAY,CAAC;AAmBpB,MAAM,WAAW,wBAAwB;IACvC,QAAQ,CAAC,UAAU,EAAE,aAAa,CAAC;IACnC,QAAQ,CAAC,eAAe,EAAE,kBAAkB,CAAC;IAC7C,QAAQ,CAAC,OAAO,EAAE,iBAAiB,CAAC;CACrC;AAED,qBAAa,wBAAwB;IAC7B,YAAY,IAAI,OAAO,CAAC,SAAS,iBAAiB,EAAE,CAAC;IAIrD,WAAW,CAAC,YAAY,EAAE,MAAM,GAAG,OAAO,CAAC,wBAAwB,GAAG,SAAS,CAAC;YAOxE,gBAAgB;YAmChB,uBAAuB;CA6EtC"}
@@ -0,0 +1,202 @@
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 { createRequire } from "node:module";
54
+ import { readdir } from "node:fs/promises";
55
+ import { basename, join } from "node:path";
56
+ import { inspectGitRepository, readCurrentBranch, } from "../../repository/repository-inspector.js";
57
+ import { createRepositorySnapshot } from "../../snapshots/repository-snapshot.js";
58
+ import { CURRENT_ATLAS_SCHEMA_VERSION, resolveExistingAtlasHome, } from "../../storage/atlas-database.js";
59
+ const REPOSITORY_ID_PATTERN = /^[0-9a-f]{64}$/u;
60
+ const require = createRequire(import.meta.url);
61
+ export class PrimaryRepositoryCatalog {
62
+ async listProjects() {
63
+ return (await this.discoverProjects()).map(({ summary }) => summary);
64
+ }
65
+ async findProject(repositoryId) {
66
+ if (!REPOSITORY_ID_PATTERN.test(repositoryId)) {
67
+ return undefined;
68
+ }
69
+ return (await this.discoverProjects(repositoryId))[0];
70
+ }
71
+ async discoverProjects(requestedRepositoryId) {
72
+ const atlasHome = resolveExistingAtlasHome();
73
+ if (atlasHome === null) {
74
+ return [];
75
+ }
76
+ const repositoriesDirectory = join(atlasHome, "repositories");
77
+ let entries;
78
+ try {
79
+ entries = await readdir(repositoriesDirectory, { withFileTypes: true });
80
+ }
81
+ catch (error) {
82
+ if (error.code === "ENOENT") {
83
+ return [];
84
+ }
85
+ throw error;
86
+ }
87
+ const repositoryIds = entries
88
+ .filter((entry) => entry.isDirectory() && REPOSITORY_ID_PATTERN.test(entry.name))
89
+ .map((entry) => entry.name)
90
+ .filter((repositoryId) => (requestedRepositoryId === undefined || repositoryId === requestedRepositoryId))
91
+ .sort();
92
+ const projects = (await Promise.all(repositoryIds.map(async (repositoryId) => (this.inspectStoredRepository(repositoriesDirectory, repositoryId))))).filter((project) => project !== undefined);
93
+ return projects.sort((left, right) => (left.summary.name.localeCompare(right.summary.name)
94
+ || left.summary.root.localeCompare(right.summary.root)));
95
+ }
96
+ async inspectStoredRepository(repositoriesDirectory, repositoryId) {
97
+ const databasePath = join(repositoriesDirectory, repositoryId, "atlas.db");
98
+ let storedState;
99
+ try {
100
+ const env_1 = { stack: [], error: void 0, hasError: false };
101
+ try {
102
+ const { DatabaseSync } = require("node:sqlite");
103
+ const database = __addDisposableResource(env_1, new DatabaseSync(databasePath, { readOnly: true }), false);
104
+ const schema = database.prepare(`
105
+ SELECT version
106
+ FROM atlas_schema
107
+ WHERE singleton = 1
108
+ `).get();
109
+ if (schema?.version !== CURRENT_ATLAS_SCHEMA_VERSION) {
110
+ return undefined;
111
+ }
112
+ storedState = database.prepare(`
113
+ SELECT
114
+ repository.repository_id,
115
+ repository.common_git_directory,
116
+ worktree.git_directory,
117
+ worktree.worktree_root,
118
+ worktree.status,
119
+ worktree.current_snapshot_id,
120
+ snapshot.payload AS snapshot_payload
121
+ FROM atlas_repositories AS repository
122
+ JOIN atlas_worktree_states AS worktree
123
+ ON worktree.repository_id = repository.repository_id
124
+ AND worktree.git_directory = repository.common_git_directory
125
+ LEFT JOIN atlas_repository_snapshots AS snapshot
126
+ ON snapshot.repository_id = worktree.repository_id
127
+ AND snapshot.snapshot_id = worktree.current_snapshot_id
128
+ WHERE repository.repository_id = ?
129
+ `).get(repositoryId);
130
+ }
131
+ catch (e_1) {
132
+ env_1.error = e_1;
133
+ env_1.hasError = true;
134
+ }
135
+ finally {
136
+ __disposeResources(env_1);
137
+ }
138
+ }
139
+ catch {
140
+ return undefined;
141
+ }
142
+ if (storedState === undefined) {
143
+ return undefined;
144
+ }
145
+ try {
146
+ const repository = await inspectGitRepository(storedState.worktree_root);
147
+ if (repository.repositoryId !== storedState.repository_id
148
+ || repository.gitDirectory !== repository.commonGitDirectory
149
+ || repository.gitDirectory !== storedState.git_directory
150
+ || repository.commonGitDirectory !== storedState.common_git_directory) {
151
+ return undefined;
152
+ }
153
+ const branch = await readCurrentBranch(repository);
154
+ if (!isPrimaryBranch(branch)) {
155
+ return undefined;
156
+ }
157
+ const currentSnapshot = await createRepositorySnapshot(repository);
158
+ const publishedSnapshot = parsePublishedSnapshot(storedState.snapshot_payload);
159
+ const freshness = projectFreshness(storedState, currentSnapshot, publishedSnapshot);
160
+ return {
161
+ repository,
162
+ currentSnapshot,
163
+ summary: {
164
+ id: repository.repositoryId,
165
+ name: basename(repository.worktreeRoot),
166
+ root: repository.worktreeRoot,
167
+ branch,
168
+ headCommit: currentSnapshot.headCommit,
169
+ snapshotId: storedState.current_snapshot_id,
170
+ freshness,
171
+ status: storedState.status,
172
+ },
173
+ };
174
+ }
175
+ catch {
176
+ return undefined;
177
+ }
178
+ }
179
+ }
180
+ function isPrimaryBranch(branch) {
181
+ return branch === "main" || branch === "master";
182
+ }
183
+ function parsePublishedSnapshot(payload) {
184
+ if (payload === null) {
185
+ return null;
186
+ }
187
+ try {
188
+ return JSON.parse(payload);
189
+ }
190
+ catch {
191
+ return null;
192
+ }
193
+ }
194
+ function projectFreshness(storedState, currentSnapshot, publishedSnapshot) {
195
+ if (storedState.current_snapshot_id === null) {
196
+ return "missing";
197
+ }
198
+ if (storedState.status !== "current" || publishedSnapshot === null) {
199
+ return "stale";
200
+ }
201
+ return publishedSnapshot.snapshotId === currentSnapshot.snapshotId ? "current" : "stale";
202
+ }
@@ -0,0 +1,41 @@
1
+ import type { BusinessGraphView, BusinessMapView, GraphSearchResult, BusinessGraphNode } from "../../graph/types.js";
2
+ import type { RepositoryLanguageSupport } from "../../repository/repository-language-support.js";
3
+ import type { StructuralIndexState } from "../../structural-backend/types.js";
4
+ import type { WorldSnapshotStatus } from "../../world/types.js";
5
+ export type WebProjectBranch = "main" | "master";
6
+ export type WebProjectFreshness = "current" | "stale" | "missing";
7
+ export interface WebProjectSummary {
8
+ readonly id: string;
9
+ readonly name: string;
10
+ readonly root: string;
11
+ readonly branch: WebProjectBranch;
12
+ readonly headCommit: string;
13
+ readonly snapshotId: string | null;
14
+ readonly freshness: WebProjectFreshness;
15
+ readonly status: WorldSnapshotStatus;
16
+ }
17
+ export interface WebProjectStatus {
18
+ readonly project: WebProjectSummary;
19
+ readonly currentRevision: {
20
+ readonly headCommit: string;
21
+ readonly changes: {
22
+ readonly staged: number;
23
+ readonly unstaged: number;
24
+ readonly untracked: number;
25
+ };
26
+ };
27
+ readonly languages: readonly RepositoryLanguageSupport[];
28
+ readonly backend: Pick<StructuralIndexState, "backendVersion" | "completeness" | "extractionVersion" | "indexedAt">;
29
+ readonly warnings: readonly {
30
+ readonly code: string;
31
+ readonly message: string;
32
+ }[];
33
+ }
34
+ export interface WebBusinessSearch {
35
+ readonly query: string;
36
+ readonly limit: number;
37
+ readonly results: readonly GraphSearchResult<BusinessGraphNode>[];
38
+ }
39
+ export type WebBusinessMap = BusinessMapView;
40
+ export type WebBusinessNode = BusinessGraphView;
41
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/web/application/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,iBAAiB,EACjB,eAAe,EACf,iBAAiB,EACjB,iBAAiB,EAClB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,iDAAiD,CAAC;AACjG,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,mCAAmC,CAAC;AAC9E,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AAEhE,MAAM,MAAM,gBAAgB,GAAG,MAAM,GAAG,QAAQ,CAAC;AACjD,MAAM,MAAM,mBAAmB,GAAG,SAAS,GAAG,OAAO,GAAG,SAAS,CAAC;AAElE,MAAM,WAAW,iBAAiB;IAChC,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,MAAM,EAAE,gBAAgB,CAAC;IAClC,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;IACnC,QAAQ,CAAC,SAAS,EAAE,mBAAmB,CAAC;IACxC,QAAQ,CAAC,MAAM,EAAE,mBAAmB,CAAC;CACtC;AAED,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,CAAC,OAAO,EAAE,iBAAiB,CAAC;IACpC,QAAQ,CAAC,eAAe,EAAE;QACxB,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;QAC5B,QAAQ,CAAC,OAAO,EAAE;YAChB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;YACxB,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;YAC1B,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;SAC5B,CAAC;KACH,CAAC;IACF,QAAQ,CAAC,SAAS,EAAE,SAAS,yBAAyB,EAAE,CAAC;IACzD,QAAQ,CAAC,OAAO,EAAE,IAAI,CACpB,oBAAoB,EACpB,gBAAgB,GAAG,cAAc,GAAG,mBAAmB,GAAG,WAAW,CACtE,CAAC;IACF,QAAQ,CAAC,QAAQ,EAAE,SAAS;QAC1B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;QACtB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;KAC1B,EAAE,CAAC;CACL;AAED,MAAM,WAAW,iBAAiB;IAChC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,OAAO,EAAE,SAAS,iBAAiB,CAAC,iBAAiB,CAAC,EAAE,CAAC;CACnE;AAED,MAAM,MAAM,cAAc,GAAG,eAAe,CAAC;AAC7C,MAAM,MAAM,eAAe,GAAG,iBAAiB,CAAC"}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,4 @@
1
+ import type { IncomingMessage, ServerResponse } from "node:http";
2
+ import { type AtlasReadOperations } from "../application/atlas-read-service.js";
3
+ export declare function createApiRequestHandler(service: AtlasReadOperations): (request: IncomingMessage, response: ServerResponse) => void;
4
+ //# sourceMappingURL=api-router.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"api-router.d.ts","sourceRoot":"","sources":["../../../src/web/server/api-router.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAGjE,OAAO,EAEL,KAAK,mBAAmB,EACzB,MAAM,sCAAsC,CAAC;AAgB9C,wBAAgB,uBAAuB,CACrC,OAAO,EAAE,mBAAmB,GAC3B,CAAC,OAAO,EAAE,eAAe,EAAE,QAAQ,EAAE,cAAc,KAAK,IAAI,CAI9D"}
@@ -0,0 +1,151 @@
1
+ import { businessKeySchema } from "../../contracts/graph.js";
2
+ import { AtlasReadError, } from "../application/atlas-read-service.js";
3
+ const PROJECT_ID_PATTERN = /^[0-9a-f]{64}$/u;
4
+ const PROJECT_ROUTE_PATTERN = /^\/api\/v1\/projects\/([^/]+)\/(status|map|search|node)$/u;
5
+ class HttpApiError extends Error {
6
+ statusCode;
7
+ code;
8
+ constructor(statusCode, code, message) {
9
+ super(message);
10
+ this.statusCode = statusCode;
11
+ this.code = code;
12
+ this.name = "HttpApiError";
13
+ }
14
+ }
15
+ export function createApiRequestHandler(service) {
16
+ return (request, response) => {
17
+ void routeApiRequest(service, request, response);
18
+ };
19
+ }
20
+ async function routeApiRequest(service, request, response) {
21
+ try {
22
+ const url = new URL(request.url ?? "/", "http://127.0.0.1");
23
+ if (request.method !== "GET") {
24
+ response.setHeader("Allow", "GET");
25
+ throw new HttpApiError(405, "METHOD_NOT_ALLOWED", "The resource supports GET only.");
26
+ }
27
+ if (url.pathname === "/api/v1/projects") {
28
+ requireAllowedQuery(url, []);
29
+ writeJson(response, 200, { data: { projects: await service.listProjects() } });
30
+ return;
31
+ }
32
+ const route = PROJECT_ROUTE_PATTERN.exec(url.pathname);
33
+ if (route === null) {
34
+ throw invalidRequest("The requested API route is invalid.");
35
+ }
36
+ const repositoryId = route[1];
37
+ const operation = route[2];
38
+ if (!PROJECT_ID_PATTERN.test(repositoryId)) {
39
+ throw invalidRequest("Expected an opaque Semantic Atlas project ID.");
40
+ }
41
+ if (operation === "status") {
42
+ requireAllowedQuery(url, []);
43
+ writeJson(response, 200, { data: await service.getStatus(repositoryId) });
44
+ return;
45
+ }
46
+ if (operation === "map") {
47
+ requireAllowedQuery(url, ["focus"]);
48
+ const focus = optionalBusinessKey(url, "focus");
49
+ writeJson(response, 200, {
50
+ data: await service.getMap(repositoryId, focus),
51
+ });
52
+ return;
53
+ }
54
+ if (operation === "search") {
55
+ requireAllowedQuery(url, ["q", "limit"]);
56
+ const query = requiredQuery(url, "q").trim();
57
+ if (query.length === 0) {
58
+ throw invalidRequest("Search query q must not be empty.");
59
+ }
60
+ const limit = positiveIntegerQuery(url, "limit", 20, 100);
61
+ writeJson(response, 200, {
62
+ data: await service.searchBusiness(repositoryId, query, limit),
63
+ });
64
+ return;
65
+ }
66
+ requireAllowedQuery(url, ["key"]);
67
+ const businessKey = requiredBusinessKey(url, "key");
68
+ writeJson(response, 200, {
69
+ data: await service.getBusinessNode(repositoryId, businessKey),
70
+ });
71
+ }
72
+ catch (error) {
73
+ writeApiError(response, error);
74
+ }
75
+ }
76
+ function requiredQuery(url, name) {
77
+ const values = url.searchParams.getAll(name);
78
+ if (values.length !== 1 || values[0] === undefined) {
79
+ throw invalidRequest(`Query parameter ${name} is required exactly once.`);
80
+ }
81
+ return values[0];
82
+ }
83
+ function optionalBusinessKey(url, name) {
84
+ const values = url.searchParams.getAll(name);
85
+ if (values.length === 0) {
86
+ return undefined;
87
+ }
88
+ if (values.length !== 1) {
89
+ throw invalidRequest(`Query parameter ${name} may be provided once.`);
90
+ }
91
+ return parseBusinessKey(values[0], name);
92
+ }
93
+ function requiredBusinessKey(url, name) {
94
+ return parseBusinessKey(requiredQuery(url, name), name);
95
+ }
96
+ function parseBusinessKey(value, name) {
97
+ const parsed = businessKeySchema.safeParse(value);
98
+ if (!parsed.success) {
99
+ throw invalidRequest(`Query parameter ${name} must be a business key.`);
100
+ }
101
+ return parsed.data;
102
+ }
103
+ function positiveIntegerQuery(url, name, defaultValue, maximum) {
104
+ const values = url.searchParams.getAll(name);
105
+ if (values.length === 0) {
106
+ return defaultValue;
107
+ }
108
+ if (values.length !== 1) {
109
+ throw invalidRequest(`Query parameter ${name} may be provided once.`);
110
+ }
111
+ const value = Number(values[0]);
112
+ if (!Number.isInteger(value) || value < 1 || value > maximum) {
113
+ throw invalidRequest(`Query parameter ${name} must be an integer from 1 through ${maximum}.`);
114
+ }
115
+ return value;
116
+ }
117
+ function requireAllowedQuery(url, allowed) {
118
+ const allowedNames = new Set(allowed);
119
+ for (const name of url.searchParams.keys()) {
120
+ if (!allowedNames.has(name)) {
121
+ throw invalidRequest(`Query parameter ${name} is not supported by this route.`);
122
+ }
123
+ }
124
+ }
125
+ function invalidRequest(message) {
126
+ return new HttpApiError(400, "INVALID_REQUEST", message);
127
+ }
128
+ function writeApiError(response, error) {
129
+ if (response.headersSent) {
130
+ response.end();
131
+ return;
132
+ }
133
+ if (error instanceof AtlasReadError || error instanceof HttpApiError) {
134
+ writeJson(response, error.statusCode, {
135
+ error: { code: error.code, message: error.message },
136
+ });
137
+ return;
138
+ }
139
+ writeJson(response, 500, {
140
+ error: {
141
+ code: "INTERNAL_ERROR",
142
+ message: "Semantic Atlas could not complete the local request.",
143
+ },
144
+ });
145
+ }
146
+ function writeJson(response, statusCode, contents) {
147
+ response.statusCode = statusCode;
148
+ response.setHeader("Content-Type", "application/json; charset=utf-8");
149
+ response.setHeader("Cache-Control", "no-store");
150
+ response.end(JSON.stringify({ schemaVersion: 1, ...contents }));
151
+ }
@@ -0,0 +1,12 @@
1
+ import type { AtlasReadOperations } from "../application/atlas-read-service.js";
2
+ export interface LocalWebServerOptions {
3
+ readonly readService: AtlasReadOperations;
4
+ readonly port: number;
5
+ readonly assetsDirectory?: string;
6
+ }
7
+ export interface RunningLocalWebServer {
8
+ readonly url: string;
9
+ close(): Promise<void>;
10
+ }
11
+ export declare function startLocalWebServer(options: LocalWebServerOptions): Promise<RunningLocalWebServer>;
12
+ //# sourceMappingURL=local-web-server.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"local-web-server.d.ts","sourceRoot":"","sources":["../../../src/web/server/local-web-server.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,sCAAsC,CAAC;AAGhF,MAAM,WAAW,qBAAqB;IACpC,QAAQ,CAAC,WAAW,EAAE,mBAAmB,CAAC;IAC1C,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,eAAe,CAAC,EAAE,MAAM,CAAC;CACnC;AAED,MAAM,WAAW,qBAAqB;IACpC,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CACxB;AAED,wBAAsB,mBAAmB,CACvC,OAAO,EAAE,qBAAqB,GAC7B,OAAO,CAAC,qBAAqB,CAAC,CA0BhC"}