@strapi/upgrade 0.0.0-experimental.d362bf200f5f9359a4bbd4a549603de5ee1f04ca → 0.0.0-experimental.d65615a2b9130dd742d3c396674457d7971da928

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 (71) hide show
  1. package/LICENSE +19 -4
  2. package/dist/cli.js +1489 -5
  3. package/dist/cli.js.map +1 -1
  4. package/dist/index.js +305 -130
  5. package/dist/index.js.map +1 -1
  6. package/dist/index.mjs +305 -131
  7. package/dist/index.mjs.map +1 -1
  8. package/dist/modules/codemod/codemod.d.ts +4 -2
  9. package/dist/modules/codemod/codemod.d.ts.map +1 -1
  10. package/dist/modules/codemod/types.d.ts +8 -1
  11. package/dist/modules/codemod/types.d.ts.map +1 -1
  12. package/dist/modules/codemod-repository/constants.d.ts.map +1 -1
  13. package/dist/modules/codemod-repository/repository.d.ts +5 -5
  14. package/dist/modules/codemod-repository/repository.d.ts.map +1 -1
  15. package/dist/modules/codemod-repository/types.d.ts +7 -3
  16. package/dist/modules/codemod-repository/types.d.ts.map +1 -1
  17. package/dist/modules/codemod-runner/codemod-runner.d.ts +6 -3
  18. package/dist/modules/codemod-runner/codemod-runner.d.ts.map +1 -1
  19. package/dist/modules/codemod-runner/index.d.ts +1 -0
  20. package/dist/modules/codemod-runner/index.d.ts.map +1 -1
  21. package/dist/modules/codemod-runner/types.d.ts +1 -0
  22. package/dist/modules/codemod-runner/types.d.ts.map +1 -1
  23. package/dist/modules/file-scanner/scanner.d.ts.map +1 -1
  24. package/dist/modules/format/formats.d.ts +6 -0
  25. package/dist/modules/format/formats.d.ts.map +1 -1
  26. package/dist/modules/project/constants.d.ts +6 -5
  27. package/dist/modules/project/constants.d.ts.map +1 -1
  28. package/dist/modules/project/project.d.ts +17 -3
  29. package/dist/modules/project/project.d.ts.map +1 -1
  30. package/dist/modules/project/types.d.ts +4 -0
  31. package/dist/modules/project/types.d.ts.map +1 -1
  32. package/dist/modules/project/utils.d.ts +1 -1
  33. package/dist/modules/project/utils.d.ts.map +1 -1
  34. package/dist/modules/report/report.d.ts.map +1 -1
  35. package/dist/modules/runner/json/transform.d.ts.map +1 -1
  36. package/dist/modules/upgrader/upgrader.d.ts.map +1 -1
  37. package/dist/modules/version/range.d.ts +2 -0
  38. package/dist/modules/version/range.d.ts.map +1 -1
  39. package/dist/tasks/codemods/index.d.ts +2 -1
  40. package/dist/tasks/codemods/index.d.ts.map +1 -1
  41. package/dist/tasks/codemods/list-codemods.d.ts +3 -0
  42. package/dist/tasks/codemods/list-codemods.d.ts.map +1 -0
  43. package/dist/tasks/codemods/run-codemods.d.ts +3 -0
  44. package/dist/tasks/codemods/run-codemods.d.ts.map +1 -0
  45. package/dist/tasks/codemods/types.d.ts +9 -3
  46. package/dist/tasks/codemods/types.d.ts.map +1 -1
  47. package/dist/tasks/codemods/utils.d.ts +6 -0
  48. package/dist/tasks/codemods/utils.d.ts.map +1 -0
  49. package/dist/tasks/index.d.ts +1 -1
  50. package/dist/tasks/index.d.ts.map +1 -1
  51. package/dist/tasks/upgrade/upgrade.d.ts.map +1 -1
  52. package/package.json +10 -9
  53. package/resources/codemods/5.0.0/comment-out-lifecycle-files.code.ts +63 -0
  54. package/resources/codemods/5.0.0/dependency-upgrade-react-and-react-dom.json.ts +67 -0
  55. package/resources/codemods/5.0.0/dependency-upgrade-styled-components.json.ts +49 -0
  56. package/resources/codemods/5.0.0/deprecate-helper-plugin.code.ts +192 -0
  57. package/resources/codemods/5.0.0/entity-service-document-service.code.ts +437 -0
  58. package/resources/codemods/5.0.0/strapi-public-interface.code.ts +126 -0
  59. package/resources/codemods/5.0.0/utils-public-interface.code.ts +320 -0
  60. package/resources/utils/change-import.ts +118 -0
  61. package/resources/utils/replace-jsx.ts +49 -0
  62. package/dist/_chunks/codemod-runner-mXNzVpHm.js +0 -798
  63. package/dist/_chunks/codemod-runner-mXNzVpHm.js.map +0 -1
  64. package/dist/_chunks/codemods-S4mNX9Qg.js +0 -105
  65. package/dist/_chunks/codemods-S4mNX9Qg.js.map +0 -1
  66. package/dist/_chunks/index-Pt-TU9MN.js +0 -103
  67. package/dist/_chunks/index-Pt-TU9MN.js.map +0 -1
  68. package/dist/_chunks/upgrade-aWNYibWB.js +0 -361
  69. package/dist/_chunks/upgrade-aWNYibWB.js.map +0 -1
  70. package/dist/tasks/codemods/codemods.d.ts +0 -3
  71. package/dist/tasks/codemods/codemods.d.ts.map +0 -1
@@ -0,0 +1,192 @@
1
+ import type { Transform } from 'jscodeshift';
2
+ import { changeImportSpecifier } from '../../utils/change-import';
3
+ import { replaceJSXElement } from '../../utils/replace-jsx';
4
+
5
+ /**
6
+ * This codemods automates all the imports and naming changes
7
+ * for methods or components that used to be imported from '@strapi/helper-plugin'
8
+ */
9
+ const transform: Transform = (file, api) => {
10
+ const { j } = api;
11
+
12
+ const root = j.withParser('tsx')(file.source);
13
+
14
+ type Replacement = {
15
+ oldName: string;
16
+ oldDependency: string;
17
+ toReplace: boolean;
18
+ toChangeImportSpecifier: boolean;
19
+ newDependency?: string;
20
+ newName?: string;
21
+ newImport?: string;
22
+ };
23
+
24
+ const replacements: Replacement[] = [
25
+ {
26
+ oldName: 'AnErrorOccurred',
27
+ newImport: 'Page',
28
+ newName: 'Page.Error',
29
+ oldDependency: '@strapi/helper-plugin',
30
+ newDependency: '@strapi/strapi/admin',
31
+ toReplace: true,
32
+ toChangeImportSpecifier: true,
33
+ },
34
+ {
35
+ oldName: 'CheckPagePermissions',
36
+ newImport: 'Page',
37
+ newName: 'Page.Protect',
38
+ oldDependency: '@strapi/helper-plugin',
39
+ newDependency: '@strapi/strapi/admin',
40
+ toReplace: true,
41
+ toChangeImportSpecifier: true,
42
+ },
43
+ {
44
+ oldName: 'ConfirmDialog',
45
+ oldDependency: '@strapi/helper-plugin',
46
+ newDependency: '@strapi/strapi/admin',
47
+ toChangeImportSpecifier: true,
48
+ toReplace: false,
49
+ },
50
+ {
51
+ oldName: 'DateTimePicker',
52
+ oldDependency: '@strapi/helper-plugin',
53
+ newDependency: '@strapi/design-system',
54
+ toChangeImportSpecifier: true,
55
+ toReplace: false,
56
+ },
57
+ {
58
+ oldName: 'getFetchClient',
59
+ oldDependency: '@strapi/helper-plugin',
60
+ newDependency: '@strapi/strapi/admin',
61
+ toChangeImportSpecifier: true,
62
+ toReplace: false,
63
+ },
64
+ {
65
+ oldName: 'LoadingIndicatorPage',
66
+ newImport: 'Page',
67
+ newName: 'Page.Loading',
68
+ oldDependency: '@strapi/helper-plugin',
69
+ newDependency: '@strapi/strapi/admin',
70
+ toReplace: true,
71
+ toChangeImportSpecifier: true,
72
+ },
73
+ {
74
+ oldName: 'NoContent',
75
+ newImport: 'EmptyStateLayout',
76
+ newName: 'EmptyStateLayout',
77
+ oldDependency: '@strapi/helper-plugin',
78
+ newDependency: '@strapi/design-system',
79
+ toReplace: true,
80
+ toChangeImportSpecifier: true,
81
+ },
82
+ {
83
+ oldName: 'NoPermissions',
84
+ newImport: 'Page',
85
+ newName: 'Page.NoPermissions',
86
+ oldDependency: '@strapi/helper-plugin',
87
+ newDependency: '@strapi/strapi/admin',
88
+ toReplace: true,
89
+ toChangeImportSpecifier: true,
90
+ },
91
+ {
92
+ oldName: 'Status',
93
+ oldDependency: '@strapi/helper-plugin',
94
+ newDependency: '@strapi/design-system',
95
+ toChangeImportSpecifier: true,
96
+ toReplace: false,
97
+ },
98
+ {
99
+ oldName: 'translatedErrors',
100
+ oldDependency: '@strapi/helper-plugin',
101
+ newDependency: '@strapi/strapi/admin',
102
+ toChangeImportSpecifier: true,
103
+ toReplace: false,
104
+ },
105
+ {
106
+ oldName: 'useAPIErrorHandler',
107
+ oldDependency: '@strapi/helper-plugin',
108
+ newDependency: '@strapi/strapi/admin',
109
+ toChangeImportSpecifier: true,
110
+ toReplace: false,
111
+ },
112
+ {
113
+ oldName: 'useCallbackRef',
114
+ oldDependency: '@strapi/helper-plugin',
115
+ newDependency: '@strapi/design-system',
116
+ toChangeImportSpecifier: true,
117
+ toReplace: false,
118
+ },
119
+ {
120
+ oldName: 'useCollator',
121
+ oldDependency: '@strapi/helper-plugin',
122
+ newDependency: '@strapi/design-system',
123
+ toChangeImportSpecifier: true,
124
+ toReplace: false,
125
+ },
126
+ {
127
+ oldName: 'useFetchClient',
128
+ oldDependency: '@strapi/helper-plugin',
129
+ newDependency: '@strapi/strapi/admin',
130
+ toChangeImportSpecifier: true,
131
+ toReplace: false,
132
+ },
133
+ {
134
+ oldName: 'useFilter',
135
+ oldDependency: '@strapi/helper-plugin',
136
+ newDependency: '@strapi/design-system',
137
+ toChangeImportSpecifier: true,
138
+ toReplace: false,
139
+ },
140
+ {
141
+ oldName: 'useQueryParams',
142
+ oldDependency: '@strapi/helper-plugin',
143
+ newDependency: '@strapi/strapi/admin',
144
+ toChangeImportSpecifier: true,
145
+ toReplace: false,
146
+ },
147
+ {
148
+ oldName: 'useRBAC',
149
+ oldDependency: '@strapi/helper-plugin',
150
+ newDependency: '@strapi/strapi/admin',
151
+ toChangeImportSpecifier: true,
152
+ toReplace: false,
153
+ },
154
+ {
155
+ oldName: 'SearchURLQuery',
156
+ oldDependency: '@strapi/helper-plugin',
157
+ newDependency: '@strapi/strapi/admin',
158
+ toChangeImportSpecifier: true,
159
+ toReplace: false,
160
+ },
161
+ {
162
+ oldName: 'useSettingsForm',
163
+ oldDependency: '@strapi/helper-plugin',
164
+ newDependency: '@strapi/strapi/admin',
165
+ toChangeImportSpecifier: true,
166
+ toReplace: false,
167
+ },
168
+ ];
169
+
170
+ replacements.forEach((replacement) => {
171
+ if (replacement.toReplace && replacement.newName) {
172
+ replaceJSXElement(root, j, {
173
+ oldElementName: replacement.oldName,
174
+ newElementName: replacement.newName,
175
+ oldDependency: replacement.oldDependency,
176
+ });
177
+ }
178
+
179
+ if (replacement.toChangeImportSpecifier && replacement.newDependency) {
180
+ changeImportSpecifier(root, j, {
181
+ oldMethodName: replacement.oldName,
182
+ newMethodName: replacement.newImport,
183
+ oldDependency: replacement.oldDependency,
184
+ newDependency: replacement.newDependency,
185
+ });
186
+ }
187
+ });
188
+
189
+ return root.toSource();
190
+ };
191
+
192
+ export default transform;
@@ -0,0 +1,437 @@
1
+ import type { Transform, JSCodeshift, ASTPath, ObjectExpression } from 'jscodeshift';
2
+
3
+ /*
4
+ This codemod transforms entity service calls to match the new document service interface.
5
+ It supports all kind of argument parsing, including spread elements & deeply nested objects.
6
+
7
+ Here is a list of scenarios this was tested against
8
+
9
+ const uid = "api::xxx.xxx";
10
+ const entityId = 1;
11
+
12
+ Case: basic call
13
+
14
+ strapi.entityService.findOne(uid, entityId, {
15
+ fields: ["id", "name", "description"],
16
+ populate: ["author", "comments"],
17
+ publicationState: "preview",
18
+ });
19
+
20
+
21
+ Case: using a variable declared somewhere else
22
+
23
+ const objectParam_2 = {
24
+ fields: ["id", "name", "description"],
25
+ populate: ["author", "comments"],
26
+ publicationState: "preview",
27
+ };
28
+
29
+ strapi.entityService.findOne(uid, entityId, objectParam_2);
30
+
31
+ Case: using a variable declared somewhere else with a spread element
32
+
33
+ const objectParam_3 = {
34
+ fields: ["id", "name", "description"],
35
+ populate: ["author", "comments"],
36
+ publicationState: "preview",
37
+ };
38
+
39
+ strapi.entityService.findOne(uid, entityId, {
40
+ ...objectParam_3,
41
+ });
42
+
43
+
44
+ Case: using a variable declared somewhere else with a spread element and overwritten properties
45
+
46
+ const objectParam_4_1 = {
47
+ fields: ["id", "name", "description"],
48
+ populate: ["author", "comments"],
49
+ publicationState: "preview",
50
+ };
51
+
52
+ const objectParam_4 = {
53
+ publicationState: "live",
54
+ ...objectParam_4_1,
55
+ };
56
+
57
+ strapi.entityService.findOne(uid, entityId, {
58
+ ...objectParam_4,
59
+ });
60
+
61
+ Case: using a variable declared somewhere else with a spread array element while that need its 1st element to be moved
62
+
63
+ const objectParam_5 = [
64
+ uid,
65
+ entityId,
66
+ {
67
+ fields: ["id", "name", "description"],
68
+ populate: ["author", "comments"],
69
+ publicationState: "preview",
70
+ },
71
+ ];
72
+
73
+ strapi.entityService.findOne(...objectParam_5);
74
+
75
+ Case: using a variable declared somewhere else with a partial spread array
76
+
77
+ const objectParam_6 = [
78
+ entityId,
79
+ {
80
+ fields: ["id", "name", "description"],
81
+ populate: ["author", "comments"],
82
+ publicationState: "preview",
83
+ },
84
+ ];
85
+
86
+ strapi.entityService.findOne(uid, ...objectParam_6);
87
+
88
+ Case: using a variable declared somewhere else with a partial & nested spread arrays
89
+
90
+ const objectParam_7_1 = [
91
+ {
92
+ fields: ["id", "name", "description"],
93
+ populate: ["author", "comments"],
94
+ publicationState: "preview",
95
+ },
96
+ ];
97
+
98
+ const objectParam_7 = [entityId, ...objectParam_7_1];
99
+
100
+ strapi.entityService.findOne(uid, ...objectParam_7);
101
+
102
+ Case: using a variable declared somewhere else with a partial & nested spread arrays & objects
103
+
104
+ const objectParam_8_1 = {
105
+ publicationState: "preview",
106
+ };
107
+
108
+ const objectParam_8 = [
109
+ entityId,
110
+ {
111
+ fields: ["id", "name", "description"],
112
+ populate: ["author", "comments"],
113
+ ...objectParam_8_1,
114
+ },
115
+ ];
116
+
117
+ strapi.entityService.findOne(uid, ...objectParam_8);
118
+
119
+
120
+ Case: some sort of mix of all the above
121
+
122
+ const objectParam_9_1 = {
123
+ publicationState: "preview",
124
+ };
125
+
126
+ const objectParam_9 = {
127
+ fields: ["id", "name", "description"],
128
+ populate: ["author", "comments"],
129
+ ...objectParam_9_1,
130
+ };
131
+
132
+ strapi.entityService.findOne(uid, ...[entityId, [objectParam_9]]);
133
+
134
+ Case: even more complex
135
+
136
+ const objectParam_10_1 = {
137
+ publicationState: "preview",
138
+ };
139
+
140
+ const objectParam_10_2 = [uid, ...[12], ...[objectParam_10_1]];
141
+ const objectParam_10 = [...objectParam_10_2];
142
+
143
+ strapi.entityService.findOne(...[...objectParam_10]);
144
+
145
+ Case: find, create, update, delete with entityId as first argument
146
+
147
+ strapi.entityService.findMany(uid, {
148
+ fields: ["id", "name", "description"],
149
+ populate: ["author", "comments"],
150
+ publicationState: "preview",
151
+ });
152
+
153
+ strapi.entityService.create(uid, {
154
+ data: {
155
+ name: "John Doe",
156
+ age: 30,
157
+ },
158
+ });
159
+
160
+ strapi.entityService.update(uid, entityId, {
161
+ data: {
162
+ name: "John Doe",
163
+ age: 30,
164
+ },
165
+ });
166
+
167
+ strapi.entityService.delete(uid, entityId);
168
+ strapi.entityService.findOne(uid, entityId);
169
+
170
+ */
171
+
172
+ const movedFunctions = ['findOne', 'findMany', 'count', 'create', 'update', 'delete'];
173
+
174
+ const functionsWithEntityId = ['findOne', 'update', 'delete'];
175
+
176
+ const transformDeclaration = (path: ASTPath<any>, name: any, j: JSCodeshift) => {
177
+ const declaration = findClosestDeclaration(path, name, j);
178
+
179
+ if (!declaration) {
180
+ return;
181
+ }
182
+
183
+ transformElement(path, declaration.init, j);
184
+ };
185
+
186
+ const transformElement = (path: ASTPath<any>, element: any, j: JSCodeshift) => {
187
+ switch (true) {
188
+ case j.ObjectExpression.check(element): {
189
+ transformObjectParam(path, element, j);
190
+ break;
191
+ }
192
+
193
+ case j.Identifier.check(element): {
194
+ transformDeclaration(path, element.name, j);
195
+ break;
196
+ }
197
+
198
+ case j.SpreadElement.check(element): {
199
+ transformElement(path, element.argument, j);
200
+ break;
201
+ }
202
+
203
+ case j.ArrayExpression.check(element): {
204
+ element.elements.forEach((element) => {
205
+ transformElement(path, element, j);
206
+ });
207
+ break;
208
+ }
209
+ default: {
210
+ break;
211
+ }
212
+ }
213
+ };
214
+
215
+ const transformObjectParam = (path: ASTPath<any>, expression: ObjectExpression, j: JSCodeshift) => {
216
+ expression.properties.forEach((prop) => {
217
+ switch (true) {
218
+ case j.ObjectProperty.check(prop): {
219
+ if (!j.Identifier.check(prop.key) && !j.Literal.check(prop.key)) {
220
+ return;
221
+ }
222
+
223
+ if (j.Identifier.check(prop.key) && prop.key.name !== 'publicationState') {
224
+ return;
225
+ }
226
+
227
+ if (j.Literal.check(prop.key) && prop.key.value !== 'publicationState') {
228
+ return;
229
+ }
230
+
231
+ if (j.Identifier.check(prop.key) && prop.key.name === 'publicationState') {
232
+ if (!prop.computed && !prop.shorthand) {
233
+ prop.key.name = 'status';
234
+ }
235
+
236
+ if (prop.shorthand && !prop.computed) {
237
+ prop.shorthand = false;
238
+ prop.key = j.identifier('status');
239
+ prop.value = j.identifier('publicationState');
240
+ }
241
+ } else if (j.Literal.check(prop.key) && prop.key.value === 'publicationState') {
242
+ prop.key.value = 'status';
243
+ }
244
+
245
+ switch (true) {
246
+ case j.Literal.check(prop.value): {
247
+ prop.value = prop.value.value === 'live' ? j.literal('published') : j.literal('draft');
248
+
249
+ break;
250
+ }
251
+ case j.Identifier.check(prop.value): {
252
+ const declaration = findClosestDeclaration(path, prop.value.name, j);
253
+
254
+ if (!declaration) {
255
+ return;
256
+ }
257
+
258
+ if (j.Literal.check(declaration.init)) {
259
+ declaration.init =
260
+ declaration.init.value === 'live' ? j.literal('published') : j.literal('draft');
261
+ }
262
+
263
+ break;
264
+ }
265
+ default: {
266
+ break;
267
+ }
268
+ }
269
+
270
+ break;
271
+ }
272
+ case j.SpreadElement.check(prop): {
273
+ transformElement(path, prop.argument, j);
274
+ break;
275
+ }
276
+ default: {
277
+ break;
278
+ }
279
+ }
280
+ });
281
+ };
282
+
283
+ const findClosestDeclaration = (path: ASTPath<any>, name: string, j) => {
284
+ // find Identifier declaration
285
+ const scope = path.scope.lookup(name);
286
+
287
+ if (!scope) {
288
+ return;
289
+ }
290
+
291
+ return j(scope.path)
292
+ .find(j.VariableDeclarator, { id: { type: 'Identifier', name } })
293
+ .nodes()[0];
294
+ };
295
+
296
+ const transform: Transform = (file, api) => {
297
+ const j = api.jscodeshift;
298
+
299
+ const root = j(file.source);
300
+
301
+ root
302
+ .find(j.CallExpression, {
303
+ callee: {
304
+ type: 'MemberExpression',
305
+ object: {
306
+ type: 'MemberExpression',
307
+ object: {
308
+ type: 'Identifier',
309
+ name: 'strapi',
310
+ },
311
+ property: {
312
+ type: 'Identifier',
313
+ name: 'entityService',
314
+ },
315
+ },
316
+ property: {
317
+ type: 'Identifier',
318
+ name: (name) => movedFunctions.includes(name),
319
+ },
320
+ },
321
+ })
322
+ .replaceWith((path) => {
323
+ if (!j.MemberExpression.check(path.value.callee)) {
324
+ return;
325
+ }
326
+
327
+ const args = path.value.arguments;
328
+
329
+ if (args.length === 0) {
330
+ // we don't know how to transform this
331
+ return;
332
+ }
333
+
334
+ type Args = typeof path.value.arguments;
335
+
336
+ function resolveArgs(args: Args): Args {
337
+ return args.flatMap((arg: Args[number]) => {
338
+ switch (true) {
339
+ case j.Identifier.check(arg):
340
+ case j.Literal.check(arg): {
341
+ return arg;
342
+ }
343
+ case j.SpreadElement.check(arg): {
344
+ switch (true) {
345
+ case j.Identifier.check(arg.argument): {
346
+ const identifier = arg.argument;
347
+
348
+ const declaration = findClosestDeclaration(path, identifier.name, j);
349
+
350
+ if (!declaration) {
351
+ return arg;
352
+ }
353
+
354
+ switch (true) {
355
+ case j.ArrayExpression.check(declaration.init): {
356
+ return resolveArgs(declaration.init.elements);
357
+ }
358
+ default:
359
+ return arg;
360
+ }
361
+ }
362
+ case j.ArrayExpression.check(arg.argument): {
363
+ return resolveArgs(arg.argument.elements as Args);
364
+ }
365
+ default: {
366
+ return arg;
367
+ }
368
+ }
369
+ }
370
+ default: {
371
+ return arg;
372
+ }
373
+ }
374
+ });
375
+ }
376
+
377
+ const resolvedArgs = resolveArgs(args);
378
+
379
+ const [docUID, ...rest] = resolvedArgs;
380
+
381
+ // function with entityId as first argument
382
+ if (
383
+ j.Identifier.check(path.value.callee.property) &&
384
+ functionsWithEntityId.includes(path.value.callee.property.name)
385
+ ) {
386
+ rest.splice(0, 1);
387
+
388
+ // in case no extra params are passed in the function e.g delete(uid, entityId)
389
+ if (rest.length === 0) {
390
+ rest.push(
391
+ j.objectExpression.from({
392
+ properties: [],
393
+ })
394
+ );
395
+ }
396
+
397
+ const params = rest[0];
398
+
399
+ const placeholder = j.objectProperty(j.identifier('documentId'), j.literal('__TODO__'));
400
+
401
+ // add documentId to params with a placeholder
402
+ if (j.ObjectExpression.check(params)) {
403
+ params.properties.unshift(placeholder);
404
+ } else if (j.Identifier.check(params)) {
405
+ const declaration = findClosestDeclaration(path, params.name, j);
406
+
407
+ if (!declaration) {
408
+ return;
409
+ }
410
+
411
+ if (j.ObjectExpression.check(declaration.init)) {
412
+ declaration.init.properties.unshift(placeholder);
413
+ }
414
+ }
415
+ }
416
+
417
+ path.value.arguments.forEach((arg) => {
418
+ transformElement(path, arg, j);
419
+ });
420
+
421
+ return j.callExpression(
422
+ j.memberExpression(
423
+ j.callExpression(j.memberExpression(j.identifier('strapi'), j.identifier('documents')), [
424
+ docUID,
425
+ ]),
426
+ path.value.callee.property
427
+ ),
428
+ rest
429
+ );
430
+ });
431
+
432
+ return root.toSource();
433
+ };
434
+
435
+ export const parser = 'tsx';
436
+
437
+ export default transform;