# Semantic value

Derived additions: `value.is.*` classification flags and `value.generated` planned representations. See [derived.md](/pack-builders/context/derived).

**Used by:** schema/composite fields, operation/workflow ports, event payloads, and other ValueRef-like semantic carriers

This is the authoritative contract for a reusable semantic value carried by a field, port, event payload, result, or similar ValueRef-like semantic carrier.

A field value is not a "constraint" and not an ambiguous reference. It has one explicit structural kind:

```text
property
schema
unknown
dynamic
```

Carrier-local semantics stay on the owning context. For example, field optionality/nullability/array/default/relation/query rules remain on a field; port ordering/direction stays on the port.

## Context tree

| Context path     | Type                                 | Meaning                                                                                    |
| ---------------- | ------------------------------------ | ------------------------------------------------------------------------------------------ |
| `value.kind`     | `property\|schema\|unknown\|dynamic` | Primary field-value discriminator.                                                         |
| `value.property` | `PropertySemanticValueContext\|null` | Reusable property meaning when `kind=property`.                                            |
| `value.schema`   | `SchemaContext\|null`                | Full schema context from [../schema.md](/pack-builders/context/schema) when `kind=schema`. |

No nested payload exists for `unknown` or `dynamic`.

## PropertySemanticValueContext

A property-backed field has a second discriminator because reusable properties have several semantic kinds:

| Context path               | Type                                                                           | Meaning                                                                                  |
| -------------------------- | ------------------------------------------------------------------------------ | ---------------------------------------------------------------------------------------- |
| `value.property.kind`      | `primitive\|enum\|composite\|literal\|union\|record\|tuple\|generic\|temporal` | Exact reusable-property kind.                                                            |
| `value.property.primitive` | `PrimitivePropertyContext\|null`                                               | Full context from [../property.primitive.md](/pack-builders/context/property-primitive). |
| `value.property.enum`      | `EnumPropertyContext\|null`                                                    | Full context from [../property.enum.md](/pack-builders/context/property-enum).           |
| `value.property.composite` | `CompositePropertyContext\|null`                                               | Full context from [../property.composite.md](/pack-builders/context/property-composite). |
| `value.property.literal`   | `LiteralPropertyContext\|null`                                                 | Full context from [../property.literal.md](/pack-builders/context/property-literal).     |
| `value.property.union`     | `UnionPropertyContext\|null`                                                   | Full context from [../property.union.md](/pack-builders/context/property-union).         |
| `value.property.record`    | `RecordPropertyContext\|null`                                                  | Full context from [../property.record.md](/pack-builders/context/property-record).       |
| `value.property.tuple`     | `TuplePropertyContext\|null`                                                   | Full context from [../property.tuple.md](/pack-builders/context/property-tuple).         |
| `value.property.generic`   | `GenericPropertyContext\|null`                                                 | Full context from [../property.generic.md](/pack-builders/context/property-generic).     |
| `value.property.temporal`  | `TemporalPropertyContext\|null`                                                | Full context from [../property.temporal.md](/pack-builders/context/property-temporal).   |

Exactly one property-kind branch is active and it must match `value.property.kind`.

The nested property context is the **same context contract** used when that property is selected directly. It is not a reduced copy and must not be redefined here.

## Property example

A decimal property field conceptually exposes:

```text
field.value.kind
    property

field.value.property.kind
    primitive

field.value.property.primitive
    → full PrimitivePropertyContext
      including:
        type = number
        kind = decimal
        constraints.precision
        constraints.scale
        constraints.range
        ...
```

A database-model template can therefore read:

```hbs
{{#if (eq field.value.property.kind "primitive")}}
  {{#if (eq field.value.property.primitive.kind "decimal")}}
    precision:
    {{field.value.property.primitive.constraints.precision}}, scale:
    {{field.value.property.primitive.constraints.scale}}
  {{/if}}
{{/if}}
```

without performing a second registry lookup.

## Schema example

A field carrying another schema exposes:

```text
field.value.kind = schema
field.value.schema = full SchemaContext
```

A template can use only identity:

```hbs
{{field.name.camel}}: {{field.value.schema.name.pascal}};
```

or explicitly request deeper nested schema facts if its generation genuinely needs them.

The full `SchemaContext` contract is reused from [../schema.md](/pack-builders/context/schema); it is not copied here.

## Unknown and dynamic

```text
unknown
    concrete value type is intentionally unspecified/opaque

dynamic
    runtime value is intentionally permitted to vary
```

Target packs choose their target-language representation.

Dryv does not convert either one into a fake property/schema reference.

## Demand-driven and recursive safety

"Full context of X" defines the available typed vocabulary, not eager expansion.

If a template requests only:

```text
schema.fields.*.value.schema.name.pascal
```

Dryv only needs the nested schema name.

If a template explicitly requests nested fields, those paths may be materialized under the same `SchemaContext` contract.

Template analysis and context resolution must keep reference expansion bounded and cycle-safe so schema↔schema or composite↔composite relationships cannot recursively explode context.

## Runtime IR implications

The current IR already distinguishes field kinds:

```text
property
schema
unknown
dynamic
```

That distinction should remain canonical.

What needs improvement is the inspection/context layer:

- property references must resolve to the complete matching reusable-property semantic context;
- schema references must resolve to the same `SchemaContext` vocabulary;
- templates must not parse reference prefixes to discover which one they received;
- field-local usage semantics must remain separate from reusable value-definition semantics.

## Reuse outside fields

The same contract is reused unchanged:

```text
SchemaFieldContext.value
CompositeFieldContext.value
OperationPortContext.value
WorkflowPortContext.value
EventContext.payload
```

A carrier never replaces this rich semantic value with a bare link merely because it is not a schema field.
