7 | {posts?.map((post) => (
8 |
{post.title}
9 | ))}
10 |
11 | );
12 | }
13 |
--------------------------------------------------------------------------------
/tests/integration/tests/frameworks/nextjs/test-project/postgres.zmodel:
--------------------------------------------------------------------------------
1 | datasource db {
2 | provider = 'postgresql'
3 | url = env('DATABASE_URL')
4 | }
5 |
6 | generator js {
7 | provider = 'prisma-client-js'
8 | }
9 |
10 | plugin swr {
11 | provider = '@zenstackhq/swr'
12 | output = 'lib/hooks'
13 | }
14 |
15 | model User {
16 | id String @id
17 | name String
18 | posts Post[]
19 | @@allow('create,read', true)
20 | @@allow('update,delete', auth() == this)
21 | }
22 |
23 | model Post {
24 | id String @id
25 | title String
26 | author User? @relation(fields: [authorId], references: [id])
27 | authorId String?
28 | published Boolean @default(false)
29 | @@allow('all', auth() == author)
30 | @@allow('read', published)
31 | }
32 |
--------------------------------------------------------------------------------
/tests/integration/tests/frameworks/nextjs/test-project/server/db.ts:
--------------------------------------------------------------------------------
1 | import { PrismaClient } from '@prisma/client';
2 |
3 | declare global {
4 | // eslint-disable-next-line no-var
5 | var prisma: PrismaClient | undefined;
6 | }
7 |
8 | export const prisma = global.prisma || new PrismaClient();
9 |
10 | if (process.env.NODE_ENV !== 'production') {
11 | global.prisma = prisma;
12 | }
13 |
--------------------------------------------------------------------------------
/tests/integration/tests/frameworks/nextjs/test-project/sqlite.zmodel:
--------------------------------------------------------------------------------
1 | datasource db {
2 | provider = 'sqlite'
3 | url = 'file:./dev.db'
4 | }
5 |
6 | generator js {
7 | provider = 'prisma-client-js'
8 | }
9 |
10 | plugin swr {
11 | provider = '@zenstackhq/swr'
12 | output = 'lib/hooks'
13 | }
14 |
15 | model User {
16 | id String @id
17 | name String
18 | posts Post[]
19 | @@allow('create,read', true)
20 | @@allow('update,delete', auth() == this)
21 | }
22 |
23 | model Post {
24 | id String @id
25 | title String
26 | author User? @relation(fields: [authorId], references: [id])
27 | authorId String?
28 | published Boolean @default(false)
29 | @@allow('all', auth() == author)
30 | @@allow('read', published)
31 | }
32 |
--------------------------------------------------------------------------------
/tests/integration/tests/frameworks/nextjs/test-project/tsconfig.json:
--------------------------------------------------------------------------------
1 | {
2 | "compilerOptions": {
3 | "target": "es5",
4 | "lib": ["dom", "dom.iterable", "esnext"],
5 | "allowJs": true,
6 | "skipLibCheck": true,
7 | "strict": true,
8 | "forceConsistentCasingInFileNames": true,
9 | "noEmit": true,
10 | "esModuleInterop": true,
11 | "module": "esnext",
12 | "moduleResolution": "node",
13 | "resolveJsonModule": true,
14 | "isolatedModules": true,
15 | "jsx": "preserve",
16 | "incremental": true
17 | },
18 | "include": ["next-env.d.ts", "**/*.ts", "**/*.tsx"],
19 | "exclude": ["node_modules"]
20 | }
21 |
--------------------------------------------------------------------------------
/tests/integration/tests/frameworks/trpc/generation.test.ts:
--------------------------------------------------------------------------------
1 | import { run } from '@zenstackhq/testtools';
2 | import fs from 'fs';
3 | import fse from 'fs-extra';
4 | import path from 'path';
5 |
6 | describe('tRPC Routers Generation Tests', () => {
7 | let origDir: string;
8 |
9 | beforeAll(() => {
10 | origDir = process.cwd();
11 | });
12 |
13 | afterEach(() => {
14 | process.chdir(origDir);
15 | });
16 |
17 | it('basic', async () => {
18 | const testDir = path.join(__dirname, './test-run/basic');
19 | if (fs.existsSync(testDir)) {
20 | fs.rmSync(testDir, { recursive: true, force: true });
21 | }
22 | fs.mkdirSync(testDir, { recursive: true });
23 | fse.copySync(path.join(__dirname, './test-project'), testDir);
24 |
25 | process.chdir(testDir);
26 | run('npm install');
27 | run('npx zenstack generate --no-dependency-check --schema ./todo.zmodel', {
28 | NODE_PATH: 'node_modules',
29 | });
30 | run('npm run build', { NODE_PATH: 'node_modules' });
31 | });
32 | });
33 |
--------------------------------------------------------------------------------
/tests/integration/tests/frameworks/trpc/test-project/.gitignore:
--------------------------------------------------------------------------------
1 | # See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2 |
3 | # dependencies
4 | /node_modules
5 | /.pnp
6 | .pnp.js
7 |
8 | # testing
9 | /coverage
10 |
11 | # next.js
12 | /.next/
13 | /out/
14 |
15 | # production
16 | /build
17 |
18 | # misc
19 | .DS_Store
20 | *.pem
21 |
22 | # debug
23 | npm-debug.log*
24 | yarn-debug.log*
25 | yarn-error.log*
26 | .pnpm-debug.log*
27 |
28 | # local env files
29 | .env*.local
30 |
31 | # vercel
32 | .vercel
33 |
34 | # typescript
35 | *.tsbuildinfo
36 | next-env.d.ts
37 |
--------------------------------------------------------------------------------
/tests/integration/tests/frameworks/trpc/test-project/.npmrc:
--------------------------------------------------------------------------------
1 | cache=../../../.npmcache
2 |
--------------------------------------------------------------------------------
/tests/integration/tests/frameworks/trpc/test-project/lib/trpc.ts:
--------------------------------------------------------------------------------
1 | import { TRPCClientError, httpBatchLink } from '@trpc/client';
2 | import { createTRPCNext } from '@trpc/next';
3 | import superjson from 'superjson';
4 | import type { AppRouter } from '../server/routers/_app';
5 |
6 | function getBaseUrl() {
7 | if (typeof window !== 'undefined') return '';
8 |
9 | if (process.env.VERCEL_URL) {
10 | return `https://${process.env.VERCEL_URL}`;
11 | } else {
12 | return `http://localhost:${process.env.PORT ?? 3000}`;
13 | }
14 | }
15 |
16 | export const trpc = createTRPCNext