pangea-server 1.0.77 → 1.0.79

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,7 @@ async function login(authHeader, db, accessToken, userCtor, extraWhere = {}) {
12
12
  if (!username || !password)
13
13
  helpers_1.AppError.ThrowInvalidCredentials();
14
14
  const where = { ...extraWhere, username };
15
- const user = await db.findOneOrNull(userCtor, where, { scopes: ['withExcludedAttributes'] });
15
+ const user = await db.findOneOrNull(userCtor, where, { scopes: ['withHiddenAttributes'] });
16
16
  if (!user)
17
17
  helpers_1.AppError.ThrowInvalidCredentials();
18
18
  const isPasswordValid = await (0, helpers_1.comparePasswords)(password, user.password);
@@ -9,12 +9,12 @@ declare global {
9
9
  type ModelName = string;
10
10
  type BaseModelCtor<BM extends BaseModel = BaseModel> = typeof BaseModel & ModelCtor<BM>;
11
11
  type ColOptional<T> = CreationOptional<T>;
12
- type ColExcluded<T> = T & {
13
- __brand: 'excluded';
12
+ type ColHidden<T> = T & {
13
+ __brand: 'hidden';
14
14
  };
15
15
  type ColVirtual<T> = NonAttribute<T>;
16
16
  type Where<BM extends BaseModel> = WhereOptions<BM> & Record<symbol, any>;
17
- type InsertParams<BM extends BaseModel> = OptionalIfNullish<OptionalIfOptional<StripRelations<OptionalFields<IncludeExcluded<Omit<InferCreationAttributes<BM>, '__brand'>>, Exclude<keyof InferCreationAttributes<BM>, '__brand'> & 'id'>>>>;
17
+ type InsertParams<BM extends BaseModel> = OptionalIfNullish<OptionalIfOptional<StripRelations<OptionalFields<IncludeHidden<Omit<InferCreationAttributes<BM>, '__brand'>>, Exclude<keyof InferCreationAttributes<BM>, '__brand'> & 'id'>>>>;
18
18
  type UpdateParams<BM extends BaseModel> = Partial<InsertParams<BM>>;
19
19
  type Tx = Transaction;
20
20
  type Db = _Db;
@@ -26,6 +26,7 @@ export type Seeds<M extends Models> = {
26
26
  export type ConnectDatabase = () => void;
27
27
  export type DisconnectDatabase = () => void;
28
28
  export type Index = {
29
+ name?: string;
29
30
  field?: string;
30
31
  fields?: string[];
31
32
  unique?: boolean;
@@ -37,7 +38,7 @@ export type ColGeneralOptions = {
37
38
  defaultValue?: DefaultValue;
38
39
  index?: boolean;
39
40
  unique?: boolean;
40
- exclude?: boolean;
41
+ hideByDefault?: boolean;
41
42
  };
42
43
  export type ColVirtualGet = (this: any) => unknown;
43
44
  export type ColVirtualSet = (this: any, val: any) => void;
@@ -51,8 +52,8 @@ type OptionalIfOptional<T> = {
51
52
  } & {
52
53
  [K in keyof T as undefined extends T[K] ? never : K]: T[K];
53
54
  };
54
- type IncludeExcluded<T> = {
55
- [K in keyof T]-?: Exclude<T[K], undefined> extends ColExcluded<infer U> ? U : T[K];
55
+ type IncludeHidden<T> = {
56
+ [K in keyof T]-?: Exclude<T[K], undefined> extends ColHidden<infer U> ? U : T[K];
56
57
  };
57
58
  type IsRelation<T> = NonNullable<T> extends BaseModel | Array<BaseModel> ? true : false;
58
59
  type StripRelations<T> = {
@@ -270,6 +270,8 @@ function getInclude(model, config = {}, relDepth = new Map()) {
270
270
  const maxDepth = rel.joinDepth;
271
271
  if (currentDepth >= maxDepth)
272
272
  continue;
273
+ if (rel.exclude)
274
+ continue;
273
275
  const relWhere = cleanWhere[relName];
274
276
  delete cleanWhere[relName];
275
277
  const newRelDepth = new Map(relDepth);
@@ -26,7 +26,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
26
26
  exports.Column = void 0;
27
27
  const seq = __importStar(require("sequelize-typescript"));
28
28
  function Column(type, options = {}) {
29
- const { nullable = false, defaultValue, index, unique = false, exclude, get, set, ...restOptions } = options;
29
+ const { nullable = false, defaultValue, index, unique = false, hideByDefault, get, set, ...restOptions } = options;
30
30
  return function (target, propertyName) {
31
31
  seq.Column({
32
32
  type: typeof type === 'string' ? seq.DataType[type] : type,
@@ -40,8 +40,8 @@ function Column(type, options = {}) {
40
40
  model.AddColumn(propertyName, { allowNull: nullable, defaultValue });
41
41
  if (index || unique)
42
42
  model.AddColumnIndex({ field: propertyName, unique });
43
- if (exclude)
44
- model.AddExcludedAttribute(propertyName);
43
+ if (hideByDefault)
44
+ model.AddHiddenAttribute(propertyName);
45
45
  };
46
46
  }
47
47
  exports.Column = Column;
@@ -1,4 +1,4 @@
1
1
  import type { ColGeneralOptions, ColVirtualGet, ColVirtualOptions, GetModelFn } from '../../../database/database.types';
2
2
  export declare function ColBool(options?: ColGeneralOptions): (target: any, propertyName: string) => void;
3
- export declare function ColForeignKey(getModelFn: GetModelFn, options?: ColGeneralOptions): (target: any, propertyName: string) => void;
3
+ export declare function ColForeignKey(getModelFn: GetModelFn, options?: Omit<ColGeneralOptions, 'index'>): (target: any, propertyName: string) => void;
4
4
  export declare function ColVirtual(options?: ColVirtualOptions | ColVirtualGet): Function;
@@ -32,7 +32,7 @@ function ColBool(options) {
32
32
  exports.ColBool = ColBool;
33
33
  function ColForeignKey(getModelFn, options) {
34
34
  return function (target, propertyName) {
35
- (0, column_1.Column)('INTEGER', { ...options, onUpdate: 'RESTRICT', onDelete: 'RESTRICT' })(target, propertyName);
35
+ (0, column_1.Column)('INTEGER', { ...options, index: true, onUpdate: 'RESTRICT', onDelete: 'RESTRICT' })(target, propertyName);
36
36
  seq.ForeignKey(getModelFn)(target, propertyName);
37
37
  };
38
38
  }
@@ -1,9 +1,10 @@
1
1
  import type { GetModelFn } from '../database.types';
2
2
  type RelationOptions = {
3
+ foreignKey?: string;
4
+ exclude?: boolean;
3
5
  required?: boolean;
4
6
  paranoid?: boolean;
5
7
  joinDepth?: number;
6
- foreignKey?: string;
7
8
  };
8
9
  export declare const BelongsTo: (getModelFn: GetModelFn, options?: RelationOptions) => (target: any, propertyName: string) => void;
9
10
  export declare const HasOne: (getModelFn: GetModelFn, options?: RelationOptions) => (target: any, propertyName: string) => void;
@@ -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 { 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 });
38
+ const { exclude = false, required = relationFn === seq.BelongsTo ? !model.Columns[`${propertyName}Id`].allowNull : false, paranoid = relationFn !== seq.BelongsTo, joinDepth = 1, ...restOptions } = relOptions;
39
+ model.AddRelation(propertyName, { getModelFn, exclude, required, paranoid, joinDepth, ...restOptions });
40
40
  };
41
41
  };
42
42
  }
@@ -40,15 +40,16 @@ function Table(tableName, options = {}) {
40
40
  underscored: true,
41
41
  timestamps: true,
42
42
  paranoid: true,
43
- indexes: allIndexes.map(({ field, fields, ...restIndex }) => {
44
- return { ...restIndex, fields: fields ? fields.map(pangea_helpers_1.camelToSnake) : field ? [(0, pangea_helpers_1.camelToSnake)(field)] : [] };
45
- }),
43
+ indexes: allIndexes.map(({ field, fields, ...restIndex }) => ({
44
+ ...restIndex,
45
+ fields: fields ? fields.map(pangea_helpers_1.camelToSnake) : field ? [(0, pangea_helpers_1.camelToSnake)(field)] : [],
46
+ })),
46
47
  })(target);
47
- const excludedAttributes = target.ExcludedAttributes;
48
- if (!excludedAttributes.length)
48
+ const hiddenAttributes = target.HiddenAttributes;
49
+ if (!hiddenAttributes.length)
49
50
  return;
50
- seq.DefaultScope(() => ({ attributes: { exclude: excludedAttributes } }))(target);
51
- seq.Scopes(() => ({ withExcludedAttributes: { attributes: { include: excludedAttributes } } }))(target);
51
+ seq.DefaultScope(() => ({ attributes: { exclude: hiddenAttributes } }))(target);
52
+ seq.Scopes(() => ({ withHiddenAttributes: { attributes: { include: hiddenAttributes } } }))(target);
52
53
  };
53
54
  }
54
55
  exports.Table = Table;
@@ -7,22 +7,23 @@ type Column = {
7
7
  type Columns = Record<string, Column>;
8
8
  type Relation = {
9
9
  getModelFn: GetModelFn;
10
+ exclude: boolean;
10
11
  required: boolean;
11
12
  paranoid: boolean;
12
13
  joinDepth: number;
13
14
  };
14
15
  type Relations = Record<string, Relation>;
15
16
  export declare abstract class BaseModel extends Model {
16
- private static __ExcludedAttributes?;
17
+ private static __HiddenAttributes?;
17
18
  private static __Columns?;
18
19
  private static __ColumnIndexes?;
19
20
  private static __Relations?;
20
21
  id: ModelId;
21
- static get ExcludedAttributes(): string[];
22
+ static get HiddenAttributes(): string[];
22
23
  static get Columns(): Columns;
23
24
  static get ColumnIndexes(): Index[];
24
25
  static get Relations(): Relations;
25
- static AddExcludedAttribute(attribute: string): void;
26
+ static AddHiddenAttribute(attribute: string): void;
26
27
  static AddColumn(colName: string, col: Column): void;
27
28
  static AddColumnIndex(index: Index): void;
28
29
  static AddRelation(relName: string, rel: Relation): void;
@@ -12,8 +12,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.BaseModel = void 0;
13
13
  const sequelize_typescript_1 = require("sequelize-typescript");
14
14
  class BaseModel extends sequelize_typescript_1.Model {
15
- static get ExcludedAttributes() {
16
- return this.__ExcludedAttributes || [];
15
+ static get HiddenAttributes() {
16
+ return this.__HiddenAttributes || [];
17
17
  }
18
18
  static get Columns() {
19
19
  return this.__Columns || {};
@@ -24,9 +24,9 @@ class BaseModel extends sequelize_typescript_1.Model {
24
24
  static get Relations() {
25
25
  return this.__Relations || {};
26
26
  }
27
- static AddExcludedAttribute(attribute) {
28
- this.__SetArray('__ExcludedAttributes');
29
- this.__ExcludedAttributes.push(attribute);
27
+ static AddHiddenAttribute(attribute) {
28
+ this.__SetArray('__HiddenAttributes');
29
+ this.__HiddenAttributes.push(attribute);
30
30
  }
31
31
  static AddColumn(colName, col) {
32
32
  this.__SetObject('__Columns');
@@ -1,5 +1,5 @@
1
1
  import { BaseModel } from './base-model.class';
2
2
  export declare abstract class User extends BaseModel {
3
3
  username: string;
4
- password?: ColExcluded<string>;
4
+ password?: ColHidden<string>;
5
5
  }
@@ -16,6 +16,6 @@ class User extends base_model_class_1.BaseModel {
16
16
  }
17
17
  exports.User = User;
18
18
  __decorate([
19
- decorators_1.col.Str({ exclude: true, maxLength: 'medium' }),
19
+ decorators_1.col.Str({ hideByDefault: true, maxLength: 'medium' }),
20
20
  __metadata("design:type", Object)
21
21
  ], User.prototype, "password", void 0);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "pangea-server",
3
3
  "description": "",
4
- "version": "1.0.77",
4
+ "version": "1.0.79",
5
5
  "files": [
6
6
  "dist"
7
7
  ],