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.
- package/README.md +51 -22
- package/build/src/benchmark.mjs +1 -1
- package/build/src/classes/DatedNode.d.mts +40 -0
- package/build/src/classes/DatedNode.mjs +61 -0
- package/build/src/classes/Node.d.mts +92 -0
- package/build/src/classes/Node.mjs +107 -0
- package/build/src/classes/ParseResult.d.mts +75 -75
- package/build/src/classes/ParseResult.mjs +96 -98
- package/build/src/classes/nodes/Balance.d.mts +32 -0
- package/build/src/classes/nodes/Balance.mjs +50 -0
- package/build/src/classes/nodes/Blankline.d.mts +23 -0
- package/build/src/classes/nodes/Blankline.mjs +37 -0
- package/build/src/classes/nodes/Close.d.mts +20 -0
- package/build/src/classes/nodes/Close.mjs +31 -0
- package/build/src/classes/nodes/Comment.d.mts +25 -0
- package/build/src/classes/nodes/Comment.mjs +42 -0
- package/build/src/classes/nodes/Commodity.d.mts +20 -0
- package/build/src/classes/nodes/Commodity.mjs +31 -0
- package/build/src/classes/nodes/Custom.d.mts +23 -0
- package/build/src/classes/nodes/Custom.mjs +38 -0
- package/build/src/classes/nodes/Document.d.mts +22 -0
- package/build/src/classes/nodes/Document.mjs +34 -0
- package/build/src/classes/nodes/Event.d.mts +23 -0
- package/build/src/classes/nodes/Event.mjs +34 -0
- package/build/src/classes/nodes/Include.d.mts +20 -0
- package/build/src/classes/nodes/Include.mjs +31 -0
- package/build/src/classes/nodes/Note.d.mts +22 -0
- package/build/src/classes/nodes/Note.mjs +34 -0
- package/build/src/classes/nodes/Open.d.mts +27 -0
- package/build/src/classes/nodes/Open.mjs +66 -0
- package/build/src/classes/nodes/Option.d.mts +23 -0
- package/build/src/classes/nodes/Option.mjs +32 -0
- package/build/src/classes/nodes/Pad.d.mts +22 -0
- package/build/src/classes/nodes/Pad.mjs +33 -0
- package/build/src/classes/nodes/Plugin.d.mts +22 -0
- package/build/src/classes/nodes/Plugin.mjs +36 -0
- package/build/src/classes/nodes/Poptag.d.mts +21 -0
- package/build/src/classes/nodes/Poptag.mjs +34 -0
- package/build/src/classes/nodes/Price.d.mts +32 -0
- package/build/src/classes/nodes/Price.mjs +57 -0
- package/build/src/classes/nodes/Pushtag.d.mts +21 -0
- package/build/src/classes/nodes/Pushtag.mjs +34 -0
- package/build/src/classes/nodes/Query.d.mts +22 -0
- package/build/src/classes/nodes/Query.mjs +34 -0
- package/build/src/classes/nodes/Transaction/Posting.d.mts +59 -0
- package/build/src/classes/nodes/Transaction/Posting.mjs +97 -0
- package/build/src/classes/nodes/Transaction/Tag.d.mts +28 -0
- package/build/src/classes/nodes/Transaction/Tag.mjs +28 -0
- package/build/src/classes/nodes/Transaction/index.d.mts +70 -0
- package/build/src/classes/nodes/Transaction/index.mjs +193 -0
- package/build/src/classes/nodes/index.d.mts +19 -0
- package/build/src/classes/nodes/index.mjs +19 -0
- package/build/src/cli.mjs +4 -4
- package/build/src/deserialize.d.mts +54 -54
- package/build/src/deserialize.mjs +89 -89
- package/build/src/directiveTypes.d.mts +10 -0
- package/build/src/directiveTypes.mjs +29 -0
- package/build/src/genericParse.d.mts +27 -20
- package/build/src/genericParse.mjs +30 -30
- package/build/src/main.d.mts +30 -31
- package/build/src/main.mjs +30 -30
- package/build/src/nodeTypeToClass.d.mts +81 -0
- package/build/src/nodeTypeToClass.mjs +37 -0
- package/build/src/parse.d.mts +16 -16
- package/build/src/parse.mjs +37 -37
- package/build/src/parseFile.d.mts +2 -2
- package/build/src/parseFile.mjs +11 -11
- package/build/src/utils/splitStringIntoSourceFragments.d.ts +14 -0
- package/build/src/utils/splitStringIntoSourceFragments.js +48 -0
- package/build/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +7 -7
|
@@ -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
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { assertNodeConstructor } from '../Node.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 class Commodity extends DatedNode {
|
|
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 node 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 NodeConstructor pattern
|
|
31
|
+
assertNodeConstructor(Commodity);
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { GenericParseResultWithDate } from '../../genericParse.mjs';
|
|
2
|
+
import { DatedNode } from '../DatedNode.mjs';
|
|
3
|
+
import { Value } from '../Value.mjs';
|
|
4
|
+
/**
|
|
5
|
+
* Represents a Custom node for user-defined directives.
|
|
6
|
+
* Custom directives allow for extensibility with arbitrary types and values.
|
|
7
|
+
*/
|
|
8
|
+
export declare class Custom extends DatedNode {
|
|
9
|
+
/** @inheritdoc */
|
|
10
|
+
type: "custom";
|
|
11
|
+
/** The custom directive type */
|
|
12
|
+
customType: Value;
|
|
13
|
+
/** Optional array of values associated with the custom directive */
|
|
14
|
+
values?: Value[];
|
|
15
|
+
/**
|
|
16
|
+
* Creates a Custom instance from a generic parse result.
|
|
17
|
+
* @param genericParseResult - The parsed custom node data
|
|
18
|
+
* @returns A new Custom instance
|
|
19
|
+
*/
|
|
20
|
+
static fromGenericParseResult(genericParseResult: GenericParseResultWithDate): Custom;
|
|
21
|
+
/** @inheritdoc */
|
|
22
|
+
toString(): string;
|
|
23
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { assertNodeConstructor } from '../Node.mjs';
|
|
2
|
+
import { DatedNode } from '../DatedNode.mjs';
|
|
3
|
+
import { simpleParseLine } from '../../utils/simpleParseLine.mjs';
|
|
4
|
+
import { Value } from '../Value.mjs';
|
|
5
|
+
/**
|
|
6
|
+
* Represents a Custom node for user-defined directives.
|
|
7
|
+
* Custom directives allow for extensibility with arbitrary types and values.
|
|
8
|
+
*/
|
|
9
|
+
export class Custom extends DatedNode {
|
|
10
|
+
constructor() {
|
|
11
|
+
super(...arguments);
|
|
12
|
+
/** @inheritdoc */
|
|
13
|
+
this.type = 'custom';
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Creates a Custom instance from a generic parse result.
|
|
17
|
+
* @param genericParseResult - The parsed custom node data
|
|
18
|
+
* @returns A new Custom instance
|
|
19
|
+
*/
|
|
20
|
+
static fromGenericParseResult(genericParseResult) {
|
|
21
|
+
const [customType, ...others] = simpleParseLine(genericParseResult.header);
|
|
22
|
+
return new Custom({
|
|
23
|
+
...genericParseResult.props,
|
|
24
|
+
customType: Value.fromString(customType),
|
|
25
|
+
values: others.length > 0 ? others.map((o) => Value.fromString(o)) : undefined,
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
/** @inheritdoc */
|
|
29
|
+
toString() {
|
|
30
|
+
const parts = [`${this.getDateTypePrefix()} ${this.customType.toString()}`];
|
|
31
|
+
if (this.values !== undefined) {
|
|
32
|
+
parts.push(...this.values.map((v) => v.toString()));
|
|
33
|
+
}
|
|
34
|
+
return parts.join(' ') + this.getMetaDataString();
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
// Ensure class conforms to NodeConstructor pattern
|
|
38
|
+
assertNodeConstructor(Custom);
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { GenericParseResultWithDate } from '../../genericParse.mjs';
|
|
2
|
+
import { DatedNode } from '../DatedNode.mjs';
|
|
3
|
+
/**
|
|
4
|
+
* Represents a Document node that links an external file to an account.
|
|
5
|
+
* Document directives associate receipts, statements, or other files with accounts.
|
|
6
|
+
*/
|
|
7
|
+
export declare class Document extends DatedNode {
|
|
8
|
+
/** @inheritdoc */
|
|
9
|
+
type: "document";
|
|
10
|
+
/** The account the document is associated with */
|
|
11
|
+
account: string;
|
|
12
|
+
/** The file path to the document */
|
|
13
|
+
pathToDocument: string;
|
|
14
|
+
/**
|
|
15
|
+
* Creates a Document instance from a generic parse result.
|
|
16
|
+
* @param genericParseResult - The parsed document node data
|
|
17
|
+
* @returns A new Document instance
|
|
18
|
+
*/
|
|
19
|
+
static fromGenericParseResult(genericParseResult: GenericParseResultWithDate): Document;
|
|
20
|
+
/** @inheritdoc */
|
|
21
|
+
toString(): string;
|
|
22
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { assertNodeConstructor } from '../Node.mjs';
|
|
2
|
+
import { DatedNode } from '../DatedNode.mjs';
|
|
3
|
+
import { parseString } from '../Value.mjs';
|
|
4
|
+
import { stringAwareParseLine } from '../../utils/stringAwareParseLine.mjs';
|
|
5
|
+
/**
|
|
6
|
+
* Represents a Document node that links an external file to an account.
|
|
7
|
+
* Document directives associate receipts, statements, or other files with accounts.
|
|
8
|
+
*/
|
|
9
|
+
export class Document extends DatedNode {
|
|
10
|
+
constructor() {
|
|
11
|
+
super(...arguments);
|
|
12
|
+
/** @inheritdoc */
|
|
13
|
+
this.type = 'document';
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Creates a Document instance from a generic parse result.
|
|
17
|
+
* @param genericParseResult - The parsed document node data
|
|
18
|
+
* @returns A new Document instance
|
|
19
|
+
*/
|
|
20
|
+
static fromGenericParseResult(genericParseResult) {
|
|
21
|
+
const [account, pathToDocument] = stringAwareParseLine(genericParseResult.header);
|
|
22
|
+
return new Document({
|
|
23
|
+
...genericParseResult.props,
|
|
24
|
+
account,
|
|
25
|
+
pathToDocument: parseString(pathToDocument),
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
/** @inheritdoc */
|
|
29
|
+
toString() {
|
|
30
|
+
return `${this.getDateTypePrefix()} ${this.account} "${this.pathToDocument}"${this.getMetaDataString()}`;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
// Ensure class conforms to NodeConstructor pattern
|
|
34
|
+
assertNodeConstructor(Document);
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { GenericParseResultWithDate } from '../../genericParse.mjs';
|
|
2
|
+
import { DatedNode } from '../DatedNode.mjs';
|
|
3
|
+
import { Value } from '../Value.mjs';
|
|
4
|
+
/**
|
|
5
|
+
* Represents an Event node that records a named event with a value.
|
|
6
|
+
* Event directives track occurrences of specific events over time.
|
|
7
|
+
*/
|
|
8
|
+
export declare class Event extends DatedNode {
|
|
9
|
+
/** @inheritdoc */
|
|
10
|
+
type: "event";
|
|
11
|
+
/** The name of the event */
|
|
12
|
+
name: string;
|
|
13
|
+
/** The value associated with the event */
|
|
14
|
+
value: Value;
|
|
15
|
+
/**
|
|
16
|
+
* Creates an Event instance from a generic parse result.
|
|
17
|
+
* @param genericParseResult - The parsed event node data
|
|
18
|
+
* @returns A new Event instance
|
|
19
|
+
*/
|
|
20
|
+
static fromGenericParseResult(genericParseResult: GenericParseResultWithDate): Event;
|
|
21
|
+
/** @inheritdoc */
|
|
22
|
+
toString(): string;
|
|
23
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { assertNodeConstructor } from '../Node.mjs';
|
|
2
|
+
import { DatedNode } from '../DatedNode.mjs';
|
|
3
|
+
import { parseString, Value } from '../Value.mjs';
|
|
4
|
+
import { stringAwareParseLine } from '../../utils/stringAwareParseLine.mjs';
|
|
5
|
+
/**
|
|
6
|
+
* Represents an Event node that records a named event with a value.
|
|
7
|
+
* Event directives track occurrences of specific events over time.
|
|
8
|
+
*/
|
|
9
|
+
export class Event extends DatedNode {
|
|
10
|
+
constructor() {
|
|
11
|
+
super(...arguments);
|
|
12
|
+
/** @inheritdoc */
|
|
13
|
+
this.type = 'event';
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Creates an Event instance from a generic parse result.
|
|
17
|
+
* @param genericParseResult - The parsed event node data
|
|
18
|
+
* @returns A new Event instance
|
|
19
|
+
*/
|
|
20
|
+
static fromGenericParseResult(genericParseResult) {
|
|
21
|
+
const [name, value] = stringAwareParseLine(genericParseResult.header);
|
|
22
|
+
return new Event({
|
|
23
|
+
...genericParseResult.props,
|
|
24
|
+
name: parseString(name),
|
|
25
|
+
value: Value.fromString(value),
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
/** @inheritdoc */
|
|
29
|
+
toString() {
|
|
30
|
+
return `${this.getDateTypePrefix()} "${this.name}" ${this.value.toString()}${this.getMetaDataString()}`;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
// Ensure class conforms to NodeConstructor pattern
|
|
34
|
+
assertNodeConstructor(Event);
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { GenericParseResult } from '../../genericParse.mjs';
|
|
2
|
+
import { Node } from '../Node.mjs';
|
|
3
|
+
/**
|
|
4
|
+
* Represents an Include node that includes another Beancount file.
|
|
5
|
+
* Include directives allow splitting ledgers across multiple files.
|
|
6
|
+
*/
|
|
7
|
+
export declare class Include extends Node {
|
|
8
|
+
/** @inheritdoc */
|
|
9
|
+
type: "include";
|
|
10
|
+
/** The filename/path of the file to include */
|
|
11
|
+
filename: string;
|
|
12
|
+
/**
|
|
13
|
+
* Creates an Include instance from a generic parse result.
|
|
14
|
+
* @param genericParseResult - The parsed include node data
|
|
15
|
+
* @returns A new Include instance
|
|
16
|
+
*/
|
|
17
|
+
static fromGenericParseResult(genericParseResult: GenericParseResult): Include;
|
|
18
|
+
/** @inheritdoc */
|
|
19
|
+
toString(): string;
|
|
20
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { parseString } from '../Value.mjs';
|
|
2
|
+
import { stringAwareParseLine } from '../../utils/stringAwareParseLine.mjs';
|
|
3
|
+
import { assertNodeConstructor, Node } from '../Node.mjs';
|
|
4
|
+
/**
|
|
5
|
+
* Represents an Include node that includes another Beancount file.
|
|
6
|
+
* Include directives allow splitting ledgers across multiple files.
|
|
7
|
+
*/
|
|
8
|
+
export class Include extends Node {
|
|
9
|
+
constructor() {
|
|
10
|
+
super(...arguments);
|
|
11
|
+
/** @inheritdoc */
|
|
12
|
+
this.type = 'include';
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Creates an Include instance from a generic parse result.
|
|
16
|
+
* @param genericParseResult - The parsed include node data
|
|
17
|
+
* @returns A new Include instance
|
|
18
|
+
*/
|
|
19
|
+
static fromGenericParseResult(genericParseResult) {
|
|
20
|
+
const [filename] = stringAwareParseLine(genericParseResult.header);
|
|
21
|
+
return new Include({
|
|
22
|
+
filename: parseString(filename),
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
/** @inheritdoc */
|
|
26
|
+
toString() {
|
|
27
|
+
return `${this.type} "${this.filename}"`;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
// Ensure class conforms to NodeConstructor pattern
|
|
31
|
+
assertNodeConstructor(Include);
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { GenericParseResultWithDate } from '../../genericParse.mjs';
|
|
2
|
+
import { DatedNode } from '../DatedNode.mjs';
|
|
3
|
+
/**
|
|
4
|
+
* Represents a Note node that attaches a comment to an account.
|
|
5
|
+
* Note directives associate free-form text descriptions with accounts at specific dates.
|
|
6
|
+
*/
|
|
7
|
+
export declare class Note extends DatedNode {
|
|
8
|
+
/** @inheritdoc */
|
|
9
|
+
type: "note";
|
|
10
|
+
/** The account the note is attached to */
|
|
11
|
+
account: string;
|
|
12
|
+
/** The note description text */
|
|
13
|
+
description: string;
|
|
14
|
+
/**
|
|
15
|
+
* Creates a Note instance from a generic parse result.
|
|
16
|
+
* @param genericParseResult - The parsed note node data
|
|
17
|
+
* @returns A new Note instance
|
|
18
|
+
*/
|
|
19
|
+
static fromGenericParseResult(genericParseResult: GenericParseResultWithDate): Note;
|
|
20
|
+
/** @inheritdoc */
|
|
21
|
+
toString(): string;
|
|
22
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { assertNodeConstructor } from '../Node.mjs';
|
|
2
|
+
import { DatedNode } from '../DatedNode.mjs';
|
|
3
|
+
import { parseString } from '../Value.mjs';
|
|
4
|
+
import { stringAwareParseLine } from '../../utils/stringAwareParseLine.mjs';
|
|
5
|
+
/**
|
|
6
|
+
* Represents a Note node that attaches a comment to an account.
|
|
7
|
+
* Note directives associate free-form text descriptions with accounts at specific dates.
|
|
8
|
+
*/
|
|
9
|
+
export class Note extends DatedNode {
|
|
10
|
+
constructor() {
|
|
11
|
+
super(...arguments);
|
|
12
|
+
/** @inheritdoc */
|
|
13
|
+
this.type = 'note';
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Creates a Note instance from a generic parse result.
|
|
17
|
+
* @param genericParseResult - The parsed note node data
|
|
18
|
+
* @returns A new Note instance
|
|
19
|
+
*/
|
|
20
|
+
static fromGenericParseResult(genericParseResult) {
|
|
21
|
+
const [account, description] = stringAwareParseLine(genericParseResult.header);
|
|
22
|
+
return new Note({
|
|
23
|
+
...genericParseResult.props,
|
|
24
|
+
account,
|
|
25
|
+
description: parseString(description),
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
/** @inheritdoc */
|
|
29
|
+
toString() {
|
|
30
|
+
return `${this.getDateTypePrefix()} ${this.account} "${this.description}"${this.getMetaDataString()}`;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
// Ensure class conforms to NodeConstructor pattern
|
|
34
|
+
assertNodeConstructor(Note);
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { GenericParseResultWithDate } from '../../genericParse.mjs';
|
|
2
|
+
import { DatedNode } from '../DatedNode.mjs';
|
|
3
|
+
import { FormatOptions } from '../ParseResult.mjs';
|
|
4
|
+
/**
|
|
5
|
+
* Represents an Open node that declares a new account.
|
|
6
|
+
* Open directives define the beginning of an account's lifespan.
|
|
7
|
+
*/
|
|
8
|
+
export declare class Open extends DatedNode {
|
|
9
|
+
/** @inheritdoc */
|
|
10
|
+
type: "open";
|
|
11
|
+
/** The account name being opened */
|
|
12
|
+
account: string;
|
|
13
|
+
/** Optional list of allowed currencies for this account */
|
|
14
|
+
constraintCurrencies?: string[];
|
|
15
|
+
/** Optional booking method specification */
|
|
16
|
+
bookingMethod?: string;
|
|
17
|
+
/**
|
|
18
|
+
* Creates an Open instance from a generic parse result.
|
|
19
|
+
* @param genericParseResult - The parsed open node data
|
|
20
|
+
* @returns A new Open instance
|
|
21
|
+
*/
|
|
22
|
+
static fromGenericParseResult(genericParseResult: GenericParseResultWithDate): Open;
|
|
23
|
+
/** @inheritdoc */
|
|
24
|
+
toString(): string;
|
|
25
|
+
/** @inheritdoc */
|
|
26
|
+
toFormattedString(formatOptions?: FormatOptions): string;
|
|
27
|
+
}
|