aiiinotate 0.3.1 → 0.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "aiiinotate",
3
- "version": "0.3.1",
3
+ "version": "0.3.2",
4
4
  "description": "a fast IIIF-compliant annotation server",
5
5
  "main": "./cli/index.js",
6
6
  "type": "module",
@@ -8,7 +8,7 @@ curdir = pathlib.Path(__file__).parent.resolve()
8
8
  pkg_file = curdir.parent.joinpath("package.json").resolve()
9
9
  pkg_lock_file = curdir.parent.joinpath("package-lock.json").resolve()
10
10
 
11
- usage = "\nupdate_version.py: cli to update NPM version.\nUSAGE: \n\tpython3 update_version.py [VERSION]\n"
11
+ usage = "\nupdate_version.py: CLI to update NPM version.\nUSAGE: \n\tpython3 update_version.py [VERSION]\n"
12
12
 
13
13
  if len(sys.argv) != 2:
14
14
  print(usage)
@@ -26,3 +26,5 @@ for fp in [pkg_file, pkg_lock_file]:
26
26
  data["version"] = version
27
27
  with open(fp, mode="w") as fh:
28
28
  json.dump(data, fh, indent=2)
29
+
30
+ print(f"\nUpdated NPM package to version: {version}.")
@@ -58,27 +58,31 @@ const getCanvasShortId = (canvasUri) =>
58
58
  * get the `on` of an annotation.
59
59
  * reimplemented from SAS: https://github.com/glenrobson/SimpleAnnotationServer/blob/dc7c8c6de9f4693c678643db2a996a49eebfcbb0/src/main/java/uk/org/llgc/annotation/store/AnnotationUtils.java#L147
60
60
  * @param {object} annotation
61
- * @returns {string}
61
+ * @returns {string[]}
62
62
  */
63
63
  const getAnnotationTarget = (annotation) => {
64
- const target = annotation.on; // either string or SpecificResource
65
- let targetOut;
66
-
67
- if ( typeof(target) === "string" ) {
68
- // remove the fragment if necesary to get the full Canvas Id
69
- const hashIdx = target.indexOf("#");
70
- targetOut = hashIdx === -1
71
- ? target
72
- : target.substring(0, hashIdx);
73
-
74
- } else {
75
- // it's a SpecificResource => get the full image's id.
76
- targetOut = target["full"];
77
- }
78
- if ( isNullish(targetOut) ) {
79
- throw new Error(`${getAnnotationTarget.name}: 'annotation.on' is not a valid IIIF 2.1 annotation target (with annotation=${target})`)
64
+ /** annotation.on is converted to an array of targets => extract the target for each item of the array */
65
+ const getSingleAnnotationTarget = (_target) => {
66
+ let _targetOut;
67
+
68
+ if ( typeof(_target) === "string" ) {
69
+ // remove the fragment if necesary to get the full Canvas Id
70
+ const hashIdx = _target.indexOf("#");
71
+ _targetOut = hashIdx === -1
72
+ ? _target
73
+ : _target.substring(0, hashIdx);
74
+
75
+ } else {
76
+ // it's a SpecificResource => get the full image's id.
77
+ _targetOut = _target["full"];
78
+ }
79
+ if ( isNullish(_targetOut) ) {
80
+ throw new Error(`${getAnnotationTarget.name}: 'annotation.on' is not a valid IIIF 2.1 annotation target (with annotation=${_target})`)
81
+ }
82
+ return _targetOut;
80
83
  }
81
- return targetOut;
84
+
85
+ return maybeToArray(annotation.on).map(getSingleAnnotationTarget);
82
86
  }
83
87
 
84
88
  /**
@@ -138,11 +142,16 @@ const makeTarget = (annotation) => {
138
142
  * NOTE this should never fail, but results will only be reliable if the `annotation.on` follows the IIIF 2.1 canvas URI scheme
139
143
  */
140
144
  const makeAnnotationId = (annotation, manifestShortId) => {
145
+ // we consider that all targets point to the same canvas and manifest => extract canvas and manifest info from the 1st target.
146
+ const targetArray = getAnnotationTarget(annotation);
147
+ if ( targetArray.length < 1 ) {
148
+ throw new Error(`${makeAnnotationId.name}: could not extract target from annotation`)
149
+ }
141
150
  const
142
- target = getAnnotationTarget(annotation),
143
- canvasId = getCanvasShortId(target);
151
+ firstTarget = targetArray[0],
152
+ canvasId = getCanvasShortId(firstTarget);
144
153
  // if manifestShortId hasn't aldready been extracted, re-extract it
145
- manifestShortId = manifestShortId || getManifestShortId(target);
154
+ manifestShortId = manifestShortId || getManifestShortId(firstTarget);
146
155
 
147
156
  if ( isNullish(manifestShortId) || isNullish(canvasId) ) {
148
157
  throw new Error(`${makeAnnotationId.name}: could not make an 'annotationId' (with manifestShortId=${manifestShortId}, annotation=${annotation})`)