pangea-server 1.0.4 → 1.0.6

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.
@@ -4,6 +4,7 @@ export declare abstract class BaseAuth<AM extends AuthMap> {
4
4
  constructor(authUsers: AuthUsers<AM>);
5
5
  free(): void;
6
6
  notSetYet(): void;
7
+ notAllowed(): void;
7
8
  isUserAuth<T extends UserType<AM>>(type: T): NonNullable<AuthUsers<AM>[T]>;
8
9
  isAnyUserAuth<const T extends readonly UserType<AM>[]>(types: T): { [I in keyof T]: InstanceType<AM[T[I]]> | null; };
9
10
  }
@@ -13,6 +13,9 @@ class BaseAuth {
13
13
  notSetYet() {
14
14
  (0, helpers_1.printWarning)('authentication', 'auth not set yet');
15
15
  }
16
+ notAllowed() {
17
+ helpers_1.AppError.ThrowUnauthorized();
18
+ }
16
19
  isUserAuth(type) {
17
20
  const user = this.__authUsers[type];
18
21
  if (!user)
@@ -3,7 +3,7 @@ type AttributeField = string;
3
3
  type AttributeOp = 'COUNT' | 'SUM';
4
4
  type AttributeColumn = AttributeField | [AttributeOp, AttributeField];
5
5
  type AttributeAlias = string;
6
- type Attribute = [AttributeColumn, AttributeAlias];
6
+ type Attribute = AttributeField | Record<AttributeAlias, AttributeColumn>;
7
7
  type IncludeItem = {
8
8
  relation?: string;
9
9
  active?: boolean;
@@ -48,13 +48,9 @@ class Db {
48
48
  const deletedAtWhere = paranoid === 'deleted' ? { deletedAt: { [_1.Ops.not]: null } } : {};
49
49
  const baseOptions = {
50
50
  attributes: getFinalAttributes(attributes),
51
- ...getIncludeAndWhere(model, include, {
52
- ...where,
53
- ...searchWhere,
54
- ...deletedAtWhere,
55
- }),
56
- ...(group && { group }),
57
- order: [...getFinalOrder(order), ['createdAt', 'DESC']],
51
+ ...getIncludeAndWhere(model, include, { ...where, ...searchWhere, ...deletedAtWhere }),
52
+ ...(group && { group: group.map(pangea_helpers_1.camelToSnake) }),
53
+ order: [...getFinalOrder(order), ...(!group ? [['createdAt', 'DESC']] : [])],
58
54
  paranoid: paranoid === 'active',
59
55
  subQuery: false,
60
56
  transaction: this.__tx,
@@ -71,10 +67,7 @@ class Db {
71
67
  limit: pageSize,
72
68
  });
73
69
  const ids = idRows.map((row) => row.id);
74
- return model.findAll({
75
- ...baseOptions,
76
- where: { id: { [_1.Ops.in]: ids } },
77
- });
70
+ return model.findAll({ ...baseOptions, where: { id: { [_1.Ops.in]: ids } } });
78
71
  })(),
79
72
  model.count({ ...baseOptions, col: 'id', distinct: true }),
80
73
  ]);
@@ -92,11 +85,7 @@ class Db {
92
85
  }
93
86
  insertMany(model, data, options = {}) {
94
87
  return handleDbError(async () => {
95
- const newInstances = await model.bulkCreate(data, {
96
- ...options,
97
- validate: true,
98
- transaction: this.__tx,
99
- });
88
+ const newInstances = await model.bulkCreate(data, { ...options, validate: true, transaction: this.__tx });
100
89
  return newInstances.length;
101
90
  });
102
91
  }
@@ -174,9 +163,12 @@ exports.Db = Db;
174
163
  function getFinalAttributes(attributes) {
175
164
  if (!attributes)
176
165
  return;
177
- return attributes.map(([column, alias]) => {
166
+ return attributes.map((attribute) => {
167
+ if (typeof attribute === 'string')
168
+ return [(0, sequelize_1.col)((0, pangea_helpers_1.camelToSnake)(attribute)), attribute];
169
+ const [alias, column] = Object.entries(attribute)[0];
178
170
  if (typeof column === 'string')
179
- return [(0, sequelize_1.col)(column), alias];
171
+ return [(0, sequelize_1.col)((0, pangea_helpers_1.camelToSnake)(column)), alias];
180
172
  const [op, field] = column;
181
173
  return [(0, sequelize_1.fn)(op, (0, sequelize_1.col)(field)), alias];
182
174
  });
@@ -6,7 +6,7 @@ declare global {
6
6
  type Req = Request;
7
7
  type Res = Response;
8
8
  type Next = NextFunction;
9
- type ReqHeaders = Req['headers'] & {
9
+ type ReqHeaders = Record<string, string | undefined> & {
10
10
  language: string;
11
11
  };
12
12
  interface Ctx<V extends RouteValidator> {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "pangea-server",
3
3
  "description": "",
4
- "version": "1.0.4",
4
+ "version": "1.0.6",
5
5
  "files": [
6
6
  "dist"
7
7
  ],