Skip to content

Releases: pietercolpaert/rdf-parser-ts

0.4.0

Choose a tag to compare

@pietercolpaert pietercolpaert released this 29 Sep 06:51

This release makes the parser fully conformant with the W3C RDF 1.1 and RDF 1.2 test suites for Turtle, TriG, N-Triples and N-Quads, with no skipped tests. It also slims the public API down to the parsers plus the RDF/JS interfaces, and makes streaming 1.3–1.5× as fast as N3.js. It contains several breaking changes; see below.

Breaking changes

The package no longer includes its own data model. Terms are now created with rdf-data-factory by default. All types are the @rdfjs/types interfaces.

  • Removed: the NamedNode, BlankNode, Literal, Variable, DefaultGraph and Quad classes, DataFactory, and the helper functions namedNode(), blankNode(), literal(), variable(), defaultGraph() and quad(). Use new DataFactory() from rdf-data-factory instead.
  • Removed: the *Like type aliases (NamedNodeLike, QuadLike, DataFactoryLike, …), and Term and TermType. Use the @rdfjs/types types instead.
  • The factory option is now typed as RDF.DataFactory<RDF.BaseQuad>.

Removed helpers: termToString(), quadToString(), termToId() and termFromId(), and the internal Parser._factory and Parser._resetBlankNodePrefix(). To serialize RDF, use rdf-writer-ts.

The browser entry no longer re-exports Writer from rdf-writer-ts, and rdf-writer-ts is no longer a dependency. The browser bundle is smaller as a result.

The rdf-parser-ts command-line tool has been removed.

Directional language tags ("x"@en--rtl) now reach a custom factory as an RDF/JS { language, direction } object instead of the string "en--rtl". The literal's datatype is now rdf:dirLangString.

Relative IRIs are resolved differently. Resolution now follows RFC 3986 instead of the WHATWG URL class, so some IRIs differ from 0.3.x:

  • Non-ASCII characters are no longer percent-encoded.
  • Host names are no longer lowercased.
  • No trailing slashes are added.
  • Bases without a hierarchy, such as tag: IRIs, now work.
  • Absolute IRIs are kept exactly as written.

Parsing is stricter. Input that 0.3.x accepted is now rejected:

  • @PREFIX and @BASE; the @ directives are case-sensitive.
  • A as a shorthand for rdf:type.
  • Graph blocks in Turtle mode, and quads in Turtle and TriG mode.
  • Directives inside TriG graph blocks.
  • Triple terms as subjects.
  • Collections and bracketed blank nodes inside reified triples.
  • rdf:langString without a language tag, in every format.
  • Relative IRIs with a colon in the first path segment.
  • \u escapes that encode surrogate code points.
  • Unescaped ~, / and # in prefixed names.
  • Invalid % sequences in prefixed names.
  • VERSION labels written with triple-quoted strings.
  • Unknown VERSION labels. Only 1.1, 1.2, 1.2-basic and *-messages are accepted, unless parseUnsupportedVersions: true is set.

The Node.js StreamParser is now built on readable-stream instead of node:stream, so it also works when bundled for browsers.

New

  • RDF 1.2 annotation syntax: reifiers (~ :r) and annotation blocks ({| :p :o |}), including inside TriG graphs, where the rdf:reifies quad goes into the enclosing graph.
  • Standalone reified triples: << :s :p :o >> .
  • Full Unicode support in names: prefixes, local names and blank node labels accept all Unicode ranges of the Turtle grammar.
  • Escapes in prefixed names: backslash escapes (ex:a\~b) and %xx sequences.
  • Other syntax:
    • Decimals written as .1.
    • @prefix:<…> without a space.
    • Repeated semicolons (;;).
    • : inside local names.
  • parse() return types: parse(input) now returns ParserOutput, and parse(input, callback) returns undefined, so the ?? [] workaround is no longer needed.
  • Non-string format option: it is ignored instead of crashing the parser.

Conformance and testing

  • All W3C test suites pass with no skipped tests: RDF 1.1 N-Triples, N-Quads, Turtle and TriG, and the RDF 1.2 syntax suites for all four formats. The RDF 1.2 Turtle and TriG evaluation suites, which also check the parsed output, are now part of npm run spec. That is 1,050 tests in total.
  • About 700 test cases from N3.js cover Turtle, TriG, N-Triples, N-Quads and 364 IRI-resolution cases. They are replayed on every test run.
  • 100% test coverage is now enforced.

Performance

Measured by streaming 100,000 generated statements, with median throughput in quads per second:

Input 0.4.0 strict 0.4.0 relax N3.js
RDF 1.2 with triple terms 1.08M 1.38M 716k
Plain N-Quads 1.42M 1.84M 993k

Where the speedup comes from:

  • The strict N-Triples/N-Quads fast path now handles triple terms too.
  • For line-based formats, input chunks are split at the last line break instead of being scanned for the last complete statement.
  • IRIs are validated with a single regular-expression check.
  • The general parser builds strings from slices instead of character by character.
  • String chunks are no longer converted to Buffers and back.

The benchmark (perf/bench.js) now streams the input through each parser without keeping the quads. The README has the full tables.

Development

  • Linting with @rubensworks/eslint-config.
  • TypeScript 6 without esModuleInterop or skipLibCheck, and Vitest 5.
  • Coveralls, Renovate, and CI badges, including an npm badge.
  • Build output (dist/) is no longer committed to the repository.

Full Changelog: 0.3.1...0.4.0

0.2.4

Choose a tag to compare

@pietercolpaert pietercolpaert released this 08 Jun 20:30

Full Changelog: 0.2.3...0.2.4

0.2.3

Choose a tag to compare

@pietercolpaert pietercolpaert released this 08 Jun 11:09

Full Changelog: 0.2.2...0.2.3

0.2.2

Choose a tag to compare

@pietercolpaert pietercolpaert released this 07 Jun 20:39

Since 0.1.0, the main changes are:

Added features

  • Incremental streaming parser that emits parsed quads before stream end and keeps only incomplete trailing input buffered.
  • Browser builds:
    • minified ESM bundle
    • minified global bundle
    • browser-specific declaration files
  • Browser-compatible StreamParser using Web Streams.
  • Writer API for serializing RDF-JS quads.
  • StreamWriter for Node.js object-mode stream serialization.
  • RDF Messages writing support:
    • streaming message quads
    • addMessage()
    • message delimiters/version output
  • Performance regression check with warning threshold.
  • Pre-commit hook that runs specs/build and stages generated dist.

Fixed bugs / improvements

  • Fixed full-buffering StreamParser behavior by adding incremental parsing.
  • Fixed UTF-8 chunk-boundary handling in streams.
  • Fixed TriG named graph parsing where valid graph blocks omit the final triple dot before }.
  • Restored spec compliance after that TriG fix:
    • Turtle no longer accepts TriG graph blocks.
    • nested graph blocks are rejected.
    • invalid graph names such as collections and blank-node property lists are rejected.
    • empty anonymous blank node graph labels remain accepted.

Full Changelog: 0.1.0...0.2.2

0.1.0

Choose a tag to compare

@pietercolpaert pietercolpaert released this 06 Jun 09:59

First public release

First public release of rdf-parser-ts, a fast TypeScript RDF parser for Node.js 24+ with an RDF-JS-compatible data model and an N3/Comunica-compatible Parser and StreamParser API.

Highlights

  • Parses N-Triples, N-Quads, Turtle, and TriG, including RDF1.2 triple terms.
  • Adds RDF Message Log support with VERSION "...-messages", MESSAGE, @version, and @message ..
  • Exposes Message, MessageQuad, parseMessages(), and toMessages() for message-level processing.
  • Provides CommonJS, ESM, type declarations, and the rdf-parser-ts CLI.
  • Includes Vitest unit tests, W3C RDF 1.1/RDF1.2 spec compliance scripts, and GitHub Actions CI.
  • Includes performance benchmarks against N3.js and Graphy, with a Graphy-inspired fast path for common N-Triples/N-Quads input.

Notes

N-Triples and N-Quads RDF 1.1/RDF1.2 spec suites run without skips. Turtle and TriG run the official manifests with explicit skips for known unsupported edge cases, documented in package.json.

Full Changelog: https://github.com/pietercolpaert/rdf-parser.ts/commits/0.1.0