@commitspark/git-adapter-github 0.20.0 → 0.30.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 +17 -0
- package/README.md +39 -0
- package/dist/cjs/errors.js +58 -0
- package/dist/cjs/errors.js.map +1 -0
- package/dist/cjs/github-adapter.js +86 -71
- package/dist/cjs/github-adapter.js.map +1 -1
- package/dist/cjs/github-api/get-entry-content.js +53 -0
- package/dist/cjs/github-api/get-entry-content.js.map +1 -0
- package/dist/cjs/github-api/get-file-paths.js +48 -0
- package/dist/cjs/github-api/get-file-paths.js.map +1 -0
- package/dist/cjs/{util → github-api}/graphql-query-factory.js +32 -23
- package/dist/cjs/github-api/graphql-query-factory.js.map +1 -0
- package/dist/cjs/types.js +10 -0
- package/dist/cjs/types.js.map +1 -0
- package/dist/cjs/util/entries-to-actions-converter.js +1 -1
- package/dist/cjs/util/entries-to-actions-converter.js.map +1 -1
- package/dist/cjs/util/entry-factory.js +10 -9
- package/dist/cjs/util/entry-factory.js.map +1 -1
- package/dist/cjs/util/path-factory.js +3 -3
- package/dist/cjs/util/path-factory.js.map +1 -1
- package/dist/esm/errors.js +51 -0
- package/dist/esm/errors.js.map +1 -0
- package/dist/esm/github-adapter.js +86 -70
- package/dist/esm/github-adapter.js.map +1 -1
- package/dist/esm/github-api/get-entry-content.js +40 -0
- package/dist/esm/github-api/get-entry-content.js.map +1 -0
- package/dist/esm/github-api/get-file-paths.js +35 -0
- package/dist/esm/github-api/get-file-paths.js.map +1 -0
- package/dist/esm/{util → github-api}/graphql-query-factory.js +30 -21
- package/dist/esm/github-api/graphql-query-factory.js.map +1 -0
- package/dist/esm/types.js +7 -0
- package/dist/esm/types.js.map +1 -0
- package/dist/esm/util/entries-to-actions-converter.js +1 -1
- package/dist/esm/util/entries-to-actions-converter.js.map +1 -1
- package/dist/esm/util/entry-factory.js +9 -8
- package/dist/esm/util/entry-factory.js.map +1 -1
- package/dist/esm/util/path-factory.js +3 -3
- package/dist/esm/util/path-factory.js.map +1 -1
- package/dist/tsconfig.build.cjs.tsbuildinfo +1 -1
- package/dist/tsconfig.build.esm.tsbuildinfo +1 -1
- package/dist/tsconfig.build.types.tsbuildinfo +1 -1
- package/dist/types/errors.d.ts +4 -0
- package/dist/types/errors.d.ts.map +1 -0
- package/dist/types/github-adapter.d.ts +0 -1
- package/dist/types/github-adapter.d.ts.map +1 -1
- package/dist/types/github-api/get-entry-content.d.ts +4 -0
- package/dist/types/github-api/get-entry-content.d.ts.map +1 -0
- package/dist/types/github-api/get-file-paths.d.ts +4 -0
- package/dist/types/github-api/get-file-paths.d.ts.map +1 -0
- package/dist/types/github-api/graphql-query-factory.d.ts +8 -0
- package/dist/types/github-api/graphql-query-factory.d.ts.map +1 -0
- package/dist/types/types.d.ts +7 -0
- package/dist/types/types.d.ts.map +1 -0
- package/dist/types/util/entry-factory.d.ts +2 -9
- package/dist/types/util/entry-factory.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/errors.ts +54 -0
- package/src/github-adapter.ts +128 -86
- package/src/github-api/get-entry-content.ts +76 -0
- package/src/github-api/get-file-paths.ts +66 -0
- package/src/{util → github-api}/graphql-query-factory.ts +42 -21
- package/src/types.ts +6 -0
- package/src/util/entries-to-actions-converter.ts +1 -1
- package/src/util/entry-factory.ts +13 -22
- package/src/util/path-factory.ts +3 -3
- package/dist/cjs/util/graphql-query-factory.js.map +0 -1
- package/dist/cjs/util/types.js +0 -7
- package/dist/cjs/util/types.js.map +0 -1
- package/dist/esm/util/graphql-query-factory.js.map +0 -1
- package/dist/esm/util/types.js +0 -4
- package/dist/esm/util/types.js.map +0 -1
- package/dist/types/util/graphql-query-factory.d.ts +0 -5
- package/dist/types/util/graphql-query-factory.d.ts.map +0 -1
- package/dist/types/util/types.d.ts +0 -4
- package/dist/types/util/types.d.ts.map +0 -1
- package/src/util/types.ts +0 -3
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getPathSchema = getPathSchema;
|
|
4
4
|
exports.getPathEntryFolder = getPathEntryFolder;
|
|
5
|
-
const types_1 = require("
|
|
5
|
+
const types_1 = require("../types");
|
|
6
6
|
function getPathSchema(gitRepositoryOptions) {
|
|
7
7
|
var _a;
|
|
8
8
|
return (_a = gitRepositoryOptions.pathSchemaFile) !== null && _a !== void 0 ? _a : types_1.PATH_SCHEMA_FILE;
|
|
@@ -10,8 +10,8 @@ function getPathSchema(gitRepositoryOptions) {
|
|
|
10
10
|
function getPathEntryFolder(gitRepositoryOptions) {
|
|
11
11
|
var _a;
|
|
12
12
|
const pathEntryFolder = (_a = gitRepositoryOptions.pathEntryFolder) !== null && _a !== void 0 ? _a : types_1.PATH_ENTRY_FOLDER;
|
|
13
|
-
if (pathEntryFolder.endsWith('/')) {
|
|
14
|
-
return pathEntryFolder
|
|
13
|
+
if (!pathEntryFolder.endsWith('/')) {
|
|
14
|
+
return pathEntryFolder + '/';
|
|
15
15
|
}
|
|
16
16
|
return pathEntryFolder;
|
|
17
17
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"path-factory.js","sourceRoot":"","sources":["../../../src/util/path-factory.ts"],"names":[],"mappings":";;AAGA,sCAEC;AAED,gDAWC;AAjBD,
|
|
1
|
+
{"version":3,"file":"path-factory.js","sourceRoot":"","sources":["../../../src/util/path-factory.ts"],"names":[],"mappings":";;AAGA,sCAEC;AAED,gDAWC;AAjBD,oCAA8D;AAE9D,SAAgB,aAAa,CAAC,oBAA6C;;IACzE,OAAO,MAAA,oBAAoB,CAAC,cAAc,mCAAI,wBAAgB,CAAA;AAChE,CAAC;AAED,SAAgB,kBAAkB,CAChC,oBAA6C;;IAE7C,MAAM,eAAe,GACnB,MAAA,oBAAoB,CAAC,eAAe,mCAAI,yBAAiB,CAAA;IAE3D,IAAI,CAAC,eAAe,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC;QACnC,OAAO,eAAe,GAAG,GAAG,CAAA;IAC9B,CAAC;IAED,OAAO,eAAe,CAAA;AACxB,CAAC"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { ErrorCode, GitAdapterError } from '@commitspark/git-adapter';
|
|
2
|
+
import { AxiosError } from 'axios';
|
|
3
|
+
export const handleHttpErrors = (error) => {
|
|
4
|
+
if (error instanceof AxiosError) {
|
|
5
|
+
const status = error.response?.status;
|
|
6
|
+
const message = error.response?.data?.message || error.message;
|
|
7
|
+
switch (status) {
|
|
8
|
+
case 400:
|
|
9
|
+
throw new GitAdapterError(ErrorCode.BAD_REQUEST, message);
|
|
10
|
+
case 401:
|
|
11
|
+
throw new GitAdapterError(ErrorCode.UNAUTHORIZED, message);
|
|
12
|
+
case 403:
|
|
13
|
+
throw new GitAdapterError(ErrorCode.FORBIDDEN, message);
|
|
14
|
+
case 404:
|
|
15
|
+
throw new GitAdapterError(ErrorCode.NOT_FOUND, message);
|
|
16
|
+
case 409:
|
|
17
|
+
throw new GitAdapterError(ErrorCode.CONFLICT, message);
|
|
18
|
+
case 429:
|
|
19
|
+
throw new GitAdapterError(ErrorCode.TOO_MANY_REQUESTS, message);
|
|
20
|
+
default:
|
|
21
|
+
throw new GitAdapterError(ErrorCode.INTERNAL_ERROR, message);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
throw new GitAdapterError(ErrorCode.INTERNAL_ERROR, error instanceof Error ? error.message : 'Unknown error');
|
|
25
|
+
};
|
|
26
|
+
export const handleGraphQLErrors = (response) => {
|
|
27
|
+
if (response.data.errors) {
|
|
28
|
+
const errors = response.data.errors;
|
|
29
|
+
const errorMessage = JSON.stringify(errors);
|
|
30
|
+
const errorType = errors[0]?.type;
|
|
31
|
+
// GitHub error types are not documented, and documentation is not planned,
|
|
32
|
+
// see https://github.com/github/docs/issues/22607
|
|
33
|
+
// Error type values below have been discovered through manual testing
|
|
34
|
+
if (errorType === 'NOT_FOUND') {
|
|
35
|
+
throw new GitAdapterError(ErrorCode.NOT_FOUND, errorMessage);
|
|
36
|
+
}
|
|
37
|
+
else if (errorType === 'RATE_LIMITED') {
|
|
38
|
+
throw new GitAdapterError(ErrorCode.TOO_MANY_REQUESTS, errorMessage);
|
|
39
|
+
}
|
|
40
|
+
else if (errorType === 'FORBIDDEN') {
|
|
41
|
+
throw new GitAdapterError(ErrorCode.FORBIDDEN, errorMessage);
|
|
42
|
+
}
|
|
43
|
+
else if (errorType === 'STALE_DATA') {
|
|
44
|
+
throw new GitAdapterError(ErrorCode.CONFLICT, errorMessage);
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
throw new GitAdapterError(ErrorCode.INTERNAL_ERROR, errorMessage);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/errors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAA;AACrE,OAAO,EAAE,UAAU,EAAiB,MAAM,OAAO,CAAA;AAEjD,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,KAAc,EAAS,EAAE;IACxD,IAAI,KAAK,YAAY,UAAU,EAAE,CAAC;QAChC,MAAM,MAAM,GAAG,KAAK,CAAC,QAAQ,EAAE,MAAM,CAAA;QACrC,MAAM,OAAO,GAAG,KAAK,CAAC,QAAQ,EAAE,IAAI,EAAE,OAAO,IAAI,KAAK,CAAC,OAAO,CAAA;QAE9D,QAAQ,MAAM,EAAE,CAAC;YACf,KAAK,GAAG;gBACN,MAAM,IAAI,eAAe,CAAC,SAAS,CAAC,WAAW,EAAE,OAAO,CAAC,CAAA;YAC3D,KAAK,GAAG;gBACN,MAAM,IAAI,eAAe,CAAC,SAAS,CAAC,YAAY,EAAE,OAAO,CAAC,CAAA;YAC5D,KAAK,GAAG;gBACN,MAAM,IAAI,eAAe,C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AE,CAAC;YACrC,MAAM,IAAI,eAAe,CAAC,SAAS,CAAC,SAAS,EAAE,YAAY,CAAC,CAAA;QAC9D,CAAC;aAAM,IAAI,SAAS,KAAK,YAAY,EAAE,CAAC;YACtC,MAAM,IAAI,eAAe,CAAC,SAAS,CAAC,QAAQ,EAAE,YAAY,CAAC,CAAA;QAC7D,CAAC;aAAM,CAAC;YACN,MAAM,IAAI,eAAe,CAAC,SAAS,CAAC,cAAc,EAAE,YAAY,CAAC,CAAA;QACnE,CAAC;IACH,CAAC;AACH,CAAC,CAAA"}
|
|
@@ -1,77 +1,85 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ErrorCode, GitAdapterError, } from '@commitspark/git-adapter';
|
|
2
|
+
import { createSingleBlobContentQuery, createCommitMutation, createLatestCommitQuery, } from './github-api/graphql-query-factory';
|
|
2
3
|
import { convertEntriesToActions } from './util/entries-to-actions-converter';
|
|
3
4
|
import { getPathEntryFolder, getPathSchema } from './util/path-factory';
|
|
4
|
-
import {
|
|
5
|
-
|
|
5
|
+
import { createEntriesFromFileContent } from './util/entry-factory';
|
|
6
|
+
import { handleGraphQLErrors, handleHttpErrors } from './errors';
|
|
7
|
+
import { getEntryContent } from './github-api/get-entry-content';
|
|
8
|
+
import { getFilePaths } from './github-api/get-file-paths';
|
|
9
|
+
import { GITHUB_GRAPHQL_API_URL } from './types';
|
|
6
10
|
export const getEntries = async (gitRepositoryOptions, axiosCacheInstance, commitHash) => {
|
|
7
|
-
const
|
|
8
|
-
const
|
|
9
|
-
|
|
10
|
-
const filesContentResponse = await axiosCacheInstance.post(API_URL, {
|
|
11
|
-
query: queryFilesContent,
|
|
12
|
-
variables: {
|
|
13
|
-
repositoryOwner: gitRepositoryOptions.repositoryOwner,
|
|
14
|
-
repositoryName: gitRepositoryOptions.repositoryName,
|
|
15
|
-
expression: `${commitHash}:${pathEntryFolder}`,
|
|
16
|
-
},
|
|
17
|
-
}, {
|
|
18
|
-
headers: {
|
|
19
|
-
authorization: `Bearer ${token}`,
|
|
20
|
-
},
|
|
21
|
-
});
|
|
22
|
-
if (!filesContentResponse.data.data.repository?.object?.entries) {
|
|
23
|
-
return [];
|
|
24
|
-
}
|
|
25
|
-
return createEntriesFromBlobsQueryResponseData(filesContentResponse.data.data.repository.object.entries);
|
|
11
|
+
const filenames = await getFilePaths(gitRepositoryOptions, axiosCacheInstance, commitHash);
|
|
12
|
+
const filePathsContentMap = await getEntryContent(gitRepositoryOptions, axiosCacheInstance, commitHash, filenames);
|
|
13
|
+
return createEntriesFromFileContent(gitRepositoryOptions, filePathsContentMap);
|
|
26
14
|
};
|
|
27
15
|
export const getSchema = async (gitRepositoryOptions, axiosCacheInstance, commitHash) => {
|
|
28
16
|
const repositoryOwner = gitRepositoryOptions.repositoryOwner;
|
|
29
17
|
const repositoryName = gitRepositoryOptions.repositoryName;
|
|
30
18
|
const token = gitRepositoryOptions.accessToken;
|
|
31
19
|
const schemaFilePath = getPathSchema(gitRepositoryOptions);
|
|
32
|
-
const queryContent =
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
20
|
+
const queryContent = createSingleBlobContentQuery();
|
|
21
|
+
let response;
|
|
22
|
+
try {
|
|
23
|
+
response = await axiosCacheInstance.post(GITHUB_GRAPHQL_API_URL, {
|
|
24
|
+
query: queryContent,
|
|
25
|
+
variables: {
|
|
26
|
+
repositoryOwner: repositoryOwner,
|
|
27
|
+
repositoryName: repositoryName,
|
|
28
|
+
expression: `${commitHash}:${schemaFilePath}`,
|
|
29
|
+
},
|
|
30
|
+
}, {
|
|
31
|
+
headers: {
|
|
32
|
+
authorization: `Bearer ${token}`,
|
|
33
|
+
},
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
catch (error) {
|
|
37
|
+
handleHttpErrors(error);
|
|
38
|
+
}
|
|
39
|
+
if (!response) {
|
|
40
|
+
throw new GitAdapterError(ErrorCode.INTERNAL_ERROR, `Failed to fetch schema`);
|
|
41
|
+
}
|
|
42
|
+
handleGraphQLErrors(response);
|
|
45
43
|
const schema = response.data?.data?.repository?.object?.text;
|
|
46
44
|
if (!schema) {
|
|
47
|
-
throw new
|
|
45
|
+
throw new GitAdapterError(ErrorCode.NOT_FOUND, `"${schemaFilePath}" not found in Git repository "${repositoryOwner}/${repositoryName}" at commit "${commitHash}"`);
|
|
48
46
|
}
|
|
49
47
|
return schema;
|
|
50
48
|
};
|
|
51
49
|
export const getLatestCommitHash = async (gitRepositoryOptions, axiosCacheInstance, ref) => {
|
|
52
50
|
const token = gitRepositoryOptions.accessToken;
|
|
53
51
|
const queryLatestCommit = createLatestCommitQuery();
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
52
|
+
let response;
|
|
53
|
+
try {
|
|
54
|
+
response = await axiosCacheInstance.post(GITHUB_GRAPHQL_API_URL, {
|
|
55
|
+
query: queryLatestCommit,
|
|
56
|
+
variables: {
|
|
57
|
+
repositoryOwner: gitRepositoryOptions.repositoryOwner,
|
|
58
|
+
repositoryName: gitRepositoryOptions.repositoryName,
|
|
59
|
+
ref: ref,
|
|
60
|
+
},
|
|
61
|
+
}, {
|
|
62
|
+
cache: false, // must not use cache, so we always get the branch's current head
|
|
63
|
+
headers: {
|
|
64
|
+
authorization: `Bearer ${token}`,
|
|
65
|
+
},
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
catch (error) {
|
|
69
|
+
handleHttpErrors(error);
|
|
70
|
+
}
|
|
71
|
+
if (!response) {
|
|
72
|
+
throw new GitAdapterError(ErrorCode.INTERNAL_ERROR, 'Failed to fetch latest commit');
|
|
73
|
+
}
|
|
74
|
+
handleGraphQLErrors(response);
|
|
67
75
|
if (!response.data.data.repository) {
|
|
68
|
-
throw new
|
|
76
|
+
throw new GitAdapterError(ErrorCode.NOT_FOUND, `No repository found "${gitRepositoryOptions.repositoryOwner}/${gitRepositoryOptions.repositoryName}"`);
|
|
69
77
|
}
|
|
70
78
|
const lastCommit = response.data.data.repository.ref?.target?.oid ??
|
|
71
79
|
response.data.data.repository.object?.oid ??
|
|
72
80
|
undefined;
|
|
73
81
|
if (!lastCommit) {
|
|
74
|
-
throw new
|
|
82
|
+
throw new GitAdapterError(ErrorCode.NOT_FOUND, `No commit found for ref "${ref}"`);
|
|
75
83
|
}
|
|
76
84
|
return lastCommit;
|
|
77
85
|
};
|
|
@@ -80,28 +88,36 @@ export const createCommit = async (gitRepositoryOptions, axiosCacheInstance, com
|
|
|
80
88
|
const pathEntryFolder = getPathEntryFolder(gitRepositoryOptions);
|
|
81
89
|
const { additions, deletions } = convertEntriesToActions(commitDraft.entries, pathEntryFolder);
|
|
82
90
|
const mutateCommit = createCommitMutation();
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
91
|
+
let response;
|
|
92
|
+
try {
|
|
93
|
+
response = await axiosCacheInstance.post(GITHUB_GRAPHQL_API_URL, {
|
|
94
|
+
query: mutateCommit,
|
|
95
|
+
variables: {
|
|
96
|
+
repositoryNameWithOwner: `${gitRepositoryOptions.repositoryOwner}/${gitRepositoryOptions.repositoryName}`,
|
|
97
|
+
branchName: commitDraft.ref,
|
|
98
|
+
commitMessage: commitDraft.message ?? '-',
|
|
99
|
+
precedingCommitSha: commitDraft.parentSha,
|
|
100
|
+
additions: additions,
|
|
101
|
+
deletions: deletions,
|
|
102
|
+
},
|
|
103
|
+
}, {
|
|
104
|
+
cache: false,
|
|
105
|
+
headers: {
|
|
106
|
+
authorization: `Bearer ${token}`,
|
|
107
|
+
},
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
catch (error) {
|
|
111
|
+
handleHttpErrors(error);
|
|
112
|
+
}
|
|
113
|
+
if (!response) {
|
|
114
|
+
throw new GitAdapterError(ErrorCode.INTERNAL_ERROR, `Failed to create commit`);
|
|
101
115
|
}
|
|
116
|
+
handleGraphQLErrors(response);
|
|
102
117
|
const mutationResult = response.data.data.commitCreate;
|
|
103
118
|
if (mutationResult.errors) {
|
|
104
|
-
|
|
119
|
+
const errorMessage = JSON.stringify(mutationResult.errors);
|
|
120
|
+
throw new GitAdapterError(ErrorCode.BAD_REQUEST, `Failed to create commit: ${errorMessage}`);
|
|
105
121
|
}
|
|
106
122
|
return { ref: mutationResult.commit.oid };
|
|
107
123
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"github-adapter.js","sourceRoot":"","sources":["../../src/github-adapter.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"github-adapter.js","sourceRoot":"","sources":["../../src/github-adapter.ts"],"names":[],"mappings":"AACA,OAAO,EAIL,SAAS,EACT,eAAe,GAChB,MAAM,0BAA0B,CAAA;AAEjC,OAAO,EACL,4BAA4B,EAC5B,oBAAoB,EACpB,uBAAuB,GACxB,MAAM,oCAAoC,CAAA;AAC3C,OAAO,EAAE,uBAAuB,EAAE,MAAM,qCAAqC,CAAA;AAC7E,OAAO,EAAE,kBAAkB,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAA;AACvE,OAAO,EAAE,4BAA4B,EAAE,MAAM,sBAAsB,CAAA;AACnE,OAAO,EAAE,mBAAmB,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAA;AAChE,OAAO,EAAE,eAAe,EAAE,MAAM,gCAAgC,CAAA;AAChE,OAAO,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAA;AAC1D,OAAO,EAAE,sBAAs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Aa,EAAE,WAAW,CAAC,OAAO,IAAI,GAAG;gBACzC,kBAAkB,EAAE,WAAW,CAAC,SAAS;gBACzC,SAAS,EAAE,SAAS;gBACpB,SAAS,EAAE,SAAS;aACrB;SACF,EACD;YACE,KAAK,EAAE,KAAK;YACZ,OAAO,EAAE;gBACP,aAAa,EAAE,UAAU,KAAK,EAAE;aACjC;SACF,CACF,CAAA;IACH,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,gBAAgB,CAAC,KAAK,CAAC,CAAA;IACzB,CAAC;IAED,IAAI,CAAC,QAAQ,EAAE,CAAC;QACd,MAAM,IAAI,eAAe,CACvB,SAAS,CAAC,cAAc,EACxB,yBAAyB,CAC1B,CAAA;IACH,CAAC;IAED,mBAAmB,CAAC,QAAQ,CAAC,CAAA;IAE7B,MAAM,cAAc,GAAG,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,YAAY,CAAA;IAEtD,IAAI,cAAc,CAAC,MAAM,EAAE,CAAC;QAC1B,MAAM,YAAY,GAAG,IAAI,CAAC,SAAS,CAAC,cAAc,CAAC,MAAM,CAAC,CAAA;QAC1D,MAAM,IAAI,eAAe,CACvB,SAAS,CAAC,WAAW,EACrB,4BAA4B,YAAY,EAAE,CAC3C,CAAA;IACH,CAAC;IAED,OAAO,EAAE,GAAG,EAAE,cAAc,CAAC,MAAM,CAAC,GAAG,EAAE,CAAA;AAC3C,CAAC,CAAA"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { createBlobsContentByFilePathsQuery } from './graphql-query-factory';
|
|
2
|
+
import { GITHUB_GRAPHQL_API_URL, QUERY_BATCH_SIZE } from '../types';
|
|
3
|
+
import { handleGraphQLErrors, handleHttpErrors } from '../errors';
|
|
4
|
+
export const getEntryContent = async (gitRepositoryOptions, axiosCacheInstance, commitHash, filePaths) => {
|
|
5
|
+
const filePathsContentMap = new Map();
|
|
6
|
+
const { queries, queryFilenameAliasMap } = createBlobsContentByFilePathsQuery(filePaths, commitHash, QUERY_BATCH_SIZE);
|
|
7
|
+
const requestPromises = [];
|
|
8
|
+
for (const contentQuery of queries) {
|
|
9
|
+
try {
|
|
10
|
+
requestPromises.push(axiosCacheInstance
|
|
11
|
+
.post(GITHUB_GRAPHQL_API_URL, {
|
|
12
|
+
query: contentQuery,
|
|
13
|
+
variables: {
|
|
14
|
+
repositoryOwner: gitRepositoryOptions.repositoryOwner,
|
|
15
|
+
repositoryName: gitRepositoryOptions.repositoryName,
|
|
16
|
+
},
|
|
17
|
+
}, {
|
|
18
|
+
headers: {
|
|
19
|
+
authorization: `Bearer ${gitRepositoryOptions.accessToken}`,
|
|
20
|
+
},
|
|
21
|
+
timeout: 30000,
|
|
22
|
+
})
|
|
23
|
+
.then((contentResponse) => processContentResponse(filePathsContentMap, queryFilenameAliasMap, contentResponse)));
|
|
24
|
+
}
|
|
25
|
+
catch (error) {
|
|
26
|
+
handleHttpErrors(error);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
await Promise.all(requestPromises);
|
|
30
|
+
return filePathsContentMap;
|
|
31
|
+
};
|
|
32
|
+
const processContentResponse = (filePathsContentMap, queryFilenameAliasMap, contentResponse) => {
|
|
33
|
+
handleGraphQLErrors(contentResponse);
|
|
34
|
+
const filesResponseData = contentResponse.data.data.repository;
|
|
35
|
+
for (const [queryAlias, fileObject] of Object.entries(filesResponseData)) {
|
|
36
|
+
filePathsContentMap.set(queryFilenameAliasMap.get(queryAlias), // we assume we received only those files we know about
|
|
37
|
+
fileObject.text);
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
//# sourceMappingURL=get-entry-content.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-entry-content.js","sourceRoot":"","sources":["../../../src/github-api/get-entry-content.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,kCAAkC,EAAE,MAAM,yBAAyB,CAAA;AAC5E,OAAO,EAAE,sBAAsB,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAA;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C,IAAI,CAAC,IAAI,CAAC,UAGnD,CAAA;IAED,KAAK,MAAM,CAAC,UAAU,EAAE,UAAU,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,iBAAiB,CAAC,EAAE,CAAC;QACzE,mBAAmB,CAAC,GAAG,CACrB,qBAAqB,CAAC,GAAG,CAAC,UAAU,CAAW,EAAE,uDAAuD;QACxG,UAAU,CAAC,IAAI,CAChB,CAAA;IACH,CAAC;AACH,CAAC,CAAA"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { ErrorCode, GitAdapterError } from '@commitspark/git-adapter';
|
|
2
|
+
import { getPathEntryFolder } from '../util/path-factory';
|
|
3
|
+
import { handleHttpErrors } from '../errors';
|
|
4
|
+
import { GITHUB_REST_API_URL } from '../types';
|
|
5
|
+
export const getFilePaths = async (gitRepositoryOptions, axiosCacheInstance, treeSha) => {
|
|
6
|
+
const pathEntryFolder = getPathEntryFolder(gitRepositoryOptions);
|
|
7
|
+
const { repositoryOwner, repositoryName, accessToken } = gitRepositoryOptions;
|
|
8
|
+
// hard limit of 100,000 entries and 7MB response size; see https://docs.github.com/en/rest/git/trees?apiVersion=2022-11-28#get-a-tree
|
|
9
|
+
const restApiUrl = GITHUB_REST_API_URL +
|
|
10
|
+
`/repos/${repositoryOwner}/${repositoryName}/git/trees/${treeSha}?recursive=1`;
|
|
11
|
+
let response;
|
|
12
|
+
try {
|
|
13
|
+
response = await axiosCacheInstance.get(restApiUrl, {
|
|
14
|
+
headers: {
|
|
15
|
+
Authorization: `Bearer ${accessToken}`,
|
|
16
|
+
Accept: 'application/vnd.github+json',
|
|
17
|
+
},
|
|
18
|
+
timeout: 30000,
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
catch (error) {
|
|
22
|
+
handleHttpErrors(error);
|
|
23
|
+
}
|
|
24
|
+
if (response === undefined) {
|
|
25
|
+
throw new GitAdapterError(ErrorCode.INTERNAL_ERROR, 'Failed to fetch repository file list.');
|
|
26
|
+
}
|
|
27
|
+
const data = response.data;
|
|
28
|
+
if (data.truncated) {
|
|
29
|
+
throw new GitAdapterError(ErrorCode.INTERNAL_ERROR, `Too many files in repository.`);
|
|
30
|
+
}
|
|
31
|
+
return data.tree
|
|
32
|
+
.filter((entry) => entry.type === 'blob' && entry.path.startsWith(pathEntryFolder))
|
|
33
|
+
.map((entry) => entry.path);
|
|
34
|
+
};
|
|
35
|
+
//# sourceMappingURL=get-file-paths.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-file-paths.js","sourceRoot":"","sources":["../../../src/github-api/get-file-paths.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAA;AACrE,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAA;AACzD,OAAO,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAA;AAC5C,OAAO,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAA;AAE9C,MAAM,CAAC,MAAM,YAAY,GAAG,KAAK,EAC/B,oBAA6C,EAC7C,kBAAsC,EACtC,OAAe,EACI,EAAE;IACrB,MAAM,eAAe,GAAG,kBAAkB,CAAC,oBAAoB,CAAC,CAAA;IAChE,MAAM,EAAE,eAAe,EAAE,cAAc,EAAE,WAAW,EAAE,GAAG,oBAAoB,CAAA;IAE7E,sIAAsI;IACtI,MAAM,UAAU,GACd,mBAAmB;QACnB,UAAU,eAAe,IAAI,cAAc,cAAc,OAAO,cAAc,CAAA;IAEhF,IAAI,QAAQ,CAAA;IACZ,IAAI,CAAC;QACH,QAAQ,GAAG,MAAM,kBAAkB,CAAC,GAAG,CAAC,UAAU,EAAE;YAClD,OAAO,EAAE;gBACP,aAAa,EAAE,UAAU,WAAW,EAAE;gBACtC,MAAM,EAAE,6BAA6B;aACtC;YACD,OAAO,EAAE,KAAK;SACf,CAAC,CAAA;IACJ,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,gBAAgB,CAAC,KAAK,CAAC,CAAA;IACzB,CAAC;IAED,IAAI,QAAQ,KAAK,SAAS,EAAE,CAAC;QAC3B,MAAM,IAAI,eAAe,CACvB,SAAS,CAAC,cAAc,EACxB,uCAAuC,CACxC,CAAA;IACH,CAAC;IAED,MAAM,IAAI,GAAG,QAAQ,CAAC,IAA0B,CAAA;IAEhD,IAAI,IAAI,CAAC,SAAS,EAAE,CAAC;QACnB,MAAM,IAAI,eAAe,CACvB,SAAS,CAAC,cAAc,EACxB,+BAA+B,CAChC,CAAA;IACH,CAAC;IAED,OAAO,IAAI,CAAC,IAAI;SACb,MAAM,CACL,CAAC,KAAK,EAAE,EAAE,CACR,KAAK,CAAC,IAAI,KAAK,MAAM,IAAI,KAAK,CAAC,IAAI,CAAC,UAAU,CAAC,eAAe,CAAC,CAClE;SACA,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,CAAA;AAC/B,CAAC,CAAA"}
|
|
@@ -1,36 +1,45 @@
|
|
|
1
|
-
export function
|
|
1
|
+
export function createSingleBlobContentQuery() {
|
|
2
2
|
return `
|
|
3
3
|
query ($repositoryOwner: String!, $repositoryName: String!, $expression: String!) {
|
|
4
4
|
repository(owner: $repositoryOwner, name: $repositoryName) {
|
|
5
5
|
object(expression: $expression) {
|
|
6
|
-
... on
|
|
7
|
-
|
|
8
|
-
name
|
|
9
|
-
object {
|
|
10
|
-
__typename
|
|
11
|
-
... on Blob {
|
|
12
|
-
text
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
}
|
|
6
|
+
... on Blob {
|
|
7
|
+
text
|
|
16
8
|
}
|
|
17
9
|
}
|
|
18
10
|
}
|
|
19
11
|
}
|
|
20
12
|
`;
|
|
21
13
|
}
|
|
22
|
-
export function
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
14
|
+
export function createBlobsContentByFilePathsQuery(filePaths, commitHash, batchSize) {
|
|
15
|
+
const queries = [];
|
|
16
|
+
const queryFilenameAliasMap = new Map();
|
|
17
|
+
for (let fileIndex = 0; fileIndex < filePaths.length; fileIndex += batchSize) {
|
|
18
|
+
// cut file content query into batches and use GraphQL aliases for maximum throughput in regard to GitHub API limits
|
|
19
|
+
const batchFilenames = filePaths.slice(fileIndex, fileIndex + batchSize);
|
|
20
|
+
let query = `
|
|
21
|
+
query ($repositoryOwner: String!, $repositoryName: String!) {
|
|
22
|
+
repository(owner: $repositoryOwner, name: $repositoryName) {`;
|
|
23
|
+
for (const [j, filename] of batchFilenames.entries()) {
|
|
24
|
+
const fileAliasIndex = fileIndex + j;
|
|
25
|
+
const fileAlias = `file${fileAliasIndex}`;
|
|
26
|
+
// using one query variable per file would significantly blow up query size, which would in turn require a lower
|
|
27
|
+
// batch size to avoid GitHub erroring out, and in consequence much lower throughput; we therefore use this poor
|
|
28
|
+
// man's manual escaping of filenames instead and write them directly into the query strings
|
|
29
|
+
const escapedExpression = JSON.stringify(`${commitHash}:${filename}`);
|
|
30
|
+
query += ` ${fileAlias}: object(expression: ${escapedExpression}) {
|
|
31
|
+
... on Blob {
|
|
32
|
+
text
|
|
31
33
|
}
|
|
32
34
|
}
|
|
33
|
-
|
|
35
|
+
`;
|
|
36
|
+
queryFilenameAliasMap.set(fileAlias, filename);
|
|
37
|
+
}
|
|
38
|
+
query += ` }
|
|
39
|
+
}`;
|
|
40
|
+
queries.push(query);
|
|
41
|
+
}
|
|
42
|
+
return { queries, queryFilenameAliasMap };
|
|
34
43
|
}
|
|
35
44
|
export function createCommitMutation() {
|
|
36
45
|
return `
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"graphql-query-factory.js","sourceRoot":"","sources":["../../../src/github-api/graphql-query-factory.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,4BAA4B;IAC1C,OAAO;;;;;;;;;;KAUJ,CAAA;AACL,CAAC;AAED,MAAM,UAAU,kCA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= '.yaml';
|
|
2
|
+
export const PATH_SCHEMA_FILE = 'commitspark/schema/schema.graphql';
|
|
3
|
+
export const PATH_ENTRY_FOLDER = 'commitspark/entries/';
|
|
4
|
+
export const QUERY_BATCH_SIZE = 250;
|
|
5
|
+
export const GITHUB_GRAPHQL_API_URL = 'https://api.github.com/graphql';
|
|
6
|
+
export const GITHUB_REST_API_URL = 'https://api.github.com';
|
|
7
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,eAAe,GAAG,OAAO,CAAA;AACtC,MAAM,CAAC,MAAM,gBAAgB,GAAG,mCAAmC,CAAA;AACnE,MAAM,CAAC,MAAM,iBAAiB,GAAG,sBAAsB,CAAA;AACvD,MAAM,CAAC,MAAM,gBAAgB,GAAG,GAAG,CAAA;AACnC,MAAM,CAAC,MAAM,sBAAsB,GAAG,gCAAgC,CAAA;AACtE,MAAM,CAAC,MAAM,mBAAmB,GAAG,wBAAwB,CAAA"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { stringify } from 'yaml';
|
|
2
2
|
import { AdditionModel } from '../model/addition.model';
|
|
3
3
|
import { DeletionModel } from '../model/deletion.model';
|
|
4
|
-
import { ENTRY_EXTENSION } from '
|
|
4
|
+
import { ENTRY_EXTENSION } from '../types';
|
|
5
5
|
export function convertEntriesToActions(entryDrafts, pathEntryFolder) {
|
|
6
6
|
const additions = [];
|
|
7
7
|
const deletions = [];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"entries-to-actions-converter.js","sourceRoot":"","sources":["../../../src/util/entries-to-actions-converter.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,MAAM,CAAA;AAChC,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAA;AACvD,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAA;AACvD,OAAO,EAAE,eAAe,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"entries-to-actions-converter.js","sourceRoot":"","sources":["../../../src/util/entries-to-actions-converter.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,MAAM,CAAA;AAChC,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAA;AACvD,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAA;AACvD,OAAO,EAAE,eAAe,EAAE,MAAM,UAAU,CAAA;AAE1C,MAAM,UAAU,uBAAuB,CACrC,WAAyB,EACzB,eAAuB;IAKvB,MAAM,SAAS,GAAoB,EAAE,CAAA;IACrC,MAAM,SAAS,GAAoB,EAAE,CAAA;IACrC,WAAW,CAAC,OAAO,CAAC,CAAC,UAAU,EAAE,EAAE;QACjC,MAAM,SAAS,GAAG,GAAG,eAAe,IAAI,UAAU,CAAC,EAAE,GAAG,eAAe,EAAE,CAAA;QACzE,IAAI,UAAU,CAAC,QAAQ,EAAE,CAAC;YACxB,SAAS,CAAC,IAAI,CAAC,IAAI,aAAa,CAAC,SAAS,CAAC,CAAC,CAAA;QAC9C,CAAC;aAAM,CAAC;YACN,SAAS,CAAC,IAAI,CACZ,IAAI,aAAa,CACf,SAAS,EACT,SAAS,CAAC;gBACR,QAAQ,EAAE,UAAU,CAAC,QAAQ;gBAC7B,IAAI,EAAE,UAAU,CAAC,IAAI;aACtB,CAAC,CACH,CACF,CAAA;QACH,CAAC;IACH,CAAC,CAAC,CAAA;IACF,OAAO;QACL,SAAS;QACT,SAAS;KACV,CAAA;AACH,CAAC"}
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { parse } from 'yaml';
|
|
2
|
-
import { ENTRY_EXTENSION } from '
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
.map((
|
|
8
|
-
const fileContent = parse(
|
|
9
|
-
const id =
|
|
2
|
+
import { ENTRY_EXTENSION } from '../types';
|
|
3
|
+
import { getPathEntryFolder } from './path-factory';
|
|
4
|
+
export function createEntriesFromFileContent(gitRepositoryOptions, filePathContentMap) {
|
|
5
|
+
return Array.from(filePathContentMap)
|
|
6
|
+
.filter(([filePath]) => filePath.endsWith(ENTRY_EXTENSION))
|
|
7
|
+
.map(([filePath, content]) => {
|
|
8
|
+
const fileContent = parse(content);
|
|
9
|
+
const id = filePath.substring(getPathEntryFolder(gitRepositoryOptions).length, // strip folder path back out
|
|
10
|
+
filePath.length - ENTRY_EXTENSION.length);
|
|
10
11
|
return {
|
|
11
12
|
id: id,
|
|
12
13
|
metadata: fileContent.metadata,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"entry-factory.js","sourceRoot":"","sources":["../../../src/util/entry-factory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,MAAM,CAAA;AAE5B,OAAO,EAAE,eAAe,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"entry-factory.js","sourceRoot":"","sources":["../../../src/util/entry-factory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,MAAM,CAAA;AAE5B,OAAO,EAAE,eAAe,EAAE,MAAM,UAAU,CAAA;AAC1C,OAAO,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAA;AAGnD,MAAM,UAAU,4BAA4B,CAC1C,oBAA6C,EAC7C,kBAAuC;IAEvC,OAAO,KAAK,CAAC,IAAI,CAAC,kBAAkB,CAAC;SAClC,MAAM,CAAC,CAAC,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC,QAAQ,CAAC,QAAQ,CAAC,eAAe,CAAC,CAAC;SAC1D,GAAG,CAAC,CAAC,CAAC,QAAQ,EAAE,OAAO,CAAC,EAAE,EAAE;QAC3B,MAAM,WAAW,GAAG,KAAK,CAAC,OAAO,CAAC,CAAA;QAClC,MAAM,EAAE,GAAG,QAAQ,CAAC,SAAS,CAC3B,kBAAkB,CAAC,oBAAoB,CAAC,CAAC,MAAM,EAAE,6BAA6B;QAC9E,QAAQ,CAAC,MAAM,GAAG,eAAe,CAAC,MAAM,CACzC,CAAA;QACD,OAAO;YACL,EAAE,EAAE,EAAE;YACN,QAAQ,EAAE,WAAW,CAAC,QAAQ;YAC9B,IAAI,EAAE,WAAW,CAAC,IAAI;SACd,CAAA;IACZ,CAAC,CAAC,CAAA;AACN,CAAC"}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { PATH_ENTRY_FOLDER, PATH_SCHEMA_FILE } from '
|
|
1
|
+
import { PATH_ENTRY_FOLDER, PATH_SCHEMA_FILE } from '../types';
|
|
2
2
|
export function getPathSchema(gitRepositoryOptions) {
|
|
3
3
|
return gitRepositoryOptions.pathSchemaFile ?? PATH_SCHEMA_FILE;
|
|
4
4
|
}
|
|
5
5
|
export function getPathEntryFolder(gitRepositoryOptions) {
|
|
6
6
|
const pathEntryFolder = gitRepositoryOptions.pathEntryFolder ?? PATH_ENTRY_FOLDER;
|
|
7
|
-
if (pathEntryFolder.endsWith('/')) {
|
|
8
|
-
return pathEntryFolder
|
|
7
|
+
if (!pathEntryFolder.endsWith('/')) {
|
|
8
|
+
return pathEntryFolder + '/';
|
|
9
9
|
}
|
|
10
10
|
return pathEntryFolder;
|
|
11
11
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"path-factory.js","sourceRoot":"","sources":["../../../src/util/path-factory.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"path-factory.js","sourceRoot":"","sources":["../../../src/util/path-factory.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAA;AAE9D,MAAM,UAAU,aAAa,CAAC,oBAA6C;IACzE,OAAO,oBAAoB,CAAC,cAAc,IAAI,gBAAgB,CAAA;AAChE,CAAC;AAED,MAAM,UAAU,kBAAkB,CAChC,oBAA6C;IAE7C,MAAM,eAAe,GACnB,oBAAoB,CAAC,eAAe,IAAI,iBAAiB,CAAA;IAE3D,IAAI,CAAC,eAAe,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC;QACnC,OAAO,eAAe,GAAG,GAAG,CAAA;IAC9B,CAAC;IAED,OAAO,eAAe,CAAA;AACxB,CAAC"}
|