Last active
January 7, 2023 16:53
-
-
Save EpicKiwi/a903d36eefbd3e8f6aeb59338a92c02b to your computer and use it in GitHub Desktop.
Couchdb Design doc to be used on json-ld database with Schema.org
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function(newDoc, oldDoc, userCtx){ | |
if(newDoc._id.startsWith("_design/")){ | |
return | |
} | |
if(newDoc._deleted){ | |
return; | |
} | |
var context = newDoc["@context"] | |
if(!context || (context != "http://schema.org/" && context[0] != "http://schema.org/")){ | |
throw({forbidden: "json-ld: Main context MUST be \"http://schema.org/\""}) | |
} | |
function checkTypes(obj, name = "."){ | |
if(obj["@type"] && obj["@type"].startsWith("http://schema.org/")){ | |
throw({forbidden: `json-ld: @type of object "${name}@type" MUST NOT start with \"http://schema.org/\"`}) | |
} | |
for(key in obj){ | |
if(typeof obj[key] == "object"){ | |
checkTypes(obj[key], name+""+key+"."); | |
} | |
} | |
} | |
checkTypes(newDoc); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment