Skip to content

Commit

Permalink
Remove deprecated @keystone-6/core/system exports
Browse files Browse the repository at this point in the history
  • Loading branch information
dcousens committed Apr 8, 2024
1 parent 4e501cd commit ed4d4f7
Show file tree
Hide file tree
Showing 34 changed files with 576 additions and 22,021 deletions.
5 changes: 5 additions & 0 deletions .changeset/no-system-export.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@keystone-6/core': major
---

Removes `@keystone-6/core/system` from exports
1 change: 0 additions & 1 deletion examples/custom-output-paths/my-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,6 @@ type ResolvedPostCreateInput = {
content?: import('./node_modules/.myprisma/client').Prisma.PostCreateInput['content']
publishDate?: import('./node_modules/.myprisma/client').Prisma.PostCreateInput['publishDate']
}

type ResolvedPostUpdateInput = {
id?: undefined
title?: import('./node_modules/.myprisma/client').Prisma.PostUpdateInput['title']
Expand Down
3 changes: 0 additions & 3 deletions examples/extend-graphql-schema-nexus/keystone-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,6 @@ type ResolvedPostCreateInput = {
publishDate?: import('./node_modules/.myprisma/client').Prisma.PostCreateInput['publishDate']
author?: import('./node_modules/.myprisma/client').Prisma.PostCreateInput['author']
}

type ResolvedPostUpdateInput = {
id?: undefined
title?: import('./node_modules/.myprisma/client').Prisma.PostUpdateInput['title']
Expand All @@ -229,13 +228,11 @@ type ResolvedPostUpdateInput = {
publishDate?: import('./node_modules/.myprisma/client').Prisma.PostUpdateInput['publishDate']
author?: import('./node_modules/.myprisma/client').Prisma.PostUpdateInput['author']
}

type ResolvedAuthorCreateInput = {
id?: import('./node_modules/.myprisma/client').Prisma.AuthorCreateInput['id']
name?: import('./node_modules/.myprisma/client').Prisma.AuthorCreateInput['name']
posts?: import('./node_modules/.myprisma/client').Prisma.AuthorCreateInput['posts']
}

type ResolvedAuthorUpdateInput = {
id?: undefined
name?: import('./node_modules/.myprisma/client').Prisma.AuthorUpdateInput['name']
Expand Down
5 changes: 0 additions & 5 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,6 @@
"module": "./access/dist/keystone-6-core-access.esm.js",
"default": "./access/dist/keystone-6-core-access.cjs.js"
},
"./system": {
"module": "./system/dist/keystone-6-core-system.esm.js",
"default": "./system/dist/keystone-6-core-system.cjs.js"
},
"./context": {
"module": "./context/dist/keystone-6-core-context.esm.js",
"default": "./context/dist/keystone-6-core-context.cjs.js"
Expand Down Expand Up @@ -265,7 +261,6 @@
"entrypoints": [
"index.ts",
"access.ts",
"system.ts",
"___internal-do-not-use-will-break-in-patch/artifacts.ts",
"___internal-do-not-use-will-break-in-patch/admin-ui/pages/*/index.tsx",
"___internal-do-not-use-will-break-in-patch/admin-ui/id-field-view.tsx",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
export {
validatePrismaAndGraphQLSchemas,
generateTypescriptTypesAndPrisma,
generatePrismaAndGraphQLSchemas,
createExpressServer,
} from '../lib/createExpressServer'
export {
createSystem,
} from '../lib/createSystem'
export {
pushPrismaSchemaToDatabase,
} from '../lib/migrations'
export {
getCommittedArtifacts,
validatePrismaAndGraphQLSchemas,
} from '../artifacts'
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,
type KeystoneConfig
type __ResolvedKeystoneConfig
} 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: KeystoneConfig,
config: __ResolvedKeystoneConfig,
graphQLSchema: GraphQLSchema,
adminMeta: AdminMetaRootVal,
projectAdminPath: string,
Expand Down
7 changes: 5 additions & 2 deletions packages/core/src/admin-ui/templates/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import * as Path from 'path'
import type { GraphQLSchema } from 'graphql'
import type { KeystoneConfig, AdminFileToWrite } from '../../types'
import {
type AdminFileToWrite,
type __ResolvedKeystoneConfig
} from '../../types'
import type { AdminMetaRootVal } from '../../lib/create-admin-meta'
import { appTemplate } from './app'
import { homeTemplate } from './home'
Expand All @@ -13,7 +16,7 @@ import { nextConfigTemplate } from './next-config'
const pkgDir = Path.dirname(require.resolve('@keystone-6/core/package.json'))

export const writeAdminFiles = (
config: KeystoneConfig,
config: __ResolvedKeystoneConfig,
graphQLSchema: GraphQLSchema,
adminMeta: AdminMetaRootVal,
configFileExists: boolean
Expand Down
59 changes: 9 additions & 50 deletions packages/core/src/artifacts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ import path from 'node:path'
import { createRequire } from 'node:module'
import { printSchema, GraphQLSchema } from 'graphql'
import { getGenerators, formatSchema } from '@prisma/internals'
import type { KeystoneConfig } from './types'
import { printGeneratedTypes } from './lib/typescript-schema-printer'
import { ExitError } from './scripts/utils'
import {
type KeystoneConfig,
type __ResolvedKeystoneConfig
} from './types'
import { initialiseLists } from './lib/core/initialise-lists'
import { printPrismaSchema } from './lib/core/prisma-schema-printer'
import { initConfig } from './system'

export function getFormattedGraphQLSchema (schema: string) {
return (
Expand All @@ -19,7 +20,7 @@ export function getFormattedGraphQLSchema (schema: string) {
)
}

export async function getCommittedArtifacts (config: KeystoneConfig, graphQLSchema: GraphQLSchema) {
export async function getCommittedArtifacts (config: __ResolvedKeystoneConfig, graphQLSchema: GraphQLSchema) {
const lists = initialiseLists(config)
const prismaSchema = printPrismaSchema(config, lists)
return {
Expand Down Expand Up @@ -71,14 +72,14 @@ export function getBuiltKeystoneConfigurationPath (cwd: string) {
}

export function getBuiltKeystoneConfiguration (cwd: string) {
return initConfig(require(getBuiltKeystoneConfigurationPath(cwd)).default)
return require(getBuiltKeystoneConfigurationPath(cwd)).default
}

function posixify (s: string) {
return s.split(path.sep).join('/')
}

export function getSystemPaths (cwd: string, config: KeystoneConfig) {
export function getSystemPaths (cwd: string, config: KeystoneConfig | __ResolvedKeystoneConfig) {
const prismaClientPath = config.db.prismaClientPath === '@prisma/client'
? null
: config.db.prismaClientPath
Expand Down Expand Up @@ -118,7 +119,7 @@ export function getSystemPaths (cwd: string, config: KeystoneConfig) {

export async function validatePrismaAndGraphQLSchemas (
cwd: string,
config: KeystoneConfig,
config: __ResolvedKeystoneConfig,
graphQLSchema: GraphQLSchema
) {
const paths = getSystemPaths(cwd, config)
Expand Down Expand Up @@ -150,49 +151,7 @@ export async function validatePrismaAndGraphQLSchemas (
throw new ExitError(1)
}

export async function generatePrismaAndGraphQLSchemas (
cwd: string,
config: KeystoneConfig,
graphQLSchema: GraphQLSchema
) {
const paths = getSystemPaths(cwd, config)
const artifacts = await getCommittedArtifacts(config, graphQLSchema)

await fs.writeFile(paths.schema.graphql, artifacts.graphql)
await fs.writeFile(paths.schema.prisma, artifacts.prisma)
return artifacts
}

export async function generateTypescriptTypes (
cwd: string,
config: KeystoneConfig,
graphQLSchema: GraphQLSchema
) {
const lists = initialiseLists(config)
const paths = getSystemPaths(cwd, config)
const schema = printGeneratedTypes(paths.types.relativePrismaPath, graphQLSchema, lists)

await fs.mkdir(path.dirname(paths.schema.types), { recursive: true })
await fs.writeFile(paths.schema.types, schema)
}

export async function generateTypescriptTypesAndPrisma (
cwd: string,
config: KeystoneConfig,
graphQLSchema: GraphQLSchema
) {
const paths = getSystemPaths(cwd, config)
const dataProxy = config.db.url.startsWith('prisma:')
if (dataProxy === true) {
console.log('✨ Generating Prisma Client (data proxy)')
}
await Promise.all([
generatePrismaClient(paths.schema.prisma, dataProxy),
generateTypescriptTypes(cwd, config, graphQLSchema),
])
}

async function generatePrismaClient (prismaSchemaPath: string, dataProxy: boolean) {
export async function generatePrismaClient (prismaSchemaPath: string, dataProxy: boolean) {
const generators = await getGenerators({
schemaPath: prismaSchemaPath,
dataProxy,
Expand Down
3 changes: 1 addition & 2 deletions packages/core/src/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@ import {
type KeystoneConfig,
type KeystoneContext
} from './types'
import { initConfig } from './system'
import { createSystem } from './lib/createSystem'

export function getContext<TypeInfo extends BaseKeystoneTypeInfo> (
config: KeystoneConfig<TypeInfo>,
PrismaModule: unknown
): KeystoneContext<TypeInfo> {
const system = createSystem(initConfig(config))
const system = createSystem(config)
const { context } = system.getKeystone(PrismaModule)
return context
}
7 changes: 5 additions & 2 deletions packages/core/src/lib/assets/createFilesContext.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { randomBytes } from 'node:crypto'

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

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

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

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

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

import { type InitialisedList } from '../core/initialise-lists'
Expand All @@ -27,7 +27,7 @@ export function createContext ({
prismaClient,
prismaTypes
}: {
config: KeystoneConfig
config: __ResolvedKeystoneConfig
lists: Record<string, InitialisedList>
graphQLSchema: GraphQLSchema
graphQLSchemaSudo: GraphQLSchema
Expand Down
10 changes: 5 additions & 5 deletions packages/core/src/lib/core/initialise-lists.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
type GraphQLTypesForList,
type ListGraphQLTypes,
type ListHooks,
type KeystoneConfig,
type __ResolvedKeystoneConfig,
type MaybePromise,
type NextFieldType,
type FieldTypeFunc,
Expand Down Expand Up @@ -143,7 +143,7 @@ function throwIfNotAFilter (x: unknown, listKey: string, fieldKey: string) {
)
}

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

function getListsWithInitialisedFields (
{ storage: configStorage, lists: listsConfig, db: { provider } }: KeystoneConfig,
{ storage: configStorage, lists: listsConfig, db: { provider } }: __ResolvedKeystoneConfig,
listGraphqlTypes: Record<string, ListGraphQLTypes>,
intermediateLists: Record<string, PartiallyInitialisedList1>
) {
Expand Down Expand Up @@ -569,7 +569,7 @@ function graphqlForOutputField (field: InitialisedField) {
}

function getListGraphqlTypes (
listsConfig: KeystoneConfig['lists'],
listsConfig: __ResolvedKeystoneConfig['lists'],
lists: Record<string, InitialisedList>,
intermediateLists: Record<string, { graphql: { isEnabled: IsEnabled } }>
): Record<string, ListGraphQLTypes> {
Expand Down Expand Up @@ -834,7 +834,7 @@ function getListGraphqlTypes (
* 5. Handle relationships - ensure correct linking between two sides of all relationships (including one-sided relationships)
* 6.
*/
export function initialiseLists (config: KeystoneConfig): Record<string, InitialisedList> {
export function initialiseLists (config: __ResolvedKeystoneConfig): Record<string, InitialisedList> {
const listsConfig = config.lists

let intermediateLists
Expand Down
15 changes: 10 additions & 5 deletions packages/core/src/lib/core/prisma-schema-printer.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
import type { ScalarDBField, ScalarDBFieldDefault } from '../../types'
import type { ResolvedDBField } from './resolve-relationships'
import type { InitialisedList } from './initialise-lists'
import type { KeystoneConfig } from '../../types'
import {
type ScalarDBField,
type ScalarDBFieldDefault
} from '../../types'
import { type ResolvedDBField } from './resolve-relationships'
import { type InitialisedList } from './initialise-lists'
import {
type __ResolvedKeystoneConfig
} from '../../types'
import { areArraysEqual, getDBFieldKeyForFieldOnMultiField } from './utils'

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

export function printPrismaSchema (
config: KeystoneConfig,
config: __ResolvedKeystoneConfig,
lists: Record<string, InitialisedList>,
) {
const {
Expand Down
10 changes: 5 additions & 5 deletions packages/core/src/lib/create-admin-meta.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import path from 'path'
import type {
KeystoneConfig,
MaybePromise,
MaybeSessionFunction,
BaseListTypeInfo,
KeystoneContext,
JSONValue,
KeystoneContext,
MaybeItemFunction,
MaybePromise,
MaybeSessionFunction,
__ResolvedKeystoneConfig,
} from '../types'
import type { FilterOrderArgs } from '../types/config/fields'

Expand Down Expand Up @@ -82,7 +82,7 @@ export type AdminMetaRootVal = {
}

export function createAdminMeta (
config: KeystoneConfig,
config: __ResolvedKeystoneConfig,
initialisedLists: Record<string, InitialisedList>
) {
const { lists } = config
Expand Down
Loading

0 comments on commit ed4d4f7

Please sign in to comment.