@neverblink/linkml
v0.15.1
Published
A Scala 3 cross-platform library and CLI for LinkML schema validation and multi-format code generation (Scala, JSON Schema, SHACL, RDFS)
Maintainers
Readme
@neverblink/linkml
JavaScript / TypeScript bindings for LinkML-Scala – LinkML schema validation and multi-format code generation (JSON Schema, SHACL, RDFS, Scala), compiled from Scala 3 to JavaScript via Scala.js.
The package ships a single self-contained ES module. It has no runtime dependencies.
Installation
npm install @neverblink/linkmlUsage
import { LinkML } from "@neverblink/linkml";
const schema = `
id: https://example.org/my-schema
name: my-schema
prefixes:
linkml: https://w3id.org/linkml/
imports:
- linkml:types
default_range: string
classes:
Person:
tree_root: true
attributes:
name:
age:
range: integer
`;
// Parse the schema once into a reusable handle. The second argument
// is an import map (filename -> YAML source) for any models referenced
// via LinkML \`imports:\`. Pass {} when there are none.
const { view, report } = LinkML.loadFromString(schema, {});
if (!view) throw new Error(JSON.stringify(report, null, 2)); // fatal problems: nothing to generate from
// Then run any generator against the loaded schema.
const jsonSchema = LinkML.jsonSchema(view);
console.log(jsonSchema);
const shacl = LinkML.shacl(view);
console.log(shacl);Loading
There are two ways to load a schema into a SchemaView handle:
loadFromString(schema, importMap)– start from the schema's YAML text. Imported models must be provided in the import map (filename → YAML).loadFromPath(path, importMap)– start from a path into the import map. The root schema is read fromimportMap[path](paths behave like file paths,.yamlis appended when missing). Because the root is tracked from the start of import resolution, this variant is immune to cyclic imports that reference the root schema back.
// loadFromPath: the root lives in the import map under its own path.
const { view } = LinkML.loadFromPath("model.yaml", {
"model.yaml": schema,
"person.yaml": personSchema, // referenced via `imports: - person`
});Available functions
Load a schema into a SchemaView handle (see above), then pass that handle to any generator:
| Function | Returns | Notes |
|----------------------------------------------------------------------| --- |--------------------------------------------------------------|
| loadFromString(schema, importMap, inferMessages?) | LoadResult | parse from YAML text; { view?, report } |
| loadFromPath(path, importMap, inferMessages?) | LoadResult | parse from a path in the import map; cycle-safe for the root |
| jsonSchema(view, open?, treeRootOverride?) | string | JSON Schema |
| shacl(view, open?, onlyClassesFromRootSchema?, format?) | string | SHACL shapes, ttl (default) or nt |
| rdfs(view, onlyClassesFromRootSchema?, format?) | string | RDFS, ttl (default) or nt |
| linkml(view, pruningMode?, skipDerivation?, treeRoot?, outFormat?) | string | derived/pruned LinkML schema |
| scala(view, packageName) | Record<string, string> | filename → generated Scala |
| frictionless(view, pruningMode?, treeRoot?, skipClassesWithoutIdentifier?) | Record<string, string> | filename → Frictionless data package (datapackage.json and schemas/*.json) |
| graphQl(view, pruningMode?, treeRoot?) | string | GraphQL |
| erDiagram(view, pruningMode?, treeRoot?, optionalMarker?) | string | Mermaid entity relationship diagram |
| lint(view, inferMessages?) | object | SchemaValidationReport (JSON) |
| buildInfo() | object | BuildInfo (JSON) – version and build metadata |
See index.d.ts for full type signatures.
Browser use
The module works in Node.js as-is. In the browser it references process.cwd
once, so provide a minimal shim before importing:
<script>
var process = { cwd: () => "/" };
</script>License
Apache-2.0 © NeverBlink
