diff --git a/docs/pages/docs/walkthroughs/lesson-4.md b/docs/pages/docs/walkthroughs/lesson-4.md index 745583969b8..33db767623e 100644 --- a/docs/pages/docs/walkthroughs/lesson-4.md +++ b/docs/pages/docs/walkthroughs/lesson-4.md @@ -152,7 +152,7 @@ const { withAuth } = createAuth({ }); let sessionSecret = '-- DEV COOKIE SECRET; CHANGE ME --'; -let sessionMaxAge = 60 * 60 * 24 * 30; // 30 days +let sessionMaxAge = 60 * 60 * 24; // 24 hours const session = statelessSessions({ maxAge: sessionMaxAge, @@ -240,7 +240,7 @@ const { withAuth } = createAuth({ }); let sessionSecret = '-- DEV COOKIE SECRET; CHANGE ME --'; -let sessionMaxAge = 60 * 60 * 24 * 30; // 30 days +let sessionMaxAge = 60 * 60 * 24; // 24 hours const session = statelessSessions({ maxAge: sessionMaxAge, @@ -272,7 +272,7 @@ const { withAuth } = createAuth({ }); let sessionSecret = '-- DEV COOKIE SECRET; CHANGE ME --'; -let sessionMaxAge = 60 * 60 * 24 * 30; // 30 days +let sessionMaxAge = 60 * 60 * 24; // 24 hours const session = statelessSessions({ maxAge: sessionMaxAge, diff --git a/examples/assets-local/schema.ts b/examples/assets-local/schema.ts index de055001af4..f30734f72c4 100644 --- a/examples/assets-local/schema.ts +++ b/examples/assets-local/schema.ts @@ -2,6 +2,8 @@ import { list } from '@keystone-6/core' import { allowAll } from '@keystone-6/core/access' import { text, image, file } from '@keystone-6/core/fields' +import type { Lists } from '.keystone/types' + export const lists = { Post: list({ access: allowAll, @@ -12,4 +14,4 @@ export const lists = { attachment: file({ storage: 'my_files' }), }, }), -} +} satisfies Lists diff --git a/examples/assets-s3/schema.ts b/examples/assets-s3/schema.ts index de055001af4..f30734f72c4 100644 --- a/examples/assets-s3/schema.ts +++ b/examples/assets-s3/schema.ts @@ -2,6 +2,8 @@ import { list } from '@keystone-6/core' import { allowAll } from '@keystone-6/core/access' import { text, image, file } from '@keystone-6/core/fields' +import type { Lists } from '.keystone/types' + export const lists = { Post: list({ access: allowAll, @@ -12,4 +14,4 @@ export const lists = { attachment: file({ storage: 'my_files' }), }, }), -} +} satisfies Lists diff --git a/examples/auth/keystone.ts b/examples/auth/keystone.ts index 4ae073b7d1a..88f7606d0a1 100644 --- a/examples/auth/keystone.ts +++ b/examples/auth/keystone.ts @@ -2,7 +2,8 @@ import { config } from '@keystone-6/core' import { statelessSessions } from '@keystone-6/core/session' import { createAuth } from '@keystone-6/auth' import { fixPrismaPath } from '../example-utils' -import { lists } from './schema' +import { type Session, lists } from './schema' +import { type TypeInfo } from '.keystone/types' // WARNING: this example is for demonstration purposes only // as with each of our examples, it has not been vetted @@ -13,8 +14,8 @@ const sessionSecret = '-- DEV COOKIE SECRET; CHANGE ME --' // statelessSessions uses cookies for session tracking // these cookies have an expiry, in seconds -// we use an expiry of 30 days for this example -const sessionMaxAge = 60 * 60 * 24 * 30 +// we use an expiry of one hour for this example +const sessionMaxAge = 60 * 60 // withAuth is a function we can use to wrap our base configuration const { withAuth } = createAuth({ @@ -47,8 +48,8 @@ const { withAuth } = createAuth({ sessionData: 'isAdmin', }) -export default withAuth( - config({ +export default withAuth>( + config({ db: { provider: 'sqlite', url: process.env.DATABASE_URL || 'file:./keystone-example.db', @@ -59,8 +60,8 @@ export default withAuth( lists, ui: { // only admins can view the AdminUI - isAccessAllowed: ({ session }) => { - return session?.data?.isAdmin ?? false + isAccessAllowed: (context) => { + return context.session?.data?.isAdmin ?? false }, }, // you can find out more at https://keystonejs.com/docs/apis/session#session-api diff --git a/examples/auth/schema.ts b/examples/auth/schema.ts index 98cf827c449..2879ee9f407 100644 --- a/examples/auth/schema.ts +++ b/examples/auth/schema.ts @@ -7,7 +7,7 @@ import type { Lists } from '.keystone/types' // as with each of our examples, it has not been vetted // or tested for any particular usage -type Session = { +export type Session = { itemId: string data: { isAdmin: boolean @@ -55,7 +55,7 @@ function isAdmin ({ session }: { session?: Session }) { return false } -export const lists: Lists = { +export const lists = { User: list({ access: { operation: { @@ -153,4 +153,4 @@ export const lists: Lists = { }), }, }), -} +} satisfies Lists diff --git a/examples/cloudinary/schema.ts b/examples/cloudinary/schema.ts index 5fb1eff855b..a3cc9474c6b 100644 --- a/examples/cloudinary/schema.ts +++ b/examples/cloudinary/schema.ts @@ -3,6 +3,8 @@ import { allowAll } from '@keystone-6/core/access' import { text } from '@keystone-6/core/fields' import { cloudinaryImage } from '@keystone-6/cloudinary' +import type { Lists } from '.keystone/types' + export const lists = { Post: list({ access: allowAll, @@ -19,4 +21,4 @@ export const lists = { }), }, }), -} +} satisfies Lists diff --git a/examples/custom-admin-ui-logo/schema.ts b/examples/custom-admin-ui-logo/schema.ts index dc24ae46d8f..3e70185066c 100644 --- a/examples/custom-admin-ui-logo/schema.ts +++ b/examples/custom-admin-ui-logo/schema.ts @@ -3,6 +3,8 @@ import { allowAll } from '@keystone-6/core/access' import { checkbox, relationship, text, timestamp } from '@keystone-6/core/fields' import { select } from '@keystone-6/core/fields' +import type { Lists } from '.keystone/types' + export const lists = { Task: list({ access: allowAll, @@ -28,4 +30,4 @@ export const lists = { tasks: relationship({ ref: 'Task.assignedTo', many: true }), }, }), -} +} satisfies Lists diff --git a/examples/custom-admin-ui-navigation/schema.ts b/examples/custom-admin-ui-navigation/schema.ts index dc24ae46d8f..3e70185066c 100644 --- a/examples/custom-admin-ui-navigation/schema.ts +++ b/examples/custom-admin-ui-navigation/schema.ts @@ -3,6 +3,8 @@ import { allowAll } from '@keystone-6/core/access' import { checkbox, relationship, text, timestamp } from '@keystone-6/core/fields' import { select } from '@keystone-6/core/fields' +import type { Lists } from '.keystone/types' + export const lists = { Task: list({ access: allowAll, @@ -28,4 +30,4 @@ export const lists = { tasks: relationship({ ref: 'Task.assignedTo', many: true }), }, }), -} +} satisfies Lists diff --git a/examples/custom-admin-ui-pages/schema.ts b/examples/custom-admin-ui-pages/schema.ts index dc24ae46d8f..3e70185066c 100644 --- a/examples/custom-admin-ui-pages/schema.ts +++ b/examples/custom-admin-ui-pages/schema.ts @@ -3,6 +3,8 @@ import { allowAll } from '@keystone-6/core/access' import { checkbox, relationship, text, timestamp } from '@keystone-6/core/fields' import { select } from '@keystone-6/core/fields' +import type { Lists } from '.keystone/types' + export const lists = { Task: list({ access: allowAll, @@ -28,4 +30,4 @@ export const lists = { tasks: relationship({ ref: 'Task.assignedTo', many: true }), }, }), -} +} satisfies Lists diff --git a/examples/custom-field-view/schema.ts b/examples/custom-field-view/schema.ts index b66f08e90a5..8a6516cd78d 100644 --- a/examples/custom-field-view/schema.ts +++ b/examples/custom-field-view/schema.ts @@ -3,6 +3,8 @@ import { allowAll } from '@keystone-6/core/access' import { checkbox, relationship, text, timestamp } from '@keystone-6/core/fields' import { json, select } from '@keystone-6/core/fields' +import type { Lists } from '.keystone/types' + export const lists = { Task: list({ access: allowAll, @@ -37,4 +39,4 @@ export const lists = { tasks: relationship({ ref: 'Task.assignedTo', many: true }), }, }), -} +} satisfies Lists diff --git a/examples/custom-field/schema.ts b/examples/custom-field/schema.ts index 777785a9db4..ac2899f29a1 100644 --- a/examples/custom-field/schema.ts +++ b/examples/custom-field/schema.ts @@ -10,7 +10,7 @@ import { feedback } from './4-conditional-field' import type { Lists } from '.keystone/types' -export const lists: Lists = { +export const lists = { Post: list({ access: allowAll, fields: { @@ -109,4 +109,4 @@ export const lists: Lists = { }, }, }), -} +} satisfies Lists diff --git a/examples/custom-id/schema.ts b/examples/custom-id/schema.ts index 1748f06e078..822aee677dc 100644 --- a/examples/custom-id/schema.ts +++ b/examples/custom-id/schema.ts @@ -8,7 +8,7 @@ function makeCustomIdentifier (listKey: string) { return `${listKey.toUpperCase()}_${createId()}` } -export const lists: Lists = { +export const lists = { Task: list({ access: allowAll, db: { @@ -48,4 +48,4 @@ export const lists: Lists = { }, }, }), -} +} satisfies Lists diff --git a/examples/custom-output-paths/schema.ts b/examples/custom-output-paths/schema.ts index 9ec2b149a40..e81eb845ad0 100644 --- a/examples/custom-output-paths/schema.ts +++ b/examples/custom-output-paths/schema.ts @@ -3,7 +3,7 @@ import { allowAll } from '@keystone-6/core/access' import { text, timestamp } from '@keystone-6/core/fields' import type { Lists } from './my-types' -export const lists: Lists = { +export const lists = { Post: list({ access: allowAll, fields: { @@ -34,4 +34,4 @@ export const lists: Lists = { }, }, }), -} +} satisfies Lists diff --git a/examples/custom-session-invalidation/schema.ts b/examples/custom-session-invalidation/schema.ts index cd4d4df26c8..a633f0a1a01 100644 --- a/examples/custom-session-invalidation/schema.ts +++ b/examples/custom-session-invalidation/schema.ts @@ -33,7 +33,7 @@ function isSameUserFilter ({ session }: { session?: Session }) { } } -export const lists: Lists = { +export const lists = { User: list({ access: { operation: hasSession, @@ -85,4 +85,4 @@ export const lists: Lists = { }, }, }), -} +} satisfies Lists diff --git a/examples/custom-session-jwt/schema.ts b/examples/custom-session-jwt/schema.ts index 6c7c06420a2..ad0496e080a 100644 --- a/examples/custom-session-jwt/schema.ts +++ b/examples/custom-session-jwt/schema.ts @@ -25,7 +25,7 @@ function isAdminOrOnlySameUser ({ session }: { session?: Session }) { } } -export const lists: Lists = { +export const lists = { Post: list({ access: { operation: { @@ -61,4 +61,4 @@ export const lists: Lists = { admin: checkbox(), }, }), -} +} satisfies Lists diff --git a/examples/custom-session-next-auth/schema.ts b/examples/custom-session-next-auth/schema.ts index 8141fe631cf..1aa3f1103e3 100644 --- a/examples/custom-session-next-auth/schema.ts +++ b/examples/custom-session-next-auth/schema.ts @@ -12,7 +12,7 @@ function hasSession ({ session }: { session?: Session }) { return Boolean(session) } -export const lists: Lists = { +export const lists = { Post: list({ // WARNING - for this example, anyone can that can login can create, query, update and delete anything // -- anyone with an account on the auth provider you are using can login @@ -43,4 +43,4 @@ export const lists: Lists = { posts: relationship({ ref: 'Post.author', many: true }), }, }), -} +} satisfies Lists diff --git a/examples/custom-session-redis/schema.ts b/examples/custom-session-redis/schema.ts index 2de6e6a6586..d41b5708c68 100644 --- a/examples/custom-session-redis/schema.ts +++ b/examples/custom-session-redis/schema.ts @@ -32,7 +32,7 @@ function isSameUserFilter ({ session }: { session?: Session }) { } } -export const lists: Lists = { +export const lists = { User: list({ access: { operation: hasSession, @@ -62,4 +62,4 @@ export const lists: Lists = { }), }, }), -} +} satisfies Lists diff --git a/examples/custom-session/schema.ts b/examples/custom-session/schema.ts index de4df6d5a76..5a07a428ed1 100644 --- a/examples/custom-session/schema.ts +++ b/examples/custom-session/schema.ts @@ -25,7 +25,7 @@ function isAdminOrOnlySameUser ({ session }: { session?: Session }) { } } -export const lists: Lists = { +export const lists = { Post: list({ access: { operation: { @@ -63,4 +63,4 @@ export const lists: Lists = { admin: checkbox(), }, }), -} +} satisfies Lists diff --git a/examples/default-values/schema.ts b/examples/default-values/schema.ts index 8479e7a012e..839dee0e55b 100644 --- a/examples/default-values/schema.ts +++ b/examples/default-values/schema.ts @@ -4,7 +4,7 @@ import { select } from '@keystone-6/core/fields' import { allowAll } from '@keystone-6/core/access' import type { Lists } from '.keystone/types' -export const lists: Lists = { +export const lists = { Task: list({ access: allowAll, fields: { @@ -82,4 +82,4 @@ export const lists: Lists = { tasks: relationship({ ref: 'Task.assignedTo', many: true }), }, }), -} +} satisfies Lists diff --git a/examples/document-field-customisation/keystone-server/src/schema.ts b/examples/document-field-customisation/keystone-server/src/schema.ts index 97b41be4a87..55fc4f413a4 100644 --- a/examples/document-field-customisation/keystone-server/src/schema.ts +++ b/examples/document-field-customisation/keystone-server/src/schema.ts @@ -2,11 +2,11 @@ import { list } from '@keystone-6/core' import { allowAll } from '@keystone-6/core/access' import { relationship, text, timestamp } from '@keystone-6/core/fields' import { document } from '@keystone-6/fields-document' -import type { KeystoneConfig } from '@keystone-6/core/types' import { componentBlocks } from './component-blocks' -import { type TypeInfo } from '.keystone/types' -export const lists: KeystoneConfig['lists'] = { +import type { Lists } from '.keystone/types' + +export const lists = { User: list({ access: allowAll, fields: { @@ -39,4 +39,4 @@ export const lists: KeystoneConfig['lists'] = { author: relationship({ ref: 'User.posts', many: false }), }, }), -} +} satisfies Lists diff --git a/examples/document-field/schema.ts b/examples/document-field/schema.ts index 6675aacf8b0..7c3d65eafa9 100644 --- a/examples/document-field/schema.ts +++ b/examples/document-field/schema.ts @@ -3,6 +3,8 @@ import { select, relationship, text, timestamp } from '@keystone-6/core/fields' import { document } from '@keystone-6/fields-document' import { allowAll } from '@keystone-6/core/access' +import type { Lists } from '.keystone/types' + export const lists = { Post: list({ access: allowAll, @@ -62,4 +64,4 @@ export const lists = { }), }, }), -} +} satisfies Lists diff --git a/examples/extend-express-app/schema.ts b/examples/extend-express-app/schema.ts index 9a7141a84d6..6aa4910b7cb 100644 --- a/examples/extend-express-app/schema.ts +++ b/examples/extend-express-app/schema.ts @@ -2,9 +2,10 @@ import { list } from '@keystone-6/core' import { allowAll } from '@keystone-6/core/access' import { checkbox, relationship, text, timestamp } from '@keystone-6/core/fields' import { select } from '@keystone-6/core/fields' + import { type Lists } from '.keystone/types' -export const lists: Lists = { +export const lists = { Task: list({ access: allowAll, fields: { @@ -29,4 +30,4 @@ export const lists: Lists = { tasks: relationship({ ref: 'Task.assignedTo', many: true }), }, }), -} +} satisfies Lists diff --git a/examples/extend-graphql-schema-graphql-tools/schema.ts b/examples/extend-graphql-schema-graphql-tools/schema.ts index 012507b359a..a3b1b786286 100644 --- a/examples/extend-graphql-schema-graphql-tools/schema.ts +++ b/examples/extend-graphql-schema-graphql-tools/schema.ts @@ -3,9 +3,10 @@ import type { GraphQLSchema } from 'graphql' import { mergeSchemas } from '@graphql-tools/schema' import { allowAll } from '@keystone-6/core/access' import { select, relationship, text, timestamp } from '@keystone-6/core/fields' + import { type Lists, type Context } from '.keystone/types' -export const lists: Lists = { +export const lists = { Post: list({ access: allowAll, fields: { @@ -30,7 +31,7 @@ export const lists: Lists = { posts: relationship({ ref: 'Post.author', many: true }), }, }), -} +} satisfies Lists export function extendGraphqlSchema (baseSchema: GraphQLSchema) { return mergeSchemas({ diff --git a/examples/extend-graphql-schema-graphql-ts/schema.ts b/examples/extend-graphql-schema-graphql-ts/schema.ts index 5aaba8d092f..88fa002334c 100644 --- a/examples/extend-graphql-schema-graphql-ts/schema.ts +++ b/examples/extend-graphql-schema-graphql-ts/schema.ts @@ -3,7 +3,7 @@ import { allowAll } from '@keystone-6/core/access' import { select, relationship, text, timestamp } from '@keystone-6/core/fields' import { type Context, type Lists } from '.keystone/types' -export const lists: Lists = { +export const lists = { Post: list({ access: allowAll, fields: { @@ -29,7 +29,7 @@ export const lists: Lists = { posts: relationship({ ref: 'Post.author', many: true }), }, }), -} +} satisfies Lists export const extendGraphqlSchema = graphql.extend(base => { const Statistics = graphql.object<{ authorId: string }>()({ diff --git a/examples/extend-graphql-schema-nexus/schema.ts b/examples/extend-graphql-schema-nexus/schema.ts index c1bc875b254..d0b089ed14b 100644 --- a/examples/extend-graphql-schema-nexus/schema.ts +++ b/examples/extend-graphql-schema-nexus/schema.ts @@ -4,9 +4,10 @@ import { list } from '@keystone-6/core' import { allowAll } from '@keystone-6/core/access' import { select, relationship, text, timestamp } from '@keystone-6/core/fields' import * as nexus from 'nexus' + import type { Lists } from './keystone-types' -export const lists: Lists = { +export const lists = { Post: list({ access: allowAll, fields: { @@ -30,7 +31,7 @@ export const lists: Lists = { posts: relationship({ ref: 'Post.author', many: true }), }, }), -} +} satisfies Lists export function extendGraphqlSchema (baseSchema: GraphQLSchema) { const NexusPostQuery = nexus.extendType({ diff --git a/examples/extend-graphql-subscriptions/schema.ts b/examples/extend-graphql-subscriptions/schema.ts index 48baeb77fbf..ce54e31ff53 100644 --- a/examples/extend-graphql-subscriptions/schema.ts +++ b/examples/extend-graphql-subscriptions/schema.ts @@ -7,7 +7,7 @@ import { pubSub } from './websocket' import type { Lists } from '.keystone/types' -export const lists: Lists = { +export const lists = { Post: list({ access: allowAll, hooks: { @@ -47,7 +47,7 @@ export const lists: Lists = { posts: relationship({ ref: 'Post.author', many: true }), }, }), -} +} satisfies Lists export const extendGraphqlSchema = (schema: GraphQLSchema) => mergeSchemas({ diff --git a/examples/extend-prisma-schema/schema.ts b/examples/extend-prisma-schema/schema.ts index 7c8398bb501..17e81f6815c 100644 --- a/examples/extend-prisma-schema/schema.ts +++ b/examples/extend-prisma-schema/schema.ts @@ -1,9 +1,10 @@ import { list } from '@keystone-6/core' import { text, relationship } from '@keystone-6/core/fields' import { allowAll } from '@keystone-6/core/access' + import { type Lists } from '.keystone/types' -export const lists: Lists = { +export const lists = { Author: list({ access: allowAll, fields: { @@ -12,7 +13,7 @@ export const lists: Lists = { }, db: { extendPrismaSchema: schema => { - // add a bad example of a multi-column unique constraint + // add a (poor) example of a multi-column unique constraint return schema.replace(/(model [^}]+)}/g, '$1@@unique([firstName, lastName])\n}') }, }, @@ -47,4 +48,4 @@ export const lists: Lists = { }), }, }), -} +} satisfies Lists diff --git a/examples/field-groups/schema.ts b/examples/field-groups/schema.ts index 3746a188b40..ad73009af9c 100644 --- a/examples/field-groups/schema.ts +++ b/examples/field-groups/schema.ts @@ -1,9 +1,10 @@ import { list, group } from '@keystone-6/core' import { allowAll, denyAll } from '@keystone-6/core/access' import { text } from '@keystone-6/core/fields' + import type { Lists } from '.keystone/types' -export const lists: Lists = { +export const lists = { Post: list({ access: allowAll, fields: { @@ -46,4 +47,4 @@ export const lists: Lists = { }), }, }), -} +} satisfies Lists diff --git a/examples/framework-astro/src/keystone/schema.ts b/examples/framework-astro/src/keystone/schema.ts index 2c7e91b7d70..c9d31fd605f 100644 --- a/examples/framework-astro/src/keystone/schema.ts +++ b/examples/framework-astro/src/keystone/schema.ts @@ -18,7 +18,7 @@ import { text, select } from '@keystone-6/core/fields' // the generated types from '.keystone/types' import type { Lists } from '.keystone/types' -export const lists: Lists = { +export const lists = { Post: list({ // WARNING // for this starter project, anyone can create, query, update and delete anything @@ -54,4 +54,4 @@ export const lists: Lists = { }), }, }), -} +} satisfies Lists diff --git a/examples/framework-nextjs-app-directory/src/keystone/schema.ts b/examples/framework-nextjs-app-directory/src/keystone/schema.ts index 03817fe8423..cee972caac8 100644 --- a/examples/framework-nextjs-app-directory/src/keystone/schema.ts +++ b/examples/framework-nextjs-app-directory/src/keystone/schema.ts @@ -2,9 +2,10 @@ import { list } from '@keystone-6/core' import { allowAll } from '@keystone-6/core/access' import { text, timestamp } from '@keystone-6/core/fields' import { document } from '@keystone-6/fields-document' + import type { Lists } from '.keystone/types' -export const lists: Lists = { +export const lists = { User: list({ // WARNING // for this example, anyone can create, query, update and delete anything @@ -28,4 +29,4 @@ export const lists: Lists = { }), }, }), -} +} satisfies Lists diff --git a/examples/framework-nextjs-pages-directory/src/keystone/schema.ts b/examples/framework-nextjs-pages-directory/src/keystone/schema.ts index bba465cc51f..59ab01ef74d 100644 --- a/examples/framework-nextjs-pages-directory/src/keystone/schema.ts +++ b/examples/framework-nextjs-pages-directory/src/keystone/schema.ts @@ -3,7 +3,7 @@ import { allowAll } from '@keystone-6/core/access' import { text, timestamp } from '@keystone-6/core/fields' import type { Lists } from '.keystone/types' -export const lists: Lists = { +export const lists = { User: list({ // WARNING // for this example, anyone can create, query, update and delete anything @@ -19,4 +19,4 @@ export const lists: Lists = { }), }, }), -} +} satisfies Lists diff --git a/examples/framework-nextjs-two-servers/keystone-server/src/schema.ts b/examples/framework-nextjs-two-servers/keystone-server/src/schema.ts index 8af19b1de47..66ed3e0b919 100644 --- a/examples/framework-nextjs-two-servers/keystone-server/src/schema.ts +++ b/examples/framework-nextjs-two-servers/keystone-server/src/schema.ts @@ -2,10 +2,10 @@ import { list } from '@keystone-6/core' import { allowAll } from '@keystone-6/core/access' import { relationship, text, timestamp } from '@keystone-6/core/fields' import { document } from '@keystone-6/fields-document' -import type { KeystoneConfig } from '@keystone-6/core/types' -import { type TypeInfo } from '.keystone/types' -export const lists: KeystoneConfig['lists'] = { +import type { Lists } from '.keystone/types' + +export const lists = { User: list({ access: allowAll, fields: { @@ -33,4 +33,4 @@ export const lists: KeystoneConfig['lists'] = { author: relationship({ ref: 'User.posts', many: false }), }, }), -} +} satisfies Lists diff --git a/examples/framework-remix/keystone.ts b/examples/framework-remix/keystone.ts index 5e17561e315..cd6af71d89d 100644 --- a/examples/framework-remix/keystone.ts +++ b/examples/framework-remix/keystone.ts @@ -2,6 +2,7 @@ import { list, config } from '@keystone-6/core' import { allowAll } from '@keystone-6/core/access' import { text } from '@keystone-6/core/fields' import { fixPrismaPath } from '../example-utils' + import type { TypeInfo } from '.keystone/types' export default config({ diff --git a/examples/graphql-ts-gql/schema.ts b/examples/graphql-ts-gql/schema.ts index 7af554db320..d67b4d333ca 100644 --- a/examples/graphql-ts-gql/schema.ts +++ b/examples/graphql-ts-gql/schema.ts @@ -2,9 +2,10 @@ import { list, graphql } from '@keystone-6/core' import { select, relationship, text, timestamp, virtual } from '@keystone-6/core/fields' import { allowAll } from '@keystone-6/core/access' import { gql } from '@ts-gql/tag/no-transform' -import { type Lists, type Context } from '.keystone/types' -export const lists: Lists = { +import type { Lists } from '.keystone/types' + +export const lists = { Post: list({ access: allowAll, fields: { @@ -82,8 +83,7 @@ export const lists: Lists = { authorName: virtual({ field: graphql.field({ type: graphql.String, - async resolve (item, args, _context) { - const context = _context as Context + async resolve (item, args, context) { const POST_AUTHOR_QUERY = gql` query POST_AUTHOR_QUERY($id: ID!) { post(where: { id: $id }) { @@ -117,8 +117,7 @@ export const lists: Lists = { field: lists => graphql.field({ type: lists.Post.types.output, - async resolve (item, args, _context) { - const context = _context as Context + async resolve (item, args, context) { const LATEST_POST_QUERY = gql` query LATEST_POST_QUERY($id: ID!) { author(where: { id: $id }) { @@ -143,4 +142,4 @@ export const lists: Lists = { }), }, }), -} +} satisfies Lists diff --git a/examples/hooks/schema.ts b/examples/hooks/schema.ts index b8c4091b961..7b5472397ed 100644 --- a/examples/hooks/schema.ts +++ b/examples/hooks/schema.ts @@ -1,6 +1,7 @@ import { list, group } from '@keystone-6/core' import { allowAll, denyAll } from '@keystone-6/core/access' import { checkbox, text, timestamp } from '@keystone-6/core/fields' + import type { Lists } from '.keystone/types' // WARNING: this example is for demonstration purposes only @@ -32,7 +33,7 @@ const readOnly = { }, } -export const lists: Lists = { +export const lists = { Post: list({ access: allowAll, // WARNING: public fields: { @@ -168,4 +169,4 @@ export const lists: Lists = { }, }, }), -} +} satisfies Lists diff --git a/examples/limits/schema.ts b/examples/limits/schema.ts index 1081ce2fb8c..d5cd42dcd12 100644 --- a/examples/limits/schema.ts +++ b/examples/limits/schema.ts @@ -2,6 +2,8 @@ import { list } from '@keystone-6/core' import { allowAll } from '@keystone-6/core/access' import { text } from '@keystone-6/core/fields' +import type { Lists } from '.keystone/types' + export const lists = { Post: list({ access: allowAll, @@ -14,4 +16,4 @@ export const lists = { maxTake: 20, }, }), -} +} satisfies Lists diff --git a/examples/omit/schema.ts b/examples/omit/schema.ts index 87b2ecba28e..9c3e84eba83 100644 --- a/examples/omit/schema.ts +++ b/examples/omit/schema.ts @@ -1,9 +1,10 @@ import { list } from '@keystone-6/core' import { allowAll } from '@keystone-6/core/access' import { text, relationship } from '@keystone-6/core/fields' + import type { Lists } from '.keystone/types' -export const lists: Lists = { +export const lists = { Person: list({ access: allowAll, fields: { @@ -72,4 +73,4 @@ export const lists: Lists = { }), }, }), -} +} satisfies Lists diff --git a/examples/reuse/schema.ts b/examples/reuse/schema.ts index 5ca16573a25..6cc07c52e6f 100644 --- a/examples/reuse/schema.ts +++ b/examples/reuse/schema.ts @@ -3,6 +3,7 @@ import { list } from '@keystone-6/core' import type { FieldHooks } from '@keystone-6/core/types' import { allowAll, denyAll } from '@keystone-6/core/access' import { checkbox, text, timestamp } from '@keystone-6/core/fields' + import type { Lists, TypeInfo } from '.keystone/types' const readOnly = { @@ -119,7 +120,7 @@ function trackingFields () { } } -export const lists: Lists = { +export const lists = { Invoice: list({ access: allowAll, fields: { @@ -144,4 +145,4 @@ export const lists: Lists = { name: text(), }, }), -} +} satisfies Lists diff --git a/examples/singleton/schema.ts b/examples/singleton/schema.ts index df81a6666dc..b6841347ac0 100644 --- a/examples/singleton/schema.ts +++ b/examples/singleton/schema.ts @@ -2,6 +2,8 @@ import { list } from '@keystone-6/core' import { allowAll } from '@keystone-6/core/access' import { relationship, text, timestamp } from '@keystone-6/core/fields' +import type { Lists } from '.keystone/types' + export const lists = { Settings: list({ access: allowAll, @@ -23,4 +25,4 @@ export const lists = { publishDate: timestamp(), }, }), -} +} satisfies Lists diff --git a/examples/testing/schema.ts b/examples/testing/schema.ts index 4de22811cee..ec4996bd081 100644 --- a/examples/testing/schema.ts +++ b/examples/testing/schema.ts @@ -25,7 +25,7 @@ function isAssignedUserFilter ({ session }: { session?: Session }) { } } -export const lists: Lists = { +export const lists = { Task: list({ access: { operation: allowAll, @@ -56,4 +56,4 @@ export const lists: Lists = { tasks: relationship({ ref: 'Task.assignedTo', many: true }), }, }), -} +} satisfies Lists diff --git a/examples/usecase-blog-moderated/schema.ts b/examples/usecase-blog-moderated/schema.ts index a577fa9a790..01799a31872 100644 --- a/examples/usecase-blog-moderated/schema.ts +++ b/examples/usecase-blog-moderated/schema.ts @@ -97,7 +97,7 @@ function editOnlyViewBy (f: ({ session }: { session?: Session }) => boolean) { return viewOnlyBy(f, 'edit') } -export const lists: Lists = { +export const lists = { Post: list({ access: { operation: { @@ -275,4 +275,4 @@ export const lists: Lists = { moderator: relationship({ ref: 'Moderator' }), }, }), -} +} satisfies Lists diff --git a/examples/usecase-blog/schema.ts b/examples/usecase-blog/schema.ts index d2be82586ff..0f278ce9127 100644 --- a/examples/usecase-blog/schema.ts +++ b/examples/usecase-blog/schema.ts @@ -13,7 +13,7 @@ import { document } from '@keystone-6/fields-document' // the generated types from '.keystone/types' import type { Lists } from '.keystone/types' -export const lists: Lists = { +export const lists = { Author: list({ // WARNING // for this example, anyone can create, query, update and delete anything @@ -118,4 +118,4 @@ export const lists: Lists = { posts: relationship({ ref: 'Post.tags', many: true }), }, }), -} +} satisfies Lists diff --git a/examples/usecase-relationship-union/schema.ts b/examples/usecase-relationship-union/schema.ts index 5641385c07e..efda8ca3385 100644 --- a/examples/usecase-relationship-union/schema.ts +++ b/examples/usecase-relationship-union/schema.ts @@ -14,7 +14,7 @@ function ifUnsetHideUI (field: string) { } } -export const lists: Lists = { +export const lists = { Post: list({ access: allowAll, fields: { @@ -127,4 +127,4 @@ export const lists: Lists = { }, }, }), -} +} satisfies Lists diff --git a/examples/usecase-roles/schema.ts b/examples/usecase-roles/schema.ts index c620ccf9fd1..246e0786604 100644 --- a/examples/usecase-roles/schema.ts +++ b/examples/usecase-roles/schema.ts @@ -19,7 +19,7 @@ import type { Lists } from '.keystone/types' - All users can see and manage todo items assigned to themselves */ -export const lists: Lists = { +export const lists = { Todo: list({ /* SPEC @@ -248,4 +248,4 @@ export const lists: Lists = { }), }, }), -} +} satisfies Lists diff --git a/examples/usecase-todo/schema.ts b/examples/usecase-todo/schema.ts index 44cc58ecc2d..7c978f3f67f 100644 --- a/examples/usecase-todo/schema.ts +++ b/examples/usecase-todo/schema.ts @@ -4,7 +4,7 @@ import { checkbox, relationship, text, timestamp } from '@keystone-6/core/fields import { select } from '@keystone-6/core/fields' import type { Lists } from '.keystone/types' -export const lists: Lists = { +export const lists = { Task: list({ access: allowAll, fields: { @@ -29,4 +29,4 @@ export const lists: Lists = { tasks: relationship({ ref: 'Task.assignedTo', many: true }), }, }), -} +} satisfies Lists diff --git a/examples/usecase-versioning/schema.ts b/examples/usecase-versioning/schema.ts index f1ad2c2a00a..46ba7cca800 100644 --- a/examples/usecase-versioning/schema.ts +++ b/examples/usecase-versioning/schema.ts @@ -1,9 +1,10 @@ import { list } from '@keystone-6/core' import { allowAll } from '@keystone-6/core/access' import { integer, text } from '@keystone-6/core/fields' + import { type Lists } from '.keystone/types' -export const lists: Lists = { +export const lists = { Post: list({ access: allowAll, fields: { @@ -36,4 +37,4 @@ export const lists: Lists = { }), }, }), -} +} satisfies Lists diff --git a/examples/virtual-field/schema.ts b/examples/virtual-field/schema.ts index ae920baa967..2dbcd848fce 100644 --- a/examples/virtual-field/schema.ts +++ b/examples/virtual-field/schema.ts @@ -1,9 +1,10 @@ import { list, graphql } from '@keystone-6/core' import { text, checkbox, virtual } from '@keystone-6/core/fields' import { allowAll } from '@keystone-6/core/access' + import type { Lists } from '.keystone/types' -export const lists: Lists = { +export const lists = { Post: list({ access: allowAll, // WARNING: public fields: { @@ -106,4 +107,4 @@ export const lists: Lists = { }), }, }), -} +} satisfies Lists diff --git a/packages/auth/src/pages/InitPage.tsx b/packages/auth/src/pages/InitPage.tsx index 950ed5445a0..cc92c2ee987 100644 --- a/packages/auth/src/pages/InitPage.tsx +++ b/packages/auth/src/pages/InitPage.tsx @@ -148,13 +148,15 @@ function Welcome ({ value, onContinue }: { value: any, onContinue: () => void }) ) } -type InitPageProps = { +function InitPage ({ + fieldPaths, + listKey, + enableWelcome +}: { listKey: string fieldPaths: string[] enableWelcome: boolean -} - -function InitPage ({ fieldPaths, listKey, enableWelcome }: InitPageProps) { +}) { const { adminMeta } = useKeystone() const fields = useMemo(() => { const fields: Record = {} @@ -271,4 +273,4 @@ function InitPage ({ fieldPaths, listKey, enableWelcome }: InitPageProps) { ) } -export const getInitPage = (props: InitPageProps) => () => +export const getInitPage = (props: Parameters[0]) => () => diff --git a/packages/auth/src/pages/SigninPage.tsx b/packages/auth/src/pages/SigninPage.tsx index d4df77b6aa6..d0b5b7536d7 100644 --- a/packages/auth/src/pages/SigninPage.tsx +++ b/packages/auth/src/pages/SigninPage.tsx @@ -24,13 +24,13 @@ type SigninPageProps = { export const getSigninPage = (props: SigninPageProps) => () => -export const SigninPage = ({ +export function SigninPage ({ identityField, secretField, mutationName, successTypename, failureTypename, -}: SigninPageProps) => { +}: SigninPageProps) { const mutation = gql` mutation($identity: String!, $secret: String!) { authenticate: ${mutationName}(${identityField}: $identity, ${secretField}: $secret) { diff --git a/packages/core/src/___internal-do-not-use-will-break-in-patch/admin-ui/id-field-view.tsx b/packages/core/src/___internal-do-not-use-will-break-in-patch/admin-ui/id-field-view.tsx index 72508c75bbc..44c788f4ed5 100644 --- a/packages/core/src/___internal-do-not-use-will-break-in-patch/admin-ui/id-field-view.tsx +++ b/packages/core/src/___internal-do-not-use-will-break-in-patch/admin-ui/id-field-view.tsx @@ -12,7 +12,9 @@ import type { } from '../../types' import { CellLink, CellContainer } from '../../admin-ui/components' -export const Field = () => null +export function Field () { + return null +} export const Cell: CellComponent = ({ item, field, linkTo }) => { let value = item[field.path] + '' @@ -29,9 +31,9 @@ export const CardValue: CardValueComponent = ({ item, field }) => { ) } -export const controller = ( +export function controller ( config: FieldControllerConfig -): FieldController => { +): FieldController { return { path: config.path, label: config.label, diff --git a/packages/core/src/___internal-do-not-use-will-break-in-patch/admin-ui/pages/HomePage/index.tsx b/packages/core/src/___internal-do-not-use-will-break-in-patch/admin-ui/pages/HomePage/index.tsx index ee564baa4fd..c64ab913080 100644 --- a/packages/core/src/___internal-do-not-use-will-break-in-patch/admin-ui/pages/HomePage/index.tsx +++ b/packages/core/src/___internal-do-not-use-will-break-in-patch/admin-ui/pages/HomePage/index.tsx @@ -13,7 +13,11 @@ import { gql, useQuery } from '../../../../admin-ui/apollo' import { useKeystone, useList } from '../../../../admin-ui/context' import { Link, type LinkProps } from '../../../../admin-ui/router' -type ListCardProps = { +function ListCard ({ + listKey, + count, + hideCreate +}: { listKey: string hideCreate: boolean count: @@ -21,9 +25,7 @@ type ListCardProps = { | { type: 'no-access' } | { type: 'error', message: string } | { type: 'loading' } -} - -const ListCard = ({ listKey, count, hideCreate }: ListCardProps) => { +}) { const { colors, palette, radii, spacing } = useTheme() const list = useList(listKey) return ( @@ -72,7 +74,7 @@ const ListCard = ({ listKey, count, hideCreate }: ListCardProps) => { ) } -const CreateButton = (props: LinkProps) => { +function CreateButton (props: LinkProps) { const theme = useTheme() return ( { ) } -export const HomePage = () => { +export function HomePage () { const { adminMeta: { lists }, visibleLists, diff --git a/packages/core/src/___internal-do-not-use-will-break-in-patch/admin-ui/pages/ItemPage/index.tsx b/packages/core/src/___internal-do-not-use-will-break-in-patch/admin-ui/pages/ItemPage/index.tsx index 9bc861e3fc1..b5f3d46cd42 100644 --- a/packages/core/src/___internal-do-not-use-will-break-in-patch/admin-ui/pages/ItemPage/index.tsx +++ b/packages/core/src/___internal-do-not-use-will-break-in-patch/admin-ui/pages/ItemPage/index.tsx @@ -567,7 +567,7 @@ function ResetChangesButton (props: { onReset: () => void }) { ) } -const StickySidebar = (props: HTMLAttributes) => { +function StickySidebar (props: HTMLAttributes) { const { spacing } = useTheme() return (
() => -const ListPage = ({ listKey }: ListPageProps) => { +function ListPage ({ listKey }: ListPageProps) { const list = useList(listKey) const { query, push } = useRouter() diff --git a/packages/core/src/admin-ui/context.tsx b/packages/core/src/admin-ui/context.tsx index 99cd780ea90..cdfadb27ffa 100644 --- a/packages/core/src/admin-ui/context.tsx +++ b/packages/core/src/admin-ui/context.tsx @@ -83,7 +83,7 @@ function InternalKeystoneProvider ({ ) } -export const KeystoneProvider = (props: KeystoneProviderProps) => { +export function KeystoneProvider (props: KeystoneProviderProps) { const apolloClient = useMemo( () => new ApolloClient({ diff --git a/packages/core/src/admin-ui/system/generateAdminUI.ts b/packages/core/src/admin-ui/system/generateAdminUI.ts index 5b1482759ca..e2ad77ba5f6 100644 --- a/packages/core/src/admin-ui/system/generateAdminUI.ts +++ b/packages/core/src/admin-ui/system/generateAdminUI.ts @@ -6,11 +6,20 @@ import type { GraphQLSchema } from 'graphql' import { type Entry, walk as _walk } from '@nodelib/fs.walk' import type { KeystoneConfig, AdminFileToWrite } from '../../types' import { writeAdminFiles } from '../templates' -import { serializePathForImport } from '../utils/serializePathForImport' import type { AdminMetaRootVal } from '../../lib/create-admin-meta' const walk = promisify(_walk) +function serializePathForImport (path: string) { + // JSON.stringify is important here because it will escape windows style paths(and any thing else that might potentially be in there) + return JSON.stringify( + path + // Next is unhappy about imports that include .ts/tsx in them because TypeScript is unhappy with them because when doing a TypeScript compilation with tsc, the imports won't be written so they would be wrong there + .replace(/\.tsx?$/, '') + .replace(new RegExp(`\\${Path.sep}`, 'g'), '/') + ) +} + function getDoesAdminConfigExist () { try { const configPath = Path.join(process.cwd(), 'admin', 'config') diff --git a/packages/core/src/admin-ui/utils/serializePathForImport.ts b/packages/core/src/admin-ui/utils/serializePathForImport.ts deleted file mode 100644 index c08358cd81d..00000000000 --- a/packages/core/src/admin-ui/utils/serializePathForImport.ts +++ /dev/null @@ -1,10 +0,0 @@ -import Path from 'path' -export function serializePathForImport (path: string) { - // JSON.stringify is important here because it will escape windows style paths(and any thing else that might potentially be in there) - return JSON.stringify( - path - // Next is unhappy about imports that include .ts/tsx in them because TypeScript is unhappy with them because when doing a TypeScript compilation with tsc, the imports won't be written so they would be wrong there - .replace(/\.tsx?$/, '') - .replace(new RegExp(`\\${Path.sep}`, 'g'), '/') - ) -} diff --git a/packages/core/src/admin-ui/utils/useAdminMeta.tsx b/packages/core/src/admin-ui/utils/useAdminMeta.tsx index 28507e23776..a83a11ff2c4 100644 --- a/packages/core/src/admin-ui/utils/useAdminMeta.tsx +++ b/packages/core/src/admin-ui/utils/useAdminMeta.tsx @@ -76,13 +76,14 @@ export function useAdminMeta (adminMetaHash: string, fieldViews: FieldViews) { } for (const field of list.fields) { - expectedExports.forEach(exportName => { + for (const exportName of expectedExports) { if ((fieldViews[field.viewsIndex] as any)[exportName] === undefined) { throw new Error( `The view for the field at ${list.key}.${field.path} is missing the ${exportName} export` ) } - }) + } + Object.keys(fieldViews[field.viewsIndex]).forEach(exportName => { if (!expectedExports.has(exportName) && exportName !== 'allowedExportsOnCustomViews') { throw new Error( @@ -90,11 +91,11 @@ export function useAdminMeta (adminMetaHash: string, fieldViews: FieldViews) { ) } }) + const views = { ...fieldViews[field.viewsIndex] } const customViews: Record = {} if (field.customViewsIndex !== null) { - const customViewsSource: FieldViews[number] & Record = - fieldViews[field.customViewsIndex] + const customViewsSource: FieldViews[number] & Record = fieldViews[field.customViewsIndex] const allowedExportsOnCustomViews = new Set(views.allowedExportsOnCustomViews) Object.keys(customViewsSource).forEach(exportName => { if (allowedExportsOnCustomViews.has(exportName)) { diff --git a/packages/core/src/admin-ui/utils/useCreateItem.ts b/packages/core/src/admin-ui/utils/useCreateItem.ts index 426dbbbebb7..cc6f9d46c68 100644 --- a/packages/core/src/admin-ui/utils/useCreateItem.ts +++ b/packages/core/src/admin-ui/utils/useCreateItem.ts @@ -67,7 +67,6 @@ export function useCreateItem (list: ListMeta): CreateItemHookResult { }) const shouldPreventNavigation = !returnedData?.item && Object.keys(data).length !== 0 - const shouldPreventNavigationRef = useRef(shouldPreventNavigation) useEffect(() => { diff --git a/packages/core/src/fields/types/checkbox/index.ts b/packages/core/src/fields/types/checkbox/index.ts index 7c2183e84a6..b69e7f6790e 100644 --- a/packages/core/src/fields/types/checkbox/index.ts +++ b/packages/core/src/fields/types/checkbox/index.ts @@ -19,12 +19,11 @@ export type CheckboxFieldConfig = } } -export const checkbox = - ({ - defaultValue = false, - ...config - }: CheckboxFieldConfig = {}): FieldTypeFunc => - meta => { +export function checkbox ({ + defaultValue = false, + ...config +}: CheckboxFieldConfig = {}): FieldTypeFunc { + return meta => { if ((config as any).isIndexed === 'unique') { throw Error("isIndexed: 'unique' is not a supported option for field type checkbox") } @@ -48,28 +47,23 @@ export const checkbox = defaultValue: typeof defaultValue === 'boolean' ? defaultValue : undefined, }), resolve (val) { - if (val === null) { - throw userInputError('Checkbox fields cannot be set to null') - } + if (val === null) throw userInputError('Checkbox fields cannot be set to null') return val ?? defaultValue }, }, update: { arg: graphql.arg({ type: graphql.Boolean }), resolve (val) { - if (val === null) { - throw userInputError('Checkbox fields cannot be set to null') - } + if (val === null) throw userInputError('Checkbox fields cannot be set to null') return val }, }, orderBy: { arg: graphql.arg({ type: orderDirectionEnum }) }, }, - output: graphql.field({ - type: graphql.Boolean, - }), + output: graphql.field({ type: graphql.Boolean, }), __ksTelemetryFieldTypeName: '@keystone-6/checkbox', views: '@keystone-6/core/fields/types/checkbox/views', getAdminMeta: () => ({ defaultValue }), }) } +} diff --git a/packages/core/src/fields/types/checkbox/views/index.tsx b/packages/core/src/fields/types/checkbox/views/index.tsx index ec5e58318ab..754d1c738fd 100644 --- a/packages/core/src/fields/types/checkbox/views/index.tsx +++ b/packages/core/src/fields/types/checkbox/views/index.tsx @@ -12,7 +12,7 @@ import { } from '../../../../types' import { CellContainer } from '../../../../admin-ui/components' -export const Field = ({ field, value, onChange, autoFocus }: FieldProps) => { +export function Field ({ field, value, onChange, autoFocus }: FieldProps) { const { fields, typography, spacing } = useTheme() return ( diff --git a/packages/core/src/fields/types/decimal/views/index.tsx b/packages/core/src/fields/types/decimal/views/index.tsx index 8ece72b5487..4c3151edebe 100644 --- a/packages/core/src/fields/types/decimal/views/index.tsx +++ b/packages/core/src/fields/types/decimal/views/index.tsx @@ -15,13 +15,13 @@ import { import { CellLink, CellContainer } from '../../../../admin-ui/components' import { useFormattedInput } from '../../integer/views/utils' -export const Field = ({ +export function Field ({ field, value, onChange, autoFocus, forceValidation, -}: FieldProps) => { +}: FieldProps) { const [hasBlurred, setHasBlurred] = useState(false) const inputProps = useFormattedInput( { @@ -113,7 +113,6 @@ type Validation = { } type InnerValue = string | Decimal | null - type Value = | { kind: 'create' diff --git a/packages/core/src/fields/types/file/index.ts b/packages/core/src/fields/types/file/index.ts index eb031f115fb..42d0720bb1d 100644 --- a/packages/core/src/fields/types/file/index.ts +++ b/packages/core/src/fields/types/file/index.ts @@ -50,11 +50,8 @@ async function inputResolver ( return context.files(storage).getDataFromStream(upload.createReadStream(), upload.filename) } -export const file = - ( - config: FileFieldConfig - ): FieldTypeFunc => - meta => { +export function file (config: FileFieldConfig): FieldTypeFunc { + return meta => { const storage = meta.getStorage(config.storage) if (!storage) { @@ -122,3 +119,4 @@ export const file = views: '@keystone-6/core/fields/types/file/views', }) } +} diff --git a/packages/core/src/fields/types/image/index.ts b/packages/core/src/fields/types/image/index.ts index 8586fc00ddf..4cd1da59337 100644 --- a/packages/core/src/fields/types/image/index.ts +++ b/packages/core/src/fields/types/image/index.ts @@ -67,11 +67,8 @@ function isValidImageExtension (extension: string): extension is ImageExtension return extensionsSet.has(extension) } -export const image = - ( - config: ImageFieldConfig - ): FieldTypeFunc => - meta => { +export function image (config: ImageFieldConfig): FieldTypeFunc { + return meta => { const storage = meta.getStorage(config.storage) if (!storage) { @@ -160,3 +157,4 @@ export const image = views: '@keystone-6/core/fields/types/image/views', }) } +} diff --git a/packages/core/src/fields/types/integer/index.ts b/packages/core/src/fields/types/integer/index.ts index f413ed27e8c..a9b6c649ec2 100644 --- a/packages/core/src/fields/types/integer/index.ts +++ b/packages/core/src/fields/types/integer/index.ts @@ -30,14 +30,13 @@ export type IntegerFieldConfig = const MAX_INT = 2147483647 const MIN_INT = -2147483648 -export const integer = - ({ - isIndexed, - defaultValue: _defaultValue, - validation, - ...config - }: IntegerFieldConfig = {}): FieldTypeFunc => - meta => { +export function integer ({ + isIndexed, + defaultValue: _defaultValue, + validation, + ...config +}: IntegerFieldConfig = {}): FieldTypeFunc { + return meta => { const defaultValue = _defaultValue ?? null const hasAutoIncDefault = typeof defaultValue == 'object' && @@ -96,7 +95,6 @@ export const integer = assertReadIsNonNullAllowed(meta, config, isNullable) const mode = isNullable === false ? 'required' : 'optional' - const fieldLabel = config.label ?? humanize(meta.fieldKey) return fieldType({ @@ -122,8 +120,7 @@ export const integer = if ( (validation?.isRequired || isNullable === false) && - (value === null || - (args.operation === 'create' && value === undefined && !hasAutoIncDefault)) + (value === null || (args.operation === 'create' && value === undefined && !hasAutoIncDefault)) ) { args.addValidationError(`${fieldLabel} is required`) } @@ -145,8 +142,7 @@ export const integer = }, }, input: { - uniqueWhere: - isIndexed === 'unique' ? { arg: graphql.arg({ type: graphql.Int }) } : undefined, + uniqueWhere: isIndexed === 'unique' ? { arg: graphql.arg({ type: graphql.Int }) } : undefined, where: { arg: graphql.arg({ type: filters[meta.provider].Int[mode] }), resolve: mode === 'optional' ? filters.resolveCommon : undefined, @@ -166,9 +162,7 @@ export const integer = update: { arg: graphql.arg({ type: graphql.Int }) }, orderBy: { arg: graphql.arg({ type: orderDirectionEnum }) }, }, - output: graphql.field({ - type: graphql.Int, - }), + output: graphql.field({ type: graphql.Int, }), __ksTelemetryFieldTypeName: '@keystone-6/integer', views: '@keystone-6/core/fields/types/integer/views', getAdminMeta () { @@ -186,3 +180,4 @@ export const integer = }, }) } +} diff --git a/packages/core/src/fields/types/password/views/index.tsx b/packages/core/src/fields/types/password/views/index.tsx index a333baf955b..cfde4fed694 100644 --- a/packages/core/src/fields/types/password/views/index.tsx +++ b/packages/core/src/fields/types/password/views/index.tsx @@ -56,13 +56,13 @@ function isSetText (isSet: null | undefined | boolean) { return isSet == null ? 'Access Denied' : isSet ? 'Is set' : 'Is not set' } -export const Field = ({ +export function Field ({ field, value, onChange, forceValidation, autoFocus, -}: FieldProps) => { +}: FieldProps) { const [showInputValue, setShowInputValue] = useState(false) const [touchedFirstInput, setTouchedFirstInput] = useState(false) const [touchedSecondInput, setTouchedSecondInput] = useState(false) diff --git a/packages/core/src/fields/types/text/views/index.tsx b/packages/core/src/fields/types/text/views/index.tsx index 79390cf2fee..f79e291dbc1 100644 --- a/packages/core/src/fields/types/text/views/index.tsx +++ b/packages/core/src/fields/types/text/views/index.tsx @@ -19,13 +19,13 @@ import { } from '../../../../types' import { CellContainer, CellLink } from '../../../../admin-ui/components' -export const Field = ({ +export function Field ({ field, value, onChange, autoFocus, forceValidation, -}: FieldProps) => { +}: FieldProps) { const { typography, fields } = useTheme() const [shouldShowErrors, setShouldShowErrors] = useState(false) const validationMessages = validate(value, field.validation, field.label) @@ -39,9 +39,15 @@ export const Field = ({