ochre-sdk 1.3.24 → 1.3.26
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 +14 -14
- package/dist/fetchers/item.mjs +14 -14
- 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 +50 -31
- package/dist/parsers/website/components.mjs +79 -51
- package/dist/parsers/website/index.d.mts +1 -1
- package/dist/parsers/website/index.mjs +43 -47
- 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 +23 -11
- package/dist/parsers/website/reader.d.mts +55 -46
- package/dist/parsers/website/reader.mjs +64 -46
- 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 +67 -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
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { ContainedItemCategoryFromOption, ContainedItemCategoryOption, Item, ItemCategory, ItemCategoryFromOption, ItemCategoryOption, ItemContainerCategory, SetItemCategory, TreeItemCategory } from "../types/index.mjs";
|
|
2
1
|
import { FetchBaseOptions, FetchLanguages } from "../parsers/helpers.mjs";
|
|
2
|
+
import { ContainedItemCategoryFromOption, ContainedItemCategoryOption, Item, ItemCategory, ItemCategoryFromOption, ItemCategoryOption, ItemContainerCategory, SetItemCategory, TreeItemCategory } from "../types/index.mjs";
|
|
3
3
|
type FetchItemChildrenResult<TItems> = Promise<{
|
|
4
4
|
items: TItems;
|
|
5
5
|
error: null;
|
|
@@ -12,17 +12,17 @@ type FetchItemChildrenResult<TItems> = Promise<{
|
|
|
12
12
|
type ItemChildCategory<U extends ItemCategory> = U extends "tree" ? TreeItemCategory : U extends "set" ? SetItemCategory : U extends "bibliography" ? "bibliography" : U extends "concept" ? "concept" : U extends "spatialUnit" ? "spatialUnit" : U extends "period" ? "period" : U extends "resource" ? "resource" : never;
|
|
13
13
|
type ItemChildrenPayloadKind<U extends ItemCategory> = U extends "tree" | "set" ? "embedded" : "standaloneChild";
|
|
14
14
|
/**
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
15
|
+
Fetches direct child items for an OCHRE item UUID without fetching parent
|
|
16
|
+
item data.
|
|
17
|
+
|
|
18
|
+
@param uuid - The UUID of the OCHRE item whose children should be fetched
|
|
19
|
+
@param options - Fetch and parser options
|
|
20
|
+
@param options.category - Optional parent item category. Passing it lets the XQuery search only the matching OCHRE collection.
|
|
21
|
+
@param options.containedItemCategory - The category of items inside returned Trees/Sets to parse. Tree accepts one category; Set accepts one category or an array.
|
|
22
|
+
@param options.languages - Language codes to parse. Inline arrays preserve literal types automatically.
|
|
23
|
+
@param options.fetch - Custom fetch function to use instead of the default fetch
|
|
24
|
+
@returns An object containing parsed child items
|
|
25
|
+
*/
|
|
26
26
|
export declare function fetchItemChildren<const TContainedItemCategory extends ContainedItemCategoryOption<ItemContainerCategory> | undefined = undefined, const TLanguages extends ReadonlyArray<string> | undefined = undefined>(uuid: string, options?: FetchBaseOptions<TLanguages> & {
|
|
27
27
|
category?: undefined;
|
|
28
28
|
containedItemCategory?: TContainedItemCategory;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { OCHRE_COLLECTION_CATEGORIES } from "../categories.mjs";
|
|
2
2
|
import { getErrorOutput } from "../errors.mjs";
|
|
3
3
|
import { requestOchre } from "./request.mjs";
|
|
4
|
-
import { uuidSchema } from "../schemas.mjs";
|
|
5
|
-
import { parseRequestedLanguages, resolveContentLanguages } from "../parsers/languages.mjs";
|
|
6
4
|
import { parseLinkedItems } from "../parsers/index.mjs";
|
|
5
|
+
import { parseRequestedLanguages, resolveContentLanguages } from "../parsers/languages.mjs";
|
|
6
|
+
import { uuidSchema } from "../schemas.mjs";
|
|
7
7
|
import { XMLItemLinksData } from "../xml/schemas.mjs";
|
|
8
8
|
import { OCHRE_RESPONSE_PADDING, compileOchreQuery, getContentLanguage, stringLiteral } from "../xquery.mjs";
|
|
9
9
|
import * as v from "valibot";
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import { ContainedItemCategoryFromOption, ContainedItemCategoryOption, Item, ItemCategory, ItemContainerCategory } from "../types/index.mjs";
|
|
2
1
|
import { FetchBaseOptions, FetchLanguages } from "../parsers/helpers.mjs";
|
|
2
|
+
import { ContainedItemCategoryFromOption, ContainedItemCategoryOption, Item, ItemCategory, ItemContainerCategory } from "../types/index.mjs";
|
|
3
3
|
/**
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
4
|
+
Fetches linked OCHRE items by source-item UUID.
|
|
5
|
+
|
|
6
|
+
@param uuid - The UUID of the OCHRE item whose linked items should be fetched
|
|
7
|
+
@param options - Fetch and parser options
|
|
8
|
+
@param options.containedItemCategory - The category of items inside linked Trees/Sets to parse. Tree accepts one category; Set accepts one category or an array.
|
|
9
|
+
@param options.languages - Language codes to parse. Inline arrays preserve literal types automatically.
|
|
10
|
+
@param options.fetch - Custom fetch function to use instead of the default fetch
|
|
11
|
+
@returns An object containing parsed linked items
|
|
12
|
+
*/
|
|
13
13
|
export declare function fetchItemLinks<const TContainedItemCategory extends ContainedItemCategoryOption<ItemContainerCategory> | undefined = undefined, const TLanguages extends ReadonlyArray<string> | undefined = undefined>(uuid: string, options?: FetchBaseOptions<TLanguages> & {
|
|
14
14
|
containedItemCategory?: TContainedItemCategory;
|
|
15
15
|
}): Promise<{
|
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
import { ITEM_CATEGORY_ALIASES, OCHRE_COLLECTION_CATEGORIES } from "../categories.mjs";
|
|
2
2
|
import { getErrorOutput } from "../errors.mjs";
|
|
3
3
|
import { requestOchre } from "./request.mjs";
|
|
4
|
-
import { uuidSchema } from "../schemas.mjs";
|
|
5
|
-
import { parseRequestedLanguages, resolveContentLanguages } from "../parsers/languages.mjs";
|
|
6
4
|
import { parseLinkedItems } from "../parsers/index.mjs";
|
|
5
|
+
import { parseRequestedLanguages, resolveContentLanguages } from "../parsers/languages.mjs";
|
|
6
|
+
import { uuidSchema } from "../schemas.mjs";
|
|
7
7
|
import { XMLItemLinksData } from "../xml/schemas.mjs";
|
|
8
8
|
import { OCHRE_RESPONSE_PADDING, compileOchreQuery, getContentLanguage, stringLiteral } from "../xquery.mjs";
|
|
9
9
|
import * as v from "valibot";
|
|
10
10
|
// src/fetchers/item-links.ts
|
|
11
11
|
/**
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
12
|
+
Build an XQuery string to fetch linked items from the OCHRE API.
|
|
13
|
+
|
|
14
|
+
@param uuid - The UUID of the OCHRE item whose links should be fetched
|
|
15
|
+
@returns An XQuery string
|
|
16
16
|
*/
|
|
17
17
|
function buildXQuery(uuid, contentLanguage) {
|
|
18
18
|
const linkedItems = `for $link at $position in $link-nodes
|
|
@@ -1,25 +1,25 @@
|
|
|
1
|
-
import { ItemLocation, Query } from "../types/index.mjs";
|
|
2
1
|
import { FetchBaseOptions, FetchLanguages } from "../parsers/helpers.mjs";
|
|
2
|
+
import { ItemLocation, Query } from "../types/index.mjs";
|
|
3
3
|
/**
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
4
|
+
Fetches the location of every Set or Tree item that matches a query, without paging
|
|
5
|
+
|
|
6
|
+
Each item carries only its identification, the scope Sets and Trees it
|
|
7
|
+
belongs to, its publication date, its coordinates, optionally its map
|
|
8
|
+
polygons, and the values of the requested property variables (inherited
|
|
9
|
+
values included), which is what a map needs to draw, color and group every
|
|
10
|
+
match into layers while a list pages through the same query with
|
|
11
|
+
{@link fetchSetItems} or {@link fetchTreeItems}.
|
|
12
|
+
|
|
13
|
+
@param parameters - The parameters for the fetch
|
|
14
|
+
@param parameters.setScopeUuids - The Set scope UUIDs to search within
|
|
15
|
+
@param parameters.treeScopeUuids - The Tree scope UUIDs to search within
|
|
16
|
+
@param parameters.queries - Recursive query tree used to filter matching items
|
|
17
|
+
@param parameters.propertyVariableUuids - The property variables whose values each item should carry
|
|
18
|
+
@param parameters.isMapDataIncluded - Whether each item should carry its map polygons
|
|
19
|
+
@param options - Options for the fetch
|
|
20
|
+
@param options.fetch - The fetch function to use
|
|
21
|
+
@returns The item locations, or an error if the fetch/parse fails
|
|
22
|
+
*/
|
|
23
23
|
export declare function fetchItemLocations<const TLanguages extends ReadonlyArray<string> | undefined = undefined>(parameters: {
|
|
24
24
|
setScopeUuids?: Array<string>;
|
|
25
25
|
treeScopeUuids?: Array<string>;
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { normalizeItemCategory } from "../categories.mjs";
|
|
2
2
|
import { getErrorOutput } from "../errors.mjs";
|
|
3
3
|
import { requestOchre } from "./request.mjs";
|
|
4
|
-
import { itemLocationsParametersSchema } from "../schemas.mjs";
|
|
5
4
|
import { parseRequiredContentLike } from "../parsers/helpers.mjs";
|
|
6
|
-
import { parseRequestedLanguages, resolveContentLanguages } from "../parsers/languages.mjs";
|
|
7
5
|
import { parseCoordinates, parseIdentification, parseSpatialUnitMapData } from "../parsers/index.mjs";
|
|
6
|
+
import { parseRequestedLanguages, resolveContentLanguages } from "../parsers/languages.mjs";
|
|
7
|
+
import { compileContainerItemsQuery } from "../query.mjs";
|
|
8
|
+
import { itemLocationsParametersSchema } from "../schemas.mjs";
|
|
8
9
|
import { XMLItemLocationsData } from "../xml/schemas.mjs";
|
|
9
10
|
import { getContentLanguage, stringLiteral } from "../xquery.mjs";
|
|
10
|
-
import { compileContainerItemsQuery } from "../query.mjs";
|
|
11
11
|
import * as v from "valibot";
|
|
12
12
|
// src/fetchers/item-locations.ts
|
|
13
13
|
async function fetchItemLocations(parameters, options) {
|
|
@@ -1,28 +1,28 @@
|
|
|
1
|
-
import { OcrString } from "../types/index.mjs";
|
|
2
1
|
import { OchreRequestOptions } from "./request.mjs";
|
|
2
|
+
import { OcrString } from "../types/index.mjs";
|
|
3
3
|
/**
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
4
|
+
Fetches and parses the OCR strings of an OCHRE item that match a search value
|
|
5
|
+
|
|
6
|
+
Resources may carry an `<ocr>` layer whose internal hierarchy is irregular
|
|
7
|
+
and therefore not parsed. Only its word nodes are returned, wherever they
|
|
8
|
+
occur in that subtree, in document order. A word node is any element whose
|
|
9
|
+
name is `string` in any casing and any namespace, and matching reads its
|
|
10
|
+
`CONTENT` attribute rather than its text content.
|
|
11
|
+
|
|
12
|
+
Each word node holds a single OCR word, so a multi-word search value is split
|
|
13
|
+
on whitespace and a node is returned when it matches any one term. Nested
|
|
14
|
+
child Resources are searched too, with `resourceUuid` naming the Resource
|
|
15
|
+
each match belongs to.
|
|
16
|
+
|
|
17
|
+
@param uuid - The UUID of the OCHRE item to read the OCR layer of
|
|
18
|
+
@param value - The search value to match against each OCR string's content
|
|
19
|
+
@param options - Options for the fetch
|
|
20
|
+
@param options.matchMode - Whether a term has to be contained in a string's content ("includes", the default) or equal it ("exact")
|
|
21
|
+
@param options.isCaseSensitive - Whether matching is case sensitive, defaulting to false
|
|
22
|
+
@param options.fetch - The fetch function to use
|
|
23
|
+
@returns The matching OCR strings, an empty array when the item has no OCR
|
|
24
|
+
layer or nothing matches, and a null output on fetch/parse errors
|
|
25
|
+
*/
|
|
26
26
|
export declare function fetchItemOcrData(uuid: string, value: string, options?: OchreRequestOptions & {
|
|
27
27
|
matchMode?: "includes" | "exact";
|
|
28
28
|
isCaseSensitive?: boolean;
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { getErrorOutput } from "../errors.mjs";
|
|
2
2
|
import { requestOchre } from "./request.mjs";
|
|
3
|
+
import { buildOcrWordPath } from "../ocr.mjs";
|
|
3
4
|
import { itemOcrDataParametersSchema } from "../schemas.mjs";
|
|
4
5
|
import { OCHRE_RESPONSE_PADDING, stringLiteral } from "../xquery.mjs";
|
|
5
|
-
import { buildOcrWordPath } from "../ocr.mjs";
|
|
6
6
|
import * as v from "valibot";
|
|
7
7
|
// src/fetchers/item-ocr-data.ts
|
|
8
8
|
const OCR_STRING_VERTEX_REGEX = /\(\s*(-?\d+(?:\.\d+)?)\s*,\s*(-?\d+(?:\.\d+)?)\s*\)/g;
|
|
9
9
|
/**
|
|
10
|
-
|
|
10
|
+
Schema for a single matched OCR string in the OCHRE API response
|
|
11
11
|
*/
|
|
12
12
|
const ocrStringSchema = v.object({
|
|
13
13
|
resourceUuid: v.optional(v.string(), ""),
|
|
@@ -19,7 +19,7 @@ const ocrStringSchema = v.object({
|
|
|
19
19
|
vertices: v.optional(v.string(), "")
|
|
20
20
|
});
|
|
21
21
|
/**
|
|
22
|
-
|
|
22
|
+
Schema for the item OCR data OCHRE API response
|
|
23
23
|
*/
|
|
24
24
|
const responseSchema = v.object({ result: v.object({ ochre: v.object({ ocrStrings: v.object({
|
|
25
25
|
found: v.optional(v.string(), "false"),
|
|
@@ -50,26 +50,26 @@ function parseOcrStringVertices(value) {
|
|
|
50
50
|
return vertices;
|
|
51
51
|
}
|
|
52
52
|
/**
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
53
|
+
Build an XQuery string to fetch matching OCR strings from the OCHRE API
|
|
54
|
+
|
|
55
|
+
The `<ocr>` layer is marked supplemental, so it is deliberately read without
|
|
56
|
+
the supplemental stripping the other fetchers apply. Word nodes are projected
|
|
57
|
+
at any depth, because OCHRE does not guarantee the shape of the surrounding
|
|
58
|
+
hierarchy.
|
|
59
|
+
|
|
60
|
+
Both the container and the word nodes are matched on a case-folded
|
|
61
|
+
`local-name()` rather than a name test, because OCHRE varies the casing of
|
|
62
|
+
these elements and may serve them in a namespace. A plain `//ocr//string`
|
|
63
|
+
name test silently matches nothing in either of those cases.
|
|
64
|
+
|
|
65
|
+
The matches are wrapped in an `<ocrStrings>` element carrying a `found`
|
|
66
|
+
flag, which tells "no such item" apart from "no matches".
|
|
67
|
+
@param parameters - The parameters for the fetch
|
|
68
|
+
@param parameters.uuid - The UUID of the OCHRE item to read the OCR layer of
|
|
69
|
+
@param parameters.terms - The whitespace-separated search terms to match against, already lowercased for case-insensitive matching
|
|
70
|
+
@param parameters.matchMode - Whether a term has to be contained in a string's content or equal it
|
|
71
|
+
@param parameters.isCaseSensitive - Whether matching is case sensitive
|
|
72
|
+
@returns An XQuery string
|
|
73
73
|
*/
|
|
74
74
|
function buildXQuery(parameters) {
|
|
75
75
|
const { uuid, terms, matchMode, isCaseSensitive } = parameters;
|
|
@@ -96,27 +96,27 @@ let $ocrStrings :=
|
|
|
96
96
|
return <ochre>${OCHRE_RESPONSE_PADDING}<ocrStrings found="{exists($ochre)}">{$ocrStrings}</ocrStrings></ochre>`;
|
|
97
97
|
}
|
|
98
98
|
/**
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
99
|
+
Fetches and parses the OCR strings of an OCHRE item that match a search value
|
|
100
|
+
|
|
101
|
+
Resources may carry an `<ocr>` layer whose internal hierarchy is irregular
|
|
102
|
+
and therefore not parsed. Only its word nodes are returned, wherever they
|
|
103
|
+
occur in that subtree, in document order. A word node is any element whose
|
|
104
|
+
name is `string` in any casing and any namespace, and matching reads its
|
|
105
|
+
`CONTENT` attribute rather than its text content.
|
|
106
|
+
|
|
107
|
+
Each word node holds a single OCR word, so a multi-word search value is split
|
|
108
|
+
on whitespace and a node is returned when it matches any one term. Nested
|
|
109
|
+
child Resources are searched too, with `resourceUuid` naming the Resource
|
|
110
|
+
each match belongs to.
|
|
111
|
+
|
|
112
|
+
@param uuid - The UUID of the OCHRE item to read the OCR layer of
|
|
113
|
+
@param value - The search value to match against each OCR string's content
|
|
114
|
+
@param options - Options for the fetch
|
|
115
|
+
@param options.matchMode - Whether a term has to be contained in a string's content ("includes", the default) or equal it ("exact")
|
|
116
|
+
@param options.isCaseSensitive - Whether matching is case sensitive, defaulting to false
|
|
117
|
+
@param options.fetch - The fetch function to use
|
|
118
|
+
@returns The matching OCR strings, an empty array when the item has no OCR
|
|
119
|
+
layer or nothing matches, and a null output on fetch/parse errors
|
|
120
120
|
*/
|
|
121
121
|
async function fetchItemOcrData(uuid, value, options) {
|
|
122
122
|
try {
|
package/dist/fetchers/item.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { ContainedItemCategoryFromOption, ContainedItemCategoryOption, Item, ItemCategory, ItemCategoryFromOption, ItemCategoryOption, ItemCategoryWithEmbeddedItems, ItemContainerCategory, ItemWithoutEmbeddedItems } from "../types/index.mjs";
|
|
2
1
|
import { FetchBaseOptions, FetchLanguages } from "../parsers/helpers.mjs";
|
|
2
|
+
import { ContainedItemCategoryFromOption, ContainedItemCategoryOption, Item, ItemCategory, ItemCategoryFromOption, ItemCategoryOption, ItemCategoryWithEmbeddedItems, ItemContainerCategory, ItemWithoutEmbeddedItems } from "../types/index.mjs";
|
|
3
3
|
type FetchItemResult<TItem> = Promise<{
|
|
4
4
|
item: TItem;
|
|
5
5
|
error: null;
|
|
@@ -10,19 +10,19 @@ type FetchItemResult<TItem> = Promise<{
|
|
|
10
10
|
detailedError: string;
|
|
11
11
|
}>;
|
|
12
12
|
/**
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
13
|
+
Fetches an OCHRE item by UUID from the OCHRE API
|
|
14
|
+
|
|
15
|
+
@param uuid - The UUID of the OCHRE item to fetch
|
|
16
|
+
@param options - Required options object
|
|
17
|
+
@param options.category - The category of the OCHRE item to fetch. Pass a
|
|
18
|
+
single category when it is known, or an array when the item may be any
|
|
19
|
+
category in that list.
|
|
20
|
+
@param options.containedItemCategory - The category of items inside the OCHRE item to fetch. Only valid for Trees and Sets. Tree accepts one category; Set accepts one category or an array.
|
|
21
|
+
@param options.shouldOmitEmbeddedItems - Whether to omit the embedded item hierarchy when fetching a recursive item category. Ignored when the fetched item does not expose recursive embedded items.
|
|
22
|
+
@param options.languages - Language codes to parse. Inline arrays preserve literal types automatically.
|
|
23
|
+
@param options.fetch - Custom fetch function to use instead of the default fetch
|
|
24
|
+
@returns An object containing the parsed item
|
|
25
|
+
*/
|
|
26
26
|
export declare function fetchItem<const TContainedItemCategory extends ContainedItemCategoryOption<ItemContainerCategory> | undefined = undefined, const TLanguages extends ReadonlyArray<string> | undefined = undefined>(uuid: string, options?: FetchBaseOptions<TLanguages> & {
|
|
27
27
|
category?: undefined;
|
|
28
28
|
containedItemCategory?: TContainedItemCategory;
|
package/dist/fetchers/item.mjs
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { ITEM_CATEGORIES_WITH_EMBEDDED_ITEMS, ITEM_CONTAINER_CATEGORIES, isItemCategoryWithEmbeddedItems, isItemContainerCategory } from "../categories.mjs";
|
|
2
2
|
import { getErrorOutput } from "../errors.mjs";
|
|
3
3
|
import { requestOchre } from "./request.mjs";
|
|
4
|
-
import { uuidSchema } from "../schemas.mjs";
|
|
5
|
-
import { parseRequestedLanguages } from "../parsers/languages.mjs";
|
|
6
4
|
import { parseItem } from "../parsers/index.mjs";
|
|
5
|
+
import { parseRequestedLanguages } from "../parsers/languages.mjs";
|
|
6
|
+
import { parseWebpageView } from "../parsers/website/index.mjs";
|
|
7
|
+
import { uuidSchema } from "../schemas.mjs";
|
|
7
8
|
import { XMLData } from "../xml/schemas.mjs";
|
|
8
9
|
import { OCHRE_RESPONSE_PADDING, compileOchreQuery, getContentLanguage, stringLiteral } from "../xquery.mjs";
|
|
9
|
-
import { parseWebpageView } from "../parsers/website/index.mjs";
|
|
10
10
|
import * as v from "valibot";
|
|
11
11
|
// src/fetchers/item.ts
|
|
12
12
|
function isItemWithEmbeddedItems(item) {
|
|
@@ -19,17 +19,17 @@ function assertItemCategoryAllowed(category, containedItemCategory) {
|
|
|
19
19
|
throw new Error(`containedItemCategory can only be used when category is "tree" or "set"; received category "${categories.join(", ")}"`);
|
|
20
20
|
}
|
|
21
21
|
/**
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
22
|
+
Build an XQuery string to fetch a single OCHRE item document by UUID.
|
|
23
|
+
|
|
24
|
+
Nodes marked `supplemental="true"` are always dropped. `$item` only ever
|
|
25
|
+
binds the item categories that carry embedded items, so the omission branch
|
|
26
|
+
is a no-op for every other category.
|
|
27
|
+
|
|
28
|
+
@param parameters - The parameters for the fetch
|
|
29
|
+
@param parameters.uuid - The UUID of the OCHRE item to fetch
|
|
30
|
+
@param parameters.shouldOmitEmbeddedItems - Whether to drop the embedded item hierarchy
|
|
31
|
+
@param parameters.contentLanguage - Keep only this language of every multilingual field
|
|
32
|
+
@returns An XQuery string
|
|
33
33
|
*/
|
|
34
34
|
function buildXQuery(parameters) {
|
|
35
35
|
const { uuid, shouldOmitEmbeddedItems, contentLanguage } = parameters;
|
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
import { MapLayer } from "../types/index.mjs";
|
|
2
1
|
import { FetchBaseOptions, FetchLanguages } from "../parsers/helpers.mjs";
|
|
2
|
+
import { MapLayer } from "../types/index.mjs";
|
|
3
3
|
/**
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
4
|
+
Fetches the layers a map draws from the Sets and Trees it links to
|
|
5
|
+
|
|
6
|
+
A linked Set holding only Sets, Trees and Resources is a layer list: each
|
|
7
|
+
linked Set or Tree becomes an OCHRE layer and each webpage Resource whose
|
|
8
|
+
href points at a geospatial web service becomes a service layer. Any other
|
|
9
|
+
linked Set or Tree is drawn as one OCHRE layer itself. The variant is
|
|
10
|
+
`"arcgis"` when any service layer is present, else `"maplibre-gl"`.
|
|
11
|
+
|
|
12
|
+
@param uuids - The UUIDs of the Sets and Trees the map links to, in order
|
|
13
|
+
@param options - Options for the fetch
|
|
14
|
+
@param options.languages - Language codes to parse
|
|
15
|
+
@param options.fetch - The fetch function to use
|
|
16
|
+
@returns The map variant and layers, or an error if the fetch/parse fails
|
|
17
|
+
*/
|
|
18
18
|
export declare function fetchMapLayers<const TLanguages extends ReadonlyArray<string> | undefined = undefined>(uuids: Array<string>, options?: FetchBaseOptions<TLanguages>): Promise<{
|
|
19
19
|
variant: "maplibre-gl" | "arcgis";
|
|
20
20
|
layers: Array<MapLayer<FetchLanguages<TLanguages>>>;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { getErrorOutput } from "../errors.mjs";
|
|
2
2
|
import { requestOchre } from "./request.mjs";
|
|
3
|
-
import { uuidSchema } from "../schemas.mjs";
|
|
4
|
-
import { parseRequestedLanguages, resolveContentLanguages } from "../parsers/languages.mjs";
|
|
5
3
|
import { parseIdentification } from "../parsers/index.mjs";
|
|
4
|
+
import { parseRequestedLanguages, resolveContentLanguages } from "../parsers/languages.mjs";
|
|
5
|
+
import { uuidSchema } from "../schemas.mjs";
|
|
6
6
|
import { XMLMapSourcesData } from "../xml/schemas.mjs";
|
|
7
7
|
import { OCHRE_RESPONSE_PADDING, compileOchreQuery, getContentLanguage, stringLiteral } from "../xquery.mjs";
|
|
8
8
|
import * as v from "valibot";
|
|
@@ -21,9 +21,9 @@ const REGEX_IMAGE_SERVER = /\/ImageServer\/?$/i;
|
|
|
21
21
|
const REGEX_TRAILING_SLASH = /\/$/;
|
|
22
22
|
const REGEX_ARCGIS_SOAP_SERVICES = /\/arcgis\/services\//i;
|
|
23
23
|
/**
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
24
|
+
Classify the href of a webpage Resource as a geospatial web service
|
|
25
|
+
@param href - The Resource href
|
|
26
|
+
@returns The service layer, or null when the href names no supported service
|
|
27
27
|
*/
|
|
28
28
|
function parseServiceLayer(href) {
|
|
29
29
|
const trimmedHref = href.trim();
|
|
@@ -70,10 +70,10 @@ function parseServiceLayer(href) {
|
|
|
70
70
|
return null;
|
|
71
71
|
}
|
|
72
72
|
/**
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
73
|
+
Build the layer a Set, Tree or Resource of a map's layer list stands for
|
|
74
|
+
@param member - The linked Set, Tree or Resource
|
|
75
|
+
@param languages - The languages to parse
|
|
76
|
+
@returns The layer, or null when a Resource names no supported service
|
|
77
77
|
*/
|
|
78
78
|
function parseMapLayer(member, languages) {
|
|
79
79
|
const { label } = parseIdentification(member.identification, { languages });
|
|
@@ -137,8 +137,9 @@ async function fetchMapLayers(uuids, options) {
|
|
|
137
137
|
const layer = parseMapLayer(member, languages);
|
|
138
138
|
if (layer != null) sourceLayers.push(layer);
|
|
139
139
|
}
|
|
140
|
-
const mapServerUrls = sourceLayers.
|
|
141
|
-
for (const layer of sourceLayers)
|
|
140
|
+
const mapServerUrls = sourceLayers.map((layer) => layer.type === "arcgis-map" ? `${layer.url}/` : null).filter((url) => url != null);
|
|
141
|
+
for (const layer of sourceLayers) {
|
|
142
|
+
if (layer.type === "wmts" && mapServerUrls.some((url) => layer.url.startsWith(url)) || layerUuids.has(layer.uuid)) continue;
|
|
142
143
|
layerUuids.add(layer.uuid);
|
|
143
144
|
layers.push(layer);
|
|
144
145
|
}
|
|
@@ -6,23 +6,23 @@ export type OchreRequestOptions = {
|
|
|
6
6
|
timeoutMilliseconds?: number;
|
|
7
7
|
};
|
|
8
8
|
/**
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
9
|
+
Turn an OCHRE XML response into validated data
|
|
10
|
+
|
|
11
|
+
The XML parser, the schema check and the metadata graft are one step: the
|
|
12
|
+
graft has to follow validation because `v.safeParse` drops the
|
|
13
|
+
non-enumerable source offsets `fast-xml-parser` records, and skipping it
|
|
14
|
+
leaves a value that is the right shape but has lost its source order. Kept
|
|
15
|
+
separate from the request so a caller holding an XML string, such as a test,
|
|
16
|
+
gets exactly what the network path produces.
|
|
17
|
+
@param parameters - The decode parameters
|
|
18
|
+
@param parameters.xml - The raw XML response body
|
|
19
|
+
@param parameters.schema - The schema the response must satisfy
|
|
20
|
+
@param parameters.label - What is being decoded, used in failure messages
|
|
21
|
+
@param parameters.checkRawData - Guard run against the parsed XML before validation
|
|
22
|
+
@returns The validated response, with XML source metadata restored
|
|
23
|
+
@throws When the query failed on the server, the guard rejects, or validation fails
|
|
24
|
+
@internal
|
|
25
|
+
*/
|
|
26
26
|
export declare function decodeOchreResponse<TOutput>(parameters: {
|
|
27
27
|
xml: string;
|
|
28
28
|
schema: v.GenericSchema<unknown, TOutput>;
|
|
@@ -30,20 +30,20 @@ export declare function decodeOchreResponse<TOutput>(parameters: {
|
|
|
30
30
|
checkRawData?: (data: unknown) => void;
|
|
31
31
|
}): TOutput;
|
|
32
32
|
/**
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
33
|
+
Post an XQuery to the OCHRE API and validate the response
|
|
34
|
+
|
|
35
|
+
Owns every fact about talking to OCHRE: the endpoint, the request shape and
|
|
36
|
+
the failure policy. Decoding the body is {@link decodeOchreResponse}.
|
|
37
|
+
@param parameters - The request parameters
|
|
38
|
+
@param parameters.xquery - The XQuery to post
|
|
39
|
+
@param parameters.schema - The schema the response must satisfy
|
|
40
|
+
@param parameters.label - What is being fetched, used in failure messages
|
|
41
|
+
@param parameters.options - Transport options
|
|
42
|
+
@param parameters.checkRawData - Guard run against the parsed XML before validation
|
|
43
|
+
@returns The validated response, with XML source metadata restored
|
|
44
|
+
@throws When the request fails, the guard rejects, or validation fails
|
|
45
|
+
@internal
|
|
46
|
+
*/
|
|
47
47
|
export declare function requestOchre<TOutput>(parameters: {
|
|
48
48
|
xquery: string;
|
|
49
49
|
schema: v.GenericSchema<unknown, TOutput>;
|
|
@@ -52,15 +52,15 @@ export declare function requestOchre<TOutput>(parameters: {
|
|
|
52
52
|
checkRawData?: (data: unknown) => void;
|
|
53
53
|
}): Promise<TOutput>;
|
|
54
54
|
/**
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
55
|
+
Post a JSON payload to the OCHRE API
|
|
56
|
+
@param parameters - The request parameters
|
|
57
|
+
@param parameters.body - The JSON payload to post
|
|
58
|
+
@param parameters.label - What is being posted, used in failure messages
|
|
59
|
+
@param parameters.options - Transport options
|
|
60
|
+
@returns Whether the API accepted the payload
|
|
61
|
+
@throws When the request cannot be completed at all
|
|
62
|
+
@internal
|
|
63
|
+
*/
|
|
64
64
|
export declare function isOchreJsonAccepted(parameters: {
|
|
65
65
|
body: unknown;
|
|
66
66
|
label: string;
|