sec-edgar-api 0.4.1 → 0.5.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 +6 -2
- package/build/index.d.ts +4 -2
- package/build/index.js +5 -16
- package/build/services/DocumentParser/DocumentParser.d.ts +1 -1
- package/build/services/DocumentParser/XBRLParser/InstanceParser.d.ts +1 -1
- package/build/services/DocumentParser/XBRLParser/LinkbaseParser.d.ts +1 -1
- package/build/services/DocumentParser/XBRLParser/SchemaParser.d.ts +1 -1
- package/build/services/DocumentParser/XBRLParser/XBRLParser.d.ts +1 -1
- package/build/services/DocumentParser/parsers/parse-companies.d.ts +1 -2
- package/build/services/DocumentParser/parsers/parse-insider-transaction.d.ts +1 -2
- package/build/services/DocumentParser/parsers/parse-xbrl.d.ts +2 -2
- package/build/services/DocumentParser/parsers/parse-xbrl.js +12 -8
- package/build/services/ReportParser/ReportParser.d.ts +19 -6
- package/build/services/ReportParser/ReportParser.js +53 -22
- package/build/services/ReportParser/ReportResolvable.d.ts +52 -0
- package/build/services/ReportParser/ReportResolvable.js +135 -0
- package/build/services/ReportParser/ReportTranslatedProxy.d.ts +1 -1
- package/build/services/ReportParser/ReportWrapper.d.ts +1 -1
- package/build/services/ReportParser/resolvers/resolve-ebit.js +6 -0
- package/build/services/ReportParser/resolvers/resolve-q4-fiscal-year-matching-properties.js +0 -1
- package/build/services/ReportRawBuilder/FactFiscalCalculator.d.ts +8 -0
- package/build/services/ReportRawBuilder/FactFiscalCalculator.js +34 -1
- package/build/services/ReportRawBuilder/FactGrouper.d.ts +1 -1
- package/build/services/ReportRawBuilder/FactPeriodResolver.d.ts +1 -1
- package/build/services/ReportRawBuilder/FactRecordBuilder.d.ts +1 -1
- package/build/services/ReportRawBuilder/FactSplitAdjuster.d.ts +1 -1
- package/build/services/ReportRawBuilder/ReportRawBuilder.d.ts +2 -3
- package/build/services/SecEdgarApi/FilingMapper.d.ts +1 -1
- package/build/services/SecEdgarApi/RequestWrapper.d.ts +1 -1
- package/build/services/SecEdgarApi/SecEdgarApi.d.ts +22 -5
- package/build/services/SecEdgarApi/SecEdgarApi.js +35 -5
- package/build/types/calculation-map.type.d.ts +13 -0
- package/build/types/calculation-map.type.js +2 -0
- package/build/types/common.type.d.ts +1 -10
- package/build/types/company-facts.type.d.ts +6 -1
- package/build/types/index.d.ts +11 -9
- package/build/types/index.js +0 -23
- package/build/types/report-translated.type.d.ts +6 -3
- package/build/util/calculation-map.d.ts +2 -0
- package/build/util/calculation-map.js +292 -0
- package/build/util/key-translations.d.ts +1 -1
- package/build/util/key-translations.js +6 -6
- package/build/util/util-map.d.ts +12 -0
- package/build/util/util-map.js +50 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -56,7 +56,6 @@ interface ReportTranslated {
|
|
|
56
56
|
|
|
57
57
|
equityTotal: number | null
|
|
58
58
|
equityRetainedEarnings: number | null
|
|
59
|
-
equityStockPreferred: number | null
|
|
60
59
|
|
|
61
60
|
sharesOutstanding: number | null
|
|
62
61
|
sharesOutstandingDiluted: number | null
|
|
@@ -83,16 +82,21 @@ interface ReportTranslated {
|
|
|
83
82
|
expenseDepreciationAccumulated: number | null
|
|
84
83
|
expenseStockCompensation: number | null
|
|
85
84
|
expenseNonCashOther: number | null
|
|
85
|
+
expenseSellingGeneralAdministrative: number | null
|
|
86
86
|
|
|
87
87
|
incomeOperating: number | null
|
|
88
88
|
incomeNet: number | null
|
|
89
|
+
incomePretax: number | null
|
|
89
90
|
|
|
90
91
|
cashFlowFree: number | null
|
|
91
92
|
cashFlowDividendsPaid: number | null
|
|
92
93
|
cashFlowDividendsPaidPreferred: number | null
|
|
93
94
|
|
|
94
|
-
cashFlowCapex: number | null
|
|
95
95
|
cashFlowOperating: number | null
|
|
96
|
+
cashFlowInvesting: number | null
|
|
97
|
+
cashFlowFinancing: number | null
|
|
98
|
+
|
|
99
|
+
cashFlowCapex: number | null
|
|
96
100
|
cashFlowDeferredTax: number | null
|
|
97
101
|
|
|
98
102
|
cashFlowWorkingCapitalNonCash: number | null
|
package/build/index.d.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import ReportParser from './services/ReportParser';
|
|
2
2
|
import SecEdgarApi from './services/SecEdgarApi';
|
|
3
|
+
import ReportResolvable from './services/ReportParser/ReportResolvable';
|
|
4
|
+
import { utilMap } from './util/util-map';
|
|
3
5
|
/**
|
|
4
6
|
* Takes company facts data from the SEC and translates them to
|
|
5
7
|
* reports as json objects.
|
|
@@ -12,5 +14,5 @@ declare const reportParser: ReportParser;
|
|
|
12
14
|
* @see https://www.sec.gov/edgar/sec-api-documentation
|
|
13
15
|
*/
|
|
14
16
|
declare const secEdgarApi: SecEdgarApi;
|
|
15
|
-
export { reportParser, secEdgarApi };
|
|
16
|
-
export * from './types';
|
|
17
|
+
export { reportParser, secEdgarApi, ReportResolvable, utilMap };
|
|
18
|
+
export type * from './types';
|
package/build/index.js
CHANGED
|
@@ -1,22 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.secEdgarApi = exports.reportParser = void 0;
|
|
3
|
+
exports.utilMap = exports.ReportResolvable = exports.secEdgarApi = exports.reportParser = void 0;
|
|
18
4
|
var ReportParser_1 = require("./services/ReportParser");
|
|
19
5
|
var SecEdgarApi_1 = require("./services/SecEdgarApi");
|
|
6
|
+
var ReportResolvable_1 = require("./services/ReportParser/ReportResolvable");
|
|
7
|
+
exports.ReportResolvable = ReportResolvable_1.default;
|
|
8
|
+
var util_map_1 = require("./util/util-map");
|
|
9
|
+
Object.defineProperty(exports, "utilMap", { enumerable: true, get: function () { return util_map_1.utilMap; } });
|
|
20
10
|
/**
|
|
21
11
|
* Takes company facts data from the SEC and translates them to
|
|
22
12
|
* reports as json objects.
|
|
@@ -31,4 +21,3 @@ exports.reportParser = reportParser;
|
|
|
31
21
|
*/
|
|
32
22
|
var secEdgarApi = new SecEdgarApi_1.default();
|
|
33
23
|
exports.secEdgarApi = secEdgarApi;
|
|
34
|
-
__exportStar(require("./types"), exports);
|
|
@@ -38,7 +38,7 @@ export default class DocumentParser {
|
|
|
38
38
|
parseCurrentFilingsXbrl(params: XMLParams): import("../../types").CurrentFilingsXBRL;
|
|
39
39
|
parseXbrl(params: XMLParams & GetDocumentXbrlParams): import("./XBRLParser/XBRLParser").XbrlParseResult & {
|
|
40
40
|
report: import("../../types").ReportRaw | null;
|
|
41
|
-
facts: import("../../types").
|
|
41
|
+
facts: import("../../types").FactItemExtended[];
|
|
42
42
|
xml: string;
|
|
43
43
|
};
|
|
44
44
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { XbrlInstance, XbrlLinkbase, XbrlSchema } from '../../../types
|
|
1
|
+
import type { XbrlInstance, XbrlLinkbase, XbrlSchema } from '../../../types';
|
|
2
2
|
import { XbrlFormHeader } from './HeaderParser';
|
|
3
3
|
export interface XbrlParseResult {
|
|
4
4
|
header: XbrlFormHeader;
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { XMLParams } from '../../../types';
|
|
2
|
-
import { CompanySearchResult } from '../../../types/company-search.type';
|
|
1
|
+
import type { CompanySearchResult, XMLParams } from '../../../types';
|
|
3
2
|
export declare function parseCompanies(params: XMLParams): {
|
|
4
3
|
items: CompanySearchResult[];
|
|
5
4
|
};
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { XMLParams } from '../../../types';
|
|
2
|
-
import { InsiderTransaction, Issuer, Owner } from '../../../types/insider-transaction.type';
|
|
1
|
+
import type { InsiderTransaction, Issuer, Owner, XMLParams } from '../../../types';
|
|
3
2
|
export declare function parseInsiderTransactions(params: XMLParams): {
|
|
4
3
|
transactions: InsiderTransaction[];
|
|
5
4
|
owners: Owner[];
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { FactItemExtended, ReportRaw, XMLParams } from '../../../types';
|
|
2
2
|
import { GetDocumentXbrlParams } from '../../SecEdgarApi';
|
|
3
3
|
import { XbrlParseResult } from '../XBRLParser/XBRLParser';
|
|
4
4
|
export declare function parseXbrl(params: XMLParams & GetDocumentXbrlParams): XbrlParseResult & {
|
|
5
5
|
report: ReportRaw | null;
|
|
6
|
-
facts:
|
|
6
|
+
facts: FactItemExtended[];
|
|
7
7
|
xml: string;
|
|
8
8
|
};
|
|
@@ -43,12 +43,7 @@ function buildReportsFromFacts(params) {
|
|
|
43
43
|
fiscalYear: fiscalYear,
|
|
44
44
|
};
|
|
45
45
|
// if there is a split fact, make sure it's from the current fiscal year
|
|
46
|
-
var
|
|
47
|
-
var splitFact = facts.find(function (f) {
|
|
48
|
-
var _a;
|
|
49
|
-
return f.name.endsWith(constants_1.KEY_SPLIT) &&
|
|
50
|
-
isWithinDays({ dateA: f.filed, dateB: (_a = filing === null || filing === void 0 ? void 0 : filing.reportDate) !== null && _a !== void 0 ? _a : '', days: allowedMonthsPriorForSplit * 30 });
|
|
51
|
-
});
|
|
46
|
+
var splitFact = facts.find(function (f) { var _a; return f.name.endsWith(constants_1.KEY_SPLIT) && isWithinDays({ dateA: f.filed, dateB: (_a = filing === null || filing === void 0 ? void 0 : filing.reportDate) !== null && _a !== void 0 ? _a : '', days: 90 }); });
|
|
52
47
|
var reportFocus = {
|
|
53
48
|
cik: Number(cik !== null && cik !== void 0 ? cik : reportFactValues.cik),
|
|
54
49
|
dateFiled: (_d = filing === null || filing === void 0 ? void 0 : filing.filingDate) !== null && _d !== void 0 ? _d : '',
|
|
@@ -71,8 +66,11 @@ function buildReportsFromFacts(params) {
|
|
|
71
66
|
startDate: (_j = fact.start) !== null && _j !== void 0 ? _j : '',
|
|
72
67
|
endDate: fact.end,
|
|
73
68
|
});
|
|
74
|
-
var
|
|
75
|
-
isFocusFactByDateKey.
|
|
69
|
+
var isSplitFact = fact === splitFact;
|
|
70
|
+
var isFocusFact = (_k = isFocusFactByDateKey.get(dateKey)) !== null && _k !== void 0 ? _k : (isWithinDays({ dateA: fact.end, dateB: reportFocus.dateReport, days: 45 }) || isSplitFact);
|
|
71
|
+
if (!isSplitFact) {
|
|
72
|
+
isFocusFactByDateKey.set(dateKey, isFocusFact);
|
|
73
|
+
}
|
|
76
74
|
var el = fact;
|
|
77
75
|
var scale = Number((_l = el.scale) !== null && _l !== void 0 ? _l : 0) || 0;
|
|
78
76
|
var decimals = Number((_m = el.decimals) !== null && _m !== void 0 ? _m : 0) || 0;
|
|
@@ -106,8 +104,14 @@ function buildReportsFromFacts(params) {
|
|
|
106
104
|
factByName.set(prevFactKey, fact);
|
|
107
105
|
reportByDateRange[dateKey][nameKey] = fact.value;
|
|
108
106
|
if (isFocusFact) {
|
|
107
|
+
if (prevFact)
|
|
108
|
+
prevFact.isUsedInReport = false;
|
|
109
|
+
fact.isUsedInReport = true;
|
|
109
110
|
reportFocus[nameKey] = fact.value;
|
|
110
111
|
}
|
|
112
|
+
else {
|
|
113
|
+
fact.isUsedInReport = false;
|
|
114
|
+
}
|
|
111
115
|
}
|
|
112
116
|
return { reportFocus: reportFocus, reportByDateRange: reportByDateRange, factsFiltered: Array.from(factByName.values()) };
|
|
113
117
|
}
|
|
@@ -1,12 +1,13 @@
|
|
|
1
|
-
import { CompanyFactListData, ReportRaw, ReportTranslated } from '../../types';
|
|
1
|
+
import type { CalculationMap, CompanyFactListData, ReportRaw, ReportTranslated } from '../../types';
|
|
2
2
|
import ReportRawBuilder from '../ReportRawBuilder';
|
|
3
|
-
import {
|
|
3
|
+
import { BuildReportsParams } from '../ReportRawBuilder/ReportRawBuilder';
|
|
4
4
|
import PropertyResolver from './PropertyResolver';
|
|
5
5
|
import ReportWrapper from './ReportWrapper';
|
|
6
6
|
interface ReportParserArgs {
|
|
7
7
|
reportBuilder?: ReportRawBuilder;
|
|
8
8
|
propertyResolver?: PropertyResolver;
|
|
9
9
|
keyTranslator?: Record<string, string[]>;
|
|
10
|
+
defaultCalculationMap?: CalculationMap<ReportTranslated>;
|
|
10
11
|
}
|
|
11
12
|
type TranslateRawReportsCallback<T> = (report: T extends undefined ? ReportTranslated : Record<keyof T, string | number>, reportRaw: ReportRaw, keyTranslator: T) => ReportTranslated | ReportRaw | Record<string, string | number | null>;
|
|
12
13
|
/**
|
|
@@ -16,24 +17,36 @@ export default class ReportParser {
|
|
|
16
17
|
private readonly keyTranslator;
|
|
17
18
|
private readonly propertyResolver;
|
|
18
19
|
private readonly reportBuilder;
|
|
20
|
+
private defaultCalculationMap;
|
|
19
21
|
constructor(args?: ReportParserArgs);
|
|
20
22
|
/**
|
|
21
23
|
* Same as parseReports but accepts ReportRaw[] instead of CompanyFactListData
|
|
24
|
+
*
|
|
25
|
+
* @deprecated Formerly parseReportsFromRaw. Will be removed in future version.
|
|
22
26
|
*/
|
|
23
|
-
|
|
27
|
+
parseReportsFromRawLegacy(params: {
|
|
24
28
|
reportsRaw: ReportRaw[];
|
|
25
29
|
usePropertyResolver?: boolean;
|
|
26
30
|
}): ReportWrapper[];
|
|
31
|
+
/**
|
|
32
|
+
* Same as parseReports but accepts ReportRaw[] instead of CompanyFactListData
|
|
33
|
+
*/
|
|
34
|
+
parseReportsFromRaw<T = ReportTranslated>(params: {
|
|
35
|
+
reportsRaw: ReportRaw[];
|
|
36
|
+
calculationMap?: CalculationMap<T>;
|
|
37
|
+
}): (ReportRaw & T)[];
|
|
27
38
|
/**
|
|
28
39
|
* Parse raw reports
|
|
29
40
|
*
|
|
30
41
|
* @see https://www.sec.gov/edgar/sec-api-documentation
|
|
31
42
|
*/
|
|
32
|
-
parseReportsRaw(companyFactListData: CompanyFactListData, options
|
|
43
|
+
parseReportsRaw(companyFactListData: CompanyFactListData, options: Omit<BuildReportsParams, 'facts'> & {
|
|
44
|
+
includeNamePrefix?: boolean;
|
|
45
|
+
}): ReportRaw[];
|
|
33
46
|
/**
|
|
34
|
-
*
|
|
47
|
+
* Builds ReportRaw[] from facts
|
|
35
48
|
*/
|
|
36
|
-
|
|
49
|
+
buildReports(params: BuildReportsParams): ReportRaw[];
|
|
37
50
|
/**
|
|
38
51
|
* Translate ReportRaw to ReportTranslated by default, but can be used to translate to any object using both the callback and keyTranslator
|
|
39
52
|
*
|
|
@@ -1,23 +1,40 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __assign = (this && this.__assign) || function () {
|
|
3
|
+
__assign = Object.assign || function(t) {
|
|
4
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
+
s = arguments[i];
|
|
6
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
+
t[p] = s[p];
|
|
8
|
+
}
|
|
9
|
+
return t;
|
|
10
|
+
};
|
|
11
|
+
return __assign.apply(this, arguments);
|
|
12
|
+
};
|
|
2
13
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
+
var calculation_map_1 = require("../../util/calculation-map");
|
|
3
15
|
var key_translations_1 = require("../../util/key-translations");
|
|
16
|
+
var util_map_1 = require("../../util/util-map");
|
|
4
17
|
var ReportRawBuilder_1 = require("../ReportRawBuilder");
|
|
5
18
|
var PropertyResolver_1 = require("./PropertyResolver");
|
|
19
|
+
var ReportResolvable_1 = require("./ReportResolvable");
|
|
6
20
|
var ReportWrapper_1 = require("./ReportWrapper");
|
|
7
21
|
/**
|
|
8
22
|
* Takes company facts data from the SEC and translates them to reports as json objects.
|
|
9
23
|
*/
|
|
10
24
|
var ReportParser = /** @class */ (function () {
|
|
11
25
|
function ReportParser(args) {
|
|
12
|
-
var _a = args !== null && args !== void 0 ? args : {}, _b = _a.propertyResolver, propertyResolver = _b === void 0 ? new PropertyResolver_1.default() : _b, _c = _a.reportBuilder, reportBuilder = _c === void 0 ? new ReportRawBuilder_1.default() : _c, _d = _a.keyTranslator, keyTranslator = _d === void 0 ? key_translations_1.default : _d;
|
|
26
|
+
var _a = args !== null && args !== void 0 ? args : {}, _b = _a.propertyResolver, propertyResolver = _b === void 0 ? new PropertyResolver_1.default() : _b, _c = _a.reportBuilder, reportBuilder = _c === void 0 ? new ReportRawBuilder_1.default() : _c, _d = _a.keyTranslator, keyTranslator = _d === void 0 ? key_translations_1.default : _d, _e = _a.defaultCalculationMap, defaultCalculationMap = _e === void 0 ? util_map_1.utilMap.expandMap(calculation_map_1.calculationMapCondensed) : _e;
|
|
13
27
|
this.keyTranslator = keyTranslator;
|
|
14
28
|
this.propertyResolver = propertyResolver;
|
|
15
29
|
this.reportBuilder = reportBuilder;
|
|
30
|
+
this.defaultCalculationMap = defaultCalculationMap;
|
|
16
31
|
}
|
|
17
32
|
/**
|
|
18
33
|
* Same as parseReports but accepts ReportRaw[] instead of CompanyFactListData
|
|
34
|
+
*
|
|
35
|
+
* @deprecated Formerly parseReportsFromRaw. Will be removed in future version.
|
|
19
36
|
*/
|
|
20
|
-
ReportParser.prototype.
|
|
37
|
+
ReportParser.prototype.parseReportsFromRawLegacy = function (params) {
|
|
21
38
|
var reportsRaw = params.reportsRaw, _a = params.usePropertyResolver, usePropertyResolver = _a === void 0 ? true : _a;
|
|
22
39
|
var reportByYearQuarter = new Map();
|
|
23
40
|
var reportsRawFiltered = reportsRaw;
|
|
@@ -33,36 +50,50 @@ var ReportParser = /** @class */ (function () {
|
|
|
33
50
|
}
|
|
34
51
|
return reportWrappers;
|
|
35
52
|
};
|
|
53
|
+
/**
|
|
54
|
+
* Same as parseReports but accepts ReportRaw[] instead of CompanyFactListData
|
|
55
|
+
*/
|
|
56
|
+
ReportParser.prototype.parseReportsFromRaw = function (params) {
|
|
57
|
+
var reportsRaw = params.reportsRaw, calculationMap = params.calculationMap;
|
|
58
|
+
var calcMap = calculationMap !== null && calculationMap !== void 0 ? calculationMap : this.defaultCalculationMap;
|
|
59
|
+
return reportsRaw.map(function (report) {
|
|
60
|
+
var _a;
|
|
61
|
+
var reportNew = {
|
|
62
|
+
cik: report.cik,
|
|
63
|
+
dateFiled: report.dateFiled,
|
|
64
|
+
dateReport: report.dateReport,
|
|
65
|
+
fiscalPeriod: report.fiscalPeriod,
|
|
66
|
+
url: report.url,
|
|
67
|
+
fiscalYear: report.fiscalYear,
|
|
68
|
+
splitDate: report.splitDate,
|
|
69
|
+
splitRatio: report.splitRatio,
|
|
70
|
+
};
|
|
71
|
+
var reportResolvable = new ReportResolvable_1.default({
|
|
72
|
+
report: report,
|
|
73
|
+
calculationMap: calcMap,
|
|
74
|
+
});
|
|
75
|
+
for (var key in calcMap) {
|
|
76
|
+
var value = (_a = reportResolvable.get(key)) !== null && _a !== void 0 ? _a : null;
|
|
77
|
+
reportNew[key] = value;
|
|
78
|
+
}
|
|
79
|
+
return reportNew;
|
|
80
|
+
});
|
|
81
|
+
};
|
|
36
82
|
/**
|
|
37
83
|
* Parse raw reports
|
|
38
84
|
*
|
|
39
85
|
* @see https://www.sec.gov/edgar/sec-api-documentation
|
|
40
86
|
*/
|
|
41
87
|
ReportParser.prototype.parseReportsRaw = function (companyFactListData, options) {
|
|
42
|
-
|
|
43
|
-
var adjustForSplits = options.adjustForSplits, resolvePeriodValues = options.resolvePeriodValues, includeNamePrefix = options.includeNamePrefix;
|
|
88
|
+
var includeNamePrefix = options.includeNamePrefix;
|
|
44
89
|
var facts = this.reportBuilder.createFacts(companyFactListData, includeNamePrefix).facts;
|
|
45
|
-
return this.reportBuilder.buildReports({
|
|
46
|
-
facts: facts,
|
|
47
|
-
adjustForSplits: adjustForSplits,
|
|
48
|
-
resolvePeriodValues: resolvePeriodValues,
|
|
49
|
-
});
|
|
90
|
+
return this.reportBuilder.buildReports(__assign({ facts: facts }, options));
|
|
50
91
|
};
|
|
51
92
|
/**
|
|
52
|
-
*
|
|
93
|
+
* Builds ReportRaw[] from facts
|
|
53
94
|
*/
|
|
54
|
-
ReportParser.prototype.
|
|
55
|
-
|
|
56
|
-
reportsRaw.forEach(function (reportRaw) {
|
|
57
|
-
var report = reportRaw;
|
|
58
|
-
delete report.dateFiled;
|
|
59
|
-
delete report.dateReport;
|
|
60
|
-
delete report.fiscalPeriod;
|
|
61
|
-
delete report.fiscalYear;
|
|
62
|
-
delete report.splitRatio;
|
|
63
|
-
delete report.splitDate;
|
|
64
|
-
});
|
|
65
|
-
return reportsRaw;
|
|
95
|
+
ReportParser.prototype.buildReports = function (params) {
|
|
96
|
+
return this.reportBuilder.buildReports(params);
|
|
66
97
|
};
|
|
67
98
|
/**
|
|
68
99
|
* Translate ReportRaw to ReportTranslated by default, but can be used to translate to any object using both the callback and keyTranslator
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import type { CalculationMapCalculation, CalculationMap } from '../../types/calculation-map.type';
|
|
2
|
+
interface GetCalculatedFromGroupResult {
|
|
3
|
+
missingKeys: string[] | null;
|
|
4
|
+
isMissingRequiredKey: boolean;
|
|
5
|
+
hasAtLeastOneKey: boolean;
|
|
6
|
+
value: number | null;
|
|
7
|
+
}
|
|
8
|
+
interface GetCalculatedFromGroupParams {
|
|
9
|
+
group: CalculationMapCalculation;
|
|
10
|
+
breakIfMissingRequiredKey?: boolean;
|
|
11
|
+
}
|
|
12
|
+
export default class ReportResolvable {
|
|
13
|
+
readonly report: Record<string, string | number | null | boolean>;
|
|
14
|
+
private readonly calculationMap;
|
|
15
|
+
private readonly keyStack;
|
|
16
|
+
private readonly calculatedValues;
|
|
17
|
+
private readonly usedGroupIndexesByKey;
|
|
18
|
+
private depth;
|
|
19
|
+
constructor(args: {
|
|
20
|
+
report: Record<string, string | number | null | boolean>;
|
|
21
|
+
calculationMap?: CalculationMap;
|
|
22
|
+
/** Used for member facts */
|
|
23
|
+
pathSeparator?: string;
|
|
24
|
+
});
|
|
25
|
+
getMap(): CalculationMap;
|
|
26
|
+
clearCache(): void;
|
|
27
|
+
/**
|
|
28
|
+
* Used when testing to remove groups that are not being used.
|
|
29
|
+
*/
|
|
30
|
+
getUsedGroupIndexesByKey(): Record<string, number[]>;
|
|
31
|
+
/**
|
|
32
|
+
* Gets value from report, or calculates it using calculationMap.
|
|
33
|
+
*/
|
|
34
|
+
get(key: string): string | number | null | boolean | undefined;
|
|
35
|
+
/**
|
|
36
|
+
* Returns 0 for non-numeric values
|
|
37
|
+
*/
|
|
38
|
+
getNumber(key: string): number;
|
|
39
|
+
getCalculatedFromGroup(params: GetCalculatedFromGroupParams): GetCalculatedFromGroupResult;
|
|
40
|
+
private _get;
|
|
41
|
+
private _getCalculatedFromGroup;
|
|
42
|
+
/**
|
|
43
|
+
* @param skipSingleMatch When true, skips groups that match only one key. Used for testing groups.
|
|
44
|
+
*/
|
|
45
|
+
getCalculated(key: string, skipSingleMatch?: boolean): {
|
|
46
|
+
value: string | number | boolean | null;
|
|
47
|
+
groupIndex: number;
|
|
48
|
+
};
|
|
49
|
+
private _getCalculated;
|
|
50
|
+
toJSON(): Record<string, string | number | boolean | null>;
|
|
51
|
+
}
|
|
52
|
+
export {};
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
var ReportResolvable = /** @class */ (function () {
|
|
4
|
+
function ReportResolvable(args) {
|
|
5
|
+
this.calculationMap = {};
|
|
6
|
+
this.keyStack = new Set();
|
|
7
|
+
this.calculatedValues = new Map();
|
|
8
|
+
this.usedGroupIndexesByKey = new Map();
|
|
9
|
+
this.depth = 0;
|
|
10
|
+
var report = args.report, calculationMap = args.calculationMap;
|
|
11
|
+
this.calculationMap = calculationMap !== null && calculationMap !== void 0 ? calculationMap : {};
|
|
12
|
+
this.report = report;
|
|
13
|
+
this.usedGroupIndexesByKey = new Map();
|
|
14
|
+
}
|
|
15
|
+
ReportResolvable.prototype.getMap = function () {
|
|
16
|
+
return this.calculationMap;
|
|
17
|
+
};
|
|
18
|
+
ReportResolvable.prototype.clearCache = function () {
|
|
19
|
+
this.calculatedValues.clear();
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* Used when testing to remove groups that are not being used.
|
|
23
|
+
*/
|
|
24
|
+
ReportResolvable.prototype.getUsedGroupIndexesByKey = function () {
|
|
25
|
+
var obj = {};
|
|
26
|
+
this.usedGroupIndexesByKey.forEach(function (indexes, key) { return (obj[key] = Array.from(indexes)); });
|
|
27
|
+
return obj;
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* Gets value from report, or calculates it using calculationMap.
|
|
31
|
+
*/
|
|
32
|
+
ReportResolvable.prototype.get = function (key) {
|
|
33
|
+
this.depth = 0;
|
|
34
|
+
return this._get(key);
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* Returns 0 for non-numeric values
|
|
38
|
+
*/
|
|
39
|
+
ReportResolvable.prototype.getNumber = function (key) {
|
|
40
|
+
return Number(this.get(key)) || 0;
|
|
41
|
+
};
|
|
42
|
+
ReportResolvable.prototype.getCalculatedFromGroup = function (params) {
|
|
43
|
+
this.depth = 0;
|
|
44
|
+
return this._getCalculatedFromGroup(params);
|
|
45
|
+
};
|
|
46
|
+
ReportResolvable.prototype._get = function (key, parentKey) {
|
|
47
|
+
var _a, _b;
|
|
48
|
+
return (_a = this.report[key]) !== null && _a !== void 0 ? _a : ((_b = this._getCalculated(key, parentKey)) !== null && _b !== void 0 ? _b : {}).value;
|
|
49
|
+
};
|
|
50
|
+
ReportResolvable.prototype._getCalculatedFromGroup = function (params, parentKey, skipSingleMatch) {
|
|
51
|
+
var _a;
|
|
52
|
+
if (skipSingleMatch === void 0) { skipSingleMatch = false; }
|
|
53
|
+
var group = params.group, _b = params.breakIfMissingRequiredKey, breakIfMissingRequiredKey = _b === void 0 ? true : _b;
|
|
54
|
+
var calculation = group.calculation;
|
|
55
|
+
var hasAtLeastOneKey = false;
|
|
56
|
+
var isMissingRequiredKey = false;
|
|
57
|
+
var missingKeys = [];
|
|
58
|
+
var finalSum = 0;
|
|
59
|
+
for (var _i = 0, calculation_1 = calculation; _i < calculation_1.length; _i++) {
|
|
60
|
+
var item = calculation_1[_i];
|
|
61
|
+
if (skipSingleMatch && calculation.length < 2)
|
|
62
|
+
continue;
|
|
63
|
+
var childKey = item.key, weight = item.weight, isRequired = item.isRequired;
|
|
64
|
+
var value = (_a = this._get(childKey, parentKey)) !== null && _a !== void 0 ? _a : null;
|
|
65
|
+
var hasKey = typeof value === 'number';
|
|
66
|
+
hasAtLeastOneKey = hasAtLeastOneKey || hasKey;
|
|
67
|
+
isMissingRequiredKey = isMissingRequiredKey || (isRequired && !hasKey);
|
|
68
|
+
if (!hasKey) {
|
|
69
|
+
missingKeys.push(childKey);
|
|
70
|
+
}
|
|
71
|
+
if (isMissingRequiredKey && breakIfMissingRequiredKey) {
|
|
72
|
+
break;
|
|
73
|
+
}
|
|
74
|
+
var valueAdjusted = (Number(value) || 0) * weight;
|
|
75
|
+
finalSum += valueAdjusted;
|
|
76
|
+
}
|
|
77
|
+
return { hasAtLeastOneKey: hasAtLeastOneKey, isMissingRequiredKey: isMissingRequiredKey, missingKeys: missingKeys, value: hasAtLeastOneKey ? finalSum : null };
|
|
78
|
+
};
|
|
79
|
+
/**
|
|
80
|
+
* @param skipSingleMatch When true, skips groups that match only one key. Used for testing groups.
|
|
81
|
+
*/
|
|
82
|
+
ReportResolvable.prototype.getCalculated = function (key, skipSingleMatch) {
|
|
83
|
+
var _a;
|
|
84
|
+
if (skipSingleMatch === void 0) { skipSingleMatch = false; }
|
|
85
|
+
this.depth = 0;
|
|
86
|
+
return (_a = this._getCalculated(key, undefined, skipSingleMatch)) !== null && _a !== void 0 ? _a : { value: null, groupIndex: -1 };
|
|
87
|
+
};
|
|
88
|
+
ReportResolvable.prototype._getCalculated = function (key, parentKey, skipSingleMatch) {
|
|
89
|
+
var _a, _b, _c, _d, _e;
|
|
90
|
+
if (skipSingleMatch === void 0) { skipSingleMatch = false; }
|
|
91
|
+
this.depth++;
|
|
92
|
+
if (this.report[key] !== undefined && !skipSingleMatch) {
|
|
93
|
+
return { value: this.report[key], groupIndex: -1 };
|
|
94
|
+
}
|
|
95
|
+
if (this.calculatedValues.has(key)) {
|
|
96
|
+
var calculatedValue = this.calculatedValues.get(key);
|
|
97
|
+
var calculatedLength = (_b = (_a = this.calculationMap[key]) === null || _a === void 0 ? void 0 : _a.groups[calculatedValue === null || calculatedValue === void 0 ? void 0 : calculatedValue.groupIndex]) === null || _b === void 0 ? void 0 : _b.calculation.length;
|
|
98
|
+
if (!skipSingleMatch || calculatedLength > 1)
|
|
99
|
+
return calculatedValue;
|
|
100
|
+
}
|
|
101
|
+
if (this.keyStack.has(key) || this.depth >= 50) {
|
|
102
|
+
return null;
|
|
103
|
+
}
|
|
104
|
+
this.keyStack.add(key);
|
|
105
|
+
var calculationOptions = (_c = this.calculationMap[key]) !== null && _c !== void 0 ? _c : { isTranslation: true, groups: [] };
|
|
106
|
+
var result = null;
|
|
107
|
+
var calculationGroups = (_d = calculationOptions.groups) !== null && _d !== void 0 ? _d : [];
|
|
108
|
+
for (var i = 0; i < calculationGroups.length; i++) {
|
|
109
|
+
var group = calculationGroups[i];
|
|
110
|
+
var _f = this._getCalculatedFromGroup({
|
|
111
|
+
group: group,
|
|
112
|
+
breakIfMissingRequiredKey: true,
|
|
113
|
+
}, key, skipSingleMatch), hasAtLeastOneKey = _f.hasAtLeastOneKey, isMissingRequiredKey = _f.isMissingRequiredKey, value = _f.value;
|
|
114
|
+
if (!hasAtLeastOneKey || isMissingRequiredKey || typeof value !== 'number') {
|
|
115
|
+
continue;
|
|
116
|
+
}
|
|
117
|
+
var groupResult = { value: value, groupIndex: i };
|
|
118
|
+
// used for dev purposes to see which groups are being used.
|
|
119
|
+
var indexBucket = ((_e = this.usedGroupIndexesByKey.get(key)) !== null && _e !== void 0 ? _e : this.usedGroupIndexesByKey.set(key, new Set()).get(key));
|
|
120
|
+
indexBucket.add(i);
|
|
121
|
+
result = groupResult;
|
|
122
|
+
break;
|
|
123
|
+
}
|
|
124
|
+
if (parentKey === undefined && !skipSingleMatch) {
|
|
125
|
+
this.calculatedValues.set(key, result);
|
|
126
|
+
}
|
|
127
|
+
this.keyStack.delete(key);
|
|
128
|
+
return result;
|
|
129
|
+
};
|
|
130
|
+
ReportResolvable.prototype.toJSON = function () {
|
|
131
|
+
return this.report;
|
|
132
|
+
};
|
|
133
|
+
return ReportResolvable;
|
|
134
|
+
}());
|
|
135
|
+
exports.default = ReportResolvable;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { FiscalPeriod, ReportRaw, ReportTranslated } from '../../types';
|
|
1
|
+
import type { FiscalPeriod, ReportRaw, ReportTranslated } from '../../types';
|
|
2
2
|
import ReportTranslatedProxy from './ReportTranslatedProxy';
|
|
3
3
|
/**
|
|
4
4
|
* Contains translated report and raw report with methods to access other reports
|
|
@@ -7,6 +7,12 @@ function resolveEbit(report) {
|
|
|
7
7
|
report.ebit = report.incomeOperating;
|
|
8
8
|
return;
|
|
9
9
|
}
|
|
10
|
+
if (!report.ebit && report.incomeNet && report.expenseTax) {
|
|
11
|
+
report.ebit = report.incomeNet + report.expenseTax;
|
|
12
|
+
}
|
|
13
|
+
if (!report.ebitda && report.ebit && report.expenseDepreciation) {
|
|
14
|
+
report.ebitda = report.ebit + report.expenseDepreciation;
|
|
15
|
+
}
|
|
10
16
|
var _a = report, ebit = _a.ebit, expenseDepreciation = _a.expenseDepreciation, ebitda = _a.ebitda;
|
|
11
17
|
var nullKey = (0, helpers_1.getSingleNullKey)({ ebit: ebit, expenseDepreciation: expenseDepreciation, ebitda: ebitda });
|
|
12
18
|
switch (nullKey) {
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { FactItem, FilingListItemTranslated } from '../../types';
|
|
1
2
|
export interface SetReportDatesParams {
|
|
2
3
|
year: number;
|
|
3
4
|
quarter: number;
|
|
@@ -17,6 +18,13 @@ export default class FactFiscalCalculator {
|
|
|
17
18
|
private readonly endDateCountMap;
|
|
18
19
|
private readonly filedDateCountByEndDate;
|
|
19
20
|
private didResolve;
|
|
21
|
+
constructor(params?: {
|
|
22
|
+
facts?: Pick<FactItem, 'end' | 'filed'>[];
|
|
23
|
+
filings?: Pick<FilingListItemTranslated, 'form' | 'reportDate' | 'filingDate' | 'accessionNumber'>[];
|
|
24
|
+
});
|
|
25
|
+
useFilingsForDates(params: {
|
|
26
|
+
filings: Pick<FilingListItemTranslated, 'form' | 'reportDate' | 'filingDate' | 'accessionNumber'>[];
|
|
27
|
+
}): void;
|
|
20
28
|
add(fact: {
|
|
21
29
|
end: string;
|
|
22
30
|
filed: string;
|