beancount 0.0.31 → 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 +51 -22
  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 +7 -7
@@ -1,28 +1,28 @@
1
1
  import { Temporal } from '@js-temporal/polyfill';
2
- import { EntryType } from '../entryTypeToClass.mjs';
3
- import { Entry } from './Entry.mjs';
4
- import type { Transaction } from './entryTypes/Transaction/index.mjs';
5
- import type { Balance } from './entryTypes/Balance.mjs';
6
- import type { Close } from './entryTypes/Close.mjs';
7
- import type { Commodity } from './entryTypes/Commodity.mjs';
8
- import type { Custom } from './entryTypes/Custom.mjs';
9
- import type { Document } from './entryTypes/Document.mjs';
10
- import type { Event } from './entryTypes/Event.mjs';
11
- import type { Include } from './entryTypes/Include.mjs';
12
- import type { Note } from './entryTypes/Note.mjs';
13
- import type { Open } from './entryTypes/Open.mjs';
14
- import type { Option } from './entryTypes/Option.mjs';
15
- import type { Pad } from './entryTypes/Pad.mjs';
16
- import type { Plugin } from './entryTypes/Plugin.mjs';
17
- import type { Poptag } from './entryTypes/Poptag.mjs';
18
- import type { Price } from './entryTypes/Price.mjs';
19
- import type { Pushtag } from './entryTypes/Pushtag.mjs';
20
- import type { Query } from './entryTypes/Query.mjs';
21
- import type { Comment } from './entryTypes/Comment.mjs';
22
- import type { Blankline } from './entryTypes/Blankline.mjs';
2
+ import { NodeType } from '../nodeTypeToClass.mjs';
3
+ import { Node } from './Node.mjs';
4
+ import type { Transaction } from './nodes/Transaction/index.mjs';
5
+ import type { Balance } from './nodes/Balance.mjs';
6
+ import type { Close } from './nodes/Close.mjs';
7
+ import type { Commodity } from './nodes/Commodity.mjs';
8
+ import type { Custom } from './nodes/Custom.mjs';
9
+ import type { Document } from './nodes/Document.mjs';
10
+ import type { Event } from './nodes/Event.mjs';
11
+ import type { Include } from './nodes/Include.mjs';
12
+ import type { Note } from './nodes/Note.mjs';
13
+ import type { Open } from './nodes/Open.mjs';
14
+ import type { Option } from './nodes/Option.mjs';
15
+ import type { Pad } from './nodes/Pad.mjs';
16
+ import type { Plugin } from './nodes/Plugin.mjs';
17
+ import type { Poptag } from './nodes/Poptag.mjs';
18
+ import type { Price } from './nodes/Price.mjs';
19
+ import type { Pushtag } from './nodes/Pushtag.mjs';
20
+ import type { Query } from './nodes/Query.mjs';
21
+ import type { Comment } from './nodes/Comment.mjs';
22
+ import type { Blankline } from './nodes/Blankline.mjs';
23
23
  export interface ParseResultObj {
24
- entries: {
25
- type: EntryType;
24
+ nodes: {
25
+ type: NodeType;
26
26
  }[];
27
27
  }
28
28
  /**
@@ -47,115 +47,115 @@ export interface CalculateCurrencyColumnOptions {
47
47
  minPadding?: number;
48
48
  }
49
49
  /**
50
- * Container class for parsed Beancount entries.
51
- * Provides methods for converting entries back to string format.
50
+ * Container class for the result of a parse.
51
+ * Provides methods for converting node back to string format.
52
52
  */
53
53
  export declare class ParseResult {
54
- entries: Entry[];
54
+ nodes: Node[];
55
55
  /**
56
56
  * Creates a new ParseResult instance.
57
- * @param entries - Array of parsed Entry objects
57
+ * @param nodes - Array of parsed nodes
58
58
  */
59
- constructor(entries: Entry[]);
59
+ constructor(nodes: Node[]);
60
60
  /**
61
- * Gets all transaction entries from the parsed entries.
62
- * @returns Array of entries that are transactions
61
+ * Gets all transaction nodes from the parsed nodes.
62
+ * @returns Array of nodes that correspond to transaction directives
63
63
  */
64
64
  get transactions(): Transaction[];
65
65
  /**
66
- * Gets all balance entries from the parsed entries.
67
- * @returns Array of entries that are balance directives
66
+ * Gets all balance nodes from the parsed nodes.
67
+ * @returns Array of nodes that correspond to balance directives
68
68
  */
69
69
  get balance(): Balance[];
70
70
  /**
71
- * Gets all close entries from the parsed entries.
72
- * @returns Array of entries that are close directives
71
+ * Gets all close nodes from the parsed nodes.
72
+ * @returns Array of nodes that correspond to close directives
73
73
  */
74
74
  get close(): Close[];
75
75
  /**
76
- * Gets all commodity entries from the parsed entries.
77
- * @returns Array of entries that are commodity directives
76
+ * Gets all commodity nodes from the parsed nodes.
77
+ * @returns Array of nodes that correspond to commodity directives
78
78
  */
79
79
  get commodity(): Commodity[];
80
80
  /**
81
- * Gets all custom entries from the parsed entries.
82
- * @returns Array of entries that are custom directives
81
+ * Gets all custom nodes from the parsed nodes.
82
+ * @returns Array of nodes that correspond to custom directives
83
83
  */
84
84
  get custom(): Custom[];
85
85
  /**
86
- * Gets all document entries from the parsed entries.
87
- * @returns Array of entries that are document directives
86
+ * Gets all document nodes from the parsed nodes.
87
+ * @returns Array of nodes that correspond to document directives
88
88
  */
89
89
  get document(): Document[];
90
90
  /**
91
- * Gets all event entries from the parsed entries.
92
- * @returns Array of entries that are event directives
91
+ * Gets all event nodes from the parsed nodes.
92
+ * @returns Array of nodes that correspond to event directives
93
93
  */
94
94
  get event(): Event[];
95
95
  /**
96
- * Gets all include entries from the parsed entries.
97
- * @returns Array of entries that are include directives
96
+ * Gets all include nodes from the parsed nodes.
97
+ * @returns Array of nodes that correspond to include directives
98
98
  */
99
99
  get include(): Include[];
100
100
  /**
101
- * Gets all note entries from the parsed entries.
102
- * @returns Array of entries that are note directives
101
+ * Gets all note nodes from the parsed nodes.
102
+ * @returns Array of nodes that correspond to note directives
103
103
  */
104
104
  get note(): Note[];
105
105
  /**
106
- * Gets all open entries from the parsed entries.
107
- * @returns Array of entries that are open directives
106
+ * Gets all open nodes from the parsed nodes.
107
+ * @returns Array of nodes that correspond to open directives
108
108
  */
109
109
  get open(): Open[];
110
110
  /**
111
- * Gets all option entries from the parsed entries.
112
- * @returns Array of entries that are option directives
111
+ * Gets all option nodes from the parsed nodes.
112
+ * @returns Array of nodes that correspond to option directives
113
113
  */
114
114
  get option(): Option[];
115
115
  /**
116
- * Gets all pad entries from the parsed entries.
117
- * @returns Array of entries that are pad directives
116
+ * Gets all pad nodes from the parsed nodes.
117
+ * @returns Array of nodes that correspond to pad directives
118
118
  */
119
119
  get pad(): Pad[];
120
120
  /**
121
- * Gets all plugin entries from the parsed entries.
122
- * @returns Array of entries that are plugin directives
121
+ * Gets all plugin nodes from the parsed nodes.
122
+ * @returns Array of nodes that correspond to plugin directives
123
123
  */
124
124
  get plugin(): Plugin[];
125
125
  /**
126
- * Gets all poptag entries from the parsed entries.
127
- * @returns Array of entries that are poptag directives
126
+ * Gets all poptag nodes from the parsed nodes.
127
+ * @returns Array of nodes that correspond to poptag directives
128
128
  */
129
129
  get poptag(): Poptag[];
130
130
  /**
131
- * Gets all price entries from the parsed entries.
132
- * @returns Array of entries that are price directives
131
+ * Gets all price nodes from the parsed nodes.
132
+ * @returns Array of nodes that correspond to price directives
133
133
  */
134
134
  get price(): Price[];
135
135
  /**
136
- * Gets all pushtag entries from the parsed entries.
137
- * @returns Array of entries that are pushtag directives
136
+ * Gets all pushtag nodes from the parsed nodes.
137
+ * @returns Array of nodes that correspond to pushtag directives
138
138
  */
139
139
  get pushtag(): Pushtag[];
140
140
  /**
141
- * Gets all query entries from the parsed entries.
142
- * @returns Array of entries that are query directives
141
+ * Gets all query nodes from the parsed nodes.
142
+ * @returns Array of nodes that correspond to query directives
143
143
  */
144
144
  get query(): Query[];
145
145
  /**
146
- * Gets all comment entries from the parsed entries.
147
- * @returns Array of entries that are comments
146
+ * Gets all comment nodes from the parsed nodes.
147
+ * @returns Array of nodes that correspond to a comments
148
148
  */
149
149
  get comment(): Comment[];
150
150
  /**
151
- * Gets all blankline entries from the parsed entries.
152
- * @returns Array of entries that are blank lines
151
+ * Gets all blankline nodes from the parsed nodes.
152
+ * @returns Array of nodes that correspond to a blank line
153
153
  */
154
154
  get blankline(): Blankline[];
155
155
  /**
156
- * Gets all unique account names used across all entries.
156
+ * Gets all unique account names used across all directives.
157
157
  * Extracts accounts from transactions (via postings), open, close,
158
- * balance, pad, note, and document entries.
158
+ * balance, pad, note, and document nodes.
159
159
  * @returns Set of unique account names
160
160
  */
161
161
  get accounts(): Set<string>;
@@ -170,14 +170,14 @@ export declare class ParseResult {
170
170
  */
171
171
  accountsActiveAt(date: Temporal.PlainDate): Set<string>;
172
172
  /**
173
- * Converts all entries to their string representation.
174
- * Each entry is converted using its toString() method and joined with newlines.
173
+ * Converts all nodes to their string representation.
174
+ * Each node is converted using its toString() method and joined with newlines.
175
175
  * @returns The complete Beancount file content as a string
176
176
  */
177
177
  toString(): string;
178
178
  /**
179
- * Converts all entries to a formatted string with aligned columns.
180
- * Uses each entry's toFormattedString() method for consistent formatting.
179
+ * Converts all nodes to a formatted string with aligned columns.
180
+ * Uses each node's toFormattedString() method for consistent formatting.
181
181
  * @param formatOptions - Formatting options
182
182
  *
183
183
  * @returns The formatted Beancount file content as a string
@@ -194,11 +194,11 @@ export declare class ParseResult {
194
194
  static fromJSON(jsonString: string): ParseResult;
195
195
  /**
196
196
  * Creates a ParseResult instance from a plain JavaScript object.
197
- * Deserializes each entry by mapping it to the appropriate Entry class based on its type.
197
+ * Deserializes each node by mapping it to the appropriate Node class based on its type.
198
198
  *
199
199
  * @param obj - Plain object representation of a ParseResult
200
- * @returns A new ParseResult instance with deserialized entries
201
- * @throws {Error} If an entry has an unknown type with no corresponding entry class
200
+ * @returns A new ParseResult instance with deserialized nodes
201
+ * @throws {Error} If an node has an unknown type with no corresponding node class
202
202
  * @remarks **Warning:** No validation is performed on the input object. We assume the object is valid and well-formed.
203
203
  */
204
204
  static fromJSONData(obj: ParseResultObj): ParseResult;
@@ -1,165 +1,165 @@
1
1
  import { Temporal } from '@js-temporal/polyfill';
2
- import { entryTypeToClass } from '../entryTypeToClass.mjs';
2
+ import { nodeTypeToClass } from '../nodeTypeToClass.mjs';
3
3
  export const defaultFormatOptions = {
4
4
  currencyColumn: 59,
5
5
  };
6
6
  /**
7
- * Container class for parsed Beancount entries.
8
- * Provides methods for converting entries back to string format.
7
+ * Container class for the result of a parse.
8
+ * Provides methods for converting node back to string format.
9
9
  */
10
10
  export class ParseResult {
11
11
  /**
12
12
  * Creates a new ParseResult instance.
13
- * @param entries - Array of parsed Entry objects
13
+ * @param nodes - Array of parsed nodes
14
14
  */
15
- constructor(entries) {
16
- this.entries = entries;
15
+ constructor(nodes) {
16
+ this.nodes = nodes;
17
17
  }
18
18
  /**
19
- * Gets all transaction entries from the parsed entries.
20
- * @returns Array of entries that are transactions
19
+ * Gets all transaction nodes from the parsed nodes.
20
+ * @returns Array of nodes that correspond to transaction directives
21
21
  */
22
22
  get transactions() {
23
- return this.entries.filter((entry) => entry.type === 'transaction');
23
+ return this.nodes.filter((node) => node.type === 'transaction');
24
24
  }
25
25
  /**
26
- * Gets all balance entries from the parsed entries.
27
- * @returns Array of entries that are balance directives
26
+ * Gets all balance nodes from the parsed nodes.
27
+ * @returns Array of nodes that correspond to balance directives
28
28
  */
29
29
  get balance() {
30
- return this.entries.filter((entry) => entry.type === 'balance');
30
+ return this.nodes.filter((node) => node.type === 'balance');
31
31
  }
32
32
  /**
33
- * Gets all close entries from the parsed entries.
34
- * @returns Array of entries that are close directives
33
+ * Gets all close nodes from the parsed nodes.
34
+ * @returns Array of nodes that correspond to close directives
35
35
  */
36
36
  get close() {
37
- return this.entries.filter((entry) => entry.type === 'close');
37
+ return this.nodes.filter((node) => node.type === 'close');
38
38
  }
39
39
  /**
40
- * Gets all commodity entries from the parsed entries.
41
- * @returns Array of entries that are commodity directives
40
+ * Gets all commodity nodes from the parsed nodes.
41
+ * @returns Array of nodes that correspond to commodity directives
42
42
  */
43
43
  get commodity() {
44
- return this.entries.filter((entry) => entry.type === 'commodity');
44
+ return this.nodes.filter((node) => node.type === 'commodity');
45
45
  }
46
46
  /**
47
- * Gets all custom entries from the parsed entries.
48
- * @returns Array of entries that are custom directives
47
+ * Gets all custom nodes from the parsed nodes.
48
+ * @returns Array of nodes that correspond to custom directives
49
49
  */
50
50
  get custom() {
51
- return this.entries.filter((entry) => entry.type === 'custom');
51
+ return this.nodes.filter((node) => node.type === 'custom');
52
52
  }
53
53
  /**
54
- * Gets all document entries from the parsed entries.
55
- * @returns Array of entries that are document directives
54
+ * Gets all document nodes from the parsed nodes.
55
+ * @returns Array of nodes that correspond to document directives
56
56
  */
57
57
  get document() {
58
- return this.entries.filter((entry) => entry.type === 'document');
58
+ return this.nodes.filter((node) => node.type === 'document');
59
59
  }
60
60
  /**
61
- * Gets all event entries from the parsed entries.
62
- * @returns Array of entries that are event directives
61
+ * Gets all event nodes from the parsed nodes.
62
+ * @returns Array of nodes that correspond to event directives
63
63
  */
64
64
  get event() {
65
- return this.entries.filter((entry) => entry.type === 'event');
65
+ return this.nodes.filter((node) => node.type === 'event');
66
66
  }
67
67
  /**
68
- * Gets all include entries from the parsed entries.
69
- * @returns Array of entries that are include directives
68
+ * Gets all include nodes from the parsed nodes.
69
+ * @returns Array of nodes that correspond to include directives
70
70
  */
71
71
  get include() {
72
- return this.entries.filter((entry) => entry.type === 'include');
72
+ return this.nodes.filter((node) => node.type === 'include');
73
73
  }
74
74
  /**
75
- * Gets all note entries from the parsed entries.
76
- * @returns Array of entries that are note directives
75
+ * Gets all note nodes from the parsed nodes.
76
+ * @returns Array of nodes that correspond to note directives
77
77
  */
78
78
  get note() {
79
- return this.entries.filter((entry) => entry.type === 'note');
79
+ return this.nodes.filter((node) => node.type === 'note');
80
80
  }
81
81
  /**
82
- * Gets all open entries from the parsed entries.
83
- * @returns Array of entries that are open directives
82
+ * Gets all open nodes from the parsed nodes.
83
+ * @returns Array of nodes that correspond to open directives
84
84
  */
85
85
  get open() {
86
- return this.entries.filter((entry) => entry.type === 'open');
86
+ return this.nodes.filter((node) => node.type === 'open');
87
87
  }
88
88
  /**
89
- * Gets all option entries from the parsed entries.
90
- * @returns Array of entries that are option directives
89
+ * Gets all option nodes from the parsed nodes.
90
+ * @returns Array of nodes that correspond to option directives
91
91
  */
92
92
  get option() {
93
- return this.entries.filter((entry) => entry.type === 'option');
93
+ return this.nodes.filter((node) => node.type === 'option');
94
94
  }
95
95
  /**
96
- * Gets all pad entries from the parsed entries.
97
- * @returns Array of entries that are pad directives
96
+ * Gets all pad nodes from the parsed nodes.
97
+ * @returns Array of nodes that correspond to pad directives
98
98
  */
99
99
  get pad() {
100
- return this.entries.filter((entry) => entry.type === 'pad');
100
+ return this.nodes.filter((node) => node.type === 'pad');
101
101
  }
102
102
  /**
103
- * Gets all plugin entries from the parsed entries.
104
- * @returns Array of entries that are plugin directives
103
+ * Gets all plugin nodes from the parsed nodes.
104
+ * @returns Array of nodes that correspond to plugin directives
105
105
  */
106
106
  get plugin() {
107
- return this.entries.filter((entry) => entry.type === 'plugin');
107
+ return this.nodes.filter((node) => node.type === 'plugin');
108
108
  }
109
109
  /**
110
- * Gets all poptag entries from the parsed entries.
111
- * @returns Array of entries that are poptag directives
110
+ * Gets all poptag nodes from the parsed nodes.
111
+ * @returns Array of nodes that correspond to poptag directives
112
112
  */
113
113
  get poptag() {
114
- return this.entries.filter((entry) => entry.type === 'poptag');
114
+ return this.nodes.filter((node) => node.type === 'poptag');
115
115
  }
116
116
  /**
117
- * Gets all price entries from the parsed entries.
118
- * @returns Array of entries that are price directives
117
+ * Gets all price nodes from the parsed nodes.
118
+ * @returns Array of nodes that correspond to price directives
119
119
  */
120
120
  get price() {
121
- return this.entries.filter((entry) => entry.type === 'price');
121
+ return this.nodes.filter((node) => node.type === 'price');
122
122
  }
123
123
  /**
124
- * Gets all pushtag entries from the parsed entries.
125
- * @returns Array of entries that are pushtag directives
124
+ * Gets all pushtag nodes from the parsed nodes.
125
+ * @returns Array of nodes that correspond to pushtag directives
126
126
  */
127
127
  get pushtag() {
128
- return this.entries.filter((entry) => entry.type === 'pushtag');
128
+ return this.nodes.filter((node) => node.type === 'pushtag');
129
129
  }
130
130
  /**
131
- * Gets all query entries from the parsed entries.
132
- * @returns Array of entries that are query directives
131
+ * Gets all query nodes from the parsed nodes.
132
+ * @returns Array of nodes that correspond to query directives
133
133
  */
134
134
  get query() {
135
- return this.entries.filter((entry) => entry.type === 'query');
135
+ return this.nodes.filter((node) => node.type === 'query');
136
136
  }
137
137
  /**
138
- * Gets all comment entries from the parsed entries.
139
- * @returns Array of entries that are comments
138
+ * Gets all comment nodes from the parsed nodes.
139
+ * @returns Array of nodes that correspond to a comments
140
140
  */
141
141
  get comment() {
142
- return this.entries.filter((entry) => entry.type === 'comment');
142
+ return this.nodes.filter((node) => node.type === 'comment');
143
143
  }
144
144
  /**
145
- * Gets all blankline entries from the parsed entries.
146
- * @returns Array of entries that are blank lines
145
+ * Gets all blankline nodes from the parsed nodes.
146
+ * @returns Array of nodes that correspond to a blank line
147
147
  */
148
148
  get blankline() {
149
- return this.entries.filter((entry) => entry.type === 'blankline');
149
+ return this.nodes.filter((node) => node.type === 'blankline');
150
150
  }
151
151
  /**
152
- * Gets all unique account names used across all entries.
152
+ * Gets all unique account names used across all directives.
153
153
  * Extracts accounts from transactions (via postings), open, close,
154
- * balance, pad, note, and document entries.
154
+ * balance, pad, note, and document nodes.
155
155
  * @returns Set of unique account names
156
156
  */
157
157
  get accounts() {
158
158
  const accountSet = new Set();
159
- for (const entry of this.entries) {
160
- switch (entry.type) {
159
+ for (const node of this.nodes) {
160
+ switch (node.type) {
161
161
  case 'transaction':
162
- for (const posting of entry.postings) {
162
+ for (const posting of node.postings) {
163
163
  accountSet.add(posting.account);
164
164
  }
165
165
  break;
@@ -168,10 +168,10 @@ export class ParseResult {
168
168
  case 'balance':
169
169
  case 'note':
170
170
  case 'document':
171
- accountSet.add(entry.account);
171
+ accountSet.add(node.account);
172
172
  break;
173
173
  case 'pad': {
174
- const pad = entry;
174
+ const pad = node;
175
175
  accountSet.add(pad.account);
176
176
  accountSet.add(pad.accountPad);
177
177
  break;
@@ -192,13 +192,13 @@ export class ParseResult {
192
192
  accountsActiveAt(date) {
193
193
  const openedAccounts = new Map();
194
194
  const closedAccounts = new Map();
195
- for (const entry of this.entries) {
196
- if (entry.type === 'open') {
197
- const open = entry;
195
+ for (const node of this.nodes) {
196
+ if (node.type === 'open') {
197
+ const open = node;
198
198
  openedAccounts.set(open.account, open.date);
199
199
  }
200
- else if (entry.type === 'close') {
201
- const close = entry;
200
+ else if (node.type === 'close') {
201
+ const close = node;
202
202
  closedAccounts.set(close.account, close.date);
203
203
  }
204
204
  }
@@ -214,25 +214,23 @@ export class ParseResult {
214
214
  return activeSet;
215
215
  }
216
216
  /**
217
- * Converts all entries to their string representation.
218
- * Each entry is converted using its toString() method and joined with newlines.
217
+ * Converts all nodes to their string representation.
218
+ * Each node is converted using its toString() method and joined with newlines.
219
219
  * @returns The complete Beancount file content as a string
220
220
  */
221
221
  toString() {
222
222
  // eslint-disable-next-line @typescript-eslint/no-base-to-string
223
- return this.entries.map((e) => e.toString()).join('\n');
223
+ return this.nodes.map((e) => e.toString()).join('\n');
224
224
  }
225
225
  /**
226
- * Converts all entries to a formatted string with aligned columns.
227
- * Uses each entry's toFormattedString() method for consistent formatting.
226
+ * Converts all nodes to a formatted string with aligned columns.
227
+ * Uses each node's toFormattedString() method for consistent formatting.
228
228
  * @param formatOptions - Formatting options
229
229
  *
230
230
  * @returns The formatted Beancount file content as a string
231
231
  */
232
232
  toFormattedString(formatOptions = defaultFormatOptions) {
233
- return this.entries
234
- .map((e) => e.toFormattedString(formatOptions))
235
- .join('\n');
233
+ return this.nodes.map((e) => e.toFormattedString(formatOptions)).join('\n');
236
234
  }
237
235
  /**
238
236
  * Creates an ParseResult instance from JSON data.
@@ -247,27 +245,27 @@ export class ParseResult {
247
245
  }
248
246
  /**
249
247
  * Creates a ParseResult instance from a plain JavaScript object.
250
- * Deserializes each entry by mapping it to the appropriate Entry class based on its type.
248
+ * Deserializes each node by mapping it to the appropriate Node class based on its type.
251
249
  *
252
250
  * @param obj - Plain object representation of a ParseResult
253
- * @returns A new ParseResult instance with deserialized entries
254
- * @throws {Error} If an entry has an unknown type with no corresponding entry class
251
+ * @returns A new ParseResult instance with deserialized nodes
252
+ * @throws {Error} If an node has an unknown type with no corresponding node class
255
253
  * @remarks **Warning:** No validation is performed on the input object. We assume the object is valid and well-formed.
256
254
  */
257
255
  static fromJSONData(obj) {
258
- const objEntries = obj.entries;
259
- const entries = objEntries.map((objEntry) => {
260
- const { type } = objEntry;
261
- const EntryClass = entryTypeToClass[type];
262
- if (!EntryClass) {
263
- throw new Error(`No entryclass found for type ${type}`);
256
+ const nodeObjects = obj.nodes;
257
+ const nodes = nodeObjects.map((nodeObj) => {
258
+ const { type } = nodeObj;
259
+ const NodeClass = nodeTypeToClass[type];
260
+ if (!NodeClass) {
261
+ throw new Error(`No class found for type ${type} while creating nodes`);
264
262
  }
265
- // Type assertion needed because TypeScript can't verify that all entry classes
263
+ // Type assertion needed because TypeScript can't verify that all node classes
266
264
  // in the union type have compatible constructor signatures
267
265
  // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access
268
- return EntryClass.fromJSONData(objEntry);
266
+ return NodeClass.fromJSONData(nodeObj);
269
267
  });
270
- return new ParseResult(entries);
268
+ return new ParseResult(nodes);
271
269
  }
272
270
  /**
273
271
  * Calculates the optimal currency column position for formatting.
@@ -303,10 +301,10 @@ export class ParseResult {
303
301
  if (transactions.length === 0) {
304
302
  return defaultFormatOptions.currencyColumn;
305
303
  }
306
- // Extract all postings
304
+ // Extract all postings from the transactions
307
305
  const allPostings = [];
308
- for (const entry of transactions) {
309
- allPostings.push(...entry.postings);
306
+ for (const transaction of transactions) {
307
+ allPostings.push(...transaction.postings);
310
308
  }
311
309
  // Edge case: No postings
312
310
  if (allPostings.length === 0) {
@@ -0,0 +1,32 @@
1
+ import type { GenericParseResultWithDate } from '../../genericParse.mjs';
2
+ import { DatedNode } from '../DatedNode.mjs';
3
+ import { FormatOptions } from '../ParseResult.mjs';
4
+ /**
5
+ * Represents a Balance assertion node.
6
+ * Balance directives assert that an account has a specific balance at a given date.
7
+ */
8
+ export declare class Balance extends DatedNode {
9
+ /** @inheritdoc */
10
+ type: "balance";
11
+ /** The account name for the balance assertion */
12
+ account: string;
13
+ /** The expected amount */
14
+ amount: string;
15
+ /** The currency of the amount */
16
+ currency: string;
17
+ /**
18
+ * Gets the formatted price string (amount + currency).
19
+ * @returns The formatted price string
20
+ */
21
+ get price(): string | undefined;
22
+ /**
23
+ * Creates a Balance instance from a generic parse result.
24
+ * @param genericParseResult - The parsed balance entry data
25
+ * @returns A new Balance instance
26
+ */
27
+ static fromGenericParseResult(genericParseResult: GenericParseResultWithDate): Balance;
28
+ /** @inheritdoc */
29
+ toString(): string;
30
+ /** @inheritdoc */
31
+ toFormattedString(formatOptions?: FormatOptions): string;
32
+ }