@ontrails/config 1.0.0-beta.13 → 1.0.0-beta.15
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-lint.log +1 -1
- package/CHANGELOG.md +18 -0
- package/README.md +204 -0
- package/dist/app-config.d.ts +4 -4
- package/dist/app-config.d.ts.map +1 -1
- package/dist/app-config.js +12 -7
- package/dist/app-config.js.map +1 -1
- package/dist/compose.d.ts +11 -11
- package/dist/compose.d.ts.map +1 -1
- package/dist/compose.js +7 -7
- package/dist/compose.js.map +1 -1
- package/dist/config-layer.d.ts +3 -3
- package/dist/config-resource.d.ts +3 -0
- package/dist/config-resource.d.ts.map +1 -0
- package/dist/{config-service.js → config-resource.js} +7 -7
- package/dist/config-resource.js.map +1 -0
- package/dist/define-config.d.ts +9 -9
- package/dist/define-config.d.ts.map +1 -1
- package/dist/define-config.js +9 -12
- package/dist/define-config.js.map +1 -1
- package/dist/{generate → derive}/env.d.ts +1 -1
- package/dist/derive/env.d.ts.map +1 -0
- package/dist/{generate → derive}/env.js +3 -3
- package/dist/derive/env.js.map +1 -0
- package/dist/{generate → derive}/example.d.ts +1 -1
- package/dist/derive/example.d.ts.map +1 -0
- package/dist/{generate → derive}/example.js +21 -19
- package/dist/derive/example.js.map +1 -0
- package/dist/{generate → derive}/helpers.d.ts +1 -1
- package/dist/derive/helpers.d.ts.map +1 -0
- package/dist/{generate → derive}/helpers.js +2 -2
- package/dist/derive/helpers.js.map +1 -0
- package/dist/derive/index.d.ts +4 -0
- package/dist/derive/index.d.ts.map +1 -0
- package/dist/derive/index.js +4 -0
- package/dist/derive/index.js.map +1 -0
- package/dist/{generate → derive}/json-schema.d.ts +1 -1
- package/dist/derive/json-schema.d.ts.map +1 -0
- package/dist/{generate → derive}/json-schema.js +1 -1
- package/dist/derive/json-schema.js.map +1 -0
- package/dist/{describe.d.ts → derive-fields.d.ts} +2 -2
- package/dist/derive-fields.d.ts.map +1 -0
- package/dist/{describe.js → derive-fields.js} +2 -2
- package/dist/derive-fields.js.map +1 -0
- package/dist/{explain.d.ts → derive-provenance.d.ts} +5 -5
- package/dist/derive-provenance.d.ts.map +1 -0
- package/dist/{explain.js → derive-provenance.js} +8 -21
- package/dist/derive-provenance.js.map +1 -0
- package/dist/doctor.d.ts.map +1 -1
- package/dist/doctor.js +1 -37
- package/dist/doctor.js.map +1 -1
- package/dist/extensions.d.ts +1 -1
- package/dist/extensions.js +1 -1
- package/dist/index.d.ts +7 -8
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -7
- package/dist/index.js.map +1 -1
- package/dist/ref.d.ts +8 -3
- package/dist/ref.d.ts.map +1 -1
- package/dist/ref.js +8 -3
- package/dist/ref.js.map +1 -1
- package/dist/registry.d.ts +2 -2
- package/dist/resolve.d.ts +6 -6
- package/dist/resolve.d.ts.map +1 -1
- package/dist/resolve.js +11 -8
- package/dist/resolve.js.map +1 -1
- package/dist/trails/config-check.d.ts +1 -1
- package/dist/trails/config-check.d.ts.map +1 -1
- package/dist/trails/config-check.js +12 -12
- package/dist/trails/config-check.js.map +1 -1
- package/dist/trails/config-describe.d.ts +1 -1
- package/dist/trails/config-describe.d.ts.map +1 -1
- package/dist/trails/config-describe.js +9 -9
- package/dist/trails/config-describe.js.map +1 -1
- package/dist/trails/config-explain.d.ts +1 -1
- package/dist/trails/config-explain.d.ts.map +1 -1
- package/dist/trails/config-explain.js +15 -15
- package/dist/trails/config-explain.js.map +1 -1
- package/dist/trails/config-init.d.ts +1 -1
- package/dist/trails/config-init.d.ts.map +1 -1
- package/dist/trails/config-init.js +16 -16
- package/dist/trails/config-init.js.map +1 -1
- package/dist/workspace.d.ts.map +1 -1
- package/dist/workspace.js +5 -0
- package/dist/workspace.js.map +1 -1
- package/package.json +2 -2
- package/src/__tests__/app-config.test.ts +19 -6
- package/src/__tests__/compose.test.ts +15 -15
- package/src/__tests__/config-check.test.ts +7 -7
- package/src/__tests__/config-describe.test.ts +7 -7
- package/src/__tests__/config-explain.test.ts +7 -7
- package/src/__tests__/config-init.test.ts +7 -7
- package/src/__tests__/{config-provision.test.ts → config-resource.test.ts} +12 -12
- package/src/__tests__/define-config.test.ts +24 -18
- package/src/__tests__/{describe.test.ts → derive-fields.test.ts} +11 -11
- package/src/__tests__/{explain.test.ts → derive-provenance.test.ts} +18 -18
- package/src/__tests__/{generate.test.ts → derive.test.ts} +30 -30
- package/src/__tests__/resolve.test.ts +31 -31
- package/src/app-config.ts +23 -12
- package/src/compose.ts +16 -22
- package/src/{config-provision.ts → config-resource.ts} +5 -5
- package/src/define-config.ts +12 -15
- package/src/{generate → derive}/env.ts +3 -3
- package/src/{generate → derive}/example.ts +1 -1
- package/src/{generate → derive}/helpers.ts +1 -1
- package/src/derive/index.ts +3 -0
- package/src/{generate → derive}/json-schema.ts +1 -1
- package/src/{describe.ts → derive-fields.ts} +1 -1
- package/src/{explain.ts → derive-provenance.ts} +6 -6
- package/src/index.ts +12 -18
- package/src/registry.ts +2 -2
- package/src/resolve.ts +13 -13
- package/src/trails/config-check.ts +3 -3
- package/src/trails/config-describe.ts +5 -5
- package/src/trails/config-explain.ts +13 -13
- package/src/trails/config-init.ts +10 -10
- package/src/workspace.ts +5 -0
- package/tsconfig.tests.json +10 -0
- package/tsconfig.tsbuildinfo +1 -1
- package/dist/config-service.d.ts +0 -3
- package/dist/config-service.d.ts.map +0 -1
- package/dist/config-service.js.map +0 -1
- package/dist/describe.d.ts.map +0 -1
- package/dist/describe.js.map +0 -1
- package/dist/explain.d.ts.map +0 -1
- package/dist/explain.js.map +0 -1
- package/dist/generate/env.d.ts.map +0 -1
- package/dist/generate/env.js.map +0 -1
- package/dist/generate/example.d.ts.map +0 -1
- package/dist/generate/example.js.map +0 -1
- package/dist/generate/helpers.d.ts.map +0 -1
- package/dist/generate/helpers.js.map +0 -1
- package/dist/generate/index.d.ts +0 -4
- package/dist/generate/index.d.ts.map +0 -1
- package/dist/generate/index.js +0 -4
- package/dist/generate/index.js.map +0 -1
- package/dist/generate/json-schema.d.ts.map +0 -1
- package/dist/generate/json-schema.js.map +0 -1
- package/src/__tests__/config-gate.test.ts +0 -53
- package/src/config-gate.ts +0 -15
- package/src/generate/index.ts +0 -3
|
@@ -2,57 +2,57 @@ import { describe, expect, test } from 'bun:test';
|
|
|
2
2
|
|
|
3
3
|
import { z } from 'zod';
|
|
4
4
|
|
|
5
|
-
import {
|
|
5
|
+
import { collectResourceConfigs } from '../compose.js';
|
|
6
6
|
|
|
7
7
|
// ---------------------------------------------------------------------------
|
|
8
8
|
// Tests
|
|
9
9
|
// ---------------------------------------------------------------------------
|
|
10
10
|
|
|
11
|
-
describe('
|
|
12
|
-
test('extracts config schemas from
|
|
11
|
+
describe('collectResourceConfigs', () => {
|
|
12
|
+
test('extracts config schemas from resources that declare them', () => {
|
|
13
13
|
const dbSchema = z.object({ url: z.string().url() });
|
|
14
14
|
const cacheSchema = z.object({ ttl: z.number() });
|
|
15
15
|
|
|
16
|
-
const
|
|
16
|
+
const resources = [
|
|
17
17
|
{ config: dbSchema, id: 'db.main' },
|
|
18
18
|
{ config: cacheSchema, id: 'cache.main' },
|
|
19
19
|
];
|
|
20
20
|
|
|
21
|
-
const entries =
|
|
21
|
+
const entries = collectResourceConfigs(resources);
|
|
22
22
|
|
|
23
23
|
expect(entries).toHaveLength(2);
|
|
24
|
-
expect(entries[0]).toEqual({
|
|
24
|
+
expect(entries[0]).toEqual({ resourceId: 'db.main', schema: dbSchema });
|
|
25
25
|
expect(entries[1]).toEqual({
|
|
26
|
-
|
|
26
|
+
resourceId: 'cache.main',
|
|
27
27
|
schema: cacheSchema,
|
|
28
28
|
});
|
|
29
29
|
});
|
|
30
30
|
|
|
31
|
-
test('excludes
|
|
31
|
+
test('excludes resources without config', () => {
|
|
32
32
|
const schema = z.object({ url: z.string() });
|
|
33
33
|
|
|
34
|
-
const
|
|
34
|
+
const resources = [
|
|
35
35
|
{ config: schema, id: 'db.main' },
|
|
36
36
|
{ id: 'counter.main' },
|
|
37
37
|
{ config: undefined, id: 'logger.main' },
|
|
38
38
|
];
|
|
39
39
|
|
|
40
|
-
const entries =
|
|
40
|
+
const entries = collectResourceConfigs(resources);
|
|
41
41
|
|
|
42
42
|
expect(entries).toHaveLength(1);
|
|
43
|
-
expect(entries[0]?.
|
|
43
|
+
expect(entries[0]?.resourceId).toBe('db.main');
|
|
44
44
|
});
|
|
45
45
|
|
|
46
|
-
test('returns empty array when no
|
|
47
|
-
const
|
|
46
|
+
test('returns empty array when no resources have config', () => {
|
|
47
|
+
const resources = [{ id: 'counter.main' }, { id: 'logger.main' }];
|
|
48
48
|
|
|
49
|
-
const entries =
|
|
49
|
+
const entries = collectResourceConfigs(resources);
|
|
50
50
|
|
|
51
51
|
expect(entries).toEqual([]);
|
|
52
52
|
});
|
|
53
53
|
|
|
54
54
|
test('returns empty array for empty input', () => {
|
|
55
|
-
const entries =
|
|
55
|
+
const entries = collectResourceConfigs([]);
|
|
56
56
|
|
|
57
57
|
expect(entries).toEqual([]);
|
|
58
58
|
});
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { describe, expect, test } from 'bun:test';
|
|
2
|
-
import {
|
|
2
|
+
import { createResourceLookup } from '@ontrails/core';
|
|
3
3
|
import type { TrailContext } from '@ontrails/core';
|
|
4
4
|
import { z } from 'zod';
|
|
5
5
|
|
|
@@ -7,7 +7,7 @@ import { configCheck } from '../trails/config-check.js';
|
|
|
7
7
|
import type { ConfigState } from '../registry.js';
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
|
-
* Build a TrailContext with
|
|
10
|
+
* Build a TrailContext with configResource resolved in extensions.
|
|
11
11
|
*/
|
|
12
12
|
const buildCtx = (state: ConfigState): TrailContext => {
|
|
13
13
|
const extensions = { config: state };
|
|
@@ -16,13 +16,13 @@ const buildCtx = (state: ConfigState): TrailContext => {
|
|
|
16
16
|
cwd: '/tmp',
|
|
17
17
|
env: {},
|
|
18
18
|
extensions,
|
|
19
|
-
provision: undefined as unknown as TrailContext['provision'],
|
|
20
19
|
requestId: 'test',
|
|
20
|
+
resource: undefined as unknown as TrailContext['resource'],
|
|
21
21
|
workspaceRoot: '/tmp',
|
|
22
22
|
};
|
|
23
23
|
const withLookup = {
|
|
24
24
|
...ctx,
|
|
25
|
-
|
|
25
|
+
resource: createResourceLookup(() => withLookup),
|
|
26
26
|
};
|
|
27
27
|
return withLookup;
|
|
28
28
|
};
|
|
@@ -49,9 +49,9 @@ describe('config.check trail', () => {
|
|
|
49
49
|
expect(configCheck.output).toBeDefined();
|
|
50
50
|
});
|
|
51
51
|
|
|
52
|
-
test('declares
|
|
53
|
-
expect(configCheck.
|
|
54
|
-
expect(configCheck.
|
|
52
|
+
test('declares configResource dependency', () => {
|
|
53
|
+
expect(configCheck.resources).toBeDefined();
|
|
54
|
+
expect(configCheck.resources?.length).toBe(1);
|
|
55
55
|
});
|
|
56
56
|
});
|
|
57
57
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { describe, expect, test } from 'bun:test';
|
|
2
|
-
import {
|
|
2
|
+
import { createResourceLookup } from '@ontrails/core';
|
|
3
3
|
import type { TrailContext } from '@ontrails/core';
|
|
4
4
|
import { z } from 'zod';
|
|
5
5
|
|
|
@@ -8,7 +8,7 @@ import { env, secret } from '../extensions.js';
|
|
|
8
8
|
import type { ConfigState } from '../registry.js';
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
|
-
* Build a TrailContext with
|
|
11
|
+
* Build a TrailContext with configResource resolved in extensions.
|
|
12
12
|
*/
|
|
13
13
|
const buildCtx = (state: ConfigState): TrailContext => {
|
|
14
14
|
const extensions = { config: state };
|
|
@@ -17,13 +17,13 @@ const buildCtx = (state: ConfigState): TrailContext => {
|
|
|
17
17
|
cwd: '/tmp',
|
|
18
18
|
env: {},
|
|
19
19
|
extensions,
|
|
20
|
-
provision: undefined as unknown as TrailContext['provision'],
|
|
21
20
|
requestId: 'test',
|
|
21
|
+
resource: undefined as unknown as TrailContext['resource'],
|
|
22
22
|
workspaceRoot: '/tmp',
|
|
23
23
|
};
|
|
24
24
|
const withLookup = {
|
|
25
25
|
...ctx,
|
|
26
|
-
|
|
26
|
+
resource: createResourceLookup(() => withLookup),
|
|
27
27
|
};
|
|
28
28
|
return withLookup;
|
|
29
29
|
};
|
|
@@ -50,9 +50,9 @@ describe('config.describe trail', () => {
|
|
|
50
50
|
expect(configDescribe.output).toBeDefined();
|
|
51
51
|
});
|
|
52
52
|
|
|
53
|
-
test('declares
|
|
54
|
-
expect(configDescribe.
|
|
55
|
-
expect(configDescribe.
|
|
53
|
+
test('declares configResource dependency', () => {
|
|
54
|
+
expect(configDescribe.resources).toBeDefined();
|
|
55
|
+
expect(configDescribe.resources?.length).toBe(1);
|
|
56
56
|
});
|
|
57
57
|
});
|
|
58
58
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { describe, expect, test } from 'bun:test';
|
|
2
|
-
import {
|
|
2
|
+
import { createResourceLookup } from '@ontrails/core';
|
|
3
3
|
import type { TrailContext } from '@ontrails/core';
|
|
4
4
|
import { z } from 'zod';
|
|
5
5
|
|
|
@@ -8,7 +8,7 @@ import { env } from '../extensions.js';
|
|
|
8
8
|
import type { ConfigState } from '../registry.js';
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
|
-
* Build a TrailContext with
|
|
11
|
+
* Build a TrailContext with configResource resolved in extensions.
|
|
12
12
|
*/
|
|
13
13
|
const buildCtx = (state: ConfigState): TrailContext => {
|
|
14
14
|
const extensions = { config: state };
|
|
@@ -17,13 +17,13 @@ const buildCtx = (state: ConfigState): TrailContext => {
|
|
|
17
17
|
cwd: '/tmp',
|
|
18
18
|
env: {},
|
|
19
19
|
extensions,
|
|
20
|
-
provision: undefined as unknown as TrailContext['provision'],
|
|
21
20
|
requestId: 'test',
|
|
21
|
+
resource: undefined as unknown as TrailContext['resource'],
|
|
22
22
|
workspaceRoot: '/tmp',
|
|
23
23
|
};
|
|
24
24
|
const withLookup = {
|
|
25
25
|
...ctx,
|
|
26
|
-
|
|
26
|
+
resource: createResourceLookup(() => withLookup),
|
|
27
27
|
};
|
|
28
28
|
return withLookup;
|
|
29
29
|
};
|
|
@@ -50,9 +50,9 @@ describe('config.explain trail', () => {
|
|
|
50
50
|
expect(configExplain.output).toBeDefined();
|
|
51
51
|
});
|
|
52
52
|
|
|
53
|
-
test('declares
|
|
54
|
-
expect(configExplain.
|
|
55
|
-
expect(configExplain.
|
|
53
|
+
test('declares configResource dependency', () => {
|
|
54
|
+
expect(configExplain.resources).toBeDefined();
|
|
55
|
+
expect(configExplain.resources?.length).toBe(1);
|
|
56
56
|
});
|
|
57
57
|
});
|
|
58
58
|
|
|
@@ -2,7 +2,7 @@ import { afterEach, beforeEach, describe, expect, test } from 'bun:test';
|
|
|
2
2
|
import { mkdtemp, readFile, rm } from 'node:fs/promises';
|
|
3
3
|
import { tmpdir } from 'node:os';
|
|
4
4
|
import { join } from 'node:path';
|
|
5
|
-
import {
|
|
5
|
+
import { createResourceLookup } from '@ontrails/core';
|
|
6
6
|
import type { TrailContext } from '@ontrails/core';
|
|
7
7
|
import { z } from 'zod';
|
|
8
8
|
|
|
@@ -11,7 +11,7 @@ import type { ConfigState } from '../registry.js';
|
|
|
11
11
|
import { configInit } from '../trails/config-init.js';
|
|
12
12
|
|
|
13
13
|
/**
|
|
14
|
-
* Build a TrailContext with
|
|
14
|
+
* Build a TrailContext with configResource resolved in extensions.
|
|
15
15
|
*/
|
|
16
16
|
const buildCtx = (state: ConfigState): TrailContext => {
|
|
17
17
|
const extensions = { config: state };
|
|
@@ -20,13 +20,13 @@ const buildCtx = (state: ConfigState): TrailContext => {
|
|
|
20
20
|
cwd: '/tmp',
|
|
21
21
|
env: {},
|
|
22
22
|
extensions,
|
|
23
|
-
provision: undefined as unknown as TrailContext['provision'],
|
|
24
23
|
requestId: 'test',
|
|
24
|
+
resource: undefined as unknown as TrailContext['resource'],
|
|
25
25
|
workspaceRoot: '/tmp',
|
|
26
26
|
};
|
|
27
27
|
const withLookup = {
|
|
28
28
|
...ctx,
|
|
29
|
-
|
|
29
|
+
resource: createResourceLookup(() => withLookup),
|
|
30
30
|
};
|
|
31
31
|
return withLookup;
|
|
32
32
|
};
|
|
@@ -63,9 +63,9 @@ describe('config.init trail', () => {
|
|
|
63
63
|
expect(configInit.output).toBeDefined();
|
|
64
64
|
});
|
|
65
65
|
|
|
66
|
-
test('declares
|
|
67
|
-
expect(configInit.
|
|
68
|
-
expect(configInit.
|
|
66
|
+
test('declares configResource dependency', () => {
|
|
67
|
+
expect(configInit.resources).toBeDefined();
|
|
68
|
+
expect(configInit.resources?.length).toBe(1);
|
|
69
69
|
});
|
|
70
70
|
});
|
|
71
71
|
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { afterEach, describe, expect, test } from 'bun:test';
|
|
2
2
|
import { z } from 'zod';
|
|
3
3
|
|
|
4
|
-
import {
|
|
4
|
+
import { configResource } from '../config-resource.js';
|
|
5
5
|
import type { ConfigState } from '../registry.js';
|
|
6
6
|
import { clearConfigState, registerConfigState } from '../registry.js';
|
|
7
7
|
|
|
8
|
-
/** Stub
|
|
8
|
+
/** Stub ResourceContext for create calls. */
|
|
9
9
|
const stubSvcCtx = {
|
|
10
10
|
config: undefined,
|
|
11
11
|
cwd: '/tmp',
|
|
@@ -13,32 +13,32 @@ const stubSvcCtx = {
|
|
|
13
13
|
workspaceRoot: '/tmp',
|
|
14
14
|
};
|
|
15
15
|
|
|
16
|
-
describe('
|
|
16
|
+
describe('configResource', () => {
|
|
17
17
|
afterEach(() => {
|
|
18
18
|
clearConfigState();
|
|
19
19
|
});
|
|
20
20
|
|
|
21
21
|
describe('identity', () => {
|
|
22
22
|
test('has id "config"', () => {
|
|
23
|
-
expect(
|
|
23
|
+
expect(configResource.id).toBe('config');
|
|
24
24
|
});
|
|
25
25
|
|
|
26
|
-
test('has kind "
|
|
27
|
-
expect(
|
|
26
|
+
test('has kind "resource"', () => {
|
|
27
|
+
expect(configResource.kind).toBe('resource');
|
|
28
28
|
});
|
|
29
29
|
|
|
30
30
|
test('has infrastructure meta', () => {
|
|
31
|
-
expect(
|
|
31
|
+
expect(configResource.meta).toEqual({ category: 'infrastructure' });
|
|
32
32
|
});
|
|
33
33
|
|
|
34
34
|
test('has description', () => {
|
|
35
|
-
expect(
|
|
35
|
+
expect(configResource.description).toBeDefined();
|
|
36
36
|
});
|
|
37
37
|
});
|
|
38
38
|
|
|
39
39
|
describe('mock', () => {
|
|
40
40
|
test('returns a ConfigState with empty schema and resolved', () => {
|
|
41
|
-
const value =
|
|
41
|
+
const value = configResource.mock?.() as ConfigState;
|
|
42
42
|
expect(value).toBeDefined();
|
|
43
43
|
expect(value.resolved).toEqual({});
|
|
44
44
|
expect(value.schema).toBeDefined();
|
|
@@ -51,7 +51,7 @@ describe('configProvision', () => {
|
|
|
51
51
|
const state: ConfigState = { resolved: { port: 3000 }, schema };
|
|
52
52
|
registerConfigState(state);
|
|
53
53
|
|
|
54
|
-
const result = await
|
|
54
|
+
const result = await configResource.create(stubSvcCtx);
|
|
55
55
|
|
|
56
56
|
expect(result.isOk()).toBe(true);
|
|
57
57
|
const value = result.unwrap() as ConfigState;
|
|
@@ -69,7 +69,7 @@ describe('configProvision', () => {
|
|
|
69
69
|
};
|
|
70
70
|
registerConfigState(state);
|
|
71
71
|
|
|
72
|
-
const result = await
|
|
72
|
+
const result = await configResource.create(stubSvcCtx);
|
|
73
73
|
|
|
74
74
|
expect(result.isOk()).toBe(true);
|
|
75
75
|
const value = result.unwrap() as ConfigState;
|
|
@@ -78,7 +78,7 @@ describe('configProvision', () => {
|
|
|
78
78
|
});
|
|
79
79
|
|
|
80
80
|
test('returns Result.err when no state is registered', async () => {
|
|
81
|
-
const result = await
|
|
81
|
+
const result = await configResource.create(stubSvcCtx);
|
|
82
82
|
|
|
83
83
|
expect(result.isErr()).toBe(true);
|
|
84
84
|
expect(result.error.message).toContain('Config state not registered');
|
|
@@ -46,21 +46,21 @@ const restoreEnv = (snapshot: EnvSnapshot): void => {
|
|
|
46
46
|
};
|
|
47
47
|
|
|
48
48
|
describe('defineConfig', () => {
|
|
49
|
-
test('returns an object with schema, base, and
|
|
49
|
+
test('returns an object with schema, base, and profiles', () => {
|
|
50
50
|
const base = { host: 'example.com' };
|
|
51
|
-
const
|
|
51
|
+
const profiles = { production: { port: 443 } };
|
|
52
52
|
|
|
53
|
-
const config = defineConfig({ base,
|
|
53
|
+
const config = defineConfig({ base, profiles, schema });
|
|
54
54
|
|
|
55
55
|
expect(config.schema).toBe(schema);
|
|
56
56
|
expect(config.base).toBe(base);
|
|
57
|
-
expect(config.
|
|
57
|
+
expect(config.profiles).toBe(profiles);
|
|
58
58
|
});
|
|
59
59
|
|
|
60
|
-
test('resolve() uses TRAILS_ENV to select
|
|
60
|
+
test('resolve() uses TRAILS_ENV to select profile', async () => {
|
|
61
61
|
const config = defineConfig({
|
|
62
62
|
base: { host: 'example.com' },
|
|
63
|
-
|
|
63
|
+
profiles: {
|
|
64
64
|
production: { host: 'prod.example.com', port: 443 },
|
|
65
65
|
test: { host: 'test.example.com', port: 9999 },
|
|
66
66
|
},
|
|
@@ -76,10 +76,10 @@ describe('defineConfig', () => {
|
|
|
76
76
|
expect(result.unwrap().port).toBe(443);
|
|
77
77
|
});
|
|
78
78
|
|
|
79
|
-
test('resolve() with explicit
|
|
79
|
+
test('resolve() with explicit profile option overrides TRAILS_ENV', async () => {
|
|
80
80
|
const config = defineConfig({
|
|
81
81
|
base: { host: 'example.com' },
|
|
82
|
-
|
|
82
|
+
profiles: {
|
|
83
83
|
production: { host: 'prod.example.com' },
|
|
84
84
|
test: { host: 'test.example.com' },
|
|
85
85
|
},
|
|
@@ -88,7 +88,7 @@ describe('defineConfig', () => {
|
|
|
88
88
|
|
|
89
89
|
const result = await config.resolve({
|
|
90
90
|
env: { TRAILS_ENV: 'production' },
|
|
91
|
-
|
|
91
|
+
profile: 'test',
|
|
92
92
|
});
|
|
93
93
|
|
|
94
94
|
expect(result.isOk()).toBe(true);
|
|
@@ -99,7 +99,7 @@ describe('defineConfig', () => {
|
|
|
99
99
|
const config = defineConfig({
|
|
100
100
|
base: { host: 'example.com' },
|
|
101
101
|
envFromNodeEnv: true,
|
|
102
|
-
|
|
102
|
+
profiles: {
|
|
103
103
|
production: { host: 'prod.example.com', port: 443 },
|
|
104
104
|
},
|
|
105
105
|
schema,
|
|
@@ -123,7 +123,7 @@ describe('defineConfig', () => {
|
|
|
123
123
|
const config = defineConfig({
|
|
124
124
|
base: { host: 'example.com' },
|
|
125
125
|
envFromNodeEnv: true,
|
|
126
|
-
|
|
126
|
+
profiles: {
|
|
127
127
|
production: { host: 'prod.example.com', port: 443 },
|
|
128
128
|
},
|
|
129
129
|
schema,
|
|
@@ -143,7 +143,7 @@ describe('defineConfig', () => {
|
|
|
143
143
|
const config = defineConfig({
|
|
144
144
|
base: { host: 'example.com' },
|
|
145
145
|
envFromNodeEnv: true,
|
|
146
|
-
|
|
146
|
+
profiles: {
|
|
147
147
|
production: { host: 'prod.example.com' },
|
|
148
148
|
test: { host: 'test.example.com' },
|
|
149
149
|
},
|
|
@@ -158,10 +158,10 @@ describe('defineConfig', () => {
|
|
|
158
158
|
expect(result.unwrap().host).toBe('test.example.com');
|
|
159
159
|
});
|
|
160
160
|
|
|
161
|
-
test('test
|
|
161
|
+
test('test profile works when TRAILS_ENV=test', async () => {
|
|
162
162
|
const config = defineConfig({
|
|
163
163
|
base: { port: 8080 },
|
|
164
|
-
|
|
164
|
+
profiles: {
|
|
165
165
|
test: { debug: true, port: 0 },
|
|
166
166
|
},
|
|
167
167
|
schema,
|
|
@@ -177,6 +177,12 @@ describe('defineConfig', () => {
|
|
|
177
177
|
expect(value.port).toBe(0);
|
|
178
178
|
});
|
|
179
179
|
|
|
180
|
+
test('inherits the canonical appConfig format list, including jsonc', () => {
|
|
181
|
+
const config = defineConfig({ schema });
|
|
182
|
+
|
|
183
|
+
expect(config.formats).toEqual(['toml', 'json', 'jsonc', 'yaml']);
|
|
184
|
+
});
|
|
185
|
+
|
|
180
186
|
describe('local overrides', () => {
|
|
181
187
|
let tempDir: string;
|
|
182
188
|
|
|
@@ -210,7 +216,7 @@ describe('defineConfig', () => {
|
|
|
210
216
|
expect(result.unwrap().port).toBe(4444);
|
|
211
217
|
});
|
|
212
218
|
|
|
213
|
-
test('local overrides applied between
|
|
219
|
+
test('local overrides applied between profile and env', async () => {
|
|
214
220
|
const configDir = join(tempDir, '.trails', 'config');
|
|
215
221
|
await mkdir(configDir, { recursive: true });
|
|
216
222
|
await Bun.write(
|
|
@@ -220,17 +226,17 @@ describe('defineConfig', () => {
|
|
|
220
226
|
|
|
221
227
|
const config = defineConfig({
|
|
222
228
|
base: { port: 8080 },
|
|
223
|
-
|
|
229
|
+
profiles: {
|
|
224
230
|
dev: { port: 9090 },
|
|
225
231
|
},
|
|
226
232
|
schema,
|
|
227
233
|
});
|
|
228
234
|
|
|
229
|
-
// Local overrides should win over
|
|
235
|
+
// Local overrides should win over profile (9090)
|
|
230
236
|
const result = await config.resolve({
|
|
231
237
|
cwd: tempDir,
|
|
232
238
|
env: { TRAILS_ENV: 'dev' },
|
|
233
|
-
|
|
239
|
+
profile: 'dev',
|
|
234
240
|
});
|
|
235
241
|
|
|
236
242
|
expect(result.isOk()).toBe(true);
|
|
@@ -2,9 +2,9 @@ import { describe, expect, test } from 'bun:test';
|
|
|
2
2
|
import { z } from 'zod';
|
|
3
3
|
|
|
4
4
|
import { deprecated, env, secret } from '../extensions.js';
|
|
5
|
-
import {
|
|
5
|
+
import { deriveConfigFields } from '../derive-fields.js';
|
|
6
6
|
|
|
7
|
-
describe('
|
|
7
|
+
describe('deriveConfigFields', () => {
|
|
8
8
|
describe('basic field descriptions', () => {
|
|
9
9
|
test('returns path, type, and required for each field', () => {
|
|
10
10
|
const schema = z.object({
|
|
@@ -13,7 +13,7 @@ describe('describeConfig', () => {
|
|
|
13
13
|
port: z.number(),
|
|
14
14
|
});
|
|
15
15
|
|
|
16
|
-
const fields =
|
|
16
|
+
const fields = deriveConfigFields(schema);
|
|
17
17
|
|
|
18
18
|
expect(fields).toHaveLength(3);
|
|
19
19
|
const host = fields.find((f) => f.path === 'host');
|
|
@@ -32,7 +32,7 @@ describe('describeConfig', () => {
|
|
|
32
32
|
host: z.string().describe('The server hostname'),
|
|
33
33
|
});
|
|
34
34
|
|
|
35
|
-
const fields =
|
|
35
|
+
const fields = deriveConfigFields(schema);
|
|
36
36
|
const host = fields.find((f) => f.path === 'host');
|
|
37
37
|
expect(host?.description).toBe('The server hostname');
|
|
38
38
|
});
|
|
@@ -47,7 +47,7 @@ describe('describeConfig', () => {
|
|
|
47
47
|
),
|
|
48
48
|
});
|
|
49
49
|
|
|
50
|
-
const fields =
|
|
50
|
+
const fields = deriveConfigFields(schema);
|
|
51
51
|
|
|
52
52
|
const apiKey = fields.find((f) => f.path === 'apiKey');
|
|
53
53
|
expect(apiKey?.env).toBe('API_KEY');
|
|
@@ -65,7 +65,7 @@ describe('describeConfig', () => {
|
|
|
65
65
|
port: z.number().default(3000),
|
|
66
66
|
});
|
|
67
67
|
|
|
68
|
-
const fields =
|
|
68
|
+
const fields = deriveConfigFields(schema);
|
|
69
69
|
|
|
70
70
|
const port = fields.find((f) => f.path === 'port');
|
|
71
71
|
expect(port?.default).toBe(3000);
|
|
@@ -85,7 +85,7 @@ describe('describeConfig', () => {
|
|
|
85
85
|
}),
|
|
86
86
|
});
|
|
87
87
|
|
|
88
|
-
const fields =
|
|
88
|
+
const fields = deriveConfigFields(schema);
|
|
89
89
|
|
|
90
90
|
const dbHost = fields.find((f) => f.path === 'db.host');
|
|
91
91
|
expect(dbHost?.type).toBe('string');
|
|
@@ -106,7 +106,7 @@ describe('describeConfig', () => {
|
|
|
106
106
|
.optional(),
|
|
107
107
|
});
|
|
108
108
|
|
|
109
|
-
const fields =
|
|
109
|
+
const fields = deriveConfigFields(schema);
|
|
110
110
|
|
|
111
111
|
expect(fields).toEqual([
|
|
112
112
|
expect.objectContaining({ path: 'db.host', required: true }),
|
|
@@ -121,7 +121,7 @@ describe('describeConfig', () => {
|
|
|
121
121
|
env: z.enum(['development', 'production', 'test']),
|
|
122
122
|
});
|
|
123
123
|
|
|
124
|
-
const fields =
|
|
124
|
+
const fields = deriveConfigFields(schema);
|
|
125
125
|
const envField = fields.find((f) => f.path === 'env');
|
|
126
126
|
expect(envField?.type).toBe('enum');
|
|
127
127
|
expect(envField?.constraints?.values).toEqual([
|
|
@@ -136,7 +136,7 @@ describe('describeConfig', () => {
|
|
|
136
136
|
port: z.number().min(1).max(65_535),
|
|
137
137
|
});
|
|
138
138
|
|
|
139
|
-
const fields =
|
|
139
|
+
const fields = deriveConfigFields(schema);
|
|
140
140
|
const port = fields.find((f) => f.path === 'port');
|
|
141
141
|
expect(port?.constraints?.min).toBe(1);
|
|
142
142
|
expect(port?.constraints?.max).toBe(65_535);
|
|
@@ -150,7 +150,7 @@ describe('describeConfig', () => {
|
|
|
150
150
|
nickname: z.string().optional(),
|
|
151
151
|
});
|
|
152
152
|
|
|
153
|
-
const fields =
|
|
153
|
+
const fields = deriveConfigFields(schema);
|
|
154
154
|
const nickname = fields.find((f) => f.path === 'nickname');
|
|
155
155
|
expect(nickname?.required).toBe(false);
|
|
156
156
|
});
|
|
@@ -2,7 +2,7 @@ import { describe, expect, test } from 'bun:test';
|
|
|
2
2
|
import { z } from 'zod';
|
|
3
3
|
|
|
4
4
|
import { env, secret } from '../extensions.js';
|
|
5
|
-
import {
|
|
5
|
+
import { deriveConfigProvenance } from '../derive-provenance.js';
|
|
6
6
|
|
|
7
7
|
const schema = z.object({
|
|
8
8
|
debug: z.boolean().default(false),
|
|
@@ -10,10 +10,10 @@ const schema = z.object({
|
|
|
10
10
|
port: z.number().default(3000),
|
|
11
11
|
});
|
|
12
12
|
|
|
13
|
-
describe('
|
|
13
|
+
describe('deriveConfigProvenance', () => {
|
|
14
14
|
describe('default source', () => {
|
|
15
15
|
test('reports "default" when no other source provides value', () => {
|
|
16
|
-
const entries =
|
|
16
|
+
const entries = deriveConfigProvenance({
|
|
17
17
|
resolved: { debug: false, host: 'localhost', port: 3000 },
|
|
18
18
|
schema,
|
|
19
19
|
});
|
|
@@ -26,7 +26,7 @@ describe('explainConfig', () => {
|
|
|
26
26
|
|
|
27
27
|
describe('base overrides default', () => {
|
|
28
28
|
test('reports "base" when base provides value', () => {
|
|
29
|
-
const entries =
|
|
29
|
+
const entries = deriveConfigProvenance({
|
|
30
30
|
base: { host: 'base.example.com' },
|
|
31
31
|
resolved: { debug: false, host: 'base.example.com', port: 3000 },
|
|
32
32
|
schema,
|
|
@@ -38,27 +38,27 @@ describe('explainConfig', () => {
|
|
|
38
38
|
});
|
|
39
39
|
});
|
|
40
40
|
|
|
41
|
-
describe('
|
|
42
|
-
test('reports "
|
|
43
|
-
const entries =
|
|
41
|
+
describe('profile overrides base', () => {
|
|
42
|
+
test('reports "profile" when profile provides winning value', () => {
|
|
43
|
+
const entries = deriveConfigProvenance({
|
|
44
44
|
base: { host: 'base.example.com' },
|
|
45
|
-
|
|
46
|
-
resolved: { debug: false, host: '
|
|
45
|
+
profile: { host: 'profile.example.com' },
|
|
46
|
+
resolved: { debug: false, host: 'profile.example.com', port: 3000 },
|
|
47
47
|
schema,
|
|
48
48
|
});
|
|
49
49
|
|
|
50
50
|
const host = entries.find((e) => e.path === 'host');
|
|
51
|
-
expect(host?.source).toBe('
|
|
52
|
-
expect(host?.value).toBe('
|
|
51
|
+
expect(host?.source).toBe('profile');
|
|
52
|
+
expect(host?.value).toBe('profile.example.com');
|
|
53
53
|
});
|
|
54
54
|
});
|
|
55
55
|
|
|
56
|
-
describe('local overrides
|
|
56
|
+
describe('local overrides profile', () => {
|
|
57
57
|
test('reports "local" when local provides winning value', () => {
|
|
58
|
-
const entries =
|
|
58
|
+
const entries = deriveConfigProvenance({
|
|
59
59
|
base: { host: 'base.example.com' },
|
|
60
|
-
loadout: { host: 'loadout.example.com' },
|
|
61
60
|
local: { host: 'local.example.com' },
|
|
61
|
+
profile: { host: 'profile.example.com' },
|
|
62
62
|
resolved: { debug: false, host: 'local.example.com', port: 3000 },
|
|
63
63
|
schema,
|
|
64
64
|
});
|
|
@@ -75,7 +75,7 @@ describe('explainConfig', () => {
|
|
|
75
75
|
port: z.number().default(3000),
|
|
76
76
|
});
|
|
77
77
|
|
|
78
|
-
const entries =
|
|
78
|
+
const entries = deriveConfigProvenance({
|
|
79
79
|
base: { host: 'base.example.com' },
|
|
80
80
|
env: { APP_HOST: 'env.example.com' },
|
|
81
81
|
resolved: { host: 'env.example.com', port: 3000 },
|
|
@@ -96,7 +96,7 @@ describe('explainConfig', () => {
|
|
|
96
96
|
.optional(),
|
|
97
97
|
});
|
|
98
98
|
|
|
99
|
-
const entries =
|
|
99
|
+
const entries = deriveConfigProvenance({
|
|
100
100
|
env: { DB_HOST: 'env.example.com' },
|
|
101
101
|
resolved: { db: { host: 'env.example.com' } },
|
|
102
102
|
schema: envSchema,
|
|
@@ -115,7 +115,7 @@ describe('explainConfig', () => {
|
|
|
115
115
|
host: z.string().default('localhost'),
|
|
116
116
|
});
|
|
117
117
|
|
|
118
|
-
const entries =
|
|
118
|
+
const entries = deriveConfigProvenance({
|
|
119
119
|
env: { API_KEY: 'super-secret-key' },
|
|
120
120
|
resolved: { apiKey: 'super-secret-key', host: 'localhost' },
|
|
121
121
|
schema: secretSchema,
|
|
@@ -127,7 +127,7 @@ describe('explainConfig', () => {
|
|
|
127
127
|
});
|
|
128
128
|
|
|
129
129
|
test('does not redact non-secret fields', () => {
|
|
130
|
-
const entries =
|
|
130
|
+
const entries = deriveConfigProvenance({
|
|
131
131
|
resolved: { debug: false, host: 'localhost', port: 3000 },
|
|
132
132
|
schema,
|
|
133
133
|
});
|