Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(client): data proxy custom output (#17772)
* fix(client): data proxy custom output * add type and more runtime tests
- Loading branch information
Showing
10 changed files
with
173 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
packages/client/tests/e2e/runtimes/data-proxy-custom-output/_steps.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { $ } from 'zx' | ||
|
||
import { executeSteps } from '../_utils/executeSteps' | ||
|
||
void executeSteps({ | ||
setup: async () => { | ||
await $`pnpm install` | ||
await $`pnpm exec prisma generate --data-proxy` | ||
}, | ||
test: async () => { | ||
await $`pnpm exec prisma -v` | ||
await $`ts-node src/index.ts` | ||
await $`pnpm exec jest` | ||
await $`pnpm exec tsc` | ||
}, | ||
finish: async () => { | ||
await $`echo "done"` | ||
}, | ||
// keep: true, // keep docker open to debug it | ||
}) |
14 changes: 14 additions & 0 deletions
14
packages/client/tests/e2e/runtimes/data-proxy-custom-output/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"private": true, | ||
"version": "0.0.0", | ||
"main": "index.js", | ||
"scripts": {}, | ||
"dependencies": { | ||
"@prisma/client": "../prisma-client-0.0.0.tgz" | ||
}, | ||
"devDependencies": { | ||
"@types/node": "16.18.11 ", | ||
"prisma": "../prisma-0.0.0.tgz", | ||
"expect-type": "0.15.0" | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
packages/client/tests/e2e/runtimes/data-proxy-custom-output/prisma/schema.prisma
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// This is your Prisma schema file, | ||
// learn more about it in the docs: https://pris.ly/d/prisma-schema | ||
|
||
generator client { | ||
provider = "prisma-client-js" | ||
output = "client" | ||
} | ||
|
||
datasource db { | ||
provider = "sqlite" | ||
url = "file:./db" | ||
} | ||
|
||
model User { | ||
id Int @id @default(autoincrement()) | ||
email String @unique | ||
name String? | ||
posts Post[] | ||
profile Profile? | ||
} | ||
|
||
model Post { | ||
id Int @id @default(autoincrement()) | ||
title String | ||
content String? | ||
published Boolean @default(false) | ||
author User @relation(fields: [authorId], references: [id]) | ||
authorId Int | ||
} | ||
|
||
model Profile { | ||
id Int @id @default(autoincrement()) | ||
bio String? | ||
user User @relation(fields: [userId], references: [id]) | ||
userId Int @unique | ||
} |
3 changes: 3 additions & 0 deletions
3
packages/client/tests/e2e/runtimes/data-proxy-custom-output/readme.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Readme | ||
|
||
This test makes sure that generating a custom output for the data proxy works. |
21 changes: 21 additions & 0 deletions
21
packages/client/tests/e2e/runtimes/data-proxy-custom-output/src/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { expectTypeOf } from 'expect-type' | ||
|
||
import { PrismaClient } from '../prisma/client' | ||
import { PrismaClient as PrismaClientEdge } from '../prisma/client/edge' | ||
|
||
// we only use this to test the types | ||
async function main() { | ||
const prisma = new PrismaClient() | ||
const prismaEdge = new PrismaClientEdge() | ||
|
||
const user = await prisma.user.create({ | ||
data: { email: 'john@doe.io' }, | ||
}) | ||
|
||
const userEdge = await prismaEdge.user.create({ | ||
data: { email: 'john@doe.io' }, | ||
}) | ||
|
||
expectTypeOf(user).toHaveProperty('email').not.toBeAny() | ||
expectTypeOf(userEdge).toHaveProperty('email').not.toBeAny() | ||
} |
61 changes: 61 additions & 0 deletions
61
packages/client/tests/e2e/runtimes/data-proxy-custom-output/tests/main.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import fs from 'fs/promises' | ||
import path from 'path' | ||
|
||
import { PrismaClient } from '../prisma/client' | ||
import { PrismaClient as PrismaClientEdge } from '../prisma/client/edge' | ||
|
||
test('assert node data proxy runtime can be used', async () => { | ||
try { | ||
const prisma = new PrismaClient() | ||
|
||
const data = await prisma.user.create({ | ||
data: { email: 'jane@doe.io' }, | ||
}) | ||
} catch (e) { | ||
expect(e.message).toMatchInlineSnapshot(`"Datasource URL must use prisma:// protocol when --data-proxy is used"`) | ||
} | ||
}) | ||
|
||
test('assert node data proxy index requires the right file', async () => { | ||
const data = await fs.readFile(path.join(__dirname, '..', 'prisma', 'client', 'index.js')) | ||
|
||
expect(data.includes('./runtime/data-proxy')).toBe(true) | ||
}) | ||
|
||
test('assert edge data proxy runtime can be used', async () => { | ||
try { | ||
const prisma = new PrismaClientEdge() | ||
|
||
const data = await prisma.user.create({ | ||
data: { email: 'jane@doe.io' }, | ||
}) | ||
} catch (e) { | ||
expect(e.message).toMatchInlineSnapshot(`"Datasource URL must use prisma:// protocol when --data-proxy is used"`) | ||
} | ||
}) | ||
|
||
test('assert edge data proxy index requires the right file', async () => { | ||
const data = await fs.readFile(path.join(__dirname, '..', 'prisma', 'client', 'edge.js')) | ||
|
||
expect(data.includes('./runtime/edge')).toBe(true) | ||
}) | ||
|
||
test('runtime files exists', async () => { | ||
const files = await fs.readdir(path.join(__dirname, '..', 'prisma', 'client', 'runtime')) | ||
|
||
console.log(files) | ||
|
||
expect(files).toMatchInlineSnapshot(` | ||
[ | ||
"data-proxy.d.ts", | ||
"data-proxy.js", | ||
"edge-esm.js", | ||
"edge.js", | ||
"index.d.ts", | ||
"library.d.ts", | ||
"library.js", | ||
] | ||
`) | ||
}) | ||
|
||
export {} |
4 changes: 4 additions & 0 deletions
4
packages/client/tests/e2e/runtimes/data-proxy-custom-output/tsconfig.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"extends": "../../tsconfig.base.json", | ||
"include": ["src/*"] | ||
} |