diff --git a/TODO.md b/TODO.md index 7aa1136c..c63f4758 100644 --- a/TODO.md +++ b/TODO.md @@ -72,6 +72,7 @@ - [x] Custom table name - [x] Custom field name - [ ] Strict undefined checks + - [ ] DbNull vs JsonNull - [ ] Benchmark - [ ] Plugin - [ ] Post-mutation hooks should be called after transaction is committed diff --git a/packages/runtime/src/client/crud-types.ts b/packages/runtime/src/client/crud-types.ts index 259e1023..e97d2e29 100644 --- a/packages/runtime/src/client/crud-types.ts +++ b/packages/runtime/src/client/crud-types.ts @@ -30,6 +30,7 @@ import type { NullableIf, Optional, OrArray, + Simplify, ValueOfPotentialTuple, WrapType, XOR, @@ -157,6 +158,14 @@ export type ModelResult< Array >; +export type SimplifiedModelResult< + Schema extends SchemaDef, + Model extends GetModels, + Args extends SelectIncludeOmit, + Optional = false, + Array = false, +> = Simplify>; + export type BatchResult = { count: number }; //#endregion @@ -215,11 +224,13 @@ type PrimitiveFilter = T extends 'St ? BooleanFilter : T extends 'DateTime' ? DateTimeFilter - : T extends 'Json' - ? 'Not implemented yet' // TODO: Json filter - : never; + : T extends 'Bytes' + ? BytesFilter + : T extends 'Json' + ? 'Not implemented yet' // TODO: Json filter + : never; -export type CommonPrimitiveFilter = { +type CommonPrimitiveFilter = { equals?: NullableIf; in?: DataType[]; notIn?: DataType[]; @@ -255,6 +266,7 @@ export type BytesFilter = notIn?: Uint8Array[]; not?: BytesFilter; }; + export type BooleanFilter = | NullableIf | { @@ -321,14 +333,14 @@ export type WhereUniqueInput['uniqueFields'], string> >; -type OmitFields> = { +export type OmitInput> = { [Key in NonRelationFields]?: true; }; export type SelectIncludeOmit, AllowCount extends boolean> = { - select?: Select; - include?: Include; - omit?: OmitFields; + select?: SelectInput; + include?: IncludeInput; + omit?: OmitInput; }; type Distinct> = { @@ -339,14 +351,14 @@ type Cursor> = { cursor?: WhereUniqueInput; }; -type Select< +export type SelectInput< Schema extends SchemaDef, Model extends GetModels, - AllowCount extends boolean, + AllowCount extends boolean = true, AllowRelation extends boolean = true, > = { [Key in NonRelationFields]?: true; -} & (AllowRelation extends true ? Include : {}) & // relation fields +} & (AllowRelation extends true ? IncludeInput : {}) & // relation fields // relation count (AllowCount extends true ? { _count?: SelectCount } : {}); @@ -362,7 +374,7 @@ type SelectCount> = }; }; -type Include> = { +export type IncludeInput> = { [Key in RelationFields]?: | boolean | FindArgs< @@ -431,7 +443,7 @@ type RelationFilter< //#region Field utils -export type MapFieldType< +type MapFieldType< Schema extends SchemaDef, Model extends GetModels, Field extends GetFields, @@ -443,7 +455,7 @@ type MapFieldDefType; -export type OptionalFieldsForCreate> = keyof { +type OptionalFieldsForCreate> = keyof { [Key in GetFields as FieldIsOptional extends true ? Key : FieldHasDefault extends true @@ -475,14 +487,14 @@ type OppositeRelation< : never : never; -export type OppositeRelationFields< +type OppositeRelationFields< Schema extends SchemaDef, Model extends GetModels, Field extends GetFields, Opposite = OppositeRelation, > = Opposite extends RelationInfo ? (Opposite['fields'] extends string[] ? Opposite['fields'] : []) : []; -export type OppositeRelationAndFK< +type OppositeRelationAndFK< Schema extends SchemaDef, Model extends GetModels, Field extends GetFields, @@ -521,6 +533,9 @@ export type FindArgs< Distinct & Cursor; +export type FindManyArgs> = FindArgs; +export type FindFirstArgs> = FindArgs; + export type FindUniqueArgs> = { where?: WhereUniqueInput; } & SelectIncludeOmit; @@ -531,9 +546,9 @@ export type FindUniqueArgs> = { data: CreateInput; - select?: Select; - include?: Include; - omit?: OmitFields; + select?: SelectInput; + include?: IncludeInput; + omit?: OmitInput; }; export type CreateManyArgs> = CreateManyInput; @@ -542,8 +557,8 @@ export type CreateManyAndReturnArgs & { - select?: Select; - omit?: OmitFields; + select?: SelectInput; + omit?: OmitInput; }; type OptionalWrap, T extends object> = Optional< @@ -633,20 +648,15 @@ type ConnectOrCreatePayload< create: CreateInput; }; -export type CreateManyInput< - Schema extends SchemaDef, - Model extends GetModels, - Without extends string = never, -> = { +type CreateManyInput, Without extends string = never> = { data: OrArray, Without> & Omit, Without>>; skipDuplicates?: boolean; }; -export type CreateInput< - Schema extends SchemaDef, - Model extends GetModels, - Without extends string = never, -> = XOR, Without>, Omit, Without>>; +type CreateInput, Without extends string = never> = XOR< + Omit, Without>, + Omit, Without> +>; type NestedCreateInput< Schema extends SchemaDef, @@ -670,9 +680,9 @@ type NestedCreateManyInput< export type UpdateArgs> = { data: UpdateInput; where: WhereUniqueInput; - select?: Select; - include?: Include; - omit?: OmitFields; + select?: SelectInput; + include?: IncludeInput; + omit?: OmitInput; }; export type UpdateManyArgs> = UpdateManyPayload< @@ -684,8 +694,8 @@ export type UpdateManyAndReturnArgs & { - select?: Select; - omit?: OmitFields; + select?: SelectInput; + omit?: OmitInput; }; type UpdateManyPayload, Without extends string = never> = { @@ -698,12 +708,12 @@ export type UpsertArgs create: CreateInput; update: UpdateInput; where: WhereUniqueInput; - select?: Select; - include?: Include; - omit?: OmitFields; + select?: SelectInput; + include?: IncludeInput; + omit?: OmitInput; }; -export type UpdateScalarInput< +type UpdateScalarInput< Schema extends SchemaDef, Model extends GetModels, Without extends string = never, @@ -736,7 +746,7 @@ type ScalarUpdatePayload< } : never); -export type UpdateRelationInput< +type UpdateRelationInput< Schema extends SchemaDef, Model extends GetModels, Without extends string = never, @@ -747,7 +757,7 @@ export type UpdateRelationInput< Without >; -export type UpdateInput< +type UpdateInput< Schema extends SchemaDef, Model extends GetModels, Without extends string = never, @@ -803,9 +813,9 @@ type ToOneRelationUpdateInput< export type DeleteArgs> = { where: WhereUniqueInput; - select?: Select; - include?: Include; - omit?: OmitFields; + select?: SelectInput; + include?: IncludeInput; + omit?: OmitInput; }; export type DeleteManyArgs> = { @@ -824,7 +834,7 @@ export type CountArgs> select?: CountAggregateInput | true; }; -export type CountAggregateInput> = { +type CountAggregateInput> = { [Key in NonRelationFields]?: true; } & { _all?: true }; diff --git a/packages/runtime/src/client/crud/operations/base.ts b/packages/runtime/src/client/crud/operations/base.ts index 59a31ecf..32775ef8 100644 --- a/packages/runtime/src/client/crud/operations/base.ts +++ b/packages/runtime/src/client/crud/operations/base.ts @@ -181,17 +181,18 @@ export abstract class BaseOperationHandler { } // select - if (args?.select) { + if (args && 'select' in args && args.select) { // select is mutually exclusive with omit - query = this.buildFieldSelection(model, query, args?.select, model); + query = this.buildFieldSelection(model, query, args.select, model); } else { // include all scalar fields except those in omit - query = this.buildSelectAllScalarFields(model, query, args?.omit); + query = this.buildSelectAllScalarFields(model, query, (args as any)?.omit); } // include - if (args?.include) { - query = this.buildFieldSelection(model, query, args?.include, model); + if (args && 'include' in args && args.include) { + // note that 'omit' is handled above already + query = this.buildFieldSelection(model, query, args.include, model); } if (args?.cursor) { @@ -1878,7 +1879,7 @@ export abstract class BaseOperationHandler { } protected trimResult(data: any, args: SelectIncludeOmit, boolean>) { - if (!args.select) { + if (!('select' in args) || !args.select) { return data; } return Object.keys(args.select).reduce((acc, field) => { @@ -1890,9 +1891,9 @@ export abstract class BaseOperationHandler { protected needReturnRelations(model: string, args: SelectIncludeOmit, boolean>) { let returnRelation = false; - if (args.include) { + if ('include' in args && args.include) { returnRelation = Object.keys(args.include).length > 0; - } else if (args.select) { + } else if ('select' in args && args.select) { returnRelation = Object.entries(args.select).some(([K, v]) => { const fieldDef = this.requireField(model, K); return fieldDef.relation && v; diff --git a/packages/runtime/src/index.ts b/packages/runtime/src/index.ts index 4f1cce44..b5018f05 100644 --- a/packages/runtime/src/index.ts +++ b/packages/runtime/src/index.ts @@ -1 +1,2 @@ export * from './client'; +export type { JsonArray, JsonObject, JsonValue } from './utils/type-utils'; diff --git a/packages/runtime/src/utils/type-utils.ts b/packages/runtime/src/utils/type-utils.ts index 6769f177..b28119a3 100644 --- a/packages/runtime/src/utils/type-utils.ts +++ b/packages/runtime/src/utils/type-utils.ts @@ -6,7 +6,7 @@ export type NullableIf = Condition extends true ? export type PartialRecord = Partial>; -type _Preserve = Date | Function | Decimal | Uint8Array; +type _Preserve = Date | Function | Decimal | Uint8Array | JsonObject | JsonValue; type _Depth = [never, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9]; export type Simplify = D extends 0 ? T diff --git a/packages/sdk/src/ts-schema-generator.ts b/packages/sdk/src/ts-schema-generator.ts index 1f06a3f7..d8c90934 100644 --- a/packages/sdk/src/ts-schema-generator.ts +++ b/packages/sdk/src/ts-schema-generator.ts @@ -52,9 +52,16 @@ export class TsSchemaGenerator { fs.mkdirSync(outputDir, { recursive: true }); + // the schema itself this.generateSchema(model, outputDir); + + // the model types this.generateModels(model, outputDir); + + // the input types + this.generateInputTypes(model, outputDir); } + private generateSchema(model: Model, outputDir: string) { const statements: ts.Statement[] = []; this.generateSchemaStatements(model, statements); @@ -960,22 +967,10 @@ export class TsSchemaGenerator { private generateModels(model: Model, outputDir: string) { const statements: ts.Statement[] = []; - // generate: import type { ModelResult } from '@zenstackhq/runtime'; - statements.push( - ts.factory.createImportDeclaration( - undefined, - ts.factory.createImportClause( - false, - undefined, - ts.factory.createNamedImports([ - ts.factory.createImportSpecifier(true, undefined, ts.factory.createIdentifier('ModelResult')), - ]), - ), - ts.factory.createStringLiteral('@zenstackhq/runtime'), - ), - ); + // generate: import { schema as $schema, type SchemaType as $Schema } from './schema'; + statements.push(this.generateSchemaTypeImport(true, true)); - // generate: import { schema } from './schema'; + // generate: import type { ModelResult as $ModelResult } from '@zenstackhq/runtime'; statements.push( ts.factory.createImportDeclaration( undefined, @@ -983,32 +978,26 @@ export class TsSchemaGenerator { false, undefined, ts.factory.createNamedImports([ - ts.factory.createImportSpecifier(false, undefined, ts.factory.createIdentifier('schema')), + ts.factory.createImportSpecifier( + true, + undefined, + ts.factory.createIdentifier(`ModelResult as $ModelResult`), + ), ]), ), - ts.factory.createStringLiteral('./schema'), - ), - ); - - // generate: type Schema = typeof schema; - statements.push( - ts.factory.createTypeAliasDeclaration( - [ts.factory.createModifier(ts.SyntaxKind.ExportKeyword)], - 'Schema', - undefined, - ts.factory.createTypeReferenceNode('typeof schema'), + ts.factory.createStringLiteral('@zenstackhq/runtime'), ), ); const dataModels = model.declarations.filter(isDataModel); for (const dm of dataModels) { - // generate: export type Model = ModelResult; + // generate: export type Model = $ModelResult; let modelType = ts.factory.createTypeAliasDeclaration( [ts.factory.createModifier(ts.SyntaxKind.ExportKeyword)], dm.name, undefined, - ts.factory.createTypeReferenceNode('ModelResult', [ - ts.factory.createTypeReferenceNode('Schema'), + ts.factory.createTypeReferenceNode('$ModelResult', [ + ts.factory.createTypeReferenceNode('$Schema'), ts.factory.createLiteralTypeNode(ts.factory.createStringLiteral(dm.name)), ]), ); @@ -1021,7 +1010,7 @@ export class TsSchemaGenerator { // generate enums const enums = model.declarations.filter(isEnum); for (const e of enums) { - // generate: export const Enum = schema.enums.Enum; + // generate: export const Enum = $schema.enums.Enum; let enumDecl = ts.factory.createVariableStatement( [ts.factory.createModifier(ts.SyntaxKind.ExportKeyword)], ts.factory.createVariableDeclarationList( @@ -1032,7 +1021,7 @@ export class TsSchemaGenerator { undefined, ts.factory.createPropertyAccessExpression( ts.factory.createPropertyAccessExpression( - ts.factory.createIdentifier('schema'), + ts.factory.createIdentifier('$schema'), ts.factory.createIdentifier('enums'), ), ts.factory.createIdentifier(e.name), @@ -1076,6 +1065,36 @@ export class TsSchemaGenerator { fs.writeFileSync(outputFile, result); } + private generateSchemaTypeImport(schemaObject: boolean, schemaType: boolean) { + const importSpecifiers = []; + + if (schemaObject) { + importSpecifiers.push( + ts.factory.createImportSpecifier( + false, + ts.factory.createIdentifier('schema'), + ts.factory.createIdentifier('$schema'), + ), + ); + } + + if (schemaType) { + importSpecifiers.push( + ts.factory.createImportSpecifier( + true, + ts.factory.createIdentifier('SchemaType'), + ts.factory.createIdentifier('$Schema'), + ), + ); + } + + return ts.factory.createImportDeclaration( + undefined, + ts.factory.createImportClause(false, undefined, ts.factory.createNamedImports(importSpecifiers)), + ts.factory.createStringLiteral('./schema'), + ); + } + private generateDocs( tsDecl: T, decl: DataModel | Enum, @@ -1087,4 +1106,139 @@ export class TsSchemaGenerator { true, ); } + + private generateInputTypes(model: Model, outputDir: string) { + const dataModels = model.declarations.filter(isDataModel); + const statements: ts.Statement[] = []; + + // generate: import { SchemaType as $Schema } from './schema'; + statements.push(this.generateSchemaTypeImport(false, true)); + + // generate: import { CreateArgs as $CreateArgs, ... } from '@zenstackhq/runtime'; + const inputTypes = [ + 'FindManyArgs', + 'FindUniqueArgs', + 'FindFirstArgs', + 'CreateArgs', + 'CreateManyArgs', + 'CreateManyAndReturnArgs', + 'UpdateArgs', + 'UpdateManyArgs', + 'UpdateManyAndReturnArgs', + 'UpsertArgs', + 'DeleteArgs', + 'DeleteManyArgs', + 'CountArgs', + 'AggregateArgs', + 'GroupByArgs', + 'WhereInput', + 'SelectInput', + 'IncludeInput', + 'OmitInput', + ]; + + const inputTypeNameFixes = { + SelectInput: 'Select', + IncludeInput: 'Include', + OmitInput: 'Omit', + }; + + // generate: import { CreateArgs as $CreateArgs, ... } from '@zenstackhq/runtime'; + statements.push( + ts.factory.createImportDeclaration( + undefined, + ts.factory.createImportClause( + true, + undefined, + ts.factory.createNamedImports( + inputTypes.map((inputType) => + ts.factory.createImportSpecifier( + false, + undefined, + ts.factory.createIdentifier(`${inputType} as $${inputType}`), + ), + ), + ), + ), + ts.factory.createStringLiteral('@zenstackhq/runtime'), + ), + ); + + // generate: import { type SelectIncludeOmit as $SelectIncludeOmit, type SimplifiedModelResult as $SimplifiedModelResult } from '@zenstackhq/runtime'; + statements.push( + ts.factory.createImportDeclaration( + undefined, + ts.factory.createImportClause( + true, + undefined, + ts.factory.createNamedImports([ + ts.factory.createImportSpecifier( + false, + undefined, + ts.factory.createIdentifier('SimplifiedModelResult as $SimplifiedModelResult'), + ), + ts.factory.createImportSpecifier( + false, + undefined, + ts.factory.createIdentifier('SelectIncludeOmit as $SelectIncludeOmit'), + ), + ]), + ), + ts.factory.createStringLiteral('@zenstackhq/runtime'), + ), + ); + + for (const dm of dataModels) { + // generate: export type ModelCreateArgs = $CreateArgs; + for (const inputType of inputTypes) { + const exportName = inputTypeNameFixes[inputType as keyof typeof inputTypeNameFixes] + ? `${dm.name}${inputTypeNameFixes[inputType as keyof typeof inputTypeNameFixes]}` + : `${dm.name}${inputType}`; + statements.push( + ts.factory.createTypeAliasDeclaration( + [ts.factory.createModifier(ts.SyntaxKind.ExportKeyword)], + exportName, + undefined, + ts.factory.createTypeReferenceNode(`$${inputType}`, [ + ts.factory.createTypeReferenceNode('$Schema'), + ts.factory.createLiteralTypeNode(ts.factory.createStringLiteral(dm.name)), + ]), + ), + ); + } + + // generate: export type ModelGetPayload> = $SimplifiedModelResult; + statements.push( + ts.factory.createTypeAliasDeclaration( + [ts.factory.createModifier(ts.SyntaxKind.ExportKeyword)], + `${dm.name}GetPayload`, + [ + ts.factory.createTypeParameterDeclaration( + undefined, + 'Args', + ts.factory.createTypeReferenceNode('$SelectIncludeOmit', [ + ts.factory.createTypeReferenceNode('$Schema'), + ts.factory.createLiteralTypeNode(ts.factory.createStringLiteral(dm.name)), + ts.factory.createLiteralTypeNode(ts.factory.createTrue()), + ]), + ), + ], + ts.factory.createTypeReferenceNode('$SimplifiedModelResult', [ + ts.factory.createTypeReferenceNode('$Schema'), + ts.factory.createLiteralTypeNode(ts.factory.createStringLiteral(dm.name)), + ts.factory.createTypeReferenceNode('Args'), + ]), + ), + ); + } + + this.generateBannerComments(statements); + + // write to file + const outputFile = path.join(outputDir, 'input.ts'); + const sourceFile = ts.createSourceFile(outputFile, '', ts.ScriptTarget.ESNext, false, ts.ScriptKind.TS); + const printer = ts.createPrinter(); + const result = printer.printList(ts.ListFormat.MultiLine, ts.factory.createNodeArray(statements), sourceFile); + fs.writeFileSync(outputFile, result); + } } diff --git a/samples/blog/zenstack/input.ts b/samples/blog/zenstack/input.ts new file mode 100644 index 00000000..c6e7433e --- /dev/null +++ b/samples/blog/zenstack/input.ts @@ -0,0 +1,70 @@ +////////////////////////////////////////////////////////////////////////////////////////////// +// DO NOT MODIFY THIS FILE // +// This file is automatically generated by ZenStack CLI and should not be manually updated. // +////////////////////////////////////////////////////////////////////////////////////////////// + +/* 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/runtime"; +import type { SimplifiedModelResult as $SimplifiedModelResult, SelectIncludeOmit as $SelectIncludeOmit } from "@zenstackhq/runtime"; +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 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 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/samples/blog/zenstack/models.ts b/samples/blog/zenstack/models.ts index 455df504..a55d9275 100644 --- a/samples/blog/zenstack/models.ts +++ b/samples/blog/zenstack/models.ts @@ -5,27 +5,26 @@ /* eslint-disable */ -import { type ModelResult } from "@zenstackhq/runtime"; -import { schema } from "./schema"; -export type Schema = typeof schema; +import { schema as $schema, type SchemaType as $Schema } from "./schema"; +import { type ModelResult as $ModelResult } from "@zenstackhq/runtime"; /** * User model * * Represents a user of the blog. */ -export type User = ModelResult; +export type User = $ModelResult<$Schema, "User">; /** * Profile model */ -export type Profile = ModelResult; +export type Profile = $ModelResult<$Schema, "Profile">; /** * Post model */ -export type Post = ModelResult; +export type Post = $ModelResult<$Schema, "Post">; /** * User roles */ -export const Role = schema.enums.Role; +export const Role = $schema.enums.Role; /** * User roles */