@stepzen/transpiler 0.0.0-experimental-20221114-610843f6

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 (103) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +1 -0
  3. package/lib/actions/configure.d.ts +12 -0
  4. package/lib/actions/configure.d.ts.map +1 -0
  5. package/lib/actions/configure.js +134 -0
  6. package/lib/actions/configure.js.map +1 -0
  7. package/lib/actions/lint.d.ts +5 -0
  8. package/lib/actions/lint.d.ts.map +1 -0
  9. package/lib/actions/lint.js +31 -0
  10. package/lib/actions/lint.js.map +1 -0
  11. package/lib/actions/merge.d.ts +15 -0
  12. package/lib/actions/merge.d.ts.map +1 -0
  13. package/lib/actions/merge.js +177 -0
  14. package/lib/actions/merge.js.map +1 -0
  15. package/lib/actions/print.d.ts +4 -0
  16. package/lib/actions/print.d.ts.map +1 -0
  17. package/lib/actions/print.js +10 -0
  18. package/lib/actions/print.js.map +1 -0
  19. package/lib/actions/stitch.d.ts +3 -0
  20. package/lib/actions/stitch.d.ts.map +1 -0
  21. package/lib/actions/stitch.js +96 -0
  22. package/lib/actions/stitch.js.map +1 -0
  23. package/lib/actions/transpile.d.ts +17 -0
  24. package/lib/actions/transpile.d.ts.map +1 -0
  25. package/lib/actions/transpile.js +62 -0
  26. package/lib/actions/transpile.js.map +1 -0
  27. package/lib/actions/validate.d.ts +5 -0
  28. package/lib/actions/validate.d.ts.map +1 -0
  29. package/lib/actions/validate.js +40 -0
  30. package/lib/actions/validate.js.map +1 -0
  31. package/lib/index.d.ts +8 -0
  32. package/lib/index.d.ts.map +1 -0
  33. package/lib/index.js +18 -0
  34. package/lib/index.js.map +1 -0
  35. package/lib/mutations/config/envvars.d.ts +3 -0
  36. package/lib/mutations/config/envvars.d.ts.map +1 -0
  37. package/lib/mutations/config/envvars.js +27 -0
  38. package/lib/mutations/config/envvars.js.map +1 -0
  39. package/lib/mutations/config/index.d.ts +3 -0
  40. package/lib/mutations/config/index.d.ts.map +1 -0
  41. package/lib/mutations/config/index.js +5 -0
  42. package/lib/mutations/config/index.js.map +1 -0
  43. package/lib/utils/constants.d.ts +4 -0
  44. package/lib/utils/constants.d.ts.map +1 -0
  45. package/lib/utils/constants.js +19 -0
  46. package/lib/utils/constants.js.map +1 -0
  47. package/lib/utils/copy-workspace-content.d.ts +15 -0
  48. package/lib/utils/copy-workspace-content.d.ts.map +1 -0
  49. package/lib/utils/copy-workspace-content.js +46 -0
  50. package/lib/utils/copy-workspace-content.js.map +1 -0
  51. package/lib/utils/dedupe-query-and-mutation-types.d.ts +3 -0
  52. package/lib/utils/dedupe-query-and-mutation-types.d.ts.map +1 -0
  53. package/lib/utils/dedupe-query-and-mutation-types.js +68 -0
  54. package/lib/utils/dedupe-query-and-mutation-types.js.map +1 -0
  55. package/lib/utils/ensure-query-and-mutation-types.d.ts +4 -0
  56. package/lib/utils/ensure-query-and-mutation-types.d.ts.map +1 -0
  57. package/lib/utils/ensure-query-and-mutation-types.js +49 -0
  58. package/lib/utils/ensure-query-and-mutation-types.js.map +1 -0
  59. package/lib/utils/graphql-helpers.d.ts +5 -0
  60. package/lib/utils/graphql-helpers.d.ts.map +1 -0
  61. package/lib/utils/graphql-helpers.js +6 -0
  62. package/lib/utils/graphql-helpers.js.map +1 -0
  63. package/lib/utils/merge-helpers.d.ts +13 -0
  64. package/lib/utils/merge-helpers.d.ts.map +1 -0
  65. package/lib/utils/merge-helpers.js +180 -0
  66. package/lib/utils/merge-helpers.js.map +1 -0
  67. package/lib/utils/set-files-in-sdl.d.ts +7 -0
  68. package/lib/utils/set-files-in-sdl.d.ts.map +1 -0
  69. package/lib/utils/set-files-in-sdl.js +122 -0
  70. package/lib/utils/set-files-in-sdl.js.map +1 -0
  71. package/lib/utils/strip-empty-queries-and-mutations.d.ts +4 -0
  72. package/lib/utils/strip-empty-queries-and-mutations.d.ts.map +1 -0
  73. package/lib/utils/strip-empty-queries-and-mutations.js +44 -0
  74. package/lib/utils/strip-empty-queries-and-mutations.js.map +1 -0
  75. package/lib/validators/config-exists/index.d.ts +4 -0
  76. package/lib/validators/config-exists/index.d.ts.map +1 -0
  77. package/lib/validators/config-exists/index.js +46 -0
  78. package/lib/validators/config-exists/index.js.map +1 -0
  79. package/lib/validators/index.d.ts +3 -0
  80. package/lib/validators/index.d.ts.map +1 -0
  81. package/lib/validators/index.js +5 -0
  82. package/lib/validators/index.js.map +1 -0
  83. package/package.json +57 -0
  84. package/src/actions/configure.ts +176 -0
  85. package/src/actions/lint.ts +44 -0
  86. package/src/actions/merge.ts +243 -0
  87. package/src/actions/print.ts +8 -0
  88. package/src/actions/stitch.ts +113 -0
  89. package/src/actions/transpile.ts +74 -0
  90. package/src/actions/validate.ts +54 -0
  91. package/src/index.ts +7 -0
  92. package/src/mutations/config/envvars.ts +33 -0
  93. package/src/mutations/config/index.ts +3 -0
  94. package/src/utils/constants.ts +22 -0
  95. package/src/utils/copy-workspace-content.ts +48 -0
  96. package/src/utils/dedupe-query-and-mutation-types.ts +74 -0
  97. package/src/utils/ensure-query-and-mutation-types.ts +52 -0
  98. package/src/utils/graphql-helpers.ts +3 -0
  99. package/src/utils/merge-helpers.ts +205 -0
  100. package/src/utils/set-files-in-sdl.ts +156 -0
  101. package/src/utils/strip-empty-queries-and-mutations.ts +43 -0
  102. package/src/validators/config-exists/index.ts +54 -0
  103. package/src/validators/index.ts +3 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2021, 2022 StepZen
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1 @@
1
+ # @stepzen/transpiler
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Get effective StepZen endpoint configuration for a directory:
3
+ * Traverse the file system starting at `source` and
4
+ * - merge all `config.yaml` files (discarding unrecognized properties)
5
+ * - merge all `config` sections from `stepzen.config.json` files
6
+ *
7
+ * Possibly, interactive: if `silent` is `false` and there are non-empty
8
+ * `config` sections in `stepzen.config.json` files.
9
+ */
10
+ declare const _default: (source: string, silent?: boolean, answers?: any) => Promise<string | false>;
11
+ export default _default;
12
+ //# sourceMappingURL=configure.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"configure.d.ts","sourceRoot":"","sources":["../../src/actions/configure.ts"],"names":[],"mappings":"AAOA;;;;;;;;GAQG;iCAC2B,MAAM,8BAA2B,GAAG;AAAlE,wBA+JC"}
@@ -0,0 +1,134 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const debug = require("debug");
4
+ const fs = require("fs-extra");
5
+ const glob = require("glob");
6
+ const inquirer = require("inquirer");
7
+ const path = require("path");
8
+ const yaml = require("yaml");
9
+ /**
10
+ * Get effective StepZen endpoint configuration for a directory:
11
+ * Traverse the file system starting at `source` and
12
+ * - merge all `config.yaml` files (discarding unrecognized properties)
13
+ * - merge all `config` sections from `stepzen.config.json` files
14
+ *
15
+ * Possibly, interactive: if `silent` is `false` and there are non-empty
16
+ * `config` sections in `stepzen.config.json` files.
17
+ */
18
+ exports.default = async (source, silent = false, answers = {}) => {
19
+ const config = {
20
+ configurationset: [],
21
+ ruleset: [],
22
+ access: undefined,
23
+ deployment: undefined,
24
+ };
25
+ debug('stepzen:transpiler:config')(`getting effective config for ${source}`);
26
+ // Now let's parse and add any config.yamls
27
+ let configYamlCount = 0;
28
+ for (const y of glob.sync('**/config.yaml', { cwd: source })) {
29
+ const filePath = path.join(source, y);
30
+ const file = fs.readFileSync(filePath, 'utf8');
31
+ let asYAML;
32
+ try {
33
+ asYAML = yaml.parse(file, { schema: 'failsafe' });
34
+ }
35
+ catch (error) {
36
+ debug('stepzen:transpiler:config')(`Ignoring an invalid config.yaml ${filePath}.` +
37
+ ` YAML parse error: ${error}`);
38
+ continue;
39
+ }
40
+ if (!asYAML) {
41
+ debug('stepzen:transpiler:config')(`ignoring an empty config.yaml ${filePath}`);
42
+ continue;
43
+ }
44
+ configYamlCount += 1;
45
+ debug('stepzen:transpiler:config')(`adding config.yaml ${filePath}:\n${JSON.stringify(asYAML, null, 2)}`);
46
+ // strip away any non-recognized properties
47
+ Object.entries(asYAML).forEach(([keyAsAny, value]) => {
48
+ if (Object.prototype.hasOwnProperty.call(config, keyAsAny)) {
49
+ const key = keyAsAny;
50
+ config[key] = Array.isArray(config[key])
51
+ ? config[key].concat(value)
52
+ : value;
53
+ }
54
+ else {
55
+ debug('stepzen:transpiler:config')(`ignoring unrecognized config property ${keyAsAny}`);
56
+ }
57
+ });
58
+ }
59
+ debug('stepzen:transpiler:config')(`done adding **/config.yaml files (processed: ${configYamlCount})`);
60
+ // Now let's build configs from questions
61
+ let configJsonCount = 0;
62
+ for await (const j of glob.sync('**/stepzen.config.json', {
63
+ cwd: source,
64
+ })) {
65
+ const filePath = path.join(source, j);
66
+ const file = fs.readFileSync(filePath, 'utf8');
67
+ const asJSON = JSON.parse(file);
68
+ configJsonCount += 1;
69
+ debug('stepzen:transpiler:config')(`adding stepzen.config.json ${filePath}:` +
70
+ `\n${JSON.stringify(asJSON, null, 2)}`);
71
+ if (asJSON.config?.questions) {
72
+ for await (const question of asJSON.config?.questions) {
73
+ const [name, key] = question.name.split('.');
74
+ let answer = {};
75
+ if (silent) {
76
+ answer = {
77
+ [name]: { [key]: answers[name]?.[key] ? answers[name]?.[key] : '' },
78
+ };
79
+ }
80
+ else {
81
+ answer = await inquirer.prompt({
82
+ type: 'password',
83
+ ...question,
84
+ });
85
+ }
86
+ const configset = {
87
+ configuration: {
88
+ name,
89
+ [key]: answer[name][key],
90
+ },
91
+ };
92
+ debug('stepzen:transpiler:config')(`question: ${JSON.stringify(question, null, 2)}`);
93
+ debug('stepzen:transpiler:config')(`answer: ${JSON.stringify(configset, null, 2)}`);
94
+ config.configurationset.push({ ...configset });
95
+ }
96
+ }
97
+ }
98
+ debug('stepzen:transpiler:config')(`done adding **/stepzen.config.json files (processed: ${configJsonCount})`);
99
+ debug('stepzen:transpiler:config')(`combined content of all config files:` +
100
+ `\n${JSON.stringify(config, null, 2)}`);
101
+ // OK now let's collate everything into shared configurations
102
+ const configurationset = [];
103
+ {
104
+ const obj = {};
105
+ for (const c of config.configurationset) {
106
+ const name = c.configuration.name;
107
+ if (!obj[name])
108
+ obj[name] = {};
109
+ for (const [key, value] of Object.entries(c.configuration)) {
110
+ if (key === name)
111
+ continue;
112
+ obj[name][key] = value;
113
+ }
114
+ }
115
+ for (const configuration of Object.keys(obj)) {
116
+ configurationset.push({
117
+ configuration: { ...obj[configuration] },
118
+ });
119
+ }
120
+ }
121
+ // Now convert back into StepZen format
122
+ const structured = Object.fromEntries(Object.entries({ ...config, configurationset }).filter(([_key, value]) => Array.isArray(value) ? value.length > 0 : value !== undefined));
123
+ // Return YAML, if appropriate
124
+ if (Object.keys(structured).length > 0) {
125
+ const configYamlStr = yaml.stringify(structured);
126
+ debug('stepzen:transpiler:config')(`effective config:\n${configYamlStr}`);
127
+ return configYamlStr;
128
+ }
129
+ debug('stepzen:transpiler:config')(`Could not find any of the supported properties in the config:` +
130
+ ` [ '${Object.keys(config).join(`', '`)}' ].` +
131
+ ` Retuning 'false' meaning 'effective config is empty'.`);
132
+ return false;
133
+ };
134
+ //# sourceMappingURL=configure.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"configure.js","sourceRoot":"","sources":["../../src/actions/configure.ts"],"names":[],"mappings":";;AAAA,+BAA8B;AAC9B,+BAA8B;AAC9B,6BAA4B;AAC5B,qCAAoC;AACpC,6BAA4B;AAC5B,6BAA4B;AAE5B;;;;;;;;GAQG;AACH,kBAAe,KAAK,EAAE,MAAc,EAAE,MAAM,GAAG,KAAK,EAAE,UAAe,EAAE,EAAE,EAAE;IACzE,MAAM,MAAM,GAAG;QACb,gBAAgB,EAAE,EAAW;QAC7B,OAAO,EAAE,EAAW;QACpB,MAAM,EAAE,SAAgB;QACxB,UAAU,EAAE,SAAgB;KAC7B,CAAA;IAED,KAAK,CAAC,2BAA2B,CAAC,CAAC,gCAAgC,MAAM,EAAE,CAAC,CAAA;IAE5E,2CAA2C;IAC3C,IAAI,eAAe,GAAG,CAAC,CAAA;IACvB,KAAK,MAAM,CAAC,IAAI,IAAI,CAAC,IAAI,CAAC,gBAAgB,EAAE,EAAC,GAAG,EAAE,MAAM,EAAC,CAAC,EAAE;QAC1D,MAAM,QAAQ,GAAG,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC,CAAA;QAErC,MAAM,IAAI,GAAG,EAAE,CAAC,YAAY,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAA;QAC9C,IAAI,MAAM,CAAA;QACV,IAAI;YACF,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,EAAC,MAAM,EAAE,UAAU,EAAC,CAAC,CAAA;SAChD;QAAC,OAAO,KAAK,EAAE;YACd,KAAK,CAAC,2BAA2B,CAAC,CAChC,mCAAmC,QAAQ,GAAG;gBAC5C,sBAAsB,KAAK,EAAE,CAChC,C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AAC,OAAO,CAAC,EAAC,GAAG,MAAM,EAAE,gBAAgB,EAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,EAAE,KAAK,CAAC,EAAE,EAAE,CACrE,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,KAAK,SAAS,CAC9D,CACF,CAAA;IAED,8BAA8B;IAC9B,IAAI,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,MAAM,GAAG,CAAC,EAAE;QACtC,MAAM,aAAa,GAAG,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,CAAA;QAChD,KAAK,CAAC,2BAA2B,CAAC,CAAC,sBAAsB,aAAa,EAAE,CAAC,CAAA;QACzE,OAAO,aAAa,CAAA;KACrB;IAED,KAAK,CAAC,2BAA2B,CAAC,CAChC,+DAA+D;QAC7D,OAAO,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,MAAM;QAC7C,wDAAwD,CAC3D,CAAA;IACD,OAAO,KAAK,CAAA;AACd,CAAC,CAAA"}
@@ -0,0 +1,5 @@
1
+ declare const _default: (source: string, options?: {
2
+ extensions: string;
3
+ }) => Promise<void>;
4
+ export default _default;
5
+ //# sourceMappingURL=lint.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lint.d.ts","sourceRoot":"","sources":["../../src/actions/lint.ts"],"names":[],"mappings":"iCASU,MAAM,YACL;IACP,UAAU,EAAE,MAAM,CAAA;CACnB;AAJH,wBAmCC"}
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const fs = require("fs-extra");
4
+ const os = require("os");
5
+ const path = require("path");
6
+ const shell = require("shelljs");
7
+ const stitch_1 = require("../actions/stitch");
8
+ const merge_helpers_1 = require("../utils/merge-helpers");
9
+ exports.default = async (source, options = {
10
+ extensions: '',
11
+ }) => {
12
+ if (!fs.existsSync(source)) {
13
+ throw new Error(`Cannot find source directory ${source}`);
14
+ }
15
+ let extensions = options.extensions;
16
+ if (!extensions) {
17
+ extensions = await (0, merge_helpers_1.getExtensions)();
18
+ }
19
+ const stitched = (0, stitch_1.default)(source);
20
+ const index = path.join(stitched, 'index.graphql');
21
+ const graphql = fs.readFileSync(index, 'utf8');
22
+ const tmp = path.join(os.tmpdir(), `stepzen-lint-${Date.now()}`);
23
+ fs.ensureDirSync(tmp);
24
+ const lintFile = path.join(tmp, 'index.graphql');
25
+ fs.writeFileSync(lintFile, `${extensions}${os.EOL}${os.EOL}${graphql}`);
26
+ shell.exec(`npx graphql-schema-linter ${lintFile}`, { silent: true }, (code, stdout, stderr) => {
27
+ console.log(stdout);
28
+ fs.removeSync(tmp);
29
+ });
30
+ };
31
+ //# sourceMappingURL=lint.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lint.js","sourceRoot":"","sources":["../../src/actions/lint.ts"],"names":[],"mappings":";;AAAA,+BAA8B;AAC9B,yBAAwB;AACxB,6BAA4B;AAC5B,iCAAgC;AAEhC,8CAAsC;AACtC,0DAAoD;AAEpD,kBAAe,KAAK,EAClB,MAAc,EACd,UAEI;IACF,UAAU,EAAE,EAAE;CACf,EACD,EAAE;IACF,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,MAAM,CAAC,EAAE;QAC1B,MAAM,IAAI,KAAK,CAAC,gCAAgC,MAAM,EAAE,CAAC,CAAA;KAC1D;IAED,IAAI,UAAU,GAAG,OAAO,CAAC,UAAU,CAAA;IAEnC,IAAI,CAAC,UAAU,EAAE;QACf,UAAU,GAAG,MAAM,IAAA,6BAAa,GAAE,CAAA;KACnC;IAED,MAAM,QAAQ,GAAG,IAAA,gBAAM,EAAC,MAAM,CAAC,CAAA;IAC/B,MAAM,KAAK,GAAG,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,eAAe,CAAC,CAAA;IAClD,MAAM,OAAO,GAAG,EAAE,CAAC,YAAY,CAAC,KAAK,EAAE,MAAM,CAAC,CAAA;IAE9C,MAAM,GAAG,GAAG,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,MAAM,EAAE,EAAE,gBAAgB,IAAI,CAAC,GAAG,EAAE,EAAE,CAAC,CAAA;IAChE,EAAE,CAAC,aAAa,CAAC,GAAG,CAAC,CAAA;IACrB,MAAM,QAAQ,GAAG,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,eAAe,CAAC,CAAA;IAChD,EAAE,CAAC,aAAa,CAAC,QAAQ,EAAE,GAAG,UAAU,GAAG,EAAE,CAAC,GAAG,GAAG,EAAE,CAAC,GAAG,GAAG,OAAO,EAAE,CAAC,CAAA;IAEvE,KAAK,CAAC,IAAI,CACR,6BAA6B,QAAQ,EAAE,EACvC,EAAC,MAAM,EAAE,IAAI,EAAC,EACd,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,EAAE;QACvB,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,CAAA;QACnB,EAAE,CAAC,UAAU,CAAC,GAAG,CAAC,CAAA;IACpB,CAAC,CACF,CAAA;AACH,CAAC,CAAA"}
@@ -0,0 +1,15 @@
1
+ declare const _default: (original: string, imported: {
2
+ name: string;
3
+ source: string;
4
+ }, options?: {
5
+ answers: any;
6
+ output: string | null;
7
+ silent: boolean;
8
+ /** when `false` merge only covers config files and updates @sdl directrive */
9
+ mergeTypes?: boolean;
10
+ /** merge behaviour when a schema with the given name exists in the source */
11
+ onConflict?: 'overwrite' | 'append';
12
+ extensions?: string;
13
+ }) => Promise<string>;
14
+ export default _default;
15
+ //# sourceMappingURL=merge.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"merge.d.ts","sourceRoot":"","sources":["../../src/actions/merge.ts"],"names":[],"mappings":"mCA4CY,MAAM,YACN;IACR,MAAM,MAAM,CAAA;IACZ,MAAM,EAAE,MAAM,CAAA;CACf,YACQ;IACP,OAAO,EAAE,GAAG,CAAA;IACZ,MAAM,EAAE,MAAM,GAAG,IAAI,CAAA;IACrB,MAAM,EAAE,OAAO,CAAA;IACf,8EAA8E;IAC9E,UAAU,CAAC,EAAE,OAAO,CAAA;IACpB,6EAA6E;IAC7E,UAAU,CAAC,EAAE,WAAW,GAAG,QAAQ,CAAA;IACnC,UAAU,CAAC,EAAE,MAAM,CAAA;CACpB;AAfH,wBAuMC"}
@@ -0,0 +1,177 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const fs = require("fs-extra");
4
+ const glob = require("glob");
5
+ const merge_1 = require("@graphql-tools/merge");
6
+ const graphql_1 = require("graphql");
7
+ const os = require("os");
8
+ const path = require("path");
9
+ const merge_helpers_1 = require("../utils/merge-helpers");
10
+ const print_1 = require("./print");
11
+ const set_files_in_sdl_1 = require("../utils/set-files-in-sdl");
12
+ const strip_empty_queries_and_mutations_1 = require("../utils/strip-empty-queries-and-mutations");
13
+ const copy_workspace_content_1 = require("../utils/copy-workspace-content");
14
+ const constants_1 = require("../utils/constants");
15
+ // It's safe to use this special placeholder value here: in case of a failure
16
+ // in the merge / import process it will not reach the workspace folder.
17
+ // All intermediary steps are carried out in a temp folder, and only when all
18
+ // merge / import steps are completed, the result it copied over to the
19
+ // workspace folder.
20
+ const BLANK_INDEX_TEMPLATE = `
21
+ schema @sdl(files: ["${constants_1.ALL_GRAPHQL_FILES}"]) {
22
+ query: Query
23
+ }
24
+ `.trim();
25
+ const BLANK_QUERY_TYPE = `
26
+ type Query {
27
+ __query: String
28
+ }
29
+ `.trim();
30
+ exports.default = async (original, imported, options = {
31
+ answers: {},
32
+ output: null,
33
+ silent: false,
34
+ mergeTypes: true,
35
+ onConflict: 'append',
36
+ extensions: '',
37
+ }) => {
38
+ // Make sure there is an output directory
39
+ if (!options.answers)
40
+ options.answers = {};
41
+ if (!options.output)
42
+ options.output = path.join(os.tmpdir(), `stepzen-tmp-${Date.now()}`);
43
+ if (!options.silent)
44
+ options.silent = false;
45
+ if (options.mergeTypes === undefined)
46
+ options.mergeTypes = true;
47
+ if (options.onConflict === undefined)
48
+ options.onConflict = 'append';
49
+ if (!options.extensions)
50
+ options.extensions = await (0, merge_helpers_1.getExtensions)();
51
+ // To stop things like
52
+ // C:\Users\Darren\AppData\Local\Temp\stepzen-tmp-config-1638293497187\C:\Users\Darren\AppData\Local\Temp\stepzen-tmp-1638293496286
53
+ options.output = (0, merge_helpers_1.dedupeTempFolder)(options.output);
54
+ // Ensure original, importing and output directories exist
55
+ if (!fs.existsSync(original))
56
+ throw new Error(`Cannot find original directory ${original}`);
57
+ if (!fs.existsSync(imported.source))
58
+ throw new Error(`Cannot find imported source directory ${imported.source}`);
59
+ fs.ensureDirSync(options.output);
60
+ // Copy the original into the output.
61
+ (0, copy_workspace_content_1.default)(original, options.output);
62
+ // Ensure an index.graphql exists
63
+ const outputIndex = path.join(options.output, 'index.graphql');
64
+ if (!fs.existsSync(outputIndex)) {
65
+ fs.writeFileSync(outputIndex, options.mergeTypes
66
+ ? // (2022-03-09, vluakshov) Not sure what'd break without the
67
+ // blank Query type, but that's why I do not want to remove it
68
+ // from the default code path.
69
+ BLANK_INDEX_TEMPLATE + BLANK_QUERY_TYPE
70
+ : // In the non-default code path that does NOT merge types
71
+ // the blank Query type causes explicit problems
72
+ // (https://github.com/steprz/stepzen-cli/issues/482).
73
+ BLANK_INDEX_TEMPLATE);
74
+ }
75
+ const targetSubfolder = options.onConflict === 'overwrite'
76
+ ? imported.name
77
+ : (0, merge_helpers_1.findNextAvailableSubfolder)(original, imported.name);
78
+ let importedGraphQLFiles = [];
79
+ if (options.mergeTypes) {
80
+ const merged = (0, merge_1.mergeTypeDefs)([
81
+ await (0, merge_helpers_1.getSchema)(options.output, options.extensions),
82
+ await (0, merge_helpers_1.getSchema)(imported.source, options.extensions),
83
+ ]);
84
+ let queries = [];
85
+ let mutations = [];
86
+ let types = [];
87
+ (0, graphql_1.visit)(merged, {
88
+ ObjectTypeDefinition(node) {
89
+ if (node.name.value === 'Query')
90
+ queries = queries.concat(node.fields);
91
+ else if (node.name.value === 'Mutation')
92
+ mutations = mutations.concat(node.fields);
93
+ else
94
+ types = types.concat(node);
95
+ },
96
+ });
97
+ const details = {
98
+ original: glob.sync('**/*.graphql', { cwd: options.output }).map(file => {
99
+ const content = fs.readFileSync(`${options.output}/${file}`, 'utf8');
100
+ return { ast: (0, graphql_1.parse)(content), file };
101
+ }),
102
+ imported: glob.sync('**/*.graphql', { cwd: imported.source }).map(file => {
103
+ const content = fs.readFileSync(`${imported.source}/${file}`, 'utf8');
104
+ return { ast: (0, graphql_1.parse)(content), file };
105
+ }),
106
+ };
107
+ // Merge Queries and Mutations
108
+ for (const type of [...queries, ...mutations]) {
109
+ const isInOriginal = (0, merge_helpers_1.findQueryMutationInSchema)(type.name.value, details.original);
110
+ const isInImported = (0, merge_helpers_1.findQueryMutationInSchema)(type.name.value, details.imported);
111
+ if (isInOriginal && isInImported) {
112
+ details.original = (0, merge_helpers_1.mergeQueryMutationIntoSchema)(type, details.original);
113
+ details.imported = (0, merge_helpers_1.removeQueryMutationFromSchema)(type.name.value, details.imported);
114
+ }
115
+ }
116
+ // Merge Types
117
+ for (const type of types) {
118
+ const isInOriginal = (0, merge_helpers_1.findTypeInSchema)(type.name.value, details.original);
119
+ const isInImported = (0, merge_helpers_1.findTypeInSchema)(type.name.value, details.imported);
120
+ if (isInOriginal && isInImported) {
121
+ details.original = (0, merge_helpers_1.mergeTypeIntoSchema)(type, details.original);
122
+ details.imported = (0, merge_helpers_1.removeTypeFromSchema)(type.name.value, details.imported);
123
+ }
124
+ }
125
+ // Clean up the files. Remove empty Query / Mutation types, filter out now-empty files
126
+ const cleaned = {
127
+ original: details.original
128
+ .map(item => ({
129
+ ...item,
130
+ ast: (0, strip_empty_queries_and_mutations_1.default)(item.ast),
131
+ }))
132
+ .filter(item => item.ast.definitions.length > 0),
133
+ imported: details.imported
134
+ .map(item => ({
135
+ ...item,
136
+ ast: (0, strip_empty_queries_and_mutations_1.default)(item.ast),
137
+ }))
138
+ .filter(item => item.ast.definitions.length > 0),
139
+ };
140
+ // Write the files to the output directory
141
+ cleaned.original.forEach((a) => {
142
+ // eslint-disable-next-line
143
+ const file = path.join(options.output, a.file);
144
+ const deduped = (0, merge_helpers_1.dedupeTempFolder)(file);
145
+ fs.ensureFileSync(deduped);
146
+ fs.writeFileSync(deduped, (0, print_1.default)(a.ast));
147
+ });
148
+ cleaned.imported.forEach(a => {
149
+ // eslint-disable-next-line
150
+ const file = path.join(options.output, targetSubfolder, a.file);
151
+ const deduped = (0, merge_helpers_1.dedupeTempFolder)(file);
152
+ fs.ensureFileSync(deduped);
153
+ fs.writeFileSync(deduped, (0, print_1.default)(a.ast));
154
+ importedGraphQLFiles.push(path.relative(options.output, deduped));
155
+ });
156
+ }
157
+ else {
158
+ glob.sync('**/*.graphql', { cwd: imported.source }).forEach(relativePath => {
159
+ const importedFullPath = path.join(imported.source, relativePath);
160
+ const targetFullPath = path.join(options.output, targetSubfolder, relativePath);
161
+ fs.ensureDirSync(path.dirname(targetFullPath));
162
+ fs.copyFileSync(importedFullPath, targetFullPath);
163
+ importedGraphQLFiles.push(path.relative(options.output, targetFullPath));
164
+ });
165
+ }
166
+ // Make sure all files are referenced in @sdl
167
+ (0, set_files_in_sdl_1.default)(options.output, importedGraphQLFiles);
168
+ // Generate configuration
169
+ const config = await (0, merge_helpers_1.getConfiguration)([options.output, imported.source], options.silent, options.answers);
170
+ if (config) {
171
+ const configFile = path.join(options.output, 'config.yaml');
172
+ fs.writeFileSync(configFile, config);
173
+ }
174
+ // Return a merged schema!
175
+ return options.output;
176
+ };
177
+ //# sourceMappingURL=merge.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"merge.js","sourceRoot":"","sources":["../../src/actions/merge.ts"],"names":[],"mappings":";;AAAA,+BAA8B;AAC9B,6BAA4B;AAC5B,gDAAkD;AAClD,qCAAoC;AACpC,yBAAwB;AACxB,6BAA4B;AAE5B,0DAY+B;AAC/B,mC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V,MAAM,UAAU,GAAG,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,aAAa,CAAC,CAAA;QAC3D,EAAE,CAAC,aAAa,CAAC,UAAU,EAAE,MAAgB,CAAC,CAAA;KAC/C;IAED,0BAA0B;IAC1B,OAAO,OAAO,CAAC,MAAM,CAAA;AACvB,CAAC,CAAA"}
@@ -0,0 +1,4 @@
1
+ import { DocumentNode } from 'graphql';
2
+ declare const _default: (ast: DocumentNode) => string;
3
+ export default _default;
4
+ //# sourceMappingURL=print.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"print.d.ts","sourceRoot":"","sources":["../../src/actions/print.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,YAAY,EAAQ,MAAM,SAAS,CAAA;8BAGtB,YAAY,KAAG,MAAM;AAA1C,wBAIC"}
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const graphql_1 = require("graphql");
4
+ const prettier = require("prettier");
5
+ exports.default = (ast) => {
6
+ const printed = (0, graphql_1.print)(ast);
7
+ const formatted = prettier.format(printed, { parser: 'graphql' });
8
+ return formatted;
9
+ };
10
+ //# sourceMappingURL=print.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"print.js","sourceRoot":"","sources":["../../src/actions/print.ts"],"names":[],"mappings":";;AAAA,qCAA2C;AAC3C,qCAAoC;AAEpC,kBAAe,CAAC,GAAiB,EAAU,EAAE;IAC3C,MAAM,OAAO,GAAG,IAAA,eAAK,EAAC,GAAG,CAAC,CAAA;IAC1B,MAAM,SAAS,GAAG,QAAQ,CAAC,MAAM,CAAC,OAAO,EAAE,EAAC,MAAM,EAAE,SAAS,EAAC,CAAC,CAAA;IAC/D,OAAO,SAAS,CAAA;AAClB,CAAC,CAAA"}
@@ -0,0 +1,3 @@
1
+ declare const _default: (source: string, output?: string) => string;
2
+ export default _default;
3
+ //# sourceMappingURL=stitch.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stitch.d.ts","sourceRoot":"","sources":["../../src/actions/stitch.ts"],"names":[],"mappings":"iCAaU,MAAM,WACN,MAAM;AAFhB,wBAoGC"}
@@ -0,0 +1,96 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const lodash_1 = require("lodash");
4
+ const graphql_1 = require("graphql");
5
+ const fs = require("fs-extra");
6
+ const glob = require("glob");
7
+ const os = require("os");
8
+ const path = require("path");
9
+ const prettier = require("prettier");
10
+ const dedupe_query_and_mutation_types_1 = require("../utils/dedupe-query-and-mutation-types");
11
+ const constants_1 = require("../utils/constants");
12
+ const copy_workspace_content_1 = require("../utils/copy-workspace-content");
13
+ exports.default = (source, output = path.join(os.tmpdir(), `stepzen-tmp-${Date.now()}`)) => {
14
+ // Ensure source and output directories exist
15
+ if (!fs.existsSync(source))
16
+ throw new Error(`Cannot find source directory ${source}`);
17
+ fs.ensureDirSync(output);
18
+ // Get a list of files.
19
+ let ast;
20
+ let files = [];
21
+ // If there's an index.graphQL - get files argument in @sdl directive
22
+ const sourceIndex = path.join(source, 'index.graphql');
23
+ if (fs.existsSync(sourceIndex)) {
24
+ const index = fs.readFileSync(sourceIndex, 'utf8');
25
+ ast = (0, graphql_1.parse)(index);
26
+ ast = (0, graphql_1.visit)(ast, {
27
+ Directive(node) {
28
+ if (node.name.value === 'sdl') {
29
+ const list = node.arguments?.find((arg) => arg.name.value === 'files');
30
+ // If we find a 'files' argument, we copy the list, and remove the argument
31
+ if (list) {
32
+ const copy = (0, lodash_1.clone)(list.value);
33
+ for (const file of copy.values) {
34
+ if (file.value === constants_1.ALL_GRAPHQL_FILES) {
35
+ files = files.concat((0, copy_workspace_content_1.getAllGraphQLFiles)(source));
36
+ }
37
+ else {
38
+ files = files.concat(file.value);
39
+ }
40
+ }
41
+ const mutated = (0, lodash_1.cloneDeep)(node);
42
+ mutated.arguments = mutated.arguments.filter((arg) => arg.name.value !== 'files');
43
+ return mutated;
44
+ }
45
+ }
46
+ },
47
+ });
48
+ }
49
+ else {
50
+ const content = glob
51
+ .sync('**/*.graphql', { cwd: source })
52
+ .map((file) => {
53
+ const graphql = fs.readFileSync(`${source}/${file}`, 'utf8');
54
+ return graphql;
55
+ });
56
+ ast = (0, graphql_1.parse)(content.join(os.EOL));
57
+ }
58
+ // Strip @sdl directive
59
+ ast = (0, graphql_1.visit)(ast, {
60
+ Directive(node) {
61
+ if (node.name.value === 'sdl')
62
+ return null;
63
+ },
64
+ });
65
+ // Check all the files exist
66
+ for (const file of files) {
67
+ const find = path.join(source, file);
68
+ if (!fs.existsSync(find)) {
69
+ throw new Error(`Cannot find file ${file} referenced in the @sdl directive in index.graphql`);
70
+ }
71
+ }
72
+ // Get all the files and stitch
73
+ const printed = (0, graphql_1.print)(ast);
74
+ let stitched = `${printed}${os.EOL}`;
75
+ for (const file of files) {
76
+ const find = path.join(source, file);
77
+ const content = fs.readFileSync(find, 'utf8');
78
+ stitched += `${content}${os.EOL}`;
79
+ }
80
+ // Dedupe Query and Mutation types
81
+ stitched = (0, dedupe_query_and_mutation_types_1.default)(stitched);
82
+ // Format
83
+ stitched = prettier.format(stitched, { parser: 'graphql' });
84
+ // Write to output folder
85
+ const outputIndex = path.join(output, 'index.graphql');
86
+ fs.writeFileSync(outputIndex, stitched);
87
+ // Copy config if exists, too
88
+ const sourceConfig = path.join(source, 'config.yaml');
89
+ const outputConfig = path.join(output, 'config.yaml');
90
+ if (fs.existsSync(sourceConfig)) {
91
+ fs.copyFileSync(sourceConfig, outputConfig);
92
+ }
93
+ // Return output folder
94
+ return output;
95
+ };
96
+ //# sourceMappingURL=stitch.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stitch.js","sourceRoot":"","sources":["../../src/actions/stitch.ts"],"names":[],"mappings":";;AAAA,mCAAuC;AACvC,qCAA2C;AAC3C,+BAA8B;AAC9B,6BAA4B;AAC5B,yBAAwB;AACxB,6BAA4B;AAC5B,qCAAoC;AAEpC,8FAAkF;AAClF,k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Zen workspace directory, apply StepZen-specific schema and config
3
+ * transformations, and return its effective GraphQL schema and configuration
4
+ * as in-memory strings.
5
+ *
6
+ * @param {*} source absolute path to a schema root folder
7
+ * @return {*} schema, configuration, and a "transpiled" flag indicating
8
+ * whether or not any StepZen-specific transformations have actually
9
+ * been applied.
10
+ */
11
+ declare const _default: (source: string) => Promise<{
12
+ config: string | false;
13
+ schema: string;
14
+ transpiled: boolean;
15
+ }>;
16
+ export default _default;
17
+ //# sourceMappingURL=transpile.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transpile.d.ts","sourceRoot":"","sources":["../../src/actions/transpile.ts"],"names":[],"mappings":"AAaA;;;;;;;;;GASG;iCAC2B,MAAM;;;;;AAApC,wBAkDC"}