@graphitation/apollo-react-relay-duct-tape-compiler 1.0.0-alpha.1

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.
Files changed (109) hide show
  1. package/CHANGELOG.md +83 -0
  2. package/README.md +3 -0
  3. package/lib/cli.d.ts +3 -0
  4. package/lib/cli.d.ts.map +1 -0
  5. package/lib/cli.js +185 -0
  6. package/lib/cli.js.map +7 -0
  7. package/lib/cli.mjs +166 -0
  8. package/lib/cli.mjs.map +7 -0
  9. package/lib/compilerTransforms/annotateFragmentReferenceTransform.d.ts +13 -0
  10. package/lib/compilerTransforms/annotateFragmentReferenceTransform.d.ts.map +1 -0
  11. package/lib/compilerTransforms/annotateFragmentReferenceTransform.js +98 -0
  12. package/lib/compilerTransforms/annotateFragmentReferenceTransform.js.map +7 -0
  13. package/lib/compilerTransforms/annotateFragmentReferenceTransform.mjs +82 -0
  14. package/lib/compilerTransforms/annotateFragmentReferenceTransform.mjs.map +7 -0
  15. package/lib/compilerTransforms/emitApolloClientConnectionTransform.d.ts +12 -0
  16. package/lib/compilerTransforms/emitApolloClientConnectionTransform.d.ts.map +1 -0
  17. package/lib/compilerTransforms/emitApolloClientConnectionTransform.js +116 -0
  18. package/lib/compilerTransforms/emitApolloClientConnectionTransform.js.map +7 -0
  19. package/lib/compilerTransforms/emitApolloClientConnectionTransform.mjs +107 -0
  20. package/lib/compilerTransforms/emitApolloClientConnectionTransform.mjs.map +7 -0
  21. package/lib/compilerTransforms/enableNodeWatchQueryTransform.d.ts +9 -0
  22. package/lib/compilerTransforms/enableNodeWatchQueryTransform.d.ts.map +1 -0
  23. package/lib/compilerTransforms/enableNodeWatchQueryTransform.js +78 -0
  24. package/lib/compilerTransforms/enableNodeWatchQueryTransform.js.map +7 -0
  25. package/lib/compilerTransforms/enableNodeWatchQueryTransform.mjs +62 -0
  26. package/lib/compilerTransforms/enableNodeWatchQueryTransform.mjs.map +7 -0
  27. package/lib/compilerTransforms/retainConnectionDirectiveTransform.d.ts +13 -0
  28. package/lib/compilerTransforms/retainConnectionDirectiveTransform.d.ts.map +1 -0
  29. package/lib/compilerTransforms/retainConnectionDirectiveTransform.js +83 -0
  30. package/lib/compilerTransforms/retainConnectionDirectiveTransform.js.map +7 -0
  31. package/lib/compilerTransforms/retainConnectionDirectiveTransform.mjs +67 -0
  32. package/lib/compilerTransforms/retainConnectionDirectiveTransform.mjs.map +7 -0
  33. package/lib/compilerTransforms/utils.d.ts +3 -0
  34. package/lib/compilerTransforms/utils.d.ts.map +1 -0
  35. package/lib/compilerTransforms/utils.js +43 -0
  36. package/lib/compilerTransforms/utils.js.map +7 -0
  37. package/lib/compilerTransforms/utils.mjs +14 -0
  38. package/lib/compilerTransforms/utils.mjs.map +7 -0
  39. package/lib/findGraphQLTags.d.ts +8 -0
  40. package/lib/findGraphQLTags.d.ts.map +1 -0
  41. package/lib/findGraphQLTags.js +90 -0
  42. package/lib/findGraphQLTags.js.map +7 -0
  43. package/lib/findGraphQLTags.mjs +61 -0
  44. package/lib/findGraphQLTags.mjs.map +7 -0
  45. package/lib/formatModule.d.ts +10 -0
  46. package/lib/formatModule.d.ts.map +1 -0
  47. package/lib/formatModule.js +121 -0
  48. package/lib/formatModule.js.map +7 -0
  49. package/lib/formatModule.mjs +93 -0
  50. package/lib/formatModule.mjs.map +7 -0
  51. package/lib/formatModuleTransforms/extractMetadataTransform.d.ts +33 -0
  52. package/lib/formatModuleTransforms/extractMetadataTransform.d.ts.map +1 -0
  53. package/lib/formatModuleTransforms/extractMetadataTransform.js +208 -0
  54. package/lib/formatModuleTransforms/extractMetadataTransform.js.map +7 -0
  55. package/lib/formatModuleTransforms/extractMetadataTransform.mjs +182 -0
  56. package/lib/formatModuleTransforms/extractMetadataTransform.mjs.map +7 -0
  57. package/lib/formatModuleTransforms/reduceNodeWatchQueryTransform.d.ts +14 -0
  58. package/lib/formatModuleTransforms/reduceNodeWatchQueryTransform.d.ts.map +1 -0
  59. package/lib/formatModuleTransforms/reduceNodeWatchQueryTransform.js +101 -0
  60. package/lib/formatModuleTransforms/reduceNodeWatchQueryTransform.js.map +7 -0
  61. package/lib/formatModuleTransforms/reduceNodeWatchQueryTransform.mjs +79 -0
  62. package/lib/formatModuleTransforms/reduceNodeWatchQueryTransform.mjs.map +7 -0
  63. package/lib/formatModuleTransforms/stripFragmentReferenceFieldSelectionTransform.d.ts +10 -0
  64. package/lib/formatModuleTransforms/stripFragmentReferenceFieldSelectionTransform.d.ts.map +1 -0
  65. package/lib/formatModuleTransforms/stripFragmentReferenceFieldSelectionTransform.js +41 -0
  66. package/lib/formatModuleTransforms/stripFragmentReferenceFieldSelectionTransform.js.map +7 -0
  67. package/lib/formatModuleTransforms/stripFragmentReferenceFieldSelectionTransform.mjs +22 -0
  68. package/lib/formatModuleTransforms/stripFragmentReferenceFieldSelectionTransform.mjs.map +7 -0
  69. package/lib/index.d.ts +3 -0
  70. package/lib/index.d.ts.map +1 -0
  71. package/lib/index.js +19 -0
  72. package/lib/index.js.map +7 -0
  73. package/lib/index.mjs +3 -0
  74. package/lib/index.mjs.map +7 -0
  75. package/lib/relayCompilerLanguagePlugin.d.ts +4 -0
  76. package/lib/relayCompilerLanguagePlugin.d.ts.map +1 -0
  77. package/lib/relayCompilerLanguagePlugin.js +91 -0
  78. package/lib/relayCompilerLanguagePlugin.js.map +7 -0
  79. package/lib/relayCompilerLanguagePlugin.mjs +65 -0
  80. package/lib/relayCompilerLanguagePlugin.mjs.map +7 -0
  81. package/lib/rewriteGraphitationDirectives.d.ts +15 -0
  82. package/lib/rewriteGraphitationDirectives.d.ts.map +1 -0
  83. package/lib/rewriteGraphitationDirectives.js +105 -0
  84. package/lib/rewriteGraphitationDirectives.js.map +7 -0
  85. package/lib/rewriteGraphitationDirectives.mjs +83 -0
  86. package/lib/rewriteGraphitationDirectives.mjs.map +7 -0
  87. package/lib/typeGenerator.d.ts +3 -0
  88. package/lib/typeGenerator.d.ts.map +1 -0
  89. package/lib/typeGenerator.js +30 -0
  90. package/lib/typeGenerator.js.map +7 -0
  91. package/lib/typeGenerator.mjs +11 -0
  92. package/lib/typeGenerator.mjs.map +7 -0
  93. package/lib/types.d.ts +9 -0
  94. package/lib/types.d.ts.map +1 -0
  95. package/lib/types.js +16 -0
  96. package/lib/types.js.map +7 -0
  97. package/lib/types.mjs +0 -0
  98. package/lib/types.mjs.map +7 -0
  99. package/lib/typescriptTransforms/createImportDocumentsTransform.d.ts +10 -0
  100. package/lib/typescriptTransforms/createImportDocumentsTransform.d.ts.map +1 -0
  101. package/lib/typescriptTransforms/createImportDocumentsTransform.js +161 -0
  102. package/lib/typescriptTransforms/createImportDocumentsTransform.js.map +7 -0
  103. package/lib/typescriptTransforms/createImportDocumentsTransform.mjs +134 -0
  104. package/lib/typescriptTransforms/createImportDocumentsTransform.mjs.map +7 -0
  105. package/lib/typings.d.js +1 -0
  106. package/lib/typings.d.js.map +7 -0
  107. package/lib/typings.d.mjs +0 -0
  108. package/lib/typings.d.mjs.map +7 -0
  109. package/package.json +55 -0
package/CHANGELOG.md ADDED
@@ -0,0 +1,83 @@
1
+ # Change Log - relay-compiler-language-graphitation
2
+
3
+ This log was last generated on Mon, 24 Jan 2022 13:40:52 GMT and should not be manually modified.
4
+
5
+ <!-- Start content -->
6
+
7
+ ## 0.8.2
8
+
9
+ Mon, 24 Jan 2022 13:40:52 GMT
10
+
11
+ ### Patches
12
+
13
+ - Fix Webpack 4 compat (mnovikov@microsoft.com)
14
+
15
+ ## 0.8.1
16
+
17
+ Thu, 06 Jan 2022 09:53:33 GMT
18
+
19
+ ### Patches
20
+
21
+ - typecript version changed from ^4.2.3 to >=4.2.3 based on https://github.com/microsoft/graphitation/pull/78 (jakubvejr@microsoft.com)
22
+
23
+ ## 0.8.0
24
+
25
+ Wed, 05 Jan 2022 15:09:43 GMT
26
+
27
+ ### Minor changes
28
+
29
+ - We were facing an error in relay-compiler-language-typescript: 14.0.0. issue described here, which caused a syntax error in generated files. With >=14.0.0 in this update we wanted to not force apps which use the graphitation plugin to have TS version 4.5 or greater. (jakubvejr@microsoft.com)
30
+
31
+ ## 0.7.0
32
+
33
+ Thu, 23 Dec 2021 11:31:14 GMT
34
+
35
+ ### Minor changes
36
+
37
+ - Added proper mjs builds (bump for main release) (mnovikov@microsoft.com)
38
+
39
+ ## 0.6.0
40
+
41
+ Tue, 14 Dec 2021 10:13:54 GMT
42
+
43
+ ### Minor changes
44
+
45
+ - Support ESM in distro packages (mnovikov@microsoft.com)
46
+
47
+ ## 0.5.3
48
+
49
+ Tue, 26 Oct 2021 21:09:29 GMT
50
+
51
+ ### Patches
52
+
53
+ - Ensure that all packages listing graphql as a peerDependency also has it as a devDependency (modevold@microsoft.com)
54
+
55
+ ## 0.5.2
56
+
57
+ Tue, 26 Oct 2021 12:46:12 GMT
58
+
59
+ ### Patches
60
+
61
+ - Align graphql dependency to version ^15.0.0 across packages (modevold@microsoft.com)
62
+
63
+ ## 0.5.1
64
+
65
+ Sat, 24 Apr 2021 23:10:54 GMT
66
+
67
+ ### Patches
68
+
69
+ - Include commonjs modules (eloy.de.enige@gmail.com)
70
+
71
+ ## 0.5.0
72
+
73
+ Fri, 23 Apr 2021 21:44:28 GMT
74
+
75
+ ### Minor changes
76
+
77
+ - First proper release (eloy.de.enige@gmail.com)
78
+
79
+ ### Patches
80
+
81
+ - fixing the publish process, publishing a new patch level (kchau@microsoft.com)
82
+ - fixing the publish process, publishing a new patch level (again) (kchau@microsoft.com)
83
+ - Include correct files (eloy.de.enige@gmail.com)
package/README.md ADDED
@@ -0,0 +1,3 @@
1
+ # @graphitation/apollo-react-relay-duct-tape-compiler
2
+
3
+ This package contains all the build tooling needed to support the `@graphitation/apollo-react-relay-duct-tape` package.
package/lib/cli.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env node
2
+ export {};
3
+ //# sourceMappingURL=cli.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":""}
package/lib/cli.js ADDED
@@ -0,0 +1,185 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+ var __create = Object.create;
4
+ var __defProp = Object.defineProperty;
5
+ var __defProps = Object.defineProperties;
6
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
7
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
8
+ var __getOwnPropNames = Object.getOwnPropertyNames;
9
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
10
+ var __getProtoOf = Object.getPrototypeOf;
11
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
12
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
13
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
14
+ var __spreadValues = (a, b) => {
15
+ for (var prop in b || (b = {}))
16
+ if (__hasOwnProp.call(b, prop))
17
+ __defNormalProp(a, prop, b[prop]);
18
+ if (__getOwnPropSymbols)
19
+ for (var prop of __getOwnPropSymbols(b)) {
20
+ if (__propIsEnum.call(b, prop))
21
+ __defNormalProp(a, prop, b[prop]);
22
+ }
23
+ return a;
24
+ };
25
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
26
+ var __copyProps = (to, from, except, desc) => {
27
+ if (from && typeof from === "object" || typeof from === "function") {
28
+ for (let key of __getOwnPropNames(from))
29
+ if (!__hasOwnProp.call(to, key) && key !== except)
30
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
31
+ }
32
+ return to;
33
+ };
34
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
35
+ // If the importer is in node compatibility mode or this is not an ESM
36
+ // file that has been converted to a CommonJS file using a Babel-
37
+ // compatible transform (i.e. "__esModule" has not been set), then set
38
+ // "default" to the CommonJS "module.exports" for node compatibility.
39
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
40
+ mod
41
+ ));
42
+ var __async = (__this, __arguments, generator) => {
43
+ return new Promise((resolve, reject) => {
44
+ var fulfilled = (value) => {
45
+ try {
46
+ step(generator.next(value));
47
+ } catch (e) {
48
+ reject(e);
49
+ }
50
+ };
51
+ var rejected = (value) => {
52
+ try {
53
+ step(generator.throw(value));
54
+ } catch (e) {
55
+ reject(e);
56
+ }
57
+ };
58
+ var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
59
+ step((generator = generator.apply(__this, __arguments)).next());
60
+ });
61
+ };
62
+ var yargs = __toESM(require("yargs"));
63
+ var import_relay_compiler = require("relay-compiler");
64
+ var import_relayCompilerLanguagePlugin = require("./relayCompilerLanguagePlugin");
65
+ var import_relay_compiler2 = require("relay-compiler");
66
+ var import_enableNodeWatchQueryTransform = require("./compilerTransforms/enableNodeWatchQueryTransform");
67
+ var import_annotateFragmentReferenceTransform = require("./compilerTransforms/annotateFragmentReferenceTransform");
68
+ var import_emitApolloClientConnectionTransform = require("./compilerTransforms/emitApolloClientConnectionTransform");
69
+ var import_retainConnectionDirectiveTransform = require("./compilerTransforms/retainConnectionDirectiveTransform");
70
+ function wrapTransform(transformName, transforms, wrapperTransform) {
71
+ const transformIndex = transforms.findIndex(
72
+ (transform) => transform.name === transformName
73
+ );
74
+ const wrappedTransform = transforms[transformIndex];
75
+ transforms[transformIndex] = wrapperTransform(wrappedTransform);
76
+ }
77
+ wrapTransform(
78
+ "filterDirectivesTransform",
79
+ import_relay_compiler2.IRTransforms.printTransforms,
80
+ import_retainConnectionDirectiveTransform.retainConnectionDirectiveTransform
81
+ );
82
+ wrapTransform(
83
+ "connectionTransform",
84
+ import_relay_compiler2.IRTransforms.commonTransforms,
85
+ import_emitApolloClientConnectionTransform.emitApolloClientConnectionTransform
86
+ );
87
+ function main() {
88
+ return __async(this, null, function* () {
89
+ const argv = yield yargs.scriptName("duct-tape-compiler").options({
90
+ src: {
91
+ demandOption: false,
92
+ default: ".",
93
+ type: "string"
94
+ },
95
+ exclude: {
96
+ demandOption: false,
97
+ type: "string",
98
+ array: true
99
+ },
100
+ include: {
101
+ demandOption: false,
102
+ type: "string",
103
+ array: true
104
+ },
105
+ schema: {
106
+ demandOption: true,
107
+ type: "string"
108
+ },
109
+ validate: {
110
+ demandOption: false,
111
+ default: false,
112
+ type: "boolean"
113
+ },
114
+ verbose: {
115
+ demandOption: false,
116
+ default: false,
117
+ type: "boolean"
118
+ },
119
+ watch: {
120
+ demandOption: false,
121
+ default: false,
122
+ type: "boolean"
123
+ },
124
+ watchman: {
125
+ demandOption: false,
126
+ default: true,
127
+ type: "boolean"
128
+ },
129
+ quiet: {
130
+ demandOption: false,
131
+ default: false,
132
+ type: "boolean"
133
+ },
134
+ emitDocuments: {
135
+ demandOption: false,
136
+ default: true,
137
+ type: "boolean"
138
+ },
139
+ emitNarrowObservables: {
140
+ demandOption: false,
141
+ default: true,
142
+ type: "boolean"
143
+ },
144
+ emitQueryDebugComments: {
145
+ demandOption: false,
146
+ default: false,
147
+ type: "boolean"
148
+ },
149
+ emitSupermassiveDocuments: {
150
+ demandOption: false,
151
+ default: false,
152
+ type: "boolean"
153
+ }
154
+ }).help().argv;
155
+ if (!argv.emitDocuments) {
156
+ argv.emitNarrowObservables = false;
157
+ argv.emitQueryDebugComments = false;
158
+ }
159
+ if (argv.emitNarrowObservables) {
160
+ import_relay_compiler2.IRTransforms.printTransforms.push(import_annotateFragmentReferenceTransform.annotateFragmentReferenceTransform);
161
+ import_relay_compiler2.IRTransforms.commonTransforms.unshift(import_enableNodeWatchQueryTransform.enableNodeWatchQueryTransform);
162
+ }
163
+ const ductTapeCompilerLanguagePlugin = yield (0, import_relayCompilerLanguagePlugin.pluginFactory)(argv);
164
+ return (0, import_relay_compiler.relayCompiler)(__spreadProps(__spreadValues({}, argv), {
165
+ language: ductTapeCompilerLanguagePlugin,
166
+ extensions: ["ts", "tsx"],
167
+ // FIXME: Why is this not taken from the language plugin?
168
+ include: argv.include || ["**"],
169
+ exclude: [
170
+ "**/node_modules/**",
171
+ "**/__mocks__/**",
172
+ "**/__generated__/**",
173
+ // relay-compiler will treat these as client-side schema extensions
174
+ "**/*.graphql",
175
+ ...argv.exclude || []
176
+ ],
177
+ noFutureProofEnums: true,
178
+ customScalars: {}
179
+ }));
180
+ });
181
+ }
182
+ main().catch((error) => {
183
+ console.error(error);
184
+ process.exit(1);
185
+ });
package/lib/cli.js.map ADDED
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/cli.ts"],
4
+ "sourcesContent": ["#!/usr/bin/env node\n\n/* istanbul ignore file */\n\nimport * as yargs from \"yargs\";\nimport { relayCompiler } from \"relay-compiler\";\nimport { pluginFactory } from \"./relayCompilerLanguagePlugin\";\n\n// TODO: This needs to be done here to ensure we get to mutate the transforms lists that get used.\nimport { IRTransforms } from \"relay-compiler\";\nimport { IRTransform } from \"relay-compiler/lib/core/CompilerContext\";\nimport { enableNodeWatchQueryTransform } from \"./compilerTransforms/enableNodeWatchQueryTransform\";\nimport { annotateFragmentReferenceTransform } from \"./compilerTransforms/annotateFragmentReferenceTransform\";\nimport { emitApolloClientConnectionTransform } from \"./compilerTransforms/emitApolloClientConnectionTransform\";\nimport { retainConnectionDirectiveTransform } from \"./compilerTransforms/retainConnectionDirectiveTransform\";\n\nfunction wrapTransform(\n transformName: string,\n transforms: IRTransform[],\n wrapperTransform: (wrappedTransform: IRTransform) => IRTransform,\n) {\n const transformIndex = transforms.findIndex(\n (transform) => transform.name === transformName,\n );\n const wrappedTransform = transforms[transformIndex];\n transforms[transformIndex] = wrapperTransform(wrappedTransform);\n}\n\nwrapTransform(\n \"filterDirectivesTransform\",\n IRTransforms.printTransforms,\n retainConnectionDirectiveTransform,\n);\nwrapTransform(\n \"connectionTransform\",\n IRTransforms.commonTransforms,\n emitApolloClientConnectionTransform,\n);\n\nasync function main() {\n const argv = await yargs\n .scriptName(\"duct-tape-compiler\")\n .options({\n src: {\n demandOption: false,\n default: \".\",\n type: \"string\",\n },\n exclude: {\n demandOption: false,\n type: \"string\",\n array: true,\n },\n include: {\n demandOption: false,\n type: \"string\",\n array: true,\n },\n schema: {\n demandOption: true,\n type: \"string\",\n },\n validate: {\n demandOption: false,\n default: false,\n type: \"boolean\",\n },\n verbose: {\n demandOption: false,\n default: false,\n type: \"boolean\",\n },\n watch: {\n demandOption: false,\n default: false,\n type: \"boolean\",\n },\n watchman: {\n demandOption: false,\n default: true,\n type: \"boolean\",\n },\n quiet: {\n demandOption: false,\n default: false,\n type: \"boolean\",\n },\n emitDocuments: {\n demandOption: false,\n default: true,\n type: \"boolean\",\n },\n emitNarrowObservables: {\n demandOption: false,\n default: true,\n type: \"boolean\",\n },\n emitQueryDebugComments: {\n demandOption: false,\n default: false,\n type: \"boolean\",\n },\n emitSupermassiveDocuments: {\n demandOption: false,\n default: false,\n type: \"boolean\",\n },\n })\n .help().argv;\n\n if (!argv.emitDocuments) {\n argv.emitNarrowObservables = false;\n argv.emitQueryDebugComments = false;\n }\n\n if (argv.emitNarrowObservables) {\n // TODO: Moving this up in the list might potentially optimize the query further\n IRTransforms.printTransforms.push(annotateFragmentReferenceTransform);\n IRTransforms.commonTransforms.unshift(enableNodeWatchQueryTransform);\n }\n\n const ductTapeCompilerLanguagePlugin = await pluginFactory(argv);\n\n return relayCompiler({\n ...argv,\n language: ductTapeCompilerLanguagePlugin,\n extensions: [\"ts\", \"tsx\"], // FIXME: Why is this not taken from the language plugin?\n include: argv.include || [\"**\"],\n exclude: [\n \"**/node_modules/**\",\n \"**/__mocks__/**\",\n \"**/__generated__/**\",\n // relay-compiler will treat these as client-side schema extensions\n \"**/*.graphql\",\n ...(argv.exclude || []),\n ],\n noFutureProofEnums: true,\n customScalars: {},\n });\n}\n\nmain().catch((error) => {\n console.error(error);\n process.exit(1);\n});\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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,QACd,SAAS;AAAA,QACT,MAAM;AAAA,MACR;AAAA,MACA,uBAAuB;AAAA,QACrB,cAAc;AAAA,QACd,SAAS;AAAA,QACT,MAAM;AAAA,MACR;AAAA,MACA,wBAAwB;AAAA,QACtB,cAAc;AAAA,QACd,SAAS;AAAA,QACT,MAAM;AAAA,MACR;AAAA,MACA,2BAA2B;AAAA,QACzB,cAAc;AAAA,QACd,SAAS;AAAA,QACT,MAAM;AAAA,MACR;AAAA,IACF,CAAC,EACA,KAAK,EAAE;AAEV,QAAI,CAAC,KAAK,eAAe;AACvB,WAAK,wBAAwB;AAC7B,WAAK,yBAAyB;AAAA,IAChC;AAEA,QAAI,KAAK,uBAAuB;AAE9B,0CAAa,gBAAgB,KAAK,4EAAkC;AACpE,0CAAa,iBAAiB,QAAQ,kEAA6B;AAAA,IACrE;AAEA,UAAM,iCAAiC,UAAM,kDAAc,IAAI;AAE/D,eAAO,qCAAc,iCAChB,OADgB;AAAA,MAEnB,UAAU;AAAA,MACV,YAAY,CAAC,MAAM,KAAK;AAAA;AAAA,MACxB,SAAS,KAAK,WAAW,CAAC,IAAI;AAAA,MAC9B,SAAS;AAAA,QACP;AAAA,QACA;AAAA,QACA;AAAA;AAAA,QAEA;AAAA,QACA,GAAI,KAAK,WAAW,CAAC;AAAA,MACvB;AAAA,MACA,oBAAoB;AAAA,MACpB,eAAe,CAAC;AAAA,IAClB,EAAC;AAAA,EACH;AAAA;AAEA,KAAK,EAAE,MAAM,CAAC,UAAU;AACtB,UAAQ,MAAM,KAAK;AACnB,UAAQ,KAAK,CAAC;AAChB,CAAC;",
6
+ "names": ["import_relay_compiler"]
7
+ }
package/lib/cli.mjs ADDED
@@ -0,0 +1,166 @@
1
+ #!/usr/bin/env node
2
+ var __defProp = Object.defineProperty;
3
+ var __defProps = Object.defineProperties;
4
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
5
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
8
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
9
+ var __spreadValues = (a, b) => {
10
+ for (var prop in b || (b = {}))
11
+ if (__hasOwnProp.call(b, prop))
12
+ __defNormalProp(a, prop, b[prop]);
13
+ if (__getOwnPropSymbols)
14
+ for (var prop of __getOwnPropSymbols(b)) {
15
+ if (__propIsEnum.call(b, prop))
16
+ __defNormalProp(a, prop, b[prop]);
17
+ }
18
+ return a;
19
+ };
20
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
21
+ var __async = (__this, __arguments, generator) => {
22
+ return new Promise((resolve, reject) => {
23
+ var fulfilled = (value) => {
24
+ try {
25
+ step(generator.next(value));
26
+ } catch (e) {
27
+ reject(e);
28
+ }
29
+ };
30
+ var rejected = (value) => {
31
+ try {
32
+ step(generator.throw(value));
33
+ } catch (e) {
34
+ reject(e);
35
+ }
36
+ };
37
+ var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
38
+ step((generator = generator.apply(__this, __arguments)).next());
39
+ });
40
+ };
41
+
42
+ // src/cli.ts
43
+ import * as yargs from "yargs";
44
+ import { relayCompiler } from "relay-compiler";
45
+ import { pluginFactory } from "./relayCompilerLanguagePlugin.mjs";
46
+ import { IRTransforms } from "relay-compiler";
47
+ import { enableNodeWatchQueryTransform } from "./compilerTransforms/enableNodeWatchQueryTransform.mjs";
48
+ import { annotateFragmentReferenceTransform } from "./compilerTransforms/annotateFragmentReferenceTransform.mjs";
49
+ import { emitApolloClientConnectionTransform } from "./compilerTransforms/emitApolloClientConnectionTransform.mjs";
50
+ import { retainConnectionDirectiveTransform } from "./compilerTransforms/retainConnectionDirectiveTransform.mjs";
51
+ function wrapTransform(transformName, transforms, wrapperTransform) {
52
+ const transformIndex = transforms.findIndex(
53
+ (transform) => transform.name === transformName
54
+ );
55
+ const wrappedTransform = transforms[transformIndex];
56
+ transforms[transformIndex] = wrapperTransform(wrappedTransform);
57
+ }
58
+ wrapTransform(
59
+ "filterDirectivesTransform",
60
+ IRTransforms.printTransforms,
61
+ retainConnectionDirectiveTransform
62
+ );
63
+ wrapTransform(
64
+ "connectionTransform",
65
+ IRTransforms.commonTransforms,
66
+ emitApolloClientConnectionTransform
67
+ );
68
+ function main() {
69
+ return __async(this, null, function* () {
70
+ const argv = yield yargs.scriptName("duct-tape-compiler").options({
71
+ src: {
72
+ demandOption: false,
73
+ default: ".",
74
+ type: "string"
75
+ },
76
+ exclude: {
77
+ demandOption: false,
78
+ type: "string",
79
+ array: true
80
+ },
81
+ include: {
82
+ demandOption: false,
83
+ type: "string",
84
+ array: true
85
+ },
86
+ schema: {
87
+ demandOption: true,
88
+ type: "string"
89
+ },
90
+ validate: {
91
+ demandOption: false,
92
+ default: false,
93
+ type: "boolean"
94
+ },
95
+ verbose: {
96
+ demandOption: false,
97
+ default: false,
98
+ type: "boolean"
99
+ },
100
+ watch: {
101
+ demandOption: false,
102
+ default: false,
103
+ type: "boolean"
104
+ },
105
+ watchman: {
106
+ demandOption: false,
107
+ default: true,
108
+ type: "boolean"
109
+ },
110
+ quiet: {
111
+ demandOption: false,
112
+ default: false,
113
+ type: "boolean"
114
+ },
115
+ emitDocuments: {
116
+ demandOption: false,
117
+ default: true,
118
+ type: "boolean"
119
+ },
120
+ emitNarrowObservables: {
121
+ demandOption: false,
122
+ default: true,
123
+ type: "boolean"
124
+ },
125
+ emitQueryDebugComments: {
126
+ demandOption: false,
127
+ default: false,
128
+ type: "boolean"
129
+ },
130
+ emitSupermassiveDocuments: {
131
+ demandOption: false,
132
+ default: false,
133
+ type: "boolean"
134
+ }
135
+ }).help().argv;
136
+ if (!argv.emitDocuments) {
137
+ argv.emitNarrowObservables = false;
138
+ argv.emitQueryDebugComments = false;
139
+ }
140
+ if (argv.emitNarrowObservables) {
141
+ IRTransforms.printTransforms.push(annotateFragmentReferenceTransform);
142
+ IRTransforms.commonTransforms.unshift(enableNodeWatchQueryTransform);
143
+ }
144
+ const ductTapeCompilerLanguagePlugin = yield pluginFactory(argv);
145
+ return relayCompiler(__spreadProps(__spreadValues({}, argv), {
146
+ language: ductTapeCompilerLanguagePlugin,
147
+ extensions: ["ts", "tsx"],
148
+ // FIXME: Why is this not taken from the language plugin?
149
+ include: argv.include || ["**"],
150
+ exclude: [
151
+ "**/node_modules/**",
152
+ "**/__mocks__/**",
153
+ "**/__generated__/**",
154
+ // relay-compiler will treat these as client-side schema extensions
155
+ "**/*.graphql",
156
+ ...argv.exclude || []
157
+ ],
158
+ noFutureProofEnums: true,
159
+ customScalars: {}
160
+ }));
161
+ });
162
+ }
163
+ main().catch((error) => {
164
+ console.error(error);
165
+ process.exit(1);
166
+ });
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/cli.ts"],
4
+ "sourcesContent": ["#!/usr/bin/env node\n\n/* istanbul ignore file */\n\nimport * as yargs from \"yargs\";\nimport { relayCompiler } from \"relay-compiler\";\nimport { pluginFactory } from \"./relayCompilerLanguagePlugin\";\n\n// TODO: This needs to be done here to ensure we get to mutate the transforms lists that get used.\nimport { IRTransforms } from \"relay-compiler\";\nimport { IRTransform } from \"relay-compiler/lib/core/CompilerContext\";\nimport { enableNodeWatchQueryTransform } from \"./compilerTransforms/enableNodeWatchQueryTransform\";\nimport { annotateFragmentReferenceTransform } from \"./compilerTransforms/annotateFragmentReferenceTransform\";\nimport { emitApolloClientConnectionTransform } from \"./compilerTransforms/emitApolloClientConnectionTransform\";\nimport { retainConnectionDirectiveTransform } from \"./compilerTransforms/retainConnectionDirectiveTransform\";\n\nfunction wrapTransform(\n transformName: string,\n transforms: IRTransform[],\n wrapperTransform: (wrappedTransform: IRTransform) => IRTransform,\n) {\n const transformIndex = transforms.findIndex(\n (transform) => transform.name === transformName,\n );\n const wrappedTransform = transforms[transformIndex];\n transforms[transformIndex] = wrapperTransform(wrappedTransform);\n}\n\nwrapTransform(\n \"filterDirectivesTransform\",\n IRTransforms.printTransforms,\n retainConnectionDirectiveTransform,\n);\nwrapTransform(\n \"connectionTransform\",\n IRTransforms.commonTransforms,\n emitApolloClientConnectionTransform,\n);\n\nasync function main() {\n const argv = await yargs\n .scriptName(\"duct-tape-compiler\")\n .options({\n src: {\n demandOption: false,\n default: \".\",\n type: \"string\",\n },\n exclude: {\n demandOption: false,\n type: \"string\",\n array: true,\n },\n include: {\n demandOption: false,\n type: \"string\",\n array: true,\n },\n schema: {\n demandOption: true,\n type: \"string\",\n },\n validate: {\n demandOption: false,\n default: false,\n type: \"boolean\",\n },\n verbose: {\n demandOption: false,\n default: false,\n type: \"boolean\",\n },\n watch: {\n demandOption: false,\n default: false,\n type: \"boolean\",\n },\n watchman: {\n demandOption: false,\n default: true,\n type: \"boolean\",\n },\n quiet: {\n demandOption: false,\n default: false,\n type: \"boolean\",\n },\n emitDocuments: {\n demandOption: false,\n default: true,\n type: \"boolean\",\n },\n emitNarrowObservables: {\n demandOption: false,\n default: true,\n type: \"boolean\",\n },\n emitQueryDebugComments: {\n demandOption: false,\n default: false,\n type: \"boolean\",\n },\n emitSupermassiveDocuments: {\n demandOption: false,\n default: false,\n type: \"boolean\",\n },\n })\n .help().argv;\n\n if (!argv.emitDocuments) {\n argv.emitNarrowObservables = false;\n argv.emitQueryDebugComments = false;\n }\n\n if (argv.emitNarrowObservables) {\n // TODO: Moving this up in the list might potentially optimize the query further\n IRTransforms.printTransforms.push(annotateFragmentReferenceTransform);\n IRTransforms.commonTransforms.unshift(enableNodeWatchQueryTransform);\n }\n\n const ductTapeCompilerLanguagePlugin = await pluginFactory(argv);\n\n return relayCompiler({\n ...argv,\n language: ductTapeCompilerLanguagePlugin,\n extensions: [\"ts\", \"tsx\"], // FIXME: Why is this not taken from the language plugin?\n include: argv.include || [\"**\"],\n exclude: [\n \"**/node_modules/**\",\n \"**/__mocks__/**\",\n \"**/__generated__/**\",\n // relay-compiler will treat these as client-side schema extensions\n \"**/*.graphql\",\n ...(argv.exclude || []),\n ],\n noFutureProofEnums: true,\n customScalars: {},\n });\n}\n\nmain().catch((error) => {\n console.error(error);\n process.exit(1);\n});\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAIA,YAAY,WAAW;AACvB,SAAS,qBAAqB;AAC9B,SAAS,qBAAqB;AAG9B,SAAS,oBAAoB;AAE7B,SAAS,qCAAqC;AAC9C,SAAS,0CAA0C;AACnD,SAAS,2CAA2C;AACpD,SAAS,0CAA0C;AAEnD,SAAS,cACP,eACA,YACA,kBACA;AACA,QAAM,iBAAiB,WAAW;AAAA,IAChC,CAAC,cAAc,UAAU,SAAS;AAAA,EACpC;AACA,QAAM,mBAAmB,WAAW,cAAc;AAClD,aAAW,cAAc,IAAI,iBAAiB,gBAAgB;AAChE;AAEA;AAAA,EACE;AAAA,EACA,aAAa;AAAA,EACb;AACF;AACA;AAAA,EACE;AAAA,EACA,aAAa;AAAA,EACb;AACF;AAEA,SAAe,OAAO;AAAA;AACpB,UAAM,OAAO,MACV,iBAAW,oBAAoB,EAC/B,QAAQ;AAAA,MACP,KAAK;AAAA,QACH,cAAc;AAAA,QACd,SAAS;AAAA,QACT,MAAM;AAAA,MACR;AAAA,MACA,SAAS;AAAA,QACP,cAAc;AAAA,QACd,MAAM;AAAA,QACN,OAAO;AAAA,MACT;AAAA,MACA,SAAS;AAAA,QACP,cAAc;AAAA,QACd,MAAM;AAAA,QACN,OAAO;AAAA,MACT;AAAA,MACA,QAAQ;AAAA,QACN,cAAc;AAAA,QACd,MAAM;AAAA,MACR;AAAA,MACA,UAAU;AAAA,QACR,cAAc;AAAA,QACd,SAAS;AAAA,QACT,MAAM;AAAA,MACR;AAAA,MACA,SAAS;AAAA,QACP,cAAc;AAAA,QACd,SAAS;AAAA,QACT,MAAM;AAAA,MACR;AAAA,MACA,OAAO;AAAA,QACL,cAAc;AAAA,QACd,SAAS;AAAA,QACT,MAA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
+ import { IRTransform } from "relay-compiler/lib/core/CompilerContext";
2
+ /**
3
+ * Inserts a `__fragments` selection at the place where a fragment reference
4
+ * boundary exists. This is either done in a `Node` inline fragment or directly
5
+ * on the `Query` type.
6
+ *
7
+ * This field, which is an Apollo Client client-side field as declared with the
8
+ * `@client` directive, will be used to pass context between the `use*Fragment`
9
+ * hooks. (Currently this is limited to request variables.) The data for this
10
+ * field is resolved by the `fragmentReferencesFieldPolicy` function.
11
+ */
12
+ export declare const annotateFragmentReferenceTransform: IRTransform;
13
+ //# sourceMappingURL=annotateFragmentReferenceTransform.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"annotateFragmentReferenceTransform.d.ts","sourceRoot":"","sources":["../../src/compilerTransforms/annotateFragmentReferenceTransform.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,WAAW,EAAE,MAAM,yCAAyC,CAAC;AAgCtE;;;;;;;;;GASG;AACH,eAAO,MAAM,kCAAkC,EAAE,WAehD,CAAC"}
@@ -0,0 +1,98 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __defProps = Object.defineProperties;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
6
+ var __getOwnPropNames = Object.getOwnPropertyNames;
7
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
8
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
9
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
10
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
11
+ var __spreadValues = (a, b) => {
12
+ for (var prop in b || (b = {}))
13
+ if (__hasOwnProp.call(b, prop))
14
+ __defNormalProp(a, prop, b[prop]);
15
+ if (__getOwnPropSymbols)
16
+ for (var prop of __getOwnPropSymbols(b)) {
17
+ if (__propIsEnum.call(b, prop))
18
+ __defNormalProp(a, prop, b[prop]);
19
+ }
20
+ return a;
21
+ };
22
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
23
+ var __export = (target, all) => {
24
+ for (var name in all)
25
+ __defProp(target, name, { get: all[name], enumerable: true });
26
+ };
27
+ var __copyProps = (to, from, except, desc) => {
28
+ if (from && typeof from === "object" || typeof from === "function") {
29
+ for (let key of __getOwnPropNames(from))
30
+ if (!__hasOwnProp.call(to, key) && key !== except)
31
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
32
+ }
33
+ return to;
34
+ };
35
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
36
+ var annotateFragmentReferenceTransform_exports = {};
37
+ __export(annotateFragmentReferenceTransform_exports, {
38
+ annotateFragmentReferenceTransform: () => annotateFragmentReferenceTransform
39
+ });
40
+ module.exports = __toCommonJS(annotateFragmentReferenceTransform_exports);
41
+ var import_IRVisitor = require("relay-compiler/lib/core/IRVisitor");
42
+ var import_utils = require("./utils");
43
+ const FRAGMENTS_SELECTION = {
44
+ kind: "ScalarField",
45
+ name: "__fragments",
46
+ alias: "__fragments",
47
+ type: "String!",
48
+ directives: [
49
+ {
50
+ kind: "Directive",
51
+ name: "client",
52
+ args: [],
53
+ loc: { kind: "Generated" },
54
+ metadata: void 0
55
+ }
56
+ ],
57
+ args: [],
58
+ loc: { kind: "Generated" },
59
+ metadata: void 0
60
+ };
61
+ const FRAGMENTS_ON_NODE_SELECTION = {
62
+ kind: "InlineFragment",
63
+ typeCondition: "Node",
64
+ selections: [FRAGMENTS_SELECTION],
65
+ directives: [],
66
+ loc: { kind: "Generated" },
67
+ metadata: void 0
68
+ };
69
+ const annotateFragmentReferenceTransform = (context) => {
70
+ const visitor = visitNodeWithSelections.bind(null, context);
71
+ let nextContext = context;
72
+ context.forEachDocument((document) => {
73
+ const nextDocument = (0, import_IRVisitor.visit)(document, {
74
+ Root: visitor,
75
+ Fragment: visitor,
76
+ InlineFragment: visitor,
77
+ LinkedField: visitor
78
+ });
79
+ nextContext = nextContext.replace(nextDocument);
80
+ });
81
+ return nextContext;
82
+ };
83
+ function visitNodeWithSelections(context, node) {
84
+ for (const selection of node.selections) {
85
+ if (selection.kind === "FragmentSpread") {
86
+ const fragment = context.getFragment(selection.name);
87
+ if ((0, import_utils.implementsNodeInterface)(context, fragment)) {
88
+ return __spreadProps(__spreadValues({}, node), {
89
+ selections: [...node.selections, FRAGMENTS_ON_NODE_SELECTION]
90
+ });
91
+ } else if (fragment.type === context.getSchema().getQueryType()) {
92
+ return __spreadProps(__spreadValues({}, node), {
93
+ selections: [...node.selections, FRAGMENTS_SELECTION]
94
+ });
95
+ }
96
+ }
97
+ }
98
+ }
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/compilerTransforms/annotateFragmentReferenceTransform.ts"],
4
+ "sourcesContent": ["import {\n CompilerContext,\n Fragment,\n InlineFragment,\n LinkedField,\n Root,\n ScalarField,\n} from \"relay-compiler\";\nimport { IRTransform } from \"relay-compiler/lib/core/CompilerContext\";\nimport { visit } from \"relay-compiler/lib/core/IRVisitor\";\nimport { implementsNodeInterface } from \"./utils\";\n\nconst FRAGMENTS_SELECTION: ScalarField = {\n kind: \"ScalarField\",\n name: \"__fragments\",\n alias: \"__fragments\",\n type: \"String!\",\n directives: [\n {\n kind: \"Directive\",\n name: \"client\",\n args: [],\n loc: { kind: \"Generated\" },\n metadata: undefined,\n },\n ],\n args: [],\n loc: { kind: \"Generated\" },\n metadata: undefined,\n};\n\nconst FRAGMENTS_ON_NODE_SELECTION: InlineFragment = {\n kind: \"InlineFragment\",\n typeCondition: \"Node\",\n selections: [FRAGMENTS_SELECTION],\n directives: [],\n loc: { kind: \"Generated\" },\n metadata: undefined,\n};\n\n/**\n * Inserts a `__fragments` selection at the place where a fragment reference\n * boundary exists. This is either done in a `Node` inline fragment or directly\n * on the `Query` type.\n *\n * This field, which is an Apollo Client client-side field as declared with the\n * `@client` directive, will be used to pass context between the `use*Fragment`\n * hooks. (Currently this is limited to request variables.) The data for this\n * field is resolved by the `fragmentReferencesFieldPolicy` function.\n */\nexport const annotateFragmentReferenceTransform: IRTransform = (context) => {\n const visitor = visitNodeWithSelections.bind(null, context);\n let nextContext = context;\n\n context.forEachDocument((document) => {\n const nextDocument = visit(document, {\n Root: visitor,\n Fragment: visitor,\n InlineFragment: visitor,\n LinkedField: visitor,\n });\n nextContext = nextContext.replace(nextDocument);\n });\n\n return nextContext;\n};\n\nfunction visitNodeWithSelections(\n context: CompilerContext,\n node: Root | Fragment | InlineFragment | LinkedField\n): Root | Fragment | InlineFragment | LinkedField | undefined {\n for (const selection of node.selections) {\n if (selection.kind === \"FragmentSpread\") {\n const fragment = context.getFragment(selection.name);\n if (implementsNodeInterface(context, fragment)) {\n return {\n ...node,\n selections: [...node.selections, FRAGMENTS_ON_NODE_SELECTION],\n };\n } else if (fragment.type === context.getSchema().getQueryType()) {\n return {\n ...node,\n selections: [...node.selections, FRAGMENTS_SELECTION],\n };\n }\n }\n }\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AASA,uBAAsB;AACtB,mBAAwC;AAExC,MAAM,sBAAmC;AAAA,EACvC,MAAM;AAAA,EACN,MAAM;AAAA,EACN,OAAO;AAAA,EACP,MAAM;AAAA,EACN,YAAY;AAAA,IACV;AAAA,MACE,MAAM;AAAA,MACN,MAAM;AAAA,MACN,MAAM,CAAC;AAAA,MACP,KAAK,EAAE,MAAM,YAAY;AAAA,MACzB,UAAU;AAAA,IACZ;AAAA,EACF;AAAA,EACA,MAAM,CAAC;AAAA,EACP,KAAK,EAAE,MAAM,YAAY;AAAA,EACzB,UAAU;AACZ;AAEA,MAAM,8BAA8C;AAAA,EAClD,MAAM;AAAA,EACN,eAAe;AAAA,EACf,YAAY,CAAC,mBAAmB;AAAA,EAChC,YAAY,CAAC;AAAA,EACb,KAAK,EAAE,MA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