# property.primitive

## Intent

A reusable primitive semantic value suitable for validators, serializers, database mappings, SDK scalars, and value aliases.

Exact selection subject:

```yaml
subject: property.primitive
```

The current Runtime IR is evidence, not authority. Target improvements needed for a usable template contract are called out explicitly.

## Scope envelope

| Scope                 | Context                                             |
| --------------------- | --------------------------------------------------- |
| `each`                | `property.primitive: PrimitivePropertyContext`      |
| `all`                 | `properties.primitives: PrimitivePropertyContext[]` |
| collection candidates | `collects.group`, `collects.feature`                |

For `collects.<dimension>`, the singular collector is added beside the plural selected-subject array. A collector is valid only when ownership is semantically provable.

## Context tree

| Context path                                 | Type                        | Meaning / template use                                                                                                                   |
| -------------------------------------------- | --------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------- |
| `property.primitive.id`                      | `string`                    | Opaque stable semantic identity.                                                                                                         |
| `property.primitive.name`                    | `NameContext`               | Stable semantic identity and finite naming variants.                                                                                     |
| `property.primitive.description`             | `string\|null`              | Human semantic description.                                                                                                              |
| `property.primitive.tags`                    | `string[]`                  | Semantic classifiers; empty when none.                                                                                                   |
| `property.primitive.explanations`            | `ExplanationContext[]`      | Advisory usage/security/implementation notes.                                                                                            |
| `property.primitive.group`                   | `SemanticLinkContext\|null` | Owning semantic group.                                                                                                                   |
| `property.primitive.feature`                 | `SemanticLinkContext\|null` | Canonical owning feature, when present.                                                                                                  |
| `property.primitive.lifecycle`               | `LifecycleContext`          | Deprecation/removal semantics.                                                                                                           |
| `property.primitive.examples`                | `CanonicalValue[]`          | Valid examples.                                                                                                                          |
| `property.primitive.type`                    | `string\|number\|boolean`   | Structural discriminator.                                                                                                                |
| `property.primitive.kind`                    | `string\|null`              | Refinement such as text, format, integer, decimal, float, double.                                                                        |
| `property.primitive.format`                  | `string\|null`              | Named semantic format. For strings it's one of the canonical `StringFormat` values below. Number formats (such as `int32`) are separate. |
| `property.primitive.money`                   | `MoneyContext\|null`        | For `format: money`: `currency` (ISO 4217 or null) and `minor_units` (true when the amount counts cents). Null otherwise.                |
| `property.primitive.constraints.length`      | `LengthContext\|null`       | Exact/min/max length.                                                                                                                    |
| `property.primitive.constraints.pattern`     | `PatternContext\|null`      | String matching rules.                                                                                                                   |
| `property.primitive.constraints.range`       | `RangeContext\|null`        | Numeric min/max.                                                                                                                         |
| `property.primitive.constraints.multiple_of` | `number\|null`              | Numeric divisibility.                                                                                                                    |
| `property.primitive.constraints.bits`        | `integer\|null`             | Integer width.                                                                                                                           |
| `property.primitive.constraints.unsigned`    | `boolean\|null`             | Unsigned integer semantics.                                                                                                              |
| `property.primitive.constraints.precision`   | `integer\|null`             | Decimal precision.                                                                                                                       |
| `property.primitive.constraints.scale`       | `integer\|null`             | Decimal scale.                                                                                                                           |

## Usage rules

- Group constraints under one predictable subtree even though current IR spreads several values across the property root.
- `type` is structural; `kind` is a refinement, not a semantic role.

## Runtime IR implications to audit

- Properties should gain universal semantic metadata.
- Consider normalizing primitive constraints canonically.

## Template example — Jinja / Python constrained scalar

```jinja
{% if property.primitive.type == "string" %}
{{ file.symbol }} = Annotated[
    str,
    StringConstraints(
        min_length={{ property.primitive.constraints.length.min }},
        max_length={{ property.primitive.constraints.length.max }},
    ),
]
{% endif %}
```

The example uses semantic context only. Any `renderType`/`render_type` helper shown is a pack-owned macro/partial consuming the documented `TypeContext`, not hidden Dryv context.

## Audit questions

- Can a real property.primitive pack generate code without parsing raw IR storage conventions?
- Is any field here present only because the current IR happens to store it?
- Does any nested item need first-class selection of its own?

## String formats

String formats are a closed vocabulary (`StringFormat`). Anything else is a text property with a `pattern`.

`uuid`, `ulid`, `email`, `url`, `uri`, `hostname`, `ipv4`, `ipv6`, `phone` (loose), `e164` (strict), `slug`, `hex-color`, `base64`, `hex`, `jwt`, `semver`, `mime-type`, `locale`, `language-tag`, `country-code`, `currency-code`, `path`, `file-path`, `file-name`, `regex`, `html`, `markdown`, `json`, `yaml`, `xml`, `csv`.

`uuid`, `ulid`, `base64`, `hex` and `jwt` are opaque: they can't carry length or pattern constraints. Dates and times are never string formats; use temporal properties.
