@adonisjs/env 7.0.0-next.1 → 7.0.0-next.2

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.js CHANGED
@@ -4,11 +4,10 @@ import {
4
4
  debug_default
5
5
  } from "./chunk-KE5AFOK2.js";
6
6
 
7
- // src/env.ts
8
- import { schema as envSchema } from "@poppinss/validator-lite";
9
-
10
7
  // src/parser.ts
8
+ import { readFile } from "fs/promises";
11
9
  import dotenv from "dotenv";
10
+ import { RuntimeException } from "@poppinss/utils/exception";
12
11
 
13
12
  // src/errors.ts
14
13
  var errors_exports = {};
@@ -29,8 +28,6 @@ var E_IDENTIFIER_ALREADY_DEFINED = createError(
29
28
  );
30
29
 
31
30
  // src/parser.ts
32
- import { readFile } from "fs/promises";
33
- import { RuntimeException } from "@poppinss/utils/exception";
34
31
  var EnvParser = class _EnvParser {
35
32
  /**
36
33
  * Raw environment file contents
@@ -260,8 +257,8 @@ var EnvValidator = class {
260
257
  *
261
258
  * @param schema - The validation schema object
262
259
  */
263
- constructor(schema) {
264
- this.#schema = schema;
260
+ constructor(schema2) {
261
+ this.#schema = schema2;
265
262
  this.#error = new E_INVALID_ENV_VARIABLES();
266
263
  }
267
264
  /**
@@ -363,6 +360,38 @@ var EnvProcessor = class {
363
360
  }
364
361
  };
365
362
 
363
+ // src/schema.ts
364
+ import { Secret } from "@poppinss/utils";
365
+ import { schema as envSchema } from "@poppinss/validator-lite";
366
+ function secret(options) {
367
+ return function validate(key, value) {
368
+ if (!value) {
369
+ throw new Error(options?.message ?? `Missing environment variable "${key}"`);
370
+ }
371
+ return new Secret(value);
372
+ };
373
+ }
374
+ secret.optional = function optionalString() {
375
+ return function validate(_, value) {
376
+ if (!value) {
377
+ return void 0;
378
+ }
379
+ return new Secret(value);
380
+ };
381
+ };
382
+ secret.optionalWhen = function optionalWhenString(condition, options) {
383
+ return function validate(key, value) {
384
+ if (typeof condition === "function" ? condition(key, value) : condition) {
385
+ return secret.optional()(key, value);
386
+ }
387
+ return secret(options)(key, value);
388
+ };
389
+ };
390
+ var schema = {
391
+ ...envSchema,
392
+ secret
393
+ };
394
+
366
395
  // src/env.ts
367
396
  var Env = class _Env {
368
397
  /**
@@ -386,9 +415,9 @@ var Env = class _Env {
386
415
  * @param schema - Validation schema for environment variables
387
416
  * @returns Promise resolving to an Env instance with validated values
388
417
  */
389
- static async create(appRoot, schema) {
418
+ static async create(appRoot, schema2) {
390
419
  const values = await new EnvProcessor(appRoot).process();
391
- const validator = this.rules(schema);
420
+ const validator = this.rules(schema2);
392
421
  return new _Env(validator.validate(values));
393
422
  }
394
423
  /**
@@ -434,7 +463,7 @@ var Env = class _Env {
434
463
  /**
435
464
  * The schema builder for defining validation rules
436
465
  */
437
- static schema = envSchema;
466
+ static schema = schema;
438
467
  /**
439
468
  * Define the validation rules for validating environment
440
469
  * variables. The return value is an instance of the
@@ -443,8 +472,8 @@ var Env = class _Env {
443
472
  * @param schema - Validation schema object
444
473
  * @returns EnvValidator instance
445
474
  */
446
- static rules(schema) {
447
- const validator = new EnvValidator(schema);
475
+ static rules(schema2) {
476
+ const validator = new EnvValidator(schema2);
448
477
  return validator;
449
478
  }
450
479
  get(key, defaultValue) {
@@ -1,6 +1,6 @@
1
- import { schema as envSchema } from '@poppinss/validator-lite';
2
1
  import type { ValidateFn } from '@poppinss/validator-lite/types';
3
2
  import { EnvValidator } from './validator.ts';
3
+ import { schema as envSchema } from './schema.ts';
4
4
  /**
5
5
  * A wrapper over "process.env" with types information.
6
6
  *
@@ -3,7 +3,7 @@ import { type DotenvParseOutput } from 'dotenv';
3
3
  * Env parser parses the environment variables from a string formatted
4
4
  * as a key-value pair seperated using an `=`. For example:
5
5
  *
6
- * ```dotenv
6
+ * ```
7
7
  * PORT=3333
8
8
  * HOST=127.0.0.1
9
9
  * ```
@@ -11,7 +11,7 @@ import { type DotenvParseOutput } from 'dotenv';
11
11
  * The variables can reference other environment variables as well using `$`.
12
12
  * For example:
13
13
  *
14
- * ```dotenv
14
+ * ```
15
15
  * PORT=3333
16
16
  * REDIS_PORT=$PORT
17
17
  * ```
@@ -19,14 +19,14 @@ import { type DotenvParseOutput } from 'dotenv';
19
19
  * The variables using characters other than letters can wrap variable
20
20
  * named inside a curly brace.
21
21
  *
22
- * ```dotenv
22
+ * ```
23
23
  * APP-PORT=3333
24
24
  * REDIS_PORT=${APP-PORT}
25
25
  * ```
26
26
  *
27
27
  * You can escape the `$` sign with a backtick.
28
28
  *
29
- * ```dotenv
29
+ * ```
30
30
  * REDIS_PASSWORD=foo\$123
31
31
  * ```
32
32
  *
@@ -0,0 +1,13 @@
1
+ import { Secret } from '@poppinss/utils';
2
+ import { type Prettify } from '@poppinss/utils/types';
3
+ import { schema as envSchema } from '@poppinss/validator-lite';
4
+ import { type SchemaFnOptions } from '@poppinss/validator-lite/types';
5
+ declare function secret(options?: SchemaFnOptions): (key: string, value?: string) => Secret<string>;
6
+ declare namespace secret {
7
+ var optional: () => (_: string, value?: string) => Secret<string> | undefined;
8
+ var optionalWhen: (condition: boolean | ((key: string, value?: string) => boolean), options?: SchemaFnOptions) => (key: string, value?: string) => Secret<string> | undefined;
9
+ }
10
+ export declare const schema: Prettify<typeof envSchema & {
11
+ secret: typeof secret;
12
+ }>;
13
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adonisjs/env",
3
- "version": "7.0.0-next.1",
3
+ "version": "7.0.0-next.2",
4
4
  "description": "Environment variable manager for Node.js",
5
5
  "main": "build/index.js",
6
6
  "type": "module",
@@ -43,20 +43,21 @@
43
43
  "@japa/runner": "^4.4.0",
44
44
  "@poppinss/ts-exec": "^1.4.1",
45
45
  "@release-it/conventional-changelog": "^10.0.1",
46
- "@types/node": "^24.3.0",
46
+ "@types/node": "^24.3.1",
47
47
  "c8": "^10.1.3",
48
48
  "cross-env": "^10.0.0",
49
49
  "del-cli": "^6.0.0",
50
- "eslint": "^9.34.0",
50
+ "eslint": "^9.35.0",
51
51
  "prettier": "^3.6.2",
52
52
  "release-it": "^19.0.4",
53
53
  "tsup": "^8.5.0",
54
+ "typedoc": "^0.28.12",
54
55
  "typescript": "^5.9.2"
55
56
  },
56
57
  "dependencies": {
57
58
  "@poppinss/utils": "^7.0.0-next.3",
58
59
  "@poppinss/validator-lite": "^2.1.2",
59
- "dotenv": "^17.2.1",
60
+ "dotenv": "^17.2.2",
60
61
  "split-lines": "^3.0.0"
61
62
  },
62
63
  "homepage": "https://github.com/adonisjs/env#readme",