Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
127 changes: 88 additions & 39 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 9 additions & 5 deletions tests/bun/e2e.test.ts → tests/runtimes/bun/bun-e2e.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { PostgresDialect } from '@zenstackhq/orm/dialects/postgres';
import { PolicyPlugin } from '@zenstackhq/plugin-policy';
import { TEST_PG_URL } from '@zenstackhq/testtools';
import { Database } from 'bun:sqlite';
import { describe, expect, it } from 'bun:test';
import { afterEach, describe, expect, it } from 'bun:test';
import type { Dialect } from 'kysely';
import { BunSqliteDialect } from 'kysely-bun-sqlite';
import { Client, Pool } from 'pg';
Expand All @@ -13,8 +13,14 @@ import { schema } from './schemas/schema';
describe('Bun e2e tests', () => {
const provider = (process.env['TEST_DB_PROVIDER'] ?? 'sqlite') as 'sqlite' | 'postgresql';

let _db: any;

afterEach(async () => {
await _db?.$disconnect();
});

it('works with simple CRUD', async () => {
const db = await createClient(provider, 'bun-e2e-crud');
const db = (_db = await createClient(provider, 'bun-e2e-crud'));

const user = await db.user.create({
data: {
Expand Down Expand Up @@ -44,7 +50,7 @@ describe('Bun e2e tests', () => {
});

it('enforces policies', async () => {
const db = await createClient(provider, 'bun-e2e-policies');
const db = (_db = await createClient(provider, 'bun-e2e-policies'));
const authDb = db.$use(new PolicyPlugin());

// create a user
Expand All @@ -58,13 +64,11 @@ describe('Bun e2e tests', () => {
{
id: 'p1',
title: 'First Post',
content: 'Hello World',
published: true,
},
{
id: 'p2',
title: 'Second Post',
content: 'Draft Post',
published: false,
},
],
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@

/* eslint-disable */

import { schema as $schema, type SchemaType as $Schema } from "./schema";
import { type ModelResult as $ModelResult, type TypeDefResult as $TypeDefResult } from "@zenstackhq/orm";
import { type SchemaType as $Schema } from "./schema";
import { type ModelResult as $ModelResult } from "@zenstackhq/orm";
export type User = $ModelResult<$Schema, "User">;
export type Post = $ModelResult<$Schema, "Post">;
export type CommonFields = $TypeDefResult<$Schema, "CommonFields">;
export const Role = $schema.enums.Role.values;
export type Role = (typeof Role)[keyof typeof Role];
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,6 @@ const _schema = {
attributes: [{ name: "@id" }, { name: "@default", args: [{ name: "value", value: ExpressionUtils.call("cuid") }] }],
default: ExpressionUtils.call("cuid")
},
createdAt: {
name: "createdAt",
type: "DateTime",
attributes: [{ name: "@default", args: [{ name: "value", value: ExpressionUtils.call("now") }] }],
default: ExpressionUtils.call("now")
},
updatedAt: {
name: "updatedAt",
type: "DateTime",
updatedAt: true,
attributes: [{ name: "@updatedAt" }]
},
email: {
name: "email",
type: "String",
Expand All @@ -44,22 +32,11 @@ const _schema = {
type: "String",
optional: true
},
role: {
name: "role",
type: "Role",
attributes: [{ name: "@default", args: [{ name: "value", value: ExpressionUtils.literal("USER") }] }],
default: "USER"
},
posts: {
name: "posts",
type: "Post",
array: true,
relation: { opposite: "author" }
},
meta: {
name: "meta",
type: "Json",
optional: true
}
},
attributes: [
Expand All @@ -82,27 +59,10 @@ const _schema = {
attributes: [{ name: "@id" }, { name: "@default", args: [{ name: "value", value: ExpressionUtils.call("cuid") }] }],
default: ExpressionUtils.call("cuid")
},
createdAt: {
name: "createdAt",
type: "DateTime",
attributes: [{ name: "@default", args: [{ name: "value", value: ExpressionUtils.call("now") }] }],
default: ExpressionUtils.call("now")
},
updatedAt: {
name: "updatedAt",
type: "DateTime",
updatedAt: true,
attributes: [{ name: "@updatedAt" }]
},
title: {
name: "title",
type: "String"
},
content: {
name: "content",
type: "String",
optional: true
},
published: {
name: "published",
type: "Boolean",
Expand Down Expand Up @@ -134,39 +94,6 @@ const _schema = {
}
}
},
typeDefs: {
CommonFields: {
name: "CommonFields",
fields: {
id: {
name: "id",
type: "String",
attributes: [{ name: "@id" }, { name: "@default", args: [{ name: "value", value: ExpressionUtils.call("cuid") }] }],
default: ExpressionUtils.call("cuid")
},
createdAt: {
name: "createdAt",
type: "DateTime",
attributes: [{ name: "@default", args: [{ name: "value", value: ExpressionUtils.call("now") }] }],
default: ExpressionUtils.call("now")
},
updatedAt: {
name: "updatedAt",
type: "DateTime",
updatedAt: true,
attributes: [{ name: "@updatedAt" }]
}
}
}
},
enums: {
Role: {
values: {
ADMIN: "ADMIN",
USER: "USER"
}
}
},
authType: "User",
plugins: {}
} as const satisfies SchemaDef;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,39 +1,25 @@
datasource db {
provider = "sqlite"
url = "file:./dev.db"
}

plugin policy {
provider = "../../../packages/plugins/policy"
}

enum Role {
ADMIN
USER
}

type CommonFields {
id String @id @default(cuid())
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
}

model User with CommonFields {
email String @unique
name String?
password String @ignore
role Role @default(USER)
posts Post[]
meta Json?
model User {
id String @id @default(cuid())
email String @unique
name String?
posts Post[]

// Access policies
@@allow('all', auth().id == id)
@@allow('read', auth() != null)
}

model Post with CommonFields {
model Post {
id String @id @default(cuid())
title String
content String?
published Boolean @default(false)
author User @relation(fields: [authorId], references: [id], onUpdate: Cascade, onDelete: Cascade)
authorId String
Expand All @@ -43,4 +29,3 @@ model Post with CommonFields {
@@allow('all', auth().id == authorId)
@@allow('read', published)
}

File renamed without changes.
File renamed without changes.
Binary file added tests/runtimes/edge-runtime/.DS_Store
Binary file not shown.
Loading