diff --git a/next.config.mjs b/next.config.mjs index 8bb032d32..de0767232 100644 --- a/next.config.mjs +++ b/next.config.mjs @@ -33,6 +33,7 @@ export default withBundleAnalyzer( '.js': ['.ts', '.tsx', '.js', '.jsx'], '.mjs': ['.mts', '.mjs'], } + return webpackConfig }, }), diff --git a/package.json b/package.json index d03ea09f8..7e1846fa2 100644 --- a/package.json +++ b/package.json @@ -124,6 +124,7 @@ "husky": "^8.0.3", "jest": "29.7.0", "jest-environment-jsdom": "29.7.0", + "json-schema-to-typescript": "11.0.3", "lint-staged": "^14.0.1", "minimist": "1.2.8", "mongodb-memory-server": "^9.0", diff --git a/packages/next/src/utilities/getPayloadHMR.ts b/packages/next/src/utilities/getPayloadHMR.ts index f3e26c997..69d660fe2 100644 --- a/packages/next/src/utilities/getPayloadHMR.ts +++ b/packages/next/src/utilities/getPayloadHMR.ts @@ -2,6 +2,7 @@ import type { GeneratedTypes, Payload } from 'payload' import type { InitOptions, SanitizedConfig } from 'payload/config' import { BasePayload } from 'payload' +import { generateTypes } from 'payload/bin' import WebSocket from 'ws' let cached: { @@ -36,6 +37,11 @@ export const reload = async (config: SanitizedConfig, payload: Payload): Promise // TODO: support HMR for other props in the future (see payload/src/index init()) hat may change on Payload singleton + // Generate types + if (config.typescript.autoGenerate !== false) { + void generateTypes(config, { log: false }) + } + await payload.db.init() if (payload.db.connect) { await payload.db.connect({ hotReload: true }) diff --git a/packages/next/src/withPayload.js b/packages/next/src/withPayload.js index a6432addd..1f17f2ff7 100644 --- a/packages/next/src/withPayload.js +++ b/packages/next/src/withPayload.js @@ -68,6 +68,7 @@ export const withPayload = (nextConfig = {}) => { 'pino', 'pino-pretty', 'graphql', + 'json-schema-to-typescript', ], webpack: (webpackConfig, webpackOptions) => { const incomingWebpackConfig = @@ -83,6 +84,7 @@ export const withPayload = (nextConfig = {}) => { 'drizzle-kit/payload', 'sharp', 'libsql', + 'json-schema-to-typescript', ], ignoreWarnings: [ ...(incomingWebpackConfig?.ignoreWarnings || []), diff --git a/packages/next/webpack.config.js b/packages/next/webpack.config.js index 8eb051b79..3c7dedb6d 100644 --- a/packages/next/webpack.config.js +++ b/packages/next/webpack.config.js @@ -18,6 +18,7 @@ const componentWebpackConfig = { 'payload/config', 'react-image-crop', 'payload/operations', + 'payload/bin', ], mode: 'production', module: { diff --git a/packages/payload/src/bin/generateTypes.ts b/packages/payload/src/bin/generateTypes.ts index 5aee6c1d7..7d85a84be 100644 --- a/packages/payload/src/bin/generateTypes.ts +++ b/packages/payload/src/bin/generateTypes.ts @@ -6,11 +6,16 @@ import type { SanitizedConfig } from '../config/types.js' import { configToJSONSchema } from '../utilities/configToJSONSchema.js' import Logger from '../utilities/logger.js' -export async function generateTypes(config: SanitizedConfig): Promise { +export async function generateTypes( + config: SanitizedConfig, + options?: { log: boolean }, +): Promise { const logger = Logger() const outputFile = process.env.PAYLOAD_TS_OUTPUT_PATH || config.typescript.outputFile - logger.info('Compiling TS types for Collections and Globals...') + const shouldLog = options?.log ?? true + + if (shouldLog) logger.info('Compiling TS types for Collections and Globals...') const jsonSchema = configToJSONSchema(config, config.db.defaultIDType) @@ -37,5 +42,5 @@ export async function generateTypes(config: SanitizedConfig): Promise { } } fs.writeFileSync(outputFile, compiled) - logger.info(`Types written to ${outputFile}`) + if (shouldLog) logger.info(`Types written to ${outputFile}`) } diff --git a/packages/payload/src/config/defaults.ts b/packages/payload/src/config/defaults.ts index e976652e4..ae628e1f8 100644 --- a/packages/payload/src/config/defaults.ts +++ b/packages/payload/src/config/defaults.ts @@ -49,6 +49,7 @@ export const defaults: Omit = { serverURL: '', telemetry: true, typescript: { + autoGenerate: true, outputFile: `${typeof process?.cwd === 'function' ? process.cwd() : ''}/payload-types.ts`, }, upload: {}, diff --git a/packages/payload/src/config/schema.ts b/packages/payload/src/config/schema.ts index edc0677d3..cc8e333ab 100644 --- a/packages/payload/src/config/schema.ts +++ b/packages/payload/src/config/schema.ts @@ -189,6 +189,7 @@ export default joi.object({ sharp: joi.any(), telemetry: joi.boolean(), typescript: joi.object({ + autoGenerate: joi.boolean(), declare: joi.alternatives().try(joi.boolean(), joi.object({ ignoreTSError: joi.boolean() })), outputFile: joi.string(), }), diff --git a/packages/payload/src/config/types.ts b/packages/payload/src/config/types.ts index 939ccf422..ca7d20e06 100644 --- a/packages/payload/src/config/types.ts +++ b/packages/payload/src/config/types.ts @@ -719,6 +719,12 @@ export type Config = { telemetry?: boolean /** Control how typescript interfaces are generated from your collections. */ typescript?: { + /** + * Automatically generate types during development + * @default true + */ + autoGenerate?: boolean + /** Disable declare block in generated types file */ declare?: | { @@ -732,6 +738,7 @@ export type Config = { ignoreTSError?: boolean } | false + /** Filename to write the generated types to */ outputFile?: string } diff --git a/packages/payload/src/exports/bin.ts b/packages/payload/src/exports/bin.ts new file mode 100644 index 000000000..5cd0b14e9 --- /dev/null +++ b/packages/payload/src/exports/bin.ts @@ -0,0 +1,5 @@ +/** + * WARNING: This file contains exports that can only be safely used on the server. + */ + +export { generateTypes } from '../bin/generateTypes.js' diff --git a/packages/payload/src/index.ts b/packages/payload/src/index.ts index ffb5ca222..0a88e31eb 100644 --- a/packages/payload/src/index.ts +++ b/packages/payload/src/index.ts @@ -47,6 +47,7 @@ import type { TypeWithVersion } from './versions/types.js' import { decrypt, encrypt } from './auth/crypto.js' import { APIKeyAuthentication } from './auth/strategies/apiKey.js' import { JWTAuthentication } from './auth/strategies/jwt.js' +import { generateTypes } from './bin/generateTypes.js' import localOperations from './collections/operations/local/index.js' import { validateSchema } from './config/validate.js' import { consoleEmailAdapter } from './email/consoleEmailAdapter.js' @@ -363,6 +364,11 @@ export class BasePayload { } }) + // Generate types on startup + if (process.env.NODE_ENV !== 'production' && this.config.typescript.autoGenerate !== false) { + void generateTypes(this.config, { log: false }) + } + this.db = this.config.db.init({ payload: this }) this.db.payload = this diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 7a40f872e..78d9b5441 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -140,6 +140,9 @@ importers: jest-environment-jsdom: specifier: 29.7.0 version: 29.7.0 + json-schema-to-typescript: + specifier: 11.0.3 + version: 11.0.3 lint-staged: specifier: ^14.0.1 version: 14.0.1 @@ -1555,6 +1558,9 @@ importers: test: devDependencies: + '@aws-sdk/client-s3': + specifier: ^3.525.0 + version: 3.550.0 '@lexical/headless': specifier: 0.16.0 version: 0.16.0 @@ -3836,7 +3842,6 @@ packages: '@types/json-schema': 7.0.15 call-me-maybe: 1.0.2 js-yaml: 4.1.0 - dev: false /@bcoe/v8-coverage@0.2.3: resolution: {integrity: sha512-0hYQ8SB4Db5zvZB4axdMHGwEaQjkZzFjQiN9LVYvIFB2nSUHW9tYpxWriPrWDASIxiaXax83REcLxuSdnGPZtw==} @@ -5461,7 +5466,6 @@ packages: /@jsdevtools/ono@7.1.3: resolution: {integrity: sha512-4JQNk+3mVzK3xh2rqd6RB4J46qUR19azEHBneZyTZM+c456qOrbbM/5xcR8huNCCcbVt7+UmizG6GuUvPvKUYg==} - dev: false /@juggle/resize-observer@3.4.0: resolution: {integrity: sha512-dfLbk+PwWvFzSxwk3n5ySL0hfBog779o8h68wK/7/APo/7cgyWp5jcXockbxdk5kFRkbeXWm4Fbi9FrdN381sA==} @@ -7108,7 +7112,6 @@ packages: /@types/prettier@2.7.3: resolution: {integrity: sha512-+68kP9yzs4LMp7VNh8gdzMSPZFL44MLGqiHWvttYJe+6qnuVr4Ek9wSBQoveqY/r+LwjCcU29kNVkidwim+kYA==} - dev: false /@types/prompts@2.4.9: resolution: {integrity: sha512-qTxFi6Buiu8+50/+3DGIWLHM6QuWsEKugJnnP6iv2Mc4ncxE4A/OJkjuVOA+5X0X1S/nq5VJRa8Lu+nwcvbrKA==} @@ -7922,7 +7925,6 @@ packages: /any-promise@1.3.0: resolution: {integrity: sha512-7UvmKalWRt1wgjL1RrGxoSJW/0QZFIegpeGvZG9kjp8vrRu55XTHbwnqq2GpXm9uLbcuhxm3IqX9OB4MZR1b2A==} - dev: false /anymatch@3.1.3: resolution: {integrity: sha512-KMReFUr0B4t+D+OBkjR3KYqvocp2XaSzO55UcB6mgQMd3KbcE+mWTyvVV7D/zsdEbNnV6acZUutkiHQXvTr1Rw==} @@ -8562,7 +8564,6 @@ packages: /call-me-maybe@1.0.2: resolution: {integrity: sha512-HpX65o1Hnr9HH25ojC1YGs7HCQLq0GCOibSaWER0eNpgJ/Z1MZv2mTc7+xh6WOPxbRVcmgbv4hGU+uSQ/2xFZQ==} - dev: false /callsites@3.1.0: resolution: {integrity: sha512-P8BjAsXvZS+VIDUI11hHCQEv74YT67YUi5JJFNWIqL235sBmjX4+qx9Muvls5ivyNENctx46xQLQ3aTuE7ssaQ==} @@ -11085,7 +11086,6 @@ packages: /get-stdin@8.0.0: resolution: {integrity: sha512-sY22aA6xchAzprjyqmSEQv4UbAAzRN0L2dQB0NlN5acTTK9Don6nhoc3eAbUnpZiCANAMfd/+40kVdKfFygohg==} engines: {node: '>=10'} - dev: false /get-stdin@9.0.0: resolution: {integrity: sha512-dVKBjfWisLAicarI2Sf+JuBE/DghV4UzNAVe9yhEJuzeREd3JhOTE9cUaJTeSa77fsbQUK3pcOpJfM59+VKZaA==} @@ -11169,7 +11169,6 @@ packages: dependencies: '@types/glob': 7.2.0 glob: 7.2.3 - dev: false /glob-to-regexp@0.4.1: resolution: {integrity: sha512-lkX1HJXwyMcprw/5YUZc2s7DrpAiHB21/V+E1rHUrVNokkvB6bqMzT0VfV6/86ZNabt1k14YOIaT7nDvOX3Iiw==} @@ -12640,7 +12639,6 @@ packages: mkdirp: 1.0.4 mz: 2.7.0 prettier: 2.8.8 - dev: false /json-schema-traverse@0.4.1: resolution: {integrity: sha512-xbbCH5dCYU5T8LcEhhuh7HJ88HXuW3qsI3Y0zOZFKfZEHcpWiHU/Jxzk629Brsab/mMiHQti9wMP+845RPe3Vg==} @@ -13393,7 +13391,6 @@ packages: any-promise: 1.3.0 object-assign: 4.1.1 thenify-all: 1.6.0 - dev: false /nanoid@3.3.7: resolution: {integrity: sha512-eSRppjcPIatRIMC1U6UngP8XFcz8MQWGQdt1MTBQ7NaAmvXDfvNxbvWV3x2y6CdEUciCSsDHDQZbhYaB8QEo2g==} @@ -13674,7 +13671,6 @@ packages: /object-assign@4.1.1: resolution: {integrity: sha512-rJgTQnkUnH1sFw8yT6VSU3zD3sWmu6sZhIseY8VX+GRu3P6F7Fu+JNDoXfklElbLJSnc3FUQHVe4cU5hj+BcUg==} engines: {node: '>=0.10.0'} - dev: false /object-inspect@1.13.1: resolution: {integrity: sha512-5qoj1RUiKOMsCCNLV1CBiPYE10sziTsnmNxkAI/rZhiD63CF7IqdFGC/XzjWjpSgLf0LxXX3bDFIh0E18f6UhQ==} @@ -15003,7 +14999,6 @@ packages: resolution: {integrity: sha512-tdN8qQGvNjw4CHbY+XXk0JgCXn9QiF21a55rBe5LJAU+kDyC4WQn4+awm2Xfk2lQMk5fKup9XgzTZtGkjBdP9Q==} engines: {node: '>=10.13.0'} hasBin: true - dev: false /prettier@3.2.5: resolution: {integrity: sha512-3/GWa9aOC0YeD7LUfvOG2NiDyhOWRvt1k+rcKhOuYnMY24iiCphgneUfJDyFXd6rZCAnuLBv6UeAULtrhT/F4A==} @@ -16654,13 +16649,11 @@ packages: engines: {node: '>=0.8'} dependencies: thenify: 3.3.1 - dev: false /thenify@3.3.1: resolution: {integrity: sha512-RVZSIV5IG10Hk3enotrhvz0T9em6cyHBLkH/YAZuKqd8hRkKhSfCGIcP2KUY0EPxndzANBmNllzWPwak+bheSw==} dependencies: any-promise: 1.3.0 - dev: false /thread-stream@2.4.1: resolution: {integrity: sha512-d/Ex2iWd1whipbT681JmTINKw0ZwOUBZm7+Gjs64DHuX34mmw8vJL2bFAaNacaW72zYiTJxSHi5abUuOi5nsfg==} diff --git a/test/_community/config.ts b/test/_community/config.ts index d00a60191..b8c887931 100644 --- a/test/_community/config.ts +++ b/test/_community/config.ts @@ -1,15 +1,13 @@ -// import path from 'path' -// import { getFileByPath } from 'payload/uploads' -// import { fileURLToPath } from 'url' +import { fileURLToPath } from 'node:url' +import path from 'path' import { buildConfigWithDefaults } from '../buildConfigWithDefaults.js' import { devUser } from '../credentials.js' // import { MediaCollection } from './collections/Media/index.js' import { PostsCollection, postsSlug } from './collections/Posts/index.js' import { MenuGlobal } from './globals/Menu/index.js' - -// const filename = fileURLToPath(import.meta.url) -// const dirname = path.dirname(filename) +const filename = fileURLToPath(import.meta.url) +const dirname = path.dirname(filename) export default buildConfigWithDefaults({ // ...extend config here @@ -48,4 +46,7 @@ export default buildConfigWithDefaults({ // file: imageFile, // }) }, + typescript: { + outputFile: path.resolve(dirname, 'payload-types.ts'), + }, }) diff --git a/test/access-control/config.ts b/test/access-control/config.ts index e16a90a86..1dbe3f84d 100644 --- a/test/access-control/config.ts +++ b/test/access-control/config.ts @@ -1,3 +1,7 @@ +import { fileURLToPath } from 'node:url' +import path from 'path' +const filename = fileURLToPath(import.meta.url) +const dirname = path.dirname(filename) import type { FieldAccess } from 'payload/types' import { buildConfigWithDefaults } from '../buildConfigWithDefaults.js' @@ -599,4 +603,7 @@ export default buildConfigWithDefaults({ }, }) }, + typescript: { + outputFile: path.resolve(dirname, 'payload-types.ts'), + }, }) diff --git a/test/admin/config.ts b/test/admin/config.ts index 21ac1e220..d0dc608b5 100644 --- a/test/admin/config.ts +++ b/test/admin/config.ts @@ -1,3 +1,7 @@ +import { fileURLToPath } from 'node:url' +import path from 'path' +const filename = fileURLToPath(import.meta.url) +const dirname = path.dirname(filename) import { buildConfigWithDefaults } from '../buildConfigWithDefaults.js' import { CustomIdRow } from './collections/CustomIdRow.js' import { CustomIdTab } from './collections/CustomIdTab.js' @@ -163,4 +167,7 @@ export default buildConfigWithDefaults({ await seed(payload) } }, + typescript: { + outputFile: path.resolve(dirname, 'payload-types.ts'), + }, }) diff --git a/test/admin/payload-types.ts b/test/admin/payload-types.ts index 7e8f87731..de4cf6390 100644 --- a/test/admin/payload-types.ts +++ b/test/admin/payload-types.ts @@ -56,6 +56,8 @@ export interface Upload { filesize?: number | null; width?: number | null; height?: number | null; + focalX?: number | null; + focalY?: number | null; } /** * This interface was referenced by `Config`'s JSON-Schema diff --git a/test/array-update/config.ts b/test/array-update/config.ts index ce38ae303..1b2070b8b 100644 --- a/test/array-update/config.ts +++ b/test/array-update/config.ts @@ -1,3 +1,7 @@ +import { fileURLToPath } from 'node:url' +import path from 'path' +const filename = fileURLToPath(import.meta.url) +const dirname = path.dirname(filename) import { buildConfigWithDefaults } from '../buildConfigWithDefaults.js' import { devUser } from '../credentials.js' import { arraySlug } from './shared.js' @@ -52,4 +56,7 @@ export default buildConfigWithDefaults({ }, }) }, + typescript: { + outputFile: path.resolve(dirname, 'payload-types.ts'), + }, }) diff --git a/test/auth/config.ts b/test/auth/config.ts index 2b231b469..cc6ade47e 100644 --- a/test/auth/config.ts +++ b/test/auth/config.ts @@ -1,3 +1,7 @@ +import { fileURLToPath } from 'node:url' +import path from 'path' +const filename = fileURLToPath(import.meta.url) +const dirname = path.dirname(filename) import { v4 as uuid } from 'uuid' import { buildConfigWithDefaults } from '../buildConfigWithDefaults.js' @@ -244,4 +248,7 @@ export default buildConfigWithDefaults({ }) } }, + typescript: { + outputFile: path.resolve(dirname, 'payload-types.ts'), + }, }) diff --git a/test/auth/custom-strategy/config.ts b/test/auth/custom-strategy/config.ts index 049c6c820..620dae6a1 100644 --- a/test/auth/custom-strategy/config.ts +++ b/test/auth/custom-strategy/config.ts @@ -1,4 +1,10 @@ -import type { AuthStrategyFunction } from 'payload/auth.js' +import { fileURLToPath } from 'node:url' +import path from 'path' + +const filename = fileURLToPath(import.meta.url) +const dirname = path.dirname(filename) + +import type { AuthStrategyFunction } from 'payload/auth' import { buildConfigWithDefaults } from '../../buildConfigWithDefaults.js' import { usersSlug } from './shared.js' @@ -78,4 +84,7 @@ export default buildConfigWithDefaults({ ], }, ], + typescript: { + outputFile: path.resolve(dirname, 'payload-types.ts'), + }, }) diff --git a/test/auth/payload-types.ts b/test/auth/payload-types.ts index 90baa3a3c..0da225fdc 100644 --- a/test/auth/payload-types.ts +++ b/test/auth/payload-types.ts @@ -44,10 +44,10 @@ export interface User { saveToJWTString?: string | null; saveToJWTFalse?: string | null; }; - saveToJWTTab: { + saveToJWTTab?: { test?: string | null; }; - tabSaveToJWTString: { + tabSaveToJWTString?: { includedByDefault?: string | null; }; tabLiftedSaveToJWT?: string | null; @@ -156,6 +156,6 @@ export interface PayloadMigration { declare module 'payload' { - // @ts-ignore + // @ts-ignore export interface GeneratedTypes extends Config {} -} +} \ No newline at end of file diff --git a/test/buildConfigWithDefaults.ts b/test/buildConfigWithDefaults.ts index 892539b09..2b91b05f7 100644 --- a/test/buildConfigWithDefaults.ts +++ b/test/buildConfigWithDefaults.ts @@ -160,12 +160,15 @@ export async function buildConfigWithDefaults( secret: 'TEST_SECRET', sharp, telemetry: false, + + ...testConfig, + typescript: { declare: { ignoreTSError: true, }, + ...testConfig?.typescript, }, - ...testConfig, i18n: { supportedLanguages: { de, diff --git a/test/collections-graphql/config.ts b/test/collections-graphql/config.ts index 7e791593b..e2d04f451 100644 --- a/test/collections-graphql/config.ts +++ b/test/collections-graphql/config.ts @@ -1,3 +1,7 @@ +import { fileURLToPath } from 'node:url' +import path from 'path' +const filename = fileURLToPath(import.meta.url) +const dirname = path.dirname(filename) import type { CollectionConfig } from 'payload/types' import { buildConfigWithDefaults } from '../buildConfigWithDefaults.js' @@ -538,4 +542,7 @@ export default buildConfigWithDefaults({ data: {}, }) }, + typescript: { + outputFile: path.resolve(dirname, 'payload-types.ts'), + }, }) diff --git a/test/collections-graphql/payload-types.ts b/test/collections-graphql/payload-types.ts index 8ad4561d3..72e152b73 100644 --- a/test/collections-graphql/payload-types.ts +++ b/test/collections-graphql/payload-types.ts @@ -19,6 +19,7 @@ export interface Config { 'payload-api-test-twos': PayloadApiTestTwo; 'content-type': ContentType; 'cyclical-relationship': CyclicalRelationship; + media: Media; 'payload-preferences': PayloadPreference; 'payload-migrations': PayloadMigration; }; @@ -105,7 +106,7 @@ export interface Post { C3?: string | null; }; }; - D1: { + D1?: { D2?: { D3?: { D4?: string | null; @@ -195,10 +196,30 @@ export interface CyclicalRelationship { id: string; title?: string | null; relationToSelf?: (string | null) | CyclicalRelationship; + media?: string | Media | null; updatedAt: string; createdAt: string; _status?: ('draft' | 'published') | null; } +/** + * This interface was referenced by `Config`'s JSON-Schema + * via the `definition` "media". + */ +export interface Media { + id: string; + title?: string | null; + updatedAt: string; + createdAt: string; + url?: string | null; + thumbnailURL?: string | null; + filename?: string | null; + mimeType?: string | null; + filesize?: number | null; + width?: number | null; + height?: number | null; + focalX?: number | null; + focalY?: number | null; +} /** * This interface was referenced by `Config`'s JSON-Schema * via the `definition` "payload-preferences". diff --git a/test/collections-rest/config.ts b/test/collections-rest/config.ts index 050f8a096..76427c0e2 100644 --- a/test/collections-rest/config.ts +++ b/test/collections-rest/config.ts @@ -1,3 +1,7 @@ +import { fileURLToPath } from 'node:url' +import path from 'path' +const filename = fileURLToPath(import.meta.url) +const dirname = path.dirname(filename) import type { CollectionConfig } from 'payload/types' import { buildConfigWithDefaults } from '../buildConfigWithDefaults.js' @@ -371,4 +375,7 @@ export default buildConfigWithDefaults({ }, }) }, + typescript: { + outputFile: path.resolve(dirname, 'payload-types.ts'), + }, }) diff --git a/test/collections-rest/payload-types.ts b/test/collections-rest/payload-types.ts index f971f830c..0f1dd1097 100644 --- a/test/collections-rest/payload-types.ts +++ b/test/collections-rest/payload-types.ts @@ -59,7 +59,7 @@ export interface Post { )[] | null; restrictedField?: string | null; - D1: { + D1?: { D2?: { D3?: { D4?: string | null; diff --git a/test/config/config.ts b/test/config/config.ts index 4fca7bead..6038ca50b 100644 --- a/test/config/config.ts +++ b/test/config/config.ts @@ -1,3 +1,7 @@ +import { fileURLToPath } from 'node:url' +import path from 'path' +const filename = fileURLToPath(import.meta.url) +const dirname = path.dirname(filename) import { buildConfigWithDefaults } from '../buildConfigWithDefaults.js' import { devUser } from '../credentials.js' @@ -106,4 +110,7 @@ export default buildConfigWithDefaults({ }, }) }, + typescript: { + outputFile: path.resolve(dirname, 'payload-types.ts'), + }, }) diff --git a/test/custom-graphql/config.ts b/test/custom-graphql/config.ts index 48f2538d2..a75f56eb6 100644 --- a/test/custom-graphql/config.ts +++ b/test/custom-graphql/config.ts @@ -1,3 +1,7 @@ +import { fileURLToPath } from 'node:url' +import path from 'path' +const filename = fileURLToPath(import.meta.url) +const dirname = path.dirname(filename) import { commitTransaction, initTransaction, killTransaction } from 'payload/database' import { buildConfigWithDefaults } from '../buildConfigWithDefaults.js' @@ -55,4 +59,7 @@ export default buildConfigWithDefaults({ }, }) }, + typescript: { + outputFile: path.resolve(dirname, 'payload-types.ts'), + }, }) diff --git a/test/database/config.ts b/test/database/config.ts index 59d855a2f..08ba65118 100644 --- a/test/database/config.ts +++ b/test/database/config.ts @@ -1,3 +1,7 @@ +import { fileURLToPath } from 'node:url' +import path from 'path' +const filename = fileURLToPath(import.meta.url) +const dirname = path.dirname(filename) import { buildConfigWithDefaults } from '../buildConfigWithDefaults.js' import { devUser } from '../credentials.js' @@ -256,6 +260,9 @@ export default buildConfigWithDefaults({ }, }) }, + typescript: { + outputFile: path.resolve(dirname, 'payload-types.ts'), + }, }) export const postDoc = { diff --git a/test/database/payload-types.ts b/test/database/payload-types.ts index a17d988ba..44122c80f 100644 --- a/test/database/payload-types.ts +++ b/test/database/payload-types.ts @@ -11,6 +11,7 @@ export interface Config { posts: Post; 'relation-a': RelationA; 'relation-b': RelationB; + 'pg-migrations': PgMigration; 'custom-schema': CustomSchema; users: User; 'payload-preferences': PayloadPreference; @@ -87,6 +88,40 @@ export interface RelationB { updatedAt: string; createdAt: string; } +/** + * This interface was referenced by `Config`'s JSON-Schema + * via the `definition` "pg-migrations". + */ +export interface PgMigration { + id: string; + relation1?: (string | null) | RelationA; + myArray?: + | { + relation2?: (string | null) | RelationB; + mySubArray?: + | { + relation3?: (string | null) | RelationB; + id?: string | null; + }[] + | null; + id?: string | null; + }[] + | null; + myGroup?: { + relation4?: (string | null) | RelationB; + }; + myBlocks?: + | { + relation5?: (string | null) | RelationA; + relation6?: (string | null) | RelationB; + id?: string | null; + blockName?: string | null; + blockType: 'myBlock'; + }[] + | null; + updatedAt: string; + createdAt: string; +} /** * This interface was referenced by `Config`'s JSON-Schema * via the `definition` "custom-schema". @@ -116,6 +151,7 @@ export interface CustomSchema { | null; updatedAt: string; createdAt: string; + _status?: ('draft' | 'published') | null; } /** * This interface was referenced by `Config`'s JSON-Schema diff --git a/test/dataloader/config.ts b/test/dataloader/config.ts index e05d248c0..e8af00ed9 100644 --- a/test/dataloader/config.ts +++ b/test/dataloader/config.ts @@ -1,3 +1,7 @@ +import { fileURLToPath } from 'node:url' +import path from 'path' +const filename = fileURLToPath(import.meta.url) +const dirname = path.dirname(filename) import { slateEditor } from '@payloadcms/richtext-slate' import type { Post } from './payload-types.js' @@ -79,6 +83,9 @@ export default buildConfigWithDefaults({ user, }) }, + typescript: { + outputFile: path.resolve(dirname, 'payload-types.ts'), + }, }) export const postDoc: Pick = { diff --git a/test/email-nodemailer/config.ts b/test/email-nodemailer/config.ts index 4012613d9..66bf00d71 100644 --- a/test/email-nodemailer/config.ts +++ b/test/email-nodemailer/config.ts @@ -1,3 +1,7 @@ +import { fileURLToPath } from 'node:url' +import path from 'path' +const filename = fileURLToPath(import.meta.url) +const dirname = path.dirname(filename) import { nodemailerAdapter } from '@payloadcms/email-nodemailer' import { buildConfigWithDefaults } from '../buildConfigWithDefaults.js' @@ -23,4 +27,7 @@ export default buildConfigWithDefaults({ payload.logger.info({ msg: 'Email sent', email }) }, + typescript: { + outputFile: path.resolve(dirname, 'payload-types.ts'), + }, }) diff --git a/test/email-resend/config.ts b/test/email-resend/config.ts index d7aa9f176..bd0297fa9 100644 --- a/test/email-resend/config.ts +++ b/test/email-resend/config.ts @@ -1,3 +1,7 @@ +import { fileURLToPath } from 'node:url' +import path from 'path' +const filename = fileURLToPath(import.meta.url) +const dirname = path.dirname(filename) import { resendAdapter } from '@payloadcms/email-resend' import { buildConfigWithDefaults } from '../buildConfigWithDefaults.js' @@ -31,4 +35,7 @@ export default buildConfigWithDefaults({ payload.logger.info({ msg: 'Email sent', email }) }, + typescript: { + outputFile: path.resolve(dirname, 'payload-types.ts'), + }, }) diff --git a/test/email/config.ts b/test/email/config.ts index 36759cbdd..c839d8a15 100644 --- a/test/email/config.ts +++ b/test/email/config.ts @@ -48,4 +48,7 @@ export default buildConfigWithDefaults({ file: imageFile, }) }, + typescript: { + outputFile: path.resolve(dirname, 'payload-types.ts'), + }, }) diff --git a/test/email/payload-types.ts b/test/email/payload-types.ts index e5613b73b..695cc34e7 100644 --- a/test/email/payload-types.ts +++ b/test/email/payload-types.ts @@ -49,6 +49,8 @@ export interface Media { filesize?: number | null; width?: number | null; height?: number | null; + focalX?: number | null; + focalY?: number | null; sizes?: { thumbnail?: { url?: string | null; diff --git a/test/endpoints/config.ts b/test/endpoints/config.ts index a90e034ba..c9c20316d 100644 --- a/test/endpoints/config.ts +++ b/test/endpoints/config.ts @@ -1,3 +1,7 @@ +import { fileURLToPath } from 'node:url' +import path from 'path' +const filename = fileURLToPath(import.meta.url) +const dirname = path.dirname(filename) import { buildConfigWithDefaults } from '../buildConfigWithDefaults.js' import { devUser } from '../credentials.js' import { collectionEndpoints } from './endpoints/collections.js' @@ -68,4 +72,7 @@ export default buildConfigWithDefaults({ }, }) }, + typescript: { + outputFile: path.resolve(dirname, 'payload-types.ts'), + }, }) diff --git a/test/field-error-states/config.ts b/test/field-error-states/config.ts index 345faa3fe..b402efe06 100644 --- a/test/field-error-states/config.ts +++ b/test/field-error-states/config.ts @@ -1,3 +1,7 @@ +import { fileURLToPath } from 'node:url' +import path from 'path' +const filename = fileURLToPath(import.meta.url) +const dirname = path.dirname(filename) import { buildConfigWithDefaults } from '../buildConfigWithDefaults.js' import { devUser } from '../credentials.js' import { ErrorFieldsCollection } from './collections/ErrorFields/index.js' @@ -25,4 +29,7 @@ export default buildConfigWithDefaults({ }, }) }, + typescript: { + outputFile: path.resolve(dirname, 'payload-types.ts'), + }, }) diff --git a/test/field-perf/config.ts b/test/field-perf/config.ts index df9787d83..d349c19d0 100644 --- a/test/field-perf/config.ts +++ b/test/field-perf/config.ts @@ -1,3 +1,7 @@ +import { fileURLToPath } from 'node:url' +import path from 'path' +const filename = fileURLToPath(import.meta.url) +const dirname = path.dirname(filename) import { buildConfigWithDefaults } from '../buildConfigWithDefaults.js' import { devUser } from '../credentials.js' @@ -93,4 +97,7 @@ export default buildConfigWithDefaults({ }, }) }, + typescript: { + outputFile: path.resolve(dirname, 'payload-types.ts'), + }, }) diff --git a/test/fields-relationship/config.ts b/test/fields-relationship/config.ts index 3bc970160..5b71e09e1 100644 --- a/test/fields-relationship/config.ts +++ b/test/fields-relationship/config.ts @@ -1,3 +1,7 @@ +import { fileURLToPath } from 'node:url' +import path from 'path' +const filename = fileURLToPath(import.meta.url) +const dirname = path.dirname(filename) import type { CollectionConfig } from 'payload/types' import type { FilterOptionsProps } from 'payload/types' @@ -527,4 +531,7 @@ export default buildConfigWithDefaults({ }) } }, + typescript: { + outputFile: path.resolve(dirname, 'payload-types.ts'), + }, }) diff --git a/test/fields-relationship/payload-types.ts b/test/fields-relationship/payload-types.ts index 53a28b411..d2deacf3c 100644 --- a/test/fields-relationship/payload-types.ts +++ b/test/fields-relationship/payload-types.ts @@ -20,7 +20,7 @@ export interface Config { 'collection-2': Collection2; videos: Video; podcasts: Podcast; - mixedMedia: MixedMedia; + 'mixed-media': MixedMedia; users: User; 'payload-preferences': PayloadPreference; 'payload-migrations': PayloadMigration; @@ -217,7 +217,7 @@ export interface Podcast { } /** * This interface was referenced by `Config`'s JSON-Schema - * via the `definition` "mixedMedia". + * via the `definition` "mixed-media". */ export interface MixedMedia { id: string; diff --git a/test/fields/config.ts b/test/fields/config.ts index b116de83e..e428e7da2 100644 --- a/test/fields/config.ts +++ b/test/fields/config.ts @@ -1,5 +1,10 @@ import type { CollectionConfig } from 'payload/types' +import { fileURLToPath } from 'node:url' +import path from 'path' +const filename = fileURLToPath(import.meta.url) +const dirname = path.dirname(filename) + import { buildConfigWithDefaults } from '../buildConfigWithDefaults.js' import ArrayFields from './collections/Array/index.js' import BlockFields from './collections/Blocks/index.js' @@ -101,4 +106,7 @@ export default buildConfigWithDefaults({ await clearAndSeedEverything(payload) } }, + typescript: { + outputFile: path.resolve(dirname, 'payload-types.ts'), + }, }) diff --git a/test/fields/payload-types.ts b/test/fields/payload-types.ts index 60783d68d..f0682a72e 100644 --- a/test/fields/payload-types.ts +++ b/test/fields/payload-types.ts @@ -838,6 +838,9 @@ export interface GroupField { id?: string | null; }[] | null; + localizedGroup?: { + text?: string | null; + }; potentiallyEmptyGroup?: { text?: string | null; }; diff --git a/test/globals/config.ts b/test/globals/config.ts index ad9a7a3e2..ee5fbe9f6 100644 --- a/test/globals/config.ts +++ b/test/globals/config.ts @@ -1,3 +1,7 @@ +import { fileURLToPath } from 'node:url' +import path from 'path' +const filename = fileURLToPath(import.meta.url) +const dirname = path.dirname(filename) import { buildConfigWithDefaults } from '../buildConfigWithDefaults.js' import { devUser } from '../credentials.js' @@ -126,4 +130,7 @@ export default buildConfigWithDefaults({ slug: accessControlSlug, }) }, + typescript: { + outputFile: path.resolve(dirname, 'payload-types.ts'), + }, }) diff --git a/test/graphql-schema-gen/payload-types.ts b/test/graphql-schema-gen/payload-types.ts index b74a99f4d..6ea4a9a51 100644 --- a/test/graphql-schema-gen/payload-types.ts +++ b/test/graphql-schema-gen/payload-types.ts @@ -154,6 +154,6 @@ export interface PayloadMigration { declare module 'payload' { - // @ts-ignore + // @ts-ignore export interface GeneratedTypes extends Config {} -} +} \ No newline at end of file diff --git a/test/hooks/config.ts b/test/hooks/config.ts index 882afc2a3..fa8d1ab6a 100644 --- a/test/hooks/config.ts +++ b/test/hooks/config.ts @@ -1,3 +1,7 @@ +import { fileURLToPath } from 'node:url' +import path from 'path' +const filename = fileURLToPath(import.meta.url) +const dirname = path.dirname(filename) import type { SanitizedConfig } from 'payload/config' import { APIError } from 'payload/errors' @@ -56,6 +60,9 @@ export const HooksConfig: Promise = buildConfigWithDefaults({ }, }) }, + typescript: { + outputFile: path.resolve(dirname, 'payload-types.ts'), + }, }) export default HooksConfig diff --git a/test/i18n/config.ts b/test/i18n/config.ts index 138e1cf2e..2e386bedb 100644 --- a/test/i18n/config.ts +++ b/test/i18n/config.ts @@ -10,6 +10,12 @@ import type { TFunction, } from '@payloadcms/translations' +import { fileURLToPath } from 'node:url' +const filename = fileURLToPath(import.meta.url) +const dirname = path.dirname(filename) + +import path from 'path' + import { buildConfigWithDefaults } from '../buildConfigWithDefaults.js' import { devUser } from '../credentials.js' import { ComponentWithCustomI18n } from './ComponentWithCustomI18n.js' @@ -81,4 +87,7 @@ export default buildConfigWithDefaults({ }, }) }, + typescript: { + outputFile: path.resolve(dirname, 'payload-types.ts'), + }, }) diff --git a/test/live-preview/config.ts b/test/live-preview/config.ts index c0873bebc..6f537ca6f 100644 --- a/test/live-preview/config.ts +++ b/test/live-preview/config.ts @@ -1,3 +1,7 @@ +import { fileURLToPath } from 'node:url' +import path from 'path' +const filename = fileURLToPath(import.meta.url) +const dirname = path.dirname(filename) import { buildConfigWithDefaults } from '../buildConfigWithDefaults.js' import Categories from './collections/Categories.js' import { Media } from './collections/Media.js' @@ -36,4 +40,7 @@ export default buildConfigWithDefaults({ collections: [Users, Pages, Posts, SSR, SSRAutosave, Tenants, Categories, Media], globals: [Header, Footer], onInit: seed, + typescript: { + outputFile: path.resolve(dirname, 'payload-types.ts'), + }, }) diff --git a/test/localization-rtl/config.ts b/test/localization-rtl/config.ts index b496ed015..f4a902576 100644 --- a/test/localization-rtl/config.ts +++ b/test/localization-rtl/config.ts @@ -1,3 +1,7 @@ +import { fileURLToPath } from 'node:url' +import path from 'path' +const filename = fileURLToPath(import.meta.url) +const dirname = path.dirname(filename) import { buildConfigWithDefaults } from '../buildConfigWithDefaults.js' import { devUser } from '../credentials.js' import { ar } from './ar.js' @@ -38,4 +42,7 @@ export default buildConfigWithDefaults({ }, }) }, + typescript: { + outputFile: path.resolve(dirname, 'payload-types.ts'), + }, }) diff --git a/test/localization/config.ts b/test/localization/config.ts index 4749f8b54..702b6cf5a 100644 --- a/test/localization/config.ts +++ b/test/localization/config.ts @@ -1,3 +1,7 @@ +import { fileURLToPath } from 'node:url' +import path from 'path' +const filename = fileURLToPath(import.meta.url) +const dirname = path.dirname(filename) import type { LocalizedPost } from './payload-types.js' import { buildConfigWithDefaults } from '../buildConfigWithDefaults.js' @@ -455,4 +459,7 @@ export default buildConfigWithDefaults({ console.log('SEED COMPLETE') }, + typescript: { + outputFile: path.resolve(dirname, 'payload-types.ts'), + }, }) diff --git a/test/migrations-cli/config.ts b/test/migrations-cli/config.ts index ebf74b263..fa46a7a18 100644 --- a/test/migrations-cli/config.ts +++ b/test/migrations-cli/config.ts @@ -1,3 +1,11 @@ +import { fileURLToPath } from 'node:url' +import path from 'path' +const filename = fileURLToPath(import.meta.url) +const dirname = path.dirname(filename) import { buildConfigWithDefaults } from '../buildConfigWithDefaults.js' -export default buildConfigWithDefaults({}) +export default buildConfigWithDefaults({ + typescript: { + outputFile: path.resolve(dirname, 'payload-types.ts'), + }, +}) diff --git a/test/nested-fields/config.ts b/test/nested-fields/config.ts index 3eac4291f..358c758da 100644 --- a/test/nested-fields/config.ts +++ b/test/nested-fields/config.ts @@ -1,4 +1,8 @@ -/* eslint-disable @typescript-eslint/ban-ts-comment */ +import { fileURLToPath } from 'node:url' +import path from 'path' +const filename = fileURLToPath(import.meta.url) +const dirname = path.dirname(filename) + import { buildConfigWithDefaults } from '../buildConfigWithDefaults.js' import { devUser } from '../credentials.js' @@ -186,4 +190,7 @@ export default buildConfigWithDefaults({ }, }) }, + typescript: { + outputFile: path.resolve(dirname, 'payload-types.ts'), + }, }) diff --git a/test/nested-fields/payload-types.ts b/test/nested-fields/payload-types.ts index c85433f9b..43be90457 100644 --- a/test/nested-fields/payload-types.ts +++ b/test/nested-fields/payload-types.ts @@ -28,7 +28,7 @@ export interface NestedField { array?: | { group?: { - namedTab: { + namedTab?: { blocks?: | { text?: string | null; @@ -48,7 +48,7 @@ export interface NestedField { id?: string | null; }[] | null; - tab1: { + tab1?: { layout?: | ( | { diff --git a/test/package.json b/test/package.json index f9aac71a2..3650a4192 100644 --- a/test/package.json +++ b/test/package.json @@ -12,6 +12,7 @@ "typecheck": "pnpm turbo build --filter test && tsc --project tsconfig.typecheck.json" }, "devDependencies": { + "@aws-sdk/client-s3": "^3.525.0", "@lexical/headless": "0.16.0", "@lexical/markdown": "0.16.0", "@payloadcms/db-mongodb": "workspace:*", diff --git a/test/plugin-cloud-storage/config.ts b/test/plugin-cloud-storage/config.ts index e2844ddc4..2eb54a6e3 100644 --- a/test/plugin-cloud-storage/config.ts +++ b/test/plugin-cloud-storage/config.ts @@ -135,4 +135,7 @@ export default buildConfigWithDefaults({ }), ], upload: uploadOptions, + typescript: { + outputFile: path.resolve(dirname, 'payload-types.ts'), + }, }) diff --git a/test/plugin-cloud-storage/payload-types.ts b/test/plugin-cloud-storage/payload-types.ts index 044e1f787..29a6323da 100644 --- a/test/plugin-cloud-storage/payload-types.ts +++ b/test/plugin-cloud-storage/payload-types.ts @@ -36,6 +36,8 @@ export interface Media { filesize?: number | null; width?: number | null; height?: number | null; + focalX?: number | null; + focalY?: number | null; sizes?: { square?: { url?: string | null; @@ -71,6 +73,8 @@ export interface MediaWithPrefix { filesize?: number | null; width?: number | null; height?: number | null; + focalX?: number | null; + focalY?: number | null; } /** * This interface was referenced by `Config`'s JSON-Schema diff --git a/test/plugin-cloud/config.ts b/test/plugin-cloud/config.ts index f55ba177f..6037b4f67 100644 --- a/test/plugin-cloud/config.ts +++ b/test/plugin-cloud/config.ts @@ -1,3 +1,6 @@ +import { fileURLToPath } from 'node:url' +const filename = fileURLToPath(import.meta.url) +const dirname = path.dirname(filename) import { payloadCloudPlugin } from '@payloadcms/plugin-cloud' import dotenv from 'dotenv' import path from 'path' @@ -25,4 +28,7 @@ export default buildConfigWithDefaults({ }, plugins: [payloadCloudPlugin()], serverURL: process.env.PAYLOAD_PUBLIC_SERVER_URL, + typescript: { + outputFile: path.resolve(dirname, 'payload-types.ts'), + }, }) diff --git a/test/plugin-cloud/payload-types.ts b/test/plugin-cloud/payload-types.ts index 64111e4d9..2059a8224 100644 --- a/test/plugin-cloud/payload-types.ts +++ b/test/plugin-cloud/payload-types.ts @@ -35,6 +35,8 @@ export interface Media { filesize?: number | null; width?: number | null; height?: number | null; + focalX?: number | null; + focalY?: number | null; sizes?: { square?: { url?: string | null; diff --git a/test/plugin-form-builder/config.ts b/test/plugin-form-builder/config.ts index cc0b04f9c..2c24bfc7e 100644 --- a/test/plugin-form-builder/config.ts +++ b/test/plugin-form-builder/config.ts @@ -1,3 +1,7 @@ +import { fileURLToPath } from 'node:url' +import path from 'path' +const filename = fileURLToPath(import.meta.url) +const dirname = path.dirname(filename) import type { Block } from 'payload/types' import { formBuilderPlugin, fields as formFields } from '@payloadcms/plugin-form-builder' @@ -97,4 +101,7 @@ export default buildConfigWithDefaults({ redirectRelationships: ['pages'], }), ], + typescript: { + outputFile: path.resolve(dirname, 'payload-types.ts'), + }, }) diff --git a/test/plugin-form-builder/payload-types.ts b/test/plugin-form-builder/payload-types.ts index 20cf04121..3089a7cc8 100644 --- a/test/plugin-form-builder/payload-types.ts +++ b/test/plugin-form-builder/payload-types.ts @@ -231,6 +231,7 @@ export interface FormSubmission { id?: string | null; }[] | null; + custom?: string | null; payment?: { field?: string | null; status?: string | null; diff --git a/test/plugin-nested-docs/config.ts b/test/plugin-nested-docs/config.ts index d67c9fdef..a4f88be6b 100644 --- a/test/plugin-nested-docs/config.ts +++ b/test/plugin-nested-docs/config.ts @@ -1,3 +1,7 @@ +import { fileURLToPath } from 'node:url' +import path from 'path' +const filename = fileURLToPath(import.meta.url) +const dirname = path.dirname(filename) import { nestedDocsPlugin } from '@payloadcms/plugin-nested-docs' import { buildConfigWithDefaults } from '../buildConfigWithDefaults.js' @@ -39,4 +43,7 @@ export default buildConfigWithDefaults({ parentFieldSlug: 'owner', }), ], + typescript: { + outputFile: path.resolve(dirname, 'payload-types.ts'), + }, }) diff --git a/test/plugin-redirects/config.ts b/test/plugin-redirects/config.ts index 35dd7d470..469c1fc38 100644 --- a/test/plugin-redirects/config.ts +++ b/test/plugin-redirects/config.ts @@ -1,3 +1,7 @@ +import { fileURLToPath } from 'node:url' +import path from 'path' +const filename = fileURLToPath(import.meta.url) +const dirname = path.dirname(filename) import { redirectsPlugin } from '@payloadcms/plugin-redirects' import { buildConfigWithDefaults } from '../buildConfigWithDefaults.js' @@ -40,4 +44,7 @@ export default buildConfigWithDefaults({ }, }), ], + typescript: { + outputFile: path.resolve(dirname, 'payload-types.ts'), + }, }) diff --git a/test/plugin-relationship-object-ids/config.ts b/test/plugin-relationship-object-ids/config.ts index bd2ef112c..ecba81317 100644 --- a/test/plugin-relationship-object-ids/config.ts +++ b/test/plugin-relationship-object-ids/config.ts @@ -129,4 +129,7 @@ export default buildConfigWithDefaults({ }) } }, + typescript: { + outputFile: path.resolve(dirname, 'payload-types.ts'), + }, }) diff --git a/test/plugin-relationship-object-ids/payload-types.ts b/test/plugin-relationship-object-ids/payload-types.ts new file mode 100644 index 000000000..a6071be86 --- /dev/null +++ b/test/plugin-relationship-object-ids/payload-types.ts @@ -0,0 +1,152 @@ +/* tslint:disable */ +/* eslint-disable */ +/** + * This file was automatically generated by Payload. + * DO NOT MODIFY IT BY HAND. Instead, modify your source Payload config, + * and re-run `payload generate:types` to regenerate this file. + */ + +export interface Config { + collections: { + uploads: Upload; + pages: Page; + posts: Post; + relations: Relation; + users: User; + 'payload-preferences': PayloadPreference; + 'payload-migrations': PayloadMigration; + }; + globals: {}; + locale: null; + user: User & { + collection: 'users'; + }; +} +/** + * This interface was referenced by `Config`'s JSON-Schema + * via the `definition` "uploads". + */ +export interface Upload { + id: string; + updatedAt: string; + createdAt: string; + url?: string | null; + thumbnailURL?: string | null; + filename?: string | null; + mimeType?: string | null; + filesize?: number | null; + width?: number | null; + height?: number | null; + focalX?: number | null; + focalY?: number | null; +} +/** + * This interface was referenced by `Config`'s JSON-Schema + * via the `definition` "pages". + */ +export interface Page { + id: string; + title: string; + updatedAt: string; + createdAt: string; +} +/** + * This interface was referenced by `Config`'s JSON-Schema + * via the `definition` "posts". + */ +export interface Post { + id: string; + title: string; + updatedAt: string; + createdAt: string; +} +/** + * This interface was referenced by `Config`'s JSON-Schema + * via the `definition` "relations". + */ +export interface Relation { + id: string; + hasOne?: (string | null) | Post; + hasOnePoly?: + | ({ + relationTo: 'pages'; + value: string | Page; + } | null) + | ({ + relationTo: 'posts'; + value: string | Post; + } | null); + hasMany?: (string | Post)[] | null; + hasManyPoly?: + | ( + | { + relationTo: 'pages'; + value: string | Page; + } + | { + relationTo: 'posts'; + value: string | Post; + } + )[] + | null; + upload?: string | Upload | null; + updatedAt: string; + createdAt: string; +} +/** + * This interface was referenced by `Config`'s JSON-Schema + * via the `definition` "users". + */ +export interface User { + id: string; + updatedAt: string; + createdAt: string; + email: string; + resetPasswordToken?: string | null; + resetPasswordExpiration?: string | null; + salt?: string | null; + hash?: string | null; + loginAttempts?: number | null; + lockUntil?: string | null; + password?: string | null; +} +/** + * This interface was referenced by `Config`'s JSON-Schema + * via the `definition` "payload-preferences". + */ +export interface PayloadPreference { + id: string; + user: { + relationTo: 'users'; + value: string | User; + }; + key?: string | null; + value?: + | { + [k: string]: unknown; + } + | unknown[] + | string + | number + | boolean + | null; + updatedAt: string; + createdAt: string; +} +/** + * This interface was referenced by `Config`'s JSON-Schema + * via the `definition` "payload-migrations". + */ +export interface PayloadMigration { + id: string; + name?: string | null; + batch?: number | null; + updatedAt: string; + createdAt: string; +} + + +declare module 'payload' { + // @ts-ignore + export interface GeneratedTypes extends Config {} +} \ No newline at end of file diff --git a/test/plugin-search/config.ts b/test/plugin-search/config.ts index f7ed0f969..1b855cbd7 100644 --- a/test/plugin-search/config.ts +++ b/test/plugin-search/config.ts @@ -1,3 +1,7 @@ +import { fileURLToPath } from 'node:url' +import path from 'path' +const filename = fileURLToPath(import.meta.url) +const dirname = path.dirname(filename) import { searchPlugin } from '@payloadcms/plugin-search' import { buildConfigWithDefaults } from '../buildConfigWithDefaults.js' @@ -50,4 +54,7 @@ export default buildConfigWithDefaults({ }, }), ], + typescript: { + outputFile: path.resolve(dirname, 'payload-types.ts'), + }, }) diff --git a/test/plugin-sentry/config.ts b/test/plugin-sentry/config.ts index d18c9e0a3..cbc211eb7 100644 --- a/test/plugin-sentry/config.ts +++ b/test/plugin-sentry/config.ts @@ -1,3 +1,7 @@ +import { fileURLToPath } from 'node:url' +import path from 'path' +const filename = fileURLToPath(import.meta.url) +const dirname = path.dirname(filename) import { sentryPlugin } from '@payloadcms/plugin-sentry' import { buildConfigWithDefaults } from '../buildConfigWithDefaults.js' @@ -37,4 +41,7 @@ export default buildConfigWithDefaults({ }, }), ], + typescript: { + outputFile: path.resolve(dirname, 'payload-types.ts'), + }, }) diff --git a/test/plugin-seo/config.ts b/test/plugin-seo/config.ts index 2e923b298..d4d6b16d8 100644 --- a/test/plugin-seo/config.ts +++ b/test/plugin-seo/config.ts @@ -1,3 +1,7 @@ +import { fileURLToPath } from 'node:url' +import path from 'path' +const filename = fileURLToPath(import.meta.url) +const dirname = path.dirname(filename) import { seoPlugin } from '@payloadcms/plugin-seo' import { en } from '@payloadcms/translations/languages/en' import { es } from '@payloadcms/translations/languages/es' @@ -63,4 +67,7 @@ export default buildConfigWithDefaults({ uploadsCollection: 'media', }), ], + typescript: { + outputFile: path.resolve(dirname, 'payload-types.ts'), + }, }) diff --git a/test/plugin-seo/payload-types.ts b/test/plugin-seo/payload-types.ts index 8dc878aa7..6bdb006e7 100644 --- a/test/plugin-seo/payload-types.ts +++ b/test/plugin-seo/payload-types.ts @@ -87,6 +87,8 @@ export interface Media { filesize?: number | null; width?: number | null; height?: number | null; + focalX?: number | null; + focalY?: number | null; } /** * This interface was referenced by `Config`'s JSON-Schema diff --git a/test/plugin-stripe/config.ts b/test/plugin-stripe/config.ts index 307383d75..eada1a3a9 100644 --- a/test/plugin-stripe/config.ts +++ b/test/plugin-stripe/config.ts @@ -1,3 +1,7 @@ +import { fileURLToPath } from 'node:url' +import path from 'path' +const filename = fileURLToPath(import.meta.url) +const dirname = path.dirname(filename) import { stripePlugin } from '@payloadcms/plugin-stripe' import { buildConfigWithDefaults } from '../buildConfigWithDefaults.js' @@ -86,4 +90,7 @@ export default buildConfigWithDefaults({ }, }), ], + typescript: { + outputFile: path.resolve(dirname, 'payload-types.ts'), + }, }) diff --git a/test/plugins/config.ts b/test/plugins/config.ts index 52413a4bc..9ba0dfeaf 100644 --- a/test/plugins/config.ts +++ b/test/plugins/config.ts @@ -1,5 +1,10 @@ +import { fileURLToPath } from 'node:url' +import path from 'path' + import { buildConfigWithDefaults } from '../buildConfigWithDefaults.js' import { devUser } from '../credentials.js' +const filename = fileURLToPath(import.meta.url) +const dirname = path.dirname(filename) export const pagesSlug = 'pages' @@ -12,7 +17,7 @@ export default buildConfigWithDefaults({ }, ], plugins: [ - async (config) => ({ + (config) => ({ ...config, collections: [ ...(config.collections || []), @@ -37,4 +42,7 @@ export default buildConfigWithDefaults({ }, }) }, + typescript: { + outputFile: path.resolve(dirname, 'payload-types.ts'), + }, }) diff --git a/test/relationships/config.ts b/test/relationships/config.ts index 81a312a69..33f24ca7e 100644 --- a/test/relationships/config.ts +++ b/test/relationships/config.ts @@ -1,3 +1,7 @@ +import { fileURLToPath } from 'node:url' +import path from 'path' +const filename = fileURLToPath(import.meta.url) +const dirname = path.dirname(filename) import type { CollectionConfig } from 'payload/types' import { buildConfigWithDefaults } from '../buildConfigWithDefaults.js' @@ -390,4 +394,7 @@ export default buildConfigWithDefaults({ }, }) }, + typescript: { + outputFile: path.resolve(dirname, 'payload-types.ts'), + }, }) diff --git a/test/storage-azure/config.ts b/test/storage-azure/config.ts index 56b931ec8..5df214e2e 100644 --- a/test/storage-azure/config.ts +++ b/test/storage-azure/config.ts @@ -45,4 +45,7 @@ export default buildConfigWithDefaults({ }), ], upload: uploadOptions, + typescript: { + outputFile: path.resolve(dirname, 'payload-types.ts'), + }, }) diff --git a/test/storage-azure/payload-types.ts b/test/storage-azure/payload-types.ts index 044e1f787..29a6323da 100644 --- a/test/storage-azure/payload-types.ts +++ b/test/storage-azure/payload-types.ts @@ -36,6 +36,8 @@ export interface Media { filesize?: number | null; width?: number | null; height?: number | null; + focalX?: number | null; + focalY?: number | null; sizes?: { square?: { url?: string | null; @@ -71,6 +73,8 @@ export interface MediaWithPrefix { filesize?: number | null; width?: number | null; height?: number | null; + focalX?: number | null; + focalY?: number | null; } /** * This interface was referenced by `Config`'s JSON-Schema diff --git a/test/storage-gcs/config.ts b/test/storage-gcs/config.ts index 47b8cb897..35509b373 100644 --- a/test/storage-gcs/config.ts +++ b/test/storage-gcs/config.ts @@ -46,4 +46,7 @@ export default buildConfigWithDefaults({ }), ], upload: uploadOptions, + typescript: { + outputFile: path.resolve(dirname, 'payload-types.ts'), + }, }) diff --git a/test/storage-gcs/payload-types.ts b/test/storage-gcs/payload-types.ts index 044e1f787..29a6323da 100644 --- a/test/storage-gcs/payload-types.ts +++ b/test/storage-gcs/payload-types.ts @@ -36,6 +36,8 @@ export interface Media { filesize?: number | null; width?: number | null; height?: number | null; + focalX?: number | null; + focalY?: number | null; sizes?: { square?: { url?: string | null; @@ -71,6 +73,8 @@ export interface MediaWithPrefix { filesize?: number | null; width?: number | null; height?: number | null; + focalX?: number | null; + focalY?: number | null; } /** * This interface was referenced by `Config`'s JSON-Schema diff --git a/test/storage-s3/config.ts b/test/storage-s3/config.ts index 6cc72116f..d1dba8b7a 100644 --- a/test/storage-s3/config.ts +++ b/test/storage-s3/config.ts @@ -51,4 +51,7 @@ export default buildConfigWithDefaults({ }), ], upload: uploadOptions, + typescript: { + outputFile: path.resolve(dirname, 'payload-types.ts'), + }, }) diff --git a/test/storage-s3/payload-types.ts b/test/storage-s3/payload-types.ts index 044e1f787..29a6323da 100644 --- a/test/storage-s3/payload-types.ts +++ b/test/storage-s3/payload-types.ts @@ -36,6 +36,8 @@ export interface Media { filesize?: number | null; width?: number | null; height?: number | null; + focalX?: number | null; + focalY?: number | null; sizes?: { square?: { url?: string | null; @@ -71,6 +73,8 @@ export interface MediaWithPrefix { filesize?: number | null; width?: number | null; height?: number | null; + focalX?: number | null; + focalY?: number | null; } /** * This interface was referenced by `Config`'s JSON-Schema diff --git a/test/storage-uploadthing/config.ts b/test/storage-uploadthing/config.ts index 5fb5e64d5..0335619a5 100644 --- a/test/storage-uploadthing/config.ts +++ b/test/storage-uploadthing/config.ts @@ -40,4 +40,7 @@ export default buildConfigWithDefaults({ }, }), ], + typescript: { + outputFile: path.resolve(dirname, 'payload-types.ts'), + }, }) diff --git a/test/storage-uploadthing/payload-types.ts b/test/storage-uploadthing/payload-types.ts new file mode 100644 index 000000000..c3553fa14 --- /dev/null +++ b/test/storage-uploadthing/payload-types.ts @@ -0,0 +1,137 @@ +/* tslint:disable */ +/* eslint-disable */ +/** + * This file was automatically generated by Payload. + * DO NOT MODIFY IT BY HAND. Instead, modify your source Payload config, + * and re-run `payload generate:types` to regenerate this file. + */ + +export interface Config { + collections: { + media: Media; + 'media-with-prefix': MediaWithPrefix; + users: User; + 'payload-preferences': PayloadPreference; + 'payload-migrations': PayloadMigration; + }; + globals: {}; + locale: null; + user: User & { + collection: 'users'; + }; +} +/** + * This interface was referenced by `Config`'s JSON-Schema + * via the `definition` "media". + */ +export interface Media { + id: string; + alt?: string | null; + _key?: string | null; + updatedAt: string; + createdAt: string; + url?: string | null; + thumbnailURL?: string | null; + filename?: string | null; + mimeType?: string | null; + filesize?: number | null; + width?: number | null; + height?: number | null; + focalX?: number | null; + focalY?: number | null; + sizes?: { + square?: { + _key?: string | null; + url?: string | null; + width?: number | null; + height?: number | null; + mimeType?: string | null; + filesize?: number | null; + filename?: string | null; + }; + sixteenByNineMedium?: { + _key?: string | null; + url?: string | null; + width?: number | null; + height?: number | null; + mimeType?: string | null; + filesize?: number | null; + filename?: string | null; + }; + }; +} +/** + * This interface was referenced by `Config`'s JSON-Schema + * via the `definition` "media-with-prefix". + */ +export interface MediaWithPrefix { + id: string; + updatedAt: string; + createdAt: string; + url?: string | null; + thumbnailURL?: string | null; + filename?: string | null; + mimeType?: string | null; + filesize?: number | null; + width?: number | null; + height?: number | null; + focalX?: number | null; + focalY?: number | null; +} +/** + * This interface was referenced by `Config`'s JSON-Schema + * via the `definition` "users". + */ +export interface User { + id: string; + updatedAt: string; + createdAt: string; + email: string; + resetPasswordToken?: string | null; + resetPasswordExpiration?: string | null; + salt?: string | null; + hash?: string | null; + loginAttempts?: number | null; + lockUntil?: string | null; + password?: string | null; +} +/** + * This interface was referenced by `Config`'s JSON-Schema + * via the `definition` "payload-preferences". + */ +export interface PayloadPreference { + id: string; + user: { + relationTo: 'users'; + value: string | User; + }; + key?: string | null; + value?: + | { + [k: string]: unknown; + } + | unknown[] + | string + | number + | boolean + | null; + updatedAt: string; + createdAt: string; +} +/** + * This interface was referenced by `Config`'s JSON-Schema + * via the `definition` "payload-migrations". + */ +export interface PayloadMigration { + id: string; + name?: string | null; + batch?: number | null; + updatedAt: string; + createdAt: string; +} + + +declare module 'payload' { + // @ts-ignore + export interface GeneratedTypes extends Config {} +} \ No newline at end of file diff --git a/test/storage-vercel-blob/config.ts b/test/storage-vercel-blob/config.ts index 40f566d87..d7dea6969 100644 --- a/test/storage-vercel-blob/config.ts +++ b/test/storage-vercel-blob/config.ts @@ -42,4 +42,7 @@ export default buildConfigWithDefaults({ }), ], upload: uploadOptions, + typescript: { + outputFile: path.resolve(dirname, 'payload-types.ts'), + }, }) diff --git a/test/storage-vercel-blob/payload-types.ts b/test/storage-vercel-blob/payload-types.ts index 044e1f787..29a6323da 100644 --- a/test/storage-vercel-blob/payload-types.ts +++ b/test/storage-vercel-blob/payload-types.ts @@ -36,6 +36,8 @@ export interface Media { filesize?: number | null; width?: number | null; height?: number | null; + focalX?: number | null; + focalY?: number | null; sizes?: { square?: { url?: string | null; @@ -71,6 +73,8 @@ export interface MediaWithPrefix { filesize?: number | null; width?: number | null; height?: number | null; + focalX?: number | null; + focalY?: number | null; } /** * This interface was referenced by `Config`'s JSON-Schema diff --git a/test/uploads/config.ts b/test/uploads/config.ts index fdca3498d..e862ce4ce 100644 --- a/test/uploads/config.ts +++ b/test/uploads/config.ts @@ -554,4 +554,7 @@ export default buildConfigWithDefaults({ fileSize: 2_000_000, // 2MB }, }, + typescript: { + outputFile: path.resolve(dirname, 'payload-types.ts'), + }, }) diff --git a/test/versions/config.ts b/test/versions/config.ts index 84fd34705..eef60f9ed 100644 --- a/test/versions/config.ts +++ b/test/versions/config.ts @@ -1,3 +1,7 @@ +import { fileURLToPath } from 'node:url' +import path from 'path' +const filename = fileURLToPath(import.meta.url) +const dirname = path.dirname(filename) import { buildConfigWithDefaults } from '../buildConfigWithDefaults.js' import AutosavePosts from './collections/Autosave.js' import CustomIDs from './collections/CustomIDs.js' @@ -33,4 +37,7 @@ export default buildConfigWithDefaults({ await seed(payload) } }, + typescript: { + outputFile: path.resolve(dirname, 'payload-types.ts'), + }, })