@payloadcms/codemod 4.0.0-internal.f15737c → 4.0.0-internal.f2a04f7

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 (50) hide show
  1. package/README.md +5 -2
  2. package/dist/registry.d.ts.map +1 -1
  3. package/dist/registry.js +6 -0
  4. package/dist/registry.js.map +1 -1
  5. package/dist/runbook/payload-v4-upgrade.md +2 -2
  6. package/dist/runbook/v4.mdx +291 -74
  7. package/dist/transforms/migrate-admin-context-properties/basic.input.js +32 -0
  8. package/dist/transforms/migrate-admin-context-properties/basic.input.js.map +1 -0
  9. package/dist/transforms/migrate-admin-context-properties/basic.output.js +30 -0
  10. package/dist/transforms/migrate-admin-context-properties/basic.output.js.map +1 -0
  11. package/dist/transforms/migrate-admin-context-properties/index.d.ts +3 -0
  12. package/dist/transforms/migrate-admin-context-properties/index.d.ts.map +1 -0
  13. package/dist/transforms/migrate-admin-context-properties/index.js +302 -0
  14. package/dist/transforms/migrate-admin-context-properties/index.js.map +1 -0
  15. package/dist/transforms/migrate-admin-context-properties/no-match.input.js +30 -0
  16. package/dist/transforms/migrate-admin-context-properties/no-match.input.js.map +1 -0
  17. package/dist/transforms/migrate-admin-context-properties/no-match.output.js +30 -0
  18. package/dist/transforms/migrate-admin-context-properties/no-match.output.js.map +1 -0
  19. package/dist/transforms/migrate-displayed-field-value-args/basic.input.js +4 -0
  20. package/dist/transforms/migrate-displayed-field-value-args/basic.input.js.map +1 -0
  21. package/dist/transforms/migrate-displayed-field-value-args/basic.output.js +8 -0
  22. package/dist/transforms/migrate-displayed-field-value-args/basic.output.js.map +1 -0
  23. package/dist/transforms/migrate-displayed-field-value-args/index.d.ts +3 -0
  24. package/dist/transforms/migrate-displayed-field-value-args/index.d.ts.map +1 -0
  25. package/dist/transforms/migrate-displayed-field-value-args/index.js +84 -0
  26. package/dist/transforms/migrate-displayed-field-value-args/index.js.map +1 -0
  27. package/dist/transforms/migrate-displayed-field-value-args/namespace.input.js +4 -0
  28. package/dist/transforms/migrate-displayed-field-value-args/namespace.input.js.map +1 -0
  29. package/dist/transforms/migrate-displayed-field-value-args/namespace.output.js +8 -0
  30. package/dist/transforms/migrate-displayed-field-value-args/namespace.output.js.map +1 -0
  31. package/dist/transforms/migrate-displayed-field-value-args/no-match.input.js +4 -0
  32. package/dist/transforms/migrate-displayed-field-value-args/no-match.input.js.map +1 -0
  33. package/dist/transforms/migrate-displayed-field-value-args/no-match.output.js +4 -0
  34. package/dist/transforms/migrate-displayed-field-value-args/no-match.output.js.map +1 -0
  35. package/dist/transforms/rename-diff-value-props/basic.input.js +38 -0
  36. package/dist/transforms/rename-diff-value-props/basic.input.js.map +1 -0
  37. package/dist/transforms/rename-diff-value-props/basic.output.js +38 -0
  38. package/dist/transforms/rename-diff-value-props/basic.output.js.map +1 -0
  39. package/dist/transforms/rename-diff-value-props/index.d.ts +3 -0
  40. package/dist/transforms/rename-diff-value-props/index.d.ts.map +1 -0
  41. package/dist/transforms/rename-diff-value-props/index.js +328 -0
  42. package/dist/transforms/rename-diff-value-props/index.js.map +1 -0
  43. package/dist/transforms/rename-diff-value-props/no-match.input.js +8 -0
  44. package/dist/transforms/rename-diff-value-props/no-match.input.js.map +1 -0
  45. package/dist/upgrade/defaultTag.d.ts +1 -1
  46. package/dist/upgrade/defaultTag.js +2 -2
  47. package/dist/upgrade/defaultTag.js.map +1 -1
  48. package/dist/upgrade/prompt.js +2 -2
  49. package/dist/upgrade/prompt.js.map +1 -1
  50. package/package.json +8 -8
@@ -0,0 +1,32 @@
1
+ import { getRootLayoutData } from '@payloadcms/ui/layouts/Root/getRootLayoutData';
2
+ import { initAdminContext } from 'payload/internal';
3
+ export async function getLayoutData(args) {
4
+ const context = await initAdminContext(args);
5
+ const { cookies, headers, languageCode, permissions, req, user } = context;
6
+ const data = await getRootLayoutData({
7
+ cookies,
8
+ headers,
9
+ importMap: args.importMap,
10
+ languageCode,
11
+ permissions,
12
+ req,
13
+ user
14
+ });
15
+ return {
16
+ data,
17
+ userAgent: context.headers.get('user-agent')
18
+ };
19
+ }
20
+ export async function getTheme(args) {
21
+ const { headers: requestHeaders, languageCode, user } = await initAdminContext(args);
22
+ return {
23
+ languageCode,
24
+ theme: requestHeaders.get('sec-ch-prefers-color-scheme'),
25
+ user
26
+ };
27
+ }
28
+ export const getUserAgent = async (args)=>(await initAdminContext(args)).headers.get('user-agent');
29
+ export const getDirection = (context)=>context.languageCode === 'ar' ? 'rtl' : 'ltr';
30
+ export const getAcceptLanguage = ({ headers })=>headers.get('accept-language');
31
+
32
+ //# sourceMappingURL=basic.input.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/transforms/migrate-admin-context-properties/basic.input.ts"],"sourcesContent":["import type { AdminContext } from 'payload'\nimport type { InitAdminContextArgs } from 'payload/internal'\n\nimport { getRootLayoutData } from '@payloadcms/ui/layouts/Root/getRootLayoutData'\nimport { initAdminContext } from 'payload/internal'\n\ntype LayoutArgs = Pick<AdminContext, 'cookies' | 'headers' | 'languageCode' | 'req'>\n\ntype LanguageCode = AdminContext['languageCode']\n\nexport async function getLayoutData(args: InitAdminContextArgs) {\n const context = await initAdminContext(args)\n\n const { cookies, headers, languageCode, permissions, req, user } = context\n\n const data = await getRootLayoutData({\n cookies,\n headers,\n importMap: args.importMap,\n languageCode,\n permissions,\n req,\n user,\n })\n\n return { data, userAgent: context.headers.get('user-agent') }\n}\n\nexport async function getTheme(args: InitAdminContextArgs) {\n const { headers: requestHeaders, languageCode, user } = await initAdminContext(args)\n\n return { languageCode, theme: requestHeaders.get('sec-ch-prefers-color-scheme'), user }\n}\n\nexport const getUserAgent = async (args: InitAdminContextArgs) =>\n (await initAdminContext(args)).headers.get('user-agent')\n\nexport const getDirection = (context: AdminContext) =>\n context.languageCode === 'ar' ? 'rtl' : 'ltr'\n\nexport const getAcceptLanguage = ({ headers }: AdminContext) => headers.get('accept-language')\n"],"names":["getRootLayoutData","initAdminContext","getLayoutData","args","context","cookies","headers","languageCode","permissions","req","user","data","importMap","userAgent","get","getTheme","requestHeaders","theme","getUserAgent","getDirection","getAcceptLanguage"],"mappings":"AAGA,SAASA,iBAAiB,QAAQ,gDAA+C;AACjF,SAASC,gBAAgB,QAAQ,mBAAkB;AAMnD,OAAO,eAAeC,cAAcC,IAA0B;IAC5D,MAAMC,UAAU,MAAMH,iBAAiBE;IAEvC,MAAM,EAAEE,OAAO,EAAEC,OAAO,EAAEC,YAAY,EAAEC,WAAW,EAAEC,GAAG,EAAEC,IAAI,EAAE,GAAGN;IAEnE,MAAMO,OAAO,MAAMX,kBAAkB;QACnCK;QACAC;QACAM,WAAWT,KAAKS,SAAS;QACzBL;QACAC;QACAC;QACAC;IACF;IAEA,OAAO;QAAEC;QAAME,WAAWT,QAAQE,OAAO,CAACQ,GAAG,CAAC;IAAc;AAC9D;AAEA,OAAO,eAAeC,SAASZ,IAA0B;IACvD,MAAM,EAAEG,SAASU,cAAc,EAAET,YAAY,EAAEG,IAAI,EAAE,GAAG,MAAMT,iBAAiBE;IAE/E,OAAO;QAAEI;QAAcU,OAAOD,eAAeF,GAAG,CAAC;QAAgCJ;IAAK;AACxF;AAEA,OAAO,MAAMQ,eAAe,OAAOf,OACjC,AAAC,CAAA,MAAMF,iBAAiBE,KAAI,EAAGG,OAAO,CAACQ,GAAG,CAAC,cAAa;AAE1D,OAAO,MAAMK,eAAe,CAACf,UAC3BA,QAAQG,YAAY,KAAK,OAAO,QAAQ,MAAK;AAE/C,OAAO,MAAMa,oBAAoB,CAAC,EAAEd,OAAO,EAAgB,GAAKA,QAAQQ,GAAG,CAAC,mBAAkB"}
@@ -0,0 +1,30 @@
1
+ import { getRootLayoutData } from '@payloadcms/ui/layouts/Root/getRootLayoutData';
2
+ import { initAdminContext } from 'payload/internal';
3
+ export async function getLayoutData(args) {
4
+ const context = await initAdminContext(args);
5
+ const { cookies, permissions, req, user } = context;
6
+ const data = await getRootLayoutData({
7
+ cookies,
8
+ importMap: args.importMap,
9
+ permissions,
10
+ req,
11
+ user
12
+ });
13
+ return {
14
+ data,
15
+ userAgent: context.req.headers.get('user-agent')
16
+ };
17
+ }
18
+ export async function getTheme(args) {
19
+ const { req: { headers: requestHeaders, i18n: { language: languageCode } }, user } = await initAdminContext(args);
20
+ return {
21
+ languageCode,
22
+ theme: requestHeaders.get('sec-ch-prefers-color-scheme'),
23
+ user
24
+ };
25
+ }
26
+ export const getUserAgent = async (args)=>(await initAdminContext(args)).req.headers.get('user-agent');
27
+ export const getDirection = (context)=>context.req.i18n.language === 'ar' ? 'rtl' : 'ltr';
28
+ export const getAcceptLanguage = ({ req: { headers } })=>headers.get('accept-language');
29
+
30
+ //# sourceMappingURL=basic.output.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/transforms/migrate-admin-context-properties/basic.output.ts"],"sourcesContent":["import type { AdminContext } from 'payload'\nimport type { InitAdminContextArgs } from 'payload/internal'\n\nimport { getRootLayoutData } from '@payloadcms/ui/layouts/Root/getRootLayoutData'\nimport { initAdminContext } from 'payload/internal'\n\ntype LayoutArgs = Pick<AdminContext, 'cookies' | 'req'>\n\ntype LanguageCode = AdminContext['req']['i18n']['language']\n\nexport async function getLayoutData(args: InitAdminContextArgs) {\n const context = await initAdminContext(args)\n\n const { cookies, permissions, req, user } = context\n\n const data = await getRootLayoutData({\n cookies,\n importMap: args.importMap,\n permissions,\n req,\n user,\n })\n\n return { data, userAgent: context.req.headers.get('user-agent') }\n}\n\nexport async function getTheme(args: InitAdminContextArgs) {\n const { req: { headers: requestHeaders, i18n: { language: languageCode } }, user } = await initAdminContext(args)\n\n return { languageCode, theme: requestHeaders.get('sec-ch-prefers-color-scheme'), user }\n}\n\nexport const getUserAgent = async (args: InitAdminContextArgs) =>\n (await initAdminContext(args)).req.headers.get('user-agent')\n\nexport const getDirection = (context: AdminContext) =>\n context.req.i18n.language === 'ar' ? 'rtl' : 'ltr'\n\nexport const getAcceptLanguage = ({ req: { headers } }: AdminContext) => headers.get('accept-language')\n"],"names":["getRootLayoutData","initAdminContext","getLayoutData","args","context","cookies","permissions","req","user","data","importMap","userAgent","headers","get","getTheme","requestHeaders","i18n","language","languageCode","theme","getUserAgent","getDirection","getAcceptLanguage"],"mappings":"AAGA,SAASA,iBAAiB,QAAQ,gDAA+C;AACjF,SAASC,gBAAgB,QAAQ,mBAAkB;AAMnD,OAAO,eAAeC,cAAcC,IAA0B;IAC5D,MAAMC,UAAU,MAAMH,iBAAiBE;IAEvC,MAAM,EAAEE,OAAO,EAAEC,WAAW,EAAEC,GAAG,EAAEC,IAAI,EAAE,GAAGJ;IAE5C,MAAMK,OAAO,MAAMT,kBAAkB;QACnCK;QACAK,WAAWP,KAAKO,SAAS;QACzBJ;QACAC;QACAC;IACF;IAEA,OAAO;QAAEC;QAAME,WAAWP,QAAQG,GAAG,CAACK,OAAO,CAACC,GAAG,CAAC;IAAc;AAClE;AAEA,OAAO,eAAeC,SAASX,IAA0B;IACvD,MAAM,EAAEI,KAAK,EAAEK,SAASG,cAAc,EAAEC,MAAM,EAAEC,UAAUC,YAAY,EAAE,EAAE,EAAEV,IAAI,EAAE,GAAG,MAAMP,iBAAiBE;IAE5G,OAAO;QAAEe;QAAcC,OAAOJ,eAAeF,GAAG,CAAC;QAAgCL;IAAK;AACxF;AAEA,OAAO,MAAMY,eAAe,OAAOjB,OACjC,AAAC,CAAA,MAAMF,iBAAiBE,KAAI,EAAGI,GAAG,CAACK,OAAO,CAACC,GAAG,CAAC,cAAa;AAE9D,OAAO,MAAMQ,eAAe,CAACjB,UAC3BA,QAAQG,GAAG,CAACS,IAAI,CAACC,QAAQ,KAAK,OAAO,QAAQ,MAAK;AAEpD,OAAO,MAAMK,oBAAoB,CAAC,EAAEf,KAAK,EAAEK,OAAO,EAAE,EAAgB,GAAKA,QAAQC,GAAG,CAAC,mBAAkB"}
@@ -0,0 +1,3 @@
1
+ import type { Transform } from '../../types.js';
2
+ export declare const migrateAdminContextProperties: Transform;
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/transforms/migrate-admin-context-properties/index.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAwC/C,eAAO,MAAM,6BAA6B,EAAE,SA8J3C,CAAA"}
@@ -0,0 +1,302 @@
1
+ import { Node, SyntaxKind } from 'ts-morph';
2
+ /** Removed `AdminContext` properties mapped to where each value lives now. */ const ADMIN_CONTEXT_PATHS = new Map([
3
+ [
4
+ 'headers',
5
+ [
6
+ 'req',
7
+ 'headers'
8
+ ]
9
+ ],
10
+ [
11
+ 'languageCode',
12
+ [
13
+ 'req',
14
+ 'i18n',
15
+ 'language'
16
+ ]
17
+ ]
18
+ ]);
19
+ const PARTIAL_ADMIN_CONTEXT_PATHS = new Map([
20
+ [
21
+ 'languageCode',
22
+ [
23
+ 'i18n',
24
+ 'language'
25
+ ]
26
+ ]
27
+ ]);
28
+ // Pre-rename names are accepted so this transform also works without `migrate-payload-request-creation`.
29
+ const IMPORTS = {
30
+ '@payloadcms/ui/layouts/Root/getRootLayoutData': {
31
+ getRootLayoutData: {
32
+ kind: 'getRootLayoutData',
33
+ paths: ADMIN_CONTEXT_PATHS
34
+ }
35
+ },
36
+ payload: {
37
+ AdminContext: {
38
+ kind: 'context',
39
+ paths: ADMIN_CONTEXT_PATHS
40
+ },
41
+ InitReqResult: {
42
+ kind: 'context',
43
+ paths: ADMIN_CONTEXT_PATHS
44
+ }
45
+ },
46
+ 'payload/internal': {
47
+ initAdminContext: {
48
+ kind: 'initAdminContext',
49
+ paths: ADMIN_CONTEXT_PATHS
50
+ },
51
+ initReq: {
52
+ kind: 'initAdminContext',
53
+ paths: ADMIN_CONTEXT_PATHS
54
+ },
55
+ InitReqPartialResult: {
56
+ kind: 'context',
57
+ paths: PARTIAL_ADMIN_CONTEXT_PATHS
58
+ },
59
+ PartialAdminContext: {
60
+ kind: 'context',
61
+ paths: PARTIAL_ADMIN_CONTEXT_PATHS
62
+ }
63
+ }
64
+ };
65
+ export const migrateAdminContextProperties = {
66
+ name: 'migrate-admin-context-properties',
67
+ apply: ({ project })=>{
68
+ const filesChanged = [];
69
+ const notes = [];
70
+ for (const file of project.getSourceFiles()){
71
+ const imports = file.getImportDeclarations().flatMap((declaration)=>{
72
+ const source = declaration.getModuleSpecifierValue();
73
+ if (!Object.hasOwn(IMPORTS, source)) {
74
+ return [];
75
+ }
76
+ return declaration.getNamedImports().flatMap((spec)=>{
77
+ const name = spec.getAliasNode() ?? spec.getNameNode();
78
+ return Object.hasOwn(IMPORTS[source], spec.getName()) && Node.isIdentifier(name) ? [
79
+ {
80
+ ...IMPORTS[source][spec.getName()],
81
+ name
82
+ }
83
+ ] : [];
84
+ });
85
+ });
86
+ if (imports.length === 0) {
87
+ continue;
88
+ }
89
+ const original = file.getFullText();
90
+ // `getRootLayoutData` reads both values from `req` now. Removing these arguments first lets
91
+ // the destructures below drop bindings that only fed this call.
92
+ for (const { name, kind } of imports){
93
+ if (kind !== 'getRootLayoutData') {
94
+ continue;
95
+ }
96
+ for (const reference of getReferences({
97
+ name,
98
+ file
99
+ })){
100
+ const call = reference.getParent();
101
+ const [argument] = Node.isCallExpression(call) && call.getExpression() === reference ? call.getArguments() : [];
102
+ if (!Node.isObjectLiteralExpression(argument)) {
103
+ continue;
104
+ }
105
+ for (const property of argument.getProperties()){
106
+ if ((Node.isPropertyAssignment(property) || Node.isShorthandPropertyAssignment(property)) && ADMIN_CONTEXT_PATHS.has(property.getName())) {
107
+ property.remove();
108
+ }
109
+ }
110
+ }
111
+ }
112
+ const state = {
113
+ edits: new Map(),
114
+ file,
115
+ notes,
116
+ rewritten: new Set()
117
+ };
118
+ for (const { name, kind, paths } of imports){
119
+ for (const reference of kind === 'getRootLayoutData' ? [] : getReferences({
120
+ name,
121
+ file
122
+ })){
123
+ const parent = reference.getParent();
124
+ if (kind === 'initAdminContext') {
125
+ if (!Node.isCallExpression(parent) || parent.getExpression() !== reference) {
126
+ continue;
127
+ }
128
+ let expression = parent;
129
+ while(Node.isAwaitExpression(expression.getParent()) || Node.isParenthesizedExpression(expression.getParent())){
130
+ expression = expression.getParentOrThrow();
131
+ }
132
+ collectExpression({
133
+ allowAlias: true,
134
+ expression,
135
+ paths,
136
+ state
137
+ });
138
+ continue;
139
+ }
140
+ if (!Node.isTypeReference(parent) || parent.getTypeName() !== reference) {
141
+ continue;
142
+ }
143
+ const owner = parent.getParent();
144
+ if ((Node.isParameterDeclaration(owner) || Node.isVariableDeclaration(owner)) && owner.getTypeNode() === parent) {
145
+ collectBinding({
146
+ binding: owner.getNameNode(),
147
+ paths,
148
+ state
149
+ });
150
+ } else if (Node.isIndexedAccessTypeNode(owner) && owner.getObjectTypeNode() === parent) {
151
+ const index = owner.getIndexTypeNode();
152
+ const literal = Node.isLiteralTypeNode(index) ? index.getLiteral() : undefined;
153
+ const property = Node.isStringLiteral(literal) ? literal.getLiteralValue() : undefined;
154
+ const path = property === undefined ? undefined : paths.get(property);
155
+ if (path) {
156
+ state.edits.set(owner, `${parent.getText()}${path.map((key)=>`['${key}']`).join('')}`);
157
+ state.rewritten.add(property);
158
+ }
159
+ } else if (Node.isTypeReference(owner) && owner.getTypeName().getText() === 'Pick' && owner.getTypeArguments()[0] === parent) {
160
+ const keys = owner.getTypeArguments()[1];
161
+ const members = Node.isUnionTypeNode(keys) ? keys.getTypeNodes() : keys ? [
162
+ keys
163
+ ] : [];
164
+ const remaining = members.filter((member)=>{
165
+ const literal = Node.isLiteralTypeNode(member) ? member.getLiteral() : undefined;
166
+ return !(Node.isStringLiteral(literal) && paths.has(literal.getLiteralValue()));
167
+ });
168
+ if (remaining.length === members.length) {
169
+ continue;
170
+ }
171
+ if (remaining.length === 0) {
172
+ notes.push(`${file.getFilePath()}:${owner.getStartLineNumber()}: \`${owner.getText()}\` only picks properties removed in v4; migrate manually.`);
173
+ continue;
174
+ }
175
+ state.edits.set(keys, remaining.map((member)=>member.getText()).join(' | '));
176
+ }
177
+ }
178
+ }
179
+ // Apply from the end of the file so earlier edits don't shift later nodes.
180
+ for (const [node, text] of [
181
+ ...state.edits
182
+ ].sort(([a], [b])=>b.getStart() - a.getStart())){
183
+ node.replaceWithText(text);
184
+ }
185
+ if (state.rewritten.has('languageCode')) {
186
+ notes.push(`${file.getFilePath()}: \`languageCode\` reads now use \`i18n.language\`, which is typed as \`string\` instead of \`AcceptedLanguages\`. Cast where the narrower type is required.`);
187
+ }
188
+ if (file.getFullText() !== original) {
189
+ filesChanged.push(file.getFilePath());
190
+ }
191
+ }
192
+ return {
193
+ filesChanged,
194
+ ...notes.length > 0 ? {
195
+ notes
196
+ } : {}
197
+ };
198
+ },
199
+ description: 'Rewrites reads of `headers` and `languageCode`, removed from `AdminContext` in v4, to `req.headers` and `req.i18n.language`. Covers `initAdminContext()` results, bindings typed as `AdminContext` or `PartialAdminContext`, and `Pick`/indexed access types, and drops both arguments from `getRootLayoutData()` calls.'
200
+ };
201
+ /** Same-file identifiers bound to the same symbol as `name`. */ function getReferences({ name, file }) {
202
+ const symbol = name.getSymbol()?.compilerSymbol;
203
+ if (!symbol) {
204
+ return [];
205
+ }
206
+ return file.getDescendantsOfKind(SyntaxKind.Identifier).filter((identifier)=>identifier !== name && identifier.getText() === name.getText() && identifier.getSymbol()?.compilerSymbol === symbol);
207
+ }
208
+ /** Handles a variable or parameter name that holds an admin context. */ function collectBinding({ binding, paths, state }) {
209
+ if (Node.isObjectBindingPattern(binding)) {
210
+ collectPattern({
211
+ paths,
212
+ pattern: binding,
213
+ state
214
+ });
215
+ return;
216
+ }
217
+ if (!Node.isIdentifier(binding)) {
218
+ return;
219
+ }
220
+ for (const reference of binding.findReferencesAsNodes()){
221
+ if (reference !== binding && reference.getSourceFile() === state.file) {
222
+ collectExpression({
223
+ allowAlias: false,
224
+ expression: reference,
225
+ paths,
226
+ state
227
+ });
228
+ }
229
+ }
230
+ }
231
+ /** Handles an expression that evaluates to an admin context. */ function collectExpression({ allowAlias, expression, paths, state }) {
232
+ const parent = expression.getParent();
233
+ if (Node.isPropertyAccessExpression(parent) && parent.getExpression() === expression) {
234
+ const path = paths.get(parent.getName());
235
+ if (path) {
236
+ state.edits.set(parent, `${expression.getText()}${parent.hasQuestionDotToken() ? '?.' : '.'}${path.join('.')}`);
237
+ state.rewritten.add(parent.getName());
238
+ }
239
+ } else if (Node.isElementAccessExpression(parent) && parent.getExpression() === expression) {
240
+ const argument = parent.getArgumentExpression();
241
+ const path = Node.isStringLiteral(argument) ? paths.get(argument.getLiteralValue()) : undefined;
242
+ if (path) {
243
+ state.notes.push(`${state.file.getFilePath()}:${parent.getStartLineNumber()}: \`${parent.getText()}\` reads a property removed in v4; migrate manually to \`${expression.getText()}.${path.join('.')}\`.`);
244
+ }
245
+ } else if (Node.isVariableDeclaration(parent) && parent.getInitializer() === expression) {
246
+ const name = parent.getNameNode();
247
+ if (Node.isObjectBindingPattern(name) || allowAlias) {
248
+ collectBinding({
249
+ binding: name,
250
+ paths,
251
+ state
252
+ });
253
+ }
254
+ }
255
+ }
256
+ /**
257
+ * Moves removed properties out of a destructure into nested patterns, e.g.
258
+ * `{ headers, user }` becomes `{ req: { headers }, user }`. Bindings that are never read are dropped.
259
+ */ function collectPattern({ paths, pattern, state }) {
260
+ const kept = [];
261
+ const moved = new Map();
262
+ let insertIndex = -1;
263
+ for (const element of pattern.getElements()){
264
+ const propertyNameNode = element.getPropertyNameNode();
265
+ const nameNode = element.getNameNode();
266
+ const property = !propertyNameNode ? nameNode.getText() : Node.isIdentifier(propertyNameNode) ? propertyNameNode.getText() : Node.isStringLiteral(propertyNameNode) ? propertyNameNode.getLiteralValue() : undefined;
267
+ const path = element.getDotDotDotToken() || property === undefined ? undefined : paths.get(property);
268
+ if (!path) {
269
+ kept.push(element.getText());
270
+ continue;
271
+ }
272
+ if (insertIndex === -1) {
273
+ insertIndex = kept.length;
274
+ }
275
+ if (Node.isIdentifier(nameNode) && nameNode.findReferencesAsNodes().every((reference)=>reference === nameNode)) {
276
+ continue;
277
+ }
278
+ let level = moved;
279
+ for (const key of path.slice(0, -1)){
280
+ const next = level.get(key);
281
+ const child = next instanceof Map ? next : new Map();
282
+ level.set(key, child);
283
+ level = child;
284
+ }
285
+ const leaf = path.at(-1);
286
+ const initializer = element.getInitializer();
287
+ level.set(leaf, `${leaf === nameNode.getText() ? leaf : `${leaf}: ${nameNode.getText()}`}${initializer ? ` = ${initializer.getText()}` : ''}`);
288
+ state.rewritten.add(property);
289
+ }
290
+ if (insertIndex === -1) {
291
+ return;
292
+ }
293
+ kept.splice(insertIndex, 0, ...renderTree(moved));
294
+ state.edits.set(pattern, `{ ${kept.join(', ')} }`);
295
+ }
296
+ function renderTree(tree) {
297
+ return [
298
+ ...tree
299
+ ].map(([key, value])=>typeof value === 'string' ? value : `${key}: { ${renderTree(value).join(', ')} }`);
300
+ }
301
+
302
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/transforms/migrate-admin-context-properties/index.ts"],"sourcesContent":["import type { Identifier, ObjectBindingPattern, SourceFile } from 'ts-morph'\n\nimport { Node, SyntaxKind } from 'ts-morph'\n\nimport type { Transform } from '../../types.js'\n\ntype Paths = Map<string, readonly string[]>\n\n/** Removed `AdminContext` properties mapped to where each value lives now. */\nconst ADMIN_CONTEXT_PATHS: Paths = new Map([\n ['headers', ['req', 'headers']],\n ['languageCode', ['req', 'i18n', 'language']],\n])\n\nconst PARTIAL_ADMIN_CONTEXT_PATHS: Paths = new Map([['languageCode', ['i18n', 'language']]])\n\ntype ImportKind = 'context' | 'getRootLayoutData' | 'initAdminContext'\n\n// Pre-rename names are accepted so this transform also works without `migrate-payload-request-creation`.\nconst IMPORTS: Record<string, Record<string, { kind: ImportKind; paths: Paths }>> = {\n '@payloadcms/ui/layouts/Root/getRootLayoutData': {\n getRootLayoutData: { kind: 'getRootLayoutData', paths: ADMIN_CONTEXT_PATHS },\n },\n payload: {\n AdminContext: { kind: 'context', paths: ADMIN_CONTEXT_PATHS },\n InitReqResult: { kind: 'context', paths: ADMIN_CONTEXT_PATHS },\n },\n 'payload/internal': {\n initAdminContext: { kind: 'initAdminContext', paths: ADMIN_CONTEXT_PATHS },\n initReq: { kind: 'initAdminContext', paths: ADMIN_CONTEXT_PATHS },\n InitReqPartialResult: { kind: 'context', paths: PARTIAL_ADMIN_CONTEXT_PATHS },\n PartialAdminContext: { kind: 'context', paths: PARTIAL_ADMIN_CONTEXT_PATHS },\n },\n}\n\ntype State = {\n /** Replacement text keyed by node, so a node reached twice is only rewritten once. */\n edits: Map<Node, string>\n file: SourceFile\n notes: string[]\n /** Removed properties whose reads were rewritten. */\n rewritten: Set<string>\n}\n\nexport const migrateAdminContextProperties: Transform = {\n name: 'migrate-admin-context-properties',\n apply: ({ project }) => {\n const filesChanged: string[] = []\n const notes: string[] = []\n\n for (const file of project.getSourceFiles()) {\n const imports = file.getImportDeclarations().flatMap((declaration) => {\n const source = declaration.getModuleSpecifierValue()\n\n if (!Object.hasOwn(IMPORTS, source)) {\n return []\n }\n\n return declaration.getNamedImports().flatMap((spec) => {\n const name = spec.getAliasNode() ?? spec.getNameNode()\n\n return Object.hasOwn(IMPORTS[source]!, spec.getName()) && Node.isIdentifier(name)\n ? [{ ...IMPORTS[source]![spec.getName()]!, name }]\n : []\n })\n })\n\n if (imports.length === 0) {\n continue\n }\n\n const original = file.getFullText()\n\n // `getRootLayoutData` reads both values from `req` now. Removing these arguments first lets\n // the destructures below drop bindings that only fed this call.\n for (const { name, kind } of imports) {\n if (kind !== 'getRootLayoutData') {\n continue\n }\n\n for (const reference of getReferences({ name, file })) {\n const call = reference.getParent()\n const [argument] =\n Node.isCallExpression(call) && call.getExpression() === reference\n ? call.getArguments()\n : []\n\n if (!Node.isObjectLiteralExpression(argument)) {\n continue\n }\n\n for (const property of argument.getProperties()) {\n if (\n (Node.isPropertyAssignment(property) ||\n Node.isShorthandPropertyAssignment(property)) &&\n ADMIN_CONTEXT_PATHS.has(property.getName())\n ) {\n property.remove()\n }\n }\n }\n }\n\n const state: State = { edits: new Map(), file, notes, rewritten: new Set() }\n\n for (const { name, kind, paths } of imports) {\n for (const reference of kind === 'getRootLayoutData' ? [] : getReferences({ name, file })) {\n const parent = reference.getParent()\n\n if (kind === 'initAdminContext') {\n if (!Node.isCallExpression(parent) || parent.getExpression() !== reference) {\n continue\n }\n\n let expression: Node = parent\n\n while (\n Node.isAwaitExpression(expression.getParent()) ||\n Node.isParenthesizedExpression(expression.getParent())\n ) {\n expression = expression.getParentOrThrow()\n }\n\n collectExpression({ allowAlias: true, expression, paths, state })\n continue\n }\n\n if (!Node.isTypeReference(parent) || parent.getTypeName() !== reference) {\n continue\n }\n\n const owner = parent.getParent()\n\n if (\n (Node.isParameterDeclaration(owner) || Node.isVariableDeclaration(owner)) &&\n owner.getTypeNode() === parent\n ) {\n collectBinding({ binding: owner.getNameNode(), paths, state })\n } else if (Node.isIndexedAccessTypeNode(owner) && owner.getObjectTypeNode() === parent) {\n const index = owner.getIndexTypeNode()\n const literal = Node.isLiteralTypeNode(index) ? index.getLiteral() : undefined\n const property = Node.isStringLiteral(literal) ? literal.getLiteralValue() : undefined\n const path = property === undefined ? undefined : paths.get(property)\n\n if (path) {\n state.edits.set(\n owner,\n `${parent.getText()}${path.map((key) => `['${key}']`).join('')}`,\n )\n state.rewritten.add(property!)\n }\n } else if (\n Node.isTypeReference(owner) &&\n owner.getTypeName().getText() === 'Pick' &&\n owner.getTypeArguments()[0] === parent\n ) {\n const keys = owner.getTypeArguments()[1]\n const members = Node.isUnionTypeNode(keys) ? keys.getTypeNodes() : keys ? [keys] : []\n const remaining = members.filter((member) => {\n const literal = Node.isLiteralTypeNode(member) ? member.getLiteral() : undefined\n return !(Node.isStringLiteral(literal) && paths.has(literal.getLiteralValue()))\n })\n\n if (remaining.length === members.length) {\n continue\n }\n\n if (remaining.length === 0) {\n notes.push(\n `${file.getFilePath()}:${owner.getStartLineNumber()}: \\`${owner.getText()}\\` only picks properties removed in v4; migrate manually.`,\n )\n continue\n }\n\n state.edits.set(keys!, remaining.map((member) => member.getText()).join(' | '))\n }\n }\n }\n\n // Apply from the end of the file so earlier edits don't shift later nodes.\n for (const [node, text] of [...state.edits].sort(([a], [b]) => b.getStart() - a.getStart())) {\n node.replaceWithText(text)\n }\n\n if (state.rewritten.has('languageCode')) {\n notes.push(\n `${file.getFilePath()}: \\`languageCode\\` reads now use \\`i18n.language\\`, which is typed as \\`string\\` instead of \\`AcceptedLanguages\\`. Cast where the narrower type is required.`,\n )\n }\n\n if (file.getFullText() !== original) {\n filesChanged.push(file.getFilePath())\n }\n }\n\n return {\n filesChanged,\n ...(notes.length > 0 ? { notes } : {}),\n }\n },\n description:\n 'Rewrites reads of `headers` and `languageCode`, removed from `AdminContext` in v4, to `req.headers` and `req.i18n.language`. Covers `initAdminContext()` results, bindings typed as `AdminContext` or `PartialAdminContext`, and `Pick`/indexed access types, and drops both arguments from `getRootLayoutData()` calls.',\n}\n\n/** Same-file identifiers bound to the same symbol as `name`. */\nfunction getReferences({ name, file }: { file: SourceFile; name: Identifier }): Identifier[] {\n const symbol = name.getSymbol()?.compilerSymbol\n\n if (!symbol) {\n return []\n }\n\n return file\n .getDescendantsOfKind(SyntaxKind.Identifier)\n .filter(\n (identifier) =>\n identifier !== name &&\n identifier.getText() === name.getText() &&\n identifier.getSymbol()?.compilerSymbol === symbol,\n )\n}\n\n/** Handles a variable or parameter name that holds an admin context. */\nfunction collectBinding({\n binding,\n paths,\n state,\n}: {\n binding: Node\n paths: Paths\n state: State\n}): void {\n if (Node.isObjectBindingPattern(binding)) {\n collectPattern({ paths, pattern: binding, state })\n return\n }\n\n if (!Node.isIdentifier(binding)) {\n return\n }\n\n for (const reference of binding.findReferencesAsNodes()) {\n if (reference !== binding && reference.getSourceFile() === state.file) {\n collectExpression({ allowAlias: false, expression: reference, paths, state })\n }\n }\n}\n\n/** Handles an expression that evaluates to an admin context. */\nfunction collectExpression({\n allowAlias,\n expression,\n paths,\n state,\n}: {\n /** Whether to follow `const context = <expression>` to the uses of `context`. */\n allowAlias: boolean\n expression: Node\n paths: Paths\n state: State\n}): void {\n const parent = expression.getParent()\n\n if (Node.isPropertyAccessExpression(parent) && parent.getExpression() === expression) {\n const path = paths.get(parent.getName())\n\n if (path) {\n state.edits.set(\n parent,\n `${expression.getText()}${parent.hasQuestionDotToken() ? '?.' : '.'}${path.join('.')}`,\n )\n state.rewritten.add(parent.getName())\n }\n } else if (Node.isElementAccessExpression(parent) && parent.getExpression() === expression) {\n const argument = parent.getArgumentExpression()\n const path = Node.isStringLiteral(argument) ? paths.get(argument.getLiteralValue()) : undefined\n\n if (path) {\n state.notes.push(\n `${state.file.getFilePath()}:${parent.getStartLineNumber()}: \\`${parent.getText()}\\` reads a property removed in v4; migrate manually to \\`${expression.getText()}.${path.join('.')}\\`.`,\n )\n }\n } else if (Node.isVariableDeclaration(parent) && parent.getInitializer() === expression) {\n const name = parent.getNameNode()\n\n if (Node.isObjectBindingPattern(name) || allowAlias) {\n collectBinding({ binding: name, paths, state })\n }\n }\n}\n\ntype Tree = Map<string, string | Tree>\n\n/**\n * Moves removed properties out of a destructure into nested patterns, e.g.\n * `{ headers, user }` becomes `{ req: { headers }, user }`. Bindings that are never read are dropped.\n */\nfunction collectPattern({\n paths,\n pattern,\n state,\n}: {\n paths: Paths\n pattern: ObjectBindingPattern\n state: State\n}): void {\n const kept: string[] = []\n const moved: Tree = new Map()\n let insertIndex = -1\n\n for (const element of pattern.getElements()) {\n const propertyNameNode = element.getPropertyNameNode()\n const nameNode = element.getNameNode()\n const property = !propertyNameNode\n ? nameNode.getText()\n : Node.isIdentifier(propertyNameNode)\n ? propertyNameNode.getText()\n : Node.isStringLiteral(propertyNameNode)\n ? propertyNameNode.getLiteralValue()\n : undefined\n const path =\n element.getDotDotDotToken() || property === undefined ? undefined : paths.get(property)\n\n if (!path) {\n kept.push(element.getText())\n continue\n }\n\n if (insertIndex === -1) {\n insertIndex = kept.length\n }\n\n if (\n Node.isIdentifier(nameNode) &&\n nameNode.findReferencesAsNodes().every((reference) => reference === nameNode)\n ) {\n continue\n }\n\n let level = moved\n\n for (const key of path.slice(0, -1)) {\n const next = level.get(key)\n const child = next instanceof Map ? next : new Map<string, string | Tree>()\n level.set(key, child)\n level = child\n }\n\n const leaf = path.at(-1)!\n const initializer = element.getInitializer()\n\n level.set(\n leaf,\n `${leaf === nameNode.getText() ? leaf : `${leaf}: ${nameNode.getText()}`}${initializer ? ` = ${initializer.getText()}` : ''}`,\n )\n state.rewritten.add(property!)\n }\n\n if (insertIndex === -1) {\n return\n }\n\n kept.splice(insertIndex, 0, ...renderTree(moved))\n state.edits.set(pattern, `{ ${kept.join(', ')} }`)\n}\n\nfunction renderTree(tree: Tree): string[] {\n return [...tree].map(([key, value]) =>\n typeof value === 'string' ? value : `${key}: { ${renderTree(value).join(', ')} }`,\n )\n}\n"],"names":["Node","SyntaxKind","ADMIN_CONTEXT_PATHS","Map","PARTIAL_ADMIN_CONTEXT_PATHS","IMPORTS","getRootLayoutData","kind","paths","payload","AdminContext","InitReqResult","initAdminContext","initReq","InitReqPartialResult","PartialAdminContext","migrateAdminContextProperties","name","apply","project","filesChanged","notes","file","getSourceFiles","imports","getImportDeclarations","flatMap","declaration","source","getModuleSpecifierValue","Object","hasOwn","getNamedImports","spec","getAliasNode","getNameNode","getName","isIdentifier","length","original","getFullText","reference","getReferences","call","getParent","argument","isCallExpression","getExpression","getArguments","isObjectLiteralExpression","property","getProperties","isPropertyAssignment","isShorthandPropertyAssignment","has","remove","state","edits","rewritten","Set","parent","expression","isAwaitExpression","isParenthesizedExpression","getParentOrThrow","collectExpression","allowAlias","isTypeReference","getTypeName","owner","isParameterDeclaration","isVariableDeclaration","getTypeNode","collectBinding","binding","isIndexedAccessTypeNode","getObjectTypeNode","index","getIndexTypeNode","literal","isLiteralTypeNode","getLiteral","undefined","isStringLiteral","getLiteralValue","path","get","set","getText","map","key","join","add","getTypeArguments","keys","members","isUnionTypeNode","getTypeNodes","remaining","filter","member","push","getFilePath","getStartLineNumber","node","text","sort","a","b","getStart","replaceWithText","description","symbol","getSymbol","compilerSymbol","getDescendantsOfKind","Identifier","identifier","isObjectBindingPattern","collectPattern","pattern","findReferencesAsNodes","getSourceFile","isPropertyAccessExpression","hasQuestionDotToken","isElementAccessExpression","getArgumentExpression","getInitializer","kept","moved","insertIndex","element","getElements","propertyNameNode","getPropertyNameNode","nameNode","getDotDotDotToken","every","level","slice","next","child","leaf","at","initializer","splice","renderTree","tree","value"],"mappings":"AAEA,SAASA,IAAI,EAAEC,UAAU,QAAQ,WAAU;AAM3C,4EAA4E,GAC5E,MAAMC,sBAA6B,IAAIC,IAAI;IACzC;QAAC;QAAW;YAAC;YAAO;SAAU;KAAC;IAC/B;QAAC;QAAgB;YAAC;YAAO;YAAQ;SAAW;KAAC;CAC9C;AAED,MAAMC,8BAAqC,IAAID,IAAI;IAAC;QAAC;QAAgB;YAAC;YAAQ;SAAW;KAAC;CAAC;AAI3F,yGAAyG;AACzG,MAAME,UAA8E;IAClF,iDAAiD;QAC/CC,mBAAmB;YAAEC,MAAM;YAAqBC,OAAON;QAAoB;IAC7E;IACAO,SAAS;QACPC,cAAc;YAAEH,MAAM;YAAWC,OAAON;QAAoB;QAC5DS,eAAe;YAAEJ,MAAM;YAAWC,OAAON;QAAoB;IAC/D;IACA,oBAAoB;QAClBU,kBAAkB;YAAEL,MAAM;YAAoBC,OAAON;QAAoB;QACzEW,SAAS;YAAEN,MAAM;YAAoBC,OAAON;QAAoB;QAChEY,sBAAsB;YAAEP,MAAM;YAAWC,OAAOJ;QAA4B;QAC5EW,qBAAqB;YAAER,MAAM;YAAWC,OAAOJ;QAA4B;IAC7E;AACF;AAWA,OAAO,MAAMY,gCAA2C;IACtDC,MAAM;IACNC,OAAO,CAAC,EAAEC,OAAO,EAAE;QACjB,MAAMC,eAAyB,EAAE;QACjC,MAAMC,QAAkB,EAAE;QAE1B,KAAK,MAAMC,QAAQH,QAAQI,cAAc,GAAI;YAC3C,MAAM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AAQG;QACV;QAEA,MAAMC,OAAOzD,KAAK0D,EAAE,CAAC,CAAC;QACtB,MAAMC,cAAcb,QAAQJ,cAAc;QAE1CW,MAAMnD,GAAG,CACPuD,MACA,GAAGA,SAASP,SAAS/C,OAAO,KAAKsD,OAAO,GAAGA,KAAK,EAAE,EAAEP,SAAS/C,OAAO,IAAI,GAAGwD,cAAc,CAAC,GAAG,EAAEA,YAAYxD,OAAO,IAAI,GAAG,IAAI;QAE/HhC,MAAME,SAAS,CAACkC,GAAG,CAAC1C;IACtB;IAEA,IAAIgF,gBAAgB,CAAC,GAAG;QACtB;IACF;IAEAF,KAAKiB,MAAM,CAACf,aAAa,MAAMgB,WAAWjB;IAC1CzE,MAAMC,KAAK,CAAC8B,GAAG,CAACiC,SAAS,CAAC,EAAE,EAAEQ,KAAKrC,IAAI,CAAC,MAAM,EAAE,CAAC;AACnD;AAEA,SAASuD,WAAWC,IAAU;IAC5B,OAAO;WAAIA;KAAK,CAAC1D,GAAG,CAAC,CAAC,CAACC,KAAK0D,MAAM,GAChC,OAAOA,UAAU,WAAWA,QAAQ,GAAG1D,IAAI,IAAI,EAAEwD,WAAWE,OAAOzD,IAAI,CAAC,MAAM,EAAE,CAAC;AAErF"}
@@ -0,0 +1,30 @@
1
+ import { initAdminContext } from 'payload/internal';
2
+ export async function getRequestInfo(request) {
3
+ const { headers } = request;
4
+ const response = await fetch(request.url, {
5
+ headers
6
+ });
7
+ return {
8
+ headers: response.headers,
9
+ status: response.status
10
+ };
11
+ }
12
+ export async function getContext(args) {
13
+ const { cookies, req } = await initAdminContext(args);
14
+ return {
15
+ cookies,
16
+ userAgent: req.headers.get('user-agent')
17
+ };
18
+ }
19
+ export function getLanguage(languageCode, context) {
20
+ const initAdminContext = (value)=>value;
21
+ return {
22
+ context,
23
+ headers: initAdminContext({
24
+ headers: new Headers()
25
+ }).headers,
26
+ languageCode
27
+ };
28
+ }
29
+
30
+ //# sourceMappingURL=no-match.input.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/transforms/migrate-admin-context-properties/no-match.input.ts"],"sourcesContent":["import type { AdminContext } from 'payload'\n\nimport { initAdminContext } from 'payload/internal'\n\ntype Context = Pick<AdminContext, 'cookies' | 'req'>\n\nexport async function getRequestInfo(request: Request) {\n const { headers } = request\n const response = await fetch(request.url, { headers })\n\n return { headers: response.headers, status: response.status }\n}\n\nexport async function getContext(args: Parameters<typeof initAdminContext>[0]) {\n const { cookies, req } = await initAdminContext(args)\n\n return { cookies, userAgent: req.headers.get('user-agent') }\n}\n\nexport function getLanguage(languageCode: string, context: Context) {\n const initAdminContext = (value: { headers: Headers }) => value\n\n return { context, headers: initAdminContext({ headers: new Headers() }).headers, languageCode }\n}\n"],"names":["initAdminContext","getRequestInfo","request","headers","response","fetch","url","status","getContext","args","cookies","req","userAgent","get","getLanguage","languageCode","context","value","Headers"],"mappings":"AAEA,SAASA,gBAAgB,QAAQ,mBAAkB;AAInD,OAAO,eAAeC,eAAeC,OAAgB;IACnD,MAAM,EAAEC,OAAO,EAAE,GAAGD;IACpB,MAAME,WAAW,MAAMC,MAAMH,QAAQI,GAAG,EAAE;QAAEH;IAAQ;IAEpD,OAAO;QAAEA,SAASC,SAASD,OAAO;QAAEI,QAAQH,SAASG,MAAM;IAAC;AAC9D;AAEA,OAAO,eAAeC,WAAWC,IAA4C;IAC3E,MAAM,EAAEC,OAAO,EAAEC,GAAG,EAAE,GAAG,MAAMX,iBAAiBS;IAEhD,OAAO;QAAEC;QAASE,WAAWD,IAAIR,OAAO,CAACU,GAAG,CAAC;IAAc;AAC7D;AAEA,OAAO,SAASC,YAAYC,YAAoB,EAAEC,OAAgB;IAChE,MAAMhB,mBAAmB,CAACiB,QAAgCA;IAE1D,OAAO;QAAED;QAASb,SAASH,iBAAiB;YAAEG,SAAS,IAAIe;QAAU,GAAGf,OAAO;QAAEY;IAAa;AAChG"}
@@ -0,0 +1,30 @@
1
+ import { initAdminContext } from 'payload/internal';
2
+ export async function getRequestInfo(request) {
3
+ const { headers } = request;
4
+ const response = await fetch(request.url, {
5
+ headers
6
+ });
7
+ return {
8
+ headers: response.headers,
9
+ status: response.status
10
+ };
11
+ }
12
+ export async function getContext(args) {
13
+ const { cookies, req } = await initAdminContext(args);
14
+ return {
15
+ cookies,
16
+ userAgent: req.headers.get('user-agent')
17
+ };
18
+ }
19
+ export function getLanguage(languageCode, context) {
20
+ const initAdminContext = (value)=>value;
21
+ return {
22
+ context,
23
+ headers: initAdminContext({
24
+ headers: new Headers()
25
+ }).headers,
26
+ languageCode
27
+ };
28
+ }
29
+
30
+ //# sourceMappingURL=no-match.output.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/transforms/migrate-admin-context-properties/no-match.output.ts"],"sourcesContent":["import type { AdminContext } from 'payload'\n\nimport { initAdminContext } from 'payload/internal'\n\ntype Context = Pick<AdminContext, 'cookies' | 'req'>\n\nexport async function getRequestInfo(request: Request) {\n const { headers } = request\n const response = await fetch(request.url, { headers })\n\n return { headers: response.headers, status: response.status }\n}\n\nexport async function getContext(args: Parameters<typeof initAdminContext>[0]) {\n const { cookies, req } = await initAdminContext(args)\n\n return { cookies, userAgent: req.headers.get('user-agent') }\n}\n\nexport function getLanguage(languageCode: string, context: Context) {\n const initAdminContext = (value: { headers: Headers }) => value\n\n return { context, headers: initAdminContext({ headers: new Headers() }).headers, languageCode }\n}\n"],"names":["initAdminContext","getRequestInfo","request","headers","response","fetch","url","status","getContext","args","cookies","req","userAgent","get","getLanguage","languageCode","context","value","Headers"],"mappings":"AAEA,SAASA,gBAAgB,QAAQ,mBAAkB;AAInD,OAAO,eAAeC,eAAeC,OAAgB;IACnD,MAAM,EAAEC,OAAO,EAAE,GAAGD;IACpB,MAAME,WAAW,MAAMC,MAAMH,QAAQI,GAAG,EAAE;QAAEH;IAAQ;IAEpD,OAAO;QAAEA,SAASC,SAASD,OAAO;QAAEI,QAAQH,SAASG,MAAM;IAAC;AAC9D;AAEA,OAAO,eAAeC,WAAWC,IAA4C;IAC3E,MAAM,EAAEC,OAAO,EAAEC,GAAG,EAAE,GAAG,MAAMX,iBAAiBS;IAEhD,OAAO;QAAEC;QAASE,WAAWD,IAAIR,OAAO,CAACU,GAAG,CAAC;IAAc;AAC7D;AAEA,OAAO,SAASC,YAAYC,YAAoB,EAAEC,OAAgB;IAChE,MAAMhB,mBAAmB,CAACiB,QAAgCA;IAE1D,OAAO;QAAED;QAASb,SAASH,iBAAiB;YAAEG,SAAS,IAAIe;QAAU,GAAGf,OAAO;QAAEY;IAAa;AAChG"}
@@ -0,0 +1,4 @@
1
+ import { getDisplayedFieldValue as display } from '@payloadcms/ui/utilities/getDisplayedFieldValue';
2
+ const result = display(fileSize, field, i18n);
3
+
4
+ //# sourceMappingURL=basic.input.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/transforms/migrate-displayed-field-value-args/basic.input.ts"],"sourcesContent":["import { getDisplayedFieldValue as display } from '@payloadcms/ui/utilities/getDisplayedFieldValue'\n\nconst result = display(fileSize, field, i18n)\n"],"names":["getDisplayedFieldValue","display","result","fileSize","field","i18n"],"mappings":"AAAA,SAASA,0BAA0BC,OAAO,QAAQ,kDAAiD;AAEnG,MAAMC,SAASD,QAAQE,UAAUC,OAAOC"}
@@ -0,0 +1,8 @@
1
+ import { getDisplayedFieldValue as display } from '@payloadcms/ui/utilities/getDisplayedFieldValue';
2
+ const result = display({
3
+ cellData: fileSize,
4
+ field: field,
5
+ i18n: i18n
6
+ });
7
+
8
+ //# sourceMappingURL=basic.output.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/transforms/migrate-displayed-field-value-args/basic.output.ts"],"sourcesContent":["import { getDisplayedFieldValue as display } from '@payloadcms/ui/utilities/getDisplayedFieldValue'\n\nconst result = display({ cellData: fileSize, field: field, i18n: i18n })\n"],"names":["getDisplayedFieldValue","display","result","cellData","fileSize","field","i18n"],"mappings":"AAAA,SAASA,0BAA0BC,OAAO,QAAQ,kDAAiD;AAEnG,MAAMC,SAASD,QAAQ;IAAEE,UAAUC;IAAUC,OAAOA;IAAOC,MAAMA;AAAK"}
@@ -0,0 +1,3 @@
1
+ import type { Transform } from '../../types.js';
2
+ export declare const migrateDisplayedFieldValueArgs: Transform;
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/transforms/migrate-displayed-field-value-args/index.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAK/C,eAAO,MAAM,8BAA8B,EAAE,SA+D5C,CAAA"}
@@ -0,0 +1,84 @@
1
+ import { Node } from 'ts-morph';
2
+ const moduleName = '@payloadcms/ui/utilities/getDisplayedFieldValue';
3
+ const functionName = 'getDisplayedFieldValue';
4
+ export const migrateDisplayedFieldValueArgs = {
5
+ name: 'migrate-displayed-field-value-args',
6
+ apply: ({ project })=>{
7
+ const filesChanged = [];
8
+ const notes = [];
9
+ for (const file of project.getSourceFiles()){
10
+ const calls = new Set();
11
+ for (const declaration of file.getImportDeclarations()){
12
+ if (declaration.getModuleSpecifierValue() !== moduleName) {
13
+ continue;
14
+ }
15
+ for (const specifier of declaration.getNamedImports()){
16
+ if (specifier.getName() !== functionName || specifier.isTypeOnly()) {
17
+ continue;
18
+ }
19
+ const localName = specifier.getAliasNode() ?? specifier.getNameNode();
20
+ if (Node.isIdentifier(localName)) {
21
+ collectCalls({
22
+ calls,
23
+ localName,
24
+ notes
25
+ });
26
+ }
27
+ }
28
+ const namespace = declaration.getNamespaceImport();
29
+ if (namespace) {
30
+ collectCalls({
31
+ calls,
32
+ isNamespace: true,
33
+ localName: namespace,
34
+ notes
35
+ });
36
+ }
37
+ }
38
+ const original = file.getFullText();
39
+ for (const call of [
40
+ ...calls
41
+ ].sort((a, b)=>b.getStart() - a.getStart())){
42
+ const args = call.getArguments();
43
+ if (args.length === 1 && Node.isObjectLiteralExpression(args[0])) {
44
+ continue;
45
+ }
46
+ if (args.length !== 3 || args.some(Node.isSpreadElement)) {
47
+ notes.push(`${file.getFilePath()}:${call.getStartLineNumber()}: ${call.getText()} has unsupported arguments; migrate manually.`);
48
+ continue;
49
+ }
50
+ call.replaceWithText(`${call.getExpression().getText()}({ cellData: ${args[0].getText()}, field: ${args[1].getText()}, i18n: ${args[2].getText()} })`);
51
+ }
52
+ if (file.getFullText() !== original) {
53
+ filesChanged.push(file.getFilePath());
54
+ }
55
+ }
56
+ return {
57
+ filesChanged,
58
+ ...notes.length > 0 ? {
59
+ notes
60
+ } : {}
61
+ };
62
+ },
63
+ description: 'Migrates `getDisplayedFieldValue(cellData, field, i18n)` calls imported from `@payloadcms/ui/utilities/getDisplayedFieldValue` to object arguments.'
64
+ };
65
+ function collectCalls({ calls, isNamespace = false, localName, notes }) {
66
+ for (const reference of localName.findReferencesAsNodes()){
67
+ if (reference === localName) {
68
+ continue;
69
+ }
70
+ const parent = reference.getParent();
71
+ const expression = isNamespace ? Node.isPropertyAccessExpression(parent) && parent.getExpression() === reference && parent.getName() === functionName ? parent : undefined : reference;
72
+ if (!expression) {
73
+ continue;
74
+ }
75
+ const call = expression.getParent();
76
+ if (Node.isCallExpression(call) && call.getExpression() === expression) {
77
+ calls.add(call);
78
+ } else {
79
+ notes.push(`${reference.getSourceFile().getFilePath()}:${reference.getStartLineNumber()}: ${expression.getText()} is referenced without a direct call; migrate manually.`);
80
+ }
81
+ }
82
+ }
83
+
84
+ //# sourceMappingURL=index.js.map