aiiinotate 0.3.0 → 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 +4 -3
- package/scripts/update_version.py +30 -0
- package/src/data/utils/iiif2Utils.js +30 -21
- package/src/schemas/schemasRoutes.js +4 -4
- package/test.json +77 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "aiiinotate",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.2",
|
|
4
4
|
"description": "a fast IIIF-compliant annotation server",
|
|
5
5
|
"main": "./cli/index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -16,7 +16,8 @@
|
|
|
16
16
|
"start": "sudo systemctl start mongod && npm run cli serve dev",
|
|
17
17
|
"test": "sudo systemctl start mongod && dotenvx run -f ./config/.env -- node --test --test-isolation=none",
|
|
18
18
|
"lint": "npx eslint --fix",
|
|
19
|
-
"migrate": "npm run cli -- migrate"
|
|
19
|
+
"migrate": "npm run cli -- migrate",
|
|
20
|
+
"update_version": "python3 scripts/update_version.py"
|
|
20
21
|
},
|
|
21
22
|
"pre-commit": [
|
|
22
23
|
"lint"
|
|
@@ -74,4 +75,4 @@
|
|
|
74
75
|
"globals": "^16.3.0",
|
|
75
76
|
"pre-commit": "^1.2.2"
|
|
76
77
|
}
|
|
77
|
-
}
|
|
78
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import re
|
|
2
|
+
import sys
|
|
3
|
+
import json
|
|
4
|
+
import shutil
|
|
5
|
+
import pathlib
|
|
6
|
+
|
|
7
|
+
curdir = pathlib.Path(__file__).parent.resolve()
|
|
8
|
+
pkg_file = curdir.parent.joinpath("package.json").resolve()
|
|
9
|
+
pkg_lock_file = curdir.parent.joinpath("package-lock.json").resolve()
|
|
10
|
+
|
|
11
|
+
usage = "\nupdate_version.py: CLI to update NPM version.\nUSAGE: \n\tpython3 update_version.py [VERSION]\n"
|
|
12
|
+
|
|
13
|
+
if len(sys.argv) != 2:
|
|
14
|
+
print(usage)
|
|
15
|
+
exit()
|
|
16
|
+
|
|
17
|
+
version = sys.argv[1]
|
|
18
|
+
if not re.search(r"^\d+\.\d+\.[^\s]+$", version):
|
|
19
|
+
print(r"argument VERSION must match '^\d+\.\d+\.[^\s]+$' (i.e. '0.2.1', '1.3.4fix'). exiting...")
|
|
20
|
+
exit()
|
|
21
|
+
|
|
22
|
+
for fp in [pkg_file, pkg_lock_file]:
|
|
23
|
+
shutil.copy2(fp, f"{fp}.bak")
|
|
24
|
+
with open(fp, mode="r") as fh:
|
|
25
|
+
data = json.load(fh)
|
|
26
|
+
data["version"] = version
|
|
27
|
+
with open(fp, mode="w") as fh:
|
|
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
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
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
|
-
|
|
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
|
-
|
|
143
|
-
canvasId = getCanvasShortId(
|
|
151
|
+
firstTarget = targetArray[0],
|
|
152
|
+
canvasId = getCanvasShortId(firstTarget);
|
|
144
153
|
// if manifestShortId hasn't aldready been extracted, re-extract it
|
|
145
|
-
manifestShortId = manifestShortId || getManifestShortId(
|
|
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})`)
|
|
@@ -47,10 +47,10 @@ function addSchemas(fastify, options, done) {
|
|
|
47
47
|
{ type: "object" },
|
|
48
48
|
{
|
|
49
49
|
type: "array",
|
|
50
|
-
items: [
|
|
50
|
+
items: { anyOf: [
|
|
51
51
|
{ type: "string" },
|
|
52
52
|
{ type: "object" }
|
|
53
|
-
],
|
|
53
|
+
]},
|
|
54
54
|
minItems: 1
|
|
55
55
|
}
|
|
56
56
|
]
|
|
@@ -75,10 +75,10 @@ function addSchemas(fastify, options, done) {
|
|
|
75
75
|
{ type: "object" },
|
|
76
76
|
{
|
|
77
77
|
type: "array",
|
|
78
|
-
items: [
|
|
78
|
+
items: { anyOf: [
|
|
79
79
|
{ type: "string" },
|
|
80
80
|
{ type: "object" }
|
|
81
|
-
],
|
|
81
|
+
]},
|
|
82
82
|
minItems: 1
|
|
83
83
|
}
|
|
84
84
|
]
|
package/test.json
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "aiiinotate",
|
|
3
|
+
"version": "0.0.0",
|
|
4
|
+
"description": "a fast IIIF-compliant annotation server",
|
|
5
|
+
"main": "./cli/index.js",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"directories": {
|
|
8
|
+
"doc": "docs"
|
|
9
|
+
},
|
|
10
|
+
"bin": {
|
|
11
|
+
"aiiinotate": "./cli/index.js"
|
|
12
|
+
},
|
|
13
|
+
"scripts": {
|
|
14
|
+
"cli": "node ./cli/index.js --env=./config/.env",
|
|
15
|
+
"setup": "sudo systemctl start mongod && npm run cli migrate apply",
|
|
16
|
+
"start": "sudo systemctl start mongod && npm run cli serve dev",
|
|
17
|
+
"test": "sudo systemctl start mongod && dotenvx run -f ./config/.env -- node --test --test-isolation=none",
|
|
18
|
+
"lint": "npx eslint --fix",
|
|
19
|
+
"migrate": "npm run cli -- migrate"
|
|
20
|
+
},
|
|
21
|
+
"pre-commit": [
|
|
22
|
+
"lint"
|
|
23
|
+
],
|
|
24
|
+
"repository": {
|
|
25
|
+
"type": "git",
|
|
26
|
+
"url": "git+https://github.com/Aikon-platform/aiiinotate.git"
|
|
27
|
+
},
|
|
28
|
+
"keywords": [
|
|
29
|
+
"annotation-server",
|
|
30
|
+
"iiif",
|
|
31
|
+
"annotation",
|
|
32
|
+
"international-image-interoperability-framework"
|
|
33
|
+
],
|
|
34
|
+
"author": "Aikon",
|
|
35
|
+
"license": "MIT",
|
|
36
|
+
"bugs": {
|
|
37
|
+
"url": "https://github.com/Aikon-platform/aiiinotate/issues"
|
|
38
|
+
},
|
|
39
|
+
"homepage": "https://github.com/Aikon-platform/aiiinotate#readme",
|
|
40
|
+
"imports": {
|
|
41
|
+
"#types": "./src/types.js",
|
|
42
|
+
"#cli/*.js": "./cli/*.js",
|
|
43
|
+
"#src/*.js": "./src/*.js",
|
|
44
|
+
"#migrations/*.js": "./migrations/*.js",
|
|
45
|
+
"#db/*.js": "./src/db/*.js",
|
|
46
|
+
"#schemas/*.js": "./src/schemas/*.js",
|
|
47
|
+
"#config/*.js": "./config/*.js",
|
|
48
|
+
"#data/*.js": "./src/data/*.js",
|
|
49
|
+
"#utils/*.js": "./src/data/utils/*.js",
|
|
50
|
+
"#fixtures/*.js": "./src/fixtures/*.js",
|
|
51
|
+
"#fixtures/*.json": "./src/fixtures/*.json",
|
|
52
|
+
"#manifests/*.js": "./src/data/manifests/*.js",
|
|
53
|
+
"#annotations/*.js": "./src/data/annotations/*.js"
|
|
54
|
+
},
|
|
55
|
+
"dependencies": {
|
|
56
|
+
"@dotenvx/dotenvx": "^1.49.0",
|
|
57
|
+
"@fastify/ajv-compiler": "^4.0.2",
|
|
58
|
+
"@fastify/cors": "^11.1.0",
|
|
59
|
+
"@fastify/mongodb": "^9.0.2",
|
|
60
|
+
"@fastify/swagger": "^9.5.2",
|
|
61
|
+
"commander": "^14.0.0",
|
|
62
|
+
"fastify": "^5.5.0",
|
|
63
|
+
"migrate-mongo": "^12.1.3",
|
|
64
|
+
"mongodb": "^6.18.0",
|
|
65
|
+
"swagger-markdown": "^3.0.0",
|
|
66
|
+
"uuid": "^11.1.0"
|
|
67
|
+
},
|
|
68
|
+
"devDependencies": {
|
|
69
|
+
"@eslint/css": "^0.10.0",
|
|
70
|
+
"@eslint/js": "^9.33.0",
|
|
71
|
+
"@eslint/json": "^0.13.1",
|
|
72
|
+
"@stylistic/eslint-plugin": "^5.2.3",
|
|
73
|
+
"eslint": "^9.33.0",
|
|
74
|
+
"globals": "^16.3.0",
|
|
75
|
+
"pre-commit": "^1.2.2"
|
|
76
|
+
}
|
|
77
|
+
}
|