pangea-server 1.0.48 → 1.0.50

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.
@@ -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 = AttributeField | Record<AttributeAlias, AttributeColumn>;
6
+ type Attributes = Record<AttributeAlias, AttributeColumn>;
7
7
  type IncludeItem = {
8
8
  relation?: string;
9
9
  active?: boolean;
@@ -14,13 +14,13 @@ type Group = string[];
14
14
  type Order = Record<string, 'asc' | 'desc'>;
15
15
  type FindOneOptions = {
16
16
  scopes?: string[];
17
- attributes?: Attribute[];
17
+ attributes?: Attributes;
18
18
  include?: IncludeItem[];
19
19
  order?: Order;
20
20
  paranoid?: boolean;
21
21
  };
22
22
  type FindManyOptions<BM extends BaseModel> = {
23
- attributes?: Attribute[];
23
+ attributes?: Attributes;
24
24
  include?: IncludeItem[];
25
25
  where?: Where<BM>;
26
26
  searchFields?: string[];
@@ -26,7 +26,7 @@ class Db {
26
26
  }
27
27
  return scopedModel.findOne({
28
28
  ...baseOptions,
29
- ...getIncludeAndWhere(model, include, filters),
29
+ ...getIncludeAndWhere(model, include, undefined, filters),
30
30
  order: getFinalOrder(order),
31
31
  });
32
32
  }
@@ -86,7 +86,7 @@ class Db {
86
86
  const deletedAtWhere = paranoid === 'deleted' ? { deletedAt: { [_1.Ops.not]: null } } : {};
87
87
  return {
88
88
  attributes: getFinalAttributes(attributes),
89
- ...getIncludeAndWhere(model, include, { ...where, ...searchWhere, ...deletedAtWhere }),
89
+ ...getIncludeAndWhere(model, include, { withoutAttributes: !!attributes }, { ...where, ...searchWhere, ...deletedAtWhere }),
90
90
  ...(group && { group: group.map(pangea_helpers_1.camelToSnake) }),
91
91
  order: [...getFinalOrder(order), ...(!group ? [['createdAt', 'DESC']] : [])],
92
92
  paranoid: paranoid === 'active',
@@ -190,22 +190,12 @@ exports.Db = Db;
190
190
  function getFinalAttributes(attributes) {
191
191
  if (!attributes)
192
192
  return;
193
- const attt = attributes.map((attribute) => {
194
- console.log('attribute: ', attribute);
195
- if (typeof attribute === 'string')
196
- return [(0, sequelize_1.col)((0, pangea_helpers_1.camelToSnake)(attribute)), attribute];
197
- console.log('--- [alias, column] --- ');
198
- const [alias, column] = Object.entries(attribute)[0];
199
- console.log(alias, ': ', column);
193
+ return Object.entries(attributes).map(([alias, column]) => {
200
194
  if (typeof column === 'string')
201
195
  return [(0, sequelize_1.col)((0, pangea_helpers_1.camelToSnake)(column)), alias];
202
- console.log('--- [op, field] --- ');
203
196
  const [op, field] = column;
204
- console.log(op, ': ', field);
205
- return [(0, sequelize_1.fn)(op, (0, sequelize_1.col)(field)), alias];
197
+ return [(0, sequelize_1.fn)(op, (0, sequelize_1.col)((0, pangea_helpers_1.camelToSnake)(field))), alias];
206
198
  });
207
- console.log('attt: ', attt);
208
- return attt;
209
199
  }
210
200
  function convertWhereKeys(obj) {
211
201
  if (Array.isArray(obj)) {
@@ -237,7 +227,7 @@ function convertWhereKeys(obj) {
237
227
  }
238
228
  return obj;
239
229
  }
240
- function getIncludeAndWhere(model, includeItems, where, relDepth = new Map()) {
230
+ function getIncludeAndWhere(model, includeItems, config = {}, where, relDepth = new Map()) {
241
231
  const includeOptions = [];
242
232
  const cleanWhere = { ...where };
243
233
  for (const [relName, rel] of Object.entries(model.Relations)) {
@@ -257,9 +247,10 @@ function getIncludeAndWhere(model, includeItems, where, relDepth = new Map()) {
257
247
  includeOptions.push({
258
248
  model: relModel,
259
249
  as: relName,
250
+ attributes: !config.withoutAttributes ? undefined : [],
260
251
  required: rel.required,
261
252
  paranoid: rel.paranoid,
262
- ...getIncludeAndWhere(relModel, nestedIncludeItems, relWhere, newRelDepth),
253
+ ...getIncludeAndWhere(relModel, nestedIncludeItems, config, relWhere, newRelDepth),
263
254
  });
264
255
  }
265
256
  return {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "pangea-server",
3
3
  "description": "",
4
- "version": "1.0.48",
4
+ "version": "1.0.50",
5
5
  "files": [
6
6
  "dist"
7
7
  ],