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,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
+ }
@@ -0,0 +1,50 @@
1
+ import { assertNodeConstructor } from '../Node.mjs';
2
+ import { DatedNode } from '../DatedNode.mjs';
3
+ import { simpleParseLine } from '../../utils/simpleParseLine.mjs';
4
+ import { formatPrice } from '../../utils/formatPrice.mjs';
5
+ import { defaultFormatOptions } from '../ParseResult.mjs';
6
+ /**
7
+ * Represents a Balance assertion node.
8
+ * Balance directives assert that an account has a specific balance at a given date.
9
+ */
10
+ export class Balance extends DatedNode {
11
+ constructor() {
12
+ super(...arguments);
13
+ /** @inheritdoc */
14
+ this.type = 'balance';
15
+ }
16
+ /**
17
+ * Gets the formatted price string (amount + currency).
18
+ * @returns The formatted price string
19
+ */
20
+ get price() {
21
+ return formatPrice(this.amount, this.currency);
22
+ }
23
+ /**
24
+ * Creates a Balance instance from a generic parse result.
25
+ * @param genericParseResult - The parsed balance entry data
26
+ * @returns A new Balance instance
27
+ */
28
+ static fromGenericParseResult(genericParseResult) {
29
+ const [account, amount, currency] = simpleParseLine(genericParseResult.header);
30
+ return new Balance({
31
+ ...genericParseResult.props,
32
+ account,
33
+ amount,
34
+ currency,
35
+ });
36
+ }
37
+ /** @inheritdoc */
38
+ toString() {
39
+ return this.toFormattedString({ currencyColumn: 0 });
40
+ }
41
+ /** @inheritdoc */
42
+ toFormattedString(formatOptions = defaultFormatOptions) {
43
+ const firstPart = `${this.getDateTypePrefix()} ${this.account}`;
44
+ const paddingLength = formatOptions.currencyColumn - firstPart.length - this.amount.length - 2; // not sure what this is for
45
+ const padding = ' '.repeat(Math.max(1, paddingLength));
46
+ return [firstPart, padding, this.price, this.getMetaDataString()].join('');
47
+ }
48
+ }
49
+ // Ensure class conforms to NodeConstructor pattern
50
+ assertNodeConstructor(Balance);
@@ -0,0 +1,23 @@
1
+ import type { GenericParseResult } from '../../genericParse.mjs';
2
+ import { Node, NodeConstructor } from '../Node.mjs';
3
+ /**
4
+ * Represents a blank line in a Beancount file.
5
+ */
6
+ export declare class Blankline extends Node {
7
+ /** @inheritdoc */
8
+ type: "blankline";
9
+ /**
10
+ * Creates a Blankline instance from a generic parse result.
11
+ * @param _genericParseResult - Unused, blank lines have no content
12
+ * @returns A new Blankline instance
13
+ */
14
+ static fromGenericParseResult(_genericParseResult: GenericParseResult): Blankline;
15
+ /** @inheritdoc */
16
+ toString(): string;
17
+ /**
18
+ * Creates a Blankline instance from a string.
19
+ * @param _input - Unused, blank lines have no content
20
+ * @returns A new Blankline instance
21
+ */
22
+ static fromString<T extends Node>(this: NodeConstructor<T>, _input: string): T;
23
+ }
@@ -0,0 +1,37 @@
1
+ import { assertNodeConstructor, Node } from '../Node.mjs';
2
+ /**
3
+ * Represents a blank line in a Beancount file.
4
+ */
5
+ export class Blankline extends Node {
6
+ constructor() {
7
+ super(...arguments);
8
+ /** @inheritdoc */
9
+ this.type = 'blankline';
10
+ }
11
+ /**
12
+ * Creates a Blankline instance from a generic parse result.
13
+ * @param _genericParseResult - Unused, blank lines have no content
14
+ * @returns A new Blankline instance
15
+ */
16
+ static fromGenericParseResult(
17
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
18
+ _genericParseResult) {
19
+ return new Blankline({});
20
+ }
21
+ /** @inheritdoc */
22
+ toString() {
23
+ return '';
24
+ }
25
+ /**
26
+ * Creates a Blankline instance from a string.
27
+ * @param _input - Unused, blank lines have no content
28
+ * @returns A new Blankline instance
29
+ */
30
+ static fromString(
31
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
32
+ _input) {
33
+ return this.fromGenericParseResult({});
34
+ }
35
+ }
36
+ // Ensure class conforms to NodeConstructor pattern
37
+ assertNodeConstructor(Blankline);
@@ -0,0 +1,20 @@
1
+ import type { GenericParseResultWithDate } from '../../genericParse.mjs';
2
+ import { DatedNode } from '../DatedNode.mjs';
3
+ /**
4
+ * Represents a Close node that closes an account.
5
+ * Close directives mark the end of an account's lifespan.
6
+ */
7
+ export declare class Close extends DatedNode {
8
+ /** @inheritdoc */
9
+ type: "close";
10
+ /** The account name being closed */
11
+ account: string;
12
+ /**
13
+ * Creates a Close instance from a generic parse result.
14
+ * @param genericParseResult - The parsed close node data
15
+ * @returns A new Close instance
16
+ */
17
+ static fromGenericParseResult(genericParseResult: GenericParseResultWithDate): Close;
18
+ /** @inheritdoc */
19
+ toString(): string;
20
+ }
@@ -0,0 +1,31 @@
1
+ import { assertNodeConstructor } from '../Node.mjs';
2
+ import { DatedNode } from '../DatedNode.mjs';
3
+ /**
4
+ * Represents a Close node that closes an account.
5
+ * Close directives mark the end of an account's lifespan.
6
+ */
7
+ export class Close extends DatedNode {
8
+ constructor() {
9
+ super(...arguments);
10
+ /** @inheritdoc */
11
+ this.type = 'close';
12
+ }
13
+ /**
14
+ * Creates a Close instance from a generic parse result.
15
+ * @param genericParseResult - The parsed close node data
16
+ * @returns A new Close instance
17
+ */
18
+ static fromGenericParseResult(genericParseResult) {
19
+ const account = genericParseResult.header.trim();
20
+ return new Close({
21
+ ...genericParseResult.props,
22
+ account,
23
+ });
24
+ }
25
+ /** @inheritdoc */
26
+ toString() {
27
+ return `${this.getDateTypePrefix()} ${this.account}${this.getMetaDataString()}`;
28
+ }
29
+ }
30
+ // Ensure class conforms to NodeConstructor pattern
31
+ assertNodeConstructor(Close);
@@ -0,0 +1,25 @@
1
+ import type { GenericParseResult } from '../../genericParse.mjs';
2
+ import { Node, NodeConstructor } from '../Node.mjs';
3
+ /**
4
+ * Represents a Comment line in a Beancount file.
5
+ * Comments are lines that start with a semicolon or hash and are ignored by the parser.
6
+ */
7
+ export declare class Comment extends Node {
8
+ /** @inheritdoc */
9
+ type: "comment";
10
+ /**
11
+ * Creates a Comment instance from a generic parse result.
12
+ * Note: This doesn't use a real GenericParseResult structure.
13
+ * @param genericParseResult - The parsed comment data
14
+ * @returns A new Comment instance
15
+ */
16
+ static fromGenericParseResult(genericParseResult: GenericParseResult): Comment;
17
+ /** @inheritdoc */
18
+ toString(): string | undefined;
19
+ /**
20
+ * Creates a Comment instance directly from a string.
21
+ * @param input - The comment text
22
+ * @returns A new Comment instance
23
+ */
24
+ static fromString<T extends Node>(this: NodeConstructor<T>, input: string): T;
25
+ }
@@ -0,0 +1,42 @@
1
+ import { assertNodeConstructor, Node } from '../Node.mjs';
2
+ /**
3
+ * Represents a Comment line in a Beancount file.
4
+ * Comments are lines that start with a semicolon or hash and are ignored by the parser.
5
+ */
6
+ export class Comment extends Node {
7
+ constructor() {
8
+ super(...arguments);
9
+ /** @inheritdoc */
10
+ this.type = 'comment';
11
+ }
12
+ /**
13
+ * Creates a Comment instance from a generic parse result.
14
+ * Note: This doesn't use a real GenericParseResult structure.
15
+ * @param genericParseResult - The parsed comment data
16
+ * @returns A new Comment instance
17
+ */
18
+ static fromGenericParseResult(genericParseResult) {
19
+ return new Comment({
20
+ comment: genericParseResult.header,
21
+ });
22
+ }
23
+ /** @inheritdoc */
24
+ toString() {
25
+ return this.comment;
26
+ }
27
+ /**
28
+ * Creates a Comment instance directly from a string.
29
+ * @param input - The comment text
30
+ * @returns A new Comment instance
31
+ */
32
+ static fromString(input) {
33
+ return this.fromGenericParseResult({
34
+ type: 'comment',
35
+ header: input,
36
+ props: {},
37
+ synthetic: true,
38
+ });
39
+ }
40
+ }
41
+ // Ensure class conforms to NodeConstructor pattern
42
+ assertNodeConstructor(Comment);
@@ -0,0 +1,20 @@
1
+ import type { GenericParseResultWithDate } from '../../genericParse.mjs';
2
+ import { DatedNode } from '../DatedNode.mjs';
3
+ /**
4
+ * Represents a Commodity declaration node.
5
+ * Commodity directives declare the existence of a commodity/currency with metadata.
6
+ */
7
+ export declare class Commodity extends DatedNode {
8
+ /** @inheritdoc */
9
+ type: "commodity";
10
+ /** The currency/commodity code being declared */
11
+ currency: string;
12
+ /**
13
+ * Creates a Commodity instance from a generic parse result.
14
+ * @param genericParseResult - The parsed commodity node data
15
+ * @returns A new Commodity instance
16
+ */
17
+ static fromGenericParseResult(genericParseResult: GenericParseResultWithDate): Commodity;
18
+ /** @inheritdoc */
19
+ toString(): string;
20
+ }