Skip to main content

Atom parsing

Version: V2
View Markdown

Atom parsing turns a raw input string into a candidate that an application can inspect. The parser keeps the original input, trims outer ASCII whitespace for detection, and returns a kind with fields specific to that kind. A catalog can use those fields to decide whether to validate an identifier, inspect a URL, or ask the user what a title refers to.

Builds on: Atoms, The Intuition Identifier (IID).

Implemented by: @0xintuition/atom-parser.

How it works​

Call parseAtom with remoteFetch set to false for local detection. Branch on kind before reading kind-specific fields. For an IID candidate, inspect valid and canonicalIid. A malformed candidate still has kind iid and carries a reason. Parsing a valid IID returns locally. Parser README, local detection, IID validation.

URL and IPFS inputs enable remote inspection by default. When a fetch is permitted and a target is available, the parser can inspect response bytes to distinguish a webpage, an image, or another content type. Set a request deadline and a byte limit for this work. For untrusted URLs, enforce destination restrictions at your network boundary as well. Parsing and fetch policy, remote transport policy.

Example​

A catalog import has three cells. With remote fetching disabled, their results call for different decisions.

InputLocal resultCatalog decision
https://example.com/catalogkind is url, with a canonical URL and no remote inspectionKeep the link as a lead. Its contents are still unknown.
int:mbid:recording:b1a9c0e9-d987-4042-ae91-78d6a3267d69kind is iid, with a valid canonical recording IIDPass the canonical value to the registry to learn which providers support that scheme.
One More Timekind is plain_stringRetain the title and ask for an identifier to distinguish recordings with the same name.

The second row uses the synthetic recording in Classify and enrich atoms. Normalization helps interpret a cell. When deriving an atom ID, use the exact bytes of the representation you choose to publish.

Common mistakes​

  • Treating every int: prefix as a valid identifier. Check the validation fields before using a candidate as an anchor.
  • Reporting a recognized URL as a verified recording. Local detection established its syntax. Even with remote inspection enabled, a denied request or timeout can leave the content unknown.
  • Replacing the original atom bytes with trimmed input when looking up an existing atom. A change in bytes can change its ID.

Next​

Atom classification explains how plugins use evidence to assign a type.

Applies to V2 · @0xintuition/atom-parser 0.1.1