pangea-server 1.0.70 → 1.0.72

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,6 +5,7 @@ export declare abstract class BaseAuth<AM extends AuthMap> {
5
5
  free(): void;
6
6
  notSetYet(): void;
7
7
  notAllowed(): void;
8
+ isUserAuth<T extends UserType<AM>>(type: T): boolean;
8
9
  getUserAuth<T extends UserType<AM>>(type: T): NonNullable<AuthUsers<AM>[T]>;
9
10
  getUsersAuth<const T extends readonly UserType<AM>[]>(types: T): { [I in keyof T]: InstanceType<AM[T[I]]> | null; };
10
11
  }
@@ -16,6 +16,9 @@ class BaseAuth {
16
16
  notAllowed() {
17
17
  helpers_1.AppError.ThrowUnauthorized();
18
18
  }
19
+ isUserAuth(type) {
20
+ return !!this.__authUsers[type];
21
+ }
19
22
  getUserAuth(type) {
20
23
  const user = this.__authUsers[type];
21
24
  if (!user)
@@ -29,15 +29,17 @@ type FindManyPagedOptions<BM extends BaseModel> = FindManyOptions<BM> & {
29
29
  };
30
30
  type AggregateManyConfig = {
31
31
  attributes: Attributes;
32
+ relations?: Record<string, BaseModelCtor>;
32
33
  group: Group;
33
34
  };
35
+ type AggregateManyOptions<BM extends BaseModel> = Omit<FindManyOptions<BM>, 'order'>;
34
36
  type Target<BM extends BaseModel> = Filters<BM> | BM;
35
37
  export declare class Db {
36
38
  private __tx?;
37
39
  constructor(tx: Tx);
38
40
  findOneOrNull<BM extends BaseModel>(model: BaseModelCtor<BM>, filters: Filters<BM>, options?: FindOneOptions): Promise<BM | null>;
39
41
  findOne<BM extends BaseModel>(model: BaseModelCtor<BM>, filters: Filters<BM>, options?: FindOneOptions): Promise<BM>;
40
- aggregateOne<BM extends BaseModel>(model: BaseModelCtor<BM>, attributes: Attributes, options?: AggregateOneOptions<BM>): Promise<BM | null>;
42
+ aggregateOne<BM extends BaseModel>(model: BaseModelCtor<BM>, attributes: Attributes, options?: AggregateOneOptions<BM>): Promise<unknown>;
41
43
  private __getFindOneBaseOptions;
42
44
  findMany<BM extends BaseModel>(model: BaseModelCtor<BM>, options?: FindManyPagedOptions<BM>): Promise<BM[]>;
43
45
  count<BM extends BaseModel>(model: BaseModelCtor<BM>, options?: FindManyOptions<BM>): Promise<number>;
@@ -45,7 +47,7 @@ export declare class Db {
45
47
  instances: BM[];
46
48
  totalCount: number;
47
49
  }>;
48
- aggregateMany<BM extends BaseModel>(model: BaseModelCtor<BM>, config: AggregateManyConfig, options?: Omit<FindManyOptions<BM>, 'order'>): Promise<BM[]>;
50
+ aggregateMany<BM extends BaseModel>(model: BaseModelCtor<BM>, config: AggregateManyConfig, options?: AggregateManyOptions<BM>): Promise<unknown[]>;
49
51
  private __getFindManyBaseOptions;
50
52
  insertOne<BM extends BaseModel>(model: BaseModelCtor<BM>, params: InsertParams<BM>): Promise<BM>;
51
53
  insertMany<BM extends BaseModel>(model: BaseModelCtor<BM>, data: InsertParams<BM>[]): Promise<number>;
@@ -38,6 +38,7 @@ class Db {
38
38
  ...baseOptions,
39
39
  attributes: getFinalAttributes(model, attributes),
40
40
  ...getInclude(model, { attributes, where: options.where }),
41
+ raw: true,
41
42
  });
42
43
  }
43
44
  __getFindOneBaseOptions(paranoid) {
@@ -74,13 +75,27 @@ class Db {
74
75
  return { instances, totalCount: instances.length };
75
76
  }
76
77
  async aggregateMany(model, config, options = {}) {
77
- const { attributes, group } = config;
78
+ const { attributes, relations = {}, group } = config;
78
79
  const baseOptions = this.__getFindManyBaseOptions(model, { ...options, attributes });
79
- return model.findAll({
80
+ const result = (await model.findAll({
80
81
  ...baseOptions,
81
82
  attributes: getFinalAttributes(model, attributes),
82
83
  ...(group && { group: group.map((field) => formatField(model.name, field)) }),
83
- });
84
+ raw: true,
85
+ }));
86
+ const relationKeys = Object.keys(relations);
87
+ if (!relationKeys.length)
88
+ return result;
89
+ for (const key of relationKeys) {
90
+ const keyId = `${key}Id`;
91
+ const ids = [...new Set(result.map((item) => item[keyId]).filter(Boolean))];
92
+ if (!ids.length)
93
+ continue;
94
+ const model = relations[key];
95
+ const instances = await this.findMany(model, { where: { id: { [_1.Ops.in]: ids } } });
96
+ result.forEach((item) => (item[key] = instances.find((instance) => instance.id === item[keyId]) || null));
97
+ }
98
+ return result;
84
99
  }
85
100
  __getFindManyBaseOptions(model, options = {}) {
86
101
  const { attributes, where, searchFields, search, order, paranoid = true } = options;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "pangea-server",
3
3
  "description": "",
4
- "version": "1.0.70",
4
+ "version": "1.0.72",
5
5
  "files": [
6
6
  "dist"
7
7
  ],