maniiifest
Version:
Typesafe IIIF presentation v3 manifest and collection parsing without external dependencies
523 lines (522 loc) • 19.4 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.normalize_homepage_strings = exports.restore_homepage_strings = exports.normalize_email_sha1_strings = exports.restore_email_sha1_strings = exports.normalize_email_strings = exports.restore_email_strings = exports.normalize_creator_item = exports.restore_creator_item = exports.normalize_creator = exports.restore_creator = exports.normalize_part_of = exports.restore_part_of = exports.normalize_context = exports.restore_context = exports.normalize_language = exports.restore_language = exports.normalize_geometry = exports.restore_geometry = exports.normalize_range_items = exports.restore_range_items = exports.normalize_selector = exports.restore_selector = exports.normalize_label = exports.restore_label = exports.normalize_first = exports.restore_first = exports.normalize_target = exports.restore_target = exports.normalize_body = exports.restore_body = exports.normalize_source = exports.restore_source = exports.normalize_resource_selector = exports.restore_resource_selector = exports.normalize_annotation_target = exports.restore_annotation_target = exports.normalize_annotation_body_items = exports.restore_annotation_body_items = exports.normalize_annotation_body = exports.restore_annotation_body = exports.normalize_motivation = exports.restore_motivation = exports.normalize_service_item = exports.restore_service_item = exports.normalize_service = exports.restore_service = exports.normalize_specification = exports.restore_specification = void 0;
function restore_specification(x, context = x, fn) {
const resultList = fn(x, context);
if (resultList.length < 2) {
throw new Error(`${JSON.stringify(x)}: Result array must contain at least two items.`);
}
return resultList[1];
}
exports.restore_specification = restore_specification;
function normalize_specification(x, context = x, fn) {
if (x.type === 'Manifest') {
return fn(['Manifest', x], context);
}
else if (x.type === 'Collection') {
return fn(['Collection', x], context);
}
else {
throw new Error(`${JSON.stringify(x)}: Input type did not match expected types.`);
}
}
exports.normalize_specification = normalize_specification;
function restore_service(x, context = x, fn) {
const resultList = fn(x, context);
if (resultList.length < 2) {
throw new Error(`${JSON.stringify(x)}: Result array must contain at least two items.`);
}
return resultList[1];
}
exports.restore_service = restore_service;
function normalize_service(x, context = x, fn) {
if (Array.isArray(x)) {
return fn(['T2', x], context);
}
else {
return fn(['T1', x], context);
}
}
exports.normalize_service = normalize_service;
function restore_service_item(x, context = x, fn) {
const resultList = fn(x, context);
if (resultList.length < 2) {
throw new Error(`${JSON.stringify(x)}: Result array must contain at least two items.`);
}
return resultList[1];
}
exports.restore_service_item = restore_service_item;
function normalize_service_item(x, context = {}, fn) {
if (x !== null && typeof x === 'object') {
if ('id' in x) {
return fn(['T1', x], context);
}
else if ('@id' in x) {
return fn(['T2', x], context);
}
else {
throw new Error(`${JSON.stringify(x)}: Input type did not match expected types.`);
}
}
else {
throw new Error(`${JSON.stringify(x)}: Input type did not match expected types.`);
}
}
exports.normalize_service_item = normalize_service_item;
function restore_motivation(x, context = x, fn) {
const resultList = fn(x, context);
if (resultList.length < 2) {
throw new Error(`${JSON.stringify(x)}: Result array must contain at least two items.`);
}
return resultList[1];
}
exports.restore_motivation = restore_motivation;
function normalize_motivation(x, context = x, fn) {
if (typeof (x) === 'string') {
return fn(['T1', x], context);
}
else if (Array.isArray(x)) {
return fn(['T2', x], context);
}
else {
throw new Error(`${JSON.stringify(x)}: Input type did not match expected types.`);
}
}
exports.normalize_motivation = normalize_motivation;
function restore_annotation_body(x, context = x, fn) {
const resultList = fn(x, context);
if (resultList.length < 2) {
throw new Error(`${JSON.stringify(x)}: Result array must contain at least two items.`);
}
return resultList[1];
}
exports.restore_annotation_body = restore_annotation_body;
function normalize_annotation_body(x, context = x, fn) {
if (typeof x === 'string') {
return fn(['T1', x], context);
}
else if (typeof x === 'object' && x.type === 'Image' || x.type == 'Video' || x.type == 'Audio' || x.type == 'Sound' || x.type == 'Text') {
return fn(['T2', x], context);
}
else if (typeof x === 'object' && x.type === 'SpecificResource') {
return fn(['T3', x], context);
}
else if (typeof x === 'object' && x.type === 'TextualBody') {
return fn(['T4', x], context);
}
else if (typeof x === 'object' && x.type === 'Feature') {
return fn(['T5', x], context);
}
else if (typeof x === 'object' && x.type === 'FeatureCollection') {
return fn(['T6', x], context);
}
else if (typeof x === 'object' && x.type === 'Choice') {
return fn(['T7', x], context);
}
else if (typeof x === 'object') {
// handle special case where type is not defined within body object
return fn(['T0', x], context);
}
else {
throw new Error(`${JSON.stringify(x)}: Input type did not match expected types.`);
}
}
exports.normalize_annotation_body = normalize_annotation_body;
function restore_annotation_body_items(x, context = x, fn) {
const resultList = fn(x, context);
if (resultList.length < 2) {
throw new Error(`${JSON.stringify(x)}: Result array must contain at least two items.`);
}
return resultList[1];
}
exports.restore_annotation_body_items = restore_annotation_body_items;
function normalize_annotation_body_items(x, context = x, fn) {
if (typeof x === 'string') {
return fn(['T1', x], context);
}
else if (typeof x === 'object' && x.type === 'Image' || x.type == 'Video' || x.type == 'Audio' || x.type == 'Sound' || x.type == 'Text') {
return fn(['T2', x], context);
}
else if (typeof x === 'object' && x.type === 'SpecificResource') {
return fn(['T3', x], context);
}
else if (typeof x === 'object' && x.type === 'TextualBody') {
return fn(['T4', x], context);
}
else if (typeof x === 'object' && x.type === 'Feature') {
return fn(['T5', x], context);
}
else {
throw new Error(`${JSON.stringify(x)}: Input type did not match expected types.`);
}
}
exports.normalize_annotation_body_items = normalize_annotation_body_items;
function restore_annotation_target(x, context = x, fn) {
const resultList = fn(x, context);
if (resultList.length < 2) {
throw new Error(`${JSON.stringify(x)}: Result array must contain at least two items.`);
}
return resultList[1];
}
exports.restore_annotation_target = restore_annotation_target;
function normalize_annotation_target(x, context = x, fn) {
if (typeof (x) === 'string') {
return fn(['T1', x], context);
}
else if (('source' in x) && ('scope' in x)) {
return fn(['T2', x], context);
}
else if (('source' in x)) {
return fn(['T3', x], context);
}
else if (('id' in x)) {
return fn(['T4', x], context);
}
else {
throw new Error(`${JSON.stringify(x)}: Input type did not match expected types.`);
}
}
exports.normalize_annotation_target = normalize_annotation_target;
function restore_resource_selector(x, context = x, fn) {
const resultList = fn(x, context);
if (resultList.length < 2) {
throw new Error(`${JSON.stringify(x)}: Result array must contain at least two items.`);
}
return resultList[1];
}
exports.restore_resource_selector = restore_resource_selector;
function normalize_resource_selector(x, context = x, fn) {
if (typeof x === 'string') {
return fn(['T1', x], context);
}
else if (typeof x === 'object' && x.type === 'PointSelector') {
return fn(['T2', x], context);
}
else if (typeof x === 'object' && x.type === 'FragmentSelector') {
return fn(['T3', x], context);
}
else if (typeof x === 'object' && x.type === 'SvgSelector') {
return fn(['T4', x], context);
}
else if (typeof x === 'object' && x.type === 'ImageApiSelector' || x.type === 'iiif:ImageApiSelector') {
return fn(['T5', x], context);
}
else if (typeof x === 'object' && x.type === 'TextQuoteSelector') {
return fn(['T6', x], context);
}
else {
throw new Error(`${JSON.stringify(x)}: Input type did not match expected types.`);
}
}
exports.normalize_resource_selector = normalize_resource_selector;
function restore_source(x, context = x, fn) {
const resultList = fn(x, context);
if (resultList.length < 2) {
throw new Error(`${JSON.stringify(x)}: Result array must contain at least two items.`);
}
return resultList[1];
}
exports.restore_source = restore_source;
function normalize_source(x, context = x, fn) {
if (typeof (x) === 'string') {
return fn(['T1', x], context);
}
else if (typeof (x) === 'object') {
return fn(['T2', x], context);
}
else {
throw new Error(`${JSON.stringify(x)}: Input type did not match expected types.`);
}
}
exports.normalize_source = normalize_source;
function restore_body(x, context = x, fn) {
const resultList = fn(x, context);
if (resultList.length < 2) {
throw new Error(`${JSON.stringify(x)}: Result array must contain at least two items.`);
}
return resultList[1];
}
exports.restore_body = restore_body;
function normalize_body(x, context = x, fn) {
if (Array.isArray(x)) {
return fn(['T2', x], context);
}
else {
return fn(['T1', x], context);
}
}
exports.normalize_body = normalize_body;
function restore_target(x, context = x, fn) {
const resultList = fn(x, context);
if (resultList.length < 2) {
throw new Error(`${JSON.stringify(x)}: Result array must contain at least two items.`);
}
return resultList[1];
}
exports.restore_target = restore_target;
function normalize_target(x, context = x, fn) {
if (Array.isArray(x)) {
return fn(['T2', x], context);
}
else {
return fn(['T1', x], context);
}
}
exports.normalize_target = normalize_target;
function restore_first(x, context = x, fn) {
const resultList = fn(x, context);
if (resultList.length < 2) {
throw new Error(`${JSON.stringify(x)}: Result array must contain at least two items.`);
}
return resultList[1];
}
exports.restore_first = restore_first;
function normalize_first(x, context = x, fn) {
if (typeof (x) === 'string') {
return fn(['T1', x], context);
}
else if (typeof (x) === 'object') {
return fn(['T2', x], context);
}
else {
throw new Error(`${JSON.stringify(x)}: Input type did not match expected types.`);
}
}
exports.normalize_first = normalize_first;
function restore_label(x, context = x, fn) {
const resultList = fn(x, context);
if (resultList.length < 2) {
throw new Error(`${JSON.stringify(x)}: Result array must contain at least two items.`);
}
return resultList[1];
}
exports.restore_label = restore_label;
function normalize_label(x, context = x, fn) {
if (typeof (x) === 'string') {
return fn(['T1', x], context);
}
else if (typeof (x) === 'object') {
return fn(['T2', x], context);
}
else {
throw new Error(`${JSON.stringify(x)}: Input type did not match expected types.`);
}
}
exports.normalize_label = normalize_label;
function restore_selector(x, context = x, fn) {
const resultList = fn(x, context);
if (resultList.length < 2) {
throw new Error(`${JSON.stringify(x)}: Result array must contain at least two items.`);
}
return resultList[1];
}
exports.restore_selector = restore_selector;
function normalize_selector(x, context = x, fn) {
if (Array.isArray(x)) {
return fn(['T2', x], context);
}
else {
return fn(['T1', x], context);
}
}
exports.normalize_selector = normalize_selector;
function restore_range_items(x, context = x, fn) {
const resultList = fn(x, context);
if (resultList.length < 2) {
throw new Error(`${JSON.stringify(x)}: Result array must contain at least two items.`);
}
return resultList[1];
}
exports.restore_range_items = restore_range_items;
function normalize_range_items(x, context = x, fn) {
if (typeof x === 'object' && x.type === 'SpecificResource') {
return fn(['T1', x], context);
}
else if (typeof x === 'object' && x.type === 'Canvas') {
return fn(['T2', x], context);
}
else if (typeof x === 'object' && x.type === 'Range') {
return fn(['T3', x], context);
}
else {
throw new Error(`${JSON.stringify(x)}: Input type did not match expected types.`);
}
}
exports.normalize_range_items = normalize_range_items;
function restore_geometry(x, context = x, fn) {
const resultList = fn(x, context);
if (resultList.length < 2) {
throw new Error(`${JSON.stringify(x)}: Result array must contain at least two items.`);
}
return resultList[1];
}
exports.restore_geometry = restore_geometry;
function normalize_geometry(x, context = x, fn) {
if (typeof x === 'object' && x.type === 'Point') {
return fn(['T1', x], context);
}
else if (typeof x === 'object' && x.type === 'MultiPoint') {
return fn(['T2', x], context);
}
else if (typeof x === 'object' && x.type === 'LineString') {
return fn(['T3', x], context);
}
else if (typeof x === 'object' && x.type === 'MultiLineString') {
return fn(['T4', x], context);
}
else if (typeof x === 'object' && x.type === 'Polygon') {
return fn(['T5', x], context);
}
else if (typeof x === 'object' && x.type === 'MultiPolygon') {
return fn(['T6', x], context);
}
else if (typeof x === 'object' && x.type === 'GeometryCollection') {
return fn(['T7', x], context);
}
else {
throw new Error(`${JSON.stringify(x)}: Input type did not match expected types.`);
}
}
exports.normalize_geometry = normalize_geometry;
function restore_language(x, context = x, fn) {
const resultList = fn(x, context);
if (resultList.length < 2) {
throw new Error(`${JSON.stringify(x)}: Result array must contain at least two items.`);
}
return resultList[1];
}
exports.restore_language = restore_language;
function normalize_language(x, context = x, fn) {
if (Array.isArray(x)) {
return fn(['T2', x], context);
}
else {
return fn(['T1', x], context);
}
}
exports.normalize_language = normalize_language;
function restore_context(x, context = x, fn) {
const resultList = fn(x, context);
if (resultList.length < 2) {
throw new Error(`${JSON.stringify(x)}: Result array must contain at least two items.`);
}
return resultList[1];
}
exports.restore_context = restore_context;
function normalize_context(x, context = x, fn) {
if (Array.isArray(x)) {
return fn(['T2', x], context);
}
else {
return fn(['T1', x], context);
}
}
exports.normalize_context = normalize_context;
function restore_part_of(x, context = x, fn) {
const resultList = fn(x, context);
if (resultList.length < 2) {
throw new Error(`${JSON.stringify(x)}: Result array must contain at least two items.`);
}
return resultList[1];
}
exports.restore_part_of = restore_part_of;
function normalize_part_of(x, context = x, fn) {
if (typeof (x) === 'string') {
return fn(['T1', x], context);
}
else if (typeof (x) === 'object') {
return fn(['T2', x], context);
}
else {
throw new Error(`${JSON.stringify(x)}: Input type did not match expected types.`);
}
}
exports.normalize_part_of = normalize_part_of;
function restore_creator(x, context = x, fn) {
const resultList = fn(x, context);
if (resultList.length < 2) {
throw new Error(`${JSON.stringify(x)}: Result array must contain at least two items.`);
}
return resultList[1];
}
exports.restore_creator = restore_creator;
function normalize_creator(x, context = x, fn) {
if (Array.isArray(x)) {
return fn(['T2', x], context);
}
else {
return fn(['T1', x], context);
}
}
exports.normalize_creator = normalize_creator;
function restore_creator_item(x, context = x, fn) {
const resultList = fn(x, context);
if (resultList.length < 2) {
throw new Error(`${JSON.stringify(x)}: Result array must contain at least two items.`);
}
return resultList[1];
}
exports.restore_creator_item = restore_creator_item;
function normalize_creator_item(x, context = x, fn) {
if (typeof (x) === 'string') {
return fn(['T1', x], context);
}
else if (typeof (x) === 'object') {
return fn(['T2', x], context);
}
else {
throw new Error(`${JSON.stringify(x)}: Input type did not match expected types.`);
}
}
exports.normalize_creator_item = normalize_creator_item;
function restore_email_strings(x, context = x, fn) {
const resultList = fn(x, context);
if (resultList.length < 2) {
throw new Error(`${JSON.stringify(x)}: Result array must contain at least two items.`);
}
return resultList[1];
}
exports.restore_email_strings = restore_email_strings;
function normalize_email_strings(x, context = x, fn) {
if (Array.isArray(x)) {
return fn(['T2', x], context);
}
else {
return fn(['T1', x], context);
}
}
exports.normalize_email_strings = normalize_email_strings;
function restore_email_sha1_strings(x, context = x, fn) {
const resultList = fn(x, context);
if (resultList.length < 2) {
throw new Error(`${JSON.stringify(x)}: Result array must contain at least two items.`);
}
return resultList[1];
}
exports.restore_email_sha1_strings = restore_email_sha1_strings;
function normalize_email_sha1_strings(x, context = x, fn) {
if (Array.isArray(x)) {
return fn(['T2', x], context);
}
else {
return fn(['T1', x], context);
}
}
exports.normalize_email_sha1_strings = normalize_email_sha1_strings;
function restore_homepage_strings(x, context = x, fn) {
const resultList = fn(x, context);
if (resultList.length < 2) {
throw new Error(`${JSON.stringify(x)}: Result array must contain at least two items.`);
}
return resultList[1];
}
exports.restore_homepage_strings = restore_homepage_strings;
function normalize_homepage_strings(x, context = x, fn) {
if (Array.isArray(x)) {
return fn(['T2', x], context);
}
else {
return fn(['T1', x], context);
}
}
exports.normalize_homepage_strings = normalize_homepage_strings;