marc-ts 0.1.0 → 0.4.2

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.
@@ -1,4 +1,4 @@
1
- import { MarcRecord, MarcWarning } from './types';
1
+ import { MarcRecord, SerializeBatchResult } from './types';
2
2
  /**
3
3
  * Options for serializing MARC records.
4
4
  */
@@ -11,47 +11,26 @@ export interface SerializeOptions {
11
11
  * to ASCII plus ANSEL Latin/combining characters.
12
12
  */
13
13
  readonly encoding?: 'utf8' | 'marc8';
14
+ /**
15
+ * Maximum number of warnings to collect per record before stopping.
16
+ * Default: 100
17
+ */
18
+ readonly maxWarnings?: number;
14
19
  }
15
20
  /**
16
- * Serialize a MARC record to ISO2709 binary format.
17
- *
18
- * @param record - The MARC record to serialize
19
- * @returns Binary representation of the record (Uint8Array for browser compatibility)
21
+ * Serialize an array of MARC records to a concatenated ISO2709 binary stream.
20
22
  *
21
- * @example
22
- * ```typescript
23
- * const record: MarcRecord = {
24
- * leader: '00000nam 2200000 4500',
25
- * fields: [
26
- * { tag: '001', data: 'ocm12345678' },
27
- * {
28
- * tag: '245',
29
- * indicator1: '1',
30
- * indicator2: '0',
31
- * subfields: [{ code: 'a', value: 'Title' }],
32
- * },
33
- * ],
34
- * };
23
+ * Each record is individually serialized (with its own 0x1D terminator) and
24
+ * the results are concatenated into a single Uint8Array.
35
25
  *
36
- * const buffer = serializeMarcRecord(record);
37
- * // Can now be written to file or transmitted
38
- * ```
26
+ * @param records - MARC records to serialize
27
+ * @param options - Encoding options forwarded to the per-record serializer
28
+ * @returns Concatenated binary representation of all records
39
29
  */
40
- export declare function serializeMarcRecord(record: MarcRecord, options?: SerializeOptions): Uint8Array;
41
- /**
42
- * Result of {@link serializeMarcRecordWithWarnings}: the serialized bytes
43
- * along with any warnings generated by the encoder (e.g. lossy MARC-8
44
- * substitutions).
45
- */
46
- export interface SerializeResult {
47
- readonly bytes: Uint8Array;
48
- readonly warnings: readonly MarcWarning[];
49
- }
30
+ export declare function serializeMarcBinary(records: MarcRecord[], options?: SerializeOptions): Uint8Array;
50
31
  /**
51
- * Serialize a MARC record and surface any warnings generated by the encoder.
52
- * Use this when you need programmatic visibility into lossy encodings — for
53
- * example, MARC-8 output of records containing characters with no MARC-8
54
- * equivalent.
32
+ * Serialize an array of MARC records to a concatenated ISO2709 binary
33
+ * stream, returning per-record serialization warnings.
55
34
  */
56
- export declare function serializeMarcRecordWithWarnings(record: MarcRecord, options?: SerializeOptions): SerializeResult;
35
+ export declare function serializeMarcBinaryWithWarnings(records: MarcRecord[], options?: SerializeOptions): SerializeBatchResult;
57
36
  //# sourceMappingURL=serializer.d.ts.map
@@ -9,4 +9,4 @@ export {
9
9
  i as t
10
10
  };
11
11
 
12
- //# sourceMappingURL=types-c4Mo9m9u.js.map
12
+ //# sourceMappingURL=types-BMKDHD1l.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types-BMKDHD1l.js","names":[],"sources":["../src/types.ts"],"sourcesContent":["/**\n * Core type definitions for MARC21 records.\n * All types use readonly modifiers to enforce immutability.\n */\n\n/**\n * A subfield within a MARC data field.\n * Contains a single-character code and its associated value.\n *\n * @example\n * ```typescript\n * const subfield: Subfield = { code: 'a', value: 'The Catcher in the Rye' };\n * ```\n */\nexport interface Subfield {\n readonly code: string;\n readonly value: string;\n}\n\n/**\n * A MARC control field (tag 00X).\n * Control fields have no indicators or subfields, only a tag and data.\n *\n * @example\n * ```typescript\n * const controlField: ControlField = { tag: '001', data: 'ocm12345678' };\n * ```\n */\nexport interface ControlField {\n readonly tag: string;\n readonly data: string;\n}\n\n/**\n * A MARC data field (tag 01X-9XX).\n * Data fields have a tag, two indicators, and one or more subfields.\n *\n * @example\n * ```typescript\n * const dataField: DataField = {\n * tag: '245',\n * indicator1: '1',\n * indicator2: '0',\n * subfields: [\n * { code: 'a', value: 'The Catcher in the Rye /' },\n * { code: 'c', value: 'J.D. Salinger.' },\n * ],\n * };\n * ```\n */\nexport interface DataField {\n readonly tag: string;\n readonly indicator1: string; // Use ' ' for blank indicator\n readonly indicator2: string; // Use ' ' for blank indicator\n readonly subfields: readonly Subfield[];\n}\n\n/**\n * A complete MARC21 record.\n * Contains a 24-character leader and an array of fields (control or data fields).\n *\n * @example\n * ```typescript\n * const record: MarcRecord = {\n * leader: '00000nam 2200000 4500',\n * fields: [\n * { tag: '001', data: 'ocm12345678' },\n * {\n * tag: '245',\n * indicator1: '1',\n * indicator2: '0',\n * subfields: [{ code: 'a', value: 'Title' }],\n * },\n * ],\n * };\n * ```\n */\nexport interface MarcRecord {\n readonly leader: string; // Always 24 characters\n readonly fields: readonly (ControlField | DataField)[];\n}\n\n/**\n * Warning type categories for MARC parsing errors.\n */\nexport type MarcWarningType =\n | 'invalid_leader'\n | 'invalid_directory'\n | 'invalid_field'\n | 'truncated_record'\n | 'encoding_error'\n | 'malformed_xml'\n | 'missing_element'\n | 'invalid_attribute';\n\n/**\n * A warning generated during MARC record parsing.\n * Warnings indicate non-fatal issues that were encountered and recovered from.\n */\nexport interface MarcWarning {\n readonly type: MarcWarningType;\n readonly message: string;\n readonly position?: number; // Byte position in the record\n readonly tag?: string; // Field tag associated with the warning\n}\n\n/**\n * Options for parsing MARC records.\n */\nexport interface ParseOptions {\n /**\n * If true, throw errors instead of collecting warnings.\n * Default: false\n */\n readonly strict?: boolean;\n\n /**\n * Maximum number of warnings to collect before stopping.\n * Prevents memory issues with severely malformed records.\n * Default: 100\n */\n readonly maxWarnings?: number;\n}\n\n/**\n * Result of parsing a MARC record.\n * Contains the parsed record (if successful) and any warnings encountered.\n */\nexport interface ParseResult {\n readonly record: MarcRecord | null;\n readonly warnings: readonly MarcWarning[];\n}\n\n/**\n * Result of parsing multiple MARC records with warning capture.\n * Each entry pairs a parsed record (or null on failure) with its warnings.\n */\nexport interface ParseBatchResult {\n readonly results: readonly ParseResult[];\n}\n\n/**\n * Result of serializing a single MARC record with warning capture.\n */\nexport interface SerializeRecordResult {\n readonly bytes: Uint8Array;\n readonly warnings: readonly MarcWarning[];\n}\n\n/**\n * Result of serializing multiple MARC records with warning capture.\n * Contains the concatenated bytes and per-record results.\n */\nexport interface SerializeBatchResult {\n readonly bytes: Uint8Array;\n readonly results: readonly SerializeRecordResult[];\n}\n\n/**\n * Type guard to check if a field is a control field.\n *\n * @param field - The field to check\n * @returns True if the field is a control field\n *\n * @example\n * ```typescript\n * if (isControlField(field)) {\n * console.log(field.data); // TypeScript knows field is ControlField\n * }\n * ```\n */\nexport function isControlField(field: ControlField | DataField): field is ControlField {\n return 'data' in field;\n}\n\n/**\n * Type guard to check if a field is a data field.\n *\n * @param field - The field to check\n * @returns True if the field is a data field\n *\n * @example\n * ```typescript\n * if (isDataField(field)) {\n * console.log(field.subfields); // TypeScript knows field is DataField\n * }\n * ```\n */\nexport function isDataField(field: ControlField | DataField): field is DataField {\n return 'subfields' in field;\n}\n"],"mappings":"AA2KA,SAAgB,EAAe,GAAwD;AACrF,SAAO,UAAU;AACnB;AAeA,SAAgB,EAAY,GAAqD;AAC/E,SAAO,eAAe;AACxB"}
@@ -1,3 +1,3 @@
1
1
  function t(e){return"data"in e}function n(e){return"subfields"in e}Object.defineProperty(exports,"isControlField",{enumerable:!0,get:function(){return t}});Object.defineProperty(exports,"isDataField",{enumerable:!0,get:function(){return n}});
2
2
 
3
- //# sourceMappingURL=types-CJcxHJff.cjs.map
3
+ //# sourceMappingURL=types-CsOhH4OF.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types-CsOhH4OF.cjs","names":[],"sources":["../src/types.ts"],"sourcesContent":["/**\n * Core type definitions for MARC21 records.\n * All types use readonly modifiers to enforce immutability.\n */\n\n/**\n * A subfield within a MARC data field.\n * Contains a single-character code and its associated value.\n *\n * @example\n * ```typescript\n * const subfield: Subfield = { code: 'a', value: 'The Catcher in the Rye' };\n * ```\n */\nexport interface Subfield {\n readonly code: string;\n readonly value: string;\n}\n\n/**\n * A MARC control field (tag 00X).\n * Control fields have no indicators or subfields, only a tag and data.\n *\n * @example\n * ```typescript\n * const controlField: ControlField = { tag: '001', data: 'ocm12345678' };\n * ```\n */\nexport interface ControlField {\n readonly tag: string;\n readonly data: string;\n}\n\n/**\n * A MARC data field (tag 01X-9XX).\n * Data fields have a tag, two indicators, and one or more subfields.\n *\n * @example\n * ```typescript\n * const dataField: DataField = {\n * tag: '245',\n * indicator1: '1',\n * indicator2: '0',\n * subfields: [\n * { code: 'a', value: 'The Catcher in the Rye /' },\n * { code: 'c', value: 'J.D. Salinger.' },\n * ],\n * };\n * ```\n */\nexport interface DataField {\n readonly tag: string;\n readonly indicator1: string; // Use ' ' for blank indicator\n readonly indicator2: string; // Use ' ' for blank indicator\n readonly subfields: readonly Subfield[];\n}\n\n/**\n * A complete MARC21 record.\n * Contains a 24-character leader and an array of fields (control or data fields).\n *\n * @example\n * ```typescript\n * const record: MarcRecord = {\n * leader: '00000nam 2200000 4500',\n * fields: [\n * { tag: '001', data: 'ocm12345678' },\n * {\n * tag: '245',\n * indicator1: '1',\n * indicator2: '0',\n * subfields: [{ code: 'a', value: 'Title' }],\n * },\n * ],\n * };\n * ```\n */\nexport interface MarcRecord {\n readonly leader: string; // Always 24 characters\n readonly fields: readonly (ControlField | DataField)[];\n}\n\n/**\n * Warning type categories for MARC parsing errors.\n */\nexport type MarcWarningType =\n | 'invalid_leader'\n | 'invalid_directory'\n | 'invalid_field'\n | 'truncated_record'\n | 'encoding_error'\n | 'malformed_xml'\n | 'missing_element'\n | 'invalid_attribute';\n\n/**\n * A warning generated during MARC record parsing.\n * Warnings indicate non-fatal issues that were encountered and recovered from.\n */\nexport interface MarcWarning {\n readonly type: MarcWarningType;\n readonly message: string;\n readonly position?: number; // Byte position in the record\n readonly tag?: string; // Field tag associated with the warning\n}\n\n/**\n * Options for parsing MARC records.\n */\nexport interface ParseOptions {\n /**\n * If true, throw errors instead of collecting warnings.\n * Default: false\n */\n readonly strict?: boolean;\n\n /**\n * Maximum number of warnings to collect before stopping.\n * Prevents memory issues with severely malformed records.\n * Default: 100\n */\n readonly maxWarnings?: number;\n}\n\n/**\n * Result of parsing a MARC record.\n * Contains the parsed record (if successful) and any warnings encountered.\n */\nexport interface ParseResult {\n readonly record: MarcRecord | null;\n readonly warnings: readonly MarcWarning[];\n}\n\n/**\n * Result of parsing multiple MARC records with warning capture.\n * Each entry pairs a parsed record (or null on failure) with its warnings.\n */\nexport interface ParseBatchResult {\n readonly results: readonly ParseResult[];\n}\n\n/**\n * Result of serializing a single MARC record with warning capture.\n */\nexport interface SerializeRecordResult {\n readonly bytes: Uint8Array;\n readonly warnings: readonly MarcWarning[];\n}\n\n/**\n * Result of serializing multiple MARC records with warning capture.\n * Contains the concatenated bytes and per-record results.\n */\nexport interface SerializeBatchResult {\n readonly bytes: Uint8Array;\n readonly results: readonly SerializeRecordResult[];\n}\n\n/**\n * Type guard to check if a field is a control field.\n *\n * @param field - The field to check\n * @returns True if the field is a control field\n *\n * @example\n * ```typescript\n * if (isControlField(field)) {\n * console.log(field.data); // TypeScript knows field is ControlField\n * }\n * ```\n */\nexport function isControlField(field: ControlField | DataField): field is ControlField {\n return 'data' in field;\n}\n\n/**\n * Type guard to check if a field is a data field.\n *\n * @param field - The field to check\n * @returns True if the field is a data field\n *\n * @example\n * ```typescript\n * if (isDataField(field)) {\n * console.log(field.subfields); // TypeScript knows field is DataField\n * }\n * ```\n */\nexport function isDataField(field: ControlField | DataField): field is DataField {\n return 'subfields' in field;\n}\n"],"mappings":"AA2KA,SAAgB,EAAe,EAAwD,CACrF,MAAO,SAAU,CACnB,CAeA,SAAgB,EAAY,EAAqD,CAC/E,MAAO,cAAe,CACxB"}
package/dist/types.d.ts CHANGED
@@ -78,7 +78,7 @@ export interface MarcRecord {
78
78
  /**
79
79
  * Warning type categories for MARC parsing errors.
80
80
  */
81
- export type MarcWarningType = 'invalid_leader' | 'invalid_directory' | 'invalid_field' | 'truncated_record' | 'encoding_error';
81
+ export type MarcWarningType = 'invalid_leader' | 'invalid_directory' | 'invalid_field' | 'truncated_record' | 'encoding_error' | 'malformed_xml' | 'missing_element' | 'invalid_attribute';
82
82
  /**
83
83
  * A warning generated during MARC record parsing.
84
84
  * Warnings indicate non-fatal issues that were encountered and recovered from.
@@ -113,6 +113,28 @@ export interface ParseResult {
113
113
  readonly record: MarcRecord | null;
114
114
  readonly warnings: readonly MarcWarning[];
115
115
  }
116
+ /**
117
+ * Result of parsing multiple MARC records with warning capture.
118
+ * Each entry pairs a parsed record (or null on failure) with its warnings.
119
+ */
120
+ export interface ParseBatchResult {
121
+ readonly results: readonly ParseResult[];
122
+ }
123
+ /**
124
+ * Result of serializing a single MARC record with warning capture.
125
+ */
126
+ export interface SerializeRecordResult {
127
+ readonly bytes: Uint8Array;
128
+ readonly warnings: readonly MarcWarning[];
129
+ }
130
+ /**
131
+ * Result of serializing multiple MARC records with warning capture.
132
+ * Contains the concatenated bytes and per-record results.
133
+ */
134
+ export interface SerializeBatchResult {
135
+ readonly bytes: Uint8Array;
136
+ readonly results: readonly SerializeRecordResult[];
137
+ }
116
138
  /**
117
139
  * Type guard to check if a field is a control field.
118
140
  *
@@ -0,0 +1,3 @@
1
+ function u(e,n,r,t){return{type:e,message:n,position:r,tag:t}}Object.defineProperty(exports,"createWarning",{enumerable:!0,get:function(){return u}});
2
+
3
+ //# sourceMappingURL=warnings-6yoB06xI.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"warnings-6yoB06xI.cjs","names":[],"sources":["../src/warnings.ts"],"sourcesContent":["/**\n * Warning system for MARC parsing.\n * Re-exports types and provides utility functions.\n */\n\nimport type { MarcWarning, MarcWarningType } from './types';\n\n/**\n * Create a warning object.\n *\n * @param type - The warning type\n * @param message - The warning message\n * @param position - Optional byte position in the record\n * @param tag - Optional field tag associated with the warning\n * @returns A MarcWarning object\n *\n * @example\n * ```typescript\n * const warning = createWarning(\n * 'invalid_leader',\n * 'Leader length is invalid',\n * 0,\n * undefined\n * );\n * ```\n */\nexport function createWarning(\n type: MarcWarningType,\n message: string,\n position?: number,\n tag?: string\n): MarcWarning {\n return { type, message, position, tag };\n}\n"],"mappings":"AA0BA,SAAgB,EACd,EACA,EACA,EACA,EACa,CACb,MAAO,CAAE,KAAA,EAAM,QAAA,EAAS,SAAA,EAAU,IAAA,CAAI,CACxC"}
@@ -0,0 +1,13 @@
1
+ function a(n, r, t, e) {
2
+ return {
3
+ type: n,
4
+ message: r,
5
+ position: t,
6
+ tag: e
7
+ };
8
+ }
9
+ export {
10
+ a as t
11
+ };
12
+
13
+ //# sourceMappingURL=warnings-Bt6wvWFe.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"warnings-Bt6wvWFe.js","names":[],"sources":["../src/warnings.ts"],"sourcesContent":["/**\n * Warning system for MARC parsing.\n * Re-exports types and provides utility functions.\n */\n\nimport type { MarcWarning, MarcWarningType } from './types';\n\n/**\n * Create a warning object.\n *\n * @param type - The warning type\n * @param message - The warning message\n * @param position - Optional byte position in the record\n * @param tag - Optional field tag associated with the warning\n * @returns A MarcWarning object\n *\n * @example\n * ```typescript\n * const warning = createWarning(\n * 'invalid_leader',\n * 'Leader length is invalid',\n * 0,\n * undefined\n * );\n * ```\n */\nexport function createWarning(\n type: MarcWarningType,\n message: string,\n position?: number,\n tag?: string\n): MarcWarning {\n return { type, message, position, tag };\n}\n"],"mappings":"AA0BA,SAAgB,EACd,GACA,GACA,GACA,GACa;AACb,SAAO;AAAA,IAAE,MAAA;AAAA,IAAM,SAAA;AAAA,IAAS,UAAA;AAAA,IAAU,KAAA;AAAA,EAAI;AACxC"}
@@ -1,5 +1,4 @@
1
- import { MarcWarning, MarcWarningType, ParseOptions, ParseResult } from './types';
2
- export type { MarcWarning, MarcWarningType, ParseOptions, ParseResult };
1
+ import { MarcWarning, MarcWarningType } from './types';
3
2
  /**
4
3
  * Create a warning object.
5
4
  *
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "marc-ts",
3
- "version": "0.1.0",
3
+ "version": "0.4.2",
4
4
  "description": "TypeScript MARC21 library for Node.js and browsers",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",
@@ -69,7 +69,7 @@
69
69
  },
70
70
  "homepage": "https://github.com/jamesrf/marc-ts#readme",
71
71
  "engines": {
72
- "node": ">=20.19.0"
72
+ "node": ">=24"
73
73
  },
74
74
  "browser": {
75
75
  "buffer": false
@@ -1 +0,0 @@
1
- {"version":3,"file":"types-CJcxHJff.cjs","names":[],"sources":["../src/types.ts"],"sourcesContent":["/**\n * Core type definitions for MARC21 records.\n * All types use readonly modifiers to enforce immutability.\n */\n\n/**\n * A subfield within a MARC data field.\n * Contains a single-character code and its associated value.\n *\n * @example\n * ```typescript\n * const subfield: Subfield = { code: 'a', value: 'The Catcher in the Rye' };\n * ```\n */\nexport interface Subfield {\n readonly code: string;\n readonly value: string;\n}\n\n/**\n * A MARC control field (tag 00X).\n * Control fields have no indicators or subfields, only a tag and data.\n *\n * @example\n * ```typescript\n * const controlField: ControlField = { tag: '001', data: 'ocm12345678' };\n * ```\n */\nexport interface ControlField {\n readonly tag: string;\n readonly data: string;\n}\n\n/**\n * A MARC data field (tag 01X-9XX).\n * Data fields have a tag, two indicators, and one or more subfields.\n *\n * @example\n * ```typescript\n * const dataField: DataField = {\n * tag: '245',\n * indicator1: '1',\n * indicator2: '0',\n * subfields: [\n * { code: 'a', value: 'The Catcher in the Rye /' },\n * { code: 'c', value: 'J.D. Salinger.' },\n * ],\n * };\n * ```\n */\nexport interface DataField {\n readonly tag: string;\n readonly indicator1: string; // Use ' ' for blank indicator\n readonly indicator2: string; // Use ' ' for blank indicator\n readonly subfields: readonly Subfield[];\n}\n\n/**\n * A complete MARC21 record.\n * Contains a 24-character leader and an array of fields (control or data fields).\n *\n * @example\n * ```typescript\n * const record: MarcRecord = {\n * leader: '00000nam 2200000 4500',\n * fields: [\n * { tag: '001', data: 'ocm12345678' },\n * {\n * tag: '245',\n * indicator1: '1',\n * indicator2: '0',\n * subfields: [{ code: 'a', value: 'Title' }],\n * },\n * ],\n * };\n * ```\n */\nexport interface MarcRecord {\n readonly leader: string; // Always 24 characters\n readonly fields: readonly (ControlField | DataField)[];\n}\n\n/**\n * Warning type categories for MARC parsing errors.\n */\nexport type MarcWarningType =\n | 'invalid_leader'\n | 'invalid_directory'\n | 'invalid_field'\n | 'truncated_record'\n | 'encoding_error';\n\n/**\n * A warning generated during MARC record parsing.\n * Warnings indicate non-fatal issues that were encountered and recovered from.\n */\nexport interface MarcWarning {\n readonly type: MarcWarningType;\n readonly message: string;\n readonly position?: number; // Byte position in the record\n readonly tag?: string; // Field tag associated with the warning\n}\n\n/**\n * Options for parsing MARC records.\n */\nexport interface ParseOptions {\n /**\n * If true, throw errors instead of collecting warnings.\n * Default: false\n */\n readonly strict?: boolean;\n\n /**\n * Maximum number of warnings to collect before stopping.\n * Prevents memory issues with severely malformed records.\n * Default: 100\n */\n readonly maxWarnings?: number;\n}\n\n/**\n * Result of parsing a MARC record.\n * Contains the parsed record (if successful) and any warnings encountered.\n */\nexport interface ParseResult {\n readonly record: MarcRecord | null;\n readonly warnings: readonly MarcWarning[];\n}\n\n/**\n * Type guard to check if a field is a control field.\n *\n * @param field - The field to check\n * @returns True if the field is a control field\n *\n * @example\n * ```typescript\n * if (isControlField(field)) {\n * console.log(field.data); // TypeScript knows field is ControlField\n * }\n * ```\n */\nexport function isControlField(field: ControlField | DataField): field is ControlField {\n return 'data' in field;\n}\n\n/**\n * Type guard to check if a field is a data field.\n *\n * @param field - The field to check\n * @returns True if the field is a data field\n *\n * @example\n * ```typescript\n * if (isDataField(field)) {\n * console.log(field.subfields); // TypeScript knows field is DataField\n * }\n * ```\n */\nexport function isDataField(field: ControlField | DataField): field is DataField {\n return 'subfields' in field;\n}\n"],"mappings":"AA+IA,SAAgB,EAAe,EAAwD,CACrF,MAAO,SAAU,CACnB,CAeA,SAAgB,EAAY,EAAqD,CAC/E,MAAO,cAAe,CACxB"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"types-c4Mo9m9u.js","names":[],"sources":["../src/types.ts"],"sourcesContent":["/**\n * Core type definitions for MARC21 records.\n * All types use readonly modifiers to enforce immutability.\n */\n\n/**\n * A subfield within a MARC data field.\n * Contains a single-character code and its associated value.\n *\n * @example\n * ```typescript\n * const subfield: Subfield = { code: 'a', value: 'The Catcher in the Rye' };\n * ```\n */\nexport interface Subfield {\n readonly code: string;\n readonly value: string;\n}\n\n/**\n * A MARC control field (tag 00X).\n * Control fields have no indicators or subfields, only a tag and data.\n *\n * @example\n * ```typescript\n * const controlField: ControlField = { tag: '001', data: 'ocm12345678' };\n * ```\n */\nexport interface ControlField {\n readonly tag: string;\n readonly data: string;\n}\n\n/**\n * A MARC data field (tag 01X-9XX).\n * Data fields have a tag, two indicators, and one or more subfields.\n *\n * @example\n * ```typescript\n * const dataField: DataField = {\n * tag: '245',\n * indicator1: '1',\n * indicator2: '0',\n * subfields: [\n * { code: 'a', value: 'The Catcher in the Rye /' },\n * { code: 'c', value: 'J.D. Salinger.' },\n * ],\n * };\n * ```\n */\nexport interface DataField {\n readonly tag: string;\n readonly indicator1: string; // Use ' ' for blank indicator\n readonly indicator2: string; // Use ' ' for blank indicator\n readonly subfields: readonly Subfield[];\n}\n\n/**\n * A complete MARC21 record.\n * Contains a 24-character leader and an array of fields (control or data fields).\n *\n * @example\n * ```typescript\n * const record: MarcRecord = {\n * leader: '00000nam 2200000 4500',\n * fields: [\n * { tag: '001', data: 'ocm12345678' },\n * {\n * tag: '245',\n * indicator1: '1',\n * indicator2: '0',\n * subfields: [{ code: 'a', value: 'Title' }],\n * },\n * ],\n * };\n * ```\n */\nexport interface MarcRecord {\n readonly leader: string; // Always 24 characters\n readonly fields: readonly (ControlField | DataField)[];\n}\n\n/**\n * Warning type categories for MARC parsing errors.\n */\nexport type MarcWarningType =\n | 'invalid_leader'\n | 'invalid_directory'\n | 'invalid_field'\n | 'truncated_record'\n | 'encoding_error';\n\n/**\n * A warning generated during MARC record parsing.\n * Warnings indicate non-fatal issues that were encountered and recovered from.\n */\nexport interface MarcWarning {\n readonly type: MarcWarningType;\n readonly message: string;\n readonly position?: number; // Byte position in the record\n readonly tag?: string; // Field tag associated with the warning\n}\n\n/**\n * Options for parsing MARC records.\n */\nexport interface ParseOptions {\n /**\n * If true, throw errors instead of collecting warnings.\n * Default: false\n */\n readonly strict?: boolean;\n\n /**\n * Maximum number of warnings to collect before stopping.\n * Prevents memory issues with severely malformed records.\n * Default: 100\n */\n readonly maxWarnings?: number;\n}\n\n/**\n * Result of parsing a MARC record.\n * Contains the parsed record (if successful) and any warnings encountered.\n */\nexport interface ParseResult {\n readonly record: MarcRecord | null;\n readonly warnings: readonly MarcWarning[];\n}\n\n/**\n * Type guard to check if a field is a control field.\n *\n * @param field - The field to check\n * @returns True if the field is a control field\n *\n * @example\n * ```typescript\n * if (isControlField(field)) {\n * console.log(field.data); // TypeScript knows field is ControlField\n * }\n * ```\n */\nexport function isControlField(field: ControlField | DataField): field is ControlField {\n return 'data' in field;\n}\n\n/**\n * Type guard to check if a field is a data field.\n *\n * @param field - The field to check\n * @returns True if the field is a data field\n *\n * @example\n * ```typescript\n * if (isDataField(field)) {\n * console.log(field.subfields); // TypeScript knows field is DataField\n * }\n * ```\n */\nexport function isDataField(field: ControlField | DataField): field is DataField {\n return 'subfields' in field;\n}\n"],"mappings":"AA+IA,SAAgB,EAAe,GAAwD;AACrF,SAAO,UAAU;AACnB;AAeA,SAAgB,EAAY,GAAqD;AAC/E,SAAO,eAAe;AACxB"}