@graphql-inspector/coverage-command 0.0.0-canary.da4bdcc → 0.0.0-canary.e88122e

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/index.d.ts CHANGED
@@ -1,5 +1,14 @@
1
- import { GlobalArgs } from '@graphql-inspector/commands';
2
- declare const _default: import("../../commands/src").CommandFactory<{}, {
1
+ import { GlobalArgs, CommandFactory } from '@graphql-inspector/commands';
2
+ import { Source as DocumentSource } from '@graphql-tools/utils';
3
+ import { GraphQLSchema } from 'graphql';
4
+ export { CommandFactory };
5
+ export declare function handler({ schema, documents, silent, writePath, }: {
6
+ schema: GraphQLSchema;
7
+ documents: DocumentSource[];
8
+ silent?: boolean;
9
+ writePath?: string;
10
+ }): void;
11
+ declare const _default: CommandFactory<{}, {
3
12
  schema: string;
4
13
  documents: string;
5
14
  write?: string | undefined;
@@ -1,5 +1,7 @@
1
1
  'use strict';
2
2
 
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
3
5
  const tslib = require('tslib');
4
6
  const commands = require('@graphql-inspector/commands');
5
7
  const logger = require('@graphql-inspector/logger');
@@ -8,24 +10,51 @@ const graphql = require('graphql');
8
10
  const path = require('path');
9
11
  const fs = require('fs');
10
12
 
13
+ function handler({ schema, documents, silent, writePath, }) {
14
+ const shouldWrite = typeof writePath !== 'undefined';
15
+ const coverage = core.coverage(schema, documents.map((doc) => new graphql.Source(graphql.print(doc.document), doc.location)));
16
+ if (silent !== true) {
17
+ renderCoverage(coverage);
18
+ }
19
+ if (shouldWrite) {
20
+ if (typeof writePath !== 'string') {
21
+ throw new Error(`--write is not valid file path: ${writePath}`);
22
+ }
23
+ const absPath = commands.ensureAbsolute(writePath);
24
+ const ext = path.extname(absPath).replace('.', '').toLocaleLowerCase();
25
+ let output = undefined;
26
+ if (ext === 'json') {
27
+ output = outputJSON(coverage);
28
+ }
29
+ if (output) {
30
+ fs.writeFileSync(absPath, output, {
31
+ encoding: 'utf-8',
32
+ });
33
+ logger.Logger.success(`Available at ${absPath}\n`);
34
+ }
35
+ else {
36
+ throw new Error(`Extension ${ext} is not supported`);
37
+ }
38
+ }
39
+ }
11
40
  const index = commands.createCommand((api) => {
12
- const { loaders, interceptArguments, interceptPositional, interceptOptions, } = api;
41
+ const { loaders } = api;
13
42
  return {
14
43
  command: 'coverage <documents> <schema>',
15
44
  describe: 'Schema coverage based on documents',
16
45
  builder(yargs) {
17
46
  return yargs
18
- .positional('schema', interceptPositional('schema', {
47
+ .positional('schema', {
19
48
  describe: 'Point to a schema',
20
49
  type: 'string',
21
50
  demandOption: true,
22
- }))
23
- .positional('documents', interceptPositional('documents', {
51
+ })
52
+ .positional('documents', {
24
53
  describe: 'Point to documents',
25
54
  type: 'string',
26
55
  demandOption: true,
27
- }))
28
- .options(interceptOptions({
56
+ })
57
+ .options({
29
58
  w: {
30
59
  alias: 'write',
31
60
  describe: 'Write a file with coverage stats',
@@ -36,43 +65,24 @@ const index = commands.createCommand((api) => {
36
65
  describe: 'Do not render any stats in the terminal',
37
66
  type: 'boolean',
38
67
  },
39
- }));
68
+ });
40
69
  },
41
70
  handler(args) {
71
+ var _a;
42
72
  return tslib.__awaiter(this, void 0, void 0, function* () {
43
- interceptArguments(args);
44
73
  const writePath = args.write;
45
- const shouldWrite = typeof writePath !== 'undefined';
74
+ const silent = args.silent;
46
75
  const { headers, token } = commands.parseGlobalArgs(args);
76
+ const apolloFederation = args.federation || false;
77
+ const aws = args.aws || false;
78
+ const method = ((_a = args.method) === null || _a === void 0 ? void 0 : _a.toUpperCase()) || 'POST';
47
79
  const schema = yield loaders.loadSchema(args.schema, {
48
80
  token,
49
81
  headers,
50
- });
82
+ method,
83
+ }, apolloFederation, aws);
51
84
  const documents = yield loaders.loadDocuments(args.documents);
52
- const coverage = core.coverage(schema, documents.map((doc) => new graphql.Source(graphql.print(doc.document), doc.location)));
53
- if (args.silent !== true) {
54
- renderCoverage(coverage);
55
- }
56
- if (shouldWrite) {
57
- if (typeof writePath !== 'string') {
58
- throw new Error(`--write is not valid file path: ${writePath}`);
59
- }
60
- const absPath = commands.ensureAbsolute(writePath);
61
- const ext = path.extname(absPath).replace('.', '').toLocaleLowerCase();
62
- let output = undefined;
63
- if (ext === 'json') {
64
- output = outputJSON(coverage);
65
- }
66
- if (output) {
67
- fs.writeFileSync(absPath, output, {
68
- encoding: 'utf-8',
69
- });
70
- logger.Logger.success(`Available at ${absPath}\n`);
71
- }
72
- else {
73
- throw new Error(`Extension ${ext} is not supported`);
74
- }
75
- }
85
+ return handler({ schema, documents, silent, writePath });
76
86
  });
77
87
  },
78
88
  };
@@ -115,5 +125,5 @@ function indent(line, space) {
115
125
  return line.padStart(line.length + space, ' ');
116
126
  }
117
127
 
118
- module.exports = index;
119
- //# sourceMappingURL=index.cjs.js.map
128
+ exports.default = index;
129
+ exports.handler = handler;
@@ -6,24 +6,51 @@ import { Source, print } from 'graphql';
6
6
  import { extname } from 'path';
7
7
  import { writeFileSync } from 'fs';
8
8
 
9
+ function handler({ schema, documents, silent, writePath, }) {
10
+ const shouldWrite = typeof writePath !== 'undefined';
11
+ const coverage$1 = coverage(schema, documents.map((doc) => new Source(print(doc.document), doc.location)));
12
+ if (silent !== true) {
13
+ renderCoverage(coverage$1);
14
+ }
15
+ if (shouldWrite) {
16
+ if (typeof writePath !== 'string') {
17
+ throw new Error(`--write is not valid file path: ${writePath}`);
18
+ }
19
+ const absPath = ensureAbsolute(writePath);
20
+ const ext = extname(absPath).replace('.', '').toLocaleLowerCase();
21
+ let output = undefined;
22
+ if (ext === 'json') {
23
+ output = outputJSON(coverage$1);
24
+ }
25
+ if (output) {
26
+ writeFileSync(absPath, output, {
27
+ encoding: 'utf-8',
28
+ });
29
+ Logger.success(`Available at ${absPath}\n`);
30
+ }
31
+ else {
32
+ throw new Error(`Extension ${ext} is not supported`);
33
+ }
34
+ }
35
+ }
9
36
  const index = createCommand((api) => {
10
- const { loaders, interceptArguments, interceptPositional, interceptOptions, } = api;
37
+ const { loaders } = api;
11
38
  return {
12
39
  command: 'coverage <documents> <schema>',
13
40
  describe: 'Schema coverage based on documents',
14
41
  builder(yargs) {
15
42
  return yargs
16
- .positional('schema', interceptPositional('schema', {
43
+ .positional('schema', {
17
44
  describe: 'Point to a schema',
18
45
  type: 'string',
19
46
  demandOption: true,
20
- }))
21
- .positional('documents', interceptPositional('documents', {
47
+ })
48
+ .positional('documents', {
22
49
  describe: 'Point to documents',
23
50
  type: 'string',
24
51
  demandOption: true,
25
- }))
26
- .options(interceptOptions({
52
+ })
53
+ .options({
27
54
  w: {
28
55
  alias: 'write',
29
56
  describe: 'Write a file with coverage stats',
@@ -34,43 +61,24 @@ const index = createCommand((api) => {
34
61
  describe: 'Do not render any stats in the terminal',
35
62
  type: 'boolean',
36
63
  },
37
- }));
64
+ });
38
65
  },
39
66
  handler(args) {
67
+ var _a;
40
68
  return __awaiter(this, void 0, void 0, function* () {
41
- interceptArguments(args);
42
69
  const writePath = args.write;
43
- const shouldWrite = typeof writePath !== 'undefined';
70
+ const silent = args.silent;
44
71
  const { headers, token } = parseGlobalArgs(args);
72
+ const apolloFederation = args.federation || false;
73
+ const aws = args.aws || false;
74
+ const method = ((_a = args.method) === null || _a === void 0 ? void 0 : _a.toUpperCase()) || 'POST';
45
75
  const schema = yield loaders.loadSchema(args.schema, {
46
76
  token,
47
77
  headers,
48
- });
78
+ method,
79
+ }, apolloFederation, aws);
49
80
  const documents = yield loaders.loadDocuments(args.documents);
50
- const coverage$1 = coverage(schema, documents.map((doc) => new Source(print(doc.document), doc.location)));
51
- if (args.silent !== true) {
52
- renderCoverage(coverage$1);
53
- }
54
- if (shouldWrite) {
55
- if (typeof writePath !== 'string') {
56
- throw new Error(`--write is not valid file path: ${writePath}`);
57
- }
58
- const absPath = ensureAbsolute(writePath);
59
- const ext = extname(absPath).replace('.', '').toLocaleLowerCase();
60
- let output = undefined;
61
- if (ext === 'json') {
62
- output = outputJSON(coverage$1);
63
- }
64
- if (output) {
65
- writeFileSync(absPath, output, {
66
- encoding: 'utf-8',
67
- });
68
- Logger.success(`Available at ${absPath}\n`);
69
- }
70
- else {
71
- throw new Error(`Extension ${ext} is not supported`);
72
- }
73
- }
81
+ return handler({ schema, documents, silent, writePath });
74
82
  });
75
83
  },
76
84
  };
@@ -114,4 +122,4 @@ function indent(line, space) {
114
122
  }
115
123
 
116
124
  export default index;
117
- //# sourceMappingURL=index.esm.js.map
125
+ export { handler };
package/package.json CHANGED
@@ -1,15 +1,15 @@
1
1
  {
2
2
  "name": "@graphql-inspector/coverage-command",
3
- "version": "0.0.0-canary.da4bdcc",
3
+ "version": "0.0.0-canary.e88122e",
4
4
  "description": "Schema Coverage in GraphQL Inspector",
5
5
  "sideEffects": false,
6
6
  "peerDependencies": {
7
- "graphql": "^0.13.0 || ^14.0.0 || ^15.0.0"
7
+ "graphql": "^0.13.0 || ^14.0.0 || ^15.0.0 || ^16.0.0"
8
8
  },
9
9
  "dependencies": {
10
- "@graphql-inspector/commands": "0.0.0-canary.da4bdcc",
11
- "@graphql-inspector/core": "0.0.0-canary.da4bdcc",
12
- "@graphql-inspector/logger": "0.0.0-canary.da4bdcc",
10
+ "@graphql-inspector/commands": "0.0.0-canary.e88122e",
11
+ "@graphql-inspector/core": "0.0.0-canary.e88122e",
12
+ "@graphql-inspector/logger": "0.0.0-canary.e88122e",
13
13
  "tslib": "^2.0.0"
14
14
  },
15
15
  "repository": {
@@ -29,10 +29,20 @@
29
29
  "url": "https://github.com/kamilkisiela"
30
30
  },
31
31
  "license": "MIT",
32
- "main": "index.cjs.js",
33
- "module": "index.esm.js",
32
+ "main": "index.js",
33
+ "module": "index.mjs",
34
34
  "typings": "index.d.ts",
35
35
  "typescript": {
36
36
  "definition": "index.d.ts"
37
+ },
38
+ "exports": {
39
+ ".": {
40
+ "require": "./index.js",
41
+ "import": "./index.mjs"
42
+ },
43
+ "./*": {
44
+ "require": "./*.js",
45
+ "import": "./*.mjs"
46
+ }
37
47
  }
38
48
  }
package/index.cjs.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.cjs.js","sources":["../../dist/commands/coverage/src/index.js"],"sourcesContent":["import { __awaiter } from \"tslib\";\nimport { createCommand, ensureAbsolute, parseGlobalArgs, } from '@graphql-inspector/commands';\nimport { Logger, chalk } from '@graphql-inspector/logger';\nimport { coverage as calculateCoverage, getTypePrefix, } from '@graphql-inspector/core';\nimport { Source, print } from 'graphql';\nimport { extname } from 'path';\nimport { writeFileSync } from 'fs';\nexport default createCommand((api) => {\n const { loaders, interceptArguments, interceptPositional, interceptOptions, } = api;\n return {\n command: 'coverage <documents> <schema>',\n describe: 'Schema coverage based on documents',\n builder(yargs) {\n return yargs\n .positional('schema', interceptPositional('schema', {\n describe: 'Point to a schema',\n type: 'string',\n demandOption: true,\n }))\n .positional('documents', interceptPositional('documents', {\n describe: 'Point to documents',\n type: 'string',\n demandOption: true,\n }))\n .options(interceptOptions({\n w: {\n alias: 'write',\n describe: 'Write a file with coverage stats',\n type: 'string',\n },\n s: {\n alias: 'silent',\n describe: 'Do not render any stats in the terminal',\n type: 'boolean',\n },\n }));\n },\n handler(args) {\n return __awaiter(this, void 0, void 0, function* () {\n interceptArguments(args);\n const writePath = args.write;\n const shouldWrite = typeof writePath !== 'undefined';\n const { headers, token } = parseGlobalArgs(args);\n const schema = yield loaders.loadSchema(args.schema, {\n token,\n headers,\n });\n const documents = yield loaders.loadDocuments(args.documents);\n const coverage = calculateCoverage(schema, documents.map((doc) => new Source(print(doc.document), doc.location)));\n if (args.silent !== true) {\n renderCoverage(coverage);\n }\n if (shouldWrite) {\n if (typeof writePath !== 'string') {\n throw new Error(`--write is not valid file path: ${writePath}`);\n }\n const absPath = ensureAbsolute(writePath);\n const ext = extname(absPath).replace('.', '').toLocaleLowerCase();\n let output = undefined;\n if (ext === 'json') {\n output = outputJSON(coverage);\n }\n if (output) {\n writeFileSync(absPath, output, {\n encoding: 'utf-8',\n });\n Logger.success(`Available at ${absPath}\\n`);\n }\n else {\n throw new Error(`Extension ${ext} is not supported`);\n }\n }\n });\n },\n };\n});\nfunction outputJSON(coverage) {\n return JSON.stringify(coverage, null, 2);\n}\nfunction renderCoverage(coverage) {\n Logger.info('Schema coverage based on documents:\\n');\n for (const typeName in coverage.types) {\n if (coverage.types.hasOwnProperty(typeName)) {\n const typeCoverage = coverage.types[typeName];\n Logger.log([\n chalk.grey(getTypePrefix(typeCoverage.type)),\n chalk.bold(`${typeName}`),\n chalk.grey('{'),\n ].join(' '));\n for (const childName in typeCoverage.children) {\n if (typeCoverage.children.hasOwnProperty(childName)) {\n const childCoverage = typeCoverage.children[childName];\n if (childCoverage.hits) {\n Logger.log([\n indent(childName, 2),\n chalk.italic.grey(`x ${childCoverage.hits}`),\n ].join(' '));\n }\n else {\n Logger.log([\n chalk.redBright(indent(childName, 2)),\n chalk.italic.grey('x 0'),\n ].join(' '));\n }\n }\n }\n Logger.log(chalk.grey('}\\n'));\n }\n }\n}\nfunction indent(line, space) {\n return line.padStart(line.length + space, ' ');\n}\n//# sourceMappingURL=index.js.map"],"names":["createCommand","__awaiter","parseGlobalArgs","calculateCoverage","Source","print","ensureAbsolute","extname","writeFileSync","Logger","chalk","getTypePrefix"],"mappings":";;;;;;;;;;AAOA,cAAeA,sBAAa,CAAC,CAAC,GAAG,KAAK;AACtC,IAAI,MAAM,EAAE,OAAO,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,gBAAgB,GAAG,GAAG,GAAG,CAAC;AACxF,IAAI,OAAO;AACX,QAAQ,OAAO,EAAE,+BAA+B;AAChD,QAAQ,QAAQ,EAAE,oCAAoC;AACtD,QAAQ,OAAO,CAAC,KAAK,EAAE;AACvB,YAAY,OAAO,KAAK;AACxB,iBAAiB,UAAU,CAAC,QAAQ,EAAE,mBAAmB,CAAC,QAAQ,EAAE;AACpE,gBAAgB,QAAQ,EAAE,mBAAmB;AAC7C,gBAAgB,IAAI,EAAE,QAAQ;AAC9B,gBAAgB,YAAY,EAAE,IAAI;AAClC,aAAa,CAAC,CA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AE,EAAE,aAAa,CAAC,IAAI,CAAC,CAAC,CAAC;AACxE,yBAAyB,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;AACrC,qBAAqB;AACrB,yBAAyB;AACzB,wBAAwBD,aAAM,CAAC,GAAG,CAAC;AACnC,4BAA4BC,YAAK,CAAC,SAAS,CAAC,MAAM,CAAC,SAAS,EAAE,CAAC,CAAC,CAAC;AACjE,4BAA4BA,YAAK,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC;AACpD,yBAAyB,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;AACrC,qBAAqB;AACrB,iBAAiB;AACjB,aAAa;AACb,YAAYD,aAAM,CAAC,GAAG,CAACC,YAAK,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC;AAC1C,SAAS;AACT,KAAK;AACL,CAAC;AACD,SAAS,MAAM,CAAC,IAAI,EAAE,KAAK,EAAE;AAC7B,IAAI,OAAO,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,MAAM,GAAG,KAAK,EAAE,GAAG,CAAC,CAAC;AACnD;;;;"}
package/index.esm.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.esm.js","sources":["../../dist/commands/coverage/src/index.js"],"sourcesContent":["import { __awaiter } from \"tslib\";\nimport { createCommand, ensureAbsolute, parseGlobalArgs, } from '@graphql-inspector/commands';\nimport { Logger, chalk } from '@graphql-inspector/logger';\nimport { coverage as calculateCoverage, getTypePrefix, } from '@graphql-inspector/core';\nimport { Source, print } from 'graphql';\nimport { extname } from 'path';\nimport { writeFileSync } from 'fs';\nexport default createCommand((api) => {\n const { loaders, interceptArguments, interceptPositional, interceptOptions, } = api;\n return {\n command: 'coverage <documents> <schema>',\n describe: 'Schema coverage based on documents',\n builder(yargs) {\n return yargs\n .positional('schema', interceptPositional('schema', {\n describe: 'Point to a schema',\n type: 'string',\n demandOption: true,\n }))\n .positional('documents', interceptPositional('documents', {\n describe: 'Point to documents',\n type: 'string',\n demandOption: true,\n }))\n .options(interceptOptions({\n w: {\n alias: 'write',\n describe: 'Write a file with coverage stats',\n type: 'string',\n },\n s: {\n alias: 'silent',\n describe: 'Do not render any stats in the terminal',\n type: 'boolean',\n },\n }));\n },\n handler(args) {\n return __awaiter(this, void 0, void 0, function* () {\n interceptArguments(args);\n const writePath = args.write;\n const shouldWrite = typeof writePath !== 'undefined';\n const { headers, token } = parseGlobalArgs(args);\n const schema = yield loaders.loadSchema(args.schema, {\n token,\n headers,\n });\n const documents = yield loaders.loadDocuments(args.documents);\n const coverage = calculateCoverage(schema, documents.map((doc) => new Source(print(doc.document), doc.location)));\n if (args.silent !== true) {\n renderCoverage(coverage);\n }\n if (shouldWrite) {\n if (typeof writePath !== 'string') {\n throw new Error(`--write is not valid file path: ${writePath}`);\n }\n const absPath = ensureAbsolute(writePath);\n const ext = extname(absPath).replace('.', '').toLocaleLowerCase();\n let output = undefined;\n if (ext === 'json') {\n output = outputJSON(coverage);\n }\n if (output) {\n writeFileSync(absPath, output, {\n encoding: 'utf-8',\n });\n Logger.success(`Available at ${absPath}\\n`);\n }\n else {\n throw new Error(`Extension ${ext} is not supported`);\n }\n }\n });\n },\n };\n});\nfunction outputJSON(coverage) {\n return JSON.stringify(coverage, null, 2);\n}\nfunction renderCoverage(coverage) {\n Logger.info('Schema coverage based on documents:\\n');\n for (const typeName in coverage.types) {\n if (coverage.types.hasOwnProperty(typeName)) {\n const typeCoverage = coverage.types[typeName];\n Logger.log([\n chalk.grey(getTypePrefix(typeCoverage.type)),\n chalk.bold(`${typeName}`),\n chalk.grey('{'),\n ].join(' '));\n for (const childName in typeCoverage.children) {\n if (typeCoverage.children.hasOwnProperty(childName)) {\n const childCoverage = typeCoverage.children[childName];\n if (childCoverage.hits) {\n Logger.log([\n indent(childName, 2),\n chalk.italic.grey(`x ${childCoverage.hits}`),\n ].join(' '));\n }\n else {\n Logger.log([\n chalk.redBright(indent(childName, 2)),\n chalk.italic.grey('x 0'),\n ].join(' '));\n }\n }\n }\n Logger.log(chalk.grey('}\\n'));\n }\n }\n}\nfunction indent(line, space) {\n return line.padStart(line.length + space, ' ');\n}\n//# sourceMappingURL=index.js.map"],"names":["coverage","calculateCoverage"],"mappings":";;;;;;;;AAOA,cAAe,aAAa,CAAC,CAAC,GAAG,KAAK;AACtC,IAAI,MAAM,EAAE,OAAO,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,gBAAgB,GAAG,GAAG,GAAG,CAAC;AACxF,IAAI,OAAO;AACX,QAAQ,OAAO,EAAE,+BAA+B;AAChD,QAAQ,QAAQ,EAAE,oCAAoC;AACtD,QAAQ,OAAO,CAAC,KAAK,EAAE;AACvB,YAAY,OAAO,KAAK;AACxB,iBAAiB,UAAU,CAAC,QAAQ,EAAE,mBAAmB,CAAC,QAAQ,EAAE;AACpE,gBAAgB,QAAQ,EAAE,mBAAmB;AAC7C,gBAAgB,IAAI,EAAE,QAAQ;AAC9B,gBAAgB,YAAY,EAAE,IAAI;AAClC,aAAa,CAAC,CAAC;AACf,iBAAiB,UAAU,CAAC,WAAW,EAAE,mBAAmB,CAAC,WAAW,EAAE;AAC1E,gBAAgB,QAAQ,EAAE,oBAAoB;AAC9C,gBAAgB,IAAI,EAAE,QAAQ;AAC9B,gBAAgB,YAAY,EAAE,IAAI;AAClC,aAAa,CAAC,CAAC;AACf,iBAAiB,OAAO,CAAC,gBAAgB,CAAC;AAC1C,gBAAgB,CAAC,EAAE;AACnB,oBAAoB,KAAK,EAAE,OAAO;AAClC,oBAAoB,QAAQ,EAAE,kCAAkC;AAChE,oBAAoB,IAAI,EAAE,QAAQ;AAClC,iBAAiB;AACjB,gBAAgB,CAAC,EAAE;AACnB,oBAAoB,KAAK,EAAE,QAAQ;AACnC,oBAAoB,QAAQ,EAAE,yCAAyC;AACvE,oBAAoB,IAAI,EAAE,SAAS;AACnC,iBAAiB;AACjB,aAAa,CAAC,CAAC,CAAC;AAChB,SAAS;AACT,QAAQ,OAAO,CAAC,IAAI,EAAE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