Skip to main content
Deno 2 is finally here 🎉️
Learn more

Version Deno

What is this?

It’s a “blazingly fastOAI-PMH Version 2.0 API client module for Node.js and Deno.

Install for Node.js

npm i oai_pmh_v2

Note For Node.js users this is an ESM only module. Read more here and maybe here.

Example

// Node.js
import { MaybeArr, OAIPMH, OAIPMHParser } from "oai_pmh_v2";
// Deno
import {
  MaybeArr,
  OAIPMH,
  OAIPMHParser,
} from "https://deno.land/x/oai_pmh_v2/src/mod.ts";

// You can find OAI-PMH providers here (although a lot of them might be non functional):
// https://www.openarchives.org/Register/BrowseSites
const oaiPmh = new OAIPMH({
  baseUrl:
    "http://bibliotecavirtual.asturias.es/i18n/oai/oai_bibliotecavirtual.asturias.es.cmd",
});

const info = await oaiPmh.identify({ signal: AbortSignal.timeout(20000) });

console.log(info);

for await (
  const records of oaiPmh.listRecords<
    {
      Define: "the structure of";
      your: "records";
      like: { so: "!"; Otherwise: { "they're of type": [unknown, "."] } };
      Use: MaybeArr<" to define arrays">;
    }
  >(
    { metadataPrefix: "marc21" },
    { signal: AbortSignal.timeout(17000) },
  )
) {
  console.log(records);
}

Warning Arrays require special attention because in XML there’s no distinction between single element array property or just a property with that element. Properties of type T[] should be defined as T | T[] (import MaybeArr utility type for convenience), and always checked with Array.isArray(), unless absolutely sure the array is always of length 2 or greater.

Note Parsed XML attributes are prefixed with @_, while XML text is parsed into #text property.

Find examples for all methods in examples directory. Some things are only documented via types for now.