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