Install the openquarry command from npm
The openquarry package on npm installs the command and the library's validators, schemas and types. @framers/openquarry is the same library without the command.
openquarry runs on Node 18 or later and is on npm under the MIT License.
Start a project
npx openquarry init starts a folder of notes or a course, and npx openquarry check validates its frontmatter and manifests. Both are commands of the openquarry package.
Notes
Makes a knowledge base with a fabric manifest, one weave, one loom and a first note.
npx openquarry init my-notes
cd my-notes
npx openquarry checkA course
Makes a course with a weave of kind course, a loom of kind unit and a first lesson.
npx openquarry init my-course --template course
cd my-course
npx openquarry checkCheck a project
check prints one line for each file it checks and lists any errors under it. It exits with 1 when a file is invalid, which fails a CI job.
npx openquarry checkAdd a note or a lesson
new writes a Markdown file with a new id, a slug made from the title, version: 1.0.0 and its contentType.
npx openquarry new note "Scale and distance" --in weaves/notes/getting-startednpx openquarry new lesson "Reading contour lines" --in weaves/my-course/first-unitPrint a new id
A note or a lesson written by hand needs its own id, and this command prints a new UUID.
npx openquarry idThe command needs Node 18 or later. init copies a starter that ships inside the package, so it works offline. It refuses a folder that already holds files unless you pass --force, and it never overwrites a file. The package's README describes every option.
Copy a starter with degit
degit copies the same two starters straight from GitHub. Each starter's check script validates its files with @framers/openquarry.
npx degit framerslab/openquarry/templates/notes my-notes
cd my-notes
npm install
npm run checknpx degit framerslab/openquarry/templates/course my-course
cd my-course
npm install
npm run checkThe degit commands need Node 20 or later. npx degit copies the starter's folder from GitHub without its history.
- The starters on GitHub
- The example course, Reading a map: two units of lessons and exercises, an assessment and a catalogue
- The schemas
- openquarry on npm, @framers/openquarry on npm and the source on GitHub
Install
Install openquarry with your package manager. It runs on Node 18 or later, as an ES module or from CommonJS. For the library without the command, install @framers/openquarry the same way.
npm install openquarrypnpm add openquarryyarn add openquarryMost examples below parse YAML with the yaml package, which npm install yaml adds.
What it exports
Each validator takes a parsed value and returns valid and errors, plus warnings when it has advice. Each line in errors starts with the path of the problem in the value. validateBlocksIndex also takes { normalize: true } and returns the index under the thread names as value.
Validators
validateThreadFrontmatter(frontmatter): a note's or a lesson's frontmatter.validateWeave(weave),validateLoom(loom): aweave.yamland aloom.yaml.validateFabricManifest(manifest): afabric.yaml.validateCatalogue(catalogue): acatalogue.yaml, with the four rules its schema states in words.validateBlocksIndex(index): a compiled blocks index.
Schemas
threadSchema,weaveSchema,loomSchema,fabricSchema,catalogueSchema,blocksIndexSchema: each schema as a JSON Schema object (draft 2020-12), the content of its YAML source.
Types
ThreadFrontmatter,Weave,Loom,FabricManifest,Catalogue,BlocksIndex: the files.CatalogueSubject,CatalogueEntry,ThreadLink,ThreadLinkGroups,ThreadBlock,SkillReference,SuggestedTag: the records inside them.ContentType,DifficultyLevel,LinkType,FabricNodeType: the values a field allows.ValidationResult,NormalizedValidationResult: validator results, with the current field names in a normalized value.
Compatibility exports
strandSchema: deprecated alias forthreadSchema.StrandFrontmatter: deprecated alias forThreadFrontmatter.KnowledgeNodeType: deprecated type for the original stored node values. UseFabricNodeTypefor new nodes.
Files
@framers/openquarry/schema/*.schema.yaml: each schema's YAML source, byte for byte.- The package also ships its docs, the map-reading course under
examples/, and its changelog.
Start a project documents the openquarry command, and From the command line checks one file with the library alone, in one Node command.
Check a note's or a lesson's frontmatter
Parse the YAML between the two --- lines, then pass it to validateThreadFrontmatter. This lesson leaves out version, so the result names it.
import { parse } from 'yaml'
import { validateThreadFrontmatter } from 'openquarry'
const frontmatter = parse(`
id: 70c967bf-2dba-4399-aef1-671174eb904f
slug: scale-and-distance
title: Scale and distance
contentType: lesson
`)
const result = validateThreadFrontmatter(frontmatter)
console.log(result.valid)
for (const error of result.errors) console.log(error)false
/ must have required property 'version'Check fabric.yaml, weave.yaml and loom.yaml
A fabric can have a fabric.yaml, a weave has a weave.yaml and a loom a loom.yaml, and each file has its own validator. A kind is one lowercase word, so Course fails.
import { validateFabricManifest, validateLoom, validateWeave } from 'openquarry'
console.log(validateFabricManifest({ format: 'openquarry', version: 2 }).valid)
console.log(validateLoom({ slug: 'the-map', title: 'The map', kind: 'unit' }).valid)
const weave = validateWeave({ slug: 'reading-a-map', title: 'Reading a map', kind: 'Course' })
for (const error of weave.errors) console.log(error)true
true
/kind must match pattern "^[a-z][a-z0-9-]*$"Check a catalogue
validateCatalogue checks a catalogue.yaml against its schema, then four rules a schema cannot hold. Each id is listed once, every link names something the catalogue lists, an entry's home is one of its subjects, and no chain of links makes a circle.
import { validateCatalogue } from 'openquarry'
const result = validateCatalogue({
id: 'field-skills',
title: 'Field skills',
subjects: [{ id: 'navigation', title: 'Navigation', broader: [] }],
entries: [
{
slug: 'reading-a-map',
home: 'outdoors',
subjects: ['navigation'],
requires: ['compass-basics'],
},
],
})
for (const error of result.errors) console.log(error)/entries/0/home must be one of the entry's subjects: "navigation"
/entries/0/requires/0 names an entry the catalogue does not list: "compass-basics"Check a saved blocks index
A blocks index lists tagged blocks in threads and uses threadPath in tag references. Save this script as blocks.mjs and run node blocks.mjs blocks-index.json on a generated index. Version 1 compatibility explains the older field names.
import { readFileSync } from 'node:fs'
import { validateBlocksIndex } from 'openquarry'
const index = JSON.parse(readFileSync(process.argv[2], 'utf8'))
const result = validateBlocksIndex(index)
console.log(result.valid)trueUse the JSON Schemas in your own validator
Each schema is exported as an object, JSON Schema draft 2020-12. Compile it with Ajv's 2020 build and ajv-formats (npm install ajv ajv-formats), or with any validator that reads draft 2020-12.
import Ajv2020 from 'ajv/dist/2020.js'
import addFormats from 'ajv-formats'
import { loomSchema } from 'openquarry'
const ajv = new Ajv2020({ allErrors: true, strict: false })
addFormats(ajv)
const validate = ajv.compile(loomSchema)
console.log(validate({ slug: 'the-map', title: 'The map', kind: 'unit' }))
console.log(validate({ slug: 'the-map' }))
console.log(validate.errors[0].message)true
false
must have required property 'title'Catch a wrong value with the TypeScript types
The types describe every file the schemas check. A value the format does not allow, such as contentType: 'lecture', fails type checking before the code runs.
import { validateThreadFrontmatter, type ThreadFrontmatter } from 'openquarry'
const lesson: ThreadFrontmatter = {
id: '70c967bf-2dba-4399-aef1-671174eb904f',
slug: 'scale-and-distance',
title: 'Scale and distance',
version: '1.0.0',
contentType: 'lesson',
difficulty: 'beginner',
teaches: ['field-skills/skill/map-scale'],
}
console.log(validateThreadFrontmatter(lesson).valid)trueLoad the package from CommonJS
The package ships an ES module build and a CommonJS build, so require works too.
const { validateLoom } = require('openquarry')
console.log(validateLoom({ slug: 'the-map', title: 'The map', kind: 'unit' })){ valid: true, errors: [] }Read the YAML sources
The package ships each schema's YAML source, byte for byte, under @framers/openquarry/schema/. These files come from @framers/openquarry, so install it to import them.
import { readFileSync } from 'node:fs'
import { createRequire } from 'node:module'
import { parse } from 'yaml'
const require = createRequire(import.meta.url)
const file = require.resolve('@framers/openquarry/schema/weave.schema.yaml')
console.log(parse(readFileSync(file, 'utf8')).title)WeaveCheck files in your editor
Every schema has a stable address on this site. Editors built on the YAML language server read a first-line comment that names a schema, then check the file as you type.
# yaml-language-server: $schema=https://openquarry.dev/schema/v1/weave.schema.json
slug: reading-a-map
title: Reading a map
kind: courseFrom the command line
npx openquarry check validates a whole project, as Check a project shows. To check one file with the library alone, this Node command reads a lesson saved as scale-and-distance.md, prints the result and exits with 1 when the frontmatter is invalid.
npm install openquarry yaml
node --input-type=module -e '
import { readFileSync } from "node:fs";
import { parse } from "yaml";
import { validateThreadFrontmatter } from "openquarry";
const text = readFileSync(process.argv[1], "utf8");
const match = /^---\r?\n([\s\S]*?)\r?\n---(?:\r?\n|$)/.exec(text);
if (!match) throw new Error("Missing YAML frontmatter");
const result = validateThreadFrontmatter(parse(match[1]));
console.log(result);
process.exitCode = result.valid ? 0 : 1;
' scale-and-distance.mdLinks
- @framers/openquarry on npm
- Source on GitHub, with the validator and types and the changelog
- JSON Schemas: thread.schema.json, blocks-index.schema.json, catalogue.schema.json, fabric.schema.json, loom.schema.json, weave.schema.json, and the index with each file's hash
- The guides to the format, courses and lessons, writing files with a language model and the schema addresses