From 283d61651aff17242f07668f790d2c97b5362686 Mon Sep 17 00:00:00 2001 From: Auke van Slooten Date: Wed, 27 Sep 2023 13:10:21 +0200 Subject: [PATCH] added submodule dependency, missing schema's, package.json, README and test fixed context.json --- .gitmodules | 3 +++ README.md | 2 ++ context.json | 18 +++++------------- curriculum-basis | 1 + package.json | 17 +++++++++++++++++ schema.jsonld | 22 ++++++++++++++++++++++ test/repl.mjs | 46 ++++++++++++++++++++++++++++++++++++++++++++++ test/test.mjs | 23 +++++++++++++++++++++++ 8 files changed, 119 insertions(+), 13 deletions(-) create mode 100644 .gitmodules create mode 100644 README.md create mode 160000 curriculum-basis create mode 100644 package.json create mode 100644 schema.jsonld create mode 100644 test/repl.mjs create mode 100644 test/test.mjs diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..7381b85 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "curriculum-basis"] + path = curriculum-basis + url = https://github.com/slonl/curriculum-basis diff --git a/README.md b/README.md new file mode 100644 index 0000000..ada6d68 --- /dev/null +++ b/README.md @@ -0,0 +1,2 @@ +# curriculum-samenhang + SLO Samenhang curriculum (relaties en begrippen) diff --git a/context.json b/context.json index c733e87..20ccd07 100644 --- a/context.json +++ b/context.json @@ -27,11 +27,11 @@ "type": "object", "properties": { "id": { - "$ref": "#/definitions/uuid" + "$ref": "https://opendata.slo.nl/curriculum/schemas/curriculum-basis/context.json#/definitions/uuid" }, "title": { "type": "string" - } + }, "fo_doelzin_id": { "allOf": [ { "$ref": "https://opendata.slo.nl/curriculum/schemas/curriculum-basis/context.json#/definitions/uuidArray" }, @@ -51,17 +51,13 @@ ] } }, - "anyOf" : [ - { "required": ["id","title","fo_doelzin"] }, - { "required": ["id","title","fo_toelichting_id"] }, - { "required": ["id","title","fo_uitwerking_id"] } - ] + "required": ["id","title"] }, "relatie": { "type": "object", "properties": { "id": { - "$ref": "#/definitions/uuid" + "$ref": "https://opendata.slo.nl/curriculum/schemas/curriculum-basis/context.json#/definitions/uuid" }, "title": { "type": "string" @@ -85,11 +81,7 @@ ] } }, - "anyOf" : [ - { "required": ["id","title","fo_doelzin","fo_doelzin"] }, - { "required": ["id","title","fo_toelichting_id","fo_toelichting_id"] }, - { "required": ["id","title","fo_uitwerking_id","fo_uitwerking_id"] } - ] + "required": ["id","title"] }, "allEntities" : { "properties" : { diff --git a/curriculum-basis b/curriculum-basis new file mode 160000 index 0000000..ce330e9 --- /dev/null +++ b/curriculum-basis @@ -0,0 +1 @@ +Subproject commit ce330e92515570d884c83a8ff6eb8632b0b01389 diff --git a/package.json b/package.json new file mode 100644 index 0000000..25835ba --- /dev/null +++ b/package.json @@ -0,0 +1,17 @@ +{ + "name": "curriculum-samenhang", + "description": "Curriculum Context: Samenhang (relaties en begrippen)", + "main": "context.json", + "scripts": { + "test": "node test/test.mjs", + "repl": "NODE_REPL_HISTORY=.repl_history && node test/repl.mjs" + }, + "author": "SLO", + "license": "MIT", + "dependencies": { + "ajv": "^6.5.5", + "curriculum-js": "^0.3.7", + "jsondiffpatch": "^0.3.11", + "uuid": "^3.3.2" + } +} diff --git a/schema.jsonld b/schema.jsonld new file mode 100644 index 0000000..0295e3b --- /dev/null +++ b/schema.jsonld @@ -0,0 +1,22 @@ +{ + "@context": { + "sh": "http://opendata.slo.nl/curriculum/schemas/samenhang.jsonld", + "id": { + "@id": "@id" + }, + "title": { + "@id": "http://purl.org/dc/terms/title", + "@type": "@id" + }, + "description": { + "@id": "http://purl.org/dc/terms/description", + "@type": "@id" + }, + "sh_tag": { + "@id": "sh:#sh_tag" + }, + "sh_relatie": { + "@id": "sh:#sh_relatie" + } + } +} \ No newline at end of file diff --git a/test/repl.mjs b/test/repl.mjs new file mode 100644 index 0000000..555ff0b --- /dev/null +++ b/test/repl.mjs @@ -0,0 +1,46 @@ +// load the curriculum-js library +import Curriculum from 'curriculum-js' +// load node filesystem support +import fs from 'fs' +import repl from 'repl'; + +// create an async function, so we can use await inside it +async function main() { + + // create new curriculum instance + const curriculum = new Curriculum() + + // read the list of all contexts from the file /curriculum-contexts.txt + const schemas = fs.readFileSync('curriculum-contexts.txt','utf8') + .split(/\n/g) // split the file on newlines + .map(line => line.trim()) // remove leading and trailing whitespace + .filter(Boolean) // filter empty lines + + // load all contexts from the editor/ and master/ folders + let loadedSchemas = schemas.map( + schema => curriculum.loadContextFromFile(schema, schema+'/context.json') + ).concat( + curriculum.loadContextFromFile('curriculum-samenhang', 'context.json') + ) + + // wait untill all contexts have been loaded, and return the promise values as schemas + Promise.allSettled(loadedSchemas).then((settledSchemas) => { + loadedSchemas = settledSchemas.map(promise => promise.value) + }) + .then(() => { + + var server = repl.start({ + ignoreUndefined: true + }); + + server.context.curriculum = curriculum; + if (process.env.NODE_REPL_HISTORY) { + server.setupHistory(process.env.NODE_REPL_HISTORY, (e) => { if (e) console.log(e); } ); + } else { + console.log('Set environment variable NODE_REPL_HISTORY=.repl_history to enable persistent REPL history'); + } + + }) +} + +main() \ No newline at end of file diff --git a/test/test.mjs b/test/test.mjs new file mode 100644 index 0000000..9b2393d --- /dev/null +++ b/test/test.mjs @@ -0,0 +1,23 @@ +import Curriculum from "curriculum-js"; + +async function validate() { + var curriculum = new Curriculum(); + var schema = await curriculum.loadContextFromFile( + "curriculum-samenhang", + "context.json" + ); + await curriculum.loadContextFromFile( + "curriculum-samenhang", + "curriculum-basis/context.json" + ); + try { + await curriculum.validate(schema); + console.log("Data is valid!"); + } catch (error) { + error.validationErrors.forEach((error) => { + console.log(error.instancePath + ": " + error.message); + }); + } +} + +validate(); \ No newline at end of file