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.
Files changed (97) hide show
  1. package/dist/categories.d.mts +56 -56
  2. package/dist/categories.mjs +39 -39
  3. package/dist/constants.d.mts +8 -8
  4. package/dist/constants.mjs +6 -6
  5. package/dist/errors.d.mts +12 -12
  6. package/dist/errors.mjs +22 -23
  7. package/dist/fetchers/container-items.d.mts +28 -28
  8. package/dist/fetchers/container-items.mjs +27 -27
  9. package/dist/fetchers/gallery.d.mts +13 -13
  10. package/dist/fetchers/gallery.mjs +2 -2
  11. package/dist/fetchers/item-children.d.mts +12 -12
  12. package/dist/fetchers/item-children.mjs +2 -2
  13. package/dist/fetchers/item-links.d.mts +10 -10
  14. package/dist/fetchers/item-links.mjs +6 -6
  15. package/dist/fetchers/item-locations.d.mts +20 -20
  16. package/dist/fetchers/item-locations.mjs +3 -3
  17. package/dist/fetchers/item-ocr-data.d.mts +23 -23
  18. package/dist/fetchers/item-ocr-data.mjs +44 -44
  19. package/dist/fetchers/item.d.mts +23 -18
  20. package/dist/fetchers/item.mjs +15 -15
  21. package/dist/fetchers/map-layers.d.mts +15 -15
  22. package/dist/fetchers/map-layers.mjs +12 -11
  23. package/dist/fetchers/request.d.mts +40 -40
  24. package/dist/fetchers/request.mjs +37 -37
  25. package/dist/fetchers/set/items.d.mts +15 -15
  26. package/dist/fetchers/set/items.mjs +1 -1
  27. package/dist/fetchers/set/property-values.d.mts +16 -16
  28. package/dist/fetchers/set/property-values.mjs +43 -43
  29. package/dist/fetchers/tree/items.d.mts +27 -27
  30. package/dist/fetchers/tree/items.mjs +1 -1
  31. package/dist/fetchers/website-metadata.d.mts +4 -4
  32. package/dist/fetchers/website-metadata.mjs +9 -9
  33. package/dist/fetchers/website.d.mts +10 -10
  34. package/dist/fetchers/website.mjs +12 -12
  35. package/dist/getters.d.mts +83 -83
  36. package/dist/getters.mjs +74 -74
  37. package/dist/helpers.d.mts +4 -4
  38. package/dist/helpers.mjs +7 -7
  39. package/dist/index.d.mts +3 -3
  40. package/dist/index.mjs +5 -5
  41. package/dist/languages.d.mts +58 -58
  42. package/dist/languages.mjs +21 -21
  43. package/dist/ocr.d.mts +27 -27
  44. package/dist/ocr.mjs +29 -29
  45. package/dist/parsers/helpers.d.mts +23 -23
  46. package/dist/parsers/helpers.mjs +8 -8
  47. package/dist/parsers/index.d.mts +2 -2
  48. package/dist/parsers/index.mjs +15 -15
  49. package/dist/parsers/languages.d.mts +49 -49
  50. package/dist/parsers/languages.mjs +49 -49
  51. package/dist/parsers/multilingual.d.mts +174 -174
  52. package/dist/parsers/multilingual.mjs +146 -146
  53. package/dist/parsers/partial-date.d.mts +12 -12
  54. package/dist/parsers/partial-date.mjs +11 -11
  55. package/dist/parsers/property-token.d.mts +20 -20
  56. package/dist/parsers/property-token.mjs +16 -16
  57. package/dist/parsers/string.d.mts +33 -33
  58. package/dist/parsers/string.mjs +62 -64
  59. package/dist/parsers/website/bounds.d.mts +6 -6
  60. package/dist/parsers/website/bounds.mjs +5 -5
  61. package/dist/parsers/website/components.d.mts +46 -31
  62. package/dist/parsers/website/components.mjs +84 -51
  63. package/dist/parsers/website/index.d.mts +2 -2
  64. package/dist/parsers/website/index.mjs +45 -48
  65. package/dist/parsers/website/links.d.mts +24 -24
  66. package/dist/parsers/website/links.mjs +18 -18
  67. package/dist/parsers/website/messages.d.mts +16 -16
  68. package/dist/parsers/website/messages.mjs +14 -14
  69. package/dist/parsers/website/options.d.mts +1 -1
  70. package/dist/parsers/website/properties.d.mts +17 -8
  71. package/dist/parsers/website/properties.mjs +31 -10
  72. package/dist/parsers/website/reader.d.mts +55 -47
  73. package/dist/parsers/website/reader.mjs +66 -51
  74. package/dist/parsers/website/slug.d.mts +50 -50
  75. package/dist/parsers/website/slug.mjs +36 -36
  76. package/dist/parsers/website/styles.d.mts +18 -18
  77. package/dist/parsers/website/styles.mjs +19 -19
  78. package/dist/parsers/website/walk.d.mts +46 -46
  79. package/dist/parsers/website/walk.mjs +34 -34
  80. package/dist/query.d.mts +63 -63
  81. package/dist/query.mjs +137 -140
  82. package/dist/reflection.d.mts +51 -51
  83. package/dist/reflection.mjs +45 -45
  84. package/dist/schemas.d.mts +44 -44
  85. package/dist/schemas.mjs +50 -50
  86. package/dist/types/index.d.mts +192 -192
  87. package/dist/types/utilities.d.mts +5 -5
  88. package/dist/types/website.d.mts +74 -62
  89. package/dist/xml/dates.d.mts +9 -9
  90. package/dist/xml/dates.mjs +9 -9
  91. package/dist/xml/metadata.d.mts +14 -14
  92. package/dist/xml/metadata.mjs +18 -18
  93. package/dist/xml/schemas.mjs +24 -24
  94. package/dist/xml/types.d.mts +9 -9
  95. package/dist/xquery.d.mts +49 -49
  96. package/dist/xquery.mjs +50 -50
  97. 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
- * 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
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
- * 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
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, Webpage, Website } from "../../types/website.mjs";
4
+ import { XMLWebsiteTree } from "../../xml/types.mjs";
5
+ export declare function resolveWebpageSettings(page: Website["properties"]["page"] | undefined): Pick<Webpage["properties"], keyof 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
- * Parses raw website properties into a standardized Website properties structure
6
- *
7
- * @param properties - Array of raw website properties in OCHRE format
8
- * @returns Parsed WebsiteProperties object
9
- */
10
- export declare function parseWebsiteProperties<T extends ReadonlyArray<string>>(properties: XMLWebsiteProperties["property"], websiteTree: XMLWebsiteTree, sidebar: WebSidebar<T> | null, options: ParserOptions<T>, parent: Website<T>["properties"] | null): Website<T>["properties"];
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, componentDefaults: Website<T>["properties"]["componentDefaults"]): Website<T>["properties"];
@@ -1,17 +1,29 @@
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
+ function resolveWebpageSettings(page) {
5
+ return {
6
+ width: page?.width ?? "default",
7
+ variant: page?.variant ?? "default",
8
+ isBreadcrumbsDisplayed: page?.isBreadcrumbsDisplayed ?? false,
9
+ isSidebarDisplayed: page?.isSidebarDisplayed ?? true,
10
+ isNavbarSearchBarDisplayed: page?.isNavbarSearchBarDisplayed ?? true
11
+ };
12
+ }
13
+ const WEBPAGE_PROPERTY_LABELS = {
14
+ width: "width",
15
+ variant: "variant",
16
+ isBreadcrumbsDisplayed: "breadcrumbs-displayed",
17
+ isSidebarDisplayed: "sidebar-displayed",
18
+ isNavbarSearchBarDisplayed: "navbar-search-bar-displayed"
19
+ };
6
20
  /**
7
- * Parses raw website properties into a standardized Website properties structure
8
- *
9
- * @param properties - Array of raw website properties in OCHRE format
10
- * @returns Parsed WebsiteProperties object
21
+ Parses raw website properties into a standardized Website properties structure
22
+
23
+ @param websiteReader - Reader over the website's "presentation" properties
24
+ @returns Parsed WebsiteProperties object
11
25
  */
12
- function parseWebsiteProperties(properties, websiteTree, sidebar, options, parent) {
13
- const mainProperties = parseSimplifiedProperties({ property: properties }, options);
14
- const websiteReader = websitePresentationReader(mainProperties).nested("presentation");
26
+ function parseWebsiteProperties(websiteReader, websiteTree, sidebar, options, parent, componentDefaults) {
15
27
  const returnProperties = {
16
28
  type: parent?.type ?? "traditional",
17
29
  status: parent?.status ?? "development",
@@ -42,6 +54,14 @@ function parseWebsiteProperties(properties, websiteTree, sidebar, options, paren
42
54
  items: parent?.footer.items ?? null
43
55
  },
44
56
  sidebar: sidebar ?? parent?.sidebar ?? null,
57
+ page: {
58
+ width: parent?.page.width ?? null,
59
+ variant: parent?.page.variant ?? null,
60
+ isBreadcrumbsDisplayed: parent?.page.isBreadcrumbsDisplayed ?? null,
61
+ isSidebarDisplayed: parent?.page.isSidebarDisplayed ?? null,
62
+ isNavbarSearchBarDisplayed: parent?.page.isNavbarSearchBarDisplayed ?? null
63
+ },
64
+ componentDefaults,
45
65
  itemPage: {
46
66
  isMainContentDisplayed: parent?.itemPage.isMainContentDisplayed ?? true,
47
67
  description: {
@@ -119,6 +139,7 @@ function parseWebsiteProperties(properties, websiteTree, sidebar, options, paren
119
139
  websiteReader.readAllUuids(returnProperties.navbar, { searchBarBoundElementUuid: "bound-element-navbar-search-bar" });
120
140
  websiteReader.readAll(returnProperties.footer, { isDisplayed: "footer-displayed" });
121
141
  websiteReader.readAllUuids(returnProperties.footer, { logoUuid: "footer-logo" });
142
+ websiteReader.nestedByValue("customize-special", "page").readAll(returnProperties.page, WEBPAGE_PROPERTY_LABELS);
122
143
  const itemPageReader = websiteReader.nestedByValue("customize-special", "item-page");
123
144
  if (itemPageReader.size > 0) {
124
145
  for (const [key, slug] of [
@@ -158,4 +179,4 @@ function parseWebsiteProperties(properties, websiteTree, sidebar, options, paren
158
179
  }
159
180
  return returnProperties;
160
181
  }
161
- export { parseWebsiteProperties };
182
+ export { WEBPAGE_PROPERTY_LABELS, parseWebsiteProperties, resolveWebpageSettings };
@@ -1,77 +1,85 @@
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
- * The fields of an object that hold a UUID, which are the only ones
7
- * {@link WebsitePresentationReader.readAllUuids} can write
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
- * 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
- */
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
- constructor(sourceProperties: ReadonlyArray<SimplifiedProperty<T>>);
22
- private propertyByValue;
28
+ private readonly fallback;
29
+ constructor(sourceProperties: ReadonlyArray<SimplifiedProperty<T>>, fallback?: WebsitePresentationReader<T> | null);
23
30
  /**
24
- * Overwrite one field from a labeled OCHRE property
25
- *
26
- * Private because {@link readAll} covers every caller: a single-field read
27
- * is a one-entry label map, and going through the map keeps the field's type
28
- * coming from the target rather than from a type argument.
29
- */
31
+ Overwrite one field from a labeled OCHRE property
32
+
33
+ Private because {@link readAll} covers every caller: a single-field read
34
+ is a one-entry label map, and going through the map keeps the field's type
35
+ coming from the target rather than from a type argument.
36
+ */
30
37
  private readOne;
38
+ propertyByValue(label: string, value: WebsitePropertyContent<T>): SimplifiedProperty<T> | null;
31
39
  property(label: string): SimplifiedProperty<T> | null;
32
40
  requiredProperty(label: string, message: string): SimplifiedProperty<T>;
33
41
  valueNode(label: string): PropertyValueContent<T> | null;
34
42
  value<U = WebsitePropertyContent<T>>(label: string): U | null;
35
43
  valueOr<U>(label: string, fallback: U): U;
36
44
  /**
37
- * Read a property whose field is a string but whose OCHRE value may not be
38
- *
39
- * OCHRE types a dimension like "width" from what was entered, so the same
40
- * property arrives as `"50%"` on one resource and `50` on another. Anything
41
- * that is neither is treated as unset rather than stringified, so a stray
42
- * boolean does not become the literal text "true".
43
- * @param label - The OCHRE property label to read
44
- * @returns The string, or null when the property is unset or not string-like
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
- * Overwrite several fields from the OCHRE properties naming them
52
- *
53
- * The defaults object carries the shape and the fallback values, and the
54
- * label map carries the OCHRE names, so a component states each property
55
- * twice rather than five times: once as a default and once as a label. The
56
- * field's type comes from the defaults object, so no type argument is needed.
57
- * @param target - The object holding the fields, pre-filled with defaults
58
- * @param labels - The OCHRE property label for each field to overwrite
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
- * Overwrite several UUID fields from the UUIDs labeled OCHRE properties
63
- * point at
64
- *
65
- * The same shape as {@link readAll}, for the fields that take the value's
66
- * target rather than its content.
67
- * @param target - The object holding the fields, pre-filled with defaults
68
- * @param labels - The OCHRE property label for each field to overwrite
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>>;
74
82
  get size(): number;
75
83
  }
76
- export declare function websitePresentationReader<T extends LanguageCodes>(properties: ReadonlyArray<SimplifiedProperty<T>>): WebsitePresentationReader<T>;
84
+ export declare function websitePresentationReader<T extends LanguageCodes>(properties: ReadonlyArray<SimplifiedProperty<T>>, fallback?: WebsitePresentationReader<T> | null): WebsitePresentationReader<T>;
77
85
  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
- * 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.
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
- constructor(sourceProperties) {
22
+ fallback;
23
+ constructor(sourceProperties, fallback = null) {
16
24
  this.sourceProperties = sourceProperties;
17
- }
18
- propertyByValue(label, value) {
19
- return getProperty(this.sourceProperties, {
20
- label,
21
- valueContent: value
22
- });
25
+ this.fallback = fallback;
23
26
  }
24
27
  /**
25
- * Overwrite one field from a labeled OCHRE property
26
- *
27
- * Private because {@link readAll} covers every caller: a single-field read
28
- * is a one-entry label map, and going through the map keeps the field's type
29
- * coming from the target rather than from a type argument.
28
+ Overwrite one field from a labeled OCHRE property
29
+
30
+ Private because {@link readAll} covers every caller: a single-field read
31
+ is a one-entry label map, and going through the map keeps the field's type
32
+ coming from the target rather than from a type argument.
30
33
  */
31
34
  readOne(target, key, label) {
32
35
  target[key] = this.valueOr(label, target[key]);
33
36
  }
37
+ propertyByValue(label, value) {
38
+ return getProperty(this.sourceProperties, {
39
+ label,
40
+ valueContent: value
41
+ }) ?? this.fallback?.propertyByValue(label, value) ?? null;
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
- * Read a property whose field is a string but whose OCHRE value may not be
53
- *
54
- * OCHRE types a dimension like "width" from what was entered, so the same
55
- * property arrives as `"50%"` on one resource and `50` on another. Anything
56
- * that is neither is treated as unset rather than stringified, so a stray
57
- * boolean does not become the literal text "true".
58
- * @param label - The OCHRE property label to read
59
- * @returns The string, or null when the property is unset or not string-like
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
- * Overwrite several fields from the OCHRE properties naming them
88
- *
89
- * The defaults object carries the shape and the fallback values, and the
90
- * label map carries the OCHRE names, so a component states each property
91
- * twice rather than five times: once as a default and once as a label. The
92
- * field's type comes from the defaults object, so no type argument is needed.
93
- * @param target - The object holding the fields, pre-filled with defaults
94
- * @param labels - The OCHRE property label for each field to overwrite
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
- * Overwrite several UUID fields from the UUIDs labeled OCHRE properties
101
- * point at
102
- *
103
- * The same shape as {@link readAll}, for the fields that take the value's
104
- * target rather than its content.
105
- * @param target - The object holding the fields, pre-filled with defaults
106
- * @param labels - The OCHRE property label for each field to overwrite
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
- return new WebsitePresentationReader(this.property(label)?.properties ?? []);
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.propertyByValue(label, value)?.properties ?? []);
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,13 @@ 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;
124
139
  }
125
140
  get size() {
126
- return this.sourceProperties.length;
141
+ return this.sourceProperties.length + (this.fallback?.size ?? 0);
127
142
  }
128
143
  };
129
- function websitePresentationReader(properties) {
130
- return new WebsitePresentationReader(properties);
144
+ function websitePresentationReader(properties, fallback = null) {
145
+ return new WebsitePresentationReader(properties, fallback);
131
146
  }
132
147
  export { WebsitePresentationReader, websitePresentationReader };
@@ -1,65 +1,65 @@
1
1
  /**
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
- */
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
- * The prefix OCHRE puts on a segment page's slug to keep it unique
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
- * The separator between a slug and its prefix
17
- */
16
+ The separator between a slug and its prefix
17
+ */
18
18
  export declare const WEBSITE_PAGE_SLUG_SEPARATOR = "/";
19
19
  /**
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
- */
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
- * 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
- */
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
- * 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
- */
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
- * 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
- */
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
- * 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
- */
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;