@ankhorage/atlas 0.19.2 → 0.20.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.next/BUILD_ID +1 -1
- package/.next/app-path-routes-manifest.json +2 -0
- package/.next/build-manifest.json +3 -3
- package/.next/fallback-build-manifest.json +3 -3
- package/.next/prerender-manifest.json +3 -3
- package/.next/routes-manifest.json +12 -0
- package/.next/server/app/_global-error/page.js +1 -1
- package/.next/server/app/_global-error/page.js.nft.json +1 -1
- package/.next/server/app/_global-error.html +1 -1
- package/.next/server/app/_global-error.rsc +1 -1
- package/.next/server/app/_global-error.segments/__PAGE__.segment.rsc +1 -1
- package/.next/server/app/_global-error.segments/_full.segment.rsc +1 -1
- package/.next/server/app/_global-error.segments/_tree.segment.rsc +1 -1
- package/.next/server/app/_not-found/page.js +1 -1
- package/.next/server/app/_not-found/page.js.nft.json +1 -1
- package/.next/server/app/_not-found.html +1 -1
- package/.next/server/app/_not-found.rsc +1 -1
- package/.next/server/app/_not-found.segments/_full.segment.rsc +1 -1
- package/.next/server/app/_not-found.segments/_not-found/__PAGE__.segment.rsc +1 -1
- package/.next/server/app/_not-found.segments/_tree.segment.rsc +1 -1
- package/.next/server/app/api/dependency-graph/route.js.nft.json +1 -1
- package/.next/server/app/api/workspace/inventory/route/app-paths-manifest.json +3 -0
- package/.next/server/app/api/workspace/inventory/route/build-manifest.json +12 -0
- package/.next/server/app/api/workspace/inventory/route/server-reference-manifest.json +4 -0
- package/.next/server/app/api/workspace/inventory/route.js +10 -0
- package/.next/server/app/api/workspace/inventory/route.js.map +5 -0
- package/.next/server/app/api/workspace/inventory/route.js.nft.json +1 -0
- package/.next/server/app/api/workspace/inventory/route_client-reference-manifest.js +3 -0
- package/.next/server/app/api/workspace/retry/route.js +2 -2
- package/.next/server/app/api/workspace/retry/route.js.nft.json +1 -1
- package/.next/server/app/api/workspace/selection/route/app-paths-manifest.json +3 -0
- package/.next/server/app/api/workspace/selection/route/build-manifest.json +12 -0
- package/.next/server/app/api/workspace/selection/route/server-reference-manifest.json +4 -0
- package/.next/server/app/api/workspace/selection/route.js +11 -0
- package/.next/server/app/api/workspace/selection/route.js.map +5 -0
- package/.next/server/app/api/workspace/selection/route.js.nft.json +1 -0
- package/.next/server/app/api/workspace/selection/route_client-reference-manifest.js +3 -0
- package/.next/server/app/page/server-reference-manifest.json +5 -5
- package/.next/server/app/page.js +1 -1
- package/.next/server/app/page.js.nft.json +1 -1
- package/.next/server/app-paths-manifest.json +2 -0
- package/.next/server/chunks/[root-of-the-server]__0o38po8._.js +3 -0
- package/.next/server/chunks/[root-of-the-server]__0o38po8._.js.map +1 -0
- package/.next/server/chunks/[root-of-the-server]__13u3w6h._.js +3 -0
- package/.next/server/chunks/[root-of-the-server]__13u3w6h._.js.map +1 -0
- package/.next/server/chunks/{[externals]__16594cb._.js → [root-of-the-server]__14-p326._.js} +2 -2
- package/.next/server/chunks/[root-of-the-server]__14-p326._.js.map +1 -0
- package/.next/server/chunks/_08j7hwz._.js +5 -0
- package/.next/server/chunks/_08j7hwz._.js.map +1 -0
- package/.next/server/chunks/_0qw9gtg._.js +3 -0
- package/.next/server/chunks/_0qw9gtg._.js.map +1 -0
- package/.next/server/chunks/_0s0tudb._.js +3 -0
- package/.next/server/chunks/_0s0tudb._.js.map +1 -0
- package/.next/server/chunks/_next-internal_server_app_api_workspace_inventory_route_actions_1d1a228.js +3 -0
- package/.next/server/chunks/_next-internal_server_app_api_workspace_selection_route_actions_1-bxxis.js +3 -0
- package/.next/server/chunks/_next-internal_server_app_api_workspace_selection_route_actions_1-bxxis.js.map +1 -0
- package/.next/server/chunks/node_modules_16e4rf7._.js +4 -4
- package/.next/server/chunks/ssr/[root-of-the-server]__0_6mxrx._.js +1 -1
- package/.next/server/chunks/ssr/{[root-of-the-server]__1o19g7g._.js → [root-of-the-server]__1b7nej0._.js} +1 -1
- package/.next/server/chunks/ssr/_0lahb16._.js +1 -1
- package/.next/server/chunks/ssr/_14-yori._.js +1 -1
- package/.next/server/chunks/ssr/_14-yori._.js.map +1 -1
- package/.next/server/middleware-build-manifest.js +3 -3
- package/.next/server/pages/404.html +1 -1
- package/.next/server/pages/500.html +1 -1
- package/.next/server/server-reference-manifest.js +1 -1
- package/.next/server/server-reference-manifest.json +6 -6
- package/CHANGELOG.md +6 -0
- package/README.md +1 -1
- package/package.json +1 -1
- package/paradox/badges/npm.svg +3 -3
- package/paradox/diagrams/architecture-overview.mmd +59 -5
- package/paradox/diagrams/export-graph.mmd +12 -0
- package/paradox/diagrams/module-relationships.mmd +47 -5
- package/paradox/index.html +601 -70
- package/paradox/paradox.json +1390 -170
- package/src/app/api/workspace/inventory/route.ts +21 -0
- package/src/app/api/workspace/selection/route.ts +22 -0
- package/src/features/workspace/adapters/inbound/next/createWorkspaceInventoryRoute.ts +38 -0
- package/src/features/workspace/adapters/inbound/next/createWorkspaceProgressResponse.ts +67 -0
- package/src/features/workspace/adapters/inbound/next/createWorkspaceSelectionRoute.ts +90 -0
- package/src/features/workspace/application/use-cases/classifyWorkspaceRepositoryFailure.ts +105 -0
- package/src/features/workspace/composition/analyzeWorkspaceRepositoryAsync.ts +79 -0
- package/src/features/workspace/composition/createWorkspaceRepositoryRuntime.ts +100 -102
- package/src/features/workspace/composition/createWorkspaceRepositoryStatus.ts +12 -8
- package/src/features/workspace/composition/loadWorkspaceProjectSourceAsync.ts +90 -2
- package/src/features/workspace/composition/loadWorkspaceRepositoryBatchAsync.ts +39 -10
- package/src/features/workspace/composition/updateWorkspaceRepositoryRuntimeAsync.ts +137 -0
- package/src/features/workspace/utils/settleBoundedAsync.ts +17 -10
- package/src/types/workspace.ts +42 -0
- package/.next/server/chunks/_0clm3_5._.js +0 -3
- package/.next/server/chunks/_0clm3_5._.js.map +0 -1
- /package/.next/server/chunks/{[externals]__16594cb._.js.map → _next-internal_server_app_api_workspace_inventory_route_actions_1d1a228.js.map} +0 -0
- /package/.next/server/chunks/ssr/{[root-of-the-server]__1o19g7g._.js.map → [root-of-the-server]__1b7nej0._.js.map} +0 -0
- /package/.next/static/{GOvrWiGb2JX15cd-oOcf6 → CthQ01_AjZZJxjY_Q1XBz}/_buildManifest.js +0 -0
- /package/.next/static/{GOvrWiGb2JX15cd-oOcf6 → CthQ01_AjZZJxjY_Q1XBz}/_clientMiddlewareManifest.js +0 -0
- /package/.next/static/{GOvrWiGb2JX15cd-oOcf6 → CthQ01_AjZZJxjY_Q1XBz}/_ssgManifest.js +0 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { readGitHubRepositoryAuthenticationAsync } from '@/features/github-auth/adapters/inbound/next/readGitHubAuthViewAsync';
|
|
2
|
+
import { createWorkspaceInventoryRoute } from '@/features/workspace/adapters/inbound/next/createWorkspaceInventoryRoute';
|
|
3
|
+
import { discoverWorkspaceInventoryAsync } from '@/features/workspace/composition/loadWorkspaceProjectSourceAsync';
|
|
4
|
+
|
|
5
|
+
/*** Bind discovery-only inventory to current request credentials without exposing them to the browser. */
|
|
6
|
+
export const GET = createWorkspaceInventoryRoute(async source =>
|
|
7
|
+
discoverWorkspaceInventoryAsync(
|
|
8
|
+
source,
|
|
9
|
+
toWorkspaceAuthorization(await readGitHubRepositoryAuthenticationAsync())
|
|
10
|
+
)
|
|
11
|
+
);
|
|
12
|
+
|
|
13
|
+
/*** Translate the auth feature's request-scoped cache scope into the workspace runtime contract. */
|
|
14
|
+
function toWorkspaceAuthorization(
|
|
15
|
+
authorization: Awaited<ReturnType<typeof readGitHubRepositoryAuthenticationAsync>>
|
|
16
|
+
) {
|
|
17
|
+
return {
|
|
18
|
+
authentication: authorization.authentication,
|
|
19
|
+
authorizationScope: authorization.cacheScope,
|
|
20
|
+
};
|
|
21
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { readGitHubRepositoryAuthenticationAsync } from '@/features/github-auth/adapters/inbound/next/readGitHubAuthViewAsync';
|
|
2
|
+
import { createWorkspaceSelectionRoute } from '@/features/workspace/adapters/inbound/next/createWorkspaceSelectionRoute';
|
|
3
|
+
import { createWorkspaceSelectionOperationAsync } from '@/features/workspace/composition/loadWorkspaceProjectSourceAsync';
|
|
4
|
+
|
|
5
|
+
/*** Bind selection streaming to current request credentials and never persist the resolved GitHub token. */
|
|
6
|
+
export const POST = createWorkspaceSelectionRoute(async (input, request) =>
|
|
7
|
+
createWorkspaceSelectionOperationAsync(
|
|
8
|
+
input,
|
|
9
|
+
toWorkspaceAuthorization(await readGitHubRepositoryAuthenticationAsync()),
|
|
10
|
+
request.signal
|
|
11
|
+
)
|
|
12
|
+
);
|
|
13
|
+
|
|
14
|
+
/*** Translate the auth feature's request-scoped cache scope into the workspace runtime contract. */
|
|
15
|
+
function toWorkspaceAuthorization(
|
|
16
|
+
authorization: Awaited<ReturnType<typeof readGitHubRepositoryAuthenticationAsync>>
|
|
17
|
+
) {
|
|
18
|
+
return {
|
|
19
|
+
authentication: authorization.authentication,
|
|
20
|
+
authorizationScope: authorization.cacheScope,
|
|
21
|
+
};
|
|
22
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { WorkspaceRepositoryInventoryOption } from '@/types/workspace';
|
|
2
|
+
|
|
3
|
+
/*** Expose only the credential-free repository inventory authorized for one normalized GitHub source. */
|
|
4
|
+
export function createWorkspaceInventoryRoute(inventoryAsync: WorkspaceInventoryAsync) {
|
|
5
|
+
return async function GET(request: Request): Promise<Response> {
|
|
6
|
+
const owner = new URL(request.url).searchParams.get('owner');
|
|
7
|
+
if (!isSelectionSource(owner))
|
|
8
|
+
return Response.json({ error: 'Invalid workspace inventory source.' }, { status: 400 });
|
|
9
|
+
try {
|
|
10
|
+
return Response.json(await inventoryAsync(owner, request), { headers: noStoreHeaders });
|
|
11
|
+
} catch {
|
|
12
|
+
return Response.json({ error: 'Unable to discover workspace inventory.' }, { status: 502 });
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/*** Accept only one GitHub owner or the authenticated-user inventory sentinel. */
|
|
18
|
+
export function isSelectionSource(value: unknown): value is string {
|
|
19
|
+
return (
|
|
20
|
+
typeof value === 'string' &&
|
|
21
|
+
(value === '@me' || /^[A-Za-z\d](?:[A-Za-z\d-]{0,37}[A-Za-z\d])?$/u.test(value))
|
|
22
|
+
);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/*** Canonicalize equivalent owner spellings before they become a runtime scope key. */
|
|
26
|
+
export function normalizeSelectionSource(source: string): string {
|
|
27
|
+
return source === '@me' ? source : source.toLowerCase();
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export type WorkspaceInventoryAsync = (
|
|
31
|
+
owner: string,
|
|
32
|
+
request: Request
|
|
33
|
+
) => Promise<{
|
|
34
|
+
readonly owner: string;
|
|
35
|
+
readonly repositories: readonly WorkspaceRepositoryInventoryOption[];
|
|
36
|
+
}>;
|
|
37
|
+
|
|
38
|
+
const noStoreHeaders = { 'cache-control': 'no-store' };
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import type { WorkspaceRepositoryRuntimeResult } from '@/features/workspace/composition/composeWorkspaceRepositoryRuntimeResult';
|
|
2
|
+
|
|
3
|
+
/*** Stream complete credential-free workspace snapshots over one request-scoped serverless response. */
|
|
4
|
+
export function createWorkspaceProgressResponse(
|
|
5
|
+
generation: number,
|
|
6
|
+
runAsync: (
|
|
7
|
+
onProgress: (result: WorkspaceRepositoryRuntimeResult) => Promise<void>,
|
|
8
|
+
signal: AbortSignal
|
|
9
|
+
) => Promise<WorkspaceRepositoryRuntimeResult>
|
|
10
|
+
): Response {
|
|
11
|
+
const encoder = new TextEncoder();
|
|
12
|
+
const abortController = new AbortController();
|
|
13
|
+
const stream = new TransformStream<Uint8Array, Uint8Array>();
|
|
14
|
+
const writer = stream.writable.getWriter();
|
|
15
|
+
void writer.closed.catch(() => {
|
|
16
|
+
abortController.abort(
|
|
17
|
+
new DOMException('The workspace progress reader was cancelled.', 'AbortError')
|
|
18
|
+
);
|
|
19
|
+
});
|
|
20
|
+
void streamWorkspaceProgressAsync(writer, encoder, generation, runAsync, abortController);
|
|
21
|
+
return new Response(stream.readable, {
|
|
22
|
+
headers: {
|
|
23
|
+
'cache-control': 'no-store',
|
|
24
|
+
'content-type': 'application/x-ndjson; charset=utf-8',
|
|
25
|
+
'x-content-type-options': 'nosniff',
|
|
26
|
+
},
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/*** Serialize progress in reader demand order and retain a credential-free terminal failure signal. */
|
|
31
|
+
async function streamWorkspaceProgressAsync(
|
|
32
|
+
writer: WritableStreamDefaultWriter<Uint8Array>,
|
|
33
|
+
encoder: TextEncoder,
|
|
34
|
+
generation: number,
|
|
35
|
+
runAsync: Parameters<typeof createWorkspaceProgressResponse>[1],
|
|
36
|
+
abortController: AbortController
|
|
37
|
+
): Promise<void> {
|
|
38
|
+
const publish = (result: WorkspaceRepositoryRuntimeResult) =>
|
|
39
|
+
writer.write(encoder.encode(`${JSON.stringify(toProgressFrame(result, generation))}\n`));
|
|
40
|
+
try {
|
|
41
|
+
await publish(await runAsync(publish, abortController.signal));
|
|
42
|
+
await writer.close();
|
|
43
|
+
} catch {
|
|
44
|
+
if (abortController.signal.aborted) return;
|
|
45
|
+
await writer.write(encoder.encode(`${JSON.stringify(toTerminalErrorFrame(generation))}\n`));
|
|
46
|
+
await writer.close();
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/*** Keep every successful NDJSON record to the stable client contract and omit transport-internal fields. */
|
|
51
|
+
function toProgressFrame(result: WorkspaceRepositoryRuntimeResult, generation: number) {
|
|
52
|
+
return {
|
|
53
|
+
generation,
|
|
54
|
+
repositoryStatuses: result.repositoryStatuses,
|
|
55
|
+
runtimeId: result.runtimeId,
|
|
56
|
+
workspace: result.workspace,
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/*** Report a bounded stream failure without exposing an upstream error, credential, or filesystem detail. */
|
|
61
|
+
function toTerminalErrorFrame(generation: number) {
|
|
62
|
+
return {
|
|
63
|
+
error: 'Workspace progress stream failed.',
|
|
64
|
+
generation,
|
|
65
|
+
type: 'terminal-error' as const,
|
|
66
|
+
};
|
|
67
|
+
}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { isRecord } from '@ankhorage/utility/object';
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
isSelectionSource,
|
|
5
|
+
normalizeSelectionSource,
|
|
6
|
+
} from '@/features/workspace/adapters/inbound/next/createWorkspaceInventoryRoute';
|
|
7
|
+
import { createWorkspaceProgressResponse } from '@/features/workspace/adapters/inbound/next/createWorkspaceProgressResponse';
|
|
8
|
+
import { WorkspaceRepositoryRuntimeError } from '@/features/workspace/composition/createWorkspaceRepositoryRuntime';
|
|
9
|
+
import type { WorkspaceSelectionRequest } from '@/types/workspace';
|
|
10
|
+
|
|
11
|
+
/*** Validate a selection diff before composing its request-scoped streaming operation. */
|
|
12
|
+
export function createWorkspaceSelectionRoute(selectionAsync: WorkspaceSelectionAsync) {
|
|
13
|
+
return async function POST(request: Request): Promise<Response> {
|
|
14
|
+
let input: WorkspaceSelectionRequest;
|
|
15
|
+
try {
|
|
16
|
+
const body: unknown = await request.json();
|
|
17
|
+
if (!isSelectionRequest(body))
|
|
18
|
+
return Response.json({ error: 'Invalid workspace selection request.' }, { status: 400 });
|
|
19
|
+
input = { ...body, source: normalizeSelectionSource(body.source) };
|
|
20
|
+
} catch {
|
|
21
|
+
return Response.json({ error: 'Invalid workspace selection request.' }, { status: 400 });
|
|
22
|
+
}
|
|
23
|
+
try {
|
|
24
|
+
const operation = await selectionAsync(input, request);
|
|
25
|
+
return createWorkspaceProgressResponse(input.generation, operation.runAsync);
|
|
26
|
+
} catch (error) {
|
|
27
|
+
return selectionFailureResponse(error);
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/*** Reject URLs, duplicate identifiers, and non-diff initial requests at the untrusted HTTP boundary. */
|
|
33
|
+
function isSelectionRequest(value: unknown): value is WorkspaceSelectionRequest {
|
|
34
|
+
if (!isRecord(value) || !isSelectionSource(value.source) || !isGeneration(value.generation))
|
|
35
|
+
return false;
|
|
36
|
+
if (
|
|
37
|
+
!isIdentifierArray(value.addedRepositoryIds) ||
|
|
38
|
+
!isIdentifierArray(value.removedRepositoryIds)
|
|
39
|
+
)
|
|
40
|
+
return false;
|
|
41
|
+
if (value.runtimeId !== undefined && !isOpaqueIdentifier(value.runtimeId)) return false;
|
|
42
|
+
if (
|
|
43
|
+
new Set([...value.addedRepositoryIds, ...value.removedRepositoryIds]).size !==
|
|
44
|
+
value.addedRepositoryIds.length + value.removedRepositoryIds.length
|
|
45
|
+
)
|
|
46
|
+
return false;
|
|
47
|
+
return value.runtimeId !== undefined || value.removedRepositoryIds.length === 0;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/*** Bound client generation values so a stale browser request cannot exhaust transport parsing. */
|
|
51
|
+
function isGeneration(value: unknown): value is number {
|
|
52
|
+
return typeof value === 'number' && Number.isSafeInteger(value) && value >= 0;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/*** Keep opaque repository and runtime identities away from paths, URLs, and unbounded input. */
|
|
56
|
+
function isOpaqueIdentifier(value: unknown): value is string {
|
|
57
|
+
return (
|
|
58
|
+
typeof value === 'string' && value.length > 0 && value.length <= 256 && !/[\\/\s]/u.test(value)
|
|
59
|
+
);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/*** Guard the discovery validation path against pathological request-array sizes. */
|
|
63
|
+
function isIdentifierArray(value: unknown): value is readonly string[] {
|
|
64
|
+
return (
|
|
65
|
+
Array.isArray(value) &&
|
|
66
|
+
value.length <= 256 &&
|
|
67
|
+
value.every(isOpaqueIdentifier) &&
|
|
68
|
+
new Set(value).size === value.length
|
|
69
|
+
);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/*** Return recoverable runtime loss before starting an NDJSON stream. */
|
|
73
|
+
function selectionFailureResponse(error: unknown): Response {
|
|
74
|
+
if (!(error instanceof WorkspaceRepositoryRuntimeError))
|
|
75
|
+
return Response.json({ error: 'Unable to apply workspace selection.' }, { status: 500 });
|
|
76
|
+
const status = error.kind === 'unavailable' ? 410 : error.kind === 'rate-limited' ? 429 : 400;
|
|
77
|
+
return Response.json(
|
|
78
|
+
{ error: error.message, recoverable: error.kind === 'unavailable' },
|
|
79
|
+
{ status }
|
|
80
|
+
);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
interface WorkspaceSelectionOperation {
|
|
84
|
+
readonly runAsync: Parameters<typeof createWorkspaceProgressResponse>[1];
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
type WorkspaceSelectionAsync = (
|
|
88
|
+
input: WorkspaceSelectionRequest,
|
|
89
|
+
request: Request
|
|
90
|
+
) => Promise<WorkspaceSelectionOperation>;
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
WorkspaceRepositoryFailure,
|
|
3
|
+
WorkspaceRepositoryFailureCategory,
|
|
4
|
+
} from '@/types/workspace';
|
|
5
|
+
|
|
6
|
+
/*** Convert only observable transport facts into a bounded, browser-safe repository failure. */
|
|
7
|
+
export function classifyWorkspaceRepositoryFailure(error: unknown): WorkspaceRepositoryFailure {
|
|
8
|
+
if (isAbort(error)) return { category: 'cancelled' };
|
|
9
|
+
const status = statusCode(error);
|
|
10
|
+
if (status === 401) return { category: 'authentication' };
|
|
11
|
+
if (status === 404) return { category: 'not-found' };
|
|
12
|
+
const rateLimitKind = rateLimitKindFrom(error);
|
|
13
|
+
if (rateLimitKind !== undefined)
|
|
14
|
+
return {
|
|
15
|
+
category: rateLimitKind,
|
|
16
|
+
...(retryAfterSeconds(error) === undefined
|
|
17
|
+
? {}
|
|
18
|
+
: { retryAfterSeconds: retryAfterSeconds(error) }),
|
|
19
|
+
};
|
|
20
|
+
if (status === 429) return { category: 'rate-limited' };
|
|
21
|
+
if (status !== undefined && status >= 500 && status <= 599) return { category: 'upstream' };
|
|
22
|
+
if (isTimeout(error)) return { category: 'timeout' };
|
|
23
|
+
if (isParsing(error)) return { category: 'parsing' };
|
|
24
|
+
if (isRuntimeLimit(error)) return { category: 'runtime-limit' };
|
|
25
|
+
return { category: 'unknown' };
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/*** Return only a prewritten explanation for a classified failure. */
|
|
29
|
+
export function workspaceRepositoryFailureDescription(failure: WorkspaceRepositoryFailure): string {
|
|
30
|
+
const descriptions: Record<WorkspaceRepositoryFailureCategory, string> = {
|
|
31
|
+
authentication: 'GitHub authentication is required to analyze this repository.',
|
|
32
|
+
authorization: 'GitHub did not authorize access to this repository.',
|
|
33
|
+
cancelled: 'Loading was cancelled.',
|
|
34
|
+
'not-found': 'The repository or requested revision was not found.',
|
|
35
|
+
'primary-rate-limit': 'GitHub rate limiting delayed this repository.',
|
|
36
|
+
'rate-limited': 'This repository is temporarily rate limited. Retry shortly.',
|
|
37
|
+
'secondary-rate-limit': 'GitHub secondary rate limiting delayed this repository.',
|
|
38
|
+
parsing: 'The repository could not be analyzed because its source could not be parsed.',
|
|
39
|
+
'runtime-limit': 'The repository exceeded an Atlas runtime resource limit.',
|
|
40
|
+
timeout: 'The repository operation timed out.',
|
|
41
|
+
unknown: 'The repository could not be analyzed. Retry to obtain a fresh diagnostic.',
|
|
42
|
+
upstream: 'GitHub or an upstream service was temporarily unavailable.',
|
|
43
|
+
};
|
|
44
|
+
const retry = failure.retryAfterSeconds;
|
|
45
|
+
return retry === undefined
|
|
46
|
+
? descriptions[failure.category]
|
|
47
|
+
: `${descriptions[failure.category]} Retry after ${retry} seconds.`;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/*** Detect intentional cancellation without reading an arbitrary error message. */
|
|
51
|
+
function isAbort(error: unknown): boolean {
|
|
52
|
+
return error instanceof DOMException
|
|
53
|
+
? error.name === 'AbortError'
|
|
54
|
+
: error instanceof Error && error.name === 'AbortError';
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/*** Read a conventional numeric HTTP status without retaining the response or body. */
|
|
58
|
+
function statusCode(error: unknown): number | undefined {
|
|
59
|
+
if (error instanceof Response) return error.status;
|
|
60
|
+
if (typeof error !== 'object' || error === null || !('status' in error)) return undefined;
|
|
61
|
+
const { status } = error;
|
|
62
|
+
return typeof status === 'number' && Number.isInteger(status) ? status : undefined;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/*** Accept only an adapter-provided, bounded rate-limit kind rather than inferring it from HTTP status. */
|
|
66
|
+
function rateLimitKindFrom(
|
|
67
|
+
error: unknown
|
|
68
|
+
): 'primary-rate-limit' | 'secondary-rate-limit' | undefined {
|
|
69
|
+
if (typeof error !== 'object' || error === null || !('rateLimitKind' in error)) return undefined;
|
|
70
|
+
return error.rateLimitKind === 'primary'
|
|
71
|
+
? 'primary-rate-limit'
|
|
72
|
+
: error.rateLimitKind === 'secondary'
|
|
73
|
+
? 'secondary-rate-limit'
|
|
74
|
+
: undefined;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/*** Extract a bounded Retry-After value only when an adapter exposed it numerically. */
|
|
78
|
+
function retryAfterSeconds(error: unknown): number | undefined {
|
|
79
|
+
if (typeof error !== 'object' || error === null || !('retryAfterSeconds' in error))
|
|
80
|
+
return undefined;
|
|
81
|
+
const { retryAfterSeconds: retryAfter } = error;
|
|
82
|
+
return typeof retryAfter === 'number' &&
|
|
83
|
+
Number.isInteger(retryAfter) &&
|
|
84
|
+
retryAfter >= 0 &&
|
|
85
|
+
retryAfter <= 86_400
|
|
86
|
+
? retryAfter
|
|
87
|
+
: undefined;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/*** Classify standard timeout names without forwarding their potentially sensitive details. */
|
|
91
|
+
function isTimeout(error: unknown): boolean {
|
|
92
|
+
return error instanceof Error && (error.name === 'TimeoutError' || error.name === 'ETIMEDOUT');
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/*** Classify parser adapters that deliberately expose a stable error class. */
|
|
96
|
+
function isParsing(error: unknown): boolean {
|
|
97
|
+
return error instanceof Error && error.name === 'SyntaxError';
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/*** Classify explicit resource-limit error names emitted by serverless and materialization adapters. */
|
|
101
|
+
function isRuntimeLimit(error: unknown): boolean {
|
|
102
|
+
return (
|
|
103
|
+
error instanceof Error && (error.name === 'RangeError' || error.name === 'ResourceLimitError')
|
|
104
|
+
);
|
|
105
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createProjectAnalysisSnapshotAsync,
|
|
3
|
+
createSourceGraphFromProjectAnalysisSnapshots,
|
|
4
|
+
projectDependencyGraphFromProjectAnalysisSnapshots,
|
|
5
|
+
} from '@ankhorage/dependency-graph';
|
|
6
|
+
import type {
|
|
7
|
+
GitHubRepositoryAuthentication,
|
|
8
|
+
GitHubRepositoryDiscoveryRepository,
|
|
9
|
+
} from '@ankhorage/repository/github';
|
|
10
|
+
|
|
11
|
+
import { inspectProjectForAnalysisAsync } from '@/features/project-analysis/adapters/outbound/project-detector/inspectProjectForAnalysisAsync';
|
|
12
|
+
import { selectParserLanguage } from '@/features/project-analysis/application/use-cases/selectParserLanguage';
|
|
13
|
+
import { createProjectFileTreeAsync } from '@/features/project-analysis/composition/createProjectFileTreeAsync';
|
|
14
|
+
import { parseProjectSource } from '@/features/project-source/application/use-cases/parseProjectSource';
|
|
15
|
+
import { loadProjectSourceAsync } from '@/features/project-source/composition/loadProjectSourceAsync';
|
|
16
|
+
import type { WorkspaceAnalysisCache } from '@/features/workspace/application/use-cases/createWorkspaceAnalysisCache';
|
|
17
|
+
import type { RepositoryAnalysis } from '@/features/workspace/composition/composeWorkspaceRepositoryRuntimeResult';
|
|
18
|
+
import type { WorkspaceRepositoryRuntimeDependencies } from '@/features/workspace/composition/createWorkspaceRepositoryRuntime';
|
|
19
|
+
|
|
20
|
+
/*** Resolve, cache, materialize, and analyze one immutable GitHub revision. */
|
|
21
|
+
export async function analyzeWorkspaceRepositoryAsync(
|
|
22
|
+
repository: GitHubRepositoryDiscoveryRepository,
|
|
23
|
+
authentication: GitHubRepositoryAuthentication,
|
|
24
|
+
authorizationScope: string,
|
|
25
|
+
cache: WorkspaceAnalysisCache<RepositoryAnalysis>,
|
|
26
|
+
dependencies: WorkspaceRepositoryRuntimeDependencies,
|
|
27
|
+
signal?: AbortSignal
|
|
28
|
+
): Promise<RepositoryAnalysis> {
|
|
29
|
+
const revision = await dependencies.resolveRevisionAsync(repository.url, authentication, signal);
|
|
30
|
+
const key = cacheKey(revision, authorizationScope);
|
|
31
|
+
const cached = cache.getAnalysis(key);
|
|
32
|
+
if (cached !== undefined) return cached;
|
|
33
|
+
const source = parseProjectSource(repository.url);
|
|
34
|
+
if (source.kind !== 'github') throw new Error('Workspace repositories must be GitHub sources.');
|
|
35
|
+
const resolved = await (dependencies.materializeAsync ?? loadProjectSourceAsync)(
|
|
36
|
+
{ ...source, revision: revision.revision.commitSha },
|
|
37
|
+
signal,
|
|
38
|
+
authentication
|
|
39
|
+
);
|
|
40
|
+
try {
|
|
41
|
+
const inspection = await (dependencies.inspectAsync ?? inspectProjectForAnalysisAsync)(
|
|
42
|
+
resolved.rootPath
|
|
43
|
+
);
|
|
44
|
+
const analysis = await createProjectAnalysisSnapshotAsync({ id: repository.id, inspection });
|
|
45
|
+
const graph = projectDependencyGraphFromProjectAnalysisSnapshots(
|
|
46
|
+
createSourceGraphFromProjectAnalysisSnapshots([analysis]),
|
|
47
|
+
[analysis]
|
|
48
|
+
);
|
|
49
|
+
const language = selectParserLanguage(inspection.detection);
|
|
50
|
+
const value = {
|
|
51
|
+
analysis,
|
|
52
|
+
files: await createProjectFileTreeAsync(
|
|
53
|
+
inspection,
|
|
54
|
+
graph,
|
|
55
|
+
language.language,
|
|
56
|
+
resolved.rootPath
|
|
57
|
+
),
|
|
58
|
+
language,
|
|
59
|
+
};
|
|
60
|
+
cache.setAnalysis(key, value);
|
|
61
|
+
return value;
|
|
62
|
+
} finally {
|
|
63
|
+
await resolved.cleanupAsync();
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/*** Scope an immutable analysis to its authorized GitHub identity and resolved revision. */
|
|
68
|
+
function cacheKey(
|
|
69
|
+
revision: Awaited<ReturnType<WorkspaceRepositoryRuntimeDependencies['resolveRevisionAsync']>>,
|
|
70
|
+
authorization: string
|
|
71
|
+
) {
|
|
72
|
+
return {
|
|
73
|
+
authorization,
|
|
74
|
+
provider: 'github' as const,
|
|
75
|
+
repositoryId: revision.repository.id,
|
|
76
|
+
revision: revision.revision.commitSha,
|
|
77
|
+
schemaVersion: 1,
|
|
78
|
+
};
|
|
79
|
+
}
|