express-sweet 1.0.15 → 1.0.16

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.
Files changed (43) hide show
  1. package/CHANGELOG.md +186 -0
  2. package/dist/build.common.js +53 -0
  3. package/dist/build.esm.js +53 -0
  4. package/package.json +1 -1
  5. package/types/database/Database.d.ts +162 -0
  6. package/types/database/Model.d.ts +221 -0
  7. package/types/database/index.d.ts +4 -0
  8. package/types/database/loadModels.d.ts +6 -0
  9. package/types/exceptions/ApiError.d.ts +29 -0
  10. package/types/exceptions/index.d.ts +2 -0
  11. package/types/handlebars_helpers/comparison.d.ts +302 -0
  12. package/types/handlebars_helpers/html.d.ts +11 -0
  13. package/types/handlebars_helpers/index.d.ts +5 -0
  14. package/types/handlebars_helpers/object.d.ts +21 -0
  15. package/types/handlebars_helpers/string.d.ts +12 -0
  16. package/types/index.d.ts +9 -0
  17. package/types/interfaces/AuthenticationOptions.d.ts +84 -0
  18. package/types/interfaces/BoundingBox.d.ts +25 -0
  19. package/types/interfaces/Config.d.ts +66 -0
  20. package/types/interfaces/DatabaseOptions.d.ts +7 -0
  21. package/types/interfaces/FaceMatch.d.ts +31 -0
  22. package/types/interfaces/RekognitionOptions.d.ts +26 -0
  23. package/types/interfaces/ViewOptions.d.ts +30 -0
  24. package/types/interfaces/index.d.ts +8 -0
  25. package/types/middlewares/Authentication.d.ts +16 -0
  26. package/types/middlewares/CORS.d.ts +16 -0
  27. package/types/middlewares/Environment.d.ts +17 -0
  28. package/types/middlewares/ErrorHandling.d.ts +16 -0
  29. package/types/middlewares/Global.d.ts +13 -0
  30. package/types/middlewares/Http.d.ts +16 -0
  31. package/types/middlewares/Local.d.ts +20 -0
  32. package/types/middlewares/View.d.ts +16 -0
  33. package/types/middlewares/index.d.ts +8 -0
  34. package/types/mount.d.ts +7 -0
  35. package/types/package.d.ts +91 -0
  36. package/types/routing/Router.d.ts +19 -0
  37. package/types/routing/index.d.ts +2 -0
  38. package/types/services/AWSRekognitionClient.d.ts +359 -0
  39. package/types/services/Authentication.d.ts +39 -0
  40. package/types/services/RedisClient.d.ts +80 -0
  41. package/types/services/index.d.ts +3 -0
  42. package/types/utils/Types.d.ts +16 -0
  43. package/types/utils/index.d.ts +2 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "express-sweet",
3
- "version": "1.0.15",
3
+ "version": "1.0.16",
4
4
  "description": "Extend Express functionality with Express Sweet and start developing fast, minimal web applications.",
5
5
  "main": "dist/build.common.js",
6
6
  "module": "dist/build.esm.js",
@@ -0,0 +1,162 @@
1
+ import sequelize from 'sequelize';
2
+ declare const _default: {
3
+ /**
4
+ * Returns true if the DB can be connected.
5
+ *
6
+ * @example
7
+ * const database = require('express-sweet').database.Database;
8
+ *
9
+ * // Check database connection.
10
+ * const isConnected = await database.isConnect();
11
+ *
12
+ * @return {Promise<boolean>} Returns true if it can connect to the database, false if it cannot.
13
+ */
14
+ isConnect(): Promise<boolean>;
15
+ Sequelize: typeof sequelize.Sequelize;
16
+ readonly config: sequelize.Config;
17
+ readonly modelManager: import("sequelize/types/lib/model-manager").ModelManager;
18
+ readonly connectionManager: import("sequelize/types/lib/connection-manager").ConnectionManager;
19
+ readonly models: {
20
+ [key: string]: sequelize.ModelCtor<sequelize.Model<any, any>>;
21
+ };
22
+ beforeValidate(name: string, fn: (instance: sequelize.Model<any, any>, options: import("sequelize/types/lib/instance-validator").ValidationOptions) => void): void;
23
+ beforeValidate(fn: (instance: sequelize.Model<any, any>, options: import("sequelize/types/lib/instance-validator").ValidationOptions) => void): void;
24
+ afterValidate(name: string, fn: (instance: sequelize.Model<any, any>, options: import("sequelize/types/lib/instance-validator").ValidationOptions) => void): void;
25
+ afterValidate(fn: (instance: sequelize.Model<any, any>, options: import("sequelize/types/lib/instance-validator").ValidationOptions) => void): void;
26
+ beforeCreate(name: string, fn: (attributes: sequelize.Model<any, any>, options: sequelize.CreateOptions) => void): void;
27
+ beforeCreate(fn: (attributes: sequelize.Model<any, any>, options: sequelize.CreateOptions) => void): void;
28
+ afterCreate(name: string, fn: (attributes: sequelize.Model<any, any>, options: sequelize.CreateOptions) => void): void;
29
+ afterCreate(fn: (attributes: sequelize.Model<any, any>, options: sequelize.CreateOptions) => void): void;
30
+ beforeDestroy(name: string, fn: (instance: sequelize.Model<any, any>, options: sequelize.InstanceDestroyOptions) => void): void;
31
+ beforeDestroy(fn: (instance: sequelize.Model<any, any>, options: sequelize.InstanceDestroyOptions) => void): void;
32
+ afterDestroy(name: string, fn: (instance: sequelize.Model<any, any>, options: sequelize.InstanceDestroyOptions) => void): void;
33
+ afterDestroy(fn: (instance: sequelize.Model<any, any>, options: sequelize.InstanceDestroyOptions) => void): void;
34
+ beforeUpdate(name: string, fn: (instance: sequelize.Model<any, any>, options: sequelize.UpdateOptions) => void): void;
35
+ beforeUpdate(fn: (instance: sequelize.Model<any, any>, options: sequelize.UpdateOptions) => void): void;
36
+ afterUpdate(name: string, fn: (instance: sequelize.Model<any, any>, options: sequelize.UpdateOptions) => void): void;
37
+ afterUpdate(fn: (instance: sequelize.Model<any, any>, options: sequelize.UpdateOptions) => void): void;
38
+ beforeBulkCreate(name: string, fn: (instances: sequelize.Model<any, any>[], options: sequelize.BulkCreateOptions) => void): void;
39
+ beforeBulkCreate(fn: (instances: sequelize.Model<any, any>[], options: sequelize.BulkCreateOptions) => void): void;
40
+ afterBulkCreate(name: string, fn: (instances: sequelize.Model<any, any>[], options: sequelize.BulkCreateOptions) => void): void;
41
+ afterBulkCreate(fn: (instances: sequelize.Model<any, any>[], options: sequelize.BulkCreateOptions) => void): void;
42
+ beforeBulkDestroy(name: string, fn: (options: sequelize.BulkCreateOptions) => void): void;
43
+ beforeBulkDestroy(fn: (options: sequelize.BulkCreateOptions) => void): void;
44
+ afterBulkDestroy(name: string, fn: (options: sequelize.DestroyOptions) => void): void;
45
+ afterBulkDestroy(fn: (options: sequelize.DestroyOptions) => void): void;
46
+ beforeBulkUpdate(name: string, fn: (options: sequelize.UpdateOptions) => void): void;
47
+ beforeBulkUpdate(fn: (options: sequelize.UpdateOptions) => void): void;
48
+ afterBulkUpdate(name: string, fn: (options: sequelize.UpdateOptions) => void): void;
49
+ afterBulkUpdate(fn: (options: sequelize.UpdateOptions) => void): void;
50
+ beforeFind(name: string, fn: (options: sequelize.FindOptions) => void): void;
51
+ beforeFind(fn: (options: sequelize.FindOptions) => void): void;
52
+ beforeFindAfterExpandIncludeAll(name: string, fn: (options: sequelize.FindOptions) => void): void;
53
+ beforeFindAfterExpandIncludeAll(fn: (options: sequelize.FindOptions) => void): void;
54
+ beforeFindAfterOptions(name: string, fn: (options: sequelize.FindOptions) => void): void;
55
+ beforeFindAfterOptions(fn: (options: sequelize.FindOptions) => void): void;
56
+ afterFind(name: string, fn: (instancesOrInstance: sequelize.Model<any, any> | sequelize.Model<any, any>[] | null, options: sequelize.FindOptions) => void): void;
57
+ afterFind(fn: (instancesOrInstance: sequelize.Model<any, any> | sequelize.Model<any, any>[] | null, options: sequelize.FindOptions) => void): void;
58
+ beforeDefine(name: string, fn: (attributes: sequelize.ModelAttributes<sequelize.Model<any, any>>, options: sequelize.ModelOptions<sequelize.Model<any, any>>) => void): void;
59
+ beforeDefine(fn: (attributes: sequelize.ModelAttributes<sequelize.Model<any, any>>, options: sequelize.ModelOptions<sequelize.Model<any, any>>) => void): void;
60
+ afterDefine(name: string, fn: (model: typeof sequelize.Model) => void): void;
61
+ afterDefine(fn: (model: typeof sequelize.Model) => void): void;
62
+ beforeInit(name: string, fn: (config: sequelize.Config, options: sequelize.Options) => void): void;
63
+ beforeInit(fn: (config: sequelize.Config, options: sequelize.Options) => void): void;
64
+ afterInit(name: string, fn: (sequelize: sequelize.Sequelize) => void): void;
65
+ afterInit(fn: (sequelize: sequelize.Sequelize) => void): void;
66
+ beforeBulkSync(name: string, fn: (options: sequelize.SyncOptions) => import("sequelize/types/lib/hooks").HookReturn): void;
67
+ beforeBulkSync(fn: (options: sequelize.SyncOptions) => import("sequelize/types/lib/hooks").HookReturn): void;
68
+ afterBulkSync(name: string, fn: (options: sequelize.SyncOptions) => import("sequelize/types/lib/hooks").HookReturn): void;
69
+ afterBulkSync(fn: (options: sequelize.SyncOptions) => import("sequelize/types/lib/hooks").HookReturn): void;
70
+ beforeSync(name: string, fn: (options: sequelize.SyncOptions) => import("sequelize/types/lib/hooks").HookReturn): void;
71
+ beforeSync(fn: (options: sequelize.SyncOptions) => import("sequelize/types/lib/hooks").HookReturn): void;
72
+ afterSync(name: string, fn: (options: sequelize.SyncOptions) => import("sequelize/types/lib/hooks").HookReturn): void;
73
+ afterSync(fn: (options: sequelize.SyncOptions) => import("sequelize/types/lib/hooks").HookReturn): void;
74
+ getDialect(): string;
75
+ getQueryInterface(): sequelize.QueryInterface;
76
+ define(modelName: string, attributes: sequelize.ModelAttributes<sequelize.Model<any, any>>, options?: sequelize.ModelOptions<sequelize.Model<any, any>> | undefined): typeof sequelize.Model;
77
+ model(modelName: string): sequelize.ModelCtor<sequelize.Model<any, any>>;
78
+ isDefined(modelName: string): boolean;
79
+ import<T extends typeof sequelize.Model>(path: string, defineFunction?: ((sequelize: sequelize.Sequelize, dataTypes: typeof sequelize.DataTypes) => T) | undefined): T;
80
+ query(sql: string | {
81
+ query: string;
82
+ values: unknown[];
83
+ }, options: sequelize.QueryOptionsWithType<sequelize.QueryTypes.UPDATE>): any;
84
+ query(sql: string | {
85
+ query: string;
86
+ values: unknown[];
87
+ }, options: sequelize.QueryOptionsWithType<sequelize.QueryTypes.BULKUPDATE>): any;
88
+ query(sql: string | {
89
+ query: string;
90
+ values: unknown[];
91
+ }, options: sequelize.QueryOptionsWithType<sequelize.QueryTypes.INSERT>): any;
92
+ query(sql: string | {
93
+ query: string;
94
+ values: unknown[];
95
+ }, options: sequelize.QueryOptionsWithType<sequelize.QueryTypes.UPSERT>): any;
96
+ query(sql: string | {
97
+ query: string;
98
+ values: unknown[];
99
+ }, options: sequelize.QueryOptionsWithType<sequelize.QueryTypes.DELETE>): any;
100
+ query(sql: string | {
101
+ query: string;
102
+ values: unknown[];
103
+ }, options: sequelize.QueryOptionsWithType<sequelize.QueryTypes.BULKDELETE>): any;
104
+ query(sql: string | {
105
+ query: string;
106
+ values: unknown[];
107
+ }, options: sequelize.QueryOptionsWithType<sequelize.QueryTypes.SHOWTABLES>): any;
108
+ query(sql: string | {
109
+ query: string;
110
+ values: unknown[];
111
+ }, options: sequelize.QueryOptionsWithType<sequelize.QueryTypes.DESCRIBE>): any;
112
+ query<M extends sequelize.Model<any, any>>(sql: string | {
113
+ query: string;
114
+ values: unknown[];
115
+ }, options: sequelize.QueryOptionsWithModel): any;
116
+ query<T_1 extends object>(sql: string | {
117
+ query: string;
118
+ values: unknown[];
119
+ }, options: sequelize.QueryOptionsWithType<sequelize.QueryTypes.SELECT> & {
120
+ plain: true;
121
+ }): any;
122
+ query<T_2 extends object>(sql: string | {
123
+ query: string;
124
+ values: unknown[];
125
+ }, options: sequelize.QueryOptionsWithType<sequelize.QueryTypes.SELECT>): any;
126
+ query(sql: string | {
127
+ query: string;
128
+ values: unknown[];
129
+ }, options: (sequelize.QueryOptions | sequelize.QueryOptionsWithType<sequelize.QueryTypes.RAW>) & {
130
+ plain: true;
131
+ }): any;
132
+ query(sql: string | {
133
+ query: string;
134
+ values: unknown[];
135
+ }, options?: sequelize.QueryOptions | sequelize.QueryOptionsWithType<sequelize.QueryTypes.RAW> | undefined): any;
136
+ random(): sequelize.Utils.Fn;
137
+ set(variables: object, options: sequelize.QueryOptionsTransactionRequired): any;
138
+ escape(value: string | number | Date): string;
139
+ createSchema(schema: string, options: sequelize.Logging): any;
140
+ showAllSchemas(options: sequelize.Logging): any;
141
+ dropSchema(schema: string, options: sequelize.Logging): any;
142
+ dropAllSchemas(options: sequelize.Logging): any;
143
+ sync(options?: sequelize.SyncOptions | undefined): any;
144
+ truncate(options?: sequelize.DestroyOptions | undefined): any;
145
+ drop(options?: sequelize.DropOptions | undefined): any;
146
+ authenticate(options?: sequelize.QueryOptions | undefined): any;
147
+ validate(options?: sequelize.QueryOptions | undefined): any;
148
+ transaction<T_3>(options: sequelize.TransactionOptions, autoCallback: (t: sequelize.Transaction) => PromiseLike<T_3>): any;
149
+ transaction<T_4>(autoCallback: (t: sequelize.Transaction) => PromiseLike<T_4>): any;
150
+ transaction(options?: sequelize.TransactionOptions | undefined): any;
151
+ close(): any;
152
+ databaseVersion(): any;
153
+ addHook<K extends keyof import("sequelize/types/lib/hooks").SequelizeHooks>(hookType: K, name: string, fn: import("sequelize/types/lib/hooks").SequelizeHooks[K]): any;
154
+ addHook<K_1 extends keyof import("sequelize/types/lib/hooks").SequelizeHooks>(hookType: K_1, fn: import("sequelize/types/lib/hooks").SequelizeHooks[K_1]): any;
155
+ removeHook<K_2 extends keyof import("sequelize/types/lib/hooks").SequelizeHooks>(hookType: K_2, name: string): any;
156
+ hasHook<K_3 extends keyof import("sequelize/types/lib/hooks").SequelizeHooks>(hookType: K_3): boolean;
157
+ hasHooks<K_4 extends keyof import("sequelize/types/lib/hooks").SequelizeHooks>(hookType: K_4): boolean;
158
+ };
159
+ /**
160
+ * Connect to DB.
161
+ */
162
+ export default _default;
@@ -0,0 +1,221 @@
1
+ import sequelize from 'sequelize';
2
+ /**
3
+ * Model base class.
4
+ */
5
+ export default class Model extends sequelize.Model {
6
+ /**
7
+ * The name of the table that the model accesses.
8
+ * This member must be defined in a subclass.
9
+ * @type {string}
10
+ */
11
+ protected static table: string;
12
+ /**
13
+ * List of columns in the table accessed by this model.
14
+ * This member must be defined in a subclass.
15
+ * @type {sequelize.ModelAttributes}
16
+ */
17
+ protected static attributes: sequelize.ModelAttributes;
18
+ /**
19
+ * Column type.
20
+ *
21
+ * @see https://sequelize.org/master/variable/index.html#static-variable-DataTypes
22
+ * @type {sequelize.DataTypes}
23
+ */
24
+ static readonly DataTypes: {
25
+ [key: string]: any;
26
+ };
27
+ /**
28
+ * An enum of query types used by sequelize.query
29
+ *
30
+ * @see https://sequelize.org/master/variable/index.html#static-variable-QueryTypes
31
+ * @type {sequelize.QueryTypes}
32
+ */
33
+ static readonly QueryTypes: {
34
+ [key: string]: string;
35
+ };
36
+ /**
37
+ * Operator.
38
+ *
39
+ * @example
40
+ * // Sequelize provides several operators.
41
+ * Post.findAll({
42
+ * where: {
43
+ * [this.Op.and]: [{a: 5}, {b: 6}], // (a = 5) AND (b = 6)
44
+ * [this.Op.or]: [{a: 5}, {b: 6}], // (a = 5) OR (b = 6)
45
+ * someAttribute: {
46
+ * // Basics
47
+ * [this.Op.eq]: 3, // = 3
48
+ * [this.Op.ne]: 20, // != 20
49
+ * [this.Op.is]: null, // IS NULL
50
+ * [this.Op.not]: true, // IS NOT TRUE
51
+ * [this.Op.or]: [5, 6], // (someAttribute = 5) OR (someAttribute = 6)
52
+ *
53
+ * // Using dialect specific column identifiers (PG in the following example):
54
+ * [this.Op.col]: 'user.organization_id', // = "user"."organization_id"
55
+ *
56
+ * // Number comparisons
57
+ * [this.Op.gt]: 6, // > 6
58
+ * [this.Op.gte]: 6, // >= 6
59
+ * [this.Op.lt]: 10, // < 10
60
+ * [this.Op.lte]: 10, // <= 10
61
+ * [this.Op.between]: [6, 10], // BETWEEN 6 AND 10
62
+ * [this.Op.notBetween]: [11, 15], // NOT BETWEEN 11 AND 15
63
+ *
64
+ * // Other operators
65
+ * [this.Op.all]: this.literal('SELECT 1'), // > ALL (SELECT 1)
66
+ * [this.Op.in]: [1, 2], // IN [1, 2]
67
+ * [this.Op.notIn]: [1, 2], // NOT IN [1, 2]
68
+ * [this.Op.like]: '%hat', // LIKE '%hat'
69
+ * [this.Op.notLike]: '%hat', // NOT LIKE '%hat'
70
+ * [this.Op.startsWith]: 'hat', // LIKE 'hat%'
71
+ * [this.Op.endsWith]: 'hat', // LIKE '%hat'
72
+ * [this.Op.substring]: 'hat', // LIKE '%hat%'
73
+ * [this.Op.iLike]: '%hat', // ILIKE '%hat' (case insensitive) (PG only)
74
+ * [this.Op.notILike]: '%hat', // NOT ILIKE '%hat' (PG only)
75
+ * [this.Op.regexp]: '^[h|a|t]', // REGEXP/~ '^[h|a|t]' (MySQL/PG only)
76
+ * [this.Op.notRegexp]: '^[h|a|t]', // NOT REGEXP/!~ '^[h|a|t]' (MySQL/PG only)
77
+ * [this.Op.iRegexp]: '^[h|a|t]', // ~* '^[h|a|t]' (PG only)
78
+ * [this.Op.notIRegexp]: '^[h|a|t]', // !~* '^[h|a|t]' (PG only)
79
+ * [this.Op.any]: [2, 3], // ANY ARRAY[2, 3]::INTEGER (PG only)
80
+ * // In Postgres, this.Op.like/this.Op.iLike/this.Op.notLike can be combined to this.Op.any:
81
+ * [this.Op.like]: {[this.Op.any]: ['cat', 'hat']} // LIKE ANY ARRAY['cat', 'hat']
82
+ * // There are more postgres-only range operators, see below
83
+ * }
84
+ * }
85
+ * });
86
+ *
87
+ * @type {sequelize.Op}
88
+ */
89
+ static readonly Op: {
90
+ [key: string]: any;
91
+ };
92
+ /**
93
+ * Creates a object representing a database function. This can be used in search queries, both in where and
94
+ * order parts, and as default values in column definitions. If you want to refer to columns in your
95
+ * function, you should use `sequelize.col`, so that the columns are properly interpreted as columns and not a strings.
96
+ *
97
+ * @example
98
+ * // Convert a user's username to upper case
99
+ * Post.update({
100
+ * username: this.fn('upper', this.col('username'))
101
+ * })
102
+ *
103
+ * @type {sequelize.fn}
104
+ */
105
+ static readonly fn: (fn: string, ...args: unknown[]) => any;
106
+ /**
107
+ * Creates a object representing a column in the DB. This is often useful in conjunction with
108
+ * `sequelize.fn`, since raw string arguments to fn will be escaped.
109
+ *
110
+ * @type {sequelize.col}
111
+ */
112
+ static readonly col: (col: string) => any;
113
+ /**
114
+ * Creates a object representing a literal, i.e. something that will not be escaped.
115
+ *
116
+ * @type {sequelize.literal}
117
+ */
118
+ static readonly literal: (val: string) => any;
119
+ /**
120
+ * A way of specifying attr = condition.
121
+ *
122
+ * @type {sequelize.where}
123
+ */
124
+ static readonly where: (attr: sequelize.AttributeType, comparator: string, logic: sequelize.LogicType) => sequelize.Utils.Where;
125
+ /**
126
+ * Reference to sequelize.Transaction.
127
+ * This includes properties such as isolation level enums used with the transaction option.
128
+ *
129
+ * @example
130
+ * BookModel.Transaction.ISOLATION_LEVELS.READ_UNCOMMITTED // "READ UNCOMMITTED"
131
+ * BookModel.Transaction.ISOLATION_LEVELS.READ_COMMITTED // "READ COMMITTED"
132
+ * BookModel.Transaction.ISOLATION_LEVELS.REPEATABLE_READ // "REPEATABLE READ"
133
+ * BookModel.Transaction.ISOLATION_LEVELS.SERIALIZABLE // "SERIALIZABLE"
134
+ *
135
+ * @see https://sequelize.org/master/class/lib/transaction.js~Transaction.html
136
+ * @type {sequelize.Transaction}
137
+ */
138
+ static readonly Transaction: (typeof sequelize.Transaction);
139
+ /**
140
+ * Initialize the model that represents the table in the DB with attributes and options.
141
+ * This method is called automatically from within the "express-sweet.mount" method, so you don't have to run it yourself.
142
+ *
143
+ * @return {typeof Model} Returns this model class itself.
144
+ */
145
+ static initialize(): (typeof Model);
146
+ /**
147
+ * Associate the model.
148
+ * Define associations with other models such as "hasOne", "hasMany", "belongsTo", "belongsToMany".
149
+ * If you omit the alias (as) option, the associated name will be hasOne, singular for belongsTo, and plural for hasMany.
150
+ * This method is called automatically from within the "express-sweet.mount" method, so you don't have to run it yourself.
151
+ *
152
+ * @see https://sequelize.org/master/manual/assocs.html
153
+ */
154
+ static association(): void;
155
+ /**
156
+ * Starts a transaction and returns a transaction object to identify the running transaction.
157
+ *
158
+ * @example
159
+ * // Simple transaction usage example.
160
+ * let transaction;
161
+ * try {
162
+ * transaction = await BookModel.begin();
163
+ * const book = await BookModel.create({title: 'When Im Gone'}, {transaction});
164
+ * await transaction.commit();
165
+ * } catch(error) {
166
+ * if (transaction)
167
+ * await transaction.rollback();
168
+ * }
169
+ *
170
+ * // You can also use transaction options.
171
+ * let transaction;
172
+ * try {
173
+ * transaction = await BookModel.begin({
174
+ * isolationLevel: BookModel.Transaction.ISOLATION_LEVELS.REPEATABLE_READ,
175
+ * type: BookModel.Transaction.TYPES.DEFERRED,
176
+ * });
177
+ * const book = await BookModel.findOne({where: {id: 1}}, {transaction});
178
+ * book.title = 'When Im Gone';
179
+ * await book.save({transaction});
180
+ * await transaction.commit();
181
+ *
182
+ * // Check the update result.
183
+ * // Output: New title of book: When Im Gone
184
+ * await book.reload();
185
+ * console.log(`New title of book: ${book.title}`);
186
+ * } catch (err) {
187
+ * if (transaction)
188
+ * await transaction.rollback();
189
+ * }
190
+ *
191
+ * @see https://sequelize.org/master/manual/transactions.html
192
+ * @param {sequelize.TransactionOptions} opts? Options provided when the transaction is created.
193
+ * @return {Promise<sequelize.Transaction>} Returns a transaction object to identify the transaction being executed.
194
+ */
195
+ static begin(opts?: sequelize.TransactionOptions): Promise<sequelize.Transaction>;
196
+ /**
197
+ * Returns data that matches the ID.
198
+ */
199
+ static findById(id: number): Promise<{} | null>;
200
+ /**
201
+ * Raw Queries.
202
+ * As there are often use cases in which it is just easier to execute raw / already prepared SQL queries, you can use the Model.query method.
203
+ *
204
+ * @example
205
+ * // By default the function will return two arguments - a results array, and an object containing metadata (such as amount of affected rows, etc).
206
+ * // Note that since this is a raw query, the metadata are dialect specific.
207
+ * const [results, metadata] = await BookModel.query("UPDATE book SET title = 'When Im Gone' WHERE id = 1");
208
+ *
209
+ * // In cases where you don't need to access the metadata you can pass in a query type to tell sequelize how to format the results. For example, for a simple select query you could do:
210
+ * // We didn't need to destructure the result here - the results were returned directly
211
+ * const users = await BookModel.query("SELECT * FROM book", {type: BookModel.QueryTypes.SELECT});
212
+ *
213
+ * @see https://sequelize.org/master/manual/raw-queries.html
214
+ *
215
+ * @param {string} sql SQL string.
216
+ * @param {object} opts Query options.
217
+ * @return {Promise<any>} By default, the function will return two arguments: an array of results, and a metadata object, containing number of affected rows etc.
218
+ * If you are running a type of query where you don't need the metadata, for example a SELECT query, you can pass in a query type to make sequelize format the results:
219
+ */
220
+ static query(sql: string, opts: sequelize.QueryOptionsWithType<sequelize.QueryTypes.UPDATE> | sequelize.QueryOptionsWithType<sequelize.QueryTypes.BULKUPDATE> | sequelize.QueryOptionsWithType<sequelize.QueryTypes.INSERT> | sequelize.QueryOptionsWithType<sequelize.QueryTypes.UPSERT> | sequelize.QueryOptionsWithType<sequelize.QueryTypes.DELETE> | sequelize.QueryOptionsWithType<sequelize.QueryTypes.BULKDELETE> | sequelize.QueryOptionsWithType<sequelize.QueryTypes.SHOWTABLES> | sequelize.QueryOptionsWithType<sequelize.QueryTypes.DESCRIBE> | sequelize.QueryOptionsWithType<sequelize.QueryTypes.SELECT> | sequelize.QueryOptionsWithType<sequelize.QueryTypes.SELECT> | sequelize.QueryOptionsWithType<sequelize.QueryTypes.RAW> | sequelize.QueryOptionsWithType<sequelize.QueryTypes.RAW>): Promise<any>;
221
+ }
@@ -0,0 +1,4 @@
1
+ import Database from './Database';
2
+ import Model from './Model';
3
+ import loadModels from './loadModels';
4
+ export { Database, Model, loadModels };
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Model initialization and association.
3
+ * All models must be pre-loaded before associating models.So it loads and caches all defined models in advance.
4
+ * This must be done before any method that may load other models is called.
5
+ */
6
+ export default function (): void;
@@ -0,0 +1,29 @@
1
+ /**
2
+ * API error.
3
+ */
4
+ export default class extends Error {
5
+ /**
6
+ * Error name.
7
+ * @type {string}
8
+ */
9
+ name: string;
10
+ /**
11
+ * HTTP status code.
12
+ * @type {number}
13
+ */
14
+ statusCode: number;
15
+ /**
16
+ * Constructs a API error.
17
+ *
18
+ * @example
19
+ * const ApiError = require('express-sweet').exceptions.ApiError;
20
+ *
21
+ * // Throw an API error.
22
+ * throw new ApiError('UserNotFount', 400, 'user not found');
23
+ *
24
+ * @param {string} name Error name.
25
+ * @param {number} statusCode HTTP status code.
26
+ * @param {string} message Error message.
27
+ */
28
+ constructor(name: string, statusCode: number, message?: string);
29
+ }
@@ -0,0 +1,2 @@
1
+ import ApiError from './ApiError';
2
+ export { ApiError };