包详细信息

@rdfine/generator

tpluscode75MIT0.8.5

Generates rdfine entities from RDF vocabulary

rdf, vocabulary, rdfjs

自述文件

@rdfine/generator

Creates entity types from RDF vocabularies

NPM version Build codecov.io

About

With this package you can easily scaffold JavaScript models based on RDF vocabularies:

  1. rdfs:Class and schema:Class become JavaScript classes
    • rdfs:subClassOf used to build up class hierarchy
    • because JavaScript mixins are used, "multiple inheritance" is possible
  2. Properties are discovered by exploring the rdfs:domain, rdfs:range, schema:domainIncludes and schema:rangeIncludes relations
    • domains and ranges defined using owl:unionOf and owl:disjointUnionOf are also considered
  3. Property return types are assigned:
    • matching JS built-in type for datatype properties
    • resource type for classes within the vocabulary
    • if all fails, the property is defined to return RDF/JS Term

TL;DR;

Check the generated vocabularies to see the generation result.

Check the examples to see how they are used.

Usage

npm i --save @rdfine/generator

The package is a command-line interface which consumes standard input of RDF data.

Usage: rdfine-gen [options]

Options:
  --format <format>        Media type of parser to use
  --namespace <namespace>  Namespace URI
  --prefix <prefix>        prefix
  --outDir <outDir>        Output directory (default: ".")
  --verbose                
  -h, --help               display help for command

Generate from a common vocabulary

The easiest way is to pipe the output from @zazuko/rdf-vocabularies CLI

npm i -g @zazuko/vocabularies
rdf-vocab prefix foaf | rdfine-gen \
  --format application/n-triples \
  --prefix foaf

Generate from the web

If the given vocabulary is dereferencable form the web, curl can be used to fetch it and pipe to the generator

curl http://xmlns.com/foaf/0.1/ -H accept:application/rdf+xml -H | \
  rdfine-gen \
  --format application/rdf+xml \
  --prefix foaf

Options

The process can be further tweaked by adding a rdfine key to package.json. Here's an example of its usage in @rdfine/schema package.

{
  "rdfine": {
    "namespace": "http://schema.org/",
    "prefix": "schema",
    "types": {
      "schema:CssSelectorType": "string",
      "schema:URL": "NamedNode",
      "schema:XPathType": "string"
    },
    "exclude": [
      "Class",
      "DataType",
      "DefinedTerm",
      "EducationalOccupationalCredential",
      "Enumeration",
      "GeospatialGeometry",
      "MedicalBusiness",
      "PhysicalActivityCategory",
      "URL",
      "VirtualLocation"
    ]
  }
}

namespace and prefix can be used in place of the CLI params. The former is optional if the vocabulary is known to @zazuko/rdf-vocabularies

types maps non-standard property ranges to built-in JS types. The keys are prefixed name of the given datatype or class. The values is one of the following: ( 'string', 'number', 'boolean', 'Date', 'NamedNode' ).

exclude causes certain classes to be ignored from being generated and removed where they would be used as property types.

What gets generated

  1. For every class Foo a Foo.ts module:
    1. exports interface Foo
    2. default-exports a mixin function Foo
    3. exports a default implementation used as new Foo.Class()
  2. main index.ts module:
    1. re-exports all Foo interfaces
    2. default-export all mixin functions as an array
  3. lib/namespace/ts is created with a @rdfjs/namespace builder export

更新日志

Change Log

0.8.5

Patch Changes

  • c41dbdd7: Updated @zazuko/env
  • c41dbdd7: Updated @tpluscode/rdf-ns-builders to v5

0.8.4

Patch Changes

  • 9b28f347: Updated dependencies to remove rdf-js references in compiled output

0.8.3

Patch Changes

  • 965859d7: Update to @rdfjs/environment v1 and @zazuko/env v2

0.8.2

Patch Changes

  • 9a838dec: Added changelog to package

0.8.1

Patch Changes

  • 3c90fafa: Use mapped type to declare vocabulary factory

0.8.0

Minor Changes

  • 9d49a7b2: Remove all Partial from mixin types to simplify extending classes

0.7.0

Minor Changes

  • 6cee88c8: Package is not ESM-only

0.6.10

Patch Changes

  • 6e11bd18: No unnecessary imports in enumeration modules
  • a140fd55: Incorrect type generated for names which need quotes
  • 4ce19cbe: Introduce a more stable order of members, exports and imports
  • f7cfefff: Update @tpluscode/rdf-ns-builders to v2

0.6.9

Patch Changes

  • 9acaff8a: Update @rdfjs/formats-common

0.6.8

Patch Changes

  • 45a4be9c: Broken imports or exports of extension modules
  • 46a6b035: Simplify generated enum modules

0.6.7

Patch Changes

  • afe232c3: Add extending mixin to generated class
  • 2cd64dfb: Generate mixins from dash:ShapeClass
  • 0faebb6b: Missing namespace import for types used only as ranges

0.6.6

Patch Changes

  • a63ec35a: Update @tpluscode/rdf-ns-builders and typescript RDF/JS types

0.6.5

Patch Changes

  • 88ff6fa8: Use latest @zazuko/rdf-vocabularies

0.6.4

Patch Changes

  • ae3bc5a1: Datatypes: basic support for owl:onDatatype constructs
  • 030fc0b2: Generate constant types defined as owl:oneOf list

0.6.3

Patch Changes

  • d538e6fb: Predicates sometimes can be generated as duplicate properties

0.6.2

Patch Changes

  • e7988f86: Ensure that properties with changed name get path decorator

0.6.1

Patch Changes

  • 04d8af79: Missing exports of extension modules

0.6.0

Minor Changes

  • 5a0d871f: Prefix terms which would clash with base class members

Patch Changes

  • fe36fd44: Use exclusions for properties
  • 2e2e7a5f: Override property to become RDF/JS Term
  • c341d76b: Add a return type to mixin functions
  • 3113b9c8: Incorrect bundle module imports
  • 60a925e4: Generating mixins extending other vocabs
  • 0d82ae01: Mixins classes implement partial interface
  • e2d18bb7: Add factory method to mixin modules

0.5.0

Minor Changes

  • 0db486f2: Move all modules into lib

    This will allow selective imports in node.

    Also remove any star imports between packages

0.4.3

Patch Changes

  • 3c5269b: Generate Term properties for rdfs:Literal and owl:Thing
  • 6b62158: Handle class/mixin names which are not safe JS identifiers
  • 61ac4a4: Generate mixin modules from owl:Class
  • ac2b29a: Update to dual ESM version of @zazuko/rdf-vcabularies
  • 47be4da: Allow properties with non-alpha characters
  • f0be5e0: Require at least node 13 by package.json engines

0.4.2

Patch Changes

  • 5727c2b: Export enumerations from main module

0.4.1

Patch Changes

  • d69277a: Generated resource types should all have generic dataset argument

0.4.0

Minor Changes

  • 57dfa37: All non-array properties are generated as possibly undefined

0.3.7

Patch Changes

  • 7438e0b: Update to @types/rdf-js v4

0.3.6

Patch Changes

  • 6c016d1: Added support for xsd date/dateTime/time

0.3.5

Patch Changes

  • 4a53697: Enumerations are now generated as typed named nodes

0.3.4

Patch Changes

  • bbf822f: Generating properties which can be single value or list

0.3.3

Patch Changes

  • 5316ea6: Add support for custom datatypes

0.3.2 (2020-07-07)

Features

  • comparing resources also with nodes and pointers (bfaf2dd)

0.3.1 (2020-07-03)

Bug Fixes

  • generator: import mixins only from index (5470637)

0.3.0 (2020-07-03)

Bug Fixes

  • resource: fix bnode id equality (c13c821)

Features

  • rename dependencies to bundles (d67afbe)

BREAKING CHANGES

  • imports need to be updated

0.2.5 (2020-06-08)

Note: Version bump only for package @rdfine/generator

0.2.4 (2020-05-05)

Features

  • generate mixins for specific rdf type to boost perf (06bf552)

0.2.3 (2020-04-29)

Bug Fixes

  • generator: avoid duplicate mixin export in dependency modules (30dcf20)
  • generator: interface annotated on decorators instead of class (c64ebdb)

0.2.2 (2020-04-29)

Bug Fixes

  • generator: do not generate default exports for mixins (840a302)

Features

  • generator: generate dependency modules for every mixin (08976d0)

0.2.1 (2020-04-18)

Bug Fixes

  • export namespace builder from shared package (f341521)

0.2.0 (2020-04-18)

Bug Fixes

  • generator: avoid conflict with rdf as vocabulary package (090aa5e)

Features

  • generator: overriding property value to generate array/list getters (394581b)

0.1.1 (2020-04-15)

Note: Version bump only for package @rdfine/generator

0.1.0 (2020-04-01)

Bug Fixes

  • use same method to slugify dimension table id (9d9205f)
  • generator: do not require namespace for common namespaces (d5d68ed)

Features

  • build: only package es modules and esm node export (4d5fa5b)
  • generator: add mixin cast to rdf:range properties (fa4e188)

BREAKING CHANGES

  • build: some exports have been moved

0.0.2 (2020-03-25)

Bug Fixes

  • core: simplify resource initialization (cfc6731)

0.0.1 (2020-03-25)

Bug Fixes

  • core: plain intialization impossible with union type properties (a545e48)
  • generator: always enable warn and error loggers (1a5999d)
  • generator: generate type-only imports of rdf-js (30c40d1)
  • schema: schema:URL should be treated as rdfResource (cd037ac)

Features

  • generator: create classes which can be easily initialized (3fb0900)
  • generator: discover properties which use owl:unionOf (70c3714)
  • generator: first version of generated schema.org (1759e17)