sec-edgar-api 0.4.2 → 0.5.1
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/XMLParser.d.ts +8 -1
- package/build/services/DocumentParser/XMLParser.js +24 -5
- package/build/services/DocumentParser/parsers/parse-companies.d.ts +1 -2
- package/build/services/DocumentParser/parsers/parse-companies.js +23 -41
- package/build/services/DocumentParser/parsers/parse-current-filings-xbrl.js +8 -0
- 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 +50 -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 +23 -4
- package/build/services/SecEdgarApi/SecEdgarApi.js +34 -2
- 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/company-search.type.d.ts +3 -1
- package/build/types/current-filings.type.d.ts +1 -0
- package/build/types/index.d.ts +11 -9
- package/build/types/index.js +0 -23
- package/build/types/insider-transaction.type.d.ts +47 -1
- package/build/types/parsed-filings.type.d.ts +1 -47
- 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,7 +1,14 @@
|
|
|
1
1
|
export default class XMLParser {
|
|
2
2
|
private readonly selfEnclosingTags;
|
|
3
|
+
private readonly textSelectStrategy;
|
|
4
|
+
private readonly tagsToIgnore;
|
|
5
|
+
private readonly textConcatDivider;
|
|
6
|
+
constructor(params?: {
|
|
7
|
+
textSelectStrategy?: 'useFirst' | 'useLast' | 'concatenate';
|
|
8
|
+
textConcatDivider?: string;
|
|
9
|
+
});
|
|
3
10
|
mapAttributes(attributes: string[]): Map<string, string>;
|
|
4
|
-
parse(xml: string):
|
|
11
|
+
parse(xml: string): any;
|
|
5
12
|
iterateXML(params: {
|
|
6
13
|
xml: string;
|
|
7
14
|
onOpenTag?: (tagName: string, attributes: string[], isSelfEnclosing: boolean) => void;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
var XMLParser = /** @class */ (function () {
|
|
4
|
-
function XMLParser() {
|
|
4
|
+
function XMLParser(params) {
|
|
5
5
|
this.selfEnclosingTags = new Set([
|
|
6
6
|
'!doctype',
|
|
7
7
|
'?xml',
|
|
@@ -14,6 +14,10 @@ var XMLParser = /** @class */ (function () {
|
|
|
14
14
|
'filename',
|
|
15
15
|
'description',
|
|
16
16
|
]);
|
|
17
|
+
this.tagsToIgnore = new Set(['script', '?xml']);
|
|
18
|
+
var _a = params !== null && params !== void 0 ? params : {}, _b = _a.textSelectStrategy, textSelectStrategy = _b === void 0 ? 'useFirst' : _b, _c = _a.textConcatDivider, textConcatDivider = _c === void 0 ? '<>' : _c;
|
|
19
|
+
this.textSelectStrategy = textSelectStrategy;
|
|
20
|
+
this.textConcatDivider = textConcatDivider;
|
|
17
21
|
}
|
|
18
22
|
XMLParser.prototype.mapAttributes = function (attributes) {
|
|
19
23
|
var attributesMap = new Map();
|
|
@@ -25,6 +29,7 @@ var XMLParser = /** @class */ (function () {
|
|
|
25
29
|
});
|
|
26
30
|
return attributesMap;
|
|
27
31
|
};
|
|
32
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
28
33
|
XMLParser.prototype.parse = function (xml) {
|
|
29
34
|
var _this = this;
|
|
30
35
|
var currentObj = {};
|
|
@@ -35,7 +40,7 @@ var XMLParser = /** @class */ (function () {
|
|
|
35
40
|
var newObj = {};
|
|
36
41
|
var obj = currentObj;
|
|
37
42
|
var isComment = tagName.startsWith('!--');
|
|
38
|
-
if (isComment || tagName
|
|
43
|
+
if (isComment || _this.tagsToIgnore.has(tagName.toLowerCase()))
|
|
39
44
|
return;
|
|
40
45
|
if (obj[tagName] === undefined) {
|
|
41
46
|
obj[tagName] = newObj;
|
|
@@ -60,10 +65,24 @@ var XMLParser = /** @class */ (function () {
|
|
|
60
65
|
if (!textTrimmed)
|
|
61
66
|
return;
|
|
62
67
|
var obj = currentObj;
|
|
63
|
-
|
|
68
|
+
switch (_this.textSelectStrategy) {
|
|
69
|
+
case 'useFirst':
|
|
70
|
+
if (obj['#text'])
|
|
71
|
+
return;
|
|
72
|
+
obj['#text'] = textTrimmed;
|
|
73
|
+
break;
|
|
74
|
+
case 'useLast':
|
|
75
|
+
obj['#text'] = textTrimmed;
|
|
76
|
+
break;
|
|
77
|
+
case 'concatenate':
|
|
78
|
+
obj['#text'] = obj['#text']
|
|
79
|
+
? "".concat(obj['#text'], " ").concat(_this.textConcatDivider, " ").concat(textTrimmed)
|
|
80
|
+
: textTrimmed;
|
|
81
|
+
break;
|
|
82
|
+
}
|
|
64
83
|
},
|
|
65
|
-
onCloseTag: function () {
|
|
66
|
-
if (objPath.length === 1)
|
|
84
|
+
onCloseTag: function (tagName) {
|
|
85
|
+
if (objPath.length === 1 || _this.tagsToIgnore.has(tagName.toLowerCase()))
|
|
67
86
|
return;
|
|
68
87
|
objPath.pop();
|
|
69
88
|
currentObj = objPath[objPath.length - 1];
|
|
@@ -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,51 +1,33 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.parseCompanies = void 0;
|
|
4
|
-
var
|
|
4
|
+
var XMLParser_1 = require("../XMLParser");
|
|
5
5
|
function parseCompanies(params) {
|
|
6
|
-
var _a, _b, _c, _d;
|
|
6
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t;
|
|
7
7
|
var xml = params.xml;
|
|
8
|
-
var parser = new
|
|
9
|
-
var
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
},
|
|
20
|
-
});
|
|
21
|
-
var header = ['cik', 'company_name', 'state_country'];
|
|
22
|
-
var table = tables.find(function (t) { return t.rows.some(function (r) { return r.some(function (c) { return c.html.includes('CIK'); }); }); });
|
|
8
|
+
var parser = new XMLParser_1.default({ textSelectStrategy: 'concatenate', textConcatDivider: '<>' });
|
|
9
|
+
var result = parser.parse(xml);
|
|
10
|
+
var body = (_b = (_a = result.html) === null || _a === void 0 ? void 0 : _a.body) !== null && _b !== void 0 ? _b : {};
|
|
11
|
+
var bodyDivs = Array.isArray(body.div) ? body.div : [body.div].filter(Boolean);
|
|
12
|
+
var contentDiv = (_c = bodyDivs.find(function (d) { return d && typeof d === 'object' && d['@_id'] === 'contentDiv'; })) !== null && _c !== void 0 ? _c : {};
|
|
13
|
+
var tableDivs = Array.isArray(contentDiv.div) ? contentDiv.div : [contentDiv.div].filter(Boolean);
|
|
14
|
+
var tableDiv = (_d = tableDivs.find(function (d) { return d && typeof d === 'object' && d['@_id'] === 'seriesDiv'; })) !== null && _d !== void 0 ? _d : {};
|
|
15
|
+
var rows = (_j = (_f = (_e = tableDiv.table) === null || _e === void 0 ? void 0 : _e.tr) !== null && _f !== void 0 ? _f : (_h = (_g = tableDiv.table) === null || _g === void 0 ? void 0 : _g.tbody) === null || _h === void 0 ? void 0 : _h.tr) !== null && _j !== void 0 ? _j : [];
|
|
16
|
+
rows = (Array.isArray(rows) ? rows : [rows])
|
|
17
|
+
.filter(function (r) { return r === null || r === void 0 ? void 0 : r.td; })
|
|
18
|
+
.map(function (r) { return (Array.isArray(r.td) ? r.td : [r.td]).filter(Boolean); });
|
|
23
19
|
var items = [];
|
|
24
|
-
for (var _i = 0,
|
|
25
|
-
var row =
|
|
26
|
-
|
|
20
|
+
for (var _i = 0, rows_1 = rows; _i < rows_1.length; _i++) {
|
|
21
|
+
var row = rows_1[_i];
|
|
22
|
+
var cik = Number((_l = (_k = row[0]) === null || _k === void 0 ? void 0 : _k.a) === null || _l === void 0 ? void 0 : _l['#text']) || 0;
|
|
23
|
+
if (!cik)
|
|
27
24
|
continue;
|
|
28
|
-
var
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
var cell = row_1[_f];
|
|
35
|
-
var colName = header[cell.colIndex];
|
|
36
|
-
switch (colName) {
|
|
37
|
-
case 'cik':
|
|
38
|
-
item.cik = Number(cell.valueParsed) || 0;
|
|
39
|
-
break;
|
|
40
|
-
case 'company_name':
|
|
41
|
-
item.companyName = String(((_d = (_c = cell.html.split('>')[1]) === null || _c === void 0 ? void 0 : _c.split('<')[0]) === null || _d === void 0 ? void 0 : _d.split('/')[0]) || cell.valueParsed).trim();
|
|
42
|
-
break;
|
|
43
|
-
case 'state_country':
|
|
44
|
-
item.stateOrCountry = String(cell.valueParsed || '');
|
|
45
|
-
break;
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
items.push(item);
|
|
25
|
+
var row1Parts = (_o = (((_m = row[1]) === null || _m === void 0 ? void 0 : _m['#text']) || '').split('<>')) !== null && _o !== void 0 ? _o : [];
|
|
26
|
+
var sic = Number((_q = (_p = row[1]) === null || _p === void 0 ? void 0 : _p.a) === null || _q === void 0 ? void 0 : _q['#text']) || null;
|
|
27
|
+
var companyName = row1Parts[0].trim();
|
|
28
|
+
var sicDescription = sic ? ((_r = row1Parts.pop()) === null || _r === void 0 ? void 0 : _r.replace('-', '').trim()) || null : null;
|
|
29
|
+
var stateOrCountry = ((_t = (_s = row[2]) === null || _s === void 0 ? void 0 : _s.a) === null || _t === void 0 ? void 0 : _t['#text']) || null;
|
|
30
|
+
items.push({ cik: cik, sic: sic, sicDescription: sicDescription, companyName: companyName, stateOrCountry: stateOrCountry });
|
|
49
31
|
}
|
|
50
32
|
return { items: items };
|
|
51
33
|
}
|
|
@@ -65,6 +65,7 @@ function parseCurrentFilingsXbrl(params) {
|
|
|
65
65
|
case 'item': {
|
|
66
66
|
result.items.push({
|
|
67
67
|
title: '',
|
|
68
|
+
url: '',
|
|
68
69
|
companyName: '',
|
|
69
70
|
cikNumber: 0,
|
|
70
71
|
link: '',
|
|
@@ -99,6 +100,13 @@ function parseCurrentFilingsXbrl(params) {
|
|
|
99
100
|
}
|
|
100
101
|
},
|
|
101
102
|
});
|
|
103
|
+
// add url to each filing
|
|
104
|
+
result.items.forEach(function (item) {
|
|
105
|
+
var cikNumber = item.cikNumber, accessionNumber = item.accessionNumber;
|
|
106
|
+
var accessionNoHyphen = accessionNumber.replace(/-/g, '');
|
|
107
|
+
var filePath = "".concat(Number(cikNumber), "/").concat(accessionNoHyphen, "/").concat(accessionNumber, ".txt");
|
|
108
|
+
item.url = "https://www.sec.gov/Archives/edgar/data/".concat(filePath);
|
|
109
|
+
});
|
|
102
110
|
return result;
|
|
103
111
|
}
|
|
104
112
|
exports.parseCurrentFilingsXbrl = parseCurrentFilingsXbrl;
|
|
@@ -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,50 @@
|
|
|
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
|
+
});
|
|
23
|
+
getMap(): CalculationMap;
|
|
24
|
+
clearCache(): void;
|
|
25
|
+
/**
|
|
26
|
+
* Used when testing to remove groups that are not being used.
|
|
27
|
+
*/
|
|
28
|
+
getUsedGroupIndexesByKey(): Record<string, number[]>;
|
|
29
|
+
/**
|
|
30
|
+
* Gets value from report, or calculates it using calculationMap.
|
|
31
|
+
*/
|
|
32
|
+
get(key: string): string | number | null | boolean | undefined;
|
|
33
|
+
/**
|
|
34
|
+
* Returns 0 for non-numeric values
|
|
35
|
+
*/
|
|
36
|
+
getNumber(key: string): number;
|
|
37
|
+
getCalculatedFromGroup(params: GetCalculatedFromGroupParams): GetCalculatedFromGroupResult;
|
|
38
|
+
private _get;
|
|
39
|
+
private _getCalculatedFromGroup;
|
|
40
|
+
/**
|
|
41
|
+
* @param skipSingleMatch When true, skips groups that match only one key. Used for testing groups.
|
|
42
|
+
*/
|
|
43
|
+
getCalculated(key: string, skipSingleMatch?: boolean): {
|
|
44
|
+
value: string | number | boolean | null;
|
|
45
|
+
groupIndex: number;
|
|
46
|
+
};
|
|
47
|
+
private _getCalculated;
|
|
48
|
+
toJSON(): Record<string, string | number | boolean | null>;
|
|
49
|
+
}
|
|
50
|
+
export {};
|