namirasoft-node 1.0.22 → 1.0.24

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.
@@ -1,4 +1,4 @@
1
1
  import { BaseSequelizeDatabase } from "./BaseSequelizeDatabase";
2
2
  export declare abstract class BaseMySqlDatabase extends BaseSequelizeDatabase {
3
- constructor(name: string, user: string, pass: string, host: string, port: number, logging?: boolean);
3
+ constructor(host: string, port: number, name: string, user: string, pass: string, logging?: boolean);
4
4
  }
@@ -3,8 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.BaseMySqlDatabase = void 0;
4
4
  const BaseSequelizeDatabase_1 = require("./BaseSequelizeDatabase");
5
5
  class BaseMySqlDatabase extends BaseSequelizeDatabase_1.BaseSequelizeDatabase {
6
- constructor(name, user, pass, host, port, logging = false) {
7
- super('mysql', name, user, pass, host, port, logging);
6
+ constructor(host, port, name, user, pass, logging = false) {
7
+ super('mysql', host, port, name, user, pass, logging);
8
8
  }
9
9
  }
10
10
  exports.BaseMySqlDatabase = BaseMySqlDatabase;
@@ -1,15 +1,12 @@
1
1
  import { Sequelize, Dialect } from "sequelize";
2
- import { Model, ModelCtor, FindOptions, Transaction, ModelAttributes, Attributes, ModelOptions } from 'sequelize';
2
+ import { FindOptions, Transaction, Attributes } from 'sequelize';
3
3
  import { BaseDatabase } from "./BaseDatabase";
4
4
  import { BaseSequelizeModel } from "./BaseSequelizeModel";
5
5
  import { Where } from "sequelize/types/utils";
6
6
  export declare abstract class BaseSequelizeDatabase extends BaseDatabase {
7
- protected sequelize: Sequelize;
8
- constructor(dialect: Dialect, name: string, user: string, pass: string, host: string, port: number, logging?: boolean);
9
- define<M extends Model, TAttributes = Attributes<M>>(modelName: string, attributes: ModelAttributes<M, TAttributes>, options?: ModelOptions<M>): ModelCtor<M>;
7
+ sequelize: Sequelize;
8
+ constructor(dialect: Dialect, host: string, port: number, name: string, user: string, pass: string, logging?: boolean);
10
9
  startTransaction<T>(handler: (trx: Transaction) => Promise<T>, trx: Transaction | null): Promise<T>;
11
- getModel<M extends BaseSequelizeModel>(modelName: string, options: FindOptions<Attributes<M>>, trx: Transaction | null): Promise<M>;
12
- getModelOrNull<M extends BaseSequelizeModel>(modelName: string, options: FindOptions<Attributes<M>>, trx: Transaction | null): Promise<M | null>;
13
10
  getGoogleSearchConditions(columns: string[], search: string, conditions: Where[]): Where[];
14
11
  paginate<T extends BaseSequelizeModel>(options: FindOptions<Attributes<T>>, page_number: number, page_size: number, page_size_default?: number): void;
15
12
  }
@@ -12,9 +12,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.BaseSequelizeDatabase = void 0;
13
13
  const sequelize_1 = require("sequelize");
14
14
  const BaseDatabase_1 = require("./BaseDatabase");
15
- const namirasoft_core_1 = require("namirasoft-core");
16
15
  class BaseSequelizeDatabase extends BaseDatabase_1.BaseDatabase {
17
- constructor(dialect, name, user, pass, host, port, logging = false) {
16
+ constructor(dialect, host, port, name, user, pass, logging = false) {
18
17
  super();
19
18
  this.sequelize = new sequelize_1.Sequelize(name, user, pass, {
20
19
  dialect,
@@ -23,32 +22,6 @@ class BaseSequelizeDatabase extends BaseDatabase_1.BaseDatabase {
23
22
  logging
24
23
  });
25
24
  }
26
- define(modelName, attributes, options) {
27
- if (!options)
28
- options = {};
29
- if (options.name == undefined)
30
- options.name = {
31
- plural: modelName,
32
- singular: modelName
33
- };
34
- if (options.paranoid == undefined)
35
- options.paranoid = true;
36
- if (options.freezeTableName == undefined)
37
- options.freezeTableName = true;
38
- if (options.tableName == undefined)
39
- options.tableName = modelName;
40
- if (options.underscored == undefined)
41
- options.underscored = true;
42
- if (options.timestamps == undefined)
43
- options.timestamps = true;
44
- if (options.paranoid == undefined)
45
- options.paranoid = true;
46
- if (options.createdAt == undefined)
47
- options.createdAt = true;
48
- if (options.updatedAt == undefined)
49
- options.updatedAt = true;
50
- return this.sequelize.define(modelName, attributes, options);
51
- }
52
25
  startTransaction(handler, trx) {
53
26
  return __awaiter(this, void 0, void 0, function* () {
54
27
  if (trx)
@@ -65,23 +38,6 @@ class BaseSequelizeDatabase extends BaseDatabase_1.BaseDatabase {
65
38
  }
66
39
  });
67
40
  }
68
- getModel(modelName, options, trx) {
69
- return __awaiter(this, void 0, void 0, function* () {
70
- let value = yield this.getModelOrNull(modelName, options, trx);
71
- if (value != null)
72
- return value;
73
- throw namirasoft_core_1.ErrorOperation.getHTTP(404, "Could not found " + modelName);
74
- });
75
- }
76
- getModelOrNull(modelName, options, trx) {
77
- return __awaiter(this, void 0, void 0, function* () {
78
- if (!options)
79
- options = {};
80
- options.transaction = trx;
81
- let model = this.sequelize.models[modelName];
82
- return yield model.findOne(options);
83
- });
84
- }
85
41
  getGoogleSearchConditions(columns, search, conditions) {
86
42
  if (!conditions)
87
43
  conditions = [];
@@ -1 +1 @@
1
- {"version":3,"file":"BaseSequelizeDatabase.js","sourceRoot":"","sources":["../src/BaseSequelizeDatabase.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,yCAAmD;AAEnD,iDAA8C;AAE9C,qDAAiD;AAGjD,MAAsB,qBAAsB,SAAQ,2BAAY;IAG5D,YAAY,OAAgB,EAAE,IAAY,EAAE,IAAY,EAAE,IAAY,EAAE,IAAY,EAAE,IAAY,EAAE,UAAmB,KAAK;QAExH,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,SAAS,GAAG,IAAI,qBAAS,CAC1B,IAAI,EACJ,IAAI,EACJ,IAAI,EACJ;YACI,OAAO;YACP,IAAI;YACJ,IAAI;YACJ,OAAO;SACV,CAAC,CAAC;IACX,CAAC;IACD,MAAM,CACF,SAAiB,EACjB,UAA2C,EAC3C,OAAyB;QAGzB,IAAI,CAAC,OAAO;YACR,OAAO,GAAG,EAAE,CAAC;QACjB,IAAI,OAAO,CAAC,IAAI,IAAI,SAAS;YACzB,OAAO,CAAC,IAAI,GAAG;gBACX,MAAM,EAAE,SAAS;gBACjB,QAAQ,EAAE,SAAS;aACtB,CAA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AC,IAAI,EAAE,IAAI,CAAC,CAAC;wBAC5C,UAAU,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;qBAC9B;iBACJ;aACJ;QACL,OAAO,UAAU,CAAC;IACtB,CAAC;IAED,QAAQ,CAA+B,OAAmC,EACtE,WAAmB,EAAE,SAAiB,EAAE,iBAA0B;QAElE,cAAc;QACd,IAAI,KAAK,CAAC,WAAW,CAAC;YAClB,WAAW,GAAG,CAAC,CAAC;QACpB,YAAY;QACZ,IAAI,KAAK,CAAC,SAAS,CAAC;YAChB,IAAI,iBAAiB;gBACjB,SAAS,GAAG,iBAAiB,CAAC;QACtC,IAAI,KAAK,CAAC,SAAS,CAAC;YAChB,SAAS,GAAG,EAAE,CAAC;QACnB,EAAE;QACF,OAAO,CAAC,MAAM,GAAG,CAAC,WAAW,GAAG,CAAC,CAAC,GAAG,SAAS,CAAC;QAC/C,OAAO,CAAC,KAAK,GAAG,SAAS,CAAC;IAC9B,CAAC;CACJ;AA7ED,sDA6EC"}
@@ -1 +1 @@
1
- {"version":3,"file":"BaseSequelizeModel.js","sourceRoot":"","sources":["../src/BaseSequelizeModel.ts"],"names":[],"mappings":";;;AACA,yCAAkC;AAElC,MAAsB,kBAAmB,SAAQ,iBAAK;CAGrD;AAHD,gDAGC"}
1
+ {"version":3,"file":"BaseSequelizeModel.js","sourceRoot":"","sources":["../src/BaseSequelizeModel.ts"],"names":[],"mappings":";;;AAAA,yCAAkC;AAElC,MAAsB,kBAAmB,SAAQ,iBAAK;CAErD;AAFD,gDAEC"}
@@ -1,8 +1,11 @@
1
- import { ModelCtor } from "sequelize";
1
+ import { ModelOptions, ModelAttributes } from "sequelize";
2
2
  import { BaseSequelizeDatabase } from "./BaseSequelizeDatabase";
3
- import { BaseSequelizeModel } from "./BaseSequelizeModel";
4
3
  import { BaseTable } from "./BaseTable";
4
+ import { ModelCtor, FindOptions, Transaction, Attributes } from 'sequelize';
5
+ import { BaseSequelizeModel } from "./BaseSequelizeModel";
5
6
  export declare class BaseSequelizeTable<D extends BaseSequelizeDatabase, M extends BaseSequelizeModel> extends BaseTable<D> {
6
7
  model: ModelCtor<M>;
7
8
  constructor(database: D);
9
+ find(options: FindOptions<Attributes<M>>, trx: Transaction | null): Promise<M>;
10
+ define<TAttributes = Attributes<M>>(modelName: string, attributes: ModelAttributes<M, TAttributes>, options?: ModelOptions<M>): void;
8
11
  }
@@ -1,11 +1,56 @@
1
1
  "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
2
11
  Object.defineProperty(exports, "__esModule", { value: true });
3
12
  exports.BaseSequelizeTable = void 0;
4
13
  const BaseTable_1 = require("./BaseTable");
14
+ const namirasoft_core_1 = require("namirasoft-core");
5
15
  class BaseSequelizeTable extends BaseTable_1.BaseTable {
6
16
  constructor(database) {
7
17
  super(database);
8
18
  }
19
+ find(options, trx) {
20
+ return __awaiter(this, void 0, void 0, function* () {
21
+ options.transaction = trx;
22
+ let value = yield this.model.findOne(options);
23
+ if (value != null)
24
+ return value;
25
+ throw namirasoft_core_1.ErrorOperation.getHTTP(404, "Could not found " + this.model.name);
26
+ });
27
+ }
28
+ define(modelName, attributes, options) {
29
+ if (!options)
30
+ options = {};
31
+ if (options.name == undefined)
32
+ options.name = {
33
+ plural: modelName,
34
+ singular: modelName
35
+ };
36
+ if (options.paranoid == undefined)
37
+ options.paranoid = true;
38
+ if (options.freezeTableName == undefined)
39
+ options.freezeTableName = true;
40
+ if (options.tableName == undefined)
41
+ options.tableName = modelName;
42
+ if (options.underscored == undefined)
43
+ options.underscored = true;
44
+ if (options.timestamps == undefined)
45
+ options.timestamps = true;
46
+ if (options.paranoid == undefined)
47
+ options.paranoid = true;
48
+ if (options.createdAt == undefined)
49
+ options.createdAt = true;
50
+ if (options.updatedAt == undefined)
51
+ options.updatedAt = true;
52
+ this.model = this.database.sequelize.define(modelName, attributes, options);
53
+ }
9
54
  }
10
55
  exports.BaseSequelizeTable = BaseSequelizeTable;
11
56
  //# sourceMappingURL=BaseSequelizeTable.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"BaseSequelizeTable.js","sourceRoot":"","sources":["../src/BaseSequelizeTable.ts"],"names":[],"mappings":";;;AAGA,2CAAwC;AAExC,MAAa,kBAAkF,SAAQ,qBAAY;IAG/G,YAAY,QAAW;QAEnB,KAAK,CAAC,QAAQ,CAAC,CAAC;IACpB,CAAC;CACJ;AAPD,gDAOC"}
1
+ {"version":3,"file":"BaseSequelizeTable.js","sourceRoot":"","sources":["../src/BaseSequelizeTable.ts"],"names":[],"mappings":";;;;;;;;;;;;AAEA,2CAAwC;AAGxC,qDAAiD;AAEjD,MAAa,kBAAkF,SAAQ,qBAAY;IAG/G,YAAY,QAAW;QAEnB,KAAK,CAAC,QAAQ,CAAC,CAAC;IACpB,CAAC;IACK,IAAI,CAAC,OAAmC,EAAE,GAAuB;;YAEnE,OAAO,CAAC,WAAW,GAAG,GAAG,CAAC;YAC1B,IAAI,KAAK,GAAG,MAAM,IAAI,CAAC,KAAK,CAAC,OAAO,CAAI,OAAO,CAAC,CAAC;YACjD,IAAI,KAAK,IAAI,IAAI;gBACb,OAAO,KAAK,CAAC;YACjB,MAAM,gCAAc,CAAC,OAAO,CAAC,GAAG,EAAE,kBAAkB,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QAC5E,CAAC;KAAA;IACD,MAAM,CACF,SAAiB,EACjB,UAA2C,EAC3C,OAAyB;QAGzB,IAAI,CAAC,OAAO;YACR,OAAO,GAAG,EAAE,CAAC;QACjB,IAAI,OAAO,CAAC,IAAI,IAAI,SAAS;YACzB,OAAO,CAAC,IAAI,GAAG;gBACX,MAAM,EAAE,SAAS;gBACjB,QAAQ,EAAE,SAAS;aACtB,CAAC;QACN,IAAI,OAAO,CAAC,QAAQ,IAAI,SAAS;YAC7B,OAAO,CAAC,QAAQ,GAAG,IAAI,CAAC;QAC5B,IAAI,OAAO,CAAC,eAAe,IAAI,SAAS;YACpC,OAAO,CAAC,eAAe,GAAG,IAAI,CAAC;QACnC,IAAI,OAAO,CAAC,SAAS,IAAI,SAAS;YAC9B,OAAO,CAAC,SAAS,GAAG,SAAS,CAAC;QAClC,IAAI,OAAO,CAAC,WAAW,IAAI,SAAS;YAChC,OAAO,CAAC,WAAW,GAAG,IAAI,CAAC;QAC/B,IAAI,OAAO,CAAC,UAAU,IAAI,SAAS;YAC/B,OAAO,CAAC,UAAU,GAAG,IAAI,CAAC;QAC9B,IAAI,OAAO,CAAC,QAAQ,IAAI,SAAS;YAC7B,OAAO,CAAC,QAAQ,GAAG,IAAI,CAAC;QAC5B,IAAI,OAAO,CAAC,SAAS,IAAI,SAAS;YAC9B,OAAO,CAAC,SAAS,GAAG,IAAI,CAAC;QAC7B,IAAI,OAAO,CAAC,SAAS,IAAI,SAAS;YAC9B,OAAO,CAAC,SAAS,GAAG,IAAI,CAAC;QAE7B,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,QAAQ,CAAC,SAAS,CAAC,MAAM,CAAC,SAAS,EAAE,UAAU,EAAE,OAAO,CAAC,CAAC;IAChF,CAAC;CACJ;AA/CD,gDA+CC"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "namirasoft-node",
3
3
  "description": "Namira Software Corporation Node NPM Package",
4
- "version": "1.0.22",
4
+ "version": "1.0.24",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
7
7
  "scripts": {},
@@ -19,11 +19,11 @@
19
19
  "express": "^4.18.2",
20
20
  "joi": "^17.11.0",
21
21
  "namirasoft-core": "^1.0.13",
22
- "namirasoft-log": "^1.0.1",
22
+ "namirasoft-log": "^1.0.3",
23
23
  "nodemailer": "^6.9.7",
24
24
  "nodemailer-smtp-transport": "^2.7.4",
25
25
  "request-ip": "^3.3.0",
26
- "sequelize": "^6.34.0",
26
+ "sequelize": "^6.35.0",
27
27
  "swagger-jsdoc": "^6.2.8",
28
28
  "swagger-ui-express": "^5.0.0"
29
29
  },
@@ -1,8 +1,8 @@
1
1
  import { BaseSequelizeDatabase } from "./BaseSequelizeDatabase";
2
2
  export abstract class BaseMySqlDatabase extends BaseSequelizeDatabase
3
3
  {
4
- constructor(name: string, user: string, pass: string, host: string, port: number, logging: boolean = false)
4
+ constructor(host: string, port: number, name: string, user: string, pass: string, logging: boolean = false)
5
5
  {
6
- super('mysql', name, user, pass, host, port, logging);
6
+ super('mysql', host, port, name, user, pass, logging);
7
7
  }
8
8
  }
@@ -1,14 +1,13 @@
1
1
  import { Sequelize, Dialect, Op } from "sequelize";
2
- import { Model, ModelCtor, FindOptions, Transaction, ModelAttributes, Attributes, ModelOptions } from 'sequelize';
2
+ import { FindOptions, Transaction, Attributes } from 'sequelize';
3
3
  import { BaseDatabase } from "./BaseDatabase";
4
4
  import { BaseSequelizeModel } from "./BaseSequelizeModel";
5
- import { ErrorOperation } from "namirasoft-core";
6
5
  import { Where } from "sequelize/types/utils";
7
6
 
8
7
  export abstract class BaseSequelizeDatabase extends BaseDatabase
9
8
  {
10
- protected sequelize: Sequelize;
11
- constructor(dialect: Dialect, name: string, user: string, pass: string, host: string, port: number, logging: boolean = false)
9
+ public sequelize: Sequelize;
10
+ constructor(dialect: Dialect, host: string, port: number, name: string, user: string, pass: string, logging: boolean = false)
12
11
  {
13
12
  super();
14
13
  this.sequelize = new Sequelize(
@@ -22,38 +21,6 @@ export abstract class BaseSequelizeDatabase extends BaseDatabase
22
21
  logging
23
22
  });
24
23
  }
25
- define<M extends Model, TAttributes = Attributes<M>>(
26
- modelName: string,
27
- attributes: ModelAttributes<M, TAttributes>,
28
- options?: ModelOptions<M>
29
- ): ModelCtor<M>
30
- {
31
- if (!options)
32
- options = {};
33
- if (options.name == undefined)
34
- options.name = {
35
- plural: modelName,
36
- singular: modelName
37
- };
38
- if (options.paranoid == undefined)
39
- options.paranoid = true;
40
- if (options.freezeTableName == undefined)
41
- options.freezeTableName = true;
42
- if (options.tableName == undefined)
43
- options.tableName = modelName;
44
- if (options.underscored == undefined)
45
- options.underscored = true;
46
- if (options.timestamps == undefined)
47
- options.timestamps = true;
48
- if (options.paranoid == undefined)
49
- options.paranoid = true;
50
- if (options.createdAt == undefined)
51
- options.createdAt = true;
52
- if (options.updatedAt == undefined)
53
- options.updatedAt = true;
54
-
55
- return this.sequelize.define(modelName, attributes, options);
56
- }
57
24
  async startTransaction<T>(handler: (trx: Transaction) => Promise<T>, trx: Transaction | null): Promise<T>
58
25
  {
59
26
  if (trx)
@@ -71,21 +38,6 @@ export abstract class BaseSequelizeDatabase extends BaseDatabase
71
38
  throw error;
72
39
  }
73
40
  }
74
- async getModel<M extends BaseSequelizeModel>(modelName: string, options: FindOptions<Attributes<M>>, trx: Transaction | null): Promise<M>
75
- {
76
- let value = await this.getModelOrNull(modelName, options, trx);
77
- if (value != null)
78
- return value;
79
- throw ErrorOperation.getHTTP(404, "Could not found " + modelName);
80
- }
81
- async getModelOrNull<M extends BaseSequelizeModel>(modelName: string, options: FindOptions<Attributes<M>>, trx: Transaction | null): Promise<M | null>
82
- {
83
- if (!options)
84
- options = {};
85
- options.transaction = trx;
86
- let model = this.sequelize.models[modelName] as ModelCtor<M>;
87
- return await model.findOne<M>(options);
88
- }
89
41
  getGoogleSearchConditions(columns: string[], search: string, conditions: Where[])
90
42
  {
91
43
  if (!conditions)
@@ -1,7 +1,5 @@
1
-
2
1
  import { Model } from 'sequelize';
3
2
 
4
3
  export abstract class BaseSequelizeModel extends Model
5
4
  {
6
-
7
5
  }
@@ -1,7 +1,9 @@
1
- import { ModelCtor } from "sequelize";
1
+ import { ModelOptions, ModelAttributes } from "sequelize";
2
2
  import { BaseSequelizeDatabase } from "./BaseSequelizeDatabase";
3
- import { BaseSequelizeModel } from "./BaseSequelizeModel";
4
3
  import { BaseTable } from "./BaseTable";
4
+ import { ModelCtor, FindOptions, Transaction, Attributes } from 'sequelize';
5
+ import { BaseSequelizeModel } from "./BaseSequelizeModel";
6
+ import { ErrorOperation } from "namirasoft-core";
5
7
 
6
8
  export class BaseSequelizeTable<D extends BaseSequelizeDatabase, M extends BaseSequelizeModel> extends BaseTable<D>
7
9
  {
@@ -10,4 +12,44 @@ export class BaseSequelizeTable<D extends BaseSequelizeDatabase, M extends BaseS
10
12
  {
11
13
  super(database);
12
14
  }
15
+ async find(options: FindOptions<Attributes<M>>, trx: Transaction | null): Promise<M>
16
+ {
17
+ options.transaction = trx;
18
+ let value = await this.model.findOne<M>(options);
19
+ if (value != null)
20
+ return value;
21
+ throw ErrorOperation.getHTTP(404, "Could not found " + this.model.name);
22
+ }
23
+ define<TAttributes = Attributes<M>>(
24
+ modelName: string,
25
+ attributes: ModelAttributes<M, TAttributes>,
26
+ options?: ModelOptions<M>
27
+ ): void
28
+ {
29
+ if (!options)
30
+ options = {};
31
+ if (options.name == undefined)
32
+ options.name = {
33
+ plural: modelName,
34
+ singular: modelName
35
+ };
36
+ if (options.paranoid == undefined)
37
+ options.paranoid = true;
38
+ if (options.freezeTableName == undefined)
39
+ options.freezeTableName = true;
40
+ if (options.tableName == undefined)
41
+ options.tableName = modelName;
42
+ if (options.underscored == undefined)
43
+ options.underscored = true;
44
+ if (options.timestamps == undefined)
45
+ options.timestamps = true;
46
+ if (options.paranoid == undefined)
47
+ options.paranoid = true;
48
+ if (options.createdAt == undefined)
49
+ options.createdAt = true;
50
+ if (options.updatedAt == undefined)
51
+ options.updatedAt = true;
52
+
53
+ this.model = this.database.sequelize.define(modelName, attributes, options);
54
+ }
13
55
  }