Metadata-Version: 2.3
Name: mcms-data
Version: 0.1.0
Summary: Provides declarative data binding and runtime data resolution for MCMS
Author: MikemathuKE
Author-email: MikemathuKE <michaelmathu6@gmail.com>
Requires-Dist: mcms-core
Requires-Python: >=3.13
Description-Content-Type: text/markdown

# MCMS Data

`mcms_data` provides declarative data binding and runtime data resolution for MCMS. It resolves data contexts and expressions before component rendering, keeping components independent of data sources and persistence mechanisms.

## Responsibilities

- Define the `DataContext` abstraction.
- Resolve named data sources through `DataRegistry`.
- Resolve internal data sources through registered Django models.
- Parse and resolve data expressions using the `--expression--` syntax.
- Build runtime data contexts and support nested context scopes.
- Resolve both single objects and collections through the same context mechanism.
- Apply query definitions when retrieving data, according to the implemented query schema.
- Keep data retrieval and binding resolution outside component definitions and the renderer.

## Data context

A data context identifies the source type, registered source name, runtime context name, and query.

```json
{
  "type": "Internal",
  "source": "posts",
  "context": "post",
  "query": {}
}
```

The initial source type is `Internal`. The architecture leaves room for additional source types, but external source types such as REST are not part of the initial implementation scope.

## Data registry

`DataRegistry` maps stable source names to registered objects, typically Django models:

```python
data_registry.register("posts", Post)
```

The registry does not own Django model registration, migrations, persistence, or model construction.

## Expressions and nested contexts

Expressions use the form:

```text
--post.title--
```

A nested context extends the runtime scope established by its parent. Descendants can resolve values from the current context and, where supported by the runtime scope rules, ancestor contexts.

Single objects and collections share the same data-context abstraction. When a source resolves to a collection, the children of the data context act as the item template and are rendered for each item.

## Resolution flow

```text
DataContext
    |
    v
DataRegistry
    |
    v
Internal source resolver
    |
    v
Runtime data context
    |
    v
Expression resolver
    |
    v
Resolved component values
    |
    v
mcms_render
```

Components do not perform ORM queries or retrieve data directly. The persisted render structure remains declarative; resolved values are runtime concerns.

## Architectural integrations

| Package / system | Relationship |
|---|---|
| `mcms_core` | Shared registry and exception infrastructure |
| Django models | Initial internal data source objects |

## Scope and limitations

The ADRs establish the context and expression model but leave the complete query schema open. The initial source type is `Internal`; REST and other external providers are future possibilities. Authentication/authorization, caching, transformations, mutation, and mixed-string interpolation are not defined by the initial decision.

## Application configuration

No specific global `apps` variable or data-root setting is named in the data ADRs. Document actual host-application registration and settings after verifying the implementation.

## Dependencies

### Architectural integrations

See the integration table. In particular, `mcms_data` depends conceptually on the common registry contract and Django model metadata for the initial `Internal` source implementation.

### Python distribution dependencies

All MCMS Packages rely on django

## Development

```bash
uv run pytest packages/mcms-data/tests
```

Run Ruff and mypy using the repository's configured commands.
