@adonisjs/env 3.0.9 → 4.0.0-1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,142 +1,118 @@
1
1
  {
2
- "name": "@adonisjs/env",
3
- "version": "3.0.9",
4
- "description": "Environment variable manager for Node.js",
5
- "main": "build/index.js",
6
- "files": [
7
- "build/adonis-typings",
8
- "build/src",
9
- "build/index.d.ts",
10
- "build/index.js"
11
- ],
12
- "scripts": {
13
- "mrm": "mrm --preset=@adonisjs/mrm-preset",
14
- "pretest": "npm run lint",
15
- "test": "node -r @adonisjs/require-ts/build/register bin/test.ts",
16
- "clean": "del-cli build",
17
- "compile": "npm run lint && npm run clean && tsc",
18
- "build": "npm run compile",
19
- "commit": "git-cz",
20
- "release": "np --message=\"chore(release): %s\"",
21
- "version": "npm run build",
22
- "prepublishOnly": "npm run build",
23
- "lint": "eslint . --ext=.ts",
24
- "format": "prettier --write .",
25
- "sync-labels": "github-label-sync --labels ./node_modules/@adonisjs/mrm-preset/gh-labels.json adonisjs/env"
26
- },
27
- "keywords": [
28
- "env",
29
- "adonisjs"
30
- ],
31
- "author": "virk,adonisjs",
32
- "license": "MIT",
33
- "devDependencies": {
34
- "@adonisjs/mrm-preset": "^5.0.3",
35
- "@adonisjs/require-ts": "^2.0.10",
36
- "@japa/assert": "^1.2.3",
37
- "@japa/run-failed-tests": "^1.0.3",
38
- "@japa/runner": "^2.0.6",
39
- "@japa/spec-reporter": "^1.1.7",
40
- "@poppinss/dev-utils": "^2.0.2",
41
- "@types/node": "^17.0.23",
42
- "commitizen": "^4.2.4",
43
- "cz-conventional-changelog": "^3.3.0",
44
- "del-cli": "^4.0.1",
45
- "eslint": "^8.12.0",
46
- "eslint-config-prettier": "^8.5.0",
47
- "eslint-plugin-adonis": "^2.1.0",
48
- "eslint-plugin-prettier": "^4.0.0",
49
- "github-label-sync": "^2.1.1",
50
- "husky": "^7.0.1",
51
- "mrm": "^4.0.0",
52
- "np": "^7.6.1",
53
- "prettier": "^2.6.2",
54
- "typescript": "^4.6.3"
55
- },
56
- "nyc": {
57
- "exclude": [
58
- "test"
59
- ],
60
- "extension": [
61
- ".ts"
62
- ]
63
- },
64
- "husky": {
65
- "hooks": {
66
- "commit-msg": "node ./node_modules/@adonisjs/mrm-preset/validateCommit/conventional/validate.js"
67
- }
68
- },
69
- "config": {
70
- "commitizen": {
71
- "path": "cz-conventional-changelog"
72
- }
73
- },
74
- "np": {
75
- "contents": ".",
76
- "anyBranch": false
77
- },
78
- "dependencies": {
79
- "@poppinss/utils": "^4.0.2",
80
- "dotenv": "^16.0.0",
81
- "validator": "^13.7.0"
82
- },
83
- "directories": {
84
- "doc": "docs",
85
- "test": "test"
86
- },
87
- "repository": {
88
- "type": "git",
89
- "url": "git+https://github.com/adonisjs/env.git"
90
- },
91
- "bugs": {
92
- "url": "https://github.com/adonisjs/env/issues"
93
- },
94
- "homepage": "https://github.com/adonisjs/env#readme",
95
- "publishConfig": {
96
- "access": "public",
97
- "tag": "latest"
98
- },
99
- "mrmConfig": {
100
- "core": true,
101
- "license": "MIT",
102
- "services": [
103
- "github-actions"
104
- ],
105
- "minNodeVersion": "14.15.4",
106
- "probotApps": [
107
- "stale",
108
- "lock"
109
- ],
110
- "runGhActionsOnWindows": false
111
- },
112
- "eslintConfig": {
113
- "extends": [
114
- "plugin:adonis/typescriptPackage",
115
- "prettier"
116
- ],
117
- "plugins": [
118
- "prettier"
119
- ],
120
- "rules": {
121
- "prettier/prettier": [
122
- "error",
123
- {
124
- "endOfLine": "auto"
125
- }
126
- ]
127
- }
128
- },
129
- "eslintIgnore": [
130
- "build"
131
- ],
132
- "prettier": {
133
- "trailingComma": "es5",
134
- "semi": false,
135
- "singleQuote": true,
136
- "useTabs": false,
137
- "quoteProps": "consistent",
138
- "bracketSpacing": true,
139
- "arrowParens": "always",
140
- "printWidth": 100
141
- }
2
+ "name": "@adonisjs/env",
3
+ "version": "4.0.0-1",
4
+ "description": "Environment variable manager for Node.js",
5
+ "main": "build/index.js",
6
+ "type": "module",
7
+ "files": [
8
+ "build/src",
9
+ "build/index.d.ts",
10
+ "build/index.js"
11
+ ],
12
+ "exports": {
13
+ ".": "./build/index.js"
14
+ },
15
+ "scripts": {
16
+ "pretest": "npm run lint",
17
+ "test": "npm run vscode:test",
18
+ "clean": "del-cli build",
19
+ "compile": "npm run lint && npm run clean && tsc",
20
+ "build": "npm run compile",
21
+ "release": "np",
22
+ "version": "npm run build",
23
+ "prepublishOnly": "npm run build",
24
+ "lint": "eslint . --ext=.ts",
25
+ "format": "prettier --write .",
26
+ "sync-labels": "github-label-sync --labels .github/labels.json adonisjs/env",
27
+ "vscode:test": "node --loader=ts-node/esm bin/test.ts"
28
+ },
29
+ "keywords": [
30
+ "env",
31
+ "adonisjs"
32
+ ],
33
+ "author": "virk,adonisjs",
34
+ "license": "MIT",
35
+ "devDependencies": {
36
+ "@commitlint/cli": "^17.1.2",
37
+ "@commitlint/config-conventional": "^17.1.0",
38
+ "@japa/assert": "^1.3.6",
39
+ "@japa/expect-type": "^1.0.2",
40
+ "@japa/run-failed-tests": "^1.1.0",
41
+ "@japa/runner": "^2.2.2",
42
+ "@japa/spec-reporter": "^1.3.2",
43
+ "@poppinss/dev-utils": "^2.0.3",
44
+ "@swc/core": "^1.3.9",
45
+ "@types/fs-extra": "^9.0.13",
46
+ "@types/node": "^18.11.0",
47
+ "del-cli": "^5.0.0",
48
+ "eslint": "^8.25.0",
49
+ "eslint-config-prettier": "^8.5.0",
50
+ "eslint-plugin-adonis": "^3.0.3",
51
+ "eslint-plugin-prettier": "^4.2.1",
52
+ "fs-extra": "^10.1.0",
53
+ "github-label-sync": "^2.2.0",
54
+ "husky": "^8.0.1",
55
+ "np": "^7.6.2",
56
+ "prettier": "^2.7.1",
57
+ "ts-node": "^10.9.1",
58
+ "typescript": "^4.8.4"
59
+ },
60
+ "dependencies": {
61
+ "@poppinss/utils": "^6.0.0-1",
62
+ "@poppinss/validator-lite": "^1.0.1",
63
+ "dotenv": "^16.0.3"
64
+ },
65
+ "repository": {
66
+ "type": "git",
67
+ "url": "git+https://github.com/adonisjs/env.git"
68
+ },
69
+ "bugs": {
70
+ "url": "https://github.com/adonisjs/env/issues"
71
+ },
72
+ "homepage": "https://github.com/adonisjs/env#readme",
73
+ "eslintConfig": {
74
+ "extends": [
75
+ "plugin:adonis/typescriptPackage",
76
+ "prettier"
77
+ ],
78
+ "plugins": [
79
+ "prettier"
80
+ ],
81
+ "rules": {
82
+ "prettier/prettier": [
83
+ "error",
84
+ {
85
+ "endOfLine": "auto"
86
+ }
87
+ ]
88
+ }
89
+ },
90
+ "eslintIgnore": [
91
+ "build"
92
+ ],
93
+ "prettier": {
94
+ "trailingComma": "es5",
95
+ "semi": false,
96
+ "singleQuote": true,
97
+ "useTabs": false,
98
+ "quoteProps": "consistent",
99
+ "bracketSpacing": true,
100
+ "arrowParens": "always",
101
+ "printWidth": 100
102
+ },
103
+ "commitlint": {
104
+ "extends": [
105
+ "@commitlint/config-conventional"
106
+ ]
107
+ },
108
+ "publishConfig": {
109
+ "access": "public",
110
+ "tag": "next"
111
+ },
112
+ "np": {
113
+ "message": "chore(release): %s",
114
+ "tag": "next",
115
+ "branch": "main",
116
+ "anyBranch": false
117
+ }
142
118
  }
@@ -1,127 +0,0 @@
1
- declare module '@ioc:Adonis/Core/Env' {
2
- /**
3
- * An interface meant to be extended in the user land that holds
4
- * types for environment variables extracted using env.validate
5
- * method.
6
- */
7
- export interface EnvTypes {
8
- }
9
- /**
10
- * The shape of the validate fn
11
- */
12
- export type ValidateFn<T extends unknown> = (key: string, value?: string) => T;
13
- /**
14
- * A standard set of options accepted by the schema validation
15
- * functions
16
- */
17
- export type SchemaFnOptions = {
18
- message?: string;
19
- };
20
- export type StringFnUrlOptions = SchemaFnOptions & {
21
- format: 'url';
22
- /**
23
- * Whether the URL must have a valid TLD in their domain.
24
- * Defaults to `true`.
25
- */
26
- tld?: boolean;
27
- /**
28
- * Whether the URL must start with a valid protocol.
29
- * Defaults to `true`.
30
- */
31
- protocol?: boolean;
32
- };
33
- /**
34
- * Options accepted by the string schema function
35
- */
36
- export type StringFnOptions = (SchemaFnOptions & {
37
- format?: 'host' | 'email';
38
- }) | StringFnUrlOptions;
39
- /**
40
- * Shape of the number validator
41
- */
42
- export interface NumberType {
43
- (options?: SchemaFnOptions): ValidateFn<number>;
44
- optional: (options?: SchemaFnOptions) => ValidateFn<number | undefined>;
45
- }
46
- /**
47
- * Shape of the string validator
48
- */
49
- export interface StringType {
50
- (options?: StringFnOptions): ValidateFn<string>;
51
- optional: (options?: StringFnOptions) => ValidateFn<string | undefined>;
52
- }
53
- /**
54
- * Shape of the boolean validator
55
- */
56
- export interface BooleanType {
57
- (options?: SchemaFnOptions): ValidateFn<boolean>;
58
- optional: (options?: SchemaFnOptions) => ValidateFn<boolean | undefined>;
59
- }
60
- /**
61
- * Shape of the enum validator
62
- */
63
- export interface EnumType {
64
- <K extends any>(choices: readonly K[], options?: SchemaFnOptions): ValidateFn<K>;
65
- optional: <K extends any>(choices: readonly K[], options?: SchemaFnOptions) => ValidateFn<K | undefined>;
66
- }
67
- /**
68
- * Available schema functions. The end user can also define their
69
- * own
70
- */
71
- export interface EnvSchema {
72
- /**
73
- * Number function to enforce value to be a strict number
74
- */
75
- number: NumberType;
76
- /**
77
- * String function to enforce value to be a string. Optionally
78
- * the format can also be defined
79
- */
80
- string: StringType;
81
- /**
82
- * Boolean function to enforce value to be a boolean value.
83
- */
84
- boolean: BooleanType;
85
- /**
86
- * Boolean function to enforce value to be one of the defined values.
87
- */
88
- enum: EnumType;
89
- }
90
- /**
91
- * Env contract
92
- */
93
- export interface EnvContract {
94
- /**
95
- * Get value for a given environment variable
96
- */
97
- get<K extends keyof EnvTypes>(key: K): EnvTypes[K];
98
- get<K extends keyof EnvTypes>(key: K, defaultValue: Exclude<EnvTypes[K], undefined>): Exclude<EnvTypes[K], undefined>;
99
- get(key: string, defaultValue?: any): any;
100
- /**
101
- * Update/set value for a given environment variable. Ideally one should
102
- * avoid updating values during runtime
103
- */
104
- set<K extends keyof EnvTypes>(key: K, value: EnvTypes[K]): void;
105
- set(key: string, value: any): void;
106
- /**
107
- * Validate environment variables
108
- */
109
- rules<T extends {
110
- [key: string]: ValidateFn<unknown>;
111
- }>(values: T): {
112
- [K in keyof T]: ReturnType<T[K]>;
113
- };
114
- /**
115
- * Processes environment variables and performs the registered
116
- * validations
117
- */
118
- process(): void;
119
- /**
120
- * Reference to the schema object for defining validation
121
- * rules
122
- */
123
- schema: EnvSchema;
124
- }
125
- const Env: EnvContract;
126
- export default Env;
127
- }
@@ -1,8 +0,0 @@
1
- /*
2
- * @adonisjs/env
3
- *
4
- * (c) Harminder Virk <virk@adonisjs.com>
5
- *
6
- * For the full copyright and license information, please view the LICENSE
7
- * file that was distributed with this source code.
8
- */
@@ -1,59 +0,0 @@
1
- /// <reference path="../../adonis-typings/env.d.ts" />
2
- import { DotenvParseOutput } from 'dotenv';
3
- import { EnvContract, ValidateFn } from '@ioc:Adonis/Core/Env';
4
- /**
5
- * The ENV module enables the use of environment variables by parsing dotfiles syntax
6
- * and updates the `process.env` object in Node.js.
7
- *
8
- * AdonisJs automatically reads and passes the contents of `.env` file to this class.
9
- */
10
- export declare class Env implements EnvContract {
11
- private valuesToProcess;
12
- /**
13
- * A boolean to know if the values have been processed or
14
- * not
15
- */
16
- private hasProcessedValues;
17
- /**
18
- * A cache of env values
19
- */
20
- private envCache;
21
- /**
22
- * The schema to be used for validating and casting environment
23
- * variables
24
- */
25
- private validationSchema;
26
- constructor(valuesToProcess: {
27
- values: DotenvParseOutput;
28
- overwriteExisting: boolean;
29
- }[]);
30
- /**
31
- * Reference to the underlying schema
32
- */
33
- schema: import("@ioc:Adonis/Core/Env").EnvSchema;
34
- /**
35
- * Process parsed env variables. The values will be validated
36
- * against the validation schema
37
- */
38
- process(): void;
39
- /**
40
- * Register the validation schema
41
- */
42
- rules(schema: {
43
- [key: string]: ValidateFn<unknown>;
44
- }): any;
45
- /**
46
- * Returns the environment variable value. First the cached
47
- * values are preferred. When missing, the value from
48
- * "process.env" is used
49
- */
50
- get(key: string, defaultValue?: any): any;
51
- /**
52
- * Set key-value pair. The value will be validated using
53
- * the validation rule if exists.
54
- *
55
- * The original value is also updated on the `process.env`
56
- * object
57
- */
58
- set(key: string, value: any): void;
59
- }
@@ -1,140 +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.Env = void 0;
12
- const Schema_1 = require("../Schema");
13
- /**
14
- * The ENV module enables the use of environment variables by parsing dotfiles syntax
15
- * and updates the `process.env` object in Node.js.
16
- *
17
- * AdonisJs automatically reads and passes the contents of `.env` file to this class.
18
- */
19
- class Env {
20
- constructor(valuesToProcess) {
21
- this.valuesToProcess = valuesToProcess;
22
- /**
23
- * A boolean to know if the values have been processed or
24
- * not
25
- */
26
- this.hasProcessedValues = false;
27
- /**
28
- * A cache of env values
29
- */
30
- this.envCache = {};
31
- /**
32
- * The schema to be used for validating and casting environment
33
- * variables
34
- */
35
- this.validationSchema = {};
36
- /**
37
- * Reference to the underlying schema
38
- */
39
- this.schema = Schema_1.schema;
40
- }
41
- /**
42
- * Process parsed env variables. The values will be validated
43
- * against the validation schema
44
- */
45
- process() {
46
- /**
47
- * Avoid re-processing the same values over and over
48
- * again
49
- */
50
- if (this.hasProcessedValues) {
51
- return;
52
- }
53
- this.hasProcessedValues = true;
54
- /**
55
- * Loop over the parsed object and set the value
56
- * on the process.env and the local cache.
57
- *
58
- * At this stage we process the values like a regular env parser with
59
- * no validation taking place
60
- */
61
- this.valuesToProcess.forEach(({ values, overwriteExisting }) => {
62
- Object.keys(values).forEach((key) => {
63
- /**
64
- * Use existing value when it already exists in process.env object
65
- * and [this.overwriteExisting] is set to false
66
- */
67
- const existingValue = process.env[key];
68
- if (existingValue && !overwriteExisting) {
69
- this.envCache[key] = existingValue;
70
- return;
71
- }
72
- /**
73
- * Otherwise set the value on "process.env"
74
- */
75
- this.envCache[key] = values[key];
76
- process.env[key] = values[key];
77
- });
78
- });
79
- /**
80
- * Release parsed values, since we don't need it anymore
81
- */
82
- this.valuesToProcess = [];
83
- /**
84
- * Perform validations by reading the environment variables
85
- */
86
- Object.keys(this.validationSchema).forEach((key) => {
87
- this.envCache[key] = this.validationSchema[key](key, this.get(key));
88
- });
89
- }
90
- /**
91
- * Register the validation schema
92
- */
93
- rules(schema) {
94
- this.validationSchema = schema;
95
- return {};
96
- }
97
- /**
98
- * Returns the environment variable value. First the cached
99
- * values are preferred. When missing, the value from
100
- * "process.env" is used
101
- */
102
- get(key, defaultValue) {
103
- /**
104
- * Return cached value
105
- */
106
- if (this.envCache[key] !== undefined) {
107
- return this.envCache[key];
108
- }
109
- /**
110
- * Get value from process.env and update the cache
111
- */
112
- const envValue = process.env[key];
113
- if (envValue) {
114
- this.envCache[key] = envValue;
115
- return envValue;
116
- }
117
- /**
118
- * Return default value when unable to lookup any other value
119
- */
120
- return defaultValue;
121
- }
122
- /**
123
- * Set key-value pair. The value will be validated using
124
- * the validation rule if exists.
125
- *
126
- * The original value is also updated on the `process.env`
127
- * object
128
- */
129
- set(key, value) {
130
- const validationFn = this.validationSchema[key];
131
- if (validationFn) {
132
- this.envCache[key] = validationFn(key, value);
133
- }
134
- else {
135
- this.envCache[key] = value;
136
- }
137
- process.env[key] = value;
138
- }
139
- }
140
- exports.Env = Env;
@@ -1,54 +0,0 @@
1
- /**
2
- * Env parser parses the environment variables from a string formatted
3
- * as a key-value pair seperated using an `=`. For example:
4
- *
5
- * ```
6
- * PORT=3333
7
- * HOST=127.0.0.1
8
- * ```
9
- *
10
- * The variables can reference other environment variables as well using `$`.
11
- * For example:
12
- *
13
- * ```
14
- * PORT=3333
15
- * REDIS_PORT=$PORT
16
- * ```
17
- *
18
- * The variables using characters other than letters can use wrap variables inside
19
- * a curly brace.
20
- *
21
- * ```
22
- * APP-PORT=3333
23
- * REDIS_PORT=${APP-PORT}
24
- * ```
25
- */
26
- export declare class EnvParser {
27
- private preferExistingEnvVariables;
28
- constructor(preferExistingEnvVariables?: boolean);
29
- /**
30
- * Returns value for a given key from the environment variables. Also
31
- * the current parsed object is used to pull the reference.
32
- */
33
- private getValue;
34
- /**
35
- * Interpolating the token wrapped inside the mustache
36
- * braces.
37
- */
38
- private interpolateMustache;
39
- /**
40
- * Interpolating the variable reference starting with a
41
- * `$`. We only capture numbers,letter and underscore.
42
- * For other characters, one can use the mustache
43
- * braces.
44
- */
45
- private interpolateVariable;
46
- /**
47
- * Interpolates the referenced values
48
- */
49
- private interpolate;
50
- /**
51
- * Parse the env string to an object of environment variables.
52
- */
53
- parse(envString: string): {};
54
- }