@haskou/ddd-kernel 1.1.0 → 1.2.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.
Files changed (49) hide show
  1. package/dist/{RetryPredicate-DAv_7ve2.d.ts → RetryPredicate-Bl3SMnbL.d.ts} +1 -1
  2. package/dist/{RetryPredicate-CBlnBUDO.d.cts → RetryPredicate-ZjioTYXn.d.cts} +1 -1
  3. package/dist/{ShutdownHook-3Gc1yyHI.d.ts → ShutdownHook-B03Mcke-.d.ts} +47 -11
  4. package/dist/{ShutdownHook-BUvR2Ii7.d.cts → ShutdownHook-BsEGvnEf.d.cts} +47 -11
  5. package/dist/adapters/index.cjs +81 -3
  6. package/dist/adapters/index.cjs.map +1 -1
  7. package/dist/adapters/index.d.cts +2 -2
  8. package/dist/adapters/index.d.ts +2 -2
  9. package/dist/adapters/index.js +81 -3
  10. package/dist/adapters/index.js.map +1 -1
  11. package/dist/adapters/pubsub/amqp/index.cjs +81 -3
  12. package/dist/adapters/pubsub/amqp/index.cjs.map +1 -1
  13. package/dist/adapters/pubsub/amqp/index.js +81 -3
  14. package/dist/adapters/pubsub/amqp/index.js.map +1 -1
  15. package/dist/adapters/pubsub/index.cjs +81 -3
  16. package/dist/adapters/pubsub/index.cjs.map +1 -1
  17. package/dist/adapters/pubsub/index.d.cts +3 -3
  18. package/dist/adapters/pubsub/index.d.ts +3 -3
  19. package/dist/adapters/pubsub/index.js +81 -3
  20. package/dist/adapters/pubsub/index.js.map +1 -1
  21. package/dist/adapters/ui/express/index.d.cts +2 -2
  22. package/dist/adapters/ui/express/index.d.ts +2 -2
  23. package/dist/adapters/ui/index.cjs +81 -3
  24. package/dist/adapters/ui/index.cjs.map +1 -1
  25. package/dist/adapters/ui/index.d.cts +1 -1
  26. package/dist/adapters/ui/index.d.ts +1 -1
  27. package/dist/adapters/ui/index.js +81 -3
  28. package/dist/adapters/ui/index.js.map +1 -1
  29. package/dist/adapters/ui/routes/index.cjs +81 -3
  30. package/dist/adapters/ui/routes/index.cjs.map +1 -1
  31. package/dist/adapters/ui/routes/index.js +81 -3
  32. package/dist/adapters/ui/routes/index.js.map +1 -1
  33. package/dist/contracts/index.d.cts +2 -2
  34. package/dist/contracts/index.d.ts +2 -2
  35. package/dist/contracts/kernel/index.d.cts +2 -2
  36. package/dist/contracts/kernel/index.d.ts +2 -2
  37. package/dist/index.cjs +83 -3
  38. package/dist/index.cjs.map +1 -1
  39. package/dist/index.d.cts +8 -2
  40. package/dist/index.d.ts +8 -2
  41. package/dist/index.js +82 -3
  42. package/dist/index.js.map +1 -1
  43. package/dist/infrastructure/express/index.d.cts +1 -1
  44. package/dist/infrastructure/express/index.d.ts +1 -1
  45. package/dist/infrastructure/scheduler/index.cjs +81 -3
  46. package/dist/infrastructure/scheduler/index.cjs.map +1 -1
  47. package/dist/infrastructure/scheduler/index.js +81 -3
  48. package/dist/infrastructure/scheduler/index.js.map +1 -1
  49. package/package.json +1 -1
@@ -1,4 +1,4 @@
1
- import { a as ConsumerExecutionContext } from './ShutdownHook-3Gc1yyHI.js';
1
+ import { a as ConsumerExecutionContext } from './ShutdownHook-B03Mcke-.js';
2
2
 
3
3
  interface IdempotencyStore {
4
4
  claim?(key: string): Promise<boolean> | boolean;
@@ -1,4 +1,4 @@
1
- import { a as ConsumerExecutionContext } from './ShutdownHook-BUvR2Ii7.cjs';
1
+ import { a as ConsumerExecutionContext } from './ShutdownHook-BsEGvnEf.cjs';
2
2
 
3
3
  interface IdempotencyStore {
4
4
  claim?(key: string): Promise<boolean> | boolean;
@@ -27,19 +27,49 @@ interface KernelDependencyInjectionOptions {
27
27
  readonly sourceDirectory?: string;
28
28
  }
29
29
 
30
- interface KernelEnvironmentVariablesOptions {
30
+ type KernelDefaultEnvironment = NodeJS.ProcessEnv;
31
+
32
+ type KernelEnvironmentVariableType = 'boolean' | 'number' | 'string';
33
+
34
+ type KernelEnvironmentVariablePrimitive<TType extends KernelEnvironmentVariableType> = TType extends 'boolean' ? boolean : TType extends 'number' ? number : string;
35
+
36
+ interface KernelEnvironmentVariableDefinition<TType extends KernelEnvironmentVariableType = KernelEnvironmentVariableType, TRequired extends boolean = boolean> {
37
+ readonly defaultValue?: KernelEnvironmentVariablePrimitive<TType>;
38
+ readonly required?: TRequired;
39
+ readonly type: TType;
40
+ }
41
+
42
+ type KernelEnvironmentSchema = Readonly<Record<string, KernelEnvironmentVariableDefinition>>;
43
+
44
+ type KernelEnvironmentValue = boolean | number | string;
45
+
46
+ type KernelEnvironmentVariable<TDefinition extends KernelEnvironmentVariableDefinition> = TDefinition extends KernelEnvironmentVariableDefinition<infer TType extends KernelEnvironmentVariableType, infer TRequired extends boolean> ? TDefinition extends {
47
+ readonly defaultValue: unknown;
48
+ } ? KernelEnvironmentVariablePrimitive<TType> : TRequired extends true ? KernelEnvironmentVariablePrimitive<TType> : KernelEnvironmentVariablePrimitive<TType> | undefined : never;
49
+
50
+ type KernelEnvironment<TSchema extends KernelEnvironmentSchema> = {
51
+ readonly [key: string]: KernelEnvironmentValue | undefined;
52
+ } & {
53
+ readonly [TKey in keyof TSchema]: KernelEnvironmentVariable<TSchema[TKey]>;
54
+ };
55
+
56
+ type KernelEnvironmentForSchema<TSchema extends KernelEnvironmentSchema | undefined> = TSchema extends KernelEnvironmentSchema ? KernelEnvironment<TSchema> : KernelDefaultEnvironment;
57
+
58
+ interface KernelEnvironmentVariablesOptions<TSchema extends KernelEnvironmentSchema | undefined = undefined> {
31
59
  readonly override?: boolean;
32
60
  readonly path?: string;
61
+ readonly schema?: TSchema;
33
62
  }
34
63
 
35
- interface KernelOptions {
64
+ interface KernelOptions<TEnvironmentSchema extends KernelEnvironmentSchema | undefined = undefined> {
36
65
  readonly di?: DependencyInjection;
66
+ readonly environmentSchema?: TEnvironmentSchema;
37
67
  readonly logger?: KernelLogger;
38
68
  readonly servicesYamlPath?: string;
39
69
  readonly sourceDirectory?: string;
40
70
  }
41
71
 
42
- declare class Kernel {
72
+ declare class Kernel<TEnvironmentSchema extends KernelEnvironmentSchema | undefined = undefined> {
43
73
  private readonly options;
44
74
  private static readonly stateKey;
45
75
  private readonly consumerMiddlewares;
@@ -49,6 +79,7 @@ declare class Kernel {
49
79
  private readonly schedulersList;
50
80
  private readonly shutdownHooks;
51
81
  private dependencyInjectionInstance;
82
+ private environmentVariables;
52
83
  private static get state();
53
84
  static get configDirectory(): string;
54
85
  static get consumers(): Consumer[];
@@ -56,15 +87,20 @@ declare class Kernel {
56
87
  static get di(): DependencyInjection;
57
88
  static get environment(): NodeJS.ProcessEnv;
58
89
  static get logger(): KernelLogger;
59
- static get active(): Kernel;
90
+ static get active(): Kernel<KernelEnvironmentSchema | undefined>;
60
91
  static get rootDirectory(): string;
61
92
  static get routes(): ServiceClass<Route>[];
62
93
  static get schedulers(): Scheduler[];
63
94
  static get sourceDirectory(): string;
64
95
  private static getActiveKernel;
96
+ private static assertRequiredEnvironmentVariable;
65
97
  private static getEnvironmentVariablesPath;
66
- static loadEnvironmentVariables(environment?: string, options?: KernelEnvironmentVariablesOptions): DotenvConfigOutput;
67
- constructor(options?: KernelOptions);
98
+ private static parseBooleanEnvironmentVariable;
99
+ private static parseNumberEnvironmentVariable;
100
+ private static parseEnvironmentVariable;
101
+ private static validateEnvironmentVariables;
102
+ static loadEnvironmentVariables(environment?: string, options?: KernelEnvironmentVariablesOptions<KernelEnvironmentSchema | undefined>): DotenvConfigOutput;
103
+ constructor(options?: KernelOptions<TEnvironmentSchema>);
68
104
  private closeCandidate;
69
105
  private getConsumerFromClass;
70
106
  private getInitializerFromClass;
@@ -73,13 +109,13 @@ declare class Kernel {
73
109
  get consumers(): Consumer[];
74
110
  get consumerMiddleware(): ConsumerMiddleware[];
75
111
  get di(): DependencyInjection;
76
- get environment(): NodeJS.ProcessEnv;
112
+ get environment(): KernelEnvironmentForSchema<TEnvironmentSchema>;
77
113
  get logger(): KernelLogger;
78
114
  get routes(): ServiceClass<Route>[];
79
115
  get schedulers(): Scheduler[];
80
116
  private getDependencyInjectionOptions;
81
117
  dependencyInjection(options?: KernelDependencyInjectionOptions): Promise<void>;
82
- loadEnvironmentVariables(environment?: string, options?: KernelEnvironmentVariablesOptions): DotenvConfigOutput;
118
+ loadEnvironmentVariables(environment?: string, options?: KernelEnvironmentVariablesOptions<KernelEnvironmentSchema | undefined>): DotenvConfigOutput;
83
119
  getRoutes(): ServiceClass<Route>[];
84
120
  registerConsumerMiddleware(...middlewares: ConsumerMiddleware[]): void;
85
121
  registerConsumers(...ClassDefinitions: ServiceClass<Consumer>[]): void;
@@ -98,7 +134,7 @@ declare class Kernel {
98
134
  runSchedulers(): Promise<void>;
99
135
  shutdown(): Promise<void>;
100
136
  }
101
- declare function createKernel(options?: KernelOptions): Kernel;
137
+ declare function createKernel<TEnvironmentSchema extends KernelEnvironmentSchema | undefined = undefined>(options?: KernelOptions<TEnvironmentSchema>): Kernel<TEnvironmentSchema>;
102
138
 
103
139
  interface ConsumerExecutionContext {
104
140
  readonly causationId?: string;
@@ -106,7 +142,7 @@ interface ConsumerExecutionContext {
106
142
  readonly eventId: string;
107
143
  readonly eventName: string;
108
144
  readonly exchange: string;
109
- readonly kernel: Kernel;
145
+ readonly kernel: Kernel<KernelEnvironmentSchema | undefined>;
110
146
  readonly metadata: Readonly<Record<string, unknown>>;
111
147
  readonly rawMessage?: unknown;
112
148
  readonly queueName: string;
@@ -120,4 +156,4 @@ interface ConsumerMiddleware {
120
156
 
121
157
  type ShutdownHook = () => Promise<void> | void;
122
158
 
123
- export { Consumer as C, Kernel as K, type ShutdownHook as S, type ConsumerExecutionContext as a, type ConsumerMiddleware as b, type ConsumerNext as c, type KernelDependencyInjectionOptions as d, type KernelEnvironmentVariablesOptions as e, type KernelOptions as f, createKernel as g };
159
+ export { Consumer as C, Kernel as K, type ShutdownHook as S, type ConsumerExecutionContext as a, type ConsumerMiddleware as b, type ConsumerNext as c, type KernelDefaultEnvironment as d, type KernelDependencyInjectionOptions as e, type KernelEnvironment as f, type KernelEnvironmentForSchema as g, type KernelEnvironmentSchema as h, type KernelEnvironmentValue as i, type KernelEnvironmentVariableDefinition as j, type KernelEnvironmentVariablePrimitive as k, type KernelEnvironmentVariableType as l, type KernelEnvironmentVariablesOptions as m, type KernelOptions as n, createKernel as o };
@@ -27,19 +27,49 @@ interface KernelDependencyInjectionOptions {
27
27
  readonly sourceDirectory?: string;
28
28
  }
29
29
 
30
- interface KernelEnvironmentVariablesOptions {
30
+ type KernelDefaultEnvironment = NodeJS.ProcessEnv;
31
+
32
+ type KernelEnvironmentVariableType = 'boolean' | 'number' | 'string';
33
+
34
+ type KernelEnvironmentVariablePrimitive<TType extends KernelEnvironmentVariableType> = TType extends 'boolean' ? boolean : TType extends 'number' ? number : string;
35
+
36
+ interface KernelEnvironmentVariableDefinition<TType extends KernelEnvironmentVariableType = KernelEnvironmentVariableType, TRequired extends boolean = boolean> {
37
+ readonly defaultValue?: KernelEnvironmentVariablePrimitive<TType>;
38
+ readonly required?: TRequired;
39
+ readonly type: TType;
40
+ }
41
+
42
+ type KernelEnvironmentSchema = Readonly<Record<string, KernelEnvironmentVariableDefinition>>;
43
+
44
+ type KernelEnvironmentValue = boolean | number | string;
45
+
46
+ type KernelEnvironmentVariable<TDefinition extends KernelEnvironmentVariableDefinition> = TDefinition extends KernelEnvironmentVariableDefinition<infer TType extends KernelEnvironmentVariableType, infer TRequired extends boolean> ? TDefinition extends {
47
+ readonly defaultValue: unknown;
48
+ } ? KernelEnvironmentVariablePrimitive<TType> : TRequired extends true ? KernelEnvironmentVariablePrimitive<TType> : KernelEnvironmentVariablePrimitive<TType> | undefined : never;
49
+
50
+ type KernelEnvironment<TSchema extends KernelEnvironmentSchema> = {
51
+ readonly [key: string]: KernelEnvironmentValue | undefined;
52
+ } & {
53
+ readonly [TKey in keyof TSchema]: KernelEnvironmentVariable<TSchema[TKey]>;
54
+ };
55
+
56
+ type KernelEnvironmentForSchema<TSchema extends KernelEnvironmentSchema | undefined> = TSchema extends KernelEnvironmentSchema ? KernelEnvironment<TSchema> : KernelDefaultEnvironment;
57
+
58
+ interface KernelEnvironmentVariablesOptions<TSchema extends KernelEnvironmentSchema | undefined = undefined> {
31
59
  readonly override?: boolean;
32
60
  readonly path?: string;
61
+ readonly schema?: TSchema;
33
62
  }
34
63
 
35
- interface KernelOptions {
64
+ interface KernelOptions<TEnvironmentSchema extends KernelEnvironmentSchema | undefined = undefined> {
36
65
  readonly di?: DependencyInjection;
66
+ readonly environmentSchema?: TEnvironmentSchema;
37
67
  readonly logger?: KernelLogger;
38
68
  readonly servicesYamlPath?: string;
39
69
  readonly sourceDirectory?: string;
40
70
  }
41
71
 
42
- declare class Kernel {
72
+ declare class Kernel<TEnvironmentSchema extends KernelEnvironmentSchema | undefined = undefined> {
43
73
  private readonly options;
44
74
  private static readonly stateKey;
45
75
  private readonly consumerMiddlewares;
@@ -49,6 +79,7 @@ declare class Kernel {
49
79
  private readonly schedulersList;
50
80
  private readonly shutdownHooks;
51
81
  private dependencyInjectionInstance;
82
+ private environmentVariables;
52
83
  private static get state();
53
84
  static get configDirectory(): string;
54
85
  static get consumers(): Consumer[];
@@ -56,15 +87,20 @@ declare class Kernel {
56
87
  static get di(): DependencyInjection;
57
88
  static get environment(): NodeJS.ProcessEnv;
58
89
  static get logger(): KernelLogger;
59
- static get active(): Kernel;
90
+ static get active(): Kernel<KernelEnvironmentSchema | undefined>;
60
91
  static get rootDirectory(): string;
61
92
  static get routes(): ServiceClass<Route>[];
62
93
  static get schedulers(): Scheduler[];
63
94
  static get sourceDirectory(): string;
64
95
  private static getActiveKernel;
96
+ private static assertRequiredEnvironmentVariable;
65
97
  private static getEnvironmentVariablesPath;
66
- static loadEnvironmentVariables(environment?: string, options?: KernelEnvironmentVariablesOptions): DotenvConfigOutput;
67
- constructor(options?: KernelOptions);
98
+ private static parseBooleanEnvironmentVariable;
99
+ private static parseNumberEnvironmentVariable;
100
+ private static parseEnvironmentVariable;
101
+ private static validateEnvironmentVariables;
102
+ static loadEnvironmentVariables(environment?: string, options?: KernelEnvironmentVariablesOptions<KernelEnvironmentSchema | undefined>): DotenvConfigOutput;
103
+ constructor(options?: KernelOptions<TEnvironmentSchema>);
68
104
  private closeCandidate;
69
105
  private getConsumerFromClass;
70
106
  private getInitializerFromClass;
@@ -73,13 +109,13 @@ declare class Kernel {
73
109
  get consumers(): Consumer[];
74
110
  get consumerMiddleware(): ConsumerMiddleware[];
75
111
  get di(): DependencyInjection;
76
- get environment(): NodeJS.ProcessEnv;
112
+ get environment(): KernelEnvironmentForSchema<TEnvironmentSchema>;
77
113
  get logger(): KernelLogger;
78
114
  get routes(): ServiceClass<Route>[];
79
115
  get schedulers(): Scheduler[];
80
116
  private getDependencyInjectionOptions;
81
117
  dependencyInjection(options?: KernelDependencyInjectionOptions): Promise<void>;
82
- loadEnvironmentVariables(environment?: string, options?: KernelEnvironmentVariablesOptions): DotenvConfigOutput;
118
+ loadEnvironmentVariables(environment?: string, options?: KernelEnvironmentVariablesOptions<KernelEnvironmentSchema | undefined>): DotenvConfigOutput;
83
119
  getRoutes(): ServiceClass<Route>[];
84
120
  registerConsumerMiddleware(...middlewares: ConsumerMiddleware[]): void;
85
121
  registerConsumers(...ClassDefinitions: ServiceClass<Consumer>[]): void;
@@ -98,7 +134,7 @@ declare class Kernel {
98
134
  runSchedulers(): Promise<void>;
99
135
  shutdown(): Promise<void>;
100
136
  }
101
- declare function createKernel(options?: KernelOptions): Kernel;
137
+ declare function createKernel<TEnvironmentSchema extends KernelEnvironmentSchema | undefined = undefined>(options?: KernelOptions<TEnvironmentSchema>): Kernel<TEnvironmentSchema>;
102
138
 
103
139
  interface ConsumerExecutionContext {
104
140
  readonly causationId?: string;
@@ -106,7 +142,7 @@ interface ConsumerExecutionContext {
106
142
  readonly eventId: string;
107
143
  readonly eventName: string;
108
144
  readonly exchange: string;
109
- readonly kernel: Kernel;
145
+ readonly kernel: Kernel<KernelEnvironmentSchema | undefined>;
110
146
  readonly metadata: Readonly<Record<string, unknown>>;
111
147
  readonly rawMessage?: unknown;
112
148
  readonly queueName: string;
@@ -120,4 +156,4 @@ interface ConsumerMiddleware {
120
156
 
121
157
  type ShutdownHook = () => Promise<void> | void;
122
158
 
123
- export { Consumer as C, Kernel as K, type ShutdownHook as S, type ConsumerExecutionContext as a, type ConsumerMiddleware as b, type ConsumerNext as c, type KernelDependencyInjectionOptions as d, type KernelEnvironmentVariablesOptions as e, type KernelOptions as f, createKernel as g };
159
+ export { Consumer as C, Kernel as K, type ShutdownHook as S, type ConsumerExecutionContext as a, type ConsumerMiddleware as b, type ConsumerNext as c, type KernelDefaultEnvironment as d, type KernelDependencyInjectionOptions as e, type KernelEnvironment as f, type KernelEnvironmentForSchema as g, type KernelEnvironmentSchema as h, type KernelEnvironmentValue as i, type KernelEnvironmentVariableDefinition as j, type KernelEnvironmentVariablePrimitive as k, type KernelEnvironmentVariableType as l, type KernelEnvironmentVariablesOptions as m, type KernelOptions as n, createKernel as o };
@@ -365,6 +365,14 @@ var DependencyInjection = class _DependencyInjection {
365
365
  }
366
366
  };
367
367
 
368
+ // src/kernel/KernelEnvironmentValidationError.ts
369
+ var KernelEnvironmentValidationError = class extends Error {
370
+ constructor(message) {
371
+ super(message);
372
+ this.name = "KernelEnvironmentValidationError";
373
+ }
374
+ };
375
+
368
376
  // src/Kernel.ts
369
377
  var Kernel = class _Kernel {
370
378
  constructor(options = {}) {
@@ -384,6 +392,7 @@ var Kernel = class _Kernel {
384
392
  schedulersList = [];
385
393
  shutdownHooks = [];
386
394
  dependencyInjectionInstance;
395
+ environmentVariables = process.env;
387
396
  static get state() {
388
397
  const stateContainer = globalThis;
389
398
  stateContainer[_Kernel.stateKey] = stateContainer[_Kernel.stateKey] ?? {};
@@ -428,18 +437,82 @@ var Kernel = class _Kernel {
428
437
  }
429
438
  return _Kernel.state.activeKernel;
430
439
  }
440
+ static assertRequiredEnvironmentVariable(name, value, schema) {
441
+ if (schema[name]?.required === true && value === void 0) {
442
+ throw new KernelEnvironmentValidationError(
443
+ `Missing required environment variable "${name}".`
444
+ );
445
+ }
446
+ }
431
447
  static getEnvironmentVariablesPath(environment, options) {
432
448
  return import_node_path2.default.resolve(
433
449
  _Kernel.rootDirectory,
434
450
  options.path ?? (environment ? `.env.${environment}` : ".env")
435
451
  );
436
452
  }
453
+ static parseBooleanEnvironmentVariable(name, value) {
454
+ if (["1", "true", "yes", "on"].includes(value.toLowerCase())) {
455
+ return true;
456
+ }
457
+ if (["0", "false", "no", "off"].includes(value.toLowerCase())) {
458
+ return false;
459
+ }
460
+ throw new KernelEnvironmentValidationError(
461
+ `Environment variable "${name}" must be a boolean.`
462
+ );
463
+ }
464
+ static parseNumberEnvironmentVariable(name, value) {
465
+ if (value.trim() === "") {
466
+ throw new KernelEnvironmentValidationError(
467
+ `Environment variable "${name}" must be a number.`
468
+ );
469
+ }
470
+ const parsedValue = Number(value);
471
+ if (Number.isFinite(parsedValue)) {
472
+ return parsedValue;
473
+ }
474
+ throw new KernelEnvironmentValidationError(
475
+ `Environment variable "${name}" must be a number.`
476
+ );
477
+ }
478
+ static parseEnvironmentVariable(name, value, schema) {
479
+ const definition = schema[name];
480
+ if (definition.type === "boolean") {
481
+ return _Kernel.parseBooleanEnvironmentVariable(name, value);
482
+ }
483
+ if (definition.type === "number") {
484
+ return _Kernel.parseNumberEnvironmentVariable(name, value);
485
+ }
486
+ return value;
487
+ }
488
+ static validateEnvironmentVariables(schema) {
489
+ const environmentVariables = {};
490
+ for (const [name, definition] of Object.entries(schema)) {
491
+ const value = process.env[name] ?? definition.defaultValue?.toString();
492
+ _Kernel.assertRequiredEnvironmentVariable(name, value, schema);
493
+ if (value !== void 0) {
494
+ environmentVariables[name] = _Kernel.parseEnvironmentVariable(
495
+ name,
496
+ value,
497
+ schema
498
+ );
499
+ }
500
+ }
501
+ return {
502
+ ...process.env,
503
+ ...environmentVariables
504
+ };
505
+ }
437
506
  static loadEnvironmentVariables(environment, options = {}) {
438
507
  const environmentName = environment ?? process.env.NODE_ENV ?? "local";
439
- return import_dotenv.default.config({
508
+ const result = import_dotenv.default.config({
440
509
  override: options.override,
441
510
  path: _Kernel.getEnvironmentVariablesPath(environmentName, options)
442
511
  });
512
+ if (options.schema) {
513
+ _Kernel.validateEnvironmentVariables(options.schema);
514
+ }
515
+ return result;
443
516
  }
444
517
  async closeCandidate(candidate) {
445
518
  if (candidate.shutdown) {
@@ -483,7 +556,7 @@ var Kernel = class _Kernel {
483
556
  return this.dependencyInjectionInstance;
484
557
  }
485
558
  get environment() {
486
- return _Kernel.environment;
559
+ return this.environmentVariables;
487
560
  }
488
561
  get logger() {
489
562
  return this.loggerInstance;
@@ -511,7 +584,12 @@ var Kernel = class _Kernel {
511
584
  _Kernel.state.activeKernel = this;
512
585
  }
513
586
  loadEnvironmentVariables(environment, options = {}) {
514
- return _Kernel.loadEnvironmentVariables(environment, options);
587
+ const result = _Kernel.loadEnvironmentVariables(environment, {
588
+ ...options,
589
+ schema: options.schema ?? this.options.environmentSchema
590
+ });
591
+ this.environmentVariables = this.options.environmentSchema ? _Kernel.validateEnvironmentVariables(this.options.environmentSchema) : process.env;
592
+ return result;
515
593
  }
516
594
  getRoutes() {
517
595
  return this.routes;