@codenameryuu/adonis-lucid-auto-preload 2.9.1 → 2.9.2
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/build/adonis-typings/auto_preload.d.ts +3 -3
- package/build/adonis-typings/container.d.ts +3 -3
- package/build/configure.d.ts +1 -1
- package/build/configure.js +1 -1
- package/build/index.d.ts +2 -2
- package/build/index.js +2 -2
- package/build/providers/auto_preload_provider.d.ts +2 -2
- package/build/providers/auto_preload_provider.js +3 -3
- package/build/src/exceptions/wrong_argument_type_exception.d.ts +1 -1
- package/build/src/exceptions/wrong_argument_type_exception.js +1 -1
- package/build/src/exceptions/wrong_relationship_type_exception.d.ts +1 -1
- package/build/src/exceptions/wrong_relationship_type_exception.js +1 -1
- package/build/src/mixins/auto_preload.d.ts +2 -2
- package/build/src/mixins/auto_preload.js +8 -8
- package/package.json +1 -1
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import type { NormalizeConstructor } from
|
|
2
|
-
import type { LucidModel } from
|
|
1
|
+
import type { NormalizeConstructor } from "@adonisjs/core/types/helpers";
|
|
2
|
+
import type { LucidModel } from "@adonisjs/lucid/types/model";
|
|
3
3
|
type GetWith<T> = T extends {
|
|
4
4
|
$with: Array<infer Item>;
|
|
5
|
-
} ? Item extends string ? Item : string : string;
|
|
5
|
+
} ? (Item extends string ? Item : string) : string;
|
|
6
6
|
export interface AutoPreloadMixin {
|
|
7
7
|
<T extends NormalizeConstructor<LucidModel>>(superclass: T): T & {
|
|
8
8
|
$with: ReadonlyArray<string | ((query: any) => void)>;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type { AutoPreloadMixin } from
|
|
2
|
-
declare module
|
|
1
|
+
import type { AutoPreloadMixin } from "./auto_preload.js";
|
|
2
|
+
declare module "@adonisjs/core/types" {
|
|
3
3
|
interface ContainerBindings {
|
|
4
|
-
|
|
4
|
+
"@codenameryuu/adonis-lucid-auto-preload": {
|
|
5
5
|
AutoPreload: AutoPreloadMixin;
|
|
6
6
|
};
|
|
7
7
|
}
|
package/build/configure.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import type Configure from
|
|
1
|
+
import type Configure from "@adonisjs/core/commands/configure";
|
|
2
2
|
export declare function configure(command: Configure): Promise<void>;
|
package/build/configure.js
CHANGED
|
@@ -4,6 +4,6 @@ export async function configure(command) {
|
|
|
4
4
|
* Register the provider inside `adonisrc.ts`
|
|
5
5
|
*/
|
|
6
6
|
await codemods.updateRcFile((rcFile) => {
|
|
7
|
-
rcFile.addProvider(
|
|
7
|
+
rcFile.addProvider("@codenameryuu/adonis-lucid-auto-preload/provider");
|
|
8
8
|
});
|
|
9
9
|
}
|
package/build/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { configure } from
|
|
2
|
-
export { AutoPreload } from
|
|
1
|
+
export { configure } from "./configure.js";
|
|
2
|
+
export { AutoPreload } from "./src/mixins/auto_preload.js";
|
package/build/index.js
CHANGED
|
@@ -6,5 +6,5 @@
|
|
|
6
6
|
* For the full copyright and license information, please view the LICENSE
|
|
7
7
|
* file that was distributed with this source code.
|
|
8
8
|
*/
|
|
9
|
-
export { configure } from
|
|
10
|
-
export { AutoPreload } from
|
|
9
|
+
export { configure } from "./configure.js";
|
|
10
|
+
export { AutoPreload } from "./src/mixins/auto_preload.js";
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { ApplicationService } from
|
|
2
|
-
export { configure } from
|
|
1
|
+
import type { ApplicationService } from "@adonisjs/core/types";
|
|
2
|
+
export { configure } from "../configure.js";
|
|
3
3
|
export default class AutoPreloadProvider {
|
|
4
4
|
protected app: ApplicationService;
|
|
5
5
|
static needsApplication: boolean;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { AutoPreload } from
|
|
2
|
-
export { configure } from
|
|
1
|
+
import { AutoPreload } from "../src/mixins/auto_preload.js";
|
|
2
|
+
export { configure } from "../configure.js";
|
|
3
3
|
export default class AutoPreloadProvider {
|
|
4
4
|
app;
|
|
5
5
|
static needsApplication = true;
|
|
@@ -7,7 +7,7 @@ export default class AutoPreloadProvider {
|
|
|
7
7
|
this.app = app;
|
|
8
8
|
}
|
|
9
9
|
register() {
|
|
10
|
-
this.app.container.singleton(
|
|
10
|
+
this.app.container.singleton("@codenameryuu/adonis-lucid-auto-preload", () => {
|
|
11
11
|
return { AutoPreload };
|
|
12
12
|
});
|
|
13
13
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Exception } from
|
|
1
|
+
import { Exception } from "@adonisjs/core/exceptions";
|
|
2
2
|
export default class WrongArgumentTypeException extends Exception {
|
|
3
3
|
static invoke(method) {
|
|
4
4
|
return new this(`The method ${method} accepts only an array of strings`);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Exception } from
|
|
1
|
+
import { Exception } from "@adonisjs/core/exceptions";
|
|
2
2
|
export default class WrongRelationshipTypeException extends Exception {
|
|
3
3
|
static invoke(model) {
|
|
4
4
|
return new this(`The model "${model}" has wrong relationships to be auto-preloaded. Only string and function types are allowed`);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { NormalizeConstructor } from
|
|
2
|
-
import type { LucidModel, ModelQueryBuilderContract } from
|
|
1
|
+
import type { NormalizeConstructor } from "@adonisjs/core/types/helpers";
|
|
2
|
+
import type { LucidModel, ModelQueryBuilderContract } from "@adonisjs/lucid/types/model";
|
|
3
3
|
type PreloadEntry = string | ((query: ModelQueryBuilderContract<any, any>) => void);
|
|
4
4
|
export declare function AutoPreload<T extends NormalizeConstructor<LucidModel>>(superclass: T): {
|
|
5
5
|
new (...args: any[]): {
|
|
@@ -13,9 +13,9 @@ export function AutoPreload(superclass) {
|
|
|
13
13
|
return;
|
|
14
14
|
this.$autoPreloadHooksRegistered = true;
|
|
15
15
|
// Register hooks on the actual model subclass.
|
|
16
|
-
this.before(
|
|
17
|
-
this.before(
|
|
18
|
-
this.before(
|
|
16
|
+
this.before("find", this.beforeFindHook.bind(this));
|
|
17
|
+
this.before("fetch", this.beforeFetchHook.bind(this));
|
|
18
|
+
this.before("paginate", this.beforePaginateHook.bind(this));
|
|
19
19
|
}
|
|
20
20
|
static beforeFindHook(query) {
|
|
21
21
|
this.applyAutoPreload(query);
|
|
@@ -24,7 +24,7 @@ export function AutoPreload(superclass) {
|
|
|
24
24
|
this.applyAutoPreload(query);
|
|
25
25
|
}
|
|
26
26
|
static beforePaginateHook(queries) {
|
|
27
|
-
const main = Array.isArray(queries) ?
|
|
27
|
+
const main = Array.isArray(queries) ? queries[1] ?? queries[0] : queries;
|
|
28
28
|
this.applyAutoPreload(main);
|
|
29
29
|
}
|
|
30
30
|
static applyAutoPreload(query) {
|
|
@@ -38,19 +38,19 @@ export function AutoPreload(superclass) {
|
|
|
38
38
|
const skipList = query.$skipPreloads || [];
|
|
39
39
|
const onlyList = query.$onlyPreloads || [];
|
|
40
40
|
for (const relation of relations) {
|
|
41
|
-
if (typeof relation ===
|
|
41
|
+
if (typeof relation === "string") {
|
|
42
42
|
if (onlyList.length > 0 && !onlyList.includes(relation))
|
|
43
43
|
continue;
|
|
44
44
|
if (skipList.includes(relation))
|
|
45
45
|
continue;
|
|
46
|
-
if (relation.includes(
|
|
47
|
-
this.handleNestedPreload(query, relation.split(
|
|
46
|
+
if (relation.includes(".")) {
|
|
47
|
+
this.handleNestedPreload(query, relation.split("."));
|
|
48
48
|
}
|
|
49
49
|
else {
|
|
50
50
|
query.preload(relation);
|
|
51
51
|
}
|
|
52
52
|
}
|
|
53
|
-
else if (typeof relation ===
|
|
53
|
+
else if (typeof relation === "function") {
|
|
54
54
|
relation(query);
|
|
55
55
|
}
|
|
56
56
|
}
|
package/package.json
CHANGED