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
Conversation
Warning: potentially stupid question ahead. |
It's a good question, so I'll try to answer with what I think is my best opinion. If we stick to the fact that |
587c573
to
5fa27f8
Compare
@@ -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 comment
The reason will be displayed to describe this comment to others. Learn more.
Not a valid entry anymore.
@@ -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 comment
The reason will be displayed to describe this comment to others. Learn more.
dataProxy = false
@@ -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 comment
The reason will be displayed to describe this comment to others. Learn more.
dataProxy = true
@@ -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 comment
The reason will be displayed to describe this comment to others. Learn more.
Not needed.
@@ -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 comment
The reason will be displayed to describe this comment to others. Learn more.
dataProxy
is now stored in the generated config instead of being in the generator config block (via schema).
@@ -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 comment
The reason will be displayed to describe this comment to others. Learn more.
Passed by the generator.
${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 comment
The reason will be displayed to describe this comment to others. Learn more.
This will be removed in the followup PR.
} | ||
|
||
// 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 comment
The 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.
@@ -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 comment
The reason will be displayed to describe this comment to others. Learn more.
Not used.
@@ -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 comment
The reason will be displayed to describe this comment to others. Learn more.
Passed to generateClient
via the generator.
@@ -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 comment
The 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.
@@ -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 comment
The reason will be displayed to describe this comment to others. Learn more.
Passed by the cli.
@@ -449,7 +458,9 @@ export function getPrismaClient(config: GetPrismaClientConfig) { | |||
return 'PrismaClient' | |||
} | |||
private getEngine(): Engine { | |||
if (this._clientEngineType === ClientEngineType.Library) { | |||
if (this._dataProxy === true) { |
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.
dataProxy = true
is an override of the other engines, as explicitly asked via --data-proxy
@@ -36,7 +36,7 @@ function getAllTestSuiteTypeChecks(fileNames: string[]) { | |||
|
|||
describe('typescript', () => { | |||
const suitePaths = glob.sync('./**/.generated/**/*.ts', { | |||
ignore: ['./**/.generated/**/*.d.ts', './**/.generated/**/_schema.ts'], | |||
ignore: ['./**/.generated/**/*.d.ts', './**/.generated/**/_*.ts'], |
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.
@@ -1,3 +1,3 @@ | |||
import { build } from '../../../helpers/compile/build' | |||
|
|||
void build([{ name: 'default' }]) | |||
void build([{ name: 'debug' }]) |
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.
@@ -237,7 +234,7 @@ export class DataProxyEngine extends Engine { | |||
const { protocol, host, searchParams } = url | |||
|
|||
if (protocol !== 'prisma:') { | |||
throw new InvalidDatasourceError('Datasource URL should use prisma:// protocol. If you are not using the Data Proxy, remove the `dataProxy` from the `previewFeatures` in your schema and ensure that `PRISMA_CLIENT_ENGINE_TYPE` environment variable is not set to `dataproxy`.', { | |||
throw new InvalidDatasourceError('Datasource URL should use prisma:// protocol when --data-proxy is used', { |
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.
TODO: use "must" instead of "should"
}, | ||
RequestInit | ||
> | ||
// our implementation handles less than the real fetch |
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.
Because of the removal of ambient types from webworkers
.
@@ -155,6 +155,7 @@ export class Migrate { | |||
printDownloadProgress: true, | |||
version: enginesVersion, | |||
cliVersion: packageJson.version, | |||
dataProxy: false, |
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.
We don't allow --data-proxy
on prisma migrate
as they are not currently compatible.
provider = \\"prisma-client-js\\" | ||
previewFeatures = [\\"dataProxy\\"] | ||
} | ||
interactiveTransactions preview feature is not yet available with --data-proxy. |
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.
TODO: re-enable this test.
@@ -3,7 +3,6 @@ import type { GeneratorConfig } from '@prisma/generator-helper' | |||
export enum ClientEngineType { | |||
Library = 'library', | |||
Binary = 'binary', | |||
DataProxy = 'dataproxy', |
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.
Not allowed here anymore.
} | ||
|
||
function checkProxyFeatureFlag(config: ConfigMetaFormat) { |
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.
Not needed anymore.
} | ||
|
||
function checkProxyFeatureFlag(config: ConfigMetaFormat) { | ||
function checkForbiddenItxWithDataProxyFlag(config: ConfigMetaFormat, options: GetGeneratorOptions) { |
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.
Make sure that itx cannot be used with --data-proxy.
Replaced by #13561 |
This PR replaces the
PRISMA_CLIENT_ENGINE_TYPE=dataproxy
mechanism in favor of--data-proxy
via the cli.Next #13512
https://github.com/orgs/prisma/projects/70#card-82299232