diff --git a/packages/accel-record-core/src/index.ts b/packages/accel-record-core/src/index.ts index a67b5f0d..84fdd778 100644 --- a/packages/accel-record-core/src/index.ts +++ b/packages/accel-record-core/src/index.ts @@ -32,8 +32,6 @@ export type Meta = ReturnType>; export declare function meta(model: T): ModelMeta; -export type SortOrder = "asc" | "desc"; - export type Filter = { in?: T[]; "<"?: T; diff --git a/packages/accel-record-core/src/meta.ts b/packages/accel-record-core/src/meta.ts index 137af55d..2ef1705c 100644 --- a/packages/accel-record-core/src/meta.ts +++ b/packages/accel-record-core/src/meta.ts @@ -1,4 +1,4 @@ -import { Meta, Model, SortOrder } from "./index.js"; +import { Meta, Model } from "./index.js"; export type { Meta }; export type Persisted = Meta["Persisted"]; @@ -12,5 +12,4 @@ export type ModelMeta = { Column: Record; WhereInput: Record; CreateInput: Record; - OrderInput: Record; }; diff --git a/packages/accel-record-core/src/model/dirty.ts b/packages/accel-record-core/src/model/dirty.ts index 939b913b..cd09727e 100644 --- a/packages/accel-record-core/src/model/dirty.ts +++ b/packages/accel-record-core/src/model/dirty.ts @@ -27,7 +27,7 @@ export class Dirty { */ isAttributeChanged( this: T, - attribute: keyof Meta["OrderInput"] + attribute: keyof Meta["Column"] ): boolean { return ( this[attribute as keyof T] !== this.originalValues[attribute as string] @@ -42,7 +42,7 @@ export class Dirty { */ isChanged( this: T, - attribute?: keyof Meta["OrderInput"] + attribute?: keyof Meta["Column"] ): boolean { if (attribute) { return this.isAttributeChanged(attribute); diff --git a/packages/accel-record-core/src/model/import.ts b/packages/accel-record-core/src/model/import.ts index 73c73bb0..ab3d3302 100644 --- a/packages/accel-record-core/src/model/import.ts +++ b/packages/accel-record-core/src/model/import.ts @@ -19,14 +19,14 @@ type ImportOptions = { * - If not provided or set to `true`, existing records will be updated. * - If set to an array of keys, only the specified keys will be updated. */ - onDuplicateKeyUpdate?: true | (keyof Meta["OrderInput"])[]; + onDuplicateKeyUpdate?: true | (keyof Meta["Column"])[]; /** * Specifies the conflict target for resolving conflicts when a duplicate key is encountered. * - If not provided, the entire record will be considered as the conflict target. * - If set to an array of keys, only the specified keys will be considered as the conflict target. */ - conflictTarget?: (keyof Meta["OrderInput"])[]; + conflictTarget?: (keyof Meta["Column"])[]; }; type ImportResult = { diff --git a/packages/accel-record-core/src/model/serialization.ts b/packages/accel-record-core/src/model/serialization.ts index 103b0dad..abec8996 100644 --- a/packages/accel-record-core/src/model/serialization.ts +++ b/packages/accel-record-core/src/model/serialization.ts @@ -51,7 +51,7 @@ type ToHashMethods< export type ToHashResult> = { [K in undefined extends O["only"] - ? Exclude["OrderInput"], ToUnion> + ? Exclude["Column"], ToUnion> : ToUnion]: T[Extract]; } & ToHashInclude & ToHashMethods; @@ -67,8 +67,8 @@ type NoArgMethods = { }[keyof T]; export type ToHashOptions = { - only?: (keyof Meta["OrderInput"])[]; - except?: (keyof Meta["OrderInput"])[]; + only?: (keyof Meta["Column"])[]; + except?: (keyof Meta["Column"])[]; methods?: NoArgMethods[]; include?: Meta["AssociationKey"] | ToHashIncludeOption; }; diff --git a/packages/accel-record-core/src/query.ts b/packages/accel-record-core/src/query.ts index b035f256..caa323af 100644 --- a/packages/accel-record-core/src/query.ts +++ b/packages/accel-record-core/src/query.ts @@ -97,10 +97,7 @@ export class Query { * @param columns - The columns to select. * @returns A `Relation` object representing the query result with the selected columns. */ - static select< - T extends typeof Model, - F extends (keyof Meta["OrderInput"])[], - >( + static select["Column"])[]>( this: T, ...attributes: F // @ts-ignore @@ -209,7 +206,7 @@ export class Query { */ static order( this: T, - attribute: keyof Meta["OrderInput"], + attribute: keyof Meta["Column"], direction?: "asc" | "desc" ): Relation, Meta> { return this.all().order(attribute, direction); @@ -338,7 +335,7 @@ export class Query { */ static maximum( this: T, - attribute: keyof Meta["OrderInput"] + attribute: keyof Meta["Column"] ) { return this.all().maximum(attribute); } @@ -350,7 +347,7 @@ export class Query { */ static minimum( this: T, - attribute: keyof Meta["OrderInput"] + attribute: keyof Meta["Column"] ) { return this.all().minimum(attribute); } @@ -362,7 +359,7 @@ export class Query { */ static average( this: T, - attribute: keyof Meta["OrderInput"] + attribute: keyof Meta["Column"] ) { return this.all().average(attribute); } diff --git a/packages/accel-record-core/src/relation/calculations.ts b/packages/accel-record-core/src/relation/calculations.ts index e0ad5a5f..3c21e2aa 100644 --- a/packages/accel-record-core/src/relation/calculations.ts +++ b/packages/accel-record-core/src/relation/calculations.ts @@ -27,7 +27,7 @@ export class Calculations { */ minimum( this: Relation, - attribute: keyof M["OrderInput"] + attribute: keyof M["Column"] ) { const res = exec( this.query().min(this.model.attributeToColumn(attribute as string)) @@ -43,7 +43,7 @@ export class Calculations { */ maximum( this: Relation, - attribute: keyof M["OrderInput"] + attribute: keyof M["Column"] ) { const res = exec( this.query().max(this.model.attributeToColumn(attribute as string)) @@ -59,7 +59,7 @@ export class Calculations { */ average( this: Relation, - attribute: keyof M["OrderInput"] + attribute: keyof M["Column"] ) { const res = exec( this.query().avg(this.model.attributeToColumn(attribute as string)) diff --git a/packages/accel-record-core/src/relation/query.ts b/packages/accel-record-core/src/relation/query.ts index f5efb37d..c5d20756 100644 --- a/packages/accel-record-core/src/relation/query.ts +++ b/packages/accel-record-core/src/relation/query.ts @@ -98,7 +98,7 @@ export class Query { */ order( this: Relation, - attribute: keyof M["OrderInput"], + attribute: keyof M["Column"], direction: "asc" | "desc" = "asc" ): Relation { const newOptions = JSON.parse(JSON.stringify(this.options)); @@ -164,7 +164,7 @@ export class Query { select< T, M extends ModelMeta, - F extends (keyof M["OrderInput"])[], + F extends (keyof M["Column"])[], // @ts-ignore R extends { [K in F[number]]: M["Persisted"][K] }, >( diff --git a/packages/accel-record-core/src/validation/validator/uniqueness.ts b/packages/accel-record-core/src/validation/validator/uniqueness.ts index b028e7b0..e19c4c20 100644 --- a/packages/accel-record-core/src/validation/validator/uniqueness.ts +++ b/packages/accel-record-core/src/validation/validator/uniqueness.ts @@ -3,7 +3,7 @@ import { Validator } from "./index.js"; export type UniqunessOptions = | boolean - | { scope: (keyof Meta["OrderInput"] & string)[] }; + | { scope: (keyof Meta["Column"] & string)[] }; export class UniquenessValidator extends Validator { constructor( diff --git a/packages/prisma-generator-accel-record/src/generators/type.ts b/packages/prisma-generator-accel-record/src/generators/type.ts index 6625af60..af3cf743 100644 --- a/packages/prisma-generator-accel-record/src/generators/type.ts +++ b/packages/prisma-generator-accel-record/src/generators/type.ts @@ -111,7 +111,6 @@ export const generateTypes = (options: GeneratorOptions) => { registerModel, type Collection, type Filter, - type SortOrder, type StringFilter, } from "accel-record"; @@ -161,12 +160,6 @@ declare module "accel-record" { return ` & ({ ${f.name}: ${f.type} } | { ${foreignKeys} })`; }) .join(""); - const orderInputs = - model.fields - .filter(reject) - .filter((field) => field.relationName == undefined) - .map((field) => `\n ${field.name}?: SortOrder;`) - .join("") + "\n "; data += ` declare module "./${model.fileName}" { interface ${model.baseModel} { @@ -187,7 +180,6 @@ type ${model.meta} = { ${columns} }${associationColumns}; WhereInput: {${whereInputs(model)}}; - OrderInput: {${orderInputs}}; }; registerModel(${model.persistedModel}); `; diff --git a/tests/models/_types.ts b/tests/models/_types.ts index 43025bec..a67dec9e 100644 --- a/tests/models/_types.ts +++ b/tests/models/_types.ts @@ -16,7 +16,6 @@ import { registerModel, type Collection, type Filter, - type SortOrder, type StringFilter, } from "accel-record"; @@ -113,14 +112,6 @@ type UserMeta = { createdAt?: Date | Date[] | Filter | null; updatedAt?: Date | Date[] | Filter | null; }; - OrderInput: { - id?: SortOrder; - email?: SortOrder; - name?: SortOrder; - age?: SortOrder; - createdAt?: SortOrder; - updatedAt?: SortOrder; - }; }; registerModel(User); @@ -159,10 +150,6 @@ type TeamMeta = { id?: number | number[] | Filter | null; name?: string | string[] | StringFilter | null; }; - OrderInput: { - id?: SortOrder; - name?: SortOrder; - }; }; registerModel(Team); @@ -210,12 +197,6 @@ type UserTeamMeta = { assignedAt?: Date | Date[] | Filter | null; assignedBy?: string | string[] | StringFilter | null; }; - OrderInput: { - userId?: SortOrder; - teamId?: SortOrder; - assignedAt?: SortOrder; - assignedBy?: SortOrder; - }; }; registerModel(UserTeam); @@ -269,13 +250,6 @@ type PostMeta = { author?: User | User[]; authorId?: number | number[] | Filter | null; }; - OrderInput: { - id?: SortOrder; - title?: SortOrder; - content?: SortOrder; - published?: SortOrder; - authorId?: SortOrder; - }; }; registerModel(Post); @@ -314,10 +288,6 @@ type PostTagMeta = { id?: number | number[] | Filter | null; name?: string | string[] | StringFilter | null; }; - OrderInput: { - id?: SortOrder; - name?: SortOrder; - }; }; registerModel(PostTag); @@ -364,13 +334,6 @@ type SettingMeta = { threshold?: number | number[] | Filter | null; createdAt?: Date | Date[] | Filter | null; }; - OrderInput: { - settingId?: SortOrder; - userId?: SortOrder; - threshold?: SortOrder; - createdAt?: SortOrder; - data?: SortOrder; - }; }; registerModel(Setting); @@ -430,16 +393,6 @@ type ProfileMeta = { uuid?: string | string[] | StringFilter | null; cuid?: string | string[] | StringFilter | null; }; - OrderInput: { - id?: SortOrder; - userId?: SortOrder; - bio?: SortOrder; - point?: SortOrder; - enabled?: SortOrder; - role?: SortOrder; - uuid?: SortOrder; - cuid?: SortOrder; - }; }; registerModel(Profile); @@ -478,10 +431,6 @@ type CompanyMeta = { id?: number | number[] | Filter | null; name?: string | string[] | StringFilter | null; }; - OrderInput: { - id?: SortOrder; - name?: SortOrder; - }; }; registerModel(Company); @@ -522,11 +471,6 @@ type EmployeeMeta = { companyId?: number | number[] | Filter | null; company?: Company | Company[]; }; - OrderInput: { - id?: SortOrder; - name?: SortOrder; - companyId?: SortOrder; - }; }; registerModel(Employee); @@ -580,13 +524,5 @@ type ValidateSampleMeta = { count?: number | number[] | Filter | null; size?: string | string[] | StringFilter | null; }; - OrderInput: { - id?: SortOrder; - accepted?: SortOrder; - pattern?: SortOrder; - key?: SortOrder; - count?: SortOrder; - size?: SortOrder; - }; }; registerModel(ValidateSample);