Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

digirati-annotation-bridge

Package Overview
Dependencies
Maintainers
3
Versions
164
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

digirati-annotation-bridge - npm Package Compare versions

Comparing version 0.8.11 to 0.8.12

17

es/annotationBody.js

@@ -13,4 +13,10 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

export function tagClassForUri(uri) {
if (!uri) {
return null;
}
var regex = /\/topics\/(?:virtual:)?([A-Za-z_+-].+)\//;
var matches = regex.exec(uri);
if (!matches) {
return null;
}

@@ -45,3 +51,3 @@ if (matches.length > 1) {

}
if (Object.prototype.toString.call(body) !== '[object Object]' && body.value) {
if (Object.prototype.toString.call(body) === '[object Object]' && body.value) {
return new AnnotationBody(null, body['value']);

@@ -64,5 +70,12 @@ }

return new AnnotationBody(type, textualBody ? textualBody[0]['value'] : null, source);
return new AnnotationBody(type, AnnotationBody.getFirstBody(textualBody), source);
};
AnnotationBody.getFirstBody = function getFirstBody(textualBody) {
if (Array.isArray(textualBody) && textualBody.length > 0 && textualBody[0] !== null) {
return textualBody[0].value;
}
return {};
};
return AnnotationBody;

@@ -69,0 +82,0 @@ }();

@@ -66,2 +66,4 @@ var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };

return createDraftFromAnnotation(resourceTemplate, anno, scale);
}).filter(function (e) {
return e;
});

@@ -122,2 +124,6 @@ }

export function detectTypeOfAnnotation(annotation) {
if (!annotation || !annotation.body) {
return 'UNKNOWN';
}
if (annotation.body && annotation.body.type === 'SpecificResource') {

@@ -158,2 +164,8 @@ return 'SPECIFIC_RESOURCE';

}
// Filter out empty bodied annotations.
var body = getAnnotationBody(annotation);
if (body === null) {
return null;
}
return {

@@ -160,0 +172,0 @@ id: annotation.id,

@@ -5,4 +5,10 @@ import { ID, OMEKA_LABEL } from './vocab';

export function castBool(str) {
if (str === undefined) {
return false;
}
if (str === true) return true;
if (str === false) return false;
if (typeof str !== 'string') {
return false;
}
return str.toLowerCase() === 'true';

@@ -38,7 +44,25 @@ }

export function castId(value, defaultValue) {
return (value[ID] ? value[ID] : value) || defaultValue;
export function caseIdWithContext(value, context) {
var contexts = Object.keys(context).map(function (key) {
return { key: key, id: context[key] && context[key][ID] ? context[key][ID] : null };
});
var found = contexts.find(function (v) {
if (!v.id) {
return false;
}
return value.substr(0, v.id.length) === v.id;
});
if (!found) {
return value.replace('#', ':');
}
return found.key + ':' + value.substr(found.id.length + 1);
}
export function get(value) {
export function castId(value, defaultValue, context) {
var returnValue = (value[ID] ? value[ID] : value) || defaultValue || '';
return context ? caseIdWithContext(returnValue, context) : returnValue;
}
export function get(value, context) {
return function (prop, defaultValue) {

@@ -106,2 +130,6 @@ return value ? value[prop] : defaultValue;

};
}
export function warning(component, id, message) {
process.env.NODE_ENV !== 'production' && process.env.NODE_ENV !== 'test' && console.warn('WARNING: ' + component + '\n==================================================\nPlease check model at:\n' + id + '\n\n' + message + '\n');
}

32

es/model/CaptureModel.js

@@ -5,4 +5,4 @@ function _objectWithoutProperties(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; }

import { castBool, castId, get, labelId, motivationFromForm } from '../helpers';
import { COMBINE, DESCRIPTION, EXTERNALISE, HAS_PART, HUMAN_READABLE, ID, LABEL_PARTS, MOTIVATED_BY, MULTIPLE, OMEKA_LABEL, SELECTOR, SERIALIZE, TITLE, UI_GROUP } from '../vocab';
import { castBool, castId, get, labelId, motivationFromForm, warning } from '../helpers';
import { TYPE, COMBINE, DESCRIPTION, EXTERNALISE, HAS_PART, HUMAN_READABLE, ID, LABEL_PARTS, MOTIVATED_BY, MULTIPLE, OMEKA_LABEL, SELECTOR, SERIALIZE, TITLE, UI_GROUP, UI_CHOICE } from '../vocab';
import Field from './Field';

@@ -16,3 +16,11 @@

var $ = get(jsonLd);
return new CaptureModel($(ID), $(TITLE), $(DESCRIPTION), {
if ($(HAS_PART) === undefined) {
warning('CaptureModel', $(ID), 'No fields found in this form, expected in field ' + HAS_PART);
}
if ($(TITLE) === undefined) {
warning('CaptureModel', $(ID), 'No title found in this form, expected in field ' + TITLE);
}
return new CaptureModel($('@context'), $(ID), $(TITLE), $(DESCRIPTION), {
combine: castBool($(COMBINE, true)),

@@ -24,7 +32,7 @@ externalise: castBool($(EXTERNALISE, true)),

// selectorValue: $(),
selector: $(SELECTOR) ? castId($(SELECTOR)).toLowerCase() : null,
selector: $(SELECTOR) ? castId($(SELECTOR), '', $('@context')).toLowerCase() : null,
motivatedBy: motivationFromForm(labelId($(MOTIVATED_BY))),
labelParts: labelId($(LABEL_PARTS))
}, asArray($(HAS_PART)).map(function (field) {
return Field.fromJsonLD(field);
return Field.fromJsonLD(field, $('@context'));
}));

@@ -60,3 +68,3 @@ };

function CaptureModel(id, title, description, metaData, fields) {
function CaptureModel(context, id, title, description, metaData, fields) {
_classCallCheck(this, CaptureModel);

@@ -66,2 +74,3 @@

this.context = context;
this.id = id;

@@ -76,5 +85,14 @@ this.title = title;

var $ = get(jsonLd);
if ($(UI_GROUP) ? $(UI_GROUP)[ID] === 'madoc:form' : false) {
if (castId($(UI_GROUP), false, $('@context')) === 'madoc:form') {
if (castBool($(UI_CHOICE), false)) {
var firstChild = Array.isArray($(HAS_PART)) ? $(HAS_PART)[0] : $(HAS_PART);
var firstChildIsField = !!firstChild['crowds:uiInputType'];
warning('CaptureModel', $(ID), 'we found the following conflicts:\n - This model is marked as a madoc:form\n - First child ' + (firstChildIsField ? 'IS' : 'IS NOT') + ' detected as a form field\n - The model is marked as a choice (crowds:uiChoice), which is incompatible with forms\n \nWe\'ve continued under the assumtion that this is a form. \nPlease update the model to get rid of this warning.\n');
}
return true;
}
// @todo remove temporary fix.
console.warn('CaptureModel:', 'please use JSON-LD fields so that @id is equal to the QName.');
return $(UI_GROUP) ? $(UI_GROUP)[OMEKA_LABEL] === 'madoc:form' : false;

@@ -81,0 +99,0 @@ };

@@ -8,3 +8,3 @@ function _objectWithoutProperties(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; }

import { COMBINE, DESCRIPTION, EXTERNALISE, HAS_PART, HUMAN_READABLE, ID, LABEL_PARTS, MOTIVATED_BY, MULTIPLE, SERIALIZE, TITLE, UI_CHOICE } from '../vocab';
import { castBool, get, labelId, motivationFromForm } from '../helpers';
import { castBool, get, labelId, motivationFromForm, warning } from '../helpers';
import { constructUnknownTemplate } from '../index';

@@ -15,2 +15,11 @@

var $ = get(choice);
if ($(UI_CHOICE) === undefined) {
warning('Choice', $(ID), 'There is not a choice field on this Choice/Form. Working under the assumtion that it is a FORM and not a choice.');
}
var firstChild = Array.isArray($(HAS_PART)) ? $(HAS_PART)[0] : $(HAS_PART);
var firstChildIsField = !!firstChild['crowds:uiInputType'];
if (castBool($(UI_CHOICE), false) === true && Array.isArray($(HAS_PART))) {}
return $(UI_CHOICE) === 'True' && Array.isArray($(HAS_PART));

@@ -17,0 +26,0 @@ };

@@ -20,3 +20,3 @@ var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };

function Field(id, inputType, annotationMetaData, omekaMetaData, metaData) {
function Field(context, id, inputType, annotationMetaData, omekaMetaData, metaData) {
_classCallCheck(this, Field);

@@ -26,2 +26,3 @@

this.context = context;
this.id = id;

@@ -41,7 +42,9 @@ this.inputType = inputType;

Field.fromJsonLD = function fromJsonLD(jsonLd) {
Field.fromJsonLD = function fromJsonLD(jsonLd, inheritedContext) {
var _$;
var $ = get(jsonLd);
return new Field($(ID), $(INPUT_TYPE, (_$ = {}, _$[ID] = null, _$))[ID], {
var $ = get(jsonLd, inheritedContext);
var context = $('@context', inheritedContext);
return new Field(context, $(ID), $(INPUT_TYPE, (_$ = {}, _$[ID] = null, _$))[ID], {
options: $(INPUT_OPTIONS),

@@ -48,0 +51,0 @@ autocomplete: Field.getAutocompleteEndpoint($(INPUT_OPTIONS))

@@ -18,4 +18,10 @@ 'use strict';

function tagClassForUri(uri) {
if (!uri) {
return null;
}
var regex = /\/topics\/(?:virtual:)?([A-Za-z_+-].+)\//;
var matches = regex.exec(uri);
if (!matches) {
return null;
}

@@ -50,3 +56,3 @@ if (matches.length > 1) {

}
if (Object.prototype.toString.call(body) !== '[object Object]' && body.value) {
if (Object.prototype.toString.call(body) === '[object Object]' && body.value) {
return new AnnotationBody(null, body['value']);

@@ -69,5 +75,12 @@ }

return new AnnotationBody(type, textualBody ? textualBody[0]['value'] : null, source);
return new AnnotationBody(type, AnnotationBody.getFirstBody(textualBody), source);
};
AnnotationBody.getFirstBody = function getFirstBody(textualBody) {
if (Array.isArray(textualBody) && textualBody.length > 0 && textualBody[0] !== null) {
return textualBody[0].value;
}
return {};
};
return AnnotationBody;

@@ -74,0 +87,0 @@ }();

@@ -89,2 +89,4 @@ 'use strict';

return createDraftFromAnnotation(resourceTemplate, anno, scale);
}).filter(function (e) {
return e;
});

@@ -145,2 +147,6 @@ }

function detectTypeOfAnnotation(annotation) {
if (!annotation || !annotation.body) {
return 'UNKNOWN';
}
if (annotation.body && annotation.body.type === 'SpecificResource') {

@@ -181,2 +187,8 @@ return 'SPECIFIC_RESOURCE';

}
// Filter out empty bodied annotations.
var body = getAnnotationBody(annotation);
if (body === null) {
return null;
}
return {

@@ -183,0 +195,0 @@ id: annotation.id,

@@ -6,2 +6,3 @@ 'use strict';

exports.parseSelectorTarget = parseSelectorTarget;
exports.caseIdWithContext = caseIdWithContext;
exports.castId = castId;

@@ -13,2 +14,3 @@ exports.get = get;

exports.iteratorGenerator = iteratorGenerator;
exports.warning = warning;

@@ -19,4 +21,10 @@ var _vocab = require('./vocab');

function castBool(str) {
if (str === undefined) {
return false;
}
if (str === true) return true;
if (str === false) return false;
if (typeof str !== 'string') {
return false;
}
return str.toLowerCase() === 'true';

@@ -52,7 +60,25 @@ }

function castId(value, defaultValue) {
return (value[_vocab.ID] ? value[_vocab.ID] : value) || defaultValue;
function caseIdWithContext(value, context) {
var contexts = Object.keys(context).map(function (key) {
return { key: key, id: context[key] && context[key][_vocab.ID] ? context[key][_vocab.ID] : null };
});
var found = contexts.find(function (v) {
if (!v.id) {
return false;
}
return value.substr(0, v.id.length) === v.id;
});
if (!found) {
return value.replace('#', ':');
}
return found.key + ':' + value.substr(found.id.length + 1);
}
function get(value) {
function castId(value, defaultValue, context) {
var returnValue = (value[_vocab.ID] ? value[_vocab.ID] : value) || defaultValue || '';
return context ? caseIdWithContext(returnValue, context) : returnValue;
}
function get(value, context) {
return function (prop, defaultValue) {

@@ -120,2 +146,6 @@ return value ? value[prop] : defaultValue;

};
}
function warning(component, id, message) {
process.env.NODE_ENV !== 'production' && process.env.NODE_ENV !== 'test' && console.warn('WARNING: ' + component + '\n==================================================\nPlease check model at:\n' + id + '\n\n' + message + '\n');
}

@@ -26,3 +26,11 @@ 'use strict';

var $ = (0, _helpers.get)(jsonLd);
return new CaptureModel($(_vocab.ID), $(_vocab.TITLE), $(_vocab.DESCRIPTION), {
if ($(_vocab.HAS_PART) === undefined) {
(0, _helpers.warning)('CaptureModel', $(_vocab.ID), 'No fields found in this form, expected in field ' + _vocab.HAS_PART);
}
if ($(_vocab.TITLE) === undefined) {
(0, _helpers.warning)('CaptureModel', $(_vocab.ID), 'No title found in this form, expected in field ' + _vocab.TITLE);
}
return new CaptureModel($('@context'), $(_vocab.ID), $(_vocab.TITLE), $(_vocab.DESCRIPTION), {
combine: (0, _helpers.castBool)($(_vocab.COMBINE, true)),

@@ -34,7 +42,7 @@ externalise: (0, _helpers.castBool)($(_vocab.EXTERNALISE, true)),

// selectorValue: $(),
selector: $(_vocab.SELECTOR) ? (0, _helpers.castId)($(_vocab.SELECTOR)).toLowerCase() : null,
selector: $(_vocab.SELECTOR) ? (0, _helpers.castId)($(_vocab.SELECTOR), '', $('@context')).toLowerCase() : null,
motivatedBy: (0, _helpers.motivationFromForm)((0, _helpers.labelId)($(_vocab.MOTIVATED_BY))),
labelParts: (0, _helpers.labelId)($(_vocab.LABEL_PARTS))
}, asArray($(_vocab.HAS_PART)).map(function (field) {
return _Field2.default.fromJsonLD(field);
return _Field2.default.fromJsonLD(field, $('@context'));
}));

@@ -70,3 +78,3 @@ };

function CaptureModel(id, title, description, metaData, fields) {
function CaptureModel(context, id, title, description, metaData, fields) {
_classCallCheck(this, CaptureModel);

@@ -76,2 +84,3 @@

this.context = context;
this.id = id;

@@ -86,5 +95,14 @@ this.title = title;

var $ = (0, _helpers.get)(jsonLd);
if ($(_vocab.UI_GROUP) ? $(_vocab.UI_GROUP)[_vocab.ID] === 'madoc:form' : false) {
if ((0, _helpers.castId)($(_vocab.UI_GROUP), false, $('@context')) === 'madoc:form') {
if ((0, _helpers.castBool)($(_vocab.UI_CHOICE), false)) {
var firstChild = Array.isArray($(_vocab.HAS_PART)) ? $(_vocab.HAS_PART)[0] : $(_vocab.HAS_PART);
var firstChildIsField = !!firstChild['crowds:uiInputType'];
(0, _helpers.warning)('CaptureModel', $(_vocab.ID), 'we found the following conflicts:\n - This model is marked as a madoc:form\n - First child ' + (firstChildIsField ? 'IS' : 'IS NOT') + ' detected as a form field\n - The model is marked as a choice (crowds:uiChoice), which is incompatible with forms\n \nWe\'ve continued under the assumtion that this is a form. \nPlease update the model to get rid of this warning.\n');
}
return true;
}
// @todo remove temporary fix.
console.warn('CaptureModel:', 'please use JSON-LD fields so that @id is equal to the QName.');
return $(_vocab.UI_GROUP) ? $(_vocab.UI_GROUP)[_vocab.OMEKA_LABEL] === 'madoc:form' : false;

@@ -91,0 +109,0 @@ };

@@ -25,2 +25,11 @@ 'use strict';

var $ = (0, _helpers.get)(choice);
if ($(_vocab.UI_CHOICE) === undefined) {
(0, _helpers.warning)('Choice', $(_vocab.ID), 'There is not a choice field on this Choice/Form. Working under the assumtion that it is a FORM and not a choice.');
}
var firstChild = Array.isArray($(_vocab.HAS_PART)) ? $(_vocab.HAS_PART)[0] : $(_vocab.HAS_PART);
var firstChildIsField = !!firstChild['crowds:uiInputType'];
if ((0, _helpers.castBool)($(_vocab.UI_CHOICE), false) === true && Array.isArray($(_vocab.HAS_PART))) {}
return $(_vocab.UI_CHOICE) === 'True' && Array.isArray($(_vocab.HAS_PART));

@@ -27,0 +36,0 @@ };

@@ -26,3 +26,3 @@ 'use strict';

function Field(id, inputType, annotationMetaData, omekaMetaData, metaData) {
function Field(context, id, inputType, annotationMetaData, omekaMetaData, metaData) {
_classCallCheck(this, Field);

@@ -32,2 +32,3 @@

this.context = context;
this.id = id;

@@ -47,7 +48,9 @@ this.inputType = inputType;

Field.fromJsonLD = function fromJsonLD(jsonLd) {
Field.fromJsonLD = function fromJsonLD(jsonLd, inheritedContext) {
var _$;
var $ = (0, _helpers.get)(jsonLd);
return new Field($(_vocab.ID), $(_vocab.INPUT_TYPE, (_$ = {}, _$[_vocab.ID] = null, _$))[_vocab.ID], {
var $ = (0, _helpers.get)(jsonLd, inheritedContext);
var context = $('@context', inheritedContext);
return new Field(context, $(_vocab.ID), $(_vocab.INPUT_TYPE, (_$ = {}, _$[_vocab.ID] = null, _$))[_vocab.ID], {
options: $(_vocab.INPUT_OPTIONS),

@@ -54,0 +57,0 @@ autocomplete: Field.getAutocompleteEndpoint($(_vocab.INPUT_OPTIONS))

{
"name": "digirati-annotation-bridge",
"version": "0.8.11",
"version": "0.8.12",
"description": "Describe annotation-bridge here",

@@ -22,3 +22,3 @@ "main": "lib/index.js",

"dependencies": {
"digirati-annotation-redux": "^0.8.6",
"digirati-annotation-redux": "^0.8.12",
"lodash.flatten": "^4.4.0"

@@ -25,0 +25,0 @@ },

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc