chyz 1.2.1-rc.2 → 1.2.4-rc.2

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 (201) hide show
  1. package/{dist/BaseChyz.js → BaseChyz.js} +0 -0
  2. package/{dist/BaseChyz.js.map → BaseChyz.js.map} +0 -0
  3. package/{dist/Chyz.js → Chyz.js} +0 -0
  4. package/{dist/Chyz.js.map → Chyz.js.map} +0 -0
  5. package/{dist/base → base}/ActionFilter.js +0 -0
  6. package/{dist/base → base}/ActionFilter.js.map +0 -0
  7. package/{dist/base → base}/BaseError.js +0 -0
  8. package/{dist/base → base}/BaseError.js.map +0 -0
  9. package/{dist/base → base}/BaseObject.js +0 -0
  10. package/{dist/base → base}/BaseObject.js.map +0 -0
  11. package/{dist/base → base}/Behavior.js +0 -0
  12. package/{dist/base → base}/Behavior.js.map +0 -0
  13. package/{dist/base → base}/CWebController.js +0 -0
  14. package/{dist/base → base}/CWebController.js.map +0 -0
  15. package/{dist/base → base}/Component.js +0 -0
  16. package/{dist/base → base}/Component.js.map +0 -0
  17. package/{dist/base → base}/Configurable.js +0 -0
  18. package/{dist/base → base}/Configurable.js.map +0 -0
  19. package/{dist/base → base}/DataErrorDbException.js +0 -0
  20. package/{dist/base → base}/DataErrorDbException.js.map +0 -0
  21. package/{dist/base → base}/DbConnection.js +0 -0
  22. package/{dist/base → base}/DbConnection.js.map +0 -0
  23. package/{dist/base → base}/ForbiddenHttpException.js +0 -0
  24. package/{dist/base → base}/ForbiddenHttpException.js.map +0 -0
  25. package/{dist/base → base}/InvalidArgumentException.js +0 -0
  26. package/{dist/base → base}/InvalidArgumentException.js.map +0 -0
  27. package/{dist/base → base}/InvalidConfigException.js +0 -0
  28. package/{dist/base → base}/InvalidConfigException.js.map +0 -0
  29. package/{dist/base → base}/Model.js +0 -0
  30. package/{dist/base → base}/Model.js.map +0 -0
  31. package/{dist/base → base}/ModelManager.js +0 -0
  32. package/{dist/base → base}/ModelManager.js.map +0 -0
  33. package/{dist/base → base}/NotFoundHttpException.js +0 -0
  34. package/{dist/base → base}/NotFoundHttpException.js.map +0 -0
  35. package/{dist/base → base}/RestClient.js +0 -0
  36. package/{dist/base → base}/RestClient.js.map +0 -0
  37. package/{dist/base → base}/UnauthorizedHttpException.js +0 -0
  38. package/{dist/base → base}/UnauthorizedHttpException.js.map +0 -0
  39. package/{dist/base → base}/ValidationHttpException.js +0 -0
  40. package/{dist/base → base}/ValidationHttpException.js.map +0 -0
  41. package/{dist/base → base}/db/Exception.js +0 -0
  42. package/{dist/base → base}/db/Exception.js.map +0 -0
  43. package/{dist/base → base}/index.js +0 -0
  44. package/{dist/base → base}/index.js.map +0 -0
  45. package/{dist/decorator → decorator}/Middleware.js +0 -0
  46. package/{dist/decorator → decorator}/Middleware.js.map +0 -0
  47. package/{dist/decorator → decorator}/controller.js +0 -0
  48. package/{dist/decorator → decorator}/controller.js.map +0 -0
  49. package/{dist/decorator → decorator}/enums/ControllerDecoratorParams.js +0 -0
  50. package/{dist/decorator → decorator}/enums/ControllerDecoratorParams.js.map +0 -0
  51. package/{dist/decorator → decorator}/get.js +0 -0
  52. package/{dist/decorator → decorator}/get.js.map +0 -0
  53. package/{dist/decorator → decorator}/index.js +0 -0
  54. package/{dist/decorator → decorator}/index.js.map +0 -0
  55. package/{dist/decorator → decorator}/post.js +0 -0
  56. package/{dist/decorator → decorator}/post.js.map +0 -0
  57. package/{dist/filters → filters}/AccessControl.js +0 -1
  58. package/filters/AccessControl.js.map +1 -0
  59. package/{dist/filters → filters}/AccessRule.js +0 -0
  60. package/{dist/filters → filters}/AccessRule.js.map +0 -0
  61. package/{dist/filters → filters}/auth/AuthInterface.js +0 -0
  62. package/{dist/filters → filters}/auth/AuthInterface.js.map +0 -0
  63. package/{dist/filters → filters}/auth/AuthMethod.js +0 -0
  64. package/{dist/filters → filters}/auth/AuthMethod.js.map +1 -1
  65. package/{dist/filters → filters}/auth/HttpBasicAuth.js +0 -0
  66. package/{dist/filters → filters}/auth/HttpBasicAuth.js.map +0 -0
  67. package/{dist/filters → filters}/auth/HttpBearerAuth.js +0 -0
  68. package/{dist/filters → filters}/auth/HttpBearerAuth.js.map +0 -0
  69. package/{dist/filters → filters}/auth/HttpHeaderAuth.js +0 -0
  70. package/{dist/filters → filters}/auth/HttpHeaderAuth.js.map +0 -0
  71. package/{dist/filters → filters}/auth/JwtHttpBearerAuth.js +2 -3
  72. package/{dist/filters → filters}/auth/JwtHttpBearerAuth.js.map +1 -1
  73. package/{dist/filters → filters}/auth/KeyCloakHttpBearerAuth.js +0 -0
  74. package/{dist/filters → filters}/auth/KeyCloakHttpBearerAuth.js.map +0 -0
  75. package/{dist/filters → filters}/auth/index.js +0 -0
  76. package/{dist/filters → filters}/auth/index.js.map +0 -0
  77. package/{dist/filters → filters}/index.js +0 -0
  78. package/{dist/filters → filters}/index.js.map +0 -0
  79. package/{dist/index.js → index.js} +3 -0
  80. package/{dist/index.js.map → index.js.map} +1 -1
  81. package/log/config/log4js.json +1 -1
  82. package/{dist/model → model}/RouteDefinition.js +0 -0
  83. package/{dist/model → model}/RouteDefinition.js.map +0 -0
  84. package/package.json +2 -2
  85. package/{dist/rbac → rbac}/AuthAssignment.js +0 -0
  86. package/{dist/rbac → rbac}/AuthAssignment.js.map +0 -0
  87. package/{dist/rbac → rbac}/AuthItem.js +0 -0
  88. package/{dist/rbac → rbac}/AuthItem.js.map +0 -0
  89. package/{dist/rbac → rbac}/AuthItemChild.js +0 -0
  90. package/{dist/rbac → rbac}/AuthItemChild.js.map +0 -0
  91. package/{dist/rbac → rbac}/AuthManager.js +0 -0
  92. package/{dist/rbac → rbac}/AuthManager.js.map +0 -0
  93. package/{dist/requiments → requiments}/Glob.js +0 -0
  94. package/{dist/requiments → requiments}/Glob.js.map +0 -0
  95. package/{dist/requiments → requiments}/ReflectUtil.js +0 -0
  96. package/{dist/requiments → requiments}/ReflectUtil.js.map +0 -0
  97. package/{dist/requiments → requiments}/Utils.js +0 -0
  98. package/{dist/requiments → requiments}/Utils.js.map +0 -0
  99. package/{dist/validators → validators}/BooleanValidator.js +0 -0
  100. package/{dist/validators → validators}/BooleanValidator.js.map +0 -0
  101. package/{dist/validators → validators}/CompareValidator.js +0 -0
  102. package/{dist/validators → validators}/CompareValidator.js.map +0 -0
  103. package/{dist/validators → validators}/DateValidator.js +0 -0
  104. package/{dist/validators → validators}/DateValidator.js.map +0 -0
  105. package/{dist/validators → validators}/EmailValidator.js +0 -0
  106. package/{dist/validators → validators}/EmailValidator.js.map +0 -0
  107. package/{dist/validators → validators}/Validator.js +0 -0
  108. package/{dist/validators → validators}/Validator.js.map +0 -0
  109. package/{dist/web → web}/IdentityInterface.js +0 -0
  110. package/{dist/web → web}/IdentityInterface.js.map +0 -0
  111. package/{dist/web → web}/WebUser.js +0 -0
  112. package/{dist/web → web}/WebUser.js.map +0 -0
  113. package/BaseChyz.ts +0 -454
  114. package/Chyz.ts +0 -11
  115. package/Doc/Moel kullanma.md +0 -13
  116. package/Examples/Controllers/ApiController.ts +0 -140
  117. package/Examples/Controllers/BasicApiController.ts +0 -121
  118. package/Examples/Controllers/KeyCloakController.ts +0 -100
  119. package/Examples/Controllers/PublicController.ts +0 -42
  120. package/Examples/Controllers/SiteController.ts +0 -149
  121. package/Examples/Models/AuthAssignment.ts +0 -50
  122. package/Examples/Models/AuthItem.ts +0 -59
  123. package/Examples/Models/AuthItemChild.ts +0 -49
  124. package/Examples/Models/Categories.ts +0 -51
  125. package/Examples/Models/Customer.ts +0 -115
  126. package/Examples/Models/KeycloakUser.ts +0 -70
  127. package/Examples/Models/Order.ts +0 -64
  128. package/Examples/Models/OrderItem.ts +0 -27
  129. package/Examples/Models/ProductModels.ts +0 -49
  130. package/Examples/Models/ProductToCategories.ts +0 -46
  131. package/Examples/Models/Products.ts +0 -50
  132. package/Examples/Models/Stocks.ts +0 -60
  133. package/Examples/Models/User.ts +0 -128
  134. package/Examples/Models/UserPermission.ts +0 -37
  135. package/Examples/Models/index.ts +0 -19
  136. package/Examples/index-keycloack.ts +0 -78
  137. package/Examples/index.ts +0 -60
  138. package/Examples/keycloak.json +0 -7
  139. package/Examples/log/access.log +0 -0
  140. package/Examples/log/app.log +0 -20601
  141. package/Examples/log/errors.log +0 -2120
  142. package/Examples/package.json +0 -49
  143. package/Examples/tsconfig.json +0 -21
  144. package/base/ActionFilter.ts +0 -71
  145. package/base/BaseError.ts +0 -28
  146. package/base/BaseObject.ts +0 -19
  147. package/base/Behavior.ts +0 -6
  148. package/base/CWebController.ts +0 -84
  149. package/base/Component.ts +0 -66
  150. package/base/Configurable.ts +0 -10
  151. package/base/DataErrorDbException.ts +0 -16
  152. package/base/DbConnection.ts +0 -55
  153. package/base/ForbiddenHttpException.ts +0 -15
  154. package/base/InvalidArgumentException.ts +0 -16
  155. package/base/InvalidConfigException.ts +0 -16
  156. package/base/Model.ts +0 -555
  157. package/base/ModelManager.ts +0 -19
  158. package/base/NotFoundHttpException.ts +0 -14
  159. package/base/RestClient.ts +0 -28
  160. package/base/UnauthorizedHttpException.ts +0 -17
  161. package/base/ValidationHttpException.ts +0 -14
  162. package/base/db/Exception.ts +0 -14
  163. package/base/index.ts +0 -18
  164. package/decorator/Middleware.ts +0 -9
  165. package/decorator/controller.ts +0 -22
  166. package/decorator/enums/ControllerDecoratorParams.ts +0 -5
  167. package/decorator/get.ts +0 -37
  168. package/decorator/index.ts +0 -3
  169. package/decorator/post.ts +0 -36
  170. package/dist/filters/AccessControl.js.map +0 -1
  171. package/dist/log/config/log4js.json +0 -55
  172. package/dist/package.json +0 -59
  173. package/filters/AccessControl.ts +0 -77
  174. package/filters/AccessRule.ts +0 -182
  175. package/filters/auth/AuthInterface.ts +0 -34
  176. package/filters/auth/AuthMethod.ts +0 -88
  177. package/filters/auth/HttpBasicAuth.ts +0 -75
  178. package/filters/auth/HttpBearerAuth.ts +0 -31
  179. package/filters/auth/HttpHeaderAuth.ts +0 -53
  180. package/filters/auth/JwtHttpBearerAuth.ts +0 -80
  181. package/filters/auth/KeyCloakHttpBearerAuth.ts +0 -115
  182. package/filters/auth/index.ts +0 -4
  183. package/filters/index.ts +0 -2
  184. package/index.ts +0 -16
  185. package/model/RouteDefinition.ts +0 -18
  186. package/package-lock.json +0 -5259
  187. package/rbac/AuthAssignment.ts +0 -50
  188. package/rbac/AuthItem.ts +0 -57
  189. package/rbac/AuthItemChild.ts +0 -50
  190. package/rbac/AuthManager.ts +0 -398
  191. package/requiments/Glob.ts +0 -9
  192. package/requiments/ReflectUtil.ts +0 -26
  193. package/requiments/Utils.ts +0 -63
  194. package/tsconfig.json +0 -18
  195. package/validators/BooleanValidator.ts +0 -0
  196. package/validators/CompareValidator.ts +0 -0
  197. package/validators/DateValidator.ts +0 -0
  198. package/validators/EmailValidator.ts +0 -0
  199. package/validators/Validator.ts +0 -27
  200. package/web/IdentityInterface.ts +0 -68
  201. package/web/WebUser.ts +0 -187
package/base/Model.ts DELETED
@@ -1,555 +0,0 @@
1
- /*
2
- * Copyright (c) 2021. Chy Bilgisayar Bilisim
3
- * Author: Cihan Ozturk
4
- * E-mail: cihan@chy.com.tr
5
- * Github:https://github.com/cihan53/
6
- */
7
-
8
- import BaseChyz from "../BaseChyz";
9
- import Utils from "../requiments/Utils";
10
- import {Component} from "./Component";
11
- import {InvalidConfigException} from "./InvalidConfigException";
12
- import {DatabaseError, DataTypes, ExclusionConstraintError, ForeignKeyConstraintError, Model as SModel, QueryTypes, TimeoutError, UniqueConstraintError, ValidationError,} from "sequelize";
13
- import {Exception} from "./db/Exception";
14
-
15
- export {DataTypes, NOW} from "sequelize";
16
-
17
-
18
- export interface Relation {
19
- type: "hasOne" | "hasMany" | "belongsToMany" | "belongsTo",
20
- allowNull?: boolean,
21
- sourceKey?: string,
22
- model: SModel,
23
- foreignKey: string,
24
- name?: string,
25
- through?: any,
26
- as?: string
27
- }
28
-
29
- /**
30
- * ValidateMe.init({
31
- bar: {
32
- type: Sequelize.STRING,
33
- validate: {
34
- is: ["^[a-z]+$",'i'], // will only allow letters
35
- is: /^[a-z]+$/i, // same as the previous example using real RegExp
36
- not: ["[a-z]",'i'], // will not allow letters
37
- isEmail: true, // checks for email format (foo@bar.com)
38
- isUrl: true, // checks for url format (http://foo.com)
39
- isIP: true, // checks for IPv4 (129.89.23.1) or IPv6 format
40
- isIPv4: true, // checks for IPv4 (129.89.23.1)
41
- isIPv6: true, // checks for IPv6 format
42
- isAlpha: true, // will only allow letters
43
- isAlphanumeric: true, // will only allow alphanumeric characters, so "_abc" will fail
44
- isNumeric: true, // will only allow numbers
45
- isInt: true, // checks for valid integers
46
- isFloat: true, // checks for valid floating point numbers
47
- isDecimal: true, // checks for any numbers
48
- isLowercase: true, // checks for lowercase
49
- isUppercase: true, // checks for uppercase
50
- notNull: true, // won't allow null
51
- isNull: true, // only allows null
52
- notEmpty: true, // don't allow empty strings
53
- equals: 'specific value', // only allow a specific value
54
- contains: 'foo', // force specific substrings
55
- notIn: [['foo', 'bar']], // check the value is not one of these
56
- isIn: [['foo', 'bar']], // check the value is one of these
57
- notContains: 'bar', // don't allow specific substrings
58
- len: [2,10], // only allow values with length between 2 and 10
59
- isUUID: 4, // only allow uuids
60
- isDate: true, // only allow date strings
61
- isAfter: "2011-11-05", // only allow date strings after a specific date
62
- isBefore: "2011-11-05", // only allow date strings before a specific date
63
- max: 23, // only allow values <= 23
64
- min: 23, // only allow values >= 23
65
- isCreditCard: true, // check for valid credit card numbers
66
-
67
- // Examples of custom validators:
68
- isEven(value) {
69
- if (parseInt(value) % 2 !== 0) {
70
- throw new Error('Only even values are allowed!');
71
- }
72
- }
73
- isGreaterThanOtherField(value) {
74
- if (parseInt(value) <= parseInt(this.otherField)) {
75
- throw new Error('Bar must be greater than otherField.');
76
- }
77
- }
78
- }
79
- }
80
- }, { sequelize });
81
- */
82
-
83
- export class Model extends Component {
84
- _sequelize: any;
85
- _register: any;
86
- private _tableName: string;
87
- private _model: any;
88
- private _attributes: any = {};
89
- private _errors: any = {}
90
-
91
-
92
- constructor(sequelize?: IDBDatabase) {
93
- super();
94
- this._tableName = this.alias();
95
-
96
- BaseChyz.debug("Model constructor", this._tableName)
97
- // this._sequelize = BaseChyz.getComponent("db").db;
98
- if (sequelize != null)
99
- this._sequelize = sequelize;
100
- else
101
- this._sequelize = this.getDb();
102
-
103
- if (!Utils.isEmpty(this.attributes())) {
104
-
105
- this._model = this._sequelize.define(this._tableName, this.attributes(), {
106
- tableName: this.tableName(),
107
- timestamps: false,
108
- createdAt: false,
109
- updateAt: false
110
- });
111
-
112
- } else {
113
- throw new InvalidConfigException(BaseChyz.t("Invalid model configuration, is not emty attributes"))
114
- }
115
-
116
- // this.init();
117
-
118
- }
119
-
120
-
121
- /**
122
- * Returns the database connection used by this AR class.
123
- * By default, the "db" application component is used as the database connection.
124
- * You may override this method if you want to use a different database connection.
125
- * @return Connection the database connection used by this AR class.
126
- */
127
- public getDb() {
128
- return BaseChyz.getComponent("db").db
129
- }
130
-
131
- public getDbConnection() {
132
- return BaseChyz.getComponent("db");
133
- }
134
-
135
- get sequelize(): any {
136
- return this._sequelize;
137
- }
138
-
139
- set sequelize(value: any) {
140
- this._sequelize = value;
141
- }
142
-
143
- public provider() {
144
- return this._sequelize;
145
- }
146
-
147
-
148
- /**
149
- *
150
- */
151
- get errors(): any {
152
- return this._errors;
153
- }
154
-
155
- set errors(value: any) {
156
- this._errors = value;
157
- }
158
-
159
- public init() {
160
- BaseChyz.debug("Model init....", this.constructor.name)
161
- /**
162
- * init buraya
163
- */
164
- BaseChyz.debug("Relation init....", this.constructor.name)
165
- for (const relation of this.relations()) {
166
- let m = relation.model;
167
-
168
- if (relation.type == "hasOne") {
169
- // @ts-ignore
170
- delete relation.model
171
- this.model().hasOne(m, relation);
172
- }
173
- //
174
- if (relation.type == "hasMany") {
175
- // @ts-ignore
176
- delete relation.model;
177
- this.model().hasMany(m, relation);
178
- }
179
-
180
- if (relation.type == "belongsTo") {
181
- // @ts-ignore
182
- delete relation.model;
183
- this.model().belongsTo(m, relation);
184
- }
185
-
186
- if (relation.type == "belongsToMany") {
187
- // @ts-ignore
188
- delete relation.model;
189
- this.model().belongsToMany(m, relation);
190
- }
191
- }
192
-
193
-
194
- }
195
-
196
- public alias() {
197
- return this.constructor.name;
198
- }
199
-
200
- public tableName() {
201
- return this._tableName;
202
- }
203
-
204
- public formName() {
205
- return this.constructor.name;
206
- }
207
-
208
- public rules() {
209
- return []
210
- }
211
-
212
-
213
- public setModel(value: any) {
214
- this._model = value;
215
- }
216
-
217
- public model() {
218
- return this._model;
219
- }
220
-
221
-
222
-
223
- public async save(params = {}, options = {}) {
224
- // now instantiate an object
225
- let p = Object.assign(params, this._attributes)
226
- let result: any;
227
- try {
228
- result = await this.model().create(p, options)
229
- } catch (e: any) {
230
- BaseChyz.debug(`Model[${this.constructor.name}].create`, e)
231
- if (e instanceof ValidationError) {
232
- let validationErrorItems = e.errors;
233
- validationErrorItems.forEach(({message, path}) => {
234
- // @ts-ignore
235
- this._errors[path] = message
236
- })
237
-
238
- return false;
239
- } else if (e instanceof DatabaseError) {
240
-
241
- } else if (e instanceof TimeoutError) {
242
-
243
- } else if (e instanceof UniqueConstraintError) {
244
-
245
- } else if (e instanceof ForeignKeyConstraintError) {
246
-
247
- } else if (e instanceof ExclusionConstraintError) {
248
-
249
- }
250
- throw new Exception(e.message, this.errors, e.code);
251
- }
252
-
253
- return result;
254
-
255
- }
256
-
257
- public async bulkCreate(params = {}, options = {}) {
258
- // now instantiate an object
259
- let p = Object.assign(params, this._attributes)
260
- let result: any;
261
- try {
262
- result = await this.model().bulkCreate(p, options)
263
- } catch (e: any) {
264
- BaseChyz.debug(`Model[${this.constructor.name}].bulkCreate`, e)
265
- if (e instanceof ValidationError) {
266
- let validationErrorItems = e.errors;
267
- validationErrorItems.forEach(({message, path}) => {
268
- // @ts-ignore
269
- this._errors[path] = message
270
- })
271
-
272
- return false;
273
- } else if (e instanceof DatabaseError) {
274
-
275
- } else if (e instanceof TimeoutError) {
276
-
277
- } else if (e instanceof UniqueConstraintError) {
278
-
279
- } else if (e instanceof ForeignKeyConstraintError) {
280
-
281
- } else if (e instanceof ExclusionConstraintError) {
282
-
283
- }
284
- throw new Exception(e.message, this.errors, e.code);
285
- }
286
-
287
- return result;
288
-
289
- }
290
-
291
- public update(params = {}, options = {}) {
292
- let p = Object.assign(params, this._attributes)
293
- return this.model().update(p, options)
294
- }
295
-
296
- public delete(params = {}, options = {}) {
297
- let p = Object.assign(params, this._attributes)
298
- return this.model().delete(p, options)
299
- }
300
-
301
- /**
302
- * As there are often use cases in which it is just easier to execute raw / already prepared SQL queries, you can use the sequelize.query method.
303
- *
304
- * By default the function will return two arguments - a results array, and an object containing metadata (such as amount of affected rows, etc). Note that since this is a raw query, the metadata are dialect specific. Some dialects return the metadata "within" the results object (as properties on an array). However, two arguments will always be returned, but for MSSQL and MySQL it will be two references to the same object.
305
- *
306
- * const [results, metadata] = await sequelize.query("UPDATE users SET y = 42 WHERE x = 12");
307
- * // Results will be an empty array and metadata will contain the number of affected rows.
308
- *
309
- * 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:
310
- *
311
- * const { QueryTypes } = require('@sequelize/core');
312
- * const users = await sequelize.query("SELECT * FROM `users`", { type: QueryTypes.SELECT });
313
- * // We didn't need to destructure the result here - the results were returned directly
314
- *
315
- * Several other query types are available. Peek into the source for details.
316
- *
317
- * A second option is the model. If you pass a model the returned data will be instances of that model.
318
- *
319
- * // Callee is the model definition. This allows you to easily map a query to a predefined model
320
- * const projects = await sequelize.query('SELECT * FROM projects', {
321
- * model: Projects,
322
- * mapToModel: true // pass true here if you have any mapped fields
323
- * });
324
- * // Each element of `projects` is now an instance of Project
325
- *
326
- * See more options in the query API reference. Some examples:
327
- * ``
328
- * const { QueryTypes } = require('@sequelize/core');
329
- * await sequelize.query('SELECT 1', {
330
- * // A function (or false) for logging your queries
331
- * // Will get called for every SQL query that gets sent
332
- * // to the server.
333
- * logging: console.log,
334
- *
335
- * // If plain is true, then sequelize will only return the first
336
- * // record of the result set. In case of false it will return all records.
337
- * plain: false,
338
- *
339
- * // Set this to true if you don't have a model definition for your query.
340
- * raw: false,
341
- *
342
- * // The type of query you are executing. The query type affects how results are formatted before they are passed back.
343
- * type: QueryTypes.SELECT
344
- * });
345
- *``
346
- * // Note the second argument being null!
347
- * // Even if we declared a callee here, the raw: true would
348
- * // supersede and return a raw object.
349
- * console.log(await sequelize.query('SELECT * FROM projects', { raw: true }));
350
- *
351
- * ##"Dotted" attributes and the nest option
352
- *
353
- * If an attribute name of the table contains dots, the resulting objects can become nested objects by setting the nest: true option. This is achieved with dottie.js under the hood. See below:
354
- *
355
- * Without nest: true:
356
- * ``
357
- * const { QueryTypes } = require('@sequelize/core');
358
- * const records = await sequelize.query('select 1 as `foo.bar.baz`', {
359
- * type: QueryTypes.SELECT
360
- * });
361
- * console.log(JSON.stringify(records[0], null, 2));
362
- *
363
- * {
364
- * "foo.bar.baz": 1
365
- * }
366
- *
367
- * With nest: true:
368
- *
369
- * const { QueryTypes } = require('@sequelize/core');
370
- * const records = await sequelize.query('select 1 as `foo.bar.baz`', {
371
- * nest: true,
372
- * type: QueryTypes.SELECT
373
- * });
374
- * console.log(JSON.stringify(records[0], null, 2));
375
- *
376
- * {
377
- * "foo": {
378
- * "bar": {
379
- * "baz": 1
380
- * }
381
- * }
382
- * }
383
- * ``
384
- * ##Replacements
385
- *
386
- * Replacements in a query can be done in two different ways, either using named parameters (starting with :), or unnamed, represented by a ?. Replacements are passed in the options object.
387
- *
388
- * If an array is passed, ? will be replaced in the order that they appear in the array
389
- * If an object is passed, :key will be replaced with the keys from that object. If the object contains keys not found in the query or vice versa, an exception will be thrown.
390
- * ``
391
- * const { QueryTypes } = require('@sequelize/core');
392
- *
393
- * await sequelize.query(
394
- * 'SELECT * FROM projects WHERE status = ?',
395
- * {
396
- * replacements: ['active'],
397
- * type: QueryTypes.SELECT
398
- * }
399
- * );
400
- *
401
- * await sequelize.query(
402
- * 'SELECT * FROM projects WHERE status = :status',
403
- * {
404
- * replacements: { status: 'active' },
405
- * type: QueryTypes.SELECT
406
- * }
407
- * );
408
- * ``
409
- * Array replacements will automatically be handled, the following query searches for projects where the status matches an array of values.
410
- * ``
411
- * const { QueryTypes } = require('@sequelize/core');
412
- *
413
- * await sequelize.query(
414
- * 'SELECT * FROM projects WHERE status IN(:status)',
415
- * {
416
- * replacements: { status: ['active', 'inactive'] },
417
- * type: QueryTypes.SELECT
418
- * }
419
- * );
420
- * ``
421
- * To use the wildcard operator %, append it to your replacement. The following query matches users with names that start with 'ben'.
422
- * ``
423
- * const { QueryTypes } = require('@sequelize/core');
424
- *
425
- * await sequelize.query(
426
- * 'SELECT * FROM users WHERE name LIKE :search_name',
427
- * {
428
- * replacements: { search_name: 'ben%' },
429
- * type: QueryTypes.SELECT
430
- * }
431
- * ); ``
432
- *
433
- * ##Bind Parameter
434
- *
435
- * Bind parameters are like replacements. Except replacements are escaped and inserted into the query by sequelize before the query is sent to the database, while bind parameters are sent to the database outside the SQL query text. A query can have either bind parameters or replacements. Bind parameters are referred to by either $1, $2, ... (numeric) or $key (alpha-numeric). This is independent of the dialect.
436
- *
437
- * If an array is passed, $1 is bound to the 1st element in the array (bind[0])
438
- * If an object is passed, $key is bound to object['key']. Each key must begin with a non-numeric char. $1 is not a valid key, even if object['1'] exists.
439
- * In either case $$ can be used to escape a literal $ sign.
440
- *
441
- * The array or object must contain all bound values or Sequelize will throw an exception. This applies even to cases in which the database may ignore the bound parameter.
442
- *
443
- * The database may add further restrictions to this. Bind parameters cannot be SQL keywords, nor table or column names. They are also ignored in quoted text or data. In PostgreSQL it may also be needed to typecast them, if the type cannot be inferred from the context $1::varchar.
444
- *``
445
- * const { QueryTypes } = require('@sequelize/core');
446
- *
447
- * await sequelize.query(
448
- * 'SELECT *, "text with literal $$1 and literal $$status" as t FROM projects WHERE status = $1',
449
- * {
450
- * bind: ['active'],
451
- * type: QueryTypes.SELECT
452
- * }
453
- * ); ``
454
- *
455
- * `` await sequelize.query(
456
- * 'SELECT *, "text with literal $$1 and literal $$status" as t FROM projects WHERE status = $status',
457
- * {
458
- * bind: { status: 'active' },
459
- * type: QueryTypes.SELECT
460
- * }
461
- * );``
462
- * @param query
463
- */
464
- public async rawQuery(query: string, options: any = {type: QueryTypes.SELECT, nest: true}) {
465
- return await this.model().query(query, options);
466
- }
467
-
468
-
469
- /**
470
- *
471
- * @param args
472
- */
473
- public findOne(...args: any[]) {
474
- return this._model.findOne(...arguments)
475
- }
476
-
477
- /**
478
- *
479
- * @param args
480
- */
481
- public findAll(...args: any[]) {
482
- return this._model. findAll(...arguments)
483
- }
484
-
485
- /**
486
- * return {count : number , rows: any}
487
- * @param args
488
- */
489
- public findAndCountAll(...args: any[]) {
490
- return this._model.findAndCountAll(...arguments)
491
- }
492
-
493
-
494
- public validate() {
495
-
496
- }
497
-
498
- /**
499
- *
500
- * @param data
501
- * @param formName
502
- */
503
- public load(data: any, formName: any = null) {
504
- let scope = formName === null ? this.formName() : formName;
505
- if (scope === '' && !Utils.isEmpty(data)) {
506
- this.setAttribute(data);
507
- return true;
508
- } else if (data[scope]) {
509
- this.setAttribute(data[scope]);
510
- return true;
511
- }
512
- return false;
513
- }
514
-
515
- public bulkLoad(data: any, formName: any = null) {
516
- let scope = formName === null ? this.formName() : formName;
517
- if (scope === '' && !Utils.isEmpty(data)) {
518
- this.setAttribute(data);
519
- return true;
520
- } else if (data[scope]) {
521
- this.setAttribute(data[scope]);
522
- return true;
523
- }
524
- return false;
525
- }
526
-
527
- public setAttribute(values: any, safeOnly = true) {
528
- if (values instanceof Object) {
529
- let attributes = this.attributes();
530
- for (const valueKey in values) {
531
- if (Object.keys(attributes).indexOf(valueKey) != -1) {
532
- // @ts-ignore
533
- BaseChyz.debug("Model[" + this.formName() + "] attributes value set ", valueKey, values[valueKey])
534
- this._attributes[valueKey] = values[valueKey];
535
- }
536
- }
537
- }
538
- }
539
-
540
- public attributes() {
541
- return {}
542
- }
543
-
544
- /**
545
- * relation return array
546
- * [
547
- *
548
- * ]
549
- */
550
- public relations(): Relation[] {
551
- return []
552
- }
553
-
554
-
555
- }
@@ -1,19 +0,0 @@
1
- import {Model} from "./Model"
2
-
3
- /*
4
- *
5
- * Copyright (c) 2021.. Chy Bilgisayar Bilisim
6
- * Author: Cihan Ozturk
7
- * E-mail: cihan@chy.com.tr
8
- * Github:https://github.com/cihan53/
9
- *
10
- */
11
- interface ObjectConstructor {
12
- _register(o: Model): void;
13
- }
14
-
15
- export const ModelManager: any = {
16
- _register(map: Model) {
17
- Object.assign(this, map)
18
- }
19
- }
@@ -1,14 +0,0 @@
1
- /*
2
- * Copyright (c) 2021. Chy Bilgisayar Bilisim
3
- * Author: Cihan Ozturk
4
- * E-mail: cihan@chy.com.tr
5
- * Github:https://github.com/cihan53/
6
- */
7
-
8
- import {BaseError} from "./BaseError";
9
-
10
- export class NotFoundHttpException extends BaseError {
11
- constructor ( public message: string) {
12
- super(message,404);
13
- }
14
- }
@@ -1,28 +0,0 @@
1
- /*
2
- *
3
- * Copyright (c) 2021.. Chy Bilgisayar Bilisim
4
- * Author: Cihan Ozturk
5
- * E-mail: cihan@chy.com.tr
6
- * Github:https://github.com/cihan53/
7
- *
8
- */
9
-
10
-
11
- import {Component} from "./Component";
12
-
13
- const axios = require('axios')
14
-
15
- export class RestClient extends Component {
16
- public post(url: string, args: any[],headers:any={}) {
17
- return axios.post(url, args,headers)
18
- }
19
-
20
- public get(url: string, args: any[],headers:any={}) {
21
- return axios.get(url, args ,headers )
22
- }
23
-
24
- public Rest(params: any) {
25
- return axios(params)
26
- }
27
- }
28
- export default new RestClient();
@@ -1,17 +0,0 @@
1
- /*
2
- * Copyright (c) 2021. Chy Bilgisayar Bilisim
3
- * Author: Cihan Ozturk
4
- * E-mail: cihan@chy.com.tr
5
- * Github:https://github.com/cihan53/
6
- */
7
-
8
- import {BaseError} from "./BaseError";
9
-
10
- export class UnauthorizedHttpException extends BaseError {
11
- constructor ( public message: string) {
12
- super(message,401);
13
- }
14
-
15
- }
16
-
17
-
@@ -1,14 +0,0 @@
1
- /*
2
- * Copyright (c) 2021. Chy Bilgisayar Bilisim
3
- * Author: Cihan Ozturk
4
- * E-mail: cihan@chy.com.tr
5
- * Github:https://github.com/cihan53/
6
- */
7
-
8
- import {BaseError} from "./BaseError";
9
-
10
- export class ValidationHttpException extends BaseError {
11
- constructor ( public message: string) {
12
- super(message,403);
13
- }
14
- }
@@ -1,14 +0,0 @@
1
- import {BaseError} from "../BaseError";
2
-
3
- export class Exception extends BaseError {
4
- public errorInfo = [];
5
- private code: string;
6
-
7
- constructor(message: string, errorInfo:any = [], code = '', previous = null) {
8
- super(message);
9
- this.errorInfo = errorInfo;
10
- this.name = 'Database Exception' // good practice
11
- this.code = code // error code for responding to client
12
- Error.captureStackTrace(this)
13
- }
14
- }
package/base/index.ts DELETED
@@ -1,18 +0,0 @@
1
- export * from "./ActionFilter"
2
- export * from "./BaseObject"
3
- export * from "./BaseError"
4
- export * from "./Behavior"
5
- export * from "./Component"
6
- export * from "./Configurable"
7
- export * from "./CWebController"
8
- export * from "./DbConnection"
9
- export * from "./ForbiddenHttpException"
10
- export * from "./InvalidConfigException"
11
- export * from "./InvalidArgumentException"
12
- export * from "./NotFoundHttpException"
13
- export * from "./UnauthorizedHttpException"
14
- export * from "./DataErrorDbException"
15
- export * from "./ValidationHttpException"
16
- export * from "./Model"
17
- export * from "./RestClient"
18
- export * from "./ModelManager"
@@ -1,9 +0,0 @@
1
- import "reflect-metadata";
2
- import { ControllerDecoratorParams } from "./enums/ControllerDecoratorParams";
3
- import { RequestHandler } from "express";
4
-
5
- export function Middleware(middlewares: RequestHandler[]): Function {
6
- return function(target: any, propertyKey: string): void {
7
- Reflect.defineMetadata(ControllerDecoratorParams.Middleware, middlewares, target, propertyKey);
8
- }
9
- }