@codenameryuu/adonis-lucid-auto-preload 1.8.0 → 1.9.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.
@@ -5,10 +5,10 @@ type GetWith<T> = T extends {
5
5
  } ? Item extends string ? Item : string : string;
6
6
  export interface AutoPreloadMixin {
7
7
  <T extends NormalizeConstructor<LucidModel>>(superclass: T): T & {
8
- $with: Array<string | ((query: any) => void)>;
9
- without(this: T, relationships: Array<GetWith<T>>): T;
10
- withOnly(this: T, relationships: Array<GetWith<T>>): T;
11
- withoutAny(this: T): T;
8
+ $with: ReadonlyArray<string | ((query: any) => void)>;
9
+ without(this: T, relationships: Array<GetWith<T>>): any;
10
+ withOnly(this: T, relationships: Array<GetWith<T>>): any;
11
+ withoutAny(this: T): any;
12
12
  new (...args: Array<any>): {};
13
13
  };
14
14
  }
@@ -1,3 +1,4 @@
1
+ import { AutoPreload } from '../src/mixins/auto_preload.js';
1
2
  export { configure } from '../configure.js';
2
3
  export default class AutoPreloadProvider {
3
4
  app;
@@ -5,7 +6,11 @@ export default class AutoPreloadProvider {
5
6
  constructor(app) {
6
7
  this.app = app;
7
8
  }
8
- register() { }
9
+ register() {
10
+ this.app.container.singleton('@codenameryuu/adonis-lucid-auto-preload', () => {
11
+ return { AutoPreload };
12
+ });
13
+ }
9
14
  async boot() { }
10
15
  async ready() { }
11
16
  async shutdown() { }
@@ -72,6 +72,7 @@ export declare function AutoPreload<T extends NormalizeConstructor<LucidModel>>(
72
72
  * Correct Implementation: Returns the Query Builder to avoid global state pollution
73
73
  */
74
74
  without(relations: string[]): ModelQueryBuilderContract</*elided*/ any & T, InstanceType</*elided*/ any & T>>;
75
+ withOnly(relations: string[]): ModelQueryBuilderContract</*elided*/ any & T, InstanceType</*elided*/ any & T>>;
75
76
  withoutAny(): ModelQueryBuilderContract</*elided*/ any & T, InstanceType</*elided*/ any & T>>;
76
77
  readonly booted: boolean;
77
78
  $columnsDefinitions: Map<string, import("@adonisjs/lucid/types/model").ModelColumnOptions>;
@@ -26,8 +26,11 @@ export function AutoPreload(superclass) {
26
26
  return;
27
27
  // Get list of relations to skip for this specific query
28
28
  const skipList = query.$skipPreloads || [];
29
+ const onlyList = query.$onlyPreloads || [];
29
30
  for (const relation of relations) {
30
31
  if (typeof relation === 'string') {
32
+ if (onlyList.length > 0 && !onlyList.includes(relation))
33
+ continue;
31
34
  if (skipList.includes(relation))
32
35
  continue;
33
36
  if (relation.includes('.')) {
@@ -60,6 +63,11 @@ export function AutoPreload(superclass) {
60
63
  query.$skipPreloads = relations;
61
64
  return query;
62
65
  }
66
+ static withOnly(relations) {
67
+ const query = this.query();
68
+ query.$onlyPreloads = relations;
69
+ return query;
70
+ }
63
71
  static withoutAny() {
64
72
  const query = this.query();
65
73
  query.$disableAutoPreload = true;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@codenameryuu/adonis-lucid-auto-preload",
3
- "version": "1.8.0",
3
+ "version": "1.9.0",
4
4
  "description": "Auto-preload multiple relationships when retrieving Lucid models on Adonis JS 7",
5
5
  "author": "codenameryuu",
6
6
  "license": "MIT",
@@ -13,17 +13,27 @@
13
13
  "node": ">=24.0.0"
14
14
  },
15
15
  "type": "module",
16
+ "types": "./build/index.d.ts",
16
17
  "files": [
17
18
  "build",
18
19
  "!build/bin",
19
20
  "!build/tests"
20
21
  ],
21
22
  "exports": {
22
- ".": "./build/index.js",
23
- "./mixins": "./build/src/mixins/auto_preload.js",
23
+ ".": {
24
+ "types": "./build/index.d.ts",
25
+ "default": "./build/index.js"
26
+ },
27
+ "./mixins": {
28
+ "types": "./build/src/mixins/auto_preload.d.ts",
29
+ "default": "./build/src/mixins/auto_preload.js"
30
+ },
24
31
  "./adonis-typings/*": "./build/adonis-typings/*.js",
25
32
  "./exceptions/*": "./build/exceptions/*.js",
26
- "./provider": "./build/providers/auto_preload_provider.js"
33
+ "./provider": {
34
+ "types": "./build/providers/auto_preload_provider.d.ts",
35
+ "default": "./build/providers/auto_preload_provider.js"
36
+ }
27
37
  },
28
38
  "scripts": {
29
39
  "clean": "del-cli build",