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,14 +1,14 @@
|
|
|
1
1
|
import { parseStringContent } from "../helpers.mjs";
|
|
2
2
|
// src/parsers/website/messages.ts
|
|
3
3
|
/**
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
4
|
+
Name a resource well enough to find it in OCHRE from an error message
|
|
5
|
+
|
|
6
|
+
Every throw in the website parser goes through here, because a UUID on its
|
|
7
|
+
own is not something anyone can look up quickly and a label on its own is
|
|
8
|
+
not unique.
|
|
9
|
+
@param resource - The resource the error is about
|
|
10
|
+
@returns A comma-separated description of the resource
|
|
11
|
+
@internal
|
|
12
12
|
*/
|
|
13
13
|
function formatXMLWebsiteResourceMetadata(resource) {
|
|
14
14
|
const metadata = [`label “${parseStringContent(resource.identification.label)}”`, `uuid “${resource.uuid}”`];
|
|
@@ -17,12 +17,12 @@ function formatXMLWebsiteResourceMetadata(resource) {
|
|
|
17
17
|
return metadata.join(", ");
|
|
18
18
|
}
|
|
19
19
|
/**
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
20
|
+
Describe a component parser failure
|
|
21
|
+
@param message - What went wrong
|
|
22
|
+
@param componentName - The component being parsed
|
|
23
|
+
@param elementResource - The element the component belongs to
|
|
24
|
+
@returns The error message
|
|
25
|
+
@internal
|
|
26
26
|
*/
|
|
27
27
|
function formatComponentError(message, componentName, elementResource) {
|
|
28
28
|
return `${message} for component “${componentName ?? "(unknown)"}” (${formatXMLWebsiteResourceMetadata(elementResource)})`;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
+
import { ParserOptions } from "../helpers.mjs";
|
|
1
2
|
import { WebOptions } from "../../types/website.mjs";
|
|
2
3
|
import { XMLWebsiteOptions } from "../../xml/types.mjs";
|
|
3
|
-
import { ParserOptions } from "../helpers.mjs";
|
|
4
4
|
export declare function parseWebsiteOptions<T extends ReadonlyArray<string>>(rawOptions: XMLWebsiteOptions | undefined, options: ParserOptions<T>): WebOptions<T>;
|
|
@@ -1,10 +1,19 @@
|
|
|
1
|
-
import { WebSidebar, Website } from "../../types/website.mjs";
|
|
2
|
-
import { XMLWebsiteProperties, XMLWebsiteTree } from "../../xml/types.mjs";
|
|
3
1
|
import { ParserOptions } from "../helpers.mjs";
|
|
2
|
+
import { WebsitePresentationReader } from "./reader.mjs";
|
|
3
|
+
import { WebSidebar, Website } from "../../types/website.mjs";
|
|
4
|
+
import { XMLWebsiteTree } from "../../xml/types.mjs";
|
|
5
|
+
export declare const WEBPAGE_PROPERTY_DEFAULTS: Website["properties"]["page"];
|
|
6
|
+
export declare const WEBPAGE_PROPERTY_LABELS: {
|
|
7
|
+
readonly width: "width";
|
|
8
|
+
readonly variant: "variant";
|
|
9
|
+
readonly isBreadcrumbsDisplayed: "breadcrumbs-displayed";
|
|
10
|
+
readonly isSidebarDisplayed: "sidebar-displayed";
|
|
11
|
+
readonly isNavbarSearchBarDisplayed: "navbar-search-bar-displayed";
|
|
12
|
+
};
|
|
4
13
|
/**
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
export declare function parseWebsiteProperties<T extends ReadonlyArray<string>>(
|
|
14
|
+
Parses raw website properties into a standardized Website properties structure
|
|
15
|
+
|
|
16
|
+
@param websiteReader - Reader over the website's "presentation" properties
|
|
17
|
+
@returns Parsed WebsiteProperties object
|
|
18
|
+
*/
|
|
19
|
+
export declare function parseWebsiteProperties<T extends ReadonlyArray<string>>(websiteReader: WebsitePresentationReader<T>, websiteTree: XMLWebsiteTree, sidebar: WebSidebar<T> | null, options: ParserOptions<T>, parent: Website<T>["properties"] | null): Website<T>["properties"];
|
|
@@ -1,17 +1,27 @@
|
|
|
1
|
-
import { parseSimplifiedProperties } from "../index.mjs";
|
|
2
1
|
import { parseWebsiteOptions } from "./options.mjs";
|
|
3
|
-
import { websitePresentationReader } from "./reader.mjs";
|
|
4
2
|
import { parseStylesheets } from "./styles.mjs";
|
|
5
3
|
// src/parsers/website/properties.ts
|
|
4
|
+
const WEBPAGE_PROPERTY_DEFAULTS = {
|
|
5
|
+
width: "default",
|
|
6
|
+
variant: "default",
|
|
7
|
+
isBreadcrumbsDisplayed: false,
|
|
8
|
+
isSidebarDisplayed: true,
|
|
9
|
+
isNavbarSearchBarDisplayed: true
|
|
10
|
+
};
|
|
11
|
+
const WEBPAGE_PROPERTY_LABELS = {
|
|
12
|
+
width: "width",
|
|
13
|
+
variant: "variant",
|
|
14
|
+
isBreadcrumbsDisplayed: "breadcrumbs-displayed",
|
|
15
|
+
isSidebarDisplayed: "sidebar-displayed",
|
|
16
|
+
isNavbarSearchBarDisplayed: "navbar-search-bar-displayed"
|
|
17
|
+
};
|
|
6
18
|
/**
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
19
|
+
Parses raw website properties into a standardized Website properties structure
|
|
20
|
+
|
|
21
|
+
@param websiteReader - Reader over the website's "presentation" properties
|
|
22
|
+
@returns Parsed WebsiteProperties object
|
|
11
23
|
*/
|
|
12
|
-
function parseWebsiteProperties(
|
|
13
|
-
const mainProperties = parseSimplifiedProperties({ property: properties }, options);
|
|
14
|
-
const websiteReader = websitePresentationReader(mainProperties).nested("presentation");
|
|
24
|
+
function parseWebsiteProperties(websiteReader, websiteTree, sidebar, options, parent) {
|
|
15
25
|
const returnProperties = {
|
|
16
26
|
type: parent?.type ?? "traditional",
|
|
17
27
|
status: parent?.status ?? "development",
|
|
@@ -42,6 +52,7 @@ function parseWebsiteProperties(properties, websiteTree, sidebar, options, paren
|
|
|
42
52
|
items: parent?.footer.items ?? null
|
|
43
53
|
},
|
|
44
54
|
sidebar: sidebar ?? parent?.sidebar ?? null,
|
|
55
|
+
page: { ...parent?.page ?? WEBPAGE_PROPERTY_DEFAULTS },
|
|
45
56
|
itemPage: {
|
|
46
57
|
isMainContentDisplayed: parent?.itemPage.isMainContentDisplayed ?? true,
|
|
47
58
|
description: {
|
|
@@ -61,7 +72,7 @@ function parseWebsiteProperties(properties, websiteTree, sidebar, options, paren
|
|
|
61
72
|
isDisplayed: parent?.itemPage.events.isDisplayed ?? true,
|
|
62
73
|
isHeaderDisplayed: parent?.itemPage.events.isHeaderDisplayed ?? true,
|
|
63
74
|
variant: parent?.itemPage.events.variant ?? "tabular",
|
|
64
|
-
isFilterInputDisplayed: parent?.itemPage.events.isFilterInputDisplayed ??
|
|
75
|
+
isFilterInputDisplayed: parent?.itemPage.events.isFilterInputDisplayed ?? false
|
|
65
76
|
},
|
|
66
77
|
periods: {
|
|
67
78
|
isDisplayed: parent?.itemPage.periods.isDisplayed ?? true,
|
|
@@ -119,6 +130,7 @@ function parseWebsiteProperties(properties, websiteTree, sidebar, options, paren
|
|
|
119
130
|
websiteReader.readAllUuids(returnProperties.navbar, { searchBarBoundElementUuid: "bound-element-navbar-search-bar" });
|
|
120
131
|
websiteReader.readAll(returnProperties.footer, { isDisplayed: "footer-displayed" });
|
|
121
132
|
websiteReader.readAllUuids(returnProperties.footer, { logoUuid: "footer-logo" });
|
|
133
|
+
websiteReader.nestedByValue("customize-special", "page").readAll(returnProperties.page, WEBPAGE_PROPERTY_LABELS);
|
|
122
134
|
const itemPageReader = websiteReader.nestedByValue("customize-special", "item-page");
|
|
123
135
|
if (itemPageReader.size > 0) {
|
|
124
136
|
for (const [key, slug] of [
|
|
@@ -158,4 +170,4 @@ function parseWebsiteProperties(properties, websiteTree, sidebar, options, paren
|
|
|
158
170
|
}
|
|
159
171
|
return returnProperties;
|
|
160
172
|
}
|
|
161
|
-
export { parseWebsiteProperties };
|
|
173
|
+
export { WEBPAGE_PROPERTY_DEFAULTS, WEBPAGE_PROPERTY_LABELS, parseWebsiteProperties };
|
|
@@ -1,32 +1,40 @@
|
|
|
1
|
+
import { ParserOptions } from "../helpers.mjs";
|
|
1
2
|
import { MultilingualString } from "../multilingual.mjs";
|
|
2
3
|
import { LanguageCodes, PropertyValueContent, SimplifiedProperty } from "../../types/index.mjs";
|
|
3
|
-
import { ParserOptions } from "../helpers.mjs";
|
|
4
4
|
type WebsitePropertyContent<T extends LanguageCodes> = PropertyValueContent<T>["content"];
|
|
5
5
|
/**
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
The fields of an object that hold a UUID, which are the only ones
|
|
7
|
+
{@link WebsitePresentationReader.readAllUuids} can write
|
|
8
|
+
*/
|
|
9
9
|
type UuidKeys<O> = { [K in keyof O]-?: O[K] extends string | null ? K : never; }[keyof O];
|
|
10
10
|
/**
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
11
|
+
Reads a website's presentation properties
|
|
12
|
+
|
|
13
|
+
OCHRE stores everything a website declares about itself as labeled property
|
|
14
|
+
values nested under a "presentation" property, so every read is "find the
|
|
15
|
+
property with this label, then take its first value". This owns that walk
|
|
16
|
+
and the coercions that go with it, and hands back readers for nested levels
|
|
17
|
+
so the caller never touches the raw property array.
|
|
18
|
+
|
|
19
|
+
A reader can fall back to another reader, which is how a website's
|
|
20
|
+
"customize-special" defaults reach the resources below it: a label the
|
|
21
|
+
resource leaves unset is read from the fallback, and a label it sets wins.
|
|
22
|
+
A property is inherited whole, so a list-valued label takes the resource's
|
|
23
|
+
values or the fallback's, never a mix of both, and the children of a label
|
|
24
|
+
set on both sides only fall back under the same value.
|
|
25
|
+
*/
|
|
19
26
|
export declare class WebsitePresentationReader<T extends LanguageCodes> {
|
|
20
27
|
private readonly sourceProperties;
|
|
21
|
-
|
|
28
|
+
private readonly fallback;
|
|
29
|
+
constructor(sourceProperties: ReadonlyArray<SimplifiedProperty<T>>, fallback?: WebsitePresentationReader<T> | null);
|
|
22
30
|
private propertyByValue;
|
|
23
31
|
/**
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
32
|
+
Overwrite one field from a labeled OCHRE property
|
|
33
|
+
|
|
34
|
+
Private because {@link readAll} covers every caller: a single-field read
|
|
35
|
+
is a one-entry label map, and going through the map keeps the field's type
|
|
36
|
+
coming from the target rather than from a type argument.
|
|
37
|
+
*/
|
|
30
38
|
private readOne;
|
|
31
39
|
property(label: string): SimplifiedProperty<T> | null;
|
|
32
40
|
requiredProperty(label: string, message: string): SimplifiedProperty<T>;
|
|
@@ -34,44 +42,45 @@ export declare class WebsitePresentationReader<T extends LanguageCodes> {
|
|
|
34
42
|
value<U = WebsitePropertyContent<T>>(label: string): U | null;
|
|
35
43
|
valueOr<U>(label: string, fallback: U): U;
|
|
36
44
|
/**
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
45
|
+
Read a property whose field is a string but whose OCHRE value may not be
|
|
46
|
+
|
|
47
|
+
OCHRE types a dimension like "width" from what was entered, so the same
|
|
48
|
+
property arrives as `"50%"` on one resource and `50` on another. Anything
|
|
49
|
+
that is neither is treated as unset rather than stringified, so a stray
|
|
50
|
+
boolean does not become the literal text "true".
|
|
51
|
+
@param label - The OCHRE property label to read
|
|
52
|
+
@returns The string, or null when the property is unset or not string-like
|
|
53
|
+
*/
|
|
46
54
|
stringValue(label: string): string | null;
|
|
47
55
|
stringValues(label: string): Array<string>;
|
|
48
56
|
uuid(label: string): string | null;
|
|
49
57
|
multilingualValue(label: string, options: ParserOptions<T>): MultilingualString<T> | null;
|
|
50
58
|
/**
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
59
|
+
Overwrite several fields from the OCHRE properties naming them
|
|
60
|
+
|
|
61
|
+
The defaults object carries the shape and the fallback values, and the
|
|
62
|
+
label map carries the OCHRE names, so a component states each property
|
|
63
|
+
twice rather than five times: once as a default and once as a label. The
|
|
64
|
+
field's type comes from the defaults object, so no type argument is needed.
|
|
65
|
+
@param target - The object holding the fields, pre-filled with defaults
|
|
66
|
+
@param labels - The OCHRE property label for each field to overwrite
|
|
67
|
+
*/
|
|
60
68
|
readAll<O extends object>(target: O, labels: Partial<Record<keyof O, string>>): void;
|
|
61
69
|
/**
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
+
Overwrite several UUID fields from the UUIDs labeled OCHRE properties
|
|
71
|
+
point at
|
|
72
|
+
|
|
73
|
+
The same shape as {@link readAll}, for the fields that take the value's
|
|
74
|
+
target rather than its content.
|
|
75
|
+
@param target - The object holding the fields, pre-filled with defaults
|
|
76
|
+
@param labels - The OCHRE property label for each field to overwrite
|
|
77
|
+
*/
|
|
70
78
|
readAllUuids<O extends object>(target: O, labels: Partial<Record<UuidKeys<O>, string>>): void;
|
|
71
79
|
nested(label: string): WebsitePresentationReader<T>;
|
|
72
80
|
nestedByValue(label: string, value: WebsitePropertyContent<T>): WebsitePresentationReader<T>;
|
|
73
81
|
nestedAllByValue(label: string, value: WebsitePropertyContent<T>): Array<WebsitePresentationReader<T>>;
|
|
82
|
+
withFallback(fallback: WebsitePresentationReader<T> | null): WebsitePresentationReader<T>;
|
|
74
83
|
get size(): number;
|
|
75
84
|
}
|
|
76
|
-
export declare function websitePresentationReader<T extends LanguageCodes>(properties: ReadonlyArray<SimplifiedProperty<T
|
|
85
|
+
export declare function websitePresentationReader<T extends LanguageCodes>(properties: ReadonlyArray<SimplifiedProperty<T>>, fallback?: WebsitePresentationReader<T> | null): WebsitePresentationReader<T>;
|
|
77
86
|
export {};
|
|
@@ -2,37 +2,46 @@ import { getProperty, getPropertyValue } from "../../getters.mjs";
|
|
|
2
2
|
import { multilingualFromText } from "../helpers.mjs";
|
|
3
3
|
// src/parsers/website/reader.ts
|
|
4
4
|
/**
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
5
|
+
Reads a website's presentation properties
|
|
6
|
+
|
|
7
|
+
OCHRE stores everything a website declares about itself as labeled property
|
|
8
|
+
values nested under a "presentation" property, so every read is "find the
|
|
9
|
+
property with this label, then take its first value". This owns that walk
|
|
10
|
+
and the coercions that go with it, and hands back readers for nested levels
|
|
11
|
+
so the caller never touches the raw property array.
|
|
12
|
+
|
|
13
|
+
A reader can fall back to another reader, which is how a website's
|
|
14
|
+
"customize-special" defaults reach the resources below it: a label the
|
|
15
|
+
resource leaves unset is read from the fallback, and a label it sets wins.
|
|
16
|
+
A property is inherited whole, so a list-valued label takes the resource's
|
|
17
|
+
values or the fallback's, never a mix of both, and the children of a label
|
|
18
|
+
set on both sides only fall back under the same value.
|
|
12
19
|
*/
|
|
13
20
|
var WebsitePresentationReader = class WebsitePresentationReader {
|
|
14
21
|
sourceProperties;
|
|
15
|
-
|
|
22
|
+
fallback;
|
|
23
|
+
constructor(sourceProperties, fallback = null) {
|
|
16
24
|
this.sourceProperties = sourceProperties;
|
|
25
|
+
this.fallback = fallback;
|
|
17
26
|
}
|
|
18
27
|
propertyByValue(label, value) {
|
|
19
28
|
return getProperty(this.sourceProperties, {
|
|
20
29
|
label,
|
|
21
30
|
valueContent: value
|
|
22
|
-
});
|
|
31
|
+
}) ?? this.fallback?.propertyByValue(label, value) ?? null;
|
|
23
32
|
}
|
|
24
33
|
/**
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
34
|
+
Overwrite one field from a labeled OCHRE property
|
|
35
|
+
|
|
36
|
+
Private because {@link readAll} covers every caller: a single-field read
|
|
37
|
+
is a one-entry label map, and going through the map keeps the field's type
|
|
38
|
+
coming from the target rather than from a type argument.
|
|
30
39
|
*/
|
|
31
40
|
readOne(target, key, label) {
|
|
32
41
|
target[key] = this.valueOr(label, target[key]);
|
|
33
42
|
}
|
|
34
43
|
property(label) {
|
|
35
|
-
return getProperty(this.sourceProperties, { label });
|
|
44
|
+
return getProperty(this.sourceProperties, { label }) ?? this.fallback?.property(label) ?? null;
|
|
36
45
|
}
|
|
37
46
|
requiredProperty(label, message) {
|
|
38
47
|
const property = this.property(label);
|
|
@@ -40,7 +49,7 @@ var WebsitePresentationReader = class WebsitePresentationReader {
|
|
|
40
49
|
return property;
|
|
41
50
|
}
|
|
42
51
|
valueNode(label) {
|
|
43
|
-
return getPropertyValue(this.sourceProperties, { label });
|
|
52
|
+
return getPropertyValue(this.sourceProperties, { label }) ?? this.fallback?.valueNode(label) ?? null;
|
|
44
53
|
}
|
|
45
54
|
value(label) {
|
|
46
55
|
return this.valueNode(label)?.content ?? null;
|
|
@@ -49,14 +58,14 @@ var WebsitePresentationReader = class WebsitePresentationReader {
|
|
|
49
58
|
return this.value(label) ?? fallback;
|
|
50
59
|
}
|
|
51
60
|
/**
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
61
|
+
Read a property whose field is a string but whose OCHRE value may not be
|
|
62
|
+
|
|
63
|
+
OCHRE types a dimension like "width" from what was entered, so the same
|
|
64
|
+
property arrives as `"50%"` on one resource and `50` on another. Anything
|
|
65
|
+
that is neither is treated as unset rather than stringified, so a stray
|
|
66
|
+
boolean does not become the literal text "true".
|
|
67
|
+
@param label - The OCHRE property label to read
|
|
68
|
+
@returns The string, or null when the property is unset or not string-like
|
|
60
69
|
*/
|
|
61
70
|
stringValue(label) {
|
|
62
71
|
const value = this.value(label);
|
|
@@ -72,7 +81,7 @@ var WebsitePresentationReader = class WebsitePresentationReader {
|
|
|
72
81
|
if (typeof value === "string" && value.trim() !== "") values.push(value.trim());
|
|
73
82
|
}
|
|
74
83
|
}
|
|
75
|
-
return values;
|
|
84
|
+
return values.length === 0 && this.fallback != null ? this.fallback.stringValues(label) : values;
|
|
76
85
|
}
|
|
77
86
|
uuid(label) {
|
|
78
87
|
return this.valueNode(label)?.uuid ?? null;
|
|
@@ -84,35 +93,41 @@ var WebsitePresentationReader = class WebsitePresentationReader {
|
|
|
84
93
|
return typeof value.content === "string" ? multilingualFromText(value.content, options) : null;
|
|
85
94
|
}
|
|
86
95
|
/**
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
96
|
+
Overwrite several fields from the OCHRE properties naming them
|
|
97
|
+
|
|
98
|
+
The defaults object carries the shape and the fallback values, and the
|
|
99
|
+
label map carries the OCHRE names, so a component states each property
|
|
100
|
+
twice rather than five times: once as a default and once as a label. The
|
|
101
|
+
field's type comes from the defaults object, so no type argument is needed.
|
|
102
|
+
@param target - The object holding the fields, pre-filled with defaults
|
|
103
|
+
@param labels - The OCHRE property label for each field to overwrite
|
|
95
104
|
*/
|
|
96
105
|
readAll(target, labels) {
|
|
97
106
|
for (const [key, label] of Object.entries(labels)) if (label != null) this.readOne(target, key, label);
|
|
98
107
|
}
|
|
99
108
|
/**
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
109
|
+
Overwrite several UUID fields from the UUIDs labeled OCHRE properties
|
|
110
|
+
point at
|
|
111
|
+
|
|
112
|
+
The same shape as {@link readAll}, for the fields that take the value's
|
|
113
|
+
target rather than its content.
|
|
114
|
+
@param target - The object holding the fields, pre-filled with defaults
|
|
115
|
+
@param labels - The OCHRE property label for each field to overwrite
|
|
107
116
|
*/
|
|
108
117
|
readAllUuids(target, labels) {
|
|
109
118
|
for (const [key, label] of Object.entries(labels)) if (label != null) target[key] = this.uuid(label) ?? target[key];
|
|
110
119
|
}
|
|
111
120
|
nested(label) {
|
|
112
|
-
|
|
121
|
+
const property = getProperty(this.sourceProperties, { label });
|
|
122
|
+
if (property == null) return this.fallback?.nested(label) ?? new WebsitePresentationReader([]);
|
|
123
|
+
const value = property.values[0]?.content;
|
|
124
|
+
return new WebsitePresentationReader(property.properties, value == null ? null : this.fallback?.nestedByValue(label, value) ?? null);
|
|
113
125
|
}
|
|
114
126
|
nestedByValue(label, value) {
|
|
115
|
-
return new WebsitePresentationReader(this.
|
|
127
|
+
return new WebsitePresentationReader(getProperty(this.sourceProperties, {
|
|
128
|
+
label,
|
|
129
|
+
valueContent: value
|
|
130
|
+
})?.properties ?? [], this.fallback?.nestedByValue(label, value) ?? null);
|
|
116
131
|
}
|
|
117
132
|
nestedAllByValue(label, value) {
|
|
118
133
|
const readers = [];
|
|
@@ -120,13 +135,16 @@ var WebsitePresentationReader = class WebsitePresentationReader {
|
|
|
120
135
|
label,
|
|
121
136
|
valueContent: value
|
|
122
137
|
}) != null) readers.push(new WebsitePresentationReader(property.properties));
|
|
123
|
-
return readers;
|
|
138
|
+
return readers.length === 0 && this.fallback != null ? this.fallback.nestedAllByValue(label, value) : readers;
|
|
139
|
+
}
|
|
140
|
+
withFallback(fallback) {
|
|
141
|
+
return new WebsitePresentationReader(this.sourceProperties, fallback);
|
|
124
142
|
}
|
|
125
143
|
get size() {
|
|
126
|
-
return this.sourceProperties.length;
|
|
144
|
+
return this.sourceProperties.length + (this.fallback?.size ?? 0);
|
|
127
145
|
}
|
|
128
146
|
};
|
|
129
|
-
function websitePresentationReader(properties) {
|
|
130
|
-
return new WebsitePresentationReader(properties);
|
|
147
|
+
function websitePresentationReader(properties, fallback = null) {
|
|
148
|
+
return new WebsitePresentationReader(properties, fallback);
|
|
131
149
|
}
|
|
132
150
|
export { WebsitePresentationReader, websitePresentationReader };
|
|
@@ -1,65 +1,65 @@
|
|
|
1
1
|
/**
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
2
|
+
How a website page slug is built
|
|
3
|
+
|
|
4
|
+
The rule runs in two places: here, while parsing a website, and inside the
|
|
5
|
+
website metadata fetcher's XQuery, which resolves a slug to a page without
|
|
6
|
+
shipping the whole tree. Both adapters live in this module so the rule
|
|
7
|
+
cannot drift. The only difference between them is how "no prefix" is
|
|
8
|
+
spelled: `undefined` in TypeScript, the empty string in XQuery, which has no
|
|
9
|
+
way to pass an absent argument.
|
|
10
|
+
*/
|
|
11
11
|
/**
|
|
12
|
-
|
|
13
|
-
|
|
12
|
+
The prefix OCHRE puts on a segment page's slug to keep it unique
|
|
13
|
+
*/
|
|
14
14
|
export declare const SEGMENT_UNIQUE_SLUG_PREFIX_PATTERN: string;
|
|
15
15
|
/**
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
The separator between a slug and its prefix
|
|
17
|
+
*/
|
|
18
18
|
export declare const WEBSITE_PAGE_SLUG_SEPARATOR = "/";
|
|
19
19
|
/**
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
20
|
+
The full slug of every page in a website, keyed by the page's UUID
|
|
21
|
+
|
|
22
|
+
Resolved before parsing begins, because a link on any page can point at any
|
|
23
|
+
other page and the target's slug depends on where that target sits in the
|
|
24
|
+
tree.
|
|
25
|
+
@internal
|
|
26
|
+
*/
|
|
27
27
|
export type WebsitePageSlugs = ReadonlyMap<string, string>;
|
|
28
28
|
/**
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
29
|
+
Strip the uniqueness prefix from a website page slug
|
|
30
|
+
@param slug - The raw slug
|
|
31
|
+
@returns The cleaned slug, or null when there was none
|
|
32
|
+
@internal
|
|
33
|
+
*/
|
|
34
34
|
export declare function cleanWebsitePageSlug(slug: string | undefined): string | null;
|
|
35
35
|
/**
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
36
|
+
Join a website page slug onto the slug of the segment holding it
|
|
37
|
+
@param slug - The page slug
|
|
38
|
+
@param slugPrefix - The slug of the enclosing segment, if any
|
|
39
|
+
@returns The full slug
|
|
40
|
+
@internal
|
|
41
|
+
*/
|
|
42
42
|
export declare function prefixSlug(slug: string, slugPrefix: string | undefined): string;
|
|
43
43
|
/**
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
44
|
+
The slug a page gives its own child pages
|
|
45
|
+
|
|
46
|
+
A page only prefixes its children once it is itself inside a segment, so a
|
|
47
|
+
top-level website keeps flat page slugs.
|
|
48
|
+
@param pageSlug - The page's own full slug
|
|
49
|
+
@param slugPrefix - The prefix the page was resolved with
|
|
50
|
+
@returns The prefix for the page's children, or undefined for no prefix
|
|
51
|
+
@internal
|
|
52
|
+
*/
|
|
53
53
|
export declare function childSlugPrefix(pageSlug: string, slugPrefix: string | undefined): string | undefined;
|
|
54
54
|
/**
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
55
|
+
The XQuery counterpart of {@link cleanWebsitePageSlug},
|
|
56
|
+
{@link prefixSlug} and {@link childSlugPrefix}
|
|
57
|
+
|
|
58
|
+
Declares `local:clean-slug`, `local:prefix-slug`, `local:page-slug` and
|
|
59
|
+
`local:page-child-slug-prefix`. "No prefix" is the empty string here.
|
|
60
|
+
`local:prefix-slug` takes a slug value rather than a resource, because a
|
|
61
|
+
segment's own slug comes from its abbreviation instead of a `@slug`
|
|
62
|
+
attribute.
|
|
63
|
+
@internal
|
|
64
|
+
*/
|
|
65
65
|
export declare const WEBSITE_PAGE_SLUG_DECLARATIONS: string;
|