ochre-sdk 1.3.25 → 1.3.27
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/dist/categories.d.mts +56 -56
- package/dist/categories.mjs +39 -39
- package/dist/constants.d.mts +8 -8
- package/dist/constants.mjs +6 -6
- package/dist/errors.d.mts +12 -12
- package/dist/errors.mjs +22 -23
- package/dist/fetchers/container-items.d.mts +28 -28
- package/dist/fetchers/container-items.mjs +27 -27
- package/dist/fetchers/gallery.d.mts +13 -13
- package/dist/fetchers/gallery.mjs +2 -2
- package/dist/fetchers/item-children.d.mts +12 -12
- package/dist/fetchers/item-children.mjs +2 -2
- package/dist/fetchers/item-links.d.mts +10 -10
- package/dist/fetchers/item-links.mjs +6 -6
- package/dist/fetchers/item-locations.d.mts +20 -20
- package/dist/fetchers/item-locations.mjs +3 -3
- package/dist/fetchers/item-ocr-data.d.mts +23 -23
- package/dist/fetchers/item-ocr-data.mjs +44 -44
- package/dist/fetchers/item.d.mts +23 -18
- package/dist/fetchers/item.mjs +15 -15
- package/dist/fetchers/map-layers.d.mts +15 -15
- package/dist/fetchers/map-layers.mjs +12 -11
- package/dist/fetchers/request.d.mts +40 -40
- package/dist/fetchers/request.mjs +37 -37
- package/dist/fetchers/set/items.d.mts +15 -15
- package/dist/fetchers/set/items.mjs +1 -1
- package/dist/fetchers/set/property-values.d.mts +16 -16
- package/dist/fetchers/set/property-values.mjs +43 -43
- package/dist/fetchers/tree/items.d.mts +27 -27
- package/dist/fetchers/tree/items.mjs +1 -1
- package/dist/fetchers/website-metadata.d.mts +4 -4
- package/dist/fetchers/website-metadata.mjs +9 -9
- package/dist/fetchers/website.d.mts +10 -10
- package/dist/fetchers/website.mjs +12 -12
- package/dist/getters.d.mts +83 -83
- package/dist/getters.mjs +74 -74
- package/dist/helpers.d.mts +4 -4
- package/dist/helpers.mjs +7 -7
- package/dist/index.d.mts +3 -3
- package/dist/index.mjs +5 -5
- package/dist/languages.d.mts +58 -58
- package/dist/languages.mjs +21 -21
- package/dist/ocr.d.mts +27 -27
- package/dist/ocr.mjs +29 -29
- package/dist/parsers/helpers.d.mts +23 -23
- package/dist/parsers/helpers.mjs +8 -8
- package/dist/parsers/index.d.mts +2 -2
- package/dist/parsers/index.mjs +15 -15
- package/dist/parsers/languages.d.mts +49 -49
- package/dist/parsers/languages.mjs +49 -49
- package/dist/parsers/multilingual.d.mts +174 -174
- package/dist/parsers/multilingual.mjs +146 -146
- package/dist/parsers/partial-date.d.mts +12 -12
- package/dist/parsers/partial-date.mjs +11 -11
- package/dist/parsers/property-token.d.mts +20 -20
- package/dist/parsers/property-token.mjs +16 -16
- package/dist/parsers/string.d.mts +33 -33
- package/dist/parsers/string.mjs +62 -64
- package/dist/parsers/website/bounds.d.mts +6 -6
- package/dist/parsers/website/bounds.mjs +5 -5
- package/dist/parsers/website/components.d.mts +46 -31
- package/dist/parsers/website/components.mjs +84 -51
- package/dist/parsers/website/index.d.mts +2 -2
- package/dist/parsers/website/index.mjs +45 -48
- package/dist/parsers/website/links.d.mts +24 -24
- package/dist/parsers/website/links.mjs +18 -18
- package/dist/parsers/website/messages.d.mts +16 -16
- package/dist/parsers/website/messages.mjs +14 -14
- package/dist/parsers/website/options.d.mts +1 -1
- package/dist/parsers/website/properties.d.mts +17 -8
- package/dist/parsers/website/properties.mjs +31 -10
- package/dist/parsers/website/reader.d.mts +55 -47
- package/dist/parsers/website/reader.mjs +66 -51
- package/dist/parsers/website/slug.d.mts +50 -50
- package/dist/parsers/website/slug.mjs +36 -36
- package/dist/parsers/website/styles.d.mts +18 -18
- package/dist/parsers/website/styles.mjs +19 -19
- package/dist/parsers/website/walk.d.mts +46 -46
- package/dist/parsers/website/walk.mjs +34 -34
- package/dist/query.d.mts +63 -63
- package/dist/query.mjs +137 -140
- package/dist/reflection.d.mts +51 -51
- package/dist/reflection.mjs +45 -45
- package/dist/schemas.d.mts +44 -44
- package/dist/schemas.mjs +50 -50
- package/dist/types/index.d.mts +192 -192
- package/dist/types/utilities.d.mts +5 -5
- package/dist/types/website.d.mts +74 -62
- package/dist/xml/dates.d.mts +9 -9
- package/dist/xml/dates.mjs +9 -9
- package/dist/xml/metadata.d.mts +14 -14
- package/dist/xml/metadata.mjs +18 -18
- package/dist/xml/schemas.mjs +24 -24
- package/dist/xml/types.d.mts +9 -9
- package/dist/xquery.d.mts +49 -49
- package/dist/xquery.mjs +50 -50
- package/package.json +10 -10
package/dist/xquery.d.mts
CHANGED
|
@@ -1,74 +1,74 @@
|
|
|
1
1
|
/**
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
2
|
+
Build a string literal for an XQuery string
|
|
3
|
+
@param value - The string value to escape
|
|
4
|
+
@returns The escaped string literal
|
|
5
|
+
@internal
|
|
6
|
+
*/
|
|
7
7
|
export declare function stringLiteral(value: string): string;
|
|
8
8
|
/**
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
9
|
+
A comment every query puts inside the `<ochre>` element it returns
|
|
10
|
+
|
|
11
|
+
The API answers a failed query with a bare `<result><ochre/></result>`, and
|
|
12
|
+
sends the same response whenever the returned `<ochre>` element holds fewer
|
|
13
|
+
than 25 characters. Padding keeps an empty or not-found result above that
|
|
14
|
+
cutoff, so the bare response only ever means failure. The XML parser drops
|
|
15
|
+
comments, so no schema sees it.
|
|
16
|
+
@internal
|
|
17
|
+
*/
|
|
18
18
|
export declare const OCHRE_RESPONSE_PADDING = "<!--ochre-sdk: keeps an empty result distinct from a failed query-->";
|
|
19
19
|
/**
|
|
20
|
-
|
|
21
|
-
|
|
20
|
+
Which language a query should return, and what to show where it is missing
|
|
21
|
+
*/
|
|
22
22
|
export type OchreContentLanguage = {
|
|
23
23
|
language: string;
|
|
24
24
|
fallbackLanguage: string;
|
|
25
25
|
};
|
|
26
26
|
/**
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
27
|
+
Resolve the content language a fetch asked for
|
|
28
|
+
@param options - The fetch options
|
|
29
|
+
@param options.language - The language to keep
|
|
30
|
+
@param options.fallbackLanguage - The language shown where `language` is missing
|
|
31
|
+
@returns The content language, or null to keep every language
|
|
32
|
+
@internal
|
|
33
|
+
*/
|
|
34
34
|
export declare function getContentLanguage(options?: {
|
|
35
35
|
language?: string;
|
|
36
36
|
fallbackLanguage?: string;
|
|
37
37
|
}): OchreContentLanguage | null;
|
|
38
38
|
/**
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
39
|
+
What a query body can ask the surrounding document for
|
|
40
|
+
|
|
41
|
+
Handed to the body rather than imported by it, so a body cannot reference a
|
|
42
|
+
prolog declaration the document did not emit.
|
|
43
|
+
*/
|
|
44
44
|
export type OchreQueryContext = {
|
|
45
45
|
/**
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
46
|
+
Wrap a node expression so supplemental nodes are omitted from it
|
|
47
|
+
@param expression - The XQuery expression returning the nodes to filter
|
|
48
|
+
@returns The wrapped XQuery expression
|
|
49
|
+
*/
|
|
50
50
|
omitSupplemental: (expression: string) => string;
|
|
51
51
|
/**
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
52
|
+
An XQuery predicate keeping only nodes that are neither supplemental
|
|
53
|
+
themselves nor nested inside a supplemental node. Use it when aggregating
|
|
54
|
+
over nodes instead of returning them.
|
|
55
|
+
*/
|
|
56
56
|
notSupplemental: string;
|
|
57
57
|
};
|
|
58
58
|
/**
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
59
|
+
Compile a complete XQuery document for the OCHRE API
|
|
60
|
+
|
|
61
|
+
Owns the version declaration, the prolog ordering, and the
|
|
62
|
+
supplemental-stripping helper. The body receives what it is allowed to call,
|
|
63
|
+
so the helper cannot be invoked without having been declared, and every
|
|
64
|
+
fetcher stops restating the same preamble.
|
|
65
|
+
@param parameters - The document parameters
|
|
66
|
+
@param parameters.declarations - Prolog declarations, emitted in order before the supplemental helper
|
|
67
|
+
@param parameters.body - Builds the query body
|
|
68
|
+
@param parameters.contentLanguage - Keep only this language of every multilingual field in the result
|
|
69
|
+
@returns A complete XQuery document
|
|
70
|
+
@internal
|
|
71
|
+
*/
|
|
72
72
|
export declare function compileOchreQuery(parameters: {
|
|
73
73
|
declarations?: ReadonlyArray<string>;
|
|
74
74
|
body: (context: OchreQueryContext) => string;
|
package/dist/xquery.mjs
CHANGED
|
@@ -1,36 +1,36 @@
|
|
|
1
1
|
import { DEFAULT_LANGUAGES } from "./constants.mjs";
|
|
2
2
|
// src/xquery.ts
|
|
3
3
|
/**
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
4
|
+
Build a string literal for an XQuery string
|
|
5
|
+
@param value - The string value to escape
|
|
6
|
+
@returns The escaped string literal
|
|
7
|
+
@internal
|
|
8
8
|
*/
|
|
9
9
|
function stringLiteral(value) {
|
|
10
10
|
return `"${value.replaceAll("\"", "\"\"")}"`;
|
|
11
11
|
}
|
|
12
12
|
/**
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
13
|
+
A comment every query puts inside the `<ochre>` element it returns
|
|
14
|
+
|
|
15
|
+
The API answers a failed query with a bare `<result><ochre/></result>`, and
|
|
16
|
+
sends the same response whenever the returned `<ochre>` element holds fewer
|
|
17
|
+
than 25 characters. Padding keeps an empty or not-found result above that
|
|
18
|
+
cutoff, so the bare response only ever means failure. The XML parser drops
|
|
19
|
+
comments, so no schema sees it.
|
|
20
|
+
@internal
|
|
21
21
|
*/
|
|
22
22
|
const OCHRE_RESPONSE_PADDING = "<!--ochre-sdk: keeps an empty result distinct from a failed query-->";
|
|
23
23
|
/**
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
24
|
+
XQuery prolog declaring `local:omit-supplemental`, which drops every element
|
|
25
|
+
carrying `supplemental="true"` from a node sequence, at any depth.
|
|
26
|
+
|
|
27
|
+
Subtrees without a supplemental descendant are returned by reference, so
|
|
28
|
+
nodes are only copied along the path leading to an omitted element. The
|
|
29
|
+
lookahead walks the attribute axis (`//@supplemental`) rather than testing
|
|
30
|
+
every element, which measures around three times faster on large documents.
|
|
31
|
+
|
|
32
|
+
Private on purpose: it is only correct when it precedes a body that calls it,
|
|
33
|
+
and {@link compileOchreQuery} is the only thing that can guarantee that.
|
|
34
34
|
*/
|
|
35
35
|
const SUPPLEMENTAL_XQUERY_PROLOG = `declare function local:omit-supplemental($nodes as node()*) as node()* {
|
|
36
36
|
for $node in $nodes
|
|
@@ -48,16 +48,16 @@ const SUPPLEMENTAL_XQUERY_PROLOG = `declare function local:omit-supplemental($no
|
|
|
48
48
|
else $node
|
|
49
49
|
};`;
|
|
50
50
|
/**
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
51
|
+
XQuery prolog declaring `local:select-language`, which keeps one language of
|
|
52
|
+
every multilingual field in a node sequence
|
|
53
|
+
|
|
54
|
+
A field's `content` children are reduced to the one in `$language`, else the
|
|
55
|
+
one in `$fallback`, else the first in any language, which is the choice the
|
|
56
|
+
API's own `lang` parameter makes. `zxx` content is always kept, since it holds
|
|
57
|
+
a field's aliases rather than a translation; the API's `lang` parameter drops
|
|
58
|
+
it, which is why the SDK selects languages itself. Leaf elements are
|
|
59
|
+
returned by reference; testing for multilingual descendants before copying a
|
|
60
|
+
subtree measured slower than copying it.
|
|
61
61
|
*/
|
|
62
62
|
const LANGUAGE_XQUERY_PROLOG = `declare function local:select-language($nodes as node()*, $language as xs:string, $fallback as xs:string) as node()* {
|
|
63
63
|
for $node in $nodes
|
|
@@ -90,12 +90,12 @@ const LANGUAGE_XQUERY_PROLOG = `declare function local:select-language($nodes as
|
|
|
90
90
|
default return $node
|
|
91
91
|
};`;
|
|
92
92
|
/**
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
93
|
+
Resolve the content language a fetch asked for
|
|
94
|
+
@param options - The fetch options
|
|
95
|
+
@param options.language - The language to keep
|
|
96
|
+
@param options.fallbackLanguage - The language shown where `language` is missing
|
|
97
|
+
@returns The content language, or null to keep every language
|
|
98
|
+
@internal
|
|
99
99
|
*/
|
|
100
100
|
function getContentLanguage(options) {
|
|
101
101
|
if (options?.language == null) return null;
|
|
@@ -106,18 +106,18 @@ function getContentLanguage(options) {
|
|
|
106
106
|
}
|
|
107
107
|
const NOT_SUPPLEMENTAL_PREDICATE = "[not(ancestor-or-self::*[@supplemental = \"true\"])]";
|
|
108
108
|
/**
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
109
|
+
Compile a complete XQuery document for the OCHRE API
|
|
110
|
+
|
|
111
|
+
Owns the version declaration, the prolog ordering, and the
|
|
112
|
+
supplemental-stripping helper. The body receives what it is allowed to call,
|
|
113
|
+
so the helper cannot be invoked without having been declared, and every
|
|
114
|
+
fetcher stops restating the same preamble.
|
|
115
|
+
@param parameters - The document parameters
|
|
116
|
+
@param parameters.declarations - Prolog declarations, emitted in order before the supplemental helper
|
|
117
|
+
@param parameters.body - Builds the query body
|
|
118
|
+
@param parameters.contentLanguage - Keep only this language of every multilingual field in the result
|
|
119
|
+
@returns A complete XQuery document
|
|
120
|
+
@internal
|
|
121
121
|
*/
|
|
122
122
|
function compileOchreQuery(parameters) {
|
|
123
123
|
const { declarations = [], body, contentLanguage } = parameters;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ochre-sdk",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.27",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"description": "Node.js library for working with OCHRE (Online Cultural and Historical Research Environment) data",
|
|
@@ -46,23 +46,23 @@
|
|
|
46
46
|
],
|
|
47
47
|
"dependencies": {
|
|
48
48
|
"@nodable/entities": "^3.1.0",
|
|
49
|
-
"fast-equals": "^6.2.
|
|
50
|
-
"fast-xml-parser": "^5.
|
|
49
|
+
"fast-equals": "^6.2.2",
|
|
50
|
+
"fast-xml-parser": "^5.12.0",
|
|
51
51
|
"valibot": "^1.5.0"
|
|
52
52
|
},
|
|
53
53
|
"devDependencies": {
|
|
54
|
-
"@antfu/eslint-config": "^
|
|
55
|
-
"@types/node": "^
|
|
54
|
+
"@antfu/eslint-config": "^10.0.0",
|
|
55
|
+
"@types/node": "^26.6.6",
|
|
56
56
|
"bumpp": "^12.3.0",
|
|
57
|
-
"eslint": "^10.
|
|
57
|
+
"eslint": "^10.14.0",
|
|
58
58
|
"eslint-plugin-erasable-syntax-only": "^0.7.2",
|
|
59
59
|
"eslint-plugin-slop": "^0.1.3",
|
|
60
60
|
"eslint-plugin-sonarjs": "^4.2.2",
|
|
61
|
-
"knip": "^6.
|
|
62
|
-
"oxfmt": "^0.
|
|
63
|
-
"tsdown": "^0.23.
|
|
61
|
+
"knip": "^6.45.1",
|
|
62
|
+
"oxfmt": "^0.78.0",
|
|
63
|
+
"tsdown": "^0.23.7",
|
|
64
64
|
"typescript": "^6.0.3",
|
|
65
|
-
"vitest": "^5.0
|
|
65
|
+
"vitest": "^5.1.0"
|
|
66
66
|
},
|
|
67
67
|
"scripts": {
|
|
68
68
|
"dev": "tsdown src/index.ts --watch",
|