@xlameiro/env-typegen 0.1.2 → 0.1.3
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/CHANGELOG.md +6 -0
- package/README.md +82 -1
- package/dist/cli.js +1241 -57
- package/dist/cli.js.map +1 -1
- package/dist/index.cjs +1513 -32
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +537 -1
- package/dist/index.d.ts +537 -1
- package/dist/index.js +1501 -33
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -28,6 +28,20 @@ type ParsedEnvVar = {
|
|
|
28
28
|
group?: string;
|
|
29
29
|
/** 1-based line number of the KEY=VALUE line in the source file */
|
|
30
30
|
lineNumber: number;
|
|
31
|
+
/** Allowed literal values from a `@enum` annotation (e.g. `["development", "staging", "production"]`). */
|
|
32
|
+
enumValues?: string[];
|
|
33
|
+
/** Numeric range constraints from `@min` / `@max` annotations. */
|
|
34
|
+
constraints?: {
|
|
35
|
+
min?: number;
|
|
36
|
+
max?: number;
|
|
37
|
+
};
|
|
38
|
+
/** Runtime scope from a `@runtime` annotation (`server` | `client` | `edge`). */
|
|
39
|
+
runtime?: "server" | "client" | "edge";
|
|
40
|
+
/**
|
|
41
|
+
* When true, the variable's value must never appear in reports or generated
|
|
42
|
+
* output — declared via a `@secret` annotation.
|
|
43
|
+
*/
|
|
44
|
+
isSecret?: boolean;
|
|
31
45
|
};
|
|
32
46
|
/**
|
|
33
47
|
* The complete result of parsing a single .env.example file.
|
|
@@ -61,6 +75,17 @@ type CommentAnnotations = {
|
|
|
61
75
|
description?: string;
|
|
62
76
|
/** true when the `@required` annotation is present in the comment block */
|
|
63
77
|
isRequired: boolean;
|
|
78
|
+
/** Allowed literal values from a `@enum` annotation (comma-separated list) */
|
|
79
|
+
enumValues?: string[];
|
|
80
|
+
/** Numeric range constraints from `@min` and/or `@max` annotations */
|
|
81
|
+
constraints?: {
|
|
82
|
+
min?: number;
|
|
83
|
+
max?: number;
|
|
84
|
+
};
|
|
85
|
+
/** Runtime scope from a `@runtime` annotation (`server` | `client` | `edge`) */
|
|
86
|
+
runtime?: "server" | "client" | "edge";
|
|
87
|
+
/** true when the `@secret` annotation is present — value must never appear in reports */
|
|
88
|
+
isSecret?: boolean;
|
|
64
89
|
};
|
|
65
90
|
/**
|
|
66
91
|
* Parse a block of consecutive comment lines (each starting with `#`) and
|
|
@@ -71,6 +96,11 @@ type CommentAnnotations = {
|
|
|
71
96
|
* - `@required` — marks the variable as required regardless of value
|
|
72
97
|
* - `@optional` — informational (isRequired stays false)
|
|
73
98
|
* - `@type <EnvVarType>` — overrides the inferred type
|
|
99
|
+
* - `@enum val1,val2,...` — declares allowed literal values (comma-separated)
|
|
100
|
+
* - `@min <number>` — declares a numeric minimum constraint
|
|
101
|
+
* - `@max <number>` — declares a numeric maximum constraint
|
|
102
|
+
* - `@runtime <scope>` — declares runtime scope: `server` | `client` | `edge`
|
|
103
|
+
* - `@secret` — marks the value as sensitive (never logged or reported)
|
|
74
104
|
*
|
|
75
105
|
* Non-annotation comment lines act as a fallback description when no
|
|
76
106
|
* `@description` annotation is present (first non-empty line wins).
|
|
@@ -235,6 +265,337 @@ declare function generateDeclaration(parsed: ParsedEnvFile): string;
|
|
|
235
265
|
*/
|
|
236
266
|
declare function generateT3Env(parsed: ParsedEnvFile): string;
|
|
237
267
|
|
|
268
|
+
/**
|
|
269
|
+
* Machine-readable CI contract types for env-typegen V1 JSON output.
|
|
270
|
+
*
|
|
271
|
+
* Stable JSON schema emitted by `env-typegen check --json` and consumed by
|
|
272
|
+
* CI pipelines, dashboards, and automation tools.
|
|
273
|
+
*
|
|
274
|
+
* Property order on {@link CiReport} is intentional and stable:
|
|
275
|
+
* `schemaVersion` → `status` → `summary` → `issues` → `meta`
|
|
276
|
+
*
|
|
277
|
+
* @module
|
|
278
|
+
*/
|
|
279
|
+
/**
|
|
280
|
+
* Stable machine-readable issue category code.
|
|
281
|
+
* Used in {@link Issue.code} to enable programmatic filtering and alerting.
|
|
282
|
+
*
|
|
283
|
+
* - `ENV_MISSING` — a required variable is absent from the env file
|
|
284
|
+
* - `ENV_EXTRA` — a variable exists in the env file but not in the contract
|
|
285
|
+
* - `ENV_INVALID_TYPE` — the value cannot be coerced to the declared type
|
|
286
|
+
* - `ENV_INVALID_VALUE` — the value fails a constraint (enum, min, max)
|
|
287
|
+
* - `ENV_CONFLICT` — the variable has inconsistent values across environments
|
|
288
|
+
* - `ENV_SECRET_EXPOSED` — a secret variable has a non-empty value in a public file
|
|
289
|
+
*
|
|
290
|
+
* @public
|
|
291
|
+
*/
|
|
292
|
+
type IssueCode$1 = "ENV_MISSING" | "ENV_EXTRA" | "ENV_INVALID_TYPE" | "ENV_INVALID_VALUE" | "ENV_CONFLICT" | "ENV_SECRET_EXPOSED";
|
|
293
|
+
/**
|
|
294
|
+
* The expected shape of an environment variable, expressed as a discriminated
|
|
295
|
+
* union on `type`. Used in {@link Issue.expected} to communicate the declared
|
|
296
|
+
* expectation when a validation failure occurs.
|
|
297
|
+
*
|
|
298
|
+
* @public
|
|
299
|
+
*/
|
|
300
|
+
type Expected$1 = {
|
|
301
|
+
type: "string";
|
|
302
|
+
} | {
|
|
303
|
+
type: "number";
|
|
304
|
+
min?: number;
|
|
305
|
+
max?: number;
|
|
306
|
+
} | {
|
|
307
|
+
type: "boolean";
|
|
308
|
+
} | {
|
|
309
|
+
type: "enum";
|
|
310
|
+
values: string[];
|
|
311
|
+
} | {
|
|
312
|
+
type: "url";
|
|
313
|
+
} | {
|
|
314
|
+
type: "email";
|
|
315
|
+
} | {
|
|
316
|
+
type: "json";
|
|
317
|
+
} | {
|
|
318
|
+
type: "semver";
|
|
319
|
+
} | {
|
|
320
|
+
type: "unknown";
|
|
321
|
+
};
|
|
322
|
+
/**
|
|
323
|
+
* Deployment environment against which a check was run.
|
|
324
|
+
*
|
|
325
|
+
* @public
|
|
326
|
+
*/
|
|
327
|
+
type Environment = "local" | "example" | "production" | "preview" | "test" | "cloud";
|
|
328
|
+
/**
|
|
329
|
+
* Whether a validation issue is blocking (`error`) or advisory (`warning`).
|
|
330
|
+
*
|
|
331
|
+
* @public
|
|
332
|
+
*/
|
|
333
|
+
type IssueSeverity$1 = "error" | "warning";
|
|
334
|
+
/**
|
|
335
|
+
* Overall check result: `"ok"` when no errors; `"fail"` when at least one
|
|
336
|
+
* error-severity issue exists.
|
|
337
|
+
*
|
|
338
|
+
* @public
|
|
339
|
+
*/
|
|
340
|
+
type ReportStatus = "ok" | "fail";
|
|
341
|
+
/**
|
|
342
|
+
* A single validation issue found during `env-typegen check`.
|
|
343
|
+
*
|
|
344
|
+
* @public
|
|
345
|
+
*/
|
|
346
|
+
type Issue = {
|
|
347
|
+
/** Stable machine-readable category code. Use this for programmatic filtering. */
|
|
348
|
+
code: IssueCode$1;
|
|
349
|
+
/** Human-readable description of the issue category (maps 1-to-1 with `code`). */
|
|
350
|
+
type: string;
|
|
351
|
+
/** The environment variable key that caused the issue. */
|
|
352
|
+
key: string;
|
|
353
|
+
/** What the contract declared was expected for this variable. */
|
|
354
|
+
expected: Expected$1;
|
|
355
|
+
/** The raw received value when applicable and not a secret. Absent otherwise. */
|
|
356
|
+
received?: string;
|
|
357
|
+
/** The environment context where this issue was detected. */
|
|
358
|
+
environment: Environment;
|
|
359
|
+
/** Whether this issue blocks deployment (`error`) or is advisory (`warning`). */
|
|
360
|
+
severity: IssueSeverity$1;
|
|
361
|
+
/**
|
|
362
|
+
* Always `null` in V1 JSON output.
|
|
363
|
+
*
|
|
364
|
+
* Prevents accidental secret exposure in machine-readable reports stored in
|
|
365
|
+
* CI artefacts, logs, or dashboards. Use `--debug-values` for human-readable
|
|
366
|
+
* output that shows the actual value for non-secret variables.
|
|
367
|
+
*/
|
|
368
|
+
value: null;
|
|
369
|
+
};
|
|
370
|
+
/**
|
|
371
|
+
* Top-level V1 JSON report emitted by `env-typegen check --json`.
|
|
372
|
+
*
|
|
373
|
+
* The property order is stable and intentional:
|
|
374
|
+
* `schemaVersion` → `status` → `summary` → `issues` → `meta`
|
|
375
|
+
*
|
|
376
|
+
* When `schemaVersion` is incremented, it indicates a breaking change to this
|
|
377
|
+
* type shape. Consumers should guard on `schemaVersion === 1` before reading.
|
|
378
|
+
*
|
|
379
|
+
* @public
|
|
380
|
+
*/
|
|
381
|
+
type CiReport = {
|
|
382
|
+
/** Integer schema version. Incremented on breaking changes to this type shape. */
|
|
383
|
+
schemaVersion: 1;
|
|
384
|
+
/** `"ok"` when no errors were found; `"fail"` when at least one error-severity issue exists. */
|
|
385
|
+
status: ReportStatus;
|
|
386
|
+
/** Issue counts by severity. */
|
|
387
|
+
summary: {
|
|
388
|
+
errors: number;
|
|
389
|
+
warnings: number;
|
|
390
|
+
};
|
|
391
|
+
/** All issues found during the check, in source order. */
|
|
392
|
+
issues: Issue[];
|
|
393
|
+
/** Execution context: which env file was checked and when. */
|
|
394
|
+
meta: {
|
|
395
|
+
env: string;
|
|
396
|
+
timestamp: string;
|
|
397
|
+
};
|
|
398
|
+
};
|
|
399
|
+
|
|
400
|
+
/**
|
|
401
|
+
* Runtime scope for an environment variable.
|
|
402
|
+
* Controls which part of the application has access to the variable.
|
|
403
|
+
*
|
|
404
|
+
* - `"server"` — accessible only in server-side code (Node.js process)
|
|
405
|
+
* - `"client"` — accessible in browser code (must be safe to expose publicly)
|
|
406
|
+
* - `"edge"` — accessible in Edge runtime (limited Node.js API surface)
|
|
407
|
+
*
|
|
408
|
+
* @public
|
|
409
|
+
*/
|
|
410
|
+
type EnvVarRuntime = "server" | "client" | "edge";
|
|
411
|
+
/**
|
|
412
|
+
* A single entry in the env contract: the canonical, authoritative declaration
|
|
413
|
+
* for one environment variable.
|
|
414
|
+
*
|
|
415
|
+
* In contract-first mode (`schemaMode: "contract-first"`) this is the source of
|
|
416
|
+
* truth. The inference engine acts only as a fallback when no contract entry
|
|
417
|
+
* exists for a given variable.
|
|
418
|
+
*
|
|
419
|
+
* @public
|
|
420
|
+
*/
|
|
421
|
+
type EnvContractEntry = {
|
|
422
|
+
/** The environment variable name as it appears in the env file (e.g. `DATABASE_URL`). */
|
|
423
|
+
name: string;
|
|
424
|
+
/** The expected TypeScript type for this variable's runtime value. */
|
|
425
|
+
expectedType: EnvVarType;
|
|
426
|
+
/** Whether this variable must be present. Overrides inference-based required detection. */
|
|
427
|
+
required: boolean;
|
|
428
|
+
/** Static default value used when the variable is absent from the env file. */
|
|
429
|
+
default?: string;
|
|
430
|
+
/** Allowed literal values for `enum`-typed variables (e.g. `["development", "staging", "production"]`). */
|
|
431
|
+
enumValues?: string[];
|
|
432
|
+
/** Numeric range constraints for `number`-typed variables. */
|
|
433
|
+
constraints?: {
|
|
434
|
+
min?: number;
|
|
435
|
+
max?: number;
|
|
436
|
+
};
|
|
437
|
+
/** Which runtime this variable is available to. Used to enforce NEXT_PUBLIC_ boundaries. */
|
|
438
|
+
runtime?: EnvVarRuntime;
|
|
439
|
+
/**
|
|
440
|
+
* When true, the variable's value is never included in reports, logs, or
|
|
441
|
+
* generated type file comments — it is treated as a secret.
|
|
442
|
+
*/
|
|
443
|
+
isSecret?: boolean;
|
|
444
|
+
/** Human-readable description used in documentation generation and error messages. */
|
|
445
|
+
description?: string;
|
|
446
|
+
};
|
|
447
|
+
/**
|
|
448
|
+
* The full environment contract — a collection of all declared variables
|
|
449
|
+
* and their expected shape.
|
|
450
|
+
*
|
|
451
|
+
* Used as the source of truth in contract-first mode (`schemaMode: "contract-first"`).
|
|
452
|
+
* Create a contract file at `env.contract.ts` and define this with {@link defineContract}
|
|
453
|
+
* from the schema loader for type safety.
|
|
454
|
+
*
|
|
455
|
+
* @public
|
|
456
|
+
*/
|
|
457
|
+
type EnvContract$1 = {
|
|
458
|
+
/** All declared environment variable contracts, in declaration order. */
|
|
459
|
+
vars: EnvContractEntry[];
|
|
460
|
+
};
|
|
461
|
+
|
|
462
|
+
/**
|
|
463
|
+
* Contract file names searched in order when calling {@link loadContract}.
|
|
464
|
+
* Mirrors the search strategy used by `loadConfig` in `config.ts`.
|
|
465
|
+
*/
|
|
466
|
+
declare const CONTRACT_FILE_NAMES: readonly ["env.contract.ts", "env.contract.mjs", "env.contract.js"];
|
|
467
|
+
/**
|
|
468
|
+
* Type-safe contract factory. Returns the contract object unchanged — exists
|
|
469
|
+
* purely for IDE autocompletion and compile-time validation of the contract shape.
|
|
470
|
+
*
|
|
471
|
+
* Use this in your `env.contract.ts` file:
|
|
472
|
+
*
|
|
473
|
+
* @example
|
|
474
|
+
* ```ts
|
|
475
|
+
* // env.contract.ts
|
|
476
|
+
* import { defineContract } from "@xlameiro/env-typegen";
|
|
477
|
+
*
|
|
478
|
+
* export default defineContract({
|
|
479
|
+
* vars: [
|
|
480
|
+
* { name: "DATABASE_URL", expectedType: "url", required: true, isSecret: true },
|
|
481
|
+
* { name: "PORT", expectedType: "number", required: false, default: "3000" },
|
|
482
|
+
* {
|
|
483
|
+
* name: "NODE_ENV",
|
|
484
|
+
* expectedType: "string",
|
|
485
|
+
* required: true,
|
|
486
|
+
* enumValues: ["development", "staging", "production"],
|
|
487
|
+
* },
|
|
488
|
+
* ],
|
|
489
|
+
* });
|
|
490
|
+
* ```
|
|
491
|
+
*
|
|
492
|
+
* @public
|
|
493
|
+
*/
|
|
494
|
+
declare function defineContract(contract: EnvContract$1): EnvContract$1;
|
|
495
|
+
/**
|
|
496
|
+
* Loads an env contract by searching for a contract file starting from `cwd`.
|
|
497
|
+
*
|
|
498
|
+
* Search order: `env.contract.ts` → `env.contract.mjs` → `env.contract.js`
|
|
499
|
+
*
|
|
500
|
+
* Returns `undefined` when no contract file is found. The contract file must
|
|
501
|
+
* use a default export of an {@link EnvContract} object, typically produced
|
|
502
|
+
* by {@link defineContract}.
|
|
503
|
+
*
|
|
504
|
+
* @param cwd - Directory to start searching from. Defaults to `process.cwd()`.
|
|
505
|
+
*
|
|
506
|
+
* @public
|
|
507
|
+
*/
|
|
508
|
+
declare function loadContract(cwd?: string): Promise<EnvContract$1 | undefined>;
|
|
509
|
+
|
|
510
|
+
type Expected = {
|
|
511
|
+
type: "string";
|
|
512
|
+
} | {
|
|
513
|
+
type: "number";
|
|
514
|
+
min?: number;
|
|
515
|
+
max?: number;
|
|
516
|
+
} | {
|
|
517
|
+
type: "boolean";
|
|
518
|
+
} | {
|
|
519
|
+
type: "enum";
|
|
520
|
+
values: string[];
|
|
521
|
+
} | {
|
|
522
|
+
type: "url";
|
|
523
|
+
} | {
|
|
524
|
+
type: "email";
|
|
525
|
+
} | {
|
|
526
|
+
type: "json";
|
|
527
|
+
} | {
|
|
528
|
+
type: "semver";
|
|
529
|
+
} | {
|
|
530
|
+
type: "unknown";
|
|
531
|
+
};
|
|
532
|
+
type EnvContractVariable = {
|
|
533
|
+
expected: Expected;
|
|
534
|
+
required: boolean;
|
|
535
|
+
clientSide: boolean;
|
|
536
|
+
description?: string;
|
|
537
|
+
secret?: boolean;
|
|
538
|
+
};
|
|
539
|
+
type EnvContract = {
|
|
540
|
+
schemaVersion: 1;
|
|
541
|
+
variables: Record<string, EnvContractVariable>;
|
|
542
|
+
};
|
|
543
|
+
type IssueCode = "ENV_MISSING" | "ENV_EXTRA" | "ENV_INVALID_TYPE" | "ENV_INVALID_VALUE" | "ENV_CONFLICT" | "ENV_SECRET_EXPOSED";
|
|
544
|
+
type IssueType = "missing" | "extra" | "invalid_type" | "invalid_value" | "conflict" | "secret_exposed";
|
|
545
|
+
type IssueSeverity = "error" | "warning";
|
|
546
|
+
type ValidationIssue$1 = {
|
|
547
|
+
code: IssueCode;
|
|
548
|
+
type: IssueType;
|
|
549
|
+
severity: IssueSeverity;
|
|
550
|
+
key: string;
|
|
551
|
+
environment: string;
|
|
552
|
+
message: string;
|
|
553
|
+
expected?: Expected;
|
|
554
|
+
receivedType?: string;
|
|
555
|
+
value: string | null;
|
|
556
|
+
};
|
|
557
|
+
type ValidationSummary = {
|
|
558
|
+
errors: number;
|
|
559
|
+
warnings: number;
|
|
560
|
+
total: number;
|
|
561
|
+
};
|
|
562
|
+
type ValidationStatus = "ok" | "fail";
|
|
563
|
+
type ValidationMeta = {
|
|
564
|
+
env: string;
|
|
565
|
+
timestamp: string;
|
|
566
|
+
};
|
|
567
|
+
type ValidationReport = {
|
|
568
|
+
schemaVersion: 1;
|
|
569
|
+
status: ValidationStatus;
|
|
570
|
+
summary: ValidationSummary;
|
|
571
|
+
issues: ValidationIssue$1[];
|
|
572
|
+
meta: ValidationMeta;
|
|
573
|
+
recommendations?: string[];
|
|
574
|
+
};
|
|
575
|
+
|
|
576
|
+
type EnvTypegenPlugin = {
|
|
577
|
+
name: string;
|
|
578
|
+
transformContract?: (contract: EnvContract) => EnvContract;
|
|
579
|
+
transformSource?: (input: {
|
|
580
|
+
environment: string;
|
|
581
|
+
values: Record<string, string>;
|
|
582
|
+
}) => Record<string, string>;
|
|
583
|
+
transformReport?: (report: ValidationReport) => ValidationReport;
|
|
584
|
+
};
|
|
585
|
+
type PluginReference = string | EnvTypegenPlugin;
|
|
586
|
+
type LoadPluginsOptions = {
|
|
587
|
+
pluginPaths: string[];
|
|
588
|
+
configPlugins?: PluginReference[];
|
|
589
|
+
cwd?: string;
|
|
590
|
+
};
|
|
591
|
+
declare function loadPlugins(options: LoadPluginsOptions): Promise<EnvTypegenPlugin[]>;
|
|
592
|
+
declare function applyContractPlugins(contract: EnvContract, plugins: readonly EnvTypegenPlugin[]): EnvContract;
|
|
593
|
+
declare function applySourcePlugins(params: {
|
|
594
|
+
environment: string;
|
|
595
|
+
values: Record<string, string>;
|
|
596
|
+
}, plugins: readonly EnvTypegenPlugin[]): Record<string, string>;
|
|
597
|
+
declare function applyReportPlugins(report: ValidationReport, plugins: readonly EnvTypegenPlugin[]): ValidationReport;
|
|
598
|
+
|
|
238
599
|
/** Generator identifiers supported by env-typegen. */
|
|
239
600
|
type GeneratorName = "typescript" | "zod" | "t3" | "declaration";
|
|
240
601
|
/** Configuration shape accepted by env-typegen's CLI and programmatic API. */
|
|
@@ -252,6 +613,27 @@ type EnvTypegenConfig = {
|
|
|
252
613
|
* Rules are matched in ascending priority order; lower numbers win.
|
|
253
614
|
*/
|
|
254
615
|
inferenceRules?: InferenceRule[];
|
|
616
|
+
/**
|
|
617
|
+
* Path to the contract file (`env.contract.ts`).
|
|
618
|
+
* When provided, the contract is the authoritative source of type information.
|
|
619
|
+
* Relative to the config file directory or `process.cwd()`.
|
|
620
|
+
*/
|
|
621
|
+
schemaFile?: string;
|
|
622
|
+
/**
|
|
623
|
+
* When `true`, variables absent from the contract emit errors rather than warnings.
|
|
624
|
+
* Defaults to `true`.
|
|
625
|
+
*/
|
|
626
|
+
strict?: boolean;
|
|
627
|
+
/**
|
|
628
|
+
* Resolution strategy for type information.
|
|
629
|
+
* - `"legacy"` (default): inference-first; annotations override inferred types.
|
|
630
|
+
* - `"contract-first"`: contract is authoritative; inference is a fallback only.
|
|
631
|
+
*/
|
|
632
|
+
schemaMode?: "legacy" | "contract-first";
|
|
633
|
+
/** Default target files for `env-typegen diff` when --targets is omitted. */
|
|
634
|
+
diffTargets?: string[];
|
|
635
|
+
/** Plugin references (module paths or plugin objects). */
|
|
636
|
+
plugins?: PluginReference[];
|
|
255
637
|
};
|
|
256
638
|
/**
|
|
257
639
|
* Type-safe config helper.
|
|
@@ -286,4 +668,158 @@ type RunGenerateOptions = {
|
|
|
286
668
|
*/
|
|
287
669
|
declare function runGenerate(options: RunGenerateOptions): Promise<void>;
|
|
288
670
|
|
|
289
|
-
|
|
671
|
+
/**
|
|
672
|
+
* Options controlling how `validateContract` handles edge cases.
|
|
673
|
+
*
|
|
674
|
+
* @internal
|
|
675
|
+
*/
|
|
676
|
+
type ValidateContractOptions = {
|
|
677
|
+
/**
|
|
678
|
+
* The deployment environment under validation.
|
|
679
|
+
* Defaults to `"local"` when not specified.
|
|
680
|
+
*/
|
|
681
|
+
environment?: Environment;
|
|
682
|
+
/**
|
|
683
|
+
* When true, variables not declared in the contract are treated as errors
|
|
684
|
+
* instead of warnings. Matches the `strict` option in `EnvTypegenConfig`.
|
|
685
|
+
*
|
|
686
|
+
* Defaults to `true` (strict by default in V1).
|
|
687
|
+
*/
|
|
688
|
+
strict?: boolean;
|
|
689
|
+
};
|
|
690
|
+
/**
|
|
691
|
+
* A single found validation issue, as produced by the validator engine.
|
|
692
|
+
* Used internally before being converted to a {@link CiReport} via the reporter.
|
|
693
|
+
*
|
|
694
|
+
* @internal
|
|
695
|
+
*/
|
|
696
|
+
type ValidationIssue = {
|
|
697
|
+
code: IssueCode$1;
|
|
698
|
+
key: string;
|
|
699
|
+
expected: Expected$1;
|
|
700
|
+
received?: string;
|
|
701
|
+
environment: Environment;
|
|
702
|
+
severity: IssueSeverity$1;
|
|
703
|
+
};
|
|
704
|
+
/**
|
|
705
|
+
* The full result of running `validateContract` against a parsed env file.
|
|
706
|
+
*
|
|
707
|
+
* @internal
|
|
708
|
+
*/
|
|
709
|
+
type ValidationResult = {
|
|
710
|
+
issues: ValidationIssue[];
|
|
711
|
+
};
|
|
712
|
+
|
|
713
|
+
/**
|
|
714
|
+
* Validate a parsed env file against a contract definition.
|
|
715
|
+
*
|
|
716
|
+
* Produces a {@link ValidationResult} containing all discovered issues.
|
|
717
|
+
* Does not throw — every problem becomes a typed {@link ValidationIssue}.
|
|
718
|
+
*
|
|
719
|
+
* Issue codes checked:
|
|
720
|
+
* - `ENV_MISSING` — required contract var absent from env file
|
|
721
|
+
* - `ENV_EXTRA` — env file var not declared in contract
|
|
722
|
+
* - `ENV_INVALID_TYPE` — value cannot be coerced to declared type
|
|
723
|
+
* - `ENV_INVALID_VALUE` — enum or min/max constraint violated
|
|
724
|
+
* - `ENV_SECRET_EXPOSED` — secret var has non-empty value in env file
|
|
725
|
+
*
|
|
726
|
+
* Note: `ENV_CONFLICT` is not emitted in V1 (requires multi-file comparison
|
|
727
|
+
* which belongs to the `diff` command, Phase 4).
|
|
728
|
+
*
|
|
729
|
+
* @param parsed — result of `parseEnvFile` for the env file under check
|
|
730
|
+
* @param contract — the authoritative contract to validate against
|
|
731
|
+
* @param opts — optional check configuration (environment, strict mode)
|
|
732
|
+
* @returns — `{ issues: ValidationIssue[] }` — empty when all checks pass
|
|
733
|
+
*
|
|
734
|
+
* @public
|
|
735
|
+
*/
|
|
736
|
+
declare function validateContract(parsed: ParsedEnvFile, contract: EnvContract$1, opts?: ValidateContractOptions): ValidationResult;
|
|
737
|
+
|
|
738
|
+
/**
|
|
739
|
+
* Build and format the V1 JSON report for `env-typegen check --json`.
|
|
740
|
+
*
|
|
741
|
+
* @module
|
|
742
|
+
*/
|
|
743
|
+
|
|
744
|
+
/**
|
|
745
|
+
* Options for {@link formatCiReport}.
|
|
746
|
+
*
|
|
747
|
+
* @public
|
|
748
|
+
*/
|
|
749
|
+
type FormatCiReportOptions = {
|
|
750
|
+
/** When `true`, the output is pretty-printed with 2-space indentation. */
|
|
751
|
+
pretty?: boolean;
|
|
752
|
+
};
|
|
753
|
+
/**
|
|
754
|
+
* Convert a {@link ValidationResult} into a stable V1 {@link CiReport}.
|
|
755
|
+
*
|
|
756
|
+
* The returned object's property order is canonical:
|
|
757
|
+
* `schemaVersion` → `status` → `summary` → `issues` → `meta`
|
|
758
|
+
*
|
|
759
|
+
* @public
|
|
760
|
+
*/
|
|
761
|
+
declare function buildCiReport(result: ValidationResult, meta: {
|
|
762
|
+
env: string;
|
|
763
|
+
timestamp: string;
|
|
764
|
+
}): CiReport;
|
|
765
|
+
/**
|
|
766
|
+
* Serialise a {@link CiReport} to JSON.
|
|
767
|
+
*
|
|
768
|
+
* @param report The report produced by {@link buildCiReport}.
|
|
769
|
+
* @param opts Optional formatting options.
|
|
770
|
+
* @returns JSON string. Compact by default; pretty-printed when `opts.pretty === true`.
|
|
771
|
+
*
|
|
772
|
+
* @public
|
|
773
|
+
*/
|
|
774
|
+
declare function formatCiReport(report: CiReport, opts?: FormatCiReportOptions): string;
|
|
775
|
+
|
|
776
|
+
/**
|
|
777
|
+
* Options for {@link runCheck}.
|
|
778
|
+
*
|
|
779
|
+
* @public
|
|
780
|
+
*/
|
|
781
|
+
type RunCheckOptions = {
|
|
782
|
+
/** Path to the env file to validate (e.g. `.env.local`). */
|
|
783
|
+
input: string;
|
|
784
|
+
/** Explicit path to the contract file. Relative to `cwd` when set. */
|
|
785
|
+
contract?: string;
|
|
786
|
+
/** Working directory for contract auto-discovery. Defaults to `process.cwd()`. */
|
|
787
|
+
cwd?: string;
|
|
788
|
+
/** Environment label attached to validation issues. */
|
|
789
|
+
environment?: Environment;
|
|
790
|
+
/**
|
|
791
|
+
* When `true` (default), undeclared variables are treated as errors.
|
|
792
|
+
* When `false`, they become warnings.
|
|
793
|
+
*/
|
|
794
|
+
strict?: boolean;
|
|
795
|
+
/** Emit machine-readable JSON to stdout instead of human-readable lines. */
|
|
796
|
+
json?: boolean;
|
|
797
|
+
/** Pretty-print the JSON output when `json: true`. */
|
|
798
|
+
pretty?: boolean;
|
|
799
|
+
/** Suppress all output (status is still returned). */
|
|
800
|
+
silent?: boolean;
|
|
801
|
+
};
|
|
802
|
+
/**
|
|
803
|
+
* Programmatic entry point for the `env-typegen check` command.
|
|
804
|
+
*
|
|
805
|
+
* Loads the contract, parses the env file, runs validation, and outputs results.
|
|
806
|
+
* Returns `"ok"` when there are no errors, `"fail"` when there are.
|
|
807
|
+
*
|
|
808
|
+
* @public
|
|
809
|
+
*/
|
|
810
|
+
declare function runCheck(opts: RunCheckOptions): Promise<ReportStatus>;
|
|
811
|
+
|
|
812
|
+
type ValidationCommand = "check" | "diff" | "doctor";
|
|
813
|
+
declare function runValidationCommand(params: {
|
|
814
|
+
command: ValidationCommand;
|
|
815
|
+
argv: string[];
|
|
816
|
+
}): Promise<number>;
|
|
817
|
+
|
|
818
|
+
type CloudProvider = "vercel" | "cloudflare" | "aws";
|
|
819
|
+
type CloudConnectorLoadOptions = {
|
|
820
|
+
provider: CloudProvider;
|
|
821
|
+
filePath: string;
|
|
822
|
+
};
|
|
823
|
+
declare function loadCloudSource(options: CloudConnectorLoadOptions): Promise<Record<string, string>>;
|
|
824
|
+
|
|
825
|
+
export { CONTRACT_FILE_NAMES, type CiReport, type CloudProvider, type CommentAnnotations, type EnvContract$1 as EnvContract, type EnvContractEntry, type EnvTypegenConfig, type EnvTypegenPlugin, type EnvVarRuntime, type EnvVarType, type Environment, type Expected$1 as Expected, type FormatCiReportOptions, type GeneratorName, type InferenceRule, type Issue, type IssueCode$1 as IssueCode, type IssueSeverity$1 as IssueSeverity, type ParsedEnvFile, type ParsedEnvVar, type PluginReference, type ReportStatus, type RunCheckOptions, type RunGenerateOptions, type ValidateContractOptions, type ValidationIssue, type ValidationResult, applyContractPlugins, applyReportPlugins, applySourcePlugins, buildCiReport, defineConfig, defineContract, formatCiReport, generateDeclaration, generateEnvValidation, generateT3Env, generateTypeScriptTypes, generateZodSchema, inferType, inferTypesFromParsedVars as inferTypes, inferenceRules, loadCloudSource, loadConfig, loadContract, loadPlugins, parseCommentBlock, parseEnvFile, parseEnvFileContent, runCheck, runGenerate, runValidationCommand, validateContract };
|