@h3ravel/arquebus 0.5.0 → 0.6.0
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/README.md +20 -1
- package/bin/index.cjs +196 -144
- package/bin/index.js +177 -94
- package/bin/seeders-8GJzfIIN.js +3 -0
- package/bin/seeders-ByeSoCAQ.cjs +131 -0
- package/bin/seeders-CltigymO.js +79 -0
- package/bin/seeders-_xJ6VGVS.cjs +3 -0
- package/dist/browser/index.cjs +9 -9
- package/dist/browser/index.d.cts +7 -7
- package/dist/browser/index.d.ts +7 -7
- package/dist/browser/index.js +9 -9
- package/dist/index.cjs +252 -121
- package/dist/index.d.cts +40 -8
- package/dist/index.d.ts +40 -8
- package/dist/index.js +245 -119
- package/dist/inspector/index.cjs +105 -33
- package/dist/inspector/index.js +102 -33
- package/dist/migrations/index.cjs +144 -126
- package/dist/migrations/index.d.cts +10 -10
- package/dist/migrations/index.d.ts +10 -10
- package/dist/migrations/index.js +148 -130
- package/dist/migrations/stubs/migration-js.stub +1 -1
- package/dist/migrations/stubs/migration-ts.stub +1 -1
- package/dist/migrations/stubs/migration.create-js.stub +5 -5
- package/dist/migrations/stubs/migration.create-ts.stub +5 -5
- package/dist/migrations/stubs/migration.update-js.stub +2 -2
- package/dist/migrations/stubs/migration.update-ts.stub +3 -3
- package/dist/seeders/index.cjs +141 -0
- package/dist/seeders/index.d.cts +4766 -0
- package/dist/seeders/index.d.ts +4766 -0
- package/dist/seeders/index.js +118 -0
- package/dist/seeders/index.ts +3 -0
- package/dist/seeders/runner.ts +102 -0
- package/dist/seeders/seeder-creator.ts +42 -0
- package/dist/seeders/seeder.ts +10 -0
- package/dist/stubs/seeder-js.stub +13 -0
- package/dist/stubs/seeder-ts.stub +9 -0
- package/package.json +14 -3
- package/types/builder.ts +153 -80
- package/types/container.ts +79 -66
- package/types/generics.ts +75 -37
- package/types/modeling.ts +213 -158
- package/types/query-builder.ts +221 -191
- package/types/query-methods.ts +145 -109
- package/types/utils.ts +64 -56
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import path from "path";
|
|
2
|
+
import { access, mkdir, readFile, writeFile } from "node:fs/promises";
|
|
3
|
+
import { dirname } from "node:path";
|
|
4
|
+
import { fileURLToPath } from "node:url";
|
|
5
|
+
|
|
6
|
+
//#region src/seeders/runner.ts
|
|
7
|
+
async function glob(folderPath) {
|
|
8
|
+
const { default: escalade } = await import("escalade");
|
|
9
|
+
const entries = [];
|
|
10
|
+
await escalade(folderPath, async (dir, names) => {
|
|
11
|
+
await Promise.all(names.map(async (name) => {
|
|
12
|
+
const p = path.join(dir, name);
|
|
13
|
+
try {
|
|
14
|
+
await access(p);
|
|
15
|
+
if (p.endsWith(".js") || p.endsWith(".ts")) entries.push(p);
|
|
16
|
+
} catch {}
|
|
17
|
+
}));
|
|
18
|
+
return "";
|
|
19
|
+
});
|
|
20
|
+
return entries;
|
|
21
|
+
}
|
|
22
|
+
var SeederRunner = class {
|
|
23
|
+
resolver;
|
|
24
|
+
connection;
|
|
25
|
+
paths = [];
|
|
26
|
+
constructor(resolver) {
|
|
27
|
+
this.resolver = resolver;
|
|
28
|
+
}
|
|
29
|
+
path(p) {
|
|
30
|
+
this.paths = Array.from(new Set([...this.paths, p]));
|
|
31
|
+
}
|
|
32
|
+
getPaths() {
|
|
33
|
+
return this.paths;
|
|
34
|
+
}
|
|
35
|
+
resolveConnection(connection) {
|
|
36
|
+
var _getInstance, _ref, _instance$connections;
|
|
37
|
+
const name = connection || this.connection || "default";
|
|
38
|
+
const instance = ((_getInstance = (_ref = this.resolver).getInstance) === null || _getInstance === void 0 ? void 0 : _getInstance.call(_ref)) ?? null;
|
|
39
|
+
if (!!!(instance === null || instance === void 0 || (_instance$connections = instance.connections) === null || _instance$connections === void 0 ? void 0 : _instance$connections[name])) this.resolver.autoLoad().catch(() => {
|
|
40
|
+
/** noop */
|
|
41
|
+
});
|
|
42
|
+
return this.resolver.fire(name);
|
|
43
|
+
}
|
|
44
|
+
setConnection(connection) {
|
|
45
|
+
this.connection = connection;
|
|
46
|
+
return this;
|
|
47
|
+
}
|
|
48
|
+
async getSeederFiles(paths) {
|
|
49
|
+
const files = [];
|
|
50
|
+
for (const p of paths) {
|
|
51
|
+
if (p.endsWith(".js") || p.endsWith(".ts")) {
|
|
52
|
+
files.push(p);
|
|
53
|
+
continue;
|
|
54
|
+
}
|
|
55
|
+
files.push(...await glob(p));
|
|
56
|
+
}
|
|
57
|
+
return files;
|
|
58
|
+
}
|
|
59
|
+
async resolvePath(filePath) {
|
|
60
|
+
try {
|
|
61
|
+
const mod = await import(filePath);
|
|
62
|
+
return new (mod.default ?? mod.Seeder)();
|
|
63
|
+
} catch {
|
|
64
|
+
return null;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
async run(paths, connection) {
|
|
68
|
+
const files = await this.getSeederFiles(paths);
|
|
69
|
+
const conn = this.resolveConnection(connection);
|
|
70
|
+
for (const file of files) {
|
|
71
|
+
const seeder = await this.resolvePath(file);
|
|
72
|
+
if (seeder && typeof seeder.run === "function") await seeder.run(conn);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
var runner_default = SeederRunner;
|
|
77
|
+
|
|
78
|
+
//#endregion
|
|
79
|
+
export { runner_default };
|
package/dist/browser/index.cjs
CHANGED
|
@@ -94,7 +94,7 @@ var casts_attributes_default = CastsAttributes;
|
|
|
94
94
|
var mixin_exports = /* @__PURE__ */ __export({ compose: () => compose$1 });
|
|
95
95
|
/**
|
|
96
96
|
* Compose function that merges multiple classes and mixins
|
|
97
|
-
*
|
|
97
|
+
*
|
|
98
98
|
* @example
|
|
99
99
|
* const SomePlugin = <TBase extends new (...args: any[]) => TGeneric> (Base: TBase) => {
|
|
100
100
|
* return class extends Base {
|
|
@@ -131,10 +131,10 @@ var mixin_exports = /* @__PURE__ */ __export({ compose: () => compose$1 });
|
|
|
131
131
|
* console.log(user.pluginMethod('w')) // "plugin"
|
|
132
132
|
* console.log(user.pluginMethod()) // "plugin"
|
|
133
133
|
* console.log(user.relationPosts()) // "hasMany Posts"
|
|
134
|
-
*
|
|
135
|
-
* @param Base
|
|
136
|
-
* @param mixins
|
|
137
|
-
* @returns
|
|
134
|
+
*
|
|
135
|
+
* @param Base
|
|
136
|
+
* @param mixins
|
|
137
|
+
* @returns
|
|
138
138
|
*/
|
|
139
139
|
function compose$1(Base, ...mixins) {
|
|
140
140
|
/**
|
|
@@ -195,10 +195,10 @@ const getAttrName = (attrMethod) => {
|
|
|
195
195
|
};
|
|
196
196
|
/**
|
|
197
197
|
* Tap into a model a collection instance
|
|
198
|
-
*
|
|
199
|
-
* @param instance
|
|
200
|
-
* @param callback
|
|
201
|
-
* @returns
|
|
198
|
+
*
|
|
199
|
+
* @param instance
|
|
200
|
+
* @param callback
|
|
201
|
+
* @returns
|
|
202
202
|
*/
|
|
203
203
|
const tap = (instance, callback) => {
|
|
204
204
|
const result = callback(instance);
|
package/dist/browser/index.d.cts
CHANGED
|
@@ -291,7 +291,7 @@ declare class Builder<M extends Model$1 = Model$1, R = IModel | ICollection<M>>
|
|
|
291
291
|
enforceOrderBy(this: any): void;
|
|
292
292
|
clone(this: any): any;
|
|
293
293
|
forPage(this: any, page: number, perPage?: number): any;
|
|
294
|
-
insert(...args: Parameters<typeof
|
|
294
|
+
insert(...args: Parameters<typeof this.query.insert>): Promise<any>;
|
|
295
295
|
update<T extends TGeneric>(values: T): Promise<any>;
|
|
296
296
|
increment(column: string, amount?: number, extra?: {}): Promise<any>;
|
|
297
297
|
decrement(column: string, amount?: number, extra?: {}): Promise<any>;
|
|
@@ -630,7 +630,7 @@ declare class QueryBuilder<M extends Model$1 = Model$1, R = M[] | M> extends Inf
|
|
|
630
630
|
chunk(count: number, callback: TFunction): Promise<boolean>;
|
|
631
631
|
paginate<F extends IPaginatorParams>(this: any, page: number | undefined, perPage: number | undefined, _pageName: string, _page: number): Promise<IPaginator<M, F>>;
|
|
632
632
|
forPage(this: any, page?: number, perPage?: number): any;
|
|
633
|
-
toSQL(...args: Parameters<typeof
|
|
633
|
+
toSQL(...args: Parameters<typeof this.connector.toSQL>): Knex.Sql;
|
|
634
634
|
count(column: string): Promise<number>;
|
|
635
635
|
min(column: string): Promise<number>;
|
|
636
636
|
max(column: string): Promise<number>;
|
|
@@ -638,9 +638,9 @@ declare class QueryBuilder<M extends Model$1 = Model$1, R = M[] | M> extends Inf
|
|
|
638
638
|
avg(column: string): Promise<number>;
|
|
639
639
|
clone(): IQueryBuilder<M, R>;
|
|
640
640
|
delete(): Promise<number | boolean>;
|
|
641
|
-
insert(...args: Parameters<typeof
|
|
642
|
-
update(...args: Parameters<typeof
|
|
643
|
-
destroy(...args: Parameters<typeof
|
|
641
|
+
insert(...args: Parameters<typeof this.connector.insert>): Promise<unknown>;
|
|
642
|
+
update(...args: Parameters<typeof this.connector.update>): Promise<number>;
|
|
643
|
+
destroy(...args: Parameters<typeof this.connector.destroy>): Promise<number>;
|
|
644
644
|
get _statements(): IStatement[] & any[];
|
|
645
645
|
get _single(): any;
|
|
646
646
|
get from(): Knex.Table<any, any> & Knex.Table<any, any[]>;
|
|
@@ -666,7 +666,7 @@ declare class Relation {
|
|
|
666
666
|
getEager(): any;
|
|
667
667
|
get(columns?: string | string[]): Promise<any>;
|
|
668
668
|
first(columns?: string[]): Promise<any>;
|
|
669
|
-
paginate(...args:
|
|
669
|
+
paginate(...args: unknown[]): Promise<any>;
|
|
670
670
|
count(...args: any[]): Promise<any>;
|
|
671
671
|
toSql(): string;
|
|
672
672
|
addConstraints(): void;
|
|
@@ -4866,7 +4866,7 @@ type ReturnTypeOfMethod<T, K extends keyof T> = T[K] extends ((...args: any[]) =
|
|
|
4866
4866
|
type SnakeToCamelCase<S extends string> = S extends `${infer T}_${infer U}` ? `${T}${Capitalize<SnakeToCamelCase<U>>}` : S;
|
|
4867
4867
|
type CamelToSnakeCase<S extends string> = S extends `${infer T}${infer U}` ? U extends Uncapitalize<U> ? `${Uncapitalize<T>}${CamelToSnakeCase<U>}` : `${Uncapitalize<T>}_${CamelToSnakeCase<U>}` : S;
|
|
4868
4868
|
type FunctionPropertyNames<T> = { [K in keyof T]: T[K] extends ((...args: any[]) => any) ? K : never }[keyof T];
|
|
4869
|
-
type RelationNames<T> = FunctionPropertyNames<T> extends infer R ? R extends `relation${infer P}` ? P extends
|
|
4869
|
+
type RelationNames<T> = FunctionPropertyNames<T> extends infer R ? R extends `relation${infer P}` ? P extends 'sToData' | 'loaded' ? never : CamelToSnakeCase<P> : never : never;
|
|
4870
4870
|
type MixinConstructor<T = TGeneric> = new (...args: any[]) => T;
|
|
4871
4871
|
//#endregion
|
|
4872
4872
|
//#region src/browser/paginator.d.ts
|
package/dist/browser/index.d.ts
CHANGED
|
@@ -291,7 +291,7 @@ declare class Builder<M extends Model$1 = Model$1, R = IModel | ICollection<M>>
|
|
|
291
291
|
enforceOrderBy(this: any): void;
|
|
292
292
|
clone(this: any): any;
|
|
293
293
|
forPage(this: any, page: number, perPage?: number): any;
|
|
294
|
-
insert(...args: Parameters<typeof
|
|
294
|
+
insert(...args: Parameters<typeof this.query.insert>): Promise<any>;
|
|
295
295
|
update<T extends TGeneric>(values: T): Promise<any>;
|
|
296
296
|
increment(column: string, amount?: number, extra?: {}): Promise<any>;
|
|
297
297
|
decrement(column: string, amount?: number, extra?: {}): Promise<any>;
|
|
@@ -630,7 +630,7 @@ declare class QueryBuilder<M extends Model$1 = Model$1, R = M[] | M> extends Inf
|
|
|
630
630
|
chunk(count: number, callback: TFunction): Promise<boolean>;
|
|
631
631
|
paginate<F extends IPaginatorParams>(this: any, page: number | undefined, perPage: number | undefined, _pageName: string, _page: number): Promise<IPaginator<M, F>>;
|
|
632
632
|
forPage(this: any, page?: number, perPage?: number): any;
|
|
633
|
-
toSQL(...args: Parameters<typeof
|
|
633
|
+
toSQL(...args: Parameters<typeof this.connector.toSQL>): Knex.Sql;
|
|
634
634
|
count(column: string): Promise<number>;
|
|
635
635
|
min(column: string): Promise<number>;
|
|
636
636
|
max(column: string): Promise<number>;
|
|
@@ -638,9 +638,9 @@ declare class QueryBuilder<M extends Model$1 = Model$1, R = M[] | M> extends Inf
|
|
|
638
638
|
avg(column: string): Promise<number>;
|
|
639
639
|
clone(): IQueryBuilder<M, R>;
|
|
640
640
|
delete(): Promise<number | boolean>;
|
|
641
|
-
insert(...args: Parameters<typeof
|
|
642
|
-
update(...args: Parameters<typeof
|
|
643
|
-
destroy(...args: Parameters<typeof
|
|
641
|
+
insert(...args: Parameters<typeof this.connector.insert>): Promise<unknown>;
|
|
642
|
+
update(...args: Parameters<typeof this.connector.update>): Promise<number>;
|
|
643
|
+
destroy(...args: Parameters<typeof this.connector.destroy>): Promise<number>;
|
|
644
644
|
get _statements(): IStatement[] & any[];
|
|
645
645
|
get _single(): any;
|
|
646
646
|
get from(): Knex.Table<any, any> & Knex.Table<any, any[]>;
|
|
@@ -666,7 +666,7 @@ declare class Relation {
|
|
|
666
666
|
getEager(): any;
|
|
667
667
|
get(columns?: string | string[]): Promise<any>;
|
|
668
668
|
first(columns?: string[]): Promise<any>;
|
|
669
|
-
paginate(...args:
|
|
669
|
+
paginate(...args: unknown[]): Promise<any>;
|
|
670
670
|
count(...args: any[]): Promise<any>;
|
|
671
671
|
toSql(): string;
|
|
672
672
|
addConstraints(): void;
|
|
@@ -4866,7 +4866,7 @@ type ReturnTypeOfMethod<T, K extends keyof T> = T[K] extends ((...args: any[]) =
|
|
|
4866
4866
|
type SnakeToCamelCase<S extends string> = S extends `${infer T}_${infer U}` ? `${T}${Capitalize<SnakeToCamelCase<U>>}` : S;
|
|
4867
4867
|
type CamelToSnakeCase<S extends string> = S extends `${infer T}${infer U}` ? U extends Uncapitalize<U> ? `${Uncapitalize<T>}${CamelToSnakeCase<U>}` : `${Uncapitalize<T>}_${CamelToSnakeCase<U>}` : S;
|
|
4868
4868
|
type FunctionPropertyNames<T> = { [K in keyof T]: T[K] extends ((...args: any[]) => any) ? K : never }[keyof T];
|
|
4869
|
-
type RelationNames<T> = FunctionPropertyNames<T> extends infer R ? R extends `relation${infer P}` ? P extends
|
|
4869
|
+
type RelationNames<T> = FunctionPropertyNames<T> extends infer R ? R extends `relation${infer P}` ? P extends 'sToData' | 'loaded' ? never : CamelToSnakeCase<P> : never : never;
|
|
4870
4870
|
type MixinConstructor<T = TGeneric> = new (...args: any[]) => T;
|
|
4871
4871
|
//#endregion
|
|
4872
4872
|
//#region src/browser/paginator.d.ts
|
package/dist/browser/index.js
CHANGED
|
@@ -70,7 +70,7 @@ var casts_attributes_default = CastsAttributes;
|
|
|
70
70
|
var mixin_exports = /* @__PURE__ */ __export({ compose: () => compose$1 });
|
|
71
71
|
/**
|
|
72
72
|
* Compose function that merges multiple classes and mixins
|
|
73
|
-
*
|
|
73
|
+
*
|
|
74
74
|
* @example
|
|
75
75
|
* const SomePlugin = <TBase extends new (...args: any[]) => TGeneric> (Base: TBase) => {
|
|
76
76
|
* return class extends Base {
|
|
@@ -107,10 +107,10 @@ var mixin_exports = /* @__PURE__ */ __export({ compose: () => compose$1 });
|
|
|
107
107
|
* console.log(user.pluginMethod('w')) // "plugin"
|
|
108
108
|
* console.log(user.pluginMethod()) // "plugin"
|
|
109
109
|
* console.log(user.relationPosts()) // "hasMany Posts"
|
|
110
|
-
*
|
|
111
|
-
* @param Base
|
|
112
|
-
* @param mixins
|
|
113
|
-
* @returns
|
|
110
|
+
*
|
|
111
|
+
* @param Base
|
|
112
|
+
* @param mixins
|
|
113
|
+
* @returns
|
|
114
114
|
*/
|
|
115
115
|
function compose$1(Base, ...mixins) {
|
|
116
116
|
/**
|
|
@@ -171,10 +171,10 @@ const getAttrName = (attrMethod) => {
|
|
|
171
171
|
};
|
|
172
172
|
/**
|
|
173
173
|
* Tap into a model a collection instance
|
|
174
|
-
*
|
|
175
|
-
* @param instance
|
|
176
|
-
* @param callback
|
|
177
|
-
* @returns
|
|
174
|
+
*
|
|
175
|
+
* @param instance
|
|
176
|
+
* @param callback
|
|
177
|
+
* @returns
|
|
178
178
|
*/
|
|
179
179
|
const tap = (instance, callback) => {
|
|
180
180
|
const result = callback(instance);
|