Skip to content
This repository was archived by the owner on Mar 1, 2026. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 3 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.

16 changes: 10 additions & 6 deletions tests/bun/e2e.test.ts → tests/runtimes/bun/bun-e2e.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { clone } from '@zenstackhq/common-helpers';
import { ZenStackClient } from '@zenstackhq/orm';
import { ZenStackClient, type ClientContract } from '@zenstackhq/orm';
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: ClientContract<typeof schema> | undefined;

afterEach(async () => {
await db?.$disconnect();
});
Comment thread
ymc9 marked this conversation as resolved.
Outdated

it('works with simple CRUD', async () => {
const db = await createClient(provider, 'bun-e2e-crud');
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');
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.
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
Loading