From 6d4d5671deaa8c1db094a7c988076ea67e1f2b5b Mon Sep 17 00:00:00 2001 From: John Moore Date: Tue, 3 Sep 2024 13:56:38 +0100 Subject: [PATCH] anotation body can have feature --- package.json | 2 +- src/adapter.ts | 8 ++++++-- src/specification.atd | 7 ++++++- src/specification.ts | 39 +++++++++++++++++++++++++++++++++++++-- 4 files changed, 50 insertions(+), 6 deletions(-) diff --git a/package.json b/package.json index 05e89a5..5211063 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "maniiifest", - "version": "1.1.4", + "version": "1.1.5", "main": "dist/index.js", "types": "dist/index.d.ts", "files": [ diff --git a/src/adapter.ts b/src/adapter.ts index ec2fd61..a38f23f 100644 --- a/src/adapter.ts +++ b/src/adapter.ts @@ -72,8 +72,10 @@ export function normalize_annotation_body(x: T, c return fn(['T2', x], context); } else if (x.type === 'TextualBody') { return fn(['T3', x], context); + } else if (x.type === 'Feature') { + return fn(['T4', x], context); } else if (x.type === 'Choice') { - return fn(['T4', x], context) + return fn(['T5', x], context) } else { throw new Error(`${JSON.stringify(x)}: Input type did not match expected types.`); } @@ -93,7 +95,9 @@ export function normalize_annotation_body_items(x } else if (x.type === 'SpecificResource') { return fn(['T2', x], context); } else if (x.type === 'TextualBody') { - return fn(['T3', x], context); + return fn(['T3', x], context); + } else if (x.type === 'Feature') { + return fn(['T4', x], context); } else { throw new Error(`${JSON.stringify(x)}: Input type did not match expected types.`); } diff --git a/src/specification.atd b/src/specification.atd index 199d8d6..3c2407d 100644 --- a/src/specification.atd +++ b/src/specification.atd @@ -210,11 +210,12 @@ type annotation_body_items_t = [ | T1 of annotation_body_t1 | T2 of annotation_body_t2 | T3 of annotation_body_t3 + | T4 of annotation_body_t4 ] type annotation_body_t = [ inherit annotation_body_items_t - | T4 of annotation_body_t4 + | T5 of annotation_body_t5 ] type annotation_body_t1 = { @@ -233,6 +234,10 @@ type annotation_body_t3 = { } type annotation_body_t4 = { + inherit feature_t; +} + +type annotation_body_t5 = { ?_type : type_t option; items : annotation_body_items_t list; } diff --git a/src/specification.ts b/src/specification.ts index 9fbcc6e..42d118b 100644 --- a/src/specification.ts +++ b/src/specification.ts @@ -291,12 +291,14 @@ export type AnnotationBodyItemsT = | { kind: 'T1'; value: AnnotationBodyT1 } | { kind: 'T2'; value: AnnotationBodyT2 } | { kind: 'T3'; value: AnnotationBodyT3 } +| { kind: 'T4'; value: AnnotationBodyT4 } export type AnnotationBodyT = | { kind: 'T1'; value: AnnotationBodyT1 } | { kind: 'T2'; value: AnnotationBodyT2 } | { kind: 'T3'; value: AnnotationBodyT3 } | { kind: 'T4'; value: AnnotationBodyT4 } +| { kind: 'T5'; value: AnnotationBodyT5 } export type AnnotationBodyT1 = { id: IdT; @@ -331,6 +333,13 @@ export type AnnotationBodyT3 = { } export type AnnotationBodyT4 = { + id?: IdT; + type?: TypeT; + properties?: PropertiesT; + geometry?: GeometryT; +} + +export type AnnotationBodyT5 = { type?: TypeT; items: AnnotationBodyItemsT[]; } @@ -1358,6 +1367,8 @@ export function _writeAnnotationBodyItemsT(x: AnnotationBodyItemsT, context: any return ['T2', writeAnnotationBodyT2(x.value, x)] case 'T3': return ['T3', writeAnnotationBodyT3(x.value, x)] + case 'T4': + return ['T4', writeAnnotationBodyT4(x.value, x)] } } @@ -1370,6 +1381,8 @@ export function _readAnnotationBodyItemsT(x: any, context: any = x): AnnotationB return { kind: 'T2', value: readAnnotationBodyT2(x[1], x) } case 'T3': return { kind: 'T3', value: readAnnotationBodyT3(x[1], x) } + case 'T4': + return { kind: 'T4', value: readAnnotationBodyT4(x[1], x) } default: _atd_bad_json('AnnotationBodyItemsT', x, context) throw new Error('impossible') @@ -1386,6 +1399,8 @@ export function _writeAnnotationBodyT(x: AnnotationBodyT, context: any = x): any return ['T3', writeAnnotationBodyT3(x.value, x)] case 'T4': return ['T4', writeAnnotationBodyT4(x.value, x)] + case 'T5': + return ['T5', writeAnnotationBodyT5(x.value, x)] } } @@ -1400,6 +1415,8 @@ export function _readAnnotationBodyT(x: any, context: any = x): AnnotationBodyT return { kind: 'T3', value: readAnnotationBodyT3(x[1], x) } case 'T4': return { kind: 'T4', value: readAnnotationBodyT4(x[1], x) } + case 'T5': + return { kind: 'T5', value: readAnnotationBodyT5(x[1], x) } default: _atd_bad_json('AnnotationBodyT', x, context) throw new Error('impossible') @@ -1484,15 +1501,33 @@ export function readAnnotationBodyT3(x: any, context: any = x): AnnotationBodyT3 export function writeAnnotationBodyT4(x: AnnotationBodyT4, context: any = x): any { return { + 'id': _atd_write_optional_field(writeIdT, x.id, x), 'type': _atd_write_optional_field(writeTypeT, x.type, x), - 'items': _atd_write_required_field('AnnotationBodyT4', 'items', _atd_write_array(writeAnnotationBodyItemsT), x.items, x), + 'properties': _atd_write_optional_field(writePropertiesT, x.properties, x), + 'geometry': _atd_write_optional_field(writeGeometryT, x.geometry, x), }; } export function readAnnotationBodyT4(x: any, context: any = x): AnnotationBodyT4 { + return { + id: _atd_read_optional_field(readIdT, x['id'], x), + type: _atd_read_optional_field(readTypeT, x['type'], x), + properties: _atd_read_optional_field(readPropertiesT, x['properties'], x), + geometry: _atd_read_optional_field(readGeometryT, x['geometry'], x), + }; +} + +export function writeAnnotationBodyT5(x: AnnotationBodyT5, context: any = x): any { + return { + 'type': _atd_write_optional_field(writeTypeT, x.type, x), + 'items': _atd_write_required_field('AnnotationBodyT5', 'items', _atd_write_array(writeAnnotationBodyItemsT), x.items, x), + }; +} + +export function readAnnotationBodyT5(x: any, context: any = x): AnnotationBodyT5 { return { type: _atd_read_optional_field(readTypeT, x['type'], x), - items: _atd_read_required_field('AnnotationBodyT4', 'items', _atd_read_array(readAnnotationBodyItemsT), x['items'], x), + items: _atd_read_required_field('AnnotationBodyT5', 'items', _atd_read_array(readAnnotationBodyItemsT), x['items'], x), }; }