pangea-server 1.0.63 → 1.0.65

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.
@@ -12,7 +12,8 @@ type FindOneOptions = {
12
12
  order?: Order;
13
13
  paranoid?: boolean;
14
14
  };
15
- type AggregateOneOptions = {
15
+ type AggregateOneOptions<BM extends BaseModel> = {
16
+ where?: Where<BM>;
16
17
  paranoid?: boolean;
17
18
  };
18
19
  type FindManyOptions<BM extends BaseModel> = {
@@ -36,7 +37,7 @@ export declare class Db {
36
37
  constructor(tx: Tx);
37
38
  findOneOrNull<BM extends BaseModel>(model: BaseModelCtor<BM>, filters: Filters<BM>, options?: FindOneOptions): Promise<BM | null>;
38
39
  findOne<BM extends BaseModel>(model: BaseModelCtor<BM>, filters: Filters<BM>, options?: FindOneOptions): Promise<BM>;
39
- aggregateOne<BM extends BaseModel>(model: BaseModelCtor<BM>, attributes: Attributes, options?: AggregateOneOptions): Promise<BM | null>;
40
+ aggregateOne<BM extends BaseModel>(model: BaseModelCtor<BM>, attributes: Attributes, options?: AggregateOneOptions<BM>): Promise<BM | null>;
40
41
  private __getFindOneBaseOptions;
41
42
  findMany<BM extends BaseModel>(model: BaseModelCtor<BM>, options?: FindManyPagedOptions<BM>): Promise<BM[]>;
42
43
  count<BM extends BaseModel>(model: BaseModelCtor<BM>, options?: FindManyOptions<BM>): Promise<number>;
@@ -37,7 +37,7 @@ class Db {
37
37
  return model.findOne({
38
38
  ...baseOptions,
39
39
  attributes: getFinalAttributes(model, attributes),
40
- ...getInclude(model, { attributes }),
40
+ ...getInclude(model, { attributes, where: options.where }),
41
41
  });
42
42
  }
43
43
  __getFindOneBaseOptions(paranoid) {
@@ -74,15 +74,16 @@ class Db {
74
74
  return { instances, totalCount: instances.length };
75
75
  }
76
76
  async aggregateMany(model, config, options = {}) {
77
- const baseOptions = this.__getFindManyBaseOptions(model, options);
77
+ const { attributes, group } = config;
78
+ const baseOptions = this.__getFindManyBaseOptions(model, { ...options, attributes });
78
79
  return model.findAll({
79
80
  ...baseOptions,
80
- attributes: getFinalAttributes(model, config.attributes),
81
- ...(config.group && { group: config.group.map((field) => formatField(model.name, field)) }),
81
+ attributes: getFinalAttributes(model, attributes),
82
+ ...(group && { group: group.map((field) => formatField(model.name, field)) }),
82
83
  });
83
84
  }
84
85
  __getFindManyBaseOptions(model, options = {}) {
85
- const { where, searchFields, search, order, paranoid = true } = options;
86
+ const { attributes, where, searchFields, search, order, paranoid = true } = options;
86
87
  let searchWhere;
87
88
  if (searchFields?.length && search) {
88
89
  const searchWords = search.split(/\s+/).filter(Boolean);
@@ -96,7 +97,7 @@ class Db {
96
97
  };
97
98
  }
98
99
  return {
99
- ...getInclude(model, { where: { ...where, ...searchWhere } }),
100
+ ...getInclude(model, { attributes, where: { ...where, ...searchWhere } }),
100
101
  order: getFinalOrder(order),
101
102
  paranoid,
102
103
  subQuery: false,
@@ -252,8 +253,6 @@ function getInclude(model, config = {}, relDepth = new Map()) {
252
253
  const maxDepth = rel.joinDepth;
253
254
  if (currentDepth >= maxDepth)
254
255
  continue;
255
- if (!rel.eager)
256
- continue;
257
256
  const relWhere = cleanWhere[relName];
258
257
  delete cleanWhere[relName];
259
258
  const newRelDepth = new Map(relDepth);
@@ -1,6 +1,5 @@
1
1
  import type { GetModelFn } from '../database.types';
2
2
  type RelationOptions = {
3
- eager?: boolean;
4
3
  required?: boolean;
5
4
  paranoid?: boolean;
6
5
  joinDepth?: number;
@@ -35,8 +35,8 @@ function getRelation(relationFn) {
35
35
  const { foreignKey, ...relOptions } = options;
36
36
  relationFn(getModelFn, { as: propertyName, ...(foreignKey && { foreignKey }) })(target, propertyName);
37
37
  const model = target.constructor;
38
- const { eager = relationFn !== seq.HasMany, required = relationFn === seq.BelongsTo ? !model.Columns[`${propertyName}Id`].allowNull : false, paranoid = relationFn !== seq.BelongsTo, joinDepth = 1, ...restOptions } = relOptions;
39
- model.AddRelation(propertyName, { getModelFn, eager, required, paranoid, joinDepth, ...restOptions });
38
+ const { required = relationFn === seq.BelongsTo ? !model.Columns[`${propertyName}Id`].allowNull : false, paranoid = relationFn !== seq.BelongsTo, joinDepth = 1, ...restOptions } = relOptions;
39
+ model.AddRelation(propertyName, { getModelFn, required, paranoid, joinDepth, ...restOptions });
40
40
  };
41
41
  };
42
42
  }
@@ -7,7 +7,6 @@ type Column = {
7
7
  type Columns = Record<string, Column>;
8
8
  type Relation = {
9
9
  getModelFn: GetModelFn;
10
- eager: boolean;
11
10
  required: boolean;
12
11
  paranoid: boolean;
13
12
  joinDepth: number;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "pangea-server",
3
3
  "description": "",
4
- "version": "1.0.63",
4
+ "version": "1.0.65",
5
5
  "files": [
6
6
  "dist"
7
7
  ],