sec-edgar-api 0.2.1 → 0.2.2

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.
Files changed (73) hide show
  1. package/README.md +3 -5
  2. package/build/services/DocumentParser/HtmlTableExtractor.d.ts +41 -0
  3. package/build/services/DocumentParser/HtmlTableExtractor.js +408 -0
  4. package/build/services/DocumentParser/XMLParser.d.ts +20 -5
  5. package/build/services/DocumentParser/XMLParser.js +122 -118
  6. package/build/services/DocumentParser/parsers/index.d.ts +5 -3
  7. package/build/services/DocumentParser/parsers/index.js +5 -3
  8. package/build/services/DocumentParser/parsers/parse-current-filings.d.ts +3 -0
  9. package/build/services/DocumentParser/parsers/parse-current-filings.js +98 -0
  10. package/build/services/DocumentParser/parsers/parse-form-13f.d.ts +6 -0
  11. package/build/services/DocumentParser/parsers/parse-form-13f.js +91 -0
  12. package/build/services/DocumentParser/parsers/parse-form-13g.js +2 -2
  13. package/build/services/DocumentParser/parsers/parse-form-4.d.ts +6 -1
  14. package/build/services/DocumentParser/parsers/parse-form-4.js +134 -204
  15. package/build/services/DocumentParser/parsers/parse-form-def14a.d.ts +1 -2
  16. package/build/services/DocumentParser/parsers/parse-form-def14a.js +157 -106
  17. package/build/services/ReportBuilder/FactFiscalCalculator.d.ts +47 -0
  18. package/build/services/ReportBuilder/FactFiscalCalculator.js +228 -0
  19. package/build/services/ReportBuilder/FactPeriodResolver.d.ts +44 -0
  20. package/build/services/ReportBuilder/FactPeriodResolver.js +185 -0
  21. package/build/services/ReportBuilder/FactRecordBuilder.d.ts +7 -0
  22. package/build/services/ReportBuilder/FactRecordBuilder.js +49 -0
  23. package/build/services/ReportBuilder/FactSplitAdjuster.d.ts +39 -0
  24. package/build/services/ReportBuilder/FactSplitAdjuster.js +192 -0
  25. package/build/services/ReportBuilder/ReportBuilder.d.ts +37 -0
  26. package/build/services/ReportBuilder/ReportBuilder.js +180 -0
  27. package/build/services/ReportBuilder/ReportRawResolvable.d.ts +17 -0
  28. package/build/services/ReportBuilder/ReportRawResolvable.js +114 -0
  29. package/build/services/ReportBuilder/index.d.ts +2 -0
  30. package/build/services/ReportBuilder/index.js +4 -0
  31. package/build/services/ReportParser/FactItem.d.ts +66 -0
  32. package/build/services/ReportParser/FactItem.js +50 -0
  33. package/build/services/ReportParser/FactItemFactory.d.ts +22 -0
  34. package/build/services/ReportParser/FactItemFactory.js +150 -0
  35. package/build/services/ReportParser/FactSplitMap.d.ts +16 -0
  36. package/build/services/ReportParser/FactSplitMap.js +101 -0
  37. package/build/services/ReportParser/PropertyResolver.d.ts +1 -0
  38. package/build/services/ReportParser/PropertyResolver.js +1 -0
  39. package/build/services/ReportParser/ReportParser.d.ts +3 -10
  40. package/build/services/ReportParser/ReportParser.js +8 -23
  41. package/build/services/ReportParser/ReportRawParser.d.ts +5 -28
  42. package/build/services/ReportParser/ReportRawParser.js +29 -141
  43. package/build/services/ReportParser/ReportWrapper.js +2 -5
  44. package/build/services/ReportParser/resolvers/index.d.ts +2 -0
  45. package/build/services/ReportParser/resolvers/index.js +2 -0
  46. package/build/services/ReportParser/resolvers/resolve-cash-flow-capex.js +4 -3
  47. package/build/services/ReportParser/resolvers/resolve-cash-flow-operating.js +1 -1
  48. package/build/services/ReportParser/resolvers/resolve-cash-flow-working-capital-non-cash.js +1 -1
  49. package/build/services/ReportParser/resolvers/resolve-expense-depreciation.js +1 -1
  50. package/build/services/ReportParser/resolvers/resolve-fiscal-year-cumulative-properties.js +28 -14
  51. package/build/services/ReportParser/resolvers/resolve-q4-fiscal-year-matching-properties.js +32 -4
  52. package/build/services/ReportParser/resolvers/resolve-split-ratio.d.ts +2 -0
  53. package/build/services/ReportParser/resolvers/resolve-split-ratio.js +37 -0
  54. package/build/services/SecEdgarApi/SecEdgarApi.d.ts +85 -47
  55. package/build/services/SecEdgarApi/SecEdgarApi.js +246 -108
  56. package/build/types/current-filings-xml.type.d.ts +74 -0
  57. package/build/types/current-filings-xml.type.js +6 -0
  58. package/build/types/current-filings.type.d.ts +44 -0
  59. package/build/types/current-filings.type.js +2 -0
  60. package/build/types/form-13f-xml.type.d.ts +105 -0
  61. package/build/types/form-13f-xml.type.js +2 -0
  62. package/build/types/form-4-xml.type.d.ts +132 -0
  63. package/build/types/form-4-xml.type.js +2 -0
  64. package/build/types/index.d.ts +2 -2
  65. package/build/types/index.js +2 -2
  66. package/build/types/parsed-filings.type.d.ts +144 -5
  67. package/build/types/report-raw.type.d.ts +4 -7
  68. package/build/types/report-translated.type.d.ts +1 -2
  69. package/build/types/submission.type.d.ts +3 -2
  70. package/build/util/calculation-map-by-ns.d.ts +6 -0
  71. package/build/util/calculation-map-by-ns.js +9 -0
  72. package/build/util/key-translations.js +1 -2
  73. package/package.json +5 -2
@@ -0,0 +1,101 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ var FactSplitMap = /** @class */ (function () {
4
+ function FactSplitMap() {
5
+ this.splitByFiscalYearAmount = new Map();
6
+ this.splitKey = 'StockholdersEquityNoteStockSplitConversionRatio1';
7
+ }
8
+ FactSplitMap.prototype.addFact = function (factItem) {
9
+ if (factItem.propertyName !== this.splitKey) {
10
+ return;
11
+ }
12
+ var split = factItem.factValue.val;
13
+ var key = "".concat(factItem.fiscalYear, "-").concat(split);
14
+ var prevSplit = this.splitByFiscalYearAmount.get(key);
15
+ if (!prevSplit) {
16
+ this.splitByFiscalYearAmount.set(key, {
17
+ factItem: factItem,
18
+ firstFiled: factItem.factValue.filed,
19
+ });
20
+ return;
21
+ }
22
+ var curEnd = factItem.factValue.end;
23
+ var curFiled = factItem.factValue.filed;
24
+ var prevEnd = prevSplit.factItem.factValue.end;
25
+ var prevFiled = prevSplit.factItem.factValue.filed;
26
+ var shouldUpdateFactItem = !prevSplit || prevEnd < curEnd || (prevEnd === curEnd && prevFiled > curFiled);
27
+ var shouldUpdateFirstFiled = prevFiled > curFiled;
28
+ this.splitByFiscalYearAmount.set(key, {
29
+ factItem: shouldUpdateFactItem ? factItem : prevSplit.factItem,
30
+ firstFiled: shouldUpdateFirstFiled ? curFiled : prevSplit === null || prevSplit === void 0 ? void 0 : prevSplit.firstFiled,
31
+ });
32
+ };
33
+ FactSplitMap.prototype.getSplits = function () {
34
+ return Array.from(this.splitByFiscalYearAmount.values());
35
+ };
36
+ FactSplitMap.prototype.isSplitFact = function (factItem) {
37
+ var _a;
38
+ return (((_a = this.splitByFiscalYearAmount.get("".concat(factItem.fiscalYear, "-").concat(factItem.factValue.val))) === null || _a === void 0 ? void 0 : _a.factItem) === factItem);
39
+ };
40
+ FactSplitMap.prototype.didApplySplit = function (factItem, split) {
41
+ var splitNode = split.factItem;
42
+ if (factItem.factValue.filed > splitNode.factValue.filed) {
43
+ return true;
44
+ }
45
+ if (factItem.factValue.filed < split.firstFiled) {
46
+ return false;
47
+ }
48
+ var isShares = factItem.unit === 'shares';
49
+ var quarter = factItem.quarter;
50
+ var factsNextQuarter = factItem.getFactsInPeriodProperty({
51
+ fiscalPeriod: "Q".concat(quarter === 4 ? 1 : quarter + 1),
52
+ fiscalYear: quarter === 4 ? factItem.fiscalYear + 1 : factItem.fiscalYear,
53
+ });
54
+ var factsPrevQuarter = factItem.getFactsInPeriodProperty({
55
+ fiscalPeriod: "Q".concat(quarter === 1 ? 4 : quarter - 1),
56
+ fiscalYear: quarter === 1 ? factItem.fiscalYear - 1 : factItem.fiscalYear,
57
+ });
58
+ var val = factItem.factValue.val;
59
+ var splitVal = split.factItem.factValue.val;
60
+ var valWithSplit = isShares ? splitVal * val : val / splitVal;
61
+ if (factsNextQuarter.length > 0) {
62
+ // expect next quarter to have split
63
+ var nextFact = factsNextQuarter.reduce(function (f, cur) { return (cur.factValue.frame && cur.factValue.filed >= f.factValue.filed ? cur : f); }, factsNextQuarter[0]);
64
+ var difference = Math.abs(nextFact.factValue.val - val);
65
+ var differenceSplit = Math.abs(nextFact.factValue.val - valWithSplit);
66
+ return difference < differenceSplit;
67
+ }
68
+ if (factsPrevQuarter.length > 0) {
69
+ // split adjustments will already be applied to prev frames by now
70
+ var prevFact = factsPrevQuarter.reduce(function (f, cur) { return (cur.factValue.frame && cur.factValue.filed >= f.factValue.filed ? cur : f); }, factsPrevQuarter[0]);
71
+ var difference = Math.abs(prevFact.factValue.val - val);
72
+ var differenceSplit = Math.abs(prevFact.factValue.val - valWithSplit);
73
+ return difference < differenceSplit;
74
+ }
75
+ return false;
76
+ };
77
+ FactSplitMap.prototype.getSplitAdjustedValue = function (factItem) {
78
+ var splits = this.getSplits();
79
+ var isShares = factItem.unit === 'shares';
80
+ var isSharesRatio = !isShares && factItem.unit.includes('share'); // ex: USD/shares or USD-per-share
81
+ var value = factItem.factValue.val;
82
+ if (isShares || isSharesRatio) {
83
+ for (var _i = 0, splits_1 = splits; _i < splits_1.length; _i++) {
84
+ var split = splits_1[_i];
85
+ if (this.didApplySplit(factItem, split)) {
86
+ continue;
87
+ }
88
+ if (isSharesRatio) {
89
+ value /= split.factItem.factValue.val;
90
+ }
91
+ else if (isShares) {
92
+ value *= split.factItem.factValue.val;
93
+ }
94
+ }
95
+ value = Math.round(value * 100) / 100;
96
+ }
97
+ return value;
98
+ };
99
+ return FactSplitMap;
100
+ }());
101
+ exports.default = FactSplitMap;
@@ -18,6 +18,7 @@ export default class PropertyResolver {
18
18
  resolveLiabilityCurrent: typeof import("./resolvers/resolve-liability-current").resolveLiabilityCurrent;
19
19
  resolveQ4FiscalYearMatchingProperties: typeof import("./resolvers/resolve-q4-fiscal-year-matching-properties").resolveQ4FiscalYearMatchingProperties;
20
20
  resolveCashFlowWorkingCapitalNonCash: typeof import("./resolvers/resolve-cash-flow-working-capital-non-cash").resolveCashFlowWorkingCapitalNonCash;
21
+ resolveSplitRatio: typeof import("./resolvers/resolve-split-ratio").resolveSplitRatio;
21
22
  };
22
23
  });
23
24
  getDefaultResolvers(): typeof resolvers;
@@ -37,6 +37,7 @@ var PropertyResolver = /** @class */ (function () {
37
37
  _this.resolvers.resolveCashFlowOperating(report);
38
38
  _this.resolvers.resolveCashFlowCapex(report);
39
39
  _this.resolvers.resolveCashFlowFree(report);
40
+ _this.resolvers.resolveSplitRatio(report);
40
41
  });
41
42
  };
42
43
  return PropertyResolver;
@@ -1,7 +1,6 @@
1
1
  import { CompanyFactListData, ReportRaw, ReportTranslated } from '../../types';
2
- import { IterateFactsCallbackData } from './FactIterator';
3
2
  import PropertyResolver from './PropertyResolver';
4
- import ReportRawParser, { ParseReportsOptions } from './ReportRawParser';
3
+ import ReportRawParser from './ReportRawParser';
5
4
  import ReportWrapper from './ReportWrapper';
6
5
  interface ReportParserArgs {
7
6
  reportRawParser?: ReportRawParser;
@@ -34,17 +33,11 @@ export default class ReportParser {
34
33
  *
35
34
  * @see https://www.sec.gov/edgar/sec-api-documentation
36
35
  */
37
- parseReportsRaw(companyFactListData: Pick<CompanyFactListData, 'facts'>, options?: ParseReportsOptions): ReportRaw[];
36
+ parseReportsRaw(companyFactListData: Pick<CompanyFactListData, 'facts'>): ReportRaw[];
38
37
  /**
39
38
  * parseReportsRaw but removes meta data from the report
40
39
  */
41
- parseReportsRawNoMeta(companyFactListData: Pick<CompanyFactListData, 'facts'>, options?: ParseReportsOptions): Record<string, number>[];
42
- /**
43
- * Avoids deep nesting logic while iteratating through company facts
44
- *
45
- * @param callback called on each company fact.
46
- */
47
- iterateCompanyFacts(companyFactListData: Pick<CompanyFactListData, 'facts'>, callback: (data: IterateFactsCallbackData) => void): void;
40
+ parseReportsRawNoMeta(companyFactListData: Pick<CompanyFactListData, 'facts'>): Record<string, number>[];
48
41
  /**
49
42
  * Translate ReportRaw to ReportTranslated by default, but can be used to translate to any object using both the callback and keyTranslator
50
43
  *
@@ -23,9 +23,7 @@ var ReportParser = /** @class */ (function () {
23
23
  */
24
24
  ReportParser.prototype.parseReports = function (companyFactListData, usePropertyResolver) {
25
25
  if (usePropertyResolver === void 0) { usePropertyResolver = true; }
26
- var reportsRaw = this.reportRawParser.parseReports(companyFactListData, {
27
- reportsToInclude: ['ANNUAL', 'QUARTERLY'],
28
- });
26
+ var reportsRaw = this.reportRawParser.parseReports(companyFactListData);
29
27
  return this.parseReportsFromRaw(reportsRaw, usePropertyResolver);
30
28
  };
31
29
  /**
@@ -34,9 +32,7 @@ var ReportParser = /** @class */ (function () {
34
32
  ReportParser.prototype.parseReportsFromRaw = function (reportsRaw, usePropertyResolver) {
35
33
  if (usePropertyResolver === void 0) { usePropertyResolver = true; }
36
34
  var reportByYearQuarter = new Map();
37
- var reportsRawFiltered = reportsRaw.filter(function (reportRaw) {
38
- return reportRaw.reportType === 'ANNUAL' || reportRaw.reportType === 'QUARTERLY';
39
- });
35
+ var reportsRawFiltered = reportsRaw;
40
36
  this.translateReportsRaw(reportsRawFiltered, function (report, reportRaw) {
41
37
  var fiscalPeriod = report.fiscalPeriod, fiscalYear = report.fiscalYear;
42
38
  var keyReport = "".concat(fiscalYear, "_").concat(fiscalPeriod);
@@ -54,36 +50,25 @@ var ReportParser = /** @class */ (function () {
54
50
  *
55
51
  * @see https://www.sec.gov/edgar/sec-api-documentation
56
52
  */
57
- ReportParser.prototype.parseReportsRaw = function (companyFactListData, options) {
58
- return this.reportRawParser.parseReports(companyFactListData, options);
53
+ ReportParser.prototype.parseReportsRaw = function (companyFactListData) {
54
+ return this.reportRawParser.parseReports(companyFactListData);
59
55
  };
60
56
  /**
61
57
  * parseReportsRaw but removes meta data from the report
62
58
  */
63
- ReportParser.prototype.parseReportsRawNoMeta = function (companyFactListData, options) {
64
- var reportsRaw = this.parseReportsRaw(companyFactListData, options);
59
+ ReportParser.prototype.parseReportsRawNoMeta = function (companyFactListData) {
60
+ var reportsRaw = this.parseReportsRaw(companyFactListData);
65
61
  reportsRaw.forEach(function (reportRaw) {
66
62
  var report = reportRaw;
67
63
  delete report.dateFiled;
68
64
  delete report.dateReport;
69
65
  delete report.fiscalPeriod;
70
66
  delete report.fiscalYear;
71
- delete report.form;
72
- delete report.frame;
73
- delete report.isTTM;
74
- delete report.reportType;
75
- delete report.taxonomy;
67
+ delete report.splitRatio;
68
+ delete report.splitDate;
76
69
  });
77
70
  return reportsRaw;
78
71
  };
79
- /**
80
- * Avoids deep nesting logic while iteratating through company facts
81
- *
82
- * @param callback called on each company fact.
83
- */
84
- ReportParser.prototype.iterateCompanyFacts = function (companyFactListData, callback) {
85
- this.reportRawParser.iterateCompanyFacts(companyFactListData, callback);
86
- };
87
72
  /**
88
73
  * Translate ReportRaw to ReportTranslated by default, but can be used to translate to any object using both the callback and keyTranslator
89
74
  *
@@ -1,34 +1,11 @@
1
- import { CompanyFactListData } from '../../types/company-facts.type';
2
- import { ReportRaw, ReportType } from '../../types/report-raw.type';
3
- import FactIterator, { IterateFactsCallbackData } from './FactIterator';
1
+ import { CompanyFactListData, ReportRaw } from '../../types';
2
+ import FactItemFactory from './FactItemFactory';
4
3
  interface ReportRawParserArgs {
5
- factIterator?: FactIterator;
4
+ factItemFactory?: FactItemFactory;
6
5
  }
7
- export interface ParseReportsOptions {
8
- /**
9
- * Instantaneous data may be filed later than the original filing date.
10
- * It is flagged by "I" at the end of the frame property. defaults to true. see https://www.sec.gov/edgar/sec-api-documentation
11
- * */
12
- mergeInstantaneousData?: boolean;
13
- reportsToInclude?: ReportType | ReportType[] | null;
14
- }
15
- /**
16
- * @see https://www.sec.gov/edgar/sec-api-documentation
17
- */
18
6
  export default class ReportRawParser {
19
- private readonly factIterator;
7
+ private readonly factItemFactory;
20
8
  constructor(args?: ReportRawParserArgs);
21
- /**
22
- * Avoids deep nesting logic while iteratating through company facts
23
- *
24
- * @param callback called on each company fact.
25
- */
26
- iterateCompanyFacts(companyFactListData: Pick<CompanyFactListData, 'facts'>, callback: (data: IterateFactsCallbackData) => void): void;
27
- /**
28
- * Returns raw reports in ascending order by report date. if date is the same, priority is filed date, frame, form
29
- */
30
- parseReports(companyFactListData: Pick<CompanyFactListData, 'facts'>, options?: ParseReportsOptions): ReportRaw[];
31
- private getReportType;
32
- private getFiscalYear;
9
+ parseReports(companyFactListData: Pick<CompanyFactListData, 'facts'>): ReportRaw[];
33
10
  }
34
11
  export {};
@@ -1,154 +1,42 @@
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
- };
13
2
  Object.defineProperty(exports, "__esModule", { value: true });
14
- var FactIterator_1 = require("./FactIterator");
15
- /**
16
- * @see https://www.sec.gov/edgar/sec-api-documentation
17
- */
3
+ var FactItemFactory_1 = require("./FactItemFactory");
18
4
  var ReportRawParser = /** @class */ (function () {
19
5
  function ReportRawParser(args) {
20
- var _a = (args !== null && args !== void 0 ? args : {}).factIterator, factIterator = _a === void 0 ? new FactIterator_1.default() : _a;
21
- this.factIterator = factIterator;
6
+ var _a = (args !== null && args !== void 0 ? args : {}).factItemFactory, factItemFactory = _a === void 0 ? new FactItemFactory_1.default() : _a;
7
+ this.factItemFactory = factItemFactory;
22
8
  }
23
- /**
24
- * Avoids deep nesting logic while iteratating through company facts
25
- *
26
- * @param callback called on each company fact.
27
- */
28
- ReportRawParser.prototype.iterateCompanyFacts = function (companyFactListData, callback) {
29
- this.factIterator.iterateCompanyFacts(companyFactListData, callback);
30
- };
31
- /**
32
- * Returns raw reports in ascending order by report date. if date is the same, priority is filed date, frame, form
33
- */
34
- ReportRawParser.prototype.parseReports = function (companyFactListData, options) {
35
- var _this = this;
36
- var _a = options !== null && options !== void 0 ? options : {}, reportsToInclude = _a.reportsToInclude, mergeInstantaneousData = _a.mergeInstantaneousData;
37
- // default to all report types
38
- var reportsToIncludeSet = reportsToInclude
39
- ? new Set(Array.isArray(reportsToInclude) ? reportsToInclude : [reportsToInclude])
40
- : null;
41
- // for getting the earliest filed date for each report
42
- var datesFiledByDateForm = new Map();
43
- // for mapping individual properties to the report
44
- var reportsByKey = new Map();
45
- // fiscal period only provided for filed date, used to map to later assign for quarter end date
46
- var monthsFiledByFiscalPeriod = new Map();
47
- // iterate individual properties AKA "facts"
48
- this.iterateCompanyFacts(companyFactListData, function (_a) {
49
- var _b, _c, _d, _e, _f, _g, _h;
50
- var factValue = _a.factValue, propertyName = _a.propertyName, taxonomy = _a.taxonomy;
51
- var filed = factValue.filed, val = factValue.val, form = factValue.form, fp = factValue.fp, dateReport = factValue.end;
52
- // get frame for keys and to merge instantaneous data
53
- var isInstantaneousData = (_c = (_b = factValue.frame) === null || _b === void 0 ? void 0 : _b.endsWith('I')) !== null && _c !== void 0 ? _c : false;
54
- var isMergableFrame = (mergeInstantaneousData !== null && mergeInstantaneousData !== void 0 ? mergeInstantaneousData : true) && isInstantaneousData;
55
- var frame = isMergableFrame ? (_d = factValue.frame) === null || _d === void 0 ? void 0 : _d.substring(0, factValue.frame.length - 1) : factValue.frame;
56
- // keys to map report and file dates
57
- var keyDateForm = "".concat(dateReport, "_").concat(form);
58
- var keyReport = "".concat(frame, "_").concat(keyDateForm);
59
- // set earliest date filed
60
- var dateFiledPrev = (_e = datesFiledByDateForm.get(keyDateForm)) !== null && _e !== void 0 ? _e : filed;
61
- var dateFiled = filed < dateFiledPrev ? filed : dateFiledPrev;
62
- datesFiledByDateForm.set(keyDateForm, dateFiled);
63
- // if frame is undefined, the value is no longer the most recent
64
- if (!frame)
65
- return;
66
- var isTTM = frame.substring(6, 8).length !== 2;
67
- var reportType = _this.getReportType({ form: form, taxonomy: taxonomy, isTTM: isTTM });
68
- var isReportToInclude = (_f = reportsToIncludeSet === null || reportsToIncludeSet === void 0 ? void 0 : reportsToIncludeSet.has(reportType)) !== null && _f !== void 0 ? _f : true;
69
- if (!isReportToInclude)
70
- return;
71
- // set the month filed, will be used to get the fiscal period and year
72
- if (reportType === 'QUARTERLY' || reportType === 'ANNUAL') {
73
- var monthFiled = Number(filed.substring(5, 7));
74
- monthsFiledByFiscalPeriod.set(fp, ((_g = monthsFiledByFiscalPeriod.get(fp)) !== null && _g !== void 0 ? _g : new Set()).add(monthFiled));
9
+ ReportRawParser.prototype.parseReports = function (companyFactListData) {
10
+ var _a;
11
+ var _b = this.factItemFactory.createFactItems(companyFactListData), factItems = _b.factItems, factSplitMap = _b.factSplitMap;
12
+ var reportByYearPeriod = new Map();
13
+ for (var _i = 0, factItems_1 = factItems; _i < factItems_1.length; _i++) {
14
+ var factItem = factItems_1[_i];
15
+ if (!factItem.factValue.frame) {
16
+ continue;
75
17
  }
76
- var report = (_h = reportsByKey.get(keyReport)) !== null && _h !== void 0 ? _h : {
77
- dateReport: dateReport,
78
- dateFiled: dateFiled,
79
- form: form,
80
- isTTM: isTTM,
81
- frame: frame,
82
- taxonomy: taxonomy,
83
- reportType: reportType,
84
- // these will be updated
85
- fiscalPeriod: 'FY',
86
- fiscalYear: 0,
18
+ var key = "".concat(factItem.fiscalYear, "-").concat(factItem.fiscalPeriod);
19
+ var report = (_a = reportByYearPeriod.get(key)) !== null && _a !== void 0 ? _a : {
20
+ dateReport: factItem.fiscalPeriodEnd,
21
+ dateFiled: factItem.fiscalPeriodFiled,
22
+ fiscalPeriod: factItem.fiscalPeriod,
23
+ fiscalYear: factItem.fiscalYear,
24
+ splitRatio: null,
25
+ splitDate: null,
87
26
  };
88
- reportsByKey.set(keyReport, report);
89
- // update earliest date filed
90
- report.dateFiled = dateFiled;
91
- report[propertyName] = val;
92
- });
93
- // end date is typically the month before the filed date, so subtract 1, set to 12 if 0
94
- var fiscalPeriodsByMonth = new Map();
95
- monthsFiledByFiscalPeriod.forEach(function (monthsSet, fiscalPeriod) {
96
- monthsSet.forEach(function (month) { return fiscalPeriodsByMonth.set(month - 1 || 12, fiscalPeriod); });
97
- });
98
- // set fiscal period and year, then merge by year_quarter, because some reports have end dates a couple days apart
99
- var reportsByYearPeriod = new Map();
100
- reportsByKey.forEach(function (report) {
101
- var _a;
102
- var dateReport = report.dateReport, reportType = report.reportType;
103
- var monthReport = Number(dateReport.substring(5, 7));
104
- var fiscalPeriod = (_a = fiscalPeriodsByMonth.get(monthReport)) !== null && _a !== void 0 ? _a : 'FY';
105
- // Q4 is always FY, so needs to be changed to Q4 (comes from fp property in fact)
106
- report.fiscalPeriod = reportType === 'QUARTERLY' && fiscalPeriod === 'FY' ? 'Q4' : fiscalPeriod;
107
- report.fiscalYear = _this.getFiscalYear({ dateReport: dateReport, reportType: reportType, fiscalPeriod: report.fiscalPeriod });
108
- var keyReport = "".concat(report.fiscalYear, "_").concat(report.fiscalPeriod);
109
- var reportPrev = reportsByYearPeriod.get(keyReport);
110
- // if a report was already assigned to this key, merge and use the latest dateReport
111
- if (reportPrev) {
112
- var dateReport_1 = report.dateReport > reportPrev.dateReport ? report.dateReport : reportPrev.dateReport;
113
- reportPrev.dateReport = dateReport_1;
114
- reportsByYearPeriod.set(keyReport, __assign(__assign({}, reportPrev), report));
27
+ if (factSplitMap.isSplitFact(factItem)) {
28
+ report.splitRatio = factItem.factValue.val;
29
+ report.splitDate = factItem.factValue.end;
115
30
  }
116
- else {
117
- reportsByYearPeriod.set(keyReport, report);
118
- }
119
- });
120
- // return in ascending order by date report, date filed, frame, form
121
- return Array.from(reportsByYearPeriod.values()).sort(function (a, b) {
122
- var keyA = "".concat(a.fiscalYear, "_").concat(a.isTTM ? 'Q5' : a.fiscalPeriod, "_").concat(a.dateReport, "_").concat(a.dateFiled);
123
- var keyB = "".concat(b.fiscalYear, "_").concat(b.isTTM ? 'Q5' : b.fiscalPeriod, "_").concat(b.dateReport, "_").concat(b.dateFiled);
124
- return keyA > keyB ? 1 : -1;
31
+ report[factItem.propertyName] = factSplitMap.getSplitAdjustedValue(factItem);
32
+ reportByYearPeriod.set(key, report);
33
+ }
34
+ return Array.from(reportByYearPeriod.values()).sort(function (a, b) {
35
+ var keyA = "".concat(a.dateReport, "_").concat(a.fiscalPeriod === 'FY' ? 'Q5' : a.fiscalPeriod);
36
+ var keyB = "".concat(b.dateReport, "_").concat(b.fiscalPeriod === 'FY' ? 'Q5' : b.fiscalPeriod);
37
+ return keyA < keyB ? -1 : 1;
125
38
  });
126
39
  };
127
- ReportRawParser.prototype.getReportType = function (data) {
128
- var form = data.form, taxonomy = data.taxonomy, isTTM = data.isTTM;
129
- if (form === '8-K')
130
- return '8K';
131
- else if (taxonomy === 'dei')
132
- return 'DOCUMENT_ENTITY_INFO';
133
- else if (isTTM)
134
- return 'ANNUAL';
135
- return 'QUARTERLY';
136
- };
137
- ReportRawParser.prototype.getFiscalYear = function (data) {
138
- var dateReport = data.dateReport, reportType = data.reportType, fiscalPeriod = data.fiscalPeriod;
139
- var date = new Date("".concat(dateReport, "T00:00:00"));
140
- var day = date.getDate();
141
- var month = day < 14 ? date.getMonth() || 12 : date.getMonth() + 1;
142
- var year = date.getFullYear();
143
- var monthAddMap = {
144
- Q1: 9,
145
- Q2: 6,
146
- Q3: 3,
147
- Q4: 0,
148
- FY: 0,
149
- };
150
- return month + monthAddMap[fiscalPeriod] > 12 && reportType === 'QUARTERLY' ? year + 1 : year;
151
- };
152
40
  return ReportRawParser;
153
41
  }());
154
42
  exports.default = ReportRawParser;
@@ -30,13 +30,10 @@ var ReportWrapper = /** @class */ (function (_super) {
30
30
  _this.reportRaw = reportRaw !== null && reportRaw !== void 0 ? reportRaw : {
31
31
  dateFiled: report.dateFiled,
32
32
  dateReport: report.dateReport,
33
- form: report.form,
34
- isTTM: report.isTTM,
35
- frame: '',
36
- taxonomy: '',
37
- reportType: report.isTTM ? 'ANNUAL' : 'QUARTERLY',
38
33
  fiscalPeriod: (_a = report.fiscalPeriod) !== null && _a !== void 0 ? _a : '',
39
34
  fiscalYear: report.fiscalYear,
35
+ splitRatio: null,
36
+ splitDate: null,
40
37
  };
41
38
  return _this;
42
39
  }
@@ -12,6 +12,7 @@ import { resolveFiscalYearCumulativeProperties } from './resolve-fiscal-year-cum
12
12
  import { resolveLiabilityCurrent } from './resolve-liability-current';
13
13
  import { resolveQ4FiscalYearMatchingProperties } from './resolve-q4-fiscal-year-matching-properties';
14
14
  import { resolveRevenueTotal } from './resolve-revenue-total';
15
+ import { resolveSplitRatio } from './resolve-split-ratio';
15
16
  declare const resolvers: {
16
17
  resolveAssetNonCurrentPPEGross: typeof resolveAssetNonCurrentPPEGross;
17
18
  resolveExpenseDepreciation: typeof resolveExpenseDepreciation;
@@ -27,5 +28,6 @@ declare const resolvers: {
27
28
  resolveLiabilityCurrent: typeof resolveLiabilityCurrent;
28
29
  resolveQ4FiscalYearMatchingProperties: typeof resolveQ4FiscalYearMatchingProperties;
29
30
  resolveCashFlowWorkingCapitalNonCash: typeof resolveCashFlowWorkingCapitalNonCash;
31
+ resolveSplitRatio: typeof resolveSplitRatio;
30
32
  };
31
33
  export default resolvers;
@@ -14,6 +14,7 @@ var resolve_fiscal_year_cumulative_properties_1 = require("./resolve-fiscal-year
14
14
  var resolve_liability_current_1 = require("./resolve-liability-current");
15
15
  var resolve_q4_fiscal_year_matching_properties_1 = require("./resolve-q4-fiscal-year-matching-properties");
16
16
  var resolve_revenue_total_1 = require("./resolve-revenue-total");
17
+ var resolve_split_ratio_1 = require("./resolve-split-ratio");
17
18
  var resolvers = {
18
19
  resolveAssetNonCurrentPPEGross: resolve_asset_non_current_ppe_gross_1.resolveAssetNonCurrentPPEGross,
19
20
  resolveExpenseDepreciation: resolve_expense_depreciation_1.resolveExpenseDepreciation,
@@ -29,5 +30,6 @@ var resolvers = {
29
30
  resolveLiabilityCurrent: resolve_liability_current_1.resolveLiabilityCurrent,
30
31
  resolveQ4FiscalYearMatchingProperties: resolve_q4_fiscal_year_matching_properties_1.resolveQ4FiscalYearMatchingProperties,
31
32
  resolveCashFlowWorkingCapitalNonCash: resolve_cash_flow_working_capital_non_cash_1.resolveCashFlowWorkingCapitalNonCash,
33
+ resolveSplitRatio: resolve_split_ratio_1.resolveSplitRatio,
32
34
  };
33
35
  exports.default = resolvers;
@@ -7,9 +7,10 @@ var helpers_1 = require("./helpers");
7
7
  */
8
8
  function resolveCashFlowCapex(report) {
9
9
  var _a, _b, _c;
10
- if (report.fiscalYear !== 2022 || report.cashFlowCapex !== null)
10
+ if (report.cashFlowCapex !== null)
11
11
  return;
12
- var reportPrev = report.getReportOffset(-1, report.isTTM ? 'ANNUAL' : 'QUARTERLY');
12
+ var isFY = report.fiscalPeriod === 'FY';
13
+ var reportPrev = report.getReportOffset(-1, isFY ? 'ANNUAL' : 'QUARTERLY');
13
14
  var _d = report.getReportsFiscalYearByPeriod(), FY = _d.FY, Q1 = _d.Q1, Q2 = _d.Q2, Q3 = _d.Q3, Q4 = _d.Q4;
14
15
  if (FY === null) {
15
16
  report.cashFlowCapex = (_a = reportPrev === null || reportPrev === void 0 ? void 0 : reportPrev.cashFlowCapex) !== null && _a !== void 0 ? _a : null;
@@ -17,7 +18,7 @@ function resolveCashFlowCapex(report) {
17
18
  }
18
19
  var sumQuarters = [Q1, Q2, Q3, Q4].reduce(function (sum, rep) { var _a; return sum + ((_a = rep === null || rep === void 0 ? void 0 : rep.cashFlowCapex) !== null && _a !== void 0 ? _a : 0); }, 0);
19
20
  var reportsQuarterlyWithoutCapex = [Q1, Q2, Q3, Q4].filter(function (rep) { return rep && rep.cashFlowCapex === null; });
20
- if (report.isTTM) {
21
+ if (isFY) {
21
22
  if (reportsQuarterlyWithoutCapex.length === 0)
22
23
  report.cashFlowCapex = sumQuarters;
23
24
  return;
@@ -27,7 +27,7 @@ function resolveCashFlowOperating(report) {
27
27
  }
28
28
  exports.resolveCashFlowOperating = resolveCashFlowOperating;
29
29
  function getCashFlowOperating(report) {
30
- var reportPrev = report.getReportOffset(-1, report.isTTM ? 'ANNUAL' : 'QUARTERLY');
30
+ var reportPrev = report.getReportOffset(-1, report.fiscalPeriod === 'FY' ? 'ANNUAL' : 'QUARTERLY');
31
31
  if (!reportPrev)
32
32
  return null;
33
33
  var _a = report, incomeNet = _a.incomeNet, expenseDepreciation = _a.expenseDepreciation, cashFlowWorkingCapitalNonCash = _a.cashFlowWorkingCapitalNonCash;
@@ -6,7 +6,7 @@ function resolveCashFlowWorkingCapitalNonCash(report) {
6
6
  if (report.cashFlowWorkingCapitalNonCash !== null)
7
7
  return;
8
8
  // the previous report is used to calculate the change in working capital in resolveCashFlowOperating
9
- var reportWrapperPrev = report.getReportOffset(-1, report.isTTM ? 'ANNUAL' : 'QUARTERLY');
9
+ var reportWrapperPrev = report.getReportOffset(-1, report.fiscalPeriod === 'FY' ? 'ANNUAL' : 'QUARTERLY');
10
10
  var _a = report.getReportsFiscalYearByPeriod(), FY = _a.FY, Q1 = _a.Q1, Q2 = _a.Q2, Q3 = _a.Q3, Q4 = _a.Q4;
11
11
  for (var _i = 0, _b = [FY, Q1, Q2, Q3, Q4, reportWrapperPrev]; _i < _b.length; _i++) {
12
12
  var report_1 = _b[_i];
@@ -81,7 +81,7 @@ function getDepreciationPercentOfPPE(report) {
81
81
  }
82
82
  // if checking depreciation using an annual report, we need to get the sum of the quarters
83
83
  var ppeDenominator = assetNonCurrentPPEGrossTTMOrPrev;
84
- if (reportTTMOrPrev.isTTM && !report.isTTM) {
84
+ if (reportTTMOrPrev.fiscalPeriod === 'FY' && report.fiscalPeriod !== 'FY') {
85
85
  var _e = reportTTMOrPrev.getReportsFiscalYearByPeriod(), Q1 = _e.Q1, Q2 = _e.Q2, Q3 = _e.Q3, Q4 = _e.Q4;
86
86
  ppeDenominator = 0;
87
87
  for (var _i = 0, _f = [Q1, Q2, Q3, Q4]; _i < _f.length; _i++) {
@@ -12,24 +12,38 @@ function resolveFiscalYearCumulativeProperties(report) {
12
12
  matchProperty('assetNonCurrentPPEGross', Q4, FY);
13
13
  matchProperty('assetNonCurrentPPENet', Q4, FY);
14
14
  matchProperty('expenseDepreciationAccumulated', Q4, FY);
15
- // keys that should not add up to the FY value
16
- var keysToSkip = new Set([
17
- 'expenseDepreciationAccumulated',
18
- 'assetNonCurrentPPEGross',
19
- 'assetNonCurrentPPENet',
20
- 'dateFiled',
21
- 'dateReport',
22
- 'fiscalPeriod',
23
- 'fiscalYear',
24
- 'isTTM',
25
- 'form',
26
- 'sharesOutstanding',
27
- 'sharesOutstandingDiluted',
15
+ var keysToInclude = new Set([
16
+ 'cashFlowCapex',
17
+ 'cashFlowDeferredTax',
18
+ 'cashFlowDividendsPaid',
19
+ 'cashFlowDividendsPaidPreferred',
20
+ 'cashFlowFree',
21
+ 'cashFlowOperating',
22
+ 'cashFlowWorkingCapitalNonCash',
23
+ 'assetNonCurrentIntangibleLessGoodwill',
24
+ 'expenseDepreciation',
25
+ 'expenseInterest',
26
+ 'expenseNonCashOther',
27
+ 'expenseOperating',
28
+ 'expenseResearchDevelopment',
29
+ 'expenseStockCompensation',
30
+ 'expenseTax',
31
+ 'expenseTotal',
32
+ 'ebit',
33
+ 'ebitda',
34
+ 'eps',
35
+ 'epsDiluted',
36
+ 'incomeNet',
37
+ 'incomeOperating',
38
+ 'profitGross',
39
+ 'revenueCost',
40
+ 'revenueOperating',
41
+ 'revenueTotal',
28
42
  ]);
29
43
  var reportKeys = Object.keys(Q1);
30
44
  var keysToResolve = reportKeys.filter(function (key) {
31
45
  var reportsWithVal = [FY, Q1, Q2, Q3, Q4].filter(function (report) {
32
- return typeof report[key] === 'number' && !keysToSkip.has(key);
46
+ return typeof report[key] === 'number' && keysToInclude.has(key);
33
47
  });
34
48
  // we want to get the keys that are in 4 of the 5 reports
35
49
  return reportsWithVal.length === 4;
@@ -8,10 +8,38 @@ function resolveQ4FiscalYearMatchingProperties(reportWrapper) {
8
8
  var _a = reportWrapper.getReportsFiscalYearByPeriod(), FY = _a.FY, Q1 = _a.Q1, Q2 = _a.Q2, Q3 = _a.Q3, Q4 = _a.Q4;
9
9
  if (!FY || !Q1 || !Q2 || !Q3 || !Q4)
10
10
  return;
11
- // these properties should be the same for Q4 and FY
12
- matchProperty('assetNonCurrentPPEGross', Q4, FY);
13
- matchProperty('assetNonCurrentPPENet', Q4, FY);
14
- matchProperty('expenseDepreciationAccumulated', Q4, FY);
11
+ var matchingProperties = [
12
+ 'assetCurrent',
13
+ 'assetCurrentAccountsReceivable',
14
+ 'assetCurrentCashEquivalents',
15
+ 'assetCurrentInventory',
16
+ 'assetCurrentInvestments',
17
+ 'assetNonCurrent',
18
+ 'assetNonCurrentGoodwill',
19
+ 'assetNonCurrentIntangibleLessGoodwill',
20
+ 'assetNonCurrentInvestments',
21
+ 'assetNonCurrentPPEGross',
22
+ 'assetNonCurrentPPENet',
23
+ 'assetTotal',
24
+ 'liabilityCurrent',
25
+ 'liabilityCurrentAccountsPayable',
26
+ 'liabilityCurrentDebt',
27
+ 'liabilityNonCurrent',
28
+ 'liabilityNonCurrentDebt',
29
+ 'liabilityTotal',
30
+ 'equityRetainedEarnings',
31
+ 'equityStockPreferred',
32
+ 'equityTotal',
33
+ 'dateFiled',
34
+ 'dateReport',
35
+ 'sharesOutstanding',
36
+ 'sharesOutstandingDiluted',
37
+ 'splitRatio',
38
+ ];
39
+ for (var _i = 0, matchingProperties_1 = matchingProperties; _i < matchingProperties_1.length; _i++) {
40
+ var property = matchingProperties_1[_i];
41
+ matchProperty(property, Q4, FY);
42
+ }
15
43
  }
16
44
  exports.resolveQ4FiscalYearMatchingProperties = resolveQ4FiscalYearMatchingProperties;
17
45
  function matchProperty(propertyName, reportA, reportB) {
@@ -0,0 +1,2 @@
1
+ import ReportWrapper from '../ReportWrapper';
2
+ export declare function resolveSplitRatio(report: ReportWrapper): void;