Build and query an entity index for URPX documents.
URPX JSON-LD documents are graphs: most entities carry a :jsonld/id and refer
to other entities by reference shape {:jsonld/id "urpx:foo"}. Coercion
leaves these references intact; consumers dereference them on demand against
an index keyed by id string.
Note: many references point to vocabulary IRIs in the URPX ontology (e.g. urpx:peakTier, urpx:allDays, urpx:bundledLedger) rather than entities defined in the document. Those lookups return nil — callers distinguish internal refs (resolve to a node) from vocabulary terms (do not).
Build and query an entity index for URPX documents.
URPX JSON-LD documents are graphs: most entities carry a :jsonld/id and refer
to other entities by reference shape `{:jsonld/id "urpx:foo"}`. Coercion
leaves these references intact; consumers dereference them on demand against
an index keyed by id string.
Note: many references point to vocabulary IRIs in the URPX ontology
(e.g. urpx:peakTier, urpx:allDays, urpx:bundledLedger) rather than entities
defined in the document. Those lookups return nil — callers distinguish
internal refs (resolve to a node) from vocabulary terms (do not).(build-index doc)Walk a URPX document (raw or coerced) and return a map from id string to
the entity node bearing that id. Suitable input: anything urpx.core/load-rate-plan
or urpx.coerce/coerce-rate-plan produces.
Walk a URPX document (raw or coerced) and return a map from id string to the entity node bearing that id. Suitable input: anything `urpx.core/load-rate-plan` or `urpx.coerce/coerce-rate-plan` produces.
(get-entity index id)Look up an entity directly by id string. Same as (resolve-ref index id)
when the input is a string, but with a clearer name when the call site
already has the bare id.
Look up an entity directly by id string. Same as `(resolve-ref index id)` when the input is a string, but with a clearer name when the call site already has the bare id.
(nested-version plan nested-key)Return the single version snapshot nested under nested-key on plan, or
nil when there is none.
urpx:hasRatePlanVersion and urpx:hasRatePlanModifierVersion are sh:minCount 0 with NO sh:maxCount upstream, so a conformant document may nest several snapshots. Documents in the wild nest exactly one, and every reader in this library expects one, so this normalizes the single-or-vector shapes and REFUSES to guess when there is genuinely more than one:
nil or absent -> nil a single map -> that map a 1-vector -> its element a longer vector -> throws
Throwing rather than taking first is deliberate. Picking arbitrarily would
resolve prices against an unpredictable snapshot and report a confident wrong
answer; the caller that knows which window it wants passes it explicitly
instead (:version in the resolve-prices opts). Which snapshot applies to a
given instant is a selection question the vocabulary does not yet settle:
urpx:hasTemporalScope carries no sh:path constraints at 95eb8e22.
Return the single version snapshot nested under `nested-key` on `plan`, or nil when there is none. urpx:hasRatePlanVersion and urpx:hasRatePlanModifierVersion are sh:minCount 0 with NO sh:maxCount upstream, so a conformant document may nest several snapshots. Documents in the wild nest exactly one, and every reader in this library expects one, so this normalizes the single-or-vector shapes and REFUSES to guess when there is genuinely more than one: nil or absent -> nil a single map -> that map a 1-vector -> its element a longer vector -> throws Throwing rather than taking `first` is deliberate. Picking arbitrarily would resolve prices against an unpredictable snapshot and report a confident wrong answer; the caller that knows which window it wants passes it explicitly instead (`:version` in the resolve-prices opts). Which snapshot applies to a given instant is a selection question the vocabulary does not yet settle: urpx:hasTemporalScope carries no sh:path constraints at 95eb8e22.
(ref? v)True if v looks like a JSON-LD @id reference — a map with a :jsonld/id
but no :jsonld/type. (Real entities carry both; references carry only :jsonld/id.)
True if `v` looks like a JSON-LD @id reference — a map with a :jsonld/id but no :jsonld/type. (Real entities carry both; references carry only :jsonld/id.)
(resolve-ref index ref-or-id)Given an index and either a Ref map ({:jsonld/id "urpx:foo"}) or an id string,
return the indexed entity, or nil if not found.
Returns nil for vocabulary IRIs that don't correspond to a node in the document.
Given an `index` and either a Ref map ({:jsonld/id "urpx:foo"}) or an id string,
return the indexed entity, or nil if not found.
Returns nil for vocabulary IRIs that don't correspond to a node in the document.(versions-by-plan doc)Walk a URPX document and return {plan-id [version-snapshot ...]}, keyed by the @id the snapshot points back at through urpx:forRatePlan or urpx:forRatePlanModifier.
This is the v0.5.1 un-nested path: a document may state the plan-to-version link downward (urpx:hasRatePlanVersion, a nested map), upward (the back pointer, with the snapshot top-level), or both. Indexing on the back pointer reaches the snapshot in every one of those shapes.
The back pointer may be a bare reference or a fully embedded RatePlan node;
both expose :jsonld/id, so one accessor covers each. Walks the raw structure
rather than build-index, so a snapshot carrying no @id of its own is still
found.
Walk a URPX document and return {plan-id [version-snapshot ...]}, keyed by
the @id the snapshot points back at through urpx:forRatePlan or
urpx:forRatePlanModifier.
This is the v0.5.1 un-nested path: a document may state the plan-to-version
link downward (urpx:hasRatePlanVersion, a nested map), upward (the back
pointer, with the snapshot top-level), or both. Indexing on the back pointer
reaches the snapshot in every one of those shapes.
The back pointer may be a bare reference or a fully embedded RatePlan node;
both expose :jsonld/id, so one accessor covers each. Walks the raw structure
rather than `build-index`, so a snapshot carrying no @id of its own is still
found.cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |