pangea-server 1.0.62 → 1.0.63

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.
@@ -78,9 +78,7 @@ class Db {
78
78
  return model.findAll({
79
79
  ...baseOptions,
80
80
  attributes: getFinalAttributes(model, config.attributes),
81
- ...(config.group && {
82
- group: config.group.map((field) => (field.includes('.') ? field : `${model.name}.${(0, pangea_helpers_1.camelToSnake)(field)}`)),
83
- }),
81
+ ...(config.group && { group: config.group.map((field) => formatField(model.name, field)) }),
84
82
  });
85
83
  }
86
84
  __getFindManyBaseOptions(model, options = {}) {
@@ -198,17 +196,22 @@ class Db {
198
196
  }
199
197
  exports.Db = Db;
200
198
  // internal functions
199
+ function formatField(modelName, field) {
200
+ if (field.includes('.')) {
201
+ const parts = field.split('.');
202
+ const last = parts.pop();
203
+ return [...parts, (0, pangea_helpers_1.camelToSnake)(last)].join('.');
204
+ }
205
+ return `${modelName}.${(0, pangea_helpers_1.camelToSnake)(field)}`;
206
+ }
201
207
  function getFinalAttributes(model, attributes) {
202
208
  if (!attributes)
203
209
  return;
204
210
  return Object.entries(attributes).map(([alias, column]) => {
205
- if (typeof column === 'string') {
206
- const field = column.includes('.') ? column : `${model.name}.${(0, pangea_helpers_1.camelToSnake)(column)}`;
207
- return [(0, sequelize_1.col)(field), alias];
208
- }
209
- const [op, fieldName] = column;
210
- const field = fieldName.includes('.') ? fieldName : `${model.name}.${(0, pangea_helpers_1.camelToSnake)(fieldName)}`;
211
- return [(0, sequelize_1.fn)(op, (0, sequelize_1.col)(field)), alias];
211
+ if (typeof column === 'string')
212
+ return [(0, sequelize_1.col)(formatField(model.name, column)), alias];
213
+ const [op, field] = column;
214
+ return [(0, sequelize_1.fn)(op, (0, sequelize_1.col)(formatField(model.name, field))), alias];
212
215
  });
213
216
  }
214
217
  function convertWhereKeys(obj) {
@@ -231,7 +234,7 @@ function convertWhereKeys(obj) {
231
234
  const parts = inner.split('.');
232
235
  if (parts.length >= 2) {
233
236
  const last = parts.pop();
234
- newKey = `$${[...parts.map((part) => (0, pangea_helpers_1.camelToSnake)(part)), (0, pangea_helpers_1.camelToSnake)(last)].join('.')}$`;
237
+ newKey = `$${[...parts, (0, pangea_helpers_1.camelToSnake)(last)].join('.')}$`;
235
238
  }
236
239
  }
237
240
  newObj[newKey] = convertWhereKeys(value);
@@ -258,7 +261,7 @@ function getInclude(model, config = {}, relDepth = new Map()) {
258
261
  const relModel = rel.getModelFn();
259
262
  includeOptions.push({
260
263
  model: relModel,
261
- as: rel.alias,
264
+ as: relName,
262
265
  attributes: !config.attributes ? undefined : [],
263
266
  required: rel.required,
264
267
  paranoid: rel.paranoid,
@@ -25,8 +25,6 @@ var __importStar = (this && this.__importStar) || function (mod) {
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
26
  exports.HasMany = exports.HasOne = exports.BelongsTo = void 0;
27
27
  const seq = __importStar(require("sequelize-typescript"));
28
- // helpers
29
- const pangea_helpers_1 = require("pangea-helpers");
30
28
  exports.BelongsTo = getRelation(seq.BelongsTo);
31
29
  exports.HasOne = getRelation(seq.HasOne);
32
30
  exports.HasMany = getRelation(seq.HasMany);
@@ -35,11 +33,10 @@ function getRelation(relationFn) {
35
33
  return function (getModelFn, options = {}) {
36
34
  return function (target, propertyName) {
37
35
  const { foreignKey, ...relOptions } = options;
38
- const alias = (0, pangea_helpers_1.camelToSnake)(propertyName);
39
- relationFn(getModelFn, { as: alias, ...(foreignKey && { foreignKey }) })(target, propertyName);
36
+ relationFn(getModelFn, { as: propertyName, ...(foreignKey && { foreignKey }) })(target, propertyName);
40
37
  const model = target.constructor;
41
38
  const { eager = relationFn !== seq.HasMany, required = relationFn === seq.BelongsTo ? !model.Columns[`${propertyName}Id`].allowNull : false, paranoid = relationFn !== seq.BelongsTo, joinDepth = 1, ...restOptions } = relOptions;
42
- model.AddRelation(propertyName, { alias, getModelFn, eager, required, paranoid, joinDepth, ...restOptions });
39
+ model.AddRelation(propertyName, { getModelFn, eager, required, paranoid, joinDepth, ...restOptions });
43
40
  };
44
41
  };
45
42
  }
@@ -6,7 +6,6 @@ type Column = {
6
6
  };
7
7
  type Columns = Record<string, Column>;
8
8
  type Relation = {
9
- alias: string;
10
9
  getModelFn: GetModelFn;
11
10
  eager: boolean;
12
11
  required: boolean;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "pangea-server",
3
3
  "description": "",
4
- "version": "1.0.62",
4
+ "version": "1.0.63",
5
5
  "files": [
6
6
  "dist"
7
7
  ],