LiveVueContract.Schema (live_vue_contract v0.3.1)

Copy Markdown View Source

Reads the generated contract file (JSON-Schema subset per Vue component) and validates encoded props against it.

The file is produced from defineProps<T>() by priv/gen.mjs; nothing in it is written by hand. Keys are paths relative to a vue_root without extension ("initiatives/InitiativeList", "prototypes/players/index"); fetch/1 resolves a v-component name the way LiveVue's findComponent does — by path suffix, index ignored — so "InitiativeList" and "prototypes/players" both work.

Summary

Functions

All schemas keyed by component name; %{} when the file is absent.

Compares attribute names with the schema. Returns [] or a list of problems. shared are props injected by LiveVue.SharedPropsView (always present on the wire).

Named types the schemas refer to with {"$ref": name}.

Schema for a v-component name: {:ok, schema}, :error, or {:ambiguous, keys}. Matches by path suffix with index segments ignored, exactly like findComponent in LiveVue's JS.

Path of the contract file, relative to the host app's cwd.

Attribute names of a <.vue> tag that LiveVue would send as props.

Shortcut tag names (<.ComponentName>): file basenames, like LiveVue.Components.

Validates an encoded (JSON-ready) props map.

Functions

all()

All schemas keyed by component name; %{} when the file is absent.

check_keys(schema, keys, shared \\ [])

Compares attribute names with the schema. Returns [] or a list of problems. shared are props injected by LiveVue.SharedPropsView (always present on the wire).

defs()

Named types the schemas refer to with {"$ref": name}.

fetch(name)

Schema for a v-component name: {:ok, schema}, :error, or {:ambiguous, keys}. Matches by path suffix with index segments ignored, exactly like findComponent in LiveVue's JS.

path()

Path of the contract file, relative to the host app's cwd.

prop_keys(keys)

Attribute names of a <.vue> tag that LiveVue would send as props.

shortcut_names()

Shortcut tag names (<.ComponentName>): file basenames, like LiveVue.Components.

validate(schema, value, defs \\ defs())

Validates an encoded (JSON-ready) props map.

Returns [] or [{severity, path, message}]. A key the TS type does not declare is :warn (TypeScript is structural; the client just never reads it), everything else is :error. defs resolves {"$ref": name}; by default, the named types of the contract file.