beancount 0.2.4 → 0.2.6
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.
- package/build/src/classes/Node.mjs +7 -7
- package/build/src/classes/nodes/Blankline.mjs +2 -6
- package/build/src/classes/nodes/Transaction/Posting.mjs +1 -1
- package/build/src/genericParse.d.mts +8 -2
- package/build/src/genericParse.mjs +19 -20
- package/build/src/main.d.mts +1 -1
- package/build/src/parse.mjs +1 -1
- package/build/src/utils/SourceLocation.d.mts +27 -4
- package/build/src/utils/splitStringIntoSourceFragments.d.ts +1 -1
- package/build/src/utils/splitStringIntoSourceFragments.js +63 -11
- package/build/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +7 -7
- package/build/src/classes/DateEntry.d.mts +0 -47
- package/build/src/classes/DateEntry.mjs +0 -60
- package/build/src/classes/Entry.d.mts +0 -92
- package/build/src/classes/Entry.mjs +0 -107
- package/build/src/classes/entryTypes/Balance.d.mts +0 -32
- package/build/src/classes/entryTypes/Balance.mjs +0 -50
- package/build/src/classes/entryTypes/Blankline.d.mts +0 -24
- package/build/src/classes/entryTypes/Blankline.mjs +0 -38
- package/build/src/classes/entryTypes/Close.d.mts +0 -20
- package/build/src/classes/entryTypes/Close.mjs +0 -31
- package/build/src/classes/entryTypes/Comment.d.mts +0 -25
- package/build/src/classes/entryTypes/Comment.mjs +0 -42
- package/build/src/classes/entryTypes/Commodity.d.mts +0 -20
- package/build/src/classes/entryTypes/Commodity.mjs +0 -31
- package/build/src/classes/entryTypes/Custom.d.mts +0 -23
- package/build/src/classes/entryTypes/Custom.mjs +0 -38
- package/build/src/classes/entryTypes/Document.d.mts +0 -22
- package/build/src/classes/entryTypes/Document.mjs +0 -34
- package/build/src/classes/entryTypes/Event.d.mts +0 -23
- package/build/src/classes/entryTypes/Event.mjs +0 -34
- package/build/src/classes/entryTypes/Include.d.mts +0 -20
- package/build/src/classes/entryTypes/Include.mjs +0 -31
- package/build/src/classes/entryTypes/Note.d.mts +0 -22
- package/build/src/classes/entryTypes/Note.mjs +0 -34
- package/build/src/classes/entryTypes/Open.d.mts +0 -27
- package/build/src/classes/entryTypes/Open.mjs +0 -66
- package/build/src/classes/entryTypes/Option.d.mts +0 -23
- package/build/src/classes/entryTypes/Option.mjs +0 -32
- package/build/src/classes/entryTypes/Pad.d.mts +0 -22
- package/build/src/classes/entryTypes/Pad.mjs +0 -33
- package/build/src/classes/entryTypes/Plugin.d.mts +0 -22
- package/build/src/classes/entryTypes/Plugin.mjs +0 -36
- package/build/src/classes/entryTypes/Poptag.d.mts +0 -21
- package/build/src/classes/entryTypes/Poptag.mjs +0 -34
- package/build/src/classes/entryTypes/Price.d.mts +0 -32
- package/build/src/classes/entryTypes/Price.mjs +0 -57
- package/build/src/classes/entryTypes/Pushtag.d.mts +0 -21
- package/build/src/classes/entryTypes/Pushtag.mjs +0 -34
- package/build/src/classes/entryTypes/Query.d.mts +0 -22
- package/build/src/classes/entryTypes/Query.mjs +0 -34
- package/build/src/classes/entryTypes/Transaction/Posting.d.mts +0 -59
- package/build/src/classes/entryTypes/Transaction/Posting.mjs +0 -97
- package/build/src/classes/entryTypes/Transaction/Tag.d.mts +0 -28
- package/build/src/classes/entryTypes/Transaction/Tag.mjs +0 -28
- package/build/src/classes/entryTypes/Transaction/index.d.mts +0 -70
- package/build/src/classes/entryTypes/Transaction/index.mjs +0 -193
- package/build/src/classes/entryTypes/index.d.mts +0 -19
- package/build/src/classes/entryTypes/index.mjs +0 -19
- package/build/src/entryTypeToClass.d.mts +0 -73
- package/build/src/entryTypeToClass.mjs +0 -37
- package/build/src/entryTypes.d.mts +0 -10
- package/build/src/entryTypes.mjs +0 -29
- package/build/src/utils/splitStringIntoUnparsedEntries.d.ts +0 -14
- package/build/src/utils/splitStringIntoUnparsedEntries.js +0 -48
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Represents a tag associated with a transaction.
|
|
3
|
-
* Tags can be specified inline in the transaction or inherited from a tag stack (pushtag/poptag).
|
|
4
|
-
*/
|
|
5
|
-
export declare class Tag {
|
|
6
|
-
/** The tag name/content (without the '#' prefix) */
|
|
7
|
-
content: string;
|
|
8
|
-
/** Whether this tag comes from the tag stack (pushtag) or is inline */
|
|
9
|
-
fromStack: boolean;
|
|
10
|
-
/**
|
|
11
|
-
* Creates a new Tag instance.
|
|
12
|
-
* @param obj - Object containing tag content and source information
|
|
13
|
-
* @param obj.content - The tag name/content
|
|
14
|
-
* @param obj.fromStack - Whether this tag is from the tag stack
|
|
15
|
-
*/
|
|
16
|
-
constructor(obj: {
|
|
17
|
-
content: string;
|
|
18
|
-
fromStack: boolean;
|
|
19
|
-
});
|
|
20
|
-
/**
|
|
21
|
-
* Converts this tag to its string representation.
|
|
22
|
-
* Tags from the stack return an empty string (they're implicit),
|
|
23
|
-
* while inline tags return '#tagname' format.
|
|
24
|
-
*
|
|
25
|
-
* @returns The tag string with '#' prefix, or empty string if from stack
|
|
26
|
-
*/
|
|
27
|
-
toString(): string;
|
|
28
|
-
}
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Represents a tag associated with a transaction.
|
|
3
|
-
* Tags can be specified inline in the transaction or inherited from a tag stack (pushtag/poptag).
|
|
4
|
-
*/
|
|
5
|
-
export class Tag {
|
|
6
|
-
/**
|
|
7
|
-
* Creates a new Tag instance.
|
|
8
|
-
* @param obj - Object containing tag content and source information
|
|
9
|
-
* @param obj.content - The tag name/content
|
|
10
|
-
* @param obj.fromStack - Whether this tag is from the tag stack
|
|
11
|
-
*/
|
|
12
|
-
constructor(obj) {
|
|
13
|
-
Object.assign(this, obj);
|
|
14
|
-
}
|
|
15
|
-
/**
|
|
16
|
-
* Converts this tag to its string representation.
|
|
17
|
-
* Tags from the stack return an empty string (they're implicit),
|
|
18
|
-
* while inline tags return '#tagname' format.
|
|
19
|
-
*
|
|
20
|
-
* @returns The tag string with '#' prefix, or empty string if from stack
|
|
21
|
-
*/
|
|
22
|
-
toString() {
|
|
23
|
-
if (this.fromStack) {
|
|
24
|
-
return '';
|
|
25
|
-
}
|
|
26
|
-
return `#${this.content}`;
|
|
27
|
-
}
|
|
28
|
-
}
|
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
import { Temporal } from '@js-temporal/polyfill';
|
|
2
|
-
import type { GenericParseResultTransaction } from '../../../genericParse.mjs';
|
|
3
|
-
import { DateEntry } from '../../DateEntry.mjs';
|
|
4
|
-
import { Posting } from './Posting.mjs';
|
|
5
|
-
import { Tag } from './Tag.mjs';
|
|
6
|
-
import { FormatOptions } from '../../ParseResult.mjs';
|
|
7
|
-
export interface PostingComment {
|
|
8
|
-
order: number;
|
|
9
|
-
comment: string;
|
|
10
|
-
}
|
|
11
|
-
/**
|
|
12
|
-
* Represents a Beancount transaction entry.
|
|
13
|
-
* Transactions record financial movements between accounts with postings.
|
|
14
|
-
*/
|
|
15
|
-
export declare class Transaction extends DateEntry {
|
|
16
|
-
/** @inheritdoc */
|
|
17
|
-
type: "transaction";
|
|
18
|
-
/** The payee of the transaction */
|
|
19
|
-
payee: string;
|
|
20
|
-
/** Optional narration/description of the transaction */
|
|
21
|
-
narration?: string;
|
|
22
|
-
/** Optional transaction flag (e.g., '*' for cleared, '!' for pending) */
|
|
23
|
-
flag?: string;
|
|
24
|
-
/** Array of postings (account movements) in this transaction */
|
|
25
|
-
postings: Posting[];
|
|
26
|
-
/** Array of comments under this transaction (mixed in with the postings) */
|
|
27
|
-
postingComments: PostingComment[];
|
|
28
|
-
/** Set of link identifiers associated with this transaction */
|
|
29
|
-
links: Set<string>;
|
|
30
|
-
/** Array of tags associated with this transaction (from inline tags and tag stack) */
|
|
31
|
-
tags: Tag[];
|
|
32
|
-
/**
|
|
33
|
-
* @inheritdoc
|
|
34
|
-
*/
|
|
35
|
-
constructor(obj: {
|
|
36
|
-
date: string | Temporal.PlainDate;
|
|
37
|
-
[key: string]: unknown;
|
|
38
|
-
});
|
|
39
|
-
/**
|
|
40
|
-
* Creates a Transaction instance from a generic parse result.
|
|
41
|
-
* Parses payee, narration, links, tags, postings, and metadata.
|
|
42
|
-
*
|
|
43
|
-
* @param genericParseResult - The parsed transaction data
|
|
44
|
-
* @returns A new Transaction instance
|
|
45
|
-
*/
|
|
46
|
-
static fromGenericParseResult(genericParseResult: GenericParseResultTransaction): Transaction;
|
|
47
|
-
/** @inheritdoc */
|
|
48
|
-
toString(): string;
|
|
49
|
-
/** @inheritdoc */
|
|
50
|
-
toFormattedString(formatOptions?: FormatOptions): string;
|
|
51
|
-
/**
|
|
52
|
-
* Converts this transaction to a JSON-serializable object.
|
|
53
|
-
* Ensures the links Set is properly serialized as an array.
|
|
54
|
-
*
|
|
55
|
-
* @returns A JSON-serializable representation of this transaction
|
|
56
|
-
*/
|
|
57
|
-
toJSON(): Record<string, unknown>;
|
|
58
|
-
/**
|
|
59
|
-
* Transforms JSON data before creating a Transaction instance.
|
|
60
|
-
* Deserializes transaction-specific properties including postings, tags, links, and metadata.
|
|
61
|
-
*
|
|
62
|
-
* @param json - The JSON data to transform
|
|
63
|
-
* @returns The transformed data with:
|
|
64
|
-
* - postings converted to Posting instances
|
|
65
|
-
* - tags converted to Tag instances
|
|
66
|
-
* - links converted from array to Set<string>
|
|
67
|
-
* - metadata values converted to Value instances
|
|
68
|
-
*/
|
|
69
|
-
protected parseJSONData(json: Record<string, unknown>): Record<string, unknown>;
|
|
70
|
-
}
|
|
@@ -1,193 +0,0 @@
|
|
|
1
|
-
import { assertEntryConstructor } from '../../Entry.mjs';
|
|
2
|
-
import { DateEntry } from '../../DateEntry.mjs';
|
|
3
|
-
import { stringAwareParseLine } from '../../../utils/stringAwareParseLine.mjs';
|
|
4
|
-
import { parseString, Value } from '../../Value.mjs';
|
|
5
|
-
import { parseMetadata } from '../../../utils/parseMetadata.mjs';
|
|
6
|
-
import { Posting } from './Posting.mjs';
|
|
7
|
-
import { Tag } from './Tag.mjs';
|
|
8
|
-
import { defaultFormatOptions } from '../../ParseResult.mjs';
|
|
9
|
-
/**
|
|
10
|
-
* Valid Beancount account type prefixes.
|
|
11
|
-
* @internal
|
|
12
|
-
*/
|
|
13
|
-
const AccountTypes = ['Assets', 'Liabilities', 'Equity', 'Income', 'Expenses'];
|
|
14
|
-
/**
|
|
15
|
-
* Parses a string to extract narration/payee, links, and tags.
|
|
16
|
-
* Links are prefixed with '^' and tags with '#'.
|
|
17
|
-
*
|
|
18
|
-
* @param input - The string to parse (may contain narration in quotes, links, and tags)
|
|
19
|
-
* @returns An object containing extracted links, tags, and the remaining string (narration/payee)
|
|
20
|
-
* @internal
|
|
21
|
-
*/
|
|
22
|
-
const getStringLinksAndTags = (input) => {
|
|
23
|
-
let links = new Set();
|
|
24
|
-
let tags = [];
|
|
25
|
-
// default if no narration
|
|
26
|
-
let strRemaining = '';
|
|
27
|
-
let linksAndTags = input;
|
|
28
|
-
// check for narration
|
|
29
|
-
const match = /^(".*")(.*)/.exec(input);
|
|
30
|
-
if (match) {
|
|
31
|
-
// strRemaining = narration
|
|
32
|
-
strRemaining = match[1];
|
|
33
|
-
linksAndTags = match[2];
|
|
34
|
-
}
|
|
35
|
-
const linksMatch = linksAndTags.matchAll(/\^([\w-_.]*)/g);
|
|
36
|
-
if (linksMatch) {
|
|
37
|
-
links = new Set(linksMatch.map((m) => m[1]));
|
|
38
|
-
}
|
|
39
|
-
const tagsMatch = linksAndTags.matchAll(/#([\w-_.]*)/g);
|
|
40
|
-
if (tagsMatch) {
|
|
41
|
-
tags = tagsMatch
|
|
42
|
-
.map((m) => new Tag({ content: m[1], fromStack: false }))
|
|
43
|
-
.toArray();
|
|
44
|
-
}
|
|
45
|
-
return { links, tags, string: strRemaining };
|
|
46
|
-
};
|
|
47
|
-
/**
|
|
48
|
-
* Represents a Beancount transaction entry.
|
|
49
|
-
* Transactions record financial movements between accounts with postings.
|
|
50
|
-
*/
|
|
51
|
-
export class Transaction extends DateEntry {
|
|
52
|
-
/**
|
|
53
|
-
* @inheritdoc
|
|
54
|
-
*/
|
|
55
|
-
constructor(obj) {
|
|
56
|
-
/*
|
|
57
|
-
* This constructor exists to provide a default value for some values.
|
|
58
|
-
* Class field initializers (e.g., `postingComments = []`) run after
|
|
59
|
-
* `super()` returns, which would overwrite values set by `Object.assign`
|
|
60
|
-
* in the parent constructor.
|
|
61
|
-
*/
|
|
62
|
-
super(obj);
|
|
63
|
-
/** @inheritdoc */
|
|
64
|
-
this.type = 'transaction';
|
|
65
|
-
this.postingComments ??= [];
|
|
66
|
-
this.postings ??= [];
|
|
67
|
-
this.links ??= new Set();
|
|
68
|
-
this.tags ??= [];
|
|
69
|
-
}
|
|
70
|
-
/**
|
|
71
|
-
* Creates a Transaction instance from a generic parse result.
|
|
72
|
-
* Parses payee, narration, links, tags, postings, and metadata.
|
|
73
|
-
*
|
|
74
|
-
* @param genericParseResult - The parsed transaction data
|
|
75
|
-
* @returns A new Transaction instance
|
|
76
|
-
*/
|
|
77
|
-
static fromGenericParseResult(genericParseResult) {
|
|
78
|
-
// eslint-disable-next-line prefer-const
|
|
79
|
-
let [payee, ...rest] = stringAwareParseLine(genericParseResult.header);
|
|
80
|
-
let links = new Set();
|
|
81
|
-
let tags = [];
|
|
82
|
-
let narration;
|
|
83
|
-
if (rest.length === 0) {
|
|
84
|
-
// no narration
|
|
85
|
-
const payeeParsed = getStringLinksAndTags(payee);
|
|
86
|
-
payee = payeeParsed.string;
|
|
87
|
-
links = payeeParsed.links;
|
|
88
|
-
tags = payeeParsed.tags;
|
|
89
|
-
}
|
|
90
|
-
else {
|
|
91
|
-
const payeeParsed = getStringLinksAndTags(rest.join(' '));
|
|
92
|
-
narration = payeeParsed.string;
|
|
93
|
-
links = payeeParsed.links;
|
|
94
|
-
tags = payeeParsed.tags;
|
|
95
|
-
}
|
|
96
|
-
const unparsedPostings = [];
|
|
97
|
-
const unparsedMetadata = [];
|
|
98
|
-
const postingComments = [];
|
|
99
|
-
genericParseResult.body.forEach((line) => {
|
|
100
|
-
// V remove flag, V get account type
|
|
101
|
-
const accountType = line.replace(/^[^ ] /, '').split(':')[0];
|
|
102
|
-
if (AccountTypes.includes(accountType)) {
|
|
103
|
-
unparsedPostings.push(line);
|
|
104
|
-
}
|
|
105
|
-
else if (line.startsWith(';')) {
|
|
106
|
-
postingComments.push({
|
|
107
|
-
comment: line,
|
|
108
|
-
order: unparsedPostings.length + postingComments.length,
|
|
109
|
-
});
|
|
110
|
-
}
|
|
111
|
-
else {
|
|
112
|
-
unparsedMetadata.push(line);
|
|
113
|
-
}
|
|
114
|
-
});
|
|
115
|
-
const postings = unparsedPostings.map((p) => Posting.fromString(p));
|
|
116
|
-
const metadata = parseMetadata(unparsedMetadata);
|
|
117
|
-
return new Transaction({
|
|
118
|
-
...genericParseResult.props,
|
|
119
|
-
payee: parseString(payee),
|
|
120
|
-
narration: narration ? parseString(narration) : undefined,
|
|
121
|
-
postings,
|
|
122
|
-
postingComments,
|
|
123
|
-
metadata,
|
|
124
|
-
links,
|
|
125
|
-
tags,
|
|
126
|
-
});
|
|
127
|
-
}
|
|
128
|
-
/** @inheritdoc */
|
|
129
|
-
toString() {
|
|
130
|
-
return this.toFormattedString({ currencyColumn: 0 });
|
|
131
|
-
}
|
|
132
|
-
/** @inheritdoc */
|
|
133
|
-
toFormattedString(formatOptions = defaultFormatOptions) {
|
|
134
|
-
const firstLine = [
|
|
135
|
-
this.date.toJSON(),
|
|
136
|
-
this.flag ?? 'txn',
|
|
137
|
-
`"${this.payee}"`,
|
|
138
|
-
];
|
|
139
|
-
if (this.narration !== undefined) {
|
|
140
|
-
firstLine.push(`"${this.narration}"`);
|
|
141
|
-
}
|
|
142
|
-
firstLine.push(...this.links.values().map((l) => `^${l}`));
|
|
143
|
-
firstLine.push(...this.tags.map((t) => t.toString()));
|
|
144
|
-
const lines = [firstLine.join(' ') + this.getMetaDataString()];
|
|
145
|
-
const postingLines = this.postings.map((p) => ` ${p.toFormattedString(formatOptions)}`);
|
|
146
|
-
this.postingComments.forEach((comment) => {
|
|
147
|
-
postingLines.splice(comment.order, 0, ` ${comment.comment}`);
|
|
148
|
-
});
|
|
149
|
-
lines.push(...postingLines);
|
|
150
|
-
return lines.join('\n');
|
|
151
|
-
}
|
|
152
|
-
/**
|
|
153
|
-
* Converts this transaction to a JSON-serializable object.
|
|
154
|
-
* Ensures the links Set is properly serialized as an array.
|
|
155
|
-
*
|
|
156
|
-
* @returns A JSON-serializable representation of this transaction
|
|
157
|
-
*/
|
|
158
|
-
toJSON() {
|
|
159
|
-
return {
|
|
160
|
-
...this,
|
|
161
|
-
links: Array.from(this.links),
|
|
162
|
-
};
|
|
163
|
-
}
|
|
164
|
-
/**
|
|
165
|
-
* Transforms JSON data before creating a Transaction instance.
|
|
166
|
-
* Deserializes transaction-specific properties including postings, tags, links, and metadata.
|
|
167
|
-
*
|
|
168
|
-
* @param json - The JSON data to transform
|
|
169
|
-
* @returns The transformed data with:
|
|
170
|
-
* - postings converted to Posting instances
|
|
171
|
-
* - tags converted to Tag instances
|
|
172
|
-
* - links converted from array to Set<string>
|
|
173
|
-
* - metadata values converted to Value instances
|
|
174
|
-
*/
|
|
175
|
-
parseJSONData(json) {
|
|
176
|
-
const { postings, postingComments, tags, links, metadata, ...rest } = json;
|
|
177
|
-
return {
|
|
178
|
-
...rest,
|
|
179
|
-
postings: postings?.map((p) => new Posting(p)),
|
|
180
|
-
postingComments: postingComments ?? [],
|
|
181
|
-
tags: tags?.map((t) => new Tag(t)),
|
|
182
|
-
links: links ? new Set(links) : new Set(),
|
|
183
|
-
metadata: metadata
|
|
184
|
-
? Object.fromEntries(Object.entries(metadata).map(([key, val]) => [
|
|
185
|
-
key,
|
|
186
|
-
new Value(val),
|
|
187
|
-
]))
|
|
188
|
-
: undefined,
|
|
189
|
-
};
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
// Ensure class conforms to EntryConstructor pattern
|
|
193
|
-
assertEntryConstructor(Transaction);
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
export { Transaction } from './Transaction/index.mjs';
|
|
2
|
-
export { Balance } from './Balance.mjs';
|
|
3
|
-
export { Blankline } from './Blankline.mjs';
|
|
4
|
-
export { Close } from './Close.mjs';
|
|
5
|
-
export { Comment } from './Comment.mjs';
|
|
6
|
-
export { Commodity } from './Commodity.mjs';
|
|
7
|
-
export { Custom } from './Custom.mjs';
|
|
8
|
-
export { Document } from './Document.mjs';
|
|
9
|
-
export { Event } from './Event.mjs';
|
|
10
|
-
export { Include } from './Include.mjs';
|
|
11
|
-
export { Note } from './Note.mjs';
|
|
12
|
-
export { Open } from './Open.mjs';
|
|
13
|
-
export { Option } from './Option.mjs';
|
|
14
|
-
export { Pad } from './Pad.mjs';
|
|
15
|
-
export { Plugin } from './Plugin.mjs';
|
|
16
|
-
export { Price } from './Price.mjs';
|
|
17
|
-
export { Poptag } from './Poptag.mjs';
|
|
18
|
-
export { Pushtag } from './Pushtag.mjs';
|
|
19
|
-
export { Query } from './Query.mjs';
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
export { Transaction } from './Transaction/index.mjs';
|
|
2
|
-
export { Balance } from './Balance.mjs';
|
|
3
|
-
export { Blankline } from './Blankline.mjs';
|
|
4
|
-
export { Close } from './Close.mjs';
|
|
5
|
-
export { Comment } from './Comment.mjs';
|
|
6
|
-
export { Commodity } from './Commodity.mjs';
|
|
7
|
-
export { Custom } from './Custom.mjs';
|
|
8
|
-
export { Document } from './Document.mjs';
|
|
9
|
-
export { Event } from './Event.mjs';
|
|
10
|
-
export { Include } from './Include.mjs';
|
|
11
|
-
export { Note } from './Note.mjs';
|
|
12
|
-
export { Open } from './Open.mjs';
|
|
13
|
-
export { Option } from './Option.mjs';
|
|
14
|
-
export { Pad } from './Pad.mjs';
|
|
15
|
-
export { Plugin } from './Plugin.mjs';
|
|
16
|
-
export { Price } from './Price.mjs';
|
|
17
|
-
export { Poptag } from './Poptag.mjs';
|
|
18
|
-
export { Pushtag } from './Pushtag.mjs';
|
|
19
|
-
export { Query } from './Query.mjs';
|
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
import { Transaction, Balance, Close, Comment, Commodity, Custom, Document, Event, Include, Note, Open, Option, Pad, Plugin, Poptag, Price, Pushtag, Query, Blankline } from './classes/entryTypes/index.mjs';
|
|
2
|
-
import type { DATED_ENTRY_TYPES, NON_DATED_ENTRY_TYPES } from './entryTypes.mjs';
|
|
3
|
-
/**
|
|
4
|
-
* Union type of all Beancount entry types that include a date field.
|
|
5
|
-
* Derived from {@link DATED_ENTRY_TYPES}.
|
|
6
|
-
*/
|
|
7
|
-
export type BeancountDatedEntryType = (typeof DATED_ENTRY_TYPES)[number];
|
|
8
|
-
/**
|
|
9
|
-
* Union type of all Beancount entry types that do NOT include a date field.
|
|
10
|
-
* Derived from {@link NON_DATED_ENTRY_TYPES}.
|
|
11
|
-
*/
|
|
12
|
-
export type BeancountNonDatedEntryType = (typeof NON_DATED_ENTRY_TYPES)[number];
|
|
13
|
-
/**
|
|
14
|
-
* Union type of all valid Beancount entry type names.
|
|
15
|
-
* EntryTypes derived from https://beancount.github.io/docs/beancount_language_syntax.html#directives-1
|
|
16
|
-
* Entries can have two additional 'fake' types: 'comment' and 'blankline', see {@link EntryType}
|
|
17
|
-
*
|
|
18
|
-
* Derived from {@link DATED_ENTRY_TYPES} and {@link NON_DATED_ENTRY_TYPES}.
|
|
19
|
-
*/
|
|
20
|
-
export type BeancountEntryType = BeancountDatedEntryType | BeancountNonDatedEntryType;
|
|
21
|
-
export type FakeEntryType = 'comment' | 'blankline';
|
|
22
|
-
/**
|
|
23
|
-
* Union type of all valid entry type names, including the 'fake' entry types of comment and blankline.
|
|
24
|
-
*/
|
|
25
|
-
export type EntryType = BeancountEntryType | FakeEntryType;
|
|
26
|
-
/**
|
|
27
|
-
* Mapping of Beancount entry type names to their corresponding class constructors.
|
|
28
|
-
* @internal
|
|
29
|
-
*/
|
|
30
|
-
export declare const beancountEntryToClass: {
|
|
31
|
-
transaction: typeof Transaction;
|
|
32
|
-
balance: typeof Balance;
|
|
33
|
-
close: typeof Close;
|
|
34
|
-
commodity: typeof Commodity;
|
|
35
|
-
custom: typeof Custom;
|
|
36
|
-
document: typeof Document;
|
|
37
|
-
event: typeof Event;
|
|
38
|
-
include: typeof Include;
|
|
39
|
-
note: typeof Note;
|
|
40
|
-
open: typeof Open;
|
|
41
|
-
option: typeof Option;
|
|
42
|
-
pad: typeof Pad;
|
|
43
|
-
plugin: typeof Plugin;
|
|
44
|
-
poptag: typeof Poptag;
|
|
45
|
-
price: typeof Price;
|
|
46
|
-
pushtag: typeof Pushtag;
|
|
47
|
-
query: typeof Query;
|
|
48
|
-
};
|
|
49
|
-
/**
|
|
50
|
-
* Mapping of all entry type names (including 'comment' and 'blankline') to their corresponding class constructors.
|
|
51
|
-
* @internal
|
|
52
|
-
*/
|
|
53
|
-
export declare const entryTypeToClass: {
|
|
54
|
-
comment: typeof Comment;
|
|
55
|
-
blankline: typeof Blankline;
|
|
56
|
-
transaction: typeof Transaction;
|
|
57
|
-
balance: typeof Balance;
|
|
58
|
-
close: typeof Close;
|
|
59
|
-
commodity: typeof Commodity;
|
|
60
|
-
custom: typeof Custom;
|
|
61
|
-
document: typeof Document;
|
|
62
|
-
event: typeof Event;
|
|
63
|
-
include: typeof Include;
|
|
64
|
-
note: typeof Note;
|
|
65
|
-
open: typeof Open;
|
|
66
|
-
option: typeof Option;
|
|
67
|
-
pad: typeof Pad;
|
|
68
|
-
plugin: typeof Plugin;
|
|
69
|
-
poptag: typeof Poptag;
|
|
70
|
-
price: typeof Price;
|
|
71
|
-
pushtag: typeof Pushtag;
|
|
72
|
-
query: typeof Query;
|
|
73
|
-
};
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import { Transaction, Balance, Close, Comment, Commodity, Custom, Document, Event, Include, Note, Open, Option, Pad, Plugin, Poptag, Price, Pushtag, Query, Blankline, } from './classes/entryTypes/index.mjs';
|
|
2
|
-
/**
|
|
3
|
-
* Mapping of Beancount entry type names to their corresponding class constructors.
|
|
4
|
-
* @internal
|
|
5
|
-
*/
|
|
6
|
-
export const beancountEntryToClass = {
|
|
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: beancountEntryToClass must have all BeancountEntryType keys
|
|
26
|
-
beancountEntryToClass;
|
|
27
|
-
/**
|
|
28
|
-
* Mapping of all entry type names (including 'comment' and 'blankline') to their corresponding class constructors.
|
|
29
|
-
* @internal
|
|
30
|
-
*/
|
|
31
|
-
export const entryTypeToClass = {
|
|
32
|
-
...beancountEntryToClass,
|
|
33
|
-
comment: Comment,
|
|
34
|
-
blankline: Blankline,
|
|
35
|
-
};
|
|
36
|
-
// Compile-time assertion: entryTypeToClass must have all EntryType keys
|
|
37
|
-
beancountEntryToClass;
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Array of all Beancount entry types that start with a date (YYYY-MM-DD format).
|
|
3
|
-
* These entries follow the pattern: `YYYY-MM-DD <type> ...`
|
|
4
|
-
*/
|
|
5
|
-
export declare const DATED_ENTRY_TYPES: readonly ["balance", "close", "commodity", "custom", "document", "event", "note", "open", "pad", "price", "query", "transaction"];
|
|
6
|
-
/**
|
|
7
|
-
* Array of all Beancount entry types that do NOT start with a date.
|
|
8
|
-
* These entries follow the pattern: `<type> ...`
|
|
9
|
-
*/
|
|
10
|
-
export declare const NON_DATED_ENTRY_TYPES: readonly ["include", "option", "plugin", "poptag", "pushtag"];
|
package/build/src/entryTypes.mjs
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Array of all Beancount entry types that start with a date (YYYY-MM-DD format).
|
|
3
|
-
* These entries follow the pattern: `YYYY-MM-DD <type> ...`
|
|
4
|
-
*/
|
|
5
|
-
export const DATED_ENTRY_TYPES = [
|
|
6
|
-
'balance',
|
|
7
|
-
'close',
|
|
8
|
-
'commodity',
|
|
9
|
-
'custom',
|
|
10
|
-
'document',
|
|
11
|
-
'event',
|
|
12
|
-
'note',
|
|
13
|
-
'open',
|
|
14
|
-
'pad',
|
|
15
|
-
'price',
|
|
16
|
-
'query',
|
|
17
|
-
'transaction',
|
|
18
|
-
];
|
|
19
|
-
/**
|
|
20
|
-
* Array of all Beancount entry types that do NOT start with a date.
|
|
21
|
-
* These entries follow the pattern: `<type> ...`
|
|
22
|
-
*/
|
|
23
|
-
export const NON_DATED_ENTRY_TYPES = [
|
|
24
|
-
'include',
|
|
25
|
-
'option',
|
|
26
|
-
'plugin',
|
|
27
|
-
'poptag',
|
|
28
|
-
'pushtag',
|
|
29
|
-
];
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Splits a Beancount file string into an array of unparsed entry arrays.
|
|
3
|
-
* Each entry is represented as an array of strings (tokens).
|
|
4
|
-
*
|
|
5
|
-
* This function handles:
|
|
6
|
-
* - Splitting on blank lines between entries
|
|
7
|
-
* - Detecting new entries based on indentation
|
|
8
|
-
* - Preserving multi-line strings that span lines
|
|
9
|
-
*
|
|
10
|
-
* @param input - The complete Beancount file content as a string
|
|
11
|
-
* @returns An array where each element is an array of string tokens representing one entry
|
|
12
|
-
* @internal
|
|
13
|
-
*/
|
|
14
|
-
export declare const splitStringIntoUnparsedEntries: (input: string) => string[][];
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import { countChar } from './countChar.mjs';
|
|
2
|
-
import { stringAwareSplitLine } from './stringAwareSplitLine.mjs';
|
|
3
|
-
/**
|
|
4
|
-
* Splits a Beancount file string into an array of unparsed entry arrays.
|
|
5
|
-
* Each entry is represented as an array of strings (tokens).
|
|
6
|
-
*
|
|
7
|
-
* This function handles:
|
|
8
|
-
* - Splitting on blank lines between entries
|
|
9
|
-
* - Detecting new entries based on indentation
|
|
10
|
-
* - Preserving multi-line strings that span lines
|
|
11
|
-
*
|
|
12
|
-
* @param input - The complete Beancount file content as a string
|
|
13
|
-
* @returns An array where each element is an array of string tokens representing one entry
|
|
14
|
-
* @internal
|
|
15
|
-
*/
|
|
16
|
-
export const splitStringIntoUnparsedEntries = (input) => {
|
|
17
|
-
const lines = input.split('\n');
|
|
18
|
-
// split up the file into entries
|
|
19
|
-
let inEntry = false;
|
|
20
|
-
let inString = false;
|
|
21
|
-
const unparsedEntries = lines.reduce((acc, line) => {
|
|
22
|
-
if (!inString) {
|
|
23
|
-
if (line.trim() === '') {
|
|
24
|
-
// empty newline, next entry starts
|
|
25
|
-
inEntry = false;
|
|
26
|
-
}
|
|
27
|
-
if (!line.startsWith(' ') && inEntry) {
|
|
28
|
-
// no indent, new entry
|
|
29
|
-
inEntry = false;
|
|
30
|
-
}
|
|
31
|
-
if (!inEntry) {
|
|
32
|
-
acc.push([]);
|
|
33
|
-
inEntry = true;
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
acc[acc.length - 1].push(line);
|
|
37
|
-
// After a blank line, ensure next line starts a new entry
|
|
38
|
-
if (!inString && line.trim() === '') {
|
|
39
|
-
inEntry = false;
|
|
40
|
-
}
|
|
41
|
-
// odd number of ", we're in an unclosed string
|
|
42
|
-
if (countChar(line, '"') % 2 === 1) {
|
|
43
|
-
inString = !inString;
|
|
44
|
-
}
|
|
45
|
-
return acc;
|
|
46
|
-
}, []);
|
|
47
|
-
return unparsedEntries.map((lines) => stringAwareSplitLine(lines.join('\n')));
|
|
48
|
-
};
|