mirror of
https://github.com/typeorm/typeorm.git
synced 2025-12-08 21:26:23 +00:00
feat: added opaque types support over primitives in find-options (#9560)
* added opaque types support over primitives in find-options * removed lock-verify because of its deprecation * fixing auto type mapping
This commit is contained in:
parent
85fa9c6e7d
commit
4ec04fa120
@ -12,14 +12,14 @@ commands:
|
||||
steps:
|
||||
- when:
|
||||
condition:
|
||||
equal: [ << parameters.databases >>, "" ]
|
||||
equal: [<< parameters.databases >>, ""]
|
||||
steps:
|
||||
- run:
|
||||
name: "Enabling Databases in ORM config"
|
||||
command: cp ormconfig.circleci-common.json ./ormconfig.json
|
||||
- unless:
|
||||
condition:
|
||||
equal: [ << parameters.databases >>, "" ]
|
||||
equal: [<< parameters.databases >>, ""]
|
||||
steps:
|
||||
- run:
|
||||
name: "Enabling Databases in ORM config"
|
||||
@ -40,9 +40,10 @@ commands:
|
||||
- restore_cache:
|
||||
name: Restore node_modules cache
|
||||
key: node_modules-<< parameters.cache-key >>-{{ checksum "package-lock.json" }}
|
||||
- run:
|
||||
name: Verify `package.json` and `package-lock.json` are in sync
|
||||
command: npx lock-verify
|
||||
# removed this item because lock-verify is deprecated
|
||||
# - run:
|
||||
# name: Verify `package.json` and `package-lock.json` are in sync
|
||||
# command: npx lock-verify
|
||||
- run:
|
||||
# This uses `npm install` instead of `npm ci`
|
||||
# because of https://github.com/npm/cli/issues/558
|
||||
|
||||
@ -11,6 +11,12 @@ export type FindOptionsOrderProperty<Property> = Property extends Promise<
|
||||
? FindOptionsOrderProperty<NonNullable<I>>
|
||||
: Property extends Function
|
||||
? never
|
||||
: Property extends string
|
||||
? FindOptionsOrderValue
|
||||
: Property extends number
|
||||
? FindOptionsOrderValue
|
||||
: Property extends boolean
|
||||
? FindOptionsOrderValue
|
||||
: Property extends Buffer
|
||||
? FindOptionsOrderValue
|
||||
: Property extends Date
|
||||
|
||||
@ -9,6 +9,12 @@ export type FindOptionsRelationsProperty<Property> = Property extends Promise<
|
||||
? FindOptionsRelationsProperty<NonNullable<I>> | boolean
|
||||
: Property extends Array<infer I>
|
||||
? FindOptionsRelationsProperty<NonNullable<I>> | boolean
|
||||
: Property extends string
|
||||
? never
|
||||
: Property extends number
|
||||
? never
|
||||
: Property extends boolean
|
||||
? never
|
||||
: Property extends Function
|
||||
? never
|
||||
: Property extends Buffer
|
||||
|
||||
@ -9,6 +9,12 @@ export type FindOptionsSelectProperty<Property> = Property extends Promise<
|
||||
? FindOptionsSelectProperty<I> | boolean
|
||||
: Property extends Array<infer I>
|
||||
? FindOptionsSelectProperty<I> | boolean
|
||||
: Property extends string
|
||||
? boolean
|
||||
: Property extends number
|
||||
? boolean
|
||||
: Property extends boolean
|
||||
? boolean
|
||||
: Property extends Function
|
||||
? never
|
||||
: Property extends Buffer
|
||||
|
||||
@ -19,6 +19,12 @@ export type FindOptionsWhereProperty<Property> = Property extends Promise<
|
||||
? Property | FindOperator<Property>
|
||||
: Property extends ObjectID
|
||||
? Property | FindOperator<Property>
|
||||
: Property extends string
|
||||
? Property | FindOperator<Property>
|
||||
: Property extends number
|
||||
? Property | FindOperator<Property>
|
||||
: Property extends boolean
|
||||
? Property | FindOperator<Property>
|
||||
: Property extends object
|
||||
?
|
||||
| FindOptionsWhere<Property>
|
||||
@ -28,7 +34,7 @@ export type FindOptionsWhereProperty<Property> = Property extends Promise<
|
||||
| boolean
|
||||
: Property | FindOperator<Property>
|
||||
|
||||
/** :
|
||||
/**
|
||||
* Used for find operations.
|
||||
*/
|
||||
export type FindOptionsWhere<Entity> = {
|
||||
|
||||
@ -0,0 +1,15 @@
|
||||
import { Column, Entity, PrimaryColumn } from "../../../../../src"
|
||||
|
||||
export type WithType<T> = T & { type: "Post" }
|
||||
|
||||
@Entity()
|
||||
export class Post {
|
||||
@PrimaryColumn({ type: Number })
|
||||
id: number & { type: "Post" }
|
||||
|
||||
@Column({ type: String })
|
||||
title: string & { type: "Post" }
|
||||
|
||||
@Column({ type: Boolean })
|
||||
isEdited: boolean & { type: "Post" }
|
||||
}
|
||||
@ -0,0 +1,100 @@
|
||||
import "reflect-metadata"
|
||||
import "../../../utils/test-setup"
|
||||
import { DataSource } from "../../../../src"
|
||||
import {
|
||||
closeTestingConnections,
|
||||
createTestingConnections,
|
||||
reloadTestingDatabases,
|
||||
} from "../../../utils/test-utils"
|
||||
import { Post, WithType } from "./entity/Post"
|
||||
|
||||
describe("find options > opaque-types-over-primitives", () => {
|
||||
let dataSources: DataSource[]
|
||||
before(
|
||||
async () =>
|
||||
(dataSources = await createTestingConnections({
|
||||
__dirname,
|
||||
})),
|
||||
)
|
||||
beforeEach(() => reloadTestingDatabases(dataSources))
|
||||
after(() => closeTestingConnections(dataSources))
|
||||
|
||||
async function prepareData(dataSource: DataSource) {
|
||||
const post1 = new Post()
|
||||
post1.id = 1 as WithType<number>
|
||||
post1.title = "Hello" as WithType<string>
|
||||
post1.isEdited = true as WithType<boolean>
|
||||
await dataSource.manager.save(post1)
|
||||
}
|
||||
|
||||
it("should work in select", () =>
|
||||
Promise.all(
|
||||
dataSources.map(async (dataSource) => {
|
||||
await prepareData(dataSource)
|
||||
|
||||
const posts1 = await dataSource
|
||||
.createQueryBuilder(Post, "post")
|
||||
.setFindOptions({
|
||||
select: {
|
||||
id: true,
|
||||
title: true,
|
||||
isEdited: true,
|
||||
},
|
||||
})
|
||||
.getMany()
|
||||
|
||||
posts1.should.be.eql([
|
||||
{ id: 1, title: "Hello", isEdited: true },
|
||||
])
|
||||
}),
|
||||
))
|
||||
|
||||
it("should work in where", () =>
|
||||
Promise.all(
|
||||
dataSources.map(async (dataSource) => {
|
||||
await prepareData(dataSource)
|
||||
|
||||
const posts = await dataSource
|
||||
.createQueryBuilder(Post, "post")
|
||||
.setFindOptions({
|
||||
where: {
|
||||
id: 1 as WithType<number>,
|
||||
},
|
||||
})
|
||||
.getMany()
|
||||
|
||||
posts.should.be.eql([
|
||||
{
|
||||
id: 1,
|
||||
title: "Hello",
|
||||
isEdited: true,
|
||||
},
|
||||
])
|
||||
}),
|
||||
))
|
||||
|
||||
it("should work in order by", () =>
|
||||
Promise.all(
|
||||
dataSources.map(async (dataSource) => {
|
||||
await prepareData(dataSource)
|
||||
|
||||
const posts1 = await dataSource
|
||||
.createQueryBuilder(Post, "post")
|
||||
.setFindOptions({
|
||||
order: {
|
||||
id: "asc",
|
||||
title: "asc",
|
||||
isEdited: "asc",
|
||||
},
|
||||
})
|
||||
.getMany()
|
||||
posts1.should.be.eql([
|
||||
{
|
||||
id: 1,
|
||||
title: "Hello",
|
||||
isEdited: true,
|
||||
},
|
||||
])
|
||||
}),
|
||||
))
|
||||
})
|
||||
Loading…
x
Reference in New Issue
Block a user