Skip to content

feat: generate referenced asset names in .riv schemas, type referencedAssets - #359

Open
mfazekas wants to merge 1 commit into
feat/type-safe-riv-schema-2from
feat/riv-schema-asset-names
Open

feat: generate referenced asset names in .riv schemas, type referencedAssets#359
mfazekas wants to merge 1 commit into
feat/type-safe-riv-schema-2from
feat/riv-schema-asset-names

Conversation

@mfazekas

Copy link
Copy Markdown
Collaborator

Stacked on #352 (git-town: main → feat/type-safe-riv-schema-2 → this). Implements the review feature request: generate asset names (images, fonts, audio) for out-of-band handling.

Generated schemas gain an assets record — unique asset identifier (the documented referencedAssets key form, e.g. 'Inter-594377') → 'image' | 'font' | 'audio'. Only non-embedded assets are listed: referenced and CDN-hosted ones are exactly what an app must supply on the new runtime, which doesn't fetch CDN assets (embedded assets need nothing, so they're omitted). Extraction happens in the existing WASM load() asset-loader callback — the only place asset metadata is visible — so no extra pass.

On the typing side, useRiveFile (and RiveFileFactory.fromSource) constrain referencedAssets for schema-typed inputs:

  1. keys must name an asset in the file,
  2. each entry's declared type must match the asset's actual kind (mislabeling a font as image is a compile error — useful since the new runtime can't infer types and relies on this hint),
  3. RiveImage objects are only accepted for image assets,
  4. files with no referenced assets reject all keys.

useRiveFile's typed/untyped overload pair is merged into one generic signature so an invalid key is a hard error instead of silently falling through to the untyped number-input overload (the same fallthrough class fixed in #355 for viewModelName — caught here by sabotage-testing the example before writing the types). Unknown schemas and plain inputs degrade to the untyped ReferencedAssets exactly as before.

The out-of-band example now uses the typed asset import as a live showcase; out_of_band.riv.d.ts shows the emitted shape (3 referenced + 3 CDN assets). All 31 committed schemas regenerated. Coverage: tsd pins for every mistake class plus backward-compat, bun unit tests for classifyAsset/emit, and the emit fuzzer extended with hostile asset names.

Runtime behavior is unchanged (pure codegen + types); semantics target the new runtime per the request — legacy is out of scope.

…dAssets

Adds an assets record to generated schemas: unique asset identifier (the
documented referencedAssets key form, e.g. 'Inter-594377') → 'image' |
'font' | 'audio'. Only non-embedded assets are listed — referenced and
CDN-hosted ones are exactly what an app must supply out-of-band on the new
runtime, which does not fetch CDN assets.

useRiveFile (and RiveFileFactory.fromSource) then constrain referencedAssets
for schema-typed inputs: keys must name an asset in the file, each entry's
declared type must match the asset's actual kind, and RiveImage objects are
only accepted for image assets. useRiveFile's typed/untyped overload pair is
merged into one generic signature so an invalid key errors instead of
silently falling through to the untyped number-input overload; unknown
schemas and plain inputs degrade to the untyped ReferencedAssets as before.

Extraction happens in the existing load() asset-loader callback (the only
place the WASM exposes asset metadata). The out-of-band example now uses the
typed asset import; every mistake class is pinned by tsd tests and the
classifyAsset/emit paths by bun tests, with assets added to the emit fuzzer.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant