@adonisjs/env 3.0.8 → 4.0.0-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/build/index.d.ts +3 -3
- package/build/index.js +3 -17
- package/build/src/env.d.ts +21 -0
- package/build/src/env.js +27 -0
- package/build/src/exceptions/missing_env_path_file.d.ts +5 -0
- package/build/src/exceptions/missing_env_path_file.js +5 -0
- package/build/src/loader.d.ts +9 -7
- package/build/src/loader.js +28 -43
- package/build/src/parser.d.ts +6 -0
- package/build/src/parser.js +60 -0
- package/build/src/validator.d.ts +12 -0
- package/build/src/validator.js +12 -0
- package/package.json +116 -140
- package/build/adonis-typings/env.d.ts +0 -127
- package/build/adonis-typings/env.js +0 -8
- package/build/src/Env/index.d.ts +0 -59
- package/build/src/Env/index.js +0 -140
- package/build/src/Parser/index.d.ts +0 -54
- package/build/src/Parser/index.js +0 -172
- package/build/src/Schema/boolean.d.ts +0 -10
- package/build/src/Schema/boolean.js +0 -49
- package/build/src/Schema/helpers.d.ts +0 -12
- package/build/src/Schema/helpers.js +0 -29
- package/build/src/Schema/index.d.ts +0 -2
- package/build/src/Schema/index.js +0 -21
- package/build/src/Schema/number.d.ts +0 -13
- package/build/src/Schema/number.js +0 -48
- package/build/src/Schema/oneOf.d.ts +0 -8
- package/build/src/Schema/oneOf.js +0 -69
- package/build/src/Schema/string.d.ts +0 -8
- package/build/src/Schema/string.js +0 -66
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { SchemaFnOptions } from '@ioc:Adonis/Core/Env';
|
|
2
|
-
/**
|
|
3
|
-
* Casts the string to a number and ensures it is no NaN
|
|
4
|
-
*/
|
|
5
|
-
export declare function castToNumber(key: string, value: string, message?: string): number;
|
|
6
|
-
/**
|
|
7
|
-
* Enforces the value to be of valid number type and the
|
|
8
|
-
* value will also be casted to a number
|
|
9
|
-
*/
|
|
10
|
-
export declare function number(options?: SchemaFnOptions): (key: string, value?: string | undefined) => number;
|
|
11
|
-
export declare namespace number {
|
|
12
|
-
var optional: (options?: SchemaFnOptions | undefined) => (key: string, value?: string | undefined) => number | undefined;
|
|
13
|
-
}
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/*
|
|
3
|
-
* @adonisjs/env
|
|
4
|
-
*
|
|
5
|
-
* (c) Harminder Virk <virk@adonisjs.com>
|
|
6
|
-
*
|
|
7
|
-
* For the full copyright and license information, please view the LICENSE
|
|
8
|
-
* file that was distributed with this source code.
|
|
9
|
-
*/
|
|
10
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
|
-
exports.number = exports.castToNumber = void 0;
|
|
12
|
-
const utils_1 = require("@poppinss/utils");
|
|
13
|
-
const helpers_1 = require("./helpers");
|
|
14
|
-
/**
|
|
15
|
-
* Casts the string to a number and ensures it is no NaN
|
|
16
|
-
*/
|
|
17
|
-
function castToNumber(key, value, message) {
|
|
18
|
-
const castedValue = Number(value);
|
|
19
|
-
if (isNaN(castedValue)) {
|
|
20
|
-
throw new utils_1.Exception(message ||
|
|
21
|
-
`Value for environment variable "${key}" must be numeric, instead received "${value}"`, 500, 'E_INVALID_ENV_VALUE');
|
|
22
|
-
}
|
|
23
|
-
return castedValue;
|
|
24
|
-
}
|
|
25
|
-
exports.castToNumber = castToNumber;
|
|
26
|
-
/**
|
|
27
|
-
* Enforces the value to be of valid number type and the
|
|
28
|
-
* value will also be casted to a number
|
|
29
|
-
*/
|
|
30
|
-
function number(options) {
|
|
31
|
-
return function validate(key, value) {
|
|
32
|
-
(0, helpers_1.ensureValue)(key, value, options?.message);
|
|
33
|
-
return castToNumber(key, value, options?.message);
|
|
34
|
-
};
|
|
35
|
-
}
|
|
36
|
-
exports.number = number;
|
|
37
|
-
/**
|
|
38
|
-
* Similar to the number rule, but also allows optional
|
|
39
|
-
* values
|
|
40
|
-
*/
|
|
41
|
-
number.optional = function optionalNumber(options) {
|
|
42
|
-
return function validate(key, value) {
|
|
43
|
-
if (!value) {
|
|
44
|
-
return undefined;
|
|
45
|
-
}
|
|
46
|
-
return castToNumber(key, value, options?.message);
|
|
47
|
-
};
|
|
48
|
-
};
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { SchemaFnOptions } from '@ioc:Adonis/Core/Env';
|
|
2
|
-
/**
|
|
3
|
-
* Enforces value to be one of the defined choices
|
|
4
|
-
*/
|
|
5
|
-
export declare function oneOf(choices: any[], options?: SchemaFnOptions): (key: string, value?: string | undefined) => any;
|
|
6
|
-
export declare namespace oneOf {
|
|
7
|
-
var optional: (choices: any[], options?: SchemaFnOptions | undefined) => (key: string, value?: string | undefined) => any;
|
|
8
|
-
}
|
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/*
|
|
3
|
-
* @adonisjs/env
|
|
4
|
-
*
|
|
5
|
-
* (c) Harminder Virk <virk@adonisjs.com>
|
|
6
|
-
*
|
|
7
|
-
* For the full copyright and license information, please view the LICENSE
|
|
8
|
-
* file that was distributed with this source code.
|
|
9
|
-
*/
|
|
10
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
|
-
exports.oneOf = void 0;
|
|
12
|
-
const utils_1 = require("@poppinss/utils");
|
|
13
|
-
const helpers_1 = require("./helpers");
|
|
14
|
-
/**
|
|
15
|
-
* Validates the number to be present in the user defined choices.
|
|
16
|
-
*
|
|
17
|
-
* The incoming value will be casted as follows:
|
|
18
|
-
*
|
|
19
|
-
* - "0", 0, "false", false will be casted to false
|
|
20
|
-
* - "1", 1, "true", true will be casted to true
|
|
21
|
-
* - string representation of a number will be casted to a number
|
|
22
|
-
*/
|
|
23
|
-
function ensureOneOf(choices, key, value, message) {
|
|
24
|
-
if (helpers_1.BOOLEAN_NEGATIVES.includes(value)) {
|
|
25
|
-
value = false;
|
|
26
|
-
}
|
|
27
|
-
else if (helpers_1.BOOLEAN_POSITIVES.includes(value)) {
|
|
28
|
-
value = true;
|
|
29
|
-
}
|
|
30
|
-
else {
|
|
31
|
-
const toNumber = Number(value);
|
|
32
|
-
if (!isNaN(toNumber)) {
|
|
33
|
-
value = toNumber;
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
/**
|
|
37
|
-
* If choices includes the value, then return the casted
|
|
38
|
-
* value
|
|
39
|
-
*/
|
|
40
|
-
if (choices.includes(value)) {
|
|
41
|
-
return value;
|
|
42
|
-
}
|
|
43
|
-
/**
|
|
44
|
-
* Otherwise raise exception
|
|
45
|
-
*/
|
|
46
|
-
throw new utils_1.Exception(message ||
|
|
47
|
-
`Value for environment variable "${key}" must be one of "${choices.join(',')}", instead received "${value}"`, 500, 'E_INVALID_ENV_VALUE');
|
|
48
|
-
}
|
|
49
|
-
/**
|
|
50
|
-
* Enforces value to be one of the defined choices
|
|
51
|
-
*/
|
|
52
|
-
function oneOf(choices, options) {
|
|
53
|
-
return function validate(key, value) {
|
|
54
|
-
(0, helpers_1.ensureValue)(key, value, options?.message);
|
|
55
|
-
return ensureOneOf(choices, key, value, options?.message);
|
|
56
|
-
};
|
|
57
|
-
}
|
|
58
|
-
exports.oneOf = oneOf;
|
|
59
|
-
/**
|
|
60
|
-
* Similar to oneOf, but also allows optional properties
|
|
61
|
-
*/
|
|
62
|
-
oneOf.optional = function optionalBoolean(choices, options) {
|
|
63
|
-
return function validate(key, value) {
|
|
64
|
-
if (!value) {
|
|
65
|
-
return undefined;
|
|
66
|
-
}
|
|
67
|
-
return ensureOneOf(choices, key, value, options?.message);
|
|
68
|
-
};
|
|
69
|
-
};
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { StringFnOptions } from '@ioc:Adonis/Core/Env';
|
|
2
|
-
/**
|
|
3
|
-
* Enforces the value to exist and be of type string
|
|
4
|
-
*/
|
|
5
|
-
export declare function string(options?: StringFnOptions): (key: string, value?: string | undefined) => string;
|
|
6
|
-
export declare namespace string {
|
|
7
|
-
var optional: (options?: StringFnOptions | undefined) => (key: string, value?: string | undefined) => string | undefined;
|
|
8
|
-
}
|
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/*
|
|
3
|
-
* @adonisjs/env
|
|
4
|
-
*
|
|
5
|
-
* (c) Harminder Virk <virk@adonisjs.com>
|
|
6
|
-
*
|
|
7
|
-
* For the full copyright and license information, please view the LICENSE
|
|
8
|
-
* file that was distributed with this source code.
|
|
9
|
-
*/
|
|
10
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
|
-
exports.string = void 0;
|
|
12
|
-
const utils_1 = require("@poppinss/utils");
|
|
13
|
-
const helpers_1 = require("./helpers");
|
|
14
|
-
/**
|
|
15
|
-
* Formats against which a string can be optionally validated. We
|
|
16
|
-
* lazy load the dependencies required for validating formats
|
|
17
|
-
*/
|
|
18
|
-
const formats = {
|
|
19
|
-
email: (key, value, options) => {
|
|
20
|
-
if (!require('validator/lib/isEmail')(value)) {
|
|
21
|
-
throw new utils_1.Exception(options.message ||
|
|
22
|
-
`Value for environment variable "${key}" must be a valid email, instead received "${value}"`, 500, 'E_INVALID_ENV_VALUE');
|
|
23
|
-
}
|
|
24
|
-
},
|
|
25
|
-
host: (key, value, options) => {
|
|
26
|
-
if (!require('validator/lib/isFQDN')(value, { require_tld: false }) &&
|
|
27
|
-
!require('validator/lib/isIP')(value)) {
|
|
28
|
-
throw new utils_1.Exception(options.message ||
|
|
29
|
-
`Value for environment variable "${key}" must be a valid (domain or ip), instead received "${value}"`, 500, 'E_INVALID_ENV_VALUE');
|
|
30
|
-
}
|
|
31
|
-
},
|
|
32
|
-
url: (key, value, options) => {
|
|
33
|
-
const { tld = true, protocol = true } = options;
|
|
34
|
-
if (!require('validator/lib/isURL')(value, { require_tld: tld, require_protocol: protocol })) {
|
|
35
|
-
throw new utils_1.Exception(options.message ||
|
|
36
|
-
`Value for environment variable "${key}" must be a valid URL, instead received "${value}"`, 500, 'E_INVALID_ENV_VALUE');
|
|
37
|
-
}
|
|
38
|
-
},
|
|
39
|
-
};
|
|
40
|
-
/**
|
|
41
|
-
* Enforces the value to exist and be of type string
|
|
42
|
-
*/
|
|
43
|
-
function string(options) {
|
|
44
|
-
return function validate(key, value) {
|
|
45
|
-
(0, helpers_1.ensureValue)(key, value, options?.message);
|
|
46
|
-
if (options?.format) {
|
|
47
|
-
formats[options.format](key, value, options);
|
|
48
|
-
}
|
|
49
|
-
return value;
|
|
50
|
-
};
|
|
51
|
-
}
|
|
52
|
-
exports.string = string;
|
|
53
|
-
/**
|
|
54
|
-
* Same as the string rule, but allows non-existing values too
|
|
55
|
-
*/
|
|
56
|
-
string.optional = function optionalString(options) {
|
|
57
|
-
return function validate(key, value) {
|
|
58
|
-
if (!value) {
|
|
59
|
-
return undefined;
|
|
60
|
-
}
|
|
61
|
-
if (options?.format) {
|
|
62
|
-
formats[options.format](key, value, options);
|
|
63
|
-
}
|
|
64
|
-
return value;
|
|
65
|
-
};
|
|
66
|
-
};
|