axe-api 1.0.0-rc9 → 1.0.1
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.
- package/build/index.d.ts +1 -0
- package/build/index.js +1 -0
- package/build/src/Builders/IndexBuilder.d.ts +7 -0
- package/build/src/Builders/IndexBuilder.js +35 -0
- package/build/src/Builders/ModelTreeBuilder.js +2 -1
- package/build/src/Builders/RouterBuilder.js +22 -11
- package/build/src/Builders/SwaggerBuilder.d.ts +2 -0
- package/build/src/Builders/SwaggerBuilder.js +609 -0
- package/build/src/Enums.d.ts +6 -1
- package/build/src/Enums.js +7 -1
- package/build/src/Handlers/DocsHandler.js +41 -0
- package/build/src/Handlers/ErrorHandler.d.ts +6 -0
- package/build/src/Handlers/ErrorHandler.js +12 -0
- package/build/src/Handlers/Helpers.d.ts +16 -4
- package/build/src/Handlers/Helpers.js +202 -5
- package/build/src/Handlers/RequestHandler.d.ts +4 -1
- package/build/src/Handlers/RequestHandler.js +36 -40
- package/build/src/Handlers/{DocsHTMLHandler.js → SwaggerHandler.js} +8 -7
- package/build/src/Interfaces.d.ts +103 -35
- package/build/src/Middlewares/RateLimit/AdaptorFactory.d.ts +3 -3
- package/build/src/Middlewares/RateLimit/MemoryAdaptor.d.ts +2 -2
- package/build/src/Middlewares/RateLimit/RedisAdaptor.d.ts +12 -4
- package/build/src/Middlewares/RateLimit/RedisAdaptor.js +24 -0
- package/build/src/Middlewares/RateLimit/index.d.ts +22 -3
- package/build/src/Middlewares/RateLimit/index.js +23 -3
- package/build/src/Model.d.ts +256 -10
- package/build/src/Model.js +322 -30
- package/build/src/Phases/All/FetchPhase.d.ts +2 -2
- package/build/src/Phases/All/PreparePhase.d.ts +2 -2
- package/build/src/Phases/All/index.d.ts +1 -1
- package/build/src/Phases/CacheTagCleanPhase.d.ts +3 -0
- package/build/src/{Handlers/MetadataHandler.js → Phases/CacheTagCleanPhase.js} +6 -10
- package/build/src/Phases/Delete/ActionPhase.d.ts +2 -2
- package/build/src/Phases/Delete/ActionPhase.js +21 -2
- package/build/src/Phases/Delete/PreparePhase.d.ts +2 -2
- package/build/src/Phases/Delete/QueryPhase.d.ts +2 -2
- package/build/src/Phases/Delete/ResponsePhase.d.ts +2 -2
- package/build/src/Phases/Delete/ResponsePhase.js +2 -1
- package/build/src/Phases/Delete/index.d.ts +4 -4
- package/build/src/Phases/ForceDelete/ActionPhase.d.ts +2 -2
- package/build/src/Phases/ForceDelete/ActionPhase.js +7 -0
- package/build/src/Phases/ForceDelete/PreparePhase.d.ts +2 -2
- package/build/src/Phases/ForceDelete/QueryPhase.d.ts +2 -2
- package/build/src/Phases/ForceDelete/index.d.ts +3 -3
- package/build/src/Phases/GetCachePhase.d.ts +3 -0
- package/build/src/Phases/GetCachePhase.js +39 -0
- package/build/src/Phases/List/RelationalPhase.d.ts +2 -2
- package/build/src/Phases/List/ResultPhase.d.ts +2 -2
- package/build/src/Phases/List/ResultPhase.js +9 -1
- package/build/src/Phases/List/SerializePhase.d.ts +2 -2
- package/build/src/Phases/List/index.d.ts +3 -3
- package/build/src/Phases/Paginate/FetchPhase.d.ts +2 -2
- package/build/src/Phases/Paginate/PreparePhase.d.ts +2 -2
- package/build/src/Phases/Paginate/index.d.ts +2 -2
- package/build/src/Phases/Patch/PrepareActionPhase.d.ts +2 -2
- package/build/src/Phases/Patch/PrepareActionPhase.js +13 -10
- package/build/src/Phases/Patch/index.d.ts +1 -1
- package/build/src/Phases/Search/FetchPhase.d.ts +3 -0
- package/build/src/Phases/Search/FetchPhase.js +66 -0
- package/build/src/Phases/Search/PreparePhase.d.ts +3 -0
- package/build/src/Phases/Search/PreparePhase.js +19 -0
- package/build/src/Phases/Search/index.d.ts +5 -0
- package/build/src/Phases/Search/index.js +11 -0
- package/build/src/Phases/Show/FetchPhase.d.ts +2 -2
- package/build/src/Phases/Show/FetchPhase.js +11 -1
- package/build/src/Phases/Show/PreparePhase.d.ts +2 -2
- package/build/src/Phases/Show/PreparePhase.js +5 -13
- package/build/src/Phases/Show/index.d.ts +2 -2
- package/build/src/Phases/Single/GetPhase.d.ts +2 -2
- package/build/src/Phases/Single/PrepareGetPhase.d.ts +2 -2
- package/build/src/Phases/Single/RelationalPhase.d.ts +2 -2
- package/build/src/Phases/Single/ResultPhase.d.ts +2 -2
- package/build/src/Phases/Single/ResultPhase.js +9 -1
- package/build/src/Phases/Single/SerializePhase.d.ts +2 -2
- package/build/src/Phases/Single/index.d.ts +5 -5
- package/build/src/Phases/Store/ActionPhase.d.ts +2 -2
- package/build/src/Phases/Store/ActionPhase.js +18 -7
- package/build/src/Phases/Store/PreparePhase.d.ts +2 -2
- package/build/src/Phases/Store/PreparePhase.js +14 -9
- package/build/src/Phases/Store/ResultPhase.d.ts +3 -0
- package/build/src/Phases/Store/ResultPhase.js +23 -0
- package/build/src/Phases/Store/index.d.ts +3 -2
- package/build/src/Phases/Store/index.js +2 -0
- package/build/src/Phases/URLSearchParamPhase.d.ts +3 -0
- package/build/src/Phases/URLSearchParamPhase.js +37 -0
- package/build/src/Phases/Update/ActionPhase.d.ts +2 -2
- package/build/src/Phases/Update/ActionPhase.js +14 -3
- package/build/src/Phases/Update/PrepareActionPhase.d.ts +2 -2
- package/build/src/Phases/Update/PrepareActionPhase.js +13 -10
- package/build/src/Phases/Update/index.d.ts +2 -2
- package/build/src/Resolvers/ModelResolver.d.ts +1 -0
- package/build/src/Resolvers/ModelResolver.js +21 -2
- package/build/src/Resolvers/TransactionResolver.js +3 -15
- package/build/src/Resolvers/VersionConfigResolver.js +6 -1
- package/build/src/Resolvers/VersionResolver.js +1 -0
- package/build/src/Server.d.ts +5 -0
- package/build/src/Server.js +44 -11
- package/build/src/Services/APIService.d.ts +3 -3
- package/build/src/Services/APIService.js +3 -16
- package/build/src/Services/App.d.ts +94 -8
- package/build/src/Services/App.js +94 -29
- package/build/src/Services/AxeRequest.d.ts +51 -2
- package/build/src/Services/AxeRequest.js +51 -4
- package/build/src/Services/AxeResponse.d.ts +28 -1
- package/build/src/Services/AxeResponse.js +28 -0
- package/build/src/Services/ConverterService.d.ts +5 -3
- package/build/src/Services/DocumentationService.d.ts +5 -2
- package/build/src/Services/DocumentationService.js +13 -1
- package/build/src/Services/ElasticService.d.ts +14 -0
- package/build/src/Services/ElasticService.js +74 -0
- package/build/src/Services/IoCService.d.ts +29 -2
- package/build/src/Services/IoCService.js +33 -6
- package/build/src/Services/LimitService.d.ts +18 -0
- package/build/src/Services/LimitService.js +18 -0
- package/build/src/Services/ModelService.d.ts +9 -5
- package/build/src/Services/ModelService.js +11 -0
- package/build/src/Services/QueryService.d.ts +3 -3
- package/build/src/Services/QueryService.js +6 -0
- package/build/src/Services/SchemaValidatorService.d.ts +1 -0
- package/build/src/Services/SchemaValidatorService.js +4 -0
- package/build/src/Services/URLService.d.ts +6 -14
- package/build/src/Services/URLService.js +10 -8
- package/build/src/Steps/Event.d.ts +11 -0
- package/build/src/Steps/Event.js +17 -0
- package/build/src/Steps/Hook.d.ts +11 -0
- package/build/src/Steps/Hook.js +17 -0
- package/build/src/Steps/Phase.d.ts +11 -0
- package/build/src/Steps/Phase.js +18 -0
- package/build/src/Types.d.ts +12 -10
- package/build/src/constants.d.ts +8 -9
- package/build/src/constants.js +217 -152
- package/package.json +51 -37
- package/build/dev-kit.d.ts +0 -1
- package/build/dev-kit.js +0 -16
- package/build/src/Middlewares/RateLimit/IAdaptor.d.ts +0 -6
- package/build/src/Middlewares/RateLimit/IAdaptor.js +0 -2
- /package/build/src/Handlers/{DocsHTMLHandler.d.ts → DocsHandler.d.ts} +0 -0
- /package/build/src/Handlers/{MetadataHandler.d.ts → SwaggerHandler.d.ts} +0 -0
package/build/src/Model.d.ts
CHANGED
|
@@ -1,26 +1,272 @@
|
|
|
1
|
-
import { IRelation, IMethodBaseConfig,
|
|
1
|
+
import { IRelation, IMethodBaseConfig, IQueryLimitConfig, IHandlerBasedTransactionConfig, ICacheConfiguration, IHandlerBasedCacheConfig, IElasticSearchParameters } from "./Interfaces";
|
|
2
2
|
import { HandlerTypes, HttpMethods } from "./Enums";
|
|
3
|
-
import {
|
|
3
|
+
import { ModelMiddleware, AxeFunction, ModelValidation } from "./Types";
|
|
4
4
|
declare class Model {
|
|
5
|
+
/**
|
|
6
|
+
* The primary key of the model. By default, it is `id`. But you can choose
|
|
7
|
+
* another name like `uuid`.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* get primaryKey() {
|
|
11
|
+
* return "id"
|
|
12
|
+
* }
|
|
13
|
+
* @type {string}
|
|
14
|
+
* @tutorial https://axe-api.com/reference/model-primary-key.html
|
|
15
|
+
*/
|
|
5
16
|
get primaryKey(): string;
|
|
17
|
+
/**
|
|
18
|
+
* The database table name of the model. By default, Axe API uses the plural
|
|
19
|
+
* version of the model(`User.ts` => `users`) name. You can specify a custom
|
|
20
|
+
* name like `my_users`.
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* get table() {
|
|
24
|
+
* return "my_users_table"
|
|
25
|
+
* }
|
|
26
|
+
* @type {string}
|
|
27
|
+
* @tutorial https://axe-api.com/reference/model-table.html
|
|
28
|
+
*/
|
|
6
29
|
get table(): string;
|
|
7
|
-
|
|
8
|
-
|
|
30
|
+
/**
|
|
31
|
+
* By this method, you can define which fields can be filled by the HTTP client.
|
|
32
|
+
* If you do not define, the HTTP client can not fill any field.
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* get fillable() {
|
|
36
|
+
* return ["name", "email", "password"]
|
|
37
|
+
* }
|
|
38
|
+
* @type {(string[] | IMethodBaseConfig)}
|
|
39
|
+
* @tutorial https://axe-api.com/reference/model-fillable.html
|
|
40
|
+
*/
|
|
41
|
+
get fillable(): string[] | IMethodBaseConfig<string[]>;
|
|
42
|
+
/**
|
|
43
|
+
* You can define the validation rules of the model. Method-based validations
|
|
44
|
+
* are also acceptable.
|
|
45
|
+
*
|
|
46
|
+
* @example
|
|
47
|
+
* get validations() {
|
|
48
|
+
* return {
|
|
49
|
+
* "name": "required|min:1|max:100",
|
|
50
|
+
* "email": "required|email",
|
|
51
|
+
* }
|
|
52
|
+
* }
|
|
53
|
+
* @type {(ModelValidation | IMethodBaseConfig<ModelValidation>)}
|
|
54
|
+
* @tutorial https://axe-api.com/reference/model-validations.html
|
|
55
|
+
*/
|
|
56
|
+
get validations(): ModelValidation | IMethodBaseConfig<ModelValidation>;
|
|
57
|
+
/**
|
|
58
|
+
* You can define acceptable handlers here.
|
|
59
|
+
*
|
|
60
|
+
* The default value is `DEFAULT_HANDLERS`
|
|
61
|
+
*
|
|
62
|
+
* @example
|
|
63
|
+
* get handlers() {
|
|
64
|
+
* return [HandlerTypes.PAGINATE]
|
|
65
|
+
* }
|
|
66
|
+
* @type {HandlerTypes[]}
|
|
67
|
+
* @tutorial https://axe-api.com/reference/model-handlers.html
|
|
68
|
+
*/
|
|
9
69
|
get handlers(): HandlerTypes[];
|
|
10
|
-
|
|
11
|
-
|
|
70
|
+
/**
|
|
71
|
+
* You can define a special handler for the model here. `MiddlewareFunction`,
|
|
72
|
+
* `HandlerFunction`, and `PhaseFunction` are acceptable middlewares.
|
|
73
|
+
*
|
|
74
|
+
* Also, you can define handler-based middlewares.
|
|
75
|
+
*
|
|
76
|
+
* @example
|
|
77
|
+
* get middlewares() {
|
|
78
|
+
* return [
|
|
79
|
+
* {
|
|
80
|
+
* handler: [HandlerTypes.DELETE],
|
|
81
|
+
* middleware: isAdminMiddleware,
|
|
82
|
+
* }
|
|
83
|
+
* ]
|
|
84
|
+
* }
|
|
85
|
+
* @type {ModelMiddleware}
|
|
86
|
+
* @tutorial https://axe-api.com/reference/model-middlewares.html
|
|
87
|
+
*/
|
|
88
|
+
get middlewares(): ModelMiddleware;
|
|
89
|
+
/**
|
|
90
|
+
* You can define which fields will be hiding in HTTP responses. The selected
|
|
91
|
+
* fields will not be listed in any response.
|
|
92
|
+
*
|
|
93
|
+
* You should mark as hidden sensitive data fields such as `password`, `token`, etc.
|
|
94
|
+
*
|
|
95
|
+
* @example
|
|
96
|
+
* get hiddens() {
|
|
97
|
+
* return ["password_salt", "password_hash", "github_token"]
|
|
98
|
+
* }
|
|
99
|
+
* @type {string[]}
|
|
100
|
+
* @tutorial https://axe-api.com/reference/model-hiddens.html
|
|
101
|
+
*/
|
|
102
|
+
get hiddens(): string[];
|
|
103
|
+
/**
|
|
104
|
+
* The `created_at` column name is in the database table. The default value is
|
|
105
|
+
* `created_at`. You can specify with a custom field name.
|
|
106
|
+
*
|
|
107
|
+
* It should be null if the table doesn't have a `created_at` column.
|
|
108
|
+
*
|
|
109
|
+
* @example
|
|
110
|
+
* get createdAtColumn() {
|
|
111
|
+
* return "created_at"
|
|
112
|
+
* }
|
|
113
|
+
* @type {(string | null)}
|
|
114
|
+
* @tutorial https://axe-api.com/reference/model-created-at-column.html
|
|
115
|
+
*/
|
|
12
116
|
get createdAtColumn(): string | null;
|
|
117
|
+
/**
|
|
118
|
+
* The `updated_at` column name is in the database table. The default value is
|
|
119
|
+
* `updated_at`. You can specify with a custom field name.
|
|
120
|
+
*
|
|
121
|
+
* It should be null if the table doesn't have a `updated_at` column.
|
|
122
|
+
*
|
|
123
|
+
* @example
|
|
124
|
+
* get updatedAtColumn() {
|
|
125
|
+
* return "updated_at"
|
|
126
|
+
* }
|
|
127
|
+
* @type {(string | null)}
|
|
128
|
+
* @tutorial https://axe-api.com/reference/model-updated-at-column.html
|
|
129
|
+
*/
|
|
13
130
|
get updatedAtColumn(): string | null;
|
|
131
|
+
/**
|
|
132
|
+
* The `deleted_at` column name is in the database table. The default value is
|
|
133
|
+
* `null`. You can specify with a custom field name.
|
|
134
|
+
*
|
|
135
|
+
* If you provide a name, that means your model supports the soft delete feature.
|
|
136
|
+
*
|
|
137
|
+
* @example
|
|
138
|
+
* get deletedAtColumn() {
|
|
139
|
+
* return "deleted_at"
|
|
140
|
+
* }
|
|
141
|
+
* @type {(string | null)}
|
|
142
|
+
* @tutorial https://axe-api.com/reference/model-deleted-at-column.html
|
|
143
|
+
*/
|
|
14
144
|
get deletedAtColumn(): string | null;
|
|
15
|
-
|
|
145
|
+
/**
|
|
146
|
+
* The transaction configuration on the model. The database transaction can
|
|
147
|
+
* be started for all endpoints on the model as well as handler-based.
|
|
148
|
+
*
|
|
149
|
+
* Creating, rollbacking, and committing a transaction is managed by Axe API.
|
|
150
|
+
*
|
|
151
|
+
* @example
|
|
152
|
+
* get transaction() {
|
|
153
|
+
* return [
|
|
154
|
+
* {
|
|
155
|
+
* handlers: [HandlerTypes.INSERT],
|
|
156
|
+
* transaction: true
|
|
157
|
+
* }
|
|
158
|
+
* ]
|
|
159
|
+
* }
|
|
160
|
+
* @type {(boolean | IHandlerBasedTransactionConfig[])}
|
|
161
|
+
* @tutorial https://axe-api.com/learn/database-transactions.html#model-based-transactions
|
|
162
|
+
*/
|
|
163
|
+
get transaction(): boolean | IHandlerBasedTransactionConfig[];
|
|
164
|
+
/**
|
|
165
|
+
* You can completely ignore the model. Axe API doesn't create the routes
|
|
166
|
+
* automatically.
|
|
167
|
+
*
|
|
168
|
+
* @example
|
|
169
|
+
* get ignore() {
|
|
170
|
+
* return true
|
|
171
|
+
* }
|
|
172
|
+
* @type {boolean}
|
|
173
|
+
* @tutorial https://axe-api.com/reference/model-ignore.html
|
|
174
|
+
*/
|
|
16
175
|
get ignore(): boolean;
|
|
176
|
+
/**
|
|
177
|
+
* You can limit query features such as `select.*` or `LIKE`, etc.
|
|
178
|
+
*
|
|
179
|
+
* @example
|
|
180
|
+
* get limits() {
|
|
181
|
+
* return [
|
|
182
|
+
* allow(QueryFeature.WhereLike),
|
|
183
|
+
* deny(QueryFeature.FieldsAll)
|
|
184
|
+
* ];
|
|
185
|
+
* }
|
|
186
|
+
* @type {Array<IQueryLimitConfig[]>}
|
|
187
|
+
* @tutorial https://axe-api.com/reference/model-limits.html
|
|
188
|
+
*/
|
|
17
189
|
get limits(): Array<IQueryLimitConfig[]>;
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
190
|
+
/**
|
|
191
|
+
* You can set the caching configuration for a specific model or handler.
|
|
192
|
+
* `NULL` means that there is not a special configuration. In that case, the
|
|
193
|
+
* inherited configuration will be used.
|
|
194
|
+
*
|
|
195
|
+
* @example
|
|
196
|
+
* get cache() {
|
|
197
|
+
* return {
|
|
198
|
+
* enable: false,
|
|
199
|
+
* ttl: 300,
|
|
200
|
+
* invalidation: CacheStrategies.TimeBased,
|
|
201
|
+
* };
|
|
202
|
+
* }
|
|
203
|
+
* @type {ICacheConfiguration | IHandlerBasedCacheConfig[] | null>}
|
|
204
|
+
* @tutorial https://axe-api.com/reference/model-cache.html
|
|
205
|
+
*/
|
|
206
|
+
get cache(): ICacheConfiguration | IHandlerBasedCacheConfig[] | null;
|
|
207
|
+
/**
|
|
208
|
+
* You can set which fields should be set to the ElasticSearch for the
|
|
209
|
+
* full-text search feature.
|
|
210
|
+
*
|
|
211
|
+
* @example
|
|
212
|
+
* get saerch() {
|
|
213
|
+
* return ["name", "surname", "email"]
|
|
214
|
+
* }
|
|
215
|
+
* @type {string[] | null>}
|
|
216
|
+
* @tutorial https://axe-api.com/reference/model-search.html
|
|
217
|
+
*/
|
|
218
|
+
get search(): string[] | null;
|
|
219
|
+
/**
|
|
220
|
+
* Model relationship definition. Axe API creates `hasMany` routes automatically.
|
|
221
|
+
*
|
|
222
|
+
* @example
|
|
223
|
+
* get relationName() {
|
|
224
|
+
* return this.hasMany("Post", "id", "user_id")
|
|
225
|
+
* }
|
|
226
|
+
* @type {Array<IQueryLimitConfig[]>}
|
|
227
|
+
* @tutorial https://axe-api.com/learn/routing.html#model-relations
|
|
228
|
+
*/
|
|
21
229
|
hasMany(relatedModel: string, primaryKey?: string, foreignKey?: string): IRelation;
|
|
230
|
+
/**
|
|
231
|
+
* Model relationship definition.
|
|
232
|
+
*
|
|
233
|
+
* @example
|
|
234
|
+
* get relationName() {
|
|
235
|
+
* return this.hasOne("User", "id", "user_id")
|
|
236
|
+
* }
|
|
237
|
+
* @type {Array<IQueryLimitConfig[]>}
|
|
238
|
+
* @tutorial https://axe-api.com/learn/routing.html#model-relations
|
|
239
|
+
*/
|
|
22
240
|
hasOne(relatedModel: string, primaryKey?: string, foreignKey?: string): IRelation;
|
|
241
|
+
/**
|
|
242
|
+
* Model relationship definition.
|
|
243
|
+
*
|
|
244
|
+
* @example
|
|
245
|
+
* get relationName() {
|
|
246
|
+
* return this.belongsTo("User", "user_id", "id")
|
|
247
|
+
* }
|
|
248
|
+
* @type {Array<IQueryLimitConfig[]>}
|
|
249
|
+
* @tutorial https://axe-api.com/learn/routing.html#model-relations
|
|
250
|
+
*/
|
|
23
251
|
belongsTo(relatedModel: string, primaryKey: string, foreignKey: string): IRelation;
|
|
252
|
+
getFillableFields(methodType: HttpMethods): string[];
|
|
253
|
+
getValidationRules(methodType: HttpMethods): ModelValidation | null;
|
|
254
|
+
getMiddlewares(handlerType: HandlerTypes): AxeFunction[];
|
|
255
|
+
/**
|
|
256
|
+
* In this function, you can use your custom Elastic Search query for the
|
|
257
|
+
* full-text search feature.
|
|
258
|
+
*
|
|
259
|
+
* By default, Axe API uses a simple full-text search.
|
|
260
|
+
*
|
|
261
|
+
* @example
|
|
262
|
+
* get getSearchQuery(params: IElasticSearchParameters) {
|
|
263
|
+
* return {
|
|
264
|
+
* // your query
|
|
265
|
+
* }
|
|
266
|
+
* }
|
|
267
|
+
* @tutorial https://axe-api.com/reference/model-get-search-query.html
|
|
268
|
+
*/
|
|
269
|
+
getSearchQuery(params: IElasticSearchParameters): any;
|
|
24
270
|
private hasStringValue;
|
|
25
271
|
}
|
|
26
272
|
export default Model;
|
package/build/src/Model.js
CHANGED
|
@@ -7,46 +7,310 @@ const pluralize_1 = __importDefault(require("pluralize"));
|
|
|
7
7
|
const snake_case_1 = require("snake-case");
|
|
8
8
|
const Enums_1 = require("./Enums");
|
|
9
9
|
const constants_1 = require("./constants");
|
|
10
|
+
const Helpers_1 = require("./Handlers/Helpers");
|
|
10
11
|
class Model {
|
|
12
|
+
/**
|
|
13
|
+
* The primary key of the model. By default, it is `id`. But you can choose
|
|
14
|
+
* another name like `uuid`.
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* get primaryKey() {
|
|
18
|
+
* return "id"
|
|
19
|
+
* }
|
|
20
|
+
* @type {string}
|
|
21
|
+
* @tutorial https://axe-api.com/reference/model-primary-key.html
|
|
22
|
+
*/
|
|
11
23
|
get primaryKey() {
|
|
12
24
|
return "id";
|
|
13
25
|
}
|
|
26
|
+
/**
|
|
27
|
+
* The database table name of the model. By default, Axe API uses the plural
|
|
28
|
+
* version of the model(`User.ts` => `users`) name. You can specify a custom
|
|
29
|
+
* name like `my_users`.
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* get table() {
|
|
33
|
+
* return "my_users_table"
|
|
34
|
+
* }
|
|
35
|
+
* @type {string}
|
|
36
|
+
* @tutorial https://axe-api.com/reference/model-table.html
|
|
37
|
+
*/
|
|
14
38
|
get table() {
|
|
15
39
|
return (0, pluralize_1.default)((0, snake_case_1.snakeCase)(this.constructor.name));
|
|
16
40
|
}
|
|
41
|
+
/**
|
|
42
|
+
* By this method, you can define which fields can be filled by the HTTP client.
|
|
43
|
+
* If you do not define, the HTTP client can not fill any field.
|
|
44
|
+
*
|
|
45
|
+
* @example
|
|
46
|
+
* get fillable() {
|
|
47
|
+
* return ["name", "email", "password"]
|
|
48
|
+
* }
|
|
49
|
+
* @type {(string[] | IMethodBaseConfig)}
|
|
50
|
+
* @tutorial https://axe-api.com/reference/model-fillable.html
|
|
51
|
+
*/
|
|
17
52
|
get fillable() {
|
|
18
53
|
return [];
|
|
19
54
|
}
|
|
55
|
+
/**
|
|
56
|
+
* You can define the validation rules of the model. Method-based validations
|
|
57
|
+
* are also acceptable.
|
|
58
|
+
*
|
|
59
|
+
* @example
|
|
60
|
+
* get validations() {
|
|
61
|
+
* return {
|
|
62
|
+
* "name": "required|min:1|max:100",
|
|
63
|
+
* "email": "required|email",
|
|
64
|
+
* }
|
|
65
|
+
* }
|
|
66
|
+
* @type {(ModelValidation | IMethodBaseConfig<ModelValidation>)}
|
|
67
|
+
* @tutorial https://axe-api.com/reference/model-validations.html
|
|
68
|
+
*/
|
|
20
69
|
get validations() {
|
|
21
70
|
return {};
|
|
22
71
|
}
|
|
72
|
+
/**
|
|
73
|
+
* You can define acceptable handlers here.
|
|
74
|
+
*
|
|
75
|
+
* The default value is `DEFAULT_HANDLERS`
|
|
76
|
+
*
|
|
77
|
+
* @example
|
|
78
|
+
* get handlers() {
|
|
79
|
+
* return [HandlerTypes.PAGINATE]
|
|
80
|
+
* }
|
|
81
|
+
* @type {HandlerTypes[]}
|
|
82
|
+
* @tutorial https://axe-api.com/reference/model-handlers.html
|
|
83
|
+
*/
|
|
23
84
|
get handlers() {
|
|
24
85
|
return [...constants_1.DEFAULT_HANDLERS];
|
|
25
86
|
}
|
|
87
|
+
/**
|
|
88
|
+
* You can define a special handler for the model here. `MiddlewareFunction`,
|
|
89
|
+
* `HandlerFunction`, and `PhaseFunction` are acceptable middlewares.
|
|
90
|
+
*
|
|
91
|
+
* Also, you can define handler-based middlewares.
|
|
92
|
+
*
|
|
93
|
+
* @example
|
|
94
|
+
* get middlewares() {
|
|
95
|
+
* return [
|
|
96
|
+
* {
|
|
97
|
+
* handler: [HandlerTypes.DELETE],
|
|
98
|
+
* middleware: isAdminMiddleware,
|
|
99
|
+
* }
|
|
100
|
+
* ]
|
|
101
|
+
* }
|
|
102
|
+
* @type {ModelMiddleware}
|
|
103
|
+
* @tutorial https://axe-api.com/reference/model-middlewares.html
|
|
104
|
+
*/
|
|
26
105
|
get middlewares() {
|
|
27
106
|
return [];
|
|
28
107
|
}
|
|
108
|
+
/**
|
|
109
|
+
* You can define which fields will be hiding in HTTP responses. The selected
|
|
110
|
+
* fields will not be listed in any response.
|
|
111
|
+
*
|
|
112
|
+
* You should mark as hidden sensitive data fields such as `password`, `token`, etc.
|
|
113
|
+
*
|
|
114
|
+
* @example
|
|
115
|
+
* get hiddens() {
|
|
116
|
+
* return ["password_salt", "password_hash", "github_token"]
|
|
117
|
+
* }
|
|
118
|
+
* @type {string[]}
|
|
119
|
+
* @tutorial https://axe-api.com/reference/model-hiddens.html
|
|
120
|
+
*/
|
|
29
121
|
get hiddens() {
|
|
30
122
|
return [];
|
|
31
123
|
}
|
|
124
|
+
/**
|
|
125
|
+
* The `created_at` column name is in the database table. The default value is
|
|
126
|
+
* `created_at`. You can specify with a custom field name.
|
|
127
|
+
*
|
|
128
|
+
* It should be null if the table doesn't have a `created_at` column.
|
|
129
|
+
*
|
|
130
|
+
* @example
|
|
131
|
+
* get createdAtColumn() {
|
|
132
|
+
* return "created_at"
|
|
133
|
+
* }
|
|
134
|
+
* @type {(string | null)}
|
|
135
|
+
* @tutorial https://axe-api.com/reference/model-created-at-column.html
|
|
136
|
+
*/
|
|
32
137
|
get createdAtColumn() {
|
|
33
138
|
return "created_at";
|
|
34
139
|
}
|
|
140
|
+
/**
|
|
141
|
+
* The `updated_at` column name is in the database table. The default value is
|
|
142
|
+
* `updated_at`. You can specify with a custom field name.
|
|
143
|
+
*
|
|
144
|
+
* It should be null if the table doesn't have a `updated_at` column.
|
|
145
|
+
*
|
|
146
|
+
* @example
|
|
147
|
+
* get updatedAtColumn() {
|
|
148
|
+
* return "updated_at"
|
|
149
|
+
* }
|
|
150
|
+
* @type {(string | null)}
|
|
151
|
+
* @tutorial https://axe-api.com/reference/model-updated-at-column.html
|
|
152
|
+
*/
|
|
35
153
|
get updatedAtColumn() {
|
|
36
154
|
return "updated_at";
|
|
37
155
|
}
|
|
156
|
+
/**
|
|
157
|
+
* The `deleted_at` column name is in the database table. The default value is
|
|
158
|
+
* `null`. You can specify with a custom field name.
|
|
159
|
+
*
|
|
160
|
+
* If you provide a name, that means your model supports the soft delete feature.
|
|
161
|
+
*
|
|
162
|
+
* @example
|
|
163
|
+
* get deletedAtColumn() {
|
|
164
|
+
* return "deleted_at"
|
|
165
|
+
* }
|
|
166
|
+
* @type {(string | null)}
|
|
167
|
+
* @tutorial https://axe-api.com/reference/model-deleted-at-column.html
|
|
168
|
+
*/
|
|
38
169
|
get deletedAtColumn() {
|
|
39
170
|
return null;
|
|
40
171
|
}
|
|
172
|
+
/**
|
|
173
|
+
* The transaction configuration on the model. The database transaction can
|
|
174
|
+
* be started for all endpoints on the model as well as handler-based.
|
|
175
|
+
*
|
|
176
|
+
* Creating, rollbacking, and committing a transaction is managed by Axe API.
|
|
177
|
+
*
|
|
178
|
+
* @example
|
|
179
|
+
* get transaction() {
|
|
180
|
+
* return [
|
|
181
|
+
* {
|
|
182
|
+
* handlers: [HandlerTypes.INSERT],
|
|
183
|
+
* transaction: true
|
|
184
|
+
* }
|
|
185
|
+
* ]
|
|
186
|
+
* }
|
|
187
|
+
* @type {(boolean | IHandlerBasedTransactionConfig[])}
|
|
188
|
+
* @tutorial https://axe-api.com/learn/database-transactions.html#model-based-transactions
|
|
189
|
+
*/
|
|
41
190
|
get transaction() {
|
|
42
|
-
return
|
|
191
|
+
return false;
|
|
43
192
|
}
|
|
193
|
+
/**
|
|
194
|
+
* You can completely ignore the model. Axe API doesn't create the routes
|
|
195
|
+
* automatically.
|
|
196
|
+
*
|
|
197
|
+
* @example
|
|
198
|
+
* get ignore() {
|
|
199
|
+
* return true
|
|
200
|
+
* }
|
|
201
|
+
* @type {boolean}
|
|
202
|
+
* @tutorial https://axe-api.com/reference/model-ignore.html
|
|
203
|
+
*/
|
|
44
204
|
get ignore() {
|
|
45
205
|
return false;
|
|
46
206
|
}
|
|
207
|
+
/**
|
|
208
|
+
* You can limit query features such as `select.*` or `LIKE`, etc.
|
|
209
|
+
*
|
|
210
|
+
* @example
|
|
211
|
+
* get limits() {
|
|
212
|
+
* return [
|
|
213
|
+
* allow(QueryFeature.WhereLike),
|
|
214
|
+
* deny(QueryFeature.FieldsAll)
|
|
215
|
+
* ];
|
|
216
|
+
* }
|
|
217
|
+
* @type {Array<IQueryLimitConfig[]>}
|
|
218
|
+
* @tutorial https://axe-api.com/reference/model-limits.html
|
|
219
|
+
*/
|
|
47
220
|
get limits() {
|
|
48
221
|
return [];
|
|
49
222
|
}
|
|
223
|
+
/**
|
|
224
|
+
* You can set the caching configuration for a specific model or handler.
|
|
225
|
+
* `NULL` means that there is not a special configuration. In that case, the
|
|
226
|
+
* inherited configuration will be used.
|
|
227
|
+
*
|
|
228
|
+
* @example
|
|
229
|
+
* get cache() {
|
|
230
|
+
* return {
|
|
231
|
+
* enable: false,
|
|
232
|
+
* ttl: 300,
|
|
233
|
+
* invalidation: CacheStrategies.TimeBased,
|
|
234
|
+
* };
|
|
235
|
+
* }
|
|
236
|
+
* @type {ICacheConfiguration | IHandlerBasedCacheConfig[] | null>}
|
|
237
|
+
* @tutorial https://axe-api.com/reference/model-cache.html
|
|
238
|
+
*/
|
|
239
|
+
get cache() {
|
|
240
|
+
return null;
|
|
241
|
+
}
|
|
242
|
+
/**
|
|
243
|
+
* You can set which fields should be set to the ElasticSearch for the
|
|
244
|
+
* full-text search feature.
|
|
245
|
+
*
|
|
246
|
+
* @example
|
|
247
|
+
* get saerch() {
|
|
248
|
+
* return ["name", "surname", "email"]
|
|
249
|
+
* }
|
|
250
|
+
* @type {string[] | null>}
|
|
251
|
+
* @tutorial https://axe-api.com/reference/model-search.html
|
|
252
|
+
*/
|
|
253
|
+
get search() {
|
|
254
|
+
return null;
|
|
255
|
+
}
|
|
256
|
+
/**
|
|
257
|
+
* Model relationship definition. Axe API creates `hasMany` routes automatically.
|
|
258
|
+
*
|
|
259
|
+
* @example
|
|
260
|
+
* get relationName() {
|
|
261
|
+
* return this.hasMany("Post", "id", "user_id")
|
|
262
|
+
* }
|
|
263
|
+
* @type {Array<IQueryLimitConfig[]>}
|
|
264
|
+
* @tutorial https://axe-api.com/learn/routing.html#model-relations
|
|
265
|
+
*/
|
|
266
|
+
hasMany(relatedModel, primaryKey = "id", foreignKey = "") {
|
|
267
|
+
if (!foreignKey) {
|
|
268
|
+
const currentModelName = pluralize_1.default.singular(this.constructor.name.toLowerCase());
|
|
269
|
+
foreignKey = `${currentModelName}_id`;
|
|
270
|
+
}
|
|
271
|
+
return {
|
|
272
|
+
name: relatedModel,
|
|
273
|
+
type: Enums_1.Relationships.HAS_MANY,
|
|
274
|
+
model: relatedModel,
|
|
275
|
+
primaryKey,
|
|
276
|
+
foreignKey,
|
|
277
|
+
};
|
|
278
|
+
}
|
|
279
|
+
/**
|
|
280
|
+
* Model relationship definition.
|
|
281
|
+
*
|
|
282
|
+
* @example
|
|
283
|
+
* get relationName() {
|
|
284
|
+
* return this.hasOne("User", "id", "user_id")
|
|
285
|
+
* }
|
|
286
|
+
* @type {Array<IQueryLimitConfig[]>}
|
|
287
|
+
* @tutorial https://axe-api.com/learn/routing.html#model-relations
|
|
288
|
+
*/
|
|
289
|
+
hasOne(relatedModel, primaryKey = "id", foreignKey = "") {
|
|
290
|
+
if (foreignKey === "") {
|
|
291
|
+
foreignKey = `${pluralize_1.default.singular(relatedModel.toLowerCase())}_id`;
|
|
292
|
+
}
|
|
293
|
+
return {
|
|
294
|
+
name: relatedModel,
|
|
295
|
+
type: Enums_1.Relationships.HAS_ONE,
|
|
296
|
+
model: relatedModel,
|
|
297
|
+
primaryKey,
|
|
298
|
+
foreignKey,
|
|
299
|
+
};
|
|
300
|
+
}
|
|
301
|
+
/**
|
|
302
|
+
* Model relationship definition.
|
|
303
|
+
*
|
|
304
|
+
* @example
|
|
305
|
+
* get relationName() {
|
|
306
|
+
* return this.belongsTo("User", "user_id", "id")
|
|
307
|
+
* }
|
|
308
|
+
* @type {Array<IQueryLimitConfig[]>}
|
|
309
|
+
* @tutorial https://axe-api.com/learn/routing.html#model-relations
|
|
310
|
+
*/
|
|
311
|
+
belongsTo(relatedModel, primaryKey, foreignKey) {
|
|
312
|
+
return this.hasOne(relatedModel, foreignKey, primaryKey);
|
|
313
|
+
}
|
|
50
314
|
getFillableFields(methodType) {
|
|
51
315
|
var _a, _b, _c;
|
|
52
316
|
if (this.fillable === null) {
|
|
@@ -89,9 +353,9 @@ class Model {
|
|
|
89
353
|
if (Array.isArray(middlewares)) {
|
|
90
354
|
middlewares.forEach((item) => {
|
|
91
355
|
if (item === null || item === void 0 ? void 0 : item.handler) {
|
|
92
|
-
const
|
|
93
|
-
if (
|
|
94
|
-
results.push(
|
|
356
|
+
const handlerBasedMiddlewares = item;
|
|
357
|
+
if (handlerBasedMiddlewares.handler.includes(handlerType)) {
|
|
358
|
+
results.push(handlerBasedMiddlewares.middleware);
|
|
95
359
|
}
|
|
96
360
|
}
|
|
97
361
|
else {
|
|
@@ -100,41 +364,69 @@ class Model {
|
|
|
100
364
|
});
|
|
101
365
|
}
|
|
102
366
|
else {
|
|
103
|
-
const
|
|
104
|
-
if (
|
|
105
|
-
results.push(
|
|
367
|
+
const handlerBasedMiddlewares = middlewares;
|
|
368
|
+
if (handlerBasedMiddlewares.handler.includes(handlerType)) {
|
|
369
|
+
results.push(handlerBasedMiddlewares.middleware);
|
|
106
370
|
}
|
|
107
371
|
}
|
|
108
372
|
return results;
|
|
109
373
|
}
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
374
|
+
/**
|
|
375
|
+
* In this function, you can use your custom Elastic Search query for the
|
|
376
|
+
* full-text search feature.
|
|
377
|
+
*
|
|
378
|
+
* By default, Axe API uses a simple full-text search.
|
|
379
|
+
*
|
|
380
|
+
* @example
|
|
381
|
+
* get getSearchQuery(params: IElasticSearchParameters) {
|
|
382
|
+
* return {
|
|
383
|
+
* // your query
|
|
384
|
+
* }
|
|
385
|
+
* }
|
|
386
|
+
* @tutorial https://axe-api.com/reference/model-get-search-query.html
|
|
387
|
+
*/
|
|
388
|
+
getSearchQuery(params) {
|
|
389
|
+
const { req, model, relation, parentModel, text } = params;
|
|
390
|
+
// Creating the basic search query
|
|
391
|
+
const query = {
|
|
392
|
+
bool: {
|
|
393
|
+
must: [
|
|
394
|
+
{
|
|
395
|
+
query_string: {
|
|
396
|
+
query: `*${text}*`,
|
|
397
|
+
analyze_wildcard: true,
|
|
398
|
+
},
|
|
399
|
+
},
|
|
400
|
+
],
|
|
401
|
+
},
|
|
121
402
|
};
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
403
|
+
// If there is any parent query, we should be able to that parent conditions
|
|
404
|
+
// to the ElasticSearch query.
|
|
405
|
+
const parentIndexQuery = (0, Helpers_1.getParentIndexQuery)(req, relation, parentModel);
|
|
406
|
+
if (Object.keys(parentIndexQuery).length > 0) {
|
|
407
|
+
query.bool.must.push({
|
|
408
|
+
term: parentIndexQuery,
|
|
409
|
+
});
|
|
410
|
+
}
|
|
411
|
+
// If there is a deletedAtColumn, it means that this table support soft-delete
|
|
412
|
+
if (model.instance.deletedAtColumn) {
|
|
413
|
+
query.bool.must_not = {
|
|
414
|
+
exists: {
|
|
415
|
+
field: model.instance.deletedAtColumn,
|
|
416
|
+
},
|
|
417
|
+
};
|
|
126
418
|
}
|
|
127
419
|
return {
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
420
|
+
query,
|
|
421
|
+
sort: [
|
|
422
|
+
{
|
|
423
|
+
_score: {
|
|
424
|
+
order: "desc",
|
|
425
|
+
},
|
|
426
|
+
},
|
|
427
|
+
],
|
|
133
428
|
};
|
|
134
429
|
}
|
|
135
|
-
belongsTo(relatedModel, primaryKey, foreignKey) {
|
|
136
|
-
return this.hasOne(relatedModel, foreignKey, primaryKey);
|
|
137
|
-
}
|
|
138
430
|
hasStringValue() {
|
|
139
431
|
const tester = this.validations;
|
|
140
432
|
let status = false;
|