Type guards for runtime validation of resource and value types.
Checks if a value is a Resource.
Checks if a value is a Patch.
Checks if a value is a Values.
Checks if a value is a Value.
Checks if a value is a Literal.
Checks if a value is a Reference.
Checks if a value is a Local.
Checks if a value is a Locals.
Functions for converting between serialized and structured representations.
Encodes a resource state as a JSON string.
Decodes a resource state from a JSON string.
Encodes a patch as a JSON string.
Decodes a patch from a JSON string.
Resource state management.
Defines types for describing resource states and partial updates in REST/JSON APIs, using native JSON types with localised text support:
Resource Operations
Retrieving
A Resource is a property map describing the state of a resource:
Resources may include an IRI property mapped to
@idin the application-defined JSON-LD@context, identifying the resource globally. This property is usually namedid, but the mapping is arbitrary. A state without such a property represents an anonymous (blank) node—useful for nested structures that don't need their own identity:Resources can link to other resources using IRI references or embedded descriptions. IRI references identify a resource without describing its state, while embedded descriptions include the linked resource's properties:
Creating
A Resource serves as payload for HTTP POST operations:
Nested resource states containing properties beyond the resource identifier are only accepted if explicitly declared as embedded in the application-defined data model; non-embedded nested resources with additional properties will be rejected during validation.
Updating
A Resource also serves as payload for HTTP PUT operations:
State replacement is total — properties not included in the state are removed from the resource; empty arrays are treated as property deletions, following set semantics where an empty set is equivalent to absence.
Patching
A Patch serves as payload for HTTP PATCH operations. Properties can be set to new values or deleted using
null; unlisted properties remain unchanged:Empty arrays are treated as property deletions, following set semantics where an empty set is equivalent to absence.
Deleting
HTTP DELETE operations remove the resource at the request URL (no payload is required):
Value Types
Each property in a resource state or patch holds Values:
Additionally, properties can hold an Indexed container, mapping arbitrary keys to Values.
A Value can be:
boolean,number,string)Arrays follow set semantics — duplicates are ignored, ordering is immaterial, and empty arrays are treated as absent values. This aligns with JSON-LD's multi-valued property model.
IRIs
An IRI (Internationalized Resource Identifier) is a globally unique string identifying a resource on the web. IRIs enable entity linking by referencing resources without embedding their full state. Properties mapped to
@idin the application-provided JSON-LD@contextexpect IRI values, establishing relationships between resources across systems and domains.Data structures require absolute IRIs. Codec functions (encodeResource, decodeResource, etc.) convert between absolute and internal (root-relative) forms for serialization.
Literals
A Literal maps directly to JSON primitives (
boolean,number,string). Dates, times, and other structured values are represented as strings in standard formats (e.g., ISO 8601). Application-level@contextobjects can declare datatype coercion rules for JSON-LD processing.Localised Text
For multilingual content, use Local or Locals language-tagged text maps. Tags follow RFC 5646 (e.g.,
en,de-CH,zh-Hans):The
@nonekey for non-localised values is not supported; for mixed content usestring | Localorreadonly string[] | Localsunion types, or thezxxtag.See