Skip to content
Shapemetry

Model - Ref

API reference for src/core/ref, src/schema/ref on @huukhanhnguyen/model, reachable from ..

See the Guide for the ModelJSON / evaluate pipeline.

API reference

Signatures are generated from the live package .d.ts - not hand-written.

encodeBase64

function

encodeBase64(text: string): string

encodeInlineRef

function

Encode a sub-model JSON doc as an inline data: reference (base64 JSON). Used by bundleModel when inlining a ref directly into the node (the alternative to the sibling models snapshot map).

encodeInlineRef(doc: unknown): string

ParsedRef

type

type ParsedRef
// = {
    scheme: RefScheme;
    /**
     * The resolver key. For `platform`/`url` it is the ref string verbatim (the
     * bare id or the full url) — the host resolver gets exactly this. For
     * `inline` it is the `data:` body decoded to a JSON model doc string (NOT the
     * raw URI) so the engine can JSON.parse it directly.
     */
    value: string;
    /** The original ref string, untouched. */
    raw: string;
}

parseRef

function

Classify a model reference string into one of the three schemes. Pure + sync. apps/web/src/evaluate.ts (the host resolver) calls this directly rather than re-testing the scheme/decoding the ref itself.

parseRef(ref: string): ParsedRef

RefScheme

type

Model reference parsing — a HOST utility for resolving which document to open/fetch (a page's root model id, a catalog pick at install time). NOT a runtime nested-model mechanism: the engine never resolves references during evaluation — the editor resolves one of these refs ONCE when installing (share.ts's installModel folds the resolved doc into a components[] entry).

A reference is a URI STRING dispatched by scheme into one of three forms:

  • platform (default, a BARE id like "abc-123"): the canonical case — every model saved today uses a bare platform id. Resolved by the host (DB / R2 / extension dir) which receives the bare id.
  • url (http://… / https://…): a sub-model fetched from an arbitrary origin. Delegated to the host resolver (which receives the FULL url and decides how to fetch). A bundle pre-fetches it into the inline snapshot, so after bundling a url ref resolves offline like any other.
  • inline (data:… URI): a self-contained snapshot carries the sub-model JSON in the ref itself (data URI body) — resolved by the engine with NO host call, so it works offline. (bundleModel can either inline each ref as a data: URI or, by default, stash the docs in a sibling models map and keep the ref a bare id; both serve offline. See bundle.ts.)
type RefScheme
// = "platform" | "url" | "inline"
Last updated: 📖 2 min readEdit on GitHub