pangea-server 1.0.78 → 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> = {
@@ -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;
@@ -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;
@@ -14,16 +14,16 @@ type Relation = {
14
14
  };
15
15
  type Relations = Record<string, Relation>;
16
16
  export declare abstract class BaseModel extends Model {
17
- private static __ExcludedAttributes?;
17
+ private static __HiddenAttributes?;
18
18
  private static __Columns?;
19
19
  private static __ColumnIndexes?;
20
20
  private static __Relations?;
21
21
  id: ModelId;
22
- static get ExcludedAttributes(): string[];
22
+ static get HiddenAttributes(): string[];
23
23
  static get Columns(): Columns;
24
24
  static get ColumnIndexes(): Index[];
25
25
  static get Relations(): Relations;
26
- static AddExcludedAttribute(attribute: string): void;
26
+ static AddHiddenAttribute(attribute: string): void;
27
27
  static AddColumn(colName: string, col: Column): void;
28
28
  static AddColumnIndex(index: Index): void;
29
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.78",
4
+ "version": "1.0.79",
5
5
  "files": [
6
6
  "dist"
7
7
  ],