Skip to content

Commit

Permalink
rename KeystoneConfig to KeystonePreConfig
Browse files Browse the repository at this point in the history
  • Loading branch information
dcousens committed Jan 20, 2025
1 parent 59ef9bf commit 4b4f49f
Show file tree
Hide file tree
Showing 35 changed files with 127 additions and 126 deletions.
2 changes: 1 addition & 1 deletion examples/custom-output-paths/my-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ export declare namespace Lists {
}
}
export type Context<Session = any> = import('@keystone-6/core/types').KeystoneContext<TypeInfo<Session>>
export type Config<Session = any> = import('@keystone-6/core/types').ResolvedKeystoneConfig<TypeInfo<Session>>
export type Config<Session = any> = import('@keystone-6/core/types').KeystoneConfig<TypeInfo<Session>>

export type TypeInfo<Session = any> = {
lists: {
Expand Down
9 changes: 6 additions & 3 deletions examples/custom-session-invalidation/keystone.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import { config } from '@keystone-6/core'
import { statelessSessions } from '@keystone-6/core/session'
import { createAuth } from '@keystone-6/auth'
import { lists, type Session } from './schema'
import {
type Session,
lists,
} from './schema'
import type { Config, Context, TypeInfo } from '.keystone/types'

// WARNING: this example is for demonstration purposes only
Expand Down Expand Up @@ -32,13 +35,13 @@ const { withAuth } = createAuth({
sessionData: 'passwordChangedAt',
})

function withSessionInvalidation (config: Config<Session>) {
function withSessionInvalidation (config: Config<Session>): Config<Session> {
const existingSessionStrategy = config.session!

return {
...config,
session: {
...config.session,
...existingSessionStrategy,
async get ({ context }: { context: Context }): Promise<Session | undefined> {
const session = await existingSessionStrategy.get({ context })
if (!session) return
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { config } from '@keystone-6/core'
import type { KeystoneConfig } from '@keystone-6/core/types'
import type { KeystoneConfigPre } from '@keystone-6/core/types'
import { seedDatabase } from './src/seed'
import { lists } from './src/schema'
import { type Context, type TypeInfo } from '.keystone/types'
import type { Context, TypeInfo } from '.keystone/types'

const db: KeystoneConfig<TypeInfo>['db'] = {
const db: KeystoneConfigPre<TypeInfo>['db'] = {
provider: 'sqlite',
url: process.env.DATABASE_URL || 'file:./database.db',
async onConnect (context: Context) {
Expand Down
2 changes: 1 addition & 1 deletion examples/extend-graphql-schema-nexus/keystone-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ export declare namespace Lists {
}
}
export type Context<Session = any> = import('@keystone-6/core/types').KeystoneContext<TypeInfo<Session>>
export type Config<Session = any> = import('@keystone-6/core/types').ResolvedKeystoneConfig<TypeInfo<Session>>
export type Config<Session = any> = import('@keystone-6/core/types').KeystoneConfig<TypeInfo<Session>>

export type TypeInfo<Session = any> = {
lists: {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { config } from '@keystone-6/core'
import type { KeystoneConfig } from '@keystone-6/core/types'
import type { KeystoneConfigPre } from '@keystone-6/core/types'
import { seedDatabase } from './src/seed'
import { lists } from './src/schema'
import type { Context, TypeInfo } from '.keystone/types'

const db: KeystoneConfig<TypeInfo>['db'] = {
const db: KeystoneConfigPre<TypeInfo>['db'] = {
provider: 'sqlite',
url: process.env.DATABASE_URL || 'file:./database.db',
async onConnect (context: Context) {
Expand Down
8 changes: 4 additions & 4 deletions packages/auth/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import type {
KeystoneContext,
SessionStrategy,
BaseKeystoneTypeInfo,
ResolvedKeystoneConfig,
KeystoneConfig,
} from '@keystone-6/core/types'
import { password, timestamp } from '@keystone-6/core/fields'

Expand Down Expand Up @@ -134,7 +134,7 @@ export function createAuth<ListTypeInfo extends BaseListTypeInfo> ({
})

function throwIfInvalidConfig<TypeInfo extends BaseKeystoneTypeInfo> (
config: ResolvedKeystoneConfig<TypeInfo>
config: KeystoneConfig<TypeInfo>
) {
if (!(listKey in config.lists)) {
throw new Error(`withAuth cannot find the list "${listKey}"`)
Expand Down Expand Up @@ -247,8 +247,8 @@ export function createAuth<ListTypeInfo extends BaseListTypeInfo> ({
* Automatically extends your configuration with a prescriptive implementation.
*/
function withAuth<TypeInfo extends BaseKeystoneTypeInfo> (
config: ResolvedKeystoneConfig<TypeInfo>
): ResolvedKeystoneConfig<TypeInfo> {
config: KeystoneConfig<TypeInfo>
): KeystoneConfig<TypeInfo> {
throwIfInvalidConfig(config)
let { ui } = config
if (!ui?.isDisabled) {
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/admin-ui/system/generateAdminUI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import type { GraphQLSchema } from 'graphql'
import { type Entry, walk as _walk } from '@nodelib/fs.walk'
import type {
AdminFileToWrite,
ResolvedKeystoneConfig
KeystoneConfig
} from '../../types'
import { writeAdminFiles } from '../templates'
import type { AdminMetaRootVal } from '../../lib/create-admin-meta'
Expand Down Expand Up @@ -66,7 +66,7 @@ export async function writeAdminFile (file: AdminFileToWrite, projectAdminPath:
const pageExtensions = new Set(['.js', '.jsx', '.ts', '.tsx'])

export async function generateAdminUI (
config: ResolvedKeystoneConfig,
config: KeystoneConfig,
graphQLSchema: GraphQLSchema,
adminMeta: AdminMetaRootVal,
projectAdminPath: string,
Expand Down
8 changes: 4 additions & 4 deletions packages/core/src/admin-ui/templates/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as Path from 'path'
import { type GraphQLSchema } from 'graphql'
import { type ResolvedKeystoneConfig } from '../../types'
import { type AdminMetaRootVal } from '../../lib/create-admin-meta'
import type { GraphQLSchema } from 'graphql'
import type { KeystoneConfig } from '../../types'
import type { AdminMetaRootVal } from '../../lib/create-admin-meta'
import { appTemplate } from './app'
import { homeTemplate } from './home'
import { listTemplate } from './list'
Expand All @@ -13,7 +13,7 @@ import { nextConfigTemplate } from './next-config'
const pkgDir = Path.dirname(require.resolve('@keystone-6/core/package.json'))

export function writeAdminFiles (
config: ResolvedKeystoneConfig,
config: KeystoneConfig,
graphQLSchema: GraphQLSchema,
adminMeta: AdminMetaRootVal,
configFileExists: boolean
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/admin-ui/templates/no-access.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { ResolvedKeystoneConfig } from '../../types'
import type { KeystoneConfig } from '../../types'

export const noAccessTemplate = (session: ResolvedKeystoneConfig['session']) =>
export const noAccessTemplate = (session: KeystoneConfig['session']) =>
`import { getNoAccessPage } from '@keystone-6/core/___internal-do-not-use-will-break-in-patch/admin-ui/pages/NoAccessPage';
export default getNoAccessPage(${JSON.stringify({ sessionsEnabled: !!session })})
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/context.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import type {
BaseKeystoneTypeInfo,
ResolvedKeystoneConfig,
KeystoneConfig,
KeystoneContext
} from './types'
import { createSystem } from './lib/createSystem'

export function getContext<TypeInfo extends BaseKeystoneTypeInfo> (
config: ResolvedKeystoneConfig<TypeInfo>,
config: KeystoneConfig<TypeInfo>,
PrismaModule: unknown
): KeystoneContext<TypeInfo> {
const system = createSystem(config)
Expand Down
8 changes: 4 additions & 4 deletions packages/core/src/lib/assets/createFilesContext.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { randomBytes } from 'node:crypto'

import {
type FilesContext,
type ResolvedKeystoneConfig,
import type {
FilesContext,
KeystoneConfig,
} from '../../types'
import { localFileAssetsAPI } from './local'
import { s3FileAssetsAPI } from './s3'
Expand All @@ -21,7 +21,7 @@ function defaultTransformName (path: string) {
return `${urlSafeName}-${id}`
}

export function createFilesContext (config: ResolvedKeystoneConfig): FilesContext {
export function createFilesContext (config: KeystoneConfig): FilesContext {
const adaptersMap = new Map<string, FileAdapter>()

for (const [storageKey, storageConfig] of Object.entries(config.storage || {})) {
Expand Down
8 changes: 4 additions & 4 deletions packages/core/src/lib/assets/createImagesContext.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { randomBytes } from 'node:crypto'
import imageSize from 'image-size'

import {
type ImagesContext,
type ResolvedKeystoneConfig,
import type {
ImagesContext,
KeystoneConfig,
} from '../../types'
import type { ImageAdapter } from './types'
import { localImageAssetsAPI } from './local'
Expand Down Expand Up @@ -33,7 +33,7 @@ async function getImageMetadataFromBuffer (buffer: Buffer) {
return { width, height, filesize: buffer.length, extension }
}

export function createImagesContext (config: ResolvedKeystoneConfig): ImagesContext {
export function createImagesContext (config: KeystoneConfig): ImagesContext {
const imageAssetsAPIs = new Map<string, ImageAdapter>()
for (const [storageKey, storageConfig] of Object.entries(config.storage || {})) {
if (storageConfig.type === 'image') {
Expand Down
16 changes: 8 additions & 8 deletions packages/core/src/lib/context/createContext.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import {
type IncomingMessage,
type ServerResponse
import type {
IncomingMessage,
ServerResponse
} from 'http'
import {
type ExecutionResult,
type GraphQLSchema,
graphql,
print
} from 'graphql'
import {
type KeystoneContext,
type KeystoneGraphQLAPI,
type ResolvedKeystoneConfig,
import type {
KeystoneContext,
KeystoneGraphQLAPI,
KeystoneConfig,
} from '../../types'

import { type InitialisedList } from '../core/initialise-lists'
Expand All @@ -27,7 +27,7 @@ export function createContext ({
prismaClient,
prismaTypes
}: {
config: ResolvedKeystoneConfig
config: KeystoneConfig
lists: Record<string, InitialisedList>
graphQLSchema: GraphQLSchema
graphQLSchemaSudo: GraphQLSchema
Expand Down
32 changes: 16 additions & 16 deletions packages/core/src/lib/core/initialise-lists.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
import type { CacheHint } from '@apollo/cache-control-types'
import { GraphQLString, isInputObjectType } from 'graphql'
import {
type BaseItem,
type BaseListTypeInfo,
type CacheHintArgs,
type FindManyArgs,
type GraphQLTypesForList,
type ListGraphQLTypes,
type ListHooks,
type ResolvedKeystoneConfig,
type MaybePromise,
type NextFieldType,
type FieldTypeFunc,
QueryMode
import type {
BaseItem,
BaseListTypeInfo,
CacheHintArgs,
FindManyArgs,
GraphQLTypesForList,
ListGraphQLTypes,
ListHooks,
KeystoneConfig,
MaybePromise,
NextFieldType,
FieldTypeFunc,
} from '../../types'
import { QueryMode } from '../../types'
import {
type GraphQLNames,
__getNames,
Expand Down Expand Up @@ -153,7 +153,7 @@ function throwIfNotAFilter (x: unknown, listKey: string, fieldKey: string) {
throw new Error(`Configuration option '${listKey}.${fieldKey}' must be either a boolean value or a function. Received '${x}'.`)
}

type ListConfigType = ResolvedKeystoneConfig['lists'][string]
type ListConfigType = KeystoneConfig['lists'][string]
type FieldConfigType = ReturnType<FieldTypeFunc<any>>
type PartiallyInitialisedList1 = { graphql: { isEnabled: IsListEnabled } }
type PartiallyInitialisedList2 = Omit<InitialisedList, 'lists' | 'resolvedDbFields'>
Expand Down Expand Up @@ -374,7 +374,7 @@ function parseFieldHooks (
}

function getListsWithInitialisedFields (
config: ResolvedKeystoneConfig,
config: KeystoneConfig,
listsRef: Record<string, InitialisedList>,
) {
const { storage: configStorage, lists: listsConfig, db: { provider } } = config
Expand Down Expand Up @@ -874,7 +874,7 @@ function graphqlForOutputField (field: InitialisedField) {
})
}

export function initialiseLists (config: ResolvedKeystoneConfig): Record<string, InitialisedList> {
export function initialiseLists (config: KeystoneConfig): Record<string, InitialisedList> {
const listsRef: Record<string, InitialisedList> = {}
let intermediateLists

Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/lib/core/prisma-schema-printer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import type {
} from '../../types'
import type { ResolvedDBField } from './resolve-relationships'
import type { InitialisedList } from './initialise-lists'
import type { ResolvedKeystoneConfig } from '../../types'
import type { KeystoneConfig } from '../../types'
import { areArraysEqual, getDBFieldKeyForFieldOnMultiField } from './utils'

const modifiers = {
Expand Down Expand Up @@ -181,7 +181,7 @@ function assertDbFieldIsValidForIdField (
}

export function printPrismaSchema (
config: ResolvedKeystoneConfig,
config: KeystoneConfig,
lists: Record<string, InitialisedList>,
) {
const {
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/lib/create-admin-meta.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import type {
MaybeItemFunction,
MaybePromise,
MaybeSessionFunction,
ResolvedKeystoneConfig,
KeystoneConfig,
} from '../types'
import type {
GraphQLNames
Expand Down Expand Up @@ -86,7 +86,7 @@ export type AdminMetaRootVal = {
}

export function createAdminMeta (
config: ResolvedKeystoneConfig,
config: KeystoneConfig,
initialisedLists: Record<string, InitialisedList>
) {
const { lists } = config
Expand Down
8 changes: 4 additions & 4 deletions packages/core/src/lib/createAdminUIMiddleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@ import url from 'url'
import path from 'path'
import type express from 'express'
import type next from 'next'
import {
type KeystoneContext,
type ResolvedKeystoneConfig,
import type {
KeystoneContext,
KeystoneConfig,
} from '../types'
import { pkgDir } from '../pkg-dir'

const adminErrorHTMLFilepath = path.join(pkgDir, 'static', 'admin-error.html')

export function createAdminUIMiddlewareWithNextApp (
config: ResolvedKeystoneConfig,
config: KeystoneConfig,
commonContext: KeystoneContext,
nextApp: ReturnType<typeof next>
) {
Expand Down
6 changes: 3 additions & 3 deletions packages/core/src/lib/createExpressServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { ApolloServerPluginLandingPageLocalDefault } from '@apollo/server/plugin
import graphqlUploadExpress from 'graphql-upload/graphqlUploadExpress.js'
import type {
KeystoneContext,
ResolvedKeystoneConfig,
KeystoneConfig,
} from '../types'

/*
Expand All @@ -28,7 +28,7 @@ The Admin UI takes a while to build for dev, and is created separately
so the CLI can bring up the dev server early to handle GraphQL requests.
*/

function formatError (graphqlConfig: ResolvedKeystoneConfig['graphql']) {
function formatError (graphqlConfig: KeystoneConfig['graphql']) {
return (formattedError: GraphQLFormattedError, error: unknown) => {
let debug = graphqlConfig.debug
if (debug === undefined) {
Expand All @@ -50,7 +50,7 @@ function formatError (graphqlConfig: ResolvedKeystoneConfig['graphql']) {
}

export async function createExpressServer (
config: Pick<ResolvedKeystoneConfig, 'graphql' | 'server' | 'storage'>,
config: Pick<KeystoneConfig, 'graphql' | 'server' | 'storage'>,
context: KeystoneContext
): Promise<{
expressServer: express.Express
Expand Down
Loading

0 comments on commit 4b4f49f

Please sign in to comment.