@config-bound/schema-export 0.1.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/.turbo/turbo-build.log +4 -0
- package/.turbo/turbo-format$colon$ci.log +6 -0
- package/.turbo/turbo-lint$colon$ci.log +4 -0
- package/.turbo/turbo-test.log +12 -0
- package/CHANGELOG.md +14 -0
- package/README.md +59 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -0
- package/dist/schemaExporter.d.ts +48 -0
- package/dist/schemaExporter.d.ts.map +1 -0
- package/dist/schemaExporter.js +66 -0
- package/dist/schemaExporter.js.map +1 -0
- package/dist/schemaExporter.spec.d.ts +2 -0
- package/dist/schemaExporter.spec.d.ts.map +1 -0
- package/dist/schemaExporter.spec.js +124 -0
- package/dist/schemaExporter.spec.js.map +1 -0
- package/dist/schemaFormatters.d.ts +22 -0
- package/dist/schemaFormatters.d.ts.map +1 -0
- package/dist/schemaFormatters.js +99 -0
- package/dist/schemaFormatters.js.map +1 -0
- package/dist/schemaFormatters.spec.d.ts +2 -0
- package/dist/schemaFormatters.spec.d.ts.map +1 -0
- package/dist/schemaFormatters.spec.js +161 -0
- package/dist/schemaFormatters.spec.js.map +1 -0
- package/eslint.config.mjs +3 -0
- package/jest.config.js +26 -0
- package/package.json +58 -0
- package/src/index.ts +14 -0
- package/src/schemaExporter.spec.ts +286 -0
- package/src/schemaExporter.ts +119 -0
- package/src/schemaFormatters.spec.ts +188 -0
- package/src/schemaFormatters.ts +124 -0
- package/tsconfig.json +12 -0
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
|
|
2
|
+
> @config-bound/schema-export@0.1.0 test
|
|
3
|
+
> jest
|
|
4
|
+
|
|
5
|
+
PASS src/schemaFormatters.spec.ts (8.823 s)
|
|
6
|
+
PASS src/schemaExporter.spec.ts (9.94 s)
|
|
7
|
+
|
|
8
|
+
Test Suites: 2 passed, 2 total
|
|
9
|
+
Tests: 23 passed, 23 total
|
|
10
|
+
Snapshots: 0 total
|
|
11
|
+
Time: 11.528 s
|
|
12
|
+
Ran all test suites.
|
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
# @config-bound/schema-export
|
|
2
|
+
|
|
3
|
+
## 0.1.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 3c2cf21: Add a CLI to export and interact with configuration schemas
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- Updated dependencies [de1dc3b]
|
|
12
|
+
- Updated dependencies [3c2cf21]
|
|
13
|
+
- Updated dependencies [dca5c72]
|
|
14
|
+
- @config-bound/config-bound@0.1.0
|
package/README.md
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
# @config-bound/schema-export
|
|
2
|
+
|
|
3
|
+
Schema export utilities for ConfigBound configuration library.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @config-bound/schema-export
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
```typescript
|
|
14
|
+
import { ConfigBound } from '@config-bound/config-bound';
|
|
15
|
+
import {
|
|
16
|
+
exportSchema,
|
|
17
|
+
formatAsJSON,
|
|
18
|
+
formatAsYAML,
|
|
19
|
+
formatAsEnvExample
|
|
20
|
+
} from '@config-bound/schema-export';
|
|
21
|
+
|
|
22
|
+
const config = ConfigBound.createConfig({
|
|
23
|
+
// ... your config schema
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
// Export schema as structured object
|
|
27
|
+
const schema = exportSchema(config.name, config.sections);
|
|
28
|
+
|
|
29
|
+
// Export as JSON
|
|
30
|
+
const json = formatAsJSON(schema);
|
|
31
|
+
|
|
32
|
+
// Export as YAML
|
|
33
|
+
const yaml = formatAsYAML(schema);
|
|
34
|
+
|
|
35
|
+
// Export as .env.example file
|
|
36
|
+
const envExample = formatAsEnvExample(schema, 'MYAPP');
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
## API
|
|
40
|
+
|
|
41
|
+
### `exportSchema(name: string, sections: Section[], includeOmitted?: boolean)`
|
|
42
|
+
|
|
43
|
+
Exports the configuration schema as a structured JavaScript object.
|
|
44
|
+
|
|
45
|
+
### `formatAsJSON(schema: ExportedSchema, pretty?: boolean)`
|
|
46
|
+
|
|
47
|
+
Formats the schema as a JSON string. Defaults to pretty-printed format.
|
|
48
|
+
|
|
49
|
+
### `formatAsYAML(schema: ExportedSchema)`
|
|
50
|
+
|
|
51
|
+
Formats the schema as a YAML string.
|
|
52
|
+
|
|
53
|
+
### `formatAsEnvExample(schema: ExportedSchema, prefix?: string)`
|
|
54
|
+
|
|
55
|
+
Formats the schema as a `.env.example` file. The optional `prefix` parameter adds a prefix to all environment variable names (e.g., `'MYAPP'` will generate `MYAPP_SECTION_ELEMENT`).
|
|
56
|
+
|
|
57
|
+
## License
|
|
58
|
+
|
|
59
|
+
MIT
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,aAAa,EACb,aAAa,EACb,YAAY,EACZ,KAAK,eAAe,EACpB,KAAK,eAAe,EACpB,KAAK,cAAc,EACpB,MAAM,qBAAqB,CAAC;AAE7B,OAAO,EACL,YAAY,EACZ,YAAY,EACZ,kBAAkB,EACnB,MAAM,uBAAuB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,aAAa,EACb,aAAa,EACb,YAAY,EAIb,MAAM,qBAAqB,CAAC;AAE7B,OAAO,EACL,YAAY,EACZ,YAAY,EACZ,kBAAkB,EACnB,MAAM,uBAAuB,CAAC"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { Section } from '@config-bound/config-bound/section';
|
|
2
|
+
import { Element } from '@config-bound/config-bound/element';
|
|
3
|
+
/**
|
|
4
|
+
* Represents a single configuration element in the exported schema
|
|
5
|
+
*/
|
|
6
|
+
export interface ExportedElement {
|
|
7
|
+
name: string;
|
|
8
|
+
description?: string;
|
|
9
|
+
type: string;
|
|
10
|
+
default?: unknown;
|
|
11
|
+
example?: unknown;
|
|
12
|
+
required: boolean;
|
|
13
|
+
sensitive: boolean;
|
|
14
|
+
joiValidation: unknown;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Represents a configuration section in the exported schema
|
|
18
|
+
*/
|
|
19
|
+
export interface ExportedSection {
|
|
20
|
+
name: string;
|
|
21
|
+
description?: string;
|
|
22
|
+
elements: ExportedElement[];
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* The complete exported configuration schema
|
|
26
|
+
*/
|
|
27
|
+
export interface ExportedSchema {
|
|
28
|
+
name: string;
|
|
29
|
+
sections: ExportedSection[];
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Exports an Element to the external schema format
|
|
33
|
+
*/
|
|
34
|
+
export declare function exportElement(element: Element<unknown>): ExportedElement;
|
|
35
|
+
/**
|
|
36
|
+
* Exports a Section to the external schema format
|
|
37
|
+
* @param section - The section to export
|
|
38
|
+
* @param includeOmitted - Whether to include elements marked with omitFromSchema (default: false)
|
|
39
|
+
*/
|
|
40
|
+
export declare function exportSection(section: Section, includeOmitted?: boolean): ExportedSection;
|
|
41
|
+
/**
|
|
42
|
+
* Exports the complete schema to a structured format
|
|
43
|
+
* @param name - The name of the configuration
|
|
44
|
+
* @param sections - Array of sections to export
|
|
45
|
+
* @param includeOmitted - Whether to include elements marked with omitFromSchema (default: false)
|
|
46
|
+
*/
|
|
47
|
+
export declare function exportSchema(name: string, sections: Section[], includeOmitted?: boolean): ExportedSchema;
|
|
48
|
+
//# sourceMappingURL=schemaExporter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schemaExporter.d.ts","sourceRoot":"","sources":["../src/schemaExporter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,oCAAoC,CAAC;AAC7D,OAAO,EAAE,OAAO,EAAE,MAAM,oCAAoC,CAAC;AAG7D;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,QAAQ,EAAE,OAAO,CAAC;IAClB,SAAS,EAAE,OAAO,CAAC;IACnB,aAAa,EAAE,OAAO,CAAC;CACxB;AAED;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,QAAQ,EAAE,eAAe,EAAE,CAAC;CAC7B;AAED;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,eAAe,EAAE,CAAC;CAC7B;AAiCD;;GAEG;AACH,wBAAgB,aAAa,CAAC,OAAO,EAAE,OAAO,CAAC,OAAO,CAAC,GAAG,eAAe,CAWxE;AAED;;;;GAIG;AACH,wBAAgB,aAAa,CAC3B,OAAO,EAAE,OAAO,EAChB,cAAc,GAAE,OAAe,GAC9B,eAAe,CAWjB;AAED;;;;;GAKG;AACH,wBAAgB,YAAY,CAC1B,IAAI,EAAE,MAAM,EACZ,QAAQ,EAAE,OAAO,EAAE,EACnB,cAAc,GAAE,OAAe,GAC9B,cAAc,CAKhB"}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Extracts type information from a Joi schema
|
|
3
|
+
*/
|
|
4
|
+
function extractJoiType(validator) {
|
|
5
|
+
const describe = validator.describe();
|
|
6
|
+
if (describe.type === 'alternatives') {
|
|
7
|
+
const types = describe.matches?.map((m) => m.schema?.type || 'unknown') || [];
|
|
8
|
+
return types.join(' | ') || 'any';
|
|
9
|
+
}
|
|
10
|
+
if (describe.type === 'string' && describe.allow) {
|
|
11
|
+
const allowed = describe.allow;
|
|
12
|
+
if (Array.isArray(allowed) && allowed.length > 0) {
|
|
13
|
+
return allowed.map((v) => `'${v}'`).join(' | ');
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
return describe.type || 'unknown';
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Extracts the raw Joi object from a schema
|
|
20
|
+
*/
|
|
21
|
+
function extractJoiValidation(validator) {
|
|
22
|
+
return validator.describe();
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Exports an Element to the external schema format
|
|
26
|
+
*/
|
|
27
|
+
export function exportElement(element) {
|
|
28
|
+
return {
|
|
29
|
+
name: element.name,
|
|
30
|
+
description: element.description,
|
|
31
|
+
type: extractJoiType(element.validator),
|
|
32
|
+
default: element.default,
|
|
33
|
+
example: element.example,
|
|
34
|
+
required: element.isRequired(),
|
|
35
|
+
sensitive: element.sensitive,
|
|
36
|
+
joiValidation: extractJoiValidation(element.validator)
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Exports a Section to the external schema format
|
|
41
|
+
* @param section - The section to export
|
|
42
|
+
* @param includeOmitted - Whether to include elements marked with omitFromSchema (default: false)
|
|
43
|
+
*/
|
|
44
|
+
export function exportSection(section, includeOmitted = false) {
|
|
45
|
+
return {
|
|
46
|
+
name: section.name,
|
|
47
|
+
description: section.description,
|
|
48
|
+
elements: section
|
|
49
|
+
.getElements()
|
|
50
|
+
.filter((element) => includeOmitted || !element.omitFromSchema)
|
|
51
|
+
.map(exportElement)
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Exports the complete schema to a structured format
|
|
56
|
+
* @param name - The name of the configuration
|
|
57
|
+
* @param sections - Array of sections to export
|
|
58
|
+
* @param includeOmitted - Whether to include elements marked with omitFromSchema (default: false)
|
|
59
|
+
*/
|
|
60
|
+
export function exportSchema(name, sections, includeOmitted = false) {
|
|
61
|
+
return {
|
|
62
|
+
name,
|
|
63
|
+
sections: sections.map((section) => exportSection(section, includeOmitted))
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
//# sourceMappingURL=schemaExporter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schemaExporter.js","sourceRoot":"","sources":["../src/schemaExporter.ts"],"names":[],"mappings":"AAmCA;;GAEG;AACH,SAAS,cAAc,CAAC,SAAwB;IAC9C,MAAM,QAAQ,GAAG,SAAS,CAAC,QAAQ,EAAE,CAAC;IAEtC,IAAI,QAAQ,CAAC,IAAI,KAAK,cAAc,EAAE,CAAC;QACrC,MAAM,KAAK,GACT,QAAQ,CAAC,OAAO,EAAE,GAAG,CACnB,CAAC,CAAkB,EAAE,EAAE,CAAC,CAAC,CAAC,MAAM,EAAE,IAAI,IAAI,SAAS,CACpD,IAAI,EAAE,CAAC;QACV,OAAO,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,KAAK,CAAC;IACpC,CAAC;IAED,IAAI,QAAQ,CAAC,IAAI,KAAK,QAAQ,IAAI,QAAQ,CAAC,KAAK,EAAE,CAAC;QACjD,MAAM,OAAO,GAAG,QAAQ,CAAC,KAAK,CAAC;QAC/B,IAAI,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,OAAO,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YACjD,OAAO,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QAClD,CAAC;IACH,CAAC;IAED,OAAO,QAAQ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":"","sources":["../src/schemaExporter.spec.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import { Section } from '@config-bound/config-bound/section';
|
|
2
|
+
import { Element } from '@config-bound/config-bound/element';
|
|
3
|
+
import Joi from 'joi';
|
|
4
|
+
import { exportElement, exportSection, exportSchema } from './schemaExporter.js';
|
|
5
|
+
describe('Schema Exporter', () => {
|
|
6
|
+
describe('exportElement', () => {
|
|
7
|
+
it('should export a basic element', () => {
|
|
8
|
+
const element = new Element('testElement', 'A test element', 'default-value', 'example-value', false, false, Joi.string());
|
|
9
|
+
const exported = exportElement(element);
|
|
10
|
+
expect(exported.name).toBe('testElement');
|
|
11
|
+
expect(exported.description).toBe('A test element');
|
|
12
|
+
expect(exported.type).toBe('string');
|
|
13
|
+
expect(exported.default).toBe('default-value');
|
|
14
|
+
expect(exported.example).toBe('example-value');
|
|
15
|
+
expect(exported.required).toBe(false);
|
|
16
|
+
expect(exported.sensitive).toBe(false);
|
|
17
|
+
});
|
|
18
|
+
it('should handle required elements', () => {
|
|
19
|
+
const element = new Element('requiredElement', 'A required element', undefined, 42, false, false, Joi.number().required());
|
|
20
|
+
const exported = exportElement(element);
|
|
21
|
+
expect(exported.required).toBe(true);
|
|
22
|
+
});
|
|
23
|
+
it('should handle sensitive elements', () => {
|
|
24
|
+
const element = new Element('secretKey', 'API secret key', undefined, 'sk_test_123', true, false, Joi.string());
|
|
25
|
+
const exported = exportElement(element);
|
|
26
|
+
expect(exported.sensitive).toBe(true);
|
|
27
|
+
});
|
|
28
|
+
it('should handle elements with omitFromSchema', () => {
|
|
29
|
+
const element = new Element('privateKey', 'Private configuration key', 'default', 'example', false, true, Joi.string());
|
|
30
|
+
expect(element.omitFromSchema).toBe(true);
|
|
31
|
+
});
|
|
32
|
+
it('should extract joi validation object', () => {
|
|
33
|
+
const element = new Element('port', 'Server port', 3000, undefined, false, false, Joi.number().min(1).max(65535).required());
|
|
34
|
+
const exported = exportElement(element);
|
|
35
|
+
expect(exported.joiValidation).toBeDefined();
|
|
36
|
+
expect(exported.joiValidation.type).toBe('number');
|
|
37
|
+
expect(exported.joiValidation.rules).toBeDefined();
|
|
38
|
+
});
|
|
39
|
+
it('should handle enum types', () => {
|
|
40
|
+
const element = new Element('environment', 'Runtime environment', 'development', undefined, false, false, Joi.string().valid('development', 'staging', 'production'));
|
|
41
|
+
const exported = exportElement(element);
|
|
42
|
+
expect(exported.type).toContain('development');
|
|
43
|
+
expect(exported.type).toContain('staging');
|
|
44
|
+
expect(exported.type).toContain('production');
|
|
45
|
+
});
|
|
46
|
+
});
|
|
47
|
+
describe('exportSection', () => {
|
|
48
|
+
it('should export a section with elements', () => {
|
|
49
|
+
const elements = [
|
|
50
|
+
new Element('host', 'Database host', 'localhost'),
|
|
51
|
+
new Element('port', 'Database port', 5432)
|
|
52
|
+
];
|
|
53
|
+
const section = new Section('database', elements, 'Database configuration');
|
|
54
|
+
const exported = exportSection(section);
|
|
55
|
+
expect(exported.name).toBe('database');
|
|
56
|
+
expect(exported.description).toBe('Database configuration');
|
|
57
|
+
expect(exported.elements).toHaveLength(2);
|
|
58
|
+
expect(exported.elements[0].name).toBe('host');
|
|
59
|
+
expect(exported.elements[1].name).toBe('port');
|
|
60
|
+
});
|
|
61
|
+
it('should handle empty sections', () => {
|
|
62
|
+
const section = new Section('empty', [], 'Empty section');
|
|
63
|
+
const exported = exportSection(section);
|
|
64
|
+
expect(exported.name).toBe('empty');
|
|
65
|
+
expect(exported.elements).toHaveLength(0);
|
|
66
|
+
});
|
|
67
|
+
it('should filter out elements with omitFromSchema: true', () => {
|
|
68
|
+
const publicElement = new Element('appName', 'Application name', 'myApp', 'exampleApp', false, false, Joi.string());
|
|
69
|
+
const privateElement = new Element('internalKey', 'Internal configuration key', 'secret', 'example', false, true, Joi.string());
|
|
70
|
+
const section = new Section('app', [publicElement, privateElement], 'Application settings');
|
|
71
|
+
const exported = exportSection(section);
|
|
72
|
+
expect(exported.name).toBe('app');
|
|
73
|
+
expect(exported.description).toBe('Application settings');
|
|
74
|
+
expect(exported.elements).toHaveLength(1);
|
|
75
|
+
expect(exported.elements[0].name).toBe('appName');
|
|
76
|
+
expect(exported.elements.find((e) => e.name === 'internalKey')).toBeUndefined();
|
|
77
|
+
});
|
|
78
|
+
it('should include omitted elements when includeOmitted is true', () => {
|
|
79
|
+
const publicElement = new Element('appName', 'Application name', 'myApp', 'exampleApp', false, false, Joi.string());
|
|
80
|
+
const privateElement = new Element('internalKey', 'Internal configuration key', 'secret', 'example', false, true, Joi.string());
|
|
81
|
+
const section = new Section('app', [publicElement, privateElement], 'Application settings');
|
|
82
|
+
const exported = exportSection(section, true);
|
|
83
|
+
expect(exported.name).toBe('app');
|
|
84
|
+
expect(exported.description).toBe('Application settings');
|
|
85
|
+
expect(exported.elements).toHaveLength(2);
|
|
86
|
+
expect(exported.elements[0].name).toBe('appName');
|
|
87
|
+
expect(exported.elements[1].name).toBe('internalKey');
|
|
88
|
+
});
|
|
89
|
+
});
|
|
90
|
+
describe('exportSchema', () => {
|
|
91
|
+
it('should export a complete schema', () => {
|
|
92
|
+
const appElements = [
|
|
93
|
+
new Element('port', 'Application port', 3000),
|
|
94
|
+
new Element('host', 'Application host', 'localhost')
|
|
95
|
+
];
|
|
96
|
+
const dbElements = [
|
|
97
|
+
new Element('connectionString', 'Database connection', undefined)
|
|
98
|
+
];
|
|
99
|
+
const sections = [
|
|
100
|
+
new Section('app', appElements, 'Application settings'),
|
|
101
|
+
new Section('database', dbElements, 'Database settings')
|
|
102
|
+
];
|
|
103
|
+
const schema = exportSchema('myApp', sections);
|
|
104
|
+
expect(schema.name).toBe('myApp');
|
|
105
|
+
expect(schema.sections).toHaveLength(2);
|
|
106
|
+
expect(schema.sections[0].name).toBe('app');
|
|
107
|
+
expect(schema.sections[1].name).toBe('database');
|
|
108
|
+
});
|
|
109
|
+
it('should include omitted elements when includeOmitted is true', () => {
|
|
110
|
+
const publicElement = new Element('appName', 'Application name', 'myApp', 'exampleApp', false, false, Joi.string());
|
|
111
|
+
const privateElement = new Element('internalKey', 'Internal configuration key', 'secret', 'example', false, true, Joi.string());
|
|
112
|
+
const sections = [
|
|
113
|
+
new Section('app', [publicElement, privateElement], 'Application settings')
|
|
114
|
+
];
|
|
115
|
+
const schema = exportSchema('myApp', sections, true);
|
|
116
|
+
expect(schema.name).toBe('myApp');
|
|
117
|
+
expect(schema.sections).toHaveLength(1);
|
|
118
|
+
expect(schema.sections[0].elements).toHaveLength(2);
|
|
119
|
+
expect(schema.sections[0].elements[0].name).toBe('appName');
|
|
120
|
+
expect(schema.sections[0].elements[1].name).toBe('internalKey');
|
|
121
|
+
});
|
|
122
|
+
});
|
|
123
|
+
});
|
|
124
|
+
//# sourceMappingURL=schemaExporter.spec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schemaExporter.spec.js","sourceRoot":"","sources":["../src/schemaExporter.spec.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,oCAAoC,CAAC;AAC7D,OAAO,EAAE,OAAO,EAAE,MAAM,oCAAoC,CAAC;AAC7D,OAAO,GAAG,MAAM,KAAK,CAAC;AACtB,OAAO,EACL,aAAa,EACb,aAAa,EACb,YAAY,EACb,MAAM,qBAAqB,CAAC;AAE7B,QAAQ,CAAC,iBAAiB,EAAE,GAAG,EAAE;IAC/B,QAAQ,CAAC,eAAe,EAAE,GAAG,EAAE;QAC7B,EAAE,CAAC,+BAA+B,EAAE,GAAG,EAAE;YACvC,MAAM,OAAO,GAAG,IAAI,OAAO,CACzB,aAAa,EACb,gBAAgB,EAChB,eAAe,EACf,eAAe,EACf,KAAK,EACL,KAAK,EACL,GAAG,CAAC,MAAM,EAAE,CACb,CAAC;YAEF,MAAM,QAAQ,GAAG,aAAa,CAAC,OAAO,CAAC,CAAC;YAExC,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC;YAC1C,MAAM,CAAC,Q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KAAK,EACL,CAAC,aAAa,EAAE,cAAc,CAAC,EAC/B,sBAAsB,CACvB;aACF,CAAC;YAEF,MAAM,MAAM,GAAG,YAAY,CAAC,OAAO,EAAE,QAAQ,EAAE,IAAI,CAAC,CAAC;YAErD,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;YAClC,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC;YACxC,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC;YACpD,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;YAC5D,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC;QAClE,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { ExportedSchema } from './schemaExporter.js';
|
|
2
|
+
/**
|
|
3
|
+
* Formats the schema as JSON string
|
|
4
|
+
* @param schema - The schema to format
|
|
5
|
+
* @param pretty - Whether to pretty print the JSON
|
|
6
|
+
* @returns The configuration schema as a JSON string
|
|
7
|
+
*/
|
|
8
|
+
export declare function formatAsJSON(schema: ExportedSchema, pretty?: boolean): string;
|
|
9
|
+
/**
|
|
10
|
+
* Formats the schema as YAML string
|
|
11
|
+
* @param schema - The schema to format
|
|
12
|
+
* @returns The configuration schema as a YAML string
|
|
13
|
+
*/
|
|
14
|
+
export declare function formatAsYAML(schema: ExportedSchema): string;
|
|
15
|
+
/**
|
|
16
|
+
* Formats the schema as a .env.example file
|
|
17
|
+
* @param schema - The exported schema
|
|
18
|
+
* @param prefix - Optional prefix for environment variable names (e.g., 'MYAPP')
|
|
19
|
+
* @returns The .env.example file content as a string
|
|
20
|
+
*/
|
|
21
|
+
export declare function formatAsEnvExample(schema: ExportedSchema, prefix?: string): string;
|
|
22
|
+
//# sourceMappingURL=schemaFormatters.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schemaFormatters.d.ts","sourceRoot":"","sources":["../src/schemaFormatters.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAmB,MAAM,qBAAqB,CAAC;AAEtE;;;;;GAKG;AACH,wBAAgB,YAAY,CAC1B,MAAM,EAAE,cAAc,EACtB,MAAM,GAAE,OAAc,GACrB,MAAM,CAER;AAED;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE,cAAc,GAAG,MAAM,CAM3D;AAwDD;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAChC,MAAM,EAAE,cAAc,EACtB,MAAM,CAAC,EAAE,MAAM,GACd,MAAM,CA+BR"}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import yaml from 'js-yaml';
|
|
2
|
+
/**
|
|
3
|
+
* Formats the schema as JSON string
|
|
4
|
+
* @param schema - The schema to format
|
|
5
|
+
* @param pretty - Whether to pretty print the JSON
|
|
6
|
+
* @returns The configuration schema as a JSON string
|
|
7
|
+
*/
|
|
8
|
+
export function formatAsJSON(schema, pretty = true) {
|
|
9
|
+
return JSON.stringify(schema, null, pretty ? 2 : 0);
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Formats the schema as YAML string
|
|
13
|
+
* @param schema - The schema to format
|
|
14
|
+
* @returns The configuration schema as a YAML string
|
|
15
|
+
*/
|
|
16
|
+
export function formatAsYAML(schema) {
|
|
17
|
+
return yaml.dump(schema, {
|
|
18
|
+
indent: 2,
|
|
19
|
+
lineWidth: 80,
|
|
20
|
+
noRefs: true
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Generates an environment variable name from section and element names
|
|
25
|
+
* @param sectionName - The name of the section
|
|
26
|
+
* @param elementName - The name of the element
|
|
27
|
+
* @param prefix - Optional prefix for the environment variable name
|
|
28
|
+
* @returns The environment variable name
|
|
29
|
+
*/
|
|
30
|
+
function generateEnvVarName(sectionName, elementName, prefix) {
|
|
31
|
+
let name = `${sectionName}_${elementName}`.replace(/\./g, '_');
|
|
32
|
+
if (prefix) {
|
|
33
|
+
name = `${prefix}_${name}`;
|
|
34
|
+
}
|
|
35
|
+
return name.toUpperCase();
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Formats a value for display in .env.example file
|
|
39
|
+
* @param element - The element to format
|
|
40
|
+
* @returns The formatted value
|
|
41
|
+
*/
|
|
42
|
+
function formatEnvValue(element) {
|
|
43
|
+
if (element.sensitive) {
|
|
44
|
+
if (element.example !== undefined) {
|
|
45
|
+
return 'your-example-value';
|
|
46
|
+
}
|
|
47
|
+
return 'your-secret-value';
|
|
48
|
+
}
|
|
49
|
+
if (element.example !== undefined) {
|
|
50
|
+
return String(element.example);
|
|
51
|
+
}
|
|
52
|
+
if (element.default !== undefined) {
|
|
53
|
+
return String(element.default);
|
|
54
|
+
}
|
|
55
|
+
switch (element.type) {
|
|
56
|
+
case 'string':
|
|
57
|
+
return 'your-value';
|
|
58
|
+
case 'number':
|
|
59
|
+
return '0';
|
|
60
|
+
case 'boolean':
|
|
61
|
+
return 'true';
|
|
62
|
+
case 'array':
|
|
63
|
+
return 'value1,value2';
|
|
64
|
+
default:
|
|
65
|
+
return 'your-value';
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Formats the schema as a .env.example file
|
|
70
|
+
* @param schema - The exported schema
|
|
71
|
+
* @param prefix - Optional prefix for environment variable names (e.g., 'MYAPP')
|
|
72
|
+
* @returns The .env.example file content as a string
|
|
73
|
+
*/
|
|
74
|
+
export function formatAsEnvExample(schema, prefix) {
|
|
75
|
+
const lines = [];
|
|
76
|
+
lines.push(`# ${schema.name} Configuration`);
|
|
77
|
+
lines.push('# Generated from schema export');
|
|
78
|
+
lines.push('');
|
|
79
|
+
for (const section of schema.sections) {
|
|
80
|
+
if (section.description) {
|
|
81
|
+
lines.push(`# ${section.description}`);
|
|
82
|
+
}
|
|
83
|
+
for (const element of section.elements) {
|
|
84
|
+
const envVarName = generateEnvVarName(section.name, element.name, prefix);
|
|
85
|
+
const value = formatEnvValue(element);
|
|
86
|
+
const isRequired = element.required && element.default === undefined;
|
|
87
|
+
if (element.description) {
|
|
88
|
+
lines.push(`# ${element.description}${isRequired ? ' (required)' : ''}`);
|
|
89
|
+
}
|
|
90
|
+
else if (isRequired) {
|
|
91
|
+
lines.push('# Required');
|
|
92
|
+
}
|
|
93
|
+
lines.push(`${envVarName}=${value}`);
|
|
94
|
+
lines.push('');
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
return lines.join('\n');
|
|
98
|
+
}
|
|
99
|
+
//# sourceMappingURL=schemaFormatters.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schemaFormatters.js","sourceRoot":"","sources":["../src/schemaFormatters.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,SAAS,CAAC;AAG3B;;;;;GAKG;AACH,MAAM,UAAU,YAAY,CAC1B,MAAsB,EACtB,SAAkB,IAAI;IAEtB,OAAO,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,IAAI,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AACtD,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,YAAY,CAAC,MAAsB;IACjD,OAAO,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE;QACvB,MAAM,EAAE,CAAC;QACT,SAAS,EAAE,EAAE;QACb,MAAM,EAAE,IAAI;KACb,CAAC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