Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

@tpluscode/rdf-ns-builders

tpluscode100.3kMIT5.0.0TypeScript support: included

Generated RDF/JS namespace builders for common vocabularies

readme

@tpluscode/rdf-ns-builders

Common RDF vocabularies extracted from @zazuko/vocabularies and wrapped as @rdfjs/namespace builder objects.

Also includes TypeScript declarations of the terms included in the known vocabularies as extracted from the actual RDF source file.

Why?

  1. If you're tired of typing const schema = namespace(prefixes.schema) every so often
  2. If you want to have your IDE "Find usages" of a @rdfjs/namespace-generated term

Installation

npm i -S @tpluscode/rdf-ns-builders

Usage

Simply import a namespace builder by its prefix defined in @zazuko/vocabularies

import { schema } from '@tpluscode/rdf-ns-builders'
import { NamedNode } from '@rdfjs/types'

const schemaPerson: NamedNode = schema.Person

Usage with RDF/JS Environment

You can also add all vocabularies to an environment. Note that this will load everything immediately, even if unused

import { NamedNode } from '@rdfjs/types'
import Environment from '@rdfjs/environment/Environment.js'
import NsBuildersFactory from '@tpluscode/rdf-ns-builders'

const rdf = new Environment([NsBuildersFactory])

const schemaPerson: NamedNode = rdf.ns.schema.Person

Loose builder

The namespace builders exported from the main module allow arbitrary term but in TypeScript, an error will be shown if they do not exist in the vocabulary. Alternatively, loose builders can be imported which will ignore terms from outside the vocabulary.

import { schema } from '@tpluscode/rdf-ns-builders/loose'
import { NamedNode } from '@rdfjs/types'

// will not show error
const schemaPerson: NamedNode = schema.Persona

Roll your own

Given a package with same exports as @zazuko/vocabularies, it is possible to generate a set of namespace builders generated from your own vocabularies.

Install required peer dependencies:

npm i -D ts-node ts-morph clownface @zazuko/vocabularies safe-identifier

Run the following command to generate builders package by providing the source package name and output directory.

npm run rdf-ns-builders generate -p @my/vocabularies -o builders

This will create a directory source, containing typescript modules for all vocabularies, similar to those from src.

Adding your own vocabularies

To extend the interface of env.ns you need to add you own factory which will add additional namespace builders to the environment. TypeScript users will also need to extend the CustomPrefixes interface.

// ./ns.ts
import { NamespaceBuilder } from '@rdfjs/namespace'

type ExampleTerms = 'foo' | 'bar

declare module '@tpluscode/rdf-ns-builders' {
  interface CustomNamespaces {
    ex: NamespaceBuilder<ExampleTerms>
  }
}

export class ExampleNsFactory {
  init(this: Environment<NsBuildersFactory | NamespaceFactory>) {
    this.ns = {
      ...this.ns,
      ex: this.namespace<ExampleTerms>('https://example.com/'),
    }
  }
}

Then, use it to create an extended environment.

// ./env.ts
import { create } from '@zazuko/env'
import { ExampleNsFactory } from './ns.js'

export default create(TalosNsFactory)

changelog

Changelog

5.0.0

Major Changes

  • 0946d41: Updated RiCO
  • 0946d41: Updated QUDT vocabularies to v3

Minor Changes

  • 0946d41: Added builders for cur:, dprod: and vso:
  • 0946d41: Updated @rdfjs/types to v2

4.3.0

Minor Changes

  • ff6f87c: Add a way to extend namespace factory

4.2.0

Minor Changes

  • a7a64b0: Add shsh (no terms)
  • a7a64b0: Update m4i terms
  • a7a64b0: Adds SHACL-AF terms

4.1.1

Patch Changes

  • 3ca58e8: Namespace interfaces must be exported to prevent error "Exported variable 'x' has or is using name 'X' from external module "./node_modules/@tpluscode/rdf-ns-builders/vocabularies/x" but cannot be named."

4.1.0

Minor Changes

  • 72556d8: Added factory module for use with @rdfjs/environment

4.0.0

Major Changes

  • 9d5b01d: Removed bogus prefix qudtv
  • 9d5b01d: Updated earl to use correct namespace (s/https/http/)
  • 9d5b01d: Removed the bin from package to remove peer deps

Minor Changes

  • 9d5b01d: Updated prefixes gs1
  • 9d5b01d: Added prefixes cert, dig, la, list, log, m4i, math, oidc, pim, set, solid, stat, string`

3.0.4

Patch Changes

  • c3a07b6: Removed @zazuko/vocabularies from peer deps

3.0.3

Patch Changes

  • 5bea3fc: Added dash-sparql prefix

3.0.2

Patch Changes

  • b649157: v3 was packaged without the modules

3.0.1

Patch Changes

  • 8fb5460: Installing from NPM would call patch-package

3.0.0

Major Changes

  • 6405678: Export ES Modules only

Minor Changes

  • 6405678: Updated all vocabularies
  • 6405678: Added crm and mads prefixes

2.0.1

Patch Changes

  • cd656db: Strict module interface did not include the empty getter for namespace itself

2.0.0

Major Changes

  • 0687532: Make strict the default export

1.1.0

Minor Changes

  • 3aefaf6: Added latest namespaces from @zazuko/rdf-ns-vocabularies:

Patch Changes

  • 3aefaf6: Updated namespaces:
    • constants
    • dbo
    • qkdv
    • quantitykind
    • qudt
    • schema
    • unit

1.0.0

Major Changes

  • 2495728: Updated vocabularies from @zazuko/rdf-vocabularies@2021.5.3:

    • New terms: hydra, quantitykind, unit
    • Fixed namespace of prefix (http://qudt.org/vocab/prefix)

Patch Changes

  • 04704d8: Use @rdfjs/types package instead of old typing
  • 768379b: CLI did not work locally because of double ts-node
  • f9f8edb: Generating failed on prefix with hyphens

0.4.5

Patch Changes

  • Missing ts-node/register

0.4.4

Patch Changes

  • 40878c6: Make bin work with local module path

0.4.3

Patch Changes

  • cfc2cff: Added a strict builders module
  • 17f45d0: Added bin for generating own builders package

0.4.2

Patch Changes

  • bdfa24e: Activity Streams - use correct namespace

0.4.1

Patch Changes

All notable changes to this project will be documented in this file. See standard-version for commit guidelines.

0.4.0 (2020-09-03)

Features

  • update to named nodes with string types (4040e87)

0.3.7 (2020-07-14)

0.3.6 (2020-06-26)

Bug Fixes

  • exports must begin with ./ (134b7dd)

0.3.5 (2020-06-17)

Features

0.3.4 (2020-06-12)

0.3.1 (2020-06-08)

0.3.0 (2020-06-07)

0.2.2 (2020-05-19)

0.2.1 (2020-05-18)

Bug Fixes

  • missing type declarations (86b5568)

0.2.0 (2020-05-18)

⚠ BREAKING CHANGES

  • removed commonjs exports

build

0.1.0 (2020-02-29)

0.0.4 (2020-02-23)

Bug Fixes

  • exports were missing the namespace builder annotation (21447d0)

0.0.3 (2020-02-23)

0.0.2 (2020-02-23)

Bug Fixes

0.0.1 (2020-02-23)

Features

  • generated first version from @zazuko/rdf-vocabularies (a63160c)