7 Commits

Author SHA1 Message Date
6fc901b3ec bump version
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/tag Build is passing
2021-11-25 17:05:22 -06:00
50e0cf3090 Fix prototype access issue with model scopes property
All checks were successful
continuous-integration/drone/push Build is passing
2021-11-25 17:02:43 -06:00
d245d15ad6 Bump version
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/tag Build is passing
2021-11-25 16:52:35 -06:00
265837b5cd Fix stupid typescript error...
All checks were successful
continuous-integration/drone/push Build is passing
2021-11-25 16:50:01 -06:00
fe0b4d6d8f bump version
Some checks failed
continuous-integration/drone/push Build is failing
continuous-integration/drone/tag Build is failing
2021-11-25 16:39:53 -06:00
ce1d22ff44 Make the linter happy
Some checks failed
continuous-integration/drone/push Build is failing
2021-11-25 16:39:25 -06:00
b7bfb3e153 Model: fix eager-loaded relation loading from static query 2021-11-25 16:39:17 -06:00
4 changed files with 30 additions and 9 deletions

View File

@@ -1,6 +1,6 @@
{ {
"name": "@extollo/lib", "name": "@extollo/lib",
"version": "0.5.9", "version": "0.5.12",
"description": "The framework library that lifts up your code.", "description": "The framework library that lifts up your code.",
"main": "lib/index.js", "main": "lib/index.js",
"types": "lib/index.d.ts", "types": "lib/index.d.ts",

View File

@@ -1,7 +1,6 @@
import { import {
Authenticatable, Authenticatable,
AuthenticatableCredentials, AuthenticatableCredentials,
AuthenticatableIdentifier,
AuthenticatableRepository, AuthenticatableRepository,
} from '../../types' } from '../../types'
import {Inject, Injectable} from '../../../di' import {Inject, Injectable} from '../../../di'
@@ -46,7 +45,7 @@ export class OAuth2Repository implements AuthenticatableRepository {
return this.getAuthenticatableFromBearer(credentials.credential) return this.getAuthenticatableFromBearer(credentials.credential)
} }
getByIdentifier(id: AuthenticatableIdentifier): Awaitable<Maybe<Authenticatable>> { getByIdentifier(): Awaitable<Maybe<Authenticatable>> {
return undefined return undefined
} }

View File

@@ -174,13 +174,35 @@ export abstract class Model<T extends Model<T>> extends AppClass implements Bus
builder.field(field.databaseKey) builder.field(field.databaseKey)
}) })
for ( const relation of this.prototype.with ) { if ( Array.isArray(this.prototype.with) ) {
// Try to get the eager-loaded relations statically, if possible
for (const relation of this.prototype.with) {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment // eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore // @ts-ignore
builder.with(relation) builder.with(relation)
} }
} else if ( this.constructor.length < 1 ) {
// Otherwise, if we can instantiate the model without any arguments,
// do that and get the eager-loaded relations directly.
const inst = Container.getContainer().make<Model<any>>(this)
if ( Array.isArray(inst.with) ) {
for (const relation of inst.with) {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
builder.with(relation)
}
}
}
if ( this.prototype.scopes ) {
// Same thing here. Try to get the scopes statically, if possible
builder.withScopes(this.prototype.scopes) builder.withScopes(this.prototype.scopes)
} else if ( this.constructor.length < 1 ) {
// Otherwise, try to instantiate the model if possible and load the scopes that way
const inst = Container.getContainer().make<Model<any>>(this)
builder.withScopes(inst.scopes)
}
return builder return builder
} }

View File

@@ -330,7 +330,7 @@ export class AsyncCollection<T> {
await this.each(async (item, index) => { await this.each(async (item, index) => {
const result = await func(item, index) const result = await func(item, index)
if ( typeof result !== 'undefined' ) { if ( typeof result !== 'undefined' ) {
newItems.push(result as NonNullable<T2>) newItems.push(result as unknown as NonNullable<T2>)
} }
}) })