Commit 39091ffc authored by anton's avatar anton
Browse files

Add Annotation and Map models

parent dcd964f9
......@@ -971,6 +971,11 @@
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz",
"integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g="
},
"qs": {
"version": "6.7.0",
"resolved": "https://registry.npmjs.org/qs/-/qs-6.7.0.tgz",
"integrity": "sha512-VCdBRNFTX1fyE7Nb6FYoURo/SPe62QCaAyzJvUjwRaIsc+NePBEniHlvxFmmX56+HZphIGtV0XeCirBtpDrTyQ=="
}
}
},
......@@ -2128,6 +2133,11 @@
"resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz",
"integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g="
},
"qs": {
"version": "6.7.0",
"resolved": "https://registry.npmjs.org/qs/-/qs-6.7.0.tgz",
"integrity": "sha512-VCdBRNFTX1fyE7Nb6FYoURo/SPe62QCaAyzJvUjwRaIsc+NePBEniHlvxFmmX56+HZphIGtV0XeCirBtpDrTyQ=="
},
"safe-buffer": {
"version": "5.1.2",
"resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.2.tgz",
......@@ -2716,9 +2726,9 @@
}
},
"harmony-reflect": {
"version": "1.6.1",
"resolved": "https://registry.npmjs.org/harmony-reflect/-/harmony-reflect-1.6.1.tgz",
"integrity": "sha512-WJTeyp0JzGtHcuMsi7rw2VwtkvLa+JyfEKJCFyfcS0+CDkjQ5lHPu7zEhFZP+PDSRrEgXa5Ah0l1MbgbE41XjA=="
"version": "1.6.2",
"resolved": "https://registry.npmjs.org/harmony-reflect/-/harmony-reflect-1.6.2.tgz",
"integrity": "sha512-HIp/n38R9kQjDEziXyDTuW3vvoxxyxjxFzXLrBr18uB47GnSt+G9D29fqrpM5ZkspMcPICud3XsBJQ4Y2URg8g=="
},
"has": {
"version": "1.0.3",
......@@ -3521,9 +3531,9 @@
}
},
"luxon": {
"version": "1.25.0",
"resolved": "https://registry.npmjs.org/luxon/-/luxon-1.25.0.tgz",
"integrity": "sha512-hEgLurSH8kQRjY6i4YLey+mcKVAWXbDNlZRmM6AgWDJ1cY3atl8Ztf5wEY7VBReFbmGnwQPz7KYJblL8B2k0jQ=="
"version": "1.27.0",
"resolved": "https://registry.npmjs.org/luxon/-/luxon-1.27.0.tgz",
"integrity": "sha512-VKsFsPggTA0DvnxtJdiExAucKdAnwbCCNlMM5ENvHlxubqWd0xhZcdb4XgZ7QFNhaRhilXCFxHuoObP5BNA4PA=="
},
"make-dir": {
"version": "1.3.0",
......@@ -3548,6 +3558,13 @@
"schema-object": "^4.0.11",
"slug": "^0.9.1",
"validator": "^9.4.1"
},
"dependencies": {
"validator": {
"version": "9.4.1",
"resolved": "https://registry.npmjs.org/validator/-/validator-9.4.1.tgz",
"integrity": "sha512-YV5KjzvRmSyJ1ee/Dm5UED0G+1L4GZnLN3w6/T+zZm8scVua4sOhYKWTUrKa0H/tMiJyO9QLHMPN+9mB/aMunA=="
}
}
},
"mbjs-filesystem": {
......@@ -3592,6 +3609,11 @@
"version": "3.4.0",
"resolved": "https://registry.npmjs.org/uuid/-/uuid-3.4.0.tgz",
"integrity": "sha512-HjSDRw6gZE5JMggctHBcjVak08+KEVhSIiDzFnT9S9aegmp85S/bReBVTb4QTFaRNptJ9kuYaNhnbNEOkbKb/A=="
},
"validator": {
"version": "9.4.1",
"resolved": "https://registry.npmjs.org/validator/-/validator-9.4.1.tgz",
"integrity": "sha512-YV5KjzvRmSyJ1ee/Dm5UED0G+1L4GZnLN3w6/T+zZm8scVua4sOhYKWTUrKa0H/tMiJyO9QLHMPN+9mB/aMunA=="
}
}
},
......@@ -4611,9 +4633,12 @@
"integrity": "sha512-XRsRjdf+j5ml+y/6GKHPZbrF/8p2Yga0JPtdqTIY2Xe5ohJPD9saDJJLPvp9+NSBprVvevdXZybnj2cv8OEd0A=="
},
"qs": {
"version": "6.7.0",
"resolved": "https://registry.npmjs.org/qs/-/qs-6.7.0.tgz",
"integrity": "sha512-VCdBRNFTX1fyE7Nb6FYoURo/SPe62QCaAyzJvUjwRaIsc+NePBEniHlvxFmmX56+HZphIGtV0XeCirBtpDrTyQ=="
"version": "6.10.1",
"resolved": "https://registry.npmjs.org/qs/-/qs-6.10.1.tgz",
"integrity": "sha512-M528Hph6wsSVOBiYUnGf+K/7w0hNshs/duGsNXPUCLH5XAqjEtiPGwNONLV0tBH8NoGb0mvD5JubnUTrujKDTg==",
"requires": {
"side-channel": "^1.0.4"
}
},
"radix-router": {
"version": "3.0.1",
......@@ -5814,9 +5839,9 @@
}
},
"validator": {
"version": "9.4.1",
"resolved": "https://registry.npmjs.org/validator/-/validator-9.4.1.tgz",
"integrity": "sha512-YV5KjzvRmSyJ1ee/Dm5UED0G+1L4GZnLN3w6/T+zZm8scVua4sOhYKWTUrKa0H/tMiJyO9QLHMPN+9mB/aMunA=="
"version": "13.6.0",
"resolved": "https://registry.npmjs.org/validator/-/validator-13.6.0.tgz",
"integrity": "sha512-gVgKbdbHgtxpRyR8K0O6oFZPhhB5tT1jeEHZR0Znr9Svg03U0+r9DXWMrnRAB+HtCStDQKlaIZm42tVsVjqtjg=="
},
"vary": {
"version": "1.1.2",
......
// annotations-model.js - A mongoose model
//
// See http://mongoosejs.com/docs/models.html
// for more of what you can do here.
const
constants = require('mbjs-data-models/src/constants'),
personSchema = require('./schema/person'),
bodySchema = require('./schema/body'),
targetSchema = require('./schema/target'),
stylesheetSchema = require('./schema/stylesheet')
module.exports = function (app) {
const modelName = 'annotations'
const mongooseClient = app.get('mongooseClient')
const { Schema } = mongooseClient
const schema = new Schema({
text: { type: String, required: true }
'@context': {
type: String,
readOnly: true,
default: 'http://www.w3.org/ns/anno.jsonld'
},
type: {
type: String,
enum: ['Annotation'],
default: 'Annotation'
},
/** Annotation data */
creator: personSchema(),
body: bodySchema({
Schema
}),
motivation: {
type: String,
enum: constants.ANNOTATION_MOTIVATIONS
},
target: targetSchema({
Schema
}),
stylesheet: stylesheetSchema({
Schema,
isSubdoument: true
})
}, {
timestamps: true
})
......
const {
DateTime,
Duration,
Interval
} = require('luxon')
const stringifyValue = (value) => {
if (typeof value === 'number') return value.toString()
if (value instanceof Date) {
return DateTime.fromJSDate(value).toISO()
}
if (value instanceof DateTime) {
return value.toISO()
}
if (value instanceof Duration) {
return value.toISO()
}
if (value instanceof Interval) {
return value.toISO()
}
return value
}
module.exports = stringifyValue
// maps-model.js - A mongoose model
//
// See http://mongoosejs.com/docs/models.html
// for more of what you can do here.
const
constants = require('mbjs-data-models/src/constants'),
personSchema = require('./schema/person'),
stylesheetSchema = require('./schema/stylesheet'),
serializedObjectSchema = require('./schema/serialized-object')
module.exports = function (app) {
const modelName = 'maps'
const mongooseClient = app.get('mongooseClient')
const { Schema } = mongooseClient
const schema = new Schema({
text: { type: String, required: true }
/** Document ID & ownership **/
'@context': {
type: String,
readOnly: true,
get: () => `${constants.BASE_URI_NS}map.jsonld`
},
type: [{
type: String,
required: true,
/** Allowed types for Map */
enum: constants.MAP_CLASSES
}],
creator: personSchema(),
/** Map title */
title: {
type: String,
required: true
},
configuration: serializedObjectSchema({
Schema,
isSubdoument: true
}),
stylesheet: stylesheetSchema({
Schema,
isSubdoument: true
})
}, {
timestamps: true
})
......
const
validators = require('../validators'),
constants = require('mbjs-data-models/src/constants'),
sourceSchema = require('./source'),
selectorSchema = require('./selector')
const bodySchema = (opts = {}) => {
const schema = {
id: {
type: String,
validate: validators.url,
required: true
},
format: {
type: String,
validate: validators.mimeType,
required: true
},
type: {
type: String,
required: true
},
purpose: {
type: String,
enum: constants.ANNOTATION_MOTIVATIONS,
required: true
},
value: { type: String },
language: [{ type: String }],
textDirection: { type: String, enum: ['ltr', 'rtl', 'auto'] },
processingLanguage: { type: String },
source: sourceSchema({
Schema: opts.Schema,
isSubdocument: true
}),
selector: selectorSchema({
Schema: opts.Schema,
isSubdocument: true
})
}
return opts.isSubdocument ? new opts.Schema(schema) : schema
}
module.exports = bodySchema
const
uuid = require('uuid'),
validators = require('../validators')
const personSchema = (opts = {}) => {
const schema = {
name: {
type: String
},
id: {
type: String,
validate: validators.url
}
}
if (opts.hasId) {
schema._id = {
type: String,
alias: 'uuid',
default: () => uuid.v4(),
validate: validators.uuid,
required: true
}
}
return opts.isSubdocument ? new opts.Schema(schema) : schema
}
module.exports = personSchema
const
qs = require('qs'),
stringifyValue = require('../lib/stringify-value')
const selectorSchema = (opts = {}) => {
const schema = {
type: {
type: String,
enum: ['FragmentSelector'],
required: true
},
value: {
type: String,
required: true,
set: value => {
if (typeof value === 'object') {
for (const key of Object.keys(value)) {
if (Array.isArray(value[key])) value[key] = value[key].map(v => stringifyValue(v)).join(',')
else value[key] = stringifyValue(value[key])
}
const enableEncoding = !!(process && process.env && process.env.FLAG_ENABLE_FRAGMENT_ENCODING)
return qs.stringify(value, {
encodeValuesOnly: enableEncoding,
encode: enableEncoding
})
}
return value
}
},
conformsTo: {
type: String,
enum: ['http://www.w3.org/TR/media-frags/']
}
}
return opts.isSubdocument ? new opts.Schema(schema) : schema
}
module.exports = selectorSchema
const
validators = require('../validators')
const serializedObjectSchema = (opts = {}) => {
const schema = {
value: {
type: String,
set: function (value) {
if (typeof value !== 'string') {
this.format = 'application/json'
return JSON.stringify(value)
}
}
},
format: {
type: String,
validate: validators.mimeType
},
id: {
type: String,
validate: validators.url
}
}
if (opts.isSubdocument) {
const instance = new opts.Schema(schema)
instance.virtual('_value').get(function () {
if (this.value && this.format === 'application/json') {
return JSON.parse(this.value)
}
return this.value
})
return instance
}
return schema
}
module.exports = serializedObjectSchema
const
validators = require('../validators'),
selectorSchema = require('./selector')
const sourceSchema = (opts = {}) => {
const schema = {
id: {
type: String,
validate: validators.url
},
type: {
type: String,
validate: validators.mimeType
},
selector: selectorSchema({ Schema: opts.Schema, isSubdocument: true })
}
return opts.isSubdocument ? new opts.Schema(schema) : schema
}
module.exports = sourceSchema
const stylesheetSchema = (opts = {}) => {
const schema = {
value: { type: String },
id: { type: String }
}
return opts.isSubdocument ? new opts.Schema(schema) : schema
}
module.exports = stylesheetSchema
const
selectorSchema = require('./selector'),
sourceSchema = require('./source')
const targetSchema = (opts = {}) => {
const schema = {
type: {
type: String
},
id: {
type: String
},
source: {
type: sourceSchema({
Schema: opts.Schema,
isSubdocument: true
}),
set: value => {
if (typeof value === 'string') value = { id: value }
return value
}
},
selector: selectorSchema(),
language: [{
type: String
}],
textDirection: {
type: String,
enum: ['ltr', 'rtl', 'auto']
},
processingLanguage: {
type: String
}
}
return opts.isSubdoument ? new opts.Schema(schema) : schema
}
module.exports = targetSchema
const
mimeType = require('./mime-type'),
url = require('./url'),
uuid = require('./uuid')
module.exports = {
mimeType,
url,
uuid
}
const isMimeType = require('validator/lib/isMimeType')
module.exports = {
validator: isMimeType,
message: () => 'errors.invalid_mime_type'
}
const isURL = require('validator/lib/isURL')
module.exports = {
validator: isURL,
message: () => 'errors.invalid_url'
}
const uuid = require('uuid')
module.exports = {
validator: uuid.validate,
message: () => 'errors.invalid_uuid'
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment