ochre-sdk 1.0.0-beta.9 → 1.0.1

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/README.md CHANGED
@@ -1,50 +1,135 @@
1
1
  # OCHRE SDK
2
2
 
3
- This is the OCHRE Node.js SDK for interacting with OCHRE ([Online Cultural and Historical Research Environment](https://ochre.uchicago.edu/)) data.
3
+ `ochre-sdk` is a TypeScript package for reading data from
4
+ [OCHRE](https://ochre.uchicago.edu/) (Online Cultural and Historical Research
5
+ Environment). It fetches OCHRE XML/XQuery responses, validates the payloads, and
6
+ parses them into typed objects that are easier to use in web applications,
7
+ digital collections, and research tools.
8
+
9
+ The package focuses on the public OCHRE v2 API and exposes higher-level helpers
10
+ for items, linked items, galleries, Set search results, Set facets, website
11
+ presentation records, multilingual text, and property access.
4
12
 
5
13
  ## Installation
6
14
 
7
- ```bash
8
- pnpm add ochre-sdk
15
+ ```sh
16
+ npm install ochre-sdk
9
17
  ```
10
18
 
11
- or
19
+ Use the equivalent command for your package manager if you do not use npm.
12
20
 
13
- ```bash
14
- npm install ochre-sdk
15
- ```
21
+ `ochre-sdk` is published as an ESM package. The runtime must provide `fetch`, or
22
+ you can pass a custom fetch implementation through each fetcher's `options.fetch`
23
+ field.
16
24
 
17
- or
25
+ ## Quick Start
18
26
 
19
- ```bash
20
- bun add ochre-sdk
21
- ```
27
+ ```ts
28
+ import { fetchItem } from "ochre-sdk";
29
+
30
+ const result = await fetchItem("<item-uuid>", {
31
+ category: "resource",
32
+ languages: ["eng"],
33
+ });
22
34
 
23
- ## Start development server
35
+ if (result.error != null) {
36
+ throw new Error(result.error);
37
+ }
24
38
 
25
- From the root directory of the project, run the following command:
39
+ console.log(result.item.identification.label.getText("eng"));
40
+ ```
26
41
 
27
- ```bash
28
- pnpm run dev
42
+ Every fetcher returns a success/error object. On success, the parsed value is
43
+ present and `error` is `null`; on failure, the parsed value is `null` and
44
+ `error` contains the message.
45
+
46
+ ## Core API
47
+
48
+ - `fetchItem(uuid, options)` fetches and parses a single OCHRE item. Passing
49
+ `category` narrows the returned TypeScript type, and `containedItemCategory`
50
+ controls how nested Tree or Set contents are parsed.
51
+ - `fetchItemLinks(uuid, options)` fetches items linked from a source item and
52
+ parses them as embedded OCHRE items.
53
+ - `fetchGallery(params, options)` fetches paginated resource galleries with an
54
+ optional label filter.
55
+ - `fetchWebsite(abbreviation, options)` fetches an OCHRE website presentation
56
+ record, including pages, segments, components, navigation, footer, sidebar,
57
+ style, collection, and item-page configuration.
58
+ - `fetchSetItems(params, containedItemCategories, options)` fetches paginated
59
+ Set search results with typed query and sort support.
60
+ - `fetchSetPropertyValues(params, options)` fetches Set property-value facets
61
+ and optional bibliography/period attribute facets for the same query model.
62
+
63
+ ## Multilingual Text
64
+
65
+ OCHRE text fields are represented with `MultilingualString`. It preserves plain
66
+ text and rich text renderings, supports language fallback, and exposes helpers
67
+ for exact-language access when consumers need stricter behavior.
68
+
69
+ ```ts
70
+ const title = result.item.identification.label;
71
+
72
+ title.getText("eng");
73
+ title.getRichText("eng");
74
+ title.getExactText("tur");
75
+ title.getAvailableLanguages();
29
76
  ```
30
77
 
31
- ## Build production server
78
+ For reusable language tuples, use `defineLanguages` to keep runtime validation
79
+ and literal TypeScript inference together.
32
80
 
33
- From the root directory of the project, run the following command:
81
+ ```ts
82
+ import { defineLanguages, fetchWebsite } from "ochre-sdk";
34
83
 
35
- ```bash
36
- pnpm run build
84
+ const languages = defineLanguages("eng", "tur");
85
+ const result = await fetchWebsite("uchicago-node", { languages });
37
86
  ```
38
87
 
39
- ## Release new version to NPM
88
+ ## Set Queries
40
89
 
41
- ```bash
42
- pnpm run release
90
+ Set fetchers accept a recursive `Query` tree. Leaf queries can target full text,
91
+ specific fields, property values, bibliographies, periods, notes, images, and
92
+ other supported OCHRE search surfaces.
93
+
94
+ ```ts
95
+ import { fetchSetItems, type Query } from "ochre-sdk";
96
+
97
+ const queries: Query = {
98
+ target: "string",
99
+ value: "Chicago",
100
+ matchMode: "includes",
101
+ isCaseSensitive: false,
102
+ language: "eng",
103
+ };
104
+
105
+ const result = await fetchSetItems(
106
+ { setScopeUuids: ["<set-uuid>"], queries, page: 1, pageSize: 48 },
107
+ ["resource", "bibliography"],
108
+ { languages: ["eng"] },
109
+ );
43
110
  ```
44
111
 
45
- ## Contributing
112
+ Use `fetchSetPropertyValues` with the same query shape when you need facet data
113
+ for a filtered result set.
114
+
115
+ ## Helpers And Types
116
+
117
+ The root export includes the SDK's public TypeScript model, website component
118
+ types, query types, property getters, and small data helpers:
119
+
120
+ - `Item`, `SetItem`, `ItemLink`, `Website`, `WebElementOf`,
121
+ `WebElementComponentOf`, `WebBlockByLayout`, `Query`, and related types.
122
+ - `getPropertyByVariableUuid`, `getPropertyValueContentByVariableUuid`,
123
+ `getPropertyByVariableLabel`, `getUniqueProperties`, `filterProperties`, and
124
+ related property helpers.
125
+ - `flattenItemProperties` and `DEFAULT_PAGE_SIZE` for common collection UI
126
+ workflows.
127
+
128
+ ## Development
46
129
 
47
- Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.
130
+ The package source lives in `src/`, and `src/index.ts` is the public entrypoint.
131
+ Published files are generated into `dist/`. See `package.json` for the
132
+ available repository scripts.
48
133
 
49
134
  ## License
50
135