import { XmlElement } from '@biblioteksentralen/xml-utils'; import { z } from 'zod'; import { ErrorObject } from 'ajv'; type SerializedMarcField = SerializedDataField | SerializedControlField; interface SerializedControlField { tag: string; value: string; } interface SerializedDataField { tag: string; ind1?: string; ind2?: string; subfields: SerializedMarcSubfield[]; } interface SerializedMarcSubfield { code: string; value: string; } declare class Subfield { readonly code: string; readonly value: string; constructor(code: string, value: string); toJSON(): SerializedMarcSubfield; toString(): string; } declare class ControlField { readonly tag: string; readonly value: string; constructor(tag: string, value: string); toJSON(): SerializedControlField; toString(): string; } declare class DataField { readonly tag: string; readonly ind1: string | undefined; readonly ind2: string | undefined; readonly subfields: Subfield[]; constructor(tag: string, ind1: string | undefined, ind2: string | undefined, subfields: Subfield[]); getSubfields(code?: string | RegExp): Subfield[]; getFirstSubfield(code: string | RegExp): Subfield | undefined; getFirstSubfieldValue(code: string | RegExp): string | undefined; toJSON(): SerializedDataField; /** * Returns a human-readable string representation of this MARC data field. * * The result is intended for debugging, logging, and test output. The format is not guaranteed to * be stable and should not be parsed or relied upon. */ toString(): string; } type MarcField = ControlField | DataField; declare const createDataField: (field: SerializedDataField) => DataField; declare const createControlField: (field: SerializedControlField) => ControlField; type Indicators = { ind1?: string; ind2?: string; }; interface SerializedMarcRecord { /** * Identifies the MARC format (examples: "MARC 21", "UNIMARC", "danMARC2", ...). */ format?: string; /** * Corresponds to ISO 2709 record label, 24 bytes */ leader: string; /** * List of control fields and data fields. */ fields: SerializedMarcField[]; } declare class MarcRecord { readonly format: string | undefined; readonly leader: string; readonly fields: MarcField[]; constructor({ leader, fields, format, }: { leader: string; fields: MarcField[]; format?: string; }); static fromJSON(data: unknown): MarcRecord; toJSON(): SerializedMarcRecord; toXML(pretty?: boolean): string; toXmlElement(): XmlElement; toLineMarc(): string; static validateJSON(data: unknown): SerializedMarcRecord; getControlFields(): ControlField[]; getControlField(tag: string): ControlField | undefined; getDataFields(tag?: string | RegExp, indicators?: Indicators): DataField[]; getFirstDataField(tag: string | RegExp, indicators?: Indicators): DataField | undefined; getSubfields(tag: string | RegExp, code: string | RegExp, indicators?: Indicators): Subfield[]; getSubfieldValues(tag: string | RegExp, code: string | RegExp, indicators?: Indicators): string[]; getFirstSubfieldValue(tag: string | RegExp, code: string | RegExp, indicators?: Indicators): string | undefined; /** * Returns a new MarcRecord without control fields matching the given predicate, without modifying * the original one. */ withoutControlFields(predicate: (field: ControlField) => boolean): MarcRecord; /** * Returns a new MarcRecord without data fields matching the given predicate, without modifying * the original one. */ withoutDataFields(predicate: (field: DataField) => boolean): MarcRecord; /** * Returns a new MarcRecord with the given fields added without modifying the original one. */ withFields(fields: MarcField[]): MarcRecord; } interface MarcXmlOptions { namespace?: string; /** * Callback function to transform or filter control fields. */ processControlField?: (field: ControlField) => ControlField | undefined; /** * Callback function to transform or filter data fields. */ processDataField?: (field: DataField) => DataField | undefined; /** * Free-form string that specifies the MARC record flavour. */ format?: string; /** * Whether to require at least one field to be present. Defaults to true. */ requireFields?: boolean; /** * If set to true, the parser throws an error if a record is missing indicators or have empty * fields or subfields. If set to false, it will set default values for missing indicators and * skip empty fields and subfields. Defaults to false. */ strict?: boolean; } declare function parseMarcXml(input: string | XmlElement, options?: MarcXmlOptions): Promise; declare const marcRecordZodSchema: z.ZodObject<{ format: z.ZodOptional; leader: z.ZodString; fields: z.ZodArray, z.ZodObject<{ tag: z.ZodString; ind1: z.ZodOptional; ind2: z.ZodOptional; subfields: z.ZodArray>; }, z.core.$strip>]>>; }, z.core.$strip>; type SerializeLineMarcOptions = { /** * Replacement character to use for $ characters in field values. * Defaults to `@{2}` */ dollarEscapeCharacter: string; }; declare function serializeLineMarc(input: MarcRecord, options?: Partial): string; declare function serializeMarcXml(input: MarcRecord, pretty?: boolean): string; declare function serializeMarcXmlCollection(input: MarcRecord[], pretty?: boolean): string; declare class MarcRecordSchemaValidationError extends Error { readonly errors: ErrorObject[]; readonly sourceData?: string | undefined; constructor(errors: ErrorObject[], sourceData?: string | undefined); } declare class MarcParseError extends Error { readonly record: string; constructor(message: string, record: string); } export { ControlField, DataField, type MarcField, MarcParseError, MarcRecord, MarcRecordSchemaValidationError, type SerializedControlField, type SerializedDataField, type SerializedMarcField, type SerializedMarcRecord, Subfield, createControlField, createDataField, marcRecordZodSchema, parseMarcXml, serializeLineMarc, serializeMarcXml, serializeMarcXmlCollection };