Skip to content
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): fix isolated data proxy issues [DPGA, 3] #13599

Merged
merged 9 commits into from Jun 7, 2022
4 changes: 2 additions & 2 deletions packages/cli/src/Generate.ts
Expand Up @@ -138,7 +138,7 @@ ${chalk.bold('Examples')}
printDownloadProgress: !watchMode,
version: enginesVersion,
cliVersion: pkg.version,
dataProxy: args['--data-proxy'],
dataProxy: !!args['--data-proxy'],
millsp marked this conversation as resolved.
Show resolved Hide resolved
})

if (!generators || generators.length === 0) {
Expand Down Expand Up @@ -261,7 +261,7 @@ Please run \`${getCommandWithExecutor('prisma generate')}\` to see the errors.`)
printDownloadProgress: !watchMode,
version: enginesVersion,
cliVersion: pkg.version,
dataProxy: args['--data-proxy'],
dataProxy: !!args['--data-proxy'],
})

if (!generatorsWatch || generatorsWatch.length === 0) {
Expand Down
4 changes: 2 additions & 2 deletions packages/client/src/generation/TSClient/TSClient.ts
Expand Up @@ -42,7 +42,7 @@ export interface TSClientOptions {
schemaPath: string
outputDir: string
activeProvider: string
dataProxy?: boolean
dataProxy: boolean
}

export class TSClient implements Generatable {
Expand All @@ -53,7 +53,7 @@ export class TSClient implements Generatable {
this.dmmf = new DMMFHelper(klona(options.document))
}

public async toJS(edge?: boolean): Promise<string> {
public async toJS(edge = false): Promise<string> {
const {
platforms,
generator,
Expand Down
2 changes: 1 addition & 1 deletion packages/client/src/generation/generateClient.ts
Expand Up @@ -46,7 +46,7 @@ export interface GenerateClientOptions {
engineVersion: string
clientVersion: string
activeProvider: string
dataProxy?: boolean
dataProxy: boolean
}

export interface BuildClientResult {
Expand Down
2 changes: 1 addition & 1 deletion packages/client/src/generation/utils/buildDirname.ts
Expand Up @@ -7,7 +7,7 @@ import path from 'path'
* @param runtimeDir
* @returns
*/
export function buildDirname(edge: boolean | undefined, relativeOutdir: string, runtimeDir: string) {
export function buildDirname(edge: boolean, relativeOutdir: string, runtimeDir: string) {
if (edge === true) {
millsp marked this conversation as resolved.
Show resolved Hide resolved
return buildDirnameDefault()
}
Expand Down
Expand Up @@ -16,7 +16,7 @@ type LoadedEnv = {
* @param datasources
* @returns
*/
export function buildInjectableEdgeEnv(edge: boolean | undefined, datasources: InternalDatasource[]) {
export function buildInjectableEdgeEnv(edge: boolean, datasources: InternalDatasource[]) {
if (edge === true) {
const envVarNames = getSelectedEnvVarNames(datasources)
const loadedEnv = getEmptyEnvObjectForVars(envVarNames)
Expand Down
Expand Up @@ -14,7 +14,7 @@ export type InlineDatasources = {
* @param internalDatasources
* @returns
*/
export function buildInlineDatasource(dataProxy: boolean | undefined, internalDatasources: InternalDatasource[]) {
export function buildInlineDatasource(dataProxy: boolean, internalDatasources: InternalDatasource[]) {
if (dataProxy === true) {
const datasources = internalToInlineDatasources(internalDatasources)

Expand Down
2 changes: 1 addition & 1 deletion packages/client/src/generation/utils/buildInlineSchema.ts
Expand Up @@ -10,7 +10,7 @@ const readFile = fs.promises.readFile
* @param schemaPath
* @returns
*/
export async function buildInlineSchema(dataProxy: boolean | undefined, schemaPath: string) {
export async function buildInlineSchema(dataProxy: boolean, schemaPath: string) {
if (dataProxy === true) {
const b64Schema = (await readFile(schemaPath)).toString('base64')
const schemaHash = crypto.createHash('sha256').update(b64Schema).digest('hex')
Expand Down
Expand Up @@ -16,7 +16,7 @@ import { map } from '../../../../../helpers/blaze/map'
* @returns
*/
export function buildNFTAnnotations(
dataProxy: boolean | undefined,
dataProxy: boolean,
engineType: ClientEngineType,
platforms: Platform[] | undefined,
relativeOutdir: string,
Expand Down
2 changes: 1 addition & 1 deletion packages/client/src/generation/utils/buildRequirePath.ts
Expand Up @@ -3,7 +3,7 @@
* @param edge
* @returns
*/
export function buildRequirePath(edge: boolean | undefined) {
export function buildRequirePath(edge: boolean) {
if (edge === true) return ''

return `
Expand Down
Expand Up @@ -6,7 +6,7 @@
* @param runtimeName
* @returns
*/
export function buildWarnEnvConflicts(edge: boolean | undefined, runtimeDir: string, runtimeName: string) {
export function buildWarnEnvConflicts(edge: boolean, runtimeDir: string, runtimeName: string) {
if (edge === true) return ''

return `
Expand Down
4 changes: 2 additions & 2 deletions packages/client/src/runtime/getPrismaClient.ts
Expand Up @@ -228,7 +228,7 @@ export interface GetPrismaClientConfig {
* If enabled, we disregard the generator config engineType.
* It means that `--data-proxy` binds you to the Data Proxy.
*/
dataProxy?: boolean
dataProxy: boolean

/**
* The contents of the schema encoded into a string
Expand Down Expand Up @@ -338,7 +338,7 @@ export function getPrismaClient(config: GetPrismaClientConfig) {
this._rejectOnNotFound = optionsArg?.rejectOnNotFound
this._clientVersion = config.clientVersion ?? clientVersion
this._activeProvider = config.activeProvider
this._dataProxy = config.dataProxy ?? false
this._dataProxy = config.dataProxy
this._clientEngineType = getClientEngineType(config.generator!)
const envPaths = {
rootEnvPath:
Expand Down
1 change: 1 addition & 0 deletions packages/client/src/utils/generateInFolder.ts
Expand Up @@ -142,6 +142,7 @@ export async function generateInFolder({
clientVersion: 'local',
engineVersion: 'local',
activeProvider: config.datasources[0].activeProvider,
dataProxy: !!process.env.DATA_PROXY,
})
const time = performance.now() - before
debug(`Done generating client in ${time}`)
Expand Down
Expand Up @@ -53,6 +53,7 @@ export async function setupTestSuiteClient(suiteMeta: TestSuiteMeta, suiteConfig
edge: [__dirname.replace(/\\/g, '/'), '..', '..', '..', 'runtime', 'edge'].join('/'),
},
projectRoot: suiteFolderPath,
dataProxy: !!process.env.DATA_PROXY,
})

return require(path.join(suiteFolderPath, 'node_modules/@prisma/client'))
Expand Down
2 changes: 1 addition & 1 deletion packages/generator-helper/src/types.ts
Expand Up @@ -89,7 +89,7 @@ export type GeneratorOptions = {
// TODO is it really always version hash? Feature is unclear.
version: string // version hash
binaryPaths?: BinaryPaths
dataProxy?: boolean
dataProxy: boolean
}

export type EngineType = 'queryEngine' | 'libqueryEngine' | 'migrationEngine' | 'introspectionEngine' | 'prismaFmt'
Expand Down
1 change: 1 addition & 0 deletions packages/migrate/src/Migrate.ts
Expand Up @@ -155,6 +155,7 @@ export class Migrate {
printDownloadProgress: true,
version: enginesVersion,
cliVersion: packageJson.version,
dataProxy: false,
})

for (const generator of generators) {
Expand Down
12 changes: 12 additions & 0 deletions packages/sdk/src/__tests__/getGenerators/getGenerators.test.ts
Expand Up @@ -37,6 +37,7 @@ describe('getGenerators', () => {
const generators = await getGenerators({
schemaPath: path.join(__dirname, 'valid-minimal-schema.prisma'),
providerAliases: aliases,
dataProxy: false,
})

expect(generators.map((g) => g.manifest)).toMatchInlineSnapshot(`
Expand Down Expand Up @@ -119,6 +120,7 @@ describe('getGenerators', () => {
const generators = await getGenerators({
schemaPath: path.join(__dirname, 'valid-minimal-schema-binaryTargets.prisma'),
providerAliases: aliases,
dataProxy: false,
})

expect(generators.map((g) => g.manifest)).toMatchInlineSnapshot(`
Expand Down Expand Up @@ -209,6 +211,7 @@ describe('getGenerators', () => {
const generators = await getGenerators({
schemaPath: path.join(__dirname, 'valid-minimal-schema-binaryTargets-env-var.prisma'),
providerAliases: aliases,
dataProxy: false,
})

expect(generators.map((g) => g.manifest)).toMatchInlineSnapshot(`
Expand Down Expand Up @@ -299,6 +302,7 @@ describe('getGenerators', () => {
const generators = await getGenerators({
schemaPath: path.join(__dirname, 'valid-minimal-schema-binaryTargets-env-var.prisma'),
providerAliases: aliases,
dataProxy: false,
})

expect(generators.map((g) => g.manifest)).toMatchInlineSnapshot(`
Expand Down Expand Up @@ -389,6 +393,7 @@ describe('getGenerators', () => {
const generators = await getGenerators({
schemaPath: path.join(__dirname, 'valid-minimal-schema-binaryTargets-env-var.prisma'),
providerAliases: aliases,
dataProxy: false,
})

expect(generators.map((g) => g.manifest)).toMatchInlineSnapshot(`
Expand Down Expand Up @@ -486,6 +491,7 @@ describe('getGenerators', () => {
const generators = await getGenerators({
schemaPath: path.join(__dirname, 'valid-minimal-schema-binaryTargets-env-var.prisma'),
providerAliases: aliases,
dataProxy: false,
})

expect(generators.map((g) => g.manifest)).toMatchInlineSnapshot(`
Expand Down Expand Up @@ -583,6 +589,7 @@ describe('getGenerators', () => {
binaryPathsOverride: {
queryEngine: queryEnginePath,
},
dataProxy: false,
})

const options = generators.map((g) => g.options?.binaryPaths)
Expand All @@ -609,6 +616,7 @@ describe('getGenerators', () => {
getGenerators({
schemaPath: path.join(__dirname, 'invalid-platforms-schema.prisma'),
providerAliases: aliases,
dataProxy: false,
}),
).rejects.toThrow('deprecated')
})
Expand All @@ -625,6 +633,7 @@ describe('getGenerators', () => {
getGenerators({
schemaPath: path.join(__dirname, 'invalid-binary-target-schema.prisma'),
providerAliases: aliases,
dataProxy: false,
}),
).rejects.toThrow('Unknown')

Expand All @@ -647,6 +656,7 @@ describe('getGenerators', () => {
await getGenerators({
schemaPath: path.join(__dirname, 'missing-datasource-schema.prisma'),
providerAliases: aliases,
dataProxy: false,
})
} catch (e) {
expect(stripAnsi(e.message)).toMatchInlineSnapshot(`
Expand Down Expand Up @@ -684,6 +694,7 @@ describe('getGenerators', () => {
await getGenerators({
schemaPath: path.join(__dirname, 'missing-models-sqlite-schema.prisma'),
providerAliases: aliases,
dataProxy: false,
})
} catch (e) {
expect(stripAnsi(e.message)).toMatchInlineSnapshot(`
Expand Down Expand Up @@ -722,6 +733,7 @@ describe('getGenerators', () => {
await getGenerators({
schemaPath: path.join(__dirname, 'missing-models-mongodb-schema.prisma'),
providerAliases: aliases,
dataProxy: false,
})
} catch (e) {
expect(stripAnsi(e.message)).toMatchInlineSnapshot(`
Expand Down
2 changes: 1 addition & 1 deletion packages/sdk/src/get-generators/getGenerators.ts
Expand Up @@ -50,7 +50,7 @@ export type GetGeneratorOptions = {
overrideGenerators?: GeneratorConfig[]
skipDownload?: boolean
binaryPathsOverride?: BinaryPathsOverride
dataProxy?: boolean
dataProxy: boolean
}
/**
* Makes sure that all generators have the binaries they deserve and returns a
Expand Down