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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 7 additions & 8 deletions packages/runtime/src/client/crud-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import type {
FieldIsDelegateDiscriminator,
FieldIsDelegateRelation,
FieldIsRelation,
FieldIsRelationArray,
FieldType,
ForeignKeyFields,
GetEnum,
Expand Down Expand Up @@ -218,11 +217,11 @@ export type WhereInput<
: Key]?: Key extends RelationFields<Schema, Model>
? // relation
RelationFilter<Schema, Model, Key>
: // enum
GetModelFieldType<Schema, Model, Key> extends GetEnums<Schema>
? EnumFilter<Schema, GetModelFieldType<Schema, Model, Key>, ModelFieldIsOptional<Schema, Model, Key>>
: FieldIsArray<Schema, Model, Key> extends true
? ArrayFilter<GetModelFieldType<Schema, Model, Key>>
: FieldIsArray<Schema, Model, Key> extends true
? ArrayFilter<GetModelFieldType<Schema, Model, Key>>
: // enum
GetModelFieldType<Schema, Model, Key> extends GetEnums<Schema>
? EnumFilter<Schema, GetModelFieldType<Schema, Model, Key>, ModelFieldIsOptional<Schema, Model, Key>>
: // primitive
PrimitiveFilter<
Schema,
Expand Down Expand Up @@ -561,9 +560,9 @@ type OptionalFieldsForCreate<Schema extends SchemaDef, Model extends GetModels<S
? Key
: FieldHasDefault<Schema, Model, Key> extends true
? Key
: GetModelField<Schema, Model, Key>['updatedAt'] extends true
: FieldIsArray<Schema, Model, Key> extends true
? Key
: FieldIsRelationArray<Schema, Model, Key> extends true
: GetModelField<Schema, Model, Key>['updatedAt'] extends true
? Key
: never]: GetModelField<Schema, Model, Key>;
};
Expand Down
2 changes: 2 additions & 0 deletions packages/runtime/test/schemas/typing/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,5 @@ 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;
export type Status = (typeof Status)[keyof typeof Status];
12 changes: 11 additions & 1 deletion packages/runtime/test/schemas/typing/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import { type SchemaDef, type OperandExpression, ExpressionUtils } from "../../../dist/schema";
export const schema = {
provider: {
type: "sqlite"
type: "postgresql"
},
models: {
User: {
Expand Down Expand Up @@ -49,6 +49,11 @@ export const schema = {
attributes: [{ name: "@default", args: [{ name: "value", value: ExpressionUtils.literal("USER") }] }],
default: "USER"
},
status: {
name: "status",
type: "Status",
array: true
},
posts: {
name: "posts",
type: "Post",
Expand Down Expand Up @@ -325,6 +330,11 @@ export const schema = {
Role: {
ADMIN: "ADMIN",
USER: "USER"
},
Status: {
ACTIVE: "ACTIVE",
INACTIVE: "INACTIVE",
BANNED: "BANNED"
}
},
authType: "User",
Expand Down
11 changes: 9 additions & 2 deletions packages/runtime/test/schemas/typing/schema.zmodel
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
datasource db {
provider = "sqlite"
url = "file:./test.db"
provider = 'postgresql'
url = env('DATABASE_URL')
}

enum Role {
ADMIN
USER
}

enum Status {
ACTIVE
INACTIVE
BANNED
}

type Identity {
providers IdentityProvider[]
}
Expand All @@ -24,6 +30,7 @@ model User {
name String
email String @unique
role Role @default(USER)
status Status[]
posts Post[]
profile Profile?
postCount Int @computed
Expand Down
5 changes: 4 additions & 1 deletion packages/runtime/test/schemas/typing/typecheck.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import SQLite from 'better-sqlite3';
import { SqliteDialect } from 'kysely';
import { ZenStackClient } from '../../../dist';
import { Role, type Identity, type IdentityProvider } from './models';
import { Role, Status, type Identity, type IdentityProvider } from './models';
import { schema } from './schema';

const client = new ZenStackClient(schema, {
Expand Down Expand Up @@ -35,6 +35,9 @@ async function find() {
where: {
name: 'Alex',
role: Role.USER,
status: {
has: Status.ACTIVE,
},
},
});
console.log(user1?.name);
Expand Down