chore: bump next, simplify i18n types

This commit is contained in:
Jarrod Flesch
2024-03-04 17:03:28 -05:00
parent a55e991bfa
commit c4d4a9b47b
5 changed files with 53 additions and 179 deletions

View File

@@ -116,7 +116,7 @@
"lint-staged": "^14.0.1",
"minimist": "1.2.8",
"mongodb-memory-server": "^9",
"next": "14.1.2-canary.5",
"next": "14.1.2",
"node-mocks-http": "^1.14.1",
"nodemon": "3.0.3",
"pino": "8.15.0",

View File

@@ -1,117 +0,0 @@
import type { ClientConfig, Field, SanitizedConfig } from 'payload/types'
export const sanitizeField = (f) => {
const field = { ...f }
if ('access' in field) delete field.access
if ('hooks' in field) delete field.hooks
if ('validate' in field) delete field.validate
if ('defaultValue' in field) delete field.defaultValue
if ('label' in field) delete field.label
if ('fields' in field) {
field.fields = sanitizeFields(field.fields)
}
if ('editor' in field) {
delete field.editor
}
if ('blocks' in field) {
field.blocks = field.blocks.map((block) => {
const sanitized = { ...block }
sanitized.fields = sanitizeFields(sanitized.fields)
return sanitized
})
}
if ('tabs' in field) {
field.tabs = field.tabs.map((tab) => sanitizeField(tab))
}
if ('admin' in field) {
field.admin = { ...field.admin }
if ('components' in field.admin) {
delete field.admin.components
}
if ('condition' in field.admin) {
delete field.admin.condition
}
if ('description' in field.admin) {
delete field.admin.description
}
}
return field
}
const sanitizeCollections = (
collections: SanitizedConfig['collections'],
): ClientConfig['collections'] =>
collections.map((collection) => {
const sanitized = { ...collection }
sanitized.fields = sanitizeFields(sanitized.fields)
delete sanitized.hooks
delete sanitized.access
delete sanitized.endpoints
if ('editor' in sanitized) delete sanitized.editor
if ('admin' in sanitized) {
sanitized.admin = { ...sanitized.admin }
if ('components' in sanitized.admin) {
delete sanitized.admin.components
}
}
return sanitized
})
const sanitizeGlobals = (globals: SanitizedConfig['globals']): ClientConfig['globals'] =>
globals.map((global) => {
const sanitized = { ...global }
sanitized.fields = sanitizeFields(sanitized.fields)
delete sanitized.hooks
delete sanitized.access
delete sanitized.endpoints
if ('admin' in sanitized) {
sanitized.admin = { ...sanitized.admin }
if ('components' in sanitized.admin) {
delete sanitized.admin.components
}
}
return sanitized
})
export const sanitizeFields = (fields: Field[]): Field[] => fields.map(sanitizeField)
export const createClientConfig = async (
configPromise: Promise<SanitizedConfig> | SanitizedConfig,
): Promise<ClientConfig> => {
const config = await configPromise
const clientConfig = { ...config }
delete clientConfig.endpoints
delete clientConfig.db
delete clientConfig.editor
'localization' in clientConfig &&
clientConfig.localization &&
clientConfig.localization.locales.forEach((locale) => {
delete locale.toString
})
clientConfig.onInit = undefined
clientConfig.collections = sanitizeCollections(clientConfig.collections)
clientConfig.globals = sanitizeGlobals(clientConfig.globals)
return clientConfig
}

View File

@@ -204,10 +204,10 @@ const initTFunction: InitTFunction = (args) => (key, vars) => {
})
}
function memoize<T>(fn: Function, keys: string[]): T {
function memoize(fn: Function, keys: string[]) {
const cacheMap = new Map()
return <T>function (args) {
const memoized = (args) => {
const cacheKey = keys.reduce((acc, key) => acc + args[key], '')
if (!cacheMap.has(cacheKey)) {
@@ -217,11 +217,13 @@ function memoize<T>(fn: Function, keys: string[]): T {
return cacheMap.get(cacheKey)!
}
return memoized
}
export const initI18n: InitI18n = memoize(
<InitI18n>(({ config, language = 'en', translations, context }) => {
const i18n = {
({ config, language = 'en', translations, context }: Parameters<InitI18n>[0]) => {
const i18n: I18n = {
fallbackLanguage: config.fallbackLanguage,
language: language || config.fallbackLanguage,
t: initTFunction({
@@ -232,6 +234,6 @@ export const initI18n: InitI18n = memoize(
}
return i18n
}),
},
['language', 'context'] satisfies Array<keyof Parameters<InitI18n>[0]>,
)

96
pnpm-lock.yaml generated
View File

@@ -192,8 +192,8 @@ importers:
specifier: ^9
version: 9.1.6
next:
specifier: 14.1.2-canary.5
version: 14.1.2-canary.5(@babel/core@7.24.0)(react-dom@18.2.0)(react@18.2.0)
specifier: 14.1.2
version: 14.1.2(@babel/core@7.24.0)(react-dom@18.2.0)(react@18.2.0)
node-mocks-http:
specifier: ^1.14.1
version: 1.14.1
@@ -4314,7 +4314,7 @@ packages:
engines: {node: ^14.15.0 || ^16.10.0 || >=18.0.0}
dependencies:
'@jest/types': 29.6.3
'@types/node': 16.18.85
'@types/node': 20.6.2
chalk: 4.1.2
jest-message-util: 29.7.0
jest-util: 29.7.0
@@ -4375,7 +4375,7 @@ packages:
dependencies:
'@jest/fake-timers': 29.7.0
'@jest/types': 29.6.3
'@types/node': 16.18.85
'@types/node': 20.6.2
jest-mock: 29.7.0
/@jest/expect-utils@29.7.0:
@@ -4399,7 +4399,7 @@ packages:
dependencies:
'@jest/types': 29.6.3
'@sinonjs/fake-timers': 10.3.0
'@types/node': 16.18.85
'@types/node': 20.6.2
jest-message-util: 29.7.0
jest-mock: 29.7.0
jest-util: 29.7.0
@@ -4430,7 +4430,7 @@ packages:
'@jest/transform': 29.7.0
'@jest/types': 29.6.3
'@jridgewell/trace-mapping': 0.3.23
'@types/node': 16.18.85
'@types/node': 20.6.2
chalk: 4.1.2
collect-v8-coverage: 1.0.2
exit: 0.1.2
@@ -4977,8 +4977,8 @@ packages:
resolution: {integrity: sha512-NpwQaDqrJSREns70aTeh6vC44GPr2qHgoZdk2SPEJmuq1rD+n21FJVn5LtueUbHSZ0RcyPfATYfvdLGnsnZybw==}
dev: false
/@next/env@14.1.2-canary.5:
resolution: {integrity: sha512-s3APjgb3xs3f25VE/r/evvhfGKUfh4eSm6d4eOTkc8jIDFBR9dKhm9nBvwdmFW/9xMg2GXQ8iAiBzxfkY3zS0A==}
/@next/env@14.1.2:
resolution: {integrity: sha512-U0iEG+JF86j6qyu330sfPgsMmDVH8vWVmzZadl+an5EU3o5HqdNytOpM+HsFpl58PmhGBTKx3UmM9c+eoLK0mA==}
dev: true
/@next/eslint-plugin-next@14.1.0:
@@ -4996,8 +4996,8 @@ packages:
dev: false
optional: true
/@next/swc-darwin-arm64@14.1.2-canary.5:
resolution: {integrity: sha512-TipqMk/dT54ywNuMncyqw34t9HhCp69vlbVwxd8KVEWGV1pjoeFgjXlw0yye3ASg3tRj3qOZoWWa9enEgFtRrg==}
/@next/swc-darwin-arm64@14.1.2:
resolution: {integrity: sha512-E4/clgk0ZrYMo9eMRwP/4IO/cvXF1yEYSnGcdGfH+NYTR8bNFy76TSlc1Vb2rK3oaQY4BVHRpx8f/sMN/D5gNw==}
engines: {node: '>= 10'}
cpu: [arm64]
os: [darwin]
@@ -5014,8 +5014,8 @@ packages:
dev: false
optional: true
/@next/swc-darwin-x64@14.1.2-canary.5:
resolution: {integrity: sha512-DZbjpjdgypvbV7g96089d+gknk8yqzqrh4sIQBx28brDMMFvUiDCrzFq5I+qPejdeOj3yWI/j9R+ExVhoe67mQ==}
/@next/swc-darwin-x64@14.1.2:
resolution: {integrity: sha512-j8mEOI+ZM0tU9B/L/OGa6F7d9FXYMkog5OWWuhTWzz3iZ91UKIGGpD/ojTNKuejainDMgbqOBTNnLg0jZywM/g==}
engines: {node: '>= 10'}
cpu: [x64]
os: [darwin]
@@ -5032,8 +5032,8 @@ packages:
dev: false
optional: true
/@next/swc-linux-arm64-gnu@14.1.2-canary.5:
resolution: {integrity: sha512-OSBL1ddNw0j3DpkSVMJEcOFEAmMG3XjrO93+y5qaZu39CdciCDk0dAvaLg0UIe1GDXmy//uh6zRRZwMJ5RVIbA==}
/@next/swc-linux-arm64-gnu@14.1.2:
resolution: {integrity: sha512-qpRrd5hl6BFTWiFLgHtJmqqQGRMs+ol0MN9pEp0SYoLs3j8OTErPiDMhbKWjMWHGdc2E3kg4RRBV3cSTZiePiQ==}
engines: {node: '>= 10'}
cpu: [arm64]
os: [linux]
@@ -5050,8 +5050,8 @@ packages:
dev: false
optional: true
/@next/swc-linux-arm64-musl@14.1.2-canary.5:
resolution: {integrity: sha512-mB+reEEjStVrq3mxkrft8Q4ABfP8d36rhLpvBzWovkKGXCIMfyzcVJvz7h1XBODrmegKz8/yipIU0VOpSDzpvQ==}
/@next/swc-linux-arm64-musl@14.1.2:
resolution: {integrity: sha512-HAhvVXAv+wnbj0wztT0YnpgJVoHtw1Mv4Y1R/JJcg5yXSU8FsP2uEGUwjQaqPoD76YSZjuKl32YbJlmPgQbLFw==}
engines: {node: '>= 10'}
cpu: [arm64]
os: [linux]
@@ -5068,8 +5068,8 @@ packages:
dev: false
optional: true
/@next/swc-linux-x64-gnu@14.1.2-canary.5:
resolution: {integrity: sha512-LC8fI5KQc3zpbcXmP583NKlznY8yjDWL7MKMpqrxZEa9Us9EGHWNx+vZUaPsKNQU0GWLUTHD0TWYRiSIVcFA7w==}
/@next/swc-linux-x64-gnu@14.1.2:
resolution: {integrity: sha512-PCWC312woXLWOXiedi1E+fEw6B/ECP1fMiK1nSoGS2E43o56Z8kq4WeJLbJoufFQGVj5ZOKU3jIVyV//3CI4wQ==}
engines: {node: '>= 10'}
cpu: [x64]
os: [linux]
@@ -5086,8 +5086,8 @@ packages:
dev: false
optional: true
/@next/swc-linux-x64-musl@14.1.2-canary.5:
resolution: {integrity: sha512-oI4+xxDndhQ+dmHYzLFWq+ddsPGxyjED6zcgiKI8fVvr88bi0LdLje6/2elJvtlvZoWEp+AzpJsBa3d6V2lUbw==}
/@next/swc-linux-x64-musl@14.1.2:
resolution: {integrity: sha512-KQSKzdWPNrYZjeTPCsepEpagOzU8Nf3Zzu53X1cLsSY6QlOIkYcSgEihRjsMKyeQW4aSvc+nN5pIpC2pLWNSMA==}
engines: {node: '>= 10'}
cpu: [x64]
os: [linux]
@@ -5104,8 +5104,8 @@ packages:
dev: false
optional: true
/@next/swc-win32-arm64-msvc@14.1.2-canary.5:
resolution: {integrity: sha512-PJL0gg0K/EOMiU5vLz9HMkB4zpY2o9kLibxYSE1SzzEBmh6eCfKm/XY2ms9/eMhc5oH2FIZqs2l2ORJpBJgdeg==}
/@next/swc-win32-arm64-msvc@14.1.2:
resolution: {integrity: sha512-3b0PouKd09Ulm2T1tjaRnwQj9+UwSsMO680d/sD4XAlm29KkNmVLAEIwWTfb3L+E11Qyw+jdcN3HtbDCg5+vYA==}
engines: {node: '>= 10'}
cpu: [arm64]
os: [win32]
@@ -5122,8 +5122,8 @@ packages:
dev: false
optional: true
/@next/swc-win32-ia32-msvc@14.1.2-canary.5:
resolution: {integrity: sha512-Dg1R0kWy6jbP+LzhXzZcQmKPUKryMNYdX7Ft5rtPG9uJ68KE5vzBRq3GH22hBQhZHxA3qoXfasN03ikruGdxDw==}
/@next/swc-win32-ia32-msvc@14.1.2:
resolution: {integrity: sha512-CC1gaJY4h+wg6d5r2biggGM6nCFXh/6WEim2VOQI0WrA6easCQi2P2hzWyrU6moQ0g1GOiWzesGc6nn0a92Kgg==}
engines: {node: '>= 10'}
cpu: [ia32]
os: [win32]
@@ -5140,8 +5140,8 @@ packages:
dev: false
optional: true
/@next/swc-win32-x64-msvc@14.1.2-canary.5:
resolution: {integrity: sha512-AqEuKvW5h+cRCL57s/JZ/izDSX9+1IsIzAKrr2L6cLSQw2Z8i4ePbpfJCPaCsM49LMTb8DOuvrmWeuCqTjzU4g==}
/@next/swc-win32-x64-msvc@14.1.2:
resolution: {integrity: sha512-pfASwanOd+yP3D80O63DuQffrBySZPuB7wRN0IGSRq/0rDm9p/MvvnLzzgP2kSiLOUklOrFYVax7P6AEzjGykQ==}
engines: {node: '>= 10'}
cpu: [x64]
os: [win32]
@@ -6081,14 +6081,6 @@ packages:
resolution: {integrity: sha512-E4KcWTpoLHqwPHLxidpOqQbcrZVgi0rsmmZXUle1jXmJfuIf/UWpczUJ7MZZ5tlxytgJXyp0w4PGkkeLiuIdZw==}
dependencies:
tslib: 2.6.2
dev: false
/@swc/helpers@0.5.5:
resolution: {integrity: sha512-KGYxvIOXcceOAbEk4bi/dVLEK9z8sZ0uBB3Il5b1rhfClSpcX0yfRO0KmTkqR2cnQDymwLB+25ZyMzICg/cm/A==}
dependencies:
'@swc/counter': 0.1.3
tslib: 2.6.2
dev: true
/@swc/jest@0.2.29(@swc/core@1.4.2):
resolution: {integrity: sha512-8reh5RvHBsSikDC3WGCd5ZTd2BXKkyOdK7QwynrCH58jk2cQFhhHhFBg/jvnWZehUQe/EoOImLENc9/DwbBFow==}
@@ -12345,7 +12337,7 @@ packages:
dependencies:
'@jest/types': 29.6.3
'@types/graceful-fs': 4.1.9
'@types/node': 16.18.85
'@types/node': 20.6.2
anymatch: 3.1.3
fb-watchman: 2.0.2
graceful-fs: 4.2.11
@@ -12402,7 +12394,7 @@ packages:
engines: {node: ^14.15.0 || ^16.10.0 || >=18.0.0}
dependencies:
'@jest/types': 29.6.3
'@types/node': 16.18.85
'@types/node': 20.6.2
jest-util: 29.7.0
/jest-pnp-resolver@1.2.3(jest-resolve@29.7.0):
@@ -12452,7 +12444,7 @@ packages:
'@jest/test-result': 29.7.0
'@jest/transform': 29.7.0
'@jest/types': 29.6.3
'@types/node': 16.18.85
'@types/node': 20.6.2
chalk: 4.1.2
emittery: 0.13.1
graceful-fs: 4.2.11
@@ -12482,7 +12474,7 @@ packages:
'@jest/test-result': 29.7.0
'@jest/transform': 29.7.0
'@jest/types': 29.6.3
'@types/node': 16.18.85
'@types/node': 20.6.2
chalk: 4.1.2
cjs-module-lexer: 1.2.3
collect-v8-coverage: 1.0.2
@@ -12555,7 +12547,7 @@ packages:
dependencies:
'@jest/test-result': 29.7.0
'@jest/types': 29.6.3
'@types/node': 16.18.85
'@types/node': 20.6.2
ansi-escapes: 4.3.2
chalk: 4.1.2
emittery: 0.13.1
@@ -13683,8 +13675,8 @@ packages:
- babel-plugin-macros
dev: false
/next@14.1.2-canary.5(@babel/core@7.24.0)(react-dom@18.2.0)(react@18.2.0):
resolution: {integrity: sha512-sxZZmvPfuT0TKe2/hVrwRz4056pFqRoJztMqQ9sC7FtX7n9+vE+V8WOmmKiv3YpEnwVAQkhzEgtKOfMHqdUZNg==}
/next@14.1.2(@babel/core@7.24.0)(react-dom@18.2.0)(react@18.2.0):
resolution: {integrity: sha512-p4RfNmopqkzRP1uUyBJnHii+qMg71f2udWhTTZopBB8b3T5QXNzn7yO+LCYHPWZG2kAvEn4l4neyJHqkXvo2wg==}
engines: {node: '>=18.17.0'}
hasBin: true
peerDependencies:
@@ -13698,8 +13690,8 @@ packages:
sass:
optional: true
dependencies:
'@next/env': 14.1.2-canary.5
'@swc/helpers': 0.5.5
'@next/env': 14.1.2
'@swc/helpers': 0.5.2
busboy: 1.6.0
caniuse-lite: 1.0.30001591
graceful-fs: 4.2.11
@@ -13708,15 +13700,15 @@ packages:
react-dom: 18.2.0(react@18.2.0)
styled-jsx: 5.1.1(@babel/core@7.24.0)(react@18.2.0)
optionalDependencies:
'@next/swc-darwin-arm64': 14.1.2-canary.5
'@next/swc-darwin-x64': 14.1.2-canary.5
'@next/swc-linux-arm64-gnu': 14.1.2-canary.5
'@next/swc-linux-arm64-musl': 14.1.2-canary.5
'@next/swc-linux-x64-gnu': 14.1.2-canary.5
'@next/swc-linux-x64-musl': 14.1.2-canary.5
'@next/swc-win32-arm64-msvc': 14.1.2-canary.5
'@next/swc-win32-ia32-msvc': 14.1.2-canary.5
'@next/swc-win32-x64-msvc': 14.1.2-canary.5
'@next/swc-darwin-arm64': 14.1.2
'@next/swc-darwin-x64': 14.1.2
'@next/swc-linux-arm64-gnu': 14.1.2
'@next/swc-linux-arm64-musl': 14.1.2
'@next/swc-linux-x64-gnu': 14.1.2
'@next/swc-linux-x64-musl': 14.1.2
'@next/swc-win32-arm64-msvc': 14.1.2
'@next/swc-win32-ia32-msvc': 14.1.2
'@next/swc-win32-x64-msvc': 14.1.2
transitivePeerDependencies:
- '@babel/core'
- babel-plugin-macros

View File

@@ -47,9 +47,6 @@
"@payloadcms/richtext-lexical": [
"./packages/richtext-lexical/src"
],
"@payloadcms/plugin-cloud": [
"./packages/plugin-cloud/src"
],
"@payloadcms/plugin-cloud-storage": [
"./packages/plugin-cloud-storage/src"
],
@@ -161,4 +158,4 @@
"app/**/*.tsx",
"scripts/**/*.ts"
]
}
}