Skip to content

Commit

Permalink
Merge branch 'main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
nikelborm committed May 13, 2024
2 parents 0f88a01 + e0006b1 commit 55e148f
Show file tree
Hide file tree
Showing 25 changed files with 297 additions and 263 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/lint-workflow-files.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ jobs:
# see https://github.com/rhysd/actionlint/blob/main/docs/usage.md
- name: Check workflow files
# https://hub.docker.com/r/rhysd/actionlint/tags
uses: docker://rhysd/actionlint:1.6.27
uses: docker://rhysd/actionlint:1.7.0
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@
"staged-git-files": "1.3.0",
"ts-node": "10.9.2",
"ts-toolbelt": "9.6.0",
"tsx": "4.9.3",
"tsx": "4.10.1",
"typescript": "5.4.5",
"zx": "7.2.3"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/bundle-size/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@
"@prisma/adapter-pg-worker": "workspace:*",
"pg": "8.11.5",
"prisma": "workspace:*",
"wrangler": "3.53.1"
"wrangler": "3.55.0"
}
}
20 changes: 11 additions & 9 deletions packages/cli/src/Generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,12 @@ ${bold('Usage')}
${bold('Options')}
-h, --help Display this help message
--schema Custom path to your Prisma schema
--watch Watch the Prisma schema and rerun after a change
--generator Generator to use (may be provided multiple times)
--no-engine Generate a client for use with Accelerate only
-h, --help Display this help message
--schema Custom path to your Prisma schema
--watch Watch the Prisma schema and rerun after a change
--generator Generator to use (may be provided multiple times)
--no-engine Generate a client for use with Accelerate only
--allow-no-models Allow generating a client without models
${bold('Examples')}
Expand Down Expand Up @@ -107,6 +108,7 @@ ${bold('Examples')}
// Only used for checkpoint information
'--postinstall': String,
'--telemetry-information': String,
'--allow-no-models': Boolean,
})

const isPostinstall = process.env.PRISMA_GENERATE_IN_POSTINSTALL
Expand Down Expand Up @@ -152,6 +154,7 @@ ${bold('Examples')}
Boolean(process.env.PRISMA_GENERATE_DATAPROXY) || // legacy, keep for backwards compatibility
Boolean(process.env.PRISMA_GENERATE_ACCELERATE) || // legacy, keep for backwards compatibility
Boolean(process.env.PRISMA_GENERATE_NO_ENGINE),
allowNoModels: Boolean(args['--allow-no-models']),
})

if (!generators || generators.length === 0) {
Expand Down Expand Up @@ -249,10 +252,9 @@ This might lead to unexpected behavior.
Please make sure they have the same version.`
: ''

const tryAccelerateMessage = `Supercharge your Prisma Client with global database caching,
scalable connection pooling and real-time database events.
Explore Prisma Accelerate: ${link('https://pris.ly/cli/-accelerate')}
Explore Prisma Pulse: ${link('https://pris.ly/cli/-pulse')}`
const tryAccelerateMessage = `Deploying your app to serverless or edge functions?
Try Prisma Accelerate for connection pooling and caching.
${link('https://pris.ly/cli/--accelerate')}`

const boxedTryAccelerateMessage = drawBox({
height: tryAccelerateMessage.split('\n').length,
Expand Down
297 changes: 135 additions & 162 deletions packages/cli/src/__tests__/commands/Generate.test.ts

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions packages/client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@
"@prisma/debug": "workspace:*",
"@prisma/driver-adapter-utils": "workspace:*",
"@prisma/engines": "workspace:*",
"@prisma/engines-version": "5.14.0-21.6eec1600785bbff7acedfa57bc6826cdac2ee9ff",
"@prisma/engines-version": "5.14.0-25.e9771e62de70f79a5e1c604a2d7c8e2a0a874b48",
"@prisma/fetch-engine": "workspace:*",
"@prisma/generator-helper": "workspace:*",
"@prisma/get-platform": "workspace:*",
Expand All @@ -192,7 +192,7 @@
"@prisma/migrate": "workspace:*",
"@prisma/mini-proxy": "0.9.5",
"@prisma/pg-worker": "workspace:*",
"@prisma/query-engine-wasm": "5.14.0-21.6eec1600785bbff7acedfa57bc6826cdac2ee9ff",
"@prisma/query-engine-wasm": "5.14.0-25.e9771e62de70f79a5e1c604a2d7c8e2a0a874b48",
"@snaplet/copycat": "0.17.3",
"@swc-node/register": "1.9.1",
"@swc/core": "1.5.3",
Expand Down Expand Up @@ -250,7 +250,7 @@
"tsd": "0.31.0",
"typescript": "5.4.5",
"undici": "5.28.4",
"wrangler": "3.53.1",
"wrangler": "3.55.0",
"zx": "7.2.3"
},
"peerDependencies": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ describe('can-not-connect-to-database', () => {
13 expect.assertions(1)
14 try {
→ 15 await prisma.user.findUnique(
Can't reach database server at \`localhost\`:\`5444\`
Can't reach database server at \`localhost:5444\`
Please make sure your database server is running at \`localhost\`:\`5444\`.
Please make sure your database server is running at \`localhost:5444\`.
`)
}
})
Expand All @@ -40,9 +40,9 @@ describe('can-not-connect-to-database', () => {
await prisma.$connect()
} catch (err) {
expect(err).toMatchInlineSnapshot(`
Can't reach database server at \`localhost\`:\`5444\`
Can't reach database server at \`localhost:5444\`
Please make sure your database server is running at \`localhost\`:\`5444\`.
Please make sure your database server is running at \`localhost:5444\`.
`)
}
})
Expand Down
15 changes: 13 additions & 2 deletions packages/client/src/generation/TSClient/PrismaClient.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { DataSource, GeneratorConfig } from '@prisma/generator-helper'
import type { DataSource, DMMF, GeneratorConfig } from '@prisma/generator-helper'
import { assertNever } from '@prisma/internals'
import indent from 'indent-string'

Expand Down Expand Up @@ -350,7 +350,18 @@ export class PrismaClientClass implements Generable {
private get jsDoc(): string {
const { dmmf } = this

const example = dmmf.mappings.modelOperations[0]
let example: DMMF.ModelMapping

if (dmmf.mappings.modelOperations.length) {
example = dmmf.mappings.modelOperations[0]
} else {
// because generator models is empty we need to create a fake example
example = {
model: 'User',
plural: 'users',
}
}

return `/**
* ## Prisma Client ʲˢ
*
Expand Down
12 changes: 6 additions & 6 deletions packages/client/src/generation/TSClient/TSClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ ${buildRequirePath(edge)}
/**
* Enums
*/
${this.dmmf.schema.enumTypes.prisma.map((type) => new Enum(type, true).toJS()).join('\n\n')}
${this.dmmf.schema.enumTypes.prisma?.map((type) => new Enum(type, true).toJS()).join('\n\n')}
${this.dmmf.schema.enumTypes.model?.map((type) => new Enum(type, false).toJS()).join('\n\n') ?? ''}
${new Enum(
Expand Down Expand Up @@ -193,7 +193,7 @@ ${buildNFTAnnotations(edge || !copyEngine, clientEngineType, binaryTargets, rela

// TODO: Make this code more efficient and directly return 2 arrays

const prismaEnums = this.dmmf.schema.enumTypes.prisma.map((type) => new Enum(type, true).toTS())
const prismaEnums = this.dmmf.schema.enumTypes.prisma?.map((type) => new Enum(type, true).toTS())

const modelEnums: string[] = []
const modelEnumsAliases: string[] = []
Expand All @@ -210,7 +210,7 @@ ${buildNFTAnnotations(edge || !copyEngine, clientEngineType, binaryTargets, rela
const fieldRefs = this.dmmf.schema.fieldRefTypes.prisma?.map((type) => new FieldRefInput(type).toTS()) ?? []

const countTypes: Count[] = this.dmmf.schema.outputObjectTypes.prisma
.filter((t) => t.name.endsWith('CountOutputType'))
?.filter((t) => t.name.endsWith('CountOutputType'))
.map((t) => new Count(t, context))

const code = `
Expand Down Expand Up @@ -268,7 +268,7 @@ ${modelAndTypes.map((model) => model.toTS()).join('\n')}
* Enums
*/
${prismaEnums.join('\n\n')}
${prismaEnums?.join('\n\n')}
${
fieldRefs.length > 0
? `
Expand All @@ -284,7 +284,7 @@ ${fieldRefs.join('\n\n')}`
*/
${this.dmmf.inputObjectTypes.prisma
.reduce((acc, inputType) => {
?.reduce((acc, inputType) => {
if (inputType.name.includes('Json') && inputType.name.includes('Filter')) {
const needsGeneric = this.genericsInfo.typeNeedsGenericModelArg(inputType)
const innerName = needsGeneric ? `${inputType.name}Base<$PrismaModel>` : `${inputType.name}Base`
Expand Down Expand Up @@ -344,7 +344,7 @@ export const dmmf: runtime.BaseDMMF
* Enums
*/
${this.dmmf.schema.enumTypes.prisma.map((type) => new Enum(type, true).toJS()).join('\n\n')}
${this.dmmf.schema.enumTypes.prisma?.map((type) => new Enum(type, true).toJS()).join('\n\n')}
${this.dmmf.schema.enumTypes.model?.map((type) => new Enum(type, false).toJS()).join('\n\n') ?? ''}
${new Enum(
Expand Down
7 changes: 7 additions & 0 deletions packages/client/src/generation/dmmf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,13 @@ export class DMMFHelper implements DMMF.Document {
}

private buildMergedOutputTypeMap(): NamespacedTypeMap<DMMF.OutputType> {
if (!this.schema.outputObjectTypes.prisma) {
return {
model: keyBy(this.schema.outputObjectTypes.model, 'name'),
prisma: keyBy([], 'name'),
}
}

return {
model: keyBy(this.schema.outputObjectTypes.model, 'name'),
prisma: keyBy(this.schema.outputObjectTypes.prisma, 'name'),
Expand Down
2 changes: 1 addition & 1 deletion packages/engines/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
},
"dependencies": {
"@prisma/debug": "workspace:*",
"@prisma/engines-version": "5.14.0-21.6eec1600785bbff7acedfa57bc6826cdac2ee9ff",
"@prisma/engines-version": "5.14.0-25.e9771e62de70f79a5e1c604a2d7c8e2a0a874b48",
"@prisma/fetch-engine": "workspace:*",
"@prisma/get-platform": "workspace:*"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/fetch-engine/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
},
"dependencies": {
"@prisma/debug": "workspace:*",
"@prisma/engines-version": "5.14.0-21.6eec1600785bbff7acedfa57bc6826cdac2ee9ff",
"@prisma/engines-version": "5.14.0-25.e9771e62de70f79a5e1c604a2d7c8e2a0a874b48",
"@prisma/get-platform": "workspace:*"
},
"scripts": {
Expand Down
1 change: 1 addition & 0 deletions packages/generator-helper/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ export type GeneratorOptions = {
binaryPaths?: BinaryPaths
postinstall?: boolean
noEngine?: boolean
allowNoModels?: boolean
}

export type EngineType = 'queryEngine' | 'libqueryEngine' | 'schemaEngine'
Expand Down
2 changes: 1 addition & 1 deletion packages/internals/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@
"@prisma/fetch-engine": "workspace:*",
"@prisma/generator-helper": "workspace:*",
"@prisma/get-platform": "workspace:*",
"@prisma/prisma-schema-wasm": "5.14.0-21.6eec1600785bbff7acedfa57bc6826cdac2ee9ff",
"@prisma/prisma-schema-wasm": "5.14.0-25.e9771e62de70f79a5e1c604a2d7c8e2a0a874b48",
"@prisma/schema-files-loader": "workspace:*",
"arg": "5.0.2",
"prompts": "2.4.2"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -758,7 +758,7 @@ describe('getGenerators', () => {
test('fail if no model(s) found - mongodb', async () => {
expect.assertions(5)
const aliases = {
'predefined-generator': {
'prisma-client-js': {
generatorPath: generatorPath,
outputPath: __dirname,
},
Expand Down Expand Up @@ -823,4 +823,42 @@ describe('getGenerators', () => {
)
}
})

test('pass if no model(s) found but allow-no-models flag is passed - sqlite', async () => {
expect.assertions(1)

const aliases = {
'predefined-generator': {
generatorPath: generatorPath,
outputPath: __dirname,
},
}

const generators = await getGenerators({
schemaPath: path.join(__dirname, 'missing-models-sqlite-schema.prisma'),
providerAliases: aliases,
allowNoModels: true,
})

return expect(generators.length).toBeGreaterThanOrEqual(1)
})

test('pass if no model(s) found but allow-no-models flag is passed - mongodb', async () => {
expect.assertions(1)

const aliases = {
'prisma-client-js': {
generatorPath: generatorPath,
outputPath: __dirname,
},
}

const generators = await getGenerators({
schemaPath: path.join(__dirname, 'missing-models-mongodb-schema.prisma'),
providerAliases: aliases,
allowNoModels: true,
})

expect(generators.length).toBeGreaterThanOrEqual(1)
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,5 @@ datasource db {

generator gen {
provider = "predefined-generator"
binaryTargets = ["darwin"]
binaryTargets = ["darwin", "darwin-arm64"]
}

10 changes: 5 additions & 5 deletions packages/internals/src/__tests__/schemaEngineCommands.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ describe('canConnectToDatabase', () => {
await expect(canConnectToDatabase('file:./doesnotexist.db')).resolves.toMatchInlineSnapshot(`
{
"code": "P1003",
"message": "Database doesnotexist.db does not exist at ./doesnotexist.db",
"message": "Database \`doesnotexist.db\` does not exist at \`./doesnotexist.db\`.",
}
`)
})
Expand All @@ -48,9 +48,9 @@ describe('canConnectToDatabase', () => {
).resolves.toMatchInlineSnapshot(`
{
"code": "P1001",
"message": "Can't reach database server at \`doesnotexist\`:\`5432\`
"message": "Can't reach database server at \`doesnotexist:5432\`
Please make sure your database server is running at \`doesnotexist\`:\`5432\`.",
Please make sure your database server is running at \`doesnotexist:5432\`.",
}
`)
}, 10_000)
Expand Down Expand Up @@ -94,9 +94,9 @@ describe('createDatabase', () => {
test('postgresql - server does not exist', async () => {
await expect(createDatabase('postgresql://johndoe:randompassword@doesnotexist:5432/mydb?schema=public', __dirname))
.rejects.toThrowErrorMatchingInlineSnapshot(`
"P1001: Can't reach database server at \`doesnotexist\`:\`5432\`
"P1001: Can't reach database server at \`doesnotexist:5432\`
Please make sure your database server is running at \`doesnotexist\`:\`5432\`."
Please make sure your database server is running at \`doesnotexist:5432\`."
`)
}, 30_000)

Expand Down
5 changes: 4 additions & 1 deletion packages/internals/src/get-generators/getGenerators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ export type GetGeneratorOptions = {
generatorNames?: string[]
postinstall?: boolean
noEngine?: boolean
allowNoModels?: boolean
}
/**
* Makes sure that all generators have the binaries they deserve and returns a
Expand All @@ -75,6 +76,7 @@ export async function getGenerators(options: GetGeneratorOptions): Promise<Gener
generatorNames = [],
postinstall,
noEngine,
allowNoModels,
} = options

if (!schemaPath) {
Expand Down Expand Up @@ -139,7 +141,7 @@ export async function getGenerators(options: GetGeneratorOptions): Promise<Gener
previewFeatures,
})

if (dmmf.datamodel.models.length === 0) {
if (dmmf.datamodel.models.length === 0 && !allowNoModels) {
// MongoDB needs extras for @id: @map("_id") @db.ObjectId
if (config.datasources.some((d) => d.provider === 'mongodb')) {
throw new Error(missingModelMessageMongoDB)
Expand Down Expand Up @@ -220,6 +222,7 @@ The generator needs to either define the \`defaultOutput\` path in the manifest
version: version || enginesVersion, // this version makes no sense anymore and should be ignored
postinstall,
noEngine,
allowNoModels,
}

// we set the options here a bit later after instantiating the Generator,
Expand Down
2 changes: 1 addition & 1 deletion packages/migrate/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
},
"dependencies": {
"@prisma/debug": "workspace:*",
"@prisma/engines-version": "5.14.0-21.6eec1600785bbff7acedfa57bc6826cdac2ee9ff",
"@prisma/engines-version": "5.14.0-25.e9771e62de70f79a5e1c604a2d7c8e2a0a874b48",
"@prisma/generator-helper": "workspace:*",
"@prisma/get-platform": "workspace:*",
"@prisma/internals": "workspace:*",
Expand Down

0 comments on commit 55e148f

Please sign in to comment.