beancount 0.1.0 → 0.2.0

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.
Files changed (71) hide show
  1. package/README.md +15 -16
  2. package/build/src/benchmark.mjs +1 -1
  3. package/build/src/classes/DatedNode.d.mts +40 -0
  4. package/build/src/classes/DatedNode.mjs +61 -0
  5. package/build/src/classes/Node.d.mts +92 -0
  6. package/build/src/classes/Node.mjs +107 -0
  7. package/build/src/classes/ParseResult.d.mts +75 -75
  8. package/build/src/classes/ParseResult.mjs +96 -98
  9. package/build/src/classes/nodes/Balance.d.mts +32 -0
  10. package/build/src/classes/nodes/Balance.mjs +50 -0
  11. package/build/src/classes/nodes/Blankline.d.mts +23 -0
  12. package/build/src/classes/nodes/Blankline.mjs +37 -0
  13. package/build/src/classes/nodes/Close.d.mts +20 -0
  14. package/build/src/classes/nodes/Close.mjs +31 -0
  15. package/build/src/classes/nodes/Comment.d.mts +25 -0
  16. package/build/src/classes/nodes/Comment.mjs +42 -0
  17. package/build/src/classes/nodes/Commodity.d.mts +20 -0
  18. package/build/src/classes/nodes/Commodity.mjs +31 -0
  19. package/build/src/classes/nodes/Custom.d.mts +23 -0
  20. package/build/src/classes/nodes/Custom.mjs +38 -0
  21. package/build/src/classes/nodes/Document.d.mts +22 -0
  22. package/build/src/classes/nodes/Document.mjs +34 -0
  23. package/build/src/classes/nodes/Event.d.mts +23 -0
  24. package/build/src/classes/nodes/Event.mjs +34 -0
  25. package/build/src/classes/nodes/Include.d.mts +20 -0
  26. package/build/src/classes/nodes/Include.mjs +31 -0
  27. package/build/src/classes/nodes/Note.d.mts +22 -0
  28. package/build/src/classes/nodes/Note.mjs +34 -0
  29. package/build/src/classes/nodes/Open.d.mts +27 -0
  30. package/build/src/classes/nodes/Open.mjs +66 -0
  31. package/build/src/classes/nodes/Option.d.mts +23 -0
  32. package/build/src/classes/nodes/Option.mjs +32 -0
  33. package/build/src/classes/nodes/Pad.d.mts +22 -0
  34. package/build/src/classes/nodes/Pad.mjs +33 -0
  35. package/build/src/classes/nodes/Plugin.d.mts +22 -0
  36. package/build/src/classes/nodes/Plugin.mjs +36 -0
  37. package/build/src/classes/nodes/Poptag.d.mts +21 -0
  38. package/build/src/classes/nodes/Poptag.mjs +34 -0
  39. package/build/src/classes/nodes/Price.d.mts +32 -0
  40. package/build/src/classes/nodes/Price.mjs +57 -0
  41. package/build/src/classes/nodes/Pushtag.d.mts +21 -0
  42. package/build/src/classes/nodes/Pushtag.mjs +34 -0
  43. package/build/src/classes/nodes/Query.d.mts +22 -0
  44. package/build/src/classes/nodes/Query.mjs +34 -0
  45. package/build/src/classes/nodes/Transaction/Posting.d.mts +59 -0
  46. package/build/src/classes/nodes/Transaction/Posting.mjs +97 -0
  47. package/build/src/classes/nodes/Transaction/Tag.d.mts +28 -0
  48. package/build/src/classes/nodes/Transaction/Tag.mjs +28 -0
  49. package/build/src/classes/nodes/Transaction/index.d.mts +70 -0
  50. package/build/src/classes/nodes/Transaction/index.mjs +193 -0
  51. package/build/src/classes/nodes/index.d.mts +19 -0
  52. package/build/src/classes/nodes/index.mjs +19 -0
  53. package/build/src/cli.mjs +4 -4
  54. package/build/src/deserialize.d.mts +54 -54
  55. package/build/src/deserialize.mjs +89 -89
  56. package/build/src/directiveTypes.d.mts +10 -0
  57. package/build/src/directiveTypes.mjs +29 -0
  58. package/build/src/genericParse.d.mts +27 -20
  59. package/build/src/genericParse.mjs +30 -30
  60. package/build/src/main.d.mts +30 -31
  61. package/build/src/main.mjs +30 -30
  62. package/build/src/nodeTypeToClass.d.mts +81 -0
  63. package/build/src/nodeTypeToClass.mjs +37 -0
  64. package/build/src/parse.d.mts +16 -16
  65. package/build/src/parse.mjs +37 -37
  66. package/build/src/parseFile.d.mts +2 -2
  67. package/build/src/parseFile.mjs +11 -11
  68. package/build/src/utils/splitStringIntoSourceFragments.d.ts +14 -0
  69. package/build/src/utils/splitStringIntoSourceFragments.js +48 -0
  70. package/build/tsconfig.build.tsbuildinfo +1 -1
  71. package/package.json +2 -2
@@ -1,27 +1,34 @@
1
- import type { BeancountEntryType, FakeEntryType } from './entryTypeToClass.mjs';
1
+ import type { BeancountDirectiveNodeType, SyntheticNodeType } from './nodeTypeToClass.mjs';
2
2
  import { type Metadata } from './utils/parseMetadata.mjs';
3
3
  /**
4
- * The basic result structure from generic parsing of a Beancount entry.
5
- * Contains the entry type, header line content, and any properties like comments.
4
+ * The basic result structure from generic parsing of a Beancount directive.
5
+ * Contains the directive type, header line content, and any properties like comments.
6
6
  */
7
7
  export interface GenericParseResult {
8
- /** The type of Beancount entry (e.g., 'open', 'close', 'balance') */
9
- type: BeancountEntryType;
10
- /** The main header content from the first line of the entry */
8
+ /** The type of Beancount directive (e.g., 'open', 'close', 'balance') */
9
+ type: BeancountDirectiveNodeType;
10
+ /** The main header content from the first line of the directive */
11
11
  header: string;
12
- /** Properties extracted from the entry */
12
+ /** Properties extracted from the directive */
13
13
  props: {
14
14
  /** Optional comment text following a semicolon */
15
15
  comment?: string;
16
16
  };
17
- fake?: false;
17
+ synthetic?: false;
18
18
  }
19
- export interface GenericParseResultFakeEntry extends Omit<GenericParseResult, 'fake' | 'type'> {
20
- type: FakeEntryType;
21
- fake: true;
19
+ /**
20
+ * Generic parse result for synthetic (non-directive) nodes.
21
+ * These represent content that doesn't correspond to actual Beancount directives,
22
+ * such as comments and blank lines, which are preserved to maintain file structure.
23
+ */
24
+ export interface GenericParseResultSyntheticNode extends Omit<GenericParseResult, 'synthetic' | 'type'> {
25
+ /** The synthetic node type (e.g., 'comment', 'blankline') */
26
+ type: SyntheticNodeType;
27
+ /** Always true to distinguish synthetic nodes from real Beancount directives */
28
+ synthetic: true;
22
29
  }
23
30
  /**
24
- * Generic parse result for entries that include a date field.
31
+ * Generic parse result for directives that include a date field.
25
32
  * Extends the base result with date and metadata properties.
26
33
  */
27
34
  export interface GenericParseResultWithDate extends GenericParseResult {
@@ -34,7 +41,7 @@ export interface GenericParseResultWithDate extends GenericParseResult {
34
41
  };
35
42
  }
36
43
  /**
37
- * Generic parse result specifically for transaction entries.
44
+ * Generic parse result specifically for transaction directives.
38
45
  * Extends the dated result with transaction-specific fields like body lines and flags.
39
46
  */
40
47
  export interface GenericParseResultTransaction extends Omit<GenericParseResultWithDate, 'metadata'> {
@@ -51,16 +58,16 @@ export interface GenericParseResultTransaction extends Omit<GenericParseResultWi
51
58
  };
52
59
  }
53
60
  /**
54
- * Performs generic parsing on an unparsed entry to extract common fields.
61
+ * Performs generic parsing on a source fragment to extract common fields.
55
62
  *
56
63
  * This function:
57
- * - Detects if the entry has a date (YYYY-MM-DD format)
58
- * - Identifies the entry type
64
+ * - Detects if the directive has a date (YYYY-MM-DD format)
65
+ * - Identifies the directive type
59
66
  * - Extracts header content and comments
60
67
  * - Handles transaction-specific parsing (flags, body lines)
61
- * - Parses metadata for dated entries
68
+ * - Parses metadata for dated directives
62
69
  *
63
- * @param unparsedEntry - Array of string tokens representing a single entry
64
- * @returns A generic parse result object appropriate for the entry type
70
+ * @param sourceFragment - Array of strings that should be parsed to a single node
71
+ * @returns A generic parse result object appropriate for the node type
65
72
  */
66
- export declare const genericParse: (unparsedEntry: string[]) => GenericParseResult | GenericParseResultTransaction | GenericParseResultWithDate | GenericParseResultFakeEntry;
73
+ export declare const genericParse: (sourceFragment: string[]) => GenericParseResult | GenericParseResultTransaction | GenericParseResultWithDate | GenericParseResultSyntheticNode;
@@ -1,68 +1,68 @@
1
- import { DATED_ENTRY_TYPES, NON_DATED_ENTRY_TYPES } from './entryTypes.mjs';
1
+ import { DATED_DIRECTIVE_TYPES, NON_DATED_DIRECTIVE_TYPES, } from './directiveTypes.mjs';
2
2
  import { parseMetadata } from './utils/parseMetadata.mjs';
3
3
  /**
4
- * Compiles a regex pattern that validates both date format AND entry type.
4
+ * Compiles a regex pattern that validates both date format AND directive type.
5
5
  *
6
6
  * The generated pattern matches lines starting with:
7
7
  * - Date in YYYY-MM-DD format
8
8
  * - Followed by one or more whitespace characters
9
9
  * - Followed by either:
10
- * - A valid dated entry type keyword from {@link DATED_ENTRY_TYPES}
10
+ * - A valid dated node type keyword from {@link DATED_DIRECTIVE_TYPES}
11
11
  * - A transaction flag (* or !)
12
12
  * - The transaction alias 'txn'
13
13
  * - Followed by a word boundary to prevent partial matches
14
14
  *
15
- * This ensures that only valid Beancount directives with correct entry types
16
- * are recognized. Invalid entry types will be treated as comments.
15
+ * This ensures that only valid Beancount directives with correct node types
16
+ * are recognized. Invalid directive types will be treated as comments.
17
17
  *
18
18
  * Pattern: `^YYYY-MM-DD\s+(validType|[*!]|txn)\b`
19
19
  *
20
- * @returns A RegExp that validates dated entry lines
20
+ * @returns A RegExp that validates dated node lines
21
21
  */
22
- function compileEntryRegex() {
23
- // Join all non dated entry types with | for regex alternation
24
- const nonDatedEntryPattern = NON_DATED_ENTRY_TYPES.join('|');
25
- // Join all dated entry types with | for regex alternation
26
- const datedEntryTypePattern = [
27
- ...DATED_ENTRY_TYPES,
22
+ function compileDirectivePattern() {
23
+ // Join all non dated directive types with | for regex alternation
24
+ const nonDatedDirectivesPattern = NON_DATED_DIRECTIVE_TYPES.join('|');
25
+ // Join all dated directive types with | for regex alternation
26
+ const datedDirectivesTypePattern = [
27
+ ...DATED_DIRECTIVE_TYPES,
28
28
  'txn',
29
29
  '[^ ]' /* flag */,
30
30
  ].join('|');
31
31
  const datePattern = `\\d{4}-\\d{2}-\\d{2}`;
32
- const datedEntryPattern = `${datePattern} +(?:${datedEntryTypePattern})`;
33
- const pattern = `^(?:${nonDatedEntryPattern})|(?:^${datedEntryPattern}) `;
32
+ const datedDirectivesPattern = `${datePattern} +(?:${datedDirectivesTypePattern})`;
33
+ const pattern = `^(?:${nonDatedDirectivesPattern})|(?:^${datedDirectivesPattern}) `;
34
34
  return new RegExp(pattern);
35
35
  }
36
36
  /**
37
- * Regex pattern to identify Beancount entries that start with a date.
38
- * Generated from {@link NON_DATED_ENTRY_TYPES} and {@link DATED_ENTRY_TYPES} to ensure validation of entry types.
37
+ * Regex pattern to identify Beancount directives that start with a date.
38
+ * Generated from {@link NON_DATED_DIRECTIVE_TYPES} and {@link DATED_DIRECTIVE_TYPES} to ensure validation of directive types.
39
39
  */
40
- const beanCountEntryRegex = compileEntryRegex();
40
+ const beanCountDirectiveRegex = compileDirectivePattern();
41
41
  /**
42
- * Performs generic parsing on an unparsed entry to extract common fields.
42
+ * Performs generic parsing on a source fragment to extract common fields.
43
43
  *
44
44
  * This function:
45
- * - Detects if the entry has a date (YYYY-MM-DD format)
46
- * - Identifies the entry type
45
+ * - Detects if the directive has a date (YYYY-MM-DD format)
46
+ * - Identifies the directive type
47
47
  * - Extracts header content and comments
48
48
  * - Handles transaction-specific parsing (flags, body lines)
49
- * - Parses metadata for dated entries
49
+ * - Parses metadata for dated directives
50
50
  *
51
- * @param unparsedEntry - Array of string tokens representing a single entry
52
- * @returns A generic parse result object appropriate for the entry type
51
+ * @param sourceFragment - Array of strings that should be parsed to a single node
52
+ * @returns A generic parse result object appropriate for the node type
53
53
  */
54
- export const genericParse = (unparsedEntry) => {
55
- const [firstLine, ...rest] = unparsedEntry;
54
+ export const genericParse = (sourceFragment) => {
55
+ const [firstLine, ...rest] = sourceFragment;
56
56
  if (firstLine.trim() === '') {
57
- return { type: 'blankline', header: '', props: {}, fake: true };
57
+ return { type: 'blankline', header: '', props: {}, synthetic: true };
58
58
  }
59
- if (!beanCountEntryRegex.test(firstLine)) {
60
- // not a valid beancount entry, return it as a comment
59
+ if (!beanCountDirectiveRegex.test(firstLine)) {
60
+ // not a valid beancount directive, return it as a comment
61
61
  return {
62
62
  type: 'comment',
63
- header: unparsedEntry.join('\n'),
63
+ header: sourceFragment.join('\n'),
64
64
  props: {},
65
- fake: true,
65
+ synthetic: true,
66
66
  };
67
67
  }
68
68
  const splitFirstLine = firstLine.split(' ');
@@ -3,7 +3,7 @@
3
3
  *
4
4
  * @remarks
5
5
  * The primary function you'll use is {@link parse}, which parses a complete Beancount file
6
- * and returns a {@link ParseResult} containing all parsed entries.
6
+ * and returns a {@link ParseResult} containing parsed nodes.
7
7
  *
8
8
  * @example
9
9
  * ```typescript
@@ -17,43 +17,42 @@
17
17
  * `
18
18
  *
19
19
  * const result = parse(beancountContent)
20
- * console.log(result.entries) // Array of parsed Entry objects
20
+ * console.log(result.nodes) // Array of parsed Node objects
21
21
  * ```
22
22
  *
23
23
  * @module
24
24
  */
25
- export { parse, parseEntry } from './parse.mjs';
26
- export { deserializeEntry, deserializeEntryFromString, deserializeEntries, deserializeEntriesFromString, } from './deserialize.mjs';
25
+ export { parse, parseSourceFragment } from './parse.mjs';
26
+ export { deserializeNode, deserializeNodeFromString, deserializeNodes, deserializeNodesFromString, } from './deserialize.mjs';
27
27
  export { parseFile, type ParseFileOptions, type FileSystemHelpers, } from './parseFile.mjs';
28
28
  export type { GenericParseResult, GenericParseResultWithDate, GenericParseResultTransaction, } from './genericParse.mjs';
29
29
  export type { Metadata } from './utils/parseMetadata.mjs';
30
30
  export { ParseResult, type ParseResultObj, type FormatOptions, type CalculateCurrencyColumnOptions, } from './classes/ParseResult.mjs';
31
- export { Entry, assertEntryConstructor } from './classes/Entry.mjs';
32
- export { DateEntry } from './classes/DateEntry.mjs';
33
- export type { BeancountDateEntryType } from './classes/DateEntry.mjs';
31
+ export { Node, assertNodeConstructor } from './classes/Node.mjs';
32
+ export { DatedNode } from './classes/DatedNode.mjs';
34
33
  export { Value } from './classes/Value.mjs';
35
34
  export type { ValueType } from './classes/Value.mjs';
36
- export { Balance } from './classes/entryTypes/Balance.mjs';
37
- export { Blankline } from './classes/entryTypes/Blankline.mjs';
38
- export { Close } from './classes/entryTypes/Close.mjs';
39
- export { Comment } from './classes/entryTypes/Comment.mjs';
40
- export { Commodity } from './classes/entryTypes/Commodity.mjs';
41
- export { Custom } from './classes/entryTypes/Custom.mjs';
42
- export { Document } from './classes/entryTypes/Document.mjs';
43
- export { Event } from './classes/entryTypes/Event.mjs';
44
- export { Include } from './classes/entryTypes/Include.mjs';
45
- export { Note } from './classes/entryTypes/Note.mjs';
46
- export { Open } from './classes/entryTypes/Open.mjs';
47
- export { Option } from './classes/entryTypes/Option.mjs';
48
- export { Pad } from './classes/entryTypes/Pad.mjs';
49
- export { Plugin } from './classes/entryTypes/Plugin.mjs';
50
- export { Poptag } from './classes/entryTypes/Poptag.mjs';
51
- export { Price } from './classes/entryTypes/Price.mjs';
52
- export { Pushtag } from './classes/entryTypes/Pushtag.mjs';
53
- export { Query } from './classes/entryTypes/Query.mjs';
54
- export { Transaction, type PostingComment, } from './classes/entryTypes/Transaction/index.mjs';
55
- export { Posting } from './classes/entryTypes/Transaction/Posting.mjs';
56
- export { Tag } from './classes/entryTypes/Transaction/Tag.mjs';
57
- export type { BeancountEntryType, EntryType, FakeEntryType, BeancountDatedEntryType, BeancountNonDatedEntryType, } from './entryTypeToClass.mjs';
58
- export { beancountEntryToClass, entryTypeToClass } from './entryTypeToClass.mjs';
59
- export { DATED_ENTRY_TYPES, NON_DATED_ENTRY_TYPES } from './entryTypes.mjs';
35
+ export { Balance } from './classes/nodes/Balance.mjs';
36
+ export { Blankline } from './classes/nodes/Blankline.mjs';
37
+ export { Close } from './classes/nodes/Close.mjs';
38
+ export { Comment } from './classes/nodes/Comment.mjs';
39
+ export { Commodity } from './classes/nodes/Commodity.mjs';
40
+ export { Custom } from './classes/nodes/Custom.mjs';
41
+ export { Document } from './classes/nodes/Document.mjs';
42
+ export { Event } from './classes/nodes/Event.mjs';
43
+ export { Include } from './classes/nodes/Include.mjs';
44
+ export { Note } from './classes/nodes/Note.mjs';
45
+ export { Open } from './classes/nodes/Open.mjs';
46
+ export { Option } from './classes/nodes/Option.mjs';
47
+ export { Pad } from './classes/nodes/Pad.mjs';
48
+ export { Plugin } from './classes/nodes/Plugin.mjs';
49
+ export { Poptag } from './classes/nodes/Poptag.mjs';
50
+ export { Price } from './classes/nodes/Price.mjs';
51
+ export { Pushtag } from './classes/nodes/Pushtag.mjs';
52
+ export { Query } from './classes/nodes/Query.mjs';
53
+ export { Transaction, type PostingComment, } from './classes/nodes/Transaction/index.mjs';
54
+ export { Posting } from './classes/nodes/Transaction/Posting.mjs';
55
+ export { Tag } from './classes/nodes/Transaction/Tag.mjs';
56
+ export type { BeancountDirectiveNodeType, NodeType, SyntheticNodeType, DatedDirectiveNodeType, NonDatedDirectiveNodeType, } from './nodeTypeToClass.mjs';
57
+ export { beancountDirectiveNodeTypeToClass, nodeTypeToClass, } from './nodeTypeToClass.mjs';
58
+ export { DATED_DIRECTIVE_TYPES, NON_DATED_DIRECTIVE_TYPES, } from './directiveTypes.mjs';
@@ -3,7 +3,7 @@
3
3
  *
4
4
  * @remarks
5
5
  * The primary function you'll use is {@link parse}, which parses a complete Beancount file
6
- * and returns a {@link ParseResult} containing all parsed entries.
6
+ * and returns a {@link ParseResult} containing parsed nodes.
7
7
  *
8
8
  * @example
9
9
  * ```typescript
@@ -17,42 +17,42 @@
17
17
  * `
18
18
  *
19
19
  * const result = parse(beancountContent)
20
- * console.log(result.entries) // Array of parsed Entry objects
20
+ * console.log(result.nodes) // Array of parsed Node objects
21
21
  * ```
22
22
  *
23
23
  * @module
24
24
  */
25
25
  // Primary parsing functionality
26
- export { parse, parseEntry } from './parse.mjs';
27
- export { deserializeEntry, deserializeEntryFromString, deserializeEntries, deserializeEntriesFromString, } from './deserialize.mjs';
26
+ export { parse, parseSourceFragment } from './parse.mjs';
27
+ export { deserializeNode, deserializeNodeFromString, deserializeNodes, deserializeNodesFromString, } from './deserialize.mjs';
28
28
  export { parseFile, } from './parseFile.mjs';
29
29
  // Core classes
30
30
  export { ParseResult, } from './classes/ParseResult.mjs';
31
- export { Entry, assertEntryConstructor } from './classes/Entry.mjs';
32
- export { DateEntry } from './classes/DateEntry.mjs';
31
+ export { Node, assertNodeConstructor } from './classes/Node.mjs';
32
+ export { DatedNode } from './classes/DatedNode.mjs';
33
33
  export { Value } from './classes/Value.mjs';
34
- // Entry type classes
35
- export { Balance } from './classes/entryTypes/Balance.mjs';
36
- export { Blankline } from './classes/entryTypes/Blankline.mjs';
37
- export { Close } from './classes/entryTypes/Close.mjs';
38
- export { Comment } from './classes/entryTypes/Comment.mjs';
39
- export { Commodity } from './classes/entryTypes/Commodity.mjs';
40
- export { Custom } from './classes/entryTypes/Custom.mjs';
41
- export { Document } from './classes/entryTypes/Document.mjs';
42
- export { Event } from './classes/entryTypes/Event.mjs';
43
- export { Include } from './classes/entryTypes/Include.mjs';
44
- export { Note } from './classes/entryTypes/Note.mjs';
45
- export { Open } from './classes/entryTypes/Open.mjs';
46
- export { Option } from './classes/entryTypes/Option.mjs';
47
- export { Pad } from './classes/entryTypes/Pad.mjs';
48
- export { Plugin } from './classes/entryTypes/Plugin.mjs';
49
- export { Poptag } from './classes/entryTypes/Poptag.mjs';
50
- export { Price } from './classes/entryTypes/Price.mjs';
51
- export { Pushtag } from './classes/entryTypes/Pushtag.mjs';
52
- export { Query } from './classes/entryTypes/Query.mjs';
53
- export { Transaction, } from './classes/entryTypes/Transaction/index.mjs';
34
+ // Node classes
35
+ export { Balance } from './classes/nodes/Balance.mjs';
36
+ export { Blankline } from './classes/nodes/Blankline.mjs';
37
+ export { Close } from './classes/nodes/Close.mjs';
38
+ export { Comment } from './classes/nodes/Comment.mjs';
39
+ export { Commodity } from './classes/nodes/Commodity.mjs';
40
+ export { Custom } from './classes/nodes/Custom.mjs';
41
+ export { Document } from './classes/nodes/Document.mjs';
42
+ export { Event } from './classes/nodes/Event.mjs';
43
+ export { Include } from './classes/nodes/Include.mjs';
44
+ export { Note } from './classes/nodes/Note.mjs';
45
+ export { Open } from './classes/nodes/Open.mjs';
46
+ export { Option } from './classes/nodes/Option.mjs';
47
+ export { Pad } from './classes/nodes/Pad.mjs';
48
+ export { Plugin } from './classes/nodes/Plugin.mjs';
49
+ export { Poptag } from './classes/nodes/Poptag.mjs';
50
+ export { Price } from './classes/nodes/Price.mjs';
51
+ export { Pushtag } from './classes/nodes/Pushtag.mjs';
52
+ export { Query } from './classes/nodes/Query.mjs';
53
+ export { Transaction, } from './classes/nodes/Transaction/index.mjs';
54
54
  // Transaction sub-components
55
- export { Posting } from './classes/entryTypes/Transaction/Posting.mjs';
56
- export { Tag } from './classes/entryTypes/Transaction/Tag.mjs';
57
- export { beancountEntryToClass, entryTypeToClass } from './entryTypeToClass.mjs';
58
- export { DATED_ENTRY_TYPES, NON_DATED_ENTRY_TYPES } from './entryTypes.mjs';
55
+ export { Posting } from './classes/nodes/Transaction/Posting.mjs';
56
+ export { Tag } from './classes/nodes/Transaction/Tag.mjs';
57
+ export { beancountDirectiveNodeTypeToClass, nodeTypeToClass, } from './nodeTypeToClass.mjs';
58
+ export { DATED_DIRECTIVE_TYPES, NON_DATED_DIRECTIVE_TYPES, } from './directiveTypes.mjs';
@@ -0,0 +1,81 @@
1
+ import { Transaction, Balance, Close, Comment, Commodity, Custom, Document, Event, Include, Note, Open, Option, Pad, Plugin, Poptag, Price, Pushtag, Query, Blankline } from './classes/nodes/index.mjs';
2
+ import type { DATED_DIRECTIVE_TYPES, NON_DATED_DIRECTIVE_TYPES } from './directiveTypes.mjs';
3
+ /**
4
+ * Union type of all node types that correspond to a Beancount directive that includes a date field.
5
+ * Derived from {@link DATED_DIRECTIVE_TYPES}.
6
+ */
7
+ export type DatedDirectiveNodeType = (typeof DATED_DIRECTIVE_TYPES)[number];
8
+ /**
9
+ * Union type of all node types that correspond to a Beancount directive type that does NOT include
10
+ * a date field.
11
+ * Derived from {@link NON_DATED_DIRECTIVE_TYPES}.
12
+ */
13
+ export type NonDatedDirectiveNodeType = (typeof NON_DATED_DIRECTIVE_TYPES)[number];
14
+ /**
15
+ * Union type of all node type that corrospond to Beancount directives.
16
+ * Directive types derived from https://beancount.github.io/docs/beancount_language_syntax.html#directives-1
17
+ * Node can have additional synthetic types, see {@link SyntheticNodeType}
18
+ *
19
+ * Derived from {@link DATED_DIRECTIVE_TYPES} and {@link NON_DATED_DIRECTIVE_TYPES}.
20
+ */
21
+ export type BeancountDirectiveNodeType = DatedDirectiveNodeType | NonDatedDirectiveNodeType;
22
+ /**
23
+ * Union type of synthetic node types that are not part of the official Beancount directive syntax.
24
+ *
25
+ * These node types are created during parsing to preserve the complete structure of a Beancount file,
26
+ * enabling lossless round-trip parsing
27
+ */
28
+ export type SyntheticNodeType = 'comment' | 'blankline';
29
+ /**
30
+ * Union type of all valid node type names, that being the beancount directive types and the additional
31
+ * synthetic node types of comment and blankline
32
+ */
33
+ export type NodeType = BeancountDirectiveNodeType | SyntheticNodeType;
34
+ /**
35
+ * Mapping of Beancount directive node type names to their corresponding class constructors.
36
+ * @internal
37
+ */
38
+ export declare const beancountDirectiveNodeTypeToClass: {
39
+ transaction: typeof Transaction;
40
+ balance: typeof Balance;
41
+ close: typeof Close;
42
+ commodity: typeof Commodity;
43
+ custom: typeof Custom;
44
+ document: typeof Document;
45
+ event: typeof Event;
46
+ include: typeof Include;
47
+ note: typeof Note;
48
+ open: typeof Open;
49
+ option: typeof Option;
50
+ pad: typeof Pad;
51
+ plugin: typeof Plugin;
52
+ poptag: typeof Poptag;
53
+ price: typeof Price;
54
+ pushtag: typeof Pushtag;
55
+ query: typeof Query;
56
+ };
57
+ /**
58
+ * Mapping of all node type names (including synthetic) to their corresponding class constructors.
59
+ * @internal
60
+ */
61
+ export declare const nodeTypeToClass: {
62
+ comment: typeof Comment;
63
+ blankline: typeof Blankline;
64
+ transaction: typeof Transaction;
65
+ balance: typeof Balance;
66
+ close: typeof Close;
67
+ commodity: typeof Commodity;
68
+ custom: typeof Custom;
69
+ document: typeof Document;
70
+ event: typeof Event;
71
+ include: typeof Include;
72
+ note: typeof Note;
73
+ open: typeof Open;
74
+ option: typeof Option;
75
+ pad: typeof Pad;
76
+ plugin: typeof Plugin;
77
+ poptag: typeof Poptag;
78
+ price: typeof Price;
79
+ pushtag: typeof Pushtag;
80
+ query: typeof Query;
81
+ };
@@ -0,0 +1,37 @@
1
+ import { Transaction, Balance, Close, Comment, Commodity, Custom, Document, Event, Include, Note, Open, Option, Pad, Plugin, Poptag, Price, Pushtag, Query, Blankline, } from './classes/nodes/index.mjs';
2
+ /**
3
+ * Mapping of Beancount directive node type names to their corresponding class constructors.
4
+ * @internal
5
+ */
6
+ export const beancountDirectiveNodeTypeToClass = {
7
+ transaction: Transaction,
8
+ balance: Balance,
9
+ close: Close,
10
+ commodity: Commodity,
11
+ custom: Custom,
12
+ document: Document,
13
+ event: Event,
14
+ include: Include,
15
+ note: Note,
16
+ open: Open,
17
+ option: Option,
18
+ pad: Pad,
19
+ plugin: Plugin,
20
+ poptag: Poptag,
21
+ price: Price,
22
+ pushtag: Pushtag,
23
+ query: Query,
24
+ };
25
+ // Compile-time assertion: beancountDirectiveNodeTypeToClass must have all BeancountDirectiveNodeType keys
26
+ beancountDirectiveNodeTypeToClass;
27
+ /**
28
+ * Mapping of all node type names (including synthetic) to their corresponding class constructors.
29
+ * @internal
30
+ */
31
+ export const nodeTypeToClass = {
32
+ ...beancountDirectiveNodeTypeToClass,
33
+ comment: Comment,
34
+ blankline: Blankline,
35
+ };
36
+ // Compile-time assertion: nodeTypeToClass must have all NodeType keys
37
+ nodeTypeToClass;
@@ -1,29 +1,29 @@
1
1
  import { ParseResult } from './classes/ParseResult.mjs';
2
- import { Comment, Blankline } from './classes/entryTypes/index.mjs';
2
+ import { Comment, Blankline } from './classes/nodes/index.mjs';
3
3
  /**
4
- * Parses a single unparsed entry into its corresponding Entry class instance.
4
+ * Parses a single source fragment into its corresponding Node class instance.
5
5
  *
6
6
  * This function:
7
- * - Performs generic parsing to determine entry type
8
- * - Instantiates the appropriate Entry subclass
7
+ * - Performs generic parsing to determine node type
8
+ * - Instantiates the appropriate Node subclass
9
9
  * - Handles special cases for comments and blank lines
10
10
  *
11
- * @param unparsedEntry - Array of string tokens representing a single entry
12
- * @returns An Entry instance
11
+ * @param sourceFragment - Array of string tokens that should be parsed to a single node
12
+ * @returns A Node instance
13
13
  */
14
- export declare const parseEntry: (unparsedEntry: string[]) => import("./classes/entryTypes/index.mjs").Transaction | import("./classes/entryTypes/Balance.mjs").Balance | import("./classes/entryTypes/Close.mjs").Close | import("./classes/entryTypes/Commodity.mjs").Commodity | import("./classes/entryTypes/Custom.mjs").Custom | import("./classes/entryTypes/Document.mjs").Document | import("./classes/entryTypes/Event.mjs").Event | import("./classes/entryTypes/Include.mjs").Include | import("./classes/entryTypes/Note.mjs").Note | import("./classes/entryTypes/Open.mjs").Open | import("./classes/entryTypes/Option.mjs").Option | import("./classes/entryTypes/Pad.mjs").Pad | import("./classes/entryTypes/Plugin.mjs").Plugin | import("./classes/entryTypes/Poptag.mjs").Poptag | import("./classes/entryTypes/Price.mjs").Price | import("./classes/entryTypes/Pushtag.mjs").Pushtag | import("./classes/entryTypes/Query.mjs").Query | Comment | Blankline;
14
+ export declare const parseSourceFragment: (sourceFragment: string[]) => import("./classes/nodes/index.mjs").Transaction | import("./classes/nodes/Balance.mjs").Balance | import("./classes/nodes/Close.mjs").Close | import("./classes/nodes/Commodity.mjs").Commodity | import("./classes/nodes/Custom.mjs").Custom | import("./classes/nodes/Document.mjs").Document | import("./classes/nodes/Event.mjs").Event | import("./classes/nodes/Include.mjs").Include | import("./classes/nodes/Note.mjs").Note | import("./classes/nodes/Open.mjs").Open | import("./classes/nodes/Option.mjs").Option | import("./classes/nodes/Pad.mjs").Pad | import("./classes/nodes/Plugin.mjs").Plugin | import("./classes/nodes/Poptag.mjs").Poptag | import("./classes/nodes/Price.mjs").Price | import("./classes/nodes/Pushtag.mjs").Pushtag | import("./classes/nodes/Query.mjs").Query | Comment | Blankline;
15
15
  /**
16
- * Parses a complete Beancount file string into a ParseResult containing Entry objects.
16
+ * Parses a complete Beancount file string into a ParseResult containing Node objects.
17
17
  *
18
18
  * This is the main entry point for parsing Beancount files. It handles:
19
- * - Splitting the input into individual entries
20
- * - Parsing each entry into its appropriate type
21
- * - Managing the tag stack for pushtag/poptag directives
19
+ * - Splitting the source into source fragment
20
+ * - Parsing each source fragment into its appropriate node
21
+ * - Managing the tag stack for pushtag/poptag nodes
22
22
  * - Applying tags from the stack to transactions
23
23
  *
24
24
  * @remarks
25
25
  * This is the primary function you'll use from this library. It takes a Beancount file
26
- * as a string and returns a structured ParseResult object containing all parsed entries.
26
+ * as a string and returns a structured ParseResult object containing the resulting parsed nodes.
27
27
  *
28
28
  * @example
29
29
  * Basic usage:
@@ -38,10 +38,10 @@ export declare const parseEntry: (unparsedEntry: string[]) => import("./classes/
38
38
  * `
39
39
  *
40
40
  * const result = parse(content)
41
- * // result.entries contains parsed Entry objects
41
+ * // result.nodes contains parsed Node objects
42
42
  * ```
43
43
  *
44
- * @param input - The complete Beancount file content as a string
45
- * @returns A ParseResult instance containing all parsed entries
44
+ * @param source - The complete Beancount file content as a string
45
+ * @returns A ParseResult instance containing all parsed nodes
46
46
  */
47
- export declare const parse: (input: string) => ParseResult;
47
+ export declare const parse: (source: string) => ParseResult;