-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
chore(client): [DPGA] implement --data-proxy #13484
Changes from 23 commits
62a09ae
b332e65
245e81f
e2db143
a4dacab
4093ab3
c66bda1
4ace46f
47f2002
3954378
b8b50e5
355dc27
7be0448
0376135
de80079
d575b57
3c393c7
bf62a31
77a6e71
5fa27f8
c67fb85
4b0a0b8
5b54c76
7d9db1c
78240b0
01d2823
f530901
ae6f4cc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,7 +9,6 @@ import { | |
getCommandWithExecutor, | ||
getGenerators, | ||
getGeneratorSuccessMessage, | ||
getPlatform, | ||
HelpError, | ||
highlightTS, | ||
isError, | ||
|
@@ -18,7 +17,6 @@ import { | |
logger, | ||
missingGeneratorMessage, | ||
parseEnvValue, | ||
Platform, | ||
} from '@prisma/sdk' | ||
import chalk from 'chalk' | ||
import fs from 'fs' | ||
|
@@ -49,9 +47,10 @@ ${chalk.bold('Usage')} | |
|
||
${chalk.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 | ||
-h, --help Display this help message | ||
--schema Custom path to your Prisma schema | ||
--data-proxy Enable the Data Proxy in the Prisma Client | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. New way to enable |
||
--watch Watch the Prisma schema and rerun after a change | ||
|
||
${chalk.bold('Examples')} | ||
|
||
|
@@ -102,6 +101,7 @@ ${chalk.bold('Examples')} | |
'-h': '--help', | ||
'--watch': Boolean, | ||
'--schema': String, | ||
'--data-proxy': Boolean, | ||
// Only used for checkpoint information | ||
'--postinstall': String, | ||
'--telemetry-information': String, | ||
|
@@ -137,6 +137,7 @@ ${chalk.bold('Examples')} | |
printDownloadProgress: !watchMode, | ||
version: enginesVersion, | ||
cliVersion: pkg.version, | ||
dataProxy: !!args['--data-proxy'], | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Pass the info down to the generators. |
||
}) | ||
|
||
if (!generators || generators.length === 0) { | ||
|
@@ -259,6 +260,7 @@ Please run \`${getCommandWithExecutor('prisma generate')}\` to see the errors.`) | |
printDownloadProgress: !watchMode, | ||
version: enginesVersion, | ||
cliVersion: pkg.version, | ||
dataProxy: !!args['--data-proxy'], | ||
}) | ||
|
||
if (!generatorsWatch || generatorsWatch.length === 0) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,6 @@ datasource db { | |
|
||
generator client { | ||
provider = "prisma-client-js" | ||
engineType = "dataproxy" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not a valid entry anymore. |
||
} | ||
|
||
model Post { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,7 +11,7 @@ function normalizePaths(snapshot: string): string { | |
|
||
describe('library', () => { | ||
it('generates annotations for a schema and a single engine', () => { | ||
const annotations = buildNFTAnnotations(ClientEngineType.Library, ['debian-openssl-1.1.x'], 'out') | ||
const annotations = buildNFTAnnotations(false, ClientEngineType.Library, ['debian-openssl-1.1.x'], 'out') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
expect(normalizePaths(annotations)).toMatchInlineSnapshot(` | ||
|
||
|
@@ -24,6 +24,7 @@ describe('library', () => { | |
|
||
it('generates annotations for a schema and multiple engines', () => { | ||
const annotations = buildNFTAnnotations( | ||
false, | ||
ClientEngineType.Library, | ||
['debian-openssl-1.1.x', 'darwin', 'windows'], | ||
'out', | ||
|
@@ -47,7 +48,7 @@ describe('library', () => { | |
|
||
describe('binary', () => { | ||
it('generates annotations for a schema and a single engine', () => { | ||
const annotations = buildNFTAnnotations(ClientEngineType.Binary, ['debian-openssl-1.1.x'], 'out') | ||
const annotations = buildNFTAnnotations(false, ClientEngineType.Binary, ['debian-openssl-1.1.x'], 'out') | ||
|
||
expect(normalizePaths(annotations)).toMatchInlineSnapshot(` | ||
|
||
|
@@ -60,6 +61,7 @@ describe('binary', () => { | |
|
||
it('generates annotations for a schema and multiple engines', () => { | ||
const annotations = buildNFTAnnotations( | ||
false, | ||
ClientEngineType.Binary, | ||
['debian-openssl-1.1.x', 'darwin', 'windows'], | ||
'out', | ||
|
@@ -84,16 +86,15 @@ describe('binary', () => { | |
describe('dataproxy', () => { | ||
it('generates no annotations', () => { | ||
const annotations = buildNFTAnnotations( | ||
ClientEngineType.DataProxy, | ||
true, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
ClientEngineType.Library, | ||
['debian-openssl-1.1.x', 'darwin', 'windows'], | ||
'out', | ||
) | ||
|
||
// TODO: when using .toMatchInlineSnapshot(), this fails after updating snapshots. | ||
// Probably an issue with the snapshot serializer? | ||
expect(normalizePaths(annotations)).toBe(` | ||
|
||
`) | ||
expect(normalizePaths(annotations)).toBe('') | ||
}) | ||
}) | ||
|
||
|
@@ -106,6 +107,7 @@ describe('special cases', () => { | |
process.env.NETLIFY = 'true' | ||
|
||
const annotations = buildNFTAnnotations( | ||
false, | ||
ClientEngineType.Library, | ||
['debian-openssl-1.1.x', 'darwin', 'windows'], | ||
'out', | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,11 +5,6 @@ import path from 'path' | |
|
||
import { generateTestClient } from '../../../../utils/getTestClient' | ||
|
||
if (getClientEngineType() === ClientEngineType.DataProxy) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not needed. |
||
// eslint-disable-next-line no-global-assign | ||
test = test.skip | ||
} | ||
|
||
test('custom engine binary path (internal API)', async () => { | ||
await generateTestClient() | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,6 +42,7 @@ export interface TSClientOptions { | |
schemaDir: string | ||
outputDir: string | ||
activeProvider: string | ||
dataProxy: boolean | ||
} | ||
|
||
export class TSClient implements Generatable { | ||
|
@@ -62,6 +63,7 @@ export class TSClient implements Generatable { | |
runtimeDir, | ||
runtimeName, | ||
datasources, | ||
dataProxy, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Passed by the generator. |
||
} = this.options | ||
const schemaPath = path.join(schemaDir, 'schema.prisma') | ||
const envPaths = getEnvPaths(schemaPath, { cwd: outputDir }) | ||
|
@@ -86,15 +88,16 @@ export class TSClient implements Generatable { | |
engineVersion: this.options.engineVersion, | ||
datasourceNames: datasources.map((d) => d.name), | ||
activeProvider: this.options.activeProvider, | ||
dataProxy: this.options.dataProxy, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
} | ||
|
||
// get relative output dir for it to be preserved even after bundling, or | ||
// being moved around as long as we keep the same project dir structure. | ||
const relativeOutdir = path.relative(process.cwd(), outputDir) | ||
|
||
const code = `${commonCodeJS({ ...this.options, browser: false })} | ||
${buildRequirePath(engineType)} | ||
${buildDirname(engineType, relativeOutdir, runtimeDir)} | ||
${buildRequirePath(dataProxy)} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We don't use the engine type in most cases anymore as that was used to do the data proxy distinction at generation time. |
||
${buildDirname(dataProxy, relativeOutdir, runtimeDir)} | ||
/** | ||
* Enums | ||
*/ | ||
|
@@ -112,22 +115,22 @@ ${new Enum( | |
}, | ||
true, | ||
).toJS()} | ||
${buildDMMF(engineType, this.dmmfString)} | ||
${buildDMMF(dataProxy, this.dmmfString)} | ||
|
||
/** | ||
* Create the Client | ||
*/ | ||
const config = ${JSON.stringify(config, null, 2)} | ||
config.document = dmmf | ||
config.dirname = dirname | ||
${buildInlineDatasource(engineType, datasources)} | ||
${await buildInlineSchema(engineType, schemaPath)} | ||
${buildInlineEnv(engineType, datasources, envPaths)} | ||
${buildWarnEnvConflicts(engineType, runtimeDir, runtimeName)} | ||
${buildInlineDatasource(dataProxy, datasources)} | ||
${await buildInlineSchema(dataProxy, schemaPath)} | ||
${buildInlineEnv(dataProxy, datasources, envPaths)} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This will be removed in the followup PR. |
||
${buildWarnEnvConflicts(dataProxy, runtimeDir, runtimeName)} | ||
const PrismaClient = getPrismaClient(config) | ||
exports.PrismaClient = PrismaClient | ||
Object.assign(exports, Prisma) | ||
${buildNFTAnnotations(engineType, platforms, relativeOutdir)} | ||
${buildNFTAnnotations(dataProxy, engineType, platforms, relativeOutdir)} | ||
` | ||
return code | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -48,6 +48,7 @@ export interface GenerateClientOptions { | |
engineVersion: string | ||
clientVersion: string | ||
activeProvider: string | ||
dataProxy: boolean | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Passed to |
||
} | ||
|
||
export interface BuildClientResult { | ||
|
@@ -57,7 +58,6 @@ export interface BuildClientResult { | |
|
||
// eslint-disable-next-line @typescript-eslint/require-await | ||
export async function buildClient({ | ||
datamodel, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not used. |
||
schemaDir = process.cwd(), | ||
runtimeDir = '@prisma/client/runtime', | ||
runtimeName = 'index', | ||
|
@@ -70,6 +70,7 @@ export async function buildClient({ | |
clientVersion, | ||
projectRoot, | ||
activeProvider, | ||
dataProxy, | ||
}: GenerateClientOptions): Promise<BuildClientResult> { | ||
const document = getPrismaClientDMMF(dmmf) | ||
const clientEngineType = getClientEngineType(generator!) | ||
|
@@ -90,6 +91,7 @@ export async function buildClient({ | |
engineVersion, | ||
projectRoot: projectRoot!, | ||
activeProvider, | ||
dataProxy, | ||
}) | ||
|
||
const fileMap = { | ||
|
@@ -146,14 +148,15 @@ export async function generateClient({ | |
clientVersion, | ||
engineVersion, | ||
activeProvider, | ||
dataProxy, | ||
}: GenerateClientOptions): Promise<void> { | ||
const useDotPrisma = testMode ? !runtimeDir : !generator?.isCustomOutput | ||
const clientEngineType = getClientEngineType(generator!) | ||
runtimeDir = runtimeDir || (useDotPrisma ? '@prisma/client/runtime' : './runtime') | ||
|
||
// we make sure that we point to the right engine build | ||
if (clientEngineType === ClientEngineType.DataProxy) { | ||
runtimeName = 'proxy' | ||
if (dataProxy === true) { | ||
runtimeName = 'proxy' // TODO: decouple the runtimes | ||
} | ||
|
||
const finalOutputDir = useDotPrisma ? await getDotPrismaDir(outputDir) : outputDir | ||
|
@@ -177,6 +180,7 @@ export async function generateClient({ | |
engineVersion, | ||
projectRoot, | ||
activeProvider, | ||
dataProxy, | ||
}) | ||
|
||
const denylistsErrors = validateDmmfAgainstDenylists(prismaClientDmmf) | ||
|
@@ -238,7 +242,8 @@ export async function generateClient({ | |
}\` in the \`binaryPaths\` object.`, | ||
) | ||
} | ||
if (transpile) { | ||
|
||
if (transpile === true && dataProxy === false) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We don't copy the query engine files if the data proxy is in use. |
||
if (process.env.NETLIFY) { | ||
await makeDir('/tmp/prisma-engines') | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -51,6 +51,7 @@ if (process.argv[1] === __filename) { | |
clientVersion, | ||
transpile: true, | ||
activeProvider: options.datasources[0]?.activeProvider, | ||
dataProxy: options.dataProxy, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Passed by the cli. |
||
}) | ||
}, | ||
}) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unrelated change to restart esbuild compiler on file deletion.