Skip to content

Commit

Permalink
anotation body can have feature
Browse files Browse the repository at this point in the history
  • Loading branch information
jptmoore committed Sep 3, 2024
1 parent e1fc649 commit 6d4d567
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 6 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "maniiifest",
"version": "1.1.4",
"version": "1.1.5",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"files": [
Expand Down
8 changes: 6 additions & 2 deletions src/adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,10 @@ export function normalize_annotation_body<T extends { type: string }, R>(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.`);
}
Expand All @@ -93,7 +95,9 @@ export function normalize_annotation_body_items<T extends { type: string }, R>(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.`);
}
Expand Down
7 changes: 6 additions & 1 deletion src/specification.atd
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand All @@ -233,6 +234,10 @@ type annotation_body_t3 = {
}

type annotation_body_t4 = {
inherit feature_t;
}

type annotation_body_t5 = {
?_type <json name="type"> : type_t option;
items : annotation_body_items_t list;
}
Expand Down
39 changes: 37 additions & 2 deletions src/specification.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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[];
}
Expand Down Expand Up @@ -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)]
}
}

Expand All @@ -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')
Expand All @@ -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)]
}
}

Expand All @@ -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')
Expand Down Expand Up @@ -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),
};
}

Expand Down

0 comments on commit 6d4d567

Please sign in to comment.