express-sweet 2.0.2 → 2.0.4

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 (58) hide show
  1. package/CHANGELOG.md +76 -9
  2. package/LICENSE +1 -1
  3. package/README.md +2193 -20
  4. package/configuration_sample/cjs/authentication.js +103 -0
  5. package/configuration_sample/cjs/config.js +74 -0
  6. package/configuration_sample/cjs/database.js +35 -0
  7. package/configuration_sample/cjs/view.js +36 -0
  8. package/configuration_sample/esm/authentication.js +103 -0
  9. package/configuration_sample/esm/config.js +74 -0
  10. package/configuration_sample/esm/database.js +35 -0
  11. package/configuration_sample/esm/view.js +36 -0
  12. package/dist/build.cjs +22 -22
  13. package/dist/build.mjs +22 -22
  14. package/package.json +8 -11
  15. package/screencaps/belongs-to-many.png +0 -0
  16. package/screencaps/belongs-to.png +0 -0
  17. package/screencaps/demonstration.webp +0 -0
  18. package/screencaps/has-many.png +0 -0
  19. package/screencaps/has-one.png +0 -0
  20. package/types/database/Database.d.ts +3 -171
  21. package/types/database/Model.d.ts +22 -19
  22. package/types/database/loadModels.d.ts +2 -1
  23. package/types/handlebars_helpers/array.d.ts +20 -0
  24. package/types/handlebars_helpers/comparison.d.ts +59 -189
  25. package/types/handlebars_helpers/date.d.ts +4 -4
  26. package/types/handlebars_helpers/html.d.ts +3 -3
  27. package/types/handlebars_helpers/index.d.ts +2 -0
  28. package/types/handlebars_helpers/layouts.d.ts +21 -0
  29. package/types/handlebars_helpers/math.d.ts +14 -21
  30. package/types/handlebars_helpers/number.d.ts +5 -5
  31. package/types/handlebars_helpers/object.d.ts +4 -4
  32. package/types/handlebars_helpers/string.d.ts +8 -13
  33. package/types/interfaces/AuthenticationConfig.d.ts +4 -11
  34. package/types/interfaces/BasicConfig.d.ts +11 -15
  35. package/types/interfaces/ViewConfig.d.ts +1 -3
  36. package/types/middlewares/Authentication.d.ts +3 -1
  37. package/types/middlewares/CORS.d.ts +3 -1
  38. package/types/middlewares/Environment.d.ts +3 -3
  39. package/types/middlewares/ErrorHandler.d.ts +3 -1
  40. package/types/middlewares/Http.d.ts +3 -1
  41. package/types/middlewares/Local.d.ts +3 -1
  42. package/types/middlewares/View.d.ts +6 -2
  43. package/types/mount.d.ts +3 -2
  44. package/types/routing/Router.d.ts +3 -1
  45. package/types/services/Authentication.d.ts +4 -2
  46. package/types/utils/Types.d.ts +2 -2
  47. package/types/utils/isAsyncFunction.d.ts +7 -7
  48. package/types/utils/isFunction.d.ts +8 -8
  49. package/types/utils/loadAuthenticationConfig.d.ts +2 -2
  50. package/types/utils/loadBasicConfig.d.ts +2 -2
  51. package/types/utils/loadDatabaseConfig.d.ts +2 -2
  52. package/types/utils/loadViewConfig.d.ts +2 -2
  53. package/INSTALL-Redis.md +0 -77
  54. package/QUICK_START.md +0 -149
  55. package/screencaps/login.jpg +0 -0
  56. package/screencaps/personal.jpg +0 -0
  57. package/screencaps/user-editing.jpg +0 -0
  58. package/screencaps/users.jpg +0 -0
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "express-sweet",
3
- "version": "2.0.2",
4
- "description": "Express Extension.",
3
+ "version": "2.0.4",
4
+ "description": "EXPRESS SWEET is a powerful Express.js extension that streamlines your workflow and boosts productivity with a suite of utilities and enhancements.",
5
5
  "type": "module",
6
6
  "main": "dist/build.cjs",
7
7
  "module": "dist/build.mjs",
@@ -16,12 +16,11 @@
16
16
  "dist/",
17
17
  "types/",
18
18
  "CHANGELOG.md",
19
- "INSTALL-Redis.md",
20
19
  "LICENSE",
21
20
  "package.json",
22
21
  "README.md",
23
- "QUICK_START.md",
24
- "screencaps/"
22
+ "screencaps/",
23
+ "configuration_sample/"
25
24
  ],
26
25
  "scripts": {
27
26
  "build": "node --max-old-space-size=8192 node_modules/rollup/dist/bin/rollup -c rollup.config.js",
@@ -71,24 +70,23 @@
71
70
  "cookie-parser": "~1.4.4",
72
71
  "dotenv": "^8.2.0",
73
72
  "express": "^4.19.2",
74
- "express-hbs": "^2.5.0",
73
+ "express-handlebars": "^7.1.3",
75
74
  "express-session": "^1.18.0",
76
75
  "glob": "^10.3.12",
77
- "handlebars-extd": "^1.0.7",
78
76
  "hbs": "~4.0.4",
79
77
  "http-errors": "~1.6.3",
80
78
  "mariadb": "^3.2.3",
81
79
  "moment": "^2.30.1",
82
80
  "morgan": "^1.10.0",
83
81
  "multer": "^1.4.5-lts.1",
84
- "passport": "^0.4.1",
82
+ "passport": "^0.7.0",
85
83
  "passport-local": "^1.0.0",
86
84
  "redis": "^4.6.8",
87
85
  "sequelize": "^6.37.1"
88
86
  },
89
87
  "devDependencies": {
90
- "@rollup/plugin-alias": "^5.1.0",
91
88
  "@rollup/plugin-commonjs": "^26.0.1",
89
+ "@rollup/plugin-json": "^6.1.0",
92
90
  "@rollup/plugin-node-resolve": "^15.2.3",
93
91
  "@rollup/plugin-terser": "^0.4.4",
94
92
  "@types/cookie-parser": "^1.4.2",
@@ -99,10 +97,9 @@
99
97
  "@types/morgan": "^1.9.9",
100
98
  "@types/multer": "^1.4.11",
101
99
  "@types/node": "^22.5.1",
102
- "@types/passport": "^1.0.6",
100
+ "@types/passport": "^1.0.16",
103
101
  "@types/passport-local": "^1.0.33",
104
102
  "rollup": "^4.21.2",
105
- "rollup-plugin-json": "^4.0.0",
106
103
  "rollup-plugin-typescript2": "^0.36.0",
107
104
  "typescript": "^5.5.4"
108
105
  }
Binary file
Binary file
Binary file
Binary file
Binary file
@@ -1,179 +1,11 @@
1
1
  import sequelize from 'sequelize';
2
2
  /**
3
- * Connect to DB.
3
+ * Database class.
4
4
  */
5
- declare const _default: {
5
+ export default class extends sequelize.Sequelize {
6
6
  /**
7
7
  * Returns true if the DB can be connected.
8
- * @example
9
- * const database = require('express-sweet').database.Database;
10
- *
11
- * // Check database connection.
12
- * const isConnected = await database.isConnect();
13
8
  * @return {Promise<boolean>} Returns true if it can connect to the database, false if it cannot.
14
9
  */
15
10
  isConnect(): Promise<boolean>;
16
- fn: typeof sequelize.fn;
17
- col: typeof sequelize.col;
18
- cast: typeof sequelize.cast;
19
- literal: typeof sequelize.literal;
20
- and: typeof sequelize.and;
21
- or: typeof sequelize.or;
22
- json: typeof sequelize.json;
23
- where: typeof sequelize.where;
24
- Sequelize: typeof sequelize.Sequelize;
25
- readonly config: sequelize.Config;
26
- readonly modelManager: import("sequelize/types/model-manager").ModelManager;
27
- readonly connectionManager: import("sequelize/types/dialects/abstract/connection-manager").ConnectionManager;
28
- readonly models: {
29
- [key: string]: sequelize.ModelCtor<sequelize.Model>;
30
- };
31
- beforeValidate(name: string, fn: (instance: sequelize.Model, options: import("sequelize/types/instance-validator").ValidationOptions) => void): void;
32
- beforeValidate(fn: (instance: sequelize.Model, options: import("sequelize/types/instance-validator").ValidationOptions) => void): void;
33
- afterValidate(name: string, fn: (instance: sequelize.Model, options: import("sequelize/types/instance-validator").ValidationOptions) => void): void;
34
- afterValidate(fn: (instance: sequelize.Model, options: import("sequelize/types/instance-validator").ValidationOptions) => void): void;
35
- beforeCreate(name: string, fn: (attributes: sequelize.Model, options: sequelize.CreateOptions<any>) => void): void;
36
- beforeCreate(fn: (attributes: sequelize.Model, options: sequelize.CreateOptions<any>) => void): void;
37
- afterCreate(name: string, fn: (attributes: sequelize.Model, options: sequelize.CreateOptions<any>) => void): void;
38
- afterCreate(fn: (attributes: sequelize.Model, options: sequelize.CreateOptions<any>) => void): void;
39
- beforeDestroy(name: string, fn: (instance: sequelize.Model, options: sequelize.InstanceDestroyOptions) => void): void;
40
- beforeDestroy(fn: (instance: sequelize.Model, options: sequelize.InstanceDestroyOptions) => void): void;
41
- afterDestroy(name: string, fn: (instance: sequelize.Model, options: sequelize.InstanceDestroyOptions) => void): void;
42
- afterDestroy(fn: (instance: sequelize.Model, options: sequelize.InstanceDestroyOptions) => void): void;
43
- beforeUpdate(name: string, fn: (instance: sequelize.Model, options: sequelize.UpdateOptions<any>) => void): void;
44
- beforeUpdate(fn: (instance: sequelize.Model, options: sequelize.UpdateOptions<any>) => void): void;
45
- afterUpdate(name: string, fn: (instance: sequelize.Model, options: sequelize.UpdateOptions<any>) => void): void;
46
- afterUpdate(fn: (instance: sequelize.Model, options: sequelize.UpdateOptions<any>) => void): void;
47
- beforeBulkCreate(name: string, fn: (instances: sequelize.Model[], options: sequelize.BulkCreateOptions<any>) => void): void;
48
- beforeBulkCreate(fn: (instances: sequelize.Model[], options: sequelize.BulkCreateOptions<any>) => void): void;
49
- afterBulkCreate(name: string, fn: (instances: sequelize.Model[], options: sequelize.BulkCreateOptions<any>) => void): void;
50
- afterBulkCreate(fn: (instances: sequelize.Model[], options: sequelize.BulkCreateOptions<any>) => void): void;
51
- beforeBulkDestroy(name: string, fn: (options: sequelize.BulkCreateOptions<any>) => void): void;
52
- beforeBulkDestroy(fn: (options: sequelize.BulkCreateOptions<any>) => void): void;
53
- afterBulkDestroy(name: string, fn: (options: sequelize.DestroyOptions<any>) => void): void;
54
- afterBulkDestroy(fn: (options: sequelize.DestroyOptions<any>) => void): void;
55
- beforeBulkUpdate(name: string, fn: (options: sequelize.UpdateOptions<any>) => void): void;
56
- beforeBulkUpdate(fn: (options: sequelize.UpdateOptions<any>) => void): void;
57
- afterBulkUpdate(name: string, fn: (options: sequelize.UpdateOptions<any>) => void): void;
58
- afterBulkUpdate(fn: (options: sequelize.UpdateOptions<any>) => void): void;
59
- beforeFind(name: string, fn: (options: sequelize.FindOptions<any>) => void): void;
60
- beforeFind(fn: (options: sequelize.FindOptions<any>) => void): void;
61
- beforeFindAfterExpandIncludeAll(name: string, fn: (options: sequelize.FindOptions<any>) => void): void;
62
- beforeFindAfterExpandIncludeAll(fn: (options: sequelize.FindOptions<any>) => void): void;
63
- beforeFindAfterOptions(name: string, fn: (options: sequelize.FindOptions<any>) => void): void;
64
- beforeFindAfterOptions(fn: (options: sequelize.FindOptions<any>) => void): void;
65
- afterFind(name: string, fn: (instancesOrInstance: sequelize.Model[] | sequelize.Model | null, options: sequelize.FindOptions<any>) => void): void;
66
- afterFind(fn: (instancesOrInstance: sequelize.Model[] | sequelize.Model | null, options: sequelize.FindOptions<any>) => void): void;
67
- beforeDefine(name: string, fn: (attributes: sequelize.ModelAttributes<sequelize.Model, any>, options: sequelize.ModelOptions) => void): void;
68
- beforeDefine(fn: (attributes: sequelize.ModelAttributes<sequelize.Model, any>, options: sequelize.ModelOptions) => void): void;
69
- afterDefine(name: string, fn: (model: sequelize.ModelType) => void): void;
70
- afterDefine(fn: (model: sequelize.ModelType) => void): void;
71
- beforeInit(name: string, fn: (config: sequelize.Config, options: sequelize.Options) => void): void;
72
- beforeInit(fn: (config: sequelize.Config, options: sequelize.Options) => void): void;
73
- afterInit(name: string, fn: (sequelize: sequelize.Sequelize) => void): void;
74
- afterInit(fn: (sequelize: sequelize.Sequelize) => void): void;
75
- beforeBulkSync(name: string, fn: (options: sequelize.SyncOptions) => import("sequelize/types/hooks").HookReturn): void;
76
- beforeBulkSync(fn: (options: sequelize.SyncOptions) => import("sequelize/types/hooks").HookReturn): void;
77
- afterBulkSync(name: string, fn: (options: sequelize.SyncOptions) => import("sequelize/types/hooks").HookReturn): void;
78
- afterBulkSync(fn: (options: sequelize.SyncOptions) => import("sequelize/types/hooks").HookReturn): void;
79
- beforeSync(name: string, fn: (options: sequelize.SyncOptions) => import("sequelize/types/hooks").HookReturn): void;
80
- beforeSync(fn: (options: sequelize.SyncOptions) => import("sequelize/types/hooks").HookReturn): void;
81
- afterSync(name: string, fn: (options: sequelize.SyncOptions) => import("sequelize/types/hooks").HookReturn): void;
82
- afterSync(fn: (options: sequelize.SyncOptions) => import("sequelize/types/hooks").HookReturn): void;
83
- getDialect(): string;
84
- getDatabaseName(): string;
85
- getQueryInterface(): sequelize.QueryInterface;
86
- define<M extends sequelize.Model, TAttributes = sequelize.Attributes<M>>(modelName: string, attributes: sequelize.ModelAttributes<M, TAttributes>, options?: sequelize.ModelOptions<M>): sequelize.ModelCtor<M>;
87
- model(modelName: string): sequelize.ModelCtor<sequelize.Model>;
88
- isDefined(modelName: string): boolean;
89
- query(sql: string | {
90
- query: string;
91
- values: unknown[];
92
- }, options: sequelize.QueryOptionsWithType<sequelize.QueryTypes.UPDATE>): Promise<[undefined, number]>;
93
- query(sql: string | {
94
- query: string;
95
- values: unknown[];
96
- }, options: sequelize.QueryOptionsWithType<sequelize.QueryTypes.BULKUPDATE>): Promise<number>;
97
- query(sql: string | {
98
- query: string;
99
- values: unknown[];
100
- }, options: sequelize.QueryOptionsWithType<sequelize.QueryTypes.INSERT>): Promise<[number, number]>;
101
- query(sql: string | {
102
- query: string;
103
- values: unknown[];
104
- }, options: sequelize.QueryOptionsWithType<sequelize.QueryTypes.UPSERT>): Promise<number>;
105
- query(sql: string | {
106
- query: string;
107
- values: unknown[];
108
- }, options: sequelize.QueryOptionsWithType<sequelize.QueryTypes.DELETE>): Promise<void>;
109
- query(sql: string | {
110
- query: string;
111
- values: unknown[];
112
- }, options: sequelize.QueryOptionsWithType<sequelize.QueryTypes.BULKDELETE>): Promise<number>;
113
- query(sql: string | {
114
- query: string;
115
- values: unknown[];
116
- }, options: sequelize.QueryOptionsWithType<sequelize.QueryTypes.SHOWTABLES>): Promise<string[]>;
117
- query(sql: string | {
118
- query: string;
119
- values: unknown[];
120
- }, options: sequelize.QueryOptionsWithType<sequelize.QueryTypes.DESCRIBE>): Promise<sequelize.ColumnsDescription>;
121
- query<M extends sequelize.Model>(sql: string | {
122
- query: string;
123
- values: unknown[];
124
- }, options: sequelize.QueryOptionsWithModel<M> & {
125
- plain: true;
126
- }): Promise<M | null>;
127
- query<M extends sequelize.Model>(sql: string | {
128
- query: string;
129
- values: unknown[];
130
- }, options: sequelize.QueryOptionsWithModel<M>): Promise<M[]>;
131
- query<T extends object>(sql: string | {
132
- query: string;
133
- values: unknown[];
134
- }, options: sequelize.QueryOptionsWithType<sequelize.QueryTypes.SELECT> & {
135
- plain: true;
136
- }): Promise<T | null>;
137
- query<T extends object>(sql: string | {
138
- query: string;
139
- values: unknown[];
140
- }, options: sequelize.QueryOptionsWithType<sequelize.QueryTypes.SELECT>): Promise<T[]>;
141
- query(sql: string | {
142
- query: string;
143
- values: unknown[];
144
- }, options: (sequelize.QueryOptions | sequelize.QueryOptionsWithType<sequelize.QueryTypes.RAW>) & {
145
- plain: true;
146
- }): Promise<{
147
- [key: string]: unknown;
148
- } | null>;
149
- query(sql: string | {
150
- query: string;
151
- values: unknown[];
152
- }, options?: sequelize.QueryOptions | sequelize.QueryOptionsWithType<sequelize.QueryTypes.RAW>): Promise<[unknown[], unknown]>;
153
- random(): sequelize.Utils.Fn;
154
- set(variables: object, options: sequelize.QueryOptionsTransactionRequired): Promise<unknown>;
155
- escape(value: string | number | Date): string;
156
- createSchema(schema: string, options: sequelize.Logging): Promise<unknown>;
157
- showAllSchemas(options: sequelize.Logging): Promise<object[]>;
158
- dropSchema(schema: string, options: sequelize.Logging): Promise<unknown[]>;
159
- dropAllSchemas(options: sequelize.Logging): Promise<unknown[]>;
160
- sync(options?: sequelize.SyncOptions): Promise<any>;
161
- truncate(options?: sequelize.DestroyOptions<any>): Promise<unknown[]>;
162
- drop(options?: sequelize.DropOptions): Promise<unknown[]>;
163
- authenticate(options?: sequelize.QueryOptions): Promise<void>;
164
- validate(options?: sequelize.QueryOptions): Promise<void>;
165
- transaction<T>(options: sequelize.TransactionOptions, autoCallback: (t: sequelize.Transaction) => PromiseLike<T>): Promise<T>;
166
- transaction<T>(autoCallback: (t: sequelize.Transaction) => PromiseLike<T>): Promise<T>;
167
- transaction(options?: sequelize.TransactionOptions): Promise<sequelize.Transaction>;
168
- close(): Promise<void>;
169
- databaseVersion(): Promise<string>;
170
- _model: sequelize.Model<any, any>;
171
- _attributes: any;
172
- _creationAttributes: any;
173
- addHook<K extends keyof import("sequelize/types/hooks").SequelizeHooks<sequelize.Model<any, any>, any, any>>(hookType: K, name: string, fn: import("sequelize/types/hooks").SequelizeHooks<sequelize.Model<any, any>, any, any>[K]): any;
174
- addHook<K extends keyof import("sequelize/types/hooks").SequelizeHooks<sequelize.Model<any, any>, any, any>>(hookType: K, fn: import("sequelize/types/hooks").SequelizeHooks<sequelize.Model<any, any>, any, any>[K]): any;
175
- removeHook<K extends keyof import("sequelize/types/hooks").SequelizeHooks<sequelize.Model<any, any>, any, any>>(hookType: K, name: string): any;
176
- hasHook<K extends keyof import("sequelize/types/hooks").SequelizeHooks<sequelize.Model<any, any>, any, any>>(hookType: K): boolean;
177
- hasHooks<K extends keyof import("sequelize/types/hooks").SequelizeHooks<sequelize.Model<any, any>, any, any>>(hookType: K): boolean;
178
- };
179
- export default _default;
11
+ }
@@ -1,4 +1,5 @@
1
1
  import sequelize from 'sequelize';
2
+ import Database from '~/database/Database';
2
3
  /**
3
4
  * Model base class.
4
5
  */
@@ -15,6 +16,11 @@ export default class Model extends sequelize.Model {
15
16
  * @type {sequelize.ModelAttributes}
16
17
  */
17
18
  protected static attributes: sequelize.ModelAttributes;
19
+ /**
20
+ * Database instance.
21
+ * @type {Database}
22
+ */
23
+ protected static database: Database;
18
24
  /**
19
25
  * Column type.
20
26
  * @see https://sequelize.org/api/v6/variable/index.html#static-variable-DataTypes
@@ -33,6 +39,7 @@ export default class Model extends sequelize.Model {
33
39
  };
34
40
  /**
35
41
  * Operator.
42
+ * @type {sequelize.Op}
36
43
  * @example
37
44
  * // Sequelize provides several operators.
38
45
  * Post.findAll({
@@ -80,7 +87,6 @@ export default class Model extends sequelize.Model {
80
87
  * }
81
88
  * }
82
89
  * });
83
- * @type {sequelize.Op}
84
90
  */
85
91
  static readonly Op: {
86
92
  [key: string]: any;
@@ -89,12 +95,12 @@ export default class Model extends sequelize.Model {
89
95
  * Creates a object representing a database function. This can be used in search queries, both in where and
90
96
  * order parts, and as default values in column definitions. If you want to refer to columns in your
91
97
  * function, you should use `sequelize.col`, so that the columns are properly interpreted as columns and not a strings.
98
+ * @type {sequelize.fn}
92
99
  * @example
93
100
  * // Convert a user's username to upper case
94
101
  * Post.update({
95
102
  * username: this.fn('upper', this.col('username'))
96
103
  * })
97
- * @type {sequelize.fn}
98
104
  */
99
105
  static readonly fn: (fn: string, ...args: unknown[]) => any;
100
106
  /**
@@ -116,22 +122,21 @@ export default class Model extends sequelize.Model {
116
122
  /**
117
123
  * Reference to sequelize.Transaction.
118
124
  * This includes properties such as isolation level enums used with the transaction option.
125
+ * @see https://sequelize.org/api/v6/class/src/transaction.js~transaction
126
+ * @type {sequelize.Transaction}
119
127
  * @example
120
128
  * BookModel.Transaction.ISOLATION_LEVELS.READ_UNCOMMITTED // "READ UNCOMMITTED"
121
129
  * BookModel.Transaction.ISOLATION_LEVELS.READ_COMMITTED // "READ COMMITTED"
122
130
  * BookModel.Transaction.ISOLATION_LEVELS.REPEATABLE_READ // "REPEATABLE READ"
123
131
  * BookModel.Transaction.ISOLATION_LEVELS.SERIALIZABLE // "SERIALIZABLE"
124
- *
125
- * @see https://sequelize.org/api/v6/class/src/transaction.js~transaction
126
- * @type {sequelize.Transaction}
127
132
  */
128
133
  static readonly Transaction: (typeof sequelize.Transaction);
129
134
  /**
130
135
  * Initialize the model that represents the table in the DB with attributes and options.
131
136
  * This method is called automatically from within the "express-sweet.mount" method, so you don't have to run it yourself.
132
- * @return {typeof Model} Returns this model class itself.
137
+ * @return {Promise<typeof Model>} Returns this model class itself.
133
138
  */
134
- static initialize(): (typeof Model);
139
+ static initialize(): Promise<typeof Model>;
135
140
  /**
136
141
  * Associate the model.
137
142
  * Define associations with other models such as "hasOne", "hasMany", "belongsTo", "belongsToMany".
@@ -142,6 +147,9 @@ export default class Model extends sequelize.Model {
142
147
  static association(): void;
143
148
  /**
144
149
  * Starts a transaction and returns a transaction object to identify the running transaction.
150
+ * @see https://sequelize.org/api/v6/class/src/transaction.js~transaction
151
+ * @param {sequelize.TransactionOptions} options? Options provided when the transaction is created.
152
+ * @return {Promise<sequelize.Transaction>} Returns a transaction object to identify the transaction being executed.
145
153
  * @example
146
154
  * // Simple transaction usage example.
147
155
  * let transaction;
@@ -166,17 +174,12 @@ export default class Model extends sequelize.Model {
166
174
  * await book.save({transaction});
167
175
  * await transaction.commit();
168
176
  *
169
- * // Check the update result.
170
- * // results in: New title of book: When Im Gone
177
+ * // Load updated data.
171
178
  * await book.reload();
172
- * console.log(`New title of book: ${book.title}`);
173
- * } catch (err) {
179
+ * } catch (error) {
174
180
  * if (transaction)
175
181
  * await transaction.rollback();
176
182
  * }
177
- * @see https://sequelize.org/api/v6/class/src/transaction.js~transaction
178
- * @param {sequelize.TransactionOptions} options? Options provided when the transaction is created.
179
- * @return {Promise<sequelize.Transaction>} Returns a transaction object to identify the transaction being executed.
180
183
  */
181
184
  static begin(options?: sequelize.TransactionOptions): Promise<sequelize.Transaction>;
182
185
  /**
@@ -186,6 +189,11 @@ export default class Model extends sequelize.Model {
186
189
  /**
187
190
  * Raw Queries.
188
191
  * 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.
192
+ * @see https://sequelize.org/master/manual/raw-queries.html
193
+ * @param {string} sql SQL string.
194
+ * @param {object} options Query options.
195
+ * @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.
196
+ * 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:
189
197
  * @example
190
198
  * // By default the function will return two arguments - a results array, and an object containing metadata (such as amount of affected rows, etc).
191
199
  * // Note that since this is a raw query, the metadata are dialect specific.
@@ -194,11 +202,6 @@ export default class Model extends sequelize.Model {
194
202
  * // 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:
195
203
  * // We didn't need to destructure the result here - the results were returned directly
196
204
  * const users = await BookModel.query("SELECT * FROM book", {type: BookModel.QueryTypes.SELECT});
197
- * @see https://sequelize.org/master/manual/raw-queries.html
198
- * @param {string} sql SQL string.
199
- * @param {object} options Query options.
200
- * @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.
201
- * 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:
202
205
  */
203
206
  static query(sql: string, options: 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>;
204
207
  }
@@ -2,6 +2,7 @@
2
2
  * Model initialization and association.
3
3
  * All models must be pre-loaded before associating models.So it loads and caches all defined models in advance.
4
4
  * This must be done before any method that may load other models is called.
5
+ * @return {Promise<void>}
5
6
  */
6
- declare const _default: () => void;
7
+ declare const _default: () => Promise<void>;
7
8
  export default _default;
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Finds an object in an array based on the specified field name and value.
3
+ * @param {Array<{[key: string]: any}>} array The array of objects to search.
4
+ * @param {string} fieldName The name of the field to search.
5
+ * @param {*} fieldValue The value to search for.
6
+ * @return {object|null} The first object in the array that matches the criteria, or null if no match is found.
7
+ * @example
8
+ * {{!--
9
+ * items is an array of objects: [{ id: 123, name: 'Item A' }, { id: 456, name: 'Item B' }]
10
+ * This code will output: "Item A"
11
+ * --}}
12
+ * {{#each items}}
13
+ * {{#if (eq id 123)}}
14
+ * {{lookup (findObjectInArray ../items 'id' id) 'name'}}
15
+ * {{/if}}
16
+ * {{/each}}
17
+ */
18
+ export declare const findObjectInArray: (array: Array<{
19
+ [key: string]: any;
20
+ }>, fieldName: string, fieldValue: any) => object | null;