Commit d92de23d authored by nanahira's avatar nanahira

bump things

parent 50afa2a0
import 'reflect-metadata'; import 'reflect-metadata';
export * from './src/register'; export * from './src/register';
export * from './src/decorators'; export * from './src/decorators';
export * from './src/cosmotype-exports';
export * from './src/base-plugin'; export * from './src/base-plugin';
export * from './src/def/interfaces'; export * from './src/def/interfaces';
export * from 'schemastery-gen'; export * from 'schemastery-gen';
export * from 'koishi-entities';
This diff is collapsed.
...@@ -50,11 +50,11 @@ ...@@ -50,11 +50,11 @@
"dependencies": { "dependencies": {
"@types/koa": "^2.13.4", "@types/koa": "^2.13.4",
"@types/koa__router": "^8.0.11", "@types/koa__router": "^8.0.11",
"koishi-decorators": "^1.3.5", "cosmotype-decorators": "^2.0.1",
"koishi-entities": "^1.0.5", "koishi-decorators": "^2.0.0",
"lodash": "^4.17.21", "lodash": "^4.17.21",
"reflect-metadata": "^0.1.13", "reflect-metadata": "^0.1.13",
"schemastery-gen": "^3.1.2", "schemastery-gen": "^3.1.4",
"typed-reflector": "^1.0.10" "typed-reflector": "^1.0.10"
}, },
"jest": { "jest": {
...@@ -75,7 +75,7 @@ ...@@ -75,7 +75,7 @@
"testEnvironment": "node" "testEnvironment": "node"
}, },
"peerDependencies": { "peerDependencies": {
"koishi": "^4.5.1", "koishi": "^4.6.0",
"schemastery": "^3.1.0" "schemastery": "^3.1.0"
} }
} }
import { ModelDecorators } from 'cosmotype-decorators';
import { Tables } from 'koishi';
const decorators = new ModelDecorators<Tables>();
export const DefineModel = decorators.DefineModel;
export const ModelField = decorators.ModelField;
export const Primary = decorators.Primary;
export const PrimaryGenerated = decorators.PrimaryGenerated;
export const Foreign = decorators.Foreign;
export const Unique = decorators.Unique;
export const ChildModel = decorators.ChildModel;
...@@ -14,7 +14,7 @@ import { ...@@ -14,7 +14,7 @@ import {
SystemInjectFun, SystemInjectFun,
} from './def'; } from './def';
import { TopLevelAction } from 'koishi-decorators'; import { TopLevelAction } from 'koishi-decorators';
import { mixinModel, ModelClassType, registerModel } from 'koishi-entities'; import { ModelClassType, ModelRegistrar } from 'cosmotype-decorators';
// Export all koishi-decorator decorators // Export all koishi-decorator decorators
...@@ -128,7 +128,10 @@ export const If = <T>(func: Condition<boolean, T>): MethodDecorator => ...@@ -128,7 +128,10 @@ export const If = <T>(func: Condition<boolean, T>): MethodDecorator =>
Metadata.append('KoishiIf', func); Metadata.append('KoishiIf', func);
export const UseModel = (...models: ModelClassType[]): ClassDecorator => export const UseModel = (...models: ModelClassType[]): ClassDecorator =>
TopLevelAction((ctx) => models.forEach((m) => registerModel(ctx, m))); TopLevelAction((ctx) => {
const registrar = new ModelRegistrar(ctx.model);
models.forEach((m) => registrar.registerModel(m));
});
export const MixinModel = <K extends Keys<Tables>>( export const MixinModel = <K extends Keys<Tables>>(
tableName: K, tableName: K,
...@@ -136,4 +139,7 @@ export const MixinModel = <K extends Keys<Tables>>( ...@@ -136,4 +139,7 @@ export const MixinModel = <K extends Keys<Tables>>(
[F in Keys<Tables[K]>]?: ModelClassType<Flatten<Tables[K][F]>>; [F in Keys<Tables[K]>]?: ModelClassType<Flatten<Tables[K][F]>>;
}, },
): ClassDecorator => ): ClassDecorator =>
TopLevelAction((ctx) => mixinModel(ctx, tableName, classDict)); TopLevelAction((ctx) => {
const registrar = new ModelRegistrar(ctx.model);
registrar.mixinModel(tableName, classDict);
});
import { MixinModel, UseModel } from '../src/decorators';
import { App } from 'koishi';
import { BasePlugin } from '../src/base-plugin';
import { DefinePlugin } from '../src/register';
import { import {
ChildModel, ChildModel,
DefineModel, DefineModel,
...@@ -5,11 +9,7 @@ import { ...@@ -5,11 +9,7 @@ import {
ModelField, ModelField,
PrimaryGenerated, PrimaryGenerated,
Unique, Unique,
} from 'koishi-entities'; } from '../src/cosmotype-exports';
import { MixinModel, UseModel } from '../src/decorators';
import { App } from 'koishi';
import { BasePlugin } from '../src/base-plugin';
import { DefinePlugin } from '../src/register';
declare module 'koishi' { declare module 'koishi' {
interface Tables { interface Tables {
...@@ -85,7 +85,7 @@ describe('Test of model', () => { ...@@ -85,7 +85,7 @@ describe('Test of model', () => {
it('should register model', async () => { it('should register model', async () => {
const app = new App(); const app = new App();
app.plugin(MyPlugin); app.plugin(MyPlugin);
expect(app.model.config.dress.fields.name.type).toBe('string'); expect(app.model.tables.dress.fields.name.type).toBe('string');
expect(app.model.config.user.fields['shirt.size'].type).toBe('string'); expect(app.model.tables.user.fields['shirt.size'].type).toBe('string');
}); });
}); });
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment