From f6a7cac05c360a4fc98bd6f2d968fcdefe10764b Mon Sep 17 00:00:00 2001 From: garrettmills Date: Mon, 4 Apr 2022 14:45:45 -0500 Subject: [PATCH] Improve ORM templates; improve StaticClass typedef; bump version --- package.json | 2 +- src/di/types.ts | 2 +- src/orm/template/migration.ts | 6 +++++- src/orm/template/model.ts | 6 +++--- 4 files changed, 10 insertions(+), 6 deletions(-) diff --git a/package.json b/package.json index 0599b92..d49c9f1 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@extollo/lib", - "version": "0.9.22", + "version": "0.9.23", "description": "The framework library that lifts up your code.", "main": "lib/index.js", "types": "lib/index.d.ts", diff --git a/src/di/types.ts b/src/di/types.ts index afe7c0f..e27b43f 100644 --- a/src/di/types.ts +++ b/src/di/types.ts @@ -36,7 +36,7 @@ export function isInstantiableOf(what: unknown, type: StaticClass): w /** * Type that identifies a value as a static class, even if it is not instantiable. */ -export type StaticClass = Function & {prototype: T} & T2 // eslint-disable-line @typescript-eslint/ban-types +export type StaticClass = 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 diff --git a/src/orm/template/migration.ts b/src/orm/template/migration.ts index 529c31c..52534a8 100644 --- a/src/orm/template/migration.ts +++ b/src/orm/template/migration.ts @@ -9,7 +9,7 @@ const templateMigration: Template = { baseAppPath: ['migrations'], description: 'Create a new class that applies a one-time migration', render: (name: string) => { - return `import {Injectable, Migration} from '@extollo/lib' + return `import {Injectable, Migration, Inject, DatabaseService} from '@extollo/lib' /** * ${name} @@ -18,11 +18,14 @@ const templateMigration: Template = { */ @Injectable() export default class ${name} extends Migration { + @Inject() + protected readonly db!: DatabaseService /** * Apply the migration. */ async up(): Promise { + const schema = this.db.get().schema() } @@ -30,6 +33,7 @@ export default class ${name} extends Migration { * Undo the migration. */ async down(): Promise { + const schema = this.db.get().schema() } } diff --git a/src/orm/template/model.ts b/src/orm/template/model.ts index 27a0c99..4a672a6 100644 --- a/src/orm/template/model.ts +++ b/src/orm/template/model.ts @@ -9,7 +9,7 @@ const templateModel: Template = { baseAppPath: ['models'], description: 'Create a new class that represents a record in a database', render: (name: string) => { - return `import {Injectable, Model} from "@extollo/lib" + return `import {Injectable, Model} from '@extollo/lib' /** * ${name} Model @@ -18,8 +18,8 @@ const templateModel: Template = { */ @Injectable() export class ${name} extends Model<${name}> { - protected static table = '${name.toLowerCase()}'; - protected static key = '${name.toLowerCase()}_id'; + protected static table = '${name.toLowerCase()}' + protected static key = '${name.toLowerCase()}_id' } ` },