Skip to content

Commit 1735ede

Browse files
committed
docs: enhance README with detailed package usage, installation instructions, and API overview
1 parent abe4419 commit 1735ede

1 file changed

Lines changed: 112 additions & 19 deletions

File tree

README.md

Lines changed: 112 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,135 @@
11
# OCHRE SDK
22

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.
412

513
## Installation
614

7-
```bash
8-
pnpm add ochre-sdk
15+
```sh
16+
npm install ochre-sdk
917
```
1018

11-
or
19+
Use the equivalent command for your package manager if you do not use npm.
1220

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.
24+
25+
## Quick Start
26+
27+
```ts
28+
import { fetchItem } from "ochre-sdk";
29+
30+
const result = await fetchItem("<item-uuid>", {
31+
category: "resource",
32+
languages: ["eng"],
33+
});
34+
35+
if (result.error != null) {
36+
throw new Error(result.error);
37+
}
1638

17-
or
39+
console.log(result.item.identification.label.getText("eng"));
40+
```
1841

19-
```bash
20-
bun add ochre-sdk
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();
2176
```
2277

23-
## Build the package
78+
For reusable language tuples, use `defineLanguages` to keep runtime validation
79+
and literal TypeScript inference together.
2480

25-
From the root directory of the project, run the following command:
81+
```ts
82+
import { defineLanguages, fetchWebsite } from "ochre-sdk";
2683

27-
```bash
28-
pnpm run build
84+
const languages = defineLanguages("eng", "tur");
85+
const result = await fetchWebsite("uchicago-node", { languages });
2986
```
3087

31-
## Release new version to NPM
88+
## Set Queries
89+
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+
};
32104

33-
```bash
34-
pnpm run release
105+
const result = await fetchSetItems(
106+
{ setScopeUuids: ["<set-uuid>"], queries, page: 1, pageSize: 48 },
107+
["resource", "bibliography"],
108+
{ languages: ["eng"] },
109+
);
35110
```
36111

37-
## 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
38129

39-
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.
40133

41134
## License
42135

0 commit comments

Comments
 (0)