@efebia/one-env 1.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/LICENSE +21 -0
- package/README.md +296 -0
- package/bin/one-env +2 -0
- package/lib/cli/commands/generate.d.ts +11 -0
- package/lib/cli/commands/generate.d.ts.map +1 -0
- package/lib/cli/commands/generate.js +57 -0
- package/lib/cli/commands/generate.js.map +1 -0
- package/lib/cli/commands/validate-aws.d.ts +11 -0
- package/lib/cli/commands/validate-aws.d.ts.map +1 -0
- package/lib/cli/commands/validate-aws.js +64 -0
- package/lib/cli/commands/validate-aws.js.map +1 -0
- package/lib/cli/commands/validate.d.ts +7 -0
- package/lib/cli/commands/validate.d.ts.map +1 -0
- package/lib/cli/commands/validate.js +60 -0
- package/lib/cli/commands/validate.js.map +1 -0
- package/lib/cli/env-tool.d.ts +11 -0
- package/lib/cli/env-tool.d.ts.map +1 -0
- package/lib/cli/env-tool.js +60 -0
- package/lib/cli/env-tool.js.map +1 -0
- package/lib/cli/types.d.ts +70 -0
- package/lib/cli/types.d.ts.map +1 -0
- package/lib/cli/types.js +5 -0
- package/lib/cli/types.js.map +1 -0
- package/lib/cli/utils/aws.d.ts +20 -0
- package/lib/cli/utils/aws.d.ts.map +1 -0
- package/lib/cli/utils/aws.js +50 -0
- package/lib/cli/utils/aws.js.map +1 -0
- package/lib/cli/utils/file.d.ts +35 -0
- package/lib/cli/utils/file.d.ts.map +1 -0
- package/lib/cli/utils/file.js +72 -0
- package/lib/cli/utils/file.js.map +1 -0
- package/lib/cli/utils/formatting.d.ts +50 -0
- package/lib/cli/utils/formatting.d.ts.map +1 -0
- package/lib/cli/utils/formatting.js +136 -0
- package/lib/cli/utils/formatting.js.map +1 -0
- package/lib/cli/utils/schema-loader.d.ts +40 -0
- package/lib/cli/utils/schema-loader.d.ts.map +1 -0
- package/lib/cli/utils/schema-loader.js +119 -0
- package/lib/cli/utils/schema-loader.js.map +1 -0
- package/lib/cli/utils/validation.d.ts +40 -0
- package/lib/cli/utils/validation.d.ts.map +1 -0
- package/lib/cli/utils/validation.js +116 -0
- package/lib/cli/utils/validation.js.map +1 -0
- package/lib/env-loader.d.ts +97 -0
- package/lib/env-loader.d.ts.map +1 -0
- package/lib/env-loader.js +199 -0
- package/lib/env-loader.js.map +1 -0
- package/lib/index.d.ts +2 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +3 -0
- package/lib/index.js.map +1 -0
- package/package.json +55 -0
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared type definitions for the environment CLI tool
|
|
3
|
+
*/
|
|
4
|
+
export interface GenerateOptions {
|
|
5
|
+
schema: string;
|
|
6
|
+
output: string;
|
|
7
|
+
force: boolean;
|
|
8
|
+
}
|
|
9
|
+
export interface ValidateOptions {
|
|
10
|
+
schema: string;
|
|
11
|
+
file: string;
|
|
12
|
+
json: boolean;
|
|
13
|
+
}
|
|
14
|
+
export interface ValidateAwsOptions {
|
|
15
|
+
schema: string;
|
|
16
|
+
secretName: string;
|
|
17
|
+
region: string;
|
|
18
|
+
profile?: string;
|
|
19
|
+
json: boolean;
|
|
20
|
+
}
|
|
21
|
+
export interface ValidationResult {
|
|
22
|
+
success: boolean;
|
|
23
|
+
source: string;
|
|
24
|
+
location?: string | undefined;
|
|
25
|
+
validFields: number;
|
|
26
|
+
invalidFields: number;
|
|
27
|
+
missingFields: number;
|
|
28
|
+
allMissingFields: string[];
|
|
29
|
+
data?: any;
|
|
30
|
+
error?: ValidationError | undefined;
|
|
31
|
+
}
|
|
32
|
+
export interface ValidationError {
|
|
33
|
+
formattedIssues: FormattedIssue[];
|
|
34
|
+
}
|
|
35
|
+
export interface FormattedIssue {
|
|
36
|
+
path: string;
|
|
37
|
+
message: string;
|
|
38
|
+
code: string;
|
|
39
|
+
actualValue?: string | undefined;
|
|
40
|
+
expectedType?: string | undefined;
|
|
41
|
+
}
|
|
42
|
+
export interface ValidationStatistics {
|
|
43
|
+
totalFields: number;
|
|
44
|
+
providedFields: number;
|
|
45
|
+
validFields: number;
|
|
46
|
+
invalidFields: number;
|
|
47
|
+
missingFields: number;
|
|
48
|
+
allMissingFields: string[];
|
|
49
|
+
}
|
|
50
|
+
export interface JsonValidationOutput {
|
|
51
|
+
success: boolean;
|
|
52
|
+
source: string;
|
|
53
|
+
location?: string | undefined;
|
|
54
|
+
statistics: {
|
|
55
|
+
totalFields: number;
|
|
56
|
+
validFields: number;
|
|
57
|
+
invalidFields: number;
|
|
58
|
+
missingFields: number;
|
|
59
|
+
};
|
|
60
|
+
errors: FormattedIssue[];
|
|
61
|
+
missingFields: string[];
|
|
62
|
+
}
|
|
63
|
+
export interface JsonErrorOutput {
|
|
64
|
+
success: false;
|
|
65
|
+
error: string;
|
|
66
|
+
type: 'file_error' | 'aws_error' | 'validation_error';
|
|
67
|
+
source?: string | undefined;
|
|
68
|
+
location?: string | undefined;
|
|
69
|
+
}
|
|
70
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/cli/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,MAAM,WAAW,eAAe;IAC5B,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,OAAO,CAAC;CAClB;AAED,MAAM,WAAW,eAAe;IAC5B,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,OAAO,CAAC;CACjB;AAED,MAAM,WAAW,kBAAkB;IAC/B,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,IAAI,EAAE,OAAO,CAAC;CACjB;AAGD,MAAM,WAAW,gBAAgB;IAC7B,OAAO,EAAE,OAAO,CAAC;IACjB,MAAM,EAAE,M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,IAAI,EAAE,YAAY,GAAG,WAAW,GAAG,kBAAkB,CAAC;IACtD,MAAM,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAC5B,QAAQ,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;CACjC"}
|
package/lib/cli/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/cli/types.ts"],"names":[],"mappings":"AAAA;;GAEG"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AWS utilities for the environment CLI tool
|
|
3
|
+
*/
|
|
4
|
+
import { SecretsManagerClient } from '@aws-sdk/client-secrets-manager';
|
|
5
|
+
/**
|
|
6
|
+
* Creates an AWS Secrets Manager client
|
|
7
|
+
* @param region - AWS region
|
|
8
|
+
* @param profile - Optional AWS profile
|
|
9
|
+
* @returns Configured SecretsManagerClient
|
|
10
|
+
*/
|
|
11
|
+
export declare function createSecretsManagerClient(region: string, profile?: string): SecretsManagerClient;
|
|
12
|
+
/**
|
|
13
|
+
* Fetches a secret value from AWS Secrets Manager
|
|
14
|
+
* @param client - SecretsManagerClient instance
|
|
15
|
+
* @param secretName - Name of the secret to fetch
|
|
16
|
+
* @returns Parsed secret data
|
|
17
|
+
* @throws Error if secret not found or has no value
|
|
18
|
+
*/
|
|
19
|
+
export declare function getSecretValue(client: SecretsManagerClient, secretName: string): Promise<any>;
|
|
20
|
+
//# sourceMappingURL=aws.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"aws.d.ts","sourceRoot":"","sources":["../../../src/cli/utils/aws.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,oBAAoB,EAAyB,MAAM,iCAAiC,CAAC;AAE9F;;;;;GAKG;AACH,wBAAgB,0BAA0B,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,oBAAoB,CAWjG;AAED;;;;;;GAMG;AACH,wBAAsB,cAAc,CAAC,MAAM,EAAE,oBAAoB,EAAE,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC,CAsBnG"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AWS utilities for the environment CLI tool
|
|
3
|
+
*/
|
|
4
|
+
import { SecretsManagerClient, GetSecretValueCommand } from '@aws-sdk/client-secrets-manager';
|
|
5
|
+
/**
|
|
6
|
+
* Creates an AWS Secrets Manager client
|
|
7
|
+
* @param region - AWS region
|
|
8
|
+
* @param profile - Optional AWS profile
|
|
9
|
+
* @returns Configured SecretsManagerClient
|
|
10
|
+
*/
|
|
11
|
+
export function createSecretsManagerClient(region, profile) {
|
|
12
|
+
const clientConfig = {
|
|
13
|
+
region: region,
|
|
14
|
+
};
|
|
15
|
+
if (profile) {
|
|
16
|
+
// Set AWS profile environment variable
|
|
17
|
+
process.env.AWS_PROFILE = profile;
|
|
18
|
+
}
|
|
19
|
+
return new SecretsManagerClient(clientConfig);
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Fetches a secret value from AWS Secrets Manager
|
|
23
|
+
* @param client - SecretsManagerClient instance
|
|
24
|
+
* @param secretName - Name of the secret to fetch
|
|
25
|
+
* @returns Parsed secret data
|
|
26
|
+
* @throws Error if secret not found or has no value
|
|
27
|
+
*/
|
|
28
|
+
export async function getSecretValue(client, secretName) {
|
|
29
|
+
try {
|
|
30
|
+
const command = new GetSecretValueCommand({
|
|
31
|
+
SecretId: secretName,
|
|
32
|
+
});
|
|
33
|
+
const response = await client.send(command);
|
|
34
|
+
if (response.SecretString) {
|
|
35
|
+
return JSON.parse(response.SecretString);
|
|
36
|
+
}
|
|
37
|
+
else if (response.SecretBinary) {
|
|
38
|
+
const buff = Buffer.from(response.SecretBinary);
|
|
39
|
+
return JSON.parse(buff.toString('utf-8'));
|
|
40
|
+
}
|
|
41
|
+
throw new Error('Secret has no value');
|
|
42
|
+
}
|
|
43
|
+
catch (error) {
|
|
44
|
+
if (error.name === 'ResourceNotFoundException') {
|
|
45
|
+
throw new Error(`Secret '${secretName}' not found in AWS Secrets Manager`);
|
|
46
|
+
}
|
|
47
|
+
throw error;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
//# sourceMappingURL=aws.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"aws.js","sourceRoot":"","sources":["../../../src/cli/utils/aws.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,oBAAoB,EAAE,qBAAqB,EAAE,MAAM,iCAAiC,CAAC;AAE9F;;;;;GAKG;AACH,MAAM,UAAU,0BAA0B,CAAC,MAAc,EAAE,OAAgB;IACvE,MAAM,YAAY,GAAQ;QACtB,MAAM,EAAE,MAAM;KACjB,CAAC;IAEF,IAAI,OAAO,EAAE,CAAC;QACV,uCAAuC;QACvC,OAAO,CAAC,GAAG,CAAC,WAAW,GAAG,OAAO,CAAC;IACtC,CAAC;IAED,OAAO,IAAI,oBAAoB,CAAC,YAAY,CAAC,CAAC;AAClD,CAAC;AAED;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,cAAc,CAAC,MAA4B,EAAE,UAAkB;IACjF,IAAI,CAAC;QACD,MAAM,OAAO,GAAG,IAAI,qBAAqB,CAAC;YACtC,QAAQ,EAAE,UAAU;SACvB,CAAC,CAAC;QAEH,MAAM,QAAQ,GAAG,MAAM,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QAE5C,IAAI,QAAQ,CAAC,YAAY,EAAE,CAAC;YACxB,OAAO,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,YAAY,CAAC,CAAC;QAC7C,CAAC;aAAM,IAAI,QAAQ,CAAC,YAAY,EAAE,CAAC;YAC/B,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,YAAY,CAAC,CAAC;YAChD,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC;QAC9C,CAAC;QAED,MAAM,IAAI,KAAK,CAAC,qBAAqB,CAAC,CAAC;IAC3C,CAAC;IAAC,OAAO,KAAU,EAAE,CAAC;QAClB,IAAI,KAAK,CAAC,IAAI,KAAK,2BAA2B,EAAE,CAAC;YAC7C,MAAM,IAAI,KAAK,CAAC,WAAW,UAAU,oCAAoC,CAAC,CAAC;QAC/E,CAAC;QACD,MAAM,KAAK,CAAC;IAChB,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* File operations utilities for the environment CLI tool
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Resolves a path relative to the current working directory
|
|
6
|
+
* @param relativePath - The path to resolve
|
|
7
|
+
* @returns Absolute path
|
|
8
|
+
*/
|
|
9
|
+
export declare function resolvePath(relativePath: string): string;
|
|
10
|
+
/**
|
|
11
|
+
* Loads and parses a YAML file
|
|
12
|
+
* @param filePath - Path to the YAML file
|
|
13
|
+
* @returns Parsed YAML content
|
|
14
|
+
* @throws Error if file not found or invalid YAML
|
|
15
|
+
*/
|
|
16
|
+
export declare function loadYamlFile(filePath: string): any;
|
|
17
|
+
/**
|
|
18
|
+
* Writes content to a file
|
|
19
|
+
* @param filePath - Path to write to
|
|
20
|
+
* @param content - Content to write
|
|
21
|
+
*/
|
|
22
|
+
export declare function writeFile(filePath: string, content: string): void;
|
|
23
|
+
/**
|
|
24
|
+
* Checks if a file exists
|
|
25
|
+
* @param filePath - Path to check
|
|
26
|
+
* @returns True if file exists
|
|
27
|
+
*/
|
|
28
|
+
export declare function fileExists(filePath: string): boolean;
|
|
29
|
+
/**
|
|
30
|
+
* Creates YAML content for environment configuration
|
|
31
|
+
* @param envData - Environment configuration data
|
|
32
|
+
* @returns Formatted YAML string
|
|
33
|
+
*/
|
|
34
|
+
export declare function createYamlContent(envData: Record<string, any>): string;
|
|
35
|
+
//# sourceMappingURL=file.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"file.d.ts","sourceRoot":"","sources":["../../../src/cli/utils/file.ts"],"names":[],"mappings":"AAAA;;GAEG;AAMH;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,YAAY,EAAE,MAAM,GAAG,MAAM,CAOxD;AAED;;;;;GAKG;AACH,wBAAgB,YAAY,CAAC,QAAQ,EAAE,MAAM,GAAG,GAAG,CAUlD;AAED;;;;GAIG;AACH,wBAAgB,SAAS,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,IAAI,CAEjE;AAED;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAEpD;AAED;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,MAAM,CAetE"}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* File operations utilities for the environment CLI tool
|
|
3
|
+
*/
|
|
4
|
+
import fs from 'node:fs';
|
|
5
|
+
import path from 'node:path';
|
|
6
|
+
import yaml from 'js-yaml';
|
|
7
|
+
/**
|
|
8
|
+
* Resolves a path relative to the current working directory
|
|
9
|
+
* @param relativePath - The path to resolve
|
|
10
|
+
* @returns Absolute path
|
|
11
|
+
*/
|
|
12
|
+
export function resolvePath(relativePath) {
|
|
13
|
+
if (path.isAbsolute(relativePath)) {
|
|
14
|
+
return relativePath;
|
|
15
|
+
}
|
|
16
|
+
// Resolve relative to current working directory
|
|
17
|
+
return path.resolve(process.cwd(), relativePath);
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Loads and parses a YAML file
|
|
21
|
+
* @param filePath - Path to the YAML file
|
|
22
|
+
* @returns Parsed YAML content
|
|
23
|
+
* @throws Error if file not found or invalid YAML
|
|
24
|
+
*/
|
|
25
|
+
export function loadYamlFile(filePath) {
|
|
26
|
+
try {
|
|
27
|
+
const fileContents = fs.readFileSync(filePath, 'utf8');
|
|
28
|
+
return yaml.load(fileContents);
|
|
29
|
+
}
|
|
30
|
+
catch (error) {
|
|
31
|
+
if (error.code === 'ENOENT') {
|
|
32
|
+
throw new Error(`Environment file '${path.basename(filePath)}' not found`);
|
|
33
|
+
}
|
|
34
|
+
throw new Error(`Failed to read YAML file: ${error.message}`);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Writes content to a file
|
|
39
|
+
* @param filePath - Path to write to
|
|
40
|
+
* @param content - Content to write
|
|
41
|
+
*/
|
|
42
|
+
export function writeFile(filePath, content) {
|
|
43
|
+
fs.writeFileSync(filePath, content, 'utf8');
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Checks if a file exists
|
|
47
|
+
* @param filePath - Path to check
|
|
48
|
+
* @returns True if file exists
|
|
49
|
+
*/
|
|
50
|
+
export function fileExists(filePath) {
|
|
51
|
+
return fs.existsSync(filePath);
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Creates YAML content for environment configuration
|
|
55
|
+
* @param envData - Environment configuration data
|
|
56
|
+
* @returns Formatted YAML string
|
|
57
|
+
*/
|
|
58
|
+
export function createYamlContent(envData) {
|
|
59
|
+
// Use js-yaml to properly format the data
|
|
60
|
+
const yamlContent = yaml.dump(envData, {
|
|
61
|
+
indent: 2,
|
|
62
|
+
lineWidth: 120,
|
|
63
|
+
sortKeys: false, // Preserve the order from schema
|
|
64
|
+
quotingType: '"',
|
|
65
|
+
forceQuotes: false,
|
|
66
|
+
noRefs: true
|
|
67
|
+
});
|
|
68
|
+
// Add header comment
|
|
69
|
+
const header = '# Environment Configuration File\n# Generated from schema defaults - customize as needed\n\n';
|
|
70
|
+
return header + yamlContent;
|
|
71
|
+
}
|
|
72
|
+
//# sourceMappingURL=file.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"file.js","sourceRoot":"","s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AAC,OAA4B;IAC1D,0CAA0C;IAC1C,MAAM,WAAW,GAAG,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE;QACnC,MAAM,EAAE,CAAC;QACT,SAAS,EAAE,GAAG;QACd,QAAQ,EAAE,KAAK,EAAE,iCAAiC;QAClD,WAAW,EAAE,GAAG;QAChB,WAAW,EAAE,KAAK;QAClB,MAAM,EAAE,IAAI;KACf,CAAC,CAAC;IAEH,qBAAqB;IACrB,MAAM,MAAM,GAAG,8FAA8F,CAAC;IAE9G,OAAO,MAAM,GAAG,WAAW,CAAC;AAChC,CAAC"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Output formatting utilities for the environment CLI tool
|
|
3
|
+
*/
|
|
4
|
+
import { ValidationResult, JsonValidationOutput, JsonErrorOutput } from '../types.js';
|
|
5
|
+
/**
|
|
6
|
+
* Prints validation results in human-readable format
|
|
7
|
+
* @param results - Validation results to print
|
|
8
|
+
*/
|
|
9
|
+
export declare function printValidationResults(results: ValidationResult): void;
|
|
10
|
+
/**
|
|
11
|
+
* Formats validation results as JSON
|
|
12
|
+
* @param results - Validation results
|
|
13
|
+
* @returns JSON output object
|
|
14
|
+
*/
|
|
15
|
+
export declare function formatJsonOutput(results: ValidationResult): JsonValidationOutput;
|
|
16
|
+
/**
|
|
17
|
+
* Formats an error as JSON
|
|
18
|
+
* @param error - Error object
|
|
19
|
+
* @param type - Type of error
|
|
20
|
+
* @param source - Optional source identifier
|
|
21
|
+
* @param location - Optional location
|
|
22
|
+
* @returns JSON error output
|
|
23
|
+
*/
|
|
24
|
+
export declare function formatJsonError(error: Error, type: 'file_error' | 'aws_error' | 'validation_error', source?: string, location?: string): JsonErrorOutput;
|
|
25
|
+
/**
|
|
26
|
+
* Prints a status message with color
|
|
27
|
+
* @param message - Message to print
|
|
28
|
+
* @param type - Type of message (info, success, warning, error)
|
|
29
|
+
*/
|
|
30
|
+
export declare function printStatus(message: string, type?: 'info' | 'success' | 'warning' | 'error'): void;
|
|
31
|
+
/**
|
|
32
|
+
* Prints an error message with formatting
|
|
33
|
+
* @param error - Error object
|
|
34
|
+
* @param tips - Optional tips to help resolve the error
|
|
35
|
+
*/
|
|
36
|
+
export declare function printError(error: Error, tips?: string[]): void;
|
|
37
|
+
/**
|
|
38
|
+
* Prints success message with additional info
|
|
39
|
+
* @param action - Action that succeeded
|
|
40
|
+
* @param details - Additional details to show
|
|
41
|
+
*/
|
|
42
|
+
export declare function printSuccess(action: string, details: Record<string, string | number>): void;
|
|
43
|
+
/**
|
|
44
|
+
* Formats field count for display
|
|
45
|
+
* @param count - Number to format
|
|
46
|
+
* @param label - Label for the count
|
|
47
|
+
* @returns Formatted string
|
|
48
|
+
*/
|
|
49
|
+
export declare function formatFieldCount(count: number, label: string): string;
|
|
50
|
+
//# sourceMappingURL=formatting.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"formatting.d.ts","sourceRoot":"","sources":["../../../src/cli/utils/formatting.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,OAAO,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAEtF;;;GAGG;AACH,wBAAgB,sBAAsB,CAAC,OAAO,EAAE,gBAAgB,GAAG,IAAI,CAiDtE;AAED;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,gBAAgB,GAAG,oBAAoB,CAchF;AAED;;;;;;;GAOG;AACH,wBAAgB,eAAe,CAC3B,KAAK,EAAE,KAAK,EACZ,IAAI,EAAE,YAAY,GAAG,WAAW,GAAG,kBAAkB,EACrD,MAAM,CAAC,EAAE,MAAM,EACf,QAAQ,CAAC,EAAE,MAAM,GAClB,eAAe,CAQjB;AAED;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,GAAE,MAAM,GAAG,SAAS,GAAG,SAAS,GAAG,OAAgB,GAAG,IAAI,CAS1G;AAED;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,KAAK,EAAE,IAAI,CAAC,EAAE,MAAM,EAAE,GAAG,IAAI,CAQ9D;AAED;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC,GAAG,IAAI,CAM3F;AAED;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAErE"}
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Output formatting utilities for the environment CLI tool
|
|
3
|
+
*/
|
|
4
|
+
import chalk from 'chalk';
|
|
5
|
+
/**
|
|
6
|
+
* Prints validation results in human-readable format
|
|
7
|
+
* @param results - Validation results to print
|
|
8
|
+
*/
|
|
9
|
+
export function printValidationResults(results) {
|
|
10
|
+
const { success, source, location, validFields, invalidFields, missingFields, allMissingFields, error } = results;
|
|
11
|
+
// Header
|
|
12
|
+
console.log('\n' + chalk.bold('='.repeat(60)));
|
|
13
|
+
if (success) {
|
|
14
|
+
console.log(chalk.green.bold('✓ VALID'));
|
|
15
|
+
console.log(`All environment variables are valid!`);
|
|
16
|
+
console.log(`${chalk.bold('Source:')} ${source}`);
|
|
17
|
+
if (location) {
|
|
18
|
+
console.log(`${chalk.bold('Location:')} ${location}`);
|
|
19
|
+
}
|
|
20
|
+
console.log(`${chalk.bold('Total fields validated:')} ${validFields}`);
|
|
21
|
+
}
|
|
22
|
+
else {
|
|
23
|
+
console.log(chalk.red.bold('✗ INVALID'));
|
|
24
|
+
console.log(`Environment validation failed for '${source}'${location ? ` in ${location}` : ''}`);
|
|
25
|
+
console.log(`\n${chalk.bold('Summary:')}`);
|
|
26
|
+
console.log(` ${chalk.green('✓ Valid fields:')} ${validFields}`);
|
|
27
|
+
console.log(` ${chalk.red('✗ Invalid fields:')} ${invalidFields}`);
|
|
28
|
+
console.log(` ${chalk.yellow('⚠ Missing fields:')} ${missingFields}`);
|
|
29
|
+
if (error && error.formattedIssues) {
|
|
30
|
+
// Filter out issues for missing fields (they'll be shown in the Missing Fields section)
|
|
31
|
+
const nonMissingIssues = error.formattedIssues.filter(issue => !allMissingFields.includes(issue.path));
|
|
32
|
+
if (nonMissingIssues.length > 0) {
|
|
33
|
+
console.log(`\n${chalk.bold('Validation Errors:')}`);
|
|
34
|
+
nonMissingIssues.forEach(issue => {
|
|
35
|
+
const field = issue.path || 'root';
|
|
36
|
+
console.log(` ${chalk.red('✗')} ${chalk.cyan(field)}: ${issue.message}`);
|
|
37
|
+
if (issue.actualValue !== undefined) {
|
|
38
|
+
console.log(` ${chalk.yellow('Actual value:')} ${issue.actualValue}`);
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
if (allMissingFields && allMissingFields.length > 0) {
|
|
44
|
+
console.log(`\n${chalk.bold('Missing Required Fields:')}`);
|
|
45
|
+
allMissingFields.forEach(field => {
|
|
46
|
+
console.log(` ${chalk.yellow('⚠')} ${chalk.cyan(field)}`);
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
console.log('\n' + chalk.bold('='.repeat(60)) + '\n');
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Formats validation results as JSON
|
|
54
|
+
* @param results - Validation results
|
|
55
|
+
* @returns JSON output object
|
|
56
|
+
*/
|
|
57
|
+
export function formatJsonOutput(results) {
|
|
58
|
+
return {
|
|
59
|
+
success: results.success,
|
|
60
|
+
source: results.source,
|
|
61
|
+
location: results.location,
|
|
62
|
+
statistics: {
|
|
63
|
+
totalFields: results.validFields + results.invalidFields + results.missingFields,
|
|
64
|
+
validFields: results.validFields,
|
|
65
|
+
invalidFields: results.invalidFields,
|
|
66
|
+
missingFields: results.missingFields,
|
|
67
|
+
},
|
|
68
|
+
errors: results.error ? results.error.formattedIssues : [],
|
|
69
|
+
missingFields: results.allMissingFields,
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Formats an error as JSON
|
|
74
|
+
* @param error - Error object
|
|
75
|
+
* @param type - Type of error
|
|
76
|
+
* @param source - Optional source identifier
|
|
77
|
+
* @param location - Optional location
|
|
78
|
+
* @returns JSON error output
|
|
79
|
+
*/
|
|
80
|
+
export function formatJsonError(error, type, source, location) {
|
|
81
|
+
return {
|
|
82
|
+
success: false,
|
|
83
|
+
error: error.message,
|
|
84
|
+
type,
|
|
85
|
+
source,
|
|
86
|
+
location,
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Prints a status message with color
|
|
91
|
+
* @param message - Message to print
|
|
92
|
+
* @param type - Type of message (info, success, warning, error)
|
|
93
|
+
*/
|
|
94
|
+
export function printStatus(message, type = 'info') {
|
|
95
|
+
const colors = {
|
|
96
|
+
info: chalk.cyan,
|
|
97
|
+
success: chalk.green,
|
|
98
|
+
warning: chalk.yellow,
|
|
99
|
+
error: chalk.red,
|
|
100
|
+
};
|
|
101
|
+
console.log(colors[type](message));
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Prints an error message with formatting
|
|
105
|
+
* @param error - Error object
|
|
106
|
+
* @param tips - Optional tips to help resolve the error
|
|
107
|
+
*/
|
|
108
|
+
export function printError(error, tips) {
|
|
109
|
+
console.error(`\n${chalk.red.bold('Error:')} ${error.message}\n`);
|
|
110
|
+
if (tips && tips.length > 0) {
|
|
111
|
+
tips.forEach(tip => {
|
|
112
|
+
console.log(`${chalk.yellow('Tip:')} ${tip}`);
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Prints success message with additional info
|
|
118
|
+
* @param action - Action that succeeded
|
|
119
|
+
* @param details - Additional details to show
|
|
120
|
+
*/
|
|
121
|
+
export function printSuccess(action, details) {
|
|
122
|
+
console.log(`\n${chalk.green('✓ Successfully ' + action)}`);
|
|
123
|
+
Object.entries(details).forEach(([key, value]) => {
|
|
124
|
+
console.log(`${chalk.bold(key + ':')} ${value}`);
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Formats field count for display
|
|
129
|
+
* @param count - Number to format
|
|
130
|
+
* @param label - Label for the count
|
|
131
|
+
* @returns Formatted string
|
|
132
|
+
*/
|
|
133
|
+
export function formatFieldCount(count, label) {
|
|
134
|
+
return `${chalk.bold(label + ':')} ${count}`;
|
|
135
|
+
}
|
|
136
|
+
//# sourceMappingURL=formatting.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"formatting.js","sourceRoot":"","sources":["../../../src/cli/utils/formatting.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,MAAM,OAAO,CAAC;AAG1B;;;GAGG;AACH,MAAM,UAAU,sBAAsB,CAAC,OAAyB;IAC5D,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,WAAW,EAAE,aAAa,EAAE,aAAa,EAAE,gBAAgB,EAAE,KAAK,EAAE,GAAG,OAAO,CAAC;IAElH,SAAS;IACT,OAAO,CAAC,GAAG,CAAC,IAAI,GAAG,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;IAE/C,IAAI,OAAO,EAAE,CAAC;QACV,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC;QACzC,OAAO,CAAC,GAAG,CAAC,sCAAsC,CAAC,CAAC;QACpD,OAAO,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,MAAM,EAAE,CAAC,CAAC;QAClD,IAAI,QAAQ,EAAE,CAAC;YACX,OAAO,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC,IAAI,CAAC,WAAW,C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AG,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,GAAG,EAAE,CAAC,CAAC;QAClD,CAAC,CAAC,CAAC;IACP,CAAC;AACL,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,YAAY,CAAC,MAAc,EAAE,OAAwC;IACjF,OAAO,CAAC,GAAG,CAAC,KAAK,KAAK,CAAC,KAAK,CAAC,iBAAiB,GAAG,MAAM,CAAC,EAAE,CAAC,CAAC;IAE5D,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,EAAE,EAAE;QAC7C,OAAO,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC,IAAI,KAAK,EAAE,CAAC,CAAC;IACrD,CAAC,CAAC,CAAC;AACP,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,gBAAgB,CAAC,KAAa,EAAE,KAAa;IACzD,OAAO,GAAG,KAAK,CAAC,IAAI,CAAC,KAAK,GAAG,GAAG,CAAC,IAAI,KAAK,EAAE,CAAC;AACjD,CAAC"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Dynamic schema loader utility
|
|
3
|
+
* Loads Zod schemas from TypeScript or JavaScript files at runtime
|
|
4
|
+
*/
|
|
5
|
+
import { z } from 'zod/v4';
|
|
6
|
+
/**
|
|
7
|
+
* Dynamically loads a Zod schema from a file
|
|
8
|
+
* @param schemaPath - Path to the schema file
|
|
9
|
+
* @returns The loaded Zod schema
|
|
10
|
+
*/
|
|
11
|
+
export declare function loadSchema(schemaPath: string): Promise<z.ZodSchema<any>>;
|
|
12
|
+
/**
|
|
13
|
+
* Extracts field information from a Zod schema
|
|
14
|
+
* @param schema - Zod schema to analyze
|
|
15
|
+
* @returns Object with field metadata
|
|
16
|
+
*/
|
|
17
|
+
export declare function analyzeSchema(schema: z.ZodSchema<any>): {
|
|
18
|
+
fields: Record<string, {
|
|
19
|
+
optional: boolean;
|
|
20
|
+
hasDefault: boolean;
|
|
21
|
+
defaultValue?: any;
|
|
22
|
+
description?: string;
|
|
23
|
+
}>;
|
|
24
|
+
totalFields: number;
|
|
25
|
+
requiredFields: string[];
|
|
26
|
+
optionalFields: string[];
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
* Generates default values from a Zod schema
|
|
30
|
+
* @param schema - Zod schema with defaults
|
|
31
|
+
* @returns Object with default values
|
|
32
|
+
*/
|
|
33
|
+
export declare function extractSchemaDefaults(schema: z.ZodSchema<any>): Record<string, any>;
|
|
34
|
+
/**
|
|
35
|
+
* Formats schema path for display
|
|
36
|
+
* @param schemaPath - Path to schema file
|
|
37
|
+
* @returns Formatted string
|
|
38
|
+
*/
|
|
39
|
+
export declare function formatSchemaSource(schemaPath: string): string;
|
|
40
|
+
//# sourceMappingURL=schema-loader.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema-loader.d.ts","sourceRoot":"","sources":["../../../src/cli/utils/schema-loader.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,OAAO,EAAE,CAAC,EAAE,MAAM,QAAQ,CAAC;AAI3B;;;;GAIG;AACH,wBAAsB,UAAU,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,CAAC,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,CAwC9E;AAWD;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,MAAM,EAAE,CAAC,CAAC,SAAS,CAAC,GAAG,CAAC,GAAG;IACrD,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE;QACnB,QAAQ,EAAE,OAAO,CAAC;QAClB,UAAU,EAAE,OAAO,CAAC;QACpB,YAAY,CAAC,EAAE,GAAG,CAAC;QACnB,WAAW,CAAC,EAAE,MAAM,CAAC;KACxB,CAAC,CAAC;IACH,WAAW,EAAE,MAAM,CAAC;IACpB,cAAc,EAAE,MAAM,EAAE,CAAC;IACzB,cAAc,EAAE,MAAM,EAAE,CAAC;CAC5B,CAgCA;AAED;;;;GAIG;AACH,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,CAAC,CAAC,SAAS,CAAC,GAAG,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAiBnF;AAED;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,UAAU,EAAE,MAAM,GAAG,MAAM,CAE7D"}
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Dynamic schema loader utility
|
|
3
|
+
* Loads Zod schemas from TypeScript or JavaScript files at runtime
|
|
4
|
+
*/
|
|
5
|
+
import { pathToFileURL } from 'node:url';
|
|
6
|
+
import { resolve } from 'node:path';
|
|
7
|
+
import { existsSync } from 'node:fs';
|
|
8
|
+
import chalk from 'chalk';
|
|
9
|
+
/**
|
|
10
|
+
* Dynamically loads a Zod schema from a file
|
|
11
|
+
* @param schemaPath - Path to the schema file
|
|
12
|
+
* @returns The loaded Zod schema
|
|
13
|
+
*/
|
|
14
|
+
export async function loadSchema(schemaPath) {
|
|
15
|
+
const absolutePath = resolve(process.cwd(), schemaPath);
|
|
16
|
+
if (!existsSync(absolutePath)) {
|
|
17
|
+
throw new Error(`Schema file not found: ${schemaPath}`);
|
|
18
|
+
}
|
|
19
|
+
try {
|
|
20
|
+
// Convert to file URL for proper ESM import
|
|
21
|
+
const fileUrl = pathToFileURL(absolutePath).href;
|
|
22
|
+
// Dynamically import the schema file
|
|
23
|
+
const schemaModule = await import(fileUrl);
|
|
24
|
+
// Always use default export
|
|
25
|
+
const schema = schemaModule.default;
|
|
26
|
+
if (!schema) {
|
|
27
|
+
throw new Error(`No default export found in ${schemaPath}.\n` +
|
|
28
|
+
`The schema file must export the schema as default: export default EnvSchema`);
|
|
29
|
+
}
|
|
30
|
+
// Verify it's a Zod schema
|
|
31
|
+
if (!isZodSchema(schema)) {
|
|
32
|
+
throw new Error(`Default export is not a valid Zod schema`);
|
|
33
|
+
}
|
|
34
|
+
return schema;
|
|
35
|
+
}
|
|
36
|
+
catch (error) {
|
|
37
|
+
if (error.code === 'ERR_MODULE_NOT_FOUND' || error.code === 'MODULE_NOT_FOUND') {
|
|
38
|
+
throw new Error(`Failed to load schema from ${schemaPath}.\n` +
|
|
39
|
+
`Make sure the file is compiled if it's TypeScript.\n` +
|
|
40
|
+
`Error: ${error.message}`);
|
|
41
|
+
}
|
|
42
|
+
throw error;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Checks if an object is a Zod schema
|
|
47
|
+
* @param obj - Object to check
|
|
48
|
+
* @returns True if it's a Zod schema
|
|
49
|
+
*/
|
|
50
|
+
function isZodSchema(obj) {
|
|
51
|
+
return obj && typeof obj === 'object' && '_def' in obj && typeof obj.parse === 'function';
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Extracts field information from a Zod schema
|
|
55
|
+
* @param schema - Zod schema to analyze
|
|
56
|
+
* @returns Object with field metadata
|
|
57
|
+
*/
|
|
58
|
+
export function analyzeSchema(schema) {
|
|
59
|
+
const shape = schema.shape || {};
|
|
60
|
+
const fields = {};
|
|
61
|
+
const requiredFields = [];
|
|
62
|
+
const optionalFields = [];
|
|
63
|
+
for (const [key, fieldSchema] of Object.entries(shape)) {
|
|
64
|
+
const def = fieldSchema._def;
|
|
65
|
+
const isOptional = def?.typeName === 'ZodOptional' || def?.typeName === 'ZodNullable';
|
|
66
|
+
const hasDefault = def?.defaultValue !== undefined;
|
|
67
|
+
const description = def?.description;
|
|
68
|
+
fields[key] = {
|
|
69
|
+
optional: isOptional,
|
|
70
|
+
hasDefault,
|
|
71
|
+
defaultValue: hasDefault ? def.defaultValue : undefined,
|
|
72
|
+
description
|
|
73
|
+
};
|
|
74
|
+
if (isOptional) {
|
|
75
|
+
optionalFields.push(key);
|
|
76
|
+
}
|
|
77
|
+
else {
|
|
78
|
+
requiredFields.push(key);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
return {
|
|
82
|
+
fields,
|
|
83
|
+
totalFields: Object.keys(fields).length,
|
|
84
|
+
requiredFields,
|
|
85
|
+
optionalFields
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Generates default values from a Zod schema
|
|
90
|
+
* @param schema - Zod schema with defaults
|
|
91
|
+
* @returns Object with default values
|
|
92
|
+
*/
|
|
93
|
+
export function extractSchemaDefaults(schema) {
|
|
94
|
+
const analysis = analyzeSchema(schema);
|
|
95
|
+
const defaults = {};
|
|
96
|
+
// Try to parse an empty object to get defaults
|
|
97
|
+
try {
|
|
98
|
+
const parsed = schema.parse({});
|
|
99
|
+
return parsed;
|
|
100
|
+
}
|
|
101
|
+
catch {
|
|
102
|
+
// If that fails, extract defaults manually
|
|
103
|
+
for (const [key, fieldInfo] of Object.entries(analysis.fields)) {
|
|
104
|
+
if (fieldInfo.hasDefault) {
|
|
105
|
+
defaults[key] = fieldInfo.defaultValue;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
return defaults;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Formats schema path for display
|
|
113
|
+
* @param schemaPath - Path to schema file
|
|
114
|
+
* @returns Formatted string
|
|
115
|
+
*/
|
|
116
|
+
export function formatSchemaSource(schemaPath) {
|
|
117
|
+
return chalk.cyan(schemaPath);
|
|
118
|
+
}
|
|
119
|
+
//# sourceMappingURL=schema-loader.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema-loader.js","sourceRoot":"","sources":["../../../src/cli/utils/schema-loader.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEpC,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B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