velocious 1.0.113 → 1.0.115

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.
Files changed (24) hide show
  1. package/dist/src/database/query/index.d.ts +5 -5
  2. package/dist/src/database/query/index.d.ts.map +1 -1
  3. package/dist/src/database/query/index.js +5 -14
  4. package/dist/src/database/query/model-class-query.d.ts +16 -37
  5. package/dist/src/database/query/model-class-query.d.ts.map +1 -1
  6. package/dist/src/database/query/model-class-query.js +10 -47
  7. package/dist/src/database/record/index.d.ts +13 -25
  8. package/dist/src/database/record/index.d.ts.map +1 -1
  9. package/dist/src/database/record/index.js +11 -22
  10. package/dist/src/database/record/instance-relationships/base.d.ts +35 -24
  11. package/dist/src/database/record/instance-relationships/base.d.ts.map +1 -1
  12. package/dist/src/database/record/instance-relationships/base.js +24 -11
  13. package/dist/src/database/record/instance-relationships/belongs-to.d.ts +11 -1
  14. package/dist/src/database/record/instance-relationships/belongs-to.d.ts.map +1 -1
  15. package/dist/src/database/record/instance-relationships/belongs-to.js +14 -3
  16. package/dist/src/database/record/instance-relationships/has-many.d.ts +23 -3
  17. package/dist/src/database/record/instance-relationships/has-many.d.ts.map +1 -1
  18. package/dist/src/database/record/instance-relationships/has-many.js +16 -4
  19. package/dist/src/database/record/instance-relationships/has-one.d.ts +21 -4
  20. package/dist/src/database/record/instance-relationships/has-one.d.ts.map +1 -1
  21. package/dist/src/database/record/instance-relationships/has-one.js +19 -8
  22. package/dist/src/environment-handlers/node/cli/commands/generate/base-models.d.ts.map +1 -1
  23. package/dist/src/environment-handlers/node/cli/commands/generate/base-models.js +15 -6
  24. package/package.json +2 -2
@@ -1,3 +1,8 @@
1
+ /**
2
+ * @typedef {{[key: string]: boolean | NestedPreloadRecord }} NestedPreloadRecord
3
+ * @typedef {string | string[] | import("./select-base.js").default | import("./select-base.js").default[]} SelectArgumentType
4
+ * @typedef {object | string} WhereArgumentType
5
+ */
1
6
  /**
2
7
  * @typedef {object} QueryArgsType
3
8
  * @property {import("../drivers/base.js").default} driver
@@ -86,11 +91,6 @@ export default class VelociousDatabaseQuery {
86
91
  * @returns {this}
87
92
  */
88
93
  perPage(perPage: number): this;
89
- /**
90
- * @param {NestedPreloadRecord} data
91
- * @returns {this}
92
- */
93
- preload(data: NestedPreloadRecord): this;
94
94
  /**
95
95
  * @param {string | number} order
96
96
  * @returns {this}
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/database/query/index.js"],"names":[],"mappings":"AAoBA;;;;;;;;;;;;;;;GAeG;AAEH;IACE;;OAEG;IACH,uHAFW,aAAa,EAoCvB;IAhBC,6CAAoB;IACpB,yCAAsB;IACtB,eAA8B;IAC9B,2CAAmB;IACnB,kBAAqB;IACrB,2CAAmB;IACnB,eAAmB;IACnB,gBAAqB;IACrB,6CAAqB;IACrB,cAAiB;IACjB,iBAAuB;IACvB,8BAAuB;IACvB,uBAAuB;IAEvB,kDAAkD;IAClD,SADW,OAAO,iBAAiB,EAAE,OAAO,EAAE,CACzB;IAGvB,sBAAsB;IACtB,SADc,IAAI,CAoBjB;IAED,oDAAoD;IACpD,YADc,OAAO,gBAAgB,EAAE,OAAO,EAAE,CAG/C;IAED,0BAA0B;IAC1B,aADc,MAAM,EAAE,CAGrB;IAED,8DAA8D;IAC9D,cADc,OAAO,4BAA4B,EAAE,OAAO,CACb;IAE7C,2DAA2D;IAC3D,cADc,KAAK,CAAC,OAAO,kBAAkB,EAAE,OAAO,CAAC,CAClB;IAErC;;;OAGG;IACH,WAHW,MAAM,GAAC,OAAO,gBAAgB,EAAE,OAAO,GACrC,IAAI,CAOhB;IAED;;;OAGG;IACH,aAHW,MAAM,GACJ,IAAI,CAKhB;IAED;;;OAGG;IACH,YAHW,MAAM,GAAC;QAAC,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;KAAC,GACzB,IAAI,CAYhB;IAED;;;OAGG;IACH,aAHW,MAAM,GACJ,IAAI,CAKhB;IAED;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AAC;aACzC,KAAK,CAAC,OAAO,iBAAiB,EAAE,OAAO,CAAC;;uBArBjC,iBAAiB;uBAEf,kBAAkB"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/database/query/index.js"],"names":[],"mappings":"AAaA;;;;GAIG;AAEH;;;;;;;;;;;;;;;GAeG;AAEH;IACE;;OAEG;IACH,uHAFW,aAAa,EAoCvB;IAhBC,6CAAoB;IACpB,yCAAsB;IACtB,eAA8B;IAC9B,2CAAmB;IACnB,kBAAqB;IACrB,2CAAmB;IACnB,eAAmB;IACnB,gBAAqB;IACrB,6CAAqB;IACrB,cAAiB;IACjB,iBAAuB;IACvB,8BAAuB;IACvB,uBAAuB;IAEvB,kDAAkD;IAClD,SADW,OAAO,iBAAiB,EAAE,OAAO,EAAE,CACzB;IAGvB,sBAAsB;IACtB,SADc,IAAI,CAoBjB;IAED,oDAAoD;IACpD,YADc,OAAO,gBAAgB,EAAE,OAAO,EAAE,CAG/C;IAED,0BAA0B;IAC1B,aADc,MAAM,EAAE,CAGrB;IAED,8DAA8D;IAC9D,cADc,OAAO,4BAA4B,EAAE,OAAO,CACb;IAE7C,2DAA2D;IAC3D,cADc,KAAK,CAAC,OAAO,kBAAkB,EAAE,OAAO,CAAC,CAClB;IAErC;;;OAGG;IACH,WAHW,MAAM,GAAC,OAAO,gBAAgB,EAAE,OAAO,GACrC,IAAI,CAOhB;IAED;;;OAGG;IACH,aAHW,MAAM,GACJ,IAAI,CAKhB;IAED;;;OAGG;IACH,YAHW,MAAM,GAAC;QAAC,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;KAAC,GACzB,IAAI,CAYhB;IAED;;;OAGG;IACH,aAHW,MAAM,GACJ,IAAI,CAKhB;IAED;;;OAGG;IACH,cAHW,MAAM,GACJ,IAAI,CAKhB;IAED;;;OAGG;IACH,aAHW,MAAM,GAAG,MAAM,GACb,IAAI,CAYhB;IAED;;;OAGG;IACH,iBAHW,MAAM,GACJ,IAAI,CAWhB;IAED;;;OAGG;IACH,iBAHW,MAAM,GACJ,IAAI,CAKhB;IAED;;;OAGG;IACH,eAHW,MAAM,GAAG,MAAM,GACb,IAAI,CAMhB;IAED,sBAAsB;IACtB,gBADc,IAAI,CAOjB;IAED;;;OAGG;IACH,eAHW,kBAAkB,GAChB,IAAI,CAoBhB;IAED;;OAEG;IACH,iBAFa,OAAO,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CASlC;IAED,2EAA2E;IAC3E,WADc,OAAO,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAGnC;IAED;;;OAGG;IACH,SAFa,MAAM,CAE4B;IAE/C;;;OAGG;IACH,aAHW,iBAAiB,GACf,IAAI,CAYhB;CACF;kCAnRY;IAAC,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,GAAG,mBAAmB,CAAA;CAAE;iCAC/C,MAAM,GAAG,MAAM,EAAE,GAAG,OAAO,kBAAkB,EAAE,OAAO,GAAG,OAAO,kBAAkB,EAAE,OAAO,EAAE;gCAC7F,MAAM,GAAG,MAAM;;YAKd,OAAO,oBAAoB,EAAE,OAAO;YACpC,KAAK,CAAC,OAAO,gBAAgB,EAAE,OAAO,CAAC;aACvC,MAAM,EAAE;YACR,KAAK,CAAC,OAAO,gBAAgB,EAAE,OAAO,CAAC;aACvC,OAAO,eAAe,EAAE,OAAO;YAC/B,MAAM,GAAG,IAAI;aACb,MAAM,GAAG,IAAI;aACb,KAAK,CAAC,OAAO,iBAAiB,EAAE,OAAO,CAAC;WACxC,MAAM,GAAG,IAAI;cACb,MAAM;cACN,mBAAmB;cACnB,KAAK,CAAC,OAAO,kBAAkB,EAAE,OAAO,CAAC;aACzC,KAAK,CAAC,OAAO,iBAAiB,EAAE,OAAO,CAAC;;uBA3BjC,iBAAiB;uBAEf,kBAAkB"}
@@ -1,11 +1,5 @@
1
1
  // @ts-check
2
- /**
3
- * @typedef {{[key: string]: boolean | NestedPreloadRecord }} NestedPreloadRecord
4
- * @typedef {string | string[] | import("./select-base.js").default | import("./select-base.js").default[]} SelectArgumentType
5
- * @typedef {object | string} WhereArgumentType
6
- */
7
2
  import FromPlain from "./from-plain.js";
8
- import { incorporate } from "incorporator";
9
3
  import { isPlainObject } from "is-plain-object";
10
4
  import JoinObject from "./join-object.js";
11
5
  import JoinPlain from "./join-plain.js";
@@ -15,6 +9,11 @@ import SelectBase from "./select-base.js";
15
9
  import SelectPlain from "./select-plain.js";
16
10
  import WhereHash from "./where-hash.js";
17
11
  import WherePlain from "./where-plain.js";
12
+ /**
13
+ * @typedef {{[key: string]: boolean | NestedPreloadRecord }} NestedPreloadRecord
14
+ * @typedef {string | string[] | import("./select-base.js").default | import("./select-base.js").default[]} SelectArgumentType
15
+ * @typedef {object | string} WhereArgumentType
16
+ */
18
17
  /**
19
18
  * @typedef {object} QueryArgsType
20
19
  * @property {import("../drivers/base.js").default} driver
@@ -175,14 +174,6 @@ export default class VelociousDatabaseQuery {
175
174
  this._perPage = perPage;
176
175
  return this;
177
176
  }
178
- /**
179
- * @param {NestedPreloadRecord} data
180
- * @returns {this}
181
- */
182
- preload(data) {
183
- incorporate(this._preload, data);
184
- return this;
185
- }
186
177
  /**
187
178
  * @param {string | number} order
188
179
  * @returns {this}
@@ -1,27 +1,19 @@
1
- /**
2
- * @typedef {{[key: string]: boolean | NestedPreloadRecord }} NestedPreloadRecord
3
- * @typedef {string | string[] | import("./select-base.js").default | import("./select-base.js").default[]} SelectArgumentType
4
- * @typedef {object | string} WhereArgumentType
5
- */
6
1
  /**
7
2
  * @template {typeof import("../record/index.js").default} MC
8
- * @typedef {InstanceType<MC>} ModelOf
9
3
  */
10
4
  /**
11
5
  * @template {typeof import("../record/index.js").default} MC
12
- * @typedef {import("./index.js").QueryArgsType & object} ModelClassQueryArgsType
13
- * @property {MC} modelClass
6
+ * @typedef {import("./index.js").QueryArgsType & {modelClass: MC}} ModelClassQueryArgsType
14
7
  */
15
8
  /**
16
9
  * A generic query over some model type.
17
10
  * @template {typeof import("../record/index.js").default} MC
18
11
  */
19
12
  export default class VelociousDatabaseQueryModelClassQuery<MC extends typeof import("../record/index.js").default> extends DatabaseQuery {
20
- /**
21
- * @param {ModelClassQueryArgsType<MC>} args
22
- */
13
+ /** @param {ModelClassQueryArgsType<MC>} args */
23
14
  constructor(args: ModelClassQueryArgsType<MC>);
24
- modelClass: any;
15
+ /** @type {MC} */
16
+ modelClass: MC;
25
17
  /** @returns {this} */
26
18
  clone(): this;
27
19
  /** @returns {Promise<number>} */
@@ -44,12 +36,12 @@ export default class VelociousDatabaseQueryModelClassQuery<MC extends typeof imp
44
36
  }): Promise<InstanceType<MC> | null>;
45
37
  /**
46
38
  * @param {{[key: string]: any}} conditions
47
- * @param {function() : void} callback
39
+ * @param {function(InstanceType<MC>) : void} callback
48
40
  * @returns {Promise<InstanceType<MC>>}
49
41
  */
50
42
  findOrCreateBy(conditions: {
51
43
  [key: string]: any;
52
- }, callback: () => void): Promise<InstanceType<MC>>;
44
+ }, callback: (arg0: InstanceType<MC>) => void): Promise<InstanceType<MC>>;
53
45
  /**
54
46
  * @param {{[key: string]: any}} conditions
55
47
  * @returns {Promise<InstanceType<MC>>}
@@ -59,40 +51,27 @@ export default class VelociousDatabaseQueryModelClassQuery<MC extends typeof imp
59
51
  }): Promise<InstanceType<MC>>;
60
52
  /**
61
53
  * @param {object} conditions
62
- * @param {function(import("../record/index.js").default) : void} callback
63
- * @returns {Promise<InstanceType<MC>>}
64
- */
65
- findOrInitializeBy(conditions: object, callback: (arg0: import("../record/index.js").default) => void): Promise<InstanceType<MC>>;
66
- /**
54
+ * @param {function(InstanceType<MC>) : void} callback
67
55
  * @returns {Promise<InstanceType<MC>>}
68
56
  */
69
- first(): Promise<InstanceType<MC>>;
70
- /**
71
- * @returns {Promise<InstanceType<MC>>}
72
- */
73
- last(): Promise<InstanceType<MC>>;
74
- /**
75
- * @param {NestedPreloadRecord} data
76
- * @returns {this}
77
- */
78
- preload(data: NestedPreloadRecord): this;
57
+ findOrInitializeBy(conditions: object, callback: (arg0: InstanceType<MC>) => void): Promise<InstanceType<MC>>;
58
+ /** @returns {Promise<InstanceType<MC> | undefined>} */
59
+ first(): Promise<InstanceType<MC> | undefined>;
60
+ /** @returns {Promise<InstanceType<MC> | undefined>} */
61
+ last(): Promise<InstanceType<MC> | undefined>;
79
62
  /**
80
- * @param {SelectArgumentType} select
63
+ * @param {import("./index.js").NestedPreloadRecord} data
81
64
  * @returns {this}
82
65
  */
83
- select(select: SelectArgumentType): this;
66
+ preload(data: import("./index.js").NestedPreloadRecord): this;
84
67
  /**
85
68
  * Converts query results to array of model instances
86
69
  * @returns {Promise<Array<InstanceType<MC>>>}
87
70
  */
88
71
  toArray(): Promise<Array<InstanceType<MC>>>;
89
72
  }
90
- export type NestedPreloadRecord = {
91
- [key: string]: boolean | NestedPreloadRecord;
73
+ export type ModelClassQueryArgsType<MC extends typeof import("../record/index.js").default> = import("./index.js").QueryArgsType & {
74
+ modelClass: MC;
92
75
  };
93
- export type SelectArgumentType = string | string[] | import("./select-base.js").default | import("./select-base.js").default[];
94
- export type WhereArgumentType = object | string;
95
- export type ModelOf<MC extends typeof import("../record/index.js").default> = InstanceType<MC>;
96
- export type ModelClassQueryArgsType<MC extends typeof import("../record/index.js").default> = import("./index.js").QueryArgsType & object;
97
76
  import DatabaseQuery from "./index.js";
98
77
  //# sourceMappingURL=model-class-query.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"model-class-query.d.ts","sourceRoot":"","sources":["../../../../src/database/query/model-class-query.js"],"names":[],"mappings":"AAWA;;;;GAIG;AACH;;;GAGG;AACH;;;;GAIG;AAEH;;;GAGG;AACH,2DAF2D,EAAE,SAAhD,cAAe,oBAAoB,EAAE,OAAQ;IAGxD;;OAEG;IACH,kBAFW,uBAAuB,CAAC,EAAE,CAAC,EAUrC;IADC,gBAA4B;IAG9B,sBAAsB;IACtB,SADc,IAAI,CAsBjB;IAED,iCAAiC;IACjC,SADc,OAAO,CAAC,MAAM,CAAC,CAqC5B;I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GAAG,OAAO,kBAAkB,EAAE,OAAO,GAAG,OAAO,kBAAkB,EAAE,OAAO,EAAE;gCAC7F,MAAM,GAAG,MAAM;oBAG+B,EAAE,SAAhD,cAAe,oBAAoB,EAAE,OAAQ,IAC7C,YAAY,CAAC,EAAE,CAAC;oCAG8B,EAAE,SAAhD,cAAe,oBAAoB,EAAE,OAAQ,IAC7C,OAAO,YAAY,EAAE,aAAa,GAAG,MAAM;0BAhB9B,YAAY"}
1
+ {"version":3,"file":"model-class-query.d.ts","sourceRoot":"","sources":["../../../../src/database/query/model-class-query.js"],"names":[],"mappings":"AASA;;GAEG;AACH;;;GAGG;AAEH;;;GAGG;AACH,2DAX2D,EAAE,SAAhD,cAAe,oBAAoB,EAAE,OAAQ;IAYxD,gDAAgD;IAChD,kBADY,uBAAuB,CAAC,EAAE,CAAC,EAWtC;IAFC,iBAAiB;IACjB,YADW,EAAE,CACe;IAG9B,sBAAsB;IACtB,SADc,IAAI,CAqBjB;IAED,iCAAiC;IACjC,SADc,OAAO,CAAC,MAAM,CAAC,CAmC5B;IAED,oBAAoB;IACpB,iBADc,EAAE,CAKf;IAED,+BAA+B;IAC/B,cADc,OAAO,CAAC,IAAI,CAAC,CAO1B;IAED;;;OAGG;IACH,eAHW,MAAM,GAAC,MAAM,GACX,OAAO,CAAC,YAAY,CAAC,EAAE,CAAC,CAAC,CAmBrC;IAED;;;OAGG;IACH,mBAHW;QAAC,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;KAAC,GAClB,OAAO,CAAC,YAAY,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,CAiB5C;IAED;;;;OAIG;IACH,2BAJW;QAAC,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;KAAC,YACpB,CAAS,IAAgB,EAAhB,YAAY,CAAC,EAAE,CAAC,KAAI,IAAI,GAC/B,OAAO,CAAC,YAAY,CAAC,EAAE,CAAC,CAAC,CAUrC;IAED;;;OAGG;IACH,yBAHW;QAAC,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;KAAC,GAClB,OAAO,CAAC,YAAY,CAAC,EAAE,CAAC,CAAC,CAuBrC;IAED;;;;OAIG;IACH,+BAJW,MAAM,YACN,CAAS,IAAgB,EAAhB,YAAY,CAAC,EAAE,CAAC,KAAI,IAAI,GAC/B,OAAO,CAAC,YAAY,CAAC,EAAE,CAAC,CAAC,CAerC;IAED,uDAAuD;IACvD,SADc,OAAO,CAAC,YAAY,CAAC,EAAE,CAAC,GAAG,SAAS,CAAC,CAMlD;IAED,uDAAuD;IACvD,QADc,OAAO,CAAC,YAAY,CAAC,EAAE,CAAC,GAAG,SAAS,CAAC,CAOlD;IAED;;;OAGG;IACH,cAHW,OAAO,YAAY,EAAE,mBAAmB,GACtC,IAAI,CAKhB;IAED;;;OAGG;IACH,WAFa,OAAO,CAAC,KAAK,CAAC,YAAY,CAAC,EAAE,CAAC,CAAC,CAAC,CAyB5C;CACF;oCAlQ0D,EAAE,SAAhD,cAAe,oBAAoB,EAAE,OAAQ,IAC7C,OAAO,YAAY,EAAE,aAAa,GAAG;IAAC,UAAU,EAAE,EAAE,CAAA;CAAC;0BARxC,YAAY"}
@@ -5,42 +5,31 @@ import { Logger } from "../../logger.js";
5
5
  import Preloader from "./preloader.js";
6
6
  import DatabaseQuery from "./index.js";
7
7
  import RecordNotFoundError from "../record/record-not-found-error.js";
8
- import SelectBase from "./select-base.js";
9
- import SelectPlain from "./select-plain.js";
10
- /**
11
- * @typedef {{[key: string]: boolean | NestedPreloadRecord }} NestedPreloadRecord
12
- * @typedef {string | string[] | import("./select-base.js").default | import("./select-base.js").default[]} SelectArgumentType
13
- * @typedef {object | string} WhereArgumentType
14
- */
15
8
  /**
16
9
  * @template {typeof import("../record/index.js").default} MC
17
- * @typedef {InstanceType<MC>} ModelOf
18
10
  */
19
11
  /**
20
12
  * @template {typeof import("../record/index.js").default} MC
21
- * @typedef {import("./index.js").QueryArgsType & object} ModelClassQueryArgsType
22
- * @property {MC} modelClass
13
+ * @typedef {import("./index.js").QueryArgsType & {modelClass: MC}} ModelClassQueryArgsType
23
14
  */
24
15
  /**
25
16
  * A generic query over some model type.
26
17
  * @template {typeof import("../record/index.js").default} MC
27
18
  */
28
19
  export default class VelociousDatabaseQueryModelClassQuery extends DatabaseQuery {
29
- /**
30
- * @param {ModelClassQueryArgsType<MC>} args
31
- */
20
+ /** @param {ModelClassQueryArgsType<MC>} args */
32
21
  constructor(args) {
33
22
  const { modelClass } = args;
34
23
  if (!modelClass)
35
24
  throw new Error(`No modelClass given in ${Object.keys(args).join(", ")}`);
36
25
  super(args);
37
26
  this.logger = new Logger(this);
27
+ /** @type {MC} */
38
28
  this.modelClass = modelClass;
39
29
  }
40
30
  /** @returns {this} */
41
31
  clone() {
42
- // @ts-expect-error
43
- const newQuery = /** @type {new (args: ModelClassQueryArgsType<MC>) => this} */ (new VelociousDatabaseQueryModelClassQuery({
32
+ const newQuery = /** @type {VelociousDatabaseQueryModelClassQuery<MC>} */ (new VelociousDatabaseQueryModelClassQuery({
44
33
  driver: this.driver,
45
34
  froms: [...this._froms],
46
35
  handler: this.handler.clone(),
@@ -70,7 +59,7 @@ export default class VelociousDatabaseQueryModelClassQuery extends DatabaseQuery
70
59
  const countQuery = this.clone();
71
60
  countQuery._selects = [];
72
61
  countQuery.select(sql);
73
- const results = /** @type {{ count: number }[]} */ (await countQuery._executeQuery());
62
+ const results = /** @type {{count: number}[]} */ (await countQuery._executeQuery());
74
63
  // The query isn't grouped and a single result has been given
75
64
  if (results.length == 1) {
76
65
  return results[0].count;
@@ -131,7 +120,7 @@ export default class VelociousDatabaseQueryModelClassQuery extends DatabaseQuery
131
120
  }
132
121
  /**
133
122
  * @param {{[key: string]: any}} conditions
134
- * @param {function() : void} callback
123
+ * @param {function(InstanceType<MC>) : void} callback
135
124
  * @returns {Promise<InstanceType<MC>>}
136
125
  */
137
126
  async findOrCreateBy(conditions, callback) {
@@ -162,7 +151,7 @@ export default class VelociousDatabaseQueryModelClassQuery extends DatabaseQuery
162
151
  }
163
152
  /**
164
153
  * @param {object} conditions
165
- * @param {function(import("../record/index.js").default) : void} callback
154
+ * @param {function(InstanceType<MC>) : void} callback
166
155
  * @returns {Promise<InstanceType<MC>>}
167
156
  */
168
157
  async findOrInitializeBy(conditions, callback) {
@@ -176,17 +165,13 @@ export default class VelociousDatabaseQueryModelClassQuery extends DatabaseQuery
176
165
  }
177
166
  return newRecord;
178
167
  }
179
- /**
180
- * @returns {Promise<InstanceType<MC>>}
181
- */
168
+ /** @returns {Promise<InstanceType<MC> | undefined>} */
182
169
  async first() {
183
170
  const newQuery = this.clone().limit(1).reorder(`${this.driver.quoteTable(this.getModelClass().tableName())}.${this.driver.quoteColumn(this.getModelClass().orderableColumn())}`);
184
171
  const results = await newQuery.toArray();
185
172
  return results[0];
186
173
  }
187
- /**
188
- * @returns {Promise<InstanceType<MC>>}
189
- */
174
+ /** @returns {Promise<InstanceType<MC> | undefined>} */
190
175
  async last() {
191
176
  const primaryKey = this.getModelClass().primaryKey();
192
177
  const tableName = this.getModelClass().tableName();
@@ -194,35 +179,13 @@ export default class VelociousDatabaseQueryModelClassQuery extends DatabaseQuery
194
179
  return results[0];
195
180
  }
196
181
  /**
197
- * @param {NestedPreloadRecord} data
182
+ * @param {import("./index.js").NestedPreloadRecord} data
198
183
  * @returns {this}
199
184
  */
200
185
  preload(data) {
201
186
  incorporate(this._preload, data);
202
187
  return this;
203
188
  }
204
- /**
205
- * @param {SelectArgumentType} select
206
- * @returns {this}
207
- */
208
- select(select) {
209
- if (Array.isArray(select)) {
210
- for (const selectInArray of select) {
211
- this.select(selectInArray);
212
- }
213
- return this;
214
- }
215
- if (typeof select == "string") {
216
- this._selects.push(new SelectPlain(select));
217
- }
218
- else if (select instanceof SelectBase) {
219
- this._selects.push(select);
220
- }
221
- else {
222
- throw new Error(`Invalid select type: ${typeof select}`);
223
- }
224
- return this;
225
- }
226
189
  /**
227
190
  * Converts query results to array of model instances
228
191
  * @returns {Promise<Array<InstanceType<MC>>>}
@@ -203,21 +203,13 @@ declare class VelociousDatabaseRecord {
203
203
  * @param {Record<string, boolean | Record<string, any>>} validators The validators to add. Key is the validator name, value is the validator arguments.
204
204
  */
205
205
  static validates(attributeName: string, validators: Record<string, boolean | Record<string, any>>): Promise<void>;
206
- /**
207
- * @returns {ModelClassQuery<typeof this>}
208
- */
206
+ /** @returns {ModelClassQuery<typeof this>} */
209
207
  static _newQuery(): ModelClassQuery<typeof this>;
210
- /**
211
- * @returns {string}
212
- */
208
+ /** @returns {string} */
213
209
  static orderableColumn(): string;
214
- /**
215
- * @returns {ModelClassQuery<typeof this>}
216
- */
210
+ /** @returns {ModelClassQuery<typeof this>} */
217
211
  static all(): ModelClassQuery<typeof this>;
218
- /**
219
- * @returns {Promise<number>}
220
- */
212
+ /** @returns {Promise<number>} */
221
213
  static count(): Promise<number>;
222
214
  static destroyAll(): Promise<void>;
223
215
  /**
@@ -249,13 +241,11 @@ declare class VelociousDatabaseRecord {
249
241
  }, callback?: () => void): Promise<InstanceType<typeof this>>;
250
242
  /**
251
243
  * @param {object} conditions
252
- * @param {function(import("../record/index.js").default) : void} [callback]
253
- * @returns {Promise<InstanceType<typeof this>>}
254
- */
255
- static findOrInitializeBy(conditions: object, callback?: (arg0: import("../record/index.js").default) => void): Promise<InstanceType<typeof this>>;
256
- /**
244
+ * @param {function(InstanceType<typeof this>) : void} [callback]
257
245
  * @returns {Promise<InstanceType<typeof this>>}
258
246
  */
247
+ static findOrInitializeBy(conditions: object, callback?: (arg0: InstanceType<typeof this>) => void): Promise<InstanceType<typeof this>>;
248
+ /** @returns {Promise<InstanceType<typeof this>>} */
259
249
  static first(): Promise<InstanceType<typeof this>>;
260
250
  /**
261
251
  * @param {string|{[key: string]: any}} join
@@ -264,9 +254,7 @@ declare class VelociousDatabaseRecord {
264
254
  static joins(join: string | {
265
255
  [key: string]: any;
266
256
  }): ModelClassQuery<typeof this>;
267
- /**
268
- * @returns {Promise<InstanceType<typeof this>>}
269
- */
257
+ /** @returns {Promise<InstanceType<typeof this>>} */
270
258
  static last(): Promise<InstanceType<typeof this>>;
271
259
  /**
272
260
  * @param {number} value
@@ -289,9 +277,9 @@ declare class VelociousDatabaseRecord {
289
277
  */
290
278
  static select(select: import("../query/index.js").SelectArgumentType): ModelClassQuery<typeof this>;
291
279
  /**
292
- * @returns {Promise<VelociousDatabaseRecord[]>}
280
+ * @returns {Promise<InstanceType<typeof this>[]>}
293
281
  */
294
- static toArray(): Promise<VelociousDatabaseRecord[]>;
282
+ static toArray(): Promise<InstanceType<typeof this>[]>;
295
283
  /**
296
284
  * @param {import("../query/index.js").WhereArgumentType} where
297
285
  * @returns {ModelClassQuery<typeof this>}
@@ -310,7 +298,7 @@ declare class VelociousDatabaseRecord {
310
298
  /** @type {import("../drivers/base.js").default | undefined} */
311
299
  __connection: import("../drivers/base.js").default | undefined;
312
300
  /** @type {Record<string, import("./instance-relationships/base.js").default>} */
313
- _instanceRelationships: Record<string, import("./instance-relationships/base.js").default>;
301
+ _instanceRelationships: Record<string, import("./instance-relationships/base.js").default<any, any>>;
314
302
  /** @type {string | undefined} */
315
303
  __tableName: string | undefined;
316
304
  /** @type {Record<string, ValidationErrorObjectType[]>} */
@@ -319,7 +307,7 @@ declare class VelociousDatabaseRecord {
319
307
  * @param {string} relationshipName
320
308
  * @returns {import("./instance-relationships/base.js").default}
321
309
  */
322
- getRelationshipByName(relationshipName: string): import("./instance-relationships/base.js").default;
310
+ getRelationshipByName(relationshipName: string): import("./instance-relationships/base.js").default<any, any>;
323
311
  /**
324
312
  * @returns {import("../../configuration.js").default}
325
313
  */
@@ -354,7 +342,7 @@ declare class VelociousDatabaseRecord {
354
342
  _autoSaveBelongsToRelationships(): Promise<{
355
343
  savedCount: number;
356
344
  }>;
357
- _autoSaveHasManyAndHasOneRelationshipsToSave(): import("./instance-relationships/base.js").default[];
345
+ _autoSaveHasManyAndHasOneRelationshipsToSave(): import("./instance-relationships/base.js").default<any, any>[];
358
346
  /**
359
347
  * @param {object} args
360
348
  * @param {boolean} args.isNewRecord
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/database/record/index.js"],"names":[],"mappings":";wCAGa;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAC;AAkB5C;IACE;;OAEG;IACH,YAFa,uBAAuB,CAMnC;IAED;;;OAGG;IACH,gBAHW,uBAAuB,GACrB,IAAI,CAIhB;IADC,gCAAmB;IAGrB,6DAA6D;IAC7D,uBADc,MAAM,CAAC,MAAM,EAAE,yBAAyB,EAAE,CAAC,CAKxD;IAED,4EAA4E;IAC5E,sCADY,MAAM,CAAC,MAAM,EAAE,yBAAyB,EAAE,CAAC,QAGtD;IADC,+DAAyC;CAE5C;AAED;IACE,iEAOC;IAED,iEAOC;IAED,iDAOC;IAED,oFAOC;IAED,6FAOC;IAuBD,uFAEC;IAED;;;OAGG;IACH,mCAHW,MAAM,kBACN,cAAc,sBAAsB,EAAE,OAAO,QAIvD;IAED;;;OAGG;IACH,uCAHW,MAAM,GACJ,cAAc,sBAAsB,EAAE,OAAO,CAMzD;IAED;;;OAGG;IACH,6CAHW,MAAM,GACJ,OAAO,CAQnB;IAED;;;;;OAKG;IACH;;;OAGG;IACH,6CAHW,MAAM;oBALH,MAAM;gBACN,OAAO,uBAAuB;eAC9B,MAAM;aA8GnB;IAED;;;OAGG;IACH,+CAHW,MAAM,GACJ,OAAO,yBAAyB,EAAE,OAAO,CAQrD;IAED;;OAEG;IACH,2BAFa,KAAK,CAAC,OAAO,yBAAyB,EAAE,OAAO,CAAC,CAI5D;IAED,wFAOC;IAED;;OAEG;IACH,+BAFa,KAAK,CAAC,MAAM,CAAC,CAIzB;IA4BD;;;;OAIG;IACH,mCAHW,MAAM,YACN,MAAM,QAIhB;IAED;;OAEG;IACH,qBAFa,OAAO,oBAAoB,EAAE,OAAO,CAShD;IAED;;;OAGG;IACH,2BAHW,MAAM,CAAC,MAAM,E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IACH,eAFa,OAAO,oBAAoB,EAAE,OAAO,CAMhD;IAED;;;OAGG;IACH,WAFa,OAAO,CAAC,IAAI,CAAC,CA2DzB;IAED,yBAAyB;IACzB,eADc,OAAO,CACyC;IAE9D;;;OAGG;IACH,aAFa,OAAO,CA6BnB;IAED,oGAAoG;IACpG,iCAWC;IAED;;OAEG;IACH,cAFa,MAAM,CAMlB;IAED;;;;OAIG;IACH,6BAHW,MAAM,GACJ,GAAG,CAQf;IAED;;;OAGG;IACH,0BAFW,MAAM,OAqBhB;IAED,yCAuBC;IAED,+BAA+B;IAC/B,oBADc,OAAO,CAAC,IAAI,CAAC,CA4C1B;IAED,+BAA+B;IAC/B,4BADc,OAAO,CAAC,IAAI,CAAC,CAsB1B;IAED,+BAA+B;IAC/B,MADc,MAAM,GAAC,MAAM,CAc1B;IAED,yBAAyB;IACzB,eADc,OAAO,CACsB;IAE3C,yBAAyB;IACzB,eADc,OAAO,CACqB;IAE1C;;;OAGG;IACH,+BAHW,OAAO,GACL,IAAI,CAIhB;IAED;;;;OAIG;IACH,cAJ8C,EAAE,SAAnC,OAAQ,uBAAwB,MAClC,MAAM,GAAG,MAAM,GACb,OAAO,CAAC,IAAI,CAAC,CAiBzB;IAED;;OAEG;IACH,UAFa,OAAO,CAAC,IAAI,CAAC,CAIzB;IAED,iCAwBC;IAED,0BAA0B;IAC1B,qBADc,MAAM,EAAE,CAgBrB;IAED;;;OAGG;IACH,2BAFW,MAAM,iBAMhB;CACF;AAED;IACE;;;OAGG;IACH,UAFa,MAAM,CAIlB;CACF;4BA9mD2B,+BAA+B"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/database/record/index.js"],"names":[],"mappings":";wCAGa;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAC;AAkB5C;IACE;;OAEG;IACH,YAFa,uBAAuB,CAMnC;IAED;;;OAGG;IACH,gBAHW,uBAAuB,GACrB,IAAI,CAIhB;IAD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W,MAAM,OAqBhB;IAED,yCAuBC;IAED,+BAA+B;IAC/B,oBADc,OAAO,CAAC,IAAI,CAAC,CA4C1B;IAED,+BAA+B;IAC/B,4BADc,OAAO,CAAC,IAAI,CAAC,CAsB1B;IAED,+BAA+B;IAC/B,MADc,MAAM,GAAC,MAAM,CAc1B;IAED,yBAAyB;IACzB,eADc,OAAO,CACsB;IAE3C,yBAAyB;IACzB,eADc,OAAO,CACqB;IAE1C;;;OAGG;IACH,+BAHW,OAAO,GACL,IAAI,CAIhB;IAED;;;;OAIG;IACH,cAJ8C,EAAE,SAAnC,OAAQ,uBAAwB,MAClC,MAAM,GAAG,MAAM,GACb,OAAO,CAAC,IAAI,CAAC,CAiBzB;IAED;;OAEG;IACH,UAFa,OAAO,CAAC,IAAI,CAAC,CAIzB;IAED,iCAwBC;IAED,0BAA0B;IAC1B,qBADc,MAAM,EAAE,CAgBrB;IAED;;;OAGG;IACH,2BAFW,MAAM,iBAMhB;CACF;AAED;IACE;;;OAGG;IACH,UAFa,MAAM,CAIlB;CACF;4BApmD2B,+BAA+B"}
@@ -899,9 +899,7 @@ class VelociousDatabaseRecord {
899
899
  assignments[name] = newValue;
900
900
  translation.assign(assignments);
901
901
  }
902
- /**
903
- * @returns {ModelClassQuery<typeof this>}
904
- */
902
+ /** @returns {ModelClassQuery<typeof this>} */
905
903
  static _newQuery() {
906
904
  const handler = new Handler();
907
905
  const query = new ModelClassQuery({
@@ -911,22 +909,16 @@ class VelociousDatabaseRecord {
911
909
  });
912
910
  return query.from(new FromTable(this.tableName()));
913
911
  }
914
- /**
915
- * @returns {string}
916
- */
912
+ /** @returns {string} */
917
913
  static orderableColumn() {
918
914
  // FIXME: Allow to change to 'created_at' if using UUID?
919
915
  return this.primaryKey();
920
916
  }
921
- /**
922
- * @returns {ModelClassQuery<typeof this>}
923
- */
917
+ /** @returns {ModelClassQuery<typeof this>} */
924
918
  static all() {
925
919
  return this._newQuery();
926
920
  }
927
- /**
928
- * @returns {Promise<number>}
929
- */
921
+ /** @returns {Promise<number>} */
930
922
  static async count() {
931
923
  return await this._newQuery().count();
932
924
  }
@@ -964,15 +956,13 @@ class VelociousDatabaseRecord {
964
956
  }
965
957
  /**
966
958
  * @param {object} conditions
967
- * @param {function(import("../record/index.js").default) : void} [callback]
959
+ * @param {function(InstanceType<typeof this>) : void} [callback]
968
960
  * @returns {Promise<InstanceType<typeof this>>}
969
961
  */
970
962
  static async findOrInitializeBy(conditions, callback) {
971
963
  return await this._newQuery().findOrInitializeBy(conditions, callback);
972
964
  }
973
- /**
974
- * @returns {Promise<InstanceType<typeof this>>}
975
- */
965
+ /** @returns {Promise<InstanceType<typeof this>>} */
976
966
  static async first() {
977
967
  return await this._newQuery().first();
978
968
  }
@@ -983,9 +973,7 @@ class VelociousDatabaseRecord {
983
973
  static joins(join) {
984
974
  return this._newQuery().joins(join);
985
975
  }
986
- /**
987
- * @returns {Promise<InstanceType<typeof this>>}
988
- */
976
+ /** @returns {Promise<InstanceType<typeof this>>} */
989
977
  static async last() {
990
978
  return await this._newQuery().last();
991
979
  }
@@ -1018,10 +1006,11 @@ class VelociousDatabaseRecord {
1018
1006
  return this._newQuery().select(select);
1019
1007
  }
1020
1008
  /**
1021
- * @returns {Promise<VelociousDatabaseRecord[]>}
1009
+ * @returns {Promise<InstanceType<typeof this>[]>}
1022
1010
  */
1023
- static toArray() {
1024
- return this._newQuery().toArray();
1011
+ static async toArray() {
1012
+ const modelClassQuery = /** @type {ModelClassQuery<typeof this>} */ (this._newQuery());
1013
+ return await modelClassQuery.toArray();
1025
1014
  }
1026
1015
  /**
1027
1016
  * @param {import("../query/index.js").WhereArgumentType} where
@@ -1,30 +1,37 @@
1
- export default class VelociousDatabaseRecordBaseInstanceRelationship {
1
+ /**
2
+ * @template {typeof import("../index.js").default} MC
3
+ * @template {typeof import("../index.js").default} TMC
4
+ * @typedef {object} InstanceRelationshipsBaseArgs
5
+ * @property {InstanceType<MC>} model
6
+ @property {import("../relationships/base.js").default} relationship
7
+ */
8
+ /**
9
+ * A generic query over some model type.
10
+ * @template {typeof import("../index.js").default} MC
11
+ * @template {typeof import("../index.js").default} TMC
12
+ */
13
+ export default class VelociousDatabaseRecordBaseInstanceRelationship<MC extends typeof import("../index.js").default, TMC extends typeof import("../index.js").default> {
2
14
  /**
3
- * @param {object} args
4
- * @param {import("../index.js").default} args.model
5
- * @param {import("../relationships/base.js").default} args.relationship
15
+ * @param {InstanceRelationshipsBaseArgs<MC, TMC>} args
6
16
  */
7
- constructor({ model, relationship }: {
8
- model: import("../index.js").default;
9
- relationship: import("../relationships/base.js").default;
10
- });
17
+ constructor({ model, relationship }: InstanceRelationshipsBaseArgs<MC, TMC>);
11
18
  /** @type {boolean | undefined} */
12
19
  _autoSave: boolean | undefined;
13
20
  _dirty: boolean;
14
- model: import("../index.js").default;
21
+ model: InstanceType<MC>;
15
22
  relationship: import("../relationships/base.js").default;
16
23
  /**
17
24
  * @abstract
18
- * @param {import("../index.js").default[] | import("../index.js").default} models
25
+ * @param {InstanceType<TMC>[] | InstanceType<TMC>} models
19
26
  * @returns {void}
20
27
  */
21
- addToLoaded(models: import("../index.js").default[] | import("../index.js").default): void;
28
+ addToLoaded(models: InstanceType<TMC>[] | InstanceType<TMC>): void;
22
29
  /**
23
30
  * @abstract
24
31
  * @param {Record<string, any>} attributes
25
- * @returns {import("../index.js").default}
32
+ * @returns {InstanceType<TMC>}
26
33
  */
27
- build(attributes: Record<string, any>): import("../index.js").default;
34
+ build(attributes: Record<string, any>): InstanceType<TMC>;
28
35
  /** @returns {boolean | undefined} Whether the relationship should be auto-saved before saving the parent model */
29
36
  getAutoSave(): boolean | undefined;
30
37
  /**
@@ -46,13 +53,13 @@ export default class VelociousDatabaseRecordBaseInstanceRelationship {
46
53
  load(): Promise<void>;
47
54
  /** @returns {boolean} Whether the relationship has been preloaded */
48
55
  isLoaded(): boolean;
49
- /** @returns {import("../index.js").default | Array<import("../index.js").default> | undefined} The loaded model or models (depending on relationship type) */
50
- loaded(): import("../index.js").default | Array<import("../index.js").default> | undefined;
51
- /** @param {import("../index.js").default|Array<import("../index.js").default>|undefined} model */
52
- setLoaded(model: import("../index.js").default | Array<import("../index.js").default> | undefined): void;
53
- _loaded: import("../index.js").default | import("../index.js").default[];
54
- /** @returns {import("../index.js").default | import("../index.js").default[] | undefined} */
55
- getLoadedOrUndefined(): import("../index.js").default | import("../index.js").default[] | undefined;
56
+ /** @returns {InstanceType<TMC> | Array<InstanceType<TMC>> | undefined} The loaded model or models (depending on relationship type) */
57
+ loaded(): InstanceType<TMC> | Array<InstanceType<TMC>> | undefined;
58
+ /** @param {InstanceType<TMC> | Array<InstanceType<TMC>> | undefined} model */
59
+ setLoaded(model: InstanceType<TMC> | Array<InstanceType<TMC>> | undefined): void;
60
+ _loaded: InstanceType<TMC> | InstanceType<TMC>[];
61
+ /** @returns {InstanceType<TMC> | InstanceType<TMC>[] | undefined} */
62
+ getLoadedOrUndefined(): InstanceType<TMC> | InstanceType<TMC>[] | undefined;
56
63
  /** @returns {boolean} The loaded model or models (depending on relationship type) */
57
64
  getPreloaded(): boolean;
58
65
  /** @param {boolean} isPreloaded */
@@ -60,15 +67,19 @@ export default class VelociousDatabaseRecordBaseInstanceRelationship {
60
67
  _preloaded: boolean;
61
68
  /** @returns {string} The foreign key for this relationship */
62
69
  getForeignKey(): string;
63
- /** @returns {import("../index.js").default} model */
64
- getModel(): import("../index.js").default;
70
+ /** @returns {InstanceType<MC>} */
71
+ getModel(): InstanceType<MC>;
65
72
  /** @returns {string} The primary key for this relationship's model */
66
73
  getPrimaryKey(): string;
67
74
  /** @returns {import("../relationships/base.js").default} The relationship object that this instance relationship is based on */
68
75
  getRelationship(): import("../relationships/base.js").default;
69
- /** @returns {typeof import("../index.js").default | undefined} The model class that this instance relationship */
70
- getTargetModelClass(): typeof import("../index.js").default | undefined;
76
+ /** @returns {TMC | undefined} The model class that this instance relationship */
77
+ getTargetModelClass(): TMC | undefined;
71
78
  /** @returns {string} The type of relationship (e.g. "has_many", "belongs_to", etc.) */
72
79
  getType(): string;
73
80
  }
81
+ export type InstanceRelationshipsBaseArgs<MC extends typeof import("../index.js").default, TMC extends typeof import("../index.js").default> = {
82
+ model: InstanceType<MC>;
83
+ relationship: import("../relationships/base.js").default;
84
+ };
74
85
  //# sourceMappingURL=base.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"base.d.ts","sourceRoot":"","sources":["../../../../../src/database/record/instance-relationships/base.js"],"names":[],"mappings":"AAEA;IAIE;;;;OAIG;IACH,qCAHG;QAA4C,KAAK,EAAzC,OAAO,aAAa,EAAE,OAAO;QACoB,YAAY,EAA7D,OAAO,0BAA0B,EAAE,OAAO;KACpD,EAKA;IAZD,kCAAkC;IAClC,WADW,OAAO,GAAG,SAAS,CACT;IAQnB,gBAAmB;IACnB,qCAAkB;IAClB,yDAAgC;IAGlC;;;;OAIG;IACH,oBAHW,OAAO,aAAa,EAAE,OAAO,EAAE,GAAG,OAAO,aAAa,EAAE,OAAO,GAC7D,IAAI,CAIhB;IAED;;;;OAIG;IACH,kBAHW,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GACjB,OAAO,aAAa,EAAE,OAAO,CAIzC;IAED,kHAAkH;IAClH,eADc,OAAO,GAAG,SAAS,CACM;IAEvC;;;OAGG;IACH,8BAHW,OAAO,GACL,IAAI,CAEkD;IAEnE;;;OAGG;IACH,mBAHW,OAAO,GACL,IAAI,CAE4B;IAE7C,+EAA+E;IAC/E,YADc,OAAO,CACY;IAEjC;;;OAGG;IACH,QAFa,OAAO,CAAC,IAAI,CAAC,CAIzB;IAED,sEAAsE;IACtE,YADe,OAAO,CACqB;IAE3C,8JAA8J;IAC9J,UADc,OAAO,aAAa,EAAE,OAAO,GAAG,KAAK,CAAC,OAAO,aAAa,EAAE,OAAO,CAAC,GAAG,SAAS,CAO7F;IAED,kGAAkG;IAClG,iBADY,OAAO,aAAa,EAAE,OAAO,GAAC,KAAK,CAAC,OAAO,aAAa,EAAE,OAAO,CAAC,GAAC,SAAS,QAC/C;IAAtB,yEAAoB;IAEvC,6FAA6F;IAC7F,wBADc,OAAO,aAAa,EAAE,OAAO,GAAG,OAAO,aAAa,EAAE,OAAO,EAAE,GAAG,SAAS,CAC3C;IAE9C,qFAAqF;IACrF,gBADc,OAAO,CAC6B;IAElD,mCAAmC;IACnC,0BADY,OAAO,QACwC;IAA/B,oBAA6B;IAEzD,8DAA8D;IAC9D,iBADc,MAAM,CAC6C;IAEjE,qDAAqD;IACrD,YADc,OAAO,aAAa,EAAE,OAAO,CACX;IAEhC,sEAAsE;IACtE,iBADc,MAAM,CAC6C;IAEjE,gIAAgI;IAChI,mBADc,OAAO,0BAA0B,EAAE,OAAO,CACV;IAE9C,kHAAkH;IAClH,uBADc,cAAc,aAAa,EAAE,OAAO,GAAG,SAAS,CACe;IAE7E,uFAAuF;IACvF,WADc,MAAM,CACiC;CACtD"}
1
+ {"version":3,"file":"base.d.ts","sourceRoot":"","sources":["../../../../../src/database/record/instance-relationships/base.js"],"names":[],"mappings":"AAEA;;;;;;GAMG;AAEH;;;;GAIG;AACH,qEAHoD,EAAE,SAAzC,cAAe,aAAa,EAAE,OAAQ,EACC,GAAG,SAA1C,cAAe,aAAa,EAAE,OAAQ;IAMjD;;OAEG;IACH,qCAFW,6BAA6B,CAAC,EAAE,EAAE,GAAG,CAAC,EAMhD;IAVD,kCAAkC;IAClC,WADW,OAAO,GAAG,SAAS,CACT;IAMnB,gBAAmB;IACnB,wBAAkB;IAClB,yDAAgC;IAGlC;;;;OAIG;IACH,oBAHW,YAAY,CAAC,GAAG,CAAC,EAAE,GAAG,YAAY,CAAC,GAAG,CAAC,GACrC,IAAI,CAIhB;IAED;;;;OAIG;IACH,kBAHW,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GACjB,YAAY,CAAC,GAAG,CAAC,CAI7B;IAED,kHAAkH;IAClH,eADc,OAAO,GAAG,SAAS,CACM;IAEvC;;;OAGG;IACH,8BAHW,OAAO,GACL,IAAI,CAEkD;IAEnE;;;OAGG;IACH,mBAHW,OAAO,GACL,IAAI,CAE4B;IAE7C,+EAA+E;IAC/E,YADc,OAAO,CACY;IAEjC;;;OAGG;IACH,QAFa,OAAO,CAAC,IAAI,CAAC,CAIzB;IAED,sEAAsE;IACtE,YADe,OAAO,CACqB;IAE3C,sIAAsI;IACtI,UADc,YAAY,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC,YAAY,CAAC,GAAG,CAAC,CAAC,GAAG,SAAS,CAOrE;IAED,8EAA8E;IAC9E,iBADY,YAAY,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC,YAAY,CAAC,GAAG,CAAC,CAAC,GAAG,SAAS,QAC3B;IAAtB,iDAAoB;IAEvC,qEAAqE;IACrE,wBADc,YAAY,CAAC,GAAG,CAAC,GAAG,YAAY,CAAC,GAAG,CAAC,EAAE,GAAG,SAAS,CACnB;IAE9C,qFAAqF;IACrF,gBADc,OAAO,CAC6B;IAElD,mCAAmC;IACnC,0BADY,OAAO,QACwC;IAA/B,oBAA6B;IAEzD,8DAA8D;IAC9D,iBADc,MAAM,CAC6C;IAEjE,kCAAkC;IAClC,YADc,YAAY,CAAC,EAAE,CAAC,CACE;IAEhC,sEAAsE;IACtE,iBADc,MAAM,CAC6C;IAEjE,gIAAgI;IAChI,mBADc,OAAO,0BAA0B,EAAE,OAAO,CACV;IAE9C,iFAAiF;IACjF,uBADc,GAAG,GAAG,SAAS,CAK5B;IAED,uFAAuF;IACvF,WADc,MAAM,CACiC;CACtD;0CAlHmD,EAAE,SAAzC,cAAe,aAAa,EAAE,OAAQ,EACC,GAAG,SAA1C,cAAe,aAAa,EAAE,OAAQ;WAErC,YAAY,CAAC,EAAE,CAAC;kBAChB,OAAO,0BAA0B,EAAE,OAAO"}
@@ -1,11 +1,21 @@
1
1
  // @ts-check
2
+ /**
3
+ * @template {typeof import("../index.js").default} MC
4
+ * @template {typeof import("../index.js").default} TMC
5
+ * @typedef {object} InstanceRelationshipsBaseArgs
6
+ * @property {InstanceType<MC>} model
7
+ @property {import("../relationships/base.js").default} relationship
8
+ */
9
+ /**
10
+ * A generic query over some model type.
11
+ * @template {typeof import("../index.js").default} MC
12
+ * @template {typeof import("../index.js").default} TMC
13
+ */
2
14
  export default class VelociousDatabaseRecordBaseInstanceRelationship {
3
15
  /** @type {boolean | undefined} */
4
16
  _autoSave = undefined;
5
17
  /**
6
- * @param {object} args
7
- * @param {import("../index.js").default} args.model
8
- * @param {import("../relationships/base.js").default} args.relationship
18
+ * @param {InstanceRelationshipsBaseArgs<MC, TMC>} args
9
19
  */
10
20
  constructor({ model, relationship }) {
11
21
  this._dirty = false;
@@ -14,7 +24,7 @@ export default class VelociousDatabaseRecordBaseInstanceRelationship {
14
24
  }
15
25
  /**
16
26
  * @abstract
17
- * @param {import("../index.js").default[] | import("../index.js").default} models
27
+ * @param {InstanceType<TMC>[] | InstanceType<TMC>} models
18
28
  * @returns {void}
19
29
  */
20
30
  addToLoaded(models) {
@@ -23,7 +33,7 @@ export default class VelociousDatabaseRecordBaseInstanceRelationship {
23
33
  /**
24
34
  * @abstract
25
35
  * @param {Record<string, any>} attributes
26
- * @returns {import("../index.js").default}
36
+ * @returns {InstanceType<TMC>}
27
37
  */
28
38
  build(attributes) {
29
39
  throw new Error("'build' not implemented");
@@ -51,16 +61,16 @@ export default class VelociousDatabaseRecordBaseInstanceRelationship {
51
61
  }
52
62
  /** @returns {boolean} Whether the relationship has been preloaded */
53
63
  isLoaded() { return Boolean(this._loaded); }
54
- /** @returns {import("../index.js").default | Array<import("../index.js").default> | undefined} The loaded model or models (depending on relationship type) */
64
+ /** @returns {InstanceType<TMC> | Array<InstanceType<TMC>> | undefined} The loaded model or models (depending on relationship type) */
55
65
  loaded() {
56
66
  if (!this._preloaded && this.model.isPersisted()) {
57
67
  throw new Error(`${this.model.constructor.name}#${this.relationship.getRelationshipName()} hasn't been preloaded`);
58
68
  }
59
69
  return this._loaded;
60
70
  }
61
- /** @param {import("../index.js").default|Array<import("../index.js").default>|undefined} model */
71
+ /** @param {InstanceType<TMC> | Array<InstanceType<TMC>> | undefined} model */
62
72
  setLoaded(model) { this._loaded = model; }
63
- /** @returns {import("../index.js").default | import("../index.js").default[] | undefined} */
73
+ /** @returns {InstanceType<TMC> | InstanceType<TMC>[] | undefined} */
64
74
  getLoadedOrUndefined() { return this._loaded; }
65
75
  /** @returns {boolean} The loaded model or models (depending on relationship type) */
66
76
  getPreloaded() { return this._preloaded || false; }
@@ -68,14 +78,17 @@ export default class VelociousDatabaseRecordBaseInstanceRelationship {
68
78
  setPreloaded(isPreloaded) { this._preloaded = isPreloaded; }
69
79
  /** @returns {string} The foreign key for this relationship */
70
80
  getForeignKey() { return this.getRelationship().getForeignKey(); }
71
- /** @returns {import("../index.js").default} model */
81
+ /** @returns {InstanceType<MC>} */
72
82
  getModel() { return this.model; }
73
83
  /** @returns {string} The primary key for this relationship's model */
74
84
  getPrimaryKey() { return this.getRelationship().getPrimaryKey(); }
75
85
  /** @returns {import("../relationships/base.js").default} The relationship object that this instance relationship is based on */
76
86
  getRelationship() { return this.relationship; }
77
- /** @returns {typeof import("../index.js").default | undefined} The model class that this instance relationship */
78
- getTargetModelClass() { return this.getRelationship().getTargetModelClass(); }
87
+ /** @returns {TMC | undefined} The model class that this instance relationship */
88
+ getTargetModelClass() {
89
+ const TargetModelClass = /** @type {TMC} */ (this.getRelationship().getTargetModelClass());
90
+ return TargetModelClass;
91
+ }
79
92
  /** @returns {string} The type of relationship (e.g. "has_many", "belongs_to", etc.) */
80
93
  getType() { return this.getRelationship().getType(); }
81
94
  }
@@ -1,4 +1,14 @@
1
- export default class VelociousDatabaseRecordBelongsToInstanceRelationship extends BaseInstanceRelationship {
1
+ /**
2
+ * A generic query over some model type.
3
+ * @template {typeof import("../index.js").default} MC
4
+ * @template {typeof import("../index.js").default} TMC
5
+ */
6
+ export default class VelociousDatabaseRecordBelongsToInstanceRelationship<MC extends typeof import("../index.js").default, TMC extends typeof import("../index.js").default> extends BaseInstanceRelationship<any, any> {
7
+ /**
8
+ * @param {Record<string, any>} data
9
+ * @returns {InstanceType<TMC>}
10
+ */
11
+ build(data: Record<string, any>): InstanceType<TMC>;
2
12
  }
3
13
  import BaseInstanceRelationship from "./base.js";
4
14
  //# sourceMappingURL=belongs-to.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"belongs-to.d.ts","sourceRoot":"","sources":["../../../../../src/database/record/instance-relationships/belongs-to.js"],"names":[],"mappings":"AAIA;CAgCC;qCAlCoC,WAAW"}
1
+ {"version":3,"file":"belongs-to.d.ts","sourceRoot":"","sources":["../../../../../src/database/record/instance-relationships/belongs-to.js"],"names":[],"mappings":"AAIA;;;;GAIG;AACH,0EAHoD,EAAE,SAAzC,cAAe,aAAa,EAAE,OAAQ,EACC,GAAG,SAA1C,cAAe,aAAa,EAAE,OAAQ;IAUjD;;;OAGG;IACH,YAHW,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GACjB,YAAY,CAAC,GAAG,CAAC,CAY7B;CAiBF;qCA9CoC,WAAW"}
@@ -1,15 +1,26 @@
1
1
  // @ts-check
2
2
  import BaseInstanceRelationship from "./base.js";
3
+ /**
4
+ * A generic query over some model type.
5
+ * @template {typeof import("../index.js").default} MC
6
+ * @template {typeof import("../index.js").default} TMC
7
+ */
3
8
  export default class VelociousDatabaseRecordBelongsToInstanceRelationship extends BaseInstanceRelationship {
9
+ /**
10
+ * @param {import("./base.js").InstanceRelationshipsBaseArgs<MC, TMC>} args
11
+ */
12
+ constructor(args) {
13
+ super(args);
14
+ }
4
15
  /**
5
16
  * @param {Record<string, any>} data
6
- * @returns {import("../index.js").default}
17
+ * @returns {InstanceType<TMC>}
7
18
  */
8
19
  build(data) {
9
- const TargetModelClass = this.getTargetModelClass();
20
+ const TargetModelClass = /** @type {TMC} */ (this.getTargetModelClass());
10
21
  if (!TargetModelClass)
11
22
  throw new Error("Can't build a new record without a target model");
12
- const newInstance = new TargetModelClass(data);
23
+ const newInstance = /** @type {InstanceType<TMC>} */ (new TargetModelClass(data));
13
24
  this._loaded = newInstance;
14
25
  return newInstance;
15
26
  }
@@ -1,8 +1,28 @@
1
- export default class VelociousDatabaseRecordHasManyInstanceRelationship extends BaseInstanceRelationship {
1
+ /**
2
+ * A generic query over some model type.
3
+ * @template {typeof import("../index.js").default} MC
4
+ * @template {typeof import("../index.js").default} TMC
5
+ */
6
+ export default class VelociousDatabaseRecordHasManyInstanceRelationship<MC extends typeof import("../index.js").default, TMC extends typeof import("../index.js").default> extends BaseInstanceRelationship<any, any> {
2
7
  /**
3
- * @param {import("../index.js").default[]} models
8
+ * @param {Record<string, any>} data
9
+ * @returns {InstanceType<TMC>}
4
10
  */
5
- setLoaded(models: import("../index.js").default[]): void;
11
+ build(data: Record<string, any>): InstanceType<TMC>;
12
+ /**
13
+ * @returns {Array<InstanceType<TMC>>} The loaded model or models (depending on relationship type)
14
+ */
15
+ loaded(): Array<InstanceType<TMC>>;
16
+ /**
17
+ * @param {InstanceType<MC>[] | InstanceType<MC>} models
18
+ * @returns {void}
19
+ */
20
+ addToLoaded(models: InstanceType<MC>[] | InstanceType<MC>): void;
21
+ /**
22
+ * @param {InstanceType<TMC>[]} models
23
+ * @returns {void}
24
+ */
25
+ setLoaded(models: InstanceType<TMC>[]): void;
6
26
  }
7
27
  import BaseInstanceRelationship from "./base.js";
8
28
  //# sourceMappingURL=has-many.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"has-many.d.ts","sourceRoot":"","sources":["../../../../../src/database/record/instance-relationships/has-many.js"],"names":[],"mappings":"AAIA;IAuGE;;OAEG;IACH,kBAFW,OAAO,aAAa,EAAE,OAAO,EAAE,QAMzC;CACF;qCAjHoC,WAAW"}
1
+ {"version":3,"file":"has-many.d.ts","sourceRoot":"","sources":["../../../../../src/database/record/instance-relationships/has-many.js"],"names":[],"mappings":"AAIA;;;;GAIG;AACH,wEAHoD,EAAE,SAAzC,cAAe,aAAa,EAAE,OAAQ,EACC,GAAG,SAA1C,cAAe,aAAa,EAAE,OAAQ;IAUjD;;;OAGG;IACH,YAHW,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GACjB,YAAY,CAAC,GAAG,CAAC,CAmC7B;IAsBD;;OAEG;IACH,UAFa,KAAK,CAAC,YAAY,CAAC,GAAG,CAAC,CAAC,CAYpC;IAED;;;OAGG;IACH,oBAHW,YAAY,CAAC,EAAE,CAAC,EAAE,GAAG,YAAY,CAAC,EAAE,CAAC,GACnC,IAAI,CAwBhB;IAED;;;OAGG;IACH,kBAHW,YAAY,CAAC,GAAG,CAAC,EAAE,GACjB,IAAI,CAMhB;CACF;qCA9HoC,WAAW"}
@@ -1,9 +1,20 @@
1
1
  // @ts-check
2
2
  import BaseInstanceRelationship from "./base.js";
3
+ /**
4
+ * A generic query over some model type.
5
+ * @template {typeof import("../index.js").default} MC
6
+ * @template {typeof import("../index.js").default} TMC
7
+ */
3
8
  export default class VelociousDatabaseRecordHasManyInstanceRelationship extends BaseInstanceRelationship {
9
+ /**
10
+ * @param {import("./base.js").InstanceRelationshipsBaseArgs<MC, TMC>} args
11
+ */
12
+ constructor(args) {
13
+ super(args);
14
+ }
4
15
  /**
5
16
  * @param {Record<string, any>} data
6
- * @returns {import("../index.js").default}
17
+ * @returns {InstanceType<TMC>}
7
18
  */
8
19
  build(data) {
9
20
  // Spawn new model of the targeted class
@@ -48,7 +59,7 @@ export default class VelociousDatabaseRecordHasManyInstanceRelationship extends
48
59
  this.setPreloaded(true);
49
60
  }
50
61
  /**
51
- * @returns {import("../index.js").default | Array<import("../index.js").default> | undefined} The loaded model or models (depending on relationship type)
62
+ * @returns {Array<InstanceType<TMC>>} The loaded model or models (depending on relationship type)
52
63
  */
53
64
  loaded() {
54
65
  if (!this._preloaded && this.model.isPersisted()) {
@@ -60,7 +71,7 @@ export default class VelociousDatabaseRecordHasManyInstanceRelationship extends
60
71
  return this._loaded;
61
72
  }
62
73
  /**
63
- * @param {import("../index.js").default[] | import("../index.js").default} models
74
+ * @param {InstanceType<MC>[] | InstanceType<MC>} models
64
75
  * @returns {void}
65
76
  */
66
77
  addToLoaded(models) {
@@ -93,7 +104,8 @@ export default class VelociousDatabaseRecordHasManyInstanceRelationship extends
93
104
  }
94
105
  }
95
106
  /**
96
- * @param {import("../index.js").default[]} models
107
+ * @param {InstanceType<TMC>[]} models
108
+ * @returns {void}
97
109
  */
98
110
  setLoaded(models) {
99
111
  if (!Array.isArray(models))
@@ -1,7 +1,24 @@
1
- export default class VelociousDatabaseRecordHasOneInstanceRelationship extends BaseInstanceRelationship {
2
- /** @type {import("../index.js").default | undefined} */
3
- _loaded: import("../index.js").default | undefined;
4
- getLoadedOrUndefined(): import("../index.js").default;
1
+ /**
2
+ * A generic query over some model type.
3
+ * @template {typeof import("../index.js").default} MC
4
+ * @template {typeof import("../index.js").default} TMC
5
+ */
6
+ export default class VelociousDatabaseRecordHasOneInstanceRelationship<MC extends typeof import("../index.js").default, TMC extends typeof import("../index.js").default> extends BaseInstanceRelationship<any, any> {
7
+ /** @type {InstanceType<TMC> | undefined} */
8
+ _loaded: InstanceType<TMC> | undefined;
9
+ /**
10
+ * @param {Record<string, any>} data
11
+ * @returns {InstanceType<TMC>}
12
+ */
13
+ build(data: Record<string, any>): InstanceType<TMC>;
14
+ /**
15
+ * @returns {InstanceType<TMC> | Array<InstanceType<TMC>> | undefined} The loaded model or models (depending on relationship type)
16
+ */
17
+ loaded(): InstanceType<TMC> | Array<InstanceType<TMC>> | undefined;
18
+ getLoadedOrUndefined(): InstanceType<TMC>;
19
+ /** @param {InstanceType<TMC> | Array<InstanceType<TMC>>} model */
20
+ setLoaded(model: InstanceType<TMC> | Array<InstanceType<TMC>>): void;
21
+ getTargetModelClass(): typeof import("../index.js").default;
5
22
  }
6
23
  import BaseInstanceRelationship from "./base.js";
7
24
  //# sourceMappingURL=has-one.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"has-one.d.ts","sourceRoot":"","sources":["../../../../../src/database/record/instance-relationships/has-one.js"],"names":[],"mappings":"AAIA;IACE,wDAAwD;IACxD,SADW,OAAO,aAAa,EAAE,OAAO,GAAG,SAAS,CACjC;IAiDnB,sDAA8C;CAU/C;qCA/DoC,WAAW"}
1
+ {"version":3,"file":"has-one.d.ts","sourceRoot":"","sources":["../../../../../src/database/record/instance-relationships/has-one.js"],"names":[],"mappings":"AAIA;;;;GAIG;AACH,uEAHoD,EAAE,SAAzC,cAAe,aAAa,EAAE,OAAQ,EACC,GAAG,SAA1C,cAAe,aAAa,EAAE,OAAQ;IAUjD,4CAA4C;IAC5C,SADW,YAAY,CAAC,GAAG,CAAC,GAAG,SAAS,CACrB;IAEnB;;;OAGG;IACH,YAHW,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GACjB,YAAY,CAAC,GAAG,CAAC,CAY7B;IAsBD;;OAEG;IACH,UAFa,YAAY,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC,YAAY,CAAC,GAAG,CAAC,CAAC,GAAG,SAAS,CAQpE;IAED,0CAA8C;IAE9C,kEAAkE;IAClE,iBADY,YAAY,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC,YAAY,CAAC,GAAG,CAAC,CAAC,QAKvD;IAED,4DAAwE;CACzE;qCA3EoC,WAAW"}
@@ -1,17 +1,28 @@
1
1
  // @ts-check
2
2
  import BaseInstanceRelationship from "./base.js";
3
+ /**
4
+ * A generic query over some model type.
5
+ * @template {typeof import("../index.js").default} MC
6
+ * @template {typeof import("../index.js").default} TMC
7
+ */
3
8
  export default class VelociousDatabaseRecordHasOneInstanceRelationship extends BaseInstanceRelationship {
4
- /** @type {import("../index.js").default | undefined} */
9
+ /**
10
+ * @param {import("./base.js").InstanceRelationshipsBaseArgs<MC, TMC>} args
11
+ */
12
+ constructor(args) {
13
+ super(args);
14
+ }
15
+ /** @type {InstanceType<TMC> | undefined} */
5
16
  _loaded = undefined;
6
17
  /**
7
18
  * @param {Record<string, any>} data
8
- * @returns {import("../index.js").default}
19
+ * @returns {InstanceType<TMC>}
9
20
  */
10
21
  build(data) {
11
- const TargetModelClass = this.getTargetModelClass();
22
+ const TargetModelClass = /** @type {TMC} */ (this.getTargetModelClass());
12
23
  if (!TargetModelClass)
13
24
  throw new Error("Can't build a new record without a target model class");
14
- const newInstance = new TargetModelClass(data);
25
+ const newInstance = /** @type {InstanceType<TMC>} */ (new TargetModelClass(data));
15
26
  this._loaded = newInstance;
16
27
  return newInstance;
17
28
  }
@@ -19,19 +30,19 @@ export default class VelociousDatabaseRecordHasOneInstanceRelationship extends B
19
30
  const foreignKey = this.getForeignKey();
20
31
  const primaryKey = this.getPrimaryKey();
21
32
  const primaryModelID = this.getModel().readColumn(primaryKey);
22
- const TargetModelClass = this.getTargetModelClass();
33
+ const TargetModelClass = /** @type {TMC} */ (this.getTargetModelClass());
23
34
  if (!TargetModelClass)
24
35
  throw new Error("Can't load without a target model class");
25
36
  /** @type {Record<string, any>} */
26
37
  const whereArgs = {};
27
38
  whereArgs[foreignKey] = primaryModelID;
28
- const foreignModel = await TargetModelClass.where(whereArgs).first();
39
+ const foreignModel = /** @type {InstanceType<TMC>} */ (await TargetModelClass.where(whereArgs).first());
29
40
  this.setLoaded(foreignModel);
30
41
  this.setDirty(false);
31
42
  this.setPreloaded(true);
32
43
  }
33
44
  /**
34
- * @returns {import("../index.js").default | Array<import("../index.js").default> | undefined} The loaded model or models (depending on relationship type)
45
+ * @returns {InstanceType<TMC> | Array<InstanceType<TMC>> | undefined} The loaded model or models (depending on relationship type)
35
46
  */
36
47
  loaded() {
37
48
  if (!this._preloaded && this.model.isPersisted()) {
@@ -40,7 +51,7 @@ export default class VelociousDatabaseRecordHasOneInstanceRelationship extends B
40
51
  return this._loaded;
41
52
  }
42
53
  getLoadedOrUndefined() { return this._loaded; }
43
- /** @param {import("../index.js").default|Array<import("../index.js").default>} model */
54
+ /** @param {InstanceType<TMC> | Array<InstanceType<TMC>>} model */
44
55
  setLoaded(model) {
45
56
  if (Array.isArray(model))
46
57
  throw new Error(`Argument given to setLoaded was an array: ${typeof model}`);
@@ -1 +1 @@
1
- {"version":3,"file":"base-models.d.ts","sourceRoot":"","sources":["../../../../../../../src/environment-handlers/node/cli/commands/generate/base-models.js"],"names":[],"mappings":"AAKA;IACE,yBA4OC;IAED;;;OAGG;IACH,4BAHW,OAAO,gDAAgD,EAAE,OAAO,GAC9D,MAAM,GAAG,SAAS,CAkB9B;CACF;wBAzQuB,oCAAoC"}
1
+ {"version":3,"file":"base-models.d.ts","sourceRoot":"","sources":["../../../../../../../src/environment-handlers/node/cli/commands/generate/base-models.js"],"names":[],"mappings":"AAKA;IACE,yBAsPC;IAED;;;OAGG;IACH,4BAHW,OAAO,gDAAgD,EAAE,OAAO,GAC9D,MAAM,GAAG,SAAS,CAkB9B;CACF;wBAnRuB,oCAAoC"}
@@ -5,22 +5,31 @@ import * as inflection from "inflection";
5
5
  export default class DbGenerateModel extends BaseCommand {
6
6
  async execute() {
7
7
  await this.getConfiguration().initializeModels();
8
- const modelsDir = `${process.cwd()}/src/model-bases`;
8
+ const modelsDir = `${process.cwd()}/src/models`;
9
+ const baseModelsDir = `${process.cwd()}/src/model-bases`;
9
10
  const modelClasses = this.getConfiguration().getModelClasses();
10
11
  let devMode = false;
11
- if (modelsDir.endsWith("velocious/spec/dummy/src/model-bases")) {
12
+ if (baseModelsDir.endsWith("velocious/spec/dummy/src/model-bases")) {
12
13
  devMode = true;
13
14
  }
14
- if (!await fileExists(modelsDir)) {
15
- await fs.mkdir(modelsDir, { recursive: true });
15
+ if (!await fileExists(baseModelsDir)) {
16
+ await fs.mkdir(baseModelsDir, { recursive: true });
16
17
  }
17
18
  for (const modelClassName in modelClasses) {
18
19
  const modelClass = modelClasses[modelClassName];
19
20
  const modelName = inflection.dasherize(modelClassName);
20
21
  const modelNameCamelized = inflection.camelize(modelName.replaceAll("-", "_"));
21
22
  const modelBaseFileName = `${inflection.dasherize(inflection.underscore(modelName))}.js`;
22
- const modelPath = `${modelsDir}/${modelBaseFileName}`;
23
+ const modelPath = `${baseModelsDir}/${modelBaseFileName}`;
23
24
  console.log(`create src/model-bases/${modelBaseFileName}`);
25
+ const sourceModelFullFilePath = `${modelsDir}/${modelBaseFileName}`;
26
+ let sourceModelFilePath;
27
+ if (await fileExists(sourceModelFullFilePath)) {
28
+ sourceModelFilePath = `../models/${modelBaseFileName}`;
29
+ }
30
+ else {
31
+ sourceModelFilePath = "velocious/dist/src/database/record/index.js";
32
+ }
24
33
  let fileContent = "";
25
34
  let velociousPath;
26
35
  if (devMode) {
@@ -169,7 +178,7 @@ export default class DbGenerateModel extends BaseCommand {
169
178
  recordImport = `${velociousPath}/database/record/index.js`;
170
179
  }
171
180
  fileContent += " /**\n";
172
- fileContent += ` * @returns {import("${hasManyRelationFilePath}").default}\n`;
181
+ fileContent += ` * @returns {import("${hasManyRelationFilePath}").default<typeof import("${sourceModelFilePath}").default, typeof import("${recordImport}").default>}\n`;
173
182
  fileContent += " */\n";
174
183
  fileContent += ` ${relationship.getRelationshipName()}() { return /** @type {import("${hasManyRelationFilePath}").default} */ (this.getRelationshipByName("${relationship.getRelationshipName()}")) }\n`;
175
184
  fileContent += "\n";
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "velocious": "dist/bin/velocious.js"
4
4
  },
5
5
  "name": "velocious",
6
- "version": "1.0.113",
6
+ "version": "1.0.115",
7
7
  "main": "dist/index.js",
8
8
  "types": "dist/index.d.ts",
9
9
  "files": ["dist/**"],
@@ -11,7 +11,7 @@
11
11
  "build": "rm -rf dist && tsc -p tsconfig.build.json && chmod +x dist/bin/velocious.js",
12
12
  "lint": "eslint",
13
13
  "test": "VELOCIOUS_TEST_DIR=../ cd spec/dummy && npx velocious test",
14
- "prepublishOnly": "npm run build",
14
+ "prepublishOnly": "npm run build && chmod +x dist/bin/velocious.js",
15
15
  "typecheck": "tsc --noEmit",
16
16
  "velocious": "asd",
17
17
  "watch": "tsc -p tsconfig.build.json -w"