Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions changelog.d/settings-file-and-resolver.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
- **TypeScript: a settings file for platform, product, size and secret store (ADR-0070, calls 5
and 13).** `.metaobjects/settings.json` sits beside `config.json`, and only TypeScript reads
it, so no port's config reader changes. It carries `targets`, `platforms`,
`resourceDefaults` (keyed by platform, then resource kind), `purposes`, `environments` and
`secrets.stores`, and may `extends` a shared estate file (a relative path or a package),
merged key by key with the nearer file winning. `@metaobjectsdev/sdk` adds `loadSettings` and
a resolver (`resolveTarget`, `resolveResource`, `resolveApp`, `resolveGeneratedStore`,
`resolveAdoptedStore`) that answers which target, product, size and store a node gets and
which layer and file each value came from. Experimental; no generator reads it yet, and a
project with no settings file sees no change. `metamodelVersion` does not move.
See `docs/features/settings.md`.
2 changes: 2 additions & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ docs/
│ ├── image-upload.md # view.image form control (TS-web)
│ ├── metadata-sources.md # where metadata comes from: sources, scope, discovery
│ ├── metadata-dependencies.md # building on a metadata model published elsewhere (FR-023)
│ ├── settings.md # .metaobjects/settings.json: platform, product, size and secret store, layered (TypeScript, ADR-0070)
│ ├── libraries.md # reusable declared design you opt into, a layer at a time (FR-043)
│ ├── reporting.md # dimensions, measures, segments, reports: vocabulary and load rules (FR-044)
│ ├── business-rules.md # operations, permission names and lifecycles: vocabulary, load rules, verify checks (ADR-0066)
Expand Down Expand Up @@ -80,6 +81,7 @@ this tree is documentation, not the source of truth.
| Compare what TS vs Java vs Kotlin vs C# vs Python emit for the same metadata | any [`features/*.md`](features/) — every feature shows all five ports side-by-side |
| Author metadata in YAML instead of JSON | [`features/yaml-authoring.md`](features/yaml-authoring.md) |
| Point the toolchain at metadata that lives somewhere other than `metaobjects/`, or scope what a project generates and migrates | [`features/metadata-sources.md`](features/metadata-sources.md) |
| Say which platform, product, size and secret store a deployment uses, layered from a shared estate file (`.metaobjects/settings.json`, TypeScript) | [`features/settings.md`](features/settings.md) |
| Build on a metadata model another repository publishes (`dependencies`, `meta deps sync`, overlay/extend across the boundary) | [`features/metadata-dependencies.md`](features/metadata-dependencies.md) |
| Adopt a design MetaObjects already ships — users/groups/roles, an LLM trace envelope — instead of authoring it (`libraries`, `meta eject <library>`) | [`features/libraries.md`](features/libraries.md) |
| Record what the system is supposed to do, and stop agents reviving retired features | [`features/requirements.md`](features/requirements.md) |
Expand Down
111 changes: 111 additions & 0 deletions docs/features/settings.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
# Settings: platform, product, size and secret store

The model says what runs and what is kept, in which environment and at which locations. It never
names a platform, a product, a size or a secret store. Those are **settings**, and they live in
their own file, `.metaobjects/settings.json`, beside `config.json` (ADR-0070, calls 5 and 13).

**TypeScript only, and experimental.** Only TypeScript reads the settings file, so no other port's
config reader changes and `config.json` gains no keys. The reader and the resolver ship in
`@metaobjectsdev/sdk` in 1.4.0; no generator reads them yet, and the file's shape may change in a
minor release while the systems work lands. A project with no settings file has no settings,
and nothing changes for it.

## The file

```json
{
"extends": "../estate/settings.json",
"targets": {
"lab": { "platform": "docker", "host": "lab-01.example", "country": "NL" }
},
"platforms": {
"docker": { "emitter": "compose" }
},
"resourceDefaults": {
"docker": { "rdb": { "product": "postgres", "version": "18" } }
},
"purposes": {
"production": { "replicas": 2, "rdb": { "backupDays": 35 } }
},
"environments": {
"Production": {
"apps": { "shop::Shop.api": { "replicas": 4 } },
"provisions": { "shop-db": { "backupDays": 14 } }
}
},
"secrets": {
"stores": { "vault": { "product": "openbao", "address": "https://bao.example" } },
"generated": { "docker": "vault" },
"adopted": "vault"
}
}
```

| Block | Says | Keyed by |
|---|---|---|
| `extends` | Another settings file this one builds on: a path relative to this file, or a package specifier | |
| `targets` | The places things can be put: a `platform`, a `country`, the platform's `region` and `zones`, and the platform's own identifiers (`account`, `project`, `host`) | A name you choose |
| `platforms` | For each platform, its `emitter`, and how it runs apps, schedules jobs and routes traffic | Platform |
| `resourceDefaults` | The `product` and `version` for each kind of resource | Platform, then resource kind |
| `purposes` | Sizes and counts for every environment of that purpose: plain values for apps, a block per resource kind | `production`, `staging`, `test`, `development` |
| `environments` | What differs in one environment: an app's size or tag (`apps`), a provision's size (`provisions`), public `hosts`, and API `addresses` | Environment, then node name |
| `secrets` | The `stores`; which one keeps generated credentials for each platform (`generated`) or for one target (`targets`); which keeps adopted keys (`adopted`) | |

`placement` (which target a location means) and `fileTransports` are accepted so a complete
settings file loads, and are read by later 1.4.0 changes. Any other top-level key is an error.

## `extends` and the layers

A settings file may extend a shared estate file, which may extend another. The files merge key
by key and the nearer file wins, so a fleet-wide upgrade from Postgres 18 to 19 is one line in the
shared file. Arrays replace rather than append. Each file may leave out what the file it extends
supplies; the merged result must be complete. `extends` takes a path relative to the file, or a
package specifier: an estate's shared settings usually live in another repository, and a published
package is how a project reaches them, as with tsconfig's `extends`.

On top of the merged file, one value for one node comes from these layers, lowest first:

| Layer | From |
|---|---|
| `generator` | The default the generator passes in |
| `resourceDefaults` | `resourceDefaults.<platform>.<kind>`, for a resource |
| `purpose` | `purposes.<purpose>`: its plain values for an app, its `<kind>` block for a resource |
| `environment` | `environments.<environment>.apps.<app>` or `.provisions.<provision>` |

Every resolved value carries its layer, the key path it was read from, and the file that wrote
it, so a generated file can say where each number came from.

```ts
import { loadSettings, resolveResource, resolveGeneratedStore } from "@metaobjectsdev/sdk";

const settings = await loadSettings(".metaobjects");
if (settings) {
const db = resolveResource(settings, {
kind: "rdb",
target: "lab",
environment: { name: "Production", purpose: "production" },
provision: "shop-db",
generatorDefaults: { product: "postgres", version: "18" },
});
db.values.get("backupDays"); // { value: 14, layer: "environment", path: [...], file: ".../settings.json" }
resolveGeneratedStore(settings, "lab")?.name; // "vault"
}
```

The resolver is told the target by name. Choosing it from a location is `placement`'s job, and
arrives with it.

## Errors

| Code | When |
|---|---|
| `ERR_SETTINGS_INVALID` | A file is not JSON, has a key the format does not know, a purpose outside the four, or a nested value where a plain one belongs; or the merged settings miss a required key |
| `ERR_SETTINGS_EXTENDS_NOT_FOUND` | `extends` names a file or package that cannot be found |
| `ERR_SETTINGS_EXTENDS_CYCLE` | Settings files extend each other in a cycle |
| `ERR_SETTINGS_UNKNOWN_PLATFORM` | A target, a `resourceDefaults` key or a `secrets.generated` key names a platform `platforms` does not declare |
| `ERR_SETTINGS_UNKNOWN_STORE` | `secrets` names a store `secrets.stores` does not declare |
| `ERR_SETTINGS_UNKNOWN_TARGET` | `secrets.targets` names, or a resolver is asked for, a target `targets` does not declare |

These are settings errors, raised by the TypeScript reader, and not loader codes. Checks that read
the model and the settings together (a key that names no node, a location with no target) are
`meta verify` rules and arrive with the vocabulary they read.
31 changes: 31 additions & 0 deletions server/typescript/packages/sdk/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,37 @@
export { ConfigSchema, DEFAULT_CONFIG, loadConfig, setConfigWarningSink, splitUnknownTopLevelKeys, CONFIG_TOP_LEVEL_KEYS, saveConfig, AllowTokenEnum, physicalNamingFromConfig, wireFormatFromConfig, enumDefaultsFromConfig, rulesSettingsFromConfig, apiPaginationFromConfig, apiUnknownFieldsFromConfig, HAND_EDITS_POLICIES, type HandEditsPolicy } from "./config.js";
export type { Config } from "./config.js";

// Settings (ADR-0070, calls 5 and 13): `.metaobjects/settings.json`, read by TypeScript only,
// its `extends` chain, and the resolver for a node's target, product, size and secret store.
export {
SETTINGS_FILE,
SETTINGS_PURPOSES,
SETTINGS_LAYERS,
SETTINGS_ERROR_CODES,
SettingsError,
SettingsFileSchema,
loadSettings,
loadSettingsFile,
resolveTarget,
resolveResource,
resolveApp,
resolveGeneratedStore,
resolveAdoptedStore,
type Settings,
type SettingsFile,
type SettingsPurpose,
type SettingsLayer,
type SettingsErrorCode,
type SettingValue,
type Resolved,
type ResolvedTarget,
type ResolvedResource,
type ResolvedStore,
type EnvironmentRef,
type ResolveResourceInput,
type ResolveAppInput,
} from "./settings.js";

// Metadata dependencies (FR-023) — the `dependencies` config key's schema,
// constants, the manifest/lock schemas + integrity hashing, and the snapshot
// verification + exclusion-key helpers `resolveCollection` composes into
Expand Down
Loading
Loading