@bejibun/core 0.1.39 → 0.1.41
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +51 -0
- package/bases/BaseController.d.ts +1 -2
- package/bases/BaseModel.js +3 -3
- package/builders/RouterBuilder.d.ts +4 -0
- package/builders/RouterBuilder.js +30 -7
- package/commands/Kernel.d.ts +1 -0
- package/commands/Kernel.js +28 -13
- package/commands/{DbSeedCommand.d.ts → db/DbSeedCommand.d.ts} +2 -2
- package/commands/{DbSeedCommand.js → db/DbSeedCommand.js} +2 -2
- package/commands/maintenance/MaintenanceDownCommand.d.ts +27 -0
- package/commands/maintenance/MaintenanceDownCommand.js +40 -0
- package/commands/{MigrateFreshCommand.d.ts → migrate/MigrateFreshCommand.d.ts} +2 -2
- package/commands/{MigrateFreshCommand.js → migrate/MigrateFreshCommand.js} +5 -4
- package/commands/{MigrateLatestCommand.d.ts → migrate/MigrateLatestCommand.d.ts} +2 -2
- package/commands/{MigrateLatestCommand.js → migrate/MigrateLatestCommand.js} +2 -2
- package/commands/{MigrateRollbackCommand.d.ts → migrate/MigrateRollbackCommand.d.ts} +2 -2
- package/commands/{MigrateRollbackCommand.js → migrate/MigrateRollbackCommand.js} +5 -4
- package/commands/{MigrateStatusCommand.d.ts → migrate/MigrateStatusCommand.d.ts} +2 -2
- package/commands/{MigrateStatusCommand.js → migrate/MigrateStatusCommand.js} +5 -4
- package/config/database.js +2 -2
- package/exceptions/ModelNotFoundException.js +2 -0
- package/exceptions/RouterInvalidException.js +2 -0
- package/exceptions/ValidatorException.js +2 -0
- package/facades/Router.d.ts +1 -0
- package/facades/Router.js +5 -14
- package/package.json +6 -5
- package/types/router.d.ts +1 -1
- package/bun.lock +0 -266
- package/src/ace.ts +0 -22
- package/src/bases/BaseController.ts +0 -139
- package/src/bases/BaseModel.ts +0 -108
- package/src/bases/BaseValidator.ts +0 -8
- package/src/bases/index.ts +0 -3
- package/src/bootstrap.ts +0 -5
- package/src/builders/ResponseBuilder.ts +0 -54
- package/src/builders/RouterBuilder.ts +0 -173
- package/src/commands/DbSeedCommand.ts +0 -57
- package/src/commands/Kernel.ts +0 -49
- package/src/commands/MigrateFreshCommand.ts +0 -76
- package/src/commands/MigrateLatestCommand.ts +0 -56
- package/src/commands/MigrateRollbackCommand.ts +0 -72
- package/src/commands/MigrateStatusCommand.ts +0 -64
- package/src/config/database.ts +0 -41
- package/src/exceptions/ModelNotFoundException.ts +0 -15
- package/src/exceptions/RouterInvalidException.ts +0 -15
- package/src/exceptions/ValidatorException.ts +0 -15
- package/src/exceptions/index.ts +0 -3
- package/src/facades/Response.ts +0 -15
- package/src/facades/Router.ts +0 -89
- package/src/facades/SoftDeletes.ts +0 -66
- package/src/facades/index.ts +0 -3
- package/src/index.ts +0 -5
- package/src/types/index.d.ts +0 -4
- package/src/types/middleware.d.ts +0 -7
- package/src/types/router.d.ts +0 -5
- package/src/types/validator.d.ts +0 -3
- package/src/types/vine.d.ts +0 -13
- package/src/utils/vine.ts +0 -2
- package/src/utils/vines/exists.ts +0 -41
- package/src/utils/vines/unique.ts +0 -41
package/src/exceptions/index.ts
DELETED
package/src/facades/Response.ts
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import ResponseBuilder from "@/builders/ResponseBuilder";
|
|
2
|
-
|
|
3
|
-
export default class Response {
|
|
4
|
-
public static setData(data?: any): ResponseBuilder {
|
|
5
|
-
return new ResponseBuilder().setData(data);
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
public static setMessage(message: string): ResponseBuilder {
|
|
9
|
-
return new ResponseBuilder().setMessage(message);
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
public static setStatus(status: number): ResponseBuilder {
|
|
13
|
-
return new ResponseBuilder().setStatus(status);
|
|
14
|
-
}
|
|
15
|
-
}
|
package/src/facades/Router.ts
DELETED
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
import type {IMiddleware} from "@/types/middleware";
|
|
2
|
-
import type {HandlerType, RouterGroup} from "@/types/router";
|
|
3
|
-
import {isEmpty} from "@bejibun/utils";
|
|
4
|
-
import HttpMethodEnum from "@bejibun/utils/enums/HttpMethodEnum";
|
|
5
|
-
import Enum from "@bejibun/utils/facades/Enum";
|
|
6
|
-
import RouterBuilder, {ResourceOptions} from "@/builders/RouterBuilder";
|
|
7
|
-
|
|
8
|
-
export default class Router {
|
|
9
|
-
public static prefix(basePath: string): RouterBuilder {
|
|
10
|
-
return new RouterBuilder().prefix(basePath);
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
public static middleware(...middlewares: Array<IMiddleware>): RouterBuilder {
|
|
14
|
-
return new RouterBuilder().middleware(...middlewares);
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
public static resources(
|
|
18
|
-
controller: Record<string, HandlerType>,
|
|
19
|
-
options?: ResourceOptions
|
|
20
|
-
): RouterGroup {
|
|
21
|
-
return new RouterBuilder().resources(controller, options);
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
public static group(routes: RouterGroup, prefix?: string, middlewares?: Array<IMiddleware>) {
|
|
25
|
-
const builder = new RouterBuilder();
|
|
26
|
-
|
|
27
|
-
if (prefix) builder.prefix(prefix);
|
|
28
|
-
if (middlewares?.length) builder.middleware(...middlewares);
|
|
29
|
-
|
|
30
|
-
return builder.group(routes);
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
public static connect(path: string, handler: string | HandlerType): RouterGroup {
|
|
34
|
-
return new RouterBuilder().buildSingle(HttpMethodEnum.Connect, path, handler);
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
public static delete(path: string, handler: string | HandlerType): RouterGroup {
|
|
38
|
-
return new RouterBuilder().buildSingle(HttpMethodEnum.Delete, path, handler);
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
public static get(path: string, handler: string | HandlerType): RouterGroup {
|
|
42
|
-
return new RouterBuilder().buildSingle(HttpMethodEnum.Get, path, handler);
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
public static head(path: string, handler: string | HandlerType): RouterGroup {
|
|
46
|
-
return new RouterBuilder().buildSingle(HttpMethodEnum.Head, path, handler);
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
public static options(path: string, handler: string | HandlerType): RouterGroup {
|
|
50
|
-
return new RouterBuilder().buildSingle(HttpMethodEnum.Options, path, handler);
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
public static patch(path: string, handler: string | HandlerType): RouterGroup {
|
|
54
|
-
return new RouterBuilder().buildSingle(HttpMethodEnum.Patch, path, handler);
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
public static post(path: string, handler: string | HandlerType): RouterGroup {
|
|
58
|
-
return new RouterBuilder().buildSingle(HttpMethodEnum.Post, path, handler);
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
public static put(path: string, handler: string | HandlerType): RouterGroup {
|
|
62
|
-
return new RouterBuilder().buildSingle(HttpMethodEnum.Put, path, handler);
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
public static trace(path: string, handler: string | HandlerType): RouterGroup {
|
|
66
|
-
return new RouterBuilder().buildSingle(HttpMethodEnum.Trace, path, handler);
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
public static match(methods: Array<HttpMethodEnum>, path: string, handler: string | HandlerType): RouterGroup {
|
|
70
|
-
const builder = new RouterBuilder();
|
|
71
|
-
const routeMap: RouterGroup = {};
|
|
72
|
-
|
|
73
|
-
for (const method of methods) {
|
|
74
|
-
const single = builder.buildSingle(method, path, handler);
|
|
75
|
-
const fullPath = Object.keys(single)[0];
|
|
76
|
-
const handlers = single[fullPath];
|
|
77
|
-
|
|
78
|
-
if (isEmpty(routeMap[fullPath])) routeMap[fullPath] = {};
|
|
79
|
-
|
|
80
|
-
Object.assign(routeMap[fullPath], handlers);
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
return routeMap;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
public static any(path: string, handler: string | HandlerType): RouterGroup {
|
|
87
|
-
return this.match(Enum.setEnums(HttpMethodEnum).toArray(), path, handler);
|
|
88
|
-
}
|
|
89
|
-
}
|
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
import {DateTime} from "luxon";
|
|
2
|
-
import {QueryBuilder, ModelClass, QueryContext, Model} from "objection";
|
|
3
|
-
|
|
4
|
-
interface SoftDeleteQueryContext extends QueryContext {
|
|
5
|
-
withTrashed?: boolean;
|
|
6
|
-
onlyTrashed?: boolean;
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export default class SoftDeletes<M extends Model, R = M[]> extends QueryBuilder<M, R> {
|
|
10
|
-
private hasFilterApplied = false;
|
|
11
|
-
|
|
12
|
-
constructor(modelClass: ModelClass<M>) {
|
|
13
|
-
// @ts-ignore
|
|
14
|
-
super(modelClass);
|
|
15
|
-
|
|
16
|
-
this.onBuild((builder: QueryBuilder<M, R>) => {
|
|
17
|
-
const context = this.context() as SoftDeleteQueryContext;
|
|
18
|
-
|
|
19
|
-
if (!this.hasFilterApplied) {
|
|
20
|
-
const tableName = this.modelClass().tableName;
|
|
21
|
-
|
|
22
|
-
if (context.onlyTrashed) {
|
|
23
|
-
builder.whereNotNull(`${tableName}.${(this.modelClass() as any).deletedColumn}`);
|
|
24
|
-
} else if (!context.withTrashed) {
|
|
25
|
-
builder.whereNull(`${tableName}.${(this.modelClass() as any).deletedColumn}`);
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
this.hasFilterApplied = true;
|
|
29
|
-
}
|
|
30
|
-
});
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
withTrashed(): this {
|
|
34
|
-
return (this as any).context({
|
|
35
|
-
...(this as any).context(),
|
|
36
|
-
withTrashed: true
|
|
37
|
-
});
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
onlyTrashed(): this {
|
|
41
|
-
return (this as any).context({
|
|
42
|
-
...(this as any).context(),
|
|
43
|
-
onlyTrashed: true
|
|
44
|
-
});
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
delete(): QueryBuilder<M, number> {
|
|
48
|
-
return this.update({
|
|
49
|
-
[(this.modelClass() as any).deletedColumn]: DateTime.now()
|
|
50
|
-
} as any);
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
del(): QueryBuilder<M, number> {
|
|
54
|
-
return this.delete();
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
forceDelete(): QueryBuilder<M, number> {
|
|
58
|
-
return super.delete();
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
restore(): QueryBuilder<M, number> {
|
|
62
|
-
return this.onlyTrashed().update({
|
|
63
|
-
[(this.modelClass() as any).deletedColumn]: null
|
|
64
|
-
} as any);
|
|
65
|
-
}
|
|
66
|
-
}
|
package/src/facades/index.ts
DELETED
package/src/index.ts
DELETED
package/src/types/index.d.ts
DELETED
package/src/types/router.d.ts
DELETED
package/src/types/validator.d.ts
DELETED
package/src/types/vine.d.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
declare module "@vinejs/vine" {
|
|
2
|
-
interface VineNumber {
|
|
3
|
-
exists(tableOrOptions: string | { table: string; column?: string }, column?: string): this;
|
|
4
|
-
unique(tableOrOptions: string | { table: string; column?: string }, column?: string): this;
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
interface VineString {
|
|
8
|
-
exists(tableOrOptions: string | { table: string; column?: string }, column?: string): this;
|
|
9
|
-
unique(tableOrOptions: string | { table: string; column?: string }, column?: string): this;
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export {};
|
package/src/utils/vine.ts
DELETED
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import {defineValue, isEmpty} from "@bejibun/utils";
|
|
2
|
-
import vine, {VineNumber, VineString} from "@vinejs/vine";
|
|
3
|
-
import {QueryBuilderType} from "objection";
|
|
4
|
-
import BaseModel from "@/bases/BaseModel";
|
|
5
|
-
|
|
6
|
-
type Options = {
|
|
7
|
-
table: typeof BaseModel;
|
|
8
|
-
column?: string;
|
|
9
|
-
withTrashed?: boolean;
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
const exists = async (value: unknown, options: Options, field: any): Promise<void> => {
|
|
13
|
-
if (!field.isValid) return;
|
|
14
|
-
|
|
15
|
-
const column = defineValue(options.column, field.name);
|
|
16
|
-
|
|
17
|
-
let query: any = options.table;
|
|
18
|
-
if (options.withTrashed) query = query.withTrashed();
|
|
19
|
-
else query = query.query();
|
|
20
|
-
|
|
21
|
-
const row = await (query as QueryBuilderType<any>).where(column, value).first();
|
|
22
|
-
|
|
23
|
-
if (isEmpty(row)) field.report("The {{ field }} field doesn't exists", "exists", field);
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
const existsRule = vine.createRule(exists, {isAsync: true});
|
|
27
|
-
|
|
28
|
-
const registerExistsMacro = (Type: any): void => {
|
|
29
|
-
Type.macro("exists", function (this: typeof Type, tableOrOptions: typeof BaseModel | Options, column?: string, withTrashed?: boolean) {
|
|
30
|
-
const isModel = typeof tableOrOptions === "function" && Object.prototype.isPrototypeOf.call(BaseModel, tableOrOptions);
|
|
31
|
-
|
|
32
|
-
const options: Options = isModel
|
|
33
|
-
? {table: tableOrOptions as typeof BaseModel, column, withTrashed}
|
|
34
|
-
: tableOrOptions as Options;
|
|
35
|
-
|
|
36
|
-
return this.use(existsRule(options));
|
|
37
|
-
});
|
|
38
|
-
};
|
|
39
|
-
|
|
40
|
-
registerExistsMacro(VineString);
|
|
41
|
-
registerExistsMacro(VineNumber);
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import {defineValue, isNotEmpty} from "@bejibun/utils";
|
|
2
|
-
import vine, {VineNumber, VineString} from "@vinejs/vine";
|
|
3
|
-
import {QueryBuilderType} from "objection";
|
|
4
|
-
import BaseModel from "@/bases/BaseModel";
|
|
5
|
-
|
|
6
|
-
type Options = {
|
|
7
|
-
table: typeof BaseModel;
|
|
8
|
-
column?: string;
|
|
9
|
-
withTrashed?: boolean;
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
const unique = async (value: unknown, options: Options, field: any): Promise<void> => {
|
|
13
|
-
if (!field.isValid) return;
|
|
14
|
-
|
|
15
|
-
const column = defineValue(options.column, field.name);
|
|
16
|
-
|
|
17
|
-
let query: any = options.table;
|
|
18
|
-
if (options.withTrashed) query = query.withTrashed();
|
|
19
|
-
else query = query.query();
|
|
20
|
-
|
|
21
|
-
const row = await (query as QueryBuilderType<any>).where(column, value).first();
|
|
22
|
-
|
|
23
|
-
if (isNotEmpty(row)) field.report("The {{ field }} field is already exists", "unique", field);
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
const uniqueRule = vine.createRule(unique, {isAsync: true});
|
|
27
|
-
|
|
28
|
-
const registerUniqueMacro = (Type: any): void => {
|
|
29
|
-
Type.macro("unique", function (this: typeof Type, tableOrOptions: typeof BaseModel | Options, column?: string, withTrashed?: boolean) {
|
|
30
|
-
const isModel = typeof tableOrOptions === "function" && Object.prototype.isPrototypeOf.call(BaseModel, tableOrOptions);
|
|
31
|
-
|
|
32
|
-
const options: Options = isModel
|
|
33
|
-
? {table: tableOrOptions as typeof BaseModel, column, withTrashed}
|
|
34
|
-
: tableOrOptions as Options;
|
|
35
|
-
|
|
36
|
-
return this.use(uniqueRule(options));
|
|
37
|
-
});
|
|
38
|
-
};
|
|
39
|
-
|
|
40
|
-
registerUniqueMacro(VineString);
|
|
41
|
-
registerUniqueMacro(VineNumber);
|