@eddeee888/gcg-typescript-resolver-files 0.1.0 → 0.1.2
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/package.json +3 -3
- package/src/generateResolverFiles/types.d.ts +2 -2
- package/src/generateResolverFiles/visitNamedType.js +2 -2
- package/src/generateResolverFiles/visitNamedType.js.map +1 -1
- package/src/getPluginsConfig/getPluginsConfig.d.ts +3 -3
- package/src/getPluginsConfig/getPluginsConfig.js +2 -2
- package/src/getPluginsConfig/getPluginsConfig.js.map +1 -1
- package/src/parseSources/parseSources.d.ts +5 -2
- package/src/parseSources/parseSources.js +5 -5
- package/src/parseSources/parseSources.js.map +1 -1
- package/src/parseTypeMappers/parseTypeMappers.d.ts +3 -3
- package/src/parseTypeMappers/parseTypeMappers.js +2 -2
- package/src/parseTypeMappers/parseTypeMappers.js.map +1 -1
- package/src/preset.d.ts +2 -19
- package/src/preset.js +6 -55
- package/src/preset.js.map +1 -1
- package/src/utils/parseLocationForWhitelistedModule.d.ts +3 -3
- package/src/utils/parseLocationForWhitelistedModule.js +3 -3
- package/src/utils/parseLocationForWhitelistedModule.js.map +1 -1
- package/src/validatePresetConfig/index.d.ts +1 -0
- package/src/validatePresetConfig/index.js +5 -0
- package/src/validatePresetConfig/index.js.map +1 -0
- package/src/validatePresetConfig/validatePresetConfig.d.ts +33 -0
- package/src/validatePresetConfig/validatePresetConfig.js +69 -0
- package/src/validatePresetConfig/validatePresetConfig.js.map +1 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@eddeee888/gcg-typescript-resolver-files",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "https://github.com/eddeee888/graphql-code-generator-plugins.git",
|
|
@@ -24,14 +24,14 @@
|
|
|
24
24
|
"author": "Eddy Nguyen <ch@eddeee888.me>",
|
|
25
25
|
"license": "MIT",
|
|
26
26
|
"peerDependencies": {
|
|
27
|
-
"graphql": "^15.0.0 || ^16.0.0"
|
|
28
|
-
"graphql-scalars": "^1.20.1"
|
|
27
|
+
"graphql": "^15.0.0 || ^16.0.0"
|
|
29
28
|
},
|
|
30
29
|
"dependencies": {
|
|
31
30
|
"@graphql-codegen/add": "^3.2.1",
|
|
32
31
|
"@graphql-codegen/plugin-helpers": "^2.7.1",
|
|
33
32
|
"@graphql-codegen/typescript": "^2.8.1",
|
|
34
33
|
"@graphql-codegen/typescript-resolvers": "^2.7.5",
|
|
34
|
+
"graphql-scalars": "^1.20.1",
|
|
35
35
|
"ts-morph": "^16.0.0"
|
|
36
36
|
},
|
|
37
37
|
"publishConfig": {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { GraphQLSchema } from 'graphql';
|
|
2
|
-
import type {
|
|
2
|
+
import type { ParseSourcesResult } from '../parseSources';
|
|
3
3
|
import type { ImportLineMeta, RootObjectType } from '../utils';
|
|
4
4
|
interface BaseVirtualFile {
|
|
5
5
|
__filetype: string;
|
|
@@ -20,7 +20,7 @@ export interface ResolverFile extends BaseVirtualFile {
|
|
|
20
20
|
export interface GenerateResolverFilesContext {
|
|
21
21
|
config: {
|
|
22
22
|
schema: GraphQLSchema;
|
|
23
|
-
|
|
23
|
+
sourceMap: ParseSourcesResult['sourceMap'];
|
|
24
24
|
baseOutputDir: string;
|
|
25
25
|
resolverTypesPath: string;
|
|
26
26
|
resolverRelativeTargetDir: string;
|
|
@@ -40,7 +40,7 @@ exports.visitNamedType = visitNamedType;
|
|
|
40
40
|
* Parse location to see which module it belongs to.
|
|
41
41
|
* Also check against whitelisted and blacklisted to see if need to generate file.
|
|
42
42
|
*/
|
|
43
|
-
const parseLocationForOutputDir = (nestedDirs, { config: { mode,
|
|
43
|
+
const parseLocationForOutputDir = (nestedDirs, { config: { mode, sourceMap, whitelistedModules, blacklistedModules, baseOutputDir, resolverRelativeTargetDir, }, }, location) => {
|
|
44
44
|
// If mode is "merged", there's only one module:
|
|
45
45
|
// - always generate a.k.a it's always whitelisted
|
|
46
46
|
// - put them together at degsinated relativeTargetDir
|
|
@@ -51,7 +51,7 @@ const parseLocationForOutputDir = (nestedDirs, { config: { mode, sourcesMap, whi
|
|
|
51
51
|
// This means one or multiple schema files can add up to one module
|
|
52
52
|
const parsedSource = (0, utils_1.parseLocationForWhitelistedModule)({
|
|
53
53
|
location,
|
|
54
|
-
|
|
54
|
+
sourceMap,
|
|
55
55
|
whitelistedModules,
|
|
56
56
|
blacklistedModules,
|
|
57
57
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"visitNamedType.js","sourceRoot":"","sources":["../../../../../packages/typescript-resolver-files/src/generateResolverFiles/visitNamedType.ts"],"names":[],"mappings":";;;AAAA,6BAA6B;AAC7B,qCAMiB;AACjB,oCAIkB;AAMlB,2EAAwE;AAejE,MAAM,cAAc,GAAG,CAC5B,EACE,SAAS,EACT,YAAY,EACZ,mBAAmB,EACnB,QAAQ,EACR,OAAO,GACc,EACvB,GAAiC,EAC3B,EAAE;IACR,MAAM,sBAAsB,GAAG,qBAAqB,CAClD,YAAY,EACZ,mBAAmB,CACpB,CAAC;IAEF,MAAM,4BAA4B,GAChC,GAAG,CAAC,MAAM,CAAC,iBAAiB,CAAC,sBAAsB,CAAC,CAAC;IACvD,IAAI,4BAA4B,EAAE;QAChC,mCAAmC;QACnC,IAAA,qDAAyB,EACvB;YACE,sBAAsB;YACtB,kBAAkB,EAAE,4BAA4B;SACjD,EACD,GAAG,CACJ,CAAC;QAEF,OAAO;KACR;IAED,kDAAkD;IAClD,MAAM,SAAS,GAAG,yBAAyB,CACzC,mBAAmB,CAAC,CAAC,CAAC,CAAC,mBAAmB,CAAC,CAAC,CAAC,CAAC,EAAE,EAChD,GAAG,EACH,QAAQ,CACT,CAAC;IACF,IAAI,CAAC,SAAS,EAAE;QACd,OAAO;KACR;IAED,4CAA4C;IAC5C,MAAM,oBAAoB,GAAG,uCAAuC,CAClE,EAAE,YAAY,EAAE,sBAAsB,EAAE,SAAS,EAAE,mBAAmB,EAAE,EACxE,GAAG,CACJ,CAAC;IAEF,IAAI,IAAA,sBAAY,EAAC,SAAS,CAAC,EAAE;QAC3B,mBAAmB;YACjB,CAAC,CAAC,OAAO,CAAC,qBAAqB,CAAC,CAAC,oBAAoB,EAAE,GAAG,CAAC;YAC3D,CAAC,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC,oBAAoB,EAAE,GAAG,CAAC,CAAC;KACtD;SAAM,IAAI,IAAA,qBAAW,EAAC,SAAS,CAAC,EAAE;QACjC,OAAO,CAAC,WAAW,CAAC,CAAC,oBAAoB,EAAE,GAAG,CAAC,CAAC;KACjD;SAAM,IAAI,IAAA,sBAAY,EAAC,SAAS,CAAC,EAAE;QAClC,OAAO,CAAC,YAAY,CAAC,CAAC,oBAAoB,EAAE,GAAG,CAAC,CAAC;KAClD;AACH,CAAC,CAAC;AAvDW,QAAA,cAAc,kBAuDzB;AAEF;;;GAGG;AACH,MAAM,yBAAyB,GAAG,CAChC,UAAoB,EACpB,EACE,MAAM,EAAE,EACN,IAAI,EACJ,
|
|
1
|
+
{"version":3,"file":"visitNamedType.js","sourceRoot":"","sources":["../../../../../packages/typescript-resolver-files/src/generateResolverFiles/visitNamedType.ts"],"names":[],"mappings":";;;AAAA,6BAA6B;AAC7B,qCAMiB;AACjB,oCAIkB;AAMlB,2EAAwE;AAejE,MAAM,cAAc,GAAG,CAC5B,EACE,SAAS,EACT,YAAY,EACZ,mBAAmB,EACnB,QAAQ,EACR,OAAO,GACc,EACvB,GAAiC,EAC3B,EAAE;IACR,MAAM,sBAAsB,GAAG,qBAAqB,CAClD,YAAY,EACZ,mBAAmB,CACpB,CAAC;IAEF,MAAM,4BAA4B,GAChC,GAAG,CAAC,MAAM,CAAC,iBAAiB,CAAC,sBAAsB,CAAC,CAAC;IACvD,IAAI,4BAA4B,EAAE;QAChC,mCAAmC;QACn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,mBAAmB;QACnB,sBAAsB;QACtB,iBAAiB;KAClB,CAAC;AACJ,CAAC,CAAC;AAEF;;;;GAIG;AACH,MAAM,qBAAqB,GAAG,CAC5B,IAAY,EACZ,UAAiC,EACzB,EAAE;IACV,IAAI,CAAC,UAAU,EAAE;QACf,OAAO,IAAI,CAAC;KACb;IACD,OAAO,GAAG,UAAU,IAAI,IAAI,EAAE,CAAC;AACjC,CAAC,CAAC"}
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { GraphQLSchema } from 'graphql';
|
|
2
|
-
import type {
|
|
2
|
+
import type { ParseSourcesResult } from '../parseSources';
|
|
3
3
|
import type { TypeMappersMap } from '../parseTypeMappers';
|
|
4
4
|
interface GetPluginsConfigParams {
|
|
5
5
|
schemaAst: GraphQLSchema;
|
|
6
|
-
|
|
6
|
+
sourceMap: ParseSourcesResult['sourceMap'];
|
|
7
7
|
typeMappersMap: TypeMappersMap;
|
|
8
8
|
whitelistedModules: string[];
|
|
9
9
|
blacklistedModules: string[];
|
|
10
10
|
}
|
|
11
11
|
declare type GetPluginsConfigResult = Record<'defaultScalarTypesMap' | 'defaultScalarExternalResolvers' | 'defaultTypeMappers', Record<string, string>>;
|
|
12
|
-
export declare const getPluginsConfig: ({ schemaAst,
|
|
12
|
+
export declare const getPluginsConfig: ({ schemaAst, sourceMap, typeMappersMap, whitelistedModules, blacklistedModules, }: GetPluginsConfigParams) => GetPluginsConfigResult;
|
|
13
13
|
export {};
|
|
@@ -4,7 +4,7 @@ exports.getPluginsConfig = void 0;
|
|
|
4
4
|
const graphql_1 = require("graphql");
|
|
5
5
|
const graphql_scalars_1 = require("graphql-scalars");
|
|
6
6
|
const utils_1 = require("../utils");
|
|
7
|
-
const getPluginsConfig = ({ schemaAst,
|
|
7
|
+
const getPluginsConfig = ({ schemaAst, sourceMap, typeMappersMap, whitelistedModules, blacklistedModules, }) => {
|
|
8
8
|
return Object.entries(schemaAst.getTypeMap()).reduce((res, [schemaType, namedType]) => {
|
|
9
9
|
var _a;
|
|
10
10
|
if ((0, utils_1.isNativeNamedType)(namedType)) {
|
|
@@ -12,7 +12,7 @@ const getPluginsConfig = ({ schemaAst, sourcesMap, typeMappersMap, whitelistedMo
|
|
|
12
12
|
}
|
|
13
13
|
const parsedSource = (0, utils_1.parseLocationForWhitelistedModule)({
|
|
14
14
|
location: (_a = namedType.astNode) === null || _a === void 0 ? void 0 : _a.loc,
|
|
15
|
-
|
|
15
|
+
sourceMap,
|
|
16
16
|
whitelistedModules,
|
|
17
17
|
blacklistedModules,
|
|
18
18
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getPluginsConfig.js","sourceRoot":"","sources":["../../../../../packages/typescript-resolver-files/src/getPluginsConfig/getPluginsConfig.ts"],"names":[],"mappings":";;;AAAA,qCAAoE;AACpE,qDAA+D;AAG/D,oCAIkB;AAiBX,MAAM,gBAAgB,GAAG,CAAC,EAC/B,SAAS,EACT,
|
|
1
|
+
{"version":3,"file":"getPluginsConfig.js","sourceRoot":"","sources":["../../../../../packages/typescript-resolver-files/src/getPluginsConfig/getPluginsConfig.ts"],"names":[],"mappings":";;;AAAA,qCAAoE;AACpE,qDAA+D;AAG/D,oCAIkB;AAiBX,MAAM,gBAAgB,GAAG,CAAC,EAC/B,SAAS,EACT,SAAS,EACT,cAAc,EACd,kBAAkB,EAClB,kBAAkB,GACK,EAA0B,EAAE;IACnD,OAAO,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,UAAU,EAAE,CAAC,CAAC,MAAM,CAClD,CAAC,GAAG,EAAE,CAAC,UAAU,EAAE,SAAS,CAAC,EAAE,EAAE;;QAC/B,IAAI,IAAA,yBAAiB,EAAC,SAAS,CAAC,EAAE;YAChC,OAAO,GAAG,CAAC;SACZ;QAED,MAAM,YAAY,GAAG,IAAA,yCAAiC,EAAC;YACrD,QAAQ,EAAE,MAAA,SAAS,CAAC,OAAO,0CAAE,GAAG;YAChC,SAAS;YACT,kBAAkB;YAClB,kBAAk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
}
|
|
9
|
-
export
|
|
10
|
-
|
|
9
|
+
export interface ParseSourcesResult {
|
|
10
|
+
sourceMap: Record<string, ParsedSource>;
|
|
11
|
+
mergedSDL: string;
|
|
12
|
+
}
|
|
13
|
+
export declare function parseSources(sources: Source[]): ParseSourcesResult;
|
|
@@ -3,21 +3,21 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.parseSources = void 0;
|
|
4
4
|
const path = require("path");
|
|
5
5
|
function parseSources(sources) {
|
|
6
|
-
|
|
7
|
-
sources.forEach((source) => {
|
|
6
|
+
return sources.reduce((result, source) => {
|
|
8
7
|
if (!source.location) {
|
|
9
8
|
throw new Error('Missing source location');
|
|
10
9
|
}
|
|
11
10
|
const sourcePath = path.parse(source.location);
|
|
12
11
|
const moduleDir = sourcePath.dir;
|
|
13
12
|
const [moduleName] = moduleDir.split(path.sep).slice(-1);
|
|
14
|
-
|
|
13
|
+
result.sourceMap[source.location] = {
|
|
15
14
|
source,
|
|
16
15
|
sourcePath,
|
|
17
16
|
moduleName,
|
|
18
17
|
};
|
|
19
|
-
|
|
20
|
-
|
|
18
|
+
result.mergedSDL += `\n${source.rawSDL}`;
|
|
19
|
+
return result;
|
|
20
|
+
}, { sourceMap: {}, mergedSDL: '' });
|
|
21
21
|
}
|
|
22
22
|
exports.parseSources = parseSources;
|
|
23
23
|
//# sourceMappingURL=parseSources.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parseSources.js","sourceRoot":"","sources":["../../../../../packages/typescript-resolver-files/src/parseSources/parseSources.ts"],"names":[],"mappings":";;;AAAA,6BAA6B;
|
|
1
|
+
{"version":3,"file":"parseSources.js","sourceRoot":"","sources":["../../../../../packages/typescript-resolver-files/src/parseSources/parseSources.ts"],"names":[],"mappings":";;;AAAA,6BAA6B;AAc7B,SAAgB,YAAY,CAAC,OAAiB;IAC5C,OAAO,OAAO,CAAC,MAAM,CACnB,CAAC,MAAM,EAAE,MAAM,EAAE,EAAE;QACjB,IAAI,CAAC,MAAM,CAAC,QAAQ,EAAE;YACpB,MAAM,IAAI,KAAK,CAAC,yBAAyB,CAAC,CAAC;SAC5C;QAED,MAAM,UAAU,GAAG,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;QAC/C,MAAM,SAAS,GAAG,UAAU,CAAC,GAAG,CAAC;QAEjC,MAAM,CAAC,UAAU,CAAC,GAAG,SAAS,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;QAEzD,MAAM,CAAC,SAAS,CAAC,MAAM,CAAC,QAAQ,CAAC,GAAG;YAClC,MAAM;YACN,UAAU;YACV,UAAU;SACX,CAAC;QAEF,MAAM,CAAC,SAAS,IAAI,KAAK,MAAM,CAAC,MAAM,EAAE,CAAC;QAEzC,OAAO,MAAM,CAAC;IAChB,CAAC,EACD,EAAE,SAAS,EAAE,EAAE,EAAE,SAAS,EAAE,EAAE,EAAE,CACjC,CAAC;AACJ,CAAC;AAxBD,oCAwBC"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { ParseSourcesResult } from '../parseSources';
|
|
2
2
|
export interface ParseTypeMappersParams {
|
|
3
|
-
|
|
3
|
+
sourceMap: ParseSourcesResult['sourceMap'];
|
|
4
4
|
resolverTypesPath: string;
|
|
5
5
|
typeMappersFileExtension: string;
|
|
6
6
|
typeMappersSuffix: string;
|
|
@@ -11,4 +11,4 @@ export interface TypeMapperDetails {
|
|
|
11
11
|
configImportPath: string;
|
|
12
12
|
}
|
|
13
13
|
export declare type TypeMappersMap = Record<string, TypeMapperDetails>;
|
|
14
|
-
export declare const parseTypeMappers: ({
|
|
14
|
+
export declare const parseTypeMappers: ({ sourceMap, resolverTypesPath, typeMappersFileExtension, typeMappersSuffix, }: ParseTypeMappersParams) => TypeMappersMap;
|
|
@@ -5,8 +5,8 @@ const path = require("path");
|
|
|
5
5
|
const fs = require("fs");
|
|
6
6
|
const ts_morph_1 = require("ts-morph");
|
|
7
7
|
const collectTypeMappersFromSourceFile_1 = require("./collectTypeMappersFromSourceFile");
|
|
8
|
-
const parseTypeMappers = ({
|
|
9
|
-
const result = Object.entries(
|
|
8
|
+
const parseTypeMappers = ({ sourceMap, resolverTypesPath, typeMappersFileExtension, typeMappersSuffix, }) => {
|
|
9
|
+
const result = Object.entries(sourceMap).reduce((res, [_, { sourcePath }]) => {
|
|
10
10
|
const typeMapperFilePath = path.join(sourcePath.dir, `${sourcePath.name}${typeMappersFileExtension}`);
|
|
11
11
|
if (!fs.existsSync(typeMapperFilePath)) {
|
|
12
12
|
return res;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parseTypeMappers.js","sourceRoot":"","sources":["../../../../../packages/typescript-resolver-files/src/parseTypeMappers/parseTypeMappers.ts"],"names":[],"mappings":";;;AAAA,6BAA6B;AAC7B,yBAAyB;AACzB,uCAAmC;AAEnC,yFAAsF;AAiB/E,MAAM,gBAAgB,GAAG,CAAC,EAC/B,
|
|
1
|
+
{"version":3,"file":"parseTypeMappers.js","sourceRoot":"","sources":["../../../../../packages/typescript-resolver-files/src/parseTypeMappers/parseTypeMappers.ts"],"names":[],"mappings":";;;AAAA,6BAA6B;AAC7B,yBAAyB;AACzB,uCAAmC;AAEnC,yFAAsF;AAiB/E,MAAM,gBAAgB,GAAG,CAAC,EAC/B,SAAS,EACT,iBAAiB,EACjB,wBAAwB,EACxB,iBAAiB,GACM,EAAkB,EAAE;IAC3C,MAAM,MAAM,GAAG,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,MAAM,CAC7C,CAAC,GAAG,EAAE,CAAC,CAAC,EAAE,EAAE,UAAU,EAAE,CAAC,EAAE,EAAE;QAC3B,MAAM,kBAAkB,GAAG,IAAI,CAAC,IAAI,CAClC,UAAU,CAAC,GAAG,EACd,GAAG,UAAU,CAAC,IAAI,GAAG,wBAAwB,EAAE,CAChD,CAAC;QAEF,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,kBAAkB,CAAC,EAAE;YACtC,OAAO,GAAG,CAAC;SACZ;QAED,MAAM,OAAO,GAAG,IAAI,kBAAO,EAAE,CAAC;QAC9B,MAAM,CAAC,qBAAqB,CAAC,GAC3B,OAAO,CAAC,qBAAqB,CAAC,kBAAkB,CAAC,CAAC;QAEpD,IAAA,mEAAgC,EAC9B,EAAE,qBAAqB,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,EAC/D,GAAG,CACJ,CAAC;QAEF,OAAO,GAAG,CAAC;IACb,CAAC,EACD,EAAE,CACH,CAAC;IACF,OAAO,MAAM,CAAC;AAChB,CAAC,CAAC;AA/BW,QAAA,gBAAgB,oBA+B3B"}
|
package/src/preset.d.ts
CHANGED
|
@@ -1,20 +1,3 @@
|
|
|
1
|
-
import * as typeScriptPlugin from '@graphql-codegen/typescript';
|
|
2
|
-
import * as typeScriptResolversPlugin from '@graphql-codegen/typescript-resolvers';
|
|
3
1
|
import type { Types } from '@graphql-codegen/plugin-helpers';
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
};
|
|
7
|
-
interface ParsedPresetConfig {
|
|
8
|
-
resolverTypesPath: string;
|
|
9
|
-
resolverRelativeTargetDir: string;
|
|
10
|
-
resolverMainFile: string;
|
|
11
|
-
mappersFileExtension: string;
|
|
12
|
-
mappersSuffix: string;
|
|
13
|
-
mode: 'merged' | 'modules';
|
|
14
|
-
whitelistedModules: string[];
|
|
15
|
-
blacklistedModules: string[];
|
|
16
|
-
externalResolvers: Record<string, string>;
|
|
17
|
-
typesPluginsConfig: ParsedTypesPluginsConfig;
|
|
18
|
-
}
|
|
19
|
-
export declare const preset: Types.OutputPreset<ParsedPresetConfig>;
|
|
20
|
-
export {};
|
|
2
|
+
import { RawPresetConfig } from './validatePresetConfig';
|
|
3
|
+
export declare const preset: Types.OutputPreset<RawPresetConfig>;
|
package/src/preset.js
CHANGED
|
@@ -9,7 +9,7 @@ const parseSources_1 = require("./parseSources");
|
|
|
9
9
|
const getPluginsConfig_1 = require("./getPluginsConfig");
|
|
10
10
|
const generateResolverFiles_1 = require("./generateResolverFiles");
|
|
11
11
|
const parseTypeMappers_1 = require("./parseTypeMappers");
|
|
12
|
-
const
|
|
12
|
+
const validatePresetConfig_1 = require("./validatePresetConfig");
|
|
13
13
|
exports.preset = {
|
|
14
14
|
buildGeneratesSection: ({ schema, schemaAst, presetConfig: rawPresetConfig, baseOutputDir, }) => {
|
|
15
15
|
if (!schemaAst) {
|
|
@@ -19,11 +19,11 @@ exports.preset = {
|
|
|
19
19
|
if (!Array.isArray(sources) || sources.length === 0) {
|
|
20
20
|
throw new Error('Empty Sources. Make sure schema files are parsed correctly.');
|
|
21
21
|
}
|
|
22
|
-
const { resolverTypesPath: relativeResolverTypesPathFromBaseOutputDir, resolverRelativeTargetDir, mappersFileExtension: typeMappersFileExtension, mappersSuffix: typeMappersSuffix, resolverMainFile, mode, whitelistedModules, blacklistedModules, externalResolvers, typesPluginsConfig, } = validatePresetConfig(rawPresetConfig);
|
|
22
|
+
const { resolverTypesPath: relativeResolverTypesPathFromBaseOutputDir, resolverRelativeTargetDir, mappersFileExtension: typeMappersFileExtension, mappersSuffix: typeMappersSuffix, resolverMainFile, mode, whitelistedModules, blacklistedModules, externalResolvers, typesPluginsConfig, } = (0, validatePresetConfig_1.validatePresetConfig)(rawPresetConfig);
|
|
23
23
|
const resolverTypesPath = path.join(baseOutputDir, relativeResolverTypesPathFromBaseOutputDir);
|
|
24
|
-
const
|
|
24
|
+
const { sourceMap } = (0, parseSources_1.parseSources)(sources);
|
|
25
25
|
const typeMappersMap = (0, parseTypeMappers_1.parseTypeMappers)({
|
|
26
|
-
|
|
26
|
+
sourceMap,
|
|
27
27
|
resolverTypesPath,
|
|
28
28
|
typeMappersFileExtension,
|
|
29
29
|
typeMappersSuffix,
|
|
@@ -31,7 +31,7 @@ exports.preset = {
|
|
|
31
31
|
// typescript and typescript-resolvers plugins config
|
|
32
32
|
const { defaultScalarTypesMap, defaultScalarExternalResolvers, defaultTypeMappers, } = (0, getPluginsConfig_1.getPluginsConfig)({
|
|
33
33
|
schemaAst,
|
|
34
|
-
|
|
34
|
+
sourceMap,
|
|
35
35
|
typeMappersMap,
|
|
36
36
|
whitelistedModules,
|
|
37
37
|
blacklistedModules,
|
|
@@ -55,7 +55,7 @@ exports.preset = {
|
|
|
55
55
|
(0, generateResolverFiles_1.generateResolverFiles)({
|
|
56
56
|
config: {
|
|
57
57
|
schema: schemaAst,
|
|
58
|
-
|
|
58
|
+
sourceMap,
|
|
59
59
|
baseOutputDir,
|
|
60
60
|
resolverTypesPath,
|
|
61
61
|
resolverRelativeTargetDir,
|
|
@@ -80,53 +80,4 @@ exports.preset = {
|
|
|
80
80
|
return generatesSection;
|
|
81
81
|
},
|
|
82
82
|
};
|
|
83
|
-
const validatePresetConfig = ({ resolverTypesPath = './types.generated.ts', resolverRelativeTargetDir = 'resolvers', resolverMainFile = 'resolvers.generated.ts', mappersFileExtension = '.mappers.ts', mappersSuffix = 'Mapper', mode = 'modules', whitelistedModules, blacklistedModules, externalResolvers = {}, typesPluginsConfig = {}, }) => {
|
|
84
|
-
if (!resolverTypesPath) {
|
|
85
|
-
throw new Error(`Validation Error - ${presetName} - presetConfig.resolverTypesPath is required`);
|
|
86
|
-
}
|
|
87
|
-
if (path.extname(resolverMainFile) === '') {
|
|
88
|
-
throw new Error(`Validation Error - ${presetName} - presetConfig.mainFile must be a valid file name`);
|
|
89
|
-
}
|
|
90
|
-
if (mode !== 'merged' && mode !== 'modules') {
|
|
91
|
-
throw new Error(`Validation Error - ${presetName} - presetConfig.mode must be "merged" or "modules" (default is "modules")`);
|
|
92
|
-
}
|
|
93
|
-
if (whitelistedModules) {
|
|
94
|
-
if (!Array.isArray(whitelistedModules)) {
|
|
95
|
-
throw new Error(`Validation Error - ${presetName} - presetConfig.whitelistedModules must be an array if provided`);
|
|
96
|
-
}
|
|
97
|
-
if (mode !== 'modules') {
|
|
98
|
-
throw new Error(`Validation Error - ${presetName} - presetConfig.whitelistedModules can only be used with presetConfig.mode == "modules"`);
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
if (blacklistedModules) {
|
|
102
|
-
if (!Array.isArray(blacklistedModules)) {
|
|
103
|
-
throw new Error(`Validation Error - ${presetName} - presetConfig.blacklistedModules must be an array if provided`);
|
|
104
|
-
}
|
|
105
|
-
if (mode !== 'modules') {
|
|
106
|
-
throw new Error(`Validation Error - ${presetName} - presetConfig.blacklistedModules can only be used with presetConfig.mode == "modules"`);
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
if (!validateTypesPluginsConfig(typesPluginsConfig)) {
|
|
110
|
-
throw new Error('Invalid typescriptPluginConfig. Should not see this.');
|
|
111
|
-
}
|
|
112
|
-
return {
|
|
113
|
-
resolverTypesPath,
|
|
114
|
-
resolverRelativeTargetDir,
|
|
115
|
-
resolverMainFile,
|
|
116
|
-
mode,
|
|
117
|
-
mappersFileExtension,
|
|
118
|
-
mappersSuffix,
|
|
119
|
-
whitelistedModules: whitelistedModules || [],
|
|
120
|
-
blacklistedModules: blacklistedModules || [],
|
|
121
|
-
externalResolvers,
|
|
122
|
-
typesPluginsConfig,
|
|
123
|
-
};
|
|
124
|
-
};
|
|
125
|
-
const validateTypesPluginsConfig = (config) => {
|
|
126
|
-
config.scalars = config.scalars || {};
|
|
127
|
-
if (typeof config.scalars === 'string') {
|
|
128
|
-
throw new Error(`Validation Error - ${presetName} - presetConfig.typesPluginsConfig.scalars of type "string" is not supported`);
|
|
129
|
-
}
|
|
130
|
-
return true;
|
|
131
|
-
};
|
|
132
83
|
//# sourceMappingURL=preset.js.map
|
package/src/preset.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"preset.js","sourceRoot":"","sources":["../../../../packages/typescript-resolver-files/src/preset.ts"],"names":[],"mappings":";;;AAAA,6BAA6B;AAC7B,kDAAkD;AAClD,gEAAgE;AAChE,mFAAmF;AAEnF,iDAA8C;AAC9C,yDAAsD;AACtD,mEAGiC;AACjC,yDAAsD;
|
|
1
|
+
{"version":3,"file":"preset.js","sourceRoot":"","sources":["../../../../packages/typescript-resolver-files/src/preset.ts"],"names":[],"mappings":";;;AAAA,6BAA6B;AAC7B,kDAAkD;AAClD,gEAAgE;AAChE,mFAAmF;AAEnF,iDAA8C;AAC9C,yDAAsD;AACtD,mEAGiC;AACjC,yDAAsD;AACtD,iEAA+E;AAElE,QAAA,MAAM,GAAwC;IACzD,qBAAqB,EAAE,CAAC,EACtB,MAAM,EACN,SAAS,EACT,YAAY,EAAE,eAAe,EAC7B,aAAa,GACd,EAAE,EAAE;QACH,IAAI,CAAC,SAAS,EAAE;YACd,MAAM,IAAI,KAAK,CAAC,mBAAmB,CAAC,CAAC;SACtC;QACD,MAAM,OAAO,GAAG,SAAS,CAAC,UAAU,CAAC,eAAe,CAAC;QACrD,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC,EAAE;YACnD,MAAM,IAAI,KAAK,CACb,6DAA6D,CAC9D,CAAC;SACH;QAED,MAAM,EACJ,iBAAiB,EAAE,0CAA0C,EAC7D,yBAAyB,EACzB,oBAAoB,EAAE,wBAAwB,EAC9C,aAAa,EAAE,iBAAiB,EAChC,gBAAgB,EAChB,IAAI,EACJ,kBAAkB,EAClB,kBAAkB,EAClB,iBAAiB,EACjB,kBAAkB,GACnB,GAAG,IAAA,2CAAoB,EAAC,eAAe,CAAC,CAAC;QAE1C,MAAM,iBAAiB,GAAG,IAAI,CAAC,IAAI,CACjC,aAAa,EACb,0CAA0C,CAC3C,CAAC;QAEF,MAAM,EAAE,SAAS,EAAE,GAAG,IAAA,2BAAY,EAAC,OAAO,CAAC,CAAC;QAE5C,MAAM,cAAc,GAAG,IAAA,mCAAgB,EAAC;YACtC,SAAS;YACT,iBAAiB;YACjB,wBAAwB;YACxB,iBAAiB;SAClB,CAAC,CAAC;QA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ACR,SAAS,EAAE,EAAE,GAAG,EAAE,SAAS,EAAE;YAC7B,OAAO,EAAE,CAAC,EAAE,GAAG,EAAE,EAAE,OAAO,EAAE,EAAE,CAAC;YAC/B,MAAM,EAAE,EAAE;YACV,MAAM;YACN,SAAS,EAAE,EAAE;SACd,CAAC,CAAC,CAAC;QACJ,gBAAgB,CAAC,IAAI,CAAC,iBAAiB,CAAC,CAAC;QACzC,OAAO,gBAAgB,CAAC;IAC1B,CAAC;CACF,CAAC"}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import type { Location } from 'graphql';
|
|
2
|
-
import type {
|
|
2
|
+
import type { ParseSourcesResult, ParsedSource } from '../parseSources';
|
|
3
3
|
export interface ParseLocationForWhitelistedModule {
|
|
4
4
|
location: Location | undefined;
|
|
5
|
-
|
|
5
|
+
sourceMap: ParseSourcesResult['sourceMap'];
|
|
6
6
|
whitelistedModules: string[];
|
|
7
7
|
blacklistedModules: string[];
|
|
8
8
|
}
|
|
9
|
-
export declare const parseLocationForWhitelistedModule: ({ location,
|
|
9
|
+
export declare const parseLocationForWhitelistedModule: ({ location, sourceMap, whitelistedModules, blacklistedModules, }: ParseLocationForWhitelistedModule) => ParsedSource | undefined;
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.parseLocationForWhitelistedModule = void 0;
|
|
4
|
-
const parseLocationForWhitelistedModule = ({ location,
|
|
4
|
+
const parseLocationForWhitelistedModule = ({ location, sourceMap, whitelistedModules, blacklistedModules, }) => {
|
|
5
5
|
if (!location) {
|
|
6
6
|
throw new Error('Location is invalid');
|
|
7
7
|
}
|
|
8
8
|
const sourceFilename = location.source.name;
|
|
9
|
-
const sourceFile =
|
|
9
|
+
const sourceFile = sourceMap[sourceFilename];
|
|
10
10
|
if (!sourceFile) {
|
|
11
|
-
throw new Error(`Unable to find ${sourceFilename} in
|
|
11
|
+
throw new Error(`Unable to find ${sourceFilename} in sourceMap`);
|
|
12
12
|
}
|
|
13
13
|
if (blacklistedModules.includes(sourceFile.moduleName)) {
|
|
14
14
|
return;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parseLocationForWhitelistedModule.js","sourceRoot":"","sources":["../../../../../packages/typescript-resolver-files/src/utils/parseLocationForWhitelistedModule.ts"],"names":[],"mappings":";;;AAUO,MAAM,iCAAiC,GAAG,CAAC,EAChD,QAAQ,EACR,
|
|
1
|
+
{"version":3,"file":"parseLocationForWhitelistedModule.js","sourceRoot":"","sources":["../../../../../packages/typescript-resolver-files/src/utils/parseLocationForWhitelistedModule.ts"],"names":[],"mappings":";;;AAUO,MAAM,iCAAiC,GAAG,CAAC,EAChD,QAAQ,EACR,SAAS,EACT,kBAAkB,EAClB,kBAAkB,GACgB,EAA4B,EAAE;IAChE,IAAI,CAAC,QAAQ,EAAE;QACb,MAAM,IAAI,KAAK,CAAC,qBAAqB,CAAC,CAAC;KACxC;IAED,MAAM,cAAc,GAAG,QAAQ,CAAC,MAAM,CAAC,IAAI,CAAC;IAC5C,MAAM,UAAU,GAAG,SAAS,CAAC,cAAc,CAAC,CAAC;IAC7C,IAAI,CAAC,UAAU,EAAE;QACf,MAAM,IAAI,KAAK,CAAC,kBAAkB,cAAc,eAAe,CAAC,CAAC;KAClE;IAED,IAAI,kBAAkB,CAAC,QAAQ,CAAC,UAAU,CAAC,UAAU,CAAC,EAAE;QACtD,OAAO;KACR;IAED,MAAM,qBAAqB;IACzB,yDAAyD;IACzD,kBAAkB,CAAC,MAAM,KAAK,CAAC;QAC7B,CAAC,CAAC,IAAI;QACN,CAAC,CAAC,kBAAkB,CAAC,QAAQ,CAAC,UAAU,CAAC,UAAU,CAAC,CAAC;IAEzD,OAAO,qBAAqB,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,SAAS,CAAC;AACxD,CAAC,CAAC;AA3BW,QAAA,iCAAiC,qCA2B5C"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './validatePresetConfig';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../packages/typescript-resolver-files/src/validatePresetConfig/index.ts"],"names":[],"mappings":";;;AAAA,iEAAuC"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import * as typeScriptPlugin from '@graphql-codegen/typescript';
|
|
2
|
+
import * as typeScriptResolversPlugin from '@graphql-codegen/typescript-resolvers';
|
|
3
|
+
declare type ParsedTypesPluginsConfig = Omit<typeScriptPlugin.TypeScriptPluginConfig, 'scalars'> & Omit<typeScriptResolversPlugin.TypeScriptResolversPluginConfig, 'scalars'> & {
|
|
4
|
+
scalars: Record<string, string>;
|
|
5
|
+
};
|
|
6
|
+
interface ParsedPresetConfig {
|
|
7
|
+
resolverTypesPath: string;
|
|
8
|
+
resolverRelativeTargetDir: string;
|
|
9
|
+
resolverMainFile: string;
|
|
10
|
+
typeDefsFilePath: string | false;
|
|
11
|
+
mappersFileExtension: string;
|
|
12
|
+
mappersSuffix: string;
|
|
13
|
+
mode: 'merged' | 'modules';
|
|
14
|
+
whitelistedModules: string[];
|
|
15
|
+
blacklistedModules: string[];
|
|
16
|
+
externalResolvers: Record<string, string>;
|
|
17
|
+
typesPluginsConfig: ParsedTypesPluginsConfig;
|
|
18
|
+
}
|
|
19
|
+
export interface RawPresetConfig {
|
|
20
|
+
resolverTypesPath?: string;
|
|
21
|
+
resolverRelativeTargetDir?: string;
|
|
22
|
+
resolverMainFile?: string;
|
|
23
|
+
typeDefsFilePath?: string | boolean;
|
|
24
|
+
mappersFileExtension?: string;
|
|
25
|
+
mappersSuffix?: string;
|
|
26
|
+
mode?: string;
|
|
27
|
+
whitelistedModules?: string[];
|
|
28
|
+
blacklistedModules?: string[];
|
|
29
|
+
externalResolvers?: Record<string, string>;
|
|
30
|
+
typesPluginsConfig?: typeScriptPlugin.TypeScriptPluginConfig & typeScriptResolversPlugin.TypeScriptResolversPluginConfig;
|
|
31
|
+
}
|
|
32
|
+
export declare const validatePresetConfig: ({ resolverTypesPath, resolverRelativeTargetDir, resolverMainFile, typeDefsFilePath, mappersFileExtension, mappersSuffix, mode, whitelistedModules, blacklistedModules, externalResolvers, typesPluginsConfig, }: RawPresetConfig) => ParsedPresetConfig;
|
|
33
|
+
export {};
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.validatePresetConfig = void 0;
|
|
4
|
+
const path = require("path");
|
|
5
|
+
const presetName = '@eddeee888/gcg-typescript-resolver-files';
|
|
6
|
+
const defaultResolverRelativeTargetDirMap = {
|
|
7
|
+
modules: 'resolvers',
|
|
8
|
+
merged: '',
|
|
9
|
+
};
|
|
10
|
+
const defaultTypeDefsFilePath = './typeDefs.generated.ts';
|
|
11
|
+
const validatePresetConfig = ({ resolverTypesPath = './types.generated.ts', resolverRelativeTargetDir, resolverMainFile = 'resolvers.generated.ts', typeDefsFilePath = defaultTypeDefsFilePath, mappersFileExtension = '.mappers.ts', mappersSuffix = 'Mapper', mode = 'modules', whitelistedModules, blacklistedModules, externalResolvers = {}, typesPluginsConfig = {}, }) => {
|
|
12
|
+
if (mode !== 'merged' && mode !== 'modules') {
|
|
13
|
+
throw new Error(`Validation Error - ${presetName} - presetConfig.mode must be "merged" or "modules" (default is "modules")`);
|
|
14
|
+
}
|
|
15
|
+
if (!resolverTypesPath) {
|
|
16
|
+
throw new Error(`Validation Error - ${presetName} - presetConfig.resolverTypesPath is required`);
|
|
17
|
+
}
|
|
18
|
+
const finalResolverRelativeTargetDir = resolverRelativeTargetDir === undefined
|
|
19
|
+
? defaultResolverRelativeTargetDirMap[mode]
|
|
20
|
+
: resolverRelativeTargetDir;
|
|
21
|
+
if (path.extname(resolverMainFile) === '') {
|
|
22
|
+
throw new Error(`Validation Error - ${presetName} - presetConfig.mainFile must be a valid file name`);
|
|
23
|
+
}
|
|
24
|
+
if (whitelistedModules) {
|
|
25
|
+
if (!Array.isArray(whitelistedModules)) {
|
|
26
|
+
throw new Error(`Validation Error - ${presetName} - presetConfig.whitelistedModules must be an array if provided`);
|
|
27
|
+
}
|
|
28
|
+
if (mode !== 'modules') {
|
|
29
|
+
throw new Error(`Validation Error - ${presetName} - presetConfig.whitelistedModules can only be used with presetConfig.mode == "modules"`);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
if (blacklistedModules) {
|
|
33
|
+
if (!Array.isArray(blacklistedModules)) {
|
|
34
|
+
throw new Error(`Validation Error - ${presetName} - presetConfig.blacklistedModules must be an array if provided`);
|
|
35
|
+
}
|
|
36
|
+
if (mode !== 'modules') {
|
|
37
|
+
throw new Error(`Validation Error - ${presetName} - presetConfig.blacklistedModules can only be used with presetConfig.mode == "modules"`);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
if (!validateTypesPluginsConfig(typesPluginsConfig)) {
|
|
41
|
+
throw new Error('Invalid typescriptPluginConfig. Should not see this.');
|
|
42
|
+
}
|
|
43
|
+
let finalTypeDefsFilePath = typeDefsFilePath;
|
|
44
|
+
if (finalTypeDefsFilePath === true) {
|
|
45
|
+
finalTypeDefsFilePath = defaultTypeDefsFilePath;
|
|
46
|
+
}
|
|
47
|
+
return {
|
|
48
|
+
resolverTypesPath,
|
|
49
|
+
resolverRelativeTargetDir: finalResolverRelativeTargetDir,
|
|
50
|
+
resolverMainFile,
|
|
51
|
+
typeDefsFilePath: finalTypeDefsFilePath,
|
|
52
|
+
mode,
|
|
53
|
+
mappersFileExtension,
|
|
54
|
+
mappersSuffix,
|
|
55
|
+
whitelistedModules: whitelistedModules || [],
|
|
56
|
+
blacklistedModules: blacklistedModules || [],
|
|
57
|
+
externalResolvers,
|
|
58
|
+
typesPluginsConfig,
|
|
59
|
+
};
|
|
60
|
+
};
|
|
61
|
+
exports.validatePresetConfig = validatePresetConfig;
|
|
62
|
+
const validateTypesPluginsConfig = (config) => {
|
|
63
|
+
config.scalars = config.scalars || {};
|
|
64
|
+
if (typeof config.scalars === 'string') {
|
|
65
|
+
throw new Error(`Validation Error - ${presetName} - presetConfig.typesPluginsConfig.scalars of type "string" is not supported`);
|
|
66
|
+
}
|
|
67
|
+
return true;
|
|
68
|
+
};
|
|
69
|
+
//# sourceMappingURL=validatePresetConfig.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validatePresetConfig.js","sourceRoot":"","sources":["../../../../../packages/typescript-resolver-files/src/validatePresetConfig/validatePresetConfig.ts"],"names":[],"mappings":";;;AAAA,6BAA6B;AAI7B,MAAM,UAAU,GAAG,0CAA0C,CAAC;AAE9D,MAAM,mCAAmC,GAGrC;IACF,OAAO,EAAE,WAAW;IACpB,MAAM,EAAE,EAAE;CACX,CAAC;AACF,MAAM,uBAAuB,GAAG,yBAAyB,CAAC;AAuCnD,MAAM,oBAAoB,GAAG,CAAC,EACnC,iBAAiB,GAAG,sBAAsB,EAC1C,yBAAyB,EACzB,gBAAgB,GAAG,wBAAwB,EAC3C,gBAAgB,GAAG,uBAAuB,EAC1C,oBAAoB,GAAG,aAAa,EACpC,aAAa,GAAG,QAAQ,EACxB,IAAI,GAAG,SAAS,EAChB,kBAAkB,EAClB,kBAAkB,EAClB,iBAAiB,GAAG,EAAE,EACtB,kBAAkB,GAAG,EAAE,GACP,EAAsB,EAAE;IACxC,IAAI,IAAI,KAAK,QAAQ,IAAI,IAAI,KAAK,SAAS,EAAE;QAC3C,MAAM,IAAI,KAAK,CACb,sBAAsB,UAAU,2EAA2E,CAC5G,CAAC;KACH;IAED,IAAI,CAAC,iBAAiB,EAAE;QACtB,MAAM,IAAI,KAAK,CACb,sBAAsB,UAAU,+CAA+C,CAChF,CAAC;KACH;IAED,MAAM,8BAA8B,GAClC,yBAAyB,KAAK,SAAS;QACrC,CAAC,CAAC,mCAAmC,CAAC,IAAI,CAAC;QAC3C,CAAC,CAAC,yBAAyB,CAAC;IAEhC,IAAI,IAAI,CAAC,OA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