@gql.tada/cli-utils 1.2.0 → 1.2.1-canary-e42804ea2a1e64b58239cd45b152b047b9afcd17

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 (34) hide show
  1. package/CHANGELOG.md +11 -0
  2. package/dist/chunks/index-chunk.js +1050 -558
  3. package/dist/chunks/index-chunk.js.map +1 -1
  4. package/dist/chunks/index-chunk.mjs +919 -425
  5. package/dist/chunks/index-chunk.mjs.map +1 -1
  6. package/dist/chunks/svelte-chunk.js +53 -51
  7. package/dist/chunks/svelte-chunk.js.map +1 -1
  8. package/dist/chunks/svelte-chunk.mjs +58 -56
  9. package/dist/chunks/svelte-chunk.mjs.map +1 -1
  10. package/dist/chunks/thread-chunk.js +97 -130
  11. package/dist/chunks/thread-chunk.js.map +1 -1
  12. package/dist/chunks/thread-chunk.mjs +94 -106
  13. package/dist/chunks/thread-chunk.mjs.map +1 -1
  14. package/dist/chunks/thread-chunk2.js +46 -82
  15. package/dist/chunks/thread-chunk2.js.map +1 -1
  16. package/dist/chunks/thread-chunk2.mjs +44 -59
  17. package/dist/chunks/thread-chunk2.mjs.map +1 -1
  18. package/dist/chunks/thread-chunk3.js +45 -50
  19. package/dist/chunks/thread-chunk3.js.map +1 -1
  20. package/dist/chunks/thread-chunk3.mjs +45 -50
  21. package/dist/chunks/thread-chunk3.mjs.map +1 -1
  22. package/dist/chunks/vue-chunk.js +18 -15
  23. package/dist/chunks/vue-chunk.js.map +1 -1
  24. package/dist/chunks/vue-chunk.mjs +18 -15
  25. package/dist/chunks/vue-chunk.mjs.map +1 -1
  26. package/dist/gql-tada-cli.js +58 -49
  27. package/dist/gql-tada-cli.js.map +1 -1
  28. package/dist/gql-tada-cli.mjs +656 -647
  29. package/dist/gql-tada-cli.mjs.map +1 -1
  30. package/package.json +2 -3
  31. package/dist/chunks/project-chunk.js +0 -63
  32. package/dist/chunks/project-chunk.js.map +0 -1
  33. package/dist/chunks/project-chunk.mjs +0 -65
  34. package/dist/chunks/project-chunk.mjs.map +0 -1
@@ -1,14 +1,10 @@
1
- import * as e from "node:path";
1
+ import e from "typescript";
2
2
 
3
- import { ts as i, Project as n } from "ts-morph";
3
+ import { findAllPersistedCallExpressions as i, getDocumentReferenceFromDocumentNode as n, getDocumentReferenceFromTypeQuery as t, unrollTadaFragments as a } from "@0no-co/graphqlsp/api";
4
4
 
5
- import { init as t, findAllPersistedCallExpressions as r, getDocumentReferenceFromDocumentNode as a, getDocumentReferenceFromTypeQuery as l, unrollTadaFragments as s } from "@0no-co/graphqlsp/api";
5
+ import { e as r, p as l } from "./index-chunk.mjs";
6
6
 
7
- import { e as o, l as u, g as c } from "./index-chunk.mjs";
8
-
9
- import { c as m } from "./project-chunk.mjs";
10
-
11
- var v = function(e) {
7
+ var s = function(e) {
12
8
  e[e.Const = 1] = "Const";
13
9
  e[e.Var = 2] = "Var";
14
10
  e[e.Int = 3] = "Int";
@@ -17,28 +13,28 @@ var v = function(e) {
17
13
  e[e.String = 6] = "String";
18
14
  e[e.Enum = 7] = "Enum";
19
15
  return e;
20
- }(v || {});
16
+ }(s || {});
21
17
 
22
- var f = function(e) {
18
+ var o = function(e) {
23
19
  e[e.Spread = 1] = "Spread";
24
20
  e[e.Name = 2] = "Name";
25
21
  return e;
26
- }(f || {});
22
+ }(o || {});
27
23
 
28
24
  function mapJoin(e, i, n) {
29
25
  var t = "";
30
- for (var r = 0; r < e.length; r++) {
31
- if (r) {
26
+ for (var a = 0; a < e.length; a++) {
27
+ if (a) {
32
28
  t += i;
33
29
  }
34
- t += n(e[r]);
30
+ t += n(e[a]);
35
31
  }
36
32
  return t;
37
33
  }
38
34
 
39
- var g = "\n";
35
+ var u = "\n";
40
36
 
41
- var p = {
37
+ var c = {
42
38
  OperationDefinition(e) {
43
39
  var i = e.operation;
44
40
  if (e.name) {
@@ -48,38 +44,38 @@ var p = {
48
44
  if (!e.name) {
49
45
  i += " ";
50
46
  }
51
- i += "(" + mapJoin(e.variableDefinitions, ", ", p.VariableDefinition) + ")";
47
+ i += "(" + mapJoin(e.variableDefinitions, ", ", c.VariableDefinition) + ")";
52
48
  }
53
49
  if (e.directives && e.directives.length) {
54
- i += " " + mapJoin(e.directives, " ", p.Directive);
50
+ i += " " + mapJoin(e.directives, " ", c.Directive);
55
51
  }
56
- return "query" !== i ? i + " " + p.SelectionSet(e.selectionSet) : p.SelectionSet(e.selectionSet);
52
+ return "query" !== i ? i + " " + c.SelectionSet(e.selectionSet) : c.SelectionSet(e.selectionSet);
57
53
  },
58
54
  VariableDefinition(e) {
59
- var i = p.Variable(e.variable) + ": " + _print(e.type);
55
+ var i = c.Variable(e.variable) + ": " + _print(e.type);
60
56
  if (e.defaultValue) {
61
57
  i += " = " + _print(e.defaultValue);
62
58
  }
63
59
  if (e.directives && e.directives.length) {
64
- i += " " + mapJoin(e.directives, " ", p.Directive);
60
+ i += " " + mapJoin(e.directives, " ", c.Directive);
65
61
  }
66
62
  return i;
67
63
  },
68
64
  Field(e) {
69
65
  var i = e.alias ? e.alias.value + ": " + e.name.value : e.name.value;
70
66
  if (e.arguments && e.arguments.length) {
71
- var n = mapJoin(e.arguments, ", ", p.Argument);
67
+ var n = mapJoin(e.arguments, ", ", c.Argument);
72
68
  if (i.length + n.length + 2 > 80) {
73
- i += "(" + (g += " ") + mapJoin(e.arguments, g, p.Argument) + (g = g.slice(0, -2)) + ")";
69
+ i += "(" + (u += " ") + mapJoin(e.arguments, u, c.Argument) + (u = u.slice(0, -2)) + ")";
74
70
  } else {
75
71
  i += "(" + n + ")";
76
72
  }
77
73
  }
78
74
  if (e.directives && e.directives.length) {
79
- i += " " + mapJoin(e.directives, " ", p.Directive);
75
+ i += " " + mapJoin(e.directives, " ", c.Directive);
80
76
  }
81
77
  if (e.selectionSet) {
82
- i += " " + p.SelectionSet(e.selectionSet);
78
+ i += " " + c.SelectionSet(e.selectionSet);
83
79
  }
84
80
  return i;
85
81
  },
@@ -87,7 +83,7 @@ var p = {
87
83
  if (e.block) {
88
84
  return function printBlockString(e) {
89
85
  return '"""\n' + e.replace(/"""/g, '\\"""') + '\n"""';
90
- }(e.value).replace(/\n/g, g);
86
+ }(e.value).replace(/\n/g, u);
91
87
  } else {
92
88
  return function printString(e) {
93
89
  return JSON.stringify(e);
@@ -102,7 +98,7 @@ var p = {
102
98
  Name: e => e.value,
103
99
  Variable: e => "$" + e.name.value,
104
100
  ListValue: e => "[" + mapJoin(e.values, ", ", _print) + "]",
105
- ObjectValue: e => "{" + mapJoin(e.fields, ", ", p.ObjectField) + "}",
101
+ ObjectValue: e => "{" + mapJoin(e.fields, ", ", c.ObjectField) + "}",
106
102
  ObjectField: e => e.name.value + ": " + _print(e.value),
107
103
  Document(e) {
108
104
  if (!e.definitions || !e.definitions.length) {
@@ -110,12 +106,12 @@ var p = {
110
106
  }
111
107
  return mapJoin(e.definitions, "\n\n", _print);
112
108
  },
113
- SelectionSet: e => "{" + (g += " ") + mapJoin(e.selections, g, _print) + (g = g.slice(0, -2)) + "}",
109
+ SelectionSet: e => "{" + (u += " ") + mapJoin(e.selections, u, _print) + (u = u.slice(0, -2)) + "}",
114
110
  Argument: e => e.name.value + ": " + _print(e.value),
115
111
  FragmentSpread(e) {
116
112
  var i = "..." + e.name.value;
117
113
  if (e.directives && e.directives.length) {
118
- i += " " + mapJoin(e.directives, " ", p.Directive);
114
+ i += " " + mapJoin(e.directives, " ", c.Directive);
119
115
  }
120
116
  return i;
121
117
  },
@@ -125,22 +121,22 @@ var p = {
125
121
  i += " on " + e.typeCondition.name.value;
126
122
  }
127
123
  if (e.directives && e.directives.length) {
128
- i += " " + mapJoin(e.directives, " ", p.Directive);
124
+ i += " " + mapJoin(e.directives, " ", c.Directive);
129
125
  }
130
- return i + " " + p.SelectionSet(e.selectionSet);
126
+ return i + " " + c.SelectionSet(e.selectionSet);
131
127
  },
132
128
  FragmentDefinition(e) {
133
129
  var i = "fragment " + e.name.value;
134
130
  i += " on " + e.typeCondition.name.value;
135
131
  if (e.directives && e.directives.length) {
136
- i += " " + mapJoin(e.directives, " ", p.Directive);
132
+ i += " " + mapJoin(e.directives, " ", c.Directive);
137
133
  }
138
- return i + " " + p.SelectionSet(e.selectionSet);
134
+ return i + " " + c.SelectionSet(e.selectionSet);
139
135
  },
140
136
  Directive(e) {
141
137
  var i = "@" + e.name.value;
142
138
  if (e.arguments && e.arguments.length) {
143
- i += "(" + mapJoin(e.arguments, ", ", p.Argument) + ")";
139
+ i += "(" + mapJoin(e.arguments, ", ", c.Argument) + ")";
144
140
  }
145
141
  return i;
146
142
  },
@@ -149,110 +145,102 @@ var p = {
149
145
  NonNullType: e => _print(e.type) + "!"
150
146
  };
151
147
 
152
- var _print = e => p[e.kind](e);
148
+ var _print = e => c[e.kind](e);
153
149
 
154
150
  function print(e) {
155
- g = "\n";
156
- return p[e.kind] ? p[e.kind](e) : "";
151
+ u = "\n";
152
+ return c[e.kind] ? c[e.kind](e) : "";
157
153
  }
158
154
 
159
- var d = o((async function* _runPersisted(o) {
160
- t({
161
- typescript: i
162
- });
163
- var v = e.dirname(o.configPath);
164
- var f = new n({
165
- tsConfigFilePath: o.configPath
166
- });
167
- var g = await u(v, f, i);
168
- if (g) {
155
+ var m = r((async function* _runPersisted(r) {
156
+ var s = l(r);
157
+ var o = s.createExternalFiles();
158
+ if (o.length) {
169
159
  yield {
170
160
  kind: "EXTERNAL_WARNING"
171
161
  };
162
+ await s.addVirtualFiles(o);
172
163
  }
173
- var p = m(f, o.pluginConfig, v, g);
174
- var d = f.getSourceFiles().filter((i => {
175
- var n = e.resolve(v, i.getFilePath());
176
- return !e.relative(o.rootPath, n).startsWith("..");
177
- }));
164
+ var u = s.build();
165
+ var c = u.getSourceFiles();
178
166
  yield {
179
167
  kind: "FILE_COUNT",
180
- fileCount: d.length
168
+ fileCount: c.length
181
169
  };
182
- for (var {compilerNode: h} of d) {
183
- var S = h.fileName;
184
- var y = {};
185
- var N = [];
186
- var b = r(h);
187
- for (var D of b) {
188
- var J = c(h, D.getStart(), void 0, g);
189
- S = J.file;
190
- var V = D.arguments[0];
191
- var F = D.arguments[1];
192
- var T = D.typeArguments && D.typeArguments[0];
193
- if (!V || !i.isStringLiteral(V)) {
194
- N.push({
170
+ for (var m of c) {
171
+ var f = m.fileName;
172
+ var v = {};
173
+ var g = [];
174
+ var d = i(m);
175
+ for (var p of d) {
176
+ var S = u.getSourcePosition(m, p.getStart());
177
+ f = S.fileName;
178
+ var h = p.arguments[0];
179
+ var y = p.arguments[1];
180
+ var N = p.typeArguments && p.typeArguments[0];
181
+ if (!h || !e.isStringLiteral(h)) {
182
+ g.push({
195
183
  message: '"graphql.persisted" must be called with a string literal as the first argument.',
196
- file: J.file,
197
- line: J.line,
198
- col: J.col
184
+ file: S.fileName,
185
+ line: S.line,
186
+ col: S.col
199
187
  });
200
188
  continue;
201
- } else if (!F && !T) {
202
- N.push({
189
+ } else if (!y && !N) {
190
+ g.push({
203
191
  message: '"graphql.persisted" is missing a document.\nThis may be passed as a generic such as `graphql.persisted<typeof document>` or as the second argument.',
204
- file: J.file,
205
- line: J.line,
206
- col: J.col
192
+ file: S.fileName,
193
+ line: S.line,
194
+ col: S.col
207
195
  });
208
196
  continue;
209
197
  }
210
- var k = null;
211
- var C = D;
212
- if (F && (i.isCallExpression(F) || i.isIdentifier(F))) {
213
- k = a(F, h.fileName, p).node;
214
- C = F;
215
- } else if (T && i.isTypeQueryNode(T)) {
216
- k = l(T, h.fileName, p).node;
217
- C = T;
198
+ var b = null;
199
+ var V = p;
200
+ if (y && (e.isCallExpression(y) || e.isIdentifier(y))) {
201
+ b = n(y, m.fileName, u.buildPluginInfo(r.pluginConfig)).node;
202
+ V = y;
203
+ } else if (N && e.isTypeQueryNode(N)) {
204
+ b = t(N, m.fileName, u.buildPluginInfo(r.pluginConfig)).node;
205
+ V = N;
218
206
  }
219
- if (!k) {
220
- N.push({
221
- message: `Could not find reference for "${C.getText()}".\nIf this is unexpected, please file an issue describing your case.`,
222
- file: J.file,
223
- line: J.line,
224
- col: J.col
207
+ if (!b) {
208
+ g.push({
209
+ message: `Could not find reference for "${V.getText()}".\nIf this is unexpected, please file an issue describing your case.`,
210
+ file: S.fileName,
211
+ line: S.line,
212
+ col: S.col
225
213
  });
226
214
  continue;
227
215
  }
228
- if (!k || !i.isCallExpression(k) || !i.isNoSubstitutionTemplateLiteral(k.arguments[0]) && !i.isStringLiteral(k.arguments[0])) {
229
- N.push({
230
- message: `The referenced document of "${C.getText()}" contains no document string literal.\nIf this is unexpected, please file an issue describing your case.`,
231
- file: J.file,
232
- line: J.line,
233
- col: J.col
216
+ if (!b || !e.isCallExpression(b) || !e.isNoSubstitutionTemplateLiteral(b.arguments[0]) && !e.isStringLiteral(b.arguments[0])) {
217
+ g.push({
218
+ message: `The referenced document of "${V.getText()}" contains no document string literal.\nIf this is unexpected, please file an issue describing your case.`,
219
+ file: S.fileName,
220
+ line: S.line,
221
+ col: S.col
234
222
  });
235
223
  continue;
236
224
  }
237
- var E = [];
238
- var x = k.arguments[0].getText().slice(1, -1);
239
- if (k.arguments[1] && i.isArrayLiteralExpression(k.arguments[1])) {
240
- s(k.arguments[1], E, p);
225
+ var D = [];
226
+ var J = b.arguments[0].getText().slice(1, -1);
227
+ if (b.arguments[1] && e.isArrayLiteralExpression(b.arguments[1])) {
228
+ a(b.arguments[1], D, u.buildPluginInfo(r.pluginConfig));
241
229
  }
242
- var I = x;
243
- for (var A of E) {
244
- I += "\n\n" + print(A);
230
+ var F = J;
231
+ for (var I of D) {
232
+ F += "\n\n" + print(I);
245
233
  }
246
- y[V.getText().slice(1, -1)] = I;
234
+ v[h.getText().slice(1, -1)] = F;
247
235
  }
248
236
  yield {
249
237
  kind: "FILE_PERSISTED",
250
- filePath: S,
251
- documents: y,
252
- warnings: N
238
+ filePath: f,
239
+ documents: v,
240
+ warnings: g
253
241
  };
254
242
  }
255
243
  }));
256
244
 
257
- export { d as runPersisted };
245
+ export { m as runPersisted };
258
246
  //# sourceMappingURL=thread-chunk.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"thread-chunk.mjs","sources":["../../src/commands/generate-persisted/thread.ts"],"sourcesContent":["import * as path from 'node:path';\nimport { print } from '@0no-co/graphql.web';\nimport { Project, ts } from 'ts-morph';\n\nimport type { FragmentDefinitionNode } from '@0no-co/graphql.web';\nimport type { GraphQLSPConfig } from '@gql.tada/internal';\n\nimport {\n init,\n findAllPersistedCallExpressions,\n getDocumentReferenceFromTypeQuery,\n getDocumentReferenceFromDocumentNode,\n unrollTadaFragments,\n} from '@0no-co/graphqlsp/api';\n\nimport { createPluginInfo, getFilePosition, loadVirtualCode } from '../../ts';\nimport { expose } from '../../threads';\n\nimport type { PersistedSignal, PersistedWarning } from './types';\n\nexport interface PersistedParams {\n rootPath: string;\n configPath: string;\n pluginConfig: GraphQLSPConfig;\n}\n\nasync function* _runPersisted(params: PersistedParams): AsyncIterableIterator<PersistedSignal> {\n init({ typescript: ts });\n\n const projectPath = path.dirname(params.configPath);\n const project = new Project({ tsConfigFilePath: params.configPath });\n\n const getVirtualPosition = await loadVirtualCode(projectPath, project, ts);\n if (!!getVirtualPosition) {\n yield { kind: 'EXTERNAL_WARNING' };\n }\n\n const pluginInfo = createPluginInfo(\n project,\n params.pluginConfig,\n projectPath,\n getVirtualPosition\n );\n\n // Filter source files by whether they're under the relevant root path\n const sourceFiles = project.getSourceFiles().filter((sourceFile) => {\n const filePath = path.resolve(projectPath, sourceFile.getFilePath());\n const relative = path.relative(params.rootPath, filePath);\n return !relative.startsWith('..');\n });\n\n yield {\n kind: 'FILE_COUNT',\n fileCount: sourceFiles.length,\n };\n\n for (const { compilerNode: sourceFile } of sourceFiles) {\n let filePath = sourceFile.fileName;\n const documents: Record<string, string> = {};\n const warnings: PersistedWarning[] = [];\n\n const calls = findAllPersistedCallExpressions(sourceFile);\n for (const call of calls) {\n const position = getFilePosition(sourceFile, call.getStart(), undefined, getVirtualPosition);\n filePath = position.file;\n\n const hashArg = call.arguments[0];\n const docArg = call.arguments[1];\n const typeQuery = call.typeArguments && call.typeArguments[0];\n if (!hashArg || !ts.isStringLiteral(hashArg)) {\n warnings.push({\n message:\n '\"graphql.persisted\" must be called with a string literal as the first argument.',\n file: position.file,\n line: position.line,\n col: position.col,\n });\n continue;\n } else if (!docArg && !typeQuery) {\n warnings.push({\n message:\n '\"graphql.persisted\" is missing a document.\\n' +\n 'This may be passed as a generic such as `graphql.persisted<typeof document>` or as the second argument.',\n file: position.file,\n line: position.line,\n col: position.col,\n });\n continue;\n }\n\n let foundNode: ts.CallExpression | null = null;\n let referencingNode: ts.Node = call;\n if (docArg && (ts.isCallExpression(docArg) || ts.isIdentifier(docArg))) {\n const result = getDocumentReferenceFromDocumentNode(\n docArg,\n sourceFile.fileName,\n pluginInfo\n );\n foundNode = result.node;\n referencingNode = docArg;\n } else if (typeQuery && ts.isTypeQueryNode(typeQuery)) {\n const result = getDocumentReferenceFromTypeQuery(\n typeQuery,\n sourceFile.fileName,\n pluginInfo\n );\n foundNode = result.node;\n referencingNode = typeQuery;\n }\n\n if (!foundNode) {\n warnings.push({\n message:\n `Could not find reference for \"${referencingNode.getText()}\".\\n` +\n 'If this is unexpected, please file an issue describing your case.',\n file: position.file,\n line: position.line,\n col: position.col,\n });\n continue;\n }\n\n if (\n !foundNode ||\n !ts.isCallExpression(foundNode) ||\n (!ts.isNoSubstitutionTemplateLiteral(foundNode.arguments[0]) &&\n !ts.isStringLiteral(foundNode.arguments[0]))\n ) {\n warnings.push({\n message:\n `The referenced document of \"${referencingNode.getText()}\" contains no document string literal.\\n` +\n 'If this is unexpected, please file an issue describing your case.',\n file: position.file,\n line: position.line,\n col: position.col,\n });\n continue;\n }\n\n const fragments: FragmentDefinitionNode[] = [];\n const operation = foundNode.arguments[0].getText().slice(1, -1);\n if (foundNode.arguments[1] && ts.isArrayLiteralExpression(foundNode.arguments[1])) {\n unrollTadaFragments(foundNode.arguments[1], fragments, pluginInfo);\n }\n\n let document = operation;\n for (const fragment of fragments) document += '\\n\\n' + print(fragment);\n documents[hashArg.getText().slice(1, -1)] = document;\n }\n\n yield {\n kind: 'FILE_PERSISTED',\n filePath,\n documents,\n warnings,\n };\n }\n}\n\nexport const runPersisted = expose(_runPersisted);\n"],"names":["runPersisted","expose","async","_runPersisted","params","init","typescript","ts","projectPath","path","dirname","configPath","project","Project","tsConfigFilePath","getVirtualPosition","loadVirtualCode","kind","pluginInfo","createPluginInfo","pluginConfig","sourceFiles","getSourceFiles","filter","sourceFile","filePath","resolve","getFilePath","relative","rootPath","startsWith","fileCount","length","compilerNode","fileName","documents","warnings","calls","findAllPersistedCallExpressions","call","position","getFilePosition","getStart","undefined","file","hashArg","arguments","docArg","typeQuery","typeArguments","isStringLiteral","push","message","line","col","foundNode","referencingNode","isCallExpression","isIdentifier","getDocumentReferenceFromDocumentNode","node","isTypeQueryNode","getDocumentReferenceFromTypeQuery","getText","isNoSubstitutionTemplateLiteral","fragments","operation","slice","isArrayLiteralExpression","unrollTadaFragments","document","fragment","print"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IA+JaA,IAAeC,GArI5BC,gBAAgBC,cAAcC;EAC5BC,EAAK;IAAEC,YAAYC;;EAEnB,IAAMC,IAAcC,EAAKC,QAAQN,EAAOO;EACxC,IAAMC,IAAU,IAAIC,EAAQ;IAAEC,kBAAkBV,EAAOO;;EAEvD,IAAMI,UAA2BC,EAAgBR,GAAaI,GAASL;EACvE,IAAMQ;UACE;MAAEE,MAAM;;;EAGhB,IAAMC,IAAaC,EACjBP,GACAR,EAAOgB,cACPZ,GACAO;EAIF,IAAMM,IAAcT,EAAQU,iBAAiBC,QAAQC;IACnD,IAAMC,IAAWhB,EAAKiB,QAAQlB,GAAagB,EAAWG;IAEtD,QADiBlB,EAAKmB,SAASxB,EA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,OACnBhD,EAAGyD,gCAAgCT,EAAUT,UAAU,QACtDvC,EAAG2C,gBAAgBK,EAAUT,UAAU,KAC1C;QACAV,EAASe,KAAK;UACZC,SACG,+BAA8BI,EAAgBO;UAEjDnB,MAAMJ,EAASI;UACfS,MAAMb,EAASa;UACfC,KAAKd,EAASc;;QAEhB;AACF;MAEA,IAAMW,IAAsC;MAC5C,IAAMC,IAAYX,EAAUT,UAAU,GAAGiB,UAAUI,MAAM,IAAI;MAC7D,IAAIZ,EAAUT,UAAU,MAAMvC,EAAG6D,yBAAyBb,EAAUT,UAAU;QAC5EuB,EAAoBd,EAAUT,UAAU,IAAImB,GAAW/C;;MAGzD,IAAIoD,IAAWJ;MACf,KAAK,IAAMK,KAAYN;QAAWK,KAAY,SAASE,MAAMD;;MAC7DpC,EAAUU,EAAQkB,UAAUI,MAAM,IAAI,MAAMG;AAC9C;UAEM;MACJrD,MAAM;MACNQ;MACAU;MACAC;;AAEJ;AACF;;"}
1
+ {"version":3,"file":"thread-chunk.mjs","sources":["../../src/commands/generate-persisted/thread.ts"],"sourcesContent":["import ts from 'typescript';\nimport { print } from '@0no-co/graphql.web';\n\nimport type { FragmentDefinitionNode } from '@0no-co/graphql.web';\nimport type { GraphQLSPConfig } from '@gql.tada/internal';\n\nimport {\n findAllPersistedCallExpressions,\n getDocumentReferenceFromTypeQuery,\n getDocumentReferenceFromDocumentNode,\n unrollTadaFragments,\n} from '@0no-co/graphqlsp/api';\n\nimport { programFactory } from '../../ts';\nimport { expose } from '../../threads';\n\nimport type { PersistedSignal, PersistedWarning } from './types';\n\nexport interface PersistedParams {\n rootPath: string;\n configPath: string;\n pluginConfig: GraphQLSPConfig;\n}\n\nasync function* _runPersisted(params: PersistedParams): AsyncIterableIterator<PersistedSignal> {\n const factory = programFactory(params);\n\n const externalFiles = factory.createExternalFiles();\n if (externalFiles.length) {\n yield { kind: 'EXTERNAL_WARNING' };\n await factory.addVirtualFiles(externalFiles);\n }\n\n const container = factory.build();\n const sourceFiles = container.getSourceFiles();\n\n yield {\n kind: 'FILE_COUNT',\n fileCount: sourceFiles.length,\n };\n\n for (const sourceFile of sourceFiles) {\n let filePath = sourceFile.fileName;\n const documents: Record<string, string> = {};\n const warnings: PersistedWarning[] = [];\n\n const calls = findAllPersistedCallExpressions(sourceFile);\n for (const call of calls) {\n const position = container.getSourcePosition(sourceFile, call.getStart());\n filePath = position.fileName;\n\n const hashArg = call.arguments[0];\n const docArg = call.arguments[1];\n const typeQuery = call.typeArguments && call.typeArguments[0];\n if (!hashArg || !ts.isStringLiteral(hashArg)) {\n warnings.push({\n message:\n '\"graphql.persisted\" must be called with a string literal as the first argument.',\n file: position.fileName,\n line: position.line,\n col: position.col,\n });\n continue;\n } else if (!docArg && !typeQuery) {\n warnings.push({\n message:\n '\"graphql.persisted\" is missing a document.\\n' +\n 'This may be passed as a generic such as `graphql.persisted<typeof document>` or as the second argument.',\n file: position.fileName,\n line: position.line,\n col: position.col,\n });\n continue;\n }\n\n let foundNode: ts.CallExpression | null = null;\n let referencingNode: ts.Node = call;\n if (docArg && (ts.isCallExpression(docArg) || ts.isIdentifier(docArg))) {\n const result = getDocumentReferenceFromDocumentNode(\n docArg,\n sourceFile.fileName,\n container.buildPluginInfo(params.pluginConfig)\n );\n foundNode = result.node;\n referencingNode = docArg;\n } else if (typeQuery && ts.isTypeQueryNode(typeQuery)) {\n const result = getDocumentReferenceFromTypeQuery(\n typeQuery,\n sourceFile.fileName,\n container.buildPluginInfo(params.pluginConfig)\n );\n foundNode = result.node;\n referencingNode = typeQuery;\n }\n\n if (!foundNode) {\n warnings.push({\n message:\n `Could not find reference for \"${referencingNode.getText()}\".\\n` +\n 'If this is unexpected, please file an issue describing your case.',\n file: position.fileName,\n line: position.line,\n col: position.col,\n });\n continue;\n }\n\n if (\n !foundNode ||\n !ts.isCallExpression(foundNode) ||\n (!ts.isNoSubstitutionTemplateLiteral(foundNode.arguments[0]) &&\n !ts.isStringLiteral(foundNode.arguments[0]))\n ) {\n warnings.push({\n message:\n `The referenced document of \"${referencingNode.getText()}\" contains no document string literal.\\n` +\n 'If this is unexpected, please file an issue describing your case.',\n file: position.fileName,\n line: position.line,\n col: position.col,\n });\n continue;\n }\n\n const fragments: FragmentDefinitionNode[] = [];\n const operation = foundNode.arguments[0].getText().slice(1, -1);\n if (foundNode.arguments[1] && ts.isArrayLiteralExpression(foundNode.arguments[1])) {\n unrollTadaFragments(\n foundNode.arguments[1],\n fragments,\n container.buildPluginInfo(params.pluginConfig)\n );\n }\n\n let document = operation;\n for (const fragment of fragments) document += '\\n\\n' + print(fragment);\n documents[hashArg.getText().slice(1, -1)] = document;\n }\n\n yield {\n kind: 'FILE_PERSISTED',\n filePath,\n documents,\n warnings,\n };\n }\n}\n\nexport const runPersisted = expose(_runPersisted);\n"],"names":["runPersisted","expose","async","_runPersisted","params","factory","programFactory","externalFiles","createExternalFiles","length","kind","addVirtualFiles","container","build","sourceFiles","getSourceFiles","fileCount","sourceFile","filePath","fileName","documents","warnings","calls","findAllPersistedCallExpressions","call","position","getSourcePosition","getStart","hashArg","arguments","docArg","typeQuery","typeArguments","ts","isStringLiteral","push","message","file","line","col","foundNode","referencingNode","isCallExpression","isIdentifier","getDocumentReferenceFromDocumentNode","buildPluginInfo","pluginConfig","node","isTypeQueryNode","getDocumentReferenceFromTypeQuery","getText","isNoSubstitutionTemplateLiteral","fragments","operation","slice","isArrayLiteralExpression","unrollTadaFragments","document","fragment","print"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAoJaA,IAAeC,GA5H5BC,gBAAgBC,cAAcC;EAC5B,IAAMC,IAAUC,EAAeF;EAE/B,IAAMG,IAAgBF,EAAQG;EAC9B,IAAID,EAAcE,QAAQ;UAClB;MAAEC,MAAM;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b,EAASa;UACfC,KAAKd,EAASc;;QAEhB;AACF;MAEA,KACGC,MACAP,EAAGS,iBAAiBF,OACnBP,EAAGkB,gCAAgCX,EAAUX,UAAU,QACtDI,EAAGC,gBAAgBM,EAAUX,UAAU,KAC1C;QACAR,EAASc,KAAK;UACZC,SACG,+BAA8BK,EAAgBS;UAEjDb,MAAMZ,EAASN;UACfmB,MAAMb,EAASa;UACfC,KAAKd,EAASc;;QAEhB;AACF;MAEA,IAAMa,IAAsC;MAC5C,IAAMC,IAAYb,EAAUX,UAAU,GAAGqB,UAAUI,MAAM,IAAI;MAC7D,IAAId,EAAUX,UAAU,MAAMI,EAAGsB,yBAAyBf,EAAUX,UAAU;QAC5E2B,EACEhB,EAAUX,UAAU,IACpBuB,GACAxC,EAAUiC,gBAAgBzC,EAAO0C;;MAIrC,IAAIW,IAAWJ;MACf,KAAK,IAAMK,KAAYN;QAAWK,KAAY,SAASE,MAAMD;;MAC7DtC,EAAUQ,EAAQsB,UAAUI,MAAM,IAAI,MAAMG;AAC9C;UAEM;MACJ/C,MAAM;MACNQ;MACAE;MACAC;;AAEJ;AACF;;"}
@@ -1,111 +1,75 @@
1
- var e = require("node:path");
1
+ var e = require("typescript");
2
2
 
3
- var r = require("ts-morph");
3
+ var a = require("./index-chunk.js");
4
4
 
5
- var a = require("@0no-co/graphqlsp/api");
6
-
7
- var t = require("./index-chunk.js");
8
-
9
- function _interopNamespaceDefault(e) {
10
- var r = Object.create(null);
11
- if (e) {
12
- Object.keys(e).forEach((function(a) {
13
- if ("default" !== a) {
14
- var t = Object.getOwnPropertyDescriptor(e, a);
15
- Object.defineProperty(r, a, t.get ? t : {
16
- enumerable: !0,
17
- get: function() {
18
- return e[a];
19
- }
20
- });
21
- }
22
- }));
23
- }
24
- r.default = e;
25
- return r;
26
- }
27
-
28
- var i = _interopNamespaceDefault(e);
29
-
30
- var n = t.expose((async function* _runTurbo(e) {
31
- a.init({
32
- typescript: r.ts
33
- });
34
- var n = i.dirname(e.configPath);
35
- var s = new r.Project({
36
- tsConfigFilePath: e.configPath,
37
- skipAddingFilesFromTsConfig: !0
5
+ var r = a.expose((async function* _runTurbo(r) {
6
+ var n = a.programFactory(r);
7
+ n.addSourceFile({
8
+ fileId: "__gql-tada-override__.d.ts",
9
+ sourceText: t,
10
+ scriptKind: e.ScriptKind.TS
38
11
  });
39
- var c = s.createSourceFile("__gql-tada-override__.d.ts", l, {
40
- overwrite: !0,
41
- scriptKind: r.ScriptKind.TS
42
- });
43
- if (c._markAsInProject) {
44
- c._markAsInProject();
45
- }
46
- s.addSourceFilesFromTsConfig(e.configPath);
47
- var p = await t.loadVirtualCode(n, s, r.ts);
48
- if (p) {
12
+ var l = n.createExternalFiles();
13
+ if (l.length) {
49
14
  yield {
50
15
  kind: "EXTERNAL_WARNING"
51
16
  };
17
+ await n.addVirtualFiles(l);
52
18
  }
53
- var u = s.getSourceFiles().filter((r => {
54
- var a = i.resolve(n, r.getFilePath());
55
- return !i.relative(e.rootPath, a).startsWith("..");
56
- }));
19
+ var o = n.build();
20
+ var s = o.getSourceFiles();
57
21
  yield {
58
22
  kind: "FILE_COUNT",
59
- fileCount: u.length
23
+ fileCount: s.length
60
24
  };
61
- var d = s.getTypeChecker().compilerObject;
62
- for (var {compilerNode: f} of u) {
63
- var g = f.fileName;
64
- var m = {};
65
- var v = [];
66
- var y = findAllCallExpressions(f, e.pluginConfig);
67
- for (var T of y) {
68
- var F = d.getTypeAtLocation(T);
69
- var h = d.getTypeAtLocation(T.arguments[0]);
70
- if (!F.symbol || "TadaDocumentNode" !== F.symbol.getEscapedName()) {
71
- var S = t.getFilePosition(f, T.getStart(), void 0, p);
72
- g = S.file;
73
- v.push({
25
+ var d = o.program.getTypeChecker();
26
+ for (var p of s) {
27
+ var u = p.fileName;
28
+ var g = {};
29
+ var c = [];
30
+ var f = findAllCallExpressions(p, r.pluginConfig);
31
+ for (var y of f) {
32
+ var T = d.getTypeAtLocation(y);
33
+ var m = d.getTypeAtLocation(y.arguments[0]);
34
+ if (!T.symbol || "TadaDocumentNode" !== T.symbol.getEscapedName()) {
35
+ var v = o.getSourcePosition(p, y.getStart());
36
+ u = v.fileName;
37
+ c.push({
74
38
  message: 'The discovered document is not of type "TadaDocumentNode".\nIf this is unexpected, please file an issue describing your case.',
75
- file: S.file,
76
- line: S.line,
77
- col: S.col
39
+ file: v.fileName,
40
+ line: v.line,
41
+ col: v.col
78
42
  });
79
43
  continue;
80
44
  }
81
- m["value" in h && "string" == typeof h.value && 0 == (h.flags & r.TypeFlags.StringLiteral) ? JSON.stringify(h.value) : d.typeToString(h, T, o)] = d.typeToString(F, T, o);
45
+ g["value" in m && "string" == typeof m.value && 0 == (m.flags & e.TypeFlags.StringLiteral) ? JSON.stringify(m.value) : d.typeToString(m, y, i)] = d.typeToString(T, y, i);
82
46
  }
83
47
  yield {
84
48
  kind: "FILE_TURBO",
85
- filePath: g,
86
- cache: m,
87
- warnings: v
49
+ filePath: u,
50
+ cache: g,
51
+ warnings: c
88
52
  };
89
53
  }
90
54
  }));
91
55
 
92
- var o = r.TypeFormatFlags.NoTruncation | r.TypeFormatFlags.NoTypeReduction | r.TypeFormatFlags.InTypeAlias | r.TypeFormatFlags.UseFullyQualifiedType | r.TypeFormatFlags.GenerateNamesForShadowedTypeParams | r.TypeFormatFlags.UseAliasDefinedOutsideCurrentScope | r.TypeFormatFlags.AllowUniqueESSymbolType | r.TypeFormatFlags.WriteTypeArgumentsOfSignature;
56
+ var i = e.TypeFormatFlags.NoTruncation | e.TypeFormatFlags.NoTypeReduction | e.TypeFormatFlags.InTypeAlias | e.TypeFormatFlags.UseFullyQualifiedType | e.TypeFormatFlags.GenerateNamesForShadowedTypeParams | e.TypeFormatFlags.UseAliasDefinedOutsideCurrentScope | e.TypeFormatFlags.AllowUniqueESSymbolType | e.TypeFormatFlags.WriteTypeArgumentsOfSignature;
93
57
 
94
- var l = "\nimport * as _gqlTada from 'gql.tada';\ndeclare module 'gql.tada' {\n interface setupCache {\n readonly __cacheDisabled: true;\n }\n}\n".trim();
58
+ var t = "\nimport * as _gqlTada from 'gql.tada';\ndeclare module 'gql.tada' {\n interface setupCache {\n readonly __cacheDisabled: true;\n }\n}\n".trim();
95
59
 
96
- function findAllCallExpressions(e, a) {
97
- var t = [];
98
- var i = new Set([ a.template, "graphql", "gql" ].filter(Boolean));
99
- !function find(e) {
100
- if (r.ts.isCallExpression(e) && i.has(e.expression.getText())) {
101
- t.push(e);
60
+ function findAllCallExpressions(a, r) {
61
+ var i = [];
62
+ var t = new Set([ r.template, "graphql", "gql" ].filter(Boolean));
63
+ !function find(a) {
64
+ if (e.isCallExpression(a) && t.has(a.expression.getText())) {
65
+ i.push(a);
102
66
  return;
103
67
  } else {
104
- r.ts.forEachChild(e, find);
68
+ e.forEachChild(a, find);
105
69
  }
106
- }(e);
107
- return t;
70
+ }(a);
71
+ return i;
108
72
  }
109
73
 
110
- exports.runTurbo = n;
74
+ exports.runTurbo = r;
111
75
  //# sourceMappingURL=thread-chunk2.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"thread-chunk2.js","sources":["../../src/commands/turbo/thread.ts"],"sourcesContent":["import * as path from 'node:path';\nimport { Project, TypeFormatFlags, TypeFlags, ScriptKind, ts } from 'ts-morph';\n\nimport type { GraphQLSPConfig } from '@gql.tada/internal';\nimport { init } from '@0no-co/graphqlsp/api';\n\nimport { getFilePosition, loadVirtualCode } from '../../ts';\nimport { expose } from '../../threads';\n\nimport type { TurboSignal, TurboWarning } from './types';\n\nexport interface TurboParams {\n rootPath: string;\n configPath: string;\n pluginConfig: GraphQLSPConfig;\n}\n\nasync function* _runTurbo(params: TurboParams): AsyncIterableIterator<TurboSignal> {\n init({ typescript: ts });\n\n const projectPath = path.dirname(params.configPath);\n const project = new Project({\n tsConfigFilePath: params.configPath,\n skipAddingFilesFromTsConfig: true,\n });\n\n // NOTE: We add our override declaration here before loading all files\n // This sets `__cacheDisabled` on the turbo cache, which disables the cache temporarily\n // If we don't disable the cache then we couldn't regenerate it from inferred types\n const overrideFile = project.createSourceFile(\n '__gql-tada-override__.d.ts',\n DECLARATION_OVERRIDE,\n {\n overwrite: true,\n scriptKind: ScriptKind.TS,\n }\n );\n if (overrideFile._markAsInProject) overrideFile._markAsInProject();\n\n project.addSourceFilesFromTsConfig(params.configPath);\n\n const getVirtualPosition = await loadVirtualCode(projectPath, project, ts);\n if (!!getVirtualPosition) {\n yield { kind: 'EXTERNAL_WARNING' };\n }\n\n // Filter source files by whether they're under the relevant root path\n const sourceFiles = project.getSourceFiles().filter((sourceFile) => {\n const filePath = path.resolve(projectPath, sourceFile.getFilePath());\n const relative = path.relative(params.rootPath, filePath);\n return !relative.startsWith('..');\n });\n\n yield {\n kind: 'FILE_COUNT',\n fileCount: sourceFiles.length,\n };\n\n const checker = project.getTypeChecker().compilerObject;\n for (const { compilerNode: sourceFile } of sourceFiles) {\n let filePath = sourceFile.fileName;\n const cache: Record<string, string> = {};\n const warnings: TurboWarning[] = [];\n\n const calls = findAllCallExpressions(sourceFile, params.pluginConfig);\n for (const call of calls) {\n const returnType = checker.getTypeAtLocation(call);\n const argumentType = checker.getTypeAtLocation(call.arguments[0]);\n // NOTE: `returnType.symbol` is incorrectly typed and is in fact\n // optional and not always present\n if (!returnType.symbol || returnType.symbol.getEscapedName() !== 'TadaDocumentNode') {\n const position = getFilePosition(\n sourceFile,\n call.getStart(),\n undefined,\n getVirtualPosition\n );\n filePath = position.file;\n warnings.push({\n message:\n `The discovered document is not of type \"TadaDocumentNode\".\\n` +\n 'If this is unexpected, please file an issue describing your case.',\n file: position.file,\n line: position.line,\n col: position.col,\n });\n continue;\n }\n\n const key: string =\n 'value' in argumentType &&\n typeof argumentType.value === 'string' &&\n (argumentType.flags & TypeFlags.StringLiteral) === 0\n ? JSON.stringify(argumentType.value)\n : checker.typeToString(argumentType, call, BUILDER_FLAGS);\n cache[key] = checker.typeToString(returnType, call, BUILDER_FLAGS);\n }\n\n yield {\n kind: 'FILE_TURBO',\n filePath,\n cache,\n warnings,\n };\n }\n}\n\nexport const runTurbo = expose(_runTurbo);\n\nconst BUILDER_FLAGS: TypeFormatFlags =\n TypeFormatFlags.NoTruncation |\n TypeFormatFlags.NoTypeReduction |\n TypeFormatFlags.InTypeAlias |\n TypeFormatFlags.UseFullyQualifiedType |\n TypeFormatFlags.GenerateNamesForShadowedTypeParams |\n TypeFormatFlags.UseAliasDefinedOutsideCurrentScope |\n TypeFormatFlags.AllowUniqueESSymbolType |\n TypeFormatFlags.WriteTypeArgumentsOfSignature;\n\nconst DECLARATION_OVERRIDE = `\nimport * as _gqlTada from 'gql.tada';\ndeclare module 'gql.tada' {\n interface setupCache {\n readonly __cacheDisabled: true;\n }\n}\n`.trim();\n\nfunction findAllCallExpressions(\n sourceFile: ts.SourceFile,\n config: GraphQLSPConfig\n): Array<ts.CallExpression> {\n const result: ts.CallExpression[] = [];\n const templates = new Set([config.template, 'graphql', 'gql'].filter(Boolean));\n function find(node: ts.Node) {\n if (ts.isCallExpression(node) && templates.has(node.expression.getText())) {\n result.push(node);\n return;\n } else {\n ts.forEachChild(node, find);\n }\n }\n find(sourceFile);\n return result;\n}\n"],"names":["runTurbo","expose","async","_runTurbo","params","init","typescript","ts","projectPath","path","dirname","configPath","project","Project","tsConfigFilePath","skipAddingFilesFromTsConfig","overrideFile","createSourceFile","DECLARATION_OVERRIDE","overwrite","scriptKind","ScriptKind","TS","_markAsInProject","addSourceFilesFromTsConfig","getVirtualPosition","loadVirtualCode","kind","sourceFiles","getSourceFiles","filter","sourceFile","filePath","resolve","getFilePath","relative","rootPath","startsWith","fileCount","length","checker","getTypeChecker","compilerObject","compilerNode","fileName","cache","warnings","calls","findAllCallExpressions","pluginConfig","call","returnType","getTypeAtLocation","argumentType","arguments","symbol","getEscapedName","position","getFilePosition","getStart","undefined","file","push","message","line","col","value","flags","TypeFlags","StringLiteral","JSON","stringify","typeToString","BUILDER_FLAGS","TypeFormatFlags","NoTruncation","NoTypeReduction","InTypeAlias","UseFullyQualifiedType","GenerateNamesForShadowedTypeParams","UseAliasDefinedOutsideCurrentScope","AllowUniqueESSymbolType","WriteTypeArgumentsOfSignature","trim","config","result","templates","Set","template","Boolean","find","node","isCallExpression","has","expression","getText","forEachChild"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;IA2GaA,IAAWC,EAAMA,QA1F9BC,gBAAgBC,UAAUC;EACxBC,OAAK;IAAEC,YAAYC,EAAAA;;EAEnB,IAAMC,IAAcC,EAAKC,QAAQN,EAAOO;EACxC,IAAMC,IAAU,IAAIC,UAAQ;IAC1BC,kBAAkBV,EAAOO;IACzBI,8BAA6B;;EAM/B,IAAMC,IAAeJ,EAAQK,iBAC3B,8BACAC,GACA;IACEC,YAAW;IACXC,YAAYC,EAAUA,WAACC;;EAG3B,IAAIN,EAAaO;IAAkBP,EAAaO;;EAEhDX,EAAQY,2BAA2BpB,EAAOO;EAE1C,IAAMc,UAA2BC,EAAeA,gBAAClB,GAAaI,GAASL,EAAEA;EACzE,IAAMkB;UACE;MAAEE,MAAM;;;EAIhB,IAAMC,IAAchB,EAAQiB,iBAAiBC,QAAQC;IACnD,IAAMC,IAAWvB,EAAKwB,QAAQzB,GAAauB,EAAWG;IAEtD,QADiBzB,EAAK0B,SAAS/B,EAAOgC,UAAUJ,GAC/BK,WAAW;AAAK;QAG7B;IACJV,MAAM;IACNW,WAAWV,EAAYW;;EAGzB,IAAMC,IAAU5B,EAAQ6B,iBAAiBC;EACzC,KAAK,KAAQC,cAAcZ,MAAgBH,GAAa;IACtD,IAAII,IAAWD,EAAWa;IAC1B,IAAMC,IAAgC,CAAA;IACtC,IAAMC,IAA2B;IAEjC,IAAMC,IAAQC,uBAAuBjB,GAAY3B,EAAO6C;IACxD,KAAK,IAAMC,KAAQH,GAAO;MACxB,IAAMI,IAAaX,EAAQY,kBAAkBF;MAC7C,IAAMG,IAAeb,EAAQY,kBAAkBF,EAAKI,UAAU;MAG9D,KAAKH,EAAWI,UAAiD,uBAAvCJ,EAAWI,OAAOC,kBAAyC;QACnF,IAAMC,IAAWC,EAAeA,gBAC9B3B,GACAmB,EAAKS,iBACLC,GACAnC;QAEFO,IAAWyB,EAASI;QACpBf,EAASgB,KAAK;UACZC,SACG;UAEHF,MAAMJ,EAASI;UACfG,MAAMP,EAASO;UACfC,KAAKR,EAASQ;;QAEhB;AACF;MAQApB,EALE,WAAWQ,KACmB,mBAAvBA,EAAaa,SAC+B,MAAlDb,EAAac,QAAQC,YAAUC,iBAC5BC,KAAKC,UAAUlB,EAAaa,SAC5B1B,EAAQgC,aAAanB,GAAcH,GAAMuB,MAClCjC,EAAQgC,aAAarB,GAAYD,GAAMuB;AACtD;UAEM;MACJ9C,MAAM;MACNK;MACAa;MACAC;;AAEJ;AACF;;AAIA,IAAM2B,IACJC,EAAeA,gBAACC,eAChBD,EAAAA,gBAAgBE,kBAChBF,EAAAA,gBAAgBG,cAChBH,EAAeA,gBAACI,wBAChBJ,EAAeA,gBAACK,qCAChBL,kBAAgBM,qCAChBN,EAAAA,gBAAgBO,0BAChBP,EAAeA,gBAACQ;;AAElB,IAAMhE,IAAwB,gJAO5BiE;;AAEF,SAASnC,uBACPjB,GACAqD;EAEA,IAAMC,IAA8B;EACpC,IAAMC,IAAY,IAAIC,IAAI,EAACH,EAAOI,UAAU,WAAW,QAAO1D,OAAO2D;GACrE,SAASC,KAAKC;IACZ,IAAIpF,EAAEA,GAACqF,iBAAiBD,MAASL,EAAUO,IAAIF,EAAKG,WAAWC,YAAY;MACzEV,EAAOvB,KAAK6B;MACZ;AACF;MACEpF,EAAAA,GAAGyF,aAAaL,GAAMD;;AAE1B,GACAA,CAAK3D;EACL,OAAOsD;AACT;;"}
1
+ {"version":3,"file":"thread-chunk2.js","sources":["../../src/commands/turbo/thread.ts"],"sourcesContent":["import ts from 'typescript';\nimport type { GraphQLSPConfig } from '@gql.tada/internal';\n\nimport { programFactory } from '../../ts';\nimport { expose } from '../../threads';\n\nimport type { TurboSignal, TurboWarning } from './types';\n\nexport interface TurboParams {\n rootPath: string;\n configPath: string;\n pluginConfig: GraphQLSPConfig;\n}\n\nasync function* _runTurbo(params: TurboParams): AsyncIterableIterator<TurboSignal> {\n const factory = programFactory(params);\n\n // NOTE: We add our override declaration here before loading all files\n // This sets `__cacheDisabled` on the turbo cache, which disables the cache temporarily\n // If we don't disable the cache then we couldn't regenerate it from inferred types\n factory.addSourceFile({\n fileId: '__gql-tada-override__.d.ts',\n sourceText: DECLARATION_OVERRIDE,\n scriptKind: ts.ScriptKind.TS,\n });\n\n const externalFiles = factory.createExternalFiles();\n if (externalFiles.length) {\n yield { kind: 'EXTERNAL_WARNING' };\n await factory.addVirtualFiles(externalFiles);\n }\n\n const container = factory.build();\n const sourceFiles = container.getSourceFiles();\n\n yield {\n kind: 'FILE_COUNT',\n fileCount: sourceFiles.length,\n };\n\n const checker = container.program.getTypeChecker();\n for (const sourceFile of sourceFiles) {\n let filePath = sourceFile.fileName;\n const cache: Record<string, string> = {};\n const warnings: TurboWarning[] = [];\n\n const calls = findAllCallExpressions(sourceFile, params.pluginConfig);\n for (const call of calls) {\n const returnType = checker.getTypeAtLocation(call);\n const argumentType = checker.getTypeAtLocation(call.arguments[0]);\n // NOTE: `returnType.symbol` is incorrectly typed and is in fact\n // optional and not always present\n if (!returnType.symbol || returnType.symbol.getEscapedName() !== 'TadaDocumentNode') {\n const position = container.getSourcePosition(sourceFile, call.getStart());\n filePath = position.fileName;\n warnings.push({\n message:\n `The discovered document is not of type \"TadaDocumentNode\".\\n` +\n 'If this is unexpected, please file an issue describing your case.',\n file: position.fileName,\n line: position.line,\n col: position.col,\n });\n continue;\n }\n\n const key: string =\n 'value' in argumentType &&\n typeof argumentType.value === 'string' &&\n (argumentType.flags & ts.TypeFlags.StringLiteral) === 0\n ? JSON.stringify(argumentType.value)\n : checker.typeToString(argumentType, call, BUILDER_FLAGS);\n cache[key] = checker.typeToString(returnType, call, BUILDER_FLAGS);\n }\n\n yield {\n kind: 'FILE_TURBO',\n filePath,\n cache,\n warnings,\n };\n }\n}\n\nexport const runTurbo = expose(_runTurbo);\n\nconst BUILDER_FLAGS: ts.TypeFormatFlags =\n ts.TypeFormatFlags.NoTruncation |\n ts.TypeFormatFlags.NoTypeReduction |\n ts.TypeFormatFlags.InTypeAlias |\n ts.TypeFormatFlags.UseFullyQualifiedType |\n ts.TypeFormatFlags.GenerateNamesForShadowedTypeParams |\n ts.TypeFormatFlags.UseAliasDefinedOutsideCurrentScope |\n ts.TypeFormatFlags.AllowUniqueESSymbolType |\n ts.TypeFormatFlags.WriteTypeArgumentsOfSignature;\n\nconst DECLARATION_OVERRIDE = `\nimport * as _gqlTada from 'gql.tada';\ndeclare module 'gql.tada' {\n interface setupCache {\n readonly __cacheDisabled: true;\n }\n}\n`.trim();\n\nfunction findAllCallExpressions(\n sourceFile: ts.SourceFile,\n config: GraphQLSPConfig\n): Array<ts.CallExpression> {\n const result: ts.CallExpression[] = [];\n const templates = new Set([config.template, 'graphql', 'gql'].filter(Boolean));\n function find(node: ts.Node) {\n if (ts.isCallExpression(node) && templates.has(node.expression.getText())) {\n result.push(node);\n return;\n } else {\n ts.forEachChild(node, find);\n }\n }\n find(sourceFile);\n return result;\n}\n"],"names":["runTurbo","expose","async","_runTurbo","params","factory","programFactory","addSourceFile","fileId","sourceText","DECLARATION_OVERRIDE","scriptKind","ts","ScriptKind","TS","externalFiles","createExternalFiles","length","kind","addVirtualFiles","container","build","sourceFiles","getSourceFiles","fileCount","checker","program","getTypeChecker","sourceFile","filePath","fileName","cache","warnings","calls","findAllCallExpressions","pluginConfig","call","returnType","getTypeAtLocation","argumentType","arguments","symbol","getEscapedName","position","getSourcePosition","getStart","push","message","file","line","col","value","flags","TypeFlags","StringLiteral","JSON","stringify","typeToString","BUILDER_FLAGS","TypeFormatFlags","NoTruncation","NoTypeReduction","InTypeAlias","UseFullyQualifiedType","GenerateNamesForShadowedTypeParams","UseAliasDefinedOutsideCurrentScope","AllowUniqueESSymbolType","WriteTypeArgumentsOfSignature","trim","config","result","templates","Set","template","filter","Boolean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