Version Deno

What is this?

It's a blazingly fast OAI-PMH Version 2.0 API client module for Node.js and Deno.

Install for Node.js

npm i oai_pmh_v2 fast-xml-parser@^4.0.11

NOTE: fast-xml-parser is an optional dependency, only required if the provided parser OaiPmhParser is used, so if you're not implementing your own parser you need it.

Example:

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

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

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

  console.log(info);
})().catch(console.error);

Define your own types, customize parser options, implement your own parser:

// Define your types
new OaiPmhParser<{
  Identify: Record<string, unknown>;
  GetRecord: Record<string, unknown>;
  ListIdentifiers: unknown[];
  ListMetadataFormats: unknown[];
  ListRecords: MARCRecordUnit[];
  ListSets: unknown[];
}>();

// Custom options
new OaiPmhParser({
  ignoreAttributes: false,
  parseAttributeValue: false,
  parseTagValue: false,
  isArray: (_, jPath) => alwaysArrayPaths.indexOf(jPath) !== -1,
});

// Implement custom parser
import type { OaiPmhParserInterface } from "https://deno.land/x/oai_pmh_v2/src/mod.ts";

export class MyOaiPmhParser<
  TOAIReturnTypes extends DefaultOAIReturnTypes = DefaultOAIReturnTypes,
> implements OaiPmhParserInterface<TOAIReturnTypes> {
  // ...
}

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