@ankhorage/repository 0.4.18 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +143 -0
- package/README.md +16 -27
- package/dist/cli/commands/materialize/definitions/MaterializeCommandOptions.d.ts +6 -0
- package/dist/cli/commands/materialize/definitions/MaterializeCommandOptions.d.ts.map +1 -0
- package/dist/cli/commands/materialize/definitions/MaterializeCommandOptions.js +2 -0
- package/dist/cli/commands/materialize/definitions/MaterializeCommandOptions.js.map +1 -0
- package/dist/cli/commands/materialize/parseMaterializeCommandOptions.d.ts +4 -0
- package/dist/cli/commands/materialize/parseMaterializeCommandOptions.d.ts.map +1 -0
- package/dist/cli/commands/materialize/parseMaterializeCommandOptions.js +33 -0
- package/dist/cli/commands/materialize/parseMaterializeCommandOptions.js.map +1 -0
- package/dist/cli/commands/materialize/parseMaterializeCommandOptions.test.d.ts +2 -0
- package/dist/cli/commands/materialize/parseMaterializeCommandOptions.test.d.ts.map +1 -0
- package/dist/cli/commands/materialize/parseMaterializeCommandOptions.test.js +23 -0
- package/dist/cli/commands/materialize/parseMaterializeCommandOptions.test.js.map +1 -0
- package/dist/cli/commands/materialize/runMaterializeCommandAsync.d.ts +10 -0
- package/dist/cli/commands/materialize/runMaterializeCommandAsync.d.ts.map +1 -0
- package/dist/cli/commands/materialize/runMaterializeCommandAsync.js +28 -0
- package/dist/cli/commands/materialize/runMaterializeCommandAsync.js.map +1 -0
- package/dist/cli/provider/createRepositoryRuntimeProvider.d.ts +14 -2
- package/dist/cli/provider/createRepositoryRuntimeProvider.d.ts.map +1 -1
- package/dist/cli/provider/createRepositoryRuntimeProvider.js +7 -9
- package/dist/cli/provider/createRepositoryRuntimeProvider.js.map +1 -1
- package/dist/cli/provider/createRepositoryRuntimeProvider.test.js +6 -2
- package/dist/cli/provider/createRepositoryRuntimeProvider.test.js.map +1 -1
- package/dist/github/index.d.ts +3 -0
- package/dist/github/index.d.ts.map +1 -1
- package/dist/github/index.js +1 -0
- package/dist/github/index.js.map +1 -1
- package/dist/metadata/index.d.ts +1 -1
- package/dist/metadata/index.js +1 -1
- package/dist/metadata/index.js.map +1 -1
- package/dist/metadata/repositoryPackageMetadata.d.ts +6 -1
- package/dist/metadata/repositoryPackageMetadata.d.ts.map +1 -1
- package/dist/metadata/repositoryPackageMetadata.js +6 -1
- package/dist/metadata/repositoryPackageMetadata.js.map +1 -1
- package/dist/providers/github/adapters/createGitHubHttpRepositoryReadGateway.d.ts +4 -0
- package/dist/providers/github/adapters/createGitHubHttpRepositoryReadGateway.d.ts.map +1 -0
- package/dist/providers/github/adapters/createGitHubHttpRepositoryReadGateway.js +115 -0
- package/dist/providers/github/adapters/createGitHubHttpRepositoryReadGateway.js.map +1 -0
- package/dist/providers/github/adapters/createGitHubHttpRepositoryReadGateway.test.d.ts +2 -0
- package/dist/providers/github/adapters/createGitHubHttpRepositoryReadGateway.test.d.ts.map +1 -0
- package/dist/providers/github/adapters/createGitHubHttpRepositoryReadGateway.test.js +80 -0
- package/dist/providers/github/adapters/createGitHubHttpRepositoryReadGateway.test.js.map +1 -0
- package/dist/providers/github/definitions/GitHubRepositoryConnectionOptions.d.ts +0 -8
- package/dist/providers/github/definitions/GitHubRepositoryConnectionOptions.d.ts.map +1 -1
- package/dist/providers/github/definitions/GitHubRepositoryMaterializationOptions.d.ts +6 -0
- package/dist/providers/github/definitions/GitHubRepositoryMaterializationOptions.d.ts.map +1 -0
- package/dist/providers/github/definitions/GitHubRepositoryMaterializationOptions.js +2 -0
- package/dist/providers/github/definitions/GitHubRepositoryMaterializationOptions.js.map +1 -0
- package/dist/providers/github/definitions/GitHubRepositoryMaterializationResult.d.ts +12 -0
- package/dist/providers/github/definitions/GitHubRepositoryMaterializationResult.d.ts.map +1 -0
- package/dist/providers/github/definitions/GitHubRepositoryMaterializationResult.js +2 -0
- package/dist/providers/github/definitions/GitHubRepositoryMaterializationResult.js.map +1 -0
- package/dist/providers/github/ports/GitHubRepositoryReadGateway.d.ts +31 -0
- package/dist/providers/github/ports/GitHubRepositoryReadGateway.d.ts.map +1 -0
- package/dist/providers/github/ports/GitHubRepositoryReadGateway.js +2 -0
- package/dist/providers/github/ports/GitHubRepositoryReadGateway.js.map +1 -0
- package/dist/providers/github/services/connectGitHubRepositoryAsync.d.ts +10 -1
- package/dist/providers/github/services/connectGitHubRepositoryAsync.d.ts.map +1 -1
- package/dist/providers/github/services/connectGitHubRepositoryAsync.js.map +1 -1
- package/dist/providers/github/services/connectGitHubRepositoryAsync.test.js.map +1 -1
- package/dist/providers/github/services/materializeGitHubRepositoryAsync.d.ts +5 -0
- package/dist/providers/github/services/materializeGitHubRepositoryAsync.d.ts.map +1 -0
- package/dist/providers/github/services/materializeGitHubRepositoryAsync.js +7 -0
- package/dist/providers/github/services/materializeGitHubRepositoryAsync.js.map +1 -0
- package/dist/providers/github/services/materializeGitHubRepositoryWithGatewayAsync.d.ts +6 -0
- package/dist/providers/github/services/materializeGitHubRepositoryWithGatewayAsync.d.ts.map +1 -0
- package/dist/providers/github/services/materializeGitHubRepositoryWithGatewayAsync.js +156 -0
- package/dist/providers/github/services/materializeGitHubRepositoryWithGatewayAsync.js.map +1 -0
- package/dist/providers/github/services/materializeGitHubRepositoryWithGatewayAsync.test.d.ts +2 -0
- package/dist/providers/github/services/materializeGitHubRepositoryWithGatewayAsync.test.d.ts.map +1 -0
- package/dist/providers/github/services/materializeGitHubRepositoryWithGatewayAsync.test.js +116 -0
- package/dist/providers/github/services/materializeGitHubRepositoryWithGatewayAsync.test.js.map +1 -0
- package/package.json +9 -8
- package/dist/readme-usage.d.ts +0 -2
- package/dist/readme-usage.d.ts.map +0 -1
- package/dist/readme-usage.js +0 -32
- package/dist/readme-usage.js.map +0 -1
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
/*** Create the read-only GitHub gateway used to materialize repository snapshots over HTTPS. */
|
|
2
|
+
export function createGitHubHttpRepositoryReadGateway(fetcher = fetch) {
|
|
3
|
+
return {
|
|
4
|
+
inspectRepositoryAsync: (target) => inspectRepositoryAsync(fetcher, target),
|
|
5
|
+
resolveRevisionAsync: (target, ref) => resolveRevisionAsync(fetcher, target, ref),
|
|
6
|
+
readTreeAsync: (target, treeSha) => readTreeAsync(fetcher, target, treeSha),
|
|
7
|
+
readFileAsync: (target, revision, path) => readFileAsync(fetcher, target, revision, path),
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
const API_ORIGIN = 'https://api.github.com';
|
|
11
|
+
const RAW_ORIGIN = 'https://raw.githubusercontent.com';
|
|
12
|
+
/*** Read repository metadata without mutating provider state. */
|
|
13
|
+
async function inspectRepositoryAsync(fetcher, target) {
|
|
14
|
+
const value = await requestJsonAsync(fetcher, `${API_ORIGIN}/repos/${encodeURIComponent(target.owner)}/${encodeURIComponent(target.name)}`);
|
|
15
|
+
const record = requireRecord(value, 'repository metadata');
|
|
16
|
+
const defaultBranch = requireString(record.default_branch, 'repository default branch');
|
|
17
|
+
const url = typeof record.html_url === 'string' ? record.html_url : target.url;
|
|
18
|
+
return { defaultBranch, url };
|
|
19
|
+
}
|
|
20
|
+
/*** Resolve a branch, tag, or commit ref to an immutable commit and tree SHA. */
|
|
21
|
+
async function resolveRevisionAsync(fetcher, target, ref) {
|
|
22
|
+
const value = await requestJsonAsync(fetcher, `${API_ORIGIN}/repos/${encodeURIComponent(target.owner)}/${encodeURIComponent(target.name)}/commits/${encodeURIComponent(ref)}`);
|
|
23
|
+
const record = requireRecord(value, 'repository revision');
|
|
24
|
+
const commit = requireRecord(record.commit, 'repository commit');
|
|
25
|
+
const tree = requireRecord(commit.tree, 'repository commit tree');
|
|
26
|
+
return {
|
|
27
|
+
commitSha: requireString(record.sha, 'repository commit SHA'),
|
|
28
|
+
treeSha: requireString(tree.sha, 'repository tree SHA'),
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
/*** Read the complete recursive tree for one immutable Git tree SHA. */
|
|
32
|
+
async function readTreeAsync(fetcher, target, treeSha) {
|
|
33
|
+
const value = await requestJsonAsync(fetcher, `${API_ORIGIN}/repos/${encodeURIComponent(target.owner)}/${encodeURIComponent(target.name)}/git/trees/${encodeURIComponent(treeSha)}?recursive=1`);
|
|
34
|
+
const record = requireRecord(value, 'repository tree');
|
|
35
|
+
if (!Array.isArray(record.tree))
|
|
36
|
+
throw new Error('GitHub returned an invalid repository tree.');
|
|
37
|
+
return {
|
|
38
|
+
entries: record.tree.map((entry) => parseTreeEntry(entry)),
|
|
39
|
+
truncated: record.truncated === true,
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
/*** Read one file from an immutable GitHub revision without executing repository code. */
|
|
43
|
+
async function readFileAsync(fetcher, target, revision, path) {
|
|
44
|
+
const encodedPath = path
|
|
45
|
+
.split('/')
|
|
46
|
+
.map((segment) => encodeURIComponent(segment))
|
|
47
|
+
.join('/');
|
|
48
|
+
const response = await fetcher(`${RAW_ORIGIN}/${encodeURIComponent(target.owner)}/${encodeURIComponent(target.name)}/${encodeURIComponent(revision)}/${encodedPath}`, { headers: requestHeaders(), signal: AbortSignal.timeout(30_000) });
|
|
49
|
+
if (!response.ok)
|
|
50
|
+
throw requestError(response, 'repository file');
|
|
51
|
+
return new Uint8Array(await response.arrayBuffer());
|
|
52
|
+
}
|
|
53
|
+
/*** Parse one Git tree item while rejecting malformed provider responses. */
|
|
54
|
+
function parseTreeEntry(value) {
|
|
55
|
+
const record = requireRecord(value, 'repository tree entry');
|
|
56
|
+
const type = requireString(record.type, 'repository tree entry type');
|
|
57
|
+
if (type !== 'blob' && type !== 'tree' && type !== 'commit') {
|
|
58
|
+
throw new Error(`GitHub returned an unsupported repository tree entry type: ${type}.`);
|
|
59
|
+
}
|
|
60
|
+
const { size } = record;
|
|
61
|
+
if (size !== undefined && (typeof size !== 'number' || !Number.isSafeInteger(size) || size < 0)) {
|
|
62
|
+
throw new Error('GitHub returned an invalid repository tree entry size.');
|
|
63
|
+
}
|
|
64
|
+
return {
|
|
65
|
+
mode: requireString(record.mode, 'repository tree entry mode'),
|
|
66
|
+
path: requireString(record.path, 'repository tree entry path'),
|
|
67
|
+
sha: requireString(record.sha, 'repository tree entry SHA'),
|
|
68
|
+
type,
|
|
69
|
+
...(size === undefined ? {} : { size }),
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
/*** Request GitHub JSON with stable safe errors and optional standard token authentication. */
|
|
73
|
+
async function requestJsonAsync(fetcher, url) {
|
|
74
|
+
const response = await fetcher(url, {
|
|
75
|
+
headers: requestHeaders(),
|
|
76
|
+
signal: AbortSignal.timeout(30_000),
|
|
77
|
+
});
|
|
78
|
+
if (!response.ok)
|
|
79
|
+
throw requestError(response, 'repository metadata');
|
|
80
|
+
try {
|
|
81
|
+
return await response.json();
|
|
82
|
+
}
|
|
83
|
+
catch (error) {
|
|
84
|
+
throw new Error('GitHub returned malformed JSON.', { cause: error });
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
/*** Build GitHub request headers without exposing credentials to callers or errors. */
|
|
88
|
+
function requestHeaders() {
|
|
89
|
+
const token = process.env.GITHUB_TOKEN ?? process.env.GH_TOKEN;
|
|
90
|
+
return {
|
|
91
|
+
Accept: 'application/vnd.github+json',
|
|
92
|
+
'User-Agent': '@ankhorage/repository',
|
|
93
|
+
'X-GitHub-Api-Version': '2022-11-28',
|
|
94
|
+
...(token ? { Authorization: `Bearer ${token}` } : {}),
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
/*** Convert one failed provider response into a credential-free diagnostic. */
|
|
98
|
+
function requestError(response, subject) {
|
|
99
|
+
return new Error(`GitHub ${subject} request failed with HTTP ${response.status}.`);
|
|
100
|
+
}
|
|
101
|
+
/*** Narrow unknown JSON values to object records. */
|
|
102
|
+
function requireRecord(value, subject) {
|
|
103
|
+
if (typeof value !== 'object' || value === null || Array.isArray(value)) {
|
|
104
|
+
throw new Error(`GitHub returned invalid ${subject}.`);
|
|
105
|
+
}
|
|
106
|
+
return Object.fromEntries(Object.entries(value));
|
|
107
|
+
}
|
|
108
|
+
/*** Require a non-empty provider string field. */
|
|
109
|
+
function requireString(value, subject) {
|
|
110
|
+
if (typeof value !== 'string' || value.trim() === '') {
|
|
111
|
+
throw new Error(`GitHub returned invalid ${subject}.`);
|
|
112
|
+
}
|
|
113
|
+
return value;
|
|
114
|
+
}
|
|
115
|
+
//# sourceMappingURL=createGitHubHttpRepositoryReadGateway.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createGitHubHttpRepositoryReadGateway.js","sourceRoot":"","sources":["../../../../src/providers/github/adapters/createGitHubHttpRepositoryReadGateway.ts"],"names":[],"mappings":"AASA,gGAAgG;AAChG,MAAM,UAAU,qCAAqC,CACnD,UAAwB,KAAK;IAE7B,OAAO;QACL,sBAAsB,EAAE,CAAC,MAAM,EAAE,EAAE,CAAC,sBAAsB,CAAC,OAAO,EAAE,MAAM,CAAC;QAC3E,oBAAoB,EAAE,CAAC,MAAM,EAAE,GAAG,EAAE,EAAE,CAAC,oBAAoB,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,CAAC;QACjF,aAAa,EAAE,CAAC,MAAM,EAAE,OAAO,EAAE,EAAE,CAAC,aAAa,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC;QAC3E,aAAa,EAAE,CAAC,MAAM,EAAE,QAAQ,EAAE,IAAI,EAAE,EAAE,CAAC,aAAa,CAAC,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,IAAI,CAAC;KAC1F,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,GAAG,wBAAwB,CAAC;AAC5C,MAAM,UAAU,GAAG,mCAAmC,CAAC;AAEvD,iEAAiE;AACjE,KAAK,UAAU,sBAAsB,CACnC,OAAqB,EACrB,MAAkC;IAElC,MAAM,KAAK,GAAG,MAAM,gBAAgB,CAClC,OAAO,EACP,GAAG,UAAU,UAAU,kBAAkB,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,kBAAkB,CAAC,MAAM,CAAC,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;IACpD,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC;QACrD,MAAM,IAAI,KAAK,CAAC,2BAA2B,OAAO,GAAG,CAAC,CAAC;IACzD,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createGitHubHttpRepositoryReadGateway.test.d.ts","sourceRoot":"","sources":["../../../../src/providers/github/adapters/createGitHubHttpRepositoryReadGateway.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { expect, test } from 'bun:test';
|
|
2
|
+
import { createGitHubHttpRepositoryReadGateway } from './createGitHubHttpRepositoryReadGateway.js';
|
|
3
|
+
test('reads repository metadata, immutable revision, tree, and raw file content', async () => {
|
|
4
|
+
const urls = [];
|
|
5
|
+
const gateway = createGitHubHttpRepositoryReadGateway(createFetchFixture(urls));
|
|
6
|
+
const target = {
|
|
7
|
+
owner: 'ankhorage',
|
|
8
|
+
name: 'demo',
|
|
9
|
+
url: 'https://github.com/ankhorage/demo',
|
|
10
|
+
};
|
|
11
|
+
expect(await gateway.inspectRepositoryAsync(target)).toEqual({
|
|
12
|
+
defaultBranch: 'main',
|
|
13
|
+
url: 'https://github.com/ankhorage/demo',
|
|
14
|
+
});
|
|
15
|
+
expect(await gateway.resolveRevisionAsync(target, 'feature/read')).toEqual({
|
|
16
|
+
commitSha: 'commit-sha',
|
|
17
|
+
treeSha: 'tree-sha',
|
|
18
|
+
});
|
|
19
|
+
expect(await gateway.readTreeAsync(target, 'tree-sha')).toEqual({
|
|
20
|
+
entries: [
|
|
21
|
+
{
|
|
22
|
+
path: 'src/index.ts',
|
|
23
|
+
mode: '100644',
|
|
24
|
+
type: 'blob',
|
|
25
|
+
sha: 'blob-sha',
|
|
26
|
+
size: 10,
|
|
27
|
+
},
|
|
28
|
+
],
|
|
29
|
+
truncated: false,
|
|
30
|
+
});
|
|
31
|
+
expect(Buffer.from(await gateway.readFileAsync(target, 'commit-sha', 'src/index.ts')).toString()).toBe('0123456789');
|
|
32
|
+
expect(urls).toContain('https://raw.githubusercontent.com/ankhorage/demo/commit-sha/src/index.ts');
|
|
33
|
+
});
|
|
34
|
+
function createFetchFixture(urls) {
|
|
35
|
+
return ((input) => {
|
|
36
|
+
const url = requestUrl(input);
|
|
37
|
+
urls.push(url);
|
|
38
|
+
return Promise.resolve(responseForUrl(url));
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
function requestUrl(input) {
|
|
42
|
+
if (typeof input === 'string')
|
|
43
|
+
return input;
|
|
44
|
+
if (input instanceof URL)
|
|
45
|
+
return input.href;
|
|
46
|
+
return input.url;
|
|
47
|
+
}
|
|
48
|
+
function responseForUrl(url) {
|
|
49
|
+
if (url.endsWith('/repos/ankhorage/demo')) {
|
|
50
|
+
return Response.json({
|
|
51
|
+
default_branch: 'main',
|
|
52
|
+
html_url: 'https://github.com/ankhorage/demo',
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
if (url.endsWith('/repos/ankhorage/demo/commits/feature%2Fread')) {
|
|
56
|
+
return Response.json({
|
|
57
|
+
sha: 'commit-sha',
|
|
58
|
+
commit: { tree: { sha: 'tree-sha' } },
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
if (url.endsWith('/repos/ankhorage/demo/git/trees/tree-sha?recursive=1')) {
|
|
62
|
+
return Response.json({
|
|
63
|
+
truncated: false,
|
|
64
|
+
tree: [
|
|
65
|
+
{
|
|
66
|
+
path: 'src/index.ts',
|
|
67
|
+
mode: '100644',
|
|
68
|
+
type: 'blob',
|
|
69
|
+
sha: 'blob-sha',
|
|
70
|
+
size: 10,
|
|
71
|
+
},
|
|
72
|
+
],
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
if (url.endsWith('/ankhorage/demo/commit-sha/src/index.ts')) {
|
|
76
|
+
return new Response('0123456789');
|
|
77
|
+
}
|
|
78
|
+
return new Response('', { status: 404 });
|
|
79
|
+
}
|
|
80
|
+
//# sourceMappingURL=createGitHubHttpRepositoryReadGateway.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createGitHubHttpRepositoryReadGateway.test.js","sourceRoot":"","sources":["../../../../src/providers/github/adapters/createGitHubHttpRepositoryReadGateway.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,UAAU,CAAC;AAExC,OAAO,EAAE,qCAAqC,EAAE,MAAM,4CAA4C,CAAC;AAEnG,IAAI,CAAC,2EAA2E,EAAE,KAAK,IAAI,EAAE;IAC3F,MAAM,IAAI,GAAa,EAAE,CAAC;IAC1B,MAAM,OAAO,GAAG,qCAAqC,CAAC,kBAAkB,CAAC,IAAI,CAAC,CAAC,CAAC;IAChF,MAAM,MAAM,GAAG;QACb,KAAK,EAAE,WAAW;QAClB,IAAI,EAAE,MAAM;QACZ,GAAG,EAAE,mCAAmC;KACzC,CAAC;IAEF,MAAM,CAAC,MAAM,OAAO,CAAC,sBAAsB,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC;QAC3D,aAAa,EAAE,MAAM;QACrB,GAAG,EAAE,mCAAmC;KACzC,CAAC,CAAC;IACH,MAAM,CAAC,MAAM,OAAO,CAAC,oBAAoB,CAAC,MAAM,EAAE,cAAc,CAAC,CAAC,CAAC,OAAO,CAAC;QACzE,SAAS,EAAE,YAAY;QACvB,OAAO,EAAE,UAAU;KACpB,CAAC,CAAC;IACH,MAAM,CAAC,MAAM,OAAO,CAAC,aAAa,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC,CAAC,OAAO,CAAC;QAC9D,OAAO,EAAE;YACP;gBACE,IAAI,EAAE,cAAc;gBACpB,IAAI,EAAE,QAAQ;gBACd,IAAI,EAAE,MAAM;gBACZ,GAAG,EAAE,UAAU;gBACf,IAAI,EAAE,EAAE;aACT;SACF;QACD,SAAS,EAAE,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D,IAAI,GAAG,CAAC,QAAQ,CAAC,sDAAsD,CAAC,EAAE,CAAC;QACzE,OAAO,QAAQ,CAAC,IAAI,CAAC;YACnB,SAAS,EAAE,KAAK;YAChB,IAAI,EAAE;gBACJ;oBACE,IAAI,EAAE,cAAc;oBACpB,IAAI,EAAE,QAAQ;oBACd,IAAI,EAAE,MAAM;oBACZ,GAAG,EAAE,UAAU;oBACf,IAAI,EAAE,EAAE;iBACT;aACF;SACF,CAAC,CAAC;IACL,CAAC;IACD,IAAI,GAAG,CAAC,QAAQ,CAAC,yCAAyC,CAAC,EAAE,CAAC;QAC5D,OAAO,IAAI,QAAQ,CAAC,YAAY,CAAC,CAAC;IACpC,CAAC;IACD,OAAO,IAAI,QAAQ,CAAC,EAAE,EAAE,EAAE,MAAM,EAAE,GAAG,EAAE,CAAC,CAAC;AAC3C,CAAC"}
|
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
import type { ProjectSnapshotReader } from '../../../connection/ports/ProjectSnapshotReader.js';
|
|
2
|
-
import type { RepositoryManifestStore } from '../../../connection/ports/RepositoryManifestStore.js';
|
|
3
|
-
import type { GitHubRepositoryGateway } from '../ports/GitHubRepositoryGateway.js';
|
|
4
1
|
import type { GitHubRepositoryVisibility } from './GitHubRepositoryVisibility.js';
|
|
5
2
|
export interface GitHubRepositoryConnectionOptions {
|
|
6
3
|
readonly projectPath?: string;
|
|
@@ -8,9 +5,4 @@ export interface GitHubRepositoryConnectionOptions {
|
|
|
8
5
|
readonly name?: string;
|
|
9
6
|
readonly visibility?: GitHubRepositoryVisibility;
|
|
10
7
|
}
|
|
11
|
-
export interface GitHubRepositoryConnectionDependencies {
|
|
12
|
-
readonly gateway?: GitHubRepositoryGateway;
|
|
13
|
-
readonly snapshotReader?: ProjectSnapshotReader;
|
|
14
|
-
readonly manifestStore?: RepositoryManifestStore;
|
|
15
|
-
}
|
|
16
8
|
//# sourceMappingURL=GitHubRepositoryConnectionOptions.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GitHubRepositoryConnectionOptions.d.ts","sourceRoot":"","sources":["../../../../src/providers/github/definitions/GitHubRepositoryConnectionOptions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"GitHubRepositoryConnectionOptions.d.ts","sourceRoot":"","sources":["../../../../src/providers/github/definitions/GitHubRepositoryConnectionOptions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,iCAAiC,CAAC;AAElF,MAAM,WAAW,iCAAiC;IAChD,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,UAAU,CAAC,EAAE,0BAA0B,CAAC;CAClD"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"GitHubRepositoryMaterializationOptions.d.ts","sourceRoot":"","sources":["../../../../src/providers/github/definitions/GitHubRepositoryMaterializationOptions.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,sCAAsC;IACrD,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,GAAG,CAAC,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,eAAe,CAAC,EAAE,MAAM,CAAC;CACnC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"GitHubRepositoryMaterializationOptions.js","sourceRoot":"","sources":["../../../../src/providers/github/definitions/GitHubRepositoryMaterializationOptions.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export interface GitHubRepositoryMaterializationResult {
|
|
2
|
+
readonly rootPath: string;
|
|
3
|
+
readonly revision: string;
|
|
4
|
+
readonly repository: {
|
|
5
|
+
readonly owner: string;
|
|
6
|
+
readonly name: string;
|
|
7
|
+
readonly url: string;
|
|
8
|
+
readonly defaultBranch: string;
|
|
9
|
+
};
|
|
10
|
+
readonly cleanupAsync: () => Promise<void>;
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=GitHubRepositoryMaterializationResult.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"GitHubRepositoryMaterializationResult.d.ts","sourceRoot":"","sources":["../../../../src/providers/github/definitions/GitHubRepositoryMaterializationResult.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,qCAAqC;IACpD,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,UAAU,EAAE;QACnB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;QACvB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;QACtB,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;QACrB,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;KAChC,CAAC;IACF,QAAQ,CAAC,YAAY,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;CAC5C"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"GitHubRepositoryMaterializationResult.js","sourceRoot":"","sources":["../../../../src/providers/github/definitions/GitHubRepositoryMaterializationResult.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
export interface GitHubRepositoryReadTarget {
|
|
2
|
+
readonly owner: string;
|
|
3
|
+
readonly name: string;
|
|
4
|
+
readonly url: string;
|
|
5
|
+
}
|
|
6
|
+
export interface GitHubRepositoryReadMetadata {
|
|
7
|
+
readonly defaultBranch: string;
|
|
8
|
+
readonly url: string;
|
|
9
|
+
}
|
|
10
|
+
export interface GitHubRepositoryRevision {
|
|
11
|
+
readonly commitSha: string;
|
|
12
|
+
readonly treeSha: string;
|
|
13
|
+
}
|
|
14
|
+
export interface GitHubRepositoryTreeEntry {
|
|
15
|
+
readonly mode: string;
|
|
16
|
+
readonly path: string;
|
|
17
|
+
readonly sha: string;
|
|
18
|
+
readonly size?: number;
|
|
19
|
+
readonly type: 'blob' | 'tree' | 'commit';
|
|
20
|
+
}
|
|
21
|
+
export interface GitHubRepositoryTree {
|
|
22
|
+
readonly entries: readonly GitHubRepositoryTreeEntry[];
|
|
23
|
+
readonly truncated: boolean;
|
|
24
|
+
}
|
|
25
|
+
export interface GitHubRepositoryReadGateway {
|
|
26
|
+
inspectRepositoryAsync(target: GitHubRepositoryReadTarget): Promise<GitHubRepositoryReadMetadata>;
|
|
27
|
+
resolveRevisionAsync(target: GitHubRepositoryReadTarget, ref: string): Promise<GitHubRepositoryRevision>;
|
|
28
|
+
readTreeAsync(target: GitHubRepositoryReadTarget, treeSha: string): Promise<GitHubRepositoryTree>;
|
|
29
|
+
readFileAsync(target: GitHubRepositoryReadTarget, revision: string, path: string): Promise<Uint8Array>;
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=GitHubRepositoryReadGateway.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"GitHubRepositoryReadGateway.d.ts","sourceRoot":"","sources":["../../../../src/providers/github/ports/GitHubRepositoryReadGateway.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,0BAA0B;IACzC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;CACtB;AAED,MAAM,WAAW,4BAA4B;IAC3C,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;IAC/B,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;CACtB;AAED,MAAM,WAAW,wBAAwB;IACvC,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;CAC1B;AAED,MAAM,WAAW,yBAAyB;IACxC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,QAAQ,CAAC;CAC3C;AAED,MAAM,WAAW,oBAAoB;IACnC,QAAQ,CAAC,OAAO,EAAE,SAAS,yBAAyB,EAAE,CAAC;IACvD,QAAQ,CAAC,SAAS,EAAE,OAAO,CAAC;CAC7B;AAED,MAAM,WAAW,2BAA2B;IAC1C,sBAAsB,CAAC,MAAM,EAAE,0BAA0B,GAAG,OAAO,CAAC,4BAA4B,CAAC,CAAC;IAClG,oBAAoB,CAClB,MAAM,EAAE,0BAA0B,EAClC,GAAG,EAAE,MAAM,GACV,OAAO,CAAC,wBAAwB,CAAC,CAAC;IACrC,aAAa,CAAC,MAAM,EAAE,0BAA0B,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,oBAAoB,CAAC,CAAC;IAClG,aAAa,CACX,MAAM,EAAE,0BAA0B,EAClC,QAAQ,EAAE,MAAM,EAChB,IAAI,EAAE,MAAM,GACX,OAAO,CAAC,UAAU,CAAC,CAAC;CACxB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"GitHubRepositoryReadGateway.js","sourceRoot":"","sources":["../../../../src/providers/github/ports/GitHubRepositoryReadGateway.ts"],"names":[],"mappings":""}
|
|
@@ -1,5 +1,14 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { ProjectSnapshotReader } from '../../../connection/ports/ProjectSnapshotReader.js';
|
|
2
|
+
import type { RepositoryManifestStore } from '../../../connection/ports/RepositoryManifestStore.js';
|
|
3
|
+
import type { GitHubRepositoryConnectionOptions } from '../definitions/GitHubRepositoryConnectionOptions.js';
|
|
2
4
|
import type { GitHubRepositoryConnectionResult } from '../definitions/GitHubRepositoryConnectionResult.js';
|
|
5
|
+
import type { GitHubRepositoryGateway } from '../ports/GitHubRepositoryGateway.js';
|
|
6
|
+
interface GitHubRepositoryConnectionDependencies {
|
|
7
|
+
readonly gateway?: GitHubRepositoryGateway;
|
|
8
|
+
readonly snapshotReader?: ProjectSnapshotReader;
|
|
9
|
+
readonly manifestStore?: RepositoryManifestStore;
|
|
10
|
+
}
|
|
3
11
|
/** Connect a standalone app to GitHub and publish its complete snapshot on `main`. */
|
|
4
12
|
export declare function connectGitHubRepositoryAsync(options?: GitHubRepositoryConnectionOptions, dependencies?: GitHubRepositoryConnectionDependencies): Promise<GitHubRepositoryConnectionResult>;
|
|
13
|
+
export {};
|
|
5
14
|
//# sourceMappingURL=connectGitHubRepositoryAsync.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"connectGitHubRepositoryAsync.d.ts","sourceRoot":"","sources":["../../../../src/providers/github/services/connectGitHubRepositoryAsync.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"connectGitHubRepositoryAsync.d.ts","sourceRoot":"","sources":["../../../../src/providers/github/services/connectGitHubRepositoryAsync.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,oDAAoD,CAAC;AAChG,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,sDAAsD,CAAC;AAEpG,OAAO,KAAK,EAAE,iCAAiC,EAAE,MAAM,qDAAqD,CAAC;AAC7G,OAAO,KAAK,EAGV,gCAAgC,EACjC,MAAM,oDAAoD,CAAC;AAC5D,OAAO,KAAK,EAEV,uBAAuB,EAExB,MAAM,qCAAqC,CAAC;AAO7C,UAAU,sCAAsC;IAC9C,QAAQ,CAAC,OAAO,CAAC,EAAE,uBAAuB,CAAC;IAC3C,QAAQ,CAAC,cAAc,CAAC,EAAE,qBAAqB,CAAC;IAChD,QAAQ,CAAC,aAAa,CAAC,EAAE,uBAAuB,CAAC;CAClD;AAED,sFAAsF;AACtF,wBAAsB,4BAA4B,CAChD,OAAO,GAAE,iCAAsC,EAC/C,YAAY,GAAE,sCAA2C,GACxD,OAAO,CAAC,gCAAgC,CAAC,CA+B3C"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"connectGitHubRepositoryAsync.js","sourceRoot":"","sources":["../../../../src/providers/github/services/connectGitHubRepositoryAsync.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gCAAgC,EAAE,MAAM,kEAAkE,CAAC;AACpH,OAAO,EAAE,kCAAkC,EAAE,MAAM,oEAAoE,CAAC;
|
|
1
|
+
{"version":3,"file":"connectGitHubRepositoryAsync.js","sourceRoot":"","sources":["../../../../src/providers/github/services/connectGitHubRepositoryAsync.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gCAAgC,EAAE,MAAM,kEAAkE,CAAC;AACpH,OAAO,EAAE,kCAAkC,EAAE,MAAM,oEAAoE,CAAC;AAIxH,OAAO,EAAE,4BAA4B,EAAE,MAAM,6CAA6C,CAAC;AAY3F,OAAO,EACL,qCAAqC,EACrC,cAAc,GACf,MAAM,4CAA4C,CAAC;AACpD,OAAO,EAAE,iCAAiC,EAAE,MAAM,wCAAwC,CAAC;AAQ3F,sFAAsF;AACtF,MAAM,CAAC,KAAK,UAAU,4BAA4B,CAChD,UAA6C,EAAE,EAC/C,eAAuD,EAAE;IAEzD,MAAM,OAAO,GAAG,YAAY,CAAC,OAAO,IAAI,4BAA4B,EAAE,CAAC;IACvE,MAAM,cAAc,GAAG,YAAY,CAAC,cAAc,IAAI,gCAAgC,EAAE,CAAC;IACzF,MAAM,aAAa,GAAG,YAAY,CAAC,aAAa,IAAI,kCAAkC,EAAE,CAAC;IACzF,IAAI,SAAS,CAAC;IACd,IAAI,CAAC;QACH,SAAS,GAAG,MAAM,qCAAqC,CACrD,OAAO,EACP,OAAO,EACP,cAAc,EACd,aAAa,CACd,CAAC;IACJ,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAA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}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"connectGitHubRepositoryAsync.test.js","sourceRoot":"","sources":["../../../../src/providers/github/services/connectGitHubRepositoryAsync.test.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"connectGitHubRepositoryAsync.test.js","sourceRoot":"","sources":["../../../../src/providers/github/services/connectGitHubRepositoryAsync.test.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,UAAU,CAAC;AAIxC,OAAO,EAAE,4BAA4B,EAAE,MAAM,mCAAmC,CAAC;AAEjF,MAAM,UAAU,GAAuB;IACrC,QAAQ,EAAE,QAAQ;IAClB,KAAK,EAAE,WAAW;IAClB,IAAI,EAAE,WAAW;IACjB,GAAG,EAAE,wCAAwC;IAC7C,aAAa,EAAE,MAAM;CACtB,CAAC;AAEF,MAAM,QAAQ,GAAoB;IAChC,WAAW,EAAE,sBAAsB;IACnC,UAAU;IACV,OAAO,EAAE,EAAE;CACZ,CAAC;AAEF,IAAI,CAAC,8EAA8E,EAAE,KAAK,IAAI,EAAE;IAC9F,MAAM,KAAK,GAAa,EAAE,CAAC;IAE3B,MAAM,MAAM,GAAG,MAAM,4BAA4B,CAC/C,EAAE,WAAW,EAAE,QAAQ,CAAC,WAAW,EAAE,IAAI,EAAE,UAAU,CAAC,IAAI,EAAE,UAAU,EAAE,SAAS,EAAE,EACnF,oCAAoC,CAAC,KAAK,CAAC,CAC5C,CAAC;IAEF,MAAM,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC;QACrB,MAAM,EAAE,mBAAmB;QAC3B,UAAU,EAAE;YACV,KAAK,EAAE,UAAU,CAAC,KAAK;YACvB,IAAI,EAAE,UAAU,CAAC,IAAI;YACrB,GAAG,EAAE,UAAU,CAAC,GAAG;YACnB,aAAa,EAAE,MAAM;SACtB;QACD,YAAY,EAAE,YAAY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AI,KAAK,CAAC,2CAA2C,CAAC,CAAC;QACxE,wBAAwB,EAAE,GAAG,EAAE,CAC7B,OAAO,CAAC,MAAM,CAAC,IAAI,KAAK,CAAC,8CAA8C,CAAC,CAAC;QAC3E,oBAAoB,EAAE,GAAG,EAAE,CACzB,OAAO,CAAC,MAAM,CAAC,IAAI,KAAK,CAAC,8CAA8C,CAAC,CAAC;QAC3E,4BAA4B,EAAE,GAAG,EAAE,CACjC,OAAO,CAAC,MAAM,CAAC,IAAI,KAAK,CAAC,6CAA6C,CAAC,CAAC;QAC1E,qBAAqB,EAAE,GAAG,EAAE;YAC1B,KAAK,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC;YAC1B,OAAO,OAAO,CAAC,OAAO,EAAE,CAAC;QAC3B,CAAC;QACD,oBAAoB,EAAE,GAAG,EAAE;YACzB,KAAK,CAAC,IAAI,CAAC,kBAAkB,CAAC,CAAC;YAC/B,OAAO,OAAO,CAAC,OAAO,EAAE,CAAC;QAC3B,CAAC;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { GitHubRepositoryMaterializationOptions } from '../definitions/GitHubRepositoryMaterializationOptions.js';
|
|
2
|
+
import type { GitHubRepositoryMaterializationResult } from '../definitions/GitHubRepositoryMaterializationResult.js';
|
|
3
|
+
/*** Materialize one GitHub repository URL into an isolated local filesystem snapshot. */
|
|
4
|
+
export declare function materializeGitHubRepositoryAsync(options: GitHubRepositoryMaterializationOptions): Promise<GitHubRepositoryMaterializationResult>;
|
|
5
|
+
//# sourceMappingURL=materializeGitHubRepositoryAsync.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"materializeGitHubRepositoryAsync.d.ts","sourceRoot":"","sources":["../../../../src/providers/github/services/materializeGitHubRepositoryAsync.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,sCAAsC,EAAE,MAAM,0DAA0D,CAAC;AACvH,OAAO,KAAK,EAAE,qCAAqC,EAAE,MAAM,yDAAyD,CAAC;AAGrH,yFAAyF;AACzF,wBAAsB,gCAAgC,CACpD,OAAO,EAAE,sCAAsC,GAC9C,OAAO,CAAC,qCAAqC,CAAC,CAKhD"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { createGitHubHttpRepositoryReadGateway } from '../adapters/createGitHubHttpRepositoryReadGateway.js';
|
|
2
|
+
import { materializeGitHubRepositoryWithGatewayAsync } from './materializeGitHubRepositoryWithGatewayAsync.js';
|
|
3
|
+
/*** Materialize one GitHub repository URL into an isolated local filesystem snapshot. */
|
|
4
|
+
export async function materializeGitHubRepositoryAsync(options) {
|
|
5
|
+
return materializeGitHubRepositoryWithGatewayAsync(options, createGitHubHttpRepositoryReadGateway());
|
|
6
|
+
}
|
|
7
|
+
//# sourceMappingURL=materializeGitHubRepositoryAsync.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"materializeGitHubRepositoryAsync.js","sourceRoot":"","sources":["../../../../src/providers/github/services/materializeGitHubRepositoryAsync.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qCAAqC,EAAE,MAAM,sDAAsD,CAAC;AAG7G,OAAO,EAAE,2CAA2C,EAAE,MAAM,kDAAkD,CAAC;AAE/G,yFAAyF;AACzF,MAAM,CAAC,KAAK,UAAU,gCAAgC,CACpD,OAA+C;IAE/C,OAAO,2CAA2C,CAChD,OAAO,EACP,qCAAqC,EAAE,CACxC,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { GitHubRepositoryMaterializationOptions } from '../definitions/GitHubRepositoryMaterializationOptions.js';
|
|
2
|
+
import type { GitHubRepositoryMaterializationResult } from '../definitions/GitHubRepositoryMaterializationResult.js';
|
|
3
|
+
import type { GitHubRepositoryReadGateway } from '../ports/GitHubRepositoryReadGateway.js';
|
|
4
|
+
/*** Materialize a GitHub repository through an injected read gateway for deterministic testing. */
|
|
5
|
+
export declare function materializeGitHubRepositoryWithGatewayAsync(options: GitHubRepositoryMaterializationOptions, gateway: GitHubRepositoryReadGateway): Promise<GitHubRepositoryMaterializationResult>;
|
|
6
|
+
//# sourceMappingURL=materializeGitHubRepositoryWithGatewayAsync.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"materializeGitHubRepositoryWithGatewayAsync.d.ts","sourceRoot":"","sources":["../../../../src/providers/github/services/materializeGitHubRepositoryWithGatewayAsync.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,sCAAsC,EAAE,MAAM,0DAA0D,CAAC;AACvH,OAAO,KAAK,EAAE,qCAAqC,EAAE,MAAM,yDAAyD,CAAC;AACrH,OAAO,KAAK,EACV,2BAA2B,EAG5B,MAAM,yCAAyC,CAAC;AAEjD,mGAAmG;AACnG,wBAAsB,2CAA2C,CAC/D,OAAO,EAAE,sCAAsC,EAC/C,OAAO,EAAE,2BAA2B,GACnC,OAAO,CAAC,qCAAqC,CAAC,CA2BhD"}
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
import { chmod, mkdir, mkdtemp, rm, writeFile } from 'node:fs/promises';
|
|
2
|
+
import { tmpdir } from 'node:os';
|
|
3
|
+
import { dirname, isAbsolute, join, relative, resolve, sep } from 'node:path';
|
|
4
|
+
/*** Materialize a GitHub repository through an injected read gateway for deterministic testing. */
|
|
5
|
+
export async function materializeGitHubRepositoryWithGatewayAsync(options, gateway) {
|
|
6
|
+
const target = parseGitHubRepositoryUrl(options.url);
|
|
7
|
+
const repository = await gateway.inspectRepositoryAsync(target);
|
|
8
|
+
const ref = normalizeRef(options.ref) ?? repository.defaultBranch;
|
|
9
|
+
const revision = await gateway.resolveRevisionAsync(target, ref);
|
|
10
|
+
const tree = await gateway.readTreeAsync(target, revision.treeSha);
|
|
11
|
+
const files = validateTree(tree.entries, tree.truncated);
|
|
12
|
+
const rootPath = await createMaterializationRootAsync(options.destinationPath);
|
|
13
|
+
try {
|
|
14
|
+
await writeFileBatchesAsync(gateway, target, revision.commitSha, rootPath, files);
|
|
15
|
+
}
|
|
16
|
+
catch (error) {
|
|
17
|
+
await rm(rootPath, { force: true, recursive: true });
|
|
18
|
+
throw error;
|
|
19
|
+
}
|
|
20
|
+
return {
|
|
21
|
+
rootPath,
|
|
22
|
+
revision: revision.commitSha,
|
|
23
|
+
repository: {
|
|
24
|
+
owner: target.owner,
|
|
25
|
+
name: target.name,
|
|
26
|
+
url: repository.url,
|
|
27
|
+
defaultBranch: repository.defaultBranch,
|
|
28
|
+
},
|
|
29
|
+
cleanupAsync: () => rm(rootPath, { force: true, recursive: true }),
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
const MAX_FILE_COUNT = 20_000;
|
|
33
|
+
const MAX_TOTAL_BYTES = 256 * 1024 * 1024;
|
|
34
|
+
const WRITE_BATCH_SIZE = 8;
|
|
35
|
+
/*** Parse the canonical GitHub repository URL accepted by repository materialization. */
|
|
36
|
+
function parseGitHubRepositoryUrl(value) {
|
|
37
|
+
const url = parseRepositoryUrl(value);
|
|
38
|
+
assertGitHubRepositoryUrl(url);
|
|
39
|
+
const segments = url.pathname.split('/').filter(Boolean);
|
|
40
|
+
if (segments.length !== 2) {
|
|
41
|
+
throw new Error('Repository URL must use https://github.com/<owner>/<repository>.');
|
|
42
|
+
}
|
|
43
|
+
const owner = segments[0] ?? '';
|
|
44
|
+
const repositorySegment = segments[1] ?? '';
|
|
45
|
+
const name = repositorySegment.endsWith('.git')
|
|
46
|
+
? repositorySegment.slice(0, -4)
|
|
47
|
+
: repositorySegment;
|
|
48
|
+
assertRepositoryIdentity(owner, name);
|
|
49
|
+
return { owner, name, url: `https://github.com/${owner}/${name}` };
|
|
50
|
+
}
|
|
51
|
+
/*** Parse a repository URL while preserving the original parsing failure as the cause. */
|
|
52
|
+
function parseRepositoryUrl(value) {
|
|
53
|
+
try {
|
|
54
|
+
return new URL(value);
|
|
55
|
+
}
|
|
56
|
+
catch (error) {
|
|
57
|
+
throw new Error('Repository URL must be a valid GitHub HTTPS URL.', { cause: error });
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
/*** Reject non-GitHub origins, credentials, query strings, and fragments. */
|
|
61
|
+
function assertGitHubRepositoryUrl(url) {
|
|
62
|
+
if (url.protocol !== 'https:' ||
|
|
63
|
+
url.hostname.toLowerCase() !== 'github.com' ||
|
|
64
|
+
url.username !== '' ||
|
|
65
|
+
url.password !== '' ||
|
|
66
|
+
url.search !== '' ||
|
|
67
|
+
url.hash !== '') {
|
|
68
|
+
throw new Error('Repository URL must use https://github.com/<owner>/<repository>.');
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
/*** Validate canonical GitHub owner and repository path segments. */
|
|
72
|
+
function assertRepositoryIdentity(owner, name) {
|
|
73
|
+
if (!/^[A-Za-z0-9](?:[A-Za-z0-9-]{0,98}[A-Za-z0-9])?$/u.test(owner)) {
|
|
74
|
+
throw new Error('GitHub repository owner is invalid.');
|
|
75
|
+
}
|
|
76
|
+
if (!/^[A-Za-z0-9._-]{1,100}$/u.test(name) || name === '.' || name === '..') {
|
|
77
|
+
throw new Error('GitHub repository name is invalid.');
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
/*** Normalize an optional requested ref while rejecting an explicitly empty value. */
|
|
81
|
+
function normalizeRef(value) {
|
|
82
|
+
if (value === undefined)
|
|
83
|
+
return undefined;
|
|
84
|
+
const normalized = value.trim();
|
|
85
|
+
if (normalized === '')
|
|
86
|
+
throw new Error('GitHub repository ref must not be empty.');
|
|
87
|
+
return normalized;
|
|
88
|
+
}
|
|
89
|
+
/*** Reject incomplete or unexpectedly large remote trees before downloading source bytes. */
|
|
90
|
+
function validateTree(entries, truncated) {
|
|
91
|
+
if (truncated) {
|
|
92
|
+
throw new Error('GitHub repository tree is truncated and cannot be materialized safely.');
|
|
93
|
+
}
|
|
94
|
+
const files = entries.filter((entry) => entry.type === 'blob');
|
|
95
|
+
if (files.length > MAX_FILE_COUNT) {
|
|
96
|
+
throw new Error(`GitHub repository exceeds the ${MAX_FILE_COUNT} file materialization limit.`);
|
|
97
|
+
}
|
|
98
|
+
if (files.some((entry) => entry.mode === '120000')) {
|
|
99
|
+
throw new Error('GitHub repository symbolic links are not supported by safe materialization.');
|
|
100
|
+
}
|
|
101
|
+
const totalBytes = files.reduce((sum, entry) => {
|
|
102
|
+
if (entry.size === undefined) {
|
|
103
|
+
throw new Error(`GitHub repository file size is missing for ${entry.path}.`);
|
|
104
|
+
}
|
|
105
|
+
return sum + entry.size;
|
|
106
|
+
}, 0);
|
|
107
|
+
if (totalBytes > MAX_TOTAL_BYTES) {
|
|
108
|
+
throw new Error('GitHub repository exceeds the 256 MiB materialization limit.');
|
|
109
|
+
}
|
|
110
|
+
return files;
|
|
111
|
+
}
|
|
112
|
+
/*** Create either an isolated temporary root or one explicitly requested empty destination. */
|
|
113
|
+
async function createMaterializationRootAsync(destinationPath) {
|
|
114
|
+
if (destinationPath === undefined) {
|
|
115
|
+
return mkdtemp(join(tmpdir(), 'ankhorage-repository-'));
|
|
116
|
+
}
|
|
117
|
+
const rootPath = resolve(destinationPath);
|
|
118
|
+
await mkdir(dirname(rootPath), { recursive: true });
|
|
119
|
+
await mkdir(rootPath);
|
|
120
|
+
return rootPath;
|
|
121
|
+
}
|
|
122
|
+
/*** Download and write bounded groups so large repositories do not fan out unbounded requests. */
|
|
123
|
+
async function writeFileBatchesAsync(gateway, target, revision, rootPath, entries) {
|
|
124
|
+
const batches = Array.from({ length: Math.ceil(entries.length / WRITE_BATCH_SIZE) }, (_, index) => entries.slice(index * WRITE_BATCH_SIZE, (index + 1) * WRITE_BATCH_SIZE));
|
|
125
|
+
for (const batch of batches) {
|
|
126
|
+
await Promise.all(batch.map((entry) => materializeFileAsync(gateway, target, revision, rootPath, entry)));
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
/*** Materialize one ordinary Git blob beneath the isolated root and preserve executable mode. */
|
|
130
|
+
async function materializeFileAsync(gateway, target, revision, rootPath, entry) {
|
|
131
|
+
const destination = resolveMaterializationPath(rootPath, entry.path);
|
|
132
|
+
const content = await gateway.readFileAsync(target, revision, entry.path);
|
|
133
|
+
if (entry.size !== content.byteLength) {
|
|
134
|
+
throw new Error(`GitHub repository file size changed while reading ${entry.path}.`);
|
|
135
|
+
}
|
|
136
|
+
await mkdir(dirname(destination), { recursive: true });
|
|
137
|
+
await writeFile(destination, content);
|
|
138
|
+
if (entry.mode === '100755')
|
|
139
|
+
await chmod(destination, 0o755);
|
|
140
|
+
}
|
|
141
|
+
/*** Resolve one provider path while rejecting traversal outside the materialization root. */
|
|
142
|
+
function resolveMaterializationPath(rootPath, repositoryPath) {
|
|
143
|
+
if (repositoryPath.trim() === '' ||
|
|
144
|
+
repositoryPath.includes('\\') ||
|
|
145
|
+
repositoryPath.startsWith('/') ||
|
|
146
|
+
repositoryPath.split('/').some((segment) => segment === '..' || segment === '')) {
|
|
147
|
+
throw new Error(`Unsafe GitHub repository path: ${repositoryPath}.`);
|
|
148
|
+
}
|
|
149
|
+
const destination = resolve(rootPath, ...repositoryPath.split('/'));
|
|
150
|
+
const child = relative(rootPath, destination);
|
|
151
|
+
if (child === '' || child === '..' || child.startsWith(`..${sep}`) || isAbsolute(child)) {
|
|
152
|
+
throw new Error(`Unsafe GitHub repository path: ${repositoryPath}.`);
|
|
153
|
+
}
|
|
154
|
+
return destination;
|
|
155
|
+
}
|
|
156
|
+
//# sourceMappingURL=materializeGitHubRepositoryWithGatewayAsync.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"materializeGitHubRepositoryWithGatewayAsync.js","sourceRoot":"","sources":["../../../../src/providers/github/services/materializeGitHubRepositoryWithGatewayAsync.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,OAAO,EAAE,EAAE,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AACxE,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AACjC,OAAO,EAAE,O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}
|
package/dist/providers/github/services/materializeGitHubRepositoryWithGatewayAsync.test.d.ts.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"materializeGitHubRepositoryWithGatewayAsync.test.d.ts","sourceRoot":"","sources":["../../../../src/providers/github/services/materializeGitHubRepositoryWithGatewayAsync.test.ts"],"names":[],"mappings":""}
|