@ditojs/server 1.13.0 → 1.14.0
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/package.json +16 -15
- package/src/app/Application.js +198 -186
- package/src/controllers/CollectionController.js +18 -14
- package/src/controllers/Controller.js +42 -29
- package/src/controllers/ModelController.js +13 -4
- package/src/controllers/RelationController.js +9 -5
- package/src/lib/EventEmitter.js +1 -1
- package/src/mixins/UserMixin.js +1 -2
- package/src/models/Model.js +19 -11
- package/src/query/QueryBuilder.js +2 -2
- package/src/services/Service.js +4 -2
- package/src/storage/DiskStorage.js +1 -3
- package/src/storage/S3Storage.js +10 -4
- package/src/storage/Storage.js +10 -0
- package/types/index.d.ts +599 -543
package/types/index.d.ts
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
|
|
6
6
|
// Export the entire Dito namespace.
|
|
7
7
|
|
|
8
|
-
import { DateFormat } from '@
|
|
8
|
+
import { DateFormat } from '@dito/utils'
|
|
9
9
|
import koaCors from '@koa/cors'
|
|
10
10
|
import * as Ajv from 'ajv/dist/2020.js'
|
|
11
11
|
import * as aws from 'aws-sdk'
|
|
@@ -23,101 +23,102 @@ import koaResponseTime from 'koa-response-time'
|
|
|
23
23
|
import koaSession from 'koa-session'
|
|
24
24
|
import * as objection from 'objection'
|
|
25
25
|
import { KnexSnakeCaseMappersFactory } from 'objection'
|
|
26
|
-
import {
|
|
26
|
+
import {
|
|
27
|
+
Class,
|
|
28
|
+
ConditionalExcept,
|
|
29
|
+
ConditionalKeys,
|
|
30
|
+
Constructor,
|
|
31
|
+
SetOptional,
|
|
32
|
+
SetReturnType
|
|
33
|
+
} from 'type-fest'
|
|
27
34
|
import { UserConfig } from 'vite'
|
|
28
35
|
|
|
29
|
-
export type Page<$Model extends Model> = {
|
|
36
|
+
export type Page<$Model extends Model = Model> = {
|
|
30
37
|
total: number
|
|
31
38
|
results: $Model[]
|
|
32
39
|
}
|
|
33
40
|
|
|
34
41
|
export type ApplicationConfig = {
|
|
35
|
-
/**
|
|
36
|
-
* @defaultValue `production`
|
|
37
|
-
*/
|
|
42
|
+
/** @defaultValue `production` */
|
|
38
43
|
env?: 'production' | 'development'
|
|
39
|
-
/**
|
|
40
|
-
* The server configuration
|
|
41
|
-
*/
|
|
44
|
+
/** The server configuration */
|
|
42
45
|
server?: {
|
|
43
|
-
/**
|
|
44
|
-
* The ip address or hostname used to serve requests
|
|
45
|
-
*/
|
|
46
|
+
/** The ip address or hostname used to serve requests */
|
|
46
47
|
host?: string
|
|
47
|
-
/**
|
|
48
|
-
* The port to listen on for connections
|
|
49
|
-
*/
|
|
48
|
+
/** The port to listen on for connections */
|
|
50
49
|
port?: string
|
|
51
50
|
}
|
|
52
|
-
/**
|
|
53
|
-
* Logging options
|
|
54
|
-
*/
|
|
51
|
+
/** Logging options */
|
|
55
52
|
log?: {
|
|
56
53
|
/**
|
|
57
54
|
* Enable logging requests to console by passing `true` or pick between
|
|
58
55
|
* 'console' for logging to console and 'file' for logging to file
|
|
56
|
+
*
|
|
59
57
|
* @defaultValue `false`
|
|
60
58
|
*/
|
|
61
59
|
requests?: boolean | 'console' | 'file'
|
|
62
60
|
/**
|
|
63
61
|
* Whether to output route (Controller) logs
|
|
62
|
+
*
|
|
64
63
|
* @defaultValue `false`
|
|
65
64
|
*/
|
|
66
65
|
routes?: boolean
|
|
67
66
|
/**
|
|
68
67
|
* Whether to log relation mappings
|
|
68
|
+
*
|
|
69
69
|
* @defaultValue `false`
|
|
70
70
|
*/
|
|
71
71
|
relations?: boolean
|
|
72
72
|
/**
|
|
73
73
|
* Whether to log the json schema generated out of the model property
|
|
74
74
|
* definitions
|
|
75
|
+
*
|
|
75
76
|
* @defaultValue `false`
|
|
76
77
|
*/
|
|
77
78
|
schema?: boolean
|
|
78
79
|
/**
|
|
79
80
|
* Whether to log sql queries
|
|
81
|
+
*
|
|
80
82
|
* @defaultValue `false`
|
|
81
83
|
*/
|
|
82
84
|
sql?: boolean
|
|
83
|
-
/**
|
|
84
|
-
* Whether to turn off all logging
|
|
85
|
-
*/
|
|
85
|
+
/** Whether to turn off all logging */
|
|
86
86
|
silent?: boolean
|
|
87
|
-
errors?:
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
json?: boolean
|
|
97
|
-
}
|
|
87
|
+
errors?:
|
|
88
|
+
| boolean
|
|
89
|
+
| {
|
|
90
|
+
/** Whether to log sql errors */
|
|
91
|
+
sql?: boolean
|
|
92
|
+
/** Whether to log the error stack */
|
|
93
|
+
stack?: boolean
|
|
94
|
+
json?: boolean
|
|
95
|
+
}
|
|
98
96
|
}
|
|
99
97
|
api?: ApiConfig
|
|
100
98
|
app?: {
|
|
101
99
|
/**
|
|
102
100
|
* Whether to normalize paths from camel case to kebab case.
|
|
103
|
-
* @see {@link https://github.com/ditojs/dito/blob/master/docs/controllers.md#path-normalization|Path Normalization}
|
|
104
101
|
*
|
|
105
102
|
* @defaultValue `false`
|
|
103
|
+
* @see {@link https://github.com/ditojs/dito/blob/master/docs/controllers.md#path-normalization|Path Normalization}
|
|
106
104
|
*/
|
|
107
105
|
normalizePaths?: boolean
|
|
108
106
|
/**
|
|
109
107
|
* Whether proxy header fields will be trusted.
|
|
108
|
+
*
|
|
110
109
|
* @defaultValue `false`
|
|
111
110
|
*/
|
|
112
111
|
proxy?: Koa['proxy']
|
|
113
112
|
/**
|
|
114
113
|
* Whether to include X-Response-Time header in responses
|
|
114
|
+
*
|
|
115
115
|
* @defaultValue `true`
|
|
116
116
|
*/
|
|
117
117
|
responseTime?: boolean | Parameters<typeof koaResponseTime>[0]
|
|
118
118
|
/**
|
|
119
119
|
* Whether to use koa-helmet middleware which provides important security
|
|
120
120
|
* headers to make your app more secure by default.
|
|
121
|
+
*
|
|
121
122
|
* @defaultValue `true`
|
|
122
123
|
* @see https://github.com/venables/koa-helmet
|
|
123
124
|
* @see https://github.com/helmetjs/helmet
|
|
@@ -128,23 +129,27 @@ export type ApplicationConfig = {
|
|
|
128
129
|
| Parameters<typeof koaPinoLogger>[0]
|
|
129
130
|
/**
|
|
130
131
|
* Configure body parser.
|
|
132
|
+
*
|
|
131
133
|
* @see https://github.com/koajs/bodyparser#options
|
|
132
134
|
*/
|
|
133
135
|
bodyParser?: koaBodyParser.Options
|
|
134
136
|
/**
|
|
135
137
|
* Enable or configure Cross-Origin Resource Sharing (CORS)
|
|
138
|
+
*
|
|
136
139
|
* @defaultValue `true`
|
|
137
140
|
* @see https://github.com/koajs/cors#corsoptions
|
|
138
141
|
*/
|
|
139
142
|
cors?: boolean | koaCors.Options
|
|
140
143
|
/**
|
|
141
144
|
* Enable or configure server response compression
|
|
145
|
+
*
|
|
142
146
|
* @defaultValue `true`
|
|
143
147
|
* @see https://github.com/koajs/compress#options
|
|
144
148
|
*/
|
|
145
149
|
compress?: boolean | koaCompress.CompressOptions
|
|
146
150
|
/**
|
|
147
151
|
* Enable ETag headers in server responses
|
|
152
|
+
*
|
|
148
153
|
* @defaultValue `true`
|
|
149
154
|
*/
|
|
150
155
|
etag?: boolean
|
|
@@ -155,27 +160,25 @@ export type ApplicationConfig = {
|
|
|
155
160
|
session?: boolean | (koaSession.opts & { modelClass: string })
|
|
156
161
|
/**
|
|
157
162
|
* Enable passport authentication middleware
|
|
163
|
+
*
|
|
158
164
|
* @defaultValue `false`
|
|
159
165
|
*/
|
|
160
166
|
passport?: boolean
|
|
161
167
|
/**
|
|
162
168
|
* Set signed cookie keys.
|
|
169
|
+
*
|
|
163
170
|
* @see https://github.com/koajs/koa/blob/master/docs/api/index.md#appkeys
|
|
164
171
|
*/
|
|
165
172
|
keys?: Koa['keys']
|
|
166
173
|
}
|
|
167
174
|
admin?: AdminConfig
|
|
168
175
|
knex?: Knex.Config<any> & {
|
|
169
|
-
/**
|
|
170
|
-
* @defaultValue `false`
|
|
171
|
-
*/
|
|
176
|
+
/** @defaultValue `false` */
|
|
172
177
|
normalizeDbNames?: boolean | Parameters<KnexSnakeCaseMappersFactory>
|
|
173
178
|
// See https://github.com/brianc/node-pg-types/blob/master/index.d.ts#L67
|
|
174
|
-
typeParsers?: Record<number, <I extends
|
|
179
|
+
typeParsers?: Record<number, <I extends string | Buffer>(value: I) => any>
|
|
175
180
|
}
|
|
176
|
-
/**
|
|
177
|
-
* Service configurations. Pass `false` as a value to disable a service.
|
|
178
|
-
*/
|
|
181
|
+
/** Service configurations. Pass `false` as a value to disable a service. */
|
|
179
182
|
services?: Services
|
|
180
183
|
storages?: StorageConfigs
|
|
181
184
|
assets?: {
|
|
@@ -183,7 +186,9 @@ export type ApplicationConfig = {
|
|
|
183
186
|
* Threshold after which unused assets that haven't seen changes for given
|
|
184
187
|
* timeframe are removed.
|
|
185
188
|
*
|
|
186
|
-
* @example
|
|
189
|
+
* @example
|
|
190
|
+
* '1 hr 20 mins'
|
|
191
|
+
*
|
|
187
192
|
* @default `0`
|
|
188
193
|
* @see https://www.npmjs.com/package/parse-duration
|
|
189
194
|
*/
|
|
@@ -204,19 +209,14 @@ export type MulterS3File = {
|
|
|
204
209
|
etag: string
|
|
205
210
|
}
|
|
206
211
|
|
|
207
|
-
export type StorageConfigs = {[key: string]: StorageConfig}
|
|
212
|
+
export type StorageConfigs = { [key: string]: StorageConfig }
|
|
208
213
|
|
|
209
214
|
export type StorageConfig =
|
|
210
215
|
| {
|
|
211
216
|
type: 's3'
|
|
212
|
-
/**
|
|
213
|
-
* The name of the destination bucket.
|
|
214
|
-
*/
|
|
217
|
+
/** The name of the destination bucket. */
|
|
215
218
|
bucket: aws.S3.BucketName
|
|
216
|
-
/**
|
|
217
|
-
*
|
|
218
|
-
* @default 'private'
|
|
219
|
-
*/
|
|
219
|
+
/** @default 'private' */
|
|
220
220
|
acl: LiteralUnion<
|
|
221
221
|
| 'private'
|
|
222
222
|
| 'public-read'
|
|
@@ -227,8 +227,7 @@ export type StorageConfig =
|
|
|
227
227
|
| 'bucket-owner-full-control'
|
|
228
228
|
>
|
|
229
229
|
/**
|
|
230
|
-
* Can be used to specify caching behavior along the request/reply
|
|
231
|
-
* chain.
|
|
230
|
+
* Can be used to specify caching behavior along the request/reply chain.
|
|
232
231
|
*
|
|
233
232
|
* @see http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.9.
|
|
234
233
|
*/
|
|
@@ -236,7 +235,7 @@ export type StorageConfig =
|
|
|
236
235
|
/**
|
|
237
236
|
* The type of storage to use for the object.
|
|
238
237
|
*
|
|
239
|
-
* @default 'STANDARD'
|
|
238
|
+
* @default 'STANDARD'
|
|
240
239
|
*/
|
|
241
240
|
storageClass?: LiteralUnion<
|
|
242
241
|
| 'STANDARD'
|
|
@@ -253,8 +252,8 @@ export type StorageConfig =
|
|
|
253
252
|
*/
|
|
254
253
|
serverSideEncryption?: aws.S3.ServerSideEncryption
|
|
255
254
|
/**
|
|
256
|
-
* If present, specifies the ID of the AWS Key Management Service
|
|
257
|
-
*
|
|
255
|
+
* If present, specifies the ID of the AWS Key Management Service (AWS
|
|
256
|
+
* KMS) symmetric customer managed customer master key (CMK)
|
|
258
257
|
*/
|
|
259
258
|
sseKmsKeyId?: aws.S3.SSEKMSKeyId
|
|
260
259
|
s3: aws.S3.ClientConfiguration
|
|
@@ -270,23 +269,15 @@ export type StorageConfig =
|
|
|
270
269
|
|
|
271
270
|
export interface AdminConfig {
|
|
272
271
|
api?: ApiConfig
|
|
272
|
+
/** Path to the admin's src directory. Mandatory when in development mode. */
|
|
273
|
+
root?: string
|
|
273
274
|
/**
|
|
274
|
-
* Path to the admin
|
|
275
|
-
* mode.
|
|
276
|
-
*/
|
|
277
|
-
root?: string;
|
|
278
|
-
/**
|
|
279
|
-
* Path to the dist/src/admin directory. Mandatory when in production
|
|
280
|
-
* mode.
|
|
281
|
-
*/
|
|
282
|
-
dist?: string;
|
|
283
|
-
/**
|
|
284
|
-
* @default Application.config.env or `'production'` when missing
|
|
275
|
+
* Path to the dist/src/admin directory. Mandatory when in production mode.
|
|
285
276
|
*/
|
|
277
|
+
dist?: string
|
|
278
|
+
/** @default Application */
|
|
286
279
|
mode?: 'production' | 'development'
|
|
287
|
-
/**
|
|
288
|
-
* Settings accessible on the browser side as `global.dito.settings`.
|
|
289
|
-
*/
|
|
280
|
+
/** Settings accessible on the browser side as `global.dito.settings`. */
|
|
290
281
|
settings?: Record<string, any>
|
|
291
282
|
}
|
|
292
283
|
|
|
@@ -297,13 +288,9 @@ export interface ApiResource {
|
|
|
297
288
|
}
|
|
298
289
|
|
|
299
290
|
export interface ApiConfig {
|
|
300
|
-
/**
|
|
301
|
-
* The base url to use for api requests.
|
|
302
|
-
*/
|
|
291
|
+
/** The base url to use for api requests. */
|
|
303
292
|
url?: string
|
|
304
|
-
/**
|
|
305
|
-
* @defaultValue 'en-US'
|
|
306
|
-
*/
|
|
293
|
+
/** @defaultValue 'en-US' */
|
|
307
294
|
locale?: string
|
|
308
295
|
dateFormat?: DateFormat
|
|
309
296
|
/**
|
|
@@ -317,8 +304,9 @@ export interface ApiConfig {
|
|
|
317
304
|
/**
|
|
318
305
|
* The amount of milliseconds multiplied with the amount of characters
|
|
319
306
|
* displayed in the notification, plus 40 (40 + title + message).
|
|
307
|
+
*
|
|
320
308
|
* @defaultValue `20`
|
|
321
|
-
|
|
309
|
+
*/
|
|
322
310
|
durationFactor: number
|
|
323
311
|
}
|
|
324
312
|
cors?: {
|
|
@@ -330,70 +318,55 @@ export interface ApiConfig {
|
|
|
330
318
|
/**
|
|
331
319
|
* Setting normalizePaths to `true` sets `api.normalizePath` to hyphenate
|
|
332
320
|
* camelized strings and `api.denormalizePath` to do the opposite. If you
|
|
333
|
-
* prefer to use another path normalization algorithm, they can be defined
|
|
334
|
-
*
|
|
321
|
+
* prefer to use another path normalization algorithm, they can be defined the
|
|
322
|
+
* api settings passed to the DitoAdmin constructor.
|
|
335
323
|
*
|
|
336
324
|
* @default Defaults to Application.config.app.normalizePaths and then
|
|
337
|
-
* `false` when missing.
|
|
338
325
|
*/
|
|
339
326
|
normalizePaths?: boolean
|
|
340
|
-
/**
|
|
341
|
-
* Auth resources
|
|
342
|
-
*/
|
|
327
|
+
/** Auth resources */
|
|
343
328
|
users?: {
|
|
344
329
|
path?: string
|
|
345
330
|
login?: {
|
|
346
|
-
/**
|
|
347
|
-
* @defaultValue `'login'`
|
|
348
|
-
*/
|
|
331
|
+
/** @defaultValue `'login'` */
|
|
349
332
|
path?: string
|
|
350
|
-
/**
|
|
351
|
-
* @defaultValue `'post'`
|
|
352
|
-
*/
|
|
333
|
+
/** @defaultValue `'post'` */
|
|
353
334
|
method?: HTTPMethod
|
|
354
335
|
}
|
|
355
336
|
logout?: {
|
|
356
|
-
/**
|
|
357
|
-
* @defaultValue `'logout'`
|
|
358
|
-
*/
|
|
337
|
+
/** @defaultValue `'logout'` */
|
|
359
338
|
path?: string
|
|
360
|
-
/**
|
|
361
|
-
* @defaultValue `'post'`
|
|
362
|
-
*/
|
|
339
|
+
/** @defaultValue `'post'` */
|
|
363
340
|
method?: HTTPMethod
|
|
364
341
|
}
|
|
365
342
|
session?: {
|
|
366
|
-
/**
|
|
367
|
-
* @defaultValue `'session'`
|
|
368
|
-
*/
|
|
343
|
+
/** @defaultValue `'session'` */
|
|
369
344
|
path?: string
|
|
370
|
-
/**
|
|
371
|
-
* @defaultValue `'get'`
|
|
372
|
-
*/
|
|
345
|
+
/** @defaultValue `'get'` */
|
|
373
346
|
method?: HTTPMethod
|
|
374
347
|
}
|
|
375
348
|
}
|
|
376
|
-
/**
|
|
377
|
-
* Optionally override resource path handlers.
|
|
378
|
-
*/
|
|
349
|
+
/** Optionally override resource path handlers. */
|
|
379
350
|
resources?: Record<string, (resource: ApiResource | string) => string>
|
|
380
351
|
|
|
381
352
|
/**
|
|
382
353
|
* Optionally override / extend headers
|
|
383
|
-
*
|
|
384
|
-
*
|
|
385
|
-
* }`
|
|
354
|
+
*
|
|
355
|
+
* @defaultValue `
|
|
386
356
|
*/
|
|
387
357
|
headers?: Record<string, string>
|
|
388
358
|
}
|
|
389
359
|
|
|
390
360
|
export interface ApplicationControllers {
|
|
391
|
-
[k: string]:
|
|
361
|
+
[k: string]:
|
|
362
|
+
| Class<ModelController>
|
|
363
|
+
| Class<Controller>
|
|
364
|
+
| ApplicationControllers
|
|
392
365
|
}
|
|
393
366
|
|
|
394
367
|
export type Models = Record<string, Class<Model>>
|
|
395
368
|
|
|
396
|
-
export class Application<$Models extends Models> {
|
|
369
|
+
export class Application<$Models extends Models = Models> {
|
|
397
370
|
constructor(options: {
|
|
398
371
|
config?: ApplicationConfig
|
|
399
372
|
validator?: Validator
|
|
@@ -412,20 +385,25 @@ export class Application<$Models extends Models> {
|
|
|
412
385
|
})
|
|
413
386
|
|
|
414
387
|
models: $Models
|
|
388
|
+
setup(): Promise<void>
|
|
389
|
+
execute(): Promise<void>
|
|
415
390
|
start(): Promise<void>
|
|
416
391
|
stop(timeout?: number): Promise<void>
|
|
417
|
-
|
|
418
|
-
|
|
392
|
+
addStorage(storage: StorageConfig): void
|
|
393
|
+
addStorages(storages: StorageConfigs): void
|
|
394
|
+
setupStorages(): Promise<void>
|
|
419
395
|
addService(service: Service): void
|
|
396
|
+
addServices(services: Services): void
|
|
397
|
+
setupServices(): Promise<void>
|
|
398
|
+
addModel(model: Class<Model>): void
|
|
399
|
+
addModels(models: Models): void
|
|
400
|
+
setupModels(): Promise<void>
|
|
420
401
|
addController(controllers: Controller, namespace?: string): void
|
|
421
402
|
addControllers(controllers: ApplicationControllers, namespace?: string): void
|
|
422
|
-
|
|
423
|
-
addStorage(storage: StorageConfig): void
|
|
424
|
-
addModels(models: Models): void
|
|
425
|
-
addModel(model: Class<Model>): void
|
|
403
|
+
setupControllers(): Promise<void>
|
|
426
404
|
getAdminViteConfig(config?: UserConfig): UserConfig
|
|
427
405
|
}
|
|
428
|
-
export interface Application
|
|
406
|
+
export interface Application
|
|
429
407
|
extends Omit<
|
|
430
408
|
Koa,
|
|
431
409
|
| 'setMaxListeners'
|
|
@@ -468,19 +446,19 @@ export interface ModelRelation {
|
|
|
468
446
|
>
|
|
469
447
|
/**
|
|
470
448
|
* The model and property name from which the relation is to be built, as a
|
|
471
|
-
* string with both identifiers separated by '.',
|
|
472
|
-
*
|
|
449
|
+
* string with both identifiers separated by '.', e.g.:
|
|
450
|
+
* 'FromModelClass.fromPropertyName'
|
|
473
451
|
*/
|
|
474
452
|
from: string
|
|
475
453
|
/**
|
|
476
454
|
* The model and property name to which the relation is to be built, as a
|
|
477
|
-
* string with both identifiers separated by '.',
|
|
478
|
-
*
|
|
455
|
+
* string with both identifiers separated by '.', e.g.:
|
|
456
|
+
* 'ToModelClass.toPropertyName'
|
|
479
457
|
*/
|
|
480
458
|
to: string
|
|
481
459
|
/**
|
|
482
|
-
* When set to true the join model class and table is to be built
|
|
483
|
-
* or allows to specify an existing one manually.
|
|
460
|
+
* When set to true the join model class and table is to be built
|
|
461
|
+
* automatically, or allows to specify an existing one manually.
|
|
484
462
|
*
|
|
485
463
|
* @see {@link https://github.com/ditojs/dito/blob/master/docs/model-relations.md#join-models-and-tables|Join Models and Tables}
|
|
486
464
|
*/
|
|
@@ -490,23 +468,24 @@ export interface ModelRelation {
|
|
|
490
468
|
/**
|
|
491
469
|
* The model and property name or table and column name of an existing
|
|
492
470
|
* join model class or join table from which the through relation is to
|
|
493
|
-
* be built, as a string with both identifiers separated by '.',
|
|
494
|
-
*
|
|
471
|
+
* be built, as a string with both identifiers separated by '.', e.g.:
|
|
472
|
+
* 'FromModelClass.fromPropertyName'
|
|
495
473
|
*/
|
|
496
474
|
from: string
|
|
497
475
|
/**
|
|
498
|
-
* The model and property name or table and column name of an existing
|
|
499
|
-
* model class or join table to which the through relation is to be
|
|
500
|
-
* as a string with both identifiers separated by '.',
|
|
501
|
-
*
|
|
476
|
+
* The model and property name or table and column name of an existing
|
|
477
|
+
* join model class or join table to which the through relation is to be
|
|
478
|
+
* built, as a string with both identifiers separated by '.', e.g.:
|
|
479
|
+
* 'toModelClass.toPropertyName'
|
|
502
480
|
*/
|
|
503
481
|
to: string
|
|
504
482
|
/**
|
|
505
483
|
* List additional columns to be added to the related model.
|
|
506
484
|
*
|
|
507
|
-
* When working with a join model class or table, extra columns from it
|
|
508
|
-
* be added to the related model, as if it was define on its own
|
|
509
|
-
* then appear as additional properties on the related
|
|
485
|
+
* When working with a join model class or table, extra columns from it
|
|
486
|
+
* can be added to the related model, as if it was define on its own
|
|
487
|
+
* table. They then appear as additional properties on the related
|
|
488
|
+
* model.
|
|
510
489
|
*/
|
|
511
490
|
extra?: string[]
|
|
512
491
|
}
|
|
@@ -515,8 +494,8 @@ export interface ModelRelation {
|
|
|
515
494
|
*
|
|
516
495
|
* This information is only required when working with through relations.
|
|
517
496
|
* Without it, Dito.js wouldn't be able to tell which side of the relation is
|
|
518
|
-
* on the left-hand side, and which is on the right-hand side when
|
|
519
|
-
* creating the join model class and table.
|
|
497
|
+
* on the left-hand side, and which is on the right-hand side when
|
|
498
|
+
* automatically creating the join model class and table.
|
|
520
499
|
*/
|
|
521
500
|
inverse?: boolean
|
|
522
501
|
/**
|
|
@@ -541,17 +520,14 @@ export interface ModelRelation {
|
|
|
541
520
|
}
|
|
542
521
|
|
|
543
522
|
export type ModelProperty<T = any> = Schema<T> & {
|
|
544
|
-
/**
|
|
545
|
-
* Marks the column as the primary key in the database.
|
|
546
|
-
*/
|
|
523
|
+
/** Marks the column as the primary key in the database. */
|
|
547
524
|
primary?: boolean
|
|
548
525
|
/**
|
|
549
526
|
* Defines if the property is a foreign key.
|
|
550
527
|
*
|
|
551
|
-
* Finds the information about the related model in the relations
|
|
552
|
-
*
|
|
553
|
-
*
|
|
554
|
-
* method.
|
|
528
|
+
* Finds the information about the related model in the relations definition
|
|
529
|
+
* and adds a reference to the related model table in migrations, by calling
|
|
530
|
+
* the .references(columnName).inTable(tableName) method.
|
|
555
531
|
*/
|
|
556
532
|
foreign?: boolean
|
|
557
533
|
/**
|
|
@@ -560,31 +536,30 @@ export type ModelProperty<T = any> = Schema<T> & {
|
|
|
560
536
|
*/
|
|
561
537
|
index?: boolean
|
|
562
538
|
/**
|
|
563
|
-
* Marks the column as nullable in the migrations, by calling the
|
|
564
|
-
*
|
|
539
|
+
* Marks the column as nullable in the migrations, by calling the .nullable()
|
|
540
|
+
* method.
|
|
565
541
|
*/
|
|
566
542
|
nullable?: boolean
|
|
567
543
|
/**
|
|
568
544
|
* Adds a unique constraint to the table for the given column in the
|
|
569
|
-
* migrations, by calling the .unique() method. If a string is provided,
|
|
570
|
-
*
|
|
571
|
-
*
|
|
545
|
+
* migrations, by calling the .unique() method. If a string is provided, all
|
|
546
|
+
* columns with the same string value for unique are grouped together in one
|
|
547
|
+
* unique constraint, by calling .unique([column1, column2, …]).
|
|
572
548
|
*/
|
|
573
549
|
unique?: boolean | string
|
|
574
550
|
/**
|
|
575
|
-
* Marks the column for a property of type 'integer' to be unsigned in
|
|
576
|
-
*
|
|
577
|
-
* method.
|
|
551
|
+
* Marks the column for a property of type 'integer' to be unsigned in the
|
|
552
|
+
* migrations, by calling the .index() method.calling the .unsigned() method.
|
|
578
553
|
*/
|
|
579
554
|
unsigned?: boolean
|
|
580
555
|
/**
|
|
581
556
|
* Marks the property as computed.
|
|
582
557
|
*
|
|
583
|
-
* Computed properties are not present as columns in the database itself.
|
|
584
|
-
*
|
|
585
|
-
*
|
|
586
|
-
*
|
|
587
|
-
*
|
|
558
|
+
* Computed properties are not present as columns in the database itself. They
|
|
559
|
+
* can be created either by an SQL statement (SELECT … AS), or by a getter
|
|
560
|
+
* accessor defined on the model. Computed properties are set when converting
|
|
561
|
+
* to JSON if not present already, and removed again before data is sent to
|
|
562
|
+
* the database.
|
|
588
563
|
*/
|
|
589
564
|
computed?: boolean
|
|
590
565
|
/**
|
|
@@ -596,24 +571,24 @@ export type ModelProperty<T = any> = Schema<T> & {
|
|
|
596
571
|
hidden?: boolean
|
|
597
572
|
}
|
|
598
573
|
|
|
599
|
-
export type ModelScope<$Model extends Model> = (
|
|
574
|
+
export type ModelScope<$Model extends Model = Model> = (
|
|
600
575
|
this: $Model,
|
|
601
576
|
query: QueryBuilder<$Model>,
|
|
602
577
|
applyParentScope: (query: QueryBuilder<$Model>) => QueryBuilder<$Model>
|
|
603
578
|
) => QueryBuilder<$Model, any> | void
|
|
604
579
|
|
|
605
|
-
export type ModelScopes<$Model extends Model> = Record<
|
|
580
|
+
export type ModelScopes<$Model extends Model = Model> = Record<
|
|
606
581
|
string,
|
|
607
582
|
ModelScope<$Model>
|
|
608
583
|
>
|
|
609
584
|
|
|
610
|
-
export type ModelFilterFunction<$Model extends Model> = (
|
|
585
|
+
export type ModelFilterFunction<$Model extends Model = Model> = (
|
|
611
586
|
queryBuilder: QueryBuilder<$Model>,
|
|
612
587
|
...args: any[]
|
|
613
588
|
) => void
|
|
614
589
|
|
|
615
|
-
export type ModelFilter<$Model extends Model> =
|
|
616
|
-
| {
|
|
590
|
+
export type ModelFilter<$Model extends Model = Model> =
|
|
591
|
+
| {
|
|
617
592
|
filter: 'text' | 'date-range'
|
|
618
593
|
properties?: string[]
|
|
619
594
|
}
|
|
@@ -623,9 +598,9 @@ export type ModelFilter<$Model extends Model> =
|
|
|
623
598
|
// TODO: validate type
|
|
624
599
|
validate?: any
|
|
625
600
|
}
|
|
626
|
-
| ModelFilterFunction<$Model
|
|
601
|
+
| ModelFilterFunction<$Model>
|
|
627
602
|
|
|
628
|
-
export type ModelFilters<$Model extends Model> = Record<
|
|
603
|
+
export type ModelFilters<$Model extends Model = Model> = Record<
|
|
629
604
|
string,
|
|
630
605
|
ModelFilter<$Model>
|
|
631
606
|
>
|
|
@@ -646,29 +621,26 @@ export interface ModelOptions extends objection.ModelOptions {
|
|
|
646
621
|
type ModelHookFunction<$Model extends Model> = (
|
|
647
622
|
args: objection.StaticHookArguments<$Model>
|
|
648
623
|
) => void
|
|
649
|
-
|
|
650
|
-
|
|
624
|
+
|
|
625
|
+
export type ModelHooks<$Model extends Model = Model> = {
|
|
626
|
+
[key in `${'before' | 'after'}:${
|
|
627
|
+
| 'find'
|
|
628
|
+
| 'insert'
|
|
629
|
+
| 'update'
|
|
630
|
+
| 'delete'}`]?: ModelHookFunction<$Model>
|
|
651
631
|
}
|
|
652
632
|
|
|
653
633
|
export class Model extends objection.Model {
|
|
654
|
-
/**
|
|
655
|
-
* @see {@link https://github.com/ditojs/dito/blob/master/docs/model-properties.md|Model Properties}
|
|
656
|
-
*/
|
|
634
|
+
/** @see {@link https://github.com/ditojs/dito/blob/master/docs/model-properties.md|Model Properties} */
|
|
657
635
|
static properties: ModelProperties
|
|
658
636
|
|
|
659
|
-
/**
|
|
660
|
-
* @see {@link https://github.com/ditojs/dito/blob/master/docs/model-relations.md|Model Relations}
|
|
661
|
-
*/
|
|
637
|
+
/** @see {@link https://github.com/ditojs/dito/blob/master/docs/model-relations.md|Model Relations} */
|
|
662
638
|
static relations: ModelRelations
|
|
663
639
|
|
|
664
|
-
/**
|
|
665
|
-
* @see {@link https://github.com/ditojs/dito/blob/master/docs/model-scopes.md|Model Scopes}
|
|
666
|
-
*/
|
|
640
|
+
/** @see {@link https://github.com/ditojs/dito/blob/master/docs/model-scopes.md|Model Scopes} */
|
|
667
641
|
static scopes: ModelScopes<Model>
|
|
668
642
|
|
|
669
|
-
/**
|
|
670
|
-
* @see {@link https://github.com/ditojs/dito/blob/master/docs/model-filters.md|Model Filters}
|
|
671
|
-
*/
|
|
643
|
+
/** @see {@link https://github.com/ditojs/dito/blob/master/docs/model-filters.md|Model Filters} */
|
|
672
644
|
static filters: ModelFilters<Model>
|
|
673
645
|
|
|
674
646
|
static hooks: ModelHooks<Model>
|
|
@@ -690,9 +662,8 @@ export class Model extends objection.Model {
|
|
|
690
662
|
readonly id: Id
|
|
691
663
|
|
|
692
664
|
/**
|
|
693
|
-
* Dito automatically adds a `foreignKeyId` property if foreign keys
|
|
694
|
-
*
|
|
695
|
-
* properties.
|
|
665
|
+
* Dito automatically adds a `foreignKeyId` property if foreign keys occurring
|
|
666
|
+
* in relations definitions are not explicitly defined in the properties.
|
|
696
667
|
*/
|
|
697
668
|
readonly foreignKeyId: Id
|
|
698
669
|
|
|
@@ -718,7 +689,7 @@ export class Model extends objection.Model {
|
|
|
718
689
|
|
|
719
690
|
$validateGraph(options: ModelOptions & Record<string, any>): Promise<this>
|
|
720
691
|
|
|
721
|
-
|
|
692
|
+
/* -------------------- Start QueryBuilder.mixin(Model) ------------------- */
|
|
722
693
|
static first: StaticQueryBuilderMethod<'first'>
|
|
723
694
|
static find: StaticQueryBuilderMethod<'find'>
|
|
724
695
|
static findOne: StaticQueryBuilderMethod<'findOne'>
|
|
@@ -764,13 +735,26 @@ export class Model extends objection.Model {
|
|
|
764
735
|
static upsertDitoGraph: StaticQueryBuilderMethod<'upsertDitoGraph'>
|
|
765
736
|
static updateDitoGraph: StaticQueryBuilderMethod<'updateDitoGraph'>
|
|
766
737
|
static patchDitoGraph: StaticQueryBuilderMethod<'patchDitoGraph'>
|
|
767
|
-
static insertDitoGraphAndFetch:
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
static
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
static
|
|
738
|
+
static insertDitoGraphAndFetch:
|
|
739
|
+
StaticQueryBuilderMethod<'insertDitoGraphAndFetch'>
|
|
740
|
+
|
|
741
|
+
static upsertDitoGraphAndFetch:
|
|
742
|
+
StaticQueryBuilderMethod<'upsertDitoGraphAndFetch'>
|
|
743
|
+
|
|
744
|
+
static updateDitoGraphAndFetch:
|
|
745
|
+
StaticQueryBuilderMethod<'updateDitoGraphAndFetch'>
|
|
746
|
+
|
|
747
|
+
static patchDitoGraphAndFetch:
|
|
748
|
+
StaticQueryBuilderMethod<'patchDitoGraphAndFetch'>
|
|
749
|
+
|
|
750
|
+
static upsertDitoGraphAndFetchById:
|
|
751
|
+
StaticQueryBuilderMethod<'upsertDitoGraphAndFetchById'>
|
|
752
|
+
|
|
753
|
+
static updateDitoGraphAndFetchById:
|
|
754
|
+
StaticQueryBuilderMethod<'updateDitoGraphAndFetchById'>
|
|
755
|
+
|
|
756
|
+
static patchDitoGraphAndFetchById:
|
|
757
|
+
StaticQueryBuilderMethod<'patchDitoGraphAndFetchById'>
|
|
774
758
|
|
|
775
759
|
static where: StaticQueryBuilderMethod<'where'>
|
|
776
760
|
static whereNot: StaticQueryBuilderMethod<'whereNot'>
|
|
@@ -798,7 +782,8 @@ export class Model extends objection.Model {
|
|
|
798
782
|
static whereJsonSubsetOf: StaticQueryBuilderMethod<'whereJsonSubsetOf'>
|
|
799
783
|
static whereJsonNotSubsetOf: StaticQueryBuilderMethod<'whereJsonNotSubsetOf'>
|
|
800
784
|
static whereJsonSupersetOf: StaticQueryBuilderMethod<'whereJsonSupersetOf'>
|
|
801
|
-
static whereJsonNotSupersetOf:
|
|
785
|
+
static whereJsonNotSupersetOf:
|
|
786
|
+
StaticQueryBuilderMethod<'whereJsonNotSupersetOf'>
|
|
802
787
|
|
|
803
788
|
static having: StaticQueryBuilderMethod<'having'>
|
|
804
789
|
static havingIn: StaticQueryBuilderMethod<'havingIn'>
|
|
@@ -836,6 +821,7 @@ type StaticQueryBuilderMethod<
|
|
|
836
821
|
...args: Parameters<QueryBuilder<InstanceType<$Model>>[K]>
|
|
837
822
|
) => ReturnType<QueryBuilder<InstanceType<$Model>>[K]>
|
|
838
823
|
|
|
824
|
+
// @eslint-disable-next-line @typescript-eslint/no-empty-interface
|
|
839
825
|
export interface Model extends EventEmitter {}
|
|
840
826
|
export interface Model extends KnexHelper {}
|
|
841
827
|
|
|
@@ -845,20 +831,20 @@ export type ModelRelations = Record<string, ModelRelation>
|
|
|
845
831
|
|
|
846
832
|
export type ModelProperties = Record<string, ModelProperty>
|
|
847
833
|
|
|
848
|
-
export type ControllerAction<$Controller extends Controller> =
|
|
834
|
+
export type ControllerAction<$Controller extends Controller = Controller> =
|
|
849
835
|
| ControllerActionOptions<$Controller>
|
|
850
836
|
| ControllerActionHandler<$Controller>
|
|
851
837
|
|
|
852
838
|
export class Controller {
|
|
853
839
|
app: Application
|
|
854
840
|
/**
|
|
855
|
-
* Optionally provide the controller path. A default is deducted from
|
|
856
|
-
*
|
|
841
|
+
* Optionally provide the controller path. A default is deducted from the
|
|
842
|
+
* normalized class name otherwise.
|
|
857
843
|
*/
|
|
858
844
|
path?: string
|
|
859
845
|
/**
|
|
860
|
-
* The controller's name. If not provided, it is automatically deducted
|
|
861
|
-
*
|
|
846
|
+
* The controller's name. If not provided, it is automatically deducted from
|
|
847
|
+
* the controller class name. If this name ends in 'Controller', that is
|
|
862
848
|
* stripped off the name, so 'GreetingsController' turns into 'Greetings'.
|
|
863
849
|
*/
|
|
864
850
|
name?: string
|
|
@@ -866,7 +852,8 @@ export class Controller {
|
|
|
866
852
|
* The controller's namespace, which is prepended to path to generate the
|
|
867
853
|
* absolute controller route. Note that it is rare to provide this manually.
|
|
868
854
|
* Usually Dito.js determines the namespace automatically from the controller
|
|
869
|
-
* object passed to the Dito.js application's constructor and its
|
|
855
|
+
* object passed to the Dito.js application's constructor and its
|
|
856
|
+
* sub-objects.
|
|
870
857
|
*
|
|
871
858
|
* @see {@link https://github.com/ditojs/dito/blob/master/docs/controllers.md#namespaces Namespaces}
|
|
872
859
|
*/
|
|
@@ -877,17 +864,16 @@ export class Controller {
|
|
|
877
864
|
*/
|
|
878
865
|
allow?: OrReadOnly<ControllerActionName[]>
|
|
879
866
|
|
|
880
|
-
/**
|
|
881
|
-
* Authorization
|
|
882
|
-
*/
|
|
867
|
+
/** Authorization */
|
|
883
868
|
authorize?: Authorize
|
|
884
869
|
actions?: ControllerActions<this>
|
|
885
870
|
|
|
871
|
+
configure(): void
|
|
872
|
+
setup(): void
|
|
886
873
|
initialize(): void
|
|
887
|
-
setup(isRoot: boolean, setupActionsObject: boolean): void
|
|
888
874
|
// TODO: type reflectActionsObject
|
|
889
875
|
reflectActionsObject(): any
|
|
890
|
-
setupRoute<$ControllerAction extends ControllerAction
|
|
876
|
+
setupRoute<$ControllerAction extends ControllerAction = ControllerAction>(
|
|
891
877
|
method: HTTPMethod,
|
|
892
878
|
url: string,
|
|
893
879
|
transacted: boolean,
|
|
@@ -906,9 +892,7 @@ export class Controller {
|
|
|
906
892
|
): void
|
|
907
893
|
|
|
908
894
|
compose(): Parameters<typeof mount>[1]
|
|
909
|
-
/**
|
|
910
|
-
* To be overridden by sub-classes.
|
|
911
|
-
*/
|
|
895
|
+
/** To be overridden by sub-classes. */
|
|
912
896
|
getPath(type: string, path: string): string
|
|
913
897
|
getUrl(type: string, path: string): string
|
|
914
898
|
inheritValues(type: string): any
|
|
@@ -930,9 +914,9 @@ export class Controller {
|
|
|
930
914
|
describeAuthorize(authorize: any): string
|
|
931
915
|
handleAuthorization(): Promise<void>
|
|
932
916
|
/**
|
|
933
|
-
*
|
|
934
917
|
* @param str The string to log.
|
|
935
918
|
* @param [indent=0] The amount of levels to indent (in pairs of two spaces).
|
|
919
|
+
* Default is `0`
|
|
936
920
|
*/
|
|
937
921
|
log(str: string, indent?: number): void
|
|
938
922
|
}
|
|
@@ -940,14 +924,12 @@ export class Controller {
|
|
|
940
924
|
export type ActionParameter = Schema & { name: string }
|
|
941
925
|
|
|
942
926
|
export type ModelControllerActionHandler<
|
|
943
|
-
$ModelController extends ModelController
|
|
927
|
+
$ModelController extends ModelController = ModelController
|
|
944
928
|
> = (this: $ModelController, ctx: KoaContext, ...args: any[]) => any
|
|
945
929
|
|
|
946
|
-
export type ControllerActionHandler
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
...args: any[]
|
|
950
|
-
) => any
|
|
930
|
+
export type ControllerActionHandler<
|
|
931
|
+
$Controller extends Controller = Controller
|
|
932
|
+
> = (this: $Controller, ctx: KoaContext, ...args: any[]) => any
|
|
951
933
|
|
|
952
934
|
export type ExtractModelProperties<$Model> = {
|
|
953
935
|
[$Key in SelectModelPropertyKeys<$Model>]: $Model[$Key] extends Model
|
|
@@ -955,14 +937,17 @@ export type ExtractModelProperties<$Model> = {
|
|
|
955
937
|
: $Model[$Key]
|
|
956
938
|
}
|
|
957
939
|
|
|
958
|
-
export type Extends<$A
|
|
940
|
+
export type Extends<$A, $B> = $A extends $B ? 1 : 0
|
|
959
941
|
|
|
960
942
|
export type SelectModelPropertyKeys<$Model extends Model> = {
|
|
961
|
-
[K in keyof $Model]-?: K extends
|
|
943
|
+
[K in keyof $Model]-?: K extends
|
|
944
|
+
| 'QueryBuilderType'
|
|
945
|
+
| 'foreignKeyId'
|
|
946
|
+
| `$${string}`
|
|
962
947
|
? never
|
|
963
948
|
: $Model[K] extends Function
|
|
964
|
-
|
|
965
|
-
|
|
949
|
+
? never
|
|
950
|
+
: K
|
|
966
951
|
}[keyof $Model]
|
|
967
952
|
|
|
968
953
|
export type Authorize =
|
|
@@ -985,22 +970,22 @@ export type BaseControllerActionOptions = {
|
|
|
985
970
|
*/
|
|
986
971
|
path?: string
|
|
987
972
|
/**
|
|
988
|
-
* Determines whether or how the request is authorized. This value can
|
|
989
|
-
*
|
|
990
|
-
*
|
|
973
|
+
* Determines whether or how the request is authorized. This value can either
|
|
974
|
+
* be one of the values as described below, an array of them or a function
|
|
975
|
+
* which returns one or more of them.
|
|
991
976
|
*
|
|
992
|
-
* -
|
|
993
|
-
* - '$self': The requested member is checked against `ctx.state.user`
|
|
994
|
-
*
|
|
995
|
-
* - '$owner': The member is asked if it is owned by `ctx.state.user`
|
|
996
|
-
*
|
|
997
|
-
* -
|
|
998
|
-
*
|
|
977
|
+
* - Boolean: `true` if the action should be authorized, `false` otherwise.
|
|
978
|
+
* - '$self': The requested member is checked against `ctx.state.user` and the
|
|
979
|
+
* action is only authorized if it matches the member.
|
|
980
|
+
* - '$owner': The member is asked if it is owned by `ctx.state.user` through
|
|
981
|
+
* the optional `Model.$hasOwner()` method.
|
|
982
|
+
* - Any string: `ctx.state.user` is checked for this role through the
|
|
983
|
+
* overridable `UserModel.hasRole()` method.
|
|
999
984
|
*/
|
|
1000
985
|
authorize?: Authorize
|
|
1001
986
|
/**
|
|
1002
|
-
* Validates action parameters and maps them to Koa's `ctx.query` object
|
|
1003
|
-
* to the action handler.
|
|
987
|
+
* Validates action parameters and maps them to Koa's `ctx.query` object
|
|
988
|
+
* passed to the action handler.
|
|
1004
989
|
*
|
|
1005
990
|
* @see {@link https://github.com/ditojs/dito/blob/master/docs/model-properties.md Model Properties}
|
|
1006
991
|
*/
|
|
@@ -1020,94 +1005,88 @@ export type BaseControllerActionOptions = {
|
|
|
1020
1005
|
*/
|
|
1021
1006
|
scope?: string[]
|
|
1022
1007
|
/**
|
|
1023
|
-
* Determines whether queries in the action should be executed within
|
|
1024
|
-
*
|
|
1025
|
-
*
|
|
1008
|
+
* Determines whether queries in the action should be executed within a
|
|
1009
|
+
* transaction. Any failure will mean the database will rollback any queries
|
|
1010
|
+
* executed to the pre-transaction state.
|
|
1026
1011
|
*/
|
|
1027
1012
|
transacted?: boolean
|
|
1028
1013
|
}
|
|
1029
1014
|
|
|
1030
|
-
export type ControllerActionOptions
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1015
|
+
export type ControllerActionOptions<
|
|
1016
|
+
$Controller extends Controller = Controller
|
|
1017
|
+
> = BaseControllerActionOptions & {
|
|
1018
|
+
handler: ControllerActionHandler<$Controller>
|
|
1019
|
+
}
|
|
1034
1020
|
|
|
1035
1021
|
export type ModelControllerActionOptions<
|
|
1036
|
-
$ModelController extends ModelController
|
|
1022
|
+
$ModelController extends ModelController = ModelController
|
|
1037
1023
|
> = BaseControllerActionOptions & {
|
|
1038
|
-
/**
|
|
1039
|
-
* The function to be called when the action route is requested.
|
|
1040
|
-
*/
|
|
1024
|
+
/** The function to be called when the action route is requested. */
|
|
1041
1025
|
handler: ModelControllerActionHandler<$ModelController>
|
|
1042
1026
|
}
|
|
1043
1027
|
|
|
1044
|
-
export type MemberActionParameter
|
|
1028
|
+
export type MemberActionParameter<$Model extends Model = Model> =
|
|
1045
1029
|
| Schema
|
|
1046
1030
|
| {
|
|
1047
1031
|
member: true
|
|
1048
1032
|
|
|
1049
|
-
/**
|
|
1050
|
-
* Sets ctx.query.
|
|
1051
|
-
*/
|
|
1033
|
+
/** Sets ctx.query. */
|
|
1052
1034
|
query?: Record<string, any>
|
|
1053
1035
|
/**
|
|
1054
1036
|
* Adds a FOR UPDATE in PostgreSQL and MySQL during a select statement.
|
|
1055
|
-
* FOR UPDATE causes the rows retrieved by the SELECT statement to be
|
|
1056
|
-
* as though for update. This prevents them from being locked,
|
|
1057
|
-
* deleted by other transactions until the current transaction
|
|
1037
|
+
* FOR UPDATE causes the rows retrieved by the SELECT statement to be
|
|
1038
|
+
* locked as though for update. This prevents them from being locked,
|
|
1039
|
+
* modified or deleted by other transactions until the current transaction
|
|
1040
|
+
* ends.
|
|
1058
1041
|
*
|
|
1059
1042
|
* @default `false`
|
|
1060
1043
|
* @see {@link http://knexjs.org/#Builder-forUpdate}
|
|
1061
1044
|
* @see {@link https://www.postgresql.org/docs/12/explicit-locking.html#LOCKING-ROWS}
|
|
1062
1045
|
*/
|
|
1063
1046
|
forUpdate?: boolean
|
|
1064
|
-
/**
|
|
1065
|
-
|
|
1066
|
-
*/
|
|
1067
|
-
modify?: (query: QueryBuilder<M>) => QueryBuilder<M>
|
|
1047
|
+
/** Modify the member query. */
|
|
1048
|
+
modify?: (query: QueryBuilder<$Model>) => QueryBuilder<$Model>
|
|
1068
1049
|
}
|
|
1069
1050
|
|
|
1070
1051
|
export type ModelControllerAction<
|
|
1071
|
-
$ModelController extends ModelController
|
|
1052
|
+
$ModelController extends ModelController = ModelController
|
|
1072
1053
|
> =
|
|
1073
1054
|
| ModelControllerActionOptions<$ModelController>
|
|
1074
|
-
| ModelControllerActionHandler<$ModelController
|
|
1055
|
+
| ModelControllerActionHandler<$ModelController>
|
|
1075
1056
|
|
|
1076
1057
|
export type ModelControllerActions<
|
|
1077
|
-
$ModelController extends ModelController
|
|
1058
|
+
$ModelController extends ModelController = ModelController
|
|
1078
1059
|
> = {
|
|
1079
|
-
[name: ControllerActionName]: ModelControllerAction<$ModelController
|
|
1080
|
-
allow?: OrReadOnly<ControllerActionName[]
|
|
1060
|
+
[name: ControllerActionName]: ModelControllerAction<$ModelController>
|
|
1061
|
+
allow?: OrReadOnly<ControllerActionName[]>
|
|
1081
1062
|
authorize?: Authorize
|
|
1082
1063
|
}
|
|
1083
1064
|
|
|
1084
1065
|
type ModelControllerMemberAction<
|
|
1085
|
-
$ModelController extends ModelController
|
|
1066
|
+
$ModelController extends ModelController = ModelController
|
|
1086
1067
|
> =
|
|
1087
|
-
| (
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
| ModelControllerActionHandler<$ModelController>
|
|
1096
|
-
)
|
|
1068
|
+
| (Omit<ModelControllerActionOptions<$ModelController>, 'parameters'> & {
|
|
1069
|
+
parameters?: {
|
|
1070
|
+
[key: string]: MemberActionParameter<
|
|
1071
|
+
ModelFromModelController<$ModelController>
|
|
1072
|
+
>
|
|
1073
|
+
}
|
|
1074
|
+
})
|
|
1075
|
+
| ModelControllerActionHandler<$ModelController>
|
|
1097
1076
|
|
|
1098
1077
|
export type ModelControllerMemberActions<
|
|
1099
|
-
$ModelController extends ModelController
|
|
1078
|
+
$ModelController extends ModelController = ModelController
|
|
1100
1079
|
> = {
|
|
1101
|
-
[name: ControllerActionName]: ModelControllerMemberAction<$ModelController
|
|
1102
|
-
allow?: OrReadOnly<ControllerActionName[]
|
|
1080
|
+
[name: ControllerActionName]: ModelControllerMemberAction<$ModelController>
|
|
1081
|
+
allow?: OrReadOnly<ControllerActionName[]>
|
|
1103
1082
|
authorize?: Authorize
|
|
1104
1083
|
}
|
|
1105
1084
|
|
|
1106
|
-
export type ControllerActionName = `${HTTPMethod}${string}
|
|
1085
|
+
export type ControllerActionName = `${HTTPMethod}${string}`
|
|
1107
1086
|
|
|
1108
|
-
export type ControllerActions<$Controller extends Controller> = {
|
|
1087
|
+
export type ControllerActions<$Controller extends Controller = Controller> = {
|
|
1109
1088
|
[name: ControllerActionName]: ControllerAction<$Controller>
|
|
1110
|
-
allow?: OrReadOnly<ControllerActionName[]
|
|
1089
|
+
allow?: OrReadOnly<ControllerActionName[]>
|
|
1111
1090
|
authorize?: Authorize
|
|
1112
1091
|
}
|
|
1113
1092
|
|
|
@@ -1139,15 +1118,15 @@ type ModelControllerHookKeys<
|
|
|
1139
1118
|
| ControllerActionName
|
|
1140
1119
|
| '*'}`
|
|
1141
1120
|
type ModelControllerHook<
|
|
1142
|
-
$ModelController extends ModelController
|
|
1121
|
+
$ModelController extends ModelController = ModelController
|
|
1143
1122
|
> = (
|
|
1144
1123
|
ctx: KoaContext,
|
|
1145
|
-
result: objection.Page<
|
|
1124
|
+
result: objection.Page<ModelFromModelController<$ModelController>>
|
|
1146
1125
|
) => any
|
|
1147
1126
|
|
|
1148
1127
|
type HookHandler = () => void
|
|
1149
1128
|
|
|
1150
|
-
type HookKeysFromController<$ModelController extends ModelController
|
|
1129
|
+
type HookKeysFromController<$ModelController extends ModelController> =
|
|
1151
1130
|
| ModelControllerHookKeys<
|
|
1152
1131
|
Exclude<
|
|
1153
1132
|
keyof Exclude<$ModelController['collection'], undefined>,
|
|
@@ -1164,7 +1143,7 @@ type HookKeysFromController<$ModelController extends ModelController<Model>> =
|
|
|
1164
1143
|
>
|
|
1165
1144
|
|
|
1166
1145
|
type HandlerFromHookKey<
|
|
1167
|
-
$ModelController extends ModelController
|
|
1146
|
+
$ModelController extends ModelController,
|
|
1168
1147
|
$Key extends HookKeysFromController<$ModelController>
|
|
1169
1148
|
> = $Key extends `${'before' | 'after' | '*'}:${
|
|
1170
1149
|
| 'collection'
|
|
@@ -1174,7 +1153,7 @@ type HandlerFromHookKey<
|
|
|
1174
1153
|
: never
|
|
1175
1154
|
|
|
1176
1155
|
type ModelControllerHooks<
|
|
1177
|
-
$ModelController extends ModelController
|
|
1156
|
+
$ModelController extends ModelController = ModelController
|
|
1178
1157
|
> = {
|
|
1179
1158
|
[$Key in HookKeysFromController<$ModelController>]?: HandlerFromHookKey<
|
|
1180
1159
|
$ModelController,
|
|
@@ -1186,20 +1165,20 @@ export type ModelControllerScope = OrArrayOf<string>
|
|
|
1186
1165
|
|
|
1187
1166
|
export class ModelController<$Model extends Model = Model> extends Controller {
|
|
1188
1167
|
/**
|
|
1189
|
-
* The model class that this controller represents. If none is provided,
|
|
1190
|
-
*
|
|
1191
|
-
*
|
|
1192
|
-
*
|
|
1168
|
+
* The model class that this controller represents. If none is provided, the
|
|
1169
|
+
* singularized controller name is used to look up the model class in models
|
|
1170
|
+
* registered with the application. As a convention, model controller names
|
|
1171
|
+
* should always be provided in pluralized form.
|
|
1193
1172
|
*/
|
|
1194
1173
|
modelClass?: Class<$Model>
|
|
1195
1174
|
/**
|
|
1196
1175
|
* The controller's collection actions. Instead of being provided on the
|
|
1197
|
-
* instance level as in the controller base class, they are to be wrapped
|
|
1198
|
-
*
|
|
1176
|
+
* instance level as in the controller base class, they are to be wrapped in a
|
|
1177
|
+
* designated object in order to be assigned to the collection.
|
|
1199
1178
|
*
|
|
1200
|
-
* To limit which collection actions will be mapped to routes, supply an
|
|
1201
|
-
*
|
|
1202
|
-
*
|
|
1179
|
+
* To limit which collection actions will be mapped to routes, supply an array
|
|
1180
|
+
* of action names under the `allow` key. Only the action names listed there
|
|
1181
|
+
* will be mapped to routes, everything else will be omitted.
|
|
1203
1182
|
*/
|
|
1204
1183
|
collection?: ModelControllerActions<ModelController<$Model>>
|
|
1205
1184
|
/**
|
|
@@ -1207,9 +1186,9 @@ export class ModelController<$Model extends Model = Model> extends Controller {
|
|
|
1207
1186
|
* level as in the controller base class, they are to be wrapped in a
|
|
1208
1187
|
* designated object in order to be assigned to the member.
|
|
1209
1188
|
*
|
|
1210
|
-
* To limit which member actions will be mapped to routes, supply an array
|
|
1211
|
-
*
|
|
1212
|
-
*
|
|
1189
|
+
* To limit which member actions will be mapped to routes, supply an array of
|
|
1190
|
+
* action names under the `allow` key. Only the action names listed there will
|
|
1191
|
+
* be mapped to routes, everything else will be omitted.
|
|
1213
1192
|
*/
|
|
1214
1193
|
member?: ModelControllerMemberActions<ModelController<$Model>>
|
|
1215
1194
|
assets?:
|
|
@@ -1235,7 +1214,7 @@ export class ModelController<$Model extends Model = Model> extends Controller {
|
|
|
1235
1214
|
* both on `collection` and `member` level. If none is provided, every
|
|
1236
1215
|
* supported parameter is allowed.
|
|
1237
1216
|
*
|
|
1238
|
-
* @
|
|
1217
|
+
* @see {@link https://github.com/ditojs/dito/blob/master/docs/model-queries.md#find-methods) Model Queries – Find Methods}
|
|
1239
1218
|
*/
|
|
1240
1219
|
allowParam?: OrArrayOf<LiteralUnion<keyof QueryParameterOptions>>
|
|
1241
1220
|
/**
|
|
@@ -1266,49 +1245,27 @@ export class ModelController<$Model extends Model = Model> extends Controller {
|
|
|
1266
1245
|
export class Validator extends objection.Validator {
|
|
1267
1246
|
constructor(schema?: {
|
|
1268
1247
|
options?: {
|
|
1269
|
-
/**
|
|
1270
|
-
* @defaultValue `false`
|
|
1271
|
-
*/
|
|
1248
|
+
/** @defaultValue `false` */
|
|
1272
1249
|
async?: boolean
|
|
1273
|
-
/**
|
|
1274
|
-
* @defaultValue `false`
|
|
1275
|
-
*/
|
|
1250
|
+
/** @defaultValue `false` */
|
|
1276
1251
|
patch?: boolean
|
|
1277
|
-
/**
|
|
1278
|
-
* @defaultValue `false`
|
|
1279
|
-
*/
|
|
1252
|
+
/** @defaultValue `false` */
|
|
1280
1253
|
$data?: boolean
|
|
1281
|
-
/**
|
|
1282
|
-
* @defaultValue `false`
|
|
1283
|
-
*/
|
|
1254
|
+
/** @defaultValue `false` */
|
|
1284
1255
|
$comment?: boolean
|
|
1285
|
-
/**
|
|
1286
|
-
* @defaultValue `false`
|
|
1287
|
-
*/
|
|
1256
|
+
/** @defaultValue `false` */
|
|
1288
1257
|
coerceTypes?: boolean
|
|
1289
|
-
/**
|
|
1290
|
-
* @defaultValue `false`
|
|
1291
|
-
*/
|
|
1258
|
+
/** @defaultValue `false` */
|
|
1292
1259
|
multipleOfPrecision?: boolean
|
|
1293
|
-
/**
|
|
1294
|
-
* @defaultValue `true`
|
|
1295
|
-
*/
|
|
1260
|
+
/** @defaultValue `true` */
|
|
1296
1261
|
ownProperties?: boolean
|
|
1297
|
-
/**
|
|
1298
|
-
* @defaultValue `false`
|
|
1299
|
-
*/
|
|
1262
|
+
/** @defaultValue `false` */
|
|
1300
1263
|
removeAdditional?: boolean
|
|
1301
|
-
/**
|
|
1302
|
-
* @defaultValue `true`
|
|
1303
|
-
*/
|
|
1264
|
+
/** @defaultValue `true` */
|
|
1304
1265
|
uniqueItems?: boolean
|
|
1305
|
-
/**
|
|
1306
|
-
* @defaultValue `true`
|
|
1307
|
-
*/
|
|
1266
|
+
/** @defaultValue `true` */
|
|
1308
1267
|
useDefaults?: boolean
|
|
1309
|
-
/**
|
|
1310
|
-
* @defaultValue `false`
|
|
1311
|
-
*/
|
|
1268
|
+
/** @defaultValue `false` */
|
|
1312
1269
|
verbose?: boolean
|
|
1313
1270
|
}
|
|
1314
1271
|
keywords?: Record<string, Keyword>
|
|
@@ -1466,9 +1423,9 @@ export type QueryParameterOptions = {
|
|
|
1466
1423
|
scope?: OrArrayOf<string>
|
|
1467
1424
|
filter?: OrArrayOf<string>
|
|
1468
1425
|
/**
|
|
1469
|
-
* A range between two numbers. When expressed as a string, the value
|
|
1470
|
-
*
|
|
1471
|
-
*
|
|
1426
|
+
* A range between two numbers. When expressed as a string, the value is split
|
|
1427
|
+
* at the ',' character ignoring any spaces on either side. i.e. `'1,2'` and
|
|
1428
|
+
* `'1 , 2'`
|
|
1472
1429
|
*/
|
|
1473
1430
|
range?: [number, number] | string
|
|
1474
1431
|
limit?: number
|
|
@@ -1479,13 +1436,9 @@ export type QueryParameterOptionKey = keyof QueryParameterOptions
|
|
|
1479
1436
|
|
|
1480
1437
|
export class Service {
|
|
1481
1438
|
constructor(app: Application<Models>, name?: string)
|
|
1482
|
-
|
|
1483
1439
|
setup(config: any): void
|
|
1484
|
-
|
|
1485
1440
|
initialize(): void
|
|
1486
|
-
|
|
1487
1441
|
start(): Promise<void>
|
|
1488
|
-
|
|
1489
1442
|
stop(): Promise<void>
|
|
1490
1443
|
}
|
|
1491
1444
|
export type Services = Record<string, Class<Service> | Service>
|
|
@@ -1495,14 +1448,13 @@ export class QueryBuilder<
|
|
|
1495
1448
|
R = M[]
|
|
1496
1449
|
> extends objection.QueryBuilder<M, R> {
|
|
1497
1450
|
/**
|
|
1498
|
-
* Returns true if the query defines normal selects:
|
|
1499
|
-
*
|
|
1451
|
+
* Returns true if the query defines normal selects: select(), column(),
|
|
1452
|
+
* columns()
|
|
1500
1453
|
*/
|
|
1501
1454
|
hasNormalSelects: () => boolean
|
|
1502
1455
|
/**
|
|
1503
|
-
* Returns true if the query defines special selects:
|
|
1504
|
-
*
|
|
1505
|
-
* sum(), sumDistinct(), avg(), avgDistinct()
|
|
1456
|
+
* Returns true if the query defines special selects: distinct(), count(),
|
|
1457
|
+
* countDistinct(), min(), max(), sum(), sumDistinct(), avg(), avgDistinct()
|
|
1506
1458
|
*/
|
|
1507
1459
|
hasSpecialSelects: () => boolean
|
|
1508
1460
|
withScope: (...scopes: string[]) => this
|
|
@@ -1645,16 +1597,13 @@ export class ResponseError extends Error {
|
|
|
1645
1597
|
constructor(
|
|
1646
1598
|
error:
|
|
1647
1599
|
| {
|
|
1648
|
-
/**
|
|
1649
|
-
* The http status code.
|
|
1650
|
-
*/
|
|
1600
|
+
/** The http status code. */
|
|
1651
1601
|
status: number
|
|
1652
|
-
/**
|
|
1653
|
-
* The error message.
|
|
1654
|
-
*/
|
|
1602
|
+
/** The error message. */
|
|
1655
1603
|
message?: string
|
|
1656
1604
|
/**
|
|
1657
|
-
* An optional code to be used to distinguish different error
|
|
1605
|
+
* An optional code to be used to distinguish different error
|
|
1606
|
+
* instances.
|
|
1658
1607
|
*/
|
|
1659
1608
|
code?: string | number
|
|
1660
1609
|
}
|
|
@@ -1702,19 +1651,19 @@ export type Mixin = (
|
|
|
1702
1651
|
|
|
1703
1652
|
type AssetFileObject = {
|
|
1704
1653
|
// The unique key within the storage (uuid/v4 + file extension)
|
|
1705
|
-
key: string
|
|
1654
|
+
key: string
|
|
1706
1655
|
// The original filename
|
|
1707
|
-
name: string
|
|
1656
|
+
name: string
|
|
1708
1657
|
// The file's mime-type
|
|
1709
|
-
type: string
|
|
1658
|
+
type: string
|
|
1710
1659
|
// The amount of bytes consumed by the file
|
|
1711
|
-
size: number
|
|
1660
|
+
size: number
|
|
1712
1661
|
// The public url of the file
|
|
1713
|
-
url: string
|
|
1662
|
+
url: string
|
|
1714
1663
|
// The width of the image if the storage defines `config.readImageSize`
|
|
1715
|
-
width: number
|
|
1664
|
+
width: number
|
|
1716
1665
|
// The height of the image if the storage defines `config.readImageSize`
|
|
1717
|
-
height: number
|
|
1666
|
+
height: number
|
|
1718
1667
|
}
|
|
1719
1668
|
|
|
1720
1669
|
export class AssetModel extends TimeStampedModel {
|
|
@@ -1724,34 +1673,36 @@ export class AssetModel extends TimeStampedModel {
|
|
|
1724
1673
|
count: number
|
|
1725
1674
|
}
|
|
1726
1675
|
|
|
1727
|
-
export const AssetMixin: <T extends Constructor>(
|
|
1728
|
-
|
|
1729
|
-
|
|
1730
|
-
|
|
1731
|
-
|
|
1732
|
-
|
|
1733
|
-
|
|
1734
|
-
|
|
1735
|
-
|
|
1736
|
-
|
|
1737
|
-
updatedAt: Date;
|
|
1738
|
-
};
|
|
1676
|
+
export const AssetMixin: <T extends Constructor>(
|
|
1677
|
+
target: T
|
|
1678
|
+
) => Constructor<
|
|
1679
|
+
InstanceType<T> & {
|
|
1680
|
+
key: string
|
|
1681
|
+
file: AssetFileObject
|
|
1682
|
+
storage: string
|
|
1683
|
+
count: number
|
|
1684
|
+
}
|
|
1685
|
+
>
|
|
1739
1686
|
|
|
1740
1687
|
export class TimeStampedModel extends Model {
|
|
1741
1688
|
createdAt: Date
|
|
1742
1689
|
updatedAt: Date
|
|
1743
1690
|
}
|
|
1744
1691
|
|
|
1745
|
-
export const TimeStampedMixin: <T extends Constructor>(
|
|
1746
|
-
|
|
1692
|
+
export const TimeStampedMixin: <T extends Constructor>(
|
|
1693
|
+
target: T
|
|
1694
|
+
) => Constructor<InstanceType<T> & {
|
|
1695
|
+
createdAt: Date
|
|
1696
|
+
updatedAt: Date
|
|
1697
|
+
}>
|
|
1747
1698
|
|
|
1748
1699
|
export class UserModel extends Model {
|
|
1749
1700
|
static options?: {
|
|
1750
1701
|
usernameProperty?: string
|
|
1751
1702
|
passwordProperty?: string
|
|
1752
1703
|
/**
|
|
1753
|
-
* This option can be used to specify (eager) scopes to be applied when
|
|
1754
|
-
*
|
|
1704
|
+
* This option can be used to specify (eager) scopes to be applied when the
|
|
1705
|
+
* user is deserialized from the session.
|
|
1755
1706
|
*/
|
|
1756
1707
|
sessionScope?: OrArrayOf<string>
|
|
1757
1708
|
}
|
|
@@ -1777,60 +1728,66 @@ export class UserModel extends Model {
|
|
|
1777
1728
|
|
|
1778
1729
|
export class SessionModel extends Model {
|
|
1779
1730
|
id: string
|
|
1780
|
-
value: {[key: string]: any }
|
|
1731
|
+
value: { [key: string]: any }
|
|
1781
1732
|
}
|
|
1782
1733
|
|
|
1783
|
-
export const SessionMixin: <T extends Constructor>(
|
|
1784
|
-
|
|
1785
|
-
|
|
1786
|
-
|
|
1787
|
-
|
|
1788
|
-
|
|
1789
|
-
|
|
1790
|
-
|
|
1734
|
+
export const SessionMixin: <T extends Constructor>(
|
|
1735
|
+
target: T
|
|
1736
|
+
) => Constructor<InstanceType<T> & {
|
|
1737
|
+
id: string
|
|
1738
|
+
value: { [key: string]: any }
|
|
1739
|
+
}>
|
|
1740
|
+
|
|
1741
|
+
export const UserMixin: <T extends Constructor>(
|
|
1742
|
+
target: T
|
|
1743
|
+
) => Constructor<
|
|
1744
|
+
InstanceType<T> & {
|
|
1745
|
+
id: string
|
|
1746
|
+
value: { [key: string]: any }
|
|
1747
|
+
}
|
|
1748
|
+
>
|
|
1791
1749
|
|
|
1792
1750
|
/**
|
|
1793
|
-
* Apply the action mixin to a controller action, in order to
|
|
1794
|
-
*
|
|
1795
|
-
*
|
|
1796
|
-
*
|
|
1797
|
-
*
|
|
1798
|
-
*
|
|
1751
|
+
* Apply the action mixin to a controller action, in order to determine which
|
|
1752
|
+
* HTTP method (`'get'`, `'post'`, `'put'`, `'delete'` or `'patch'`) the action
|
|
1753
|
+
* should listen to and optionally the path to which it is mapped, defined in
|
|
1754
|
+
* relation to the route path of its controller. By default, the normalized
|
|
1755
|
+
* method name is used as the action's path, and the `'get'` method is assigned
|
|
1756
|
+
* if none is provided.
|
|
1799
1757
|
*/
|
|
1800
1758
|
export const action: (method: string, path: string) => Mixin
|
|
1801
1759
|
|
|
1802
1760
|
/**
|
|
1803
|
-
* Apply the authorize mixin to a controller action, in order to
|
|
1804
|
-
*
|
|
1805
|
-
*
|
|
1806
|
-
*
|
|
1761
|
+
* Apply the authorize mixin to a controller action, in order to determines
|
|
1762
|
+
* whether or how the request is authorized. This value can either be one of the
|
|
1763
|
+
* values as described below, an array of them or a function which returns one
|
|
1764
|
+
* or more of them.
|
|
1807
1765
|
*
|
|
1808
|
-
* -
|
|
1809
|
-
* - '$self': The requested member is checked against `ctx.state.user`
|
|
1810
|
-
*
|
|
1811
|
-
* - '$owner': The member is asked if it is owned by `ctx.state.user`
|
|
1812
|
-
*
|
|
1813
|
-
* -
|
|
1814
|
-
*
|
|
1766
|
+
* - Boolean: `true` if the action should be authorized, `false` otherwise.
|
|
1767
|
+
* - '$self': The requested member is checked against `ctx.state.user` and the
|
|
1768
|
+
* action is only authorized if it matches the member.
|
|
1769
|
+
* - '$owner': The member is asked if it is owned by `ctx.state.user` through
|
|
1770
|
+
* the optional `Model.$hasOwner()` method.
|
|
1771
|
+
* - Any string: `ctx.state.user` is checked for this role through the
|
|
1772
|
+
* overridable `UserModel.hasRole()` method.
|
|
1815
1773
|
*/
|
|
1816
1774
|
export const authorize: (
|
|
1817
1775
|
authorize: (ctx: KoaContext) => void | boolean | OrArrayOf<string>
|
|
1818
1776
|
) => Mixin
|
|
1819
1777
|
|
|
1820
1778
|
/**
|
|
1821
|
-
* Apply the parameters mixin to a controller action, in order to
|
|
1822
|
-
*
|
|
1823
|
-
*
|
|
1779
|
+
* Apply the parameters mixin to a controller action, in order to apply
|
|
1780
|
+
* automatic mapping of Koa.js' `ctx.query` object to method parameters along
|
|
1781
|
+
* with their automatic validation.
|
|
1824
1782
|
*
|
|
1825
1783
|
* @see {@link https://github.com/ditojs/dito/blob/master/docs/model-properties.md Model Properties}
|
|
1826
1784
|
*/
|
|
1827
1785
|
export const parameters: (params: { [key: string]: Schema }) => Mixin
|
|
1828
1786
|
|
|
1829
1787
|
/**
|
|
1830
|
-
* Apply the returns mixin to a controller action, in order to
|
|
1831
|
-
*
|
|
1832
|
-
*
|
|
1833
|
-
* contains a `name` property.
|
|
1788
|
+
* Apply the returns mixin to a controller action, in order to provide a schema
|
|
1789
|
+
* for the value returned from the action handler and optionally map the value
|
|
1790
|
+
* to a key inside a returned object when it contains a `name` property.
|
|
1834
1791
|
*/
|
|
1835
1792
|
export const returns: (
|
|
1836
1793
|
returns: Schema & { name?: string },
|
|
@@ -1838,18 +1795,17 @@ export const returns: (
|
|
|
1838
1795
|
) => Mixin
|
|
1839
1796
|
|
|
1840
1797
|
/**
|
|
1841
|
-
* Apply the scope mixin to a controller action, in order to
|
|
1842
|
-
*
|
|
1843
|
-
*
|
|
1844
|
-
* definitions.
|
|
1798
|
+
* Apply the scope mixin to a controller action, in order to determine the
|
|
1799
|
+
* scope(s) to be applied when loading the relation's models. The scope needs to
|
|
1800
|
+
* be defined in the related model class' scopes definitions.
|
|
1845
1801
|
*/
|
|
1846
1802
|
export const scope: (...scopes: string[]) => Mixin
|
|
1847
1803
|
|
|
1848
1804
|
/**
|
|
1849
|
-
* Apply the transacted mixin to a controller action in order to
|
|
1850
|
-
*
|
|
1851
|
-
*
|
|
1852
|
-
*
|
|
1805
|
+
* Apply the transacted mixin to a controller action in order to determine
|
|
1806
|
+
* whether queries in the action should be executed within a transaction. Any
|
|
1807
|
+
* failure will mean the database will rollback any queries executed to the
|
|
1808
|
+
* pre-transaction state.
|
|
1853
1809
|
*/
|
|
1854
1810
|
export const transacted: () => Mixin
|
|
1855
1811
|
|
|
@@ -1880,7 +1836,7 @@ export interface KnexHelper {
|
|
|
1880
1836
|
export type Keyword =
|
|
1881
1837
|
| SetOptional<Ajv.MacroKeywordDefinition, 'keyword'>
|
|
1882
1838
|
| SetOptional<Ajv.CodeKeywordDefinition, 'keyword'>
|
|
1883
|
-
| SetOptional<Ajv.FuncKeywordDefinition, 'keyword'
|
|
1839
|
+
| SetOptional<Ajv.FuncKeywordDefinition, 'keyword'>
|
|
1884
1840
|
export type Format = Ajv.ValidateFunction | Ajv.FormatDefinition<string>
|
|
1885
1841
|
export type Id = string | number
|
|
1886
1842
|
export type KoaContext<$State = any> = Koa.ParameterizedContext<
|
|
@@ -1891,7 +1847,7 @@ export type KoaContext<$State = any> = Koa.ParameterizedContext<
|
|
|
1891
1847
|
}
|
|
1892
1848
|
>
|
|
1893
1849
|
|
|
1894
|
-
type LiteralUnion<T extends U, U = string> = T | (U & Record<never, never>)
|
|
1850
|
+
type LiteralUnion<T extends U, U = string> = T | (U & Record<never, never>)
|
|
1895
1851
|
|
|
1896
1852
|
type ReflectArrayType<Source, Target> = Source extends any[] ? Target[] : Target
|
|
1897
1853
|
|
|
@@ -1901,7 +1857,7 @@ type OrReadOnly<T> = Readonly<T> | T
|
|
|
1901
1857
|
|
|
1902
1858
|
type OrPromiseOf<T> = Promise<T> | T
|
|
1903
1859
|
|
|
1904
|
-
type
|
|
1860
|
+
type ModelFromModelController<$ModelController extends ModelController> =
|
|
1905
1861
|
InstanceType<Exclude<$ModelController['modelClass'], undefined>>
|
|
1906
1862
|
|
|
1907
1863
|
export type SelectModelProperties<T> = {
|
|
@@ -1911,8 +1867,11 @@ export type SelectModelProperties<T> = {
|
|
|
1911
1867
|
}
|
|
1912
1868
|
|
|
1913
1869
|
// https://stackoverflow.com/questions/49927523/disallow-call-with-any/49928360#49928360
|
|
1914
|
-
type AnyGate
|
|
1915
|
-
|
|
1870
|
+
type AnyGate<
|
|
1871
|
+
$CheckType,
|
|
1872
|
+
$TypeWhenNotAny,
|
|
1873
|
+
$TypeWhenAny = $CheckType
|
|
1874
|
+
> = 0 extends 1 & $CheckType ? $TypeWhenAny : $TypeWhenNotAny
|
|
1916
1875
|
|
|
1917
1876
|
export type SelectModelKeys<T> = AnyGate<
|
|
1918
1877
|
T,
|
|
@@ -1923,7 +1882,7 @@ export type SelectModelKeys<T> = AnyGate<
|
|
|
1923
1882
|
string
|
|
1924
1883
|
>
|
|
1925
1884
|
|
|
1926
|
-
/*
|
|
1885
|
+
/* ---------------------- Extended from Ajv JSON Schema --------------------- */
|
|
1927
1886
|
|
|
1928
1887
|
export type Schema<T = any> = JSONSchemaType<T> & {
|
|
1929
1888
|
// keywords/_validate.js
|
|
@@ -1954,8 +1913,8 @@ export type Schema<T = any> = JSONSchemaType<T> & {
|
|
|
1954
1913
|
|
|
1955
1914
|
// keywords/_instanceof.js
|
|
1956
1915
|
/**
|
|
1957
|
-
* Validates whether the value is an instance of at least one of the
|
|
1958
|
-
*
|
|
1916
|
+
* Validates whether the value is an instance of at least one of the passed
|
|
1917
|
+
* types.
|
|
1959
1918
|
*/
|
|
1960
1919
|
instanceof?: OrArrayOf<
|
|
1961
1920
|
| LiteralUnion<
|
|
@@ -1982,144 +1941,241 @@ export type Schema<T = any> = JSONSchemaType<T> & {
|
|
|
1982
1941
|
>
|
|
1983
1942
|
}
|
|
1984
1943
|
|
|
1985
|
-
declare type StrictNullChecksWrapper<
|
|
1986
|
-
|
|
1987
|
-
|
|
1988
|
-
|
|
1989
|
-
|
|
1990
|
-
|
|
1944
|
+
declare type StrictNullChecksWrapper<
|
|
1945
|
+
Name extends string,
|
|
1946
|
+
Type
|
|
1947
|
+
> = undefined extends null
|
|
1948
|
+
? `strictNullChecks must be true in tsconfig to use ${Name}`
|
|
1949
|
+
: Type
|
|
1950
|
+
declare type UnionToIntersection<U> = (
|
|
1951
|
+
U extends any ? (_: U) => void : never
|
|
1952
|
+
) extends (_: infer I) => void
|
|
1953
|
+
? I
|
|
1954
|
+
: never
|
|
1955
|
+
declare type SomeJSONSchema = UncheckedJSONSchemaType<Known, true>
|
|
1956
|
+
declare type UncheckedPartialSchema<T> = Partial<
|
|
1957
|
+
UncheckedJSONSchemaType<T, true>
|
|
1958
|
+
>
|
|
1959
|
+
declare type PartialSchema<T> = StrictNullChecksWrapper<
|
|
1960
|
+
'PartialSchema',
|
|
1961
|
+
UncheckedPartialSchema<T>
|
|
1962
|
+
>
|
|
1963
|
+
declare type JSONType<
|
|
1964
|
+
T extends string,
|
|
1965
|
+
IsPartial extends boolean
|
|
1966
|
+
> = IsPartial extends true ? T | undefined : T
|
|
1991
1967
|
interface NumberKeywords {
|
|
1992
|
-
|
|
1993
|
-
|
|
1994
|
-
|
|
1995
|
-
|
|
1996
|
-
|
|
1997
|
-
|
|
1998
|
-
|
|
1999
|
-
|
|
1968
|
+
minimum?: number
|
|
1969
|
+
maximum?: number
|
|
1970
|
+
exclusiveMinimum?: number
|
|
1971
|
+
exclusiveMaximum?: number
|
|
1972
|
+
multipleOf?: number
|
|
1973
|
+
format?: string
|
|
1974
|
+
range?: [number, number]
|
|
1975
|
+
}
|
|
2000
1976
|
interface StringKeywords {
|
|
2001
|
-
|
|
2002
|
-
|
|
2003
|
-
|
|
2004
|
-
|
|
2005
|
-
|
|
2006
|
-
|
|
2007
|
-
|
|
2008
|
-
|
|
2009
|
-
|
|
2010
|
-
|
|
2011
|
-
|
|
2012
|
-
|
|
2013
|
-
|
|
2014
|
-
|
|
2015
|
-
|
|
2016
|
-
|
|
2017
|
-
|
|
2018
|
-
|
|
2019
|
-
|
|
1977
|
+
minLength?: number
|
|
1978
|
+
maxLength?: number
|
|
1979
|
+
pattern?: string
|
|
1980
|
+
format?: LiteralUnion<
|
|
1981
|
+
| 'date'
|
|
1982
|
+
| 'time'
|
|
1983
|
+
| 'uri'
|
|
1984
|
+
| 'uri-reference'
|
|
1985
|
+
| 'uri-template'
|
|
1986
|
+
| 'email'
|
|
1987
|
+
| 'hostname'
|
|
1988
|
+
| 'ipv4'
|
|
1989
|
+
| 'ipv6'
|
|
1990
|
+
| 'uuid'
|
|
1991
|
+
| 'json-pointer'
|
|
1992
|
+
| 'relative-json-pointer'
|
|
1993
|
+
| 'datetime'
|
|
1994
|
+
| 'timestamp'
|
|
1995
|
+
>
|
|
2020
1996
|
}
|
|
2021
|
-
declare type UncheckedJSONSchemaType<
|
|
2022
|
-
|
|
2023
|
-
|
|
2024
|
-
|
|
2025
|
-
|
|
2026
|
-
|
|
2027
|
-
|
|
2028
|
-
|
|
2029
|
-
|
|
2030
|
-
}
|
|
2031
|
-
|
|
2032
|
-
|
|
2033
|
-
|
|
2034
|
-
|
|
2035
|
-
|
|
2036
|
-
|
|
2037
|
-
|
|
2038
|
-
|
|
2039
|
-
|
|
2040
|
-
|
|
2041
|
-
|
|
2042
|
-
|
|
2043
|
-
|
|
2044
|
-
|
|
2045
|
-
|
|
2046
|
-
|
|
2047
|
-
|
|
2048
|
-
|
|
2049
|
-
|
|
2050
|
-
|
|
2051
|
-
|
|
2052
|
-
|
|
2053
|
-
|
|
2054
|
-
|
|
2055
|
-
|
|
2056
|
-
|
|
2057
|
-
|
|
2058
|
-
}
|
|
2059
|
-
|
|
2060
|
-
|
|
2061
|
-
|
|
2062
|
-
|
|
2063
|
-
|
|
2064
|
-
|
|
2065
|
-
|
|
2066
|
-
|
|
2067
|
-
|
|
2068
|
-
|
|
2069
|
-
|
|
2070
|
-
|
|
2071
|
-
|
|
2072
|
-
|
|
2073
|
-
|
|
2074
|
-
|
|
2075
|
-
|
|
2076
|
-
|
|
2077
|
-
|
|
2078
|
-
|
|
2079
|
-
|
|
2080
|
-
}
|
|
2081
|
-
|
|
2082
|
-
|
|
2083
|
-
|
|
2084
|
-
|
|
2085
|
-
|
|
2086
|
-
|
|
2087
|
-
|
|
2088
|
-
|
|
2089
|
-
|
|
2090
|
-
|
|
2091
|
-
|
|
2092
|
-
|
|
2093
|
-
|
|
2094
|
-
|
|
2095
|
-
|
|
2096
|
-
|
|
2097
|
-
|
|
2098
|
-
|
|
2099
|
-
|
|
2100
|
-
|
|
2101
|
-
|
|
2102
|
-
|
|
2103
|
-
|
|
2104
|
-
|
|
2105
|
-
|
|
1997
|
+
declare type UncheckedJSONSchemaType<
|
|
1998
|
+
T,
|
|
1999
|
+
IsPartial extends boolean
|
|
2000
|
+
> = // these two unions allow arbitrary unions of types
|
|
2001
|
+
(| {
|
|
2002
|
+
anyOf: readonly UncheckedJSONSchemaType<T, IsPartial>[]
|
|
2003
|
+
}
|
|
2004
|
+
| {
|
|
2005
|
+
oneOf: readonly UncheckedJSONSchemaType<T, IsPartial>[]
|
|
2006
|
+
}
|
|
2007
|
+
| ({
|
|
2008
|
+
type: readonly (T extends number
|
|
2009
|
+
? JSONType<'number' | 'integer', IsPartial>
|
|
2010
|
+
: T extends string
|
|
2011
|
+
? JSONType<'string', IsPartial>
|
|
2012
|
+
: T extends boolean
|
|
2013
|
+
? JSONType<'boolean', IsPartial>
|
|
2014
|
+
: never)[]
|
|
2015
|
+
} & UnionToIntersection<
|
|
2016
|
+
T extends number
|
|
2017
|
+
? NumberKeywords
|
|
2018
|
+
: T extends string
|
|
2019
|
+
? StringKeywords
|
|
2020
|
+
: T extends boolean
|
|
2021
|
+
? {}
|
|
2022
|
+
: never
|
|
2023
|
+
>)
|
|
2024
|
+
| ((T extends number
|
|
2025
|
+
? {
|
|
2026
|
+
type: JSONType<'number' | 'integer', IsPartial>
|
|
2027
|
+
} & NumberKeywords
|
|
2028
|
+
: T extends string
|
|
2029
|
+
? {
|
|
2030
|
+
type: JSONType<
|
|
2031
|
+
'string' | 'text' | 'date' | 'datetime' | 'timestamp',
|
|
2032
|
+
IsPartial
|
|
2033
|
+
>
|
|
2034
|
+
} & StringKeywords
|
|
2035
|
+
: T extends Date
|
|
2036
|
+
? {
|
|
2037
|
+
type: JSONType<'date' | 'datetime' | 'timestamp', IsPartial>
|
|
2038
|
+
}
|
|
2039
|
+
: T extends boolean
|
|
2040
|
+
? {
|
|
2041
|
+
type: JSONType<'boolean', IsPartial>
|
|
2042
|
+
}
|
|
2043
|
+
: T extends readonly [any, ...any[]]
|
|
2044
|
+
? {
|
|
2045
|
+
type: JSONType<'array', IsPartial>
|
|
2046
|
+
items: {
|
|
2047
|
+
readonly [K in keyof T]-?: UncheckedJSONSchemaType<T[K], false> &
|
|
2048
|
+
Nullable<T[K]>
|
|
2049
|
+
} & {
|
|
2050
|
+
length: T['length']
|
|
2051
|
+
}
|
|
2052
|
+
minItems: T['length']
|
|
2053
|
+
} & (
|
|
2054
|
+
| {
|
|
2055
|
+
maxItems: T['length']
|
|
2056
|
+
}
|
|
2057
|
+
| {
|
|
2058
|
+
additionalItems: false
|
|
2059
|
+
}
|
|
2060
|
+
)
|
|
2061
|
+
: T extends readonly any[]
|
|
2062
|
+
? {
|
|
2063
|
+
type: JSONType<'array', IsPartial>
|
|
2064
|
+
items: UncheckedJSONSchemaType<T[0], false>
|
|
2065
|
+
contains?: UncheckedPartialSchema<T[0]>
|
|
2066
|
+
minItems?: number
|
|
2067
|
+
maxItems?: number
|
|
2068
|
+
minContains?: number
|
|
2069
|
+
maxContains?: number
|
|
2070
|
+
uniqueItems?: true
|
|
2071
|
+
additionalItems?: never
|
|
2072
|
+
}
|
|
2073
|
+
: T extends Record<string, any>
|
|
2074
|
+
? {
|
|
2075
|
+
type: JSONType<'object', IsPartial>
|
|
2076
|
+
additionalProperties?:
|
|
2077
|
+
| boolean
|
|
2078
|
+
| UncheckedJSONSchemaType<T[string], false>
|
|
2079
|
+
unevaluatedProperties?:
|
|
2080
|
+
| boolean
|
|
2081
|
+
| UncheckedJSONSchemaType<T[string], false>
|
|
2082
|
+
properties?: IsPartial extends true
|
|
2083
|
+
? Partial<UncheckedPropertiesSchema<T>>
|
|
2084
|
+
: UncheckedPropertiesSchema<T>
|
|
2085
|
+
patternProperties?: Record<
|
|
2086
|
+
string,
|
|
2087
|
+
UncheckedJSONSchemaType<T[string], false>
|
|
2088
|
+
>
|
|
2089
|
+
propertyNames?: Omit<
|
|
2090
|
+
UncheckedJSONSchemaType<string, false>,
|
|
2091
|
+
'type'
|
|
2092
|
+
> & {
|
|
2093
|
+
type?: 'string'
|
|
2094
|
+
}
|
|
2095
|
+
dependencies?: {
|
|
2096
|
+
[K in keyof T]?: Readonly<(keyof T)[]> | UncheckedPartialSchema<T>
|
|
2097
|
+
}
|
|
2098
|
+
dependentRequired?: {
|
|
2099
|
+
[K in keyof T]?: Readonly<(keyof T)[]>
|
|
2100
|
+
}
|
|
2101
|
+
dependentSchemas?: {
|
|
2102
|
+
[K in keyof T]?: UncheckedPartialSchema<T>
|
|
2103
|
+
}
|
|
2104
|
+
minProperties?: number
|
|
2105
|
+
maxProperties?: number
|
|
2106
|
+
} & (IsPartial extends true
|
|
2107
|
+
? {
|
|
2108
|
+
required: Readonly<(keyof T)[] | boolean>
|
|
2109
|
+
}
|
|
2110
|
+
: [UncheckedRequiredMembers<T>] extends [never]
|
|
2111
|
+
? {
|
|
2112
|
+
required?: Readonly<UncheckedRequiredMembers<T>[]> | boolean
|
|
2113
|
+
}
|
|
2114
|
+
: {
|
|
2115
|
+
required: Readonly<UncheckedRequiredMembers<T>[]> | boolean
|
|
2116
|
+
})
|
|
2117
|
+
: T extends null
|
|
2118
|
+
? {
|
|
2119
|
+
type: JSONType<'null', IsPartial>
|
|
2120
|
+
nullable: true
|
|
2121
|
+
}
|
|
2122
|
+
: never) & {
|
|
2123
|
+
allOf?: Readonly<UncheckedPartialSchema<T>[]>
|
|
2124
|
+
anyOf?: Readonly<UncheckedPartialSchema<T>[]>
|
|
2125
|
+
oneOf?: Readonly<UncheckedPartialSchema<T>[]>
|
|
2126
|
+
if?: UncheckedPartialSchema<T>
|
|
2127
|
+
then?: UncheckedPartialSchema<T>
|
|
2128
|
+
else?: UncheckedPartialSchema<T>
|
|
2129
|
+
not?: UncheckedPartialSchema<T>
|
|
2130
|
+
})
|
|
2131
|
+
) & {
|
|
2132
|
+
[keyword: string]: any
|
|
2133
|
+
$id?: string
|
|
2134
|
+
$ref?: string
|
|
2135
|
+
$defs?: Record<string, UncheckedJSONSchemaType<Known, true>>
|
|
2136
|
+
definitions?: Record<string, UncheckedJSONSchemaType<Known, true>>
|
|
2137
|
+
}
|
|
2138
|
+
declare type JSONSchemaType<T> = StrictNullChecksWrapper<
|
|
2139
|
+
'JSONSchemaType',
|
|
2140
|
+
UncheckedJSONSchemaType<T, false>
|
|
2141
|
+
>
|
|
2142
|
+
declare type Known =
|
|
2143
|
+
| {
|
|
2144
|
+
[key: string]: Known
|
|
2145
|
+
}
|
|
2146
|
+
| [Known, ...Known[]]
|
|
2147
|
+
| Known[]
|
|
2148
|
+
| number
|
|
2149
|
+
| string
|
|
2150
|
+
| boolean
|
|
2151
|
+
| null
|
|
2106
2152
|
declare type UncheckedPropertiesSchema<T> = {
|
|
2107
|
-
|
|
2108
|
-
|
|
2109
|
-
|
|
2110
|
-
|
|
2111
|
-
|
|
2153
|
+
[K in keyof T]-?:
|
|
2154
|
+
| (UncheckedJSONSchemaType<T[K], false> & Nullable<T[K]>)
|
|
2155
|
+
| {
|
|
2156
|
+
$ref: string
|
|
2157
|
+
}
|
|
2158
|
+
}
|
|
2159
|
+
declare type PropertiesSchema<T> = StrictNullChecksWrapper<
|
|
2160
|
+
'PropertiesSchema',
|
|
2161
|
+
UncheckedPropertiesSchema<T>
|
|
2162
|
+
>
|
|
2112
2163
|
declare type UncheckedRequiredMembers<T> = {
|
|
2113
|
-
|
|
2114
|
-
}[keyof T]
|
|
2115
|
-
declare type RequiredMembers<T> = StrictNullChecksWrapper<
|
|
2116
|
-
|
|
2117
|
-
|
|
2118
|
-
|
|
2119
|
-
|
|
2120
|
-
|
|
2121
|
-
|
|
2122
|
-
|
|
2123
|
-
|
|
2124
|
-
|
|
2125
|
-
}
|
|
2164
|
+
[K in keyof T]-?: undefined extends T[K] ? never : K
|
|
2165
|
+
}[keyof T]
|
|
2166
|
+
declare type RequiredMembers<T> = StrictNullChecksWrapper<
|
|
2167
|
+
'RequiredMembers',
|
|
2168
|
+
UncheckedRequiredMembers<T>
|
|
2169
|
+
>
|
|
2170
|
+
declare type Nullable<T> = undefined extends T
|
|
2171
|
+
? {
|
|
2172
|
+
nullable: true
|
|
2173
|
+
const?: null
|
|
2174
|
+
enum?: Readonly<(T | null)[]>
|
|
2175
|
+
default?: T | null
|
|
2176
|
+
}
|
|
2177
|
+
: {
|
|
2178
|
+
const?: T
|
|
2179
|
+
enum?: Readonly<T[]>
|
|
2180
|
+
default?: T
|
|
2181
|
+
}
|