beancount 0.2.5 → 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 +4 -3
- package/build/src/genericParse.mjs +18 -19
- package/build/src/main.d.mts +1 -1
- package/build/src/parse.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.js +30 -8
- 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
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "beancount",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.6",
|
|
4
4
|
"description": "Parse and work with Beancount accounting files in TypeScript with full type safety",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -25,12 +25,12 @@
|
|
|
25
25
|
},
|
|
26
26
|
"homepage": "https://Boelensman1.github.io/node-beancount/",
|
|
27
27
|
"devDependencies": {
|
|
28
|
-
"wtf-devconfigs": "^0.
|
|
29
|
-
"eslint-plugin-jsdoc": "^62.
|
|
30
|
-
"prettier": "^3.8.
|
|
28
|
+
"wtf-devconfigs": "^0.4.2",
|
|
29
|
+
"eslint-plugin-jsdoc": "^62.9.0",
|
|
30
|
+
"prettier": "^3.8.3",
|
|
31
31
|
"tsx": "^4.21.0",
|
|
32
|
-
"typedoc": "^0.28.
|
|
33
|
-
"vitest": "^4.
|
|
32
|
+
"typedoc": "^0.28.19",
|
|
33
|
+
"vitest": "^4.1.5"
|
|
34
34
|
},
|
|
35
35
|
"engines": {
|
|
36
36
|
"node": ">=22"
|
|
@@ -38,4 +38,4 @@
|
|
|
38
38
|
"dependencies": {
|
|
39
39
|
"@js-temporal/polyfill": "^0.5.1"
|
|
40
40
|
}
|
|
41
|
-
}
|
|
41
|
+
}
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import { Temporal } from '@js-temporal/polyfill';
|
|
2
|
-
import { Entry } from './Entry.mjs';
|
|
3
|
-
import { Value } from './Value.mjs';
|
|
4
|
-
import type { BeancountDatedEntryType } from '../entryTypeToClass.mjs';
|
|
5
|
-
/**
|
|
6
|
-
* Union type of all Beancount entry types that include a date field.
|
|
7
|
-
* Excludes non-dated directives: include, option, plugin, pushtag, poptag.
|
|
8
|
-
*
|
|
9
|
-
* @deprecated This type is re-exported from entryTypeToClass.mjs for backward compatibility.
|
|
10
|
-
* Use BeancountDatedEntryType instead.
|
|
11
|
-
*/
|
|
12
|
-
export type BeancountDateEntryType = BeancountDatedEntryType;
|
|
13
|
-
/**
|
|
14
|
-
* Abstract base class for all Beancount entry types that have a date.
|
|
15
|
-
*
|
|
16
|
-
* Child classes must implement static `fromGenericParseResult` method
|
|
17
|
-
*/
|
|
18
|
-
export declare abstract class DateEntry extends Entry {
|
|
19
|
-
/** The type of this dated entry */
|
|
20
|
-
abstract type: BeancountDatedEntryType;
|
|
21
|
-
/** The date of this entry as a Temporal.PlainDate object */
|
|
22
|
-
date: Temporal.PlainDate;
|
|
23
|
-
/** Optional metadata key-value pairs associated with this entry */
|
|
24
|
-
metadata?: Record<string, Value>;
|
|
25
|
-
/**
|
|
26
|
-
* Creates a new DateEntry instance.
|
|
27
|
-
* @param obj - Object containing entry properties
|
|
28
|
-
* @param obj.date - The date string in YYYY-MM-DD format
|
|
29
|
-
*/
|
|
30
|
-
constructor(obj: {
|
|
31
|
-
date: string | Temporal.PlainDate;
|
|
32
|
-
[key: string]: unknown;
|
|
33
|
-
});
|
|
34
|
-
/**
|
|
35
|
-
* Returns the common prefix for all DateEntry toString methods.
|
|
36
|
-
* Format: "YYYY-MM-DD <type>"
|
|
37
|
-
* @returns The formatted date and type prefix string
|
|
38
|
-
*/
|
|
39
|
-
protected getDateTypePrefix(): string;
|
|
40
|
-
/**
|
|
41
|
-
* Converts metadata and comment to a formatted string.
|
|
42
|
-
* If metadata exists, each key-value pair is formatted on separate indented lines.
|
|
43
|
-
*
|
|
44
|
-
* @returns The formatted metadata and comment string, or empty string if neither exists
|
|
45
|
-
*/
|
|
46
|
-
getMetaDataString(): string;
|
|
47
|
-
}
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
import { Temporal } from '@js-temporal/polyfill';
|
|
2
|
-
import { Entry } from './Entry.mjs';
|
|
3
|
-
import { Value } from './Value.mjs';
|
|
4
|
-
/**
|
|
5
|
-
* Abstract base class for all Beancount entry types that have a date.
|
|
6
|
-
*
|
|
7
|
-
* Child classes must implement static `fromGenericParseResult` method
|
|
8
|
-
*/
|
|
9
|
-
export class DateEntry extends Entry {
|
|
10
|
-
/**
|
|
11
|
-
* Creates a new DateEntry instance.
|
|
12
|
-
* @param obj - Object containing entry properties
|
|
13
|
-
* @param obj.date - The date string in YYYY-MM-DD format
|
|
14
|
-
*/
|
|
15
|
-
constructor(obj) {
|
|
16
|
-
const { date, metadata, ...props } = obj;
|
|
17
|
-
super(props);
|
|
18
|
-
if (date) {
|
|
19
|
-
if (date instanceof Temporal.PlainDate) {
|
|
20
|
-
this.date = date;
|
|
21
|
-
}
|
|
22
|
-
else if (typeof date === 'string') {
|
|
23
|
-
this.date = Temporal.PlainDate.from(date, { overflow: 'reject' });
|
|
24
|
-
}
|
|
25
|
-
else {
|
|
26
|
-
throw new Error('Could not parse date, should be either string of Temporal.PlainDate');
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
if (metadata) {
|
|
30
|
-
this.metadata = Object.fromEntries(Object.entries(metadata).map(([key, val]) => [
|
|
31
|
-
key,
|
|
32
|
-
new Value(val),
|
|
33
|
-
]));
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
/**
|
|
37
|
-
* Returns the common prefix for all DateEntry toString methods.
|
|
38
|
-
* Format: "YYYY-MM-DD <type>"
|
|
39
|
-
* @returns The formatted date and type prefix string
|
|
40
|
-
*/
|
|
41
|
-
getDateTypePrefix() {
|
|
42
|
-
return `${this.date.toJSON()} ${this.type}`;
|
|
43
|
-
}
|
|
44
|
-
/**
|
|
45
|
-
* Converts metadata and comment to a formatted string.
|
|
46
|
-
* If metadata exists, each key-value pair is formatted on separate indented lines.
|
|
47
|
-
*
|
|
48
|
-
* @returns The formatted metadata and comment string, or empty string if neither exists
|
|
49
|
-
*/
|
|
50
|
-
getMetaDataString() {
|
|
51
|
-
const comment = this.comment ? ` ; ${this.comment}` : '';
|
|
52
|
-
if (!this.metadata) {
|
|
53
|
-
return comment;
|
|
54
|
-
}
|
|
55
|
-
return (`${comment}\n` +
|
|
56
|
-
Object.entries(this.metadata)
|
|
57
|
-
.map(([key, val]) => ` ${key}: ${val.toString()}`)
|
|
58
|
-
.join('\n'));
|
|
59
|
-
}
|
|
60
|
-
}
|
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
import type { BeancountEntryType } from '../entryTypeToClass.mjs';
|
|
2
|
-
import { genericParse } from '../../src/genericParse.mjs';
|
|
3
|
-
import { FormatOptions } from './ParseResult.mjs';
|
|
4
|
-
/**
|
|
5
|
-
* Type helper for Entry class constructors that enforce the static factory methods.
|
|
6
|
-
* Child classes must implement static fromGenericParseResult and fromObject methods to create instances.
|
|
7
|
-
* Note: The constructor is protected, so only the static factory methods are part of the public API.
|
|
8
|
-
*/
|
|
9
|
-
export interface EntryConstructor<T extends Entry> {
|
|
10
|
-
/**
|
|
11
|
-
* Creates an Entry instance from a generic parse result.
|
|
12
|
-
* @param parsedStart - The result from genericParse containing parsed entry data
|
|
13
|
-
* @returns A new instance of the Entry subclass
|
|
14
|
-
*/
|
|
15
|
-
fromGenericParseResult(parsedStart: ReturnType<typeof genericParse>): T;
|
|
16
|
-
}
|
|
17
|
-
/**
|
|
18
|
-
* Abstract base class for all Beancount entry types.
|
|
19
|
-
*
|
|
20
|
-
* Child classes must implement static `fromGenericParseResult` method
|
|
21
|
-
*/
|
|
22
|
-
export declare abstract class Entry {
|
|
23
|
-
/** Optional comment text associated with this entry */
|
|
24
|
-
comment?: string;
|
|
25
|
-
/** Internal metadata key-value pairs associated with this entry.
|
|
26
|
-
* These can be anything, are not used in the output, and are meant to be used
|
|
27
|
-
* to allow your pipeline to keep track of an internal property */
|
|
28
|
-
internalMetadata: Record<string, unknown>;
|
|
29
|
-
/** The type of this entry (e.g., 'open', 'close', 'transaction', 'comment', 'blankline') */
|
|
30
|
-
abstract type: BeancountEntryType | 'comment' | 'blankline';
|
|
31
|
-
/**
|
|
32
|
-
* Creates a new Entry instance.
|
|
33
|
-
* @param obj - Object containing entry properties
|
|
34
|
-
*/
|
|
35
|
-
constructor(obj: Record<string, unknown>);
|
|
36
|
-
/**
|
|
37
|
-
* Creates an Entry instance from a Beancount string.
|
|
38
|
-
* Parses the input string and constructs the appropriate Entry subclass.
|
|
39
|
-
*
|
|
40
|
-
* @param input - A single Beancount entry as a string
|
|
41
|
-
* @returns A new instance of the Entry subclass
|
|
42
|
-
*/
|
|
43
|
-
static fromString<T extends Entry>(this: EntryConstructor<T>, input: string): T;
|
|
44
|
-
/**
|
|
45
|
-
* Creates an Entry instance from JSON data.
|
|
46
|
-
* Calls fromJSONData to allow subclasses to transform the data before construction.
|
|
47
|
-
*
|
|
48
|
-
* @param jsonString - JSON data representing an entry
|
|
49
|
-
* @returns A new instance of the Entry subclass
|
|
50
|
-
* @remarks **Warning:** No validation is performed on the JSON input. We assume the JSON is valid and well-formed.
|
|
51
|
-
*/
|
|
52
|
-
static fromJSON<T extends Entry>(this: new (obj: any) => T, jsonString: string): T;
|
|
53
|
-
/**
|
|
54
|
-
* Creates an Entry instance from JSON data.
|
|
55
|
-
* Calls fromJSONData to allow subclasses to transform the data before construction.
|
|
56
|
-
*
|
|
57
|
-
* @param jsonData - object representing an entry
|
|
58
|
-
* @returns A new instance of the Entry subclass
|
|
59
|
-
* @remarks **Warning:** No validation is performed on the input. We assume the input is valid and well-formed.
|
|
60
|
-
*/
|
|
61
|
-
static fromJSONData<T extends Entry>(this: new (obj: any) => T, jsonData: Record<string, unknown>): T;
|
|
62
|
-
/**
|
|
63
|
-
* Converts this entry to a formatted string with aligned columns.
|
|
64
|
-
* Default implementation delegates to toString(). Subclasses can override for custom formatting.
|
|
65
|
-
*
|
|
66
|
-
* @param _formatOptions - Formatting options (unused in base implementation)
|
|
67
|
-
* @returns The formatted string representation of this entry
|
|
68
|
-
*/
|
|
69
|
-
toFormattedString(_formatOptions?: FormatOptions): string;
|
|
70
|
-
/**
|
|
71
|
-
* Transforms JSON data before creating an Entry instance.
|
|
72
|
-
* Default implementation returns the input unchanged.
|
|
73
|
-
* Subclasses can override this to handle custom deserialization logic
|
|
74
|
-
* (e.g., converting nested objects, handling dates, etc.).
|
|
75
|
-
*
|
|
76
|
-
* @param json - The JSON data to transform
|
|
77
|
-
* @returns The transformed data ready for the constructor
|
|
78
|
-
*/
|
|
79
|
-
protected parseJSONData(json: Record<string, unknown>): Record<string, unknown>;
|
|
80
|
-
/**
|
|
81
|
-
* Converts an entry to a JSON-serializable object.
|
|
82
|
-
* @returns A JSON-serializable representation of this entry
|
|
83
|
-
*/
|
|
84
|
-
toJSON(): Record<string, unknown>;
|
|
85
|
-
}
|
|
86
|
-
/**
|
|
87
|
-
* Type assertion helper to ensure a class conforms to EntryConstructor.
|
|
88
|
-
* Usage: assertEntryConstructor(MyEntryClass)
|
|
89
|
-
* @param _ctor - The constructor to validate (unused at runtime)
|
|
90
|
-
* @internal
|
|
91
|
-
*/
|
|
92
|
-
export declare function assertEntryConstructor<T extends Entry>(_ctor: EntryConstructor<T>): void;
|
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
import { genericParse } from '../../src/genericParse.mjs';
|
|
2
|
-
import { stringAwareSplitLine } from '../utils/stringAwareSplitLine.mjs';
|
|
3
|
-
import { defaultFormatOptions } from './ParseResult.mjs';
|
|
4
|
-
/**
|
|
5
|
-
* Abstract base class for all Beancount entry types.
|
|
6
|
-
*
|
|
7
|
-
* Child classes must implement static `fromGenericParseResult` method
|
|
8
|
-
*/
|
|
9
|
-
export class Entry {
|
|
10
|
-
/**
|
|
11
|
-
* Creates a new Entry instance.
|
|
12
|
-
* @param obj - Object containing entry properties
|
|
13
|
-
*/
|
|
14
|
-
constructor(obj) {
|
|
15
|
-
/** Internal metadata key-value pairs associated with this entry.
|
|
16
|
-
* These can be anything, are not used in the output, and are meant to be used
|
|
17
|
-
* to allow your pipeline to keep track of an internal property */
|
|
18
|
-
this.internalMetadata = {};
|
|
19
|
-
Object.assign(this, obj);
|
|
20
|
-
}
|
|
21
|
-
/**
|
|
22
|
-
* Creates an Entry instance from a Beancount string.
|
|
23
|
-
* Parses the input string and constructs the appropriate Entry subclass.
|
|
24
|
-
*
|
|
25
|
-
* @param input - A single Beancount entry as a string
|
|
26
|
-
* @returns A new instance of the Entry subclass
|
|
27
|
-
*/
|
|
28
|
-
static fromString(input) {
|
|
29
|
-
const unparsedEntry = stringAwareSplitLine(input);
|
|
30
|
-
const genericParseResult = genericParse(unparsedEntry);
|
|
31
|
-
const result = this.fromGenericParseResult(genericParseResult);
|
|
32
|
-
if (result.type !== genericParseResult.type) {
|
|
33
|
-
console.warn('Parse result type is not equal to requested object type, make sure the correct class is initiated');
|
|
34
|
-
}
|
|
35
|
-
return result;
|
|
36
|
-
}
|
|
37
|
-
/**
|
|
38
|
-
* Creates an Entry instance from JSON data.
|
|
39
|
-
* Calls fromJSONData to allow subclasses to transform the data before construction.
|
|
40
|
-
*
|
|
41
|
-
* @param jsonString - JSON data representing an entry
|
|
42
|
-
* @returns A new instance of the Entry subclass
|
|
43
|
-
* @remarks **Warning:** No validation is performed on the JSON input. We assume the JSON is valid and well-formed.
|
|
44
|
-
*/
|
|
45
|
-
static fromJSON(jsonString) {
|
|
46
|
-
const json = JSON.parse(jsonString);
|
|
47
|
-
// @ts-expect-error Not sure how to type this correctly
|
|
48
|
-
return this.fromJSONData(json); // eslint-disable-line
|
|
49
|
-
}
|
|
50
|
-
/**
|
|
51
|
-
* Creates an Entry instance from JSON data.
|
|
52
|
-
* Calls fromJSONData to allow subclasses to transform the data before construction.
|
|
53
|
-
*
|
|
54
|
-
* @param jsonData - object representing an entry
|
|
55
|
-
* @returns A new instance of the Entry subclass
|
|
56
|
-
* @remarks **Warning:** No validation is performed on the input. We assume the input is valid and well-formed.
|
|
57
|
-
*/
|
|
58
|
-
static fromJSONData(jsonData) {
|
|
59
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
60
|
-
const instance = new this({});
|
|
61
|
-
const transformedData = instance.parseJSONData(jsonData);
|
|
62
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
63
|
-
return new this(transformedData);
|
|
64
|
-
}
|
|
65
|
-
/**
|
|
66
|
-
* Converts this entry to a formatted string with aligned columns.
|
|
67
|
-
* Default implementation delegates to toString(). Subclasses can override for custom formatting.
|
|
68
|
-
*
|
|
69
|
-
* @param _formatOptions - Formatting options (unused in base implementation)
|
|
70
|
-
* @returns The formatted string representation of this entry
|
|
71
|
-
*/
|
|
72
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
73
|
-
toFormattedString(_formatOptions = defaultFormatOptions) {
|
|
74
|
-
// eslint-disable-next-line @typescript-eslint/no-base-to-string
|
|
75
|
-
return this.toString();
|
|
76
|
-
}
|
|
77
|
-
/**
|
|
78
|
-
* Transforms JSON data before creating an Entry instance.
|
|
79
|
-
* Default implementation returns the input unchanged.
|
|
80
|
-
* Subclasses can override this to handle custom deserialization logic
|
|
81
|
-
* (e.g., converting nested objects, handling dates, etc.).
|
|
82
|
-
*
|
|
83
|
-
* @param json - The JSON data to transform
|
|
84
|
-
* @returns The transformed data ready for the constructor
|
|
85
|
-
*/
|
|
86
|
-
parseJSONData(json) {
|
|
87
|
-
return json;
|
|
88
|
-
}
|
|
89
|
-
/**
|
|
90
|
-
* Converts an entry to a JSON-serializable object.
|
|
91
|
-
* @returns A JSON-serializable representation of this entry
|
|
92
|
-
*/
|
|
93
|
-
toJSON() {
|
|
94
|
-
return {
|
|
95
|
-
...this,
|
|
96
|
-
};
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
/**
|
|
100
|
-
* Type assertion helper to ensure a class conforms to EntryConstructor.
|
|
101
|
-
* Usage: assertEntryConstructor(MyEntryClass)
|
|
102
|
-
* @param _ctor - The constructor to validate (unused at runtime)
|
|
103
|
-
* @internal
|
|
104
|
-
*/
|
|
105
|
-
export function assertEntryConstructor(
|
|
106
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
107
|
-
_ctor) { }
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import type { GenericParseResultWithDate } from '../../genericParse.mjs';
|
|
2
|
-
import { DateEntry } from '../DateEntry.mjs';
|
|
3
|
-
import { FormatOptions } from '../ParseResult.mjs';
|
|
4
|
-
/**
|
|
5
|
-
* Represents a Balance assertion entry.
|
|
6
|
-
* Balance directives assert that an account has a specific balance at a given date.
|
|
7
|
-
*/
|
|
8
|
-
export declare class Balance extends DateEntry {
|
|
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
|
-
}
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import { assertEntryConstructor } from '../Entry.mjs';
|
|
2
|
-
import { DateEntry } from '../DateEntry.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 entry.
|
|
8
|
-
* Balance directives assert that an account has a specific balance at a given date.
|
|
9
|
-
*/
|
|
10
|
-
export class Balance extends DateEntry {
|
|
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 EntryConstructor pattern
|
|
50
|
-
assertEntryConstructor(Balance);
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import type { GenericParseResult } from '../../genericParse.mjs';
|
|
2
|
-
import { Entry, EntryConstructor } from '../Entry.mjs';
|
|
3
|
-
/**
|
|
4
|
-
* Represents a blank line in a Beancount file.
|
|
5
|
-
* Blank lines are used to separate entries for readability.
|
|
6
|
-
*/
|
|
7
|
-
export declare class Blankline extends Entry {
|
|
8
|
-
/** @inheritdoc */
|
|
9
|
-
type: "blankline";
|
|
10
|
-
/**
|
|
11
|
-
* Creates a Blankline instance from a generic parse result.
|
|
12
|
-
* @param _genericParseResult - Unused, blank lines have no content
|
|
13
|
-
* @returns A new Blankline instance
|
|
14
|
-
*/
|
|
15
|
-
static fromGenericParseResult(_genericParseResult: GenericParseResult): Blankline;
|
|
16
|
-
/** @inheritdoc */
|
|
17
|
-
toString(): string;
|
|
18
|
-
/**
|
|
19
|
-
* Creates a Blankline instance from a string.
|
|
20
|
-
* @param _input - Unused, blank lines have no content
|
|
21
|
-
* @returns A new Blankline instance
|
|
22
|
-
*/
|
|
23
|
-
static fromString<T extends Entry>(this: EntryConstructor<T>, _input: string): T;
|
|
24
|
-
}
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import { assertEntryConstructor, Entry } from '../Entry.mjs';
|
|
2
|
-
/**
|
|
3
|
-
* Represents a blank line in a Beancount file.
|
|
4
|
-
* Blank lines are used to separate entries for readability.
|
|
5
|
-
*/
|
|
6
|
-
export class Blankline extends Entry {
|
|
7
|
-
constructor() {
|
|
8
|
-
super(...arguments);
|
|
9
|
-
/** @inheritdoc */
|
|
10
|
-
this.type = 'blankline';
|
|
11
|
-
}
|
|
12
|
-
/**
|
|
13
|
-
* Creates a Blankline instance from a generic parse result.
|
|
14
|
-
* @param _genericParseResult - Unused, blank lines have no content
|
|
15
|
-
* @returns A new Blankline instance
|
|
16
|
-
*/
|
|
17
|
-
static fromGenericParseResult(
|
|
18
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
19
|
-
_genericParseResult) {
|
|
20
|
-
return new Blankline({});
|
|
21
|
-
}
|
|
22
|
-
/** @inheritdoc */
|
|
23
|
-
toString() {
|
|
24
|
-
return '';
|
|
25
|
-
}
|
|
26
|
-
/**
|
|
27
|
-
* Creates a Blankline instance from a string.
|
|
28
|
-
* @param _input - Unused, blank lines have no content
|
|
29
|
-
* @returns A new Blankline instance
|
|
30
|
-
*/
|
|
31
|
-
static fromString(
|
|
32
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
33
|
-
_input) {
|
|
34
|
-
return this.fromGenericParseResult({});
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
// Ensure class conforms to EntryConstructor pattern
|
|
38
|
-
assertEntryConstructor(Blankline);
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import type { GenericParseResultWithDate } from '../../genericParse.mjs';
|
|
2
|
-
import { DateEntry } from '../DateEntry.mjs';
|
|
3
|
-
/**
|
|
4
|
-
* Represents a Close entry that closes an account.
|
|
5
|
-
* Close directives mark the end of an account's lifespan.
|
|
6
|
-
*/
|
|
7
|
-
export declare class Close extends DateEntry {
|
|
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 entry data
|
|
15
|
-
* @returns A new Close instance
|
|
16
|
-
*/
|
|
17
|
-
static fromGenericParseResult(genericParseResult: GenericParseResultWithDate): Close;
|
|
18
|
-
/** @inheritdoc */
|
|
19
|
-
toString(): string;
|
|
20
|
-
}
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { assertEntryConstructor } from '../Entry.mjs';
|
|
2
|
-
import { DateEntry } from '../DateEntry.mjs';
|
|
3
|
-
/**
|
|
4
|
-
* Represents a Close entry that closes an account.
|
|
5
|
-
* Close directives mark the end of an account's lifespan.
|
|
6
|
-
*/
|
|
7
|
-
export class Close extends DateEntry {
|
|
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 entry 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 EntryConstructor pattern
|
|
31
|
-
assertEntryConstructor(Close);
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import type { GenericParseResult } from '../../genericParse.mjs';
|
|
2
|
-
import { Entry, EntryConstructor } from '../Entry.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 Entry {
|
|
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 Entry>(this: EntryConstructor<T>, input: string): T;
|
|
25
|
-
}
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import { assertEntryConstructor, Entry } from '../Entry.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 Entry {
|
|
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
|
-
fake: true,
|
|
38
|
-
});
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
// Ensure class conforms to EntryConstructor pattern
|
|
42
|
-
assertEntryConstructor(Comment);
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import type { GenericParseResultWithDate } from '../../genericParse.mjs';
|
|
2
|
-
import { DateEntry } from '../DateEntry.mjs';
|
|
3
|
-
/**
|
|
4
|
-
* Represents a Commodity declaration entry.
|
|
5
|
-
* Commodity directives declare the existence of a commodity/currency with metadata.
|
|
6
|
-
*/
|
|
7
|
-
export declare class Commodity extends DateEntry {
|
|
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 entry data
|
|
15
|
-
* @returns A new Commodity instance
|
|
16
|
-
*/
|
|
17
|
-
static fromGenericParseResult(genericParseResult: GenericParseResultWithDate): Commodity;
|
|
18
|
-
/** @inheritdoc */
|
|
19
|
-
toString(): string;
|
|
20
|
-
}
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { assertEntryConstructor } from '../Entry.mjs';
|
|
2
|
-
import { DateEntry } from '../DateEntry.mjs';
|
|
3
|
-
/**
|
|
4
|
-
* Represents a Commodity declaration entry.
|
|
5
|
-
* Commodity directives declare the existence of a commodity/currency with metadata.
|
|
6
|
-
*/
|
|
7
|
-
export class Commodity extends DateEntry {
|
|
8
|
-
constructor() {
|
|
9
|
-
super(...arguments);
|
|
10
|
-
/** @inheritdoc */
|
|
11
|
-
this.type = 'commodity';
|
|
12
|
-
}
|
|
13
|
-
/**
|
|
14
|
-
* Creates a Commodity instance from a generic parse result.
|
|
15
|
-
* @param genericParseResult - The parsed commodity entry data
|
|
16
|
-
* @returns A new Commodity instance
|
|
17
|
-
*/
|
|
18
|
-
static fromGenericParseResult(genericParseResult) {
|
|
19
|
-
const currency = genericParseResult.header.trim();
|
|
20
|
-
return new Commodity({
|
|
21
|
-
...genericParseResult.props,
|
|
22
|
-
currency,
|
|
23
|
-
});
|
|
24
|
-
}
|
|
25
|
-
/** @inheritdoc */
|
|
26
|
-
toString() {
|
|
27
|
-
return `${this.getDateTypePrefix()} ${this.currency}${this.getMetaDataString()}`;
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
// Ensure class conforms to EntryConstructor pattern
|
|
31
|
-
assertEntryConstructor(Commodity);
|