-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathapp-bootstrap.ts
More file actions
72 lines (63 loc) · 2.07 KB
/
Copy pathapp-bootstrap.ts
File metadata and controls
72 lines (63 loc) · 2.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/**
* Installs process-wide compatibility helpers used by the legacy service layer.
*
* This module is loaded before controllers and services so their Joi schemas and
* BigInt values retain the behavior exposed by the original JavaScript runtime.
*/
global.Promise = require('bluebird')
const config = require('config')
const Joi = require('joi')
/**
* Creates the optional UUID schema used for resource and relationship identifiers.
*
* @returns A Joi string schema that accepts UUID values and rejects invalid GUIDs.
* @throws Does not throw while constructing the schema.
*/
function optionalIdSchema () {
return Joi.string().uuid()
}
/**
* Creates the required UUID schema used for mandatory identifiers.
*
* @returns A required Joi UUID schema.
* @throws Does not throw while constructing the schema.
*/
function requiredIdSchema () {
return Joi.optionalId().required()
}
/**
* Creates the page-number schema used by paginated endpoints.
*
* Query-string numbers are converted by Joi, values must be positive integers,
* and omitted values default to the first page.
*
* @returns A Joi number schema for a one-based page number.
* @throws Does not throw while constructing the schema.
*/
function pageSchema () {
return Joi.number().integer().min(1).default(1)
}
/**
* Creates the page-size schema used by paginated endpoints.
*
* @returns A Joi number schema bounded from 1 through 10,000 and defaulted from
* the existing DEFAULT_PAGE_SIZE configuration value.
* @throws Does not throw while constructing the schema.
*/
function perPageSchema () {
return Joi.number().integer().min(1).max(10000).default(config.DEFAULT_PAGE_SIZE)
}
/**
* Serializes a BigInt as its decimal string representation for JSON responses.
*
* @returns The BigInt value represented as a base-10 string.
* @throws Does not throw for a BigInt receiver.
*/
function bigIntToJSON (this: bigint): string {
return this.toString()
}
Joi.optionalId = optionalIdSchema
Joi.id = requiredIdSchema
Joi.page = pageSchema
Joi.perPage = perPageSchema
;(BigInt.prototype as any).toJSON = bigIntToJSON