diff --git a/packages/cli/src/actions/migrate.ts b/packages/cli/src/actions/migrate.ts index 19f94ce7..eb001e8f 100644 --- a/packages/cli/src/actions/migrate.ts +++ b/packages/cli/src/actions/migrate.ts @@ -86,7 +86,7 @@ async function runReset(prismaSchemaFile: string, options: ResetOptions) { 'prisma migrate reset', ` --schema "${prismaSchemaFile}"`, ' --skip-generate', - options.force ? ' --force' : '' + options.force ? ' --force' : '', ].join(''); await execPackage(cmd); diff --git a/packages/server/package.json b/packages/server/package.json index 43870381..96a11f36 100644 --- a/packages/server/package.json +++ b/packages/server/package.json @@ -108,6 +108,16 @@ "types": "./dist/sveltekit.d.cts", "default": "./dist/sveltekit.cjs" } + }, + "./tanstack-start": { + "import": { + "types": "./dist/tanstack-start.d.ts", + "default": "./dist/tanstack-start.js" + }, + "require": { + "types": "./dist/tanstack-start.d.cts", + "default": "./dist/tanstack-start.cjs" + } } }, "dependencies": { diff --git a/packages/server/src/adapter/common.ts b/packages/server/src/adapter/common.ts index bc6ee7c8..40886543 100644 --- a/packages/server/src/adapter/common.ts +++ b/packages/server/src/adapter/common.ts @@ -1,6 +1,6 @@ -import type { SchemaDef } from "@zenstackhq/orm/schema"; -import { log } from "../api/utils"; -import type { ApiHandler, LogConfig } from "../types"; +import type { SchemaDef } from '@zenstackhq/orm/schema'; +import { log } from '../api/utils'; +import type { ApiHandler, LogConfig } from '../types'; /** * Options common to all adapters @@ -13,5 +13,9 @@ export interface CommonAdapterOptions { } export function logInternalError(logger: LogConfig | undefined, err: unknown) { - log(logger, 'error', `An unhandled error occurred while processing the request: ${err}${err instanceof Error ? '\n' + err.stack : ''}`); -} \ No newline at end of file + log( + logger, + 'error', + `An unhandled error occurred while processing the request: ${err}${err instanceof Error ? '\n' + err.stack : ''}`, + ); +} diff --git a/packages/server/src/adapter/fastify/index.ts b/packages/server/src/adapter/fastify/index.ts index 94d6329b..48a3dacc 100644 --- a/packages/server/src/adapter/fastify/index.ts +++ b/packages/server/src/adapter/fastify/index.ts @@ -1,2 +1 @@ export { ZenStackFastifyPlugin, type FastifyPluginOptions } from './plugin'; - diff --git a/packages/server/src/adapter/fastify/plugin.ts b/packages/server/src/adapter/fastify/plugin.ts index a1ab0013..b22012b9 100644 --- a/packages/server/src/adapter/fastify/plugin.ts +++ b/packages/server/src/adapter/fastify/plugin.ts @@ -8,7 +8,6 @@ import { logInternalError, type CommonAdapterOptions } from '../common'; * Fastify plugin options */ export interface FastifyPluginOptions extends CommonAdapterOptions { - /** * Url prefix, e.g.: /api */ @@ -17,7 +16,10 @@ export interface FastifyPluginOptions extends CommonAd /** * Callback for getting a ZenStackClient for the given request */ - getClient: (request: FastifyRequest, reply: FastifyReply) => ClientContract | Promise>; + getClient: ( + request: FastifyRequest, + reply: FastifyReply, + ) => ClientContract | Promise>; } /** diff --git a/packages/server/src/adapter/nuxt/handler.ts b/packages/server/src/adapter/nuxt/handler.ts index 01f26bdc..c1c2efcd 100644 --- a/packages/server/src/adapter/nuxt/handler.ts +++ b/packages/server/src/adapter/nuxt/handler.ts @@ -1,13 +1,6 @@ import type { ClientContract } from '@zenstackhq/orm'; import type { SchemaDef } from '@zenstackhq/orm/schema'; -import { - H3Event, - defineEventHandler, - getQuery, - getRouterParams, - readBody, - type EventHandlerRequest -} from 'h3'; +import { H3Event, defineEventHandler, getQuery, getRouterParams, readBody, type EventHandlerRequest } from 'h3'; import { setResponseStatus } from 'nuxt/app'; import { logInternalError, type CommonAdapterOptions } from '../common'; diff --git a/packages/server/src/adapter/tanstack-start/handler.ts b/packages/server/src/adapter/tanstack-start/handler.ts new file mode 100644 index 00000000..de27933e --- /dev/null +++ b/packages/server/src/adapter/tanstack-start/handler.ts @@ -0,0 +1,73 @@ +import type { SchemaDef } from '@zenstackhq/orm/schema'; +import type { TanStackStartOptions } from '.'; +import { logInternalError } from '../common'; + +/** + * Creates a TanStack Start server route handler which encapsulates ZenStack CRUD operations. + * + * @param options Options for initialization + * @returns A TanStack Start server route handler + */ +export default function factory( + options: TanStackStartOptions, +): ({ request, params }: { request: Request; params: Record }) => Promise { + return async ({ request, params }: { request: Request; params: Record }) => { + const client = await options.getClient(request, params); + if (!client) { + return new Response(JSON.stringify({ message: 'unable to get ZenStackClient from request context' }), { + status: 500, + headers: { + 'Content-Type': 'application/json', + }, + }); + } + + const url = new URL(request.url); + const query = Object.fromEntries(url.searchParams); + + // Extract path from params._splat for catch-all routes + const path = params['_splat']; + + if (!path) { + return new Response(JSON.stringify({ message: 'missing path parameter' }), { + status: 400, + headers: { + 'Content-Type': 'application/json', + }, + }); + } + + let requestBody: unknown; + if (request.body) { + try { + requestBody = await request.json(); + } catch { + // noop + } + } + + try { + const r = await options.apiHandler.handleRequest({ + method: request.method!, + path, + query, + requestBody, + client, + }); + return new Response(JSON.stringify(r.body), { + status: r.status, + headers: { + 'Content-Type': 'application/json', + }, + }); + } catch (err) { + logInternalError(options.apiHandler.log, err); + return new Response(JSON.stringify({ message: 'An internal server error occurred' }), { + status: 500, + headers: { + 'Content-Type': 'application/json', + }, + }); + } + }; +} diff --git a/packages/server/src/adapter/tanstack-start/index.ts b/packages/server/src/adapter/tanstack-start/index.ts new file mode 100644 index 00000000..c8298121 --- /dev/null +++ b/packages/server/src/adapter/tanstack-start/index.ts @@ -0,0 +1,29 @@ +import type { ClientContract } from '@zenstackhq/orm'; +import type { SchemaDef } from '@zenstackhq/orm/schema'; +import type { CommonAdapterOptions } from '../common'; +import { default as Handler } from './handler'; + +/** + * Options for initializing a TanStack Start server route handler. + */ +export interface TanStackStartOptions extends CommonAdapterOptions { + /** + * Callback method for getting a ZenStackClient instance for the given request and params. + */ + getClient: ( + request: Request, + params: Record, + ) => ClientContract | Promise>; +} + +/** + * Creates a TanStack Start server route handler. + * @see https://zenstack.dev/docs/reference/server-adapters/tanstack-start + */ +export function TanStackStartHandler( + options: TanStackStartOptions, +): ReturnType { + return Handler(options); +} + +export default TanStackStartHandler; diff --git a/packages/server/test/adapter/elysia.test.ts b/packages/server/test/adapter/elysia.test.ts index 009ee938..9d02e35c 100644 --- a/packages/server/test/adapter/elysia.test.ts +++ b/packages/server/test/adapter/elysia.test.ts @@ -11,7 +11,11 @@ describe('Elysia adapter tests - rpc handler', () => { const client = await createTestClient(schema); const handler = await createElysiaApp( - createElysiaHandler({ getClient: () => client, basePath: '/api', apiHandler: new RPCApiHandler({ schema: client.schema }) }) + createElysiaHandler({ + getClient: () => client, + basePath: '/api', + apiHandler: new RPCApiHandler({ schema: client.schema }), + }), ); let r = await handler(makeRequest('GET', makeUrl('/api/post/findMany', { where: { id: { equals: '1' } } }))); @@ -31,7 +35,7 @@ describe('Elysia adapter tests - rpc handler', () => { ], }, }, - }) + }), ); expect(r.status).toBe(201); expect((await unmarshal(r)).data).toMatchObject({ @@ -51,7 +55,7 @@ describe('Elysia adapter tests - rpc handler', () => { expect((await unmarshal(r)).data).toHaveLength(1); r = await handler( - makeRequest('PUT', '/api/user/update', { where: { id: 'user1' }, data: { email: 'user1@def.com' } }) + makeRequest('PUT', '/api/user/update', { where: { id: 'user1' }, data: { email: 'user1@def.com' } }), ); expect(r.status).toBe(200); expect((await unmarshal(r)).data.email).toBe('user1@def.com'); @@ -65,14 +69,14 @@ describe('Elysia adapter tests - rpc handler', () => { expect((await unmarshal(r)).data._sum.viewCount).toBe(3); r = await handler( - makeRequest('GET', makeUrl('/api/post/groupBy', { by: ['published'], _sum: { viewCount: true } })) + makeRequest('GET', makeUrl('/api/post/groupBy', { by: ['published'], _sum: { viewCount: true } })), ); expect(r.status).toBe(200); expect((await unmarshal(r)).data).toEqual( expect.arrayContaining([ expect.objectContaining({ published: true, _sum: { viewCount: 1 } }), expect.objectContaining({ published: false, _sum: { viewCount: 2 } }), - ]) + ]), ); r = await handler(makeRequest('DELETE', makeUrl('/api/user/deleteMany', { where: { id: 'user1' } }))); @@ -89,8 +93,8 @@ describe('Elysia adapter tests - rest handler', () => { createElysiaHandler({ getClient: () => client, basePath: '/api', - apiHandler: new RestApiHandler({schema: client.$schema, endpoint: 'http://localhost/api' }), - }) + apiHandler: new RestApiHandler({ schema: client.$schema, endpoint: 'http://localhost/api' }), + }), ); let r = await handler(makeRequest('GET', makeUrl('/api/post/1'))); @@ -102,7 +106,7 @@ describe('Elysia adapter tests - rest handler', () => { type: 'user', attributes: { id: 'user1', email: 'user1@abc.com' }, }, - }) + }), ); expect(r.status).toBe(201); expect(await unmarshal(r)).toMatchObject({ @@ -129,7 +133,7 @@ describe('Elysia adapter tests - rest handler', () => { r = await handler( makeRequest('PUT', makeUrl('/api/user/user1'), { data: { type: 'user', attributes: { email: 'user1@def.com' } }, - }) + }), ); expect(r.status).toBe(200); expect((await unmarshal(r)).data.attributes.email).toBe('user1@def.com'); diff --git a/packages/server/test/adapter/fastify.test.ts b/packages/server/test/adapter/fastify.test.ts index ba487859..85c0a463 100644 --- a/packages/server/test/adapter/fastify.test.ts +++ b/packages/server/test/adapter/fastify.test.ts @@ -13,7 +13,7 @@ describe('Fastify adapter tests - rpc handler', () => { app.register(ZenStackFastifyPlugin, { prefix: '/api', getClient: () => client, - apiHandler: new RPCApiHandler({ schema: client.schema }) + apiHandler: new RPCApiHandler({ schema: client.schema }), }); let r = await app.inject({ @@ -49,7 +49,7 @@ describe('Fastify adapter tests - rpc handler', () => { expect.objectContaining({ title: 'post1' }), expect.objectContaining({ title: 'post2' }), ]), - }) + }), ); r = await app.inject({ @@ -97,7 +97,7 @@ describe('Fastify adapter tests - rpc handler', () => { expect.arrayContaining([ expect.objectContaining({ published: true, _sum: { viewCount: 1 } }), expect.objectContaining({ published: false, _sum: { viewCount: 2 } }), - ]) + ]), ); r = await app.inject({ diff --git a/packages/server/test/adapter/hono.test.ts b/packages/server/test/adapter/hono.test.ts index e5e51c7e..3b406f9b 100644 --- a/packages/server/test/adapter/hono.test.ts +++ b/packages/server/test/adapter/hono.test.ts @@ -10,7 +10,9 @@ describe('Hono adapter tests - rpc handler', () => { it('properly handles requests', async () => { const client = await createTestClient(schema); - const handler = await createHonoApp(createHonoHandler({ getClient: () => client, apiHandler: new RPCApiHandler({schema: client.$schema}) })); + const handler = await createHonoApp( + createHonoHandler({ getClient: () => client, apiHandler: new RPCApiHandler({ schema: client.$schema }) }), + ); let r = await handler(makeRequest('GET', makeUrl('/api/post/findMany', { where: { id: { equals: '1' } } }))); expect(r.status).toBe(200); @@ -29,7 +31,7 @@ describe('Hono adapter tests - rpc handler', () => { ], }, }, - }) + }), ); expect(r.status).toBe(201); expect((await unmarshal(r)).data).toMatchObject({ @@ -49,7 +51,7 @@ describe('Hono adapter tests - rpc handler', () => { expect((await unmarshal(r)).data).toHaveLength(1); r = await handler( - makeRequest('PUT', '/api/user/update', { where: { id: 'user1' }, data: { email: 'user1@def.com' } }) + makeRequest('PUT', '/api/user/update', { where: { id: 'user1' }, data: { email: 'user1@def.com' } }), ); expect(r.status).toBe(200); expect((await unmarshal(r)).data.email).toBe('user1@def.com'); @@ -63,14 +65,14 @@ describe('Hono adapter tests - rpc handler', () => { expect((await unmarshal(r)).data._sum.viewCount).toBe(3); r = await handler( - makeRequest('GET', makeUrl('/api/post/groupBy', { by: ['published'], _sum: { viewCount: true } })) + makeRequest('GET', makeUrl('/api/post/groupBy', { by: ['published'], _sum: { viewCount: true } })), ); expect(r.status).toBe(200); expect((await unmarshal(r)).data).toEqual( expect.arrayContaining([ expect.objectContaining({ published: true, _sum: { viewCount: 1 } }), expect.objectContaining({ published: false, _sum: { viewCount: 2 } }), - ]) + ]), ); r = await handler(makeRequest('DELETE', makeUrl('/api/user/deleteMany', { where: { id: 'user1' } }))); @@ -87,7 +89,7 @@ describe('Hono adapter tests - rest handler', () => { createHonoHandler({ getClient: () => client, apiHandler: new RestApiHandler({ endpoint: 'http://localhost/api', schema: client.$schema }), - }) + }), ); let r = await handler(makeRequest('GET', makeUrl('/api/post/1'))); @@ -99,7 +101,7 @@ describe('Hono adapter tests - rest handler', () => { type: 'user', attributes: { id: 'user1', email: 'user1@abc.com' }, }, - }) + }), ); expect(r.status).toBe(201); expect(await unmarshal(r)).toMatchObject({ @@ -126,7 +128,7 @@ describe('Hono adapter tests - rest handler', () => { r = await handler( makeRequest('PUT', makeUrl('/api/user/user1'), { data: { type: 'user', attributes: { email: 'user1@def.com' } }, - }) + }), ); expect(r.status).toBe(200); expect((await unmarshal(r)).data.attributes.email).toBe('user1@def.com'); diff --git a/packages/server/test/adapter/sveltekit.test.ts b/packages/server/test/adapter/sveltekit.test.ts index 01ee8b09..16f2f374 100644 --- a/packages/server/test/adapter/sveltekit.test.ts +++ b/packages/server/test/adapter/sveltekit.test.ts @@ -9,7 +9,11 @@ describe('SvelteKit adapter tests - rpc handler', () => { it('properly handles requests', async () => { const client = await createTestClient(schema); - const handler = SvelteKitHandler({ prefix: '/api', getClient: () => client, apiHandler: new RPCApiHandler({ schema: client.schema }) }); + const handler = SvelteKitHandler({ + prefix: '/api', + getClient: () => client, + apiHandler: new RPCApiHandler({ schema: client.schema }), + }); let r = await handler(makeRequest('GET', makeUrl('/api/post/findMany', { where: { id: { equals: '1' } } }))); expect(r.status).toBe(200); @@ -28,7 +32,7 @@ describe('SvelteKit adapter tests - rpc handler', () => { ], }, }, - }) + }), ); expect(r.status).toBe(201); expect((await unmarshal(r)).data).toMatchObject({ @@ -48,7 +52,7 @@ describe('SvelteKit adapter tests - rpc handler', () => { expect((await unmarshal(r)).data).toHaveLength(1); r = await handler( - makeRequest('PUT', '/api/user/update', { where: { id: 'user1' }, data: { email: 'user1@def.com' } }) + makeRequest('PUT', '/api/user/update', { where: { id: 'user1' }, data: { email: 'user1@def.com' } }), ); expect(r.status).toBe(200); expect((await unmarshal(r)).data.email).toBe('user1@def.com'); @@ -62,14 +66,14 @@ describe('SvelteKit adapter tests - rpc handler', () => { expect((await unmarshal(r)).data._sum.viewCount).toBe(3); r = await handler( - makeRequest('GET', makeUrl('/api/post/groupBy', { by: ['published'], _sum: { viewCount: true } })) + makeRequest('GET', makeUrl('/api/post/groupBy', { by: ['published'], _sum: { viewCount: true } })), ); expect(r.status).toBe(200); expect((await unmarshal(r)).data).toEqual( expect.arrayContaining([ expect.objectContaining({ published: true, _sum: { viewCount: 1 } }), expect.objectContaining({ published: false, _sum: { viewCount: 2 } }), - ]) + ]), ); r = await handler(makeRequest('DELETE', makeUrl('/api/user/deleteMany', { where: { id: 'user1' } }))); @@ -97,7 +101,7 @@ describe('SvelteKit adapter tests - rest handler', () => { type: 'user', attributes: { id: 'user1', email: 'user1@abc.com' }, }, - }) + }), ); expect(r.status).toBe(201); expect(await unmarshal(r)).toMatchObject({ @@ -124,7 +128,7 @@ describe('SvelteKit adapter tests - rest handler', () => { r = await handler( makeRequest('PUT', makeUrl('/api/user/user1'), { data: { type: 'user', attributes: { email: 'user1@def.com' } }, - }) + }), ); expect(r.status).toBe(200); expect((await unmarshal(r)).data.attributes.email).toBe('user1@def.com'); diff --git a/packages/server/test/adapter/tanstack-start.test.ts b/packages/server/test/adapter/tanstack-start.test.ts new file mode 100644 index 00000000..1fb83a25 --- /dev/null +++ b/packages/server/test/adapter/tanstack-start.test.ts @@ -0,0 +1,267 @@ +import { SchemaDef } from '@zenstackhq/orm/schema'; +import { createPolicyTestClient, createTestClient } from '@zenstackhq/testtools'; +import { describe, expect, it } from 'vitest'; +import { TanStackStartHandler, TanStackStartOptions } from '../../src/adapter/tanstack-start'; +import { RestApiHandler, RPCApiHandler } from '../../src/api'; + +function makeRequest(method: string, url: string, body?: any): Request { + const payload = body ? JSON.stringify(body) : undefined; + return new Request(url, { method, body: payload }); +} + +async function unmarshal(response: Response): Promise { + const text = await response.text(); + return JSON.parse(text); +} + +interface TestClient { + get: () => Promise<{ status: number; body: any }>; + post: () => { send: (data: any) => Promise<{ status: number; body: any }> }; + put: () => { send: (data: any) => Promise<{ status: number; body: any }> }; + del: () => Promise<{ status: number; body: any }>; +} + +function makeTestClient( + apiPath: string, + options: TanStackStartOptions, + qArg?: unknown, + otherArgs?: any, +): TestClient { + const pathParts = apiPath.split('/').filter((p) => p); + const path = pathParts.join('/'); + + const handler = TanStackStartHandler(options); + + const params = { + _splat: path, + ...otherArgs, + }; + + const buildUrl = (method: string) => { + const baseUrl = `http://localhost${apiPath}`; + if (method === 'GET' || method === 'DELETE') { + const url = new URL(baseUrl); + if (qArg) { + url.searchParams.set('q', JSON.stringify(qArg)); + } + if (otherArgs) { + Object.entries(otherArgs).forEach(([key, value]) => { + url.searchParams.set(key, String(value)); + }); + } + return url.toString(); + } + return baseUrl; + }; + + const executeRequest = async (method: string, body?: any) => { + const url = buildUrl(method); + const request = makeRequest(method, url, body); + const response = await handler({ request, params }); + const responseBody = await unmarshal(response); + return { + status: response.status, + body: responseBody, + }; + }; + + return { + get: async () => executeRequest('GET'), + post: () => ({ + send: async (data: any) => executeRequest('POST', data), + }), + put: () => ({ + send: async (data: any) => executeRequest('PUT', data), + }), + del: async () => executeRequest('DELETE'), + }; +} + +describe('TanStack Start adapter tests - rpc handler', () => { + it('simple crud', async () => { + const model = ` +model M { + id String @id @default(cuid()) + value Int +} + `; + + const db = await createTestClient(model); + const options: TanStackStartOptions = { + getClient: () => db, + apiHandler: new RPCApiHandler({ schema: db.schema }), + }; + + const client = await makeTestClient('/m/create', options) + .post() + .send({ data: { id: '1', value: 1 } }); + expect(client.status).toBe(201); + expect(client.body.data.value).toBe(1); + + const findUnique = await makeTestClient('/m/findUnique', options, { where: { id: '1' } }).get(); + expect(findUnique.status).toBe(200); + expect(findUnique.body.data.value).toBe(1); + + const findFirst = await makeTestClient('/m/findFirst', options, { where: { id: '1' } }).get(); + expect(findFirst.status).toBe(200); + expect(findFirst.body.data.value).toBe(1); + + const findMany = await makeTestClient('/m/findMany', options, {}).get(); + expect(findMany.status).toBe(200); + expect(findMany.body.data).toHaveLength(1); + + const update = await makeTestClient('/m/update', options) + .put() + .send({ where: { id: '1' }, data: { value: 2 } }); + expect(update.status).toBe(200); + expect(update.body.data.value).toBe(2); + + const updateMany = await makeTestClient('/m/updateMany', options) + .put() + .send({ data: { value: 4 } }); + expect(updateMany.status).toBe(200); + expect(updateMany.body.data.count).toBe(1); + + const upsert1 = await makeTestClient('/m/upsert', options) + .post() + .send({ where: { id: '2' }, create: { id: '2', value: 2 }, update: { value: 3 } }); + expect(upsert1.status).toBe(201); + expect(upsert1.body.data.value).toBe(2); + + const upsert2 = await makeTestClient('/m/upsert', options) + .post() + .send({ where: { id: '2' }, create: { id: '2', value: 2 }, update: { value: 3 } }); + expect(upsert2.status).toBe(201); + expect(upsert2.body.data.value).toBe(3); + + const count1 = await makeTestClient('/m/count', options, { where: { id: '1' } }).get(); + expect(count1.status).toBe(200); + expect(count1.body.data).toBe(1); + + const count2 = await makeTestClient('/m/count', options, {}).get(); + expect(count2.status).toBe(200); + expect(count2.body.data).toBe(2); + + const aggregate = await makeTestClient('/m/aggregate', options, { _sum: { value: true } }).get(); + expect(aggregate.status).toBe(200); + expect(aggregate.body.data._sum.value).toBe(7); + + const groupBy = await makeTestClient('/m/groupBy', options, { by: ['id'], _sum: { value: true } }).get(); + expect(groupBy.status).toBe(200); + const data = groupBy.body.data; + expect(data).toHaveLength(2); + expect(data.find((item: any) => item.id === '1')._sum.value).toBe(4); + expect(data.find((item: any) => item.id === '2')._sum.value).toBe(3); + + const deleteOne = await makeTestClient('/m/delete', options, { where: { id: '1' } }).del(); + expect(deleteOne.status).toBe(200); + expect(await db.m.count()).toBe(1); + + const deleteMany = await makeTestClient('/m/deleteMany', options, {}).del(); + expect(deleteMany.status).toBe(200); + expect(deleteMany.body.data.count).toBe(1); + expect(await db.m.count()).toBe(0); + }); + + it('access policy crud', async () => { + const model = ` +model M { + id String @id @default(cuid()) + value Int + + @@allow('create,update', true) + @@allow('read', value > 0) + @@allow('post-update', value > 1) + @@allow('delete', value > 2) +} + `; + + const db = await createPolicyTestClient(model); + const options: TanStackStartOptions = { + getClient: () => db, + apiHandler: new RPCApiHandler({ schema: db.schema }), + }; + + const createForbidden = await makeTestClient('/m/create', options) + .post() + .send({ data: { value: 0 } }); + expect(createForbidden.status).toBe(403); + expect(createForbidden.body.error.rejectReason).toBe('cannot-read-back'); + + const create = await makeTestClient('/m/create', options) + .post() + .send({ data: { id: '1', value: 1 } }); + expect(create.status).toBe(201); + + const findMany = await makeTestClient('/m/findMany', options).get(); + expect(findMany.status).toBe(200); + expect(findMany.body.data).toHaveLength(1); + + const updateForbidden1 = await makeTestClient('/m/update', options) + .put() + .send({ where: { id: '1' }, data: { value: 0 } }); + expect(updateForbidden1.status).toBe(403); + + const update1 = await makeTestClient('/m/update', options) + .put() + .send({ where: { id: '1' }, data: { value: 2 } }); + expect(update1.status).toBe(200); + + const deleteForbidden = await makeTestClient('/m/delete', options, { where: { id: '1' } }).del(); + expect(deleteForbidden.status).toBe(404); + + const update2 = await makeTestClient('/m/update', options) + .put() + .send({ where: { id: '1' }, data: { value: 3 } }); + expect(update2.status).toBe(200); + + const deleteOne = await makeTestClient('/m/delete', options, { where: { id: '1' } }).del(); + expect(deleteOne.status).toBe(200); + }); +}); + +describe('TanStack Start adapter tests - rest handler', () => { + it('properly handles requests', async () => { + const model = ` +model M { + id String @id @default(cuid()) + value Int +} + `; + + const db = await createTestClient(model); + + const options: TanStackStartOptions = { + getClient: () => db, + apiHandler: new RestApiHandler({ endpoint: 'http://localhost/api', schema: db.schema }), + }; + + const create = await makeTestClient('/m', options) + .post() + .send({ data: { type: 'm', attributes: { id: '1', value: 1 } } }); + expect(create.status).toBe(201); + expect(create.body.data.attributes.value).toBe(1); + + const getOne = await makeTestClient('/m/1', options).get(); + expect(getOne.status).toBe(200); + expect(getOne.body.data.id).toBe('1'); + + const findWithFilter1 = await makeTestClient('/m', options, undefined, { 'filter[value]': '1' }).get(); + expect(findWithFilter1.status).toBe(200); + expect(findWithFilter1.body.data).toHaveLength(1); + + const findWithFilter2 = await makeTestClient('/m', options, undefined, { 'filter[value]': '2' }).get(); + expect(findWithFilter2.status).toBe(200); + expect(findWithFilter2.body.data).toHaveLength(0); + + const update = await makeTestClient('/m/1', options) + .put() + .send({ data: { type: 'm', attributes: { value: 2 } } }); + expect(update.status).toBe(200); + expect(update.body.data.attributes.value).toBe(2); + + const deleteOne = await makeTestClient('/m/1', options).del(); + expect(deleteOne.status).toBe(200); + expect(await db.m.count()).toBe(0); + }); +}); diff --git a/packages/server/tsup.config.ts b/packages/server/tsup.config.ts index fcce984c..4c236d2f 100644 --- a/packages/server/tsup.config.ts +++ b/packages/server/tsup.config.ts @@ -10,6 +10,7 @@ export default defineConfig({ nuxt: 'src/adapter/nuxt/index.ts', hono: 'src/adapter/hono/index.ts', sveltekit: 'src/adapter/sveltekit/index.ts', + 'tanstack-start': 'src/adapter/tanstack-start/index.ts', }, outDir: 'dist', splitting: false, diff --git a/tests/e2e/orm/schemas/basic/input.ts b/tests/e2e/orm/schemas/basic/input.ts index 70de8c2e..b36565a2 100644 --- a/tests/e2e/orm/schemas/basic/input.ts +++ b/tests/e2e/orm/schemas/basic/input.ts @@ -5,86 +5,125 @@ /* eslint-disable */ -import { type SchemaType as $Schema } from "./schema"; -import type { FindManyArgs as $FindManyArgs, FindUniqueArgs as $FindUniqueArgs, FindFirstArgs as $FindFirstArgs, CreateArgs as $CreateArgs, CreateManyArgs as $CreateManyArgs, CreateManyAndReturnArgs as $CreateManyAndReturnArgs, UpdateArgs as $UpdateArgs, UpdateManyArgs as $UpdateManyArgs, UpdateManyAndReturnArgs as $UpdateManyAndReturnArgs, UpsertArgs as $UpsertArgs, DeleteArgs as $DeleteArgs, DeleteManyArgs as $DeleteManyArgs, CountArgs as $CountArgs, AggregateArgs as $AggregateArgs, GroupByArgs as $GroupByArgs, WhereInput as $WhereInput, SelectInput as $SelectInput, IncludeInput as $IncludeInput, OmitInput as $OmitInput } from "@zenstackhq/orm"; -import type { SimplifiedModelResult as $SimplifiedModelResult, SelectIncludeOmit as $SelectIncludeOmit } from "@zenstackhq/orm"; -export type UserFindManyArgs = $FindManyArgs<$Schema, "User">; -export type UserFindUniqueArgs = $FindUniqueArgs<$Schema, "User">; -export type UserFindFirstArgs = $FindFirstArgs<$Schema, "User">; -export type UserCreateArgs = $CreateArgs<$Schema, "User">; -export type UserCreateManyArgs = $CreateManyArgs<$Schema, "User">; -export type UserCreateManyAndReturnArgs = $CreateManyAndReturnArgs<$Schema, "User">; -export type UserUpdateArgs = $UpdateArgs<$Schema, "User">; -export type UserUpdateManyArgs = $UpdateManyArgs<$Schema, "User">; -export type UserUpdateManyAndReturnArgs = $UpdateManyAndReturnArgs<$Schema, "User">; -export type UserUpsertArgs = $UpsertArgs<$Schema, "User">; -export type UserDeleteArgs = $DeleteArgs<$Schema, "User">; -export type UserDeleteManyArgs = $DeleteManyArgs<$Schema, "User">; -export type UserCountArgs = $CountArgs<$Schema, "User">; -export type UserAggregateArgs = $AggregateArgs<$Schema, "User">; -export type UserGroupByArgs = $GroupByArgs<$Schema, "User">; -export type UserWhereInput = $WhereInput<$Schema, "User">; -export type UserSelect = $SelectInput<$Schema, "User">; -export type UserInclude = $IncludeInput<$Schema, "User">; -export type UserOmit = $OmitInput<$Schema, "User">; -export type UserGetPayload> = $SimplifiedModelResult<$Schema, "User", Args>; -export type PostFindManyArgs = $FindManyArgs<$Schema, "Post">; -export type PostFindUniqueArgs = $FindUniqueArgs<$Schema, "Post">; -export type PostFindFirstArgs = $FindFirstArgs<$Schema, "Post">; -export type PostCreateArgs = $CreateArgs<$Schema, "Post">; -export type PostCreateManyArgs = $CreateManyArgs<$Schema, "Post">; -export type PostCreateManyAndReturnArgs = $CreateManyAndReturnArgs<$Schema, "Post">; -export type PostUpdateArgs = $UpdateArgs<$Schema, "Post">; -export type PostUpdateManyArgs = $UpdateManyArgs<$Schema, "Post">; -export type PostUpdateManyAndReturnArgs = $UpdateManyAndReturnArgs<$Schema, "Post">; -export type PostUpsertArgs = $UpsertArgs<$Schema, "Post">; -export type PostDeleteArgs = $DeleteArgs<$Schema, "Post">; -export type PostDeleteManyArgs = $DeleteManyArgs<$Schema, "Post">; -export type PostCountArgs = $CountArgs<$Schema, "Post">; -export type PostAggregateArgs = $AggregateArgs<$Schema, "Post">; -export type PostGroupByArgs = $GroupByArgs<$Schema, "Post">; -export type PostWhereInput = $WhereInput<$Schema, "Post">; -export type PostSelect = $SelectInput<$Schema, "Post">; -export type PostInclude = $IncludeInput<$Schema, "Post">; -export type PostOmit = $OmitInput<$Schema, "Post">; -export type PostGetPayload> = $SimplifiedModelResult<$Schema, "Post", Args>; -export type CommentFindManyArgs = $FindManyArgs<$Schema, "Comment">; -export type CommentFindUniqueArgs = $FindUniqueArgs<$Schema, "Comment">; -export type CommentFindFirstArgs = $FindFirstArgs<$Schema, "Comment">; -export type CommentCreateArgs = $CreateArgs<$Schema, "Comment">; -export type CommentCreateManyArgs = $CreateManyArgs<$Schema, "Comment">; -export type CommentCreateManyAndReturnArgs = $CreateManyAndReturnArgs<$Schema, "Comment">; -export type CommentUpdateArgs = $UpdateArgs<$Schema, "Comment">; -export type CommentUpdateManyArgs = $UpdateManyArgs<$Schema, "Comment">; -export type CommentUpdateManyAndReturnArgs = $UpdateManyAndReturnArgs<$Schema, "Comment">; -export type CommentUpsertArgs = $UpsertArgs<$Schema, "Comment">; -export type CommentDeleteArgs = $DeleteArgs<$Schema, "Comment">; -export type CommentDeleteManyArgs = $DeleteManyArgs<$Schema, "Comment">; -export type CommentCountArgs = $CountArgs<$Schema, "Comment">; -export type CommentAggregateArgs = $AggregateArgs<$Schema, "Comment">; -export type CommentGroupByArgs = $GroupByArgs<$Schema, "Comment">; -export type CommentWhereInput = $WhereInput<$Schema, "Comment">; -export type CommentSelect = $SelectInput<$Schema, "Comment">; -export type CommentInclude = $IncludeInput<$Schema, "Comment">; -export type CommentOmit = $OmitInput<$Schema, "Comment">; -export type CommentGetPayload> = $SimplifiedModelResult<$Schema, "Comment", Args>; -export type ProfileFindManyArgs = $FindManyArgs<$Schema, "Profile">; -export type ProfileFindUniqueArgs = $FindUniqueArgs<$Schema, "Profile">; -export type ProfileFindFirstArgs = $FindFirstArgs<$Schema, "Profile">; -export type ProfileCreateArgs = $CreateArgs<$Schema, "Profile">; -export type ProfileCreateManyArgs = $CreateManyArgs<$Schema, "Profile">; -export type ProfileCreateManyAndReturnArgs = $CreateManyAndReturnArgs<$Schema, "Profile">; -export type ProfileUpdateArgs = $UpdateArgs<$Schema, "Profile">; -export type ProfileUpdateManyArgs = $UpdateManyArgs<$Schema, "Profile">; -export type ProfileUpdateManyAndReturnArgs = $UpdateManyAndReturnArgs<$Schema, "Profile">; -export type ProfileUpsertArgs = $UpsertArgs<$Schema, "Profile">; -export type ProfileDeleteArgs = $DeleteArgs<$Schema, "Profile">; -export type ProfileDeleteManyArgs = $DeleteManyArgs<$Schema, "Profile">; -export type ProfileCountArgs = $CountArgs<$Schema, "Profile">; -export type ProfileAggregateArgs = $AggregateArgs<$Schema, "Profile">; -export type ProfileGroupByArgs = $GroupByArgs<$Schema, "Profile">; -export type ProfileWhereInput = $WhereInput<$Schema, "Profile">; -export type ProfileSelect = $SelectInput<$Schema, "Profile">; -export type ProfileInclude = $IncludeInput<$Schema, "Profile">; -export type ProfileOmit = $OmitInput<$Schema, "Profile">; -export type ProfileGetPayload> = $SimplifiedModelResult<$Schema, "Profile", Args>; +import { type SchemaType as $Schema } from './schema'; +import type { + FindManyArgs as $FindManyArgs, + FindUniqueArgs as $FindUniqueArgs, + FindFirstArgs as $FindFirstArgs, + CreateArgs as $CreateArgs, + CreateManyArgs as $CreateManyArgs, + CreateManyAndReturnArgs as $CreateManyAndReturnArgs, + UpdateArgs as $UpdateArgs, + UpdateManyArgs as $UpdateManyArgs, + UpdateManyAndReturnArgs as $UpdateManyAndReturnArgs, + UpsertArgs as $UpsertArgs, + DeleteArgs as $DeleteArgs, + DeleteManyArgs as $DeleteManyArgs, + CountArgs as $CountArgs, + AggregateArgs as $AggregateArgs, + GroupByArgs as $GroupByArgs, + WhereInput as $WhereInput, + SelectInput as $SelectInput, + IncludeInput as $IncludeInput, + OmitInput as $OmitInput, +} from '@zenstackhq/orm'; +import type { + SimplifiedModelResult as $SimplifiedModelResult, + SelectIncludeOmit as $SelectIncludeOmit, +} from '@zenstackhq/orm'; +export type UserFindManyArgs = $FindManyArgs<$Schema, 'User'>; +export type UserFindUniqueArgs = $FindUniqueArgs<$Schema, 'User'>; +export type UserFindFirstArgs = $FindFirstArgs<$Schema, 'User'>; +export type UserCreateArgs = $CreateArgs<$Schema, 'User'>; +export type UserCreateManyArgs = $CreateManyArgs<$Schema, 'User'>; +export type UserCreateManyAndReturnArgs = $CreateManyAndReturnArgs<$Schema, 'User'>; +export type UserUpdateArgs = $UpdateArgs<$Schema, 'User'>; +export type UserUpdateManyArgs = $UpdateManyArgs<$Schema, 'User'>; +export type UserUpdateManyAndReturnArgs = $UpdateManyAndReturnArgs<$Schema, 'User'>; +export type UserUpsertArgs = $UpsertArgs<$Schema, 'User'>; +export type UserDeleteArgs = $DeleteArgs<$Schema, 'User'>; +export type UserDeleteManyArgs = $DeleteManyArgs<$Schema, 'User'>; +export type UserCountArgs = $CountArgs<$Schema, 'User'>; +export type UserAggregateArgs = $AggregateArgs<$Schema, 'User'>; +export type UserGroupByArgs = $GroupByArgs<$Schema, 'User'>; +export type UserWhereInput = $WhereInput<$Schema, 'User'>; +export type UserSelect = $SelectInput<$Schema, 'User'>; +export type UserInclude = $IncludeInput<$Schema, 'User'>; +export type UserOmit = $OmitInput<$Schema, 'User'>; +export type UserGetPayload> = $SimplifiedModelResult< + $Schema, + 'User', + Args +>; +export type PostFindManyArgs = $FindManyArgs<$Schema, 'Post'>; +export type PostFindUniqueArgs = $FindUniqueArgs<$Schema, 'Post'>; +export type PostFindFirstArgs = $FindFirstArgs<$Schema, 'Post'>; +export type PostCreateArgs = $CreateArgs<$Schema, 'Post'>; +export type PostCreateManyArgs = $CreateManyArgs<$Schema, 'Post'>; +export type PostCreateManyAndReturnArgs = $CreateManyAndReturnArgs<$Schema, 'Post'>; +export type PostUpdateArgs = $UpdateArgs<$Schema, 'Post'>; +export type PostUpdateManyArgs = $UpdateManyArgs<$Schema, 'Post'>; +export type PostUpdateManyAndReturnArgs = $UpdateManyAndReturnArgs<$Schema, 'Post'>; +export type PostUpsertArgs = $UpsertArgs<$Schema, 'Post'>; +export type PostDeleteArgs = $DeleteArgs<$Schema, 'Post'>; +export type PostDeleteManyArgs = $DeleteManyArgs<$Schema, 'Post'>; +export type PostCountArgs = $CountArgs<$Schema, 'Post'>; +export type PostAggregateArgs = $AggregateArgs<$Schema, 'Post'>; +export type PostGroupByArgs = $GroupByArgs<$Schema, 'Post'>; +export type PostWhereInput = $WhereInput<$Schema, 'Post'>; +export type PostSelect = $SelectInput<$Schema, 'Post'>; +export type PostInclude = $IncludeInput<$Schema, 'Post'>; +export type PostOmit = $OmitInput<$Schema, 'Post'>; +export type PostGetPayload> = $SimplifiedModelResult< + $Schema, + 'Post', + Args +>; +export type CommentFindManyArgs = $FindManyArgs<$Schema, 'Comment'>; +export type CommentFindUniqueArgs = $FindUniqueArgs<$Schema, 'Comment'>; +export type CommentFindFirstArgs = $FindFirstArgs<$Schema, 'Comment'>; +export type CommentCreateArgs = $CreateArgs<$Schema, 'Comment'>; +export type CommentCreateManyArgs = $CreateManyArgs<$Schema, 'Comment'>; +export type CommentCreateManyAndReturnArgs = $CreateManyAndReturnArgs<$Schema, 'Comment'>; +export type CommentUpdateArgs = $UpdateArgs<$Schema, 'Comment'>; +export type CommentUpdateManyArgs = $UpdateManyArgs<$Schema, 'Comment'>; +export type CommentUpdateManyAndReturnArgs = $UpdateManyAndReturnArgs<$Schema, 'Comment'>; +export type CommentUpsertArgs = $UpsertArgs<$Schema, 'Comment'>; +export type CommentDeleteArgs = $DeleteArgs<$Schema, 'Comment'>; +export type CommentDeleteManyArgs = $DeleteManyArgs<$Schema, 'Comment'>; +export type CommentCountArgs = $CountArgs<$Schema, 'Comment'>; +export type CommentAggregateArgs = $AggregateArgs<$Schema, 'Comment'>; +export type CommentGroupByArgs = $GroupByArgs<$Schema, 'Comment'>; +export type CommentWhereInput = $WhereInput<$Schema, 'Comment'>; +export type CommentSelect = $SelectInput<$Schema, 'Comment'>; +export type CommentInclude = $IncludeInput<$Schema, 'Comment'>; +export type CommentOmit = $OmitInput<$Schema, 'Comment'>; +export type CommentGetPayload> = $SimplifiedModelResult< + $Schema, + 'Comment', + Args +>; +export type ProfileFindManyArgs = $FindManyArgs<$Schema, 'Profile'>; +export type ProfileFindUniqueArgs = $FindUniqueArgs<$Schema, 'Profile'>; +export type ProfileFindFirstArgs = $FindFirstArgs<$Schema, 'Profile'>; +export type ProfileCreateArgs = $CreateArgs<$Schema, 'Profile'>; +export type ProfileCreateManyArgs = $CreateManyArgs<$Schema, 'Profile'>; +export type ProfileCreateManyAndReturnArgs = $CreateManyAndReturnArgs<$Schema, 'Profile'>; +export type ProfileUpdateArgs = $UpdateArgs<$Schema, 'Profile'>; +export type ProfileUpdateManyArgs = $UpdateManyArgs<$Schema, 'Profile'>; +export type ProfileUpdateManyAndReturnArgs = $UpdateManyAndReturnArgs<$Schema, 'Profile'>; +export type ProfileUpsertArgs = $UpsertArgs<$Schema, 'Profile'>; +export type ProfileDeleteArgs = $DeleteArgs<$Schema, 'Profile'>; +export type ProfileDeleteManyArgs = $DeleteManyArgs<$Schema, 'Profile'>; +export type ProfileCountArgs = $CountArgs<$Schema, 'Profile'>; +export type ProfileAggregateArgs = $AggregateArgs<$Schema, 'Profile'>; +export type ProfileGroupByArgs = $GroupByArgs<$Schema, 'Profile'>; +export type ProfileWhereInput = $WhereInput<$Schema, 'Profile'>; +export type ProfileSelect = $SelectInput<$Schema, 'Profile'>; +export type ProfileInclude = $IncludeInput<$Schema, 'Profile'>; +export type ProfileOmit = $OmitInput<$Schema, 'Profile'>; +export type ProfileGetPayload> = $SimplifiedModelResult< + $Schema, + 'Profile', + Args +>; diff --git a/tests/e2e/orm/schemas/basic/models.ts b/tests/e2e/orm/schemas/basic/models.ts index d532d7d4..64d667b7 100644 --- a/tests/e2e/orm/schemas/basic/models.ts +++ b/tests/e2e/orm/schemas/basic/models.ts @@ -5,12 +5,12 @@ /* eslint-disable */ -import { schema as $schema, type SchemaType as $Schema } from "./schema"; -import { type ModelResult as $ModelResult, type TypeDefResult as $TypeDefResult } from "@zenstackhq/orm"; -export type User = $ModelResult<$Schema, "User">; -export type Post = $ModelResult<$Schema, "Post">; -export type Comment = $ModelResult<$Schema, "Comment">; -export type Profile = $ModelResult<$Schema, "Profile">; -export type CommonFields = $TypeDefResult<$Schema, "CommonFields">; +import { schema as $schema, type SchemaType as $Schema } from './schema'; +import { type ModelResult as $ModelResult, type TypeDefResult as $TypeDefResult } from '@zenstackhq/orm'; +export type User = $ModelResult<$Schema, 'User'>; +export type Post = $ModelResult<$Schema, 'Post'>; +export type Comment = $ModelResult<$Schema, 'Comment'>; +export type Profile = $ModelResult<$Schema, 'Profile'>; +export type CommonFields = $TypeDefResult<$Schema, 'CommonFields'>; export const Role = $schema.enums.Role; export type Role = (typeof Role)[keyof typeof Role]; diff --git a/tests/e2e/orm/schemas/basic/schema.ts b/tests/e2e/orm/schemas/basic/schema.ts index 14e627b9..1816323a 100644 --- a/tests/e2e/orm/schemas/basic/schema.ts +++ b/tests/e2e/orm/schemas/basic/schema.ts @@ -5,281 +5,392 @@ /* eslint-disable */ -import { type SchemaDef, ExpressionUtils } from "@zenstackhq/orm/schema"; +import { type SchemaDef, ExpressionUtils } from '@zenstackhq/orm/schema'; export const schema = { provider: { - type: "sqlite" + type: 'sqlite', }, models: { User: { - name: "User", + name: 'User', fields: { id: { - name: "id", - type: "String", + name: 'id', + type: 'String', id: true, - attributes: [{ name: "@id" }, { name: "@default", args: [{ name: "value", value: ExpressionUtils.call("cuid") }] }], - default: ExpressionUtils.call("cuid") + 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") + name: 'createdAt', + type: 'DateTime', + attributes: [{ name: '@default', args: [{ name: 'value', value: ExpressionUtils.call('now') }] }], + default: ExpressionUtils.call('now'), }, updatedAt: { - name: "updatedAt", - type: "DateTime", + name: 'updatedAt', + type: 'DateTime', updatedAt: true, - attributes: [{ name: "@updatedAt" }] + attributes: [{ name: '@updatedAt' }], }, email: { - name: "email", - type: "String", + name: 'email', + type: 'String', unique: true, - attributes: [{ name: "@unique" }] + attributes: [{ name: '@unique' }], }, name: { - name: "name", - type: "String", - optional: true + name: 'name', + type: 'String', + optional: true, }, role: { - name: "role", - type: "Role", - attributes: [{ name: "@default", args: [{ name: "value", value: ExpressionUtils.literal("USER") }] }], - default: "USER" + name: 'role', + type: 'Role', + attributes: [ + { name: '@default', args: [{ name: 'value', value: ExpressionUtils.literal('USER') }] }, + ], + default: 'USER', }, posts: { - name: "posts", - type: "Post", + name: 'posts', + type: 'Post', array: true, - relation: { opposite: "author" } + relation: { opposite: 'author' }, }, profile: { - name: "profile", - type: "Profile", + name: 'profile', + type: 'Profile', optional: true, - relation: { opposite: "user" } + relation: { opposite: 'user' }, }, meta: { - name: "meta", - type: "Json", - optional: true - } + name: 'meta', + type: 'Json', + optional: true, + }, }, attributes: [ - { name: "@@allow", args: [{ name: "operation", value: ExpressionUtils.literal("all") }, { name: "condition", value: ExpressionUtils.binary(ExpressionUtils.member(ExpressionUtils.call("auth"), ["id"]), "==", ExpressionUtils.field("id")) }] }, - { name: "@@allow", args: [{ name: "operation", value: ExpressionUtils.literal("read") }, { name: "condition", value: ExpressionUtils.binary(ExpressionUtils.call("auth"), "!=", ExpressionUtils._null()) }] } + { + name: '@@allow', + args: [ + { name: 'operation', value: ExpressionUtils.literal('all') }, + { + name: 'condition', + value: ExpressionUtils.binary( + ExpressionUtils.member(ExpressionUtils.call('auth'), ['id']), + '==', + ExpressionUtils.field('id'), + ), + }, + ], + }, + { + name: '@@allow', + args: [ + { name: 'operation', value: ExpressionUtils.literal('read') }, + { + name: 'condition', + value: ExpressionUtils.binary(ExpressionUtils.call('auth'), '!=', ExpressionUtils._null()), + }, + ], + }, ], - idFields: ["id"], + idFields: ['id'], uniqueFields: { - id: { type: "String" }, - email: { type: "String" } - } + id: { type: 'String' }, + email: { type: 'String' }, + }, }, Post: { - name: "Post", + name: 'Post', fields: { id: { - name: "id", - type: "String", + name: 'id', + type: 'String', id: true, - attributes: [{ name: "@id" }, { name: "@default", args: [{ name: "value", value: ExpressionUtils.call("cuid") }] }], - default: ExpressionUtils.call("cuid") + 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") + name: 'createdAt', + type: 'DateTime', + attributes: [{ name: '@default', args: [{ name: 'value', value: ExpressionUtils.call('now') }] }], + default: ExpressionUtils.call('now'), }, updatedAt: { - name: "updatedAt", - type: "DateTime", + name: 'updatedAt', + type: 'DateTime', updatedAt: true, - attributes: [{ name: "@updatedAt" }] + attributes: [{ name: '@updatedAt' }], }, title: { - name: "title", - type: "String" + name: 'title', + type: 'String', }, content: { - name: "content", - type: "String", - optional: true + name: 'content', + type: 'String', + optional: true, }, published: { - name: "published", - type: "Boolean", - attributes: [{ name: "@default", args: [{ name: "value", value: ExpressionUtils.literal(false) }] }], - default: false + name: 'published', + type: 'Boolean', + attributes: [ + { name: '@default', args: [{ name: 'value', value: ExpressionUtils.literal(false) }] }, + ], + default: false, }, author: { - name: "author", - type: "User", - attributes: [{ name: "@relation", args: [{ name: "fields", value: ExpressionUtils.array([ExpressionUtils.field("authorId")]) }, { name: "references", value: ExpressionUtils.array([ExpressionUtils.field("id")]) }, { name: "onUpdate", value: ExpressionUtils.literal("Cascade") }, { name: "onDelete", value: ExpressionUtils.literal("Cascade") }] }], - relation: { opposite: "posts", fields: ["authorId"], references: ["id"], onUpdate: "Cascade", onDelete: "Cascade" } + name: 'author', + type: 'User', + attributes: [ + { + name: '@relation', + args: [ + { name: 'fields', value: ExpressionUtils.array([ExpressionUtils.field('authorId')]) }, + { name: 'references', value: ExpressionUtils.array([ExpressionUtils.field('id')]) }, + { name: 'onUpdate', value: ExpressionUtils.literal('Cascade') }, + { name: 'onDelete', value: ExpressionUtils.literal('Cascade') }, + ], + }, + ], + relation: { + opposite: 'posts', + fields: ['authorId'], + references: ['id'], + onUpdate: 'Cascade', + onDelete: 'Cascade', + }, }, authorId: { - name: "authorId", - type: "String", - foreignKeyFor: [ - "author" - ] + name: 'authorId', + type: 'String', + foreignKeyFor: ['author'], }, comments: { - name: "comments", - type: "Comment", + name: 'comments', + type: 'Comment', array: true, - relation: { opposite: "post" } - } + relation: { opposite: 'post' }, + }, }, attributes: [ - { name: "@@deny", args: [{ name: "operation", value: ExpressionUtils.literal("all") }, { name: "condition", value: ExpressionUtils.binary(ExpressionUtils.call("auth"), "==", ExpressionUtils._null()) }] }, - { name: "@@allow", args: [{ name: "operation", value: ExpressionUtils.literal("all") }, { name: "condition", value: ExpressionUtils.binary(ExpressionUtils.member(ExpressionUtils.call("auth"), ["id"]), "==", ExpressionUtils.field("authorId")) }] }, - { name: "@@allow", args: [{ name: "operation", value: ExpressionUtils.literal("read") }, { name: "condition", value: ExpressionUtils.field("published") }] } + { + name: '@@deny', + args: [ + { name: 'operation', value: ExpressionUtils.literal('all') }, + { + name: 'condition', + value: ExpressionUtils.binary(ExpressionUtils.call('auth'), '==', ExpressionUtils._null()), + }, + ], + }, + { + name: '@@allow', + args: [ + { name: 'operation', value: ExpressionUtils.literal('all') }, + { + name: 'condition', + value: ExpressionUtils.binary( + ExpressionUtils.member(ExpressionUtils.call('auth'), ['id']), + '==', + ExpressionUtils.field('authorId'), + ), + }, + ], + }, + { + name: '@@allow', + args: [ + { name: 'operation', value: ExpressionUtils.literal('read') }, + { name: 'condition', value: ExpressionUtils.field('published') }, + ], + }, ], - idFields: ["id"], + idFields: ['id'], uniqueFields: { - id: { type: "String" } - } + id: { type: 'String' }, + }, }, Comment: { - name: "Comment", + name: 'Comment', fields: { id: { - name: "id", - type: "String", + name: 'id', + type: 'String', id: true, - attributes: [{ name: "@id" }, { name: "@default", args: [{ name: "value", value: ExpressionUtils.call("cuid") }] }], - default: ExpressionUtils.call("cuid") + 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") + name: 'createdAt', + type: 'DateTime', + attributes: [{ name: '@default', args: [{ name: 'value', value: ExpressionUtils.call('now') }] }], + default: ExpressionUtils.call('now'), }, updatedAt: { - name: "updatedAt", - type: "DateTime", + name: 'updatedAt', + type: 'DateTime', updatedAt: true, - attributes: [{ name: "@updatedAt" }] + attributes: [{ name: '@updatedAt' }], }, content: { - name: "content", - type: "String" + name: 'content', + type: 'String', }, post: { - name: "post", - type: "Post", + name: 'post', + type: 'Post', optional: true, - attributes: [{ name: "@relation", args: [{ name: "fields", value: ExpressionUtils.array([ExpressionUtils.field("postId")]) }, { name: "references", value: ExpressionUtils.array([ExpressionUtils.field("id")]) }, { name: "onUpdate", value: ExpressionUtils.literal("Cascade") }, { name: "onDelete", value: ExpressionUtils.literal("Cascade") }] }], - relation: { opposite: "comments", fields: ["postId"], references: ["id"], onUpdate: "Cascade", onDelete: "Cascade" } + attributes: [ + { + name: '@relation', + args: [ + { name: 'fields', value: ExpressionUtils.array([ExpressionUtils.field('postId')]) }, + { name: 'references', value: ExpressionUtils.array([ExpressionUtils.field('id')]) }, + { name: 'onUpdate', value: ExpressionUtils.literal('Cascade') }, + { name: 'onDelete', value: ExpressionUtils.literal('Cascade') }, + ], + }, + ], + relation: { + opposite: 'comments', + fields: ['postId'], + references: ['id'], + onUpdate: 'Cascade', + onDelete: 'Cascade', + }, }, postId: { - name: "postId", - type: "String", + name: 'postId', + type: 'String', optional: true, - foreignKeyFor: [ - "post" - ] - } + foreignKeyFor: ['post'], + }, }, - idFields: ["id"], + idFields: ['id'], uniqueFields: { - id: { type: "String" } - } + id: { type: 'String' }, + }, }, Profile: { - name: "Profile", + name: 'Profile', fields: { id: { - name: "id", - type: "String", + name: 'id', + type: 'String', id: true, - attributes: [{ name: "@id" }, { name: "@default", args: [{ name: "value", value: ExpressionUtils.call("cuid") }] }], - default: ExpressionUtils.call("cuid") + 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") + name: 'createdAt', + type: 'DateTime', + attributes: [{ name: '@default', args: [{ name: 'value', value: ExpressionUtils.call('now') }] }], + default: ExpressionUtils.call('now'), }, updatedAt: { - name: "updatedAt", - type: "DateTime", + name: 'updatedAt', + type: 'DateTime', updatedAt: true, - attributes: [{ name: "@updatedAt" }] + attributes: [{ name: '@updatedAt' }], }, bio: { - name: "bio", - type: "String" + name: 'bio', + type: 'String', }, age: { - name: "age", - type: "Int", - optional: true + name: 'age', + type: 'Int', + optional: true, }, user: { - name: "user", - type: "User", + name: 'user', + type: 'User', optional: true, - attributes: [{ name: "@relation", args: [{ name: "fields", value: ExpressionUtils.array([ExpressionUtils.field("userId")]) }, { name: "references", value: ExpressionUtils.array([ExpressionUtils.field("id")]) }, { name: "onUpdate", value: ExpressionUtils.literal("Cascade") }, { name: "onDelete", value: ExpressionUtils.literal("Cascade") }] }], - relation: { opposite: "profile", fields: ["userId"], references: ["id"], onUpdate: "Cascade", onDelete: "Cascade" } + attributes: [ + { + name: '@relation', + args: [ + { name: 'fields', value: ExpressionUtils.array([ExpressionUtils.field('userId')]) }, + { name: 'references', value: ExpressionUtils.array([ExpressionUtils.field('id')]) }, + { name: 'onUpdate', value: ExpressionUtils.literal('Cascade') }, + { name: 'onDelete', value: ExpressionUtils.literal('Cascade') }, + ], + }, + ], + relation: { + opposite: 'profile', + fields: ['userId'], + references: ['id'], + onUpdate: 'Cascade', + onDelete: 'Cascade', + }, }, userId: { - name: "userId", - type: "String", + name: 'userId', + type: 'String', unique: true, optional: true, - attributes: [{ name: "@unique" }], - foreignKeyFor: [ - "user" - ] - } + attributes: [{ name: '@unique' }], + foreignKeyFor: ['user'], + }, }, - idFields: ["id"], + idFields: ['id'], uniqueFields: { - id: { type: "String" }, - userId: { type: "String" } - } - } + id: { type: 'String' }, + userId: { type: 'String' }, + }, + }, }, typeDefs: { CommonFields: { - name: "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") + 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") + name: 'createdAt', + type: 'DateTime', + attributes: [{ name: '@default', args: [{ name: 'value', value: ExpressionUtils.call('now') }] }], + default: ExpressionUtils.call('now'), }, updatedAt: { - name: "updatedAt", - type: "DateTime", + name: 'updatedAt', + type: 'DateTime', updatedAt: true, - attributes: [{ name: "@updatedAt" }] - } - } - } + attributes: [{ name: '@updatedAt' }], + }, + }, + }, }, enums: { Role: { - ADMIN: "ADMIN", - USER: "USER" - } + ADMIN: 'ADMIN', + USER: 'USER', + }, }, - authType: "User", - plugins: {} + authType: 'User', + plugins: {}, } as const satisfies SchemaDef; export type SchemaType = typeof schema; diff --git a/tests/e2e/orm/schemas/delegate/input.ts b/tests/e2e/orm/schemas/delegate/input.ts index 1d43c413..cbb5a808 100644 --- a/tests/e2e/orm/schemas/delegate/input.ts +++ b/tests/e2e/orm/schemas/delegate/input.ts @@ -5,146 +5,197 @@ /* eslint-disable */ -import { type SchemaType as $Schema } from "./schema"; -import type { FindManyArgs as $FindManyArgs, FindUniqueArgs as $FindUniqueArgs, FindFirstArgs as $FindFirstArgs, CreateArgs as $CreateArgs, CreateManyArgs as $CreateManyArgs, CreateManyAndReturnArgs as $CreateManyAndReturnArgs, UpdateArgs as $UpdateArgs, UpdateManyArgs as $UpdateManyArgs, UpdateManyAndReturnArgs as $UpdateManyAndReturnArgs, UpsertArgs as $UpsertArgs, DeleteArgs as $DeleteArgs, DeleteManyArgs as $DeleteManyArgs, CountArgs as $CountArgs, AggregateArgs as $AggregateArgs, GroupByArgs as $GroupByArgs, WhereInput as $WhereInput, SelectInput as $SelectInput, IncludeInput as $IncludeInput, OmitInput as $OmitInput } from "@zenstackhq/orm"; -import type { SimplifiedModelResult as $SimplifiedModelResult, SelectIncludeOmit as $SelectIncludeOmit } from "@zenstackhq/orm"; -export type UserFindManyArgs = $FindManyArgs<$Schema, "User">; -export type UserFindUniqueArgs = $FindUniqueArgs<$Schema, "User">; -export type UserFindFirstArgs = $FindFirstArgs<$Schema, "User">; -export type UserCreateArgs = $CreateArgs<$Schema, "User">; -export type UserCreateManyArgs = $CreateManyArgs<$Schema, "User">; -export type UserCreateManyAndReturnArgs = $CreateManyAndReturnArgs<$Schema, "User">; -export type UserUpdateArgs = $UpdateArgs<$Schema, "User">; -export type UserUpdateManyArgs = $UpdateManyArgs<$Schema, "User">; -export type UserUpdateManyAndReturnArgs = $UpdateManyAndReturnArgs<$Schema, "User">; -export type UserUpsertArgs = $UpsertArgs<$Schema, "User">; -export type UserDeleteArgs = $DeleteArgs<$Schema, "User">; -export type UserDeleteManyArgs = $DeleteManyArgs<$Schema, "User">; -export type UserCountArgs = $CountArgs<$Schema, "User">; -export type UserAggregateArgs = $AggregateArgs<$Schema, "User">; -export type UserGroupByArgs = $GroupByArgs<$Schema, "User">; -export type UserWhereInput = $WhereInput<$Schema, "User">; -export type UserSelect = $SelectInput<$Schema, "User">; -export type UserInclude = $IncludeInput<$Schema, "User">; -export type UserOmit = $OmitInput<$Schema, "User">; -export type UserGetPayload> = $SimplifiedModelResult<$Schema, "User", Args>; -export type CommentFindManyArgs = $FindManyArgs<$Schema, "Comment">; -export type CommentFindUniqueArgs = $FindUniqueArgs<$Schema, "Comment">; -export type CommentFindFirstArgs = $FindFirstArgs<$Schema, "Comment">; -export type CommentCreateArgs = $CreateArgs<$Schema, "Comment">; -export type CommentCreateManyArgs = $CreateManyArgs<$Schema, "Comment">; -export type CommentCreateManyAndReturnArgs = $CreateManyAndReturnArgs<$Schema, "Comment">; -export type CommentUpdateArgs = $UpdateArgs<$Schema, "Comment">; -export type CommentUpdateManyArgs = $UpdateManyArgs<$Schema, "Comment">; -export type CommentUpdateManyAndReturnArgs = $UpdateManyAndReturnArgs<$Schema, "Comment">; -export type CommentUpsertArgs = $UpsertArgs<$Schema, "Comment">; -export type CommentDeleteArgs = $DeleteArgs<$Schema, "Comment">; -export type CommentDeleteManyArgs = $DeleteManyArgs<$Schema, "Comment">; -export type CommentCountArgs = $CountArgs<$Schema, "Comment">; -export type CommentAggregateArgs = $AggregateArgs<$Schema, "Comment">; -export type CommentGroupByArgs = $GroupByArgs<$Schema, "Comment">; -export type CommentWhereInput = $WhereInput<$Schema, "Comment">; -export type CommentSelect = $SelectInput<$Schema, "Comment">; -export type CommentInclude = $IncludeInput<$Schema, "Comment">; -export type CommentOmit = $OmitInput<$Schema, "Comment">; -export type CommentGetPayload> = $SimplifiedModelResult<$Schema, "Comment", Args>; -export type AssetFindManyArgs = $FindManyArgs<$Schema, "Asset">; -export type AssetFindUniqueArgs = $FindUniqueArgs<$Schema, "Asset">; -export type AssetFindFirstArgs = $FindFirstArgs<$Schema, "Asset">; -export type AssetCreateArgs = $CreateArgs<$Schema, "Asset">; -export type AssetCreateManyArgs = $CreateManyArgs<$Schema, "Asset">; -export type AssetCreateManyAndReturnArgs = $CreateManyAndReturnArgs<$Schema, "Asset">; -export type AssetUpdateArgs = $UpdateArgs<$Schema, "Asset">; -export type AssetUpdateManyArgs = $UpdateManyArgs<$Schema, "Asset">; -export type AssetUpdateManyAndReturnArgs = $UpdateManyAndReturnArgs<$Schema, "Asset">; -export type AssetUpsertArgs = $UpsertArgs<$Schema, "Asset">; -export type AssetDeleteArgs = $DeleteArgs<$Schema, "Asset">; -export type AssetDeleteManyArgs = $DeleteManyArgs<$Schema, "Asset">; -export type AssetCountArgs = $CountArgs<$Schema, "Asset">; -export type AssetAggregateArgs = $AggregateArgs<$Schema, "Asset">; -export type AssetGroupByArgs = $GroupByArgs<$Schema, "Asset">; -export type AssetWhereInput = $WhereInput<$Schema, "Asset">; -export type AssetSelect = $SelectInput<$Schema, "Asset">; -export type AssetInclude = $IncludeInput<$Schema, "Asset">; -export type AssetOmit = $OmitInput<$Schema, "Asset">; -export type AssetGetPayload> = $SimplifiedModelResult<$Schema, "Asset", Args>; -export type VideoFindManyArgs = $FindManyArgs<$Schema, "Video">; -export type VideoFindUniqueArgs = $FindUniqueArgs<$Schema, "Video">; -export type VideoFindFirstArgs = $FindFirstArgs<$Schema, "Video">; -export type VideoCreateArgs = $CreateArgs<$Schema, "Video">; -export type VideoCreateManyArgs = $CreateManyArgs<$Schema, "Video">; -export type VideoCreateManyAndReturnArgs = $CreateManyAndReturnArgs<$Schema, "Video">; -export type VideoUpdateArgs = $UpdateArgs<$Schema, "Video">; -export type VideoUpdateManyArgs = $UpdateManyArgs<$Schema, "Video">; -export type VideoUpdateManyAndReturnArgs = $UpdateManyAndReturnArgs<$Schema, "Video">; -export type VideoUpsertArgs = $UpsertArgs<$Schema, "Video">; -export type VideoDeleteArgs = $DeleteArgs<$Schema, "Video">; -export type VideoDeleteManyArgs = $DeleteManyArgs<$Schema, "Video">; -export type VideoCountArgs = $CountArgs<$Schema, "Video">; -export type VideoAggregateArgs = $AggregateArgs<$Schema, "Video">; -export type VideoGroupByArgs = $GroupByArgs<$Schema, "Video">; -export type VideoWhereInput = $WhereInput<$Schema, "Video">; -export type VideoSelect = $SelectInput<$Schema, "Video">; -export type VideoInclude = $IncludeInput<$Schema, "Video">; -export type VideoOmit = $OmitInput<$Schema, "Video">; -export type VideoGetPayload> = $SimplifiedModelResult<$Schema, "Video", Args>; -export type RatedVideoFindManyArgs = $FindManyArgs<$Schema, "RatedVideo">; -export type RatedVideoFindUniqueArgs = $FindUniqueArgs<$Schema, "RatedVideo">; -export type RatedVideoFindFirstArgs = $FindFirstArgs<$Schema, "RatedVideo">; -export type RatedVideoCreateArgs = $CreateArgs<$Schema, "RatedVideo">; -export type RatedVideoCreateManyArgs = $CreateManyArgs<$Schema, "RatedVideo">; -export type RatedVideoCreateManyAndReturnArgs = $CreateManyAndReturnArgs<$Schema, "RatedVideo">; -export type RatedVideoUpdateArgs = $UpdateArgs<$Schema, "RatedVideo">; -export type RatedVideoUpdateManyArgs = $UpdateManyArgs<$Schema, "RatedVideo">; -export type RatedVideoUpdateManyAndReturnArgs = $UpdateManyAndReturnArgs<$Schema, "RatedVideo">; -export type RatedVideoUpsertArgs = $UpsertArgs<$Schema, "RatedVideo">; -export type RatedVideoDeleteArgs = $DeleteArgs<$Schema, "RatedVideo">; -export type RatedVideoDeleteManyArgs = $DeleteManyArgs<$Schema, "RatedVideo">; -export type RatedVideoCountArgs = $CountArgs<$Schema, "RatedVideo">; -export type RatedVideoAggregateArgs = $AggregateArgs<$Schema, "RatedVideo">; -export type RatedVideoGroupByArgs = $GroupByArgs<$Schema, "RatedVideo">; -export type RatedVideoWhereInput = $WhereInput<$Schema, "RatedVideo">; -export type RatedVideoSelect = $SelectInput<$Schema, "RatedVideo">; -export type RatedVideoInclude = $IncludeInput<$Schema, "RatedVideo">; -export type RatedVideoOmit = $OmitInput<$Schema, "RatedVideo">; -export type RatedVideoGetPayload> = $SimplifiedModelResult<$Schema, "RatedVideo", Args>; -export type ImageFindManyArgs = $FindManyArgs<$Schema, "Image">; -export type ImageFindUniqueArgs = $FindUniqueArgs<$Schema, "Image">; -export type ImageFindFirstArgs = $FindFirstArgs<$Schema, "Image">; -export type ImageCreateArgs = $CreateArgs<$Schema, "Image">; -export type ImageCreateManyArgs = $CreateManyArgs<$Schema, "Image">; -export type ImageCreateManyAndReturnArgs = $CreateManyAndReturnArgs<$Schema, "Image">; -export type ImageUpdateArgs = $UpdateArgs<$Schema, "Image">; -export type ImageUpdateManyArgs = $UpdateManyArgs<$Schema, "Image">; -export type ImageUpdateManyAndReturnArgs = $UpdateManyAndReturnArgs<$Schema, "Image">; -export type ImageUpsertArgs = $UpsertArgs<$Schema, "Image">; -export type ImageDeleteArgs = $DeleteArgs<$Schema, "Image">; -export type ImageDeleteManyArgs = $DeleteManyArgs<$Schema, "Image">; -export type ImageCountArgs = $CountArgs<$Schema, "Image">; -export type ImageAggregateArgs = $AggregateArgs<$Schema, "Image">; -export type ImageGroupByArgs = $GroupByArgs<$Schema, "Image">; -export type ImageWhereInput = $WhereInput<$Schema, "Image">; -export type ImageSelect = $SelectInput<$Schema, "Image">; -export type ImageInclude = $IncludeInput<$Schema, "Image">; -export type ImageOmit = $OmitInput<$Schema, "Image">; -export type ImageGetPayload> = $SimplifiedModelResult<$Schema, "Image", Args>; -export type GalleryFindManyArgs = $FindManyArgs<$Schema, "Gallery">; -export type GalleryFindUniqueArgs = $FindUniqueArgs<$Schema, "Gallery">; -export type GalleryFindFirstArgs = $FindFirstArgs<$Schema, "Gallery">; -export type GalleryCreateArgs = $CreateArgs<$Schema, "Gallery">; -export type GalleryCreateManyArgs = $CreateManyArgs<$Schema, "Gallery">; -export type GalleryCreateManyAndReturnArgs = $CreateManyAndReturnArgs<$Schema, "Gallery">; -export type GalleryUpdateArgs = $UpdateArgs<$Schema, "Gallery">; -export type GalleryUpdateManyArgs = $UpdateManyArgs<$Schema, "Gallery">; -export type GalleryUpdateManyAndReturnArgs = $UpdateManyAndReturnArgs<$Schema, "Gallery">; -export type GalleryUpsertArgs = $UpsertArgs<$Schema, "Gallery">; -export type GalleryDeleteArgs = $DeleteArgs<$Schema, "Gallery">; -export type GalleryDeleteManyArgs = $DeleteManyArgs<$Schema, "Gallery">; -export type GalleryCountArgs = $CountArgs<$Schema, "Gallery">; -export type GalleryAggregateArgs = $AggregateArgs<$Schema, "Gallery">; -export type GalleryGroupByArgs = $GroupByArgs<$Schema, "Gallery">; -export type GalleryWhereInput = $WhereInput<$Schema, "Gallery">; -export type GallerySelect = $SelectInput<$Schema, "Gallery">; -export type GalleryInclude = $IncludeInput<$Schema, "Gallery">; -export type GalleryOmit = $OmitInput<$Schema, "Gallery">; -export type GalleryGetPayload> = $SimplifiedModelResult<$Schema, "Gallery", Args>; +import { type SchemaType as $Schema } from './schema'; +import type { + FindManyArgs as $FindManyArgs, + FindUniqueArgs as $FindUniqueArgs, + FindFirstArgs as $FindFirstArgs, + CreateArgs as $CreateArgs, + CreateManyArgs as $CreateManyArgs, + CreateManyAndReturnArgs as $CreateManyAndReturnArgs, + UpdateArgs as $UpdateArgs, + UpdateManyArgs as $UpdateManyArgs, + UpdateManyAndReturnArgs as $UpdateManyAndReturnArgs, + UpsertArgs as $UpsertArgs, + DeleteArgs as $DeleteArgs, + DeleteManyArgs as $DeleteManyArgs, + CountArgs as $CountArgs, + AggregateArgs as $AggregateArgs, + GroupByArgs as $GroupByArgs, + WhereInput as $WhereInput, + SelectInput as $SelectInput, + IncludeInput as $IncludeInput, + OmitInput as $OmitInput, +} from '@zenstackhq/orm'; +import type { + SimplifiedModelResult as $SimplifiedModelResult, + SelectIncludeOmit as $SelectIncludeOmit, +} from '@zenstackhq/orm'; +export type UserFindManyArgs = $FindManyArgs<$Schema, 'User'>; +export type UserFindUniqueArgs = $FindUniqueArgs<$Schema, 'User'>; +export type UserFindFirstArgs = $FindFirstArgs<$Schema, 'User'>; +export type UserCreateArgs = $CreateArgs<$Schema, 'User'>; +export type UserCreateManyArgs = $CreateManyArgs<$Schema, 'User'>; +export type UserCreateManyAndReturnArgs = $CreateManyAndReturnArgs<$Schema, 'User'>; +export type UserUpdateArgs = $UpdateArgs<$Schema, 'User'>; +export type UserUpdateManyArgs = $UpdateManyArgs<$Schema, 'User'>; +export type UserUpdateManyAndReturnArgs = $UpdateManyAndReturnArgs<$Schema, 'User'>; +export type UserUpsertArgs = $UpsertArgs<$Schema, 'User'>; +export type UserDeleteArgs = $DeleteArgs<$Schema, 'User'>; +export type UserDeleteManyArgs = $DeleteManyArgs<$Schema, 'User'>; +export type UserCountArgs = $CountArgs<$Schema, 'User'>; +export type UserAggregateArgs = $AggregateArgs<$Schema, 'User'>; +export type UserGroupByArgs = $GroupByArgs<$Schema, 'User'>; +export type UserWhereInput = $WhereInput<$Schema, 'User'>; +export type UserSelect = $SelectInput<$Schema, 'User'>; +export type UserInclude = $IncludeInput<$Schema, 'User'>; +export type UserOmit = $OmitInput<$Schema, 'User'>; +export type UserGetPayload> = $SimplifiedModelResult< + $Schema, + 'User', + Args +>; +export type CommentFindManyArgs = $FindManyArgs<$Schema, 'Comment'>; +export type CommentFindUniqueArgs = $FindUniqueArgs<$Schema, 'Comment'>; +export type CommentFindFirstArgs = $FindFirstArgs<$Schema, 'Comment'>; +export type CommentCreateArgs = $CreateArgs<$Schema, 'Comment'>; +export type CommentCreateManyArgs = $CreateManyArgs<$Schema, 'Comment'>; +export type CommentCreateManyAndReturnArgs = $CreateManyAndReturnArgs<$Schema, 'Comment'>; +export type CommentUpdateArgs = $UpdateArgs<$Schema, 'Comment'>; +export type CommentUpdateManyArgs = $UpdateManyArgs<$Schema, 'Comment'>; +export type CommentUpdateManyAndReturnArgs = $UpdateManyAndReturnArgs<$Schema, 'Comment'>; +export type CommentUpsertArgs = $UpsertArgs<$Schema, 'Comment'>; +export type CommentDeleteArgs = $DeleteArgs<$Schema, 'Comment'>; +export type CommentDeleteManyArgs = $DeleteManyArgs<$Schema, 'Comment'>; +export type CommentCountArgs = $CountArgs<$Schema, 'Comment'>; +export type CommentAggregateArgs = $AggregateArgs<$Schema, 'Comment'>; +export type CommentGroupByArgs = $GroupByArgs<$Schema, 'Comment'>; +export type CommentWhereInput = $WhereInput<$Schema, 'Comment'>; +export type CommentSelect = $SelectInput<$Schema, 'Comment'>; +export type CommentInclude = $IncludeInput<$Schema, 'Comment'>; +export type CommentOmit = $OmitInput<$Schema, 'Comment'>; +export type CommentGetPayload> = $SimplifiedModelResult< + $Schema, + 'Comment', + Args +>; +export type AssetFindManyArgs = $FindManyArgs<$Schema, 'Asset'>; +export type AssetFindUniqueArgs = $FindUniqueArgs<$Schema, 'Asset'>; +export type AssetFindFirstArgs = $FindFirstArgs<$Schema, 'Asset'>; +export type AssetCreateArgs = $CreateArgs<$Schema, 'Asset'>; +export type AssetCreateManyArgs = $CreateManyArgs<$Schema, 'Asset'>; +export type AssetCreateManyAndReturnArgs = $CreateManyAndReturnArgs<$Schema, 'Asset'>; +export type AssetUpdateArgs = $UpdateArgs<$Schema, 'Asset'>; +export type AssetUpdateManyArgs = $UpdateManyArgs<$Schema, 'Asset'>; +export type AssetUpdateManyAndReturnArgs = $UpdateManyAndReturnArgs<$Schema, 'Asset'>; +export type AssetUpsertArgs = $UpsertArgs<$Schema, 'Asset'>; +export type AssetDeleteArgs = $DeleteArgs<$Schema, 'Asset'>; +export type AssetDeleteManyArgs = $DeleteManyArgs<$Schema, 'Asset'>; +export type AssetCountArgs = $CountArgs<$Schema, 'Asset'>; +export type AssetAggregateArgs = $AggregateArgs<$Schema, 'Asset'>; +export type AssetGroupByArgs = $GroupByArgs<$Schema, 'Asset'>; +export type AssetWhereInput = $WhereInput<$Schema, 'Asset'>; +export type AssetSelect = $SelectInput<$Schema, 'Asset'>; +export type AssetInclude = $IncludeInput<$Schema, 'Asset'>; +export type AssetOmit = $OmitInput<$Schema, 'Asset'>; +export type AssetGetPayload> = $SimplifiedModelResult< + $Schema, + 'Asset', + Args +>; +export type VideoFindManyArgs = $FindManyArgs<$Schema, 'Video'>; +export type VideoFindUniqueArgs = $FindUniqueArgs<$Schema, 'Video'>; +export type VideoFindFirstArgs = $FindFirstArgs<$Schema, 'Video'>; +export type VideoCreateArgs = $CreateArgs<$Schema, 'Video'>; +export type VideoCreateManyArgs = $CreateManyArgs<$Schema, 'Video'>; +export type VideoCreateManyAndReturnArgs = $CreateManyAndReturnArgs<$Schema, 'Video'>; +export type VideoUpdateArgs = $UpdateArgs<$Schema, 'Video'>; +export type VideoUpdateManyArgs = $UpdateManyArgs<$Schema, 'Video'>; +export type VideoUpdateManyAndReturnArgs = $UpdateManyAndReturnArgs<$Schema, 'Video'>; +export type VideoUpsertArgs = $UpsertArgs<$Schema, 'Video'>; +export type VideoDeleteArgs = $DeleteArgs<$Schema, 'Video'>; +export type VideoDeleteManyArgs = $DeleteManyArgs<$Schema, 'Video'>; +export type VideoCountArgs = $CountArgs<$Schema, 'Video'>; +export type VideoAggregateArgs = $AggregateArgs<$Schema, 'Video'>; +export type VideoGroupByArgs = $GroupByArgs<$Schema, 'Video'>; +export type VideoWhereInput = $WhereInput<$Schema, 'Video'>; +export type VideoSelect = $SelectInput<$Schema, 'Video'>; +export type VideoInclude = $IncludeInput<$Schema, 'Video'>; +export type VideoOmit = $OmitInput<$Schema, 'Video'>; +export type VideoGetPayload> = $SimplifiedModelResult< + $Schema, + 'Video', + Args +>; +export type RatedVideoFindManyArgs = $FindManyArgs<$Schema, 'RatedVideo'>; +export type RatedVideoFindUniqueArgs = $FindUniqueArgs<$Schema, 'RatedVideo'>; +export type RatedVideoFindFirstArgs = $FindFirstArgs<$Schema, 'RatedVideo'>; +export type RatedVideoCreateArgs = $CreateArgs<$Schema, 'RatedVideo'>; +export type RatedVideoCreateManyArgs = $CreateManyArgs<$Schema, 'RatedVideo'>; +export type RatedVideoCreateManyAndReturnArgs = $CreateManyAndReturnArgs<$Schema, 'RatedVideo'>; +export type RatedVideoUpdateArgs = $UpdateArgs<$Schema, 'RatedVideo'>; +export type RatedVideoUpdateManyArgs = $UpdateManyArgs<$Schema, 'RatedVideo'>; +export type RatedVideoUpdateManyAndReturnArgs = $UpdateManyAndReturnArgs<$Schema, 'RatedVideo'>; +export type RatedVideoUpsertArgs = $UpsertArgs<$Schema, 'RatedVideo'>; +export type RatedVideoDeleteArgs = $DeleteArgs<$Schema, 'RatedVideo'>; +export type RatedVideoDeleteManyArgs = $DeleteManyArgs<$Schema, 'RatedVideo'>; +export type RatedVideoCountArgs = $CountArgs<$Schema, 'RatedVideo'>; +export type RatedVideoAggregateArgs = $AggregateArgs<$Schema, 'RatedVideo'>; +export type RatedVideoGroupByArgs = $GroupByArgs<$Schema, 'RatedVideo'>; +export type RatedVideoWhereInput = $WhereInput<$Schema, 'RatedVideo'>; +export type RatedVideoSelect = $SelectInput<$Schema, 'RatedVideo'>; +export type RatedVideoInclude = $IncludeInput<$Schema, 'RatedVideo'>; +export type RatedVideoOmit = $OmitInput<$Schema, 'RatedVideo'>; +export type RatedVideoGetPayload> = $SimplifiedModelResult< + $Schema, + 'RatedVideo', + Args +>; +export type ImageFindManyArgs = $FindManyArgs<$Schema, 'Image'>; +export type ImageFindUniqueArgs = $FindUniqueArgs<$Schema, 'Image'>; +export type ImageFindFirstArgs = $FindFirstArgs<$Schema, 'Image'>; +export type ImageCreateArgs = $CreateArgs<$Schema, 'Image'>; +export type ImageCreateManyArgs = $CreateManyArgs<$Schema, 'Image'>; +export type ImageCreateManyAndReturnArgs = $CreateManyAndReturnArgs<$Schema, 'Image'>; +export type ImageUpdateArgs = $UpdateArgs<$Schema, 'Image'>; +export type ImageUpdateManyArgs = $UpdateManyArgs<$Schema, 'Image'>; +export type ImageUpdateManyAndReturnArgs = $UpdateManyAndReturnArgs<$Schema, 'Image'>; +export type ImageUpsertArgs = $UpsertArgs<$Schema, 'Image'>; +export type ImageDeleteArgs = $DeleteArgs<$Schema, 'Image'>; +export type ImageDeleteManyArgs = $DeleteManyArgs<$Schema, 'Image'>; +export type ImageCountArgs = $CountArgs<$Schema, 'Image'>; +export type ImageAggregateArgs = $AggregateArgs<$Schema, 'Image'>; +export type ImageGroupByArgs = $GroupByArgs<$Schema, 'Image'>; +export type ImageWhereInput = $WhereInput<$Schema, 'Image'>; +export type ImageSelect = $SelectInput<$Schema, 'Image'>; +export type ImageInclude = $IncludeInput<$Schema, 'Image'>; +export type ImageOmit = $OmitInput<$Schema, 'Image'>; +export type ImageGetPayload> = $SimplifiedModelResult< + $Schema, + 'Image', + Args +>; +export type GalleryFindManyArgs = $FindManyArgs<$Schema, 'Gallery'>; +export type GalleryFindUniqueArgs = $FindUniqueArgs<$Schema, 'Gallery'>; +export type GalleryFindFirstArgs = $FindFirstArgs<$Schema, 'Gallery'>; +export type GalleryCreateArgs = $CreateArgs<$Schema, 'Gallery'>; +export type GalleryCreateManyArgs = $CreateManyArgs<$Schema, 'Gallery'>; +export type GalleryCreateManyAndReturnArgs = $CreateManyAndReturnArgs<$Schema, 'Gallery'>; +export type GalleryUpdateArgs = $UpdateArgs<$Schema, 'Gallery'>; +export type GalleryUpdateManyArgs = $UpdateManyArgs<$Schema, 'Gallery'>; +export type GalleryUpdateManyAndReturnArgs = $UpdateManyAndReturnArgs<$Schema, 'Gallery'>; +export type GalleryUpsertArgs = $UpsertArgs<$Schema, 'Gallery'>; +export type GalleryDeleteArgs = $DeleteArgs<$Schema, 'Gallery'>; +export type GalleryDeleteManyArgs = $DeleteManyArgs<$Schema, 'Gallery'>; +export type GalleryCountArgs = $CountArgs<$Schema, 'Gallery'>; +export type GalleryAggregateArgs = $AggregateArgs<$Schema, 'Gallery'>; +export type GalleryGroupByArgs = $GroupByArgs<$Schema, 'Gallery'>; +export type GalleryWhereInput = $WhereInput<$Schema, 'Gallery'>; +export type GallerySelect = $SelectInput<$Schema, 'Gallery'>; +export type GalleryInclude = $IncludeInput<$Schema, 'Gallery'>; +export type GalleryOmit = $OmitInput<$Schema, 'Gallery'>; +export type GalleryGetPayload> = $SimplifiedModelResult< + $Schema, + 'Gallery', + Args +>; diff --git a/tests/e2e/orm/schemas/delegate/models.ts b/tests/e2e/orm/schemas/delegate/models.ts index 0a4350d2..9d37be96 100644 --- a/tests/e2e/orm/schemas/delegate/models.ts +++ b/tests/e2e/orm/schemas/delegate/models.ts @@ -5,12 +5,12 @@ /* eslint-disable */ -import { type SchemaType as $Schema } from "./schema"; -import { type ModelResult as $ModelResult } from "@zenstackhq/orm"; -export type User = $ModelResult<$Schema, "User">; -export type Comment = $ModelResult<$Schema, "Comment">; -export type Asset = $ModelResult<$Schema, "Asset">; -export type Video = $ModelResult<$Schema, "Video">; -export type RatedVideo = $ModelResult<$Schema, "RatedVideo">; -export type Image = $ModelResult<$Schema, "Image">; -export type Gallery = $ModelResult<$Schema, "Gallery">; +import { type SchemaType as $Schema } from './schema'; +import { type ModelResult as $ModelResult } from '@zenstackhq/orm'; +export type User = $ModelResult<$Schema, 'User'>; +export type Comment = $ModelResult<$Schema, 'Comment'>; +export type Asset = $ModelResult<$Schema, 'Asset'>; +export type Video = $ModelResult<$Schema, 'Video'>; +export type RatedVideo = $ModelResult<$Schema, 'RatedVideo'>; +export type Image = $ModelResult<$Schema, 'Image'>; +export type Gallery = $ModelResult<$Schema, 'Gallery'>; diff --git a/tests/e2e/orm/schemas/delegate/schema.ts b/tests/e2e/orm/schemas/delegate/schema.ts index 8767b8e1..e085404c 100644 --- a/tests/e2e/orm/schemas/delegate/schema.ts +++ b/tests/e2e/orm/schemas/delegate/schema.ts @@ -5,461 +5,540 @@ /* eslint-disable */ -import { type SchemaDef, ExpressionUtils } from "@zenstackhq/orm/schema"; +import { type SchemaDef, ExpressionUtils } from '@zenstackhq/orm/schema'; export const schema = { provider: { - type: "sqlite" + type: 'sqlite', }, models: { User: { - name: "User", + name: 'User', fields: { id: { - name: "id", - type: "Int", + name: 'id', + type: 'Int', id: true, - attributes: [{ name: "@id" }, { name: "@default", args: [{ name: "value", value: ExpressionUtils.call("autoincrement") }] }], - default: ExpressionUtils.call("autoincrement") + attributes: [ + { name: '@id' }, + { name: '@default', args: [{ name: 'value', value: ExpressionUtils.call('autoincrement') }] }, + ], + default: ExpressionUtils.call('autoincrement'), }, email: { - name: "email", - type: "String", + name: 'email', + type: 'String', unique: true, optional: true, - attributes: [{ name: "@unique" }] + attributes: [{ name: '@unique' }], }, level: { - name: "level", - type: "Int", - attributes: [{ name: "@default", args: [{ name: "value", value: ExpressionUtils.literal(0) }] }], - default: 0 + name: 'level', + type: 'Int', + attributes: [{ name: '@default', args: [{ name: 'value', value: ExpressionUtils.literal(0) }] }], + default: 0, }, assets: { - name: "assets", - type: "Asset", + name: 'assets', + type: 'Asset', array: true, - relation: { opposite: "owner" } + relation: { opposite: 'owner' }, }, ratedVideos: { - name: "ratedVideos", - type: "RatedVideo", + name: 'ratedVideos', + type: 'RatedVideo', array: true, - attributes: [{ name: "@relation", args: [{ name: "name", value: ExpressionUtils.literal("direct") }] }], - relation: { opposite: "user", name: "direct" } - } + attributes: [ + { name: '@relation', args: [{ name: 'name', value: ExpressionUtils.literal('direct') }] }, + ], + relation: { opposite: 'user', name: 'direct' }, + }, }, - idFields: ["id"], + idFields: ['id'], uniqueFields: { - id: { type: "Int" }, - email: { type: "String" } - } + id: { type: 'Int' }, + email: { type: 'String' }, + }, }, Comment: { - name: "Comment", + name: 'Comment', fields: { id: { - name: "id", - type: "Int", + name: 'id', + type: 'Int', id: true, - attributes: [{ name: "@id" }, { name: "@default", args: [{ name: "value", value: ExpressionUtils.call("autoincrement") }] }], - default: ExpressionUtils.call("autoincrement") + attributes: [ + { name: '@id' }, + { name: '@default', args: [{ name: 'value', value: ExpressionUtils.call('autoincrement') }] }, + ], + default: ExpressionUtils.call('autoincrement'), }, content: { - name: "content", - type: "String" + name: 'content', + type: 'String', }, asset: { - name: "asset", - type: "Asset", + name: 'asset', + type: 'Asset', optional: true, - attributes: [{ name: "@relation", args: [{ name: "fields", value: ExpressionUtils.array([ExpressionUtils.field("assetId")]) }, { name: "references", value: ExpressionUtils.array([ExpressionUtils.field("id")]) }, { name: "onDelete", value: ExpressionUtils.literal("Cascade") }] }], - relation: { opposite: "comments", fields: ["assetId"], references: ["id"], onDelete: "Cascade" } + attributes: [ + { + name: '@relation', + args: [ + { name: 'fields', value: ExpressionUtils.array([ExpressionUtils.field('assetId')]) }, + { name: 'references', value: ExpressionUtils.array([ExpressionUtils.field('id')]) }, + { name: 'onDelete', value: ExpressionUtils.literal('Cascade') }, + ], + }, + ], + relation: { opposite: 'comments', fields: ['assetId'], references: ['id'], onDelete: 'Cascade' }, }, assetId: { - name: "assetId", - type: "Int", + name: 'assetId', + type: 'Int', optional: true, - foreignKeyFor: [ - "asset" - ] - } + foreignKeyFor: ['asset'], + }, }, - idFields: ["id"], + idFields: ['id'], uniqueFields: { - id: { type: "Int" } - } + id: { type: 'Int' }, + }, }, Asset: { - name: "Asset", + name: 'Asset', fields: { id: { - name: "id", - type: "Int", + name: 'id', + type: 'Int', id: true, - attributes: [{ name: "@id" }, { name: "@default", args: [{ name: "value", value: ExpressionUtils.call("autoincrement") }] }], - default: ExpressionUtils.call("autoincrement") + attributes: [ + { name: '@id' }, + { name: '@default', args: [{ name: 'value', value: ExpressionUtils.call('autoincrement') }] }, + ], + default: ExpressionUtils.call('autoincrement'), }, createdAt: { - name: "createdAt", - type: "DateTime", - attributes: [{ name: "@default", args: [{ name: "value", value: ExpressionUtils.call("now") }] }], - default: ExpressionUtils.call("now") + name: 'createdAt', + type: 'DateTime', + attributes: [{ name: '@default', args: [{ name: 'value', value: ExpressionUtils.call('now') }] }], + default: ExpressionUtils.call('now'), }, updatedAt: { - name: "updatedAt", - type: "DateTime", + name: 'updatedAt', + type: 'DateTime', updatedAt: true, - attributes: [{ name: "@updatedAt" }] + attributes: [{ name: '@updatedAt' }], }, viewCount: { - name: "viewCount", - type: "Int", - attributes: [{ name: "@default", args: [{ name: "value", value: ExpressionUtils.literal(0) }] }], - default: 0 + name: 'viewCount', + type: 'Int', + attributes: [{ name: '@default', args: [{ name: 'value', value: ExpressionUtils.literal(0) }] }], + default: 0, }, owner: { - name: "owner", - type: "User", + name: 'owner', + type: 'User', optional: true, - attributes: [{ name: "@relation", args: [{ name: "fields", value: ExpressionUtils.array([ExpressionUtils.field("ownerId")]) }, { name: "references", value: ExpressionUtils.array([ExpressionUtils.field("id")]) }, { name: "onDelete", value: ExpressionUtils.literal("Cascade") }] }], - relation: { opposite: "assets", fields: ["ownerId"], references: ["id"], onDelete: "Cascade" } + attributes: [ + { + name: '@relation', + args: [ + { name: 'fields', value: ExpressionUtils.array([ExpressionUtils.field('ownerId')]) }, + { name: 'references', value: ExpressionUtils.array([ExpressionUtils.field('id')]) }, + { name: 'onDelete', value: ExpressionUtils.literal('Cascade') }, + ], + }, + ], + relation: { opposite: 'assets', fields: ['ownerId'], references: ['id'], onDelete: 'Cascade' }, }, ownerId: { - name: "ownerId", - type: "Int", + name: 'ownerId', + type: 'Int', optional: true, - foreignKeyFor: [ - "owner" - ] + foreignKeyFor: ['owner'], }, comments: { - name: "comments", - type: "Comment", + name: 'comments', + type: 'Comment', array: true, - relation: { opposite: "asset" } + relation: { opposite: 'asset' }, }, assetType: { - name: "assetType", - type: "String", - isDiscriminator: true - } + name: 'assetType', + type: 'String', + isDiscriminator: true, + }, }, attributes: [ - { name: "@@delegate", args: [{ name: "discriminator", value: ExpressionUtils.field("assetType") }] } + { name: '@@delegate', args: [{ name: 'discriminator', value: ExpressionUtils.field('assetType') }] }, ], - idFields: ["id"], + idFields: ['id'], uniqueFields: { - id: { type: "Int" } + id: { type: 'Int' }, }, isDelegate: true, - subModels: ["Video", "Image"] + subModels: ['Video', 'Image'], }, Video: { - name: "Video", - baseModel: "Asset", + name: 'Video', + baseModel: 'Asset', fields: { id: { - name: "id", - type: "Int", + name: 'id', + type: 'Int', id: true, - attributes: [{ name: "@id" }, { name: "@default", args: [{ name: "value", value: ExpressionUtils.call("autoincrement") }] }], - default: ExpressionUtils.call("autoincrement") + attributes: [ + { name: '@id' }, + { name: '@default', args: [{ name: 'value', value: ExpressionUtils.call('autoincrement') }] }, + ], + default: ExpressionUtils.call('autoincrement'), }, createdAt: { - name: "createdAt", - type: "DateTime", - originModel: "Asset", - attributes: [{ name: "@default", args: [{ name: "value", value: ExpressionUtils.call("now") }] }], - default: ExpressionUtils.call("now") + name: 'createdAt', + type: 'DateTime', + originModel: 'Asset', + attributes: [{ name: '@default', args: [{ name: 'value', value: ExpressionUtils.call('now') }] }], + default: ExpressionUtils.call('now'), }, updatedAt: { - name: "updatedAt", - type: "DateTime", + name: 'updatedAt', + type: 'DateTime', updatedAt: true, - originModel: "Asset", - attributes: [{ name: "@updatedAt" }] + originModel: 'Asset', + attributes: [{ name: '@updatedAt' }], }, viewCount: { - name: "viewCount", - type: "Int", - originModel: "Asset", - attributes: [{ name: "@default", args: [{ name: "value", value: ExpressionUtils.literal(0) }] }], - default: 0 + name: 'viewCount', + type: 'Int', + originModel: 'Asset', + attributes: [{ name: '@default', args: [{ name: 'value', value: ExpressionUtils.literal(0) }] }], + default: 0, }, owner: { - name: "owner", - type: "User", + name: 'owner', + type: 'User', optional: true, - originModel: "Asset", - attributes: [{ name: "@relation", args: [{ name: "fields", value: ExpressionUtils.array([ExpressionUtils.field("ownerId")]) }, { name: "references", value: ExpressionUtils.array([ExpressionUtils.field("id")]) }, { name: "onDelete", value: ExpressionUtils.literal("Cascade") }] }], - relation: { opposite: "assets", fields: ["ownerId"], references: ["id"], onDelete: "Cascade" } + originModel: 'Asset', + attributes: [ + { + name: '@relation', + args: [ + { name: 'fields', value: ExpressionUtils.array([ExpressionUtils.field('ownerId')]) }, + { name: 'references', value: ExpressionUtils.array([ExpressionUtils.field('id')]) }, + { name: 'onDelete', value: ExpressionUtils.literal('Cascade') }, + ], + }, + ], + relation: { opposite: 'assets', fields: ['ownerId'], references: ['id'], onDelete: 'Cascade' }, }, ownerId: { - name: "ownerId", - type: "Int", + name: 'ownerId', + type: 'Int', optional: true, - originModel: "Asset", - foreignKeyFor: [ - "owner" - ] + originModel: 'Asset', + foreignKeyFor: ['owner'], }, comments: { - name: "comments", - type: "Comment", + name: 'comments', + type: 'Comment', array: true, - originModel: "Asset", - relation: { opposite: "asset" } + originModel: 'Asset', + relation: { opposite: 'asset' }, }, assetType: { - name: "assetType", - type: "String", - originModel: "Asset", - isDiscriminator: true + name: 'assetType', + type: 'String', + originModel: 'Asset', + isDiscriminator: true, }, duration: { - name: "duration", - type: "Int" + name: 'duration', + type: 'Int', }, url: { - name: "url", - type: "String", + name: 'url', + type: 'String', unique: true, - attributes: [{ name: "@unique" }] + attributes: [{ name: '@unique' }], }, videoType: { - name: "videoType", - type: "String", - isDiscriminator: true - } + name: 'videoType', + type: 'String', + isDiscriminator: true, + }, }, attributes: [ - { name: "@@delegate", args: [{ name: "discriminator", value: ExpressionUtils.field("videoType") }] } + { name: '@@delegate', args: [{ name: 'discriminator', value: ExpressionUtils.field('videoType') }] }, ], - idFields: ["id"], + idFields: ['id'], uniqueFields: { - id: { type: "Int" }, - url: { type: "String" } + id: { type: 'Int' }, + url: { type: 'String' }, }, isDelegate: true, - subModels: ["RatedVideo"] + subModels: ['RatedVideo'], }, RatedVideo: { - name: "RatedVideo", - baseModel: "Video", + name: 'RatedVideo', + baseModel: 'Video', fields: { id: { - name: "id", - type: "Int", + name: 'id', + type: 'Int', id: true, - attributes: [{ name: "@id" }, { name: "@default", args: [{ name: "value", value: ExpressionUtils.call("autoincrement") }] }], - default: ExpressionUtils.call("autoincrement") + attributes: [ + { name: '@id' }, + { name: '@default', args: [{ name: 'value', value: ExpressionUtils.call('autoincrement') }] }, + ], + default: ExpressionUtils.call('autoincrement'), }, createdAt: { - name: "createdAt", - type: "DateTime", - originModel: "Asset", - attributes: [{ name: "@default", args: [{ name: "value", value: ExpressionUtils.call("now") }] }], - default: ExpressionUtils.call("now") + name: 'createdAt', + type: 'DateTime', + originModel: 'Asset', + attributes: [{ name: '@default', args: [{ name: 'value', value: ExpressionUtils.call('now') }] }], + default: ExpressionUtils.call('now'), }, updatedAt: { - name: "updatedAt", - type: "DateTime", + name: 'updatedAt', + type: 'DateTime', updatedAt: true, - originModel: "Asset", - attributes: [{ name: "@updatedAt" }] + originModel: 'Asset', + attributes: [{ name: '@updatedAt' }], }, viewCount: { - name: "viewCount", - type: "Int", - originModel: "Asset", - attributes: [{ name: "@default", args: [{ name: "value", value: ExpressionUtils.literal(0) }] }], - default: 0 + name: 'viewCount', + type: 'Int', + originModel: 'Asset', + attributes: [{ name: '@default', args: [{ name: 'value', value: ExpressionUtils.literal(0) }] }], + default: 0, }, owner: { - name: "owner", - type: "User", + name: 'owner', + type: 'User', optional: true, - originModel: "Asset", - attributes: [{ name: "@relation", args: [{ name: "fields", value: ExpressionUtils.array([ExpressionUtils.field("ownerId")]) }, { name: "references", value: ExpressionUtils.array([ExpressionUtils.field("id")]) }, { name: "onDelete", value: ExpressionUtils.literal("Cascade") }] }], - relation: { opposite: "assets", fields: ["ownerId"], references: ["id"], onDelete: "Cascade" } + originModel: 'Asset', + attributes: [ + { + name: '@relation', + args: [ + { name: 'fields', value: ExpressionUtils.array([ExpressionUtils.field('ownerId')]) }, + { name: 'references', value: ExpressionUtils.array([ExpressionUtils.field('id')]) }, + { name: 'onDelete', value: ExpressionUtils.literal('Cascade') }, + ], + }, + ], + relation: { opposite: 'assets', fields: ['ownerId'], references: ['id'], onDelete: 'Cascade' }, }, ownerId: { - name: "ownerId", - type: "Int", + name: 'ownerId', + type: 'Int', optional: true, - originModel: "Asset", - foreignKeyFor: [ - "owner" - ] + originModel: 'Asset', + foreignKeyFor: ['owner'], }, comments: { - name: "comments", - type: "Comment", + name: 'comments', + type: 'Comment', array: true, - originModel: "Asset", - relation: { opposite: "asset" } + originModel: 'Asset', + relation: { opposite: 'asset' }, }, assetType: { - name: "assetType", - type: "String", - originModel: "Asset", - isDiscriminator: true + name: 'assetType', + type: 'String', + originModel: 'Asset', + isDiscriminator: true, }, duration: { - name: "duration", - type: "Int", - originModel: "Video" + name: 'duration', + type: 'Int', + originModel: 'Video', }, url: { - name: "url", - type: "String", + name: 'url', + type: 'String', unique: true, - originModel: "Video", - attributes: [{ name: "@unique" }] + originModel: 'Video', + attributes: [{ name: '@unique' }], }, videoType: { - name: "videoType", - type: "String", - originModel: "Video", - isDiscriminator: true + name: 'videoType', + type: 'String', + originModel: 'Video', + isDiscriminator: true, }, rating: { - name: "rating", - type: "Int" + name: 'rating', + type: 'Int', }, user: { - name: "user", - type: "User", + name: 'user', + type: 'User', optional: true, - attributes: [{ name: "@relation", args: [{ name: "name", value: ExpressionUtils.literal("direct") }, { name: "fields", value: ExpressionUtils.array([ExpressionUtils.field("userId")]) }, { name: "references", value: ExpressionUtils.array([ExpressionUtils.field("id")]) }, { name: "onDelete", value: ExpressionUtils.literal("Cascade") }] }], - relation: { opposite: "ratedVideos", name: "direct", fields: ["userId"], references: ["id"], onDelete: "Cascade" } + attributes: [ + { + name: '@relation', + args: [ + { name: 'name', value: ExpressionUtils.literal('direct') }, + { name: 'fields', value: ExpressionUtils.array([ExpressionUtils.field('userId')]) }, + { name: 'references', value: ExpressionUtils.array([ExpressionUtils.field('id')]) }, + { name: 'onDelete', value: ExpressionUtils.literal('Cascade') }, + ], + }, + ], + relation: { + opposite: 'ratedVideos', + name: 'direct', + fields: ['userId'], + references: ['id'], + onDelete: 'Cascade', + }, }, userId: { - name: "userId", - type: "Int", + name: 'userId', + type: 'Int', optional: true, - foreignKeyFor: [ - "user" - ] - } + foreignKeyFor: ['user'], + }, }, - idFields: ["id"], + idFields: ['id'], uniqueFields: { - id: { type: "Int" }, - url: { type: "String" } - } + id: { type: 'Int' }, + url: { type: 'String' }, + }, }, Image: { - name: "Image", - baseModel: "Asset", + name: 'Image', + baseModel: 'Asset', fields: { id: { - name: "id", - type: "Int", + name: 'id', + type: 'Int', id: true, - attributes: [{ name: "@id" }, { name: "@default", args: [{ name: "value", value: ExpressionUtils.call("autoincrement") }] }], - default: ExpressionUtils.call("autoincrement") + attributes: [ + { name: '@id' }, + { name: '@default', args: [{ name: 'value', value: ExpressionUtils.call('autoincrement') }] }, + ], + default: ExpressionUtils.call('autoincrement'), }, createdAt: { - name: "createdAt", - type: "DateTime", - originModel: "Asset", - attributes: [{ name: "@default", args: [{ name: "value", value: ExpressionUtils.call("now") }] }], - default: ExpressionUtils.call("now") + name: 'createdAt', + type: 'DateTime', + originModel: 'Asset', + attributes: [{ name: '@default', args: [{ name: 'value', value: ExpressionUtils.call('now') }] }], + default: ExpressionUtils.call('now'), }, updatedAt: { - name: "updatedAt", - type: "DateTime", + name: 'updatedAt', + type: 'DateTime', updatedAt: true, - originModel: "Asset", - attributes: [{ name: "@updatedAt" }] + originModel: 'Asset', + attributes: [{ name: '@updatedAt' }], }, viewCount: { - name: "viewCount", - type: "Int", - originModel: "Asset", - attributes: [{ name: "@default", args: [{ name: "value", value: ExpressionUtils.literal(0) }] }], - default: 0 + name: 'viewCount', + type: 'Int', + originModel: 'Asset', + attributes: [{ name: '@default', args: [{ name: 'value', value: ExpressionUtils.literal(0) }] }], + default: 0, }, owner: { - name: "owner", - type: "User", + name: 'owner', + type: 'User', optional: true, - originModel: "Asset", - attributes: [{ name: "@relation", args: [{ name: "fields", value: ExpressionUtils.array([ExpressionUtils.field("ownerId")]) }, { name: "references", value: ExpressionUtils.array([ExpressionUtils.field("id")]) }, { name: "onDelete", value: ExpressionUtils.literal("Cascade") }] }], - relation: { opposite: "assets", fields: ["ownerId"], references: ["id"], onDelete: "Cascade" } + originModel: 'Asset', + attributes: [ + { + name: '@relation', + args: [ + { name: 'fields', value: ExpressionUtils.array([ExpressionUtils.field('ownerId')]) }, + { name: 'references', value: ExpressionUtils.array([ExpressionUtils.field('id')]) }, + { name: 'onDelete', value: ExpressionUtils.literal('Cascade') }, + ], + }, + ], + relation: { opposite: 'assets', fields: ['ownerId'], references: ['id'], onDelete: 'Cascade' }, }, ownerId: { - name: "ownerId", - type: "Int", + name: 'ownerId', + type: 'Int', optional: true, - originModel: "Asset", - foreignKeyFor: [ - "owner" - ] + originModel: 'Asset', + foreignKeyFor: ['owner'], }, comments: { - name: "comments", - type: "Comment", + name: 'comments', + type: 'Comment', array: true, - originModel: "Asset", - relation: { opposite: "asset" } + originModel: 'Asset', + relation: { opposite: 'asset' }, }, assetType: { - name: "assetType", - type: "String", - originModel: "Asset", - isDiscriminator: true + name: 'assetType', + type: 'String', + originModel: 'Asset', + isDiscriminator: true, }, format: { - name: "format", - type: "String" + name: 'format', + type: 'String', }, gallery: { - name: "gallery", - type: "Gallery", + name: 'gallery', + type: 'Gallery', optional: true, - attributes: [{ name: "@relation", args: [{ name: "fields", value: ExpressionUtils.array([ExpressionUtils.field("galleryId")]) }, { name: "references", value: ExpressionUtils.array([ExpressionUtils.field("id")]) }, { name: "onDelete", value: ExpressionUtils.literal("Cascade") }] }], - relation: { opposite: "images", fields: ["galleryId"], references: ["id"], onDelete: "Cascade" } + attributes: [ + { + name: '@relation', + args: [ + { name: 'fields', value: ExpressionUtils.array([ExpressionUtils.field('galleryId')]) }, + { name: 'references', value: ExpressionUtils.array([ExpressionUtils.field('id')]) }, + { name: 'onDelete', value: ExpressionUtils.literal('Cascade') }, + ], + }, + ], + relation: { opposite: 'images', fields: ['galleryId'], references: ['id'], onDelete: 'Cascade' }, }, galleryId: { - name: "galleryId", - type: "Int", + name: 'galleryId', + type: 'Int', optional: true, - foreignKeyFor: [ - "gallery" - ] - } + foreignKeyFor: ['gallery'], + }, }, - idFields: ["id"], + idFields: ['id'], uniqueFields: { - id: { type: "Int" } - } + id: { type: 'Int' }, + }, }, Gallery: { - name: "Gallery", + name: 'Gallery', fields: { id: { - name: "id", - type: "Int", + name: 'id', + type: 'Int', id: true, - attributes: [{ name: "@id" }, { name: "@default", args: [{ name: "value", value: ExpressionUtils.call("autoincrement") }] }], - default: ExpressionUtils.call("autoincrement") + attributes: [ + { name: '@id' }, + { name: '@default', args: [{ name: 'value', value: ExpressionUtils.call('autoincrement') }] }, + ], + default: ExpressionUtils.call('autoincrement'), }, images: { - name: "images", - type: "Image", + name: 'images', + type: 'Image', array: true, - relation: { opposite: "gallery" } - } + relation: { opposite: 'gallery' }, + }, }, - idFields: ["id"], + idFields: ['id'], uniqueFields: { - id: { type: "Int" } - } - } + id: { type: 'Int' }, + }, + }, }, - authType: "User", - plugins: {} + authType: 'User', + plugins: {}, } as const satisfies SchemaDef; export type SchemaType = typeof schema; diff --git a/tests/e2e/orm/schemas/name-mapping/input.ts b/tests/e2e/orm/schemas/name-mapping/input.ts index 6c876632..63aa490a 100644 --- a/tests/e2e/orm/schemas/name-mapping/input.ts +++ b/tests/e2e/orm/schemas/name-mapping/input.ts @@ -5,46 +5,77 @@ /* eslint-disable */ -import { type SchemaType as $Schema } from "./schema"; -import type { FindManyArgs as $FindManyArgs, FindUniqueArgs as $FindUniqueArgs, FindFirstArgs as $FindFirstArgs, CreateArgs as $CreateArgs, CreateManyArgs as $CreateManyArgs, CreateManyAndReturnArgs as $CreateManyAndReturnArgs, UpdateArgs as $UpdateArgs, UpdateManyArgs as $UpdateManyArgs, UpdateManyAndReturnArgs as $UpdateManyAndReturnArgs, UpsertArgs as $UpsertArgs, DeleteArgs as $DeleteArgs, DeleteManyArgs as $DeleteManyArgs, CountArgs as $CountArgs, AggregateArgs as $AggregateArgs, GroupByArgs as $GroupByArgs, WhereInput as $WhereInput, SelectInput as $SelectInput, IncludeInput as $IncludeInput, OmitInput as $OmitInput } from "@zenstackhq/orm"; -import type { SimplifiedModelResult as $SimplifiedModelResult, SelectIncludeOmit as $SelectIncludeOmit } from "@zenstackhq/orm"; -export type UserFindManyArgs = $FindManyArgs<$Schema, "User">; -export type UserFindUniqueArgs = $FindUniqueArgs<$Schema, "User">; -export type UserFindFirstArgs = $FindFirstArgs<$Schema, "User">; -export type UserCreateArgs = $CreateArgs<$Schema, "User">; -export type UserCreateManyArgs = $CreateManyArgs<$Schema, "User">; -export type UserCreateManyAndReturnArgs = $CreateManyAndReturnArgs<$Schema, "User">; -export type UserUpdateArgs = $UpdateArgs<$Schema, "User">; -export type UserUpdateManyArgs = $UpdateManyArgs<$Schema, "User">; -export type UserUpdateManyAndReturnArgs = $UpdateManyAndReturnArgs<$Schema, "User">; -export type UserUpsertArgs = $UpsertArgs<$Schema, "User">; -export type UserDeleteArgs = $DeleteArgs<$Schema, "User">; -export type UserDeleteManyArgs = $DeleteManyArgs<$Schema, "User">; -export type UserCountArgs = $CountArgs<$Schema, "User">; -export type UserAggregateArgs = $AggregateArgs<$Schema, "User">; -export type UserGroupByArgs = $GroupByArgs<$Schema, "User">; -export type UserWhereInput = $WhereInput<$Schema, "User">; -export type UserSelect = $SelectInput<$Schema, "User">; -export type UserInclude = $IncludeInput<$Schema, "User">; -export type UserOmit = $OmitInput<$Schema, "User">; -export type UserGetPayload> = $SimplifiedModelResult<$Schema, "User", Args>; -export type PostFindManyArgs = $FindManyArgs<$Schema, "Post">; -export type PostFindUniqueArgs = $FindUniqueArgs<$Schema, "Post">; -export type PostFindFirstArgs = $FindFirstArgs<$Schema, "Post">; -export type PostCreateArgs = $CreateArgs<$Schema, "Post">; -export type PostCreateManyArgs = $CreateManyArgs<$Schema, "Post">; -export type PostCreateManyAndReturnArgs = $CreateManyAndReturnArgs<$Schema, "Post">; -export type PostUpdateArgs = $UpdateArgs<$Schema, "Post">; -export type PostUpdateManyArgs = $UpdateManyArgs<$Schema, "Post">; -export type PostUpdateManyAndReturnArgs = $UpdateManyAndReturnArgs<$Schema, "Post">; -export type PostUpsertArgs = $UpsertArgs<$Schema, "Post">; -export type PostDeleteArgs = $DeleteArgs<$Schema, "Post">; -export type PostDeleteManyArgs = $DeleteManyArgs<$Schema, "Post">; -export type PostCountArgs = $CountArgs<$Schema, "Post">; -export type PostAggregateArgs = $AggregateArgs<$Schema, "Post">; -export type PostGroupByArgs = $GroupByArgs<$Schema, "Post">; -export type PostWhereInput = $WhereInput<$Schema, "Post">; -export type PostSelect = $SelectInput<$Schema, "Post">; -export type PostInclude = $IncludeInput<$Schema, "Post">; -export type PostOmit = $OmitInput<$Schema, "Post">; -export type PostGetPayload> = $SimplifiedModelResult<$Schema, "Post", Args>; +import { type SchemaType as $Schema } from './schema'; +import type { + FindManyArgs as $FindManyArgs, + FindUniqueArgs as $FindUniqueArgs, + FindFirstArgs as $FindFirstArgs, + CreateArgs as $CreateArgs, + CreateManyArgs as $CreateManyArgs, + CreateManyAndReturnArgs as $CreateManyAndReturnArgs, + UpdateArgs as $UpdateArgs, + UpdateManyArgs as $UpdateManyArgs, + UpdateManyAndReturnArgs as $UpdateManyAndReturnArgs, + UpsertArgs as $UpsertArgs, + DeleteArgs as $DeleteArgs, + DeleteManyArgs as $DeleteManyArgs, + CountArgs as $CountArgs, + AggregateArgs as $AggregateArgs, + GroupByArgs as $GroupByArgs, + WhereInput as $WhereInput, + SelectInput as $SelectInput, + IncludeInput as $IncludeInput, + OmitInput as $OmitInput, +} from '@zenstackhq/orm'; +import type { + SimplifiedModelResult as $SimplifiedModelResult, + SelectIncludeOmit as $SelectIncludeOmit, +} from '@zenstackhq/orm'; +export type UserFindManyArgs = $FindManyArgs<$Schema, 'User'>; +export type UserFindUniqueArgs = $FindUniqueArgs<$Schema, 'User'>; +export type UserFindFirstArgs = $FindFirstArgs<$Schema, 'User'>; +export type UserCreateArgs = $CreateArgs<$Schema, 'User'>; +export type UserCreateManyArgs = $CreateManyArgs<$Schema, 'User'>; +export type UserCreateManyAndReturnArgs = $CreateManyAndReturnArgs<$Schema, 'User'>; +export type UserUpdateArgs = $UpdateArgs<$Schema, 'User'>; +export type UserUpdateManyArgs = $UpdateManyArgs<$Schema, 'User'>; +export type UserUpdateManyAndReturnArgs = $UpdateManyAndReturnArgs<$Schema, 'User'>; +export type UserUpsertArgs = $UpsertArgs<$Schema, 'User'>; +export type UserDeleteArgs = $DeleteArgs<$Schema, 'User'>; +export type UserDeleteManyArgs = $DeleteManyArgs<$Schema, 'User'>; +export type UserCountArgs = $CountArgs<$Schema, 'User'>; +export type UserAggregateArgs = $AggregateArgs<$Schema, 'User'>; +export type UserGroupByArgs = $GroupByArgs<$Schema, 'User'>; +export type UserWhereInput = $WhereInput<$Schema, 'User'>; +export type UserSelect = $SelectInput<$Schema, 'User'>; +export type UserInclude = $IncludeInput<$Schema, 'User'>; +export type UserOmit = $OmitInput<$Schema, 'User'>; +export type UserGetPayload> = $SimplifiedModelResult< + $Schema, + 'User', + Args +>; +export type PostFindManyArgs = $FindManyArgs<$Schema, 'Post'>; +export type PostFindUniqueArgs = $FindUniqueArgs<$Schema, 'Post'>; +export type PostFindFirstArgs = $FindFirstArgs<$Schema, 'Post'>; +export type PostCreateArgs = $CreateArgs<$Schema, 'Post'>; +export type PostCreateManyArgs = $CreateManyArgs<$Schema, 'Post'>; +export type PostCreateManyAndReturnArgs = $CreateManyAndReturnArgs<$Schema, 'Post'>; +export type PostUpdateArgs = $UpdateArgs<$Schema, 'Post'>; +export type PostUpdateManyArgs = $UpdateManyArgs<$Schema, 'Post'>; +export type PostUpdateManyAndReturnArgs = $UpdateManyAndReturnArgs<$Schema, 'Post'>; +export type PostUpsertArgs = $UpsertArgs<$Schema, 'Post'>; +export type PostDeleteArgs = $DeleteArgs<$Schema, 'Post'>; +export type PostDeleteManyArgs = $DeleteManyArgs<$Schema, 'Post'>; +export type PostCountArgs = $CountArgs<$Schema, 'Post'>; +export type PostAggregateArgs = $AggregateArgs<$Schema, 'Post'>; +export type PostGroupByArgs = $GroupByArgs<$Schema, 'Post'>; +export type PostWhereInput = $WhereInput<$Schema, 'Post'>; +export type PostSelect = $SelectInput<$Schema, 'Post'>; +export type PostInclude = $IncludeInput<$Schema, 'Post'>; +export type PostOmit = $OmitInput<$Schema, 'Post'>; +export type PostGetPayload> = $SimplifiedModelResult< + $Schema, + 'Post', + Args +>; diff --git a/tests/e2e/orm/schemas/name-mapping/models.ts b/tests/e2e/orm/schemas/name-mapping/models.ts index 72654e58..1d56e435 100644 --- a/tests/e2e/orm/schemas/name-mapping/models.ts +++ b/tests/e2e/orm/schemas/name-mapping/models.ts @@ -5,7 +5,7 @@ /* eslint-disable */ -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">; +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'>; diff --git a/tests/e2e/orm/schemas/name-mapping/schema.ts b/tests/e2e/orm/schemas/name-mapping/schema.ts index 5c27728b..cd26b74d 100644 --- a/tests/e2e/orm/schemas/name-mapping/schema.ts +++ b/tests/e2e/orm/schemas/name-mapping/schema.ts @@ -5,84 +5,99 @@ /* eslint-disable */ -import { type SchemaDef, ExpressionUtils } from "@zenstackhq/orm/schema"; +import { type SchemaDef, ExpressionUtils } from '@zenstackhq/orm/schema'; export const schema = { provider: { - type: "sqlite" + type: 'sqlite', }, models: { User: { - name: "User", + name: 'User', fields: { id: { - name: "id", - type: "Int", + name: 'id', + type: 'Int', id: true, - attributes: [{ name: "@id" }, { name: "@default", args: [{ name: "value", value: ExpressionUtils.call("autoincrement") }] }], - default: ExpressionUtils.call("autoincrement") + attributes: [ + { name: '@id' }, + { name: '@default', args: [{ name: 'value', value: ExpressionUtils.call('autoincrement') }] }, + ], + default: ExpressionUtils.call('autoincrement'), }, email: { - name: "email", - type: "String", + name: 'email', + type: 'String', unique: true, - attributes: [{ name: "@map", args: [{ name: "name", value: ExpressionUtils.literal("user_email") }] }, { name: "@unique" }] + attributes: [ + { name: '@map', args: [{ name: 'name', value: ExpressionUtils.literal('user_email') }] }, + { name: '@unique' }, + ], }, posts: { - name: "posts", - type: "Post", + name: 'posts', + type: 'Post', array: true, - relation: { opposite: "author" } - } + relation: { opposite: 'author' }, + }, }, - attributes: [ - { name: "@@map", args: [{ name: "name", value: ExpressionUtils.literal("users") }] } - ], - idFields: ["id"], + attributes: [{ name: '@@map', args: [{ name: 'name', value: ExpressionUtils.literal('users') }] }], + idFields: ['id'], uniqueFields: { - id: { type: "Int" }, - email: { type: "String" } - } + id: { type: 'Int' }, + email: { type: 'String' }, + }, }, Post: { - name: "Post", + name: 'Post', fields: { id: { - name: "id", - type: "Int", + name: 'id', + type: 'Int', id: true, - attributes: [{ name: "@id" }, { name: "@default", args: [{ name: "value", value: ExpressionUtils.call("autoincrement") }] }], - default: ExpressionUtils.call("autoincrement") + attributes: [ + { name: '@id' }, + { name: '@default', args: [{ name: 'value', value: ExpressionUtils.call('autoincrement') }] }, + ], + default: ExpressionUtils.call('autoincrement'), }, title: { - name: "title", - type: "String", - attributes: [{ name: "@map", args: [{ name: "name", value: ExpressionUtils.literal("post_title") }] }] + name: 'title', + type: 'String', + attributes: [ + { name: '@map', args: [{ name: 'name', value: ExpressionUtils.literal('post_title') }] }, + ], }, author: { - name: "author", - type: "User", - attributes: [{ name: "@relation", args: [{ name: "fields", value: ExpressionUtils.array([ExpressionUtils.field("authorId")]) }, { name: "references", value: ExpressionUtils.array([ExpressionUtils.field("id")]) }] }], - relation: { opposite: "posts", fields: ["authorId"], references: ["id"] } + name: 'author', + type: 'User', + attributes: [ + { + name: '@relation', + args: [ + { name: 'fields', value: ExpressionUtils.array([ExpressionUtils.field('authorId')]) }, + { name: 'references', value: ExpressionUtils.array([ExpressionUtils.field('id')]) }, + ], + }, + ], + relation: { opposite: 'posts', fields: ['authorId'], references: ['id'] }, }, authorId: { - name: "authorId", - type: "Int", - attributes: [{ name: "@map", args: [{ name: "name", value: ExpressionUtils.literal("author_id") }] }], - foreignKeyFor: [ - "author" - ] - } + name: 'authorId', + type: 'Int', + attributes: [ + { name: '@map', args: [{ name: 'name', value: ExpressionUtils.literal('author_id') }] }, + ], + foreignKeyFor: ['author'], + }, }, - attributes: [ - { name: "@@map", args: [{ name: "name", value: ExpressionUtils.literal("posts") }] } - ], - idFields: ["id"], + attributes: [{ name: '@@map', args: [{ name: 'name', value: ExpressionUtils.literal('posts') }] }], + idFields: ['id'], uniqueFields: { - id: { type: "Int" } - } - } + id: { type: 'Int' }, + }, + }, }, - authType: "User", - plugins: {} + authType: 'User', + plugins: {}, } as const satisfies SchemaDef; export type SchemaType = typeof schema; diff --git a/tests/e2e/orm/schemas/petstore/input.ts b/tests/e2e/orm/schemas/petstore/input.ts index 690d1d90..e6cf9c14 100644 --- a/tests/e2e/orm/schemas/petstore/input.ts +++ b/tests/e2e/orm/schemas/petstore/input.ts @@ -5,66 +5,101 @@ /* eslint-disable */ -import { type SchemaType as $Schema } from "./schema"; -import type { FindManyArgs as $FindManyArgs, FindUniqueArgs as $FindUniqueArgs, FindFirstArgs as $FindFirstArgs, CreateArgs as $CreateArgs, CreateManyArgs as $CreateManyArgs, CreateManyAndReturnArgs as $CreateManyAndReturnArgs, UpdateArgs as $UpdateArgs, UpdateManyArgs as $UpdateManyArgs, UpdateManyAndReturnArgs as $UpdateManyAndReturnArgs, UpsertArgs as $UpsertArgs, DeleteArgs as $DeleteArgs, DeleteManyArgs as $DeleteManyArgs, CountArgs as $CountArgs, AggregateArgs as $AggregateArgs, GroupByArgs as $GroupByArgs, WhereInput as $WhereInput, SelectInput as $SelectInput, IncludeInput as $IncludeInput, OmitInput as $OmitInput } from "@zenstackhq/orm"; -import type { SimplifiedModelResult as $SimplifiedModelResult, SelectIncludeOmit as $SelectIncludeOmit } from "@zenstackhq/orm"; -export type UserFindManyArgs = $FindManyArgs<$Schema, "User">; -export type UserFindUniqueArgs = $FindUniqueArgs<$Schema, "User">; -export type UserFindFirstArgs = $FindFirstArgs<$Schema, "User">; -export type UserCreateArgs = $CreateArgs<$Schema, "User">; -export type UserCreateManyArgs = $CreateManyArgs<$Schema, "User">; -export type UserCreateManyAndReturnArgs = $CreateManyAndReturnArgs<$Schema, "User">; -export type UserUpdateArgs = $UpdateArgs<$Schema, "User">; -export type UserUpdateManyArgs = $UpdateManyArgs<$Schema, "User">; -export type UserUpdateManyAndReturnArgs = $UpdateManyAndReturnArgs<$Schema, "User">; -export type UserUpsertArgs = $UpsertArgs<$Schema, "User">; -export type UserDeleteArgs = $DeleteArgs<$Schema, "User">; -export type UserDeleteManyArgs = $DeleteManyArgs<$Schema, "User">; -export type UserCountArgs = $CountArgs<$Schema, "User">; -export type UserAggregateArgs = $AggregateArgs<$Schema, "User">; -export type UserGroupByArgs = $GroupByArgs<$Schema, "User">; -export type UserWhereInput = $WhereInput<$Schema, "User">; -export type UserSelect = $SelectInput<$Schema, "User">; -export type UserInclude = $IncludeInput<$Schema, "User">; -export type UserOmit = $OmitInput<$Schema, "User">; -export type UserGetPayload> = $SimplifiedModelResult<$Schema, "User", Args>; -export type PetFindManyArgs = $FindManyArgs<$Schema, "Pet">; -export type PetFindUniqueArgs = $FindUniqueArgs<$Schema, "Pet">; -export type PetFindFirstArgs = $FindFirstArgs<$Schema, "Pet">; -export type PetCreateArgs = $CreateArgs<$Schema, "Pet">; -export type PetCreateManyArgs = $CreateManyArgs<$Schema, "Pet">; -export type PetCreateManyAndReturnArgs = $CreateManyAndReturnArgs<$Schema, "Pet">; -export type PetUpdateArgs = $UpdateArgs<$Schema, "Pet">; -export type PetUpdateManyArgs = $UpdateManyArgs<$Schema, "Pet">; -export type PetUpdateManyAndReturnArgs = $UpdateManyAndReturnArgs<$Schema, "Pet">; -export type PetUpsertArgs = $UpsertArgs<$Schema, "Pet">; -export type PetDeleteArgs = $DeleteArgs<$Schema, "Pet">; -export type PetDeleteManyArgs = $DeleteManyArgs<$Schema, "Pet">; -export type PetCountArgs = $CountArgs<$Schema, "Pet">; -export type PetAggregateArgs = $AggregateArgs<$Schema, "Pet">; -export type PetGroupByArgs = $GroupByArgs<$Schema, "Pet">; -export type PetWhereInput = $WhereInput<$Schema, "Pet">; -export type PetSelect = $SelectInput<$Schema, "Pet">; -export type PetInclude = $IncludeInput<$Schema, "Pet">; -export type PetOmit = $OmitInput<$Schema, "Pet">; -export type PetGetPayload> = $SimplifiedModelResult<$Schema, "Pet", Args>; -export type OrderFindManyArgs = $FindManyArgs<$Schema, "Order">; -export type OrderFindUniqueArgs = $FindUniqueArgs<$Schema, "Order">; -export type OrderFindFirstArgs = $FindFirstArgs<$Schema, "Order">; -export type OrderCreateArgs = $CreateArgs<$Schema, "Order">; -export type OrderCreateManyArgs = $CreateManyArgs<$Schema, "Order">; -export type OrderCreateManyAndReturnArgs = $CreateManyAndReturnArgs<$Schema, "Order">; -export type OrderUpdateArgs = $UpdateArgs<$Schema, "Order">; -export type OrderUpdateManyArgs = $UpdateManyArgs<$Schema, "Order">; -export type OrderUpdateManyAndReturnArgs = $UpdateManyAndReturnArgs<$Schema, "Order">; -export type OrderUpsertArgs = $UpsertArgs<$Schema, "Order">; -export type OrderDeleteArgs = $DeleteArgs<$Schema, "Order">; -export type OrderDeleteManyArgs = $DeleteManyArgs<$Schema, "Order">; -export type OrderCountArgs = $CountArgs<$Schema, "Order">; -export type OrderAggregateArgs = $AggregateArgs<$Schema, "Order">; -export type OrderGroupByArgs = $GroupByArgs<$Schema, "Order">; -export type OrderWhereInput = $WhereInput<$Schema, "Order">; -export type OrderSelect = $SelectInput<$Schema, "Order">; -export type OrderInclude = $IncludeInput<$Schema, "Order">; -export type OrderOmit = $OmitInput<$Schema, "Order">; -export type OrderGetPayload> = $SimplifiedModelResult<$Schema, "Order", Args>; +import { type SchemaType as $Schema } from './schema'; +import type { + FindManyArgs as $FindManyArgs, + FindUniqueArgs as $FindUniqueArgs, + FindFirstArgs as $FindFirstArgs, + CreateArgs as $CreateArgs, + CreateManyArgs as $CreateManyArgs, + CreateManyAndReturnArgs as $CreateManyAndReturnArgs, + UpdateArgs as $UpdateArgs, + UpdateManyArgs as $UpdateManyArgs, + UpdateManyAndReturnArgs as $UpdateManyAndReturnArgs, + UpsertArgs as $UpsertArgs, + DeleteArgs as $DeleteArgs, + DeleteManyArgs as $DeleteManyArgs, + CountArgs as $CountArgs, + AggregateArgs as $AggregateArgs, + GroupByArgs as $GroupByArgs, + WhereInput as $WhereInput, + SelectInput as $SelectInput, + IncludeInput as $IncludeInput, + OmitInput as $OmitInput, +} from '@zenstackhq/orm'; +import type { + SimplifiedModelResult as $SimplifiedModelResult, + SelectIncludeOmit as $SelectIncludeOmit, +} from '@zenstackhq/orm'; +export type UserFindManyArgs = $FindManyArgs<$Schema, 'User'>; +export type UserFindUniqueArgs = $FindUniqueArgs<$Schema, 'User'>; +export type UserFindFirstArgs = $FindFirstArgs<$Schema, 'User'>; +export type UserCreateArgs = $CreateArgs<$Schema, 'User'>; +export type UserCreateManyArgs = $CreateManyArgs<$Schema, 'User'>; +export type UserCreateManyAndReturnArgs = $CreateManyAndReturnArgs<$Schema, 'User'>; +export type UserUpdateArgs = $UpdateArgs<$Schema, 'User'>; +export type UserUpdateManyArgs = $UpdateManyArgs<$Schema, 'User'>; +export type UserUpdateManyAndReturnArgs = $UpdateManyAndReturnArgs<$Schema, 'User'>; +export type UserUpsertArgs = $UpsertArgs<$Schema, 'User'>; +export type UserDeleteArgs = $DeleteArgs<$Schema, 'User'>; +export type UserDeleteManyArgs = $DeleteManyArgs<$Schema, 'User'>; +export type UserCountArgs = $CountArgs<$Schema, 'User'>; +export type UserAggregateArgs = $AggregateArgs<$Schema, 'User'>; +export type UserGroupByArgs = $GroupByArgs<$Schema, 'User'>; +export type UserWhereInput = $WhereInput<$Schema, 'User'>; +export type UserSelect = $SelectInput<$Schema, 'User'>; +export type UserInclude = $IncludeInput<$Schema, 'User'>; +export type UserOmit = $OmitInput<$Schema, 'User'>; +export type UserGetPayload> = $SimplifiedModelResult< + $Schema, + 'User', + Args +>; +export type PetFindManyArgs = $FindManyArgs<$Schema, 'Pet'>; +export type PetFindUniqueArgs = $FindUniqueArgs<$Schema, 'Pet'>; +export type PetFindFirstArgs = $FindFirstArgs<$Schema, 'Pet'>; +export type PetCreateArgs = $CreateArgs<$Schema, 'Pet'>; +export type PetCreateManyArgs = $CreateManyArgs<$Schema, 'Pet'>; +export type PetCreateManyAndReturnArgs = $CreateManyAndReturnArgs<$Schema, 'Pet'>; +export type PetUpdateArgs = $UpdateArgs<$Schema, 'Pet'>; +export type PetUpdateManyArgs = $UpdateManyArgs<$Schema, 'Pet'>; +export type PetUpdateManyAndReturnArgs = $UpdateManyAndReturnArgs<$Schema, 'Pet'>; +export type PetUpsertArgs = $UpsertArgs<$Schema, 'Pet'>; +export type PetDeleteArgs = $DeleteArgs<$Schema, 'Pet'>; +export type PetDeleteManyArgs = $DeleteManyArgs<$Schema, 'Pet'>; +export type PetCountArgs = $CountArgs<$Schema, 'Pet'>; +export type PetAggregateArgs = $AggregateArgs<$Schema, 'Pet'>; +export type PetGroupByArgs = $GroupByArgs<$Schema, 'Pet'>; +export type PetWhereInput = $WhereInput<$Schema, 'Pet'>; +export type PetSelect = $SelectInput<$Schema, 'Pet'>; +export type PetInclude = $IncludeInput<$Schema, 'Pet'>; +export type PetOmit = $OmitInput<$Schema, 'Pet'>; +export type PetGetPayload> = $SimplifiedModelResult< + $Schema, + 'Pet', + Args +>; +export type OrderFindManyArgs = $FindManyArgs<$Schema, 'Order'>; +export type OrderFindUniqueArgs = $FindUniqueArgs<$Schema, 'Order'>; +export type OrderFindFirstArgs = $FindFirstArgs<$Schema, 'Order'>; +export type OrderCreateArgs = $CreateArgs<$Schema, 'Order'>; +export type OrderCreateManyArgs = $CreateManyArgs<$Schema, 'Order'>; +export type OrderCreateManyAndReturnArgs = $CreateManyAndReturnArgs<$Schema, 'Order'>; +export type OrderUpdateArgs = $UpdateArgs<$Schema, 'Order'>; +export type OrderUpdateManyArgs = $UpdateManyArgs<$Schema, 'Order'>; +export type OrderUpdateManyAndReturnArgs = $UpdateManyAndReturnArgs<$Schema, 'Order'>; +export type OrderUpsertArgs = $UpsertArgs<$Schema, 'Order'>; +export type OrderDeleteArgs = $DeleteArgs<$Schema, 'Order'>; +export type OrderDeleteManyArgs = $DeleteManyArgs<$Schema, 'Order'>; +export type OrderCountArgs = $CountArgs<$Schema, 'Order'>; +export type OrderAggregateArgs = $AggregateArgs<$Schema, 'Order'>; +export type OrderGroupByArgs = $GroupByArgs<$Schema, 'Order'>; +export type OrderWhereInput = $WhereInput<$Schema, 'Order'>; +export type OrderSelect = $SelectInput<$Schema, 'Order'>; +export type OrderInclude = $IncludeInput<$Schema, 'Order'>; +export type OrderOmit = $OmitInput<$Schema, 'Order'>; +export type OrderGetPayload> = $SimplifiedModelResult< + $Schema, + 'Order', + Args +>; diff --git a/tests/e2e/orm/schemas/petstore/models.ts b/tests/e2e/orm/schemas/petstore/models.ts index dfa5b23e..840f39bb 100644 --- a/tests/e2e/orm/schemas/petstore/models.ts +++ b/tests/e2e/orm/schemas/petstore/models.ts @@ -5,8 +5,8 @@ /* eslint-disable */ -import { type SchemaType as $Schema } from "./schema"; -import { type ModelResult as $ModelResult } from "@zenstackhq/orm"; -export type User = $ModelResult<$Schema, "User">; -export type Pet = $ModelResult<$Schema, "Pet">; -export type Order = $ModelResult<$Schema, "Order">; +import { type SchemaType as $Schema } from './schema'; +import { type ModelResult as $ModelResult } from '@zenstackhq/orm'; +export type User = $ModelResult<$Schema, 'User'>; +export type Pet = $ModelResult<$Schema, 'Pet'>; +export type Order = $ModelResult<$Schema, 'Order'>; diff --git a/tests/e2e/orm/schemas/petstore/schema.ts b/tests/e2e/orm/schemas/petstore/schema.ts index 747372a7..0db944f1 100644 --- a/tests/e2e/orm/schemas/petstore/schema.ts +++ b/tests/e2e/orm/schemas/petstore/schema.ts @@ -5,153 +5,254 @@ /* eslint-disable */ -import { type SchemaDef, ExpressionUtils } from "@zenstackhq/orm/schema"; +import { type SchemaDef, ExpressionUtils } from '@zenstackhq/orm/schema'; export const schema = { provider: { - type: "sqlite" + type: 'sqlite', }, models: { User: { - name: "User", + name: 'User', fields: { id: { - name: "id", - type: "String", + name: 'id', + type: 'String', id: true, - attributes: [{ name: "@id" }, { name: "@default", args: [{ name: "value", value: ExpressionUtils.call("cuid") }] }], - default: ExpressionUtils.call("cuid") + attributes: [ + { name: '@id' }, + { name: '@default', args: [{ name: 'value', value: ExpressionUtils.call('cuid') }] }, + ], + default: ExpressionUtils.call('cuid'), }, email: { - name: "email", - type: "String", + name: 'email', + type: 'String', unique: true, - attributes: [{ name: "@unique" }] + attributes: [{ name: '@unique' }], }, orders: { - name: "orders", - type: "Order", + name: 'orders', + type: 'Order', array: true, - relation: { opposite: "user" } - } + relation: { opposite: 'user' }, + }, }, attributes: [ - { name: "@@allow", args: [{ name: "operation", value: ExpressionUtils.literal("create") }, { name: "condition", value: ExpressionUtils.literal(true) }] }, - { name: "@@allow", args: [{ name: "operation", value: ExpressionUtils.literal("read") }, { name: "condition", value: ExpressionUtils.literal(true) }] } + { + name: '@@allow', + args: [ + { name: 'operation', value: ExpressionUtils.literal('create') }, + { name: 'condition', value: ExpressionUtils.literal(true) }, + ], + }, + { + name: '@@allow', + args: [ + { name: 'operation', value: ExpressionUtils.literal('read') }, + { name: 'condition', value: ExpressionUtils.literal(true) }, + ], + }, ], - idFields: ["id"], + idFields: ['id'], uniqueFields: { - id: { type: "String" }, - email: { type: "String" } - } + id: { type: 'String' }, + email: { type: 'String' }, + }, }, Pet: { - name: "Pet", + name: 'Pet', fields: { id: { - name: "id", - type: "String", + name: 'id', + type: 'String', id: true, - attributes: [{ name: "@id" }, { name: "@default", args: [{ name: "value", value: ExpressionUtils.call("cuid") }] }], - default: ExpressionUtils.call("cuid") + 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") + name: 'createdAt', + type: 'DateTime', + attributes: [{ name: '@default', args: [{ name: 'value', value: ExpressionUtils.call('now') }] }], + default: ExpressionUtils.call('now'), }, updatedAt: { - name: "updatedAt", - type: "DateTime", + name: 'updatedAt', + type: 'DateTime', updatedAt: true, - attributes: [{ name: "@updatedAt" }] + attributes: [{ name: '@updatedAt' }], }, name: { - name: "name", - type: "String" + name: 'name', + type: 'String', }, category: { - name: "category", - type: "String" + name: 'category', + type: 'String', }, order: { - name: "order", - type: "Order", + name: 'order', + type: 'Order', optional: true, - attributes: [{ name: "@relation", args: [{ name: "fields", value: ExpressionUtils.array([ExpressionUtils.field("orderId")]) }, { name: "references", value: ExpressionUtils.array([ExpressionUtils.field("id")]) }] }], - relation: { opposite: "pets", fields: ["orderId"], references: ["id"] } + attributes: [ + { + name: '@relation', + args: [ + { name: 'fields', value: ExpressionUtils.array([ExpressionUtils.field('orderId')]) }, + { name: 'references', value: ExpressionUtils.array([ExpressionUtils.field('id')]) }, + ], + }, + ], + relation: { opposite: 'pets', fields: ['orderId'], references: ['id'] }, }, orderId: { - name: "orderId", - type: "String", + name: 'orderId', + type: 'String', optional: true, - foreignKeyFor: [ - "order" - ] - } + foreignKeyFor: ['order'], + }, }, attributes: [ - { name: "@@allow", args: [{ name: "operation", value: ExpressionUtils.literal("read") }, { name: "condition", value: ExpressionUtils.binary(ExpressionUtils.binary(ExpressionUtils.field("orderId"), "==", ExpressionUtils._null()), "||", ExpressionUtils.binary(ExpressionUtils.member(ExpressionUtils.field("order"), ["user"]), "==", ExpressionUtils.call("auth"))) }] }, - { name: "@@allow", args: [{ name: "operation", value: ExpressionUtils.literal("update") }, { name: "condition", value: ExpressionUtils.binary(ExpressionUtils.call("auth"), "!=", ExpressionUtils._null()) }] }, - { name: "@@allow", args: [{ name: "operation", value: ExpressionUtils.literal("post-update") }, { name: "condition", value: ExpressionUtils.binary(ExpressionUtils.binary(ExpressionUtils.binary(ExpressionUtils.member(ExpressionUtils.call("before"), ["name"]), "==", ExpressionUtils.field("name")), "&&", ExpressionUtils.binary(ExpressionUtils.member(ExpressionUtils.call("before"), ["category"]), "==", ExpressionUtils.field("category"))), "&&", ExpressionUtils.binary(ExpressionUtils.member(ExpressionUtils.call("before"), ["orderId"]), "==", ExpressionUtils._null())) }] } + { + name: '@@allow', + args: [ + { name: 'operation', value: ExpressionUtils.literal('read') }, + { + name: 'condition', + value: ExpressionUtils.binary( + ExpressionUtils.binary(ExpressionUtils.field('orderId'), '==', ExpressionUtils._null()), + '||', + ExpressionUtils.binary( + ExpressionUtils.member(ExpressionUtils.field('order'), ['user']), + '==', + ExpressionUtils.call('auth'), + ), + ), + }, + ], + }, + { + name: '@@allow', + args: [ + { name: 'operation', value: ExpressionUtils.literal('update') }, + { + name: 'condition', + value: ExpressionUtils.binary(ExpressionUtils.call('auth'), '!=', ExpressionUtils._null()), + }, + ], + }, + { + name: '@@allow', + args: [ + { name: 'operation', value: ExpressionUtils.literal('post-update') }, + { + name: 'condition', + value: ExpressionUtils.binary( + ExpressionUtils.binary( + ExpressionUtils.binary( + ExpressionUtils.member(ExpressionUtils.call('before'), ['name']), + '==', + ExpressionUtils.field('name'), + ), + '&&', + ExpressionUtils.binary( + ExpressionUtils.member(ExpressionUtils.call('before'), ['category']), + '==', + ExpressionUtils.field('category'), + ), + ), + '&&', + ExpressionUtils.binary( + ExpressionUtils.member(ExpressionUtils.call('before'), ['orderId']), + '==', + ExpressionUtils._null(), + ), + ), + }, + ], + }, ], - idFields: ["id"], + idFields: ['id'], uniqueFields: { - id: { type: "String" } - } + id: { type: 'String' }, + }, }, Order: { - name: "Order", + name: 'Order', fields: { id: { - name: "id", - type: "String", + name: 'id', + type: 'String', id: true, - attributes: [{ name: "@id" }, { name: "@default", args: [{ name: "value", value: ExpressionUtils.call("cuid") }] }], - default: ExpressionUtils.call("cuid") + 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") + name: 'createdAt', + type: 'DateTime', + attributes: [{ name: '@default', args: [{ name: 'value', value: ExpressionUtils.call('now') }] }], + default: ExpressionUtils.call('now'), }, updatedAt: { - name: "updatedAt", - type: "DateTime", + name: 'updatedAt', + type: 'DateTime', updatedAt: true, - attributes: [{ name: "@updatedAt" }] + attributes: [{ name: '@updatedAt' }], }, pets: { - name: "pets", - type: "Pet", + name: 'pets', + type: 'Pet', array: true, - relation: { opposite: "order" } + relation: { opposite: 'order' }, }, user: { - name: "user", - type: "User", - attributes: [{ name: "@relation", args: [{ name: "fields", value: ExpressionUtils.array([ExpressionUtils.field("userId")]) }, { name: "references", value: ExpressionUtils.array([ExpressionUtils.field("id")]) }] }], - relation: { opposite: "orders", fields: ["userId"], references: ["id"] } + name: 'user', + type: 'User', + attributes: [ + { + name: '@relation', + args: [ + { name: 'fields', value: ExpressionUtils.array([ExpressionUtils.field('userId')]) }, + { name: 'references', value: ExpressionUtils.array([ExpressionUtils.field('id')]) }, + ], + }, + ], + relation: { opposite: 'orders', fields: ['userId'], references: ['id'] }, }, userId: { - name: "userId", - type: "String", - foreignKeyFor: [ - "user" - ] - } + name: 'userId', + type: 'String', + foreignKeyFor: ['user'], + }, }, attributes: [ - { name: "@@allow", args: [{ name: "operation", value: ExpressionUtils.literal("read,create") }, { name: "condition", value: ExpressionUtils.binary(ExpressionUtils.call("auth"), "==", ExpressionUtils.field("user")) }] } + { + name: '@@allow', + args: [ + { name: 'operation', value: ExpressionUtils.literal('read,create') }, + { + name: 'condition', + value: ExpressionUtils.binary( + ExpressionUtils.call('auth'), + '==', + ExpressionUtils.field('user'), + ), + }, + ], + }, ], - idFields: ["id"], + idFields: ['id'], uniqueFields: { - id: { type: "String" } - } - } + id: { type: 'String' }, + }, + }, }, - authType: "User", - plugins: {} + authType: 'User', + plugins: {}, } as const satisfies SchemaDef; export type SchemaType = typeof schema; diff --git a/tests/e2e/orm/schemas/todo/input.ts b/tests/e2e/orm/schemas/todo/input.ts index 22fd5a19..ac856b06 100644 --- a/tests/e2e/orm/schemas/todo/input.ts +++ b/tests/e2e/orm/schemas/todo/input.ts @@ -5,106 +5,149 @@ /* eslint-disable */ -import { type SchemaType as $Schema } from "./schema"; -import type { FindManyArgs as $FindManyArgs, FindUniqueArgs as $FindUniqueArgs, FindFirstArgs as $FindFirstArgs, CreateArgs as $CreateArgs, CreateManyArgs as $CreateManyArgs, CreateManyAndReturnArgs as $CreateManyAndReturnArgs, UpdateArgs as $UpdateArgs, UpdateManyArgs as $UpdateManyArgs, UpdateManyAndReturnArgs as $UpdateManyAndReturnArgs, UpsertArgs as $UpsertArgs, DeleteArgs as $DeleteArgs, DeleteManyArgs as $DeleteManyArgs, CountArgs as $CountArgs, AggregateArgs as $AggregateArgs, GroupByArgs as $GroupByArgs, WhereInput as $WhereInput, SelectInput as $SelectInput, IncludeInput as $IncludeInput, OmitInput as $OmitInput } from "@zenstackhq/orm"; -import type { SimplifiedModelResult as $SimplifiedModelResult, SelectIncludeOmit as $SelectIncludeOmit } from "@zenstackhq/orm"; -export type SpaceFindManyArgs = $FindManyArgs<$Schema, "Space">; -export type SpaceFindUniqueArgs = $FindUniqueArgs<$Schema, "Space">; -export type SpaceFindFirstArgs = $FindFirstArgs<$Schema, "Space">; -export type SpaceCreateArgs = $CreateArgs<$Schema, "Space">; -export type SpaceCreateManyArgs = $CreateManyArgs<$Schema, "Space">; -export type SpaceCreateManyAndReturnArgs = $CreateManyAndReturnArgs<$Schema, "Space">; -export type SpaceUpdateArgs = $UpdateArgs<$Schema, "Space">; -export type SpaceUpdateManyArgs = $UpdateManyArgs<$Schema, "Space">; -export type SpaceUpdateManyAndReturnArgs = $UpdateManyAndReturnArgs<$Schema, "Space">; -export type SpaceUpsertArgs = $UpsertArgs<$Schema, "Space">; -export type SpaceDeleteArgs = $DeleteArgs<$Schema, "Space">; -export type SpaceDeleteManyArgs = $DeleteManyArgs<$Schema, "Space">; -export type SpaceCountArgs = $CountArgs<$Schema, "Space">; -export type SpaceAggregateArgs = $AggregateArgs<$Schema, "Space">; -export type SpaceGroupByArgs = $GroupByArgs<$Schema, "Space">; -export type SpaceWhereInput = $WhereInput<$Schema, "Space">; -export type SpaceSelect = $SelectInput<$Schema, "Space">; -export type SpaceInclude = $IncludeInput<$Schema, "Space">; -export type SpaceOmit = $OmitInput<$Schema, "Space">; -export type SpaceGetPayload> = $SimplifiedModelResult<$Schema, "Space", Args>; -export type SpaceUserFindManyArgs = $FindManyArgs<$Schema, "SpaceUser">; -export type SpaceUserFindUniqueArgs = $FindUniqueArgs<$Schema, "SpaceUser">; -export type SpaceUserFindFirstArgs = $FindFirstArgs<$Schema, "SpaceUser">; -export type SpaceUserCreateArgs = $CreateArgs<$Schema, "SpaceUser">; -export type SpaceUserCreateManyArgs = $CreateManyArgs<$Schema, "SpaceUser">; -export type SpaceUserCreateManyAndReturnArgs = $CreateManyAndReturnArgs<$Schema, "SpaceUser">; -export type SpaceUserUpdateArgs = $UpdateArgs<$Schema, "SpaceUser">; -export type SpaceUserUpdateManyArgs = $UpdateManyArgs<$Schema, "SpaceUser">; -export type SpaceUserUpdateManyAndReturnArgs = $UpdateManyAndReturnArgs<$Schema, "SpaceUser">; -export type SpaceUserUpsertArgs = $UpsertArgs<$Schema, "SpaceUser">; -export type SpaceUserDeleteArgs = $DeleteArgs<$Schema, "SpaceUser">; -export type SpaceUserDeleteManyArgs = $DeleteManyArgs<$Schema, "SpaceUser">; -export type SpaceUserCountArgs = $CountArgs<$Schema, "SpaceUser">; -export type SpaceUserAggregateArgs = $AggregateArgs<$Schema, "SpaceUser">; -export type SpaceUserGroupByArgs = $GroupByArgs<$Schema, "SpaceUser">; -export type SpaceUserWhereInput = $WhereInput<$Schema, "SpaceUser">; -export type SpaceUserSelect = $SelectInput<$Schema, "SpaceUser">; -export type SpaceUserInclude = $IncludeInput<$Schema, "SpaceUser">; -export type SpaceUserOmit = $OmitInput<$Schema, "SpaceUser">; -export type SpaceUserGetPayload> = $SimplifiedModelResult<$Schema, "SpaceUser", Args>; -export type UserFindManyArgs = $FindManyArgs<$Schema, "User">; -export type UserFindUniqueArgs = $FindUniqueArgs<$Schema, "User">; -export type UserFindFirstArgs = $FindFirstArgs<$Schema, "User">; -export type UserCreateArgs = $CreateArgs<$Schema, "User">; -export type UserCreateManyArgs = $CreateManyArgs<$Schema, "User">; -export type UserCreateManyAndReturnArgs = $CreateManyAndReturnArgs<$Schema, "User">; -export type UserUpdateArgs = $UpdateArgs<$Schema, "User">; -export type UserUpdateManyArgs = $UpdateManyArgs<$Schema, "User">; -export type UserUpdateManyAndReturnArgs = $UpdateManyAndReturnArgs<$Schema, "User">; -export type UserUpsertArgs = $UpsertArgs<$Schema, "User">; -export type UserDeleteArgs = $DeleteArgs<$Schema, "User">; -export type UserDeleteManyArgs = $DeleteManyArgs<$Schema, "User">; -export type UserCountArgs = $CountArgs<$Schema, "User">; -export type UserAggregateArgs = $AggregateArgs<$Schema, "User">; -export type UserGroupByArgs = $GroupByArgs<$Schema, "User">; -export type UserWhereInput = $WhereInput<$Schema, "User">; -export type UserSelect = $SelectInput<$Schema, "User">; -export type UserInclude = $IncludeInput<$Schema, "User">; -export type UserOmit = $OmitInput<$Schema, "User">; -export type UserGetPayload> = $SimplifiedModelResult<$Schema, "User", Args>; -export type ListFindManyArgs = $FindManyArgs<$Schema, "List">; -export type ListFindUniqueArgs = $FindUniqueArgs<$Schema, "List">; -export type ListFindFirstArgs = $FindFirstArgs<$Schema, "List">; -export type ListCreateArgs = $CreateArgs<$Schema, "List">; -export type ListCreateManyArgs = $CreateManyArgs<$Schema, "List">; -export type ListCreateManyAndReturnArgs = $CreateManyAndReturnArgs<$Schema, "List">; -export type ListUpdateArgs = $UpdateArgs<$Schema, "List">; -export type ListUpdateManyArgs = $UpdateManyArgs<$Schema, "List">; -export type ListUpdateManyAndReturnArgs = $UpdateManyAndReturnArgs<$Schema, "List">; -export type ListUpsertArgs = $UpsertArgs<$Schema, "List">; -export type ListDeleteArgs = $DeleteArgs<$Schema, "List">; -export type ListDeleteManyArgs = $DeleteManyArgs<$Schema, "List">; -export type ListCountArgs = $CountArgs<$Schema, "List">; -export type ListAggregateArgs = $AggregateArgs<$Schema, "List">; -export type ListGroupByArgs = $GroupByArgs<$Schema, "List">; -export type ListWhereInput = $WhereInput<$Schema, "List">; -export type ListSelect = $SelectInput<$Schema, "List">; -export type ListInclude = $IncludeInput<$Schema, "List">; -export type ListOmit = $OmitInput<$Schema, "List">; -export type ListGetPayload> = $SimplifiedModelResult<$Schema, "List", Args>; -export type TodoFindManyArgs = $FindManyArgs<$Schema, "Todo">; -export type TodoFindUniqueArgs = $FindUniqueArgs<$Schema, "Todo">; -export type TodoFindFirstArgs = $FindFirstArgs<$Schema, "Todo">; -export type TodoCreateArgs = $CreateArgs<$Schema, "Todo">; -export type TodoCreateManyArgs = $CreateManyArgs<$Schema, "Todo">; -export type TodoCreateManyAndReturnArgs = $CreateManyAndReturnArgs<$Schema, "Todo">; -export type TodoUpdateArgs = $UpdateArgs<$Schema, "Todo">; -export type TodoUpdateManyArgs = $UpdateManyArgs<$Schema, "Todo">; -export type TodoUpdateManyAndReturnArgs = $UpdateManyAndReturnArgs<$Schema, "Todo">; -export type TodoUpsertArgs = $UpsertArgs<$Schema, "Todo">; -export type TodoDeleteArgs = $DeleteArgs<$Schema, "Todo">; -export type TodoDeleteManyArgs = $DeleteManyArgs<$Schema, "Todo">; -export type TodoCountArgs = $CountArgs<$Schema, "Todo">; -export type TodoAggregateArgs = $AggregateArgs<$Schema, "Todo">; -export type TodoGroupByArgs = $GroupByArgs<$Schema, "Todo">; -export type TodoWhereInput = $WhereInput<$Schema, "Todo">; -export type TodoSelect = $SelectInput<$Schema, "Todo">; -export type TodoInclude = $IncludeInput<$Schema, "Todo">; -export type TodoOmit = $OmitInput<$Schema, "Todo">; -export type TodoGetPayload> = $SimplifiedModelResult<$Schema, "Todo", Args>; +import { type SchemaType as $Schema } from './schema'; +import type { + FindManyArgs as $FindManyArgs, + FindUniqueArgs as $FindUniqueArgs, + FindFirstArgs as $FindFirstArgs, + CreateArgs as $CreateArgs, + CreateManyArgs as $CreateManyArgs, + CreateManyAndReturnArgs as $CreateManyAndReturnArgs, + UpdateArgs as $UpdateArgs, + UpdateManyArgs as $UpdateManyArgs, + UpdateManyAndReturnArgs as $UpdateManyAndReturnArgs, + UpsertArgs as $UpsertArgs, + DeleteArgs as $DeleteArgs, + DeleteManyArgs as $DeleteManyArgs, + CountArgs as $CountArgs, + AggregateArgs as $AggregateArgs, + GroupByArgs as $GroupByArgs, + WhereInput as $WhereInput, + SelectInput as $SelectInput, + IncludeInput as $IncludeInput, + OmitInput as $OmitInput, +} from '@zenstackhq/orm'; +import type { + SimplifiedModelResult as $SimplifiedModelResult, + SelectIncludeOmit as $SelectIncludeOmit, +} from '@zenstackhq/orm'; +export type SpaceFindManyArgs = $FindManyArgs<$Schema, 'Space'>; +export type SpaceFindUniqueArgs = $FindUniqueArgs<$Schema, 'Space'>; +export type SpaceFindFirstArgs = $FindFirstArgs<$Schema, 'Space'>; +export type SpaceCreateArgs = $CreateArgs<$Schema, 'Space'>; +export type SpaceCreateManyArgs = $CreateManyArgs<$Schema, 'Space'>; +export type SpaceCreateManyAndReturnArgs = $CreateManyAndReturnArgs<$Schema, 'Space'>; +export type SpaceUpdateArgs = $UpdateArgs<$Schema, 'Space'>; +export type SpaceUpdateManyArgs = $UpdateManyArgs<$Schema, 'Space'>; +export type SpaceUpdateManyAndReturnArgs = $UpdateManyAndReturnArgs<$Schema, 'Space'>; +export type SpaceUpsertArgs = $UpsertArgs<$Schema, 'Space'>; +export type SpaceDeleteArgs = $DeleteArgs<$Schema, 'Space'>; +export type SpaceDeleteManyArgs = $DeleteManyArgs<$Schema, 'Space'>; +export type SpaceCountArgs = $CountArgs<$Schema, 'Space'>; +export type SpaceAggregateArgs = $AggregateArgs<$Schema, 'Space'>; +export type SpaceGroupByArgs = $GroupByArgs<$Schema, 'Space'>; +export type SpaceWhereInput = $WhereInput<$Schema, 'Space'>; +export type SpaceSelect = $SelectInput<$Schema, 'Space'>; +export type SpaceInclude = $IncludeInput<$Schema, 'Space'>; +export type SpaceOmit = $OmitInput<$Schema, 'Space'>; +export type SpaceGetPayload> = $SimplifiedModelResult< + $Schema, + 'Space', + Args +>; +export type SpaceUserFindManyArgs = $FindManyArgs<$Schema, 'SpaceUser'>; +export type SpaceUserFindUniqueArgs = $FindUniqueArgs<$Schema, 'SpaceUser'>; +export type SpaceUserFindFirstArgs = $FindFirstArgs<$Schema, 'SpaceUser'>; +export type SpaceUserCreateArgs = $CreateArgs<$Schema, 'SpaceUser'>; +export type SpaceUserCreateManyArgs = $CreateManyArgs<$Schema, 'SpaceUser'>; +export type SpaceUserCreateManyAndReturnArgs = $CreateManyAndReturnArgs<$Schema, 'SpaceUser'>; +export type SpaceUserUpdateArgs = $UpdateArgs<$Schema, 'SpaceUser'>; +export type SpaceUserUpdateManyArgs = $UpdateManyArgs<$Schema, 'SpaceUser'>; +export type SpaceUserUpdateManyAndReturnArgs = $UpdateManyAndReturnArgs<$Schema, 'SpaceUser'>; +export type SpaceUserUpsertArgs = $UpsertArgs<$Schema, 'SpaceUser'>; +export type SpaceUserDeleteArgs = $DeleteArgs<$Schema, 'SpaceUser'>; +export type SpaceUserDeleteManyArgs = $DeleteManyArgs<$Schema, 'SpaceUser'>; +export type SpaceUserCountArgs = $CountArgs<$Schema, 'SpaceUser'>; +export type SpaceUserAggregateArgs = $AggregateArgs<$Schema, 'SpaceUser'>; +export type SpaceUserGroupByArgs = $GroupByArgs<$Schema, 'SpaceUser'>; +export type SpaceUserWhereInput = $WhereInput<$Schema, 'SpaceUser'>; +export type SpaceUserSelect = $SelectInput<$Schema, 'SpaceUser'>; +export type SpaceUserInclude = $IncludeInput<$Schema, 'SpaceUser'>; +export type SpaceUserOmit = $OmitInput<$Schema, 'SpaceUser'>; +export type SpaceUserGetPayload> = $SimplifiedModelResult< + $Schema, + 'SpaceUser', + Args +>; +export type UserFindManyArgs = $FindManyArgs<$Schema, 'User'>; +export type UserFindUniqueArgs = $FindUniqueArgs<$Schema, 'User'>; +export type UserFindFirstArgs = $FindFirstArgs<$Schema, 'User'>; +export type UserCreateArgs = $CreateArgs<$Schema, 'User'>; +export type UserCreateManyArgs = $CreateManyArgs<$Schema, 'User'>; +export type UserCreateManyAndReturnArgs = $CreateManyAndReturnArgs<$Schema, 'User'>; +export type UserUpdateArgs = $UpdateArgs<$Schema, 'User'>; +export type UserUpdateManyArgs = $UpdateManyArgs<$Schema, 'User'>; +export type UserUpdateManyAndReturnArgs = $UpdateManyAndReturnArgs<$Schema, 'User'>; +export type UserUpsertArgs = $UpsertArgs<$Schema, 'User'>; +export type UserDeleteArgs = $DeleteArgs<$Schema, 'User'>; +export type UserDeleteManyArgs = $DeleteManyArgs<$Schema, 'User'>; +export type UserCountArgs = $CountArgs<$Schema, 'User'>; +export type UserAggregateArgs = $AggregateArgs<$Schema, 'User'>; +export type UserGroupByArgs = $GroupByArgs<$Schema, 'User'>; +export type UserWhereInput = $WhereInput<$Schema, 'User'>; +export type UserSelect = $SelectInput<$Schema, 'User'>; +export type UserInclude = $IncludeInput<$Schema, 'User'>; +export type UserOmit = $OmitInput<$Schema, 'User'>; +export type UserGetPayload> = $SimplifiedModelResult< + $Schema, + 'User', + Args +>; +export type ListFindManyArgs = $FindManyArgs<$Schema, 'List'>; +export type ListFindUniqueArgs = $FindUniqueArgs<$Schema, 'List'>; +export type ListFindFirstArgs = $FindFirstArgs<$Schema, 'List'>; +export type ListCreateArgs = $CreateArgs<$Schema, 'List'>; +export type ListCreateManyArgs = $CreateManyArgs<$Schema, 'List'>; +export type ListCreateManyAndReturnArgs = $CreateManyAndReturnArgs<$Schema, 'List'>; +export type ListUpdateArgs = $UpdateArgs<$Schema, 'List'>; +export type ListUpdateManyArgs = $UpdateManyArgs<$Schema, 'List'>; +export type ListUpdateManyAndReturnArgs = $UpdateManyAndReturnArgs<$Schema, 'List'>; +export type ListUpsertArgs = $UpsertArgs<$Schema, 'List'>; +export type ListDeleteArgs = $DeleteArgs<$Schema, 'List'>; +export type ListDeleteManyArgs = $DeleteManyArgs<$Schema, 'List'>; +export type ListCountArgs = $CountArgs<$Schema, 'List'>; +export type ListAggregateArgs = $AggregateArgs<$Schema, 'List'>; +export type ListGroupByArgs = $GroupByArgs<$Schema, 'List'>; +export type ListWhereInput = $WhereInput<$Schema, 'List'>; +export type ListSelect = $SelectInput<$Schema, 'List'>; +export type ListInclude = $IncludeInput<$Schema, 'List'>; +export type ListOmit = $OmitInput<$Schema, 'List'>; +export type ListGetPayload> = $SimplifiedModelResult< + $Schema, + 'List', + Args +>; +export type TodoFindManyArgs = $FindManyArgs<$Schema, 'Todo'>; +export type TodoFindUniqueArgs = $FindUniqueArgs<$Schema, 'Todo'>; +export type TodoFindFirstArgs = $FindFirstArgs<$Schema, 'Todo'>; +export type TodoCreateArgs = $CreateArgs<$Schema, 'Todo'>; +export type TodoCreateManyArgs = $CreateManyArgs<$Schema, 'Todo'>; +export type TodoCreateManyAndReturnArgs = $CreateManyAndReturnArgs<$Schema, 'Todo'>; +export type TodoUpdateArgs = $UpdateArgs<$Schema, 'Todo'>; +export type TodoUpdateManyArgs = $UpdateManyArgs<$Schema, 'Todo'>; +export type TodoUpdateManyAndReturnArgs = $UpdateManyAndReturnArgs<$Schema, 'Todo'>; +export type TodoUpsertArgs = $UpsertArgs<$Schema, 'Todo'>; +export type TodoDeleteArgs = $DeleteArgs<$Schema, 'Todo'>; +export type TodoDeleteManyArgs = $DeleteManyArgs<$Schema, 'Todo'>; +export type TodoCountArgs = $CountArgs<$Schema, 'Todo'>; +export type TodoAggregateArgs = $AggregateArgs<$Schema, 'Todo'>; +export type TodoGroupByArgs = $GroupByArgs<$Schema, 'Todo'>; +export type TodoWhereInput = $WhereInput<$Schema, 'Todo'>; +export type TodoSelect = $SelectInput<$Schema, 'Todo'>; +export type TodoInclude = $IncludeInput<$Schema, 'Todo'>; +export type TodoOmit = $OmitInput<$Schema, 'Todo'>; +export type TodoGetPayload> = $SimplifiedModelResult< + $Schema, + 'Todo', + Args +>; diff --git a/tests/e2e/orm/schemas/todo/models.ts b/tests/e2e/orm/schemas/todo/models.ts index 635b68de..0d8ecda6 100644 --- a/tests/e2e/orm/schemas/todo/models.ts +++ b/tests/e2e/orm/schemas/todo/models.ts @@ -5,10 +5,10 @@ /* eslint-disable */ -import { type SchemaType as $Schema } from "./schema"; -import { type ModelResult as $ModelResult } from "@zenstackhq/orm"; -export type Space = $ModelResult<$Schema, "Space">; -export type SpaceUser = $ModelResult<$Schema, "SpaceUser">; -export type User = $ModelResult<$Schema, "User">; -export type List = $ModelResult<$Schema, "List">; -export type Todo = $ModelResult<$Schema, "Todo">; +import { type SchemaType as $Schema } from './schema'; +import { type ModelResult as $ModelResult } from '@zenstackhq/orm'; +export type Space = $ModelResult<$Schema, 'Space'>; +export type SpaceUser = $ModelResult<$Schema, 'SpaceUser'>; +export type User = $ModelResult<$Schema, 'User'>; +export type List = $ModelResult<$Schema, 'List'>; +export type Todo = $ModelResult<$Schema, 'Todo'>; diff --git a/tests/e2e/orm/schemas/todo/schema.ts b/tests/e2e/orm/schemas/todo/schema.ts index 4a8f811c..58f9ecfa 100644 --- a/tests/e2e/orm/schemas/todo/schema.ts +++ b/tests/e2e/orm/schemas/todo/schema.ts @@ -5,392 +5,831 @@ /* eslint-disable */ -import { type SchemaDef, ExpressionUtils } from "@zenstackhq/orm/schema"; +import { type SchemaDef, ExpressionUtils } from '@zenstackhq/orm/schema'; export const schema = { provider: { - type: "sqlite" + type: 'sqlite', }, models: { Space: { - name: "Space", + name: 'Space', fields: { id: { - name: "id", - type: "String", + name: 'id', + type: 'String', id: true, - attributes: [{ name: "@id" }, { name: "@default", args: [{ name: "value", value: ExpressionUtils.call("uuid") }] }], - default: ExpressionUtils.call("uuid") + attributes: [ + { name: '@id' }, + { name: '@default', args: [{ name: 'value', value: ExpressionUtils.call('uuid') }] }, + ], + default: ExpressionUtils.call('uuid'), }, createdAt: { - name: "createdAt", - type: "DateTime", - attributes: [{ name: "@default", args: [{ name: "value", value: ExpressionUtils.call("now") }] }], - default: ExpressionUtils.call("now") + name: 'createdAt', + type: 'DateTime', + attributes: [{ name: '@default', args: [{ name: 'value', value: ExpressionUtils.call('now') }] }], + default: ExpressionUtils.call('now'), }, updatedAt: { - name: "updatedAt", - type: "DateTime", + name: 'updatedAt', + type: 'DateTime', updatedAt: true, - attributes: [{ name: "@updatedAt" }] + attributes: [{ name: '@updatedAt' }], }, name: { - name: "name", - type: "String", - attributes: [{ name: "@length", args: [{ name: "min", value: ExpressionUtils.literal(4) }, { name: "max", value: ExpressionUtils.literal(50) }] }] + name: 'name', + type: 'String', + attributes: [ + { + name: '@length', + args: [ + { name: 'min', value: ExpressionUtils.literal(4) }, + { name: 'max', value: ExpressionUtils.literal(50) }, + ], + }, + ], }, slug: { - name: "slug", - type: "String", + name: 'slug', + type: 'String', unique: true, - attributes: [{ name: "@unique" }, { name: "@length", args: [{ name: "min", value: ExpressionUtils.literal(4) }, { name: "max", value: ExpressionUtils.literal(16) }] }] + attributes: [ + { name: '@unique' }, + { + name: '@length', + args: [ + { name: 'min', value: ExpressionUtils.literal(4) }, + { name: 'max', value: ExpressionUtils.literal(16) }, + ], + }, + ], }, owner: { - name: "owner", - type: "User", + name: 'owner', + type: 'User', optional: true, - attributes: [{ name: "@relation", args: [{ name: "fields", value: ExpressionUtils.array([ExpressionUtils.field("ownerId")]) }, { name: "references", value: ExpressionUtils.array([ExpressionUtils.field("id")]) }, { name: "onDelete", value: ExpressionUtils.literal("Cascade") }] }], - relation: { opposite: "ownedSpaces", fields: ["ownerId"], references: ["id"], onDelete: "Cascade" } + attributes: [ + { + name: '@relation', + args: [ + { name: 'fields', value: ExpressionUtils.array([ExpressionUtils.field('ownerId')]) }, + { name: 'references', value: ExpressionUtils.array([ExpressionUtils.field('id')]) }, + { name: 'onDelete', value: ExpressionUtils.literal('Cascade') }, + ], + }, + ], + relation: { opposite: 'ownedSpaces', fields: ['ownerId'], references: ['id'], onDelete: 'Cascade' }, }, ownerId: { - name: "ownerId", - type: "String", + name: 'ownerId', + type: 'String', optional: true, - foreignKeyFor: [ - "owner" - ] + foreignKeyFor: ['owner'], }, members: { - name: "members", - type: "SpaceUser", + name: 'members', + type: 'SpaceUser', array: true, - relation: { opposite: "space" } + relation: { opposite: 'space' }, }, lists: { - name: "lists", - type: "List", + name: 'lists', + type: 'List', array: true, - relation: { opposite: "space" } - } + relation: { opposite: 'space' }, + }, }, attributes: [ - { name: "@@deny", args: [{ name: "operation", value: ExpressionUtils.literal("all") }, { name: "condition", value: ExpressionUtils.binary(ExpressionUtils.call("auth"), "==", ExpressionUtils._null()) }] }, - { name: "@@allow", args: [{ name: "operation", value: ExpressionUtils.literal("create") }, { name: "condition", value: ExpressionUtils.literal(true) }] }, - { name: "@@allow", args: [{ name: "operation", value: ExpressionUtils.literal("read") }, { name: "condition", value: ExpressionUtils.binary(ExpressionUtils.field("members"), "?", ExpressionUtils.binary(ExpressionUtils.field("userId"), "==", ExpressionUtils.member(ExpressionUtils.call("auth"), ["id"]))) }] }, - { name: "@@allow", args: [{ name: "operation", value: ExpressionUtils.literal("update,delete") }, { name: "condition", value: ExpressionUtils.binary(ExpressionUtils.field("members"), "?", ExpressionUtils.binary(ExpressionUtils.binary(ExpressionUtils.field("userId"), "==", ExpressionUtils.member(ExpressionUtils.call("auth"), ["id"])), "&&", ExpressionUtils.binary(ExpressionUtils.field("role"), "==", ExpressionUtils.literal("ADMIN")))) }] } + { + name: '@@deny', + args: [ + { name: 'operation', value: ExpressionUtils.literal('all') }, + { + name: 'condition', + value: ExpressionUtils.binary(ExpressionUtils.call('auth'), '==', ExpressionUtils._null()), + }, + ], + }, + { + name: '@@allow', + args: [ + { name: 'operation', value: ExpressionUtils.literal('create') }, + { name: 'condition', value: ExpressionUtils.literal(true) }, + ], + }, + { + name: '@@allow', + args: [ + { name: 'operation', value: ExpressionUtils.literal('read') }, + { + name: 'condition', + value: ExpressionUtils.binary( + ExpressionUtils.field('members'), + '?', + ExpressionUtils.binary( + ExpressionUtils.field('userId'), + '==', + ExpressionUtils.member(ExpressionUtils.call('auth'), ['id']), + ), + ), + }, + ], + }, + { + name: '@@allow', + args: [ + { name: 'operation', value: ExpressionUtils.literal('update,delete') }, + { + name: 'condition', + value: ExpressionUtils.binary( + ExpressionUtils.field('members'), + '?', + ExpressionUtils.binary( + ExpressionUtils.binary( + ExpressionUtils.field('userId'), + '==', + ExpressionUtils.member(ExpressionUtils.call('auth'), ['id']), + ), + '&&', + ExpressionUtils.binary( + ExpressionUtils.field('role'), + '==', + ExpressionUtils.literal('ADMIN'), + ), + ), + ), + }, + ], + }, ], - idFields: ["id"], + idFields: ['id'], uniqueFields: { - id: { type: "String" }, - slug: { type: "String" } - } + id: { type: 'String' }, + slug: { type: 'String' }, + }, }, SpaceUser: { - name: "SpaceUser", + name: 'SpaceUser', fields: { id: { - name: "id", - type: "String", + name: 'id', + type: 'String', id: true, - attributes: [{ name: "@id" }, { name: "@default", args: [{ name: "value", value: ExpressionUtils.call("uuid") }] }], - default: ExpressionUtils.call("uuid") + attributes: [ + { name: '@id' }, + { name: '@default', args: [{ name: 'value', value: ExpressionUtils.call('uuid') }] }, + ], + default: ExpressionUtils.call('uuid'), }, createdAt: { - name: "createdAt", - type: "DateTime", - attributes: [{ name: "@default", args: [{ name: "value", value: ExpressionUtils.call("now") }] }], - default: ExpressionUtils.call("now") + name: 'createdAt', + type: 'DateTime', + attributes: [{ name: '@default', args: [{ name: 'value', value: ExpressionUtils.call('now') }] }], + default: ExpressionUtils.call('now'), }, updatedAt: { - name: "updatedAt", - type: "DateTime", + name: 'updatedAt', + type: 'DateTime', updatedAt: true, - attributes: [{ name: "@updatedAt" }] + attributes: [{ name: '@updatedAt' }], }, space: { - name: "space", - type: "Space", - attributes: [{ name: "@relation", args: [{ name: "fields", value: ExpressionUtils.array([ExpressionUtils.field("spaceId")]) }, { name: "references", value: ExpressionUtils.array([ExpressionUtils.field("id")]) }, { name: "onDelete", value: ExpressionUtils.literal("Cascade") }] }], - relation: { opposite: "members", fields: ["spaceId"], references: ["id"], onDelete: "Cascade" } + name: 'space', + type: 'Space', + attributes: [ + { + name: '@relation', + args: [ + { name: 'fields', value: ExpressionUtils.array([ExpressionUtils.field('spaceId')]) }, + { name: 'references', value: ExpressionUtils.array([ExpressionUtils.field('id')]) }, + { name: 'onDelete', value: ExpressionUtils.literal('Cascade') }, + ], + }, + ], + relation: { opposite: 'members', fields: ['spaceId'], references: ['id'], onDelete: 'Cascade' }, }, spaceId: { - name: "spaceId", - type: "String", - foreignKeyFor: [ - "space" - ] + name: 'spaceId', + type: 'String', + foreignKeyFor: ['space'], }, user: { - name: "user", - type: "User", - attributes: [{ name: "@relation", args: [{ name: "fields", value: ExpressionUtils.array([ExpressionUtils.field("userId")]) }, { name: "references", value: ExpressionUtils.array([ExpressionUtils.field("id")]) }, { name: "onDelete", value: ExpressionUtils.literal("Cascade") }] }], - relation: { opposite: "spaces", fields: ["userId"], references: ["id"], onDelete: "Cascade" } + name: 'user', + type: 'User', + attributes: [ + { + name: '@relation', + args: [ + { name: 'fields', value: ExpressionUtils.array([ExpressionUtils.field('userId')]) }, + { name: 'references', value: ExpressionUtils.array([ExpressionUtils.field('id')]) }, + { name: 'onDelete', value: ExpressionUtils.literal('Cascade') }, + ], + }, + ], + relation: { opposite: 'spaces', fields: ['userId'], references: ['id'], onDelete: 'Cascade' }, }, userId: { - name: "userId", - type: "String", - foreignKeyFor: [ - "user" - ] + name: 'userId', + type: 'String', + foreignKeyFor: ['user'], }, role: { - name: "role", - type: "String" - } + name: 'role', + type: 'String', + }, }, attributes: [ - { name: "@@unique", args: [{ name: "fields", value: ExpressionUtils.array([ExpressionUtils.field("userId"), ExpressionUtils.field("spaceId")]) }] }, - { name: "@@deny", args: [{ name: "operation", value: ExpressionUtils.literal("all") }, { name: "condition", value: ExpressionUtils.binary(ExpressionUtils.call("auth"), "==", ExpressionUtils._null()) }] }, - { name: "@@allow", args: [{ name: "operation", value: ExpressionUtils.literal("create,update,delete") }, { name: "condition", value: ExpressionUtils.binary(ExpressionUtils.binary(ExpressionUtils.member(ExpressionUtils.field("space"), ["ownerId"]), "==", ExpressionUtils.member(ExpressionUtils.call("auth"), ["id"])), "||", ExpressionUtils.binary(ExpressionUtils.member(ExpressionUtils.field("space"), ["members"]), "?", ExpressionUtils.binary(ExpressionUtils.binary(ExpressionUtils.field("userId"), "==", ExpressionUtils.member(ExpressionUtils.call("auth"), ["id"])), "&&", ExpressionUtils.binary(ExpressionUtils.field("role"), "==", ExpressionUtils.literal("ADMIN"))))) }] }, - { name: "@@allow", args: [{ name: "operation", value: ExpressionUtils.literal("read") }, { name: "condition", value: ExpressionUtils.binary(ExpressionUtils.member(ExpressionUtils.field("space"), ["members"]), "?", ExpressionUtils.binary(ExpressionUtils.field("userId"), "==", ExpressionUtils.member(ExpressionUtils.call("auth"), ["id"]))) }] } + { + name: '@@unique', + args: [ + { + name: 'fields', + value: ExpressionUtils.array([ + ExpressionUtils.field('userId'), + ExpressionUtils.field('spaceId'), + ]), + }, + ], + }, + { + name: '@@deny', + args: [ + { name: 'operation', value: ExpressionUtils.literal('all') }, + { + name: 'condition', + value: ExpressionUtils.binary(ExpressionUtils.call('auth'), '==', ExpressionUtils._null()), + }, + ], + }, + { + name: '@@allow', + args: [ + { name: 'operation', value: ExpressionUtils.literal('create,update,delete') }, + { + name: 'condition', + value: ExpressionUtils.binary( + ExpressionUtils.binary( + ExpressionUtils.member(ExpressionUtils.field('space'), ['ownerId']), + '==', + ExpressionUtils.member(ExpressionUtils.call('auth'), ['id']), + ), + '||', + ExpressionUtils.binary( + ExpressionUtils.member(ExpressionUtils.field('space'), ['members']), + '?', + ExpressionUtils.binary( + ExpressionUtils.binary( + ExpressionUtils.field('userId'), + '==', + ExpressionUtils.member(ExpressionUtils.call('auth'), ['id']), + ), + '&&', + ExpressionUtils.binary( + ExpressionUtils.field('role'), + '==', + ExpressionUtils.literal('ADMIN'), + ), + ), + ), + ), + }, + ], + }, + { + name: '@@allow', + args: [ + { name: 'operation', value: ExpressionUtils.literal('read') }, + { + name: 'condition', + value: ExpressionUtils.binary( + ExpressionUtils.member(ExpressionUtils.field('space'), ['members']), + '?', + ExpressionUtils.binary( + ExpressionUtils.field('userId'), + '==', + ExpressionUtils.member(ExpressionUtils.call('auth'), ['id']), + ), + ), + }, + ], + }, ], - idFields: ["id"], + idFields: ['id'], uniqueFields: { - id: { type: "String" }, - userId_spaceId: { userId: { type: "String" }, spaceId: { type: "String" } } - } + id: { type: 'String' }, + userId_spaceId: { userId: { type: 'String' }, spaceId: { type: 'String' } }, + }, }, User: { - name: "User", + name: 'User', fields: { id: { - name: "id", - type: "String", + name: 'id', + type: 'String', id: true, - attributes: [{ name: "@id" }, { name: "@default", args: [{ name: "value", value: ExpressionUtils.call("uuid") }] }], - default: ExpressionUtils.call("uuid") + attributes: [ + { name: '@id' }, + { name: '@default', args: [{ name: 'value', value: ExpressionUtils.call('uuid') }] }, + ], + default: ExpressionUtils.call('uuid'), }, createdAt: { - name: "createdAt", - type: "DateTime", - attributes: [{ name: "@default", args: [{ name: "value", value: ExpressionUtils.call("now") }] }], - default: ExpressionUtils.call("now") + name: 'createdAt', + type: 'DateTime', + attributes: [{ name: '@default', args: [{ name: 'value', value: ExpressionUtils.call('now') }] }], + default: ExpressionUtils.call('now'), }, updatedAt: { - name: "updatedAt", - type: "DateTime", + name: 'updatedAt', + type: 'DateTime', updatedAt: true, - attributes: [{ name: "@updatedAt" }] + attributes: [{ name: '@updatedAt' }], }, email: { - name: "email", - type: "String", + name: 'email', + type: 'String', unique: true, - attributes: [{ name: "@unique" }, { name: "@email" }] + attributes: [{ name: '@unique' }, { name: '@email' }], }, password: { - name: "password", - type: "String", - optional: true + name: 'password', + type: 'String', + optional: true, }, emailVerified: { - name: "emailVerified", - type: "DateTime", - optional: true + name: 'emailVerified', + type: 'DateTime', + optional: true, }, name: { - name: "name", - type: "String", - optional: true + name: 'name', + type: 'String', + optional: true, }, ownedSpaces: { - name: "ownedSpaces", - type: "Space", + name: 'ownedSpaces', + type: 'Space', array: true, - relation: { opposite: "owner" } + relation: { opposite: 'owner' }, }, spaces: { - name: "spaces", - type: "SpaceUser", + name: 'spaces', + type: 'SpaceUser', array: true, - relation: { opposite: "user" } + relation: { opposite: 'user' }, }, image: { - name: "image", - type: "String", + name: 'image', + type: 'String', optional: true, - attributes: [{ name: "@url" }] + attributes: [{ name: '@url' }], }, lists: { - name: "lists", - type: "List", + name: 'lists', + type: 'List', array: true, - relation: { opposite: "owner" } + relation: { opposite: 'owner' }, }, todos: { - name: "todos", - type: "Todo", + name: 'todos', + type: 'Todo', array: true, - relation: { opposite: "owner" } - } + relation: { opposite: 'owner' }, + }, }, attributes: [ - { name: "@@allow", args: [{ name: "operation", value: ExpressionUtils.literal("create") }, { name: "condition", value: ExpressionUtils.literal(true) }] }, - { name: "@@allow", args: [{ name: "operation", value: ExpressionUtils.literal("read") }, { name: "condition", value: ExpressionUtils.binary(ExpressionUtils.field("spaces"), "?", ExpressionUtils.binary(ExpressionUtils.member(ExpressionUtils.field("space"), ["members"]), "?", ExpressionUtils.binary(ExpressionUtils.field("userId"), "==", ExpressionUtils.member(ExpressionUtils.call("auth"), ["id"])))) }] }, - { name: "@@allow", args: [{ name: "operation", value: ExpressionUtils.literal("all") }, { name: "condition", value: ExpressionUtils.binary(ExpressionUtils.member(ExpressionUtils.call("auth"), ["id"]), "==", ExpressionUtils.field("id")) }] } + { + name: '@@allow', + args: [ + { name: 'operation', value: ExpressionUtils.literal('create') }, + { name: 'condition', value: ExpressionUtils.literal(true) }, + ], + }, + { + name: '@@allow', + args: [ + { name: 'operation', value: ExpressionUtils.literal('read') }, + { + name: 'condition', + value: ExpressionUtils.binary( + ExpressionUtils.field('spaces'), + '?', + ExpressionUtils.binary( + ExpressionUtils.member(ExpressionUtils.field('space'), ['members']), + '?', + ExpressionUtils.binary( + ExpressionUtils.field('userId'), + '==', + ExpressionUtils.member(ExpressionUtils.call('auth'), ['id']), + ), + ), + ), + }, + ], + }, + { + name: '@@allow', + args: [ + { name: 'operation', value: ExpressionUtils.literal('all') }, + { + name: 'condition', + value: ExpressionUtils.binary( + ExpressionUtils.member(ExpressionUtils.call('auth'), ['id']), + '==', + ExpressionUtils.field('id'), + ), + }, + ], + }, ], - idFields: ["id"], + idFields: ['id'], uniqueFields: { - id: { type: "String" }, - email: { type: "String" } - } + id: { type: 'String' }, + email: { type: 'String' }, + }, }, List: { - name: "List", + name: 'List', fields: { id: { - name: "id", - type: "String", + name: 'id', + type: 'String', id: true, - attributes: [{ name: "@id" }, { name: "@default", args: [{ name: "value", value: ExpressionUtils.call("uuid") }] }], - default: ExpressionUtils.call("uuid") + attributes: [ + { name: '@id' }, + { name: '@default', args: [{ name: 'value', value: ExpressionUtils.call('uuid') }] }, + ], + default: ExpressionUtils.call('uuid'), }, createdAt: { - name: "createdAt", - type: "DateTime", - attributes: [{ name: "@default", args: [{ name: "value", value: ExpressionUtils.call("now") }] }], - default: ExpressionUtils.call("now") + name: 'createdAt', + type: 'DateTime', + attributes: [{ name: '@default', args: [{ name: 'value', value: ExpressionUtils.call('now') }] }], + default: ExpressionUtils.call('now'), }, updatedAt: { - name: "updatedAt", - type: "DateTime", + name: 'updatedAt', + type: 'DateTime', updatedAt: true, - attributes: [{ name: "@updatedAt" }] + attributes: [{ name: '@updatedAt' }], }, space: { - name: "space", - type: "Space", - attributes: [{ name: "@relation", args: [{ name: "fields", value: ExpressionUtils.array([ExpressionUtils.field("spaceId")]) }, { name: "references", value: ExpressionUtils.array([ExpressionUtils.field("id")]) }, { name: "onDelete", value: ExpressionUtils.literal("Cascade") }] }], - relation: { opposite: "lists", fields: ["spaceId"], references: ["id"], onDelete: "Cascade" } + name: 'space', + type: 'Space', + attributes: [ + { + name: '@relation', + args: [ + { name: 'fields', value: ExpressionUtils.array([ExpressionUtils.field('spaceId')]) }, + { name: 'references', value: ExpressionUtils.array([ExpressionUtils.field('id')]) }, + { name: 'onDelete', value: ExpressionUtils.literal('Cascade') }, + ], + }, + ], + relation: { opposite: 'lists', fields: ['spaceId'], references: ['id'], onDelete: 'Cascade' }, }, spaceId: { - name: "spaceId", - type: "String", - foreignKeyFor: [ - "space" - ] + name: 'spaceId', + type: 'String', + foreignKeyFor: ['space'], }, owner: { - name: "owner", - type: "User", - attributes: [{ name: "@relation", args: [{ name: "fields", value: ExpressionUtils.array([ExpressionUtils.field("ownerId")]) }, { name: "references", value: ExpressionUtils.array([ExpressionUtils.field("id")]) }, { name: "onDelete", value: ExpressionUtils.literal("Cascade") }] }], - relation: { opposite: "lists", fields: ["ownerId"], references: ["id"], onDelete: "Cascade" } + name: 'owner', + type: 'User', + attributes: [ + { + name: '@relation', + args: [ + { name: 'fields', value: ExpressionUtils.array([ExpressionUtils.field('ownerId')]) }, + { name: 'references', value: ExpressionUtils.array([ExpressionUtils.field('id')]) }, + { name: 'onDelete', value: ExpressionUtils.literal('Cascade') }, + ], + }, + ], + relation: { opposite: 'lists', fields: ['ownerId'], references: ['id'], onDelete: 'Cascade' }, }, ownerId: { - name: "ownerId", - type: "String", - foreignKeyFor: [ - "owner" - ] + name: 'ownerId', + type: 'String', + foreignKeyFor: ['owner'], }, title: { - name: "title", - type: "String", - attributes: [{ name: "@length", args: [{ name: "min", value: ExpressionUtils.literal(1) }, { name: "max", value: ExpressionUtils.literal(100) }] }] + name: 'title', + type: 'String', + attributes: [ + { + name: '@length', + args: [ + { name: 'min', value: ExpressionUtils.literal(1) }, + { name: 'max', value: ExpressionUtils.literal(100) }, + ], + }, + ], }, private: { - name: "private", - type: "Boolean", - attributes: [{ name: "@default", args: [{ name: "value", value: ExpressionUtils.literal(false) }] }], - default: false + name: 'private', + type: 'Boolean', + attributes: [ + { name: '@default', args: [{ name: 'value', value: ExpressionUtils.literal(false) }] }, + ], + default: false, }, todos: { - name: "todos", - type: "Todo", + name: 'todos', + type: 'Todo', array: true, - relation: { opposite: "list" } + relation: { opposite: 'list' }, }, revision: { - name: "revision", - type: "Int", - attributes: [{ name: "@default", args: [{ name: "value", value: ExpressionUtils.literal(0) }] }], - default: 0 - } + name: 'revision', + type: 'Int', + attributes: [{ name: '@default', args: [{ name: 'value', value: ExpressionUtils.literal(0) }] }], + default: 0, + }, }, attributes: [ - { name: "@@deny", args: [{ name: "operation", value: ExpressionUtils.literal("all") }, { name: "condition", value: ExpressionUtils.binary(ExpressionUtils.call("auth"), "==", ExpressionUtils._null()) }] }, - { name: "@@allow", args: [{ name: "operation", value: ExpressionUtils.literal("read") }, { name: "condition", value: ExpressionUtils.binary(ExpressionUtils.binary(ExpressionUtils.field("ownerId"), "==", ExpressionUtils.member(ExpressionUtils.call("auth"), ["id"])), "||", ExpressionUtils.binary(ExpressionUtils.binary(ExpressionUtils.member(ExpressionUtils.field("space"), ["members"]), "?", ExpressionUtils.binary(ExpressionUtils.field("userId"), "==", ExpressionUtils.member(ExpressionUtils.call("auth"), ["id"]))), "&&", ExpressionUtils.unary("!", ExpressionUtils.field("private")))) }] }, - { name: "@@allow", args: [{ name: "operation", value: ExpressionUtils.literal("create") }, { name: "condition", value: ExpressionUtils.binary(ExpressionUtils.binary(ExpressionUtils.field("ownerId"), "==", ExpressionUtils.member(ExpressionUtils.call("auth"), ["id"])), "&&", ExpressionUtils.binary(ExpressionUtils.member(ExpressionUtils.field("space"), ["members"]), "?", ExpressionUtils.binary(ExpressionUtils.field("userId"), "==", ExpressionUtils.member(ExpressionUtils.call("auth"), ["id"])))) }] }, - { name: "@@allow", args: [{ name: "operation", value: ExpressionUtils.literal("update") }, { name: "condition", value: ExpressionUtils.binary(ExpressionUtils.binary(ExpressionUtils.field("ownerId"), "==", ExpressionUtils.member(ExpressionUtils.call("auth"), ["id"])), "&&", ExpressionUtils.binary(ExpressionUtils.member(ExpressionUtils.field("space"), ["members"]), "?", ExpressionUtils.binary(ExpressionUtils.field("userId"), "==", ExpressionUtils.member(ExpressionUtils.call("auth"), ["id"])))) }] }, - { name: "@@deny", args: [{ name: "operation", value: ExpressionUtils.literal("post-update") }, { name: "condition", value: ExpressionUtils.binary(ExpressionUtils.member(ExpressionUtils.call("before"), ["ownerId"]), "!=", ExpressionUtils.field("ownerId")) }] }, - { name: "@@allow", args: [{ name: "operation", value: ExpressionUtils.literal("delete") }, { name: "condition", value: ExpressionUtils.binary(ExpressionUtils.field("ownerId"), "==", ExpressionUtils.member(ExpressionUtils.call("auth"), ["id"])) }] } + { + name: '@@deny', + args: [ + { name: 'operation', value: ExpressionUtils.literal('all') }, + { + name: 'condition', + value: ExpressionUtils.binary(ExpressionUtils.call('auth'), '==', ExpressionUtils._null()), + }, + ], + }, + { + name: '@@allow', + args: [ + { name: 'operation', value: ExpressionUtils.literal('read') }, + { + name: 'condition', + value: ExpressionUtils.binary( + ExpressionUtils.binary( + ExpressionUtils.field('ownerId'), + '==', + ExpressionUtils.member(ExpressionUtils.call('auth'), ['id']), + ), + '||', + ExpressionUtils.binary( + ExpressionUtils.binary( + ExpressionUtils.member(ExpressionUtils.field('space'), ['members']), + '?', + ExpressionUtils.binary( + ExpressionUtils.field('userId'), + '==', + ExpressionUtils.member(ExpressionUtils.call('auth'), ['id']), + ), + ), + '&&', + ExpressionUtils.unary('!', ExpressionUtils.field('private')), + ), + ), + }, + ], + }, + { + name: '@@allow', + args: [ + { name: 'operation', value: ExpressionUtils.literal('create') }, + { + name: 'condition', + value: ExpressionUtils.binary( + ExpressionUtils.binary( + ExpressionUtils.field('ownerId'), + '==', + ExpressionUtils.member(ExpressionUtils.call('auth'), ['id']), + ), + '&&', + ExpressionUtils.binary( + ExpressionUtils.member(ExpressionUtils.field('space'), ['members']), + '?', + ExpressionUtils.binary( + ExpressionUtils.field('userId'), + '==', + ExpressionUtils.member(ExpressionUtils.call('auth'), ['id']), + ), + ), + ), + }, + ], + }, + { + name: '@@allow', + args: [ + { name: 'operation', value: ExpressionUtils.literal('update') }, + { + name: 'condition', + value: ExpressionUtils.binary( + ExpressionUtils.binary( + ExpressionUtils.field('ownerId'), + '==', + ExpressionUtils.member(ExpressionUtils.call('auth'), ['id']), + ), + '&&', + ExpressionUtils.binary( + ExpressionUtils.member(ExpressionUtils.field('space'), ['members']), + '?', + ExpressionUtils.binary( + ExpressionUtils.field('userId'), + '==', + ExpressionUtils.member(ExpressionUtils.call('auth'), ['id']), + ), + ), + ), + }, + ], + }, + { + name: '@@deny', + args: [ + { name: 'operation', value: ExpressionUtils.literal('post-update') }, + { + name: 'condition', + value: ExpressionUtils.binary( + ExpressionUtils.member(ExpressionUtils.call('before'), ['ownerId']), + '!=', + ExpressionUtils.field('ownerId'), + ), + }, + ], + }, + { + name: '@@allow', + args: [ + { name: 'operation', value: ExpressionUtils.literal('delete') }, + { + name: 'condition', + value: ExpressionUtils.binary( + ExpressionUtils.field('ownerId'), + '==', + ExpressionUtils.member(ExpressionUtils.call('auth'), ['id']), + ), + }, + ], + }, ], - idFields: ["id"], + idFields: ['id'], uniqueFields: { - id: { type: "String" } - } + id: { type: 'String' }, + }, }, Todo: { - name: "Todo", + name: 'Todo', fields: { id: { - name: "id", - type: "String", + name: 'id', + type: 'String', id: true, - attributes: [{ name: "@id" }, { name: "@default", args: [{ name: "value", value: ExpressionUtils.call("uuid") }] }], - default: ExpressionUtils.call("uuid") + attributes: [ + { name: '@id' }, + { name: '@default', args: [{ name: 'value', value: ExpressionUtils.call('uuid') }] }, + ], + default: ExpressionUtils.call('uuid'), }, createdAt: { - name: "createdAt", - type: "DateTime", - attributes: [{ name: "@default", args: [{ name: "value", value: ExpressionUtils.call("now") }] }], - default: ExpressionUtils.call("now") + name: 'createdAt', + type: 'DateTime', + attributes: [{ name: '@default', args: [{ name: 'value', value: ExpressionUtils.call('now') }] }], + default: ExpressionUtils.call('now'), }, updatedAt: { - name: "updatedAt", - type: "DateTime", + name: 'updatedAt', + type: 'DateTime', updatedAt: true, - attributes: [{ name: "@updatedAt" }] + attributes: [{ name: '@updatedAt' }], }, owner: { - name: "owner", - type: "User", - attributes: [{ name: "@relation", args: [{ name: "fields", value: ExpressionUtils.array([ExpressionUtils.field("ownerId")]) }, { name: "references", value: ExpressionUtils.array([ExpressionUtils.field("id")]) }, { name: "onDelete", value: ExpressionUtils.literal("Cascade") }] }], - relation: { opposite: "todos", fields: ["ownerId"], references: ["id"], onDelete: "Cascade" } + name: 'owner', + type: 'User', + attributes: [ + { + name: '@relation', + args: [ + { name: 'fields', value: ExpressionUtils.array([ExpressionUtils.field('ownerId')]) }, + { name: 'references', value: ExpressionUtils.array([ExpressionUtils.field('id')]) }, + { name: 'onDelete', value: ExpressionUtils.literal('Cascade') }, + ], + }, + ], + relation: { opposite: 'todos', fields: ['ownerId'], references: ['id'], onDelete: 'Cascade' }, }, ownerId: { - name: "ownerId", - type: "String", - foreignKeyFor: [ - "owner" - ] + name: 'ownerId', + type: 'String', + foreignKeyFor: ['owner'], }, list: { - name: "list", - type: "List", - attributes: [{ name: "@relation", args: [{ name: "fields", value: ExpressionUtils.array([ExpressionUtils.field("listId")]) }, { name: "references", value: ExpressionUtils.array([ExpressionUtils.field("id")]) }, { name: "onDelete", value: ExpressionUtils.literal("Cascade") }] }], - relation: { opposite: "todos", fields: ["listId"], references: ["id"], onDelete: "Cascade" } + name: 'list', + type: 'List', + attributes: [ + { + name: '@relation', + args: [ + { name: 'fields', value: ExpressionUtils.array([ExpressionUtils.field('listId')]) }, + { name: 'references', value: ExpressionUtils.array([ExpressionUtils.field('id')]) }, + { name: 'onDelete', value: ExpressionUtils.literal('Cascade') }, + ], + }, + ], + relation: { opposite: 'todos', fields: ['listId'], references: ['id'], onDelete: 'Cascade' }, }, listId: { - name: "listId", - type: "String", - foreignKeyFor: [ - "list" - ] + name: 'listId', + type: 'String', + foreignKeyFor: ['list'], }, title: { - name: "title", - type: "String", - attributes: [{ name: "@length", args: [{ name: "min", value: ExpressionUtils.literal(1) }, { name: "max", value: ExpressionUtils.literal(100) }] }] + name: 'title', + type: 'String', + attributes: [ + { + name: '@length', + args: [ + { name: 'min', value: ExpressionUtils.literal(1) }, + { name: 'max', value: ExpressionUtils.literal(100) }, + ], + }, + ], }, completedAt: { - name: "completedAt", - type: "DateTime", - optional: true - } + name: 'completedAt', + type: 'DateTime', + optional: true, + }, }, attributes: [ - { name: "@@deny", args: [{ name: "operation", value: ExpressionUtils.literal("all") }, { name: "condition", value: ExpressionUtils.binary(ExpressionUtils.call("auth"), "==", ExpressionUtils._null()) }] }, - { name: "@@allow", args: [{ name: "operation", value: ExpressionUtils.literal("all") }, { name: "condition", value: ExpressionUtils.binary(ExpressionUtils.member(ExpressionUtils.field("list"), ["ownerId"]), "==", ExpressionUtils.member(ExpressionUtils.call("auth"), ["id"])) }] }, - { name: "@@allow", args: [{ name: "operation", value: ExpressionUtils.literal("all") }, { name: "condition", value: ExpressionUtils.binary(ExpressionUtils.binary(ExpressionUtils.member(ExpressionUtils.field("list"), ["space", "members"]), "?", ExpressionUtils.binary(ExpressionUtils.field("userId"), "==", ExpressionUtils.member(ExpressionUtils.call("auth"), ["id"]))), "&&", ExpressionUtils.unary("!", ExpressionUtils.member(ExpressionUtils.field("list"), ["private"]))) }] }, - { name: "@@deny", args: [{ name: "operation", value: ExpressionUtils.literal("post-update") }, { name: "condition", value: ExpressionUtils.binary(ExpressionUtils.member(ExpressionUtils.call("before"), ["ownerId"]), "!=", ExpressionUtils.field("ownerId")) }] } + { + name: '@@deny', + args: [ + { name: 'operation', value: ExpressionUtils.literal('all') }, + { + name: 'condition', + value: ExpressionUtils.binary(ExpressionUtils.call('auth'), '==', ExpressionUtils._null()), + }, + ], + }, + { + name: '@@allow', + args: [ + { name: 'operation', value: ExpressionUtils.literal('all') }, + { + name: 'condition', + value: ExpressionUtils.binary( + ExpressionUtils.member(ExpressionUtils.field('list'), ['ownerId']), + '==', + ExpressionUtils.member(ExpressionUtils.call('auth'), ['id']), + ), + }, + ], + }, + { + name: '@@allow', + args: [ + { name: 'operation', value: ExpressionUtils.literal('all') }, + { + name: 'condition', + value: ExpressionUtils.binary( + ExpressionUtils.binary( + ExpressionUtils.member(ExpressionUtils.field('list'), ['space', 'members']), + '?', + ExpressionUtils.binary( + ExpressionUtils.field('userId'), + '==', + ExpressionUtils.member(ExpressionUtils.call('auth'), ['id']), + ), + ), + '&&', + ExpressionUtils.unary( + '!', + ExpressionUtils.member(ExpressionUtils.field('list'), ['private']), + ), + ), + }, + ], + }, + { + name: '@@deny', + args: [ + { name: 'operation', value: ExpressionUtils.literal('post-update') }, + { + name: 'condition', + value: ExpressionUtils.binary( + ExpressionUtils.member(ExpressionUtils.call('before'), ['ownerId']), + '!=', + ExpressionUtils.field('ownerId'), + ), + }, + ], + }, ], - idFields: ["id"], + idFields: ['id'], uniqueFields: { - id: { type: "String" } - } - } + id: { type: 'String' }, + }, + }, }, - authType: "User", - plugins: {} + authType: 'User', + plugins: {}, } as const satisfies SchemaDef; export type SchemaType = typeof schema; diff --git a/tests/e2e/orm/schemas/typing/input.ts b/tests/e2e/orm/schemas/typing/input.ts index 13d7d458..c7de2e40 100644 --- a/tests/e2e/orm/schemas/typing/input.ts +++ b/tests/e2e/orm/schemas/typing/input.ts @@ -5,126 +5,173 @@ /* eslint-disable */ -import { type SchemaType as $Schema } from "./schema"; -import type { FindManyArgs as $FindManyArgs, FindUniqueArgs as $FindUniqueArgs, FindFirstArgs as $FindFirstArgs, CreateArgs as $CreateArgs, CreateManyArgs as $CreateManyArgs, CreateManyAndReturnArgs as $CreateManyAndReturnArgs, UpdateArgs as $UpdateArgs, UpdateManyArgs as $UpdateManyArgs, UpdateManyAndReturnArgs as $UpdateManyAndReturnArgs, UpsertArgs as $UpsertArgs, DeleteArgs as $DeleteArgs, DeleteManyArgs as $DeleteManyArgs, CountArgs as $CountArgs, AggregateArgs as $AggregateArgs, GroupByArgs as $GroupByArgs, WhereInput as $WhereInput, SelectInput as $SelectInput, IncludeInput as $IncludeInput, OmitInput as $OmitInput } from "@zenstackhq/orm"; -import type { SimplifiedModelResult as $SimplifiedModelResult, SelectIncludeOmit as $SelectIncludeOmit } from "@zenstackhq/orm"; -export type UserFindManyArgs = $FindManyArgs<$Schema, "User">; -export type UserFindUniqueArgs = $FindUniqueArgs<$Schema, "User">; -export type UserFindFirstArgs = $FindFirstArgs<$Schema, "User">; -export type UserCreateArgs = $CreateArgs<$Schema, "User">; -export type UserCreateManyArgs = $CreateManyArgs<$Schema, "User">; -export type UserCreateManyAndReturnArgs = $CreateManyAndReturnArgs<$Schema, "User">; -export type UserUpdateArgs = $UpdateArgs<$Schema, "User">; -export type UserUpdateManyArgs = $UpdateManyArgs<$Schema, "User">; -export type UserUpdateManyAndReturnArgs = $UpdateManyAndReturnArgs<$Schema, "User">; -export type UserUpsertArgs = $UpsertArgs<$Schema, "User">; -export type UserDeleteArgs = $DeleteArgs<$Schema, "User">; -export type UserDeleteManyArgs = $DeleteManyArgs<$Schema, "User">; -export type UserCountArgs = $CountArgs<$Schema, "User">; -export type UserAggregateArgs = $AggregateArgs<$Schema, "User">; -export type UserGroupByArgs = $GroupByArgs<$Schema, "User">; -export type UserWhereInput = $WhereInput<$Schema, "User">; -export type UserSelect = $SelectInput<$Schema, "User">; -export type UserInclude = $IncludeInput<$Schema, "User">; -export type UserOmit = $OmitInput<$Schema, "User">; -export type UserGetPayload> = $SimplifiedModelResult<$Schema, "User", Args>; -export type PostFindManyArgs = $FindManyArgs<$Schema, "Post">; -export type PostFindUniqueArgs = $FindUniqueArgs<$Schema, "Post">; -export type PostFindFirstArgs = $FindFirstArgs<$Schema, "Post">; -export type PostCreateArgs = $CreateArgs<$Schema, "Post">; -export type PostCreateManyArgs = $CreateManyArgs<$Schema, "Post">; -export type PostCreateManyAndReturnArgs = $CreateManyAndReturnArgs<$Schema, "Post">; -export type PostUpdateArgs = $UpdateArgs<$Schema, "Post">; -export type PostUpdateManyArgs = $UpdateManyArgs<$Schema, "Post">; -export type PostUpdateManyAndReturnArgs = $UpdateManyAndReturnArgs<$Schema, "Post">; -export type PostUpsertArgs = $UpsertArgs<$Schema, "Post">; -export type PostDeleteArgs = $DeleteArgs<$Schema, "Post">; -export type PostDeleteManyArgs = $DeleteManyArgs<$Schema, "Post">; -export type PostCountArgs = $CountArgs<$Schema, "Post">; -export type PostAggregateArgs = $AggregateArgs<$Schema, "Post">; -export type PostGroupByArgs = $GroupByArgs<$Schema, "Post">; -export type PostWhereInput = $WhereInput<$Schema, "Post">; -export type PostSelect = $SelectInput<$Schema, "Post">; -export type PostInclude = $IncludeInput<$Schema, "Post">; -export type PostOmit = $OmitInput<$Schema, "Post">; -export type PostGetPayload> = $SimplifiedModelResult<$Schema, "Post", Args>; -export type ProfileFindManyArgs = $FindManyArgs<$Schema, "Profile">; -export type ProfileFindUniqueArgs = $FindUniqueArgs<$Schema, "Profile">; -export type ProfileFindFirstArgs = $FindFirstArgs<$Schema, "Profile">; -export type ProfileCreateArgs = $CreateArgs<$Schema, "Profile">; -export type ProfileCreateManyArgs = $CreateManyArgs<$Schema, "Profile">; -export type ProfileCreateManyAndReturnArgs = $CreateManyAndReturnArgs<$Schema, "Profile">; -export type ProfileUpdateArgs = $UpdateArgs<$Schema, "Profile">; -export type ProfileUpdateManyArgs = $UpdateManyArgs<$Schema, "Profile">; -export type ProfileUpdateManyAndReturnArgs = $UpdateManyAndReturnArgs<$Schema, "Profile">; -export type ProfileUpsertArgs = $UpsertArgs<$Schema, "Profile">; -export type ProfileDeleteArgs = $DeleteArgs<$Schema, "Profile">; -export type ProfileDeleteManyArgs = $DeleteManyArgs<$Schema, "Profile">; -export type ProfileCountArgs = $CountArgs<$Schema, "Profile">; -export type ProfileAggregateArgs = $AggregateArgs<$Schema, "Profile">; -export type ProfileGroupByArgs = $GroupByArgs<$Schema, "Profile">; -export type ProfileWhereInput = $WhereInput<$Schema, "Profile">; -export type ProfileSelect = $SelectInput<$Schema, "Profile">; -export type ProfileInclude = $IncludeInput<$Schema, "Profile">; -export type ProfileOmit = $OmitInput<$Schema, "Profile">; -export type ProfileGetPayload> = $SimplifiedModelResult<$Schema, "Profile", Args>; -export type TagFindManyArgs = $FindManyArgs<$Schema, "Tag">; -export type TagFindUniqueArgs = $FindUniqueArgs<$Schema, "Tag">; -export type TagFindFirstArgs = $FindFirstArgs<$Schema, "Tag">; -export type TagCreateArgs = $CreateArgs<$Schema, "Tag">; -export type TagCreateManyArgs = $CreateManyArgs<$Schema, "Tag">; -export type TagCreateManyAndReturnArgs = $CreateManyAndReturnArgs<$Schema, "Tag">; -export type TagUpdateArgs = $UpdateArgs<$Schema, "Tag">; -export type TagUpdateManyArgs = $UpdateManyArgs<$Schema, "Tag">; -export type TagUpdateManyAndReturnArgs = $UpdateManyAndReturnArgs<$Schema, "Tag">; -export type TagUpsertArgs = $UpsertArgs<$Schema, "Tag">; -export type TagDeleteArgs = $DeleteArgs<$Schema, "Tag">; -export type TagDeleteManyArgs = $DeleteManyArgs<$Schema, "Tag">; -export type TagCountArgs = $CountArgs<$Schema, "Tag">; -export type TagAggregateArgs = $AggregateArgs<$Schema, "Tag">; -export type TagGroupByArgs = $GroupByArgs<$Schema, "Tag">; -export type TagWhereInput = $WhereInput<$Schema, "Tag">; -export type TagSelect = $SelectInput<$Schema, "Tag">; -export type TagInclude = $IncludeInput<$Schema, "Tag">; -export type TagOmit = $OmitInput<$Schema, "Tag">; -export type TagGetPayload> = $SimplifiedModelResult<$Schema, "Tag", Args>; -export type RegionFindManyArgs = $FindManyArgs<$Schema, "Region">; -export type RegionFindUniqueArgs = $FindUniqueArgs<$Schema, "Region">; -export type RegionFindFirstArgs = $FindFirstArgs<$Schema, "Region">; -export type RegionCreateArgs = $CreateArgs<$Schema, "Region">; -export type RegionCreateManyArgs = $CreateManyArgs<$Schema, "Region">; -export type RegionCreateManyAndReturnArgs = $CreateManyAndReturnArgs<$Schema, "Region">; -export type RegionUpdateArgs = $UpdateArgs<$Schema, "Region">; -export type RegionUpdateManyArgs = $UpdateManyArgs<$Schema, "Region">; -export type RegionUpdateManyAndReturnArgs = $UpdateManyAndReturnArgs<$Schema, "Region">; -export type RegionUpsertArgs = $UpsertArgs<$Schema, "Region">; -export type RegionDeleteArgs = $DeleteArgs<$Schema, "Region">; -export type RegionDeleteManyArgs = $DeleteManyArgs<$Schema, "Region">; -export type RegionCountArgs = $CountArgs<$Schema, "Region">; -export type RegionAggregateArgs = $AggregateArgs<$Schema, "Region">; -export type RegionGroupByArgs = $GroupByArgs<$Schema, "Region">; -export type RegionWhereInput = $WhereInput<$Schema, "Region">; -export type RegionSelect = $SelectInput<$Schema, "Region">; -export type RegionInclude = $IncludeInput<$Schema, "Region">; -export type RegionOmit = $OmitInput<$Schema, "Region">; -export type RegionGetPayload> = $SimplifiedModelResult<$Schema, "Region", Args>; -export type MetaFindManyArgs = $FindManyArgs<$Schema, "Meta">; -export type MetaFindUniqueArgs = $FindUniqueArgs<$Schema, "Meta">; -export type MetaFindFirstArgs = $FindFirstArgs<$Schema, "Meta">; -export type MetaCreateArgs = $CreateArgs<$Schema, "Meta">; -export type MetaCreateManyArgs = $CreateManyArgs<$Schema, "Meta">; -export type MetaCreateManyAndReturnArgs = $CreateManyAndReturnArgs<$Schema, "Meta">; -export type MetaUpdateArgs = $UpdateArgs<$Schema, "Meta">; -export type MetaUpdateManyArgs = $UpdateManyArgs<$Schema, "Meta">; -export type MetaUpdateManyAndReturnArgs = $UpdateManyAndReturnArgs<$Schema, "Meta">; -export type MetaUpsertArgs = $UpsertArgs<$Schema, "Meta">; -export type MetaDeleteArgs = $DeleteArgs<$Schema, "Meta">; -export type MetaDeleteManyArgs = $DeleteManyArgs<$Schema, "Meta">; -export type MetaCountArgs = $CountArgs<$Schema, "Meta">; -export type MetaAggregateArgs = $AggregateArgs<$Schema, "Meta">; -export type MetaGroupByArgs = $GroupByArgs<$Schema, "Meta">; -export type MetaWhereInput = $WhereInput<$Schema, "Meta">; -export type MetaSelect = $SelectInput<$Schema, "Meta">; -export type MetaInclude = $IncludeInput<$Schema, "Meta">; -export type MetaOmit = $OmitInput<$Schema, "Meta">; -export type MetaGetPayload> = $SimplifiedModelResult<$Schema, "Meta", Args>; +import { type SchemaType as $Schema } from './schema'; +import type { + FindManyArgs as $FindManyArgs, + FindUniqueArgs as $FindUniqueArgs, + FindFirstArgs as $FindFirstArgs, + CreateArgs as $CreateArgs, + CreateManyArgs as $CreateManyArgs, + CreateManyAndReturnArgs as $CreateManyAndReturnArgs, + UpdateArgs as $UpdateArgs, + UpdateManyArgs as $UpdateManyArgs, + UpdateManyAndReturnArgs as $UpdateManyAndReturnArgs, + UpsertArgs as $UpsertArgs, + DeleteArgs as $DeleteArgs, + DeleteManyArgs as $DeleteManyArgs, + CountArgs as $CountArgs, + AggregateArgs as $AggregateArgs, + GroupByArgs as $GroupByArgs, + WhereInput as $WhereInput, + SelectInput as $SelectInput, + IncludeInput as $IncludeInput, + OmitInput as $OmitInput, +} from '@zenstackhq/orm'; +import type { + SimplifiedModelResult as $SimplifiedModelResult, + SelectIncludeOmit as $SelectIncludeOmit, +} from '@zenstackhq/orm'; +export type UserFindManyArgs = $FindManyArgs<$Schema, 'User'>; +export type UserFindUniqueArgs = $FindUniqueArgs<$Schema, 'User'>; +export type UserFindFirstArgs = $FindFirstArgs<$Schema, 'User'>; +export type UserCreateArgs = $CreateArgs<$Schema, 'User'>; +export type UserCreateManyArgs = $CreateManyArgs<$Schema, 'User'>; +export type UserCreateManyAndReturnArgs = $CreateManyAndReturnArgs<$Schema, 'User'>; +export type UserUpdateArgs = $UpdateArgs<$Schema, 'User'>; +export type UserUpdateManyArgs = $UpdateManyArgs<$Schema, 'User'>; +export type UserUpdateManyAndReturnArgs = $UpdateManyAndReturnArgs<$Schema, 'User'>; +export type UserUpsertArgs = $UpsertArgs<$Schema, 'User'>; +export type UserDeleteArgs = $DeleteArgs<$Schema, 'User'>; +export type UserDeleteManyArgs = $DeleteManyArgs<$Schema, 'User'>; +export type UserCountArgs = $CountArgs<$Schema, 'User'>; +export type UserAggregateArgs = $AggregateArgs<$Schema, 'User'>; +export type UserGroupByArgs = $GroupByArgs<$Schema, 'User'>; +export type UserWhereInput = $WhereInput<$Schema, 'User'>; +export type UserSelect = $SelectInput<$Schema, 'User'>; +export type UserInclude = $IncludeInput<$Schema, 'User'>; +export type UserOmit = $OmitInput<$Schema, 'User'>; +export type UserGetPayload> = $SimplifiedModelResult< + $Schema, + 'User', + Args +>; +export type PostFindManyArgs = $FindManyArgs<$Schema, 'Post'>; +export type PostFindUniqueArgs = $FindUniqueArgs<$Schema, 'Post'>; +export type PostFindFirstArgs = $FindFirstArgs<$Schema, 'Post'>; +export type PostCreateArgs = $CreateArgs<$Schema, 'Post'>; +export type PostCreateManyArgs = $CreateManyArgs<$Schema, 'Post'>; +export type PostCreateManyAndReturnArgs = $CreateManyAndReturnArgs<$Schema, 'Post'>; +export type PostUpdateArgs = $UpdateArgs<$Schema, 'Post'>; +export type PostUpdateManyArgs = $UpdateManyArgs<$Schema, 'Post'>; +export type PostUpdateManyAndReturnArgs = $UpdateManyAndReturnArgs<$Schema, 'Post'>; +export type PostUpsertArgs = $UpsertArgs<$Schema, 'Post'>; +export type PostDeleteArgs = $DeleteArgs<$Schema, 'Post'>; +export type PostDeleteManyArgs = $DeleteManyArgs<$Schema, 'Post'>; +export type PostCountArgs = $CountArgs<$Schema, 'Post'>; +export type PostAggregateArgs = $AggregateArgs<$Schema, 'Post'>; +export type PostGroupByArgs = $GroupByArgs<$Schema, 'Post'>; +export type PostWhereInput = $WhereInput<$Schema, 'Post'>; +export type PostSelect = $SelectInput<$Schema, 'Post'>; +export type PostInclude = $IncludeInput<$Schema, 'Post'>; +export type PostOmit = $OmitInput<$Schema, 'Post'>; +export type PostGetPayload> = $SimplifiedModelResult< + $Schema, + 'Post', + Args +>; +export type ProfileFindManyArgs = $FindManyArgs<$Schema, 'Profile'>; +export type ProfileFindUniqueArgs = $FindUniqueArgs<$Schema, 'Profile'>; +export type ProfileFindFirstArgs = $FindFirstArgs<$Schema, 'Profile'>; +export type ProfileCreateArgs = $CreateArgs<$Schema, 'Profile'>; +export type ProfileCreateManyArgs = $CreateManyArgs<$Schema, 'Profile'>; +export type ProfileCreateManyAndReturnArgs = $CreateManyAndReturnArgs<$Schema, 'Profile'>; +export type ProfileUpdateArgs = $UpdateArgs<$Schema, 'Profile'>; +export type ProfileUpdateManyArgs = $UpdateManyArgs<$Schema, 'Profile'>; +export type ProfileUpdateManyAndReturnArgs = $UpdateManyAndReturnArgs<$Schema, 'Profile'>; +export type ProfileUpsertArgs = $UpsertArgs<$Schema, 'Profile'>; +export type ProfileDeleteArgs = $DeleteArgs<$Schema, 'Profile'>; +export type ProfileDeleteManyArgs = $DeleteManyArgs<$Schema, 'Profile'>; +export type ProfileCountArgs = $CountArgs<$Schema, 'Profile'>; +export type ProfileAggregateArgs = $AggregateArgs<$Schema, 'Profile'>; +export type ProfileGroupByArgs = $GroupByArgs<$Schema, 'Profile'>; +export type ProfileWhereInput = $WhereInput<$Schema, 'Profile'>; +export type ProfileSelect = $SelectInput<$Schema, 'Profile'>; +export type ProfileInclude = $IncludeInput<$Schema, 'Profile'>; +export type ProfileOmit = $OmitInput<$Schema, 'Profile'>; +export type ProfileGetPayload> = $SimplifiedModelResult< + $Schema, + 'Profile', + Args +>; +export type TagFindManyArgs = $FindManyArgs<$Schema, 'Tag'>; +export type TagFindUniqueArgs = $FindUniqueArgs<$Schema, 'Tag'>; +export type TagFindFirstArgs = $FindFirstArgs<$Schema, 'Tag'>; +export type TagCreateArgs = $CreateArgs<$Schema, 'Tag'>; +export type TagCreateManyArgs = $CreateManyArgs<$Schema, 'Tag'>; +export type TagCreateManyAndReturnArgs = $CreateManyAndReturnArgs<$Schema, 'Tag'>; +export type TagUpdateArgs = $UpdateArgs<$Schema, 'Tag'>; +export type TagUpdateManyArgs = $UpdateManyArgs<$Schema, 'Tag'>; +export type TagUpdateManyAndReturnArgs = $UpdateManyAndReturnArgs<$Schema, 'Tag'>; +export type TagUpsertArgs = $UpsertArgs<$Schema, 'Tag'>; +export type TagDeleteArgs = $DeleteArgs<$Schema, 'Tag'>; +export type TagDeleteManyArgs = $DeleteManyArgs<$Schema, 'Tag'>; +export type TagCountArgs = $CountArgs<$Schema, 'Tag'>; +export type TagAggregateArgs = $AggregateArgs<$Schema, 'Tag'>; +export type TagGroupByArgs = $GroupByArgs<$Schema, 'Tag'>; +export type TagWhereInput = $WhereInput<$Schema, 'Tag'>; +export type TagSelect = $SelectInput<$Schema, 'Tag'>; +export type TagInclude = $IncludeInput<$Schema, 'Tag'>; +export type TagOmit = $OmitInput<$Schema, 'Tag'>; +export type TagGetPayload> = $SimplifiedModelResult< + $Schema, + 'Tag', + Args +>; +export type RegionFindManyArgs = $FindManyArgs<$Schema, 'Region'>; +export type RegionFindUniqueArgs = $FindUniqueArgs<$Schema, 'Region'>; +export type RegionFindFirstArgs = $FindFirstArgs<$Schema, 'Region'>; +export type RegionCreateArgs = $CreateArgs<$Schema, 'Region'>; +export type RegionCreateManyArgs = $CreateManyArgs<$Schema, 'Region'>; +export type RegionCreateManyAndReturnArgs = $CreateManyAndReturnArgs<$Schema, 'Region'>; +export type RegionUpdateArgs = $UpdateArgs<$Schema, 'Region'>; +export type RegionUpdateManyArgs = $UpdateManyArgs<$Schema, 'Region'>; +export type RegionUpdateManyAndReturnArgs = $UpdateManyAndReturnArgs<$Schema, 'Region'>; +export type RegionUpsertArgs = $UpsertArgs<$Schema, 'Region'>; +export type RegionDeleteArgs = $DeleteArgs<$Schema, 'Region'>; +export type RegionDeleteManyArgs = $DeleteManyArgs<$Schema, 'Region'>; +export type RegionCountArgs = $CountArgs<$Schema, 'Region'>; +export type RegionAggregateArgs = $AggregateArgs<$Schema, 'Region'>; +export type RegionGroupByArgs = $GroupByArgs<$Schema, 'Region'>; +export type RegionWhereInput = $WhereInput<$Schema, 'Region'>; +export type RegionSelect = $SelectInput<$Schema, 'Region'>; +export type RegionInclude = $IncludeInput<$Schema, 'Region'>; +export type RegionOmit = $OmitInput<$Schema, 'Region'>; +export type RegionGetPayload> = $SimplifiedModelResult< + $Schema, + 'Region', + Args +>; +export type MetaFindManyArgs = $FindManyArgs<$Schema, 'Meta'>; +export type MetaFindUniqueArgs = $FindUniqueArgs<$Schema, 'Meta'>; +export type MetaFindFirstArgs = $FindFirstArgs<$Schema, 'Meta'>; +export type MetaCreateArgs = $CreateArgs<$Schema, 'Meta'>; +export type MetaCreateManyArgs = $CreateManyArgs<$Schema, 'Meta'>; +export type MetaCreateManyAndReturnArgs = $CreateManyAndReturnArgs<$Schema, 'Meta'>; +export type MetaUpdateArgs = $UpdateArgs<$Schema, 'Meta'>; +export type MetaUpdateManyArgs = $UpdateManyArgs<$Schema, 'Meta'>; +export type MetaUpdateManyAndReturnArgs = $UpdateManyAndReturnArgs<$Schema, 'Meta'>; +export type MetaUpsertArgs = $UpsertArgs<$Schema, 'Meta'>; +export type MetaDeleteArgs = $DeleteArgs<$Schema, 'Meta'>; +export type MetaDeleteManyArgs = $DeleteManyArgs<$Schema, 'Meta'>; +export type MetaCountArgs = $CountArgs<$Schema, 'Meta'>; +export type MetaAggregateArgs = $AggregateArgs<$Schema, 'Meta'>; +export type MetaGroupByArgs = $GroupByArgs<$Schema, 'Meta'>; +export type MetaWhereInput = $WhereInput<$Schema, 'Meta'>; +export type MetaSelect = $SelectInput<$Schema, 'Meta'>; +export type MetaInclude = $IncludeInput<$Schema, 'Meta'>; +export type MetaOmit = $OmitInput<$Schema, 'Meta'>; +export type MetaGetPayload> = $SimplifiedModelResult< + $Schema, + 'Meta', + Args +>; diff --git a/tests/e2e/orm/schemas/typing/models.ts b/tests/e2e/orm/schemas/typing/models.ts index b2fa673f..06d9a3c9 100644 --- a/tests/e2e/orm/schemas/typing/models.ts +++ b/tests/e2e/orm/schemas/typing/models.ts @@ -5,16 +5,16 @@ /* eslint-disable */ -import { schema as $schema, type SchemaType as $Schema } from "./schema"; -import { type ModelResult as $ModelResult, type TypeDefResult as $TypeDefResult } from "@zenstackhq/orm"; -export type User = $ModelResult<$Schema, "User">; -export type Post = $ModelResult<$Schema, "Post">; -export type Profile = $ModelResult<$Schema, "Profile">; -export type Tag = $ModelResult<$Schema, "Tag">; -export type Region = $ModelResult<$Schema, "Region">; -export type Meta = $ModelResult<$Schema, "Meta">; -export type Identity = $TypeDefResult<$Schema, "Identity">; -export type IdentityProvider = $TypeDefResult<$Schema, "IdentityProvider">; +import { schema as $schema, type SchemaType as $Schema } from './schema'; +import { type ModelResult as $ModelResult, type TypeDefResult as $TypeDefResult } from '@zenstackhq/orm'; +export type User = $ModelResult<$Schema, 'User'>; +export type Post = $ModelResult<$Schema, 'Post'>; +export type Profile = $ModelResult<$Schema, 'Profile'>; +export type Tag = $ModelResult<$Schema, 'Tag'>; +export type Region = $ModelResult<$Schema, 'Region'>; +export type Meta = $ModelResult<$Schema, 'Meta'>; +export type Identity = $TypeDefResult<$Schema, 'Identity'>; +export type IdentityProvider = $TypeDefResult<$Schema, 'IdentityProvider'>; export const Role = $schema.enums.Role; export type Role = (typeof Role)[keyof typeof Role]; export const Status = $schema.enums.Status; diff --git a/tests/e2e/orm/schemas/typing/schema.ts b/tests/e2e/orm/schemas/typing/schema.ts index 10c4daa7..ab27ac19 100644 --- a/tests/e2e/orm/schemas/typing/schema.ts +++ b/tests/e2e/orm/schemas/typing/schema.ts @@ -5,339 +5,403 @@ /* eslint-disable */ -import { type SchemaDef, type OperandExpression, ExpressionUtils } from "@zenstackhq/orm/schema"; +import { type SchemaDef, type OperandExpression, ExpressionUtils } from '@zenstackhq/orm/schema'; export const schema = { provider: { - type: "postgresql" + type: 'postgresql', }, models: { User: { - name: "User", + name: 'User', fields: { id: { - name: "id", - type: "Int", + name: 'id', + type: 'Int', id: true, - attributes: [{ name: "@id" }, { name: "@default", args: [{ name: "value", value: ExpressionUtils.call("autoincrement") }] }], - default: ExpressionUtils.call("autoincrement") + attributes: [ + { name: '@id' }, + { name: '@default', args: [{ name: 'value', value: ExpressionUtils.call('autoincrement') }] }, + ], + default: ExpressionUtils.call('autoincrement'), }, createdAt: { - name: "createdAt", - type: "DateTime", - attributes: [{ name: "@default", args: [{ name: "value", value: ExpressionUtils.call("now") }] }], - default: ExpressionUtils.call("now") + name: 'createdAt', + type: 'DateTime', + attributes: [{ name: '@default', args: [{ name: 'value', value: ExpressionUtils.call('now') }] }], + default: ExpressionUtils.call('now'), }, updatedAt: { - name: "updatedAt", - type: "DateTime", + name: 'updatedAt', + type: 'DateTime', updatedAt: true, - attributes: [{ name: "@updatedAt" }] + attributes: [{ name: '@updatedAt' }], }, name: { - name: "name", - type: "String" + name: 'name', + type: 'String', }, email: { - name: "email", - type: "String", + name: 'email', + type: 'String', unique: true, - attributes: [{ name: "@unique" }] + attributes: [{ name: '@unique' }], }, role: { - name: "role", - type: "Role", - attributes: [{ name: "@default", args: [{ name: "value", value: ExpressionUtils.literal("USER") }] }], - default: "USER" + name: 'role', + type: 'Role', + attributes: [ + { name: '@default', args: [{ name: 'value', value: ExpressionUtils.literal('USER') }] }, + ], + default: 'USER', }, status: { - name: "status", - type: "Status", - array: true + name: 'status', + type: 'Status', + array: true, }, posts: { - name: "posts", - type: "Post", + name: 'posts', + type: 'Post', array: true, - relation: { opposite: "author" } + relation: { opposite: 'author' }, }, profile: { - name: "profile", - type: "Profile", + name: 'profile', + type: 'Profile', optional: true, - relation: { opposite: "user" } + relation: { opposite: 'user' }, }, postCount: { - name: "postCount", - type: "Int", - attributes: [{ name: "@computed" }], - computed: true + name: 'postCount', + type: 'Int', + attributes: [{ name: '@computed' }], + computed: true, }, identity: { - name: "identity", - type: "Identity", + name: 'identity', + type: 'Identity', optional: true, - attributes: [{ name: "@json" }] - } + attributes: [{ name: '@json' }], + }, }, - idFields: ["id"], + idFields: ['id'], uniqueFields: { - id: { type: "Int" }, - email: { type: "String" } + id: { type: 'Int' }, + email: { type: 'String' }, }, computedFields: { - postCount(_context: { - modelAlias: string; - }): OperandExpression { - throw new Error("This is a stub for computed field"); - } - } + postCount(_context: { modelAlias: string }): OperandExpression { + throw new Error('This is a stub for computed field'); + }, + }, }, Post: { - name: "Post", + name: 'Post', fields: { id: { - name: "id", - type: "Int", + name: 'id', + type: 'Int', id: true, - attributes: [{ name: "@id" }, { name: "@default", args: [{ name: "value", value: ExpressionUtils.call("autoincrement") }] }], - default: ExpressionUtils.call("autoincrement") + attributes: [ + { name: '@id' }, + { name: '@default', args: [{ name: 'value', value: ExpressionUtils.call('autoincrement') }] }, + ], + default: ExpressionUtils.call('autoincrement'), }, title: { - name: "title", - type: "String" + name: 'title', + type: 'String', }, content: { - name: "content", - type: "String" + name: 'content', + type: 'String', }, author: { - name: "author", - type: "User", - attributes: [{ name: "@relation", args: [{ name: "fields", value: ExpressionUtils.array([ExpressionUtils.field("authorId")]) }, { name: "references", value: ExpressionUtils.array([ExpressionUtils.field("id")]) }] }], - relation: { opposite: "posts", fields: ["authorId"], references: ["id"] } + name: 'author', + type: 'User', + attributes: [ + { + name: '@relation', + args: [ + { name: 'fields', value: ExpressionUtils.array([ExpressionUtils.field('authorId')]) }, + { name: 'references', value: ExpressionUtils.array([ExpressionUtils.field('id')]) }, + ], + }, + ], + relation: { opposite: 'posts', fields: ['authorId'], references: ['id'] }, }, authorId: { - name: "authorId", - type: "Int", - foreignKeyFor: [ - "author" - ] + name: 'authorId', + type: 'Int', + foreignKeyFor: ['author'], }, tags: { - name: "tags", - type: "Tag", + name: 'tags', + type: 'Tag', array: true, - relation: { opposite: "posts" } + relation: { opposite: 'posts' }, }, meta: { - name: "meta", - type: "Meta", + name: 'meta', + type: 'Meta', optional: true, - relation: { opposite: "post" } - } + relation: { opposite: 'post' }, + }, }, - idFields: ["id"], + idFields: ['id'], uniqueFields: { - id: { type: "Int" } - } + id: { type: 'Int' }, + }, }, Profile: { - name: "Profile", + name: 'Profile', fields: { id: { - name: "id", - type: "Int", + name: 'id', + type: 'Int', id: true, - attributes: [{ name: "@id" }, { name: "@default", args: [{ name: "value", value: ExpressionUtils.call("autoincrement") }] }], - default: ExpressionUtils.call("autoincrement") + attributes: [ + { name: '@id' }, + { name: '@default', args: [{ name: 'value', value: ExpressionUtils.call('autoincrement') }] }, + ], + default: ExpressionUtils.call('autoincrement'), }, age: { - name: "age", - type: "Int" + name: 'age', + type: 'Int', }, region: { - name: "region", - type: "Region", + name: 'region', + type: 'Region', optional: true, - attributes: [{ name: "@relation", args: [{ name: "fields", value: ExpressionUtils.array([ExpressionUtils.field("regionCountry"), ExpressionUtils.field("regionCity")]) }, { name: "references", value: ExpressionUtils.array([ExpressionUtils.field("country"), ExpressionUtils.field("city")]) }] }], - relation: { opposite: "profiles", fields: ["regionCountry", "regionCity"], references: ["country", "city"] } + attributes: [ + { + name: '@relation', + args: [ + { + name: 'fields', + value: ExpressionUtils.array([ + ExpressionUtils.field('regionCountry'), + ExpressionUtils.field('regionCity'), + ]), + }, + { + name: 'references', + value: ExpressionUtils.array([ + ExpressionUtils.field('country'), + ExpressionUtils.field('city'), + ]), + }, + ], + }, + ], + relation: { + opposite: 'profiles', + fields: ['regionCountry', 'regionCity'], + references: ['country', 'city'], + }, }, regionCountry: { - name: "regionCountry", - type: "String", + name: 'regionCountry', + type: 'String', optional: true, - foreignKeyFor: [ - "region" - ] + foreignKeyFor: ['region'], }, regionCity: { - name: "regionCity", - type: "String", + name: 'regionCity', + type: 'String', optional: true, - foreignKeyFor: [ - "region" - ] + foreignKeyFor: ['region'], }, user: { - name: "user", - type: "User", - attributes: [{ name: "@relation", args: [{ name: "fields", value: ExpressionUtils.array([ExpressionUtils.field("userId")]) }, { name: "references", value: ExpressionUtils.array([ExpressionUtils.field("id")]) }] }], - relation: { opposite: "profile", fields: ["userId"], references: ["id"] } + name: 'user', + type: 'User', + attributes: [ + { + name: '@relation', + args: [ + { name: 'fields', value: ExpressionUtils.array([ExpressionUtils.field('userId')]) }, + { name: 'references', value: ExpressionUtils.array([ExpressionUtils.field('id')]) }, + ], + }, + ], + relation: { opposite: 'profile', fields: ['userId'], references: ['id'] }, }, userId: { - name: "userId", - type: "Int", + name: 'userId', + type: 'Int', unique: true, - attributes: [{ name: "@unique" }], - foreignKeyFor: [ - "user" - ] - } + attributes: [{ name: '@unique' }], + foreignKeyFor: ['user'], + }, }, - idFields: ["id"], + idFields: ['id'], uniqueFields: { - id: { type: "Int" }, - userId: { type: "Int" } - } + id: { type: 'Int' }, + userId: { type: 'Int' }, + }, }, Tag: { - name: "Tag", + name: 'Tag', fields: { id: { - name: "id", - type: "Int", + name: 'id', + type: 'Int', id: true, - attributes: [{ name: "@id" }, { name: "@default", args: [{ name: "value", value: ExpressionUtils.call("autoincrement") }] }], - default: ExpressionUtils.call("autoincrement") + attributes: [ + { name: '@id' }, + { name: '@default', args: [{ name: 'value', value: ExpressionUtils.call('autoincrement') }] }, + ], + default: ExpressionUtils.call('autoincrement'), }, name: { - name: "name", - type: "String" + name: 'name', + type: 'String', }, posts: { - name: "posts", - type: "Post", + name: 'posts', + type: 'Post', array: true, - relation: { opposite: "tags" } - } + relation: { opposite: 'tags' }, + }, }, - idFields: ["id"], + idFields: ['id'], uniqueFields: { - id: { type: "Int" } - } + id: { type: 'Int' }, + }, }, Region: { - name: "Region", + name: 'Region', fields: { country: { - name: "country", - type: "String", - id: true + name: 'country', + type: 'String', + id: true, }, city: { - name: "city", - type: "String", - id: true + name: 'city', + type: 'String', + id: true, }, zip: { - name: "zip", - type: "String", - optional: true + name: 'zip', + type: 'String', + optional: true, }, profiles: { - name: "profiles", - type: "Profile", + name: 'profiles', + type: 'Profile', array: true, - relation: { opposite: "region" } - } + relation: { opposite: 'region' }, + }, }, attributes: [ - { name: "@@id", args: [{ name: "fields", value: ExpressionUtils.array([ExpressionUtils.field("country"), ExpressionUtils.field("city")]) }] } + { + name: '@@id', + args: [ + { + name: 'fields', + value: ExpressionUtils.array([ + ExpressionUtils.field('country'), + ExpressionUtils.field('city'), + ]), + }, + ], + }, ], - idFields: ["country", "city"], + idFields: ['country', 'city'], uniqueFields: { - country_city: { country: { type: "String" }, city: { type: "String" } } - } + country_city: { country: { type: 'String' }, city: { type: 'String' } }, + }, }, Meta: { - name: "Meta", + name: 'Meta', fields: { id: { - name: "id", - type: "Int", + name: 'id', + type: 'Int', id: true, - attributes: [{ name: "@id" }, { name: "@default", args: [{ name: "value", value: ExpressionUtils.call("autoincrement") }] }], - default: ExpressionUtils.call("autoincrement") + attributes: [ + { name: '@id' }, + { name: '@default', args: [{ name: 'value', value: ExpressionUtils.call('autoincrement') }] }, + ], + default: ExpressionUtils.call('autoincrement'), }, reviewed: { - name: "reviewed", - type: "Boolean" + name: 'reviewed', + type: 'Boolean', }, published: { - name: "published", - type: "Boolean" + name: 'published', + type: 'Boolean', }, post: { - name: "post", - type: "Post", - attributes: [{ name: "@relation", args: [{ name: "fields", value: ExpressionUtils.array([ExpressionUtils.field("postId")]) }, { name: "references", value: ExpressionUtils.array([ExpressionUtils.field("id")]) }] }], - relation: { opposite: "meta", fields: ["postId"], references: ["id"] } + name: 'post', + type: 'Post', + attributes: [ + { + name: '@relation', + args: [ + { name: 'fields', value: ExpressionUtils.array([ExpressionUtils.field('postId')]) }, + { name: 'references', value: ExpressionUtils.array([ExpressionUtils.field('id')]) }, + ], + }, + ], + relation: { opposite: 'meta', fields: ['postId'], references: ['id'] }, }, postId: { - name: "postId", - type: "Int", + name: 'postId', + type: 'Int', unique: true, - attributes: [{ name: "@unique" }], - foreignKeyFor: [ - "post" - ] - } + attributes: [{ name: '@unique' }], + foreignKeyFor: ['post'], + }, }, - idFields: ["id"], + idFields: ['id'], uniqueFields: { - id: { type: "Int" }, - postId: { type: "Int" } - } - } + id: { type: 'Int' }, + postId: { type: 'Int' }, + }, + }, }, typeDefs: { Identity: { - name: "Identity", + name: 'Identity', fields: { providers: { - name: "providers", - type: "IdentityProvider", - array: true - } - } + name: 'providers', + type: 'IdentityProvider', + array: true, + }, + }, }, IdentityProvider: { - name: "IdentityProvider", + name: 'IdentityProvider', fields: { id: { - name: "id", - type: "String" + name: 'id', + type: 'String', }, name: { - name: "name", - type: "String", - optional: true - } - } - } + name: 'name', + type: 'String', + optional: true, + }, + }, + }, }, enums: { Role: { - ADMIN: "ADMIN", - USER: "USER" + ADMIN: 'ADMIN', + USER: 'USER', }, Status: { - ACTIVE: "ACTIVE", - INACTIVE: "INACTIVE", - BANNED: "BANNED" - } + ACTIVE: 'ACTIVE', + INACTIVE: 'INACTIVE', + BANNED: 'BANNED', + }, }, - authType: "User", - plugins: {} + authType: 'User', + plugins: {}, } as const satisfies SchemaDef; export type SchemaType = typeof schema;