@ontrails/config 1.0.0-beta.12 → 1.0.0-beta.14

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.
Files changed (73) hide show
  1. package/.turbo/turbo-lint.log +1 -1
  2. package/CHANGELOG.md +44 -5
  3. package/README.md +212 -0
  4. package/dist/compose.d.ts +15 -11
  5. package/dist/compose.d.ts.map +1 -1
  6. package/dist/compose.js +9 -7
  7. package/dist/compose.js.map +1 -1
  8. package/dist/config-gate.d.ts +11 -0
  9. package/dist/config-gate.d.ts.map +1 -0
  10. package/dist/config-gate.js +6 -0
  11. package/dist/config-gate.js.map +1 -0
  12. package/dist/config-provision.d.ts +3 -0
  13. package/dist/config-provision.d.ts.map +1 -0
  14. package/dist/config-provision.js +26 -0
  15. package/dist/config-provision.js.map +1 -0
  16. package/dist/doctor.d.ts.map +1 -1
  17. package/dist/doctor.js +1 -37
  18. package/dist/doctor.js.map +1 -1
  19. package/dist/explain.d.ts.map +1 -1
  20. package/dist/explain.js +5 -18
  21. package/dist/explain.js.map +1 -1
  22. package/dist/extensions.d.ts +1 -1
  23. package/dist/extensions.js +1 -1
  24. package/dist/generate/example.d.ts.map +1 -1
  25. package/dist/generate/example.js +20 -18
  26. package/dist/generate/example.js.map +1 -1
  27. package/dist/generate/helpers.js +1 -1
  28. package/dist/generate/helpers.js.map +1 -1
  29. package/dist/index.d.ts +3 -3
  30. package/dist/index.d.ts.map +1 -1
  31. package/dist/index.js +3 -3
  32. package/dist/index.js.map +1 -1
  33. package/dist/ref.d.ts +8 -3
  34. package/dist/ref.d.ts.map +1 -1
  35. package/dist/ref.js +8 -3
  36. package/dist/ref.js.map +1 -1
  37. package/dist/registry.d.ts +1 -1
  38. package/dist/resolve.d.ts.map +1 -1
  39. package/dist/resolve.js +4 -1
  40. package/dist/resolve.js.map +1 -1
  41. package/dist/trails/config-check.js +12 -12
  42. package/dist/trails/config-check.js.map +1 -1
  43. package/dist/trails/config-describe.js +8 -8
  44. package/dist/trails/config-describe.js.map +1 -1
  45. package/dist/trails/config-explain.js +12 -12
  46. package/dist/trails/config-explain.js.map +1 -1
  47. package/dist/trails/config-init.js +13 -13
  48. package/dist/trails/config-init.js.map +1 -1
  49. package/dist/workspace.d.ts.map +1 -1
  50. package/dist/workspace.js +5 -0
  51. package/dist/workspace.js.map +1 -1
  52. package/package.json +2 -2
  53. package/src/__tests__/compose.test.ts +15 -15
  54. package/src/__tests__/config-check.test.ts +15 -15
  55. package/src/__tests__/config-describe.test.ts +15 -15
  56. package/src/__tests__/config-explain.test.ts +15 -15
  57. package/src/__tests__/{config-layer.test.ts → config-gate.test.ts} +9 -9
  58. package/src/__tests__/config-init.test.ts +19 -19
  59. package/src/__tests__/{config-service.test.ts → config-provision.test.ts} +13 -13
  60. package/src/compose.ts +22 -16
  61. package/src/config-gate.ts +15 -0
  62. package/src/{config-service.ts → config-provision.ts} +6 -6
  63. package/src/explain.ts +6 -6
  64. package/src/extensions.ts +1 -1
  65. package/src/index.ts +8 -3
  66. package/src/registry.ts +1 -1
  67. package/src/trails/config-check.ts +12 -12
  68. package/src/trails/config-describe.ts +8 -8
  69. package/src/trails/config-explain.ts +12 -12
  70. package/src/trails/config-init.ts +15 -15
  71. package/src/workspace.ts +5 -0
  72. package/tsconfig.tsbuildinfo +1 -1
  73. package/src/config-layer.ts +0 -15
package/src/compose.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  /**
2
- * Config composition utilities for services.
2
+ * Config composition utilities for provisions.
3
3
  *
4
- * Collects config schemas from service declarations so they can be
4
+ * Collects config schemas from provision declarations so they can be
5
5
  * composed into a unified config structure via `defineConfig`.
6
6
  */
7
7
 
@@ -11,14 +11,17 @@ import type { z } from 'zod';
11
11
  // Types
12
12
  // ---------------------------------------------------------------------------
13
13
 
14
- /** A service config schema entry extracted from a service declaration. */
15
- export interface ServiceConfigEntry {
16
- readonly serviceId: string;
14
+ /** A provision config schema entry extracted from a provision declaration. */
15
+ export interface ProvisionConfigEntry {
16
+ readonly provisionId: string;
17
17
  readonly schema: z.ZodType;
18
18
  }
19
19
 
20
- /** Minimal shape needed to extract config from a service-like object. */
21
- interface ServiceWithOptionalConfig {
20
+ /** Backward-compatible alias while the migration is in flight. */
21
+ export type ServiceConfigEntry = ProvisionConfigEntry;
22
+
23
+ /** Minimal shape needed to extract config from a provision-like object. */
24
+ interface ProvisionWithOptionalConfig {
22
25
  readonly id: string;
23
26
  readonly config?: z.ZodType | undefined;
24
27
  }
@@ -28,19 +31,22 @@ interface ServiceWithOptionalConfig {
28
31
  // ---------------------------------------------------------------------------
29
32
 
30
33
  /**
31
- * Collect config schemas from services that declare them.
34
+ * Collect config schemas from provisions that declare them.
32
35
  *
33
- * Returns entries keyed by service ID for composition into `defineConfig`.
34
- * Services without a `config` schema are excluded.
36
+ * Returns entries keyed by provision ID for composition into `defineConfig`.
37
+ * Provisions without a `config` schema are excluded.
35
38
  */
36
- export const collectServiceConfigs = (
37
- services: readonly ServiceWithOptionalConfig[]
38
- ): ServiceConfigEntry[] =>
39
- services
39
+ export const collectProvisionConfigs = (
40
+ provisions: readonly ProvisionWithOptionalConfig[]
41
+ ): ProvisionConfigEntry[] =>
42
+ provisions
40
43
  .filter(
41
44
  (
42
45
  svc
43
- ): svc is ServiceWithOptionalConfig & { readonly config: z.ZodType } =>
46
+ ): svc is ProvisionWithOptionalConfig & { readonly config: z.ZodType } =>
44
47
  svc.config !== undefined
45
48
  )
46
- .map((svc) => ({ schema: svc.config, serviceId: svc.id }));
49
+ .map((svc) => ({ provisionId: svc.id, schema: svc.config }));
50
+
51
+ /** Backward-compatible alias while the migration is in flight. */
52
+ export const collectServiceConfigs = collectProvisionConfigs;
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Config gate — attaches resolved config to the execution context.
3
+ *
4
+ * For v1, the gate is a pass-through: config resolution happens at
5
+ * bootstrap time and the provision pipeline (TRL-91) injects the resolved
6
+ * config before any trail runs. The gate reserves a named slot so future
7
+ * versions can add per-trail config overrides or validation.
8
+ */
9
+ import type { Gate } from '@ontrails/core';
10
+
11
+ export const configGate: Gate = {
12
+ description: 'Ensures resolved config is available in the execution context',
13
+ name: 'config',
14
+ wrap: (_trail, impl) => (input, ctx) => impl(input, ctx),
15
+ };
@@ -1,17 +1,17 @@
1
1
  /**
2
- * Config service — manages resolved config lifecycle.
2
+ * Config provision — manages resolved config lifecycle.
3
3
  *
4
4
  * The config is resolved during bootstrap (two-phase init per ADR-010)
5
- * and registered via `registerConfigState`. This service reads from the
6
- * global registry so trails can access it through `configService.from(ctx)`.
5
+ * and registered via `registerConfigState`. This provision reads from the
6
+ * global registry so trails can access it through `configProvision.from(ctx)`.
7
7
  */
8
- import { InternalError, Result, service } from '@ontrails/core';
8
+ import { InternalError, Result, provision } from '@ontrails/core';
9
9
  import { z } from 'zod';
10
10
 
11
11
  import type { ConfigState } from './registry.js';
12
12
  import { getConfigState } from './registry.js';
13
13
 
14
- export const configService = service<ConfigState>('config', {
14
+ export const configProvision = provision<ConfigState>('config', {
15
15
  create: () => {
16
16
  const state = getConfigState();
17
17
  if (state === undefined) {
@@ -24,7 +24,7 @@ export const configService = service<ConfigState>('config', {
24
24
  return Result.ok(state);
25
25
  },
26
26
  description: 'Resolved application configuration',
27
- metadata: { category: 'infrastructure' },
27
+ meta: { category: 'infrastructure' },
28
28
  mock: (): ConfigState => ({
29
29
  resolved: {},
30
30
  schema: z.object({}),
package/src/explain.ts CHANGED
@@ -64,8 +64,8 @@ const buildSecretSet = (
64
64
  return result;
65
65
  };
66
66
 
67
- /** Source layers in reverse precedence order for winner detection. */
68
- type SourceLayer = readonly [
67
+ /** Source entries in reverse precedence order for winner detection. */
68
+ type SourceEntry = readonly [
69
69
  name: ProvenanceEntry['source'],
70
70
  values: Record<string, unknown> | undefined,
71
71
  ];
@@ -74,7 +74,7 @@ type SourceLayer = readonly [
74
74
  const determineSource = (
75
75
  path: string,
76
76
  resolved: Record<string, unknown>,
77
- layers: readonly SourceLayer[],
77
+ sources: readonly SourceEntry[],
78
78
  envMap: Map<string, string>,
79
79
  envVars: Record<string, string | undefined> | undefined
80
80
  ): ProvenanceEntry['source'] => {
@@ -86,7 +86,7 @@ const determineSource = (
86
86
  }
87
87
 
88
88
  const resolvedValue = getAtPath(resolved, path);
89
- for (const [name, values] of layers) {
89
+ for (const [name, values] of sources) {
90
90
  if (values && getAtPath(values, path) === resolvedValue) {
91
91
  return name;
92
92
  }
@@ -144,7 +144,7 @@ export const explainConfig = <T extends z.ZodType>(
144
144
  const envMap = buildEnvMap(objSchema);
145
145
  const secretSet = buildSecretSet(objSchema);
146
146
 
147
- const layers: readonly SourceLayer[] = [
147
+ const sources: readonly SourceEntry[] = [
148
148
  ['local', options.local],
149
149
  ['loadout', options.loadout],
150
150
  ['base', options.base],
@@ -156,7 +156,7 @@ export const explainConfig = <T extends z.ZodType>(
156
156
  const source = determineSource(
157
157
  path,
158
158
  options.resolved,
159
- layers,
159
+ sources,
160
160
  envMap,
161
161
  options.env
162
162
  );
package/src/extensions.ts CHANGED
@@ -34,7 +34,7 @@ export const secret = <T extends z.ZodType>(schema: T): T =>
34
34
  * standard key. We set `deprecated: true` so Zod-native tooling (schema
35
35
  * serializers, OpenAPI generators) recognises the field as deprecated, and store
36
36
  * the human-readable message under `deprecationMessage` for our own
37
- * `collectConfigMeta` / survey / explain surfaces.
37
+ * `collectConfigMeta` / survey / explain trailheads.
38
38
  *
39
39
  * Must be called BEFORE `.default()`, `.optional()`, or other transforms
40
40
  * so that the metadata lives on the inner type where `collectConfigMeta`
package/src/index.ts CHANGED
@@ -7,7 +7,12 @@ export {
7
7
  type ResolveOptions,
8
8
  } from './app-config.js';
9
9
  export { collectConfigMeta } from './collect.js';
10
- export { collectServiceConfigs, type ServiceConfigEntry } from './compose.js';
10
+ export {
11
+ collectProvisionConfigs,
12
+ collectServiceConfigs,
13
+ type ProvisionConfigEntry,
14
+ type ServiceConfigEntry,
15
+ } from './compose.js';
11
16
  export { defineConfig, type DefineConfigOptions } from './define-config.js';
12
17
  export { describeConfig, type FieldDescription } from './describe.js';
13
18
  export {
@@ -26,8 +31,8 @@ export {
26
31
  generateExample,
27
32
  generateJsonSchema,
28
33
  } from './generate/index.js';
29
- export { configLayer } from './config-layer.js';
30
- export { configService } from './config-service.js';
34
+ export { configGate } from './config-gate.js';
35
+ export { configProvision } from './config-provision.js';
31
36
  export {
32
37
  clearConfigState,
33
38
  type ConfigState,
package/src/registry.ts CHANGED
@@ -2,7 +2,7 @@
2
2
  * Module-level config state registry.
3
3
  *
4
4
  * Config is resolved once at bootstrap (two-phase init per ADR-010) and
5
- * registered here so `configService` can surface it to trails. This is
5
+ * registered here so `configProvision` can expose it to trailheads. This is
6
6
  * a process-level singleton — config resolution is inherently global.
7
7
  */
8
8
  import type { z } from 'zod';
@@ -7,7 +7,7 @@
7
7
  import { Result, trail } from '@ontrails/core';
8
8
  import { z } from 'zod';
9
9
 
10
- import { configService } from '../config-service.js';
10
+ import { configProvision } from '../config-provision.js';
11
11
  import { checkConfig } from '../doctor.js';
12
12
  import { deepMerge } from '../merge.js';
13
13
 
@@ -32,6 +32,15 @@ const mergeValues = (
32
32
  };
33
33
 
34
34
  export const configCheck = trail('config.check', {
35
+ blaze: (input, ctx) => {
36
+ const state = configProvision.from(ctx);
37
+ const effective = mergeValues(state.resolved, input.values);
38
+ const checked = checkConfig(state.schema, effective);
39
+ return Result.ok({
40
+ diagnostics: [...checked.diagnostics],
41
+ valid: checked.valid,
42
+ });
43
+ },
35
44
  examples: [
36
45
  {
37
46
  input: {},
@@ -45,16 +54,7 @@ export const configCheck = trail('config.check', {
45
54
  .default({}),
46
55
  }),
47
56
  intent: 'read',
48
- metadata: { category: 'infrastructure' },
57
+ meta: { category: 'infrastructure' },
49
58
  output: outputSchema,
50
- run: (input, ctx) => {
51
- const state = configService.from(ctx);
52
- const effective = mergeValues(state.resolved, input.values);
53
- const checked = checkConfig(state.schema, effective);
54
- return Result.ok({
55
- diagnostics: [...checked.diagnostics],
56
- valid: checked.valid,
57
- });
58
- },
59
- services: [configService],
59
+ provisions: [configProvision],
60
60
  });
@@ -7,7 +7,7 @@
7
7
  import { Result, trail } from '@ontrails/core';
8
8
  import { z } from 'zod';
9
9
 
10
- import { configService } from '../config-service.js';
10
+ import { configProvision } from '../config-provision.js';
11
11
  import { describeConfig } from '../describe.js';
12
12
 
13
13
  const fieldSchema = z.object({
@@ -25,6 +25,11 @@ const outputSchema = z.object({
25
25
  });
26
26
 
27
27
  export const configDescribe = trail('config.describe', {
28
+ blaze: (_input, ctx) => {
29
+ const state = configProvision.from(ctx);
30
+ const fields = describeConfig(state.schema);
31
+ return Result.ok({ fields: [...fields] });
32
+ },
28
33
  examples: [
29
34
  {
30
35
  input: {},
@@ -33,12 +38,7 @@ export const configDescribe = trail('config.describe', {
33
38
  ],
34
39
  input: z.object({}),
35
40
  intent: 'read',
36
- metadata: { category: 'infrastructure' },
41
+ meta: { category: 'infrastructure' },
37
42
  output: outputSchema,
38
- run: (_input, ctx) => {
39
- const state = configService.from(ctx);
40
- const fields = describeConfig(state.schema);
41
- return Result.ok({ fields: [...fields] });
42
- },
43
- services: [configService],
43
+ provisions: [configProvision],
44
44
  });
@@ -7,7 +7,7 @@
7
7
  import { Result, trail } from '@ontrails/core';
8
8
  import { z } from 'zod';
9
9
 
10
- import { configService } from '../config-service.js';
10
+ import { configProvision } from '../config-provision.js';
11
11
  import type { ExplainConfigOptions } from '../explain.js';
12
12
  import { explainConfig } from '../explain.js';
13
13
  import type { ConfigState } from '../registry.js';
@@ -34,7 +34,7 @@ const filterByPath = (
34
34
  )
35
35
  : entries;
36
36
 
37
- /** Build ExplainConfigOptions from ConfigState, omitting undefined layers. */
37
+ /** Build ExplainConfigOptions from ConfigState, omitting undefined source overrides. */
38
38
  const toExplainOptions = (
39
39
  state: ConfigState
40
40
  ): ExplainConfigOptions<typeof state.schema> => {
@@ -48,7 +48,7 @@ const toExplainOptions = (
48
48
  return base;
49
49
  };
50
50
 
51
- /** Enrich explain options with env and layer overrides from state. */
51
+ /** Enrich explain options with env and source overrides from state. */
52
52
  const enrichOptions = (
53
53
  state: ConfigState,
54
54
  options: ExplainConfigOptions<typeof state.schema>
@@ -67,6 +67,13 @@ const enrichOptions = (
67
67
  };
68
68
 
69
69
  export const configExplain = trail('config.explain', {
70
+ blaze: (input, ctx) => {
71
+ const state = configProvision.from(ctx);
72
+ const options = enrichOptions(state, toExplainOptions(state));
73
+ const entries = explainConfig(options);
74
+ const filtered = filterByPath(entries, input.path);
75
+ return Result.ok({ entries: [...filtered] });
76
+ },
70
77
  examples: [
71
78
  {
72
79
  input: {},
@@ -80,14 +87,7 @@ export const configExplain = trail('config.explain', {
80
87
  .default(''),
81
88
  }),
82
89
  intent: 'read',
83
- metadata: { category: 'infrastructure' },
90
+ meta: { category: 'infrastructure' },
84
91
  output: outputSchema,
85
- run: (input, ctx) => {
86
- const state = configService.from(ctx);
87
- const options = enrichOptions(state, toExplainOptions(state));
88
- const entries = explainConfig(options);
89
- const filtered = filterByPath(entries, input.path);
90
- return Result.ok({ entries: [...filtered] });
91
- },
92
- services: [configService],
92
+ provisions: [configProvision],
93
93
  });
@@ -14,7 +14,7 @@ import { Result, trail } from '@ontrails/core';
14
14
  import type { z } from 'zod';
15
15
  import { z as zod } from 'zod';
16
16
 
17
- import { configService } from '../config-service.js';
17
+ import { configProvision } from '../config-provision.js';
18
18
  import {
19
19
  generateEnvExample,
20
20
  generateExample,
@@ -62,6 +62,18 @@ const writeArtifacts = async (
62
62
  };
63
63
 
64
64
  export const configInit = trail('config.init', {
65
+ blaze: async (input, ctx) => {
66
+ const state = configProvision.from(ctx);
67
+ const schema = state.schema as z.ZodObject<Record<string, z.ZodType>>;
68
+ const content = generateExample(schema, input.format);
69
+
70
+ if (input.dir) {
71
+ const writtenFiles = await writeArtifacts(input.dir, schema);
72
+ return Result.ok({ content, format: input.format, writtenFiles });
73
+ }
74
+
75
+ return Result.ok({ content, format: input.format });
76
+ },
65
77
  examples: [
66
78
  {
67
79
  input: {},
@@ -78,19 +90,7 @@ export const configInit = trail('config.init', {
78
90
  .default('toml'),
79
91
  }),
80
92
  intent: 'write',
81
- metadata: { category: 'infrastructure' },
93
+ meta: { category: 'infrastructure' },
82
94
  output: outputSchema,
83
- run: async (input, ctx) => {
84
- const state = configService.from(ctx);
85
- const schema = state.schema as z.ZodObject<Record<string, z.ZodType>>;
86
- const content = generateExample(schema, input.format);
87
-
88
- if (input.dir) {
89
- const writtenFiles = await writeArtifacts(input.dir, schema);
90
- return Result.ok({ content, format: input.format, writtenFiles });
91
- }
92
-
93
- return Result.ok({ content, format: input.format });
94
- },
95
- services: [configService],
95
+ provisions: [configProvision],
96
96
  });
package/src/workspace.ts CHANGED
@@ -20,6 +20,11 @@ const GITIGNORE_CONTENT = [
20
20
  '# Generated artifacts',
21
21
  'generated/',
22
22
  '',
23
+ '# Shared Trails database',
24
+ 'trails.db',
25
+ 'trails.db-shm',
26
+ 'trails.db-wal',
27
+ '',
23
28
  ].join('\n');
24
29
 
25
30
  /**
@@ -1 +1 @@
1
- {"root":["./src/app-config.ts","./src/collect.ts","./src/compose.ts","./src/config-layer.ts","./src/config-service.ts","./src/define-config.ts","./src/describe.ts","./src/doctor.ts","./src/explain.ts","./src/extensions.ts","./src/index.ts","./src/merge.ts","./src/ref.ts","./src/registry.ts","./src/resolve.ts","./src/secret-heuristics.ts","./src/workspace.ts","./src/zod-utils.ts","./src/generate/env.ts","./src/generate/example.ts","./src/generate/helpers.ts","./src/generate/index.ts","./src/generate/json-schema.ts","./src/trails/config-check.ts","./src/trails/config-describe.ts","./src/trails/config-explain.ts","./src/trails/config-init.ts"],"version":"5.9.3"}
1
+ {"root":["./src/app-config.ts","./src/collect.ts","./src/compose.ts","./src/config-gate.ts","./src/config-provision.ts","./src/define-config.ts","./src/describe.ts","./src/doctor.ts","./src/explain.ts","./src/extensions.ts","./src/index.ts","./src/merge.ts","./src/ref.ts","./src/registry.ts","./src/resolve.ts","./src/secret-heuristics.ts","./src/workspace.ts","./src/zod-utils.ts","./src/generate/env.ts","./src/generate/example.ts","./src/generate/helpers.ts","./src/generate/index.ts","./src/generate/json-schema.ts","./src/trails/config-check.ts","./src/trails/config-describe.ts","./src/trails/config-explain.ts","./src/trails/config-init.ts"],"version":"5.9.3"}
@@ -1,15 +0,0 @@
1
- /**
2
- * Config layer — attaches resolved config to the execution context.
3
- *
4
- * For v1, the layer is a pass-through: config resolution happens at
5
- * bootstrap time and the service pipeline (TRL-91) injects the resolved
6
- * config before any trail runs. The layer reserves a named slot so
7
- * future versions can add per-trail config overrides or validation.
8
- */
9
- import type { Layer } from '@ontrails/core';
10
-
11
- export const configLayer: Layer = {
12
- description: 'Ensures resolved config is available in the execution context',
13
- name: 'config',
14
- wrap: (_trail, impl) => (input, ctx) => impl(input, ctx),
15
- };