@async/db

schema

Infer first, then make the contract explicit when the app depends on it.

Fixture data can prove field names, primitive types, arrays, nested objects, and enum-like values. Explicit schema is the upgrade path for descriptions, defaults, constraints, relations, UI hints, and stricter validation.

data-first

Start with fixtures

Use the inferred contract while the resource shape is still forming.

explicit

Promote important fields

Add `.schema.json`, `.schema.jsonc`, or `.schema.mjs` when inference cannot prove intent.

strictness

Warn, then fail

Keep `unknownFields: "warn"` during discovery. Switch to `"error"` when drift should block.

Explicit schema adds intent

{
  "name": "users",
  "type": "collection",
  "fields": {
    "id": { "type": "string", "required": true },
    "email": {
      "type": "string",
      "description": "Email address used for local sign-in."
    },
    "role": {
      "type": "string",
      "values": ["admin", "member"],
      "default": "member"
    }
  }
}

The same contract feeds tools

  • Generated TypeScript uses field descriptions as JSDoc.
  • GraphQL SDL can expose the same resource metadata.
  • Viewer manifests can drive forms, table columns, and relation hints.
  • Defaults apply on create and safe additive store hydration unless disabled.