@ethlete/query 6.0.0-next.3 → 6.0.0-next.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.
@@ -0,0 +1,589 @@
1
+ import { visitNotIgnoredFiles } from '@nx/devkit';
2
+ import * as ts from 'typescript';
3
+ import { capitalizeFirstLetter, createSourceFile, ensureConfigSuffix, ensureImportFromQuery } from './shared.js';
4
+ const LEGACY_HTTP_METHOD = {
5
+ GET: 'get',
6
+ POST: 'post',
7
+ PUT: 'put',
8
+ PATCH: 'patch',
9
+ DELETE: 'delete',
10
+ };
11
+ const isLegacyHttpMethod = (value) => {
12
+ return Object.values(LEGACY_HTTP_METHOD).includes(value);
13
+ };
14
+ export const createNewQueryCreators = (tree, queryClientFiles, report) => {
15
+ const createdFiles = [];
16
+ const authProvidersNeeded = new Map();
17
+ const clientNameToFilePath = new Map();
18
+ queryClientFiles.forEach((configNames, filePath) => {
19
+ configNames.forEach((configName) => {
20
+ clientNameToFilePath.set(configName, filePath);
21
+ });
22
+ });
23
+ visitNotIgnoredFiles(tree, '', (filePath) => {
24
+ if (!filePath.endsWith('.ts') || filePath.endsWith('.spec.ts')) {
25
+ return;
26
+ }
27
+ const content = tree.read(filePath, 'utf-8');
28
+ if (!content) {
29
+ return;
30
+ }
31
+ const legacyCreators = analyzeLegacyQueryCreators(content, queryClientFiles, filePath, report);
32
+ if (legacyCreators.length === 0) {
33
+ return;
34
+ }
35
+ legacyCreators.forEach((creator) => {
36
+ if (!creator.secure) {
37
+ return;
38
+ }
39
+ const clientFilePath = clientNameToFilePath.get(creator.clientName);
40
+ if (clientFilePath) {
41
+ authProvidersNeeded.set(creator.clientName, clientFilePath);
42
+ }
43
+ });
44
+ const nextContent = transformLegacyQueryCreators(content, legacyCreators);
45
+ if (nextContent !== content) {
46
+ tree.write(filePath, nextContent);
47
+ createdFiles.push(filePath);
48
+ }
49
+ });
50
+ if (authProvidersNeeded.size > 0) {
51
+ createAuthProviders(tree, authProvidersNeeded, report);
52
+ }
53
+ if (createdFiles.length > 0) {
54
+ console.log('\n✅ Created new query creators in:');
55
+ createdFiles.forEach((filePath) => console.log(` - ${filePath}`));
56
+ }
57
+ };
58
+ export const updateLegacyCreatorImportsAndUsages = (tree) => {
59
+ const legacyCreators = new Map();
60
+ const updatedFiles = [];
61
+ visitNotIgnoredFiles(tree, '', (filePath) => {
62
+ if (!filePath.endsWith('.ts') || filePath.endsWith('.spec.ts')) {
63
+ return;
64
+ }
65
+ const content = tree.read(filePath, 'utf-8');
66
+ if (!content) {
67
+ return;
68
+ }
69
+ const wrappers = findLegacyWrappers(content);
70
+ wrappers.forEach((legacyName, originalName) => {
71
+ legacyCreators.set(originalName, legacyName);
72
+ });
73
+ });
74
+ if (legacyCreators.size === 0) {
75
+ return;
76
+ }
77
+ console.log(`\n✅ Found ${legacyCreators.size} legacy query creator wrappers`);
78
+ visitNotIgnoredFiles(tree, '', (filePath) => {
79
+ if (!filePath.endsWith('.ts') || filePath.endsWith('.spec.ts')) {
80
+ return;
81
+ }
82
+ const content = tree.read(filePath, 'utf-8');
83
+ if (!content || containsLegacyWrapperDefinitions(content)) {
84
+ return;
85
+ }
86
+ const nextImports = updateLegacyCreatorImports(content, legacyCreators);
87
+ const nextContent = updateLegacyCreatorUsages(nextImports, legacyCreators);
88
+ if (nextContent !== content) {
89
+ tree.write(filePath, nextContent);
90
+ updatedFiles.push(filePath);
91
+ }
92
+ });
93
+ if (updatedFiles.length > 0) {
94
+ console.log('\n✅ Updated legacy creator imports and usages in:');
95
+ updatedFiles.forEach((filePath) => console.log(` - ${filePath}`));
96
+ }
97
+ };
98
+ const toLegacyName = (name) => `legacy${capitalizeFirstLetter(name)}`;
99
+ const analyzeLegacyQueryCreators = (content, queryClientFiles, filePath, report) => {
100
+ const sourceFile = createSourceFile(content, filePath);
101
+ const creators = [];
102
+ const oldClientNames = new Set();
103
+ queryClientFiles.forEach((configNames) => {
104
+ configNames.forEach((configName) => oldClientNames.add(configName));
105
+ });
106
+ const visit = (node) => {
107
+ if (ts.isVariableDeclaration(node) &&
108
+ ts.isIdentifier(node.name) &&
109
+ node.initializer &&
110
+ ts.isCallExpression(node.initializer) &&
111
+ ts.isPropertyAccessExpression(node.initializer.expression)) {
112
+ const objectExpression = node.initializer.expression.expression;
113
+ const methodExpression = node.initializer.expression.name;
114
+ if (!ts.isIdentifier(objectExpression) || !ts.isIdentifier(methodExpression)) {
115
+ ts.forEachChild(node, visit);
116
+ return;
117
+ }
118
+ if (!oldClientNames.has(objectExpression.text) || !isLegacyHttpMethod(methodExpression.text)) {
119
+ ts.forEachChild(node, visit);
120
+ return;
121
+ }
122
+ const creatorName = node.name.text;
123
+ const info = {
124
+ name: creatorName,
125
+ clientName: objectExpression.text,
126
+ method: methodExpression.text,
127
+ route: '',
128
+ secure: false,
129
+ httpOptions: new Map(),
130
+ };
131
+ const configObject = node.initializer.arguments[0];
132
+ if (configObject && ts.isObjectLiteralExpression(configObject)) {
133
+ configObject.properties.forEach((property) => {
134
+ if (!ts.isPropertyAssignment(property) || !ts.isIdentifier(property.name)) {
135
+ return;
136
+ }
137
+ if (property.name.text === 'route') {
138
+ info.route = property.initializer.getText(sourceFile);
139
+ }
140
+ if (property.name.text === 'secure' && property.initializer.kind === ts.SyntaxKind.TrueKeyword) {
141
+ info.secure = true;
142
+ }
143
+ if (property.name.text === 'types' && ts.isObjectLiteralExpression(property.initializer)) {
144
+ property.initializer.properties.forEach((typeProperty) => {
145
+ if (!ts.isPropertyAssignment(typeProperty) || !ts.isIdentifier(typeProperty.name)) {
146
+ return;
147
+ }
148
+ const extractedType = extractTypeFromDef(typeProperty.initializer, sourceFile);
149
+ if (!extractedType) {
150
+ report.addManualReview({
151
+ title: `Verify generated types for ${creatorName}`,
152
+ summary: `The migration could not extract the \`${typeProperty.name.text}\` type for ${creatorName} automatically.`,
153
+ action: 'Check the generated creator type arguments and restore any missing args/body/response types manually.',
154
+ locations: [
155
+ {
156
+ filePath,
157
+ line: sourceFile.getLineAndCharacterOfPosition(typeProperty.getStart(sourceFile)).line + 1,
158
+ },
159
+ ],
160
+ source: 'legacy-query-creator-migration',
161
+ dedupeKey: `type-extraction:${filePath}:${creatorName}:${typeProperty.name.text}`,
162
+ });
163
+ return;
164
+ }
165
+ if (typeProperty.name.text === 'args') {
166
+ info.typeArgs = extractedType;
167
+ }
168
+ if (typeProperty.name.text === 'response') {
169
+ info.typeResponse = extractedType;
170
+ }
171
+ if (typeProperty.name.text === 'body') {
172
+ info.typeBody = extractedType;
173
+ }
174
+ });
175
+ }
176
+ if (['reportProgress', 'responseType', 'transferCache', 'withCredentials'].includes(property.name.text)) {
177
+ info.httpOptions.set(property.name.text, property.initializer.getText(sourceFile));
178
+ }
179
+ });
180
+ }
181
+ if (info.route) {
182
+ creators.push(info);
183
+ }
184
+ }
185
+ ts.forEachChild(node, visit);
186
+ };
187
+ visit(sourceFile);
188
+ return creators;
189
+ };
190
+ const extractTypeFromDef = (node, sourceFile) => {
191
+ if (ts.isCallExpression(node) && ts.isIdentifier(node.expression) && node.expression.text === 'def') {
192
+ if (node.typeArguments && node.typeArguments.length > 0) {
193
+ return node.typeArguments[0].getText(sourceFile);
194
+ }
195
+ }
196
+ return undefined;
197
+ };
198
+ const transformLegacyQueryCreators = (content, legacyCreators) => {
199
+ const sourceFile = createSourceFile(content);
200
+ const creatorsByClient = new Map();
201
+ const replacements = [];
202
+ legacyCreators.forEach((creator) => {
203
+ if (!creatorsByClient.has(creator.clientName)) {
204
+ creatorsByClient.set(creator.clientName, []);
205
+ }
206
+ creatorsByClient.get(creator.clientName).push(creator);
207
+ });
208
+ legacyCreators.forEach((creator) => {
209
+ const nextCreator = generateNewQueryCreator(creator);
210
+ const legacyWrapper = generateLegacyWrapper(creator);
211
+ let variableStatement;
212
+ const visit = (node) => {
213
+ if (ts.isVariableStatement(node)) {
214
+ const declaration = node.declarationList.declarations[0];
215
+ if (declaration && ts.isIdentifier(declaration.name) && declaration.name.text === creator.name) {
216
+ variableStatement = node;
217
+ }
218
+ }
219
+ ts.forEachChild(node, visit);
220
+ };
221
+ visit(sourceFile);
222
+ if (variableStatement) {
223
+ replacements.push({
224
+ start: variableStatement.getStart(sourceFile),
225
+ end: variableStatement.getEnd(),
226
+ replacement: `${nextCreator}\n${legacyWrapper}`,
227
+ });
228
+ }
229
+ });
230
+ let result = content;
231
+ replacements.sort((left, right) => right.start - left.start);
232
+ replacements.forEach(({ start, end, replacement }) => {
233
+ result = result.slice(0, start) + replacement + result.slice(end);
234
+ });
235
+ result = ensureImportFromQuery(result, ['createLegacyQueryCreator']);
236
+ return addCreatorImports(result, creatorsByClient);
237
+ };
238
+ const addCreatorImports = (content, creatorsByClient) => {
239
+ const sourceFile = createSourceFile(content);
240
+ const replacements = [];
241
+ const importsByClient = new Map();
242
+ creatorsByClient.forEach((creators, clientName) => {
243
+ const clientBaseName = clientName.replace(/Client$/, '');
244
+ const importsNeeded = new Set([ensureConfigSuffix(clientName)]);
245
+ let hasSecureCreators = false;
246
+ creators.forEach((creator) => {
247
+ hasSecureCreators ||= creator.secure;
248
+ const capitalizedMethod = capitalizeFirstLetter(creator.method);
249
+ importsNeeded.add(`${clientBaseName}${capitalizedMethod}`);
250
+ if (creator.secure) {
251
+ importsNeeded.add(`${clientBaseName}${capitalizedMethod}Secure`);
252
+ }
253
+ });
254
+ if (hasSecureCreators) {
255
+ ['Get', 'Post', 'Put', 'Patch', 'Delete'].forEach((methodName) => {
256
+ const secureImport = `${clientBaseName}${methodName}Secure`;
257
+ if (creators.some((creator) => capitalizeFirstLetter(creator.method) === methodName && creator.secure)) {
258
+ importsNeeded.add(secureImport);
259
+ }
260
+ });
261
+ }
262
+ importsByClient.set(clientName, importsNeeded);
263
+ });
264
+ const visit = (node) => {
265
+ if (ts.isImportDeclaration(node) && ts.isStringLiteral(node.moduleSpecifier)) {
266
+ const clientsInImport = [];
267
+ const existingImports = new Set();
268
+ if (node.importClause?.namedBindings && ts.isNamedImports(node.importClause.namedBindings)) {
269
+ node.importClause.namedBindings.elements.forEach((element) => {
270
+ existingImports.add(element.name.text);
271
+ if (importsByClient.has(element.name.text)) {
272
+ clientsInImport.push(element.name.text);
273
+ }
274
+ });
275
+ }
276
+ if (clientsInImport.length === 0) {
277
+ ts.forEachChild(node, visit);
278
+ return;
279
+ }
280
+ const nextImports = new Set();
281
+ clientsInImport.forEach((clientName) => {
282
+ importsByClient.get(clientName)?.forEach((importName) => nextImports.add(importName));
283
+ });
284
+ existingImports.forEach((importName) => {
285
+ if (!clientsInImport.includes(importName)) {
286
+ nextImports.add(importName);
287
+ }
288
+ });
289
+ replacements.push({
290
+ start: node.getStart(sourceFile),
291
+ end: node.getEnd(),
292
+ replacement: `import { ${Array.from(nextImports).sort().join(', ')} } from '${node.moduleSpecifier.text}';`,
293
+ });
294
+ }
295
+ ts.forEachChild(node, visit);
296
+ };
297
+ visit(sourceFile);
298
+ let result = content;
299
+ replacements.sort((left, right) => right.start - left.start);
300
+ replacements.forEach(({ start, end, replacement }) => {
301
+ result = result.slice(0, start) + replacement + result.slice(end);
302
+ });
303
+ return result;
304
+ };
305
+ const generateNewQueryCreator = (creator) => {
306
+ const clientBaseName = creator.clientName.replace(/Client$/, '');
307
+ const capitalizedMethod = capitalizeFirstLetter(creator.method);
308
+ const creatorFunction = creator.secure
309
+ ? `${clientBaseName}${capitalizedMethod}Secure`
310
+ : `${clientBaseName}${capitalizedMethod}`;
311
+ const typeParameter = getTypeParameter(creator);
312
+ const options = Array.from(creator.httpOptions.entries()).map(([key, value]) => `${key}: ${value}`);
313
+ const optionsBlock = options.length > 0 ? `, {\n ${options.join(',\n ')}\n}` : '';
314
+ return `export const ${creator.name} = ${creatorFunction}${typeParameter}(${creator.route}${optionsBlock});`;
315
+ };
316
+ const getTypeParameter = (creator) => {
317
+ if (creator.typeArgs && (creator.typeBody || creator.typeResponse)) {
318
+ const additionalTypes = [];
319
+ if (creator.typeBody) {
320
+ additionalTypes.push(`body: ${creator.typeBody}`);
321
+ }
322
+ if (creator.typeResponse) {
323
+ additionalTypes.push(`response: ${creator.typeResponse}`);
324
+ }
325
+ return `<${creator.typeArgs} & { ${additionalTypes.join('; ')} }>`;
326
+ }
327
+ if (creator.typeArgs) {
328
+ return `<${creator.typeArgs}>`;
329
+ }
330
+ if (creator.typeBody || creator.typeResponse) {
331
+ const typeProperties = [];
332
+ if (creator.typeBody) {
333
+ typeProperties.push(`body: ${creator.typeBody}`);
334
+ }
335
+ if (creator.typeResponse) {
336
+ typeProperties.push(`response: ${creator.typeResponse}`);
337
+ }
338
+ return `<{ ${typeProperties.join('; ')} }>`;
339
+ }
340
+ return '';
341
+ };
342
+ const generateLegacyWrapper = (creator) => {
343
+ return `export const ${toLegacyName(creator.name)} = createLegacyQueryCreator({ creator: ${creator.name} });`;
344
+ };
345
+ const createAuthProviders = (tree, authProvidersNeeded, report) => {
346
+ const createdProviders = [];
347
+ authProvidersNeeded.forEach((filePath, clientName) => {
348
+ const content = tree.read(filePath, 'utf-8');
349
+ if (!content) {
350
+ return;
351
+ }
352
+ const authProviderName = `${clientName}AuthProvider`;
353
+ if (content.includes(`export const ${authProviderName} = createBearerAuthProvider(`)) {
354
+ return;
355
+ }
356
+ const nextContent = generateSecureQueryCreators(addAuthProviderToFile(content, clientName), clientName);
357
+ if (nextContent === content) {
358
+ return;
359
+ }
360
+ tree.write(filePath, nextContent);
361
+ createdProviders.push(filePath);
362
+ report.addFollowUp({
363
+ title: `Configure auth queries for ${authProviderName}`,
364
+ summary: `The migration created ${authProviderName} with an empty \`queries\` array because it cannot infer login or refresh builders safely.`,
365
+ action: 'Add authQuery/tokenRefreshQuery builders, verify token extraction, and remove the placeholder empty array once the provider is configured.',
366
+ locations: [{ filePath }],
367
+ source: 'legacy-query-creator-migration',
368
+ dedupeKey: `auth-provider:${filePath}:${authProviderName}`,
369
+ });
370
+ });
371
+ if (createdProviders.length > 0) {
372
+ console.log('\n✅ Created auth providers in:');
373
+ createdProviders.forEach((filePath) => console.log(` - ${filePath}`));
374
+ }
375
+ };
376
+ const addAuthProviderToFile = (content, clientName) => {
377
+ const nextContent = ensureImportFromQuery(content, ['createBearerAuthProvider']);
378
+ const sourceFile = createSourceFile(nextContent);
379
+ const configName = ensureConfigSuffix(clientName);
380
+ const configPosition = findVariableStatementEnd(sourceFile, configName, 'createQueryClient');
381
+ if (!configPosition) {
382
+ return content;
383
+ }
384
+ const authProviderName = `${clientName}AuthProvider`;
385
+ const capitalizedClientName = capitalizeFirstLetter(clientName);
386
+ const authProviderBlock = [
387
+ '',
388
+ `export const ${authProviderName} = createBearerAuthProvider({`,
389
+ ` name: '${clientName}',`,
390
+ ` queryClientRef: ${configName},`,
391
+ ` queries: [],`,
392
+ '});',
393
+ '',
394
+ `export const [provide${capitalizedClientName}AuthProvider, inject${capitalizedClientName}AuthProvider] = ${authProviderName};`,
395
+ ].join('\n');
396
+ return nextContent.slice(0, configPosition) + authProviderBlock + nextContent.slice(configPosition);
397
+ };
398
+ const findVariableStatementEnd = (sourceFile, variableName, initializerName) => {
399
+ let variableStatementEnd;
400
+ const visit = (node) => {
401
+ if (ts.isVariableDeclaration(node) &&
402
+ ts.isIdentifier(node.name) &&
403
+ node.name.text === variableName &&
404
+ node.initializer &&
405
+ ts.isCallExpression(node.initializer) &&
406
+ ts.isIdentifier(node.initializer.expression) &&
407
+ node.initializer.expression.text === initializerName) {
408
+ let parent = node.parent;
409
+ while (parent && !ts.isVariableStatement(parent)) {
410
+ parent = parent.parent;
411
+ }
412
+ if (parent && ts.isVariableStatement(parent)) {
413
+ variableStatementEnd = parent.getEnd();
414
+ }
415
+ }
416
+ ts.forEachChild(node, visit);
417
+ };
418
+ visit(sourceFile);
419
+ return variableStatementEnd;
420
+ };
421
+ const generateSecureQueryCreators = (content, clientName) => {
422
+ const nextContent = ensureImportFromQuery(content, [
423
+ 'createSecureDeleteQuery',
424
+ 'createSecureGetQuery',
425
+ 'createSecurePatchQuery',
426
+ 'createSecurePostQuery',
427
+ 'createSecurePutQuery',
428
+ ]);
429
+ const sourceFile = createSourceFile(nextContent);
430
+ const authProviderName = `${clientName}AuthProvider`;
431
+ const authProviderPosition = findVariableStatementEnd(sourceFile, authProviderName, 'createBearerAuthProvider');
432
+ if (!authProviderPosition) {
433
+ return content;
434
+ }
435
+ const clientBaseName = clientName.replace(/Client$/, '');
436
+ const configName = ensureConfigSuffix(clientName);
437
+ const secureCreatorBlock = [
438
+ `export const ${clientBaseName}GetSecure = createSecureGetQuery(${configName}, ${authProviderName});`,
439
+ `export const ${clientBaseName}PostSecure = createSecurePostQuery(${configName}, ${authProviderName});`,
440
+ `export const ${clientBaseName}PutSecure = createSecurePutQuery(${configName}, ${authProviderName});`,
441
+ `export const ${clientBaseName}PatchSecure = createSecurePatchQuery(${configName}, ${authProviderName});`,
442
+ `export const ${clientBaseName}DeleteSecure = createSecureDeleteQuery(${configName}, ${authProviderName});`,
443
+ ].join('\n');
444
+ return (nextContent.slice(0, authProviderPosition) + `\n\n${secureCreatorBlock}` + nextContent.slice(authProviderPosition));
445
+ };
446
+ const containsLegacyWrapperDefinitions = (content) => content.includes('createLegacyQueryCreator');
447
+ const findLegacyWrappers = (content) => {
448
+ const wrappers = new Map();
449
+ const sourceFile = createSourceFile(content);
450
+ const visit = (node) => {
451
+ if (ts.isVariableDeclaration(node) &&
452
+ ts.isIdentifier(node.name) &&
453
+ node.name.text.startsWith('legacy') &&
454
+ node.initializer &&
455
+ ts.isCallExpression(node.initializer) &&
456
+ ts.isIdentifier(node.initializer.expression) &&
457
+ node.initializer.expression.text === 'createLegacyQueryCreator') {
458
+ const legacyWrapperName = node.name.text;
459
+ const configObject = node.initializer.arguments[0];
460
+ if (configObject && ts.isObjectLiteralExpression(configObject)) {
461
+ configObject.properties.forEach((property) => {
462
+ if (ts.isPropertyAssignment(property) &&
463
+ ts.isIdentifier(property.name) &&
464
+ property.name.text === 'creator' &&
465
+ ts.isIdentifier(property.initializer)) {
466
+ wrappers.set(property.initializer.text, legacyWrapperName);
467
+ }
468
+ });
469
+ }
470
+ }
471
+ ts.forEachChild(node, visit);
472
+ };
473
+ visit(sourceFile);
474
+ return wrappers;
475
+ };
476
+ const updateLegacyCreatorImports = (content, legacyCreators) => {
477
+ const sourceFile = createSourceFile(content);
478
+ const replacements = [];
479
+ const visit = (node) => {
480
+ if (ts.isImportDeclaration(node) &&
481
+ node.importClause?.namedBindings &&
482
+ ts.isNamedImports(node.importClause.namedBindings)) {
483
+ const nextElements = node.importClause.namedBindings.elements.map((element) => {
484
+ const importedName = element.propertyName ? element.propertyName.text : element.name.text;
485
+ const legacyName = legacyCreators.get(importedName);
486
+ return legacyName ?? element.getText(sourceFile);
487
+ });
488
+ const hasChanges = node.importClause.namedBindings.elements.some((element) => {
489
+ const importedName = element.propertyName ? element.propertyName.text : element.name.text;
490
+ return legacyCreators.has(importedName);
491
+ });
492
+ if (hasChanges) {
493
+ replacements.push({
494
+ start: node.getStart(sourceFile),
495
+ end: node.getEnd(),
496
+ replacement: `import { ${nextElements.join(', ')} } from '${node.moduleSpecifier.text}';`,
497
+ });
498
+ }
499
+ }
500
+ ts.forEachChild(node, visit);
501
+ };
502
+ visit(sourceFile);
503
+ let result = content;
504
+ replacements.sort((left, right) => right.start - left.start);
505
+ replacements.forEach(({ start, end, replacement }) => {
506
+ result = result.slice(0, start) + replacement + result.slice(end);
507
+ });
508
+ return result;
509
+ };
510
+ const updateLegacyCreatorUsages = (content, legacyCreators) => {
511
+ const sourceFile = createSourceFile(content);
512
+ const replacements = [];
513
+ const visit = (node) => {
514
+ if (ts.isObjectLiteralExpression(node)) {
515
+ node.properties.forEach((property) => {
516
+ if (ts.isPropertyAssignment(property) && ts.isIdentifier(property.initializer)) {
517
+ const nextName = legacyCreators.get(property.initializer.text);
518
+ if (nextName) {
519
+ replacements.push({
520
+ start: property.initializer.getStart(sourceFile),
521
+ end: property.initializer.getEnd(),
522
+ replacement: nextName,
523
+ });
524
+ }
525
+ }
526
+ if (ts.isShorthandPropertyAssignment(property) && legacyCreators.has(property.name.text)) {
527
+ replacements.push({
528
+ start: property.getStart(sourceFile),
529
+ end: property.getEnd(),
530
+ replacement: `${property.name.text}: ${legacyCreators.get(property.name.text)}`,
531
+ });
532
+ }
533
+ });
534
+ }
535
+ if (ts.isIdentifier(node) && legacyCreators.has(node.text)) {
536
+ const parent = node.parent;
537
+ if (ts.isPropertyAccessExpression(parent) && parent.name === node) {
538
+ ts.forEachChild(node, visit);
539
+ return;
540
+ }
541
+ if (ts.isPropertyAssignment(parent) && (parent.name === node || parent.initializer === node)) {
542
+ ts.forEachChild(node, visit);
543
+ return;
544
+ }
545
+ if (ts.isShorthandPropertyAssignment(parent) && parent.name === node) {
546
+ ts.forEachChild(node, visit);
547
+ return;
548
+ }
549
+ if (ts.isVariableDeclaration(parent) && parent.name === node) {
550
+ ts.forEachChild(node, visit);
551
+ return;
552
+ }
553
+ if (ts.isImportSpecifier(parent)) {
554
+ ts.forEachChild(node, visit);
555
+ return;
556
+ }
557
+ if (ts.isFunctionDeclaration(parent) && parent.name === node) {
558
+ ts.forEachChild(node, visit);
559
+ return;
560
+ }
561
+ if (ts.isMethodDeclaration(parent) && parent.name === node) {
562
+ ts.forEachChild(node, visit);
563
+ return;
564
+ }
565
+ if (ts.isParameter(parent) && parent.name === node) {
566
+ ts.forEachChild(node, visit);
567
+ return;
568
+ }
569
+ if (ts.isPropertyDeclaration(parent) && parent.name === node) {
570
+ ts.forEachChild(node, visit);
571
+ return;
572
+ }
573
+ replacements.push({
574
+ start: node.getStart(sourceFile),
575
+ end: node.getEnd(),
576
+ replacement: legacyCreators.get(node.text),
577
+ });
578
+ }
579
+ ts.forEachChild(node, visit);
580
+ };
581
+ visit(sourceFile);
582
+ let result = content;
583
+ replacements.sort((left, right) => right.start - left.start);
584
+ replacements.forEach(({ start, end, replacement }) => {
585
+ result = result.slice(0, start) + replacement + result.slice(end);
586
+ });
587
+ return result;
588
+ };
589
+ //# sourceMappingURL=legacy-query-creator-migration.js.map