@ontrails/config 1.0.0-beta.14 → 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 +7 -0
- package/README.md +20 -28
- 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 -15
- package/dist/compose.d.ts.map +1 -1
- package/dist/compose.js +7 -9
- 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-provision.js → config-resource.js} +6 -6
- 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 +1 -1
- 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 +1 -1
- 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} +3 -3
- package/dist/derive-provenance.js.map +1 -0
- 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/registry.d.ts +2 -2
- package/dist/resolve.d.ts +6 -6
- package/dist/resolve.d.ts.map +1 -1
- package/dist/resolve.js +7 -7
- 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 +3 -3
- 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 +5 -5
- 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 +8 -8
- 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 +7 -7
- package/dist/trails/config-init.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/tsconfig.tests.json +10 -0
- package/tsconfig.tsbuildinfo +1 -1
- package/dist/config-gate.d.ts +0 -11
- package/dist/config-gate.d.ts.map +0 -1
- package/dist/config-gate.js +0 -6
- package/dist/config-gate.js.map +0 -1
- package/dist/config-provision.d.ts +0 -3
- package/dist/config-provision.d.ts.map +0 -1
- package/dist/config-provision.js.map +0 -1
- package/dist/config-service.d.ts +0 -3
- package/dist/config-service.d.ts.map +0 -1
- package/dist/config-service.js +0 -26
- 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
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config-explain.js","sourceRoot":"","sources":["../../src/trails/config-explain.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AAC/C,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"config-explain.js","sourceRoot":"","sources":["../../src/trails/config-explain.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AAC/C,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAEvD,OAAO,EAAE,sBAAsB,EAAE,MAAM,yBAAyB,CAAC;AAGjE,MAAM,qBAAqB,GAAG,CAAC,CAAC,MAAM,CAAC;IACrC,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE;IAChB,QAAQ,EAAE,CAAC,CAAC,OAAO,EAAE;IACrB,MAAM,EAAE,CAAC,CAAC,MAAM,EAAE;IAClB,KAAK,EAAE,CAAC,CAAC,OAAO,EAAE;CACnB,CAAC,CAAC;AAEH,MAAM,YAAY,GAAG,CAAC,CAAC,MAAM,CAAC;IAC5B,OAAO,EAAE,CAAC,CAAC,KAAK,CAAC,qBAAqB,CAAC;CACxC,CAAC,CAAC;AAEH,+DAA+D;AAC/D,MAAM,YAAY,GAAG,CACnB,OAA6C,EAC7C,MAAc,EACwB,EAAE,CACxC,MAAM;IACJ,CAAC,CAAC,OAAO,CAAC,MAAM,CACZ,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,IAAI,KAAK,MAAM,IAAI,KAAK,CAAC,IAAI,CAAC,UAAU,CAAC,GAAG,MAAM,GAAG,CAAC,CACxE;IACH,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AAO,GAAG,sBAAsB,CAAC,OAAO,CAAC,CAAC;QAChD,MAAM,QAAQ,GAAG,YAAY,CAAC,OAAO,EAAE,KAAK,CAAC,IAAI,CAAC,CAAC;QACnD,OAAO,MAAM,CAAC,EAAE,CAAC,EAAE,OAAO,EAAE,CAAC,GAAG,QAAQ,CAAC,EAAE,CAAC,CAAC;IAC/C,CAAC;IACD,QAAQ,EAAE;QACR;YACE,KAAK,EAAE,EAAE;YACT,IAAI,EAAE,oBAAoB;SAC3B;KACF;IACD,KAAK,EAAE,CAAC,CAAC,MAAM,CAAC;QACd,IAAI,EAAE,CAAC;aACJ,MAAM,EAAE;aACR,QAAQ,CAAC,iDAAiD,CAAC;aAC3D,OAAO,CAAC,EAAE,CAAC;KACf,CAAC;IACF,MAAM,EAAE,MAAM;IACd,IAAI,EAAE,EAAE,QAAQ,EAAE,gBAAgB,EAAE;IACpC,MAAM,EAAE,YAAY;IACpB,SAAS,EAAE,CAAC,cAAc,CAAC;CAC5B,CAAC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config-init.d.ts","sourceRoot":"","sources":["../../src/trails/config-init.ts"],"names":[],"mappings":"AA+DA,eAAO,MAAM,UAAU;;;;;;;
|
|
1
|
+
{"version":3,"file":"config-init.d.ts","sourceRoot":"","sources":["../../src/trails/config-init.ts"],"names":[],"mappings":"AA+DA,eAAO,MAAM,UAAU;;;;;;;SAgCrB,CAAC"}
|
|
@@ -11,8 +11,8 @@ import { join } from 'node:path';
|
|
|
11
11
|
import { mkdir } from 'node:fs/promises';
|
|
12
12
|
import { Result, trail } from '@ontrails/core';
|
|
13
13
|
import { z as zod } from 'zod';
|
|
14
|
-
import {
|
|
15
|
-
import {
|
|
14
|
+
import { configResource } from '../config-resource.js';
|
|
15
|
+
import { deriveConfigEnvExample, deriveConfigExample, deriveConfigJsonSchema, } from '../derive/index.js';
|
|
16
16
|
const formatEnum = zod.enum(['toml', 'json', 'jsonc', 'yaml']);
|
|
17
17
|
const outputSchema = zod.object({
|
|
18
18
|
content: zod.string(),
|
|
@@ -22,13 +22,13 @@ const outputSchema = zod.object({
|
|
|
22
22
|
/** Collect artifacts to write: [relativeName, content] pairs. */
|
|
23
23
|
const collectArtifacts = (schema) => {
|
|
24
24
|
const artifacts = [];
|
|
25
|
-
const envContent =
|
|
25
|
+
const envContent = deriveConfigEnvExample(schema);
|
|
26
26
|
if (envContent.length > 0) {
|
|
27
27
|
artifacts.push(['.env.example', envContent]);
|
|
28
28
|
}
|
|
29
29
|
artifacts.push([
|
|
30
30
|
'.schema.json',
|
|
31
|
-
JSON.stringify(
|
|
31
|
+
JSON.stringify(deriveConfigJsonSchema(schema), null, 2),
|
|
32
32
|
]);
|
|
33
33
|
return artifacts;
|
|
34
34
|
};
|
|
@@ -46,9 +46,9 @@ const writeArtifacts = async (dir, schema) => {
|
|
|
46
46
|
};
|
|
47
47
|
export const configInit = trail('config.init', {
|
|
48
48
|
blaze: async (input, ctx) => {
|
|
49
|
-
const state =
|
|
49
|
+
const state = configResource.from(ctx);
|
|
50
50
|
const schema = state.schema;
|
|
51
|
-
const content =
|
|
51
|
+
const content = deriveConfigExample(schema, input.format);
|
|
52
52
|
if (input.dir) {
|
|
53
53
|
const writtenFiles = await writeArtifacts(input.dir, schema);
|
|
54
54
|
return Result.ok({ content, format: input.format, writtenFiles });
|
|
@@ -73,6 +73,6 @@ export const configInit = trail('config.init', {
|
|
|
73
73
|
intent: 'write',
|
|
74
74
|
meta: { category: 'infrastructure' },
|
|
75
75
|
output: outputSchema,
|
|
76
|
-
|
|
76
|
+
resources: [configResource],
|
|
77
77
|
});
|
|
78
78
|
//# sourceMappingURL=config-init.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config-init.js","sourceRoot":"","sources":["../../src/trails/config-init.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,KAAK,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MAAM,CAAC,CAAC;YAC7D,OAAO,MAAM,CAAC,EAAE,CAAC,EAAE,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,MAAM,EAAE,YAAY,EAAE,CAAC,CAAC;QACpE,CAAC;QAED,OAAO,MAAM,CAAC,EAAE,CAAC,EAAE,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,MAAM,EAAE,CAAC,CAAC;IACtD,CAAC;IACD,QAAQ,EAAE;QACR;YACE,KAAK,EAAE,EAAE;YACT,IAAI,EAAE,uBAAuB;SAC9B;KACF;IACD,KAAK,EAAE,GAAG,CAAC,MAAM,CAAC;QAChB,GAAG,EAAE,GAAG;aACL,MAAM,EAAE;aACR,QAAQ,CAAC,2CAA2C,CAAC;aACrD,QAAQ,EAAE;QACb,MAAM,EAAE,UAAU;aACf,QAAQ,CAAC,2CAA2C,CAAC;aACrD,OAAO,CAAC,MAAM,CAAC;KACnB,CAAC;IACF,MAAM,EAAE,OAAO;IACf,IAAI,EAAE,EAAE,QAAQ,EAAE,gBAAgB,EAAE;IACpC,MAAM,EAAE,YAAY;IACpB,SAAS,EAAE,CAAC,cAAc,CAAC;CAC5B,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ontrails/config",
|
|
3
|
-
"version": "1.0.0-beta.
|
|
3
|
+
"version": "1.0.0-beta.15",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": "./src/index.ts",
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
"clean": "rm -rf dist *.tsbuildinfo"
|
|
15
15
|
},
|
|
16
16
|
"peerDependencies": {
|
|
17
|
-
"@ontrails/core": "^1.0.0-beta.
|
|
17
|
+
"@ontrails/core": "^1.0.0-beta.14",
|
|
18
18
|
"zod": "^4.3.5"
|
|
19
19
|
}
|
|
20
20
|
}
|
|
@@ -6,7 +6,7 @@ import { z } from 'zod';
|
|
|
6
6
|
|
|
7
7
|
import type { AppConfig } from '../app-config.js';
|
|
8
8
|
import { appConfig } from '../app-config.js';
|
|
9
|
-
import {
|
|
9
|
+
import { deriveConfigFields } from '../derive-fields.js';
|
|
10
10
|
import { checkConfig } from '../doctor.js';
|
|
11
11
|
import { configRef } from '../ref.js';
|
|
12
12
|
|
|
@@ -45,9 +45,9 @@ describe('appConfig()', () => {
|
|
|
45
45
|
expect(config.schema).toBe(testSchema);
|
|
46
46
|
});
|
|
47
47
|
|
|
48
|
-
test('defaults formats to toml, json, yaml when not specified', () => {
|
|
48
|
+
test('defaults formats to toml, json, jsonc, yaml when not specified', () => {
|
|
49
49
|
const config = appConfig('myapp', { schema: testSchema });
|
|
50
|
-
expect(config.formats).toEqual(['toml', 'json', 'yaml']);
|
|
50
|
+
expect(config.formats).toEqual(['toml', 'json', 'jsonc', 'yaml']);
|
|
51
51
|
});
|
|
52
52
|
|
|
53
53
|
test('uses provided formats', () => {
|
|
@@ -218,6 +218,19 @@ describe('appConfig()', () => {
|
|
|
218
218
|
expect(result.unwrap().output).toBe('./from-toml');
|
|
219
219
|
});
|
|
220
220
|
|
|
221
|
+
test('includes jsonc in the default discovery set', async () => {
|
|
222
|
+
await Bun.write(
|
|
223
|
+
join(tempDir, 'myapp.config.jsonc'),
|
|
224
|
+
'{\n // comment\n "output": "./from-jsonc"\n}\n'
|
|
225
|
+
);
|
|
226
|
+
|
|
227
|
+
const config = appConfig('myapp', { schema: testSchema });
|
|
228
|
+
const result = await config.resolve({ cwd: tempDir });
|
|
229
|
+
|
|
230
|
+
expect(result.isOk()).toBe(true);
|
|
231
|
+
expect(result.unwrap().output).toBe('./from-jsonc');
|
|
232
|
+
});
|
|
233
|
+
|
|
221
234
|
test('returns Result.err when no config file found', async () => {
|
|
222
235
|
const config = appConfig('myapp', { schema: testSchema });
|
|
223
236
|
const result = await config.resolve({ cwd: tempDir });
|
|
@@ -289,10 +302,10 @@ describe('appConfig()', () => {
|
|
|
289
302
|
});
|
|
290
303
|
|
|
291
304
|
describe('method delegations', () => {
|
|
292
|
-
test('describe() returns same result as
|
|
305
|
+
test('describe() returns same result as deriveConfigFields(schema)', () => {
|
|
293
306
|
const config = appConfig('myapp', { schema: testSchema });
|
|
294
307
|
const methodResult = config.describe();
|
|
295
|
-
const standaloneResult =
|
|
308
|
+
const standaloneResult = deriveConfigFields(testSchema);
|
|
296
309
|
|
|
297
310
|
expect(methodResult).toEqual(standaloneResult);
|
|
298
311
|
});
|
|
@@ -315,7 +328,7 @@ describe('appConfig()', () => {
|
|
|
315
328
|
expect(methodResult).toEqual(standaloneResult);
|
|
316
329
|
});
|
|
317
330
|
|
|
318
|
-
test('explain() delegates to
|
|
331
|
+
test('explain() delegates to deriveConfigProvenance with bound schema', () => {
|
|
319
332
|
const config = appConfig('myapp', { schema: testSchema });
|
|
320
333
|
const resolved = { output: './dist', verbose: true };
|
|
321
334
|
|
|
@@ -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);
|