Improve ORM templates; improve StaticClass typedef; bump version
This commit is contained in:
parent
25265b5560
commit
f6a7cac05c
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@extollo/lib",
|
"name": "@extollo/lib",
|
||||||
"version": "0.9.22",
|
"version": "0.9.23",
|
||||||
"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",
|
||||||
|
@ -36,7 +36,7 @@ export function isInstantiableOf<T>(what: unknown, type: StaticClass<T, any>): w
|
|||||||
/**
|
/**
|
||||||
* Type that identifies a value as a static class, even if it is not instantiable.
|
* Type that identifies a value as a static class, even if it is not instantiable.
|
||||||
*/
|
*/
|
||||||
export type StaticClass<T, T2> = Function & {prototype: T} & T2 // eslint-disable-line @typescript-eslint/ban-types
|
export type StaticClass<T, T2, TCtorParams extends any[] = any[]> = Function & {prototype: T} & { new (...args: TCtorParams) : T } & T2 // eslint-disable-line @typescript-eslint/ban-types
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Type that identifies a value as a static class that instantiates to itself
|
* Type that identifies a value as a static class that instantiates to itself
|
||||||
|
@ -9,7 +9,7 @@ const templateMigration: Template = {
|
|||||||
baseAppPath: ['migrations'],
|
baseAppPath: ['migrations'],
|
||||||
description: 'Create a new class that applies a one-time migration',
|
description: 'Create a new class that applies a one-time migration',
|
||||||
render: (name: string) => {
|
render: (name: string) => {
|
||||||
return `import {Injectable, Migration} from '@extollo/lib'
|
return `import {Injectable, Migration, Inject, DatabaseService} from '@extollo/lib'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ${name}
|
* ${name}
|
||||||
@ -18,11 +18,14 @@ const templateMigration: Template = {
|
|||||||
*/
|
*/
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export default class ${name} extends Migration {
|
export default class ${name} extends Migration {
|
||||||
|
@Inject()
|
||||||
|
protected readonly db!: DatabaseService
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Apply the migration.
|
* Apply the migration.
|
||||||
*/
|
*/
|
||||||
async up(): Promise<void> {
|
async up(): Promise<void> {
|
||||||
|
const schema = this.db.get().schema()
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -30,6 +33,7 @@ export default class ${name} extends Migration {
|
|||||||
* Undo the migration.
|
* Undo the migration.
|
||||||
*/
|
*/
|
||||||
async down(): Promise<void> {
|
async down(): Promise<void> {
|
||||||
|
const schema = this.db.get().schema()
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -9,7 +9,7 @@ const templateModel: Template = {
|
|||||||
baseAppPath: ['models'],
|
baseAppPath: ['models'],
|
||||||
description: 'Create a new class that represents a record in a database',
|
description: 'Create a new class that represents a record in a database',
|
||||||
render: (name: string) => {
|
render: (name: string) => {
|
||||||
return `import {Injectable, Model} from "@extollo/lib"
|
return `import {Injectable, Model} from '@extollo/lib'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ${name} Model
|
* ${name} Model
|
||||||
@ -18,8 +18,8 @@ const templateModel: Template = {
|
|||||||
*/
|
*/
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class ${name} extends Model<${name}> {
|
export class ${name} extends Model<${name}> {
|
||||||
protected static table = '${name.toLowerCase()}';
|
protected static table = '${name.toLowerCase()}'
|
||||||
protected static key = '${name.toLowerCase()}_id';
|
protected static key = '${name.toLowerCase()}_id'
|
||||||
}
|
}
|
||||||
`
|
`
|
||||||
},
|
},
|
||||||
|
Loading…
Reference in New Issue
Block a user