@gql.tada/cli-utils 1.7.3 → 1.7.4

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.
@@ -1,39 +1,20 @@
1
1
  import e from "typescript";
2
2
 
3
- import * as r from "node:path";
3
+ import r from "node:v8";
4
4
 
5
- import { getSchemaNamesFromConfig as a } from "@gql.tada/internal";
5
+ import a from "node:vm";
6
6
 
7
- import { findAllCallExpressions as t } from "@0no-co/graphqlsp/api";
7
+ import * as t from "node:path";
8
8
 
9
- import { e as i } from "./index-chunk2.mjs";
9
+ import { getSchemaNamesFromConfig as i } from "@gql.tada/internal";
10
10
 
11
- import { p as o } from "./index-chunk.mjs";
11
+ import { findAllCallExpressions as o } from "@0no-co/graphqlsp/api";
12
12
 
13
- function traceCallToImportSource(r, a, t) {
14
- var i = t.getTypeChecker();
15
- var o = r.expression;
16
- var s;
17
- if (e.isIdentifier(o)) {
18
- s = o;
19
- } else if (e.isPropertyAccessExpression(o) && e.isIdentifier(o.expression)) {
20
- s = o.expression;
21
- }
22
- if (!s) {
23
- return;
24
- }
25
- var n = i.getSymbolAtLocation(s);
26
- if (!n || !n.declarations) {
27
- return;
28
- }
29
- for (var l of n.declarations) {
30
- var u = findImportDeclaration(l);
31
- if (u && e.isStringLiteral(u.moduleSpecifier)) {
32
- return resolveModulePath(u.moduleSpecifier.text, a, t);
33
- }
34
- }
35
- return;
36
- }
13
+ import { e as n } from "./index-chunk2.mjs";
14
+
15
+ import { p as s } from "./index-chunk.mjs";
16
+
17
+ var l = 262144e4;
37
18
 
38
19
  function findImportDeclaration(r) {
39
20
  var a = r;
@@ -49,40 +30,40 @@ function findImportDeclaration(r) {
49
30
  function resolveModulePath(r, a, t) {
50
31
  var i = t.getCompilerOptions();
51
32
  var o = e.createCompilerHost(i);
52
- var s = e.resolveModuleName(r, a.fileName, i, o);
53
- if (s.resolvedModule) {
54
- return s.resolvedModule.resolvedFileName;
33
+ var n = e.resolveModuleName(r, a.fileName, i, o);
34
+ if (n.resolvedModule) {
35
+ return n.resolvedModule.resolvedFileName;
55
36
  }
56
37
  return;
57
38
  }
58
39
 
59
- function collectImportsFromSourceFile(a, t, i, o, s) {
60
- var n = [];
40
+ function collectImportsFromSourceFile(r, a, i, o, n) {
41
+ var s = [];
61
42
  var l = function getTadaOutputPaths(e) {
62
43
  var r = [];
63
44
  if ("schema" in e && e.tadaOutputLocation) {
64
45
  r.push(e.tadaOutputLocation);
65
46
  }
66
47
  return r;
67
- }(t);
68
- !function visit(t) {
69
- if (e.isImportDeclaration(t) && e.isStringLiteral(t.moduleSpecifier)) {
70
- var u = t.moduleSpecifier.text;
71
- if (!function isTadaImport(e, a, t) {
48
+ }(a);
49
+ !function visit(a) {
50
+ if (e.isImportDeclaration(a) && e.isStringLiteral(a.moduleSpecifier)) {
51
+ var u = a.moduleSpecifier.text;
52
+ if (!function isTadaImport(e, r, a) {
72
53
  if (e.startsWith(".")) {
73
- var i = r.dirname(a);
74
- var o = r.resolve(i, e);
75
- return t.some((e => {
76
- var a = r.resolve(e);
77
- return o === a || o.startsWith(a + r.sep);
54
+ var i = t.dirname(r);
55
+ var o = t.resolve(i, e);
56
+ return a.some((e => {
57
+ var r = t.resolve(e);
58
+ return o === r || o.startsWith(r + t.sep);
78
59
  }));
79
60
  }
80
- return t.some((r => e === r || e.startsWith(r + "/")));
81
- }(u, a.fileName, l)) {
82
- var c = t.getFullText().trim();
61
+ return a.some((r => e === r || e.startsWith(r + "/")));
62
+ }(u, r.fileName, l)) {
63
+ var c = a.getFullText().trim();
83
64
  if (o) {
84
- var p = i(u, a.fileName, o);
85
- if (s) {
65
+ var p = i(u, r.fileName, o);
66
+ if (n) {
86
67
  if (p.endsWith(".ts") || p.endsWith(".tsx")) {
87
68
  p = p.replace(/\.ts$/, ".js").replace(/\.tsx$/, ".js");
88
69
  }
@@ -90,123 +71,195 @@ function collectImportsFromSourceFile(a, t, i, o, s) {
90
71
  p = p.replace(/\.ts$/, "").replace(/\.tsx$/, "");
91
72
  }
92
73
  if (p && !p.includes("gql.tada")) {
93
- n.push({
74
+ s.push({
94
75
  specifier: p,
95
76
  importClause: c.replace(u, p)
96
77
  });
97
78
  }
98
79
  } else {
99
- n.push({
80
+ s.push({
100
81
  specifier: u,
101
82
  importClause: c
102
83
  });
103
84
  }
104
85
  }
105
86
  }
106
- e.forEachChild(t, visit);
107
- }(a);
108
- return n;
87
+ e.forEachChild(a, visit);
88
+ }(r);
89
+ return s;
109
90
  }
110
91
 
111
- var s = i((async function* _runTurbo(r) {
112
- var i = a(r.pluginConfig);
113
- var s = o(r);
114
- s.addSourceFile({
92
+ var u;
93
+
94
+ function forceGc() {
95
+ if (void 0 === u) {
96
+ var e = globalThis.gc;
97
+ if ("function" == typeof e) {
98
+ u = e;
99
+ } else {
100
+ try {
101
+ r.setFlagsFromString("--expose-gc");
102
+ u = a.runInNewContext("gc");
103
+ r.setFlagsFromString("--no-expose-gc");
104
+ } catch {
105
+ u = null;
106
+ }
107
+ }
108
+ }
109
+ if (u) {
110
+ u();
111
+ }
112
+ }
113
+
114
+ var c = n((async function* _runTurbo(r) {
115
+ var a = i(r.pluginConfig);
116
+ var t = s(r);
117
+ t.addSourceFile({
115
118
  fileId: "__gql-tada-override__.d.ts",
116
- sourceText: l,
119
+ sourceText: m,
117
120
  scriptKind: e.ScriptKind.TS
118
121
  });
119
- var u = s.createExternalFiles();
120
- if (u.length) {
122
+ var n = t.createExternalFiles();
123
+ if (n.length) {
121
124
  yield {
122
125
  kind: "EXTERNAL_WARNING"
123
126
  };
124
- await s.addVirtualFiles(u);
127
+ await t.addVirtualFiles(n);
125
128
  }
126
- var c = s.build();
127
- var p = c.buildPluginInfo(r.pluginConfig);
128
- var m = c.getSourceFiles();
129
+ var u = t.build();
130
+ var c = u.buildPluginInfo(r.pluginConfig);
131
+ var f = u.getSourceFiles().map((e => e.fileName));
129
132
  yield {
130
133
  kind: "FILE_COUNT",
131
- fileCount: m.length
134
+ fileCount: f.length
132
135
  };
133
- var d = c.program.getTypeChecker();
134
- var f = new Map;
135
- for (var v of m) {
136
- var g = v.fileName;
137
- var h = [];
138
- var y = [];
139
- var T = t(v, p, !1).nodes;
140
- var _loop = async function*(a) {
141
- var t = a.node.parent;
142
- if (!e.isCallExpression(t)) {
136
+ var d = new Map;
137
+ var processSourceFile = (i, n, s, l) => {
138
+ var u = i.fileName;
139
+ var c = [];
140
+ var m = [];
141
+ var f = o(i, s, !1).nodes;
142
+ var _loop = function(o) {
143
+ var s = o.node.parent;
144
+ if (!e.isCallExpression(s)) {
143
145
  return 0;
144
146
  }
145
- var o = c.getSourcePosition(v, t.getStart());
146
- g = o.fileName;
147
- if (!i.has(a.schema)) {
148
- y.push({
149
- message: a.schema ? `The '${a.schema}' schema is not in the configuration but was referenced by document.` : i.size > 1 ? "The document is not for a known schema. Have you re-generated the output file?" : "Multiple schemas are configured, but the document is not for a specific schema.",
150
- file: o.fileName,
151
- line: o.line,
152
- col: o.col
147
+ var f = n.getSourcePosition(i, s.getStart());
148
+ u = f.fileName;
149
+ if (!a.has(o.schema)) {
150
+ m.push({
151
+ message: o.schema ? `The '${o.schema}' schema is not in the configuration but was referenced by document.` : a.size > 1 ? "The document is not for a known schema. Have you re-generated the output file?" : "Multiple schemas are configured, but the document is not for a specific schema.",
152
+ file: f.fileName,
153
+ line: f.line,
154
+ col: f.col
153
155
  });
154
156
  return 0;
155
157
  }
156
- var l = traceCallToImportSource(t, v, c.program);
157
- if (l && !f.has(l)) {
158
- var u = c.program.getSourceFile(l);
159
- if (u) {
160
- var p = Array.isArray(r.turboOutputPath) ? r.turboOutputPath.find((e => e.schemaName === a.schema))?.path : r.turboOutputPath;
161
- var m = collectImportsFromSourceFile(u, r.pluginConfig, s.resolveModuleName.bind(s), p, !!s.wasOriginallyNodeNext);
162
- f.set(l, {
163
- absolutePath: l,
164
- imports: m
158
+ var g = function traceCallToImportSource(r, a, t) {
159
+ var i = t.getTypeChecker();
160
+ var o = r.expression;
161
+ var n;
162
+ if (e.isIdentifier(o)) {
163
+ n = o;
164
+ } else if (e.isPropertyAccessExpression(o) && e.isIdentifier(o.expression)) {
165
+ n = o.expression;
166
+ }
167
+ if (!n) {
168
+ return;
169
+ }
170
+ var s = i.getSymbolAtLocation(n);
171
+ if (!s || !s.declarations) {
172
+ return;
173
+ }
174
+ for (var l of s.declarations) {
175
+ var u = findImportDeclaration(l);
176
+ if (u && e.isStringLiteral(u.moduleSpecifier)) {
177
+ return resolveModulePath(u.moduleSpecifier.text, a, t);
178
+ }
179
+ }
180
+ return;
181
+ }(s, i, n.program);
182
+ if (g && !d.has(g)) {
183
+ var v = n.program.getSourceFile(g);
184
+ if (v) {
185
+ var h = Array.isArray(r.turboOutputPath) ? r.turboOutputPath.find((e => e.schemaName === o.schema))?.path : r.turboOutputPath;
186
+ var y = collectImportsFromSourceFile(v, r.pluginConfig, t.resolveModuleName.bind(t), h, !!t.wasOriginallyNodeNext);
187
+ d.set(g, {
188
+ absolutePath: g,
189
+ imports: y
165
190
  });
166
191
  }
167
192
  }
168
- var T = d.getTypeAtLocation(t);
169
- var F = d.getTypeAtLocation(a.node);
193
+ var T = l.getTypeAtLocation(s);
194
+ var F = l.getTypeAtLocation(o.node);
170
195
  if (!T.symbol || "TadaDocumentNode" !== T.symbol.getEscapedName()) {
171
- y.push({
196
+ m.push({
172
197
  message: 'The discovered document is not of type "TadaDocumentNode".\nIf this is unexpected, please file an issue describing your case.',
173
- file: o.fileName,
174
- line: o.line,
175
- col: o.col
198
+ file: f.fileName,
199
+ line: f.line,
200
+ col: f.col
176
201
  });
177
202
  return 0;
178
203
  }
179
- var S = "value" in F && "string" == typeof F.value && !(F.flags & e.TypeFlags.StringLiteral) ? JSON.stringify(F.value) : d.typeToString(F, t, n);
180
- var N = d.typeToString(T, t, n);
181
- h.push({
182
- schemaName: a.schema,
204
+ var S = "value" in F && "string" == typeof F.value && !(F.flags & e.TypeFlags.StringLiteral) ? JSON.stringify(F.value) : l.typeToString(F, s, p);
205
+ var N = l.typeToString(T, s, p);
206
+ c.push({
207
+ schemaName: o.schema,
183
208
  argumentKey: S,
184
209
  documentType: N
185
210
  });
186
211
  };
187
- for (var F of T) {
188
- if (0 === (yield* _loop(F))) {
212
+ for (var g of f) {
213
+ if (0 === _loop(g)) {
189
214
  continue;
190
215
  }
191
216
  }
217
+ return {
218
+ filePath: u,
219
+ documents: c,
220
+ warnings: m
221
+ };
222
+ };
223
+ var isHeapOverSoftLimit = () => {
224
+ if (process.memoryUsage().heapUsed < l) {
225
+ return !1;
226
+ }
227
+ forceGc();
228
+ return process.memoryUsage().heapUsed >= l;
229
+ };
230
+ var g = u.program.getTypeChecker();
231
+ var v = 0;
232
+ for (var h of f) {
233
+ if (v > 0 && (v >= 1e3 || isHeapOverSoftLimit())) {
234
+ c = (u = t.build()).buildPluginInfo(r.pluginConfig);
235
+ forceGc();
236
+ g = u.program.getTypeChecker();
237
+ v = 0;
238
+ }
239
+ var y = u.getSourceFile(h);
240
+ if (!y) {
241
+ continue;
242
+ }
243
+ var {filePath: T, documents: F, warnings: S} = processSourceFile(y, u, c, g);
244
+ v++;
192
245
  yield {
193
246
  kind: "FILE_TURBO",
194
- filePath: g,
195
- documents: h,
196
- warnings: y
247
+ filePath: T,
248
+ documents: F,
249
+ warnings: S
197
250
  };
198
251
  }
199
- if (f.size > 0) {
252
+ if (d.size > 0) {
200
253
  yield {
201
254
  kind: "GRAPHQL_SOURCES",
202
- sources: Array.from(f.values())
255
+ sources: Array.from(d.values())
203
256
  };
204
257
  }
205
258
  }));
206
259
 
207
- var n = e.TypeFormatFlags.NoTruncation | e.TypeFormatFlags.NoTypeReduction | e.TypeFormatFlags.InTypeAlias | e.TypeFormatFlags.UseFullyQualifiedType | e.TypeFormatFlags.GenerateNamesForShadowedTypeParams | e.TypeFormatFlags.UseAliasDefinedOutsideCurrentScope | e.TypeFormatFlags.AllowUniqueESSymbolType | e.TypeFormatFlags.WriteTypeArgumentsOfSignature;
260
+ var p = e.TypeFormatFlags.NoTruncation | e.TypeFormatFlags.NoTypeReduction | e.TypeFormatFlags.InTypeAlias | e.TypeFormatFlags.UseFullyQualifiedType | e.TypeFormatFlags.GenerateNamesForShadowedTypeParams | e.TypeFormatFlags.UseAliasDefinedOutsideCurrentScope | e.TypeFormatFlags.AllowUniqueESSymbolType | e.TypeFormatFlags.WriteTypeArgumentsOfSignature;
208
261
 
209
- var l = "\nimport * as _gqlTada from 'gql.tada';\ndeclare module 'gql.tada' {\n interface setupCache {\n readonly __cacheDisabled: true;\n }\n}\n".trim();
262
+ var m = "\nimport * as _gqlTada from 'gql.tada';\ndeclare module 'gql.tada' {\n interface setupCache {\n readonly __cacheDisabled: true;\n }\n}\n".trim();
210
263
 
211
- export { s as runTurbo };
264
+ export { c as runTurbo };
212
265
  //# sourceMappingURL=thread-chunk2.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"thread-chunk2.mjs","sources":["../../src/commands/turbo/thread.ts"],"sourcesContent":["import ts from 'typescript';\nimport * as path from 'node:path';\nimport type { GraphQLSPConfig } from '@gql.tada/internal';\n\nimport { getSchemaNamesFromConfig } from '@gql.tada/internal';\nimport { findAllCallExpressions } from '@0no-co/graphqlsp/api';\n\nimport { programFactory } from '../../ts';\nimport { expose } from '../../threads';\n\nimport type {\n TurboSignal,\n TurboWarning,\n TurboDocument,\n GraphQLSourceFile,\n GraphQLSourceImport,\n TurboPath,\n} from './types';\n\nexport interface TurboParams {\n rootPath: string;\n configPath: string;\n pluginConfig: GraphQLSPConfig;\n turboOutputPath: string | TurboPath[];\n}\n\nfunction traceCallToImportSource(\n callExpression: ts.CallExpression,\n sourceFile: ts.SourceFile,\n program: ts.Program\n): string | undefined {\n const typeChecker = program.getTypeChecker();\n const expression = callExpression.expression;\n\n let identifier: ts.Identifier | undefined;\n if (ts.isIdentifier(expression)) {\n identifier = expression;\n } else if (ts.isPropertyAccessExpression(expression) && ts.isIdentifier(expression.expression)) {\n identifier = expression.expression;\n }\n\n if (!identifier) return undefined;\n\n const symbol = typeChecker.getSymbolAtLocation(identifier);\n if (!symbol || !symbol.declarations) return undefined;\n\n for (const declaration of symbol.declarations) {\n const importDeclaration = findImportDeclaration(declaration);\n if (importDeclaration && ts.isStringLiteral(importDeclaration.moduleSpecifier)) {\n const moduleName = importDeclaration.moduleSpecifier.text;\n return resolveModulePath(moduleName, sourceFile, program);\n }\n }\n\n return undefined;\n}\n\nfunction findImportDeclaration(node: ts.Node): ts.ImportDeclaration | undefined {\n let current: ts.Node | undefined = node;\n\n while (current) {\n if (ts.isImportDeclaration(current)) {\n return current;\n }\n current = current.parent;\n }\n\n return undefined;\n}\n\nfunction resolveModulePath(\n moduleName: string,\n containingFile: ts.SourceFile,\n program: ts.Program\n): string | undefined {\n const compilerOptions = program.getCompilerOptions();\n const host = ts.createCompilerHost(compilerOptions);\n\n const resolved = ts.resolveModuleName(moduleName, containingFile.fileName, compilerOptions, host);\n\n if (resolved.resolvedModule) {\n return resolved.resolvedModule.resolvedFileName;\n }\n\n return undefined;\n}\n\nfunction collectImportsFromSourceFile(\n sourceFile: ts.SourceFile,\n pluginConfig: GraphQLSPConfig,\n resolveModuleName: (importSpecifier: string, fromPath: string, toPath: string) => string,\n turboOutputPath?: string,\n shouldTreatImportsAsNodeNext?: boolean\n): GraphQLSourceImport[] {\n const imports: GraphQLSourceImport[] = [];\n\n const tadaImportPaths = getTadaOutputPaths(pluginConfig);\n\n function visit(node: ts.Node) {\n if (ts.isImportDeclaration(node) && ts.isStringLiteral(node.moduleSpecifier)) {\n const specifier = node.moduleSpecifier.text;\n\n if (!isTadaImport(specifier, sourceFile.fileName, tadaImportPaths)) {\n const importClause = node.getFullText().trim();\n if (turboOutputPath) {\n // Adjust the import specifier to point to the turbo output path\n let adjustedSpecifier = resolveModuleName(\n specifier,\n sourceFile.fileName,\n turboOutputPath\n );\n\n if (shouldTreatImportsAsNodeNext) {\n if (adjustedSpecifier.endsWith('.ts') || adjustedSpecifier.endsWith('.tsx')) {\n adjustedSpecifier = adjustedSpecifier\n .replace(/\\.ts$/, '.js')\n .replace(/\\.tsx$/, '.js');\n }\n } else {\n adjustedSpecifier = adjustedSpecifier.replace(/\\.ts$/, '').replace(/\\.tsx$/, '');\n }\n\n if (adjustedSpecifier && !adjustedSpecifier.includes('gql.tada')) {\n imports.push({\n specifier: adjustedSpecifier,\n importClause: importClause.replace(specifier, adjustedSpecifier),\n });\n }\n } else {\n imports.push({ specifier, importClause });\n }\n }\n }\n ts.forEachChild(node, visit);\n }\n\n visit(sourceFile);\n return imports;\n}\n\nfunction getTadaOutputPaths(pluginConfig: GraphQLSPConfig): string[] {\n const paths: string[] = [];\n\n if ('schema' in pluginConfig && pluginConfig.tadaOutputLocation) {\n paths.push(pluginConfig.tadaOutputLocation);\n } else {\n // Multiple schemas aren't supported in this context\n }\n\n return paths;\n}\n\nfunction isTadaImport(\n importSpecifier: string,\n sourceFilePath: string,\n tadaOutputLocationPaths: string[]\n): boolean {\n if (importSpecifier.startsWith('.')) {\n const sourceDir = path.dirname(sourceFilePath);\n const absoluteImportPath = path.resolve(sourceDir, importSpecifier);\n\n return tadaOutputLocationPaths.some((tadaOutputLocationPath) => {\n const absoluteTadaPath = path.resolve(tadaOutputLocationPath);\n return (\n absoluteImportPath === absoluteTadaPath ||\n absoluteImportPath.startsWith(absoluteTadaPath + path.sep)\n );\n });\n }\n\n return tadaOutputLocationPaths.some(\n (tadaPath) => importSpecifier === tadaPath || importSpecifier.startsWith(tadaPath + '/')\n );\n}\n\nasync function* _runTurbo(params: TurboParams): AsyncIterableIterator<TurboSignal> {\n const schemaNames = getSchemaNamesFromConfig(params.pluginConfig);\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 pluginInfo = container.buildPluginInfo(params.pluginConfig);\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 const uniqueGraphQLSources = new Map<string, GraphQLSourceFile>();\n\n for (const sourceFile of sourceFiles) {\n let filePath = sourceFile.fileName;\n const documents: TurboDocument[] = [];\n const warnings: TurboWarning[] = [];\n\n const calls = findAllCallExpressions(sourceFile, pluginInfo, false).nodes;\n for (const call of calls) {\n const callExpression = call.node.parent;\n if (!ts.isCallExpression(callExpression)) {\n continue;\n }\n\n const position = container.getSourcePosition(sourceFile, callExpression.getStart());\n filePath = position.fileName;\n if (!schemaNames.has(call.schema)) {\n warnings.push({\n message: call.schema\n ? `The '${call.schema}' schema is not in the configuration but was referenced by document.`\n : schemaNames.size > 1\n ? 'The document is not for a known schema. Have you re-generated the output file?'\n : 'Multiple schemas are configured, but the document is not for a specific schema.',\n file: position.fileName,\n line: position.line,\n col: position.col,\n });\n continue;\n }\n\n const graphqlSourcePath = traceCallToImportSource(\n callExpression,\n sourceFile,\n container.program\n );\n\n if (graphqlSourcePath && !uniqueGraphQLSources.has(graphqlSourcePath)) {\n const graphqlSourceFile = container.program.getSourceFile(graphqlSourcePath);\n if (graphqlSourceFile) {\n const turboPath = Array.isArray(params.turboOutputPath)\n ? params.turboOutputPath.find((cfg) => cfg.schemaName === call.schema)?.path\n : params.turboOutputPath;\n const imports = collectImportsFromSourceFile(\n graphqlSourceFile,\n params.pluginConfig,\n factory.resolveModuleName.bind(factory),\n turboPath,\n !!factory.wasOriginallyNodeNext\n );\n uniqueGraphQLSources.set(graphqlSourcePath, {\n absolutePath: graphqlSourcePath,\n imports,\n });\n }\n }\n\n const returnType = checker.getTypeAtLocation(callExpression);\n const argumentType = checker.getTypeAtLocation(call.node);\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 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 argumentKey: 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, callExpression, BUILDER_FLAGS);\n const documentType = checker.typeToString(returnType, callExpression, BUILDER_FLAGS);\n\n documents.push({\n schemaName: call.schema,\n argumentKey,\n documentType,\n });\n }\n\n yield {\n kind: 'FILE_TURBO',\n filePath,\n documents,\n warnings,\n };\n }\n\n if (uniqueGraphQLSources.size > 0) {\n yield {\n kind: 'GRAPHQL_SOURCES',\n sources: Array.from(uniqueGraphQLSources.values()),\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"],"names":["traceCallToImportSource","callExpression","sourceFile","program","typeChecker","getTypeChecker","expression","identifier","ts","isIdentifier","isPropertyAccessExpression","symbol","getSymbolAtLocation","declarations","declaration","importDeclaration","findImportDeclaration","isStringLiteral","moduleSpecifier","resolveModulePath","text","node","current","isImportDeclaration","parent","moduleName","containingFile","compilerOptions","getCompilerOptions","host","createCompilerHost","resolved","resolveModuleName","fileName","resolvedModule","resolvedFileName","collectImportsFromSourceFile","pluginConfig","turboOutputPath","shouldTreatImportsAsNodeNext","imports","tadaImportPaths","getTadaOutputPaths","paths","tadaOutputLocation","push","visit","specifier","isTadaImport","importSpecifier","sourceFilePath","tadaOutputLocationPaths","startsWith","sourceDir","path","dirname","absoluteImportPath","resolve","some","tadaOutputLocationPath","absoluteTadaPath","sep","tadaPath","importClause","getFullText","trim","adjustedSpecifier","endsWith","replace","includes","forEachChild","runTurbo","expose","async","_runTurbo","params","schemaNames","getSchemaNamesFromConfig","factory","programFactory","addSourceFile","fileId","sourceText","DECLARATION_OVERRIDE","scriptKind","ScriptKind","TS","externalFiles","createExternalFiles","length","kind","addVirtualFiles","container","build","pluginInfo","buildPluginInfo","sourceFiles","getSourceFiles","fileCount","checker","uniqueGraphQLSources","Map","filePath","documents","warnings","calls","findAllCallExpressions","nodes","_loop","call","isCallExpression","position","getSourcePosition","getStart","has","schema","message","size","file","line","col","graphqlSourcePath","graphqlSourceFile","getSourceFile","turboPath","Array","isArray","find","cfg","schemaName","bind","wasOriginallyNodeNext","set","absolutePath","returnType","getTypeAtLocation","argumentType","getEscapedName","argumentKey","value","flags","TypeFlags","StringLiteral","JSON","stringify","typeToString","BUILDER_FLAGS","documentType","sources","from","values","TypeFormatFlags","NoTruncation","NoTypeReduction","InTypeAlias","UseFullyQualifiedType","GenerateNamesForShadowedTypeParams","UseAliasDefinedOutsideCurrentScope","AllowUniqueESSymbolType","WriteTypeArgumentsOfSignature"],"mappings":";;;;;;;;;;;;AA0BA,SAASA,wBACPC,GACAC,GACAC;EAEA,IAAMC,IAAcD,EAAQE;EAC5B,IAAMC,IAAaL,EAAeK;EAElC,IAAIC;EACJ,IAAIC,EAAGC,aAAaH;IAClBC,IAAaD;SACR,IAAIE,EAAGE,2BAA2BJ,MAAeE,EAAGC,aAAaH,E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;MAGpD,KAAKiH,EAAW3H,UAAiD,uBAAvC2H,EAAW3H,OAAO8H,kBAAyC;QACnFjC,EAAS3D,KAAK;UACZuE,SACE;UAEFE,MAAMP,EAAS9E;UACfsF,MAAMR,EAASQ;UACfC,KAAKT,EAASS;;QACb,OAAA;AAEL;MAEA,IAAMkB,IACJ,WAAWF,KACmB,mBAAvBA,EAAaG,WACnBH,EAAaI,QAAQpI,EAAGqI,UAAUC,iBAC/BC,KAAKC,UAAUR,EAAaG,SAC5BxC,EAAQ8C,aAAaT,GAAcvI,GAAgBiJ;MACzD,IAAMC,IAAehD,EAAQ8C,aAAaX,GAAYrI,GAAgBiJ;MAEtE3C,EAAU1D,KAAK;QACboF,YAAYpB,EAAKM;QACjBuB;QACAS;;AAEH;IA7ED,KAAK,IAAMtC,KAAQJ;MAAK,IAGpB,cAHoBG,MAAAC;QAGpB;;;UA4EE;MACJnB,MAAM;MACNY;MACAC;MACAC;;AAEJ;EAEA,IAAIJ,EAAqBiB,OAAO;UACxB;MACJ3B,MAAM;MACN0D,SAASvB,MAAMwB,KAAKjD,EAAqBkD;;;AAG/C;;AAIA,IAAMJ,IACJ1I,EAAG+I,gBAAgBC,eACnBhJ,EAAG+I,gBAAgBE,kBACnBjJ,EAAG+I,gBAAgBG,cACnBlJ,EAAG+I,gBAAgBI,wBACnBnJ,EAAG+I,gBAAgBK,qCACnBpJ,EAAG+I,gBAAgBM,qCACnBrJ,EAAG+I,gBAAgBO,0BACnBtJ,EAAG+I,gBAAgBQ;;AAErB,IAAM5E,IAAuB,gJAO3BlB;;"}
1
+ {"version":3,"file":"thread-chunk2.mjs","sources":["../../src/commands/turbo/thread.ts"],"sourcesContent":["import ts from 'typescript';\nimport v8 from 'node:v8';\nimport vm from 'node:vm';\nimport * as path from 'node:path';\nimport type { GraphQLSPConfig } from '@gql.tada/internal';\n\nimport { getSchemaNamesFromConfig } from '@gql.tada/internal';\nimport { findAllCallExpressions } from '@0no-co/graphqlsp/api';\n\nimport type { ProgramContainer, PluginCreateInfo } from '../../ts';\nimport { programFactory } from '../../ts';\nimport { expose } from '../../threads';\n\nimport type {\n TurboSignal,\n TurboWarning,\n TurboDocument,\n GraphQLSourceFile,\n GraphQLSourceImport,\n TurboPath,\n} from './types';\n\nexport interface TurboParams {\n rootPath: string;\n configPath: string;\n pluginConfig: GraphQLSPConfig;\n turboOutputPath: string | TurboPath[];\n}\n\nconst HEAP_SOFT_LIMIT_BYTES = 2_500 * 1_024 * 1_024;\nconst TURBO_MAX_BATCH = 1_000;\n\nfunction traceCallToImportSource(\n callExpression: ts.CallExpression,\n sourceFile: ts.SourceFile,\n program: ts.Program\n): string | undefined {\n const typeChecker = program.getTypeChecker();\n const expression = callExpression.expression;\n\n let identifier: ts.Identifier | undefined;\n if (ts.isIdentifier(expression)) {\n identifier = expression;\n } else if (ts.isPropertyAccessExpression(expression) && ts.isIdentifier(expression.expression)) {\n identifier = expression.expression;\n }\n\n if (!identifier) return undefined;\n\n const symbol = typeChecker.getSymbolAtLocation(identifier);\n if (!symbol || !symbol.declarations) return undefined;\n\n for (const declaration of symbol.declarations) {\n const importDeclaration = findImportDeclaration(declaration);\n if (importDeclaration && ts.isStringLiteral(importDeclaration.moduleSpecifier)) {\n const moduleName = importDeclaration.moduleSpecifier.text;\n return resolveModulePath(moduleName, sourceFile, program);\n }\n }\n\n return undefined;\n}\n\nfunction findImportDeclaration(node: ts.Node): ts.ImportDeclaration | undefined {\n let current: ts.Node | undefined = node;\n\n while (current) {\n if (ts.isImportDeclaration(current)) {\n return current;\n }\n current = current.parent;\n }\n\n return undefined;\n}\n\nfunction resolveModulePath(\n moduleName: string,\n containingFile: ts.SourceFile,\n program: ts.Program\n): string | undefined {\n const compilerOptions = program.getCompilerOptions();\n const host = ts.createCompilerHost(compilerOptions);\n\n const resolved = ts.resolveModuleName(moduleName, containingFile.fileName, compilerOptions, host);\n\n if (resolved.resolvedModule) {\n return resolved.resolvedModule.resolvedFileName;\n }\n\n return undefined;\n}\n\nfunction collectImportsFromSourceFile(\n sourceFile: ts.SourceFile,\n pluginConfig: GraphQLSPConfig,\n resolveModuleName: (importSpecifier: string, fromPath: string, toPath: string) => string,\n turboOutputPath?: string,\n shouldTreatImportsAsNodeNext?: boolean\n): GraphQLSourceImport[] {\n const imports: GraphQLSourceImport[] = [];\n\n const tadaImportPaths = getTadaOutputPaths(pluginConfig);\n\n function visit(node: ts.Node) {\n if (ts.isImportDeclaration(node) && ts.isStringLiteral(node.moduleSpecifier)) {\n const specifier = node.moduleSpecifier.text;\n\n if (!isTadaImport(specifier, sourceFile.fileName, tadaImportPaths)) {\n const importClause = node.getFullText().trim();\n if (turboOutputPath) {\n // Adjust the import specifier to point to the turbo output path\n let adjustedSpecifier = resolveModuleName(\n specifier,\n sourceFile.fileName,\n turboOutputPath\n );\n\n if (shouldTreatImportsAsNodeNext) {\n if (adjustedSpecifier.endsWith('.ts') || adjustedSpecifier.endsWith('.tsx')) {\n adjustedSpecifier = adjustedSpecifier\n .replace(/\\.ts$/, '.js')\n .replace(/\\.tsx$/, '.js');\n }\n } else {\n adjustedSpecifier = adjustedSpecifier.replace(/\\.ts$/, '').replace(/\\.tsx$/, '');\n }\n\n if (adjustedSpecifier && !adjustedSpecifier.includes('gql.tada')) {\n imports.push({\n specifier: adjustedSpecifier,\n importClause: importClause.replace(specifier, adjustedSpecifier),\n });\n }\n } else {\n imports.push({ specifier, importClause });\n }\n }\n }\n ts.forEachChild(node, visit);\n }\n\n visit(sourceFile);\n return imports;\n}\n\nfunction getTadaOutputPaths(pluginConfig: GraphQLSPConfig): string[] {\n const paths: string[] = [];\n\n if ('schema' in pluginConfig && pluginConfig.tadaOutputLocation) {\n paths.push(pluginConfig.tadaOutputLocation);\n } else {\n // Multiple schemas aren't supported in this context\n }\n\n return paths;\n}\n\nfunction isTadaImport(\n importSpecifier: string,\n sourceFilePath: string,\n tadaOutputLocationPaths: string[]\n): boolean {\n if (importSpecifier.startsWith('.')) {\n const sourceDir = path.dirname(sourceFilePath);\n const absoluteImportPath = path.resolve(sourceDir, importSpecifier);\n\n return tadaOutputLocationPaths.some((tadaOutputLocationPath) => {\n const absoluteTadaPath = path.resolve(tadaOutputLocationPath);\n return (\n absoluteImportPath === absoluteTadaPath ||\n absoluteImportPath.startsWith(absoluteTadaPath + path.sep)\n );\n });\n }\n\n return tadaOutputLocationPaths.some(\n (tadaPath) => importSpecifier === tadaPath || importSpecifier.startsWith(tadaPath + '/')\n );\n}\n\nasync function* _runTurbo(params: TurboParams): AsyncIterableIterator<TurboSignal> {\n const schemaNames = getSchemaNamesFromConfig(params.pluginConfig);\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 // Initially, we only build the program to count files\n // Later, we may reinstantiate to free up memory between batches\n let container = factory.build();\n let pluginInfo = container.buildPluginInfo(params.pluginConfig);\n const fileNames = container.getSourceFiles().map((sourceFile) => sourceFile.fileName);\n\n yield {\n kind: 'FILE_COUNT',\n fileCount: fileNames.length,\n };\n\n const uniqueGraphQLSources = new Map<string, GraphQLSourceFile>();\n\n const processSourceFile = (\n sourceFile: ts.SourceFile,\n container: ProgramContainer,\n pluginInfo: PluginCreateInfo,\n checker: ts.TypeChecker\n ): { filePath: string; documents: TurboDocument[]; warnings: TurboWarning[] } => {\n let filePath = sourceFile.fileName;\n const documents: TurboDocument[] = [];\n const warnings: TurboWarning[] = [];\n\n const calls = findAllCallExpressions(sourceFile, pluginInfo, false).nodes;\n for (const call of calls) {\n const callExpression = call.node.parent;\n if (!ts.isCallExpression(callExpression)) {\n continue;\n }\n\n const position = container.getSourcePosition(sourceFile, callExpression.getStart());\n filePath = position.fileName;\n if (!schemaNames.has(call.schema)) {\n warnings.push({\n message: call.schema\n ? `The '${call.schema}' schema is not in the configuration but was referenced by document.`\n : schemaNames.size > 1\n ? 'The document is not for a known schema. Have you re-generated the output file?'\n : 'Multiple schemas are configured, but the document is not for a specific schema.',\n file: position.fileName,\n line: position.line,\n col: position.col,\n });\n continue;\n }\n\n const graphqlSourcePath = traceCallToImportSource(\n callExpression,\n sourceFile,\n container.program\n );\n\n if (graphqlSourcePath && !uniqueGraphQLSources.has(graphqlSourcePath)) {\n const graphqlSourceFile = container.program.getSourceFile(graphqlSourcePath);\n if (graphqlSourceFile) {\n const turboPath = Array.isArray(params.turboOutputPath)\n ? params.turboOutputPath.find((cfg) => cfg.schemaName === call.schema)?.path\n : params.turboOutputPath;\n const imports = collectImportsFromSourceFile(\n graphqlSourceFile,\n params.pluginConfig,\n factory.resolveModuleName.bind(factory),\n turboPath,\n !!factory.wasOriginallyNodeNext\n );\n uniqueGraphQLSources.set(graphqlSourcePath, {\n absolutePath: graphqlSourcePath,\n imports,\n });\n }\n }\n\n const returnType = checker.getTypeAtLocation(callExpression);\n const argumentType = checker.getTypeAtLocation(call.node);\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 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 argumentKey: 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, callExpression, BUILDER_FLAGS);\n const documentType = checker.typeToString(returnType, callExpression, BUILDER_FLAGS);\n\n documents.push({\n schemaName: call.schema,\n argumentKey,\n documentType,\n });\n }\n\n return { filePath, documents, warnings };\n };\n\n const isHeapOverSoftLimit = (): boolean => {\n if (process.memoryUsage().heapUsed < HEAP_SOFT_LIMIT_BYTES) return false;\n forceGc();\n return process.memoryUsage().heapUsed >= HEAP_SOFT_LIMIT_BYTES;\n };\n\n let checker = container.program.getTypeChecker();\n let filesInBatch = 0;\n\n for (const fileName of fileNames) {\n // When heap or batch limit is reached, rotate out the type checker\n if (filesInBatch > 0 && (filesInBatch >= TURBO_MAX_BATCH || isHeapOverSoftLimit())) {\n container = factory.build();\n pluginInfo = container.buildPluginInfo(params.pluginConfig);\n forceGc();\n checker = container.program.getTypeChecker();\n filesInBatch = 0;\n }\n\n const sourceFile = container.getSourceFile(fileName);\n if (!sourceFile) continue;\n\n const { filePath, documents, warnings } = processSourceFile(\n sourceFile,\n container,\n pluginInfo,\n checker\n );\n filesInBatch++;\n\n yield {\n kind: 'FILE_TURBO',\n filePath,\n documents,\n warnings,\n };\n }\n\n if (uniqueGraphQLSources.size > 0) {\n yield {\n kind: 'GRAPHQL_SOURCES',\n sources: Array.from(uniqueGraphQLSources.values()),\n };\n }\n}\n\nlet cachedGc: (() => void) | null | undefined;\n\nfunction forceGc(): void {\n if (cachedGc === undefined) {\n const existing = (globalThis as { gc?: () => void }).gc;\n if (typeof existing === 'function') {\n cachedGc = existing;\n } else {\n // NOTE: If gc isn't available, try to retrieve it via `node:vm`\n try {\n v8.setFlagsFromString('--expose-gc');\n cachedGc = vm.runInNewContext('gc') as () => void;\n v8.setFlagsFromString('--no-expose-gc');\n } catch {\n cachedGc = null;\n }\n }\n }\n if (cachedGc) cachedGc();\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"],"names":["HEAP_SOFT_LIMIT_BYTES","findImportDeclaration","node","current","ts","isImportDeclaration","parent","resolveModulePath","moduleName","containingFile","program","compilerOptions","getCompilerOptions","host","createCompilerHost","resolved","resolveModuleName","fileName","resolvedModule","resolvedFileName","collectImportsFromSourceFile","sourceFile","pluginConfig","turboOutputPath","shouldTreatImportsAsNodeNext","imports","tadaImportPaths","getTadaOutputPaths","paths","tadaOutputLocation","push","visit","isStringLiteral","moduleSpecifier","specifier","text","isTadaImport","importSpecifier","sourceFilePath","tadaOutputLocationPaths","startsWith","sourceDir","path","dirname","absoluteImportPath","resolve","some","tadaOutputLocationPath","absoluteTadaPath","sep","tadaPath","importClause","getFullText","trim","adjustedSpecifier","endsWith","replace","includes","forEachChild","cachedGc","forceGc","undefined","existing","globalThis","gc","v8","setFlagsFromString","vm","runInNewContext","runTurbo","expose","async","_runTurbo","params","schemaNames","getSchemaNamesFromConfig","factory","programFactory","addSourceFile","fileId","sourceText","DECLARATION_OVERRIDE","scriptKind","ScriptKind","TS","externalFiles","createExternalFiles","length","kind","addVirtualFiles","container","build","pluginInfo","buildPluginInfo","fileNames","getSourceFiles","map","fileCount","uniqueGraphQLSources","Map","processSourceFile","checker","filePath","documents","warnings","calls","findAllCallExpressions","nodes","_loop","call","callExpression","isCallExpression","position","getSourcePosition","getStart","has","schema","message","size","file","line","col","graphqlSourcePath","traceCallToImportSource","typeChecker","getTypeChecker","expression","identifier","isIdentifier","isPropertyAccessExpression","symbol","getSymbolAtLocation","declarations","declaration","importDeclaration","graphqlSourceFile","getSourceFile","turboPath","Array","isArray","find","cfg","schemaName","bind","wasOriginallyNodeNext","set","absolutePath","returnType","getTypeAtLocation","argumentType","getEscapedName","argumentKey","value","flags","TypeFlags","StringLiteral","JSON","stringify","typeToString","BUILDER_FLAGS","documentType","isHeapOverSoftLimit","process","memoryUsage","heapUsed","filesInBatch","sources","from","values","TypeFormatFlags","NoTruncation","NoTypeReduction","InTypeAlias","UseFullyQualifiedType","GenerateNamesForShadowedTypeParams","UseAliasDefinedOutsideCurrentScope","AllowUniqueESSymbolType","WriteTypeArgumentsOfSignature"],"mappings":";;;;;;;;;;;;;;;;AA6BA,IAAMA,IAAwB;;AAkC9B,SAASC,sBAAsBC;EAC7B,IAAIC,IAA+BD;EAEnC,OAAOC,GAAS;IACd,IAAIC,EAAGC,oBAAoBF;MACzB,OAAOA;;IAETA,IAAUA,EAAQG;AACpB;EAEA;AACF;;AAEA,SAASC,kBACPC,GACAC,GACAC;EAEA,IAAMC,IAAkBD,EAAQE;EAChC,IAAMC,IAAOT,EAAGU,mBAAmBH;EAEnC,IAAMI,IAAWX,EAAGY,kBAAkBR,GAAYC,EAAeQ,UAAUN,GAAiBE;EAE5F,IAAIE,EAASG;IACX,OAAOH,EAASG,eAAeC;;EAGjC;AACF;;AAEA,SAASC,6BACPC,GACAC,GACAN,GACAO,GACAC;EAEA,IAAMC,IAAiC;EAEvC,IAAMC,IA4CR,SAASC,mBAAmBL;IAC1B,IAAMM,IAAkB;IAExB,IAAI,YAAYN,KAAgBA,EAAaO;MAC3CD,EAAME,KAAKR,EAAaO;;IAK1B,OAAOD;AACT,GAtD0BD,CAAmBL;GAE3C,SAASS,MAAM7B;IACb,IAAIE,EAAGC,oBAAoBH,MAASE,EAAG4B,gBAAgB9B,EAAK+B,kBAAkB;MAC5E,IAAMC,IAAYhC,EAAK+B,gBAAgBE;MAEvC,KAkDN,SAASC,aACPC,GACAC,GACAC;QAEA,IAAIF,EAAgBG,WAAW,MAAM;UACnC,IAAMC,IAAYC,EAAKC,QAAQL;UAC/B,IAAMM,IAAqBF,EAAKG,QAAQJ,GAAWJ;UAEnD,OA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 "version": "1.7.4",
4
4
  "public": true,
5
5
  "description": "Main logic for gql.tada’s CLI tool.",
6
6
  "author": "0no.co <hi@0no.co>",
@@ -45,13 +45,13 @@
45
45
  "semiver": "^1.1.0",
46
46
  "typanion": "^3.14.0",
47
47
  "type-fest": "^4.10.2",
48
- "typescript": "^5.5.2",
48
+ "typescript": "^5.9.3",
49
49
  "wonka": "^6.3.4"
50
50
  },
51
51
  "dependencies": {
52
52
  "@0no-co/graphqlsp": "^1.12.13",
53
53
  "graphql": "^15.5.0 || ^16.0.0 || ^17.0.0",
54
- "@gql.tada/internal": "1.0.9"
54
+ "@gql.tada/internal": "1.0.10"
55
55
  },
56
56
  "peerDependenciesMeta": {
57
57
  "@gql.tada/svelte-support": {
@@ -64,9 +64,9 @@
64
64
  "peerDependencies": {
65
65
  "@0no-co/graphqlsp": "^1.12.13",
66
66
  "graphql": "^15.5.0 || ^16.0.0 || ^17.0.0",
67
- "typescript": "^5.0.0 || ^6.0.0",
68
- "@gql.tada/vue-support": "1.0.2",
69
- "@gql.tada/svelte-support": "1.0.2"
67
+ "typescript": "^5.0.0 || ^6.0.0 || ^7.0.0 || ^8.0.0",
68
+ "@gql.tada/svelte-support": "1.0.3",
69
+ "@gql.tada/vue-support": "1.0.3"
70
70
  },
71
71
  "publishConfig": {
72
72
  "access": "public",